diff --git a/.flake8 b/.flake8 index 29227d4cf4..2e43874986 100644 --- a/.flake8 +++ b/.flake8 @@ -16,7 +16,7 @@ # Generated by synthtool. DO NOT EDIT! [flake8] -ignore = E203, E266, E501, W503 +ignore = E203, E231, E266, E501, W503 exclude = # Exclude generated code. **/proto/** diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml new file mode 100644 index 0000000000..757c9dca75 --- /dev/null +++ b/.github/.OwlBot.lock.yaml @@ -0,0 +1,17 @@ +# Copyright 2022 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. +docker: + image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest + digest: sha256:81ed5ecdfc7cac5b699ba4537376f3563f6f04122c4ec9e735d3b3dc1d43dd32 +# created: 2022-05-05T22:08:23.383410683Z diff --git a/.github/.OwlBot.yaml b/.github/.OwlBot.yaml new file mode 100644 index 0000000000..62483abbee --- /dev/null +++ b/.github/.OwlBot.yaml @@ -0,0 +1,28 @@ +# 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 +# +# 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. + +docker: + image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest + +deep-remove-regex: + - /owl-bot-staging + +deep-copy-regex: + - source: /google/cloud/aiplatform/(v.*)/aiplatform-.*-py/(.*) + dest: /owl-bot-staging/$1/$2 + - source: /google/cloud/aiplatform/v*/schema/.*/.*-py/(google/cloud/.*) + dest: /owl-bot-staging/$1 + +begin-after-commit-hash: 7774246dfb7839067cd64bba0600089b1c91bd85 + diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index f0c14d5c2b..14998d13e5 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -4,18 +4,28 @@ # For syntax help see: # https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners#codeowners-syntax -# yoshi-python is the default owner -* @googleapis/yoshi-python +# @googleapis/cdpe-cloudai and yoshi-python are the default owners +* @googleapis/cdpe-cloudai @googleapis/yoshi-python # The AI Platform GAPIC libraries are owned by Cloud AI DPE -/google/cloud/aiplatform* @googleapis/cdpe-cloudai +/google/cloud/aiplatform_*/** @googleapis/cdpe-cloudai -# The Vertex SDK is owned by Model Builder SDK Dev team -/google/cloud/aiplatform/* @googleapis/cloud-aiplatform-model-builder-sdk -/tests/unit/aiplatform/* @googleapis/cloud-aiplatform-model-builder-sdk +# The Vertex SDK is owned by Vertex SDK Dev team +/google/cloud/aiplatform/** @googleapis/cloud-aiplatform-model-builder-sdk +/tests/system/aiplatform/** @googleapis/cloud-aiplatform-model-builder-sdk +/tests/unit/aiplatform/** @googleapis/cloud-aiplatform-model-builder-sdk # The Cloud AI DPE team is the default owner for samples -/samples/**/*.py @googleapis/cdpe-cloudai @googleapis/python-samples-owners +/samples/**/*.py @googleapis/cdpe-cloudai @googleapis/python-samples-reviewers +/.sample_configs/** @googleapis/cdpe-cloudai # The enhanced client library tests are owned by Cloud AI DPE /tests/unit/enhanced_library/*.py @googleapis/cdpe-cloudai + +# Core library files owned by Cloud AI DPE and Vertex SDK Dev teams +CHANGELOG.md @googleapis/cloud-aiplatform-model-builder-sdk @googleapis/cdpe-cloudai +README.rst @googleapis/cloud-aiplatform-model-builder-sdk @googleapis/cdpe-cloudai +setup.py @googleapis/cloud-aiplatform-model-builder-sdk @googleapis/cdpe-cloudai + +# Vertex AI product team-specific ownership +/google/cloud/aiplatform/constants/prediction.py @googleapis/vertex-prediction-team diff --git a/.github/auto-approve.yml b/.github/auto-approve.yml new file mode 100644 index 0000000000..311ebbb853 --- /dev/null +++ b/.github/auto-approve.yml @@ -0,0 +1,3 @@ +# https://github.com/googleapis/repo-automation-bots/tree/main/packages/auto-approve +processes: + - "OwlBotTemplateChanges" diff --git a/.github/auto-label.yaml b/.github/auto-label.yaml new file mode 100644 index 0000000000..41bff0b537 --- /dev/null +++ b/.github/auto-label.yaml @@ -0,0 +1,15 @@ +# Copyright 2022 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. +requestsize: + enabled: true diff --git a/.github/release-please.yml b/.github/release-please.yml index 4507ad0598..6def37a84c 100644 --- a/.github/release-please.yml +++ b/.github/release-please.yml @@ -1 +1,8 @@ releaseType: python +handleGHRelease: true +# NOTE: this section is generated by synthtool.languages.python +# See https://github.com/googleapis/synthtool/blob/master/synthtool/languages/python.py +branches: +- branch: v0 + handleGHRelease: true + releaseType: python diff --git a/.github/release-trigger.yml b/.github/release-trigger.yml new file mode 100644 index 0000000000..d4ca94189e --- /dev/null +++ b/.github/release-trigger.yml @@ -0,0 +1 @@ +enabled: true diff --git a/.github/sync-repo-settings.yaml b/.github/sync-repo-settings.yaml index 1e00173609..e0ac340c75 100644 --- a/.github/sync-repo-settings.yaml +++ b/.github/sync-repo-settings.yaml @@ -1,11 +1,12 @@ -# https://github.com/googleapis/repo-automation-bots/tree/master/packages/sync-repo-settings -# Rules for master branch protection +# https://github.com/googleapis/repo-automation-bots/tree/main/packages/sync-repo-settings +# Rules for main branch protection mergeCommitAllowed: true branchProtectionRules: # Identifies the protection rule pattern. Name of the branch to be protected. -# Defaults to `master` -- pattern: master +# Defaults to `main` +- pattern: main + requiresCodeOwnerReviews: true + requiresStrictStatusChecks: true requiredStatusCheckContexts: - - 'Kokoro' - 'cla/google' - - 'Samples - Lint' + - 'Presubmit - Unit Tests' diff --git a/.kokoro/build.sh b/.kokoro/build.sh index 35e4a0f6ce..32e6d625b4 100755 --- a/.kokoro/build.sh +++ b/.kokoro/build.sh @@ -41,7 +41,7 @@ python3 -m pip install --upgrade --quiet nox python3 -m nox --version # If this is a continuous build, send the test log to the FlakyBot. -# See https://github.com/googleapis/repo-automation-bots/tree/master/packages/flakybot. +# See https://github.com/googleapis/repo-automation-bots/tree/main/packages/flakybot. if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"continuous"* ]]; then cleanup() { chmod +x $KOKORO_GFILE_DIR/linux_amd64/flakybot diff --git a/.kokoro/continuous/common.cfg b/.kokoro/continuous/common.cfg index 7e71cb43e9..c8f353660a 100644 --- a/.kokoro/continuous/common.cfg +++ b/.kokoro/continuous/common.cfg @@ -25,3 +25,11 @@ env_vars: { key: "TRAMPOLINE_BUILD_FILE" value: "github/python-aiplatform/.kokoro/build.sh" } +env_vars: { + key: "BUILD_SPECIFIC_GCLOUD_PROJECT" + value: "ucaip-sample-tests" +} +env_vars { + key: "_VPC_NETWORK_URI" + value: "projects/580378083368/global/networks/system-tests" +} diff --git a/.kokoro/continuous/system.cfg b/.kokoro/continuous/system.cfg new file mode 100644 index 0000000000..1fdefbaa72 --- /dev/null +++ b/.kokoro/continuous/system.cfg @@ -0,0 +1,15 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +env_vars: { + key: "NOX_SESSION" + value: "system-3.8" +} + +# Run system tests in parallel, splitting up by file +env_vars: { + key: "PYTEST_ADDOPTS" + value: "-n=auto --dist=loadscope" +} + +# Kokoro VM timeout of 5 hours for system tests +timeout_mins: 300 diff --git a/.kokoro/continuous/unit.cfg b/.kokoro/continuous/unit.cfg new file mode 100644 index 0000000000..57188a42d1 --- /dev/null +++ b/.kokoro/continuous/unit.cfg @@ -0,0 +1,13 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Run all unit test sessions, in Python 3.7 to 3.9 +env_vars: { + key: "NOX_SESSION" + value: "unit" +} + +# Run unit tests in parallel, splitting up by test +env_vars: { + key: "PYTEST_ADDOPTS" + value: "-n=auto --dist=loadscope" +} diff --git a/.kokoro/docker/docs/Dockerfile b/.kokoro/docker/docs/Dockerfile index 412b0b56a9..238b87b9d1 100644 --- a/.kokoro/docker/docs/Dockerfile +++ b/.kokoro/docker/docs/Dockerfile @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from ubuntu:20.04 +from ubuntu:22.04 ENV DEBIAN_FRONTEND noninteractive @@ -40,6 +40,7 @@ RUN apt-get update \ libssl-dev \ libsqlite3-dev \ portaudio19-dev \ + python3-distutils \ redis-server \ software-properties-common \ ssh \ @@ -59,40 +60,24 @@ RUN apt-get update \ && rm -rf /var/lib/apt/lists/* \ && rm -f /var/cache/apt/archives/*.deb +###################### Install python 3.8.11 -COPY fetch_gpg_keys.sh /tmp -# Install the desired versions of Python. -RUN set -ex \ - && export GNUPGHOME="$(mktemp -d)" \ - && echo "disable-ipv6" >> "${GNUPGHOME}/dirmngr.conf" \ - && /tmp/fetch_gpg_keys.sh \ - && for PYTHON_VERSION in 3.7.8 3.8.5; do \ - wget --no-check-certificate -O python-${PYTHON_VERSION}.tar.xz "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz" \ - && wget --no-check-certificate -O python-${PYTHON_VERSION}.tar.xz.asc "https://www.python.org/ftp/python/${PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc" \ - && gpg --batch --verify python-${PYTHON_VERSION}.tar.xz.asc python-${PYTHON_VERSION}.tar.xz \ - && rm -r python-${PYTHON_VERSION}.tar.xz.asc \ - && mkdir -p /usr/src/python-${PYTHON_VERSION} \ - && tar -xJC /usr/src/python-${PYTHON_VERSION} --strip-components=1 -f python-${PYTHON_VERSION}.tar.xz \ - && rm python-${PYTHON_VERSION}.tar.xz \ - && cd /usr/src/python-${PYTHON_VERSION} \ - && ./configure \ - --enable-shared \ - # This works only on Python 2.7 and throws a warning on every other - # version, but seems otherwise harmless. - --enable-unicode=ucs4 \ - --with-system-ffi \ - --without-ensurepip \ - && make -j$(nproc) \ - && make install \ - && ldconfig \ - ; done \ - && rm -rf "${GNUPGHOME}" \ - && rm -rf /usr/src/python* \ - && rm -rf ~/.cache/ +# Download python 3.8.11 +RUN wget https://www.python.org/ftp/python/3.8.11/Python-3.8.11.tgz +# Extract files +RUN tar -xvf Python-3.8.11.tgz + +# Install python 3.8.11 +RUN ./Python-3.8.11/configure --enable-optimizations +RUN make altinstall + +###################### Install pip RUN wget -O /tmp/get-pip.py 'https://bootstrap.pypa.io/get-pip.py' \ - && python3.7 /tmp/get-pip.py \ - && python3.8 /tmp/get-pip.py \ + && python3 /tmp/get-pip.py \ && rm /tmp/get-pip.py -CMD ["python3.7"] +# Test pip +RUN python3 -m pip + +CMD ["python3.8"] diff --git a/.kokoro/docker/docs/fetch_gpg_keys.sh b/.kokoro/docker/docs/fetch_gpg_keys.sh deleted file mode 100755 index d653dd868e..0000000000 --- a/.kokoro/docker/docs/fetch_gpg_keys.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash -# 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. - -# A script to fetch gpg keys with retry. -# Avoid jinja parsing the file. -# - -function retry { - if [[ "${#}" -le 1 ]]; then - echo "Usage: ${0} retry_count commands.." - exit 1 - fi - local retries=${1} - local command="${@:2}" - until [[ "${retries}" -le 0 ]]; do - $command && return 0 - if [[ $? -ne 0 ]]; then - echo "command failed, retrying" - ((retries--)) - fi - done - return 1 -} - -# 3.6.9, 3.7.5 (Ned Deily) -retry 3 gpg --keyserver ha.pool.sks-keyservers.net --recv-keys \ - 0D96DF4D4110E5C43FBFB17F2D347EA6AA65421D - -# 3.8.0 (Ɓukasz Langa) -retry 3 gpg --keyserver ha.pool.sks-keyservers.net --recv-keys \ - E3FF2839C048B25C084DEBE9B26995E310250568 - -# diff --git a/.kokoro/docs/common.cfg b/.kokoro/docs/common.cfg index 5adc161f36..fe691d5317 100644 --- a/.kokoro/docs/common.cfg +++ b/.kokoro/docs/common.cfg @@ -30,6 +30,7 @@ env_vars: { env_vars: { key: "V2_STAGING_BUCKET" + # Push google cloud library docs to the Cloud RAD bucket `docs-staging-v2` value: "docs-staging-v2" } diff --git a/.kokoro/presubmit/presubmit.cfg b/.kokoro/presubmit/presubmit.cfg index 8f43917d92..66f7c8a934 100644 --- a/.kokoro/presubmit/presubmit.cfg +++ b/.kokoro/presubmit/presubmit.cfg @@ -1 +1,13 @@ -# Format: //devtools/kokoro/config/proto/build.proto \ No newline at end of file +# Format: //devtools/kokoro/config/proto/build.proto + +# Run all sessions except system tests and docs builds +env_vars: { + key: "NOX_SESSION" + value: "unit lint lint_setup_py blacken cover" +} + +# Run unit tests in parallel, splitting up by file +env_vars: { + key: "PYTEST_ADDOPTS" + value: "-n=auto --dist=loadscope" +} diff --git a/.kokoro/presubmit/release.cfg b/.kokoro/presubmit/release.cfg new file mode 100644 index 0000000000..fc047df824 --- /dev/null +++ b/.kokoro/presubmit/release.cfg @@ -0,0 +1,13 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Run system tests in presubmit for library releases +env_vars: { + key: "NOX_SESSION" + value: "system-3.8 unit" +} + +# Run system tests in parallel, splitting up by file +env_vars: { + key: "PYTEST_ADDOPTS" + value: "-n=auto --dist=loadscope" +} diff --git a/.kokoro/presubmit/system.cfg b/.kokoro/presubmit/system.cfg new file mode 100644 index 0000000000..29bcaf044c --- /dev/null +++ b/.kokoro/presubmit/system.cfg @@ -0,0 +1,13 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Run system tests when test files are modified +env_vars: { + key: "NOX_SESSION" + value: "system-3.8" +} + +# Run system tests in parallel, splitting up by file +env_vars: { + key: "PYTEST_ADDOPTS" + value: "-n=auto --dist=loadscope" +} diff --git a/.kokoro/release.sh b/.kokoro/release.sh index 62bdb892ff..7ca397271d 100755 --- a/.kokoro/release.sh +++ b/.kokoro/release.sh @@ -26,7 +26,7 @@ python3 -m pip install --upgrade twine wheel setuptools export PYTHONUNBUFFERED=1 # Move into the package, build the distribution and upload. -TWINE_PASSWORD=$(cat "${KOKORO_GFILE_DIR}/secret_manager/google-cloud-pypi-token") +TWINE_PASSWORD=$(cat "${KOKORO_KEYSTORE_DIR}/73713_google-cloud-pypi-token-keystore-1") cd github/python-aiplatform python3 setup.py sdist bdist_wheel twine upload --username __token__ --password "${TWINE_PASSWORD}" dist/* diff --git a/.kokoro/release/common.cfg b/.kokoro/release/common.cfg index 5293e75110..08012edcbd 100644 --- a/.kokoro/release/common.cfg +++ b/.kokoro/release/common.cfg @@ -23,8 +23,18 @@ env_vars: { value: "github/python-aiplatform/.kokoro/release.sh" } +# Fetch PyPI password +before_action { + fetch_keystore { + keystore_resource { + keystore_config_id: 73713 + keyname: "google-cloud-pypi-token-keystore-1" + } + } +} + # Tokens needed to report release status back to GitHub env_vars: { key: "SECRET_MANAGER_KEYS" - value: "releasetool-publish-reporter-app,releasetool-publish-reporter-googleapis-installation,releasetool-publish-reporter-pem,google-cloud-pypi-token" + value: "releasetool-publish-reporter-app,releasetool-publish-reporter-googleapis-installation,releasetool-publish-reporter-pem" } diff --git a/.kokoro/samples/lint/common.cfg b/.kokoro/samples/lint/common.cfg index 87d5295efb..a239d54498 100644 --- a/.kokoro/samples/lint/common.cfg +++ b/.kokoro/samples/lint/common.cfg @@ -31,4 +31,4 @@ gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples" gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" # Use the trampoline script to run in docker. -build_file: "python-aiplatform/.kokoro/trampoline.sh" \ No newline at end of file +build_file: "python-aiplatform/.kokoro/trampoline_v2.sh" \ No newline at end of file diff --git a/.kokoro/samples/python3.10/common.cfg b/.kokoro/samples/python3.10/common.cfg new file mode 100644 index 0000000000..a49138fd0a --- /dev/null +++ b/.kokoro/samples/python3.10/common.cfg @@ -0,0 +1,40 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Build logs will be here +action { + define_artifacts { + regex: "**/*sponge_log.xml" + } +} + +# Specify which tests to run +env_vars: { + key: "RUN_TESTS_SESSION" + value: "py-3.10" +} + +# Declare build specific Cloud project. +env_vars: { + key: "BUILD_SPECIFIC_GCLOUD_PROJECT" + value: "ucaip-sample-tests" +} + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/python-aiplatform/.kokoro/test-samples.sh" +} + +# Configure the docker image for kokoro-trampoline. +env_vars: { + key: "TRAMPOLINE_IMAGE" + value: "gcr.io/cloud-devrel-kokoro-resources/python-samples-testing-docker" +} + +# Download secrets for samples +gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples" + +# Download trampoline resources. +gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" + +# Use the trampoline script to run in docker. +build_file: "python-aiplatform/.kokoro/trampoline_v2.sh" \ No newline at end of file diff --git a/.kokoro/samples/python3.10/continuous.cfg b/.kokoro/samples/python3.10/continuous.cfg new file mode 100644 index 0000000000..a1c8d9759c --- /dev/null +++ b/.kokoro/samples/python3.10/continuous.cfg @@ -0,0 +1,6 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +env_vars: { + key: "INSTALL_LIBRARY_FROM_SOURCE" + value: "True" +} \ No newline at end of file diff --git a/.kokoro/samples/python3.10/periodic-head.cfg b/.kokoro/samples/python3.10/periodic-head.cfg new file mode 100644 index 0000000000..88d5235e34 --- /dev/null +++ b/.kokoro/samples/python3.10/periodic-head.cfg @@ -0,0 +1,11 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +env_vars: { + key: "INSTALL_LIBRARY_FROM_SOURCE" + value: "True" +} + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/python-aiplatform/.kokoro/test-samples-against-head.sh" +} diff --git a/.kokoro/samples/python3.6/periodic.cfg b/.kokoro/samples/python3.10/periodic.cfg similarity index 98% rename from .kokoro/samples/python3.6/periodic.cfg rename to .kokoro/samples/python3.10/periodic.cfg index 50fec96497..71cd1e597e 100644 --- a/.kokoro/samples/python3.6/periodic.cfg +++ b/.kokoro/samples/python3.10/periodic.cfg @@ -3,4 +3,4 @@ env_vars: { key: "INSTALL_LIBRARY_FROM_SOURCE" value: "False" -} \ No newline at end of file +} diff --git a/.kokoro/samples/python3.10/presubmit.cfg b/.kokoro/samples/python3.10/presubmit.cfg new file mode 100644 index 0000000000..a1c8d9759c --- /dev/null +++ b/.kokoro/samples/python3.10/presubmit.cfg @@ -0,0 +1,6 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +env_vars: { + key: "INSTALL_LIBRARY_FROM_SOURCE" + value: "True" +} \ No newline at end of file diff --git a/.kokoro/samples/python3.6/common.cfg b/.kokoro/samples/python3.6/common.cfg index 9801281f05..72bfadc9f4 100644 --- a/.kokoro/samples/python3.6/common.cfg +++ b/.kokoro/samples/python3.6/common.cfg @@ -7,18 +7,18 @@ action { } } -# Declare build specific Cloud project. -env_vars: { - key: "BUILD_SPECIFIC_GCLOUD_PROJECT" - value: "ucaip-sample-tests" -} - # Specify which tests to run env_vars: { key: "RUN_TESTS_SESSION" value: "py-3.6" } +# Declare build specific Cloud project. +env_vars: { + key: "BUILD_SPECIFIC_GCLOUD_PROJECT" + value: "ucaip-sample-tests" +} + env_vars: { key: "TRAMPOLINE_BUILD_FILE" value: "github/python-aiplatform/.kokoro/test-samples.sh" @@ -37,4 +37,4 @@ gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples" gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" # Use the trampoline script to run in docker. -build_file: "python-aiplatform/.kokoro/trampoline.sh" \ No newline at end of file +build_file: "python-aiplatform/.kokoro/trampoline_v2.sh" \ No newline at end of file diff --git a/.kokoro/samples/python3.6/periodic-head.cfg b/.kokoro/samples/python3.6/periodic-head.cfg new file mode 100644 index 0000000000..88d5235e34 --- /dev/null +++ b/.kokoro/samples/python3.6/periodic-head.cfg @@ -0,0 +1,11 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +env_vars: { + key: "INSTALL_LIBRARY_FROM_SOURCE" + value: "True" +} + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/python-aiplatform/.kokoro/test-samples-against-head.sh" +} diff --git a/.kokoro/samples/python3.7/common.cfg b/.kokoro/samples/python3.7/common.cfg index c71cf79c57..cc8296c89d 100644 --- a/.kokoro/samples/python3.7/common.cfg +++ b/.kokoro/samples/python3.7/common.cfg @@ -7,18 +7,18 @@ action { } } -# Declare build specific Cloud project. -env_vars: { - key: "BUILD_SPECIFIC_GCLOUD_PROJECT" - value: "ucaip-sample-tests" -} - # Specify which tests to run env_vars: { key: "RUN_TESTS_SESSION" value: "py-3.7" } +# Declare build specific Cloud project. +env_vars: { + key: "BUILD_SPECIFIC_GCLOUD_PROJECT" + value: "ucaip-sample-tests" +} + env_vars: { key: "TRAMPOLINE_BUILD_FILE" value: "github/python-aiplatform/.kokoro/test-samples.sh" @@ -37,4 +37,4 @@ gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples" gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" # Use the trampoline script to run in docker. -build_file: "python-aiplatform/.kokoro/trampoline.sh" \ No newline at end of file +build_file: "python-aiplatform/.kokoro/trampoline_v2.sh" \ No newline at end of file diff --git a/.kokoro/samples/python3.7/periodic-head.cfg b/.kokoro/samples/python3.7/periodic-head.cfg new file mode 100644 index 0000000000..88d5235e34 --- /dev/null +++ b/.kokoro/samples/python3.7/periodic-head.cfg @@ -0,0 +1,11 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +env_vars: { + key: "INSTALL_LIBRARY_FROM_SOURCE" + value: "True" +} + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/python-aiplatform/.kokoro/test-samples-against-head.sh" +} diff --git a/.kokoro/samples/python3.7/periodic.cfg b/.kokoro/samples/python3.7/periodic.cfg index 50fec96497..b196817872 100644 --- a/.kokoro/samples/python3.7/periodic.cfg +++ b/.kokoro/samples/python3.7/periodic.cfg @@ -2,5 +2,5 @@ env_vars: { key: "INSTALL_LIBRARY_FROM_SOURCE" - value: "False" -} \ No newline at end of file + value: "True" +} diff --git a/.kokoro/samples/python3.8/common.cfg b/.kokoro/samples/python3.8/common.cfg index 21b411c8e1..a118253a82 100644 --- a/.kokoro/samples/python3.8/common.cfg +++ b/.kokoro/samples/python3.8/common.cfg @@ -7,22 +7,16 @@ action { } } -# Declare build specific Cloud project. -env_vars: { - key: "BUILD_SPECIFIC_GCLOUD_PROJECT" - value: "ucaip-sample-tests" -} - # Specify which tests to run env_vars: { key: "RUN_TESTS_SESSION" value: "py-3.8" } -# Run tests located under tests/system +# Declare build specific Cloud project. env_vars: { - key: "RUN_SYSTEM_TESTS" - value: "true" + key: "BUILD_SPECIFIC_GCLOUD_PROJECT" + value: "ucaip-sample-tests" } env_vars: { @@ -43,4 +37,4 @@ gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples" gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" # Use the trampoline script to run in docker. -build_file: "python-aiplatform/.kokoro/trampoline.sh" \ No newline at end of file +build_file: "python-aiplatform/.kokoro/trampoline_v2.sh" \ No newline at end of file diff --git a/.kokoro/samples/python3.8/periodic-head.cfg b/.kokoro/samples/python3.8/periodic-head.cfg new file mode 100644 index 0000000000..88d5235e34 --- /dev/null +++ b/.kokoro/samples/python3.8/periodic-head.cfg @@ -0,0 +1,11 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +env_vars: { + key: "INSTALL_LIBRARY_FROM_SOURCE" + value: "True" +} + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/python-aiplatform/.kokoro/test-samples-against-head.sh" +} diff --git a/.kokoro/samples/python3.8/periodic.cfg b/.kokoro/samples/python3.8/periodic.cfg index 50fec96497..b196817872 100644 --- a/.kokoro/samples/python3.8/periodic.cfg +++ b/.kokoro/samples/python3.8/periodic.cfg @@ -2,5 +2,5 @@ env_vars: { key: "INSTALL_LIBRARY_FROM_SOURCE" - value: "False" -} \ No newline at end of file + value: "True" +} diff --git a/.kokoro/samples/python3.9/common.cfg b/.kokoro/samples/python3.9/common.cfg new file mode 100644 index 0000000000..5a549c80fc --- /dev/null +++ b/.kokoro/samples/python3.9/common.cfg @@ -0,0 +1,40 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +# Build logs will be here +action { + define_artifacts { + regex: "**/*sponge_log.xml" + } +} + +# Specify which tests to run +env_vars: { + key: "RUN_TESTS_SESSION" + value: "py-3.9" +} + +# Declare build specific Cloud project. +env_vars: { + key: "BUILD_SPECIFIC_GCLOUD_PROJECT" + value: "ucaip-sample-tests" +} + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/python-aiplatform/.kokoro/test-samples.sh" +} + +# Configure the docker image for kokoro-trampoline. +env_vars: { + key: "TRAMPOLINE_IMAGE" + value: "gcr.io/cloud-devrel-kokoro-resources/python-samples-testing-docker" +} + +# Download secrets for samples +gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples" + +# Download trampoline resources. +gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" + +# Use the trampoline script to run in docker. +build_file: "python-aiplatform/.kokoro/trampoline_v2.sh" \ No newline at end of file diff --git a/.kokoro/samples/python3.9/continuous.cfg b/.kokoro/samples/python3.9/continuous.cfg new file mode 100644 index 0000000000..a1c8d9759c --- /dev/null +++ b/.kokoro/samples/python3.9/continuous.cfg @@ -0,0 +1,6 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +env_vars: { + key: "INSTALL_LIBRARY_FROM_SOURCE" + value: "True" +} \ No newline at end of file diff --git a/.kokoro/samples/python3.9/periodic-head.cfg b/.kokoro/samples/python3.9/periodic-head.cfg new file mode 100644 index 0000000000..88d5235e34 --- /dev/null +++ b/.kokoro/samples/python3.9/periodic-head.cfg @@ -0,0 +1,11 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +env_vars: { + key: "INSTALL_LIBRARY_FROM_SOURCE" + value: "True" +} + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/python-aiplatform/.kokoro/test-samples-against-head.sh" +} diff --git a/.kokoro/samples/python3.9/periodic.cfg b/.kokoro/samples/python3.9/periodic.cfg new file mode 100644 index 0000000000..71cd1e597e --- /dev/null +++ b/.kokoro/samples/python3.9/periodic.cfg @@ -0,0 +1,6 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +env_vars: { + key: "INSTALL_LIBRARY_FROM_SOURCE" + value: "False" +} diff --git a/.kokoro/samples/python3.9/presubmit.cfg b/.kokoro/samples/python3.9/presubmit.cfg new file mode 100644 index 0000000000..a1c8d9759c --- /dev/null +++ b/.kokoro/samples/python3.9/presubmit.cfg @@ -0,0 +1,6 @@ +# Format: //devtools/kokoro/config/proto/build.proto + +env_vars: { + key: "INSTALL_LIBRARY_FROM_SOURCE" + value: "True" +} \ No newline at end of file diff --git a/.kokoro/test-samples-against-head.sh b/.kokoro/test-samples-against-head.sh index 8f0597f90d..ba3a707b04 100755 --- a/.kokoro/test-samples-against-head.sh +++ b/.kokoro/test-samples-against-head.sh @@ -23,6 +23,4 @@ set -eo pipefail # Enables `**` to include files nested inside sub-folders shopt -s globstar -cd github/python-aiplatform - exec .kokoro/test-samples-impl.sh diff --git a/.kokoro/test-samples-impl.sh b/.kokoro/test-samples-impl.sh index cf5de74c17..8a324c9c7b 100755 --- a/.kokoro/test-samples-impl.sh +++ b/.kokoro/test-samples-impl.sh @@ -20,9 +20,9 @@ set -eo pipefail # Enables `**` to include files nested inside sub-folders shopt -s globstar -# Exit early if samples directory doesn't exist -if [ ! -d "./samples" ]; then - echo "No tests run. `./samples` not found" +# Exit early if samples don't exist +if ! find samples -name 'requirements.txt' | grep -q .; then + echo "No tests run. './samples/**/requirements.txt' not found" exit 0 fi @@ -80,7 +80,7 @@ for file in samples/**/requirements.txt; do EXIT=$? # If this is a periodic build, send the test log to the FlakyBot. - # See https://github.com/googleapis/repo-automation-bots/tree/master/packages/flakybot. + # See https://github.com/googleapis/repo-automation-bots/tree/main/packages/flakybot. if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"periodic"* ]]; then chmod +x $KOKORO_GFILE_DIR/linux_amd64/flakybot $KOKORO_GFILE_DIR/linux_amd64/flakybot diff --git a/.kokoro/test-samples.sh b/.kokoro/test-samples.sh index 6bb4d5c30b..11c042d342 100755 --- a/.kokoro/test-samples.sh +++ b/.kokoro/test-samples.sh @@ -24,8 +24,6 @@ set -eo pipefail # Enables `**` to include files nested inside sub-folders shopt -s globstar -cd github/python-aiplatform - # Run periodic samples tests at latest release if [[ $KOKORO_BUILD_ARTIFACTS_SUBDIR = *"periodic"* ]]; then # preserving the test runner implementation. diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4f00c7cffc..46d237160f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -16,13 +16,13 @@ # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v3.4.0 + rev: v4.0.1 hooks: - id: trailing-whitespace - id: end-of-file-fixer - id: check-yaml - repo: https://github.com/psf/black - rev: 19.10b0 + rev: 22.3.0 hooks: - id: black - repo: https://gitlab.com/pycqa/flake8 diff --git a/.repo-metadata.json b/.repo-metadata.json index 46b1493222..d207a35896 100644 --- a/.repo-metadata.json +++ b/.repo-metadata.json @@ -2,12 +2,13 @@ "name": "aiplatform", "name_pretty": "AI Platform", "product_documentation": "https://cloud.google.com/ai-platform", - "client_documentation": "https://googleapis.dev/python/aiplatform/latest", + "client_documentation": "https://cloud.google.com/python/docs/reference/aiplatform/latest", "issue_tracker": "https://issuetracker.google.com/savedsearches/559744", - "release_level": "ga", + "release_level": "stable", "language": "python", "library_type": "GAPIC_COMBO", "repo": "googleapis/python-aiplatform", "distribution_name": "google-cloud-aiplatform", - "api_id": "aiplatform.googleapis.com" -} \ No newline at end of file + "api_id": "aiplatform.googleapis.com", + "api_shortname": "aiplatform" +} diff --git a/.sample_configs/param_handlers/create_batch_prediction_job_tabular_forecasting_sample.py b/.sample_configs/param_handlers/create_batch_prediction_job_tabular_forecasting_sample.py index d03f13dff1..fab2aafc8c 100644 --- a/.sample_configs/param_handlers/create_batch_prediction_job_tabular_forecasting_sample.py +++ b/.sample_configs/param_handlers/create_batch_prediction_job_tabular_forecasting_sample.py @@ -1,3 +1,18 @@ +# Copyright 2022 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. +# + def make_parent(parent: str) -> str: parent = parent diff --git a/.sample_configs/process_configs.yaml b/.sample_configs/process_configs.yaml index 4e6608b4fd..91c8b61c8f 100644 --- a/.sample_configs/process_configs.yaml +++ b/.sample_configs/process_configs.yaml @@ -266,7 +266,7 @@ predict_image_classification_sample: instance_dict: predict.instance.ImageClassificationPredictionInstance parameters_dict: predict.params.ImageClassificationPredictionParams comments: - predictions: See gs://google-cloud-aiplatform/schema/predict/prediction/classification.yaml + predictions: See gs://google-cloud-aiplatform/schema/predict/prediction/image_classification_1.0.0.yaml for the format of the predictions. predict_image_file_sample: max_depth: 1 @@ -278,7 +278,7 @@ predict_image_object_detection_sample: instance_dict: predict.instance.ImageObjectDetectionPredictionInstance parameters_dict: predict.params.ImageObjectDetectionPredictionParams comments: - predictions: See gs://google-cloud-aiplatform/schema/predict/prediction/image_object_detection.yaml + predictions: See gs://google-cloud-aiplatform/schema/predict/prediction/image_object_detection_1.0.0.yaml for the format of the predictions. predict_sample: max_depth: 1 @@ -290,30 +290,27 @@ predict_tabular_classification_sample: max_depth: 1 resource_name: endpoint comments: - predictions: See gs://google-cloud-aiplatform/schema/predict/prediction/tables_classification.yaml + predictions: See gs://google-cloud-aiplatform/schema/predict/prediction/tabular_classification_1.0.0.yaml for the format of the predictions. predict_tabular_forecasting_sample: {} predict_tabular_regression_sample: max_depth: 1 resource_name: endpoint comments: - predictions: See gs://google-cloud-aiplatform/schema/predict/prediction/tables_regression.yaml + predictions: See gs://google-cloud-aiplatform/schema/predict/prediction/tabular_regression_1.0.0.yaml for the format of the predictions. predict_text_classification_single_label_sample: max_depth: 1 resource_name: endpoint schema_types: instance_dict: predict.instance.TextClassificationPredictionInstance - comments: - predictions: See gs://google-cloud-aiplatform/schema/predict/prediction/text_classification.yaml - for the format of the predictions. predict_text_entity_extraction_sample: max_depth: 1 resource_name: endpoint schema_types: instance_dict: predict.instance.TextExtractionPredictionInstance comments: - predictions: See gs://google-cloud-aiplatform/schema/predict/prediction/text_extraction.yaml + predictions: See gs://google-cloud-aiplatform/schema/predict/prediction/text_extraction_1.0.0.yaml for the format of the predictions. predict_text_sentiment_analysis_sample: max_depth: 1 @@ -321,7 +318,7 @@ predict_text_sentiment_analysis_sample: schema_types: instance_dict: predict.instance.TextSentimentPredictionInstance comments: - predictions: See gs://google-cloud-aiplatform/schema/predict/prediction/text_sentiment.yaml + predictions: See gs://google-cloud-aiplatform/schema/predict/prediction/text_sentiment_1.0.0.yaml for the format of the predictions. search_migratable_resources_sample: {} undeploy_model_sample: diff --git a/.trampolinerc b/.trampolinerc index 383b6ec89f..0eee72ab62 100644 --- a/.trampolinerc +++ b/.trampolinerc @@ -16,15 +16,26 @@ # Add required env vars here. required_envvars+=( - "STAGING_BUCKET" - "V2_STAGING_BUCKET" ) # Add env vars which are passed down into the container here. pass_down_envvars+=( + "NOX_SESSION" + ############### + # Docs builds + ############### "STAGING_BUCKET" "V2_STAGING_BUCKET" - "NOX_SESSION" + ################## + # Samples builds + ################## + "INSTALL_LIBRARY_FROM_SOURCE" + "RUN_TESTS_SESSION" + "BUILD_SPECIFIC_GCLOUD_PROJECT" + # Target directories. + "RUN_TESTS_DIRS" + # The nox session to run. + "RUN_TESTS_SESSION" ) # Prevent unintentional override on the default image. diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fa4409fd9..f4c8f96d1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,612 @@ # Changelog -### [1.0.1](https://www.github.com/googleapis/python-aiplatform/compare/v1.0.0...v1.0.1) (2021-05-21) +## [1.14.0](https://github.com/googleapis/python-aiplatform/compare/v1.13.1...v1.14.0) (2022-06-08) + + +### Features + +* add a way to easily clone a PipelineJob ([#1239](https://github.com/googleapis/python-aiplatform/issues/1239)) ([efaf6ed](https://github.com/googleapis/python-aiplatform/commit/efaf6edc36262b095aa13d0b40348c20e39b3fc6)) +* add display_name and metadata to ModelEvaluation in aiplatform model_evaluation.proto ([b6bf6dc](https://github.com/googleapis/python-aiplatform/commit/b6bf6dc643274220e6eeca6479b5f9df61b11d16)) +* add Examples to Explanation related messages in aiplatform v1beta1 explanation.proto ([b6bf6dc](https://github.com/googleapis/python-aiplatform/commit/b6bf6dc643274220e6eeca6479b5f9df61b11d16)) +* Add hierarchy and window configs to Vertex Forecasting training job ([#1255](https://github.com/googleapis/python-aiplatform/issues/1255)) ([8560fa8](https://github.com/googleapis/python-aiplatform/commit/8560fa88c8e0fe51f2ae56f68be575e85db3696a)) +* add holiday regions for vertex forecasting ([#1253](https://github.com/googleapis/python-aiplatform/issues/1253)) ([0036ab0](https://github.com/googleapis/python-aiplatform/commit/0036ab07004e0c9ae7806c4c2c25f22d5af4a978)) +* add IAM policy to aiplatform_v1beta1.yaml ([b6bf6dc](https://github.com/googleapis/python-aiplatform/commit/b6bf6dc643274220e6eeca6479b5f9df61b11d16)) +* add latent_space_source to ExplanationMetadata in aiplatform v1 explanation_metadata.proto ([b6bf6dc](https://github.com/googleapis/python-aiplatform/commit/b6bf6dc643274220e6eeca6479b5f9df61b11d16)) +* add latent_space_source to ExplanationMetadata in aiplatform v1beta1 explanation_metadata.proto ([b6bf6dc](https://github.com/googleapis/python-aiplatform/commit/b6bf6dc643274220e6eeca6479b5f9df61b11d16)) +* add preset configuration for example-based explanations in aiplatform v1beta1 explanation.proto ([b6bf6dc](https://github.com/googleapis/python-aiplatform/commit/b6bf6dc643274220e6eeca6479b5f9df61b11d16)) +* add scaling to OnlineServingConfig in aiplatform v1 featurestore.proto ([b6bf6dc](https://github.com/googleapis/python-aiplatform/commit/b6bf6dc643274220e6eeca6479b5f9df61b11d16)) +* add seq2seq forecasting training job ([#1196](https://github.com/googleapis/python-aiplatform/issues/1196)) ([643d335](https://github.com/googleapis/python-aiplatform/commit/643d335693ec57848949ee173401867a1188678b)) +* add successful_forecast_point_count to CompletionStats in completion_stats.proto ([b6bf6dc](https://github.com/googleapis/python-aiplatform/commit/b6bf6dc643274220e6eeca6479b5f9df61b11d16)) +* add template_metadata to PipelineJob in aiplatform v1 pipeline_job.proto ([b6bf6dc](https://github.com/googleapis/python-aiplatform/commit/b6bf6dc643274220e6eeca6479b5f9df61b11d16)) +* Add Vertex Forecasting E2E test. ([#1248](https://github.com/googleapis/python-aiplatform/issues/1248)) ([e82c179](https://github.com/googleapis/python-aiplatform/commit/e82c1792293396045a1032df015a3700fc38609b)) +* Added forecasting snippets and fixed bugs with existing snippets ([#1210](https://github.com/googleapis/python-aiplatform/issues/1210)) ([4e4bff5](https://github.com/googleapis/python-aiplatform/commit/4e4bff5cac3a99e7f55145ab2aee83b20af67060)) + + +### Bug Fixes + +* change endpoint update method to return resource ([#1409](https://github.com/googleapis/python-aiplatform/issues/1409)) ([44e279b](https://github.com/googleapis/python-aiplatform/commit/44e279b15a1b03bf234111333517153ffdbaf696)) +* Changed system test to use list_models() correctly ([#1397](https://github.com/googleapis/python-aiplatform/issues/1397)) ([a3da19a](https://github.com/googleapis/python-aiplatform/commit/a3da19aac6bdd3fa8d218408582205f7241a4b04)) +* Pinned protobuf to prevent issues with pb files. ([#1398](https://github.com/googleapis/python-aiplatform/issues/1398)) ([7a54637](https://github.com/googleapis/python-aiplatform/commit/7a54637d9b0e7a52ec4648505a6902610c4cc5b7)) + + +### Documentation + +* fix changelog header to consistent size ([#1404](https://github.com/googleapis/python-aiplatform/issues/1404)) ([f6a7e6f](https://github.com/googleapis/python-aiplatform/commit/f6a7e6f35188d6032fc8b34a3c205b0632029e02)) + +## [1.13.1](https://github.com/googleapis/python-aiplatform/compare/v1.13.0...v1.13.1) (2022-05-26) + + +### Features + +* add batch_size kwarg for batch prediction jobs ([#1194](https://github.com/googleapis/python-aiplatform/issues/1194)) ([50bdb01](https://github.com/googleapis/python-aiplatform/commit/50bdb01504740ed31de788d8a160f3e2be7f55df)) +* add update endpoint ([#1162](https://github.com/googleapis/python-aiplatform/issues/1162)) ([0ecfe1e](https://github.com/googleapis/python-aiplatform/commit/0ecfe1e7ab8687c13cb4267985e8b6ebc7bd2534)) +* support autoscaling metrics when deploying models ([#1197](https://github.com/googleapis/python-aiplatform/issues/1197)) ([095717c](https://github.com/googleapis/python-aiplatform/commit/095717c8b77dc5d66e677413a437ea6ed92e0b1a)) + + +### Bug Fixes + +* check in service proto file ([#1174](https://github.com/googleapis/python-aiplatform/issues/1174)) ([5fdf151](https://github.com/googleapis/python-aiplatform/commit/5fdf151ee0d0a630c07a75dc8f19906e7ad1aa8a)) +* regenerate pb2 files using grpcio-tools ([#1394](https://github.com/googleapis/python-aiplatform/issues/1394)) ([406c868](https://github.com/googleapis/python-aiplatform/commit/406c868344280d424f4191c98bcbbdeaf947b2d1)) + + +### Documentation + +* update aiplatform SDK arrangement for Sphinx ([#1163](https://github.com/googleapis/python-aiplatform/issues/1163)) ([e9510ea](https://github.com/googleapis/python-aiplatform/commit/e9510ea6344a296e0c93ddf32280cf4c010ee4f1)) + + +### Miscellaneous Chores + +* release 1.13.1 ([#1395](https://github.com/googleapis/python-aiplatform/issues/1395)) ([df78407](https://github.com/googleapis/python-aiplatform/commit/df78407b2f14c95c9e84b4b1375a8de5bc9c7bb5)) + +## [1.13.0](https://github.com/googleapis/python-aiplatform/compare/v1.12.1...v1.13.0) (2022-05-09) + + +### Features + +* add ConvexAutomatedStoppingSpec to StudySpec in aiplatform v1 study.proto ([847ad78](https://github.com/googleapis/python-aiplatform/commit/847ad789e09aec14238a7476a3fa88729ce24d6f)) +* add ConvexAutomatedStoppingSpec to StudySpec in aiplatform v1beta1 study.proto ([847ad78](https://github.com/googleapis/python-aiplatform/commit/847ad789e09aec14238a7476a3fa88729ce24d6f)) +* add JOB_STATE_UPDATING to JobState in aiplatform v1 job_state.proto ([847ad78](https://github.com/googleapis/python-aiplatform/commit/847ad789e09aec14238a7476a3fa88729ce24d6f)) +* add JOB_STATE_UPDATING to JobState in aiplatform v1beta1 job_state.proto ([847ad78](https://github.com/googleapis/python-aiplatform/commit/847ad789e09aec14238a7476a3fa88729ce24d6f)) +* add LatestMonitoringPipelineMetadata to ModelDeploymentMonitoringJob in aiplatform v1beta1 model_deployment_monitoring_job.proto ([847ad78](https://github.com/googleapis/python-aiplatform/commit/847ad789e09aec14238a7476a3fa88729ce24d6f)) +* add ListModelVersion, DeleteModelVersion, and MergeVersionAliases rpcs to aiplatform v1beta1 model_service.proto ([847ad78](https://github.com/googleapis/python-aiplatform/commit/847ad789e09aec14238a7476a3fa88729ce24d6f)) +* add MfsMount in aiplatform v1 machine_resources.proto ([847ad78](https://github.com/googleapis/python-aiplatform/commit/847ad789e09aec14238a7476a3fa88729ce24d6f)) +* add MfsMount in aiplatform v1beta1 machine_resources.proto ([847ad78](https://github.com/googleapis/python-aiplatform/commit/847ad789e09aec14238a7476a3fa88729ce24d6f)) +* add model_id and parent_model to TrainingPipeline in aiplatform v1beta1 training_pipeline.proto ([847ad78](https://github.com/googleapis/python-aiplatform/commit/847ad789e09aec14238a7476a3fa88729ce24d6f)) +* add model_version_id to DeployedModel in aiplatform v1beta1 endpoint.proto ([847ad78](https://github.com/googleapis/python-aiplatform/commit/847ad789e09aec14238a7476a3fa88729ce24d6f)) +* add model_version_id to PredictResponse in aiplatform v1beta1 prediction_service.proto ([847ad78](https://github.com/googleapis/python-aiplatform/commit/847ad789e09aec14238a7476a3fa88729ce24d6f)) +* add model_version_id to UploadModelRequest and UploadModelResponse in aiplatform v1beta1 model_service.proto ([847ad78](https://github.com/googleapis/python-aiplatform/commit/847ad789e09aec14238a7476a3fa88729ce24d6f)) +* add nfs_mounts to WorkPoolSpec in aiplatform v1 custom_job.proto ([847ad78](https://github.com/googleapis/python-aiplatform/commit/847ad789e09aec14238a7476a3fa88729ce24d6f)) +* add nfs_mounts to WorkPoolSpec in aiplatform v1beta1 custom_job.proto ([847ad78](https://github.com/googleapis/python-aiplatform/commit/847ad789e09aec14238a7476a3fa88729ce24d6f)) +* add Pandas DataFrame support to TabularDataset ([#1185](https://github.com/googleapis/python-aiplatform/issues/1185)) ([4fe4558](https://github.com/googleapis/python-aiplatform/commit/4fe4558ea0aaf73e3c0e9715ae90cb729a4c5678)) +* add PredictRequestResponseLoggingConfig to aiplatform v1beta1 endpoint.proto ([847ad78](https://github.com/googleapis/python-aiplatform/commit/847ad789e09aec14238a7476a3fa88729ce24d6f)) +* add reserved_ip_ranges to CustomJobSpec in aiplatform v1 custom_job.proto ([#1165](https://github.com/googleapis/python-aiplatform/issues/1165)) ([847ad78](https://github.com/googleapis/python-aiplatform/commit/847ad789e09aec14238a7476a3fa88729ce24d6f)) +* add reserved_ip_ranges to CustomJobSpec in aiplatform v1beta1 custom_job.proto ([847ad78](https://github.com/googleapis/python-aiplatform/commit/847ad789e09aec14238a7476a3fa88729ce24d6f)) +* add template_metadata to PipelineJob in aiplatform v1beta1 pipeline_job.proto ([#1186](https://github.com/googleapis/python-aiplatform/issues/1186)) ([99aca4a](https://github.com/googleapis/python-aiplatform/commit/99aca4a9b0deeefd294cfd64fa3e247cc41e006c)) +* add version_id to Model in aiplatform v1beta1 model.proto ([847ad78](https://github.com/googleapis/python-aiplatform/commit/847ad789e09aec14238a7476a3fa88729ce24d6f)) +* allow creating featurestore without online node ([#1180](https://github.com/googleapis/python-aiplatform/issues/1180)) ([3224ae3](https://github.com/googleapis/python-aiplatform/commit/3224ae3402e9493866dd4958d011a431968b9c2c)) +* Allow users to specify timestamp split for vertex forecasting ([#1187](https://github.com/googleapis/python-aiplatform/issues/1187)) ([ee49e00](https://github.com/googleapis/python-aiplatform/commit/ee49e004c8fbd0c8c27760b525c6e7431057a45e)) +* Make matching engine API public ([#1192](https://github.com/googleapis/python-aiplatform/issues/1192)) ([469db6b](https://github.com/googleapis/python-aiplatform/commit/469db6b08a9aa7fc64d8ea27f7e2e2fb2e9f643b)) +* rename Similarity to Examples, and similarity to examples in ExplanationParameters in aiplatform v1beta1 explanation.proto ([847ad78](https://github.com/googleapis/python-aiplatform/commit/847ad789e09aec14238a7476a3fa88729ce24d6f)) + + +### Documentation + +* fix type in docstring for map fields ([847ad78](https://github.com/googleapis/python-aiplatform/commit/847ad789e09aec14238a7476a3fa88729ce24d6f)) + +## [1.12.1](https://github.com/googleapis/python-aiplatform/compare/v1.12.0...v1.12.1) (2022-04-20) + + +### Features + +* Add endpoind_id arg to Endpoint#create ([#1168](https://github.com/googleapis/python-aiplatform/issues/1168)) ([4c21993](https://github.com/googleapis/python-aiplatform/commit/4c21993642b84d7595ead7a63424260deafaf43c)) +* add ModelEvaluation support ([#1167](https://github.com/googleapis/python-aiplatform/issues/1167)) ([10f95cd](https://github.com/googleapis/python-aiplatform/commit/10f95cde5e0282a99041ff2108111970f52379f3)) + + +### Bug Fixes + +* change default for create_request_timeout arg to None ([#1175](https://github.com/googleapis/python-aiplatform/issues/1175)) ([47791f7](https://github.com/googleapis/python-aiplatform/commit/47791f79c56a67be7503b5d5d4eb72dc409b18a0)) + + +### Documentation + +* endpoint.create => aiplatform.Endpoint.create ([#1153](https://github.com/googleapis/python-aiplatform/issues/1153)) ([1122a26](https://github.com/googleapis/python-aiplatform/commit/1122a26fd01d4c964055ca85a683de0c91867b6f)) +* update changelog headers ([#1164](https://github.com/googleapis/python-aiplatform/issues/1164)) ([c1e899d](https://github.com/googleapis/python-aiplatform/commit/c1e899dba3f57e515b1f1958e962f355276460c4)) +* update model code snippet order in README ([#1154](https://github.com/googleapis/python-aiplatform/issues/1154)) ([404d7f1](https://github.com/googleapis/python-aiplatform/commit/404d7f13d8666ea673743ab54928046eb64ee542)) + + +### Miscellaneous Chores + +* release 1.12.1 ([#1176](https://github.com/googleapis/python-aiplatform/issues/1176)) ([f98d92e](https://github.com/googleapis/python-aiplatform/commit/f98d92ecf7ad42fdbb095e65f98800bc6b2d3d12)) + +## [1.12.0](https://github.com/googleapis/python-aiplatform/compare/v1.11.0...v1.12.0) (2022-04-07) + + +### Features + +* add categorical_threshold_config to FeaturestoreMonitoringConfig in aiplatform v1 featurestore_monitoring.proto ([38f3711](https://github.com/googleapis/python-aiplatform/commit/38f3711bd76bbcfe4ce48739bb11049e2711d47f)) +* add categorical_threshold_config to FeaturestoreMonitoringConfig in aiplatform v1beta1 featurestore_monitoring.proto ([38f3711](https://github.com/googleapis/python-aiplatform/commit/38f3711bd76bbcfe4ce48739bb11049e2711d47f)) +* add disable_monitoring to Feature in aiplatform v1 feature.proto ([38f3711](https://github.com/googleapis/python-aiplatform/commit/38f3711bd76bbcfe4ce48739bb11049e2711d47f)) +* add disable_monitoring to Feature in aiplatform v1beta1 feature.proto ([38f3711](https://github.com/googleapis/python-aiplatform/commit/38f3711bd76bbcfe4ce48739bb11049e2711d47f)) +* Add done method for pipeline, training, and batch prediction jobs ([#1062](https://github.com/googleapis/python-aiplatform/issues/1062)) ([f3338fc](https://github.com/googleapis/python-aiplatform/commit/f3338fcd4f51072ee86b765ee580cfe3c4b222ce)) +* add import_features_analysis to FeaturestoreMonitoringConfig in aiplatform v1 featurestore_monitoring.proto ([38f3711](https://github.com/googleapis/python-aiplatform/commit/38f3711bd76bbcfe4ce48739bb11049e2711d47f)) +* add import_features_analysis to FeaturestoreMonitoringConfig in aiplatform v1beta1 featurestore_monitoring.proto ([38f3711](https://github.com/googleapis/python-aiplatform/commit/38f3711bd76bbcfe4ce48739bb11049e2711d47f)) +* add ImportModelEvaluation in aiplatform v1 model_service.proto ([#1105](https://github.com/googleapis/python-aiplatform/issues/1105)) ([ef5930c](https://github.com/googleapis/python-aiplatform/commit/ef5930c58838ce51f92ef1acb941f5141c83faad)) +* add monitoring_config to EntityType in aiplatform v1 entity_type.proto ([#1077](https://github.com/googleapis/python-aiplatform/issues/1077)) ([38f3711](https://github.com/googleapis/python-aiplatform/commit/38f3711bd76bbcfe4ce48739bb11049e2711d47f)) +* add monitoring_stats_anomalies to Feature in aiplatform v1 feature.proto ([38f3711](https://github.com/googleapis/python-aiplatform/commit/38f3711bd76bbcfe4ce48739bb11049e2711d47f)) +* add monitoring_stats_anomalies to Feature in aiplatform v1beta1 feature.proto ([38f3711](https://github.com/googleapis/python-aiplatform/commit/38f3711bd76bbcfe4ce48739bb11049e2711d47f)) +* add numerical_threshold_config to FeaturestoreMonitoringConfig in aiplatform v1 featurestore_monitoring.proto ([38f3711](https://github.com/googleapis/python-aiplatform/commit/38f3711bd76bbcfe4ce48739bb11049e2711d47f)) +* add numerical_threshold_config to FeaturestoreMonitoringConfig in aiplatform v1beta1 featurestore_monitoring.proto ([38f3711](https://github.com/googleapis/python-aiplatform/commit/38f3711bd76bbcfe4ce48739bb11049e2711d47f)) +* add objective to MonitoringStatsSpec in aiplatform v1 featurestore_service.proto ([38f3711](https://github.com/googleapis/python-aiplatform/commit/38f3711bd76bbcfe4ce48739bb11049e2711d47f)) +* add objective to MonitoringStatsSpec in aiplatform v1beta1 featurestore_service.proto ([38f3711](https://github.com/googleapis/python-aiplatform/commit/38f3711bd76bbcfe4ce48739bb11049e2711d47f)) +* add PredictRequestResponseLoggingConfig to Endpoint in aiplatform v1 endpoint.proto ([#1072](https://github.com/googleapis/python-aiplatform/issues/1072)) ([be0ccc4](https://github.com/googleapis/python-aiplatform/commit/be0ccc488dac22128be317ca40337d6b93af0906)) +* add staleness_days to SnapshotAnalysis in aiplatform v1 featurestore_monitoring.proto ([38f3711](https://github.com/googleapis/python-aiplatform/commit/38f3711bd76bbcfe4ce48739bb11049e2711d47f)) +* add staleness_days to SnapshotAnalysis in aiplatform v1beta1 featurestore_monitoring.proto ([38f3711](https://github.com/googleapis/python-aiplatform/commit/38f3711bd76bbcfe4ce48739bb11049e2711d47f)) +* Add support for Vertex Tables Q1 regions ([#1065](https://github.com/googleapis/python-aiplatform/issues/1065)) ([6383d4f](https://github.com/googleapis/python-aiplatform/commit/6383d4f20f1ab0a7634c1028cb9f270e91c31d2a)) +* add timeout arg across SDK ([#1099](https://github.com/googleapis/python-aiplatform/issues/1099)) ([184f7f3](https://github.com/googleapis/python-aiplatform/commit/184f7f327aa00b4c8d1acc24dcb1c4c4be6c5bcc)) +* Add timeout arguments to Endpoint.predict and Endpoint.explain ([#1094](https://github.com/googleapis/python-aiplatform/issues/1094)) ([cc59e60](https://github.com/googleapis/python-aiplatform/commit/cc59e60193a72bb57d699cabea03ab7bdd386b0e)) +* Made display_name parameter optional for most calls ([#882](https://github.com/googleapis/python-aiplatform/issues/882)) ([400b760](https://github.com/googleapis/python-aiplatform/commit/400b7608afeaca9a36936cabd402c5322eb9345b)) +* **sdk:** enable loading both JSON and YAML pipelines IR ([#1089](https://github.com/googleapis/python-aiplatform/issues/1089)) ([f2e70b1](https://github.com/googleapis/python-aiplatform/commit/f2e70b1563171b5a92a2c40edf29ae373bbeb175)) +* **v1beta1:** add `service_account` to `BatchPredictionJob` in `batch_prediction_job.proto` ([#1084](https://github.com/googleapis/python-aiplatform/issues/1084)) ([b7a5177](https://github.com/googleapis/python-aiplatform/commit/b7a517731bc8127d4186838bfb88fa883b2be853)) + + +### Bug Fixes + +* add resource manager utils to get project ID from project number ([#1068](https://github.com/googleapis/python-aiplatform/issues/1068)) ([f10a1d4](https://github.com/googleapis/python-aiplatform/commit/f10a1d4280c3e653c9f4795f0423bf07a23acdf9)) +* add self.wait() in operations after optional_sync supported resource creation ([#1083](https://github.com/googleapis/python-aiplatform/issues/1083)) ([79aeec1](https://github.com/googleapis/python-aiplatform/commit/79aeec1380068318398851b2a7b2fd6ddee7fa8b)) +* Don't throw exception when getting representation of unrun GCA objects ([#1071](https://github.com/googleapis/python-aiplatform/issues/1071)) ([c9ba060](https://github.com/googleapis/python-aiplatform/commit/c9ba0603e6a8e3d772af67367242aad7a18e03c8)) +* Fix import error string showing wrong pip install path ([#1076](https://github.com/googleapis/python-aiplatform/issues/1076)) ([74ffa19](https://github.com/googleapis/python-aiplatform/commit/74ffa19e7d540f6bb5f21d2335c2a5d23cc49ee2)) +* Fixed getting project ID when running on Vertex AI; Fixes [#852](https://github.com/googleapis/python-aiplatform/issues/852) ([#943](https://github.com/googleapis/python-aiplatform/issues/943)) ([876cb33](https://github.com/googleapis/python-aiplatform/commit/876cb33a407cfea5c965e4f348056b147b1d16c3)) +* Give aiplatform logging its own log namespace, let the user configure their own root logger ([#1081](https://github.com/googleapis/python-aiplatform/issues/1081)) ([fb78243](https://github.com/googleapis/python-aiplatform/commit/fb782434d456f41c6c6bd6664b203cebb53131b8)) +* Honoring the model's supported_deployment_resources_types ([#865](https://github.com/googleapis/python-aiplatform/issues/865)) ([db34b85](https://github.com/googleapis/python-aiplatform/commit/db34b85aaf211ca491313d2b8ae2a45253109614)) +* missing reference to logged_web_access_uris ([#1056](https://github.com/googleapis/python-aiplatform/issues/1056)) ([198a1b5](https://github.com/googleapis/python-aiplatform/commit/198a1b5753f509c9137a8d9e9b56d68e6e386563)) +* system tests failure from test_upload_and_deploy_xgboost_model ([#1149](https://github.com/googleapis/python-aiplatform/issues/1149)) ([c8422a9](https://github.com/googleapis/python-aiplatform/commit/c8422a9b807e092f2d48e7f3fa8b40c8724cc028)) + + +### Documentation + +* fix CustomContainerTrainingJob example in docstring ([#1101](https://github.com/googleapis/python-aiplatform/issues/1101)) ([d2fb9db](https://github.com/googleapis/python-aiplatform/commit/d2fb9db095d1acb15894df3d0a5e66128ce8f14e)) +* improve bigquery_destination_prefix docstring ([#1098](https://github.com/googleapis/python-aiplatform/issues/1098)) ([a46df64](https://github.com/googleapis/python-aiplatform/commit/a46df64ab99aee8d7e47b44394a234243dc2a0f8)) +* Include time dependency in documentation for weight, time, and target columns. ([#1102](https://github.com/googleapis/python-aiplatform/issues/1102)) ([52273c2](https://github.com/googleapis/python-aiplatform/commit/52273c2108c9bb24eadab214036f2ef93b847321)) +* **samples:** read, import, batch_serve, batch_create features ([#1046](https://github.com/googleapis/python-aiplatform/issues/1046)) ([80dd40d](https://github.com/googleapis/python-aiplatform/commit/80dd40dcb830ece3b5442d60834357ada6583204)) +* Update AutoML Video docstring ([#987](https://github.com/googleapis/python-aiplatform/issues/987)) ([6002d5d](https://github.com/googleapis/python-aiplatform/commit/6002d5d9bf24542f9f3f844e469bc3f8ad9636ec)) + +## [1.11.0](https://github.com/googleapis/python-aiplatform/compare/v1.10.0...v1.11.0) (2022-03-03) + + +### Features + +* add additional_experiement flag in the tables and forecasting training job ([#979](https://github.com/googleapis/python-aiplatform/issues/979)) ([5fe59a4](https://github.com/googleapis/python-aiplatform/commit/5fe59a4015882d56c22f9973aff888966dd53a2e)) +* add TPU_V2 & TPU_V3 values to AcceleratorType in aiplatform v1/v1beta1 accelerator_type.proto ([#1010](https://github.com/googleapis/python-aiplatform/issues/1010)) ([09c2e8a](https://github.com/googleapis/python-aiplatform/commit/09c2e8a368c6d265d99acfb12addd5ba6f1a50e6)) +* Added scheduling to CustomTrainingJob, CustomPythonPackageTrainingJob, CustomContainerTrainingJob ([#970](https://github.com/googleapis/python-aiplatform/issues/970)) ([89078e0](https://github.com/googleapis/python-aiplatform/commit/89078e0d2a719e2b0d25ae36ecd06c356a5a33c9)) + + +### Bug Fixes + +* **deps:** allow google-cloud-storage < 3.0.0dev ([#1008](https://github.com/googleapis/python-aiplatform/issues/1008)) ([1c34154](https://github.com/googleapis/python-aiplatform/commit/1c341544e9bd94c6ff0ee41177565c8c078673a3)) +* **deps:** require google-api-core>=1.31.5, >=2.3.2 ([#1050](https://github.com/googleapis/python-aiplatform/issues/1050)) ([dfbd68a](https://github.com/googleapis/python-aiplatform/commit/dfbd68a79f1c892c4380405dd900deb6ac6574a6)) +* **deps:** require proto-plus>=1.15.0 ([dfbd68a](https://github.com/googleapis/python-aiplatform/commit/dfbd68a79f1c892c4380405dd900deb6ac6574a6)) +* enforce bq SchemaField field_type and mode using feature value_type ([#1019](https://github.com/googleapis/python-aiplatform/issues/1019)) ([095bea2](https://github.com/googleapis/python-aiplatform/commit/095bea23bc15a490ddbb1a8edac7f5db626bc659)) +* Fix create_lit_model_from_endpoint not accepting models that don't return a dictionary. ([#1020](https://github.com/googleapis/python-aiplatform/issues/1020)) ([b9a057d](https://github.com/googleapis/python-aiplatform/commit/b9a057d001deb8727cb725d44bb5528dce330653)) +* loosen assertions for system test featurestore ([#1040](https://github.com/googleapis/python-aiplatform/issues/1040)) ([2ba404f](https://github.com/googleapis/python-aiplatform/commit/2ba404f8bfbccd7a18ef613417912ed94882c4bd)) +* remove empty scripts kwarg in setup.py ([#1014](https://github.com/googleapis/python-aiplatform/issues/1014)) ([ef3fcc8](https://github.com/googleapis/python-aiplatform/commit/ef3fcc86fb3808b37706470c8c49903ec3a302fb)) +* show logs when TFX pipelines are submitted ([#976](https://github.com/googleapis/python-aiplatform/issues/976)) ([c10923b](https://github.com/googleapis/python-aiplatform/commit/c10923b47b9b9941d14ae2c5398348d971a23f9d)) +* update system test_model_upload to use BUILD_SPECIFIC_GCP_PROJECT ([#1043](https://github.com/googleapis/python-aiplatform/issues/1043)) ([e7d2719](https://github.com/googleapis/python-aiplatform/commit/e7d27193f323f88f4238206ecb380d746d98df31)) + + +### Documentation + +* **samples:** add samples to create/delete featurestore ([#980](https://github.com/googleapis/python-aiplatform/issues/980)) ([5ee6354](https://github.com/googleapis/python-aiplatform/commit/5ee6354a12c6422015acb81caef32d6d2f52c838)) +* **samples:** added create feature and create entity type samples and tests ([#984](https://github.com/googleapis/python-aiplatform/issues/984)) ([d221e6b](https://github.com/googleapis/python-aiplatform/commit/d221e6bebd7fb98a8c6e3f3b8ae507f2f214128f)) + +## [1.10.0](https://github.com/googleapis/python-aiplatform/compare/v1.9.0...v1.10.0) (2022-02-07) + + +### Features + +* _TrainingScriptPythonPackager to support folders ([#812](https://github.com/googleapis/python-aiplatform/issues/812)) ([3aec6a7](https://github.com/googleapis/python-aiplatform/commit/3aec6a7b8f26ef2a5b378a6224d6402e3b42c917)) +* add dedicated_resources to DeployedIndex in aiplatform v1beta1 index_endpoint.proto feat: add Scaling to OnlineServingConfig in aiplatform v1beta1 featurestore.proto chore: sort imports ([#991](https://github.com/googleapis/python-aiplatform/issues/991)) ([7a7f0d4](https://github.com/googleapis/python-aiplatform/commit/7a7f0d45f3d08c93b11fcd2c5a265a8db4b0c890)) +* add dedicated_resources to DeployedIndex message in aiplatform v1 index_endpoint.proto chore: sort imports ([#990](https://github.com/googleapis/python-aiplatform/issues/990)) ([a814923](https://github.com/googleapis/python-aiplatform/commit/a8149233bcd857e75700c6ec7d29c0aabf1687c1)) +* Add XAI SDK integration to TensorFlow models with LIT integration ([#917](https://github.com/googleapis/python-aiplatform/issues/917)) ([ea2b5cf](https://github.com/googleapis/python-aiplatform/commit/ea2b5cfbcafead1c63009fda10bd44a00d560efb)) +* Added `aiplatform.Model.update` method ([#952](https://github.com/googleapis/python-aiplatform/issues/952)) ([44e208a](https://github.com/googleapis/python-aiplatform/commit/44e208a8dbf082e770373d58c31b3ad3e8b39f4f)) +* Enable europe-west6 and northamerica-northeast2 regions ([0f6b670](https://github.com/googleapis/python-aiplatform/commit/0f6b6701e96fb0ec345e81560d03059a7900160f)) +* enable feature store batch serve to BigQuery and GCS for csv and tfrecord ([#919](https://github.com/googleapis/python-aiplatform/issues/919)) ([c840728](https://github.com/googleapis/python-aiplatform/commit/c840728e503eea3300e9629405978e28c6aafec7)) +* enable feature store batch serve to Pandas DataFrame; fix: read instances uri for batch serve ([#983](https://github.com/googleapis/python-aiplatform/issues/983)) ([e0fec36](https://github.com/googleapis/python-aiplatform/commit/e0fec36686e373c13acca3203372572c760c7af4)) +* enable feature store online serving ([#918](https://github.com/googleapis/python-aiplatform/issues/918)) ([b8f5f82](https://github.com/googleapis/python-aiplatform/commit/b8f5f82ae43edfb933305a074c315e2f3239b4b1)) +* enable ingest from pd.DataFrame ([#977](https://github.com/googleapis/python-aiplatform/issues/977)) ([9289f2d](https://github.com/googleapis/python-aiplatform/commit/9289f2d3ce424f3f9754a3dd23883e25dec1300f)) +* Open LIT with a deployed model ([#963](https://github.com/googleapis/python-aiplatform/issues/963)) ([ea16849](https://github.com/googleapis/python-aiplatform/commit/ea16849f936d7a2e8402fd235decefe5972685ed)) + + +### Bug Fixes + +* Fixed BigQuery datasets that have colon in URI ([#855](https://github.com/googleapis/python-aiplatform/issues/855)) ([153578f](https://github.com/googleapis/python-aiplatform/commit/153578f19d57db96e3674b2d797c5352c107f936)) +* Fixed integration test for model.upload ([#975](https://github.com/googleapis/python-aiplatform/issues/975)) ([0ca3747](https://github.com/googleapis/python-aiplatform/commit/0ca374769f922fd427c5b6f58c9ce1ab40f18d18)) +* rename teardown fixture ([#1004](https://github.com/googleapis/python-aiplatform/issues/1004)) ([fcd0096](https://github.com/googleapis/python-aiplatform/commit/fcd00969dbbbf06887dfdbaa6bc65b135c24f95f)) + + +### Documentation + +* **samples:** replace deprecated fields in create_training_pipeline_tabular_forecasting_sample.py ([#981](https://github.com/googleapis/python-aiplatform/issues/981)) ([9ebc972](https://github.com/googleapis/python-aiplatform/commit/9ebc972bba972b1e1920db422ed28a721e90329d)) + +## [1.9.0](https://www.github.com/googleapis/python-aiplatform/compare/v1.8.1...v1.9.0) (2021-12-29) + + +### Features + +* add create in Featurestore, EntityType, Feature; add create_entity_type in Featurestore; add create_feature, batch_create_features in EntityType; add ingest_from_* for bq and gcs in EntityType; add and update delete with force delete nested resources ([#872](https://www.github.com/googleapis/python-aiplatform/issues/872)) ([ba11c3d](https://www.github.com/googleapis/python-aiplatform/commit/ba11c3d3cd8d3869e2deb3207a8698fa7ce284ec)) +* Add LIT methods for Pandas DataFrame and TensorFlow saved model. ([#874](https://www.github.com/googleapis/python-aiplatform/issues/874)) ([03cf301](https://www.github.com/googleapis/python-aiplatform/commit/03cf301989a5802b122803eac7a2d03f2d1769fb)) +* Add support to create TensorboardExperiment ([#909](https://www.github.com/googleapis/python-aiplatform/issues/909)) ([96ce738](https://www.github.com/googleapis/python-aiplatform/commit/96ce7387ac58e0ec7cb6a7f6d6a6e422eae5da96)) +* Add support to create TensorboardRun ([#912](https://www.github.com/googleapis/python-aiplatform/issues/912)) ([8df74a2](https://www.github.com/googleapis/python-aiplatform/commit/8df74a29df0adb95fff5500fcc9d7a025012ab5e)) + + +### Bug Fixes + +* Fix timestamp proto util to default to timestamp at call time. ([#933](https://www.github.com/googleapis/python-aiplatform/issues/933)) ([d72a254](https://www.github.com/googleapis/python-aiplatform/commit/d72a254e97cf74f3fdd55a32a4af86737243593a)) +* Improve handling of undeploying model without redistributing remaining traffic ([#898](https://www.github.com/googleapis/python-aiplatform/issues/898)) ([8a8a4fa](https://www.github.com/googleapis/python-aiplatform/commit/8a8a4faa667bde2a4df04afa23a6dd5b1856f958)) +* issues/192254729 ([#914](https://www.github.com/googleapis/python-aiplatform/issues/914)) ([3ec620c](https://www.github.com/googleapis/python-aiplatform/commit/3ec620c64bd60ceb5b89918200e11e3fbff67370)) +* issues/192254729 ([#915](https://www.github.com/googleapis/python-aiplatform/issues/915)) ([0f22ff6](https://www.github.com/googleapis/python-aiplatform/commit/0f22ff61460a3f2bd55d2c10c4ee06e582f03944)) +* use open_in_new_tab in the render method. ([#926](https://www.github.com/googleapis/python-aiplatform/issues/926)) ([04618e0](https://www.github.com/googleapis/python-aiplatform/commit/04618e0563b8588eec2ccd8342c6085ca08b5adb)) + +## [1.8.1](https://www.github.com/googleapis/python-aiplatform/compare/v1.8.0...v1.8.1) (2021-12-14) + + +### Bug Fixes + +* add clarity to param model_name ([#888](https://www.github.com/googleapis/python-aiplatform/issues/888)) ([1d81783](https://www.github.com/googleapis/python-aiplatform/commit/1d81783b2f914dd7606ee884ca31c1a594e5135f)) +* add clarity to parameters per user feedback ([#886](https://www.github.com/googleapis/python-aiplatform/issues/886)) ([37ee0a1](https://www.github.com/googleapis/python-aiplatform/commit/37ee0a1dc6e0105e19aca18f44995a352bfc40cb)) +* add param for multi-label per user's feedback ([#887](https://www.github.com/googleapis/python-aiplatform/issues/887)) ([fda942f](https://www.github.com/googleapis/python-aiplatform/commit/fda942ffbe009077b47f36aad1c29603a451e38b)) +* add support for API base path overriding ([#908](https://www.github.com/googleapis/python-aiplatform/issues/908)) ([45c4086](https://www.github.com/googleapis/python-aiplatform/commit/45c4086dd07dd7d3d3b7417196ff61a7107d8a1a)) +* Important the correct constants and use v1 for tensorboard experiments ([#905](https://www.github.com/googleapis/python-aiplatform/issues/905)) ([48c2bf1](https://www.github.com/googleapis/python-aiplatform/commit/48c2bf1ea2fa42afea1b5d419527bfb8e49e0ac0)) +* incorrect uri for IOD yaml ([#889](https://www.github.com/googleapis/python-aiplatform/issues/889)) ([e108ef8](https://www.github.com/googleapis/python-aiplatform/commit/e108ef8250c77c8a8edeccb6b601cbe0b0380c89)) +* Minor docstring and snippet fixes ([#873](https://www.github.com/googleapis/python-aiplatform/issues/873)) ([578e06d](https://www.github.com/googleapis/python-aiplatform/commit/578e06df481c3d60074a7b8e9365f8361b04e32b)) + + +### Documentation + +* Update references to containers and notebook samples. ([#890](https://www.github.com/googleapis/python-aiplatform/issues/890)) ([67fa1f1](https://www.github.com/googleapis/python-aiplatform/commit/67fa1f179af66686339d797e5b368e96816ed1c5)) +* Updated docstrings with exception error classes ([#894](https://www.github.com/googleapis/python-aiplatform/issues/894)) ([f9aecd2](https://www.github.com/googleapis/python-aiplatform/commit/f9aecd22fe08a97e45187b4d11c755ac3b9dfadd)) + +## [1.8.0](https://www.github.com/googleapis/python-aiplatform/compare/v1.7.1...v1.8.0) (2021-12-03) + + +### Features + +* Add cloud profiler to training_utils ([6d5c7c4](https://www.github.com/googleapis/python-aiplatform/commit/6d5c7c42d1c352f161e4738c6dbbf540a032017b)) +* add enable_private_service_connect field to Endpoint feat: add id field to DeployedModel feat: add service_attachment field to PrivateEndpoints feat: add endpoint_id to CreateEndpointRequest and method signature to CreateEndpoint feat: add method... ([#878](https://www.github.com/googleapis/python-aiplatform/issues/878)) ([ca813be](https://www.github.com/googleapis/python-aiplatform/commit/ca813be08ec2620380b5a12b0d6cdc079e27ba79)) +* add enable_private_service_connect field to Endpoint feat: add id field to DeployedModel feat: add service_attachment field to PrivateEndpoints feat: add endpoint_id to CreateEndpointRequest and method signature to CreateEndpoint feat: add method... ([#879](https://www.github.com/googleapis/python-aiplatform/issues/879)) ([47e93b2](https://www.github.com/googleapis/python-aiplatform/commit/47e93b20843f30805b73cd6db214c8743f8bfc97)) +* add featurestore module including Featurestore, EntityType, and Feature classes; add get, update, delete, list methods in all featurestore classes; add search method in Feature class ([#850](https://www.github.com/googleapis/python-aiplatform/issues/850)) ([66745a6](https://www.github.com/googleapis/python-aiplatform/commit/66745a6ce13fb8b32dd7fbf3eb86e71bd291869b)) +* Add prediction container URI builder method ([#805](https://www.github.com/googleapis/python-aiplatform/issues/805)) ([91dd3c0](https://www.github.com/googleapis/python-aiplatform/commit/91dd3c0d5de72fac5b1dc8a9bc23d6cb431061a4)) +* default to custom job display name if experiment name looks like a custom job ID ([#833](https://www.github.com/googleapis/python-aiplatform/issues/833)) ([8b9376e](https://www.github.com/googleapis/python-aiplatform/commit/8b9376e9c961a751799f5b80d1b19917c8c353f8)) +* Support uploading local models ([#779](https://www.github.com/googleapis/python-aiplatform/issues/779)) ([bffbd9d](https://www.github.com/googleapis/python-aiplatform/commit/bffbd9d359edb099e661736a0c77269bb3a0c746)) +* Tensorboard v1 protos release ([#847](https://www.github.com/googleapis/python-aiplatform/issues/847)) ([e0fc3d9](https://www.github.com/googleapis/python-aiplatform/commit/e0fc3d9e4e8a7911f21671ea49818c5f84798d12)) +* updating Tensorboard related code to use v1 ([#851](https://www.github.com/googleapis/python-aiplatform/issues/851)) ([b613b26](https://www.github.com/googleapis/python-aiplatform/commit/b613b264524aaab2cb65e63a5487770736faa7c8)) +* Upgrade Tensorboard from v1beta1 to v1 ([#849](https://www.github.com/googleapis/python-aiplatform/issues/849)) ([c40ec85](https://www.github.com/googleapis/python-aiplatform/commit/c40ec85e1fca2bee6813f52712d063f96264ec2c)) + + +### Bug Fixes + +* Import error for cloud_profiler ([#869](https://www.github.com/googleapis/python-aiplatform/issues/869)) ([0f124e9](https://www.github.com/googleapis/python-aiplatform/commit/0f124e93a1ddead16c0018970f34e45c73d5ed81)) +* Support multiple instances in custom predict sample ([#857](https://www.github.com/googleapis/python-aiplatform/issues/857)) ([8cb4839](https://www.github.com/googleapis/python-aiplatform/commit/8cb483918bdbaeae34935eef2b3cd997c1ae89a3)) + + +### Documentation + +* Added comment for evaluation_id to python examples ([#860](https://www.github.com/googleapis/python-aiplatform/issues/860)) ([004bf5f](https://www.github.com/googleapis/python-aiplatform/commit/004bf5fa4cb2d66e36de7ec52dee8e2c8dd438ee)) +* Reverted IDs in model_service snippets test ([#871](https://www.github.com/googleapis/python-aiplatform/issues/871)) ([da747b5](https://www.github.com/googleapis/python-aiplatform/commit/da747b5ffca3c12b8d64bc80bfe93da5afde0d43)) +* Update name of BQ source parameter in samples ([#859](https://www.github.com/googleapis/python-aiplatform/issues/859)) ([f11b598](https://www.github.com/googleapis/python-aiplatform/commit/f11b598f9069f77e86631ada53941876aea010bc)) + +## [1.7.1](https://www.github.com/googleapis/python-aiplatform/compare/v1.7.0...v1.7.1) (2021-11-16) + + +### Features + +* Add support for new Vertex regions ([#811](https://www.github.com/googleapis/python-aiplatform/issues/811)) ([8d04138](https://www.github.com/googleapis/python-aiplatform/commit/8d0413880486d03314ecab80347a713318c6944a)) + + +### Bug Fixes + +* add parameters_value in PipelineJob for schema > 2.0.0 ([#817](https://www.github.com/googleapis/python-aiplatform/issues/817)) ([900a449](https://www.github.com/googleapis/python-aiplatform/commit/900a44962ac85608dbcb3d23049db160d49d842a)) +* exclude support for python 3.10 ([#831](https://www.github.com/googleapis/python-aiplatform/issues/831)) ([0301a1d](https://www.github.com/googleapis/python-aiplatform/commit/0301a1de5719031c6c826fe4887ff5fb6bcfa956)) + + +### Miscellaneous Chores + +* release 1.7.1 ([#845](https://www.github.com/googleapis/python-aiplatform/issues/845)) ([ca04de6](https://www.github.com/googleapis/python-aiplatform/commit/ca04de6a95f8b22d0161e250d8d4314a35becfab)) + +## [1.7.0](https://www.github.com/googleapis/python-aiplatform/compare/v1.6.2...v1.7.0) (2021-11-06) + + +### Features + +* Adds support for `google.protobuf.Value` pipeline parameters in the `parameter_values` field ([#807](https://www.github.com/googleapis/python-aiplatform/issues/807)) ([c97199d](https://www.github.com/googleapis/python-aiplatform/commit/c97199dd2cb712ef436ee9cbf6b8add27b42b174)) +* Adds support for `google.protobuf.Value` pipeline parameters in the `parameter_values` field ([#808](https://www.github.com/googleapis/python-aiplatform/issues/808)) ([726b620](https://www.github.com/googleapis/python-aiplatform/commit/726b620bea1223c80225c9a3c2b54342e9c14052)) +* PipelineJob switch to v1 API from v1beta1 API ([#750](https://www.github.com/googleapis/python-aiplatform/issues/750)) ([8db7e0c](https://www.github.com/googleapis/python-aiplatform/commit/8db7e0ca4e796fea47c1bdf4c0fccd514f2dd8c2)) + + +### Bug Fixes + +* Correct PipelineJob credentials description ([#816](https://www.github.com/googleapis/python-aiplatform/issues/816)) ([49aaa87](https://www.github.com/googleapis/python-aiplatform/commit/49aaa8719a3daabf7e0d23fa1cd1d64c19159a83)) +* Fixed docstrings for Dataset in AutoMLForecastingTrainingJob ([760887b](https://www.github.com/googleapis/python-aiplatform/commit/760887b196884707473896def9e8b69c9fc77423)) + + +### Documentation + +* Fix pydocs README to be consistent with repo README ([#821](https://www.github.com/googleapis/python-aiplatform/issues/821)) ([95dbd60](https://www.github.com/googleapis/python-aiplatform/commit/95dbd6020ee8f3037b0834eb39312b5d7e5fd8e1)) +* Update sample with feedback from b/191251050 ([#818](https://www.github.com/googleapis/python-aiplatform/issues/818)) ([6b2d938](https://www.github.com/googleapis/python-aiplatform/commit/6b2d93834734b6789c13ef3782b1b3632f5c6133)) + +## [1.6.2](https://www.github.com/googleapis/python-aiplatform/compare/v1.6.1...v1.6.2) (2021-11-01) + + +### Features + +* Add PipelineJob.submit to create PipelineJob without monitoring it's completion. ([#798](https://www.github.com/googleapis/python-aiplatform/issues/798)) ([7ab05d5](https://www.github.com/googleapis/python-aiplatform/commit/7ab05d5e127636d96365b7ea408974ccd6c2f0fe)) +* support new protobuf value param types for Pipeline Job client ([#797](https://www.github.com/googleapis/python-aiplatform/issues/797)) ([2fc05ca](https://www.github.com/googleapis/python-aiplatform/commit/2fc05cab03a2c7f8462b234b02d43bc7581ba845)) + + +### Bug Fixes + +* Add retries when polling during monitoring runs ([#786](https://www.github.com/googleapis/python-aiplatform/issues/786)) ([45401c0](https://www.github.com/googleapis/python-aiplatform/commit/45401c09f23ed616a7ca84b3d7f53b8a1db21c7c)) +* use version.py for versioning ([#804](https://www.github.com/googleapis/python-aiplatform/issues/804)) ([514031f](https://www.github.com/googleapis/python-aiplatform/commit/514031fce90b6e4606279d4903dc93b0f18b9f2a)) +* Widen system test timeout, handle tearing down failed training pipelines ([#791](https://www.github.com/googleapis/python-aiplatform/issues/791)) ([78879e2](https://www.github.com/googleapis/python-aiplatform/commit/78879e2482cac7ef5520f1d7fe900768147b948e)) + + +### Miscellaneous Chores + +* release 1.6.2 ([#809](https://www.github.com/googleapis/python-aiplatform/issues/809)) ([e50b049](https://www.github.com/googleapis/python-aiplatform/commit/e50b0497574411a9c7462d76dca489281ee48d83)) + +## [1.6.1](https://www.github.com/googleapis/python-aiplatform/compare/v1.6.0...v1.6.1) (2021-10-25) + + +### Features + +* Add debugging terminal support for CustomJob, HyperparameterTun
 ([#699](https://www.github.com/googleapis/python-aiplatform/issues/699)) ([2deb505](https://www.github.com/googleapis/python-aiplatform/commit/2deb50502ae2bb8ba3f97d69b06b72b7625639a4)) +* add support for python 3.10 ([#769](https://www.github.com/googleapis/python-aiplatform/issues/769)) ([8344804](https://www.github.com/googleapis/python-aiplatform/commit/83448044508f5feb052ae7fc5a5a7ca917cee0d1)) +* Add training_utils folder and environment_variables for training ([141c008](https://www.github.com/googleapis/python-aiplatform/commit/141c008759aefe56a41e1eac654739c509d9754d)) +* enable reduction server ([#741](https://www.github.com/googleapis/python-aiplatform/issues/741)) ([8ef0ded](https://www.github.com/googleapis/python-aiplatform/commit/8ef0ded034db797adb4d458eba43537992d822bd)) +* enabling AutoML Forecasting training response to include BigQuery location of exported evaluated examples ([#657](https://www.github.com/googleapis/python-aiplatform/issues/657)) ([c1c2326](https://www.github.com/googleapis/python-aiplatform/commit/c1c2326b2342ab1b6f4c4ce3852e63376eae740d)) +* **PipelineJob:** allow PipelineSpec as param ([#774](https://www.github.com/googleapis/python-aiplatform/issues/774)) ([f90a1bd](https://www.github.com/googleapis/python-aiplatform/commit/f90a1bd775daa0892e16fd82fc1738fa9a912ec7)) +* pre batch creating TensorboardRuns and TensorboardTimeSeries in one_shot mode to speed up uploading ([#772](https://www.github.com/googleapis/python-aiplatform/issues/772)) ([c9f68c6](https://www.github.com/googleapis/python-aiplatform/commit/c9f68c6e840ba3cda04080623dfbcba6945d53e8)) + + +### Bug Fixes + +* cast resource labels to dict type ([#783](https://www.github.com/googleapis/python-aiplatform/issues/783)) ([255edc9](https://www.github.com/googleapis/python-aiplatform/commit/255edc92dc897619ddd705463aefb8a1723ae8cd)) +* Remove sync parameter from create_endpoint_sample ([#695](https://www.github.com/googleapis/python-aiplatform/issues/695)) ([0477f5a](https://www.github.com/googleapis/python-aiplatform/commit/0477f5a10ba1048e64c11fc3d7e1e375b19a10fe)) + + +### Miscellaneous Chores + +* release 1.6.1 ([#789](https://www.github.com/googleapis/python-aiplatform/issues/789)) ([4520d35](https://www.github.com/googleapis/python-aiplatform/commit/4520d350beb756549304de60d62ff637bb1807c5)) + +## [1.6.0](https://www.github.com/googleapis/python-aiplatform/compare/v1.5.0...v1.6.0) (2021-10-12) + + +### Features + +* add featurestore service to aiplatform v1 ([#765](https://www.github.com/googleapis/python-aiplatform/issues/765)) ([68c88e4](https://www.github.com/googleapis/python-aiplatform/commit/68c88e48f62d5c2ff561862ba810a48389f7e41a)) +* Add one shot profile uploads to tensorboard uploader. ([#704](https://www.github.com/googleapis/python-aiplatform/issues/704)) ([a83f253](https://www.github.com/googleapis/python-aiplatform/commit/a83f2535b31e2aaff0306c7290265b864b9ddb40)) +* Added column_specs, training_encryption_spec_key_name, model_encryption_spec_key_name to AutoMLForecastingTrainingJob.init and various split methods to AutoMLForecastingTrainingJob.run ([#647](https://www.github.com/googleapis/python-aiplatform/issues/647)) ([7cb6976](https://www.github.com/googleapis/python-aiplatform/commit/7cb69764e0f9be9ca0fcb1641f4dc90e3b306bed)) +* Lazy load Endpoint class ([#655](https://www.github.com/googleapis/python-aiplatform/issues/655)) ([c795c6f](https://www.github.com/googleapis/python-aiplatform/commit/c795c6fbb87c4f71845cfbd2647c1adbc029bcef)) + +## [1.5.0](https://www.github.com/googleapis/python-aiplatform/compare/v1.4.3...v1.5.0) (2021-09-30) + + +### Features + +* Add data plane code snippets for feature store service ([#713](https://www.github.com/googleapis/python-aiplatform/issues/713)) ([e3ea683](https://www.github.com/googleapis/python-aiplatform/commit/e3ea683bf754832340853a15bdb0a0662500a70f)) +* add flaky test diagnostic script ([#734](https://www.github.com/googleapis/python-aiplatform/issues/734)) ([09e48de](https://www.github.com/googleapis/python-aiplatform/commit/09e48de8b79fb5d601169663c9a8e1c33883f1cf)) +* add vizier service to aiplatform v1 BUILD.bazel ([#731](https://www.github.com/googleapis/python-aiplatform/issues/731)) ([1a580ae](https://www.github.com/googleapis/python-aiplatform/commit/1a580aec158b5e25b94f27a6a9daa3943124c485)) +* code snippets for feature store control plane ([#709](https://www.github.com/googleapis/python-aiplatform/issues/709)) ([8e06ced](https://www.github.com/googleapis/python-aiplatform/commit/8e06ced83ed2cc480d869318c4debef9c28ad214)) +* Updating the Tensorboard uploader to use the new batch write API so it runs more efficiently ([#710](https://www.github.com/googleapis/python-aiplatform/issues/710)) ([9d1b01a](https://www.github.com/googleapis/python-aiplatform/commit/9d1b01a91dc077bfe8edf023216b65b826d67d5f)) + + +### Bug Fixes + +* [#677](https://www.github.com/googleapis/python-aiplatform/issues/677) ([#728](https://www.github.com/googleapis/python-aiplatform/issues/728)) ([7f548e4](https://www.github.com/googleapis/python-aiplatform/commit/7f548e4b5322055a3c2befcdc9d4eef1bc2278ca)) +* **PipelineJob:** use name as output only field ([#719](https://www.github.com/googleapis/python-aiplatform/issues/719)) ([1c84464](https://www.github.com/googleapis/python-aiplatform/commit/1c84464e3130f9db81cd341306b334f9a490587f)) +* use the project id from BQ dataset instead of the default project id ([#717](https://www.github.com/googleapis/python-aiplatform/issues/717)) ([e87a255](https://www.github.com/googleapis/python-aiplatform/commit/e87a255705a5d04ade79f12c706dc842c0228118)) + +## [1.4.3](https://www.github.com/googleapis/python-aiplatform/compare/v1.4.2...v1.4.3) (2021-09-17) + + +### Features + +* **PipelineJob:** support dict, list, bool typed input parameters fr
 ([#693](https://www.github.com/googleapis/python-aiplatform/issues/693)) ([243b75c](https://www.github.com/googleapis/python-aiplatform/commit/243b75c2655beeef47848410a40d86a072428ac3)) + + +### Bug Fixes + +* Update milli node_hours for image training ([#663](https://www.github.com/googleapis/python-aiplatform/issues/663)) ([64768c3](https://www.github.com/googleapis/python-aiplatform/commit/64768c3591f648932e023713d2a728ce5318bb8b)) +* XAI Metadata compatibility with Model.upload ([#705](https://www.github.com/googleapis/python-aiplatform/issues/705)) ([f0570cb](https://www.github.com/googleapis/python-aiplatform/commit/f0570cb999f024ca96e7daaa102c81b681c2a575)) + + +### Miscellaneous Chores + +* release 1.4.3 ([#715](https://www.github.com/googleapis/python-aiplatform/issues/715)) ([b610486](https://www.github.com/googleapis/python-aiplatform/commit/b6104868161a236fc5585855b5948a5e3294aea2)) + +## [1.4.2](https://www.github.com/googleapis/python-aiplatform/compare/v1.4.1...v1.4.2) (2021-09-10) + + +### Features + +* add explanation metadata `get_metadata_protobuf` for reuse ([#672](https://www.github.com/googleapis/python-aiplatform/issues/672)) ([efb6d18](https://www.github.com/googleapis/python-aiplatform/commit/efb6d18f868086bc53aceab60942eb837ced65b7)) + + +## [1.4.1](https://www.github.com/googleapis/python-aiplatform/compare/v1.4.0...v1.4.1) (2021-09-07) + + +### Features + +* add prediction service RPC RawPredict to aiplatform_v1beta1 feat: add tensorboard service RPCs to aiplatform_v1beta1: BatchCreateTensorboardRuns, BatchCreateTensorboardTimeSeries, WriteTensorboardExperimentData feat: add model_deployment_monitori... ([#670](https://www.github.com/googleapis/python-aiplatform/issues/670)) ([b73cd94](https://www.github.com/googleapis/python-aiplatform/commit/b73cd9485f8713ac42e7efa9bfd952f67368b778)) +* add Vizier service to aiplatform v1 ([#671](https://www.github.com/googleapis/python-aiplatform/issues/671)) ([179150a](https://www.github.com/googleapis/python-aiplatform/commit/179150aed80d1386993a07870fe34f2b637ded18)) +* add XAI, model monitoring, and index services to aiplatform v1 ([#668](https://www.github.com/googleapis/python-aiplatform/issues/668)) ([1fbce55](https://www.github.com/googleapis/python-aiplatform/commit/1fbce55fd846f473f41c16c1185be893e2376bdd)) +* Update tensorboard uploader to use Dispatcher for handling different event types ([#651](https://www.github.com/googleapis/python-aiplatform/issues/651)) ([d20b520](https://www.github.com/googleapis/python-aiplatform/commit/d20b520ea936a6554a24099beb0e044f237ff741)), closes [#519](https://www.github.com/googleapis/python-aiplatform/issues/519) + + +### Documentation + +* Add code sample for Pipelines ([#684](https://www.github.com/googleapis/python-aiplatform/issues/684)) ([4f0c18e](https://www.github.com/googleapis/python-aiplatform/commit/4f0c18e8989cf353019876a73aa57457332e88fb)) + +## [1.4.0](https://www.github.com/googleapis/python-aiplatform/compare/v1.3.0...v1.4.0) (2021-08-30) + + +### Features + +* add filter and timestamp splits ([#627](https://www.github.com/googleapis/python-aiplatform/issues/627)) ([1a13577](https://www.github.com/googleapis/python-aiplatform/commit/1a135775966c8a2303ded529eba514dcf9db7205)) +* add labels to all resource creation apis ([#601](https://www.github.com/googleapis/python-aiplatform/issues/601)) ([4e7666a](https://www.github.com/googleapis/python-aiplatform/commit/4e7666a30b4472698ed980d9d746ba85ad4142d8)) +* add PipelineJob.list ([a58ea82](https://www.github.com/googleapis/python-aiplatform/commit/a58ea826c575b9b0c8cb69e47fc2f07a98bb285b)) +* add support for export_evaluated_data_items_config in AutoMLTab
 ([#583](https://www.github.com/googleapis/python-aiplatform/issues/583)) ([2a6b0a3](https://www.github.com/googleapis/python-aiplatform/commit/2a6b0a369296698f79d75e93007e4c7319f3523c)) +* add util functions to get URLs for Tensorboard web app. ([#635](https://www.github.com/googleapis/python-aiplatform/issues/635)) ([8d88c00](https://www.github.com/googleapis/python-aiplatform/commit/8d88c006c5586b28d340448382a9292543448fd6)) +* Add wait_for_resource_creation to BatchPredictionJob and unblock async creation when model is pending creation. ([#660](https://www.github.com/googleapis/python-aiplatform/issues/660)) ([db580ad](https://www.github.com/googleapis/python-aiplatform/commit/db580ad43e97e0d877c29c0e8c077c37dee33ff3)) +* Added the VertexAiResourceNoun.to_dict() method ([#588](https://www.github.com/googleapis/python-aiplatform/issues/588)) ([b478075](https://www.github.com/googleapis/python-aiplatform/commit/b478075efb05553760514256fee9a63126a9916f)) +* expose base_output_dir for custom job ([#586](https://www.github.com/googleapis/python-aiplatform/issues/586)) ([2f138d1](https://www.github.com/googleapis/python-aiplatform/commit/2f138d1dfe4959d1b5f53a9dfef90a18de9908ec)) +* expose boot disk type and size for CustomTrainingJob, CustomPythonPackageTrainingJob, and CustomContainerTrainingJob ([#602](https://www.github.com/googleapis/python-aiplatform/issues/602)) ([355ea24](https://www.github.com/googleapis/python-aiplatform/commit/355ea24c6dd9b061ae0933df4dd07dd5b8c2232b)) +* split GAPIC samples by service ([#599](https://www.github.com/googleapis/python-aiplatform/issues/599)) ([5f15b4f](https://www.github.com/googleapis/python-aiplatform/commit/5f15b4f9a4bad2c9447747a8bdebaa99eab00b75)) + + +### Bug Fixes + +* Fixed bug in TabularDataset.column_names ([#590](https://www.github.com/googleapis/python-aiplatform/issues/590)) ([0fbcd59](https://www.github.com/googleapis/python-aiplatform/commit/0fbcd592cd7e9c4b0a131d777fa84e592a43a21c)) +* pipeline none values ([#649](https://www.github.com/googleapis/python-aiplatform/issues/649)) ([2f89343](https://www.github.com/googleapis/python-aiplatform/commit/2f89343adbd69610fc5cacc7121119fc7279186e)) +* Populate service_account and network in PipelineJob instead of pipeline_spec ([#658](https://www.github.com/googleapis/python-aiplatform/issues/658)) ([8fde2ce](https://www.github.com/googleapis/python-aiplatform/commit/8fde2ce4441139784bc0fdd62c88d4b833018765)) +* re-remove extra TB dependencies introduced due to merge conflict ([#593](https://www.github.com/googleapis/python-aiplatform/issues/593)) ([433b94a](https://www.github.com/googleapis/python-aiplatform/commit/433b94a78004de6d3a4726317d8bac32c358ace8)) +* Update BatchPredictionJob.iter_outputs() and BQ docstrings ([#631](https://www.github.com/googleapis/python-aiplatform/issues/631)) ([28f32fd](https://www.github.com/googleapis/python-aiplatform/commit/28f32fd11470ad86d2f103346b3e6be8f1adc2d8)) + +## [1.3.0](https://www.github.com/googleapis/python-aiplatform/compare/v1.2.0...v1.3.0) (2021-07-30) + + +### Features + +* add get method for PipelineJob ([#561](https://www.github.com/googleapis/python-aiplatform/issues/561)) ([fe5e6e4](https://www.github.com/googleapis/python-aiplatform/commit/fe5e6e4576a6c8c73549effae99bced709e29402)) +* add Samples section to CONTRIBUTING.rst ([#558](https://www.github.com/googleapis/python-aiplatform/issues/558)) ([d35c466](https://www.github.com/googleapis/python-aiplatform/commit/d35c466e19ac9fa43b5668ce18520090b5e4edd9)) +* add tensorboard resource management ([#539](https://www.github.com/googleapis/python-aiplatform/issues/539)) ([6f8d3d1](https://www.github.com/googleapis/python-aiplatform/commit/6f8d3d1ed89f0aa6f2f0418ae752185104196c63)) +* add tf1 metadata builder ([#526](https://www.github.com/googleapis/python-aiplatform/issues/526)) ([918998c](https://www.github.com/googleapis/python-aiplatform/commit/918998c0bdc25b6a39d359a34f892dac1ca4efac)) +* add wait for creation and more informative exception when properties are not available ([#566](https://www.github.com/googleapis/python-aiplatform/issues/566)) ([e346117](https://www.github.com/googleapis/python-aiplatform/commit/e346117d5453358a32a1d6e584613ace5c2251d9)) +* Adds a new API method FindMostStableBuild ([6a99b12](https://www.github.com/googleapis/python-aiplatform/commit/6a99b125922b8fca7c997150b81b6925376e9d1d)) +* Adds attribution_score_drift_threshold field ([6a99b12](https://www.github.com/googleapis/python-aiplatform/commit/6a99b125922b8fca7c997150b81b6925376e9d1d)) +* Adds attribution_score_skew_thresholds field ([6a99b12](https://www.github.com/googleapis/python-aiplatform/commit/6a99b125922b8fca7c997150b81b6925376e9d1d)) +* Adds BigQuery output table field to batch prediction job output config ([6a99b12](https://www.github.com/googleapis/python-aiplatform/commit/6a99b125922b8fca7c997150b81b6925376e9d1d)) +* Adds CustomJob.enable_web_access field ([6a99b12](https://www.github.com/googleapis/python-aiplatform/commit/6a99b125922b8fca7c997150b81b6925376e9d1d)) +* Adds CustomJob.web_access_uris field ([6a99b12](https://www.github.com/googleapis/python-aiplatform/commit/6a99b125922b8fca7c997150b81b6925376e9d1d)) +* Adds Endpoint.network, Endpoint.private_endpoints fields and PrivateEndpoints message ([6a99b12](https://www.github.com/googleapis/python-aiplatform/commit/6a99b125922b8fca7c997150b81b6925376e9d1d)) +* Adds Execution.State constants: CACHED and CANCELLED ([6a99b12](https://www.github.com/googleapis/python-aiplatform/commit/6a99b125922b8fca7c997150b81b6925376e9d1d)) +* Adds Feature Store features ([6a99b12](https://www.github.com/googleapis/python-aiplatform/commit/6a99b125922b8fca7c997150b81b6925376e9d1d)) +* Adds fields to Study message ([6a99b12](https://www.github.com/googleapis/python-aiplatform/commit/6a99b125922b8fca7c997150b81b6925376e9d1d)) +* Adds IndexEndpoint.private_ip_ranges field ([6a99b12](https://www.github.com/googleapis/python-aiplatform/commit/6a99b125922b8fca7c997150b81b6925376e9d1d)) +* Adds IndexEndpointService.deployed_index_id field ([6a99b12](https://www.github.com/googleapis/python-aiplatform/commit/6a99b125922b8fca7c997150b81b6925376e9d1d)) +* Adds MetadataService.DeleteArtifact and DeleteExecution methods ([6a99b12](https://www.github.com/googleapis/python-aiplatform/commit/6a99b125922b8fca7c997150b81b6925376e9d1d)) +* Adds ModelMonitoringObjectConfig.explanation_config field ([6a99b12](https://www.github.com/googleapis/python-aiplatform/commit/6a99b125922b8fca7c997150b81b6925376e9d1d)) +* Adds ModelMonitoringObjectConfig.ExplanationConfig message field ([6a99b12](https://www.github.com/googleapis/python-aiplatform/commit/6a99b125922b8fca7c997150b81b6925376e9d1d)) +* column specs for tabular transformation ([#466](https://www.github.com/googleapis/python-aiplatform/issues/466)) ([71d0bd4](https://www.github.com/googleapis/python-aiplatform/commit/71d0bd4615b436eaa3ec3eade4445934552f1cb3)) +* enable_caching in PipelineJob to compile time settings ([#557](https://www.github.com/googleapis/python-aiplatform/issues/557)) ([c9da662](https://www.github.com/googleapis/python-aiplatform/commit/c9da662ec24709622bcc4a9e85d1938bead91923)) +* Removes breaking change from v1 version of AI Platform protos ([6a99b12](https://www.github.com/googleapis/python-aiplatform/commit/6a99b125922b8fca7c997150b81b6925376e9d1d)) + + +### Bug Fixes + +* change default replica count to 1 for custom training job classes ([#579](https://www.github.com/googleapis/python-aiplatform/issues/579)) ([c24251f](https://www.github.com/googleapis/python-aiplatform/commit/c24251fdd230e73c2aadb4369266b78979a31015)) +* create pipeline job with user-specified job id ([#567](https://www.github.com/googleapis/python-aiplatform/issues/567)) ([df68ec3](https://www.github.com/googleapis/python-aiplatform/commit/df68ec3441eeb7670531f50aaed00df6f7e2a1a3)) +* **deps:** pin 'google-{api,cloud}-core', 'google-auth' to allow 2.x versions ([#556](https://www.github.com/googleapis/python-aiplatform/issues/556)) ([5d79795](https://www.github.com/googleapis/python-aiplatform/commit/5d797956737f2d0d4afa4d28fe1fa2f835992991)) +* enable self signed jwt for grpc ([#570](https://www.github.com/googleapis/python-aiplatform/issues/570)) ([6a99b12](https://www.github.com/googleapis/python-aiplatform/commit/6a99b125922b8fca7c997150b81b6925376e9d1d)) + + +### Documentation + +* fix spelling ([#565](https://www.github.com/googleapis/python-aiplatform/issues/565)) ([fe5c702](https://www.github.com/googleapis/python-aiplatform/commit/fe5c7020040fb0b3b558643b8bc3e12e76f4055f)) + +## [1.2.0](https://www.github.com/googleapis/python-aiplatform/compare/v1.1.1...v1.2.0) (2021-07-14) + + +### Features + +* Add additional_experiments field to AutoMlTablesInputs ([#540](https://www.github.com/googleapis/python-aiplatform/issues/540)) ([96ee726](https://www.github.com/googleapis/python-aiplatform/commit/96ee7261d5c3ffac5598c618b7c7499fad34ab12)) +* add always_use_jwt_access ([#498](https://www.github.com/googleapis/python-aiplatform/issues/498)) ([6df4866](https://www.github.com/googleapis/python-aiplatform/commit/6df48663286db10b1b88f947fc5873a18084cf37)) +* add explain get_metadata function for tf2. ([#507](https://www.github.com/googleapis/python-aiplatform/issues/507)) ([f6f9a97](https://www.github.com/googleapis/python-aiplatform/commit/f6f9a97bb178d9859b8d43166a43792d88e57710)) +* Add structure for XAI explain (from XAI SDK) ([#502](https://www.github.com/googleapis/python-aiplatform/issues/502)) ([cb9ef11](https://www.github.com/googleapis/python-aiplatform/commit/cb9ef1115e58c230f3d009397a6e6a27fd376bed)) +* Add two new ModelType constants for Video Action Recognition training jobs ([96ee726](https://www.github.com/googleapis/python-aiplatform/commit/96ee7261d5c3ffac5598c618b7c7499fad34ab12)) +* Adds AcceleratorType.NVIDIA_TESLA_A100 constant ([f3a3d03](https://www.github.com/googleapis/python-aiplatform/commit/f3a3d03c8509dc49c24139155a572dacbe954f66)) +* Adds additional_experiments field to AutoMlForecastingInputs ([8077b3d](https://www.github.com/googleapis/python-aiplatform/commit/8077b3d728b6e168c8aad41291dd90144ab75633)) +* Adds additional_experiments field to AutoMlTablesInputs ([#544](https://www.github.com/googleapis/python-aiplatform/issues/544)) ([8077b3d](https://www.github.com/googleapis/python-aiplatform/commit/8077b3d728b6e168c8aad41291dd90144ab75633)) +* Adds AutoscalingMetricSpec message ([f3a3d03](https://www.github.com/googleapis/python-aiplatform/commit/f3a3d03c8509dc49c24139155a572dacbe954f66)) +* Adds BigQuery output table field to batch prediction job output config ([f3a3d03](https://www.github.com/googleapis/python-aiplatform/commit/f3a3d03c8509dc49c24139155a572dacbe954f66)) +* Adds fields to Study message ([f3a3d03](https://www.github.com/googleapis/python-aiplatform/commit/f3a3d03c8509dc49c24139155a572dacbe954f66)) +* Adds JobState.JOB_STATE_EXPIRED constant ([f3a3d03](https://www.github.com/googleapis/python-aiplatform/commit/f3a3d03c8509dc49c24139155a572dacbe954f66)) +* Adds PipelineService methods for Create, Get, List, Delete, Cancel ([f3a3d03](https://www.github.com/googleapis/python-aiplatform/commit/f3a3d03c8509dc49c24139155a572dacbe954f66)) +* Adds two new ModelType constants for Video Action Recognition training jobs ([8077b3d](https://www.github.com/googleapis/python-aiplatform/commit/8077b3d728b6e168c8aad41291dd90144ab75633)) +* Removes AcceleratorType.TPU_V2 and TPU_V3 constants ([#543](https://www.github.com/googleapis/python-aiplatform/issues/543)) ([f3a3d03](https://www.github.com/googleapis/python-aiplatform/commit/f3a3d03c8509dc49c24139155a572dacbe954f66)) + + +### Bug Fixes + +* Handle nested fields from BigQuery source when getting default column_names ([#522](https://www.github.com/googleapis/python-aiplatform/issues/522)) ([3fc1d44](https://www.github.com/googleapis/python-aiplatform/commit/3fc1d44ac0acbb4f58088e7eeb16d85818af1125)) +* log pipeline completion and raise pipeline failures ([#523](https://www.github.com/googleapis/python-aiplatform/issues/523)) ([2508fe9](https://www.github.com/googleapis/python-aiplatform/commit/2508fe9d8a75ac8b05f06a78589c657313bd1d3d)) +* making the uploader depend on tensorflow-proper ([#499](https://www.github.com/googleapis/python-aiplatform/issues/499)) ([b95e040](https://www.github.com/googleapis/python-aiplatform/commit/b95e0406566879e8f71cefda72b41dc6fe4e578f)) +* Set prediction client when listing Endpoints ([#512](https://www.github.com/googleapis/python-aiplatform/issues/512)) ([95639ee](https://www.github.com/googleapis/python-aiplatform/commit/95639ee1c2c9cb66624265383d4d27bed3ff7dbd)) + +## [1.1.1](https://www.github.com/googleapis/python-aiplatform/compare/v1.1.0...v1.1.1) (2021-06-22) + + +### Features + +* add cancel method to pipeline client ([#488](https://www.github.com/googleapis/python-aiplatform/issues/488)) ([3b19fff](https://www.github.com/googleapis/python-aiplatform/commit/3b19fff399b85c92e661eb83a48a4c6636423518)) + + +### Bug Fixes + +* check if training_task_metadata is populated before logging backingCustomJob ([#494](https://www.github.com/googleapis/python-aiplatform/issues/494)) ([2e627f8](https://www.github.com/googleapis/python-aiplatform/commit/2e627f876e1d7dd03e5d6bd2e81e6234e361a9df)) + + +### Documentation + +* omit mention of Python 2.7 in 'CONTRIBUTING.rst' ([#1127](https://www.github.com/googleapis/python-aiplatform/issues/1127)) ([#489](https://www.github.com/googleapis/python-aiplatform/issues/489)) ([cbc47f8](https://www.github.com/googleapis/python-aiplatform/commit/cbc47f862f291b00b85718498571e0c737cb26a6)) + + +### Miscellaneous Chores + +* release 1.1.1 ([1a38ce2](https://www.github.com/googleapis/python-aiplatform/commit/1a38ce2f9879e1c42c0c6b25b72bd4836e3a1f73)) + +## [1.1.0](https://www.github.com/googleapis/python-aiplatform/compare/v1.0.1...v1.1.0) (2021-06-17) + + +### Features + +* add aiplatform API Vizier service ([fdc968f](https://www.github.com/googleapis/python-aiplatform/commit/fdc968f49e89a5c7ca14692080c0ae7e8b6e0865)) +* add featurestore, index, metadata, monitoring, pipeline, and tensorboard services to aiplatform v1beta1 ([fdc968f](https://www.github.com/googleapis/python-aiplatform/commit/fdc968f49e89a5c7ca14692080c0ae7e8b6e0865)) +* add invalid_row_count to ImportFeatureValuesResponse and ImportFeatureValuesOperationMetadata ([fdc968f](https://www.github.com/googleapis/python-aiplatform/commit/fdc968f49e89a5c7ca14692080c0ae7e8b6e0865)) +* add pipeline client init and run to vertex AI ([1f1226f](https://www.github.com/googleapis/python-aiplatform/commit/1f1226fd8c745a7cd86c299fa0cfc2291947f3e7)) +* add tensorboard support for CustomTrainingJob, CustomContainerTrainingJob, CustomPythonPackageTrainingJob ([#462](https://www.github.com/googleapis/python-aiplatform/issues/462)) ([8cfd611](https://www.github.com/googleapis/python-aiplatform/commit/8cfd61179af06232173b91b4d9fd633028823624)) +* adds enhanced protos for time series forecasting ([fdc968f](https://www.github.com/googleapis/python-aiplatform/commit/fdc968f49e89a5c7ca14692080c0ae7e8b6e0865)) +* adds enhanced protos for time series forecasting ([#374](https://www.github.com/googleapis/python-aiplatform/issues/374)) ([fdc968f](https://www.github.com/googleapis/python-aiplatform/commit/fdc968f49e89a5c7ca14692080c0ae7e8b6e0865)) +* allow the prediction endpoint to be overridden ([#461](https://www.github.com/googleapis/python-aiplatform/issues/461)) ([c2cf612](https://www.github.com/googleapis/python-aiplatform/commit/c2cf61288326cad28ab474064b887687bc649d76)) +* AutoMlImageSegmentationInputs.ModelType adds MOBILE_TF_LOW_LATENCY constant ([fdc968f](https://www.github.com/googleapis/python-aiplatform/commit/fdc968f49e89a5c7ca14692080c0ae7e8b6e0865)) +* AutoMlVideoClassificationInputs.ModelType adds MOBILE_JETSON_VERSATILE_1 constant ([fdc968f](https://www.github.com/googleapis/python-aiplatform/commit/fdc968f49e89a5c7ca14692080c0ae7e8b6e0865)) +* Expose additional attributes into Vertex SDK to close gap with GAPIC ([#477](https://www.github.com/googleapis/python-aiplatform/issues/477)) ([572a27c](https://www.github.com/googleapis/python-aiplatform/commit/572a27c7929e5686b61950e09e17134564987d50)) +* ImageSegmentationPredictionResult.category_mask field changed to string data type ([fdc968f](https://www.github.com/googleapis/python-aiplatform/commit/fdc968f49e89a5c7ca14692080c0ae7e8b6e0865)) +* remove unsupported accelerator types ([fdc968f](https://www.github.com/googleapis/python-aiplatform/commit/fdc968f49e89a5c7ca14692080c0ae7e8b6e0865)) +* removes forecasting (time_series_forecasting proto) from public v1beta1 protos ([fdc968f](https://www.github.com/googleapis/python-aiplatform/commit/fdc968f49e89a5c7ca14692080c0ae7e8b6e0865)) +* removes unused protos from schema/ folders: schema/io_format.proto, schema/saved_query_metadata.proto ([fdc968f](https://www.github.com/googleapis/python-aiplatform/commit/fdc968f49e89a5c7ca14692080c0ae7e8b6e0865)) +* support additional_experiments for AutoML Tables and AutoML Forecasting ([#428](https://www.github.com/googleapis/python-aiplatform/issues/428)) ([b4211f2](https://www.github.com/googleapis/python-aiplatform/commit/b4211f2f60aead88107c08a18d30b0800b019593)) +* support self-signed JWT flow for service accounts ([fdc968f](https://www.github.com/googleapis/python-aiplatform/commit/fdc968f49e89a5c7ca14692080c0ae7e8b6e0865)) + + +### Bug Fixes + +* add async client to %name_%version/init.py ([fdc968f](https://www.github.com/googleapis/python-aiplatform/commit/fdc968f49e89a5c7ca14692080c0ae7e8b6e0865)) +* add target_column docstring ([#473](https://www.github.com/googleapis/python-aiplatform/issues/473)) ([c0543cd](https://www.github.com/googleapis/python-aiplatform/commit/c0543cdd1e9ba0efd18d7d1a442906938fc6db9a)) +* configuring timeouts for aiplatform v1 methods ([fdc968f](https://www.github.com/googleapis/python-aiplatform/commit/fdc968f49e89a5c7ca14692080c0ae7e8b6e0865)) +* Enable MetadataStore to use credentials when aiplatfrom.init passed experiment and credentials. ([#460](https://www.github.com/googleapis/python-aiplatform/issues/460)) ([e7bf0d8](https://www.github.com/googleapis/python-aiplatform/commit/e7bf0d83d8bb0849a9bce886c958d13f5cbe5fab)) +* exclude docs and tests from package ([#481](https://www.github.com/googleapis/python-aiplatform/issues/481)) ([b209904](https://www.github.com/googleapis/python-aiplatform/commit/b2099049484f66f4348ddd4448c676feecb0b46e)) +* pass credentials to BQ and GCS clients ([#469](https://www.github.com/googleapis/python-aiplatform/issues/469)) ([481d172](https://www.github.com/googleapis/python-aiplatform/commit/481d172542ffd80e18f4fab5b01945be17d5e18c)) +* remove display_name from FeatureStore ([fdc968f](https://www.github.com/googleapis/python-aiplatform/commit/fdc968f49e89a5c7ca14692080c0ae7e8b6e0865)) +* Remove URI attribute from Endpoint sample ([#478](https://www.github.com/googleapis/python-aiplatform/issues/478)) ([e3cbdd8](https://www.github.com/googleapis/python-aiplatform/commit/e3cbdd8322c854f526c8564f8bb61fb6525598d7)) + + +### Documentation + +* changes product name to Vertex AI ([fdc968f](https://www.github.com/googleapis/python-aiplatform/commit/fdc968f49e89a5c7ca14692080c0ae7e8b6e0865)) +* correct link to fieldmask ([fdc968f](https://www.github.com/googleapis/python-aiplatform/commit/fdc968f49e89a5c7ca14692080c0ae7e8b6e0865)) +* removes tinyurl links ([fdc968f](https://www.github.com/googleapis/python-aiplatform/commit/fdc968f49e89a5c7ca14692080c0ae7e8b6e0865)) + +## [1.0.1](https://www.github.com/googleapis/python-aiplatform/compare/v1.0.0...v1.0.1) (2021-05-21) ### Bug Fixes @@ -70,7 +676,7 @@ * env formatiing ([#379](https://www.github.com/googleapis/python-aiplatform/issues/379)) ([6bc4c61](https://www.github.com/googleapis/python-aiplatform/commit/6bc4c612d5471911f82ee5ada9fb3a9307ee836f)) * remove Optional type hint on deploy ([#345](https://www.github.com/googleapis/python-aiplatform/issues/345)) ([79b0ab1](https://www.github.com/googleapis/python-aiplatform/commit/79b0ab13e6d08a12ac0a0971a8001e9ddb8baf56)) -### [0.7.1](https://www.github.com/googleapis/python-aiplatform/compare/v0.7.0...v0.7.1) (2021-04-14) +## [0.7.1](https://www.github.com/googleapis/python-aiplatform/compare/v0.7.0...v0.7.1) (2021-04-14) ### Bug Fixes @@ -108,7 +714,7 @@ * skip create data labeling job sample tests ([#254](https://www.github.com/googleapis/python-aiplatform/issues/254)) ([116a29b](https://www.github.com/googleapis/python-aiplatform/commit/116a29b1efcebb15bad14c3c36d3591c09ef10be)) -### [0.5.1](https://www.github.com/googleapis/python-aiplatform/compare/v0.5.0...v0.5.1) (2021-03-01) +## [0.5.1](https://www.github.com/googleapis/python-aiplatform/compare/v0.5.0...v0.5.1) (2021-03-01) ### Bug Fixes @@ -172,7 +778,7 @@ * update readme ([#81](https://www.github.com/googleapis/python-aiplatform/issues/81)) ([19dc31a](https://www.github.com/googleapis/python-aiplatform/commit/19dc31a7e63ec112e9d0dc72e22db04910137d07)) -### [0.3.1](https://www.github.com/googleapis/python-aiplatform/compare/v0.3.0...v0.3.1) (2020-11-13) +## [0.3.1](https://www.github.com/googleapis/python-aiplatform/compare/v0.3.0...v0.3.1) (2020-11-13) ### Features diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index f865e3769d..bdf18d174f 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -22,7 +22,7 @@ In order to add a feature: documentation. - The feature must work fully on the following CPython versions: - 3.6, 3.7, 3.8 and 3.9 on both UNIX and Windows. + 3.7, 3.8 and 3.9 on both UNIX and Windows. - The feature must not add unnecessary dependencies (where "unnecessary" is of course subjective, but new dependencies should @@ -50,9 +50,9 @@ You'll have to create a development environment using a Git checkout: # Configure remotes such that you can pull changes from the googleapis/python-aiplatform # repository into your local repository. $ git remote add upstream git@github.com:googleapis/python-aiplatform.git - # fetch and merge changes from upstream into master + # fetch and merge changes from upstream into main $ git fetch upstream - $ git merge upstream/master + $ git merge upstream/main Now your local repo is set up such that you will push changes to your GitHub repo, from which you can submit a pull request. @@ -68,15 +68,12 @@ Using ``nox`` We use `nox `__ to instrument our tests. - To test your changes, run unit tests with ``nox``:: + $ nox -s unit - $ nox -s unit-2.7 - $ nox -s unit-3.8 - $ ... +- To run a single unit test:: -- Args to pytest can be passed through the nox command separated by a `--`. For - example, to run a single test:: + $ nox -s unit-3.9 -- -k - $ nox -s unit-3.8 -- -k .. note:: @@ -113,12 +110,12 @@ Coding Style variables:: export GOOGLE_CLOUD_TESTING_REMOTE="upstream" - export GOOGLE_CLOUD_TESTING_BRANCH="master" + export GOOGLE_CLOUD_TESTING_BRANCH="main" By doing this, you are specifying the location of the most up-to-date - version of ``python-aiplatform``. The the suggested remote name ``upstream`` - should point to the official ``googleapis`` checkout and the - the branch should be the main branch on that remote (``master``). + version of ``python-aiplatform``. The + remote name ``upstream`` should point to the official ``googleapis`` + checkout and the branch should be the default branch on that remote (``main``). - This repository contains configuration for the `pre-commit `__ tool, which automates checking @@ -143,8 +140,7 @@ Running System Tests - To run system tests, you can execute:: # Run all system tests - $ nox -s system-3.8 - $ nox -s system-2.7 + $ nox -s system # Run a single system test $ nox -s system-3.8 -- -k @@ -152,9 +148,8 @@ Running System Tests .. note:: - System tests are only configured to run under Python 2.7 and - Python 3.8. For expediency, we do not run them in older versions - of Python 3. + System tests are only configured to run under Python 3.8. + For expediency, we do not run them in older versions of Python 3. This alone will not run the tests. You'll need to change some local auth settings and change some configuration in your project to @@ -182,6 +177,30 @@ Build the docs via: $ nox -s docs +************************* +Samples and code snippets +************************* + +Code samples and snippets live in the `samples/` catalogue. Feel free to +provide more examples, but make sure to write tests for those examples. +Each folder containing example code requires its own `noxfile.py` script +which automates testing. If you decide to create a new folder, you can +base it on the `samples/snippets` folder (providing `noxfile.py` and +the requirements files). + +The tests will run against a real Google Cloud Project, so you should +configure them just like the System Tests. + +- To run sample tests, you can execute:: + + # Run all tests in a folder + $ cd samples/snippets + $ nox -s py-3.8 + + # Run a single sample test + $ cd samples/snippets + $ nox -s py-3.8 -- -k + ******************************************** Note About ``README`` as it pertains to PyPI ******************************************** @@ -190,7 +209,7 @@ The `description on PyPI`_ for the project comes directly from the ``README``. Due to the reStructuredText (``rst``) parser used by PyPI, relative links which will work on GitHub (e.g. ``CONTRIBUTING.rst`` instead of -``https://github.com/googleapis/python-aiplatform/blob/master/CONTRIBUTING.rst``) +``https://github.com/googleapis/python-aiplatform/blob/main/CONTRIBUTING.rst``) may cause problems creating links or rendering the description. .. _description on PyPI: https://pypi.org/project/google-cloud-aiplatform @@ -202,12 +221,10 @@ Supported Python Versions We support: -- `Python 3.6`_ - `Python 3.7`_ - `Python 3.8`_ - `Python 3.9`_ -.. _Python 3.6: https://docs.python.org/3.6/ .. _Python 3.7: https://docs.python.org/3.7/ .. _Python 3.8: https://docs.python.org/3.8/ .. _Python 3.9: https://docs.python.org/3.9/ @@ -215,11 +232,11 @@ We support: Supported versions can be found in our ``noxfile.py`` `config`_. -.. _config: https://github.com/googleapis/python-aiplatform/blob/master/noxfile.py +.. _config: https://github.com/googleapis/python-aiplatform/blob/main/noxfile.py -We also explicitly decided to support Python 3 beginning with version -3.6. Reasons for this include: +We also explicitly decided to support Python 3 beginning with version 3.7. +Reasons for this include: - Encouraging use of newest versions of Python 3 - Taking the lead of `prominent`_ open-source `projects`_ diff --git a/README.rst b/README.rst index 57ead60fea..0b959ee04f 100644 --- a/README.rst +++ b/README.rst @@ -1,7 +1,7 @@ -Vertex SDK for Python +Vertex AI SDK for Python ================================================= -|GA| |pypi| |versions| +|GA| |pypi| |versions| |unit-tests| |system-tests| |sample-tests| `Vertex AI`_: Google Vertex AI is an integrated suite of machine learning tools and services for building and using ML models with AutoML or custom code. It offers both novices and experts the best workbench for the entire machine learning development lifecycle. @@ -10,13 +10,19 @@ Vertex SDK for Python - `Product Documentation`_ .. |GA| image:: https://img.shields.io/badge/support-ga-gold.svg - :target: https://github.com/googleapis/google-cloud-python/blob/master/README.rst#general-availability + :target: https://github.com/googleapis/google-cloud-python/blob/main/README.rst#general-availability .. |pypi| image:: https://img.shields.io/pypi/v/google-cloud-aiplatform.svg :target: https://pypi.org/project/google-cloud-aiplatform/ .. |versions| image:: https://img.shields.io/pypi/pyversions/google-cloud-aiplatform.svg :target: https://pypi.org/project/google-cloud-aiplatform/ +.. |unit-tests| image:: https://storage.googleapis.com/cloud-devrel-public/python-aiplatform/badges/sdk-unit-tests.svg + :target: https://storage.googleapis.com/cloud-devrel-public/python-aiplatform/badges/sdk-unit-tests.html +.. |system-tests| image:: https://storage.googleapis.com/cloud-devrel-public/python-aiplatform/badges/sdk-system-tests.svg + :target: https://storage.googleapis.com/cloud-devrel-public/python-aiplatform/badges/sdk-system-tests.html +.. |sample-tests| image:: https://storage.googleapis.com/cloud-devrel-public/python-aiplatform/badges/sdk-sample-tests.svg + :target: https://storage.googleapis.com/cloud-devrel-public/python-aiplatform/badges/sdk-sample-tests.html .. _Vertex AI: https://cloud.google.com/vertex-ai/docs -.. _Client Library Documentation: https://googleapis.dev/python/aiplatform/latest +.. _Client Library Documentation: https://cloud.google.com/python/docs/reference/aiplatform/latest .. _Product Documentation: https://cloud.google.com/vertex-ai/docs Quick Start @@ -70,11 +76,34 @@ Windows \Scripts\pip.exe install google-cloud-aiplatform +Supported Python Versions +^^^^^^^^^^^^^^^^^^^^^^^^^ +Python >= 3.7 + +Deprecated Python Versions +^^^^^^^^^^^^^^^^^^^^^^^^^^ +Python == 3.6. + +The last version of this library compatible with Python 3.6 is google-cloud-aiplatform==1.12.1. + Overview ~~~~~~~~ -This section provides a brief overview of the Vertex SDK for Python. You can also reference the notebooks in `vertex-ai-samples`_ for examples. +This section provides a brief overview of the Vertex AI SDK for Python. You can also reference the notebooks in `vertex-ai-samples`_ for examples. + +.. _vertex-ai-samples: https://github.com/GoogleCloudPlatform/vertex-ai-samples/tree/main/notebooks/community/sdk + +All publicly available SDK features can be found in the :code:`google/cloud/aiplatform` directory. +Under the hood, Vertex SDK builds on top of GAPIC, which stands for Google API CodeGen. +The GAPIC library code sits in :code:`google/cloud/aiplatform_v1` and :code:`google/cloud/aiplatform_v1beta1`, +and it is auto-generated from Google's service proto files. -.. _vertex-ai-samples: https://github.com/GoogleCloudPlatform/ai-platform-samples/tree/master/ai-platform-unified/notebooks/unofficial/sdk +For most developers' programmatic needs, they can follow these steps to figure out which libraries to import: + +1. Look through :code:`google/cloud/aiplatform` first -- Vertex SDK's APIs will almost always be easier to use and more concise comparing with GAPIC +2. If the feature that you are looking for cannot be found there, look through :code:`aiplatform_v1` to see if it's available in GAPIC +3. If it is still in beta phase, it will be available in :code:`aiplatform_v1beta1` + +If none of the above scenarios could help you find the right tools for your task, please feel free to open a github issue and send us a feature request. Importing ^^^^^^^^^ @@ -100,12 +129,12 @@ Initialize the SDK to store common configurations that you use with the SDK. # defaults to us-central1 location='us-central1', - # Googlge Cloud Stoage bucket in same region as location + # Google Cloud Storage bucket in same region as location # used to stage artifacts staging_bucket='gs://my_staging_bucket', # custom google.auth.credentials.Credentials - # environment default creds used if not set + # environment default credentials used if not set credentials=my_credentials, # customer managed encryption key resource name @@ -117,7 +146,7 @@ Initialize the SDK to store common configurations that you use with the SDK. experiment='my-experiment', # description of the experiment above - experiment_description='my experiment decsription' + experiment_description='my experiment description' ) Datasets @@ -149,7 +178,7 @@ You can also create and import a dataset in separate steps: To get a previously created Dataset: .. code-block:: Python - + dataset = aiplatform.ImageDataset('projects/my-project/location/us-central1/datasets/{DATASET_ID}') Vertex AI supports a variety of dataset schemas. References to these schemas are available under the @@ -160,7 +189,7 @@ Vertex AI supports a variety of dataset schemas. References to these schemas are Training ^^^^^^^^ -The Vertex SDK for Python allows you train Custom and AutoML Models. +The Vertex AI SDK for Python allows you train Custom and AutoML Models. You can train custom models using a custom Python script, custom Python package, or container. @@ -173,7 +202,7 @@ It must read datasets from the environment variables populated by the training s .. code-block:: Python - os.environ['AIP_DATA_FORMAT'] # provides format of data + os.environ['AIP_DATA_FORMAT'] # provides format of data os.environ['AIP_TRAINING_DATA_URI'] # uri to training split os.environ['AIP_VALIDATION_DATA_URI'] # uri to validation split os.environ['AIP_TEST_DATA_URI'] # uri to test split @@ -182,9 +211,9 @@ Please visit `Using a managed dataset in a custom training application`_ for a d .. _Using a managed dataset in a custom training application: https://cloud.google.com/vertex-ai/docs/training/using-managed-datasets -It must write the model artifact to the environment variable populated by the traing service: +It must write the model artifact to the environment variable populated by the training service: -.. code-block:: Python +.. code-block:: Python os.environ['AIP_MODEL_DIR'] @@ -195,9 +224,9 @@ It must write the model artifact to the environment variable populated by the tr job = aiplatform.CustomTrainingJob( display_name="my-training-job", script_path="training_script.py", - container_uri="gcr.io/cloud-aiplatform/training/tf-cpu.2-2:latest", + container_uri="us-docker.pkg.dev/vertex-ai/training/tf-cpu.2-2:latest", requirements=["gcsfs==0.7.1"], - model_serving_container_image_uri="gcr.io/cloud-aiplatform/prediction/tf2-cpu.2-2:latest", + model_serving_container_image_uri="us-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-2:latest", ) model = job.run(my_dataset, @@ -211,7 +240,7 @@ In the code block above `my_dataset` is managed dataset created in the `Dataset` AutoMLs ------- -The Vertex SDK for Python supports AutoML tabular, image, text, video, and forecasting. +The Vertex AI SDK for Python supports AutoML tabular, image, text, video, and forecasting. To train an AutoML tabular model: @@ -239,6 +268,26 @@ To train an AutoML tabular model: Models ------ +To get a model: + + +.. code-block:: Python + + model = aiplatform.Model('/projects/my-project/locations/us-central1/models/{MODEL_ID}') + + + +To upload a model: + +.. code-block:: Python + + model = aiplatform.Model.upload( + display_name='my-model', + artifact_uri="gs://python/to/my/model/dir", + serving_container_image_uri="us-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-2:latest", + ) + + To deploy a model: @@ -253,49 +302,100 @@ To deploy a model: accelerator_count=1) -To upload a model: +Please visit `Importing models to Vertex AI`_ for a detailed overview: + +.. _Importing models to Vertex AI: https://cloud.google.com/vertex-ai/docs/general/import-model + +Model Evaluation +---------------- + +The Vertex AI SDK for Python currently supports getting model evaluation metrics for all AutoML models. + +To list all model evaluations for a model: .. code-block:: Python - model = aiplatform.Model.upload( - display_name='my-model', - artifact_uri="gs://python/to/my/model/dir", - serving_container_image_uri="gcr.io/cloud-aiplatform/prediction/tf2-cpu.2-2:latest", - ) + model = aiplatform.Model('/projects/my-project/locations/us-central1/models/{MODEL_ID}') -To get a model: + evaluations = model.list_model_evaluations() + + +To get the model evaluation resource for a given model: .. code-block:: Python model = aiplatform.Model('/projects/my-project/locations/us-central1/models/{MODEL_ID}') -Please visit `Importing models to Vertex AI`_ for a detailed overview: + # returns the first evaluation with no arguments, you can also pass the evaluation ID + evaluation = model.get_model_evaluation() -.. _Importing models to Vertex AI: https://cloud.google.com/vertex-ai/docs/general/import-model + eval_metrics = evaluation.metrics -Endpoints ---------- +You can also create a reference to your model evaluation directly by passing in the resource name of the model evaluation: -To get predictions from endpoints: +.. code-block:: Python + + evaluation = aiplatform.ModelEvaluation( + evaluation_name='/projects/my-project/locations/us-central1/models/{MODEL_ID}/evaluations/{EVALUATION_ID}') + +Alternatively, you can create a reference to your evaluation by passing in the model and evaluation IDs: .. code-block:: Python - endpoint.predict(instances=[[6.7, 3.1, 4.7, 1.5], [4.6, 3.1, 1.5, 0.2]]) + evaluation = aiplatform.ModelEvaluation( + evaluation_name={EVALUATION_ID}, + model_id={MODEL_ID}) + + +Batch Prediction +---------------- + +To create a batch prediction job: + +.. code-block:: Python + + model = aiplatform.Model('/projects/my-project/locations/us-central1/models/{MODEL_ID}') + + batch_prediction_job = model.batch_predict( + job_display_name='my-batch-prediction-job', + instances_format='csv' + machine_type='n1-standard-4', + gcs_source=['gs://path/to/my/file.csv'] + gcs_destination_prefix='gs://path/to/by/batch_prediction/results/' + ) + +You can also create a batch prediction job asynchronously by including the `sync=False` argument: + +.. code-block:: Python + + batch_prediction_job = model.batch_predict(..., sync=False) + + # wait for resource to be created + batch_prediction_job.wait_for_resource_creation() + + # get the state + batch_prediction_job.state + # block until job is complete + batch_prediction_job.wait() -To create an endpoint + +Endpoints +--------- + +To create an endpoint: .. code-block:: Python - endpoint = endpoint.create(display_name='my-endpoint') + endpoint = aiplatform.Endpoint.create(display_name='my-endpoint') To deploy a model to a created endpoint: .. code-block:: Python model = aiplatform.Model('/projects/my-project/locations/us-central1/models/{MODEL_ID}') - + endpoint.deploy(model, min_replica_count=1, max_replica_count=5 @@ -303,6 +403,12 @@ To deploy a model to a created endpoint: accelerator_type='NVIDIA_TESLA_K80', accelerator_count=1) +To get predictions from endpoints: + +.. code-block:: Python + + endpoint.predict(instances=[[6.7, 3.1, 4.7, 1.5], [4.6, 3.1, 1.5, 0.2]]) + To undeploy models from an endpoint: .. code-block:: Python @@ -312,10 +418,137 @@ To undeploy models from an endpoint: To delete an endpoint: .. code-block:: Python - + endpoint.delete() +Pipelines +--------- + +To create a Vertex AI Pipeline run and monitor until completion: + +.. code-block:: Python + + # Instantiate PipelineJob object + pl = PipelineJob( + display_name="My first pipeline", + + # Whether or not to enable caching + # True = always cache pipeline step result + # False = never cache pipeline step result + # None = defer to cache option for each pipeline component in the pipeline definition + enable_caching=False, + + # Local or GCS path to a compiled pipeline definition + template_path="pipeline.json", + + # Dictionary containing input parameters for your pipeline + parameter_values=parameter_values, + + # GCS path to act as the pipeline root + pipeline_root=pipeline_root, + ) + + # Execute pipeline in Vertex AI and monitor until completion + pl.run( + # Email address of service account to use for the pipeline run + # You must have iam.serviceAccounts.actAs permission on the service account to use it + service_account=service_account, + + # Whether this function call should be synchronous (wait for pipeline run to finish before terminating) + # or asynchronous (return immediately) + sync=True + ) + +To create a Vertex AI Pipeline without monitoring until completion, use `submit` instead of `run`: + +.. code-block:: Python + + # Instantiate PipelineJob object + pl = PipelineJob( + display_name="My first pipeline", + + # Whether or not to enable caching + # True = always cache pipeline step result + # False = never cache pipeline step result + # None = defer to cache option for each pipeline component in the pipeline definition + enable_caching=False, + + # Local or GCS path to a compiled pipeline definition + template_path="pipeline.json", + + # Dictionary containing input parameters for your pipeline + parameter_values=parameter_values, + + # GCS path to act as the pipeline root + pipeline_root=pipeline_root, + ) + + # Submit the Pipeline to Vertex AI + pl.submit( + # Email address of service account to use for the pipeline run + # You must have iam.serviceAccounts.actAs permission on the service account to use it + service_account=service_account, + ) + + +Explainable AI: Get Metadata +---------------------------- + +To get metadata in dictionary format from TensorFlow 1 models: + +.. code-block:: Python + + from google.cloud.aiplatform.explain.metadata.tf.v1 import saved_model_metadata_builder + + builder = saved_model_metadata_builder.SavedModelMetadataBuilder( + 'gs://python/to/my/model/dir', tags=[tf.saved_model.tag_constants.SERVING] + ) + generated_md = builder.get_metadata() + +To get metadata in dictionary format from TensorFlow 2 models: + +.. code-block:: Python + + from google.cloud.aiplatform.explain.metadata.tf.v2 import saved_model_metadata_builder + + builder = saved_model_metadata_builder.SavedModelMetadataBuilder('gs://python/to/my/model/dir') + generated_md = builder.get_metadata() + +To use Explanation Metadata in endpoint deployment and model upload: + +.. code-block:: Python + + explanation_metadata = builder.get_metadata_protobuf() + + # To deploy a model to an endpoint with explanation + model.deploy(..., explanation_metadata=explanation_metadata) + + # To deploy a model to a created endpoint with explanation + endpoint.deploy(..., explanation_metadata=explanation_metadata) + + # To upload a model with explanation + aiplatform.Model.upload(..., explanation_metadata=explanation_metadata) + + +Cloud Profiler +---------------------------- + +Cloud Profiler allows you to profile your remote Vertex AI Training jobs on demand and visualize the results in Vertex AI Tensorboard. + +To start using the profiler with TensorFlow, update your training script to include the following: + +.. code-block:: Python + + from google.cloud.aiplatform.training_utils import cloud_profiler + ... + cloud_profiler.init() + +Next, run the job with with a Vertex AI TensorBoard instance. For full details on how to do this, visit https://cloud.google.com/vertex-ai/docs/experiments/tensorboard-overview + +Finally, visit your TensorBoard in your Google Cloud Console, navigate to the "Profile" tab, and click the `Capture Profile` button. This will allow users to capture profiling statistics for the running jobs. + + Next Steps ~~~~~~~~~~ @@ -327,4 +560,4 @@ Next Steps APIs that we cover. .. _Vertex AI API Product documentation: https://cloud.google.com/vertex-ai/docs -.. _README: https://github.com/googleapis/google-cloud-python/blob/master/README.rst \ No newline at end of file +.. _README: https://github.com/googleapis/google-cloud-python/blob/main/README.rst diff --git a/docs/README.rst b/docs/README.rst index 391fa89e8f..f1c894550c 100644 --- a/docs/README.rst +++ b/docs/README.rst @@ -1,27 +1,24 @@ -Python Client for Cloud AI Platform +Vertex AI SDK for Python ================================================= -|beta| |pypi| |versions| +|GA| |pypi| |versions| -`Cloud AI Platform`_: Cloud AI Platform is a suite of machine learning tools that enables - developers to train high-quality models specific to their business needs. - It offers both novices and experts the best workbench for machine learning - development by leveraging Google's state-of-the-art transfer learning and - Neural Architecture Search technology. +`Vertex AI`_: Google Vertex AI is an integrated suite of machine learning tools and services for building and using ML models with AutoML or custom code. It offers both novices and experts the best workbench for the entire machine learning development lifecycle. - `Client Library Documentation`_ - `Product Documentation`_ -.. |beta| image:: https://img.shields.io/badge/support-beta-orange.svg - :target: https://github.com/googleapis/google-cloud-python/blob/master/README.rst#beta-support +.. |GA| image:: https://img.shields.io/badge/support-ga-gold.svg + :target: https://github.com/googleapis/google-cloud-python/blob/main/README.rst#general-availability .. |pypi| image:: https://img.shields.io/pypi/v/google-cloud-aiplatform.svg :target: https://pypi.org/project/google-cloud-aiplatform/ .. |versions| image:: https://img.shields.io/pypi/pyversions/google-cloud-aiplatform.svg :target: https://pypi.org/project/google-cloud-aiplatform/ -.. _Cloud AI Platform: https://cloud.google.com/ai-platform/docs +.. _Vertex AI: https://cloud.google.com/vertex-ai/docs .. _Client Library Documentation: https://googleapis.dev/python/aiplatform/latest .. _Product Documentation: https://cloud.google.com/ai-platform/docs + Quick Start ----------- @@ -72,15 +69,403 @@ Windows \Scripts\activate \Scripts\pip.exe install google-cloud-aiplatform +Overview +~~~~~~~~ +This section provides a brief overview of the Vertex AI SDK for Python. You can also reference the notebooks in `vertex-ai-samples`_ for examples. + +.. _vertex-ai-samples: https://github.com/GoogleCloudPlatform/ai-platform-samples/tree/master/ai-platform-unified/notebooks/unofficial/sdk + +Importing +^^^^^^^^^ +SDK functionality can be used from the root of the package: + +.. code-block:: Python + + from google.cloud import aiplatform + + +Initialization +^^^^^^^^^^^^^^ +Initialize the SDK to store common configurations that you use with the SDK. + +.. code-block:: Python + + aiplatform.init( + # your Google Cloud Project ID or number + # environment default used is not set + project='my-project', + + # the Vertex AI region you will use + # defaults to us-central1 + location='us-central1', + + # Google Cloud Storage bucket in same region as location + # used to stage artifacts + staging_bucket='gs://my_staging_bucket', + + # custom google.auth.credentials.Credentials + # environment default creds used if not set + credentials=my_credentials, + + # customer managed encryption key resource name + # will be applied to all Vertex AI resources if set + encryption_spec_key_name=my_encryption_key_name, + + # the name of the experiment to use to track + # logged metrics and parameters + experiment='my-experiment', + + # description of the experiment above + experiment_description='my experiment decsription' + ) + +Datasets +^^^^^^^^ +Vertex AI provides managed tabular, text, image, and video datasets. In the SDK, datasets can be used downstream to +train models. + +To create a tabular dataset: + +.. code-block:: Python + + my_dataset = aiplatform.TabularDataset.create( + display_name="my-dataset", gcs_source=['gs://path/to/my/dataset.csv']) + +You can also create and import a dataset in separate steps: + +.. code-block:: Python + + from google.cloud import aiplatform + + my_dataset = aiplatform.TextDataset.create( + display_name="my-dataset") + + my_dataset.import( + gcs_source=['gs://path/to/my/dataset.csv'] + import_schema_uri=aiplatform.schema.dataset.ioformat.text.multi_label_classification + ) + +To get a previously created Dataset: + +.. code-block:: Python + + dataset = aiplatform.ImageDataset('projects/my-project/location/us-central1/datasets/{DATASET_ID}') + +Vertex AI supports a variety of dataset schemas. References to these schemas are available under the +:code:`aiplatform.schema.dataset` namespace. For more information on the supported dataset schemas please refer to the +`Preparing data docs`_. + +.. _Preparing data docs: https://cloud.google.com/ai-platform-unified/docs/datasets/prepare + +Training +^^^^^^^^ +The Vertex AI SDK for Python allows you train Custom and AutoML Models. + +You can train custom models using a custom Python script, custom Python package, or container. + +**Preparing Your Custom Code** + +Vertex AI custom training enables you to train on Vertex AI datasets and produce Vertex AI models. To do so your +script must adhere to the following contract: + +It must read datasets from the environment variables populated by the training service: + +.. code-block:: Python + + os.environ['AIP_DATA_FORMAT'] # provides format of data + os.environ['AIP_TRAINING_DATA_URI'] # uri to training split + os.environ['AIP_VALIDATION_DATA_URI'] # uri to validation split + os.environ['AIP_TEST_DATA_URI'] # uri to test split + +Please visit `Using a managed dataset in a custom training application`_ for a detailed overview. + +.. _Using a managed dataset in a custom training application: https://cloud.google.com/vertex-ai/docs/training/using-managed-datasets + +It must write the model artifact to the environment variable populated by the traing service: + +.. code-block:: Python + + os.environ['AIP_MODEL_DIR'] + +**Running Training** + +.. code-block:: Python + + job = aiplatform.CustomTrainingJob( + display_name="my-training-job", + script_path="training_script.py", + container_uri="gcr.io/cloud-aiplatform/training/tf-cpu.2-2:latest", + requirements=["gcsfs==0.7.1"], + model_serving_container_image_uri="gcr.io/cloud-aiplatform/prediction/tf2-cpu.2-2:latest", + ) + + model = job.run(my_dataset, + replica_count=1, + machine_type="n1-standard-4", + accelerator_type='NVIDIA_TESLA_K80', + accelerator_count=1) + +In the code block above `my_dataset` is managed dataset created in the `Dataset` section above. The `model` variable is a managed Vertex AI model that can be deployed or exported. + + +AutoMLs +------- +The Vertex AI SDK for Python supports AutoML tabular, image, text, video, and forecasting. + +To train an AutoML tabular model: + +.. code-block:: Python + + dataset = aiplatform.TabularDataset('projects/my-project/location/us-central1/datasets/{DATASET_ID}') + + job = aiplatform.AutoMLTabularTrainingJob( + display_name="train-automl", + optimization_prediction_type="regression", + optimization_objective="minimize-rmse", + ) + + model = job.run( + dataset=dataset, + target_column="target_column_name", + training_fraction_split=0.6, + validation_fraction_split=0.2, + test_fraction_split=0.2, + budget_milli_node_hours=1000, + model_display_name="my-automl-model", + disable_early_stopping=False, + ) + + +Models +------ + +To deploy a model: + + +.. code-block:: Python + + endpoint = model.deploy(machine_type="n1-standard-4", + min_replica_count=1, + max_replica_count=5 + machine_type='n1-standard-4', + accelerator_type='NVIDIA_TESLA_K80', + accelerator_count=1) + + +To upload a model: + +.. code-block:: Python + + model = aiplatform.Model.upload( + display_name='my-model', + artifact_uri="gs://python/to/my/model/dir", + serving_container_image_uri="gcr.io/cloud-aiplatform/prediction/tf2-cpu.2-2:latest", + ) + +To get a model: + +.. code-block:: Python + + model = aiplatform.Model('/projects/my-project/locations/us-central1/models/{MODEL_ID}') + +Please visit `Importing models to Vertex AI`_ for a detailed overview: + +.. _Importing models to Vertex AI: https://cloud.google.com/vertex-ai/docs/general/import-model + + +Batch Prediction +---------------- + +To create a batch prediction job: + +.. code-block:: Python + + model = aiplatform.Model('/projects/my-project/locations/us-central1/models/{MODEL_ID}') + + batch_prediction_job = model.batch_predict( + job_display_name='my-batch-prediction-job', + instances_format='csv' + machine_type='n1-standard-4', + gcs_source=['gs://path/to/my/file.csv'] + gcs_destination_prefix='gs://path/to/by/batch_prediction/results/' + ) + +You can also create a batch prediction job asynchronously by including the `sync=False` argument: + +.. code-block:: Python + + batch_prediction_job = model.batch_predict(..., sync=False) + + # wait for resource to be created + batch_prediction_job.wait_for_resource_creation() + + # get the state + batch_prediction_job.state + + # block until job is complete + batch_prediction_job.wait() + + +Endpoints +--------- + +To get predictions from endpoints: + +.. code-block:: Python + + endpoint.predict(instances=[[6.7, 3.1, 4.7, 1.5], [4.6, 3.1, 1.5, 0.2]]) + + +To create an endpoint + +.. code-block:: Python + + endpoint = endpoint.create(display_name='my-endpoint') + +To deploy a model to a created endpoint: + +.. code-block:: Python + + model = aiplatform.Model('/projects/my-project/locations/us-central1/models/{MODEL_ID}') + + endpoint.deploy(model, + min_replica_count=1, + max_replica_count=5 + machine_type='n1-standard-4', + accelerator_type='NVIDIA_TESLA_K80', + accelerator_count=1) + +To undeploy models from an endpoint: + +.. code-block:: Python + + endpoint.undeploy_all() + +To delete an endpoint: + +.. code-block:: Python + + endpoint.delete() + + +Pipelines +--------- + +To create a Vertex AI Pipeline run and monitor until completion: + +.. code-block:: Python + + # Instantiate PipelineJob object + pl = PipelineJob( + display_name="My first pipeline", + + # Whether or not to enable caching + # True = always cache pipeline step result + # False = never cache pipeline step result + # None = defer to cache option for each pipeline component in the pipeline definition + enable_caching=False, + + # Local or GCS path to a compiled pipeline definition + template_path="pipeline.json", + + # Dictionary containing input parameters for your pipeline + parameter_values=parameter_values, + + # GCS path to act as the pipeline root + pipeline_root=pipeline_root, + ) + + # Execute pipeline in Vertex AI and monitor until completion + pl.run( + # Email address of service account to use for the pipeline run + # You must have iam.serviceAccounts.actAs permission on the service account to use it + service_account=service_account, + + # Whether this function call should be synchronous (wait for pipeline run to finish before terminating) + # or asynchronous (return immediately) + sync=True + ) + +To create a Vertex AI Pipeline without monitoring until completion, use `submit` instead of `run`: + +.. code-block:: Python + + # Instantiate PipelineJob object + pl = PipelineJob( + display_name="My first pipeline", + + # Whether or not to enable caching + # True = always cache pipeline step result + # False = never cache pipeline step result + # None = defer to cache option for each pipeline component in the pipeline definition + enable_caching=False, + + # Local or GCS path to a compiled pipeline definition + template_path="pipeline.json", + + # Dictionary containing input parameters for your pipeline + parameter_values=parameter_values, + + # GCS path to act as the pipeline root + pipeline_root=pipeline_root, + ) + + # Submit the Pipeline to Vertex AI + pl.submit( + # Email address of service account to use for the pipeline run + # You must have iam.serviceAccounts.actAs permission on the service account to use it + service_account=service_account, + ) + + +Explainable AI: Get Metadata +---------------------------- + +To get metadata in dictionary format from TensorFlow 1 models: + +.. code-block:: Python + + from google.cloud.aiplatform.explain.metadata.tf.v1 import saved_model_metadata_builder + + builder = saved_model_metadata_builder.SavedModelMetadataBuilder( + 'gs://python/to/my/model/dir', tags=[tf.saved_model.tag_constants.SERVING] + ) + generated_md = builder.get_metadata() + +To get metadata in dictionary format from TensorFlow 2 models: + +.. code-block:: Python + + from google.cloud.aiplatform.explain.metadata.tf.v2 import saved_model_metadata_builder + + builder = saved_model_metadata_builder.SavedModelMetadataBuilder('gs://python/to/my/model/dir') + generated_md = builder.get_metadata() + +To use Explanation Metadata in endpoint deployment and model upload: + +.. code-block:: Python + + explanation_metadata = builder.get_metadata_protobuf() + + # To deploy a model to an endpoint with explanation + model.deploy(..., explanation_metadata=explanation_metadata) + + # To deploy a model to a created endpoint with explanation + endpoint.deploy(..., explanation_metadata=explanation_metadata) + + # To upload a model with explanation + aiplatform.Model.upload(..., explanation_metadata=explanation_metadata) + + Next Steps ~~~~~~~~~~ -- Read the `Client Library Documentation`_ for Cloud AI Platform +- Read the `Client Library Documentation`_ for Vertex AI API to see other available methods on the client. -- Read the `Cloud AI Platform API Product documentation`_ to learn +- Read the `Vertex AI API Product documentation`_ to learn more about the product and see How-to Guides. - View this `README`_ to see the full list of Cloud APIs that we cover. -.. _Cloud AI Platform API Product documentation: https://cloud.google.com/ai-platform/docs -.. _README: https://github.com/googleapis/google-cloud-python/blob/master/README.rst \ No newline at end of file +.. _Vertex AI API Product documentation: https://cloud.google.com/vertex-ai/docs +.. _README: https://github.com/googleapis/google-cloud-python/blob/main/README.rst diff --git a/docs/aiplatform/definition_v1/types.rst b/docs/aiplatform/definition_v1/types.rst new file mode 100644 index 0000000000..a1df2bce25 --- /dev/null +++ b/docs/aiplatform/definition_v1/types.rst @@ -0,0 +1,7 @@ +Types for Google Cloud Aiplatform V1 Schema Trainingjob Definition v1 API +========================================================================= + +.. automodule:: google.cloud.aiplatform.v1.schema.trainingjob.definition_v1.types + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/aiplatform/definition_v1beta1/types.rst b/docs/aiplatform/definition_v1beta1/types.rst new file mode 100644 index 0000000000..f4fe7a5301 --- /dev/null +++ b/docs/aiplatform/definition_v1beta1/types.rst @@ -0,0 +1,7 @@ +Types for Google Cloud Aiplatform V1beta1 Schema Trainingjob Definition v1beta1 API +=================================================================================== + +.. automodule:: google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1.types + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/aiplatform/instance_v1/types.rst b/docs/aiplatform/instance_v1/types.rst new file mode 100644 index 0000000000..564ab013ee --- /dev/null +++ b/docs/aiplatform/instance_v1/types.rst @@ -0,0 +1,7 @@ +Types for Google Cloud Aiplatform V1 Schema Predict Instance v1 API +=================================================================== + +.. automodule:: google.cloud.aiplatform.v1.schema.predict.instance_v1.types + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/aiplatform/instance_v1beta1/types.rst b/docs/aiplatform/instance_v1beta1/types.rst new file mode 100644 index 0000000000..7caa088065 --- /dev/null +++ b/docs/aiplatform/instance_v1beta1/types.rst @@ -0,0 +1,7 @@ +Types for Google Cloud Aiplatform V1beta1 Schema Predict Instance v1beta1 API +============================================================================= + +.. automodule:: google.cloud.aiplatform.v1beta1.schema.predict.instance_v1beta1.types + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/aiplatform/params_v1/types.rst b/docs/aiplatform/params_v1/types.rst new file mode 100644 index 0000000000..956ef5224d --- /dev/null +++ b/docs/aiplatform/params_v1/types.rst @@ -0,0 +1,7 @@ +Types for Google Cloud Aiplatform V1 Schema Predict Params v1 API +================================================================= + +.. automodule:: google.cloud.aiplatform.v1.schema.predict.params_v1.types + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/aiplatform/params_v1beta1/types.rst b/docs/aiplatform/params_v1beta1/types.rst new file mode 100644 index 0000000000..722a1d8ba0 --- /dev/null +++ b/docs/aiplatform/params_v1beta1/types.rst @@ -0,0 +1,7 @@ +Types for Google Cloud Aiplatform V1beta1 Schema Predict Params v1beta1 API +=========================================================================== + +.. automodule:: google.cloud.aiplatform.v1beta1.schema.predict.params_v1beta1.types + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/aiplatform/prediction_v1/types.rst b/docs/aiplatform/prediction_v1/types.rst new file mode 100644 index 0000000000..a97faf34de --- /dev/null +++ b/docs/aiplatform/prediction_v1/types.rst @@ -0,0 +1,7 @@ +Types for Google Cloud Aiplatform V1 Schema Predict Prediction v1 API +===================================================================== + +.. automodule:: google.cloud.aiplatform.v1.schema.predict.prediction_v1.types + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/aiplatform/prediction_v1beta1/types.rst b/docs/aiplatform/prediction_v1beta1/types.rst new file mode 100644 index 0000000000..b14182d6d7 --- /dev/null +++ b/docs/aiplatform/prediction_v1beta1/types.rst @@ -0,0 +1,7 @@ +Types for Google Cloud Aiplatform V1beta1 Schema Predict Prediction v1beta1 API +=============================================================================== + +.. automodule:: google.cloud.aiplatform.v1beta1.schema.predict.prediction_v1beta1.types + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/aiplatform.rst b/docs/aiplatform/services.rst similarity index 84% rename from docs/aiplatform.rst rename to docs/aiplatform/services.rst index bf5cd4625b..0d21fe6bd1 100644 --- a/docs/aiplatform.rst +++ b/docs/aiplatform/services.rst @@ -3,4 +3,4 @@ Google Cloud Aiplatform SDK .. automodule:: google.cloud.aiplatform :members: - :show-inheritance: \ No newline at end of file + :show-inheritance: diff --git a/docs/aiplatform/types.rst b/docs/aiplatform/types.rst new file mode 100644 index 0000000000..119f762bca --- /dev/null +++ b/docs/aiplatform/types.rst @@ -0,0 +1,13 @@ +Types for Google Cloud Aiplatform SDK API +=========================================== +.. toctree:: + :maxdepth: 2 + + instance_v1 + instance_v1beta1 + params_v1 + params_v1beta1 + prediction_v1 + prediction_v1beta1 + definition_v1 + definition_v1beta1 diff --git a/docs/aiplatform_v1/featurestore_online_serving_service.rst b/docs/aiplatform_v1/featurestore_online_serving_service.rst new file mode 100644 index 0000000000..ace5b9dd1a --- /dev/null +++ b/docs/aiplatform_v1/featurestore_online_serving_service.rst @@ -0,0 +1,6 @@ +FeaturestoreOnlineServingService +-------------------------------------------------- + +.. automodule:: google.cloud.aiplatform_v1.services.featurestore_online_serving_service + :members: + :inherited-members: diff --git a/docs/aiplatform_v1/featurestore_service.rst b/docs/aiplatform_v1/featurestore_service.rst new file mode 100644 index 0000000000..90a303a4c4 --- /dev/null +++ b/docs/aiplatform_v1/featurestore_service.rst @@ -0,0 +1,10 @@ +FeaturestoreService +------------------------------------- + +.. automodule:: google.cloud.aiplatform_v1.services.featurestore_service + :members: + :inherited-members: + +.. automodule:: google.cloud.aiplatform_v1.services.featurestore_service.pagers + :members: + :inherited-members: diff --git a/docs/aiplatform_v1/index_endpoint_service.rst b/docs/aiplatform_v1/index_endpoint_service.rst new file mode 100644 index 0000000000..9a87b81082 --- /dev/null +++ b/docs/aiplatform_v1/index_endpoint_service.rst @@ -0,0 +1,10 @@ +IndexEndpointService +-------------------------------------- + +.. automodule:: google.cloud.aiplatform_v1.services.index_endpoint_service + :members: + :inherited-members: + +.. automodule:: google.cloud.aiplatform_v1.services.index_endpoint_service.pagers + :members: + :inherited-members: diff --git a/docs/aiplatform_v1/index_service.rst b/docs/aiplatform_v1/index_service.rst new file mode 100644 index 0000000000..b07b444c23 --- /dev/null +++ b/docs/aiplatform_v1/index_service.rst @@ -0,0 +1,10 @@ +IndexService +------------------------------ + +.. automodule:: google.cloud.aiplatform_v1.services.index_service + :members: + :inherited-members: + +.. automodule:: google.cloud.aiplatform_v1.services.index_service.pagers + :members: + :inherited-members: diff --git a/docs/aiplatform_v1/metadata_service.rst b/docs/aiplatform_v1/metadata_service.rst new file mode 100644 index 0000000000..419fd0a850 --- /dev/null +++ b/docs/aiplatform_v1/metadata_service.rst @@ -0,0 +1,10 @@ +MetadataService +--------------------------------- + +.. automodule:: google.cloud.aiplatform_v1.services.metadata_service + :members: + :inherited-members: + +.. automodule:: google.cloud.aiplatform_v1.services.metadata_service.pagers + :members: + :inherited-members: diff --git a/docs/aiplatform_v1/services.rst b/docs/aiplatform_v1/services.rst index fd5a8c9aa7..0a6443a972 100644 --- a/docs/aiplatform_v1/services.rst +++ b/docs/aiplatform_v1/services.rst @@ -5,9 +5,16 @@ Services for Google Cloud Aiplatform v1 API dataset_service endpoint_service + featurestore_online_serving_service + featurestore_service + index_endpoint_service + index_service job_service + metadata_service migration_service model_service pipeline_service prediction_service specialist_pool_service + tensorboard_service + vizier_service diff --git a/docs/aiplatform_v1/tensorboard_service.rst b/docs/aiplatform_v1/tensorboard_service.rst new file mode 100644 index 0000000000..0fa17e10b8 --- /dev/null +++ b/docs/aiplatform_v1/tensorboard_service.rst @@ -0,0 +1,10 @@ +TensorboardService +------------------------------------ + +.. automodule:: google.cloud.aiplatform_v1.services.tensorboard_service + :members: + :inherited-members: + +.. automodule:: google.cloud.aiplatform_v1.services.tensorboard_service.pagers + :members: + :inherited-members: diff --git a/docs/aiplatform_v1/vizier_service.rst b/docs/aiplatform_v1/vizier_service.rst new file mode 100644 index 0000000000..efdbafe3c8 --- /dev/null +++ b/docs/aiplatform_v1/vizier_service.rst @@ -0,0 +1,10 @@ +VizierService +------------------------------- + +.. automodule:: google.cloud.aiplatform_v1.services.vizier_service + :members: + :inherited-members: + +.. automodule:: google.cloud.aiplatform_v1.services.vizier_service.pagers + :members: + :inherited-members: diff --git a/docs/conf.py b/docs/conf.py index cd484b1e23..9be57dd7f7 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -76,13 +76,13 @@ # The encoding of source files. # source_encoding = 'utf-8-sig' -# The master toctree document. -master_doc = "index" +# The root toctree document. +root_doc = "index" # General information about the project. -project = u"google-cloud-aiplatform" -copyright = u"2019, Google" -author = u"Google APIs" +project = "google-cloud-aiplatform" +copyright = "2019, Google" +author = "Google APIs" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the @@ -110,6 +110,7 @@ # directories to ignore when looking for source files. exclude_patterns = [ "_build", + "**/.nox/**/*", "samples/AUTHORING_GUIDE.md", "samples/CONTRIBUTING.md", "samples/snippets/README.rst", @@ -279,9 +280,9 @@ # author, documentclass [howto, manual, or own class]). latex_documents = [ ( - master_doc, + root_doc, "google-cloud-aiplatform.tex", - u"google-cloud-aiplatform Documentation", + "google-cloud-aiplatform Documentation", author, "manual", ) @@ -314,9 +315,9 @@ # (source start file, name, description, authors, manual section). man_pages = [ ( - master_doc, + root_doc, "google-cloud-aiplatform", - u"google-cloud-aiplatform Documentation", + "google-cloud-aiplatform Documentation", [author], 1, ) @@ -333,9 +334,9 @@ # dir menu entry, description, category) texinfo_documents = [ ( - master_doc, + root_doc, "google-cloud-aiplatform", - u"google-cloud-aiplatform Documentation", + "google-cloud-aiplatform Documentation", author, "google-cloud-aiplatform", "google-cloud-aiplatform Library", @@ -360,9 +361,13 @@ intersphinx_mapping = { "python": ("https://python.readthedocs.org/en/latest/", None), "google-auth": ("https://googleapis.dev/python/google-auth/latest/", None), - "google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None,), + "google.api_core": ( + "https://googleapis.dev/python/google-api-core/latest/", + None, + ), "grpc": ("https://grpc.github.io/grpc/python/", None), "proto-plus": ("https://proto-plus-python.readthedocs.io/en/latest/", None), + "protobuf": ("https://googleapis.dev/python/protobuf/latest/", None), } diff --git a/docs/index.rst b/docs/index.rst index 031271a261..6094720bd8 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -7,7 +7,9 @@ API Reference .. toctree:: :maxdepth: 2 - aiplatform + aiplatform/services + aiplatform/types + aiplatform_v1/services aiplatform_v1/types @@ -22,4 +24,4 @@ For a list of all ``google-cloud-aiplatform`` releases: .. toctree:: :maxdepth: 2 - changelog \ No newline at end of file + changelog diff --git a/docs/multiprocessing.rst b/docs/multiprocessing.rst index 1cb29d4ca9..536d17b2ea 100644 --- a/docs/multiprocessing.rst +++ b/docs/multiprocessing.rst @@ -1,7 +1,7 @@ .. note:: - Because this client uses :mod:`grpcio` library, it is safe to + Because this client uses :mod:`grpc` library, it is safe to share instances across threads. In multiprocessing scenarios, the best practice is to create client instances *after* the invocation of - :func:`os.fork` by :class:`multiprocessing.Pool` or + :func:`os.fork` by :class:`multiprocessing.pool.Pool` or :class:`multiprocessing.Process`. diff --git a/google/cloud/aiplatform/__init__.py b/google/cloud/aiplatform/__init__.py index 6aa8f64161..31f459d3f7 100644 --- a/google/cloud/aiplatform/__init__.py +++ b/google/cloud/aiplatform/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,10 +15,14 @@ # limitations under the License. # -from google.cloud.aiplatform import gapic -from google.cloud.aiplatform import explain + +from google.cloud.aiplatform import version as aiplatform_version + +__version__ = aiplatform_version.__version__ + from google.cloud.aiplatform import initializer + from google.cloud.aiplatform.datasets import ( ImageDataset, TabularDataset, @@ -26,25 +30,46 @@ TimeSeriesDataset, VideoDataset, ) +from google.cloud.aiplatform import explain +from google.cloud.aiplatform import gapic from google.cloud.aiplatform import hyperparameter_tuning -from google.cloud.aiplatform.metadata import metadata +from google.cloud.aiplatform.featurestore import ( + EntityType, + Feature, + Featurestore, +) +from google.cloud.aiplatform.matching_engine import ( + MatchingEngineIndex, + MatchingEngineIndexEndpoint, +) +from google.cloud.aiplatform import metadata from google.cloud.aiplatform.models import Endpoint from google.cloud.aiplatform.models import Model +from google.cloud.aiplatform.model_evaluation import ModelEvaluation from google.cloud.aiplatform.jobs import ( BatchPredictionJob, CustomJob, HyperparameterTuningJob, ) +from google.cloud.aiplatform.pipeline_jobs import PipelineJob +from google.cloud.aiplatform.tensorboard import ( + Tensorboard, + TensorboardExperiment, + TensorboardRun, + TensorboardTimeSeries, +) from google.cloud.aiplatform.training_jobs import ( CustomTrainingJob, CustomContainerTrainingJob, CustomPythonPackageTrainingJob, AutoMLTabularTrainingJob, AutoMLForecastingTrainingJob, + SequenceToSequencePlusForecastingTrainingJob, AutoMLImageTrainingJob, AutoMLTextTrainingJob, AutoMLVideoTrainingJob, ) +from google.cloud.aiplatform import helpers """ Usage: @@ -54,23 +79,39 @@ """ init = initializer.global_config.init -log_params = metadata.metadata_service.log_params -log_metrics = metadata.metadata_service.log_metrics -get_experiment_df = metadata.metadata_service.get_experiment_df -get_pipeline_df = metadata.metadata_service.get_pipeline_df -start_run = metadata.metadata_service.start_run +get_pipeline_df = metadata.metadata._LegacyExperimentService.get_pipeline_df + +log_params = metadata.metadata._experiment_tracker.log_params +log_metrics = metadata.metadata._experiment_tracker.log_metrics +get_experiment_df = metadata.metadata._experiment_tracker.get_experiment_df +start_run = metadata.metadata._experiment_tracker.start_run +start_execution = metadata.metadata._experiment_tracker.start_execution +log = metadata.metadata._experiment_tracker.log +log_time_series_metrics = metadata.metadata._experiment_tracker.log_time_series_metrics +end_run = metadata.metadata._experiment_tracker.end_run + +Experiment = metadata.experiment_resources.Experiment +ExperimentRun = metadata.experiment_run_resource.ExperimentRun +Artifact = metadata.artifact.Artifact +Execution = metadata.execution.Execution __all__ = ( + "end_run", "explain", "gapic", "init", + "helpers", "hyperparameter_tuning", + "log", "log_params", "log_metrics", + "log_time_series_metrics", "get_experiment_df", "get_pipeline_df", "start_run", + "start_execution", + "Artifact", "AutoMLImageTrainingJob", "AutoMLTabularTrainingJob", "AutoMLForecastingTrainingJob", @@ -82,10 +123,25 @@ "CustomContainerTrainingJob", "CustomPythonPackageTrainingJob", "Endpoint", + "EntityType", + "Execution", + "Experiment", + "ExperimentRun", + "Feature", + "Featurestore", + "MatchingEngineIndex", + "MatchingEngineIndexEndpoint", "ImageDataset", "HyperparameterTuningJob", "Model", + "ModelEvaluation", + "PipelineJob", + "SequenceToSequencePlusForecastingTrainingJob", "TabularDataset", + "Tensorboard", + "TensorboardExperiment", + "TensorboardRun", + "TensorboardTimeSeries", "TextDataset", "TimeSeriesDataset", "VideoDataset", diff --git a/google/cloud/aiplatform/base.py b/google/cloud/aiplatform/base.py index 07e4c2fe4a..ceb9287322 100644 --- a/google/cloud/aiplatform/base.py +++ b/google/cloud/aiplatform/base.py @@ -23,6 +23,7 @@ import logging import sys import threading +import time from typing import ( Any, Callable, @@ -38,25 +39,34 @@ import proto +from google.api_core import retry from google.api_core import operation from google.auth import credentials as auth_credentials from google.cloud.aiplatform import initializer from google.cloud.aiplatform import utils +from google.cloud.aiplatform.compat.types import encryption_spec as gca_encryption_spec +from google.protobuf import json_format - -logging.basicConfig(level=logging.INFO, stream=sys.stdout) +# This is the default retry callback to be used with get methods. +_DEFAULT_RETRY = retry.Retry() class Logger: """Logging wrapper class with high level helper methods.""" - def __init__(self, name: str = ""): - """Initializes logger with name. + def __init__(self, name: str): + """Initializes logger with optional name. Args: name (str): Name to associate with logger. """ self._logger = logging.getLogger(name) + self._logger.setLevel(logging.INFO) + + handler = logging.StreamHandler(sys.stdout) + handler.setLevel(logging.INFO) + + self._logger.addHandler(handler) def log_create_with_lro( self, @@ -92,7 +102,7 @@ def log_create_complete( cls (VertexAiResourceNoun): Vertex AI Resource Noun class that is being created. resource (proto.Message): - Vertex AI Resourc proto.Message + Vertex AI Resource proto.Message variable_name (str): Name of variable to use for code snippet """ self._logger.info(f"{cls.__name__} created. Resource name: {resource.name}") @@ -115,7 +125,7 @@ def log_create_complete_with_getter( cls (VertexAiResourceNoun): Vertex AI Resource Noun class that is being created. resource (proto.Message): - Vertex AI Resourc proto.Message + Vertex AI Resource proto.Message variable_name (str): Name of variable to use for code snippet """ self._logger.info(f"{cls.__name__} created. Resource name: {resource.name}") @@ -391,7 +401,6 @@ class VertexAiResourceNoun(metaclass=abc.ABCMeta): Subclasses require two class attributes: client_class: The client to instantiate to interact with this resource noun. - _is_client_prediction_client: Flag to indicate if the client requires a prediction endpoint. Subclass is required to populate private attribute _gca_resource which is the service representation of the resource noun. @@ -408,29 +417,43 @@ def client_class(cls) -> Type[utils.VertexAiServiceClientWithOverride]: @property @classmethod @abc.abstractmethod - def _is_client_prediction_client(cls) -> bool: - """Flag to indicate whether to use prediction endpoint with client.""" - pass - - @property - @abc.abstractmethod def _getter_method(cls) -> str: """Name of getter method of client class for retrieving the resource.""" pass @property + @classmethod @abc.abstractmethod def _delete_method(cls) -> str: """Name of delete method of client class for deleting the resource.""" pass @property + @classmethod @abc.abstractmethod def _resource_noun(cls) -> str: """Resource noun.""" pass + @property + @classmethod + @abc.abstractmethod + def _parse_resource_name_method(cls) -> str: + """Method name on GAPIC client to parse a resource name.""" + pass + + @property + @classmethod + @abc.abstractmethod + def _format_resource_name_method(self) -> str: + """Method name on GAPIC client to format a resource name.""" + pass + + # Override this value with staticmethod + # to use custom resource id validators per resource + _resource_id_validator: Optional[Callable[[str], None]] = None + def __init__( self, project: Optional[str] = None, @@ -443,7 +466,7 @@ def __init__( Args: project(str): Project of the resource noun. location(str): The location of the resource noun. - credentials(google.auth.crendentials.Crendentials): Optional custom + credentials(google.auth.credentials.Credentials): Optional custom credentials to use when accessing interacting with resource noun. resource_name(str): A fully-qualified resource name or ID. """ @@ -480,15 +503,48 @@ def _instantiate_client( client_class=cls.client_class, credentials=credentials, location_override=location, - prediction_client=cls._is_client_prediction_client, ) + @classmethod + def _parse_resource_name(cls, resource_name: str) -> Dict[str, str]: + """ + Parses resource name into its component segments. + + Args: + resource_name: Resource name of this resource. + Returns: + Dictionary of component segments. + """ + # gets the underlying wrapped gapic client class + return getattr( + cls.client_class.get_gapic_client_class(), cls._parse_resource_name_method + )(resource_name) + + @classmethod + def _format_resource_name(cls, **kwargs: str) -> str: + """ + Formats a resource name using its component segments. + + Args: + **kwargs: Resource name parts. Singular and snake case. ie: + format_resource_name( + project='my-project', + location='us-central1' + ) + Returns: + Resource name. + """ + # gets the underlying wrapped gapic client class + return getattr( + cls.client_class.get_gapic_client_class(), cls._format_resource_name_method + )(**kwargs) + def _get_and_validate_project_location( self, resource_name: str, project: Optional[str] = None, location: Optional[str] = None, - ) -> Tuple: + ) -> Tuple[str, str]: """Validate the project and location for the resource. @@ -498,39 +554,50 @@ def _get_and_validate_project_location( location(str): The location of the resource noun. Raises: - RuntimeError if location is different from resource location + RuntimeError: If location is different from resource location """ - fields = utils.extract_fields_from_resource_name( - resource_name, self._resource_noun - ) + fields = self._parse_resource_name(resource_name) + if not fields: return project, location - if location and fields.location != location: + if location and fields["location"] != location: raise RuntimeError( f"location {location} is provided, but different from " - f"the resource location {fields.location}" + f"the resource location {fields['location']}" ) - return fields.project, fields.location + return fields["project"], fields["location"] + + def _get_gca_resource( + self, + resource_name: str, + parent_resource_name_fields: Optional[Dict[str, str]] = None, + ) -> proto.Message: + """Returns GAPIC service representation of client class resource. - def _get_gca_resource(self, resource_name: str) -> proto.Message: - """Returns GAPIC service representation of client class resource.""" - """ Args: - resource_name (str): - Required. A fully-qualified resource name or ID. + resource_name (str): Required. A fully-qualified resource name or ID. + parent_resource_name_fields (Dict[str,str]): + Optional. Mapping of parent resource name key to values. These + will be used to compose the resource name if only resource ID is given. + Should not include project and location. """ - resource_name = utils.full_resource_name( resource_name=resource_name, resource_noun=self._resource_noun, + parse_resource_name_method=self._parse_resource_name, + format_resource_name_method=self._format_resource_name, project=self.project, location=self.location, + parent_resource_name_fields=parent_resource_name_fields, + resource_id_validator=self._resource_id_validator, ) - return getattr(self.api_client, self._getter_method)(name=resource_name) + return getattr(self.api_client, self._getter_method)( + name=resource_name, retry=_DEFAULT_RETRY + ) def _sync_gca_resource(self): """Sync GAPIC service representation of client class resource.""" @@ -540,21 +607,44 @@ def _sync_gca_resource(self): @property def name(self) -> str: """Name of this resource.""" + self._assert_gca_resource_is_available() return self._gca_resource.name.split("/")[-1] + @property + def _project_tuple(self) -> Tuple[Optional[str], Optional[str]]: + """Returns the tuple of project id and project inferred from the local instance. + + Another option is to use resource_manager_utils but requires the caller have resource manager + get role. + """ + # we may not have the project if project inferred from the resource name + maybe_project_id = self.project + if self._gca_resource is not None and self._gca_resource.name: + project_no = self._parse_resource_name(self._gca_resource.name)["project"] + else: + project_no = None + + if maybe_project_id == project_no: + return (None, project_no) + else: + return (maybe_project_id, project_no) + @property def resource_name(self) -> str: """Full qualified resource name.""" + self._assert_gca_resource_is_available() return self._gca_resource.name @property def display_name(self) -> str: """Display name of this resource.""" + self._assert_gca_resource_is_available() return self._gca_resource.display_name @property def create_time(self) -> datetime.datetime: """Time this resource was created.""" + self._assert_gca_resource_is_available() return self._gca_resource.create_time @property @@ -563,14 +653,65 @@ def update_time(self) -> datetime.datetime: self._sync_gca_resource() return self._gca_resource.update_time + @property + def encryption_spec(self) -> Optional[gca_encryption_spec.EncryptionSpec]: + """Customer-managed encryption key options for this Vertex AI resource. + + If this is set, then all resources created by this Vertex AI resource will + be encrypted with the provided encryption key. + """ + self._assert_gca_resource_is_available() + return getattr(self._gca_resource, "encryption_spec") + + @property + def labels(self) -> Dict[str, str]: + """User-defined labels containing metadata about this resource. + + Read more about labels at https://goo.gl/xmQnxf + """ + self._assert_gca_resource_is_available() + return dict(self._gca_resource.labels) + @property def gca_resource(self) -> proto.Message: - """The underlying resource proto represenation.""" + """The underlying resource proto representation.""" + self._assert_gca_resource_is_available() return self._gca_resource + @property + def _resource_is_available(self) -> bool: + """Returns True if GCA resource has been created and is available, otherwise False""" + try: + self._assert_gca_resource_is_available() + return True + except RuntimeError: + return False + + def _assert_gca_resource_is_available(self) -> None: + """Helper method to raise when property is not accessible. + + Raises: + RuntimeError: If _gca_resource is has not been created. + """ + if self._gca_resource is None: + raise RuntimeError( + f"{self.__class__.__name__} resource has not been created" + ) + def __repr__(self) -> str: return f"{object.__repr__(self)} \nresource name: {self.resource_name}" + def to_dict(self) -> Dict[str, Any]: + """Returns the resource proto as a dictionary.""" + return json_format.MessageToDict(self.gca_resource._pb) + + @classmethod + def _generate_display_name(cls, prefix: Optional[str] = None) -> str: + """Returns a display name containing class name and time string.""" + if not prefix: + prefix = cls.__name__ + return prefix + " " + datetime.datetime.now().isoformat(sep=" ") + def optional_sync( construct_object_on_arg: Optional[str] = None, @@ -624,7 +765,7 @@ def wrapper(*args, **kwargs): # if sync then wait for any Futures to complete and execute if sync: if self: - self.wait() + VertexAiResourceNounWithFutureManager.wait(self) return method(*args, **kwargs) # callbacks to call within the Future (in same Thread) @@ -639,17 +780,21 @@ def wrapper(*args, **kwargs): inspect.getfullargspec(method).annotations["return"] ) + # object produced by the method + returned_object = bound_args.arguments.get(return_input_arg) + # is a classmethod that creates the object and returns it if args and inspect.isclass(args[0]): - # assumes classmethod is our resource noun - returned_object = args[0]._empty_constructor() + + # assumes class in classmethod is the resource noun + returned_object = ( + args[0]._empty_constructor() + if not returned_object + else returned_object + ) self = returned_object else: # instance method - - # object produced by the method - returned_object = bound_args.arguments.get(return_input_arg) - # if we're returning an input object if returned_object and returned_object is not self: @@ -727,7 +872,7 @@ def __init__( Args: project (str): Optional. Project of the resource noun. location (str): Optional. The location of the resource noun. - credentials(google.auth.crendentials.Crendentials): + credentials(google.auth.credentials.Credentials): Optional. custom credentials to use when accessing interacting with resource noun. resource_name(str): A fully-qualified resource name or ID. @@ -757,7 +902,7 @@ def _empty_constructor( Args: project (str): Optional. Project of the resource noun. location (str): Optional. The location of the resource noun. - credentials(google.auth.crendentials.Crendentials): + credentials(google.auth.credentials.Credentials): Optional. custom credentials to use when accessing interacting with resource noun. resource_name(str): A fully-qualified resource name or ID. @@ -802,8 +947,9 @@ def _sync_object_with_future_result( if value: setattr(self, attribute, value) + @classmethod def _construct_sdk_resource_from_gapic( - self, + cls, gapic_resource: proto.Message, project: Optional[str] = None, location: Optional[str] = None, @@ -813,7 +959,7 @@ def _construct_sdk_resource_from_gapic( Args: gapic_resource (proto.Message): - A GAPIC representation of an Vertex AI resource, usually + A GAPIC representation of a Vertex AI resource, usually retrieved by a get_* or in a list_* API call. project (str): Optional. Project to construct SDK object from. If not set, @@ -829,7 +975,7 @@ def _construct_sdk_resource_from_gapic( VertexAiResourceNoun: An initialized SDK object that represents GAPIC type. """ - sdk_resource = self._empty_constructor( + sdk_resource = cls._empty_constructor( project=project, location=location, credentials=credentials ) sdk_resource._gca_resource = gapic_resource @@ -846,6 +992,7 @@ def _list( project: Optional[str] = None, location: Optional[str] = None, credentials: Optional[auth_credentials.Credentials] = None, + parent: Optional[str] = None, ) -> List[VertexAiResourceNoun]: """Private method to list all instances of this Vertex AI Resource, takes a `cls_filter` arg to filter to a particular SDK resource @@ -873,21 +1020,24 @@ def _list( credentials (auth_credentials.Credentials): Optional. Custom credentials to use to retrieve list. Overrides credentials set in aiplatform.init. + parent (str): + Optional. The parent resource name if any to retrieve resource list from. Returns: List[VertexAiResourceNoun] - A list of SDK resource objects """ - self = cls._empty_constructor( + resource = cls._empty_constructor( project=project, location=location, credentials=credentials ) # Fetch credentials once and re-use for all `_empty_constructor()` calls - creds = initializer.global_config.credentials + creds = resource.credentials - resource_list_method = getattr(self.api_client, self._list_method) + resource_list_method = getattr(resource.api_client, resource._list_method) list_request = { - "parent": initializer.global_config.common_location_path( + "parent": parent + or initializer.global_config.common_location_path( project=project, location=location ), "filter": filter, @@ -899,7 +1049,7 @@ def _list( resource_list = resource_list_method(request=list_request) or [] return [ - self._construct_sdk_resource_from_gapic( + cls._construct_sdk_resource_from_gapic( gapic_resource, project=project, location=location, credentials=creds ) for gapic_resource in resource_list @@ -977,6 +1127,7 @@ def list( project: Optional[str] = None, location: Optional[str] = None, credentials: Optional[auth_credentials.Credentials] = None, + parent: Optional[str] = None, ) -> List[VertexAiResourceNoun]: """List all instances of this Vertex AI Resource. @@ -1005,6 +1156,8 @@ def list( credentials (auth_credentials.Credentials): Optional. Custom credentials to use to retrieve list. Overrides credentials set in aiplatform.init. + parent (str): + Optional. The parent resource name if any to retrieve list from. Returns: List[VertexAiResourceNoun] - A list of SDK resource objects @@ -1016,12 +1169,13 @@ def list( project=project, location=location, credentials=credentials, + parent=parent, ) @optional_sync() def delete(self, sync: bool = True) -> None: """Deletes this Vertex AI resource. WARNING: This deletion is - permament. + permanent. Args: sync (bool): @@ -1038,11 +1192,61 @@ def delete(self, sync: bool = True) -> None: _LOGGER.log_action_completed_against_resource("deleted.", "", self) def __repr__(self) -> str: - if self._gca_resource: + if self._gca_resource and self._resource_is_available: return VertexAiResourceNoun.__repr__(self) return FutureManager.__repr__(self) + def _wait_for_resource_creation(self) -> None: + """Wait until underlying resource is created. + + Currently this should only be used on subclasses that implement the construct then + `run` pattern because the underlying sync=False implementation will not update + downstream resource noun object's _gca_resource until the entire invoked method is complete. + + Ex: + job = CustomTrainingJob() + job.run(sync=False, ...) + job._wait_for_resource_creation() + Raises: + RuntimeError: If the resource has not been scheduled to be created. + """ + + # If the user calls this but didn't actually invoke an API to create + if self._are_futures_done() and not getattr(self._gca_resource, "name", None): + self._raise_future_exception() + raise RuntimeError( + f"{self.__class__.__name__} resource is not scheduled to be created." + ) + + while not getattr(self._gca_resource, "name", None): + # breaks out of loop if creation has failed async + if self._are_futures_done() and not getattr( + self._gca_resource, "name", None + ): + self._raise_future_exception() + + time.sleep(1) + + def _assert_gca_resource_is_available(self) -> None: + """Helper method to raise when accessing properties that do not exist. + + Overrides VertexAiResourceNoun to provide a more informative exception if + resource creation has failed asynchronously. + + Raises: + RuntimeError: When resource has not been created. + """ + if not getattr(self._gca_resource, "name", None): + raise RuntimeError( + f"{self.__class__.__name__} resource has not been created." + + ( + f" Resource failed with: {self._exception}" + if self._exception + else "" + ) + ) + def get_annotation_class(annotation: type) -> type: """Helper method to retrieve type annotation. @@ -1055,3 +1259,58 @@ def get_annotation_class(annotation: type) -> type: return annotation.__args__[0] else: return annotation + + +class DoneMixin(abc.ABC): + """An abstract class for implementing a done method, indicating + whether a job has completed. + + """ + + @abc.abstractmethod + def done(self) -> bool: + """Method indicating whether a job has completed.""" + pass + + +class StatefulResource(DoneMixin): + """Extends DoneMixin to check whether a job returning a stateful resource has compted.""" + + @property + @abc.abstractmethod + def state(self): + """The current state of the job.""" + pass + + @property + @classmethod + @abc.abstractmethod + def _valid_done_states(cls): + """A set() containing all job states associated with a completed job.""" + pass + + def done(self) -> bool: + """Method indicating whether a job has completed. + + Returns: + True if the job has completed. + """ + if self.state in self._valid_done_states: + return True + else: + return False + + +class VertexAiStatefulResource(VertexAiResourceNounWithFutureManager, StatefulResource): + """Extends StatefulResource to include a check for self._gca_resource.""" + + def done(self) -> bool: + """Method indicating whether a job has completed. + + Returns: + True if the job has completed. + """ + if self._gca_resource and self._gca_resource.name: + return super().done() + else: + return False diff --git a/google/cloud/aiplatform/compat/__init__.py b/google/cloud/aiplatform/compat/__init__.py index 55a72fea16..02e66ec494 100644 --- a/google/cloud/aiplatform/compat/__init__.py +++ b/google/cloud/aiplatform/compat/__init__.py @@ -27,6 +27,10 @@ services.dataset_service_client = services.dataset_service_client_v1beta1 services.endpoint_service_client = services.endpoint_service_client_v1beta1 + services.featurestore_online_serving_service_client = ( + services.featurestore_online_serving_service_client_v1beta1 + ) + services.featurestore_service_client = services.featurestore_service_client_v1beta1 services.job_service_client = services.job_service_client_v1beta1 services.model_service_client = services.model_service_client_v1beta1 services.pipeline_service_client = services.pipeline_service_client_v1beta1 @@ -36,12 +40,18 @@ ) services.metadata_service_client = services.metadata_service_client_v1beta1 services.tensorboard_service_client = services.tensorboard_service_client_v1beta1 + services.index_service_client = services.index_service_client_v1beta1 + services.index_endpoint_service_client = ( + services.index_endpoint_service_client_v1beta1 + ) types.accelerator_type = types.accelerator_type_v1beta1 types.annotation = types.annotation_v1beta1 types.annotation_spec = types.annotation_spec_v1beta1 + types.artifact = types.artifact_v1beta1 types.batch_prediction_job = types.batch_prediction_job_v1beta1 types.completion_stats = types.completion_stats_v1beta1 + types.context = types.context_v1beta1 types.custom_job = types.custom_job_v1beta1 types.data_item = types.data_item_v1beta1 types.data_labeling_job = types.data_labeling_job_v1beta1 @@ -51,50 +61,83 @@ types.encryption_spec = types.encryption_spec_v1beta1 types.endpoint = types.endpoint_v1beta1 types.endpoint_service = types.endpoint_service_v1beta1 + types.entity_type = types.entity_type_v1beta1 types.env_var = types.env_var_v1beta1 + types.event = types.event_v1beta1 + types.execution = types.execution_v1beta1 types.explanation = types.explanation_v1beta1 types.explanation_metadata = types.explanation_metadata_v1beta1 + types.feature = types.feature_v1beta1 + types.feature_monitoring_stats = types.feature_monitoring_stats_v1beta1 + types.feature_selector = types.feature_selector_v1beta1 + types.featurestore = types.featurestore_v1beta1 + types.featurestore_monitoring = types.featurestore_monitoring_v1beta1 + types.featurestore_online_service = types.featurestore_online_service_v1beta1 + types.featurestore_service = types.featurestore_service_v1beta1 types.hyperparameter_tuning_job = types.hyperparameter_tuning_job_v1beta1 + types.index = types.index_v1beta1 + types.index_endpoint = types.index_endpoint_v1beta1 types.io = types.io_v1beta1 types.job_service = types.job_service_v1beta1 types.job_state = types.job_state_v1beta1 + types.lineage_subgraph = types.lineage_subgraph_v1beta1 types.machine_resources = types.machine_resources_v1beta1 types.manual_batch_tuning_parameters = types.manual_batch_tuning_parameters_v1beta1 + types.matching_engine_deployed_index_ref = ( + types.matching_engine_deployed_index_ref_v1beta1 + ) + types.matching_engine_index = types.index_v1beta1 + types.matching_engine_index_endpoint = types.index_endpoint_v1beta1 + types.metadata_service = types.metadata_service_v1beta1 + types.metadata_schema = types.metadata_schema_v1beta1 + types.metadata_store = types.metadata_store_v1beta1 types.model = types.model_v1beta1 types.model_evaluation = types.model_evaluation_v1beta1 types.model_evaluation_slice = types.model_evaluation_slice_v1beta1 types.model_service = types.model_service_v1beta1 types.operation = types.operation_v1beta1 + types.pipeline_failure_policy = types.pipeline_failure_policy_v1beta1 + types.pipeline_job = types.pipeline_job_v1beta1 types.pipeline_service = types.pipeline_service_v1beta1 types.pipeline_state = types.pipeline_state_v1beta1 types.prediction_service = types.prediction_service_v1beta1 types.specialist_pool = types.specialist_pool_v1beta1 types.specialist_pool_service = types.specialist_pool_service_v1beta1 types.study = types.study_v1beta1 - types.training_pipeline = types.training_pipeline_v1beta1 - types.metadata_service = types.metadata_service_v1beta1 + types.tensorboard = types.tensorboard_v1beta1 types.tensorboard_service = types.tensorboard_service_v1beta1 types.tensorboard_data = types.tensorboard_data_v1beta1 types.tensorboard_experiment = types.tensorboard_experiment_v1beta1 types.tensorboard_run = types.tensorboard_run_v1beta1 types.tensorboard_service = types.tensorboard_service_v1beta1 types.tensorboard_time_series = types.tensorboard_time_series_v1beta1 + types.training_pipeline = types.training_pipeline_v1beta1 + types.types = types.types_v1beta1 if DEFAULT_VERSION == V1: services.dataset_service_client = services.dataset_service_client_v1 services.endpoint_service_client = services.endpoint_service_client_v1 + services.featurestore_online_serving_service_client = ( + services.featurestore_online_serving_service_client_v1 + ) + services.featurestore_service_client = services.featurestore_service_client_v1 services.job_service_client = services.job_service_client_v1 services.model_service_client = services.model_service_client_v1 services.pipeline_service_client = services.pipeline_service_client_v1 services.prediction_service_client = services.prediction_service_client_v1 services.specialist_pool_service_client = services.specialist_pool_service_client_v1 + services.tensorboard_service_client = services.tensorboard_service_client_v1 + services.index_service_client = services.index_service_client_v1 + services.index_endpoint_service_client = services.index_endpoint_service_client_v1 types.accelerator_type = types.accelerator_type_v1 types.annotation = types.annotation_v1 types.annotation_spec = types.annotation_spec_v1 + types.artifact = types.artifact_v1 types.batch_prediction_job = types.batch_prediction_job_v1 types.completion_stats = types.completion_stats_v1 + types.context = types.context_v1 types.custom_job = types.custom_job_v1 types.data_item = types.data_item_v1 types.data_labeling_job = types.data_labeling_job_v1 @@ -104,25 +147,57 @@ types.encryption_spec = types.encryption_spec_v1 types.endpoint = types.endpoint_v1 types.endpoint_service = types.endpoint_service_v1 + types.entity_type = types.entity_type_v1 types.env_var = types.env_var_v1 + types.event = types.event_v1 + types.execution = types.execution_v1 + types.explanation = types.explanation_v1 + types.explanation_metadata = types.explanation_metadata_v1 + types.feature = types.feature_v1 + types.feature_monitoring_stats = types.feature_monitoring_stats_v1 + types.feature_selector = types.feature_selector_v1 + types.featurestore = types.featurestore_v1 + types.featurestore_online_service = types.featurestore_online_service_v1 + types.featurestore_service = types.featurestore_service_v1 types.hyperparameter_tuning_job = types.hyperparameter_tuning_job_v1 + types.index = types.index_v1 + types.index_endpoint = types.index_endpoint_v1 types.io = types.io_v1 types.job_service = types.job_service_v1 types.job_state = types.job_state_v1 + types.lineage_subgraph = types.lineage_subgraph_v1 types.machine_resources = types.machine_resources_v1 types.manual_batch_tuning_parameters = types.manual_batch_tuning_parameters_v1 + types.matching_engine_deployed_index_ref = ( + types.matching_engine_deployed_index_ref_v1 + ) + types.matching_engine_index = types.index_v1 + types.matching_engine_index_endpoint = types.index_endpoint_v1 + types.metadata_service = types.metadata_service_v1 + types.metadata_schema = types.metadata_schema_v1 + types.metadata_store = types.metadata_store_v1 types.model = types.model_v1 types.model_evaluation = types.model_evaluation_v1 types.model_evaluation_slice = types.model_evaluation_slice_v1 types.model_service = types.model_service_v1 types.operation = types.operation_v1 + types.pipeline_failure_policy = types.pipeline_failure_policy_v1 + types.pipeline_job = types.pipeline_job_v1 types.pipeline_service = types.pipeline_service_v1 types.pipeline_state = types.pipeline_state_v1 types.prediction_service = types.prediction_service_v1 types.specialist_pool = types.specialist_pool_v1 types.specialist_pool_service = types.specialist_pool_service_v1 types.study = types.study_v1 + types.tensorboard = types.tensorboard_v1 + types.tensorboard_service = types.tensorboard_service_v1 + types.tensorboard_data = types.tensorboard_data_v1 + types.tensorboard_experiment = types.tensorboard_experiment_v1 + types.tensorboard_run = types.tensorboard_run_v1 + types.tensorboard_service = types.tensorboard_service_v1 + types.tensorboard_time_series = types.tensorboard_time_series_v1 types.training_pipeline = types.training_pipeline_v1 + types.types = types.types_v1 __all__ = ( DEFAULT_VERSION, diff --git a/google/cloud/aiplatform/compat/services/__init__.py b/google/cloud/aiplatform/compat/services/__init__.py index 5c104ab41f..68440de4c5 100644 --- a/google/cloud/aiplatform/compat/services/__init__.py +++ b/google/cloud/aiplatform/compat/services/__init__.py @@ -21,9 +21,24 @@ from google.cloud.aiplatform_v1beta1.services.endpoint_service import ( client as endpoint_service_client_v1beta1, ) +from google.cloud.aiplatform_v1beta1.services.featurestore_online_serving_service import ( + client as featurestore_online_serving_service_client_v1beta1, +) +from google.cloud.aiplatform_v1beta1.services.featurestore_service import ( + client as featurestore_service_client_v1beta1, +) +from google.cloud.aiplatform_v1beta1.services.index_service import ( + client as index_service_client_v1beta1, +) +from google.cloud.aiplatform_v1beta1.services.index_endpoint_service import ( + client as index_endpoint_service_client_v1beta1, +) from google.cloud.aiplatform_v1beta1.services.job_service import ( client as job_service_client_v1beta1, ) +from google.cloud.aiplatform_v1beta1.services.metadata_service import ( + client as metadata_service_client_v1beta1, +) from google.cloud.aiplatform_v1beta1.services.model_service import ( client as model_service_client_v1beta1, ) @@ -36,9 +51,6 @@ from google.cloud.aiplatform_v1beta1.services.specialist_pool_service import ( client as specialist_pool_service_client_v1beta1, ) -from google.cloud.aiplatform_v1beta1.services.metadata_service import ( - client as metadata_service_client_v1beta1, -) from google.cloud.aiplatform_v1beta1.services.tensorboard_service import ( client as tensorboard_service_client_v1beta1, ) @@ -49,9 +61,24 @@ from google.cloud.aiplatform_v1.services.endpoint_service import ( client as endpoint_service_client_v1, ) +from google.cloud.aiplatform_v1.services.featurestore_online_serving_service import ( + client as featurestore_online_serving_service_client_v1, +) +from google.cloud.aiplatform_v1.services.featurestore_service import ( + client as featurestore_service_client_v1, +) +from google.cloud.aiplatform_v1.services.index_service import ( + client as index_service_client_v1, +) +from google.cloud.aiplatform_v1.services.index_endpoint_service import ( + client as index_endpoint_service_client_v1, +) from google.cloud.aiplatform_v1.services.job_service import ( client as job_service_client_v1, ) +from google.cloud.aiplatform_v1.services.metadata_service import ( + client as metadata_service_client_v1, +) from google.cloud.aiplatform_v1.services.model_service import ( client as model_service_client_v1, ) @@ -64,19 +91,32 @@ from google.cloud.aiplatform_v1.services.specialist_pool_service import ( client as specialist_pool_service_client_v1, ) +from google.cloud.aiplatform_v1.services.tensorboard_service import ( + client as tensorboard_service_client_v1, +) __all__ = ( # v1 dataset_service_client_v1, endpoint_service_client_v1, + featurestore_online_serving_service_client_v1, + featurestore_service_client_v1, + index_service_client_v1, + index_endpoint_service_client_v1, job_service_client_v1, + metadata_service_client_v1, model_service_client_v1, pipeline_service_client_v1, prediction_service_client_v1, specialist_pool_service_client_v1, + tensorboard_service_client_v1, # v1beta1 dataset_service_client_v1beta1, endpoint_service_client_v1beta1, + featurestore_online_serving_service_client_v1beta1, + featurestore_service_client_v1beta1, + index_service_client_v1beta1, + index_endpoint_service_client_v1beta1, job_service_client_v1beta1, model_service_client_v1beta1, pipeline_service_client_v1beta1, diff --git a/google/cloud/aiplatform/compat/types/__init__.py b/google/cloud/aiplatform/compat/types/__init__.py index 7bd512e7e8..25c7515877 100644 --- a/google/cloud/aiplatform/compat/types/__init__.py +++ b/google/cloud/aiplatform/compat/types/__init__.py @@ -19,80 +19,130 @@ accelerator_type as accelerator_type_v1beta1, annotation as annotation_v1beta1, annotation_spec as annotation_spec_v1beta1, + artifact as artifact_v1beta1, batch_prediction_job as batch_prediction_job_v1beta1, completion_stats as completion_stats_v1beta1, + context as context_v1beta1, custom_job as custom_job_v1beta1, data_item as data_item_v1beta1, data_labeling_job as data_labeling_job_v1beta1, dataset as dataset_v1beta1, dataset_service as dataset_service_v1beta1, + deployed_index_ref as matching_engine_deployed_index_ref_v1beta1, deployed_model_ref as deployed_model_ref_v1beta1, encryption_spec as encryption_spec_v1beta1, endpoint as endpoint_v1beta1, endpoint_service as endpoint_service_v1beta1, + entity_type as entity_type_v1beta1, env_var as env_var_v1beta1, + event as event_v1beta1, + execution as execution_v1beta1, explanation as explanation_v1beta1, explanation_metadata as explanation_metadata_v1beta1, + feature as feature_v1beta1, + feature_monitoring_stats as feature_monitoring_stats_v1beta1, + feature_selector as feature_selector_v1beta1, + featurestore as featurestore_v1beta1, + featurestore_monitoring as featurestore_monitoring_v1beta1, + featurestore_online_service as featurestore_online_service_v1beta1, + featurestore_service as featurestore_service_v1beta1, + index as index_v1beta1, + index_endpoint as index_endpoint_v1beta1, hyperparameter_tuning_job as hyperparameter_tuning_job_v1beta1, io as io_v1beta1, job_service as job_service_v1beta1, job_state as job_state_v1beta1, + lineage_subgraph as lineage_subgraph_v1beta1, machine_resources as machine_resources_v1beta1, manual_batch_tuning_parameters as manual_batch_tuning_parameters_v1beta1, + metadata_schema as metadata_schema_v1beta1, + metadata_service as metadata_service_v1beta1, + metadata_store as metadata_store_v1beta1, model as model_v1beta1, model_evaluation as model_evaluation_v1beta1, model_evaluation_slice as model_evaluation_slice_v1beta1, model_service as model_service_v1beta1, operation as operation_v1beta1, + pipeline_failure_policy as pipeline_failure_policy_v1beta1, + pipeline_job as pipeline_job_v1beta1, pipeline_service as pipeline_service_v1beta1, pipeline_state as pipeline_state_v1beta1, prediction_service as prediction_service_v1beta1, specialist_pool as specialist_pool_v1beta1, specialist_pool_service as specialist_pool_service_v1beta1, study as study_v1beta1, - training_pipeline as training_pipeline_v1beta1, - metadata_service as metadata_service_v1beta1, - tensorboard_service as tensorboard_service_v1beta1, + tensorboard as tensorboard_v1beta1, tensorboard_data as tensorboard_data_v1beta1, tensorboard_experiment as tensorboard_experiment_v1beta1, tensorboard_run as tensorboard_run_v1beta1, tensorboard_service as tensorboard_service_v1beta1, tensorboard_time_series as tensorboard_time_series_v1beta1, + training_pipeline as training_pipeline_v1beta1, + types as types_v1beta1, ) from google.cloud.aiplatform_v1.types import ( accelerator_type as accelerator_type_v1, annotation as annotation_v1, annotation_spec as annotation_spec_v1, + artifact as artifact_v1, batch_prediction_job as batch_prediction_job_v1, completion_stats as completion_stats_v1, + context as context_v1, custom_job as custom_job_v1, data_item as data_item_v1, data_labeling_job as data_labeling_job_v1, dataset as dataset_v1, dataset_service as dataset_service_v1, + deployed_index_ref as matching_engine_deployed_index_ref_v1, deployed_model_ref as deployed_model_ref_v1, encryption_spec as encryption_spec_v1, endpoint as endpoint_v1, endpoint_service as endpoint_service_v1, + entity_type as entity_type_v1, env_var as env_var_v1, + event as event_v1, + execution as execution_v1, + explanation as explanation_v1, + explanation_metadata as explanation_metadata_v1, + feature as feature_v1, + feature_monitoring_stats as feature_monitoring_stats_v1, + feature_selector as feature_selector_v1, + featurestore as featurestore_v1, + featurestore_online_service as featurestore_online_service_v1, + featurestore_service as featurestore_service_v1, hyperparameter_tuning_job as hyperparameter_tuning_job_v1, + index as index_v1, + index_endpoint as index_endpoint_v1, io as io_v1, job_service as job_service_v1, job_state as job_state_v1, + lineage_subgraph as lineage_subgraph_v1, machine_resources as machine_resources_v1, manual_batch_tuning_parameters as manual_batch_tuning_parameters_v1, + metadata_service as metadata_service_v1, + metadata_schema as metadata_schema_v1, + metadata_store as metadata_store_v1, model as model_v1, model_evaluation as model_evaluation_v1, model_evaluation_slice as model_evaluation_slice_v1, model_service as model_service_v1, operation as operation_v1, + pipeline_failure_policy as pipeline_failure_policy_v1, + pipeline_job as pipeline_job_v1, pipeline_service as pipeline_service_v1, pipeline_state as pipeline_state_v1, prediction_service as prediction_service_v1, specialist_pool as specialist_pool_v1, specialist_pool_service as specialist_pool_service_v1, study as study_v1, + tensorboard as tensorboard_v1, + tensorboard_data as tensorboard_data_v1, + tensorboard_experiment as tensorboard_experiment_v1, + tensorboard_run as tensorboard_run_v1, + tensorboard_service as tensorboard_service_v1, + tensorboard_time_series as tensorboard_time_series_v1, training_pipeline as training_pipeline_v1, + types as types_v1, ) __all__ = ( @@ -100,8 +150,10 @@ accelerator_type_v1, annotation_v1, annotation_spec_v1, + artifact_v1, batch_prediction_job_v1, completion_stats_v1, + context_v1, custom_job_v1, data_item_v1, data_labeling_job_v1, @@ -111,30 +163,59 @@ encryption_spec_v1, endpoint_v1, endpoint_service_v1, + entity_type_v1, env_var_v1, + event_v1, + execution_v1, + explanation_v1, + explanation_metadata_v1, + feature_v1, + feature_monitoring_stats_v1, + feature_selector_v1, + featurestore_v1, + featurestore_online_service_v1, + featurestore_service_v1, hyperparameter_tuning_job_v1, io_v1, job_service_v1, job_state_v1, + lineage_subgraph_v1, machine_resources_v1, manual_batch_tuning_parameters_v1, + matching_engine_deployed_index_ref_v1, + index_v1, + index_endpoint_v1, + metadata_service_v1, + metadata_schema_v1, + metadata_store_v1, model_v1, model_evaluation_v1, model_evaluation_slice_v1, model_service_v1, operation_v1, + pipeline_failure_policy_v1beta1, + pipeline_job_v1, pipeline_service_v1, pipeline_state_v1, prediction_service_v1, specialist_pool_v1, specialist_pool_service_v1, + tensorboard_v1, + tensorboard_data_v1, + tensorboard_experiment_v1, + tensorboard_run_v1, + tensorboard_service_v1, + tensorboard_time_series_v1, training_pipeline_v1, + types_v1, # v1beta1 accelerator_type_v1beta1, annotation_v1beta1, annotation_spec_v1beta1, + artifact_v1beta1, batch_prediction_job_v1beta1, completion_stats_v1beta1, + context_v1beta1, custom_job_v1beta1, data_item_v1beta1, data_labeling_job_v1beta1, @@ -144,31 +225,50 @@ encryption_spec_v1beta1, endpoint_v1beta1, endpoint_service_v1beta1, + entity_type_v1beta1, env_var_v1beta1, + event_v1beta1, + execution_v1beta1, explanation_v1beta1, explanation_metadata_v1beta1, + feature_v1beta1, + feature_monitoring_stats_v1beta1, + feature_selector_v1beta1, + featurestore_v1beta1, + featurestore_monitoring_v1beta1, + featurestore_online_service_v1beta1, + featurestore_service_v1beta1, hyperparameter_tuning_job_v1beta1, io_v1beta1, job_service_v1beta1, job_state_v1beta1, + lineage_subgraph_v1beta1, machine_resources_v1beta1, manual_batch_tuning_parameters_v1beta1, + matching_engine_deployed_index_ref_v1beta1, + index_v1beta1, + index_endpoint_v1beta1, + metadata_service_v1beta1, + metadata_schema_v1beta1, + metadata_store_v1beta1, model_v1beta1, model_evaluation_v1beta1, model_evaluation_slice_v1beta1, model_service_v1beta1, operation_v1beta1, + pipeline_failure_policy_v1beta1, + pipeline_job_v1beta1, pipeline_service_v1beta1, pipeline_state_v1beta1, prediction_service_v1beta1, specialist_pool_v1beta1, specialist_pool_service_v1beta1, - training_pipeline_v1beta1, - metadata_service_v1beta1, - tensorboard_service_v1beta1, + tensorboard_v1beta1, tensorboard_data_v1beta1, tensorboard_experiment_v1beta1, tensorboard_run_v1beta1, tensorboard_service_v1beta1, tensorboard_time_series_v1beta1, + training_pipeline_v1beta1, + types_v1beta1, ) diff --git a/google/cloud/aiplatform/constants/__init__.py b/google/cloud/aiplatform/constants/__init__.py new file mode 100644 index 0000000000..95f437a335 --- /dev/null +++ b/google/cloud/aiplatform/constants/__init__.py @@ -0,0 +1,18 @@ +# 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.aiplatform.constants import base +from google.cloud.aiplatform.constants import prediction + +__all__ = ("base", "prediction") diff --git a/google/cloud/aiplatform/constants.py b/google/cloud/aiplatform/constants/base.py similarity index 92% rename from google/cloud/aiplatform/constants.py rename to google/cloud/aiplatform/constants/base.py index a7d81084cd..230918d564 100644 --- a/google/cloud/aiplatform/constants.py +++ b/google/cloud/aiplatform/constants/base.py @@ -18,21 +18,30 @@ DEFAULT_REGION = "us-central1" SUPPORTED_REGIONS = { "asia-east1", + "asia-east2", "asia-northeast1", "asia-northeast3", + "asia-south1", "asia-southeast1", "australia-southeast1", "europe-west1", "europe-west2", + "europe-west3", "europe-west4", + "europe-west6", "northamerica-northeast1", + "northamerica-northeast2", "us-central1", "us-east1", "us-east4", "us-west1", + "us-west2", + "us-west4", + "southamerica-east1", } API_BASE_PATH = "aiplatform.googleapis.com" +PREDICTION_API_BASE_PATH = API_BASE_PATH # Batch Prediction BATCH_PREDICTION_INPUT_STORAGE_FORMATS = ( diff --git a/google/cloud/aiplatform/constants/prediction.py b/google/cloud/aiplatform/constants/prediction.py new file mode 100644 index 0000000000..8bfdf12655 --- /dev/null +++ b/google/cloud/aiplatform/constants/prediction.py @@ -0,0 +1,147 @@ +# 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 re + +from collections import defaultdict + +# [region]-docker.pkg.dev/vertex-ai/prediction/[framework]-[accelerator].[version]:latest +CONTAINER_URI_PATTERN = re.compile( + r"(?P[\w]+)\-docker\.pkg\.dev\/vertex\-ai\/prediction\/" + r"(?P[\w]+)\-(?P[\w]+)\.(?P[\d-]+):latest" +) + +SKLEARN = "sklearn" +TF = "tf" +TF2 = "tf2" +XGBOOST = "xgboost" + +XGBOOST_CONTAINER_URIS = [ + "us-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.1-5:latest", + "europe-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.1-5:latest", + "asia-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.1-5:latest", + "us-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.1-4:latest", + "europe-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.1-4:latest", + "asia-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.1-4:latest", + "us-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.1-3:latest", + "europe-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.1-3:latest", + "asia-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.1-3:latest", + "us-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.1-2:latest", + "europe-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.1-2:latest", + "asia-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.1-2:latest", + "us-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.1-1:latest", + "europe-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.1-1:latest", + "asia-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.1-1:latest", + "us-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.0-90:latest", + "europe-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.0-90:latest", + "asia-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.0-90:latest", + "us-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.0-82:latest", + "europe-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.0-82:latest", + "asia-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.0-82:latest", +] + +SKLEARN_CONTAINER_URIS = [ + "us-docker.pkg.dev/vertex-ai/prediction/sklearn-cpu.1-0:latest", + "europe-docker.pkg.dev/vertex-ai/prediction/sklearn-cpu.1-0:latest", + "asia-docker.pkg.dev/vertex-ai/prediction/sklearn-cpu.1-0:latest", + "us-docker.pkg.dev/vertex-ai/prediction/sklearn-cpu.0-24:latest", + "europe-docker.pkg.dev/vertex-ai/prediction/sklearn-cpu.0-24:latest", + "asia-docker.pkg.dev/vertex-ai/prediction/sklearn-cpu.0-24:latest", + "us-docker.pkg.dev/vertex-ai/prediction/sklearn-cpu.0-23:latest", + "europe-docker.pkg.dev/vertex-ai/prediction/sklearn-cpu.0-23:latest", + "asia-docker.pkg.dev/vertex-ai/prediction/sklearn-cpu.0-23:latest", + "us-docker.pkg.dev/vertex-ai/prediction/sklearn-cpu.0-22:latest", + "europe-docker.pkg.dev/vertex-ai/prediction/sklearn-cpu.0-22:latest", + "asia-docker.pkg.dev/vertex-ai/prediction/sklearn-cpu.0-22:latest", + "us-docker.pkg.dev/vertex-ai/prediction/sklearn-cpu.0-20:latest", + "europe-docker.pkg.dev/vertex-ai/prediction/sklearn-cpu.0-20:latest", + "asia-docker.pkg.dev/vertex-ai/prediction/sklearn-cpu.0-20:latest", +] + +TF_CONTAINER_URIS = [ + "us-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-8:latest", + "europe-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-8:latest", + "asia-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-8:latest", + "us-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-8:latest", + "europe-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-8:latest", + "asia-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-8:latest", + "us-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-7:latest", + "europe-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-7:latest", + "asia-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-7:latest", + "us-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-7:latest", + "europe-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-7:latest", + "asia-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-7:latest", + "us-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-6:latest", + "europe-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-6:latest", + "asia-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-6:latest", + "us-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-6:latest", + "europe-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-6:latest", + "asia-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-6:latest", + "us-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-5:latest", + "europe-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-5:latest", + "asia-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-5:latest", + "us-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-5:latest", + "europe-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-5:latest", + "asia-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-5:latest", + "us-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-4:latest", + "europe-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-4:latest", + "asia-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-4:latest", + "us-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-4:latest", + "europe-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-4:latest", + "asia-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-4:latest", + "us-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-3:latest", + "europe-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-3:latest", + "asia-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-3:latest", + "us-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-3:latest", + "europe-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-3:latest", + "asia-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-3:latest", + "us-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-2:latest", + "europe-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-2:latest", + "asia-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-2:latest", + "us-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-2:latest", + "europe-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-2:latest", + "asia-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-2:latest", + "us-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-1:latest", + "europe-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-1:latest", + "asia-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-1:latest", + "us-docker.pkg.dev/vertex-ai/prediction/tf-cpu.1-15:latest", + "europe-docker.pkg.dev/vertex-ai/prediction/tf-cpu.1-15:latest", + "asia-docker.pkg.dev/vertex-ai/prediction/tf-cpu.1-15:latest", + "us-docker.pkg.dev/vertex-ai/prediction/tf-gpu.1-15:latest", + "europe-docker.pkg.dev/vertex-ai/prediction/tf-gpu.1-15:latest", + "asia-docker.pkg.dev/vertex-ai/prediction/tf-gpu.1-15:latest", +] + +SERVING_CONTAINER_URIS = ( + SKLEARN_CONTAINER_URIS + TF_CONTAINER_URIS + XGBOOST_CONTAINER_URIS +) + +# Map of all first-party prediction containers +d = defaultdict(lambda: defaultdict(lambda: defaultdict(lambda: defaultdict(str)))) + +for container_uri in SERVING_CONTAINER_URIS: + m = CONTAINER_URI_PATTERN.match(container_uri) + region, framework, accelerator, version = m[1], m[2], m[3], m[4] + version = version.replace("-", ".") + + if framework in (TF2, TF): # Store both `tf`, `tf2` as `tensorflow` + framework = "tensorflow" + + d[region][framework][accelerator][version] = container_uri + +_SERVING_CONTAINER_URI_MAP = d + +_SERVING_CONTAINER_DOCUMENTATION_URL = ( + "https://cloud.google.com/vertex-ai/docs/predictions/pre-built-containers" +) diff --git a/google/cloud/aiplatform/datasets/__init__.py b/google/cloud/aiplatform/datasets/__init__.py index b297530955..0f6b7f42fa 100644 --- a/google/cloud/aiplatform/datasets/__init__.py +++ b/google/cloud/aiplatform/datasets/__init__.py @@ -16,6 +16,7 @@ # from google.cloud.aiplatform.datasets.dataset import _Dataset +from google.cloud.aiplatform.datasets.column_names_dataset import _ColumnNamesDataset from google.cloud.aiplatform.datasets.tabular_dataset import TabularDataset from google.cloud.aiplatform.datasets.time_series_dataset import TimeSeriesDataset from google.cloud.aiplatform.datasets.image_dataset import ImageDataset @@ -25,6 +26,7 @@ __all__ = ( "_Dataset", + "_ColumnNamesDataset", "TabularDataset", "TimeSeriesDataset", "ImageDataset", diff --git a/google/cloud/aiplatform/datasets/_datasources.py b/google/cloud/aiplatform/datasets/_datasources.py index 9323f40382..5fc51c03f6 100644 --- a/google/cloud/aiplatform/datasets/_datasources.py +++ b/google/cloud/aiplatform/datasets/_datasources.py @@ -71,7 +71,7 @@ def __init__( "bq://project.dataset.table_name" Raises: - ValueError if source configuration is not valid. + ValueError: If source configuration is not valid. """ dataset_metadata = None @@ -121,10 +121,9 @@ def __init__( Args: gcs_source (Union[str, Sequence[str]]): Required. The Google Cloud Storage location for the input content. - Google Cloud Storage URI(-s) to the input file(s). May contain - wildcards. For more information on wildcards, see - https://cloud.google.com/storage/docs/gsutil/addlhelp/WildcardNames. - examples: + Google Cloud Storage URI(-s) to the input file(s). + + Examples: str: "gs://bucket/file.csv" Sequence[str]: ["gs://bucket/file1.csv", "gs://bucket/file2.csv"] import_schema_uri (str): @@ -185,10 +184,9 @@ def create_datasource( `OpenAPI 3.0.2 Schema gcs_source (Union[str, Sequence[str]]): The Google Cloud Storage location for the input content. - Google Cloud Storage URI(-s) to the input file(s). May contain - wildcards. For more information on wildcards, see - https://cloud.google.com/storage/docs/gsutil/addlhelp/WildcardNames. - examples: + Google Cloud Storage URI(-s) to the input file(s). + + Examples: str: "gs://bucket/file.csv" Sequence[str]: ["gs://bucket/file1.csv", "gs://bucket/file2.csv"] bq_source (str): @@ -215,7 +213,7 @@ def create_datasource( datasource (Datasource) Raises: - ValueError when below scenarios happen + ValueError: When below scenarios happen: - import_schema_uri is identified for creating TabularDatasource - either import_schema_uri or gcs_source is missing for creating NonTabularDatasourceImportable """ diff --git a/google/cloud/aiplatform/datasets/column_names_dataset.py b/google/cloud/aiplatform/datasets/column_names_dataset.py new file mode 100644 index 0000000000..27783d6c80 --- /dev/null +++ b/google/cloud/aiplatform/datasets/column_names_dataset.py @@ -0,0 +1,256 @@ +# -*- coding: utf-8 -*- + +# 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 +# +# 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. +# + + +import csv +import logging +from typing import List, Optional, Set +from google.auth import credentials as auth_credentials + +from google.cloud import bigquery +from google.cloud import storage + +from google.cloud.aiplatform import utils +from google.cloud.aiplatform import datasets + + +class _ColumnNamesDataset(datasets._Dataset): + @property + def column_names(self) -> List[str]: + """Retrieve the columns for the dataset by extracting it from the Google Cloud Storage or + Google BigQuery source. + + Returns: + List[str] + A list of columns names + + Raises: + RuntimeError: When no valid source is found. + """ + + self._assert_gca_resource_is_available() + + metadata = self._gca_resource.metadata + + if metadata is None: + raise RuntimeError("No metadata found for dataset") + + input_config = metadata.get("inputConfig") + + if input_config is None: + raise RuntimeError("No inputConfig found for dataset") + + gcs_source = input_config.get("gcsSource") + bq_source = input_config.get("bigquerySource") + + if gcs_source: + gcs_source_uris = gcs_source.get("uri") + + if gcs_source_uris and len(gcs_source_uris) > 0: + # Lexicographically sort the files + gcs_source_uris.sort() + + # Get the first file in sorted list + # TODO(b/193044977): Return as Set instead of List + return list( + self._retrieve_gcs_source_columns( + project=self.project, + gcs_csv_file_path=gcs_source_uris[0], + credentials=self.credentials, + ) + ) + elif bq_source: + bq_table_uri = bq_source.get("uri") + if bq_table_uri: + # TODO(b/193044977): Return as Set instead of List + return list( + self._retrieve_bq_source_columns( + project=self.project, + bq_table_uri=bq_table_uri, + credentials=self.credentials, + ) + ) + + raise RuntimeError("No valid CSV or BigQuery datasource found.") + + @staticmethod + def _retrieve_gcs_source_columns( + project: str, + gcs_csv_file_path: str, + credentials: Optional[auth_credentials.Credentials] = None, + ) -> Set[str]: + """Retrieve the columns from a comma-delimited CSV file stored on Google Cloud Storage + + Example Usage: + + column_names = _retrieve_gcs_source_columns( + "project_id", + "gs://example-bucket/path/to/csv_file" + ) + + # column_names = {"column_1", "column_2"} + + Args: + project (str): + Required. Project to initiate the Google Cloud Storage client with. + gcs_csv_file_path (str): + Required. A full path to a CSV files stored on Google Cloud Storage. + Must include "gs://" prefix. + credentials (auth_credentials.Credentials): + Credentials to use to with GCS Client. + Returns: + Set[str] + A set of columns names in the CSV file. + + Raises: + RuntimeError: When the retrieved CSV file is invalid. + """ + + gcs_bucket, gcs_blob = utils.extract_bucket_and_prefix_from_gcs_path( + gcs_csv_file_path + ) + client = storage.Client(project=project, credentials=credentials) + bucket = client.bucket(gcs_bucket) + blob = bucket.blob(gcs_blob) + + # Incrementally download the CSV file until the header is retrieved + first_new_line_index = -1 + start_index = 0 + increment = 1000 + line = "" + + try: + logger = logging.getLogger("google.resumable_media._helpers") + logging_warning_filter = utils.LoggingFilter(logging.INFO) + logger.addFilter(logging_warning_filter) + + while first_new_line_index == -1: + line += blob.download_as_bytes( + start=start_index, end=start_index + increment - 1 + ).decode("utf-8") + + first_new_line_index = line.find("\n") + start_index += increment + + header_line = line[:first_new_line_index] + + # Split to make it an iterable + header_line = header_line.split("\n")[:1] + + csv_reader = csv.reader(header_line, delimiter=",") + except (ValueError, RuntimeError) as err: + raise RuntimeError( + "There was a problem extracting the headers from the CSV file at '{}': {}".format( + gcs_csv_file_path, err + ) + ) + finally: + logger.removeFilter(logging_warning_filter) + + return set(next(csv_reader)) + + @staticmethod + def _get_bq_schema_field_names_recursively( + schema_field: bigquery.SchemaField, + ) -> Set[str]: + """Retrieve the name for a schema field along with ancestor fields. + Nested schema fields are flattened and concatenated with a ".". + Schema fields with child fields are not included, but the children are. + + Args: + project (str): + Required. Project to initiate the BigQuery client with. + bq_table_uri (str): + Required. A URI to a BigQuery table. + Can include "bq://" prefix but not required. + credentials (auth_credentials.Credentials): + Credentials to use with BQ Client. + + Returns: + Set[str] + A set of columns names in the BigQuery table. + """ + + ancestor_names = { + nested_field_name + for field in schema_field.fields + for nested_field_name in _ColumnNamesDataset._get_bq_schema_field_names_recursively( + field + ) + } + + # Only return "leaf nodes", basically any field that doesn't have children + if len(ancestor_names) == 0: + return {schema_field.name} + else: + return {f"{schema_field.name}.{name}" for name in ancestor_names} + + @staticmethod + def _retrieve_bq_source_columns( + project: str, + bq_table_uri: str, + credentials: Optional[auth_credentials.Credentials] = None, + ) -> Set[str]: + """Retrieve the column names from a table on Google BigQuery + Nested schema fields are flattened and concatenated with a ".". + Schema fields with child fields are not included, but the children are. + + Example Usage: + + column_names = _retrieve_bq_source_columns( + "project_id", + "bq://project_id.dataset.table" + ) + + # column_names = {"column_1", "column_2", "column_3.nested_field"} + + Args: + project (str): + Required. Project to initiate the BigQuery client with. + bq_table_uri (str): + Required. A URI to a BigQuery table. + Can include "bq://" prefix but not required. + credentials (auth_credentials.Credentials): + Credentials to use with BQ Client. + + Returns: + Set[str] + A set of column names in the BigQuery table. + """ + + # Remove bq:// prefix + prefix = "bq://" + if bq_table_uri.startswith(prefix): + bq_table_uri = bq_table_uri[len(prefix) :] + + # The colon-based "project:dataset.table" format is no longer supported: + # Invalid dataset ID "bigquery-public-data:chicago_taxi_trips". + # Dataset IDs must be alphanumeric (plus underscores and dashes) and must be at most 1024 characters long. + # Using dot-based "project.dataset.table" format instead. + bq_table_uri = bq_table_uri.replace(":", ".") + + client = bigquery.Client(project=project, credentials=credentials) + table = client.get_table(bq_table_uri) + schema = table.schema + + return { + field_name + for field in schema + for field_name in _ColumnNamesDataset._get_bq_schema_field_names_recursively( + field + ) + } diff --git a/google/cloud/aiplatform/datasets/dataset.py b/google/cloud/aiplatform/datasets/dataset.py index 1eb1663b2b..508932779b 100644 --- a/google/cloud/aiplatform/datasets/dataset.py +++ b/google/cloud/aiplatform/datasets/dataset.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ # limitations under the License. # -from typing import Optional, Sequence, Dict, Tuple, Union, List +from typing import Dict, List, Optional, Sequence, Tuple, Union from google.api_core import operation from google.auth import credentials as auth_credentials @@ -31,6 +31,7 @@ io as gca_io, ) from google.cloud.aiplatform.datasets import _datasources +from google.protobuf import field_mask_pb2 _LOGGER = base.Logger(__name__) @@ -39,11 +40,12 @@ class _Dataset(base.VertexAiResourceNounWithFutureManager): """Managed dataset resource for Vertex AI.""" client_class = utils.DatasetClientWithOverride - _is_client_prediction_client = False _resource_noun = "datasets" _getter_method = "get_dataset" _list_method = "list_datasets" _delete_method = "delete_dataset" + _parse_resource_name_method = "parse_dataset_path" + _format_resource_name_method = "dataset_path" _supported_metadata_schema_uris: Tuple[str] = () @@ -68,7 +70,7 @@ def __init__( Optional location to retrieve dataset from. If not set, location set in aiplatform.init will be used. credentials (auth_credentials.Credentials): - Custom credentials to use to upload this model. Overrides + Custom credentials to use to retrieve this Dataset. Overrides credentials set in aiplatform.init. """ @@ -84,13 +86,14 @@ def __init__( @property def metadata_schema_uri(self) -> str: """The metadata schema uri of this dataset resource.""" + self._assert_gca_resource_is_available() return self._gca_resource.metadata_schema_uri def _validate_metadata_schema_uri(self) -> None: """Validate the metadata_schema_uri of retrieved dataset resource. Raises: - ValueError if the dataset type of the retrieved dataset resource is + ValueError: If the dataset type of the retrieved dataset resource is not supported by the class. """ if self._supported_metadata_schema_uris and ( @@ -104,6 +107,7 @@ def _validate_metadata_schema_uri(self) -> None: @classmethod def create( cls, + # TODO(b/223262536): Make the display_name parameter optional in the next major release display_name: str, metadata_schema_uri: str, gcs_source: Optional[Union[str, Sequence[str]]] = None, @@ -114,8 +118,10 @@ def create( location: Optional[str] = None, credentials: Optional[auth_credentials.Credentials] = None, request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + labels: Optional[Dict[str, str]] = None, encryption_spec_key_name: Optional[str] = None, sync: bool = True, + create_request_timeout: Optional[float] = None, ) -> "_Dataset": """Creates a new dataset and optionally imports data into dataset when source and import_schema_uri are passed. @@ -161,7 +167,7 @@ def create( be picked randomly. Two DataItems are considered identical if their content bytes are identical (e.g. image bytes or pdf bytes). These labels will be overridden by Annotation - labels specified inside index file refenced by + labels specified inside index file referenced by ``import_schema_uri``, e.g. jsonl file. project (str): @@ -175,6 +181,16 @@ def create( credentials set in aiplatform.init. request_metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. + labels (Dict[str, str]): + Optional. Labels with user-defined metadata to organize your Tensorboards. + Label keys and values can be no longer than 64 characters + (Unicode codepoints), can only contain lowercase letters, numeric + characters, underscores and dashes. International characters are allowed. + No more than 64 user labels can be associated with one Tensorboard + (System labels are excluded). + See https://goo.gl/xmQnxf for more information and examples of labels. + System reserved label keys are prefixed with "aiplatform.googleapis.com/" + and are immutable. encryption_spec_key_name (Optional[str]): Optional. The Cloud KMS resource identifier of the customer managed encryption key used to protect the dataset. Has the @@ -190,13 +206,18 @@ def create( Whether to execute this method synchronously. If False, this method will be executed in concurrent Future and any downstream object will be immediately returned and synced when the Future has completed. + create_request_timeout (float): + Optional. The timeout for the create request in seconds. Returns: dataset (Dataset): Instantiated representation of the managed dataset resource. """ - + if not display_name: + display_name = cls._generate_display_name() utils.validate_display_name(display_name) + if labels: + utils.validate_labels(labels) api_client = cls._instantiate_client(location=location, credentials=credentials) @@ -220,10 +241,12 @@ def create( location=location or initializer.global_config.location, credentials=credentials or initializer.global_config.credentials, request_metadata=request_metadata, + labels=labels, encryption_spec=initializer.global_config.get_encryption_spec( encryption_spec_key_name=encryption_spec_key_name ), sync=sync, + create_request_timeout=create_request_timeout, ) @classmethod @@ -239,8 +262,11 @@ def _create_and_import( location: str, credentials: Optional[auth_credentials.Credentials], request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + labels: Optional[Dict[str, str]] = None, encryption_spec: Optional[gca_encryption_spec.EncryptionSpec] = None, sync: bool = True, + create_request_timeout: Optional[float] = None, + import_request_timeout: Optional[float] = None, ) -> "_Dataset": """Creates a new dataset and optionally imports data into dataset when source and import_schema_uri are passed. @@ -276,6 +302,16 @@ def _create_and_import( credentials set in aiplatform.init. request_metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. + labels (Dict[str, str]): + Optional. Labels with user-defined metadata to organize your Tensorboards. + Label keys and values can be no longer than 64 characters + (Unicode codepoints), can only contain lowercase letters, numeric + characters, underscores and dashes. International characters are allowed. + No more than 64 user labels can be associated with one Tensorboard + (System labels are excluded). + See https://goo.gl/xmQnxf for more information and examples of labels. + System reserved label keys are prefixed with "aiplatform.googleapis.com/" + and are immutable. encryption_spec (Optional[gca_encryption_spec.EncryptionSpec]): Optional. The Cloud KMS customer managed encryption key used to protect the dataset. The key needs to be in the same region as where the compute @@ -286,6 +322,10 @@ def _create_and_import( Whether to execute this method synchronously. If False, this method will be executed in concurrent Future and any downstream object will be immediately returned and synced when the Future has completed. + create_request_timeout (float): + Optional. The timeout for the create request in seconds. + import_request_timeout (float): + Optional. The timeout for the import request in seconds. Returns: dataset (Dataset): @@ -299,7 +339,9 @@ def _create_and_import( metadata_schema_uri=metadata_schema_uri, datasource=datasource, request_metadata=request_metadata, + labels=labels, encryption_spec=encryption_spec, + create_request_timeout=create_request_timeout, ) _LOGGER.log_create_with_lro(cls, create_dataset_lro) @@ -317,16 +359,26 @@ def _create_and_import( # Import if import datasource is DatasourceImportable if isinstance(datasource, _datasources.DatasourceImportable): - dataset_obj._import_and_wait(datasource) + dataset_obj._import_and_wait( + datasource, import_request_timeout=import_request_timeout + ) return dataset_obj - def _import_and_wait(self, datasource): + def _import_and_wait( + self, + datasource, + import_request_timeout: Optional[float] = None, + ): _LOGGER.log_action_start_against_resource( - "Importing", "data", self, + "Importing", + "data", + self, ) - import_lro = self._import(datasource=datasource) + import_lro = self._import( + datasource=datasource, import_request_timeout=import_request_timeout + ) _LOGGER.log_action_started_against_resource_with_lro( "Import", "data", self.__class__, import_lro @@ -345,7 +397,9 @@ def _create( metadata_schema_uri: str, datasource: _datasources.Datasource, request_metadata: Sequence[Tuple[str, str]] = (), + labels: Optional[Dict[str, str]] = None, encryption_spec: Optional[gca_encryption_spec.EncryptionSpec] = None, + create_request_timeout: Optional[float] = None, ) -> operation.Operation: """Creates a new managed dataset by directly calling API client. @@ -372,12 +426,24 @@ def _create( request_metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the create_dataset request as metadata. Usually to specify special dataset config. + labels (Dict[str, str]): + Optional. Labels with user-defined metadata to organize your Tensorboards. + Label keys and values can be no longer than 64 characters + (Unicode codepoints), can only contain lowercase letters, numeric + characters, underscores and dashes. International characters are allowed. + No more than 64 user labels can be associated with one Tensorboard + (System labels are excluded). + See https://goo.gl/xmQnxf for more information and examples of labels. + System reserved label keys are prefixed with "aiplatform.googleapis.com/" + and are immutable. encryption_spec (Optional[gca_encryption_spec.EncryptionSpec]): Optional. The Cloud KMS customer managed encryption key used to protect the dataset. The key needs to be in the same region as where the compute resource is created. If set, this Dataset and all sub-resources of this Dataset will be secured by this key. + create_request_timeout (float): + Optional. The timeout for the create request in seconds. Returns: operation (Operation): An object representing a long-running operation. @@ -387,28 +453,38 @@ def _create( display_name=display_name, metadata_schema_uri=metadata_schema_uri, metadata=datasource.dataset_metadata, + labels=labels, encryption_spec=encryption_spec, ) return api_client.create_dataset( - parent=parent, dataset=gapic_dataset, metadata=request_metadata + parent=parent, + dataset=gapic_dataset, + metadata=request_metadata, + timeout=create_request_timeout, ) def _import( - self, datasource: _datasources.DatasourceImportable, + self, + datasource: _datasources.DatasourceImportable, + import_request_timeout: Optional[float] = None, ) -> operation.Operation: """Imports data into managed dataset by directly calling API client. Args: datasource (_datasources.DatasourceImportable): Required. Datasource for importing data to an existing dataset for Vertex AI. + import_request_timeout (float): + Optional. The timeout for the import request in seconds. Returns: operation (Operation): An object representing a long-running operation. """ return self.api_client.import_data( - name=self.resource_name, import_configs=[datasource.import_data_config] + name=self.resource_name, + import_configs=[datasource.import_data_config], + timeout=import_request_timeout, ) @base.optional_sync(return_input_arg="self") @@ -418,6 +494,7 @@ def import_data( import_schema_uri: str, data_item_labels: Optional[Dict] = None, sync: bool = True, + import_request_timeout: Optional[float] = None, ) -> "_Dataset": """Upload data to existing managed dataset. @@ -448,13 +525,15 @@ def import_data( be picked randomly. Two DataItems are considered identical if their content bytes are identical (e.g. image bytes or pdf bytes). These labels will be overridden by Annotation - labels specified inside index file refenced by + labels specified inside index file referenced by ``import_schema_uri``, e.g. jsonl file. sync (bool): Whether to execute this method synchronously. If False, this method will be executed in concurrent Future and any downstream object will be immediately returned and synced when the Future has completed. + import_request_timeout (float): + Optional. The timeout for the import request in seconds. Returns: dataset (Dataset): @@ -467,7 +546,9 @@ def import_data( data_item_labels=data_item_labels, ) - self._import_and_wait(datasource=datasource) + self._import_and_wait( + datasource=datasource, import_request_timeout=import_request_timeout + ) return self # TODO(b/174751568) add optional sync support @@ -517,8 +598,69 @@ def export_data(self, output_dir: str) -> Sequence[str]: return export_data_response.exported_files - def update(self): - raise NotImplementedError("Update dataset has not been implemented yet") + def update( + self, + *, + display_name: Optional[str] = None, + labels: Optional[Dict[str, str]] = None, + description: Optional[str] = None, + update_request_timeout: Optional[float] = None, + ) -> "_Dataset": + """Update the dataset. + Updatable fields: + - ``display_name`` + - ``description`` + - ``labels`` + + Args: + display_name (str): + Optional. The user-defined name of the Dataset. + The name can be up to 128 characters long and can be consist + of any UTF-8 characters. + labels (Dict[str, str]): + Optional. Labels with user-defined metadata to organize your Tensorboards. + Label keys and values can be no longer than 64 characters + (Unicode codepoints), can only contain lowercase letters, numeric + characters, underscores and dashes. International characters are allowed. + No more than 64 user labels can be associated with one Tensorboard + (System labels are excluded). + See https://goo.gl/xmQnxf for more information and examples of labels. + System reserved label keys are prefixed with "aiplatform.googleapis.com/" + and are immutable. + description (str): + Optional. The description of the Dataset. + update_request_timeout (float): + Optional. The timeout for the update request in seconds. + + Returns: + dataset (Dataset): + Updated dataset. + """ + + update_mask = field_mask_pb2.FieldMask() + if display_name: + update_mask.paths.append("display_name") + + if labels: + update_mask.paths.append("labels") + + if description: + update_mask.paths.append("description") + + update_dataset = gca_dataset.Dataset( + name=self.resource_name, + display_name=display_name, + description=description, + labels=labels, + ) + + self._gca_resource = self.api_client.update_dataset( + dataset=update_dataset, + update_mask=update_mask, + timeout=update_request_timeout, + ) + + return self @classmethod def list( diff --git a/google/cloud/aiplatform/datasets/image_dataset.py b/google/cloud/aiplatform/datasets/image_dataset.py index 506338c915..b7f7954278 100644 --- a/google/cloud/aiplatform/datasets/image_dataset.py +++ b/google/cloud/aiplatform/datasets/image_dataset.py @@ -15,7 +15,7 @@ # limitations under the License. # -from typing import Optional, Sequence, Dict, Tuple, Union +from typing import Dict, Optional, Sequence, Tuple, Union from google.auth import credentials as auth_credentials @@ -36,7 +36,7 @@ class ImageDataset(datasets._Dataset): @classmethod def create( cls, - display_name: str, + display_name: Optional[str] = None, gcs_source: Optional[Union[str, Sequence[str]]] = None, import_schema_uri: Optional[str] = None, data_item_labels: Optional[Dict] = None, @@ -44,23 +44,24 @@ def create( location: Optional[str] = None, credentials: Optional[auth_credentials.Credentials] = None, request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + labels: Optional[Dict[str, str]] = None, encryption_spec_key_name: Optional[str] = None, sync: bool = True, + create_request_timeout: Optional[float] = None, ) -> "ImageDataset": """Creates a new image dataset and optionally imports data into dataset when source and import_schema_uri are passed. Args: display_name (str): - Required. The user-defined name of the Dataset. + Optional. The user-defined name of the Dataset. The name can be up to 128 characters long and can be consist of any UTF-8 characters. gcs_source (Union[str, Sequence[str]]): Google Cloud Storage URI(-s) to the - input file(s). May contain wildcards. For more - information on wildcards, see - https://cloud.google.com/storage/docs/gsutil/addlhelp/WildcardNames. - examples: + input file(s). + + Examples: str: "gs://bucket/file.csv" Sequence[str]: ["gs://bucket/file1.csv", "gs://bucket/file2.csv"] import_schema_uri (str): @@ -81,7 +82,7 @@ def create( be picked randomly. Two DataItems are considered identical if their content bytes are identical (e.g. image bytes or pdf bytes). These labels will be overridden by Annotation - labels specified inside index file refenced by + labels specified inside index file referenced by ``import_schema_uri``, e.g. jsonl file. project (str): @@ -95,6 +96,16 @@ def create( credentials set in aiplatform.init. request_metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. + labels (Dict[str, str]): + Optional. Labels with user-defined metadata to organize your Tensorboards. + Label keys and values can be no longer than 64 characters + (Unicode codepoints), can only contain lowercase letters, numeric + characters, underscores and dashes. International characters are allowed. + No more than 64 user labels can be associated with one Tensorboard + (System labels are excluded). + See https://goo.gl/xmQnxf for more information and examples of labels. + System reserved label keys are prefixed with "aiplatform.googleapis.com/" + and are immutable. encryption_spec_key_name (Optional[str]): Optional. The Cloud KMS resource identifier of the customer managed encryption key used to protect the dataset. Has the @@ -110,13 +121,19 @@ def create( Whether to execute this method synchronously. If False, this method will be executed in concurrent Future and any downstream object will be immediately returned and synced when the Future has completed. + create_request_timeout (float): + Optional. The timeout for the create request in seconds. Returns: image_dataset (ImageDataset): Instantiated representation of the managed image dataset resource. """ + if not display_name: + display_name = cls._generate_display_name() utils.validate_display_name(display_name) + if labels: + utils.validate_labels(labels) api_client = cls._instantiate_client(location=location, credentials=credentials) @@ -141,8 +158,10 @@ def create( location=location or initializer.global_config.location, credentials=credentials or initializer.global_config.credentials, request_metadata=request_metadata, + labels=labels, encryption_spec=initializer.global_config.get_encryption_spec( encryption_spec_key_name=encryption_spec_key_name ), sync=sync, + create_request_timeout=create_request_timeout, ) diff --git a/google/cloud/aiplatform/datasets/tabular_dataset.py b/google/cloud/aiplatform/datasets/tabular_dataset.py index 95f1b16f98..f4366e4a24 100644 --- a/google/cloud/aiplatform/datasets/tabular_dataset.py +++ b/google/cloud/aiplatform/datasets/tabular_dataset.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,207 +15,57 @@ # limitations under the License. # -import csv -import logging - -from typing import List, Optional, Sequence, Tuple, Union +from typing import Dict, Optional, Sequence, Tuple, Union from google.auth import credentials as auth_credentials from google.cloud import bigquery -from google.cloud import storage - +from google.cloud.aiplatform import base from google.cloud.aiplatform import datasets from google.cloud.aiplatform.datasets import _datasources from google.cloud.aiplatform import initializer from google.cloud.aiplatform import schema from google.cloud.aiplatform import utils +_AUTOML_TRAINING_MIN_ROWS = 1000 + +_LOGGER = base.Logger(__name__) + -class TabularDataset(datasets._Dataset): +class TabularDataset(datasets._ColumnNamesDataset): """Managed tabular dataset resource for Vertex AI.""" _supported_metadata_schema_uris: Optional[Tuple[str]] = ( schema.dataset.metadata.tabular, ) - @property - def column_names(self) -> List[str]: - """Retrieve the columns for the dataset by extracting it from the Google Cloud Storage or - Google BigQuery source. - - Returns: - List[str] - A list of columns names - - Raises: - RuntimeError: When no valid source is found. - """ - - metadata = self._gca_resource.metadata - - if metadata is None: - raise RuntimeError("No metadata found for dataset") - - input_config = metadata.get("inputConfig") - - if input_config is None: - raise RuntimeError("No inputConfig found for dataset") - - gcs_source = input_config.get("gcsSource") - bq_source = input_config.get("bigquerySource") - - if gcs_source: - gcs_source_uris = gcs_source.get("uri") - - if gcs_source_uris and len(gcs_source_uris) > 0: - # Lexicographically sort the files - gcs_source_uris.sort() - - # Get the first file in sorted list - return TabularDataset._retrieve_gcs_source_columns( - self.project, gcs_source_uris[0] - ) - elif bq_source: - bq_table_uri = bq_source.get("uri") - if bq_table_uri: - return TabularDataset._retrieve_bq_source_columns( - self.project, bq_table_uri - ) - - raise RuntimeError("No valid CSV or BigQuery datasource found.") - - @staticmethod - def _retrieve_gcs_source_columns(project: str, gcs_csv_file_path: str) -> List[str]: - """Retrieve the columns from a comma-delimited CSV file stored on Google Cloud Storage - - Example Usage: - - column_names = _retrieve_gcs_source_columns( - "project_id", - "gs://example-bucket/path/to/csv_file" - ) - - # column_names = ["column_1", "column_2"] - - Args: - project (str): - Required. Project to initiate the Google Cloud Storage client with. - gcs_csv_file_path (str): - Required. A full path to a CSV files stored on Google Cloud Storage. - Must include "gs://" prefix. - - Returns: - List[str] - A list of columns names in the CSV file. - - Raises: - RuntimeError: When the retrieved CSV file is invalid. - """ - - gcs_bucket, gcs_blob = utils.extract_bucket_and_prefix_from_gcs_path( - gcs_csv_file_path - ) - client = storage.Client(project=project) - bucket = client.bucket(gcs_bucket) - blob = bucket.blob(gcs_blob) - - # Incrementally download the CSV file until the header is retrieved - first_new_line_index = -1 - start_index = 0 - increment = 1000 - line = "" - - try: - logger = logging.getLogger("google.resumable_media._helpers") - logging_warning_filter = utils.LoggingFilter(logging.INFO) - logger.addFilter(logging_warning_filter) - - while first_new_line_index == -1: - line += blob.download_as_bytes( - start=start_index, end=start_index + increment - ).decode("utf-8") - first_new_line_index = line.find("\n") - start_index += increment - - header_line = line[:first_new_line_index] - - # Split to make it an iterable - header_line = header_line.split("\n")[:1] - - csv_reader = csv.reader(header_line, delimiter=",") - except (ValueError, RuntimeError) as err: - raise RuntimeError( - "There was a problem extracting the headers from the CSV file at '{}': {}".format( - gcs_csv_file_path, err - ) - ) - finally: - logger.removeFilter(logging_warning_filter) - - return next(csv_reader) - - @staticmethod - def _retrieve_bq_source_columns(project: str, bq_table_uri: str) -> List[str]: - """Retrieve the columns from a table on Google BigQuery - - Example Usage: - - column_names = _retrieve_bq_source_columns( - "project_id", - "bq://project_id.dataset.table" - ) - - # column_names = ["column_1", "column_2"] - - Args: - project (str): - Required. Project to initiate the BigQuery client with. - bq_table_uri (str): - Required. A URI to a BigQuery table. - Can include "bq://" prefix but not required. - - Returns: - List[str] - A list of columns names in the BigQuery table. - """ - - # Remove bq:// prefix - prefix = "bq://" - if bq_table_uri.startswith(prefix): - bq_table_uri = bq_table_uri[len(prefix) :] - - client = bigquery.Client(project=project) - table = client.get_table(bq_table_uri) - schema = table.schema - return [schema.name for schema in schema] - @classmethod def create( cls, - display_name: str, + display_name: Optional[str] = None, gcs_source: Optional[Union[str, Sequence[str]]] = None, bq_source: Optional[str] = None, project: Optional[str] = None, location: Optional[str] = None, credentials: Optional[auth_credentials.Credentials] = None, request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + labels: Optional[Dict[str, str]] = None, encryption_spec_key_name: Optional[str] = None, sync: bool = True, + create_request_timeout: Optional[float] = None, ) -> "TabularDataset": """Creates a new tabular dataset. Args: display_name (str): - Required. The user-defined name of the Dataset. + Optional. The user-defined name of the Dataset. The name can be up to 128 characters long and can be consist of any UTF-8 characters. gcs_source (Union[str, Sequence[str]]): Google Cloud Storage URI(-s) to the - input file(s). May contain wildcards. For more - information on wildcards, see - https://cloud.google.com/storage/docs/gsutil/addlhelp/WildcardNames. - examples: + input file(s). + + Examples: str: "gs://bucket/file.csv" Sequence[str]: ["gs://bucket/file1.csv", "gs://bucket/file2.csv"] bq_source (str): @@ -233,6 +83,16 @@ def create( credentials set in aiplatform.init. request_metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. + labels (Dict[str, str]): + Optional. Labels with user-defined metadata to organize your Tensorboards. + Label keys and values can be no longer than 64 characters + (Unicode codepoints), can only contain lowercase letters, numeric + characters, underscores and dashes. International characters are allowed. + No more than 64 user labels can be associated with one Tensorboard + (System labels are excluded). + See https://goo.gl/xmQnxf for more information and examples of labels. + System reserved label keys are prefixed with "aiplatform.googleapis.com/" + and are immutable. encryption_spec_key_name (Optional[str]): Optional. The Cloud KMS resource identifier of the customer managed encryption key used to protect the dataset. Has the @@ -248,13 +108,18 @@ def create( Whether to execute this method synchronously. If False, this method will be executed in concurrent Future and any downstream object will be immediately returned and synced when the Future has completed. + create_request_timeout (float): + Optional. The timeout for the create request in seconds. Returns: tabular_dataset (TabularDataset): Instantiated representation of the managed tabular dataset resource. """ - + if not display_name: + display_name = cls._generate_display_name() utils.validate_display_name(display_name) + if labels: + utils.validate_labels(labels) api_client = cls._instantiate_client(location=location, credentials=credentials) @@ -278,12 +143,120 @@ def create( location=location or initializer.global_config.location, credentials=credentials or initializer.global_config.credentials, request_metadata=request_metadata, + labels=labels, encryption_spec=initializer.global_config.get_encryption_spec( encryption_spec_key_name=encryption_spec_key_name ), sync=sync, + create_request_timeout=create_request_timeout, + ) + + @classmethod + def create_from_dataframe( + cls, + df_source: "pd.DataFrame", # noqa: F821 - skip check for undefined name 'pd' + staging_path: str, + bq_schema: Optional[Union[str, bigquery.SchemaField]] = None, + display_name: Optional[str] = None, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ) -> "TabularDataset": + """Creates a new tabular dataset from a Pandas DataFrame. + + Args: + df_source (pd.DataFrame): + Required. Pandas DataFrame containing the source data for + ingestion as a TabularDataset. This method will use the data + types from the provided DataFrame when creating the dataset. + staging_path (str): + Required. The BigQuery table to stage the data + for Vertex. Because Vertex maintains a reference to this source + to create the Vertex Dataset, this BigQuery table should + not be deleted. Example: `bq://my-project.my-dataset.my-table`. + If the provided BigQuery table doesn't exist, this method will + create the table. If the provided BigQuery table already exists, + and the schemas of the BigQuery table and your DataFrame match, + this method will append the data in your local DataFrame to the table. + The location of the provided BigQuery table should conform to the location requirements + specified here: https://cloud.google.com/vertex-ai/docs/general/locations#bq-locations. + bq_schema (Optional[Union[str, bigquery.SchemaField]]): + Optional. If not set, BigQuery will autodetect the schema using your DataFrame's column types. + If set, BigQuery will use the schema you provide when creating the staging table. For more details, + see: https://cloud.google.com/python/docs/reference/bigquery/latest/google.cloud.bigquery.job.LoadJobConfig#google_cloud_bigquery_job_LoadJobConfig_schema + display_name (str): + Optional. The user-defined name of the Dataset. + The name can be up to 128 characters long and can be consist + of any UTF-8 charact + project (str): + Optional. Project to upload this dataset to. Overrides project set in + aiplatform.init. + location (str): + Optional. Location to upload this dataset to. Overrides location set in + aiplatform.init. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to upload this dataset. Overrides + credentials set in aiplatform.init. + Returns: + tabular_dataset (TabularDataset): + Instantiated representation of the managed tabular dataset resource. + """ + + if staging_path.startswith("bq://"): + bq_staging_path = staging_path[len("bq://") :] + else: + raise ValueError( + "Only BigQuery staging paths are supported. Provide a staging path in the format `bq://your-project.your-dataset.your-table`." + ) + + try: + import pyarrow # noqa: F401 - skip check for 'pyarrow' which is required when using 'google.cloud.bigquery' + except ImportError: + raise ImportError( + "Pyarrow is not installed, and is required to use the BigQuery client." + 'Please install the SDK using "pip install google-cloud-aiplatform[datasets]"' + ) + + if len(df_source) < _AUTOML_TRAINING_MIN_ROWS: + _LOGGER.info( + "Your DataFrame has %s rows and AutoML requires %s rows to train on tabular data. You can still train a custom model once your dataset has been uploaded to Vertex, but you will not be able to use AutoML for training." + % (len(df_source), _AUTOML_TRAINING_MIN_ROWS), + ) + + bigquery_client = bigquery.Client( + project=project or initializer.global_config.project, + credentials=credentials or initializer.global_config.credentials, ) + try: + parquet_options = bigquery.format_options.ParquetOptions() + parquet_options.enable_list_inference = True + + job_config = bigquery.LoadJobConfig( + source_format=bigquery.SourceFormat.PARQUET, + parquet_options=parquet_options, + ) + + if bq_schema: + job_config.schema = bq_schema + + job = bigquery_client.load_table_from_dataframe( + dataframe=df_source, destination=bq_staging_path, job_config=job_config + ) + + job.result() + + finally: + dataset_from_dataframe = cls.create( + display_name=display_name, + bq_source=staging_path, + project=project, + location=location, + credentials=credentials, + ) + + return dataset_from_dataframe + def import_data(self): raise NotImplementedError( f"{self.__class__.__name__} class does not support 'import_data'" diff --git a/google/cloud/aiplatform/datasets/text_dataset.py b/google/cloud/aiplatform/datasets/text_dataset.py index 85676ed2ed..f74fb76bb7 100644 --- a/google/cloud/aiplatform/datasets/text_dataset.py +++ b/google/cloud/aiplatform/datasets/text_dataset.py @@ -15,7 +15,7 @@ # limitations under the License. # -from typing import Optional, Sequence, Dict, Tuple, Union +from typing import Dict, Optional, Sequence, Tuple, Union from google.auth import credentials as auth_credentials @@ -36,7 +36,7 @@ class TextDataset(datasets._Dataset): @classmethod def create( cls, - display_name: str, + display_name: Optional[str] = None, gcs_source: Optional[Union[str, Sequence[str]]] = None, import_schema_uri: Optional[str] = None, data_item_labels: Optional[Dict] = None, @@ -44,8 +44,10 @@ def create( location: Optional[str] = None, credentials: Optional[auth_credentials.Credentials] = None, request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + labels: Optional[Dict[str, str]] = None, encryption_spec_key_name: Optional[str] = None, sync: bool = True, + create_request_timeout: Optional[float] = None, ) -> "TextDataset": """Creates a new text dataset and optionally imports data into dataset when source and import_schema_uri are passed. @@ -59,15 +61,14 @@ def create( Args: display_name (str): - Required. The user-defined name of the Dataset. + Optional. The user-defined name of the Dataset. The name can be up to 128 characters long and can be consist of any UTF-8 characters. gcs_source (Union[str, Sequence[str]]): Google Cloud Storage URI(-s) to the - input file(s). May contain wildcards. For more - information on wildcards, see - https://cloud.google.com/storage/docs/gsutil/addlhelp/WildcardNames. - examples: + input file(s). + + Examples: str: "gs://bucket/file.csv" Sequence[str]: ["gs://bucket/file1.csv", "gs://bucket/file2.csv"] import_schema_uri (str): @@ -88,7 +89,7 @@ def create( be picked randomly. Two DataItems are considered identical if their content bytes are identical (e.g. image bytes or pdf bytes). These labels will be overridden by Annotation - labels specified inside index file refenced by + labels specified inside index file referenced by ``import_schema_uri``, e.g. jsonl file. project (str): @@ -102,6 +103,16 @@ def create( credentials set in aiplatform.init. request_metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. + labels (Dict[str, str]): + Optional. Labels with user-defined metadata to organize your Tensorboards. + Label keys and values can be no longer than 64 characters + (Unicode codepoints), can only contain lowercase letters, numeric + characters, underscores and dashes. International characters are allowed. + No more than 64 user labels can be associated with one Tensorboard + (System labels are excluded). + See https://goo.gl/xmQnxf for more information and examples of labels. + System reserved label keys are prefixed with "aiplatform.googleapis.com/" + and are immutable. encryption_spec_key_name (Optional[str]): Optional. The Cloud KMS resource identifier of the customer managed encryption key used to protect the dataset. Has the @@ -113,6 +124,8 @@ def create( If set, this Dataset and all sub-resources of this Dataset will be secured by this key. Overrides encryption_spec_key_name set in aiplatform.init. + create_request_timeout (float): + Optional. The timeout for the create request in seconds. sync (bool): Whether to execute this method synchronously. If False, this method will be executed in concurrent Future and any downstream object will @@ -122,8 +135,11 @@ def create( text_dataset (TextDataset): Instantiated representation of the managed text dataset resource. """ - + if not display_name: + display_name = cls._generate_display_name() utils.validate_display_name(display_name) + if labels: + utils.validate_labels(labels) api_client = cls._instantiate_client(location=location, credentials=credentials) @@ -148,8 +164,10 @@ def create( location=location or initializer.global_config.location, credentials=credentials or initializer.global_config.credentials, request_metadata=request_metadata, + labels=labels, encryption_spec=initializer.global_config.get_encryption_spec( encryption_spec_key_name=encryption_spec_key_name ), sync=sync, + create_request_timeout=create_request_timeout, ) diff --git a/google/cloud/aiplatform/datasets/time_series_dataset.py b/google/cloud/aiplatform/datasets/time_series_dataset.py index d5aa3dcbf2..6cc48e2558 100644 --- a/google/cloud/aiplatform/datasets/time_series_dataset.py +++ b/google/cloud/aiplatform/datasets/time_series_dataset.py @@ -15,7 +15,7 @@ # limitations under the License. # -from typing import Optional, Sequence, Tuple, Union +from typing import Dict, Optional, Sequence, Tuple, Union from google.auth import credentials as auth_credentials @@ -26,7 +26,7 @@ from google.cloud.aiplatform import utils -class TimeSeriesDataset(datasets._Dataset): +class TimeSeriesDataset(datasets._ColumnNamesDataset): """Managed time series dataset resource for Vertex AI""" _supported_metadata_schema_uris: Optional[Tuple[str]] = ( @@ -36,29 +36,30 @@ class TimeSeriesDataset(datasets._Dataset): @classmethod def create( cls, - display_name: str, + display_name: Optional[str] = None, gcs_source: Optional[Union[str, Sequence[str]]] = None, bq_source: Optional[str] = None, project: Optional[str] = None, location: Optional[str] = None, credentials: Optional[auth_credentials.Credentials] = None, request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + labels: Optional[Dict[str, str]] = None, encryption_spec_key_name: Optional[str] = None, sync: bool = True, + create_request_timeout: Optional[float] = None, ) -> "TimeSeriesDataset": - """Creates a new tabular dataset. + """Creates a new time series dataset. Args: display_name (str): - Required. The user-defined name of the Dataset. + Optional. The user-defined name of the Dataset. The name can be up to 128 characters long and can be consist of any UTF-8 characters. gcs_source (Union[str, Sequence[str]]): Google Cloud Storage URI(-s) to the - input file(s). May contain wildcards. For more - information on wildcards, see - https://cloud.google.com/storage/docs/gsutil/addlhelp/WildcardNames. - examples: + input file(s). + + Examples: str: "gs://bucket/file.csv" Sequence[str]: ["gs://bucket/file1.csv", "gs://bucket/file2.csv"] bq_source (str): @@ -76,6 +77,16 @@ def create( credentials set in aiplatform.init. request_metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. + labels (Dict[str, str]): + Optional. Labels with user-defined metadata to organize your Tensorboards. + Label keys and values can be no longer than 64 characters + (Unicode codepoints), can only contain lowercase letters, numeric + characters, underscores and dashes. International characters are allowed. + No more than 64 user labels can be associated with one Tensorboard + (System labels are excluded). + See https://goo.gl/xmQnxf for more information and examples of labels. + System reserved label keys are prefixed with "aiplatform.googleapis.com/" + and are immutable. encryption_spec_key_name (Optional[str]): Optional. The Cloud KMS resource identifier of the customer managed encryption key used to protect the dataset. Has the @@ -91,14 +102,19 @@ def create( Whether to execute this method synchronously. If False, this method will be executed in concurrent Future and any downstream object will be immediately returned and synced when the Future has completed. + create_request_timeout (float): + Optional. The timeout for the create request in seconds. Returns: time_series_dataset (TimeSeriesDataset): Instantiated representation of the managed time series dataset resource. """ - + if not display_name: + display_name = cls._generate_display_name() utils.validate_display_name(display_name) + if labels: + utils.validate_labels(labels) api_client = cls._instantiate_client(location=location, credentials=credentials) @@ -122,10 +138,12 @@ def create( location=location or initializer.global_config.location, credentials=credentials or initializer.global_config.credentials, request_metadata=request_metadata, + labels=labels, encryption_spec=initializer.global_config.get_encryption_spec( encryption_spec_key_name=encryption_spec_key_name ), sync=sync, + create_request_timeout=create_request_timeout, ) def import_data(self): diff --git a/google/cloud/aiplatform/datasets/video_dataset.py b/google/cloud/aiplatform/datasets/video_dataset.py index 594a4ac407..bef719b17b 100644 --- a/google/cloud/aiplatform/datasets/video_dataset.py +++ b/google/cloud/aiplatform/datasets/video_dataset.py @@ -15,7 +15,7 @@ # limitations under the License. # -from typing import Optional, Sequence, Dict, Tuple, Union +from typing import Dict, Optional, Sequence, Tuple, Union from google.auth import credentials as auth_credentials @@ -36,7 +36,7 @@ class VideoDataset(datasets._Dataset): @classmethod def create( cls, - display_name: str, + display_name: Optional[str] = None, gcs_source: Optional[Union[str, Sequence[str]]] = None, import_schema_uri: Optional[str] = None, data_item_labels: Optional[Dict] = None, @@ -44,23 +44,24 @@ def create( location: Optional[str] = None, credentials: Optional[auth_credentials.Credentials] = None, request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + labels: Optional[Dict[str, str]] = None, encryption_spec_key_name: Optional[str] = None, sync: bool = True, + create_request_timeout: Optional[float] = None, ) -> "VideoDataset": """Creates a new video dataset and optionally imports data into dataset when source and import_schema_uri are passed. Args: display_name (str): - Required. The user-defined name of the Dataset. + Optional. The user-defined name of the Dataset. The name can be up to 128 characters long and can be consist of any UTF-8 characters. gcs_source (Union[str, Sequence[str]]): Google Cloud Storage URI(-s) to the - input file(s). May contain wildcards. For more - information on wildcards, see - https://cloud.google.com/storage/docs/gsutil/addlhelp/WildcardNames. - examples: + input file(s). + + Examples: str: "gs://bucket/file.csv" Sequence[str]: ["gs://bucket/file1.csv", "gs://bucket/file2.csv"] import_schema_uri (str): @@ -81,7 +82,7 @@ def create( be picked randomly. Two DataItems are considered identical if their content bytes are identical (e.g. image bytes or pdf bytes). These labels will be overridden by Annotation - labels specified inside index file refenced by + labels specified inside index file referenced by ``import_schema_uri``, e.g. jsonl file. project (str): @@ -95,6 +96,16 @@ def create( credentials set in aiplatform.init. request_metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. + labels (Dict[str, str]): + Optional. Labels with user-defined metadata to organize your Tensorboards. + Label keys and values can be no longer than 64 characters + (Unicode codepoints), can only contain lowercase letters, numeric + characters, underscores and dashes. International characters are allowed. + No more than 64 user labels can be associated with one Tensorboard + (System labels are excluded). + See https://goo.gl/xmQnxf for more information and examples of labels. + System reserved label keys are prefixed with "aiplatform.googleapis.com/" + and are immutable. encryption_spec_key_name (Optional[str]): Optional. The Cloud KMS resource identifier of the customer managed encryption key used to protect the dataset. Has the @@ -106,6 +117,8 @@ def create( If set, this Dataset and all sub-resources of this Dataset will be secured by this key. Overrides encryption_spec_key_name set in aiplatform.init. + create_request_timeout (float): + Optional. The timeout for the create request in seconds. sync (bool): Whether to execute this method synchronously. If False, this method will be executed in concurrent Future and any downstream object will @@ -115,8 +128,11 @@ def create( video_dataset (VideoDataset): Instantiated representation of the managed video dataset resource. """ - + if not display_name: + display_name = cls._generate_display_name() utils.validate_display_name(display_name) + if labels: + utils.validate_labels(labels) api_client = cls._instantiate_client(location=location, credentials=credentials) @@ -141,8 +157,10 @@ def create( location=location or initializer.global_config.location, credentials=credentials or initializer.global_config.credentials, request_metadata=request_metadata, + labels=labels, encryption_spec=initializer.global_config.get_encryption_spec( encryption_spec_key_name=encryption_spec_key_name ), sync=sync, + create_request_timeout=create_request_timeout, ) diff --git a/google/cloud/aiplatform/explain/__init__.py b/google/cloud/aiplatform/explain/__init__.py index 61b9181834..4701d709b5 100644 --- a/google/cloud/aiplatform/explain/__init__.py +++ b/google/cloud/aiplatform/explain/__init__.py @@ -16,11 +16,11 @@ # from google.cloud.aiplatform.compat.types import ( - explanation_metadata_v1beta1 as explanation_metadata, - explanation_v1beta1 as explanation, + explanation as explanation_compat, + explanation_metadata as explanation_metadata_compat, ) -ExplanationMetadata = explanation_metadata.ExplanationMetadata +ExplanationMetadata = explanation_metadata_compat.ExplanationMetadata # ExplanationMetadata subclasses InputMetadata = ExplanationMetadata.InputMetadata @@ -32,15 +32,14 @@ Visualization = InputMetadata.Visualization -ExplanationParameters = explanation.ExplanationParameters -FeatureNoiseSigma = explanation.FeatureNoiseSigma +ExplanationParameters = explanation_compat.ExplanationParameters +FeatureNoiseSigma = explanation_compat.FeatureNoiseSigma # Classes used by ExplanationParameters -IntegratedGradientsAttribution = explanation.IntegratedGradientsAttribution - -SampledShapleyAttribution = explanation.SampledShapleyAttribution -SmoothGradConfig = explanation.SmoothGradConfig -XraiAttribution = explanation.XraiAttribution +IntegratedGradientsAttribution = explanation_compat.IntegratedGradientsAttribution +SampledShapleyAttribution = explanation_compat.SampledShapleyAttribution +SmoothGradConfig = explanation_compat.SmoothGradConfig +XraiAttribution = explanation_compat.XraiAttribution __all__ = ( diff --git a/google/cloud/aiplatform/explain/lit.py b/google/cloud/aiplatform/explain/lit.py new file mode 100644 index 0000000000..6d388f4559 --- /dev/null +++ b/google/cloud/aiplatform/explain/lit.py @@ -0,0 +1,482 @@ +# -*- coding: utf-8 -*- + +# 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 +# +# 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. + +import logging +import os + +from google.cloud import aiplatform +from typing import Dict, List, Mapping, Optional, Tuple, Union + +try: + from lit_nlp.api import dataset as lit_dataset + from lit_nlp.api import dtypes as lit_dtypes + from lit_nlp.api import model as lit_model + from lit_nlp.api import types as lit_types + from lit_nlp import notebook +except ImportError: + raise ImportError( + "LIT is not installed and is required to get Dataset as the return format. " + 'Please install the SDK using "pip install google-cloud-aiplatform[lit]"' + ) + +try: + import tensorflow as tf +except ImportError: + raise ImportError( + "Tensorflow is not installed and is required to load saved model. " + 'Please install the SDK using "pip install google-cloud-aiplatform[lit]"' + ) + +try: + import pandas as pd +except ImportError: + raise ImportError( + "Pandas is not installed and is required to read the dataset. " + 'Please install Pandas using "pip install google-cloud-aiplatform[lit]"' + ) + + +class _VertexLitDataset(lit_dataset.Dataset): + """LIT dataset class for the Vertex LIT integration. + + This is used in the create_lit_dataset function. + """ + + def __init__( + self, + dataset: pd.DataFrame, + column_types: "OrderedDict[str, lit_types.LitType]", # noqa: F821 + ): + """Construct a VertexLitDataset. + Args: + dataset: + Required. A Pandas DataFrame that includes feature column names and data. + column_types: + Required. An OrderedDict of string names matching the columns of the dataset + as the key, and the associated LitType of the column. + """ + self._examples = dataset.to_dict(orient="records") + self._column_types = column_types + + def spec(self): + """Return a spec describing dataset elements.""" + return dict(self._column_types) + + +class _EndpointLitModel(lit_model.Model): + """LIT model class for the Vertex LIT integration with a model deployed to an endpoint. + + This is used in the create_lit_model function. + """ + + def __init__( + self, + endpoint: Union[str, aiplatform.Endpoint], + input_types: "OrderedDict[str, lit_types.LitType]", # noqa: F821 + output_types: "OrderedDict[str, lit_types.LitType]", # noqa: F821 + model_id: Optional[str] = None, + ): + """Construct a VertexLitModel. + Args: + model: + Required. The name of the Endpoint resource. Format: + ``projects/{project}/locations/{location}/endpoints/{endpoint}`` + input_types: + Required. An OrderedDict of string names matching the features of the model + as the key, and the associated LitType of the feature. + output_types: + Required. An OrderedDict of string names matching the labels of the model + as the key, and the associated LitType of the label. + model_id: + Optional. A string of the specific model in the endpoint to create the + LIT model from. If this is not set, any usable model in the endpoint is + used to create the LIT model. + Raises: + ValueError if the model_id was not found in the endpoint. + """ + if isinstance(endpoint, str): + self._endpoint = aiplatform.Endpoint(endpoint) + else: + self._endpoint = endpoint + self._model_id = model_id + self._input_types = input_types + self._output_types = output_types + # Check if the model with the model ID has explanation enabled + if model_id: + deployed_model = next( + filter( + lambda model: model.id == model_id, self._endpoint.list_models() + ), + None, + ) + if not deployed_model: + raise ValueError( + "A model with id {model_id} was not found in the endpoint {endpoint}.".format( + model_id=model_id, endpoint=endpoint + ) + ) + self._explanation_enabled = bool(deployed_model.explanation_spec) + # Check if all models in the endpoint have explanation enabled + else: + self._explanation_enabled = all( + model.explanation_spec for model in self._endpoint.list_models() + ) + + def predict_minibatch( + self, inputs: List[lit_types.JsonDict] + ) -> List[lit_types.JsonDict]: + """Retun predictions based on a batch of inputs. + Args: + inputs: Requred. a List of instances to predict on based on the input spec. + Returns: + A list of predictions based on the output spec. + """ + instances = [] + for input in inputs: + instance = [input[feature] for feature in self._input_types] + instances.append(instance) + if self._explanation_enabled: + prediction_object = self._endpoint.explain(instances) + else: + prediction_object = self._endpoint.predict(instances) + outputs = [] + for prediction in prediction_object.predictions: + if isinstance(prediction, Mapping): + outputs.append({key: prediction[key] for key in self._output_types}) + else: + outputs.append( + {key: prediction[i] for i, key in enumerate(self._output_types)} + ) + if self._explanation_enabled: + for i, explanation in enumerate(prediction_object.explanations): + attributions = explanation.attributions + outputs[i]["feature_attribution"] = lit_dtypes.FeatureSalience( + attributions + ) + return outputs + + def input_spec(self) -> lit_types.Spec: + """Return a spec describing model inputs.""" + return dict(self._input_types) + + def output_spec(self) -> lit_types.Spec: + """Return a spec describing model outputs.""" + output_spec_dict = dict(self._output_types) + if self._explanation_enabled: + output_spec_dict["feature_attribution"] = lit_types.FeatureSalience( + signed=True + ) + return output_spec_dict + + +class _TensorFlowLitModel(lit_model.Model): + """LIT model class for the Vertex LIT integration with a TensorFlow saved model. + + This is used in the create_lit_model function. + """ + + def __init__( + self, + model: str, + input_types: "OrderedDict[str, lit_types.LitType]", # noqa: F821 + output_types: "OrderedDict[str, lit_types.LitType]", # noqa: F821 + attribution_method: str = "sampled_shapley", + ): + """Construct a VertexLitModel. + Args: + model: + Required. A string reference to a local TensorFlow saved model directory. + The model must have at most one input and one output tensor. + input_types: + Required. An OrderedDict of string names matching the features of the model + as the key, and the associated LitType of the feature. + output_types: + Required. An OrderedDict of string names matching the labels of the model + as the key, and the associated LitType of the label. + attribution_method: + Optional. A string to choose what attribution configuration to + set up the explainer with. Valid options are 'sampled_shapley' + or 'integrated_gradients'. + """ + self._load_model(model) + self._input_types = input_types + self._output_types = output_types + self._input_tensor_name = next(iter(self._kwargs_signature)) + self._attribution_explainer = None + if os.environ.get("LIT_PROXY_URL"): + self._set_up_attribution_explainer(model, attribution_method) + + @property + def attribution_explainer( + self, + ) -> Optional["AttributionExplainer"]: # noqa: F821 + """Gets the attribution explainer property if set.""" + return self._attribution_explainer + + def predict_minibatch( + self, inputs: List[lit_types.JsonDict] + ) -> List[lit_types.JsonDict]: + """Retun predictions based on a batch of inputs. + Args: + inputs: Requred. a List of instances to predict on based on the input spec. + Returns: + A list of predictions based on the output spec. + """ + instances = [] + for input in inputs: + instance = [input[feature] for feature in self._input_types] + instances.append(instance) + prediction_input_dict = { + self._input_tensor_name: tf.convert_to_tensor(instances) + } + prediction_dict = self._loaded_model.signatures[ + tf.saved_model.DEFAULT_SERVING_SIGNATURE_DEF_KEY + ](**prediction_input_dict) + predictions = prediction_dict[next(iter(self._output_signature))].numpy() + outputs = [] + for prediction in predictions: + outputs.append( + { + label: value + for label, value in zip(self._output_types.keys(), prediction) + } + ) + # Get feature attributions + if self.attribution_explainer: + attributions = self.attribution_explainer.explain( + [{self._input_tensor_name: i} for i in instances] + ) + for i, attribution in enumerate(attributions): + outputs[i]["feature_attribution"] = lit_dtypes.FeatureSalience( + attribution.feature_importance() + ) + return outputs + + def input_spec(self) -> lit_types.Spec: + """Return a spec describing model inputs.""" + return dict(self._input_types) + + def output_spec(self) -> lit_types.Spec: + """Return a spec describing model outputs.""" + output_spec_dict = dict(self._output_types) + if self.attribution_explainer: + output_spec_dict["feature_attribution"] = lit_types.FeatureSalience( + signed=True + ) + return output_spec_dict + + def _load_model(self, model: str): + """Loads a TensorFlow saved model and populates the input and output signature attributes of the class. + Args: + model: Required. A string reference to a TensorFlow saved model directory. + Raises: + ValueError if the model has more than one input tensor or more than one output tensor. + """ + self._loaded_model = tf.saved_model.load(model) + serving_default = self._loaded_model.signatures[ + tf.saved_model.DEFAULT_SERVING_SIGNATURE_DEF_KEY + ] + _, self._kwargs_signature = serving_default.structured_input_signature + self._output_signature = serving_default.structured_outputs + + if len(self._kwargs_signature) != 1: + raise ValueError("Please use a model with only one input tensor.") + + if len(self._output_signature) != 1: + raise ValueError("Please use a model with only one output tensor.") + + def _set_up_attribution_explainer( + self, model: str, attribution_method: str = "integrated_gradients" + ): + """Populates the attribution explainer attribute of the class. + Args: + model: Required. A string reference to a TensorFlow saved model directory. + attribution_method: + Optional. A string to choose what attribution configuration to + set up the explainer with. Valid options are 'sampled_shapley' + or 'integrated_gradients'. + """ + try: + import explainable_ai_sdk + from explainable_ai_sdk.metadata.tf.v2 import SavedModelMetadataBuilder + except ImportError: + logging.info( + "Skipping explanations because the Explainable AI SDK is not installed." + 'Please install the SDK using "pip install explainable-ai-sdk"' + ) + return + + builder = SavedModelMetadataBuilder(model) + builder.get_metadata() + builder.set_numeric_metadata( + self._input_tensor_name, + index_feature_mapping=list(self._input_types.keys()), + ) + builder.save_metadata(model) + if attribution_method == "integrated_gradients": + explainer_config = explainable_ai_sdk.IntegratedGradientsConfig() + else: + explainer_config = explainable_ai_sdk.SampledShapleyConfig() + + self._attribution_explainer = explainable_ai_sdk.load_model_from_local_path( + model, explainer_config + ) + self._load_model(model) + + +def create_lit_dataset( + dataset: pd.DataFrame, + column_types: "OrderedDict[str, lit_types.LitType]", # noqa: F821 +) -> lit_dataset.Dataset: + """Creates a LIT Dataset object. + Args: + dataset: + Required. A Pandas DataFrame that includes feature column names and data. + column_types: + Required. An OrderedDict of string names matching the columns of the dataset + as the key, and the associated LitType of the column. + Returns: + A LIT Dataset object that has the data from the dataset provided. + """ + return _VertexLitDataset(dataset, column_types) + + +def create_lit_model_from_endpoint( + endpoint: Union[str, aiplatform.Endpoint], + input_types: "OrderedDict[str, lit_types.LitType]", # noqa: F821 + output_types: "OrderedDict[str, lit_types.LitType]", # noqa: F821 + model_id: Optional[str] = None, +) -> lit_model.Model: + """Creates a LIT Model object. + Args: + model: + Required. The name of the Endpoint resource or an Endpoint instance. + Endpoint name format: ``projects/{project}/locations/{location}/endpoints/{endpoint}`` + input_types: + Required. An OrderedDict of string names matching the features of the model + as the key, and the associated LitType of the feature. + output_types: + Required. An OrderedDict of string names matching the labels of the model + as the key, and the associated LitType of the label. + model_id: + Optional. A string of the specific model in the endpoint to create the + LIT model from. If this is not set, any usable model in the endpoint is + used to create the LIT model. + Returns: + A LIT Model object that has the same functionality as the model provided. + """ + return _EndpointLitModel(endpoint, input_types, output_types, model_id) + + +def create_lit_model( + model: str, + input_types: "OrderedDict[str, lit_types.LitType]", # noqa: F821 + output_types: "OrderedDict[str, lit_types.LitType]", # noqa: F821 + attribution_method: str = "sampled_shapley", +) -> lit_model.Model: + """Creates a LIT Model object. + Args: + model: + Required. A string reference to a local TensorFlow saved model directory. + The model must have at most one input and one output tensor. + input_types: + Required. An OrderedDict of string names matching the features of the model + as the key, and the associated LitType of the feature. + output_types: + Required. An OrderedDict of string names matching the labels of the model + as the key, and the associated LitType of the label. + attribution_method: + Optional. A string to choose what attribution configuration to + set up the explainer with. Valid options are 'sampled_shapley' + or 'integrated_gradients'. + Returns: + A LIT Model object that has the same functionality as the model provided. + """ + return _TensorFlowLitModel(model, input_types, output_types, attribution_method) + + +def open_lit( + models: Dict[str, lit_model.Model], + datasets: Dict[str, lit_dataset.Dataset], + open_in_new_tab: bool = True, +): + """Open LIT from the provided models and datasets. + Args: + models: + Required. A list of LIT models to open LIT with. + input_types: + Required. A lit of LIT datasets to open LIT with. + open_in_new_tab: + Optional. A boolean to choose if LIT open in a new tab or not. + Raises: + ImportError if LIT is not installed. + """ + widget = notebook.LitWidget(models, datasets) + widget.render(open_in_new_tab=open_in_new_tab) + + +def set_up_and_open_lit( + dataset: Union[pd.DataFrame, lit_dataset.Dataset], + column_types: "OrderedDict[str, lit_types.LitType]", # noqa: F821 + model: Union[str, lit_model.Model], + input_types: Union[List[str], Dict[str, lit_types.LitType]], + output_types: Union[str, List[str], Dict[str, lit_types.LitType]], + attribution_method: str = "sampled_shapley", + open_in_new_tab: bool = True, +) -> Tuple[lit_dataset.Dataset, lit_model.Model]: + """Creates a LIT dataset and model and opens LIT. + Args: + dataset: + Required. A Pandas DataFrame that includes feature column names and data. + column_types: + Required. An OrderedDict of string names matching the columns of the dataset + as the key, and the associated LitType of the column. + model: + Required. A string reference to a TensorFlow saved model directory. + The model must have at most one input and one output tensor. + input_types: + Required. An OrderedDict of string names matching the features of the model + as the key, and the associated LitType of the feature. + output_types: + Required. An OrderedDict of string names matching the labels of the model + as the key, and the associated LitType of the label. + attribution_method: + Optional. A string to choose what attribution configuration to + set up the explainer with. Valid options are 'sampled_shapley' + or 'integrated_gradients'. + open_in_new_tab: + Optional. A boolean to choose if LIT open in a new tab or not. + Returns: + A Tuple of the LIT dataset and model created. + Raises: + ImportError if LIT or TensorFlow is not installed. + ValueError if the model doesn't have only 1 input and output tensor. + """ + if not isinstance(dataset, lit_dataset.Dataset): + dataset = create_lit_dataset(dataset, column_types) + + if not isinstance(model, lit_model.Model): + model = create_lit_model( + model, input_types, output_types, attribution_method=attribution_method + ) + + open_lit( + {"model": model}, + {"dataset": dataset}, + open_in_new_tab=open_in_new_tab, + ) + + return dataset, model diff --git a/google/cloud/aiplatform/explain/metadata/__init__.py b/google/cloud/aiplatform/explain/metadata/__init__.py new file mode 100644 index 0000000000..0e973c9a40 --- /dev/null +++ b/google/cloud/aiplatform/explain/metadata/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- + +# 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 +# +# 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. diff --git a/google/cloud/aiplatform/explain/metadata/metadata_builder.py b/google/cloud/aiplatform/explain/metadata/metadata_builder.py new file mode 100644 index 0000000000..002317d508 --- /dev/null +++ b/google/cloud/aiplatform/explain/metadata/metadata_builder.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- + +# 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 +# +# 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. + + +"""Base abstract class for metadata builders.""" + +import abc + +_ABC = abc.ABCMeta("ABC", (object,), {"__slots__": ()}) + + +class MetadataBuilder(_ABC): + """Abstract base class for metadata builders.""" + + @abc.abstractmethod + def get_metadata(self): + """Returns the current metadata as a dictionary.""" + + @abc.abstractmethod + def get_metadata_protobuf(self): + """Returns the current metadata as ExplanationMetadata protobuf""" diff --git a/google/cloud/aiplatform/explain/metadata/tf/__init__.py b/google/cloud/aiplatform/explain/metadata/tf/__init__.py new file mode 100644 index 0000000000..0e973c9a40 --- /dev/null +++ b/google/cloud/aiplatform/explain/metadata/tf/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- + +# 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 +# +# 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. diff --git a/google/cloud/aiplatform/explain/metadata/tf/v1/__init__.py b/google/cloud/aiplatform/explain/metadata/tf/v1/__init__.py new file mode 100644 index 0000000000..0e973c9a40 --- /dev/null +++ b/google/cloud/aiplatform/explain/metadata/tf/v1/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- + +# 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 +# +# 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. diff --git a/google/cloud/aiplatform/explain/metadata/tf/v1/saved_model_metadata_builder.py b/google/cloud/aiplatform/explain/metadata/tf/v1/saved_model_metadata_builder.py new file mode 100644 index 0000000000..c9fc2d0e22 --- /dev/null +++ b/google/cloud/aiplatform/explain/metadata/tf/v1/saved_model_metadata_builder.py @@ -0,0 +1,171 @@ +# -*- coding: utf-8 -*- + +# 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 +# +# 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 google.protobuf import json_format +from typing import Any, Dict, List, Optional + +from google.cloud.aiplatform.compat.types import explanation_metadata +from google.cloud.aiplatform.explain.metadata import metadata_builder + + +class SavedModelMetadataBuilder(metadata_builder.MetadataBuilder): + """Metadata builder class that accepts a TF1 saved model.""" + + def __init__( + self, + model_path: str, + tags: Optional[List[str]] = None, + signature_name: Optional[str] = None, + outputs_to_explain: Optional[List[str]] = None, + ) -> None: + """Initializes a SavedModelMetadataBuilder object. + + Args: + model_path: + Required. Local or GCS path to load the saved model from. + tags: + Optional. Tags to identify the model graph. If None or empty, + TensorFlow's default serving tag will be used. + signature_name: + Optional. Name of the signature to be explained. Inputs and + outputs of this signature will be written in the metadata. If not + provided, the default signature will be used. + outputs_to_explain: + Optional. List of output names to explain. Only single output is + supported for now. Hence, the list should contain one element. + This parameter is required if the model signature (provided via + signature_name) specifies multiple outputs. + + Raises: + ValueError: If outputs_to_explain contains more than 1 element or + signature contains multiple outputs. + """ + if outputs_to_explain: + if len(outputs_to_explain) > 1: + raise ValueError( + "Only one output is supported at the moment. " + f"Received: {outputs_to_explain}." + ) + self._output_to_explain = next(iter(outputs_to_explain)) + + try: + import tensorflow.compat.v1 as tf + except ImportError: + raise ImportError( + "Tensorflow is not installed and is required to load saved model. " + 'Please install the SDK using "pip install "tensorflow>=1.15,<2.0""' + ) + + if not signature_name: + signature_name = tf.saved_model.DEFAULT_SERVING_SIGNATURE_DEF_KEY + self._tags = tags or [tf.saved_model.tag_constants.SERVING] + self._graph = tf.Graph() + + with self.graph.as_default(): + self._session = tf.Session(graph=self.graph) + self._metagraph_def = tf.saved_model.loader.load( + sess=self.session, tags=self._tags, export_dir=model_path + ) + if signature_name not in self._metagraph_def.signature_def: + raise ValueError( + f"Serving sigdef key {signature_name} not in the signature def." + ) + serving_sigdef = self._metagraph_def.signature_def[signature_name] + if not outputs_to_explain: + if len(serving_sigdef.outputs) > 1: + raise ValueError( + "The signature contains multiple outputs. Specify " + 'an output via "outputs_to_explain" parameter.' + ) + self._output_to_explain = next(iter(serving_sigdef.outputs.keys())) + + self._inputs = _create_input_metadata_from_signature(serving_sigdef.inputs) + self._outputs = _create_output_metadata_from_signature( + serving_sigdef.outputs, self._output_to_explain + ) + + @property + def graph(self) -> "tf.Graph": # noqa: F821 + return self._graph + + @property + def session(self) -> "tf.Session": # noqa: F821 + return self._session + + def get_metadata(self) -> Dict[str, Any]: + """Returns the current metadata as a dictionary. + + Returns: + Json format of the explanation metadata. + """ + return json_format.MessageToDict(self.get_metadata_protobuf()._pb) + + def get_metadata_protobuf(self) -> explanation_metadata.ExplanationMetadata: + """Returns the current metadata as a Protobuf object. + + Returns: + ExplanationMetadata object format of the explanation metadata. + """ + return explanation_metadata.ExplanationMetadata( + inputs=self._inputs, + outputs=self._outputs, + ) + + +def _create_input_metadata_from_signature( + signature_inputs: Dict[str, "tf.Tensor"] # noqa: F821 +) -> Dict[str, explanation_metadata.ExplanationMetadata.InputMetadata]: + """Creates InputMetadata from signature inputs. + + Args: + signature_inputs: + Required. Inputs of the signature to be explained. If not provided, + the default signature will be used. + + Returns: + Inferred input metadata from the model. + """ + input_mds = {} + for key, tensor in signature_inputs.items(): + input_mds[key] = explanation_metadata.ExplanationMetadata.InputMetadata( + input_tensor_name=tensor.name + ) + return input_mds + + +def _create_output_metadata_from_signature( + signature_outputs: Dict[str, "tf.Tensor"], # noqa: F821 + output_to_explain: Optional[str] = None, +) -> Dict[str, explanation_metadata.ExplanationMetadata.OutputMetadata]: + """Creates OutputMetadata from signature inputs. + + Args: + signature_outputs: + Required. Inputs of the signature to be explained. If not provided, + the default signature will be used. + output_to_explain: + Optional. Output name to explain. + + Returns: + Inferred output metadata from the model. + """ + output_mds = {} + for key, tensor in signature_outputs.items(): + if not output_to_explain or output_to_explain == key: + output_mds[key] = explanation_metadata.ExplanationMetadata.OutputMetadata( + output_tensor_name=tensor.name + ) + return output_mds diff --git a/google/cloud/aiplatform/explain/metadata/tf/v2/__init__.py b/google/cloud/aiplatform/explain/metadata/tf/v2/__init__.py new file mode 100644 index 0000000000..0e973c9a40 --- /dev/null +++ b/google/cloud/aiplatform/explain/metadata/tf/v2/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- + +# 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 +# +# 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. diff --git a/google/cloud/aiplatform/explain/metadata/tf/v2/saved_model_metadata_builder.py b/google/cloud/aiplatform/explain/metadata/tf/v2/saved_model_metadata_builder.py new file mode 100644 index 0000000000..7d19e5680d --- /dev/null +++ b/google/cloud/aiplatform/explain/metadata/tf/v2/saved_model_metadata_builder.py @@ -0,0 +1,139 @@ +# -*- coding: utf-8 -*- + +# 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 +# +# 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 google.protobuf import json_format +from typing import Optional, List, Dict, Any, Tuple + +from google.cloud.aiplatform.explain.metadata import metadata_builder +from google.cloud.aiplatform.compat.types import explanation_metadata + + +class SavedModelMetadataBuilder(metadata_builder.MetadataBuilder): + """Class for generating metadata for a model built with TF 2.X Keras API.""" + + def __init__( + self, + model_path: str, + signature_name: Optional[str] = None, + outputs_to_explain: Optional[List[str]] = None, + **kwargs + ) -> None: + """Initializes a SavedModelMetadataBuilder object. + + Args: + model_path: + Required. Local or GCS path to load the saved model from. + signature_name: + Optional. Name of the signature to be explained. Inputs and + outputs of this signature will be written in the metadata. If not + provided, the default signature will be used. + outputs_to_explain: + Optional. List of output names to explain. Only single output is + supported for now. Hence, the list should contain one element. + This parameter is required if the model signature (provided via + signature_name) specifies multiple outputs. + **kwargs: + Any keyword arguments to be passed to tf.saved_model.save() function. + + Raises: + ValueError: If outputs_to_explain contains more than 1 element. + ImportError: If tf is not imported. + """ + if outputs_to_explain and len(outputs_to_explain) > 1: + raise ValueError( + '"outputs_to_explain" can only contain 1 element.\n' + "Got: %s" % len(outputs_to_explain) + ) + self._explain_output = outputs_to_explain + self._saved_model_args = kwargs + + try: + import tensorflow as tf + except ImportError: + raise ImportError( + "Tensorflow is not installed and is required to load saved model. " + 'Please install the SDK using "pip install google-cloud-aiplatform[full]"' + ) + + if not signature_name: + signature_name = tf.saved_model.DEFAULT_SERVING_SIGNATURE_DEF_KEY + self._loaded_model = tf.saved_model.load(model_path) + self._inputs, self._outputs = self._infer_metadata_entries_from_model( + signature_name + ) + + def _infer_metadata_entries_from_model( + self, signature_name: str + ) -> Tuple[ + Dict[str, explanation_metadata.ExplanationMetadata.InputMetadata], + Dict[str, explanation_metadata.ExplanationMetadata.OutputMetadata], + ]: + """Infers metadata inputs and outputs. + + Args: + signature_name: + Required. Name of the signature to be explained. Inputs and outputs of this signature will be written in the metadata. If not provided, the default signature will be used. + + Returns: + Inferred input metadata and output metadata from the model. + + Raises: + ValueError: If specified name is not found in signature outputs. + """ + + loaded_sig = self._loaded_model.signatures[signature_name] + _, input_sig = loaded_sig.structured_input_signature + output_sig = loaded_sig.structured_outputs + input_mds = {} + for name, tensor_spec in input_sig.items(): + input_mds[name] = explanation_metadata.ExplanationMetadata.InputMetadata( + input_tensor_name=name, + modality=None if tensor_spec.dtype.is_floating else "categorical", + ) + + output_mds = {} + for name in output_sig: + if not self._explain_output or self._explain_output[0] == name: + output_mds[ + name + ] = explanation_metadata.ExplanationMetadata.OutputMetadata( + output_tensor_name=name, + ) + break + else: + raise ValueError( + "Specified output name cannot be found in given signature outputs." + ) + return input_mds, output_mds + + def get_metadata(self) -> Dict[str, Any]: + """Returns the current metadata as a dictionary. + + Returns: + Json format of the explanation metadata. + """ + return json_format.MessageToDict(self.get_metadata_protobuf()._pb) + + def get_metadata_protobuf(self) -> explanation_metadata.ExplanationMetadata: + """Returns the current metadata as a Protobuf object. + + Returns: + ExplanationMetadata object format of the explanation metadata. + """ + return explanation_metadata.ExplanationMetadata( + inputs=self._inputs, + outputs=self._outputs, + ) diff --git a/google/cloud/aiplatform/featurestore/__init__.py b/google/cloud/aiplatform/featurestore/__init__.py new file mode 100644 index 0000000000..883f72dd26 --- /dev/null +++ b/google/cloud/aiplatform/featurestore/__init__.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- + +# 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 +# +# 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 google.cloud.aiplatform.featurestore.entity_type import EntityType +from google.cloud.aiplatform.featurestore.feature import Feature +from google.cloud.aiplatform.featurestore.featurestore import Featurestore + +__all__ = ( + "EntityType", + "Feature", + "Featurestore", +) diff --git a/google/cloud/aiplatform/featurestore/entity_type.py b/google/cloud/aiplatform/featurestore/entity_type.py new file mode 100644 index 0000000000..edd0c7433b --- /dev/null +++ b/google/cloud/aiplatform/featurestore/entity_type.py @@ -0,0 +1,1540 @@ +# -*- coding: utf-8 -*- + +# 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 +# +# 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. +# + +import datetime +from typing import Dict, List, Optional, Sequence, Tuple, Union +import uuid + +from google.auth import credentials as auth_credentials +from google.protobuf import field_mask_pb2 + +from google.cloud.aiplatform import base +from google.cloud.aiplatform.compat.types import ( + entity_type as gca_entity_type, + feature_selector as gca_feature_selector, + featurestore_service as gca_featurestore_service, + featurestore_online_service as gca_featurestore_online_service, + io as gca_io, +) +from google.cloud.aiplatform import featurestore +from google.cloud.aiplatform import initializer +from google.cloud.aiplatform import utils +from google.cloud.aiplatform.utils import featurestore_utils, resource_manager_utils + +from google.cloud import bigquery + +_LOGGER = base.Logger(__name__) +_ALL_FEATURE_IDS = "*" + + +class EntityType(base.VertexAiResourceNounWithFutureManager): + """Managed entityType resource for Vertex AI.""" + + client_class = utils.FeaturestoreClientWithOverride + + _resource_noun = "entityTypes" + _getter_method = "get_entity_type" + _list_method = "list_entity_types" + _delete_method = "delete_entity_type" + _parse_resource_name_method = "parse_entity_type_path" + _format_resource_name_method = "entity_type_path" + + @staticmethod + def _resource_id_validator(resource_id: str): + """Validates resource ID. + + Args: + resource_id(str): + The resource id to validate. + """ + featurestore_utils.validate_id(resource_id) + + def __init__( + self, + entity_type_name: str, + featurestore_id: Optional[str] = None, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ): + """Retrieves an existing managed entityType given an entityType resource name or an entity_type ID. + + Example Usage: + + my_entity_type = aiplatform.EntityType( + entity_type_name='projects/123/locations/us-central1/featurestores/my_featurestore_id/\ + entityTypes/my_entity_type_id' + ) + or + my_entity_type = aiplatform.EntityType( + entity_type_name='my_entity_type_id', + featurestore_id='my_featurestore_id', + ) + + Args: + entity_type_name (str): + Required. A fully-qualified entityType resource name or an entity_type ID. + Example: "projects/123/locations/us-central1/featurestores/my_featurestore_id/entityTypes/my_entity_type_id" + or "my_entity_type_id" when project and location are initialized or passed, with featurestore_id passed. + featurestore_id (str): + Optional. Featurestore ID of an existing featurestore to retrieve entityType from, + when entity_type_name is passed as entity_type ID. + project (str): + Optional. Project to retrieve entityType from. If not set, project + set in aiplatform.init will be used. + location (str): + Optional. Location to retrieve entityType from. If not set, location + set in aiplatform.init will be used. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to retrieve this EntityType. Overrides + credentials set in aiplatform.init. + """ + + super().__init__( + project=project, + location=location, + credentials=credentials, + resource_name=entity_type_name, + ) + self._gca_resource = self._get_gca_resource( + resource_name=entity_type_name, + parent_resource_name_fields={ + featurestore.Featurestore._resource_noun: featurestore_id + } + if featurestore_id + else featurestore_id, + ) + + self._featurestore_online_client = self._instantiate_featurestore_online_client( + location=self.location, + credentials=credentials, + ) + + def _get_featurestore_name(self) -> str: + """Gets full qualified resource name of the managed featurestore in which this EntityType is.""" + entity_type_name_components = self._parse_resource_name(self.resource_name) + return featurestore.Featurestore._format_resource_name( + project=entity_type_name_components["project"], + location=entity_type_name_components["location"], + featurestore=entity_type_name_components["featurestore"], + ) + + @property + def featurestore_name(self) -> str: + """Full qualified resource name of the managed featurestore in which this EntityType is.""" + self.wait() + return self._get_featurestore_name() + + def get_featurestore(self) -> "featurestore.Featurestore": + """Retrieves the managed featurestore in which this EntityType is. + + Returns: + featurestore.Featurestore - The managed featurestore in which this EntityType is. + """ + return featurestore.Featurestore(self.featurestore_name) + + def _get_feature(self, feature_id: str) -> "featurestore.Feature": + """Retrieves an existing managed feature in this EntityType. + + Args: + feature_id (str): + Required. The managed feature resource ID in this EntityType. + Returns: + featurestore.Feature - The managed feature resource object. + """ + entity_type_name_components = self._parse_resource_name(self.resource_name) + return featurestore.Feature( + feature_name=featurestore.Feature._format_resource_name( + project=entity_type_name_components["project"], + location=entity_type_name_components["location"], + featurestore=entity_type_name_components["featurestore"], + entity_type=entity_type_name_components["entity_type"], + feature=feature_id, + ) + ) + + def get_feature(self, feature_id: str) -> "featurestore.Feature": + """Retrieves an existing managed feature in this EntityType. + + Args: + feature_id (str): + Required. The managed feature resource ID in this EntityType. + Returns: + featurestore.Feature - The managed feature resource object. + """ + self.wait() + return self._get_feature(feature_id=feature_id) + + def update( + self, + description: Optional[str] = None, + labels: Optional[Dict[str, str]] = None, + request_metadata: Sequence[Tuple[str, str]] = (), + update_request_timeout: Optional[float] = None, + ) -> "EntityType": + """Updates an existing managed entityType resource. + + Example Usage: + + my_entity_type = aiplatform.EntityType( + entity_type_name='my_entity_type_id', + featurestore_id='my_featurestore_id', + ) + my_entity_type.update( + description='update my description', + ) + + Args: + description (str): + Optional. Description of the EntityType. + labels (Dict[str, str]): + Optional. The labels with user-defined + metadata to organize your EntityTypes. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + on and examples of labels. No more than 64 user + labels can be associated with one Feature + (System labels are excluded)." + System reserved label keys are prefixed with + "aiplatform.googleapis.com/" and are immutable. + request_metadata (Sequence[Tuple[str, str]]): + Required. Strings which should be sent along with the request as metadata. + update_request_timeout (float): + Optional. The timeout for the update request in seconds. + Returns: + EntityType - The updated entityType resource object. + """ + self.wait() + update_mask = list() + + if description: + update_mask.append("description") + + if labels: + utils.validate_labels(labels) + update_mask.append("labels") + + update_mask = field_mask_pb2.FieldMask(paths=update_mask) + + gapic_entity_type = gca_entity_type.EntityType( + name=self.resource_name, + description=description, + labels=labels, + ) + + _LOGGER.log_action_start_against_resource( + "Updating", + "entityType", + self, + ) + + update_entity_type_lro = self.api_client.update_entity_type( + entity_type=gapic_entity_type, + update_mask=update_mask, + metadata=request_metadata, + timeout=update_request_timeout, + ) + + _LOGGER.log_action_started_against_resource_with_lro( + "Update", "entityType", self.__class__, update_entity_type_lro + ) + + update_entity_type_lro.result() + + _LOGGER.log_action_completed_against_resource("entityType", "updated", self) + + return self + + @classmethod + def list( + cls, + featurestore_name: str, + filter: Optional[str] = None, + order_by: Optional[str] = None, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ) -> List["EntityType"]: + """Lists existing managed entityType resources in a featurestore, given a featurestore resource name or a featurestore ID. + + Example Usage: + + my_entityTypes = aiplatform.EntityType.list( + featurestore_name='projects/123/locations/us-central1/featurestores/my_featurestore_id' + ) + or + my_entityTypes = aiplatform.EntityType.list( + featurestore_name='my_featurestore_id' + ) + + Args: + featurestore_name (str): + Required. A fully-qualified featurestore resource name or a featurestore ID + of an existing featurestore to list entityTypes in. + Example: "projects/123/locations/us-central1/featurestores/my_featurestore_id" + or "my_featurestore_id" when project and location are initialized or passed. + filter (str): + Optional. Lists the EntityTypes that match the filter expression. The + following filters are supported: + + - ``create_time``: Supports ``=``, ``!=``, ``<``, ``>``, + ``>=``, and ``<=`` comparisons. Values must be in RFC + 3339 format. + - ``update_time``: Supports ``=``, ``!=``, ``<``, ``>``, + ``>=``, and ``<=`` comparisons. Values must be in RFC + 3339 format. + - ``labels``: Supports key-value equality as well as key + presence. + + Examples: + + - ``create_time > \"2020-01-31T15:30:00.000000Z\" OR update_time > \"2020-01-31T15:30:00.000000Z\"`` + --> EntityTypes created or updated after + 2020-01-31T15:30:00.000000Z. + - ``labels.active = yes AND labels.env = prod`` --> + EntityTypes having both (active: yes) and (env: prod) + labels. + - ``labels.env: *`` --> Any EntityType which has a label + with 'env' as the key. + order_by (str): + Optional. A comma-separated list of fields to order by, sorted in + ascending order. Use "desc" after a field name for + descending. + + Supported fields: + + - ``entity_type_id`` + - ``create_time`` + - ``update_time`` + project (str): + Optional. Project to list entityTypes in. If not set, project + set in aiplatform.init will be used. + location (str): + Optional. Location to list entityTypes in. If not set, location + set in aiplatform.init will be used. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to list entityTypes. Overrides + credentials set in aiplatform.init. + + Returns: + List[EntityType] - A list of managed entityType resource objects + """ + + return cls._list( + filter=filter, + order_by=order_by, + project=project, + location=location, + credentials=credentials, + parent=utils.full_resource_name( + resource_name=featurestore_name, + resource_noun=featurestore.Featurestore._resource_noun, + parse_resource_name_method=featurestore.Featurestore._parse_resource_name, + format_resource_name_method=featurestore.Featurestore._format_resource_name, + project=project, + location=location, + resource_id_validator=featurestore.Featurestore._resource_id_validator, + ), + ) + + def list_features( + self, + filter: Optional[str] = None, + order_by: Optional[str] = None, + ) -> List["featurestore.Feature"]: + """Lists existing managed feature resources in this EntityType. + + Example Usage: + + my_entity_type = aiplatform.EntityType( + entity_type_name='my_entity_type_id', + featurestore_id='my_featurestore_id', + ) + my_entityType.list_features() + + Args: + filter (str): + Optional. Lists the Features that match the filter expression. The + following filters are supported: + + - ``value_type``: Supports = and != comparisons. + - ``create_time``: Supports =, !=, <, >, >=, and <= + comparisons. Values must be in RFC 3339 format. + - ``update_time``: Supports =, !=, <, >, >=, and <= + comparisons. Values must be in RFC 3339 format. + - ``labels``: Supports key-value equality as well as key + presence. + + Examples: + + - ``value_type = DOUBLE`` --> Features whose type is + DOUBLE. + - ``create_time > \"2020-01-31T15:30:00.000000Z\" OR update_time > \"2020-01-31T15:30:00.000000Z\"`` + --> EntityTypes created or updated after + 2020-01-31T15:30:00.000000Z. + - ``labels.active = yes AND labels.env = prod`` --> + Features having both (active: yes) and (env: prod) + labels. + - ``labels.env: *`` --> Any Feature which has a label with + 'env' as the key. + order_by (str): + Optional. A comma-separated list of fields to order by, sorted in + ascending order. Use "desc" after a field name for + descending. Supported fields: + + - ``feature_id`` + - ``value_type`` + - ``create_time`` + - ``update_time`` + + Returns: + List[featurestore.Feature] - A list of managed feature resource objects. + """ + self.wait() + return featurestore.Feature.list( + entity_type_name=self.resource_name, + filter=filter, + order_by=order_by, + ) + + @base.optional_sync() + def delete_features( + self, + feature_ids: List[str], + sync: bool = True, + ) -> None: + """Deletes feature resources in this EntityType given their feature IDs. + WARNING: This deletion is permanent. + + Args: + feature_ids (List[str]): + Required. The list of feature IDs to be deleted. + sync (bool): + Optional. Whether to execute this deletion synchronously. If False, this method + will be executed in concurrent Future and any downstream object will + be immediately returned and synced when the Future has completed. + """ + features = [] + for feature_id in feature_ids: + feature = self._get_feature(feature_id=feature_id) + feature.delete(sync=False) + features.append(feature) + + for feature in features: + feature.wait() + + @base.optional_sync() + def delete(self, sync: bool = True, force: bool = False) -> None: + """Deletes this EntityType resource. If force is set to True, + all features in this EntityType will be deleted prior to entityType deletion. + + WARNING: This deletion is permanent. + + Args: + force (bool): + If set to true, any Features for this + EntityType will also be deleted. + (Otherwise, the request will only work + if the EntityType has no Features.) + sync (bool): + Whether to execute this deletion synchronously. If False, this method + will be executed in concurrent Future and any downstream object will + be immediately returned and synced when the Future has completed. + Raises: + FailedPrecondition: If features are created in this EntityType and force = False. + """ + _LOGGER.log_action_start_against_resource("Deleting", "", self) + lro = getattr(self.api_client, self._delete_method)( + name=self.resource_name, force=force + ) + _LOGGER.log_action_started_against_resource_with_lro( + "Delete", "", self.__class__, lro + ) + lro.result() + _LOGGER.log_action_completed_against_resource("deleted.", "", self) + + @classmethod + @base.optional_sync() + def create( + cls, + entity_type_id: str, + featurestore_name: str, + description: Optional[str] = None, + labels: Optional[Dict[str, str]] = None, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + sync: bool = True, + create_request_timeout: Optional[float] = None, + ) -> "EntityType": + """Creates an EntityType resource in a Featurestore. + + Example Usage: + + my_entity_type = aiplatform.EntityType.create( + entity_type_id='my_entity_type_id', + featurestore_name='projects/123/locations/us-central1/featurestores/my_featurestore_id' + ) + or + my_entity_type = aiplatform.EntityType.create( + entity_type_id='my_entity_type_id', + featurestore_name='my_featurestore_id', + ) + + Args: + entity_type_id (str): + Required. The ID to use for the EntityType, which will + become the final component of the EntityType's resource + name. + + This value may be up to 60 characters, and valid characters + are ``[a-z0-9_]``. The first character cannot be a number. + + The value must be unique within a featurestore. + featurestore_name (str): + Required. A fully-qualified featurestore resource name or a featurestore ID + of an existing featurestore to create EntityType in. + Example: "projects/123/locations/us-central1/featurestores/my_featurestore_id" + or "my_featurestore_id" when project and location are initialized or passed. + description (str): + Optional. Description of the EntityType. + labels (Dict[str, str]): + Optional. The labels with user-defined + metadata to organize your EntityTypes. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + on and examples of labels. No more than 64 user + labels can be associated with one EntityType + (System labels are excluded)." + System reserved label keys are prefixed with + "aiplatform.googleapis.com/" and are immutable. + project (str): + Optional. Project to create EntityType in if `featurestore_name` is passed an featurestore ID. + If not set, project set in aiplatform.init will be used. + location (str): + Optional. Location to create EntityType in if `featurestore_name` is passed an featurestore ID. + If not set, location set in aiplatform.init will be used. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to create EntityTypes. Overrides + credentials set in aiplatform.init. + request_metadata (Sequence[Tuple[str, str]]): + Optional. Strings which should be sent along with the request as metadata. + sync (bool): + Optional. Whether to execute this creation synchronously. If False, this method + will be executed in concurrent Future and any downstream object will + be immediately returned and synced when the Future has completed. + create_request_timeout (float): + Optional. The timeout for the create request in seconds. + Returns: + EntityType - entity_type resource object + + """ + + featurestore_name = utils.full_resource_name( + resource_name=featurestore_name, + resource_noun=featurestore.Featurestore._resource_noun, + parse_resource_name_method=featurestore.Featurestore._parse_resource_name, + format_resource_name_method=featurestore.Featurestore._format_resource_name, + project=project, + location=location, + resource_id_validator=featurestore.Featurestore._resource_id_validator, + ) + + featurestore_name_components = featurestore.Featurestore._parse_resource_name( + featurestore_name + ) + + gapic_entity_type = gca_entity_type.EntityType() + + if labels: + utils.validate_labels(labels) + gapic_entity_type.labels = labels + + if description: + gapic_entity_type.description = description + + api_client = cls._instantiate_client( + location=featurestore_name_components["location"], + credentials=credentials, + ) + + created_entity_type_lro = api_client.create_entity_type( + parent=featurestore_name, + entity_type=gapic_entity_type, + entity_type_id=entity_type_id, + metadata=request_metadata, + timeout=create_request_timeout, + ) + + _LOGGER.log_create_with_lro(cls, created_entity_type_lro) + + created_entity_type = created_entity_type_lro.result() + + _LOGGER.log_create_complete(cls, created_entity_type, "entity_type") + + entity_type_obj = cls( + entity_type_name=created_entity_type.name, + project=project, + location=location, + credentials=credentials, + ) + + return entity_type_obj + + def create_feature( + self, + feature_id: str, + value_type: str, + description: Optional[str] = None, + labels: Optional[Dict[str, str]] = None, + request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + sync: bool = True, + create_request_timeout: Optional[float] = None, + ) -> "featurestore.Feature": + """Creates a Feature resource in this EntityType. + + Example Usage: + + my_entity_type = aiplatform.EntityType( + entity_type_name='my_entity_type_id', + featurestore_id='my_featurestore_id', + ) + my_feature = my_entity_type.create_feature( + feature_id='my_feature_id', + value_type='INT64', + ) + + Args: + feature_id (str): + Required. The ID to use for the Feature, which will become + the final component of the Feature's resource name, which is immutable. + + This value may be up to 60 characters, and valid characters + are ``[a-z0-9_]``. The first character cannot be a number. + + The value must be unique within an EntityType. + value_type (str): + Required. Immutable. Type of Feature value. + One of BOOL, BOOL_ARRAY, DOUBLE, DOUBLE_ARRAY, INT64, INT64_ARRAY, STRING, STRING_ARRAY, BYTES. + description (str): + Optional. Description of the Feature. + labels (Dict[str, str]): + Optional. The labels with user-defined + metadata to organize your Features. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + on and examples of labels. No more than 64 user + labels can be associated with one Feature + (System labels are excluded)." + System reserved label keys are prefixed with + "aiplatform.googleapis.com/" and are immutable. + request_metadata (Sequence[Tuple[str, str]]): + Optional. Strings which should be sent along with the request as metadata. + create_request_timeout (float): + Optional. The timeout for the create request in seconds. + sync (bool): + Optional. Whether to execute this creation synchronously. If False, this method + will be executed in concurrent Future and any downstream object will + be immediately returned and synced when the Future has completed. + + Returns: + featurestore.Feature - feature resource object + + """ + self.wait() + return featurestore.Feature.create( + feature_id=feature_id, + value_type=value_type, + entity_type_name=self.resource_name, + description=description, + labels=labels, + request_metadata=request_metadata, + sync=sync, + create_request_timeout=create_request_timeout, + ) + + def _validate_and_get_create_feature_requests( + self, + feature_configs: Dict[str, Dict[str, Union[bool, int, Dict[str, str], str]]], + ) -> List[gca_featurestore_service.CreateFeatureRequest]: + """Validates feature_configs and get requests for batch feature creation + + Args: + feature_configs (Dict[str, Dict[str, Union[bool, int, Dict[str, str], str]]]): + Required. A user defined Dict containing configurations for feature creation. + + Returns: + List[gca_featurestore_service.CreateFeatureRequest] - requests for batch feature creation + """ + + requests = [] + for feature_id, feature_config in feature_configs.items(): + feature_config = featurestore_utils._FeatureConfig( + feature_id=feature_id, + value_type=feature_config.get( + "value_type", featurestore_utils._FEATURE_VALUE_TYPE_UNSPECIFIED + ), + description=feature_config.get("description", None), + labels=feature_config.get("labels", {}), + ) + create_feature_request = feature_config.get_create_feature_request() + requests.append(create_feature_request) + + return requests + + @base.optional_sync(return_input_arg="self") + def batch_create_features( + self, + feature_configs: Dict[str, Dict[str, Union[bool, int, Dict[str, str], str]]], + request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + sync: bool = True, + ) -> "EntityType": + """Batch creates Feature resources in this EntityType. + + Example Usage: + + my_entity_type = aiplatform.EntityType( + entity_type_name='my_entity_type_id', + featurestore_id='my_featurestore_id', + ) + my_entity_type.batch_create_features( + feature_configs={ + "my_feature_id1": { + "value_type": "INT64", + }, + "my_feature_id2": { + "value_type": "BOOL", + }, + "my_feature_id3": { + "value_type": "STRING", + }, + } + ) + + Args: + feature_configs (Dict[str, Dict[str, Union[bool, int, Dict[str, str], str]]]): + Required. A user defined Dict containing configurations for feature creation. + + The feature_configs Dict[str, Dict] i.e. {feature_id: feature_config} contains configuration for each creating feature: + Example: + feature_configs = { + "my_feature_id_1": feature_config_1, + "my_feature_id_2": feature_config_2, + "my_feature_id_3": feature_config_3, + } + + Each feature_config requires "value_type", and optional "description", "labels": + Example: + feature_config_1 = { + "value_type": "INT64", + } + feature_config_2 = { + "value_type": "BOOL", + "description": "my feature id 2 description" + } + feature_config_3 = { + "value_type": "STRING", + "labels": { + "my key": "my value", + } + } + + request_metadata (Sequence[Tuple[str, str]]): + Optional. Strings which should be sent along with the request as metadata. + sync (bool): + Optional. Whether to execute this creation synchronously. If False, this method + will be executed in concurrent Future and any downstream object will + be immediately returned and synced when the Future has completed. + + Returns: + EntityType - entity_type resource object + """ + create_feature_requests = self._validate_and_get_create_feature_requests( + feature_configs=feature_configs + ) + + _LOGGER.log_action_start_against_resource( + "Batch creating features", + "entityType", + self, + ) + + batch_created_features_lro = self.api_client.batch_create_features( + parent=self.resource_name, + requests=create_feature_requests, + metadata=request_metadata, + ) + + _LOGGER.log_action_started_against_resource_with_lro( + "Batch create Features", + "entityType", + self.__class__, + batch_created_features_lro, + ) + + batch_created_features_lro.result() + + _LOGGER.log_action_completed_against_resource( + "entityType", "Batch created features", self + ) + + return self + + @staticmethod + def _validate_and_get_import_feature_values_request( + entity_type_name: str, + feature_ids: List[str], + feature_time: Union[str, datetime.datetime], + data_source: Union[gca_io.AvroSource, gca_io.BigQuerySource, gca_io.CsvSource], + feature_source_fields: Optional[Dict[str, str]] = None, + entity_id_field: Optional[str] = None, + disable_online_serving: Optional[bool] = None, + worker_count: Optional[int] = None, + ) -> gca_featurestore_service.ImportFeatureValuesRequest: + """Validates and get import feature values request. + Args: + entity_type_name (str): + Required. A fully-qualified entityType resource name. + feature_ids (List[str]): + Required. IDs of the Feature to import values + of. The Features must exist in the target + EntityType, or the request will fail. + feature_time (Union[str, datetime.datetime]): + Required. The feature_time can be one of: + - The source column that holds the Feature + timestamp for all Feature values in each entity. + - A single Feature timestamp for all entities + being imported. The timestamp must not have + higher than millisecond precision. + data_source (Union[gca_io.AvroSource, gca_io.BiqQuerySource, gca_io.CsvSource]): + Required. The data_source can be one of: + - AvroSource + - BiqQuerySource + - CsvSource + feature_source_fields (Dict[str, str]): + Optional. User defined dictionary to map ID of the Feature for importing values + of to the source column for getting the Feature values from. + + Specify the features whose ID and source column are not the same. + If not provided, the source column need to be the same as the Feature ID. + + Example: + feature_ids = ['my_feature_id_1', 'my_feature_id_2', 'my_feature_id_3'] + + feature_source_fields = { + 'my_feature_id_1': 'my_feature_id_1_source_field', + } + + Note: + The source column of 'my_feature_id_1' is 'my_feature_id_1_source_field', + The source column of 'my_feature_id_2' is the ID of the feature, same for 'my_feature_id_3'. + + entity_id_field (str): + Optional. Source column that holds entity IDs. If not provided, entity + IDs are extracted from the column named ``entity_id``. + disable_online_serving (bool): + Optional. If set, data will not be imported for online + serving. This is typically used for backfilling, + where Feature generation timestamps are not in + the timestamp range needed for online serving. + worker_count (int): + Optional. Specifies the number of workers that are used + to write data to the Featurestore. Consider the + online serving capacity that you require to + achieve the desired import throughput without + interfering with online serving. The value must + be positive, and less than or equal to 100. If + not set, defaults to using 1 worker. The low + count ensures minimal impact on online serving + performance. + Returns: + gca_featurestore_service.ImportFeatureValuesRequest - request message for importing feature values + Raises: + ValueError if data_source type is not supported + ValueError if feature_time type is not supported + """ + feature_source_fields = feature_source_fields or {} + feature_specs = [ + gca_featurestore_service.ImportFeatureValuesRequest.FeatureSpec( + id=feature_id, source_field=feature_source_fields.get(feature_id) + ) + for feature_id in set(feature_ids) + ] + + import_feature_values_request = ( + gca_featurestore_service.ImportFeatureValuesRequest( + entity_type=entity_type_name, + feature_specs=feature_specs, + entity_id_field=entity_id_field, + disable_online_serving=disable_online_serving, + worker_count=worker_count, + ) + ) + + if isinstance(data_source, gca_io.AvroSource): + import_feature_values_request.avro_source = data_source + elif isinstance(data_source, gca_io.BigQuerySource): + import_feature_values_request.bigquery_source = data_source + elif isinstance(data_source, gca_io.CsvSource): + import_feature_values_request.csv_source = data_source + else: + raise ValueError( + f"The type of `data_source` field should be: " + f"`gca_io.AvroSource`, `gca_io.BigQuerySource`, or `gca_io.CsvSource`, " + f"get {type(data_source)} instead. " + ) + + if isinstance(feature_time, str): + import_feature_values_request.feature_time_field = feature_time + elif isinstance(feature_time, datetime.datetime): + import_feature_values_request.feature_time = utils.get_timestamp_proto( + time=feature_time + ) + else: + raise ValueError( + f"The type of `feature_time` field should be: `str` or `datetime.datetime`, " + f"get {type(feature_time)} instead. " + ) + + return import_feature_values_request + + def _import_feature_values( + self, + import_feature_values_request: gca_featurestore_service.ImportFeatureValuesRequest, + request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + ingest_request_timeout: Optional[float] = None, + ) -> "EntityType": + """Imports Feature values into the Featurestore from a source storage. + + Args: + import_feature_values_request (gca_featurestore_service.ImportFeatureValuesRequest): + Required. Request message for importing feature values. + request_metadata (Sequence[Tuple[str, str]]): + Optional. Strings which should be sent along with the request as metadata. + ingest_request_timeout (float): + Optional. The timeout for the ingest request in seconds. + Returns: + EntityType - The entityType resource object with imported feature values. + """ + _LOGGER.log_action_start_against_resource( + "Importing", + "feature values", + self, + ) + + import_lro = self.api_client.import_feature_values( + request=import_feature_values_request, + metadata=request_metadata, + timeout=ingest_request_timeout, + ) + + _LOGGER.log_action_started_against_resource_with_lro( + "Import", "feature values", self.__class__, import_lro + ) + + import_lro.result() + + _LOGGER.log_action_completed_against_resource( + "feature values", "imported", self + ) + + return self + + @base.optional_sync(return_input_arg="self") + def ingest_from_bq( + self, + feature_ids: List[str], + feature_time: Union[str, datetime.datetime], + bq_source_uri: str, + feature_source_fields: Optional[Dict[str, str]] = None, + entity_id_field: Optional[str] = None, + disable_online_serving: Optional[bool] = None, + worker_count: Optional[int] = None, + request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + sync: bool = True, + ingest_request_timeout: Optional[float] = None, + ) -> "EntityType": + """Ingest feature values from BigQuery. + + Args: + feature_ids (List[str]): + Required. IDs of the Feature to import values + of. The Features must exist in the target + EntityType, or the request will fail. + feature_time (Union[str, datetime.datetime]): + Required. The feature_time can be one of: + - The source column that holds the Feature + timestamp for all Feature values in each entity. + - A single Feature timestamp for all entities + being imported. The timestamp must not have + higher than millisecond precision. + bq_source_uri (str): + Required. BigQuery URI to the input table. + Example: + 'bq://project.dataset.table_name' + feature_source_fields (Dict[str, str]): + Optional. User defined dictionary to map ID of the Feature for importing values + of to the source column for getting the Feature values from. + + Specify the features whose ID and source column are not the same. + If not provided, the source column need to be the same as the Feature ID. + + Example: + feature_ids = ['my_feature_id_1', 'my_feature_id_2', 'my_feature_id_3'] + + feature_source_fields = { + 'my_feature_id_1': 'my_feature_id_1_source_field', + } + + Note: + The source column of 'my_feature_id_1' is 'my_feature_id_1_source_field', + The source column of 'my_feature_id_2' is the ID of the feature, same for 'my_feature_id_3'. + + entity_id_field (str): + Optional. Source column that holds entity IDs. If not provided, entity + IDs are extracted from the column named ``entity_id``. + disable_online_serving (bool): + Optional. If set, data will not be imported for online + serving. This is typically used for backfilling, + where Feature generation timestamps are not in + the timestamp range needed for online serving. + worker_count (int): + Optional. Specifies the number of workers that are used + to write data to the Featurestore. Consider the + online serving capacity that you require to + achieve the desired import throughput without + interfering with online serving. The value must + be positive, and less than or equal to 100. If + not set, defaults to using 1 worker. The low + count ensures minimal impact on online serving + performance. + request_metadata (Sequence[Tuple[str, str]]): + Optional. Strings which should be sent along with the request as metadata. + sync (bool): + Optional. Whether to execute this import synchronously. If False, this method + will be executed in concurrent Future and any downstream object will + be immediately returned and synced when the Future has completed. + ingest_request_timeout (float): + Optional. The timeout for the ingest request in seconds. + + Returns: + EntityType - The entityType resource object with feature values imported. + + """ + + bigquery_source = gca_io.BigQuerySource(input_uri=bq_source_uri) + + import_feature_values_request = ( + self._validate_and_get_import_feature_values_request( + entity_type_name=self.resource_name, + feature_ids=feature_ids, + feature_time=feature_time, + data_source=bigquery_source, + feature_source_fields=feature_source_fields, + entity_id_field=entity_id_field, + disable_online_serving=disable_online_serving, + worker_count=worker_count, + ) + ) + + return self._import_feature_values( + import_feature_values_request=import_feature_values_request, + request_metadata=request_metadata, + ingest_request_timeout=ingest_request_timeout, + ) + + @base.optional_sync(return_input_arg="self") + def ingest_from_gcs( + self, + feature_ids: List[str], + feature_time: Union[str, datetime.datetime], + gcs_source_uris: Union[str, List[str]], + gcs_source_type: str, + feature_source_fields: Optional[Dict[str, str]] = None, + entity_id_field: Optional[str] = None, + disable_online_serving: Optional[bool] = None, + worker_count: Optional[int] = None, + request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + sync: bool = True, + ingest_request_timeout: Optional[float] = None, + ) -> "EntityType": + """Ingest feature values from GCS. + + Args: + feature_ids (List[str]): + Required. IDs of the Feature to import values + of. The Features must exist in the target + EntityType, or the request will fail. + feature_time (Union[str, datetime.datetime]): + Required. The feature_time can be one of: + - The source column that holds the Feature + timestamp for all Feature values in each entity. + - A single Feature timestamp for all entities + being imported. The timestamp must not have + higher than millisecond precision. + gcs_source_uris (Union[str, List[str]]): + Required. Google Cloud Storage URI(-s) to the + input file(s). May contain wildcards. For more + information on wildcards, see + https://cloud.google.com/storage/docs/gsutil/addlhelp/WildcardNames. + Example: + ["gs://my_bucket/my_file_1.csv", "gs://my_bucket/my_file_2.csv"] + or + "gs://my_bucket/my_file.avro" + gcs_source_type (str): + Required. The type of the input file(s) provided by `gcs_source_uris`, + the value of gcs_source_type can only be either `csv`, or `avro`. + feature_source_fields (Dict[str, str]): + Optional. User defined dictionary to map ID of the Feature for importing values + of to the source column for getting the Feature values from. + + Specify the features whose ID and source column are not the same. + If not provided, the source column need to be the same as the Feature ID. + + Example: + feature_ids = ['my_feature_id_1', 'my_feature_id_2', 'my_feature_id_3'] + + feature_source_fields = { + 'my_feature_id_1': 'my_feature_id_1_source_field', + } + + Note: + The source column of 'my_feature_id_1' is 'my_feature_id_1_source_field', + The source column of 'my_feature_id_2' is the ID of the feature, same for 'my_feature_id_3'. + + entity_id_field (str): + Optional. Source column that holds entity IDs. If not provided, entity + IDs are extracted from the column named ``entity_id``. + disable_online_serving (bool): + Optional. If set, data will not be imported for online + serving. This is typically used for backfilling, + where Feature generation timestamps are not in + the timestamp range needed for online serving. + worker_count (int): + Optional. Specifies the number of workers that are used + to write data to the Featurestore. Consider the + online serving capacity that you require to + achieve the desired import throughput without + interfering with online serving. The value must + be positive, and less than or equal to 100. If + not set, defaults to using 1 worker. The low + count ensures minimal impact on online serving + performance. + request_metadata (Sequence[Tuple[str, str]]): + Optional. Strings which should be sent along with the request as metadata. + sync (bool): + Optional. Whether to execute this import synchronously. If False, this method + will be executed in concurrent Future and any downstream object will + be immediately returned and synced when the Future has completed. + ingest_request_timeout (float): + Optional. The timeout for the ingest request in seconds. + + Returns: + EntityType - The entityType resource object with feature values imported. + + Raises: + ValueError if gcs_source_type is not supported. + """ + if gcs_source_type not in featurestore_utils.GCS_SOURCE_TYPE: + raise ValueError( + "Only %s are supported gcs_source_type, not `%s`. " + % ( + "`" + "`, `".join(featurestore_utils.GCS_SOURCE_TYPE) + "`", + gcs_source_type, + ) + ) + + if isinstance(gcs_source_uris, str): + gcs_source_uris = [gcs_source_uris] + gcs_source = gca_io.GcsSource(uris=gcs_source_uris) + + if gcs_source_type == "csv": + data_source = gca_io.CsvSource(gcs_source=gcs_source) + if gcs_source_type == "avro": + data_source = gca_io.AvroSource(gcs_source=gcs_source) + + import_feature_values_request = ( + self._validate_and_get_import_feature_values_request( + entity_type_name=self.resource_name, + feature_ids=feature_ids, + feature_time=feature_time, + data_source=data_source, + feature_source_fields=feature_source_fields, + entity_id_field=entity_id_field, + disable_online_serving=disable_online_serving, + worker_count=worker_count, + ) + ) + + return self._import_feature_values( + import_feature_values_request=import_feature_values_request, + request_metadata=request_metadata, + ingest_request_timeout=ingest_request_timeout, + ) + + def ingest_from_df( + self, + feature_ids: List[str], + feature_time: Union[str, datetime.datetime], + df_source: "pd.DataFrame", # noqa: F821 - skip check for undefined name 'pd' + feature_source_fields: Optional[Dict[str, str]] = None, + entity_id_field: Optional[str] = None, + request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + ingest_request_timeout: Optional[float] = None, + ) -> "EntityType": + """Ingest feature values from DataFrame. + + Note: + Calling this method will automatically create and delete a temporary + bigquery dataset in the same GCP project, which will be used + as the intermediary storage for ingesting feature values + from dataframe to featurestore. + + The call will return upon ingestion completes, where the + feature values will be ingested into the entity_type. + + Args: + feature_ids (List[str]): + Required. IDs of the Feature to import values + of. The Features must exist in the target + EntityType, or the request will fail. + feature_time (Union[str, datetime.datetime]): + Required. The feature_time can be one of: + - The source column that holds the Feature + timestamp for all Feature values in each entity. + + Note: + The dtype of the source column should be `datetime64`. + + - A single Feature timestamp for all entities + being imported. The timestamp must not have + higher than millisecond precision. + + Example: + feature_time = datetime.datetime(year=2022, month=1, day=1, hour=11, minute=59, second=59) + or + feature_time_str = datetime.datetime.now().isoformat(sep=" ", timespec="milliseconds") + feature_time = datetime.datetime.strptime(feature_time_str, "%Y-%m-%d %H:%M:%S.%f") + + df_source (pd.DataFrame): + Required. Pandas DataFrame containing the source data for ingestion. + feature_source_fields (Dict[str, str]): + Optional. User defined dictionary to map ID of the Feature for importing values + of to the source column for getting the Feature values from. + + Specify the features whose ID and source column are not the same. + If not provided, the source column need to be the same as the Feature ID. + + Example: + feature_ids = ['my_feature_id_1', 'my_feature_id_2', 'my_feature_id_3'] + + feature_source_fields = { + 'my_feature_id_1': 'my_feature_id_1_source_field', + } + + Note: + The source column of 'my_feature_id_1' is 'my_feature_id_1_source_field', + The source column of 'my_feature_id_2' is the ID of the feature, same for 'my_feature_id_3'. + + entity_id_field (str): + Optional. Source column that holds entity IDs. If not provided, entity + IDs are extracted from the column named ``entity_id``. + request_metadata (Sequence[Tuple[str, str]]): + Optional. Strings which should be sent along with the request as metadata. + ingest_request_timeout (float): + Optional. The timeout for the ingest request in seconds. + + Returns: + EntityType - The entityType resource object with feature values imported. + + """ + try: + import pyarrow # noqa: F401 - skip check for 'pyarrow' which is required when using 'google.cloud.bigquery' + except ImportError: + raise ImportError( + f"Pyarrow is not installed. Please install pyarrow to use " + f"{self.ingest_from_df.__name__}" + ) + + bigquery_client = bigquery.Client( + project=self.project, credentials=self.credentials + ) + + self.wait() + + feature_source_fields = feature_source_fields or {} + bq_schema = [] + for feature_id in feature_ids: + feature_field_name = feature_source_fields.get(feature_id, feature_id) + feature_value_type = self.get_feature(feature_id).to_dict()["valueType"] + bq_schema_field = self._get_bq_schema_field( + feature_field_name, feature_value_type + ) + bq_schema.append(bq_schema_field) + + entity_type_name_components = self._parse_resource_name(self.resource_name) + featurestore_id, entity_type_id = ( + entity_type_name_components["featurestore"], + entity_type_name_components["entity_type"], + ) + + temp_bq_dataset_name = f"temp_{featurestore_id}_{uuid.uuid4()}".replace( + "-", "_" + ) + + project_id = resource_manager_utils.get_project_id( + project_number=entity_type_name_components["project"], + credentials=self.credentials, + ) + temp_bq_dataset_id = f"{project_id}.{temp_bq_dataset_name}"[:1024] + temp_bq_table_id = f"{temp_bq_dataset_id}.{entity_type_id}" + + temp_bq_dataset = bigquery.Dataset(dataset_ref=temp_bq_dataset_id) + temp_bq_dataset.location = self.location + + temp_bq_dataset = bigquery_client.create_dataset(temp_bq_dataset) + + try: + + parquet_options = bigquery.format_options.ParquetOptions() + parquet_options.enable_list_inference = True + + job_config = bigquery.LoadJobConfig( + schema=bq_schema, + source_format=bigquery.SourceFormat.PARQUET, + parquet_options=parquet_options, + ) + + job = bigquery_client.load_table_from_dataframe( + dataframe=df_source, + destination=temp_bq_table_id, + job_config=job_config, + ) + job.result() + + entity_type_obj = self.ingest_from_bq( + feature_ids=feature_ids, + feature_time=feature_time, + bq_source_uri=f"bq://{temp_bq_table_id}", + feature_source_fields=feature_source_fields, + entity_id_field=entity_id_field, + request_metadata=request_metadata, + ingest_request_timeout=ingest_request_timeout, + ) + + finally: + bigquery_client.delete_dataset( + dataset=temp_bq_dataset.dataset_id, + delete_contents=True, + ) + + return entity_type_obj + + @staticmethod + def _get_bq_schema_field( + name: str, feature_value_type: str + ) -> bigquery.SchemaField: + """Helper method to get BigQuery Schema Field. + + Args: + name (str): + Required. The name of the schema field, which can be either the feature_id, + or the field_name in BigQuery for the feature if different than the feature_id. + feature_value_type (str): + Required. The feature value_type. + + Returns: + bigquery.SchemaField: bigquery.SchemaField + """ + bq_data_type = ( + utils.featurestore_utils.FEATURE_STORE_VALUE_TYPE_TO_BQ_DATA_TYPE_MAP[ + feature_value_type + ] + ) + bq_schema_field = bigquery.SchemaField( + name=name, + field_type=bq_data_type["field_type"], + mode=bq_data_type.get("mode") or "NULLABLE", + ) + return bq_schema_field + + @staticmethod + def _instantiate_featurestore_online_client( + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ) -> utils.FeaturestoreOnlineServingClientWithOverride: + """Helper method to instantiates featurestore online client. + + Args: + location (str): The location of this featurestore. + credentials (google.auth.credentials.Credentials): + Optional custom credentials to use when interacting with + the featurestore online client. + Returns: + utils.FeaturestoreOnlineServingClientWithOverride: + Initialized featurestore online client with optional overrides. + """ + return initializer.global_config.create_client( + client_class=utils.FeaturestoreOnlineServingClientWithOverride, + credentials=credentials, + location_override=location, + ) + + def read( + self, + entity_ids: Union[str, List[str]], + feature_ids: Union[str, List[str]] = "*", + request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + read_request_timeout: Optional[float] = None, + ) -> "pd.DataFrame": # noqa: F821 - skip check for undefined name 'pd' + """Reads feature values for given feature IDs of given entity IDs in this EntityType. + + Args: + entity_ids (Union[str, List[str]]): + Required. ID for a specific entity, or a list of IDs of entities + to read Feature values of. The maximum number of IDs is 100 if a list. + feature_ids (Union[str, List[str]]): + Required. ID for a specific feature, or a list of IDs of Features in the EntityType + for reading feature values. Default to "*", where value of all features will be read. + request_metadata (Sequence[Tuple[str, str]]): + Optional. Strings which should be sent along with the request as metadata. + read_request_timeout (float): + Optional. The timeout for the read request in seconds. + + Returns: + pd.DataFrame: entities' feature values in DataFrame + """ + self.wait() + if isinstance(feature_ids, str): + feature_ids = [feature_ids] + + feature_selector = gca_feature_selector.FeatureSelector( + id_matcher=gca_feature_selector.IdMatcher(ids=feature_ids) + ) + + if isinstance(entity_ids, str): + read_feature_values_request = ( + gca_featurestore_online_service.ReadFeatureValuesRequest( + entity_type=self.resource_name, + entity_id=entity_ids, + feature_selector=feature_selector, + ) + ) + read_feature_values_response = ( + self._featurestore_online_client.read_feature_values( + request=read_feature_values_request, + metadata=request_metadata, + timeout=read_request_timeout, + ) + ) + header = read_feature_values_response.header + entity_views = [read_feature_values_response.entity_view] + elif isinstance(entity_ids, list): + streaming_read_feature_values_request = ( + gca_featurestore_online_service.StreamingReadFeatureValuesRequest( + entity_type=self.resource_name, + entity_ids=entity_ids, + feature_selector=feature_selector, + ) + ) + streaming_read_feature_values_responses = [ + response + for response in self._featurestore_online_client.streaming_read_feature_values( + request=streaming_read_feature_values_request, + metadata=request_metadata, + timeout=read_request_timeout, + ) + ] + header = streaming_read_feature_values_responses[0].header + entity_views = [ + response.entity_view + for response in streaming_read_feature_values_responses[1:] + ] + + feature_ids = [ + feature_descriptor.id for feature_descriptor in header.feature_descriptors + ] + + return self._construct_dataframe( + feature_ids=feature_ids, + entity_views=entity_views, + ) + + @staticmethod + def _construct_dataframe( + feature_ids: List[str], + entity_views: List[ + gca_featurestore_online_service.ReadFeatureValuesResponse.EntityView + ], + ) -> "pd.DataFrame": # noqa: F821 - skip check for undefined name 'pd' + """Constructs a dataframe using the header and entity_views + + Args: + feature_ids (List[str]): + Required. A list of feature ids corresponding to the feature values for each entity in entity_views. + entity_views (List[gca_featurestore_online_service.ReadFeatureValuesResponse.EntityView]): + Required. A list of Entity views with Feature values. + For each Entity view, it may be + the entity in the Featurestore if values for all + Features were requested, or a projection of the + entity in the Featurestore if values for only + some Features were requested. + + Raises: + ImportError: If pandas is not installed when using this method. + + Returns: + pd.DataFrame - entities feature values in DataFrame + ) + """ + + try: + import pandas as pd + except ImportError: + raise ImportError( + f"Pandas is not installed. Please install pandas to use " + f"{EntityType._construct_dataframe.__name__}" + ) + + data = [] + for entity_view in entity_views: + entity_data = {"entity_id": entity_view.entity_id} + for feature_id, feature_data in zip(feature_ids, entity_view.data): + if feature_data._pb.HasField("value"): + value_type = feature_data.value._pb.WhichOneof("value") + feature_value = getattr(feature_data.value, value_type) + if hasattr(feature_value, "values"): + feature_value = feature_value.values + entity_data[feature_id] = feature_value + else: + entity_data[feature_id] = None + data.append(entity_data) + + return pd.DataFrame(data=data, columns=["entity_id"] + feature_ids) diff --git a/google/cloud/aiplatform/featurestore/feature.py b/google/cloud/aiplatform/featurestore/feature.py new file mode 100644 index 0000000000..7a7fc0f29a --- /dev/null +++ b/google/cloud/aiplatform/featurestore/feature.py @@ -0,0 +1,644 @@ +# -*- coding: utf-8 -*- + +# 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 +# +# 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 typing import Dict, List, Optional, Sequence, Tuple + +from google.auth import credentials as auth_credentials +from google.protobuf import field_mask_pb2 + +from google.cloud.aiplatform import base +from google.cloud.aiplatform.compat.types import feature as gca_feature +from google.cloud.aiplatform import featurestore +from google.cloud.aiplatform import initializer +from google.cloud.aiplatform import utils +from google.cloud.aiplatform.utils import featurestore_utils + +_LOGGER = base.Logger(__name__) + + +class Feature(base.VertexAiResourceNounWithFutureManager): + """Managed feature resource for Vertex AI.""" + + client_class = utils.FeaturestoreClientWithOverride + + _resource_noun = "features" + _getter_method = "get_feature" + _list_method = "list_features" + _delete_method = "delete_feature" + _parse_resource_name_method = "parse_feature_path" + _format_resource_name_method = "feature_path" + + @staticmethod + def _resource_id_validator(resource_id: str): + """Validates resource ID. + + Args: + resource_id(str): + The resource id to validate. + """ + featurestore_utils.validate_feature_id(resource_id) + + def __init__( + self, + feature_name: str, + featurestore_id: Optional[str] = None, + entity_type_id: Optional[str] = None, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ): + """Retrieves an existing managed feature given a feature resource name or a feature ID. + + Example Usage: + + my_feature = aiplatform.Feature( + feature_name='projects/123/locations/us-central1/featurestores/my_featurestore_id/\ + entityTypes/my_entity_type_id/features/my_feature_id' + ) + or + my_feature = aiplatform.Feature( + feature_name='my_feature_id', + featurestore_id='my_featurestore_id', + entity_type_id='my_entity_type_id', + ) + + Args: + feature_name (str): + Required. A fully-qualified feature resource name or a feature ID. + Example: "projects/123/locations/us-central1/featurestores/my_featurestore_id/entityTypes/my_entity_type_id/features/my_feature_id" + or "my_feature_id" when project and location are initialized or passed, with featurestore_id and entity_type_id passed. + featurestore_id (str): + Optional. Featurestore ID of an existing featurestore to retrieve feature from, + when feature_name is passed as Feature ID. + entity_type_id (str): + Optional. EntityType ID of an existing entityType to retrieve feature from, + when feature_name is passed as Feature ID. + The EntityType must exist in the Featurestore if provided by the featurestore_id. + project (str): + Optional. Project to retrieve feature from. If not set, project + set in aiplatform.init will be used. + location (str): + Optional. Location to retrieve feature from. If not set, location + set in aiplatform.init will be used. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to retrieve this Feature. Overrides + credentials set in aiplatform.init. + Raises: + ValueError: If only one of featurestore_id or entity_type_id is provided. + """ + + if bool(featurestore_id) != bool(entity_type_id): + raise ValueError( + "featurestore_id and entity_type_id must both be provided or ommitted." + ) + + super().__init__( + project=project, + location=location, + credentials=credentials, + resource_name=feature_name, + ) + self._gca_resource = self._get_gca_resource( + resource_name=feature_name, + parent_resource_name_fields={ + featurestore.Featurestore._resource_noun: featurestore_id, + featurestore.EntityType._resource_noun: entity_type_id, + } + if featurestore_id + else featurestore_id, + ) + + def _get_featurestore_name(self) -> str: + """Gets full qualified resource name of the managed featurestore in which this Feature is.""" + feature_path_components = self._parse_resource_name(self.resource_name) + return featurestore.Featurestore._format_resource_name( + project=feature_path_components["project"], + location=feature_path_components["location"], + featurestore=feature_path_components["featurestore"], + ) + + @property + def featurestore_name(self) -> str: + """Full qualified resource name of the managed featurestore in which this Feature is.""" + self.wait() + return self._get_featurestore_name() + + def get_featurestore(self) -> "featurestore.Featurestore": + """Retrieves the managed featurestore in which this Feature is. + + Returns: + featurestore.Featurestore - The managed featurestore in which this Feature is. + """ + return featurestore.Featurestore(featurestore_name=self.featurestore_name) + + def _get_entity_type_name(self) -> str: + """Gets full qualified resource name of the managed entityType in which this Feature is.""" + feature_path_components = self._parse_resource_name(self.resource_name) + return featurestore.EntityType._format_resource_name( + project=feature_path_components["project"], + location=feature_path_components["location"], + featurestore=feature_path_components["featurestore"], + entity_type=feature_path_components["entity_type"], + ) + + @property + def entity_type_name(self) -> str: + """Full qualified resource name of the managed entityType in which this Feature is.""" + self.wait() + return self._get_entity_type_name() + + def get_entity_type(self) -> "featurestore.EntityType": + """Retrieves the managed entityType in which this Feature is. + + Returns: + featurestore.EntityType - The managed entityType in which this Feature is. + """ + return featurestore.EntityType(entity_type_name=self.entity_type_name) + + def update( + self, + description: Optional[str] = None, + labels: Optional[Dict[str, str]] = None, + request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + update_request_timeout: Optional[float] = None, + ) -> "Feature": + """Updates an existing managed feature resource. + + Example Usage: + + my_feature = aiplatform.Feature( + feature_name='my_feature_id', + featurestore_id='my_featurestore_id', + entity_type_id='my_entity_type_id', + ) + my_feature.update( + description='update my description', + ) + + Args: + description (str): + Optional. Description of the Feature. + labels (Dict[str, str]): + Optional. The labels with user-defined + metadata to organize your Features. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + on and examples of labels. No more than 64 user + labels can be associated with one Feature + (System labels are excluded)." + System reserved label keys are prefixed with + "aiplatform.googleapis.com/" and are immutable. + request_metadata (Sequence[Tuple[str, str]]): + Optional. Strings which should be sent along with the request as metadata. + update_request_timeout (float): + Optional. The timeout for the update request in seconds. + + Returns: + Feature - The updated feature resource object. + """ + self.wait() + update_mask = list() + + if description: + update_mask.append("description") + + if labels: + utils.validate_labels(labels) + update_mask.append("labels") + + update_mask = field_mask_pb2.FieldMask(paths=update_mask) + + gapic_feature = gca_feature.Feature( + name=self.resource_name, + description=description, + labels=labels, + ) + + _LOGGER.log_action_start_against_resource( + "Updating", + "feature", + self, + ) + + update_feature_lro = self.api_client.update_feature( + feature=gapic_feature, + update_mask=update_mask, + metadata=request_metadata, + timeout=update_request_timeout, + ) + + _LOGGER.log_action_started_against_resource_with_lro( + "Update", "feature", self.__class__, update_feature_lro + ) + + update_feature_lro.result() + + _LOGGER.log_action_completed_against_resource("feature", "updated", self) + + return self + + @classmethod + def list( + cls, + entity_type_name: str, + featurestore_id: Optional[str] = None, + filter: Optional[str] = None, + order_by: Optional[str] = None, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ) -> List["Feature"]: + """Lists existing managed feature resources in an entityType, given an entityType resource name or an entity_type ID. + + Example Usage: + + my_features = aiplatform.Feature.list( + entity_type_name='projects/123/locations/us-central1/featurestores/my_featurestore_id/\ + entityTypes/my_entity_type_id' + ) + or + my_features = aiplatform.Feature.list( + entity_type_name='my_entity_type_id', + featurestore_id='my_featurestore_id', + ) + + Args: + entity_type_name (str): + Required. A fully-qualified entityType resource name or an entity_type ID of an existing entityType + to list features in. The EntityType must exist in the Featurestore if provided by the featurestore_id. + Example: "projects/123/locations/us-central1/featurestores/my_featurestore_id/entityTypes/my_entity_type_id" + or "my_entity_type_id" when project and location are initialized or passed, with featurestore_id passed. + featurestore_id (str): + Optional. Featurestore ID of an existing featurestore to list features in, + when entity_type_name is passed as entity_type ID. + filter (str): + Optional. Lists the Features that match the filter expression. The + following filters are supported: + + - ``value_type``: Supports = and != comparisons. + - ``create_time``: Supports =, !=, <, >, >=, and <= + comparisons. Values must be in RFC 3339 format. + - ``update_time``: Supports =, !=, <, >, >=, and <= + comparisons. Values must be in RFC 3339 format. + - ``labels``: Supports key-value equality as well as key + presence. + + Examples: + + - ``value_type = DOUBLE`` --> Features whose type is + DOUBLE. + - ``create_time > \"2020-01-31T15:30:00.000000Z\" OR update_time > \"2020-01-31T15:30:00.000000Z\"`` + --> EntityTypes created or updated after + 2020-01-31T15:30:00.000000Z. + - ``labels.active = yes AND labels.env = prod`` --> + Features having both (active: yes) and (env: prod) + labels. + - ``labels.env: *`` --> Any Feature which has a label with + 'env' as the key. + order_by (str): + Optional. A comma-separated list of fields to order by, sorted in + ascending order. Use "desc" after a field name for + descending. Supported fields: + + - ``feature_id`` + - ``value_type`` + - ``create_time`` + - ``update_time`` + project (str): + Optional. Project to list features in. If not set, project + set in aiplatform.init will be used. + location (str): + Optional. Location to list features in. If not set, location + set in aiplatform.init will be used. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to list features. Overrides + credentials set in aiplatform.init. + + Returns: + List[Feature] - A list of managed feature resource objects + """ + + return cls._list( + filter=filter, + order_by=order_by, + project=project, + location=location, + credentials=credentials, + parent=utils.full_resource_name( + resource_name=entity_type_name, + resource_noun=featurestore.EntityType._resource_noun, + parse_resource_name_method=featurestore.EntityType._parse_resource_name, + format_resource_name_method=featurestore.EntityType._format_resource_name, + parent_resource_name_fields={ + featurestore.Featurestore._resource_noun: featurestore_id + } + if featurestore_id + else featurestore_id, + project=project, + location=location, + resource_id_validator=featurestore.EntityType._resource_id_validator, + ), + ) + + @classmethod + def search( + cls, + query: Optional[str] = None, + page_size: Optional[int] = None, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ) -> List["Feature"]: + """Searches existing managed Feature resources. + + Example Usage: + + my_features = aiplatform.Feature.search() + + Args: + query (str): + Optional. Query string that is a conjunction of field-restricted + queries and/or field-restricted filters. + Field-restricted queries and filters can be combined + using ``AND`` to form a conjunction. + + A field query is in the form FIELD:QUERY. This + implicitly checks if QUERY exists as a substring within + Feature's FIELD. The QUERY and the FIELD are converted + to a sequence of words (i.e. tokens) for comparison. + This is done by: + + - Removing leading/trailing whitespace and tokenizing + the search value. Characters that are not one of + alphanumeric ``[a-zA-Z0-9]``, underscore ``_``, or + asterisk ``*`` are treated as delimiters for tokens. + ``*`` is treated as a wildcard that matches + characters within a token. + - Ignoring case. + - Prepending an asterisk to the first and appending an + asterisk to the last token in QUERY. + + A QUERY must be either a singular token or a phrase. A + phrase is one or multiple words enclosed in double + quotation marks ("). With phrases, the order of the + words is important. Words in the phrase must be matching + in order and consecutively. + + Supported FIELDs for field-restricted queries: + + - ``feature_id`` + - ``description`` + - ``entity_type_id`` + + Examples: + + - ``feature_id: foo`` --> Matches a Feature with ID + containing the substring ``foo`` (eg. ``foo``, + ``foofeature``, ``barfoo``). + - ``feature_id: foo*feature`` --> Matches a Feature + with ID containing the substring ``foo*feature`` (eg. + ``foobarfeature``). + - ``feature_id: foo AND description: bar`` --> Matches + a Feature with ID containing the substring ``foo`` + and description containing the substring ``bar``. + + Besides field queries, the following exact-match filters + are supported. The exact-match filters do not support + wildcards. Unlike field-restricted queries, exact-match + filters are case-sensitive. + + - ``feature_id``: Supports = comparisons. + - ``description``: Supports = comparisons. Multi-token + filters should be enclosed in quotes. + - ``entity_type_id``: Supports = comparisons. + - ``value_type``: Supports = and != comparisons. + - ``labels``: Supports key-value equality as well as + key presence. + - ``featurestore_id``: Supports = comparisons. + + Examples: + + - ``description = "foo bar"`` --> Any Feature with + description exactly equal to ``foo bar`` + - ``value_type = DOUBLE`` --> Features whose type is + DOUBLE. + - ``labels.active = yes AND labels.env = prod`` --> + Features having both (active: yes) and (env: prod) + labels. + - ``labels.env: *`` --> Any Feature which has a label + with ``env`` as the key. + + This corresponds to the ``query`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + page_size (int): + Optional. The maximum number of Features to return. The + service may return fewer than this value. If + unspecified, at most 100 Features will be + returned. The maximum value is 100; any value + greater than 100 will be coerced to 100. + project (str): + Optional. Project to list features in. If not set, project + set in aiplatform.init will be used. + location (str): + Optional. Location to list features in. If not set, location + set in aiplatform.init will be used. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to list features. Overrides + credentials set in aiplatform.init. + + Returns: + List[Feature] - A list of managed feature resource objects + """ + resource = cls._empty_constructor( + project=project, location=location, credentials=credentials + ) + + # Fetch credentials once and re-use for all `_empty_constructor()` calls + creds = resource.credentials + + search_features_request = { + "location": initializer.global_config.common_location_path( + project=project, location=location + ), + "query": query, + } + + if page_size: + search_features_request["page_size"] = page_size + + resource_list = ( + resource.api_client.search_features(request=search_features_request) or [] + ) + + return [ + cls._construct_sdk_resource_from_gapic( + gapic_resource, project=project, location=location, credentials=creds + ) + for gapic_resource in resource_list + ] + + @classmethod + @base.optional_sync() + def create( + cls, + feature_id: str, + value_type: str, + entity_type_name: str, + featurestore_id: Optional[str] = None, + description: Optional[str] = None, + labels: Optional[Dict[str, str]] = None, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + sync: bool = True, + create_request_timeout: Optional[float] = None, + ) -> "Feature": + """Creates a Feature resource in an EntityType. + + Example Usage: + + my_feature = aiplatform.Feature.create( + feature_id='my_feature_id', + value_type='INT64', + entity_type_name='projects/123/locations/us-central1/featurestores/my_featurestore_id/\ + entityTypes/my_entity_type_id' + ) + or + my_feature = aiplatform.Feature.create( + feature_id='my_feature_id', + value_type='INT64', + entity_type_name='my_entity_type_id', + featurestore_id='my_featurestore_id', + ) + + Args: + feature_id (str): + Required. The ID to use for the Feature, which will become + the final component of the Feature's resource name, which is immutable. + + This value may be up to 60 characters, and valid characters + are ``[a-z0-9_]``. The first character cannot be a number. + + The value must be unique within an EntityType. + value_type (str): + Required. Immutable. Type of Feature value. + One of BOOL, BOOL_ARRAY, DOUBLE, DOUBLE_ARRAY, INT64, INT64_ARRAY, STRING, STRING_ARRAY, BYTES. + entity_type_name (str): + Required. A fully-qualified entityType resource name or an entity_type ID of an existing entityType + to create Feature in. The EntityType must exist in the Featurestore if provided by the featurestore_id. + Example: "projects/123/locations/us-central1/featurestores/my_featurestore_id/entityTypes/my_entity_type_id" + or "my_entity_type_id" when project and location are initialized or passed, with featurestore_id passed. + featurestore_id (str): + Optional. Featurestore ID of an existing featurestore to create Feature in + if `entity_type_name` is passed an entity_type ID. + description (str): + Optional. Description of the Feature. + labels (Dict[str, str]): + Optional. The labels with user-defined + metadata to organize your Features. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + on and examples of labels. No more than 64 user + labels can be associated with one Feature + (System labels are excluded)." + System reserved label keys are prefixed with + "aiplatform.googleapis.com/" and are immutable. + project (str): + Optional. Project to create Feature in if `entity_type_name` is passed an entity_type ID. + If not set, project set in aiplatform.init will be used. + location (str): + Optional. Location to create Feature in if `entity_type_name` is passed an entity_type ID. + If not set, location set in aiplatform.init will be used. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to create Features. Overrides + credentials set in aiplatform.init. + request_metadata (Sequence[Tuple[str, str]]): + Optional. Strings which should be sent along with the request as metadata. + sync (bool): + Optional. Whether to execute this creation synchronously. If False, this method + will be executed in concurrent Future and any downstream object will + be immediately returned and synced when the Future has completed. + create_request_timeout (float): + Optional. The timeout for the create request in seconds. + + Returns: + Feature - feature resource object + + """ + entity_type_name = utils.full_resource_name( + resource_name=entity_type_name, + resource_noun=featurestore.EntityType._resource_noun, + parse_resource_name_method=featurestore.EntityType._parse_resource_name, + format_resource_name_method=featurestore.EntityType._format_resource_name, + parent_resource_name_fields={ + featurestore.Featurestore._resource_noun: featurestore_id + } + if featurestore_id + else featurestore_id, + project=project, + location=location, + resource_id_validator=featurestore.EntityType._resource_id_validator, + ) + entity_type_name_components = featurestore.EntityType._parse_resource_name( + entity_type_name + ) + + feature_config = featurestore_utils._FeatureConfig( + feature_id=feature_id, + value_type=value_type, + description=description, + labels=labels, + ) + + create_feature_request = feature_config.get_create_feature_request() + create_feature_request.parent = entity_type_name + + api_client = cls._instantiate_client( + location=entity_type_name_components["location"], + credentials=credentials, + ) + + created_feature_lro = api_client.create_feature( + request=create_feature_request, + metadata=request_metadata, + timeout=create_request_timeout, + ) + + _LOGGER.log_create_with_lro(cls, created_feature_lro) + + created_feature = created_feature_lro.result() + + _LOGGER.log_create_complete(cls, created_feature, "feature") + + feature_obj = cls( + feature_name=created_feature.name, + project=project, + location=location, + credentials=credentials, + ) + + return feature_obj diff --git a/google/cloud/aiplatform/featurestore/featurestore.py b/google/cloud/aiplatform/featurestore/featurestore.py new file mode 100644 index 0000000000..3bb5d44b80 --- /dev/null +++ b/google/cloud/aiplatform/featurestore/featurestore.py @@ -0,0 +1,1281 @@ +# -*- coding: utf-8 -*- + +# 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 +# +# 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 typing import Dict, List, Optional, Sequence, Tuple, Union +import uuid + +from google.auth import credentials as auth_credentials +from google.protobuf import field_mask_pb2 + +from google.cloud.aiplatform import base +from google.cloud.aiplatform.compat.types import ( + feature_selector as gca_feature_selector, + featurestore as gca_featurestore, + featurestore_service as gca_featurestore_service, + io as gca_io, +) +from google.cloud.aiplatform import featurestore +from google.cloud.aiplatform import initializer +from google.cloud.aiplatform import utils +from google.cloud.aiplatform.utils import featurestore_utils, resource_manager_utils + +from google.cloud import bigquery + +_LOGGER = base.Logger(__name__) + + +class Featurestore(base.VertexAiResourceNounWithFutureManager): + """Managed featurestore resource for Vertex AI.""" + + client_class = utils.FeaturestoreClientWithOverride + + _resource_noun = "featurestores" + _getter_method = "get_featurestore" + _list_method = "list_featurestores" + _delete_method = "delete_featurestore" + _parse_resource_name_method = "parse_featurestore_path" + _format_resource_name_method = "featurestore_path" + + @staticmethod + def _resource_id_validator(resource_id: str): + """Validates resource ID. + + Args: + resource_id(str): + The resource id to validate. + """ + featurestore_utils.validate_id(resource_id) + + def __init__( + self, + featurestore_name: str, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ): + """Retrieves an existing managed featurestore given a featurestore resource name or a featurestore ID. + + Example Usage: + + my_featurestore = aiplatform.Featurestore( + featurestore_name='projects/123/locations/us-central1/featurestores/my_featurestore_id' + ) + or + my_featurestore = aiplatform.Featurestore( + featurestore_name='my_featurestore_id' + ) + + Args: + featurestore_name (str): + Required. A fully-qualified featurestore resource name or a featurestore ID. + Example: "projects/123/locations/us-central1/featurestores/my_featurestore_id" + or "my_featurestore_id" when project and location are initialized or passed. + project (str): + Optional. Project to retrieve featurestore from. If not set, project + set in aiplatform.init will be used. + location (str): + Optional. Location to retrieve featurestore from. If not set, location + set in aiplatform.init will be used. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to retrieve this Featurestore. Overrides + credentials set in aiplatform.init. + """ + + super().__init__( + project=project, + location=location, + credentials=credentials, + resource_name=featurestore_name, + ) + self._gca_resource = self._get_gca_resource(resource_name=featurestore_name) + + def get_entity_type(self, entity_type_id: str) -> "featurestore.EntityType": + """Retrieves an existing managed entityType in this Featurestore. + + Args: + entity_type_id (str): + Required. The managed entityType resource ID in this Featurestore. + Returns: + featurestore.EntityType - The managed entityType resource object. + """ + self.wait() + return self._get_entity_type(entity_type_id=entity_type_id) + + def _get_entity_type(self, entity_type_id: str) -> "featurestore.EntityType": + """Retrieves an existing managed entityType in this Featurestore. + + Args: + entity_type_id (str): + Required. The managed entityType resource ID in this Featurestore. + Returns: + featurestore.EntityType - The managed entityType resource object. + """ + featurestore_name_components = self._parse_resource_name(self.resource_name) + return featurestore.EntityType( + entity_type_name=featurestore.EntityType._format_resource_name( + project=featurestore_name_components["project"], + location=featurestore_name_components["location"], + featurestore=featurestore_name_components["featurestore"], + entity_type=entity_type_id, + ) + ) + + def update( + self, + labels: Optional[Dict[str, str]] = None, + request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + update_request_timeout: Optional[float] = None, + ) -> "Featurestore": + """Updates an existing managed featurestore resource. + + Example Usage: + + my_featurestore = aiplatform.Featurestore( + featurestore_name='my_featurestore_id', + ) + my_featurestore.update( + labels={'update my key': 'update my value'}, + ) + + Args: + labels (Dict[str, str]): + Optional. The labels with user-defined + metadata to organize your Featurestores. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + on and examples of labels. No more than 64 user + labels can be associated with one Feature + (System labels are excluded)." + System reserved label keys are prefixed with + "aiplatform.googleapis.com/" and are immutable. + request_metadata (Sequence[Tuple[str, str]]): + Optional. Strings which should be sent along with the request as metadata. + update_request_timeout (float): + Optional. The timeout for the update request in seconds. + + Returns: + Featurestore - The updated featurestore resource object. + """ + + return self._update( + labels=labels, + request_metadata=request_metadata, + update_request_timeout=update_request_timeout, + ) + + # TODO(b/206818784): Add enable_online_store and disable_online_store methods + def update_online_store( + self, + fixed_node_count: int, + request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + update_request_timeout: Optional[float] = None, + ) -> "Featurestore": + """Updates the online store of an existing managed featurestore resource. + + Example Usage: + + my_featurestore = aiplatform.Featurestore( + featurestore_name='my_featurestore_id', + ) + my_featurestore.update_online_store( + fixed_node_count=2, + ) + + Args: + fixed_node_count (int): + Required. Config for online serving resources, can only update the node count to >= 1. + request_metadata (Sequence[Tuple[str, str]]): + Optional. Strings which should be sent along with the request as metadata. + update_request_timeout (float): + Optional. The timeout for the update request in seconds. + + Returns: + Featurestore - The updated featurestore resource object. + """ + return self._update( + fixed_node_count=fixed_node_count, + request_metadata=request_metadata, + update_request_timeout=update_request_timeout, + ) + + def _update( + self, + labels: Optional[Dict[str, str]] = None, + fixed_node_count: Optional[int] = None, + request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + update_request_timeout: Optional[float] = None, + ) -> "Featurestore": + """Updates an existing managed featurestore resource. + + Args: + labels (Dict[str, str]): + Optional. The labels with user-defined + metadata to organize your Featurestores. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + on and examples of labels. No more than 64 user + labels can be associated with one Feature + (System labels are excluded)." + System reserved label keys are prefixed with + "aiplatform.googleapis.com/" and are immutable. + fixed_node_count (int): + Optional. Config for online serving resources, can only update the node count to >= 1. + request_metadata (Sequence[Tuple[str, str]]): + Optional. Strings which should be sent along with the request as metadata. + update_request_timeout (float): + Optional. The timeout for the update request in seconds. + + Returns: + Featurestore - The updated featurestore resource object. + """ + self.wait() + update_mask = list() + + if labels: + utils.validate_labels(labels) + update_mask.append("labels") + + if fixed_node_count is not None: + update_mask.append("online_serving_config.fixed_node_count") + + update_mask = field_mask_pb2.FieldMask(paths=update_mask) + + gapic_featurestore = gca_featurestore.Featurestore( + name=self.resource_name, + labels=labels, + online_serving_config=gca_featurestore.Featurestore.OnlineServingConfig( + fixed_node_count=fixed_node_count + ), + ) + + _LOGGER.log_action_start_against_resource( + "Updating", + "featurestore", + self, + ) + + update_featurestore_lro = self.api_client.update_featurestore( + featurestore=gapic_featurestore, + update_mask=update_mask, + metadata=request_metadata, + timeout=update_request_timeout, + ) + + _LOGGER.log_action_started_against_resource_with_lro( + "Update", "featurestore", self.__class__, update_featurestore_lro + ) + + update_featurestore_lro.result() + + _LOGGER.log_action_completed_against_resource("featurestore", "updated", self) + + return self + + def list_entity_types( + self, + filter: Optional[str] = None, + order_by: Optional[str] = None, + ) -> List["featurestore.EntityType"]: + """Lists existing managed entityType resources in this Featurestore. + + Example Usage: + + my_featurestore = aiplatform.Featurestore( + featurestore_name='my_featurestore_id', + ) + my_featurestore.list_entity_types() + + Args: + filter (str): + Optional. Lists the EntityTypes that match the filter expression. The + following filters are supported: + + - ``create_time``: Supports ``=``, ``!=``, ``<``, ``>``, + ``>=``, and ``<=`` comparisons. Values must be in RFC + 3339 format. + - ``update_time``: Supports ``=``, ``!=``, ``<``, ``>``, + ``>=``, and ``<=`` comparisons. Values must be in RFC + 3339 format. + - ``labels``: Supports key-value equality as well as key + presence. + + Examples: + + - ``create_time > \"2020-01-31T15:30:00.000000Z\" OR update_time > \"2020-01-31T15:30:00.000000Z\"`` + --> EntityTypes created or updated after + 2020-01-31T15:30:00.000000Z. + - ``labels.active = yes AND labels.env = prod`` --> + EntityTypes having both (active: yes) and (env: prod) + labels. + - ``labels.env: *`` --> Any EntityType which has a label + with 'env' as the key. + order_by (str): + Optional. A comma-separated list of fields to order by, sorted in + ascending order. Use "desc" after a field name for + descending. + + Supported fields: + + - ``entity_type_id`` + - ``create_time`` + - ``update_time`` + + Returns: + List[featurestore.EntityType] - A list of managed entityType resource objects. + """ + self.wait() + return featurestore.EntityType.list( + featurestore_name=self.resource_name, + filter=filter, + order_by=order_by, + ) + + @base.optional_sync() + def delete_entity_types( + self, + entity_type_ids: List[str], + sync: bool = True, + force: bool = False, + ) -> None: + """Deletes entity_type resources in this Featurestore given their entity_type IDs. + WARNING: This deletion is permanent. + + Args: + entity_type_ids (List[str]): + Required. The list of entity_type IDs to be deleted. + sync (bool): + Optional. Whether to execute this deletion synchronously. If False, this method + will be executed in concurrent Future and any downstream object will + be immediately returned and synced when the Future has completed. + force (bool): + Optional. If force is set to True, all features in each entityType + will be deleted prior to entityType deletion. Default is False. + """ + entity_types = [] + for entity_type_id in entity_type_ids: + entity_type = self._get_entity_type(entity_type_id=entity_type_id) + entity_type.delete(force=force, sync=False) + entity_types.append(entity_type) + + for entity_type in entity_types: + entity_type.wait() + + @base.optional_sync() + def delete(self, sync: bool = True, force: bool = False) -> None: + """Deletes this Featurestore resource. If force is set to True, + all entityTypes in this Featurestore will be deleted prior to featurestore deletion, + and all features in each entityType will be deleted prior to each entityType deletion. + + WARNING: This deletion is permanent. + + Args: + force (bool): + If set to true, any EntityTypes and + Features for this Featurestore will also + be deleted. (Otherwise, the request will + only work if the Featurestore has no + EntityTypes.) + sync (bool): + Whether to execute this deletion synchronously. If False, this method + will be executed in concurrent Future and any downstream object will + be immediately returned and synced when the Future has completed. + """ + _LOGGER.log_action_start_against_resource("Deleting", "", self) + lro = getattr(self.api_client, self._delete_method)( + name=self.resource_name, force=force + ) + _LOGGER.log_action_started_against_resource_with_lro( + "Delete", "", self.__class__, lro + ) + lro.result() + _LOGGER.log_action_completed_against_resource("deleted.", "", self) + + @classmethod + @base.optional_sync() + def create( + cls, + featurestore_id: str, + online_store_fixed_node_count: Optional[int] = None, + labels: Optional[Dict[str, str]] = None, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + encryption_spec_key_name: Optional[str] = None, + sync: bool = True, + create_request_timeout: Optional[float] = None, + ) -> "Featurestore": + """Creates a Featurestore resource. + + Example Usage: + + my_featurestore = aiplatform.Featurestore.create( + featurestore_id='my_featurestore_id', + ) + + Args: + featurestore_id (str): + Required. The ID to use for this Featurestore, which will + become the final component of the Featurestore's resource + name. + + This value may be up to 60 characters, and valid characters + are ``[a-z0-9_]``. The first character cannot be a number. + + The value must be unique within the project and location. + online_store_fixed_node_count (int): + Optional. Config for online serving resources. + When not specified, no fixed node count for online serving. The + number of nodes will not scale automatically but + can be scaled manually by providing different + values when updating. + labels (Dict[str, str]): + Optional. The labels with user-defined + metadata to organize your Featurestore. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + on and examples of labels. No more than 64 user + labels can be associated with one + Featurestore(System labels are excluded)." + System reserved label keys are prefixed with + "aiplatform.googleapis.com/" and are immutable. + project (str): + Optional. Project to create EntityType in. If not set, project + set in aiplatform.init will be used. + location (str): + Optional. Location to create EntityType in. If not set, location + set in aiplatform.init will be used. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to create EntityTypes. Overrides + credentials set in aiplatform.init. + request_metadata (Sequence[Tuple[str, str]]): + Optional. Strings which should be sent along with the request as metadata. + request_metadata (Sequence[Tuple[str, str]]): + Optional. Strings which should be sent along with the request as metadata. + encryption_spec (str): + Optional. Customer-managed encryption key + spec for data storage. If set, both of the + online and offline data storage will be secured + by this key. + sync (bool): + Optional. Whether to execute this creation synchronously. If False, this method + will be executed in concurrent Future and any downstream object will + be immediately returned and synced when the Future has completed. + create_request_timeout (float): + Optional. The timeout for the create request in seconds. + + Returns: + Featurestore - Featurestore resource object + + """ + gapic_featurestore = gca_featurestore.Featurestore( + online_serving_config=gca_featurestore.Featurestore.OnlineServingConfig( + fixed_node_count=online_store_fixed_node_count + ) + ) + + if labels: + utils.validate_labels(labels) + gapic_featurestore.labels = labels + + if encryption_spec_key_name: + gapic_featurestore.encryption_spec = ( + initializer.global_config.get_encryption_spec( + encryption_spec_key_name=encryption_spec_key_name + ) + ) + + api_client = cls._instantiate_client(location=location, credentials=credentials) + + created_featurestore_lro = api_client.create_featurestore( + parent=initializer.global_config.common_location_path( + project=project, location=location + ), + featurestore=gapic_featurestore, + featurestore_id=featurestore_id, + metadata=request_metadata, + timeout=create_request_timeout, + ) + + _LOGGER.log_create_with_lro(cls, created_featurestore_lro) + + created_featurestore = created_featurestore_lro.result() + + _LOGGER.log_create_complete(cls, created_featurestore, "featurestore") + + featurestore_obj = cls( + featurestore_name=created_featurestore.name, + project=project, + location=location, + credentials=credentials, + ) + + return featurestore_obj + + def create_entity_type( + self, + entity_type_id: str, + description: Optional[str] = None, + labels: Optional[Dict[str, str]] = None, + request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + sync: bool = True, + create_request_timeout: Optional[float] = None, + ) -> "featurestore.EntityType": + """Creates an EntityType resource in this Featurestore. + + Example Usage: + + my_featurestore = aiplatform.Featurestore.create( + featurestore_id='my_featurestore_id' + ) + my_entity_type = my_featurestore.create_entity_type( + entity_type_id='my_entity_type_id', + ) + + Args: + entity_type_id (str): + Required. The ID to use for the EntityType, which will + become the final component of the EntityType's resource + name. + + This value may be up to 60 characters, and valid characters + are ``[a-z0-9_]``. The first character cannot be a number. + + The value must be unique within a featurestore. + description (str): + Optional. Description of the EntityType. + labels (Dict[str, str]): + Optional. The labels with user-defined + metadata to organize your EntityTypes. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + on and examples of labels. No more than 64 user + labels can be associated with one EntityType + (System labels are excluded)." + System reserved label keys are prefixed with + "aiplatform.googleapis.com/" and are immutable. + request_metadata (Sequence[Tuple[str, str]]): + Optional. Strings which should be sent along with the request as metadata. + create_request_timeout (float): + Optional. The timeout for the create request in seconds. + sync (bool): + Optional. Whether to execute this creation synchronously. If False, this method + will be executed in concurrent Future and any downstream object will + be immediately returned and synced when the Future has completed. + + Returns: + featurestore.EntityType - EntityType resource object + + """ + self.wait() + return featurestore.EntityType.create( + entity_type_id=entity_type_id, + featurestore_name=self.resource_name, + description=description, + labels=labels, + request_metadata=request_metadata, + sync=sync, + create_request_timeout=create_request_timeout, + ) + + def _batch_read_feature_values( + self, + batch_read_feature_values_request: gca_featurestore_service.BatchReadFeatureValuesRequest, + request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + serve_request_timeout: Optional[float] = None, + ) -> "Featurestore": + """Batch read Feature values from the Featurestore to a destination storage. + + Args: + batch_read_feature_values_request (gca_featurestore_service.BatchReadFeatureValuesRequest): + Required. Request of batch read feature values. + request_metadata (Sequence[Tuple[str, str]]): + Optional. Strings which should be sent along with the request as metadata. + serve_request_timeout (float): + Optional. The timeout for the serve request in seconds. + + Returns: + Featurestore: The featurestore resource object batch read feature values from. + """ + + _LOGGER.log_action_start_against_resource( + "Serving", + "feature values", + self, + ) + + batch_read_lro = self.api_client.batch_read_feature_values( + request=batch_read_feature_values_request, + metadata=request_metadata, + timeout=serve_request_timeout, + ) + + _LOGGER.log_action_started_against_resource_with_lro( + "Serve", "feature values", self.__class__, batch_read_lro + ) + + batch_read_lro.result() + + _LOGGER.log_action_completed_against_resource("feature values", "served", self) + + return self + + @staticmethod + def _validate_and_get_read_instances( + read_instances_uri: str, + ) -> Union[gca_io.BigQuerySource, gca_io.CsvSource]: + """Gets read_instances + + Args: + read_instances_uri (str): + Required. Read_instances_uri can be either BigQuery URI to an input table, + or Google Cloud Storage URI to a csv file. + + Returns: + Union[gca_io.BigQuerySource, gca_io.CsvSource]: + BigQuery source or Csv source for read instances. The Csv source contains exactly 1 URI. + + Raises: + ValueError if read_instances_uri does not start with 'bq://' or 'gs://'. + """ + if not ( + read_instances_uri.startswith("bq://") + or read_instances_uri.startswith("gs://") + ): + raise ValueError( + "The read_instances_uri should be a single uri starts with either 'bq://' or 'gs://'." + ) + + if read_instances_uri.startswith("bq://"): + return gca_io.BigQuerySource(input_uri=read_instances_uri) + if read_instances_uri.startswith("gs://"): + return gca_io.CsvSource( + gcs_source=gca_io.GcsSource(uris=[read_instances_uri]) + ) + + def _validate_and_get_batch_read_feature_values_request( + self, + featurestore_name: str, + serving_feature_ids: Dict[str, List[str]], + destination: Union[ + gca_io.BigQueryDestination, + gca_io.CsvDestination, + gca_io.TFRecordDestination, + ], + read_instances: Union[gca_io.BigQuerySource, gca_io.CsvSource], + pass_through_fields: Optional[List[str]] = None, + feature_destination_fields: Optional[Dict[str, str]] = None, + ) -> gca_featurestore_service.BatchReadFeatureValuesRequest: + """Validates and gets batch_read_feature_values_request + + Args: + featurestore_name (str): + Required. A fully-qualified featurestore resource name. + serving_feature_ids (Dict[str, List[str]]): + Required. A user defined dictionary to define the entity_types and their features for batch serve/read. + The keys of the dictionary are the serving entity_type ids and + the values are lists of serving feature ids in each entity_type. + + Example: + serving_feature_ids = { + 'my_entity_type_id_1': ['feature_id_1_1', 'feature_id_1_2'], + 'my_entity_type_id_2': ['feature_id_2_1', 'feature_id_2_2'], + } + + destination (Union[gca_io.BigQueryDestination, gca_io.CsvDestination, gca_io.TFRecordDestination]): + Required. BigQuery destination, Csv destination or TFRecord destination. + read_instances (Union[gca_io.BigQuerySource, gca_io.CsvSource]): + Required. BigQuery source or Csv source for read instances. + The Csv source must contain exactly 1 URI. + pass_through_fields (List[str]): + Optional. When not empty, the specified fields in the + read_instances source will be joined as-is in the output, + in addition to those fields from the Featurestore Entity. + + For BigQuery source, the type of the pass-through values + will be automatically inferred. For CSV source, the + pass-through values will be passed as opaque bytes. + feature_destination_fields (Dict[str, str]): + Optional. A user defined dictionary to map a feature's fully qualified resource name to + its destination field name. If the destination field name is not defined, + the feature ID will be used as its destination field name. + + Example: + feature_destination_fields = { + 'projects/123/locations/us-central1/featurestores/fs_id/entityTypes/et_id1/features/f_id11': 'foo', + 'projects/123/locations/us-central1/featurestores/fs_id/entityTypes/et_id2/features/f_id22': 'bar', + } + + Returns: + gca_featurestore_service.BatchReadFeatureValuesRequest: batch read feature values request + """ + featurestore_name_components = self._parse_resource_name(featurestore_name) + + feature_destination_fields = feature_destination_fields or {} + + entity_type_specs = [] + for entity_type_id, feature_ids in serving_feature_ids.items(): + destination_feature_settings = [] + for feature_id in feature_ids: + feature_resource_name = featurestore.Feature._format_resource_name( + project=featurestore_name_components["project"], + location=featurestore_name_components["location"], + featurestore=featurestore_name_components["featurestore"], + entity_type=entity_type_id, + feature=feature_id, + ) + + feature_destination_field = feature_destination_fields.get( + feature_resource_name + ) + if feature_destination_field: + destination_feature_setting_proto = ( + gca_featurestore_service.DestinationFeatureSetting( + feature_id=feature_id, + destination_field=feature_destination_field, + ) + ) + destination_feature_settings.append( + destination_feature_setting_proto + ) + + entity_type_spec = ( + gca_featurestore_service.BatchReadFeatureValuesRequest.EntityTypeSpec( + entity_type_id=entity_type_id, + feature_selector=gca_feature_selector.FeatureSelector( + id_matcher=gca_feature_selector.IdMatcher(ids=feature_ids) + ), + settings=destination_feature_settings or None, + ) + ) + entity_type_specs.append(entity_type_spec) + + batch_read_feature_values_request = ( + gca_featurestore_service.BatchReadFeatureValuesRequest( + featurestore=featurestore_name, + entity_type_specs=entity_type_specs, + ) + ) + + if isinstance(destination, gca_io.BigQueryDestination): + batch_read_feature_values_request.destination = ( + gca_featurestore_service.FeatureValueDestination( + bigquery_destination=destination + ) + ) + elif isinstance(destination, gca_io.CsvDestination): + batch_read_feature_values_request.destination = ( + gca_featurestore_service.FeatureValueDestination( + csv_destination=destination + ) + ) + elif isinstance(destination, gca_io.TFRecordDestination): + batch_read_feature_values_request.destination = ( + gca_featurestore_service.FeatureValueDestination( + tfrecord_destination=destination + ) + ) + + if isinstance(read_instances, gca_io.BigQuerySource): + batch_read_feature_values_request.bigquery_read_instances = read_instances + elif isinstance(read_instances, gca_io.CsvSource): + batch_read_feature_values_request.csv_read_instances = read_instances + + if pass_through_fields is not None: + batch_read_feature_values_request.pass_through_fields = [ + gca_featurestore_service.BatchReadFeatureValuesRequest.PassThroughField( + field_name=pass_through_field + ) + for pass_through_field in pass_through_fields + ] + + return batch_read_feature_values_request + + @base.optional_sync(return_input_arg="self") + def batch_serve_to_bq( + self, + bq_destination_output_uri: str, + serving_feature_ids: Dict[str, List[str]], + read_instances_uri: str, + pass_through_fields: Optional[List[str]] = None, + feature_destination_fields: Optional[Dict[str, str]] = None, + request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + serve_request_timeout: Optional[float] = None, + sync: bool = True, + ) -> "Featurestore": + """Batch serves feature values to BigQuery destination + + Args: + bq_destination_output_uri (str): + Required. BigQuery URI to the detination table. + + Example: + 'bq://project.dataset.table_name' + + It requires an existing BigQuery destination Dataset, under the same project as the Featurestore. + + serving_feature_ids (Dict[str, List[str]]): + Required. A user defined dictionary to define the entity_types and their features for batch serve/read. + The keys of the dictionary are the serving entity_type ids and + the values are lists of serving feature ids in each entity_type. + + Example: + serving_feature_ids = { + 'my_entity_type_id_1': ['feature_id_1_1', 'feature_id_1_2'], + 'my_entity_type_id_2': ['feature_id_2_1', 'feature_id_2_2'], + } + + read_instances_uri (str): + Required. Read_instances_uri can be either BigQuery URI to an input table, + or Google Cloud Storage URI to a csv file. + + Example: + 'bq://project.dataset.table_name' + or + "gs://my_bucket/my_file.csv" + + Each read instance should consist of exactly one read timestamp + and one or more entity IDs identifying entities of the + corresponding EntityTypes whose Features are requested. + + Each output instance contains Feature values of requested + entities concatenated together as of the read time. + + An example read instance may be + ``foo_entity_id, bar_entity_id, 2020-01-01T10:00:00.123Z``. + + An example output instance may be + ``foo_entity_id, bar_entity_id, 2020-01-01T10:00:00.123Z, foo_entity_feature1_value, bar_entity_feature2_value``. + + Timestamp in each read instance must be millisecond-aligned. + + The columns can be in any order. + + Values in the timestamp column must use the RFC 3339 format, + e.g. ``2012-07-30T10:43:17.123Z``. + + pass_through_fields (List[str]): + Optional. When not empty, the specified fields in the + read_instances source will be joined as-is in the output, + in addition to those fields from the Featurestore Entity. + + For BigQuery source, the type of the pass-through values + will be automatically inferred. For CSV source, the + pass-through values will be passed as opaque bytes. + + feature_destination_fields (Dict[str, str]): + Optional. A user defined dictionary to map a feature's fully qualified resource name to + its destination field name. If the destination field name is not defined, + the feature ID will be used as its destination field name. + + Example: + feature_destination_fields = { + 'projects/123/locations/us-central1/featurestores/fs_id/entityTypes/et_id1/features/f_id11': 'foo', + 'projects/123/locations/us-central1/featurestores/fs_id/entityTypes/et_id2/features/f_id22': 'bar', + } + serve_request_timeout (float): + Optional. The timeout for the serve request in seconds. + Returns: + Featurestore: The featurestore resource object batch read feature values from. + + Raises: + NotFound: if the BigQuery destination Dataset does not exist. + FailedPrecondition: if the BigQuery destination Dataset/Table is in a different project. + """ + read_instances = self._validate_and_get_read_instances(read_instances_uri) + + batch_read_feature_values_request = ( + self._validate_and_get_batch_read_feature_values_request( + featurestore_name=self.resource_name, + serving_feature_ids=serving_feature_ids, + destination=gca_io.BigQueryDestination( + output_uri=bq_destination_output_uri + ), + feature_destination_fields=feature_destination_fields, + read_instances=read_instances, + pass_through_fields=pass_through_fields, + ) + ) + + return self._batch_read_feature_values( + batch_read_feature_values_request=batch_read_feature_values_request, + request_metadata=request_metadata, + serve_request_timeout=serve_request_timeout, + ) + + @base.optional_sync(return_input_arg="self") + def batch_serve_to_gcs( + self, + gcs_destination_output_uri_prefix: str, + gcs_destination_type: str, + serving_feature_ids: Dict[str, List[str]], + read_instances_uri: str, + pass_through_fields: Optional[List[str]] = None, + feature_destination_fields: Optional[Dict[str, str]] = None, + request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + sync: bool = True, + serve_request_timeout: Optional[float] = None, + ) -> "Featurestore": + """Batch serves feature values to GCS destination + + Args: + gcs_destination_output_uri_prefix (str): + Required. Google Cloud Storage URI to output + directory. If the uri doesn't end with '/', a + '/' will be automatically appended. The + directory is created if it doesn't exist. + + Example: + "gs://bucket/path/to/prefix" + + gcs_destination_type (str): + Required. The type of the destination files(s), + the value of gcs_destination_type can only be either `csv`, or `tfrecord`. + + For CSV format. Array Feature value types are not allowed in CSV format. + + For TFRecord format. + + Below are the mapping from Feature value type in + Featurestore to Feature value type in TFRecord: + + :: + + Value type in Featurestore | Value type in TFRecord + DOUBLE, DOUBLE_ARRAY | FLOAT_LIST + INT64, INT64_ARRAY | INT64_LIST + STRING, STRING_ARRAY, BYTES | BYTES_LIST + true -> byte_string("true"), false -> byte_string("false") + BOOL, BOOL_ARRAY (true, false) | BYTES_LIST + + serving_feature_ids (Dict[str, List[str]]): + Required. A user defined dictionary to define the entity_types and their features for batch serve/read. + The keys of the dictionary are the serving entity_type ids and + the values are lists of serving feature ids in each entity_type. + + Example: + serving_feature_ids = { + 'my_entity_type_id_1': ['feature_id_1_1', 'feature_id_1_2'], + 'my_entity_type_id_2': ['feature_id_2_1', 'feature_id_2_2'], + } + + read_instances_uri (str): + Required. Read_instances_uri can be either BigQuery URI to an input table, + or Google Cloud Storage URI to a csv file. + + Example: + 'bq://project.dataset.table_name' + or + "gs://my_bucket/my_file.csv" + + Each read instance should consist of exactly one read timestamp + and one or more entity IDs identifying entities of the + corresponding EntityTypes whose Features are requested. + + Each output instance contains Feature values of requested + entities concatenated together as of the read time. + + An example read instance may be + ``foo_entity_id, bar_entity_id, 2020-01-01T10:00:00.123Z``. + + An example output instance may be + ``foo_entity_id, bar_entity_id, 2020-01-01T10:00:00.123Z, foo_entity_feature1_value, bar_entity_feature2_value``. + + Timestamp in each read instance must be millisecond-aligned. + + The columns can be in any order. + + Values in the timestamp column must use the RFC 3339 format, + e.g. ``2012-07-30T10:43:17.123Z``. + + pass_through_fields (List[str]): + Optional. When not empty, the specified fields in the + read_instances source will be joined as-is in the output, + in addition to those fields from the Featurestore Entity. + + For BigQuery source, the type of the pass-through values + will be automatically inferred. For CSV source, the + pass-through values will be passed as opaque bytes. + + feature_destination_fields (Dict[str, str]): + Optional. A user defined dictionary to map a feature's fully qualified resource name to + its destination field name. If the destination field name is not defined, + the feature ID will be used as its destination field name. + + Example: + feature_destination_fields = { + 'projects/123/locations/us-central1/featurestores/fs_id/entityTypes/et_id1/features/f_id11': 'foo', + 'projects/123/locations/us-central1/featurestores/fs_id/entityTypes/et_id2/features/f_id22': 'bar', + } + serve_request_timeout (float): + Optional. The timeout for the serve request in seconds. + + Returns: + Featurestore: The featurestore resource object batch read feature values from. + + Raises: + ValueError if gcs_destination_type is not supported. + + """ + destination = None + if gcs_destination_type not in featurestore_utils.GCS_DESTINATION_TYPE: + raise ValueError( + "Only %s are supported gcs_destination_type, not `%s`. " + % ( + "`" + "`, `".join(featurestore_utils.GCS_DESTINATION_TYPE) + "`", + gcs_destination_type, + ) + ) + + gcs_destination = gca_io.GcsDestination( + output_uri_prefix=gcs_destination_output_uri_prefix + ) + if gcs_destination_type == "csv": + destination = gca_io.CsvDestination(gcs_destination=gcs_destination) + if gcs_destination_type == "tfrecord": + destination = gca_io.TFRecordDestination(gcs_destination=gcs_destination) + + read_instances = self._validate_and_get_read_instances(read_instances_uri) + + batch_read_feature_values_request = ( + self._validate_and_get_batch_read_feature_values_request( + featurestore_name=self.resource_name, + serving_feature_ids=serving_feature_ids, + destination=destination, + feature_destination_fields=feature_destination_fields, + read_instances=read_instances, + pass_through_fields=pass_through_fields, + ) + ) + + return self._batch_read_feature_values( + batch_read_feature_values_request=batch_read_feature_values_request, + request_metadata=request_metadata, + serve_request_timeout=serve_request_timeout, + ) + + def batch_serve_to_df( + self, + serving_feature_ids: Dict[str, List[str]], + read_instances_df: "pd.DataFrame", # noqa: F821 - skip check for undefined name 'pd' + pass_through_fields: Optional[List[str]] = None, + feature_destination_fields: Optional[Dict[str, str]] = None, + request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + serve_request_timeout: Optional[float] = None, + ) -> "pd.DataFrame": # noqa: F821 - skip check for undefined name 'pd' + """Batch serves feature values to pandas DataFrame + + Note: + Calling this method will automatically create and delete a temporary + bigquery dataset in the same GCP project, which will be used + as the intermediary storage for batch serve feature values + from featurestore to dataframe. + + Args: + serving_feature_ids (Dict[str, List[str]]): + Required. A user defined dictionary to define the entity_types and their features for batch serve/read. + The keys of the dictionary are the serving entity_type ids and + the values are lists of serving feature ids in each entity_type. + + Example: + serving_feature_ids = { + 'my_entity_type_id_1': ['feature_id_1_1', 'feature_id_1_2'], + 'my_entity_type_id_2': ['feature_id_2_1', 'feature_id_2_2'], + } + + read_instances_df (pd.DataFrame): + Required. Read_instances_df is a pandas DataFrame containing the read instances. + + Each read instance should consist of exactly one read timestamp + and one or more entity IDs identifying entities of the + corresponding EntityTypes whose Features are requested. + + Each output instance contains Feature values of requested + entities concatenated together as of the read time. + + An example read_instances_df may be + pd.DataFrame( + data=[ + { + "my_entity_type_id_1": "my_entity_type_id_1_entity_1", + "my_entity_type_id_2": "my_entity_type_id_2_entity_1", + "timestamp": "2020-01-01T10:00:00.123Z" + ], + ) + + An example batch_serve_output_df may be + pd.DataFrame( + data=[ + { + "my_entity_type_id_1": "my_entity_type_id_1_entity_1", + "my_entity_type_id_2": "my_entity_type_id_2_entity_1", + "foo": "feature_id_1_1_feature_value", + "feature_id_1_2": "feature_id_1_2_feature_value", + "feature_id_2_1": "feature_id_2_1_feature_value", + "bar": "feature_id_2_2_feature_value", + "timestamp": "2020-01-01T10:00:00.123Z" + ], + ) + + Timestamp in each read instance must be millisecond-aligned. + + The columns can be in any order. + + Values in the timestamp column must use the RFC 3339 format, + e.g. ``2012-07-30T10:43:17.123Z``. + + pass_through_fields (List[str]): + Optional. When not empty, the specified fields in the + read_instances source will be joined as-is in the output, + in addition to those fields from the Featurestore Entity. + + For BigQuery source, the type of the pass-through values + will be automatically inferred. For CSV source, the + pass-through values will be passed as opaque bytes. + + feature_destination_fields (Dict[str, str]): + Optional. A user defined dictionary to map a feature's fully qualified resource name to + its destination field name. If the destination field name is not defined, + the feature ID will be used as its destination field name. + + Example: + feature_destination_fields = { + 'projects/123/locations/us-central1/featurestores/fs_id/entityTypes/et_id1/features/f_id11': 'foo', + 'projects/123/locations/us-central1/featurestores/fs_id/entityTypes/et_id2/features/f_id22': 'bar', + } + serve_request_timeout (float): + Optional. The timeout for the serve request in seconds. + + Returns: + pd.DataFrame: The pandas DataFrame containing feature values from batch serving. + + """ + try: + from google.cloud import bigquery_storage + except ImportError: + raise ImportError( + f"Google-Cloud-Bigquery-Storage is not installed. Please install google-cloud-bigquery-storage to use " + f"{self.batch_serve_to_df.__name__}" + ) + + try: + import pyarrow # noqa: F401 - skip check for 'pyarrow' which is required when using 'google.cloud.bigquery' + except ImportError: + raise ImportError( + f"Pyarrow is not installed. Please install pyarrow to use " + f"{self.batch_serve_to_df.__name__}" + ) + + try: + import pandas as pd + except ImportError: + raise ImportError( + f"Pandas is not installed. Please install pandas to use " + f"{self.batch_serve_to_df.__name__}" + ) + + bigquery_client = bigquery.Client( + project=self.project, credentials=self.credentials + ) + + self.wait() + featurestore_name_components = self._parse_resource_name(self.resource_name) + featurestore_id = featurestore_name_components["featurestore"] + + temp_bq_dataset_name = f"temp_{featurestore_id}_{uuid.uuid4()}".replace( + "-", "_" + ) + + project_id = resource_manager_utils.get_project_id( + project_number=featurestore_name_components["project"], + credentials=self.credentials, + ) + temp_bq_dataset_id = f"{project_id}.{temp_bq_dataset_name}"[:1024] + temp_bq_dataset = bigquery.Dataset(dataset_ref=temp_bq_dataset_id) + temp_bq_dataset.location = self.location + temp_bq_dataset = bigquery_client.create_dataset(temp_bq_dataset) + + temp_bq_batch_serve_table_name = "batch_serve" + temp_bq_read_instances_table_name = "read_instances" + temp_bq_batch_serve_table_id = ( + f"{temp_bq_dataset_id}.{temp_bq_batch_serve_table_name}" + ) + temp_bq_read_instances_table_id = ( + f"{temp_bq_dataset_id}.{temp_bq_read_instances_table_name}" + ) + + try: + + job = bigquery_client.load_table_from_dataframe( + dataframe=read_instances_df, destination=temp_bq_read_instances_table_id + ) + job.result() + + self.batch_serve_to_bq( + bq_destination_output_uri=f"bq://{temp_bq_batch_serve_table_id}", + serving_feature_ids=serving_feature_ids, + read_instances_uri=f"bq://{temp_bq_read_instances_table_id}", + pass_through_fields=pass_through_fields, + feature_destination_fields=feature_destination_fields, + request_metadata=request_metadata, + serve_request_timeout=serve_request_timeout, + ) + + bigquery_storage_read_client = bigquery_storage.BigQueryReadClient( + credentials=self.credentials + ) + read_session_proto = bigquery_storage_read_client.create_read_session( + parent=f"projects/{self.project}", + read_session=bigquery_storage.types.ReadSession( + table="projects/{project}/datasets/{dataset}/tables/{table}".format( + project=self.project, + dataset=temp_bq_dataset_name, + table=temp_bq_batch_serve_table_name, + ), + data_format=bigquery_storage.types.DataFormat.ARROW, + ), + ) + + frames = [] + for stream in read_session_proto.streams: + reader = bigquery_storage_read_client.read_rows(stream.name) + for message in reader.rows().pages: + frames.append(message.to_dataframe()) + + finally: + bigquery_client.delete_dataset( + dataset=temp_bq_dataset.dataset_id, + delete_contents=True, + ) + + return pd.concat(frames, ignore_index=True) if frames else pd.DataFrame(frames) diff --git a/google/cloud/aiplatform/gapic/schema/__init__.py b/google/cloud/aiplatform/gapic/schema/__init__.py index e726749c77..5d31a70f1f 100644 --- a/google/cloud/aiplatform/gapic/schema/__init__.py +++ b/google/cloud/aiplatform/gapic/schema/__init__.py @@ -14,7 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from google.cloud.aiplatform.helpers import _decorators +from google.cloud.aiplatform.utils.enhanced_library import _decorators from google.cloud.aiplatform.v1.schema import predict from google.cloud.aiplatform.v1.schema import trainingjob from google.cloud.aiplatform.v1beta1.schema import predict as predict_v1beta1 diff --git a/google/cloud/aiplatform/helpers/__init__.py b/google/cloud/aiplatform/helpers/__init__.py index 3f031f2bb4..e5fa8f665d 100644 --- a/google/cloud/aiplatform/helpers/__init__.py +++ b/google/cloud/aiplatform/helpers/__init__.py @@ -1,3 +1,21 @@ -from google.cloud.aiplatform.helpers import value_converter +# 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 +# +# 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. -__all__ = (value_converter,) +from google.cloud.aiplatform.helpers import container_uri_builders + +get_prebuilt_prediction_container_uri = ( + container_uri_builders.get_prebuilt_prediction_container_uri +) + +__all__ = "get_prebuilt_prediction_container_uri" diff --git a/google/cloud/aiplatform/helpers/container_uri_builders.py b/google/cloud/aiplatform/helpers/container_uri_builders.py new file mode 100644 index 0000000000..6b49d3e230 --- /dev/null +++ b/google/cloud/aiplatform/helpers/container_uri_builders.py @@ -0,0 +1,109 @@ +# 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 +# +# 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 typing import Optional + +from google.cloud.aiplatform.constants import prediction +from google.cloud.aiplatform import initializer + + +def get_prebuilt_prediction_container_uri( + framework: str, + framework_version: str, + region: Optional[str] = None, + accelerator: str = "cpu", +) -> str: + """ + Get a Vertex AI pre-built prediction Docker container URI for + a given framework, version, region, and accelerator use. + + Example usage: + ``` + uri = aiplatform.helpers.get_prebuilt_prediction_container_uri( + framework="tensorflow", + framework_version="2.6", + accelerator="gpu" + ) + + model = aiplatform.Model.upload( + display_name="boston_housing_", + artifact_uri="gs://my-bucket/my-model/", + serving_container_image_uri=uri + ) + ``` + + Args: + framework (str): + Required. The ML framework of the pre-built container. For example, + `"tensorflow"`, `"xgboost"`, or `"sklearn"` + framework_version (str): + Required. The version of the specified ML framework as a string. + region (str): + Optional. AI region or multi-region. Used to select the correct + Artifact Registry multi-region repository and reduce latency. + Must start with `"us"`, `"asia"` or `"europe"`. + Default is location set by `aiplatform.init()`. + accelerator (str): + Optional. The type of accelerator support provided by container. For + example: `"cpu"` or `"gpu"` + Default is `"cpu"`. + + Returns: + uri (str): + A Vertex AI prediction container URI + + Raises: + ValueError: If containers for provided framework are unavailable or the + container does not support the specified version, accelerator, or region. + """ + URI_MAP = prediction._SERVING_CONTAINER_URI_MAP + DOCS_URI_MESSAGE = ( + f"See {prediction._SERVING_CONTAINER_DOCUMENTATION_URL} " + "for complete list of supported containers" + ) + + # If region not provided, use initializer location + region = region or initializer.global_config.location + region = region.split("-", 1)[0] + framework = framework.lower() + + if not URI_MAP.get(region): + raise ValueError( + f"Unsupported container region `{region}`, supported regions are " + f"{', '.join(URI_MAP.keys())}. " + f"{DOCS_URI_MESSAGE}" + ) + + if not URI_MAP[region].get(framework): + raise ValueError( + f"No containers found for framework `{framework}`. Supported frameworks are " + f"{', '.join(URI_MAP[region].keys())} {DOCS_URI_MESSAGE}" + ) + + if not URI_MAP[region][framework].get(accelerator): + raise ValueError( + f"{framework} containers do not support `{accelerator}` accelerator. Supported accelerators " + f"are {', '.join(URI_MAP[region][framework].keys())}. {DOCS_URI_MESSAGE}" + ) + + final_uri = URI_MAP[region][framework][accelerator].get(framework_version) + + if not final_uri: + raise ValueError( + f"No serving container for `{framework}` version `{framework_version}` " + f"with accelerator `{accelerator}` found. Supported versions " + f"include {', '.join(URI_MAP[region][framework][accelerator].keys())}. {DOCS_URI_MESSAGE}" + ) + + return final_uri diff --git a/google/cloud/aiplatform/hyperparameter_tuning.py b/google/cloud/aiplatform/hyperparameter_tuning.py index a7a0e641cd..a43f1c39fd 100644 --- a/google/cloud/aiplatform/hyperparameter_tuning.py +++ b/google/cloud/aiplatform/hyperparameter_tuning.py @@ -101,7 +101,10 @@ class DoubleParameterSpec(_ParameterSpec): _parameter_spec_value_key = "double_value_spec" def __init__( - self, min: float, max: float, scale: str, + self, + min: float, + max: float, + scale: str, ): """ Value specification for a parameter in ``DOUBLE`` type. @@ -135,7 +138,10 @@ class IntegerParameterSpec(_ParameterSpec): _parameter_spec_value_key = "integer_value_spec" def __init__( - self, min: int, max: int, scale: str, + self, + min: int, + max: int, + scale: str, ): """ Value specification for a parameter in ``INTEGER`` type. @@ -169,7 +175,8 @@ class CategoricalParameterSpec(_ParameterSpec): _parameter_spec_value_key = "categorical_value_spec" def __init__( - self, values: Sequence[str], + self, + values: Sequence[str], ): """Value specification for a parameter in ``CATEGORICAL`` type. @@ -192,7 +199,9 @@ class DiscreteParameterSpec(_ParameterSpec): _parameter_spec_value_key = "discrete_value_spec" def __init__( - self, values: Sequence[float], scale: str, + self, + values: Sequence[float], + scale: str, ): """Value specification for a parameter in ``DISCRETE`` type. diff --git a/google/cloud/aiplatform/initializer.py b/google/cloud/aiplatform/initializer.py index 18341bde46..9f0afd9e70 100644 --- a/google/cloud/aiplatform/initializer.py +++ b/google/cloud/aiplatform/initializer.py @@ -29,9 +29,11 @@ from google.auth.exceptions import GoogleAuthError from google.cloud.aiplatform import compat -from google.cloud.aiplatform import constants +from google.cloud.aiplatform.constants import base as constants from google.cloud.aiplatform import utils from google.cloud.aiplatform.metadata import metadata +from google.cloud.aiplatform.utils import resource_manager_utils +from google.cloud.aiplatform.tensorboard import tensorboard_resource from google.cloud.aiplatform.compat.types import ( encryption_spec as gca_encryption_spec_compat, @@ -57,6 +59,9 @@ def init( location: Optional[str] = None, experiment: Optional[str] = None, experiment_description: Optional[str] = None, + experiment_tensorboard: Optional[ + Union[str, tensorboard_resource.Tensorboard] + ] = None, staging_bucket: Optional[str] = None, credentials: Optional[auth_credentials.Credentials] = None, encryption_spec_key_name: Optional[str] = None, @@ -67,8 +72,15 @@ def init( project (str): The default project to use when making API calls. location (str): The default location to use when making API calls. If not set defaults to us-central-1. - experiment (str): The experiment name. - experiment_description (str): The description of the experiment. + experiment (str): Optional. The experiment name. + experiment_description (str): Optional. The description of the experiment. + experiment_tensorboard (Union[str, tensorboard_resource.Tensorboard]): + Optional. The Vertex AI TensorBoard instance, Tensorboard resource name, + or Tensorboard resource ID to use as a backing Tensorboard for the provided + experiment. + + Example tensorboard resource name format: + "projects/123/locations/us-central1/tensorboards/456" staging_bucket (str): The default staging bucket to use to stage artifacts when making API calls. In the form gs://... credentials (google.auth.credentials.Credentials): The default custom @@ -83,28 +95,35 @@ def init( resource is created. If set, this resource and all sub-resources will be secured by this key. + Raises: + ValueError: + If experiment_description is provided but experiment is not. + If experiment_tensorboard is provided but expeirment is not. """ + if experiment_description and experiment is None: + raise ValueError( + "Experiment needs to be set in `init` in order to add experiment descriptions." + ) + + if experiment_tensorboard and experiment is None: + raise ValueError( + "Experiment needs to be set in `init` in order to add experiment_tensorboard." + ) + # reset metadata_service config if project or location is updated. if (project and project != self._project) or ( location and location != self._location ): - if metadata.metadata_service.experiment_name: - logging.info("project/location updated, reset Metadata config.") - metadata.metadata_service.reset() + if metadata._experiment_tracker.experiment_name: + logging.info("project/location updated, reset Experiment config.") + metadata._experiment_tracker.reset() + if project: self._project = project if location: utils.validate_region(location) self._location = location - if experiment: - metadata.metadata_service.set_experiment( - experiment=experiment, description=experiment_description - ) - if experiment_description and experiment is None: - raise ValueError( - "Experiment name needs to be set in `init` in order to add experiment descriptions." - ) if staging_bucket: self._staging_bucket = staging_bucket if credentials: @@ -112,6 +131,13 @@ def init( if encryption_spec_key_name: self._encryption_spec_key_name = encryption_spec_key_name + if experiment: + metadata._experiment_tracker.set_experiment( + experiment=experiment, + description=experiment_description, + backing_tensorboard=experiment_tensorboard, + ) + def get_encryption_spec( self, encryption_spec_key_name: Optional[str], @@ -147,6 +173,26 @@ def project(self) -> str: if self._project: return self._project + # Project is not set. Trying to get it from the environment. + # See https://github.com/googleapis/python-aiplatform/issues/852 + # See https://github.com/googleapis/google-auth-library-python/issues/924 + # TODO: Remove when google.auth.default() learns the + # CLOUD_ML_PROJECT_ID env variable or Vertex AI starts setting GOOGLE_CLOUD_PROJECT env variable. + project_number = os.environ.get("CLOUD_ML_PROJECT_ID") + if project_number: + # Try to convert project number to project ID which is more readable. + try: + project_id = resource_manager_utils.get_project_id( + project_number=project_number, + credentials=self.credentials, + ) + return project_id + except Exception: + logging.getLogger(__name__).warning( + "Failed to convert project number to project ID.", exc_info=True + ) + return project_number + project_not_found_exception_str = ( "Unable to find your project. Please provide a project ID by:" "\n- Passing a constructor argument" @@ -191,17 +237,26 @@ def encryption_spec_key_name(self) -> Optional[str]: """Default encryption spec key name, if provided.""" return self._encryption_spec_key_name + @property + def experiment_name(self) -> Optional[str]: + """Default experiment name, if provided.""" + return metadata._experiment_tracker.experiment_name + def get_client_options( - self, location_override: Optional[str] = None + self, + location_override: Optional[str] = None, + prediction_client: bool = False, + api_base_path_override: Optional[str] = None, ) -> client_options.ClientOptions: """Creates GAPIC client_options using location and type. Args: location_override (str): - Set this parameter to get client options for a location different from - location set by initializer. Must be a GCP region supported by AI - Platform (Unified). - + Optional. Set this parameter to get client options for a location different + from location set by initializer. Must be a GCP region supported by + Vertex AI. + prediction_client (str): Optional. flag to use a prediction endpoint. + api_base_path_override (str): Optional. Override default API base path. Returns: clients_options (google.api_core.client_options.ClientOptions): A ClientOptions object set with regionalized API endpoint, i.e. @@ -218,8 +273,14 @@ def get_client_options( utils.validate_region(region) + service_base_path = api_base_path_override or ( + constants.PREDICTION_API_BASE_PATH + if prediction_client + else constants.API_BASE_PATH + ) + return client_options.ClientOptions( - api_endpoint=f"{region}-{constants.API_BASE_PATH}" + api_endpoint=f"{region}-{service_base_path}" ) def common_location_path( @@ -251,17 +312,19 @@ def create_client( credentials: Optional[auth_credentials.Credentials] = None, location_override: Optional[str] = None, prediction_client: bool = False, + api_base_path_override: Optional[str] = None, ) -> utils.VertexAiServiceClientWithOverride: """Instantiates a given VertexAiServiceClient with optional overrides. Args: client_class (utils.VertexAiServiceClientWithOverride): - (Required) An Vertex AI Service Client with optional overrides. + Required. A Vertex AI Service Client with optional overrides. credentials (auth_credentials.Credentials): - Custom auth credentials. If not provided will use the current config. - location_override (str): Optional location override. - prediction_client (str): Optional flag to use a prediction endpoint. + Optional. Custom auth credentials. If not provided will use the current config. + location_override (str): Optional. location override. + prediction_client (str): Optional. flag to use a prediction endpoint. + api_base_path_override (str): Optional. Override default api base path. Returns: client: Instantiated Vertex AI Service client with optional overrides """ @@ -276,7 +339,9 @@ def create_client( kwargs = { "credentials": credentials or self.credentials, "client_options": self.get_client_options( - location_override=location_override + location_override=location_override, + prediction_client=prediction_client, + api_base_path_override=api_base_path_override, ), "client_info": client_info, } diff --git a/google/cloud/aiplatform/jobs.py b/google/cloud/aiplatform/jobs.py index c37530a78f..ab24afb171 100644 --- a/google/cloud/aiplatform/jobs.py +++ b/google/cloud/aiplatform/jobs.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,45 +19,39 @@ import abc import copy -import sys +import datetime import time -import logging from google.cloud import storage from google.cloud import bigquery from google.auth import credentials as auth_credentials from google.protobuf import duration_pb2 # type: ignore +from google.rpc import status_pb2 from google.cloud import aiplatform from google.cloud.aiplatform import base -from google.cloud.aiplatform import compat -from google.cloud.aiplatform import constants -from google.cloud.aiplatform import initializer -from google.cloud.aiplatform import hyperparameter_tuning -from google.cloud.aiplatform import utils -from google.cloud.aiplatform.utils import source_utils -from google.cloud.aiplatform.utils import worker_spec_utils - -from google.cloud.aiplatform.compat.services import job_service_client from google.cloud.aiplatform.compat.types import ( batch_prediction_job as gca_bp_job_compat, - batch_prediction_job_v1 as gca_bp_job_v1, - batch_prediction_job_v1beta1 as gca_bp_job_v1beta1, + completion_stats as gca_completion_stats, custom_job as gca_custom_job_compat, - custom_job_v1beta1 as gca_custom_job_v1beta1, - explanation_v1beta1 as gca_explanation_v1beta1, + explanation as gca_explanation_compat, io as gca_io_compat, - io_v1beta1 as gca_io_v1beta1, job_state as gca_job_state, hyperparameter_tuning_job as gca_hyperparameter_tuning_job_compat, - hyperparameter_tuning_job_v1beta1 as gca_hyperparameter_tuning_job_v1beta1, machine_resources as gca_machine_resources_compat, - machine_resources_v1beta1 as gca_machine_resources_v1beta1, + manual_batch_tuning_parameters as gca_manual_batch_tuning_parameters_compat, study as gca_study_compat, ) +from google.cloud.aiplatform.constants import base as constants +from google.cloud.aiplatform import initializer +from google.cloud.aiplatform import hyperparameter_tuning +from google.cloud.aiplatform import utils +from google.cloud.aiplatform.utils import console_utils +from google.cloud.aiplatform.utils import source_utils +from google.cloud.aiplatform.utils import worker_spec_utils + -logging.basicConfig(level=logging.INFO, stream=sys.stdout) _LOGGER = base.Logger(__name__) _JOB_COMPLETE_STATES = ( @@ -72,8 +66,14 @@ gca_job_state.JobState.JOB_STATE_CANCELLED, ) +# _block_until_complete wait times +_JOB_WAIT_TIME = 5 # start at five seconds +_LOG_WAIT_TIME = 5 +_MAX_WAIT_TIME = 60 * 5 # 5 minute wait +_WAIT_TIME_MULTIPLIER = 2 # scale wait by 2 every iteration + -class _Job(base.VertexAiResourceNounWithFutureManager): +class _Job(base.VertexAiStatefulResource): """Class that represents a general Job resource in Vertex AI. Cannot be directly instantiated. @@ -89,7 +89,9 @@ class _Job(base.VertexAiResourceNounWithFutureManager): """ client_class = utils.JobClientWithOverride - _is_client_prediction_client = False + + # Required by the done() method + _valid_done_states = _JOB_COMPLETE_STATES def __init__( self, @@ -98,7 +100,7 @@ def __init__( location: Optional[str] = None, credentials: Optional[auth_credentials.Credentials] = None, ): - """Retrives Job subclass resource by calling a subclass-specific getter + """Retrieves Job subclass resource by calling a subclass-specific getter method. Args: @@ -138,6 +140,27 @@ def state(self) -> gca_job_state.JobState: return self._gca_resource.state + @property + def start_time(self) -> Optional[datetime.datetime]: + """Time when the Job resource entered the `JOB_STATE_RUNNING` for the + first time.""" + self._sync_gca_resource() + return getattr(self._gca_resource, "start_time") + + @property + def end_time(self) -> Optional[datetime.datetime]: + """Time when the Job resource entered the `JOB_STATE_SUCCEEDED`, + `JOB_STATE_FAILED`, or `JOB_STATE_CANCELLED` state.""" + self._sync_gca_resource() + return getattr(self._gca_resource, "end_time") + + @property + def error(self) -> Optional[status_pb2.Status]: + """Detailed error info for this Job resource. Only populated when the + Job's state is `JOB_STATE_FAILED` or `JOB_STATE_CANCELLED`.""" + self._sync_gca_resource() + return getattr(self._gca_resource, "error") + @property @abc.abstractmethod def _job_type(cls) -> str: @@ -153,10 +176,24 @@ def _cancel_method(cls) -> str: def _dashboard_uri(self) -> Optional[str]: """Helper method to compose the dashboard uri where job can be viewed.""" - fields = utils.extract_fields_from_resource_name(self.resource_name) - url = f"https://console.cloud.google.com/ai/platform/locations/{fields.location}/{self._job_type}/{fields.id}?project={fields.project}" + fields = self._parse_resource_name(self.resource_name) + location = fields.pop("location") + project = fields.pop("project") + job = list(fields.values())[0] + url = f"https://console.cloud.google.com/ai/platform/locations/{location}/{self._job_type}/{job}?project={project}" return url + def _log_job_state(self): + """Helper method to log job state.""" + _LOGGER.info( + "%s %s current state:\n%s" + % ( + self.__class__.__name__, + self._gca_resource.name, + self._gca_resource.state, + ) + ) + def _block_until_complete(self): """Helper method to block and check on job until complete. @@ -164,36 +201,19 @@ def _block_until_complete(self): RuntimeError: If job failed or cancelled. """ - # Used these numbers so failures surface fast - wait = 5 # start at five seconds - log_wait = 5 - max_wait = 60 * 5 # 5 minute wait - multiplier = 2 # scale wait by 2 every iteration + log_wait = _LOG_WAIT_TIME previous_time = time.time() while self.state not in _JOB_COMPLETE_STATES: current_time = time.time() if current_time - previous_time >= log_wait: - _LOGGER.info( - "%s %s current state:\n%s" - % ( - self.__class__.__name__, - self._gca_resource.name, - self._gca_resource.state, - ) - ) - log_wait = min(log_wait * multiplier, max_wait) + self._log_job_state() + log_wait = min(log_wait * _WAIT_TIME_MULTIPLIER, _MAX_WAIT_TIME) previous_time = current_time - time.sleep(wait) + time.sleep(_JOB_WAIT_TIME) + + self._log_job_state() - _LOGGER.info( - "%s %s current state:\n%s" - % ( - self.__class__.__name__, - self._gca_resource.name, - self._gca_resource.state, - ) - ) # Error is only populated when the job state is # JOB_STATE_FAILED or JOB_STATE_CANCELLED. if self._gca_resource.state in _JOB_ERROR_STATES: @@ -267,6 +287,8 @@ class BatchPredictionJob(_Job): _cancel_method = "cancel_batch_prediction_job" _delete_method = "delete_batch_prediction_job" _job_type = "batch-predictions" + _parse_resource_name_method = "parse_batch_prediction_job_path" + _format_resource_name_method = "batch_prediction_job_path" def __init__( self, @@ -301,11 +323,38 @@ def __init__( credentials=credentials, ) + @property + def output_info( + self, + ) -> Optional[aiplatform.gapic.BatchPredictionJob.OutputInfo]: + """Information describing the output of this job, including output location + into which prediction output is written. + + This is only available for batch prediction jobs that have run successfully. + """ + self._assert_gca_resource_is_available() + return self._gca_resource.output_info + + @property + def partial_failures(self) -> Optional[Sequence[status_pb2.Status]]: + """Partial failures encountered. For example, single files that can't be read. + This field never exceeds 20 entries. Status details fields contain standard + GCP error details.""" + self._assert_gca_resource_is_available() + return getattr(self._gca_resource, "partial_failures") + + @property + def completion_stats(self) -> Optional[gca_completion_stats.CompletionStats]: + """Statistics on completed and failed prediction instances.""" + self._assert_gca_resource_is_available() + return getattr(self._gca_resource, "completion_stats") + @classmethod def create( cls, + # TODO(b/223262536): Make the job_display_name parameter optional in the next major release job_display_name: str, - model_name: str, + model_name: Union[str, "aiplatform.Model"], instances_format: str = "jsonl", predictions_format: str = "jsonl", gcs_source: Optional[Union[str, Sequence[str]]] = None, @@ -323,12 +372,14 @@ def create( explanation_parameters: Optional[ "aiplatform.explain.ExplanationParameters" ] = None, - labels: Optional[dict] = None, + labels: Optional[Dict[str, str]] = None, project: Optional[str] = None, location: Optional[str] = None, credentials: Optional[auth_credentials.Credentials] = None, encryption_spec_key_name: Optional[str] = None, sync: bool = True, + create_request_timeout: Optional[float] = None, + batch_size: Optional[int] = None, ) -> "BatchPredictionJob": """Create a batch prediction job. @@ -337,29 +388,31 @@ def create( Required. The user-defined name of the BatchPredictionJob. The name can be up to 128 characters long and can be consist of any UTF-8 characters. - model_name (str): + model_name (Union[str, aiplatform.Model]): Required. A fully-qualified model resource name or model ID. Example: "projects/123/locations/us-central1/models/456" or "456" when project and location are initialized or passed. + + Or an instance of aiplatform.Model. instances_format (str): - Required. The format in which instances are given, must be one - of "jsonl", "csv", "bigquery", "tf-record", "tf-record-gzip", - or "file-list". Default is "jsonl" when using `gcs_source`. If a - `bigquery_source` is provided, this is overriden to "bigquery". + Required. The format in which instances are provided. Must be one + of the formats listed in `Model.supported_input_storage_formats`. + Default is "jsonl" when using `gcs_source`. If a `bigquery_source` + is provided, this is overridden to "bigquery". predictions_format (str): - Required. The format in which Vertex AI gives the - predictions, must be one of "jsonl", "csv", or "bigquery". + Required. The format in which Vertex AI outputs the + predictions, must be one of the formats specified in + `Model.supported_output_storage_formats`. Default is "jsonl" when using `gcs_destination_prefix`. If a - `bigquery_destination_prefix` is provided, this is overriden to + `bigquery_destination_prefix` is provided, this is overridden to "bigquery". gcs_source (Optional[Sequence[str]]): Google Cloud Storage URI(-s) to your instances to run batch prediction on. They must match `instances_format`. - May contain wildcards. For more information on wildcards, see - https://cloud.google.com/storage/docs/gsutil/addlhelp/WildcardNames. + bigquery_source (Optional[str]): BigQuery URI to a table, up to 2000 characters long. For example: - `projectId.bqDatasetId.bqTableId` + `bq://projectId.bqDatasetId.bqTableId` gcs_destination_prefix (Optional[str]): The Google Cloud Storage location of the directory where the output is to be written to. In the given directory a new @@ -383,24 +436,27 @@ def create( which as value has ```google.rpc.Status`` `__ containing only ``code`` and ``message`` fields. bigquery_destination_prefix (Optional[str]): - The BigQuery project location where the output is to be - written to. In the given project a new dataset is created - with name - ``prediction__`` where - is made BigQuery-dataset-name compatible (for example, most - special characters become underscores), and timestamp is in - YYYY_MM_DDThh_mm_ss_sssZ "based on ISO-8601" format. In the - dataset two tables will be created, ``predictions``, and - ``errors``. If the Model has both ``instance`` and ``prediction`` - schemata defined then the tables have columns as follows: - The ``predictions`` table contains instances for which the - prediction succeeded, it has columns as per a concatenation - of the Model's instance and prediction schemata. The - ``errors`` table contains rows for which the prediction has - failed, it has instance columns, as per the instance schema, - followed by a single "errors" column, which as values has - ```google.rpc.Status`` `__ represented as a STRUCT, - and containing only ``code`` and ``message``. + The BigQuery URI to a project or table, up to 2000 characters long. + When only the project is specified, the Dataset and Table is created. + When the full table reference is specified, the Dataset must exist and + table must not exist. Accepted forms: ``bq://projectId`` or + ``bq://projectId.bqDatasetId`` or + ``bq://projectId.bqDatasetId.bqTableId``. If no Dataset is specified, + a new one is created with the name + ``prediction__`` + where the table name is made BigQuery-dataset-name compatible + (for example, most special characters become underscores), and + timestamp is in YYYY_MM_DDThh_mm_ss_sssZ "based on ISO-8601" + format. In the dataset two tables will be created, ``predictions``, + and ``errors``. If the Model has both ``instance`` and + ``prediction`` schemata defined then the tables have columns as + follows: The ``predictions`` table contains instances for which + the prediction succeeded, it has columns as per a concatenation + of the Model's instance and prediction schemata. The ``errors`` + table contains rows for which the prediction has failed, it has + instance columns, as per the instance schema, followed by a single + "errors" column, which as values has ```google.rpc.Status`` `__ + represented as a STRUCT, and containing only ``code`` and ``message``. model_parameters (Optional[Dict]): The parameters that govern the predictions. The schema of the parameters may be specified via the Model's `parameters_schema_uri`. @@ -452,8 +508,8 @@ def create( a field of the `explanation_parameters` object is not populated, the corresponding field of the `Model.explanation_parameters` object is inherited. For more details, see `Ref docs ` - labels (Optional[dict]): - The labels with user-defined metadata to organize your + labels (Dict[str, str]): + Optional. The labels with user-defined metadata to organize your BatchPredictionJobs. Label keys and values can be no longer than 64 characters (Unicode codepoints), can only contain lowercase letters, numeric characters, underscores and dashes. @@ -479,20 +535,36 @@ def create( Whether to execute this method synchronously. If False, this method will be executed in concurrent Future and any downstream object will be immediately returned and synced when the Future has completed. - + create_request_timeout (float): + Optional. The timeout for the create request in seconds. + batch_size (int): + Optional. The number of the records (e.g. instances) of the operation given in each batch + to a machine replica. Machine type, and size of a single record should be considered + when setting this parameter, higher value speeds up the batch operation's execution, + but too high value will result in a whole batch not fitting in a machine's memory, + and the whole operation will fail. + The default value is 64. Returns: (jobs.BatchPredictionJob): Instantiated representation of the created batch prediction job. """ + if not job_display_name: + job_display_name = cls._generate_display_name() utils.validate_display_name(job_display_name) - model_name = utils.full_resource_name( - resource_name=model_name, - resource_noun="models", - project=project, - location=location, - ) + if labels: + utils.validate_labels(labels) + + if isinstance(model_name, str): + model_name = utils.full_resource_name( + resource_name=model_name, + resource_noun="models", + parse_resource_name_method=aiplatform.Model._parse_resource_name, + format_resource_name_method=aiplatform.Model._format_resource_name, + project=project, + location=location, + ) # Raise error if both or neither source URIs are provided if bool(gcs_source) == bool(bigquery_source): @@ -521,38 +593,28 @@ def create( f"{predictions_format} is not an accepted prediction format " f"type. Please choose from: {constants.BATCH_PREDICTION_OUTPUT_STORAGE_FORMATS}" ) - gca_bp_job = gca_bp_job_compat - gca_io = gca_io_compat - gca_machine_resources = gca_machine_resources_compat - select_version = compat.DEFAULT_VERSION - if generate_explanation: - gca_bp_job = gca_bp_job_v1beta1 - gca_io = gca_io_v1beta1 - gca_machine_resources = gca_machine_resources_v1beta1 - select_version = compat.V1BETA1 - gapic_batch_prediction_job = gca_bp_job.BatchPredictionJob() + gapic_batch_prediction_job = gca_bp_job_compat.BatchPredictionJob() # Required Fields gapic_batch_prediction_job.display_name = job_display_name - gapic_batch_prediction_job.model = model_name - input_config = gca_bp_job.BatchPredictionJob.InputConfig() - output_config = gca_bp_job.BatchPredictionJob.OutputConfig() + input_config = gca_bp_job_compat.BatchPredictionJob.InputConfig() + output_config = gca_bp_job_compat.BatchPredictionJob.OutputConfig() if bigquery_source: input_config.instances_format = "bigquery" - input_config.bigquery_source = gca_io.BigQuerySource() + input_config.bigquery_source = gca_io_compat.BigQuerySource() input_config.bigquery_source.input_uri = bigquery_source else: input_config.instances_format = instances_format - input_config.gcs_source = gca_io.GcsSource( + input_config.gcs_source = gca_io_compat.GcsSource( uris=gcs_source if type(gcs_source) == list else [gcs_source] ) if bigquery_destination_prefix: output_config.predictions_format = "bigquery" - output_config.bigquery_destination = gca_io.BigQueryDestination() + output_config.bigquery_destination = gca_io_compat.BigQueryDestination() bq_dest_prefix = bigquery_destination_prefix @@ -562,7 +624,7 @@ def create( output_config.bigquery_destination.output_uri = bq_dest_prefix else: output_config.predictions_format = predictions_format - output_config.gcs_destination = gca_io.GcsDestination( + output_config.gcs_destination = gca_io_compat.GcsDestination( output_uri_prefix=gcs_destination_prefix ) @@ -570,9 +632,10 @@ def create( gapic_batch_prediction_job.output_config = output_config # Optional Fields - gapic_batch_prediction_job.encryption_spec = initializer.global_config.get_encryption_spec( - encryption_spec_key_name=encryption_spec_key_name, - select_version=select_version, + gapic_batch_prediction_job.encryption_spec = ( + initializer.global_config.get_encryption_spec( + encryption_spec_key_name=encryption_spec_key_name + ) ) if model_parameters: @@ -581,12 +644,12 @@ def create( # Custom Compute if machine_type: - machine_spec = gca_machine_resources.MachineSpec() + machine_spec = gca_machine_resources_compat.MachineSpec() machine_spec.machine_type = machine_type machine_spec.accelerator_type = accelerator_type machine_spec.accelerator_count = accelerator_count - dedicated_resources = gca_machine_resources.BatchDedicatedResources() + dedicated_resources = gca_machine_resources_compat.BatchDedicatedResources() dedicated_resources.machine_spec = machine_spec dedicated_resources.starting_replica_count = starting_replica_count @@ -594,7 +657,14 @@ def create( gapic_batch_prediction_job.dedicated_resources = dedicated_resources - gapic_batch_prediction_job.manual_batch_tuning_parameters = None + manual_batch_tuning_parameters = ( + gca_manual_batch_tuning_parameters_compat.ManualBatchTuningParameters() + ) + manual_batch_tuning_parameters.batch_size = batch_size + + gapic_batch_prediction_job.manual_batch_tuning_parameters = ( + manual_batch_tuning_parameters + ) # User Labels gapic_batch_prediction_job.labels = labels @@ -604,67 +674,53 @@ def create( gapic_batch_prediction_job.generate_explanation = generate_explanation if explanation_metadata or explanation_parameters: - gapic_batch_prediction_job.explanation_spec = gca_explanation_v1beta1.ExplanationSpec( - metadata=explanation_metadata, parameters=explanation_parameters + gapic_batch_prediction_job.explanation_spec = ( + gca_explanation_compat.ExplanationSpec( + metadata=explanation_metadata, parameters=explanation_parameters + ) ) - # TODO (b/174502913): Support private feature once released - - api_client = cls._instantiate_client(location=location, credentials=credentials) + empty_batch_prediction_job = cls._empty_constructor( + project=project, + location=location, + credentials=credentials, + ) return cls._create( - api_client=api_client, - parent=initializer.global_config.common_location_path( - project=project, location=location - ), - batch_prediction_job=gapic_batch_prediction_job, + empty_batch_prediction_job=empty_batch_prediction_job, + model_or_model_name=model_name, + gca_batch_prediction_job=gapic_batch_prediction_job, generate_explanation=generate_explanation, - project=project or initializer.global_config.project, - location=location or initializer.global_config.location, - credentials=credentials or initializer.global_config.credentials, sync=sync, + create_request_timeout=create_request_timeout, ) @classmethod - @base.optional_sync() + @base.optional_sync(return_input_arg="empty_batch_prediction_job") def _create( cls, - api_client: job_service_client.JobServiceClient, - parent: str, - batch_prediction_job: Union[ - gca_bp_job_v1beta1.BatchPredictionJob, gca_bp_job_v1.BatchPredictionJob - ], + empty_batch_prediction_job: "BatchPredictionJob", + model_or_model_name: Union[str, "aiplatform.Model"], + gca_batch_prediction_job: gca_bp_job_compat.BatchPredictionJob, generate_explanation: bool, - project: str, - location: str, - credentials: Optional[auth_credentials.Credentials], sync: bool = True, + create_request_timeout: Optional[float] = None, ) -> "BatchPredictionJob": """Create a batch prediction job. Args: - api_client (dataset_service_client.DatasetServiceClient): - Required. An instance of DatasetServiceClient with the correct api_endpoint - already set based on user's preferences. - batch_prediction_job (gca_bp_job.BatchPredictionJob): + empty_batch_prediction_job (BatchPredictionJob): + Required. BatchPredictionJob without _gca_resource populated. + model_or_model_name (Union[str, aiplatform.Model]): + Required. Required. A fully-qualified model resource name or + an instance of aiplatform.Model. + gca_batch_prediction_job (gca_bp_job.BatchPredictionJob): Required. a batch prediction job proto for creating a batch prediction job on Vertex AI. generate_explanation (bool): Required. Generate explanation along with the batch prediction results. - parent (str): - Required. Also known as common location path, that usually contains the - project and location that the user provided to the upstream method. - Example: "projects/my-prj/locations/us-central1" - project (str): - Required. Project to upload this model to. Overrides project set in - aiplatform.init. - location (str): - Required. Location to upload this model to. Overrides location set in - aiplatform.init. - credentials (Optional[auth_credentials.Credentials]): - Custom credentials to use to upload this model. Overrides - credentials set in aiplatform.init. - + create_request_timeout (float): + Optional. The timeout for the create request in seconds. Returns: (jobs.BatchPredictionJob): Instantiated representation of the created batch prediction job. @@ -676,21 +732,33 @@ def _create( by Vertex AI. """ # select v1beta1 if explain else use default v1 - if generate_explanation: - api_client = api_client.select_version(compat.V1BETA1) + + parent = initializer.global_config.common_location_path( + project=empty_batch_prediction_job.project, + location=empty_batch_prediction_job.location, + ) + + model_resource_name = ( + model_or_model_name + if isinstance(model_or_model_name, str) + else model_or_model_name.resource_name + ) + + gca_batch_prediction_job.model = model_resource_name + + api_client = empty_batch_prediction_job.api_client _LOGGER.log_create_with_lro(cls) gca_batch_prediction_job = api_client.create_batch_prediction_job( - parent=parent, batch_prediction_job=batch_prediction_job + parent=parent, + batch_prediction_job=gca_batch_prediction_job, + timeout=create_request_timeout, ) - batch_prediction_job = cls( - batch_prediction_job_name=gca_batch_prediction_job.name, - project=project, - location=location, - credentials=credentials, - ) + empty_batch_prediction_job._gca_resource = gca_batch_prediction_job + + batch_prediction_job = empty_batch_prediction_job _LOGGER.log_create_complete(cls, batch_prediction_job._gca_resource, "bpj") @@ -729,6 +797,8 @@ def iter_outputs( GCS or BQ output provided. """ + self._assert_gca_resource_is_available() + if self.state != gca_job_state.JobState.JOB_STATE_SUCCEEDED: raise RuntimeError( f"Cannot read outputs until BatchPredictionJob has succeeded, " @@ -757,23 +827,27 @@ def iter_outputs( # BigQuery Destination, return RowIterator elif output_info.bigquery_output_dataset: - # Build a BigQuery Client using the same credentials as JobServiceClient - bq_client = bigquery.Client( - project=self.project, - credentials=self.api_client._transport._credentials, - ) - - # Format from service is `bq://projectId.bqDatasetId` + # Format of `bigquery_output_dataset` from service is `bq://projectId.bqDatasetId` bq_dataset = output_info.bigquery_output_dataset + bq_table = output_info.bigquery_output_table + + if not bq_table: + raise RuntimeError( + "A BigQuery table with predictions was not found, this " + f"might be due to errors. Visit {self._dashboard_uri()} for details." + ) if bq_dataset.startswith("bq://"): bq_dataset = bq_dataset[5:] - # # Split project ID and BQ dataset ID - _, bq_dataset_id = bq_dataset.split(".", 1) + # Build a BigQuery Client using the same credentials as JobServiceClient + bq_client = bigquery.Client( + project=self.project, + credentials=self.api_client._transport._credentials, + ) row_iterator = bq_client.list_rows( - table=f"{bq_dataset_id}.predictions", max_results=bq_max_results + table=f"{bq_dataset}.{bq_table}", max_results=bq_max_results ) return row_iterator @@ -785,6 +859,10 @@ def iter_outputs( f"on your prediction output:\n{output_info}" ) + def wait_for_resource_creation(self) -> None: + """Waits until resource has been created.""" + self._wait_for_resource_creation() + class _RunnableJob(_Job): """ABC to interface job as a runnable training class.""" @@ -800,7 +878,7 @@ def __init__( Args: project(str): Project of the resource noun. location(str): The location of the resource noun. - credentials(google.auth.crendentials.Crendentials): Optional custom + credentials(google.auth.credentials.Credentials): Optional custom credentials to use when accessing interacting with resource noun. """ @@ -812,26 +890,95 @@ def __init__( project=project, location=location ) + self._logged_web_access_uris = set() + + @classmethod + def _empty_constructor( + cls, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + resource_name: Optional[str] = None, + ) -> "_RunnableJob": + """Initializes with all attributes set to None. + + The attributes should be populated after a future is complete. This allows + scheduling of additional API calls before the resource is created. + + Args: + project (str): Optional. Project of the resource noun. + location (str): Optional. The location of the resource noun. + credentials(google.auth.credentials.Credentials): + Optional. custom credentials to use when accessing interacting with + resource noun. + resource_name(str): Optional. A fully-qualified resource name or ID. + Returns: + An instance of this class with attributes set to None. + """ + self = super()._empty_constructor( + project=project, + location=location, + credentials=credentials, + resource_name=resource_name, + ) + + self._logged_web_access_uris = set() + return self + + @property + def web_access_uris(self) -> Dict[str, Union[str, Dict[str, str]]]: + """Fetch the runnable job again and return the latest web access uris. + + Returns: + (Dict[str, Union[str, Dict[str, str]]]): + Web access uris of the runnable job. + """ + + # Fetch the Job again for most up-to-date web access uris + self._sync_gca_resource() + return self._get_web_access_uris() + @abc.abstractmethod - def run(self) -> None: + def _get_web_access_uris(self): + """Helper method to get the web access uris of the runnable job""" pass - @property - def _has_run(self) -> bool: - """Property returns true if this class has a resource name.""" - return bool(self._gca_resource.name) + @abc.abstractmethod + def _log_web_access_uris(self): + """Helper method to log the web access uris of the runnable job""" + pass - @property - def state(self) -> gca_job_state.JobState: - """Current state of job. + def _block_until_complete(self): + """Helper method to block and check on runnable job until complete. Raises: - RuntimeError if job run has not been called. + RuntimeError: If job failed or cancelled. """ - if not self._has_run: - raise RuntimeError("Job has not run. No state available.") - return super().state + log_wait = _LOG_WAIT_TIME + + previous_time = time.time() + while self.state not in _JOB_COMPLETE_STATES: + current_time = time.time() + if current_time - previous_time >= _LOG_WAIT_TIME: + self._log_job_state() + log_wait = min(log_wait * _WAIT_TIME_MULTIPLIER, _MAX_WAIT_TIME) + previous_time = current_time + self._log_web_access_uris() + time.sleep(_JOB_WAIT_TIME) + + self._log_job_state() + + # Error is only populated when the job state is + # JOB_STATE_FAILED or JOB_STATE_CANCELLED. + if self._gca_resource.state in _JOB_ERROR_STATES: + raise RuntimeError("Job failed with:\n%s" % self._gca_resource.error) + else: + _LOGGER.log_action_completed_against_resource("run", "completed", self) + + @abc.abstractmethod + def run(self) -> None: + pass @classmethod def get( @@ -841,7 +988,7 @@ def get( location: Optional[str] = None, credentials: Optional[auth_credentials.Credentials] = None, ) -> "_RunnableJob": - """Get an Vertex AI Job for the given resource_name. + """Get a Vertex AI Job for the given resource_name. Args: resource_name (str): @@ -857,7 +1004,7 @@ def get( credentials set in aiplatform.init. Returns: - An Vertex AI Job. + A Vertex AI Job. """ self = cls._empty_constructor( project=project, @@ -870,6 +1017,10 @@ def get( return self + def wait_for_resource_creation(self) -> None: + """Waits until resource has been created.""" + self._wait_for_resource_creation() + class DataLabelingJob(_Job): _resource_noun = "dataLabelingJobs" @@ -878,6 +1029,8 @@ class DataLabelingJob(_Job): _cancel_method = "cancel_data_labeling_job" _delete_method = "delete_data_labeling_job" _job_type = "labeling-tasks" + _parse_resource_name_method = "parse_data_labeling_job_path" + _format_resource_name_method = "data_labeling_job_path" pass @@ -886,22 +1039,27 @@ class CustomJob(_RunnableJob): _resource_noun = "customJobs" _getter_method = "get_custom_job" - _list_method = "list_custom_job" + _list_method = "list_custom_jobs" _cancel_method = "cancel_custom_job" _delete_method = "delete_custom_job" + _parse_resource_name_method = "parse_custom_job_path" + _format_resource_name_method = "custom_job_path" _job_type = "training" def __init__( self, + # TODO(b/223262536): Make display_name parameter fully optional in next major release display_name: str, worker_pool_specs: Union[List[Dict], List[aiplatform.gapic.WorkerPoolSpec]], + base_output_dir: Optional[str] = None, project: Optional[str] = None, location: Optional[str] = None, credentials: Optional[auth_credentials.Credentials] = None, + labels: Optional[Dict[str, str]] = None, encryption_spec_key_name: Optional[str] = None, staging_bucket: Optional[str] = None, ): - """Cosntruct a Custom Job with Worker Pool Specs. + """Constructs a Custom Job with Worker Pool Specs. ``` Example usage: @@ -923,7 +1081,8 @@ def __init__( my_job = aiplatform.CustomJob( display_name='my_job', - worker_pool_specs=worker_pool_specs + worker_pool_specs=worker_pool_specs, + labels={'my_key': 'my_value'}, ) my_job.run() @@ -942,6 +1101,9 @@ def __init__( worker_pool_specs (Union[List[Dict], List[aiplatform.gapic.WorkerPoolSpec]]): Required. The spec of the worker pools including machine type and Docker image. Can provided as a list of dictionaries or list of WorkerPoolSpec proto messages. + base_output_dir (str): + Optional. GCS output directory of job. If not provided a + timestamped directory in the staging directory will be used. project (str): Optional.Project to run the custom job in. Overrides project set in aiplatform.init. location (str): @@ -949,6 +1111,16 @@ def __init__( credentials (auth_credentials.Credentials): Optional.Custom credentials to use to run call custom job service. Overrides credentials set in aiplatform.init. + labels (Dict[str, str]): + Optional. The labels with user-defined metadata to + organize CustomJobs. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + and examples of labels. encryption_spec_key_name (str): Optional.Customer-managed encryption key name for a CustomJob. If this is set, then all resources @@ -959,7 +1131,7 @@ def __init__( staging_bucket set in aiplatform.init. Raises: - RuntimeError is not staging bucket was set using aiplatfrom.init and a staging + RuntimeError: If staging bucket was not set using aiplatform.init and a staging bucket was not passed in. """ @@ -973,35 +1145,95 @@ def __init__( "should be set using aiplatform.init(staging_bucket='gs://my-bucket')" ) + if labels: + utils.validate_labels(labels) + + # default directory if not given + base_output_dir = base_output_dir or utils._timestamped_gcs_dir( + staging_bucket, "aiplatform-custom-job" + ) + + if not display_name: + display_name = self.__class__._generate_display_name() + self._gca_resource = gca_custom_job_compat.CustomJob( display_name=display_name, job_spec=gca_custom_job_compat.CustomJobSpec( worker_pool_specs=worker_pool_specs, base_output_directory=gca_io_compat.GcsDestination( - output_uri_prefix=staging_bucket + output_uri_prefix=base_output_dir ), ), + labels=labels, encryption_spec=initializer.global_config.get_encryption_spec( encryption_spec_key_name=encryption_spec_key_name ), ) + @property + def network(self) -> Optional[str]: + """The full name of the Google Compute Engine + [network](https://cloud.google.com/vpc/docs/vpc#networks) to which this + CustomJob should be peered. + + Takes the format `projects/{project}/global/networks/{network}`. Where + {project} is a project number, as in `12345`, and {network} is a network name. + + Private services access must already be configured for the network. If left + unspecified, the CustomJob is not peered with any network. + """ + self._assert_gca_resource_is_available() + return self._gca_resource.job_spec.network + + def _get_web_access_uris(self) -> Dict[str, str]: + """Helper method to get the web access uris of the custom job + + Returns: + (Dict[str, str]): + Web access uris of the custom job. + """ + return dict(self._gca_resource.web_access_uris) + + def _log_web_access_uris(self): + """Helper method to log the web access uris of the custom job""" + + for worker, uri in self._get_web_access_uris().items(): + if uri not in self._logged_web_access_uris: + _LOGGER.info( + "%s %s access the interactive shell terminals for the custom job:\n%s:\n%s" + % ( + self.__class__.__name__, + self._gca_resource.name, + worker, + uri, + ), + ) + self._logged_web_access_uris.add(uri) + @classmethod def from_local_script( cls, + # TODO(b/223262536): Make display_name parameter fully optional in next major release display_name: str, script_path: str, container_uri: str, - args: Optional[List[Union[str, float, int]]] = None, + args: Optional[Sequence[str]] = None, requirements: Optional[Sequence[str]] = None, environment_variables: Optional[Dict[str, str]] = None, replica_count: int = 1, machine_type: str = "n1-standard-4", accelerator_type: str = "ACCELERATOR_TYPE_UNSPECIFIED", accelerator_count: int = 0, + boot_disk_type: str = "pd-ssd", + boot_disk_size_gb: int = 100, + reduction_server_replica_count: int = 0, + reduction_server_machine_type: Optional[str] = None, + reduction_server_container_uri: Optional[str] = None, + base_output_dir: Optional[str] = None, project: Optional[str] = None, location: Optional[str] = None, credentials: Optional[auth_credentials.Credentials] = None, + labels: Optional[Dict[str, str]] = None, encryption_spec_key_name: Optional[str] = None, staging_bucket: Optional[str] = None, ) -> "CustomJob": @@ -1017,6 +1249,7 @@ def from_local_script( replica_count=1, args=['--dataset', 'gs://my-bucket/my-dataset', '--model_output_uri', 'gs://my-bucket/model'] + labels={'my_key': 'my_value'}, ) job.run() @@ -1029,7 +1262,7 @@ def from_local_script( Required. Local path to training script. container_uri (str): Required: Uri of the training container image to use for custom job. - args (Optional[List[Union[str, float, int]]]): + args (Optional[Sequence[str]]): Optional. Command line arguments to be passed to the Python task. requirements (Sequence[str]): Optional. List of python packages dependencies of script. @@ -1055,6 +1288,23 @@ def from_local_script( NVIDIA_TESLA_T4 accelerator_count (int): Optional. The number of accelerators to attach to a worker replica. + boot_disk_type (str): + Optional. Type of the boot disk, default is `pd-ssd`. + Valid values: `pd-ssd` (Persistent Disk Solid State Drive) or + `pd-standard` (Persistent Disk Hard Disk Drive). + boot_disk_size_gb (int): + Optional. Size in GB of the boot disk, default is 100GB. + boot disk size must be within the range of [100, 64000]. + reduction_server_replica_count (int): + The number of reduction server replicas, default is 0. + reduction_server_machine_type (str): + Optional. The type of machine to use for reduction server. + reduction_server_container_uri (str): + Optional. The Uri of the reduction server container image. + See details: https://cloud.google.com/vertex-ai/docs/training/distributed-training#reduce_training_time_with_reduction_server + base_output_dir (str): + Optional. GCS output directory of job. If not provided a + timestamped directory in the staging directory will be used. project (str): Optional. Project to run the custom job in. Overrides project set in aiplatform.init. location (str): @@ -1062,6 +1312,16 @@ def from_local_script( credentials (auth_credentials.Credentials): Optional. Custom credentials to use to run call custom job service. Overrides credentials set in aiplatform.init. + labels (Dict[str, str]): + Optional. The labels with user-defined metadata to + organize CustomJobs. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + and examples of labels. encryption_spec_key_name (str): Optional. Customer-managed encryption key name for a CustomJob. If this is set, then all resources @@ -1072,7 +1332,7 @@ def from_local_script( staging_bucket set in aiplatform.init. Raises: - RuntimeError is not staging bucket was set using aiplatfrom.init and a staging + RuntimeError: If staging bucket was not set using aiplatform.init and a staging bucket was not passed in. """ @@ -1086,43 +1346,68 @@ def from_local_script( "should be set using aiplatform.init(staging_bucket='gs://my-bucket')" ) - worker_pool_specs = worker_spec_utils._DistributedTrainingSpec.chief_worker_pool( - replica_count=replica_count, - machine_type=machine_type, - accelerator_count=accelerator_count, - accelerator_type=accelerator_type, - ).pool_specs + if labels: + utils.validate_labels(labels) + + worker_pool_specs = ( + worker_spec_utils._DistributedTrainingSpec.chief_worker_pool( + replica_count=replica_count, + machine_type=machine_type, + accelerator_count=accelerator_count, + accelerator_type=accelerator_type, + boot_disk_type=boot_disk_type, + boot_disk_size_gb=boot_disk_size_gb, + reduction_server_replica_count=reduction_server_replica_count, + reduction_server_machine_type=reduction_server_machine_type, + ).pool_specs + ) python_packager = source_utils._TrainingScriptPythonPackager( script_path=script_path, requirements=requirements ) package_gcs_uri = python_packager.package_and_copy_to_gcs( - gcs_staging_dir=staging_bucket, project=project, credentials=credentials, + gcs_staging_dir=staging_bucket, + project=project, + credentials=credentials, ) - for spec in worker_pool_specs: - spec["python_package_spec"] = { - "executor_image_uri": container_uri, - "python_module": python_packager.module_name, - "package_uris": [package_gcs_uri], - } + for spec_order, spec in enumerate(worker_pool_specs): + + if not spec: + continue - if args: - spec["python_package_spec"]["args"] = args + if ( + spec_order == worker_spec_utils._SPEC_ORDERS["server_spec"] + and reduction_server_replica_count > 0 + ): + spec["container_spec"] = { + "image_uri": reduction_server_container_uri, + } + else: + spec["python_package_spec"] = { + "executor_image_uri": container_uri, + "python_module": python_packager.module_name, + "package_uris": [package_gcs_uri], + } - if environment_variables: - spec["python_package_spec"]["env"] = [ - {"name": key, "value": value} - for key, value in environment_variables.items() - ] + if args: + spec["python_package_spec"]["args"] = args + + if environment_variables: + spec["python_package_spec"]["env"] = [ + {"name": key, "value": value} + for key, value in environment_variables.items() + ] return cls( display_name=display_name, worker_pool_specs=worker_pool_specs, + base_output_dir=base_output_dir, project=project, location=location, credentials=credentials, + labels=labels, encryption_spec_key_name=encryption_spec_key_name, staging_bucket=staging_bucket, ) @@ -1134,8 +1419,10 @@ def run( network: Optional[str] = None, timeout: Optional[int] = None, restart_job_on_worker_restart: bool = False, + enable_web_access: bool = False, tensorboard: Optional[str] = None, sync: bool = True, + create_request_timeout: Optional[float] = None, ) -> None: """Run this configured CustomJob. @@ -1155,8 +1442,12 @@ def run( gets restarted. This feature can be used by distributed training jobs that are not resilient to workers leaving and joining a job. + enable_web_access (bool): + Whether you want Vertex AI to enable interactive shell access + to training containers. + https://cloud.google.com/vertex-ai/docs/training/monitor-debug-interactive-shell tensorboard (str): - Optional. The name of an Vertex AI + Optional. The name of a Vertex AI [Tensorboard][google.cloud.aiplatform.v1beta1.Tensorboard] resource to which this CustomJob will upload Tensorboard logs. Format: @@ -1173,6 +1464,8 @@ def run( sync (bool): Whether to execute this method synchronously. If False, this method will unblock and it will be executed in a concurrent Future. + create_request_timeout (float): + Optional. The timeout for the create request in seconds. """ if service_account: @@ -1188,19 +1481,18 @@ def run( restart_job_on_worker_restart=restart_job_on_worker_restart, ) + if enable_web_access: + self._gca_resource.job_spec.enable_web_access = enable_web_access + if tensorboard: - v1beta1_gca_resource = gca_custom_job_v1beta1.CustomJob() - v1beta1_gca_resource._pb.MergeFromString( - self._gca_resource._pb.SerializeToString() - ) - self._gca_resource = v1beta1_gca_resource self._gca_resource.job_spec.tensorboard = tensorboard _LOGGER.log_create_with_lro(self.__class__) - version = "v1beta1" if tensorboard else "v1" - self._gca_resource = self.api_client.select_version(version).create_custom_job( - parent=self._parent, custom_job=self._gca_resource + self._gca_resource = self.api_client.create_custom_job( + parent=self._parent, + custom_job=self._gca_resource, + timeout=create_request_timeout, ) _LOGGER.log_create_complete_with_getter( @@ -1209,6 +1501,14 @@ def run( _LOGGER.info("View Custom Job:\n%s" % self._dashboard_uri()) + if tensorboard: + _LOGGER.info( + "View Tensorboard:\n%s" + % console_utils.custom_job_tensorboard_console_uri( + tensorboard, self.resource_name + ) + ) + self._block_until_complete() @property @@ -1236,10 +1536,13 @@ class HyperparameterTuningJob(_RunnableJob): _list_method = "list_hyperparameter_tuning_jobs" _cancel_method = "cancel_hyperparameter_tuning_job" _delete_method = "delete_hyperparameter_tuning_job" + _parse_resource_name_method = "parse_hyperparameter_tuning_job_path" + _format_resource_name_method = "hyperparameter_tuning_job_path" _job_type = "training" def __init__( self, + # TODO(b/223262536): Make display_name parameter fully optional in next major release display_name: str, custom_job: CustomJob, metric_spec: Dict[str, str], @@ -1252,6 +1555,7 @@ def __init__( project: Optional[str] = None, location: Optional[str] = None, credentials: Optional[auth_credentials.Credentials] = None, + labels: Optional[Dict[str, str]] = None, encryption_spec_key_name: Optional[str] = None, ): """ @@ -1280,7 +1584,8 @@ def __init__( custom_job = aiplatform.CustomJob( display_name='my_job', - worker_pool_specs=worker_pool_specs + worker_pool_specs=worker_pool_specs, + labels={'my_key': 'my_value'}, ) @@ -1298,6 +1603,7 @@ def __init__( }, max_trial_count=128, parallel_trial_count=8, + labels={'my_key': 'my_value'}, ) hp_job.run() @@ -1318,7 +1624,7 @@ def __init__( Required. Configured CustomJob. The worker pool spec from this custom job applies to the CustomJobs created in all the trials. metric_spec: Dict[str, str] - Required. Dicionary representing metrics to optimize. The dictionary key is the metric_id, + Required. Dictionary representing metrics to optimize. The dictionary key is the metric_id, which is reported by your training job, and the dictionary value is the optimization goal of the metric('minimize' or 'maximize'). example: @@ -1326,7 +1632,7 @@ def __init__( parameter_spec (Dict[str, hyperparameter_tuning._ParameterSpec]): Required. Dictionary representing parameters to optimize. The dictionary key is the metric_id, - which is passed into your training job as a command line key word arguemnt, and the + which is passed into your training job as a command line key word argument, and the dictionary value is the parameter specification of the metric. @@ -1343,7 +1649,7 @@ def __init__( DoubleParameterSpec, IntegerParameterSpec, CategoricalParameterSpace, DiscreteParameterSpec max_trial_count (int): - Reuired. The desired total number of Trials. + Required. The desired total number of Trials. parallel_trial_count (int): Required. The desired number of Trials to run in parallel. max_failed_trial_count (int): @@ -1393,6 +1699,16 @@ def __init__( credentials (auth_credentials.Credentials): Optional. Custom credentials to use to run call HyperparameterTuning service. Overrides credentials set in aiplatform.init. + labels (Dict[str, str]): + Optional. The labels with user-defined metadata to + organize HyperparameterTuningJobs. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + and examples of labels. encryption_spec_key_name (str): Optional. Customer-managed encryption key options for a HyperparameterTuningJob. If this is set, then @@ -1423,18 +1739,71 @@ def __init__( ], ) - self._gca_resource = gca_hyperparameter_tuning_job_compat.HyperparameterTuningJob( - display_name=display_name, - study_spec=study_spec, - max_trial_count=max_trial_count, - parallel_trial_count=parallel_trial_count, - max_failed_trial_count=max_failed_trial_count, - trial_job_spec=copy.deepcopy(custom_job.job_spec), - encryption_spec=initializer.global_config.get_encryption_spec( - encryption_spec_key_name=encryption_spec_key_name - ), + if not display_name: + display_name = self.__class__._generate_display_name() + + self._gca_resource = ( + gca_hyperparameter_tuning_job_compat.HyperparameterTuningJob( + display_name=display_name, + study_spec=study_spec, + max_trial_count=max_trial_count, + parallel_trial_count=parallel_trial_count, + max_failed_trial_count=max_failed_trial_count, + trial_job_spec=copy.deepcopy(custom_job.job_spec), + labels=labels, + encryption_spec=initializer.global_config.get_encryption_spec( + encryption_spec_key_name=encryption_spec_key_name + ), + ) ) + @property + def network(self) -> Optional[str]: + """The full name of the Google Compute Engine + [network](https://cloud.google.com/vpc/docs/vpc#networks) to which this + HyperparameterTuningJob should be peered. + + Takes the format `projects/{project}/global/networks/{network}`. Where + {project} is a project number, as in `12345`, and {network} is a network name. + + Private services access must already be configured for the network. If left + unspecified, the HyperparameterTuningJob is not peered with any network. + """ + self._assert_gca_resource_is_available() + return getattr(self._gca_resource.trial_job_spec, "network") + + def _get_web_access_uris(self) -> Dict[str, Dict[str, str]]: + """Helper method to get the web access uris of the hyperparameter job + + Returns: + (Dict[str, Dict[str, str]]): + Web access uris of the hyperparameter job. + """ + web_access_uris = dict() + for trial in self.trials: + web_access_uris[trial.id] = web_access_uris.get(trial.id, dict()) + for worker, uri in trial.web_access_uris.items(): + web_access_uris[trial.id][worker] = uri + return web_access_uris + + def _log_web_access_uris(self): + """Helper method to log the web access uris of the hyperparameter job""" + + for trial_id, trial_web_access_uris in self._get_web_access_uris().items(): + for worker, uri in trial_web_access_uris.items(): + if uri not in self._logged_web_access_uris: + _LOGGER.info( + "%s %s access the interactive shell terminals for trial - %s:\n%s:\n%s" + % ( + self.__class__.__name__, + self._gca_resource.name, + trial_id, + worker, + uri, + ), + ) + self._logged_web_access_uris.add(uri) + @base.optional_sync() def run( self, @@ -1442,8 +1811,10 @@ def run( network: Optional[str] = None, timeout: Optional[int] = None, # seconds restart_job_on_worker_restart: bool = False, + enable_web_access: bool = False, tensorboard: Optional[str] = None, sync: bool = True, + create_request_timeout: Optional[float] = None, ) -> None: """Run this configured CustomJob. @@ -1463,8 +1834,12 @@ def run( gets restarted. This feature can be used by distributed training jobs that are not resilient to workers leaving and joining a job. + enable_web_access (bool): + Whether you want Vertex AI to enable interactive shell access + to training containers. + https://cloud.google.com/vertex-ai/docs/training/monitor-debug-interactive-shell tensorboard (str): - Optional. The name of an Vertex AI + Optional. The name of a Vertex AI [Tensorboard][google.cloud.aiplatform.v1beta1.Tensorboard] resource to which this CustomJob will upload Tensorboard logs. Format: @@ -1481,6 +1856,8 @@ def run( sync (bool): Whether to execute this method synchronously. If False, this method will unblock and it will be executed in a concurrent Future. + create_request_timeout (float): + Optional. The timeout for the create request in seconds. """ if service_account: @@ -1491,28 +1868,25 @@ def run( if timeout or restart_job_on_worker_restart: duration = duration_pb2.Duration(seconds=timeout) if timeout else None - self._gca_resource.trial_job_spec.scheduling = gca_custom_job_compat.Scheduling( - timeout=duration, - restart_job_on_worker_restart=restart_job_on_worker_restart, + self._gca_resource.trial_job_spec.scheduling = ( + gca_custom_job_compat.Scheduling( + timeout=duration, + restart_job_on_worker_restart=restart_job_on_worker_restart, + ) ) + if enable_web_access: + self._gca_resource.trial_job_spec.enable_web_access = enable_web_access + if tensorboard: - v1beta1_gca_resource = ( - gca_hyperparameter_tuning_job_v1beta1.HyperparameterTuningJob() - ) - v1beta1_gca_resource._pb.MergeFromString( - self._gca_resource._pb.SerializeToString() - ) - self._gca_resource = v1beta1_gca_resource self._gca_resource.trial_job_spec.tensorboard = tensorboard _LOGGER.log_create_with_lro(self.__class__) - version = "v1beta1" if tensorboard else "v1" - self._gca_resource = self.api_client.select_version( - version - ).create_hyperparameter_tuning_job( - parent=self._parent, hyperparameter_tuning_job=self._gca_resource + self._gca_resource = self.api_client.create_hyperparameter_tuning_job( + parent=self._parent, + hyperparameter_tuning_job=self._gca_resource, + timeout=create_request_timeout, ) _LOGGER.log_create_complete_with_getter( @@ -1521,8 +1895,17 @@ def run( _LOGGER.info("View HyperparameterTuningJob:\n%s" % self._dashboard_uri()) + if tensorboard: + _LOGGER.info( + "View Tensorboard:\n%s" + % console_utils.custom_job_tensorboard_console_uri( + tensorboard, self.resource_name + ) + ) + self._block_until_complete() @property def trials(self) -> List[gca_study_compat.Trial]: + self._assert_gca_resource_is_available() return list(self._gca_resource.trials) diff --git a/google/cloud/aiplatform/matching_engine/__init__.py b/google/cloud/aiplatform/matching_engine/__init__.py new file mode 100644 index 0000000000..4616d01bbd --- /dev/null +++ b/google/cloud/aiplatform/matching_engine/__init__.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- + +# Copyright 2022 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 google.cloud.aiplatform.matching_engine.matching_engine_index import ( + MatchingEngineIndex, +) +from google.cloud.aiplatform.matching_engine.matching_engine_index_config import ( + BruteForceConfig as MatchingEngineBruteForceAlgorithmConfig, + MatchingEngineIndexConfig as MatchingEngineIndexConfig, + TreeAhConfig as MatchingEngineTreeAhAlgorithmConfig, +) +from google.cloud.aiplatform.matching_engine.matching_engine_index_endpoint import ( + MatchingEngineIndexEndpoint, +) + +__all__ = ( + "MatchingEngineIndex", + "MatchingEngineIndexEndpoint", + "MatchingEngineIndexConfig", + "MatchingEngineBruteForceAlgorithmConfig", + "MatchingEngineTreeAhAlgorithmConfig", +) diff --git a/google/cloud/aiplatform/matching_engine/_protos/match_service.proto b/google/cloud/aiplatform/matching_engine/_protos/match_service.proto new file mode 100644 index 0000000000..158b0f146a --- /dev/null +++ b/google/cloud/aiplatform/matching_engine/_protos/match_service.proto @@ -0,0 +1,136 @@ +syntax = "proto3"; + +package google.cloud.aiplatform.container.v1beta1; + +import "google/rpc/status.proto"; + +// MatchService is a Google managed service for efficient vector similarity +// search at scale. +service MatchService { + // Returns the nearest neighbors for the query. If it is a sharded + // deployment, calls the other shards and aggregates the responses. + rpc Match(MatchRequest) returns (MatchResponse) {} + + // Returns the nearest neighbors for batch queries. If it is a sharded + // deployment, calls the other shards and aggregates the responses. + rpc BatchMatch(BatchMatchRequest) returns (BatchMatchResponse) {} +} + +// Parameters for a match query. +message MatchRequest { + // The ID of the DeploydIndex that will serve the request. + // This MatchRequest is sent to a specific IndexEndpoint of the Control API, + // as per the IndexEndpoint.network. That IndexEndpoint also has + // IndexEndpoint.deployed_indexes, and each such index has an + // DeployedIndex.id field. + // The value of the field below must equal one of the DeployedIndex.id + // fields of the IndexEndpoint that is being called for this request. + string deployed_index_id = 1; + + // The embedding values. + repeated float float_val = 2; + + // The number of nearest neighbors to be retrieved from database for + // each query. If not set, will use the default from + // the service configuration. + int32 num_neighbors = 3; + + // The list of restricts. + repeated Namespace restricts = 4; + + // Crowding is a constraint on a neighbor list produced by nearest neighbor + // search requiring that no more than some value k' of the k neighbors + // returned have the same value of crowding_attribute. + // It's used for improving result diversity. + // This field is the maximum number of matches with the same crowding tag. + int32 per_crowding_attribute_num_neighbors = 5; + + // The number of neighbors to find via approximate search before + // exact reordering is performed. If not set, the default value from scam + // config is used; if set, this value must be > 0. + int32 approx_num_neighbors = 6; + + // The fraction of the number of leaves to search, set at query time allows + // user to tune search performance. This value increase result in both search + // accuracy and latency increase. The value should be between 0.0 and 1.0. If + // not set or set to 0.0, query uses the default value specified in + // NearestNeighborSearchConfig.TreeAHConfig.leaf_nodes_to_search_percent. + int32 leaf_nodes_to_search_percent_override = 7; +} + +// Response of a match query. +message MatchResponse { + message Neighbor { + // The ids of the matches. + string id = 1; + + // The distances of the matches. + double distance = 2; + } + // All its neighbors. + repeated Neighbor neighbor = 1; +} + +// Parameters for a batch match query. +message BatchMatchRequest { + // Batched requests against one index. + message BatchMatchRequestPerIndex { + // The ID of the DeploydIndex that will serve the request. + string deployed_index_id = 1; + + // The requests against the index identified by the above deployed_index_id. + repeated MatchRequest requests = 2; + + // Selects the optimal batch size to use for low-level batching. Queries + // within each low level batch are executed sequentially while low level + // batches are executed in parallel. + // This field is optional, defaults to 0 if not set. A non-positive number + // disables low level batching, i.e. all queries are executed sequentially. + int32 low_level_batch_size = 3; + } + + // The batch requests grouped by indexes. + repeated BatchMatchRequestPerIndex requests = 1; +} + +// Response of a batch match query. +message BatchMatchResponse { + // Batched responses for one index. + message BatchMatchResponsePerIndex { + // The ID of the DeployedIndex that produced the responses. + string deployed_index_id = 1; + + // The match responses produced by the index identified by the above + // deployed_index_id. This field is set only when the query against that + // index succeed. + repeated MatchResponse responses = 2; + + // The status of response for the batch query identified by the above + // deployed_index_id. + google.rpc.Status status = 3; + } + + // The batched responses grouped by indexes. + repeated BatchMatchResponsePerIndex responses = 1; +} + +// Namespace specifies the rules for determining the datapoints that are +// eligible for each matching query, overall query is an AND across namespaces. +message Namespace { + // The string name of the namespace that this proto is specifying, + // such as "color", "shape", "geo", or "tags". + string name = 1; + + // The allowed tokens in the namespace. + repeated string allow_tokens = 2; + + // The denied tokens in the namespace. + // The denied tokens have exactly the same format as the token fields, but + // represents a negation. When a token is denied, then matches will be + // excluded whenever the other datapoint has that token. + // + // For example, if a query specifies {color: red, blue, !purple}, then that + // query will match datapoints that are red or blue, but if those points are + // also purple, then they will be excluded even if they are red/blue. + repeated string deny_tokens = 3; +} diff --git a/google/cloud/aiplatform/matching_engine/_protos/match_service_pb2.py b/google/cloud/aiplatform/matching_engine/_protos/match_service_pb2.py new file mode 100644 index 0000000000..6b3ab988b2 --- /dev/null +++ b/google/cloud/aiplatform/matching_engine/_protos/match_service_pb2.py @@ -0,0 +1,158 @@ +# -*- coding: utf-8 -*- + +# Copyright 2022 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. + +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: google/cloud/aiplatform/matching_engine/_protos/match_service.proto +"""Generated protocol buffer code.""" +from google.protobuf import descriptor as _descriptor +from google.protobuf import descriptor_pool as _descriptor_pool +from google.protobuf import message as _message +from google.protobuf import reflection as _reflection +from google.protobuf import symbol_database as _symbol_database + +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + +from google.rpc import status_pb2 as google_dot_rpc_dot_status__pb2 + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile( + b'\nCgoogle/cloud/aiplatform/matching_engine/_protos/match_service.proto\x12)google.cloud.aiplatform.container.v1beta1\x1a\x17google/rpc/status.proto"\x97\x02\n\x0cMatchRequest\x12\x19\n\x11\x64\x65ployed_index_id\x18\x01 \x01(\t\x12\x11\n\tfloat_val\x18\x02 \x03(\x02\x12\x15\n\rnum_neighbors\x18\x03 \x01(\x05\x12G\n\trestricts\x18\x04 \x03(\x0b\x32\x34.google.cloud.aiplatform.container.v1beta1.Namespace\x12,\n$per_crowding_attribute_num_neighbors\x18\x05 \x01(\x05\x12\x1c\n\x14\x61pprox_num_neighbors\x18\x06 \x01(\x05\x12-\n%leaf_nodes_to_search_percent_override\x18\x07 \x01(\x05"\x8e\x01\n\rMatchResponse\x12S\n\x08neighbor\x18\x01 \x03(\x0b\x32\x41.google.cloud.aiplatform.container.v1beta1.MatchResponse.Neighbor\x1a(\n\x08Neighbor\x12\n\n\x02id\x18\x01 \x01(\t\x12\x10\n\x08\x64istance\x18\x02 \x01(\x01"\x9f\x02\n\x11\x42\x61tchMatchRequest\x12h\n\x08requests\x18\x01 \x03(\x0b\x32V.google.cloud.aiplatform.container.v1beta1.BatchMatchRequest.BatchMatchRequestPerIndex\x1a\x9f\x01\n\x19\x42\x61tchMatchRequestPerIndex\x12\x19\n\x11\x64\x65ployed_index_id\x18\x01 \x01(\t\x12I\n\x08requests\x18\x02 \x03(\x0b\x32\x37.google.cloud.aiplatform.container.v1beta1.MatchRequest\x12\x1c\n\x14low_level_batch_size\x18\x03 \x01(\x05"\xac\x02\n\x12\x42\x61tchMatchResponse\x12k\n\tresponses\x18\x01 \x03(\x0b\x32X.google.cloud.aiplatform.container.v1beta1.BatchMatchResponse.BatchMatchResponsePerIndex\x1a\xa8\x01\n\x1a\x42\x61tchMatchResponsePerIndex\x12\x19\n\x11\x64\x65ployed_index_id\x18\x01 \x01(\t\x12K\n\tresponses\x18\x02 \x03(\x0b\x32\x38.google.cloud.aiplatform.container.v1beta1.MatchResponse\x12"\n\x06status\x18\x03 \x01(\x0b\x32\x12.google.rpc.Status"D\n\tNamespace\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x14\n\x0c\x61llow_tokens\x18\x02 \x03(\t\x12\x13\n\x0b\x64\x65ny_tokens\x18\x03 \x03(\t2\x9a\x02\n\x0cMatchService\x12|\n\x05Match\x12\x37.google.cloud.aiplatform.container.v1beta1.MatchRequest\x1a\x38.google.cloud.aiplatform.container.v1beta1.MatchResponse"\x00\x12\x8b\x01\n\nBatchMatch\x12<.google.cloud.aiplatform.container.v1beta1.BatchMatchRequest\x1a=.google.cloud.aiplatform.container.v1beta1.BatchMatchResponse"\x00\x62\x06proto3' +) + + +_MATCHREQUEST = DESCRIPTOR.message_types_by_name["MatchRequest"] +_MATCHRESPONSE = DESCRIPTOR.message_types_by_name["MatchResponse"] +_MATCHRESPONSE_NEIGHBOR = _MATCHRESPONSE.nested_types_by_name["Neighbor"] +_BATCHMATCHREQUEST = DESCRIPTOR.message_types_by_name["BatchMatchRequest"] +_BATCHMATCHREQUEST_BATCHMATCHREQUESTPERINDEX = _BATCHMATCHREQUEST.nested_types_by_name[ + "BatchMatchRequestPerIndex" +] +_BATCHMATCHRESPONSE = DESCRIPTOR.message_types_by_name["BatchMatchResponse"] +_BATCHMATCHRESPONSE_BATCHMATCHRESPONSEPERINDEX = ( + _BATCHMATCHRESPONSE.nested_types_by_name["BatchMatchResponsePerIndex"] +) +_NAMESPACE = DESCRIPTOR.message_types_by_name["Namespace"] +MatchRequest = _reflection.GeneratedProtocolMessageType( + "MatchRequest", + (_message.Message,), + { + "DESCRIPTOR": _MATCHREQUEST, + "__module__": "google.cloud.aiplatform.matching_engine._protos.match_service_pb2" + # @@protoc_insertion_point(class_scope:google.cloud.aiplatform.container.v1beta1.MatchRequest) + }, +) +_sym_db.RegisterMessage(MatchRequest) + +MatchResponse = _reflection.GeneratedProtocolMessageType( + "MatchResponse", + (_message.Message,), + { + "Neighbor": _reflection.GeneratedProtocolMessageType( + "Neighbor", + (_message.Message,), + { + "DESCRIPTOR": _MATCHRESPONSE_NEIGHBOR, + "__module__": "google.cloud.aiplatform.matching_engine._protos.match_service_pb2" + # @@protoc_insertion_point(class_scope:google.cloud.aiplatform.container.v1beta1.MatchResponse.Neighbor) + }, + ), + "DESCRIPTOR": _MATCHRESPONSE, + "__module__": "google.cloud.aiplatform.matching_engine._protos.match_service_pb2" + # @@protoc_insertion_point(class_scope:google.cloud.aiplatform.container.v1beta1.MatchResponse) + }, +) +_sym_db.RegisterMessage(MatchResponse) +_sym_db.RegisterMessage(MatchResponse.Neighbor) + +BatchMatchRequest = _reflection.GeneratedProtocolMessageType( + "BatchMatchRequest", + (_message.Message,), + { + "BatchMatchRequestPerIndex": _reflection.GeneratedProtocolMessageType( + "BatchMatchRequestPerIndex", + (_message.Message,), + { + "DESCRIPTOR": _BATCHMATCHREQUEST_BATCHMATCHREQUESTPERINDEX, + "__module__": "google.cloud.aiplatform.matching_engine._protos.match_service_pb2" + # @@protoc_insertion_point(class_scope:google.cloud.aiplatform.container.v1beta1.BatchMatchRequest.BatchMatchRequestPerIndex) + }, + ), + "DESCRIPTOR": _BATCHMATCHREQUEST, + "__module__": "google.cloud.aiplatform.matching_engine._protos.match_service_pb2" + # @@protoc_insertion_point(class_scope:google.cloud.aiplatform.container.v1beta1.BatchMatchRequest) + }, +) +_sym_db.RegisterMessage(BatchMatchRequest) +_sym_db.RegisterMessage(BatchMatchRequest.BatchMatchRequestPerIndex) + +BatchMatchResponse = _reflection.GeneratedProtocolMessageType( + "BatchMatchResponse", + (_message.Message,), + { + "BatchMatchResponsePerIndex": _reflection.GeneratedProtocolMessageType( + "BatchMatchResponsePerIndex", + (_message.Message,), + { + "DESCRIPTOR": _BATCHMATCHRESPONSE_BATCHMATCHRESPONSEPERINDEX, + "__module__": "google.cloud.aiplatform.matching_engine._protos.match_service_pb2" + # @@protoc_insertion_point(class_scope:google.cloud.aiplatform.container.v1beta1.BatchMatchResponse.BatchMatchResponsePerIndex) + }, + ), + "DESCRIPTOR": _BATCHMATCHRESPONSE, + "__module__": "google.cloud.aiplatform.matching_engine._protos.match_service_pb2" + # @@protoc_insertion_point(class_scope:google.cloud.aiplatform.container.v1beta1.BatchMatchResponse) + }, +) +_sym_db.RegisterMessage(BatchMatchResponse) +_sym_db.RegisterMessage(BatchMatchResponse.BatchMatchResponsePerIndex) + +Namespace = _reflection.GeneratedProtocolMessageType( + "Namespace", + (_message.Message,), + { + "DESCRIPTOR": _NAMESPACE, + "__module__": "google.cloud.aiplatform.matching_engine._protos.match_service_pb2" + # @@protoc_insertion_point(class_scope:google.cloud.aiplatform.container.v1beta1.Namespace) + }, +) +_sym_db.RegisterMessage(Namespace) + +_MATCHSERVICE = DESCRIPTOR.services_by_name["MatchService"] +if _descriptor._USE_C_DESCRIPTORS == False: + + DESCRIPTOR._options = None + _MATCHREQUEST._serialized_start = 140 + _MATCHREQUEST._serialized_end = 419 + _MATCHRESPONSE._serialized_start = 422 + _MATCHRESPONSE._serialized_end = 564 + _MATCHRESPONSE_NEIGHBOR._serialized_start = 524 + _MATCHRESPONSE_NEIGHBOR._serialized_end = 564 + _BATCHMATCHREQUEST._serialized_start = 567 + _BATCHMATCHREQUEST._serialized_end = 854 + _BATCHMATCHREQUEST_BATCHMATCHREQUESTPERINDEX._serialized_start = 695 + _BATCHMATCHREQUEST_BATCHMATCHREQUESTPERINDEX._serialized_end = 854 + _BATCHMATCHRESPONSE._serialized_start = 857 + _BATCHMATCHRESPONSE._serialized_end = 1157 + _BATCHMATCHRESPONSE_BATCHMATCHRESPONSEPERINDEX._serialized_start = 989 + _BATCHMATCHRESPONSE_BATCHMATCHRESPONSEPERINDEX._serialized_end = 1157 + _NAMESPACE._serialized_start = 1159 + _NAMESPACE._serialized_end = 1227 + _MATCHSERVICE._serialized_start = 1230 + _MATCHSERVICE._serialized_end = 1512 +# @@protoc_insertion_point(module_scope) diff --git a/google/cloud/aiplatform/matching_engine/_protos/match_service_pb2_grpc.py b/google/cloud/aiplatform/matching_engine/_protos/match_service_pb2_grpc.py new file mode 100644 index 0000000000..2c0c14f8ed --- /dev/null +++ b/google/cloud/aiplatform/matching_engine/_protos/match_service_pb2_grpc.py @@ -0,0 +1,166 @@ +# -*- coding: utf-8 -*- + +# Copyright 2022 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. +# + +# Copyright 2022 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. + +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! + +"""Client and server classes corresponding to protobuf-defined services.""" +from google.cloud.aiplatform.matching_engine._protos import match_service_pb2 + +import grpc + + +class MatchServiceStub(object): + """MatchService is a Google managed service for efficient vector similarity + search at scale. + """ + + def __init__(self, channel): + """Constructor. + + Args: + channel: A grpc.Channel. + """ + self.Match = channel.unary_unary( + "/google.cloud.aiplatform.container.v1beta1.MatchService/Match", + request_serializer=match_service_pb2.MatchRequest.SerializeToString, + response_deserializer=match_service_pb2.MatchResponse.FromString, + ) + self.BatchMatch = channel.unary_unary( + "/google.cloud.aiplatform.container.v1beta1.MatchService/BatchMatch", + request_serializer=match_service_pb2.BatchMatchRequest.SerializeToString, + response_deserializer=match_service_pb2.BatchMatchResponse.FromString, + ) + + +class MatchServiceServicer(object): + """MatchService is a Google managed service for efficient vector similarity + search at scale. + """ + + def Match(self, request, context): + """Returns the nearest neighbors for the query. If it is a sharded + deployment, calls the other shards and aggregates the responses. + """ + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details("Method not implemented!") + raise NotImplementedError("Method not implemented!") + + def BatchMatch(self, request, context): + """Returns the nearest neighbors for batch queries. If it is a sharded + deployment, calls the other shards and aggregates the responses. + """ + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details("Method not implemented!") + raise NotImplementedError("Method not implemented!") + + +def add_MatchServiceServicer_to_server(servicer, server): + rpc_method_handlers = { + "Match": grpc.unary_unary_rpc_method_handler( + servicer.Match, + request_deserializer=match_service_pb2.MatchRequest.FromString, + response_serializer=match_service_pb2.MatchResponse.SerializeToString, + ), + "BatchMatch": grpc.unary_unary_rpc_method_handler( + servicer.BatchMatch, + request_deserializer=match_service_pb2.BatchMatchRequest.FromString, + response_serializer=match_service_pb2.BatchMatchResponse.SerializeToString, + ), + } + generic_handler = grpc.method_handlers_generic_handler( + "google.cloud.aiplatform.container.v1beta1.MatchService", rpc_method_handlers + ) + server.add_generic_rpc_handlers((generic_handler,)) + + +# This class is part of an EXPERIMENTAL API. +class MatchService(object): + """MatchService is a Google managed service for efficient vector similarity + search at scale. + """ + + @staticmethod + def Match( + request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None, + ): + return grpc.experimental.unary_unary( + request, + target, + "/google.cloud.aiplatform.container.v1beta1.MatchService/Match", + match_service_pb2.MatchRequest.SerializeToString, + match_service_pb2.MatchResponse.FromString, + options, + channel_credentials, + insecure, + call_credentials, + compression, + wait_for_ready, + timeout, + metadata, + ) + + @staticmethod + def BatchMatch( + request, + target, + options=(), + channel_credentials=None, + call_credentials=None, + insecure=False, + compression=None, + wait_for_ready=None, + timeout=None, + metadata=None, + ): + return grpc.experimental.unary_unary( + request, + target, + "/google.cloud.aiplatform.container.v1beta1.MatchService/BatchMatch", + match_service_pb2.BatchMatchRequest.SerializeToString, + match_service_pb2.BatchMatchResponse.FromString, + options, + channel_credentials, + insecure, + call_credentials, + compression, + wait_for_ready, + timeout, + metadata, + ) diff --git a/google/cloud/aiplatform/matching_engine/matching_engine_index.py b/google/cloud/aiplatform/matching_engine/matching_engine_index.py new file mode 100644 index 0000000000..d382a126f1 --- /dev/null +++ b/google/cloud/aiplatform/matching_engine/matching_engine_index.py @@ -0,0 +1,606 @@ +# -*- coding: utf-8 -*- + +# Copyright 2022 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 typing import Dict, List, Optional, Sequence, Tuple + +from google.auth import credentials as auth_credentials +from google.protobuf import field_mask_pb2 +from google.cloud.aiplatform import base +from google.cloud.aiplatform.compat.types import ( + matching_engine_deployed_index_ref as gca_matching_engine_deployed_index_ref, + matching_engine_index as gca_matching_engine_index, +) +from google.cloud.aiplatform import initializer +from google.cloud.aiplatform.matching_engine import matching_engine_index_config +from google.cloud.aiplatform import utils + +_LOGGER = base.Logger(__name__) + + +class MatchingEngineIndex(base.VertexAiResourceNounWithFutureManager): + """Matching Engine index resource for Vertex AI.""" + + client_class = utils.IndexClientWithOverride + + _resource_noun = "indexes" + _getter_method = "get_index" + _list_method = "list_indexes" + _delete_method = "delete_index" + _parse_resource_name_method = "parse_index_path" + _format_resource_name_method = "index_path" + + def __init__( + self, + index_name: str, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ): + """Retrieves an existing index given an index name or ID. + + Example Usage: + + my_index = aiplatform.MatchingEngineIndex( + index_name='projects/123/locations/us-central1/indexes/my_index_id' + ) + or + my_index = aiplatform.MatchingEngineIndex( + index_name='my_index_id' + ) + + Args: + index_name (str): + Required. A fully-qualified index resource name or a index ID. + Example: "projects/123/locations/us-central1/indexes/my_index_id" + or "my_index_id" when project and location are initialized or passed. + project (str): + Optional. Project to retrieve index from. If not set, project + set in aiplatform.init will be used. + location (str): + Optional. Location to retrieve index from. If not set, location + set in aiplatform.init will be used. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to retrieve this Index. Overrides + credentials set in aiplatform.init. + """ + + super().__init__( + project=project, + location=location, + credentials=credentials, + resource_name=index_name, + ) + self._gca_resource = self._get_gca_resource(resource_name=index_name) + + @property + def description(self) -> str: + """Description of the index.""" + self._assert_gca_resource_is_available() + return self._gca_resource.description + + @classmethod + @base.optional_sync() + def _create( + cls, + display_name: str, + contents_delta_uri: str, + config: matching_engine_index_config.MatchingEngineIndexConfig, + description: Optional[str] = None, + labels: Optional[Dict[str, str]] = None, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + sync: bool = True, + ) -> "MatchingEngineIndex": + """Creates a MatchingEngineIndex resource. + + Args: + display_name (str): + Required. The display name of the Index. + The name can be up to 128 characters long and + can be consist of any UTF-8 characters. + contents_delta_uri (str): + Required. Allows inserting, updating or deleting the contents of the Matching Engine Index. + The string must be a valid Google Cloud Storage directory path. If this + field is set when calling IndexService.UpdateIndex, then no other + Index field can be also updated as part of the same call. + The expected structure and format of the files this URI points to is + described at + https://docs.google.com/document/d/12DLVB6Nq6rdv8grxfBsPhUA283KWrQ9ZenPBp0zUC30 + config (matching_engine_index_config.MatchingEngineIndexConfig): + Required. The configuration with regard to the algorithms used for efficient search. + description (str): + Optional. The description of the Index. + labels (Dict[str, str]): + Optional. The labels with user-defined + metadata to organize your Index. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + on and examples of labels. No more than 64 user + labels can be associated with one + Index(System labels are excluded)." + System reserved label keys are prefixed with + "aiplatform.googleapis.com/" and are immutable. + project (str): + Optional. Project to create EntityType in. If not set, project + set in aiplatform.init will be used. + location (str): + Optional. Location to create EntityType in. If not set, location + set in aiplatform.init will be used. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to create EntityTypes. Overrides + credentials set in aiplatform.init. + request_metadata (Sequence[Tuple[str, str]]): + Optional. Strings which should be sent along with the request as metadata. + encryption_spec (str): + Optional. Customer-managed encryption key + spec for data storage. If set, both of the + online and offline data storage will be secured + by this key. + sync (bool): + Optional. Whether to execute this creation synchronously. If False, this method + will be executed in concurrent Future and any downstream object will + be immediately returned and synced when the Future has completed. + + Returns: + MatchingEngineIndex - Index resource object + + """ + gapic_index = gca_matching_engine_index.Index( + display_name=display_name, + description=description, + metadata={ + "config": config.as_dict(), + "contentsDeltaUri": contents_delta_uri, + }, + ) + + if labels: + utils.validate_labels(labels) + gapic_index.labels = labels + + api_client = cls._instantiate_client(location=location, credentials=credentials) + + create_lro = api_client.create_index( + parent=initializer.global_config.common_location_path( + project=project, location=location + ), + index=gapic_index, + metadata=request_metadata, + ) + + _LOGGER.log_create_with_lro(cls, create_lro) + + created_index = create_lro.result() + + _LOGGER.log_create_complete(cls, created_index, "index") + + index_obj = cls( + index_name=created_index.name, + project=project, + location=location, + credentials=credentials, + ) + + return index_obj + + def update_metadata( + self, + display_name: Optional[str] = None, + description: Optional[str] = None, + labels: Optional[Dict[str, str]] = None, + request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + ) -> "MatchingEngineIndex": + """Updates the metadata for this index. + + Args: + display_name (str): + Optional. The display name of the Index. + The name can be up to 128 characters long and + can be consist of any UTF-8 characters. + description (str): + Optional. The description of the Index. + labels (Dict[str, str]): + Optional. The labels with user-defined + metadata to organize your Indexs. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + on and examples of labels. No more than 64 user + labels can be associated with one Index + (System labels are excluded)." + System reserved label keys are prefixed with + "aiplatform.googleapis.com/" and are immutable. + request_metadata (Sequence[Tuple[str, str]]): + Optional. Strings which should be sent along with the request as metadata. + + Returns: + MatchingEngineIndex - The updated index resource object. + """ + + self.wait() + + update_mask = list() + + if labels: + utils.validate_labels(labels) + update_mask.append("labels") + + if display_name is not None: + update_mask.append("display_name") + + if description is not None: + update_mask.append("description") + + update_mask = field_mask_pb2.FieldMask(paths=update_mask) + + gapic_index = gca_matching_engine_index.Index( + name=self.resource_name, + display_name=display_name, + description=description, + labels=labels, + ) + + _LOGGER.log_action_start_against_resource( + "Updating", + "index", + self, + ) + + update_lro = self.api_client.update_index( + index=gapic_index, + update_mask=update_mask, + metadata=request_metadata, + ) + + _LOGGER.log_action_started_against_resource_with_lro( + "Update", "index", self.__class__, update_lro + ) + + self._gca_resource = update_lro.result() + + _LOGGER.log_action_completed_against_resource("index", "Updated", self) + + return self + + def update_embeddings( + self, + contents_delta_uri: str, + is_complete_overwrite: Optional[bool] = None, + request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + ) -> "MatchingEngineIndex": + """Updates the embeddings for this index. + + Args: + contents_delta_uri (str): + Required. Allows inserting, updating or deleting the contents of the Matching Engine Index. + The string must be a valid Google Cloud Storage directory path. If this + field is set when calling IndexService.UpdateIndex, then no other + Index field can be also updated as part of the same call. + The expected structure and format of the files this URI points to is + described at + https://docs.google.com/document/d/12DLVB6Nq6rdv8grxfBsPhUA283KWrQ9ZenPBp0zUC30 + is_complete_overwrite (bool): + Optional. If this field is set together with contentsDeltaUri when calling IndexService.UpdateIndex, + then existing content of the Index will be replaced by the data from the contentsDeltaUri. + request_metadata (Sequence[Tuple[str, str]]): + Optional. Strings which should be sent along with the request as metadata. + + Returns: + MatchingEngineIndex - The updated index resource object. + """ + + self.wait() + + update_mask = list() + + if contents_delta_uri or is_complete_overwrite: + update_mask.append("metadata") + + update_mask = field_mask_pb2.FieldMask(paths=update_mask) + + gapic_index = gca_matching_engine_index.Index( + name=self.resource_name, + metadata={ + "contentsDeltaUri": contents_delta_uri, + "isCompleteOverwrite": is_complete_overwrite, + }, + ) + + _LOGGER.log_action_start_against_resource( + "Updating", + "index", + self, + ) + + update_lro = self.api_client.update_index( + index=gapic_index, + update_mask=update_mask, + metadata=request_metadata, + ) + + _LOGGER.log_action_started_against_resource_with_lro( + "Update", "index", self.__class__, update_lro + ) + + self._gca_resource = update_lro.result() + + _LOGGER.log_action_completed_against_resource("index", "Updated", self) + + return self + + @property + def deployed_indexes( + self, + ) -> List[gca_matching_engine_deployed_index_ref.DeployedIndexRef]: + """Returns a list of deployed index references that originate from this index. + + Returns: + List[gca_matching_engine_deployed_index_ref.DeployedIndexRef] - Deployed index references + """ + + self.wait() + + return self._gca_resource.deployed_indexes + + @classmethod + def create_tree_ah_index( + cls, + display_name: str, + contents_delta_uri: str, + dimensions: int, + approximate_neighbors_count: int, + leaf_node_embedding_count: Optional[int] = None, + leaf_nodes_to_search_percent: Optional[float] = None, + distance_measure_type: Optional[ + matching_engine_index_config.DistanceMeasureType + ] = None, + description: Optional[str] = None, + labels: Optional[Dict[str, str]] = None, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + sync: bool = True, + ) -> "MatchingEngineIndex": + """Creates a MatchingEngineIndex resource that uses the tree-AH algorithm. + + Example Usage: + + my_index = aiplatform.Index.create_tree_ah_index( + display_name="my_display_name", + contents_delta_uri="gs://my_bucket/embeddings", + dimensions=1, + approximate_neighbors_count=150, + distance_measure_type="SQUARED_L2_DISTANCE", + leaf_node_embedding_count=100, + leaf_nodes_to_search_percent=50, + description="my description", + labels={ "label_name": "label_value" }, + ) + + Args: + display_name (str): + Required. The display name of the Index. + The name can be up to 128 characters long and + can be consist of any UTF-8 characters. + contents_delta_uri (str): + Required. Allows inserting, updating or deleting the contents of the Matching Engine Index. + The string must be a valid Google Cloud Storage directory path. If this + field is set when calling IndexService.UpdateIndex, then no other + Index field can be also updated as part of the same call. + The expected structure and format of the files this URI points to is + described at + https://docs.google.com/document/d/12DLVB6Nq6rdv8grxfBsPhUA283KWrQ9ZenPBp0zUC30 + dimensions (int): + Required. The number of dimensions of the input vectors. + approximate_neighbors_count (int): + Required. The default number of neighbors to find via approximate search before exact reordering is + performed. Exact reordering is a procedure where results returned by an + approximate search algorithm are reordered via a more expensive distance computation. + leaf_node_embedding_count (int): + Optional. Number of embeddings on each leaf node. The default value is 1000 if not set. + leaf_nodes_to_search_percent (float): + Optional. The default percentage of leaf nodes that any query may be searched. Must be in + range 1-100, inclusive. The default value is 10 (means 10%) if not set. + distance_measure_type (matching_engine_index_config.DistanceMeasureType): + Optional. The distance measure used in nearest neighbor search. + description (str): + Optional. The description of the Index. + labels (Dict[str, str]): + Optional. The labels with user-defined + metadata to organize your Index. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + on and examples of labels. No more than 64 user + labels can be associated with one + Index(System labels are excluded)." + System reserved label keys are prefixed with + "aiplatform.googleapis.com/" and are immutable. + project (str): + Optional. Project to create EntityType in. If not set, project + set in aiplatform.init will be used. + location (str): + Optional. Location to create EntityType in. If not set, location + set in aiplatform.init will be used. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to create EntityTypes. Overrides + credentials set in aiplatform.init. + request_metadata (Sequence[Tuple[str, str]]): + Optional. Strings which should be sent along with the request as metadata. + encryption_spec (str): + Optional. Customer-managed encryption key + spec for data storage. If set, both of the + online and offline data storage will be secured + by this key. + sync (bool): + Optional. Whether to execute this creation synchronously. If False, this method + will be executed in concurrent Future and any downstream object will + be immediately returned and synced when the Future has completed. + + Returns: + MatchingEngineIndex - Index resource object + + """ + + algorithm_config = matching_engine_index_config.TreeAhConfig( + leaf_node_embedding_count=leaf_node_embedding_count, + leaf_nodes_to_search_percent=leaf_nodes_to_search_percent, + ) + + config = matching_engine_index_config.MatchingEngineIndexConfig( + dimensions=dimensions, + algorithm_config=algorithm_config, + approximate_neighbors_count=approximate_neighbors_count, + distance_measure_type=distance_measure_type, + ) + + return cls._create( + display_name=display_name, + contents_delta_uri=contents_delta_uri, + config=config, + description=description, + labels=labels, + project=project, + location=location, + credentials=credentials, + request_metadata=request_metadata, + sync=sync, + ) + + @classmethod + def create_brute_force_index( + cls, + display_name: str, + contents_delta_uri: str, + dimensions: int, + distance_measure_type: Optional[ + matching_engine_index_config.DistanceMeasureType + ] = None, + description: Optional[str] = None, + labels: Optional[Dict[str, str]] = None, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + sync: bool = True, + ) -> "MatchingEngineIndex": + """Creates a MatchingEngineIndex resource that uses the brute force algorithm. + + Example Usage: + + my_index = aiplatform.Index.create_brute_force_index( + display_name="my_display_name", + contents_delta_uri="gs://my_bucket/embeddings", + dimensions=1, + approximate_neighbors_count=150, + distance_measure_type="SQUARED_L2_DISTANCE", + description="my description", + labels={ "label_name": "label_value" }, + ) + + Args: + display_name (str): + Required. The display name of the Index. + The name can be up to 128 characters long and + can be consist of any UTF-8 characters. + contents_delta_uri (str): + Required. Allows inserting, updating or deleting the contents of the Matching Engine Index. + The string must be a valid Google Cloud Storage directory path. If this + field is set when calling IndexService.UpdateIndex, then no other + Index field can be also updated as part of the same call. + The expected structure and format of the files this URI points to is + described at + https://docs.google.com/document/d/12DLVB6Nq6rdv8grxfBsPhUA283KWrQ9ZenPBp0zUC30 + dimensions (int): + Required. The number of dimensions of the input vectors. + distance_measure_type (matching_engine_index_config.DistanceMeasureType): + Optional. The distance measure used in nearest neighbor search. + description (str): + Optional. The description of the Index. + labels (Dict[str, str]): + Optional. The labels with user-defined + metadata to organize your Index. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + on and examples of labels. No more than 64 user + labels can be associated with one + Index(System labels are excluded)." + System reserved label keys are prefixed with + "aiplatform.googleapis.com/" and are immutable. + project (str): + Optional. Project to create EntityType in. If not set, project + set in aiplatform.init will be used. + location (str): + Optional. Location to create EntityType in. If not set, location + set in aiplatform.init will be used. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to create EntityTypes. Overrides + credentials set in aiplatform.init. + request_metadata (Sequence[Tuple[str, str]]): + Optional. Strings which should be sent along with the request as metadata. + encryption_spec (str): + Optional. Customer-managed encryption key + spec for data storage. If set, both of the + online and offline data storage will be secured + by this key. + sync (bool): + Optional. Whether to execute this creation synchronously. If False, this method + will be executed in concurrent Future and any downstream object will + be immediately returned and synced when the Future has completed. + + Returns: + MatchingEngineIndex - Index resource object + + """ + + algorithm_config = matching_engine_index_config.BruteForceConfig() + + config = matching_engine_index_config.MatchingEngineIndexConfig( + dimensions=dimensions, + algorithm_config=algorithm_config, + distance_measure_type=distance_measure_type, + ) + + return cls._create( + display_name=display_name, + contents_delta_uri=contents_delta_uri, + config=config, + description=description, + labels=labels, + project=project, + location=location, + credentials=credentials, + request_metadata=request_metadata, + sync=sync, + ) diff --git a/google/cloud/aiplatform/matching_engine/matching_engine_index_config.py b/google/cloud/aiplatform/matching_engine/matching_engine_index_config.py new file mode 100644 index 0000000000..d0552f8de1 --- /dev/null +++ b/google/cloud/aiplatform/matching_engine/matching_engine_index_config.py @@ -0,0 +1,142 @@ +# -*- coding: utf-8 -*- + +# Copyright 2022 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. +# + +import abc +import enum +from dataclasses import dataclass +from typing import Any, Dict, Optional + + +# This file mirrors the configuration options as defined in gs://google-cloud-aiplatform/schema/matchingengine/metadata/nearest_neighbor_search_1.0.0.yaml +class DistanceMeasureType(enum.Enum): + """The distance measure used in nearest neighbor search.""" + + # Dot Product Distance. Defined as a negative of the dot product + DOT_PRODUCT_DISTANCE = "DOT_PRODUCT_DISTANCE" + # Euclidean (L_2) Distance + SQUARED_L2_DISTANCE = "SQUARED_L2_DISTANCE" + # Manhattan (L_1) Distance + L1_DISTANCE = "L1_DISTANCE" + # Cosine Distance. Defined as 1 - cosine similarity. + COSINE_DISTANCE = "COSINE_DISTANCE" + + +class FeatureNormType(enum.Enum): + """Type of normalization to be carried out on each vector.""" + + # Unit L2 normalization type. + UNIT_L2_NORM = "UNIT_L2_NORM" + # No normalization type is specified. + NONE = "NONE" + + +class AlgorithmConfig(abc.ABC): + """Base class for configuration options for matching algorithm.""" + + def as_dict(self) -> Dict: + """Returns the configuration as a dictionary. + + Returns: + Dict[str, Any] + """ + pass + + +@dataclass +class TreeAhConfig(AlgorithmConfig): + """Configuration options for using the tree-AH algorithm (Shallow tree + Asymmetric Hashing). + Please refer to this paper for more details: https://arxiv.org/abs/1908.10396 + + Args: + leaf_node_embedding_count (int): + Optional. Number of embeddings on each leaf node. The default value is 1000 if not set. + leaf_nodes_to_search_percent (float): + The default percentage of leaf nodes that any query may be searched. Must be in + range 1-100, inclusive. The default value is 10 (means 10%) if not set. + """ + + leaf_node_embedding_count: Optional[int] = None + leaf_nodes_to_search_percent: Optional[float] = None + + def as_dict(self) -> Dict: + """Returns the configuration as a dictionary. + + Returns: + Dict[str, Any] + """ + + return { + "treeAhConfig": { + "leafNodeEmbeddingCount": self.leaf_node_embedding_count, + "leafNodesToSearchPercent": self.leaf_nodes_to_search_percent, + } + } + + +@dataclass +class BruteForceConfig(AlgorithmConfig): + """Configuration options for using brute force search, which simply + implements the standard linear search in the database for each query. + """ + + def as_dict(self) -> Dict: + """Returns the configuration as a dictionary. + + Returns: + Dict[str, Any] + """ + return {"bruteForceConfig": {}} + + +@dataclass +class MatchingEngineIndexConfig: + """Configuration options for using the tree-AH algorithm (Shallow tree + Asymmetric Hashing). + Please refer to this paper for more details: https://arxiv.org/abs/1908.10396 + + Args: + dimensions (int): + Required. The number of dimensions of the input vectors. + algorithm_config (AlgorithmConfig): + Required. The configuration with regard to the algorithms used for efficient search. + approximate_neighbors_count (int): + Optional. The default number of neighbors to find via approximate search before exact reordering is + performed. Exact reordering is a procedure where results returned by an + approximate search algorithm are reordered via a more expensive distance computation. + + Required if tree-AH algorithm is used. + distance_measure_type (DistanceMeasureType): + Optional. The distance measure used in nearest neighbor search. + """ + + dimensions: int + algorithm_config: AlgorithmConfig + approximate_neighbors_count: Optional[int] = None + distance_measure_type: Optional[DistanceMeasureType] = None + + def as_dict(self) -> Dict[str, Any]: + """Returns the configuration as a dictionary. + + Returns: + Dict[str, Any] + """ + + return { + "dimensions": self.dimensions, + "algorithmConfig": self.algorithm_config.as_dict(), + "approximateNeighborsCount": self.approximate_neighbors_count, + "distanceMeasureType": self.distance_measure_type, + } diff --git a/google/cloud/aiplatform/matching_engine/matching_engine_index_endpoint.py b/google/cloud/aiplatform/matching_engine/matching_engine_index_endpoint.py new file mode 100644 index 0000000000..da155496ae --- /dev/null +++ b/google/cloud/aiplatform/matching_engine/matching_engine_index_endpoint.py @@ -0,0 +1,861 @@ +# -*- coding: utf-8 -*- + +# Copyright 2022 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 dataclasses import dataclass +from typing import Dict, List, Optional, Sequence, Tuple + +from google.auth import credentials as auth_credentials +from google.cloud.aiplatform import base +from google.cloud.aiplatform import initializer +from google.cloud.aiplatform import matching_engine +from google.cloud.aiplatform import utils +from google.cloud.aiplatform.compat.types import ( + machine_resources as gca_machine_resources_compat, + matching_engine_index_endpoint as gca_matching_engine_index_endpoint, +) +from google.cloud.aiplatform.matching_engine._protos import match_service_pb2 +from google.cloud.aiplatform.matching_engine._protos import match_service_pb2_grpc +from google.protobuf import field_mask_pb2 + +import grpc + +_LOGGER = base.Logger(__name__) + + +@dataclass +class MatchNeighbor: + """The id and distance of a nearest neighbor match for a given query embedding. + + Args: + id (str): + Required. The id of the neighbor. + distance (float): + Required. The distance to the query embedding. + """ + + id: str + distance: float + + +class MatchingEngineIndexEndpoint(base.VertexAiResourceNounWithFutureManager): + """Matching Engine index endpoint resource for Vertex AI.""" + + client_class = utils.IndexEndpointClientWithOverride + + _resource_noun = "indexEndpoints" + _getter_method = "get_index_endpoint" + _list_method = "list_index_endpoints" + _delete_method = "delete_index_endpoint" + _parse_resource_name_method = "parse_index_endpoint_path" + _format_resource_name_method = "index_endpoint_path" + + def __init__( + self, + index_endpoint_name: str, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ): + """Retrieves an existing index endpoint given a name or ID. + + Example Usage: + + my_index_endpoint = aiplatform.MatchingEngineIndexEndpoint( + index_endpoint_name='projects/123/locations/us-central1/index_endpoint/my_index_id' + ) + or + my_index_endpoint = aiplatform.MatchingEngineIndexEndpoint( + index_endpoint_name='my_index_endpoint_id' + ) + + Args: + index_endpoint_name (str): + Required. A fully-qualified index endpoint resource name or a index ID. + Example: "projects/123/locations/us-central1/index_endpoints/my_index_id" + or "my_index_id" when project and location are initialized or passed. + project (str): + Optional. Project to retrieve index endpoint from. If not set, project + set in aiplatform.init will be used. + location (str): + Optional. Location to retrieve index endpoint from. If not set, location + set in aiplatform.init will be used. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to retrieve this IndexEndpoint. Overrides + credentials set in aiplatform.init. + """ + + super().__init__( + project=project, + location=location, + credentials=credentials, + resource_name=index_endpoint_name, + ) + self._gca_resource = self._get_gca_resource(resource_name=index_endpoint_name) + + @classmethod + @base.optional_sync() + def create( + cls, + display_name: str, + network: str, + description: Optional[str] = None, + labels: Optional[Dict[str, str]] = None, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + sync: bool = True, + ) -> "MatchingEngineIndexEndpoint": + """Creates a MatchingEngineIndexEndpoint resource. + + Example Usage: + + my_index_endpoint = aiplatform.IndexEndpoint.create( + display_name='my_endpoint', + ) + + Args: + display_name (str): + Required. The display name of the IndexEndpoint. + The name can be up to 128 characters long and + can be consist of any UTF-8 characters. + network (str): + Required. The full name of the Google Compute Engine + `network `__ + to which the IndexEndpoint should be peered. + + Private services access must already be configured for the + network. If left unspecified, the Endpoint is not peered + with any network. + + `Format `__: + projects/{project}/global/networks/{network}. Where + {project} is a project number, as in '12345', and {network} + is network name. + description (str): + Optional. The description of the IndexEndpoint. + labels (Dict[str, str]): + Optional. The labels with user-defined + metadata to organize your IndexEndpoint. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + on and examples of labels. No more than 64 user + labels can be associated with one + IndexEndpoint (System labels are excluded)." + System reserved label keys are prefixed with + "aiplatform.googleapis.com/" and are immutable. + project (str): + Optional. Project to create EntityType in. If not set, project + set in aiplatform.init will be used. + location (str): + Optional. Location to create EntityType in. If not set, location + set in aiplatform.init will be used. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to create EntityTypes. Overrides + credentials set in aiplatform.init. + request_metadata (Sequence[Tuple[str, str]]): + Optional. Strings which should be sent along with the request as metadata. + sync (bool): + Optional. Whether to execute this creation synchronously. If False, this method + will be executed in concurrent Future and any downstream object will + be immediately returned and synced when the Future has completed. + + Returns: + MatchingEngineIndexEndpoint - IndexEndpoint resource object + + """ + gapic_index_endpoint = gca_matching_engine_index_endpoint.IndexEndpoint( + display_name=display_name, + description=description, + network=network, + ) + + if labels: + utils.validate_labels(labels) + gapic_index_endpoint.labels = labels + + api_client = cls._instantiate_client(location=location, credentials=credentials) + + create_lro = api_client.create_index_endpoint( + parent=initializer.global_config.common_location_path( + project=project, location=location + ), + index_endpoint=gapic_index_endpoint, + metadata=request_metadata, + ) + + _LOGGER.log_create_with_lro(cls, create_lro) + + created_index = create_lro.result() + + _LOGGER.log_create_complete(cls, created_index, "index_endpoint") + + index_obj = cls( + index_endpoint_name=created_index.name, + project=project, + location=location, + credentials=credentials, + ) + + return index_obj + + def update( + self, + display_name: str, + description: Optional[str] = None, + labels: Optional[Dict[str, str]] = None, + request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + ) -> "MatchingEngineIndexEndpoint": + """Updates an existing index endpoint resource. + + Args: + display_name (str): + Required. The display name of the IndexEndpoint. + The name can be up to 128 characters long and + can be consist of any UTF-8 characters. + description (str): + Optional. The description of the IndexEndpoint. + labels (Dict[str, str]): + Optional. The labels with user-defined + metadata to organize your Indexs. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + on and examples of labels. No more than 64 user + labels can be associated with one IndexEndpoint + (System labels are excluded)." + System reserved label keys are prefixed with + "aiplatform.googleapis.com/" and are immutable. + request_metadata (Sequence[Tuple[str, str]]): + Optional. Strings which should be sent along with the request as metadata. + + Returns: + MatchingEngineIndexEndpoint - The updated index endpoint resource object. + """ + + self.wait() + + update_mask = list() + + if labels: + utils.validate_labels(labels) + update_mask.append("labels") + + if display_name is not None: + update_mask.append("display_name") + + if description is not None: + update_mask.append("description") + + update_mask = field_mask_pb2.FieldMask(paths=update_mask) + + gapic_index_endpoint = gca_matching_engine_index_endpoint.IndexEndpoint( + name=self.resource_name, + display_name=display_name, + description=description, + labels=labels, + ) + + self._gca_resource = self.api_client.update_index_endpoint( + index_endpoint=gapic_index_endpoint, + update_mask=update_mask, + metadata=request_metadata, + ) + + return self + + @staticmethod + def _build_deployed_index( + deployed_index_id: str, + index_resource_name: Optional[str] = None, + display_name: Optional[str] = None, + machine_type: Optional[str] = None, + min_replica_count: Optional[int] = None, + max_replica_count: Optional[int] = None, + enable_access_logging: Optional[bool] = None, + reserved_ip_ranges: Optional[Sequence[str]] = None, + deployment_group: Optional[str] = None, + auth_config_audiences: Optional[Sequence[str]] = None, + auth_config_allowed_issuers: Optional[Sequence[str]] = None, + ) -> gca_matching_engine_index_endpoint.DeployedIndex: + """Builds a DeployedIndex. + + Args: + deployed_index_id (str): + Required. The user specified ID of the + DeployedIndex. The ID can be up to 128 + characters long and must start with a letter and + only contain letters, numbers, and underscores. + The ID must be unique within the project it is + created in. + index_resource_name (str): + Optional. A fully-qualified index endpoint resource name or a index ID. + Example: "projects/123/locations/us-central1/index_endpoints/my_index_id" + display_name (str): + Optional. The display name of the DeployedIndex. If not provided upon + creation, the Index's display_name is used. + machine_type (str): + Optional. The type of machine. Not specifying machine type will + result in model to be deployed with automatic resources. + min_replica_count (int): + Optional. The minimum number of machine replicas this deployed + model will be always deployed on. If traffic against it increases, + it may dynamically be deployed onto more replicas, and as traffic + decreases, some of these extra replicas may be freed. + + If this value is not provided, the value of 2 will be used. + max_replica_count (int): + Optional. The maximum number of replicas this deployed model may + be deployed on when the traffic against it increases. If requested + value is too large, the deployment will error, but if deployment + succeeds then the ability to scale the model to that many replicas + is guaranteed (barring service outages). If traffic against the + deployed model increases beyond what its replicas at maximum may + handle, a portion of the traffic will be dropped. If this value + is not provided, the larger value of min_replica_count or 2 will + be used. If value provided is smaller than min_replica_count, it + will automatically be increased to be min_replica_count. + enable_access_logging (bool): + Optional. If true, private endpoint's access + logs are sent to StackDriver Logging. + These logs are like standard server access logs, + containing information like timestamp and + latency for each MatchRequest. + Note that Stackdriver logs may incur a cost, + especially if the deployed index receives a high + queries per second rate (QPS). Estimate your + costs before enabling this option. + deployed_index_auth_config (google.cloud.aiplatform_v1.types.DeployedIndexAuthConfig): + Optional. If set, the authentication is + enabled for the private endpoint. + reserved_ip_ranges (Sequence[str]): + Optional. A list of reserved ip ranges under + the VPC network that can be used for this + DeployedIndex. + If set, we will deploy the index within the + provided ip ranges. Otherwise, the index might + be deployed to any ip ranges under the provided + VPC network. + + The value sohuld be the name of the address + (https://cloud.google.com/compute/docs/reference/rest/v1/addresses) + Example: 'vertex-ai-ip-range'. + deployment_group (str): + Optional. The deployment group can be no longer than 64 + characters (eg: 'test', 'prod'). If not set, we will use the + 'default' deployment group. + + Creating ``deployment_groups`` with ``reserved_ip_ranges`` + is a recommended practice when the peered network has + multiple peering ranges. This creates your deployments from + predictable IP spaces for easier traffic administration. + Also, one deployment_group (except 'default') can only be + used with the same reserved_ip_ranges which means if the + deployment_group has been used with reserved_ip_ranges: [a, + b, c], using it with [a, b] or [d, e] is disallowed. + + Note: we only support up to 5 deployment groups(not + including 'default'). + auth_config_audiences (Sequence[str]): + Optional. The list of JWT + `audiences `__. + that are allowed to access. A JWT containing any of these + audiences will be accepted. + auth_config_allowed_issuers (Sequence[str]): + Optional. A list of allowed JWT issuers. Each entry must be a valid + Google service account, in the following format: + + ``service-account-name@project-id.iam.gserviceaccount.com`` + request_metadata (Sequence[Tuple[str, str]]): + Optional. Strings which should be sent along with the request as metadata. + """ + + deployed_index = gca_matching_engine_index_endpoint.DeployedIndex( + id=deployed_index_id, + index=index_resource_name, + display_name=display_name, + enable_access_logging=enable_access_logging, + reserved_ip_ranges=reserved_ip_ranges, + deployment_group=deployment_group, + ) + + if auth_config_audiences and auth_config_allowed_issuers: + deployed_index.deployed_index_auth_config = gca_matching_engine_index_endpoint.DeployedIndexAuthConfig( + auth_provider=gca_matching_engine_index_endpoint.DeployedIndexAuthConfig.AuthProvider( + audiences=auth_config_audiences, + allowed_issuers=auth_config_allowed_issuers, + ) + ) + + if machine_type: + machine_spec = gca_machine_resources_compat.MachineSpec( + machine_type=machine_type + ) + + deployed_index.dedicated_resources = ( + gca_machine_resources_compat.DedicatedResources( + machine_spec=machine_spec, + min_replica_count=min_replica_count, + max_replica_count=max_replica_count, + ) + ) + + else: + deployed_index.automatic_resources = ( + gca_machine_resources_compat.AutomaticResources( + min_replica_count=min_replica_count, + max_replica_count=max_replica_count, + ) + ) + return deployed_index + + def deploy_index( + self, + index: matching_engine.MatchingEngineIndex, + deployed_index_id: str, + display_name: Optional[str] = None, + machine_type: Optional[str] = None, + min_replica_count: Optional[int] = None, + max_replica_count: Optional[int] = None, + enable_access_logging: Optional[bool] = None, + reserved_ip_ranges: Optional[Sequence[str]] = None, + deployment_group: Optional[str] = None, + auth_config_audiences: Optional[Sequence[str]] = None, + auth_config_allowed_issuers: Optional[Sequence[str]] = None, + request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + ) -> "MatchingEngineIndexEndpoint": + """Deploys an existing index resource to this endpoint resource. + + Args: + index (MatchingEngineIndex): + Required. The Index this is the + deployment of. We may refer to this Index as the + DeployedIndex's "original" Index. + deployed_index_id (str): + Required. The user specified ID of the + DeployedIndex. The ID can be up to 128 + characters long and must start with a letter and + only contain letters, numbers, and underscores. + The ID must be unique within the project it is + created in. + display_name (str): + The display name of the DeployedIndex. If not provided upon + creation, the Index's display_name is used. + machine_type (str): + Optional. The type of machine. Not specifying machine type will + result in model to be deployed with automatic resources. + min_replica_count (int): + Optional. The minimum number of machine replicas this deployed + model will be always deployed on. If traffic against it increases, + it may dynamically be deployed onto more replicas, and as traffic + decreases, some of these extra replicas may be freed. + + If this value is not provided, the value of 2 will be used. + max_replica_count (int): + Optional. The maximum number of replicas this deployed model may + be deployed on when the traffic against it increases. If requested + value is too large, the deployment will error, but if deployment + succeeds then the ability to scale the model to that many replicas + is guaranteed (barring service outages). If traffic against the + deployed model increases beyond what its replicas at maximum may + handle, a portion of the traffic will be dropped. If this value + is not provided, the larger value of min_replica_count or 2 will + be used. If value provided is smaller than min_replica_count, it + will automatically be increased to be min_replica_count. + enable_access_logging (bool): + Optional. If true, private endpoint's access + logs are sent to StackDriver Logging. + These logs are like standard server access logs, + containing information like timestamp and + latency for each MatchRequest. + Note that Stackdriver logs may incur a cost, + especially if the deployed index receives a high + queries per second rate (QPS). Estimate your + costs before enabling this option. + reserved_ip_ranges (Sequence[str]): + Optional. A list of reserved ip ranges under + the VPC network that can be used for this + DeployedIndex. + If set, we will deploy the index within the + provided ip ranges. Otherwise, the index might + be deployed to any ip ranges under the provided + VPC network. + + The value sohuld be the name of the address + (https://cloud.google.com/compute/docs/reference/rest/v1/addresses) + Example: 'vertex-ai-ip-range'. + deployment_group (str): + Optional. The deployment group can be no longer than 64 + characters (eg: 'test', 'prod'). If not set, we will use the + 'default' deployment group. + + Creating ``deployment_groups`` with ``reserved_ip_ranges`` + is a recommended practice when the peered network has + multiple peering ranges. This creates your deployments from + predictable IP spaces for easier traffic administration. + Also, one deployment_group (except 'default') can only be + used with the same reserved_ip_ranges which means if the + deployment_group has been used with reserved_ip_ranges: [a, + b, c], using it with [a, b] or [d, e] is disallowed. + + Note: we only support up to 5 deployment groups(not + including 'default'). + auth_config_audiences (Sequence[str]): + The list of JWT + `audiences `__. + that are allowed to access. A JWT containing any of these + audiences will be accepted. + + auth_config_audiences and auth_config_allowed_issuers must be passed together. + auth_config_allowed_issuers (Sequence[str]): + A list of allowed JWT issuers. Each entry must be a valid + Google service account, in the following format: + + ``service-account-name@project-id.iam.gserviceaccount.com`` + + auth_config_audiences and auth_config_allowed_issuers must be passed together. + request_metadata (Sequence[Tuple[str, str]]): + Optional. Strings which should be sent along with the request as metadata. + Returns: + MatchingEngineIndexEndpoint - IndexEndpoint resource object + """ + + self.wait() + + _LOGGER.log_action_start_against_resource( + "Deploying index", + "index_endpoint", + self, + ) + + deployed_index = self._build_deployed_index( + deployed_index_id=deployed_index_id, + index_resource_name=index.resource_name, + display_name=display_name, + machine_type=machine_type, + min_replica_count=min_replica_count, + max_replica_count=max_replica_count, + enable_access_logging=enable_access_logging, + reserved_ip_ranges=reserved_ip_ranges, + deployment_group=deployment_group, + auth_config_audiences=auth_config_audiences, + auth_config_allowed_issuers=auth_config_allowed_issuers, + ) + + deploy_lro = self.api_client.deploy_index( + index_endpoint=self.resource_name, + deployed_index=deployed_index, + metadata=request_metadata, + ) + + _LOGGER.log_action_started_against_resource_with_lro( + "Deploy index", "index_endpoint", self.__class__, deploy_lro + ) + + deploy_lro.result() + + _LOGGER.log_action_completed_against_resource( + "index_endpoint", "Deployed index", self + ) + + # update local resource + self._sync_gca_resource() + + return self + + def undeploy_index( + self, + deployed_index_id: str, + request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + ) -> "MatchingEngineIndexEndpoint": + """Undeploy a deployed index endpoint resource. + + Args: + deployed_index_id (str): + Required. The ID of the DeployedIndex + to be undeployed from the IndexEndpoint. + request_metadata (Sequence[Tuple[str, str]]): + Optional. Strings which should be sent along with the request as metadata. + Returns: + MatchingEngineIndexEndpoint - IndexEndpoint resource object + """ + + self.wait() + + _LOGGER.log_action_start_against_resource( + "Undeploying index", + "index_endpoint", + self, + ) + + undeploy_lro = self.api_client.undeploy_index( + index_endpoint=self.resource_name, + deployed_index_id=deployed_index_id, + metadata=request_metadata, + ) + + _LOGGER.log_action_started_against_resource_with_lro( + "Undeploy index", "index_endpoint", self.__class__, undeploy_lro + ) + + undeploy_lro.result() + + _LOGGER.log_action_completed_against_resource( + "index_endpoint", "Undeployed index", self + ) + + return self + + def mutate_deployed_index( + self, + deployed_index_id: str, + min_replica_count: int = 1, + max_replica_count: int = 1, + request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + ): + """Updates an existing deployed index under this endpoint resource. + + Args: + index_id (str): + Required. The ID of the MatchingEnginIndex associated with the DeployedIndex. + deployed_index_id (str): + Required. The user specified ID of the + DeployedIndex. The ID can be up to 128 + characters long and must start with a letter and + only contain letters, numbers, and underscores. + The ID must be unique within the project it is + created in. + min_replica_count (int): + Optional. The minimum number of machine replicas this deployed + model will be always deployed on. If traffic against it increases, + it may dynamically be deployed onto more replicas, and as traffic + decreases, some of these extra replicas may be freed. + max_replica_count (int): + Optional. The maximum number of replicas this deployed model may + be deployed on when the traffic against it increases. If requested + value is too large, the deployment will error, but if deployment + succeeds then the ability to scale the model to that many replicas + is guaranteed (barring service outages). If traffic against the + deployed model increases beyond what its replicas at maximum may + handle, a portion of the traffic will be dropped. If this value + is not provided, the larger value of min_replica_count or 1 will + be used. If value provided is smaller than min_replica_count, it + will automatically be increased to be min_replica_count. + request_metadata (Sequence[Tuple[str, str]]): + Optional. Strings which should be sent along with the request as metadata. + """ + + self.wait() + + _LOGGER.log_action_start_against_resource( + "Mutating index", + "index_endpoint", + self, + ) + + deployed_index = self._build_deployed_index( + index_resource_name=None, + deployed_index_id=deployed_index_id, + min_replica_count=min_replica_count, + max_replica_count=max_replica_count, + ) + + deploy_lro = self.api_client.mutate_deployed_index( + index_endpoint=self.resource_name, + deployed_index=deployed_index, + metadata=request_metadata, + ) + + _LOGGER.log_action_started_against_resource_with_lro( + "Mutate index", "index_endpoint", self.__class__, deploy_lro + ) + + deploy_lro.result() + + # update local resource + self._sync_gca_resource() + + _LOGGER.log_action_completed_against_resource("index_endpoint", "Mutated", self) + + return self + + @property + def deployed_indexes( + self, + ) -> List[gca_matching_engine_index_endpoint.DeployedIndex]: + """Returns a list of deployed indexes on this endpoint. + + Returns: + List[gca_matching_engine_index_endpoint.DeployedIndex] - Deployed indexes + """ + self._assert_gca_resource_is_available() + return self._gca_resource.deployed_indexes + + @base.optional_sync() + def _undeploy( + self, + deployed_index_id: str, + metadata: Optional[Sequence[Tuple[str, str]]] = (), + sync=True, + ) -> None: + """Undeploys a deployed index. + + Args: + deployed_index_id (str): + Required. The ID of the DeployedIndex to be undeployed from the + Endpoint. + metadata (Sequence[Tuple[str, str]]): + Optional. Strings which should be sent along with the request as + metadata. + """ + self._sync_gca_resource() + + _LOGGER.log_action_start_against_resource("Undeploying", "index_endpoint", self) + + operation_future = self.api_client.undeploy_index( + index_endpoint=self.resource_name, + deployed_index_id=deployed_index_id, + metadata=metadata, + ) + + _LOGGER.log_action_started_against_resource_with_lro( + "Undeploy", "index_endpoint", self.__class__, operation_future + ) + + # block before returning + operation_future.result() + + # update local resource + self._sync_gca_resource() + + _LOGGER.log_action_completed_against_resource( + "index_endpoint", "undeployed", self + ) + + def undeploy_all(self, sync: bool = True) -> "MatchingEngineIndexEndpoint": + """Undeploys every index deployed to this MatchingEngineIndexEndpoint. + + Args: + sync (bool): + Whether to execute this method synchronously. If False, this method + will be executed in concurrent Future and any downstream object will + be immediately returned and synced when the Future has completed. + """ + self._sync_gca_resource() + + for deployed_index in self.deployed_indexes: + self._undeploy(deployed_index_id=deployed_index.id, sync=sync) + + return self + + def delete(self, force: bool = False, sync: bool = True) -> None: + """Deletes this MatchingEngineIndexEndpoint resource. If force is set to True, + all indexes on this endpoint will be undeployed prior to deletion. + + Args: + force (bool): + Required. If force is set to True, all deployed indexes on this + endpoint will be undeployed first. Default is False. + sync (bool): + Whether to execute this method synchronously. If False, this method + will be executed in concurrent Future and any downstream object will + be immediately returned and synced when the Future has completed. + Raises: + FailedPrecondition: If indexes are deployed on this MatchingEngineIndexEndpoint and force = False. + """ + if force: + self.undeploy_all(sync=sync) + + super().delete(sync=sync) + + @property + def description(self) -> str: + """Description of the index endpoint.""" + self._assert_gca_resource_is_available() + return self._gca_resource.description + + def match( + self, deployed_index_id: str, queries: List[List[float]], num_neighbors: int = 1 + ) -> List[List[MatchNeighbor]]: + """Retrieves nearest neighbors for the given embedding queries on the specified deployed index. + + Args: + deployed_index_id (str): + Required. The ID of the DeployedIndex to match the queries against. + queries (List[List[float]]): + Required. A list of queries. Each query is a list of floats, representing a single embedding. + num_neighbors (int): + Required. The number of nearest neighbors to be retrieved from database for + each query. + + Returns: + List[List[MatchNeighbor]] - A list of nearest neighbors for each query. + """ + + # Find the deployed index by id + deployed_indexes = [ + deployed_index + for deployed_index in self.deployed_indexes + if deployed_index.id == deployed_index_id + ] + + if not deployed_indexes: + raise RuntimeError(f"No deployed index with id '{deployed_index_id}' found") + + # Retrieve server ip from deployed index + server_ip = deployed_indexes[0].private_endpoints.match_grpc_address + + # Set up channel and stub + channel = grpc.insecure_channel("{}:10000".format(server_ip)) + stub = match_service_pb2_grpc.MatchServiceStub(channel) + + # Create the batch match request + batch_request = match_service_pb2.BatchMatchRequest() + batch_request_for_index = ( + match_service_pb2.BatchMatchRequest.BatchMatchRequestPerIndex() + ) + batch_request_for_index.deployed_index_id = deployed_index_id + batch_request_for_index.requests.extend( + [ + match_service_pb2.MatchRequest( + num_neighbors=num_neighbors, + deployed_index_id=deployed_index_id, + float_val=query, + ) + for query in queries + ] + ) + batch_request.requests.append(batch_request_for_index) + + # Perform the request + response = stub.BatchMatch(batch_request) + + # Wrap the results in MatchNeighbor objects and return + return [ + [ + MatchNeighbor(id=neighbor.id, distance=neighbor.distance) + for neighbor in embedding_neighbors.neighbor + ] + for embedding_neighbors in response.responses[0].responses + ] diff --git a/google/cloud/aiplatform/metadata/artifact.py b/google/cloud/aiplatform/metadata/artifact.py index b3ef6e09a2..65ee2cb92b 100644 --- a/google/cloud/aiplatform/metadata/artifact.py +++ b/google/cloud/aiplatform/metadata/artifact.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2021 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,21 +15,76 @@ # limitations under the License. # -from typing import Optional, Dict +from typing import Optional, Dict, Union import proto +from google.auth import credentials as auth_credentials + +from google.cloud.aiplatform import base +from google.cloud.aiplatform import models from google.cloud.aiplatform import utils -from google.cloud.aiplatform.metadata.resource import _Resource -from google.cloud.aiplatform_v1beta1 import ListArtifactsRequest -from google.cloud.aiplatform_v1beta1.types import artifact as gca_artifact +from google.cloud.aiplatform.compat.types import artifact as gca_artifact +from google.cloud.aiplatform.compat.types import ( + metadata_service as gca_metadata_service, +) +from google.cloud.aiplatform.metadata import metadata_store +from google.cloud.aiplatform.metadata import resource +from google.cloud.aiplatform.metadata import utils as metadata_utils +from google.cloud.aiplatform.metadata.schema import base_artifact +from google.cloud.aiplatform.utils import rest_utils + +_LOGGER = base.Logger(__name__) -class _Artifact(_Resource): + +class Artifact(resource._Resource): """Metadata Artifact resource for Vertex AI""" + def __init__( + self, + artifact_name: str, + *, + metadata_store_id: str = "default", + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ): + """Retrieves an existing Metadata Artifact given a resource name or ID. + + Args: + artifact_name (str): + Required. A fully-qualified resource name or resource ID of the Artifact. + Example: "projects/123/locations/us-central1/metadataStores/default/artifacts/my-resource". + or "my-resource" when project and location are initialized or passed. + metadata_store_id (str): + Optional. MetadataStore to retrieve Artifact from. If not set, metadata_store_id is set to "default". + If artifact_name is a fully-qualified resource, its metadata_store_id overrides this one. + project (str): + Optional. Project to retrieve the artifact from. If not set, project + set in aiplatform.init will be used. + location (str): + Optional. Location to retrieve the Artifact from. If not set, location + set in aiplatform.init will be used. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to retrieve this Artifact. Overrides + credentials set in aiplatform.init. + """ + + super().__init__( + resource_name=artifact_name, + metadata_store_id=metadata_store_id, + project=project, + location=location, + credentials=credentials, + ) + _resource_noun = "artifacts" _getter_method = "get_artifact" + _delete_method = "delete_artifact" + _parse_resource_name_method = "parse_artifact_path" + _format_resource_name_method = "artifact_path" + _list_method = "list_artifacts" @classmethod def _create_resource( @@ -38,25 +93,125 @@ def _create_resource( parent: str, resource_id: str, schema_title: str, + uri: Optional[str] = None, display_name: Optional[str] = None, schema_version: Optional[str] = None, description: Optional[str] = None, metadata: Optional[Dict] = None, - ) -> proto.Message: + state: gca_artifact.Artifact.State = gca_artifact.Artifact.State.LIVE, + ) -> gca_artifact.Artifact: gapic_artifact = gca_artifact.Artifact( + uri=uri, schema_title=schema_title, schema_version=schema_version, display_name=display_name, description=description, metadata=metadata if metadata else {}, + state=state, ) return client.create_artifact( - parent=parent, artifact=gapic_artifact, artifact_id=resource_id, + parent=parent, + artifact=gapic_artifact, + artifact_id=resource_id, ) + @classmethod + def _create( + cls, + resource_id: str, + schema_title: str, + uri: Optional[str] = None, + display_name: Optional[str] = None, + schema_version: Optional[str] = None, + description: Optional[str] = None, + metadata: Optional[Dict] = None, + state: gca_artifact.Artifact.State = gca_artifact.Artifact.State.LIVE, + metadata_store_id: Optional[str] = "default", + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ) -> "Artifact": + """Creates a new Metadata resource. + + Args: + resource_id (str): + Required. The portion of the resource name with + the format: + projects/123/locations/us-central1/metadataStores///. + schema_title (str): + Required. schema_title identifies the schema title used by the resource. + display_name (str): + Optional. The user-defined name of the resource. + schema_version (str): + Optional. schema_version specifies the version used by the resource. + If not set, defaults to use the latest version. + description (str): + Optional. Describes the purpose of the resource to be created. + metadata (Dict): + Optional. Contains the metadata information that will be stored in the resource. + state (google.cloud.gapic.types.Artifact.State): + Optional. The state of this Artifact. This is a + property of the Artifact, and does not imply or + capture any ongoing process. This property is + managed by clients (such as Vertex AI + Pipelines), and the system does not prescribe or + check the validity of state transitions. + metadata_store_id (str): + The portion of the resource name with + the format: + projects/123/locations/us-central1/metadataStores/// + If not provided, the MetadataStore's ID will be set to "default". + project (str): + Project used to create this resource. Overrides project set in + aiplatform.init. + location (str): + Location used to create this resource. Overrides location set in + aiplatform.init. + credentials (auth_credentials.Credentials): + Custom credentials used to create this resource. Overrides + credentials set in aiplatform.init. + + Returns: + resource (_Resource): + Instantiated representation of the managed Metadata resource. + + """ + api_client = cls._instantiate_client(location=location, credentials=credentials) + + parent = utils.full_resource_name( + resource_name=metadata_store_id, + resource_noun=metadata_store._MetadataStore._resource_noun, + parse_resource_name_method=metadata_store._MetadataStore._parse_resource_name, + format_resource_name_method=metadata_store._MetadataStore._format_resource_name, + project=project, + location=location, + ) + + resource = cls._create_resource( + client=api_client, + parent=parent, + resource_id=resource_id, + schema_title=schema_title, + uri=uri, + display_name=display_name, + schema_version=schema_version, + description=description, + metadata=metadata, + state=state, + ) + + self = cls._empty_constructor( + project=project, location=location, credentials=credentials + ) + self._gca_resource = resource + + return self + @classmethod def _update_resource( - cls, client: utils.MetadataClientWithOverride, resource: proto.Message, + cls, + client: utils.MetadataClientWithOverride, + resource: proto.Message, ) -> proto.Message: """Update Artifacts with given input. @@ -86,5 +241,326 @@ def _list_resources( filter (str): Optional. filter string to restrict the list result """ - list_request = ListArtifactsRequest(parent=parent, filter=filter,) + list_request = gca_metadata_service.ListArtifactsRequest( + parent=parent, + filter=filter, + ) return client.list_artifacts(request=list_request) + + @classmethod + def create( + cls, + schema_title: str, + *, + resource_id: Optional[str] = None, + uri: Optional[str] = None, + display_name: Optional[str] = None, + schema_version: Optional[str] = None, + description: Optional[str] = None, + metadata: Optional[Dict] = None, + state: gca_artifact.Artifact.State = gca_artifact.Artifact.State.LIVE, + metadata_store_id: Optional[str] = "default", + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ) -> "Artifact": + """Creates a new Metadata Artifact. + + Args: + schema_title (str): + Required. schema_title identifies the schema title used by the Artifact. + + Please reference https://cloud.google.com/vertex-ai/docs/ml-metadata/system-schemas. + resource_id (str): + Optional. The portion of the Artifact name with + the format. This is globally unique in a metadataStore: + projects/123/locations/us-central1/metadataStores//artifacts/. + uri (str): + Optional. The uniform resource identifier of the artifact file. May be empty if there is no actual + artifact file. + display_name (str): + Optional. The user-defined name of the Artifact. + schema_version (str): + Optional. schema_version specifies the version used by the Artifact. + If not set, defaults to use the latest version. + description (str): + Optional. Describes the purpose of the Artifact to be created. + metadata (Dict): + Optional. Contains the metadata information that will be stored in the Artifact. + state (google.cloud.gapic.types.Artifact.State): + Optional. The state of this Artifact. This is a + property of the Artifact, and does not imply or + capture any ongoing process. This property is + managed by clients (such as Vertex AI + Pipelines), and the system does not prescribe or + check the validity of state transitions. + metadata_store_id (str): + Optional. The portion of the resource name with + the format: + projects/123/locations/us-central1/metadataStores//artifacts/ + If not provided, the MetadataStore's ID will be set to "default". + project (str): + Optional. Project used to create this Artifact. Overrides project set in + aiplatform.init. + location (str): + Optional. Location used to create this Artifact. Overrides location set in + aiplatform.init. + credentials (auth_credentials.Credentials): + Optional. Custom credentials used to create this Artifact. Overrides + credentials set in aiplatform.init. + + Returns: + Artifact: Instantiated representation of the managed Metadata Artifact. + """ + return cls._create( + resource_id=resource_id, + schema_title=schema_title, + uri=uri, + display_name=display_name, + schema_version=schema_version, + description=description, + metadata=metadata, + state=state, + metadata_store_id=metadata_store_id, + project=project, + location=location, + credentials=credentials, + ) + + @classmethod + def create_from_base_artifact_schema( + cls, + *, + base_artifact_schema: "base_artifact.BaseArtifactSchema", + metadata_store_id: Optional[str] = "default", + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ) -> "Artifact": + """Creates a new Metadata Artifact from a BaseArtifactSchema class instance. + + Args: + base_artifact_schema (BaseArtifactSchema): + Required. An instance of the BaseArtifactType class that can be + provided instead of providing artifact specific parameters. + metadata_store_id (str): + Optional. The portion of the resource name with + the format: + projects/123/locations/us-central1/metadataStores//artifacts/ + If not provided, the MetadataStore's ID will be set to "default". + project (str): + Optional. Project used to create this Artifact. Overrides project set in + aiplatform.init. + location (str): + Optional. Location used to create this Artifact. Overrides location set in + aiplatform.init. + credentials (auth_credentials.Credentials): + Optional. Custom credentials used to create this Artifact. Overrides + credentials set in aiplatform.init. + + Returns: + Artifact: Instantiated representation of the managed Metadata Artifact. + """ + + return cls.create( + resource_id=base_artifact_schema.artifact_id, + schema_title=base_artifact_schema.schema_title, + uri=base_artifact_schema.uri, + display_name=base_artifact_schema.display_name, + schema_version=base_artifact_schema.schema_version, + description=base_artifact_schema.description, + metadata=base_artifact_schema.metadata, + state=base_artifact_schema.state, + metadata_store_id=metadata_store_id, + project=project, + location=location, + credentials=credentials, + ) + + @property + def uri(self) -> Optional[str]: + "Uri for this Artifact." + return self.gca_resource.uri + + @classmethod + def get_with_uri( + cls, + uri: str, + *, + metadata_store_id: Optional[str] = "default", + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ) -> "Artifact": + """Get an Artifact by it's uri. + + If more than one Artifact with this uri is in the metadata store then the Artifact with the latest + create_time is returned. + + Args: + uri(str): + Required. Uri of the Artifact to retrieve. + metadata_store_id (str): + Optional. MetadataStore to retrieve Artifact from. If not set, metadata_store_id is set to "default". + If artifact_name is a fully-qualified resource, its metadata_store_id overrides this one. + project (str): + Optional. Project to retrieve the artifact from. If not set, project + set in aiplatform.init will be used. + location (str): + Optional. Location to retrieve the Artifact from. If not set, location + set in aiplatform.init will be used. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to retrieve this Artifact. Overrides + credentials set in aiplatform.init. + Returns: + Artifact: Artifact with given uri. + Raises: + ValueError: If no Artifact exists with the provided uri. + + """ + + matched_artifacts = cls.list( + filter=f'uri = "{uri}"', + metadata_store_id=metadata_store_id, + project=project, + location=location, + credentials=credentials, + ) + + if not matched_artifacts: + raise ValueError( + f"No artifact with uri {uri} is in the `{metadata_store_id}` MetadataStore." + ) + + if len(matched_artifacts) > 1: + matched_artifacts.sort(key=lambda a: a.create_time, reverse=True) + resource_names = "\n".join(a.resource_name for a in matched_artifacts) + _LOGGER.warn( + f"Mutiple artifacts with uri {uri} were found: {resource_names}" + ) + _LOGGER.warn(f"Returning {matched_artifacts[0].resource_name}") + + return matched_artifacts[0] + + @property + def lineage_console_uri(self) -> str: + """Cloud console uri to view this Artifact Lineage.""" + metadata_store = self._parse_resource_name(self.resource_name)["metadata_store"] + return f"https://console.cloud.google.com/vertex-ai/locations/{self.location}/metadata-stores/{metadata_store}/artifacts/{self.name}?project={self.project}" + + def __repr__(self) -> str: + if self._gca_resource: + return f"{object.__repr__(self)} \nresource name: {self.resource_name}\nuri: {self.uri}\nschema_title:{self.gca_resource.schema_title}" + + return base.FutureManager.__repr__(self) + + +class _VertexResourceArtifactResolver: + + # TODO(b/235594717) Add support for managed datasets + _resource_to_artifact_type = {models.Model: "google.VertexModel"} + + @classmethod + def supports_metadata(cls, resource: base.VertexAiResourceNoun) -> bool: + """Returns True if Vertex resource is supported in Vertex Metadata otherwise False. + + Args: + resource (base.VertexAiResourceNoun): + Requried. Instance of Vertex AI Resource. + Returns: + True if Vertex resource is supported in Vertex Metadata otherwise False. + """ + return type(resource) in cls._resource_to_artifact_type + + @classmethod + def validate_resource_supports_metadata(cls, resource: base.VertexAiResourceNoun): + """Validates Vertex resource is supported in Vertex Metadata. + + Args: + resource (base.VertexAiResourceNoun): + Required. Instance of Vertex AI Resource. + Raises: + ValueError: If Vertex AI Resource is not support in Vertex Metadata. + """ + if not cls.supports_metadata(resource): + raise ValueError( + f"Vertex {type(resource)} is not yet supported in Vertex Metadata." + f"Only {list(cls._resource_to_artifact_type.keys())} are supported" + ) + + @classmethod + def resolve_vertex_resource( + cls, resource: Union[models.Model] + ) -> Optional[Artifact]: + """Resolves Vertex Metadata Artifact that represents this Vertex Resource. + + If there are multiple Artifacts in the metadata store that represent the provided resource. The one with the + latest create_time is returned. + + Args: + resource (base.VertexAiResourceNoun): + Required. Instance of Vertex AI Resource. + Returns: + Artifact: Artifact that represents this Vertex Resource. None if Resource not found in Metadata store. + """ + cls.validate_resource_supports_metadata(resource) + resource.wait() + metadata_type = cls._resource_to_artifact_type[type(resource)] + uri = rest_utils.make_gcp_resource_rest_url(resource=resource) + + artifacts = Artifact.list( + filter=metadata_utils._make_filter_string( + schema_title=metadata_type, + uri=uri, + ), + project=resource.project, + location=resource.location, + credentials=resource.credentials, + ) + + artifacts.sort(key=lambda a: a.create_time, reverse=True) + if artifacts: + # most recent + return artifacts[0] + + @classmethod + def create_vertex_resource_artifact(cls, resource: Union[models.Model]) -> Artifact: + """Creates Vertex Metadata Artifact that represents this Vertex Resource. + + Args: + resource (base.VertexAiResourceNoun): + Required. Instance of Vertex AI Resource. + Returns: + Artifact: Artifact that represents this Vertex Resource. + """ + cls.validate_resource_supports_metadata(resource) + resource.wait() + metadata_type = cls._resource_to_artifact_type[type(resource)] + uri = rest_utils.make_gcp_resource_rest_url(resource=resource) + + return Artifact.create( + schema_title=metadata_type, + display_name=getattr(resource.gca_resource, "display_name", None), + uri=uri, + metadata={"resourceName": resource.resource_name}, + project=resource.project, + location=resource.location, + credentials=resource.credentials, + ) + + @classmethod + def resolve_or_create_resource_artifact( + cls, resource: Union[models.Model] + ) -> Artifact: + """Create of gets Vertex Metadata Artifact that represents this Vertex Resource. + + Args: + resource (base.VertexAiResourceNoun): + Required. Instance of Vertex AI Resource. + Returns: + Artifact: Artifact that represents this Vertex Resource. + """ + artifact = cls.resolve_vertex_resource(resource=resource) + if artifact: + return artifact + return cls.create_vertex_resource_artifact(resource=resource) diff --git a/google/cloud/aiplatform/metadata/constants.py b/google/cloud/aiplatform/metadata/constants.py index 62e7d6e075..8776aef3b1 100644 --- a/google/cloud/aiplatform/metadata/constants.py +++ b/google/cloud/aiplatform/metadata/constants.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2021 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,21 +14,54 @@ # See the License for the specific language governing permissions and # limitations under the License. # +from google.cloud.aiplatform.compat.types import artifact SYSTEM_RUN = "system.Run" SYSTEM_EXPERIMENT = "system.Experiment" +SYSTEM_EXPERIMENT_RUN = "system.ExperimentRun" SYSTEM_PIPELINE = "system.Pipeline" +SYSTEM_PIPELINE_RUN = "system.PipelineRun" SYSTEM_METRICS = "system.Metrics" +_EXPERIMENTS_V2_TENSORBOARD_RUN = "google.VertexTensorboardRun" + _DEFAULT_SCHEMA_VERSION = "0.0.1" SCHEMA_VERSIONS = { SYSTEM_RUN: _DEFAULT_SCHEMA_VERSION, SYSTEM_EXPERIMENT: _DEFAULT_SCHEMA_VERSION, + SYSTEM_EXPERIMENT_RUN: _DEFAULT_SCHEMA_VERSION, SYSTEM_PIPELINE: _DEFAULT_SCHEMA_VERSION, SYSTEM_METRICS: _DEFAULT_SCHEMA_VERSION, } -# The EXPERIMENT_METADATA is needed until we support context deletion in backend service. -# TODO: delete EXPERIMENT_METADATA once backend supports context deletion. +_BACKING_TENSORBOARD_RESOURCE_KEY = "backing_tensorboard_resource" + + +_PARAM_KEY = "_params" +_METRIC_KEY = "_metrics" +_STATE_KEY = "_state" + +_PARAM_PREFIX = "param" +_METRIC_PREFIX = "metric" +_TIME_SERIES_METRIC_PREFIX = "time_series_metric" + +# This is currently used to filter in the Console. EXPERIMENT_METADATA = {"experiment_deleted": False} + +PIPELINE_PARAM_PREFIX = "input:" + +TENSORBOARD_CUSTOM_JOB_EXPERIMENT_FIELD = "tensorboard_link" + +GCP_ARTIFACT_RESOURCE_NAME_KEY = "resourceName" + +# constant to mark an Experiment context as originating from the SDK +# TODO(b/235593750) Remove this field +_VERTEX_EXPERIMENT_TRACKING_LABEL = "vertex_experiment_tracking" + +_TENSORBOARD_RUN_REFERENCE_ARTIFACT = artifact.Artifact( + name="google-vertex-tensorboard-run-v0-0-1", + schema_title=_EXPERIMENTS_V2_TENSORBOARD_RUN, + schema_version="0.0.1", + metadata={_VERTEX_EXPERIMENT_TRACKING_LABEL: True}, +) diff --git a/google/cloud/aiplatform/metadata/context.py b/google/cloud/aiplatform/metadata/context.py index ddd583bbdf..d072a6e047 100644 --- a/google/cloud/aiplatform/metadata/context.py +++ b/google/cloud/aiplatform/metadata/context.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2021 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,21 +15,39 @@ # limitations under the License. # -from typing import Optional, Dict, Sequence +from typing import Optional, Dict, List, Sequence import proto +from google.cloud.aiplatform import base from google.cloud.aiplatform import utils -from google.cloud.aiplatform.metadata.resource import _Resource -from google.cloud.aiplatform_v1beta1 import ListContextsRequest -from google.cloud.aiplatform_v1beta1.types import context as gca_context - - -class _Context(_Resource): +from google.cloud.aiplatform.metadata import utils as metadata_utils +from google.cloud.aiplatform.compat.types import context as gca_context +from google.cloud.aiplatform.compat.types import ( + lineage_subgraph as gca_lineage_subgraph, +) +from google.cloud.aiplatform.compat.types import ( + metadata_service as gca_metadata_service, +) +from google.cloud.aiplatform.metadata import artifact +from google.cloud.aiplatform.metadata import execution +from google.cloud.aiplatform.metadata import resource + + +class _Context(resource._Resource): """Metadata Context resource for Vertex AI""" _resource_noun = "contexts" _getter_method = "get_context" + _delete_method = "delete_context" + _parse_resource_name_method = "parse_context_path" + _format_resource_name_method = "context_path" + _list_method = "list_contexts" + + @property + def parent_contexts(self) -> Sequence[str]: + """The parent context resource names of this context.""" + return self.gca_resource.parent_contexts def add_artifacts_and_executions( self, @@ -50,6 +68,19 @@ def add_artifacts_and_executions( executions=execution_resource_names, ) + def get_artifacts(self) -> List[artifact.Artifact]: + """Returns all Artifact attributed to this Context. + + Returns: + artifacts(List[Artifacts]): All Artifacts under this context. + """ + return artifact.Artifact.list( + filter=metadata_utils._make_filter_string(in_context=[self.resource_name]), + project=self.project, + location=self.location, + credentials=self.credentials, + ) + @classmethod def _create_resource( cls, @@ -70,12 +101,16 @@ def _create_resource( metadata=metadata if metadata else {}, ) return client.create_context( - parent=parent, context=gapic_context, context_id=resource_id, + parent=parent, + context=gapic_context, + context_id=resource_id, ) @classmethod def _update_resource( - cls, client: utils.MetadataClientWithOverride, resource: proto.Message, + cls, + client: utils.MetadataClientWithOverride, + resource: proto.Message, ) -> proto.Message: """Update Contexts with given input. @@ -106,5 +141,43 @@ def _list_resources( Optional. filter string to restrict the list result """ - list_request = ListContextsRequest(parent=parent, filter=filter,) + list_request = gca_metadata_service.ListContextsRequest( + parent=parent, + filter=filter, + ) return client.list_contexts(request=list_request) + + def add_context_children(self, contexts: List["_Context"]): + """Adds the provided contexts as children of this context. + + Args: + contexts (List[_Context]): Contexts to add as children. + """ + self.api_client.add_context_children( + context=self.resource_name, + child_contexts=[c.resource_name for c in contexts], + ) + + def query_lineage_subgraph(self) -> gca_lineage_subgraph.LineageSubgraph: + """Queries lineage subgraph of this context. + + Returns: + lineage subgraph(gca_lineage_subgraph.LineageSubgraph): Lineage subgraph of this Context. + """ + + return self.api_client.query_context_lineage_subgraph( + context=self.resource_name, retry=base._DEFAULT_RETRY + ) + + def get_executions(self) -> List[execution.Execution]: + """Returns Executions associated to this context. + + Returns: + executions (List[Executions]): Executions associated to this context. + """ + return execution.Execution.list( + filter=metadata_utils._make_filter_string(in_context=[self.resource_name]), + project=self.project, + location=self.location, + credentials=self.credentials, + ) diff --git a/google/cloud/aiplatform/metadata/execution.py b/google/cloud/aiplatform/metadata/execution.py index 3605efdb4f..895417fc64 100644 --- a/google/cloud/aiplatform/metadata/execution.py +++ b/google/cloud/aiplatform/metadata/execution.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2021 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,92 +14,400 @@ # See the License for the specific language governing permissions and # limitations under the License. # - -from typing import Optional, Dict, Sequence +from copy import deepcopy +from typing import Any, Dict, List, Optional, Union import proto -from google.api_core import exceptions +from google.auth import credentials as auth_credentials +from google.cloud.aiplatform import base +from google.cloud.aiplatform import models from google.cloud.aiplatform import utils -from google.cloud.aiplatform.metadata.artifact import _Artifact -from google.cloud.aiplatform.metadata.resource import _Resource -from google.cloud.aiplatform_v1beta1 import Event -from google.cloud.aiplatform_v1beta1.types import execution as gca_execution -from google.cloud.aiplatform_v1beta1.types.metadata_service import ListExecutionsRequest +from google.cloud.aiplatform.compat.types import event as gca_event +from google.cloud.aiplatform.compat.types import execution as gca_execution +from google.cloud.aiplatform.compat.types import ( + metadata_service as gca_metadata_service, +) +from google.cloud.aiplatform.metadata import artifact +from google.cloud.aiplatform.metadata import metadata_store +from google.cloud.aiplatform.metadata import resource +from google.cloud.aiplatform.metadata.schema import base_execution -class _Execution(_Resource): +class Execution(resource._Resource): """Metadata Execution resource for Vertex AI""" _resource_noun = "executions" _getter_method = "get_execution" + _delete_method = "delete_execution" + _parse_resource_name_method = "parse_execution_path" + _format_resource_name_method = "execution_path" + _list_method = "list_executions" + + def __init__( + self, + execution_name: str, + *, + metadata_store_id: str = "default", + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ): + """Retrieves an existing Metadata Execution given a resource name or ID. + + Args: + execution_name (str): + Required. A fully-qualified resource name or resource ID of the Execution. + Example: "projects/123/locations/us-central1/metadataStores/default/executions/my-resource". + or "my-resource" when project and location are initialized or passed. + metadata_store_id (str): + Optional. MetadataStore to retrieve Execution from. If not set, metadata_store_id is set to "default". + If execution_name is a fully-qualified resource, its metadata_store_id overrides this one. + project (str): + Optional. Project to retrieve the artifact from. If not set, project + set in aiplatform.init will be used. + location (str): + Optional. Location to retrieve the Execution from. If not set, location + set in aiplatform.init will be used. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to retrieve this Execution. Overrides + credentials set in aiplatform.init. + """ + + super().__init__( + resource_name=execution_name, + metadata_store_id=metadata_store_id, + project=project, + location=location, + credentials=credentials, + ) + + @property + def state(self) -> gca_execution.Execution.State: + """State of this Execution.""" + return self._gca_resource.state + + @classmethod + def create( + cls, + schema_title: str, + *, + state: gca_execution.Execution.State = gca_execution.Execution.State.RUNNING, + resource_id: Optional[str] = None, + display_name: Optional[str] = None, + schema_version: Optional[str] = None, + metadata: Optional[Dict[str, Any]] = None, + description: Optional[str] = None, + metadata_store_id: str = "default", + project: Optional[str] = None, + location: Optional[str] = None, + credentials=Optional[auth_credentials.Credentials], + ) -> "Execution": + """ + Creates a new Metadata Execution. + + Args: + schema_title (str): + Required. schema_title identifies the schema title used by the Execution. + state (gca_execution.Execution.State.RUNNING): + Optional. State of this Execution. Defaults to RUNNING. + resource_id (str): + Optional. The portion of the Execution name with + the format. This is globally unique in a metadataStore: + projects/123/locations/us-central1/metadataStores//executions/. + display_name (str): + Optional. The user-defined name of the Execution. + schema_version (str): + Optional. schema_version specifies the version used by the Execution. + If not set, defaults to use the latest version. + metadata (Dict): + Optional. Contains the metadata information that will be stored in the Execution. + description (str): + Optional. Describes the purpose of the Execution to be created. + metadata_store_id (str): + Optional. The portion of the resource name with + the format: + projects/123/locations/us-central1/metadataStores//artifacts/ + If not provided, the MetadataStore's ID will be set to "default". + project (str): + Optional. Project used to create this Execution. Overrides project set in + aiplatform.init. + location (str): + Optional. Location used to create this Execution. Overrides location set in + aiplatform.init. + credentials (auth_credentials.Credentials): + Optional. Custom credentials used to create this Execution. Overrides + credentials set in aiplatform.init. + + Returns: + Execution: Instantiated representation of the managed Metadata Execution. + + """ + self = cls._empty_constructor( + project=project, location=location, credentials=credentials + ) + super(base.VertexAiResourceNounWithFutureManager, self).__init__() + + resource = Execution._create_resource( + client=self.api_client, + parent=metadata_store._MetadataStore._format_resource_name( + project=self.project, + location=self.location, + metadata_store=metadata_store_id, + ), + schema_title=schema_title, + resource_id=resource_id, + metadata=metadata, + description=description, + display_name=display_name, + schema_version=schema_version, + state=state, + ) + self._gca_resource = resource + + return self + + @classmethod + def create_from_base_execution_schema( + cls, + *, + base_execution_schema: "base_execution.BaseExecutionSchema", + metadata_store_id: Optional[str] = "default", + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ) -> "Execution": + """ + Creates a new Metadata Execution. + + Args: + base_execution_schema (BaseExecutionSchema): + An instance of the BaseExecutionSchema class that can be + provided instead of providing schema specific parameters. + metadata_store_id (str): + Optional. The portion of the resource name with + the format: + projects/123/locations/us-central1/metadataStores//artifacts/ + If not provided, the MetadataStore's ID will be set to "default". + project (str): + Optional. Project used to create this Execution. Overrides project set in + aiplatform.init. + location (str): + Optional. Location used to create this Execution. Overrides location set in + aiplatform.init. + credentials (auth_credentials.Credentials): + Optional. Custom credentials used to create this Execution. Overrides + credentials set in aiplatform.init. + + Returns: + Execution: Instantiated representation of the managed Metadata Execution. + + """ + resource = Execution.create( + state=base_execution_schema.state, + schema_title=base_execution_schema.schema_title, + resource_id=base_execution_schema.execution_id, + display_name=base_execution_schema.display_name, + schema_version=base_execution_schema.schema_version, + metadata=base_execution_schema.metadata, + description=base_execution_schema.description, + metadata_store_id=metadata_store_id, + project=project, + location=location, + credentials=credentials, + ) + return resource + + def __enter__(self): + if self.state is not gca_execution.Execution.State.RUNNING: + self.update(state=gca_execution.Execution.State.RUNNING) + return self + + def __exit__(self, exc_type, exc_val, exc_tb): + state = ( + gca_execution.Execution.State.FAILED + if exc_type + else gca_execution.Execution.State.COMPLETE + ) + self.update(state=state) + + def assign_input_artifacts( + self, artifacts: List[Union[artifact.Artifact, models.Model]] + ): + """Assigns Artifacts as inputs to this Executions. + + Args: + artifacts (List[Union[artifact.Artifact, models.Model]]): + Required. Artifacts to assign as input. + """ + self._add_artifact(artifacts=artifacts, input=True) + + def assign_output_artifacts( + self, artifacts: List[Union[artifact.Artifact, models.Model]] + ): + """Assigns Artifacts as outputs to this Executions. - def add_artifact( - self, artifact_resource_name: str, input: bool, + Args: + artifacts (List[Union[artifact.Artifact, models.Model]]): + Required. Artifacts to assign as input. + """ + self._add_artifact(artifacts=artifacts, input=False) + + def _add_artifact( + self, + artifacts: List[Union[artifact.Artifact, models.Model]], + input: bool, ): """Connect Artifact to a given Execution. Args: - artifact_resource_name (str): + artifact_resource_names (List[str]): Required. The full resource name of the Artifact to connect to the Execution through an Event. input (bool) Required. Whether Artifact is an input event to the Execution or not. """ - event = Event( - artifact=artifact_resource_name, - type_=Event.Type.INPUT if input else Event.Type.OUTPUT, - ) + artifact_resource_names = [] + for a in artifacts: + if isinstance(a, artifact.Artifact): + artifact_resource_names.append(a.resource_name) + else: + artifact_resource_names.append( + artifact._VertexResourceArtifactResolver.resolve_or_create_resource_artifact( + a + ).resource_name + ) + + events = [ + gca_event.Event( + artifact=artifact_resource_name, + type_=gca_event.Event.Type.INPUT + if input + else gca_event.Event.Type.OUTPUT, + ) + for artifact_resource_name in artifact_resource_names + ] self.api_client.add_execution_events( - execution=self.resource_name, events=[event], + execution=self.resource_name, + events=events, ) - def query_input_and_output_artifacts(self) -> Sequence[_Artifact]: - """query the input and output artifacts connected to the execution. + def _get_artifacts( + self, event_type: gca_event.Event.Type + ) -> List[artifact.Artifact]: + """Get Executions input or output Artifacts. + Args: + event_type (gca_event.Event.Type): + Required. The Event type, input or output. Returns: - A Sequence of _Artifacts + List of Artifacts. """ + subgraph = self.api_client.query_execution_inputs_and_outputs( + execution=self.resource_name + ) - try: - artifacts = self.api_client.query_execution_inputs_and_outputs( - execution=self.resource_name - ).artifacts - except exceptions.NotFound: - return [] + artifact_map = { + artifact_metadata.name: artifact_metadata + for artifact_metadata in subgraph.artifacts + } - return [ - _Artifact( - resource=artifact, + gca_artifacts = [ + artifact_map[event.artifact] + for event in subgraph.events + if event.type_ == event_type + ] + + artifacts = [] + for gca_artifact in gca_artifacts: + this_artifact = artifact.Artifact._empty_constructor( project=self.project, location=self.location, credentials=self.credentials, ) - for artifact in artifacts - ] + this_artifact._gca_resource = gca_artifact + artifacts.append(this_artifact) + + return artifacts + + def get_input_artifacts(self) -> List[artifact.Artifact]: + """Get the input Artifacts of this Execution. + + Returns: + List of input Artifacts. + """ + return self._get_artifacts(event_type=gca_event.Event.Type.INPUT) + + def get_output_artifacts(self) -> List[artifact.Artifact]: + """Get the output Artifacts of this Execution. + + Returns: + List of output Artifacts. + """ + return self._get_artifacts(event_type=gca_event.Event.Type.OUTPUT) @classmethod def _create_resource( cls, client: utils.MetadataClientWithOverride, parent: str, - resource_id: str, schema_title: str, + state: gca_execution.Execution.State = gca_execution.Execution.State.RUNNING, + resource_id: Optional[str] = None, display_name: Optional[str] = None, schema_version: Optional[str] = None, description: Optional[str] = None, metadata: Optional[Dict] = None, - ) -> proto.Message: + ) -> gca_execution.Execution: + """ + Creates a new Metadata Execution. + + Args: + client (utils.MetadataClientWithOverride): + Required. Instantiated Metadata Service Client. + parent (str): + Required: MetadataStore parent in which to create this Execution. + schema_title (str): + Required. schema_title identifies the schema title used by the Execution. + state (gca_execution.Execution.State): + Optional. State of this Execution. Defaults to RUNNING. + resource_id (str): + Optional. The {execution} portion of the resource name with the + format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` + If not provided, the Execution's ID will be a UUID generated + by the service. Must be 4-128 characters in length. Valid + characters are ``/[a-z][0-9]-/``. Must be unique across all + Executions in the parent MetadataStore. (Otherwise the + request will fail with ALREADY_EXISTS, or PERMISSION_DENIED + if the caller can't view the preexisting Execution.) + display_name (str): + Optional. The user-defined name of the Execution. + schema_version (str): + Optional. schema_version specifies the version used by the Execution. + If not set, defaults to use the latest version. + description (str): + Optional. Describes the purpose of the Execution to be created. + metadata (Dict): + Optional. Contains the metadata information that will be stored in the Execution. + + Returns: + Execution: Instantiated representation of the managed Metadata Execution. + + """ gapic_execution = gca_execution.Execution( schema_title=schema_title, schema_version=schema_version, display_name=display_name, description=description, metadata=metadata if metadata else {}, + state=state, ) return client.create_execution( - parent=parent, execution=gapic_execution, execution_id=resource_id, + parent=parent, + execution=gapic_execution, + execution_id=resource_id, ) @classmethod @@ -120,12 +428,17 @@ def _list_resources( Optional. filter string to restrict the list result """ - list_request = ListExecutionsRequest(parent=parent, filter=filter,) + list_request = gca_metadata_service.ListExecutionsRequest( + parent=parent, + filter=filter, + ) return client.list_executions(request=list_request) @classmethod def _update_resource( - cls, client: utils.MetadataClientWithOverride, resource: proto.Message, + cls, + client: utils.MetadataClientWithOverride, + resource: proto.Message, ) -> proto.Message: """Update Executions with given input. @@ -137,3 +450,30 @@ def _update_resource( """ return client.update_execution(execution=resource) + + def update( + self, + state: Optional[gca_execution.Execution.State] = None, + description: Optional[str] = None, + metadata: Optional[Dict[str, Any]] = None, + ): + """Update this Execution. + + Args: + state (gca_execution.Execution.State): + Optional. State of this Execution. + description (str): + Optional. Describes the purpose of the Execution to be created. + metadata (Dict[str, Any): + Optional. Contains the metadata information that will be stored in the Execution. + """ + + gca_resource = deepcopy(self._gca_resource) + if state: + gca_resource.state = state + if description: + gca_resource.description = description + self._nested_update_metadata(gca_resource=gca_resource, metadata=metadata) + self._gca_resource = self._update_resource( + self.api_client, resource=gca_resource + ) diff --git a/google/cloud/aiplatform/metadata/experiment_resources.py b/google/cloud/aiplatform/metadata/experiment_resources.py new file mode 100644 index 0000000000..c79de84aa5 --- /dev/null +++ b/google/cloud/aiplatform/metadata/experiment_resources.py @@ -0,0 +1,721 @@ +# -*- coding: utf-8 -*- + +# Copyright 2022 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. +# + +import abc +from dataclasses import dataclass +import logging +from typing import Dict, List, NamedTuple, Optional, Union, Tuple, Type + +from google.auth import credentials as auth_credentials + +from google.cloud.aiplatform import base +from google.cloud.aiplatform.metadata import artifact +from google.cloud.aiplatform.metadata import constants +from google.cloud.aiplatform.metadata import context +from google.cloud.aiplatform.metadata import execution +from google.cloud.aiplatform.metadata import metadata +from google.cloud.aiplatform.metadata import metadata_store +from google.cloud.aiplatform.metadata import resource +from google.cloud.aiplatform.metadata import utils as metadata_utils +from google.cloud.aiplatform.tensorboard import tensorboard_resource + +_LOGGER = base.Logger(__name__) + + +@dataclass +class _ExperimentRow: + """Class for representing a run row in an Experiments Dataframe. + + Attributes: + params (Dict[str, Union[float, int, str]]): Optional. The parameters of this run. + metrics (Dict[str, Union[float, int, str]]): Optional. The metrics of this run. + time_series_metrics (Dict[str, float]): Optional. The latest time series metrics of this run. + experiment_run_type (Optional[str]): Optional. The type of this run. + name (str): Optional. The name of this run. + state (str): Optional. The state of this run. + """ + + params: Optional[Dict[str, Union[float, int, str]]] = None + metrics: Optional[Dict[str, Union[float, int, str]]] = None + time_series_metrics: Optional[Dict[str, float]] = None + experiment_run_type: Optional[str] = None + name: Optional[str] = None + state: Optional[str] = None + + def to_dict(self) -> Dict[str, Union[float, int, str]]: + """Converts this experiment row into a dictionary. + + Returns: + Row as a dictionary. + """ + result = { + "run_type": self.experiment_run_type, + "run_name": self.name, + "state": self.state, + } + for prefix, field in [ + (constants._PARAM_PREFIX, self.params), + (constants._METRIC_PREFIX, self.metrics), + (constants._TIME_SERIES_METRIC_PREFIX, self.time_series_metrics), + ]: + if field: + result.update( + {f"{prefix}.{key}": value for key, value in field.items()} + ) + return result + + +class Experiment: + """Represents a Vertex AI Experiment resource.""" + + def __init__( + self, + experiment_name: str, + *, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ): + """ + + ``` + my_experiment = aiplatform.Experiment('my-experiment') + ``` + + Args: + experiment_name (str): Required. The name or resource name of this experiment. + + Resource name is of the format: projects/123/locations/us-central1/experiments/my-experiment + project (str): + Optional. Project where this experiment is located. Overrides project set in + aiplatform.init. + location (str): + Optional. Location where this experiment is located. Overrides location set in + aiplatform.init. + credentials (auth_credentials.Credentials): + Optional. Custom credentials used to retrieve this experiment. Overrides + credentials set in aiplatform.init. + """ + + metadata_args = dict( + resource_name=experiment_name, + project=project, + location=location, + credentials=credentials, + ) + + with _SetLoggerLevel(resource): + experiment_context = context._Context(**metadata_args) + self._validate_experiment_context(experiment_context) + + self._metadata_context = experiment_context + + @staticmethod + def _validate_experiment_context(experiment_context: context._Context): + """Validates this context is an experiment context. + + Args: + experiment_context (context._Context): Metadata context. + Raises: + ValueError: If Metadata context is not an experiment context or a TensorboardExperiment. + """ + if experiment_context.schema_title != constants.SYSTEM_EXPERIMENT: + raise ValueError( + f"Experiment name {experiment_context.name} is of type " + f"({experiment_context.schema_title}) in this MetadataStore. " + f"It must of type {constants.SYSTEM_EXPERIMENT}." + ) + if Experiment._is_tensorboard_experiment(experiment_context): + raise ValueError( + f"Experiment name {experiment_context.name} is a TensorboardExperiment context " + f"and cannot be used as a Vertex AI Experiment." + ) + + @staticmethod + def _is_tensorboard_experiment(context: context._Context) -> bool: + """Returns True if Experiment is a Tensorboard Experiment created by CustomJob.""" + return constants.TENSORBOARD_CUSTOM_JOB_EXPERIMENT_FIELD in context.metadata + + @property + def name(self) -> str: + """The name of this experiment.""" + return self._metadata_context.name + + @classmethod + def create( + cls, + experiment_name: str, + *, + description: Optional[str] = None, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ) -> "Experiment": + """Creates a new experiment in Vertex AI Experiments. + + ``` + my_experiment = aiplatform.Experiment.create('my-experiment', description='my description') + ``` + + Args: + experiment_name (str): Required. The name of this experiment. + description (str): Optional. Describes this experiment's purpose. + project (str): + Optional. Project where this experiment will be created. Overrides project set in + aiplatform.init. + location (str): + Optional. Location where this experiment will be created. Overrides location set in + aiplatform.init. + credentials (auth_credentials.Credentials): + Optional. Custom credentials used to create this experiment. Overrides + credentials set in aiplatform.init. + Returns: + The newly created experiment. + """ + + metadata_store._MetadataStore.ensure_default_metadata_store_exists( + project=project, location=location, credentials=credentials + ) + + with _SetLoggerLevel(resource): + experiment_context = context._Context._create( + resource_id=experiment_name, + display_name=experiment_name, + description=description, + schema_title=constants.SYSTEM_EXPERIMENT, + schema_version=metadata._get_experiment_schema_version(), + metadata=constants.EXPERIMENT_METADATA, + project=project, + location=location, + credentials=credentials, + ) + + self = cls.__new__() + self._metadata_context = experiment_context + + return self + + @classmethod + def get_or_create( + cls, + experiment_name: str, + *, + description: Optional[str] = None, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ) -> "Experiment": + """Gets experiment if one exists with this experiment_name in Vertex AI Experiments. + + Otherwise creates this experiment. + + ``` + my_experiment = aiplatform.Experiment.get_or_create('my-experiment', description='my description') + ``` + + Args: + experiment_name (str): Required. The name of this experiment. + description (str): Optional. Describes this experiment's purpose. + project (str): + Optional. Project where this experiment will be retrieved from or created. Overrides project set in + aiplatform.init. + location (str): + Optional. Location where this experiment will be retrieved from or created. Overrides location set in + aiplatform.init. + credentials (auth_credentials.Credentials): + Optional. Custom credentials used to retrieve or create this experiment. Overrides + credentials set in aiplatform.init. + Returns: + Vertex AI experiment. + """ + + metadata_store._MetadataStore.ensure_default_metadata_store_exists( + project=project, location=location, credentials=credentials + ) + + with _SetLoggerLevel(resource): + experiment_context = context._Context.get_or_create( + resource_id=experiment_name, + display_name=experiment_name, + description=description, + schema_title=constants.SYSTEM_EXPERIMENT, + schema_version=metadata._get_experiment_schema_version(), + metadata=constants.EXPERIMENT_METADATA, + project=project, + location=location, + credentials=credentials, + ) + + cls._validate_experiment_context(experiment_context) + + if description and description != experiment_context.description: + experiment_context.update(description=description) + + self = cls.__new__(cls) + self._metadata_context = experiment_context + + return self + + @classmethod + def list( + cls, + *, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ) -> List["Experiment"]: + """List all Vertex AI Experiments in the given project. + + ``` + my_experiments = aiplatform.Experiment.list() + ``` + + Args: + project (str): + Optional. Project to list these experiments from. Overrides project set in + aiplatform.init. + location (str): + Optional. Location to list these experiments from. Overrides location set in + aiplatform.init. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to list these experiments. Overrides + credentials set in aiplatform.init. + Returns: + List of Vertex AI experiments. + """ + + filter_str = metadata_utils._make_filter_string( + schema_title=constants.SYSTEM_EXPERIMENT + ) + + with _SetLoggerLevel(resource): + experiment_contexts = context._Context.list( + filter=filter_str, + project=project, + location=location, + credentials=credentials, + ) + + experiments = [] + for experiment_context in experiment_contexts: + # Filters Tensorboard Experiments + if not cls._is_tensorboard_experiment(experiment_context): + experiment = cls.__new__(cls) + experiment._metadata_context = experiment_context + experiments.append(experiment) + return experiments + + @property + def resource_name(self) -> str: + """The Metadata context resource name of this experiment.""" + return self._metadata_context.resource_name + + def delete(self, *, delete_backing_tensorboard_runs: bool = False): + """Deletes this experiment all the experiment runs under this experiment + + Does not delete Pipeline runs, Artifacts, or Executions associated to this experiment + or experiment runs in this experiment. + + ``` + my_experiment = aiplatform.Experiment('my-experiment') + my_experiment.delete(delete_backing_tensorboard_runs=True) + ``` + + Args: + delete_backing_tensorboard_runs (bool): + Optional. If True will also delete the Tensorboard Runs associated to the experiment + runs under this experiment that we used to store time series metrics. + """ + + experiment_runs = _SUPPORTED_LOGGABLE_RESOURCES[context._Context][ + constants.SYSTEM_EXPERIMENT_RUN + ].list(experiment=self) + for experiment_run in experiment_runs: + experiment_run.delete( + delete_backing_tensorboard_run=delete_backing_tensorboard_runs + ) + self._metadata_context.delete() + + def get_data_frame(self) -> "pd.DataFrame": # noqa: F821 + """Get parameters, metrics, and time series metrics of all runs in this experiment as Dataframe. + + ``` + my_experiment = aiplatform.Experiment('my-experiment') + df = my_experiment.get_data_frame() + ``` + + Returns: + pd.DataFrame: Pandas Dataframe of Experiment Runs. + + Raises: + ImportError: If pandas is not installed. + """ + try: + import pandas as pd + except ImportError: + raise ImportError( + "Pandas is not installed and is required to get dataframe as the return format. " + 'Please install the SDK using "pip install google-cloud-aiplatform[metadata]"' + ) + + service_request_args = dict( + project=self._metadata_context.project, + location=self._metadata_context.location, + credentials=self._metadata_context.credentials, + ) + + filter_str = metadata_utils._make_filter_string( + schema_title=sorted( + list(_SUPPORTED_LOGGABLE_RESOURCES[context._Context].keys()) + ), + parent_contexts=[self._metadata_context.resource_name], + ) + contexts = context._Context.list(filter_str, **service_request_args) + + filter_str = metadata_utils._make_filter_string( + schema_title=list( + _SUPPORTED_LOGGABLE_RESOURCES[execution.Execution].keys() + ), + in_context=[self._metadata_context.resource_name], + ) + + executions = execution.Execution.list(filter_str, **service_request_args) + + rows = [] + for metadata_context in contexts: + row_dict = ( + _SUPPORTED_LOGGABLE_RESOURCES[context._Context][ + metadata_context.schema_title + ] + ._query_experiment_row(metadata_context) + .to_dict() + ) + row_dict.update({"experiment_name": self.name}) + rows.append(row_dict) + + # backward compatibility + for metadata_execution in executions: + row_dict = ( + _SUPPORTED_LOGGABLE_RESOURCES[execution.Execution][ + metadata_execution.schema_title + ] + ._query_experiment_row(metadata_execution) + .to_dict() + ) + row_dict.update({"experiment_name": self.name}) + rows.append(row_dict) + + df = pd.DataFrame(rows) + + column_name_sort_map = { + "experiment_name": -1, + "run_name": 1, + "run_type": 2, + "state": 3, + } + + def column_sort_key(key: str) -> int: + """Helper method to reorder columns.""" + order = column_name_sort_map.get(key) + if order: + return order + elif key.startswith("param"): + return 5 + elif key.startswith("metric"): + return 6 + else: + return 7 + + columns = df.columns + columns = sorted(columns, key=column_sort_key) + df = df.reindex(columns, axis=1) + + return df + + def _lookup_backing_tensorboard(self) -> Optional[tensorboard_resource.Tensorboard]: + """Returns backing tensorboard if one is set. + + Returns: + Tensorboard resource if one exists. + """ + tensorboard_resource_name = self._metadata_context.metadata.get( + constants._BACKING_TENSORBOARD_RESOURCE_KEY + ) + + if not tensorboard_resource_name: + with _SetLoggerLevel(resource): + self._metadata_context.sync_resource() + tensorboard_resource_name = self._metadata_context.metadata.get( + constants._BACKING_TENSORBOARD_RESOURCE_KEY + ) + + if tensorboard_resource_name: + return tensorboard_resource.Tensorboard( + tensorboard_resource_name, + credentials=self._metadata_context.credentials, + ) + + def get_backing_tensorboard_resource( + self, + ) -> Optional[tensorboard_resource.Tensorboard]: + """Get the backing tensorboard for this experiment in one exists. + + ``` + my_experiment = aiplatform.Experiment('my-experiment') + tb = my_experiment.get_backing_tensorboard_resource() + ``` + + Returns: + Backing Tensorboard resource for this experiment if one exists. + """ + return self._lookup_backing_tensorboard() + + def assign_backing_tensorboard( + self, tensorboard: Union[tensorboard_resource.Tensorboard, str] + ): + """Assigns tensorboard as backing tensorboard to support time series metrics logging. + + ``` + tb = aiplatform.Tensorboard('tensorboard-resource-id') + my_experiment = aiplatform.Experiment('my-experiment') + my_experiment.assign_backing_tensorboard(tb) + ``` + + Args: + tensorboard (Union[aiplatform.Tensorboard, str]): + Required. Tensorboard resource or resource name to associate to this experiment. + + Raises: + ValueError: If this experiment already has a previously set backing tensorboard resource. + ValueError: If Tensorboard is not in same project and location as this experiment. + """ + + backing_tensorboard = self._lookup_backing_tensorboard() + if backing_tensorboard: + tensorboard_resource_name = ( + tensorboard + if isinstance(tensorboard, str) + else tensorboard.resource_name + ) + if tensorboard_resource_name != backing_tensorboard.resource_name: + raise ValueError( + f"Experiment {self._metadata_context.name} already associated '" + f"to tensorboard resource {backing_tensorboard.resource_name}" + ) + + if isinstance(tensorboard, str): + tensorboard = tensorboard_resource.Tensorboard( + tensorboard, + project=self._metadata_context.project, + location=self._metadata_context.location, + credentials=self._metadata_context.credentials, + ) + + if tensorboard.project not in self._metadata_context._project_tuple: + raise ValueError( + f"Tensorboard is in project {tensorboard.project} but must be in project {self._metadata_context.project}" + ) + if tensorboard.location != self._metadata_context.location: + raise ValueError( + f"Tensorboard is in location {tensorboard.location} but must be in location {self._metadata_context.location}" + ) + + self._metadata_context.update( + metadata={ + constants._BACKING_TENSORBOARD_RESOURCE_KEY: tensorboard.resource_name + } + ) + + def _log_experiment_loggable(self, experiment_loggable: "_ExperimentLoggable"): + """Associates a Vertex resource that can be logged to an Experiment as run of this experiment. + + Args: + experiment_loggable (_ExperimentLoggable): + A Vertex Resource that can be logged to an Experiment directly. + """ + context = experiment_loggable._get_context() + self._metadata_context.add_context_children([context]) + + +class _SetLoggerLevel: + """Helper method to suppress logging.""" + + def __init__(self, module): + self._module = module + + def __enter__(self): + logging.getLogger(self._module.__name__).setLevel(logging.WARNING) + + def __exit__(self, exc_type, exc_value, traceback): + logging.getLogger(self._module.__name__).setLevel(logging.INFO) + + +class _VertexResourceWithMetadata(NamedTuple): + """Represents a resource coupled with it's metadata representation""" + + resource: base.VertexAiResourceNoun + metadata: Union[artifact.Artifact, execution.Execution, context._Context] + + +class _ExperimentLoggableSchema(NamedTuple): + """Used with _ExperimentLoggable to capture Metadata representation information about resoure. + + For example: + _ExperimentLoggableSchema(title='system.PipelineRun', type=context._Context) + + Defines the schema and metadata type to lookup PipelineJobs. + """ + + title: str + type: Union[Type[context._Context], Type[execution.Execution]] = context._Context + + +class _ExperimentLoggable(abc.ABC): + """Abstract base class to define a Vertex Resource as loggable against an Experiment. + + For example: + class PipelineJob(..., experiment_loggable_schemas= + (_ExperimentLoggableSchema(title='system.PipelineRun'), ) + + """ + + def __init_subclass__( + cls, *, experiment_loggable_schemas: Tuple[_ExperimentLoggableSchema], **kwargs + ): + """Register the metadata_schema for the subclass so Experiment can use it to retrieve the associated types. + + usage: + + class PipelineJob(..., experiment_loggable_schemas= + (_ExperimentLoggableSchema(title='system.PipelineRun'), ) + + Args: + experiment_loggable_schemas: + Tuple of the schema_title and type pairs that represent this resource. Note that a single item in the + tuple will be most common. Currently only experiment run has multiple representation for backwards + compatibility. Almost all schemas should be Contexts and Execution is currently only supported + for backwards compatibility of experiment runs. + + """ + super().__init_subclass__(**kwargs) + + # register the type when module is loaded + for schema in experiment_loggable_schemas: + _SUPPORTED_LOGGABLE_RESOURCES[schema.type][schema.title] = cls + + @abc.abstractmethod + def _get_context(self) -> context._Context: + """Should return the metadata context that represents this resource. + + The subclass should enforce this context exists. + + Returns: + Context that represents this resource. + """ + pass + + @classmethod + @abc.abstractmethod + def _query_experiment_row( + cls, node: Union[context._Context, execution.Execution] + ) -> _ExperimentRow: + """Should return parameters and metrics for this resource as a run row. + + Args: + node: The metadata node that represents this resource. + Returns: + A populated run row for this resource. + """ + pass + + def _validate_experiment(self, experiment: Union[str, Experiment]): + """Validates experiment is accessible. Can be used by subclass to throw before creating the intended resource. + + Args: + experiment (Union[str, Experiment]): The experiment that this resource will be associated to. + + Raises: + RuntimeError: If service raises any exception when trying to access this experiment. + ValueError: If resource project or location do not match experiment project or location. + """ + + if isinstance(experiment, str): + try: + experiment = Experiment.get_or_create( + experiment, + project=self.project, + location=self.location, + credentials=self.credentials, + ) + except Exception as e: + raise RuntimeError( + f"Experiment {experiment} could not be found or created. {self.__class__.__name__} not created" + ) from e + + if self.project not in experiment._metadata_context._project_tuple: + raise ValueError( + f"{self.__class__.__name__} project {self.project} does not match experiment " + f"{experiment.name} project {experiment.project}" + ) + + if experiment._metadata_context.location != self.location: + raise ValueError( + f"{self.__class__.__name__} location {self.location} does not match experiment " + f"{experiment.name} location {experiment.location}" + ) + + def _associate_to_experiment(self, experiment: Union[str, Experiment]): + """Associates this resource to the provided Experiment. + + Args: + experiment (Union[str, Experiment]): Required. Experiment name or experiment instance. + + Raises: + RuntimeError: If Metadata service cannot associate resource to Experiment. + """ + experiment_name = experiment if isinstance(experiment, str) else experiment.name + _LOGGER.info( + "Associating %s to Experiment: %s" % (self.resource_name, experiment_name) + ) + + try: + if isinstance(experiment, str): + experiment = Experiment.get_or_create( + experiment, + project=self.project, + location=self.location, + credentials=self.credentials, + ) + experiment._log_experiment_loggable(self) + except Exception as e: + raise RuntimeError( + f"{self.resource_name} could not be associated with Experiment {experiment.name}" + ) from e + + +# maps context names to their resources classes +# used by the Experiment implementation to filter for representations in the metadata store +# populated at module import time from class that inherit _ExperimentLoggable +# example mapping: +# {Metadata Type} -> {schema title} -> {vertex sdk class} +# Context -> 'system.PipelineRun' -> aiplatform.PipelineJob +# Context -> 'system.ExperimentRun' -> aiplatform.ExperimentRun +# Execution -> 'system.Run' -> aiplatform.ExperimentRun +_SUPPORTED_LOGGABLE_RESOURCES: Dict[ + Union[Type[context._Context], Type[execution.Execution]], + Dict[str, _ExperimentLoggable], +] = {execution.Execution: dict(), context._Context: dict()} diff --git a/google/cloud/aiplatform/metadata/experiment_run_resource.py b/google/cloud/aiplatform/metadata/experiment_run_resource.py new file mode 100644 index 0000000000..b10a9d5dcb --- /dev/null +++ b/google/cloud/aiplatform/metadata/experiment_run_resource.py @@ -0,0 +1,1197 @@ +# -*- coding: utf-8 -*- + +# Copyright 2022 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. + +import collections +import concurrent.futures +import functools +from typing import Callable, Dict, List, Optional, Set, Union, Any + +from google.api_core import exceptions +from google.auth import credentials as auth_credentials +from google.protobuf import timestamp_pb2 + +from google.cloud.aiplatform import base +from google.cloud.aiplatform import initializer +from google.cloud.aiplatform import pipeline_jobs +from google.cloud.aiplatform.compat.types import artifact as gca_artifact +from google.cloud.aiplatform.compat.types import execution as gca_execution +from google.cloud.aiplatform.compat.types import ( + tensorboard_time_series as gca_tensorboard_time_series, +) +from google.cloud.aiplatform.metadata import artifact +from google.cloud.aiplatform.metadata import constants +from google.cloud.aiplatform.metadata import context +from google.cloud.aiplatform.metadata import execution +from google.cloud.aiplatform.metadata import experiment_resources +from google.cloud.aiplatform.metadata import metadata +from google.cloud.aiplatform.metadata import resource +from google.cloud.aiplatform.metadata import utils as metadata_utils +from google.cloud.aiplatform.tensorboard import tensorboard_resource +from google.cloud.aiplatform.utils import rest_utils + + +_LOGGER = base.Logger(__name__) + + +def _format_experiment_run_resource_id(experiment_name: str, run_name: str) -> str: + """Formats the the experiment run resource id as a concatenation of experiment name and run name. + + Args: + experiment_name (str): Name of the experiment which is it's resource id. + run_name (str): Name of the run. + Returns: + The resource id to be used with this run. + """ + return f"{experiment_name}-{run_name}" + + +def _v1_not_supported(method: Callable) -> Callable: + """Helpers wrapper for backward compatibility. Raises when using an API not support for legacy runs.""" + + @functools.wraps(method) + def wrapper(self, *args, **kwargs): + if isinstance(self._metadata_node, execution.Execution): + raise NotImplementedError( + f"{self._run_name} is an Execution run created during Vertex Experiment Preview and does not support" + f" {method.__name__}. Please create a new Experiment run to use this method." + ) + else: + return method(self, *args, **kwargs) + + return wrapper + + +class ExperimentRun( + experiment_resources._ExperimentLoggable, + experiment_loggable_schemas=( + experiment_resources._ExperimentLoggableSchema( + title=constants.SYSTEM_EXPERIMENT_RUN, type=context._Context + ), + # backwards compatibility with Preview Experiment runs + experiment_resources._ExperimentLoggableSchema( + title=constants.SYSTEM_RUN, type=execution.Execution + ), + ), +): + """A Vertex AI Experiment run""" + + def __init__( + self, + run_name: str, + experiment: Union[experiment_resources.Experiment, str], + *, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ): + """ + + ``` + my_run = aiplatform.ExperimentRun('my-run, experiment='my-experiment') + ``` + + Args: + run (str): Required. The name of this run. + experiment (Union[experiment_resources.Experiment, str]): + Required. The name or instance of this experiment. + project (str): + Optional. Project where this experiment run is located. Overrides project set in + aiplatform.init. + location (str): + Optional. Location where this experiment run is located. Overrides location set in + aiplatform.init. + credentials (auth_credentials.Credentials): + Optional. Custom credentials used to retrieve this experiment run. Overrides + credentials set in aiplatform.init. + """ + + self._experiment = self._get_experiment( + experiment=experiment, + project=project, + location=location, + credentials=credentials, + ) + self._run_name = run_name + + run_id = _format_experiment_run_resource_id( + experiment_name=self._experiment.name, run_name=run_name + ) + + metadata_args = dict( + project=project, + location=location, + credentials=credentials, + ) + + def _get_context() -> context._Context: + with experiment_resources._SetLoggerLevel(resource): + run_context = context._Context( + **{**metadata_args, "resource_name": run_id} + ) + if run_context.schema_title != constants.SYSTEM_EXPERIMENT_RUN: + raise ValueError( + f"Run {run_name} must be of type {constants.SYSTEM_EXPERIMENT_RUN}" + f" but is of type {run_context.schema_title}" + ) + return run_context + + try: + self._metadata_node = _get_context() + except exceptions.NotFound as context_not_found: + try: + # backward compatibility + self._v1_resolve_experiment_run( + { + **metadata_args, + "execution_name": run_id, + } + ) + except exceptions.NotFound: + raise context_not_found + else: + self._backing_tensorboard_run = self._lookup_tensorboard_run_artifact() + + # initially set to None. Will initially update from resource then track locally. + self._largest_step: Optional[int] = None + + def _v1_resolve_experiment_run(self, metadata_args: Dict[str, Any]): + """Resolves preview Experiment. + + Args: + metadata_args (Dict[str, Any): Arguments to pass to Execution constructor. + """ + + def _get_execution(): + with experiment_resources._SetLoggerLevel(resource): + run_execution = execution.Execution(**metadata_args) + if run_execution.schema_title != constants.SYSTEM_RUN: + # note this will raise the context not found exception in the constructor + raise exceptions.NotFound("Experiment run not found.") + return run_execution + + self._metadata_node = _get_execution() + self._metadata_metric_artifact = self._v1_get_metric_artifact() + + def _v1_get_metric_artifact(self) -> artifact.Artifact: + """Resolves metric artifact for backward compatibility. + + Returns: + Instance of Artifact that represents this run's metric artifact. + """ + metadata_args = dict( + artifact_name=self._v1_format_artifact_name(self._metadata_node.name), + project=self.project, + location=self.location, + credentials=self.credentials, + ) + + with experiment_resources._SetLoggerLevel(resource): + metric_artifact = artifact.Artifact(**metadata_args) + + if metric_artifact.schema_title != constants.SYSTEM_METRICS: + # note this will raise the context not found exception in the constructor + raise exceptions.NotFound("Experiment run not found.") + + return metric_artifact + + @staticmethod + def _v1_format_artifact_name(run_id: str) -> str: + """Formats resource id of legacy metric artifact for this run.""" + return f"{run_id}-metrics" + + def _get_context(self) -> context._Context: + """Returns this metadata context that represents this run. + + Returns: + Context instance of this run. + """ + return self._metadata_node + + @property + def resource_id(self) -> str: + """The resource ID of this experiment run's Metadata context. + + The resource ID is the final part of the resource name: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{resource ID}`` + """ + return self._metadata_node.name + + @property + def name(self) -> str: + """This run's name used to identify this run within it's Experiment.""" + return self._run_name + + @property + def resource_name(self) -> str: + """This run's Metadata context resource name. + + In the format: ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` + """ + return self._metadata_node.resource_name + + @property + def project(self) -> str: + """The project that this experiment run is located in.""" + return self._metadata_node.project + + @property + def location(self) -> str: + """The location that this experiment is located in.""" + return self._metadata_node.location + + @property + def credentials(self) -> auth_credentials.Credentials: + """The credentials used to access this experiment run.""" + return self._metadata_node.credentials + + @property + def state(self) -> gca_execution.Execution.State: + """The state of this run.""" + if self._is_legacy_experiment_run(): + return self._metadata_node.state + else: + return getattr( + gca_execution.Execution.State, + self._metadata_node.metadata[constants._STATE_KEY], + ) + + @staticmethod + def _get_experiment( + experiment: Optional[Union[experiment_resources.Experiment, str]] = None, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ) -> experiment_resources.Experiment: + """Helper method ot get the experiment by name(str) or instance. + + Args: + experiment(str): + Optional. The name of this experiment. Defaults to experiment set in aiplatform.init if not provided. + project (str): + Optional. Project where this experiment is located. Overrides project set in + aiplatform.init. + location (str): + Optional. Location where this experiment is located. Overrides location set in + aiplatform.init. + credentials (auth_credentials.Credentials): + Optional. Custom credentials used to retrieve this experiment. Overrides + credentials set in aiplatform.init. + Raises: + ValueError if experiment is None and experiment has not been set using aiplatform.init. + """ + + experiment = experiment or initializer.global_config.experiment + + if not experiment: + raise ValueError( + "experiment must be provided or experiment should be set using aiplatform.init" + ) + + if not isinstance(experiment, experiment_resources.Experiment): + experiment = experiment_resources.Experiment( + experiment_name=experiment, + project=project, + location=location, + credentials=credentials, + ) + return experiment + + def _is_backing_tensorboard_run_artifact(self, artifact: artifact.Artifact) -> bool: + """Helper method to confirm tensorboard run metadata artifact is this run's tensorboard artifact. + + Args: + artifact (artifact.Artifact): Required. Instance of metadata Artifact. + Returns: + bool whether the provided artifact is this run's TensorboardRun's artifact. + """ + return all( + [ + artifact.metadata.get(constants._VERTEX_EXPERIMENT_TRACKING_LABEL), + artifact.name == self._tensorboard_run_id(self._metadata_node.name), + artifact.schema_title + == constants._TENSORBOARD_RUN_REFERENCE_ARTIFACT.schema_title, + ] + ) + + def _is_legacy_experiment_run(self) -> bool: + """Helper method that return True if this is a legacy experiment run.""" + return isinstance(self._metadata_node, execution.Execution) + + def update_state(self, state: gca_execution.Execution.State): + """Update the state of this experiment run. + + ``` + my_run = aiplatform.ExperimentRun('my-run', experiment='my-experiment') + my_run.update_state(state=aiplatform.gapic.Execution.State.COMPLETE) + ``` + + Args: + state (aiplatform.gapic.Execution.State): State of this run. + """ + if self._is_legacy_experiment_run(): + self._metadata_node.update(state=state) + else: + self._metadata_node.update(metadata={constants._STATE_KEY: state.name}) + + def _lookup_tensorboard_run_artifact( + self, + ) -> Optional[experiment_resources._VertexResourceWithMetadata]: + """Helpers method to resolve this run's TensorboardRun Artifact if it exists. + + Returns: + Tuple of Tensorboard Run Artifact and TensorboardRun is it exists. + """ + with experiment_resources._SetLoggerLevel(resource): + try: + tensorboard_run_artifact = artifact.Artifact( + artifact_name=self._tensorboard_run_id(self._metadata_node.name), + project=self._metadata_node.project, + location=self._metadata_node.location, + credentials=self._metadata_node.credentials, + ) + except exceptions.NotFound: + tensorboard_run_artifact = None + + if tensorboard_run_artifact and self._is_backing_tensorboard_run_artifact( + tensorboard_run_artifact + ): + return experiment_resources._VertexResourceWithMetadata( + resource=tensorboard_resource.TensorboardRun( + tensorboard_run_artifact.metadata[ + constants.GCP_ARTIFACT_RESOURCE_NAME_KEY + ] + ), + metadata=tensorboard_run_artifact, + ) + + @classmethod + def list( + cls, + *, + experiment: Optional[Union[experiment_resources.Experiment, str]] = None, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ) -> List["ExperimentRun"]: + """List the experiment runs for a given aiplatform.Experiment. + + ``` + my_runs = aiplatform.ExperimentRun.list(experiment='my-experiment') + ``` + + Args: + experiment (Union[aiplatform.Experiment, str]): + Optional. The experiment name or instance to list the experiment run from. If not provided, + will use the experiment set in aiplatform.init. + project (str): + Optional. Project where this experiment is located. Overrides project set in + aiplatform.init. + location (str): + Optional. Location where this experiment is located. Overrides location set in + aiplatform.init. + credentials (auth_credentials.Credentials): + Optional. Custom credentials used to retrieve this experiment. Overrides + credentials set in aiplatform.init. + Returns: + List of experiment runs. + """ + + experiment = cls._get_experiment( + experiment=experiment, + project=project, + location=location, + credentials=credentials, + ) + + metadata_args = dict( + project=experiment._metadata_context.project, + location=experiment._metadata_context.location, + credentials=experiment._metadata_context.credentials, + ) + + filter_str = metadata_utils._make_filter_string( + schema_title=constants.SYSTEM_EXPERIMENT_RUN, + parent_contexts=[experiment.resource_name], + ) + + run_contexts = context._Context.list(filter=filter_str, **metadata_args) + + filter_str = metadata_utils._make_filter_string( + schema_title=constants.SYSTEM_RUN, in_context=[experiment.resource_name] + ) + + run_executions = execution.Execution.list(filter=filter_str, **metadata_args) + + def _initialize_experiment_run(context: context._Context) -> ExperimentRun: + this_experiment_run = cls.__new__(cls) + this_experiment_run._experiment = experiment + this_experiment_run._run_name = context.display_name + this_experiment_run._metadata_node = context + + with experiment_resources._SetLoggerLevel(resource): + tb_run = this_experiment_run._lookup_tensorboard_run_artifact() + if tb_run: + this_experiment_run._backing_tensorboard_run = tb_run + else: + this_experiment_run._backing_tensorboard_run = None + + this_experiment_run._largest_step = None + + return this_experiment_run + + def _initialize_v1_experiment_run( + execution: execution.Execution, + ) -> ExperimentRun: + this_experiment_run = cls.__new__(cls) + this_experiment_run._experiment = experiment + this_experiment_run._run_name = execution.display_name + this_experiment_run._metadata_node = execution + this_experiment_run._metadata_metric_artifact = ( + this_experiment_run._v1_get_metric_artifact() + ) + + return this_experiment_run + + if run_contexts or run_executions: + with concurrent.futures.ThreadPoolExecutor( + max_workers=max([len(run_contexts), len(run_executions)]) + ) as executor: + submissions = [ + executor.submit(_initialize_experiment_run, context) + for context in run_contexts + ] + experiment_runs = [submission.result() for submission in submissions] + + submissions = [ + executor.submit(_initialize_v1_experiment_run, execution) + for execution in run_executions + ] + + for submission in submissions: + experiment_runs.append(submission.result()) + + return experiment_runs + else: + return [] + + @classmethod + def _query_experiment_row( + cls, node: Union[context._Context, execution.Execution] + ) -> experiment_resources._ExperimentRow: + """Retrieves the runs metric and parameters into an experiment run row. + + Args: + node (Union[context._Context, execution.Execution]): + Required. Metadata node instance that represents this run. + Returns: + Experiment run row that represents this run. + """ + this_experiment_run = cls.__new__(cls) + this_experiment_run._metadata_node = node + + row = experiment_resources._ExperimentRow( + experiment_run_type=node.schema_title, + name=node.display_name, + ) + + if isinstance(node, context._Context): + this_experiment_run._backing_tensorboard_run = ( + this_experiment_run._lookup_tensorboard_run_artifact() + ) + row.params = node.metadata[constants._PARAM_KEY] + row.metrics = node.metadata[constants._METRIC_KEY] + row.time_series_metrics = ( + this_experiment_run._get_latest_time_series_metric_columns() + ) + row.state = node.metadata[constants._STATE_KEY] + else: + this_experiment_run._metadata_metric_artifact = ( + this_experiment_run._v1_get_metric_artifact() + ) + row.params = node.metadata + row.metrics = this_experiment_run._metadata_metric_artifact.metadata + row.state = node.state.name + return row + + def _get_logged_pipeline_runs(self) -> List[context._Context]: + """Returns Pipeline Run contexts logged to this Experiment Run. + + Returns: + List of Pipeline system.PipelineRun contexts. + """ + + service_request_args = dict( + project=self._metadata_node.project, + location=self._metadata_node.location, + credentials=self._metadata_node.credentials, + ) + + filter_str = metadata_utils._make_filter_string( + schema_title=constants.SYSTEM_PIPELINE_RUN, + parent_contexts=[self._metadata_node.resource_name], + ) + + return context._Context.list(filter=filter_str, **service_request_args) + + def _get_latest_time_series_metric_columns(self) -> Dict[str, Union[float, int]]: + """Determines the latest step for each time series metric. + + Returns: + Dictionary mapping time series metric key to the latest step of that metric. + """ + if self._backing_tensorboard_run: + time_series_metrics = ( + self._backing_tensorboard_run.resource.read_time_series_data() + ) + + return { + display_name: data.values[-1].scalar.value + for display_name, data in time_series_metrics.items() + if data.value_type + == gca_tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR + } + return {} + + def _log_pipeline_job(self, pipeline_job: pipeline_jobs.PipelineJob): + """Associate this PipelineJob's Context to the current ExperimentRun Context as a child context. + + Args: + pipeline_job (pipeline_jobs.PipelineJob): + Required. The PipelineJob to associate. + """ + + pipeline_job_context = pipeline_job._get_context() + self._metadata_node.add_context_children([pipeline_job_context]) + + @_v1_not_supported + def log( + self, + *, + pipeline_job: Optional[pipeline_jobs.PipelineJob] = None, + ): + """Log a Vertex Resource to this experiment run. + + ``` + my_run = aiplatform.ExperimentRun('my-run', experiment='my-experiment') + my_job = aiplatform.PipelineJob(...) + my_job.submit() + my_run.log(my_job) + ``` + + Args: + pipeline_job (aiplatform.PipelineJob): Optional. A Vertex PipelineJob. + """ + if pipeline_job: + self._log_pipeline_job(pipeline_job=pipeline_job) + + @staticmethod + def _validate_run_id(run_id: str): + """Validates the run id + + Args: + run_id(str): Required. The run id to validate. + Raises: + ValueError if run id is too long. + """ + + if len(run_id) > 128: + raise ValueError( + f"Length of Experiment ID and Run ID cannot be greater than 128. " + f"{run_id} is of length {len(run_id)}" + ) + + @classmethod + def create( + cls, + run_name: str, + *, + experiment: Optional[Union[experiment_resources.Experiment, str]] = None, + tensorboard: Optional[Union[tensorboard_resource.Tensorboard, str]] = None, + state: gca_execution.Execution.State = gca_execution.Execution.State.RUNNING, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ) -> "ExperimentRun": + """Creates a new experiment run in Vertex AI Experiments. + + ``` + my_run = aiplatform.ExperimentRun.create('my-run', experiment='my-experiment') + ``` + + Args: + run_name (str): Required. The name of this run. + experiment (Union[aiplatform.Experiment, str]): + Optional. The name or instance of the experiment to create this run under. + If not provided, will default to the experiment set in `aiplatform.init`. + tensorboard (Union[aiplatform.Tensorboard, str]): + Optional. The resource name or instance of Vertex Tensorbaord to use as the backing + Tensorboard for time series metric logging. If not provided, will default to the + the backing tensorboard of parent experiment if set. Must be in same project and location + as this experiment run. + state (aiplatform.gapic.Execution.State): + Optional. The state of this run. Defaults to RUNNING. + project (str): + Optional. Project where this experiment will be created. Overrides project set in + aiplatform.init. + location (str): + Optional. Location where this experiment will be created. Overrides location set in + aiplatform.init. + credentials (auth_credentials.Credentials): + Optional. Custom credentials used to create this experiment. Overrides + credentials set in aiplatform.init. + Returns: + The newly created experiment run. + """ + + experiment = cls._get_experiment(experiment) + + run_id = _format_experiment_run_resource_id( + experiment_name=experiment.name, run_name=run_name + ) + + cls._validate_run_id(run_id) + + def _create_context(): + with experiment_resources._SetLoggerLevel(resource): + return context._Context._create( + resource_id=run_id, + display_name=run_name, + schema_title=constants.SYSTEM_EXPERIMENT_RUN, + schema_version=constants.SCHEMA_VERSIONS[ + constants.SYSTEM_EXPERIMENT_RUN + ], + metadata={ + constants._PARAM_KEY: {}, + constants._METRIC_KEY: {}, + constants._STATE_KEY: state.name, + }, + project=project, + location=location, + credentials=credentials, + ) + + metadata_context = _create_context() + + if metadata_context is None: + raise RuntimeError( + f"Experiment Run with name {run_name} in {experiment.name} already exists." + ) + + experiment_run = cls.__new__(cls) + experiment_run._experiment = experiment + experiment_run._run_name = metadata_context.display_name + experiment_run._metadata_node = metadata_context + experiment_run._backing_tensorboard_run = None + experiment_run._largest_step = None + + if tensorboard: + cls._assign_backing_tensorboard( + self=experiment_run, tensorboard=tensorboard + ) + else: + cls._assign_to_experiment_backing_tensorboard(self=experiment_run) + + experiment_run._associate_to_experiment(experiment) + return experiment_run + + def _assign_to_experiment_backing_tensorboard(self): + """Assigns parent Experiment backing tensorboard resource to this Experiment Run.""" + backing_tensorboard_resource = ( + self._experiment.get_backing_tensorboard_resource() + ) + + if backing_tensorboard_resource: + self.assign_backing_tensorboard(tensorboard=backing_tensorboard_resource) + + @staticmethod + def _format_tensorboard_experiment_display_name(experiment_name: str) -> str: + """Formats Tensorboard experiment name that backs this run. + Args: + experiment_name (str): Required. The name of the experiment. + Returns: + Formatted Tensorboard Experiment name + """ + # post fix helps distinguish from the Vertex Experiment in console + return f"{experiment_name} Backing Tensorboard Experiment" + + def _assign_backing_tensorboard( + self, tensorboard: Union[tensorboard_resource.Tensorboard, str] + ): + """Assign tensorboard as the backing tensorboard to this run. + + Args: + tensorboard (Union[tensorboard_resource.Tensorboard, str]): + Required. Tensorboard instance or resource name. + """ + if isinstance(tensorboard, str): + tensorboard = tensorboard_resource.Tensorboard( + tensorboard, credentials=self._metadata_node.credentials + ) + + tensorboard_resource_name_parts = tensorboard._parse_resource_name( + tensorboard.resource_name + ) + tensorboard_experiment_resource_name = ( + tensorboard_resource.TensorboardExperiment._format_resource_name( + experiment=self._experiment.name, **tensorboard_resource_name_parts + ) + ) + try: + tensorboard_experiment = tensorboard_resource.TensorboardExperiment( + tensorboard_experiment_resource_name, + credentials=tensorboard.credentials, + ) + except exceptions.NotFound: + with experiment_resources._SetLoggerLevel(tensorboard_resource): + tensorboard_experiment = ( + tensorboard_resource.TensorboardExperiment.create( + tensorboard_experiment_id=self._experiment.name, + display_name=self._format_tensorboard_experiment_display_name( + self._experiment.name + ), + tensorboard_name=tensorboard.resource_name, + credentials=tensorboard.credentials, + ) + ) + + tensorboard_experiment_name_parts = tensorboard_experiment._parse_resource_name( + tensorboard_experiment.resource_name + ) + tensorboard_run_resource_name = ( + tensorboard_resource.TensorboardRun._format_resource_name( + run=self._run_name, **tensorboard_experiment_name_parts + ) + ) + try: + tensorboard_run = tensorboard_resource.TensorboardRun( + tensorboard_run_resource_name + ) + except exceptions.NotFound: + with experiment_resources._SetLoggerLevel(tensorboard_resource): + tensorboard_run = tensorboard_resource.TensorboardRun.create( + tensorboard_run_id=self._run_name, + tensorboard_experiment_name=tensorboard_experiment.resource_name, + credentials=tensorboard.credentials, + ) + + gcp_resource_url = rest_utils.make_gcp_resource_rest_url(tensorboard_run) + + with experiment_resources._SetLoggerLevel(resource): + tensorboard_run_metadata_artifact = artifact.Artifact._create( + uri=gcp_resource_url, + resource_id=self._tensorboard_run_id(self._metadata_node.name), + metadata={ + "resourceName": tensorboard_run.resource_name, + constants._VERTEX_EXPERIMENT_TRACKING_LABEL: True, + }, + schema_title=constants._TENSORBOARD_RUN_REFERENCE_ARTIFACT.schema_title, + schema_version=constants._TENSORBOARD_RUN_REFERENCE_ARTIFACT.schema_version, + state=gca_artifact.Artifact.State.LIVE, + ) + + self._metadata_node.add_artifacts_and_executions( + artifact_resource_names=[tensorboard_run_metadata_artifact.resource_name] + ) + + self._backing_tensorboard_run = ( + experiment_resources._VertexResourceWithMetadata( + resource=tensorboard_run, metadata=tensorboard_run_metadata_artifact + ) + ) + + @staticmethod + def _tensorboard_run_id(run_id: str) -> str: + """Helper method to format the tensorboard run artifact resource id for a run. + + Args: + run_id: The resource id of the experiment run. + + Returns: + Resource id for the associated tensorboard run artifact. + """ + return f"{run_id}-tb-run" + + @_v1_not_supported + def assign_backing_tensorboard( + self, tensorboard: Union[tensorboard_resource.Tensorboard, str] + ): + """Assigns tensorboard as backing tensorboard to support timeseries metrics logging for this run. + + Args: + tensorboard (Union[aiplatform.Tensorboard, str]): + Required. Tensorboard instance or resource name. + """ + + backing_tensorboard = self._lookup_tensorboard_run_artifact() + if backing_tensorboard: + raise ValueError( + f"Experiment run {self._run_name} already associated to tensorboard resource {backing_tensorboard.resource.resource_name}" + ) + + self._assign_backing_tensorboard(tensorboard=tensorboard) + + def _get_latest_time_series_step(self) -> int: + """Gets latest time series step of all time series from Tensorboard resource. + + Returns: + Latest step of all time series metrics. + """ + data = self._backing_tensorboard_run.resource.read_time_series_data() + return max(ts.values[-1].step if ts.values else 0 for ts in data.values()) + + @_v1_not_supported + def log_time_series_metrics( + self, + metrics: Dict[str, float], + step: Optional[int] = None, + wall_time: Optional[timestamp_pb2.Timestamp] = None, + ): + """Logs time series metrics to backing TensorboardRun of this Experiment Run. + + ``` + run.log_time_series_metrics({'accuracy': 0.9}, step=10) + ``` + + Args: + metrics (Dict[str, Union[str, float]]): + Required. Dictionary of where keys are metric names and values are metric values. + step (int): + Optional. Step index of this data point within the run. + + If not provided, the latest + step amongst all time series metrics already logged will be used. + wall_time (timestamp_pb2.Timestamp): + Optional. Wall clock timestamp when this data point is + generated by the end user. + + If not provided, this will be generated based on the value from time.time() + Raises: + RuntimeError: If current experiment run doesn't have a backing Tensorboard resource. + """ + + if not self._backing_tensorboard_run: + self._assign_to_experiment_backing_tensorboard() + if not self._backing_tensorboard_run: + raise RuntimeError( + "Please set this experiment run with backing tensorboard resource to use log_time_series_metrics." + ) + + self._soft_create_time_series(metric_keys=set(metrics.keys())) + + if not step: + step = self._largest_step or self._get_latest_time_series_step() + step += 1 + self._largest_step = step + + self._backing_tensorboard_run.resource.write_tensorboard_scalar_data( + time_series_data=metrics, step=step, wall_time=wall_time + ) + + def _soft_create_time_series(self, metric_keys: Set[str]): + """Creates TensorboardTimeSeries for the metric keys if one currently does not exist. + + Args: + metric_keys (Set[str]): Keys of the metrics. + """ + + if any( + key + not in self._backing_tensorboard_run.resource._time_series_display_name_to_id_mapping + for key in metric_keys + ): + self._backing_tensorboard_run.resource._sync_time_series_display_name_to_id_mapping() + + for key in metric_keys: + if ( + key + not in self._backing_tensorboard_run.resource._time_series_display_name_to_id_mapping + ): + with experiment_resources._SetLoggerLevel(tensorboard_resource): + self._backing_tensorboard_run.resource.create_tensorboard_time_series( + display_name=key + ) + + def log_params(self, params: Dict[str, Union[float, int, str]]): + """Log single or multiple parameters with specified key value pairs. + + Parameters with the same key will be overwritten. + + ``` + my_run = aiplatform.ExperimentRun('my-run', experiment='my-experiment') + my_run.log_params({'learning_rate': 0.1, 'dropout_rate': 0.2}) + ``` + + Args: + params (Dict[str, Union[float, int, str]]): + Required. Parameter key/value pairs. + + Raises: + ValueError: If key is not str or value is not float, int, str. + """ + # query the latest run execution resource before logging. + for key, value in params.items(): + if not isinstance(key, str): + raise TypeError( + f"{key} is of type {type(key).__name__} must of type str" + ) + if not isinstance(value, (float, int, str)): + raise TypeError( + f"Value for key {key} is of type {type(value).__name__} but must be one of float, int, str" + ) + + if self._is_legacy_experiment_run(): + self._metadata_node.update(metadata=params) + else: + self._metadata_node.update(metadata={constants._PARAM_KEY: params}) + + def log_metrics(self, metrics: Dict[str, Union[float, int, str]]): + """Log single or multiple Metrics with specified key and value pairs. + + Metrics with the same key will be overwritten. + + ``` + my_run = aiplatform.ExperimentRun('my-run', experiment='my-experiment') + my_run.log_metrics({'accuracy': 0.9, 'recall': 0.8}) + ``` + + Args: + metrics (Dict[str, Union[float, int]]): + Required. Metrics key/value pairs. + Raises: + TypeError: If keys are not str or values are not float, int, or str. + """ + for key, value in metrics.items(): + if not isinstance(key, str): + raise TypeError( + f"{key} is of type {type(key).__name__} must of type str" + ) + if not isinstance(value, (float, int, str)): + raise TypeError( + f"Value for key {key} is of type {type(value).__name__} but must be one of float, int, str" + ) + + if self._is_legacy_experiment_run(): + self._metadata_metric_artifact.update(metadata=metrics) + else: + # TODO: query the latest metrics artifact resource before logging. + self._metadata_node.update(metadata={constants._METRIC_KEY: metrics}) + + @_v1_not_supported + def get_time_series_data_frame(self) -> "pd.DataFrame": # noqa: F821 + """Returns all time series in this Run as a DataFrame. + + Returns: + pd.DataFrame: Time series metrics in this Run as a Dataframe. + """ + try: + import pandas as pd + except ImportError: + raise ImportError( + "Pandas is not installed and is required to get dataframe as the return format. " + 'Please install the SDK using "pip install google-cloud-aiplatform[metadata]"' + ) + + if not self._backing_tensorboard_run: + return pd.DataFrame({}) + data = self._backing_tensorboard_run.resource.read_time_series_data() + + if not data: + return pd.DataFrame({}) + + return ( + pd.DataFrame( + { + name: entry.scalar.value, + "step": entry.step, + "wall_time": entry.wall_time, + } + for name, ts in data.items() + for entry in ts.values + ) + .groupby(["step", "wall_time"]) + .first() + .reset_index() + ) + + @_v1_not_supported + def get_logged_pipeline_jobs(self) -> List[pipeline_jobs.PipelineJob]: + """Get all PipelineJobs associated to this experiment run. + + Returns: + List of PipelineJobs associated this run. + """ + + pipeline_job_contexts = self._get_logged_pipeline_runs() + + return [ + pipeline_jobs.PipelineJob.get( + c.display_name, + project=c.project, + location=c.location, + credentials=c.credentials, + ) + for c in pipeline_job_contexts + ] + + def __enter__(self): + return self + + def __exit__(self, exc_type, exc_value, traceback): + state = ( + gca_execution.Execution.State.FAILED + if exc_type + else gca_execution.Execution.State.COMPLETE + ) + + if metadata._experiment_tracker.experiment_run is self: + metadata._experiment_tracker.end_run(state=state) + else: + self.end_run(state) + + def end_run( + self, + *, + state: gca_execution.Execution.State = gca_execution.Execution.State.COMPLETE, + ): + """Ends this experiment run and sets state to COMPLETE. + + Args: + state (aiplatform.gapic.Execution.State): + Optional. Override the state at the end of run. Defaults to COMPLETE. + """ + self.update_state(state) + + def delete(self, *, delete_backing_tensorboard_run: bool = False): + """Deletes this experiment run. + + Does not delete the executions, artifacts, or resources logged to this run. + + Args: + delete_backing_tensorboard_run (bool): + Optional. Whether to delete the backing tensorboard run that stores time series metrics for this run. + """ + if delete_backing_tensorboard_run: + if not self._is_legacy_experiment_run(): + if not self._backing_tensorboard_run: + self._backing_tensorboard_run = ( + self._lookup_tensorboard_run_artifact() + ) + if self._backing_tensorboard_run: + self._backing_tensorboard_run.resource.delete() + self._backing_tensorboard_run.metadata.delete() + else: + _LOGGER.warn( + f"Experiment run {self.name} does not have a backing tensorboard run." + " Skipping deletion." + ) + else: + _LOGGER.warn( + f"Experiment run {self.name} does not have a backing tensorboard run." + " Skipping deletion." + ) + + self._metadata_node.delete() + + if self._is_legacy_experiment_run(): + self._metadata_metric_artifact.delete() + + @_v1_not_supported + def get_artifacts(self) -> List[artifact.Artifact]: + """Get the list of artifacts associated to this run. + + Returns: + List of artifacts associated to this run. + """ + return self._metadata_node.get_artifacts() + + @_v1_not_supported + def get_executions(self) -> List[execution.Execution]: + """Get the List of Executions associated to this run + + Returns: + List of executions associated to this run. + """ + return self._metadata_node.get_executions() + + def get_params(self) -> Dict[str, Union[int, float, str]]: + """Get the parameters logged to this run. + + Returns: + Parameters logged to this experiment run. + """ + if self._is_legacy_experiment_run(): + return self._metadata_node.metadata + else: + return self._metadata_node.metadata[constants._PARAM_KEY] + + def get_metrics(self) -> Dict[str, Union[float, int, str]]: + """Get the summary metrics logged to this run. + + Returns: + Summary metrics logged to this experiment run. + """ + if self._is_legacy_experiment_run(): + return self._metadata_metric_artifact.metadata + else: + return self._metadata_node.metadata[constants._METRIC_KEY] + + @_v1_not_supported + def associate_execution(self, execution: execution.Execution): + """Associate an execution to this experiment run. + + Args: + execution (aiplatform.Execution): Execution to associate to this run. + """ + self._metadata_node.add_artifacts_and_executions( + execution_resource_names=[execution.resource_name] + ) + + def _association_wrapper(self, f: Callable[..., Any]) -> Callable[..., Any]: + """Wraps methods and automatically associates all passed in Artifacts or Executions to this ExperimentRun. + + This is used to wrap artifact passing methods of Executions so they get associated to this run. + """ + + @functools.wraps(f) + def wrapper(*args, **kwargs): + artifacts = [] + executions = [] + for value in [*args, *kwargs.values()]: + value = value if isinstance(value, collections.Iterable) else [value] + for item in value: + if isinstance(item, execution.Execution): + executions.append(item) + elif isinstance(item, artifact.Artifact): + artifacts.append(item) + elif artifact._VertexResourceArtifactResolver.supports_metadata( + item + ): + artifacts.append( + artifact._VertexResourceArtifactResolver.resolve_or_create_resource_artifact( + item + ) + ) + + if artifacts or executions: + self._metadata_node.add_artifacts_and_executions( + artifact_resource_names=[a.resource_name for a in artifacts], + execution_resource_names=[e.resource_name for e in executions], + ) + + result = f(*args, **kwargs) + return result + + return wrapper diff --git a/google/cloud/aiplatform/metadata/metadata.py b/google/cloud/aiplatform/metadata/metadata.py index 919eff8619..f321a622b3 100644 --- a/google/cloud/aiplatform/metadata/metadata.py +++ b/google/cloud/aiplatform/metadata/metadata.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2021 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,363 +15,634 @@ # limitations under the License. # -from typing import Dict, Union, Optional +from typing import Dict, Union, Optional, Any + +from google.api_core import exceptions +from google.auth import credentials as auth_credentials +from google.protobuf import timestamp_pb2 + +from google.cloud.aiplatform import base +from google.cloud.aiplatform import gapic +from google.cloud.aiplatform import pipeline_jobs +from google.cloud.aiplatform.compat.types import execution as gca_execution from google.cloud.aiplatform.metadata import constants -from google.cloud.aiplatform.metadata.artifact import _Artifact -from google.cloud.aiplatform.metadata.context import _Context -from google.cloud.aiplatform.metadata.execution import _Execution -from google.cloud.aiplatform.metadata.metadata_store import _MetadataStore +from google.cloud.aiplatform.metadata import context +from google.cloud.aiplatform.metadata import execution +from google.cloud.aiplatform.metadata import experiment_resources +from google.cloud.aiplatform.metadata import experiment_run_resource +from google.cloud.aiplatform.tensorboard import tensorboard_resource + +_LOGGER = base.Logger(__name__) + + +def _get_experiment_schema_version() -> str: + """Helper method to get experiment schema version + Returns: + str: schema version of the currently set experiment tracking version + """ + return constants.SCHEMA_VERSIONS[constants.SYSTEM_EXPERIMENT] -class _MetadataService: + +# Legacy Experiment tracking +# Maintaining creation APIs for backwards compatibility testing +class _LegacyExperimentService: """Contains the exposed APIs to interact with the Managed Metadata Service.""" + @staticmethod + def get_pipeline_df(pipeline: str) -> "pd.DataFrame": # noqa: F821 + """Returns a Pandas DataFrame of the parameters and metrics associated with one pipeline. + + Args: + pipeline: Name of the Pipeline to filter results. + + Returns: + Pandas Dataframe of Pipeline with metrics and parameters. + """ + + source = "pipeline" + pipeline_resource_name = ( + _LegacyExperimentService._get_experiment_or_pipeline_resource_name( + name=pipeline, source=source, expected_schema=constants.SYSTEM_PIPELINE + ) + ) + + return _LegacyExperimentService._query_runs_to_data_frame( + context_id=pipeline, + context_resource_name=pipeline_resource_name, + source=source, + ) + + @staticmethod + def _get_experiment_or_pipeline_resource_name( + name: str, source: str, expected_schema: str + ) -> str: + """Get the full resource name of the Context representing an Experiment or Pipeline. + + Args: + name (str): + Name of the Experiment or Pipeline. + source (str): + Identify whether the this is an Experiment or a Pipeline. + expected_schema (str): + expected_schema identifies the expected schema used for Experiment or Pipeline. + + Returns: + The full resource name of the Experiment or Pipeline Context. + + Raise: + NotFound exception if experiment or pipeline does not exist. + """ + + this_context = context._Context(resource_name=name) + + if this_context.schema_title != expected_schema: + raise ValueError( + f"Please provide a valid {source} name. {name} is not a {source}." + ) + return this_context.resource_name + + @staticmethod + def _query_runs_to_data_frame( + context_id: str, context_resource_name: str, source: str + ) -> "pd.DataFrame": # noqa: F821 + """Get metrics and parameters associated with a given Context into a Dataframe. + + Args: + context_id (str): + Name of the Experiment or Pipeline. + context_resource_name (str): + Full resource name of the Context associated with an Experiment or Pipeline. + source (str): + Identify whether the this is an Experiment or a Pipeline. + + Returns: + The full resource name of the Experiment or Pipeline Context. + """ + + try: + import pandas as pd + except ImportError: + raise ImportError( + "Pandas is not installed and is required to get dataframe as the return format. " + 'Please install the SDK using "pip install google-cloud-aiplatform[metadata]"' + ) + + filter = f'schema_title="{constants.SYSTEM_RUN}" AND in_context("{context_resource_name}")' + run_executions = execution.Execution.list(filter=filter) + + context_summary = [] + for run_execution in run_executions: + run_dict = { + f"{source}_name": context_id, + "run_name": run_execution.display_name, + } + run_dict.update( + _LegacyExperimentService._execution_to_column_named_metadata( + "param", run_execution.metadata + ) + ) + + for metric_artifact in run_execution.get_output_artifacts(): + run_dict.update( + _LegacyExperimentService._execution_to_column_named_metadata( + "metric", metric_artifact.metadata + ) + ) + + context_summary.append(run_dict) + + return pd.DataFrame(context_summary) + + @staticmethod + def _execution_to_column_named_metadata( + metadata_type: str, metadata: Dict, filter_prefix: Optional[str] = None + ) -> Dict[str, Union[int, float, str]]: + """Returns a dict of the Execution/Artifact metadata with column names. + + Args: + metadata_type: The type of this execution properties (param, metric). + metadata: Either an Execution or Artifact metadata field. + filter_prefix: + Remove this prefix from the key of metadata field. Mainly used for removing + "input:" from PipelineJob parameter keys + + Returns: + Dict of custom properties with keys mapped to column names + """ + column_key_to_value = {} + for key, value in metadata.items(): + if filter_prefix and key.startswith(filter_prefix): + key = key[len(filter_prefix) :] + column_key_to_value[".".join([metadata_type, key])] = value + + return column_key_to_value + + +class _ExperimentTracker: + """Tracks Experiments and Experiment Runs wil high level APIs""" + def __init__(self): - self._experiment = None - self._run = None - self._metrics = None + self._experiment: Optional[experiment_resources.Experiment] = None + self._experiment_run: Optional[experiment_run_resource.ExperimentRun] = None def reset(self): - """Reset all _MetadataService fields to None""" + """Resets this experiment tracker, clearing the current experiment and run.""" self._experiment = None - self._run = None - self._metrics = None + self._experiment_run = None @property def experiment_name(self) -> Optional[str]: - """Return the experiment name of the _MetadataService, if experiment is not set, return None""" + """Return the currently set experiment name, if experiment is not set, return None""" if self._experiment: - return self._experiment.display_name + return self._experiment.name return None @property - def run_name(self) -> Optional[str]: - """Return the run name of the _MetadataService, if run is not set, return None""" - if self._run: - return self._run.display_name - return None + def experiment(self) -> Optional[experiment_resources.Experiment]: + "Returns the currently set Experiment." + return self._experiment - def set_experiment(self, experiment: str, description: Optional[str] = None): - """Setup a experiment to current session. + @property + def experiment_run(self) -> Optional[experiment_run_resource.ExperimentRun]: + """Returns the currently set experiment run.""" + return self._experiment_run + + def set_experiment( + self, + experiment: str, + *, + description: Optional[str] = None, + backing_tensorboard: Optional[ + Union[str, tensorboard_resource.Tensorboard] + ] = None, + ): + """Set the experiment. Will retrieve the Experiment if it exists or create one with the provided name. Args: experiment (str): - Required. Name of the experiment to assign current session with. + Required. Name of the experiment to set. description (str): Optional. Description of an experiment. + backing_tensorboard Union[str, aiplatform.Tensorboard]: + Optional. If provided, assigns tensorboard as backing tensorboard to support time series metrics + logging. """ + self.reset() - _MetadataStore.get_or_create() - context = _Context.get_or_create( - resource_id=experiment, - display_name=experiment, - description=description, - schema_title=constants.SYSTEM_EXPERIMENT, - schema_version=constants.SCHEMA_VERSIONS[constants.SYSTEM_EXPERIMENT], - metadata=constants.EXPERIMENT_METADATA, + experiment = experiment_resources.Experiment.get_or_create( + experiment_name=experiment, description=description ) - if context.schema_title != constants.SYSTEM_EXPERIMENT: - raise ValueError( - f"Experiment name {experiment} has been used to create other type of resources " - f"({context.schema_title}) in this MetadataStore, please choose a different experiment name." - ) - if description and context.description != description: - context.update(metadata=context.metadata, description=description) + if backing_tensorboard: + experiment.assign_backing_tensorboard(tensorboard=backing_tensorboard) + + self._experiment = experiment + + def start_run( + self, + run: str, + *, + tensorboard: Union[tensorboard_resource.Tensorboard, str, None] = None, + resume=False, + ) -> experiment_run_resource.ExperimentRun: + """Start a run to current session. + + ``` + aiplatform.init(experiment='my-experiment') + aiplatform.start_run('my-run') + aiplatform.log_params({'learning_rate':0.1}) + ``` + + Use as context manager. Run will be ended on context exit: + ``` + aiplatform.init(experiment='my-experiment') + with aiplatform.start_run('my-run') as my_run: + my_run.log_params({'learning_rate':0.1}) + ``` + + Resume a previously started run: + ``` + aiplatform.init(experiment='my-experiment') + with aiplatform.start_run('my-run') as my_run: + my_run.log_params({'learning_rate':0.1}) + ``` - self._experiment = context - - def start_run(self, run: str): - """Setup a run to current session. Args: - run (str): + run(str): Required. Name of the run to assign current session with. - Raise: - ValueError if experiment is not set. Or if run execution or metrics artifact - is already created but with a different schema. + tensorboard Union[str, tensorboard_resource.Tensorboard]: + Optional. Backing Tensorboard Resource to enable and store time series metrics + logged to this Experiment Run using `log_time_series_metrics`. + + If not provided will the the default backing tensorboard of the currently + set experiment. + resume (bool): + Whether to resume this run. If False a new run will be created. + Raises: + ValueError: + if experiment is not set. Or if run execution or metrics artifact is already created + but with a different schema. """ if not self._experiment: raise ValueError( "No experiment set for this run. Make sure to call aiplatform.init(experiment='my-experiment') " - "before trying to start_run. " + "before invoking start_run. " ) - run_execution_id = f"{self._experiment.name}-{run}" - run_execution = _Execution.get_or_create( - resource_id=run_execution_id, - display_name=run, - schema_title=constants.SYSTEM_RUN, - schema_version=constants.SCHEMA_VERSIONS[constants.SYSTEM_RUN], - ) - if run_execution.schema_title != constants.SYSTEM_RUN: - raise ValueError( - f"Run name {run} has been used to create other type of resources ({run_execution.schema_title}) " - "in this MetadataStore, please choose a different run name." + + if self._experiment_run: + self.end_run() + + if resume: + self._experiment_run = experiment_run_resource.ExperimentRun( + run_name=run, experiment=self._experiment ) - self._experiment.add_artifacts_and_executions( - execution_resource_names=[run_execution.resource_name] - ) + if tensorboard: + self._experiment_run.assign_backing_tensorboard(tensorboard=tensorboard) - metrics_artifact_id = f"{self._experiment.name}-{run}-metrics" - metrics_artifact = _Artifact.get_or_create( - resource_id=metrics_artifact_id, - display_name=metrics_artifact_id, - schema_title=constants.SYSTEM_METRICS, - schema_version=constants.SCHEMA_VERSIONS[constants.SYSTEM_METRICS], - ) - if metrics_artifact.schema_title != constants.SYSTEM_METRICS: - raise ValueError( - f"Run name {run} has been used to create other type of resources ({metrics_artifact.schema_title}) " - "in this MetadataStore, please choose a different run name." + self._experiment_run.update_state(state=gapic.Execution.State.RUNNING) + + else: + self._experiment_run = experiment_run_resource.ExperimentRun.create( + run_name=run, experiment=self._experiment, tensorboard=tensorboard ) - run_execution.add_artifact( - artifact_resource_name=metrics_artifact.resource_name, input=False - ) - self._run = run_execution - self._metrics = metrics_artifact + return self._experiment_run + + def end_run(self, state: gapic.Execution.State = gapic.Execution.State.COMPLETE): + """Ends the the current experiment run. + + ``` + aiplatform.start_run('my-run') + ... + aiplatform.end_run() + ``` + + """ + self._validate_experiment_and_run(method_name="end_run") + try: + self._experiment_run.end_run(state=state) + except exceptions.NotFound: + _LOGGER.warn( + f"Experiment run {self._experiment_run.name} was not found." + "It may have been deleted" + ) + finally: + self._experiment_run = None def log_params(self, params: Dict[str, Union[float, int, str]]): """Log single or multiple parameters with specified key and value pairs. + Parameters with the same key will be overwritten. + + ``` + aiplatform.start_run('my-run') + aiplatform.log_params({'learning_rate': 0.1, 'dropout_rate': 0.2}) + ``` + Args: - params (Dict): + params (Dict[str, Union[float, int, str]]): Required. Parameter key/value pairs. """ self._validate_experiment_and_run(method_name="log_params") # query the latest run execution resource before logging. - execution = _Execution.get_or_create( - resource_id=self._run.name, - schema_title=constants.SYSTEM_RUN, - schema_version=constants.SCHEMA_VERSIONS[constants.SYSTEM_RUN], - ) - execution.update(metadata=params) + self._experiment_run.log_params(params=params) - def log_metrics(self, metrics: Dict[str, Union[float, int]]): + def log_metrics(self, metrics: Dict[str, Union[float, int, str]]): """Log single or multiple Metrics with specified key and value pairs. + Metrics with the same key will be overwritten. + + ``` + aiplatform.start_run('my-run', experiment='my-experiment') + aiplatform.log_metrics({'accuracy': 0.9, 'recall': 0.8}) + ``` + Args: - metrics (Dict): - Required. Metrics key/value pairs. Only flot and int are supported format for value. - Raises: - TypeError if value contains unsupported types. - ValueError if Experiment or Run is not set. + metrics (Dict[str, Union[float, int, str]]): + Required. Metrics key/value pairs. """ self._validate_experiment_and_run(method_name="log_metrics") - self._validate_metrics_value_type(metrics) # query the latest metrics artifact resource before logging. - artifact = _Artifact.get_or_create( - resource_id=self._metrics.name, - schema_title=constants.SYSTEM_METRICS, - schema_version=constants.SCHEMA_VERSIONS[constants.SYSTEM_METRICS], - ) - artifact.update(metadata=metrics) + self._experiment_run.log_metrics(metrics=metrics) - def get_experiment_df( - self, experiment: Optional[str] = None - ) -> "pd.DataFrame": # noqa: F821 - """Returns a Pandas DataFrame of the parameters and metrics associated with one experiment. - - Example: - - aiplatform.init(experiment='exp-1') - aiplatform.start_run(run='run-1') - aiplatform.log_params({'learning_rate': 0.1}) - aiplatform.log_metrics({'accuracy': 0.9}) + def _validate_experiment_and_run(self, method_name: str): + """Validates Experiment and Run are set and raises informative error message. - aiplatform.start_run(run='run-2') - aiplatform.log_params({'learning_rate': 0.2}) - aiplatform.log_metrics({'accuracy': 0.95}) + Args: + method_name: The name of th method to raise from. - Will result in the following DataFrame - ___________________________________________________________________________ - | experiment_name | run_name | param.learning_rate | metric.accuracy | - --------------------------------------------------------------------------- - | exp-1 | run-1 | 0.1 | 0.9 | - | exp-1 | run-2 | 0.2 | 0.95 | - --------------------------------------------------------------------------- + Raises: + ValueError: If Experiment or Run are not set. + """ - Args: - experiment (str): - Name of the Experiment to filter results. If not set, return results of current active experiment. + if not self._experiment: + raise ValueError( + f"No experiment set. Make sure to call aiplatform.init(experiment='my-experiment') " + f"before trying to {method_name}. " + ) + if not self._experiment_run: + raise ValueError( + f"No run set. Make sure to call aiplatform.start_run('my-run') before trying to {method_name}. " + ) - Returns: - Pandas Dataframe of Experiment with metrics and parameters. + def get_experiment_df( + self, experiment: Optional[str] = None + ) -> "pd.DataFrame": # noqa: F821 + """Returns a Pandas DataFrame of the parameters and metrics associated with one experiment. - Raise: - NotFound exception if experiment does not exist. - ValueError if given experiment is not associated with a wrong schema. - """ + Example: - if not experiment: - experiment = self._experiment.name + aiplatform.init(experiment='exp-1') + aiplatform.start_run(run='run-1') + aiplatform.log_params({'learning_rate': 0.1}) + aiplatform.log_metrics({'accuracy': 0.9}) - source = "experiment" - experiment_resource_name = self._get_experiment_or_pipeline_resource_name( - name=experiment, source=source, expected_schema=constants.SYSTEM_EXPERIMENT, - ) + aiplatform.start_run(run='run-2') + aiplatform.log_params({'learning_rate': 0.2}) + aiplatform.log_metrics({'accuracy': 0.95}) - return self._query_runs_to_data_frame( - context_id=experiment, - context_resource_name=experiment_resource_name, - source=source, - ) + aiplatform.get_experiments_df() - def get_pipeline_df(self, pipeline: str) -> "pd.DataFrame": # noqa: F821 - """Returns a Pandas DataFrame of the parameters and metrics associated with one pipeline. + Will result in the following DataFrame + ___________________________________________________________________________ + | experiment_name | run_name | param.learning_rate | metric.accuracy | + --------------------------------------------------------------------------- + | exp-1 | run-1 | 0.1 | 0.9 | + | exp-1 | run-2 | 0.2 | 0.95 | + --------------------------------------------------------------------------- Args: - pipeline: Name of the Pipeline to filter results. + experiment (str): + Name of the Experiment to filter results. If not set, return results of current active experiment. Returns: - Pandas Dataframe of Pipeline with metrics and parameters. + Pandas Dataframe of Experiment with metrics and parameters. Raise: NotFound exception if experiment does not exist. ValueError if given experiment is not associated with a wrong schema. """ - source = "pipeline" - pipeline_resource_name = self._get_experiment_or_pipeline_resource_name( - name=pipeline, source=source, expected_schema=constants.SYSTEM_PIPELINE - ) - - return self._query_runs_to_data_frame( - context_id=pipeline, - context_resource_name=pipeline_resource_name, - source=source, - ) - - def _validate_experiment_and_run(self, method_name: str): - if not self._experiment: - raise ValueError( - f"No experiment set. Make sure to call aiplatform.init(experiment='my-experiment') " - f"before trying to {method_name}. " - ) - if not self._run: - raise ValueError( - f"No run set. Make sure to call aiplatform.start_run('my-run') before trying to {method_name}. " - ) - - @staticmethod - def _validate_metrics_value_type(metrics: Dict[str, Union[float, int]]): - """Verify that metrics value are with supported types. + if not experiment: + experiment = self._experiment + else: + experiment = experiment_resources.Experiment(experiment) + + return experiment.get_data_frame() + + def log( + self, + *, + pipeline_job: Optional[pipeline_jobs.PipelineJob] = None, + ): + """Log Vertex AI Resources to the current experiment run. + + ``` + aiplatform.start_run('my-run') + my_job = aiplatform.PipelineJob(...) + my_job.submit() + aiplatform.log(my_job) + ``` Args: - metrics (Dict): - Required. Metrics key/value pairs. Only flot and int are supported format for value. - Raises: - TypeError if value contains unsupported types. + pipeline_job (pipeline_jobs.PipelineJob): + Optional. Vertex PipelineJob to associate to this Experiment Run. """ + self._validate_experiment_and_run(method_name="log") + self._experiment_run.log(pipeline_job=pipeline_job) - for key, value in metrics.items(): - if isinstance(value, int) or isinstance(value, float): - continue - raise TypeError( - f"metrics contain unsupported value types. key: {key}; value: {value}; type: {type(value)}" - ) + def log_time_series_metrics( + self, + metrics: Dict[str, Union[float]], + step: Optional[int] = None, + wall_time: Optional[timestamp_pb2.Timestamp] = None, + ): + """Logs time series metrics to to this Experiment Run. - @staticmethod - def _get_experiment_or_pipeline_resource_name( - name: str, source: str, expected_schema: str - ) -> str: - """Get the full resource name of the Context representing an Experiment or Pipeline. + Requires the experiment or experiment run has a backing Vertex Tensorboard resource. - Args: - name (str): - Name of the Experiment or Pipeline. - source (str): - Identify whether the this is an Experiment or a Pipeline. - expected_schema (str): - expected_schema identifies the expected schema used for Experiment or Pipeline. + ``` + my_tensorboard = aiplatform.Tensorboard(...) + aiplatform.init(experiment='my-experiment', experiment_tensorboard=my_tensorboard) + aiplatform.start_run('my-run') - Returns: - The full resource name of the Experiment or Pipeline Context. + # increments steps as logged + for i in range(10): + aiplatform.log_time_series_metrics({'loss': loss}) - Raise: - NotFound exception if experiment or pipeline does not exist. - """ + # explicitly log steps + for i in range(10): + aiplatform.log_time_series_metrics({'loss': loss}, step=i) + ``` - context = _Context(resource_name=name) + Args: + metrics (Dict[str, Union[str, float]]): + Required. Dictionary of where keys are metric names and values are metric values. + step (int): + Optional. Step index of this data point within the run. - if context.schema_title != expected_schema: - raise ValueError( - f"Please provide a valid {source} name. {name} is not a {source}." - ) - return context.resource_name + If not provided, the latest + step amongst all time series metrics already logged will be used. + wall_time (timestamp_pb2.Timestamp): + Optional. Wall clock timestamp when this data point is + generated by the end user. - def _query_runs_to_data_frame( - self, context_id: str, context_resource_name: str, source: str - ) -> "pd.DataFrame": # noqa: F821 - """Get metrics and parameters associated with a given Context into a Dataframe. + If not provided, this will be generated based on the value from time.time() + + Raises: + RuntimeError: If current experiment run doesn't have a backing Tensorboard resource. + """ + self._validate_experiment_and_run(method_name="log_time_series_metrics") + self._experiment_run.log_time_series_metrics( + metrics=metrics, step=step, wall_time=wall_time + ) + def start_execution( + self, + *, + schema_title: Optional[str] = None, + display_name: Optional[str] = None, + resource_id: Optional[str] = None, + metadata: Optional[Dict[str, Any]] = None, + schema_version: Optional[str] = None, + description: Optional[str] = None, + resume: bool = False, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ) -> execution.Execution: + """ + Create and starts a new Metadata Execution or resumes a previously created Execution. + + To start a new execution: + + ``` + with aiplatform.start_execution(schema_title='system.ContainerExecution', display_name='trainer) as exc: + exc.assign_input_artifacts([my_artifact]) + model = aiplatform.Artifact.create(uri='gs://my-uri', schema_title='system.Model') + exc.assign_output_artifacts([model]) + ``` + + To continue a previously created execution: + ``` + with aiplatform.start_execution(resource_id='my-exc', resume=True) as exc: + ... + ``` Args: - context_id (str): - Name of the Experiment or Pipeline. - context_resource_name (str): - Full resource name of the Context associated with an Experiment or Pipeline. - source (str): - Identify whether the this is an Experiment or a Pipeline. + schema_title (str): + Optional. schema_title identifies the schema title used by the Execution. Required if starting + a new Execution. + resource_id (str): + Optional. The portion of the Execution name with + the format. This is globally unique in a metadataStore: + projects/123/locations/us-central1/metadataStores//executions/. + display_name (str): + Optional. The user-defined name of the Execution. + schema_version (str): + Optional. schema_version specifies the version used by the Execution. + If not set, defaults to use the latest version. + metadata (Dict): + Optional. Contains the metadata information that will be stored in the Execution. + description (str): + Optional. Describes the purpose of the Execution to be created. + metadata_store_id (str): + Optional. The portion of the resource name with + the format: + projects/123/locations/us-central1/metadataStores//artifacts/ + If not provided, the MetadataStore's ID will be set to "default". + project (str): + Optional. Project used to create this Execution. Overrides project set in + aiplatform.init. + location (str): + Optional. Location used to create this Execution. Overrides location set in + aiplatform.init. + credentials (auth_credentials.Credentials): + Optional. Custom credentials used to create this Execution. Overrides + credentials set in aiplatform.init. Returns: - The full resource name of the Experiment or Pipeline Context. - """ + Execution: Instantiated representation of the managed Metadata Execution. - filter = f'schema_title="{constants.SYSTEM_RUN}" AND in_context("{context_resource_name}")' - run_executions = _Execution.list(filter=filter) + Raises: + ValueError: If experiment run is set and project or location do not match experiment run. + ValueError: If resume set to `True` and resource_id is not provided. + ValueError: If creating a new executin and schema_title is not provided. + """ - context_summary = [] - for run_execution in run_executions: - run_dict = { - f"{source}_name": context_id, - "run_name": run_execution.display_name, - } - run_dict.update( - self._execution_to_column_named_metadata( - "param", run_execution.metadata + if ( + self._experiment_run + and not self._experiment_run._is_legacy_experiment_run() + ): + if project and project != self._experiment_run.project: + raise ValueError( + f"Currently set Experiment run project {self._experiment_run.project} must" + f"match provided project {project}" ) - ) - - for metric_artifact in run_execution.query_input_and_output_artifacts(): - run_dict.update( - self._execution_to_column_named_metadata( - "metric", metric_artifact.metadata - ) + if location and location != self._experiment_run.location: + raise ValueError( + f"Currently set Experiment run location {self._experiment_run.location} must" + f"match provided location {project}" ) - context_summary.append(run_dict) + if resume: + if not resource_id: + raise ValueError("resource_id is required when resume=True") - try: - import pandas as pd - except ImportError: - raise ImportError( - "Pandas is not installed and is required to get dataframe as the return format. " - 'Please install the SDK using "pip install python-aiplatform[full]"' + run_execution = execution.Execution( + execution_name=resource_id, + project=project, + location=location, + credentials=credentials, ) - return pd.DataFrame(context_summary) + # TODO(handle updates if resuming) - @staticmethod - def _execution_to_column_named_metadata( - metadata_type: str, metadata: Dict, - ) -> Dict[str, Union[int, float, str]]: - """Returns a dict of the Execution/Artifact metadata with column names. + run_execution.update(state=gca_execution.Execution.State.RUNNING) + else: + if not schema_title: + raise ValueError( + "schema_title must be provided when starting a new Execution" + ) - Args: - metadata_type: The type of this execution properties (param, metric). - metadata: Either an Execution or Artifact metadata field. + run_execution = execution.Execution.create( + display_name=display_name, + schema_title=schema_title, + schema_version=schema_version, + metadata=metadata, + description=description, + resource_id=resource_id, + project=project, + location=location, + credentials=credentials, + ) - Returns: - Dict of custom properties with keys mapped to column names - """ + if self.experiment_run: + if self.experiment_run._is_legacy_experiment_run(): + _LOGGER.warn( + f"{self.experiment_run._run_name} is an Experiment run created in Vertex Experiment Preview", + " and does not support tracking Executions." + " Please create a new Experiment run to track executions against an Experiment run.", + ) + else: + self.experiment_run.associate_execution(run_execution) + run_execution.assign_input_artifacts = ( + self.experiment_run._association_wrapper( + run_execution.assign_input_artifacts + ) + ) + run_execution.assign_output_artifacts = ( + self.experiment_run._association_wrapper( + run_execution.assign_output_artifacts + ) + ) - return { - ".".join([metadata_type, key]): value for key, value in metadata.items() - } + return run_execution -metadata_service = _MetadataService() +_experiment_tracker = _ExperimentTracker() diff --git a/google/cloud/aiplatform/metadata/metadata_store.py b/google/cloud/aiplatform/metadata/metadata_store.py index 494d31aca4..2f0c8e2955 100644 --- a/google/cloud/aiplatform/metadata/metadata_store.py +++ b/google/cloud/aiplatform/metadata/metadata_store.py @@ -24,7 +24,7 @@ from google.cloud.aiplatform import base, initializer from google.cloud.aiplatform import compat from google.cloud.aiplatform import utils -from google.cloud.aiplatform_v1beta1.types import metadata_store as gca_metadata_store +from google.cloud.aiplatform.compat.types import metadata_store as gca_metadata_store class _MetadataStore(base.VertexAiResourceNounWithFutureManager): @@ -35,6 +35,8 @@ class _MetadataStore(base.VertexAiResourceNounWithFutureManager): _resource_noun = "metadataStores" _getter_method = "get_metadata_store" _delete_method = "delete_metadata_store" + _parse_resource_name_method = "parse_metadata_store_path" + _format_resource_name_method = "metadata_store_path" def __init__( self, @@ -64,7 +66,9 @@ def __init__( """ super().__init__( - project=project, location=location, credentials=credentials, + project=project, + location=location, + credentials=credentials, ) self._gca_resource = self._get_gca_resource(resource_name=metadata_store_name) @@ -77,7 +81,7 @@ def get_or_create( credentials: Optional[auth_credentials.Credentials] = None, encryption_spec_key_name: Optional[str] = None, ) -> "_MetadataStore": - """"Retrieves or Creates (if it does not exist) a Metadata Store. + """ "Retrieves or Creates (if it does not exist) a Metadata Store. Args: metadata_store_id (str): @@ -176,7 +180,7 @@ def _create( gapic_metadata_store = gca_metadata_store.MetadataStore( encryption_spec=initializer.global_config.get_encryption_spec( encryption_spec_key_name=encryption_spec_key_name, - select_version=compat.V1BETA1, + select_version=compat.DEFAULT_VERSION, ) ) @@ -205,7 +209,7 @@ def _get( project: Optional[str] = None, location: Optional[str] = None, credentials: Optional[auth_credentials.Credentials] = None, - ) -> "Optional[_MetadataStore]": + ) -> Optional["_MetadataStore"]: """Returns a MetadataStore resource. Args: @@ -238,3 +242,43 @@ def _get( ) except exceptions.NotFound: logging.info(f"MetadataStore {metadata_store_name} not found.") + + @classmethod + def ensure_default_metadata_store_exists( + cls, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + encryption_key_spec_name: Optional[str] = None, + ): + """Helpers method to ensure the `default` MetadataStore exists in this project and location. + + Args: + project (str): + Optional. Project to retrieve resource from. If not set, project + set in aiplatform.init will be used. + location (str): + Optional. Location to retrieve resource from. If not set, location + set in aiplatform.init will be used. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to upload this model. Overrides + credentials set in aiplatform.init. + encryption_spec_key_name (str): + Optional. The Cloud KMS resource identifier of the customer + managed encryption key used to protect the metadata store. Has the + form: + ``projects/my-project/locations/my-region/keyRings/my-kr/cryptoKeys/my-key``. + The key needs to be in the same region as where the compute + resource is created. + + If set, this MetadataStore and all sub-resources of this MetadataStore will be secured by this key. + + Overrides encryption_spec_key_name set in aiplatform.init. + """ + + cls.get_or_create( + project=project, + location=location, + credentials=credentials, + encryption_spec_key_name=encryption_key_spec_name, + ) diff --git a/google/cloud/aiplatform/metadata/resource.py b/google/cloud/aiplatform/metadata/resource.py index 85ac419d40..89c145dcbe 100644 --- a/google/cloud/aiplatform/metadata/resource.py +++ b/google/cloud/aiplatform/metadata/resource.py @@ -16,34 +16,37 @@ # import abc -import logging +import collections import re from copy import deepcopy -from typing import Optional, Dict, Union, Sequence +from typing import Dict, Optional, Union, Any, List import proto from google.api_core import exceptions from google.auth import credentials as auth_credentials -from google.protobuf import json_format from google.cloud.aiplatform import base, initializer +from google.cloud.aiplatform import metadata from google.cloud.aiplatform import utils -from google.cloud.aiplatform_v1beta1 import Artifact as GapicArtifact -from google.cloud.aiplatform_v1beta1 import Context as GapicContext -from google.cloud.aiplatform_v1beta1 import Execution as GapicExecution +from google.cloud.aiplatform.compat.types import artifact as gca_artifact +from google.cloud.aiplatform.compat.types import context as gca_context +from google.cloud.aiplatform.compat.types import execution as gca_execution + +_LOGGER = base.Logger(__name__) class _Resource(base.VertexAiResourceNounWithFutureManager, abc.ABC): """Metadata Resource for Vertex AI""" client_class = utils.MetadataClientWithOverride - _is_client_prediction_client = False _delete_method = None def __init__( self, resource_name: Optional[str] = None, - resource: Optional[Union[GapicContext, GapicArtifact, GapicExecution]] = None, + resource: Optional[ + Union[gca_context.Context, gca_artifact.Artifact, gca_execution.Execution] + ] = None, metadata_store_id: str = "default", project: Optional[str] = None, location: Optional[str] = None, @@ -57,7 +60,7 @@ def __init__( Example: "projects/123/locations/us-central1/metadataStores/default//my-resource". or "my-resource" when project and location are initialized or passed. if ``resource`` is provided, this should not be set. - resource (Union[GapicContext, GapicArtifact, GapicExecution]): + resource (Union[gca_context.Context, gca_artifact.Artifact, gca_execution.Execution]): The proto.Message that contains the full information of the resource. If both set, this field overrides ``resource_name`` field. metadata_store_id (str): @@ -70,35 +73,38 @@ def __init__( Optional location to retrieve the resource from. If not set, location set in aiplatform.init will be used. credentials (auth_credentials.Credentials): - Custom credentials to use to upload this model. Overrides + Custom credentials to use to retrieve this resource. Overrides credentials set in aiplatform.init. """ super().__init__( - project=project, location=location, credentials=credentials, + project=project, + location=location, + credentials=credentials, ) if resource: self._gca_resource = resource - return - - full_resource_name = resource_name - # Construct the full_resource_name if input resource_name is the resource_id - if "/" not in resource_name: + else: full_resource_name = utils.full_resource_name( resource_name=resource_name, - resource_noun=f"metadataStores/{metadata_store_id}/{self._resource_noun}", + resource_noun=self._resource_noun, + parse_resource_name_method=self._parse_resource_name, + format_resource_name_method=self._format_resource_name, + parent_resource_name_fields={ + metadata.metadata_store._MetadataStore._resource_noun: metadata_store_id + }, project=self.project, location=self.location, ) - self._gca_resource = getattr(self.api_client, self._getter_method)( - name=full_resource_name - ) + self._gca_resource = getattr(self.api_client, self._getter_method)( + name=full_resource_name, retry=base._DEFAULT_RETRY + ) @property def metadata(self) -> Dict: - return json_format.MessageToDict(self._gca_resource._pb)["metadata"] + return self.to_dict()["metadata"] @property def schema_title(self) -> str: @@ -168,7 +174,7 @@ def get_or_create( credentials=credentials, ) if not resource: - logging.info(f"Creating Resource {resource_id}") + _LOGGER.info(f"Creating Resource {resource_id}") resource = cls._create( resource_id=resource_id, schema_title=schema_title, @@ -183,9 +189,45 @@ def get_or_create( ) return resource + def sync_resource(self): + """Syncs local resource with the resource in metadata store.""" + self._gca_resource = getattr(self.api_client, self._getter_method)( + name=self.resource_name, retry=base._DEFAULT_RETRY + ) + + @staticmethod + def _nested_update_metadata( + gca_resource: Union[ + gca_context.Context, gca_execution.Execution, gca_artifact.Artifact + ], + metadata: Optional[Dict[str, Any]] = None, + ): + """Helper method to update gca_resource in place. + + Performs a one-level deep nested update on the metadata field. + + Args: + gca_resource (Union[gca_context.Context, gca_execution.Execution, gca_artifact.Artifact]): + Required. Metadata Protobuf resource. This proto's metadata will be + updated in place. + metadata (Dict[str, Any]): + Optional. Metadata dictionary to merge into gca_resource.metadata. + """ + + if metadata: + if gca_resource.metadata: + for key, value in metadata.items(): + # Note: This only support nested dictionaries one level deep + if isinstance(value, collections.abc.Mapping): + gca_resource.metadata[key].update(value) + else: + gca_resource.metadata[key] = value + else: + gca_resource.metadata = metadata + def update( self, - metadata: Dict, + metadata: Optional[Dict] = None, description: Optional[str] = None, credentials: Optional[auth_credentials.Credentials] = None, ): @@ -193,27 +235,26 @@ def update( Args: metadata (Dict): - Required. metadata contains the updated metadata information. + Optional. metadata contains the updated metadata information. description (str): Optional. Description describes the resource to be updated. credentials (auth_credentials.Credentials): Custom credentials to use to update this resource. Overrides credentials set in aiplatform.init. - """ gca_resource = deepcopy(self._gca_resource) - if gca_resource.metadata: - gca_resource.metadata.update(metadata) - else: - gca_resource.metadata = metadata + if metadata: + self._nested_update_metadata(gca_resource=gca_resource, metadata=metadata) if description: gca_resource.description = description api_client = self._instantiate_client(credentials=credentials) + # TODO: if etag is not valid sync and retry update_gca_resource = self._update_resource( - client=api_client, resource=gca_resource, + client=api_client, + resource=gca_resource, ) self._gca_resource = update_gca_resource @@ -225,7 +266,7 @@ def list( project: Optional[str] = None, location: Optional[str] = None, credentials: Optional[auth_credentials.Credentials] = None, - ) -> Sequence["_Resource"]: + ) -> List["_Resource"]: """List Metadata resources that match the list filter in target metadataStore. Args: @@ -252,8 +293,6 @@ def list( a list of managed Metadata resource. """ - api_client = cls._instantiate_client(location=location, credentials=credentials) - parent = ( initializer.global_config.common_location_path( project=project, location=location @@ -261,25 +300,13 @@ def list( + f"/metadataStores/{metadata_store_id}" ) - try: - resources = cls._list_resources( - client=api_client, parent=parent, filter=filter, - ) - except exceptions.NotFound: - logging.info( - f"No matching resources in metadataStore: {metadata_store_id} with filter: {filter}" - ) - return [] - - return [ - cls( - resource=resource, - project=project, - location=location, - credentials=credentials, - ) - for resource in resources - ] + return super().list( + filter=filter, + project=project, + location=location, + credentials=credentials, + parent=parent, + ) @classmethod def _create( @@ -294,7 +321,7 @@ def _create( project: Optional[str] = None, location: Optional[str] = None, credentials: Optional[auth_credentials.Credentials] = None, - ): + ) -> Optional["_Resource"]: """Creates a new Metadata resource. Args: @@ -354,16 +381,19 @@ def _create( metadata=metadata, ) except exceptions.AlreadyExists: - logging.info(f"Resource '{resource_id}' already exist") + _LOGGER.info(f"Resource '{resource_id}' already exist") return - return cls( - resource=resource, + self = cls._empty_constructor( project=project, location=location, credentials=credentials, ) + self._gca_resource = resource + + return self + @classmethod def _get( cls, @@ -403,14 +433,14 @@ def _get( try: return cls( - resource_name=resource_name, + resource_name, metadata_store_id=metadata_store_id, project=project, location=location, credentials=credentials, ) except exceptions.NotFound: - logging.info(f"Resource {resource_name} not found.") + _LOGGER.info(f"Resource {resource_name} not found.") @classmethod @abc.abstractmethod @@ -431,7 +461,9 @@ def _create_resource( @classmethod @abc.abstractmethod def _update_resource( - cls, client: utils.MetadataClientWithOverride, resource: proto.Message, + cls, + client: utils.MetadataClientWithOverride, + resource: proto.Message, ) -> proto.Message: """Update resource method.""" pass @@ -450,7 +482,7 @@ def _extract_metadata_store_id(resource_name, resource_noun) -> str: metadata_store_id (str): The metadata store id for the particular resource name. Raises: - ValueError if it does not exist. + ValueError: If it does not exist. """ pattern = re.compile( r"^projects\/(?P[\w-]+)\/locations\/(?P[\w-]+)\/metadataStores\/(?P[\w-]+)\/" diff --git a/google/cloud/aiplatform/metadata/schema/base_artifact.py b/google/cloud/aiplatform/metadata/schema/base_artifact.py new file mode 100644 index 0000000000..c89d989edd --- /dev/null +++ b/google/cloud/aiplatform/metadata/schema/base_artifact.py @@ -0,0 +1,126 @@ +# -*- coding: utf-8 -*- + +# Copyright 2022 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. +# + +import abc + +from typing import Optional, Dict + +from google.auth import credentials as auth_credentials + +from google.cloud.aiplatform.compat.types import artifact as gca_artifact +from google.cloud.aiplatform.metadata import artifact +from google.cloud.aiplatform.metadata import constants + + +class BaseArtifactSchema(metaclass=abc.ABCMeta): + """Base class for Metadata Artifact types.""" + + @property + @classmethod + @abc.abstractmethod + def schema_title(cls) -> str: + """Identifies the Vertex Metadta schema title used by the resource.""" + pass + + def __init__( + self, + *, + artifact_id: Optional[str] = None, + uri: Optional[str] = None, + display_name: Optional[str] = None, + schema_version: Optional[str] = None, + description: Optional[str] = None, + metadata: Optional[Dict] = None, + state: Optional[gca_artifact.Artifact.State] = gca_artifact.Artifact.State.LIVE, + ): + + """Initializes the Artifact with the given name, URI and metadata. + + This is the base class for defining various artifact types, which can be + passed to google.Artifact to create a corresponding resource. + Artifacts carry a `metadata` field, which is a dictionary for storing + metadata related to this artifact. Subclasses from ArtifactType can enforce + various structure and field requirements for the metadata field. + + Args: + resource_id (str): + Optional. The portion of the Artifact name with + the following format, this is globally unique in a metadataStore: + projects/123/locations/us-central1/metadataStores//artifacts/. + uri (str): + Optional. The uniform resource identifier of the artifact file. May be empty if there is no actual + artifact file. + display_name (str): + Optional. The user-defined name of the Artifact. + schema_version (str): + Optional. schema_version specifies the version used by the Artifact. + If not set, defaults to use the latest version. + description (str): + Optional. Describes the purpose of the Artifact to be created. + metadata (Dict): + Optional. Contains the metadata information that will be stored in the Artifact. + state (google.cloud.gapic.types.Artifact.State): + Optional. The state of this Artifact. This is a + property of the Artifact, and does not imply or + capture any ongoing process. This property is + managed by clients (such as Vertex AI + Pipelines), and the system does not prescribe or + check the validity of state transitions. + """ + self.artifact_id = artifact_id + self.uri = uri + self.display_name = display_name + self.schema_version = schema_version or constants._DEFAULT_SCHEMA_VERSION + self.description = description + self.metadata = metadata + self.state = state + + def create( + self, + *, + metadata_store_id: Optional[str] = "default", + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ) -> "artifact.Artifact": + """Creates a new Metadata Artifact. + + Args: + metadata_store_id (str): + Optional. The portion of the resource name with + the format: + projects/123/locations/us-central1/metadataStores//artifacts/ + If not provided, the MetadataStore's ID will be set to "default". + project (str): + Optional. Project used to create this Artifact. Overrides project set in + aiplatform.init. + location (str): + Optional. Location used to create this Artifact. Overrides location set in + aiplatform.init. + credentials (auth_credentials.Credentials): + Optional. Custom credentials used to create this Artifact. Overrides + credentials set in aiplatform.init. + Returns: + Artifact: Instantiated representation of the managed Metadata Artifact. + """ + return artifact.Artifact.create_from_base_artifact_schema( + base_artifact_schema=self, + metadata_store_id=metadata_store_id, + project=project, + location=location, + credentials=credentials, + ) diff --git a/google/cloud/aiplatform/metadata/schema/base_execution.py b/google/cloud/aiplatform/metadata/schema/base_execution.py new file mode 100644 index 0000000000..811b7d9791 --- /dev/null +++ b/google/cloud/aiplatform/metadata/schema/base_execution.py @@ -0,0 +1,114 @@ +# -*- coding: utf-8 -*- + +# Copyright 2022 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. +# + +import abc + +from typing import Optional, Dict + +from google.auth import credentials as auth_credentials + +from google.cloud.aiplatform.compat.types import execution as gca_execution +from google.cloud.aiplatform.metadata import constants +from google.cloud.aiplatform.metadata import execution + + +class BaseExecutionSchema(metaclass=abc.ABCMeta): + """Base class for Metadata Execution schema.""" + + @property + @classmethod + @abc.abstractmethod + def schema_title(cls) -> str: + """Identifies the Vertex Metadta schema title used by the resource.""" + pass + + def __init__( + self, + *, + state: Optional[ + gca_execution.Execution.State + ] = gca_execution.Execution.State.RUNNING, + execution_id: Optional[str] = None, + display_name: Optional[str] = None, + schema_version: Optional[str] = None, + metadata: Optional[Dict] = None, + description: Optional[str] = None, + ): + + """Initializes the Execution with the given name, URI and metadata. + + Args: + state (gca_execution.Execution.State.RUNNING): + Optional. State of this Execution. Defaults to RUNNING. + execution_id (str): + Optional. The portion of the Execution name with + the following format, this is globally unique in a metadataStore. + projects/123/locations/us-central1/metadataStores//executions/. + display_name (str): + Optional. The user-defined name of the Execution. + schema_version (str): + Optional. schema_version specifies the version used by the Execution. + If not set, defaults to use the latest version. + metadata (Dict): + Optional. Contains the metadata information that will be stored in the Execution. + description (str): + Optional. Describes the purpose of the Execution to be created. + """ + self.state = state + self.execution_id = execution_id + self.display_name = display_name + self.schema_version = schema_version or constants._DEFAULT_SCHEMA_VERSION + self.metadata = metadata + self.description = description + + def create( + self, + *, + metadata_store_id: Optional[str] = "default", + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ) -> "execution.Execution": + """Creates a new Metadata Execution. + + Args: + metadata_store_id (str): + Optional. The portion of the resource name with + the format: + projects/123/locations/us-central1/metadataStores//executions/ + If not provided, the MetadataStore's ID will be set to "default". + project (str): + Optional. Project used to create this Execution. Overrides project set in + aiplatform.init. + location (str): + Optional. Location used to create this Execution. Overrides location set in + aiplatform.init. + credentials (auth_credentials.Credentials): + Optional. Custom credentials used to create this Execution. Overrides + credentials set in aiplatform.init. + Returns: + Execution: Instantiated representation of the managed Metadata Execution. + + """ + self.execution = execution.Execution.create_from_base_execution_schema( + base_execution_schema=self, + metadata_store_id=metadata_store_id, + project=project, + location=location, + credentials=credentials, + ) + return self.execution diff --git a/google/cloud/aiplatform/metadata/schema/google/artifact_schema.py b/google/cloud/aiplatform/metadata/schema/google/artifact_schema.py new file mode 100644 index 0000000000..99e0fb0ba6 --- /dev/null +++ b/google/cloud/aiplatform/metadata/schema/google/artifact_schema.py @@ -0,0 +1,270 @@ +# -*- coding: utf-8 -*- + +# Copyright 2022 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. + +import copy +from typing import Optional, Dict + +from google.cloud.aiplatform.compat.types import artifact as gca_artifact +from google.cloud.aiplatform.metadata.schema import base_artifact +from google.cloud.aiplatform.metadata.schema import utils + +# The artifact property key for the resource_name +_ARTIFACT_PROPERTY_KEY_RESOURCE_NAME = "resourceName" + + +class VertexDataset(base_artifact.BaseArtifactSchema): + """An artifact representing a Vertex Dataset.""" + + schema_title = "google.VertexDataset" + + def __init__( + self, + *, + vertex_dataset_name: str, + artifact_id: Optional[str] = None, + display_name: Optional[str] = None, + schema_version: Optional[str] = None, + description: Optional[str] = None, + metadata: Optional[Dict] = None, + state: Optional[gca_artifact.Artifact.State] = gca_artifact.Artifact.State.LIVE, + ): + """Args: + vertex_dataset_name (str): + The name of the Dataset resource, in a form of + projects/{project}/locations/{location}/datasets/{dataset}. For + more details, see + https://cloud.google.com/vertex-ai/docs/reference/rest/v1/projects.locations.datasets/get + This is used to generate the resource uri as follows: + https://{service-endpoint}/v1/{dataset_name}, + where {service-endpoint} is one of the supported service endpoints at + https://cloud.google.com/vertex-ai/docs/reference/rest#rest_endpoints + artifact_id (str): + Optional. The portion of the Artifact name with + the format. This is globally unique in a metadataStore: + projects/123/locations/us-central1/metadataStores//artifacts/. + display_name (str): + Optional. The user-defined name of the Artifact. + schema_version (str): + Optional. schema_version specifies the version used by the Artifact. + If not set, defaults to use the latest version. + description (str): + Optional. Describes the purpose of the Artifact to be created. + metadata (Dict): + Optional. Contains the metadata information that will be stored in the Artifact. + state (google.cloud.gapic.types.Artifact.State): + Optional. The state of this Artifact. This is a + property of the Artifact, and does not imply or + capture any ongoing process. This property is + managed by clients (such as Vertex AI + Pipelines), and the system does not prescribe or + check the validity of state transitions. + """ + extended_metadata = copy.deepcopy(metadata) if metadata else {} + extended_metadata[_ARTIFACT_PROPERTY_KEY_RESOURCE_NAME] = vertex_dataset_name + + super(VertexDataset, self).__init__( + uri=utils.create_uri_from_resource_name(resource_name=vertex_dataset_name), + artifact_id=artifact_id, + display_name=display_name, + schema_version=schema_version, + description=description, + metadata=extended_metadata, + state=state, + ) + + +class VertexModel(base_artifact.BaseArtifactSchema): + """An artifact representing a Vertex Model.""" + + schema_title = "google.VertexModel" + + def __init__( + self, + *, + vertex_model_name: str, + artifact_id: Optional[str] = None, + display_name: Optional[str] = None, + schema_version: Optional[str] = None, + description: Optional[str] = None, + metadata: Optional[Dict] = None, + state: Optional[gca_artifact.Artifact.State] = gca_artifact.Artifact.State.LIVE, + ): + """Args: + vertex_model_name (str): + The name of the Model resource, in a form of + projects/{project}/locations/{location}/models/{model}. For + more details, see + https://cloud.google.com/vertex-ai/docs/reference/rest/v1/projects.locations.models/get + This is used to generate the resource uri as follows: + https://{service-endpoint}/v1/{vertex_model_name}, + where {service-endpoint} is one of the supported service endpoints at + https://cloud.google.com/vertex-ai/docs/reference/rest#rest_endpoints + artifact_id (str): + Optional. The portion of the Artifact name with + the format. This is globally unique in a metadataStore: + projects/123/locations/us-central1/metadataStores//artifacts/. + display_name (str): + Optional. The user-defined name of the Artifact. + schema_version (str): + Optional. schema_version specifies the version used by the Artifact. + If not set, defaults to use the latest version. + description (str): + Optional. Describes the purpose of the Artifact to be created. + metadata (Dict): + Optional. Contains the metadata information that will be stored in the Artifact. + state (google.cloud.gapic.types.Artifact.State): + Optional. The state of this Artifact. This is a + property of the Artifact, and does not imply or + capture any ongoing process. This property is + managed by clients (such as Vertex AI + Pipelines), and the system does not prescribe or + check the validity of state transitions. + """ + extended_metadata = copy.deepcopy(metadata) if metadata else {} + extended_metadata[_ARTIFACT_PROPERTY_KEY_RESOURCE_NAME] = vertex_model_name + + super(VertexModel, self).__init__( + uri=utils.create_uri_from_resource_name(resource_name=vertex_model_name), + artifact_id=artifact_id, + display_name=display_name, + schema_version=schema_version, + description=description, + metadata=extended_metadata, + state=state, + ) + + +class VertexEndpoint(base_artifact.BaseArtifactSchema): + """An artifact representing a Vertex Endpoint.""" + + schema_title = "google.VertexEndpoint" + + def __init__( + self, + *, + vertex_endpoint_name: str, + artifact_id: Optional[str] = None, + display_name: Optional[str] = None, + schema_version: Optional[str] = None, + description: Optional[str] = None, + metadata: Optional[Dict] = None, + state: Optional[gca_artifact.Artifact.State] = gca_artifact.Artifact.State.LIVE, + ): + """Args: + vertex_endpoint_name (str): + The name of the Endpoint resource, in a form of + projects/{project}/locations/{location}/endpoints/{endpoint}. For + more details, see + https://cloud.google.com/vertex-ai/docs/reference/rest/v1/projects.locations.endpoints/get + This is used to generate the resource uri as follows: + https://{service-endpoint}/v1/{vertex_endpoint_name}, + where {service-endpoint} is one of the supported service endpoints at + https://cloud.google.com/vertex-ai/docs/reference/rest#rest_endpoints + artifact_id (str): + Optional. The portion of the Artifact name with + the format. This is globally unique in a metadataStore: + projects/123/locations/us-central1/metadataStores//artifacts/. + display_name (str): + Optional. The user-defined name of the Artifact. + schema_version (str): + Optional. schema_version specifies the version used by the Artifact. + If not set, defaults to use the latest version. + description (str): + Optional. Describes the purpose of the Artifact to be created. + metadata (Dict): + Optional. Contains the metadata information that will be stored in the Artifact. + state (google.cloud.gapic.types.Artifact.State): + Optional. The state of this Artifact. This is a + property of the Artifact, and does not imply or + capture any ongoing process. This property is + managed by clients (such as Vertex AI + Pipelines), and the system does not prescribe or + check the validity of state transitions. + """ + extended_metadata = copy.deepcopy(metadata) if metadata else {} + extended_metadata[_ARTIFACT_PROPERTY_KEY_RESOURCE_NAME] = vertex_endpoint_name + + super(VertexEndpoint, self).__init__( + uri=utils.create_uri_from_resource_name(resource_name=vertex_endpoint_name), + artifact_id=artifact_id, + display_name=display_name, + schema_version=schema_version, + description=description, + metadata=extended_metadata, + state=state, + ) + + +class UnmanagedContainerModel(base_artifact.BaseArtifactSchema): + """An artifact representing a Vertex Unmanaged Container Model.""" + + schema_title = "google.UnmanagedContainerModel" + + def __init__( + self, + *, + predict_schema_ta: utils.PredictSchemata, + container_spec: utils.ContainerSpec, + artifact_id: Optional[str] = None, + uri: Optional[str] = None, + display_name: Optional[str] = None, + schema_version: Optional[str] = None, + description: Optional[str] = None, + metadata: Optional[Dict] = None, + state: Optional[gca_artifact.Artifact.State] = gca_artifact.Artifact.State.LIVE, + ): + """Args: + predict_schema_ta (PredictSchemata): + An instance of PredictSchemata which holds instance, parameter and prediction schema uris. + container_spec (ContainerSpec): + An instance of ContainerSpec which holds the container configuration for the model. + artifact_id (str): + Optional. The portion of the Artifact name with + the format. This is globally unique in a metadataStore: + projects/123/locations/us-central1/metadataStores//artifacts/. + uri (str): + Optional. The uniform resource identifier of the artifact file. May be empty if there is no actual + artifact file. + display_name (str): + Optional. The user-defined name of the Artifact. + schema_version (str): + Optional. schema_version specifies the version used by the Artifact. + If not set, defaults to use the latest version. + description (str): + Optional. Describes the purpose of the Artifact to be created. + metadata (Dict): + Optional. Contains the metadata information that will be stored in the Artifact. + state (google.cloud.gapic.types.Artifact.State): + Optional. The state of this Artifact. This is a + property of the Artifact, and does not imply or + capture any ongoing process. This property is + managed by clients (such as Vertex AI + Pipelines), and the system does not prescribe or + check the validity of state transitions. + """ + extended_metadata = copy.deepcopy(metadata) if metadata else {} + extended_metadata["predictSchemata"] = predict_schema_ta.to_dict() + extended_metadata["containerSpec"] = container_spec.to_dict() + + super(UnmanagedContainerModel, self).__init__( + uri=uri, + artifact_id=artifact_id, + display_name=display_name, + schema_version=schema_version, + description=description, + metadata=extended_metadata, + state=state, + ) diff --git a/google/cloud/aiplatform/metadata/schema/system/artifact_schema.py b/google/cloud/aiplatform/metadata/schema/system/artifact_schema.py new file mode 100644 index 0000000000..f3491a5573 --- /dev/null +++ b/google/cloud/aiplatform/metadata/schema/system/artifact_schema.py @@ -0,0 +1,265 @@ +# -*- coding: utf-8 -*- + +# Copyright 2022 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. +# + +import copy +from typing import Optional, Dict + +from google.cloud.aiplatform.compat.types import artifact as gca_artifact +from google.cloud.aiplatform.metadata.schema import base_artifact + + +class Model(base_artifact.BaseArtifactSchema): + """Artifact type for model.""" + + schema_title = "system.Model" + + def __init__( + self, + *, + uri: Optional[str] = None, + artifact_id: Optional[str] = None, + display_name: Optional[str] = None, + schema_version: Optional[str] = None, + description: Optional[str] = None, + metadata: Optional[Dict] = None, + state: Optional[gca_artifact.Artifact.State] = gca_artifact.Artifact.State.LIVE, + ): + """Args: + uri (str): + Optional. The uniform resource identifier of the artifact file. May be empty if there is no actual + artifact file. + artifact_id (str): + Optional. The portion of the Artifact name with + the format. This is globally unique in a metadataStore: + projects/123/locations/us-central1/metadataStores//artifacts/. + display_name (str): + Optional. The user-defined name of the base. + schema_version (str): + Optional. schema_version specifies the version used by the base. + If not set, defaults to use the latest version. + description (str): + Optional. Describes the purpose of the Artifact to be created. + metadata (Dict): + Optional. Contains the metadata information that will be stored in the Artifact. + state (google.cloud.gapic.types.Artifact.State): + Optional. The state of this Artifact. This is a + property of the Artifact, and does not imply or + capture any ongoing process. This property is + managed by clients (such as Vertex AI + Pipelines), and the system does not prescribe or + check the validity of state transitions. + """ + extended_metadata = copy.deepcopy(metadata) if metadata else {} + super(Model, self).__init__( + uri=uri, + artifact_id=artifact_id, + display_name=display_name, + schema_version=schema_version, + description=description, + metadata=extended_metadata, + state=state, + ) + + +class Artifact(base_artifact.BaseArtifactSchema): + """A generic artifact.""" + + schema_title = "system.Artifact" + + def __init__( + self, + *, + uri: Optional[str] = None, + artifact_id: Optional[str] = None, + display_name: Optional[str] = None, + schema_version: Optional[str] = None, + description: Optional[str] = None, + metadata: Optional[Dict] = None, + state: Optional[gca_artifact.Artifact.State] = gca_artifact.Artifact.State.LIVE, + ): + """Args: + uri (str): + Optional. The uniform resource identifier of the artifact file. May be empty if there is no actual + artifact file. + artifact_id (str): + Optional. The portion of the Artifact name with + the format. This is globally unique in a metadataStore: + projects/123/locations/us-central1/metadataStores//artifacts/. + display_name (str): + Optional. The user-defined name of the base. + schema_version (str): + Optional. schema_version specifies the version used by the base. + If not set, defaults to use the latest version. + description (str): + Optional. Describes the purpose of the Artifact to be created. + metadata (Dict): + Optional. Contains the metadata information that will be stored in the Artifact. + state (google.cloud.gapic.types.Artifact.State): + Optional. The state of this Artifact. This is a + property of the Artifact, and does not imply or + capture any ongoing process. This property is + managed by clients (such as Vertex AI + Pipelines), and the system does not prescribe or + check the validity of state transitions. + """ + extended_metadata = copy.deepcopy(metadata) if metadata else {} + super(Artifact, self).__init__( + uri=uri, + artifact_id=artifact_id, + display_name=display_name, + schema_version=schema_version, + description=description, + metadata=extended_metadata, + state=state, + ) + + +class Dataset(base_artifact.BaseArtifactSchema): + """An artifact representing a system Dataset.""" + + schema_title = "system.Dataset" + + def __init__( + self, + *, + uri: Optional[str] = None, + artifact_id: Optional[str] = None, + display_name: Optional[str] = None, + schema_version: Optional[str] = None, + description: Optional[str] = None, + metadata: Optional[Dict] = None, + state: Optional[gca_artifact.Artifact.State] = gca_artifact.Artifact.State.LIVE, + ): + """Args: + uri (str): + Optional. The uniform resource identifier of the artifact file. May be empty if there is no actual + artifact file. + artifact_id (str): + Optional. The portion of the Artifact name with + the format. This is globally unique in a metadataStore: + projects/123/locations/us-central1/metadataStores//artifacts/. + display_name (str): + Optional. The user-defined name of the base. + schema_version (str): + Optional. schema_version specifies the version used by the base. + If not set, defaults to use the latest version. + description (str): + Optional. Describes the purpose of the Artifact to be created. + metadata (Dict): + Optional. Contains the metadata information that will be stored in the Artifact. + state (google.cloud.gapic.types.Artifact.State): + Optional. The state of this Artifact. This is a + property of the Artifact, and does not imply or + capture any ongoing process. This property is + managed by clients (such as Vertex AI + Pipelines), and the system does not prescribe or + check the validity of state transitions. + """ + extended_metadata = copy.deepcopy(metadata) if metadata else {} + super(Dataset, self).__init__( + uri=uri, + artifact_id=artifact_id, + display_name=display_name, + schema_version=schema_version, + description=description, + metadata=extended_metadata, + state=state, + ) + + +class Metrics(base_artifact.BaseArtifactSchema): + """Artifact schema for scalar metrics.""" + + schema_title = "system.Metrics" + + def __init__( + self, + *, + accuracy: Optional[float] = None, + precision: Optional[float] = None, + recall: Optional[float] = None, + f1score: Optional[float] = None, + mean_absolute_error: Optional[float] = None, + mean_squared_error: Optional[float] = None, + uri: Optional[str] = None, + artifact_id: Optional[str] = None, + display_name: Optional[str] = None, + schema_version: Optional[str] = None, + description: Optional[str] = None, + metadata: Optional[Dict] = None, + state: Optional[gca_artifact.Artifact.State] = gca_artifact.Artifact.State.LIVE, + ): + """Args: + accuracy (float): + Optional. + precision (float): + Optional. + recall (float): + Optional. + f1score (float): + Optional. + mean_absolute_error (float): + Optional. + mean_squared_error (float): + Optional. + uri (str): + Optional. The uniform resource identifier of the artifact file. May be empty if there is no actual + artifact file. + artifact_id (str): + Optional. The portion of the Artifact name with + the format. This is globally unique in a metadataStore: + projects/123/locations/us-central1/metadataStores//artifacts/. + display_name (str): + Optional. The user-defined name of the base. + schema_version (str): + Optional. schema_version specifies the version used by the base. + If not set, defaults to use the latest version. + description (str): + Optional. Describes the purpose of the Artifact to be created. + metadata (Dict): + Optional. Contains the metadata information that will be stored in the Artifact. + state (google.cloud.gapic.types.Artifact.State): + Optional. The state of this Artifact. This is a + property of the Artifact, and does not imply or + capture any ongoing process. This property is + managed by clients (such as Vertex AI + Pipelines), and the system does not prescribe or + check the validity of state transitions. + """ + extended_metadata = copy.deepcopy(metadata) if metadata else {} + if accuracy: + extended_metadata["accuracy"] = accuracy + if precision: + extended_metadata["precision"] = precision + if recall: + extended_metadata["recall"] = recall + if f1score: + extended_metadata["f1score"] = f1score + if mean_absolute_error: + extended_metadata["mean_absolute_error"] = mean_absolute_error + if mean_squared_error: + extended_metadata["mean_squared_error"] = mean_squared_error + + super(Metrics, self).__init__( + uri=uri, + artifact_id=artifact_id, + display_name=display_name, + schema_version=schema_version, + description=description, + metadata=extended_metadata, + state=state, + ) diff --git a/google/cloud/aiplatform/metadata/schema/system/execution_schema.py b/google/cloud/aiplatform/metadata/schema/system/execution_schema.py new file mode 100644 index 0000000000..68c96902cb --- /dev/null +++ b/google/cloud/aiplatform/metadata/schema/system/execution_schema.py @@ -0,0 +1,157 @@ +# -*- coding: utf-8 -*- + +# Copyright 2022 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. +# + +import copy +from typing import Optional, Dict + +from google.cloud.aiplatform.compat.types import execution as gca_execution +from google.cloud.aiplatform.metadata.schema import base_execution + + +class ContainerExecution(base_execution.BaseExecutionSchema): + """Execution schema for a container execution.""" + + schema_title = "system.ContainerExecution" + + def __init__( + self, + *, + state: Optional[ + gca_execution.Execution.State + ] = gca_execution.Execution.State.RUNNING, + execution_id: Optional[str] = None, + display_name: Optional[str] = None, + schema_version: Optional[str] = None, + metadata: Optional[Dict] = None, + description: Optional[str] = None, + ): + """Args: + state (gca_execution.Execution.State.RUNNING): + Optional. State of this Execution. Defaults to RUNNING. + execution_id (str): + Optional. The portion of the Execution name with + the following format, this is globally unique in a metadataStore. + projects/123/locations/us-central1/metadataStores//executions/. + display_name (str): + Optional. The user-defined name of the Execution. + schema_version (str): + Optional. schema_version specifies the version used by the Execution. + If not set, defaults to use the latest version. + metadata (Dict): + Optional. Contains the metadata information that will be stored in the Execution. + description (str): + Optional. Describes the purpose of the Execution to be created. + """ + extended_metadata = copy.deepcopy(metadata) if metadata else {} + super(ContainerExecution, self).__init__( + execution_id=execution_id, + state=state, + display_name=display_name, + schema_version=schema_version, + description=description, + metadata=extended_metadata, + ) + + +class CustomJobExecution(base_execution.BaseExecutionSchema): + """Execution schema for a custom job execution.""" + + schema_title = "system.CustomJobExecution" + + def __init__( + self, + *, + state: Optional[ + gca_execution.Execution.State + ] = gca_execution.Execution.State.RUNNING, + execution_id: Optional[str] = None, + display_name: Optional[str] = None, + schema_version: Optional[str] = None, + metadata: Optional[Dict] = None, + description: Optional[str] = None, + ): + """Args: + state (gca_execution.Execution.State.RUNNING): + Optional. State of this Execution. Defaults to RUNNING. + execution_id (str): + Optional. The portion of the Execution name with + the following format, this is globally unique in a metadataStore. + projects/123/locations/us-central1/metadataStores//executions/. + display_name (str): + Optional. The user-defined name of the Execution. + schema_version (str): + Optional. schema_version specifies the version used by the Execution. + If not set, defaults to use the latest version. + metadata (Dict): + Optional. Contains the metadata information that will be stored in the Execution. + description (str): + Optional. Describes the purpose of the Execution to be created. + """ + extended_metadata = copy.deepcopy(metadata) if metadata else {} + super(CustomJobExecution, self).__init__( + execution_id=execution_id, + state=state, + display_name=display_name, + schema_version=schema_version, + description=description, + metadata=extended_metadata, + ) + + +class Run(base_execution.BaseExecutionSchema): + """Execution schema for root run execution.""" + + schema_title = "system.Run" + + def __init__( + self, + *, + state: Optional[ + gca_execution.Execution.State + ] = gca_execution.Execution.State.RUNNING, + execution_id: Optional[str] = None, + display_name: Optional[str] = None, + schema_version: Optional[str] = None, + metadata: Optional[Dict] = None, + description: Optional[str] = None, + ): + """Args: + state (gca_execution.Execution.State.RUNNING): + Optional. State of this Execution. Defaults to RUNNING. + execution_id (str): + Optional. The portion of the Execution name with + the following format, this is globally unique in a metadataStore. + projects/123/locations/us-central1/metadataStores//executions/. + display_name (str): + Optional. The user-defined name of the Execution. + schema_version (str): + Optional. schema_version specifies the version used by the Execution. + If not set, defaults to use the latest version. + metadata (Dict): + Optional. Contains the metadata information that will be stored in the Execution. + description (str): + Optional. Describes the purpose of the Execution to be created. + """ + extended_metadata = copy.deepcopy(metadata) if metadata else {} + super(Run, self).__init__( + execution_id=execution_id, + state=state, + display_name=display_name, + schema_version=schema_version, + description=description, + metadata=extended_metadata, + ) diff --git a/google/cloud/aiplatform/metadata/schema/utils.py b/google/cloud/aiplatform/metadata/schema/utils.py new file mode 100644 index 0000000000..72577d9324 --- /dev/null +++ b/google/cloud/aiplatform/metadata/schema/utils.py @@ -0,0 +1,169 @@ +# -*- coding: utf-8 -*- + +# Copyright 2022 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. +# +import re + +from typing import Optional, Dict, List +from dataclasses import dataclass + + +@dataclass +class PredictSchemata: + """A class holding instance, parameter and prediction schema uris. + + Args: + instance_schema_uri (str): + Required. Points to a YAML file stored on Google Cloud Storage + describing the format of a single instance, which are used in + PredictRequest.instances, ExplainRequest.instances and + BatchPredictionJob.input_config. The schema is defined as an + OpenAPI 3.0.2 `Schema Object. + parameters_schema_uri (str): + Required. Points to a YAML file stored on Google Cloud Storage + describing the parameters of prediction and explanation via + PredictRequest.parameters, ExplainRequest.parameters and + BatchPredictionJob.model_parameters. The schema is defined as an + OpenAPI 3.0.2 `Schema Object. + prediction_schema_uri (str): + Required. Points to a YAML file stored on Google Cloud Storage + describing the format of a single prediction produced by this Model + , which are returned via PredictResponse.predictions, + ExplainResponse.explanations, and BatchPredictionJob.output_config. + The schema is defined as an OpenAPI 3.0.2 `Schema Object. + """ + + instance_schema_uri: str + parameters_schema_uri: str + prediction_schema_uri: str + + def to_dict(self): + """ML metadata schema dictionary representation of this DataClass""" + results = {} + results["instanceSchemaUri"] = self.instance_schema_uri + results["parametersSchemaUri"] = self.parameters_schema_uri + results["predictionSchemaUri"] = self.prediction_schema_uri + + return results + + +@dataclass +class ContainerSpec: + """Container configuration for the model. + Args: + image_uri (str): + Required. URI of the Docker image to be used as the custom + container for serving predictions. This URI must identify an image + in Artifact Registry or Container Registry. + command (Sequence[str]): + Optional. Specifies the command that runs when the container + starts. This overrides the container's `ENTRYPOINT`. + args (Sequence[str]): + Optional. Specifies arguments for the command that runs when the + container starts. This overrides the container's `CMD` + env (Sequence[google.cloud.aiplatform_v1.types.EnvVar]): + Optional. List of environment variables to set in the container. + After the container starts running, code running in the container + can read these environment variables. Additionally, the command + and args fields can reference these variables. Later entries in + this list can also reference earlier entries. For example, the + following example sets the variable ``VAR_2`` to have the value + ``foo bar``: .. code:: json [ { "name": "VAR_1", "value": "foo" }, + { "name": "VAR_2", "value": "$(VAR_1) bar" } ] If you switch the + order of the variables in the example, then the expansion does not + occur. This field corresponds to the ``env`` field of the + Kubernetes Containers `v1 core API. + ports (Sequence[google.cloud.aiplatform_v1.types.Port]): + Optional. List of ports to expose from the container. Vertex AI + sends any prediction requests that it receives to the first port on + this list. Vertex AI also sends `liveness and health checks. + predict_route (str): + Optional. HTTP path on the container to send prediction requests + to. Vertex AI forwards requests sent using + projects.locations.endpoints.predict to this path on the + container's IP address and port. Vertex AI then returns the + container's response in the API response. For example, if you set + this field to ``/foo``, then when Vertex AI receives a prediction + request, it forwards the request body in a POST request to the + ``/foo`` path on the port of your container specified by the first + value of this ``ModelContainerSpec``'s ports field. If you don't + specify this field, it defaults to the following value when you + deploy this Model to an Endpoint + /v1/endpoints/ENDPOINT/deployedModels/DEPLOYED_MODEL:predict + The placeholders in this value are replaced as follows: + - ENDPOINT: The last segment (following ``endpoints/``)of the + Endpoint.name][] field of the Endpoint where this Model has + been deployed. (Vertex AI makes this value available to your + container code as the ```AIP_ENDPOINT_ID`` environment variable + health_route (str): + Optional. HTTP path on the container to send health checks to. + Vertex AI intermittently sends GET requests to this path on the + container's IP address and port to check that the container is + healthy. Read more about `health checks + display_name (str): + """ + + image_uri: str + command: Optional[List[str]] = None + args: Optional[List[str]] = None + env: Optional[List[Dict[str, str]]] = None + ports: Optional[List[int]] = None + predict_route: Optional[str] = None + health_route: Optional[str] = None + + def to_dict(self): + """ML metadata schema dictionary representation of this DataClass""" + results = {} + results["imageUri"] = self.image_uri + if self.command: + results["command"] = self.command + if self.args: + results["args"] = self.args + if self.env: + results["env"] = self.env + if self.ports: + results["ports"] = self.ports + if self.predict_route: + results["predictRoute"] = self.predict_route + if self.health_route: + results["healthRoute"] = self.health_route + + return results + + +def create_uri_from_resource_name(resource_name: str) -> bool: + """Construct the service URI for a given resource_name. + Args: + resource_name (str): + The name of the Vertex resource, in a form of + projects/{project}/locations/{location}/{resource_type}/{resource_id} + Returns: + The resource URI in the form of: + https://{service-endpoint}/v1/{resource_name}, + where {service-endpoint} is one of the supported service endpoints at + https://cloud.google.com/vertex-ai/docs/reference/rest#rest_endpoints + Raises: + ValueError: If resource_name does not match the specified format. + """ + # TODO: support nested resource names such as models/123/evaluations/456 + match_results = re.match( + r"^projects\/[A-Za-z0-9-]*\/locations\/([A-Za-z0-9-]*)\/[A-Za-z0-9-]*\/[A-Za-z0-9-]*$", + resource_name, + ) + if not match_results: + raise ValueError(f"Invalid resource_name format for {resource_name}.") + + location = match_results.group(1) + return f"https://{location}-aiplatform.googleapis.com/v1/{resource_name}" diff --git a/google/cloud/aiplatform/metadata/utils.py b/google/cloud/aiplatform/metadata/utils.py new file mode 100644 index 0000000000..57eb4c0691 --- /dev/null +++ b/google/cloud/aiplatform/metadata/utils.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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 typing import List, Optional, Union + + +def _make_filter_string( + schema_title: Optional[Union[str, List[str]]] = None, + in_context: Optional[List[str]] = None, + parent_contexts: Optional[List[str]] = None, + uri: Optional[str] = None, +) -> str: + """Helper method to format filter strings for Metadata querying. + + No enforcement of correctness. + + Args: + schema_title (Union[str, List[str]]): Optional. schema_titles to filter for. + in_context (List[str]): + Optional. Context resource names that the node should be in. Only for Artifacts/Executions. + parent_contexts (List[str]): Optional. Parent contexts the context should be in. Only for Contexts. + uri (str): Optional. uri to match for. Only for Artifacts. + Returns: + String that can be used for Metadata service filtering. + """ + parts = [] + if schema_title: + if isinstance(schema_title, str): + parts.append(f'schema_title="{schema_title}"') + else: + substring = " OR ".join(f'schema_title="{s}"' for s in schema_title) + parts.append(f"({substring})") + if in_context: + for context in in_context: + parts.append(f'in_context("{context}")') + if parent_contexts: + parent_context_str = ",".join([f'"{c}"' for c in parent_contexts]) + parts.append(f"parent_contexts:{parent_context_str}") + if uri: + parts.append(f'uri="{uri}"') + return " AND ".join(parts) diff --git a/google/cloud/aiplatform/model_evaluation/__init__.py b/google/cloud/aiplatform/model_evaluation/__init__.py new file mode 100644 index 0000000000..7dcbee2db5 --- /dev/null +++ b/google/cloud/aiplatform/model_evaluation/__init__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- + +# Copyright 2022 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 google.cloud.aiplatform.model_evaluation.model_evaluation import ModelEvaluation + +__all__ = ("ModelEvaluation",) diff --git a/google/cloud/aiplatform/model_evaluation/model_evaluation.py b/google/cloud/aiplatform/model_evaluation/model_evaluation.py new file mode 100644 index 0000000000..f8553b7644 --- /dev/null +++ b/google/cloud/aiplatform/model_evaluation/model_evaluation.py @@ -0,0 +1,93 @@ +# -*- coding: utf-8 -*- + +# Copyright 2022 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 google.auth import credentials as auth_credentials + +from google.cloud.aiplatform import base +from google.cloud.aiplatform import utils +from google.cloud.aiplatform import models +from google.protobuf import struct_pb2 + +from typing import Optional + + +class ModelEvaluation(base.VertexAiResourceNounWithFutureManager): + + client_class = utils.ModelClientWithOverride + _resource_noun = "evaluations" + _delete_method = None + _getter_method = "get_model_evaluation" + _list_method = "list_model_evaluations" + _parse_resource_name_method = "parse_model_evaluation_path" + _format_resource_name_method = "model_evaluation_path" + + @property + def metrics(self) -> Optional[struct_pb2.Value]: + """Gets the evaluation metrics from the Model Evaluation. + Returns: + A dict with model metrics created from the Model Evaluation or + None if the metrics for this evaluation are empty. + """ + return self._gca_resource.metrics + + def __init__( + self, + evaluation_name: str, + model_id: Optional[str] = None, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ): + """Retrieves the ModelEvaluation resource and instantiates its representation. + + Args: + evaluation_name (str): + Required. A fully-qualified model evaluation resource name or evaluation ID. + Example: "projects/123/locations/us-central1/models/456/evaluations/789" or + "789". If passing only the evaluation ID, model_id must be provided. + model_id (str): + Optional. The ID of the model to retrieve this evaluation from. If passing + only the evaluation ID as evaluation_name, model_id must be provided. + project (str): + Optional project to retrieve model evaluation from. If not set, project + set in aiplatform.init will be used. + location (str): + Optional location to retrieve model evaluation from. If not set, location + set in aiplatform.init will be used. + credentials: Optional[auth_credentials.Credentials]=None, + Custom credentials to use to retrieve this model evaluation. If not set, + credentials set in aiplatform.init will be used. + """ + + super().__init__( + project=project, + location=location, + credentials=credentials, + resource_name=evaluation_name, + ) + + self._gca_resource = self._get_gca_resource( + resource_name=evaluation_name, + parent_resource_name_fields={models.Model._resource_noun: model_id} + if model_id + else model_id, + ) + + def delete(self): + raise NotImplementedError( + "Deleting a model evaluation has not been implemented yet." + ) diff --git a/google/cloud/aiplatform/models.py b/google/cloud/aiplatform/models.py index b93f569eaa..93243b5678 100644 --- a/google/cloud/aiplatform/models.py +++ b/google/cloud/aiplatform/models.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,44 +14,57 @@ # See the License for the specific language governing permissions and # limitations under the License. # +import pathlib import proto +import re +import shutil +import tempfile from typing import Dict, List, NamedTuple, Optional, Sequence, Tuple, Union from google.api_core import operation +from google.api_core import exceptions as api_exceptions from google.auth import credentials as auth_credentials +from google.cloud import aiplatform from google.cloud.aiplatform import base -from google.cloud.aiplatform import compat from google.cloud.aiplatform import explain from google.cloud.aiplatform import initializer from google.cloud.aiplatform import jobs from google.cloud.aiplatform import models from google.cloud.aiplatform import utils +from google.cloud.aiplatform.utils import gcs_utils +from google.cloud.aiplatform import model_evaluation from google.cloud.aiplatform.compat.services import endpoint_service_client from google.cloud.aiplatform.compat.types import ( encryption_spec as gca_encryption_spec, endpoint as gca_endpoint_compat, - endpoint_v1 as gca_endpoint_v1, - endpoint_v1beta1 as gca_endpoint_v1beta1, - explanation_v1beta1 as gca_explanation_v1beta1, + explanation as gca_explanation_compat, io as gca_io_compat, machine_resources as gca_machine_resources_compat, - machine_resources_v1beta1 as gca_machine_resources_v1beta1, model as gca_model_compat, model_service as gca_model_service_compat, - model_v1beta1 as gca_model_v1beta1, env_var as gca_env_var_compat, - env_var_v1beta1 as gca_env_var_v1beta1, ) -from google.protobuf import json_format +from google.protobuf import field_mask_pb2, json_format +_DEFAULT_MACHINE_TYPE = "n1-standard-2" +_DEPLOYING_MODEL_TRAFFIC_SPLIT_KEY = "0" _LOGGER = base.Logger(__name__) +_SUPPORTED_MODEL_FILE_NAMES = [ + "model.pkl", + "model.joblib", + "model.bst", + "saved_model.pb", + "saved_model.pbtxt", +] + + class Prediction(NamedTuple): """Prediction class envelopes returned Model predictions and the Model id. @@ -70,17 +83,18 @@ class Prediction(NamedTuple): predictions: Dict[str, List] deployed_model_id: str - explanations: Optional[Sequence[gca_explanation_v1beta1.Explanation]] = None + explanations: Optional[Sequence[gca_explanation_compat.Explanation]] = None class Endpoint(base.VertexAiResourceNounWithFutureManager): client_class = utils.EndpointClientWithOverride - _is_client_prediction_client = False _resource_noun = "endpoints" _getter_method = "get_endpoint" _list_method = "list_endpoints" _delete_method = "delete_endpoint" + _parse_resource_name_method = "parse_endpoint_path" + _format_resource_name_method = "endpoint_path" def __init__( self, @@ -113,30 +127,94 @@ def __init__( credentials=credentials, resource_name=endpoint_name, ) - self._gca_resource = self._get_gca_resource(resource_name=endpoint_name) + + endpoint_name = utils.full_resource_name( + resource_name=endpoint_name, + resource_noun="endpoints", + parse_resource_name_method=self._parse_resource_name, + format_resource_name_method=self._format_resource_name, + project=project, + location=location, + ) + + # Lazy load the Endpoint gca_resource until needed + self._gca_resource = gca_endpoint_compat.Endpoint(name=endpoint_name) + self._prediction_client = self._instantiate_prediction_client( - location=location or initializer.global_config.location, + location=self.location, credentials=credentials, ) + def _skipped_getter_call(self) -> bool: + """Check if GAPIC resource was populated by call to get/list API methods + + Returns False if `_gca_resource` is None or fully populated. Returns True + if `_gca_resource` is partially populated + """ + return self._gca_resource and not self._gca_resource.create_time + + def _sync_gca_resource_if_skipped(self) -> None: + """Sync GAPIC service representation of Endpoint class resource only if + get_endpoint() was never called.""" + if self._skipped_getter_call(): + self._gca_resource = self._get_gca_resource( + resource_name=self._gca_resource.name + ) + + def _assert_gca_resource_is_available(self) -> None: + """Ensures Endpoint getter was called at least once before + asserting on gca_resource's availability.""" + super()._assert_gca_resource_is_available() + self._sync_gca_resource_if_skipped() + + @property + def traffic_split(self) -> Dict[str, int]: + """A map from a DeployedModel's ID to the percentage of this Endpoint's + traffic that should be forwarded to that DeployedModel. + + If a DeployedModel's ID is not listed in this map, then it receives no traffic. + + The traffic percentage values must add up to 100, or map must be empty if + the Endpoint is to not accept any traffic at a moment. + """ + self._sync_gca_resource() + return dict(self._gca_resource.traffic_split) + + @property + def network(self) -> Optional[str]: + """The full name of the Google Compute Engine + [network](https://cloud.google.com/vpc/docs/vpc#networks) to which this + Endpoint should be peered. + + Takes the format `projects/{project}/global/networks/{network}`. Where + {project} is a project number, as in `12345`, and {network} is a network name. + + Private services access must already be configured for the network. If left + unspecified, the Endpoint is not peered with any network. + """ + self._assert_gca_resource_is_available() + return getattr(self._gca_resource, "network", None) + @classmethod def create( cls, - display_name: str, + display_name: Optional[str] = None, description: Optional[str] = None, - labels: Optional[Dict] = None, + labels: Optional[Dict[str, str]] = None, metadata: Optional[Sequence[Tuple[str, str]]] = (), project: Optional[str] = None, location: Optional[str] = None, credentials: Optional[auth_credentials.Credentials] = None, encryption_spec_key_name: Optional[str] = None, sync=True, + create_request_timeout: Optional[float] = None, + endpoint_id: Optional[str] = None, ) -> "Endpoint": """Creates a new endpoint. Args: display_name (str): - Required. The user-defined name of the Endpoint. + Optional. The user-defined name of the Endpoint. The name can be up to 128 characters long and can be consist of any UTF-8 characters. project (str): @@ -147,7 +225,7 @@ def create( set in aiplatform.init will be used. description (str): Optional. The description of the Endpoint. - labels (Dict): + labels (Dict[str, str]): Optional. The labels with user-defined metadata to organize your Endpoints. Label keys and values can be no longer than 64 @@ -178,6 +256,19 @@ def create( Whether to execute this method synchronously. If False, this method will be executed in concurrent Future and any downstream object will be immediately returned and synced when the Future has completed. + create_request_timeout (float): + Optional. The timeout for the create request in seconds. + endpoint_id (str): + Optional. The ID to use for endpoint, which will become + the final component of the endpoint resource name. If + not provided, Vertex AI will generate a value for this + ID. + + This value should be 1-10 characters, and valid + characters are /[0-9]/. When using HTTP/JSON, this field + is populated based on a query string argument, such as + ``?endpoint_id=12345``. This is the fallback for fields + that are not included in either the URI or the body. Returns: endpoint (endpoint.Endpoint): Created endpoint. @@ -185,7 +276,12 @@ def create( api_client = cls._instantiate_client(location=location, credentials=credentials) + if not display_name: + display_name = cls._generate_display_name() + utils.validate_display_name(display_name) + if labels: + utils.validate_labels(labels) project = project or initializer.global_config.project location = location or initializer.global_config.location @@ -203,6 +299,8 @@ def create( encryption_spec_key_name=encryption_spec_key_name ), sync=sync, + create_request_timeout=create_request_timeout, + endpoint_id=endpoint_id, ) @classmethod @@ -214,11 +312,13 @@ def _create( project: str, location: str, description: Optional[str] = None, - labels: Optional[Dict] = None, + labels: Optional[Dict[str, str]] = None, metadata: Optional[Sequence[Tuple[str, str]]] = (), credentials: Optional[auth_credentials.Credentials] = None, encryption_spec: Optional[gca_encryption_spec.EncryptionSpec] = None, sync=True, + create_request_timeout: Optional[float] = None, + endpoint_id: Optional[str] = None, ) -> "Endpoint": """Creates a new endpoint by calling the API client. @@ -238,7 +338,7 @@ def _create( set in aiplatform.init will be used. description (str): Optional. The description of the Endpoint. - labels (Dict): + labels (Dict[str, str]): Optional. The labels with user-defined metadata to organize your Endpoints. Label keys and values can be no longer than 64 @@ -262,6 +362,19 @@ def _create( If set, this Dataset and all sub-resources of this Dataset will be secured by this key. sync (bool): Whether to create this endpoint synchronously. + create_request_timeout (float): + Optional. The timeout for the create request in seconds. + endpoint_id (str): + Optional. The ID to use for endpoint, which will become + the final component of the endpoint resource name. If + not provided, Vertex AI will generate a value for this + ID. + + This value should be 1-10 characters, and valid + characters are /[0-9]/. When using HTTP/JSON, this field + is populated based on a query string argument, such as + ``?endpoint_id=12345``. This is the fallback for fields + that are not included in either the URI or the body. Returns: endpoint (endpoint.Endpoint): Created endpoint. @@ -279,7 +392,11 @@ def _create( ) operation_future = api_client.create_endpoint( - parent=parent, endpoint=gapic_endpoint, metadata=metadata + parent=parent, + endpoint=gapic_endpoint, + endpoint_id=endpoint_id, + metadata=metadata, + timeout=create_request_timeout, ) _LOGGER.log_create_with_lro(cls, operation_future) @@ -288,16 +405,58 @@ def _create( _LOGGER.log_create_complete(cls, created_endpoint, "endpoint") - return cls( - endpoint_name=created_endpoint.name, + return cls._construct_sdk_resource_from_gapic( + gapic_resource=created_endpoint, project=project, location=location, credentials=credentials, ) + @classmethod + def _construct_sdk_resource_from_gapic( + cls, + gapic_resource: proto.Message, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ) -> "Endpoint": + """Given a GAPIC Endpoint object, return the SDK representation. + + Args: + gapic_resource (proto.Message): + A GAPIC representation of a Endpoint resource, usually + retrieved by a get_* or in a list_* API call. + project (str): + Optional. Project to construct Endpoint object from. If not set, + project set in aiplatform.init will be used. + location (str): + Optional. Location to construct Endpoint object from. If not set, + location set in aiplatform.init will be used. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to construct Endpoint. + Overrides credentials set in aiplatform.init. + + Returns: + Endpoint: + An initialized Endpoint resource. + """ + endpoint = cls._empty_constructor( + project=project, location=location, credentials=credentials + ) + + endpoint._gca_resource = gapic_resource + + endpoint._prediction_client = cls._instantiate_prediction_client( + location=endpoint.location, + credentials=credentials, + ) + + return endpoint + @staticmethod def _allocate_traffic( - traffic_split: Dict[str, int], traffic_percentage: int, + traffic_split: Dict[str, int], + traffic_percentage: int, ) -> Dict[str, int]: """Allocates desired traffic to new deployed model and scales traffic of older deployed models. @@ -327,13 +486,14 @@ def _allocate_traffic( new_traffic_split[deployed_model] += 1 unallocated_traffic -= 1 - new_traffic_split["0"] = traffic_percentage + new_traffic_split[_DEPLOYING_MODEL_TRAFFIC_SPLIT_KEY] = traffic_percentage return new_traffic_split @staticmethod def _unallocate_traffic( - traffic_split: Dict[str, int], deployed_model_id: str, + traffic_split: Dict[str, int], + deployed_model_id: str, ) -> Dict[str, int]: """Sets deployed model id's traffic to 0 and scales the traffic of other deployed models. @@ -452,7 +612,6 @@ def _validate_deploy_args( raise ValueError("Traffic percentage cannot be negative.") elif traffic_split: - # TODO(b/172678233) verify every referenced deployed model exists if sum(traffic_split.values()) != 100: raise ValueError( "Sum of all traffic within traffic split needs to be 100." @@ -483,6 +642,9 @@ def deploy( explanation_parameters: Optional[explain.ExplanationParameters] = None, metadata: Optional[Sequence[Tuple[str, str]]] = (), sync=True, + deploy_request_timeout: Optional[float] = None, + autoscaling_target_cpu_utilization: Optional[int] = None, + autoscaling_target_accelerator_duty_cycle: Optional[int] = None, ) -> None: """Deploys a Model to the Endpoint. @@ -554,7 +716,17 @@ def deploy( Whether to execute this method synchronously. If False, this method will be executed in concurrent Future and any downstream object will be immediately returned and synced when the Future has completed. + deploy_request_timeout (float): + Optional. The timeout for the deploy request in seconds. + autoscaling_target_cpu_utilization (int): + Target CPU Utilization to use for Autoscaling Replicas. + A default value of 60 will be used if not specified. + autoscaling_target_accelerator_duty_cycle (int): + Target Accelerator Duty Cycle. + Must also set accelerator_type and accelerator_count if specified. + A default value of 60 will be used if not specified. """ + self._sync_gca_resource_if_skipped() self._validate_deploy_args( min_replica_count, @@ -582,6 +754,9 @@ def deploy( explanation_parameters=explanation_parameters, metadata=metadata, sync=sync, + deploy_request_timeout=deploy_request_timeout, + autoscaling_target_cpu_utilization=autoscaling_target_cpu_utilization, + autoscaling_target_accelerator_duty_cycle=autoscaling_target_accelerator_duty_cycle, ) @base.optional_sync() @@ -601,6 +776,9 @@ def _deploy( explanation_parameters: Optional[explain.ExplanationParameters] = None, metadata: Optional[Sequence[Tuple[str, str]]] = (), sync=True, + deploy_request_timeout: Optional[float] = None, + autoscaling_target_cpu_utilization: Optional[int] = None, + autoscaling_target_accelerator_duty_cycle: Optional[int] = None, ) -> None: """Deploys a Model to the Endpoint. @@ -672,8 +850,17 @@ def _deploy( Whether to execute this method synchronously. If False, this method will be executed in concurrent Future and any downstream object will be immediately returned and synced when the Future has completed. + deploy_request_timeout (float): + Optional. The timeout for the deploy request in seconds. + autoscaling_target_cpu_utilization (int): + Target CPU Utilization to use for Autoscaling Replicas. + A default value of 60 will be used if not specified. + autoscaling_target_accelerator_duty_cycle (int): + Target Accelerator Duty Cycle. + Must also set accelerator_type and accelerator_count if specified. + A default value of 60 will be used if not specified. Raises: - ValueError if there is not current traffic split and traffic percentage + ValueError: If there is not current traffic split and traffic percentage is not 0 or 100. """ _LOGGER.log_action_start_against_resource( @@ -683,7 +870,7 @@ def _deploy( self._deploy_call( self.api_client, self.resource_name, - model.resource_name, + model, self._gca_resource.traffic_split, deployed_model_display_name=deployed_model_display_name, traffic_percentage=traffic_percentage, @@ -697,6 +884,9 @@ def _deploy( explanation_metadata=explanation_metadata, explanation_parameters=explanation_parameters, metadata=metadata, + deploy_request_timeout=deploy_request_timeout, + autoscaling_target_cpu_utilization=autoscaling_target_cpu_utilization, + autoscaling_target_accelerator_duty_cycle=autoscaling_target_accelerator_duty_cycle, ) _LOGGER.log_action_completed_against_resource("model", "deployed", self) @@ -708,7 +898,7 @@ def _deploy_call( cls, api_client: endpoint_service_client.EndpointServiceClient, endpoint_resource_name: str, - model_resource_name: str, + model: "Model", endpoint_resource_traffic_split: Optional[proto.MapField] = None, deployed_model_display_name: Optional[str] = None, traffic_percentage: Optional[int] = 0, @@ -722,6 +912,9 @@ def _deploy_call( explanation_metadata: Optional[explain.ExplanationMetadata] = None, explanation_parameters: Optional[explain.ExplanationParameters] = None, metadata: Optional[Sequence[Tuple[str, str]]] = (), + deploy_request_timeout: Optional[float] = None, + autoscaling_target_cpu_utilization: Optional[int] = None, + autoscaling_target_accelerator_duty_cycle: Optional[int] = None, ): """Helper method to deploy model to endpoint. @@ -730,8 +923,8 @@ def _deploy_call( Required. endpoint_service_client.EndpointServiceClient to make call. endpoint_resource_name (str): Required. Endpoint resource name to deploy model to. - model_resource_name (str): - Required. Model resource name of Model to deploy. + model (aiplatform.Model): + Required. Model to be deployed. endpoint_resource_traffic_split (proto.MapField): Optional. Endpoint current resource traffic split. deployed_model_display_name (str): @@ -793,11 +986,21 @@ def _deploy_call( Whether to execute this method synchronously. If False, this method will be executed in concurrent Future and any downstream object will be immediately returned and synced when the Future has completed. + deploy_request_timeout (float): + Optional. The timeout for the deploy request in seconds. + autoscaling_target_cpu_utilization (int): + Optional. Target CPU Utilization to use for Autoscaling Replicas. + A default value of 60 will be used if not specified. + autoscaling_target_accelerator_duty_cycle (int): + Optional. Target Accelerator Duty Cycle. + Must also set accelerator_type and accelerator_count if specified. + A default value of 60 will be used if not specified. Raises: ValueError: If there is not current traffic split and traffic percentage is not 0 or 100. ValueError: If only `explanation_metadata` or `explanation_parameters` is specified. + ValueError: If model does not support deployment. """ max_replica_count = max(min_replica_count, max_replica_count) @@ -807,42 +1010,107 @@ def _deploy_call( "Both `accelerator_type` and `accelerator_count` should be specified or None." ) - gca_endpoint = gca_endpoint_compat - gca_machine_resources = gca_machine_resources_compat - if explanation_metadata and explanation_parameters: - gca_endpoint = gca_endpoint_v1beta1 - gca_machine_resources = gca_machine_resources_v1beta1 + if autoscaling_target_accelerator_duty_cycle is not None and ( + not accelerator_type or not accelerator_count + ): + raise ValueError( + "Both `accelerator_type` and `accelerator_count` should be set " + "when specifying autoscaling_target_accelerator_duty_cycle`" + ) - deployed_model = gca_endpoint.DeployedModel( - model=model_resource_name, + deployed_model = gca_endpoint_compat.DeployedModel( + model=model.resource_name, display_name=deployed_model_display_name, service_account=service_account, ) - if machine_type: - machine_spec = gca_machine_resources.MachineSpec(machine_type=machine_type) + supports_automatic_resources = ( + aiplatform.gapic.Model.DeploymentResourcesType.AUTOMATIC_RESOURCES + in model.supported_deployment_resources_types + ) + supports_dedicated_resources = ( + aiplatform.gapic.Model.DeploymentResourcesType.DEDICATED_RESOURCES + in model.supported_deployment_resources_types + ) + provided_custom_machine_spec = ( + machine_type + or accelerator_type + or accelerator_count + or autoscaling_target_accelerator_duty_cycle + or autoscaling_target_cpu_utilization + ) + + # If the model supports both automatic and dedicated deployment resources, + # decide based on the presence of machine spec customizations + use_dedicated_resources = supports_dedicated_resources and ( + not supports_automatic_resources or provided_custom_machine_spec + ) + + if provided_custom_machine_spec and not use_dedicated_resources: + _LOGGER.info( + "Model does not support dedicated deployment resources. " + "The machine_type, accelerator_type and accelerator_count," + "autoscaling_target_accelerator_duty_cycle," + "autoscaling_target_cpu_utilization parameters are ignored." + ) + + if use_dedicated_resources and not machine_type: + machine_type = _DEFAULT_MACHINE_TYPE + _LOGGER.info(f"Using default machine_type: {machine_type}") + + if use_dedicated_resources: + + dedicated_resources = gca_machine_resources_compat.DedicatedResources( + min_replica_count=min_replica_count, + max_replica_count=max_replica_count, + ) + + machine_spec = gca_machine_resources_compat.MachineSpec( + machine_type=machine_type + ) + + if autoscaling_target_cpu_utilization: + autoscaling_metric_spec = gca_machine_resources_compat.AutoscalingMetricSpec( + metric_name="aiplatform.googleapis.com/prediction/online/cpu/utilization", + target=autoscaling_target_cpu_utilization, + ) + dedicated_resources.autoscaling_metric_specs.extend( + [autoscaling_metric_spec] + ) if accelerator_type and accelerator_count: utils.validate_accelerator_type(accelerator_type) machine_spec.accelerator_type = accelerator_type machine_spec.accelerator_count = accelerator_count - deployed_model.dedicated_resources = gca_machine_resources.DedicatedResources( - machine_spec=machine_spec, - min_replica_count=min_replica_count, - max_replica_count=max_replica_count, - ) + if autoscaling_target_accelerator_duty_cycle: + autoscaling_metric_spec = gca_machine_resources_compat.AutoscalingMetricSpec( + metric_name="aiplatform.googleapis.com/prediction/online/accelerator/duty_cycle", + target=autoscaling_target_accelerator_duty_cycle, + ) + dedicated_resources.autoscaling_metric_specs.extend( + [autoscaling_metric_spec] + ) + + dedicated_resources.machine_spec = machine_spec + deployed_model.dedicated_resources = dedicated_resources + elif supports_automatic_resources: + deployed_model.automatic_resources = ( + gca_machine_resources_compat.AutomaticResources( + min_replica_count=min_replica_count, + max_replica_count=max_replica_count, + ) + ) else: - deployed_model.automatic_resources = gca_machine_resources.AutomaticResources( - min_replica_count=min_replica_count, - max_replica_count=max_replica_count, + raise ValueError( + "Model does not support deployment. " + "See https://cloud.google.com/vertex-ai/docs/reference/rpc/google.cloud.aiplatform.v1#google.cloud.aiplatform.v1.Model.FIELDS.repeated.google.cloud.aiplatform.v1.Model.DeploymentResourcesType.google.cloud.aiplatform.v1.Model.supported_deployment_resources_types" ) # Service will throw error if both metadata and parameters are not provided if explanation_metadata and explanation_parameters: - api_client = api_client.select_version(compat.V1BETA1) - explanation_spec = gca_endpoint.explanation.ExplanationSpec() + explanation_spec = gca_endpoint_compat.explanation.ExplanationSpec() explanation_spec.metadata = explanation_metadata explanation_spec.parameters = explanation_parameters deployed_model.explanation_spec = explanation_spec @@ -869,6 +1137,7 @@ def _deploy_call( deployed_model=deployed_model, traffic_split=traffic_split, metadata=metadata, + timeout=deploy_request_timeout, ) _LOGGER.log_action_started_against_resource_with_lro( @@ -886,34 +1155,49 @@ def undeploy( ) -> None: """Undeploys a deployed model. - Proportionally adjusts the traffic_split among the remaining deployed - models of the endpoint. + The model to be undeployed should have no traffic or user must provide + a new traffic_split with the remaining deployed models. Refer + to `Endpoint.traffic_split` for the current traffic split mapping. Args: deployed_model_id (str): Required. The ID of the DeployedModel to be undeployed from the Endpoint. traffic_split (Dict[str, int]): - Optional. A map from a DeployedModel's ID to the percentage of + Optional. A map of DeployedModel IDs to the percentage of this Endpoint's traffic that should be forwarded to that DeployedModel. - If a DeployedModel's ID is not listed in this map, then it receives - no traffic. The traffic percentage values must add up to 100, or - map must be empty if the Endpoint is to not accept any traffic at - the moment. Key for model being deployed is "0". Should not be - provided if traffic_percentage is provided. + Required if undeploying a model with non-zero traffic from an Endpoint + with multiple deployed models. The traffic percentage values must add + up to 100, or map must be empty if the Endpoint is to not accept any traffic + at the moment. If a DeployedModel's ID is not listed in this map, then it + receives no traffic. metadata (Sequence[Tuple[str, str]]): Optional. Strings which should be sent along with the request as metadata. """ + self._sync_gca_resource_if_skipped() + if traffic_split is not None: if deployed_model_id in traffic_split and traffic_split[deployed_model_id]: raise ValueError("Model being undeployed should have 0 traffic.") if sum(traffic_split.values()) != 100: - # TODO(b/172678233) verify every referenced deployed model exists raise ValueError( "Sum of all traffic within traffic split needs to be 100." ) + # Two or more models deployed to Endpoint and remaining traffic will be zero + elif ( + len(self.traffic_split) > 1 + and deployed_model_id in self._gca_resource.traffic_split + and self._gca_resource.traffic_split[deployed_model_id] == 100 + ): + raise ValueError( + f"Undeploying deployed model '{deployed_model_id}' would leave the remaining " + "traffic split at 0%. Traffic split must add up to 100% when models are " + "deployed. Please undeploy the other models first or provide an updated " + "traffic_split." + ) + self._undeploy( deployed_model_id=deployed_model_id, traffic_split=traffic_split, @@ -950,6 +1234,7 @@ def _undeploy( Optional. Strings which should be sent along with the request as metadata. """ + self._sync_gca_resource_if_skipped() current_traffic_split = traffic_split or dict(self._gca_resource.traffic_split) if deployed_model_id in current_traffic_split: @@ -996,7 +1281,7 @@ def _instantiate_prediction_client( the prediction client. Returns: prediction_client (prediction_service_client.PredictionServiceClient): - Initalized prediction client with optional overrides. + Initialized prediction client with optional overrides. """ return initializer.global_config.create_client( client_class=utils.PredictionClientWithOverride, @@ -1005,7 +1290,110 @@ def _instantiate_prediction_client( prediction_client=True, ) - def predict(self, instances: List, parameters: Optional[Dict] = None) -> Prediction: + def update( + self, + display_name: Optional[str] = None, + description: Optional[str] = None, + labels: Optional[Dict[str, str]] = None, + traffic_split: Optional[Dict[str, int]] = None, + request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + update_request_timeout: Optional[float] = None, + ) -> "Endpoint": + """Updates an endpoint. + + Example usage: + + my_endpoint = my_endpoint.update( + display_name='my-updated-endpoint', + description='my updated description', + labels={'key': 'value'}, + traffic_split={ + '123456': 20, + '234567': 80, + }, + ) + + Args: + display_name (str): + Optional. The display name of the Endpoint. + The name can be up to 128 characters long and can be consist of any UTF-8 + characters. + description (str): + Optional. The description of the Endpoint. + labels (Dict[str, str]): + Optional. The labels with user-defined metadata to organize your Endpoints. + Label keys and values can be no longer than 64 characters + (Unicode codepoints), can only contain lowercase letters, numeric + characters, underscores and dashes. International characters are allowed. + See https://goo.gl/xmQnxf for more information and examples of labels. + traffic_split (Dict[str, int]): + Optional. A map from a DeployedModel's ID to the percentage of this Endpoint's + traffic that should be forwarded to that DeployedModel. + If a DeployedModel's ID is not listed in this map, then it receives no traffic. + The traffic percentage values must add up to 100, or map must be empty if + the Endpoint is to not accept any traffic at a moment. + request_metadata (Sequence[Tuple[str, str]]): + Optional. Strings which should be sent along with the request as metadata. + update_request_timeout (float): + Optional. The timeout for the update request in seconds. + + Returns: + Endpoint - Updated endpoint resource. + + Raises: + ValueError: If `labels` is not the correct format. + """ + + self.wait() + + current_endpoint_proto = self.gca_resource + copied_endpoint_proto = current_endpoint_proto.__class__(current_endpoint_proto) + + update_mask: List[str] = [] + + if display_name: + utils.validate_display_name(display_name) + copied_endpoint_proto.display_name = display_name + update_mask.append("display_name") + + if description: + copied_endpoint_proto.description = description + update_mask.append("description") + + if labels: + utils.validate_labels(labels) + copied_endpoint_proto.labels = labels + update_mask.append("labels") + + if traffic_split: + update_mask.append("traffic_split") + copied_endpoint_proto.traffic_split = traffic_split + + update_mask = field_mask_pb2.FieldMask(paths=update_mask) + + _LOGGER.log_action_start_against_resource( + "Updating", + "endpoint", + self, + ) + + self._gca_resource = self.api_client.update_endpoint( + endpoint=copied_endpoint_proto, + update_mask=update_mask, + metadata=request_metadata, + timeout=update_request_timeout, + ) + + _LOGGER.log_action_completed_against_resource("endpoint", "updated", self) + + return self + + def predict( + self, + instances: List, + parameters: Optional[Dict] = None, + timeout: Optional[float] = None, + ) -> Prediction: """Make a prediction against this Endpoint. Args: @@ -1028,13 +1416,17 @@ def predict(self, instances: List, parameters: Optional[Dict] = None) -> Predict ][google.cloud.aiplatform.v1beta1.DeployedModel.model] [PredictSchemata's][google.cloud.aiplatform.v1beta1.Model.predict_schemata] ``parameters_schema_uri``. + timeout (float): Optional. The timeout for this request in seconds. Returns: prediction: Prediction with returned predictions and Model Id. """ self.wait() prediction_response = self._prediction_client.predict( - endpoint=self.resource_name, instances=instances, parameters=parameters + endpoint=self._gca_resource.name, + instances=instances, + parameters=parameters, + timeout=timeout, ) return Prediction( @@ -1050,6 +1442,7 @@ def explain( instances: List[Dict], parameters: Optional[Dict] = None, deployed_model_id: Optional[str] = None, + timeout: Optional[float] = None, ) -> Prediction: """Make a prediction with explanations against this Endpoint. @@ -1080,18 +1473,18 @@ def explain( deployed_model_id (str): Optional. If specified, this ExplainRequest will be served by the chosen DeployedModel, overriding this Endpoint's traffic split. + timeout (float): Optional. The timeout for this request in seconds. Returns: prediction: Prediction with returned predictions, explanations and Model Id. """ self.wait() - explain_response = self._prediction_client.select_version( - compat.V1BETA1 - ).explain( + explain_response = self._prediction_client.explain( endpoint=self.resource_name, instances=instances, parameters=parameters, deployed_model_id=deployed_model_id, + timeout=timeout, ) return Prediction( @@ -1150,19 +1543,15 @@ def list( credentials=credentials, ) - def list_models( - self, - ) -> Sequence[ - Union[gca_endpoint_v1.DeployedModel, gca_endpoint_v1beta1.DeployedModel] - ]: + def list_models(self) -> List[gca_endpoint_compat.DeployedModel]: """Returns a list of the models deployed to this Endpoint. Returns: - deployed_models (Sequence[aiplatform.gapic.DeployedModel]): + deployed_models (List[aiplatform.gapic.DeployedModel]): A list of the models deployed in this Endpoint. """ self._sync_gca_resource() - return self._gca_resource.deployed_models + return list(self._gca_resource.deployed_models) def undeploy_all(self, sync: bool = True) -> "Endpoint": """Undeploys every model deployed to this Endpoint. @@ -1175,8 +1564,13 @@ def undeploy_all(self, sync: bool = True) -> "Endpoint": """ self._sync_gca_resource() - for deployed_model in self._gca_resource.deployed_models: - self._undeploy(deployed_model_id=deployed_model.id, sync=sync) + models_to_undeploy = sorted( # Undeploy zero traffic models first + self._gca_resource.traffic_split.keys(), + key=lambda id: self._gca_resource.traffic_split[id], + ) + + for deployed_model in models_to_undeploy: + self._undeploy(deployed_model_id=deployed_model, sync=sync) return self @@ -1204,20 +1598,24 @@ def delete(self, force: bool = False, sync: bool = True) -> None: class Model(base.VertexAiResourceNounWithFutureManager): client_class = utils.ModelClientWithOverride - _is_client_prediction_client = False _resource_noun = "models" _getter_method = "get_model" _list_method = "list_models" _delete_method = "delete_model" + _parse_resource_name_method = "parse_model_path" + _format_resource_name_method = "model_path" @property - def uri(self): - """Uri of the model.""" - return self._gca_resource.artifact_uri + def uri(self) -> Optional[str]: + """Path to the directory containing the Model artifact and any of its + supporting files. Not present for AutoML Models.""" + self._assert_gca_resource_is_available() + return self._gca_resource.artifact_uri or None @property - def description(self): + def description(self) -> str: """Description of the model.""" + self._assert_gca_resource_is_available() return self._gca_resource.description @property @@ -1232,6 +1630,7 @@ def supported_export_formats( {'tf-saved-model': []} """ + self._assert_gca_resource_is_available() return { export_format.id: [ gca_model_compat.Model.ExportFormat.ExportableContent(content) @@ -1240,6 +1639,104 @@ def supported_export_formats( for export_format in self._gca_resource.supported_export_formats } + @property + def supported_deployment_resources_types( + self, + ) -> List[aiplatform.gapic.Model.DeploymentResourcesType]: + """List of deployment resource types accepted for this Model. + + When this Model is deployed, its prediction resources are described by + the `prediction_resources` field of the objects returned by + `Endpoint.list_models()`. Because not all Models support all resource + configuration types, the configuration types this Model supports are + listed here. + + If no configuration types are listed, the Model cannot be + deployed to an `Endpoint` and does not support online predictions + (`Endpoint.predict()` or `Endpoint.explain()`). Such a Model can serve + predictions by using a `BatchPredictionJob`, if it has at least one entry + each in `Model.supported_input_storage_formats` and + `Model.supported_output_storage_formats`.""" + self._assert_gca_resource_is_available() + return list(self._gca_resource.supported_deployment_resources_types) + + @property + def supported_input_storage_formats(self) -> List[str]: + """The formats this Model supports in the `input_config` field of a + `BatchPredictionJob`. If `Model.predict_schemata.instance_schema_uri` + exists, the instances should be given as per that schema. + + [Read the docs for more on batch prediction formats](https://cloud.google.com/vertex-ai/docs/predictions/batch-predictions#batch_request_input) + + If this Model doesn't support any of these formats it means it cannot be + used with a `BatchPredictionJob`. However, if it has + `supported_deployment_resources_types`, it could serve online predictions + by using `Endpoint.predict()` or `Endpoint.explain()`. + """ + self._assert_gca_resource_is_available() + return list(self._gca_resource.supported_input_storage_formats) + + @property + def supported_output_storage_formats(self) -> List[str]: + """The formats this Model supports in the `output_config` field of a + `BatchPredictionJob`. + + If both `Model.predict_schemata.instance_schema_uri` and + `Model.predict_schemata.prediction_schema_uri` exist, the predictions + are returned together with their instances. In other words, the + prediction has the original instance data first, followed by the actual + prediction content (as per the schema). + + [Read the docs for more on batch prediction formats](https://cloud.google.com/vertex-ai/docs/predictions/batch-predictions) + + If this Model doesn't support any of these formats it means it cannot be + used with a `BatchPredictionJob`. However, if it has + `supported_deployment_resources_types`, it could serve online predictions + by using `Endpoint.predict()` or `Endpoint.explain()`. + """ + self._assert_gca_resource_is_available() + return list(self._gca_resource.supported_output_storage_formats) + + @property + def predict_schemata(self) -> Optional[aiplatform.gapic.PredictSchemata]: + """The schemata that describe formats of the Model's predictions and + explanations, if available.""" + self._assert_gca_resource_is_available() + return getattr(self._gca_resource, "predict_schemata") + + @property + def training_job(self) -> Optional["aiplatform.training_jobs._TrainingJob"]: + """The TrainingJob that uploaded this Model, if any. + + Raises: + api_core.exceptions.NotFound: If the Model's training job resource + cannot be found on the Vertex service. + """ + self._assert_gca_resource_is_available() + job_name = getattr(self._gca_resource, "training_pipeline") + + if not job_name: + return None + + try: + return aiplatform.training_jobs._TrainingJob._get_and_return_subclass( + resource_name=job_name, + project=self.project, + location=self.location, + credentials=self.credentials, + ) + except api_exceptions.NotFound: + raise api_exceptions.NotFound( + f"The training job used to create this model could not be found: {job_name}" + ) + + @property + def container_spec(self) -> Optional[aiplatform.gapic.ModelContainerSpec]: + """The specification of the container that is to be used when deploying + this Model. Not present for AutoML Models.""" + self._assert_gca_resource_is_available() + return getattr(self._gca_resource, "container_spec") + def __init__( self, model_name: str, @@ -1273,13 +1770,81 @@ def __init__( ) self._gca_resource = self._get_gca_resource(resource_name=model_name) + def update( + self, + display_name: Optional[str] = None, + description: Optional[str] = None, + labels: Optional[Dict[str, str]] = None, + ) -> "Model": + """Updates a model. + + Example usage: + + my_model = my_model.update( + display_name='my-model', + description='my description', + labels={'key': 'value'}, + ) + + Args: + display_name (str): + The display name of the Model. The name can be up to 128 + characters long and can be consist of any UTF-8 characters. + description (str): + The description of the model. + labels (Dict[str, str]): + Optional. The labels with user-defined metadata to + organize your Models. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + and examples of labels. + Returns: + model: Updated model resource. + Raises: + ValueError: If `labels` is not the correct format. + """ + + self.wait() + + current_model_proto = self.gca_resource + copied_model_proto = current_model_proto.__class__(current_model_proto) + + update_mask: List[str] = [] + + if display_name: + utils.validate_display_name(display_name) + + copied_model_proto.display_name = display_name + update_mask.append("display_name") + + if description: + copied_model_proto.description = description + update_mask.append("description") + + if labels: + utils.validate_labels(labels) + + copied_model_proto.labels = labels + update_mask.append("labels") + + update_mask = field_mask_pb2.FieldMask(paths=update_mask) + + self.api_client.update_model(model=copied_model_proto, update_mask=update_mask) + + self._sync_gca_resource() + + return self + # TODO(b/170979552) Add support for predict schemata # TODO(b/170979926) Add support for metadata and metadata schema @classmethod @base.optional_sync() def upload( cls, - display_name: str, serving_container_image_uri: str, *, artifact_uri: Optional[str] = None, @@ -1295,11 +1860,15 @@ def upload( prediction_schema_uri: Optional[str] = None, explanation_metadata: Optional[explain.ExplanationMetadata] = None, explanation_parameters: Optional[explain.ExplanationParameters] = None, + display_name: Optional[str] = None, project: Optional[str] = None, location: Optional[str] = None, credentials: Optional[auth_credentials.Credentials] = None, + labels: Optional[Dict[str, str]] = None, encryption_spec_key_name: Optional[str] = None, + staging_bucket: Optional[str] = None, sync=True, + upload_request_timeout: Optional[float] = None, ) -> "Model": """Uploads a model and returns a Model representing the uploaded Model resource. @@ -1314,7 +1883,7 @@ def upload( Args: display_name (str): - Required. The display name of the Model. The name can be up to 128 + Optional. The display name of the Model. The name can be up to 128 characters long and can be consist of any UTF-8 characters. serving_container_image_uri (str): Required. The URI of the Model serving container. @@ -1421,6 +1990,16 @@ def upload( credentials: Optional[auth_credentials.Credentials]=None, Custom credentials to use to upload this model. Overrides credentials set in aiplatform.init. + labels (Dict[str, str]): + Optional. The labels with user-defined metadata to + organize your Models. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + and examples of labels. encryption_spec_key_name (Optional[str]): Optional. The Cloud KMS resource identifier of the customer managed encryption key used to protect the model. Has the @@ -1432,42 +2011,45 @@ def upload( If set, this Model and all sub-resources of this Model will be secured by this key. Overrides encryption_spec_key_name set in aiplatform.init. + staging_bucket (str): + Optional. Bucket to stage local model artifacts. Overrides + staging_bucket set in aiplatform.init. + upload_request_timeout (float): + Optional. The timeout for the upload request in seconds. Returns: model: Instantiated representation of the uploaded model resource. Raises: ValueError: If only `explanation_metadata` or `explanation_parameters` is specified. + Also if model directory does not contain a supported model file. """ + if not display_name: + display_name = cls._generate_display_name() utils.validate_display_name(display_name) + if labels: + utils.validate_labels(labels) if bool(explanation_metadata) != bool(explanation_parameters): raise ValueError( "Both `explanation_metadata` and `explanation_parameters` should be specified or None." ) - gca_endpoint = gca_endpoint_compat - gca_model = gca_model_compat - gca_env_var = gca_env_var_compat - if explanation_metadata and explanation_parameters: - gca_endpoint = gca_endpoint_v1beta1 - gca_model = gca_model_v1beta1 - gca_env_var = gca_env_var_v1beta1 - api_client = cls._instantiate_client(location, credentials) env = None ports = None if serving_container_environment_variables: env = [ - gca_env_var.EnvVar(name=str(key), value=str(value)) + gca_env_var_compat.EnvVar(name=str(key), value=str(value)) for key, value in serving_container_environment_variables.items() ] if serving_container_ports: ports = [ - gca_model.Port(container_port=port) for port in serving_container_ports + gca_model_compat.Port(container_port=port) + for port in serving_container_ports ] - container_spec = gca_model.ModelContainerSpec( + container_spec = gca_model_compat.ModelContainerSpec( image_uri=serving_container_image_uri, command=serving_container_command, args=serving_container_args, @@ -1479,7 +2061,7 @@ def upload( model_predict_schemata = None if any([instance_schema_uri, parameters_schema_uri, prediction_schema_uri]): - model_predict_schemata = gca_model.PredictSchemata( + model_predict_schemata = gca_model_compat.PredictSchemata( instance_schema_uri=instance_schema_uri, parameters_schema_uri=parameters_schema_uri, prediction_schema_uri=prediction_schema_uri, @@ -1490,21 +2072,51 @@ def upload( encryption_spec_key_name=encryption_spec_key_name, ) - managed_model = gca_model.Model( + managed_model = gca_model_compat.Model( display_name=display_name, description=description, container_spec=container_spec, predict_schemata=model_predict_schemata, + labels=labels, encryption_spec=encryption_spec, ) + if artifact_uri and not artifact_uri.startswith("gs://"): + model_dir = pathlib.Path(artifact_uri) + # Validating the model directory + if not model_dir.exists(): + raise ValueError(f"artifact_uri path does not exist: '{artifact_uri}'") + PREBUILT_IMAGE_RE = "(us|europe|asia)-docker.pkg.dev/vertex-ai/prediction/" + if re.match(PREBUILT_IMAGE_RE, serving_container_image_uri): + if not model_dir.is_dir(): + raise ValueError( + f"artifact_uri path must be a directory: '{artifact_uri}' when using prebuilt image '{serving_container_image_uri}'" + ) + if not any( + (model_dir / file_name).exists() + for file_name in _SUPPORTED_MODEL_FILE_NAMES + ): + raise ValueError( + "artifact_uri directory does not contain any supported model files. " + f"When using a prebuilt serving image, the upload method only supports the following model files: '{_SUPPORTED_MODEL_FILE_NAMES}'" + ) + + # Uploading the model + staged_data_uri = gcs_utils.stage_local_data_in_gcs( + data_path=str(model_dir), + staging_gcs_dir=staging_bucket, + project=project, + location=location, + credentials=credentials, + ) + artifact_uri = staged_data_uri + if artifact_uri: managed_model.artifact_uri = artifact_uri # Override explanation_spec if both required fields are provided if explanation_metadata and explanation_parameters: - api_client = api_client.select_version(compat.V1BETA1) - explanation_spec = gca_endpoint.explanation.ExplanationSpec() + explanation_spec = gca_endpoint_compat.explanation.ExplanationSpec() explanation_spec.metadata = explanation_metadata explanation_spec.parameters = explanation_parameters managed_model.explanation_spec = explanation_spec @@ -1512,6 +2124,7 @@ def upload( lro = api_client.upload_model( parent=initializer.global_config.common_location_path(project, location), model=managed_model, + timeout=upload_request_timeout, ) _LOGGER.log_create_with_lro(cls, lro) @@ -1542,6 +2155,9 @@ def deploy( metadata: Optional[Sequence[Tuple[str, str]]] = (), encryption_spec_key_name: Optional[str] = None, sync=True, + deploy_request_timeout: Optional[float] = None, + autoscaling_target_cpu_utilization: Optional[int] = None, + autoscaling_target_accelerator_duty_cycle: Optional[int] = None, ) -> Endpoint: """Deploys model to endpoint. Endpoint will be created if unspecified. @@ -1624,6 +2240,15 @@ def deploy( Whether to execute this method synchronously. If False, this method will be executed in concurrent Future and any downstream object will be immediately returned and synced when the Future has completed. + deploy_request_timeout (float): + Optional. The timeout for the deploy request in seconds. + autoscaling_target_cpu_utilization (int): + Optional. Target CPU Utilization to use for Autoscaling Replicas. + A default value of 60 will be used if not specified. + autoscaling_target_accelerator_duty_cycle (int): + Optional. Target Accelerator Duty Cycle. + Must also set accelerator_type and accelerator_count if specified. + A default value of 60 will be used if not specified. Returns: endpoint ("Endpoint"): Endpoint with the deployed model. @@ -1657,6 +2282,9 @@ def deploy( encryption_spec_key_name=encryption_spec_key_name or initializer.global_config.encryption_spec_key_name, sync=sync, + deploy_request_timeout=deploy_request_timeout, + autoscaling_target_cpu_utilization=autoscaling_target_cpu_utilization, + autoscaling_target_accelerator_duty_cycle=autoscaling_target_accelerator_duty_cycle, ) @base.optional_sync(return_input_arg="endpoint", bind_future_to_self=False) @@ -1677,6 +2305,9 @@ def _deploy( metadata: Optional[Sequence[Tuple[str, str]]] = (), encryption_spec_key_name: Optional[str] = None, sync: bool = True, + deploy_request_timeout: Optional[float] = None, + autoscaling_target_cpu_utilization: Optional[int] = None, + autoscaling_target_accelerator_duty_cycle: Optional[int] = None, ) -> Endpoint: """Deploys model to endpoint. Endpoint will be created if unspecified. @@ -1759,6 +2390,15 @@ def _deploy( Whether to execute this method synchronously. If False, this method will be executed in concurrent Future and any downstream object will be immediately returned and synced when the Future has completed. + deploy_request_timeout (float): + Optional. The timeout for the deploy request in seconds. + autoscaling_target_cpu_utilization (int): + Optional. Target CPU Utilization to use for Autoscaling Replicas. + A default value of 60 will be used if not specified. + autoscaling_target_accelerator_duty_cycle (int): + Optional. Target Accelerator Duty Cycle. + Must also set accelerator_type and accelerator_count if specified. + A default value of 60 will be used if not specified. Returns: endpoint ("Endpoint"): Endpoint with the deployed model. @@ -1779,7 +2419,7 @@ def _deploy( Endpoint._deploy_call( endpoint.api_client, endpoint.resource_name, - self.resource_name, + self, endpoint._gca_resource.traffic_split, deployed_model_display_name=deployed_model_display_name, traffic_percentage=traffic_percentage, @@ -1793,6 +2433,9 @@ def _deploy( explanation_metadata=explanation_metadata, explanation_parameters=explanation_parameters, metadata=metadata, + deploy_request_timeout=deploy_request_timeout, + autoscaling_target_cpu_utilization=autoscaling_target_cpu_utilization, + autoscaling_target_accelerator_duty_cycle=autoscaling_target_accelerator_duty_cycle, ) _LOGGER.log_action_completed_against_resource("model", "deployed", endpoint) @@ -1803,7 +2446,7 @@ def _deploy( def batch_predict( self, - job_display_name: str, + job_display_name: Optional[str] = None, gcs_source: Optional[Union[str, Sequence[str]]] = None, bigquery_source: Optional[str] = None, instances_format: str = "jsonl", @@ -1819,10 +2462,12 @@ def batch_predict( generate_explanation: Optional[bool] = False, explanation_metadata: Optional[explain.ExplanationMetadata] = None, explanation_parameters: Optional[explain.ExplanationParameters] = None, - labels: Optional[dict] = None, + labels: Optional[Dict[str, str]] = None, credentials: Optional[auth_credentials.Credentials] = None, encryption_spec_key_name: Optional[str] = None, sync: bool = True, + create_request_timeout: Optional[float] = None, + batch_size: Optional[int] = None, ) -> jobs.BatchPredictionJob: """Creates a batch prediction job using this Model and outputs prediction results to the provided destination prefix in the specified @@ -1840,22 +2485,20 @@ def batch_predict( Args: job_display_name (str): - Required. The user-defined name of the BatchPredictionJob. + Optional. The user-defined name of the BatchPredictionJob. The name can be up to 128 characters long and can be consist of any UTF-8 characters. gcs_source: Optional[Sequence[str]] = None Google Cloud Storage URI(-s) to your instances to run batch prediction on. They must match `instances_format`. - May contain wildcards. For more information on wildcards, see - https://cloud.google.com/storage/docs/gsutil/addlhelp/WildcardNames. bigquery_source: Optional[str] = None BigQuery URI to a table, up to 2000 characters long. For example: - `projectId.bqDatasetId.bqTableId` + `bq://projectId.bqDatasetId.bqTableId` instances_format: str = "jsonl" - Required. The format in which instances are given, must be one - of "jsonl", "csv", "bigquery", "tf-record", "tf-record-gzip", - or "file-list". Default is "jsonl" when using `gcs_source`. If a - `bigquery_source` is provided, this is overriden to "bigquery". + The format in which instances are provided. Must be one + of the formats listed in `Model.supported_input_storage_formats`. + Default is "jsonl" when using `gcs_source`. If a `bigquery_source` + is provided, this is overridden to "bigquery". gcs_destination_prefix: Optional[str] = None The Google Cloud Storage location of the directory where the output is to be written to. In the given directory a new @@ -1879,29 +2522,33 @@ def batch_predict( which as value has ```google.rpc.Status`` `__ containing only ``code`` and ``message`` fields. bigquery_destination_prefix: Optional[str] = None - The BigQuery project location where the output is to be - written to. In the given project a new dataset is created - with name - ``prediction__`` where - is made BigQuery-dataset-name compatible (for example, most - special characters become underscores), and timestamp is in - YYYY_MM_DDThh_mm_ss_sssZ "based on ISO-8601" format. In the - dataset two tables will be created, ``predictions``, and - ``errors``. If the Model has both ``instance`` and ``prediction`` - schemata defined then the tables have columns as follows: - The ``predictions`` table contains instances for which the - prediction succeeded, it has columns as per a concatenation - of the Model's instance and prediction schemata. The - ``errors`` table contains rows for which the prediction has - failed, it has instance columns, as per the instance schema, - followed by a single "errors" column, which as values has - ```google.rpc.Status`` `__ represented as a STRUCT, - and containing only ``code`` and ``message``. + The BigQuery URI to a project or table, up to 2000 characters long. + When only the project is specified, the Dataset and Table is created. + When the full table reference is specified, the Dataset must exist and + table must not exist. Accepted forms: ``bq://projectId`` or + ``bq://projectId.bqDatasetId`` or + ``bq://projectId.bqDatasetId.bqTableId``. If no Dataset is specified, + a new one is created with the name + ``prediction__`` + where the table name is made BigQuery-dataset-name compatible + (for example, most special characters become underscores), and + timestamp is in YYYY_MM_DDThh_mm_ss_sssZ "based on ISO-8601" + format. In the dataset two tables will be created, ``predictions``, + and ``errors``. If the Model has both ``instance`` and + ``prediction`` schemata defined then the tables have columns as + follows: The ``predictions`` table contains instances for which + the prediction succeeded, it has columns as per a concatenation + of the Model's instance and prediction schemata. The ``errors`` + table contains rows for which the prediction has failed, it has + instance columns, as per the instance schema, followed by a single + "errors" column, which as values has ```google.rpc.Status`` `__ + represented as a STRUCT, and containing only ``code`` and ``message``. predictions_format: str = "jsonl" - Required. The format in which Vertex AI gives the - predictions, must be one of "jsonl", "csv", or "bigquery". + Required. The format in which Vertex AI outputs the + predictions, must be one of the formats specified in + `Model.supported_output_storage_formats`. Default is "jsonl" when using `gcs_destination_prefix`. If a - `bigquery_destination_prefix` is provided, this is overriden to + `bigquery_destination_prefix` is provided, this is overridden to "bigquery". model_parameters: Optional[Dict] = None Optional. The parameters that govern the predictions. The schema of @@ -1954,7 +2601,7 @@ def batch_predict( a field of the `explanation_parameters` object is not populated, the corresponding field of the `Model.explanation_parameters` object is inherited. For more details, see `Ref docs ` - labels: Optional[dict] = None + labels: Optional[Dict[str, str]] = None Optional. The labels with user-defined metadata to organize your BatchPredictionJobs. Label keys and values can be no longer than 64 characters (Unicode codepoints), can only contain lowercase @@ -1975,15 +2622,23 @@ def batch_predict( If set, this Model and all sub-resources of this Model will be secured by this key. Overrides encryption_spec_key_name set in aiplatform.init. + create_request_timeout (float): + Optional. The timeout for the create request in seconds. + batch_size (int): + Optional. The number of the records (e.g. instances) of the operation given in each batch + to a machine replica. Machine type, and size of a single record should be considered + when setting this parameter, higher value speeds up the batch operation's execution, + but too high value will result in a whole batch not fitting in a machine's memory, + and the whole operation will fail. + The default value is 64. Returns: (jobs.BatchPredictionJob): Instantiated representation of the created batch prediction job. """ - self.wait() return jobs.BatchPredictionJob.create( job_display_name=job_display_name, - model_name=self.resource_name, + model_name=self, instances_format=instances_format, predictions_format=predictions_format, gcs_source=gcs_source, @@ -1996,6 +2651,7 @@ def batch_predict( accelerator_count=accelerator_count, starting_replica_count=starting_replica_count, max_replica_count=max_replica_count, + batch_size=batch_size, generate_explanation=generate_explanation, explanation_metadata=explanation_metadata, explanation_parameters=explanation_parameters, @@ -2005,6 +2661,7 @@ def batch_predict( credentials=credentials or self.credentials, encryption_spec_key_name=encryption_spec_key_name, sync=sync, + create_request_timeout=create_request_timeout, ) @classmethod @@ -2119,11 +2776,13 @@ def export_model( Details of the completed export with output destination paths to the artifacts or container image. Raises: - ValueError if model does not support exporting. + ValueError: If model does not support exporting. - ValueError if invalid arguments or export formats are provided. + ValueError: If invalid arguments or export formats are provided. """ + self.wait() + # Model does not support exporting if not self.supported_export_formats: raise ValueError(f"The model `{self.resource_name}` is not exportable.") @@ -2172,8 +2831,8 @@ def export_model( ) if image_destination: - output_config.image_destination = gca_io_compat.ContainerRegistryDestination( - output_uri=image_destination + output_config.image_destination = ( + gca_io_compat.ContainerRegistryDestination(output_uri=image_destination) ) _LOGGER.log_action_start_against_resource("Exporting", "model", self) @@ -2192,3 +2851,655 @@ def export_model( _LOGGER.log_action_completed_against_resource("model", "exported", self) return json_format.MessageToDict(operation_future.metadata.output_info._pb) + + @classmethod + @base.optional_sync() + def upload_xgboost_model_file( + cls, + model_file_path: str, + xgboost_version: Optional[str] = None, + display_name: Optional[str] = None, + description: Optional[str] = None, + instance_schema_uri: Optional[str] = None, + parameters_schema_uri: Optional[str] = None, + prediction_schema_uri: Optional[str] = None, + explanation_metadata: Optional[explain.ExplanationMetadata] = None, + explanation_parameters: Optional[explain.ExplanationParameters] = None, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + labels: Optional[Dict[str, str]] = None, + encryption_spec_key_name: Optional[str] = None, + staging_bucket: Optional[str] = None, + sync=True, + upload_request_timeout: Optional[float] = None, + ) -> "Model": + """Uploads a model and returns a Model representing the uploaded Model + resource. + + Note: This function is *experimental* and can be changed in the future. + + Example usage:: + + my_model = Model.upload_xgboost_model_file( + model_file_path="iris.xgboost_model.bst" + ) + + Args: + model_file_path (str): Required. Local file path of the model. + xgboost_version (str): Optional. The version of the XGBoost serving container. + Supported versions: ["0.82", "0.90", "1.1", "1.2", "1.3", "1.4"]. + If the version is not specified, the latest version is used. + display_name (str): + Optional. The display name of the Model. The name can be up to 128 + characters long and can be consist of any UTF-8 characters. + description (str): + The description of the model. + instance_schema_uri (str): + Optional. Points to a YAML file stored on Google Cloud + Storage describing the format of a single instance, which + are used in + ``PredictRequest.instances``, + ``ExplainRequest.instances`` + and + ``BatchPredictionJob.input_config``. + The schema is defined as an OpenAPI 3.0.2 `Schema + Object `__. + AutoML Models always have this field populated by AI + Platform. Note: The URI given on output will be immutable + and probably different, including the URI scheme, than the + one given on input. The output URI will point to a location + where the user only has a read access. + parameters_schema_uri (str): + Optional. Points to a YAML file stored on Google Cloud + Storage describing the parameters of prediction and + explanation via + ``PredictRequest.parameters``, + ``ExplainRequest.parameters`` + and + ``BatchPredictionJob.model_parameters``. + The schema is defined as an OpenAPI 3.0.2 `Schema + Object `__. + AutoML Models always have this field populated by AI + Platform, if no parameters are supported it is set to an + empty string. Note: The URI given on output will be + immutable and probably different, including the URI scheme, + than the one given on input. The output URI will point to a + location where the user only has a read access. + prediction_schema_uri (str): + Optional. Points to a YAML file stored on Google Cloud + Storage describing the format of a single prediction + produced by this Model, which are returned via + ``PredictResponse.predictions``, + ``ExplainResponse.explanations``, + and + ``BatchPredictionJob.output_config``. + The schema is defined as an OpenAPI 3.0.2 `Schema + Object `__. + AutoML Models always have this field populated by AI + Platform. Note: The URI given on output will be immutable + and probably different, including the URI scheme, than the + one given on input. The output URI will point to a location + where the user only has a read access. + explanation_metadata (explain.ExplanationMetadata): + Optional. Metadata describing the Model's input and output for explanation. + Both `explanation_metadata` and `explanation_parameters` must be + passed together when used. For more details, see + `Ref docs ` + explanation_parameters (explain.ExplanationParameters): + Optional. Parameters to configure explaining for Model's predictions. + For more details, see `Ref docs ` + project: Optional[str]=None, + Project to upload this model to. Overrides project set in + aiplatform.init. + location: Optional[str]=None, + Location to upload this model to. Overrides location set in + aiplatform.init. + credentials: Optional[auth_credentials.Credentials]=None, + Custom credentials to use to upload this model. Overrides credentials + set in aiplatform.init. + labels (Dict[str, str]): + Optional. The labels with user-defined metadata to + organize your Models. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + and examples of labels. + encryption_spec_key_name (Optional[str]): + Optional. The Cloud KMS resource identifier of the customer + managed encryption key used to protect the model. Has the + form: + ``projects/my-project/locations/my-region/keyRings/my-kr/cryptoKeys/my-key``. + The key needs to be in the same region as where the compute + resource is created. + + If set, this Model and all sub-resources of this Model will be secured by this key. + + Overrides encryption_spec_key_name set in aiplatform.init. + staging_bucket (str): + Optional. Bucket to stage local model artifacts. Overrides + staging_bucket set in aiplatform.init. + upload_request_timeout (float): + Optional. The timeout for the upload request in seconds. + Returns: + model: Instantiated representation of the uploaded model resource. + Raises: + ValueError: If only `explanation_metadata` or `explanation_parameters` + is specified. + Also if model directory does not contain a supported model file. + """ + if not display_name: + display_name = cls._generate_display_name("XGBoost model") + + XGBOOST_SUPPORTED_MODEL_FILE_EXTENSIONS = [ + ".pkl", + ".joblib", + ".bst", + ] + + container_image_uri = aiplatform.helpers.get_prebuilt_prediction_container_uri( + region=location, + framework="xgboost", + framework_version=xgboost_version or "1.4", + accelerator="cpu", + ) + + model_file_path_obj = pathlib.Path(model_file_path) + if not model_file_path_obj.is_file(): + raise ValueError( + f"model_file_path path must point to a file: '{model_file_path}'" + ) + + model_file_extension = model_file_path_obj.suffix + if model_file_extension not in XGBOOST_SUPPORTED_MODEL_FILE_EXTENSIONS: + _LOGGER.warning( + f"Only the following XGBoost model file extensions are currently supported: '{XGBOOST_SUPPORTED_MODEL_FILE_EXTENSIONS}'" + ) + _LOGGER.warning( + "Treating the model file as a binary serialized XGBoost Booster." + ) + model_file_extension = ".bst" + + # Preparing model directory + # We cannot clean up the directory immediately after calling Model.upload since + # that call may be asynchronous and return before the model file has been read. + # To work around this, we make this method asynchronous (decorate with @base.optional_sync) + # but call Model.upload with sync=True. + with tempfile.TemporaryDirectory() as prepared_model_dir: + prepared_model_file_path = pathlib.Path(prepared_model_dir) / ( + "model" + model_file_extension + ) + shutil.copy(model_file_path_obj, prepared_model_file_path) + + return cls.upload( + serving_container_image_uri=container_image_uri, + artifact_uri=prepared_model_dir, + display_name=display_name, + description=description, + instance_schema_uri=instance_schema_uri, + parameters_schema_uri=parameters_schema_uri, + prediction_schema_uri=prediction_schema_uri, + explanation_metadata=explanation_metadata, + explanation_parameters=explanation_parameters, + project=project, + location=location, + credentials=credentials, + labels=labels, + encryption_spec_key_name=encryption_spec_key_name, + staging_bucket=staging_bucket, + sync=True, + upload_request_timeout=upload_request_timeout, + ) + + @classmethod + @base.optional_sync() + def upload_scikit_learn_model_file( + cls, + model_file_path: str, + sklearn_version: Optional[str] = None, + display_name: Optional[str] = None, + description: Optional[str] = None, + instance_schema_uri: Optional[str] = None, + parameters_schema_uri: Optional[str] = None, + prediction_schema_uri: Optional[str] = None, + explanation_metadata: Optional[explain.ExplanationMetadata] = None, + explanation_parameters: Optional[explain.ExplanationParameters] = None, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + labels: Optional[Dict[str, str]] = None, + encryption_spec_key_name: Optional[str] = None, + staging_bucket: Optional[str] = None, + sync=True, + upload_request_timeout: Optional[float] = None, + ) -> "Model": + """Uploads a model and returns a Model representing the uploaded Model + resource. + + Note: This function is *experimental* and can be changed in the future. + + Example usage:: + + my_model = Model.upload_scikit_learn_model_file( + model_file_path="iris.sklearn_model.joblib" + ) + + Args: + model_file_path (str): Required. Local file path of the model. + sklearn_version (str): + Optional. The version of the Scikit-learn serving container. + Supported versions: ["0.20", "0.22", "0.23", "0.24", "1.0"]. + If the version is not specified, the latest version is used. + display_name (str): + Optional. The display name of the Model. The name can be up to 128 + characters long and can be consist of any UTF-8 characters. + description (str): + The description of the model. + instance_schema_uri (str): + Optional. Points to a YAML file stored on Google Cloud + Storage describing the format of a single instance, which + are used in + ``PredictRequest.instances``, + ``ExplainRequest.instances`` + and + ``BatchPredictionJob.input_config``. + The schema is defined as an OpenAPI 3.0.2 `Schema + Object `__. + AutoML Models always have this field populated by AI + Platform. Note: The URI given on output will be immutable + and probably different, including the URI scheme, than the + one given on input. The output URI will point to a location + where the user only has a read access. + parameters_schema_uri (str): + Optional. Points to a YAML file stored on Google Cloud + Storage describing the parameters of prediction and + explanation via + ``PredictRequest.parameters``, + ``ExplainRequest.parameters`` + and + ``BatchPredictionJob.model_parameters``. + The schema is defined as an OpenAPI 3.0.2 `Schema + Object `__. + AutoML Models always have this field populated by AI + Platform, if no parameters are supported it is set to an + empty string. Note: The URI given on output will be + immutable and probably different, including the URI scheme, + than the one given on input. The output URI will point to a + location where the user only has a read access. + prediction_schema_uri (str): + Optional. Points to a YAML file stored on Google Cloud + Storage describing the format of a single prediction + produced by this Model, which are returned via + ``PredictResponse.predictions``, + ``ExplainResponse.explanations``, + and + ``BatchPredictionJob.output_config``. + The schema is defined as an OpenAPI 3.0.2 `Schema + Object `__. + AutoML Models always have this field populated by AI + Platform. Note: The URI given on output will be immutable + and probably different, including the URI scheme, than the + one given on input. The output URI will point to a location + where the user only has a read access. + explanation_metadata (explain.ExplanationMetadata): + Optional. Metadata describing the Model's input and output for explanation. + Both `explanation_metadata` and `explanation_parameters` must be + passed together when used. For more details, see + `Ref docs ` + explanation_parameters (explain.ExplanationParameters): + Optional. Parameters to configure explaining for Model's predictions. + For more details, see `Ref docs ` + project: Optional[str]=None, + Project to upload this model to. Overrides project set in + aiplatform.init. + location: Optional[str]=None, + Location to upload this model to. Overrides location set in + aiplatform.init. + credentials: Optional[auth_credentials.Credentials]=None, + Custom credentials to use to upload this model. Overrides credentials + set in aiplatform.init. + labels (Dict[str, str]): + Optional. The labels with user-defined metadata to + organize your Models. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + and examples of labels. + encryption_spec_key_name (Optional[str]): + Optional. The Cloud KMS resource identifier of the customer + managed encryption key used to protect the model. Has the + form: + ``projects/my-project/locations/my-region/keyRings/my-kr/cryptoKeys/my-key``. + The key needs to be in the same region as where the compute + resource is created. + + If set, this Model and all sub-resources of this Model will be secured by this key. + + Overrides encryption_spec_key_name set in aiplatform.init. + staging_bucket (str): + Optional. Bucket to stage local model artifacts. Overrides + staging_bucket set in aiplatform.init. + upload_request_timeout (float): + Optional. The timeout for the upload request in seconds. + Returns: + model: Instantiated representation of the uploaded model resource. + Raises: + ValueError: If only `explanation_metadata` or `explanation_parameters` + is specified. + Also if model directory does not contain a supported model file. + """ + if not display_name: + display_name = cls._generate_display_name("Scikit-Learn model") + + SKLEARN_SUPPORTED_MODEL_FILE_EXTENSIONS = [ + ".pkl", + ".joblib", + ] + + container_image_uri = aiplatform.helpers.get_prebuilt_prediction_container_uri( + region=location, + framework="sklearn", + framework_version=sklearn_version or "1.0", + accelerator="cpu", + ) + + model_file_path_obj = pathlib.Path(model_file_path) + if not model_file_path_obj.is_file(): + raise ValueError( + f"model_file_path path must point to a file: '{model_file_path}'" + ) + + model_file_extension = model_file_path_obj.suffix + if model_file_extension not in SKLEARN_SUPPORTED_MODEL_FILE_EXTENSIONS: + _LOGGER.warning( + f"Only the following Scikit-learn model file extensions are currently supported: '{SKLEARN_SUPPORTED_MODEL_FILE_EXTENSIONS}'" + ) + _LOGGER.warning( + "Treating the model file as a pickle serialized Scikit-learn model." + ) + model_file_extension = ".pkl" + + # Preparing model directory + # We cannot clean up the directory immediately after calling Model.upload since + # that call may be asynchronous and return before the model file has been read. + # To work around this, we make this method asynchronous (decorate with @base.optional_sync) + # but call Model.upload with sync=True. + with tempfile.TemporaryDirectory() as prepared_model_dir: + prepared_model_file_path = pathlib.Path(prepared_model_dir) / ( + "model" + model_file_extension + ) + shutil.copy(model_file_path_obj, prepared_model_file_path) + + return cls.upload( + serving_container_image_uri=container_image_uri, + artifact_uri=prepared_model_dir, + display_name=display_name, + description=description, + instance_schema_uri=instance_schema_uri, + parameters_schema_uri=parameters_schema_uri, + prediction_schema_uri=prediction_schema_uri, + explanation_metadata=explanation_metadata, + explanation_parameters=explanation_parameters, + project=project, + location=location, + credentials=credentials, + labels=labels, + encryption_spec_key_name=encryption_spec_key_name, + staging_bucket=staging_bucket, + sync=True, + upload_request_timeout=upload_request_timeout, + ) + + @classmethod + def upload_tensorflow_saved_model( + cls, + saved_model_dir: str, + tensorflow_version: Optional[str] = None, + use_gpu: bool = False, + display_name: Optional[str] = None, + description: Optional[str] = None, + instance_schema_uri: Optional[str] = None, + parameters_schema_uri: Optional[str] = None, + prediction_schema_uri: Optional[str] = None, + explanation_metadata: Optional[explain.ExplanationMetadata] = None, + explanation_parameters: Optional[explain.ExplanationParameters] = None, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + labels: Optional[Dict[str, str]] = None, + encryption_spec_key_name: Optional[str] = None, + staging_bucket: Optional[str] = None, + sync=True, + upload_request_timeout: Optional[str] = None, + ) -> "Model": + """Uploads a model and returns a Model representing the uploaded Model + resource. + + Note: This function is *experimental* and can be changed in the future. + + Example usage:: + + my_model = Model.upload_scikit_learn_model_file( + model_file_path="iris.tensorflow_model.SavedModel" + ) + + Args: + saved_model_dir (str): Required. + Local directory of the Tensorflow SavedModel. + tensorflow_version (str): + Optional. The version of the Tensorflow serving container. + Supported versions: ["0.15", "2.1", "2.2", "2.3", "2.4", "2.5", "2.6", "2.7"]. + If the version is not specified, the latest version is used. + use_gpu (bool): Whether to use GPU for model serving. + display_name (str): + Optional. The display name of the Model. The name can be up to 128 + characters long and can be consist of any UTF-8 characters. + description (str): + The description of the model. + instance_schema_uri (str): + Optional. Points to a YAML file stored on Google Cloud + Storage describing the format of a single instance, which + are used in + ``PredictRequest.instances``, + ``ExplainRequest.instances`` + and + ``BatchPredictionJob.input_config``. + The schema is defined as an OpenAPI 3.0.2 `Schema + Object `__. + AutoML Models always have this field populated by AI + Platform. Note: The URI given on output will be immutable + and probably different, including the URI scheme, than the + one given on input. The output URI will point to a location + where the user only has a read access. + parameters_schema_uri (str): + Optional. Points to a YAML file stored on Google Cloud + Storage describing the parameters of prediction and + explanation via + ``PredictRequest.parameters``, + ``ExplainRequest.parameters`` + and + ``BatchPredictionJob.model_parameters``. + The schema is defined as an OpenAPI 3.0.2 `Schema + Object `__. + AutoML Models always have this field populated by AI + Platform, if no parameters are supported it is set to an + empty string. Note: The URI given on output will be + immutable and probably different, including the URI scheme, + than the one given on input. The output URI will point to a + location where the user only has a read access. + prediction_schema_uri (str): + Optional. Points to a YAML file stored on Google Cloud + Storage describing the format of a single prediction + produced by this Model, which are returned via + ``PredictResponse.predictions``, + ``ExplainResponse.explanations``, + and + ``BatchPredictionJob.output_config``. + The schema is defined as an OpenAPI 3.0.2 `Schema + Object `__. + AutoML Models always have this field populated by AI + Platform. Note: The URI given on output will be immutable + and probably different, including the URI scheme, than the + one given on input. The output URI will point to a location + where the user only has a read access. + explanation_metadata (explain.ExplanationMetadata): + Optional. Metadata describing the Model's input and output for explanation. + Both `explanation_metadata` and `explanation_parameters` must be + passed together when used. For more details, see + `Ref docs ` + explanation_parameters (explain.ExplanationParameters): + Optional. Parameters to configure explaining for Model's predictions. + For more details, see `Ref docs ` + project: Optional[str]=None, + Project to upload this model to. Overrides project set in + aiplatform.init. + location: Optional[str]=None, + Location to upload this model to. Overrides location set in + aiplatform.init. + credentials: Optional[auth_credentials.Credentials]=None, + Custom credentials to use to upload this model. Overrides credentials + set in aiplatform.init. + labels (Dict[str, str]): + Optional. The labels with user-defined metadata to + organize your Models. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + and examples of labels. + encryption_spec_key_name (Optional[str]): + Optional. The Cloud KMS resource identifier of the customer + managed encryption key used to protect the model. Has the + form: + ``projects/my-project/locations/my-region/keyRings/my-kr/cryptoKeys/my-key``. + The key needs to be in the same region as where the compute + resource is created. + + If set, this Model and all sub-resources of this Model will be secured by this key. + + Overrides encryption_spec_key_name set in aiplatform.init. + staging_bucket (str): + Optional. Bucket to stage local model artifacts. Overrides + staging_bucket set in aiplatform.init. + upload_request_timeout (float): + Optional. The timeout for the upload request in seconds. + Returns: + model: Instantiated representation of the uploaded model resource. + Raises: + ValueError: If only `explanation_metadata` or `explanation_parameters` + is specified. + Also if model directory does not contain a supported model file. + """ + if not display_name: + display_name = cls._generate_display_name("Tensorflow model") + + container_image_uri = aiplatform.helpers.get_prebuilt_prediction_container_uri( + region=location, + framework="tensorflow", + framework_version=tensorflow_version or "2.7", + accelerator="gpu" if use_gpu else "cpu", + ) + + return cls.upload( + serving_container_image_uri=container_image_uri, + artifact_uri=saved_model_dir, + display_name=display_name, + description=description, + instance_schema_uri=instance_schema_uri, + parameters_schema_uri=parameters_schema_uri, + prediction_schema_uri=prediction_schema_uri, + explanation_metadata=explanation_metadata, + explanation_parameters=explanation_parameters, + project=project, + location=location, + credentials=credentials, + labels=labels, + encryption_spec_key_name=encryption_spec_key_name, + staging_bucket=staging_bucket, + sync=sync, + upload_request_timeout=upload_request_timeout, + ) + + def list_model_evaluations( + self, + ) -> List["model_evaluation.ModelEvaluation"]: + """List all Model Evaluation resources associated with this model. + + Example Usage: + + my_model = Model( + model_name="projects/123/locations/us-central1/models/456" + ) + + my_evaluations = my_model.list_model_evaluations() + + Returns: + List[model_evaluation.ModelEvaluation]: List of ModelEvaluation resources + for the model. + """ + + self.wait() + + return model_evaluation.ModelEvaluation._list( + parent=self.resource_name, + credentials=self.credentials, + ) + + def get_model_evaluation( + self, + evaluation_id: Optional[str] = None, + ) -> Optional[model_evaluation.ModelEvaluation]: + """Returns a ModelEvaluation resource and instantiates its representation. + If no evaluation_id is passed, it will return the first evaluation associated + with this model. + + Example usage: + + my_model = Model( + model_name="projects/123/locations/us-central1/models/456" + ) + + my_evaluation = my_model.get_model_evaluation( + evaluation_id="789" + ) + + # If no arguments are passed, this returns the first evaluation for the model + my_evaluation = my_model.get_model_evaluation() + + Args: + evaluation_id (str): + Optional. The ID of the model evaluation to retrieve. + Returns: + model_evaluation.ModelEvaluation: Instantiated representation of the + ModelEvaluation resource. + """ + + evaluations = self.list_model_evaluations() + + if not evaluation_id: + if len(evaluations) > 1: + _LOGGER.warning( + f"Your model has more than one model evaluation, this is returning only one evaluation resource: {evaluations[0].resource_name}" + ) + return evaluations[0] if evaluations else evaluations + else: + resource_uri_parts = self._parse_resource_name(self.resource_name) + evaluation_resource_name = ( + model_evaluation.ModelEvaluation._format_resource_name( + **resource_uri_parts, + evaluation=evaluation_id, + ) + ) + + return model_evaluation.ModelEvaluation( + evaluation_name=evaluation_resource_name, + credentials=self.credentials, + ) diff --git a/google/cloud/aiplatform/pipeline_jobs.py b/google/cloud/aiplatform/pipeline_jobs.py new file mode 100644 index 0000000000..f6fcc3a0af --- /dev/null +++ b/google/cloud/aiplatform/pipeline_jobs.py @@ -0,0 +1,778 @@ +# -*- coding: utf-8 -*- + +# 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 +# +# 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. +# + +import datetime +import logging +import time +import re +from typing import Any, Dict, List, Optional, Union + +from google.auth import credentials as auth_credentials +from google.cloud.aiplatform import base +from google.cloud.aiplatform import initializer +from google.cloud.aiplatform import utils +from google.cloud.aiplatform.metadata import artifact +from google.cloud.aiplatform.metadata import context +from google.cloud.aiplatform.metadata import execution +from google.cloud.aiplatform.metadata import constants as metadata_constants +from google.cloud.aiplatform.metadata import experiment_resources +from google.cloud.aiplatform.metadata import utils as metadata_utils +from google.cloud.aiplatform.utils import yaml_utils +from google.cloud.aiplatform.utils import pipeline_utils +from google.protobuf import json_format + +from google.cloud.aiplatform.compat.types import ( + pipeline_job as gca_pipeline_job, + pipeline_state as gca_pipeline_state, +) + +_LOGGER = base.Logger(__name__) + +_PIPELINE_COMPLETE_STATES = set( + [ + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, + gca_pipeline_state.PipelineState.PIPELINE_STATE_FAILED, + gca_pipeline_state.PipelineState.PIPELINE_STATE_CANCELLED, + gca_pipeline_state.PipelineState.PIPELINE_STATE_PAUSED, + ] +) + +_PIPELINE_ERROR_STATES = set([gca_pipeline_state.PipelineState.PIPELINE_STATE_FAILED]) + +# Pattern for valid names used as a Vertex resource name. +_VALID_NAME_PATTERN = re.compile("^[a-z][-a-z0-9]{0,127}$") + +# Pattern for an Artifact Registry URL. +_VALID_AR_URL = re.compile(r"^https:\/\/([\w-]+)-kfp\.pkg\.dev\/.*") + + +def _get_current_time() -> datetime.datetime: + """Gets the current timestamp.""" + return datetime.datetime.now() + + +def _set_enable_caching_value( + pipeline_spec: Dict[str, Any], enable_caching: bool +) -> None: + """Sets pipeline tasks caching options. + + Args: + pipeline_spec (Dict[str, Any]): + Required. The dictionary of pipeline spec. + enable_caching (bool): + Required. Whether to enable caching. + """ + for component in [pipeline_spec["root"]] + list( + pipeline_spec["components"].values() + ): + if "dag" in component: + for task in component["dag"]["tasks"].values(): + task["cachingOptions"] = {"enableCache": enable_caching} + + +class PipelineJob( + base.VertexAiStatefulResource, + experiment_resources._ExperimentLoggable, + experiment_loggable_schemas=( + experiment_resources._ExperimentLoggableSchema( + title=metadata_constants.SYSTEM_PIPELINE_RUN + ), + ), +): + + client_class = utils.PipelineJobClientWithOverride + _resource_noun = "pipelineJobs" + _delete_method = "delete_pipeline_job" + _getter_method = "get_pipeline_job" + _list_method = "list_pipeline_jobs" + _parse_resource_name_method = "parse_pipeline_job_path" + _format_resource_name_method = "pipeline_job_path" + + # Required by the done() method + _valid_done_states = _PIPELINE_COMPLETE_STATES + + def __init__( + self, + # TODO(b/223262536): Make the display_name parameter optional in the next major release + display_name: str, + template_path: str, + job_id: Optional[str] = None, + pipeline_root: Optional[str] = None, + parameter_values: Optional[Dict[str, Any]] = None, + enable_caching: Optional[bool] = None, + encryption_spec_key_name: Optional[str] = None, + labels: Optional[Dict[str, str]] = None, + credentials: Optional[auth_credentials.Credentials] = None, + project: Optional[str] = None, + location: Optional[str] = None, + failure_policy: Optional[str] = None, + ): + """Retrieves a PipelineJob resource and instantiates its + representation. + + Args: + display_name (str): + Required. The user-defined name of this Pipeline. + template_path (str): + Required. The path of PipelineJob or PipelineSpec JSON or YAML file. It + can be a local path, a Google Cloud Storage URI (e.g. "gs://project.name"), + or an Artifact Registry URI (e.g. + "https://us-central1-kfp.pkg.dev/proj/repo/pack/latest"). + job_id (str): + Optional. The unique ID of the job run. + If not specified, pipeline name + timestamp will be used. + pipeline_root (str): + Optional. The root of the pipeline outputs. Default to be staging bucket. + parameter_values (Dict[str, Any]): + Optional. The mapping from runtime parameter names to its values that + control the pipeline run. + enable_caching (bool): + Optional. Whether to turn on caching for the run. + + If this is not set, defaults to the compile time settings, which + are True for all tasks by default, while users may specify + different caching options for individual tasks. + + If this is set, the setting applies to all tasks in the pipeline. + + Overrides the compile time settings. + encryption_spec_key_name (str): + Optional. The Cloud KMS resource identifier of the customer + managed encryption key used to protect the job. Has the + form: + ``projects/my-project/locations/my-region/keyRings/my-kr/cryptoKeys/my-key``. + The key needs to be in the same region as where the compute + resource is created. + + If this is set, then all + resources created by the PipelineJob will + be encrypted with the provided encryption key. + + Overrides encryption_spec_key_name set in aiplatform.init. + labels (Dict[str, str]): + Optional. The user defined metadata to organize PipelineJob. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to create this PipelineJob. + Overrides credentials set in aiplatform.init. + project (str): + Optional. The project that you want to run this PipelineJob in. If not set, + the project set in aiplatform.init will be used. + location (str): + Optional. Location to create PipelineJob. If not set, + location set in aiplatform.init will be used. + failure_policy (str): + Optional. The failure policy - "slow" or "fast". + Currently, the default of a pipeline is that the pipeline will continue to + run until no more tasks can be executed, also known as + PIPELINE_FAILURE_POLICY_FAIL_SLOW (corresponds to "slow"). + However, if a pipeline is set to + PIPELINE_FAILURE_POLICY_FAIL_FAST (corresponds to "fast"), + it will stop scheduling any new tasks when a task has failed. Any + scheduled tasks will continue to completion. + + Raises: + ValueError: If job_id or labels have incorrect format. + """ + if not display_name: + display_name = self.__class__._generate_display_name() + utils.validate_display_name(display_name) + + if labels: + utils.validate_labels(labels) + + super().__init__(project=project, location=location, credentials=credentials) + + self._parent = initializer.global_config.common_location_path( + project=project, location=location + ) + + # this loads both .yaml and .json files because YAML is a superset of JSON + pipeline_json = yaml_utils.load_yaml( + template_path, self.project, self.credentials + ) + + # Pipeline_json can be either PipelineJob or PipelineSpec. + if pipeline_json.get("pipelineSpec") is not None: + pipeline_job = pipeline_json + pipeline_root = ( + pipeline_root + or pipeline_job["pipelineSpec"].get("defaultPipelineRoot") + or pipeline_job["runtimeConfig"].get("gcsOutputDirectory") + or initializer.global_config.staging_bucket + ) + else: + pipeline_job = { + "pipelineSpec": pipeline_json, + "runtimeConfig": {}, + } + pipeline_root = ( + pipeline_root + or pipeline_job["pipelineSpec"].get("defaultPipelineRoot") + or initializer.global_config.staging_bucket + ) + builder = pipeline_utils.PipelineRuntimeConfigBuilder.from_job_spec_json( + pipeline_job + ) + builder.update_pipeline_root(pipeline_root) + builder.update_runtime_parameters(parameter_values) + builder.update_failure_policy(failure_policy) + runtime_config_dict = builder.build() + + runtime_config = gca_pipeline_job.PipelineJob.RuntimeConfig()._pb + json_format.ParseDict(runtime_config_dict, runtime_config) + + pipeline_name = pipeline_job["pipelineSpec"]["pipelineInfo"]["name"] + self.job_id = job_id or "{pipeline_name}-{timestamp}".format( + pipeline_name=re.sub("[^-0-9a-z]+", "-", pipeline_name.lower()) + .lstrip("-") + .rstrip("-"), + timestamp=_get_current_time().strftime("%Y%m%d%H%M%S"), + ) + if not _VALID_NAME_PATTERN.match(self.job_id): + raise ValueError( + f"Generated job ID: {self.job_id} is illegal as a Vertex pipelines job ID. " + "Expecting an ID following the regex pattern " + f'"{_VALID_NAME_PATTERN.pattern[1:-1]}"' + ) + + if enable_caching is not None: + _set_enable_caching_value(pipeline_job["pipelineSpec"], enable_caching) + + pipeline_job_args = { + "display_name": display_name, + "pipeline_spec": pipeline_job["pipelineSpec"], + "labels": labels, + "runtime_config": runtime_config, + "encryption_spec": initializer.global_config.get_encryption_spec( + encryption_spec_key_name=encryption_spec_key_name + ), + } + + if _VALID_AR_URL.match(template_path): + pipeline_job_args["template_uri"] = template_path + + self._gca_resource = gca_pipeline_job.PipelineJob(**pipeline_job_args) + + @base.optional_sync() + def run( + self, + service_account: Optional[str] = None, + network: Optional[str] = None, + sync: Optional[bool] = True, + create_request_timeout: Optional[float] = None, + ) -> None: + """Run this configured PipelineJob and monitor the job until completion. + + Args: + service_account (str): + Optional. Specifies the service account for workload run-as account. + Users submitting jobs must have act-as permission on this run-as account. + network (str): + Optional. The full name of the Compute Engine network to which the job + should be peered. For example, projects/12345/global/networks/myVPC. + + Private services access must already be configured for the network. + If left unspecified, the job is not peered with any network. + sync (bool): + Optional. Whether to execute this method synchronously. If False, this method will unblock and it will be executed in a concurrent Future. + create_request_timeout (float): + Optional. The timeout for the create request in seconds. + """ + self.submit( + service_account=service_account, + network=network, + create_request_timeout=create_request_timeout, + ) + + self._block_until_complete() + + def submit( + self, + service_account: Optional[str] = None, + network: Optional[str] = None, + create_request_timeout: Optional[float] = None, + *, + experiment: Optional[Union[str, experiment_resources.Experiment]] = None, + ) -> None: + """Run this configured PipelineJob. + + Args: + service_account (str): + Optional. Specifies the service account for workload run-as account. + Users submitting jobs must have act-as permission on this run-as account. + network (str): + Optional. The full name of the Compute Engine network to which the job + should be peered. For example, projects/12345/global/networks/myVPC. + + Private services access must already be configured for the network. + If left unspecified, the job is not peered with any network. + create_request_timeout (float): + Optional. The timeout for the create request in seconds. + experiment (Union[str, experiments_resource.Experiment]): + Optional. The Vertex AI experiment name or instance to associate to this PipelineJob. + + Metrics produced by the PipelineJob as system.Metric Artifacts + will be associated as metrics to the current Experiment Run. + + Pipeline parameters will be associated as parameters to the + current Experiment Run. + """ + if service_account: + self._gca_resource.service_account = service_account + + if network: + self._gca_resource.network = network + + # Prevents logs from being supressed on TFX pipelines + if self._gca_resource.pipeline_spec.get("sdkVersion", "").startswith("tfx"): + _LOGGER.setLevel(logging.INFO) + + if experiment: + self._validate_experiment(experiment) + + _LOGGER.log_create_with_lro(self.__class__) + + self._gca_resource = self.api_client.create_pipeline_job( + parent=self._parent, + pipeline_job=self._gca_resource, + pipeline_job_id=self.job_id, + timeout=create_request_timeout, + ) + + _LOGGER.log_create_complete_with_getter( + self.__class__, self._gca_resource, "pipeline_job" + ) + + _LOGGER.info("View Pipeline Job:\n%s" % self._dashboard_uri()) + + if experiment: + self._associate_to_experiment(experiment) + + def wait(self): + """Wait for this PipelineJob to complete.""" + if self._latest_future is None: + self._block_until_complete() + else: + super().wait() + + @property + def pipeline_spec(self): + return self._gca_resource.pipeline_spec + + @property + def state(self) -> Optional[gca_pipeline_state.PipelineState]: + """Current pipeline state.""" + self._sync_gca_resource() + return self._gca_resource.state + + @property + def task_details(self) -> List[gca_pipeline_job.PipelineTaskDetail]: + self._sync_gca_resource() + return list(self._gca_resource.job_detail.task_details) + + @property + def has_failed(self) -> bool: + """Returns True if pipeline has failed. + + False otherwise. + """ + return self.state == gca_pipeline_state.PipelineState.PIPELINE_STATE_FAILED + + def _dashboard_uri(self) -> str: + """Helper method to compose the dashboard uri where pipeline can be + viewed.""" + fields = self._parse_resource_name(self.resource_name) + url = f"https://console.cloud.google.com/vertex-ai/locations/{fields['location']}/pipelines/runs/{fields['pipeline_job']}?project={fields['project']}" + return url + + def _block_until_complete(self): + """Helper method to block and check on job until complete.""" + # Used these numbers so failures surface fast + wait = 5 # start at five seconds + log_wait = 5 + max_wait = 60 * 5 # 5 minute wait + multiplier = 2 # scale wait by 2 every iteration + + previous_time = time.time() + while self.state not in _PIPELINE_COMPLETE_STATES: + current_time = time.time() + if current_time - previous_time >= log_wait: + _LOGGER.info( + "%s %s current state:\n%s" + % ( + self.__class__.__name__, + self._gca_resource.name, + self._gca_resource.state, + ) + ) + log_wait = min(log_wait * multiplier, max_wait) + previous_time = current_time + time.sleep(wait) + + # Error is only populated when the job state is + # JOB_STATE_FAILED or JOB_STATE_CANCELLED. + if self._gca_resource.state in _PIPELINE_ERROR_STATES: + raise RuntimeError("Job failed with:\n%s" % self._gca_resource.error) + else: + _LOGGER.log_action_completed_against_resource("run", "completed", self) + + @classmethod + def get( + cls, + resource_name: str, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ) -> "PipelineJob": + """Get a Vertex AI Pipeline Job for the given resource_name. + + Args: + resource_name (str): + Required. A fully-qualified resource name or ID. + project (str): + Optional. Project to retrieve dataset from. If not set, project + set in aiplatform.init will be used. + location (str): + Optional. Location to retrieve dataset from. If not set, + location set in aiplatform.init will be used. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to upload this model. + Overrides credentials set in aiplatform.init. + + Returns: + A Vertex AI PipelineJob. + """ + self = cls._empty_constructor( + project=project, + location=location, + credentials=credentials, + resource_name=resource_name, + ) + + self._gca_resource = self._get_gca_resource(resource_name=resource_name) + + return self + + def cancel(self) -> None: + """Starts asynchronous cancellation on the PipelineJob. The server + makes a best effort to cancel the job, but success is not guaranteed. + On successful cancellation, the PipelineJob is not deleted; instead it + becomes a job with state set to `CANCELLED`. + """ + self.api_client.cancel_pipeline_job(name=self.resource_name) + + @classmethod + def list( + cls, + filter: Optional[str] = None, + order_by: Optional[str] = None, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ) -> List["PipelineJob"]: + """List all instances of this PipelineJob resource. + + Example Usage: + + aiplatform.PipelineJob.list( + filter='display_name="experiment_a27"', + order_by='create_time desc' + ) + + Args: + filter (str): + Optional. An expression for filtering the results of the request. + For field names both snake_case and camelCase are supported. + order_by (str): + Optional. A comma-separated list of fields to order by, sorted in + ascending order. Use "desc" after a field name for descending. + Supported fields: `display_name`, `create_time`, `update_time` + project (str): + Optional. Project to retrieve list from. If not set, project + set in aiplatform.init will be used. + location (str): + Optional. Location to retrieve list from. If not set, location + set in aiplatform.init will be used. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to retrieve list. Overrides + credentials set in aiplatform.init. + + Returns: + List[PipelineJob] - A list of PipelineJob resource objects + """ + + return cls._list_with_local_order( + filter=filter, + order_by=order_by, + project=project, + location=location, + credentials=credentials, + ) + + def wait_for_resource_creation(self) -> None: + """Waits until resource has been created.""" + self._wait_for_resource_creation() + + def done(self) -> bool: + """Helper method that return True is PipelineJob is done. False otherwise.""" + if not self._gca_resource: + return False + + return self.state in _PIPELINE_COMPLETE_STATES + + def _has_failed(self) -> bool: + """Return True if PipelineJob has Failed.""" + if not self._gca_resource: + return False + + return self.state in _PIPELINE_ERROR_STATES + + def _get_context(self) -> context._Context: + """Returns the PipelineRun Context for this PipelineJob in the MetadataStore. + + Returns: + System.PipelineRUn Context instance that represents this PipelineJob. + + Raises: + RuntimeError if Pipeline has failed or system.PipelineRun context is not found. + """ + self.wait_for_resource_creation() + pipeline_run_context = self._gca_resource.job_detail.pipeline_run_context + + # PipelineJob context is created asynchronously so we need to poll until it exists. + while not self.done(): + pipeline_run_context = self._gca_resource.job_detail.pipeline_run_context + if pipeline_run_context: + break + time.sleep(1) + + if not pipeline_run_context: + if self._has_failed: + raise RuntimeError( + f"Cannot associate PipelineJob to Experiment: {self.gca_resource.error}" + ) + else: + raise RuntimeError( + "Cannot associate PipelineJob to Experiment because PipelineJob context could not be found." + ) + + return context._Context( + resource=pipeline_run_context, + project=self.project, + location=self.location, + credentials=self.credentials, + ) + + @classmethod + def _query_experiment_row( + cls, node: context._Context + ) -> experiment_resources._ExperimentRow: + """Queries the PipelineJob metadata as an experiment run parameter and metric row. + + Parameters are retrieved from the system.Run Execution.metadata of the PipelineJob. + + Metrics are retrieved from the system.Metric Artifacts.metadata produced by this PipelineJob. + + Args: + node (context._Context): + Required. System.PipelineRun context that represents a PipelineJob Run. + Returns: + Experiment run row representing this PipelineJob. + """ + + system_run_executions = execution.Execution.list( + project=node.project, + location=node.location, + credentials=node.credentials, + filter=metadata_utils._make_filter_string( + in_context=[node.resource_name], + schema_title=metadata_constants.SYSTEM_RUN, + ), + ) + + metric_artifacts = artifact.Artifact.list( + project=node.project, + location=node.location, + credentials=node.credentials, + filter=metadata_utils._make_filter_string( + in_context=[node.resource_name], + schema_title=metadata_constants.SYSTEM_METRICS, + ), + ) + + row = experiment_resources._ExperimentRow( + experiment_run_type=node.schema_title, name=node.display_name + ) + + if system_run_executions: + row.params = { + key[len(metadata_constants.PIPELINE_PARAM_PREFIX) :]: value + for key, value in system_run_executions[0].metadata.items() + } + row.state = system_run_executions[0].state.name + + for metric_artifact in metric_artifacts: + if row.metrics: + row.metrics.update(metric_artifact.metadata) + else: + row.metrics = metric_artifact.metadata + + return row + + def clone( + self, + display_name: Optional[str] = None, + job_id: Optional[str] = None, + pipeline_root: Optional[str] = None, + parameter_values: Optional[Dict[str, Any]] = None, + enable_caching: Optional[bool] = None, + encryption_spec_key_name: Optional[str] = None, + labels: Optional[Dict[str, str]] = None, + credentials: Optional[auth_credentials.Credentials] = None, + project: Optional[str] = None, + location: Optional[str] = None, + ) -> "PipelineJob": + """Returns a new PipelineJob object with the same settings as the original one. + + Args: + display_name (str): + Optional. The user-defined name of this cloned Pipeline. + If not specified, original pipeline display name will be used. + job_id (str): + Optional. The unique ID of the job run. + If not specified, "cloned" + pipeline name + timestamp will be used. + pipeline_root (str): + Optional. The root of the pipeline outputs. Default to be the same + staging bucket as original pipeline. + parameter_values (Dict[str, Any]): + Optional. The mapping from runtime parameter names to its values that + control the pipeline run. Defaults to be the same values as original + PipelineJob. + enable_caching (bool): + Optional. Whether to turn on caching for the run. + If this is not set, defaults to be the same as original pipeline. + If this is set, the setting applies to all tasks in the pipeline. + encryption_spec_key_name (str): + Optional. The Cloud KMS resource identifier of the customer + managed encryption key used to protect the job. Has the + form: + ``projects/my-project/locations/my-region/keyRings/my-kr/cryptoKeys/my-key``. + The key needs to be in the same region as where the compute resource is created. + If this is set, then all + resources created by the PipelineJob will + be encrypted with the provided encryption key. + If not specified, encryption_spec of original PipelineJob will be used. + labels (Dict[str, str]): + Optional. The user defined metadata to organize PipelineJob. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to create this PipelineJob. + Overrides credentials set in aiplatform.init. + project (str): + Optional. The project that you want to run this PipelineJob in. + If not set, the project set in original PipelineJob will be used. + location (str): + Optional. Location to create PipelineJob. + If not set, location set in original PipelineJob will be used. + + Returns: + A Vertex AI PipelineJob. + + Raises: + ValueError: If job_id or labels have incorrect format. + """ + ## Initialize an empty PipelineJob + if not project: + project = self.project + if not location: + location = self.location + if not credentials: + credentials = self.credentials + + cloned = self.__class__._empty_constructor( + project=project, + location=location, + credentials=credentials, + ) + cloned._parent = initializer.global_config.common_location_path( + project=project, location=location + ) + + ## Get gca_resource from original PipelineJob + pipeline_job = json_format.MessageToDict(self._gca_resource._pb) + + ## Set pipeline_spec + pipeline_spec = pipeline_job["pipelineSpec"] + if "deploymentConfig" in pipeline_spec: + del pipeline_spec["deploymentConfig"] + + ## Set caching + if enable_caching is not None: + _set_enable_caching_value(pipeline_spec, enable_caching) + + ## Set job_id + pipeline_name = pipeline_spec["pipelineInfo"]["name"] + cloned.job_id = job_id or "cloned-{pipeline_name}-{timestamp}".format( + pipeline_name=re.sub("[^-0-9a-z]+", "-", pipeline_name.lower()) + .lstrip("-") + .rstrip("-"), + timestamp=_get_current_time().strftime("%Y%m%d%H%M%S"), + ) + if not _VALID_NAME_PATTERN.match(cloned.job_id): + raise ValueError( + f"Generated job ID: {cloned.job_id} is illegal as a Vertex pipelines job ID. " + "Expecting an ID following the regex pattern " + f'"{_VALID_NAME_PATTERN.pattern[1:-1]}"' + ) + + ## Set display_name, labels and encryption_spec + if display_name: + utils.validate_display_name(display_name) + elif not display_name and "displayName" in pipeline_job: + display_name = pipeline_job["displayName"] + + if labels: + utils.validate_labels(labels) + elif not labels and "labels" in pipeline_job: + labels = pipeline_job["labels"] + + if encryption_spec_key_name or "encryptionSpec" not in pipeline_job: + encryption_spec = initializer.global_config.get_encryption_spec( + encryption_spec_key_name=encryption_spec_key_name + ) + else: + encryption_spec = pipeline_job["encryptionSpec"] + + ## Set runtime_config + builder = pipeline_utils.PipelineRuntimeConfigBuilder.from_job_spec_json( + pipeline_job + ) + builder.update_pipeline_root(pipeline_root) + builder.update_runtime_parameters(parameter_values) + runtime_config_dict = builder.build() + runtime_config = gca_pipeline_job.PipelineJob.RuntimeConfig()._pb + json_format.ParseDict(runtime_config_dict, runtime_config) + + ## Create gca_resource for cloned PipelineJob + cloned._gca_resource = gca_pipeline_job.PipelineJob( + display_name=display_name, + pipeline_spec=pipeline_spec, + labels=labels, + runtime_config=runtime_config, + encryption_spec=encryption_spec, + ) + + return cloned diff --git a/google/cloud/aiplatform/schema.py b/google/cloud/aiplatform/schema.py index a1da75d9e6..96a7a50bbd 100644 --- a/google/cloud/aiplatform/schema.py +++ b/google/cloud/aiplatform/schema.py @@ -23,6 +23,7 @@ class definition: custom_task = "gs://google-cloud-aiplatform/schema/trainingjob/definition/custom_task_1.0.0.yaml" automl_tabular = "gs://google-cloud-aiplatform/schema/trainingjob/definition/automl_tabular_1.0.0.yaml" automl_forecasting = "gs://google-cloud-aiplatform/schema/trainingjob/definition/automl_time_series_forecasting_1.0.0.yaml" + seq2seq_plus_forecasting = "gs://google-cloud-aiplatform/schema/trainingjob/definition/seq2seq_plus_time_series_forecasting_1.0.0.yaml" automl_image_classification = "gs://google-cloud-aiplatform/schema/trainingjob/definition/automl_image_classification_1.0.0.yaml" automl_image_object_detection = "gs://google-cloud-aiplatform/schema/trainingjob/definition/automl_image_object_detection_1.0.0.yaml" automl_text_classification = "gs://google-cloud-aiplatform/schema/trainingjob/definition/automl_text_classification_1.0.0.yaml" diff --git a/google/cloud/aiplatform/tensorboard/__init__.py b/google/cloud/aiplatform/tensorboard/__init__.py index a6fbe4122f..58eb7c3640 100644 --- a/google/cloud/aiplatform/tensorboard/__init__.py +++ b/google/cloud/aiplatform/tensorboard/__init__.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2021 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,3 +14,18 @@ # See the License for the specific language governing permissions and # limitations under the License. # + +from google.cloud.aiplatform.tensorboard.tensorboard_resource import ( + Tensorboard, + TensorboardExperiment, + TensorboardRun, + TensorboardTimeSeries, +) + + +__all__ = ( + "Tensorboard", + "TensorboardExperiment", + "TensorboardRun", + "TensorboardTimeSeries", +) diff --git a/google/cloud/aiplatform/tensorboard/plugins/tf_profiler/profile_uploader.py b/google/cloud/aiplatform/tensorboard/plugins/tf_profiler/profile_uploader.py new file mode 100644 index 0000000000..5fd3f58e4d --- /dev/null +++ b/google/cloud/aiplatform/tensorboard/plugins/tf_profiler/profile_uploader.py @@ -0,0 +1,596 @@ +# -*- coding: utf-8 -*- + +# 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. +# +"""Upload profile sessions to Vertex AI Tensorboard.""" +from collections import defaultdict +import datetime +import functools +import os +import re +from typing import ( + DefaultDict, + Dict, + Generator, + List, + Optional, + Set, + Tuple, +) + +import grpc +from tensorboard.uploader import upload_tracker +from tensorboard.uploader import util +from tensorboard.uploader.proto import server_info_pb2 +from tensorboard.util import tb_logging +import tensorflow as tf + +from google.cloud import storage +from google.cloud.aiplatform.compat.services import tensorboard_service_client +from google.cloud.aiplatform.compat.types import tensorboard_data +from google.cloud.aiplatform.compat.types import tensorboard_service +from google.cloud.aiplatform.compat.types import tensorboard_time_series +from google.cloud.aiplatform.tensorboard import uploader_utils +from google.protobuf import timestamp_pb2 as timestamp + +TensorboardServiceClient = tensorboard_service_client.TensorboardServiceClient + +logger = tb_logging.get_logger() + + +class ProfileRequestSender(uploader_utils.RequestSender): + """Helper class for building requests for the profiler plugin. + + While the profile plugin does create event files when a profile run is performed + for a new training run, these event files do not contain any values + like other events do. Instead, the plugin will create subdirectories and profiling + files within these subdirectories. + + To verify the plugin, subdirectories need to be searched to confirm valid + profile directories and files. + + This class is not threadsafe. Use external synchronization if + calling its methods concurrently. + """ + + PLUGIN_NAME = "profile" + PROFILE_PATH = "plugins/profile" + + def __init__( + self, + experiment_resource_name: str, + api: TensorboardServiceClient, + upload_limits: server_info_pb2.UploadLimits, + blob_rpc_rate_limiter: util.RateLimiter, + blob_storage_bucket: storage.Bucket, + blob_storage_folder: str, + tracker: upload_tracker.UploadTracker, + logdir: str, + source_bucket: Optional[storage.Bucket], + ): + """Constructs ProfileRequestSender for the given experiment resource. + + Args: + experiment_resource_name (str): + Required. Name of the experiment resource of the form: + projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment} + api (TensorboardServiceClient): + Required. Tensorboard service stub used to interact with experiment resource. + upload_limits (server_info_pb2.UploadLimits): + Required. Upload limits for for api calls. + blob_rpc_rate_limiter (util.RateLimiter): + Required. A `RateLimiter` to use to limit write RPC frequency. + Note this limit applies at the level of single RPCs in the Scalar and + Tensor case, but at the level of an entire blob upload in the Blob + case-- which may require a few preparatory RPCs and a stream of chunks. + Note the chunk stream is internally rate-limited by backpressure from + the server, so it is not a concern that we do not explicitly rate-limit + within the stream here. + blob_storage_bucket (storage.Bucket): + Required. A `storage.Bucket` to send all blob files to. + blob_storage_folder (str): + Required. Name of the folder to save blob files to within the blob_storage_bucket. + tracker (upload_tracker.UploadTracker): + Required. Upload tracker to track information about uploads. + logdir (str). + Required. The log directory for the request sender to search. + source_bucket (Optional[storage.Bucket]): + Optional. The user's specified `storage.Bucket` to save events to. If a user is uploading from + a local directory, this can be None. + """ + self._experiment_resource_name = experiment_resource_name + self._api = api + self._logdir = logdir + self._tag_metadata = {} + self._tracker = tracker + self._one_platform_resource_manager = uploader_utils.OnePlatformResourceManager( + experiment_resource_name=experiment_resource_name, api=api + ) + + self._run_to_file_request_sender: Dict[str, _FileRequestSender] = {} + self._run_to_profile_loaders: Dict[str, _ProfileSessionLoader] = {} + + self._file_request_sender_factory = functools.partial( + _FileRequestSender, + api=api, + rpc_rate_limiter=blob_rpc_rate_limiter, + max_blob_request_size=upload_limits.max_blob_request_size, + max_blob_size=upload_limits.max_blob_size, + blob_storage_bucket=blob_storage_bucket, + source_bucket=source_bucket, + blob_storage_folder=blob_storage_folder, + tracker=self._tracker, + ) + + def _is_valid_event(self, run_name: str) -> bool: + """Determines whether a valid profile session has occurred. + + Profile events are determined by whether a corresponding directory has + been created for the profile plugin. + + Args: + run_name (str): + Required. String representing the run name. + + Returns: + True if is a valid profile plugin event, False otherwise. + """ + + return tf.io.gfile.isdir(self._profile_dir(run_name)) + + def _profile_dir(self, run_name: str) -> str: + """Converts run name to full profile path. + + Args: + run_name (str): + Required. Name of training run. + + Returns: + Full path for run name. + """ + return os.path.join(self._logdir, run_name, self.PROFILE_PATH) + + def send_request(self, run_name: str): + """Accepts run_name and sends an RPC request if an event is detected. + + Args: + run_name (str): + Required. Name of the training run. + """ + + if not self._is_valid_event(run_name): + logger.warning("No such profile run for %s", run_name) + return + + # Create a profiler loader if one is not created. + # This will store any new runs that occur within the training. + if run_name not in self._run_to_profile_loaders: + self._run_to_profile_loaders[run_name] = _ProfileSessionLoader( + self._profile_dir(run_name) + ) + + tb_run = self._one_platform_resource_manager.get_run_resource_name(run_name) + + if run_name not in self._run_to_file_request_sender: + self._run_to_file_request_sender[ + run_name + ] = self._file_request_sender_factory(tb_run) + + # Loop through any of the profiling sessions within this training run. + # A training run can have multiple profile sessions. + for prof_session, files in self._run_to_profile_loaders[ + run_name + ].prof_sessions_to_files(): + event_time = datetime.datetime.strptime(prof_session, "%Y_%m_%d_%H_%M_%S") + event_timestamp = timestamp.Timestamp().FromDatetime(event_time) + + # Implicit flush to any files after they are uploaded. + self._run_to_file_request_sender[run_name].add_files( + files=files, + tag=prof_session, + plugin=self.PLUGIN_NAME, + event_timestamp=event_timestamp, + ) + + +class _ProfileSessionLoader(object): + """Loader for a profile session within a training run. + + The term 'session' refers to an instance of a profile, where + one may have multiple profile sessions under a training run. + """ + + # A regular expression for the naming of a profiling path. + PROF_PATH_REGEX = r".*\/plugins\/profile\/[0-9]{4}_[0-9]{2}_[0-9]{2}_[0-9]{2}_[0-9]{2}_[0-9]{2}\/?$" + + def __init__( + self, + path: str, + ): + """Create a loader for profiling sessions with a training run. + + Args: + path (str): + Required. Path to the training run, which contains one or more profiling + sessions. Path should end with '/profile/plugin'. + """ + self._path = path + self._prof_session_to_files: DefaultDict[str, Set[str]] = defaultdict(set) + + def _path_filter(self, path: str) -> bool: + """Determine which paths we should upload. + + Paths written by profiler should be of form: + /some/path/to/dir/plugins/profile/%Y_%m_%d_%H_%M_%S + + Args: + path (str): + Required. String representing a full directory path. + + Returns: + True if valid path and path matches the filter, False otherwise. + """ + return tf.io.gfile.isdir(path) and re.match(self.PROF_PATH_REGEX, path) + + def _path_to_files(self, prof_session: str, path: str) -> List[str]: + """Generates files that have not yet been tracked. + + Files are generated by the profiler and are added to an internal + dictionary. For files that have not yet been uploaded, we return these + files. + + Args: + prof_session (str): + Required. The profiling session name. + path (str): + Required. Directory of the profiling session. + + Returns: + files (List[str]): + Files that have not been tracked yet. + """ + + files = [] + for prof_file in tf.io.gfile.listdir(path): + full_file_path = os.path.join(path, prof_file) + if full_file_path not in self._prof_session_to_files[prof_session]: + files.append(full_file_path) + + self._prof_session_to_files[prof_session].update(files) + return files + + def prof_sessions_to_files(self) -> Generator[Tuple[str, List[str]], None, None]: + """Map files to a profile session. + + Yields: + A tuple containing the profiling session name and a list of files + that have not yet been tracked. + """ + + prof_sessions = tf.io.gfile.listdir(self._path) + + for prof_session in prof_sessions: + # Remove trailing slashes in path names + prof_session = ( + prof_session if not prof_session.endswith("/") else prof_session[:-1] + ) + + full_path = os.path.join(self._path, prof_session) + if not self._path_filter(full_path): + continue + + files = self._path_to_files(prof_session, full_path) + + if files: + yield (prof_session, files) + + +class _FileRequestSender(object): + """Uploader for file based items. + + This sender is closely related to the `_BlobRequestSender`, however it expects + file paths instead of blob files, so that data is not directly read in and instead + files are moved between buckets. Additionally, this sender does not take event files + as the other request sender objects do. The sender takes files from either local storage + or a gcs bucket and uploads to the tensorboard bucket. + + This class is not threadsafe. Use external synchronization if calling its + methods concurrently. + """ + + def __init__( + self, + run_resource_id: str, + api: TensorboardServiceClient, + rpc_rate_limiter: util.RateLimiter, + max_blob_request_size: int, + max_blob_size: int, + blob_storage_bucket: storage.Bucket, + blob_storage_folder: str, + tracker: upload_tracker.UploadTracker, + source_bucket: Optional[storage.Bucket] = None, + ): + """Creates a _FileRequestSender object. + + Args: + run_resource_id (str): + Required. Name of the run resource of the form: + projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run} + api (TensorboardServiceClient): + Required. TensorboardServiceStub for calling various tensorboard services. + rpc_rate_limiter (util.RateLimiter): + Required. A `RateLimiter` to use to limit write RPC frequency. + Note this limit applies at the level of single RPCs in the Scalar and + Tensor case, but at the level of an entire blob upload in the Blob + case-- which may require a few preparatory RPCs and a stream of chunks. + Note the chunk stream is internally rate-limited by backpressure from + the server, so it is not a concern that we do not explicitly rate-limit + within the stream here. + max_blob_request_size (int): + Required. Maximum request size to send. + max_blob_size (int): + Required. Maximum size in bytes of the blobs to send. + blob_storage_bucket (storage.Bucket): + Required. Bucket to send event files to. + blob_storage_folder (str): + Required. The folder to save blob files to. + tracker (upload_tracker.UploadTracker): + Required. Track any uploads to backend. + source_bucket (storage.Bucket): + Optional. The source bucket to upload from. If not set, use local filesystem instead. + """ + self._run_resource_id = run_resource_id + self._api = api + self._rpc_rate_limiter = rpc_rate_limiter + self._max_blob_request_size = max_blob_request_size + self._max_blob_size = max_blob_size + self._tracker = tracker + self._time_series_resource_manager = uploader_utils.TimeSeriesResourceManager( + run_resource_id, api + ) + + self._bucket = blob_storage_bucket + self._folder = blob_storage_folder + self._source_bucket = source_bucket + + self._new_request() + + def _new_request(self): + """Declares the previous event complete.""" + self._files = [] + self._tag = None + self._plugin = None + self._event_timestamp = None + + def add_files( + self, + files: List[str], + tag: str, + plugin: str, + event_timestamp: timestamp.Timestamp, + ): + """Attempts to add the given file to the current request. + + If a file does not exist, the file is ignored and the rest of the + files are checked to ensure the remaining files exist. After checking + the files, an rpc is immediately sent. + + Files are flushed immediately, opposed to some of the other request senders. + + Args: + files (List[str]): + Required. The paths of the files to upload. + tag (str): + Required. A unique identifier for the blob sequence. + plugin (str): + Required. Name of the plugin making the request. + event_timestamp (timestamp.Timestamp): + Required. The time the event is created. + """ + + for prof_file in files: + if not tf.io.gfile.exists(prof_file): + logger.warning( + "The file provided does not exist. " + "Will not be uploading file %s.", + prof_file, + ) + else: + self._files.append(prof_file) + + self._tag = tag + self._plugin = plugin + self._event_timestamp = event_timestamp + self.flush() + self._new_request() + + def flush(self): + """Sends the current file fully, and clears it to make way for the next.""" + if not self._files: + return + + time_series_proto = self._time_series_resource_manager.get_or_create( + self._tag, + lambda: tensorboard_time_series.TensorboardTimeSeries( + display_name=self._tag, + value_type=tensorboard_time_series.TensorboardTimeSeries.ValueType.BLOB_SEQUENCE, + plugin_name=self._plugin, + ), + ) + m = re.match( + ".*/tensorboards/(.*)/experiments/(.*)/runs/(.*)/timeSeries/(.*)", + time_series_proto.name, + ) + blob_path_prefix = "tensorboard-{}/{}/{}/{}".format(m[1], m[2], m[3], m[4]) + blob_path_prefix = ( + "{}/{}".format(self._folder, blob_path_prefix) + if self._folder + else blob_path_prefix + ) + sent_blob_ids = [] + + for prof_file in self._files: + self._rpc_rate_limiter.tick() + file_size = tf.io.gfile.stat(prof_file).length + with self._tracker.blob_tracker(file_size) as blob_tracker: + if not self._file_too_large(prof_file): + blob_id = self._upload(prof_file, blob_path_prefix) + sent_blob_ids.append(str(blob_id)) + blob_tracker.mark_uploaded(blob_id is not None) + + data_point = tensorboard_data.TimeSeriesDataPoint( + blobs=tensorboard_data.TensorboardBlobSequence( + values=[ + tensorboard_data.TensorboardBlob(id=blob_id) + for blob_id in sent_blob_ids + ] + ), + wall_time=self._event_timestamp, + ) + + time_series_data_proto = tensorboard_data.TimeSeriesData( + tensorboard_time_series_id=time_series_proto.name.split("/")[-1], + value_type=tensorboard_time_series.TensorboardTimeSeries.ValueType.BLOB_SEQUENCE, + values=[data_point], + ) + request = tensorboard_service.WriteTensorboardRunDataRequest( + time_series_data=[time_series_data_proto] + ) + + _prune_empty_time_series_from_blob(request) + if not request.time_series_data: + return + + with uploader_utils.request_logger(request): + try: + self._api.write_tensorboard_run_data( + tensorboard_run=self._run_resource_id, + time_series_data=request.time_series_data, + ) + except grpc.RpcError as e: + logger.error("Upload call failed with error %s", e) + + def _file_too_large(self, filename: str) -> bool: + """Determines if a file is too large to upload. + + Args: + filename (str): + Required. The filename to check. + + Returns: + True if too large, False otherwise. + """ + + file_size = tf.io.gfile.stat(filename).length + if file_size > self._max_blob_size: + logger.warning( + "Blob too large; skipping. Size %d exceeds limit of %d bytes.", + file_size, + self._max_blob_size, + ) + return True + return False + + def _upload(self, filename: str, blob_path_prefix: Optional[str] = None) -> str: + """Copies files between either a local directory or a bucket and the tenant bucket. + + Args: + filename (str): + Required. The full path of the file to upload. + blob_path_prefix (str): + Optional. Path prefix for the location to store the file. + + Returns: + blob_id (str): + The base path of the file. + """ + blob_id = os.path.basename(filename) + blob_path = ( + "{}/{}".format(blob_path_prefix, blob_id) if blob_path_prefix else blob_id + ) + + # Source bucket indicates files are storage on cloud storage + if self._source_bucket: + self._copy_between_buckets(filename, blob_path) + else: + self._upload_from_local(filename, blob_path) + + return blob_id + + def _copy_between_buckets(self, filename: str, blob_path: str): + """Move files between the user's bucket and the tenant bucket. + + Args: + filename (str): + Required. Full path of the file to upload. + blob_path (str): + Required. A bucket path to upload the file to. + + """ + blob_name = _get_blob_from_file(filename) + + source_blob = self._source_bucket.blob(blob_name) + + self._source_bucket.copy_blob( + source_blob, + self._bucket, + blob_path, + ) + + def _upload_from_local(self, filename: str, blob_path: str): + """Uploads a local file to the tenant bucket. + + Args: + filename (str): + Required. Full path of the file to upload. + blob_path (str): + Required. A bucket path to upload the file to.a + """ + blob = self._bucket.blob(blob_path) + blob.upload_from_filename(filename) + + +def _get_blob_from_file(fp: str) -> Optional[str]: + """Gets blob name from a storage bucket. + + Args: + fp (str): + Required. A file path. + + Returns: + blob_name (str): + Optional. Base blob file name if it exists, else None + """ + m = re.match(r"gs:\/\/.*?\/(.*)", fp) + if not m: + logger.warning("Could not get the blob name from file %s", fp) + return None + return m[1] + + +def _prune_empty_time_series_from_blob( + request: tensorboard_service.WriteTensorboardRunDataRequest, +): + """Removes empty time_series from request if there are no blob files.' + + Args: + request (tensorboard_service.WriteTensorboardRunDataRequest): + Required. A write request for blob files. + """ + for time_series_idx, time_series_data in reversed( + list(enumerate(request.time_series_data)) + ): + if not any(x.blobs for x in time_series_data.values): + del request.time_series_data[time_series_idx] diff --git a/google/cloud/aiplatform/tensorboard/tensorboard_resource.py b/google/cloud/aiplatform/tensorboard/tensorboard_resource.py new file mode 100644 index 0000000000..76e89ca6bd --- /dev/null +++ b/google/cloud/aiplatform/tensorboard/tensorboard_resource.py @@ -0,0 +1,1289 @@ +# -*- coding: utf-8 -*- + +# 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 +# +# 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 typing import Dict, List, Optional, Sequence, Tuple, Union + +from google.auth import credentials as auth_credentials +from google.protobuf import field_mask_pb2 +from google.protobuf import timestamp_pb2 + +from google.cloud.aiplatform import base +from google.cloud.aiplatform import initializer +from google.cloud.aiplatform import utils +from google.cloud.aiplatform.compat.types import tensorboard as gca_tensorboard +from google.cloud.aiplatform.compat.types import ( + tensorboard_data as gca_tensorboard_data, +) +from google.cloud.aiplatform.compat.types import ( + tensorboard_experiment as gca_tensorboard_experiment, +) +from google.cloud.aiplatform.compat.types import tensorboard_run as gca_tensorboard_run +from google.cloud.aiplatform.compat.types import ( + tensorboard_service as gca_tensorboard_service, +) +from google.cloud.aiplatform.compat.types import ( + tensorboard_time_series as gca_tensorboard_time_series, +) + +_LOGGER = base.Logger(__name__) + + +class _TensorboardServiceResource(base.VertexAiResourceNounWithFutureManager): + client_class = utils.TensorboardClientWithOverride + + +class Tensorboard(_TensorboardServiceResource): + """Managed tensorboard resource for Vertex AI.""" + + _resource_noun = "tensorboards" + _getter_method = "get_tensorboard" + _list_method = "list_tensorboards" + _delete_method = "delete_tensorboard" + _parse_resource_name_method = "parse_tensorboard_path" + _format_resource_name_method = "tensorboard_path" + + def __init__( + self, + tensorboard_name: str, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ): + """Retrieves an existing managed tensorboard given a tensorboard name or ID. + + Args: + tensorboard_name (str): + Required. A fully-qualified tensorboard resource name or tensorboard ID. + Example: "projects/123/locations/us-central1/tensorboards/456" or + "456" when project and location are initialized or passed. + project (str): + Optional. Project to retrieve tensorboard from. If not set, project + set in aiplatform.init will be used. + location (str): + Optional. Location to retrieve tensorboard from. If not set, location + set in aiplatform.init will be used. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to retrieve this Tensorboard. Overrides + credentials set in aiplatform.init. + """ + + super().__init__( + project=project, + location=location, + credentials=credentials, + resource_name=tensorboard_name, + ) + self._gca_resource = self._get_gca_resource(resource_name=tensorboard_name) + + @classmethod + def create( + cls, + display_name: Optional[str] = None, + description: Optional[str] = None, + labels: Optional[Dict[str, str]] = None, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + encryption_spec_key_name: Optional[str] = None, + create_request_timeout: Optional[float] = None, + ) -> "Tensorboard": + """Creates a new tensorboard. + + Example Usage: + + tb = aiplatform.Tensorboard.create( + display_name='my display name', + description='my description', + labels={ + 'key1': 'value1', + 'key2': 'value2' + } + ) + + Args: + display_name (str): + Optional. The user-defined name of the Tensorboard. + The name can be up to 128 characters long and can be consist + of any UTF-8 characters. + description (str): + Optional. Description of this Tensorboard. + labels (Dict[str, str]): + Optional. Labels with user-defined metadata to organize your Tensorboards. + Label keys and values can be no longer than 64 characters + (Unicode codepoints), can only contain lowercase letters, numeric + characters, underscores and dashes. International characters are allowed. + No more than 64 user labels can be associated with one Tensorboard + (System labels are excluded). + See https://goo.gl/xmQnxf for more information and examples of labels. + System reserved label keys are prefixed with "aiplatform.googleapis.com/" + and are immutable. + project (str): + Optional. Project to upload this model to. Overrides project set in + aiplatform.init. + location (str): + Optional. Location to upload this model to. Overrides location set in + aiplatform.init. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to upload this model. Overrides + credentials set in aiplatform.init. + request_metadata (Sequence[Tuple[str, str]]): + Optional. Strings which should be sent along with the request as metadata. + encryption_spec_key_name (str): + Optional. Cloud KMS resource identifier of the customer + managed encryption key used to protect the tensorboard. Has the + form: + ``projects/my-project/locations/my-region/keyRings/my-kr/cryptoKeys/my-key``. + The key needs to be in the same region as where the compute + resource is created. + + If set, this Tensorboard and all sub-resources of this Tensorboard will be secured by this key. + + Overrides encryption_spec_key_name set in aiplatform.init. + create_request_timeout (float): + Optional. The timeout for the create request in seconds. + + Returns: + tensorboard (Tensorboard): + Instantiated representation of the managed tensorboard resource. + """ + if not display_name: + display_name = cls._generate_display_name() + + utils.validate_display_name(display_name) + if labels: + utils.validate_labels(labels) + + api_client = cls._instantiate_client(location=location, credentials=credentials) + + parent = initializer.global_config.common_location_path( + project=project, location=location + ) + + encryption_spec = initializer.global_config.get_encryption_spec( + encryption_spec_key_name=encryption_spec_key_name + ) + + gapic_tensorboard = gca_tensorboard.Tensorboard( + display_name=display_name, + description=description, + labels=labels, + encryption_spec=encryption_spec, + ) + + create_tensorboard_lro = api_client.create_tensorboard( + parent=parent, + tensorboard=gapic_tensorboard, + metadata=request_metadata, + timeout=create_request_timeout, + ) + + _LOGGER.log_create_with_lro(cls, create_tensorboard_lro) + + created_tensorboard = create_tensorboard_lro.result() + + _LOGGER.log_create_complete(cls, created_tensorboard, "tb") + + return cls( + tensorboard_name=created_tensorboard.name, + credentials=credentials, + ) + + def update( + self, + display_name: Optional[str] = None, + description: Optional[str] = None, + labels: Optional[Dict[str, str]] = None, + request_metadata: Optional[Sequence[Tuple[str, str]]] = (), + encryption_spec_key_name: Optional[str] = None, + ) -> "Tensorboard": + """Updates an existing tensorboard. + + Example Usage: + + tb = aiplatform.Tensorboard(tensorboard_name='123456') + tb.update( + display_name='update my display name', + description='update my description', + ) + + Args: + display_name (str): + Optional. User-defined name of the Tensorboard. + The name can be up to 128 characters long and can be consist + of any UTF-8 characters. + description (str): + Optional. Description of this Tensorboard. + labels (Dict[str, str]): + Optional. Labels with user-defined metadata to organize your Tensorboards. + Label keys and values can be no longer than 64 characters + (Unicode codepoints), can only contain lowercase letters, numeric + characters, underscores and dashes. International characters are allowed. + No more than 64 user labels can be associated with one Tensorboard + (System labels are excluded). + See https://goo.gl/xmQnxf for more information and examples of labels. + System reserved label keys are prefixed with "aiplatform.googleapis.com/" + and are immutable. + request_metadata (Sequence[Tuple[str, str]]): + Optional. Strings which should be sent along with the request as metadata. + encryption_spec_key_name (str): + Optional. Cloud KMS resource identifier of the customer + managed encryption key used to protect the tensorboard. Has the + form: + ``projects/my-project/locations/my-region/keyRings/my-kr/cryptoKeys/my-key``. + The key needs to be in the same region as where the compute + resource is created. + + If set, this Tensorboard and all sub-resources of this Tensorboard will be secured by this key. + + Overrides encryption_spec_key_name set in aiplatform.init. + + Returns: + Tensorboard: The managed tensorboard resource. + """ + update_mask = list() + + if display_name: + utils.validate_display_name(display_name) + update_mask.append("display_name") + + if description: + update_mask.append("description") + + if labels: + utils.validate_labels(labels) + update_mask.append("labels") + + encryption_spec = None + if encryption_spec_key_name: + encryption_spec = initializer.global_config.get_encryption_spec( + encryption_spec_key_name=encryption_spec_key_name, + ) + update_mask.append("encryption_spec") + + update_mask = field_mask_pb2.FieldMask(paths=update_mask) + + gapic_tensorboard = gca_tensorboard.Tensorboard( + name=self.resource_name, + display_name=display_name, + description=description, + labels=labels, + encryption_spec=encryption_spec, + ) + + _LOGGER.log_action_start_against_resource( + "Updating", + "tensorboard", + self, + ) + + update_tensorboard_lro = self.api_client.update_tensorboard( + tensorboard=gapic_tensorboard, + update_mask=update_mask, + metadata=request_metadata, + ) + + _LOGGER.log_action_started_against_resource_with_lro( + "Update", "tensorboard", self.__class__, update_tensorboard_lro + ) + + update_tensorboard_lro.result() + + _LOGGER.log_action_completed_against_resource("tensorboard", "updated", self) + + return self + + +class TensorboardExperiment(_TensorboardServiceResource): + """Managed tensorboard resource for Vertex AI.""" + + _resource_noun = "experiments" + _getter_method = "get_tensorboard_experiment" + _list_method = "list_tensorboard_experiments" + _delete_method = "delete_tensorboard_experiment" + _parse_resource_name_method = "parse_tensorboard_experiment_path" + _format_resource_name_method = "tensorboard_experiment_path" + + def __init__( + self, + tensorboard_experiment_name: str, + tensorboard_id: Optional[str] = None, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ): + """Retrieves an existing tensorboard experiment given a tensorboard experiment name or ID. + + Example Usage: + + tb_exp = aiplatform.TensorboardExperiment( + tensorboard_experiment_name= "projects/123/locations/us-central1/tensorboards/456/experiments/678" + ) + + tb_exp = aiplatform.TensorboardExperiment( + tensorboard_experiment_name= "678" + tensorboard_id = "456" + ) + + Args: + tensorboard_experiment_name (str): + Required. A fully-qualified tensorboard experiment resource name or resource ID. + Example: "projects/123/locations/us-central1/tensorboards/456/experiments/678" or + "678" when tensorboard_id is passed and project and location are initialized or passed. + tensorboard_id (str): + Optional. A tensorboard resource ID. + project (str): + Optional. Project to retrieve tensorboard from. If not set, project + set in aiplatform.init will be used. + location (str): + Optional. Location to retrieve tensorboard from. If not set, location + set in aiplatform.init will be used. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to retrieve this Tensorboard. Overrides + credentials set in aiplatform.init. + """ + + super().__init__( + project=project, + location=location, + credentials=credentials, + resource_name=tensorboard_experiment_name, + ) + self._gca_resource = self._get_gca_resource( + resource_name=tensorboard_experiment_name, + parent_resource_name_fields={Tensorboard._resource_noun: tensorboard_id} + if tensorboard_id + else tensorboard_id, + ) + + @classmethod + def create( + cls, + tensorboard_experiment_id: str, + tensorboard_name: str, + display_name: Optional[str] = None, + description: Optional[str] = None, + labels: Optional[Dict[str, str]] = None, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + request_metadata: Sequence[Tuple[str, str]] = (), + create_request_timeout: Optional[float] = None, + ) -> "TensorboardExperiment": + """Creates a new TensorboardExperiment. + + Example Usage: + + tb_exp = aiplatform.TensorboardExperiment.create( + tensorboard_experiment_id='my-experiment' + tensorboard_id='456' + display_name='my display name', + description='my description', + labels={ + 'key1': 'value1', + 'key2': 'value2' + } + ) + + Args: + tensorboard_experiment_id (str): + Required. The ID to use for the Tensorboard experiment, + which will become the final component of the Tensorboard + experiment's resource name. + + This value should be 1-128 characters, and valid + characters are /[a-z][0-9]-/. + + This corresponds to the ``tensorboard_experiment_id`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + tensorboard_name (str): + Required. The resource name or ID of the Tensorboard to create + the TensorboardExperiment in. Format of resource name: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}`` + display_name (str): + Optional. The user-defined name of the Tensorboard Experiment. + The name can be up to 128 characters long and can be consist + of any UTF-8 characters. + description (str): + Optional. Description of this Tensorboard Experiment. + labels (Dict[str, str]): + Optional. Labels with user-defined metadata to organize your Tensorboards. + Label keys and values can be no longer than 64 characters + (Unicode codepoints), can only contain lowercase letters, numeric + characters, underscores and dashes. International characters are allowed. + No more than 64 user labels can be associated with one Tensorboard + (System labels are excluded). + See https://goo.gl/xmQnxf for more information and examples of labels. + System reserved label keys are prefixed with "aiplatform.googleapis.com/" + and are immutable. + project (str): + Optional. Project to upload this model to. Overrides project set in + aiplatform.init. + location (str): + Optional. Location to upload this model to. Overrides location set in + aiplatform.init. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to upload this model. Overrides + credentials set in aiplatform.init. + request_metadata (Sequence[Tuple[str, str]]): + Optional. Strings which should be sent along with the request as metadata. + create_request_timeout (float): + Optional. The timeout for the create request in seconds. + Returns: + TensorboardExperiment: The TensorboardExperiment resource. + """ + + if display_name: + utils.validate_display_name(display_name) + + if labels: + utils.validate_labels(labels) + + api_client = cls._instantiate_client(location=location, credentials=credentials) + + parent = utils.full_resource_name( + resource_name=tensorboard_name, + resource_noun=Tensorboard._resource_noun, + parse_resource_name_method=Tensorboard._parse_resource_name, + format_resource_name_method=Tensorboard._format_resource_name, + project=project, + location=location, + ) + + gapic_tensorboard_experiment = gca_tensorboard_experiment.TensorboardExperiment( + display_name=display_name, + description=description, + labels=labels, + ) + + _LOGGER.log_create_with_lro(cls) + + tensorboard_experiment = api_client.create_tensorboard_experiment( + parent=parent, + tensorboard_experiment=gapic_tensorboard_experiment, + tensorboard_experiment_id=tensorboard_experiment_id, + metadata=request_metadata, + timeout=create_request_timeout, + ) + + _LOGGER.log_create_complete(cls, tensorboard_experiment, "tb experiment") + + return cls( + tensorboard_experiment_name=tensorboard_experiment.name, + credentials=credentials, + ) + + @classmethod + def list( + cls, + tensorboard_name: str, + filter: Optional[str] = None, + order_by: Optional[str] = None, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ) -> List["TensorboardExperiment"]: + """List TensorboardExperiemnts in a Tensorboard resource. + + Example Usage: + + aiplatform.TensorboardExperiment.list( + tensorboard_name='projects/my-project/locations/us-central1/tensorboards/123' + ) + + Args: + tensorboard_name(str): + Required. The resource name or resource ID of the + Tensorboard to list + TensorboardExperiments. Format, if resource name: + 'projects/{project}/locations/{location}/tensorboards/{tensorboard}' + filter (str): + Optional. An expression for filtering the results of the request. + For field names both snake_case and camelCase are supported. + order_by (str): + Optional. A comma-separated list of fields to order by, sorted in + ascending order. Use "desc" after a field name for descending. + Supported fields: `display_name`, `create_time`, `update_time` + project (str): + Optional. Project to retrieve list from. If not set, project + set in aiplatform.init will be used. + location (str): + Optional. Location to retrieve list from. If not set, location + set in aiplatform.init will be used. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to retrieve list. Overrides + credentials set in aiplatform.init. + Returns: + List[TensorboardExperiment] - A list of TensorboardExperiments + """ + + parent = utils.full_resource_name( + resource_name=tensorboard_name, + resource_noun=Tensorboard._resource_noun, + parse_resource_name_method=Tensorboard._parse_resource_name, + format_resource_name_method=Tensorboard._format_resource_name, + project=project, + location=location, + ) + + return super()._list( + filter=filter, + order_by=order_by, + project=project, + location=location, + credentials=credentials, + parent=parent, + ) + + +class TensorboardRun(_TensorboardServiceResource): + """Managed tensorboard resource for Vertex AI.""" + + _resource_noun = "runs" + _getter_method = "get_tensorboard_run" + _list_method = "list_tensorboard_runs" + _delete_method = "delete_tensorboard_run" + _parse_resource_name_method = "parse_tensorboard_run_path" + _format_resource_name_method = "tensorboard_run_path" + + def __init__( + self, + tensorboard_run_name: str, + tensorboard_id: Optional[str] = None, + tensorboard_experiment_id: Optional[str] = None, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ): + """Retrieves an existing tensorboard run given a tensorboard run name or ID. + + Example Usage: + + tb_run = aiplatform.TensorboardRun( + tensorboard_run_name= "projects/123/locations/us-central1/tensorboards/456/experiments/678/run/8910" + ) + + tb_run = aiplatform.TensorboardRun( + tensorboard_run_name= "8910", + tensorboard_id = "456", + tensorboard_experiment_id = "678" + ) + + Args: + tensorboard_run_name (str): + Required. A fully-qualified tensorboard run resource name or resource ID. + Example: "projects/123/locations/us-central1/tensorboards/456/experiments/678/runs/8910" or + "8910" when tensorboard_id and tensorboard_experiment_id are passed + and project and location are initialized or passed. + tensorboard_id (str): + Optional. A tensorboard resource ID. + tensorboard_experiment_id (str): + Optional. A tensorboard experiment resource ID. + project (str): + Optional. Project to retrieve tensorboard from. If not set, project + set in aiplatform.init will be used. + location (str): + Optional. Location to retrieve tensorboard from. If not set, location + set in aiplatform.init will be used. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to retrieve this Tensorboard. Overrides + credentials set in aiplatform.init. + Raises: + ValueError: if only one of tensorboard_id or tensorboard_experiment_id is provided. + """ + if bool(tensorboard_id) != bool(tensorboard_experiment_id): + raise ValueError( + "Both tensorboard_id and tensorboard_experiment_id must be provided or neither should be provided." + ) + + super().__init__( + project=project, + location=location, + credentials=credentials, + resource_name=tensorboard_run_name, + ) + self._gca_resource = self._get_gca_resource( + resource_name=tensorboard_run_name, + parent_resource_name_fields={ + Tensorboard._resource_noun: tensorboard_id, + TensorboardExperiment._resource_noun: tensorboard_experiment_id, + } + if tensorboard_id + else tensorboard_id, + ) + + self._time_series_display_name_to_id_mapping = ( + self._get_time_series_display_name_to_id_mapping() + ) + + @classmethod + def create( + cls, + tensorboard_run_id: str, + tensorboard_experiment_name: str, + tensorboard_id: Optional[str] = None, + display_name: Optional[str] = None, + description: Optional[str] = None, + labels: Optional[Dict[str, str]] = None, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + request_metadata: Sequence[Tuple[str, str]] = (), + create_request_timeout: Optional[float] = None, + ) -> "TensorboardRun": + """Creates a new tensorboard run. + + Example Usage: + + tb_run = aiplatform.TensorboardRun.create( + tensorboard_run_id='my-run' + tensorboard_experiment_name='my-experiment' + tensorboard_id='456' + display_name='my display name', + description='my description', + labels={ + 'key1': 'value1', + 'key2': 'value2' + } + ) + + Args: + tensorboard_run_id (str): + Required. The ID to use for the Tensorboard run, which + will become the final component of the Tensorboard run's + resource name. + + This value should be 1-128 characters, and valid: + characters are /[a-z][0-9]-/. + tensorboard_experiment_name (str): + Required. The resource name or ID of the TensorboardExperiment + to create the TensorboardRun in. Resource name format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` + + If resource ID is provided then tensorboard_id must be provided. + tensorboard_id (str): + Optional. The resource ID of the Tensorboard to create the TensorboardRun in. + display_name (str): + Optional. The user-defined name of the Tensorboard Run. + This value must be unique among all TensorboardRuns belonging to the + same parent TensorboardExperiment. + + If not provided tensorboard_run_id will be used. + description (str): + Optional. Description of this Tensorboard Run. + labels (Dict[str, str]): + Optional. Labels with user-defined metadata to organize your Tensorboards. + Label keys and values can be no longer than 64 characters + (Unicode codepoints), can only contain lowercase letters, numeric + characters, underscores and dashes. International characters are allowed. + No more than 64 user labels can be associated with one Tensorboard + (System labels are excluded). + See https://goo.gl/xmQnxf for more information and examples of labels. + System reserved label keys are prefixed with "aiplatform.googleapis.com/" + and are immutable. + project (str): + Optional. Project to upload this model to. Overrides project set in + aiplatform.init. + location (str): + Optional. Location to upload this model to. Overrides location set in + aiplatform.init. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to upload this model. Overrides + credentials set in aiplatform.init. + request_metadata (Sequence[Tuple[str, str]]): + Optional. Strings which should be sent along with the request as metadata. + create_request_timeout (float): + Optional. The timeout for the create request in seconds. + Returns: + TensorboardRun: The TensorboardRun resource. + """ + if display_name: + utils.validate_display_name(display_name) + + if labels: + utils.validate_labels(labels) + + display_name = display_name or tensorboard_run_id + + api_client = cls._instantiate_client(location=location, credentials=credentials) + + parent = utils.full_resource_name( + resource_name=tensorboard_experiment_name, + resource_noun=TensorboardExperiment._resource_noun, + parse_resource_name_method=TensorboardExperiment._parse_resource_name, + format_resource_name_method=TensorboardExperiment._format_resource_name, + parent_resource_name_fields={Tensorboard._resource_noun: tensorboard_id}, + project=project, + location=location, + ) + + gapic_tensorboard_run = gca_tensorboard_run.TensorboardRun( + display_name=display_name, + description=description, + labels=labels, + ) + + _LOGGER.log_create_with_lro(cls) + + tensorboard_run = api_client.create_tensorboard_run( + parent=parent, + tensorboard_run=gapic_tensorboard_run, + tensorboard_run_id=tensorboard_run_id, + metadata=request_metadata, + timeout=create_request_timeout, + ) + + _LOGGER.log_create_complete(cls, tensorboard_run, "tb_run") + + return cls( + tensorboard_run_name=tensorboard_run.name, + credentials=credentials, + ) + + @classmethod + def list( + cls, + tensorboard_experiment_name: str, + tensorboard_id: Optional[str] = None, + filter: Optional[str] = None, + order_by: Optional[str] = None, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ) -> List["TensorboardRun"]: + """List all instances of TensorboardRun in TensorboardExperiment. + + Example Usage: + + aiplatform.TensorboardRun.list( + tensorboard_experiment_name='projects/my-project/locations/us-central1/tensorboards/123/experiments/456' + ) + + Args: + tensorboard_experiment_name (str): + Required. The resource name or resource ID of the + TensorboardExperiment to list + TensorboardRun. Format, if resource name: + 'projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}' + + If resource ID is provided then tensorboard_id must be provided. + tensorboard_id (str): + Optional. The resource ID of the Tensorboard that contains the TensorboardExperiment + to list TensorboardRun. + filter (str): + Optional. An expression for filtering the results of the request. + For field names both snake_case and camelCase are supported. + order_by (str): + Optional. A comma-separated list of fields to order by, sorted in + ascending order. Use "desc" after a field name for descending. + Supported fields: `display_name`, `create_time`, `update_time` + project (str): + Optional. Project to retrieve list from. If not set, project + set in aiplatform.init will be used. + location (str): + Optional. Location to retrieve list from. If not set, location + set in aiplatform.init will be used. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to retrieve list. Overrides + credentials set in aiplatform.init. + Returns: + List[TensorboardRun] - A list of TensorboardRun + """ + + parent = utils.full_resource_name( + resource_name=tensorboard_experiment_name, + resource_noun=TensorboardExperiment._resource_noun, + parse_resource_name_method=TensorboardExperiment._parse_resource_name, + format_resource_name_method=TensorboardExperiment._format_resource_name, + parent_resource_name_fields={Tensorboard._resource_noun: tensorboard_id}, + project=project, + location=location, + ) + + tensorboard_runs = super()._list( + filter=filter, + order_by=order_by, + project=project, + location=location, + credentials=credentials, + parent=parent, + ) + + for tensorboard_run in tensorboard_runs: + tensorboard_run._sync_time_series_display_name_to_id_mapping() + + return tensorboard_runs + + def write_tensorboard_scalar_data( + self, + time_series_data: Dict[str, float], + step: int, + wall_time: Optional[timestamp_pb2.Timestamp] = None, + ): + """Writes tensorboard scalar data to this run. + + Args: + time_series_data (Dict[str, float]): + Required. Dictionary of where keys are TensorboardTimeSeries display name and values are the scalar value.. + step (int): + Required. Step index of this data point within the run. + wall_time (timestamp_pb2.Timestamp): + Optional. Wall clock timestamp when this data point is + generated by the end user. + + If not provided, this will be generated based on the value from time.time() + """ + + if not wall_time: + wall_time = utils.get_timestamp_proto() + + ts_data = [] + + if any( + key not in self._time_series_display_name_to_id_mapping + for key in time_series_data.keys() + ): + self._sync_time_series_display_name_to_id_mapping() + + for display_name, value in time_series_data.items(): + time_series_id = self._time_series_display_name_to_id_mapping.get( + display_name + ) + + if not time_series_id: + raise RuntimeError( + f"TensorboardTimeSeries with display name {display_name} has not been created in TensorboardRun {self.resource_name}." + ) + + ts_data.append( + gca_tensorboard_data.TimeSeriesData( + tensorboard_time_series_id=time_series_id, + value_type=gca_tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR, + values=[ + gca_tensorboard_data.TimeSeriesDataPoint( + scalar=gca_tensorboard_data.Scalar(value=value), + wall_time=wall_time, + step=step, + ) + ], + ) + ) + + self.api_client.write_tensorboard_run_data( + tensorboard_run=self.resource_name, time_series_data=ts_data + ) + + def _get_time_series_display_name_to_id_mapping(self) -> Dict[str, str]: + """Returns a mapping of the TimeSeries display names to resource IDs for this Run. + + Returns: + Dict[str, str] - Dictionary mapping TensorboardTimeSeries display names to + resource IDs of TensorboardTimeSeries in this TensorboardRun.""" + time_series = TensorboardTimeSeries.list( + tensorboard_run_name=self.resource_name, credentials=self.credentials + ) + + return {ts.display_name: ts.name for ts in time_series} + + def _sync_time_series_display_name_to_id_mapping(self): + """Updates the local map of TimeSeries diplay name to resource ID.""" + self._time_series_display_name_to_id_mapping = ( + self._get_time_series_display_name_to_id_mapping() + ) + + def create_tensorboard_time_series( + self, + display_name: str, + value_type: Union[ + gca_tensorboard_time_series.TensorboardTimeSeries.ValueType, str + ] = "SCALAR", + plugin_name: str = "scalars", + plugin_data: Optional[bytes] = None, + description: Optional[str] = None, + ) -> "TensorboardTimeSeries": + """Creates a new tensorboard time series. + + Example Usage: + + tb_ts = tensorboard_run.create_tensorboard_time_series( + display_name='my display name', + tensorboard_run_name='my-run' + tensorboard_id='456' + tensorboard_experiment_id='my-experiment' + description='my description', + labels={ + 'key1': 'value1', + 'key2': 'value2' + } + ) + + Args: + display_name (str): + Optional. User provided name of this + TensorboardTimeSeries. This value should be + unique among all TensorboardTimeSeries resources + belonging to the same TensorboardRun resource + (parent resource). + value_type (Union[gca_tensorboard_time_series.TensorboardTimeSeries.ValueType, str]): + Optional. Type of TensorboardTimeSeries value. One of 'SCALAR', 'TENSOR', 'BLOB_SEQUENCE'. + plugin_name (str): + Optional. Name of the plugin this time series pertain to. Such as Scalar, Tensor, Blob. + plugin_data (bytes): + Optional. Data of the current plugin, with the size limited to 65KB. + description (str): + Optional. Description of this TensorboardTimeseries. + Returns: + TensorboardTimeSeries: The TensorboardTimeSeries resource. + """ + + tb_time_series = TensorboardTimeSeries.create( + display_name=display_name, + tensorboard_run_name=self.resource_name, + value_type=value_type, + plugin_name=plugin_name, + plugin_data=plugin_data, + description=description, + credentials=self.credentials, + ) + + self._time_series_display_name_to_id_mapping[ + tb_time_series.display_name + ] = tb_time_series.name + + return tb_time_series + + def read_time_series_data(self) -> Dict[str, gca_tensorboard_data.TimeSeriesData]: + """Read the time series data of this run. + + ``` + time_series_data = tensorboard_run.read_time_series_data() + + print(time_series_data['loss'].values[-1].scalar.value) + ``` + + Returns: + Dictionary of time series metric id to TimeSeriesData. + """ + self._sync_time_series_display_name_to_id_mapping() + + resource_name_parts = self._parse_resource_name(self.resource_name) + inverted_mapping = { + resource_id: display_name + for display_name, resource_id in self._time_series_display_name_to_id_mapping.items() + } + + time_series_resource_names = [ + TensorboardTimeSeries._format_resource_name( + time_series=resource_id, **resource_name_parts + ) + for resource_id in inverted_mapping.keys() + ] + + resource_name_parts.pop("experiment") + resource_name_parts.pop("run") + + tensorboard_resource_name = Tensorboard._format_resource_name( + **resource_name_parts + ) + + read_response = self.api_client.batch_read_tensorboard_time_series_data( + request=gca_tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest( + tensorboard=tensorboard_resource_name, + time_series=time_series_resource_names, + ) + ) + + return { + inverted_mapping[data.tensorboard_time_series_id]: data + for data in read_response.time_series_data + } + + +class TensorboardTimeSeries(_TensorboardServiceResource): + """Managed tensorboard resource for Vertex AI.""" + + _resource_noun = "timeSeries" + _getter_method = "get_tensorboard_time_series" + _list_method = "list_tensorboard_time_series" + _delete_method = "delete_tensorboard_time_series" + _parse_resource_name_method = "parse_tensorboard_time_series_path" + _format_resource_name_method = "tensorboard_time_series_path" + + def __init__( + self, + tensorboard_time_series_name: str, + tensorboard_id: Optional[str] = None, + tensorboard_experiment_id: Optional[str] = None, + tensorboard_run_id: Optional[str] = None, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ): + """Retrieves an existing tensorboard time series given a tensorboard time series name or ID. + + Example Usage: + + tb_ts = aiplatform.TensorboardTimeSeries( + tensorboard_time_series_name="projects/123/locations/us-central1/tensorboards/456/experiments/789/run/1011/timeSeries/mse" + ) + + tb_ts = aiplatform.TensorboardTimeSeries( + tensorboard_time_series_name= "mse", + tensorboard_id = "456", + tensorboard_experiment_id = "789" + tensorboard_run_id = "1011" + ) + + Args: + tensorboard_time_series_name (str): + Required. A fully-qualified tensorboard time series resource name or resource ID. + Example: "projects/123/locations/us-central1/tensorboards/456/experiments/789/run/1011/timeSeries/mse" or + "mse" when tensorboard_id, tensorboard_experiment_id, tensorboard_run_id are passed + and project and location are initialized or passed. + tensorboard_id (str): + Optional. A tensorboard resource ID. + tensorboard_experiment_id (str): + Optional. A tensorboard experiment resource ID. + tensorboard_run_id (str): + Optional. A tensorboard run resource ID. + project (str): + Optional. Project to retrieve tensorboard from. If not set, project + set in aiplatform.init will be used. + location (str): + Optional. Location to retrieve tensorboard from. If not set, location + set in aiplatform.init will be used. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to retrieve this Tensorboard. Overrides + credentials set in aiplatform.init. + Raises: + ValueError: if only one of tensorboard_id or tensorboard_experiment_id is provided. + """ + if not ( + bool(tensorboard_id) + == bool(tensorboard_experiment_id) + == bool(tensorboard_run_id) + ): + raise ValueError( + "tensorboard_id, tensorboard_experiment_id, tensorboard_run_id must all be provided or none should be provided." + ) + + super().__init__( + project=project, + location=location, + credentials=credentials, + resource_name=tensorboard_time_series_name, + ) + self._gca_resource = self._get_gca_resource( + resource_name=tensorboard_time_series_name, + parent_resource_name_fields={ + Tensorboard._resource_noun: tensorboard_id, + TensorboardExperiment._resource_noun: tensorboard_experiment_id, + TensorboardRun._resource_noun: tensorboard_run_id, + } + if tensorboard_id + else tensorboard_id, + ) + + @classmethod + def create( + cls, + display_name: str, + tensorboard_run_name: str, + tensorboard_id: Optional[str] = None, + tensorboard_experiment_id: Optional[str] = None, + value_type: Union[ + gca_tensorboard_time_series.TensorboardTimeSeries.ValueType, str + ] = "SCALAR", + plugin_name: str = "scalars", + plugin_data: Optional[bytes] = None, + description: Optional[str] = None, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ) -> "TensorboardTimeSeries": + """Creates a new tensorboard time series. + + Example Usage: + + tb_ts = aiplatform.TensorboardTimeSeries.create( + display_name='my display name', + tensorboard_run_name='my-run' + tensorboard_id='456' + tensorboard_experiment_id='my-experiment' + description='my description', + labels={ + 'key1': 'value1', + 'key2': 'value2' + } + ) + + Args: + display_name (str): + Optional. User provided name of this + TensorboardTimeSeries. This value should be + unique among all TensorboardTimeSeries resources + belonging to the same TensorboardRun resource + (parent resource). + tensorboard_run_name (str): + Required. The resource name or ID of the TensorboardRun + to create the TensorboardTimeseries in. Resource name format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}`` + + If resource ID is provided then tensorboard_id and tensorboard_experiment_id must be provided. + tensorboard_id (str): + Optional. The resource ID of the Tensorboard to create the TensorboardTimeSeries in. + tensorboard_experiment_id (str): + Optional. The ID of the TensorboardExperiment to create the TensorboardTimeSeries in. + value_type (Union[gca_tensorboard_time_series.TensorboardTimeSeries.ValueType, str]): + Optional. Type of TensorboardTimeSeries value. One of 'SCALAR', 'TENSOR', 'BLOB_SEQUENCE'. + plugin_name (str): + Optional. Name of the plugin this time series pertain to. + plugin_data (bytes): + Optional. Data of the current plugin, with the size limited to 65KB. + description (str): + Optional. Description of this TensorboardTimeseries. + project (str): + Optional. Project to upload this model to. Overrides project set in + aiplatform.init. + location (str): + Optional. Location to upload this model to. Overrides location set in + aiplatform.init. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to upload this model. Overrides + credentials set in aiplatform.init. + Returns: + TensorboardTimeSeries: The TensorboardTimeSeries resource. + """ + + if isinstance(value_type, str): + value_type = getattr( + gca_tensorboard_time_series.TensorboardTimeSeries.ValueType, value_type + ) + + api_client = cls._instantiate_client(location=location, credentials=credentials) + + parent = utils.full_resource_name( + resource_name=tensorboard_run_name, + resource_noun=TensorboardRun._resource_noun, + parse_resource_name_method=TensorboardRun._parse_resource_name, + format_resource_name_method=TensorboardRun._format_resource_name, + parent_resource_name_fields={ + Tensorboard._resource_noun: tensorboard_id, + TensorboardExperiment._resource_noun: tensorboard_experiment_id, + }, + project=project, + location=location, + ) + + gapic_tensorboard_time_series = ( + gca_tensorboard_time_series.TensorboardTimeSeries( + display_name=display_name, + description=description, + value_type=value_type, + plugin_name=plugin_name, + plugin_data=plugin_data, + ) + ) + + _LOGGER.log_create_with_lro(cls) + + tensorboard_time_series = api_client.create_tensorboard_time_series( + parent=parent, tensorboard_time_series=gapic_tensorboard_time_series + ) + + _LOGGER.log_create_complete(cls, tensorboard_time_series, "tb_time_series") + + self = cls._empty_constructor( + project=project, location=location, credentials=credentials + ) + self._gca_resource = tensorboard_time_series + + return self + + @classmethod + def list( + cls, + tensorboard_run_name: str, + tensorboard_id: Optional[str] = None, + tensorboard_experiment_id: Optional[str] = None, + filter: Optional[str] = None, + order_by: Optional[str] = None, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ) -> List["TensorboardTimeSeries"]: + """List all instances of TensorboardTimeSeries in TensorboardRun. + + Example Usage: + + aiplatform.TensorboardTimeSeries.list( + tensorboard_run_name='projects/my-project/locations/us-central1/tensorboards/123/experiments/my-experiment/runs/my-run' + ) + + Args: + tensorboard_run_name (str): + Required. The resource name or ID of the TensorboardRun + to list the TensorboardTimeseries from. Resource name format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}`` + + If resource ID is provided then tensorboard_id and tensorboard_experiment_id must be provided. + tensorboard_id (str): + Optional. The resource ID of the Tensorboard to list the TensorboardTimeSeries from. + tensorboard_experiment_id (str): + Optional. The ID of the TensorboardExperiment to list the TensorboardTimeSeries from. + filter (str): + Optional. An expression for filtering the results of the request. + For field names both snake_case and camelCase are supported. + order_by (str): + Optional. A comma-separated list of fields to order by, sorted in + ascending order. Use "desc" after a field name for descending. + Supported fields: `display_name`, `create_time`, `update_time` + project (str): + Optional. Project to retrieve list from. If not set, project + set in aiplatform.init will be used. + location (str): + Optional. Location to retrieve list from. If not set, location + set in aiplatform.init will be used. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to retrieve list. Overrides + credentials set in aiplatform.init. + Returns: + List[TensorboardTimeSeries] - A list of TensorboardTimeSeries + """ + + parent = utils.full_resource_name( + resource_name=tensorboard_run_name, + resource_noun=TensorboardRun._resource_noun, + parse_resource_name_method=TensorboardRun._parse_resource_name, + format_resource_name_method=TensorboardRun._format_resource_name, + parent_resource_name_fields={ + Tensorboard._resource_noun: tensorboard_id, + TensorboardExperiment._resource_noun: tensorboard_experiment_id, + }, + project=project, + location=location, + ) + + return super()._list( + filter=filter, + order_by=order_by, + project=project, + location=location, + credentials=credentials, + parent=parent, + ) diff --git a/google/cloud/aiplatform/tensorboard/uploader.py b/google/cloud/aiplatform/tensorboard/uploader.py index 57dcbedf60..c9926eb18a 100644 --- a/google/cloud/aiplatform/tensorboard/uploader.py +++ b/google/cloud/aiplatform/tensorboard/uploader.py @@ -15,13 +15,22 @@ # limitations under the License. # """Uploads a TensorBoard logdir to TensorBoard.gcp.""" -import contextlib +import abc +from collections import defaultdict import functools -import json +import logging import os import time import re -from typing import Callable, Dict, FrozenSet, Generator, Iterable, Optional, Tuple +from typing import ( + Dict, + FrozenSet, + Generator, + Iterable, + Optional, + ContextManager, + Tuple, +) import uuid import grpc @@ -47,26 +56,17 @@ from google.api_core import exceptions from google.cloud import storage -from google.cloud.aiplatform.compat.services import tensorboard_service_client_v1beta1 -from google.cloud.aiplatform.compat.types import ( - tensorboard_data_v1beta1 as tensorboard_data, -) -from google.cloud.aiplatform.compat.types import ( - tensorboard_experiment_v1beta1 as tensorboard_experiment, -) -from google.cloud.aiplatform.compat.types import ( - tensorboard_run_v1beta1 as tensorboard_run, -) -from google.cloud.aiplatform.compat.types import ( - tensorboard_service_v1beta1 as tensorboard_service, -) -from google.cloud.aiplatform.compat.types import ( - tensorboard_time_series_v1beta1 as tensorboard_time_series, -) +from google.cloud.aiplatform.compat.services import tensorboard_service_client +from google.cloud.aiplatform.compat.types import tensorboard_data +from google.cloud.aiplatform.compat.types import tensorboard_experiment +from google.cloud.aiplatform.compat.types import tensorboard_service +from google.cloud.aiplatform.compat.types import tensorboard_time_series +from google.cloud.aiplatform.tensorboard import uploader_utils +from google.cloud.aiplatform.tensorboard.plugins.tf_profiler import profile_uploader from google.protobuf import message from google.protobuf import timestamp_pb2 as timestamp -TensorboardServiceClient = tensorboard_service_client_v1beta1.TensorboardServiceClient +TensorboardServiceClient = tensorboard_service_client.TensorboardServiceClient # Minimum length of a logdir polling cycle in seconds. Shorter cycles will # sleep to avoid spinning over the logdir, which isn't great for disks and can @@ -83,7 +83,7 @@ _DEFAULT_MIN_SCALAR_REQUEST_INTERVAL = 10 # Default maximum WriteTensorbordRunData request size in bytes. -_DEFAULT_MAX_SCALAR_REQUEST_SIZE = 24 * (2 ** 10) # 24KiB +_DEFAULT_MAX_SCALAR_REQUEST_SIZE = 128 * (2**10) # 128KiB # Default minimum interval between initiating WriteTensorbordRunData RPCs in # milliseconds. @@ -94,16 +94,26 @@ _DEFAULT_MIN_BLOB_REQUEST_INTERVAL = 10 # Default maximum WriteTensorbordRunData request size in bytes. -_DEFAULT_MAX_TENSOR_REQUEST_SIZE = 512 * (2 ** 10) # 512KiB +_DEFAULT_MAX_TENSOR_REQUEST_SIZE = 512 * (2**10) # 512KiB -_DEFAULT_MAX_BLOB_REQUEST_SIZE = 4 * (2 ** 20) - 256 * (2 ** 10) # 4MiB-256KiB +_DEFAULT_MAX_BLOB_REQUEST_SIZE = 128 * (2**10) # 24KiB # Default maximum tensor point size in bytes. -_DEFAULT_MAX_TENSOR_POINT_SIZE = 16 * (2 ** 10) # 16KiB +_DEFAULT_MAX_TENSOR_POINT_SIZE = 16 * (2**10) # 16KiB -_DEFAULT_MAX_BLOB_SIZE = 10 * (2 ** 30) # 10GiB +_DEFAULT_MAX_BLOB_SIZE = 10 * (2**30) # 10GiB logger = tb_logging.get_logger() +logger.setLevel(logging.WARNING) + + +class RequestSender(object): + """A base class for additional request sender objects. + + Currently just used for typing. + """ + + pass class TensorBoardUploader(object): @@ -178,6 +188,7 @@ def __init__( self._logdir = logdir self._allowed_plugins = frozenset(allowed_plugins) self._run_name_prefix = run_name_prefix + self._is_brand_new_experiment = False self._upload_limits = upload_limits if not self._upload_limits: @@ -200,11 +211,11 @@ def __init__( ) self._upload_limits.max_blob_request_size = _DEFAULT_MAX_BLOB_REQUEST_SIZE self._upload_limits.max_blob_size = _DEFAULT_MAX_BLOB_SIZE - self._description = description self._verbosity = verbosity self._one_shot = one_shot - self._request_sender = None + self._dispatcher = None + self._additional_senders: Dict[str, uploader_utils.RequestSender] = {} if logdir_poll_rate_limiter is None: self._logdir_poll_rate_limiter = util.RateLimiter( _MIN_LOGDIR_POLL_INTERVAL_SECS @@ -248,8 +259,13 @@ def active_filter(secs): self._logdir_loader = logdir_loader.LogdirLoader( self._logdir, directory_loader_factory ) + self._logdir_loader_pre_create = logdir_loader.LogdirLoader( + self._logdir, directory_loader_factory + ) self._tracker = upload_tracker.UploadTracker(verbosity=self._verbosity) + self._create_additional_senders() + def _create_or_get_experiment(self) -> tensorboard_experiment.TensorboardExperiment: """Create an experiment or get an experiment. @@ -271,6 +287,7 @@ def _create_or_get_experiment(self) -> tensorboard_experiment.TensorboardExperim tensorboard_experiment=tb_experiment, tensorboard_experiment_id=self._experiment_name, ) + self._is_brand_new_experiment = True except exceptions.AlreadyExists: logger.info("Creating experiment failed. Retrieving experiment.") experiment_name = os.path.join( @@ -284,6 +301,10 @@ def create_experiment(self): experiment = self._create_or_get_experiment() self._experiment = experiment + self._one_platform_resource_manager = uploader_utils.OnePlatformResourceManager( + self._experiment.name, self._api + ) + self._request_sender = _BatchedRequestSender( self._experiment.name, self._api, @@ -294,9 +315,48 @@ def create_experiment(self): blob_rpc_rate_limiter=self._blob_rpc_rate_limiter, blob_storage_bucket=self._blob_storage_bucket, blob_storage_folder=self._blob_storage_folder, + one_platform_resource_manager=self._one_platform_resource_manager, tracker=self._tracker, ) + # Update partials with experiment name + for sender in self._additional_senders.keys(): + self._additional_senders[sender] = self._additional_senders[sender]( + experiment_resource_name=self._experiment.name, + ) + + self._dispatcher = _Dispatcher( + request_sender=self._request_sender, + additional_senders=self._additional_senders, + ) + + def _create_additional_senders(self) -> Dict[str, uploader_utils.RequestSender]: + """Create any additional senders for non traditional event files. + + Some items that are used for plugins do not process typical event files, + but need to be searched for and stored so that they can be used by the + plugin. If there are any items that cannot be searched for via the + `_BatchedRequestSender`, add them here. + """ + if "profile" in self._allowed_plugins: + if not self._one_shot: + raise ValueError( + "Profile plugin currently only supported for one shot." + ) + source_bucket = uploader_utils.get_source_bucket(self._logdir) + + self._additional_senders["profile"] = functools.partial( + profile_uploader.ProfileRequestSender, + api=self._api, + upload_limits=self._upload_limits, + blob_rpc_rate_limiter=self._blob_rpc_rate_limiter, + blob_storage_bucket=self._blob_storage_bucket, + blob_storage_folder=self._blob_storage_folder, + source_bucket=source_bucket, + tracker=self._tracker, + logdir=self._logdir, + ) + def get_experiment_resource_name(self): return self._experiment.name @@ -308,8 +368,19 @@ def start_uploading(self): ExperimentNotFoundError: If the experiment is deleted during the course of the upload. """ - if self._request_sender is None: + if self._dispatcher is None: raise RuntimeError("Must call create_experiment() before start_uploading()") + + if self._one_shot: + if self._is_brand_new_experiment: + self._pre_create_runs_and_time_series() + else: + logger.warning( + "Please consider uploading to a new experiment instead of " + "an existing one, as the former allows for better upload " + "performance." + ) + while True: self._logdir_poll_rate_limiter.tick() self._upload_once() @@ -321,6 +392,58 @@ def start_uploading(self): "without any uploadable data" % self._logdir ) + def _pre_create_runs_and_time_series(self): + """ + Iterates though the log dir to collect TensorboardRuns and + TensorboardTimeSeries that need to be created, and creates them in batch + to speed up uploading later on. + """ + self._logdir_loader_pre_create.synchronize_runs() + run_to_events = self._logdir_loader_pre_create.get_run_events() + if self._run_name_prefix: + run_to_events = { + self._run_name_prefix + k: v for k, v in run_to_events.items() + } + + run_names = [] + run_tag_name_to_time_series_proto = {} + for (run_name, events) in run_to_events.items(): + run_names.append(run_name) + for event in events: + _filter_graph_defs(event) + for value in event.summary.value: + metadata, is_valid = self._request_sender.get_metadata_and_validate( + run_name, value + ) + if not is_valid: + continue + if metadata.data_class == summary_pb2.DATA_CLASS_SCALAR: + value_type = ( + tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR + ) + elif metadata.data_class == summary_pb2.DATA_CLASS_TENSOR: + value_type = ( + tensorboard_time_series.TensorboardTimeSeries.ValueType.TENSOR + ) + elif metadata.data_class == summary_pb2.DATA_CLASS_BLOB_SEQUENCE: + value_type = ( + tensorboard_time_series.TensorboardTimeSeries.ValueType.BLOB_SEQUENCE + ) + + run_tag_name_to_time_series_proto[ + (run_name, value.tag) + ] = tensorboard_time_series.TensorboardTimeSeries( + display_name=value.tag, + value_type=value_type, + plugin_name=metadata.plugin_data.plugin_name, + plugin_data=metadata.plugin_data.content, + ) + + self._one_platform_resource_manager.batch_create_runs(run_names) + self._one_platform_resource_manager.batch_create_time_series( + run_tag_name_to_time_series_proto + ) + def _upload_once(self): """Runs one upload cycle, sending zero or more RPCs.""" logger.info("Starting an upload cycle") @@ -336,19 +459,15 @@ def _upload_once(self): self._run_name_prefix + k: v for k, v in run_to_events.items() } with self._tracker.send_tracker(): - self._request_sender.send_requests(run_to_events) - - -class ExperimentNotFoundError(RuntimeError): - pass + self._dispatcher.dispatch_requests(run_to_events) class PermissionDeniedError(RuntimeError): pass -class ExistingResourceNotFoundError(RuntimeError): - """Resource could not be created or retrieved.""" +class ExperimentNotFoundError(RuntimeError): + pass class _OutOfSpaceError(Exception): @@ -387,6 +506,7 @@ def __init__( blob_rpc_rate_limiter: util.RateLimiter, blob_storage_bucket: storage.Bucket, blob_storage_folder: str, + one_platform_resource_manager: uploader_utils.OnePlatformResourceManager, tracker: upload_tracker.UploadTracker, ): """Constructs _BatchedRequestSender for the given experiment resource. @@ -404,6 +524,8 @@ def __init__( Note the chunk stream is internally rate-limited by backpressure from the server, so it is not a concern that we do not explicitly rate-limit within the stream here. + one_platform_resource_manager: An instance of the One Platform + resource management class. tracker: Upload tracker to track information about uploads. """ self._experiment_resource_name = experiment_resource_name @@ -411,27 +533,26 @@ def __init__( self._tag_metadata = {} self._allowed_plugins = frozenset(allowed_plugins) self._tracker = tracker - self._run_to_request_sender: Dict[str, _ScalarBatchedRequestSender] = {} - self._run_to_tensor_request_sender: Dict[str, _TensorBatchedRequestSender] = {} - self._run_to_blob_request_sender: Dict[str, _BlobRequestSender] = {} - self._run_to_run_resource: Dict[str, tensorboard_run.TensorboardRun] = {} - self._scalar_request_sender_factory = functools.partial( - _ScalarBatchedRequestSender, + self._one_platform_resource_manager = one_platform_resource_manager + self._scalar_request_sender = _ScalarBatchedRequestSender( + experiment_resource_id=experiment_resource_name, api=api, rpc_rate_limiter=rpc_rate_limiter, max_request_size=upload_limits.max_scalar_request_size, tracker=self._tracker, + one_platform_resource_manager=self._one_platform_resource_manager, ) - self._tensor_request_sender_factory = functools.partial( - _TensorBatchedRequestSender, + self._tensor_request_sender = _TensorBatchedRequestSender( + experiment_resource_id=experiment_resource_name, api=api, rpc_rate_limiter=tensor_rpc_rate_limiter, max_request_size=upload_limits.max_tensor_request_size, max_tensor_point_size=upload_limits.max_tensor_point_size, tracker=self._tracker, + one_platform_resource_manager=self._one_platform_resource_manager, ) - self._blob_request_sender_factory = functools.partial( - _BlobRequestSender, + self._blob_request_sender = _BlobRequestSender( + experiment_resource_id=experiment_resource_name, api=api, rpc_rate_limiter=blob_rpc_rate_limiter, max_blob_request_size=upload_limits.max_blob_request_size, @@ -439,10 +560,14 @@ def __init__( blob_storage_bucket=blob_storage_bucket, blob_storage_folder=blob_storage_folder, tracker=self._tracker, + one_platform_resource_manager=self._one_platform_resource_manager, ) - def send_requests( - self, run_to_events: Dict[str, Generator[tf.compat.v1.Event, None, None]] + def send_request( + self, + run_name: str, + event: tf.compat.v1.Event, + value: tf.compat.v1.Summary.Value, ): """Accepts a stream of TF events and sends batched write RPCs. @@ -450,127 +575,127 @@ def send_requests( the type of data (Scalar vs Tensor vs Blob) being sent. Args: - run_to_events: Mapping from run name to generator of `tf.compat.v1.Event` - values, as returned by `LogdirLoader.get_run_events`. + run_name: Name of the run retrieved by `LogdirLoader.get_run_events` + event: The `tf.compat.v1.Event` for the run + value: A single `tf.compat.v1.Summary.Value` from the event, where + there can be multiple values per event. Raises: RuntimeError: If no progress can be made because even a single point is too large (say, due to a gigabyte-long tag name). """ + metadata, is_valid = self.get_metadata_and_validate(run_name, value) + if not is_valid: + return + plugin_name = metadata.plugin_data.plugin_name + self._tracker.add_plugin_name(plugin_name) - for (run_name, event, value) in self._run_values(run_to_events): - time_series_key = (run_name, value.tag) - - # The metadata for a time series is memorized on the first event. - # If later events arrive with a mismatching plugin_name, they are - # ignored with a warning. - metadata = self._tag_metadata.get(time_series_key) - first_in_time_series = False - if metadata is None: - first_in_time_series = True - metadata = value.metadata - self._tag_metadata[time_series_key] = metadata - - plugin_name = metadata.plugin_data.plugin_name - if value.HasField("metadata") and ( - plugin_name != value.metadata.plugin_data.plugin_name - ): - logger.warning( - "Mismatching plugin names for %s. Expected %s, found %s.", + if metadata.data_class == summary_pb2.DATA_CLASS_SCALAR: + self._scalar_request_sender.add_event(run_name, event, value, metadata) + elif metadata.data_class == summary_pb2.DATA_CLASS_TENSOR: + self._tensor_request_sender.add_event(run_name, event, value, metadata) + elif metadata.data_class == summary_pb2.DATA_CLASS_BLOB_SEQUENCE: + self._blob_request_sender.add_event(run_name, event, value, metadata) + + def flush(self): + """Flushes any events that have been stored.""" + self._scalar_request_sender.flush() + self._tensor_request_sender.flush() + self._blob_request_sender.flush() + + def get_metadata_and_validate( + self, run_name: str, value: tf.compat.v1.Summary.Value + ) -> Tuple[tf.compat.v1.SummaryMetadata, bool]: + """ + + :param run_name: Name of the run retrieved by + `LogdirLoader.get_run_events` + :param value: A single `tf.compat.v1.Summary.Value` from the event, + where there can be multiple values per event. + :return: (metadata, is_valid): a metadata derived from the value, and + whether the value itself is valid. + """ + + time_series_key = (run_name, value.tag) + + # The metadata for a time series is memorized on the first event. + # If later events arrive with a mismatching plugin_name, they are + # ignored with a warning. + metadata = self._tag_metadata.get(time_series_key) + first_in_time_series = False + if metadata is None: + first_in_time_series = True + metadata = value.metadata + self._tag_metadata[time_series_key] = metadata + + plugin_name = metadata.plugin_data.plugin_name + if value.HasField("metadata") and ( + plugin_name != value.metadata.plugin_data.plugin_name + ): + logger.warning( + "Mismatching plugin names for %s. Expected %s, found %s.", + time_series_key, + metadata.plugin_data.plugin_name, + value.metadata.plugin_data.plugin_name, + ) + return metadata, False + if plugin_name not in self._allowed_plugins: + if first_in_time_series: + logger.info( + "Skipping time series %r with unsupported plugin name %r", time_series_key, - metadata.plugin_data.plugin_name, - value.metadata.plugin_data.plugin_name, - ) - continue - if plugin_name not in self._allowed_plugins: - if first_in_time_series: - logger.info( - "Skipping time series %r with unsupported plugin name %r", - time_series_key, - plugin_name, - ) - continue - self._tracker.add_plugin_name(plugin_name) - # If this is the first time we've seen this run create a new run resource - # and an associated request sender. - if run_name not in self._run_to_run_resource: - self._create_or_get_run_resource(run_name) - self._run_to_request_sender[ - run_name - ] = self._scalar_request_sender_factory( - self._run_to_run_resource[run_name].name - ) - self._run_to_tensor_request_sender[ - run_name - ] = self._tensor_request_sender_factory( - self._run_to_run_resource[run_name].name - ) - self._run_to_blob_request_sender[ - run_name - ] = self._blob_request_sender_factory( - self._run_to_run_resource[run_name].name + plugin_name, ) + return metadata, False + return metadata, True - if metadata.data_class == summary_pb2.DATA_CLASS_SCALAR: - self._run_to_request_sender[run_name].add_event(event, value, metadata) - elif metadata.data_class == summary_pb2.DATA_CLASS_TENSOR: - self._run_to_tensor_request_sender[run_name].add_event( - event, value, metadata - ) - elif metadata.data_class == summary_pb2.DATA_CLASS_BLOB_SEQUENCE: - self._run_to_blob_request_sender[run_name].add_event( - event, value, metadata - ) - for scalar_request_sender in self._run_to_request_sender.values(): - scalar_request_sender.flush() +class _Dispatcher(object): + """Dispatch the requests to the correct request senders.""" - for tensor_request_sender in self._run_to_tensor_request_sender.values(): - tensor_request_sender.flush() + def __init__( + self, + request_sender: _BatchedRequestSender, + additional_senders: Optional[Dict[str, uploader_utils.RequestSender]] = None, + ): + """Construct a _Dispatcher object for the TensorboardUploader. - for blob_request_sender in self._run_to_blob_request_sender.values(): - blob_request_sender.flush() + Args: + request_sender: A `_BatchedRequestSender` for handling events. + additional_senders: A dictionary mapping a plugin name to additional + Senders. + """ + self._request_sender = request_sender - def _create_or_get_run_resource(self, run_name: str): - """Creates a new Run Resource in current Tensorboard Experiment resource. + if not additional_senders: + additional_senders = {} + self._additional_senders = additional_senders + + def _dispatch_additional_senders( + self, + run_name: str, + ): + """Dispatch events to any additional senders. + + These senders process non traditional event files for a specific plugin + and use a send_request function to process events. Args: - run_name: The display name of this run. + run_name: String of current training run """ - tb_run = tensorboard_run.TensorboardRun() - tb_run.display_name = run_name - try: - tb_run = self._api.create_tensorboard_run( - parent=self._experiment_resource_name, - tensorboard_run=tb_run, - tensorboard_run_id=str(uuid.uuid4()), - ) - except exceptions.InvalidArgument as e: - # If the run name already exists then retrieve it - if "already exist" in e.message: - runs_pages = self._api.list_tensorboard_runs( - parent=self._experiment_resource_name - ) - for tb_run in runs_pages: - if tb_run.display_name == run_name: - break - - if tb_run.display_name != run_name: - raise ExistingResourceNotFoundError( - "Run with name %s already exists but is not resource list." - % run_name - ) - else: - raise - - self._run_to_run_resource[run_name] = tb_run + for key, sender in self._additional_senders.items(): + sender.send_request(run_name) - def _run_values( + def dispatch_requests( self, run_to_events: Dict[str, Generator[tf.compat.v1.Event, None, None]] - ) -> Generator[ - Tuple[str, tf.compat.v1.Event, tf.compat.v1.Summary.Value], None, None - ]: - """Helper generator to create a single stream of work items. + ): + """Routes events to the appropriate sender. + + Takes a mapping from strings to an event generator. The function routes + any events that should be handled by the `_BatchedRequestSender` and + non-traditional events that need to be handled differently, which are + stored as "_additional_senders". The `_request_sender` is then flushed + after all events are added. Note that `dataclass_compat` may emit multiple variants of the same event, for backwards compatibility. Thus this stream should @@ -586,92 +711,17 @@ def _run_values( Args: run_to_events: Mapping from run name to generator of `tf.compat.v1.Event` values, as returned by `LogdirLoader.get_run_events`. - - Yields: - Tuple of run name, tf.compat.v1.Event, tf.compat.v1.Summary.Value per - value. """ - # Note that this join in principle has deletion anomalies: if the input - # stream contains runs with no events, or events with no values, we'll - # lose that information. This is not a problem: we would need to prune - # such data from the request anyway. for (run_name, events) in run_to_events.items(): + self._dispatch_additional_senders(run_name) for event in events: _filter_graph_defs(event) for value in event.summary.value: - yield (run_name, event, value) - - -class _TimeSeriesResourceManager(object): - """Helper class managing Time Series resources.""" - - def __init__(self, run_resource_id: str, api: TensorboardServiceClient): - """Constructor for _TimeSeriesResourceManager. - - Args: - run_resource_id: The resource id for the run with the following format - projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run} - api: TensorboardServiceStub - """ - self._run_resource_id = run_resource_id - self._api = api - self._tag_to_time_series_proto: Dict[ - str, tensorboard_time_series.TensorboardTimeSeries - ] = {} - - def get_or_create( - self, - tag_name: str, - time_series_resource_creator: Callable[ - [], tensorboard_time_series.TensorboardTimeSeries - ], - ) -> tensorboard_time_series.TensorboardTimeSeries: - """get a time series resource with given tag_name, and create a new one on - - OnePlatform if not present. - - Args: - tag_name: The tag name of the time series in the Tensorboard log dir. - time_series_resource_creator: A callable that produces a TimeSeries for - creation. - """ - if tag_name in self._tag_to_time_series_proto: - return self._tag_to_time_series_proto[tag_name] - - time_series = time_series_resource_creator() - time_series.display_name = tag_name - try: - time_series = self._api.create_tensorboard_time_series( - parent=self._run_resource_id, tensorboard_time_series=time_series - ) - except exceptions.InvalidArgument as e: - # If the time series display name already exists then retrieve it - if "already exist" in e.message: - list_of_time_series = self._api.list_tensorboard_time_series( - request=tensorboard_service.ListTensorboardTimeSeriesRequest( - parent=self._run_resource_id, - filter="display_name = {}".format(json.dumps(str(tag_name))), - ) - ) - num = 0 - for ts in list_of_time_series: - time_series = ts - num += 1 - break - if num != 1: - raise ValueError( - "More than one time series resource found with display_name: {}".format( - tag_name - ) - ) - else: - raise - - self._tag_to_time_series_proto[tag_name] = time_series - return time_series + self._request_sender.send_request(run_name, event, value) + self._request_sender.flush() -class _ScalarBatchedRequestSender(object): +class _BaseBatchedRequestSender(object): """Helper class for building requests that fit under a size limit. This class accumulates a current request. `add_event(...)` may or may not @@ -684,47 +734,49 @@ class _ScalarBatchedRequestSender(object): def __init__( self, - run_resource_id: str, + experiment_resource_id: str, api: TensorboardServiceClient, rpc_rate_limiter: util.RateLimiter, max_request_size: int, tracker: upload_tracker.UploadTracker, + one_platform_resource_manager: uploader_utils.OnePlatformResourceManager, ): - """Constructer for _ScalarBatchedRequestSender. + """Constructor for _BaseBatchedRequestSender. Args: - run_resource_id: The resource id for the run with the following format - projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run} + experiment_resource_id: The resource id for the experiment with the following format + projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment} api: TensorboardServiceStub rpc_rate_limiter: until.RateLimiter to limit rate of this request sender max_request_size: max number of bytes to send tracker: """ - self._run_resource_id = run_resource_id + self._experiment_resource_id = experiment_resource_id self._api = api self._rpc_rate_limiter = rpc_rate_limiter self._byte_budget_manager = _ByteBudgetManager(max_request_size) self._tracker = tracker + self._one_platform_resource_manager = one_platform_resource_manager # cache: map from Tensorboard tag to TimeSeriesData # cleared whenever a new request is created - self._tag_to_time_series_data: Dict[str, tensorboard_data.TimeSeriesData] = {} - - self._time_series_resource_manager = _TimeSeriesResourceManager( - self._run_resource_id, self._api - ) + self._run_to_tag_to_time_series_data: Dict[ + str, Dict[str, tensorboard_data.TimeSeriesData] + ] = defaultdict(defaultdict) self._new_request() def _new_request(self): """Allocates a new request and refreshes the budget.""" - self._request = tensorboard_service.WriteTensorboardRunDataRequest() - self._tag_to_time_series_data.clear() + self._request = tensorboard_service.WriteTensorboardExperimentDataRequest( + tensorboard_experiment=self._experiment_resource_id + ) + self._run_to_tag_to_time_series_data.clear() self._num_values = 0 - self._request.tensorboard_run = self._run_resource_id self._byte_budget_manager.reset(self._request) def add_event( self, + run_name: str, event: tf.compat.v1.Event, value: tf.compat.v1.Summary.Value, metadata: tf.compat.v1.SummaryMetadata, @@ -741,27 +793,32 @@ def add_event( metadata: SummaryMetadata of the event. """ try: - self._add_event_internal(event, value, metadata) + self._add_event_internal(run_name, event, value, metadata) except _OutOfSpaceError: self.flush() # Try again. This attempt should never produce OutOfSpaceError # because we just flushed. try: - self._add_event_internal(event, value, metadata) + self._add_event_internal(run_name, event, value, metadata) except _OutOfSpaceError: raise RuntimeError("add_event failed despite flush") def _add_event_internal( self, + run_name: str, event: tf.compat.v1.Event, value: tf.compat.v1.Summary.Value, metadata: tf.compat.v1.SummaryMetadata, ): self._num_values += 1 - time_series_data_proto = self._tag_to_time_series_data.get(value.tag) + time_series_data_proto = self._run_to_tag_to_time_series_data[run_name].get( + value.tag + ) if time_series_data_proto is None: - time_series_data_proto = self._create_time_series_data(value.tag, metadata) - self._create_point(time_series_data_proto, event, value) + time_series_data_proto = self._create_time_series_data( + run_name, value.tag, metadata + ) + self._create_point(run_name, time_series_data_proto, event, value, metadata) def flush(self): """Sends the active request after removing empty runs and tags. @@ -769,19 +826,34 @@ def flush(self): Starts a new, empty active request. """ request = self._request - request.time_series_data = list(self._tag_to_time_series_data.values()) - _prune_empty_time_series(request) - if not request.time_series_data: + has_data = False + for ( + run_name, + tag_to_time_series_data, + ) in self._run_to_tag_to_time_series_data.items(): + r = tensorboard_service.WriteTensorboardRunDataRequest( + tensorboard_run=self._one_platform_resource_manager.get_run_resource_name( + run_name + ) + ) + r.time_series_data = list(tag_to_time_series_data.values()) + _prune_empty_time_series(r) + if not r.time_series_data: + continue + request.write_run_data_requests.extend([r]) + has_data = True + + if not has_data: return self._rpc_rate_limiter.tick() - with _request_logger(request): - with self._tracker.scalars_tracker(self._num_values): + with uploader_utils.request_logger(request): + with self._get_tracker(): try: - self._api.write_tensorboard_run_data( - tensorboard_run=self._run_resource_id, - time_series_data=request.time_series_data, + self._api.write_tensorboard_experiment_data( + tensorboard_experiment=request.tensorboard_experiment, + write_run_data_requests=request.write_run_data_requests, ) except grpc.RpcError as e: if ( @@ -794,7 +866,7 @@ def flush(self): self._new_request() def _create_time_series_data( - self, tag_name: str, metadata: tf.compat.v1.SummaryMetadata + self, run_name: str, tag_name: str, metadata: tf.compat.v1.SummaryMetadata ) -> tensorboard_data.TimeSeriesData: """Adds a time_series for the tag_name, if there's space. @@ -808,52 +880,55 @@ def _create_time_series_data( _OutOfSpaceError: If adding the tag would exceed the remaining request budget. """ - time_series_data_proto = tensorboard_data.TimeSeriesData( - tensorboard_time_series_id=self._time_series_resource_manager.get_or_create( + time_series_resource_name = ( + self._one_platform_resource_manager.get_time_series_resource_name( + run_name, tag_name, lambda: tensorboard_time_series.TensorboardTimeSeries( display_name=tag_name, - value_type=tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR, + value_type=self._value_type, plugin_name=metadata.plugin_data.plugin_name, plugin_data=metadata.plugin_data.content, ), - ).name.split("/")[-1], - value_type=tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR, + ) + ) + + time_series_data_proto = tensorboard_data.TimeSeriesData( + tensorboard_time_series_id=time_series_resource_name.split("/")[-1], + value_type=self._value_type, ) - self._request.time_series_data.extend([time_series_data_proto]) self._byte_budget_manager.add_time_series(time_series_data_proto) - self._tag_to_time_series_data[tag_name] = time_series_data_proto + self._run_to_tag_to_time_series_data[run_name][ + tag_name + ] = time_series_data_proto return time_series_data_proto def _create_point( self, + run_name: str, time_series_proto: tensorboard_data.TimeSeriesData, event: tf.compat.v1.Event, value: tf.compat.v1.Summary.Value, + metadata: tf.compat.v1.SummaryMetadata, ): """Adds a scalar point to the given tag, if there's space. Args: time_series_proto: TimeSeriesData proto to which to add a point. event: Enclosing `Event` proto with the step and wall time data. - value: Scalar `Summary.Value` proto with the actual scalar data. + value: `Summary.Value` proto. + metadata: SummaryMetadata of the event. Raises: _OutOfSpaceError: If adding the point would exceed the remaining request budget. """ - scalar_proto = tensorboard_data.Scalar( - value=tensor_util.make_ndarray(value.tensor).item() - ) - point = tensorboard_data.TimeSeriesDataPoint( - step=event.step, - scalar=scalar_proto, - wall_time=timestamp.Timestamp( - seconds=int(event.wall_time), - nanos=int(round((event.wall_time % 1) * 10 ** 9)), - ), - ) + point = self._create_data_point(run_name, event, value, metadata) + + if not self._validate(point, event, value): + return + time_series_proto.values.extend([point]) try: self._byte_budget_manager.add_point(point) @@ -861,193 +936,196 @@ def _create_point( time_series_proto.values.pop() raise + @abc.abstractmethod + def _get_tracker(self) -> ContextManager: + """ + :return: tracker function from upload_tracker.UploadTracker + """ + pass + + @property + @classmethod + @abc.abstractmethod + def _value_type( + cls, + ) -> tensorboard_time_series.TensorboardTimeSeries.ValueType: + """ + :return: Value type of the time series. + """ + pass -class _TensorBatchedRequestSender(object): - """Helper class for building WriteTensor() requests that fit under a size limit. + @abc.abstractmethod + def _create_data_point( + self, + run_name: str, + event: tf.compat.v1.Event, + value: tf.compat.v1.Summary.Value, + metadata: tf.compat.v1.SummaryMetadata, + ) -> tensorboard_data.TimeSeriesDataPoint: + """ + Creates data point protos for sending to the OnePlatform API. + """ + pass + + def _validate( + self, + point: tensorboard_data.TimeSeriesDataPoint, + event: tf.compat.v1.Event, + value: tf.compat.v1.Summary.Value, + ): + """ + Validations performed before including the data point to be sent to the + OnePlatform API. + """ + return True + + +class _ScalarBatchedRequestSender(_BaseBatchedRequestSender): + """Helper class for building requests that fit under a size limit. This class accumulates a current request. `add_event(...)` may or may not send the request (and start a new one). After all `add_event(...)` calls are complete, a final call to `flush()` is needed to send the final request. + This class is not threadsafe. Use external synchronization if calling its methods concurrently. """ + _value_type = tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR + def __init__( self, - run_resource_id: str, + experiment_resource_id: str, api: TensorboardServiceClient, rpc_rate_limiter: util.RateLimiter, max_request_size: int, - max_tensor_point_size: int, tracker: upload_tracker.UploadTracker, + one_platform_resource_manager: uploader_utils.OnePlatformResourceManager, ): - """Constructer for _TensorBatchedRequestSender. + """Constructor for _ScalarBatchedRequestSender. Args: - run_resource_id: The resource id for the run with the following format - projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run} + experiment_resource_id: The resource id for the experiment with the following format + projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment} api: TensorboardServiceStub rpc_rate_limiter: until.RateLimiter to limit rate of this request sender max_request_size: max number of bytes to send tracker: """ - self._run_resource_id = run_resource_id - self._api = api - self._rpc_rate_limiter = rpc_rate_limiter - self._byte_budget_manager = _ByteBudgetManager(max_request_size) - self._max_tensor_point_size = max_tensor_point_size - self._tracker = tracker - - # cache: map from Tensorboard tag to TimeSeriesData - # cleared whenever a new request is created - self._tag_to_time_series_data: Dict[str, tensorboard_data.TimeSeriesData] = {} - - self._time_series_resource_manager = _TimeSeriesResourceManager( - run_resource_id, api + super().__init__( + experiment_resource_id, + api, + rpc_rate_limiter, + max_request_size, + tracker, + one_platform_resource_manager, ) - self._new_request() - - def _new_request(self): - """Allocates a new request and refreshes the budget.""" - self._request = tensorboard_service.WriteTensorboardRunDataRequest() - self._tag_to_time_series_data.clear() - self._num_values = 0 - self._request.tensorboard_run = self._run_resource_id - self._byte_budget_manager.reset(self._request) - self._num_values = 0 - self._num_values_skipped = 0 - self._tensor_bytes = 0 - self._tensor_bytes_skipped = 0 - - def add_event( - self, - event: tf.compat.v1.Event, - value: tf.compat.v1.Summary.Value, - metadata: tf.compat.v1.SummaryMetadata, - ): - """Attempts to add the given event to the current request. - If the event cannot be added to the current request because the byte - budget is exhausted, the request is flushed, and the event is added - to the next request. - """ - try: - self._add_event_internal(event, value, metadata) - except _OutOfSpaceError: - self.flush() - # Try again. This attempt should never produce OutOfSpaceError - # because we just flushed. - try: - self._add_event_internal(event, value, metadata) - except _OutOfSpaceError: - raise RuntimeError("add_event failed despite flush") + def _get_tracker(self) -> ContextManager: + return self._tracker.scalars_tracker(self._num_values) - def _add_event_internal( + def _create_data_point( self, + run_name: str, event: tf.compat.v1.Event, value: tf.compat.v1.Summary.Value, metadata: tf.compat.v1.SummaryMetadata, - ): - self._num_values += 1 - time_series_data_proto = self._tag_to_time_series_data.get(value.tag) - if time_series_data_proto is None: - time_series_data_proto = self._create_time_series_data(value.tag, metadata) - self._create_point(time_series_data_proto, event, value) - - def flush(self): - """Sends the active request after removing empty runs and tags. + ) -> tensorboard_data.TimeSeriesDataPoint: + scalar_proto = tensorboard_data.Scalar( + value=tensor_util.make_ndarray(value.tensor).item() + ) + return tensorboard_data.TimeSeriesDataPoint( + step=event.step, + scalar=scalar_proto, + wall_time=timestamp.Timestamp( + seconds=int(event.wall_time), + nanos=int(round((event.wall_time % 1) * 10**9)), + ), + ) - Starts a new, empty active request. - """ - request = self._request - request.time_series_data = list(self._tag_to_time_series_data.values()) - _prune_empty_time_series(request) - if not request.time_series_data: - return - self._rpc_rate_limiter.tick() +class _TensorBatchedRequestSender(_BaseBatchedRequestSender): + """Helper class for building WriteTensor() requests that fit under a size limit. - with _request_logger(request): - with self._tracker.tensors_tracker( - self._num_values, - self._num_values_skipped, - self._tensor_bytes, - self._tensor_bytes_skipped, - ): - try: - self._api.write_tensorboard_run_data( - tensorboard_run=self._run_resource_id, - time_series_data=request.time_series_data, - ) - except grpc.RpcError as e: - if e.code() == grpc.StatusCode.NOT_FOUND: - raise ExperimentNotFoundError() - logger.error("Upload call failed with error %s", e) + This class accumulates a current request. `add_event(...)` may or may not + send the request (and start a new one). After all `add_event(...)` calls + are complete, a final call to `flush()` is needed to send the final request. + This class is not threadsafe. Use external synchronization if calling its + methods concurrently. + """ - self._new_request() + _value_type = tensorboard_time_series.TensorboardTimeSeries.ValueType.TENSOR - def _create_time_series_data( - self, tag_name: str, metadata: tf.compat.v1.SummaryMetadata - ) -> tensorboard_data.TimeSeriesData: - """Adds a time_series for the tag_name, if there's space. + def __init__( + self, + experiment_resource_id: str, + api: TensorboardServiceClient, + rpc_rate_limiter: util.RateLimiter, + max_request_size: int, + max_tensor_point_size: int, + tracker: upload_tracker.UploadTracker, + one_platform_resource_manager: uploader_utils.OnePlatformResourceManager, + ): + """Constructor for _TensorBatchedRequestSender. Args: - tag_name: String name of the tag to add (as `value.tag`). - metadata: SummaryMetadata of the event. - - Returns: - The TimeSeriesData in _request proto with the given tag name. - - Raises: - _OutOfSpaceError: If adding the tag would exceed the remaining - request budget. + experiment_resource_id: The resource id for the experiment with the following format + projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment} + api: TensorboardServiceStub + rpc_rate_limiter: until.RateLimiter to limit rate of this request sender + max_request_size: max number of bytes to send + tracker: """ - time_series_data_proto = tensorboard_data.TimeSeriesData( - tensorboard_time_series_id=self._time_series_resource_manager.get_or_create( - tag_name, - lambda: tensorboard_time_series.TensorboardTimeSeries( - display_name=tag_name, - value_type=tensorboard_time_series.TensorboardTimeSeries.ValueType.TENSOR, - plugin_name=metadata.plugin_data.plugin_name, - plugin_data=metadata.plugin_data.content, - ), - ).name.split("/")[-1], - value_type=tensorboard_time_series.TensorboardTimeSeries.ValueType.TENSOR, + super().__init__( + experiment_resource_id, + api, + rpc_rate_limiter, + max_request_size, + tracker, + one_platform_resource_manager, ) + self._max_tensor_point_size = max_tensor_point_size - self._request.time_series_data.extend([time_series_data_proto]) - self._byte_budget_manager.add_time_series(time_series_data_proto) - self._tag_to_time_series_data[tag_name] = time_series_data_proto - return time_series_data_proto + def _new_request(self): + """Allocates a new request and refreshes the budget.""" + super()._new_request() + self._num_values = 0 + self._num_values_skipped = 0 + self._tensor_bytes = 0 + self._tensor_bytes_skipped = 0 - def _create_point( + def _get_tracker(self) -> ContextManager: + return self._tracker.tensors_tracker( + self._num_values, + self._num_values_skipped, + self._tensor_bytes, + self._tensor_bytes_skipped, + ) + + def _create_data_point( self, - time_series_proto: tensorboard_data.TimeSeriesData, + run_name: str, event: tf.compat.v1.Event, value: tf.compat.v1.Summary.Value, - ): - """Adds a tensor point to the given tag, if there's space. - - Args: - tag_proto: `WriteTensorRequest.Tag` proto to which to add a point. - event: Enclosing `Event` proto with the step and wall time data. - value: Tensor `Summary.Value` proto with the actual tensor data. - - Raises: - _OutOfSpaceError: If adding the point would exceed the remaining - request budget. - """ - point = tensorboard_data.TimeSeriesDataPoint( + metadata: tf.compat.v1.SummaryMetadata, + ) -> tensorboard_data.TimeSeriesDataPoint: + return tensorboard_data.TimeSeriesDataPoint( step=event.step, tensor=tensorboard_data.TensorboardTensor( value=value.tensor.SerializeToString() ), wall_time=timestamp.Timestamp( seconds=int(event.wall_time), - nanos=int(round((event.wall_time % 1) * 10 ** 9)), + nanos=int(round((event.wall_time % 1) * 10**9)), ), ) + def _validate( + self, + point: tensorboard_data.TimeSeriesDataPoint, + event: tf.compat.v1.Event, + value: tf.compat.v1.Summary.Value, + ): self._num_values += 1 tensor_size = len(point.tensor.value) self._tensor_bytes += tensor_size @@ -1059,32 +1137,19 @@ def _create_point( ) self._num_values_skipped += 1 self._tensor_bytes_skipped += tensor_size - return - - self._validate_tensor_value( - value.tensor, value.tag, event.step, event.wall_time - ) - - time_series_proto.values.extend([point]) + return False try: - self._byte_budget_manager.add_point(point) - except _OutOfSpaceError: - time_series_proto.values.pop() - raise - - def _validate_tensor_value(self, tensor_proto, tag, step, wall_time): - """Validate a TensorProto by attempting to parse it.""" - try: - tensor_util.make_ndarray(tensor_proto) + tensor_util.make_ndarray(value.tensor) except ValueError as error: raise ValueError( "The uploader failed to upload a tensor. This seems to be " "due to a malformation in the tensor, which may be caused by " "a bug in the process that wrote the tensor.\n\n" "The tensor has tag '%s' and is at step %d and wall_time %.6f.\n\n" - "Original error:\n%s" % (tag, step, wall_time, error) + "Original error:\n%s" % (value.tag, event.step, event.wall_time, error) ) + return True class _ByteBudgetManager(object): @@ -1108,7 +1173,9 @@ def __init__(self, max_bytes: int): self._byte_budget = None # type: int self._max_bytes = max_bytes - def reset(self, base_request: tensorboard_service.WriteTensorboardRunDataRequest): + def reset( + self, base_request: tensorboard_service.WriteTensorboardExperimentDataRequest + ): """Resets the byte budget and calculates the cost of the base request. Args: @@ -1176,7 +1243,7 @@ def add_point(self, point_proto: tensorboard_data.TimeSeriesDataPoint): self._byte_budget -= cost -class _BlobRequestSender(object): +class _BlobRequestSender(_BaseBatchedRequestSender): """Uploader for blob-type event data. Unlike the other types, this class does not accumulate events in batches; @@ -1187,9 +1254,11 @@ class _BlobRequestSender(object): methods concurrently. """ + _value_type = tensorboard_time_series.TensorboardTimeSeries.ValueType.BLOB_SEQUENCE + def __init__( self, - run_resource_id: str, + experiment_resource_id: str, api: TensorboardServiceClient, rpc_rate_limiter: util.RateLimiter, max_blob_request_size: int, @@ -1197,79 +1266,59 @@ def __init__( blob_storage_bucket: storage.Bucket, blob_storage_folder: str, tracker: upload_tracker.UploadTracker, + one_platform_resource_manager: uploader_utils.OnePlatformResourceManager, ): - self._run_resource_id = run_resource_id - self._api = api - self._rpc_rate_limiter = rpc_rate_limiter - self._max_blob_request_size = max_blob_request_size - self._max_blob_size = max_blob_size - self._tracker = tracker - self._time_series_resource_manager = _TimeSeriesResourceManager( - run_resource_id, api + super().__init__( + experiment_resource_id, + api, + rpc_rate_limiter, + max_blob_request_size, + tracker, + one_platform_resource_manager, ) - + self._max_blob_size = max_blob_size self._bucket = blob_storage_bucket self._folder = blob_storage_folder - self._new_request() - def _new_request(self): - """Declares the previous event complete.""" - self._event = None - self._value = None - self._metadata = None + super()._new_request() + self._blob_sizes = 0 - def add_event( + def _get_tracker(self) -> ContextManager: + return self._tracker.blob_tracker(0) + + def _create_data_point( self, + run_name: str, event: tf.compat.v1.Event, value: tf.compat.v1.Summary.Value, metadata: tf.compat.v1.SummaryMetadata, - ): - """Attempts to add the given event to the current request. - - If the event cannot be added to the current request because the byte - budget is exhausted, the request is flushed, and the event is added - to the next request. - """ - if self._value: - raise RuntimeError("Tried to send blob while another is pending") - self._event = event # provides step and possibly plugin_name - self._value = value - self._blobs = tensor_util.make_ndarray(self._value.tensor) - if self._blobs.ndim == 1: - self._metadata = metadata - self.flush() - else: + ) -> tensorboard_data.TimeSeriesDataPoint: + blobs = tensor_util.make_ndarray(value.tensor) + if blobs.ndim != 1: logger.warning( "A blob sequence must be represented as a rank-1 Tensor. " "Provided data has rank %d, for run %s, tag %s, step %s ('%s' plugin) .", - self._blobs.ndim, - self._run_resource_id, - self._value.tag, - self._event.step, + blobs.ndim, + run_name, + value.tag, + event.step, metadata.plugin_data.plugin_name, ) - # Skip this upload. - self._new_request() - - def flush(self): - """Sends the current blob sequence fully, and clears it to make way for the next.""" - if not self._value: - self._new_request() - return + return None - time_series_proto = self._time_series_resource_manager.get_or_create( - self._value.tag, - lambda: tensorboard_time_series.TensorboardTimeSeries( - display_name=self._value.tag, - value_type=tensorboard_time_series.TensorboardTimeSeries.ValueType.BLOB_SEQUENCE, - plugin_name=self._metadata.plugin_data.plugin_name, - plugin_data=self._metadata.plugin_data.content, - ), - ) m = re.match( ".*/tensorboards/(.*)/experiments/(.*)/runs/(.*)/timeSeries/(.*)", - time_series_proto.name, + self._one_platform_resource_manager.get_time_series_resource_name( + run_name, + value.tag, + lambda: tensorboard_time_series.TensorboardTimeSeries( + display_name=value.tag, + value_type=tensorboard_time_series.TensorboardTimeSeries.ValueType.BLOB_SEQUENCE, + plugin_name=metadata.plugin_data.plugin_name, + plugin_data=metadata.plugin_data.content, + ), + ), ) blob_path_prefix = "tensorboard-{}/{}/{}/{}".format(m[1], m[2], m[3], m[4]) blob_path_prefix = ( @@ -1278,16 +1327,15 @@ def flush(self): else blob_path_prefix ) sent_blob_ids = [] - for blob in self._blobs: - self._rpc_rate_limiter.tick() + for blob in blobs: with self._tracker.blob_tracker(len(blob)) as blob_tracker: blob_id = self._send_blob(blob, blob_path_prefix) if blob_id is not None: sent_blob_ids.append(str(blob_id)) - blob_tracker.mark_uploaded(blob_id is not None) + blob_tracker.mark_uploaded(blob_id is not None) - data_point = tensorboard_data.TimeSeriesDataPoint( - step=self._event.step, + return tensorboard_data.TimeSeriesDataPoint( + step=event.step, blobs=tensorboard_data.TensorboardBlobSequence( values=[ tensorboard_data.TensorboardBlob(id=blob_id) @@ -1295,37 +1343,11 @@ def flush(self): ] ), wall_time=timestamp.Timestamp( - seconds=int(self._event.wall_time), - nanos=int(round((self._event.wall_time % 1) * 10 ** 9)), + seconds=int(event.wall_time), + nanos=int(round((event.wall_time % 1) * 10**9)), ), ) - time_series_data_proto = tensorboard_data.TimeSeriesData( - tensorboard_time_series_id=time_series_proto.name.split("/")[-1], - value_type=tensorboard_time_series.TensorboardTimeSeries.ValueType.BLOB_SEQUENCE, - values=[data_point], - ) - request = tensorboard_service.WriteTensorboardRunDataRequest( - time_series_data=[time_series_data_proto] - ) - - _prune_empty_time_series(request) - if not request.time_series_data: - return - - with _request_logger(request): - try: - self._api.write_tensorboard_run_data( - tensorboard_run=self._run_resource_id, - time_series_data=request.time_series_data, - ) - except grpc.RpcError as e: - if e.code() == grpc.StatusCode.NOT_FOUND: - raise ExperimentNotFoundError() - logger.error("Upload call failed with error %s", e) - - self._new_request() - def _send_blob(self, blob, blob_path_prefix): """Sends a single blob to a GCS bucket in the consumer project. @@ -1350,19 +1372,6 @@ def _send_blob(self, blob, blob_path_prefix): return blob_id -@contextlib.contextmanager -def _request_logger(request: tensorboard_service.WriteTensorboardRunDataRequest): - """Context manager to log request size and duration.""" - upload_start_time = time.time() - request_bytes = request._pb.ByteSize() # pylint: disable=protected-access - logger.info("Trying request of %d bytes", request_bytes) - yield - upload_duration_secs = time.time() - upload_start_time - logger.info( - "Upload of (%d bytes) took %.3f seconds", request_bytes, upload_duration_secs, - ) - - def _varint_cost(n: int): """Computes the size of `n` encoded as an unsigned base-128 varint. @@ -1433,7 +1442,8 @@ def _filtered_graph_bytes(graph_bytes: bytes): # a combination of mysterious circumstances. except (message.DecodeError, RuntimeWarning): logger.warning( - "Could not parse GraphDef of size %d. Skipping.", len(graph_bytes), + "Could not parse GraphDef of size %d. Skipping.", + len(graph_bytes), ) return None # Use the default filter parameters: diff --git a/google/cloud/aiplatform/tensorboard/uploader_main.py b/google/cloud/aiplatform/tensorboard/uploader_main.py index ebd4aa5147..e6adb9cbe2 100644 --- a/google/cloud/aiplatform/tensorboard/uploader_main.py +++ b/google/cloud/aiplatform/tensorboard/uploader_main.py @@ -28,8 +28,11 @@ from tensorboard.plugins.image import metadata as images_metadata from tensorboard.plugins.graph import metadata as graphs_metadata +from google.api_core import exceptions from google.cloud import storage from google.cloud import aiplatform +from google.cloud.aiplatform.constants import base as constants +from google.cloud.aiplatform import jobs from google.cloud.aiplatform.tensorboard import uploader from google.cloud.aiplatform.utils import TensorboardClientWithOverride @@ -89,14 +92,15 @@ def main(argv): if len(argv) > 1: raise app.UsageError("Too many command-line arguments.") - aiplatform.constants.API_BASE_PATH = FLAGS.api_uri + constants.API_BASE_PATH = FLAGS.api_uri m = re.match( "projects/(.*)/locations/(.*)/tensorboards/.*", FLAGS.tensorboard_resource_name ) project_id = m[1] region = m[2] api_client = aiplatform.initializer.global_config.create_client( - client_class=TensorboardClientWithOverride, location_override=region, + client_class=TensorboardClientWithOverride, + location_override=region, ) try: @@ -123,9 +127,14 @@ def main(argv): exitcode=0, ) + experiment_name = FLAGS.experiment_name + experiment_display_name = get_experiment_display_name_with_override( + experiment_name, FLAGS.experiment_display_name, project_id, region + ) + tb_uploader = uploader.TensorBoardUploader( - experiment_name=FLAGS.experiment_name, - experiment_display_name=FLAGS.experiment_display_name, + experiment_name=experiment_name, + experiment_display_name=experiment_display_name, tensorboard_resource_name=tensorboard.name, blob_storage_bucket=blob_storage_bucket, blob_storage_folder=blob_storage_folder, @@ -146,10 +155,22 @@ def main(argv): tb_uploader.get_experiment_resource_name().replace("/", "+"), ) ) - if FLAGS.one_shot: - tb_uploader._upload_once() # pylint: disable=protected-access - else: - tb_uploader.start_uploading() + tb_uploader.start_uploading() + + +def get_experiment_display_name_with_override( + experiment_name, experiment_display_name, project_id, region +): + if experiment_name.isdecimal() and not experiment_display_name: + try: + return jobs.CustomJob.get( + resource_name=experiment_name, + project=project_id, + location=region, + ).display_name + except exceptions.NotFound: + return experiment_display_name + return experiment_display_name def flags_parser(args): diff --git a/google/cloud/aiplatform/tensorboard/uploader_utils.py b/google/cloud/aiplatform/tensorboard/uploader_utils.py new file mode 100644 index 0000000000..849a12fef6 --- /dev/null +++ b/google/cloud/aiplatform/tensorboard/uploader_utils.py @@ -0,0 +1,480 @@ +# -*- coding: utf-8 -*- + +# 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. +# + +"""Shared utils for tensorboard log uploader.""" +import abc +import contextlib +import json +import logging +import re +import time +from typing import Callable, Dict, Generator, Optional, List, Tuple +import uuid + +from tensorboard.util import tb_logging + +from google.api_core import exceptions +from google.cloud import storage +from google.cloud.aiplatform.compat.types import tensorboard_run +from google.cloud.aiplatform.compat.types import tensorboard_service +from google.cloud.aiplatform.compat.types import tensorboard_time_series +from google.cloud.aiplatform.compat.services import tensorboard_service_client + +TensorboardServiceClient = tensorboard_service_client.TensorboardServiceClient + +logger = tb_logging.get_logger() +logger.setLevel(logging.WARNING) + + +class ExistingResourceNotFoundError(RuntimeError): + """Resource could not be created or retrieved.""" + + +class RequestSender(object): + """A base class for additional request sender objects. + + Currently just used for typing. + """ + + @abc.abstractmethod + def send_requests(run_name: str): + """Sends any request for the run.""" + pass + + +class OnePlatformResourceManager(object): + """Helper class managing One Platform resources.""" + + CREATE_RUN_BATCH_SIZE = 1000 + CREATE_TIME_SERIES_BATCH_SIZE = 1000 + + def __init__(self, experiment_resource_name: str, api: TensorboardServiceClient): + """Constructor for OnePlatformResourceManager. + + Args: + experiment_resource_name (str): + Required. The resource id for the run with the following format + projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment} + api (TensorboardServiceClient): + Required. TensorboardServiceStub for calling various tensorboard services. + """ + self._experiment_resource_name = experiment_resource_name + self._api = api + self._run_name_to_run_resource_name: Dict[str, str] = {} + self._run_tag_name_to_time_series_name: Dict[(str, str), str] = {} + + def batch_create_runs( + self, run_names: List[str] + ) -> List[tensorboard_run.TensorboardRun]: + """Batch creates TensorboardRuns. + + Args: + run_names: a list of run_names for creating the TensorboardRuns. + Returns: + the created TensorboardRuns + """ + batch_size = OnePlatformResourceManager.CREATE_RUN_BATCH_SIZE + created_runs = [] + for i in range(0, len(run_names), batch_size): + one_batch_run_names = run_names[i : i + batch_size] + tb_run_requests = [ + tensorboard_service.CreateTensorboardRunRequest( + parent=self._experiment_resource_name, + tensorboard_run=tensorboard_run.TensorboardRun( + display_name=run_name + ), + tensorboard_run_id=str(uuid.uuid4()), + ) + for run_name in one_batch_run_names + ] + + tb_runs = self._api.batch_create_tensorboard_runs( + parent=self._experiment_resource_name, + requests=tb_run_requests, + ).tensorboard_runs + + self._run_name_to_run_resource_name.update( + {run.display_name: run.name for run in tb_runs} + ) + + created_runs.extend(tb_runs) + + return created_runs + + def batch_create_time_series( + self, + run_tag_name_to_time_series: Dict[ + Tuple[str, str], tensorboard_time_series.TensorboardTimeSeries + ], + ) -> List[tensorboard_time_series.TensorboardTimeSeries]: + """Batch creates TensorboardTimeSeries. + + Args: + run_tag_name_to_time_series: a dictionary of + (run_name, tag_name) to TensorboardTimeSeries proto, containing + the TensorboardTimeSeries to create. + Returns: + the created TensorboardTimeSeries + """ + batch_size = OnePlatformResourceManager.CREATE_TIME_SERIES_BATCH_SIZE + run_tag_name_to_time_series_entries = list(run_tag_name_to_time_series.items()) + run_resource_name_to_run_name = { + v: k for k, v in self._run_name_to_run_resource_name.items() + } + created_time_series = [] + for i in range(0, len(run_tag_name_to_time_series_entries), batch_size): + requests = [ + tensorboard_service.CreateTensorboardTimeSeriesRequest( + parent=self._run_name_to_run_resource_name[run_name], + tensorboard_time_series=time_series, + ) + for ( + (run_name, tag_name), + time_series, + ) in run_tag_name_to_time_series_entries[i : i + batch_size] + ] + + time_series = self._api.batch_create_tensorboard_time_series( + parent=self._experiment_resource_name, + requests=requests, + ).tensorboard_time_series + + self._run_tag_name_to_time_series_name.update( + { + ( + run_resource_name_to_run_name[ + ts.name[: ts.name.index("/timeSeries")] + ], + ts.display_name, + ): ts.name + for ts in time_series + } + ) + + created_time_series.extend(time_series) + + return created_time_series + + def get_run_resource_name(self, run_name: str) -> str: + """ + Get the resource name of the run if it exists, otherwise creates the run + on One Platform before returning its resource name. + + Args: + run_name (str): + Required. The name of the run. + + Returns: + run_resource (str): + Resource name of the run. + """ + if run_name not in self._run_name_to_run_resource_name: + tb_run = self._create_or_get_run_resource(run_name) + self._run_name_to_run_resource_name[run_name] = tb_run.name + return self._run_name_to_run_resource_name[run_name] + + def _create_or_get_run_resource( + self, run_name: str + ) -> tensorboard_run.TensorboardRun: + """Creates a new run resource in current tensorboard experiment resource. + + Args: + run_name (str): + Required. The display name of this run. + + Returns: + tb_run (tensorboard_run.TensorboardRun): + The TensorboardRun given the run_name. + + Raises: + ExistingResourceNotFoundError: + Run name could not be found in resource list. + exceptions.InvalidArgument: + run_name argument is invalid. + """ + tb_run = tensorboard_run.TensorboardRun() + tb_run.display_name = run_name + try: + tb_run = self._api.create_tensorboard_run( + parent=self._experiment_resource_name, + tensorboard_run=tb_run, + tensorboard_run_id=str(uuid.uuid4()), + ) + except exceptions.InvalidArgument as e: + # If the run name already exists then retrieve it + if "already exist" in e.message: + runs_pages = self._api.list_tensorboard_runs( + parent=self._experiment_resource_name + ) + for tb_run in runs_pages: + if tb_run.display_name == run_name: + break + + if tb_run.display_name != run_name: + raise ExistingResourceNotFoundError( + "Run with name %s already exists but is not resource list." + % run_name + ) + else: + raise + return tb_run + + def get_time_series_resource_name( + self, + run_name: str, + tag_name: str, + time_series_resource_creator: Callable[ + [], tensorboard_time_series.TensorboardTimeSeries + ], + ) -> str: + """ + Get the resource name of the time series corresponding to the tag, if it + exists, otherwise creates the time series on One Platform before + returning its resource name. + + Args: + run_name (str): + Required. The name of the run. + tag_name (str): + Required. The name of the tag. + time_series_resource_creator (tensorboard_time_series.TensorboardTimeSeries): + Required. A constructor used for creating the time series on One Platform. + + Returns: + time_series_name (str): + Resource name of the time series + """ + if (run_name, tag_name) not in self._run_tag_name_to_time_series_name: + time_series = self._create_or_get_time_series( + self.get_run_resource_name(run_name), + tag_name, + time_series_resource_creator, + ) + self._run_tag_name_to_time_series_name[ + (run_name, tag_name) + ] = time_series.name + return self._run_tag_name_to_time_series_name[(run_name, tag_name)] + + def _create_or_get_time_series( + self, + run_resource_name: str, + tag_name: str, + time_series_resource_creator: Callable[ + [], tensorboard_time_series.TensorboardTimeSeries + ], + ) -> tensorboard_time_series.TensorboardTimeSeries: + """ + Get a time series resource with given tag_name, and create a new one on + OnePlatform if not present. + + Args: + tag_name (str): + Required. The tag name of the time series in the Tensorboard log dir. + time_series_resource_creator (Callable[[], tensorboard_time_series.TensorboardTimeSeries): + Required. A callable that produces a TimeSeries for creation. + + Returns: + time_series (tensorboard_time_series.TensorboardTimeSeries): + A created or existing tensorboard_time_series.TensorboardTimeSeries. + + Raises: + exceptions.InvalidArgument: + Invalid run_resource_name, tag_name, or time_series_resource_creator. + ExistingResourceNotFoundError: + Could not find the resource given the tag name. + ValueError: + More than one time series with the resource name was found. + """ + time_series = time_series_resource_creator() + time_series.display_name = tag_name + try: + time_series = self._api.create_tensorboard_time_series( + parent=run_resource_name, tensorboard_time_series=time_series + ) + except exceptions.InvalidArgument as e: + # If the time series display name already exists then retrieve it + if "already exist" in e.message: + list_of_time_series = self._api.list_tensorboard_time_series( + request=tensorboard_service.ListTensorboardTimeSeriesRequest( + parent=run_resource_name, + filter="display_name = {}".format(json.dumps(str(tag_name))), + ) + ) + num = 0 + time_series = None + + for ts in list_of_time_series: + num += 1 + if num > 1: + break + time_series = ts + + if not time_series: + raise ExistingResourceNotFoundError( + "Could not find time series resource with display name: {}".format( + tag_name + ) + ) + + if num != 1: + raise ValueError( + "More than one time series resource found with display_name: {}".format( + tag_name + ) + ) + else: + raise + return time_series + + +class TimeSeriesResourceManager(object): + """Helper class managing Time Series resources.""" + + def __init__(self, run_resource_id: str, api: TensorboardServiceClient): + """Constructor for TimeSeriesResourceManager. + + Args: + run_resource_id (str): + Required. The resource id for the run with the following format. + projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run} + api (TensorboardServiceClient): + Required. A TensorboardServiceStub. + """ + self._run_resource_id = run_resource_id + self._api = api + self._tag_to_time_series_proto: Dict[ + str, tensorboard_time_series.TensorboardTimeSeries + ] = {} + + def get_or_create( + self, + tag_name: str, + time_series_resource_creator: Callable[ + [], tensorboard_time_series.TensorboardTimeSeries + ], + ) -> tensorboard_time_series.TensorboardTimeSeries: + """ + Get a time series resource with given tag_name, and create a new one on + OnePlatform if not present. + + Args: + tag_name (str): + Required. The tag name of the time series in the Tensorboard log dir. + time_series_resource_creator (Callable[[], tensorboard_time_series.TensorboardTimeSeries]): + Required. A callable that produces a TimeSeries for creation. + + Returns: + time_series (tensorboard_time_series.TensorboardTimeSeries): + A new or existing tensorboard_time_series.TensorboardTimeSeries. + + Raises: + exceptions.InvalidArgument: + The tag_name or time_series_resource_creator is an invalid argument + to create_tensorboard_time_series api call. + ExistingResourceNotFoundError: + Could not find the resource given the tag name. + ValueError: + More than one time series with the resource name was found. + """ + if tag_name in self._tag_to_time_series_proto: + return self._tag_to_time_series_proto[tag_name] + + time_series = time_series_resource_creator() + time_series.display_name = tag_name + try: + time_series = self._api.create_tensorboard_time_series( + parent=self._run_resource_id, tensorboard_time_series=time_series + ) + except exceptions.InvalidArgument as e: + # If the time series display name already exists then retrieve it + if "already exist" in e.message: + list_of_time_series = self._api.list_tensorboard_time_series( + request=tensorboard_service.ListTensorboardTimeSeriesRequest( + parent=self._run_resource_id, + filter="display_name = {}".format(json.dumps(str(tag_name))), + ) + ) + num = 0 + time_series = None + + for ts in list_of_time_series: + num += 1 + if num > 1: + break + time_series = ts + + if not time_series: + raise ExistingResourceNotFoundError( + "Could not find time series resource with display name: {}".format( + tag_name + ) + ) + + if num != 1: + raise ValueError( + "More than one time series resource found with display_name: {}".format( + tag_name + ) + ) + else: + raise + + self._tag_to_time_series_proto[tag_name] = time_series + return time_series + + +def get_source_bucket(logdir: str) -> Optional[storage.Bucket]: + """Returns a storage bucket object given a log directory. + + Args: + logdir (str): + Required. Path of the log directory. + + Returns: + bucket (Optional[storage.Bucket]): + A bucket if the path is a gs bucket, None otherwise. + """ + m = re.match(r"gs:\/\/(.*?)(?=\/|$)", logdir) + if not m: + return None + bucket = storage.Client().bucket(m[1]) + return bucket + + +@contextlib.contextmanager +def request_logger( + request: tensorboard_service.WriteTensorboardRunDataRequest, +) -> Generator[None, None, None]: + """Context manager to log request size and duration. + + Args: + request (tensorboard_service.WriteTensorboardRunDataRequest): + Required. A request object that provides the size of the request. + + Yields: + An empty response when the request logger has started. + """ + upload_start_time = time.time() + request_bytes = request._pb.ByteSize() # pylint: disable=protected-access + logger.info("Trying request of %d bytes", request_bytes) + yield + upload_duration_secs = time.time() - upload_start_time + logger.info( + "Upload of (%d bytes) took %.3f seconds", + request_bytes, + upload_duration_secs, + ) diff --git a/google/cloud/aiplatform/training_jobs.py b/google/cloud/aiplatform/training_jobs.py index 91e061f4ba..b2a93d952c 100644 --- a/google/cloud/aiplatform/training_jobs.py +++ b/google/cloud/aiplatform/training_jobs.py @@ -15,6 +15,7 @@ # limitations under the License. # +import datetime import time from typing import Dict, List, Optional, Sequence, Tuple, Union @@ -22,12 +23,14 @@ from google.auth import credentials as auth_credentials from google.cloud.aiplatform import base -from google.cloud.aiplatform import constants +from google.cloud.aiplatform.constants import base as constants from google.cloud.aiplatform import datasets from google.cloud.aiplatform import initializer from google.cloud.aiplatform import models +from google.cloud.aiplatform import jobs from google.cloud.aiplatform import schema from google.cloud.aiplatform import utils +from google.cloud.aiplatform.utils import console_utils from google.cloud.aiplatform.compat.types import ( env_var as gca_env_var, @@ -39,12 +42,14 @@ from google.cloud.aiplatform.utils import _timestamped_gcs_dir from google.cloud.aiplatform.utils import source_utils from google.cloud.aiplatform.utils import worker_spec_utils +from google.cloud.aiplatform.utils import column_transformations_utils from google.cloud.aiplatform.v1.schema.trainingjob import ( definition_v1 as training_job_inputs, ) from google.rpc import code_pb2 +from google.rpc import status_pb2 import proto @@ -60,22 +65,33 @@ ] ) +# _block_until_complete wait times +_JOB_WAIT_TIME = 5 # start at five seconds +_LOG_WAIT_TIME = 5 +_MAX_WAIT_TIME = 60 * 5 # 5 minute wait +_WAIT_TIME_MULTIPLIER = 2 # scale wait by 2 every iteration -class _TrainingJob(base.VertexAiResourceNounWithFutureManager): + +class _TrainingJob(base.VertexAiStatefulResource): client_class = utils.PipelineClientWithOverride - _is_client_prediction_client = False _resource_noun = "trainingPipelines" _getter_method = "get_training_pipeline" _list_method = "list_training_pipelines" _delete_method = "delete_training_pipeline" + _parse_resource_name_method = "parse_training_pipeline_path" + _format_resource_name_method = "training_pipeline_path" + + # Required by the done() method + _valid_done_states = _PIPELINE_COMPLETE_STATES def __init__( self, - display_name: str, + display_name: Optional[str] = None, project: Optional[str] = None, location: Optional[str] = None, credentials: Optional[auth_credentials.Credentials] = None, + labels: Optional[Dict[str, str]] = None, training_encryption_spec_key_name: Optional[str] = None, model_encryption_spec_key_name: Optional[str] = None, ): @@ -83,7 +99,7 @@ def __init__( Args: display_name (str): - Required. The user-defined name of this TrainingPipeline. + Optional. The user-defined name of this TrainingPipeline. project (str): Optional project to retrieve model from. If not set, project set in aiplatform.init will be used. @@ -92,6 +108,16 @@ def __init__( aiplatform.init will be used. credentials (auth_credentials.Credentials): Optional credentials to use to retrieve the model. + labels (Dict[str, str]): + Optional. The labels with user-defined metadata to + organize TrainingPipelines. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + and examples of labels. training_encryption_spec_key_name (Optional[str]): Optional. The Cloud KMS resource identifier of the customer managed encryption key used to protect the training pipeline. Has the @@ -118,10 +144,15 @@ def __init__( Overrides encryption_spec_key_name set in aiplatform.init. """ + if not display_name: + display_name = self.__class__._generate_display_name() utils.validate_display_name(display_name) + if labels: + utils.validate_labels(labels) super().__init__(project=project, location=location, credentials=credentials) self._display_name = display_name + self._labels = labels self._training_encryption_spec = initializer.global_config.get_encryption_spec( encryption_spec_key_name=training_encryption_spec_key_name ) @@ -135,9 +166,30 @@ def __init__( @abc.abstractmethod def _supported_training_schemas(cls) -> Tuple[str]: """List of supported schemas for this training job.""" - pass + @property + def start_time(self) -> Optional[datetime.datetime]: + """Time when the TrainingJob entered the `PIPELINE_STATE_RUNNING` for + the first time.""" + self._sync_gca_resource() + return getattr(self._gca_resource, "start_time") + + @property + def end_time(self) -> Optional[datetime.datetime]: + """Time when the TrainingJob resource entered the `PIPELINE_STATE_SUCCEEDED`, + `PIPELINE_STATE_FAILED`, `PIPELINE_STATE_CANCELLED` state.""" + self._sync_gca_resource() + return getattr(self._gca_resource, "end_time") + + @property + def error(self) -> Optional[status_pb2.Status]: + """Detailed error info for this TrainingJob resource. Only populated when + the TrainingJob's state is `PIPELINE_STATE_FAILED` or + `PIPELINE_STATE_CANCELLED`.""" + self._sync_gca_resource() + return getattr(self._gca_resource, "error") + @classmethod def get( cls, @@ -152,10 +204,10 @@ def get( resource_name (str): Required. A fully-qualified resource name or ID. project (str): - Optional project to retrieve dataset from. If not set, project + Optional project to retrieve training job from. If not set, project set in aiplatform.init will be used. location (str): - Optional location to retrieve dataset from. If not set, location + Optional location to retrieve training job from. If not set, location set in aiplatform.init will be used. credentials (auth_credentials.Credentials): Custom credentials to use to upload this model. Overrides @@ -166,7 +218,7 @@ def get( doesn't match the custom training task definition. Returns: - An Vertex AI Training Job + A Vertex AI Training Job """ # Create job with dummy parameters @@ -193,11 +245,68 @@ def get( return self + @classmethod + def _get_and_return_subclass( + cls, + resource_name: str, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, + ) -> "_TrainingJob": + """Retrieve Training Job subclass for the given resource_name without + knowing the training_task_definition. + + Example usage: + ``` + aiplatform.training_jobs._TrainingJob._get_and_return_subclass( + 'projects/.../locations/.../trainingPipelines/12345' + ) + # Returns: + ``` + + Args: + resource_name (str): + Required. A fully-qualified resource name or ID. + project (str): + Optional project to retrieve dataset from. If not set, project + set in aiplatform.init will be used. + location (str): + Optional location to retrieve dataset from. If not set, location + set in aiplatform.init will be used. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to upload this model. Overrides + credentials set in aiplatform.init. + + Returns: + A Vertex AI Training Job + """ + + # Retrieve training pipeline resource before class construction + client = cls._instantiate_client(location=location, credentials=credentials) + + gca_training_pipeline = getattr(client, cls._getter_method)(name=resource_name) + + schema_uri = gca_training_pipeline.training_task_definition + + # Collect all AutoML training job classes and CustomTrainingJob + class_list = [ + c for c in cls.__subclasses__() if c.__name__.startswith("AutoML") + ] + [CustomTrainingJob] + + # Identify correct training job subclass, construct and return object + for c in class_list: + if schema_uri in c._supported_training_schemas: + return c._empty_constructor( + project=project, + location=location, + credentials=credentials, + resource_name=resource_name, + ) + @property @abc.abstractmethod def _model_upload_fail_string(self) -> str: """Helper property for model upload failure.""" - pass @abc.abstractmethod @@ -212,10 +321,14 @@ def run(self) -> Optional[models.Model]: def _create_input_data_config( dataset: Optional[datasets._Dataset] = None, annotation_schema_uri: Optional[str] = None, - training_fraction_split: float = 0.8, - validation_fraction_split: float = 0.1, - test_fraction_split: float = 0.1, + training_fraction_split: Optional[float] = None, + validation_fraction_split: Optional[float] = None, + test_fraction_split: Optional[float] = None, + training_filter_split: Optional[str] = None, + validation_filter_split: Optional[str] = None, + test_filter_split: Optional[str] = None, predefined_split_column_name: Optional[str] = None, + timestamp_split_column_name: Optional[str] = None, gcs_destination_uri_prefix: Optional[str] = None, bigquery_destination: Optional[str] = None, ) -> Optional[gca_training_pipeline.InputDataConfig]: @@ -233,7 +346,7 @@ def _create_input_data_config( annotation_schema_uri (str): Google Cloud Storage URI points to a YAML file describing annotation schema. The schema is defined as an OpenAPI 3.0.2 - [Schema Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#schema-object) The schema files + [Schema Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.2.md#schema-object) The schema files that can be used here are found in gs://google-cloud-aiplatform/schema/dataset/annotation/, note that the chosen schema must be consistent with @@ -253,17 +366,35 @@ def _create_input_data_config( and ``annotation_schema_uri``. training_fraction_split (float): - The fraction of the input data that is to be - used to train the Model. This is ignored if Dataset is not provided. - training_fraction_split (float): - The fraction of the input data that is to be - used to train the Model. This is ignored if Dataset is not provided. + Optional. The fraction of the input data that is to be used to train + the Model. This is ignored if Dataset is not provided. validation_fraction_split (float): - The fraction of the input data that is to be - used to validate the Model. This is ignored if Dataset is not provided. + Optional. The fraction of the input data that is to be used to validate + the Model. This is ignored if Dataset is not provided. test_fraction_split (float): - The fraction of the input data that is to be - used to evaluate the Model. This is ignored if Dataset is not provided. + Optional. The fraction of the input data that is to be used to evaluate + the Model. This is ignored if Dataset is not provided. + training_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to train the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. + validation_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to validate the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. + test_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to test the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. predefined_split_column_name (str): Optional. The key is a name of one of the Dataset's data columns. The value of the key (either the label's value or @@ -274,6 +405,17 @@ def _create_input_data_config( ignored by the pipeline. Supported only for tabular and time series Datasets. + timestamp_split_column_name (str): + Optional. The key is a name of one of the Dataset's data + columns. The value of the key values of the key (the values in + the column) must be in RFC 3339 `date-time` format, where + `time-offset` = `"Z"` (e.g. 1985-04-12T23:20:50.52Z). If for a + piece of data the key is not present or has an invalid value, + that piece is ignored by the pipeline. + + Supported only for tabular and time series Datasets. + This parameter must be used with training_fraction_split, + validation_fraction_split, and test_fraction_split. gcs_destination_uri_prefix (str): Optional. The Google Cloud Storage location. @@ -300,33 +442,97 @@ def _create_input_data_config( - AIP_TRAINING_DATA_URI ="bigquery_destination.dataset_*.training" - AIP_VALIDATION_DATA_URI = "bigquery_destination.dataset_*.validation" - AIP_TEST_DATA_URI = "bigquery_destination.dataset_*.test" + Raises: + ValueError: When more than 1 type of split configuration is passed or when + the split configuration passed is incompatible with the dataset schema. """ input_data_config = None if dataset: - # Create fraction split spec - fraction_split = gca_training_pipeline.FractionSplit( - training_fraction=training_fraction_split, - validation_fraction=validation_fraction_split, - test_fraction=test_fraction_split, - ) - - # Create predefined split spec + # Initialize all possible splits + filter_split = None predefined_split = None - if predefined_split_column_name: - if dataset._gca_resource.metadata_schema_uri not in ( - schema.dataset.metadata.tabular, - schema.dataset.metadata.time_series, + timestamp_split = None + fraction_split = None + + # Create filter split + if any( + [ + training_filter_split is not None, + validation_filter_split is not None, + test_filter_split is not None, + ] + ): + if all( + [ + training_filter_split is not None, + validation_filter_split is not None, + test_filter_split is not None, + ] ): + filter_split = gca_training_pipeline.FilterSplit( + training_filter=training_filter_split, + validation_filter=validation_filter_split, + test_filter=test_filter_split, + ) + else: raise ValueError( - "A pre-defined split may only be used with a tabular or time series Dataset" + "All filter splits must be passed together or not at all" ) + # Create predefined split + if predefined_split_column_name: predefined_split = gca_training_pipeline.PredefinedSplit( key=predefined_split_column_name ) - # Create GCS destination + # Create timestamp split or fraction split + if timestamp_split_column_name: + timestamp_split = gca_training_pipeline.TimestampSplit( + training_fraction=training_fraction_split, + validation_fraction=validation_fraction_split, + test_fraction=test_fraction_split, + key=timestamp_split_column_name, + ) + elif any( + [ + training_fraction_split is not None, + validation_fraction_split is not None, + test_fraction_split is not None, + ] + ): + fraction_split = gca_training_pipeline.FractionSplit( + training_fraction=training_fraction_split, + validation_fraction=validation_fraction_split, + test_fraction=test_fraction_split, + ) + + splits = [ + split + for split in [ + filter_split, + predefined_split, + timestamp_split_column_name, + fraction_split, + ] + if split is not None + ] + + # Fallback to fraction split if nothing else is specified + if len(splits) == 0: + _LOGGER.info( + "No dataset split provided. The service will use a default split." + ) + elif len(splits) > 1: + raise ValueError( + """Can only specify one of: + 1. training_filter_split, validation_filter_split, test_filter_split + 2. predefined_split_column_name + 3. timestamp_split_column_name, training_fraction_split, validation_fraction_split, test_fraction_split + 4. training_fraction_split, validation_fraction_split, test_fraction_split""" + ) + + # create GCS destination gcs_destination = None if gcs_destination_uri_prefix: gcs_destination = gca_io.GcsDestination( @@ -343,7 +549,9 @@ def _create_input_data_config( # create input data config input_data_config = gca_training_pipeline.InputDataConfig( fraction_split=fraction_split, + filter_split=filter_split, predefined_split=predefined_split, + timestamp_split=timestamp_split, dataset_id=dataset.name, annotation_schema_uri=annotation_schema_uri, gcs_destination=gcs_destination, @@ -357,14 +565,19 @@ def _run_job( training_task_definition: str, training_task_inputs: Union[dict, proto.Message], dataset: Optional[datasets._Dataset], - training_fraction_split: float, - validation_fraction_split: float, - test_fraction_split: float, - annotation_schema_uri: Optional[str] = None, + training_fraction_split: Optional[float] = None, + validation_fraction_split: Optional[float] = None, + test_fraction_split: Optional[float] = None, + training_filter_split: Optional[str] = None, + validation_filter_split: Optional[str] = None, + test_filter_split: Optional[str] = None, predefined_split_column_name: Optional[str] = None, + timestamp_split_column_name: Optional[str] = None, + annotation_schema_uri: Optional[str] = None, model: Optional[gca_model.Model] = None, gcs_destination_uri_prefix: Optional[str] = None, bigquery_destination: Optional[str] = None, + create_request_timeout: Optional[float] = None, ) -> Optional[models.Model]: """Runs the training job. @@ -392,19 +605,10 @@ def _run_job( [google.cloud.aiplatform.v1beta1.TrainingPipeline.training_task_definition]. For tabular Datasets, all their data is exported to training, to pick and choose from. - training_fraction_split (float): - The fraction of the input data that is to be - used to train the Model. This is ignored if Dataset is not provided. - validation_fraction_split (float): - The fraction of the input data that is to be - used to validate the Model. This is ignored if Dataset is not provided. - test_fraction_split (float): - The fraction of the input data that is to be - used to evaluate the Model. This is ignored if Dataset is not provided. annotation_schema_uri (str): Google Cloud Storage URI points to a YAML file describing annotation schema. The schema is defined as an OpenAPI 3.0.2 - [Schema Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#schema-object) The schema files + [Schema Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.2.md#schema-object) The schema files that can be used here are found in gs://google-cloud-aiplatform/schema/dataset/annotation/, note that the chosen schema must be consistent with @@ -423,6 +627,36 @@ def _run_job( ``annotations_filter`` and ``annotation_schema_uri``. + training_fraction_split (float): + Optional. The fraction of the input data that is to be used to train + the Model. This is ignored if Dataset is not provided. + validation_fraction_split (float): + Optional. The fraction of the input data that is to be used to validate + the Model. This is ignored if Dataset is not provided. + test_fraction_split (float): + Optional. The fraction of the input data that is to be used to evaluate + the Model. This is ignored if Dataset is not provided. + training_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to train the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. + validation_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to validate the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. + test_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to test the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. predefined_split_column_name (str): Optional. The key is a name of one of the Dataset's data columns. The value of the key (either the label's value or @@ -433,6 +667,17 @@ def _run_job( ignored by the pipeline. Supported only for tabular and time series Datasets. + timestamp_split_column_name (str): + Optional. The key is a name of one of the Dataset's data + columns. The value of the key values of the key (the values in + the column) must be in RFC 3339 `date-time` format, where + `time-offset` = `"Z"` (e.g. 1985-04-12T23:20:50.52Z). If for a + piece of data the key is not present or has an invalid value, + that piece is ignored by the pipeline. + + Supported only for tabular and time series Datasets. + This parameter must be used with training_fraction_split, + validation_fraction_split, and test_fraction_split. model (~.model.Model): Optional. Describes the Model that may be uploaded (via [ModelService.UploadMode][]) by this TrainingPipeline. The @@ -479,6 +724,8 @@ def _run_job( - AIP_TRAINING_DATA_URI ="bigquery_destination.dataset_*.training" - AIP_VALIDATION_DATA_URI = "bigquery_destination.dataset_*.validation" - AIP_TEST_DATA_URI = "bigquery_destination.dataset_*.test" + create_request_timeout (float): + Optional. The timeout for the create request in seconds. """ input_data_config = self._create_input_data_config( @@ -487,7 +734,11 @@ def _run_job( training_fraction_split=training_fraction_split, validation_fraction_split=validation_fraction_split, test_fraction_split=test_fraction_split, + training_filter_split=training_filter_split, + validation_filter_split=validation_filter_split, + test_filter_split=test_filter_split, predefined_split_column_name=predefined_split_column_name, + timestamp_split_column_name=timestamp_split_column_name, gcs_destination_uri_prefix=gcs_destination_uri_prefix, bigquery_destination=bigquery_destination, ) @@ -499,6 +750,7 @@ def _run_job( training_task_inputs=training_task_inputs, model_to_upload=model, input_data_config=input_data_config, + labels=self._labels, encryption_spec=self._training_encryption_spec, ) @@ -507,6 +759,7 @@ def _run_job( self.project, self.location ), training_pipeline=training_pipeline, + timeout=create_request_timeout, ) self._gca_resource = training_pipeline @@ -594,7 +847,7 @@ def _get_model(self) -> Optional[models.Model]: """Helper method to get and instantiate the Model to Upload. Returns: - model: Vertex AI Model if training succeeded and produced an Vertex AI + model: Vertex AI Model if training succeeded and produced a Vertex AI Model. None otherwise. Raises: @@ -611,24 +864,19 @@ def _get_model(self) -> Optional[models.Model]: return None if self._gca_resource.model_to_upload.name: - fields = utils.extract_fields_from_resource_name( - self._gca_resource.model_to_upload.name - ) + return models.Model(model_name=self._gca_resource.model_to_upload.name) - return models.Model( - fields.id, project=fields.project, location=fields.location, - ) + def _wait_callback(self): + """Callback performs custom logging during _block_until_complete. Override in subclass.""" + pass def _block_until_complete(self): """Helper method to block and check on job until complete.""" - # Used these numbers so failures surface fast - wait = 5 # start at five seconds - log_wait = 5 - max_wait = 60 * 5 # 5 minute wait - multiplier = 2 # scale wait by 2 every iteration + log_wait = _LOG_WAIT_TIME previous_time = time.time() + while self.state not in _PIPELINE_COMPLETE_STATES: current_time = time.time() if current_time - previous_time >= log_wait: @@ -640,9 +888,10 @@ def _block_until_complete(self): self._gca_resource.state, ) ) - log_wait = min(log_wait * multiplier, max_wait) + log_wait = min(log_wait * _WAIT_TIME_MULTIPLIER, _MAX_WAIT_TIME) previous_time = current_time - time.sleep(wait) + self._wait_callback() + time.sleep(_JOB_WAIT_TIME) self._raise_failure() @@ -675,16 +924,10 @@ def has_failed(self) -> bool: def _dashboard_uri(self) -> str: """Helper method to compose the dashboard uri where training can be viewed.""" - fields = utils.extract_fields_from_resource_name(self.resource_name) - url = f"https://console.cloud.google.com/ai/platform/locations/{fields.location}/training/{fields.id}?project={fields.project}" + fields = self._parse_resource_name(self.resource_name) + url = f"https://console.cloud.google.com/ai/platform/locations/{fields['location']}/training/{fields['training_pipeline']}?project={fields['project']}" return url - def _sync_gca_resource(self): - """Helper method to sync the local gca_source against the service.""" - self._gca_resource = self.api_client.get_training_pipeline( - name=self.resource_name - ) - @property def _has_run(self) -> bool: """Helper property to check if this training job has been run.""" @@ -771,6 +1014,10 @@ def cancel(self) -> None: ) self.api_client.cancel_training_pipeline(name=self.resource_name) + def wait_for_resource_creation(self) -> None: + """Waits until resource has been created.""" + self._wait_for_resource_creation() + class _CustomTrainingJob(_TrainingJob): """ABC for Custom Training Pipelines..""" @@ -779,6 +1026,7 @@ class _CustomTrainingJob(_TrainingJob): def __init__( self, + # TODO(b/223262536): Make display_name parameter fully optional in next major release display_name: str, container_uri: str, model_serving_container_image_uri: Optional[str] = None, @@ -795,6 +1043,7 @@ def __init__( project: Optional[str] = None, location: Optional[str] = None, credentials: Optional[auth_credentials.Credentials] = None, + labels: Optional[Dict[str, str]] = None, training_encryption_spec_key_name: Optional[str] = None, model_encryption_spec_key_name: Optional[str] = None, staging_bucket: Optional[str] = None, @@ -899,6 +1148,16 @@ def __init__( credentials (auth_credentials.Credentials): Custom credentials to use to run call training service. Overrides credentials set in aiplatform.init. + labels (Dict[str, str]): + Optional. The labels with user-defined metadata to + organize TrainingPipelines. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + and examples of labels. training_encryption_spec_key_name (Optional[str]): Optional. The Cloud KMS resource identifier of the customer managed encryption key used to protect the training pipeline. Has the @@ -928,11 +1187,14 @@ def __init__( Bucket used to stage source and training artifacts. Overrides staging_bucket set in aiplatform.init. """ + if not display_name: + display_name = self.__class__._generate_display_name() super().__init__( display_name=display_name, project=project, location=location, credentials=credentials, + labels=labels, training_encryption_spec_key_name=training_encryption_spec_key_name, model_encryption_spec_key_name=model_encryption_spec_key_name, ) @@ -997,13 +1259,40 @@ def __init__( "set using aiplatform.init(staging_bucket='gs://my-bucket')" ) + # Backing Custom Job resource is not known until after data preprocessing + # once Custom Job is known we log the console uri and the tensorboard uri + # this flags keeps that state so we don't log it multiple times + self._has_logged_custom_job = False + self._logged_web_access_uris = set() + + @property + def network(self) -> Optional[str]: + """The full name of the Google Compute Engine + [network](https://cloud.google.com/vpc/docs/vpc#networks) to which this + CustomTrainingJob should be peered. + + Takes the format `projects/{project}/global/networks/{network}`. Where + {project} is a project number, as in `12345`, and {network} is a network name. + + Private services access must already be configured for the network. If left + unspecified, the CustomTrainingJob is not peered with any network. + """ + # Return `network` value in training task inputs if set in Map + self._assert_gca_resource_is_available() + return self._gca_resource.training_task_inputs.get("network") + def _prepare_and_validate_run( self, model_display_name: Optional[str] = None, - replica_count: int = 0, + model_labels: Optional[Dict[str, str]] = None, + replica_count: int = 1, machine_type: str = "n1-standard-4", accelerator_type: str = "ACCELERATOR_TYPE_UNSPECIFIED", accelerator_count: int = 0, + boot_disk_type: str = "pd-ssd", + boot_disk_size_gb: int = 100, + reduction_server_replica_count: int = 0, + reduction_server_machine_type: Optional[str] = None, ) -> Tuple[worker_spec_utils._DistributedTrainingSpec, Optional[gca_model.Model]]: """Create worker pool specs and managed model as well validating the run. @@ -1015,6 +1304,16 @@ def _prepare_and_validate_run( of any UTF-8 characters. If not provided upon creation, the job's display_name is used. + model_labels (Dict[str, str]): + Optional. The labels with user-defined metadata to + organize your Models. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + and examples of labels. replica_count (int): The number of worker replicas. If replica count = 1 then one chief replica will be provisioned. If replica_count > 1 the remainder will be @@ -1027,6 +1326,17 @@ def _prepare_and_validate_run( NVIDIA_TESLA_T4 accelerator_count (int): The number of accelerators to attach to a worker replica. + boot_disk_type (str): + Type of the boot disk, default is `pd-ssd`. + Valid values: `pd-ssd` (Persistent Disk Solid State Drive) or + `pd-standard` (Persistent Disk Hard Disk Drive). + boot_disk_size_gb (int): + Size in GB of the boot disk, default is 100GB. + boot disk size must be within the range of [100, 64000]. + reduction_server_replica_count (int): + The number of reduction server replicas, default is 0. + reduction_server_machine_type (str): + Optional. The type of machine to use for reduction server. Returns: Worker pools specs and managed model for run. @@ -1054,17 +1364,28 @@ def _prepare_and_validate_run( model_display_name = model_display_name or self._display_name + "-model" # validates args and will raise - worker_pool_specs = worker_spec_utils._DistributedTrainingSpec.chief_worker_pool( - replica_count=replica_count, - machine_type=machine_type, - accelerator_count=accelerator_count, - accelerator_type=accelerator_type, - ).pool_specs + worker_pool_specs = ( + worker_spec_utils._DistributedTrainingSpec.chief_worker_pool( + replica_count=replica_count, + machine_type=machine_type, + accelerator_count=accelerator_count, + accelerator_type=accelerator_type, + boot_disk_type=boot_disk_type, + boot_disk_size_gb=boot_disk_size_gb, + reduction_server_replica_count=reduction_server_replica_count, + reduction_server_machine_type=reduction_server_machine_type, + ).pool_specs + ) managed_model = self._managed_model if model_display_name: utils.validate_display_name(model_display_name) managed_model.display_name = model_display_name + if model_labels: + utils.validate_labels(model_labels) + managed_model.labels = model_labels + else: + managed_model.labels = self._labels else: managed_model = None @@ -1076,6 +1397,10 @@ def _prepare_training_task_inputs_and_output_dir( base_output_dir: Optional[str] = None, service_account: Optional[str] = None, network: Optional[str] = None, + timeout: Optional[int] = None, + restart_job_on_worker_restart: bool = False, + enable_web_access: bool = False, + tensorboard: Optional[str] = None, ) -> Tuple[Dict, str]: """Prepares training task inputs and output directory for custom job. @@ -1093,6 +1418,32 @@ def _prepare_training_task_inputs_and_output_dir( should be peered. For example, projects/12345/global/networks/myVPC. Private services access must already be configured for the network. If left unspecified, the job is not peered with any network. + timeout (int): + The maximum job running time in seconds. The default is 7 days. + restart_job_on_worker_restart (bool): + Restarts the entire CustomJob if a worker + gets restarted. This feature can be used by + distributed training jobs that are not resilient + to workers leaving and joining a job. + enable_web_access (bool): + Whether you want Vertex AI to enable interactive shell access + to training containers. + https://cloud.google.com/vertex-ai/docs/training/monitor-debug-interactive-shell + tensorboard (str): + Optional. The name of a Vertex AI + [Tensorboard][google.cloud.aiplatform.v1beta1.Tensorboard] + resource to which this CustomJob will upload Tensorboard + logs. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}`` + + The training script should write Tensorboard to following Vertex AI environment + variable: + + AIP_TENSORBOARD_LOG_DIR + + `service_account` is required with provided `tensorboard`. + For more information on configuring your service account please visit: + https://cloud.google.com/vertex-ai/docs/experiments/tensorboard-training Returns: Training task inputs and Output directory for custom job. """ @@ -1113,9 +1464,93 @@ def _prepare_training_task_inputs_and_output_dir( training_task_inputs["service_account"] = service_account if network: training_task_inputs["network"] = network + if tensorboard: + training_task_inputs["tensorboard"] = tensorboard + if enable_web_access: + training_task_inputs["enable_web_access"] = enable_web_access + + if timeout or restart_job_on_worker_restart: + timeout = f"{timeout}s" if timeout else None + scheduling = { + "timeout": timeout, + "restart_job_on_worker_restart": restart_job_on_worker_restart, + } + training_task_inputs["scheduling"] = scheduling return training_task_inputs, base_output_dir + @property + def web_access_uris(self) -> Dict[str, str]: + """Get the web access uris of the backing custom job. + + Returns: + (Dict[str, str]): + Web access uris of the backing custom job. + """ + web_access_uris = dict() + if ( + self._gca_resource.training_task_metadata + and self._gca_resource.training_task_metadata.get("backingCustomJob") + ): + custom_job_resource_name = self._gca_resource.training_task_metadata.get( + "backingCustomJob" + ) + custom_job = jobs.CustomJob.get(resource_name=custom_job_resource_name) + + web_access_uris = dict(custom_job.web_access_uris) + + return web_access_uris + + def _log_web_access_uris(self): + """Helper method to log the web access uris of the backing custom job""" + for worker, uri in self.web_access_uris.items(): + if uri not in self._logged_web_access_uris: + _LOGGER.info( + "%s %s access the interactive shell terminals for the backing custom job:\n%s:\n%s" + % ( + self.__class__.__name__, + self._gca_resource.name, + worker, + uri, + ), + ) + self._logged_web_access_uris.add(uri) + + def _wait_callback(self): + if ( + self._gca_resource.training_task_metadata + and self._gca_resource.training_task_metadata.get("backingCustomJob") + and not self._has_logged_custom_job + ): + _LOGGER.info(f"View backing custom job:\n{self._custom_job_console_uri()}") + + if self._gca_resource.training_task_inputs.get("tensorboard"): + _LOGGER.info(f"View tensorboard:\n{self._tensorboard_console_uri()}") + + self._has_logged_custom_job = True + + if self._gca_resource.training_task_inputs.get("enable_web_access"): + self._log_web_access_uris() + + def _custom_job_console_uri(self) -> str: + """Helper method to compose the dashboard uri where custom job can be viewed.""" + custom_job_resource_name = self._gca_resource.training_task_metadata.get( + "backingCustomJob" + ) + return console_utils.custom_job_console_uri(custom_job_resource_name) + + def _tensorboard_console_uri(self) -> str: + """Helper method to compose dashboard uri where tensorboard can be viewed.""" + tensorboard_resource_name = self._gca_resource.training_task_inputs.get( + "tensorboard" + ) + custom_job_resource_name = self._gca_resource.training_task_metadata.get( + "backingCustomJob" + ) + return console_utils.custom_job_tensorboard_console_uri( + tensorboard_resource_name, custom_job_resource_name + ) + @property def _model_upload_fail_string(self) -> str: """Helper property for model upload failure.""" @@ -1128,533 +1563,560 @@ def _model_upload_fail_string(self) -> str: ) -# TODO(b/172368325) add scheduling, custom_job.Scheduling -class CustomTrainingJob(_CustomTrainingJob): - """Class to launch a Custom Training Job in Vertex AI using a script. +class _ForecastingTrainingJob(_TrainingJob): + """ABC for Forecasting Training Pipelines.""" - Takes a training implementation as a python script and executes that - script in Cloud Vertex AI Training. - """ + _supported_training_schemas = tuple() def __init__( self, - display_name: str, - script_path: str, - container_uri: str, - requirements: Optional[Sequence[str]] = None, - model_serving_container_image_uri: Optional[str] = None, - model_serving_container_predict_route: Optional[str] = None, - model_serving_container_health_route: Optional[str] = None, - model_serving_container_command: Optional[Sequence[str]] = None, - model_serving_container_args: Optional[Sequence[str]] = None, - model_serving_container_environment_variables: Optional[Dict[str, str]] = None, - model_serving_container_ports: Optional[Sequence[int]] = None, - model_description: Optional[str] = None, - model_instance_schema_uri: Optional[str] = None, - model_parameters_schema_uri: Optional[str] = None, - model_prediction_schema_uri: Optional[str] = None, + display_name: Optional[str] = None, + optimization_objective: Optional[str] = None, + column_specs: Optional[Dict[str, str]] = None, + column_transformations: Optional[List[Dict[str, Dict[str, str]]]] = None, project: Optional[str] = None, location: Optional[str] = None, credentials: Optional[auth_credentials.Credentials] = None, + labels: Optional[Dict[str, str]] = None, training_encryption_spec_key_name: Optional[str] = None, model_encryption_spec_key_name: Optional[str] = None, - staging_bucket: Optional[str] = None, ): - """Constructs a Custom Training Job from a Python script. - - job = aiplatform.CustomTrainingJob( - display_name='test-train', - script_path='test_script.py', - requirements=['pandas', 'numpy'], - container_uri='gcr.io/cloud-aiplatform/training/tf-cpu.2-2:latest', - model_serving_container_image_uri='gcr.io/my-trainer/serving:1', - model_serving_container_predict_route='predict', - model_serving_container_health_route='metadata) - - Usage with Dataset: + """Constructs a Forecasting Training Job. - ds = aiplatform.TabularDataset( - 'projects/my-project/locations/us-central1/datasets/12345') - - job.run(ds, replica_count=1, model_display_name='my-trained-model') + Args: + display_name (str): + Optional. The user-defined name of this TrainingPipeline. + optimization_objective (str): + Optional. Objective function the model is to be optimized towards. + The training process creates a Model that optimizes the value of the objective + function over the validation set. The supported optimization objectives: + "minimize-rmse" (default) - Minimize root-mean-squared error (RMSE). + "minimize-mae" - Minimize mean-absolute error (MAE). + "minimize-rmsle" - Minimize root-mean-squared log error (RMSLE). + "minimize-rmspe" - Minimize root-mean-squared percentage error (RMSPE). + "minimize-wape-mae" - Minimize the combination of weighted absolute percentage error (WAPE) + and mean-absolute-error (MAE). + "minimize-quantile-loss" - Minimize the quantile loss at the defined quantiles. + (Set this objective to build quantile forecasts.) + column_specs (Dict[str, str]): + Optional. Alternative to column_transformations where the keys of the dict + are column names and their respective values are one of + AutoMLTabularTrainingJob.column_data_types. + When creating transformation for BigQuery Struct column, the column + should be flattened using "." as the delimiter. Only columns with no child + should have a transformation. + If an input column has no transformations on it, such a column is + ignored by the training, except for the targetColumn, which should have + no transformations defined on. + Only one of column_transformations or column_specs should be passed. + column_transformations (List[Dict[str, Dict[str, str]]]): + Optional. Transformations to apply to the input columns (i.e. columns other + than the targetColumn). Each transformation may produce multiple + result values from the column's value, and all are used for training. + When creating transformation for BigQuery Struct column, the column + should be flattened using "." as the delimiter. Only columns with no child + should have a transformation. + If an input column has no transformations on it, such a column is + ignored by the training, except for the targetColumn, which should have + no transformations defined on. + Only one of column_transformations or column_specs should be passed. + Consider using column_specs as column_transformations will be deprecated eventually. + project (str): + Optional. Project to run training in. Overrides project set in aiplatform.init. + location (str): + Optional. Location to run training in. Overrides location set in aiplatform.init. + credentials (auth_credentials.Credentials): + Optional. Custom credentials to use to run call training service. Overrides + credentials set in aiplatform.init. + labels (Dict[str, str]): + Optional. The labels with user-defined metadata to + organize TrainingPipelines. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + and examples of labels. + training_encryption_spec_key_name (Optional[str]): + Optional. The Cloud KMS resource identifier of the customer + managed encryption key used to protect the training pipeline. Has the + form: + ``projects/my-project/locations/my-region/keyRings/my-kr/cryptoKeys/my-key``. + The key needs to be in the same region as where the compute + resource is created. + If set, this TrainingPipeline will be secured by this key. + Note: Model trained by this TrainingPipeline is also secured + by this key if ``model_to_upload`` is not set separately. + Overrides encryption_spec_key_name set in aiplatform.init. + model_encryption_spec_key_name (Optional[str]): + Optional. The Cloud KMS resource identifier of the customer + managed encryption key used to protect the model. Has the + form: + ``projects/my-project/locations/my-region/keyRings/my-kr/cryptoKeys/my-key``. + The key needs to be in the same region as where the compute + resource is created. + If set, the trained Model will be secured by this key. + Overrides encryption_spec_key_name set in aiplatform.init. + Raises: + ValueError: If both column_transformations and column_specs were provided. + """ + super().__init__( + display_name=display_name, + project=project, + location=location, + credentials=credentials, + labels=labels, + training_encryption_spec_key_name=training_encryption_spec_key_name, + model_encryption_spec_key_name=model_encryption_spec_key_name, + ) - Usage without Dataset: + self._column_transformations = ( + column_transformations_utils.validate_and_get_column_transformations( + column_specs, + column_transformations, + ) + ) - job.run(replica_count=1, model_display_name='my-trained-model) + self._optimization_objective = optimization_objective + self._additional_experiments = [] + @property + @classmethod + @abc.abstractmethod + def _model_type(cls) -> str: + """The type of forecasting model.""" + pass - TODO(b/169782082) add documentation about traning utilities - To ensure your model gets saved in Vertex AI, write your saved model to - os.environ["AIP_MODEL_DIR"] in your provided training script. + @property + @classmethod + @abc.abstractmethod + def _training_task_definition(cls) -> str: + """A GCS path to the YAML file that defines the training task. + The definition files that can be used here are found in + gs://google-cloud-aiplatform/schema/trainingjob/definition/. + """ + pass - Args: - display_name (str): - Required. The user-defined name of this TrainingPipeline. - script_path (str): Required. Local path to training script. - container_uri (str): - Required: Uri of the training container image in the GCR. - requirements (Sequence[str]): - List of python packages dependencies of script. - model_serving_container_image_uri (str): - If the training produces a managed Vertex AI Model, the URI of the - Model serving container suitable for serving the model produced by the - training script. - model_serving_container_predict_route (str): - If the training produces a managed Vertex AI Model, An HTTP path to - send prediction requests to the container, and which must be supported - by it. If not specified a default HTTP path will be used by Vertex AI. - model_serving_container_health_route (str): - If the training produces a managed Vertex AI Model, an HTTP path to - send health check requests to the container, and which must be supported - by it. If not specified a standard HTTP path will be used by AI - Platform. - model_serving_container_command (Sequence[str]): - The command with which the container is run. Not executed within a - shell. The Docker image's ENTRYPOINT is used if this is not provided. - Variable references $(VAR_NAME) are expanded using the container's - environment. If a variable cannot be resolved, the reference in the - input string will be unchanged. The $(VAR_NAME) syntax can be escaped - with a double $$, ie: $$(VAR_NAME). Escaped references will never be - expanded, regardless of whether the variable exists or not. - model_serving_container_args (Sequence[str]): - The arguments to the command. The Docker image's CMD is used if this is - not provided. Variable references $(VAR_NAME) are expanded using the - container's environment. If a variable cannot be resolved, the reference - in the input string will be unchanged. The $(VAR_NAME) syntax can be - escaped with a double $$, ie: $$(VAR_NAME). Escaped references will - never be expanded, regardless of whether the variable exists or not. - model_serving_container_environment_variables (Dict[str, str]): - The environment variables that are to be present in the container. - Should be a dictionary where keys are environment variable names - and values are environment variable values for those names. - model_serving_container_ports (Sequence[int]): - Declaration of ports that are exposed by the container. This field is - primarily informational, it gives Vertex AI information about the - network connections the container uses. Listing or not a port here has - no impact on whether the port is actually exposed, any port listening on - the default "0.0.0.0" address inside a container will be accessible from - the network. - model_description (str): - The description of the Model. - model_instance_schema_uri (str): - Optional. Points to a YAML file stored on Google Cloud - Storage describing the format of a single instance, which - are used in - ``PredictRequest.instances``, - ``ExplainRequest.instances`` - and - ``BatchPredictionJob.input_config``. - The schema is defined as an OpenAPI 3.0.2 `Schema - Object `__. - AutoML Models always have this field populated by AI - Platform. Note: The URI given on output will be immutable - and probably different, including the URI scheme, than the - one given on input. The output URI will point to a location - where the user only has a read access. - model_parameters_schema_uri (str): - Optional. Points to a YAML file stored on Google Cloud - Storage describing the parameters of prediction and - explanation via - ``PredictRequest.parameters``, - ``ExplainRequest.parameters`` - and - ``BatchPredictionJob.model_parameters``. - The schema is defined as an OpenAPI 3.0.2 `Schema - Object `__. - AutoML Models always have this field populated by AI - Platform, if no parameters are supported it is set to an - empty string. Note: The URI given on output will be - immutable and probably different, including the URI scheme, - than the one given on input. The output URI will point to a - location where the user only has a read access. - model_prediction_schema_uri (str): - Optional. Points to a YAML file stored on Google Cloud - Storage describing the format of a single prediction - produced by this Model, which are returned via - ``PredictResponse.predictions``, - ``ExplainResponse.explanations``, - and - ``BatchPredictionJob.output_config``. - The schema is defined as an OpenAPI 3.0.2 `Schema - Object `__. - AutoML Models always have this field populated by AI - Platform. Note: The URI given on output will be immutable - and probably different, including the URI scheme, than the - one given on input. The output URI will point to a location - where the user only has a read access. - project (str): - Project to run training in. Overrides project set in aiplatform.init. - location (str): - Location to run training in. Overrides location set in aiplatform.init. - credentials (auth_credentials.Credentials): - Custom credentials to use to run call training service. Overrides - credentials set in aiplatform.init. - training_encryption_spec_key_name (Optional[str]): - Optional. The Cloud KMS resource identifier of the customer - managed encryption key used to protect the training pipeline. Has the - form: - ``projects/my-project/locations/my-region/keyRings/my-kr/cryptoKeys/my-key``. - The key needs to be in the same region as where the compute - resource is created. - - If set, this TrainingPipeline will be secured by this key. - - Note: Model trained by this TrainingPipeline is also secured - by this key if ``model_to_upload`` is not set separately. - - Overrides encryption_spec_key_name set in aiplatform.init. - model_encryption_spec_key_name (Optional[str]): - Optional. The Cloud KMS resource identifier of the customer - managed encryption key used to protect the model. Has the - form: - ``projects/my-project/locations/my-region/keyRings/my-kr/cryptoKeys/my-key``. - The key needs to be in the same region as where the compute - resource is created. - - If set, the trained Model will be secured by this key. - - Overrides encryption_spec_key_name set in aiplatform.init. - staging_bucket (str): - Bucket used to stage source and training artifacts. Overrides - staging_bucket set in aiplatform.init. - """ - super().__init__( - display_name=display_name, - project=project, - location=location, - credentials=credentials, - training_encryption_spec_key_name=training_encryption_spec_key_name, - model_encryption_spec_key_name=model_encryption_spec_key_name, - container_uri=container_uri, - model_instance_schema_uri=model_instance_schema_uri, - model_parameters_schema_uri=model_parameters_schema_uri, - model_prediction_schema_uri=model_prediction_schema_uri, - model_serving_container_environment_variables=model_serving_container_environment_variables, - model_serving_container_ports=model_serving_container_ports, - model_serving_container_image_uri=model_serving_container_image_uri, - model_serving_container_command=model_serving_container_command, - model_serving_container_args=model_serving_container_args, - model_serving_container_predict_route=model_serving_container_predict_route, - model_serving_container_health_route=model_serving_container_health_route, - model_description=model_description, - staging_bucket=staging_bucket, - ) - - self._requirements = requirements - self._script_path = script_path - - # TODO(b/172365904) add filter split, training_pipeline.FilterSplit - # TODO(b/172368070) add timestamp split, training_pipeline.TimestampSplit def run( self, - dataset: Optional[ - Union[ - datasets.ImageDataset, - datasets.TabularDataset, - datasets.TextDataset, - datasets.VideoDataset, - ] - ] = None, - annotation_schema_uri: Optional[str] = None, - model_display_name: Optional[str] = None, - base_output_dir: Optional[str] = None, - service_account: Optional[str] = None, - network: Optional[str] = None, - bigquery_destination: Optional[str] = None, - args: Optional[List[Union[str, float, int]]] = None, - environment_variables: Optional[Dict[str, str]] = None, - replica_count: int = 0, - machine_type: str = "n1-standard-4", - accelerator_type: str = "ACCELERATOR_TYPE_UNSPECIFIED", - accelerator_count: int = 0, - training_fraction_split: float = 0.8, - validation_fraction_split: float = 0.1, - test_fraction_split: float = 0.1, + dataset: datasets.TimeSeriesDataset, + target_column: str, + time_column: str, + time_series_identifier_column: str, + unavailable_at_forecast_columns: List[str], + available_at_forecast_columns: List[str], + forecast_horizon: int, + data_granularity_unit: str, + data_granularity_count: int, + training_fraction_split: Optional[float] = None, + validation_fraction_split: Optional[float] = None, + test_fraction_split: Optional[float] = None, predefined_split_column_name: Optional[str] = None, - sync=True, - ) -> Optional[models.Model]: - """Runs the custom training job. - - Distributed Training Support: - If replica count = 1 then one chief replica will be provisioned. If - replica_count > 1 the remainder will be provisioned as a worker replica pool. - ie: replica_count = 10 will result in 1 chief and 9 workers - All replicas have same machine_type, accelerator_type, and accelerator_count + timestamp_split_column_name: Optional[str] = None, + weight_column: Optional[str] = None, + time_series_attribute_columns: Optional[List[str]] = None, + context_window: Optional[int] = None, + export_evaluated_data_items: bool = False, + export_evaluated_data_items_bigquery_destination_uri: Optional[str] = None, + export_evaluated_data_items_override_destination: bool = False, + quantiles: Optional[List[float]] = None, + validation_options: Optional[str] = None, + budget_milli_node_hours: int = 1000, + model_display_name: Optional[str] = None, + model_labels: Optional[Dict[str, str]] = None, + additional_experiments: Optional[List[str]] = None, + hierarchy_group_columns: Optional[List[str]] = None, + hierarchy_group_total_weight: Optional[float] = None, + hierarchy_temporal_total_weight: Optional[float] = None, + hierarchy_group_temporal_total_weight: Optional[float] = None, + window_column: Optional[str] = None, + window_stride_length: Optional[int] = None, + window_max_count: Optional[int] = None, + holiday_regions: Optional[List[str]] = None, + sync: bool = True, + create_request_timeout: Optional[float] = None, + ) -> models.Model: + """Runs the training job and returns a model. - Data fraction splits: - Any of ``training_fraction_split``, ``validation_fraction_split`` and - ``test_fraction_split`` may optionally be provided, they must sum to up to 1. If - the provided ones sum to less than 1, the remainder is assigned to sets as - decided by Vertex AI.If none of the fractions are set, by default roughly 80% - of data will be used for training, 10% for validation, and 10% for test. + If training on a Vertex AI dataset, you can use one of the following split configurations: + Data fraction splits: + Any of ``training_fraction_split``, ``validation_fraction_split`` and + ``test_fraction_split`` may optionally be provided, they must sum to up to 1. If + the provided ones sum to less than 1, the remainder is assigned to sets as + decided by Vertex AI. If none of the fractions are set, by default roughly 80% + of data will be used for training, 10% for validation, and 10% for test. + + Predefined splits: + Assigns input data to training, validation, and test sets based on the value of a provided key. + If using predefined splits, ``predefined_split_column_name`` must be provided. + Supported only for tabular Datasets. + + Timestamp splits: + Assigns input data to training, validation, and test sets + based on a provided timestamps. The youngest data pieces are + assigned to training set, next to validation set, and the oldest + to the test set. + Supported only for tabular Datasets. Args: - dataset ( - Union[ - datasets.ImageDataset, - datasets.TabularDataset, - datasets.TextDataset, - datasets.VideoDataset, - ] - ): - Vertex AI to fit this training against. Custom training script should - retrieve datasets through passed in environment variables uris: + dataset (datasets.TimeSeriesDataset): + Required. The dataset within the same Project from which data will be used to train the Model. The + Dataset must use schema compatible with Model being trained, + and what is compatible should be described in the used + TrainingPipeline's [training_task_definition] + [google.cloud.aiplatform.v1beta1.TrainingPipeline.training_task_definition]. + For time series Datasets, all their data is exported to + training, to pick and choose from. + target_column (str): + Required. Name of the column that the Model is to predict values for. This + column must be unavailable at forecast. + time_column (str): + Required. Name of the column that identifies time order in the time series. + This column must be available at forecast. + time_series_identifier_column (str): + Required. Name of the column that identifies the time series. + unavailable_at_forecast_columns (List[str]): + Required. Column names of columns that are unavailable at forecast. + Each column contains information for the given entity (identified by the + [time_series_identifier_column]) that is unknown before the forecast + (e.g. population of a city in a given year, or weather on a given day). + available_at_forecast_columns (List[str]): + Required. Column names of columns that are available at forecast. + Each column contains information for the given entity (identified by the + [time_series_identifier_column]) that is known at forecast. + forecast_horizon: (int): + Required. The amount of time into the future for which forecasted values for the target are + returned. Expressed in number of units defined by the [data_granularity_unit] and + [data_granularity_count] field. Inclusive. + data_granularity_unit (str): + Required. The data granularity unit. Accepted values are ``minute``, + ``hour``, ``day``, ``week``, ``month``, ``year``. + data_granularity_count (int): + Required. The number of data granularity units between data points in the training + data. If [data_granularity_unit] is `minute`, can be 1, 5, 10, 15, or 30. For all other + values of [data_granularity_unit], must be 1. + predefined_split_column_name (str): + Optional. The key is a name of one of the Dataset's data + columns. The value of the key (either the label's value or + value in the column) must be one of {``TRAIN``, + ``VALIDATE``, ``TEST``}, and it defines to which set the + given piece of data is assigned. If for a piece of data the + key is not present or has an invalid value, that piece is + ignored by the pipeline. - os.environ["AIP_TRAINING_DATA_URI"] - os.environ["AIP_VALIDATION_DATA_URI"] - os.environ["AIP_TEST_DATA_URI"] + Supported only for tabular and time series Datasets. + timestamp_split_column_name (str): + Optional. The key is a name of one of the Dataset's data + columns. The value of the key values of the key (the values in + the column) must be in RFC 3339 `date-time` format, where + `time-offset` = `"Z"` (e.g. 1985-04-12T23:20:50.52Z). If for a + piece of data the key is not present or has an invalid value, + that piece is ignored by the pipeline. + Supported only for tabular and time series Datasets. + This parameter must be used with training_fraction_split, + validation_fraction_split, and test_fraction_split. + weight_column (str): + Optional. Name of the column that should be used as the weight column. + Higher values in this column give more importance to the row + during Model training. The column must have numeric values between 0 and + 10000 inclusively, and 0 value means that the row is ignored. + If the weight column field is not set, then all rows are assumed to have + equal weight of 1. This column must be available at forecast. + time_series_attribute_columns (List[str]): + Optional. Column names that should be used as attribute columns. + Each column is constant within a time series. + context_window (int): + Optional. The amount of time into the past training and prediction data is used for + model training and prediction respectively. Expressed in number of units defined by the + [data_granularity_unit] and [data_granularity_count] fields. When not provided uses the + default value of 0 which means the model sets each series context window to be 0 (also + known as "cold start"). Inclusive. + export_evaluated_data_items (bool): + Whether to export the test set predictions to a BigQuery table. + If False, then the export is not performed. + export_evaluated_data_items_bigquery_destination_uri (string): + Optional. URI of desired destination BigQuery table for exported test set predictions. - Additionally the dataset format is passed in as: + Expected format: + ``bq://::`` - os.environ["AIP_DATA_FORMAT"] - annotation_schema_uri (str): - Google Cloud Storage URI points to a YAML file describing - annotation schema. The schema is defined as an OpenAPI 3.0.2 - [Schema Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#schema-object) The schema files - that can be used here are found in - gs://google-cloud-aiplatform/schema/dataset/annotation/, - note that the chosen schema must be consistent with - ``metadata`` - of the Dataset specified by - ``dataset_id``. + If not specified, then results are exported to the following auto-created BigQuery + table: + ``:export_evaluated_examples__.evaluated_examples`` - Only Annotations that both match this schema and belong to - DataItems not ignored by the split method are used in - respectively training, validation or test role, depending on - the role of the DataItem they are on. + Applies only if [export_evaluated_data_items] is True. + export_evaluated_data_items_override_destination (bool): + Whether to override the contents of [export_evaluated_data_items_bigquery_destination_uri], + if the table exists, for exported test set predictions. If False, and the + table exists, then the training job will fail. - When used in conjunction with - ``annotations_filter``, - the Annotations used for training are filtered by both - ``annotations_filter`` - and - ``annotation_schema_uri``. + Applies only if [export_evaluated_data_items] is True and + [export_evaluated_data_items_bigquery_destination_uri] is specified. + quantiles (List[float]): + Quantiles to use for the `minimize-quantile-loss` + [AutoMLForecastingTrainingJob.optimization_objective]. This argument is required in + this case. + + Accepts up to 5 quantiles in the form of a double from 0 to 1, exclusive. + Each quantile must be unique. + validation_options (str): + Validation options for the data validation component. The available options are: + "fail-pipeline" - (default), will validate against the validation and fail the pipeline + if it fails. + "ignore-validation" - ignore the results of the validation and continue the pipeline + budget_milli_node_hours (int): + Optional. The train budget of creating this Model, expressed in milli node + hours i.e. 1,000 value in this field means 1 node hour. + The training cost of the model will not exceed this budget. The final + cost will be attempted to be close to the budget, though may end up + being (even) noticeably smaller - at the backend's discretion. This + especially may happen when further model training ceases to provide + any improvements. + If the budget is set to a value known to be insufficient to train a + Model for the given training set, the training won't be attempted and + will error. + The minimum value is 1000 and the maximum is 72000. model_display_name (str): - If the script produces a managed Vertex AI Model. The display name of + Optional. If the script produces a managed Vertex AI Model. The display name of the Model. The name can be up to 128 characters long and can be consist of any UTF-8 characters. If not provided upon creation, the job's display_name is used. - base_output_dir (str): - GCS output directory of job. If not provided a - timestamped directory in the staging directory will be used. - - Vertex AI sets the following environment variables when it runs your training code: - - - AIP_MODEL_DIR: a Cloud Storage URI of a directory intended for saving model artifacts, i.e. /model/ - - AIP_CHECKPOINT_DIR: a Cloud Storage URI of a directory intended for saving checkpoints, i.e. /checkpoints/ - - AIP_TENSORBOARD_LOG_DIR: a Cloud Storage URI of a directory intended for saving TensorBoard logs, i.e. /logs/ - - service_account (str): - Specifies the service account for workload run-as account. - Users submitting jobs must have act-as permission on this run-as account. - network (str): - The full name of the Compute Engine network to which the job - should be peered. For example, projects/12345/global/networks/myVPC. - Private services access must already be configured for the network. - If left unspecified, the job is not peered with any network. - bigquery_destination (str): - Provide this field if `dataset` is a BiqQuery dataset. - The BigQuery project location where the training data is to - be written to. In the given project a new dataset is created - with name - ``dataset___`` - where timestamp is in YYYY_MM_DDThh_mm_ss_sssZ format. All - training input data will be written into that dataset. In - the dataset three tables will be created, ``training``, - ``validation`` and ``test``. - - - AIP_DATA_FORMAT = "bigquery". - - AIP_TRAINING_DATA_URI ="bigquery_destination.dataset_*.training" - - AIP_VALIDATION_DATA_URI = "bigquery_destination.dataset_*.validation" - - AIP_TEST_DATA_URI = "bigquery_destination.dataset_*.test" - args (List[Unions[str, int, float]]): - Command line arguments to be passed to the Python script. - environment_variables (Dict[str, str]): - Environment variables to be passed to the container. - Should be a dictionary where keys are environment variable names - and values are environment variable values for those names. - At most 10 environment variables can be specified. - The Name of the environment variable must be unique. - - environment_variables = { - 'MY_KEY': 'MY_VALUE' - } - replica_count (int): - The number of worker replicas. If replica count = 1 then one chief - replica will be provisioned. If replica_count > 1 the remainder will be - provisioned as a worker replica pool. - machine_type (str): - The type of machine to use for training. - accelerator_type (str): - Hardware accelerator type. One of ACCELERATOR_TYPE_UNSPECIFIED, - NVIDIA_TESLA_K80, NVIDIA_TESLA_P100, NVIDIA_TESLA_V100, NVIDIA_TESLA_P4, - NVIDIA_TESLA_T4 - accelerator_count (int): - The number of accelerators to attach to a worker replica. - training_fraction_split (float): - The fraction of the input data that is to be - used to train the Model. This is ignored if Dataset is not provided. - validation_fraction_split (float): - The fraction of the input data that is to be - used to validate the Model. This is ignored if Dataset is not provided. - test_fraction_split (float): - The fraction of the input data that is to be - used to evaluate the Model. This is ignored if Dataset is not provided. - predefined_split_column_name (str): - Optional. The key is a name of one of the Dataset's data - columns. The value of the key (either the label's value or - value in the column) must be one of {``training``, - ``validation``, ``test``}, and it defines to which set the - given piece of data is assigned. If for a piece of data the - key is not present or has an invalid value, that piece is - ignored by the pipeline. - - Supported only for tabular and time series Datasets. + model_labels (Dict[str, str]): + Optional. The labels with user-defined metadata to + organize your Models. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + and examples of labels. + additional_experiments (List[str]): + Optional. Additional experiment flags for the time series forcasting training. + create_request_timeout (float): + Optional. The timeout for the create request in seconds. + hierarchy_group_columns (List[str]): + Optional. A list of time series attribute column names that + define the time series hierarchy. Only one level of hierarchy is + supported, ex. ``region`` for a hierarchy of stores or + ``department`` for a hierarchy of products. If multiple columns + are specified, time series will be grouped by their combined + values, ex. (``blue``, ``large``) for ``color`` and ``size``, up + to 5 columns are accepted. If no group columns are specified, + all time series are considered to be part of the same group. + hierarchy_group_total_weight (float): + Optional. The weight of the loss for predictions aggregated over + time series in the same hierarchy group. + hierarchy_temporal_total_weight (float): + Optional. The weight of the loss for predictions aggregated over + the horizon for a single time series. + hierarchy_group_temporal_total_weight (float): + Optional. The weight of the loss for predictions aggregated over + both the horizon and time series in the same hierarchy group. + window_column (str): + Optional. Name of the column that should be used to filter input + rows. The column should contain either booleans or string + booleans; if the value of the row is True, generate a sliding + window from that row. + window_stride_length (int): + Optional. Step length used to generate input examples. Every + ``window_stride_length`` rows will be used to generate a sliding + window. + window_max_count (int): + Optional. Number of rows that should be used to generate input + examples. If the total row count is larger than this number, the + input data will be randomly sampled to hit the count. + holiday_regions (List[str]): + Optional. The geographical regions to use when creating holiday + features. This option is only allowed when data_granularity_unit + is ``day``. Acceptable values can come from any of the following + levels: + Top level: GLOBAL + Second level: continental regions + NA: North America + JAPAC: Japan and Asia Pacific + EMEA: Europe, the Middle East and Africa + LAC: Latin America and the Caribbean + Third level: countries from ISO 3166-1 Country codes. sync (bool): Whether to execute this method synchronously. If False, this method will be executed in concurrent Future and any downstream object will be immediately returned and synced when the Future has completed. - Returns: model: The trained Vertex AI Model resource or None if training did not - produce an Vertex AI Model. - """ - worker_pool_specs, managed_model = self._prepare_and_validate_run( - model_display_name=model_display_name, - replica_count=replica_count, - machine_type=machine_type, - accelerator_count=accelerator_count, - accelerator_type=accelerator_type, - ) + produce a Vertex AI Model. - # make and copy package - python_packager = source_utils._TrainingScriptPythonPackager( - script_path=self._script_path, requirements=self._requirements - ) + Raises: + RuntimeError: If Training job has already been run or is waiting to run. + """ - return self._run( - python_packager=python_packager, - dataset=dataset, - annotation_schema_uri=annotation_schema_uri, - worker_pool_specs=worker_pool_specs, - managed_model=managed_model, - args=args, - environment_variables=environment_variables, - base_output_dir=base_output_dir, - service_account=service_account, - network=network, - bigquery_destination=bigquery_destination, - training_fraction_split=training_fraction_split, - validation_fraction_split=validation_fraction_split, - test_fraction_split=test_fraction_split, - predefined_split_column_name=predefined_split_column_name, - sync=sync, - ) + if model_display_name: + utils.validate_display_name(model_display_name) + if model_labels: + utils.validate_labels(model_labels) - @base.optional_sync(construct_object_on_arg="managed_model") - def _run( - self, - python_packager: source_utils._TrainingScriptPythonPackager, - dataset: Optional[ - Union[ - datasets.ImageDataset, - datasets.TabularDataset, - datasets.TextDataset, - datasets.VideoDataset, - ] - ], - annotation_schema_uri: Optional[str], - worker_pool_specs: worker_spec_utils._DistributedTrainingSpec, - managed_model: Optional[gca_model.Model] = None, - args: Optional[List[Union[str, float, int]]] = None, - environment_variables: Optional[Dict[str, str]] = None, - base_output_dir: Optional[str] = None, - service_account: Optional[str] = None, - network: Optional[str] = None, - bigquery_destination: Optional[str] = None, - training_fraction_split: float = 0.8, - validation_fraction_split: float = 0.1, - test_fraction_split: float = 0.1, - predefined_split_column_name: Optional[str] = None, - sync=True, - ) -> Optional[models.Model]: - """Packages local script and launches training_job. + if self._is_waiting_to_run(): + raise RuntimeError( + f"{self._model_type} Forecasting Training is already scheduled " + "to run." + ) - Args: - python_packager (source_utils._TrainingScriptPythonPackager): - Required. Python Packager pointing to training script locally. - dataset ( - Union[ - datasets.ImageDataset, - datasets.TabularDataset, - datasets.TextDataset, - datasets.VideoDataset, - ] - ): - Vertex AI to fit this training against. - annotation_schema_uri (str): - Google Cloud Storage URI points to a YAML file describing - annotation schema. - worker_pools_spec (worker_spec_utils._DistributedTrainingSpec): - Worker pools pecs required to run job. - managed_model (gca_model.Model): - Model proto if this script produces a Managed Model. - args (List[Unions[str, int, float]]): - Command line arguments to be passed to the Python script. - environment_variables (Dict[str, str]): - Environment variables to be passed to the container. - Should be a dictionary where keys are environment variable names - and values are environment variable values for those names. - At most 10 environment variables can be specified. - The Name of the environment variable must be unique. + if self._has_run: + raise RuntimeError( + f"{self._model_type} Forecasting Training has already run." + ) - environment_variables = { - 'MY_KEY': 'MY_VALUE' - } - base_output_dir (str): - GCS output directory of job. If not provided a - timestamped directory in the staging directory will be used. + if additional_experiments: + self._add_additional_experiments(additional_experiments) - Vertex AI sets the following environment variables when it runs your training code: + return self._run( + dataset=dataset, + target_column=target_column, + time_column=time_column, + time_series_identifier_column=time_series_identifier_column, + unavailable_at_forecast_columns=unavailable_at_forecast_columns, + available_at_forecast_columns=available_at_forecast_columns, + forecast_horizon=forecast_horizon, + data_granularity_unit=data_granularity_unit, + data_granularity_count=data_granularity_count, + training_fraction_split=training_fraction_split, + validation_fraction_split=validation_fraction_split, + test_fraction_split=test_fraction_split, + predefined_split_column_name=predefined_split_column_name, + timestamp_split_column_name=timestamp_split_column_name, + weight_column=weight_column, + time_series_attribute_columns=time_series_attribute_columns, + context_window=context_window, + budget_milli_node_hours=budget_milli_node_hours, + export_evaluated_data_items=export_evaluated_data_items, + export_evaluated_data_items_bigquery_destination_uri=export_evaluated_data_items_bigquery_destination_uri, + export_evaluated_data_items_override_destination=export_evaluated_data_items_override_destination, + quantiles=quantiles, + validation_options=validation_options, + model_display_name=model_display_name, + model_labels=model_labels, + hierarchy_group_columns=hierarchy_group_columns, + hierarchy_group_total_weight=hierarchy_group_total_weight, + hierarchy_temporal_total_weight=hierarchy_temporal_total_weight, + hierarchy_group_temporal_total_weight=hierarchy_group_temporal_total_weight, + window_column=window_column, + window_stride_length=window_stride_length, + window_max_count=window_max_count, + holiday_regions=holiday_regions, + sync=sync, + create_request_timeout=create_request_timeout, + ) - - AIP_MODEL_DIR: a Cloud Storage URI of a directory intended for saving model artifacts, i.e. /model/ - - AIP_CHECKPOINT_DIR: a Cloud Storage URI of a directory intended for saving checkpoints, i.e. /checkpoints/ - - AIP_TENSORBOARD_LOG_DIR: a Cloud Storage URI of a directory intended for saving TensorBoard logs, i.e. /logs/ + @base.optional_sync() + def _run( + self, + dataset: datasets.TimeSeriesDataset, + target_column: str, + time_column: str, + time_series_identifier_column: str, + unavailable_at_forecast_columns: List[str], + available_at_forecast_columns: List[str], + forecast_horizon: int, + data_granularity_unit: str, + data_granularity_count: int, + training_fraction_split: Optional[float] = None, + validation_fraction_split: Optional[float] = None, + test_fraction_split: Optional[float] = None, + predefined_split_column_name: Optional[str] = None, + timestamp_split_column_name: Optional[str] = None, + weight_column: Optional[str] = None, + time_series_attribute_columns: Optional[List[str]] = None, + context_window: Optional[int] = None, + export_evaluated_data_items: bool = False, + export_evaluated_data_items_bigquery_destination_uri: Optional[str] = None, + export_evaluated_data_items_override_destination: bool = False, + quantiles: Optional[List[float]] = None, + validation_options: Optional[str] = None, + budget_milli_node_hours: int = 1000, + model_display_name: Optional[str] = None, + model_labels: Optional[Dict[str, str]] = None, + hierarchy_group_columns: Optional[List[str]] = None, + hierarchy_group_total_weight: Optional[float] = None, + hierarchy_temporal_total_weight: Optional[float] = None, + hierarchy_group_temporal_total_weight: Optional[float] = None, + window_column: Optional[str] = None, + window_stride_length: Optional[int] = None, + window_max_count: Optional[int] = None, + holiday_regions: Optional[List[str]] = None, + sync: bool = True, + create_request_timeout: Optional[float] = None, + ) -> models.Model: + """Runs the training job and returns a model. - service_account (str): - Specifies the service account for workload run-as account. - Users submitting jobs must have act-as permission on this run-as account. - network (str): - The full name of the Compute Engine network to which the job - should be peered. For example, projects/12345/global/networks/myVPC. - Private services access must already be configured for the network. - If left unspecified, the job is not peered with any network. - bigquery_destination (str): - Provide this field if `dataset` is a BiqQuery dataset. - The BigQuery project location where the training data is to - be written to. In the given project a new dataset is created - with name - ``dataset___`` - where timestamp is in YYYY_MM_DDThh_mm_ss_sssZ format. All - training input data will be written into that dataset. In - the dataset three tables will be created, ``training``, - ``validation`` and ``test``. + If training on a Vertex AI dataset, you can use one of the following split configurations: + Data fraction splits: + Any of ``training_fraction_split``, ``validation_fraction_split`` and + ``test_fraction_split`` may optionally be provided, they must sum to up to 1. If + the provided ones sum to less than 1, the remainder is assigned to sets as + decided by Vertex AI. If none of the fractions are set, by default roughly 80% + of data will be used for training, 10% for validation, and 10% for test. + + Predefined splits: + Assigns input data to training, validation, and test sets based on the value of a provided key. + If using predefined splits, ``predefined_split_column_name`` must be provided. + Supported only for tabular Datasets. + + Timestamp splits: + Assigns input data to training, validation, and test sets + based on a provided timestamps. The youngest data pieces are + assigned to training set, next to validation set, and the oldest + to the test set. + Supported only for tabular Datasets. - - AIP_DATA_FORMAT = "bigquery". - - AIP_TRAINING_DATA_URI ="bigquery_destination.dataset_*.training" - - AIP_VALIDATION_DATA_URI = "bigquery_destination.dataset_*.validation" - - AIP_TEST_DATA_URI = "bigquery_destination.dataset_*.test" + Args: + dataset (datasets.TimeSeriesDataset): + Required. The dataset within the same Project from which data will be used to train the Model. The + Dataset must use schema compatible with Model being trained, + and what is compatible should be described in the used + TrainingPipeline's [training_task_definition] + [google.cloud.aiplatform.v1beta1.TrainingPipeline.training_task_definition]. + For time series Datasets, all their data is exported to + training, to pick and choose from. + target_column (str): + Required. Name of the column that the Model is to predict values for. This + column must be unavailable at forecast. + time_column (str): + Required. Name of the column that identifies time order in the time series. + This column must be available at forecast. + time_series_identifier_column (str): + Required. Name of the column that identifies the time series. + unavailable_at_forecast_columns (List[str]): + Required. Column names of columns that are unavailable at forecast. + Each column contains information for the given entity (identified by the + [time_series_identifier_column]) that is unknown before the forecast + (e.g. population of a city in a given year, or weather on a given day). + available_at_forecast_columns (List[str]): + Required. Column names of columns that are available at forecast. + Each column contains information for the given entity (identified by the + [time_series_identifier_column]) that is known at forecast. + forecast_horizon: (int): + Required. The amount of time into the future for which forecasted values for the target are + returned. Expressed in number of units defined by the [data_granularity_unit] and + [data_granularity_count] field. Inclusive. + data_granularity_unit (str): + Required. The data granularity unit. Accepted values are ``minute``, + ``hour``, ``day``, ``week``, ``month``, ``year``. + data_granularity_count (int): + Required. The number of data granularity units between data points in the training + data. If [data_granularity_unit] is `minute`, can be 1, 5, 10, 15, or 30. For all other + values of [data_granularity_unit], must be 1. training_fraction_split (float): - The fraction of the input data that is to be - used to train the Model. + Optional. The fraction of the input data that is to be used to train + the Model. This is ignored if Dataset is not provided. validation_fraction_split (float): - The fraction of the input data that is to be - used to validate the Model. + Optional. The fraction of the input data that is to be used to validate + the Model. This is ignored if Dataset is not provided. test_fraction_split (float): - The fraction of the input data that is to be - used to evaluate the Model. + Optional. The fraction of the input data that is to be used to evaluate + the Model. This is ignored if Dataset is not provided. predefined_split_column_name (str): Optional. The key is a name of one of the Dataset's data columns. The value of the key (either the label's value or @@ -1665,73 +2127,326 @@ def _run( ignored by the pipeline. Supported only for tabular and time series Datasets. + timestamp_split_column_name (str): + Optional. The key is a name of one of the Dataset's data + columns. The value of the key values of the key (the values in + the column) must be in RFC 3339 `date-time` format, where + `time-offset` = `"Z"` (e.g. 1985-04-12T23:20:50.52Z). If for a + piece of data the key is not present or has an invalid value, + that piece is ignored by the pipeline. + Supported only for tabular and time series Datasets. + This parameter must be used with training_fraction_split, + validation_fraction_split, and test_fraction_split. + weight_column (str): + Optional. Name of the column that should be used as the weight column. + Higher values in this column give more importance to the row + during Model training. The column must have numeric values between 0 and + 10000 inclusively, and 0 value means that the row is ignored. + If the weight column field is not set, then all rows are assumed to have + equal weight of 1. This column must be available at forecast. + time_series_attribute_columns (List[str]): + Optional. Column names that should be used as attribute columns. + Each column is constant within a time series. + context_window (int): + Optional. The amount of time into the past training and prediction data is used for + model training and prediction respectively. Expressed in number of units defined by the + [data_granularity_unit] and [data_granularity_count] fields. When not provided uses the + default value of 0 which means the model sets each series context window to be 0 (also + known as "cold start"). Inclusive. + export_evaluated_data_items (bool): + Whether to export the test set predictions to a BigQuery table. + If False, then the export is not performed. + export_evaluated_data_items_bigquery_destination_uri (string): + Optional. URI of desired destination BigQuery table for exported test set predictions. + + Expected format: + ``bq://::
`` + + If not specified, then results are exported to the following auto-created BigQuery + table: + ``:export_evaluated_examples__.evaluated_examples`` + + Applies only if [export_evaluated_data_items] is True. + export_evaluated_data_items_override_destination (bool): + Whether to override the contents of [export_evaluated_data_items_bigquery_destination_uri], + if the table exists, for exported test set predictions. If False, and the + table exists, then the training job will fail. + + Applies only if [export_evaluated_data_items] is True and + [export_evaluated_data_items_bigquery_destination_uri] is specified. + quantiles (List[float]): + Quantiles to use for the `minimize-quantile-loss` + [AutoMLForecastingTrainingJob.optimization_objective]. This argument is required in + this case. + + Accepts up to 5 quantiles in the form of a double from 0 to 1, exclusive. + Each quantile must be unique. + validation_options (str): + Validation options for the data validation component. The available options are: + "fail-pipeline" - (default), will validate against the validation and fail the pipeline + if it fails. + "ignore-validation" - ignore the results of the validation and continue the pipeline + budget_milli_node_hours (int): + Optional. The train budget of creating this Model, expressed in milli node + hours i.e. 1,000 value in this field means 1 node hour. + The training cost of the model will not exceed this budget. The final + cost will be attempted to be close to the budget, though may end up + being (even) noticeably smaller - at the backend's discretion. This + especially may happen when further model training ceases to provide + any improvements. + If the budget is set to a value known to be insufficient to train a + Model for the given training set, the training won't be attempted and + will error. + The minimum value is 1000 and the maximum is 72000. + model_display_name (str): + Optional. If the script produces a managed Vertex AI Model. The display name of + the Model. The name can be up to 128 characters long and can be consist + of any UTF-8 characters. + + If not provided upon creation, the job's display_name is used. + model_labels (Dict[str, str]): + Optional. The labels with user-defined metadata to + organize your Models. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + and examples of labels. + hierarchy_group_columns (List[str]): + Optional. A list of time series attribute column names that + define the time series hierarchy. Only one level of hierarchy is + supported, ex. ``region`` for a hierarchy of stores or + ``department`` for a hierarchy of products. If multiple columns + are specified, time series will be grouped by their combined + values, ex. (``blue``, ``large``) for ``color`` and ``size``, up + to 5 columns are accepted. If no group columns are specified, + all time series are considered to be part of the same group. + hierarchy_group_total_weight (float): + Optional. The weight of the loss for predictions aggregated over + time series in the same hierarchy group. + hierarchy_temporal_total_weight (float): + Optional. The weight of the loss for predictions aggregated over + the horizon for a single time series. + hierarchy_group_temporal_total_weight (float): + Optional. The weight of the loss for predictions aggregated over + both the horizon and time series in the same hierarchy group. + window_column (str): + Optional. Name of the column that should be used to filter input + rows. The column should contain either booleans or string + booleans; if the value of the row is True, generate a sliding + window from that row. + window_stride_length (int): + Optional. Step length used to generate input examples. Every + ``window_stride_length`` rows will be used to generate a sliding + window. + window_max_count (int): + Optional. Number of rows that should be used to generate input + examples. If the total row count is larger than this number, the + input data will be randomly sampled to hit the count. + holiday_regions (List[str]): + Optional. The geographical regions to use when creating holiday + features. This option is only allowed when data_granularity_unit + is ``day``. Acceptable values can come from any of the following + levels: + Top level: GLOBAL + Second level: continental regions + NA: North America + JAPAC: Japan and Asia Pacific + EMEA: Europe, the Middle East and Africa + LAC: Latin America and the Caribbean + Third level: countries from ISO 3166-1 Country codes. sync (bool): Whether to execute this method synchronously. If False, this method will be executed in concurrent Future and any downstream object will be immediately returned and synced when the Future has completed. - + create_request_timeout (float): + Optional. The timeout for the create request in seconds. Returns: model: The trained Vertex AI Model resource or None if training did not - produce an Vertex AI Model. + produce a Vertex AI Model. """ - package_gcs_uri = python_packager.package_and_copy_to_gcs( - gcs_staging_dir=self._staging_bucket, - project=self.project, - credentials=self.credentials, + # auto-populate transformations + if self._column_transformations is None: + _LOGGER.info( + "No column transformations provided, so now retrieving columns from dataset in order to set default column transformations." + ) + + ( + self._column_transformations, + column_names, + ) = dataset._get_default_column_transformations(target_column) + + _LOGGER.info( + "The column transformation of type 'auto' was set for the following columns: %s." + % column_names + ) + + window_config = self._create_window_config( + column=window_column, + stride_length=window_stride_length, + max_count=window_max_count, ) - for spec in worker_pool_specs: - spec["python_package_spec"] = { - "executor_image_uri": self._container_uri, - "python_module": python_packager.module_name, - "package_uris": [package_gcs_uri], + training_task_inputs_dict = { + # required inputs + "targetColumn": target_column, + "timeColumn": time_column, + "timeSeriesIdentifierColumn": time_series_identifier_column, + "timeSeriesAttributeColumns": time_series_attribute_columns, + "unavailableAtForecastColumns": unavailable_at_forecast_columns, + "availableAtForecastColumns": available_at_forecast_columns, + "forecastHorizon": forecast_horizon, + "dataGranularity": { + "unit": data_granularity_unit, + "quantity": data_granularity_count, + }, + "transformations": self._column_transformations, + "trainBudgetMilliNodeHours": budget_milli_node_hours, + # optional inputs + "weightColumn": weight_column, + "contextWindow": context_window, + "quantiles": quantiles, + "validationOptions": validation_options, + "optimizationObjective": self._optimization_objective, + "holidayRegions": holiday_regions, + } + + # TODO(TheMichaelHu): Remove the ifs once the API supports these inputs. + if any( + [ + hierarchy_group_columns, + hierarchy_group_total_weight, + hierarchy_temporal_total_weight, + hierarchy_group_temporal_total_weight, + ] + ): + training_task_inputs_dict["hierarchyConfig"] = { + "groupColumns": hierarchy_group_columns, + "groupTotalWeight": hierarchy_group_total_weight, + "temporalTotalWeight": hierarchy_temporal_total_weight, + "groupTemporalTotalWeight": hierarchy_group_temporal_total_weight, } + if window_config: + training_task_inputs_dict["windowConfig"] = window_config - if args: - spec["python_package_spec"]["args"] = args + final_export_eval_bq_uri = export_evaluated_data_items_bigquery_destination_uri + if final_export_eval_bq_uri and not final_export_eval_bq_uri.startswith( + "bq://" + ): + final_export_eval_bq_uri = f"bq://{final_export_eval_bq_uri}" - if environment_variables: - spec["python_package_spec"]["env"] = [ - {"name": key, "value": value} - for key, value in environment_variables.items() - ] + if export_evaluated_data_items: + training_task_inputs_dict["exportEvaluatedDataItemsConfig"] = { + "destinationBigqueryUri": final_export_eval_bq_uri, + "overrideExistingTable": export_evaluated_data_items_override_destination, + } - ( - training_task_inputs, - base_output_dir, - ) = self._prepare_training_task_inputs_and_output_dir( - worker_pool_specs=worker_pool_specs, - base_output_dir=base_output_dir, - service_account=service_account, - network=network, + if self._additional_experiments: + training_task_inputs_dict[ + "additionalExperiments" + ] = self._additional_experiments + + model = gca_model.Model( + display_name=model_display_name or self._display_name, + labels=model_labels or self._labels, + encryption_spec=self._model_encryption_spec, ) - model = self._run_job( - training_task_definition=schema.training_job.definition.custom_task, - training_task_inputs=training_task_inputs, + new_model = self._run_job( + training_task_definition=self._training_task_definition, + training_task_inputs=training_task_inputs_dict, dataset=dataset, - annotation_schema_uri=annotation_schema_uri, training_fraction_split=training_fraction_split, validation_fraction_split=validation_fraction_split, test_fraction_split=test_fraction_split, predefined_split_column_name=predefined_split_column_name, - model=managed_model, - gcs_destination_uri_prefix=base_output_dir, - bigquery_destination=bigquery_destination, + timestamp_split_column_name=timestamp_split_column_name, + model=model, + create_request_timeout=create_request_timeout, ) - return model + if export_evaluated_data_items: + _LOGGER.info( + "Exported examples available at:\n%s" + % self.evaluated_data_items_bigquery_uri + ) + return new_model -class CustomContainerTrainingJob(_CustomTrainingJob): - """Class to launch a Custom Training Job in Vertex AI using a - Container.""" + @property + def _model_upload_fail_string(self) -> str: + """Helper property for model upload failure.""" + return ( + f"Training Pipeline {self.resource_name} is not configured to upload a " + "Model." + ) + + @property + def evaluated_data_items_bigquery_uri(self) -> Optional[str]: + """BigQuery location of exported evaluated examples from the Training Job + Returns: + str: BigQuery uri for the exported evaluated examples if the export + feature is enabled for training. + None: If the export feature was not enabled for training. + """ + + self._assert_gca_resource_is_available() + + metadata = self._gca_resource.training_task_metadata + if metadata and "evaluatedDataItemsBigqueryUri" in metadata: + return metadata["evaluatedDataItemsBigqueryUri"] + + return None + + def _add_additional_experiments(self, additional_experiments: List[str]): + """Add experiment flags to the training job. + Args: + additional_experiments (List[str]): + Experiment flags that can enable some experimental training features. + """ + self._additional_experiments.extend(additional_experiments) + + @staticmethod + def _create_window_config( + column: Optional[str] = None, + stride_length: Optional[int] = None, + max_count: Optional[int] = None, + ) -> Optional[Dict[str, Union[int, str]]]: + """Creates a window config from training job arguments.""" + configs = { + "column": column, + "strideLength": stride_length, + "maxCount": max_count, + } + present_configs = {k: v for k, v in configs.items() if v is not None} + if not present_configs: + return None + if len(present_configs) > 1: + raise ValueError( + "More than one windowing strategy provided. Make sure only one " + "of window_column, window_stride_length, or window_max_count " + "is specified." + ) + return present_configs + + +# TODO(b/172368325) add scheduling, custom_job.Scheduling +class CustomTrainingJob(_CustomTrainingJob): + """Class to launch a Custom Training Job in Vertex AI using a script. + + Takes a training implementation as a python script and executes that + script in Cloud Vertex AI Training. + """ def __init__( self, + # TODO(b/223262536): Make display_name parameter fully optional in next major release display_name: str, + script_path: str, container_uri: str, - command: Sequence[str] = None, + requirements: Optional[Sequence[str]] = None, model_serving_container_image_uri: Optional[str] = None, model_serving_container_predict_route: Optional[str] = None, model_serving_container_health_route: Optional[str] = None, @@ -1746,26 +2461,35 @@ def __init__( project: Optional[str] = None, location: Optional[str] = None, credentials: Optional[auth_credentials.Credentials] = None, + labels: Optional[Dict[str, str]] = None, training_encryption_spec_key_name: Optional[str] = None, model_encryption_spec_key_name: Optional[str] = None, staging_bucket: Optional[str] = None, ): - """Constructs a Custom Container Training Job. + """Constructs a Custom Training Job from a Python script. job = aiplatform.CustomTrainingJob( display_name='test-train', + script_path='test_script.py', + requirements=['pandas', 'numpy'], container_uri='gcr.io/cloud-aiplatform/training/tf-cpu.2-2:latest', - command=['python3', 'run_script.py'] model_serving_container_image_uri='gcr.io/my-trainer/serving:1', model_serving_container_predict_route='predict', - model_serving_container_health_route='metadata) + model_serving_container_health_route='metadata, + labels={'key': 'value'}, + ) Usage with Dataset: ds = aiplatform.TabularDataset( 'projects/my-project/locations/us-central1/datasets/12345') - job.run(ds, replica_count=1, model_display_name='my-trained-model') + job.run( + ds, + replica_count=1, + model_display_name='my-trained-model', + model_labels={'key': 'value'}, + ) Usage without Dataset: @@ -1780,11 +2504,11 @@ def __init__( Args: display_name (str): Required. The user-defined name of this TrainingPipeline. + script_path (str): Required. Local path to training script. container_uri (str): Required: Uri of the training container image in the GCR. - command (Sequence[str]): - The command to be invoked when the container is started. - It overrides the entrypoint instruction in Dockerfile when provided + requirements (Sequence[str]): + List of python packages dependencies of script. model_serving_container_image_uri (str): If the training produces a managed Vertex AI Model, the URI of the Model serving container suitable for serving the model produced by the @@ -1879,6 +2603,16 @@ def __init__( credentials (auth_credentials.Credentials): Custom credentials to use to run call training service. Overrides credentials set in aiplatform.init. + labels (Dict[str, str]): + Optional. The labels with user-defined metadata to + organize TrainingPipelines. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + and examples of labels. training_encryption_spec_key_name (Optional[str]): Optional. The Cloud KMS resource identifier of the customer managed encryption key used to protect the training pipeline. Has the @@ -1908,11 +2642,14 @@ def __init__( Bucket used to stage source and training artifacts. Overrides staging_bucket set in aiplatform.init. """ + if not display_name: + display_name = self.__class__._generate_display_name() super().__init__( display_name=display_name, project=project, location=location, credentials=credentials, + labels=labels, training_encryption_spec_key_name=training_encryption_spec_key_name, model_encryption_spec_key_name=model_encryption_spec_key_name, container_uri=container_uri, @@ -1930,10 +2667,9 @@ def __init__( staging_bucket=staging_bucket, ) - self._command = command + self._requirements = requirements + self._script_path = script_path - # TODO(b/172365904) add filter split, training_pipeline.FilterSplit - # TODO(b/172368070) add timestamp split, training_pipeline.TimestampSplit def run( self, dataset: Optional[ @@ -1946,21 +2682,36 @@ def run( ] = None, annotation_schema_uri: Optional[str] = None, model_display_name: Optional[str] = None, + model_labels: Optional[Dict[str, str]] = None, base_output_dir: Optional[str] = None, service_account: Optional[str] = None, network: Optional[str] = None, bigquery_destination: Optional[str] = None, args: Optional[List[Union[str, float, int]]] = None, environment_variables: Optional[Dict[str, str]] = None, - replica_count: int = 0, + replica_count: int = 1, machine_type: str = "n1-standard-4", accelerator_type: str = "ACCELERATOR_TYPE_UNSPECIFIED", accelerator_count: int = 0, - training_fraction_split: float = 0.8, - validation_fraction_split: float = 0.1, - test_fraction_split: float = 0.1, + boot_disk_type: str = "pd-ssd", + boot_disk_size_gb: int = 100, + reduction_server_replica_count: int = 0, + reduction_server_machine_type: Optional[str] = None, + reduction_server_container_uri: Optional[str] = None, + training_fraction_split: Optional[float] = None, + validation_fraction_split: Optional[float] = None, + test_fraction_split: Optional[float] = None, + training_filter_split: Optional[str] = None, + validation_filter_split: Optional[str] = None, + test_filter_split: Optional[str] = None, predefined_split_column_name: Optional[str] = None, + timestamp_split_column_name: Optional[str] = None, + timeout: Optional[int] = None, + restart_job_on_worker_restart: bool = False, + enable_web_access: bool = False, + tensorboard: Optional[str] = None, sync=True, + create_request_timeout: Optional[float] = None, ) -> Optional[models.Model]: """Runs the custom training job. @@ -1970,15 +2721,46 @@ def run( ie: replica_count = 10 will result in 1 chief and 9 workers All replicas have same machine_type, accelerator_type, and accelerator_count - Data fraction splits: - Any of ``training_fraction_split``, ``validation_fraction_split`` and - ``test_fraction_split`` may optionally be provided, they must sum to up to 1. If - the provided ones sum to less than 1, the remainder is assigned to sets as - decided by Vertex AI. If none of the fractions are set, by default roughly 80% - of data will be used for training, 10% for validation, and 10% for test. + If training on a Vertex AI dataset, you can use one of the following split configurations: + Data fraction splits: + Any of ``training_fraction_split``, ``validation_fraction_split`` and + ``test_fraction_split`` may optionally be provided, they must sum to up to 1. If + the provided ones sum to less than 1, the remainder is assigned to sets as + decided by Vertex AI. If none of the fractions are set, by default roughly 80% + of data will be used for training, 10% for validation, and 10% for test. + + Data filter splits: + Assigns input data to training, validation, and test sets + based on the given filters, data pieces not matched by any + filter are ignored. Currently only supported for Datasets + containing DataItems. + If any of the filters in this message are to match nothing, then + they can be set as '-' (the minus sign). + If using filter splits, all of ``training_filter_split``, ``validation_filter_split`` and + ``test_filter_split`` must be provided. + Supported only for unstructured Datasets. + + Predefined splits: + Assigns input data to training, validation, and test sets based on the value of a provided key. + If using predefined splits, ``predefined_split_column_name`` must be provided. + Supported only for tabular Datasets. + + Timestamp splits: + Assigns input data to training, validation, and test sets + based on a provided timestamps. The youngest data pieces are + assigned to training set, next to validation set, and the oldest + to the test set. + Supported only for tabular Datasets. Args: - dataset (Union[datasets.ImageDataset,datasets.TabularDataset,datasets.TextDataset,datasets.VideoDataset]): + dataset ( + Union[ + datasets.ImageDataset, + datasets.TabularDataset, + datasets.TextDataset, + datasets.VideoDataset, + ] + ): Vertex AI to fit this training against. Custom training script should retrieve datasets through passed in environment variables uris: @@ -1992,7 +2774,7 @@ def run( annotation_schema_uri (str): Google Cloud Storage URI points to a YAML file describing annotation schema. The schema is defined as an OpenAPI 3.0.2 - [Schema Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#schema-object) The schema files + [Schema Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.2.md#schema-object) The schema files that can be used here are found in gs://google-cloud-aiplatform/schema/dataset/annotation/, note that the chosen schema must be consistent with @@ -2017,6 +2799,16 @@ def run( of any UTF-8 characters. If not provided upon creation, the job's display_name is used. + model_labels (Dict[str, str]): + Optional. The labels with user-defined metadata to + organize your Models. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + and examples of labels. base_output_dir (str): GCS output directory of job. If not provided a timestamped directory in the staging directory will be used. @@ -2074,15 +2866,50 @@ def run( NVIDIA_TESLA_T4 accelerator_count (int): The number of accelerators to attach to a worker replica. + boot_disk_type (str): + Type of the boot disk, default is `pd-ssd`. + Valid values: `pd-ssd` (Persistent Disk Solid State Drive) or + `pd-standard` (Persistent Disk Hard Disk Drive). + boot_disk_size_gb (int): + Size in GB of the boot disk, default is 100GB. + boot disk size must be within the range of [100, 64000]. + reduction_server_replica_count (int): + The number of reduction server replicas, default is 0. + reduction_server_machine_type (str): + Optional. The type of machine to use for reduction server. + reduction_server_container_uri (str): + Optional. The Uri of the reduction server container image. + See details: https://cloud.google.com/vertex-ai/docs/training/distributed-training#reduce_training_time_with_reduction_server training_fraction_split (float): - The fraction of the input data that is to be - used to train the Model. This is ignored if Dataset is not provided. + Optional. The fraction of the input data that is to be used to train + the Model. This is ignored if Dataset is not provided. validation_fraction_split (float): - The fraction of the input data that is to be - used to validate the Model. This is ignored if Dataset is not provided. + Optional. The fraction of the input data that is to be used to validate + the Model. This is ignored if Dataset is not provided. test_fraction_split (float): - The fraction of the input data that is to be - used to evaluate the Model. This is ignored if Dataset is not provided. + Optional. The fraction of the input data that is to be used to evaluate + the Model. This is ignored if Dataset is not provided. + training_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to train the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. + validation_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to validate the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. + test_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to test the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. predefined_split_column_name (str): Optional. The key is a name of one of the Dataset's data columns. The value of the key (either the label's value or @@ -2093,6 +2920,43 @@ def run( ignored by the pipeline. Supported only for tabular and time series Datasets. + timestamp_split_column_name (str): + Optional. The key is a name of one of the Dataset's data + columns. The value of the key values of the key (the values in + the column) must be in RFC 3339 `date-time` format, where + `time-offset` = `"Z"` (e.g. 1985-04-12T23:20:50.52Z). If for a + piece of data the key is not present or has an invalid value, + that piece is ignored by the pipeline. + + Supported only for tabular and time series Datasets. + timeout (int): + The maximum job running time in seconds. The default is 7 days. + restart_job_on_worker_restart (bool): + Restarts the entire CustomJob if a worker + gets restarted. This feature can be used by + distributed training jobs that are not resilient + to workers leaving and joining a job. + enable_web_access (bool): + Whether you want Vertex AI to enable interactive shell access + to training containers. + https://cloud.google.com/vertex-ai/docs/training/monitor-debug-interactive-shell + tensorboard (str): + Optional. The name of a Vertex AI + [Tensorboard][google.cloud.aiplatform.v1beta1.Tensorboard] + resource to which this CustomJob will upload Tensorboard + logs. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}`` + + The training script should write Tensorboard to following Vertex AI environment + variable: + + AIP_TENSORBOARD_LOG_DIR + + `service_account` is required with provided `tensorboard`. + For more information on configuring your service account please visit: + https://cloud.google.com/vertex-ai/docs/experiments/tensorboard-training + create_request_timeout (float): + Optional. The timeout for the create request in seconds. sync (bool): Whether to execute this method synchronously. If False, this method will be executed in concurrent Future and any downstream object will @@ -2100,22 +2964,28 @@ def run( Returns: model: The trained Vertex AI Model resource or None if training did not - produce an Vertex AI Model. - - Raises: - RuntimeError: If Training job has already been run, staging_bucket has not - been set, or model_display_name was provided but required arguments - were not provided in constructor. + produce a Vertex AI Model. """ worker_pool_specs, managed_model = self._prepare_and_validate_run( model_display_name=model_display_name, + model_labels=model_labels, replica_count=replica_count, machine_type=machine_type, accelerator_count=accelerator_count, accelerator_type=accelerator_type, + boot_disk_type=boot_disk_type, + boot_disk_size_gb=boot_disk_size_gb, + reduction_server_replica_count=reduction_server_replica_count, + reduction_server_machine_type=reduction_server_machine_type, + ) + + # make and copy package + python_packager = source_utils._TrainingScriptPythonPackager( + script_path=self._script_path, requirements=self._requirements ) return self._run( + python_packager=python_packager, dataset=dataset, annotation_schema_uri=annotation_schema_uri, worker_pool_specs=worker_pool_specs, @@ -2129,13 +2999,26 @@ def run( training_fraction_split=training_fraction_split, validation_fraction_split=validation_fraction_split, test_fraction_split=test_fraction_split, + training_filter_split=training_filter_split, + validation_filter_split=validation_filter_split, + test_filter_split=test_filter_split, predefined_split_column_name=predefined_split_column_name, + timestamp_split_column_name=timestamp_split_column_name, + timeout=timeout, + restart_job_on_worker_restart=restart_job_on_worker_restart, + enable_web_access=enable_web_access, + tensorboard=tensorboard, + reduction_server_container_uri=reduction_server_container_uri + if reduction_server_replica_count > 0 + else None, sync=sync, + create_request_timeout=create_request_timeout, ) @base.optional_sync(construct_object_on_arg="managed_model") def _run( self, + python_packager: source_utils._TrainingScriptPythonPackager, dataset: Optional[ Union[ datasets.ImageDataset, @@ -2153,14 +3036,27 @@ def _run( service_account: Optional[str] = None, network: Optional[str] = None, bigquery_destination: Optional[str] = None, - training_fraction_split: float = 0.8, - validation_fraction_split: float = 0.1, - test_fraction_split: float = 0.1, + training_fraction_split: Optional[float] = None, + validation_fraction_split: Optional[float] = None, + test_fraction_split: Optional[float] = None, + training_filter_split: Optional[str] = None, + validation_filter_split: Optional[str] = None, + test_filter_split: Optional[str] = None, predefined_split_column_name: Optional[str] = None, + timestamp_split_column_name: Optional[str] = None, + timeout: Optional[int] = None, + restart_job_on_worker_restart: bool = False, + enable_web_access: bool = False, + tensorboard: Optional[str] = None, + reduction_server_container_uri: Optional[str] = None, sync=True, + create_request_timeout: Optional[float] = None, ) -> Optional[models.Model]: """Packages local script and launches training_job. + Args: + python_packager (source_utils._TrainingScriptPythonPackager): + Required. Python Packager pointing to training script locally. dataset ( Union[ datasets.ImageDataset, @@ -2208,6 +3104,7 @@ def _run( Private services access must already be configured for the network. If left unspecified, the job is not peered with any network. bigquery_destination (str): + Provide this field if `dataset` is a BiqQuery dataset. The BigQuery project location where the training data is to be written to. In the given project a new dataset is created with name @@ -2222,14 +3119,35 @@ def _run( - AIP_VALIDATION_DATA_URI = "bigquery_destination.dataset_*.validation" - AIP_TEST_DATA_URI = "bigquery_destination.dataset_*.test" training_fraction_split (float): - The fraction of the input data that is to be - used to train the Model. + Optional. The fraction of the input data that is to be used to train + the Model. This is ignored if Dataset is not provided. validation_fraction_split (float): - The fraction of the input data that is to be - used to validate the Model. + Optional. The fraction of the input data that is to be used to validate + the Model. This is ignored if Dataset is not provided. test_fraction_split (float): - The fraction of the input data that is to be - used to evaluate the Model. + Optional. The fraction of the input data that is to be used to evaluate + the Model. This is ignored if Dataset is not provided. + training_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to train the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. + validation_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to validate the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. + test_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to test the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. predefined_split_column_name (str): Optional. The key is a name of one of the Dataset's data columns. The value of the key (either the label's value or @@ -2240,30 +3158,87 @@ def _run( ignored by the pipeline. Supported only for tabular and time series Datasets. + timestamp_split_column_name (str): + Optional. The key is a name of one of the Dataset's data + columns. The value of the key values of the key (the values in + the column) must be in RFC 3339 `date-time` format, where + `time-offset` = `"Z"` (e.g. 1985-04-12T23:20:50.52Z). If for a + piece of data the key is not present or has an invalid value, + that piece is ignored by the pipeline. + + Supported only for tabular and time series Datasets. + timeout (int): + The maximum job running time in seconds. The default is 7 days. + restart_job_on_worker_restart (bool): + Restarts the entire CustomJob if a worker + gets restarted. This feature can be used by + distributed training jobs that are not resilient + to workers leaving and joining a job. + enable_web_access (bool): + Whether you want Vertex AI to enable interactive shell access + to training containers. + https://cloud.google.com/vertex-ai/docs/training/monitor-debug-interactive-shell + tensorboard (str): + Optional. The name of a Vertex AI + [Tensorboard][google.cloud.aiplatform.v1beta1.Tensorboard] + resource to which this CustomJob will upload Tensorboard + logs. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}`` + + The training script should write Tensorboard to following Vertex AI environment + variable: + + AIP_TENSORBOARD_LOG_DIR + + `service_account` is required with provided `tensorboard`. + For more information on configuring your service account please visit: + https://cloud.google.com/vertex-ai/docs/experiments/tensorboard-training + reduction_server_container_uri (str): + Optional. The Uri of the reduction server container image. sync (bool): Whether to execute this method synchronously. If False, this method will be executed in concurrent Future and any downstream object will be immediately returned and synced when the Future has completed. + create_request_timeout (float) + Optional. The timeout for the create request in seconds Returns: model: The trained Vertex AI Model resource or None if training did not - produce an Vertex AI Model. + produce a Vertex AI Model. """ + package_gcs_uri = python_packager.package_and_copy_to_gcs( + gcs_staging_dir=self._staging_bucket, + project=self.project, + credentials=self.credentials, + ) - for spec in worker_pool_specs: - spec["containerSpec"] = {"imageUri": self._container_uri} + for spec_order, spec in enumerate(worker_pool_specs): - if self._command: - spec["containerSpec"]["command"] = self._command + if not spec: + continue - if args: - spec["containerSpec"]["args"] = args + if ( + spec_order == worker_spec_utils._SPEC_ORDERS["server_spec"] + and reduction_server_container_uri + ): + spec["container_spec"] = { + "image_uri": reduction_server_container_uri, + } + else: + spec["python_package_spec"] = { + "executor_image_uri": self._container_uri, + "python_module": python_packager.module_name, + "package_uris": [package_gcs_uri], + } - if environment_variables: - spec["containerSpec"]["env"] = [ - {"name": key, "value": value} - for key, value in environment_variables.items() - ] + if args: + spec["python_package_spec"]["args"] = args + + if environment_variables: + spec["python_package_spec"]["env"] = [ + {"name": key, "value": value} + for key, value in environment_variables.items() + ] ( training_task_inputs, @@ -2273,6 +3248,10 @@ def _run( base_output_dir=base_output_dir, service_account=service_account, network=network, + timeout=timeout, + restart_job_on_worker_restart=restart_job_on_worker_restart, + enable_web_access=enable_web_access, + tensorboard=tensorboard, ) model = self._run_job( @@ -2283,101 +3262,195 @@ def _run( training_fraction_split=training_fraction_split, validation_fraction_split=validation_fraction_split, test_fraction_split=test_fraction_split, + training_filter_split=training_filter_split, + validation_filter_split=validation_filter_split, + test_filter_split=test_filter_split, predefined_split_column_name=predefined_split_column_name, + timestamp_split_column_name=timestamp_split_column_name, model=managed_model, gcs_destination_uri_prefix=base_output_dir, bigquery_destination=bigquery_destination, + create_request_timeout=create_request_timeout, ) return model -class AutoMLTabularTrainingJob(_TrainingJob): - _supported_training_schemas = (schema.training_job.definition.automl_tabular,) +class CustomContainerTrainingJob(_CustomTrainingJob): + """Class to launch a Custom Training Job in Vertex AI using a + Container.""" def __init__( self, + # TODO(b/223262536): Make display_name parameter fully optional in next major release display_name: str, - optimization_prediction_type: str, - optimization_objective: Optional[str] = None, - column_transformations: Optional[Union[Dict, List[Dict]]] = None, - optimization_objective_recall_value: Optional[float] = None, - optimization_objective_precision_value: Optional[float] = None, + container_uri: str, + command: Sequence[str] = None, + model_serving_container_image_uri: Optional[str] = None, + model_serving_container_predict_route: Optional[str] = None, + model_serving_container_health_route: Optional[str] = None, + model_serving_container_command: Optional[Sequence[str]] = None, + model_serving_container_args: Optional[Sequence[str]] = None, + model_serving_container_environment_variables: Optional[Dict[str, str]] = None, + model_serving_container_ports: Optional[Sequence[int]] = None, + model_description: Optional[str] = None, + model_instance_schema_uri: Optional[str] = None, + model_parameters_schema_uri: Optional[str] = None, + model_prediction_schema_uri: Optional[str] = None, project: Optional[str] = None, location: Optional[str] = None, credentials: Optional[auth_credentials.Credentials] = None, + labels: Optional[Dict[str, str]] = None, training_encryption_spec_key_name: Optional[str] = None, model_encryption_spec_key_name: Optional[str] = None, + staging_bucket: Optional[str] = None, ): - """Constructs a AutoML Tabular Training Job. + """Constructs a Custom Container Training Job. - Args: - display_name (str): - Required. The user-defined name of this TrainingPipeline. - optimization_prediction_type (str): - The type of prediction the Model is to produce. - "classification" - Predict one out of multiple target values is - picked for each row. - "regression" - Predict a value based on its relation to other values. - This type is available only to columns that contain - semantically numeric values, i.e. integers or floating - point number, even if stored as e.g. strings. + job = aiplatform.CustomContainerTrainingJob( + display_name='test-train', + container_uri='gcr.io/my_project_id/my_image_name:tag', + command=['python3', 'run_script.py'] + model_serving_container_image_uri='gcr.io/my-trainer/serving:1', + model_serving_container_predict_route='predict', + model_serving_container_health_route='metadata, + labels={'key': 'value'}, + ) - optimization_objective (str): - Optional. Objective function the Model is to be optimized towards. The training - task creates a Model that maximizes/minimizes the value of the objective - function over the validation set. + Usage with Dataset: - The supported optimization objectives depend on the prediction type, and - in the case of classification also the number of distinct values in the - target column (two distint values -> binary, 3 or more distinct values - -> multi class). - If the field is not set, the default objective function is used. + ds = aiplatform.TabularDataset( + 'projects/my-project/locations/us-central1/datasets/12345') - Classification (binary): - "maximize-au-roc" (default) - Maximize the area under the receiver - operating characteristic (ROC) curve. - "minimize-log-loss" - Minimize log loss. - "maximize-au-prc" - Maximize the area under the precision-recall curve. - "maximize-precision-at-recall" - Maximize precision for a specified - recall value. - "maximize-recall-at-precision" - Maximize recall for a specified - precision value. + job.run( + ds, + replica_count=1, + model_display_name='my-trained-model', + model_labels={'key': 'value'}, + ) - Classification (multi class): - "minimize-log-loss" (default) - Minimize log loss. + Usage without Dataset: - Regression: - "minimize-rmse" (default) - Minimize root-mean-squared error (RMSE). - "minimize-mae" - Minimize mean-absolute error (MAE). - "minimize-rmsle" - Minimize root-mean-squared log error (RMSLE). - column_transformations (Optional[Union[Dict, List[Dict]]]): - Optional. Transformations to apply to the input columns (i.e. columns other - than the targetColumn). Each transformation may produce multiple - result values from the column's value, and all are used for training. - When creating transformation for BigQuery Struct column, the column - should be flattened using "." as the delimiter. - If an input column has no transformations on it, such a column is - ignored by the training, except for the targetColumn, which should have - no transformations defined on. - optimization_objective_recall_value (float): - Optional. Required when maximize-precision-at-recall optimizationObjective was - picked, represents the recall value at which the optimization is done. + job.run(replica_count=1, model_display_name='my-trained-model) - The minimum value is 0 and the maximum is 1.0. - optimization_objective_precision_value (float): - Optional. Required when maximize-recall-at-precision optimizationObjective was - picked, represents the precision value at which the optimization is - done. - The minimum value is 0 and the maximum is 1.0. + TODO(b/169782082) add documentation about traning utilities + To ensure your model gets saved in Vertex AI, write your saved model to + os.environ["AIP_MODEL_DIR"] in your provided training script. + + + Args: + display_name (str): + Required. The user-defined name of this TrainingPipeline. + container_uri (str): + Required: Uri of the training container image in the GCR. + command (Sequence[str]): + The command to be invoked when the container is started. + It overrides the entrypoint instruction in Dockerfile when provided + model_serving_container_image_uri (str): + If the training produces a managed Vertex AI Model, the URI of the + Model serving container suitable for serving the model produced by the + training script. + model_serving_container_predict_route (str): + If the training produces a managed Vertex AI Model, An HTTP path to + send prediction requests to the container, and which must be supported + by it. If not specified a default HTTP path will be used by Vertex AI. + model_serving_container_health_route (str): + If the training produces a managed Vertex AI Model, an HTTP path to + send health check requests to the container, and which must be supported + by it. If not specified a standard HTTP path will be used by AI + Platform. + model_serving_container_command (Sequence[str]): + The command with which the container is run. Not executed within a + shell. The Docker image's ENTRYPOINT is used if this is not provided. + Variable references $(VAR_NAME) are expanded using the container's + environment. If a variable cannot be resolved, the reference in the + input string will be unchanged. The $(VAR_NAME) syntax can be escaped + with a double $$, ie: $$(VAR_NAME). Escaped references will never be + expanded, regardless of whether the variable exists or not. + model_serving_container_args (Sequence[str]): + The arguments to the command. The Docker image's CMD is used if this is + not provided. Variable references $(VAR_NAME) are expanded using the + container's environment. If a variable cannot be resolved, the reference + in the input string will be unchanged. The $(VAR_NAME) syntax can be + escaped with a double $$, ie: $$(VAR_NAME). Escaped references will + never be expanded, regardless of whether the variable exists or not. + model_serving_container_environment_variables (Dict[str, str]): + The environment variables that are to be present in the container. + Should be a dictionary where keys are environment variable names + and values are environment variable values for those names. + model_serving_container_ports (Sequence[int]): + Declaration of ports that are exposed by the container. This field is + primarily informational, it gives Vertex AI information about the + network connections the container uses. Listing or not a port here has + no impact on whether the port is actually exposed, any port listening on + the default "0.0.0.0" address inside a container will be accessible from + the network. + model_description (str): + The description of the Model. + model_instance_schema_uri (str): + Optional. Points to a YAML file stored on Google Cloud + Storage describing the format of a single instance, which + are used in + ``PredictRequest.instances``, + ``ExplainRequest.instances`` + and + ``BatchPredictionJob.input_config``. + The schema is defined as an OpenAPI 3.0.2 `Schema + Object `__. + AutoML Models always have this field populated by AI + Platform. Note: The URI given on output will be immutable + and probably different, including the URI scheme, than the + one given on input. The output URI will point to a location + where the user only has a read access. + model_parameters_schema_uri (str): + Optional. Points to a YAML file stored on Google Cloud + Storage describing the parameters of prediction and + explanation via + ``PredictRequest.parameters``, + ``ExplainRequest.parameters`` + and + ``BatchPredictionJob.model_parameters``. + The schema is defined as an OpenAPI 3.0.2 `Schema + Object `__. + AutoML Models always have this field populated by AI + Platform, if no parameters are supported it is set to an + empty string. Note: The URI given on output will be + immutable and probably different, including the URI scheme, + than the one given on input. The output URI will point to a + location where the user only has a read access. + model_prediction_schema_uri (str): + Optional. Points to a YAML file stored on Google Cloud + Storage describing the format of a single prediction + produced by this Model, which are returned via + ``PredictResponse.predictions``, + ``ExplainResponse.explanations``, + and + ``BatchPredictionJob.output_config``. + The schema is defined as an OpenAPI 3.0.2 `Schema + Object `__. + AutoML Models always have this field populated by AI + Platform. Note: The URI given on output will be immutable + and probably different, including the URI scheme, than the + one given on input. The output URI will point to a location + where the user only has a read access. project (str): - Optional. Project to run training in. Overrides project set in aiplatform.init. + Project to run training in. Overrides project set in aiplatform.init. location (str): - Optional. Location to run training in. Overrides location set in aiplatform.init. + Location to run training in. Overrides location set in aiplatform.init. credentials (auth_credentials.Credentials): - Optional. Custom credentials to use to run call training service. Overrides + Custom credentials to use to run call training service. Overrides credentials set in aiplatform.init. + labels (Dict[str, str]): + Optional. The labels with user-defined metadata to + organize TrainingPipelines. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + and examples of labels. training_encryption_spec_key_name (Optional[str]): Optional. The Cloud KMS resource identifier of the customer managed encryption key used to protect the training pipeline. Has the @@ -2403,64 +3476,270 @@ def __init__( If set, the trained Model will be secured by this key. Overrides encryption_spec_key_name set in aiplatform.init. + staging_bucket (str): + Bucket used to stage source and training artifacts. Overrides + staging_bucket set in aiplatform.init. """ + if not display_name: + display_name = self.__class__._generate_display_name() super().__init__( display_name=display_name, project=project, location=location, credentials=credentials, + labels=labels, training_encryption_spec_key_name=training_encryption_spec_key_name, model_encryption_spec_key_name=model_encryption_spec_key_name, - ) - self._column_transformations = column_transformations - self._optimization_objective = optimization_objective - self._optimization_prediction_type = optimization_prediction_type - self._optimization_objective_recall_value = optimization_objective_recall_value - self._optimization_objective_precision_value = ( - optimization_objective_precision_value + container_uri=container_uri, + model_instance_schema_uri=model_instance_schema_uri, + model_parameters_schema_uri=model_parameters_schema_uri, + model_prediction_schema_uri=model_prediction_schema_uri, + model_serving_container_environment_variables=model_serving_container_environment_variables, + model_serving_container_ports=model_serving_container_ports, + model_serving_container_image_uri=model_serving_container_image_uri, + model_serving_container_command=model_serving_container_command, + model_serving_container_args=model_serving_container_args, + model_serving_container_predict_route=model_serving_container_predict_route, + model_serving_container_health_route=model_serving_container_health_route, + model_description=model_description, + staging_bucket=staging_bucket, ) + self._command = command + def run( self, - dataset: datasets.TabularDataset, - target_column: str, - training_fraction_split: float = 0.8, - validation_fraction_split: float = 0.1, - test_fraction_split: float = 0.1, - predefined_split_column_name: Optional[str] = None, - weight_column: Optional[str] = None, - budget_milli_node_hours: int = 1000, + dataset: Optional[ + Union[ + datasets.ImageDataset, + datasets.TabularDataset, + datasets.TextDataset, + datasets.VideoDataset, + ] + ] = None, + annotation_schema_uri: Optional[str] = None, model_display_name: Optional[str] = None, - disable_early_stopping: bool = False, - sync: bool = True, - ) -> models.Model: - """Runs the training job and returns a model. + model_labels: Optional[Dict[str, str]] = None, + base_output_dir: Optional[str] = None, + service_account: Optional[str] = None, + network: Optional[str] = None, + bigquery_destination: Optional[str] = None, + args: Optional[List[Union[str, float, int]]] = None, + environment_variables: Optional[Dict[str, str]] = None, + replica_count: int = 1, + machine_type: str = "n1-standard-4", + accelerator_type: str = "ACCELERATOR_TYPE_UNSPECIFIED", + accelerator_count: int = 0, + boot_disk_type: str = "pd-ssd", + boot_disk_size_gb: int = 100, + reduction_server_replica_count: int = 0, + reduction_server_machine_type: Optional[str] = None, + reduction_server_container_uri: Optional[str] = None, + training_fraction_split: Optional[float] = None, + validation_fraction_split: Optional[float] = None, + test_fraction_split: Optional[float] = None, + training_filter_split: Optional[str] = None, + validation_filter_split: Optional[str] = None, + test_filter_split: Optional[str] = None, + predefined_split_column_name: Optional[str] = None, + timestamp_split_column_name: Optional[str] = None, + timeout: Optional[int] = None, + restart_job_on_worker_restart: bool = False, + enable_web_access: bool = False, + tensorboard: Optional[str] = None, + sync=True, + create_request_timeout: Optional[float] = None, + ) -> Optional[models.Model]: + """Runs the custom training job. + + Distributed Training Support: + If replica count = 1 then one chief replica will be provisioned. If + replica_count > 1 the remainder will be provisioned as a worker replica pool. + ie: replica_count = 10 will result in 1 chief and 9 workers + All replicas have same machine_type, accelerator_type, and accelerator_count - Data fraction splits: - Any of ``training_fraction_split``, ``validation_fraction_split`` and - ``test_fraction_split`` may optionally be provided, they must sum to up to 1. If - the provided ones sum to less than 1, the remainder is assigned to sets as - decided by Vertex AI. If none of the fractions are set, by default roughly 80% - of data will be used for training, 10% for validation, and 10% for test. + If training on a Vertex AI dataset, you can use one of the following split configurations: + Data fraction splits: + Any of ``training_fraction_split``, ``validation_fraction_split`` and + ``test_fraction_split`` may optionally be provided, they must sum to up to 1. If + the provided ones sum to less than 1, the remainder is assigned to sets as + decided by Vertex AI. If none of the fractions are set, by default roughly 80% + of data will be used for training, 10% for validation, and 10% for test. + + Data filter splits: + Assigns input data to training, validation, and test sets + based on the given filters, data pieces not matched by any + filter are ignored. Currently only supported for Datasets + containing DataItems. + If any of the filters in this message are to match nothing, then + they can be set as '-' (the minus sign). + If using filter splits, all of ``training_filter_split``, ``validation_filter_split`` and + ``test_filter_split`` must be provided. + Supported only for unstructured Datasets. + + Predefined splits: + Assigns input data to training, validation, and test sets based on the value of a provided key. + If using predefined splits, ``predefined_split_column_name`` must be provided. + Supported only for tabular Datasets. + + Timestamp splits: + Assigns input data to training, validation, and test sets + based on a provided timestamps. The youngest data pieces are + assigned to training set, next to validation set, and the oldest + to the test set. + Supported only for tabular Datasets. Args: - dataset (datasets.TabularDataset): - Required. The dataset within the same Project from which data will be used to train the Model. The - Dataset must use schema compatible with Model being trained, - and what is compatible should be described in the used - TrainingPipeline's [training_task_definition] - [google.cloud.aiplatform.v1beta1.TrainingPipeline.training_task_definition]. - For tabular Datasets, all their data is exported to - training, to pick and choose from. + dataset (Union[datasets.ImageDataset,datasets.TabularDataset,datasets.TextDataset,datasets.VideoDataset]): + Vertex AI to fit this training against. Custom training script should + retrieve datasets through passed in environment variables uris: + + os.environ["AIP_TRAINING_DATA_URI"] + os.environ["AIP_VALIDATION_DATA_URI"] + os.environ["AIP_TEST_DATA_URI"] + + Additionally the dataset format is passed in as: + + os.environ["AIP_DATA_FORMAT"] + annotation_schema_uri (str): + Google Cloud Storage URI points to a YAML file describing + annotation schema. The schema is defined as an OpenAPI 3.0.2 + [Schema Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.2.md#schema-object) The schema files + that can be used here are found in + gs://google-cloud-aiplatform/schema/dataset/annotation/, + note that the chosen schema must be consistent with + ``metadata`` + of the Dataset specified by + ``dataset_id``. + + Only Annotations that both match this schema and belong to + DataItems not ignored by the split method are used in + respectively training, validation or test role, depending on + the role of the DataItem they are on. + + When used in conjunction with + ``annotations_filter``, + the Annotations used for training are filtered by both + ``annotations_filter`` + and + ``annotation_schema_uri``. + model_display_name (str): + If the script produces a managed Vertex AI Model. The display name of + the Model. The name can be up to 128 characters long and can be consist + of any UTF-8 characters. + + If not provided upon creation, the job's display_name is used. + model_labels (Dict[str, str]): + Optional. The labels with user-defined metadata to + organize your Models. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + and examples of labels. + base_output_dir (str): + GCS output directory of job. If not provided a + timestamped directory in the staging directory will be used. + + Vertex AI sets the following environment variables when it runs your training code: + + - AIP_MODEL_DIR: a Cloud Storage URI of a directory intended for saving model artifacts, i.e. /model/ + - AIP_CHECKPOINT_DIR: a Cloud Storage URI of a directory intended for saving checkpoints, i.e. /checkpoints/ + - AIP_TENSORBOARD_LOG_DIR: a Cloud Storage URI of a directory intended for saving TensorBoard logs, i.e. /logs/ + + service_account (str): + Specifies the service account for workload run-as account. + Users submitting jobs must have act-as permission on this run-as account. + network (str): + The full name of the Compute Engine network to which the job + should be peered. For example, projects/12345/global/networks/myVPC. + Private services access must already be configured for the network. + If left unspecified, the job is not peered with any network. + bigquery_destination (str): + Provide this field if `dataset` is a BiqQuery dataset. + The BigQuery project location where the training data is to + be written to. In the given project a new dataset is created + with name + ``dataset___`` + where timestamp is in YYYY_MM_DDThh_mm_ss_sssZ format. All + training input data will be written into that dataset. In + the dataset three tables will be created, ``training``, + ``validation`` and ``test``. + + - AIP_DATA_FORMAT = "bigquery". + - AIP_TRAINING_DATA_URI ="bigquery_destination.dataset_*.training" + - AIP_VALIDATION_DATA_URI = "bigquery_destination.dataset_*.validation" + - AIP_TEST_DATA_URI = "bigquery_destination.dataset_*.test" + args (List[Unions[str, int, float]]): + Command line arguments to be passed to the Python script. + environment_variables (Dict[str, str]): + Environment variables to be passed to the container. + Should be a dictionary where keys are environment variable names + and values are environment variable values for those names. + At most 10 environment variables can be specified. + The Name of the environment variable must be unique. + + environment_variables = { + 'MY_KEY': 'MY_VALUE' + } + replica_count (int): + The number of worker replicas. If replica count = 1 then one chief + replica will be provisioned. If replica_count > 1 the remainder will be + provisioned as a worker replica pool. + machine_type (str): + The type of machine to use for training. + accelerator_type (str): + Hardware accelerator type. One of ACCELERATOR_TYPE_UNSPECIFIED, + NVIDIA_TESLA_K80, NVIDIA_TESLA_P100, NVIDIA_TESLA_V100, NVIDIA_TESLA_P4, + NVIDIA_TESLA_T4 + accelerator_count (int): + The number of accelerators to attach to a worker replica. + boot_disk_type (str): + Type of the boot disk, default is `pd-ssd`. + Valid values: `pd-ssd` (Persistent Disk Solid State Drive) or + `pd-standard` (Persistent Disk Hard Disk Drive). + boot_disk_size_gb (int): + Size in GB of the boot disk, default is 100GB. + boot disk size must be within the range of [100, 64000]. + reduction_server_replica_count (int): + The number of reduction server replicas, default is 0. + reduction_server_machine_type (str): + Optional. The type of machine to use for reduction server. + reduction_server_container_uri (str): + Optional. The Uri of the reduction server container image. + See details: https://cloud.google.com/vertex-ai/docs/training/distributed-training#reduce_training_time_with_reduction_server training_fraction_split (float): - Required. The fraction of the input data that is to be - used to train the Model. This is ignored if Dataset is not provided. + Optional. The fraction of the input data that is to be used to train + the Model. This is ignored if Dataset is not provided. validation_fraction_split (float): - Required. The fraction of the input data that is to be - used to validate the Model. This is ignored if Dataset is not provided. + Optional. The fraction of the input data that is to be used to validate + the Model. This is ignored if Dataset is not provided. test_fraction_split (float): - Required. The fraction of the input data that is to be - used to evaluate the Model. This is ignored if Dataset is not provided. + Optional. The fraction of the input data that is to be used to evaluate + the Model. This is ignored if Dataset is not provided. + training_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to train the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. + validation_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to validate the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. + test_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to test the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. predefined_split_column_name (str): Optional. The key is a name of one of the Dataset's data columns. The value of the key (either the label's value or @@ -2471,111 +3750,235 @@ def run( ignored by the pipeline. Supported only for tabular and time series Datasets. - weight_column (str): - Optional. Name of the column that should be used as the weight column. - Higher values in this column give more importance to the row - during Model training. The column must have numeric values between 0 and - 10000 inclusively, and 0 value means that the row is ignored. - If the weight column field is not set, then all rows are assumed to have - equal weight of 1. - budget_milli_node_hours (int): - Optional. The train budget of creating this Model, expressed in milli node - hours i.e. 1,000 value in this field means 1 node hour. - The training cost of the model will not exceed this budget. The final - cost will be attempted to be close to the budget, though may end up - being (even) noticeably smaller - at the backend's discretion. This - especially may happen when further model training ceases to provide - any improvements. - If the budget is set to a value known to be insufficient to train a - Model for the given training set, the training won't be attempted and - will error. - The minimum value is 1000 and the maximum is 72000. - model_display_name (str): - Optional. If the script produces a managed Vertex AI Model. The display name of - the Model. The name can be up to 128 characters long and can be consist - of any UTF-8 characters. + timestamp_split_column_name (str): + Optional. The key is a name of one of the Dataset's data + columns. The value of the key values of the key (the values in + the column) must be in RFC 3339 `date-time` format, where + `time-offset` = `"Z"` (e.g. 1985-04-12T23:20:50.52Z). If for a + piece of data the key is not present or has an invalid value, + that piece is ignored by the pipeline. - If not provided upon creation, the job's display_name is used. - disable_early_stopping (bool): - Required. If true, the entire budget is used. This disables the early stopping - feature. By default, the early stopping feature is enabled, which means - that training might stop before the entire training budget has been - used, if further training does no longer brings significant improvement - to the model. + Supported only for tabular and time series Datasets. + timeout (int): + The maximum job running time in seconds. The default is 7 days. + restart_job_on_worker_restart (bool): + Restarts the entire CustomJob if a worker + gets restarted. This feature can be used by + distributed training jobs that are not resilient + to workers leaving and joining a job. + enable_web_access (bool): + Whether you want Vertex AI to enable interactive shell access + to training containers. + https://cloud.google.com/vertex-ai/docs/training/monitor-debug-interactive-shell + tensorboard (str): + Optional. The name of a Vertex AI + [Tensorboard][google.cloud.aiplatform.v1beta1.Tensorboard] + resource to which this CustomJob will upload Tensorboard + logs. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}`` + + The training script should write Tensorboard to following Vertex AI environment + variable: + + AIP_TENSORBOARD_LOG_DIR + + `service_account` is required with provided `tensorboard`. + For more information on configuring your service account please visit: + https://cloud.google.com/vertex-ai/docs/experiments/tensorboard-training sync (bool): Whether to execute this method synchronously. If False, this method will be executed in concurrent Future and any downstream object will be immediately returned and synced when the Future has completed. + create_request_timeout (float): + Optional. The timeout for the create request in seconds. + Returns: model: The trained Vertex AI Model resource or None if training did not - produce an Vertex AI Model. + produce a Vertex AI Model. Raises: - RuntimeError: If Training job has already been run or is waiting to run. + RuntimeError: If Training job has already been run, staging_bucket has not + been set, or model_display_name was provided but required arguments + were not provided in constructor. """ - - if self._is_waiting_to_run(): - raise RuntimeError("AutoML Tabular Training is already scheduled to run.") - - if self._has_run: - raise RuntimeError("AutoML Tabular Training has already run.") + worker_pool_specs, managed_model = self._prepare_and_validate_run( + model_display_name=model_display_name, + model_labels=model_labels, + replica_count=replica_count, + machine_type=machine_type, + accelerator_count=accelerator_count, + accelerator_type=accelerator_type, + boot_disk_type=boot_disk_type, + boot_disk_size_gb=boot_disk_size_gb, + reduction_server_replica_count=reduction_server_replica_count, + reduction_server_machine_type=reduction_server_machine_type, + ) return self._run( dataset=dataset, - target_column=target_column, + annotation_schema_uri=annotation_schema_uri, + worker_pool_specs=worker_pool_specs, + managed_model=managed_model, + args=args, + environment_variables=environment_variables, + base_output_dir=base_output_dir, + service_account=service_account, + network=network, + bigquery_destination=bigquery_destination, training_fraction_split=training_fraction_split, validation_fraction_split=validation_fraction_split, test_fraction_split=test_fraction_split, + training_filter_split=training_filter_split, + validation_filter_split=validation_filter_split, + test_filter_split=test_filter_split, predefined_split_column_name=predefined_split_column_name, - weight_column=weight_column, - budget_milli_node_hours=budget_milli_node_hours, - model_display_name=model_display_name, - disable_early_stopping=disable_early_stopping, + timestamp_split_column_name=timestamp_split_column_name, + timeout=timeout, + restart_job_on_worker_restart=restart_job_on_worker_restart, + enable_web_access=enable_web_access, + tensorboard=tensorboard, + reduction_server_container_uri=reduction_server_container_uri + if reduction_server_replica_count > 0 + else None, sync=sync, + create_request_timeout=create_request_timeout, ) - @base.optional_sync() + @base.optional_sync(construct_object_on_arg="managed_model") def _run( self, - dataset: datasets.TabularDataset, - target_column: str, - training_fraction_split: float = 0.8, - validation_fraction_split: float = 0.1, - test_fraction_split: float = 0.1, + dataset: Optional[ + Union[ + datasets.ImageDataset, + datasets.TabularDataset, + datasets.TextDataset, + datasets.VideoDataset, + ] + ], + annotation_schema_uri: Optional[str], + worker_pool_specs: worker_spec_utils._DistributedTrainingSpec, + managed_model: Optional[gca_model.Model] = None, + args: Optional[List[Union[str, float, int]]] = None, + environment_variables: Optional[Dict[str, str]] = None, + base_output_dir: Optional[str] = None, + service_account: Optional[str] = None, + network: Optional[str] = None, + bigquery_destination: Optional[str] = None, + training_fraction_split: Optional[float] = None, + validation_fraction_split: Optional[float] = None, + test_fraction_split: Optional[float] = None, + training_filter_split: Optional[str] = None, + validation_filter_split: Optional[str] = None, + test_filter_split: Optional[str] = None, predefined_split_column_name: Optional[str] = None, - weight_column: Optional[str] = None, - budget_milli_node_hours: int = 1000, - model_display_name: Optional[str] = None, - disable_early_stopping: bool = False, - sync: bool = True, - ) -> models.Model: - """Runs the training job and returns a model. + timestamp_split_column_name: Optional[str] = None, + timeout: Optional[int] = None, + restart_job_on_worker_restart: bool = False, + enable_web_access: bool = False, + tensorboard: Optional[str] = None, + reduction_server_container_uri: Optional[str] = None, + sync=True, + create_request_timeout: Optional[float] = None, + ) -> Optional[models.Model]: + """Packages local script and launches training_job. + Args: + dataset ( + Union[ + datasets.ImageDataset, + datasets.TabularDataset, + datasets.TextDataset, + datasets.VideoDataset, + ] + ): + Vertex AI to fit this training against. + annotation_schema_uri (str): + Google Cloud Storage URI points to a YAML file describing + annotation schema. + worker_pools_spec (worker_spec_utils._DistributedTrainingSpec): + Worker pools pecs required to run job. + managed_model (gca_model.Model): + Model proto if this script produces a Managed Model. + args (List[Unions[str, int, float]]): + Command line arguments to be passed to the Python script. + environment_variables (Dict[str, str]): + Environment variables to be passed to the container. + Should be a dictionary where keys are environment variable names + and values are environment variable values for those names. + At most 10 environment variables can be specified. + The Name of the environment variable must be unique. - Data fraction splits: - Any of ``training_fraction_split``, ``validation_fraction_split`` and - ``test_fraction_split`` may optionally be provided, they must sum to up to 1. If - the provided ones sum to less than 1, the remainder is assigned to sets as - decided by Vertex AI. If none of the fractions are set, by default roughly 80% - of data will be used for training, 10% for validation, and 10% for test. + environment_variables = { + 'MY_KEY': 'MY_VALUE' + } + base_output_dir (str): + GCS output directory of job. If not provided a + timestamped directory in the staging directory will be used. - Args: - dataset (datasets.TabularDataset): - Required. The dataset within the same Project from which data will be used to train the Model. The - Dataset must use schema compatible with Model being trained, - and what is compatible should be described in the used - TrainingPipeline's [training_task_definition] - [google.cloud.aiplatform.v1beta1.TrainingPipeline.training_task_definition]. - For tabular Datasets, all their data is exported to - training, to pick and choose from. + Vertex AI sets the following environment variables when it runs your training code: + + - AIP_MODEL_DIR: a Cloud Storage URI of a directory intended for saving model artifacts, i.e. /model/ + - AIP_CHECKPOINT_DIR: a Cloud Storage URI of a directory intended for saving checkpoints, i.e. /checkpoints/ + - AIP_TENSORBOARD_LOG_DIR: a Cloud Storage URI of a directory intended for saving TensorBoard logs, i.e. /logs/ + + service_account (str): + Specifies the service account for workload run-as account. + Users submitting jobs must have act-as permission on this run-as account. + network (str): + The full name of the Compute Engine network to which the job + should be peered. For example, projects/12345/global/networks/myVPC. + Private services access must already be configured for the network. + If left unspecified, the job is not peered with any network. + timeout (int): + The maximum job running time in seconds. The default is 7 days. + restart_job_on_worker_restart (bool): + Restarts the entire CustomJob if a worker + gets restarted. This feature can be used by + distributed training jobs that are not resilient + to workers leaving and joining a job. + bigquery_destination (str): + The BigQuery project location where the training data is to + be written to. In the given project a new dataset is created + with name + ``dataset___`` + where timestamp is in YYYY_MM_DDThh_mm_ss_sssZ format. All + training input data will be written into that dataset. In + the dataset three tables will be created, ``training``, + ``validation`` and ``test``. + + - AIP_DATA_FORMAT = "bigquery". + - AIP_TRAINING_DATA_URI ="bigquery_destination.dataset_*.training" + - AIP_VALIDATION_DATA_URI = "bigquery_destination.dataset_*.validation" + - AIP_TEST_DATA_URI = "bigquery_destination.dataset_*.test" training_fraction_split (float): - Required. The fraction of the input data that is to be - used to train the Model. This is ignored if Dataset is not provided. + Optional. The fraction of the input data that is to be used to train + the Model. This is ignored if Dataset is not provided. validation_fraction_split (float): - Required. The fraction of the input data that is to be - used to validate the Model. This is ignored if Dataset is not provided. + Optional. The fraction of the input data that is to be used to validate + the Model. This is ignored if Dataset is not provided. test_fraction_split (float): - Required. The fraction of the input data that is to be - used to evaluate the Model. This is ignored if Dataset is not provided. + Optional. The fraction of the input data that is to be used to evaluate + the Model. This is ignored if Dataset is not provided. + training_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to train the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. + validation_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to validate the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. + test_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to test the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. predefined_split_column_name (str): Optional. The key is a name of one of the Dataset's data columns. The value of the key (either the label's value or @@ -2586,150 +3989,224 @@ def _run( ignored by the pipeline. Supported only for tabular and time series Datasets. - weight_column (str): - Optional. Name of the column that should be used as the weight column. - Higher values in this column give more importance to the row - during Model training. The column must have numeric values between 0 and - 10000 inclusively, and 0 value means that the row is ignored. - If the weight column field is not set, then all rows are assumed to have - equal weight of 1. - budget_milli_node_hours (int): - Optional. The train budget of creating this Model, expressed in milli node - hours i.e. 1,000 value in this field means 1 node hour. - The training cost of the model will not exceed this budget. The final - cost will be attempted to be close to the budget, though may end up - being (even) noticeably smaller - at the backend's discretion. This - especially may happen when further model training ceases to provide - any improvements. - If the budget is set to a value known to be insufficient to train a - Model for the given training set, the training won't be attempted and - will error. - The minimum value is 1000 and the maximum is 72000. - model_display_name (str): - Optional. If the script produces a managed Vertex AI Model. The display name of - the Model. The name can be up to 128 characters long and can be consist - of any UTF-8 characters. + timestamp_split_column_name (str): + Optional. The key is a name of one of the Dataset's data + columns. The value of the key values of the key (the values in + the column) must be in RFC 3339 `date-time` format, where + `time-offset` = `"Z"` (e.g. 1985-04-12T23:20:50.52Z). If for a + piece of data the key is not present or has an invalid value, + that piece is ignored by the pipeline. - If not provided upon creation, the job's display_name is used. - disable_early_stopping (bool): - Required. If true, the entire budget is used. This disables the early stopping - feature. By default, the early stopping feature is enabled, which means - that training might stop before the entire training budget has been - used, if further training does no longer brings significant improvement - to the model. + Supported only for tabular and time series Datasets. + enable_web_access (bool): + Whether you want Vertex AI to enable interactive shell access + to training containers. + https://cloud.google.com/vertex-ai/docs/training/monitor-debug-interactive-shell + tensorboard (str): + Optional. The name of a Vertex AI + [Tensorboard][google.cloud.aiplatform.v1beta1.Tensorboard] + resource to which this CustomJob will upload Tensorboard + logs. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}`` + + The training script should write Tensorboard to following Vertex AI environment + variable: + + AIP_TENSORBOARD_LOG_DIR + + `service_account` is required with provided `tensorboard`. + For more information on configuring your service account please visit: + https://cloud.google.com/vertex-ai/docs/experiments/tensorboard-training + reduction_server_container_uri (str): + Optional. The Uri of the reduction server container image. sync (bool): Whether to execute this method synchronously. If False, this method will be executed in concurrent Future and any downstream object will be immediately returned and synced when the Future has completed. + create_request_timeout (float): + Optional. The timeout for the create request in seconds. Returns: model: The trained Vertex AI Model resource or None if training did not - produce an Vertex AI Model. + produce a Vertex AI Model. """ - training_task_definition = schema.training_job.definition.automl_tabular + for spec_order, spec in enumerate(worker_pool_specs): - if self._column_transformations is None: - _LOGGER.info( - "No column transformations provided, so now retrieving columns from dataset in order to set default column transformations." - ) + if not spec: + continue - column_names = [ - column_name - for column_name in dataset.column_names - if column_name != target_column - ] - column_transformations = [ - {"auto": {"column_name": column_name}} for column_name in column_names - ] + if ( + spec_order == worker_spec_utils._SPEC_ORDERS["server_spec"] + and reduction_server_container_uri + ): + spec["container_spec"] = { + "image_uri": reduction_server_container_uri, + } + else: + spec["containerSpec"] = {"imageUri": self._container_uri} - _LOGGER.info( - "The column transformation of type 'auto' was set for the following columns: %s." - % column_names - ) - else: - column_transformations = self._column_transformations + if self._command: + spec["containerSpec"]["command"] = self._command - training_task_inputs_dict = { - # required inputs - "targetColumn": target_column, - "transformations": column_transformations, - "trainBudgetMilliNodeHours": budget_milli_node_hours, - # optional inputs - "weightColumnName": weight_column, - "disableEarlyStopping": disable_early_stopping, - "optimizationObjective": self._optimization_objective, - "predictionType": self._optimization_prediction_type, - "optimizationObjectiveRecallValue": self._optimization_objective_recall_value, - "optimizationObjectivePrecisionValue": self._optimization_objective_precision_value, - } + if args: + spec["containerSpec"]["args"] = args - if model_display_name is None: - model_display_name = self._display_name + if environment_variables: + spec["containerSpec"]["env"] = [ + {"name": key, "value": value} + for key, value in environment_variables.items() + ] - model = gca_model.Model( - display_name=model_display_name, - encryption_spec=self._model_encryption_spec, + ( + training_task_inputs, + base_output_dir, + ) = self._prepare_training_task_inputs_and_output_dir( + worker_pool_specs=worker_pool_specs, + base_output_dir=base_output_dir, + service_account=service_account, + network=network, + timeout=timeout, + restart_job_on_worker_restart=restart_job_on_worker_restart, + enable_web_access=enable_web_access, + tensorboard=tensorboard, ) - return self._run_job( - training_task_definition=training_task_definition, - training_task_inputs=training_task_inputs_dict, + model = self._run_job( + training_task_definition=schema.training_job.definition.custom_task, + training_task_inputs=training_task_inputs, dataset=dataset, + annotation_schema_uri=annotation_schema_uri, training_fraction_split=training_fraction_split, validation_fraction_split=validation_fraction_split, test_fraction_split=test_fraction_split, + training_filter_split=training_filter_split, + validation_filter_split=validation_filter_split, + test_filter_split=test_filter_split, predefined_split_column_name=predefined_split_column_name, - model=model, + timestamp_split_column_name=timestamp_split_column_name, + model=managed_model, + gcs_destination_uri_prefix=base_output_dir, + bigquery_destination=bigquery_destination, + create_request_timeout=create_request_timeout, ) - @property - def _model_upload_fail_string(self) -> str: - """Helper property for model upload failure.""" - return ( - f"Training Pipeline {self.resource_name} is not configured to upload a " - "Model." - ) + return model -class AutoMLForecastingTrainingJob(_TrainingJob): - _supported_training_schemas = (schema.training_job.definition.automl_forecasting,) +class AutoMLTabularTrainingJob(_TrainingJob): + _supported_training_schemas = (schema.training_job.definition.automl_tabular,) def __init__( self, + # TODO(b/223262536): Make display_name parameter fully optional in next major release display_name: str, + optimization_prediction_type: str, optimization_objective: Optional[str] = None, - column_transformations: Optional[Union[Dict, List[Dict]]] = None, + column_specs: Optional[Dict[str, str]] = None, + column_transformations: Optional[List[Dict[str, Dict[str, str]]]] = None, + optimization_objective_recall_value: Optional[float] = None, + optimization_objective_precision_value: Optional[float] = None, project: Optional[str] = None, location: Optional[str] = None, credentials: Optional[auth_credentials.Credentials] = None, + labels: Optional[Dict[str, str]] = None, + training_encryption_spec_key_name: Optional[str] = None, + model_encryption_spec_key_name: Optional[str] = None, ): - """Constructs a AutoML Forecasting Training Job. + """Constructs a AutoML Tabular Training Job. + + Example usage: + + job = training_jobs.AutoMLTabularTrainingJob( + display_name="my_display_name", + optimization_prediction_type="classification", + optimization_objective="minimize-log-loss", + column_specs={"column_1": "auto", "column_2": "numeric"}, + labels={'key': 'value'}, + ) Args: display_name (str): Required. The user-defined name of this TrainingPipeline. + optimization_prediction_type (str): + The type of prediction the Model is to produce. + "classification" - Predict one out of multiple target values is + picked for each row. + "regression" - Predict a value based on its relation to other values. + This type is available only to columns that contain + semantically numeric values, i.e. integers or floating + point number, even if stored as e.g. strings. + optimization_objective (str): - Optional. Objective function the model is to be optimized towards. - The training process creates a Model that optimizes the value of the objective - function over the validation set. The supported optimization objectives: + Optional. Objective function the Model is to be optimized towards. The training + task creates a Model that maximizes/minimizes the value of the objective + function over the validation set. + + The supported optimization objectives depend on the prediction type, and + in the case of classification also the number of distinct values in the + target column (two distint values -> binary, 3 or more distinct values + -> multi class). + If the field is not set, the default objective function is used. + + Classification (binary): + "maximize-au-roc" (default) - Maximize the area under the receiver + operating characteristic (ROC) curve. + "minimize-log-loss" - Minimize log loss. + "maximize-au-prc" - Maximize the area under the precision-recall curve. + "maximize-precision-at-recall" - Maximize precision for a specified + recall value. + "maximize-recall-at-precision" - Maximize recall for a specified + precision value. + + Classification (multi class): + "minimize-log-loss" (default) - Minimize log loss. + + Regression: "minimize-rmse" (default) - Minimize root-mean-squared error (RMSE). "minimize-mae" - Minimize mean-absolute error (MAE). "minimize-rmsle" - Minimize root-mean-squared log error (RMSLE). - "minimize-rmspe" - Minimize root-mean-squared percentage error (RMSPE). - "minimize-wape-mae" - Minimize the combination of weighted absolute percentage error (WAPE) - and mean-absolute-error (MAE). - "minimize-quantile-loss" - Minimize the quantile loss at the defined quantiles. - (Set this objective to build quantile forecasts.) - column_transformations (Optional[Union[Dict, List[Dict]]]): + column_specs (Dict[str, str]): + Optional. Alternative to column_transformations where the keys of the dict + are column names and their respective values are one of + AutoMLTabularTrainingJob.column_data_types. + When creating transformation for BigQuery Struct column, the column + should be flattened using "." as the delimiter. Only columns with no child + should have a transformation. + If an input column has no transformations on it, such a column is + ignored by the training, except for the targetColumn, which should have + no transformations defined on. + Only one of column_transformations or column_specs should be passed. If none + of column_transformations or column_specs is passed, the local credentials + being used will try setting column_specs to "auto". To do this, the local + credentials require read access to the GCS or BigQuery training data source. + column_transformations (List[Dict[str, Dict[str, str]]]): Optional. Transformations to apply to the input columns (i.e. columns other than the targetColumn). Each transformation may produce multiple result values from the column's value, and all are used for training. When creating transformation for BigQuery Struct column, the column - should be flattened using "." as the delimiter. + should be flattened using "." as the delimiter. Only columns with no child + should have a transformation. If an input column has no transformations on it, such a column is ignored by the training, except for the targetColumn, which should have no transformations defined on. + Only one of column_transformations or column_specs should be passed. + Consider using column_specs as column_transformations will be deprecated + eventually. If none of column_transformations or column_specs is passed, + the local credentials being used will try setting column_transformations to + "auto". To do this, the local credentials require read access to the GCS or + BigQuery training data source. + optimization_objective_recall_value (float): + Optional. Required when maximize-precision-at-recall optimizationObjective was + picked, represents the recall value at which the optimization is done. + + The minimum value is 0 and the maximum is 1.0. + optimization_objective_precision_value (float): + Optional. Required when maximize-recall-at-precision optimizationObjective was + picked, represents the precision value at which the optimization is + done. + + The minimum value is 0 and the maximum is 1.0. project (str): Optional. Project to run training in. Overrides project set in aiplatform.init. location (str): @@ -2737,90 +4214,155 @@ def __init__( credentials (auth_credentials.Credentials): Optional. Custom credentials to use to run call training service. Overrides credentials set in aiplatform.init. + labels (Dict[str, str]): + Optional. The labels with user-defined metadata to + organize TrainingPipelines. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + and examples of labels. + training_encryption_spec_key_name (Optional[str]): + Optional. The Cloud KMS resource identifier of the customer + managed encryption key used to protect the training pipeline. Has the + form: + ``projects/my-project/locations/my-region/keyRings/my-kr/cryptoKeys/my-key``. + The key needs to be in the same region as where the compute + resource is created. + + If set, this TrainingPipeline will be secured by this key. + + Note: Model trained by this TrainingPipeline is also secured + by this key if ``model_to_upload`` is not set separately. + + Overrides encryption_spec_key_name set in aiplatform.init. + model_encryption_spec_key_name (Optional[str]): + Optional. The Cloud KMS resource identifier of the customer + managed encryption key used to protect the model. Has the + form: + ``projects/my-project/locations/my-region/keyRings/my-kr/cryptoKeys/my-key``. + The key needs to be in the same region as where the compute + resource is created. + + If set, the trained Model will be secured by this key. + + Overrides encryption_spec_key_name set in aiplatform.init. + + Raises: + ValueError: If both column_transformations and column_specs were provided. """ + if not display_name: + display_name = self.__class__._generate_display_name() super().__init__( display_name=display_name, project=project, location=location, credentials=credentials, + labels=labels, + training_encryption_spec_key_name=training_encryption_spec_key_name, + model_encryption_spec_key_name=model_encryption_spec_key_name, + ) + + self._column_transformations = ( + column_transformations_utils.validate_and_get_column_transformations( + column_specs, column_transformations + ) ) - self._column_transformations = column_transformations + self._optimization_objective = optimization_objective + self._optimization_prediction_type = optimization_prediction_type + self._optimization_objective_recall_value = optimization_objective_recall_value + self._optimization_objective_precision_value = ( + optimization_objective_precision_value + ) + + self._additional_experiments = [] def run( self, - dataset: datasets.TimeSeriesDataset, + dataset: datasets.TabularDataset, target_column: str, - time_column: str, - time_series_identifier_column: str, - unavailable_at_forecast_columns: List[str], - available_at_forecast_columns: List[str], - forecast_horizon: int, - data_granularity_unit: str, - data_granularity_count: int, + training_fraction_split: Optional[float] = None, + validation_fraction_split: Optional[float] = None, + test_fraction_split: Optional[float] = None, predefined_split_column_name: Optional[str] = None, + timestamp_split_column_name: Optional[str] = None, weight_column: Optional[str] = None, - time_series_attribute_columns: Optional[List[str]] = None, - context_window: Optional[int] = None, + budget_milli_node_hours: int = 1000, + model_display_name: Optional[str] = None, + model_labels: Optional[Dict[str, str]] = None, + disable_early_stopping: bool = False, export_evaluated_data_items: bool = False, export_evaluated_data_items_bigquery_destination_uri: Optional[str] = None, export_evaluated_data_items_override_destination: bool = False, - quantiles: Optional[List[float]] = None, - validation_options: Optional[str] = None, - budget_milli_node_hours: int = 1000, - model_display_name: Optional[str] = None, + additional_experiments: Optional[List[str]] = None, sync: bool = True, + create_request_timeout: Optional[float] = None, ) -> models.Model: """Runs the training job and returns a model. - The training data splits are set by default: Roughly 80% will be used for training, - 10% for validation, and 10% for test. + If training on a Vertex AI dataset, you can use one of the following split configurations: + Data fraction splits: + Any of ``training_fraction_split``, ``validation_fraction_split`` and + ``test_fraction_split`` may optionally be provided, they must sum to up to 1. If + the provided ones sum to less than 1, the remainder is assigned to sets as + decided by Vertex AI. If none of the fractions are set, by default roughly 80% + of data will be used for training, 10% for validation, and 10% for test. + + Predefined splits: + Assigns input data to training, validation, and test sets based on the value of a provided key. + If using predefined splits, ``predefined_split_column_name`` must be provided. + Supported only for tabular Datasets. + + Timestamp splits: + Assigns input data to training, validation, and test sets + based on a provided timestamps. The youngest data pieces are + assigned to training set, next to validation set, and the oldest + to the test set. + Supported only for tabular Datasets. Args: - dataset (datasets.Dataset): + dataset (datasets.TabularDataset): Required. The dataset within the same Project from which data will be used to train the Model. The Dataset must use schema compatible with Model being trained, and what is compatible should be described in the used TrainingPipeline's [training_task_definition] [google.cloud.aiplatform.v1beta1.TrainingPipeline.training_task_definition]. - For time series Datasets, all their data is exported to + For tabular Datasets, all their data is exported to training, to pick and choose from. target_column (str): - Required. Name of the column that the Model is to predict values for. - time_column (str): - Required. Name of the column that identifies time order in the time series. - time_series_identifier_column (str): - Required. Name of the column that identifies the time series. - unavailable_at_forecast_columns (List[str]): - Required. Column names of columns that are unavailable at forecast. - Each column contains information for the given entity (identified by the - [time_series_identifier_column]) that is unknown before the forecast - (e.g. population of a city in a given year, or weather on a given day). - available_at_forecast_columns (List[str]): - Required. Column names of columns that are available at forecast. - Each column contains information for the given entity (identified by the - [time_series_identifier_column]) that is known at forecast. - forecast_horizon: (int): - Required. The amount of time into the future for which forecasted values for the target are - returned. Expressed in number of units defined by the [data_granularity_unit] and - [data_granularity_count] field. Inclusive. - data_granularity_unit (str): - Required. The data granularity unit. Accepted values are ``minute``, - ``hour``, ``day``, ``week``, ``month``, ``year``. - data_granularity_count (int): - Required. The number of data granularity units between data points in the training - data. If [data_granularity_unit] is `minute`, can be 1, 5, 10, 15, or 30. For all other - values of [data_granularity_unit], must be 1. + Required. The name of the column values of which the Model is to predict. + training_fraction_split (float): + Optional. The fraction of the input data that is to be used to train + the Model. This is ignored if Dataset is not provided. + validation_fraction_split (float): + Optional. The fraction of the input data that is to be used to validate + the Model. This is ignored if Dataset is not provided. + test_fraction_split (float): + Optional. The fraction of the input data that is to be used to evaluate + the Model. This is ignored if Dataset is not provided. predefined_split_column_name (str): Optional. The key is a name of one of the Dataset's data columns. The value of the key (either the label's value or - value in the column) must be one of {``TRAIN``, - ``VALIDATE``, ``TEST``}, and it defines to which set the + value in the column) must be one of {``training``, + ``validation``, ``test``}, and it defines to which set the given piece of data is assigned. If for a piece of data the key is not present or has an invalid value, that piece is ignored by the pipeline. Supported only for tabular and time series Datasets. + timestamp_split_column_name (str): + Optional. The key is a name of one of the Dataset's data + columns. The value of the key values of the key (the values in + the column) must be in RFC 3339 `date-time` format, where + `time-offset` = `"Z"` (e.g. 1985-04-12T23:20:50.52Z). If for a + piece of data the key is not present or has an invalid value, + that piece is ignored by the pipeline. + Supported only for tabular and time series Datasets. + This parameter must be used with training_fraction_split, + validation_fraction_split, and test_fraction_split. weight_column (str): Optional. Name of the column that should be used as the weight column. Higher values in this column give more importance to the row @@ -2828,15 +4370,40 @@ def run( 10000 inclusively, and 0 value means that the row is ignored. If the weight column field is not set, then all rows are assumed to have equal weight of 1. - time_series_attribute_columns (List[str]): - Optional. Column names that should be used as attribute columns. - Each column is constant within a time series. - context_window (int): - Optional. The amount of time into the past training and prediction data is used for - model training and prediction respectively. Expressed in number of units defined by the - [data_granularity_unit] and [data_granularity_count] fields. When not provided uses the - default value of 0 which means the model sets each series context window to be 0 (also - known as "cold start"). Inclusive. + budget_milli_node_hours (int): + Optional. The train budget of creating this Model, expressed in milli node + hours i.e. 1,000 value in this field means 1 node hour. + The training cost of the model will not exceed this budget. The final + cost will be attempted to be close to the budget, though may end up + being (even) noticeably smaller - at the backend's discretion. This + especially may happen when further model training ceases to provide + any improvements. + If the budget is set to a value known to be insufficient to train a + Model for the given training set, the training won't be attempted and + will error. + The minimum value is 1000 and the maximum is 72000. + model_display_name (str): + Optional. If the script produces a managed Vertex AI Model. The display name of + the Model. The name can be up to 128 characters long and can be consist + of any UTF-8 characters. + + If not provided upon creation, the job's display_name is used. + model_labels (Dict[str, str]): + Optional. The labels with user-defined metadata to + organize your Models. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + and examples of labels. + disable_early_stopping (bool): + Required. If true, the entire budget is used. This disables the early stopping + feature. By default, the early stopping feature is enabled, which means + that training might stop before the entire training budget has been + used, if further training does no longer brings significant improvement + to the model. export_evaluated_data_items (bool): Whether to export the test set predictions to a BigQuery table. If False, then the export is not performed. @@ -2858,155 +4425,138 @@ def run( Applies only if [export_evaluated_data_items] is True and [export_evaluated_data_items_bigquery_destination_uri] is specified. - quantiles (List[float]): - Quantiles to use for the `minizmize-quantile-loss` - [AutoMLForecastingTrainingJob.optimization_objective]. This argument is required in - this case. - - Accepts up to 5 quantiles in the form of a double from 0 to 1, exclusive. - Each quantile must be unique. - validation_options (str): - Validation options for the data validation component. The available options are: - "fail-pipeline" - (default), will validate against the validation and fail the pipeline - if it fails. - "ignore-validation" - ignore the results of the validation and continue the pipeline - budget_milli_node_hours (int): - Optional. The train budget of creating this Model, expressed in milli node - hours i.e. 1,000 value in this field means 1 node hour. - The training cost of the model will not exceed this budget. The final - cost will be attempted to be close to the budget, though may end up - being (even) noticeably smaller - at the backend's discretion. This - especially may happen when further model training ceases to provide - any improvements. - If the budget is set to a value known to be insufficient to train a - Model for the given training set, the training won't be attempted and - will error. - The minimum value is 1000 and the maximum is 72000. - model_display_name (str): - Optional. If the script produces a managed Vertex AI Model. The display name of - the Model. The name can be up to 128 characters long and can be consist - of any UTF-8 characters. - - If not provided upon creation, the job's display_name is used. + additional_experiments (List[str]): + Optional. Additional experiment flags for the automl tables training. sync (bool): Whether to execute this method synchronously. If False, this method will be executed in concurrent Future and any downstream object will be immediately returned and synced when the Future has completed. + create_request_timeout (float): + Optional. The timeout for the create request in seconds. Returns: model: The trained Vertex AI Model resource or None if training did not - produce an Vertex AI Model. + produce a Vertex AI Model. Raises: - RuntimeError if Training job has already been run or is waiting to run. + RuntimeError: If Training job has already been run or is waiting to run. """ + if model_display_name: + utils.validate_display_name(model_display_name) + if model_labels: + utils.validate_labels(model_labels) if self._is_waiting_to_run(): - raise RuntimeError( - "AutoML Forecasting Training is already scheduled to run." - ) + raise RuntimeError("AutoML Tabular Training is already scheduled to run.") if self._has_run: - raise RuntimeError("AutoML Forecasting Training has already run.") + raise RuntimeError("AutoML Tabular Training has already run.") + + if additional_experiments: + self._add_additional_experiments(additional_experiments) return self._run( dataset=dataset, target_column=target_column, - time_column=time_column, - time_series_identifier_column=time_series_identifier_column, - unavailable_at_forecast_columns=unavailable_at_forecast_columns, - available_at_forecast_columns=available_at_forecast_columns, - forecast_horizon=forecast_horizon, - data_granularity_unit=data_granularity_unit, - data_granularity_count=data_granularity_count, + training_fraction_split=training_fraction_split, + validation_fraction_split=validation_fraction_split, + test_fraction_split=test_fraction_split, predefined_split_column_name=predefined_split_column_name, + timestamp_split_column_name=timestamp_split_column_name, weight_column=weight_column, - time_series_attribute_columns=time_series_attribute_columns, - context_window=context_window, budget_milli_node_hours=budget_milli_node_hours, + model_display_name=model_display_name, + model_labels=model_labels, + disable_early_stopping=disable_early_stopping, export_evaluated_data_items=export_evaluated_data_items, export_evaluated_data_items_bigquery_destination_uri=export_evaluated_data_items_bigquery_destination_uri, export_evaluated_data_items_override_destination=export_evaluated_data_items_override_destination, - quantiles=quantiles, - validation_options=validation_options, - model_display_name=model_display_name, sync=sync, + create_request_timeout=create_request_timeout, ) @base.optional_sync() def _run( self, - dataset: datasets.TimeSeriesDataset, + dataset: datasets.TabularDataset, target_column: str, - time_column: str, - time_series_identifier_column: str, - unavailable_at_forecast_columns: List[str], - available_at_forecast_columns: List[str], - forecast_horizon: int, - data_granularity_unit: str, - data_granularity_count: int, + training_fraction_split: Optional[float] = None, + validation_fraction_split: Optional[float] = None, + test_fraction_split: Optional[float] = None, predefined_split_column_name: Optional[str] = None, + timestamp_split_column_name: Optional[str] = None, weight_column: Optional[str] = None, - time_series_attribute_columns: Optional[List[str]] = None, - context_window: Optional[int] = None, + budget_milli_node_hours: int = 1000, + model_display_name: Optional[str] = None, + model_labels: Optional[Dict[str, str]] = None, + disable_early_stopping: bool = False, export_evaluated_data_items: bool = False, export_evaluated_data_items_bigquery_destination_uri: Optional[str] = None, export_evaluated_data_items_override_destination: bool = False, - quantiles: Optional[List[float]] = None, - validation_options: Optional[str] = None, - budget_milli_node_hours: int = 1000, - model_display_name: Optional[str] = None, sync: bool = True, + create_request_timeout: Optional[float] = None, ) -> models.Model: """Runs the training job and returns a model. - The training data splits are set by default: Roughly 80% will be used for training, - 10% for validation, and 10% for test. + If training on a Vertex AI dataset, you can use one of the following split configurations: + Data fraction splits: + Any of ``training_fraction_split``, ``validation_fraction_split`` and + ``test_fraction_split`` may optionally be provided, they must sum to up to 1. If + the provided ones sum to less than 1, the remainder is assigned to sets as + decided by Vertex AI. If none of the fractions are set, by default roughly 80% + of data will be used for training, 10% for validation, and 10% for test. + + Predefined splits: + Assigns input data to training, validation, and test sets based on the value of a provided key. + If using predefined splits, ``predefined_split_column_name`` must be provided. + Supported only for tabular Datasets. + + Timestamp splits: + Assigns input data to training, validation, and test sets + based on a provided timestamps. The youngest data pieces are + assigned to training set, next to validation set, and the oldest + to the test set. + Supported only for tabular Datasets. Args: - dataset (datasets.Dataset): + dataset (datasets.TabularDataset): Required. The dataset within the same Project from which data will be used to train the Model. The Dataset must use schema compatible with Model being trained, and what is compatible should be described in the used TrainingPipeline's [training_task_definition] [google.cloud.aiplatform.v1beta1.TrainingPipeline.training_task_definition]. - For time series Datasets, all their data is exported to + For tabular Datasets, all their data is exported to training, to pick and choose from. target_column (str): - Required. Name of the column that the Model is to predict values for. - time_column (str): - Required. Name of the column that identifies time order in the time series. - time_series_identifier_column (str): - Required. Name of the column that identifies the time series. - unavailable_at_forecast_columns (List[str]): - Required. Column names of columns that are unavailable at forecast. - Each column contains information for the given entity (identified by the - [time_series_identifier_column]) that is unknown before the forecast - (e.g. population of a city in a given year, or weather on a given day). - available_at_forecast_columns (List[str]): - Required. Column names of columns that are available at forecast. - Each column contains information for the given entity (identified by the - [time_series_identifier_column]) that is known at forecast. - forecast_horizon: (int): - Required. The amount of time into the future for which forecasted values for the target are - returned. Expressed in number of units defined by the [data_granularity_unit] and - [data_granularity_count] field. Inclusive. - data_granularity_unit (str): - Required. The data granularity unit. Accepted values are ``minute``, - ``hour``, ``day``, ``week``, ``month``, ``year``. - data_granularity_count (int): - Required. The number of data granularity units between data points in the training - data. If [data_granularity_unit] is `minute`, can be 1, 5, 10, 15, or 30. For all other - values of [data_granularity_unit], must be 1. + Required. The name of the column values of which the Model is to predict. + training_fraction_split (float): + Optional. The fraction of the input data that is to be used to train + the Model. This is ignored if Dataset is not provided. + validation_fraction_split (float): + Optional. The fraction of the input data that is to be used to validate + the Model. This is ignored if Dataset is not provided. + test_fraction_split (float): + Optional. The fraction of the input data that is to be used to evaluate + the Model. This is ignored if Dataset is not provided. predefined_split_column_name (str): Optional. The key is a name of one of the Dataset's data columns. The value of the key (either the label's value or - value in the column) must be one of {``TRAIN``, - ``VALIDATE``, ``TEST``}, and it defines to which set the + value in the column) must be one of {``training``, + ``validation``, ``test``}, and it defines to which set the given piece of data is assigned. If for a piece of data the key is not present or has an invalid value, that piece is ignored by the pipeline. Supported only for tabular and time series Datasets. + timestamp_split_column_name (str): + Optional. The key is a name of one of the Dataset's data + columns. The value of the key values of the key (the values in + the column) must be in RFC 3339 `date-time` format, where + `time-offset` = `"Z"` (e.g. 1985-04-12T23:20:50.52Z). If for a + piece of data the key is not present or has an invalid value, + that piece is ignored by the pipeline. + Supported only for tabular and time series Datasets. + This parameter must be used with training_fraction_split, + validation_fraction_split, and test_fraction_split. weight_column (str): Optional. Name of the column that should be used as the weight column. Higher values in this column give more importance to the row @@ -3014,14 +4564,40 @@ def _run( 10000 inclusively, and 0 value means that the row is ignored. If the weight column field is not set, then all rows are assumed to have equal weight of 1. - time_series_attribute_columns (List[str]): - Optional. Column names that should be used as attribute columns. - Each column is constant within a time series. - context_window (int): - Optional. The number of periods offset into the past to restrict past sequence, where each - period is one unit of granularity as defined by [period]. When not provided uses the - default value of 0 which means the model sets each series historical window to be 0 (also - known as "cold start"). Inclusive. + budget_milli_node_hours (int): + Optional. The train budget of creating this Model, expressed in milli node + hours i.e. 1,000 value in this field means 1 node hour. + The training cost of the model will not exceed this budget. The final + cost will be attempted to be close to the budget, though may end up + being (even) noticeably smaller - at the backend's discretion. This + especially may happen when further model training ceases to provide + any improvements. + If the budget is set to a value known to be insufficient to train a + Model for the given training set, the training won't be attempted and + will error. + The minimum value is 1000 and the maximum is 72000. + model_display_name (str): + Optional. If the script produces a managed Vertex AI Model. The display name of + the Model. The name can be up to 128 characters long and can be consist + of any UTF-8 characters. + + If not provided upon creation, the job's display_name is used. + model_labels (Dict[str, str]): + Optional. The labels with user-defined metadata to + organize your Models. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + and examples of labels. + disable_early_stopping (bool): + Required. If true, the entire budget is used. This disables the early stopping + feature. By default, the early stopping feature is enabled, which means + that training might stop before the entire training budget has been + used, if further training does no longer brings significant improvement + to the model. export_evaluated_data_items (bool): Whether to export the test set predictions to a BigQuery table. If False, then the export is not performed. @@ -3043,68 +4619,50 @@ def _run( Applies only if [export_evaluated_data_items] is True and [export_evaluated_data_items_bigquery_destination_uri] is specified. - quantiles (List[float]): - Quantiles to use for the `minizmize-quantile-loss` - [AutoMLForecastingTrainingJob.optimization_objective]. This argument is required in - this case. - - Accepts up to 5 quantiles in the form of a double from 0 to 1, exclusive. - Each quantile must be unique. - validation_options (str): - Validation options for the data validation component. The available options are: - "fail-pipeline" - (default), will validate against the validation and fail the pipeline - if it fails. - "ignore-validation" - ignore the results of the validation and continue the pipeline - budget_milli_node_hours (int): - Optional. The train budget of creating this Model, expressed in milli node - hours i.e. 1,000 value in this field means 1 node hour. - The training cost of the model will not exceed this budget. The final - cost will be attempted to be close to the budget, though may end up - being (even) noticeably smaller - at the backend's discretion. This - especially may happen when further model training ceases to provide - any improvements. - If the budget is set to a value known to be insufficient to train a - Model for the given training set, the training won't be attempted and - will error. - The minimum value is 1000 and the maximum is 72000. - model_display_name (str): - Optional. If the script produces a managed Vertex AI Model. The display name of - the Model. The name can be up to 128 characters long and can be consist - of any UTF-8 characters. - - If not provided upon creation, the job's display_name is used. sync (bool): Whether to execute this method synchronously. If False, this method will be executed in concurrent Future and any downstream object will be immediately returned and synced when the Future has completed. + create_request_timeout (float): + Optional. The timeout for the create request in seconds. + Returns: model: The trained Vertex AI Model resource or None if training did not - produce an Vertex AI Model. + produce a Vertex AI Model. """ - training_task_definition = schema.training_job.definition.automl_forecasting + training_task_definition = schema.training_job.definition.automl_tabular + + # auto-populate transformations + if self._column_transformations is None: + _LOGGER.info( + "No column transformations provided, so now retrieving columns from dataset in order to set default column transformations." + ) + + ( + self._column_transformations, + column_names, + ) = column_transformations_utils.get_default_column_transformations( + dataset=dataset, target_column=target_column + ) + + _LOGGER.info( + "The column transformation of type 'auto' was set for the following columns: %s." + % column_names + ) training_task_inputs_dict = { # required inputs "targetColumn": target_column, - "timeColumn": time_column, - "timeSeriesIdentifierColumn": time_series_identifier_column, - "timeSeriesAttributeColumns": time_series_attribute_columns, - "unavailableAtForecastColumns": unavailable_at_forecast_columns, - "availableAtForecastColumns": available_at_forecast_columns, - "forecastHorizon": forecast_horizon, - "dataGranularity": { - "unit": data_granularity_unit, - "quantity": data_granularity_count, - }, "transformations": self._column_transformations, "trainBudgetMilliNodeHours": budget_milli_node_hours, # optional inputs - "weightColumn": weight_column, - "contextWindow": context_window, - "quantiles": quantiles, - "validationOptions": validation_options, + "weightColumnName": weight_column, + "disableEarlyStopping": disable_early_stopping, "optimizationObjective": self._optimization_objective, + "predictionType": self._optimization_prediction_type, + "optimizationObjectiveRecallValue": self._optimization_objective_recall_value, + "optimizationObjectivePrecisionValue": self._optimization_objective_precision_value, } final_export_eval_bq_uri = export_evaluated_data_items_bigquery_destination_uri @@ -3119,20 +4677,28 @@ def _run( "overrideExistingTable": export_evaluated_data_items_override_destination, } - if model_display_name is None: - model_display_name = self._display_name + if self._additional_experiments: + training_task_inputs_dict[ + "additionalExperiments" + ] = self._additional_experiments - model = gca_model.Model(display_name=model_display_name) + model = gca_model.Model( + display_name=model_display_name or self._display_name, + labels=model_labels or self._labels, + encryption_spec=self._model_encryption_spec, + ) return self._run_job( training_task_definition=training_task_definition, training_task_inputs=training_task_inputs_dict, dataset=dataset, - training_fraction_split=0.8, - validation_fraction_split=0.1, - test_fraction_split=0.1, + training_fraction_split=training_fraction_split, + validation_fraction_split=validation_fraction_split, + test_fraction_split=test_fraction_split, predefined_split_column_name=predefined_split_column_name, + timestamp_split_column_name=timestamp_split_column_name, model=model, + create_request_timeout=create_request_timeout, ) @property @@ -3143,6 +4709,223 @@ def _model_upload_fail_string(self) -> str: "Model." ) + def _add_additional_experiments(self, additional_experiments: List[str]): + """Add experiment flags to the training job. + Args: + additional_experiments (List[str]): + Experiment flags that can enable some experimental training features. + """ + self._additional_experiments.extend(additional_experiments) + + @staticmethod + def get_auto_column_specs( + dataset: datasets.TabularDataset, + target_column: str, + ) -> Dict[str, str]: + """Returns a dict with all non-target columns as keys and 'auto' as values. + + Example usage: + + column_specs = training_jobs.AutoMLTabularTrainingJob.get_auto_column_specs( + dataset=my_dataset, + target_column="my_target_column", + ) + + Args: + dataset (datasets.TabularDataset): + Required. Intended dataset. + target_column(str): + Required. Intended target column. + Returns: + Dict[str, str] + Column names as keys and 'auto' as values + """ + column_names = [ + column for column in dataset.column_names if column != target_column + ] + column_specs = {column: "auto" for column in column_names} + return column_specs + + class column_data_types: + AUTO = "auto" + NUMERIC = "numeric" + CATEGORICAL = "categorical" + TIMESTAMP = "timestamp" + TEXT = "text" + REPEATED_NUMERIC = "repeated_numeric" + REPEATED_CATEGORICAL = "repeated_categorical" + REPEATED_TEXT = "repeated_text" + + +class AutoMLForecastingTrainingJob(_ForecastingTrainingJob): + _model_type = "AutoML" + _training_task_definition = schema.training_job.definition.automl_forecasting + _supported_training_schemas = (schema.training_job.definition.automl_forecasting,) + + def run( + self, + dataset: datasets.TimeSeriesDataset, + target_column: str, + time_column: str, + time_series_identifier_column: str, + unavailable_at_forecast_columns: List[str], + available_at_forecast_columns: List[str], + forecast_horizon: int, + data_granularity_unit: str, + data_granularity_count: int, + training_fraction_split: Optional[float] = None, + validation_fraction_split: Optional[float] = None, + test_fraction_split: Optional[float] = None, + predefined_split_column_name: Optional[str] = None, + timestamp_split_column_name: Optional[str] = None, + weight_column: Optional[str] = None, + time_series_attribute_columns: Optional[List[str]] = None, + context_window: Optional[int] = None, + export_evaluated_data_items: bool = False, + export_evaluated_data_items_bigquery_destination_uri: Optional[str] = None, + export_evaluated_data_items_override_destination: bool = False, + quantiles: Optional[List[float]] = None, + validation_options: Optional[str] = None, + budget_milli_node_hours: int = 1000, + model_display_name: Optional[str] = None, + model_labels: Optional[Dict[str, str]] = None, + additional_experiments: Optional[List[str]] = None, + hierarchy_group_columns: Optional[List[str]] = None, + hierarchy_group_total_weight: Optional[float] = None, + hierarchy_temporal_total_weight: Optional[float] = None, + hierarchy_group_temporal_total_weight: Optional[float] = None, + window_column: Optional[str] = None, + window_stride_length: Optional[int] = None, + window_max_count: Optional[int] = None, + holiday_regions: Optional[List[str]] = None, + sync: bool = True, + create_request_timeout: Optional[float] = None, + ) -> models.Model: + return super().run( + dataset=dataset, + target_column=target_column, + time_column=time_column, + time_series_identifier_column=time_series_identifier_column, + unavailable_at_forecast_columns=unavailable_at_forecast_columns, + available_at_forecast_columns=available_at_forecast_columns, + forecast_horizon=forecast_horizon, + data_granularity_unit=data_granularity_unit, + data_granularity_count=data_granularity_count, + training_fraction_split=training_fraction_split, + validation_fraction_split=validation_fraction_split, + test_fraction_split=test_fraction_split, + predefined_split_column_name=predefined_split_column_name, + timestamp_split_column_name=timestamp_split_column_name, + weight_column=weight_column, + time_series_attribute_columns=time_series_attribute_columns, + context_window=context_window, + budget_milli_node_hours=budget_milli_node_hours, + export_evaluated_data_items=export_evaluated_data_items, + export_evaluated_data_items_bigquery_destination_uri=export_evaluated_data_items_bigquery_destination_uri, + export_evaluated_data_items_override_destination=export_evaluated_data_items_override_destination, + quantiles=quantiles, + validation_options=validation_options, + model_display_name=model_display_name, + model_labels=model_labels, + additional_experiments=additional_experiments, + hierarchy_group_columns=hierarchy_group_columns, + hierarchy_group_total_weight=hierarchy_group_total_weight, + hierarchy_temporal_total_weight=hierarchy_temporal_total_weight, + hierarchy_group_temporal_total_weight=hierarchy_group_temporal_total_weight, + window_column=window_column, + window_stride_length=window_stride_length, + window_max_count=window_max_count, + holiday_regions=holiday_regions, + sync=sync, + create_request_timeout=create_request_timeout, + ) + + +class SequenceToSequencePlusForecastingTrainingJob(_ForecastingTrainingJob): + _model_type = "Seq2Seq" + _training_task_definition = schema.training_job.definition.seq2seq_plus_forecasting + _supported_training_schemas = ( + schema.training_job.definition.seq2seq_plus_forecasting, + ) + + def run( + self, + dataset: datasets.TimeSeriesDataset, + target_column: str, + time_column: str, + time_series_identifier_column: str, + unavailable_at_forecast_columns: List[str], + available_at_forecast_columns: List[str], + forecast_horizon: int, + data_granularity_unit: str, + data_granularity_count: int, + training_fraction_split: Optional[float] = None, + validation_fraction_split: Optional[float] = None, + test_fraction_split: Optional[float] = None, + predefined_split_column_name: Optional[str] = None, + timestamp_split_column_name: Optional[str] = None, + weight_column: Optional[str] = None, + time_series_attribute_columns: Optional[List[str]] = None, + context_window: Optional[int] = None, + export_evaluated_data_items: bool = False, + export_evaluated_data_items_bigquery_destination_uri: Optional[str] = None, + export_evaluated_data_items_override_destination: bool = False, + quantiles: Optional[List[float]] = None, + validation_options: Optional[str] = None, + budget_milli_node_hours: int = 1000, + model_display_name: Optional[str] = None, + model_labels: Optional[Dict[str, str]] = None, + additional_experiments: Optional[List[str]] = None, + hierarchy_group_columns: Optional[List[str]] = None, + hierarchy_group_total_weight: Optional[float] = None, + hierarchy_temporal_total_weight: Optional[float] = None, + hierarchy_group_temporal_total_weight: Optional[float] = None, + window_column: Optional[str] = None, + window_stride_length: Optional[int] = None, + window_max_count: Optional[int] = None, + holiday_regions: Optional[List[str]] = None, + sync: bool = True, + create_request_timeout: Optional[float] = None, + ) -> models.Model: + return super().run( + dataset=dataset, + target_column=target_column, + time_column=time_column, + time_series_identifier_column=time_series_identifier_column, + unavailable_at_forecast_columns=unavailable_at_forecast_columns, + available_at_forecast_columns=available_at_forecast_columns, + forecast_horizon=forecast_horizon, + data_granularity_unit=data_granularity_unit, + data_granularity_count=data_granularity_count, + training_fraction_split=training_fraction_split, + validation_fraction_split=validation_fraction_split, + test_fraction_split=test_fraction_split, + predefined_split_column_name=predefined_split_column_name, + timestamp_split_column_name=timestamp_split_column_name, + weight_column=weight_column, + time_series_attribute_columns=time_series_attribute_columns, + context_window=context_window, + budget_milli_node_hours=budget_milli_node_hours, + export_evaluated_data_items=export_evaluated_data_items, + export_evaluated_data_items_bigquery_destination_uri=export_evaluated_data_items_bigquery_destination_uri, + export_evaluated_data_items_override_destination=export_evaluated_data_items_override_destination, + quantiles=quantiles, + validation_options=validation_options, + model_display_name=model_display_name, + model_labels=model_labels, + additional_experiments=additional_experiments, + hierarchy_group_columns=hierarchy_group_columns, + hierarchy_group_total_weight=hierarchy_group_total_weight, + hierarchy_temporal_total_weight=hierarchy_temporal_total_weight, + hierarchy_group_temporal_total_weight=hierarchy_group_temporal_total_weight, + window_column=window_column, + window_stride_length=window_stride_length, + window_max_count=window_max_count, + holiday_regions=holiday_regions, + sync=sync, + create_request_timeout=create_request_timeout, + ) + class AutoMLImageTrainingJob(_TrainingJob): _supported_training_schemas = ( @@ -3152,7 +4935,7 @@ class AutoMLImageTrainingJob(_TrainingJob): def __init__( self, - display_name: str, + display_name: Optional[str] = None, prediction_type: str = "classification", multi_label: bool = False, model_type: str = "CLOUD", @@ -3160,6 +4943,7 @@ def __init__( project: Optional[str] = None, location: Optional[str] = None, credentials: Optional[auth_credentials.Credentials] = None, + labels: Optional[Dict[str, str]] = None, training_encryption_spec_key_name: Optional[str] = None, model_encryption_spec_key_name: Optional[str] = None, ): @@ -3167,7 +4951,7 @@ def __init__( Args: display_name (str): - Required. The user-defined name of this TrainingPipeline. + Optional. The user-defined name of this TrainingPipeline. prediction_type (str): The type of prediction the Model is to produce, one of: "classification" - Predict one out of multiple target values is @@ -3225,6 +5009,16 @@ def __init__( credentials (auth_credentials.Credentials): Optional. Custom credentials to use to run call training service. Overrides credentials set in aiplatform.init. + labels (Dict[str, str]): + Optional. The labels with user-defined metadata to + organize TrainingPipelines. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + and examples of labels. training_encryption_spec_key_name (Optional[str]): Optional. The Cloud KMS resource identifier of the customer managed encryption key used to protect the training pipeline. Has the @@ -3253,6 +5047,8 @@ def __init__( Raises: ValueError: When an invalid prediction_type or model_type is provided. """ + if not display_name: + display_name = self.__class__._generate_display_name() valid_model_types = constants.AUTOML_IMAGE_PREDICTION_MODEL_TYPES.get( prediction_type, None @@ -3285,6 +5081,7 @@ def __init__( project=project, location=location, credentials=credentials, + labels=labels, training_encryption_spec_key_name=training_encryption_spec_key_name, model_encryption_spec_key_name=model_encryption_spec_key_name, ) @@ -3297,22 +5094,39 @@ def __init__( def run( self, dataset: datasets.ImageDataset, - training_fraction_split: float = 0.8, - validation_fraction_split: float = 0.1, - test_fraction_split: float = 0.1, - budget_milli_node_hours: int = 1000, + training_fraction_split: Optional[float] = None, + validation_fraction_split: Optional[float] = None, + test_fraction_split: Optional[float] = None, + training_filter_split: Optional[str] = None, + validation_filter_split: Optional[str] = None, + test_filter_split: Optional[str] = None, + budget_milli_node_hours: Optional[int] = None, model_display_name: Optional[str] = None, + model_labels: Optional[Dict[str, str]] = None, disable_early_stopping: bool = False, sync: bool = True, + create_request_timeout: Optional[float] = None, ) -> models.Model: """Runs the AutoML Image training job and returns a model. - Data fraction splits: - Any of ``training_fraction_split``, ``validation_fraction_split`` and - ``test_fraction_split`` may optionally be provided, they must sum to up to 1. If - the provided ones sum to less than 1, the remainder is assigned to sets as - decided by Vertex AI. If none of the fractions are set, by default roughly 80% - of data will be used for training, 10% for validation, and 10% for test. + If training on a Vertex AI dataset, you can use one of the following split configurations: + Data fraction splits: + Any of ``training_fraction_split``, ``validation_fraction_split`` and + ``test_fraction_split`` may optionally be provided, they must sum to up to 1. If + the provided ones sum to less than 1, the remainder is assigned to sets as + decided by Vertex AI. If none of the fractions are set, by default roughly 80% + of data will be used for training, 10% for validation, and 10% for test. + + Data filter splits: + Assigns input data to training, validation, and test sets + based on the given filters, data pieces not matched by any + filter are ignored. Currently only supported for Datasets + containing DataItems. + If any of the filters in this message are to match nothing, then + they can be set as '-' (the minus sign). + If using filter splits, all of ``training_filter_split``, ``validation_filter_split`` and + ``test_filter_split`` must be provided. + Supported only for unstructured Datasets. Args: dataset (datasets.ImageDataset): @@ -3323,31 +5137,70 @@ def run( [google.cloud.aiplatform.v1beta1.TrainingPipeline.training_task_definition]. For tabular Datasets, all their data is exported to training, to pick and choose from. - training_fraction_split: float = 0.8 - Required. The fraction of the input data that is to be - used to train the Model. This is ignored if Dataset is not provided. - validation_fraction_split: float = 0.1 - Required. The fraction of the input data that is to be - used to validate the Model. This is ignored if Dataset is not provided. - test_fraction_split: float = 0.1 - Required. The fraction of the input data that is to be - used to evaluate the Model. This is ignored if Dataset is not provided. - budget_milli_node_hours: int = 1000 + training_fraction_split (float): + Optional. The fraction of the input data that is to be used to train + the Model. This is ignored if Dataset is not provided. + validation_fraction_split (float): + Optional. The fraction of the input data that is to be used to validate + the Model. This is ignored if Dataset is not provided. + test_fraction_split (float): + Optional. The fraction of the input data that is to be used to evaluate + the Model. This is ignored if Dataset is not provided. + training_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to train the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. + validation_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to validate the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. + test_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to test the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. + budget_milli_node_hours (int): Optional. The train budget of creating this Model, expressed in milli node hours i.e. 1,000 value in this field means 1 node hour. + + Defaults by `prediction_type`: + + `classification` - For Cloud models the budget must be: 8,000 - 800,000 + milli node hours (inclusive). The default value is 192,000 which + represents one day in wall time, assuming 8 nodes are used. + `object_detection` - For Cloud models the budget must be: 20,000 - 900,000 + milli node hours (inclusive). The default value is 216,000 which represents + one day in wall time, assuming 9 nodes are used. + The training cost of the model will not exceed this budget. The final cost will be attempted to be close to the budget, though may end up being (even) noticeably smaller - at the backend's discretion. This especially may happen when further model training ceases to provide - any improvements. - If the budget is set to a value known to be insufficient to train a - Model for the given training set, the training won't be attempted and + any improvements. If the budget is set to a value known to be insufficient to + train a Model for the given training set, the training won't be attempted and will error. - The minimum value is 1000 and the maximum is 72000. model_display_name (str): Optional. The display name of the managed Vertex AI Model. The name can be up to 128 characters long and can be consist of any UTF-8 characters. If not provided upon creation, the job's display_name is used. + model_labels (Dict[str, str]): + Optional. The labels with user-defined metadata to + organize your Models. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + and examples of labels. disable_early_stopping: bool = False Required. If true, the entire budget is used. This disables the early stopping feature. By default, the early stopping feature is enabled, which means @@ -3358,14 +5211,21 @@ def run( Whether to execute this method synchronously. If False, this method will be executed in concurrent Future and any downstream object will be immediately returned and synced when the Future has completed. + create_request_timeout (float): + Optional. The timeout for the create request in seconds. Returns: model: The trained Vertex AI Model resource or None if training did not - produce an Vertex AI Model. + produce a Vertex AI Model. Raises: RuntimeError: If Training job has already been run or is waiting to run. """ + if model_display_name: + utils.validate_display_name(model_display_name) + if model_labels: + utils.validate_labels(model_labels) + if self._is_waiting_to_run(): raise RuntimeError("AutoML Image Training is already scheduled to run.") @@ -3378,10 +5238,15 @@ def run( training_fraction_split=training_fraction_split, validation_fraction_split=validation_fraction_split, test_fraction_split=test_fraction_split, + training_filter_split=training_filter_split, + validation_filter_split=validation_filter_split, + test_filter_split=test_filter_split, budget_milli_node_hours=budget_milli_node_hours, model_display_name=model_display_name, + model_labels=model_labels, disable_early_stopping=disable_early_stopping, sync=sync, + create_request_timeout=create_request_timeout, ) @base.optional_sync() @@ -3389,22 +5254,39 @@ def _run( self, dataset: datasets.ImageDataset, base_model: Optional[models.Model] = None, - training_fraction_split: float = 0.8, - validation_fraction_split: float = 0.1, - test_fraction_split: float = 0.1, + training_fraction_split: Optional[float] = None, + validation_fraction_split: Optional[float] = None, + test_fraction_split: Optional[float] = None, + training_filter_split: Optional[str] = None, + validation_filter_split: Optional[str] = None, + test_filter_split: Optional[str] = None, budget_milli_node_hours: int = 1000, model_display_name: Optional[str] = None, + model_labels: Optional[Dict[str, str]] = None, disable_early_stopping: bool = False, sync: bool = True, + create_request_timeout: Optional[float] = None, ) -> models.Model: """Runs the training job and returns a model. - Data fraction splits: - Any of ``training_fraction_split``, ``validation_fraction_split`` and - ``test_fraction_split`` may optionally be provided, they must sum to up to 1. If - the provided ones sum to less than 1, the remainder is assigned to sets as - decided by Vertex AI. If none of the fractions are set, by default roughly 80% - of data will be used for training, 10% for validation, and 10% for test. + If training on a Vertex AI dataset, you can use one of the following split configurations: + Data fraction splits: + Any of ``training_fraction_split``, ``validation_fraction_split`` and + ``test_fraction_split`` may optionally be provided, they must sum to up to 1. If + the provided ones sum to less than 1, the remainder is assigned to sets as + decided by Vertex AI. If none of the fractions are set, by default roughly 80% + of data will be used for training, 10% for validation, and 10% for test. + + Data filter splits: + Assigns input data to training, validation, and test sets + based on the given filters, data pieces not matched by any + filter are ignored. Currently only supported for Datasets + containing DataItems. + If any of the filters in this message are to match nothing, then + they can be set as '-' (the minus sign). + If using filter splits, all of ``training_filter_split``, ``validation_filter_split`` and + ``test_filter_split`` must be provided. + Supported only for unstructured Datasets. Args: dataset (datasets.ImageDataset): @@ -3422,14 +5304,35 @@ def _run( must be in the same Project and Location as the new Model to train, and have the same model_type. training_fraction_split (float): - Required. The fraction of the input data that is to be - used to train the Model. This is ignored if Dataset is not provided. + Optional. The fraction of the input data that is to be used to train + the Model. This is ignored if Dataset is not provided. validation_fraction_split (float): - Required. The fraction of the input data that is to be - used to validate the Model. This is ignored if Dataset is not provided. + Optional. The fraction of the input data that is to be used to validate + the Model. This is ignored if Dataset is not provided. test_fraction_split (float): - Required. The fraction of the input data that is to be - used to evaluate the Model. This is ignored if Dataset is not provided. + Optional. The fraction of the input data that is to be used to evaluate + the Model. This is ignored if Dataset is not provided. + training_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to train the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. + validation_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to validate the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. + test_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to test the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. budget_milli_node_hours (int): Optional. The train budget of creating this Model, expressed in milli node hours i.e. 1,000 value in this field means 1 node hour. @@ -3448,6 +5351,16 @@ def _run( characters. If a `base_model` was provided, the display_name in the base_model will be overritten with this value. If not provided upon creation, the job's display_name is used. + model_labels (Dict[str, str]): + Optional. The labels with user-defined metadata to + organize your Models. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + and examples of labels. disable_early_stopping (bool): Required. If true, the entire budget is used. This disables the early stopping feature. By default, the early stopping feature is enabled, which means @@ -3458,10 +5371,12 @@ def _run( Whether to execute this method synchronously. If False, this method will be executed in concurrent Future and any downstream object will be immediately returned and synced when the Future has completed. + create_request_timeout (float): + Optional. The timeout for the create request in seconds. Returns: model: The trained Vertex AI Model resource or None if training did not - produce an Vertex AI Model. + produce a Vertex AI Model. """ # Retrieve the objective-specific training task schema based on prediction_type @@ -3484,6 +5399,7 @@ def _run( model_tbt = gca_model.Model(encryption_spec=self._model_encryption_spec) model_tbt.display_name = model_display_name or self._display_name + model_tbt.labels = model_labels or self._labels if base_model: # Use provided base_model to pass to model_to_upload causing the @@ -3501,7 +5417,11 @@ def _run( training_fraction_split=training_fraction_split, validation_fraction_split=validation_fraction_split, test_fraction_split=test_fraction_split, + training_filter_split=training_filter_split, + validation_filter_split=validation_filter_split, + test_filter_split=test_filter_split, model=model_tbt, + create_request_timeout=create_request_timeout, ) @property @@ -3523,6 +5443,7 @@ class CustomPythonPackageTrainingJob(_CustomTrainingJob): def __init__( self, + # TODO(b/223262536): Make display_name parameter fully optional in next major release display_name: str, python_package_gcs_uri: str, python_module_name: str, @@ -3541,6 +5462,7 @@ def __init__( project: Optional[str] = None, location: Optional[str] = None, credentials: Optional[auth_credentials.Credentials] = None, + labels: Optional[Dict[str, str]] = None, training_encryption_spec_key_name: Optional[str] = None, model_encryption_spec_key_name: Optional[str] = None, staging_bucket: Optional[str] = None, @@ -3554,7 +5476,8 @@ def __init__( container_uri='gcr.io/cloud-aiplatform/training/tf-cpu.2-2:latest', model_serving_container_image_uri='gcr.io/my-trainer/serving:1', model_serving_container_predict_route='predict', - model_serving_container_health_route='metadata + model_serving_container_health_route='metadata, + labels={'key': 'value'}, ) Usage with Dataset: @@ -3566,14 +5489,16 @@ def __init__( job.run( ds, replica_count=1, - model_display_name='my-trained-model' + model_display_name='my-trained-model', + model_labels={'key': 'value'}, ) Usage without Dataset: job.run( replica_count=1, - model_display_name='my-trained-model' + model_display_name='my-trained-model', + model_labels={'key': 'value'}, ) To ensure your model gets saved in Vertex AI, write your saved model to @@ -3682,6 +5607,16 @@ def __init__( credentials (auth_credentials.Credentials): Custom credentials to use to run call training service. Overrides credentials set in aiplatform.init. + labels (Dict[str, str]): + Optional. The labels with user-defined metadata to + organize TrainingPipelines. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + and examples of labels. training_encryption_spec_key_name (Optional[str]): Optional. The Cloud KMS resource identifier of the customer managed encryption key used to protect the training pipeline. Has the @@ -3711,11 +5646,14 @@ def __init__( Bucket used to stage source and training artifacts. Overrides staging_bucket set in aiplatform.init. """ + if not display_name: + display_name = self.__class__._generate_display_name() super().__init__( display_name=display_name, project=project, location=location, credentials=credentials, + labels=labels, training_encryption_spec_key_name=training_encryption_spec_key_name, model_encryption_spec_key_name=model_encryption_spec_key_name, container_uri=container_uri, @@ -3748,21 +5686,36 @@ def run( ] = None, annotation_schema_uri: Optional[str] = None, model_display_name: Optional[str] = None, + model_labels: Optional[Dict[str, str]] = None, base_output_dir: Optional[str] = None, service_account: Optional[str] = None, network: Optional[str] = None, bigquery_destination: Optional[str] = None, args: Optional[List[Union[str, float, int]]] = None, environment_variables: Optional[Dict[str, str]] = None, - replica_count: int = 0, + replica_count: int = 1, machine_type: str = "n1-standard-4", accelerator_type: str = "ACCELERATOR_TYPE_UNSPECIFIED", accelerator_count: int = 0, - training_fraction_split: float = 0.8, - validation_fraction_split: float = 0.1, - test_fraction_split: float = 0.1, + boot_disk_type: str = "pd-ssd", + boot_disk_size_gb: int = 100, + reduction_server_replica_count: int = 0, + reduction_server_machine_type: Optional[str] = None, + reduction_server_container_uri: Optional[str] = None, + training_fraction_split: Optional[float] = None, + validation_fraction_split: Optional[float] = None, + test_fraction_split: Optional[float] = None, + training_filter_split: Optional[str] = None, + validation_filter_split: Optional[str] = None, + test_filter_split: Optional[str] = None, predefined_split_column_name: Optional[str] = None, + timestamp_split_column_name: Optional[str] = None, + timeout: Optional[int] = None, + restart_job_on_worker_restart: bool = False, + enable_web_access: bool = False, + tensorboard: Optional[str] = None, sync=True, + create_request_timeout: Optional[float] = None, ) -> Optional[models.Model]: """Runs the custom training job. @@ -3772,12 +5725,36 @@ def run( ie: replica_count = 10 will result in 1 chief and 9 workers All replicas have same machine_type, accelerator_type, and accelerator_count - Data fraction splits: - Any of ``training_fraction_split``, ``validation_fraction_split`` and - ``test_fraction_split`` may optionally be provided, they must sum to up to 1. If - the provided ones sum to less than 1, the remainder is assigned to sets as - decided by Vertex AI.If none of the fractions are set, by default roughly 80% - of data will be used for training, 10% for validation, and 10% for test. + If training on a Vertex AI dataset, you can use one of the following split configurations: + Data fraction splits: + Any of ``training_fraction_split``, ``validation_fraction_split`` and + ``test_fraction_split`` may optionally be provided, they must sum to up to 1. If + the provided ones sum to less than 1, the remainder is assigned to sets as + decided by Vertex AI. If none of the fractions are set, by default roughly 80% + of data will be used for training, 10% for validation, and 10% for test. + + Data filter splits: + Assigns input data to training, validation, and test sets + based on the given filters, data pieces not matched by any + filter are ignored. Currently only supported for Datasets + containing DataItems. + If any of the filters in this message are to match nothing, then + they can be set as '-' (the minus sign). + If using filter splits, all of ``training_filter_split``, ``validation_filter_split`` and + ``test_filter_split`` must be provided. + Supported only for unstructured Datasets. + + Predefined splits: + Assigns input data to training, validation, and test sets based on the value of a provided key. + If using predefined splits, ``predefined_split_column_name`` must be provided. + Supported only for tabular Datasets. + + Timestamp splits: + Assigns input data to training, validation, and test sets + based on a provided timestamps. The youngest data pieces are + assigned to training set, next to validation set, and the oldest + to the test set. + Supported only for tabular Datasets. Args: dataset (Union[datasets.ImageDataset,datasets.TabularDataset,datasets.TextDataset,datasets.VideoDataset,]): @@ -3794,7 +5771,7 @@ def run( annotation_schema_uri (str): Google Cloud Storage URI points to a YAML file describing annotation schema. The schema is defined as an OpenAPI 3.0.2 - [Schema Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#schema-object) The schema files + [Schema Object](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.2.md#schema-object) The schema files that can be used here are found in gs://google-cloud-aiplatform/schema/dataset/annotation/, note that the chosen schema must be consistent with @@ -3819,6 +5796,16 @@ def run( of any UTF-8 characters. If not provided upon creation, the job's display_name is used. + model_labels (Dict[str, str]): + Optional. The labels with user-defined metadata to + organize your Models. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + and examples of labels. base_output_dir (str): GCS output directory of job. If not provided a timestamped directory in the staging directory will be used. @@ -3876,15 +5863,50 @@ def run( NVIDIA_TESLA_T4 accelerator_count (int): The number of accelerators to attach to a worker replica. + boot_disk_type (str): + Type of the boot disk, default is `pd-ssd`. + Valid values: `pd-ssd` (Persistent Disk Solid State Drive) or + `pd-standard` (Persistent Disk Hard Disk Drive). + boot_disk_size_gb (int): + Size in GB of the boot disk, default is 100GB. + boot disk size must be within the range of [100, 64000]. + reduction_server_replica_count (int): + The number of reduction server replicas, default is 0. + reduction_server_machine_type (str): + Optional. The type of machine to use for reduction server. + reduction_server_container_uri (str): + Optional. The Uri of the reduction server container image. + See details: https://cloud.google.com/vertex-ai/docs/training/distributed-training#reduce_training_time_with_reduction_server training_fraction_split (float): - The fraction of the input data that is to be - used to train the Model. This is ignored if Dataset is not provided. + Optional. The fraction of the input data that is to be used to train + the Model. This is ignored if Dataset is not provided. validation_fraction_split (float): - The fraction of the input data that is to be - used to validate the Model. This is ignored if Dataset is not provided. + Optional. The fraction of the input data that is to be used to validate + the Model. This is ignored if Dataset is not provided. test_fraction_split (float): - The fraction of the input data that is to be - used to evaluate the Model. This is ignored if Dataset is not provided. + Optional. The fraction of the input data that is to be used to evaluate + the Model. This is ignored if Dataset is not provided. + training_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to train the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. + validation_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to validate the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. + test_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to test the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. predefined_split_column_name (str): Optional. The key is a name of one of the Dataset's data columns. The value of the key (either the label's value or @@ -3895,21 +5917,63 @@ def run( ignored by the pipeline. Supported only for tabular and time series Datasets. + timestamp_split_column_name (str): + Optional. The key is a name of one of the Dataset's data + columns. The value of the key values of the key (the values in + the column) must be in RFC 3339 `date-time` format, where + `time-offset` = `"Z"` (e.g. 1985-04-12T23:20:50.52Z). If for a + piece of data the key is not present or has an invalid value, + that piece is ignored by the pipeline. + + Supported only for tabular and time series Datasets. + timeout (int): + The maximum job running time in seconds. The default is 7 days. + restart_job_on_worker_restart (bool): + Restarts the entire CustomJob if a worker + gets restarted. This feature can be used by + distributed training jobs that are not resilient + to workers leaving and joining a job. + enable_web_access (bool): + Whether you want Vertex AI to enable interactive shell access + to training containers. + https://cloud.google.com/vertex-ai/docs/training/monitor-debug-interactive-shell + tensorboard (str): + Optional. The name of a Vertex AI + [Tensorboard][google.cloud.aiplatform.v1beta1.Tensorboard] + resource to which this CustomJob will upload Tensorboard + logs. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}`` + + The training script should write Tensorboard to following Vertex AI environment + variable: + + AIP_TENSORBOARD_LOG_DIR + + `service_account` is required with provided `tensorboard`. + For more information on configuring your service account please visit: + https://cloud.google.com/vertex-ai/docs/experiments/tensorboard-training sync (bool): Whether to execute this method synchronously. If False, this method will be executed in concurrent Future and any downstream object will be immediately returned and synced when the Future has completed. + create_request_timeout (float): + Optional. The timeout for the create request in seconds. Returns: model: The trained Vertex AI Model resource or None if training did not - produce an Vertex AI Model. + produce a Vertex AI Model. """ worker_pool_specs, managed_model = self._prepare_and_validate_run( model_display_name=model_display_name, + model_labels=model_labels, replica_count=replica_count, machine_type=machine_type, accelerator_count=accelerator_count, accelerator_type=accelerator_type, + boot_disk_type=boot_disk_type, + boot_disk_size_gb=boot_disk_size_gb, + reduction_server_replica_count=reduction_server_replica_count, + reduction_server_machine_type=reduction_server_machine_type, ) return self._run( @@ -3925,9 +5989,21 @@ def run( training_fraction_split=training_fraction_split, validation_fraction_split=validation_fraction_split, test_fraction_split=test_fraction_split, + training_filter_split=training_filter_split, + validation_filter_split=validation_filter_split, + test_filter_split=test_filter_split, predefined_split_column_name=predefined_split_column_name, + timestamp_split_column_name=timestamp_split_column_name, bigquery_destination=bigquery_destination, + timeout=timeout, + restart_job_on_worker_restart=restart_job_on_worker_restart, + enable_web_access=enable_web_access, + tensorboard=tensorboard, + reduction_server_container_uri=reduction_server_container_uri + if reduction_server_replica_count > 0 + else None, sync=sync, + create_request_timeout=create_request_timeout, ) @base.optional_sync(construct_object_on_arg="managed_model") @@ -3949,12 +6025,22 @@ def _run( base_output_dir: Optional[str] = None, service_account: Optional[str] = None, network: Optional[str] = None, - training_fraction_split: float = 0.8, - validation_fraction_split: float = 0.1, - test_fraction_split: float = 0.1, + training_fraction_split: Optional[float] = None, + validation_fraction_split: Optional[float] = None, + test_fraction_split: Optional[float] = None, + training_filter_split: Optional[str] = None, + validation_filter_split: Optional[str] = None, + test_filter_split: Optional[str] = None, predefined_split_column_name: Optional[str] = None, + timestamp_split_column_name: Optional[str] = None, bigquery_destination: Optional[str] = None, + timeout: Optional[int] = None, + restart_job_on_worker_restart: bool = False, + enable_web_access: bool = False, + tensorboard: Optional[str] = None, + reduction_server_container_uri: Optional[str] = None, sync=True, + create_request_timeout: Optional[float] = None, ) -> Optional[models.Model]: """Packages local script and launches training_job. @@ -4006,14 +6092,35 @@ def _run( Private services access must already be configured for the network. If left unspecified, the job is not peered with any network. training_fraction_split (float): - The fraction of the input data that is to be - used to train the Model. + Optional. The fraction of the input data that is to be used to train + the Model. This is ignored if Dataset is not provided. validation_fraction_split (float): - The fraction of the input data that is to be - used to validate the Model. + Optional. The fraction of the input data that is to be used to validate + the Model. This is ignored if Dataset is not provided. test_fraction_split (float): - The fraction of the input data that is to be - used to evaluate the Model. + Optional. The fraction of the input data that is to be used to evaluate + the Model. This is ignored if Dataset is not provided. + training_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to train the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. + validation_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to validate the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. + test_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to test the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. predefined_split_column_name (str): Optional. The key is a name of one of the Dataset's data columns. The value of the key (either the label's value or @@ -4024,30 +6131,81 @@ def _run( ignored by the pipeline. Supported only for tabular and time series Datasets. + timestamp_split_column_name (str): + Optional. The key is a name of one of the Dataset's data + columns. The value of the key values of the key (the values in + the column) must be in RFC 3339 `date-time` format, where + `time-offset` = `"Z"` (e.g. 1985-04-12T23:20:50.52Z). If for a + piece of data the key is not present or has an invalid value, + that piece is ignored by the pipeline. + + Supported only for tabular and time series Datasets. + timeout (int): + The maximum job running time in seconds. The default is 7 days. + restart_job_on_worker_restart (bool): + Restarts the entire CustomJob if a worker + gets restarted. This feature can be used by + distributed training jobs that are not resilient + to workers leaving and joining a job. + enable_web_access (bool): + Whether you want Vertex AI to enable interactive shell access + to training containers. + https://cloud.google.com/vertex-ai/docs/training/monitor-debug-interactive-shell + tensorboard (str): + Optional. The name of a Vertex AI + [Tensorboard][google.cloud.aiplatform.v1beta1.Tensorboard] + resource to which this CustomJob will upload Tensorboard + logs. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}`` + + The training script should write Tensorboard to following Vertex AI environment + variable: + + AIP_TENSORBOARD_LOG_DIR + + `service_account` is required with provided `tensorboard`. + For more information on configuring your service account please visit: + https://cloud.google.com/vertex-ai/docs/experiments/tensorboard-training + reduction_server_container_uri (str): + Optional. The Uri of the reduction server container image. sync (bool): Whether to execute this method synchronously. If False, this method will be executed in concurrent Future and any downstream object will be immediately returned and synced when the Future has completed. + create_request_timeout (float): + Optional. The timeout for the create request in seconds. Returns: model: The trained Vertex AI Model resource or None if training did not - produce an Vertex AI Model. + produce a Vertex AI Model. """ - for spec in worker_pool_specs: - spec["python_package_spec"] = { - "executor_image_uri": self._container_uri, - "python_module": self._python_module, - "package_uris": [self._package_gcs_uri], - } + for spec_order, spec in enumerate(worker_pool_specs): - if args: - spec["python_package_spec"]["args"] = args + if not spec: + continue - if environment_variables: - spec["python_package_spec"]["env"] = [ - {"name": key, "value": value} - for key, value in environment_variables.items() - ] + if ( + spec_order == worker_spec_utils._SPEC_ORDERS["server_spec"] + and reduction_server_container_uri + ): + spec["container_spec"] = { + "image_uri": reduction_server_container_uri, + } + else: + spec["python_package_spec"] = { + "executor_image_uri": self._container_uri, + "python_module": self._python_module, + "package_uris": [self._package_gcs_uri], + } + + if args: + spec["python_package_spec"]["args"] = args + + if environment_variables: + spec["python_package_spec"]["env"] = [ + {"name": key, "value": value} + for key, value in environment_variables.items() + ] ( training_task_inputs, @@ -4057,6 +6215,10 @@ def _run( base_output_dir=base_output_dir, service_account=service_account, network=network, + timeout=timeout, + restart_job_on_worker_restart=restart_job_on_worker_restart, + enable_web_access=enable_web_access, + tensorboard=tensorboard, ) model = self._run_job( @@ -4067,10 +6229,15 @@ def _run( training_fraction_split=training_fraction_split, validation_fraction_split=validation_fraction_split, test_fraction_split=test_fraction_split, + training_filter_split=training_filter_split, + validation_filter_split=validation_filter_split, + test_filter_split=test_filter_split, predefined_split_column_name=predefined_split_column_name, + timestamp_split_column_name=timestamp_split_column_name, model=managed_model, gcs_destination_uri_prefix=base_output_dir, bigquery_destination=bigquery_destination, + create_request_timeout=create_request_timeout, ) return model @@ -4086,12 +6253,13 @@ class AutoMLVideoTrainingJob(_TrainingJob): def __init__( self, - display_name: str, + display_name: Optional[str] = None, prediction_type: str = "classification", model_type: str = "CLOUD", project: Optional[str] = None, location: Optional[str] = None, credentials: Optional[auth_credentials.Credentials] = None, + labels: Optional[Dict[str, str]] = None, training_encryption_spec_key_name: Optional[str] = None, model_encryption_spec_key_name: Optional[str] = None, ): @@ -4108,7 +6276,7 @@ def __init__( multiple objects in shots and segments. You can use these models to track objects in your videos according to your own pre-defined, custom labels. - "action_recognition" - A video action reconition model pinpoints + "action_recognition" - A video action recognition model pinpoints the location of actions with short temporal durations (~1 second). model_type: str = "CLOUD" Required. One of the following: @@ -4141,6 +6309,16 @@ def __init__( credentials (auth_credentials.Credentials): Optional. Custom credentials to use to run call training service. Overrides credentials set in aiplatform.init. + labels (Dict[str, str]): + Optional. The labels with user-defined metadata to + organize TrainingPipelines. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + and examples of labels. training_encryption_spec_key_name (Optional[str]): Optional. The Cloud KMS resource identifier of the customer managed encryption key used to protect the training pipeline. Has the @@ -4169,6 +6347,9 @@ def __init__( Raises: ValueError: When an invalid prediction_type and/or model_type is provided. """ + if not display_name: + display_name = self.__class__._generate_display_name() + valid_model_types = constants.AUTOML_VIDEO_PREDICTION_MODEL_TYPES.get( prediction_type, None ) @@ -4190,6 +6371,7 @@ def __init__( project=project, location=location, credentials=credentials, + labels=labels, training_encryption_spec_key_name=training_encryption_spec_key_name, model_encryption_spec_key_name=model_encryption_spec_key_name, ) @@ -4200,17 +6382,33 @@ def __init__( def run( self, dataset: datasets.VideoDataset, - training_fraction_split: float = 0.8, - test_fraction_split: float = 0.2, + training_fraction_split: Optional[float] = None, + test_fraction_split: Optional[float] = None, + training_filter_split: Optional[str] = None, + test_filter_split: Optional[str] = None, model_display_name: Optional[str] = None, + model_labels: Optional[Dict[str, str]] = None, sync: bool = True, + create_request_timeout: Optional[float] = None, ) -> models.Model: - """Runs the AutoML Image training job and returns a model. - - Data fraction splits: - ``training_fraction_split``, and ``test_fraction_split`` may optionally - be provided, they must sum to up to 1. If none of the fractions are set, - by default roughly 80% of data will be used for training, and 20% for test. + """Runs the AutoML Video training job and returns a model. + + If training on a Vertex AI dataset, you can use one of the following split configurations: + Data fraction splits: + ``training_fraction_split``, and ``test_fraction_split`` may optionally + be provided, they must sum to up to 1. If none of the fractions are set, + by default roughly 80% of data will be used for training, and 20% for test. + + Data filter splits: + Assigns input data to training, validation, and test sets + based on the given filters, data pieces not matched by any + filter are ignored. Currently only supported for Datasets + containing DataItems. + If any of the filters in this message are to match nothing, then + they can be set as '-' (the minus sign). + If using filter splits, all of ``training_filter_split``, ``validation_filter_split`` and + ``test_filter_split`` must be provided. + Supported only for unstructured Datasets. Args: dataset (datasets.VideoDataset): @@ -4221,28 +6419,59 @@ def run( [google.cloud.aiplatform.v1beta1.TrainingPipeline.training_task_definition]. For tabular Datasets, all their data is exported to training, to pick and choose from. - training_fraction_split: float = 0.8 - Required. The fraction of the input data that is to be - used to train the Model. This is ignored if Dataset is not provided. - test_fraction_split: float = 0.2 - Required. The fraction of the input data that is to be - used to evaluate the Model. This is ignored if Dataset is not provided. + training_fraction_split (float): + Optional. The fraction of the input data that is to be used to train + the Model. This is ignored if Dataset is not provided. + test_fraction_split (float): + Optional. The fraction of the input data that is to be used to evaluate + the Model. This is ignored if Dataset is not provided. + training_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to train the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. + test_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to test the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. model_display_name (str): Optional. The display name of the managed Vertex AI Model. The name can be up to 128 characters long and can be consist of any UTF-8 characters. If not provided upon creation, the job's display_name is used. + model_labels (Dict[str, str]): + Optional. The labels with user-defined metadata to + organize your Models. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + and examples of labels. sync: bool = True Whether to execute this method synchronously. If False, this method will be executed in concurrent Future and any downstream object will be immediately returned and synced when the Future has completed. + create_request_timeout (float): + Optional. The timeout for the create request in seconds. Returns: model: The trained Vertex AI Model resource or None if training did not - produce an Vertex AI Model. + produce a Vertex AI Model. Raises: RuntimeError: If Training job has already been run or is waiting to run. """ + if model_display_name: + utils.validate_display_name(model_display_name) + if model_labels: + utils.validate_labels(model_labels) + if self._is_waiting_to_run(): raise RuntimeError("AutoML Video Training is already scheduled to run.") @@ -4253,25 +6482,45 @@ def run( dataset=dataset, training_fraction_split=training_fraction_split, test_fraction_split=test_fraction_split, + training_filter_split=training_filter_split, + test_filter_split=test_filter_split, model_display_name=model_display_name, + model_labels=model_labels, sync=sync, + create_request_timeout=create_request_timeout, ) @base.optional_sync() def _run( self, dataset: datasets.VideoDataset, - training_fraction_split: float = 0.8, - test_fraction_split: float = 0.2, + training_fraction_split: Optional[float] = None, + test_fraction_split: Optional[float] = None, + training_filter_split: Optional[str] = None, + test_filter_split: Optional[str] = None, model_display_name: Optional[str] = None, + model_labels: Optional[Dict[str, str]] = None, sync: bool = True, + create_request_timeout: Optional[float] = None, ) -> models.Model: """Runs the training job and returns a model. - Data fraction splits: - Any of ``training_fraction_split``, and ``test_fraction_split`` may optionally - be provided, they must sum to up to 1. If none of the fractions are set, - by default roughly 80% of data will be used for training, and 20% for test. + If training on a Vertex AI dataset, you can use one of the following split configurations: + Data fraction splits: + Any of ``training_fraction_split``, and ``test_fraction_split`` may optionally + be provided, they must sum to up to 1. If none of the fractions are set, + by default roughly 80% of data will be used for training, and 20% for test. + + Data filter splits: + Assigns input data to training, validation, and test sets + based on the given filters, data pieces not matched by any + filter are ignored. Currently only supported for Datasets + containing DataItems. + If any of the filters in this message are to match nothing, then + they can be set as '-' (the minus sign). + If using filter splits, all of ``training_filter_split``, ``validation_filter_split`` and + ``test_filter_split`` must be provided. + Supported only for unstructured Datasets. Args: dataset (datasets.VideoDataset): @@ -4283,25 +6532,51 @@ def _run( For tabular Datasets, all their data is exported to training, to pick and choose from. training_fraction_split (float): - Required. The fraction of the input data that is to be - used to train the Model. This is ignored if Dataset is not provided. + Optional. The fraction of the input data that is to be used to train + the Model. This is ignored if Dataset is not provided. test_fraction_split (float): - Required. The fraction of the input data that is to be - used to evaluate the Model. This is ignored if Dataset is not provided. + Optional. The fraction of the input data that is to be used to evaluate + the Model. This is ignored if Dataset is not provided. + training_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to train the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. + test_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to test the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. model_display_name (str): Optional. The display name of the managed Vertex AI Model. The name can be up to 128 characters long and can be consist of any UTF-8 characters. If a `base_model` was provided, the display_name in the base_model will be overritten with this value. If not provided upon creation, the job's display_name is used. + model_labels (Dict[str, str]): + Optional. The labels with user-defined metadata to + organize your Models. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + and examples of labels. sync (bool): Whether to execute this method synchronously. If False, this method will be executed in concurrent Future and any downstream object will be immediately returned and synced when the Future has completed. + create_request_timeout (float): + Optional. The timeout for the create request in seconds. Returns: model: The trained Vertex AI Model resource or None if training did not - produce an Vertex AI Model. + produce a Vertex AI Model. """ # Retrieve the objective-specific training task schema based on prediction_type @@ -4316,15 +6591,26 @@ def _run( # gca Model to be trained model_tbt = gca_model.Model(encryption_spec=self._model_encryption_spec) model_tbt.display_name = model_display_name or self._display_name + model_tbt.labels = model_labels or self._labels + + # AutoMLVideo does not support validation, so pass in '-' if any other filter split is provided. + validation_filter_split = ( + "-" + if all([training_filter_split is not None, test_filter_split is not None]) + else None + ) return self._run_job( training_task_definition=training_task_definition, training_task_inputs=training_task_inputs_dict, dataset=dataset, training_fraction_split=training_fraction_split, - validation_fraction_split=0.0, test_fraction_split=test_fraction_split, + training_filter_split=training_filter_split, + validation_filter_split=validation_filter_split, + test_filter_split=test_filter_split, model=model_tbt, + create_request_timeout=create_request_timeout, ) @property @@ -4345,6 +6631,7 @@ class AutoMLTextTrainingJob(_TrainingJob): def __init__( self, + # TODO(b/223262536): Make display_name parameter fully optional in next major release display_name: str, prediction_type: str, multi_label: bool = False, @@ -4352,6 +6639,7 @@ def __init__( project: Optional[str] = None, location: Optional[str] = None, credentials: Optional[auth_credentials.Credentials] = None, + labels: Optional[Dict[str, str]] = None, training_encryption_spec_key_name: Optional[str] = None, model_encryption_spec_key_name: Optional[str] = None, ): @@ -4395,6 +6683,16 @@ def __init__( credentials (auth_credentials.Credentials): Optional. Custom credentials to use to run call training service. Overrides credentials set in aiplatform.init. + labels (Dict[str, str]): + Optional. The labels with user-defined metadata to + organize TrainingPipelines. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + and examples of labels. training_encryption_spec_key_name (Optional[str]): Optional. The Cloud KMS resource identifier of the customer managed encryption key used to protect the training pipeline. Has the @@ -4421,11 +6719,14 @@ def __init__( Overrides encryption_spec_key_name set in aiplatform.init. """ + if not display_name: + display_name = self.__class__._generate_display_name() super().__init__( display_name=display_name, project=project, location=location, credentials=credentials, + labels=labels, training_encryption_spec_key_name=training_encryption_spec_key_name, model_encryption_spec_key_name=model_encryption_spec_key_name, ) @@ -4438,8 +6739,10 @@ def __init__( schema.training_job.definition.automl_text_classification ) - training_task_inputs_dict = training_job_inputs.AutoMlTextClassificationInputs( - multi_label=multi_label + training_task_inputs_dict = ( + training_job_inputs.AutoMlTextClassificationInputs( + multi_label=multi_label + ) ) elif prediction_type == "extraction": training_task_definition = ( @@ -4466,20 +6769,37 @@ def __init__( def run( self, dataset: datasets.TextDataset, - training_fraction_split: float = 0.8, - validation_fraction_split: float = 0.1, - test_fraction_split: float = 0.1, + training_fraction_split: Optional[float] = None, + validation_fraction_split: Optional[float] = None, + test_fraction_split: Optional[float] = None, + training_filter_split: Optional[str] = None, + validation_filter_split: Optional[str] = None, + test_filter_split: Optional[str] = None, model_display_name: Optional[str] = None, + model_labels: Optional[Dict[str, str]] = None, sync: bool = True, + create_request_timeout: Optional[float] = None, ) -> models.Model: """Runs the training job and returns a model. - Data fraction splits: - Any of ``training_fraction_split``, ``validation_fraction_split`` and - ``test_fraction_split`` may optionally be provided, they must sum to up to 1. If - the provided ones sum to less than 1, the remainder is assigned to sets as - decided by Vertex AI. If none of the fractions are set, by default roughly 80% - of data will be used for training, 10% for validation, and 10% for test. + If training on a Vertex AI dataset, you can use one of the following split configurations: + Data fraction splits: + Any of ``training_fraction_split``, ``validation_fraction_split`` and + ``test_fraction_split`` may optionally be provided, they must sum to up to 1. If + the provided ones sum to less than 1, the remainder is assigned to sets as + decided by Vertex AI. If none of the fractions are set, by default roughly 80% + of data will be used for training, 10% for validation, and 10% for test. + + Data filter splits: + Assigns input data to training, validation, and test sets + based on the given filters, data pieces not matched by any + filter are ignored. Currently only supported for Datasets + containing DataItems. + If any of the filters in this message are to match nothing, then + they can be set as '-' (the minus sign). + If using filter splits, all of ``training_filter_split``, ``validation_filter_split`` and + ``test_filter_split`` must be provided. + Supported only for unstructured Datasets. Args: dataset (datasets.TextDataset): @@ -4488,25 +6808,58 @@ def run( and what is compatible should be described in the used TrainingPipeline's [training_task_definition] [google.cloud.aiplatform.v1beta1.TrainingPipeline.training_task_definition]. - training_fraction_split: float = 0.8 - Required. The fraction of the input data that is to be - used to train the Model. This is ignored if Dataset is not provided. - validation_fraction_split: float = 0.1 - Required. The fraction of the input data that is to be - used to validate the Model. This is ignored if Dataset is not provided. - test_fraction_split: float = 0.1 - Required. The fraction of the input data that is to be - used to evaluate the Model. This is ignored if Dataset is not provided. + training_fraction_split (float): + Optional. The fraction of the input data that is to be used to train + the Model. This is ignored if Dataset is not provided. + validation_fraction_split (float): + Optional. The fraction of the input data that is to be used to validate + the Model. This is ignored if Dataset is not provided. + test_fraction_split (float): + Optional. The fraction of the input data that is to be used to evaluate + the Model. This is ignored if Dataset is not provided. + training_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to train the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. + validation_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to validate the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. + test_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to test the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. model_display_name (str): Optional. The display name of the managed Vertex AI Model. The name can be up to 128 characters long and can consist of any UTF-8 characters. If not provided upon creation, the job's display_name is used. + model_labels (Dict[str, str]): + Optional. The labels with user-defined metadata to + organize your Models. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + and examples of labels.. sync (bool): Whether to execute this method synchronously. If False, this method will be executed in concurrent Future and any downstream object will be immediately returned and synced when the Future has completed. + create_request_timeout (float): + Optional. The timeout for the create request in seconds Returns: model: The trained Vertex AI Model resource. @@ -4514,6 +6867,11 @@ def run( RuntimeError: If Training job has already been run or is waiting to run. """ + if model_display_name: + utils.validate_display_name(model_display_name) + if model_labels: + utils.validate_labels(model_labels) + if self._is_waiting_to_run(): raise RuntimeError("AutoML Text Training is already scheduled to run.") @@ -4525,28 +6883,50 @@ def run( training_fraction_split=training_fraction_split, validation_fraction_split=validation_fraction_split, test_fraction_split=test_fraction_split, + training_filter_split=training_filter_split, + validation_filter_split=validation_filter_split, + test_filter_split=test_filter_split, model_display_name=model_display_name, + model_labels=model_labels, sync=sync, + create_request_timeout=create_request_timeout, ) @base.optional_sync() def _run( self, dataset: datasets.TextDataset, - training_fraction_split: float = 0.8, - validation_fraction_split: float = 0.1, - test_fraction_split: float = 0.1, + training_fraction_split: Optional[float] = None, + validation_fraction_split: Optional[float] = None, + test_fraction_split: Optional[float] = None, + training_filter_split: Optional[str] = None, + validation_filter_split: Optional[str] = None, + test_filter_split: Optional[str] = None, model_display_name: Optional[str] = None, + model_labels: Optional[Dict[str, str]] = None, sync: bool = True, + create_request_timeout: Optional[float] = None, ) -> models.Model: """Runs the training job and returns a model. - Data fraction splits: - Any of ``training_fraction_split``, ``validation_fraction_split`` and - ``test_fraction_split`` may optionally be provided, they must sum to up to 1. If - the provided ones sum to less than 1, the remainder is assigned to sets as - decided by Vertex AI. If none of the fractions are set, by default roughly 80% - of data will be used for training, 10% for validation, and 10% for test. + If training on a Vertex AI dataset, you can use one of the following split configurations: + Data fraction splits: + Any of ``training_fraction_split``, ``validation_fraction_split`` and + ``test_fraction_split`` may optionally be provided, they must sum to up to 1. If + the provided ones sum to less than 1, the remainder is assigned to sets as + decided by Vertex AI. If none of the fractions are set, by default roughly 80% + of data will be used for training, 10% for validation, and 10% for test. + + Data filter splits: + Assigns input data to training, validation, and test sets + based on the given filters, data pieces not matched by any + filter are ignored. Currently only supported for Datasets + containing DataItems. + If any of the filters in this message are to match nothing, then + they can be set as '-' (the minus sign). + If using filter splits, all of ``training_filter_split``, ``validation_filter_split`` and + ``test_filter_split`` must be provided. + Supported only for unstructured Datasets. Args: dataset (datasets.TextDataset): @@ -4558,35 +6938,66 @@ def _run( For Text Datasets, all their data is exported to training, to pick and choose from. training_fraction_split (float): - Required. The fraction of the input data that is to be - used to train the Model. This is ignored if Dataset is not provided. + Optional. The fraction of the input data that is to be used to train + the Model. This is ignored if Dataset is not provided. validation_fraction_split (float): - Required. The fraction of the input data that is to be - used to validate the Model. This is ignored if Dataset is not provided. + Optional. The fraction of the input data that is to be used to validate + the Model. This is ignored if Dataset is not provided. test_fraction_split (float): - Required. The fraction of the input data that is to be - used to evaluate the Model. This is ignored if Dataset is not provided. + Optional. The fraction of the input data that is to be used to evaluate + the Model. This is ignored if Dataset is not provided. + training_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to train the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. + validation_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to validate the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. + test_filter_split (str): + Optional. A filter on DataItems of the Dataset. DataItems that match + this filter are used to test the Model. A filter with same syntax + as the one used in DatasetService.ListDataItems may be used. If a + single DataItem is matched by more than one of the FilterSplit filters, + then it is assigned to the first set that applies to it in the training, + validation, test order. This is ignored if Dataset is not provided. model_display_name (str): Optional. If the script produces a managed Vertex AI Model. The display name of the Model. The name can be up to 128 characters long and can be consist of any UTF-8 characters. If not provided upon creation, the job's display_name is used. + model_labels (Dict[str, str]): + Optional. The labels with user-defined metadata to + organize your Models. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + and examples of labels. sync (bool): Whether to execute this method synchronously. If False, this method will be executed in concurrent Future and any downstream object will be immediately returned and synced when the Future has completed. + create_request_timeout (float): + Optional. The timeout for the create request in seconds. Returns: model: The trained Vertex AI Model resource or None if training did not - produce an Vertex AI Model. + produce a Vertex AI Model. """ - if model_display_name is None: - model_display_name = self._display_name - model = gca_model.Model( - display_name=model_display_name, + display_name=model_display_name or self._display_name, + labels=model_labels or self._labels, encryption_spec=self._model_encryption_spec, ) @@ -4597,8 +7008,11 @@ def _run( training_fraction_split=training_fraction_split, validation_fraction_split=validation_fraction_split, test_fraction_split=test_fraction_split, - predefined_split_column_name=None, + training_filter_split=training_filter_split, + validation_filter_split=validation_filter_split, + test_filter_split=test_filter_split, model=model, + create_request_timeout=create_request_timeout, ) @property diff --git a/google/cloud/aiplatform/training_utils/__init__.py b/google/cloud/aiplatform/training_utils/__init__.py new file mode 100644 index 0000000000..0e973c9a40 --- /dev/null +++ b/google/cloud/aiplatform/training_utils/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- + +# 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 +# +# 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. diff --git a/google/cloud/aiplatform/training_utils/cloud_profiler/README.rst b/google/cloud/aiplatform/training_utils/cloud_profiler/README.rst new file mode 100644 index 0000000000..6c6cfc1af9 --- /dev/null +++ b/google/cloud/aiplatform/training_utils/cloud_profiler/README.rst @@ -0,0 +1,20 @@ +Cloud Profiler +================================= + +Cloud Profiler allows you to profile your remote Vertex AI Training jobs on demand and visualize the results in Vertex Tensorboard. + +Quick Start +------------ + +To start using the profiler with TensorFlow, update your training script to include the following: + +.. code-block:: Python + + from google.cloud.aiplatform.training_utils import cloud_profiler + ... + cloud_profiler.init() + + +Next, run the job with with a Vertex TensorBoard instance. For full details on how to do this, visit https://cloud.google.com/vertex-ai/docs/experiments/tensorboard-overview + +Finally, visit your TensorBoard in your Google Cloud Console, navigate to the "Profile" tab, and click the `Capture Profile` button. This will allow users to capture profiling statistics for the running jobs. diff --git a/google/cloud/aiplatform/training_utils/cloud_profiler/__init__.py b/google/cloud/aiplatform/training_utils/cloud_profiler/__init__.py new file mode 100644 index 0000000000..1b0c5eb925 --- /dev/null +++ b/google/cloud/aiplatform/training_utils/cloud_profiler/__init__.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- + +# 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.aiplatform.training_utils.cloud_profiler import initializer + +""" +Initialize the cloud profiler for tensorflow. + +Usage: +from google.cloud.aiplatform.training_utils import cloud_profiler + +cloud_profiler.init(profiler='tensorflow') +""" + +init = initializer.initialize diff --git a/google/cloud/aiplatform/training_utils/cloud_profiler/cloud_profiler_utils.py b/google/cloud/aiplatform/training_utils/cloud_profiler/cloud_profiler_utils.py new file mode 100644 index 0000000000..f7f6e8d8f6 --- /dev/null +++ b/google/cloud/aiplatform/training_utils/cloud_profiler/cloud_profiler_utils.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- + +# 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_error_msg = ( + "Could not load the cloud profiler. To use the profiler, " + "install the SDK using 'pip install google-cloud-aiplatform[cloud-profiler]'" +) diff --git a/google/cloud/aiplatform/training_utils/cloud_profiler/initializer.py b/google/cloud/aiplatform/training_utils/cloud_profiler/initializer.py new file mode 100644 index 0000000000..7abc815078 --- /dev/null +++ b/google/cloud/aiplatform/training_utils/cloud_profiler/initializer.py @@ -0,0 +1,130 @@ +# -*- coding: utf-8 -*- + +# 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 logging +import threading +from typing import Optional, Type + +from google.cloud.aiplatform.training_utils.cloud_profiler import cloud_profiler_utils + +try: + from werkzeug import serving +except ImportError as err: + raise ImportError(cloud_profiler_utils.import_error_msg) from err + + +from google.cloud.aiplatform.training_utils import environment_variables +from google.cloud.aiplatform.training_utils.cloud_profiler import webserver +from google.cloud.aiplatform.training_utils.cloud_profiler.plugins import base_plugin +from google.cloud.aiplatform.training_utils.cloud_profiler.plugins.tensorflow import ( + tf_profiler, +) + + +# Mapping of available plugins to use +_AVAILABLE_PLUGINS = {"tensorflow": tf_profiler.TFProfiler} + + +class MissingEnvironmentVariableException(Exception): + pass + + +def _build_plugin( + plugin: Type[base_plugin.BasePlugin], +) -> Optional[base_plugin.BasePlugin]: + """Builds the plugin given the object. + + Args: + plugin (Type[base_plugin]): + Required. An uninitialized plugin class. + + Returns: + An initialized plugin, or None if plugin cannot be + initialized. + """ + if not plugin.can_initialize(): + logging.warning("Cannot initialize the plugin") + return + + plugin.setup() + + if not plugin.post_setup_check(): + return + + return plugin() + + +def _run_app_thread(server: webserver.WebServer, port: int): + """Run the webserver in a separate thread. + + Args: + server (webserver.WebServer): + Required. A webserver to accept requests. + port (int): + Required. The port to run the webserver on. + """ + daemon = threading.Thread( + name="profile_server", + target=serving.run_simple, + args=( + "0.0.0.0", + port, + server, + ), + ) + daemon.setDaemon(True) + daemon.start() + + +def initialize(plugin: str = "tensorflow"): + """Initializes the profiling SDK. + + Args: + plugin (str): + Required. Name of the plugin to initialize. + Current options are ["tensorflow"] + + Raises: + ValueError: + The plugin does not exist. + MissingEnvironmentVariableException: + An environment variable that is needed is not set. + """ + plugin_obj = _AVAILABLE_PLUGINS.get(plugin) + + if not plugin_obj: + raise ValueError( + "Plugin {} not available, must choose from {}".format( + plugin, _AVAILABLE_PLUGINS.keys() + ) + ) + + prof_plugin = _build_plugin(plugin_obj) + + if prof_plugin is None: + return + + server = webserver.WebServer([prof_plugin]) + + if not environment_variables.http_handler_port: + raise MissingEnvironmentVariableException( + "'AIP_HTTP_HANDLER_PORT' must be set." + ) + + port = int(environment_variables.http_handler_port) + + _run_app_thread(server, port) diff --git a/google/cloud/aiplatform/training_utils/cloud_profiler/plugins/base_plugin.py b/google/cloud/aiplatform/training_utils/cloud_profiler/plugins/base_plugin.py new file mode 100644 index 0000000000..67b6b40ae9 --- /dev/null +++ b/google/cloud/aiplatform/training_utils/cloud_profiler/plugins/base_plugin.py @@ -0,0 +1,71 @@ +# -*- coding: utf-8 -*- + +# 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 abc +from typing import Callable, Dict +from werkzeug import Response + + +class BasePlugin(abc.ABC): + """Base plugin for cloud training tools endpoints. + + The plugins support registering http handlers to be used for + AI Platform training jobs. + """ + + @staticmethod + @abc.abstractmethod + def setup() -> None: + """Run any setup code for the plugin before webserver is launched.""" + raise NotImplementedError + + @staticmethod + @abc.abstractmethod + def can_initialize() -> bool: + """Check whether a plugin is able to be initialized. + + Used for checking if correct dependencies are installed, system requirements, etc. + + Returns: + Bool indicating whether the plugin can be initialized. + """ + raise NotImplementedError + + @staticmethod + @abc.abstractmethod + def post_setup_check() -> bool: + """Check if after initialization, we need to use the plugin. + + Example: Web server only needs to run for main node for training, others + just need to have 'setup()' run to start the rpc server. + + Returns: + A boolean indicating whether post setup checks pass. + """ + raise NotImplementedError + + @abc.abstractmethod + def get_routes(self) -> Dict[str, Callable[..., Response]]: + """Get the mapping from path to handler. + + This is the method in which plugins can assign different routes to + different handlers. + + Returns: + A mapping from a route to a handler. + """ + raise NotImplementedError diff --git a/google/cloud/aiplatform/training_utils/cloud_profiler/plugins/tensorflow/tensorboard_api.py b/google/cloud/aiplatform/training_utils/cloud_profiler/plugins/tensorflow/tensorboard_api.py new file mode 100644 index 0000000000..c74d4cfa55 --- /dev/null +++ b/google/cloud/aiplatform/training_utils/cloud_profiler/plugins/tensorflow/tensorboard_api.py @@ -0,0 +1,194 @@ +# -*- coding: utf-8 -*- + +# 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. +# + +"""Helpers for creating a profile request sender for tf profiler plugin.""" + +import os +import re +from typing import Tuple + +from tensorboard.uploader import upload_tracker +from tensorboard.uploader import util +from tensorboard.uploader.proto import server_info_pb2 +from tensorboard.util import tb_logging + +from google.api_core import exceptions +from google.cloud import aiplatform +from google.cloud import storage +from google.cloud.aiplatform.utils import TensorboardClientWithOverride +from google.cloud.aiplatform.tensorboard import uploader_utils +from google.cloud.aiplatform.compat.types import tensorboard_experiment +from google.cloud.aiplatform.tensorboard.plugins.tf_profiler import profile_uploader +from google.cloud.aiplatform import training_utils + +logger = tb_logging.get_logger() + + +def _get_api_client() -> TensorboardClientWithOverride: + """Creates an Tensorboard API client.""" + m = re.match( + "projects/.*/locations/(.*)/tensorboards/.*", + training_utils.environment_variables.tensorboard_resource_name, + ) + region = m[1] + + api_client = aiplatform.initializer.global_config.create_client( + client_class=TensorboardClientWithOverride, + location_override=region, + api_base_path_override=training_utils.environment_variables.tensorboard_api_uri, + ) + + return api_client + + +def _get_project_id() -> str: + """Gets the project id from the tensorboard resource name. + + Returns: + Project ID for current project. + + Raises: + ValueError: Cannot parse the tensorboard resource name. + """ + m = re.match( + "projects/(.*)/locations/.*/tensorboards/.*", + training_utils.environment_variables.tensorboard_resource_name, + ) + if not m: + raise ValueError( + "Incorrect format for tensorboard resource name: %s", + training_utils.environment_variables.tensorboard_resource_name, + ) + return m[1] + + +def _make_upload_limits() -> server_info_pb2.UploadLimits: + """Creates the upload limits for tensorboard. + + Returns: + An UploadLimits object. + """ + upload_limits = server_info_pb2.UploadLimits() + upload_limits.min_blob_request_interval = 10 + upload_limits.max_blob_request_size = 4 * (2**20) - 256 * (2**10) + upload_limits.max_blob_size = 10 * (2**30) # 10GiB + + return upload_limits + + +def _get_blob_items( + api_client: TensorboardClientWithOverride, +) -> Tuple[storage.bucket.Bucket, str]: + """Gets the blob storage items for the tensorboard resource. + + Args: + api_client (): + Required. Client go get information about the tensorboard instance. + + Returns: + A tuple of storage buckets and the blob storage folder name. + """ + project_id = _get_project_id() + tensorboard = api_client.get_tensorboard( + name=training_utils.environment_variables.tensorboard_resource_name + ) + + path_prefix = tensorboard.blob_storage_path_prefix + "/" + first_slash_index = path_prefix.find("/") + bucket_name = path_prefix[:first_slash_index] + blob_storage_bucket = storage.Client(project=project_id).bucket(bucket_name) + blob_storage_folder = path_prefix[first_slash_index + 1 :] + + return blob_storage_bucket, blob_storage_folder + + +def _get_or_create_experiment( + api: TensorboardClientWithOverride, experiment_name: str +) -> str: + """Creates a tensorboard experiment. + + Args: + api (TensorboardClientWithOverride): + Required. An api for interfacing with tensorboard resources. + experiment_name (str): + Required. The name of the experiment to get or create. + + Returns: + The name of the experiment. + """ + tb_experiment = tensorboard_experiment.TensorboardExperiment() + + try: + experiment = api.create_tensorboard_experiment( + parent=training_utils.environment_variables.tensorboard_resource_name, + tensorboard_experiment=tb_experiment, + tensorboard_experiment_id=experiment_name, + ) + except exceptions.AlreadyExists: + logger.info("Creating experiment failed. Retrieving experiment.") + experiment_name = os.path.join( + training_utils.environment_variables.tensorboard_resource_name, + "experiments", + experiment_name, + ) + experiment = api.get_tensorboard_experiment(name=experiment_name) + + return experiment.name + + +def create_profile_request_sender() -> profile_uploader.ProfileRequestSender: + """Creates the `ProfileRequestSender` for the profile plugin. + + A profile request sender is created for the plugin so that after profiling runs + have finished, data can be uploaded to the tensorboard backend. + + Returns: + A ProfileRequestSender object. + """ + api_client = _get_api_client() + + experiment_name = _get_or_create_experiment( + api_client, training_utils.environment_variables.cloud_ml_job_id + ) + + upload_limits = _make_upload_limits() + + blob_rpc_rate_limiter = util.RateLimiter( + upload_limits.min_blob_request_interval / 100 + ) + + blob_storage_bucket, blob_storage_folder = _get_blob_items( + api_client, + ) + + source_bucket = uploader_utils.get_source_bucket( + training_utils.environment_variables.tensorboard_log_dir + ) + + profile_request_sender = profile_uploader.ProfileRequestSender( + experiment_name, + api_client, + upload_limits=upload_limits, + blob_rpc_rate_limiter=blob_rpc_rate_limiter, + blob_storage_bucket=blob_storage_bucket, + blob_storage_folder=blob_storage_folder, + source_bucket=source_bucket, + tracker=upload_tracker.UploadTracker(verbosity=1), + logdir=training_utils.environment_variables.tensorboard_log_dir, + ) + + return profile_request_sender diff --git a/google/cloud/aiplatform/training_utils/cloud_profiler/plugins/tensorflow/tf_profiler.py b/google/cloud/aiplatform/training_utils/cloud_profiler/plugins/tensorflow/tf_profiler.py new file mode 100644 index 0000000000..81b43145b3 --- /dev/null +++ b/google/cloud/aiplatform/training_utils/cloud_profiler/plugins/tensorflow/tf_profiler.py @@ -0,0 +1,352 @@ +# -*- 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. +# + +"""A plugin to handle remote tensoflow profiler sessions for Vertex AI.""" + +from google.cloud.aiplatform.training_utils.cloud_profiler import cloud_profiler_utils + +try: + import tensorflow as tf + from tensorboard_plugin_profile.profile_plugin import ProfilePlugin +except ImportError as err: + raise ImportError(cloud_profiler_utils.import_error_msg) from err + +import argparse +from collections import namedtuple +import importlib.util +import json +import logging +from typing import Callable, Dict, Optional +from urllib import parse + +import tensorboard.plugins.base_plugin as tensorboard_base_plugin +from werkzeug import Response + +from google.cloud.aiplatform.tensorboard.plugins.tf_profiler import profile_uploader +from google.cloud.aiplatform.training_utils import environment_variables +from google.cloud.aiplatform.training_utils.cloud_profiler import wsgi_types +from google.cloud.aiplatform.training_utils.cloud_profiler.plugins import base_plugin +from google.cloud.aiplatform.training_utils.cloud_profiler.plugins.tensorflow import ( + tensorboard_api, +) + + +# TF verison information. +Version = namedtuple("Version", ["major", "minor", "patch"]) + +logger = logging.Logger("tf-profiler") + +_BASE_TB_ENV_WARNING = ( + "To set this environment variable, run your training with the 'tensorboard' " + "option. For more information on how to run with training with tensorboard, visit " + "https://cloud.google.com/vertex-ai/docs/experiments/tensorboard-training" +) + + +def _get_tf_versioning() -> Optional[Version]: + """Convert version string to a Version namedtuple for ease of parsing. + + Returns: + A version object if finding the version was successful, None otherwise. + """ + version = tf.__version__ + + versioning = version.split(".") + if len(versioning) != 3: + return + + return Version(int(versioning[0]), int(versioning[1]), int(versioning[2])) + + +def _is_compatible_version(version: Version) -> bool: + """Check if version is compatible with tf profiling. + + Profiling plugin is available to be used for version >= 2.4.0. + While the profiler is available in 2.2.0 >=, some additional dependencies + that are included in 2.4.0 >= are also needed for the tensorboard-plugin-profile. + + Profiler: + https://www.tensorflow.org/guide/profiler + Required commit for tensorboard-plugin-profile: + https://github.com/tensorflow/tensorflow/commit/8b9c207242db515daef033e74d69ea5d8e023dc6 + + Args: + version (Version): + Required. `Verison` of tensorflow. + + Returns: + Bool indicating wheter version is compatible with profiler. + """ + return version.major >= 2 and version.minor >= 4 + + +def _check_tf() -> bool: + """Check whether all the tensorflow prereqs are met. + + Returns: + True if all requirements met, False otherwise. + """ + # Check tf is installed + if importlib.util.find_spec("tensorflow") is None: + logger.warning("Tensorflow not installed, cannot initialize profiling plugin") + return False + + # Check tensorflow version + version = _get_tf_versioning() + if version is None: + logger.warning( + "Could not find major, minor, and patch versions of tensorflow. Version found: %s", + version, + ) + return False + + # Check compatibility, introduced in tensorflow >= 2.2.0 + if not _is_compatible_version(version): + logger.warning( + "Version %s is incompatible with tf profiler." + "To use the profiler, choose a version >= 2.2.0", + "%s.%s.%s" % (version.major, version.minor, version.patch), + ) + return False + + # Check for the tf profiler plugin + if importlib.util.find_spec("tensorboard_plugin_profile") is None: + logger.warning( + "Could not import tensorboard_plugin_profile, will not run tf profiling service" + ) + return False + + return True + + +def _create_profiling_context() -> tensorboard_base_plugin.TBContext: + """Creates the base context needed for TB Profiler. + + Returns: + An initialized `TBContext`. + """ + + context_flags = argparse.Namespace(master_tpu_unsecure_channel=None) + + context = tensorboard_base_plugin.TBContext( + logdir=environment_variables.tensorboard_log_dir, + multiplexer=None, + flags=context_flags, + ) + + return context + + +def _host_to_grpc(hostname: str) -> str: + """Format a hostname to a grpc address. + + Args: + hostname (str): + Required. Address in form: `{hostname}:{port}` + + Returns: + Address in form of: 'grpc://{hostname}:{port}' + """ + return ( + "grpc://" + + "".join(hostname.split(":")[:-1]) + + ":" + + environment_variables.tf_profiler_port + ) + + +def _get_hostnames() -> Optional[str]: + """Get the hostnames for all servers running. + + Returns: + A host formatted by `_host_to_grpc` if obtaining the cluster spec + is successful, None otherwise. + """ + cluster_spec = environment_variables.cluster_spec + if cluster_spec is None: + return + + cluster = cluster_spec.get("cluster", "") + if not cluster: + return + + hostnames = [] + for value in cluster.values(): + hostnames.extend(value) + + return ",".join([_host_to_grpc(x) for x in hostnames]) + + +def _update_environ(environ: wsgi_types.Environment) -> bool: + """Add parameters to the query that are retrieved from training side. + + Args: + environ (wsgi_types.Environment): + Required. The WSGI Environment. + + Returns: + Whether the environment was successfully updated. + """ + hosts = _get_hostnames() + + if hosts is None: + return False + + query_dict = {} + query_dict["service_addr"] = hosts + + # Update service address and worker list + # Use parse_qsl and then convert list to dictionary so we can update + # attributes + prev_query_string = dict(parse.parse_qsl(environ["QUERY_STRING"])) + prev_query_string.update(query_dict) + + environ["QUERY_STRING"] = parse.urlencode(prev_query_string) + + return True + + +def warn_tensorboard_env_var(var_name: str): + """Warns if a tensorboard related environment variable is missing. + + Args: + var_name (str): + Required. The name of the missing environment variable. + """ + logging.warning( + f"Environment variable `{var_name}` must be set. " + _BASE_TB_ENV_WARNING + ) + + +def _check_env_vars() -> bool: + """Determine whether the correct environment variables are set. + + Returns: + bool indicating all necessary variables are set. + """ + # The below are tensorboard specific environment variables. + if environment_variables.tf_profiler_port is None: + warn_tensorboard_env_var("AIP_TF_PROFILER_PORT") + return False + + if environment_variables.tensorboard_log_dir is None: + warn_tensorboard_env_var("AIP_TENSORBOARD_LOG_DIR") + return False + + if environment_variables.tensorboard_api_uri is None: + warn_tensorboard_env_var("AIP_TENSORBOARD_API_URI") + return False + + if environment_variables.tensorboard_resource_name is None: + warn_tensorboard_env_var("AIP_TENSORBOARD_RESOURCE_NAME") + return False + + # These environment variables are not tensorboard related, they are + # variables set for any Vertex training run. + cluster_spec = environment_variables.cluster_spec + if cluster_spec is None: + logger.warning("Environment variable `CLUSTER_SPEC` is not set.") + return False + + if environment_variables.cloud_ml_job_id is None: + logger.warning("Environment variable `CLOUD_ML_JOB_ID` is not set") + return False + + return True + + +class TFProfiler(base_plugin.BasePlugin): + """Handler for Tensorflow Profiling.""" + + PLUGIN_NAME = "profile" + + def __init__(self): + """Build a TFProfiler object.""" + context = _create_profiling_context() + self._profile_request_sender: profile_uploader.ProfileRequestSender = ( + tensorboard_api.create_profile_request_sender() + ) + self._profile_plugin: ProfilePlugin = ProfilePlugin(context) + + def get_routes( + self, + ) -> Dict[str, Callable[[Dict[str, str], Callable[..., None]], Response]]: + """List of routes to serve. + + Returns: + A callable that takes an werkzeug env and start response and returns a response. + """ + return {"/capture_profile": self.capture_profile_wrapper} + + # Define routes below + def capture_profile_wrapper( + self, environ: wsgi_types.Environment, start_response: wsgi_types.StartResponse + ) -> Response: + """Take a request from tensorboard.gcp and run the profiling for the available servers. + + Args: + environ (wsgi_types.Environment): + Required. The WSGI environment. + start_response (wsgi_types.StartResponse): + Required. The response callable provided by the WSGI server. + + Returns: + A response iterable. + """ + # The service address (localhost) and worker list are populated locally + if not _update_environ(environ): + err = {"error": "Could not parse the environ: %s"} + return Response( + json.dumps(err), content_type="application/json", status=500 + ) + + response = self._profile_plugin.capture_route(environ, start_response) + + self._profile_request_sender.send_request("") + + return response + + # End routes + + @staticmethod + def setup() -> None: + """Sets up the plugin.""" + tf.profiler.experimental.server.start( + int(environment_variables.tf_profiler_port) + ) + + @staticmethod + def post_setup_check() -> bool: + """Only chief and task 0 should run the webserver.""" + cluster_spec = environment_variables.cluster_spec + task_type = cluster_spec.get("task", {}).get("type", "") + task_index = cluster_spec.get("task", {}).get("index", -1) + + return task_type in {"workerpool0", "chief"} and task_index == 0 + + @staticmethod + def can_initialize() -> bool: + """Check that we can use the TF Profiler plugin. + + This function checks a number of dependencies for the plugin to ensure we have the + right packages installed, the necessary versions, and the correct environment variables set. + + Returns: + True if can initialize, False otherwise. + """ + + return _check_env_vars() and _check_tf() diff --git a/google/cloud/aiplatform/training_utils/cloud_profiler/webserver.py b/google/cloud/aiplatform/training_utils/cloud_profiler/webserver.py new file mode 100644 index 0000000000..3f7706bb34 --- /dev/null +++ b/google/cloud/aiplatform/training_utils/cloud_profiler/webserver.py @@ -0,0 +1,114 @@ +# -*- coding: utf-8 -*- + +# 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. +# + +"""A basic webserver for hosting plugin routes.""" + +import os + +from google.cloud.aiplatform.training_utils.cloud_profiler import wsgi_types +from google.cloud.aiplatform.training_utils.cloud_profiler.plugins import base_plugin +from typing import List +from werkzeug import wrappers, Response + + +class WebServer: + """A basic web server for handling requests.""" + + def __init__(self, plugins: List[base_plugin.BasePlugin]): + """Creates a web server to host plugin routes. + + Args: + plugins (List[base_plugin.BasePlugin]): + Required. A list of `BasePlugin` objects. + + Raises: + ValueError: + When there is an invalid route passed from + one of the plugins. + """ + + self._plugins = plugins + self._routes = {} + + # Routes are in form {plugin_name}/{route} + for plugin in self._plugins: + for route, handler in plugin.get_routes().items(): + if not route.startswith("/"): + raise ValueError( + 'Routes should start with a "/", ' + "invalid route for plugin %s, route %s" + % (plugin.PLUGIN_NAME, route) + ) + + app_route = os.path.join("/", plugin.PLUGIN_NAME) + + app_route += route + self._routes[app_route] = handler + + def dispatch_request( + self, environ: wsgi_types.Environment, start_response: wsgi_types.StartResponse + ) -> Response: + """Handles the routing of requests. + + Args: + environ (wsgi_types.Environment): + Required. The WSGI environment. + start_response (wsgi_types.StartResponse): + Required. The response callable provided by the WSGI server. + + Returns: + A response iterable. + """ + # Check for existince of route + request = wrappers.Request(environ) + + if request.path in self._routes: + return self._routes[request.path](environ, start_response) + + response = wrappers.Response("Not Found", status=404) + return response(environ, start_response) + + def wsgi_app( + self, environ: wsgi_types.Environment, start_response: wsgi_types.StartResponse + ) -> Response: + """Entrypoint for wsgi application. + + Args: + environ (wsgi_types.Environment): + Required. The WSGI environment. + start_response (wsgi_types.StartResponse): + Required. The response callable provided by the WSGI server. + + Returns: + A response iterable. + """ + response = self.dispatch_request(environ, start_response) + return response + + def __call__(self, environ, start_response): + """Entrypoint for wsgi application. + + Args: + environ (wsgi_types.Environment): + Required. The WSGI environment. + start_response (wsgi_types.StartResponse): + Required. The response callable provided by the WSGI server. + + Returns: + A response iterable. + """ + return self.wsgi_app(environ, start_response) diff --git a/google/cloud/aiplatform/training_utils/cloud_profiler/wsgi_types.py b/google/cloud/aiplatform/training_utils/cloud_profiler/wsgi_types.py new file mode 100644 index 0000000000..0348c5b91e --- /dev/null +++ b/google/cloud/aiplatform/training_utils/cloud_profiler/wsgi_types.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- + +# 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. +# + +# Typing description for the WSGI App callables +# For more information on WSGI, see PEP 3333 + +from typing import Any, Dict, Text, Callable + +# Contain CGI environment variables, as defined by the Common Gateway Interface +# specification. +Environment = Dict[Text, Any] + +# Used to begin the HTTP response. +StartResponse = Callable[..., Callable[[bytes], None]] diff --git a/google/cloud/aiplatform/training_utils/environment_variables.py b/google/cloud/aiplatform/training_utils/environment_variables.py new file mode 100644 index 0000000000..0783e78251 --- /dev/null +++ b/google/cloud/aiplatform/training_utils/environment_variables.py @@ -0,0 +1,81 @@ +# -*- coding: utf-8 -*- + +# 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. +# + +# Environment variables used in Vertex AI Training. + +import json +import os + +from typing import Dict, Optional + + +def _json_helper(env_var: str) -> Optional[Dict]: + """Helper to convert a dictionary represented as a string to a dictionary. + + Args: + env_var (str): + Required. The name of the environment variable. + + Returns: + A dictionary if the variable was found, None otherwise. + """ + env = os.environ.get(env_var) + if env is not None: + return json.loads(env) + else: + return None + + +# Cloud Storage URI of a directory intended for training data. +training_data_uri = os.environ.get("AIP_TRAINING_DATA_URI") + +# Cloud Storage URI of a directory intended for validation data. +validation_data_uri = os.environ.get("AIP_VALIDATION_DATA_URI") + +# Cloud Storage URI of a directory intended for test data. +test_data_uri = os.environ.get("AIP_TEST_DATA_URI") + +# Cloud Storage URI of a directory intended for saving model artefacts. +model_dir = os.environ.get("AIP_MODEL_DIR") + +# Cloud Storage URI of a directory intended for saving checkpoints. +checkpoint_dir = os.environ.get("AIP_CHECKPOINT_DIR") + +# Cloud Storage URI of a directory intended for saving TensorBoard logs. +tensorboard_log_dir = os.environ.get("AIP_TENSORBOARD_LOG_DIR") + +# json string as described in https://cloud.google.com/ai-platform-unified/docs/training/distributed-training#cluster-variables +cluster_spec = _json_helper("CLUSTER_SPEC") + +# json string as described in https://cloud.google.com/ai-platform-unified/docs/training/distributed-training#tf-config +tf_config = _json_helper("TF_CONFIG") + +# Profiler port used for capturing profiling samples. +tf_profiler_port = os.environ.get("AIP_TF_PROFILER_PORT") + +# API URI used for the tensorboard uploader. +tensorboard_api_uri = os.environ.get("AIP_TENSORBOARD_API_URI") + +# The name of the tensorboard resource, in the form: +# `projects/{project_id}/locations/{location}/tensorboards/{tensorboard_name}` +tensorboard_resource_name = os.environ.get("AIP_TENSORBOARD_RESOURCE_NAME") + +# The name given to the training job. +cloud_ml_job_id = os.environ.get("CLOUD_ML_JOB_ID") + +# The HTTP Handler port to use to host the profiling webserver. +http_handler_port = os.environ.get("AIP_HTTP_HANDLER_PORT") diff --git a/google/cloud/aiplatform/utils/__init__.py b/google/cloud/aiplatform/utils/__init__.py index 4404defb21..9ec2f27779 100644 --- a/google/cloud/aiplatform/utils/__init__.py +++ b/google/cloud/aiplatform/utils/__init__.py @@ -19,10 +19,11 @@ import abc import datetime import pathlib -from collections import namedtuple import logging import re -from typing import Any, Match, Optional, Type, TypeVar, Tuple +from typing import Any, Callable, Dict, Optional, Type, TypeVar, Tuple + +from google.protobuf import timestamp_pb2 from google.api_core import client_options from google.api_core import gapic_v1 @@ -30,26 +31,36 @@ from google.cloud import storage from google.cloud.aiplatform import compat -from google.cloud.aiplatform import constants +from google.cloud.aiplatform.constants import base as constants from google.cloud.aiplatform import initializer from google.cloud.aiplatform.compat.services import ( dataset_service_client_v1beta1, endpoint_service_client_v1beta1, + featurestore_online_serving_service_client_v1beta1, + featurestore_service_client_v1beta1, + index_service_client_v1beta1, + index_endpoint_service_client_v1beta1, job_service_client_v1beta1, + metadata_service_client_v1beta1, model_service_client_v1beta1, pipeline_service_client_v1beta1, prediction_service_client_v1beta1, - metadata_service_client_v1beta1, tensorboard_service_client_v1beta1, ) from google.cloud.aiplatform.compat.services import ( dataset_service_client_v1, endpoint_service_client_v1, + featurestore_online_serving_service_client_v1, + featurestore_service_client_v1, + index_service_client_v1, + index_endpoint_service_client_v1, job_service_client_v1, + metadata_service_client_v1, model_service_client_v1, pipeline_service_client_v1, prediction_service_client_v1, + tensorboard_service_client_v1, ) from google.cloud.aiplatform.compat.types import ( @@ -61,85 +72,55 @@ # v1beta1 dataset_service_client_v1beta1.DatasetServiceClient, endpoint_service_client_v1beta1.EndpointServiceClient, + featurestore_online_serving_service_client_v1beta1.FeaturestoreOnlineServingServiceClient, + featurestore_service_client_v1beta1.FeaturestoreServiceClient, + index_service_client_v1beta1.IndexServiceClient, + index_endpoint_service_client_v1beta1.IndexEndpointServiceClient, model_service_client_v1beta1.ModelServiceClient, prediction_service_client_v1beta1.PredictionServiceClient, pipeline_service_client_v1beta1.PipelineServiceClient, job_service_client_v1beta1.JobServiceClient, metadata_service_client_v1beta1.MetadataServiceClient, + tensorboard_service_client_v1beta1.TensorboardServiceClient, # v1 dataset_service_client_v1.DatasetServiceClient, endpoint_service_client_v1.EndpointServiceClient, + featurestore_online_serving_service_client_v1.FeaturestoreOnlineServingServiceClient, + featurestore_service_client_v1.FeaturestoreServiceClient, + metadata_service_client_v1.MetadataServiceClient, model_service_client_v1.ModelServiceClient, prediction_service_client_v1.PredictionServiceClient, pipeline_service_client_v1.PipelineServiceClient, job_service_client_v1.JobServiceClient, + tensorboard_service_client_v1.TensorboardServiceClient, ) -RESOURCE_NAME_PATTERN = re.compile( - r"^projects\/(?P[\w-]+)\/locations\/(?P[\w-]+)\/(?P[\w\-\/]+)\/(?P[\w-]+)$" -) -RESOURCE_ID_PATTERN = re.compile(r"^[\w-]+$") - -Fields = namedtuple("Fields", ["project", "location", "resource", "id"],) - -def _match_to_fields(match: Match) -> Optional[Fields]: - """Normalize RegEx groups from resource name pattern Match to class - Fields.""" - if not match: - return None - - return Fields( - project=match["project"], - location=match["location"], - resource=match["resource"], - id=match["id"], - ) - - -def validate_id(resource_id: str) -> bool: - """Validate int64 resource ID number.""" - return bool(RESOURCE_ID_PATTERN.match(resource_id)) +RESOURCE_ID_PATTERN = re.compile(r"^[\w-]+$") -def extract_fields_from_resource_name( - resource_name: str, resource_noun: Optional[str] = None -) -> Optional[Fields]: - """Validates and returns extracted fields from a fully-qualified resource - name. Returns None if name is invalid. +def validate_id(resource_id: str): + """Validate resource ID. Args: - resource_name (str): - Required. A fully-qualified Vertex AI resource name + resource_id (str): Resource id. + Raises: + ValueError: If resource id is not a valid format. - resource_noun (str): - A resource noun to validate the resource name against. - For example, you would pass "datasets" to validate - "projects/123/locations/us-central1/datasets/456". - In the case of deeper naming structures, e.g., - "projects/123/locations/us-central1/metadataStores/123/contexts/456", - you would pass "metadataStores/123/contexts" as the resource_noun. - Returns: - fields (Fields): - A named tuple containing four extracted fields from a resource name: - project, location, resource, and id. These fields can be used for - subsequent method calls in the SDK. """ - fields = _match_to_fields(RESOURCE_NAME_PATTERN.match(resource_name)) - - if not fields: - return None - if resource_noun and fields.resource != resource_noun: - return None - - return fields + if not RESOURCE_ID_PATTERN.match(resource_id): + raise ValueError(f"Resource {resource_id} is not a valid resource id.") def full_resource_name( resource_name: str, resource_noun: str, + parse_resource_name_method: Callable[[str], Dict[str, str]], + format_resource_name_method: Callable[..., str], + parent_resource_name_fields: Optional[Dict[str, str]] = None, project: Optional[str] = None, location: Optional[str] = None, + resource_id_validator: Optional[Callable[[str], None]] = None, ) -> str: """Returns fully qualified resource name. @@ -148,85 +129,92 @@ def full_resource_name( Required. A fully-qualified Vertex AI resource name or resource ID. resource_noun (str): - A resource noun to validate the resource name against. + Required. A resource noun to validate the resource name against. For example, you would pass "datasets" to validate "projects/123/locations/us-central1/datasets/456". - In the case of deeper naming structures, e.g., - "projects/123/locations/us-central1/metadataStores/123/contexts/456", - you would pass "metadataStores/123/contexts" as the resource_noun. + parse_resource_name_method (Callable[[str], Dict[str,str]]): + Required. Method that parses a resource name into its segment parts. + These are generally included with GAPIC clients. + format_resource_name_method (Callable[..., str]): + Required. Method that takes segment parts of resource names and returns + the formated resource name. These are generally included with GAPIC clients. + parent_resource_name_fields (Dict[str, str]): + Optional. Dictionary of segment parts where key is the resource noun and + values are the resource ids. + For example: + { + "metadataStores": "123" + } project (str): - Optional project to retrieve resource_noun from. If not set, project + Optional. project to retrieve resource_noun from. If not set, project set in aiplatform.init will be used. location (str): - Optional location to retrieve resource_noun from. If not set, location + Optional. location to retrieve resource_noun from. If not set, location set in aiplatform.init will be used. + resource_id_validator (Callable[str, None]): + Optional. Function that validates the resource ID. Overrides the default validator, validate_id. + Should take a resource ID as string and raise ValueError if invalid. Returns: resource_name (str): A fully-qualified Vertex AI resource name. - - Raises: - ValueError: - If resource name, resource ID or project ID not provided. """ - validate_resource_noun(resource_noun) # Fully qualified resource name, e.g., "projects/.../locations/.../datasets/12345" or # "projects/.../locations/.../metadataStores/.../contexts/12345" - valid_name = extract_fields_from_resource_name( - resource_name=resource_name, resource_noun=resource_noun - ) + fields = parse_resource_name_method(resource_name) + if fields: + return resource_name + + resource_id_validator = resource_id_validator or validate_id user_project = project or initializer.global_config.project user_location = location or initializer.global_config.location - # Partial resource name (i.e. "12345") with known project and location - if ( - not valid_name - and validate_project(user_project) - and validate_region(user_location) - and validate_id(resource_name) - ): - resource_name = f"projects/{user_project}/locations/{user_location}/{resource_noun}/{resource_name}" - # Invalid resource_name parameter - elif not valid_name: - raise ValueError(f"Please provide a valid {resource_noun[:-1]} name or ID") - - return resource_name + validate_region(user_location) + resource_id_validator(resource_name) + + format_args = { + "location": user_location, + "project": user_project, + convert_camel_case_resource_noun_to_snake_case(resource_noun): resource_name, + } + + if parent_resource_name_fields: + format_args.update( + { + convert_camel_case_resource_noun_to_snake_case(key): value + for key, value in parent_resource_name_fields.items() + } + ) + return format_resource_name_method(**format_args) -# TODO(b/172286889) validate resource noun -def validate_resource_noun(resource_noun: str) -> bool: - """Validates resource noun. - Args: - resource_noun: resource noun to validate - Returns: - bool: True if no errors raised - Raises: - ValueError: If resource noun not supported. - """ - if resource_noun: - return True - raise ValueError("Please provide a valid resource noun") +# Resource nouns that are not plural in their resource names. +# Userd below to avoid conversion from plural to singular. +_SINGULAR_RESOURCE_NOUNS = {"time_series"} +_SINGULAR_RESOURCE_NOUNS_MAP = {"indexes": "index"} -# TODO(b/172288287) validate project -def validate_project(project: str) -> bool: - """Validates project. +def convert_camel_case_resource_noun_to_snake_case(resource_noun: str) -> str: + """Converts camel case to snake case to map resource name parts to GAPIC parameter names. Args: - project: project to validate + resource_noun (str): The resource noun in camel case to covert. Returns: - bool: True if no errors raised - Raises: - ValueError: If project does not exist. + Singular snake case resource noun. """ - if project: - return True - raise ValueError("Please provide a valid project ID") + snake_case = re.sub("([A-Z]+)", r"_\1", resource_noun).lower() + + # plural to singular + if snake_case in _SINGULAR_RESOURCE_NOUNS or not snake_case.endswith("s"): + return snake_case + elif snake_case in _SINGULAR_RESOURCE_NOUNS_MAP: + return _SINGULAR_RESOURCE_NOUNS_MAP[snake_case] + else: + return snake_case[:-1] -# TODO(b/172932277) verify display name only contains utf-8 chars def validate_display_name(display_name: str): """Verify display name is at most 128 chars. @@ -239,6 +227,22 @@ def validate_display_name(display_name: str): raise ValueError("Display name needs to be less than 128 characters.") +def validate_labels(labels: Dict[str, str]): + """Validate labels. + + Args: + labels: labels to verify + Raises: + ValueError: if labels is not a mapping of string key value pairs. + """ + for k, v in labels.items(): + if not isinstance(k, str) or not isinstance(v, str): + raise ValueError( + "Expect labels to be a mapping of string key value pairs. " + 'Got "{}".'.format(labels) + ) + + def validate_region(region: str) -> bool: """Validates region against supported regions. @@ -373,6 +377,16 @@ def _default_version(self) -> str: def _version_map(self) -> Tuple: pass + @property + def api_endpoint(self) -> str: + """Default API endpoint used by this client.""" + client = self._clients[self._default_version] + + if self._is_temporary: + return client._client_options.api_endpoint + else: + return client._transport._host.split(":")[0] + def __init__( self, client_options: client_options.ClientOptions, @@ -413,6 +427,22 @@ def __getattr__(self, name: str) -> Any: def select_version(self, version: str) -> VertexAiServiceClient: return self._clients[version] + @classmethod + def get_gapic_client_class( + cls, version: Optional[str] = None + ) -> Type[VertexAiServiceClient]: + """Gets the underyilng GAPIC client. + + Used to access class and static methods without instantiating. + + Args: + version (str): + Optional. Version of client to retreive otherwise the default version is returned. + Retuns: + Underlying GAPIC client for this wrapper and version. + """ + return dict(cls._version_map)[version or cls._default_version] + class DatasetClientWithOverride(ClientWithOverride): _is_temporary = True @@ -432,6 +462,51 @@ class EndpointClientWithOverride(ClientWithOverride): ) +class IndexClientWithOverride(ClientWithOverride): + _is_temporary = True + _default_version = compat.DEFAULT_VERSION + _version_map = ( + (compat.V1, index_service_client_v1.IndexServiceClient), + (compat.V1BETA1, index_service_client_v1beta1.IndexServiceClient), + ) + + +class IndexEndpointClientWithOverride(ClientWithOverride): + _is_temporary = True + _default_version = compat.DEFAULT_VERSION + _version_map = ( + (compat.V1, index_endpoint_service_client_v1.IndexEndpointServiceClient), + ( + compat.V1BETA1, + index_endpoint_service_client_v1beta1.IndexEndpointServiceClient, + ), + ) + + +class FeaturestoreClientWithOverride(ClientWithOverride): + _is_temporary = True + _default_version = compat.DEFAULT_VERSION + _version_map = ( + (compat.V1, featurestore_service_client_v1.FeaturestoreServiceClient), + (compat.V1BETA1, featurestore_service_client_v1beta1.FeaturestoreServiceClient), + ) + + +class FeaturestoreOnlineServingClientWithOverride(ClientWithOverride): + _is_temporary = False + _default_version = compat.DEFAULT_VERSION + _version_map = ( + ( + compat.V1, + featurestore_online_serving_service_client_v1.FeaturestoreOnlineServingServiceClient, + ), + ( + compat.V1BETA1, + featurestore_online_serving_service_client_v1beta1.FeaturestoreOnlineServingServiceClient, + ), + ) + + class JobClientWithOverride(ClientWithOverride): _is_temporary = True _default_version = compat.DEFAULT_VERSION @@ -459,6 +534,15 @@ class PipelineClientWithOverride(ClientWithOverride): ) +class PipelineJobClientWithOverride(ClientWithOverride): + _is_temporary = True + _default_version = compat.DEFAULT_VERSION + _version_map = ( + (compat.V1, pipeline_service_client_v1.PipelineServiceClient), + (compat.V1BETA1, pipeline_service_client_v1beta1.PipelineServiceClient), + ) + + class PredictionClientWithOverride(ClientWithOverride): _is_temporary = False _default_version = compat.DEFAULT_VERSION @@ -470,16 +554,18 @@ class PredictionClientWithOverride(ClientWithOverride): class MetadataClientWithOverride(ClientWithOverride): _is_temporary = True - _default_version = compat.V1BETA1 + _default_version = compat.DEFAULT_VERSION _version_map = ( + (compat.V1, metadata_service_client_v1.MetadataServiceClient), (compat.V1BETA1, metadata_service_client_v1beta1.MetadataServiceClient), ) class TensorboardClientWithOverride(ClientWithOverride): _is_temporary = False - _default_version = compat.V1BETA1 + _default_version = compat.DEFAULT_VERSION _version_map = ( + (compat.V1, tensorboard_service_client_v1.TensorboardServiceClient), (compat.V1BETA1, tensorboard_service_client_v1beta1.TensorboardServiceClient), ) @@ -488,9 +574,11 @@ class TensorboardClientWithOverride(ClientWithOverride): "VertexAiServiceClientWithOverride", DatasetClientWithOverride, EndpointClientWithOverride, + FeaturestoreClientWithOverride, JobClientWithOverride, ModelClientWithOverride, PipelineClientWithOverride, + PipelineJobClientWithOverride, PredictionClientWithOverride, MetadataClientWithOverride, TensorboardClientWithOverride, @@ -566,3 +654,25 @@ def _timestamped_copy_to_gcs( gcs_path = "".join(["gs://", "/".join([blob.bucket.name, blob.name])]) return gcs_path + + +def get_timestamp_proto( + time: Optional[datetime.datetime] = None, +) -> timestamp_pb2.Timestamp: + """Gets timestamp proto of a given time. + Args: + time (datetime.datetime): + Optional. A user provided time. Default to datetime.datetime.now() if not given. + Returns: + timestamp_pb2.Timestamp: timestamp proto of the given time, not have higher than millisecond precision. + """ + if not time: + time = datetime.datetime.now() + + time_str = time.isoformat(sep=" ", timespec="milliseconds") + time = datetime.datetime.strptime(time_str, "%Y-%m-%d %H:%M:%S.%f") + + timestamp_proto = timestamp_pb2.Timestamp() + timestamp_proto.FromDatetime(time) + + return timestamp_proto diff --git a/google/cloud/aiplatform/utils/column_transformations_utils.py b/google/cloud/aiplatform/utils/column_transformations_utils.py new file mode 100644 index 0000000000..fe7c16983c --- /dev/null +++ b/google/cloud/aiplatform/utils/column_transformations_utils.py @@ -0,0 +1,111 @@ +# -*- coding: utf-8 -*- + +# 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 +# +# 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 typing import Dict, List, Optional, Tuple +import warnings + +from google.cloud.aiplatform import datasets + + +def get_default_column_transformations( + dataset: datasets._ColumnNamesDataset, + target_column: str, +) -> Tuple[List[Dict[str, Dict[str, str]]], List[str]]: + """Get default column transformations from the column names, while omitting the target column. + + Args: + dataset (_ColumnNamesDataset): + Required. The dataset + target_column (str): + Required. The name of the column values of which the Model is to predict. + + Returns: + Tuple[List[Dict[str, Dict[str, str]]], List[str]]: + The default column transformations and the default column names. + """ + + column_names = [ + column_name + for column_name in dataset.column_names + if column_name != target_column + ] + column_transformations = [ + {"auto": {"column_name": column_name}} for column_name in column_names + ] + + return (column_transformations, column_names) + + +def validate_and_get_column_transformations( + column_specs: Optional[Dict[str, str]], + column_transformations: Optional[List[Dict[str, Dict[str, str]]]], +) -> List[Dict[str, Dict[str, str]]]: + """Validates column specs and transformations, then returns processed transformations. + + Args: + column_specs (Dict[str, str]): + Optional. Alternative to column_transformations where the keys of the dict + are column names and their respective values are one of + AutoMLTabularTrainingJob.column_data_types. + When creating transformation for BigQuery Struct column, the column + should be flattened using "." as the delimiter. Only columns with no child + should have a transformation. + If an input column has no transformations on it, such a column is + ignored by the training, except for the targetColumn, which should have + no transformations defined on. + Only one of column_transformations or column_specs should be passed. + column_transformations (List[Dict[str, Dict[str, str]]]): + Optional. Transformations to apply to the input columns (i.e. columns other + than the targetColumn). Each transformation may produce multiple + result values from the column's value, and all are used for training. + When creating transformation for BigQuery Struct column, the column + should be flattened using "." as the delimiter. Only columns with no child + should have a transformation. + If an input column has no transformations on it, such a column is + ignored by the training, except for the targetColumn, which should have + no transformations defined on. + Only one of column_transformations or column_specs should be passed. + Consider using column_specs as column_transformations will be deprecated eventually. + + Returns: + List[Dict[str, Dict[str, str]]]: + The column transformations. + + Raises: + ValueError: If both column_transformations and column_specs were provided. + """ + # user populated transformations + if column_transformations is not None and column_specs is not None: + raise ValueError( + "Both column_transformations and column_specs were passed. Only one is allowed." + ) + if column_transformations is not None: + warnings.simplefilter("always", DeprecationWarning) + warnings.warn( + "consider using column_specs instead. column_transformations will be deprecated in the future.", + DeprecationWarning, + stacklevel=2, + ) + + return column_transformations + elif column_specs is not None: + return [ + {transformation: {"column_name": column_name}} + for column_name, transformation in column_specs.items() + ] + else: + return None diff --git a/google/cloud/aiplatform/utils/console_utils.py b/google/cloud/aiplatform/utils/console_utils.py new file mode 100644 index 0000000000..c108b0605e --- /dev/null +++ b/google/cloud/aiplatform/utils/console_utils.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- + +# 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 +# +# 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 google.cloud.aiplatform import jobs +from google.cloud.aiplatform import tensorboard + + +def custom_job_console_uri(custom_job_resource_name: str) -> str: + """Helper method to create console uri from custom job resource name.""" + fields = jobs.CustomJob._parse_resource_name(custom_job_resource_name) + return f"https://console.cloud.google.com/ai/platform/locations/{fields['location']}/training/{fields['custom_job']}?project={fields['project']}" + + +def custom_job_tensorboard_console_uri( + tensorboard_resource_name: str, custom_job_resource_name: str +) -> str: + """Helper method to create console uri to tensorboard from custom job resource.""" + # projects+40556267596+locations+us-central1+tensorboards+740208820004847616+experiments+2214368039829241856 + fields = tensorboard.Tensorboard._parse_resource_name(tensorboard_resource_name) + experiment_resource_name = f"{tensorboard_resource_name}/experiments/{custom_job_resource_name.split('/')[-1]}" + uri_experiment_resource_name = experiment_resource_name.replace("/", "+") + return f"https://{fields['location']}.tensorboard.googleusercontent.com/experiment/{uri_experiment_resource_name}" diff --git a/google/cloud/aiplatform/utils/enhanced_library/__init__.py b/google/cloud/aiplatform/utils/enhanced_library/__init__.py new file mode 100644 index 0000000000..7e1ec16ec8 --- /dev/null +++ b/google/cloud/aiplatform/utils/enhanced_library/__init__.py @@ -0,0 +1,13 @@ +# 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 +# +# 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. diff --git a/google/cloud/aiplatform/helpers/_decorators.py b/google/cloud/aiplatform/utils/enhanced_library/_decorators.py similarity index 97% rename from google/cloud/aiplatform/helpers/_decorators.py rename to google/cloud/aiplatform/utils/enhanced_library/_decorators.py index 95aac31c4f..43e395393b 100644 --- a/google/cloud/aiplatform/helpers/_decorators.py +++ b/google/cloud/aiplatform/utils/enhanced_library/_decorators.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. from __future__ import absolute_import -from google.cloud.aiplatform.helpers import value_converter +from google.cloud.aiplatform.utils.enhanced_library import value_converter from proto.marshal import Marshal from proto.marshal.rules.struct import ValueRule diff --git a/google/cloud/aiplatform/helpers/value_converter.py b/google/cloud/aiplatform/utils/enhanced_library/value_converter.py similarity index 100% rename from google/cloud/aiplatform/helpers/value_converter.py rename to google/cloud/aiplatform/utils/enhanced_library/value_converter.py diff --git a/google/cloud/aiplatform/utils/featurestore_utils.py b/google/cloud/aiplatform/utils/featurestore_utils.py new file mode 100644 index 0000000000..b57824e15f --- /dev/null +++ b/google/cloud/aiplatform/utils/featurestore_utils.py @@ -0,0 +1,177 @@ +# -*- coding: utf-8 -*- + +# 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 +# +# 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. +# + +import re +from typing import Dict, NamedTuple, Optional + +from google.cloud.aiplatform.compat.services import featurestore_service_client +from google.cloud.aiplatform.compat.types import ( + feature as gca_feature, + featurestore_service as gca_featurestore_service, +) +from google.cloud.aiplatform import utils + +CompatFeaturestoreServiceClient = featurestore_service_client.FeaturestoreServiceClient + +RESOURCE_ID_PATTERN_REGEX = r"[a-z_][a-z0-9_]{0,59}" +GCS_SOURCE_TYPE = {"csv", "avro"} +GCS_DESTINATION_TYPE = {"csv", "tfrecord"} + +_FEATURE_VALUE_TYPE_UNSPECIFIED = "VALUE_TYPE_UNSPECIFIED" + +FEATURE_STORE_VALUE_TYPE_TO_BQ_DATA_TYPE_MAP = { + "BOOL": {"field_type": "BOOL"}, + "BOOL_ARRAY": {"field_type": "BOOL", "mode": "REPEATED"}, + "DOUBLE": {"field_type": "FLOAT64"}, + "DOUBLE_ARRAY": {"field_type": "FLOAT64", "mode": "REPEATED"}, + "INT64": {"field_type": "INT64"}, + "INT64_ARRAY": {"field_type": "INT64", "mode": "REPEATED"}, + "STRING": {"field_type": "STRING"}, + "STRING_ARRAY": {"field_type": "STRING", "mode": "REPEATED"}, + "BYTES": {"field_type": "BYTES"}, +} + + +def validate_id(resource_id: str) -> None: + """Validates feature store resource ID pattern. + + Args: + resource_id (str): + Required. Feature Store resource ID. + + Raises: + ValueError if resource_id is invalid. + """ + if not re.compile(r"^" + RESOURCE_ID_PATTERN_REGEX + r"$").match(resource_id): + raise ValueError("Resource ID {resource_id} is not a valied resource id.") + + +def validate_feature_id(feature_id: str) -> None: + """Validates feature ID. + + Args: + feature_id (str): + Required. Feature resource ID. + + Raises: + ValueError if feature_id is invalid. + """ + match = re.compile(r"^" + RESOURCE_ID_PATTERN_REGEX + r"$").match(feature_id) + + if not match: + raise ValueError( + f"The value of feature_id may be up to 60 characters, and valid characters are `[a-z0-9_]`. " + f"The first character cannot be a number. Instead, get {feature_id}." + ) + + reserved_words = ["entity_id", "feature_timestamp", "arrival_timestamp"] + if feature_id.lower() in reserved_words: + raise ValueError( + "The feature_id can not be any of the reserved_words: `%s`" + % ("`, `".join(reserved_words)) + ) + + +def validate_value_type(value_type: str) -> None: + """Validates user provided feature value_type string. + + Args: + value_type (str): + Required. Immutable. Type of Feature value. + One of BOOL, BOOL_ARRAY, DOUBLE, DOUBLE_ARRAY, INT64, INT64_ARRAY, STRING, STRING_ARRAY, BYTES. + + Raises: + ValueError if value_type is invalid or unspecified. + """ + if getattr(gca_feature.Feature.ValueType, value_type, None) in ( + gca_feature.Feature.ValueType.VALUE_TYPE_UNSPECIFIED, + None, + ): + raise ValueError( + f"Given value_type `{value_type}` invalid or unspecified. " + f"Choose one of {gca_feature.Feature.ValueType._member_names_} except `{_FEATURE_VALUE_TYPE_UNSPECIFIED}`" + ) + + +class _FeatureConfig(NamedTuple): + """Configuration for feature creation. + + Usage: + + config = _FeatureConfig( + feature_id='my_feature_id', + value_type='int64', + description='my description', + labels={'my_key': 'my_value'}, + ) + """ + + feature_id: str + value_type: str = _FEATURE_VALUE_TYPE_UNSPECIFIED + description: Optional[str] = None + labels: Optional[Dict[str, str]] = None + + def _get_feature_id(self) -> str: + """Validates and returns the feature_id. + + Returns: + str - valid feature ID. + + Raise: + ValueError if feature_id is invalid + """ + + # Raises ValueError if invalid feature_id + validate_feature_id(feature_id=self.feature_id) + + return self.feature_id + + def _get_value_type_enum(self) -> int: + """Validates value_type and returns the enum of the value type. + + Returns: + int - valid value type enum. + """ + + # Raises ValueError if invalid value_type + validate_value_type(value_type=self.value_type) + + value_type_enum = getattr(gca_feature.Feature.ValueType, self.value_type) + + return value_type_enum + + def get_create_feature_request( + self, + ) -> gca_featurestore_service.CreateFeatureRequest: + """Return create feature request.""" + + gapic_feature = gca_feature.Feature( + value_type=self._get_value_type_enum(), + ) + + if self.labels: + utils.validate_labels(self.labels) + gapic_feature.labels = self.labels + + if self.description: + gapic_feature.description = self.description + + create_feature_request = gca_featurestore_service.CreateFeatureRequest( + feature=gapic_feature, feature_id=self._get_feature_id() + ) + + return create_feature_request diff --git a/google/cloud/aiplatform/utils/gcs_utils.py b/google/cloud/aiplatform/utils/gcs_utils.py new file mode 100644 index 0000000000..855b7991f1 --- /dev/null +++ b/google/cloud/aiplatform/utils/gcs_utils.py @@ -0,0 +1,165 @@ +# -*- coding: utf-8 -*- + +# 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 +# +# 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. + + +import datetime +import glob +import logging +import pathlib +from typing import Optional + +from google.auth import credentials as auth_credentials +from google.cloud import storage + +from google.cloud.aiplatform import initializer + + +_logger = logging.getLogger(__name__) + + +def upload_to_gcs( + source_path: str, + destination_uri: str, + project: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, +): + """Uploads local files to GCS. + + After upload the `destination_uri` will contain the same data as the `source_path`. + + Args: + source_path: Required. Path of the local data to copy to GCS. + destination_uri: Required. GCS URI where the data should be uploaded. + project: Optional. Google Cloud Project that contains the staging bucket. + credentials: The custom credentials to use when making API calls. + If not provided, default credentials will be used. + + Raises: + RuntimeError: When source_path does not exist. + GoogleCloudError: When the upload process fails. + """ + source_path_obj = pathlib.Path(source_path) + if not source_path_obj.exists(): + raise RuntimeError(f"Source path does not exist: {source_path}") + + project = project or initializer.global_config.project + credentials = credentials or initializer.global_config.credentials + + storage_client = storage.Client(project=project, credentials=credentials) + if source_path_obj.is_dir(): + source_file_paths = glob.glob( + pathname=str(source_path_obj / "**"), recursive=True + ) + for source_file_path in source_file_paths: + source_file_path_obj = pathlib.Path(source_file_path) + if source_file_path_obj.is_dir(): + continue + source_file_relative_path_obj = source_file_path_obj.relative_to( + source_path_obj + ) + source_file_relative_posix_path = source_file_relative_path_obj.as_posix() + destination_file_uri = ( + destination_uri.rstrip("/") + "/" + source_file_relative_posix_path + ) + _logger.debug(f'Uploading "{source_file_path}" to "{destination_file_uri}"') + destination_blob = storage.Blob.from_string( + destination_file_uri, client=storage_client + ) + destination_blob.upload_from_filename(filename=source_file_path) + else: + source_file_path = source_path + destination_file_uri = destination_uri + _logger.debug(f'Uploading "{source_file_path}" to "{destination_file_uri}"') + destination_blob = storage.Blob.from_string( + destination_file_uri, client=storage_client + ) + destination_blob.upload_from_filename(filename=source_file_path) + + +def stage_local_data_in_gcs( + data_path: str, + staging_gcs_dir: Optional[str] = None, + project: Optional[str] = None, + location: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, +) -> str: + """Stages a local data in GCS. + + The file copied to GCS is the name of the local file prepended with an + "aiplatform-{timestamp}-" string. + + Args: + data_path: Required. Path of the local data to copy to GCS. + staging_gcs_dir: + Optional. Google Cloud Storage bucket to be used for data staging. + project: Optional. Google Cloud Project that contains the staging bucket. + location: Optional. Google Cloud location to use for the staging bucket. + credentials: The custom credentials to use when making API calls. + If not provided, default credentials will be used. + + Returns: + Google Cloud Storage URI of the staged data. + + Raises: + RuntimeError: When source_path does not exist. + GoogleCloudError: When the upload process fails. + """ + data_path_obj = pathlib.Path(data_path) + + if not data_path_obj.exists(): + raise RuntimeError(f"Local data does not exist: data_path='{data_path}'") + + staging_gcs_dir = staging_gcs_dir or initializer.global_config.staging_bucket + if not staging_gcs_dir: + project = project or initializer.global_config.project + location = location or initializer.global_config.location + credentials = credentials or initializer.global_config.credentials + # Creating the bucket if it does not exist. + # Currently we only do this when staging_gcs_dir is not specified. + # The buckets that we create are regional. + # This prevents errors when some service required regional bucket. + # E.g. "FailedPrecondition: 400 The Cloud Storage bucket of `gs://...` is in location `us`. It must be in the same regional location as the service location `us-central1`." + # We are making the bucket name region-specific since the bucket is regional. + staging_bucket_name = project + "-vertex-staging-" + location + client = storage.Client(project=project, credentials=credentials) + staging_bucket = storage.Bucket(client=client, name=staging_bucket_name) + if not staging_bucket.exists(): + _logger.info(f'Creating staging GCS bucket "{staging_bucket_name}"') + staging_bucket = client.create_bucket( + bucket_or_name=staging_bucket, + project=project, + location=location, + ) + staging_gcs_dir = "gs://" + staging_bucket_name + + timestamp = datetime.datetime.now().isoformat(sep="-", timespec="milliseconds") + staging_gcs_subdir = ( + staging_gcs_dir.rstrip("/") + "/vertex_ai_auto_staging/" + timestamp + ) + + staged_data_uri = staging_gcs_subdir + if data_path_obj.is_file(): + staged_data_uri = staging_gcs_subdir + "/" + data_path_obj.name + + _logger.info(f'Uploading "{data_path}" to "{staged_data_uri}"') + upload_to_gcs( + source_path=data_path, + destination_uri=staged_data_uri, + project=project, + credentials=credentials, + ) + + return staged_data_uri diff --git a/google/cloud/aiplatform/utils/pipeline_utils.py b/google/cloud/aiplatform/utils/pipeline_utils.py new file mode 100644 index 0000000000..f988cc307e --- /dev/null +++ b/google/cloud/aiplatform/utils/pipeline_utils.py @@ -0,0 +1,256 @@ +# -*- coding: utf-8 -*- +# 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 +# +# 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. +# + +import copy +import json +from typing import Any, Dict, Mapping, Optional, Union +from google.cloud.aiplatform.compat.types import pipeline_failure_policy +import packaging.version + + +class PipelineRuntimeConfigBuilder(object): + """Pipeline RuntimeConfig builder. + + Constructs a RuntimeConfig spec with pipeline_root and parameter overrides. + """ + + def __init__( + self, + pipeline_root: str, + schema_version: str, + parameter_types: Mapping[str, str], + parameter_values: Optional[Dict[str, Any]] = None, + failure_policy: Optional[pipeline_failure_policy.PipelineFailurePolicy] = None, + ): + """Creates a PipelineRuntimeConfigBuilder object. + + Args: + pipeline_root (str): + Required. The root of the pipeline outputs. + schema_version (str): + Required. Schema version of the IR. This field determines the fields supported in current version of IR. + parameter_types (Mapping[str, str]): + Required. The mapping from pipeline parameter name to its type. + parameter_values (Dict[str, Any]): + Optional. The mapping from runtime parameter name to its value. + failure_policy (pipeline_failure_policy.PipelineFailurePolicy): + Optional. Represents the failure policy of a pipeline. Currently, the + default of a pipeline is that the pipeline will continue to + run until no more tasks can be executed, also known as + PIPELINE_FAILURE_POLICY_FAIL_SLOW. However, if a pipeline is + set to PIPELINE_FAILURE_POLICY_FAIL_FAST, it will stop + scheduling any new tasks when a task has failed. Any + scheduled tasks will continue to completion. + """ + self._pipeline_root = pipeline_root + self._schema_version = schema_version + self._parameter_types = parameter_types + self._parameter_values = copy.deepcopy(parameter_values or {}) + self._failure_policy = failure_policy + + @classmethod + def from_job_spec_json( + cls, + job_spec: Mapping[str, Any], + ) -> "PipelineRuntimeConfigBuilder": + """Creates a PipelineRuntimeConfigBuilder object from PipelineJob json spec. + + Args: + job_spec (Mapping[str, Any]): + Required. The PipelineJob spec. + + Returns: + A PipelineRuntimeConfigBuilder object. + """ + runtime_config_spec = job_spec["runtimeConfig"] + parameter_input_definitions = ( + job_spec["pipelineSpec"]["root"] + .get("inputDefinitions", {}) + .get("parameters", {}) + ) + schema_version = job_spec["pipelineSpec"]["schemaVersion"] + + # 'type' is deprecated in IR and change to 'parameterType'. + parameter_types = { + k: v.get("parameterType") or v.get("type") + for k, v in parameter_input_definitions.items() + } + + pipeline_root = runtime_config_spec.get("gcsOutputDirectory") + parameter_values = _parse_runtime_parameters(runtime_config_spec) + failure_policy = runtime_config_spec.get("failurePolicy") + return cls( + pipeline_root, + schema_version, + parameter_types, + parameter_values, + failure_policy, + ) + + def update_pipeline_root(self, pipeline_root: Optional[str]) -> None: + """Updates pipeline_root value. + + Args: + pipeline_root (str): + Optional. The root of the pipeline outputs. + """ + if pipeline_root: + self._pipeline_root = pipeline_root + + def update_runtime_parameters( + self, parameter_values: Optional[Mapping[str, Any]] = None + ) -> None: + """Merges runtime parameter values. + + Args: + parameter_values (Mapping[str, Any]): + Optional. The mapping from runtime parameter names to its values. + """ + if parameter_values: + parameters = dict(parameter_values) + if packaging.version.parse(self._schema_version) <= packaging.version.parse( + "2.0.0" + ): + for k, v in parameter_values.items(): + if isinstance(v, (dict, list, bool)): + parameters[k] = json.dumps(v) + self._parameter_values.update(parameters) + + def update_failure_policy(self, failure_policy: Optional[str] = None) -> None: + """Merges runtime failure policy. + + Args: + failure_policy (str): + Optional. The failure policy - "slow" or "fast". + + Raises: + ValueError: if failure_policy is not valid. + """ + if failure_policy: + if failure_policy in _FAILURE_POLICY_TO_ENUM_VALUE: + self._failure_policy = _FAILURE_POLICY_TO_ENUM_VALUE[failure_policy] + else: + raise ValueError( + f'failure_policy should be either "slow" or "fast", but got: "{failure_policy}".' + ) + + def build(self) -> Dict[str, Any]: + """Build a RuntimeConfig proto. + + Raises: + ValueError: if the pipeline root is not specified. + """ + if not self._pipeline_root: + raise ValueError( + "Pipeline root must be specified, either during " + "compile time, or when calling the service." + ) + if packaging.version.parse(self._schema_version) > packaging.version.parse( + "2.0.0" + ): + parameter_values_key = "parameterValues" + else: + parameter_values_key = "parameters" + + runtime_config = { + "gcsOutputDirectory": self._pipeline_root, + parameter_values_key: { + k: self._get_vertex_value(k, v) + for k, v in self._parameter_values.items() + if v is not None + }, + } + + if self._failure_policy: + runtime_config["failurePolicy"] = self._failure_policy + + return runtime_config + + def _get_vertex_value( + self, name: str, value: Union[int, float, str, bool, list, dict] + ) -> Union[int, float, str, bool, list, dict]: + """Converts primitive values into Vertex pipeline Value proto message. + + Args: + name (str): + Required. The name of the pipeline parameter. + value (Union[int, float, str, bool, list, dict]): + Required. The value of the pipeline parameter. + + Returns: + A dictionary represents the Vertex pipeline Value proto message. + + Raises: + ValueError: if the parameter name is not found in pipeline root + inputs, or value is none. + """ + if value is None: + raise ValueError("None values should be filtered out.") + + if name not in self._parameter_types: + raise ValueError( + "The pipeline parameter {} is not found in the " + "pipeline job input definitions.".format(name) + ) + + if packaging.version.parse(self._schema_version) <= packaging.version.parse( + "2.0.0" + ): + result = {} + if self._parameter_types[name] == "INT": + result["intValue"] = value + elif self._parameter_types[name] == "DOUBLE": + result["doubleValue"] = value + elif self._parameter_types[name] == "STRING": + result["stringValue"] = value + else: + raise TypeError("Got unknown type of value: {}".format(value)) + return result + else: + return value + + +def _parse_runtime_parameters( + runtime_config_spec: Mapping[str, Any] +) -> Optional[Dict[str, Any]]: + """Extracts runtime parameters from runtime config json spec. + + Raises: + TypeError: if the parameter type is not one of 'INT', 'DOUBLE', 'STRING'. + """ + # 'parameters' are deprecated in IR and changed to 'parameterValues'. + if runtime_config_spec.get("parameterValues") is not None: + return runtime_config_spec.get("parameterValues") + + if runtime_config_spec.get("parameters") is not None: + result = {} + for name, value in runtime_config_spec.get("parameters").items(): + if "intValue" in value: + result[name] = int(value["intValue"]) + elif "doubleValue" in value: + result[name] = float(value["doubleValue"]) + elif "stringValue" in value: + result[name] = value["stringValue"] + else: + raise TypeError("Got unknown type of value: {}".format(value)) + return result + + +_FAILURE_POLICY_TO_ENUM_VALUE = { + "slow": pipeline_failure_policy.PipelineFailurePolicy.PIPELINE_FAILURE_POLICY_FAIL_SLOW, + "fast": pipeline_failure_policy.PipelineFailurePolicy.PIPELINE_FAILURE_POLICY_FAIL_FAST, + None: pipeline_failure_policy.PipelineFailurePolicy.PIPELINE_FAILURE_POLICY_UNSPECIFIED, +} diff --git a/google/cloud/aiplatform/utils/resource_manager_utils.py b/google/cloud/aiplatform/utils/resource_manager_utils.py new file mode 100644 index 0000000000..f918c766bf --- /dev/null +++ b/google/cloud/aiplatform/utils/resource_manager_utils.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- + +# Copyright 2022 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 typing import Optional + +from google.auth import credentials as auth_credentials +from google.cloud import resourcemanager + +from google.cloud.aiplatform import initializer + + +def get_project_id( + project_number: str, + credentials: Optional[auth_credentials.Credentials] = None, +) -> str: + """Gets project ID given the project number + + Args: + project_number (str): + Required. The automatically generated unique identifier for your GCP project. + credentials: The custom credentials to use when making API calls. + Optional. If not provided, default credentials will be used. + + Returns: + str - The unique string used to differentiate your GCP project from all others in Google Cloud. + + """ + + credentials = credentials or initializer.global_config.credentials + + projects_client = resourcemanager.ProjectsClient(credentials=credentials) + + project = projects_client.get_project(name=f"projects/{project_number}") + + return project.project_id diff --git a/google/cloud/aiplatform/utils/rest_utils.py b/google/cloud/aiplatform/utils/rest_utils.py new file mode 100644 index 0000000000..4d8db45c47 --- /dev/null +++ b/google/cloud/aiplatform/utils/rest_utils.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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 google.cloud.aiplatform import base + + +def make_gcp_resource_rest_url(resource: base.VertexAiResourceNoun) -> str: + """Helper function to format the GCP resource url for google.X metadata schemas. + + Args: + resource (base.VertexAiResourceNoun): Required. A Vertex resource instance. + Returns: + The formatted url of resource. + """ + resource_name = resource.resource_name + version = resource.api_client._default_version + api_uri = resource.api_client.api_endpoint + + return f"https://{api_uri}/{version}/{resource_name}" diff --git a/google/cloud/aiplatform/utils/source_utils.py b/google/cloud/aiplatform/utils/source_utils.py index b7fcef806f..dc3c14a759 100644 --- a/google/cloud/aiplatform/utils/source_utils.py +++ b/google/cloud/aiplatform/utils/source_utils.py @@ -16,6 +16,7 @@ import functools +import os import pathlib import shutil import subprocess @@ -62,7 +63,7 @@ class _TrainingScriptPythonPackager: Constant command to generate the source distribution package. Attributes: - script_path: local path of script to package + script_path: local path of script or folder to package requirements: list of Python dependencies to add to package Usage: @@ -70,7 +71,7 @@ class _TrainingScriptPythonPackager: packager = TrainingScriptPythonPackager('my_script.py', ['pandas', 'pytorch']) gcs_path = packager.package_and_copy_to_gcs( gcs_staging_dir='my-bucket', - project='my-prject') + project='my-project') module_name = packager.module_name The package after installed can be executed as: @@ -79,7 +80,6 @@ class _TrainingScriptPythonPackager: _TRAINER_FOLDER = "trainer" _ROOT_MODULE = "aiplatform_custom_trainer_script" - _TASK_MODULE_NAME = "task" _SETUP_PY_VERSION = "0.1" _SETUP_PY_TEMPLATE = """from setuptools import find_packages @@ -96,10 +96,12 @@ class _TrainingScriptPythonPackager: _SETUP_PY_SOURCE_DISTRIBUTION_CMD = "setup.py sdist --formats=gztar" - # Module name that can be executed during training. ie. python -m - module_name = f"{_ROOT_MODULE}.{_TASK_MODULE_NAME}" - - def __init__(self, script_path: str, requirements: Optional[Sequence[str]] = None): + def __init__( + self, + script_path: str, + task_module_name: str = "task", + requirements: Optional[Sequence[str]] = None, + ): """Initializes packager. Args: @@ -109,8 +111,14 @@ def __init__(self, script_path: str, requirements: Optional[Sequence[str]] = Non """ self.script_path = script_path + self.task_module_name = task_module_name self.requirements = requirements or [] + @property + def module_name(self) -> str: + # Module name that can be executed during training. ie. python -m + return f"{self._ROOT_MODULE}.{self.task_module_name}" + def make_package(self, package_directory: str) -> str: """Converts script into a Python package suitable for python module execution. @@ -134,9 +142,6 @@ def make_package(self, package_directory: str) -> str: # __init__.py path in root module init_path = trainer_path / "__init__.py" - # The module that will contain the script - script_out_path = trainer_path / f"{self._TASK_MODULE_NAME}.py" - # The path to setup.py in the package. setup_py_path = trainer_root_path / "setup.py" @@ -165,8 +170,18 @@ def make_package(self, package_directory: str) -> str: with setup_py_path.open("w") as fp: fp.write(setup_py_output) - # Copy script as module of python package. - shutil.copy(self.script_path, script_out_path) + if os.path.isdir(self.script_path): + # Remove destination path if it already exists + shutil.rmtree(trainer_path) + + # Copy folder recursively + shutil.copytree(src=self.script_path, dst=trainer_path) + else: + # The module that will contain the script + script_out_path = trainer_path / f"{self.task_module_name}.py" + + # Copy script as module of python package. + shutil.copy(self.script_path, script_out_path) # Run setup.py to create the source distribution. setup_cmd = [ diff --git a/google/cloud/aiplatform/utils/tensorboard_utils.py b/google/cloud/aiplatform/utils/tensorboard_utils.py new file mode 100644 index 0000000000..32962aa1ab --- /dev/null +++ b/google/cloud/aiplatform/utils/tensorboard_utils.py @@ -0,0 +1,93 @@ +# -*- coding: utf-8 -*- +# 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 +# +# 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 typing import Sequence, Dict +from google.cloud.aiplatform_v1beta1.services.tensorboard_service.client import ( + TensorboardServiceClient, +) + +_SERVING_DOMAIN = "tensorboard.googleusercontent.com" + + +def _parse_experiment_name(experiment_name: str) -> Dict[str, str]: + """Parses an experiment_name into its component segments. + + Args: + experiment_name: Resource name of the TensorboardExperiment. E.g. + "projects/123/locations/asia-east1/tensorboards/456/experiments/exp1" + + Returns: + Components of the experiment name. + + Raises: + ValueError: If the experiment_name is invalid. + """ + matched = TensorboardServiceClient.parse_tensorboard_experiment_path( + experiment_name + ) + if not matched: + raise ValueError(f"Invalid experiment name: {experiment_name}.") + return matched + + +def get_experiment_url(experiment_name: str) -> str: + """Get URL for comparing experiments. + + Args: + experiment_name: Resource name of the TensorboardExperiment. E.g. + "projects/123/locations/asia-east1/tensorboards/456/experiments/exp1" + + Returns: + URL for the tensorboard web app. + """ + location = _parse_experiment_name(experiment_name)["location"] + name_for_url = experiment_name.replace("/", "+") + return f"https://{location}.{_SERVING_DOMAIN}/experiment/{name_for_url}" + + +def get_experiments_compare_url(experiment_names: Sequence[str]) -> str: + """Get URL for comparing experiments. + + Args: + experiment_names: Resource names of the TensorboardExperiments that needs to + be compared. + + Returns: + URL for the tensorboard web app. + """ + if len(experiment_names) < 2: + raise ValueError("At least two experiment_names are required.") + + locations = { + _parse_experiment_name(experiment_name)["location"] + for experiment_name in experiment_names + } + if len(locations) != 1: + raise ValueError( + f"Got experiments from different locations: {', '.join(locations)}." + ) + location = locations.pop() + + experiment_url_segments = [] + for idx, experiment_name in enumerate(experiment_names): + name_segments = _parse_experiment_name(experiment_name) + experiment_url_segments.append( + "{cnt}-{experiment}:{project}+{location}+{tensorboard}+{experiment}".format( + cnt=idx + 1, **name_segments + ) + ) + encoded_names = ",".join(experiment_url_segments) + return f"https://{location}.{_SERVING_DOMAIN}/compare/{encoded_names}" diff --git a/google/cloud/aiplatform/utils/worker_spec_utils.py b/google/cloud/aiplatform/utils/worker_spec_utils.py index 385ac83979..2de1bf2f28 100644 --- a/google/cloud/aiplatform/utils/worker_spec_utils.py +++ b/google/cloud/aiplatform/utils/worker_spec_utils.py @@ -21,17 +21,31 @@ accelerator_type as gca_accelerator_type_compat, ) +# `_SPEC_ORDERS` contains the worker pool spec type and its order in the `_WorkerPoolSpec`. +# The `server_spec` supports either reduction server or parameter server, each +# with different configuration for its `container_spec`. This mapping will be +# used during configuration of `container_spec` for all worker pool specs. +_SPEC_ORDERS = { + "chief_spec": 0, + "worker_spec": 1, + "server_spec": 2, + "evaluator_spec": 3, +} -class _MachineSpec(NamedTuple): - """Specification container for Machine specs used for distributed training. + +class _WorkerPoolSpec(NamedTuple): + """Specification container for Worker Pool specs used for distributed training. Usage: - spec = _MachineSpec( + spec = _WorkerPoolSpec( replica_count=10, machine_type='n1-standard-4', accelerator_count=2, - accelerator_type='NVIDIA_TESLA_K80') + accelerator_type='NVIDIA_TESLA_K80', + boot_disk_type='pd-ssd', + boot_disk_size_gb=100, + ) Note that container and python package specs are not stored with this spec. """ @@ -40,6 +54,8 @@ class _MachineSpec(NamedTuple): machine_type: str = "n1-standard-4" accelerator_count: int = 0 accelerator_type: str = "ACCELERATOR_TYPE_UNSPECIFIED" + boot_disk_type: str = "pd-ssd" + boot_disk_size_gb: int = 100 def _get_accelerator_type(self) -> Optional[str]: """Validates accelerator_type and returns the name of the accelerator. @@ -70,7 +86,12 @@ def spec_dict(self) -> Dict[str, Union[int, str, Dict[str, Union[int, str]]]]: spec = { "machine_spec": {"machine_type": self.machine_type}, "replica_count": self.replica_count, + "disk_spec": { + "boot_disk_type": self.boot_disk_type, + "boot_disk_size_gb": self.boot_disk_size_gb, + }, } + accelerator_type = self._get_accelerator_type() if accelerator_type and self.accelerator_count: spec["machine_spec"]["accelerator_type"] = accelerator_type @@ -98,25 +119,29 @@ class _DistributedTrainingSpec(NamedTuple): Usage: dist_training_spec = _DistributedTrainingSpec( - chief_spec = _MachineSpec( + chief_spec = _WorkerPoolSpec( replica_count=1, machine_type='n1-standard-4', accelerator_count=2, - accelerator_type='NVIDIA_TESLA_K80' - ), - worker_spec = _MachineSpec( + accelerator_type='NVIDIA_TESLA_K80', + boot_disk_type='pd-ssd', + boot_disk_size_gb=100, + ), + worker_spec = _WorkerPoolSpec( replica_count=10, machine_type='n1-standard-4', accelerator_count=2, - accelerator_type='NVIDIA_TESLA_K80' - ) + accelerator_type='NVIDIA_TESLA_K80', + boot_disk_type='pd-ssd', + boot_disk_size_gb=100, + ), ) """ - chief_spec: _MachineSpec = _MachineSpec() - worker_spec: _MachineSpec = _MachineSpec() - parameter_server_spec: _MachineSpec = _MachineSpec() - evaluator_spec: _MachineSpec = _MachineSpec() + chief_spec: _WorkerPoolSpec = _WorkerPoolSpec() + worker_spec: _WorkerPoolSpec = _WorkerPoolSpec() + server_spec: _WorkerPoolSpec = _WorkerPoolSpec() + evaluator_spec: _WorkerPoolSpec = _WorkerPoolSpec() @property def pool_specs( @@ -138,10 +163,10 @@ def pool_specs( spec_order = [ self.chief_spec, self.worker_spec, - self.parameter_server_spec, + self.server_spec, self.evaluator_spec, ] - specs = [s.spec_dict for s in spec_order] + specs = [{} if s.is_empty else s.spec_dict for s in spec_order] for i in reversed(range(len(spec_order))): if spec_order[i].is_empty: specs.pop() @@ -156,8 +181,12 @@ def chief_worker_pool( machine_type: str = "n1-standard-4", accelerator_count: int = 0, accelerator_type: str = "ACCELERATOR_TYPE_UNSPECIFIED", + boot_disk_type: str = "pd-ssd", + boot_disk_size_gb: int = 100, + reduction_server_replica_count: int = 0, + reduction_server_machine_type: str = None, ) -> "_DistributedTrainingSpec": - """Parameterizes Config to support only chief with worker replicas. + """Parametrizes Config to support only chief with worker replicas. For replica is assigned to chief and the remainder to workers. All spec have the same machine type, accelerator count, and accelerator type. @@ -174,26 +203,51 @@ def chief_worker_pool( NVIDIA_TESLA_T4 accelerator_count (int): The number of accelerators to attach to a worker replica. + boot_disk_type (str): + Type of the boot disk (default is `pd-ssd`). + Valid values: `pd-ssd` (Persistent Disk Solid State Drive) or + `pd-standard` (Persistent Disk Hard Disk Drive). + boot_disk_size_gb (int): + Size in GB of the boot disk (default is 100GB). + boot disk size must be within the range of [100, 64000]. + reduction_server_replica_count (int): + The number of reduction server replicas, default is 0. + reduction_server_machine_type (str): + The type of machine to use for reduction server, default is `n1-highcpu-16`. Returns: - _DistributedTrainingSpec representing one chief and n workers all of same - type. If replica_count <= 0 then an empty spec is returned. + _DistributedTrainingSpec representing one chief and n workers all of + same type, optional with reduction server(s). If replica_count <= 0 + then an empty spec is returned. """ if replica_count <= 0: return cls() - chief_spec = _MachineSpec( + chief_spec = _WorkerPoolSpec( replica_count=1, machine_type=machine_type, accelerator_count=accelerator_count, accelerator_type=accelerator_type, + boot_disk_type=boot_disk_type, + boot_disk_size_gb=boot_disk_size_gb, ) - worker_spec = _MachineSpec( + worker_spec = _WorkerPoolSpec( replica_count=replica_count - 1, machine_type=machine_type, accelerator_count=accelerator_count, accelerator_type=accelerator_type, + boot_disk_type=boot_disk_type, + boot_disk_size_gb=boot_disk_size_gb, ) - return cls(chief_spec=chief_spec, worker_spec=worker_spec) + reduction_server_spec = _WorkerPoolSpec( + replica_count=reduction_server_replica_count, + machine_type=reduction_server_machine_type, + ) + + return cls( + chief_spec=chief_spec, + worker_spec=worker_spec, + server_spec=reduction_server_spec, + ) diff --git a/google/cloud/aiplatform/utils/yaml_utils.py b/google/cloud/aiplatform/utils/yaml_utils.py new file mode 100644 index 0000000000..bac33733dc --- /dev/null +++ b/google/cloud/aiplatform/utils/yaml_utils.py @@ -0,0 +1,139 @@ +# -*- 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. +# + +import re +from typing import Any, Dict, Optional +from urllib import request + +from google.auth import credentials as auth_credentials +from google.auth import transport +from google.cloud import storage + +# Pattern for an Artifact Registry URL. +_VALID_AR_URL = re.compile(r"^https:\/\/([\w-]+)-kfp\.pkg\.dev\/.*") + + +def load_yaml( + path: str, + project: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, +) -> Dict[str, Any]: + """Loads data from a YAML document. + + Args: + path (str): + Required. The path of the YAML document in Google Cloud Storage or + local. + project (str): + Optional. Project to initiate the Storage client with. + credentials (auth_credentials.Credentials): + Optional. Credentials to use with Storage Client. + + Returns: + A Dict object representing the YAML document. + """ + if path.startswith("gs://"): + return _load_yaml_from_gs_uri(path, project, credentials) + elif _VALID_AR_URL.match(path): + return _load_yaml_from_ar_uri(path, credentials) + else: + return _load_yaml_from_local_file(path) + + +def _load_yaml_from_gs_uri( + uri: str, + project: Optional[str] = None, + credentials: Optional[auth_credentials.Credentials] = None, +) -> Dict[str, Any]: + """Loads data from a YAML document referenced by a GCS URI. + + Args: + path (str): + Required. GCS URI for YAML document. + project (str): + Optional. Project to initiate the Storage client with. + credentials (auth_credentials.Credentials): + Optional. Credentials to use with Storage Client. + + Returns: + A Dict object representing the YAML document. + """ + try: + import yaml + except ImportError: + raise ImportError( + "pyyaml is not installed and is required to parse PipelineJob or PipelineSpec files. " + 'Please install the SDK using "pip install google-cloud-aiplatform[pipelines]"' + ) + storage_client = storage.Client(project=project, credentials=credentials) + blob = storage.Blob.from_string(uri, storage_client) + return yaml.safe_load(blob.download_as_bytes()) + + +def _load_yaml_from_local_file(file_path: str) -> Dict[str, Any]: + """Loads data from a YAML local file. + + Args: + file_path (str): + Required. The local file path of the YAML document. + + Returns: + A Dict object representing the YAML document. + """ + try: + import yaml + except ImportError: + raise ImportError( + "pyyaml is not installed and is required to parse PipelineJob or PipelineSpec files. " + 'Please install the SDK using "pip install google-cloud-aiplatform[pipelines]"' + ) + with open(file_path) as f: + return yaml.safe_load(f) + + +def _load_yaml_from_ar_uri( + uri: str, + credentials: Optional[auth_credentials.Credentials] = None, +) -> Dict[str, Any]: + """Loads data from a YAML document referenced by a Artifact Registry URI. + + Args: + path (str): + Required. Artifact Registry URI for YAML document. + credentials (auth_credentials.Credentials): + Optional. Credentials to use with Artifact Registry. + + Returns: + A Dict object representing the YAML document. + """ + try: + import yaml + except ImportError: + raise ImportError( + "pyyaml is not installed and is required to parse PipelineJob or PipelineSpec files. " + 'Please install the SDK using "pip install google-cloud-aiplatform[pipelines]"' + ) + req = request.Request(uri) + + if credentials: + if not credentials.valid: + credentials.refresh(transport.requests.Request()) + if credentials.token: + req.add_header("Authorization", "Bearer " + credentials.token) + response = request.urlopen(req) + + return yaml.safe_load(response.read().decode("utf-8")) diff --git a/google/cloud/aiplatform/v1/schema/predict/instance/__init__.py b/google/cloud/aiplatform/v1/schema/predict/instance/__init__.py index 135e131a29..5d321a91dd 100644 --- a/google/cloud/aiplatform/v1/schema/predict/instance/__init__.py +++ b/google/cloud/aiplatform/v1/schema/predict/instance/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform/v1/schema/predict/instance_v1/__init__.py b/google/cloud/aiplatform/v1/schema/predict/instance_v1/__init__.py index fdfe1ca46f..47708ddc7f 100644 --- a/google/cloud/aiplatform/v1/schema/predict/instance_v1/__init__.py +++ b/google/cloud/aiplatform/v1/schema/predict/instance_v1/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/__init__.py b/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/__init__.py index 744852e8a3..c36f147d50 100644 --- a/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/__init__.py +++ b/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,15 +13,33 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from .image_classification import ImageClassificationPredictionInstance -from .image_object_detection import ImageObjectDetectionPredictionInstance -from .image_segmentation import ImageSegmentationPredictionInstance -from .text_classification import TextClassificationPredictionInstance -from .text_extraction import TextExtractionPredictionInstance -from .text_sentiment import TextSentimentPredictionInstance -from .video_action_recognition import VideoActionRecognitionPredictionInstance -from .video_classification import VideoClassificationPredictionInstance -from .video_object_tracking import VideoObjectTrackingPredictionInstance +from .image_classification import ( + ImageClassificationPredictionInstance, +) +from .image_object_detection import ( + ImageObjectDetectionPredictionInstance, +) +from .image_segmentation import ( + ImageSegmentationPredictionInstance, +) +from .text_classification import ( + TextClassificationPredictionInstance, +) +from .text_extraction import ( + TextExtractionPredictionInstance, +) +from .text_sentiment import ( + TextSentimentPredictionInstance, +) +from .video_action_recognition import ( + VideoActionRecognitionPredictionInstance, +) +from .video_classification import ( + VideoClassificationPredictionInstance, +) +from .video_object_tracking import ( + VideoObjectTrackingPredictionInstance, +) __all__ = ( "ImageClassificationPredictionInstance", diff --git a/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/image_classification.py b/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/image_classification.py index 04e7b841a5..0507c768a1 100644 --- a/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/image_classification.py +++ b/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/image_classification.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,16 +18,19 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1.schema.predict.instance", - manifest={"ImageClassificationPredictionInstance",}, + manifest={ + "ImageClassificationPredictionInstance", + }, ) class ImageClassificationPredictionInstance(proto.Message): r"""Prediction input format for Image Classification. + Attributes: content (str): - The image bytes or GCS URI to make the - prediction on. + The image bytes or Cloud Storage URI to make + the prediction on. mime_type (str): The MIME type of the content of the image. Only the images in below listed MIME types are @@ -40,8 +43,14 @@ class ImageClassificationPredictionInstance(proto.Message): - image/vnd.microsoft.icon """ - content = proto.Field(proto.STRING, number=1,) - mime_type = proto.Field(proto.STRING, number=2,) + content = proto.Field( + proto.STRING, + number=1, + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/image_object_detection.py b/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/image_object_detection.py index 5180c12ece..4f45ab1745 100644 --- a/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/image_object_detection.py +++ b/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/image_object_detection.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,16 +18,19 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1.schema.predict.instance", - manifest={"ImageObjectDetectionPredictionInstance",}, + manifest={ + "ImageObjectDetectionPredictionInstance", + }, ) class ImageObjectDetectionPredictionInstance(proto.Message): r"""Prediction input format for Image Object Detection. + Attributes: content (str): - The image bytes or GCS URI to make the - prediction on. + The image bytes or Cloud Storage URI to make + the prediction on. mime_type (str): The MIME type of the content of the image. Only the images in below listed MIME types are @@ -40,8 +43,14 @@ class ImageObjectDetectionPredictionInstance(proto.Message): - image/vnd.microsoft.icon """ - content = proto.Field(proto.STRING, number=1,) - mime_type = proto.Field(proto.STRING, number=2,) + content = proto.Field( + proto.STRING, + number=1, + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/image_segmentation.py b/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/image_segmentation.py index 0591b17208..0f18a3e7bb 100644 --- a/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/image_segmentation.py +++ b/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/image_segmentation.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1.schema.predict.instance", - manifest={"ImageSegmentationPredictionInstance",}, + manifest={ + "ImageSegmentationPredictionInstance", + }, ) class ImageSegmentationPredictionInstance(proto.Message): r"""Prediction input format for Image Segmentation. + Attributes: content (str): The image bytes to make the predictions on. @@ -34,8 +37,14 @@ class ImageSegmentationPredictionInstance(proto.Message): - image/png """ - content = proto.Field(proto.STRING, number=1,) - mime_type = proto.Field(proto.STRING, number=2,) + content = proto.Field( + proto.STRING, + number=1, + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/text_classification.py b/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/text_classification.py index aafbcac3e7..27c3487fb2 100644 --- a/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/text_classification.py +++ b/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/text_classification.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1.schema.predict.instance", - manifest={"TextClassificationPredictionInstance",}, + manifest={ + "TextClassificationPredictionInstance", + }, ) class TextClassificationPredictionInstance(proto.Message): r"""Prediction input format for Text Classification. + Attributes: content (str): The text snippet to make the predictions on. @@ -33,8 +36,14 @@ class TextClassificationPredictionInstance(proto.Message): - text/plain """ - content = proto.Field(proto.STRING, number=1,) - mime_type = proto.Field(proto.STRING, number=2,) + content = proto.Field( + proto.STRING, + number=1, + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/text_extraction.py b/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/text_extraction.py index ba1997ba05..88a9e61c67 100644 --- a/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/text_extraction.py +++ b/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/text_extraction.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1.schema.predict.instance", - manifest={"TextExtractionPredictionInstance",}, + manifest={ + "TextExtractionPredictionInstance", + }, ) class TextExtractionPredictionInstance(proto.Message): r"""Prediction input format for Text Extraction. + Attributes: content (str): The text snippet to make the predictions on. @@ -36,15 +39,24 @@ class TextExtractionPredictionInstance(proto.Message): If a key is provided, the batch prediction result will by mapped to this key. If omitted, then the batch prediction result will contain - the entire input instance. AI Platform will not + the entire input instance. Vertex AI will not check if keys in the request are duplicates, so it is up to the caller to ensure the keys are unique. """ - content = proto.Field(proto.STRING, number=1,) - mime_type = proto.Field(proto.STRING, number=2,) - key = proto.Field(proto.STRING, number=3,) + content = proto.Field( + proto.STRING, + number=1, + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) + key = proto.Field( + proto.STRING, + number=3, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/text_sentiment.py b/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/text_sentiment.py index d86d58f40f..7907d6e31c 100644 --- a/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/text_sentiment.py +++ b/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/text_sentiment.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1.schema.predict.instance", - manifest={"TextSentimentPredictionInstance",}, + manifest={ + "TextSentimentPredictionInstance", + }, ) class TextSentimentPredictionInstance(proto.Message): r"""Prediction input format for Text Sentiment. + Attributes: content (str): The text snippet to make the predictions on. @@ -33,8 +36,14 @@ class TextSentimentPredictionInstance(proto.Message): - text/plain """ - content = proto.Field(proto.STRING, number=1,) - mime_type = proto.Field(proto.STRING, number=2,) + content = proto.Field( + proto.STRING, + number=1, + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/video_action_recognition.py b/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/video_action_recognition.py index d8db889408..c11836967d 100644 --- a/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/video_action_recognition.py +++ b/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/video_action_recognition.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1.schema.predict.instance", - manifest={"VideoActionRecognitionPredictionInstance",}, + manifest={ + "VideoActionRecognitionPredictionInstance", + }, ) class VideoActionRecognitionPredictionInstance(proto.Message): r"""Prediction input format for Video Action Recognition. + Attributes: content (str): The Google Cloud Storage location of the @@ -49,10 +52,22 @@ class VideoActionRecognitionPredictionInstance(proto.Message): is allowed, which means the end of the video. """ - content = proto.Field(proto.STRING, number=1,) - mime_type = proto.Field(proto.STRING, number=2,) - time_segment_start = proto.Field(proto.STRING, number=3,) - time_segment_end = proto.Field(proto.STRING, number=4,) + content = proto.Field( + proto.STRING, + number=1, + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) + time_segment_start = proto.Field( + proto.STRING, + number=3, + ) + time_segment_end = proto.Field( + proto.STRING, + number=4, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/video_classification.py b/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/video_classification.py index f03e673f90..30dbf42ca5 100644 --- a/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/video_classification.py +++ b/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/video_classification.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1.schema.predict.instance", - manifest={"VideoClassificationPredictionInstance",}, + manifest={ + "VideoClassificationPredictionInstance", + }, ) class VideoClassificationPredictionInstance(proto.Message): r"""Prediction input format for Video Classification. + Attributes: content (str): The Google Cloud Storage location of the @@ -49,10 +52,22 @@ class VideoClassificationPredictionInstance(proto.Message): is allowed, which means the end of the video. """ - content = proto.Field(proto.STRING, number=1,) - mime_type = proto.Field(proto.STRING, number=2,) - time_segment_start = proto.Field(proto.STRING, number=3,) - time_segment_end = proto.Field(proto.STRING, number=4,) + content = proto.Field( + proto.STRING, + number=1, + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) + time_segment_start = proto.Field( + proto.STRING, + number=3, + ) + time_segment_end = proto.Field( + proto.STRING, + number=4, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/video_object_tracking.py b/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/video_object_tracking.py index 5df1e42eb5..3bf0c6a275 100644 --- a/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/video_object_tracking.py +++ b/google/cloud/aiplatform/v1/schema/predict/instance_v1/types/video_object_tracking.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1.schema.predict.instance", - manifest={"VideoObjectTrackingPredictionInstance",}, + manifest={ + "VideoObjectTrackingPredictionInstance", + }, ) class VideoObjectTrackingPredictionInstance(proto.Message): r"""Prediction input format for Video Object Tracking. + Attributes: content (str): The Google Cloud Storage location of the @@ -49,10 +52,22 @@ class VideoObjectTrackingPredictionInstance(proto.Message): is allowed, which means the end of the video. """ - content = proto.Field(proto.STRING, number=1,) - mime_type = proto.Field(proto.STRING, number=2,) - time_segment_start = proto.Field(proto.STRING, number=3,) - time_segment_end = proto.Field(proto.STRING, number=4,) + content = proto.Field( + proto.STRING, + number=1, + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) + time_segment_start = proto.Field( + proto.STRING, + number=3, + ) + time_segment_end = proto.Field( + proto.STRING, + number=4, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1/schema/predict/params/__init__.py b/google/cloud/aiplatform/v1/schema/predict/params/__init__.py index a55ff6dc0f..803e6dd857 100644 --- a/google/cloud/aiplatform/v1/schema/predict/params/__init__.py +++ b/google/cloud/aiplatform/v1/schema/predict/params/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform/v1/schema/predict/params_v1/__init__.py b/google/cloud/aiplatform/v1/schema/predict/params_v1/__init__.py index dcf74bb7a0..fd80646afd 100644 --- a/google/cloud/aiplatform/v1/schema/predict/params_v1/__init__.py +++ b/google/cloud/aiplatform/v1/schema/predict/params_v1/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform/v1/schema/predict/params_v1/types/__init__.py b/google/cloud/aiplatform/v1/schema/predict/params_v1/types/__init__.py index 26997a8d81..135f3bff54 100644 --- a/google/cloud/aiplatform/v1/schema/predict/params_v1/types/__init__.py +++ b/google/cloud/aiplatform/v1/schema/predict/params_v1/types/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,12 +13,24 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from .image_classification import ImageClassificationPredictionParams -from .image_object_detection import ImageObjectDetectionPredictionParams -from .image_segmentation import ImageSegmentationPredictionParams -from .video_action_recognition import VideoActionRecognitionPredictionParams -from .video_classification import VideoClassificationPredictionParams -from .video_object_tracking import VideoObjectTrackingPredictionParams +from .image_classification import ( + ImageClassificationPredictionParams, +) +from .image_object_detection import ( + ImageObjectDetectionPredictionParams, +) +from .image_segmentation import ( + ImageSegmentationPredictionParams, +) +from .video_action_recognition import ( + VideoActionRecognitionPredictionParams, +) +from .video_classification import ( + VideoClassificationPredictionParams, +) +from .video_object_tracking import ( + VideoObjectTrackingPredictionParams, +) __all__ = ( "ImageClassificationPredictionParams", diff --git a/google/cloud/aiplatform/v1/schema/predict/params_v1/types/image_classification.py b/google/cloud/aiplatform/v1/schema/predict/params_v1/types/image_classification.py index e042f39854..dfa355995e 100644 --- a/google/cloud/aiplatform/v1/schema/predict/params_v1/types/image_classification.py +++ b/google/cloud/aiplatform/v1/schema/predict/params_v1/types/image_classification.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1.schema.predict.params", - manifest={"ImageClassificationPredictionParams",}, + manifest={ + "ImageClassificationPredictionParams", + }, ) class ImageClassificationPredictionParams(proto.Message): r"""Prediction model parameters for Image Classification. + Attributes: confidence_threshold (float): The Model only returns predictions with at @@ -36,8 +39,14 @@ class ImageClassificationPredictionParams(proto.Message): return fewer predictions. Default value is 10. """ - confidence_threshold = proto.Field(proto.FLOAT, number=1,) - max_predictions = proto.Field(proto.INT32, number=2,) + confidence_threshold = proto.Field( + proto.FLOAT, + number=1, + ) + max_predictions = proto.Field( + proto.INT32, + number=2, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1/schema/predict/params_v1/types/image_object_detection.py b/google/cloud/aiplatform/v1/schema/predict/params_v1/types/image_object_detection.py index 4ca8404d61..7ee9d4046f 100644 --- a/google/cloud/aiplatform/v1/schema/predict/params_v1/types/image_object_detection.py +++ b/google/cloud/aiplatform/v1/schema/predict/params_v1/types/image_object_detection.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1.schema.predict.params", - manifest={"ImageObjectDetectionPredictionParams",}, + manifest={ + "ImageObjectDetectionPredictionParams", + }, ) class ImageObjectDetectionPredictionParams(proto.Message): r"""Prediction model parameters for Image Object Detection. + Attributes: confidence_threshold (float): The Model only returns predictions with at @@ -37,8 +40,14 @@ class ImageObjectDetectionPredictionParams(proto.Message): value is 10. """ - confidence_threshold = proto.Field(proto.FLOAT, number=1,) - max_predictions = proto.Field(proto.INT32, number=2,) + confidence_threshold = proto.Field( + proto.FLOAT, + number=1, + ) + max_predictions = proto.Field( + proto.INT32, + number=2, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1/schema/predict/params_v1/types/image_segmentation.py b/google/cloud/aiplatform/v1/schema/predict/params_v1/types/image_segmentation.py index 6a2102b808..a346c8b185 100644 --- a/google/cloud/aiplatform/v1/schema/predict/params_v1/types/image_segmentation.py +++ b/google/cloud/aiplatform/v1/schema/predict/params_v1/types/image_segmentation.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1.schema.predict.params", - manifest={"ImageSegmentationPredictionParams",}, + manifest={ + "ImageSegmentationPredictionParams", + }, ) class ImageSegmentationPredictionParams(proto.Message): r"""Prediction model parameters for Image Segmentation. + Attributes: confidence_threshold (float): When the model predicts category of pixels of @@ -33,7 +36,10 @@ class ImageSegmentationPredictionParams(proto.Message): background. Default value is 0.5. """ - confidence_threshold = proto.Field(proto.FLOAT, number=1,) + confidence_threshold = proto.Field( + proto.FLOAT, + number=1, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1/schema/predict/params_v1/types/video_action_recognition.py b/google/cloud/aiplatform/v1/schema/predict/params_v1/types/video_action_recognition.py index f09d2058e3..4b85f006ae 100644 --- a/google/cloud/aiplatform/v1/schema/predict/params_v1/types/video_action_recognition.py +++ b/google/cloud/aiplatform/v1/schema/predict/params_v1/types/video_action_recognition.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1.schema.predict.params", - manifest={"VideoActionRecognitionPredictionParams",}, + manifest={ + "VideoActionRecognitionPredictionParams", + }, ) class VideoActionRecognitionPredictionParams(proto.Message): r"""Prediction model parameters for Video Action Recognition. + Attributes: confidence_threshold (float): The Model only returns predictions with at @@ -37,8 +40,14 @@ class VideoActionRecognitionPredictionParams(proto.Message): Default value is 50. """ - confidence_threshold = proto.Field(proto.FLOAT, number=1,) - max_predictions = proto.Field(proto.INT32, number=2,) + confidence_threshold = proto.Field( + proto.FLOAT, + number=1, + ) + max_predictions = proto.Field( + proto.INT32, + number=2, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1/schema/predict/params_v1/types/video_classification.py b/google/cloud/aiplatform/v1/schema/predict/params_v1/types/video_classification.py index 1ab180bbe2..ea1748191d 100644 --- a/google/cloud/aiplatform/v1/schema/predict/params_v1/types/video_classification.py +++ b/google/cloud/aiplatform/v1/schema/predict/params_v1/types/video_classification.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1.schema.predict.params", - manifest={"VideoClassificationPredictionParams",}, + manifest={ + "VideoClassificationPredictionParams", + }, ) class VideoClassificationPredictionParams(proto.Message): r"""Prediction model parameters for Video Classification. + Attributes: confidence_threshold (float): The Model only returns predictions with at @@ -37,16 +40,16 @@ class VideoClassificationPredictionParams(proto.Message): 10,000. segment_classification (bool): Set to true to request segment-level - classification. AI Platform returns labels and + classification. Vertex AI returns labels and their confidence scores for the entire time segment of the video that user specified in the input instance. Default value is true shot_classification (bool): Set to true to request shot-level - classification. AI Platform determines the + classification. Vertex AI determines the boundaries for each camera shot in the entire time segment of the video that user specified in - the input instance. AI Platform then returns + the input instance. Vertex AI then returns labels and their confidence scores for each detected shot, along with the start and end time of the shot. @@ -57,22 +60,36 @@ class VideoClassificationPredictionParams(proto.Message): Default value is false one_sec_interval_classification (bool): Set to true to request classification for a - video at one-second intervals. AI Platform - returns labels and their confidence scores for - each second of the entire time segment of the - video that user specified in the input WARNING: - Model evaluation is not done for this - classification type, the quality of it depends - on the training data, but there are no metrics - provided to describe that quality. Default value - is false + video at one-second intervals. Vertex AI returns + labels and their confidence scores for each + second of the entire time segment of the video + that user specified in the input WARNING: Model + evaluation is not done for this classification + type, the quality of it depends on the training + data, but there are no metrics provided to + describe that quality. Default value is false """ - confidence_threshold = proto.Field(proto.FLOAT, number=1,) - max_predictions = proto.Field(proto.INT32, number=2,) - segment_classification = proto.Field(proto.BOOL, number=3,) - shot_classification = proto.Field(proto.BOOL, number=4,) - one_sec_interval_classification = proto.Field(proto.BOOL, number=5,) + confidence_threshold = proto.Field( + proto.FLOAT, + number=1, + ) + max_predictions = proto.Field( + proto.INT32, + number=2, + ) + segment_classification = proto.Field( + proto.BOOL, + number=3, + ) + shot_classification = proto.Field( + proto.BOOL, + number=4, + ) + one_sec_interval_classification = proto.Field( + proto.BOOL, + number=5, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1/schema/predict/params_v1/types/video_object_tracking.py b/google/cloud/aiplatform/v1/schema/predict/params_v1/types/video_object_tracking.py index 83dedee1d9..a4cc867a44 100644 --- a/google/cloud/aiplatform/v1/schema/predict/params_v1/types/video_object_tracking.py +++ b/google/cloud/aiplatform/v1/schema/predict/params_v1/types/video_object_tracking.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1.schema.predict.params", - manifest={"VideoObjectTrackingPredictionParams",}, + manifest={ + "VideoObjectTrackingPredictionParams", + }, ) class VideoObjectTrackingPredictionParams(proto.Message): r"""Prediction model parameters for Video Object Tracking. + Attributes: confidence_threshold (float): The Model only returns predictions with at @@ -41,9 +44,18 @@ class VideoObjectTrackingPredictionParams(proto.Message): frame size are returned. Default value is 0.0. """ - confidence_threshold = proto.Field(proto.FLOAT, number=1,) - max_predictions = proto.Field(proto.INT32, number=2,) - min_bounding_box_size = proto.Field(proto.FLOAT, number=3,) + confidence_threshold = proto.Field( + proto.FLOAT, + number=1, + ) + max_predictions = proto.Field( + proto.INT32, + number=2, + ) + min_bounding_box_size = proto.Field( + proto.FLOAT, + number=3, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1/schema/predict/prediction/__init__.py b/google/cloud/aiplatform/v1/schema/predict/prediction/__init__.py index a39dd71937..0bd9e1fc3b 100644 --- a/google/cloud/aiplatform/v1/schema/predict/prediction/__init__.py +++ b/google/cloud/aiplatform/v1/schema/predict/prediction/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform/v1/schema/predict/prediction_v1/__init__.py b/google/cloud/aiplatform/v1/schema/predict/prediction_v1/__init__.py index 866cade4d0..73c5336994 100644 --- a/google/cloud/aiplatform/v1/schema/predict/prediction_v1/__init__.py +++ b/google/cloud/aiplatform/v1/schema/predict/prediction_v1/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/__init__.py b/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/__init__.py index 0bb99636b3..12fc5b9a2f 100644 --- a/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/__init__.py +++ b/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,16 +13,36 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from .classification import ClassificationPredictionResult -from .image_object_detection import ImageObjectDetectionPredictionResult -from .image_segmentation import ImageSegmentationPredictionResult -from .tabular_classification import TabularClassificationPredictionResult -from .tabular_regression import TabularRegressionPredictionResult -from .text_extraction import TextExtractionPredictionResult -from .text_sentiment import TextSentimentPredictionResult -from .video_action_recognition import VideoActionRecognitionPredictionResult -from .video_classification import VideoClassificationPredictionResult -from .video_object_tracking import VideoObjectTrackingPredictionResult +from .classification import ( + ClassificationPredictionResult, +) +from .image_object_detection import ( + ImageObjectDetectionPredictionResult, +) +from .image_segmentation import ( + ImageSegmentationPredictionResult, +) +from .tabular_classification import ( + TabularClassificationPredictionResult, +) +from .tabular_regression import ( + TabularRegressionPredictionResult, +) +from .text_extraction import ( + TextExtractionPredictionResult, +) +from .text_sentiment import ( + TextSentimentPredictionResult, +) +from .video_action_recognition import ( + VideoActionRecognitionPredictionResult, +) +from .video_classification import ( + VideoClassificationPredictionResult, +) +from .video_object_tracking import ( + VideoObjectTrackingPredictionResult, +) __all__ = ( "ClassificationPredictionResult", diff --git a/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/classification.py b/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/classification.py index 490d81e91d..0cfd533f16 100644 --- a/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/classification.py +++ b/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/classification.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,17 +18,19 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1.schema.predict.prediction", - manifest={"ClassificationPredictionResult",}, + manifest={ + "ClassificationPredictionResult", + }, ) class ClassificationPredictionResult(proto.Message): r"""Prediction output format for Image and Text Classification. + Attributes: ids (Sequence[int]): The resource IDs of the AnnotationSpecs that - had been identified, ordered by the confidence - score descendingly. + had been identified. display_names (Sequence[str]): The display names of the AnnotationSpecs that had been identified, order matches the IDs. @@ -38,9 +40,18 @@ class ClassificationPredictionResult(proto.Message): confidence. Order matches the Ids. """ - ids = proto.RepeatedField(proto.INT64, number=1,) - display_names = proto.RepeatedField(proto.STRING, number=2,) - confidences = proto.RepeatedField(proto.FLOAT, number=3,) + ids = proto.RepeatedField( + proto.INT64, + number=1, + ) + display_names = proto.RepeatedField( + proto.STRING, + number=2, + ) + confidences = proto.RepeatedField( + proto.FLOAT, + number=3, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/image_object_detection.py b/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/image_object_detection.py index c44d4744a3..c1459a3e3a 100644 --- a/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/image_object_detection.py +++ b/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/image_object_detection.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,12 +20,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1.schema.predict.prediction", - manifest={"ImageObjectDetectionPredictionResult",}, + manifest={ + "ImageObjectDetectionPredictionResult", + }, ) class ImageObjectDetectionPredictionResult(proto.Message): r"""Prediction output format for Image Object Detection. + Attributes: ids (Sequence[int]): The resource IDs of the AnnotationSpecs that @@ -48,10 +51,23 @@ class ImageObjectDetectionPredictionResult(proto.Message): image. """ - ids = proto.RepeatedField(proto.INT64, number=1,) - display_names = proto.RepeatedField(proto.STRING, number=2,) - confidences = proto.RepeatedField(proto.FLOAT, number=3,) - bboxes = proto.RepeatedField(proto.MESSAGE, number=4, message=struct_pb2.ListValue,) + ids = proto.RepeatedField( + proto.INT64, + number=1, + ) + display_names = proto.RepeatedField( + proto.STRING, + number=2, + ) + confidences = proto.RepeatedField( + proto.FLOAT, + number=3, + ) + bboxes = proto.RepeatedField( + proto.MESSAGE, + number=4, + message=struct_pb2.ListValue, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/image_segmentation.py b/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/image_segmentation.py index 4608baeaf6..6c49da5628 100644 --- a/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/image_segmentation.py +++ b/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/image_segmentation.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1.schema.predict.prediction", - manifest={"ImageSegmentationPredictionResult",}, + manifest={ + "ImageSegmentationPredictionResult", + }, ) class ImageSegmentationPredictionResult(proto.Message): r"""Prediction output format for Image Segmentation. + Attributes: category_mask (str): A PNG image where each pixel in the mask @@ -46,8 +49,14 @@ class ImageSegmentationPredictionResult(proto.Message): confidence and white means complete confidence. """ - category_mask = proto.Field(proto.STRING, number=1,) - confidence_mask = proto.Field(proto.STRING, number=2,) + category_mask = proto.Field( + proto.STRING, + number=1, + ) + confidence_mask = proto.Field( + proto.STRING, + number=2, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/tabular_classification.py b/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/tabular_classification.py index 295fd13983..1899462c99 100644 --- a/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/tabular_classification.py +++ b/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/tabular_classification.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1.schema.predict.prediction", - manifest={"TabularClassificationPredictionResult",}, + manifest={ + "TabularClassificationPredictionResult", + }, ) class TabularClassificationPredictionResult(proto.Message): r"""Prediction output format for Tabular Classification. + Attributes: classes (Sequence[str]): The name of the classes being classified, @@ -36,8 +39,14 @@ class TabularClassificationPredictionResult(proto.Message): classes. """ - classes = proto.RepeatedField(proto.STRING, number=1,) - scores = proto.RepeatedField(proto.FLOAT, number=2,) + classes = proto.RepeatedField( + proto.STRING, + number=1, + ) + scores = proto.RepeatedField( + proto.FLOAT, + number=2, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/tabular_regression.py b/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/tabular_regression.py index 76be0023f1..41f4f657b4 100644 --- a/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/tabular_regression.py +++ b/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/tabular_regression.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1.schema.predict.prediction", - manifest={"TabularRegressionPredictionResult",}, + manifest={ + "TabularRegressionPredictionResult", + }, ) class TabularRegressionPredictionResult(proto.Message): r"""Prediction output format for Tabular Regression. + Attributes: value (float): The regression value. @@ -33,9 +36,18 @@ class TabularRegressionPredictionResult(proto.Message): The upper bound of the prediction interval. """ - value = proto.Field(proto.FLOAT, number=1,) - lower_bound = proto.Field(proto.FLOAT, number=2,) - upper_bound = proto.Field(proto.FLOAT, number=3,) + value = proto.Field( + proto.FLOAT, + number=1, + ) + lower_bound = proto.Field( + proto.FLOAT, + number=2, + ) + upper_bound = proto.Field( + proto.FLOAT, + number=3, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/text_extraction.py b/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/text_extraction.py index 601509934a..abff499d75 100644 --- a/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/text_extraction.py +++ b/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/text_extraction.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1.schema.predict.prediction", - manifest={"TextExtractionPredictionResult",}, + manifest={ + "TextExtractionPredictionResult", + }, ) class TextExtractionPredictionResult(proto.Message): r"""Prediction output format for Text Extraction. + Attributes: ids (Sequence[int]): The resource IDs of the AnnotationSpecs that @@ -50,11 +53,26 @@ class TextExtractionPredictionResult(proto.Message): confidence. Order matches the Ids. """ - ids = proto.RepeatedField(proto.INT64, number=1,) - display_names = proto.RepeatedField(proto.STRING, number=2,) - text_segment_start_offsets = proto.RepeatedField(proto.INT64, number=3,) - text_segment_end_offsets = proto.RepeatedField(proto.INT64, number=4,) - confidences = proto.RepeatedField(proto.FLOAT, number=5,) + ids = proto.RepeatedField( + proto.INT64, + number=1, + ) + display_names = proto.RepeatedField( + proto.STRING, + number=2, + ) + text_segment_start_offsets = proto.RepeatedField( + proto.INT64, + number=3, + ) + text_segment_end_offsets = proto.RepeatedField( + proto.INT64, + number=4, + ) + confidences = proto.RepeatedField( + proto.FLOAT, + number=5, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/text_sentiment.py b/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/text_sentiment.py index 663a40ce7c..821ebef472 100644 --- a/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/text_sentiment.py +++ b/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/text_sentiment.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1.schema.predict.prediction", - manifest={"TextSentimentPredictionResult",}, + manifest={ + "TextSentimentPredictionResult", + }, ) class TextSentimentPredictionResult(proto.Message): r"""Prediction output format for Text Sentiment + Attributes: sentiment (int): The integer sentiment labels between 0 @@ -36,7 +39,10 @@ class TextSentimentPredictionResult(proto.Message): (inclusive) and 10 (inclusive). """ - sentiment = proto.Field(proto.INT32, number=1,) + sentiment = proto.Field( + proto.INT32, + number=1, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/video_action_recognition.py b/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/video_action_recognition.py index c23c8b8e07..277d3e5bea 100644 --- a/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/video_action_recognition.py +++ b/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/video_action_recognition.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,12 +21,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1.schema.predict.prediction", - manifest={"VideoActionRecognitionPredictionResult",}, + manifest={ + "VideoActionRecognitionPredictionResult", + }, ) class VideoActionRecognitionPredictionResult(proto.Message): r"""Prediction output format for Video Action Recognition. + Attributes: id (str): The resource ID of the AnnotationSpec that @@ -54,15 +57,29 @@ class VideoActionRecognitionPredictionResult(proto.Message): confidence. """ - id = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) + id = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) time_segment_start = proto.Field( - proto.MESSAGE, number=4, message=duration_pb2.Duration, + proto.MESSAGE, + number=4, + message=duration_pb2.Duration, ) time_segment_end = proto.Field( - proto.MESSAGE, number=5, message=duration_pb2.Duration, + proto.MESSAGE, + number=5, + message=duration_pb2.Duration, + ) + confidence = proto.Field( + proto.MESSAGE, + number=6, + message=wrappers_pb2.FloatValue, ) - confidence = proto.Field(proto.MESSAGE, number=6, message=wrappers_pb2.FloatValue,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/video_classification.py b/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/video_classification.py index 5edacfb81c..5686aa3571 100644 --- a/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/video_classification.py +++ b/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/video_classification.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,12 +21,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1.schema.predict.prediction", - manifest={"VideoClassificationPredictionResult",}, + manifest={ + "VideoClassificationPredictionResult", + }, ) class VideoClassificationPredictionResult(proto.Message): r"""Prediction output format for Video Classification. + Attributes: id (str): The resource ID of the AnnotationSpec that @@ -68,16 +71,33 @@ class VideoClassificationPredictionResult(proto.Message): confidence. """ - id = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) - type_ = proto.Field(proto.STRING, number=3,) + id = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + type_ = proto.Field( + proto.STRING, + number=3, + ) time_segment_start = proto.Field( - proto.MESSAGE, number=4, message=duration_pb2.Duration, + proto.MESSAGE, + number=4, + message=duration_pb2.Duration, ) time_segment_end = proto.Field( - proto.MESSAGE, number=5, message=duration_pb2.Duration, + proto.MESSAGE, + number=5, + message=duration_pb2.Duration, + ) + confidence = proto.Field( + proto.MESSAGE, + number=6, + message=wrappers_pb2.FloatValue, ) - confidence = proto.Field(proto.MESSAGE, number=6, message=wrappers_pb2.FloatValue,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/video_object_tracking.py b/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/video_object_tracking.py index b103c70546..7651895e91 100644 --- a/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/video_object_tracking.py +++ b/google/cloud/aiplatform/v1/schema/predict/prediction_v1/types/video_object_tracking.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,12 +21,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1.schema.predict.prediction", - manifest={"VideoObjectTrackingPredictionResult",}, + manifest={ + "VideoObjectTrackingPredictionResult", + }, ) class VideoObjectTrackingPredictionResult(proto.Message): r"""Prediction output format for Video Object Tracking. + Attributes: id (str): The resource ID of the AnnotationSpec that @@ -84,23 +87,59 @@ class Frame(proto.Message): """ time_offset = proto.Field( - proto.MESSAGE, number=1, message=duration_pb2.Duration, + proto.MESSAGE, + number=1, + message=duration_pb2.Duration, + ) + x_min = proto.Field( + proto.MESSAGE, + number=2, + message=wrappers_pb2.FloatValue, + ) + x_max = proto.Field( + proto.MESSAGE, + number=3, + message=wrappers_pb2.FloatValue, + ) + y_min = proto.Field( + proto.MESSAGE, + number=4, + message=wrappers_pb2.FloatValue, + ) + y_max = proto.Field( + proto.MESSAGE, + number=5, + message=wrappers_pb2.FloatValue, ) - x_min = proto.Field(proto.MESSAGE, number=2, message=wrappers_pb2.FloatValue,) - x_max = proto.Field(proto.MESSAGE, number=3, message=wrappers_pb2.FloatValue,) - y_min = proto.Field(proto.MESSAGE, number=4, message=wrappers_pb2.FloatValue,) - y_max = proto.Field(proto.MESSAGE, number=5, message=wrappers_pb2.FloatValue,) - id = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) + id = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) time_segment_start = proto.Field( - proto.MESSAGE, number=3, message=duration_pb2.Duration, + proto.MESSAGE, + number=3, + message=duration_pb2.Duration, ) time_segment_end = proto.Field( - proto.MESSAGE, number=4, message=duration_pb2.Duration, + proto.MESSAGE, + number=4, + message=duration_pb2.Duration, + ) + confidence = proto.Field( + proto.MESSAGE, + number=5, + message=wrappers_pb2.FloatValue, + ) + frames = proto.RepeatedField( + proto.MESSAGE, + number=6, + message=Frame, ) - confidence = proto.Field(proto.MESSAGE, number=5, message=wrappers_pb2.FloatValue,) - frames = proto.RepeatedField(proto.MESSAGE, number=6, message=Frame,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1/schema/trainingjob/definition/__init__.py b/google/cloud/aiplatform/v1/schema/trainingjob/definition/__init__.py index bd4624d83b..7235407e1c 100644 --- a/google/cloud/aiplatform/v1/schema/trainingjob/definition/__init__.py +++ b/google/cloud/aiplatform/v1/schema/trainingjob/definition/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/__init__.py b/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/__init__.py index 16b66c2fb6..20be708c73 100644 --- a/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/__init__.py +++ b/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/__init__.py b/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/__init__.py index d70e297826..f85b4686a6 100644 --- a/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/__init__.py +++ b/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -57,7 +57,9 @@ AutoMlVideoObjectTracking, AutoMlVideoObjectTrackingInputs, ) -from .export_evaluated_data_items_config import ExportEvaluatedDataItemsConfig +from .export_evaluated_data_items_config import ( + ExportEvaluatedDataItemsConfig, +) __all__ = ( "AutoMlImageClassification", diff --git a/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_image_classification.py b/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_image_classification.py index d8732f8865..5660b377f4 100644 --- a/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_image_classification.py +++ b/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_image_classification.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -38,15 +38,20 @@ class AutoMlImageClassification(proto.Message): """ inputs = proto.Field( - proto.MESSAGE, number=1, message="AutoMlImageClassificationInputs", + proto.MESSAGE, + number=1, + message="AutoMlImageClassificationInputs", ) metadata = proto.Field( - proto.MESSAGE, number=2, message="AutoMlImageClassificationMetadata", + proto.MESSAGE, + number=2, + message="AutoMlImageClassificationMetadata", ) class AutoMlImageClassificationInputs(proto.Message): r""" + Attributes: model_type (google.cloud.aiplatform.v1.schema.trainingjob.definition_v1.types.AutoMlImageClassificationInputs.ModelType): @@ -97,15 +102,32 @@ class ModelType(proto.Enum): MOBILE_TF_VERSATILE_1 = 3 MOBILE_TF_HIGH_ACCURACY_1 = 4 - model_type = proto.Field(proto.ENUM, number=1, enum=ModelType,) - base_model_id = proto.Field(proto.STRING, number=2,) - budget_milli_node_hours = proto.Field(proto.INT64, number=3,) - disable_early_stopping = proto.Field(proto.BOOL, number=4,) - multi_label = proto.Field(proto.BOOL, number=5,) + model_type = proto.Field( + proto.ENUM, + number=1, + enum=ModelType, + ) + base_model_id = proto.Field( + proto.STRING, + number=2, + ) + budget_milli_node_hours = proto.Field( + proto.INT64, + number=3, + ) + disable_early_stopping = proto.Field( + proto.BOOL, + number=4, + ) + multi_label = proto.Field( + proto.BOOL, + number=5, + ) class AutoMlImageClassificationMetadata(proto.Message): r""" + Attributes: cost_milli_node_hours (int): The actual training cost of creating this @@ -124,9 +146,14 @@ class SuccessfulStopReason(proto.Enum): BUDGET_REACHED = 1 MODEL_CONVERGED = 2 - cost_milli_node_hours = proto.Field(proto.INT64, number=1,) + cost_milli_node_hours = proto.Field( + proto.INT64, + number=1, + ) successful_stop_reason = proto.Field( - proto.ENUM, number=2, enum=SuccessfulStopReason, + proto.ENUM, + number=2, + enum=SuccessfulStopReason, ) diff --git a/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_image_object_detection.py b/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_image_object_detection.py index c9284686fd..5e7d6efddd 100644 --- a/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_image_object_detection.py +++ b/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_image_object_detection.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -38,15 +38,20 @@ class AutoMlImageObjectDetection(proto.Message): """ inputs = proto.Field( - proto.MESSAGE, number=1, message="AutoMlImageObjectDetectionInputs", + proto.MESSAGE, + number=1, + message="AutoMlImageObjectDetectionInputs", ) metadata = proto.Field( - proto.MESSAGE, number=2, message="AutoMlImageObjectDetectionMetadata", + proto.MESSAGE, + number=2, + message="AutoMlImageObjectDetectionMetadata", ) class AutoMlImageObjectDetectionInputs(proto.Message): r""" + Attributes: model_type (google.cloud.aiplatform.v1.schema.trainingjob.definition_v1.types.AutoMlImageObjectDetectionInputs.ModelType): @@ -86,13 +91,24 @@ class ModelType(proto.Enum): MOBILE_TF_VERSATILE_1 = 4 MOBILE_TF_HIGH_ACCURACY_1 = 5 - model_type = proto.Field(proto.ENUM, number=1, enum=ModelType,) - budget_milli_node_hours = proto.Field(proto.INT64, number=2,) - disable_early_stopping = proto.Field(proto.BOOL, number=3,) + model_type = proto.Field( + proto.ENUM, + number=1, + enum=ModelType, + ) + budget_milli_node_hours = proto.Field( + proto.INT64, + number=2, + ) + disable_early_stopping = proto.Field( + proto.BOOL, + number=3, + ) class AutoMlImageObjectDetectionMetadata(proto.Message): r""" + Attributes: cost_milli_node_hours (int): The actual training cost of creating this @@ -111,9 +127,14 @@ class SuccessfulStopReason(proto.Enum): BUDGET_REACHED = 1 MODEL_CONVERGED = 2 - cost_milli_node_hours = proto.Field(proto.INT64, number=1,) + cost_milli_node_hours = proto.Field( + proto.INT64, + number=1, + ) successful_stop_reason = proto.Field( - proto.ENUM, number=2, enum=SuccessfulStopReason, + proto.ENUM, + number=2, + enum=SuccessfulStopReason, ) diff --git a/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_image_segmentation.py b/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_image_segmentation.py index ccd2449ccd..c9cd437303 100644 --- a/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_image_segmentation.py +++ b/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_image_segmentation.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -38,15 +38,20 @@ class AutoMlImageSegmentation(proto.Message): """ inputs = proto.Field( - proto.MESSAGE, number=1, message="AutoMlImageSegmentationInputs", + proto.MESSAGE, + number=1, + message="AutoMlImageSegmentationInputs", ) metadata = proto.Field( - proto.MESSAGE, number=2, message="AutoMlImageSegmentationMetadata", + proto.MESSAGE, + number=2, + message="AutoMlImageSegmentationMetadata", ) class AutoMlImageSegmentationInputs(proto.Message): r""" + Attributes: model_type (google.cloud.aiplatform.v1.schema.trainingjob.definition_v1.types.AutoMlImageSegmentationInputs.ModelType): @@ -80,13 +85,24 @@ class ModelType(proto.Enum): CLOUD_LOW_ACCURACY_1 = 2 MOBILE_TF_LOW_LATENCY_1 = 3 - model_type = proto.Field(proto.ENUM, number=1, enum=ModelType,) - budget_milli_node_hours = proto.Field(proto.INT64, number=2,) - base_model_id = proto.Field(proto.STRING, number=3,) + model_type = proto.Field( + proto.ENUM, + number=1, + enum=ModelType, + ) + budget_milli_node_hours = proto.Field( + proto.INT64, + number=2, + ) + base_model_id = proto.Field( + proto.STRING, + number=3, + ) class AutoMlImageSegmentationMetadata(proto.Message): r""" + Attributes: cost_milli_node_hours (int): The actual training cost of creating this @@ -105,9 +121,14 @@ class SuccessfulStopReason(proto.Enum): BUDGET_REACHED = 1 MODEL_CONVERGED = 2 - cost_milli_node_hours = proto.Field(proto.INT64, number=1,) + cost_milli_node_hours = proto.Field( + proto.INT64, + number=1, + ) successful_stop_reason = proto.Field( - proto.ENUM, number=2, enum=SuccessfulStopReason, + proto.ENUM, + number=2, + enum=SuccessfulStopReason, ) diff --git a/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_tables.py b/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_tables.py index f05b633c87..bbcfabac75 100644 --- a/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_tables.py +++ b/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_tables.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -22,12 +22,17 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1.schema.trainingjob.definition", - manifest={"AutoMlTables", "AutoMlTablesInputs", "AutoMlTablesMetadata",}, + manifest={ + "AutoMlTables", + "AutoMlTablesInputs", + "AutoMlTablesMetadata", + }, ) class AutoMlTables(proto.Message): r"""A TrainingJob that trains and uploads an AutoML Tables Model. + Attributes: inputs (google.cloud.aiplatform.v1.schema.trainingjob.definition_v1.types.AutoMlTablesInputs): The input parameters of this TrainingJob. @@ -35,21 +40,41 @@ class AutoMlTables(proto.Message): The metadata information. """ - inputs = proto.Field(proto.MESSAGE, number=1, message="AutoMlTablesInputs",) - metadata = proto.Field(proto.MESSAGE, number=2, message="AutoMlTablesMetadata",) + inputs = proto.Field( + proto.MESSAGE, + number=1, + message="AutoMlTablesInputs", + ) + metadata = proto.Field( + proto.MESSAGE, + number=2, + message="AutoMlTablesMetadata", + ) class AutoMlTablesInputs(proto.Message): r""" + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: optimization_objective_recall_value (float): Required when optimization_objective is "maximize-precision-at-recall". Must be between 0 and 1, inclusive. + + This field is a member of `oneof`_ ``additional_optimization_objective_config``. optimization_objective_precision_value (float): Required when optimization_objective is "maximize-recall-at-precision". Must be between 0 and 1, inclusive. + + This field is a member of `oneof`_ ``additional_optimization_objective_config``. prediction_type (str): The type of prediction the Model is to produce. "classification" - Predict one out of @@ -86,9 +111,9 @@ class AutoMlTablesInputs(proto.Message): operating characteristic (ROC) curve. "minimize-log-loss" - Minimize log loss. "maximize-au-prc" - Maximize the area under - the precision-recall curve. "maximize- - precision-at-recall" - Maximize precision for a - specified + the precision-recall curve. + "maximize-precision-at-recall" - Maximize + precision for a specified recall value. "maximize-recall-at-precision" - Maximize recall for a specified precision value. @@ -96,11 +121,11 @@ class AutoMlTablesInputs(proto.Message): "minimize-log-loss" (default) - Minimize log loss. regression: - "minimize-rmse" (default) - Minimize root- - mean-squared error (RMSE). "minimize-mae" - - Minimize mean-absolute error (MAE). "minimize- - rmsle" - Minimize root-mean-squared log error - (RMSLE). + "minimize-rmse" (default) - Minimize + root-mean-squared error (RMSE). "minimize-mae" + - Minimize mean-absolute error (MAE). + "minimize-rmsle" - Minimize root-mean-squared + log error (RMSLE). train_budget_milli_node_hours (int): Required. The train budget of creating this model, expressed in milli node hours i.e. 1,000 @@ -139,27 +164,46 @@ class AutoMlTablesInputs(proto.Message): predictions to a BigQuery table. If this configuration is absent, then the export is not performed. + additional_experiments (Sequence[str]): + Additional experiment flags for the Tables + training pipeline. """ class Transformation(proto.Message): r""" + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: auto (google.cloud.aiplatform.v1.schema.trainingjob.definition_v1.types.AutoMlTablesInputs.Transformation.AutoTransformation): + This field is a member of `oneof`_ ``transformation_detail``. numeric (google.cloud.aiplatform.v1.schema.trainingjob.definition_v1.types.AutoMlTablesInputs.Transformation.NumericTransformation): + This field is a member of `oneof`_ ``transformation_detail``. categorical (google.cloud.aiplatform.v1.schema.trainingjob.definition_v1.types.AutoMlTablesInputs.Transformation.CategoricalTransformation): + This field is a member of `oneof`_ ``transformation_detail``. timestamp (google.cloud.aiplatform.v1.schema.trainingjob.definition_v1.types.AutoMlTablesInputs.Transformation.TimestampTransformation): + This field is a member of `oneof`_ ``transformation_detail``. text (google.cloud.aiplatform.v1.schema.trainingjob.definition_v1.types.AutoMlTablesInputs.Transformation.TextTransformation): + This field is a member of `oneof`_ ``transformation_detail``. repeated_numeric (google.cloud.aiplatform.v1.schema.trainingjob.definition_v1.types.AutoMlTablesInputs.Transformation.NumericArrayTransformation): + This field is a member of `oneof`_ ``transformation_detail``. repeated_categorical (google.cloud.aiplatform.v1.schema.trainingjob.definition_v1.types.AutoMlTablesInputs.Transformation.CategoricalArrayTransformation): + This field is a member of `oneof`_ ``transformation_detail``. repeated_text (google.cloud.aiplatform.v1.schema.trainingjob.definition_v1.types.AutoMlTablesInputs.Transformation.TextArrayTransformation): + This field is a member of `oneof`_ ``transformation_detail``. """ class AutoTransformation(proto.Message): @@ -171,7 +215,10 @@ class AutoTransformation(proto.Message): """ - column_name = proto.Field(proto.STRING, number=1,) + column_name = proto.Field( + proto.STRING, + number=1, + ) class NumericTransformation(proto.Message): r"""Training pipeline will perform following transformation functions. @@ -197,8 +244,14 @@ class NumericTransformation(proto.Message): from trainining data. """ - column_name = proto.Field(proto.STRING, number=1,) - invalid_values_allowed = proto.Field(proto.BOOL, number=2,) + column_name = proto.Field( + proto.STRING, + number=1, + ) + invalid_values_allowed = proto.Field( + proto.BOOL, + number=2, + ) class CategoricalTransformation(proto.Message): r"""Training pipeline will perform following transformation functions. @@ -216,7 +269,10 @@ class CategoricalTransformation(proto.Message): """ - column_name = proto.Field(proto.STRING, number=1,) + column_name = proto.Field( + proto.STRING, + number=1, + ) class TimestampTransformation(proto.Message): r"""Training pipeline will perform following transformation functions. @@ -253,9 +309,18 @@ class TimestampTransformation(proto.Message): from trainining data. """ - column_name = proto.Field(proto.STRING, number=1,) - time_format = proto.Field(proto.STRING, number=2,) - invalid_values_allowed = proto.Field(proto.BOOL, number=3,) + column_name = proto.Field( + proto.STRING, + number=1, + ) + time_format = proto.Field( + proto.STRING, + number=2, + ) + invalid_values_allowed = proto.Field( + proto.BOOL, + number=3, + ) class TextTransformation(proto.Message): r"""Training pipeline will perform following transformation functions. @@ -275,7 +340,10 @@ class TextTransformation(proto.Message): """ - column_name = proto.Field(proto.STRING, number=1,) + column_name = proto.Field( + proto.STRING, + number=1, + ) class NumericArrayTransformation(proto.Message): r"""Treats the column as numerical array and performs following @@ -296,8 +364,14 @@ class NumericArrayTransformation(proto.Message): from trainining data. """ - column_name = proto.Field(proto.STRING, number=1,) - invalid_values_allowed = proto.Field(proto.BOOL, number=2,) + column_name = proto.Field( + proto.STRING, + number=1, + ) + invalid_values_allowed = proto.Field( + proto.BOOL, + number=2, + ) class CategoricalArrayTransformation(proto.Message): r"""Treats the column as categorical array and performs following @@ -314,7 +388,10 @@ class CategoricalArrayTransformation(proto.Message): """ - column_name = proto.Field(proto.STRING, number=1,) + column_name = proto.Field( + proto.STRING, + number=1, + ) class TextArrayTransformation(proto.Message): r"""Treats the column as text array and performs following @@ -330,7 +407,10 @@ class TextArrayTransformation(proto.Message): """ - column_name = proto.Field(proto.STRING, number=1,) + column_name = proto.Field( + proto.STRING, + number=1, + ) auto = proto.Field( proto.MESSAGE, @@ -382,29 +462,58 @@ class TextArrayTransformation(proto.Message): ) optimization_objective_recall_value = proto.Field( - proto.FLOAT, number=5, oneof="additional_optimization_objective_config", + proto.FLOAT, + number=5, + oneof="additional_optimization_objective_config", ) optimization_objective_precision_value = proto.Field( - proto.FLOAT, number=6, oneof="additional_optimization_objective_config", + proto.FLOAT, + number=6, + oneof="additional_optimization_objective_config", + ) + prediction_type = proto.Field( + proto.STRING, + number=1, + ) + target_column = proto.Field( + proto.STRING, + number=2, ) - prediction_type = proto.Field(proto.STRING, number=1,) - target_column = proto.Field(proto.STRING, number=2,) transformations = proto.RepeatedField( - proto.MESSAGE, number=3, message=Transformation, + proto.MESSAGE, + number=3, + message=Transformation, + ) + optimization_objective = proto.Field( + proto.STRING, + number=4, + ) + train_budget_milli_node_hours = proto.Field( + proto.INT64, + number=7, + ) + disable_early_stopping = proto.Field( + proto.BOOL, + number=8, + ) + weight_column_name = proto.Field( + proto.STRING, + number=9, ) - optimization_objective = proto.Field(proto.STRING, number=4,) - train_budget_milli_node_hours = proto.Field(proto.INT64, number=7,) - disable_early_stopping = proto.Field(proto.BOOL, number=8,) - weight_column_name = proto.Field(proto.STRING, number=9,) export_evaluated_data_items_config = proto.Field( proto.MESSAGE, number=10, message=gcastd_export_evaluated_data_items_config.ExportEvaluatedDataItemsConfig, ) + additional_experiments = proto.RepeatedField( + proto.STRING, + number=11, + ) class AutoMlTablesMetadata(proto.Message): r"""Model metadata specific to AutoML Tables. + Attributes: train_cost_milli_node_hours (int): Output only. The actual training cost of the @@ -413,7 +522,10 @@ class AutoMlTablesMetadata(proto.Message): Guaranteed to not exceed the train budget. """ - train_cost_milli_node_hours = proto.Field(proto.INT64, number=1,) + train_cost_milli_node_hours = proto.Field( + proto.INT64, + number=1, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_text_classification.py b/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_text_classification.py index 21014e1b0a..805d83c1e2 100644 --- a/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_text_classification.py +++ b/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_text_classification.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,7 +18,10 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1.schema.trainingjob.definition", - manifest={"AutoMlTextClassification", "AutoMlTextClassificationInputs",}, + manifest={ + "AutoMlTextClassification", + "AutoMlTextClassificationInputs", + }, ) @@ -32,18 +35,24 @@ class AutoMlTextClassification(proto.Message): """ inputs = proto.Field( - proto.MESSAGE, number=1, message="AutoMlTextClassificationInputs", + proto.MESSAGE, + number=1, + message="AutoMlTextClassificationInputs", ) class AutoMlTextClassificationInputs(proto.Message): r""" + Attributes: multi_label (bool): """ - multi_label = proto.Field(proto.BOOL, number=1,) + multi_label = proto.Field( + proto.BOOL, + number=1, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_text_extraction.py b/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_text_extraction.py index e475b1989b..d08f678fca 100644 --- a/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_text_extraction.py +++ b/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_text_extraction.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,7 +18,10 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1.schema.trainingjob.definition", - manifest={"AutoMlTextExtraction", "AutoMlTextExtractionInputs",}, + manifest={ + "AutoMlTextExtraction", + "AutoMlTextExtractionInputs", + }, ) @@ -31,11 +34,15 @@ class AutoMlTextExtraction(proto.Message): The input parameters of this TrainingJob. """ - inputs = proto.Field(proto.MESSAGE, number=1, message="AutoMlTextExtractionInputs",) + inputs = proto.Field( + proto.MESSAGE, + number=1, + message="AutoMlTextExtractionInputs", + ) class AutoMlTextExtractionInputs(proto.Message): - r""" """ + r""" """ __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_text_sentiment.py b/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_text_sentiment.py index 373ea85902..bf73cf5144 100644 --- a/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_text_sentiment.py +++ b/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_text_sentiment.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,7 +18,10 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1.schema.trainingjob.definition", - manifest={"AutoMlTextSentiment", "AutoMlTextSentimentInputs",}, + manifest={ + "AutoMlTextSentiment", + "AutoMlTextSentimentInputs", + }, ) @@ -31,11 +34,16 @@ class AutoMlTextSentiment(proto.Message): The input parameters of this TrainingJob. """ - inputs = proto.Field(proto.MESSAGE, number=1, message="AutoMlTextSentimentInputs",) + inputs = proto.Field( + proto.MESSAGE, + number=1, + message="AutoMlTextSentimentInputs", + ) class AutoMlTextSentimentInputs(proto.Message): r""" + Attributes: sentiment_max (int): A sentiment is expressed as an integer @@ -50,7 +58,10 @@ class AutoMlTextSentimentInputs(proto.Message): between 1 and 10 (inclusive). """ - sentiment_max = proto.Field(proto.INT32, number=1,) + sentiment_max = proto.Field( + proto.INT32, + number=1, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_video_action_recognition.py b/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_video_action_recognition.py index f9eefb8c4d..8b97dfc426 100644 --- a/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_video_action_recognition.py +++ b/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_video_action_recognition.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,7 +18,10 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1.schema.trainingjob.definition", - manifest={"AutoMlVideoActionRecognition", "AutoMlVideoActionRecognitionInputs",}, + manifest={ + "AutoMlVideoActionRecognition", + "AutoMlVideoActionRecognitionInputs", + }, ) @@ -32,12 +35,15 @@ class AutoMlVideoActionRecognition(proto.Message): """ inputs = proto.Field( - proto.MESSAGE, number=1, message="AutoMlVideoActionRecognitionInputs", + proto.MESSAGE, + number=1, + message="AutoMlVideoActionRecognitionInputs", ) class AutoMlVideoActionRecognitionInputs(proto.Message): r""" + Attributes: model_type (google.cloud.aiplatform.v1.schema.trainingjob.definition_v1.types.AutoMlVideoActionRecognitionInputs.ModelType): @@ -48,8 +54,14 @@ class ModelType(proto.Enum): MODEL_TYPE_UNSPECIFIED = 0 CLOUD = 1 MOBILE_VERSATILE_1 = 2 + MOBILE_JETSON_VERSATILE_1 = 3 + MOBILE_CORAL_VERSATILE_1 = 4 - model_type = proto.Field(proto.ENUM, number=1, enum=ModelType,) + model_type = proto.Field( + proto.ENUM, + number=1, + enum=ModelType, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_video_classification.py b/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_video_classification.py index a0a4e88195..49b139a3ba 100644 --- a/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_video_classification.py +++ b/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_video_classification.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,7 +18,10 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1.schema.trainingjob.definition", - manifest={"AutoMlVideoClassification", "AutoMlVideoClassificationInputs",}, + manifest={ + "AutoMlVideoClassification", + "AutoMlVideoClassificationInputs", + }, ) @@ -32,12 +35,15 @@ class AutoMlVideoClassification(proto.Message): """ inputs = proto.Field( - proto.MESSAGE, number=1, message="AutoMlVideoClassificationInputs", + proto.MESSAGE, + number=1, + message="AutoMlVideoClassificationInputs", ) class AutoMlVideoClassificationInputs(proto.Message): r""" + Attributes: model_type (google.cloud.aiplatform.v1.schema.trainingjob.definition_v1.types.AutoMlVideoClassificationInputs.ModelType): @@ -50,7 +56,11 @@ class ModelType(proto.Enum): MOBILE_VERSATILE_1 = 2 MOBILE_JETSON_VERSATILE_1 = 3 - model_type = proto.Field(proto.ENUM, number=1, enum=ModelType,) + model_type = proto.Field( + proto.ENUM, + number=1, + enum=ModelType, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_video_object_tracking.py b/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_video_object_tracking.py index 4db3a783cf..c29fcb0161 100644 --- a/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_video_object_tracking.py +++ b/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/automl_video_object_tracking.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,7 +18,10 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1.schema.trainingjob.definition", - manifest={"AutoMlVideoObjectTracking", "AutoMlVideoObjectTrackingInputs",}, + manifest={ + "AutoMlVideoObjectTracking", + "AutoMlVideoObjectTrackingInputs", + }, ) @@ -32,12 +35,15 @@ class AutoMlVideoObjectTracking(proto.Message): """ inputs = proto.Field( - proto.MESSAGE, number=1, message="AutoMlVideoObjectTrackingInputs", + proto.MESSAGE, + number=1, + message="AutoMlVideoObjectTrackingInputs", ) class AutoMlVideoObjectTrackingInputs(proto.Message): r""" + Attributes: model_type (google.cloud.aiplatform.v1.schema.trainingjob.definition_v1.types.AutoMlVideoObjectTrackingInputs.ModelType): @@ -53,7 +59,11 @@ class ModelType(proto.Enum): MOBILE_JETSON_VERSATILE_1 = 5 MOBILE_JETSON_LOW_LATENCY_1 = 6 - model_type = proto.Field(proto.ENUM, number=1, enum=ModelType,) + model_type = proto.Field( + proto.ENUM, + number=1, + enum=ModelType, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/export_evaluated_data_items_config.py b/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/export_evaluated_data_items_config.py index 47d910fefb..d93085ab54 100644 --- a/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/export_evaluated_data_items_config.py +++ b/google/cloud/aiplatform/v1/schema/trainingjob/definition_v1/types/export_evaluated_data_items_config.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,7 +18,9 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1.schema.trainingjob.definition", - manifest={"ExportEvaluatedDataItemsConfig",}, + manifest={ + "ExportEvaluatedDataItemsConfig", + }, ) @@ -33,7 +35,6 @@ class ExportEvaluatedDataItemsConfig(proto.Message): If not specified, then results are exported to the following auto-created BigQuery table: - :export_evaluated_examples__.evaluated_examples override_existing_table (bool): If true and an export destination is @@ -43,8 +44,14 @@ class ExportEvaluatedDataItemsConfig(proto.Message): operation fails. """ - destination_bigquery_uri = proto.Field(proto.STRING, number=1,) - override_existing_table = proto.Field(proto.BOOL, number=2,) + destination_bigquery_uri = proto.Field( + proto.STRING, + number=1, + ) + override_existing_table = proto.Field( + proto.BOOL, + number=2, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1beta1/schema/predict/instance/__init__.py b/google/cloud/aiplatform/v1beta1/schema/predict/instance/__init__.py index 4ddd6e1439..ae404a7377 100644 --- a/google/cloud/aiplatform/v1beta1/schema/predict/instance/__init__.py +++ b/google/cloud/aiplatform/v1beta1/schema/predict/instance/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/__init__.py b/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/__init__.py index fdfe1ca46f..47708ddc7f 100644 --- a/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/__init__.py +++ b/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/__init__.py b/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/__init__.py index 744852e8a3..c36f147d50 100644 --- a/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/__init__.py +++ b/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,15 +13,33 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from .image_classification import ImageClassificationPredictionInstance -from .image_object_detection import ImageObjectDetectionPredictionInstance -from .image_segmentation import ImageSegmentationPredictionInstance -from .text_classification import TextClassificationPredictionInstance -from .text_extraction import TextExtractionPredictionInstance -from .text_sentiment import TextSentimentPredictionInstance -from .video_action_recognition import VideoActionRecognitionPredictionInstance -from .video_classification import VideoClassificationPredictionInstance -from .video_object_tracking import VideoObjectTrackingPredictionInstance +from .image_classification import ( + ImageClassificationPredictionInstance, +) +from .image_object_detection import ( + ImageObjectDetectionPredictionInstance, +) +from .image_segmentation import ( + ImageSegmentationPredictionInstance, +) +from .text_classification import ( + TextClassificationPredictionInstance, +) +from .text_extraction import ( + TextExtractionPredictionInstance, +) +from .text_sentiment import ( + TextSentimentPredictionInstance, +) +from .video_action_recognition import ( + VideoActionRecognitionPredictionInstance, +) +from .video_classification import ( + VideoClassificationPredictionInstance, +) +from .video_object_tracking import ( + VideoObjectTrackingPredictionInstance, +) __all__ = ( "ImageClassificationPredictionInstance", diff --git a/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/image_classification.py b/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/image_classification.py index 4c2154dd90..008a5ee3d9 100644 --- a/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/image_classification.py +++ b/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/image_classification.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,16 +18,19 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1.schema.predict.instance", - manifest={"ImageClassificationPredictionInstance",}, + manifest={ + "ImageClassificationPredictionInstance", + }, ) class ImageClassificationPredictionInstance(proto.Message): r"""Prediction input format for Image Classification. + Attributes: content (str): - The image bytes or GCS URI to make the - prediction on. + The image bytes or Cloud Storage URI to make + the prediction on. mime_type (str): The MIME type of the content of the image. Only the images in below listed MIME types are @@ -40,8 +43,14 @@ class ImageClassificationPredictionInstance(proto.Message): - image/vnd.microsoft.icon """ - content = proto.Field(proto.STRING, number=1,) - mime_type = proto.Field(proto.STRING, number=2,) + content = proto.Field( + proto.STRING, + number=1, + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/image_object_detection.py b/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/image_object_detection.py index d7b41623aa..7ab83116b4 100644 --- a/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/image_object_detection.py +++ b/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/image_object_detection.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,16 +18,19 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1.schema.predict.instance", - manifest={"ImageObjectDetectionPredictionInstance",}, + manifest={ + "ImageObjectDetectionPredictionInstance", + }, ) class ImageObjectDetectionPredictionInstance(proto.Message): r"""Prediction input format for Image Object Detection. + Attributes: content (str): - The image bytes or GCS URI to make the - prediction on. + The image bytes or Cloud Storage URI to make + the prediction on. mime_type (str): The MIME type of the content of the image. Only the images in below listed MIME types are @@ -40,8 +43,14 @@ class ImageObjectDetectionPredictionInstance(proto.Message): - image/vnd.microsoft.icon """ - content = proto.Field(proto.STRING, number=1,) - mime_type = proto.Field(proto.STRING, number=2,) + content = proto.Field( + proto.STRING, + number=1, + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/image_segmentation.py b/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/image_segmentation.py index 13c96535a1..600bfdc427 100644 --- a/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/image_segmentation.py +++ b/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/image_segmentation.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1.schema.predict.instance", - manifest={"ImageSegmentationPredictionInstance",}, + manifest={ + "ImageSegmentationPredictionInstance", + }, ) class ImageSegmentationPredictionInstance(proto.Message): r"""Prediction input format for Image Segmentation. + Attributes: content (str): The image bytes to make the predictions on. @@ -34,8 +37,14 @@ class ImageSegmentationPredictionInstance(proto.Message): - image/png """ - content = proto.Field(proto.STRING, number=1,) - mime_type = proto.Field(proto.STRING, number=2,) + content = proto.Field( + proto.STRING, + number=1, + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/text_classification.py b/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/text_classification.py index 141b031701..e5e505b153 100644 --- a/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/text_classification.py +++ b/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/text_classification.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1.schema.predict.instance", - manifest={"TextClassificationPredictionInstance",}, + manifest={ + "TextClassificationPredictionInstance", + }, ) class TextClassificationPredictionInstance(proto.Message): r"""Prediction input format for Text Classification. + Attributes: content (str): The text snippet to make the predictions on. @@ -33,8 +36,14 @@ class TextClassificationPredictionInstance(proto.Message): - text/plain """ - content = proto.Field(proto.STRING, number=1,) - mime_type = proto.Field(proto.STRING, number=2,) + content = proto.Field( + proto.STRING, + number=1, + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/text_extraction.py b/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/text_extraction.py index 9c393faa73..7ced4e00e0 100644 --- a/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/text_extraction.py +++ b/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/text_extraction.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1.schema.predict.instance", - manifest={"TextExtractionPredictionInstance",}, + manifest={ + "TextExtractionPredictionInstance", + }, ) class TextExtractionPredictionInstance(proto.Message): r"""Prediction input format for Text Extraction. + Attributes: content (str): The text snippet to make the predictions on. @@ -36,15 +39,24 @@ class TextExtractionPredictionInstance(proto.Message): If a key is provided, the batch prediction result will by mapped to this key. If omitted, then the batch prediction result will contain - the entire input instance. AI Platform will not + the entire input instance. Vertex AI will not check if keys in the request are duplicates, so it is up to the caller to ensure the keys are unique. """ - content = proto.Field(proto.STRING, number=1,) - mime_type = proto.Field(proto.STRING, number=2,) - key = proto.Field(proto.STRING, number=3,) + content = proto.Field( + proto.STRING, + number=1, + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) + key = proto.Field( + proto.STRING, + number=3, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/text_sentiment.py b/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/text_sentiment.py index cc530e26b9..694e0a5dec 100644 --- a/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/text_sentiment.py +++ b/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/text_sentiment.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1.schema.predict.instance", - manifest={"TextSentimentPredictionInstance",}, + manifest={ + "TextSentimentPredictionInstance", + }, ) class TextSentimentPredictionInstance(proto.Message): r"""Prediction input format for Text Sentiment. + Attributes: content (str): The text snippet to make the predictions on. @@ -33,8 +36,14 @@ class TextSentimentPredictionInstance(proto.Message): - text/plain """ - content = proto.Field(proto.STRING, number=1,) - mime_type = proto.Field(proto.STRING, number=2,) + content = proto.Field( + proto.STRING, + number=1, + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/video_action_recognition.py b/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/video_action_recognition.py index 921f17b892..f85e5cf17b 100644 --- a/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/video_action_recognition.py +++ b/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/video_action_recognition.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1.schema.predict.instance", - manifest={"VideoActionRecognitionPredictionInstance",}, + manifest={ + "VideoActionRecognitionPredictionInstance", + }, ) class VideoActionRecognitionPredictionInstance(proto.Message): r"""Prediction input format for Video Action Recognition. + Attributes: content (str): The Google Cloud Storage location of the @@ -49,10 +52,22 @@ class VideoActionRecognitionPredictionInstance(proto.Message): is allowed, which means the end of the video. """ - content = proto.Field(proto.STRING, number=1,) - mime_type = proto.Field(proto.STRING, number=2,) - time_segment_start = proto.Field(proto.STRING, number=3,) - time_segment_end = proto.Field(proto.STRING, number=4,) + content = proto.Field( + proto.STRING, + number=1, + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) + time_segment_start = proto.Field( + proto.STRING, + number=3, + ) + time_segment_end = proto.Field( + proto.STRING, + number=4, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/video_classification.py b/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/video_classification.py index f7c58db248..3d64c39aac 100644 --- a/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/video_classification.py +++ b/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/video_classification.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1.schema.predict.instance", - manifest={"VideoClassificationPredictionInstance",}, + manifest={ + "VideoClassificationPredictionInstance", + }, ) class VideoClassificationPredictionInstance(proto.Message): r"""Prediction input format for Video Classification. + Attributes: content (str): The Google Cloud Storage location of the @@ -49,10 +52,22 @@ class VideoClassificationPredictionInstance(proto.Message): is allowed, which means the end of the video. """ - content = proto.Field(proto.STRING, number=1,) - mime_type = proto.Field(proto.STRING, number=2,) - time_segment_start = proto.Field(proto.STRING, number=3,) - time_segment_end = proto.Field(proto.STRING, number=4,) + content = proto.Field( + proto.STRING, + number=1, + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) + time_segment_start = proto.Field( + proto.STRING, + number=3, + ) + time_segment_end = proto.Field( + proto.STRING, + number=4, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/video_object_tracking.py b/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/video_object_tracking.py index 8fd28ed924..4476b8af60 100644 --- a/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/video_object_tracking.py +++ b/google/cloud/aiplatform/v1beta1/schema/predict/instance_v1beta1/types/video_object_tracking.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1.schema.predict.instance", - manifest={"VideoObjectTrackingPredictionInstance",}, + manifest={ + "VideoObjectTrackingPredictionInstance", + }, ) class VideoObjectTrackingPredictionInstance(proto.Message): r"""Prediction input format for Video Object Tracking. + Attributes: content (str): The Google Cloud Storage location of the @@ -49,10 +52,22 @@ class VideoObjectTrackingPredictionInstance(proto.Message): is allowed, which means the end of the video. """ - content = proto.Field(proto.STRING, number=1,) - mime_type = proto.Field(proto.STRING, number=2,) - time_segment_start = proto.Field(proto.STRING, number=3,) - time_segment_end = proto.Field(proto.STRING, number=4,) + content = proto.Field( + proto.STRING, + number=1, + ) + mime_type = proto.Field( + proto.STRING, + number=2, + ) + time_segment_start = proto.Field( + proto.STRING, + number=3, + ) + time_segment_end = proto.Field( + proto.STRING, + number=4, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1beta1/schema/predict/params/__init__.py b/google/cloud/aiplatform/v1beta1/schema/predict/params/__init__.py index 4a5b144b93..1f64628545 100644 --- a/google/cloud/aiplatform/v1beta1/schema/predict/params/__init__.py +++ b/google/cloud/aiplatform/v1beta1/schema/predict/params/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform/v1beta1/schema/predict/params_v1beta1/__init__.py b/google/cloud/aiplatform/v1beta1/schema/predict/params_v1beta1/__init__.py index dcf74bb7a0..fd80646afd 100644 --- a/google/cloud/aiplatform/v1beta1/schema/predict/params_v1beta1/__init__.py +++ b/google/cloud/aiplatform/v1beta1/schema/predict/params_v1beta1/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform/v1beta1/schema/predict/params_v1beta1/types/__init__.py b/google/cloud/aiplatform/v1beta1/schema/predict/params_v1beta1/types/__init__.py index 26997a8d81..135f3bff54 100644 --- a/google/cloud/aiplatform/v1beta1/schema/predict/params_v1beta1/types/__init__.py +++ b/google/cloud/aiplatform/v1beta1/schema/predict/params_v1beta1/types/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,12 +13,24 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from .image_classification import ImageClassificationPredictionParams -from .image_object_detection import ImageObjectDetectionPredictionParams -from .image_segmentation import ImageSegmentationPredictionParams -from .video_action_recognition import VideoActionRecognitionPredictionParams -from .video_classification import VideoClassificationPredictionParams -from .video_object_tracking import VideoObjectTrackingPredictionParams +from .image_classification import ( + ImageClassificationPredictionParams, +) +from .image_object_detection import ( + ImageObjectDetectionPredictionParams, +) +from .image_segmentation import ( + ImageSegmentationPredictionParams, +) +from .video_action_recognition import ( + VideoActionRecognitionPredictionParams, +) +from .video_classification import ( + VideoClassificationPredictionParams, +) +from .video_object_tracking import ( + VideoObjectTrackingPredictionParams, +) __all__ = ( "ImageClassificationPredictionParams", diff --git a/google/cloud/aiplatform/v1beta1/schema/predict/params_v1beta1/types/image_classification.py b/google/cloud/aiplatform/v1beta1/schema/predict/params_v1beta1/types/image_classification.py index ada760e415..9282610720 100644 --- a/google/cloud/aiplatform/v1beta1/schema/predict/params_v1beta1/types/image_classification.py +++ b/google/cloud/aiplatform/v1beta1/schema/predict/params_v1beta1/types/image_classification.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1.schema.predict.params", - manifest={"ImageClassificationPredictionParams",}, + manifest={ + "ImageClassificationPredictionParams", + }, ) class ImageClassificationPredictionParams(proto.Message): r"""Prediction model parameters for Image Classification. + Attributes: confidence_threshold (float): The Model only returns predictions with at @@ -36,8 +39,14 @@ class ImageClassificationPredictionParams(proto.Message): return fewer predictions. Default value is 10. """ - confidence_threshold = proto.Field(proto.FLOAT, number=1,) - max_predictions = proto.Field(proto.INT32, number=2,) + confidence_threshold = proto.Field( + proto.FLOAT, + number=1, + ) + max_predictions = proto.Field( + proto.INT32, + number=2, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1beta1/schema/predict/params_v1beta1/types/image_object_detection.py b/google/cloud/aiplatform/v1beta1/schema/predict/params_v1beta1/types/image_object_detection.py index b160fc8400..381517a2a1 100644 --- a/google/cloud/aiplatform/v1beta1/schema/predict/params_v1beta1/types/image_object_detection.py +++ b/google/cloud/aiplatform/v1beta1/schema/predict/params_v1beta1/types/image_object_detection.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1.schema.predict.params", - manifest={"ImageObjectDetectionPredictionParams",}, + manifest={ + "ImageObjectDetectionPredictionParams", + }, ) class ImageObjectDetectionPredictionParams(proto.Message): r"""Prediction model parameters for Image Object Detection. + Attributes: confidence_threshold (float): The Model only returns predictions with at @@ -37,8 +40,14 @@ class ImageObjectDetectionPredictionParams(proto.Message): value is 10. """ - confidence_threshold = proto.Field(proto.FLOAT, number=1,) - max_predictions = proto.Field(proto.INT32, number=2,) + confidence_threshold = proto.Field( + proto.FLOAT, + number=1, + ) + max_predictions = proto.Field( + proto.INT32, + number=2, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1beta1/schema/predict/params_v1beta1/types/image_segmentation.py b/google/cloud/aiplatform/v1beta1/schema/predict/params_v1beta1/types/image_segmentation.py index 1c1e3cdb2e..92e69a2441 100644 --- a/google/cloud/aiplatform/v1beta1/schema/predict/params_v1beta1/types/image_segmentation.py +++ b/google/cloud/aiplatform/v1beta1/schema/predict/params_v1beta1/types/image_segmentation.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1.schema.predict.params", - manifest={"ImageSegmentationPredictionParams",}, + manifest={ + "ImageSegmentationPredictionParams", + }, ) class ImageSegmentationPredictionParams(proto.Message): r"""Prediction model parameters for Image Segmentation. + Attributes: confidence_threshold (float): When the model predicts category of pixels of @@ -33,7 +36,10 @@ class ImageSegmentationPredictionParams(proto.Message): background. Default value is 0.5. """ - confidence_threshold = proto.Field(proto.FLOAT, number=1,) + confidence_threshold = proto.Field( + proto.FLOAT, + number=1, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1beta1/schema/predict/params_v1beta1/types/video_action_recognition.py b/google/cloud/aiplatform/v1beta1/schema/predict/params_v1beta1/types/video_action_recognition.py index 86afdac15f..3f6e7deca7 100644 --- a/google/cloud/aiplatform/v1beta1/schema/predict/params_v1beta1/types/video_action_recognition.py +++ b/google/cloud/aiplatform/v1beta1/schema/predict/params_v1beta1/types/video_action_recognition.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1.schema.predict.params", - manifest={"VideoActionRecognitionPredictionParams",}, + manifest={ + "VideoActionRecognitionPredictionParams", + }, ) class VideoActionRecognitionPredictionParams(proto.Message): r"""Prediction model parameters for Video Action Recognition. + Attributes: confidence_threshold (float): The Model only returns predictions with at @@ -37,8 +40,14 @@ class VideoActionRecognitionPredictionParams(proto.Message): Default value is 50. """ - confidence_threshold = proto.Field(proto.FLOAT, number=1,) - max_predictions = proto.Field(proto.INT32, number=2,) + confidence_threshold = proto.Field( + proto.FLOAT, + number=1, + ) + max_predictions = proto.Field( + proto.INT32, + number=2, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1beta1/schema/predict/params_v1beta1/types/video_classification.py b/google/cloud/aiplatform/v1beta1/schema/predict/params_v1beta1/types/video_classification.py index 35ad2ca0ee..6edd0f2402 100644 --- a/google/cloud/aiplatform/v1beta1/schema/predict/params_v1beta1/types/video_classification.py +++ b/google/cloud/aiplatform/v1beta1/schema/predict/params_v1beta1/types/video_classification.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1.schema.predict.params", - manifest={"VideoClassificationPredictionParams",}, + manifest={ + "VideoClassificationPredictionParams", + }, ) class VideoClassificationPredictionParams(proto.Message): r"""Prediction model parameters for Video Classification. + Attributes: confidence_threshold (float): The Model only returns predictions with at @@ -37,16 +40,16 @@ class VideoClassificationPredictionParams(proto.Message): 10,000. segment_classification (bool): Set to true to request segment-level - classification. AI Platform returns labels and + classification. Vertex AI returns labels and their confidence scores for the entire time segment of the video that user specified in the input instance. Default value is true shot_classification (bool): Set to true to request shot-level - classification. AI Platform determines the + classification. Vertex AI determines the boundaries for each camera shot in the entire time segment of the video that user specified in - the input instance. AI Platform then returns + the input instance. Vertex AI then returns labels and their confidence scores for each detected shot, along with the start and end time of the shot. @@ -57,22 +60,36 @@ class VideoClassificationPredictionParams(proto.Message): Default value is false one_sec_interval_classification (bool): Set to true to request classification for a - video at one-second intervals. AI Platform - returns labels and their confidence scores for - each second of the entire time segment of the - video that user specified in the input WARNING: - Model evaluation is not done for this - classification type, the quality of it depends - on the training data, but there are no metrics - provided to describe that quality. Default value - is false + video at one-second intervals. Vertex AI returns + labels and their confidence scores for each + second of the entire time segment of the video + that user specified in the input WARNING: Model + evaluation is not done for this classification + type, the quality of it depends on the training + data, but there are no metrics provided to + describe that quality. Default value is false """ - confidence_threshold = proto.Field(proto.FLOAT, number=1,) - max_predictions = proto.Field(proto.INT32, number=2,) - segment_classification = proto.Field(proto.BOOL, number=3,) - shot_classification = proto.Field(proto.BOOL, number=4,) - one_sec_interval_classification = proto.Field(proto.BOOL, number=5,) + confidence_threshold = proto.Field( + proto.FLOAT, + number=1, + ) + max_predictions = proto.Field( + proto.INT32, + number=2, + ) + segment_classification = proto.Field( + proto.BOOL, + number=3, + ) + shot_classification = proto.Field( + proto.BOOL, + number=4, + ) + one_sec_interval_classification = proto.Field( + proto.BOOL, + number=5, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1beta1/schema/predict/params_v1beta1/types/video_object_tracking.py b/google/cloud/aiplatform/v1beta1/schema/predict/params_v1beta1/types/video_object_tracking.py index b4cd10b795..f81f4738b1 100644 --- a/google/cloud/aiplatform/v1beta1/schema/predict/params_v1beta1/types/video_object_tracking.py +++ b/google/cloud/aiplatform/v1beta1/schema/predict/params_v1beta1/types/video_object_tracking.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1.schema.predict.params", - manifest={"VideoObjectTrackingPredictionParams",}, + manifest={ + "VideoObjectTrackingPredictionParams", + }, ) class VideoObjectTrackingPredictionParams(proto.Message): r"""Prediction model parameters for Video Object Tracking. + Attributes: confidence_threshold (float): The Model only returns predictions with at @@ -41,9 +44,18 @@ class VideoObjectTrackingPredictionParams(proto.Message): frame size are returned. Default value is 0.0. """ - confidence_threshold = proto.Field(proto.FLOAT, number=1,) - max_predictions = proto.Field(proto.INT32, number=2,) - min_bounding_box_size = proto.Field(proto.FLOAT, number=3,) + confidence_threshold = proto.Field( + proto.FLOAT, + number=1, + ) + max_predictions = proto.Field( + proto.INT32, + number=2, + ) + min_bounding_box_size = proto.Field( + proto.FLOAT, + number=3, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1beta1/schema/predict/prediction/__init__.py b/google/cloud/aiplatform/v1beta1/schema/predict/prediction/__init__.py index df5f78f60c..dcb271f09c 100644 --- a/google/cloud/aiplatform/v1beta1/schema/predict/prediction/__init__.py +++ b/google/cloud/aiplatform/v1beta1/schema/predict/prediction/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -36,6 +36,9 @@ from google.cloud.aiplatform.v1beta1.schema.predict.prediction_v1beta1.types.text_sentiment import ( TextSentimentPredictionResult, ) +from google.cloud.aiplatform.v1beta1.schema.predict.prediction_v1beta1.types.time_series_forecasting import ( + TimeSeriesForecastingPredictionResult, +) from google.cloud.aiplatform.v1beta1.schema.predict.prediction_v1beta1.types.video_action_recognition import ( VideoActionRecognitionPredictionResult, ) @@ -54,6 +57,7 @@ "TabularRegressionPredictionResult", "TextExtractionPredictionResult", "TextSentimentPredictionResult", + "TimeSeriesForecastingPredictionResult", "VideoActionRecognitionPredictionResult", "VideoClassificationPredictionResult", "VideoObjectTrackingPredictionResult", diff --git a/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/__init__.py b/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/__init__.py index 866cade4d0..be90457ec5 100644 --- a/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/__init__.py +++ b/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -22,6 +22,7 @@ from .types.tabular_regression import TabularRegressionPredictionResult from .types.text_extraction import TextExtractionPredictionResult from .types.text_sentiment import TextSentimentPredictionResult +from .types.time_series_forecasting import TimeSeriesForecastingPredictionResult from .types.video_action_recognition import VideoActionRecognitionPredictionResult from .types.video_classification import VideoClassificationPredictionResult from .types.video_object_tracking import VideoObjectTrackingPredictionResult @@ -34,6 +35,7 @@ "TabularRegressionPredictionResult", "TextExtractionPredictionResult", "TextSentimentPredictionResult", + "TimeSeriesForecastingPredictionResult", "VideoActionRecognitionPredictionResult", "VideoClassificationPredictionResult", "VideoObjectTrackingPredictionResult", diff --git a/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/__init__.py b/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/__init__.py index 0bb99636b3..582c0bbe12 100644 --- a/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/__init__.py +++ b/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,16 +13,39 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from .classification import ClassificationPredictionResult -from .image_object_detection import ImageObjectDetectionPredictionResult -from .image_segmentation import ImageSegmentationPredictionResult -from .tabular_classification import TabularClassificationPredictionResult -from .tabular_regression import TabularRegressionPredictionResult -from .text_extraction import TextExtractionPredictionResult -from .text_sentiment import TextSentimentPredictionResult -from .video_action_recognition import VideoActionRecognitionPredictionResult -from .video_classification import VideoClassificationPredictionResult -from .video_object_tracking import VideoObjectTrackingPredictionResult +from .classification import ( + ClassificationPredictionResult, +) +from .image_object_detection import ( + ImageObjectDetectionPredictionResult, +) +from .image_segmentation import ( + ImageSegmentationPredictionResult, +) +from .tabular_classification import ( + TabularClassificationPredictionResult, +) +from .tabular_regression import ( + TabularRegressionPredictionResult, +) +from .text_extraction import ( + TextExtractionPredictionResult, +) +from .text_sentiment import ( + TextSentimentPredictionResult, +) +from .time_series_forecasting import ( + TimeSeriesForecastingPredictionResult, +) +from .video_action_recognition import ( + VideoActionRecognitionPredictionResult, +) +from .video_classification import ( + VideoClassificationPredictionResult, +) +from .video_object_tracking import ( + VideoObjectTrackingPredictionResult, +) __all__ = ( "ClassificationPredictionResult", @@ -32,6 +55,7 @@ "TabularRegressionPredictionResult", "TextExtractionPredictionResult", "TextSentimentPredictionResult", + "TimeSeriesForecastingPredictionResult", "VideoActionRecognitionPredictionResult", "VideoClassificationPredictionResult", "VideoObjectTrackingPredictionResult", diff --git a/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/classification.py b/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/classification.py index d37236a5cc..ce41c4e442 100644 --- a/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/classification.py +++ b/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/classification.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,17 +18,19 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1.schema.predict.prediction", - manifest={"ClassificationPredictionResult",}, + manifest={ + "ClassificationPredictionResult", + }, ) class ClassificationPredictionResult(proto.Message): r"""Prediction output format for Image and Text Classification. + Attributes: ids (Sequence[int]): The resource IDs of the AnnotationSpecs that - had been identified, ordered by the confidence - score descendingly. + had been identified. display_names (Sequence[str]): The display names of the AnnotationSpecs that had been identified, order matches the IDs. @@ -38,9 +40,18 @@ class ClassificationPredictionResult(proto.Message): confidence. Order matches the Ids. """ - ids = proto.RepeatedField(proto.INT64, number=1,) - display_names = proto.RepeatedField(proto.STRING, number=2,) - confidences = proto.RepeatedField(proto.FLOAT, number=3,) + ids = proto.RepeatedField( + proto.INT64, + number=1, + ) + display_names = proto.RepeatedField( + proto.STRING, + number=2, + ) + confidences = proto.RepeatedField( + proto.FLOAT, + number=3, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/image_object_detection.py b/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/image_object_detection.py index e1ed4f5c1e..069e92b2b6 100644 --- a/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/image_object_detection.py +++ b/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/image_object_detection.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,12 +20,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1.schema.predict.prediction", - manifest={"ImageObjectDetectionPredictionResult",}, + manifest={ + "ImageObjectDetectionPredictionResult", + }, ) class ImageObjectDetectionPredictionResult(proto.Message): r"""Prediction output format for Image Object Detection. + Attributes: ids (Sequence[int]): The resource IDs of the AnnotationSpecs that @@ -48,10 +51,23 @@ class ImageObjectDetectionPredictionResult(proto.Message): image. """ - ids = proto.RepeatedField(proto.INT64, number=1,) - display_names = proto.RepeatedField(proto.STRING, number=2,) - confidences = proto.RepeatedField(proto.FLOAT, number=3,) - bboxes = proto.RepeatedField(proto.MESSAGE, number=4, message=struct_pb2.ListValue,) + ids = proto.RepeatedField( + proto.INT64, + number=1, + ) + display_names = proto.RepeatedField( + proto.STRING, + number=2, + ) + confidences = proto.RepeatedField( + proto.FLOAT, + number=3, + ) + bboxes = proto.RepeatedField( + proto.MESSAGE, + number=4, + message=struct_pb2.ListValue, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/image_segmentation.py b/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/image_segmentation.py index 538de9f561..7aa51cf2a0 100644 --- a/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/image_segmentation.py +++ b/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/image_segmentation.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1.schema.predict.prediction", - manifest={"ImageSegmentationPredictionResult",}, + manifest={ + "ImageSegmentationPredictionResult", + }, ) class ImageSegmentationPredictionResult(proto.Message): r"""Prediction output format for Image Segmentation. + Attributes: category_mask (str): A PNG image where each pixel in the mask @@ -46,8 +49,14 @@ class ImageSegmentationPredictionResult(proto.Message): confidence and white means complete confidence. """ - category_mask = proto.Field(proto.STRING, number=1,) - confidence_mask = proto.Field(proto.STRING, number=2,) + category_mask = proto.Field( + proto.STRING, + number=1, + ) + confidence_mask = proto.Field( + proto.STRING, + number=2, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/tabular_classification.py b/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/tabular_classification.py index e6673fe360..019c2d74b1 100644 --- a/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/tabular_classification.py +++ b/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/tabular_classification.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1.schema.predict.prediction", - manifest={"TabularClassificationPredictionResult",}, + manifest={ + "TabularClassificationPredictionResult", + }, ) class TabularClassificationPredictionResult(proto.Message): r"""Prediction output format for Tabular Classification. + Attributes: classes (Sequence[str]): The name of the classes being classified, @@ -36,8 +39,14 @@ class TabularClassificationPredictionResult(proto.Message): classes. """ - classes = proto.RepeatedField(proto.STRING, number=1,) - scores = proto.RepeatedField(proto.FLOAT, number=2,) + classes = proto.RepeatedField( + proto.STRING, + number=1, + ) + scores = proto.RepeatedField( + proto.FLOAT, + number=2, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/tabular_regression.py b/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/tabular_regression.py index f8273be054..ffa086d406 100644 --- a/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/tabular_regression.py +++ b/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/tabular_regression.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1.schema.predict.prediction", - manifest={"TabularRegressionPredictionResult",}, + manifest={ + "TabularRegressionPredictionResult", + }, ) class TabularRegressionPredictionResult(proto.Message): r"""Prediction output format for Tabular Regression. + Attributes: value (float): The regression value. @@ -33,9 +36,18 @@ class TabularRegressionPredictionResult(proto.Message): The upper bound of the prediction interval. """ - value = proto.Field(proto.FLOAT, number=1,) - lower_bound = proto.Field(proto.FLOAT, number=2,) - upper_bound = proto.Field(proto.FLOAT, number=3,) + value = proto.Field( + proto.FLOAT, + number=1, + ) + lower_bound = proto.Field( + proto.FLOAT, + number=2, + ) + upper_bound = proto.Field( + proto.FLOAT, + number=3, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/text_extraction.py b/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/text_extraction.py index 1c70ab440b..8f9ca9cf7f 100644 --- a/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/text_extraction.py +++ b/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/text_extraction.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1.schema.predict.prediction", - manifest={"TextExtractionPredictionResult",}, + manifest={ + "TextExtractionPredictionResult", + }, ) class TextExtractionPredictionResult(proto.Message): r"""Prediction output format for Text Extraction. + Attributes: ids (Sequence[int]): The resource IDs of the AnnotationSpecs that @@ -50,11 +53,26 @@ class TextExtractionPredictionResult(proto.Message): confidence. Order matches the Ids. """ - ids = proto.RepeatedField(proto.INT64, number=1,) - display_names = proto.RepeatedField(proto.STRING, number=2,) - text_segment_start_offsets = proto.RepeatedField(proto.INT64, number=3,) - text_segment_end_offsets = proto.RepeatedField(proto.INT64, number=4,) - confidences = proto.RepeatedField(proto.FLOAT, number=5,) + ids = proto.RepeatedField( + proto.INT64, + number=1, + ) + display_names = proto.RepeatedField( + proto.STRING, + number=2, + ) + text_segment_start_offsets = proto.RepeatedField( + proto.INT64, + number=3, + ) + text_segment_end_offsets = proto.RepeatedField( + proto.INT64, + number=4, + ) + confidences = proto.RepeatedField( + proto.FLOAT, + number=5, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/text_sentiment.py b/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/text_sentiment.py index 76ac7392aa..a897d06c2f 100644 --- a/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/text_sentiment.py +++ b/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/text_sentiment.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1.schema.predict.prediction", - manifest={"TextSentimentPredictionResult",}, + manifest={ + "TextSentimentPredictionResult", + }, ) class TextSentimentPredictionResult(proto.Message): r"""Prediction output format for Text Sentiment + Attributes: sentiment (int): The integer sentiment labels between 0 @@ -36,7 +39,10 @@ class TextSentimentPredictionResult(proto.Message): (inclusive) and 10 (inclusive). """ - sentiment = proto.Field(proto.INT32, number=1,) + sentiment = proto.Field( + proto.INT32, + number=1, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/time_series_forecasting.py b/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/time_series_forecasting.py index 38bd8e3c85..eccda58c18 100644 --- a/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/time_series_forecasting.py +++ b/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/time_series_forecasting.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- - -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,13 +13,14 @@ # See the License for the specific language governing permissions and # limitations under the License. # - import proto # type: ignore __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1.schema.predict.prediction", - manifest={"TimeSeriesForecastingPredictionResult",}, + manifest={ + "TimeSeriesForecastingPredictionResult", + }, ) @@ -30,17 +30,12 @@ class TimeSeriesForecastingPredictionResult(proto.Message): Attributes: value (float): The regression value. - lower_bound (float): - The lower bound of the prediction interval. - upper_bound (float): - The upper bound of the prediction interval. """ - value = proto.Field(proto.FLOAT, number=1) - - lower_bound = proto.Field(proto.FLOAT, number=2) - - upper_bound = proto.Field(proto.FLOAT, number=3) + value = proto.Field( + proto.FLOAT, + number=1, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/video_action_recognition.py b/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/video_action_recognition.py index b33184277e..b435c3c0af 100644 --- a/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/video_action_recognition.py +++ b/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/video_action_recognition.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,12 +21,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1.schema.predict.prediction", - manifest={"VideoActionRecognitionPredictionResult",}, + manifest={ + "VideoActionRecognitionPredictionResult", + }, ) class VideoActionRecognitionPredictionResult(proto.Message): r"""Prediction output format for Video Action Recognition. + Attributes: id (str): The resource ID of the AnnotationSpec that @@ -54,15 +57,29 @@ class VideoActionRecognitionPredictionResult(proto.Message): confidence. """ - id = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) + id = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) time_segment_start = proto.Field( - proto.MESSAGE, number=4, message=duration_pb2.Duration, + proto.MESSAGE, + number=4, + message=duration_pb2.Duration, ) time_segment_end = proto.Field( - proto.MESSAGE, number=5, message=duration_pb2.Duration, + proto.MESSAGE, + number=5, + message=duration_pb2.Duration, + ) + confidence = proto.Field( + proto.MESSAGE, + number=6, + message=wrappers_pb2.FloatValue, ) - confidence = proto.Field(proto.MESSAGE, number=6, message=wrappers_pb2.FloatValue,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/video_classification.py b/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/video_classification.py index 3d4abadd6a..38bb28ea11 100644 --- a/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/video_classification.py +++ b/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/video_classification.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,12 +21,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1.schema.predict.prediction", - manifest={"VideoClassificationPredictionResult",}, + manifest={ + "VideoClassificationPredictionResult", + }, ) class VideoClassificationPredictionResult(proto.Message): r"""Prediction output format for Video Classification. + Attributes: id (str): The resource ID of the AnnotationSpec that @@ -68,16 +71,33 @@ class VideoClassificationPredictionResult(proto.Message): confidence. """ - id = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) - type_ = proto.Field(proto.STRING, number=3,) + id = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + type_ = proto.Field( + proto.STRING, + number=3, + ) time_segment_start = proto.Field( - proto.MESSAGE, number=4, message=duration_pb2.Duration, + proto.MESSAGE, + number=4, + message=duration_pb2.Duration, ) time_segment_end = proto.Field( - proto.MESSAGE, number=5, message=duration_pb2.Duration, + proto.MESSAGE, + number=5, + message=duration_pb2.Duration, + ) + confidence = proto.Field( + proto.MESSAGE, + number=6, + message=wrappers_pb2.FloatValue, ) - confidence = proto.Field(proto.MESSAGE, number=6, message=wrappers_pb2.FloatValue,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/video_object_tracking.py b/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/video_object_tracking.py index 9b085f2309..690952e808 100644 --- a/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/video_object_tracking.py +++ b/google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/video_object_tracking.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,12 +21,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1.schema.predict.prediction", - manifest={"VideoObjectTrackingPredictionResult",}, + manifest={ + "VideoObjectTrackingPredictionResult", + }, ) class VideoObjectTrackingPredictionResult(proto.Message): r"""Prediction output format for Video Object Tracking. + Attributes: id (str): The resource ID of the AnnotationSpec that @@ -84,23 +87,59 @@ class Frame(proto.Message): """ time_offset = proto.Field( - proto.MESSAGE, number=1, message=duration_pb2.Duration, + proto.MESSAGE, + number=1, + message=duration_pb2.Duration, + ) + x_min = proto.Field( + proto.MESSAGE, + number=2, + message=wrappers_pb2.FloatValue, + ) + x_max = proto.Field( + proto.MESSAGE, + number=3, + message=wrappers_pb2.FloatValue, + ) + y_min = proto.Field( + proto.MESSAGE, + number=4, + message=wrappers_pb2.FloatValue, + ) + y_max = proto.Field( + proto.MESSAGE, + number=5, + message=wrappers_pb2.FloatValue, ) - x_min = proto.Field(proto.MESSAGE, number=2, message=wrappers_pb2.FloatValue,) - x_max = proto.Field(proto.MESSAGE, number=3, message=wrappers_pb2.FloatValue,) - y_min = proto.Field(proto.MESSAGE, number=4, message=wrappers_pb2.FloatValue,) - y_max = proto.Field(proto.MESSAGE, number=5, message=wrappers_pb2.FloatValue,) - id = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) + id = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) time_segment_start = proto.Field( - proto.MESSAGE, number=3, message=duration_pb2.Duration, + proto.MESSAGE, + number=3, + message=duration_pb2.Duration, ) time_segment_end = proto.Field( - proto.MESSAGE, number=4, message=duration_pb2.Duration, + proto.MESSAGE, + number=4, + message=duration_pb2.Duration, + ) + confidence = proto.Field( + proto.MESSAGE, + number=5, + message=wrappers_pb2.FloatValue, + ) + frames = proto.RepeatedField( + proto.MESSAGE, + number=6, + message=Frame, ) - confidence = proto.Field(proto.MESSAGE, number=5, message=wrappers_pb2.FloatValue,) - frames = proto.RepeatedField(proto.MESSAGE, number=6, message=Frame,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition/__init__.py b/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition/__init__.py index eae6c5d2fa..3e9dbeaae4 100644 --- a/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition/__init__.py +++ b/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -69,6 +69,15 @@ from google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1.types.automl_text_sentiment import ( AutoMlTextSentimentInputs, ) +from google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1.types.automl_time_series_forecasting import ( + AutoMlForecasting, +) +from google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1.types.automl_time_series_forecasting import ( + AutoMlForecastingInputs, +) +from google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1.types.automl_time_series_forecasting import ( + AutoMlForecastingMetadata, +) from google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1.types.automl_video_action_recognition import ( AutoMlVideoActionRecognition, ) @@ -110,6 +119,9 @@ "AutoMlTextExtractionInputs", "AutoMlTextSentiment", "AutoMlTextSentimentInputs", + "AutoMlForecasting", + "AutoMlForecastingInputs", + "AutoMlForecastingMetadata", "AutoMlVideoActionRecognition", "AutoMlVideoActionRecognitionInputs", "AutoMlVideoClassification", diff --git a/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/__init__.py b/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/__init__.py index 16b66c2fb6..c35353f39c 100644 --- a/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/__init__.py +++ b/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -33,6 +33,9 @@ from .types.automl_text_extraction import AutoMlTextExtractionInputs from .types.automl_text_sentiment import AutoMlTextSentiment from .types.automl_text_sentiment import AutoMlTextSentimentInputs +from .types.automl_time_series_forecasting import AutoMlForecasting +from .types.automl_time_series_forecasting import AutoMlForecastingInputs +from .types.automl_time_series_forecasting import AutoMlForecastingMetadata from .types.automl_video_action_recognition import AutoMlVideoActionRecognition from .types.automl_video_action_recognition import AutoMlVideoActionRecognitionInputs from .types.automl_video_classification import AutoMlVideoClassification @@ -42,6 +45,9 @@ from .types.export_evaluated_data_items_config import ExportEvaluatedDataItemsConfig __all__ = ( + "AutoMlForecasting", + "AutoMlForecastingInputs", + "AutoMlForecastingMetadata", "AutoMlImageClassification", "AutoMlImageClassificationInputs", "AutoMlImageClassificationMetadata", diff --git a/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/__init__.py b/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/__init__.py index d70e297826..7de288bc76 100644 --- a/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/__init__.py +++ b/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -45,6 +45,11 @@ AutoMlTextSentiment, AutoMlTextSentimentInputs, ) +from .automl_time_series_forecasting import ( + AutoMlForecasting, + AutoMlForecastingInputs, + AutoMlForecastingMetadata, +) from .automl_video_action_recognition import ( AutoMlVideoActionRecognition, AutoMlVideoActionRecognitionInputs, @@ -57,7 +62,9 @@ AutoMlVideoObjectTracking, AutoMlVideoObjectTrackingInputs, ) -from .export_evaluated_data_items_config import ExportEvaluatedDataItemsConfig +from .export_evaluated_data_items_config import ( + ExportEvaluatedDataItemsConfig, +) __all__ = ( "AutoMlImageClassification", @@ -78,6 +85,9 @@ "AutoMlTextExtractionInputs", "AutoMlTextSentiment", "AutoMlTextSentimentInputs", + "AutoMlForecasting", + "AutoMlForecastingInputs", + "AutoMlForecastingMetadata", "AutoMlVideoActionRecognition", "AutoMlVideoActionRecognitionInputs", "AutoMlVideoClassification", diff --git a/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_forecasting.py b/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_forecasting.py index 34f700f8af..3571368e5f 100644 --- a/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_forecasting.py +++ b/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_forecasting.py @@ -44,10 +44,16 @@ class AutoMlForecasting(proto.Message): The metadata information. """ - inputs = proto.Field(proto.MESSAGE, number=1, message="AutoMlForecastingInputs",) + inputs = proto.Field( + proto.MESSAGE, + number=1, + message="AutoMlForecastingInputs", + ) metadata = proto.Field( - proto.MESSAGE, number=2, message="AutoMlForecastingMetadata", + proto.MESSAGE, + number=2, + message="AutoMlForecastingMetadata", ) @@ -439,7 +445,9 @@ class Period(proto.Message): time_column = proto.Field(proto.STRING, number=3) transformations = proto.RepeatedField( - proto.MESSAGE, number=4, message=Transformation, + proto.MESSAGE, + number=4, + message=Transformation, ) optimization_objective = proto.Field(proto.STRING, number=5) @@ -454,7 +462,11 @@ class Period(proto.Message): time_variant_past_and_future_columns = proto.RepeatedField(proto.STRING, number=10) - period = proto.Field(proto.MESSAGE, number=11, message=Period,) + period = proto.Field( + proto.MESSAGE, + number=11, + message=Period, + ) forecast_window_start = proto.Field(proto.INT64, number=12) diff --git a/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_image_classification.py b/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_image_classification.py index 945962bb50..4c2e019747 100644 --- a/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_image_classification.py +++ b/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_image_classification.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -38,15 +38,20 @@ class AutoMlImageClassification(proto.Message): """ inputs = proto.Field( - proto.MESSAGE, number=1, message="AutoMlImageClassificationInputs", + proto.MESSAGE, + number=1, + message="AutoMlImageClassificationInputs", ) metadata = proto.Field( - proto.MESSAGE, number=2, message="AutoMlImageClassificationMetadata", + proto.MESSAGE, + number=2, + message="AutoMlImageClassificationMetadata", ) class AutoMlImageClassificationInputs(proto.Message): r""" + Attributes: model_type (google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1.types.AutoMlImageClassificationInputs.ModelType): @@ -97,15 +102,32 @@ class ModelType(proto.Enum): MOBILE_TF_VERSATILE_1 = 3 MOBILE_TF_HIGH_ACCURACY_1 = 4 - model_type = proto.Field(proto.ENUM, number=1, enum=ModelType,) - base_model_id = proto.Field(proto.STRING, number=2,) - budget_milli_node_hours = proto.Field(proto.INT64, number=3,) - disable_early_stopping = proto.Field(proto.BOOL, number=4,) - multi_label = proto.Field(proto.BOOL, number=5,) + model_type = proto.Field( + proto.ENUM, + number=1, + enum=ModelType, + ) + base_model_id = proto.Field( + proto.STRING, + number=2, + ) + budget_milli_node_hours = proto.Field( + proto.INT64, + number=3, + ) + disable_early_stopping = proto.Field( + proto.BOOL, + number=4, + ) + multi_label = proto.Field( + proto.BOOL, + number=5, + ) class AutoMlImageClassificationMetadata(proto.Message): r""" + Attributes: cost_milli_node_hours (int): The actual training cost of creating this @@ -124,9 +146,14 @@ class SuccessfulStopReason(proto.Enum): BUDGET_REACHED = 1 MODEL_CONVERGED = 2 - cost_milli_node_hours = proto.Field(proto.INT64, number=1,) + cost_milli_node_hours = proto.Field( + proto.INT64, + number=1, + ) successful_stop_reason = proto.Field( - proto.ENUM, number=2, enum=SuccessfulStopReason, + proto.ENUM, + number=2, + enum=SuccessfulStopReason, ) diff --git a/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_image_object_detection.py b/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_image_object_detection.py index 1d95b93970..1fa70c468e 100644 --- a/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_image_object_detection.py +++ b/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_image_object_detection.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -38,15 +38,20 @@ class AutoMlImageObjectDetection(proto.Message): """ inputs = proto.Field( - proto.MESSAGE, number=1, message="AutoMlImageObjectDetectionInputs", + proto.MESSAGE, + number=1, + message="AutoMlImageObjectDetectionInputs", ) metadata = proto.Field( - proto.MESSAGE, number=2, message="AutoMlImageObjectDetectionMetadata", + proto.MESSAGE, + number=2, + message="AutoMlImageObjectDetectionMetadata", ) class AutoMlImageObjectDetectionInputs(proto.Message): r""" + Attributes: model_type (google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1.types.AutoMlImageObjectDetectionInputs.ModelType): @@ -86,13 +91,24 @@ class ModelType(proto.Enum): MOBILE_TF_VERSATILE_1 = 4 MOBILE_TF_HIGH_ACCURACY_1 = 5 - model_type = proto.Field(proto.ENUM, number=1, enum=ModelType,) - budget_milli_node_hours = proto.Field(proto.INT64, number=2,) - disable_early_stopping = proto.Field(proto.BOOL, number=3,) + model_type = proto.Field( + proto.ENUM, + number=1, + enum=ModelType, + ) + budget_milli_node_hours = proto.Field( + proto.INT64, + number=2, + ) + disable_early_stopping = proto.Field( + proto.BOOL, + number=3, + ) class AutoMlImageObjectDetectionMetadata(proto.Message): r""" + Attributes: cost_milli_node_hours (int): The actual training cost of creating this @@ -111,9 +127,14 @@ class SuccessfulStopReason(proto.Enum): BUDGET_REACHED = 1 MODEL_CONVERGED = 2 - cost_milli_node_hours = proto.Field(proto.INT64, number=1,) + cost_milli_node_hours = proto.Field( + proto.INT64, + number=1, + ) successful_stop_reason = proto.Field( - proto.ENUM, number=2, enum=SuccessfulStopReason, + proto.ENUM, + number=2, + enum=SuccessfulStopReason, ) diff --git a/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_image_segmentation.py b/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_image_segmentation.py index 4b47874f37..5cdf7b69b5 100644 --- a/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_image_segmentation.py +++ b/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_image_segmentation.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -38,15 +38,20 @@ class AutoMlImageSegmentation(proto.Message): """ inputs = proto.Field( - proto.MESSAGE, number=1, message="AutoMlImageSegmentationInputs", + proto.MESSAGE, + number=1, + message="AutoMlImageSegmentationInputs", ) metadata = proto.Field( - proto.MESSAGE, number=2, message="AutoMlImageSegmentationMetadata", + proto.MESSAGE, + number=2, + message="AutoMlImageSegmentationMetadata", ) class AutoMlImageSegmentationInputs(proto.Message): r""" + Attributes: model_type (google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1.types.AutoMlImageSegmentationInputs.ModelType): @@ -80,13 +85,24 @@ class ModelType(proto.Enum): CLOUD_LOW_ACCURACY_1 = 2 MOBILE_TF_LOW_LATENCY_1 = 3 - model_type = proto.Field(proto.ENUM, number=1, enum=ModelType,) - budget_milli_node_hours = proto.Field(proto.INT64, number=2,) - base_model_id = proto.Field(proto.STRING, number=3,) + model_type = proto.Field( + proto.ENUM, + number=1, + enum=ModelType, + ) + budget_milli_node_hours = proto.Field( + proto.INT64, + number=2, + ) + base_model_id = proto.Field( + proto.STRING, + number=3, + ) class AutoMlImageSegmentationMetadata(proto.Message): r""" + Attributes: cost_milli_node_hours (int): The actual training cost of creating this @@ -105,9 +121,14 @@ class SuccessfulStopReason(proto.Enum): BUDGET_REACHED = 1 MODEL_CONVERGED = 2 - cost_milli_node_hours = proto.Field(proto.INT64, number=1,) + cost_milli_node_hours = proto.Field( + proto.INT64, + number=1, + ) successful_stop_reason = proto.Field( - proto.ENUM, number=2, enum=SuccessfulStopReason, + proto.ENUM, + number=2, + enum=SuccessfulStopReason, ) diff --git a/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_tables.py b/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_tables.py index 3531ec74f6..f1b1bf9aba 100644 --- a/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_tables.py +++ b/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_tables.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -22,12 +22,17 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1.schema.trainingjob.definition", - manifest={"AutoMlTables", "AutoMlTablesInputs", "AutoMlTablesMetadata",}, + manifest={ + "AutoMlTables", + "AutoMlTablesInputs", + "AutoMlTablesMetadata", + }, ) class AutoMlTables(proto.Message): r"""A TrainingJob that trains and uploads an AutoML Tables Model. + Attributes: inputs (google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1.types.AutoMlTablesInputs): The input parameters of this TrainingJob. @@ -35,21 +40,41 @@ class AutoMlTables(proto.Message): The metadata information. """ - inputs = proto.Field(proto.MESSAGE, number=1, message="AutoMlTablesInputs",) - metadata = proto.Field(proto.MESSAGE, number=2, message="AutoMlTablesMetadata",) + inputs = proto.Field( + proto.MESSAGE, + number=1, + message="AutoMlTablesInputs", + ) + metadata = proto.Field( + proto.MESSAGE, + number=2, + message="AutoMlTablesMetadata", + ) class AutoMlTablesInputs(proto.Message): r""" + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: optimization_objective_recall_value (float): Required when optimization_objective is "maximize-precision-at-recall". Must be between 0 and 1, inclusive. + + This field is a member of `oneof`_ ``additional_optimization_objective_config``. optimization_objective_precision_value (float): Required when optimization_objective is "maximize-recall-at-precision". Must be between 0 and 1, inclusive. + + This field is a member of `oneof`_ ``additional_optimization_objective_config``. prediction_type (str): The type of prediction the Model is to produce. "classification" - Predict one out of @@ -86,9 +111,9 @@ class AutoMlTablesInputs(proto.Message): operating characteristic (ROC) curve. "minimize-log-loss" - Minimize log loss. "maximize-au-prc" - Maximize the area under - the precision-recall curve. "maximize- - precision-at-recall" - Maximize precision for a - specified + the precision-recall curve. + "maximize-precision-at-recall" - Maximize + precision for a specified recall value. "maximize-recall-at-precision" - Maximize recall for a specified precision value. @@ -96,11 +121,11 @@ class AutoMlTablesInputs(proto.Message): "minimize-log-loss" (default) - Minimize log loss. regression: - "minimize-rmse" (default) - Minimize root- - mean-squared error (RMSE). "minimize-mae" - - Minimize mean-absolute error (MAE). "minimize- - rmsle" - Minimize root-mean-squared log error - (RMSLE). + "minimize-rmse" (default) - Minimize + root-mean-squared error (RMSE). "minimize-mae" + - Minimize mean-absolute error (MAE). + "minimize-rmsle" - Minimize root-mean-squared + log error (RMSLE). train_budget_milli_node_hours (int): Required. The train budget of creating this model, expressed in milli node hours i.e. 1,000 @@ -139,27 +164,46 @@ class AutoMlTablesInputs(proto.Message): predictions to a BigQuery table. If this configuration is absent, then the export is not performed. + additional_experiments (Sequence[str]): + Additional experiment flags for the Tables + training pipeline. """ class Transformation(proto.Message): r""" + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: auto (google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1.types.AutoMlTablesInputs.Transformation.AutoTransformation): + This field is a member of `oneof`_ ``transformation_detail``. numeric (google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1.types.AutoMlTablesInputs.Transformation.NumericTransformation): + This field is a member of `oneof`_ ``transformation_detail``. categorical (google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1.types.AutoMlTablesInputs.Transformation.CategoricalTransformation): + This field is a member of `oneof`_ ``transformation_detail``. timestamp (google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1.types.AutoMlTablesInputs.Transformation.TimestampTransformation): + This field is a member of `oneof`_ ``transformation_detail``. text (google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1.types.AutoMlTablesInputs.Transformation.TextTransformation): + This field is a member of `oneof`_ ``transformation_detail``. repeated_numeric (google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1.types.AutoMlTablesInputs.Transformation.NumericArrayTransformation): + This field is a member of `oneof`_ ``transformation_detail``. repeated_categorical (google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1.types.AutoMlTablesInputs.Transformation.CategoricalArrayTransformation): + This field is a member of `oneof`_ ``transformation_detail``. repeated_text (google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1.types.AutoMlTablesInputs.Transformation.TextArrayTransformation): + This field is a member of `oneof`_ ``transformation_detail``. """ class AutoTransformation(proto.Message): @@ -171,7 +215,10 @@ class AutoTransformation(proto.Message): """ - column_name = proto.Field(proto.STRING, number=1,) + column_name = proto.Field( + proto.STRING, + number=1, + ) class NumericTransformation(proto.Message): r"""Training pipeline will perform following transformation functions. @@ -197,8 +244,14 @@ class NumericTransformation(proto.Message): from trainining data. """ - column_name = proto.Field(proto.STRING, number=1,) - invalid_values_allowed = proto.Field(proto.BOOL, number=2,) + column_name = proto.Field( + proto.STRING, + number=1, + ) + invalid_values_allowed = proto.Field( + proto.BOOL, + number=2, + ) class CategoricalTransformation(proto.Message): r"""Training pipeline will perform following transformation functions. @@ -216,7 +269,10 @@ class CategoricalTransformation(proto.Message): """ - column_name = proto.Field(proto.STRING, number=1,) + column_name = proto.Field( + proto.STRING, + number=1, + ) class TimestampTransformation(proto.Message): r"""Training pipeline will perform following transformation functions. @@ -253,9 +309,18 @@ class TimestampTransformation(proto.Message): from trainining data. """ - column_name = proto.Field(proto.STRING, number=1,) - time_format = proto.Field(proto.STRING, number=2,) - invalid_values_allowed = proto.Field(proto.BOOL, number=3,) + column_name = proto.Field( + proto.STRING, + number=1, + ) + time_format = proto.Field( + proto.STRING, + number=2, + ) + invalid_values_allowed = proto.Field( + proto.BOOL, + number=3, + ) class TextTransformation(proto.Message): r"""Training pipeline will perform following transformation functions. @@ -275,7 +340,10 @@ class TextTransformation(proto.Message): """ - column_name = proto.Field(proto.STRING, number=1,) + column_name = proto.Field( + proto.STRING, + number=1, + ) class NumericArrayTransformation(proto.Message): r"""Treats the column as numerical array and performs following @@ -296,8 +364,14 @@ class NumericArrayTransformation(proto.Message): from trainining data. """ - column_name = proto.Field(proto.STRING, number=1,) - invalid_values_allowed = proto.Field(proto.BOOL, number=2,) + column_name = proto.Field( + proto.STRING, + number=1, + ) + invalid_values_allowed = proto.Field( + proto.BOOL, + number=2, + ) class CategoricalArrayTransformation(proto.Message): r"""Treats the column as categorical array and performs following @@ -314,7 +388,10 @@ class CategoricalArrayTransformation(proto.Message): """ - column_name = proto.Field(proto.STRING, number=1,) + column_name = proto.Field( + proto.STRING, + number=1, + ) class TextArrayTransformation(proto.Message): r"""Treats the column as text array and performs following @@ -330,7 +407,10 @@ class TextArrayTransformation(proto.Message): """ - column_name = proto.Field(proto.STRING, number=1,) + column_name = proto.Field( + proto.STRING, + number=1, + ) auto = proto.Field( proto.MESSAGE, @@ -382,29 +462,58 @@ class TextArrayTransformation(proto.Message): ) optimization_objective_recall_value = proto.Field( - proto.FLOAT, number=5, oneof="additional_optimization_objective_config", + proto.FLOAT, + number=5, + oneof="additional_optimization_objective_config", ) optimization_objective_precision_value = proto.Field( - proto.FLOAT, number=6, oneof="additional_optimization_objective_config", + proto.FLOAT, + number=6, + oneof="additional_optimization_objective_config", + ) + prediction_type = proto.Field( + proto.STRING, + number=1, + ) + target_column = proto.Field( + proto.STRING, + number=2, ) - prediction_type = proto.Field(proto.STRING, number=1,) - target_column = proto.Field(proto.STRING, number=2,) transformations = proto.RepeatedField( - proto.MESSAGE, number=3, message=Transformation, + proto.MESSAGE, + number=3, + message=Transformation, + ) + optimization_objective = proto.Field( + proto.STRING, + number=4, + ) + train_budget_milli_node_hours = proto.Field( + proto.INT64, + number=7, + ) + disable_early_stopping = proto.Field( + proto.BOOL, + number=8, + ) + weight_column_name = proto.Field( + proto.STRING, + number=9, ) - optimization_objective = proto.Field(proto.STRING, number=4,) - train_budget_milli_node_hours = proto.Field(proto.INT64, number=7,) - disable_early_stopping = proto.Field(proto.BOOL, number=8,) - weight_column_name = proto.Field(proto.STRING, number=9,) export_evaluated_data_items_config = proto.Field( proto.MESSAGE, number=10, message=gcastd_export_evaluated_data_items_config.ExportEvaluatedDataItemsConfig, ) + additional_experiments = proto.RepeatedField( + proto.STRING, + number=11, + ) class AutoMlTablesMetadata(proto.Message): r"""Model metadata specific to AutoML Tables. + Attributes: train_cost_milli_node_hours (int): Output only. The actual training cost of the @@ -413,7 +522,10 @@ class AutoMlTablesMetadata(proto.Message): Guaranteed to not exceed the train budget. """ - train_cost_milli_node_hours = proto.Field(proto.INT64, number=1,) + train_cost_milli_node_hours = proto.Field( + proto.INT64, + number=1, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_text_classification.py b/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_text_classification.py index bd52a0e808..ca1a163c1a 100644 --- a/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_text_classification.py +++ b/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_text_classification.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,7 +18,10 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1.schema.trainingjob.definition", - manifest={"AutoMlTextClassification", "AutoMlTextClassificationInputs",}, + manifest={ + "AutoMlTextClassification", + "AutoMlTextClassificationInputs", + }, ) @@ -32,18 +35,24 @@ class AutoMlTextClassification(proto.Message): """ inputs = proto.Field( - proto.MESSAGE, number=1, message="AutoMlTextClassificationInputs", + proto.MESSAGE, + number=1, + message="AutoMlTextClassificationInputs", ) class AutoMlTextClassificationInputs(proto.Message): r""" + Attributes: multi_label (bool): """ - multi_label = proto.Field(proto.BOOL, number=1,) + multi_label = proto.Field( + proto.BOOL, + number=1, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_text_extraction.py b/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_text_extraction.py index ba838e0ccc..89ae0aeeb9 100644 --- a/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_text_extraction.py +++ b/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_text_extraction.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,7 +18,10 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1.schema.trainingjob.definition", - manifest={"AutoMlTextExtraction", "AutoMlTextExtractionInputs",}, + manifest={ + "AutoMlTextExtraction", + "AutoMlTextExtractionInputs", + }, ) @@ -31,11 +34,15 @@ class AutoMlTextExtraction(proto.Message): The input parameters of this TrainingJob. """ - inputs = proto.Field(proto.MESSAGE, number=1, message="AutoMlTextExtractionInputs",) + inputs = proto.Field( + proto.MESSAGE, + number=1, + message="AutoMlTextExtractionInputs", + ) class AutoMlTextExtractionInputs(proto.Message): - r""" """ + r""" """ __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_text_sentiment.py b/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_text_sentiment.py index 4439db4bcc..9d9b6d9e31 100644 --- a/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_text_sentiment.py +++ b/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_text_sentiment.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,7 +18,10 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1.schema.trainingjob.definition", - manifest={"AutoMlTextSentiment", "AutoMlTextSentimentInputs",}, + manifest={ + "AutoMlTextSentiment", + "AutoMlTextSentimentInputs", + }, ) @@ -31,11 +34,16 @@ class AutoMlTextSentiment(proto.Message): The input parameters of this TrainingJob. """ - inputs = proto.Field(proto.MESSAGE, number=1, message="AutoMlTextSentimentInputs",) + inputs = proto.Field( + proto.MESSAGE, + number=1, + message="AutoMlTextSentimentInputs", + ) class AutoMlTextSentimentInputs(proto.Message): r""" + Attributes: sentiment_max (int): A sentiment is expressed as an integer @@ -50,7 +58,10 @@ class AutoMlTextSentimentInputs(proto.Message): between 1 and 10 (inclusive). """ - sentiment_max = proto.Field(proto.INT32, number=1,) + sentiment_max = proto.Field( + proto.INT32, + number=1, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_time_series_forecasting.py b/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_time_series_forecasting.py new file mode 100644 index 0000000000..3f1e03c914 --- /dev/null +++ b/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_time_series_forecasting.py @@ -0,0 +1,495 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + +from google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1.types import ( + export_evaluated_data_items_config as gcastd_export_evaluated_data_items_config, +) + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1beta1.schema.trainingjob.definition", + manifest={ + "AutoMlForecasting", + "AutoMlForecastingInputs", + "AutoMlForecastingMetadata", + }, +) + + +class AutoMlForecasting(proto.Message): + r"""A TrainingJob that trains and uploads an AutoML Forecasting + Model. + + Attributes: + inputs (google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1.types.AutoMlForecastingInputs): + The input parameters of this TrainingJob. + metadata (google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1.types.AutoMlForecastingMetadata): + The metadata information. + """ + + inputs = proto.Field( + proto.MESSAGE, + number=1, + message="AutoMlForecastingInputs", + ) + metadata = proto.Field( + proto.MESSAGE, + number=2, + message="AutoMlForecastingMetadata", + ) + + +class AutoMlForecastingInputs(proto.Message): + r""" + + Attributes: + target_column (str): + The name of the column that the model is to + predict. + time_series_identifier_column (str): + The name of the column that identifies the + time series. + time_column (str): + The name of the column that identifies time + order in the time series. + transformations (Sequence[google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1.types.AutoMlForecastingInputs.Transformation]): + Each transformation will apply transform + function to given input column. And the result + will be used for training. When creating + transformation for BigQuery Struct column, the + column should be flattened using "." as the + delimiter. + optimization_objective (str): + Objective function the model is optimizing towards. The + training process creates a model that optimizes the value of + the objective function over the validation set. + + The supported optimization objectives: + + - "minimize-rmse" (default) - Minimize root-mean-squared + error (RMSE). + + - "minimize-mae" - Minimize mean-absolute error (MAE). + + - "minimize-rmsle" - Minimize root-mean-squared log error + (RMSLE). + + - "minimize-rmspe" - Minimize root-mean-squared percentage + error (RMSPE). + + - "minimize-wape-mae" - Minimize the combination of + weighted absolute percentage error (WAPE) and + mean-absolute-error (MAE). + + - "minimize-quantile-loss" - Minimize the quantile loss at + the quantiles defined in ``quantiles``. + train_budget_milli_node_hours (int): + Required. The train budget of creating this + model, expressed in milli node hours i.e. 1,000 + value in this field means 1 node hour. + The training cost of the model will not exceed + this budget. The final cost will be attempted to + be close to the budget, though may end up being + (even) noticeably smaller - at the backend's + discretion. This especially may happen when + further model training ceases to provide any + improvements. + If the budget is set to a value known to be + insufficient to train a model for the given + dataset, the training won't be attempted and + will error. + + The train budget must be between 1,000 and + 72,000 milli node hours, inclusive. + weight_column (str): + Column name that should be used as the weight + column. Higher values in this column give more + importance to the row during model training. The + column must have numeric values between 0 and + 10000 inclusively; 0 means the row is ignored + for training. If weight column field is not set, + then all rows are assumed to have equal weight + of 1. + time_series_attribute_columns (Sequence[str]): + Column names that should be used as attribute + columns. The value of these columns does not + vary as a function of time. For example, store + ID or item color. + unavailable_at_forecast_columns (Sequence[str]): + Names of columns that are unavailable when a forecast is + requested. This column contains information for the given + entity (identified by the time_series_identifier_column) + that is unknown before the forecast For example, actual + weather on a given day. + available_at_forecast_columns (Sequence[str]): + Names of columns that are available and provided when a + forecast is requested. These columns contain information for + the given entity (identified by the + time_series_identifier_column column) that is known at + forecast. For example, predicted weather for a specific day. + data_granularity (google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1.types.AutoMlForecastingInputs.Granularity): + Expected difference in time granularity + between rows in the data. + forecast_horizon (int): + The amount of time into the future for which forecasted + values for the target are returned. Expressed in number of + units defined by the ``data_granularity`` field. + context_window (int): + The amount of time into the past training and prediction + data is used for model training and prediction respectively. + Expressed in number of units defined by the + ``data_granularity`` field. + export_evaluated_data_items_config (google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1.types.ExportEvaluatedDataItemsConfig): + Configuration for exporting test set + predictions to a BigQuery table. If this + configuration is absent, then the export is not + performed. + quantiles (Sequence[float]): + Quantiles to use for minimize-quantile-loss + ``optimization_objective``. Up to 5 quantiles are allowed of + values between 0 and 1, exclusive. Required if the value of + optimization_objective is minimize-quantile-loss. Represents + the percent quantiles to use for that objective. Quantiles + must be unique. + validation_options (str): + Validation options for the data validation component. The + available options are: + + - "fail-pipeline" - default, will validate against the + validation and fail the pipeline if it fails. + + - "ignore-validation" - ignore the results of the + validation and continue + additional_experiments (Sequence[str]): + Additional experiment flags for the time + series forcasting training. + """ + + class Transformation(proto.Message): + r""" + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + auto (google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1.types.AutoMlForecastingInputs.Transformation.AutoTransformation): + + This field is a member of `oneof`_ ``transformation_detail``. + numeric (google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1.types.AutoMlForecastingInputs.Transformation.NumericTransformation): + + This field is a member of `oneof`_ ``transformation_detail``. + categorical (google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1.types.AutoMlForecastingInputs.Transformation.CategoricalTransformation): + + This field is a member of `oneof`_ ``transformation_detail``. + timestamp (google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1.types.AutoMlForecastingInputs.Transformation.TimestampTransformation): + + This field is a member of `oneof`_ ``transformation_detail``. + text (google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1.types.AutoMlForecastingInputs.Transformation.TextTransformation): + + This field is a member of `oneof`_ ``transformation_detail``. + """ + + class AutoTransformation(proto.Message): + r"""Training pipeline will infer the proper transformation based + on the statistic of dataset. + + Attributes: + column_name (str): + + """ + + column_name = proto.Field( + proto.STRING, + number=1, + ) + + class NumericTransformation(proto.Message): + r"""Training pipeline will perform following transformation functions. + + - The value converted to float32. + + - The z_score of the value. + + - log(value+1) when the value is greater than or equal to 0. + Otherwise, this transformation is not applied and the value is + considered a missing value. + + - z_score of log(value+1) when the value is greater than or equal + to 0. Otherwise, this transformation is not applied and the value + is considered a missing value. + + - A boolean value that indicates whether the value is valid. + + Attributes: + column_name (str): + + """ + + column_name = proto.Field( + proto.STRING, + number=1, + ) + + class CategoricalTransformation(proto.Message): + r"""Training pipeline will perform following transformation functions. + + - The categorical string as is--no change to case, punctuation, + spelling, tense, and so on. + + - Convert the category name to a dictionary lookup index and + generate an embedding for each index. + + - Categories that appear less than 5 times in the training dataset + are treated as the "unknown" category. The "unknown" category + gets its own special lookup index and resulting embedding. + + Attributes: + column_name (str): + + """ + + column_name = proto.Field( + proto.STRING, + number=1, + ) + + class TimestampTransformation(proto.Message): + r"""Training pipeline will perform following transformation functions. + + - Apply the transformation functions for Numerical columns. + + - Determine the year, month, day,and weekday. Treat each value from + the timestamp as a Categorical column. + + - Invalid numerical values (for example, values that fall outside + of a typical timestamp range, or are extreme values) receive no + special treatment and are not removed. + + Attributes: + column_name (str): + + time_format (str): + The format in which that time field is expressed. The + time_format must either be one of: + + - ``unix-seconds`` + + - ``unix-milliseconds`` + + - ``unix-microseconds`` + + - ``unix-nanoseconds`` + + (for respectively number of seconds, milliseconds, + microseconds and nanoseconds since start of the Unix epoch); + + or be written in ``strftime`` syntax. + + If time_format is not set, then the default format is RFC + 3339 ``date-time`` format, where ``time-offset`` = ``"Z"`` + (e.g. 1985-04-12T23:20:50.52Z) + """ + + column_name = proto.Field( + proto.STRING, + number=1, + ) + time_format = proto.Field( + proto.STRING, + number=2, + ) + + class TextTransformation(proto.Message): + r"""Training pipeline will perform following transformation functions. + + - The text as is--no change to case, punctuation, spelling, tense, + and so on. + + - Convert the category name to a dictionary lookup index and + generate an embedding for each index. + + Attributes: + column_name (str): + + """ + + column_name = proto.Field( + proto.STRING, + number=1, + ) + + auto = proto.Field( + proto.MESSAGE, + number=1, + oneof="transformation_detail", + message="AutoMlForecastingInputs.Transformation.AutoTransformation", + ) + numeric = proto.Field( + proto.MESSAGE, + number=2, + oneof="transformation_detail", + message="AutoMlForecastingInputs.Transformation.NumericTransformation", + ) + categorical = proto.Field( + proto.MESSAGE, + number=3, + oneof="transformation_detail", + message="AutoMlForecastingInputs.Transformation.CategoricalTransformation", + ) + timestamp = proto.Field( + proto.MESSAGE, + number=4, + oneof="transformation_detail", + message="AutoMlForecastingInputs.Transformation.TimestampTransformation", + ) + text = proto.Field( + proto.MESSAGE, + number=5, + oneof="transformation_detail", + message="AutoMlForecastingInputs.Transformation.TextTransformation", + ) + + class Granularity(proto.Message): + r"""A duration of time expressed in time granularity units. + + Attributes: + unit (str): + The time granularity unit of this time period. The supported + units are: + + - "minute" + + - "hour" + + - "day" + + - "week" + + - "month" + + - "year". + quantity (int): + The number of granularity_units between data points in the + training data. If ``granularity_unit`` is ``minute``, can be + 1, 5, 10, 15, or 30. For all other values of + ``granularity_unit``, must be 1. + """ + + unit = proto.Field( + proto.STRING, + number=1, + ) + quantity = proto.Field( + proto.INT64, + number=2, + ) + + target_column = proto.Field( + proto.STRING, + number=1, + ) + time_series_identifier_column = proto.Field( + proto.STRING, + number=2, + ) + time_column = proto.Field( + proto.STRING, + number=3, + ) + transformations = proto.RepeatedField( + proto.MESSAGE, + number=4, + message=Transformation, + ) + optimization_objective = proto.Field( + proto.STRING, + number=5, + ) + train_budget_milli_node_hours = proto.Field( + proto.INT64, + number=6, + ) + weight_column = proto.Field( + proto.STRING, + number=7, + ) + time_series_attribute_columns = proto.RepeatedField( + proto.STRING, + number=19, + ) + unavailable_at_forecast_columns = proto.RepeatedField( + proto.STRING, + number=20, + ) + available_at_forecast_columns = proto.RepeatedField( + proto.STRING, + number=21, + ) + data_granularity = proto.Field( + proto.MESSAGE, + number=22, + message=Granularity, + ) + forecast_horizon = proto.Field( + proto.INT64, + number=23, + ) + context_window = proto.Field( + proto.INT64, + number=24, + ) + export_evaluated_data_items_config = proto.Field( + proto.MESSAGE, + number=15, + message=gcastd_export_evaluated_data_items_config.ExportEvaluatedDataItemsConfig, + ) + quantiles = proto.RepeatedField( + proto.DOUBLE, + number=16, + ) + validation_options = proto.Field( + proto.STRING, + number=17, + ) + additional_experiments = proto.RepeatedField( + proto.STRING, + number=25, + ) + + +class AutoMlForecastingMetadata(proto.Message): + r"""Model metadata specific to AutoML Forecasting. + + Attributes: + train_cost_milli_node_hours (int): + Output only. The actual training cost of the + model, expressed in milli node hours, i.e. 1,000 + value in this field means 1 node hour. + Guaranteed to not exceed the train budget. + """ + + train_cost_milli_node_hours = proto.Field( + proto.INT64, + number=1, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_video_action_recognition.py b/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_video_action_recognition.py index 4132a92bdc..d20cd00015 100644 --- a/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_video_action_recognition.py +++ b/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_video_action_recognition.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,7 +18,10 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1.schema.trainingjob.definition", - manifest={"AutoMlVideoActionRecognition", "AutoMlVideoActionRecognitionInputs",}, + manifest={ + "AutoMlVideoActionRecognition", + "AutoMlVideoActionRecognitionInputs", + }, ) @@ -32,12 +35,15 @@ class AutoMlVideoActionRecognition(proto.Message): """ inputs = proto.Field( - proto.MESSAGE, number=1, message="AutoMlVideoActionRecognitionInputs", + proto.MESSAGE, + number=1, + message="AutoMlVideoActionRecognitionInputs", ) class AutoMlVideoActionRecognitionInputs(proto.Message): r""" + Attributes: model_type (google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1.types.AutoMlVideoActionRecognitionInputs.ModelType): @@ -48,8 +54,14 @@ class ModelType(proto.Enum): MODEL_TYPE_UNSPECIFIED = 0 CLOUD = 1 MOBILE_VERSATILE_1 = 2 + MOBILE_JETSON_VERSATILE_1 = 3 + MOBILE_CORAL_VERSATILE_1 = 4 - model_type = proto.Field(proto.ENUM, number=1, enum=ModelType,) + model_type = proto.Field( + proto.ENUM, + number=1, + enum=ModelType, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_video_classification.py b/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_video_classification.py index f5860b0d16..767d27cbc3 100644 --- a/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_video_classification.py +++ b/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_video_classification.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,7 +18,10 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1.schema.trainingjob.definition", - manifest={"AutoMlVideoClassification", "AutoMlVideoClassificationInputs",}, + manifest={ + "AutoMlVideoClassification", + "AutoMlVideoClassificationInputs", + }, ) @@ -32,12 +35,15 @@ class AutoMlVideoClassification(proto.Message): """ inputs = proto.Field( - proto.MESSAGE, number=1, message="AutoMlVideoClassificationInputs", + proto.MESSAGE, + number=1, + message="AutoMlVideoClassificationInputs", ) class AutoMlVideoClassificationInputs(proto.Message): r""" + Attributes: model_type (google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1.types.AutoMlVideoClassificationInputs.ModelType): @@ -50,7 +56,11 @@ class ModelType(proto.Enum): MOBILE_VERSATILE_1 = 2 MOBILE_JETSON_VERSATILE_1 = 3 - model_type = proto.Field(proto.ENUM, number=1, enum=ModelType,) + model_type = proto.Field( + proto.ENUM, + number=1, + enum=ModelType, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_video_object_tracking.py b/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_video_object_tracking.py index ea684c9977..bb000644df 100644 --- a/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_video_object_tracking.py +++ b/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/automl_video_object_tracking.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,7 +18,10 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1.schema.trainingjob.definition", - manifest={"AutoMlVideoObjectTracking", "AutoMlVideoObjectTrackingInputs",}, + manifest={ + "AutoMlVideoObjectTracking", + "AutoMlVideoObjectTrackingInputs", + }, ) @@ -32,12 +35,15 @@ class AutoMlVideoObjectTracking(proto.Message): """ inputs = proto.Field( - proto.MESSAGE, number=1, message="AutoMlVideoObjectTrackingInputs", + proto.MESSAGE, + number=1, + message="AutoMlVideoObjectTrackingInputs", ) class AutoMlVideoObjectTrackingInputs(proto.Message): r""" + Attributes: model_type (google.cloud.aiplatform.v1beta1.schema.trainingjob.definition_v1beta1.types.AutoMlVideoObjectTrackingInputs.ModelType): @@ -53,7 +59,11 @@ class ModelType(proto.Enum): MOBILE_JETSON_VERSATILE_1 = 5 MOBILE_JETSON_LOW_LATENCY_1 = 6 - model_type = proto.Field(proto.ENUM, number=1, enum=ModelType,) + model_type = proto.Field( + proto.ENUM, + number=1, + enum=ModelType, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/export_evaluated_data_items_config.py b/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/export_evaluated_data_items_config.py index 15046f72c1..b8820db522 100644 --- a/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/export_evaluated_data_items_config.py +++ b/google/cloud/aiplatform/v1beta1/schema/trainingjob/definition_v1beta1/types/export_evaluated_data_items_config.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,7 +18,9 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1.schema.trainingjob.definition", - manifest={"ExportEvaluatedDataItemsConfig",}, + manifest={ + "ExportEvaluatedDataItemsConfig", + }, ) @@ -33,7 +35,6 @@ class ExportEvaluatedDataItemsConfig(proto.Message): If not specified, then results are exported to the following auto-created BigQuery table: - :export_evaluated_examples__.evaluated_examples override_existing_table (bool): If true and an export destination is @@ -43,8 +44,14 @@ class ExportEvaluatedDataItemsConfig(proto.Message): operation fails. """ - destination_bigquery_uri = proto.Field(proto.STRING, number=1,) - override_existing_table = proto.Field(proto.BOOL, number=2,) + destination_bigquery_uri = proto.Field( + proto.STRING, + number=1, + ) + override_existing_table = proto.Field( + proto.BOOL, + number=2, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform/version.py b/google/cloud/aiplatform/version.py new file mode 100644 index 0000000000..21995202bd --- /dev/null +++ b/google/cloud/aiplatform/version.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- + +# 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 +# +# 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. +# + +__version__ = "1.14.0" diff --git a/google/cloud/aiplatform_v1/__init__.py b/google/cloud/aiplatform_v1/__init__.py index d765cc599d..d4e36a264c 100644 --- a/google/cloud/aiplatform_v1/__init__.py +++ b/google/cloud/aiplatform_v1/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,8 +18,22 @@ from .services.dataset_service import DatasetServiceAsyncClient from .services.endpoint_service import EndpointServiceClient from .services.endpoint_service import EndpointServiceAsyncClient +from .services.featurestore_online_serving_service import ( + FeaturestoreOnlineServingServiceClient, +) +from .services.featurestore_online_serving_service import ( + FeaturestoreOnlineServingServiceAsyncClient, +) +from .services.featurestore_service import FeaturestoreServiceClient +from .services.featurestore_service import FeaturestoreServiceAsyncClient +from .services.index_endpoint_service import IndexEndpointServiceClient +from .services.index_endpoint_service import IndexEndpointServiceAsyncClient +from .services.index_service import IndexServiceClient +from .services.index_service import IndexServiceAsyncClient from .services.job_service import JobServiceClient from .services.job_service import JobServiceAsyncClient +from .services.metadata_service import MetadataServiceClient +from .services.metadata_service import MetadataServiceAsyncClient from .services.migration_service import MigrationServiceClient from .services.migration_service import MigrationServiceAsyncClient from .services.model_service import ModelServiceClient @@ -30,12 +44,18 @@ from .services.prediction_service import PredictionServiceAsyncClient from .services.specialist_pool_service import SpecialistPoolServiceClient from .services.specialist_pool_service import SpecialistPoolServiceAsyncClient +from .services.tensorboard_service import TensorboardServiceClient +from .services.tensorboard_service import TensorboardServiceAsyncClient +from .services.vizier_service import VizierServiceClient +from .services.vizier_service import VizierServiceAsyncClient from .types.accelerator_type import AcceleratorType from .types.annotation import Annotation from .types.annotation_spec import AnnotationSpec +from .types.artifact import Artifact from .types.batch_prediction_job import BatchPredictionJob from .types.completion_stats import CompletionStats +from .types.context import Context from .types.custom_job import ContainerSpec from .types.custom_job import CustomJob from .types.custom_job import CustomJobSpec @@ -68,10 +88,13 @@ from .types.dataset_service import ListDatasetsRequest from .types.dataset_service import ListDatasetsResponse from .types.dataset_service import UpdateDatasetRequest +from .types.deployed_index_ref import DeployedIndexRef from .types.deployed_model_ref import DeployedModelRef from .types.encryption_spec import EncryptionSpec from .types.endpoint import DeployedModel from .types.endpoint import Endpoint +from .types.endpoint import PredictRequestResponseLoggingConfig +from .types.endpoint import PrivateEndpoints from .types.endpoint_service import CreateEndpointOperationMetadata from .types.endpoint_service import CreateEndpointRequest from .types.endpoint_service import DeleteEndpointRequest @@ -85,13 +108,116 @@ from .types.endpoint_service import UndeployModelRequest from .types.endpoint_service import UndeployModelResponse from .types.endpoint_service import UpdateEndpointRequest +from .types.entity_type import EntityType from .types.env_var import EnvVar +from .types.event import Event +from .types.execution import Execution +from .types.explanation import Attribution +from .types.explanation import BlurBaselineConfig +from .types.explanation import ExamplesOverride +from .types.explanation import ExamplesRestrictionsNamespace +from .types.explanation import Explanation +from .types.explanation import ExplanationMetadataOverride +from .types.explanation import ExplanationParameters +from .types.explanation import ExplanationSpec +from .types.explanation import ExplanationSpecOverride +from .types.explanation import FeatureNoiseSigma +from .types.explanation import IntegratedGradientsAttribution +from .types.explanation import ModelExplanation +from .types.explanation import Neighbor +from .types.explanation import SampledShapleyAttribution +from .types.explanation import SmoothGradConfig +from .types.explanation import XraiAttribution +from .types.explanation_metadata import ExplanationMetadata +from .types.feature import Feature +from .types.feature_monitoring_stats import FeatureStatsAnomaly +from .types.feature_selector import FeatureSelector +from .types.feature_selector import IdMatcher +from .types.featurestore import Featurestore +from .types.featurestore_monitoring import FeaturestoreMonitoringConfig +from .types.featurestore_online_service import FeatureValue +from .types.featurestore_online_service import FeatureValueList +from .types.featurestore_online_service import ReadFeatureValuesRequest +from .types.featurestore_online_service import ReadFeatureValuesResponse +from .types.featurestore_online_service import StreamingReadFeatureValuesRequest +from .types.featurestore_service import BatchCreateFeaturesOperationMetadata +from .types.featurestore_service import BatchCreateFeaturesRequest +from .types.featurestore_service import BatchCreateFeaturesResponse +from .types.featurestore_service import BatchReadFeatureValuesOperationMetadata +from .types.featurestore_service import BatchReadFeatureValuesRequest +from .types.featurestore_service import BatchReadFeatureValuesResponse +from .types.featurestore_service import CreateEntityTypeOperationMetadata +from .types.featurestore_service import CreateEntityTypeRequest +from .types.featurestore_service import CreateFeatureOperationMetadata +from .types.featurestore_service import CreateFeatureRequest +from .types.featurestore_service import CreateFeaturestoreOperationMetadata +from .types.featurestore_service import CreateFeaturestoreRequest +from .types.featurestore_service import DeleteEntityTypeRequest +from .types.featurestore_service import DeleteFeatureRequest +from .types.featurestore_service import DeleteFeaturestoreRequest +from .types.featurestore_service import DestinationFeatureSetting +from .types.featurestore_service import ExportFeatureValuesOperationMetadata +from .types.featurestore_service import ExportFeatureValuesRequest +from .types.featurestore_service import ExportFeatureValuesResponse +from .types.featurestore_service import FeatureValueDestination +from .types.featurestore_service import GetEntityTypeRequest +from .types.featurestore_service import GetFeatureRequest +from .types.featurestore_service import GetFeaturestoreRequest +from .types.featurestore_service import ImportFeatureValuesOperationMetadata +from .types.featurestore_service import ImportFeatureValuesRequest +from .types.featurestore_service import ImportFeatureValuesResponse +from .types.featurestore_service import ListEntityTypesRequest +from .types.featurestore_service import ListEntityTypesResponse +from .types.featurestore_service import ListFeaturesRequest +from .types.featurestore_service import ListFeaturesResponse +from .types.featurestore_service import ListFeaturestoresRequest +from .types.featurestore_service import ListFeaturestoresResponse +from .types.featurestore_service import SearchFeaturesRequest +from .types.featurestore_service import SearchFeaturesResponse +from .types.featurestore_service import UpdateEntityTypeRequest +from .types.featurestore_service import UpdateFeatureRequest +from .types.featurestore_service import UpdateFeaturestoreOperationMetadata +from .types.featurestore_service import UpdateFeaturestoreRequest from .types.hyperparameter_tuning_job import HyperparameterTuningJob +from .types.index import Index +from .types.index_endpoint import DeployedIndex +from .types.index_endpoint import DeployedIndexAuthConfig +from .types.index_endpoint import IndexEndpoint +from .types.index_endpoint import IndexPrivateEndpoints +from .types.index_endpoint_service import CreateIndexEndpointOperationMetadata +from .types.index_endpoint_service import CreateIndexEndpointRequest +from .types.index_endpoint_service import DeleteIndexEndpointRequest +from .types.index_endpoint_service import DeployIndexOperationMetadata +from .types.index_endpoint_service import DeployIndexRequest +from .types.index_endpoint_service import DeployIndexResponse +from .types.index_endpoint_service import GetIndexEndpointRequest +from .types.index_endpoint_service import ListIndexEndpointsRequest +from .types.index_endpoint_service import ListIndexEndpointsResponse +from .types.index_endpoint_service import MutateDeployedIndexOperationMetadata +from .types.index_endpoint_service import MutateDeployedIndexRequest +from .types.index_endpoint_service import MutateDeployedIndexResponse +from .types.index_endpoint_service import UndeployIndexOperationMetadata +from .types.index_endpoint_service import UndeployIndexRequest +from .types.index_endpoint_service import UndeployIndexResponse +from .types.index_endpoint_service import UpdateIndexEndpointRequest +from .types.index_service import CreateIndexOperationMetadata +from .types.index_service import CreateIndexRequest +from .types.index_service import DeleteIndexRequest +from .types.index_service import GetIndexRequest +from .types.index_service import ListIndexesRequest +from .types.index_service import ListIndexesResponse +from .types.index_service import NearestNeighborSearchOperationMetadata +from .types.index_service import UpdateIndexOperationMetadata +from .types.index_service import UpdateIndexRequest +from .types.io import AvroSource from .types.io import BigQueryDestination from .types.io import BigQuerySource from .types.io import ContainerRegistryDestination +from .types.io import CsvDestination +from .types.io import CsvSource from .types.io import GcsDestination from .types.io import GcsSource +from .types.io import TFRecordDestination from .types.job_service import CancelBatchPredictionJobRequest from .types.job_service import CancelCustomJobRequest from .types.job_service import CancelDataLabelingJobRequest @@ -100,14 +226,17 @@ from .types.job_service import CreateCustomJobRequest from .types.job_service import CreateDataLabelingJobRequest from .types.job_service import CreateHyperparameterTuningJobRequest +from .types.job_service import CreateModelDeploymentMonitoringJobRequest from .types.job_service import DeleteBatchPredictionJobRequest from .types.job_service import DeleteCustomJobRequest from .types.job_service import DeleteDataLabelingJobRequest from .types.job_service import DeleteHyperparameterTuningJobRequest +from .types.job_service import DeleteModelDeploymentMonitoringJobRequest from .types.job_service import GetBatchPredictionJobRequest from .types.job_service import GetCustomJobRequest from .types.job_service import GetDataLabelingJobRequest from .types.job_service import GetHyperparameterTuningJobRequest +from .types.job_service import GetModelDeploymentMonitoringJobRequest from .types.job_service import ListBatchPredictionJobsRequest from .types.job_service import ListBatchPredictionJobsResponse from .types.job_service import ListCustomJobsRequest @@ -116,14 +245,74 @@ from .types.job_service import ListDataLabelingJobsResponse from .types.job_service import ListHyperparameterTuningJobsRequest from .types.job_service import ListHyperparameterTuningJobsResponse +from .types.job_service import ListModelDeploymentMonitoringJobsRequest +from .types.job_service import ListModelDeploymentMonitoringJobsResponse +from .types.job_service import PauseModelDeploymentMonitoringJobRequest +from .types.job_service import ResumeModelDeploymentMonitoringJobRequest +from .types.job_service import SearchModelDeploymentMonitoringStatsAnomaliesRequest +from .types.job_service import SearchModelDeploymentMonitoringStatsAnomaliesResponse +from .types.job_service import UpdateModelDeploymentMonitoringJobOperationMetadata +from .types.job_service import UpdateModelDeploymentMonitoringJobRequest from .types.job_state import JobState +from .types.lineage_subgraph import LineageSubgraph from .types.machine_resources import AutomaticResources +from .types.machine_resources import AutoscalingMetricSpec from .types.machine_resources import BatchDedicatedResources from .types.machine_resources import DedicatedResources from .types.machine_resources import DiskSpec from .types.machine_resources import MachineSpec +from .types.machine_resources import NfsMount from .types.machine_resources import ResourcesConsumed from .types.manual_batch_tuning_parameters import ManualBatchTuningParameters +from .types.metadata_schema import MetadataSchema +from .types.metadata_service import AddContextArtifactsAndExecutionsRequest +from .types.metadata_service import AddContextArtifactsAndExecutionsResponse +from .types.metadata_service import AddContextChildrenRequest +from .types.metadata_service import AddContextChildrenResponse +from .types.metadata_service import AddExecutionEventsRequest +from .types.metadata_service import AddExecutionEventsResponse +from .types.metadata_service import CreateArtifactRequest +from .types.metadata_service import CreateContextRequest +from .types.metadata_service import CreateExecutionRequest +from .types.metadata_service import CreateMetadataSchemaRequest +from .types.metadata_service import CreateMetadataStoreOperationMetadata +from .types.metadata_service import CreateMetadataStoreRequest +from .types.metadata_service import DeleteArtifactRequest +from .types.metadata_service import DeleteContextRequest +from .types.metadata_service import DeleteExecutionRequest +from .types.metadata_service import DeleteMetadataStoreOperationMetadata +from .types.metadata_service import DeleteMetadataStoreRequest +from .types.metadata_service import GetArtifactRequest +from .types.metadata_service import GetContextRequest +from .types.metadata_service import GetExecutionRequest +from .types.metadata_service import GetMetadataSchemaRequest +from .types.metadata_service import GetMetadataStoreRequest +from .types.metadata_service import ListArtifactsRequest +from .types.metadata_service import ListArtifactsResponse +from .types.metadata_service import ListContextsRequest +from .types.metadata_service import ListContextsResponse +from .types.metadata_service import ListExecutionsRequest +from .types.metadata_service import ListExecutionsResponse +from .types.metadata_service import ListMetadataSchemasRequest +from .types.metadata_service import ListMetadataSchemasResponse +from .types.metadata_service import ListMetadataStoresRequest +from .types.metadata_service import ListMetadataStoresResponse +from .types.metadata_service import PurgeArtifactsMetadata +from .types.metadata_service import PurgeArtifactsRequest +from .types.metadata_service import PurgeArtifactsResponse +from .types.metadata_service import PurgeContextsMetadata +from .types.metadata_service import PurgeContextsRequest +from .types.metadata_service import PurgeContextsResponse +from .types.metadata_service import PurgeExecutionsMetadata +from .types.metadata_service import PurgeExecutionsRequest +from .types.metadata_service import PurgeExecutionsResponse +from .types.metadata_service import QueryArtifactLineageSubgraphRequest +from .types.metadata_service import QueryContextLineageSubgraphRequest +from .types.metadata_service import QueryExecutionInputsAndOutputsRequest +from .types.metadata_service import UpdateArtifactRequest +from .types.metadata_service import UpdateContextRequest +from .types.metadata_service import UpdateExecutionRequest +from .types.metadata_store import MetadataStore from .types.migratable_resource import MigratableResource from .types.migration_service import BatchMigrateResourcesOperationMetadata from .types.migration_service import BatchMigrateResourcesRequest @@ -136,36 +325,74 @@ from .types.model import ModelContainerSpec from .types.model import Port from .types.model import PredictSchemata +from .types.model_deployment_monitoring_job import ( + ModelDeploymentMonitoringBigQueryTable, +) +from .types.model_deployment_monitoring_job import ModelDeploymentMonitoringJob +from .types.model_deployment_monitoring_job import ( + ModelDeploymentMonitoringObjectiveConfig, +) +from .types.model_deployment_monitoring_job import ( + ModelDeploymentMonitoringScheduleConfig, +) +from .types.model_deployment_monitoring_job import ModelMonitoringStatsAnomalies +from .types.model_deployment_monitoring_job import ( + ModelDeploymentMonitoringObjectiveType, +) from .types.model_evaluation import ModelEvaluation from .types.model_evaluation_slice import ModelEvaluationSlice +from .types.model_monitoring import ModelMonitoringAlertConfig +from .types.model_monitoring import ModelMonitoringObjectiveConfig +from .types.model_monitoring import SamplingStrategy +from .types.model_monitoring import ThresholdConfig from .types.model_service import DeleteModelRequest +from .types.model_service import DeleteModelVersionRequest from .types.model_service import ExportModelOperationMetadata from .types.model_service import ExportModelRequest from .types.model_service import ExportModelResponse from .types.model_service import GetModelEvaluationRequest from .types.model_service import GetModelEvaluationSliceRequest from .types.model_service import GetModelRequest +from .types.model_service import ImportModelEvaluationRequest from .types.model_service import ListModelEvaluationSlicesRequest from .types.model_service import ListModelEvaluationSlicesResponse from .types.model_service import ListModelEvaluationsRequest from .types.model_service import ListModelEvaluationsResponse from .types.model_service import ListModelsRequest from .types.model_service import ListModelsResponse +from .types.model_service import ListModelVersionsRequest +from .types.model_service import ListModelVersionsResponse +from .types.model_service import MergeVersionAliasesRequest from .types.model_service import UpdateModelRequest from .types.model_service import UploadModelOperationMetadata from .types.model_service import UploadModelRequest from .types.model_service import UploadModelResponse from .types.operation import DeleteOperationMetadata from .types.operation import GenericOperationMetadata +from .types.pipeline_failure_policy import PipelineFailurePolicy +from .types.pipeline_job import PipelineJob +from .types.pipeline_job import PipelineJobDetail +from .types.pipeline_job import PipelineTaskDetail +from .types.pipeline_job import PipelineTaskExecutorDetail +from .types.pipeline_job import PipelineTemplateMetadata +from .types.pipeline_service import CancelPipelineJobRequest from .types.pipeline_service import CancelTrainingPipelineRequest +from .types.pipeline_service import CreatePipelineJobRequest from .types.pipeline_service import CreateTrainingPipelineRequest +from .types.pipeline_service import DeletePipelineJobRequest from .types.pipeline_service import DeleteTrainingPipelineRequest +from .types.pipeline_service import GetPipelineJobRequest from .types.pipeline_service import GetTrainingPipelineRequest +from .types.pipeline_service import ListPipelineJobsRequest +from .types.pipeline_service import ListPipelineJobsResponse from .types.pipeline_service import ListTrainingPipelinesRequest from .types.pipeline_service import ListTrainingPipelinesResponse from .types.pipeline_state import PipelineState +from .types.prediction_service import ExplainRequest +from .types.prediction_service import ExplainResponse from .types.prediction_service import PredictRequest from .types.prediction_service import PredictResponse +from .types.prediction_service import RawPredictRequest from .types.specialist_pool import SpecialistPool from .types.specialist_pool_service import CreateSpecialistPoolOperationMetadata from .types.specialist_pool_service import CreateSpecialistPoolRequest @@ -176,56 +403,203 @@ from .types.specialist_pool_service import UpdateSpecialistPoolOperationMetadata from .types.specialist_pool_service import UpdateSpecialistPoolRequest from .types.study import Measurement +from .types.study import Study from .types.study import StudySpec from .types.study import Trial +from .types.tensorboard import Tensorboard +from .types.tensorboard_data import Scalar +from .types.tensorboard_data import TensorboardBlob +from .types.tensorboard_data import TensorboardBlobSequence +from .types.tensorboard_data import TensorboardTensor +from .types.tensorboard_data import TimeSeriesData +from .types.tensorboard_data import TimeSeriesDataPoint +from .types.tensorboard_experiment import TensorboardExperiment +from .types.tensorboard_run import TensorboardRun +from .types.tensorboard_service import BatchCreateTensorboardRunsRequest +from .types.tensorboard_service import BatchCreateTensorboardRunsResponse +from .types.tensorboard_service import BatchCreateTensorboardTimeSeriesRequest +from .types.tensorboard_service import BatchCreateTensorboardTimeSeriesResponse +from .types.tensorboard_service import BatchReadTensorboardTimeSeriesDataRequest +from .types.tensorboard_service import BatchReadTensorboardTimeSeriesDataResponse +from .types.tensorboard_service import CreateTensorboardExperimentRequest +from .types.tensorboard_service import CreateTensorboardOperationMetadata +from .types.tensorboard_service import CreateTensorboardRequest +from .types.tensorboard_service import CreateTensorboardRunRequest +from .types.tensorboard_service import CreateTensorboardTimeSeriesRequest +from .types.tensorboard_service import DeleteTensorboardExperimentRequest +from .types.tensorboard_service import DeleteTensorboardRequest +from .types.tensorboard_service import DeleteTensorboardRunRequest +from .types.tensorboard_service import DeleteTensorboardTimeSeriesRequest +from .types.tensorboard_service import ExportTensorboardTimeSeriesDataRequest +from .types.tensorboard_service import ExportTensorboardTimeSeriesDataResponse +from .types.tensorboard_service import GetTensorboardExperimentRequest +from .types.tensorboard_service import GetTensorboardRequest +from .types.tensorboard_service import GetTensorboardRunRequest +from .types.tensorboard_service import GetTensorboardTimeSeriesRequest +from .types.tensorboard_service import ListTensorboardExperimentsRequest +from .types.tensorboard_service import ListTensorboardExperimentsResponse +from .types.tensorboard_service import ListTensorboardRunsRequest +from .types.tensorboard_service import ListTensorboardRunsResponse +from .types.tensorboard_service import ListTensorboardsRequest +from .types.tensorboard_service import ListTensorboardsResponse +from .types.tensorboard_service import ListTensorboardTimeSeriesRequest +from .types.tensorboard_service import ListTensorboardTimeSeriesResponse +from .types.tensorboard_service import ReadTensorboardBlobDataRequest +from .types.tensorboard_service import ReadTensorboardBlobDataResponse +from .types.tensorboard_service import ReadTensorboardTimeSeriesDataRequest +from .types.tensorboard_service import ReadTensorboardTimeSeriesDataResponse +from .types.tensorboard_service import UpdateTensorboardExperimentRequest +from .types.tensorboard_service import UpdateTensorboardOperationMetadata +from .types.tensorboard_service import UpdateTensorboardRequest +from .types.tensorboard_service import UpdateTensorboardRunRequest +from .types.tensorboard_service import UpdateTensorboardTimeSeriesRequest +from .types.tensorboard_service import WriteTensorboardExperimentDataRequest +from .types.tensorboard_service import WriteTensorboardExperimentDataResponse +from .types.tensorboard_service import WriteTensorboardRunDataRequest +from .types.tensorboard_service import WriteTensorboardRunDataResponse +from .types.tensorboard_time_series import TensorboardTimeSeries from .types.training_pipeline import FilterSplit from .types.training_pipeline import FractionSplit from .types.training_pipeline import InputDataConfig from .types.training_pipeline import PredefinedSplit +from .types.training_pipeline import StratifiedSplit from .types.training_pipeline import TimestampSplit from .types.training_pipeline import TrainingPipeline +from .types.types import BoolArray +from .types.types import DoubleArray +from .types.types import Int64Array +from .types.types import StringArray +from .types.unmanaged_container_model import UnmanagedContainerModel from .types.user_action_reference import UserActionReference +from .types.value import Value +from .types.vizier_service import AddTrialMeasurementRequest +from .types.vizier_service import CheckTrialEarlyStoppingStateMetatdata +from .types.vizier_service import CheckTrialEarlyStoppingStateRequest +from .types.vizier_service import CheckTrialEarlyStoppingStateResponse +from .types.vizier_service import CompleteTrialRequest +from .types.vizier_service import CreateStudyRequest +from .types.vizier_service import CreateTrialRequest +from .types.vizier_service import DeleteStudyRequest +from .types.vizier_service import DeleteTrialRequest +from .types.vizier_service import GetStudyRequest +from .types.vizier_service import GetTrialRequest +from .types.vizier_service import ListOptimalTrialsRequest +from .types.vizier_service import ListOptimalTrialsResponse +from .types.vizier_service import ListStudiesRequest +from .types.vizier_service import ListStudiesResponse +from .types.vizier_service import ListTrialsRequest +from .types.vizier_service import ListTrialsResponse +from .types.vizier_service import LookupStudyRequest +from .types.vizier_service import StopTrialRequest +from .types.vizier_service import SuggestTrialsMetadata +from .types.vizier_service import SuggestTrialsRequest +from .types.vizier_service import SuggestTrialsResponse __all__ = ( "DatasetServiceAsyncClient", "EndpointServiceAsyncClient", + "FeaturestoreOnlineServingServiceAsyncClient", + "FeaturestoreServiceAsyncClient", + "IndexEndpointServiceAsyncClient", + "IndexServiceAsyncClient", "JobServiceAsyncClient", + "MetadataServiceAsyncClient", "MigrationServiceAsyncClient", "ModelServiceAsyncClient", "PipelineServiceAsyncClient", "PredictionServiceAsyncClient", "SpecialistPoolServiceAsyncClient", + "TensorboardServiceAsyncClient", + "VizierServiceAsyncClient", "AcceleratorType", "ActiveLearningConfig", + "AddContextArtifactsAndExecutionsRequest", + "AddContextArtifactsAndExecutionsResponse", + "AddContextChildrenRequest", + "AddContextChildrenResponse", + "AddExecutionEventsRequest", + "AddExecutionEventsResponse", + "AddTrialMeasurementRequest", "Annotation", "AnnotationSpec", + "Artifact", + "Attribution", "AutomaticResources", + "AutoscalingMetricSpec", + "AvroSource", + "BatchCreateFeaturesOperationMetadata", + "BatchCreateFeaturesRequest", + "BatchCreateFeaturesResponse", + "BatchCreateTensorboardRunsRequest", + "BatchCreateTensorboardRunsResponse", + "BatchCreateTensorboardTimeSeriesRequest", + "BatchCreateTensorboardTimeSeriesResponse", "BatchDedicatedResources", "BatchMigrateResourcesOperationMetadata", "BatchMigrateResourcesRequest", "BatchMigrateResourcesResponse", "BatchPredictionJob", + "BatchReadFeatureValuesOperationMetadata", + "BatchReadFeatureValuesRequest", + "BatchReadFeatureValuesResponse", + "BatchReadTensorboardTimeSeriesDataRequest", + "BatchReadTensorboardTimeSeriesDataResponse", "BigQueryDestination", "BigQuerySource", + "BlurBaselineConfig", + "BoolArray", "CancelBatchPredictionJobRequest", "CancelCustomJobRequest", "CancelDataLabelingJobRequest", "CancelHyperparameterTuningJobRequest", + "CancelPipelineJobRequest", "CancelTrainingPipelineRequest", + "CheckTrialEarlyStoppingStateMetatdata", + "CheckTrialEarlyStoppingStateRequest", + "CheckTrialEarlyStoppingStateResponse", + "CompleteTrialRequest", "CompletionStats", "ContainerRegistryDestination", "ContainerSpec", + "Context", + "CreateArtifactRequest", "CreateBatchPredictionJobRequest", + "CreateContextRequest", "CreateCustomJobRequest", "CreateDataLabelingJobRequest", "CreateDatasetOperationMetadata", "CreateDatasetRequest", "CreateEndpointOperationMetadata", "CreateEndpointRequest", + "CreateEntityTypeOperationMetadata", + "CreateEntityTypeRequest", + "CreateExecutionRequest", + "CreateFeatureOperationMetadata", + "CreateFeatureRequest", + "CreateFeaturestoreOperationMetadata", + "CreateFeaturestoreRequest", "CreateHyperparameterTuningJobRequest", + "CreateIndexEndpointOperationMetadata", + "CreateIndexEndpointRequest", + "CreateIndexOperationMetadata", + "CreateIndexRequest", + "CreateMetadataSchemaRequest", + "CreateMetadataStoreOperationMetadata", + "CreateMetadataStoreRequest", + "CreateModelDeploymentMonitoringJobRequest", + "CreatePipelineJobRequest", "CreateSpecialistPoolOperationMetadata", "CreateSpecialistPoolRequest", + "CreateStudyRequest", + "CreateTensorboardExperimentRequest", + "CreateTensorboardOperationMetadata", + "CreateTensorboardRequest", + "CreateTensorboardRunRequest", + "CreateTensorboardTimeSeriesRequest", "CreateTrainingPipelineRequest", + "CreateTrialRequest", + "CsvDestination", + "CsvSource", "CustomJob", "CustomJobSpec", "DataItem", @@ -233,62 +607,153 @@ "Dataset", "DatasetServiceClient", "DedicatedResources", + "DeleteArtifactRequest", "DeleteBatchPredictionJobRequest", + "DeleteContextRequest", "DeleteCustomJobRequest", "DeleteDataLabelingJobRequest", "DeleteDatasetRequest", "DeleteEndpointRequest", + "DeleteEntityTypeRequest", + "DeleteExecutionRequest", + "DeleteFeatureRequest", + "DeleteFeaturestoreRequest", "DeleteHyperparameterTuningJobRequest", + "DeleteIndexEndpointRequest", + "DeleteIndexRequest", + "DeleteMetadataStoreOperationMetadata", + "DeleteMetadataStoreRequest", + "DeleteModelDeploymentMonitoringJobRequest", "DeleteModelRequest", + "DeleteModelVersionRequest", "DeleteOperationMetadata", + "DeletePipelineJobRequest", "DeleteSpecialistPoolRequest", + "DeleteStudyRequest", + "DeleteTensorboardExperimentRequest", + "DeleteTensorboardRequest", + "DeleteTensorboardRunRequest", + "DeleteTensorboardTimeSeriesRequest", "DeleteTrainingPipelineRequest", + "DeleteTrialRequest", + "DeployIndexOperationMetadata", + "DeployIndexRequest", + "DeployIndexResponse", "DeployModelOperationMetadata", "DeployModelRequest", "DeployModelResponse", + "DeployedIndex", + "DeployedIndexAuthConfig", + "DeployedIndexRef", "DeployedModel", "DeployedModelRef", + "DestinationFeatureSetting", "DiskSpec", + "DoubleArray", "EncryptionSpec", "Endpoint", "EndpointServiceClient", + "EntityType", "EnvVar", + "Event", + "ExamplesOverride", + "ExamplesRestrictionsNamespace", + "Execution", + "ExplainRequest", + "ExplainResponse", + "Explanation", + "ExplanationMetadata", + "ExplanationMetadataOverride", + "ExplanationParameters", + "ExplanationSpec", + "ExplanationSpecOverride", "ExportDataConfig", "ExportDataOperationMetadata", "ExportDataRequest", "ExportDataResponse", + "ExportFeatureValuesOperationMetadata", + "ExportFeatureValuesRequest", + "ExportFeatureValuesResponse", "ExportModelOperationMetadata", "ExportModelRequest", "ExportModelResponse", + "ExportTensorboardTimeSeriesDataRequest", + "ExportTensorboardTimeSeriesDataResponse", + "Feature", + "FeatureNoiseSigma", + "FeatureSelector", + "FeatureStatsAnomaly", + "FeatureValue", + "FeatureValueDestination", + "FeatureValueList", + "Featurestore", + "FeaturestoreMonitoringConfig", + "FeaturestoreOnlineServingServiceClient", + "FeaturestoreServiceClient", "FilterSplit", "FractionSplit", "GcsDestination", "GcsSource", "GenericOperationMetadata", "GetAnnotationSpecRequest", + "GetArtifactRequest", "GetBatchPredictionJobRequest", + "GetContextRequest", "GetCustomJobRequest", "GetDataLabelingJobRequest", "GetDatasetRequest", "GetEndpointRequest", + "GetEntityTypeRequest", + "GetExecutionRequest", + "GetFeatureRequest", + "GetFeaturestoreRequest", "GetHyperparameterTuningJobRequest", + "GetIndexEndpointRequest", + "GetIndexRequest", + "GetMetadataSchemaRequest", + "GetMetadataStoreRequest", + "GetModelDeploymentMonitoringJobRequest", "GetModelEvaluationRequest", "GetModelEvaluationSliceRequest", "GetModelRequest", + "GetPipelineJobRequest", "GetSpecialistPoolRequest", + "GetStudyRequest", + "GetTensorboardExperimentRequest", + "GetTensorboardRequest", + "GetTensorboardRunRequest", + "GetTensorboardTimeSeriesRequest", "GetTrainingPipelineRequest", + "GetTrialRequest", "HyperparameterTuningJob", + "IdMatcher", "ImportDataConfig", "ImportDataOperationMetadata", "ImportDataRequest", "ImportDataResponse", + "ImportFeatureValuesOperationMetadata", + "ImportFeatureValuesRequest", + "ImportFeatureValuesResponse", + "ImportModelEvaluationRequest", + "Index", + "IndexEndpoint", + "IndexEndpointServiceClient", + "IndexPrivateEndpoints", + "IndexServiceClient", "InputDataConfig", + "Int64Array", + "IntegratedGradientsAttribution", "JobServiceClient", "JobState", + "LineageSubgraph", "ListAnnotationsRequest", "ListAnnotationsResponse", + "ListArtifactsRequest", + "ListArtifactsResponse", "ListBatchPredictionJobsRequest", "ListBatchPredictionJobsResponse", + "ListContextsRequest", + "ListContextsResponse", "ListCustomJobsRequest", "ListCustomJobsResponse", "ListDataItemsRequest", @@ -299,62 +764,203 @@ "ListDatasetsResponse", "ListEndpointsRequest", "ListEndpointsResponse", + "ListEntityTypesRequest", + "ListEntityTypesResponse", + "ListExecutionsRequest", + "ListExecutionsResponse", + "ListFeaturesRequest", + "ListFeaturesResponse", + "ListFeaturestoresRequest", + "ListFeaturestoresResponse", "ListHyperparameterTuningJobsRequest", "ListHyperparameterTuningJobsResponse", + "ListIndexEndpointsRequest", + "ListIndexEndpointsResponse", + "ListIndexesRequest", + "ListIndexesResponse", + "ListMetadataSchemasRequest", + "ListMetadataSchemasResponse", + "ListMetadataStoresRequest", + "ListMetadataStoresResponse", + "ListModelDeploymentMonitoringJobsRequest", + "ListModelDeploymentMonitoringJobsResponse", "ListModelEvaluationSlicesRequest", "ListModelEvaluationSlicesResponse", "ListModelEvaluationsRequest", "ListModelEvaluationsResponse", + "ListModelVersionsRequest", + "ListModelVersionsResponse", "ListModelsRequest", "ListModelsResponse", + "ListOptimalTrialsRequest", + "ListOptimalTrialsResponse", + "ListPipelineJobsRequest", + "ListPipelineJobsResponse", "ListSpecialistPoolsRequest", "ListSpecialistPoolsResponse", + "ListStudiesRequest", + "ListStudiesResponse", + "ListTensorboardExperimentsRequest", + "ListTensorboardExperimentsResponse", + "ListTensorboardRunsRequest", + "ListTensorboardRunsResponse", + "ListTensorboardTimeSeriesRequest", + "ListTensorboardTimeSeriesResponse", + "ListTensorboardsRequest", + "ListTensorboardsResponse", "ListTrainingPipelinesRequest", "ListTrainingPipelinesResponse", + "ListTrialsRequest", + "ListTrialsResponse", + "LookupStudyRequest", "MachineSpec", "ManualBatchTuningParameters", "Measurement", + "MergeVersionAliasesRequest", + "MetadataSchema", + "MetadataServiceClient", + "MetadataStore", "MigratableResource", "MigrateResourceRequest", "MigrateResourceResponse", "MigrationServiceClient", "Model", "ModelContainerSpec", + "ModelDeploymentMonitoringBigQueryTable", + "ModelDeploymentMonitoringJob", + "ModelDeploymentMonitoringObjectiveConfig", + "ModelDeploymentMonitoringObjectiveType", + "ModelDeploymentMonitoringScheduleConfig", "ModelEvaluation", "ModelEvaluationSlice", + "ModelExplanation", + "ModelMonitoringAlertConfig", + "ModelMonitoringObjectiveConfig", + "ModelMonitoringStatsAnomalies", "ModelServiceClient", + "MutateDeployedIndexOperationMetadata", + "MutateDeployedIndexRequest", + "MutateDeployedIndexResponse", + "NearestNeighborSearchOperationMetadata", + "Neighbor", + "NfsMount", + "PauseModelDeploymentMonitoringJobRequest", + "PipelineFailurePolicy", + "PipelineJob", + "PipelineJobDetail", "PipelineServiceClient", "PipelineState", + "PipelineTaskDetail", + "PipelineTaskExecutorDetail", + "PipelineTemplateMetadata", "Port", "PredefinedSplit", "PredictRequest", + "PredictRequestResponseLoggingConfig", "PredictResponse", "PredictSchemata", "PredictionServiceClient", + "PrivateEndpoints", + "PurgeArtifactsMetadata", + "PurgeArtifactsRequest", + "PurgeArtifactsResponse", + "PurgeContextsMetadata", + "PurgeContextsRequest", + "PurgeContextsResponse", + "PurgeExecutionsMetadata", + "PurgeExecutionsRequest", + "PurgeExecutionsResponse", "PythonPackageSpec", + "QueryArtifactLineageSubgraphRequest", + "QueryContextLineageSubgraphRequest", + "QueryExecutionInputsAndOutputsRequest", + "RawPredictRequest", + "ReadFeatureValuesRequest", + "ReadFeatureValuesResponse", + "ReadTensorboardBlobDataRequest", + "ReadTensorboardBlobDataResponse", + "ReadTensorboardTimeSeriesDataRequest", + "ReadTensorboardTimeSeriesDataResponse", "ResourcesConsumed", + "ResumeModelDeploymentMonitoringJobRequest", "SampleConfig", + "SampledShapleyAttribution", + "SamplingStrategy", + "Scalar", "Scheduling", + "SearchFeaturesRequest", + "SearchFeaturesResponse", "SearchMigratableResourcesRequest", "SearchMigratableResourcesResponse", + "SearchModelDeploymentMonitoringStatsAnomaliesRequest", + "SearchModelDeploymentMonitoringStatsAnomaliesResponse", + "SmoothGradConfig", "SpecialistPool", "SpecialistPoolServiceClient", + "StopTrialRequest", + "StratifiedSplit", + "StreamingReadFeatureValuesRequest", + "StringArray", + "Study", "StudySpec", + "SuggestTrialsMetadata", + "SuggestTrialsRequest", + "SuggestTrialsResponse", + "TFRecordDestination", + "Tensorboard", + "TensorboardBlob", + "TensorboardBlobSequence", + "TensorboardExperiment", + "TensorboardRun", + "TensorboardServiceClient", + "TensorboardTensor", + "TensorboardTimeSeries", + "ThresholdConfig", + "TimeSeriesData", + "TimeSeriesDataPoint", "TimestampSplit", "TrainingConfig", "TrainingPipeline", "Trial", + "UndeployIndexOperationMetadata", + "UndeployIndexRequest", + "UndeployIndexResponse", "UndeployModelOperationMetadata", "UndeployModelRequest", "UndeployModelResponse", + "UnmanagedContainerModel", + "UpdateArtifactRequest", + "UpdateContextRequest", "UpdateDatasetRequest", "UpdateEndpointRequest", + "UpdateEntityTypeRequest", + "UpdateExecutionRequest", + "UpdateFeatureRequest", + "UpdateFeaturestoreOperationMetadata", + "UpdateFeaturestoreRequest", + "UpdateIndexEndpointRequest", + "UpdateIndexOperationMetadata", + "UpdateIndexRequest", + "UpdateModelDeploymentMonitoringJobOperationMetadata", + "UpdateModelDeploymentMonitoringJobRequest", "UpdateModelRequest", "UpdateSpecialistPoolOperationMetadata", "UpdateSpecialistPoolRequest", + "UpdateTensorboardExperimentRequest", + "UpdateTensorboardOperationMetadata", + "UpdateTensorboardRequest", + "UpdateTensorboardRunRequest", + "UpdateTensorboardTimeSeriesRequest", "UploadModelOperationMetadata", "UploadModelRequest", "UploadModelResponse", "UserActionReference", + "Value", + "VizierServiceClient", "WorkerPoolSpec", + "WriteTensorboardExperimentDataRequest", + "WriteTensorboardExperimentDataResponse", + "WriteTensorboardRunDataRequest", + "WriteTensorboardRunDataResponse", + "XraiAttribution", ) diff --git a/google/cloud/aiplatform_v1/gapic_metadata.json b/google/cloud/aiplatform_v1/gapic_metadata.json index 0abed0fd70..35cf881fe2 100644 --- a/google/cloud/aiplatform_v1/gapic_metadata.json +++ b/google/cloud/aiplatform_v1/gapic_metadata.json @@ -203,514 +203,1892 @@ } } }, - "JobService": { + "FeaturestoreOnlineServingService": { "clients": { "grpc": { - "libraryClient": "JobServiceClient", + "libraryClient": "FeaturestoreOnlineServingServiceClient", "rpcs": { - "CancelBatchPredictionJob": { + "ReadFeatureValues": { "methods": [ - "cancel_batch_prediction_job" + "read_feature_values" ] }, - "CancelCustomJob": { + "StreamingReadFeatureValues": { "methods": [ - "cancel_custom_job" + "streaming_read_feature_values" ] - }, - "CancelDataLabelingJob": { + } + } + }, + "grpc-async": { + "libraryClient": "FeaturestoreOnlineServingServiceAsyncClient", + "rpcs": { + "ReadFeatureValues": { "methods": [ - "cancel_data_labeling_job" + "read_feature_values" ] }, - "CancelHyperparameterTuningJob": { + "StreamingReadFeatureValues": { "methods": [ - "cancel_hyperparameter_tuning_job" + "streaming_read_feature_values" ] - }, - "CreateBatchPredictionJob": { + } + } + } + } + }, + "FeaturestoreService": { + "clients": { + "grpc": { + "libraryClient": "FeaturestoreServiceClient", + "rpcs": { + "BatchCreateFeatures": { "methods": [ - "create_batch_prediction_job" + "batch_create_features" ] }, - "CreateCustomJob": { + "BatchReadFeatureValues": { "methods": [ - "create_custom_job" + "batch_read_feature_values" ] }, - "CreateDataLabelingJob": { + "CreateEntityType": { "methods": [ - "create_data_labeling_job" + "create_entity_type" ] }, - "CreateHyperparameterTuningJob": { + "CreateFeature": { "methods": [ - "create_hyperparameter_tuning_job" + "create_feature" ] }, - "DeleteBatchPredictionJob": { + "CreateFeaturestore": { "methods": [ - "delete_batch_prediction_job" + "create_featurestore" ] }, - "DeleteCustomJob": { + "DeleteEntityType": { "methods": [ - "delete_custom_job" + "delete_entity_type" ] }, - "DeleteDataLabelingJob": { + "DeleteFeature": { "methods": [ - "delete_data_labeling_job" + "delete_feature" ] }, - "DeleteHyperparameterTuningJob": { + "DeleteFeaturestore": { "methods": [ - "delete_hyperparameter_tuning_job" + "delete_featurestore" ] }, - "GetBatchPredictionJob": { + "ExportFeatureValues": { "methods": [ - "get_batch_prediction_job" + "export_feature_values" ] }, - "GetCustomJob": { + "GetEntityType": { "methods": [ - "get_custom_job" + "get_entity_type" ] }, - "GetDataLabelingJob": { + "GetFeature": { "methods": [ - "get_data_labeling_job" + "get_feature" ] }, - "GetHyperparameterTuningJob": { + "GetFeaturestore": { "methods": [ - "get_hyperparameter_tuning_job" + "get_featurestore" ] }, - "ListBatchPredictionJobs": { + "ImportFeatureValues": { "methods": [ - "list_batch_prediction_jobs" + "import_feature_values" ] }, - "ListCustomJobs": { + "ListEntityTypes": { "methods": [ - "list_custom_jobs" + "list_entity_types" ] }, - "ListDataLabelingJobs": { + "ListFeatures": { "methods": [ - "list_data_labeling_jobs" + "list_features" ] }, - "ListHyperparameterTuningJobs": { + "ListFeaturestores": { "methods": [ - "list_hyperparameter_tuning_jobs" + "list_featurestores" ] - } - } - }, - "grpc-async": { - "libraryClient": "JobServiceAsyncClient", - "rpcs": { - "CancelBatchPredictionJob": { + }, + "SearchFeatures": { "methods": [ - "cancel_batch_prediction_job" + "search_features" ] }, - "CancelCustomJob": { + "UpdateEntityType": { "methods": [ - "cancel_custom_job" + "update_entity_type" ] }, - "CancelDataLabelingJob": { + "UpdateFeature": { "methods": [ - "cancel_data_labeling_job" + "update_feature" ] }, - "CancelHyperparameterTuningJob": { + "UpdateFeaturestore": { "methods": [ - "cancel_hyperparameter_tuning_job" + "update_featurestore" ] - }, - "CreateBatchPredictionJob": { + } + } + }, + "grpc-async": { + "libraryClient": "FeaturestoreServiceAsyncClient", + "rpcs": { + "BatchCreateFeatures": { "methods": [ - "create_batch_prediction_job" + "batch_create_features" ] }, - "CreateCustomJob": { + "BatchReadFeatureValues": { "methods": [ - "create_custom_job" + "batch_read_feature_values" ] }, - "CreateDataLabelingJob": { + "CreateEntityType": { "methods": [ - "create_data_labeling_job" + "create_entity_type" ] }, - "CreateHyperparameterTuningJob": { + "CreateFeature": { "methods": [ - "create_hyperparameter_tuning_job" + "create_feature" ] }, - "DeleteBatchPredictionJob": { + "CreateFeaturestore": { "methods": [ - "delete_batch_prediction_job" + "create_featurestore" ] }, - "DeleteCustomJob": { + "DeleteEntityType": { "methods": [ - "delete_custom_job" + "delete_entity_type" ] }, - "DeleteDataLabelingJob": { + "DeleteFeature": { "methods": [ - "delete_data_labeling_job" + "delete_feature" ] }, - "DeleteHyperparameterTuningJob": { + "DeleteFeaturestore": { "methods": [ - "delete_hyperparameter_tuning_job" + "delete_featurestore" ] }, - "GetBatchPredictionJob": { + "ExportFeatureValues": { "methods": [ - "get_batch_prediction_job" + "export_feature_values" ] }, - "GetCustomJob": { + "GetEntityType": { "methods": [ - "get_custom_job" + "get_entity_type" ] }, - "GetDataLabelingJob": { + "GetFeature": { "methods": [ - "get_data_labeling_job" + "get_feature" ] }, - "GetHyperparameterTuningJob": { + "GetFeaturestore": { "methods": [ - "get_hyperparameter_tuning_job" + "get_featurestore" ] }, - "ListBatchPredictionJobs": { + "ImportFeatureValues": { "methods": [ - "list_batch_prediction_jobs" + "import_feature_values" ] }, - "ListCustomJobs": { + "ListEntityTypes": { "methods": [ - "list_custom_jobs" + "list_entity_types" ] }, - "ListDataLabelingJobs": { + "ListFeatures": { "methods": [ - "list_data_labeling_jobs" + "list_features" ] }, - "ListHyperparameterTuningJobs": { + "ListFeaturestores": { "methods": [ - "list_hyperparameter_tuning_jobs" + "list_featurestores" ] - } - } - } - } - }, - "MigrationService": { - "clients": { - "grpc": { - "libraryClient": "MigrationServiceClient", - "rpcs": { - "BatchMigrateResources": { + }, + "SearchFeatures": { "methods": [ - "batch_migrate_resources" + "search_features" ] }, - "SearchMigratableResources": { + "UpdateEntityType": { "methods": [ - "search_migratable_resources" + "update_entity_type" ] - } - } - }, - "grpc-async": { - "libraryClient": "MigrationServiceAsyncClient", - "rpcs": { - "BatchMigrateResources": { + }, + "UpdateFeature": { "methods": [ - "batch_migrate_resources" + "update_feature" ] }, - "SearchMigratableResources": { + "UpdateFeaturestore": { "methods": [ - "search_migratable_resources" + "update_featurestore" ] } } } } }, - "ModelService": { + "IndexEndpointService": { "clients": { "grpc": { - "libraryClient": "ModelServiceClient", + "libraryClient": "IndexEndpointServiceClient", "rpcs": { - "DeleteModel": { - "methods": [ - "delete_model" - ] - }, - "ExportModel": { + "CreateIndexEndpoint": { "methods": [ - "export_model" - ] - }, - "GetModel": { - "methods": [ - "get_model" + "create_index_endpoint" ] }, - "GetModelEvaluation": { + "DeleteIndexEndpoint": { "methods": [ - "get_model_evaluation" + "delete_index_endpoint" ] }, - "GetModelEvaluationSlice": { + "DeployIndex": { "methods": [ - "get_model_evaluation_slice" + "deploy_index" ] }, - "ListModelEvaluationSlices": { + "GetIndexEndpoint": { "methods": [ - "list_model_evaluation_slices" + "get_index_endpoint" ] }, - "ListModelEvaluations": { + "ListIndexEndpoints": { "methods": [ - "list_model_evaluations" + "list_index_endpoints" ] }, - "ListModels": { + "MutateDeployedIndex": { "methods": [ - "list_models" + "mutate_deployed_index" ] }, - "UpdateModel": { + "UndeployIndex": { "methods": [ - "update_model" + "undeploy_index" ] }, - "UploadModel": { + "UpdateIndexEndpoint": { "methods": [ - "upload_model" + "update_index_endpoint" ] } } }, "grpc-async": { - "libraryClient": "ModelServiceAsyncClient", + "libraryClient": "IndexEndpointServiceAsyncClient", "rpcs": { - "DeleteModel": { - "methods": [ - "delete_model" - ] - }, - "ExportModel": { - "methods": [ - "export_model" - ] - }, - "GetModel": { + "CreateIndexEndpoint": { "methods": [ - "get_model" + "create_index_endpoint" ] }, - "GetModelEvaluation": { + "DeleteIndexEndpoint": { "methods": [ - "get_model_evaluation" + "delete_index_endpoint" ] }, - "GetModelEvaluationSlice": { + "DeployIndex": { "methods": [ - "get_model_evaluation_slice" + "deploy_index" ] }, - "ListModelEvaluationSlices": { + "GetIndexEndpoint": { "methods": [ - "list_model_evaluation_slices" + "get_index_endpoint" ] }, - "ListModelEvaluations": { + "ListIndexEndpoints": { "methods": [ - "list_model_evaluations" + "list_index_endpoints" ] }, - "ListModels": { + "MutateDeployedIndex": { "methods": [ - "list_models" + "mutate_deployed_index" ] }, - "UpdateModel": { + "UndeployIndex": { "methods": [ - "update_model" + "undeploy_index" ] }, - "UploadModel": { + "UpdateIndexEndpoint": { "methods": [ - "upload_model" + "update_index_endpoint" ] } } } } }, - "PipelineService": { + "IndexService": { "clients": { "grpc": { - "libraryClient": "PipelineServiceClient", + "libraryClient": "IndexServiceClient", "rpcs": { - "CancelTrainingPipeline": { + "CreateIndex": { "methods": [ - "cancel_training_pipeline" + "create_index" ] }, - "CreateTrainingPipeline": { + "DeleteIndex": { "methods": [ - "create_training_pipeline" + "delete_index" ] }, - "DeleteTrainingPipeline": { + "GetIndex": { "methods": [ - "delete_training_pipeline" + "get_index" ] }, - "GetTrainingPipeline": { + "ListIndexes": { "methods": [ - "get_training_pipeline" + "list_indexes" ] }, - "ListTrainingPipelines": { + "UpdateIndex": { "methods": [ - "list_training_pipelines" + "update_index" ] } } }, "grpc-async": { - "libraryClient": "PipelineServiceAsyncClient", + "libraryClient": "IndexServiceAsyncClient", "rpcs": { - "CancelTrainingPipeline": { + "CreateIndex": { "methods": [ - "cancel_training_pipeline" + "create_index" ] }, - "CreateTrainingPipeline": { + "DeleteIndex": { "methods": [ - "create_training_pipeline" + "delete_index" ] }, - "DeleteTrainingPipeline": { + "GetIndex": { "methods": [ - "delete_training_pipeline" + "get_index" ] }, - "GetTrainingPipeline": { + "ListIndexes": { "methods": [ - "get_training_pipeline" + "list_indexes" ] }, - "ListTrainingPipelines": { + "UpdateIndex": { "methods": [ - "list_training_pipelines" + "update_index" ] } } } } }, - "PredictionService": { + "JobService": { "clients": { "grpc": { - "libraryClient": "PredictionServiceClient", + "libraryClient": "JobServiceClient", "rpcs": { - "Predict": { + "CancelBatchPredictionJob": { "methods": [ - "predict" + "cancel_batch_prediction_job" ] - } - } - }, - "grpc-async": { - "libraryClient": "PredictionServiceAsyncClient", - "rpcs": { - "Predict": { + }, + "CancelCustomJob": { "methods": [ - "predict" + "cancel_custom_job" ] - } - } - } - } - }, - "SpecialistPoolService": { - "clients": { - "grpc": { - "libraryClient": "SpecialistPoolServiceClient", - "rpcs": { - "CreateSpecialistPool": { + }, + "CancelDataLabelingJob": { "methods": [ - "create_specialist_pool" + "cancel_data_labeling_job" ] }, - "DeleteSpecialistPool": { + "CancelHyperparameterTuningJob": { "methods": [ - "delete_specialist_pool" + "cancel_hyperparameter_tuning_job" ] }, - "GetSpecialistPool": { + "CreateBatchPredictionJob": { "methods": [ - "get_specialist_pool" + "create_batch_prediction_job" + ] + }, + "CreateCustomJob": { + "methods": [ + "create_custom_job" + ] + }, + "CreateDataLabelingJob": { + "methods": [ + "create_data_labeling_job" + ] + }, + "CreateHyperparameterTuningJob": { + "methods": [ + "create_hyperparameter_tuning_job" + ] + }, + "CreateModelDeploymentMonitoringJob": { + "methods": [ + "create_model_deployment_monitoring_job" + ] + }, + "DeleteBatchPredictionJob": { + "methods": [ + "delete_batch_prediction_job" + ] + }, + "DeleteCustomJob": { + "methods": [ + "delete_custom_job" + ] + }, + "DeleteDataLabelingJob": { + "methods": [ + "delete_data_labeling_job" + ] + }, + "DeleteHyperparameterTuningJob": { + "methods": [ + "delete_hyperparameter_tuning_job" + ] + }, + "DeleteModelDeploymentMonitoringJob": { + "methods": [ + "delete_model_deployment_monitoring_job" + ] + }, + "GetBatchPredictionJob": { + "methods": [ + "get_batch_prediction_job" + ] + }, + "GetCustomJob": { + "methods": [ + "get_custom_job" + ] + }, + "GetDataLabelingJob": { + "methods": [ + "get_data_labeling_job" + ] + }, + "GetHyperparameterTuningJob": { + "methods": [ + "get_hyperparameter_tuning_job" + ] + }, + "GetModelDeploymentMonitoringJob": { + "methods": [ + "get_model_deployment_monitoring_job" + ] + }, + "ListBatchPredictionJobs": { + "methods": [ + "list_batch_prediction_jobs" + ] + }, + "ListCustomJobs": { + "methods": [ + "list_custom_jobs" + ] + }, + "ListDataLabelingJobs": { + "methods": [ + "list_data_labeling_jobs" + ] + }, + "ListHyperparameterTuningJobs": { + "methods": [ + "list_hyperparameter_tuning_jobs" + ] + }, + "ListModelDeploymentMonitoringJobs": { + "methods": [ + "list_model_deployment_monitoring_jobs" + ] + }, + "PauseModelDeploymentMonitoringJob": { + "methods": [ + "pause_model_deployment_monitoring_job" + ] + }, + "ResumeModelDeploymentMonitoringJob": { + "methods": [ + "resume_model_deployment_monitoring_job" + ] + }, + "SearchModelDeploymentMonitoringStatsAnomalies": { + "methods": [ + "search_model_deployment_monitoring_stats_anomalies" + ] + }, + "UpdateModelDeploymentMonitoringJob": { + "methods": [ + "update_model_deployment_monitoring_job" + ] + } + } + }, + "grpc-async": { + "libraryClient": "JobServiceAsyncClient", + "rpcs": { + "CancelBatchPredictionJob": { + "methods": [ + "cancel_batch_prediction_job" + ] + }, + "CancelCustomJob": { + "methods": [ + "cancel_custom_job" + ] + }, + "CancelDataLabelingJob": { + "methods": [ + "cancel_data_labeling_job" + ] + }, + "CancelHyperparameterTuningJob": { + "methods": [ + "cancel_hyperparameter_tuning_job" + ] + }, + "CreateBatchPredictionJob": { + "methods": [ + "create_batch_prediction_job" + ] + }, + "CreateCustomJob": { + "methods": [ + "create_custom_job" + ] + }, + "CreateDataLabelingJob": { + "methods": [ + "create_data_labeling_job" + ] + }, + "CreateHyperparameterTuningJob": { + "methods": [ + "create_hyperparameter_tuning_job" + ] + }, + "CreateModelDeploymentMonitoringJob": { + "methods": [ + "create_model_deployment_monitoring_job" + ] + }, + "DeleteBatchPredictionJob": { + "methods": [ + "delete_batch_prediction_job" + ] + }, + "DeleteCustomJob": { + "methods": [ + "delete_custom_job" + ] + }, + "DeleteDataLabelingJob": { + "methods": [ + "delete_data_labeling_job" + ] + }, + "DeleteHyperparameterTuningJob": { + "methods": [ + "delete_hyperparameter_tuning_job" + ] + }, + "DeleteModelDeploymentMonitoringJob": { + "methods": [ + "delete_model_deployment_monitoring_job" + ] + }, + "GetBatchPredictionJob": { + "methods": [ + "get_batch_prediction_job" + ] + }, + "GetCustomJob": { + "methods": [ + "get_custom_job" + ] + }, + "GetDataLabelingJob": { + "methods": [ + "get_data_labeling_job" + ] + }, + "GetHyperparameterTuningJob": { + "methods": [ + "get_hyperparameter_tuning_job" + ] + }, + "GetModelDeploymentMonitoringJob": { + "methods": [ + "get_model_deployment_monitoring_job" + ] + }, + "ListBatchPredictionJobs": { + "methods": [ + "list_batch_prediction_jobs" + ] + }, + "ListCustomJobs": { + "methods": [ + "list_custom_jobs" + ] + }, + "ListDataLabelingJobs": { + "methods": [ + "list_data_labeling_jobs" + ] + }, + "ListHyperparameterTuningJobs": { + "methods": [ + "list_hyperparameter_tuning_jobs" + ] + }, + "ListModelDeploymentMonitoringJobs": { + "methods": [ + "list_model_deployment_monitoring_jobs" + ] + }, + "PauseModelDeploymentMonitoringJob": { + "methods": [ + "pause_model_deployment_monitoring_job" + ] + }, + "ResumeModelDeploymentMonitoringJob": { + "methods": [ + "resume_model_deployment_monitoring_job" + ] + }, + "SearchModelDeploymentMonitoringStatsAnomalies": { + "methods": [ + "search_model_deployment_monitoring_stats_anomalies" + ] + }, + "UpdateModelDeploymentMonitoringJob": { + "methods": [ + "update_model_deployment_monitoring_job" + ] + } + } + } + } + }, + "MetadataService": { + "clients": { + "grpc": { + "libraryClient": "MetadataServiceClient", + "rpcs": { + "AddContextArtifactsAndExecutions": { + "methods": [ + "add_context_artifacts_and_executions" + ] + }, + "AddContextChildren": { + "methods": [ + "add_context_children" + ] + }, + "AddExecutionEvents": { + "methods": [ + "add_execution_events" + ] + }, + "CreateArtifact": { + "methods": [ + "create_artifact" + ] + }, + "CreateContext": { + "methods": [ + "create_context" + ] + }, + "CreateExecution": { + "methods": [ + "create_execution" + ] + }, + "CreateMetadataSchema": { + "methods": [ + "create_metadata_schema" + ] + }, + "CreateMetadataStore": { + "methods": [ + "create_metadata_store" + ] + }, + "DeleteArtifact": { + "methods": [ + "delete_artifact" + ] + }, + "DeleteContext": { + "methods": [ + "delete_context" + ] + }, + "DeleteExecution": { + "methods": [ + "delete_execution" + ] + }, + "DeleteMetadataStore": { + "methods": [ + "delete_metadata_store" + ] + }, + "GetArtifact": { + "methods": [ + "get_artifact" + ] + }, + "GetContext": { + "methods": [ + "get_context" + ] + }, + "GetExecution": { + "methods": [ + "get_execution" + ] + }, + "GetMetadataSchema": { + "methods": [ + "get_metadata_schema" + ] + }, + "GetMetadataStore": { + "methods": [ + "get_metadata_store" + ] + }, + "ListArtifacts": { + "methods": [ + "list_artifacts" + ] + }, + "ListContexts": { + "methods": [ + "list_contexts" + ] + }, + "ListExecutions": { + "methods": [ + "list_executions" + ] + }, + "ListMetadataSchemas": { + "methods": [ + "list_metadata_schemas" + ] + }, + "ListMetadataStores": { + "methods": [ + "list_metadata_stores" + ] + }, + "PurgeArtifacts": { + "methods": [ + "purge_artifacts" + ] + }, + "PurgeContexts": { + "methods": [ + "purge_contexts" + ] + }, + "PurgeExecutions": { + "methods": [ + "purge_executions" + ] + }, + "QueryArtifactLineageSubgraph": { + "methods": [ + "query_artifact_lineage_subgraph" + ] + }, + "QueryContextLineageSubgraph": { + "methods": [ + "query_context_lineage_subgraph" + ] + }, + "QueryExecutionInputsAndOutputs": { + "methods": [ + "query_execution_inputs_and_outputs" + ] + }, + "UpdateArtifact": { + "methods": [ + "update_artifact" + ] + }, + "UpdateContext": { + "methods": [ + "update_context" + ] + }, + "UpdateExecution": { + "methods": [ + "update_execution" + ] + } + } + }, + "grpc-async": { + "libraryClient": "MetadataServiceAsyncClient", + "rpcs": { + "AddContextArtifactsAndExecutions": { + "methods": [ + "add_context_artifacts_and_executions" + ] + }, + "AddContextChildren": { + "methods": [ + "add_context_children" + ] + }, + "AddExecutionEvents": { + "methods": [ + "add_execution_events" + ] + }, + "CreateArtifact": { + "methods": [ + "create_artifact" + ] + }, + "CreateContext": { + "methods": [ + "create_context" + ] + }, + "CreateExecution": { + "methods": [ + "create_execution" + ] + }, + "CreateMetadataSchema": { + "methods": [ + "create_metadata_schema" + ] + }, + "CreateMetadataStore": { + "methods": [ + "create_metadata_store" + ] + }, + "DeleteArtifact": { + "methods": [ + "delete_artifact" + ] + }, + "DeleteContext": { + "methods": [ + "delete_context" + ] + }, + "DeleteExecution": { + "methods": [ + "delete_execution" + ] + }, + "DeleteMetadataStore": { + "methods": [ + "delete_metadata_store" + ] + }, + "GetArtifact": { + "methods": [ + "get_artifact" + ] + }, + "GetContext": { + "methods": [ + "get_context" + ] + }, + "GetExecution": { + "methods": [ + "get_execution" + ] + }, + "GetMetadataSchema": { + "methods": [ + "get_metadata_schema" + ] + }, + "GetMetadataStore": { + "methods": [ + "get_metadata_store" + ] + }, + "ListArtifacts": { + "methods": [ + "list_artifacts" + ] + }, + "ListContexts": { + "methods": [ + "list_contexts" + ] + }, + "ListExecutions": { + "methods": [ + "list_executions" + ] + }, + "ListMetadataSchemas": { + "methods": [ + "list_metadata_schemas" + ] + }, + "ListMetadataStores": { + "methods": [ + "list_metadata_stores" + ] + }, + "PurgeArtifacts": { + "methods": [ + "purge_artifacts" + ] + }, + "PurgeContexts": { + "methods": [ + "purge_contexts" + ] + }, + "PurgeExecutions": { + "methods": [ + "purge_executions" + ] + }, + "QueryArtifactLineageSubgraph": { + "methods": [ + "query_artifact_lineage_subgraph" + ] + }, + "QueryContextLineageSubgraph": { + "methods": [ + "query_context_lineage_subgraph" + ] + }, + "QueryExecutionInputsAndOutputs": { + "methods": [ + "query_execution_inputs_and_outputs" + ] + }, + "UpdateArtifact": { + "methods": [ + "update_artifact" + ] + }, + "UpdateContext": { + "methods": [ + "update_context" + ] + }, + "UpdateExecution": { + "methods": [ + "update_execution" + ] + } + } + } + } + }, + "MigrationService": { + "clients": { + "grpc": { + "libraryClient": "MigrationServiceClient", + "rpcs": { + "BatchMigrateResources": { + "methods": [ + "batch_migrate_resources" + ] + }, + "SearchMigratableResources": { + "methods": [ + "search_migratable_resources" + ] + } + } + }, + "grpc-async": { + "libraryClient": "MigrationServiceAsyncClient", + "rpcs": { + "BatchMigrateResources": { + "methods": [ + "batch_migrate_resources" + ] + }, + "SearchMigratableResources": { + "methods": [ + "search_migratable_resources" + ] + } + } + } + } + }, + "ModelService": { + "clients": { + "grpc": { + "libraryClient": "ModelServiceClient", + "rpcs": { + "DeleteModel": { + "methods": [ + "delete_model" + ] + }, + "DeleteModelVersion": { + "methods": [ + "delete_model_version" + ] + }, + "ExportModel": { + "methods": [ + "export_model" + ] + }, + "GetModel": { + "methods": [ + "get_model" + ] + }, + "GetModelEvaluation": { + "methods": [ + "get_model_evaluation" + ] + }, + "GetModelEvaluationSlice": { + "methods": [ + "get_model_evaluation_slice" + ] + }, + "ImportModelEvaluation": { + "methods": [ + "import_model_evaluation" + ] + }, + "ListModelEvaluationSlices": { + "methods": [ + "list_model_evaluation_slices" + ] + }, + "ListModelEvaluations": { + "methods": [ + "list_model_evaluations" + ] + }, + "ListModelVersions": { + "methods": [ + "list_model_versions" + ] + }, + "ListModels": { + "methods": [ + "list_models" + ] + }, + "MergeVersionAliases": { + "methods": [ + "merge_version_aliases" + ] + }, + "UpdateModel": { + "methods": [ + "update_model" + ] + }, + "UploadModel": { + "methods": [ + "upload_model" + ] + } + } + }, + "grpc-async": { + "libraryClient": "ModelServiceAsyncClient", + "rpcs": { + "DeleteModel": { + "methods": [ + "delete_model" + ] + }, + "DeleteModelVersion": { + "methods": [ + "delete_model_version" + ] + }, + "ExportModel": { + "methods": [ + "export_model" + ] + }, + "GetModel": { + "methods": [ + "get_model" + ] + }, + "GetModelEvaluation": { + "methods": [ + "get_model_evaluation" + ] + }, + "GetModelEvaluationSlice": { + "methods": [ + "get_model_evaluation_slice" + ] + }, + "ImportModelEvaluation": { + "methods": [ + "import_model_evaluation" + ] + }, + "ListModelEvaluationSlices": { + "methods": [ + "list_model_evaluation_slices" + ] + }, + "ListModelEvaluations": { + "methods": [ + "list_model_evaluations" + ] + }, + "ListModelVersions": { + "methods": [ + "list_model_versions" + ] + }, + "ListModels": { + "methods": [ + "list_models" + ] + }, + "MergeVersionAliases": { + "methods": [ + "merge_version_aliases" + ] + }, + "UpdateModel": { + "methods": [ + "update_model" + ] + }, + "UploadModel": { + "methods": [ + "upload_model" + ] + } + } + } + } + }, + "PipelineService": { + "clients": { + "grpc": { + "libraryClient": "PipelineServiceClient", + "rpcs": { + "CancelPipelineJob": { + "methods": [ + "cancel_pipeline_job" + ] + }, + "CancelTrainingPipeline": { + "methods": [ + "cancel_training_pipeline" + ] + }, + "CreatePipelineJob": { + "methods": [ + "create_pipeline_job" + ] + }, + "CreateTrainingPipeline": { + "methods": [ + "create_training_pipeline" + ] + }, + "DeletePipelineJob": { + "methods": [ + "delete_pipeline_job" + ] + }, + "DeleteTrainingPipeline": { + "methods": [ + "delete_training_pipeline" + ] + }, + "GetPipelineJob": { + "methods": [ + "get_pipeline_job" + ] + }, + "GetTrainingPipeline": { + "methods": [ + "get_training_pipeline" + ] + }, + "ListPipelineJobs": { + "methods": [ + "list_pipeline_jobs" + ] + }, + "ListTrainingPipelines": { + "methods": [ + "list_training_pipelines" + ] + } + } + }, + "grpc-async": { + "libraryClient": "PipelineServiceAsyncClient", + "rpcs": { + "CancelPipelineJob": { + "methods": [ + "cancel_pipeline_job" + ] + }, + "CancelTrainingPipeline": { + "methods": [ + "cancel_training_pipeline" + ] + }, + "CreatePipelineJob": { + "methods": [ + "create_pipeline_job" + ] + }, + "CreateTrainingPipeline": { + "methods": [ + "create_training_pipeline" + ] + }, + "DeletePipelineJob": { + "methods": [ + "delete_pipeline_job" + ] + }, + "DeleteTrainingPipeline": { + "methods": [ + "delete_training_pipeline" + ] + }, + "GetPipelineJob": { + "methods": [ + "get_pipeline_job" + ] + }, + "GetTrainingPipeline": { + "methods": [ + "get_training_pipeline" + ] + }, + "ListPipelineJobs": { + "methods": [ + "list_pipeline_jobs" + ] + }, + "ListTrainingPipelines": { + "methods": [ + "list_training_pipelines" + ] + } + } + } + } + }, + "PredictionService": { + "clients": { + "grpc": { + "libraryClient": "PredictionServiceClient", + "rpcs": { + "Explain": { + "methods": [ + "explain" + ] + }, + "Predict": { + "methods": [ + "predict" + ] + }, + "RawPredict": { + "methods": [ + "raw_predict" + ] + } + } + }, + "grpc-async": { + "libraryClient": "PredictionServiceAsyncClient", + "rpcs": { + "Explain": { + "methods": [ + "explain" + ] + }, + "Predict": { + "methods": [ + "predict" + ] + }, + "RawPredict": { + "methods": [ + "raw_predict" + ] + } + } + } + } + }, + "SpecialistPoolService": { + "clients": { + "grpc": { + "libraryClient": "SpecialistPoolServiceClient", + "rpcs": { + "CreateSpecialistPool": { + "methods": [ + "create_specialist_pool" + ] + }, + "DeleteSpecialistPool": { + "methods": [ + "delete_specialist_pool" + ] + }, + "GetSpecialistPool": { + "methods": [ + "get_specialist_pool" + ] + }, + "ListSpecialistPools": { + "methods": [ + "list_specialist_pools" + ] + }, + "UpdateSpecialistPool": { + "methods": [ + "update_specialist_pool" + ] + } + } + }, + "grpc-async": { + "libraryClient": "SpecialistPoolServiceAsyncClient", + "rpcs": { + "CreateSpecialistPool": { + "methods": [ + "create_specialist_pool" + ] + }, + "DeleteSpecialistPool": { + "methods": [ + "delete_specialist_pool" + ] + }, + "GetSpecialistPool": { + "methods": [ + "get_specialist_pool" ] }, "ListSpecialistPools": { "methods": [ - "list_specialist_pools" + "list_specialist_pools" + ] + }, + "UpdateSpecialistPool": { + "methods": [ + "update_specialist_pool" + ] + } + } + } + } + }, + "TensorboardService": { + "clients": { + "grpc": { + "libraryClient": "TensorboardServiceClient", + "rpcs": { + "BatchCreateTensorboardRuns": { + "methods": [ + "batch_create_tensorboard_runs" + ] + }, + "BatchCreateTensorboardTimeSeries": { + "methods": [ + "batch_create_tensorboard_time_series" + ] + }, + "BatchReadTensorboardTimeSeriesData": { + "methods": [ + "batch_read_tensorboard_time_series_data" ] }, - "UpdateSpecialistPool": { + "CreateTensorboard": { "methods": [ - "update_specialist_pool" + "create_tensorboard" + ] + }, + "CreateTensorboardExperiment": { + "methods": [ + "create_tensorboard_experiment" + ] + }, + "CreateTensorboardRun": { + "methods": [ + "create_tensorboard_run" + ] + }, + "CreateTensorboardTimeSeries": { + "methods": [ + "create_tensorboard_time_series" + ] + }, + "DeleteTensorboard": { + "methods": [ + "delete_tensorboard" + ] + }, + "DeleteTensorboardExperiment": { + "methods": [ + "delete_tensorboard_experiment" + ] + }, + "DeleteTensorboardRun": { + "methods": [ + "delete_tensorboard_run" + ] + }, + "DeleteTensorboardTimeSeries": { + "methods": [ + "delete_tensorboard_time_series" + ] + }, + "ExportTensorboardTimeSeriesData": { + "methods": [ + "export_tensorboard_time_series_data" + ] + }, + "GetTensorboard": { + "methods": [ + "get_tensorboard" + ] + }, + "GetTensorboardExperiment": { + "methods": [ + "get_tensorboard_experiment" + ] + }, + "GetTensorboardRun": { + "methods": [ + "get_tensorboard_run" + ] + }, + "GetTensorboardTimeSeries": { + "methods": [ + "get_tensorboard_time_series" + ] + }, + "ListTensorboardExperiments": { + "methods": [ + "list_tensorboard_experiments" + ] + }, + "ListTensorboardRuns": { + "methods": [ + "list_tensorboard_runs" + ] + }, + "ListTensorboardTimeSeries": { + "methods": [ + "list_tensorboard_time_series" + ] + }, + "ListTensorboards": { + "methods": [ + "list_tensorboards" + ] + }, + "ReadTensorboardBlobData": { + "methods": [ + "read_tensorboard_blob_data" + ] + }, + "ReadTensorboardTimeSeriesData": { + "methods": [ + "read_tensorboard_time_series_data" + ] + }, + "UpdateTensorboard": { + "methods": [ + "update_tensorboard" + ] + }, + "UpdateTensorboardExperiment": { + "methods": [ + "update_tensorboard_experiment" + ] + }, + "UpdateTensorboardRun": { + "methods": [ + "update_tensorboard_run" + ] + }, + "UpdateTensorboardTimeSeries": { + "methods": [ + "update_tensorboard_time_series" + ] + }, + "WriteTensorboardExperimentData": { + "methods": [ + "write_tensorboard_experiment_data" + ] + }, + "WriteTensorboardRunData": { + "methods": [ + "write_tensorboard_run_data" ] } } }, "grpc-async": { - "libraryClient": "SpecialistPoolServiceAsyncClient", + "libraryClient": "TensorboardServiceAsyncClient", "rpcs": { - "CreateSpecialistPool": { + "BatchCreateTensorboardRuns": { "methods": [ - "create_specialist_pool" + "batch_create_tensorboard_runs" ] }, - "DeleteSpecialistPool": { + "BatchCreateTensorboardTimeSeries": { "methods": [ - "delete_specialist_pool" + "batch_create_tensorboard_time_series" ] }, - "GetSpecialistPool": { + "BatchReadTensorboardTimeSeriesData": { "methods": [ - "get_specialist_pool" + "batch_read_tensorboard_time_series_data" ] }, - "ListSpecialistPools": { + "CreateTensorboard": { "methods": [ - "list_specialist_pools" + "create_tensorboard" ] }, - "UpdateSpecialistPool": { + "CreateTensorboardExperiment": { "methods": [ - "update_specialist_pool" + "create_tensorboard_experiment" + ] + }, + "CreateTensorboardRun": { + "methods": [ + "create_tensorboard_run" + ] + }, + "CreateTensorboardTimeSeries": { + "methods": [ + "create_tensorboard_time_series" + ] + }, + "DeleteTensorboard": { + "methods": [ + "delete_tensorboard" + ] + }, + "DeleteTensorboardExperiment": { + "methods": [ + "delete_tensorboard_experiment" + ] + }, + "DeleteTensorboardRun": { + "methods": [ + "delete_tensorboard_run" + ] + }, + "DeleteTensorboardTimeSeries": { + "methods": [ + "delete_tensorboard_time_series" + ] + }, + "ExportTensorboardTimeSeriesData": { + "methods": [ + "export_tensorboard_time_series_data" + ] + }, + "GetTensorboard": { + "methods": [ + "get_tensorboard" + ] + }, + "GetTensorboardExperiment": { + "methods": [ + "get_tensorboard_experiment" + ] + }, + "GetTensorboardRun": { + "methods": [ + "get_tensorboard_run" + ] + }, + "GetTensorboardTimeSeries": { + "methods": [ + "get_tensorboard_time_series" + ] + }, + "ListTensorboardExperiments": { + "methods": [ + "list_tensorboard_experiments" + ] + }, + "ListTensorboardRuns": { + "methods": [ + "list_tensorboard_runs" + ] + }, + "ListTensorboardTimeSeries": { + "methods": [ + "list_tensorboard_time_series" + ] + }, + "ListTensorboards": { + "methods": [ + "list_tensorboards" + ] + }, + "ReadTensorboardBlobData": { + "methods": [ + "read_tensorboard_blob_data" + ] + }, + "ReadTensorboardTimeSeriesData": { + "methods": [ + "read_tensorboard_time_series_data" + ] + }, + "UpdateTensorboard": { + "methods": [ + "update_tensorboard" + ] + }, + "UpdateTensorboardExperiment": { + "methods": [ + "update_tensorboard_experiment" + ] + }, + "UpdateTensorboardRun": { + "methods": [ + "update_tensorboard_run" + ] + }, + "UpdateTensorboardTimeSeries": { + "methods": [ + "update_tensorboard_time_series" + ] + }, + "WriteTensorboardExperimentData": { + "methods": [ + "write_tensorboard_experiment_data" + ] + }, + "WriteTensorboardRunData": { + "methods": [ + "write_tensorboard_run_data" + ] + } + } + } + } + }, + "VizierService": { + "clients": { + "grpc": { + "libraryClient": "VizierServiceClient", + "rpcs": { + "AddTrialMeasurement": { + "methods": [ + "add_trial_measurement" + ] + }, + "CheckTrialEarlyStoppingState": { + "methods": [ + "check_trial_early_stopping_state" + ] + }, + "CompleteTrial": { + "methods": [ + "complete_trial" + ] + }, + "CreateStudy": { + "methods": [ + "create_study" + ] + }, + "CreateTrial": { + "methods": [ + "create_trial" + ] + }, + "DeleteStudy": { + "methods": [ + "delete_study" + ] + }, + "DeleteTrial": { + "methods": [ + "delete_trial" + ] + }, + "GetStudy": { + "methods": [ + "get_study" + ] + }, + "GetTrial": { + "methods": [ + "get_trial" + ] + }, + "ListOptimalTrials": { + "methods": [ + "list_optimal_trials" + ] + }, + "ListStudies": { + "methods": [ + "list_studies" + ] + }, + "ListTrials": { + "methods": [ + "list_trials" + ] + }, + "LookupStudy": { + "methods": [ + "lookup_study" + ] + }, + "StopTrial": { + "methods": [ + "stop_trial" + ] + }, + "SuggestTrials": { + "methods": [ + "suggest_trials" + ] + } + } + }, + "grpc-async": { + "libraryClient": "VizierServiceAsyncClient", + "rpcs": { + "AddTrialMeasurement": { + "methods": [ + "add_trial_measurement" + ] + }, + "CheckTrialEarlyStoppingState": { + "methods": [ + "check_trial_early_stopping_state" + ] + }, + "CompleteTrial": { + "methods": [ + "complete_trial" + ] + }, + "CreateStudy": { + "methods": [ + "create_study" + ] + }, + "CreateTrial": { + "methods": [ + "create_trial" + ] + }, + "DeleteStudy": { + "methods": [ + "delete_study" + ] + }, + "DeleteTrial": { + "methods": [ + "delete_trial" + ] + }, + "GetStudy": { + "methods": [ + "get_study" + ] + }, + "GetTrial": { + "methods": [ + "get_trial" + ] + }, + "ListOptimalTrials": { + "methods": [ + "list_optimal_trials" + ] + }, + "ListStudies": { + "methods": [ + "list_studies" + ] + }, + "ListTrials": { + "methods": [ + "list_trials" + ] + }, + "LookupStudy": { + "methods": [ + "lookup_study" + ] + }, + "StopTrial": { + "methods": [ + "stop_trial" + ] + }, + "SuggestTrials": { + "methods": [ + "suggest_trials" ] } } diff --git a/google/cloud/aiplatform_v1/services/__init__.py b/google/cloud/aiplatform_v1/services/__init__.py index 4de65971c2..e8e1c3845d 100644 --- a/google/cloud/aiplatform_v1/services/__init__.py +++ b/google/cloud/aiplatform_v1/services/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1/services/dataset_service/__init__.py b/google/cloud/aiplatform_v1/services/dataset_service/__init__.py index 42adf5e5af..163172b9a0 100644 --- a/google/cloud/aiplatform_v1/services/dataset_service/__init__.py +++ b/google/cloud/aiplatform_v1/services/dataset_service/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1/services/dataset_service/async_client.py b/google/cloud/aiplatform_v1/services/dataset_service/async_client.py index b937183e37..51397c4189 100644 --- a/google/cloud/aiplatform_v1/services/dataset_service/async_client.py +++ b/google/cloud/aiplatform_v1/services/dataset_service/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,16 +16,21 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation as gac_operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1.services.dataset_service import pagers @@ -37,6 +42,10 @@ from google.cloud.aiplatform_v1.types import dataset_service from google.cloud.aiplatform_v1.types import encryption_spec from google.cloud.aiplatform_v1.types import operation as gca_operation +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import struct_pb2 # type: ignore @@ -47,7 +56,9 @@ class DatasetServiceAsyncClient: - """""" + """The service that handles the CRUD of Vertex AI Dataset and + its child resources. + """ _client: DatasetServiceClient @@ -91,7 +102,8 @@ class DatasetServiceAsyncClient: @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -106,7 +118,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -121,9 +133,45 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return DatasetServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> DatasetServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: DatasetServiceTransport: The transport used by the client instance. @@ -142,7 +190,7 @@ def __init__( client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the dataset service client. + """Instantiates the dataset service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -183,18 +231,47 @@ def __init__( async def create_dataset( self, - request: dataset_service.CreateDatasetRequest = None, + request: Union[dataset_service.CreateDatasetRequest, dict] = None, *, parent: str = None, dataset: gca_dataset.Dataset = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Creates a Dataset. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_create_dataset(): + # Create a client + client = aiplatform_v1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + dataset = aiplatform_v1.Dataset() + dataset.display_name = "display_name_value" + dataset.metadata_schema_uri = "metadata_schema_uri_value" + dataset.metadata.null_value = "NULL_VALUE" + + request = aiplatform_v1.CreateDatasetRequest( + parent="parent_value", + dataset=dataset, + ) + + # Make the request + operation = client.create_dataset(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.CreateDatasetRequest`): + request (Union[google.cloud.aiplatform_v1.types.CreateDatasetRequest, dict]): The request object. Request message for [DatasetService.CreateDataset][google.cloud.aiplatform.v1.DatasetService.CreateDataset]. parent (:class:`str`): @@ -226,7 +303,7 @@ async def create_dataset( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, dataset]) if request is not None and has_flattened_params: @@ -248,7 +325,7 @@ async def create_dataset( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.create_dataset, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -259,7 +336,12 @@ async def create_dataset( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -274,17 +356,36 @@ async def create_dataset( async def get_dataset( self, - request: dataset_service.GetDatasetRequest = None, + request: Union[dataset_service.GetDatasetRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> dataset.Dataset: r"""Gets a Dataset. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_get_dataset(): + # Create a client + client = aiplatform_v1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetDatasetRequest( + name="name_value", + ) + + # Make the request + response = await client.get_dataset(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.GetDatasetRequest`): + request (Union[google.cloud.aiplatform_v1.types.GetDatasetRequest, dict]): The request object. Request message for [DatasetService.GetDataset][google.cloud.aiplatform.v1.DatasetService.GetDataset]. name (:class:`str`): @@ -307,7 +408,7 @@ async def get_dataset( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -327,7 +428,7 @@ async def get_dataset( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.get_dataset, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -338,25 +439,54 @@ async def get_dataset( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def update_dataset( self, - request: dataset_service.UpdateDatasetRequest = None, + request: Union[dataset_service.UpdateDatasetRequest, dict] = None, *, dataset: gca_dataset.Dataset = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_dataset.Dataset: r"""Updates a Dataset. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_update_dataset(): + # Create a client + client = aiplatform_v1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + dataset = aiplatform_v1.Dataset() + dataset.display_name = "display_name_value" + dataset.metadata_schema_uri = "metadata_schema_uri_value" + dataset.metadata.null_value = "NULL_VALUE" + + request = aiplatform_v1.UpdateDatasetRequest( + dataset=dataset, + ) + + # Make the request + response = await client.update_dataset(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.UpdateDatasetRequest`): + request (Union[google.cloud.aiplatform_v1.types.UpdateDatasetRequest, dict]): The request object. Request message for [DatasetService.UpdateDataset][google.cloud.aiplatform.v1.DatasetService.UpdateDataset]. dataset (:class:`google.cloud.aiplatform_v1.types.Dataset`): @@ -369,7 +499,7 @@ async def update_dataset( update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): Required. The update mask applies to the resource. For the ``FieldMask`` definition, see - `FieldMask `__. + [google.protobuf.FieldMask][google.protobuf.FieldMask]. Updatable fields: - ``display_name`` @@ -392,7 +522,7 @@ async def update_dataset( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([dataset, update_mask]) if request is not None and has_flattened_params: @@ -414,7 +544,7 @@ async def update_dataset( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.update_dataset, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -427,24 +557,49 @@ async def update_dataset( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_datasets( self, - request: dataset_service.ListDatasetsRequest = None, + request: Union[dataset_service.ListDatasetsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListDatasetsAsyncPager: r"""Lists Datasets in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_list_datasets(): + # Create a client + client = aiplatform_v1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListDatasetsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_datasets(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.ListDatasetsRequest`): + request (Union[google.cloud.aiplatform_v1.types.ListDatasetsRequest, dict]): The request object. Request message for [DatasetService.ListDatasets][google.cloud.aiplatform.v1.DatasetService.ListDatasets]. parent (:class:`str`): @@ -470,7 +625,7 @@ async def list_datasets( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -490,7 +645,7 @@ async def list_datasets( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.list_datasets, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -501,12 +656,20 @@ async def list_datasets( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListDatasetsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -514,17 +677,40 @@ async def list_datasets( async def delete_dataset( self, - request: dataset_service.DeleteDatasetRequest = None, + request: Union[dataset_service.DeleteDatasetRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a Dataset. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_delete_dataset(): + # Create a client + client = aiplatform_v1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteDatasetRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_dataset(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.DeleteDatasetRequest`): + request (Union[google.cloud.aiplatform_v1.types.DeleteDatasetRequest, dict]): The request object. Request message for [DatasetService.DeleteDataset][google.cloud.aiplatform.v1.DatasetService.DeleteDataset]. name (:class:`str`): @@ -561,7 +747,7 @@ async def delete_dataset( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -581,7 +767,7 @@ async def delete_dataset( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.delete_dataset, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -592,7 +778,12 @@ async def delete_dataset( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -607,18 +798,46 @@ async def delete_dataset( async def import_data( self, - request: dataset_service.ImportDataRequest = None, + request: Union[dataset_service.ImportDataRequest, dict] = None, *, name: str = None, import_configs: Sequence[dataset.ImportDataConfig] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Imports data into a Dataset. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_import_data(): + # Create a client + client = aiplatform_v1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + import_configs = aiplatform_v1.ImportDataConfig() + import_configs.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + import_configs.import_schema_uri = "import_schema_uri_value" + + request = aiplatform_v1.ImportDataRequest( + name="name_value", + import_configs=import_configs, + ) + + # Make the request + operation = client.import_data(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.ImportDataRequest`): + request (Union[google.cloud.aiplatform_v1.types.ImportDataRequest, dict]): The request object. Request message for [DatasetService.ImportData][google.cloud.aiplatform.v1.DatasetService.ImportData]. name (:class:`str`): @@ -653,7 +872,7 @@ async def import_data( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, import_configs]) if request is not None and has_flattened_params: @@ -675,7 +894,7 @@ async def import_data( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.import_data, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -686,7 +905,12 @@ async def import_data( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -701,18 +925,45 @@ async def import_data( async def export_data( self, - request: dataset_service.ExportDataRequest = None, + request: Union[dataset_service.ExportDataRequest, dict] = None, *, name: str = None, export_config: dataset.ExportDataConfig = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Exports data from a Dataset. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_export_data(): + # Create a client + client = aiplatform_v1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + export_config = aiplatform_v1.ExportDataConfig() + export_config.gcs_destination.output_uri_prefix = "output_uri_prefix_value" + + request = aiplatform_v1.ExportDataRequest( + name="name_value", + export_config=export_config, + ) + + # Make the request + operation = client.export_data(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.ExportDataRequest`): + request (Union[google.cloud.aiplatform_v1.types.ExportDataRequest, dict]): The request object. Request message for [DatasetService.ExportData][google.cloud.aiplatform.v1.DatasetService.ExportData]. name (:class:`str`): @@ -746,7 +997,7 @@ async def export_data( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, export_config]) if request is not None and has_flattened_params: @@ -768,7 +1019,7 @@ async def export_data( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.export_data, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -779,7 +1030,12 @@ async def export_data( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -794,17 +1050,37 @@ async def export_data( async def list_data_items( self, - request: dataset_service.ListDataItemsRequest = None, + request: Union[dataset_service.ListDataItemsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListDataItemsAsyncPager: r"""Lists DataItems in a Dataset. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_list_data_items(): + # Create a client + client = aiplatform_v1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListDataItemsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_data_items(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.ListDataItemsRequest`): + request (Union[google.cloud.aiplatform_v1.types.ListDataItemsRequest, dict]): The request object. Request message for [DatasetService.ListDataItems][google.cloud.aiplatform.v1.DatasetService.ListDataItems]. parent (:class:`str`): @@ -831,7 +1107,7 @@ async def list_data_items( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -851,7 +1127,7 @@ async def list_data_items( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.list_data_items, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -862,12 +1138,20 @@ async def list_data_items( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListDataItemsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -875,23 +1159,41 @@ async def list_data_items( async def get_annotation_spec( self, - request: dataset_service.GetAnnotationSpecRequest = None, + request: Union[dataset_service.GetAnnotationSpecRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> annotation_spec.AnnotationSpec: r"""Gets an AnnotationSpec. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_get_annotation_spec(): + # Create a client + client = aiplatform_v1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetAnnotationSpecRequest( + name="name_value", + ) + + # Make the request + response = await client.get_annotation_spec(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.GetAnnotationSpecRequest`): + request (Union[google.cloud.aiplatform_v1.types.GetAnnotationSpecRequest, dict]): The request object. Request message for [DatasetService.GetAnnotationSpec][google.cloud.aiplatform.v1.DatasetService.GetAnnotationSpec]. name (:class:`str`): Required. The name of the AnnotationSpec resource. Format: - ``projects/{project}/locations/{location}/datasets/{dataset}/annotationSpecs/{annotation_spec}`` This corresponds to the ``name`` field @@ -910,7 +1212,7 @@ async def get_annotation_spec( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -930,7 +1232,7 @@ async def get_annotation_spec( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.get_annotation_spec, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -941,30 +1243,54 @@ async def get_annotation_spec( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_annotations( self, - request: dataset_service.ListAnnotationsRequest = None, + request: Union[dataset_service.ListAnnotationsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListAnnotationsAsyncPager: r"""Lists Annotations belongs to a dataitem + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_list_annotations(): + # Create a client + client = aiplatform_v1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListAnnotationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_annotations(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.ListAnnotationsRequest`): + request (Union[google.cloud.aiplatform_v1.types.ListAnnotationsRequest, dict]): The request object. Request message for [DatasetService.ListAnnotations][google.cloud.aiplatform.v1.DatasetService.ListAnnotations]. parent (:class:`str`): Required. The resource name of the DataItem to list Annotations from. Format: - ``projects/{project}/locations/{location}/datasets/{dataset}/dataItems/{data_item}`` This corresponds to the ``parent`` field @@ -986,7 +1312,7 @@ async def list_annotations( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1006,7 +1332,7 @@ async def list_annotations( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.list_annotations, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -1017,17 +1343,702 @@ async def list_annotations( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListAnnotationsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_operations, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.delete_operation, + default_timeout=None, + 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 cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + 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 wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.wait_operation, + default_timeout=None, + 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 set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) # Done; return the response. return response + async def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_location, + default_timeout=None, + 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 list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_locations, + default_timeout=None, + 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 __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/aiplatform_v1/services/dataset_service/client.py b/google/cloud/aiplatform_v1/services/dataset_service/client.py index 201d814c99..08ae4b98cf 100644 --- a/google/cloud/aiplatform_v1/services/dataset_service/client.py +++ b/google/cloud/aiplatform_v1/services/dataset_service/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,22 +14,26 @@ # 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 +from typing import Dict, Mapping, 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 as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_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 +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation as gac_operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1.services.dataset_service import pagers @@ -41,6 +45,10 @@ from google.cloud.aiplatform_v1.types import dataset_service from google.cloud.aiplatform_v1.types import encryption_spec from google.cloud.aiplatform_v1.types import operation as gca_operation +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import struct_pb2 # type: ignore @@ -64,8 +72,11 @@ class DatasetServiceClientMeta(type): _transport_registry["grpc"] = DatasetServiceGrpcTransport _transport_registry["grpc_asyncio"] = DatasetServiceGrpcAsyncIOTransport - def get_transport_class(cls, label: str = None,) -> Type[DatasetServiceTransport]: - """Return an appropriate transport class. + def get_transport_class( + cls, + label: str = None, + ) -> Type[DatasetServiceTransport]: + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -84,11 +95,14 @@ def get_transport_class(cls, label: str = None,) -> Type[DatasetServiceTransport class DatasetServiceClient(metaclass=DatasetServiceClientMeta): - """""" + """The service that handles the CRUD of Vertex AI Dataset and + its child resources. + """ @staticmethod def _get_default_mtls_endpoint(api_endpoint): - """Convert api endpoint to mTLS endpoint. + """Converts api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. Args: @@ -122,7 +136,8 @@ def _get_default_mtls_endpoint(api_endpoint): @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -139,7 +154,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -158,18 +173,23 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> DatasetServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - DatasetServiceTransport: The transport used by the client instance. + DatasetServiceTransport: The transport used by the client + instance. """ return self._transport @staticmethod def annotation_path( - project: str, location: str, dataset: str, data_item: str, annotation: str, + project: str, + location: str, + dataset: str, + data_item: str, + annotation: str, ) -> str: - """Return a fully-qualified annotation string.""" + """Returns a fully-qualified annotation string.""" return "projects/{project}/locations/{location}/datasets/{dataset}/dataItems/{data_item}/annotations/{annotation}".format( project=project, location=location, @@ -180,7 +200,7 @@ def annotation_path( @staticmethod def parse_annotation_path(path: str) -> Dict[str, str]: - """Parse a annotation path into its component segments.""" + """Parses a annotation path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/datasets/(?P.+?)/dataItems/(?P.+?)/annotations/(?P.+?)$", path, @@ -189,9 +209,12 @@ def parse_annotation_path(path: str) -> Dict[str, str]: @staticmethod def annotation_spec_path( - project: str, location: str, dataset: str, annotation_spec: str, + project: str, + location: str, + dataset: str, + annotation_spec: str, ) -> str: - """Return a fully-qualified annotation_spec string.""" + """Returns a fully-qualified annotation_spec string.""" return "projects/{project}/locations/{location}/datasets/{dataset}/annotationSpecs/{annotation_spec}".format( project=project, location=location, @@ -201,7 +224,7 @@ def annotation_spec_path( @staticmethod def parse_annotation_spec_path(path: str) -> Dict[str, str]: - """Parse a annotation_spec path into its component segments.""" + """Parses a annotation_spec path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/datasets/(?P.+?)/annotationSpecs/(?P.+?)$", path, @@ -210,16 +233,22 @@ def parse_annotation_spec_path(path: str) -> Dict[str, str]: @staticmethod def data_item_path( - project: str, location: str, dataset: str, data_item: str, + project: str, + location: str, + dataset: str, + data_item: str, ) -> str: - """Return a fully-qualified data_item string.""" + """Returns a fully-qualified data_item string.""" return "projects/{project}/locations/{location}/datasets/{dataset}/dataItems/{data_item}".format( - project=project, location=location, dataset=dataset, data_item=data_item, + project=project, + location=location, + dataset=dataset, + data_item=data_item, ) @staticmethod def parse_data_item_path(path: str) -> Dict[str, str]: - """Parse a data_item path into its component segments.""" + """Parses a data_item path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/datasets/(?P.+?)/dataItems/(?P.+?)$", path, @@ -227,15 +256,21 @@ def parse_data_item_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def dataset_path(project: str, location: str, dataset: str,) -> str: - """Return a fully-qualified dataset string.""" + def dataset_path( + project: str, + location: str, + dataset: str, + ) -> str: + """Returns a fully-qualified dataset string.""" return "projects/{project}/locations/{location}/datasets/{dataset}".format( - project=project, location=location, dataset=dataset, + project=project, + location=location, + dataset=dataset, ) @staticmethod def parse_dataset_path(path: str) -> Dict[str, str]: - """Parse a dataset path into its component segments.""" + """Parses a dataset path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/datasets/(?P.+?)$", path, @@ -243,8 +278,10 @@ def parse_dataset_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + def common_billing_account_path( + billing_account: str, + ) -> str: + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -256,9 +293,13 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: 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,) + def common_folder_path( + folder: str, + ) -> str: + """Returns a fully-qualified folder string.""" + return "folders/{folder}".format( + folder=folder, + ) @staticmethod def parse_common_folder_path(path: str) -> Dict[str, str]: @@ -267,9 +308,13 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: 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,) + def common_organization_path( + organization: str, + ) -> str: + """Returns a fully-qualified organization string.""" + return "organizations/{organization}".format( + organization=organization, + ) @staticmethod def parse_common_organization_path(path: str) -> Dict[str, str]: @@ -278,9 +323,13 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: 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,) + def common_project_path( + project: str, + ) -> str: + """Returns a fully-qualified project string.""" + return "projects/{project}".format( + project=project, + ) @staticmethod def parse_common_project_path(path: str) -> Dict[str, str]: @@ -289,10 +338,14 @@ def parse_common_project_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_location_path(project: str, location: str,) -> str: - """Return a fully-qualified location string.""" + def common_location_path( + project: str, + location: str, + ) -> str: + """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) @staticmethod @@ -301,6 +354,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + def __init__( self, *, @@ -309,7 +429,7 @@ def __init__( client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the dataset service client. + """Instantiates the dataset service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -351,58 +471,42 @@ def __init__( 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")) + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - client_cert_source_func = ( - mtls.default_client_cert_source() 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" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # 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, DatasetServiceTransport): # transport is a DatasetServiceTransport instance. - if credentials or client_options.credentials_file: + if credentials or client_options.credentials_file or api_key_value: 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." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + Transport = type(self).get_transport_class(transport) self._transport = Transport( credentials=credentials, @@ -412,22 +516,52 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, + always_use_jwt_access=True, ) def create_dataset( self, - request: dataset_service.CreateDatasetRequest = None, + request: Union[dataset_service.CreateDatasetRequest, dict] = None, *, parent: str = None, dataset: gca_dataset.Dataset = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Creates a Dataset. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_create_dataset(): + # Create a client + client = aiplatform_v1.DatasetServiceClient() + + # Initialize request argument(s) + dataset = aiplatform_v1.Dataset() + dataset.display_name = "display_name_value" + dataset.metadata_schema_uri = "metadata_schema_uri_value" + dataset.metadata.null_value = "NULL_VALUE" + + request = aiplatform_v1.CreateDatasetRequest( + parent="parent_value", + dataset=dataset, + ) + + # Make the request + operation = client.create_dataset(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1.types.CreateDatasetRequest): + request (Union[google.cloud.aiplatform_v1.types.CreateDatasetRequest, dict]): The request object. Request message for [DatasetService.CreateDataset][google.cloud.aiplatform.v1.DatasetService.CreateDataset]. parent (str): @@ -459,7 +593,7 @@ def create_dataset( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, dataset]) if request is not None and has_flattened_params: @@ -492,7 +626,12 @@ def create_dataset( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -507,17 +646,36 @@ def create_dataset( def get_dataset( self, - request: dataset_service.GetDatasetRequest = None, + request: Union[dataset_service.GetDatasetRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> dataset.Dataset: r"""Gets a Dataset. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_get_dataset(): + # Create a client + client = aiplatform_v1.DatasetServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetDatasetRequest( + name="name_value", + ) + + # Make the request + response = client.get_dataset(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1.types.GetDatasetRequest): + request (Union[google.cloud.aiplatform_v1.types.GetDatasetRequest, dict]): The request object. Request message for [DatasetService.GetDataset][google.cloud.aiplatform.v1.DatasetService.GetDataset]. name (str): @@ -540,7 +698,7 @@ def get_dataset( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -571,25 +729,54 @@ def get_dataset( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def update_dataset( self, - request: dataset_service.UpdateDatasetRequest = None, + request: Union[dataset_service.UpdateDatasetRequest, dict] = None, *, dataset: gca_dataset.Dataset = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_dataset.Dataset: r"""Updates a Dataset. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_update_dataset(): + # Create a client + client = aiplatform_v1.DatasetServiceClient() + + # Initialize request argument(s) + dataset = aiplatform_v1.Dataset() + dataset.display_name = "display_name_value" + dataset.metadata_schema_uri = "metadata_schema_uri_value" + dataset.metadata.null_value = "NULL_VALUE" + + request = aiplatform_v1.UpdateDatasetRequest( + dataset=dataset, + ) + + # Make the request + response = client.update_dataset(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1.types.UpdateDatasetRequest): + request (Union[google.cloud.aiplatform_v1.types.UpdateDatasetRequest, dict]): The request object. Request message for [DatasetService.UpdateDataset][google.cloud.aiplatform.v1.DatasetService.UpdateDataset]. dataset (google.cloud.aiplatform_v1.types.Dataset): @@ -602,7 +789,7 @@ def update_dataset( update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. The update mask applies to the resource. For the ``FieldMask`` definition, see - `FieldMask `__. + [google.protobuf.FieldMask][google.protobuf.FieldMask]. Updatable fields: - ``display_name`` @@ -625,7 +812,7 @@ def update_dataset( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([dataset, update_mask]) if request is not None and has_flattened_params: @@ -660,24 +847,49 @@ def update_dataset( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_datasets( self, - request: dataset_service.ListDatasetsRequest = None, + request: Union[dataset_service.ListDatasetsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListDatasetsPager: r"""Lists Datasets in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_list_datasets(): + # Create a client + client = aiplatform_v1.DatasetServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListDatasetsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_datasets(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1.types.ListDatasetsRequest): + request (Union[google.cloud.aiplatform_v1.types.ListDatasetsRequest, dict]): The request object. Request message for [DatasetService.ListDatasets][google.cloud.aiplatform.v1.DatasetService.ListDatasets]. parent (str): @@ -703,7 +915,7 @@ def list_datasets( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -734,12 +946,20 @@ def list_datasets( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListDatasetsPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -747,17 +967,40 @@ def list_datasets( def delete_dataset( self, - request: dataset_service.DeleteDatasetRequest = None, + request: Union[dataset_service.DeleteDatasetRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Deletes a Dataset. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_delete_dataset(): + # Create a client + client = aiplatform_v1.DatasetServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteDatasetRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_dataset(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1.types.DeleteDatasetRequest): + request (Union[google.cloud.aiplatform_v1.types.DeleteDatasetRequest, dict]): The request object. Request message for [DatasetService.DeleteDataset][google.cloud.aiplatform.v1.DatasetService.DeleteDataset]. name (str): @@ -794,7 +1037,7 @@ def delete_dataset( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -825,7 +1068,12 @@ def delete_dataset( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -840,18 +1088,46 @@ def delete_dataset( def import_data( self, - request: dataset_service.ImportDataRequest = None, + request: Union[dataset_service.ImportDataRequest, dict] = None, *, name: str = None, import_configs: Sequence[dataset.ImportDataConfig] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Imports data into a Dataset. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_import_data(): + # Create a client + client = aiplatform_v1.DatasetServiceClient() + + # Initialize request argument(s) + import_configs = aiplatform_v1.ImportDataConfig() + import_configs.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + import_configs.import_schema_uri = "import_schema_uri_value" + + request = aiplatform_v1.ImportDataRequest( + name="name_value", + import_configs=import_configs, + ) + + # Make the request + operation = client.import_data(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1.types.ImportDataRequest): + request (Union[google.cloud.aiplatform_v1.types.ImportDataRequest, dict]): The request object. Request message for [DatasetService.ImportData][google.cloud.aiplatform.v1.DatasetService.ImportData]. name (str): @@ -886,7 +1162,7 @@ def import_data( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, import_configs]) if request is not None and has_flattened_params: @@ -919,7 +1195,12 @@ def import_data( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -934,18 +1215,45 @@ def import_data( def export_data( self, - request: dataset_service.ExportDataRequest = None, + request: Union[dataset_service.ExportDataRequest, dict] = None, *, name: str = None, export_config: dataset.ExportDataConfig = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Exports data from a Dataset. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_export_data(): + # Create a client + client = aiplatform_v1.DatasetServiceClient() + + # Initialize request argument(s) + export_config = aiplatform_v1.ExportDataConfig() + export_config.gcs_destination.output_uri_prefix = "output_uri_prefix_value" + + request = aiplatform_v1.ExportDataRequest( + name="name_value", + export_config=export_config, + ) + + # Make the request + operation = client.export_data(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1.types.ExportDataRequest): + request (Union[google.cloud.aiplatform_v1.types.ExportDataRequest, dict]): The request object. Request message for [DatasetService.ExportData][google.cloud.aiplatform.v1.DatasetService.ExportData]. name (str): @@ -979,7 +1287,7 @@ def export_data( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, export_config]) if request is not None and has_flattened_params: @@ -1012,7 +1320,12 @@ def export_data( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -1027,17 +1340,37 @@ def export_data( def list_data_items( self, - request: dataset_service.ListDataItemsRequest = None, + request: Union[dataset_service.ListDataItemsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListDataItemsPager: r"""Lists DataItems in a Dataset. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_list_data_items(): + # Create a client + client = aiplatform_v1.DatasetServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListDataItemsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_data_items(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1.types.ListDataItemsRequest): + request (Union[google.cloud.aiplatform_v1.types.ListDataItemsRequest, dict]): The request object. Request message for [DatasetService.ListDataItems][google.cloud.aiplatform.v1.DatasetService.ListDataItems]. parent (str): @@ -1064,7 +1397,7 @@ def list_data_items( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1095,12 +1428,20 @@ def list_data_items( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListDataItemsPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -1108,23 +1449,41 @@ def list_data_items( def get_annotation_spec( self, - request: dataset_service.GetAnnotationSpecRequest = None, + request: Union[dataset_service.GetAnnotationSpecRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> annotation_spec.AnnotationSpec: r"""Gets an AnnotationSpec. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_get_annotation_spec(): + # Create a client + client = aiplatform_v1.DatasetServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetAnnotationSpecRequest( + name="name_value", + ) + + # Make the request + response = client.get_annotation_spec(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1.types.GetAnnotationSpecRequest): + request (Union[google.cloud.aiplatform_v1.types.GetAnnotationSpecRequest, dict]): The request object. Request message for [DatasetService.GetAnnotationSpec][google.cloud.aiplatform.v1.DatasetService.GetAnnotationSpec]. name (str): Required. The name of the AnnotationSpec resource. Format: - ``projects/{project}/locations/{location}/datasets/{dataset}/annotationSpecs/{annotation_spec}`` This corresponds to the ``name`` field @@ -1143,7 +1502,7 @@ def get_annotation_spec( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1174,30 +1533,54 @@ def get_annotation_spec( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_annotations( self, - request: dataset_service.ListAnnotationsRequest = None, + request: Union[dataset_service.ListAnnotationsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListAnnotationsPager: r"""Lists Annotations belongs to a dataitem + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_list_annotations(): + # Create a client + client = aiplatform_v1.DatasetServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListAnnotationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_annotations(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1.types.ListAnnotationsRequest): + request (Union[google.cloud.aiplatform_v1.types.ListAnnotationsRequest, dict]): The request object. Request message for [DatasetService.ListAnnotations][google.cloud.aiplatform.v1.DatasetService.ListAnnotations]. parent (str): Required. The resource name of the DataItem to list Annotations from. Format: - ``projects/{project}/locations/{location}/datasets/{dataset}/dataItems/{data_item}`` This corresponds to the ``parent`` field @@ -1219,7 +1602,7 @@ def list_annotations( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1250,12 +1633,704 @@ def list_annotations( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListAnnotationsPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_operations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.delete_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.wait_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_location, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_locations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) # Done; return the response. diff --git a/google/cloud/aiplatform_v1/services/dataset_service/pagers.py b/google/cloud/aiplatform_v1/services/dataset_service/pagers.py index be142bd36e..577519f725 100644 --- a/google/cloud/aiplatform_v1/services/dataset_service/pagers.py +++ b/google/cloud/aiplatform_v1/services/dataset_service/pagers.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,13 +15,13 @@ # from typing import ( Any, - AsyncIterable, + AsyncIterator, Awaitable, Callable, - Iterable, Sequence, Tuple, Optional, + Iterator, ) from google.cloud.aiplatform_v1.types import annotation @@ -77,14 +77,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[dataset_service.ListDatasetsResponse]: + def pages(self) -> Iterator[dataset_service.ListDatasetsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[dataset.Dataset]: + def __iter__(self) -> Iterator[dataset.Dataset]: for page in self.pages: yield from page.datasets @@ -118,7 +118,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -139,14 +139,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - async def pages(self) -> AsyncIterable[dataset_service.ListDatasetsResponse]: + async def pages(self) -> AsyncIterator[dataset_service.ListDatasetsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[dataset.Dataset]: + def __aiter__(self) -> AsyncIterator[dataset.Dataset]: async def async_generator(): async for page in self.pages: for response in page.datasets: @@ -205,14 +205,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[dataset_service.ListDataItemsResponse]: + def pages(self) -> Iterator[dataset_service.ListDataItemsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[data_item.DataItem]: + def __iter__(self) -> Iterator[data_item.DataItem]: for page in self.pages: yield from page.data_items @@ -246,7 +246,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -267,14 +267,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - async def pages(self) -> AsyncIterable[dataset_service.ListDataItemsResponse]: + async def pages(self) -> AsyncIterator[dataset_service.ListDataItemsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[data_item.DataItem]: + def __aiter__(self) -> AsyncIterator[data_item.DataItem]: async def async_generator(): async for page in self.pages: for response in page.data_items: @@ -333,14 +333,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[dataset_service.ListAnnotationsResponse]: + def pages(self) -> Iterator[dataset_service.ListAnnotationsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[annotation.Annotation]: + def __iter__(self) -> Iterator[annotation.Annotation]: for page in self.pages: yield from page.annotations @@ -374,7 +374,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -395,14 +395,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - async def pages(self) -> AsyncIterable[dataset_service.ListAnnotationsResponse]: + async def pages(self) -> AsyncIterator[dataset_service.ListAnnotationsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[annotation.Annotation]: + def __aiter__(self) -> AsyncIterator[annotation.Annotation]: async def async_generator(): async for page in self.pages: for response in page.annotations: diff --git a/google/cloud/aiplatform_v1/services/dataset_service/transports/__init__.py b/google/cloud/aiplatform_v1/services/dataset_service/transports/__init__.py index 902a4fb01f..07bc11c0c8 100644 --- a/google/cloud/aiplatform_v1/services/dataset_service/transports/__init__.py +++ b/google/cloud/aiplatform_v1/services/dataset_service/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1/services/dataset_service/transports/base.py b/google/cloud/aiplatform_v1/services/dataset_service/transports/base.py index c049ed37ba..aa75e138ea 100644 --- a/google/cloud/aiplatform_v1/services/dataset_service/transports/base.py +++ b/google/cloud/aiplatform_v1/services/dataset_service/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,21 +15,25 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.api_core import operations_v1 # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.aiplatform_v1.types import annotation_spec from google.cloud.aiplatform_v1.types import dataset from google.cloud.aiplatform_v1.types import dataset as gca_dataset from google.cloud.aiplatform_v1.types import dataset_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore try: @@ -41,17 +45,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - -_API_CORE_VERSION = google.api_core.__version__ - class DatasetServiceTransport(abc.ABC): """Abstract transport class for DatasetService.""" @@ -69,6 +62,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -92,16 +86,19 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -114,97 +111,88 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id ) - # Save the credentials. - self._credentials = credentials - - # TODO(busunkim): These two class methods are in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-api-core - # and google-auth are increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") + # If the credentials are service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs + credentials = credentials.with_always_use_jwt_access(True) - # TODO: Remove this function once google-api-core >= 1.26.0 is required - @classmethod - def _get_self_signed_jwt_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Union[Optional[Sequence[str]], str]]: - """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" - - self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} - - if _API_CORE_VERSION and ( - packaging.version.parse(_API_CORE_VERSION) - >= packaging.version.parse("1.26.0") - ): - self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES - self_signed_jwt_kwargs["scopes"] = scopes - self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST - else: - self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES - - return self_signed_jwt_kwargs + # Save the credentials. + self._credentials = credentials def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { self.create_dataset: gapic_v1.method.wrap_method( - self.create_dataset, default_timeout=5.0, client_info=client_info, + self.create_dataset, + default_timeout=None, + client_info=client_info, ), self.get_dataset: gapic_v1.method.wrap_method( - self.get_dataset, default_timeout=5.0, client_info=client_info, + self.get_dataset, + default_timeout=None, + client_info=client_info, ), self.update_dataset: gapic_v1.method.wrap_method( - self.update_dataset, default_timeout=5.0, client_info=client_info, + self.update_dataset, + default_timeout=None, + client_info=client_info, ), self.list_datasets: gapic_v1.method.wrap_method( - self.list_datasets, default_timeout=5.0, client_info=client_info, + self.list_datasets, + default_timeout=None, + client_info=client_info, ), self.delete_dataset: gapic_v1.method.wrap_method( - self.delete_dataset, default_timeout=5.0, client_info=client_info, + self.delete_dataset, + default_timeout=None, + client_info=client_info, ), self.import_data: gapic_v1.method.wrap_method( - self.import_data, default_timeout=5.0, client_info=client_info, + self.import_data, + default_timeout=None, + client_info=client_info, ), self.export_data: gapic_v1.method.wrap_method( - self.export_data, default_timeout=5.0, client_info=client_info, + self.export_data, + default_timeout=None, + client_info=client_info, ), self.list_data_items: gapic_v1.method.wrap_method( - self.list_data_items, default_timeout=5.0, client_info=client_info, + self.list_data_items, + default_timeout=None, + client_info=client_info, ), self.get_annotation_spec: gapic_v1.method.wrap_method( - self.get_annotation_spec, default_timeout=5.0, client_info=client_info, + self.get_annotation_spec, + default_timeout=None, + client_info=client_info, ), self.list_annotations: gapic_v1.method.wrap_method( - self.list_annotations, default_timeout=5.0, client_info=client_info, + self.list_annotations, + default_timeout=None, + client_info=client_info, ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() @@ -309,5 +297,102 @@ def list_annotations( ]: raise NotImplementedError() + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], + Union[ + operations_pb2.ListOperationsResponse, + Awaitable[operations_pb2.ListOperationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None,]: + raise NotImplementedError() + + @property + def wait_operation( + self, + ) -> Callable[ + [operations_pb2.WaitOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def set_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def get_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_location( + self, + ) -> Callable[ + [locations_pb2.GetLocationRequest], + Union[locations_pb2.Location, Awaitable[locations_pb2.Location]], + ]: + raise NotImplementedError() + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], + Union[ + locations_pb2.ListLocationsResponse, + Awaitable[locations_pb2.ListLocationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + __all__ = ("DatasetServiceTransport",) diff --git a/google/cloud/aiplatform_v1/services/dataset_service/transports/grpc.py b/google/cloud/aiplatform_v1/services/dataset_service/transports/grpc.py index d38f841665..137b823324 100644 --- a/google/cloud/aiplatform_v1/services/dataset_service/transports/grpc.py +++ b/google/cloud/aiplatform_v1/services/dataset_service/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,9 +16,9 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import operations_v1 +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -29,6 +29,10 @@ from google.cloud.aiplatform_v1.types import dataset from google.cloud.aiplatform_v1.types import dataset as gca_dataset from google.cloud.aiplatform_v1.types import dataset_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from .base import DatasetServiceTransport, DEFAULT_CLIENT_INFO @@ -36,6 +40,9 @@ class DatasetServiceGrpcTransport(DatasetServiceTransport): """gRPC backend transport for DatasetService. + The service that handles the CRUD of Vertex AI Dataset and + its child resources. + This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation and call it. @@ -60,6 +67,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -82,16 +90,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -100,6 +108,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport @@ -110,7 +120,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -153,13 +163,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -208,21 +222,20 @@ def create_channel( and ``credentials_file`` are passed. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @property def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ + """Return the channel designed to connect to this service.""" return self._grpc_channel @property @@ -232,7 +245,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsClient(self.grpc_channel) @@ -508,5 +521,215 @@ def list_annotations( ) return self._stubs["list_annotations"] + def close(self): + self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + @property + def kind(self) -> str: + return "grpc" + __all__ = ("DatasetServiceGrpcTransport",) diff --git a/google/cloud/aiplatform_v1/services/dataset_service/transports/grpc_asyncio.py b/google/cloud/aiplatform_v1/services/dataset_service/transports/grpc_asyncio.py index dad35d6eca..f3ace0efc9 100644 --- a/google/cloud/aiplatform_v1/services/dataset_service/transports/grpc_asyncio.py +++ b/google/cloud/aiplatform_v1/services/dataset_service/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,12 +16,11 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore -from google.api_core import operations_v1 # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore @@ -30,6 +29,10 @@ from google.cloud.aiplatform_v1.types import dataset from google.cloud.aiplatform_v1.types import dataset as gca_dataset from google.cloud.aiplatform_v1.types import dataset_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from .base import DatasetServiceTransport, DEFAULT_CLIENT_INFO from .grpc import DatasetServiceGrpcTransport @@ -38,6 +41,9 @@ class DatasetServiceGrpcAsyncIOTransport(DatasetServiceTransport): """gRPC AsyncIO backend transport for DatasetService. + The service that handles the CRUD of Vertex AI Dataset and + its child resources. + This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation and call it. @@ -81,14 +87,14 @@ def create_channel( aio.Channel: A gRPC AsyncIO channel object. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @@ -106,6 +112,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -129,16 +136,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -147,6 +154,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport @@ -157,7 +166,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -199,13 +208,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -235,7 +248,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel @@ -526,5 +539,211 @@ def list_annotations( ) return self._stubs["list_annotations"] + def close(self): + return self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + __all__ = ("DatasetServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/aiplatform_v1/services/endpoint_service/__init__.py b/google/cloud/aiplatform_v1/services/endpoint_service/__init__.py index 96fb4ad6d6..3c37159f9d 100644 --- a/google/cloud/aiplatform_v1/services/endpoint_service/__init__.py +++ b/google/cloud/aiplatform_v1/services/endpoint_service/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1/services/endpoint_service/async_client.py b/google/cloud/aiplatform_v1/services/endpoint_service/async_client.py index 544a7788df..87a4c32dee 100644 --- a/google/cloud/aiplatform_v1/services/endpoint_service/async_client.py +++ b/google/cloud/aiplatform_v1/services/endpoint_service/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,16 +16,21 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation as gac_operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1.services.endpoint_service import pagers @@ -34,6 +39,10 @@ from google.cloud.aiplatform_v1.types import endpoint as gca_endpoint from google.cloud.aiplatform_v1.types import endpoint_service from google.cloud.aiplatform_v1.types import operation as gca_operation +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore @@ -43,7 +52,7 @@ class EndpointServiceAsyncClient: - """""" + """A service for managing Vertex AI's Endpoints.""" _client: EndpointServiceClient @@ -54,6 +63,14 @@ class EndpointServiceAsyncClient: parse_endpoint_path = staticmethod(EndpointServiceClient.parse_endpoint_path) model_path = staticmethod(EndpointServiceClient.model_path) parse_model_path = staticmethod(EndpointServiceClient.parse_model_path) + model_deployment_monitoring_job_path = staticmethod( + EndpointServiceClient.model_deployment_monitoring_job_path + ) + parse_model_deployment_monitoring_job_path = staticmethod( + EndpointServiceClient.parse_model_deployment_monitoring_job_path + ) + network_path = staticmethod(EndpointServiceClient.network_path) + parse_network_path = staticmethod(EndpointServiceClient.parse_network_path) common_billing_account_path = staticmethod( EndpointServiceClient.common_billing_account_path ) @@ -81,7 +98,8 @@ class EndpointServiceAsyncClient: @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -96,7 +114,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -111,9 +129,45 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return EndpointServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> EndpointServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: EndpointServiceTransport: The transport used by the client instance. @@ -132,7 +186,7 @@ def __init__( client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the endpoint service client. + """Instantiates the endpoint service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -173,18 +227,46 @@ def __init__( async def create_endpoint( self, - request: endpoint_service.CreateEndpointRequest = None, + request: Union[endpoint_service.CreateEndpointRequest, dict] = None, *, parent: str = None, endpoint: gca_endpoint.Endpoint = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + endpoint_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Creates an Endpoint. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_create_endpoint(): + # Create a client + client = aiplatform_v1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + endpoint = aiplatform_v1.Endpoint() + endpoint.display_name = "display_name_value" + + request = aiplatform_v1.CreateEndpointRequest( + parent="parent_value", + endpoint=endpoint, + ) + + # Make the request + operation = client.create_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.CreateEndpointRequest`): + request (Union[google.cloud.aiplatform_v1.types.CreateEndpointRequest, dict]): The request object. Request message for [EndpointService.CreateEndpoint][google.cloud.aiplatform.v1.EndpointService.CreateEndpoint]. parent (:class:`str`): @@ -200,6 +282,21 @@ async def create_endpoint( This corresponds to the ``endpoint`` field on the ``request`` instance; if ``request`` is provided, this should not be set. + endpoint_id (:class:`str`): + Immutable. The ID to use for endpoint, which will become + the final component of the endpoint resource name. If + not provided, Vertex AI will generate a value for this + ID. + + This value should be 1-10 characters, and valid + characters are /[0-9]/. When using HTTP/JSON, this field + is populated based on a query string argument, such as + ``?endpoint_id=12345``. This is the fallback for fields + that are not included in either the URI or the body. + + This corresponds to the ``endpoint_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. @@ -215,9 +312,9 @@ async def create_endpoint( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, endpoint]) + has_flattened_params = any([parent, endpoint, endpoint_id]) if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " @@ -232,12 +329,14 @@ async def create_endpoint( request.parent = parent if endpoint is not None: request.endpoint = endpoint + if endpoint_id is not None: + request.endpoint_id = endpoint_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_endpoint, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -248,7 +347,12 @@ async def create_endpoint( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -263,17 +367,36 @@ async def create_endpoint( async def get_endpoint( self, - request: endpoint_service.GetEndpointRequest = None, + request: Union[endpoint_service.GetEndpointRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> endpoint.Endpoint: r"""Gets an Endpoint. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_get_endpoint(): + # Create a client + client = aiplatform_v1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetEndpointRequest( + name="name_value", + ) + + # Make the request + response = await client.get_endpoint(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.GetEndpointRequest`): + request (Union[google.cloud.aiplatform_v1.types.GetEndpointRequest, dict]): The request object. Request message for [EndpointService.GetEndpoint][google.cloud.aiplatform.v1.EndpointService.GetEndpoint] name (:class:`str`): @@ -297,7 +420,7 @@ async def get_endpoint( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -317,7 +440,7 @@ async def get_endpoint( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.get_endpoint, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -328,24 +451,49 @@ async def get_endpoint( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_endpoints( self, - request: endpoint_service.ListEndpointsRequest = None, + request: Union[endpoint_service.ListEndpointsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListEndpointsAsyncPager: r"""Lists Endpoints in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_list_endpoints(): + # Create a client + client = aiplatform_v1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListEndpointsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_endpoints(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.ListEndpointsRequest`): + request (Union[google.cloud.aiplatform_v1.types.ListEndpointsRequest, dict]): The request object. Request message for [EndpointService.ListEndpoints][google.cloud.aiplatform.v1.EndpointService.ListEndpoints]. parent (:class:`str`): @@ -372,7 +520,7 @@ async def list_endpoints( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -392,7 +540,7 @@ async def list_endpoints( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.list_endpoints, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -403,12 +551,20 @@ async def list_endpoints( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListEndpointsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -416,18 +572,40 @@ async def list_endpoints( async def update_endpoint( self, - request: endpoint_service.UpdateEndpointRequest = None, + request: Union[endpoint_service.UpdateEndpointRequest, dict] = None, *, endpoint: gca_endpoint.Endpoint = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_endpoint.Endpoint: r"""Updates an Endpoint. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_update_endpoint(): + # Create a client + client = aiplatform_v1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + endpoint = aiplatform_v1.Endpoint() + endpoint.display_name = "display_name_value" + + request = aiplatform_v1.UpdateEndpointRequest( + endpoint=endpoint, + ) + + # Make the request + response = await client.update_endpoint(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.UpdateEndpointRequest`): + request (Union[google.cloud.aiplatform_v1.types.UpdateEndpointRequest, dict]): The request object. Request message for [EndpointService.UpdateEndpoint][google.cloud.aiplatform.v1.EndpointService.UpdateEndpoint]. endpoint (:class:`google.cloud.aiplatform_v1.types.Endpoint`): @@ -439,7 +617,7 @@ async def update_endpoint( should not be set. update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): Required. The update mask applies to the resource. See - `FieldMask `__. + [google.protobuf.FieldMask][google.protobuf.FieldMask]. This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this @@ -458,7 +636,7 @@ async def update_endpoint( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([endpoint, update_mask]) if request is not None and has_flattened_params: @@ -480,7 +658,7 @@ async def update_endpoint( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.update_endpoint, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -493,24 +671,52 @@ async def update_endpoint( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def delete_endpoint( self, - request: endpoint_service.DeleteEndpointRequest = None, + request: Union[endpoint_service.DeleteEndpointRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes an Endpoint. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_delete_endpoint(): + # Create a client + client = aiplatform_v1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteEndpointRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.DeleteEndpointRequest`): + request (Union[google.cloud.aiplatform_v1.types.DeleteEndpointRequest, dict]): The request object. Request message for [EndpointService.DeleteEndpoint][google.cloud.aiplatform.v1.EndpointService.DeleteEndpoint]. name (:class:`str`): @@ -547,7 +753,7 @@ async def delete_endpoint( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -567,7 +773,7 @@ async def delete_endpoint( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.delete_endpoint, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -578,7 +784,12 @@ async def delete_endpoint( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -593,22 +804,48 @@ async def delete_endpoint( async def deploy_model( self, - request: endpoint_service.DeployModelRequest = None, + request: Union[endpoint_service.DeployModelRequest, dict] = None, *, endpoint: str = None, deployed_model: gca_endpoint.DeployedModel = None, - traffic_split: Sequence[ - endpoint_service.DeployModelRequest.TrafficSplitEntry - ] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + traffic_split: Mapping[str, int] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deploys a Model into this Endpoint, creating a DeployedModel within it. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_deploy_model(): + # Create a client + client = aiplatform_v1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + deployed_model = aiplatform_v1.DeployedModel() + deployed_model.dedicated_resources.min_replica_count = 1803 + deployed_model.model = "model_value" + + request = aiplatform_v1.DeployModelRequest( + endpoint="endpoint_value", + deployed_model=deployed_model, + ) + + # Make the request + operation = client.deploy_model(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.DeployModelRequest`): + request (Union[google.cloud.aiplatform_v1.types.DeployModelRequest, dict]): The request object. Request message for [EndpointService.DeployModel][google.cloud.aiplatform.v1.EndpointService.DeployModel]. endpoint (:class:`str`): @@ -630,7 +867,7 @@ async def deploy_model( This corresponds to the ``deployed_model`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - traffic_split (:class:`Sequence[google.cloud.aiplatform_v1.types.DeployModelRequest.TrafficSplitEntry]`): + traffic_split (:class:`Mapping[str, int]`): A map from a DeployedModel's ID to the percentage of this Endpoint's traffic that should be forwarded to that DeployedModel. @@ -667,7 +904,7 @@ async def deploy_model( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([endpoint, deployed_model, traffic_split]) if request is not None and has_flattened_params: @@ -692,7 +929,7 @@ async def deploy_model( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.deploy_model, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -703,7 +940,12 @@ async def deploy_model( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -718,14 +960,12 @@ async def deploy_model( async def undeploy_model( self, - request: endpoint_service.UndeployModelRequest = None, + request: Union[endpoint_service.UndeployModelRequest, dict] = None, *, endpoint: str = None, deployed_model_id: str = None, - traffic_split: Sequence[ - endpoint_service.UndeployModelRequest.TrafficSplitEntry - ] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + traffic_split: Mapping[str, int] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -733,8 +973,32 @@ async def undeploy_model( DeployedModel from it, and freeing all resources it's using. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_undeploy_model(): + # Create a client + client = aiplatform_v1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.UndeployModelRequest( + endpoint="endpoint_value", + deployed_model_id="deployed_model_id_value", + ) + + # Make the request + operation = client.undeploy_model(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.UndeployModelRequest`): + request (Union[google.cloud.aiplatform_v1.types.UndeployModelRequest, dict]): The request object. Request message for [EndpointService.UndeployModel][google.cloud.aiplatform.v1.EndpointService.UndeployModel]. endpoint (:class:`str`): @@ -752,7 +1016,7 @@ async def undeploy_model( This corresponds to the ``deployed_model_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - traffic_split (:class:`Sequence[google.cloud.aiplatform_v1.types.UndeployModelRequest.TrafficSplitEntry]`): + traffic_split (:class:`Mapping[str, int]`): If this field is provided, then the Endpoint's [traffic_split][google.cloud.aiplatform.v1.Endpoint.traffic_split] will be overwritten with it. If last DeployedModel is @@ -783,7 +1047,7 @@ async def undeploy_model( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([endpoint, deployed_model_id, traffic_split]) if request is not None and has_flattened_params: @@ -808,7 +1072,7 @@ async def undeploy_model( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.undeploy_model, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -819,7 +1083,12 @@ async def undeploy_model( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -832,6 +1101,683 @@ async def undeploy_model( # Done; return the response. return response + async def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_operations, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.delete_operation, + default_timeout=None, + 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 cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + 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 wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.wait_operation, + default_timeout=None, + 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 set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_location, + default_timeout=None, + 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 list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_locations, + default_timeout=None, + 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 __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/aiplatform_v1/services/endpoint_service/client.py b/google/cloud/aiplatform_v1/services/endpoint_service/client.py index 8bc3a8026f..b55399fdf8 100644 --- a/google/cloud/aiplatform_v1/services/endpoint_service/client.py +++ b/google/cloud/aiplatform_v1/services/endpoint_service/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,22 +14,26 @@ # 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 +from typing import Dict, Mapping, 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 as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_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 +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation as gac_operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1.services.endpoint_service import pagers @@ -38,6 +42,10 @@ from google.cloud.aiplatform_v1.types import endpoint as gca_endpoint from google.cloud.aiplatform_v1.types import endpoint_service from google.cloud.aiplatform_v1.types import operation as gca_operation +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore @@ -60,8 +68,11 @@ class EndpointServiceClientMeta(type): _transport_registry["grpc"] = EndpointServiceGrpcTransport _transport_registry["grpc_asyncio"] = EndpointServiceGrpcAsyncIOTransport - def get_transport_class(cls, label: str = None,) -> Type[EndpointServiceTransport]: - """Return an appropriate transport class. + def get_transport_class( + cls, + label: str = None, + ) -> Type[EndpointServiceTransport]: + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -80,11 +91,12 @@ def get_transport_class(cls, label: str = None,) -> Type[EndpointServiceTranspor class EndpointServiceClient(metaclass=EndpointServiceClientMeta): - """""" + """A service for managing Vertex AI's Endpoints.""" @staticmethod def _get_default_mtls_endpoint(api_endpoint): - """Convert api endpoint to mTLS endpoint. + """Converts api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. Args: @@ -118,7 +130,8 @@ def _get_default_mtls_endpoint(api_endpoint): @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -135,7 +148,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -154,23 +167,30 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> EndpointServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - EndpointServiceTransport: The transport used by the client instance. + EndpointServiceTransport: The transport used by the client + instance. """ return self._transport @staticmethod - def endpoint_path(project: str, location: str, endpoint: str,) -> str: - """Return a fully-qualified endpoint string.""" + def endpoint_path( + project: str, + location: str, + endpoint: str, + ) -> str: + """Returns a fully-qualified endpoint string.""" return "projects/{project}/locations/{location}/endpoints/{endpoint}".format( - project=project, location=location, endpoint=endpoint, + project=project, + location=location, + endpoint=endpoint, ) @staticmethod def parse_endpoint_path(path: str) -> Dict[str, str]: - """Parse a endpoint path into its component segments.""" + """Parses a endpoint path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/endpoints/(?P.+?)$", path, @@ -178,15 +198,21 @@ def parse_endpoint_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def model_path(project: str, location: str, model: str,) -> str: - """Return a fully-qualified model string.""" + def model_path( + project: str, + location: str, + model: str, + ) -> str: + """Returns a fully-qualified model string.""" return "projects/{project}/locations/{location}/models/{model}".format( - project=project, location=location, model=model, + project=project, + location=location, + model=model, ) @staticmethod def parse_model_path(path: str) -> Dict[str, str]: - """Parse a model path into its component segments.""" + """Parses a model path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/models/(?P.+?)$", path, @@ -194,8 +220,51 @@ def parse_model_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + def model_deployment_monitoring_job_path( + project: str, + location: str, + model_deployment_monitoring_job: str, + ) -> str: + """Returns a fully-qualified model_deployment_monitoring_job string.""" + return "projects/{project}/locations/{location}/modelDeploymentMonitoringJobs/{model_deployment_monitoring_job}".format( + project=project, + location=location, + model_deployment_monitoring_job=model_deployment_monitoring_job, + ) + + @staticmethod + def parse_model_deployment_monitoring_job_path(path: str) -> Dict[str, str]: + """Parses a model_deployment_monitoring_job path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/modelDeploymentMonitoringJobs/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def network_path( + project: str, + network: str, + ) -> str: + """Returns a fully-qualified network string.""" + return "projects/{project}/global/networks/{network}".format( + project=project, + network=network, + ) + + @staticmethod + def parse_network_path(path: str) -> Dict[str, str]: + """Parses a network path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/global/networks/(?P.+?)$", path + ) + return m.groupdict() if m else {} + + @staticmethod + def common_billing_account_path( + billing_account: str, + ) -> str: + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -207,9 +276,13 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: 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,) + def common_folder_path( + folder: str, + ) -> str: + """Returns a fully-qualified folder string.""" + return "folders/{folder}".format( + folder=folder, + ) @staticmethod def parse_common_folder_path(path: str) -> Dict[str, str]: @@ -218,9 +291,13 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: 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,) + def common_organization_path( + organization: str, + ) -> str: + """Returns a fully-qualified organization string.""" + return "organizations/{organization}".format( + organization=organization, + ) @staticmethod def parse_common_organization_path(path: str) -> Dict[str, str]: @@ -229,9 +306,13 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: 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,) + def common_project_path( + project: str, + ) -> str: + """Returns a fully-qualified project string.""" + return "projects/{project}".format( + project=project, + ) @staticmethod def parse_common_project_path(path: str) -> Dict[str, str]: @@ -240,10 +321,14 @@ def parse_common_project_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_location_path(project: str, location: str,) -> str: - """Return a fully-qualified location string.""" + def common_location_path( + project: str, + location: str, + ) -> str: + """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) @staticmethod @@ -252,6 +337,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + def __init__( self, *, @@ -260,7 +412,7 @@ def __init__( client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the endpoint service client. + """Instantiates the endpoint service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -302,58 +454,42 @@ def __init__( 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")) + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - client_cert_source_func = ( - mtls.default_client_cert_source() 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" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # 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, EndpointServiceTransport): # transport is a EndpointServiceTransport instance. - if credentials or client_options.credentials_file: + if credentials or client_options.credentials_file or api_key_value: 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." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + Transport = type(self).get_transport_class(transport) self._transport = Transport( credentials=credentials, @@ -363,22 +499,51 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, + always_use_jwt_access=True, ) def create_endpoint( self, - request: endpoint_service.CreateEndpointRequest = None, + request: Union[endpoint_service.CreateEndpointRequest, dict] = None, *, parent: str = None, endpoint: gca_endpoint.Endpoint = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + endpoint_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Creates an Endpoint. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_create_endpoint(): + # Create a client + client = aiplatform_v1.EndpointServiceClient() + + # Initialize request argument(s) + endpoint = aiplatform_v1.Endpoint() + endpoint.display_name = "display_name_value" + + request = aiplatform_v1.CreateEndpointRequest( + parent="parent_value", + endpoint=endpoint, + ) + + # Make the request + operation = client.create_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1.types.CreateEndpointRequest): + request (Union[google.cloud.aiplatform_v1.types.CreateEndpointRequest, dict]): The request object. Request message for [EndpointService.CreateEndpoint][google.cloud.aiplatform.v1.EndpointService.CreateEndpoint]. parent (str): @@ -394,6 +559,21 @@ def create_endpoint( This corresponds to the ``endpoint`` field on the ``request`` instance; if ``request`` is provided, this should not be set. + endpoint_id (str): + Immutable. The ID to use for endpoint, which will become + the final component of the endpoint resource name. If + not provided, Vertex AI will generate a value for this + ID. + + This value should be 1-10 characters, and valid + characters are /[0-9]/. When using HTTP/JSON, this field + is populated based on a query string argument, such as + ``?endpoint_id=12345``. This is the fallback for fields + that are not included in either the URI or the body. + + This corresponds to the ``endpoint_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. @@ -409,9 +589,9 @@ def create_endpoint( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, endpoint]) + has_flattened_params = any([parent, endpoint, endpoint_id]) if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " @@ -430,6 +610,8 @@ def create_endpoint( request.parent = parent if endpoint is not None: request.endpoint = endpoint + if endpoint_id is not None: + request.endpoint_id = endpoint_id # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -442,7 +624,12 @@ def create_endpoint( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -457,17 +644,36 @@ def create_endpoint( def get_endpoint( self, - request: endpoint_service.GetEndpointRequest = None, + request: Union[endpoint_service.GetEndpointRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> endpoint.Endpoint: r"""Gets an Endpoint. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_get_endpoint(): + # Create a client + client = aiplatform_v1.EndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetEndpointRequest( + name="name_value", + ) + + # Make the request + response = client.get_endpoint(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1.types.GetEndpointRequest): + request (Union[google.cloud.aiplatform_v1.types.GetEndpointRequest, dict]): The request object. Request message for [EndpointService.GetEndpoint][google.cloud.aiplatform.v1.EndpointService.GetEndpoint] name (str): @@ -491,7 +697,7 @@ def get_endpoint( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -522,24 +728,49 @@ def get_endpoint( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_endpoints( self, - request: endpoint_service.ListEndpointsRequest = None, + request: Union[endpoint_service.ListEndpointsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListEndpointsPager: r"""Lists Endpoints in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_list_endpoints(): + # Create a client + client = aiplatform_v1.EndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListEndpointsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_endpoints(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1.types.ListEndpointsRequest): + request (Union[google.cloud.aiplatform_v1.types.ListEndpointsRequest, dict]): The request object. Request message for [EndpointService.ListEndpoints][google.cloud.aiplatform.v1.EndpointService.ListEndpoints]. parent (str): @@ -566,7 +797,7 @@ def list_endpoints( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -597,12 +828,20 @@ def list_endpoints( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListEndpointsPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -610,18 +849,40 @@ def list_endpoints( def update_endpoint( self, - request: endpoint_service.UpdateEndpointRequest = None, + request: Union[endpoint_service.UpdateEndpointRequest, dict] = None, *, endpoint: gca_endpoint.Endpoint = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_endpoint.Endpoint: r"""Updates an Endpoint. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_update_endpoint(): + # Create a client + client = aiplatform_v1.EndpointServiceClient() + + # Initialize request argument(s) + endpoint = aiplatform_v1.Endpoint() + endpoint.display_name = "display_name_value" + + request = aiplatform_v1.UpdateEndpointRequest( + endpoint=endpoint, + ) + + # Make the request + response = client.update_endpoint(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1.types.UpdateEndpointRequest): + request (Union[google.cloud.aiplatform_v1.types.UpdateEndpointRequest, dict]): The request object. Request message for [EndpointService.UpdateEndpoint][google.cloud.aiplatform.v1.EndpointService.UpdateEndpoint]. endpoint (google.cloud.aiplatform_v1.types.Endpoint): @@ -633,7 +894,7 @@ def update_endpoint( should not be set. update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. The update mask applies to the resource. See - `FieldMask `__. + [google.protobuf.FieldMask][google.protobuf.FieldMask]. This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this @@ -652,7 +913,7 @@ def update_endpoint( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([endpoint, update_mask]) if request is not None and has_flattened_params: @@ -687,24 +948,52 @@ def update_endpoint( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def delete_endpoint( self, - request: endpoint_service.DeleteEndpointRequest = None, + request: Union[endpoint_service.DeleteEndpointRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Deletes an Endpoint. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_delete_endpoint(): + # Create a client + client = aiplatform_v1.EndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteEndpointRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1.types.DeleteEndpointRequest): + request (Union[google.cloud.aiplatform_v1.types.DeleteEndpointRequest, dict]): The request object. Request message for [EndpointService.DeleteEndpoint][google.cloud.aiplatform.v1.EndpointService.DeleteEndpoint]. name (str): @@ -741,7 +1030,7 @@ def delete_endpoint( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -772,7 +1061,12 @@ def delete_endpoint( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -787,22 +1081,48 @@ def delete_endpoint( def deploy_model( self, - request: endpoint_service.DeployModelRequest = None, + request: Union[endpoint_service.DeployModelRequest, dict] = None, *, endpoint: str = None, deployed_model: gca_endpoint.DeployedModel = None, - traffic_split: Sequence[ - endpoint_service.DeployModelRequest.TrafficSplitEntry - ] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + traffic_split: Mapping[str, int] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Deploys a Model into this Endpoint, creating a DeployedModel within it. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_deploy_model(): + # Create a client + client = aiplatform_v1.EndpointServiceClient() + + # Initialize request argument(s) + deployed_model = aiplatform_v1.DeployedModel() + deployed_model.dedicated_resources.min_replica_count = 1803 + deployed_model.model = "model_value" + + request = aiplatform_v1.DeployModelRequest( + endpoint="endpoint_value", + deployed_model=deployed_model, + ) + + # Make the request + operation = client.deploy_model(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1.types.DeployModelRequest): + request (Union[google.cloud.aiplatform_v1.types.DeployModelRequest, dict]): The request object. Request message for [EndpointService.DeployModel][google.cloud.aiplatform.v1.EndpointService.DeployModel]. endpoint (str): @@ -824,7 +1144,7 @@ def deploy_model( This corresponds to the ``deployed_model`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - traffic_split (Sequence[google.cloud.aiplatform_v1.types.DeployModelRequest.TrafficSplitEntry]): + traffic_split (Mapping[str, int]): A map from a DeployedModel's ID to the percentage of this Endpoint's traffic that should be forwarded to that DeployedModel. @@ -861,7 +1181,7 @@ def deploy_model( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([endpoint, deployed_model, traffic_split]) if request is not None and has_flattened_params: @@ -896,7 +1216,12 @@ def deploy_model( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -911,14 +1236,12 @@ def deploy_model( def undeploy_model( self, - request: endpoint_service.UndeployModelRequest = None, + request: Union[endpoint_service.UndeployModelRequest, dict] = None, *, endpoint: str = None, deployed_model_id: str = None, - traffic_split: Sequence[ - endpoint_service.UndeployModelRequest.TrafficSplitEntry - ] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + traffic_split: Mapping[str, int] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: @@ -926,8 +1249,32 @@ def undeploy_model( DeployedModel from it, and freeing all resources it's using. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_undeploy_model(): + # Create a client + client = aiplatform_v1.EndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.UndeployModelRequest( + endpoint="endpoint_value", + deployed_model_id="deployed_model_id_value", + ) + + # Make the request + operation = client.undeploy_model(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1.types.UndeployModelRequest): + request (Union[google.cloud.aiplatform_v1.types.UndeployModelRequest, dict]): The request object. Request message for [EndpointService.UndeployModel][google.cloud.aiplatform.v1.EndpointService.UndeployModel]. endpoint (str): @@ -945,7 +1292,7 @@ def undeploy_model( This corresponds to the ``deployed_model_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - traffic_split (Sequence[google.cloud.aiplatform_v1.types.UndeployModelRequest.TrafficSplitEntry]): + traffic_split (Mapping[str, int]): If this field is provided, then the Endpoint's [traffic_split][google.cloud.aiplatform.v1.Endpoint.traffic_split] will be overwritten with it. If last DeployedModel is @@ -976,7 +1323,7 @@ def undeploy_model( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([endpoint, deployed_model_id, traffic_split]) if request is not None and has_flattened_params: @@ -1011,7 +1358,12 @@ def undeploy_model( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -1024,6 +1376,690 @@ def undeploy_model( # Done; return the response. return response + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_operations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.delete_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.wait_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_location, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_locations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/aiplatform_v1/services/endpoint_service/pagers.py b/google/cloud/aiplatform_v1/services/endpoint_service/pagers.py index 0b222aee01..4b65110ad5 100644 --- a/google/cloud/aiplatform_v1/services/endpoint_service/pagers.py +++ b/google/cloud/aiplatform_v1/services/endpoint_service/pagers.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,13 +15,13 @@ # from typing import ( Any, - AsyncIterable, + AsyncIterator, Awaitable, Callable, - Iterable, Sequence, Tuple, Optional, + Iterator, ) from google.cloud.aiplatform_v1.types import endpoint @@ -75,14 +75,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[endpoint_service.ListEndpointsResponse]: + def pages(self) -> Iterator[endpoint_service.ListEndpointsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[endpoint.Endpoint]: + def __iter__(self) -> Iterator[endpoint.Endpoint]: for page in self.pages: yield from page.endpoints @@ -116,7 +116,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -137,14 +137,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - async def pages(self) -> AsyncIterable[endpoint_service.ListEndpointsResponse]: + async def pages(self) -> AsyncIterator[endpoint_service.ListEndpointsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[endpoint.Endpoint]: + def __aiter__(self) -> AsyncIterator[endpoint.Endpoint]: async def async_generator(): async for page in self.pages: for response in page.endpoints: diff --git a/google/cloud/aiplatform_v1/services/endpoint_service/transports/__init__.py b/google/cloud/aiplatform_v1/services/endpoint_service/transports/__init__.py index 4d336c5875..92f3485150 100644 --- a/google/cloud/aiplatform_v1/services/endpoint_service/transports/__init__.py +++ b/google/cloud/aiplatform_v1/services/endpoint_service/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1/services/endpoint_service/transports/base.py b/google/cloud/aiplatform_v1/services/endpoint_service/transports/base.py index a760eddfef..38d4ad241c 100644 --- a/google/cloud/aiplatform_v1/services/endpoint_service/transports/base.py +++ b/google/cloud/aiplatform_v1/services/endpoint_service/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,20 +15,24 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.api_core import operations_v1 # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.aiplatform_v1.types import endpoint from google.cloud.aiplatform_v1.types import endpoint as gca_endpoint from google.cloud.aiplatform_v1.types import endpoint_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore try: @@ -40,17 +44,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - -_API_CORE_VERSION = google.api_core.__version__ - class EndpointServiceTransport(abc.ABC): """Abstract transport class for EndpointService.""" @@ -68,6 +61,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -91,16 +85,19 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -113,88 +110,73 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id ) - # Save the credentials. - self._credentials = credentials - - # TODO(busunkim): These two class methods are in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-api-core - # and google-auth are increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") + # If the credentials are service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs + credentials = credentials.with_always_use_jwt_access(True) - # TODO: Remove this function once google-api-core >= 1.26.0 is required - @classmethod - def _get_self_signed_jwt_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Union[Optional[Sequence[str]], str]]: - """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" - - self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} - - if _API_CORE_VERSION and ( - packaging.version.parse(_API_CORE_VERSION) - >= packaging.version.parse("1.26.0") - ): - self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES - self_signed_jwt_kwargs["scopes"] = scopes - self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST - else: - self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES - - return self_signed_jwt_kwargs + # Save the credentials. + self._credentials = credentials def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { self.create_endpoint: gapic_v1.method.wrap_method( - self.create_endpoint, default_timeout=5.0, client_info=client_info, + self.create_endpoint, + default_timeout=None, + client_info=client_info, ), self.get_endpoint: gapic_v1.method.wrap_method( - self.get_endpoint, default_timeout=5.0, client_info=client_info, + self.get_endpoint, + default_timeout=None, + client_info=client_info, ), self.list_endpoints: gapic_v1.method.wrap_method( - self.list_endpoints, default_timeout=5.0, client_info=client_info, + self.list_endpoints, + default_timeout=None, + client_info=client_info, ), self.update_endpoint: gapic_v1.method.wrap_method( - self.update_endpoint, default_timeout=5.0, client_info=client_info, + self.update_endpoint, + default_timeout=None, + client_info=client_info, ), self.delete_endpoint: gapic_v1.method.wrap_method( - self.delete_endpoint, default_timeout=5.0, client_info=client_info, + self.delete_endpoint, + default_timeout=None, + client_info=client_info, ), self.deploy_model: gapic_v1.method.wrap_method( - self.deploy_model, default_timeout=5.0, client_info=client_info, + self.deploy_model, + default_timeout=None, + client_info=client_info, ), self.undeploy_model: gapic_v1.method.wrap_method( - self.undeploy_model, default_timeout=5.0, client_info=client_info, + self.undeploy_model, + default_timeout=None, + client_info=client_info, ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() @@ -264,5 +246,102 @@ def undeploy_model( ]: raise NotImplementedError() + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], + Union[ + operations_pb2.ListOperationsResponse, + Awaitable[operations_pb2.ListOperationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None,]: + raise NotImplementedError() + + @property + def wait_operation( + self, + ) -> Callable[ + [operations_pb2.WaitOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def set_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def get_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_location( + self, + ) -> Callable[ + [locations_pb2.GetLocationRequest], + Union[locations_pb2.Location, Awaitable[locations_pb2.Location]], + ]: + raise NotImplementedError() + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], + Union[ + locations_pb2.ListLocationsResponse, + Awaitable[locations_pb2.ListLocationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + __all__ = ("EndpointServiceTransport",) diff --git a/google/cloud/aiplatform_v1/services/endpoint_service/transports/grpc.py b/google/cloud/aiplatform_v1/services/endpoint_service/transports/grpc.py index d81853d560..f6de887c2a 100644 --- a/google/cloud/aiplatform_v1/services/endpoint_service/transports/grpc.py +++ b/google/cloud/aiplatform_v1/services/endpoint_service/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,9 +16,9 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import operations_v1 +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -28,6 +28,10 @@ from google.cloud.aiplatform_v1.types import endpoint from google.cloud.aiplatform_v1.types import endpoint as gca_endpoint from google.cloud.aiplatform_v1.types import endpoint_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from .base import EndpointServiceTransport, DEFAULT_CLIENT_INFO @@ -35,6 +39,8 @@ class EndpointServiceGrpcTransport(EndpointServiceTransport): """gRPC backend transport for EndpointService. + A service for managing Vertex AI's Endpoints. + This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation and call it. @@ -59,6 +65,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -81,16 +88,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -99,6 +106,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport @@ -109,7 +118,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -152,13 +161,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -207,21 +220,20 @@ def create_channel( and ``credentials_file`` are passed. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @property def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ + """Return the channel designed to connect to this service.""" return self._grpc_channel @property @@ -231,7 +243,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsClient(self.grpc_channel) @@ -425,5 +437,215 @@ def undeploy_model( ) return self._stubs["undeploy_model"] + def close(self): + self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + @property + def kind(self) -> str: + return "grpc" + __all__ = ("EndpointServiceGrpcTransport",) diff --git a/google/cloud/aiplatform_v1/services/endpoint_service/transports/grpc_asyncio.py b/google/cloud/aiplatform_v1/services/endpoint_service/transports/grpc_asyncio.py index 41f295e135..f2c05e7bbc 100644 --- a/google/cloud/aiplatform_v1/services/endpoint_service/transports/grpc_asyncio.py +++ b/google/cloud/aiplatform_v1/services/endpoint_service/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,12 +16,11 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore -from google.api_core import operations_v1 # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore @@ -29,6 +28,10 @@ from google.cloud.aiplatform_v1.types import endpoint from google.cloud.aiplatform_v1.types import endpoint as gca_endpoint from google.cloud.aiplatform_v1.types import endpoint_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from .base import EndpointServiceTransport, DEFAULT_CLIENT_INFO from .grpc import EndpointServiceGrpcTransport @@ -37,6 +40,8 @@ class EndpointServiceGrpcAsyncIOTransport(EndpointServiceTransport): """gRPC AsyncIO backend transport for EndpointService. + A service for managing Vertex AI's Endpoints. + This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation and call it. @@ -80,14 +85,14 @@ def create_channel( aio.Channel: A gRPC AsyncIO channel object. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @@ -105,6 +110,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -128,16 +134,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -146,6 +152,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport @@ -156,7 +164,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -198,13 +206,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -234,7 +246,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel @@ -441,5 +453,211 @@ def undeploy_model( ) return self._stubs["undeploy_model"] + def close(self): + return self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + __all__ = ("EndpointServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/aiplatform_v1/services/featurestore_online_serving_service/__init__.py b/google/cloud/aiplatform_v1/services/featurestore_online_serving_service/__init__.py new file mode 100644 index 0000000000..a2f6b5fa66 --- /dev/null +++ b/google/cloud/aiplatform_v1/services/featurestore_online_serving_service/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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 .client import FeaturestoreOnlineServingServiceClient +from .async_client import FeaturestoreOnlineServingServiceAsyncClient + +__all__ = ( + "FeaturestoreOnlineServingServiceClient", + "FeaturestoreOnlineServingServiceAsyncClient", +) diff --git a/google/cloud/aiplatform_v1/services/featurestore_online_serving_service/async_client.py b/google/cloud/aiplatform_v1/services/featurestore_online_serving_service/async_client.py new file mode 100644 index 0000000000..37cd57510a --- /dev/null +++ b/google/cloud/aiplatform_v1/services/featurestore_online_serving_service/async_client.py @@ -0,0 +1,1148 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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, + Mapping, + Optional, + AsyncIterable, + Awaitable, + Sequence, + Tuple, + Type, + Union, +) +import pkg_resources + +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore + +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + +from google.cloud.aiplatform_v1.types import featurestore_online_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from .transports.base import ( + FeaturestoreOnlineServingServiceTransport, + DEFAULT_CLIENT_INFO, +) +from .transports.grpc_asyncio import ( + FeaturestoreOnlineServingServiceGrpcAsyncIOTransport, +) +from .client import FeaturestoreOnlineServingServiceClient + + +class FeaturestoreOnlineServingServiceAsyncClient: + """A service for serving online feature values.""" + + _client: FeaturestoreOnlineServingServiceClient + + DEFAULT_ENDPOINT = FeaturestoreOnlineServingServiceClient.DEFAULT_ENDPOINT + DEFAULT_MTLS_ENDPOINT = FeaturestoreOnlineServingServiceClient.DEFAULT_MTLS_ENDPOINT + + entity_type_path = staticmethod( + FeaturestoreOnlineServingServiceClient.entity_type_path + ) + parse_entity_type_path = staticmethod( + FeaturestoreOnlineServingServiceClient.parse_entity_type_path + ) + common_billing_account_path = staticmethod( + FeaturestoreOnlineServingServiceClient.common_billing_account_path + ) + parse_common_billing_account_path = staticmethod( + FeaturestoreOnlineServingServiceClient.parse_common_billing_account_path + ) + common_folder_path = staticmethod( + FeaturestoreOnlineServingServiceClient.common_folder_path + ) + parse_common_folder_path = staticmethod( + FeaturestoreOnlineServingServiceClient.parse_common_folder_path + ) + common_organization_path = staticmethod( + FeaturestoreOnlineServingServiceClient.common_organization_path + ) + parse_common_organization_path = staticmethod( + FeaturestoreOnlineServingServiceClient.parse_common_organization_path + ) + common_project_path = staticmethod( + FeaturestoreOnlineServingServiceClient.common_project_path + ) + parse_common_project_path = staticmethod( + FeaturestoreOnlineServingServiceClient.parse_common_project_path + ) + common_location_path = staticmethod( + FeaturestoreOnlineServingServiceClient.common_location_path + ) + parse_common_location_path = staticmethod( + FeaturestoreOnlineServingServiceClient.parse_common_location_path + ) + + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials + info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + FeaturestoreOnlineServingServiceAsyncClient: The constructed client. + """ + return FeaturestoreOnlineServingServiceClient.from_service_account_info.__func__(FeaturestoreOnlineServingServiceAsyncClient, info, *args, **kwargs) # type: ignore + + @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: + FeaturestoreOnlineServingServiceAsyncClient: The constructed client. + """ + return FeaturestoreOnlineServingServiceClient.from_service_account_file.__func__(FeaturestoreOnlineServingServiceAsyncClient, filename, *args, **kwargs) # type: ignore + + from_service_account_json = from_service_account_file + + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return FeaturestoreOnlineServingServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + + @property + def transport(self) -> FeaturestoreOnlineServingServiceTransport: + """Returns the transport used by the client instance. + + Returns: + FeaturestoreOnlineServingServiceTransport: The transport used by the client instance. + """ + return self._client.transport + + get_transport_class = functools.partial( + type(FeaturestoreOnlineServingServiceClient).get_transport_class, + type(FeaturestoreOnlineServingServiceClient), + ) + + def __init__( + self, + *, + credentials: ga_credentials.Credentials = None, + transport: Union[ + str, FeaturestoreOnlineServingServiceTransport + ] = "grpc_asyncio", + client_options: ClientOptions = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the featurestore online serving 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, ~.FeaturestoreOnlineServingServiceTransport]): 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 = FeaturestoreOnlineServingServiceClient( + credentials=credentials, + transport=transport, + client_options=client_options, + client_info=client_info, + ) + + async def read_feature_values( + self, + request: Union[ + featurestore_online_service.ReadFeatureValuesRequest, dict + ] = None, + *, + entity_type: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> featurestore_online_service.ReadFeatureValuesResponse: + r"""Reads Feature values of a specific entity of an + EntityType. For reading feature values of multiple + entities of an EntityType, please use + StreamingReadFeatureValues. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_read_feature_values(): + # Create a client + client = aiplatform_v1.FeaturestoreOnlineServingServiceAsyncClient() + + # Initialize request argument(s) + feature_selector = aiplatform_v1.FeatureSelector() + feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1.ReadFeatureValuesRequest( + entity_type="entity_type_value", + entity_id="entity_id_value", + feature_selector=feature_selector, + ) + + # Make the request + response = await client.read_feature_values(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ReadFeatureValuesRequest, dict]): + The request object. Request message for + [FeaturestoreOnlineServingService.ReadFeatureValues][google.cloud.aiplatform.v1.FeaturestoreOnlineServingService.ReadFeatureValues]. + entity_type (:class:`str`): + Required. The resource name of the EntityType for the + entity being read. Value format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entityType}``. + For example, for a machine learning model predicting + user clicks on a website, an EntityType ID could be + ``user``. + + This corresponds to the ``entity_type`` 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: + google.cloud.aiplatform_v1.types.ReadFeatureValuesResponse: + Response message for + [FeaturestoreOnlineServingService.ReadFeatureValues][google.cloud.aiplatform.v1.FeaturestoreOnlineServingService.ReadFeatureValues]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([entity_type]) + 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 = featurestore_online_service.ReadFeatureValuesRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if entity_type is not None: + request.entity_type = entity_type + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.read_feature_values, + default_timeout=None, + 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( + (("entity_type", request.entity_type),) + ), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def streaming_read_feature_values( + self, + request: Union[ + featurestore_online_service.StreamingReadFeatureValuesRequest, dict + ] = None, + *, + entity_type: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> Awaitable[ + AsyncIterable[featurestore_online_service.ReadFeatureValuesResponse] + ]: + r"""Reads Feature values for multiple entities. Depending + on their size, data for different entities may be broken + up across multiple responses. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_streaming_read_feature_values(): + # Create a client + client = aiplatform_v1.FeaturestoreOnlineServingServiceAsyncClient() + + # Initialize request argument(s) + feature_selector = aiplatform_v1.FeatureSelector() + feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1.StreamingReadFeatureValuesRequest( + entity_type="entity_type_value", + entity_ids=['entity_ids_value_1', 'entity_ids_value_2'], + feature_selector=feature_selector, + ) + + # Make the request + stream = await client.streaming_read_feature_values(request=request) + + # Handle the response + async for response in stream: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.StreamingReadFeatureValuesRequest, dict]): + The request object. Request message for + [FeaturestoreOnlineServingService.StreamingFeatureValuesRead][]. + entity_type (:class:`str`): + Required. The resource name of the entities' type. Value + format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entityType}``. + For example, for a machine learning model predicting + user clicks on a website, an EntityType ID could be + ``user``. + + This corresponds to the ``entity_type`` 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: + AsyncIterable[google.cloud.aiplatform_v1.types.ReadFeatureValuesResponse]: + Response message for + [FeaturestoreOnlineServingService.ReadFeatureValues][google.cloud.aiplatform.v1.FeaturestoreOnlineServingService.ReadFeatureValues]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([entity_type]) + 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 = featurestore_online_service.StreamingReadFeatureValuesRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if entity_type is not None: + request.entity_type = entity_type + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.streaming_read_feature_values, + default_timeout=None, + 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( + (("entity_type", request.entity_type),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_operations, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.delete_operation, + default_timeout=None, + 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 cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + 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 wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.wait_operation, + default_timeout=None, + 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 set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_location, + default_timeout=None, + 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 list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_locations, + default_timeout=None, + 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 __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-aiplatform", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ("FeaturestoreOnlineServingServiceAsyncClient",) diff --git a/google/cloud/aiplatform_v1/services/featurestore_online_serving_service/client.py b/google/cloud/aiplatform_v1/services/featurestore_online_serving_service/client.py new file mode 100644 index 0000000000..4e64bc8a22 --- /dev/null +++ b/google/cloud/aiplatform_v1/services/featurestore_online_serving_service/client.py @@ -0,0 +1,1368 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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 os +import re +from typing import Dict, Mapping, Optional, Iterable, Sequence, Tuple, Type, Union +import pkg_resources + +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.auth import credentials as ga_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 + +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + +from google.cloud.aiplatform_v1.types import featurestore_online_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from .transports.base import ( + FeaturestoreOnlineServingServiceTransport, + DEFAULT_CLIENT_INFO, +) +from .transports.grpc import FeaturestoreOnlineServingServiceGrpcTransport +from .transports.grpc_asyncio import ( + FeaturestoreOnlineServingServiceGrpcAsyncIOTransport, +) + + +class FeaturestoreOnlineServingServiceClientMeta(type): + """Metaclass for the FeaturestoreOnlineServingService 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[FeaturestoreOnlineServingServiceTransport]] + _transport_registry["grpc"] = FeaturestoreOnlineServingServiceGrpcTransport + _transport_registry[ + "grpc_asyncio" + ] = FeaturestoreOnlineServingServiceGrpcAsyncIOTransport + + def get_transport_class( + cls, + label: str = None, + ) -> Type[FeaturestoreOnlineServingServiceTransport]: + """Returns 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 FeaturestoreOnlineServingServiceClient( + metaclass=FeaturestoreOnlineServingServiceClientMeta +): + """A service for serving online feature values.""" + + @staticmethod + def _get_default_mtls_endpoint(api_endpoint): + """Converts 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 = "aiplatform.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials + info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + FeaturestoreOnlineServingServiceClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + + @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: + FeaturestoreOnlineServingServiceClient: 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) -> FeaturestoreOnlineServingServiceTransport: + """Returns the transport used by the client instance. + + Returns: + FeaturestoreOnlineServingServiceTransport: The transport used by the client + instance. + """ + return self._transport + + @staticmethod + def entity_type_path( + project: str, + location: str, + featurestore: str, + entity_type: str, + ) -> str: + """Returns a fully-qualified entity_type string.""" + return "projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}".format( + project=project, + location=location, + featurestore=featurestore, + entity_type=entity_type, + ) + + @staticmethod + def parse_entity_type_path(path: str) -> Dict[str, str]: + """Parses a entity_type path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/featurestores/(?P.+?)/entityTypes/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def common_billing_account_path( + billing_account: str, + ) -> str: + """Returns 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: + """Returns 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: + """Returns 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: + """Returns 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: + """Returns 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 {} + + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + + def __init__( + self, + *, + credentials: Optional[ga_credentials.Credentials] = None, + transport: Union[str, FeaturestoreOnlineServingServiceTransport, None] = None, + client_options: Optional[client_options_lib.ClientOptions] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the featurestore online serving 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, FeaturestoreOnlineServingServiceTransport]): The + transport to use. If set to None, a transport is chosen + automatically. + client_options (google.api_core.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. + 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() + + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options + ) + + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) + + # 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, FeaturestoreOnlineServingServiceTransport): + # transport is a FeaturestoreOnlineServingServiceTransport instance. + if credentials or client_options.credentials_file or api_key_value: + 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: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + + 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, + client_cert_source_for_mtls=client_cert_source_func, + quota_project_id=client_options.quota_project_id, + client_info=client_info, + always_use_jwt_access=True, + ) + + def read_feature_values( + self, + request: Union[ + featurestore_online_service.ReadFeatureValuesRequest, dict + ] = None, + *, + entity_type: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> featurestore_online_service.ReadFeatureValuesResponse: + r"""Reads Feature values of a specific entity of an + EntityType. For reading feature values of multiple + entities of an EntityType, please use + StreamingReadFeatureValues. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_read_feature_values(): + # Create a client + client = aiplatform_v1.FeaturestoreOnlineServingServiceClient() + + # Initialize request argument(s) + feature_selector = aiplatform_v1.FeatureSelector() + feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1.ReadFeatureValuesRequest( + entity_type="entity_type_value", + entity_id="entity_id_value", + feature_selector=feature_selector, + ) + + # Make the request + response = client.read_feature_values(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ReadFeatureValuesRequest, dict]): + The request object. Request message for + [FeaturestoreOnlineServingService.ReadFeatureValues][google.cloud.aiplatform.v1.FeaturestoreOnlineServingService.ReadFeatureValues]. + entity_type (str): + Required. The resource name of the EntityType for the + entity being read. Value format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entityType}``. + For example, for a machine learning model predicting + user clicks on a website, an EntityType ID could be + ``user``. + + This corresponds to the ``entity_type`` 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: + google.cloud.aiplatform_v1.types.ReadFeatureValuesResponse: + Response message for + [FeaturestoreOnlineServingService.ReadFeatureValues][google.cloud.aiplatform.v1.FeaturestoreOnlineServingService.ReadFeatureValues]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([entity_type]) + 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 featurestore_online_service.ReadFeatureValuesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, featurestore_online_service.ReadFeatureValuesRequest + ): + request = featurestore_online_service.ReadFeatureValuesRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if entity_type is not None: + request.entity_type = entity_type + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.read_feature_values] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("entity_type", request.entity_type),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def streaming_read_feature_values( + self, + request: Union[ + featurestore_online_service.StreamingReadFeatureValuesRequest, dict + ] = None, + *, + entity_type: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> Iterable[featurestore_online_service.ReadFeatureValuesResponse]: + r"""Reads Feature values for multiple entities. Depending + on their size, data for different entities may be broken + up across multiple responses. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_streaming_read_feature_values(): + # Create a client + client = aiplatform_v1.FeaturestoreOnlineServingServiceClient() + + # Initialize request argument(s) + feature_selector = aiplatform_v1.FeatureSelector() + feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1.StreamingReadFeatureValuesRequest( + entity_type="entity_type_value", + entity_ids=['entity_ids_value_1', 'entity_ids_value_2'], + feature_selector=feature_selector, + ) + + # Make the request + stream = client.streaming_read_feature_values(request=request) + + # Handle the response + for response in stream: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.StreamingReadFeatureValuesRequest, dict]): + The request object. Request message for + [FeaturestoreOnlineServingService.StreamingFeatureValuesRead][]. + entity_type (str): + Required. The resource name of the entities' type. Value + format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entityType}``. + For example, for a machine learning model predicting + user clicks on a website, an EntityType ID could be + ``user``. + + This corresponds to the ``entity_type`` 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: + Iterable[google.cloud.aiplatform_v1.types.ReadFeatureValuesResponse]: + Response message for + [FeaturestoreOnlineServingService.ReadFeatureValues][google.cloud.aiplatform.v1.FeaturestoreOnlineServingService.ReadFeatureValues]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([entity_type]) + 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 featurestore_online_service.StreamingReadFeatureValuesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, featurestore_online_service.StreamingReadFeatureValuesRequest + ): + request = featurestore_online_service.StreamingReadFeatureValuesRequest( + request + ) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if entity_type is not None: + request.entity_type = entity_type + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.streaming_read_feature_values + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("entity_type", request.entity_type),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_operations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.delete_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.wait_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_location, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_locations, + default_timeout=None, + 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 = 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-aiplatform", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ("FeaturestoreOnlineServingServiceClient",) diff --git a/google/cloud/aiplatform_v1/services/featurestore_online_serving_service/transports/__init__.py b/google/cloud/aiplatform_v1/services/featurestore_online_serving_service/transports/__init__.py new file mode 100644 index 0000000000..c929d350e6 --- /dev/null +++ b/google/cloud/aiplatform_v1/services/featurestore_online_serving_service/transports/__init__.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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 typing import Dict, Type + +from .base import FeaturestoreOnlineServingServiceTransport +from .grpc import FeaturestoreOnlineServingServiceGrpcTransport +from .grpc_asyncio import FeaturestoreOnlineServingServiceGrpcAsyncIOTransport + + +# Compile a registry of transports. +_transport_registry = ( + OrderedDict() +) # type: Dict[str, Type[FeaturestoreOnlineServingServiceTransport]] +_transport_registry["grpc"] = FeaturestoreOnlineServingServiceGrpcTransport +_transport_registry[ + "grpc_asyncio" +] = FeaturestoreOnlineServingServiceGrpcAsyncIOTransport + +__all__ = ( + "FeaturestoreOnlineServingServiceTransport", + "FeaturestoreOnlineServingServiceGrpcTransport", + "FeaturestoreOnlineServingServiceGrpcAsyncIOTransport", +) diff --git a/google/cloud/aiplatform_v1/services/featurestore_online_serving_service/transports/base.py b/google/cloud/aiplatform_v1/services/featurestore_online_serving_service/transports/base.py new file mode 100644 index 0000000000..e7ff1c284e --- /dev/null +++ b/google/cloud/aiplatform_v1/services/featurestore_online_serving_service/transports/base.py @@ -0,0 +1,271 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import abc +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +import pkg_resources + +import google.auth # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore + +from google.cloud.aiplatform_v1.types import featurestore_online_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-aiplatform", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +class FeaturestoreOnlineServingServiceTransport(abc.ABC): + """Abstract transport class for FeaturestoreOnlineServingService.""" + + AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) + + DEFAULT_HOST: str = "aiplatform.googleapis.com" + + def __init__( + self, + *, + host: str = DEFAULT_HOST, + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + **kwargs, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + 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. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is mutually exclusive with credentials. + scopes (Optional[Sequence[str]]): A list of scopes. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + 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. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + """ + + # Save the hostname. Default to port 443 (HTTPS) if none is specified. + if ":" not in host: + host += ":443" + self._host = host + + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} + + # Save the scopes. + self._scopes = scopes + + # If no credentials are provided, then determine the appropriate + # defaults. + if credentials and credentials_file: + raise core_exceptions.DuplicateCredentialArgs( + "'credentials_file' and 'credentials' are mutually exclusive" + ) + + if credentials_file is not None: + credentials, _ = google.auth.load_credentials_from_file( + credentials_file, **scopes_kwargs, quota_project_id=quota_project_id + ) + elif credentials is None: + credentials, _ = google.auth.default( + **scopes_kwargs, quota_project_id=quota_project_id + ) + + # If the credentials are service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + + # Save the credentials. + self._credentials = credentials + + def _prep_wrapped_messages(self, client_info): + # Precompute the wrapped methods. + self._wrapped_methods = { + self.read_feature_values: gapic_v1.method.wrap_method( + self.read_feature_values, + default_timeout=None, + client_info=client_info, + ), + self.streaming_read_feature_values: gapic_v1.method.wrap_method( + self.streaming_read_feature_values, + default_timeout=None, + client_info=client_info, + ), + } + + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + + @property + def read_feature_values( + self, + ) -> Callable[ + [featurestore_online_service.ReadFeatureValuesRequest], + Union[ + featurestore_online_service.ReadFeatureValuesResponse, + Awaitable[featurestore_online_service.ReadFeatureValuesResponse], + ], + ]: + raise NotImplementedError() + + @property + def streaming_read_feature_values( + self, + ) -> Callable[ + [featurestore_online_service.StreamingReadFeatureValuesRequest], + Union[ + featurestore_online_service.ReadFeatureValuesResponse, + Awaitable[featurestore_online_service.ReadFeatureValuesResponse], + ], + ]: + raise NotImplementedError() + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], + Union[ + operations_pb2.ListOperationsResponse, + Awaitable[operations_pb2.ListOperationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None,]: + raise NotImplementedError() + + @property + def wait_operation( + self, + ) -> Callable[ + [operations_pb2.WaitOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def set_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def get_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_location( + self, + ) -> Callable[ + [locations_pb2.GetLocationRequest], + Union[locations_pb2.Location, Awaitable[locations_pb2.Location]], + ]: + raise NotImplementedError() + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], + Union[ + locations_pb2.ListLocationsResponse, + Awaitable[locations_pb2.ListLocationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + + +__all__ = ("FeaturestoreOnlineServingServiceTransport",) diff --git a/google/cloud/aiplatform_v1/services/featurestore_online_serving_service/transports/grpc.py b/google/cloud/aiplatform_v1/services/featurestore_online_serving_service/transports/grpc.py new file mode 100644 index 0000000000..150569313b --- /dev/null +++ b/google/cloud/aiplatform_v1/services/featurestore_online_serving_service/transports/grpc.py @@ -0,0 +1,512 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import warnings +from typing import Callable, Dict, Optional, Sequence, Tuple, Union + +from google.api_core import grpc_helpers +from google.api_core import gapic_v1 +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore + +import grpc # type: ignore + +from google.cloud.aiplatform_v1.types import featurestore_online_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from .base import FeaturestoreOnlineServingServiceTransport, DEFAULT_CLIENT_INFO + + +class FeaturestoreOnlineServingServiceGrpcTransport( + FeaturestoreOnlineServingServiceTransport +): + """gRPC backend transport for FeaturestoreOnlineServingService. + + A service for serving online feature values. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + + _stubs: Dict[str, Callable] + + def __init__( + self, + *, + host: str = "aiplatform.googleapis.com", + credentials: ga_credentials.Credentials = None, + credentials_file: str = None, + scopes: Sequence[str] = None, + channel: grpc.Channel = None, + api_mtls_endpoint: str = None, + client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, + ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + 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. + This argument is ignored if ``channel`` is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional(Sequence[str])): A list of scopes. This argument is + ignored if ``channel`` is provided. + channel (Optional[grpc.Channel]): A ``Channel`` instance through + which to make calls. + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or application default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for the grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure a mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + 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. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + self._grpc_channel = None + self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + + if channel: + # Ignore credentials if a channel was passed. + credentials = False + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + self._ssl_channel_credentials = None + + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials + + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + ) + + if not self._grpc_channel: + self._grpc_channel = type(self).create_channel( + self._host, + # use the credentials which are saved + credentials=self._credentials, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, + quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) + + @classmethod + def create_channel( + cls, + host: str = "aiplatform.googleapis.com", + credentials: ga_credentials.Credentials = None, + credentials_file: str = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs, + ) -> grpc.Channel: + """Create and return a gRPC channel object. + Args: + host (Optional[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is mutually exclusive with credentials. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + grpc.Channel: A gRPC channel object. + + Raises: + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + + return grpc_helpers.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + quota_project_id=quota_project_id, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, + **kwargs, + ) + + @property + def grpc_channel(self) -> grpc.Channel: + """Return the channel designed to connect to this service.""" + return self._grpc_channel + + @property + def read_feature_values( + self, + ) -> Callable[ + [featurestore_online_service.ReadFeatureValuesRequest], + featurestore_online_service.ReadFeatureValuesResponse, + ]: + r"""Return a callable for the read feature values method over gRPC. + + Reads Feature values of a specific entity of an + EntityType. For reading feature values of multiple + entities of an EntityType, please use + StreamingReadFeatureValues. + + Returns: + Callable[[~.ReadFeatureValuesRequest], + ~.ReadFeatureValuesResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "read_feature_values" not in self._stubs: + self._stubs["read_feature_values"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreOnlineServingService/ReadFeatureValues", + request_serializer=featurestore_online_service.ReadFeatureValuesRequest.serialize, + response_deserializer=featurestore_online_service.ReadFeatureValuesResponse.deserialize, + ) + return self._stubs["read_feature_values"] + + @property + def streaming_read_feature_values( + self, + ) -> Callable[ + [featurestore_online_service.StreamingReadFeatureValuesRequest], + featurestore_online_service.ReadFeatureValuesResponse, + ]: + r"""Return a callable for the streaming read feature values method over gRPC. + + Reads Feature values for multiple entities. Depending + on their size, data for different entities may be broken + up across multiple responses. + + Returns: + Callable[[~.StreamingReadFeatureValuesRequest], + ~.ReadFeatureValuesResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "streaming_read_feature_values" not in self._stubs: + self._stubs[ + "streaming_read_feature_values" + ] = self.grpc_channel.unary_stream( + "/google.cloud.aiplatform.v1.FeaturestoreOnlineServingService/StreamingReadFeatureValues", + request_serializer=featurestore_online_service.StreamingReadFeatureValuesRequest.serialize, + response_deserializer=featurestore_online_service.ReadFeatureValuesResponse.deserialize, + ) + return self._stubs["streaming_read_feature_values"] + + def close(self): + self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + @property + def kind(self) -> str: + return "grpc" + + +__all__ = ("FeaturestoreOnlineServingServiceGrpcTransport",) diff --git a/google/cloud/aiplatform_v1/services/featurestore_online_serving_service/transports/grpc_asyncio.py b/google/cloud/aiplatform_v1/services/featurestore_online_serving_service/transports/grpc_asyncio.py new file mode 100644 index 0000000000..9bfcb672aa --- /dev/null +++ b/google/cloud/aiplatform_v1/services/featurestore_online_serving_service/transports/grpc_asyncio.py @@ -0,0 +1,511 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import warnings +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union + +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore + +import grpc # type: ignore +from grpc.experimental import aio # type: ignore + +from google.cloud.aiplatform_v1.types import featurestore_online_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from .base import FeaturestoreOnlineServingServiceTransport, DEFAULT_CLIENT_INFO +from .grpc import FeaturestoreOnlineServingServiceGrpcTransport + + +class FeaturestoreOnlineServingServiceGrpcAsyncIOTransport( + FeaturestoreOnlineServingServiceTransport +): + """gRPC AsyncIO backend transport for FeaturestoreOnlineServingService. + + A service for serving online feature values. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + + _grpc_channel: aio.Channel + _stubs: Dict[str, Callable] = {} + + @classmethod + def create_channel( + cls, + host: str = "aiplatform.googleapis.com", + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs, + ) -> aio.Channel: + """Create and return a gRPC AsyncIO channel object. + Args: + host (Optional[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + aio.Channel: A gRPC AsyncIO channel object. + """ + + return grpc_helpers_async.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + quota_project_id=quota_project_id, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, + **kwargs, + ) + + def __init__( + self, + *, + host: str = "aiplatform.googleapis.com", + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: aio.Channel = None, + api_mtls_endpoint: str = None, + client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, + ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, + quota_project_id=None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + 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. + This argument is ignored if ``channel`` is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + channel (Optional[aio.Channel]): A ``Channel`` instance through + which to make calls. + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or application default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for the grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure a mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + 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. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + + Raises: + google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + self._grpc_channel = None + self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + + if channel: + # Ignore credentials if a channel was passed. + credentials = False + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + self._ssl_channel_credentials = None + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials + + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + ) + + if not self._grpc_channel: + self._grpc_channel = type(self).create_channel( + self._host, + # use the credentials which are saved + credentials=self._credentials, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, + quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) + + @property + def grpc_channel(self) -> aio.Channel: + """Create the channel designed to connect to this service. + + This property caches on the instance; repeated calls return + the same channel. + """ + # Return the channel from cache. + return self._grpc_channel + + @property + def read_feature_values( + self, + ) -> Callable[ + [featurestore_online_service.ReadFeatureValuesRequest], + Awaitable[featurestore_online_service.ReadFeatureValuesResponse], + ]: + r"""Return a callable for the read feature values method over gRPC. + + Reads Feature values of a specific entity of an + EntityType. For reading feature values of multiple + entities of an EntityType, please use + StreamingReadFeatureValues. + + Returns: + Callable[[~.ReadFeatureValuesRequest], + Awaitable[~.ReadFeatureValuesResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "read_feature_values" not in self._stubs: + self._stubs["read_feature_values"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreOnlineServingService/ReadFeatureValues", + request_serializer=featurestore_online_service.ReadFeatureValuesRequest.serialize, + response_deserializer=featurestore_online_service.ReadFeatureValuesResponse.deserialize, + ) + return self._stubs["read_feature_values"] + + @property + def streaming_read_feature_values( + self, + ) -> Callable[ + [featurestore_online_service.StreamingReadFeatureValuesRequest], + Awaitable[featurestore_online_service.ReadFeatureValuesResponse], + ]: + r"""Return a callable for the streaming read feature values method over gRPC. + + Reads Feature values for multiple entities. Depending + on their size, data for different entities may be broken + up across multiple responses. + + Returns: + Callable[[~.StreamingReadFeatureValuesRequest], + Awaitable[~.ReadFeatureValuesResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "streaming_read_feature_values" not in self._stubs: + self._stubs[ + "streaming_read_feature_values" + ] = self.grpc_channel.unary_stream( + "/google.cloud.aiplatform.v1.FeaturestoreOnlineServingService/StreamingReadFeatureValues", + request_serializer=featurestore_online_service.StreamingReadFeatureValuesRequest.serialize, + response_deserializer=featurestore_online_service.ReadFeatureValuesResponse.deserialize, + ) + return self._stubs["streaming_read_feature_values"] + + def close(self): + return self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + +__all__ = ("FeaturestoreOnlineServingServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/aiplatform_v1/services/featurestore_service/__init__.py b/google/cloud/aiplatform_v1/services/featurestore_service/__init__.py new file mode 100644 index 0000000000..3f53c57568 --- /dev/null +++ b/google/cloud/aiplatform_v1/services/featurestore_service/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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 .client import FeaturestoreServiceClient +from .async_client import FeaturestoreServiceAsyncClient + +__all__ = ( + "FeaturestoreServiceClient", + "FeaturestoreServiceAsyncClient", +) diff --git a/google/cloud/aiplatform_v1/services/featurestore_service/async_client.py b/google/cloud/aiplatform_v1/services/featurestore_service/async_client.py new file mode 100644 index 0000000000..c2f7102c03 --- /dev/null +++ b/google/cloud/aiplatform_v1/services/featurestore_service/async_client.py @@ -0,0 +1,3464 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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, Mapping, Optional, Sequence, Tuple, Type, Union +import pkg_resources + +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore + +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + +from google.api_core import operation as gac_operation # type: ignore +from google.api_core import operation_async # type: ignore +from google.cloud.aiplatform_v1.services.featurestore_service import pagers +from google.cloud.aiplatform_v1.types import encryption_spec +from google.cloud.aiplatform_v1.types import entity_type +from google.cloud.aiplatform_v1.types import entity_type as gca_entity_type +from google.cloud.aiplatform_v1.types import feature +from google.cloud.aiplatform_v1.types import feature as gca_feature +from google.cloud.aiplatform_v1.types import featurestore +from google.cloud.aiplatform_v1.types import featurestore as gca_featurestore +from google.cloud.aiplatform_v1.types import featurestore_monitoring +from google.cloud.aiplatform_v1.types import featurestore_service +from google.cloud.aiplatform_v1.types import operation as gca_operation +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from .transports.base import FeaturestoreServiceTransport, DEFAULT_CLIENT_INFO +from .transports.grpc_asyncio import FeaturestoreServiceGrpcAsyncIOTransport +from .client import FeaturestoreServiceClient + + +class FeaturestoreServiceAsyncClient: + """The service that handles CRUD and List for resources for + Featurestore. + """ + + _client: FeaturestoreServiceClient + + DEFAULT_ENDPOINT = FeaturestoreServiceClient.DEFAULT_ENDPOINT + DEFAULT_MTLS_ENDPOINT = FeaturestoreServiceClient.DEFAULT_MTLS_ENDPOINT + + entity_type_path = staticmethod(FeaturestoreServiceClient.entity_type_path) + parse_entity_type_path = staticmethod( + FeaturestoreServiceClient.parse_entity_type_path + ) + feature_path = staticmethod(FeaturestoreServiceClient.feature_path) + parse_feature_path = staticmethod(FeaturestoreServiceClient.parse_feature_path) + featurestore_path = staticmethod(FeaturestoreServiceClient.featurestore_path) + parse_featurestore_path = staticmethod( + FeaturestoreServiceClient.parse_featurestore_path + ) + common_billing_account_path = staticmethod( + FeaturestoreServiceClient.common_billing_account_path + ) + parse_common_billing_account_path = staticmethod( + FeaturestoreServiceClient.parse_common_billing_account_path + ) + common_folder_path = staticmethod(FeaturestoreServiceClient.common_folder_path) + parse_common_folder_path = staticmethod( + FeaturestoreServiceClient.parse_common_folder_path + ) + common_organization_path = staticmethod( + FeaturestoreServiceClient.common_organization_path + ) + parse_common_organization_path = staticmethod( + FeaturestoreServiceClient.parse_common_organization_path + ) + common_project_path = staticmethod(FeaturestoreServiceClient.common_project_path) + parse_common_project_path = staticmethod( + FeaturestoreServiceClient.parse_common_project_path + ) + common_location_path = staticmethod(FeaturestoreServiceClient.common_location_path) + parse_common_location_path = staticmethod( + FeaturestoreServiceClient.parse_common_location_path + ) + + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials + info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + FeaturestoreServiceAsyncClient: The constructed client. + """ + return FeaturestoreServiceClient.from_service_account_info.__func__(FeaturestoreServiceAsyncClient, info, *args, **kwargs) # type: ignore + + @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: + FeaturestoreServiceAsyncClient: The constructed client. + """ + return FeaturestoreServiceClient.from_service_account_file.__func__(FeaturestoreServiceAsyncClient, filename, *args, **kwargs) # type: ignore + + from_service_account_json = from_service_account_file + + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return FeaturestoreServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + + @property + def transport(self) -> FeaturestoreServiceTransport: + """Returns the transport used by the client instance. + + Returns: + FeaturestoreServiceTransport: The transport used by the client instance. + """ + return self._client.transport + + get_transport_class = functools.partial( + type(FeaturestoreServiceClient).get_transport_class, + type(FeaturestoreServiceClient), + ) + + def __init__( + self, + *, + credentials: ga_credentials.Credentials = None, + transport: Union[str, FeaturestoreServiceTransport] = "grpc_asyncio", + client_options: ClientOptions = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the featurestore 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, ~.FeaturestoreServiceTransport]): 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 = FeaturestoreServiceClient( + credentials=credentials, + transport=transport, + client_options=client_options, + client_info=client_info, + ) + + async def create_featurestore( + self, + request: Union[featurestore_service.CreateFeaturestoreRequest, dict] = None, + *, + parent: str = None, + featurestore: gca_featurestore.Featurestore = None, + featurestore_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Creates a new Featurestore in a given project and + location. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_create_featurestore(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateFeaturestoreRequest( + parent="parent_value", + featurestore_id="featurestore_id_value", + ) + + # Make the request + operation = client.create_featurestore(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CreateFeaturestoreRequest, dict]): + The request object. Request message for + [FeaturestoreService.CreateFeaturestore][google.cloud.aiplatform.v1.FeaturestoreService.CreateFeaturestore]. + parent (:class:`str`): + Required. The resource name of the Location to create + Featurestores. Format: + ``projects/{project}/locations/{location}'`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + featurestore (:class:`google.cloud.aiplatform_v1.types.Featurestore`): + Required. The Featurestore to create. + This corresponds to the ``featurestore`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + featurestore_id (:class:`str`): + Required. The ID to use for this Featurestore, which + will become the final component of the Featurestore's + resource name. + + This value may be up to 60 characters, and valid + characters are ``[a-z0-9_]``. The first character cannot + be a number. + + The value must be unique within the project and + location. + + This corresponds to the ``featurestore_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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.cloud.aiplatform_v1.types.Featurestore` Vertex AI Feature Store provides a centralized repository for organizing, + storing, and serving ML features. The Featurestore is + a top-level container for your features and their + values. + + """ + # Create or coerce a protobuf request object. + # Quick 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, featurestore, featurestore_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 = featurestore_service.CreateFeaturestoreRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if featurestore is not None: + request.featurestore = featurestore + if featurestore_id is not None: + request.featurestore_id = featurestore_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_featurestore, + default_timeout=None, + 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, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + gca_featurestore.Featurestore, + metadata_type=featurestore_service.CreateFeaturestoreOperationMetadata, + ) + + # Done; return the response. + return response + + async def get_featurestore( + self, + request: Union[featurestore_service.GetFeaturestoreRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> featurestore.Featurestore: + r"""Gets details of a single Featurestore. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_get_featurestore(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetFeaturestoreRequest( + name="name_value", + ) + + # Make the request + response = await client.get_featurestore(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetFeaturestoreRequest, dict]): + The request object. Request message for + [FeaturestoreService.GetFeaturestore][google.cloud.aiplatform.v1.FeaturestoreService.GetFeaturestore]. + name (:class:`str`): + Required. The name of the + Featurestore resource. + + 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: + google.cloud.aiplatform_v1.types.Featurestore: + Vertex AI Feature Store provides a + centralized repository for organizing, + storing, and serving ML features. The + Featurestore is a top-level container + for your features and their values. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = featurestore_service.GetFeaturestoreRequest(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_featurestore, + default_timeout=None, + 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 list_featurestores( + self, + request: Union[featurestore_service.ListFeaturestoresRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListFeaturestoresAsyncPager: + r"""Lists Featurestores in a given project and location. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_list_featurestores(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListFeaturestoresRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_featurestores(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListFeaturestoresRequest, dict]): + The request object. Request message for + [FeaturestoreService.ListFeaturestores][google.cloud.aiplatform.v1.FeaturestoreService.ListFeaturestores]. + parent (:class:`str`): + Required. The resource name of the Location to list + Featurestores. Format: + ``projects/{project}/locations/{location}`` + + 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: + google.cloud.aiplatform_v1.services.featurestore_service.pagers.ListFeaturestoresAsyncPager: + Response message for + [FeaturestoreService.ListFeaturestores][google.cloud.aiplatform.v1.FeaturestoreService.ListFeaturestores]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = featurestore_service.ListFeaturestoresRequest(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_featurestores, + default_timeout=None, + 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.ListFeaturestoresAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def update_featurestore( + self, + request: Union[featurestore_service.UpdateFeaturestoreRequest, dict] = None, + *, + featurestore: gca_featurestore.Featurestore = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Updates the parameters of a single Featurestore. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_update_featurestore(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.UpdateFeaturestoreRequest( + ) + + # Make the request + operation = client.update_featurestore(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.UpdateFeaturestoreRequest, dict]): + The request object. Request message for + [FeaturestoreService.UpdateFeaturestore][google.cloud.aiplatform.v1.FeaturestoreService.UpdateFeaturestore]. + featurestore (:class:`google.cloud.aiplatform_v1.types.Featurestore`): + Required. The Featurestore's ``name`` field is used to + identify the Featurestore to be updated. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}`` + + This corresponds to the ``featurestore`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + Field mask is used to specify the fields to be + overwritten in the Featurestore resource by the update. + The fields specified in the update_mask are relative to + the resource, not the full request. A field will be + overwritten if it is in the mask. If the user does not + provide a mask then only the non-empty fields present in + the request will be overwritten. Set the update_mask to + ``*`` to override all fields. + + Updatable fields: + + - ``labels`` + - ``online_serving_config.fixed_node_count`` + - ``online_serving_config.scaling`` + + 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.cloud.aiplatform_v1.types.Featurestore` Vertex AI Feature Store provides a centralized repository for organizing, + storing, and serving ML features. The Featurestore is + a top-level container for your features and their + values. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([featurestore, 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 = featurestore_service.UpdateFeaturestoreRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if featurestore is not None: + request.featurestore = featurestore + 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_featurestore, + default_timeout=None, + 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( + (("featurestore.name", request.featurestore.name),) + ), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + gca_featurestore.Featurestore, + metadata_type=featurestore_service.UpdateFeaturestoreOperationMetadata, + ) + + # Done; return the response. + return response + + async def delete_featurestore( + self, + request: Union[featurestore_service.DeleteFeaturestoreRequest, dict] = None, + *, + name: str = None, + force: bool = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Deletes a single Featurestore. The Featurestore must not contain + any EntityTypes or ``force`` must be set to true for the request + to succeed. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_delete_featurestore(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteFeaturestoreRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_featurestore(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.DeleteFeaturestoreRequest, dict]): + The request object. Request message for + [FeaturestoreService.DeleteFeaturestore][google.cloud.aiplatform.v1.FeaturestoreService.DeleteFeaturestore]. + name (:class:`str`): + Required. The name of the Featurestore to be deleted. + Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + force (:class:`bool`): + If set to true, any EntityTypes and + Features for this Featurestore will also + be deleted. (Otherwise, the request will + only work if the Featurestore has no + EntityTypes.) + + This corresponds to the ``force`` 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # Create or coerce a protobuf request object. + # Quick 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, force]) + 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 = featurestore_service.DeleteFeaturestoreRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + if force is not None: + request.force = force + + # 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_featurestore, + default_timeout=None, + 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, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, + ) + + # Done; return the response. + return response + + async def create_entity_type( + self, + request: Union[featurestore_service.CreateEntityTypeRequest, dict] = None, + *, + parent: str = None, + entity_type: gca_entity_type.EntityType = None, + entity_type_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Creates a new EntityType in a given Featurestore. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_create_entity_type(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateEntityTypeRequest( + parent="parent_value", + entity_type_id="entity_type_id_value", + ) + + # Make the request + operation = client.create_entity_type(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CreateEntityTypeRequest, dict]): + The request object. Request message for + [FeaturestoreService.CreateEntityType][google.cloud.aiplatform.v1.FeaturestoreService.CreateEntityType]. + parent (:class:`str`): + Required. The resource name of the Featurestore to + create EntityTypes. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + entity_type (:class:`google.cloud.aiplatform_v1.types.EntityType`): + The EntityType to create. + This corresponds to the ``entity_type`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + entity_type_id (:class:`str`): + Required. The ID to use for the EntityType, which will + become the final component of the EntityType's resource + name. + + This value may be up to 60 characters, and valid + characters are ``[a-z0-9_]``. The first character cannot + be a number. + + The value must be unique within a featurestore. + + This corresponds to the ``entity_type_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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.cloud.aiplatform_v1.types.EntityType` An entity type is a type of object in a system that needs to be modeled and + have stored information about. For example, driver is + an entity type, and driver0 is an instance of an + entity type driver. + + """ + # Create or coerce a protobuf request object. + # Quick 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, entity_type, entity_type_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 = featurestore_service.CreateEntityTypeRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if entity_type is not None: + request.entity_type = entity_type + if entity_type_id is not None: + request.entity_type_id = entity_type_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_entity_type, + default_timeout=None, + 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, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + gca_entity_type.EntityType, + metadata_type=featurestore_service.CreateEntityTypeOperationMetadata, + ) + + # Done; return the response. + return response + + async def get_entity_type( + self, + request: Union[featurestore_service.GetEntityTypeRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> entity_type.EntityType: + r"""Gets details of a single EntityType. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_get_entity_type(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetEntityTypeRequest( + name="name_value", + ) + + # Make the request + response = await client.get_entity_type(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetEntityTypeRequest, dict]): + The request object. Request message for + [FeaturestoreService.GetEntityType][google.cloud.aiplatform.v1.FeaturestoreService.GetEntityType]. + name (:class:`str`): + Required. The name of the EntityType resource. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}`` + + 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: + google.cloud.aiplatform_v1.types.EntityType: + An entity type is a type of object in + a system that needs to be modeled and + have stored information about. For + example, driver is an entity type, and + driver0 is an instance of an entity type + driver. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = featurestore_service.GetEntityTypeRequest(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_entity_type, + default_timeout=None, + 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 list_entity_types( + self, + request: Union[featurestore_service.ListEntityTypesRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListEntityTypesAsyncPager: + r"""Lists EntityTypes in a given Featurestore. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_list_entity_types(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListEntityTypesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_entity_types(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListEntityTypesRequest, dict]): + The request object. Request message for + [FeaturestoreService.ListEntityTypes][google.cloud.aiplatform.v1.FeaturestoreService.ListEntityTypes]. + parent (:class:`str`): + Required. The resource name of the Featurestore to list + EntityTypes. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}`` + + 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: + google.cloud.aiplatform_v1.services.featurestore_service.pagers.ListEntityTypesAsyncPager: + Response message for + [FeaturestoreService.ListEntityTypes][google.cloud.aiplatform.v1.FeaturestoreService.ListEntityTypes]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = featurestore_service.ListEntityTypesRequest(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_entity_types, + default_timeout=None, + 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.ListEntityTypesAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def update_entity_type( + self, + request: Union[featurestore_service.UpdateEntityTypeRequest, dict] = None, + *, + entity_type: gca_entity_type.EntityType = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_entity_type.EntityType: + r"""Updates the parameters of a single EntityType. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_update_entity_type(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.UpdateEntityTypeRequest( + ) + + # Make the request + response = await client.update_entity_type(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.UpdateEntityTypeRequest, dict]): + The request object. Request message for + [FeaturestoreService.UpdateEntityType][google.cloud.aiplatform.v1.FeaturestoreService.UpdateEntityType]. + entity_type (:class:`google.cloud.aiplatform_v1.types.EntityType`): + Required. The EntityType's ``name`` field is used to + identify the EntityType to be updated. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}`` + + This corresponds to the ``entity_type`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + Field mask is used to specify the fields to be + overwritten in the EntityType resource by the update. + The fields specified in the update_mask are relative to + the resource, not the full request. A field will be + overwritten if it is in the mask. If the user does not + provide a mask then only the non-empty fields present in + the request will be overwritten. Set the update_mask to + ``*`` to override all fields. + + Updatable fields: + + - ``description`` + - ``labels`` + - ``monitoring_config.snapshot_analysis.disabled`` + - ``monitoring_config.snapshot_analysis.monitoring_interval_days`` + - ``monitoring_config.snapshot_analysis.staleness_days`` + - ``monitoring_config.import_features_analysis.state`` + - ``monitoring_config.import_features_analysis.anomaly_detection_baseline`` + - ``monitoring_config.numerical_threshold_config.value`` + - ``monitoring_config.categorical_threshold_config.value`` + + 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: + google.cloud.aiplatform_v1.types.EntityType: + An entity type is a type of object in + a system that needs to be modeled and + have stored information about. For + example, driver is an entity type, and + driver0 is an instance of an entity type + driver. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([entity_type, 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 = featurestore_service.UpdateEntityTypeRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if entity_type is not None: + request.entity_type = entity_type + 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_entity_type, + default_timeout=None, + 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( + (("entity_type.name", request.entity_type.name),) + ), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def delete_entity_type( + self, + request: Union[featurestore_service.DeleteEntityTypeRequest, dict] = None, + *, + name: str = None, + force: bool = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Deletes a single EntityType. The EntityType must not have any + Features or ``force`` must be set to true for the request to + succeed. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_delete_entity_type(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteEntityTypeRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_entity_type(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.DeleteEntityTypeRequest, dict]): + The request object. Request message for + [FeaturestoreService.DeleteEntityTypes][]. + name (:class:`str`): + Required. The name of the EntityType to be deleted. + Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + force (:class:`bool`): + If set to true, any Features for this + EntityType will also be deleted. + (Otherwise, the request will only work + if the EntityType has no Features.) + + This corresponds to the ``force`` 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # Create or coerce a protobuf request object. + # Quick 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, force]) + 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 = featurestore_service.DeleteEntityTypeRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + if force is not None: + request.force = force + + # 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_entity_type, + default_timeout=None, + 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, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, + ) + + # Done; return the response. + return response + + async def create_feature( + self, + request: Union[featurestore_service.CreateFeatureRequest, dict] = None, + *, + parent: str = None, + feature: gca_feature.Feature = None, + feature_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Creates a new Feature in a given EntityType. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_create_feature(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + feature = aiplatform_v1.Feature() + feature.value_type = "BYTES" + + request = aiplatform_v1.CreateFeatureRequest( + parent="parent_value", + feature=feature, + feature_id="feature_id_value", + ) + + # Make the request + operation = client.create_feature(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CreateFeatureRequest, dict]): + The request object. Request message for + [FeaturestoreService.CreateFeature][google.cloud.aiplatform.v1.FeaturestoreService.CreateFeature]. + parent (:class:`str`): + Required. The resource name of the EntityType to create + a Feature. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + feature (:class:`google.cloud.aiplatform_v1.types.Feature`): + Required. The Feature to create. + This corresponds to the ``feature`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + feature_id (:class:`str`): + Required. The ID to use for the Feature, which will + become the final component of the Feature's resource + name. + + This value may be up to 60 characters, and valid + characters are ``[a-z0-9_]``. The first character cannot + be a number. + + The value must be unique within an EntityType. + + This corresponds to the ``feature_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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.cloud.aiplatform_v1.types.Feature` Feature Metadata information that describes an attribute of an entity type. + For example, apple is an entity type, and color is a + feature that describes apple. + + """ + # Create or coerce a protobuf request object. + # Quick 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, feature, feature_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 = featurestore_service.CreateFeatureRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if feature is not None: + request.feature = feature + if feature_id is not None: + request.feature_id = feature_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_feature, + default_timeout=None, + 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, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + gca_feature.Feature, + metadata_type=featurestore_service.CreateFeatureOperationMetadata, + ) + + # Done; return the response. + return response + + async def batch_create_features( + self, + request: Union[featurestore_service.BatchCreateFeaturesRequest, dict] = None, + *, + parent: str = None, + requests: Sequence[featurestore_service.CreateFeatureRequest] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Creates a batch of Features in a given EntityType. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_batch_create_features(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + requests = aiplatform_v1.CreateFeatureRequest() + requests.parent = "parent_value" + requests.feature.value_type = "BYTES" + requests.feature_id = "feature_id_value" + + request = aiplatform_v1.BatchCreateFeaturesRequest( + parent="parent_value", + requests=requests, + ) + + # Make the request + operation = client.batch_create_features(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.BatchCreateFeaturesRequest, dict]): + The request object. Request message for + [FeaturestoreService.BatchCreateFeatures][google.cloud.aiplatform.v1.FeaturestoreService.BatchCreateFeatures]. + parent (:class:`str`): + Required. The resource name of the EntityType to create + the batch of Features under. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + requests (:class:`Sequence[google.cloud.aiplatform_v1.types.CreateFeatureRequest]`): + Required. The request message specifying the Features to + create. All Features must be created under the same + parent EntityType. The ``parent`` field in each child + request message can be omitted. If ``parent`` is set in + a child request, then the value must match the + ``parent`` value in this request message. + + This corresponds to the ``requests`` 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.aiplatform_v1.types.BatchCreateFeaturesResponse` + Response message for + [FeaturestoreService.BatchCreateFeatures][google.cloud.aiplatform.v1.FeaturestoreService.BatchCreateFeatures]. + + """ + # Create or coerce a protobuf request object. + # Quick 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, requests]) + 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 = featurestore_service.BatchCreateFeaturesRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if requests: + request.requests.extend(requests) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.batch_create_features, + default_timeout=None, + 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, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + featurestore_service.BatchCreateFeaturesResponse, + metadata_type=featurestore_service.BatchCreateFeaturesOperationMetadata, + ) + + # Done; return the response. + return response + + async def get_feature( + self, + request: Union[featurestore_service.GetFeatureRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> feature.Feature: + r"""Gets details of a single Feature. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_get_feature(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetFeatureRequest( + name="name_value", + ) + + # Make the request + response = await client.get_feature(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetFeatureRequest, dict]): + The request object. Request message for + [FeaturestoreService.GetFeature][google.cloud.aiplatform.v1.FeaturestoreService.GetFeature]. + name (:class:`str`): + Required. The name of the Feature resource. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}`` + + 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: + google.cloud.aiplatform_v1.types.Feature: + Feature Metadata information that + describes an attribute of an entity + type. For example, apple is an entity + type, and color is a feature that + describes apple. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = featurestore_service.GetFeatureRequest(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_feature, + default_timeout=None, + 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 list_features( + self, + request: Union[featurestore_service.ListFeaturesRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListFeaturesAsyncPager: + r"""Lists Features in a given EntityType. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_list_features(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListFeaturesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_features(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListFeaturesRequest, dict]): + The request object. Request message for + [FeaturestoreService.ListFeatures][google.cloud.aiplatform.v1.FeaturestoreService.ListFeatures]. + parent (:class:`str`): + Required. The resource name of the Location to list + Features. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}`` + + 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: + google.cloud.aiplatform_v1.services.featurestore_service.pagers.ListFeaturesAsyncPager: + Response message for + [FeaturestoreService.ListFeatures][google.cloud.aiplatform.v1.FeaturestoreService.ListFeatures]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = featurestore_service.ListFeaturesRequest(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_features, + default_timeout=None, + 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.ListFeaturesAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def update_feature( + self, + request: Union[featurestore_service.UpdateFeatureRequest, dict] = None, + *, + feature: gca_feature.Feature = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_feature.Feature: + r"""Updates the parameters of a single Feature. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_update_feature(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + feature = aiplatform_v1.Feature() + feature.value_type = "BYTES" + + request = aiplatform_v1.UpdateFeatureRequest( + feature=feature, + ) + + # Make the request + response = await client.update_feature(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.UpdateFeatureRequest, dict]): + The request object. Request message for + [FeaturestoreService.UpdateFeature][google.cloud.aiplatform.v1.FeaturestoreService.UpdateFeature]. + feature (:class:`google.cloud.aiplatform_v1.types.Feature`): + Required. The Feature's ``name`` field is used to + identify the Feature to be updated. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}/features/{feature}`` + + This corresponds to the ``feature`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + Field mask is used to specify the fields to be + overwritten in the Features resource by the update. The + fields specified in the update_mask are relative to the + resource, not the full request. A field will be + overwritten if it is in the mask. If the user does not + provide a mask then only the non-empty fields present in + the request will be overwritten. Set the update_mask to + ``*`` to override all fields. + + Updatable fields: + + - ``description`` + - ``labels`` + - ``disable_monitoring`` + + 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: + google.cloud.aiplatform_v1.types.Feature: + Feature Metadata information that + describes an attribute of an entity + type. For example, apple is an entity + type, and color is a feature that + describes apple. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([feature, 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 = featurestore_service.UpdateFeatureRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if feature is not None: + request.feature = feature + 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_feature, + default_timeout=None, + 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( + (("feature.name", request.feature.name),) + ), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def delete_feature( + self, + request: Union[featurestore_service.DeleteFeatureRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Deletes a single Feature. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_delete_feature(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteFeatureRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_feature(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.DeleteFeatureRequest, dict]): + The request object. Request message for + [FeaturestoreService.DeleteFeature][google.cloud.aiplatform.v1.FeaturestoreService.DeleteFeature]. + name (:class:`str`): + Required. The name of the Features to be deleted. + Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}/features/{feature}`` + + 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = featurestore_service.DeleteFeatureRequest(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_feature, + default_timeout=None, + 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, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, + ) + + # Done; return the response. + return response + + async def import_feature_values( + self, + request: Union[featurestore_service.ImportFeatureValuesRequest, dict] = None, + *, + entity_type: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Imports Feature values into the Featurestore from a + source storage. + The progress of the import is tracked by the returned + operation. The imported features are guaranteed to be + visible to subsequent read operations after the + operation is marked as successfully done. + If an import operation fails, the Feature values + returned from reads and exports may be inconsistent. If + consistency is required, the caller must retry the same + import request again and wait till the new operation + returned is marked as successfully done. + There are also scenarios where the caller can cause + inconsistency. + - Source data for import contains multiple distinct + Feature values for the same entity ID and timestamp. + - Source is modified during an import. This includes + adding, updating, or removing source data and/or + metadata. Examples of updating metadata include but are + not limited to changing storage location, storage class, + or retention policy. + - Online serving cluster is under-provisioned. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_import_feature_values(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + avro_source = aiplatform_v1.AvroSource() + avro_source.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + + feature_specs = aiplatform_v1.FeatureSpec() + feature_specs.id = "id_value" + + request = aiplatform_v1.ImportFeatureValuesRequest( + avro_source=avro_source, + feature_time_field="feature_time_field_value", + entity_type="entity_type_value", + feature_specs=feature_specs, + ) + + # Make the request + operation = client.import_feature_values(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ImportFeatureValuesRequest, dict]): + The request object. Request message for + [FeaturestoreService.ImportFeatureValues][google.cloud.aiplatform.v1.FeaturestoreService.ImportFeatureValues]. + entity_type (:class:`str`): + Required. The resource name of the EntityType grouping + the Features for which values are being imported. + Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entityType}`` + + This corresponds to the ``entity_type`` 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.aiplatform_v1.types.ImportFeatureValuesResponse` + Response message for + [FeaturestoreService.ImportFeatureValues][google.cloud.aiplatform.v1.FeaturestoreService.ImportFeatureValues]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([entity_type]) + 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 = featurestore_service.ImportFeatureValuesRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if entity_type is not None: + request.entity_type = entity_type + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.import_feature_values, + default_timeout=None, + 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( + (("entity_type", request.entity_type),) + ), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + featurestore_service.ImportFeatureValuesResponse, + metadata_type=featurestore_service.ImportFeatureValuesOperationMetadata, + ) + + # Done; return the response. + return response + + async def batch_read_feature_values( + self, + request: Union[featurestore_service.BatchReadFeatureValuesRequest, dict] = None, + *, + featurestore: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Batch reads Feature values from a Featurestore. + This API enables batch reading Feature values, where + each read instance in the batch may read Feature values + of entities from one or more EntityTypes. Point-in-time + correctness is guaranteed for Feature values of each + read instance as of each instance's read timestamp. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_batch_read_feature_values(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + csv_read_instances = aiplatform_v1.CsvSource() + csv_read_instances.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + + destination = aiplatform_v1.FeatureValueDestination() + destination.bigquery_destination.output_uri = "output_uri_value" + + entity_type_specs = aiplatform_v1.EntityTypeSpec() + entity_type_specs.entity_type_id = "entity_type_id_value" + entity_type_specs.feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1.BatchReadFeatureValuesRequest( + csv_read_instances=csv_read_instances, + featurestore="featurestore_value", + destination=destination, + entity_type_specs=entity_type_specs, + ) + + # Make the request + operation = client.batch_read_feature_values(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.BatchReadFeatureValuesRequest, dict]): + The request object. Request message for + [FeaturestoreService.BatchReadFeatureValues][google.cloud.aiplatform.v1.FeaturestoreService.BatchReadFeatureValues]. + featurestore (:class:`str`): + Required. The resource name of the Featurestore from + which to query Feature values. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}`` + + This corresponds to the ``featurestore`` 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.aiplatform_v1.types.BatchReadFeatureValuesResponse` + Response message for + [FeaturestoreService.BatchReadFeatureValues][google.cloud.aiplatform.v1.FeaturestoreService.BatchReadFeatureValues]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([featurestore]) + 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 = featurestore_service.BatchReadFeatureValuesRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if featurestore is not None: + request.featurestore = featurestore + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.batch_read_feature_values, + default_timeout=None, + 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( + (("featurestore", request.featurestore),) + ), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + featurestore_service.BatchReadFeatureValuesResponse, + metadata_type=featurestore_service.BatchReadFeatureValuesOperationMetadata, + ) + + # Done; return the response. + return response + + async def export_feature_values( + self, + request: Union[featurestore_service.ExportFeatureValuesRequest, dict] = None, + *, + entity_type: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Exports Feature values from all the entities of a + target EntityType. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_export_feature_values(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + destination = aiplatform_v1.FeatureValueDestination() + destination.bigquery_destination.output_uri = "output_uri_value" + + feature_selector = aiplatform_v1.FeatureSelector() + feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1.ExportFeatureValuesRequest( + entity_type="entity_type_value", + destination=destination, + feature_selector=feature_selector, + ) + + # Make the request + operation = client.export_feature_values(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ExportFeatureValuesRequest, dict]): + The request object. Request message for + [FeaturestoreService.ExportFeatureValues][google.cloud.aiplatform.v1.FeaturestoreService.ExportFeatureValues]. + entity_type (:class:`str`): + Required. The resource name of the EntityType from which + to export Feature values. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}`` + + This corresponds to the ``entity_type`` 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.aiplatform_v1.types.ExportFeatureValuesResponse` + Response message for + [FeaturestoreService.ExportFeatureValues][google.cloud.aiplatform.v1.FeaturestoreService.ExportFeatureValues]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([entity_type]) + 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 = featurestore_service.ExportFeatureValuesRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if entity_type is not None: + request.entity_type = entity_type + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.export_feature_values, + default_timeout=None, + 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( + (("entity_type", request.entity_type),) + ), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + featurestore_service.ExportFeatureValuesResponse, + metadata_type=featurestore_service.ExportFeatureValuesOperationMetadata, + ) + + # Done; return the response. + return response + + async def search_features( + self, + request: Union[featurestore_service.SearchFeaturesRequest, dict] = None, + *, + location: str = None, + query: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.SearchFeaturesAsyncPager: + r"""Searches Features matching a query in a given + project. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_search_features(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.SearchFeaturesRequest( + location="location_value", + ) + + # Make the request + page_result = client.search_features(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.SearchFeaturesRequest, dict]): + The request object. Request message for + [FeaturestoreService.SearchFeatures][google.cloud.aiplatform.v1.FeaturestoreService.SearchFeatures]. + location (:class:`str`): + Required. The resource name of the Location to search + Features. Format: + ``projects/{project}/locations/{location}`` + + This corresponds to the ``location`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + query (:class:`str`): + Query string that is a conjunction of field-restricted + queries and/or field-restricted filters. + Field-restricted queries and filters can be combined + using ``AND`` to form a conjunction. + + A field query is in the form FIELD:QUERY. This + implicitly checks if QUERY exists as a substring within + Feature's FIELD. The QUERY and the FIELD are converted + to a sequence of words (i.e. tokens) for comparison. + This is done by: + + - Removing leading/trailing whitespace and tokenizing + the search value. Characters that are not one of + alphanumeric ``[a-zA-Z0-9]``, underscore ``_``, or + asterisk ``*`` are treated as delimiters for tokens. + ``*`` is treated as a wildcard that matches + characters within a token. + - Ignoring case. + - Prepending an asterisk to the first and appending an + asterisk to the last token in QUERY. + + A QUERY must be either a singular token or a phrase. A + phrase is one or multiple words enclosed in double + quotation marks ("). With phrases, the order of the + words is important. Words in the phrase must be matching + in order and consecutively. + + Supported FIELDs for field-restricted queries: + + - ``feature_id`` + - ``description`` + - ``entity_type_id`` + + Examples: + + - ``feature_id: foo`` --> Matches a Feature with ID + containing the substring ``foo`` (eg. ``foo``, + ``foofeature``, ``barfoo``). + - ``feature_id: foo*feature`` --> Matches a Feature + with ID containing the substring ``foo*feature`` (eg. + ``foobarfeature``). + - ``feature_id: foo AND description: bar`` --> Matches + a Feature with ID containing the substring ``foo`` + and description containing the substring ``bar``. + + Besides field queries, the following exact-match filters + are supported. The exact-match filters do not support + wildcards. Unlike field-restricted queries, exact-match + filters are case-sensitive. + + - ``feature_id``: Supports = comparisons. + - ``description``: Supports = comparisons. Multi-token + filters should be enclosed in quotes. + - ``entity_type_id``: Supports = comparisons. + - ``value_type``: Supports = and != comparisons. + - ``labels``: Supports key-value equality as well as + key presence. + - ``featurestore_id``: Supports = comparisons. + + Examples: + + - ``description = "foo bar"`` --> Any Feature with + description exactly equal to ``foo bar`` + - ``value_type = DOUBLE`` --> Features whose type is + DOUBLE. + - ``labels.active = yes AND labels.env = prod`` --> + Features having both (active: yes) and (env: prod) + labels. + - ``labels.env: *`` --> Any Feature which has a label + with ``env`` as the key. + + 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: + google.cloud.aiplatform_v1.services.featurestore_service.pagers.SearchFeaturesAsyncPager: + Response message for + [FeaturestoreService.SearchFeatures][google.cloud.aiplatform.v1.FeaturestoreService.SearchFeatures]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([location, 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 = featurestore_service.SearchFeaturesRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if location is not None: + request.location = location + 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_features, + default_timeout=None, + 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((("location", request.location),)), + ) + + # 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.SearchFeaturesAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_operations, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.delete_operation, + default_timeout=None, + 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 cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + 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 wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.wait_operation, + default_timeout=None, + 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 set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_location, + default_timeout=None, + 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 list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_locations, + default_timeout=None, + 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 __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-aiplatform", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ("FeaturestoreServiceAsyncClient",) diff --git a/google/cloud/aiplatform_v1/services/featurestore_service/client.py b/google/cloud/aiplatform_v1/services/featurestore_service/client.py new file mode 100644 index 0000000000..e75b3f4f1e --- /dev/null +++ b/google/cloud/aiplatform_v1/services/featurestore_service/client.py @@ -0,0 +1,3738 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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 os +import re +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union +import pkg_resources + +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.auth import credentials as ga_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 + +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + +from google.api_core import operation as gac_operation # type: ignore +from google.api_core import operation_async # type: ignore +from google.cloud.aiplatform_v1.services.featurestore_service import pagers +from google.cloud.aiplatform_v1.types import encryption_spec +from google.cloud.aiplatform_v1.types import entity_type +from google.cloud.aiplatform_v1.types import entity_type as gca_entity_type +from google.cloud.aiplatform_v1.types import feature +from google.cloud.aiplatform_v1.types import feature as gca_feature +from google.cloud.aiplatform_v1.types import featurestore +from google.cloud.aiplatform_v1.types import featurestore as gca_featurestore +from google.cloud.aiplatform_v1.types import featurestore_monitoring +from google.cloud.aiplatform_v1.types import featurestore_service +from google.cloud.aiplatform_v1.types import operation as gca_operation +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from .transports.base import FeaturestoreServiceTransport, DEFAULT_CLIENT_INFO +from .transports.grpc import FeaturestoreServiceGrpcTransport +from .transports.grpc_asyncio import FeaturestoreServiceGrpcAsyncIOTransport + + +class FeaturestoreServiceClientMeta(type): + """Metaclass for the FeaturestoreService 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[FeaturestoreServiceTransport]] + _transport_registry["grpc"] = FeaturestoreServiceGrpcTransport + _transport_registry["grpc_asyncio"] = FeaturestoreServiceGrpcAsyncIOTransport + + def get_transport_class( + cls, + label: str = None, + ) -> Type[FeaturestoreServiceTransport]: + """Returns 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 FeaturestoreServiceClient(metaclass=FeaturestoreServiceClientMeta): + """The service that handles CRUD and List for resources for + Featurestore. + """ + + @staticmethod + def _get_default_mtls_endpoint(api_endpoint): + """Converts 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 = "aiplatform.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials + info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + FeaturestoreServiceClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + + @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: + FeaturestoreServiceClient: 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) -> FeaturestoreServiceTransport: + """Returns the transport used by the client instance. + + Returns: + FeaturestoreServiceTransport: The transport used by the client + instance. + """ + return self._transport + + @staticmethod + def entity_type_path( + project: str, + location: str, + featurestore: str, + entity_type: str, + ) -> str: + """Returns a fully-qualified entity_type string.""" + return "projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}".format( + project=project, + location=location, + featurestore=featurestore, + entity_type=entity_type, + ) + + @staticmethod + def parse_entity_type_path(path: str) -> Dict[str, str]: + """Parses a entity_type path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/featurestores/(?P.+?)/entityTypes/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def feature_path( + project: str, + location: str, + featurestore: str, + entity_type: str, + feature: str, + ) -> str: + """Returns a fully-qualified feature string.""" + return "projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}/features/{feature}".format( + project=project, + location=location, + featurestore=featurestore, + entity_type=entity_type, + feature=feature, + ) + + @staticmethod + def parse_feature_path(path: str) -> Dict[str, str]: + """Parses a feature path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/featurestores/(?P.+?)/entityTypes/(?P.+?)/features/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def featurestore_path( + project: str, + location: str, + featurestore: str, + ) -> str: + """Returns a fully-qualified featurestore string.""" + return "projects/{project}/locations/{location}/featurestores/{featurestore}".format( + project=project, + location=location, + featurestore=featurestore, + ) + + @staticmethod + def parse_featurestore_path(path: str) -> Dict[str, str]: + """Parses a featurestore path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/featurestores/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def common_billing_account_path( + billing_account: str, + ) -> str: + """Returns 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: + """Returns 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: + """Returns 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: + """Returns 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: + """Returns 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 {} + + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + + def __init__( + self, + *, + credentials: Optional[ga_credentials.Credentials] = None, + transport: Union[str, FeaturestoreServiceTransport, None] = None, + client_options: Optional[client_options_lib.ClientOptions] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the featurestore 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, FeaturestoreServiceTransport]): The + transport to use. If set to None, a transport is chosen + automatically. + client_options (google.api_core.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. + 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() + + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options + ) + + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) + + # 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, FeaturestoreServiceTransport): + # transport is a FeaturestoreServiceTransport instance. + if credentials or client_options.credentials_file or api_key_value: + 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: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + + 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, + client_cert_source_for_mtls=client_cert_source_func, + quota_project_id=client_options.quota_project_id, + client_info=client_info, + always_use_jwt_access=True, + ) + + def create_featurestore( + self, + request: Union[featurestore_service.CreateFeaturestoreRequest, dict] = None, + *, + parent: str = None, + featurestore: gca_featurestore.Featurestore = None, + featurestore_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Creates a new Featurestore in a given project and + location. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_create_featurestore(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateFeaturestoreRequest( + parent="parent_value", + featurestore_id="featurestore_id_value", + ) + + # Make the request + operation = client.create_featurestore(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CreateFeaturestoreRequest, dict]): + The request object. Request message for + [FeaturestoreService.CreateFeaturestore][google.cloud.aiplatform.v1.FeaturestoreService.CreateFeaturestore]. + parent (str): + Required. The resource name of the Location to create + Featurestores. Format: + ``projects/{project}/locations/{location}'`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + featurestore (google.cloud.aiplatform_v1.types.Featurestore): + Required. The Featurestore to create. + This corresponds to the ``featurestore`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + featurestore_id (str): + Required. The ID to use for this Featurestore, which + will become the final component of the Featurestore's + resource name. + + This value may be up to 60 characters, and valid + characters are ``[a-z0-9_]``. The first character cannot + be a number. + + The value must be unique within the project and + location. + + This corresponds to the ``featurestore_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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.cloud.aiplatform_v1.types.Featurestore` Vertex AI Feature Store provides a centralized repository for organizing, + storing, and serving ML features. The Featurestore is + a top-level container for your features and their + values. + + """ + # Create or coerce a protobuf request object. + # Quick 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, featurestore, featurestore_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 featurestore_service.CreateFeaturestoreRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, featurestore_service.CreateFeaturestoreRequest): + request = featurestore_service.CreateFeaturestoreRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if featurestore is not None: + request.featurestore = featurestore + if featurestore_id is not None: + request.featurestore_id = featurestore_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_featurestore] + + # 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, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + gca_featurestore.Featurestore, + metadata_type=featurestore_service.CreateFeaturestoreOperationMetadata, + ) + + # Done; return the response. + return response + + def get_featurestore( + self, + request: Union[featurestore_service.GetFeaturestoreRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> featurestore.Featurestore: + r"""Gets details of a single Featurestore. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_get_featurestore(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetFeaturestoreRequest( + name="name_value", + ) + + # Make the request + response = client.get_featurestore(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetFeaturestoreRequest, dict]): + The request object. Request message for + [FeaturestoreService.GetFeaturestore][google.cloud.aiplatform.v1.FeaturestoreService.GetFeaturestore]. + name (str): + Required. The name of the + Featurestore resource. + + 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: + google.cloud.aiplatform_v1.types.Featurestore: + Vertex AI Feature Store provides a + centralized repository for organizing, + storing, and serving ML features. The + Featurestore is a top-level container + for your features and their values. + + """ + # Create or coerce a protobuf request object. + # Quick 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 featurestore_service.GetFeaturestoreRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, featurestore_service.GetFeaturestoreRequest): + request = featurestore_service.GetFeaturestoreRequest(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_featurestore] + + # 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 list_featurestores( + self, + request: Union[featurestore_service.ListFeaturestoresRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListFeaturestoresPager: + r"""Lists Featurestores in a given project and location. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_list_featurestores(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListFeaturestoresRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_featurestores(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListFeaturestoresRequest, dict]): + The request object. Request message for + [FeaturestoreService.ListFeaturestores][google.cloud.aiplatform.v1.FeaturestoreService.ListFeaturestores]. + parent (str): + Required. The resource name of the Location to list + Featurestores. Format: + ``projects/{project}/locations/{location}`` + + 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: + google.cloud.aiplatform_v1.services.featurestore_service.pagers.ListFeaturestoresPager: + Response message for + [FeaturestoreService.ListFeaturestores][google.cloud.aiplatform.v1.FeaturestoreService.ListFeaturestores]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 featurestore_service.ListFeaturestoresRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, featurestore_service.ListFeaturestoresRequest): + request = featurestore_service.ListFeaturestoresRequest(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_featurestores] + + # 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.ListFeaturestoresPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def update_featurestore( + self, + request: Union[featurestore_service.UpdateFeaturestoreRequest, dict] = None, + *, + featurestore: gca_featurestore.Featurestore = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Updates the parameters of a single Featurestore. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_update_featurestore(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.UpdateFeaturestoreRequest( + ) + + # Make the request + operation = client.update_featurestore(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.UpdateFeaturestoreRequest, dict]): + The request object. Request message for + [FeaturestoreService.UpdateFeaturestore][google.cloud.aiplatform.v1.FeaturestoreService.UpdateFeaturestore]. + featurestore (google.cloud.aiplatform_v1.types.Featurestore): + Required. The Featurestore's ``name`` field is used to + identify the Featurestore to be updated. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}`` + + This corresponds to the ``featurestore`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Field mask is used to specify the fields to be + overwritten in the Featurestore resource by the update. + The fields specified in the update_mask are relative to + the resource, not the full request. A field will be + overwritten if it is in the mask. If the user does not + provide a mask then only the non-empty fields present in + the request will be overwritten. Set the update_mask to + ``*`` to override all fields. + + Updatable fields: + + - ``labels`` + - ``online_serving_config.fixed_node_count`` + - ``online_serving_config.scaling`` + + 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.cloud.aiplatform_v1.types.Featurestore` Vertex AI Feature Store provides a centralized repository for organizing, + storing, and serving ML features. The Featurestore is + a top-level container for your features and their + values. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([featurestore, 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 featurestore_service.UpdateFeaturestoreRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, featurestore_service.UpdateFeaturestoreRequest): + request = featurestore_service.UpdateFeaturestoreRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if featurestore is not None: + request.featurestore = featurestore + 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_featurestore] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("featurestore.name", request.featurestore.name),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + gca_featurestore.Featurestore, + metadata_type=featurestore_service.UpdateFeaturestoreOperationMetadata, + ) + + # Done; return the response. + return response + + def delete_featurestore( + self, + request: Union[featurestore_service.DeleteFeaturestoreRequest, dict] = None, + *, + name: str = None, + force: bool = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Deletes a single Featurestore. The Featurestore must not contain + any EntityTypes or ``force`` must be set to true for the request + to succeed. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_delete_featurestore(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteFeaturestoreRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_featurestore(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.DeleteFeaturestoreRequest, dict]): + The request object. Request message for + [FeaturestoreService.DeleteFeaturestore][google.cloud.aiplatform.v1.FeaturestoreService.DeleteFeaturestore]. + name (str): + Required. The name of the Featurestore to be deleted. + Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + force (bool): + If set to true, any EntityTypes and + Features for this Featurestore will also + be deleted. (Otherwise, the request will + only work if the Featurestore has no + EntityTypes.) + + This corresponds to the ``force`` 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # Create or coerce a protobuf request object. + # Quick 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, force]) + 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 featurestore_service.DeleteFeaturestoreRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, featurestore_service.DeleteFeaturestoreRequest): + request = featurestore_service.DeleteFeaturestoreRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + if force is not None: + request.force = force + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.delete_featurestore] + + # 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, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, + ) + + # Done; return the response. + return response + + def create_entity_type( + self, + request: Union[featurestore_service.CreateEntityTypeRequest, dict] = None, + *, + parent: str = None, + entity_type: gca_entity_type.EntityType = None, + entity_type_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Creates a new EntityType in a given Featurestore. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_create_entity_type(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateEntityTypeRequest( + parent="parent_value", + entity_type_id="entity_type_id_value", + ) + + # Make the request + operation = client.create_entity_type(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CreateEntityTypeRequest, dict]): + The request object. Request message for + [FeaturestoreService.CreateEntityType][google.cloud.aiplatform.v1.FeaturestoreService.CreateEntityType]. + parent (str): + Required. The resource name of the Featurestore to + create EntityTypes. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + entity_type (google.cloud.aiplatform_v1.types.EntityType): + The EntityType to create. + This corresponds to the ``entity_type`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + entity_type_id (str): + Required. The ID to use for the EntityType, which will + become the final component of the EntityType's resource + name. + + This value may be up to 60 characters, and valid + characters are ``[a-z0-9_]``. The first character cannot + be a number. + + The value must be unique within a featurestore. + + This corresponds to the ``entity_type_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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.cloud.aiplatform_v1.types.EntityType` An entity type is a type of object in a system that needs to be modeled and + have stored information about. For example, driver is + an entity type, and driver0 is an instance of an + entity type driver. + + """ + # Create or coerce a protobuf request object. + # Quick 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, entity_type, entity_type_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 featurestore_service.CreateEntityTypeRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, featurestore_service.CreateEntityTypeRequest): + request = featurestore_service.CreateEntityTypeRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if entity_type is not None: + request.entity_type = entity_type + if entity_type_id is not None: + request.entity_type_id = entity_type_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_entity_type] + + # 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, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + gca_entity_type.EntityType, + metadata_type=featurestore_service.CreateEntityTypeOperationMetadata, + ) + + # Done; return the response. + return response + + def get_entity_type( + self, + request: Union[featurestore_service.GetEntityTypeRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> entity_type.EntityType: + r"""Gets details of a single EntityType. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_get_entity_type(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetEntityTypeRequest( + name="name_value", + ) + + # Make the request + response = client.get_entity_type(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetEntityTypeRequest, dict]): + The request object. Request message for + [FeaturestoreService.GetEntityType][google.cloud.aiplatform.v1.FeaturestoreService.GetEntityType]. + name (str): + Required. The name of the EntityType resource. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}`` + + 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: + google.cloud.aiplatform_v1.types.EntityType: + An entity type is a type of object in + a system that needs to be modeled and + have stored information about. For + example, driver is an entity type, and + driver0 is an instance of an entity type + driver. + + """ + # Create or coerce a protobuf request object. + # Quick 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 featurestore_service.GetEntityTypeRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, featurestore_service.GetEntityTypeRequest): + request = featurestore_service.GetEntityTypeRequest(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_entity_type] + + # 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 list_entity_types( + self, + request: Union[featurestore_service.ListEntityTypesRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListEntityTypesPager: + r"""Lists EntityTypes in a given Featurestore. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_list_entity_types(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListEntityTypesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_entity_types(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListEntityTypesRequest, dict]): + The request object. Request message for + [FeaturestoreService.ListEntityTypes][google.cloud.aiplatform.v1.FeaturestoreService.ListEntityTypes]. + parent (str): + Required. The resource name of the Featurestore to list + EntityTypes. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}`` + + 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: + google.cloud.aiplatform_v1.services.featurestore_service.pagers.ListEntityTypesPager: + Response message for + [FeaturestoreService.ListEntityTypes][google.cloud.aiplatform.v1.FeaturestoreService.ListEntityTypes]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 featurestore_service.ListEntityTypesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, featurestore_service.ListEntityTypesRequest): + request = featurestore_service.ListEntityTypesRequest(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_entity_types] + + # 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.ListEntityTypesPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def update_entity_type( + self, + request: Union[featurestore_service.UpdateEntityTypeRequest, dict] = None, + *, + entity_type: gca_entity_type.EntityType = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_entity_type.EntityType: + r"""Updates the parameters of a single EntityType. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_update_entity_type(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.UpdateEntityTypeRequest( + ) + + # Make the request + response = client.update_entity_type(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.UpdateEntityTypeRequest, dict]): + The request object. Request message for + [FeaturestoreService.UpdateEntityType][google.cloud.aiplatform.v1.FeaturestoreService.UpdateEntityType]. + entity_type (google.cloud.aiplatform_v1.types.EntityType): + Required. The EntityType's ``name`` field is used to + identify the EntityType to be updated. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}`` + + This corresponds to the ``entity_type`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Field mask is used to specify the fields to be + overwritten in the EntityType resource by the update. + The fields specified in the update_mask are relative to + the resource, not the full request. A field will be + overwritten if it is in the mask. If the user does not + provide a mask then only the non-empty fields present in + the request will be overwritten. Set the update_mask to + ``*`` to override all fields. + + Updatable fields: + + - ``description`` + - ``labels`` + - ``monitoring_config.snapshot_analysis.disabled`` + - ``monitoring_config.snapshot_analysis.monitoring_interval_days`` + - ``monitoring_config.snapshot_analysis.staleness_days`` + - ``monitoring_config.import_features_analysis.state`` + - ``monitoring_config.import_features_analysis.anomaly_detection_baseline`` + - ``monitoring_config.numerical_threshold_config.value`` + - ``monitoring_config.categorical_threshold_config.value`` + + 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: + google.cloud.aiplatform_v1.types.EntityType: + An entity type is a type of object in + a system that needs to be modeled and + have stored information about. For + example, driver is an entity type, and + driver0 is an instance of an entity type + driver. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([entity_type, 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 featurestore_service.UpdateEntityTypeRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, featurestore_service.UpdateEntityTypeRequest): + request = featurestore_service.UpdateEntityTypeRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if entity_type is not None: + request.entity_type = entity_type + 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_entity_type] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("entity_type.name", request.entity_type.name),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_entity_type( + self, + request: Union[featurestore_service.DeleteEntityTypeRequest, dict] = None, + *, + name: str = None, + force: bool = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Deletes a single EntityType. The EntityType must not have any + Features or ``force`` must be set to true for the request to + succeed. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_delete_entity_type(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteEntityTypeRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_entity_type(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.DeleteEntityTypeRequest, dict]): + The request object. Request message for + [FeaturestoreService.DeleteEntityTypes][]. + name (str): + Required. The name of the EntityType to be deleted. + Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + force (bool): + If set to true, any Features for this + EntityType will also be deleted. + (Otherwise, the request will only work + if the EntityType has no Features.) + + This corresponds to the ``force`` 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # Create or coerce a protobuf request object. + # Quick 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, force]) + 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 featurestore_service.DeleteEntityTypeRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, featurestore_service.DeleteEntityTypeRequest): + request = featurestore_service.DeleteEntityTypeRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + if force is not None: + request.force = force + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.delete_entity_type] + + # 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, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, + ) + + # Done; return the response. + return response + + def create_feature( + self, + request: Union[featurestore_service.CreateFeatureRequest, dict] = None, + *, + parent: str = None, + feature: gca_feature.Feature = None, + feature_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Creates a new Feature in a given EntityType. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_create_feature(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + feature = aiplatform_v1.Feature() + feature.value_type = "BYTES" + + request = aiplatform_v1.CreateFeatureRequest( + parent="parent_value", + feature=feature, + feature_id="feature_id_value", + ) + + # Make the request + operation = client.create_feature(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CreateFeatureRequest, dict]): + The request object. Request message for + [FeaturestoreService.CreateFeature][google.cloud.aiplatform.v1.FeaturestoreService.CreateFeature]. + parent (str): + Required. The resource name of the EntityType to create + a Feature. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + feature (google.cloud.aiplatform_v1.types.Feature): + Required. The Feature to create. + This corresponds to the ``feature`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + feature_id (str): + Required. The ID to use for the Feature, which will + become the final component of the Feature's resource + name. + + This value may be up to 60 characters, and valid + characters are ``[a-z0-9_]``. The first character cannot + be a number. + + The value must be unique within an EntityType. + + This corresponds to the ``feature_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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.cloud.aiplatform_v1.types.Feature` Feature Metadata information that describes an attribute of an entity type. + For example, apple is an entity type, and color is a + feature that describes apple. + + """ + # Create or coerce a protobuf request object. + # Quick 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, feature, feature_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 featurestore_service.CreateFeatureRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, featurestore_service.CreateFeatureRequest): + request = featurestore_service.CreateFeatureRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if feature is not None: + request.feature = feature + if feature_id is not None: + request.feature_id = feature_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_feature] + + # 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, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + gca_feature.Feature, + metadata_type=featurestore_service.CreateFeatureOperationMetadata, + ) + + # Done; return the response. + return response + + def batch_create_features( + self, + request: Union[featurestore_service.BatchCreateFeaturesRequest, dict] = None, + *, + parent: str = None, + requests: Sequence[featurestore_service.CreateFeatureRequest] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Creates a batch of Features in a given EntityType. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_batch_create_features(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + requests = aiplatform_v1.CreateFeatureRequest() + requests.parent = "parent_value" + requests.feature.value_type = "BYTES" + requests.feature_id = "feature_id_value" + + request = aiplatform_v1.BatchCreateFeaturesRequest( + parent="parent_value", + requests=requests, + ) + + # Make the request + operation = client.batch_create_features(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.BatchCreateFeaturesRequest, dict]): + The request object. Request message for + [FeaturestoreService.BatchCreateFeatures][google.cloud.aiplatform.v1.FeaturestoreService.BatchCreateFeatures]. + parent (str): + Required. The resource name of the EntityType to create + the batch of Features under. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + requests (Sequence[google.cloud.aiplatform_v1.types.CreateFeatureRequest]): + Required. The request message specifying the Features to + create. All Features must be created under the same + parent EntityType. The ``parent`` field in each child + request message can be omitted. If ``parent`` is set in + a child request, then the value must match the + ``parent`` value in this request message. + + This corresponds to the ``requests`` 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.aiplatform_v1.types.BatchCreateFeaturesResponse` + Response message for + [FeaturestoreService.BatchCreateFeatures][google.cloud.aiplatform.v1.FeaturestoreService.BatchCreateFeatures]. + + """ + # Create or coerce a protobuf request object. + # Quick 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, requests]) + 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 featurestore_service.BatchCreateFeaturesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, featurestore_service.BatchCreateFeaturesRequest): + request = featurestore_service.BatchCreateFeaturesRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if requests is not None: + request.requests = requests + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.batch_create_features] + + # 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, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + featurestore_service.BatchCreateFeaturesResponse, + metadata_type=featurestore_service.BatchCreateFeaturesOperationMetadata, + ) + + # Done; return the response. + return response + + def get_feature( + self, + request: Union[featurestore_service.GetFeatureRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> feature.Feature: + r"""Gets details of a single Feature. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_get_feature(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetFeatureRequest( + name="name_value", + ) + + # Make the request + response = client.get_feature(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetFeatureRequest, dict]): + The request object. Request message for + [FeaturestoreService.GetFeature][google.cloud.aiplatform.v1.FeaturestoreService.GetFeature]. + name (str): + Required. The name of the Feature resource. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}`` + + 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: + google.cloud.aiplatform_v1.types.Feature: + Feature Metadata information that + describes an attribute of an entity + type. For example, apple is an entity + type, and color is a feature that + describes apple. + + """ + # Create or coerce a protobuf request object. + # Quick 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 featurestore_service.GetFeatureRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, featurestore_service.GetFeatureRequest): + request = featurestore_service.GetFeatureRequest(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_feature] + + # 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 list_features( + self, + request: Union[featurestore_service.ListFeaturesRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListFeaturesPager: + r"""Lists Features in a given EntityType. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_list_features(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListFeaturesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_features(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListFeaturesRequest, dict]): + The request object. Request message for + [FeaturestoreService.ListFeatures][google.cloud.aiplatform.v1.FeaturestoreService.ListFeatures]. + parent (str): + Required. The resource name of the Location to list + Features. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}`` + + 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: + google.cloud.aiplatform_v1.services.featurestore_service.pagers.ListFeaturesPager: + Response message for + [FeaturestoreService.ListFeatures][google.cloud.aiplatform.v1.FeaturestoreService.ListFeatures]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 featurestore_service.ListFeaturesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, featurestore_service.ListFeaturesRequest): + request = featurestore_service.ListFeaturesRequest(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_features] + + # 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.ListFeaturesPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def update_feature( + self, + request: Union[featurestore_service.UpdateFeatureRequest, dict] = None, + *, + feature: gca_feature.Feature = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_feature.Feature: + r"""Updates the parameters of a single Feature. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_update_feature(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + feature = aiplatform_v1.Feature() + feature.value_type = "BYTES" + + request = aiplatform_v1.UpdateFeatureRequest( + feature=feature, + ) + + # Make the request + response = client.update_feature(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.UpdateFeatureRequest, dict]): + The request object. Request message for + [FeaturestoreService.UpdateFeature][google.cloud.aiplatform.v1.FeaturestoreService.UpdateFeature]. + feature (google.cloud.aiplatform_v1.types.Feature): + Required. The Feature's ``name`` field is used to + identify the Feature to be updated. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}/features/{feature}`` + + This corresponds to the ``feature`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Field mask is used to specify the fields to be + overwritten in the Features resource by the update. The + fields specified in the update_mask are relative to the + resource, not the full request. A field will be + overwritten if it is in the mask. If the user does not + provide a mask then only the non-empty fields present in + the request will be overwritten. Set the update_mask to + ``*`` to override all fields. + + Updatable fields: + + - ``description`` + - ``labels`` + - ``disable_monitoring`` + + 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: + google.cloud.aiplatform_v1.types.Feature: + Feature Metadata information that + describes an attribute of an entity + type. For example, apple is an entity + type, and color is a feature that + describes apple. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([feature, 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 featurestore_service.UpdateFeatureRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, featurestore_service.UpdateFeatureRequest): + request = featurestore_service.UpdateFeatureRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if feature is not None: + request.feature = feature + 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_feature] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("feature.name", request.feature.name),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_feature( + self, + request: Union[featurestore_service.DeleteFeatureRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Deletes a single Feature. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_delete_feature(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteFeatureRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_feature(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.DeleteFeatureRequest, dict]): + The request object. Request message for + [FeaturestoreService.DeleteFeature][google.cloud.aiplatform.v1.FeaturestoreService.DeleteFeature]. + name (str): + Required. The name of the Features to be deleted. + Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}/features/{feature}`` + + 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # Create or coerce a protobuf request object. + # Quick 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 featurestore_service.DeleteFeatureRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, featurestore_service.DeleteFeatureRequest): + request = featurestore_service.DeleteFeatureRequest(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_feature] + + # 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, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, + ) + + # Done; return the response. + return response + + def import_feature_values( + self, + request: Union[featurestore_service.ImportFeatureValuesRequest, dict] = None, + *, + entity_type: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Imports Feature values into the Featurestore from a + source storage. + The progress of the import is tracked by the returned + operation. The imported features are guaranteed to be + visible to subsequent read operations after the + operation is marked as successfully done. + If an import operation fails, the Feature values + returned from reads and exports may be inconsistent. If + consistency is required, the caller must retry the same + import request again and wait till the new operation + returned is marked as successfully done. + There are also scenarios where the caller can cause + inconsistency. + - Source data for import contains multiple distinct + Feature values for the same entity ID and timestamp. + - Source is modified during an import. This includes + adding, updating, or removing source data and/or + metadata. Examples of updating metadata include but are + not limited to changing storage location, storage class, + or retention policy. + - Online serving cluster is under-provisioned. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_import_feature_values(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + avro_source = aiplatform_v1.AvroSource() + avro_source.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + + feature_specs = aiplatform_v1.FeatureSpec() + feature_specs.id = "id_value" + + request = aiplatform_v1.ImportFeatureValuesRequest( + avro_source=avro_source, + feature_time_field="feature_time_field_value", + entity_type="entity_type_value", + feature_specs=feature_specs, + ) + + # Make the request + operation = client.import_feature_values(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ImportFeatureValuesRequest, dict]): + The request object. Request message for + [FeaturestoreService.ImportFeatureValues][google.cloud.aiplatform.v1.FeaturestoreService.ImportFeatureValues]. + entity_type (str): + Required. The resource name of the EntityType grouping + the Features for which values are being imported. + Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entityType}`` + + This corresponds to the ``entity_type`` 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.aiplatform_v1.types.ImportFeatureValuesResponse` + Response message for + [FeaturestoreService.ImportFeatureValues][google.cloud.aiplatform.v1.FeaturestoreService.ImportFeatureValues]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([entity_type]) + 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 featurestore_service.ImportFeatureValuesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, featurestore_service.ImportFeatureValuesRequest): + request = featurestore_service.ImportFeatureValuesRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if entity_type is not None: + request.entity_type = entity_type + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.import_feature_values] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("entity_type", request.entity_type),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + featurestore_service.ImportFeatureValuesResponse, + metadata_type=featurestore_service.ImportFeatureValuesOperationMetadata, + ) + + # Done; return the response. + return response + + def batch_read_feature_values( + self, + request: Union[featurestore_service.BatchReadFeatureValuesRequest, dict] = None, + *, + featurestore: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Batch reads Feature values from a Featurestore. + This API enables batch reading Feature values, where + each read instance in the batch may read Feature values + of entities from one or more EntityTypes. Point-in-time + correctness is guaranteed for Feature values of each + read instance as of each instance's read timestamp. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_batch_read_feature_values(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + csv_read_instances = aiplatform_v1.CsvSource() + csv_read_instances.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + + destination = aiplatform_v1.FeatureValueDestination() + destination.bigquery_destination.output_uri = "output_uri_value" + + entity_type_specs = aiplatform_v1.EntityTypeSpec() + entity_type_specs.entity_type_id = "entity_type_id_value" + entity_type_specs.feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1.BatchReadFeatureValuesRequest( + csv_read_instances=csv_read_instances, + featurestore="featurestore_value", + destination=destination, + entity_type_specs=entity_type_specs, + ) + + # Make the request + operation = client.batch_read_feature_values(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.BatchReadFeatureValuesRequest, dict]): + The request object. Request message for + [FeaturestoreService.BatchReadFeatureValues][google.cloud.aiplatform.v1.FeaturestoreService.BatchReadFeatureValues]. + featurestore (str): + Required. The resource name of the Featurestore from + which to query Feature values. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}`` + + This corresponds to the ``featurestore`` 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.aiplatform_v1.types.BatchReadFeatureValuesResponse` + Response message for + [FeaturestoreService.BatchReadFeatureValues][google.cloud.aiplatform.v1.FeaturestoreService.BatchReadFeatureValues]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([featurestore]) + 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 featurestore_service.BatchReadFeatureValuesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, featurestore_service.BatchReadFeatureValuesRequest): + request = featurestore_service.BatchReadFeatureValuesRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if featurestore is not None: + request.featurestore = featurestore + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.batch_read_feature_values + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("featurestore", request.featurestore),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + featurestore_service.BatchReadFeatureValuesResponse, + metadata_type=featurestore_service.BatchReadFeatureValuesOperationMetadata, + ) + + # Done; return the response. + return response + + def export_feature_values( + self, + request: Union[featurestore_service.ExportFeatureValuesRequest, dict] = None, + *, + entity_type: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Exports Feature values from all the entities of a + target EntityType. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_export_feature_values(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + destination = aiplatform_v1.FeatureValueDestination() + destination.bigquery_destination.output_uri = "output_uri_value" + + feature_selector = aiplatform_v1.FeatureSelector() + feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1.ExportFeatureValuesRequest( + entity_type="entity_type_value", + destination=destination, + feature_selector=feature_selector, + ) + + # Make the request + operation = client.export_feature_values(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ExportFeatureValuesRequest, dict]): + The request object. Request message for + [FeaturestoreService.ExportFeatureValues][google.cloud.aiplatform.v1.FeaturestoreService.ExportFeatureValues]. + entity_type (str): + Required. The resource name of the EntityType from which + to export Feature values. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}`` + + This corresponds to the ``entity_type`` 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.aiplatform_v1.types.ExportFeatureValuesResponse` + Response message for + [FeaturestoreService.ExportFeatureValues][google.cloud.aiplatform.v1.FeaturestoreService.ExportFeatureValues]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([entity_type]) + 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 featurestore_service.ExportFeatureValuesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, featurestore_service.ExportFeatureValuesRequest): + request = featurestore_service.ExportFeatureValuesRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if entity_type is not None: + request.entity_type = entity_type + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.export_feature_values] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("entity_type", request.entity_type),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + featurestore_service.ExportFeatureValuesResponse, + metadata_type=featurestore_service.ExportFeatureValuesOperationMetadata, + ) + + # Done; return the response. + return response + + def search_features( + self, + request: Union[featurestore_service.SearchFeaturesRequest, dict] = None, + *, + location: str = None, + query: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.SearchFeaturesPager: + r"""Searches Features matching a query in a given + project. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_search_features(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.SearchFeaturesRequest( + location="location_value", + ) + + # Make the request + page_result = client.search_features(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.SearchFeaturesRequest, dict]): + The request object. Request message for + [FeaturestoreService.SearchFeatures][google.cloud.aiplatform.v1.FeaturestoreService.SearchFeatures]. + location (str): + Required. The resource name of the Location to search + Features. Format: + ``projects/{project}/locations/{location}`` + + This corresponds to the ``location`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + query (str): + Query string that is a conjunction of field-restricted + queries and/or field-restricted filters. + Field-restricted queries and filters can be combined + using ``AND`` to form a conjunction. + + A field query is in the form FIELD:QUERY. This + implicitly checks if QUERY exists as a substring within + Feature's FIELD. The QUERY and the FIELD are converted + to a sequence of words (i.e. tokens) for comparison. + This is done by: + + - Removing leading/trailing whitespace and tokenizing + the search value. Characters that are not one of + alphanumeric ``[a-zA-Z0-9]``, underscore ``_``, or + asterisk ``*`` are treated as delimiters for tokens. + ``*`` is treated as a wildcard that matches + characters within a token. + - Ignoring case. + - Prepending an asterisk to the first and appending an + asterisk to the last token in QUERY. + + A QUERY must be either a singular token or a phrase. A + phrase is one or multiple words enclosed in double + quotation marks ("). With phrases, the order of the + words is important. Words in the phrase must be matching + in order and consecutively. + + Supported FIELDs for field-restricted queries: + + - ``feature_id`` + - ``description`` + - ``entity_type_id`` + + Examples: + + - ``feature_id: foo`` --> Matches a Feature with ID + containing the substring ``foo`` (eg. ``foo``, + ``foofeature``, ``barfoo``). + - ``feature_id: foo*feature`` --> Matches a Feature + with ID containing the substring ``foo*feature`` (eg. + ``foobarfeature``). + - ``feature_id: foo AND description: bar`` --> Matches + a Feature with ID containing the substring ``foo`` + and description containing the substring ``bar``. + + Besides field queries, the following exact-match filters + are supported. The exact-match filters do not support + wildcards. Unlike field-restricted queries, exact-match + filters are case-sensitive. + + - ``feature_id``: Supports = comparisons. + - ``description``: Supports = comparisons. Multi-token + filters should be enclosed in quotes. + - ``entity_type_id``: Supports = comparisons. + - ``value_type``: Supports = and != comparisons. + - ``labels``: Supports key-value equality as well as + key presence. + - ``featurestore_id``: Supports = comparisons. + + Examples: + + - ``description = "foo bar"`` --> Any Feature with + description exactly equal to ``foo bar`` + - ``value_type = DOUBLE`` --> Features whose type is + DOUBLE. + - ``labels.active = yes AND labels.env = prod`` --> + Features having both (active: yes) and (env: prod) + labels. + - ``labels.env: *`` --> Any Feature which has a label + with ``env`` as the key. + + 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: + google.cloud.aiplatform_v1.services.featurestore_service.pagers.SearchFeaturesPager: + Response message for + [FeaturestoreService.SearchFeatures][google.cloud.aiplatform.v1.FeaturestoreService.SearchFeatures]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([location, 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 featurestore_service.SearchFeaturesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, featurestore_service.SearchFeaturesRequest): + request = featurestore_service.SearchFeaturesRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if location is not None: + request.location = location + 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_features] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("location", request.location),)), + ) + + # 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.SearchFeaturesPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_operations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.delete_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.wait_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_location, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_locations, + default_timeout=None, + 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 = 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-aiplatform", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ("FeaturestoreServiceClient",) diff --git a/google/cloud/aiplatform_v1/services/featurestore_service/pagers.py b/google/cloud/aiplatform_v1/services/featurestore_service/pagers.py new file mode 100644 index 0000000000..304d244edf --- /dev/null +++ b/google/cloud/aiplatform_v1/services/featurestore_service/pagers.py @@ -0,0 +1,548 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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 typing import ( + Any, + AsyncIterator, + Awaitable, + Callable, + Sequence, + Tuple, + Optional, + Iterator, +) + +from google.cloud.aiplatform_v1.types import entity_type +from google.cloud.aiplatform_v1.types import feature +from google.cloud.aiplatform_v1.types import featurestore +from google.cloud.aiplatform_v1.types import featurestore_service + + +class ListFeaturestoresPager: + """A pager for iterating through ``list_featurestores`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListFeaturestoresResponse` object, and + provides an ``__iter__`` method to iterate through its + ``featurestores`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListFeaturestores`` requests and continue to iterate + through the ``featurestores`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListFeaturestoresResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., featurestore_service.ListFeaturestoresResponse], + request: featurestore_service.ListFeaturestoresRequest, + response: featurestore_service.ListFeaturestoresResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListFeaturestoresRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListFeaturestoresResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = featurestore_service.ListFeaturestoresRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[featurestore_service.ListFeaturestoresResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterator[featurestore.Featurestore]: + for page in self.pages: + yield from page.featurestores + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListFeaturestoresAsyncPager: + """A pager for iterating through ``list_featurestores`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListFeaturestoresResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``featurestores`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListFeaturestores`` requests and continue to iterate + through the ``featurestores`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListFeaturestoresResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[ + ..., Awaitable[featurestore_service.ListFeaturestoresResponse] + ], + request: featurestore_service.ListFeaturestoresRequest, + response: featurestore_service.ListFeaturestoresResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListFeaturestoresRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListFeaturestoresResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = featurestore_service.ListFeaturestoresRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages( + self, + ) -> AsyncIterator[featurestore_service.ListFeaturestoresResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + + def __aiter__(self) -> AsyncIterator[featurestore.Featurestore]: + async def async_generator(): + async for page in self.pages: + for response in page.featurestores: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListEntityTypesPager: + """A pager for iterating through ``list_entity_types`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListEntityTypesResponse` object, and + provides an ``__iter__`` method to iterate through its + ``entity_types`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListEntityTypes`` requests and continue to iterate + through the ``entity_types`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListEntityTypesResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., featurestore_service.ListEntityTypesResponse], + request: featurestore_service.ListEntityTypesRequest, + response: featurestore_service.ListEntityTypesResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListEntityTypesRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListEntityTypesResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = featurestore_service.ListEntityTypesRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[featurestore_service.ListEntityTypesResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterator[entity_type.EntityType]: + for page in self.pages: + yield from page.entity_types + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListEntityTypesAsyncPager: + """A pager for iterating through ``list_entity_types`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListEntityTypesResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``entity_types`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListEntityTypes`` requests and continue to iterate + through the ``entity_types`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListEntityTypesResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., Awaitable[featurestore_service.ListEntityTypesResponse]], + request: featurestore_service.ListEntityTypesRequest, + response: featurestore_service.ListEntityTypesResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListEntityTypesRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListEntityTypesResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = featurestore_service.ListEntityTypesRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages( + self, + ) -> AsyncIterator[featurestore_service.ListEntityTypesResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + + def __aiter__(self) -> AsyncIterator[entity_type.EntityType]: + async def async_generator(): + async for page in self.pages: + for response in page.entity_types: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListFeaturesPager: + """A pager for iterating through ``list_features`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListFeaturesResponse` object, and + provides an ``__iter__`` method to iterate through its + ``features`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListFeatures`` requests and continue to iterate + through the ``features`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListFeaturesResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., featurestore_service.ListFeaturesResponse], + request: featurestore_service.ListFeaturesRequest, + response: featurestore_service.ListFeaturesResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListFeaturesRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListFeaturesResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = featurestore_service.ListFeaturesRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[featurestore_service.ListFeaturesResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterator[feature.Feature]: + for page in self.pages: + yield from page.features + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListFeaturesAsyncPager: + """A pager for iterating through ``list_features`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListFeaturesResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``features`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListFeatures`` requests and continue to iterate + through the ``features`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListFeaturesResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., Awaitable[featurestore_service.ListFeaturesResponse]], + request: featurestore_service.ListFeaturesRequest, + response: featurestore_service.ListFeaturesResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListFeaturesRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListFeaturesResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = featurestore_service.ListFeaturesRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[featurestore_service.ListFeaturesResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + + def __aiter__(self) -> AsyncIterator[feature.Feature]: + async def async_generator(): + async for page in self.pages: + for response in page.features: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class SearchFeaturesPager: + """A pager for iterating through ``search_features`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.SearchFeaturesResponse` object, and + provides an ``__iter__`` method to iterate through its + ``features`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``SearchFeatures`` requests and continue to iterate + through the ``features`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.SearchFeaturesResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., featurestore_service.SearchFeaturesResponse], + request: featurestore_service.SearchFeaturesRequest, + response: featurestore_service.SearchFeaturesResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.SearchFeaturesRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.SearchFeaturesResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = featurestore_service.SearchFeaturesRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[featurestore_service.SearchFeaturesResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterator[feature.Feature]: + for page in self.pages: + yield from page.features + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class SearchFeaturesAsyncPager: + """A pager for iterating through ``search_features`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.SearchFeaturesResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``features`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``SearchFeatures`` requests and continue to iterate + through the ``features`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.SearchFeaturesResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., Awaitable[featurestore_service.SearchFeaturesResponse]], + request: featurestore_service.SearchFeaturesRequest, + response: featurestore_service.SearchFeaturesResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.SearchFeaturesRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.SearchFeaturesResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = featurestore_service.SearchFeaturesRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[featurestore_service.SearchFeaturesResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + + def __aiter__(self) -> AsyncIterator[feature.Feature]: + async def async_generator(): + async for page in self.pages: + for response in page.features: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) diff --git a/google/cloud/aiplatform_v1/services/featurestore_service/transports/__init__.py b/google/cloud/aiplatform_v1/services/featurestore_service/transports/__init__.py new file mode 100644 index 0000000000..640a209314 --- /dev/null +++ b/google/cloud/aiplatform_v1/services/featurestore_service/transports/__init__.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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 typing import Dict, Type + +from .base import FeaturestoreServiceTransport +from .grpc import FeaturestoreServiceGrpcTransport +from .grpc_asyncio import FeaturestoreServiceGrpcAsyncIOTransport + + +# Compile a registry of transports. +_transport_registry = ( + OrderedDict() +) # type: Dict[str, Type[FeaturestoreServiceTransport]] +_transport_registry["grpc"] = FeaturestoreServiceGrpcTransport +_transport_registry["grpc_asyncio"] = FeaturestoreServiceGrpcAsyncIOTransport + +__all__ = ( + "FeaturestoreServiceTransport", + "FeaturestoreServiceGrpcTransport", + "FeaturestoreServiceGrpcAsyncIOTransport", +) diff --git a/google/cloud/aiplatform_v1/services/featurestore_service/transports/base.py b/google/cloud/aiplatform_v1/services/featurestore_service/transports/base.py new file mode 100644 index 0000000000..54501bb6dd --- /dev/null +++ b/google/cloud/aiplatform_v1/services/featurestore_service/transports/base.py @@ -0,0 +1,541 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import abc +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +import pkg_resources + +import google.auth # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import operations_v1 +from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore + +from google.cloud.aiplatform_v1.types import entity_type +from google.cloud.aiplatform_v1.types import entity_type as gca_entity_type +from google.cloud.aiplatform_v1.types import feature +from google.cloud.aiplatform_v1.types import feature as gca_feature +from google.cloud.aiplatform_v1.types import featurestore +from google.cloud.aiplatform_v1.types import featurestore_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.longrunning import operations_pb2 # type: ignore + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-aiplatform", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +class FeaturestoreServiceTransport(abc.ABC): + """Abstract transport class for FeaturestoreService.""" + + AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) + + DEFAULT_HOST: str = "aiplatform.googleapis.com" + + def __init__( + self, + *, + host: str = DEFAULT_HOST, + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + **kwargs, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + 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. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is mutually exclusive with credentials. + scopes (Optional[Sequence[str]]): A list of scopes. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + 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. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + """ + + # Save the hostname. Default to port 443 (HTTPS) if none is specified. + if ":" not in host: + host += ":443" + self._host = host + + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} + + # Save the scopes. + self._scopes = scopes + + # If no credentials are provided, then determine the appropriate + # defaults. + if credentials and credentials_file: + raise core_exceptions.DuplicateCredentialArgs( + "'credentials_file' and 'credentials' are mutually exclusive" + ) + + if credentials_file is not None: + credentials, _ = google.auth.load_credentials_from_file( + credentials_file, **scopes_kwargs, quota_project_id=quota_project_id + ) + elif credentials is None: + credentials, _ = google.auth.default( + **scopes_kwargs, quota_project_id=quota_project_id + ) + + # If the credentials are service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + + # Save the credentials. + self._credentials = credentials + + def _prep_wrapped_messages(self, client_info): + # Precompute the wrapped methods. + self._wrapped_methods = { + self.create_featurestore: gapic_v1.method.wrap_method( + self.create_featurestore, + default_timeout=None, + client_info=client_info, + ), + self.get_featurestore: gapic_v1.method.wrap_method( + self.get_featurestore, + default_timeout=None, + client_info=client_info, + ), + self.list_featurestores: gapic_v1.method.wrap_method( + self.list_featurestores, + default_timeout=None, + client_info=client_info, + ), + self.update_featurestore: gapic_v1.method.wrap_method( + self.update_featurestore, + default_timeout=None, + client_info=client_info, + ), + self.delete_featurestore: gapic_v1.method.wrap_method( + self.delete_featurestore, + default_timeout=None, + client_info=client_info, + ), + self.create_entity_type: gapic_v1.method.wrap_method( + self.create_entity_type, + default_timeout=None, + client_info=client_info, + ), + self.get_entity_type: gapic_v1.method.wrap_method( + self.get_entity_type, + default_timeout=None, + client_info=client_info, + ), + self.list_entity_types: gapic_v1.method.wrap_method( + self.list_entity_types, + default_timeout=None, + client_info=client_info, + ), + self.update_entity_type: gapic_v1.method.wrap_method( + self.update_entity_type, + default_timeout=None, + client_info=client_info, + ), + self.delete_entity_type: gapic_v1.method.wrap_method( + self.delete_entity_type, + default_timeout=None, + client_info=client_info, + ), + self.create_feature: gapic_v1.method.wrap_method( + self.create_feature, + default_timeout=None, + client_info=client_info, + ), + self.batch_create_features: gapic_v1.method.wrap_method( + self.batch_create_features, + default_timeout=None, + client_info=client_info, + ), + self.get_feature: gapic_v1.method.wrap_method( + self.get_feature, + default_timeout=None, + client_info=client_info, + ), + self.list_features: gapic_v1.method.wrap_method( + self.list_features, + default_timeout=None, + client_info=client_info, + ), + self.update_feature: gapic_v1.method.wrap_method( + self.update_feature, + default_timeout=None, + client_info=client_info, + ), + self.delete_feature: gapic_v1.method.wrap_method( + self.delete_feature, + default_timeout=None, + client_info=client_info, + ), + self.import_feature_values: gapic_v1.method.wrap_method( + self.import_feature_values, + default_timeout=None, + client_info=client_info, + ), + self.batch_read_feature_values: gapic_v1.method.wrap_method( + self.batch_read_feature_values, + default_timeout=None, + client_info=client_info, + ), + self.export_feature_values: gapic_v1.method.wrap_method( + self.export_feature_values, + default_timeout=None, + client_info=client_info, + ), + self.search_features: gapic_v1.method.wrap_method( + self.search_features, + default_timeout=None, + client_info=client_info, + ), + } + + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + + @property + def operations_client(self): + """Return the client designed to process long-running operations.""" + raise NotImplementedError() + + @property + def create_featurestore( + self, + ) -> Callable[ + [featurestore_service.CreateFeaturestoreRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def get_featurestore( + self, + ) -> Callable[ + [featurestore_service.GetFeaturestoreRequest], + Union[featurestore.Featurestore, Awaitable[featurestore.Featurestore]], + ]: + raise NotImplementedError() + + @property + def list_featurestores( + self, + ) -> Callable[ + [featurestore_service.ListFeaturestoresRequest], + Union[ + featurestore_service.ListFeaturestoresResponse, + Awaitable[featurestore_service.ListFeaturestoresResponse], + ], + ]: + raise NotImplementedError() + + @property + def update_featurestore( + self, + ) -> Callable[ + [featurestore_service.UpdateFeaturestoreRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def delete_featurestore( + self, + ) -> Callable[ + [featurestore_service.DeleteFeaturestoreRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def create_entity_type( + self, + ) -> Callable[ + [featurestore_service.CreateEntityTypeRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def get_entity_type( + self, + ) -> Callable[ + [featurestore_service.GetEntityTypeRequest], + Union[entity_type.EntityType, Awaitable[entity_type.EntityType]], + ]: + raise NotImplementedError() + + @property + def list_entity_types( + self, + ) -> Callable[ + [featurestore_service.ListEntityTypesRequest], + Union[ + featurestore_service.ListEntityTypesResponse, + Awaitable[featurestore_service.ListEntityTypesResponse], + ], + ]: + raise NotImplementedError() + + @property + def update_entity_type( + self, + ) -> Callable[ + [featurestore_service.UpdateEntityTypeRequest], + Union[gca_entity_type.EntityType, Awaitable[gca_entity_type.EntityType]], + ]: + raise NotImplementedError() + + @property + def delete_entity_type( + self, + ) -> Callable[ + [featurestore_service.DeleteEntityTypeRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def create_feature( + self, + ) -> Callable[ + [featurestore_service.CreateFeatureRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def batch_create_features( + self, + ) -> Callable[ + [featurestore_service.BatchCreateFeaturesRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def get_feature( + self, + ) -> Callable[ + [featurestore_service.GetFeatureRequest], + Union[feature.Feature, Awaitable[feature.Feature]], + ]: + raise NotImplementedError() + + @property + def list_features( + self, + ) -> Callable[ + [featurestore_service.ListFeaturesRequest], + Union[ + featurestore_service.ListFeaturesResponse, + Awaitable[featurestore_service.ListFeaturesResponse], + ], + ]: + raise NotImplementedError() + + @property + def update_feature( + self, + ) -> Callable[ + [featurestore_service.UpdateFeatureRequest], + Union[gca_feature.Feature, Awaitable[gca_feature.Feature]], + ]: + raise NotImplementedError() + + @property + def delete_feature( + self, + ) -> Callable[ + [featurestore_service.DeleteFeatureRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def import_feature_values( + self, + ) -> Callable[ + [featurestore_service.ImportFeatureValuesRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def batch_read_feature_values( + self, + ) -> Callable[ + [featurestore_service.BatchReadFeatureValuesRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def export_feature_values( + self, + ) -> Callable[ + [featurestore_service.ExportFeatureValuesRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def search_features( + self, + ) -> Callable[ + [featurestore_service.SearchFeaturesRequest], + Union[ + featurestore_service.SearchFeaturesResponse, + Awaitable[featurestore_service.SearchFeaturesResponse], + ], + ]: + raise NotImplementedError() + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], + Union[ + operations_pb2.ListOperationsResponse, + Awaitable[operations_pb2.ListOperationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None,]: + raise NotImplementedError() + + @property + def wait_operation( + self, + ) -> Callable[ + [operations_pb2.WaitOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def set_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def get_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_location( + self, + ) -> Callable[ + [locations_pb2.GetLocationRequest], + Union[locations_pb2.Location, Awaitable[locations_pb2.Location]], + ]: + raise NotImplementedError() + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], + Union[ + locations_pb2.ListLocationsResponse, + Awaitable[locations_pb2.ListLocationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + + +__all__ = ("FeaturestoreServiceTransport",) diff --git a/google/cloud/aiplatform_v1/services/featurestore_service/transports/grpc.py b/google/cloud/aiplatform_v1/services/featurestore_service/transports/grpc.py new file mode 100644 index 0000000000..824951d154 --- /dev/null +++ b/google/cloud/aiplatform_v1/services/featurestore_service/transports/grpc.py @@ -0,0 +1,1058 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import warnings +from typing import Callable, Dict, Optional, Sequence, Tuple, Union + +from google.api_core import grpc_helpers +from google.api_core import operations_v1 +from google.api_core import gapic_v1 +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore + +import grpc # type: ignore + +from google.cloud.aiplatform_v1.types import entity_type +from google.cloud.aiplatform_v1.types import entity_type as gca_entity_type +from google.cloud.aiplatform_v1.types import feature +from google.cloud.aiplatform_v1.types import feature as gca_feature +from google.cloud.aiplatform_v1.types import featurestore +from google.cloud.aiplatform_v1.types import featurestore_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.longrunning import operations_pb2 # type: ignore +from .base import FeaturestoreServiceTransport, DEFAULT_CLIENT_INFO + + +class FeaturestoreServiceGrpcTransport(FeaturestoreServiceTransport): + """gRPC backend transport for FeaturestoreService. + + The service that handles CRUD and List for resources for + Featurestore. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + + _stubs: Dict[str, Callable] + + def __init__( + self, + *, + host: str = "aiplatform.googleapis.com", + credentials: ga_credentials.Credentials = None, + credentials_file: str = None, + scopes: Sequence[str] = None, + channel: grpc.Channel = None, + api_mtls_endpoint: str = None, + client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, + ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + 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. + This argument is ignored if ``channel`` is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional(Sequence[str])): A list of scopes. This argument is + ignored if ``channel`` is provided. + channel (Optional[grpc.Channel]): A ``Channel`` instance through + which to make calls. + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or application default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for the grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure a mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + 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. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + self._grpc_channel = None + self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client: Optional[operations_v1.OperationsClient] = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + + if channel: + # Ignore credentials if a channel was passed. + credentials = False + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + self._ssl_channel_credentials = None + + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials + + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + ) + + if not self._grpc_channel: + self._grpc_channel = type(self).create_channel( + self._host, + # use the credentials which are saved + credentials=self._credentials, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, + quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) + + @classmethod + def create_channel( + cls, + host: str = "aiplatform.googleapis.com", + credentials: ga_credentials.Credentials = None, + credentials_file: str = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs, + ) -> grpc.Channel: + """Create and return a gRPC channel object. + Args: + host (Optional[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is mutually exclusive with credentials. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + grpc.Channel: A gRPC channel object. + + Raises: + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + + return grpc_helpers.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + quota_project_id=quota_project_id, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, + **kwargs, + ) + + @property + def grpc_channel(self) -> grpc.Channel: + """Return the channel designed to connect to this service.""" + return self._grpc_channel + + @property + def operations_client(self) -> operations_v1.OperationsClient: + """Create the client designed to process long-running operations. + + This property caches on the instance; repeated calls return the same + client. + """ + # Quick check: Only create a new client if we do not already have one. + if self._operations_client is None: + self._operations_client = operations_v1.OperationsClient(self.grpc_channel) + + # Return the client from cache. + return self._operations_client + + @property + def create_featurestore( + self, + ) -> Callable[ + [featurestore_service.CreateFeaturestoreRequest], operations_pb2.Operation + ]: + r"""Return a callable for the create featurestore method over gRPC. + + Creates a new Featurestore in a given project and + location. + + Returns: + Callable[[~.CreateFeaturestoreRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_featurestore" not in self._stubs: + self._stubs["create_featurestore"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/CreateFeaturestore", + request_serializer=featurestore_service.CreateFeaturestoreRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["create_featurestore"] + + @property + def get_featurestore( + self, + ) -> Callable[ + [featurestore_service.GetFeaturestoreRequest], featurestore.Featurestore + ]: + r"""Return a callable for the get featurestore method over gRPC. + + Gets details of a single Featurestore. + + Returns: + Callable[[~.GetFeaturestoreRequest], + ~.Featurestore]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_featurestore" not in self._stubs: + self._stubs["get_featurestore"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/GetFeaturestore", + request_serializer=featurestore_service.GetFeaturestoreRequest.serialize, + response_deserializer=featurestore.Featurestore.deserialize, + ) + return self._stubs["get_featurestore"] + + @property + def list_featurestores( + self, + ) -> Callable[ + [featurestore_service.ListFeaturestoresRequest], + featurestore_service.ListFeaturestoresResponse, + ]: + r"""Return a callable for the list featurestores method over gRPC. + + Lists Featurestores in a given project and location. + + Returns: + Callable[[~.ListFeaturestoresRequest], + ~.ListFeaturestoresResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_featurestores" not in self._stubs: + self._stubs["list_featurestores"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/ListFeaturestores", + request_serializer=featurestore_service.ListFeaturestoresRequest.serialize, + response_deserializer=featurestore_service.ListFeaturestoresResponse.deserialize, + ) + return self._stubs["list_featurestores"] + + @property + def update_featurestore( + self, + ) -> Callable[ + [featurestore_service.UpdateFeaturestoreRequest], operations_pb2.Operation + ]: + r"""Return a callable for the update featurestore method over gRPC. + + Updates the parameters of a single Featurestore. + + Returns: + Callable[[~.UpdateFeaturestoreRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_featurestore" not in self._stubs: + self._stubs["update_featurestore"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/UpdateFeaturestore", + request_serializer=featurestore_service.UpdateFeaturestoreRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["update_featurestore"] + + @property + def delete_featurestore( + self, + ) -> Callable[ + [featurestore_service.DeleteFeaturestoreRequest], operations_pb2.Operation + ]: + r"""Return a callable for the delete featurestore method over gRPC. + + Deletes a single Featurestore. The Featurestore must not contain + any EntityTypes or ``force`` must be set to true for the request + to succeed. + + Returns: + Callable[[~.DeleteFeaturestoreRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_featurestore" not in self._stubs: + self._stubs["delete_featurestore"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/DeleteFeaturestore", + request_serializer=featurestore_service.DeleteFeaturestoreRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_featurestore"] + + @property + def create_entity_type( + self, + ) -> Callable[ + [featurestore_service.CreateEntityTypeRequest], operations_pb2.Operation + ]: + r"""Return a callable for the create entity type method over gRPC. + + Creates a new EntityType in a given Featurestore. + + Returns: + Callable[[~.CreateEntityTypeRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_entity_type" not in self._stubs: + self._stubs["create_entity_type"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/CreateEntityType", + request_serializer=featurestore_service.CreateEntityTypeRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["create_entity_type"] + + @property + def get_entity_type( + self, + ) -> Callable[[featurestore_service.GetEntityTypeRequest], entity_type.EntityType]: + r"""Return a callable for the get entity type method over gRPC. + + Gets details of a single EntityType. + + Returns: + Callable[[~.GetEntityTypeRequest], + ~.EntityType]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_entity_type" not in self._stubs: + self._stubs["get_entity_type"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/GetEntityType", + request_serializer=featurestore_service.GetEntityTypeRequest.serialize, + response_deserializer=entity_type.EntityType.deserialize, + ) + return self._stubs["get_entity_type"] + + @property + def list_entity_types( + self, + ) -> Callable[ + [featurestore_service.ListEntityTypesRequest], + featurestore_service.ListEntityTypesResponse, + ]: + r"""Return a callable for the list entity types method over gRPC. + + Lists EntityTypes in a given Featurestore. + + Returns: + Callable[[~.ListEntityTypesRequest], + ~.ListEntityTypesResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_entity_types" not in self._stubs: + self._stubs["list_entity_types"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/ListEntityTypes", + request_serializer=featurestore_service.ListEntityTypesRequest.serialize, + response_deserializer=featurestore_service.ListEntityTypesResponse.deserialize, + ) + return self._stubs["list_entity_types"] + + @property + def update_entity_type( + self, + ) -> Callable[ + [featurestore_service.UpdateEntityTypeRequest], gca_entity_type.EntityType + ]: + r"""Return a callable for the update entity type method over gRPC. + + Updates the parameters of a single EntityType. + + Returns: + Callable[[~.UpdateEntityTypeRequest], + ~.EntityType]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_entity_type" not in self._stubs: + self._stubs["update_entity_type"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/UpdateEntityType", + request_serializer=featurestore_service.UpdateEntityTypeRequest.serialize, + response_deserializer=gca_entity_type.EntityType.deserialize, + ) + return self._stubs["update_entity_type"] + + @property + def delete_entity_type( + self, + ) -> Callable[ + [featurestore_service.DeleteEntityTypeRequest], operations_pb2.Operation + ]: + r"""Return a callable for the delete entity type method over gRPC. + + Deletes a single EntityType. The EntityType must not have any + Features or ``force`` must be set to true for the request to + succeed. + + Returns: + Callable[[~.DeleteEntityTypeRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_entity_type" not in self._stubs: + self._stubs["delete_entity_type"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/DeleteEntityType", + request_serializer=featurestore_service.DeleteEntityTypeRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_entity_type"] + + @property + def create_feature( + self, + ) -> Callable[ + [featurestore_service.CreateFeatureRequest], operations_pb2.Operation + ]: + r"""Return a callable for the create feature method over gRPC. + + Creates a new Feature in a given EntityType. + + Returns: + Callable[[~.CreateFeatureRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_feature" not in self._stubs: + self._stubs["create_feature"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/CreateFeature", + request_serializer=featurestore_service.CreateFeatureRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["create_feature"] + + @property + def batch_create_features( + self, + ) -> Callable[ + [featurestore_service.BatchCreateFeaturesRequest], operations_pb2.Operation + ]: + r"""Return a callable for the batch create features method over gRPC. + + Creates a batch of Features in a given EntityType. + + Returns: + Callable[[~.BatchCreateFeaturesRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "batch_create_features" not in self._stubs: + self._stubs["batch_create_features"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/BatchCreateFeatures", + request_serializer=featurestore_service.BatchCreateFeaturesRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["batch_create_features"] + + @property + def get_feature( + self, + ) -> Callable[[featurestore_service.GetFeatureRequest], feature.Feature]: + r"""Return a callable for the get feature method over gRPC. + + Gets details of a single Feature. + + Returns: + Callable[[~.GetFeatureRequest], + ~.Feature]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_feature" not in self._stubs: + self._stubs["get_feature"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/GetFeature", + request_serializer=featurestore_service.GetFeatureRequest.serialize, + response_deserializer=feature.Feature.deserialize, + ) + return self._stubs["get_feature"] + + @property + def list_features( + self, + ) -> Callable[ + [featurestore_service.ListFeaturesRequest], + featurestore_service.ListFeaturesResponse, + ]: + r"""Return a callable for the list features method over gRPC. + + Lists Features in a given EntityType. + + Returns: + Callable[[~.ListFeaturesRequest], + ~.ListFeaturesResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_features" not in self._stubs: + self._stubs["list_features"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/ListFeatures", + request_serializer=featurestore_service.ListFeaturesRequest.serialize, + response_deserializer=featurestore_service.ListFeaturesResponse.deserialize, + ) + return self._stubs["list_features"] + + @property + def update_feature( + self, + ) -> Callable[[featurestore_service.UpdateFeatureRequest], gca_feature.Feature]: + r"""Return a callable for the update feature method over gRPC. + + Updates the parameters of a single Feature. + + Returns: + Callable[[~.UpdateFeatureRequest], + ~.Feature]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_feature" not in self._stubs: + self._stubs["update_feature"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/UpdateFeature", + request_serializer=featurestore_service.UpdateFeatureRequest.serialize, + response_deserializer=gca_feature.Feature.deserialize, + ) + return self._stubs["update_feature"] + + @property + def delete_feature( + self, + ) -> Callable[ + [featurestore_service.DeleteFeatureRequest], operations_pb2.Operation + ]: + r"""Return a callable for the delete feature method over gRPC. + + Deletes a single Feature. + + Returns: + Callable[[~.DeleteFeatureRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_feature" not in self._stubs: + self._stubs["delete_feature"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/DeleteFeature", + request_serializer=featurestore_service.DeleteFeatureRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_feature"] + + @property + def import_feature_values( + self, + ) -> Callable[ + [featurestore_service.ImportFeatureValuesRequest], operations_pb2.Operation + ]: + r"""Return a callable for the import feature values method over gRPC. + + Imports Feature values into the Featurestore from a + source storage. + The progress of the import is tracked by the returned + operation. The imported features are guaranteed to be + visible to subsequent read operations after the + operation is marked as successfully done. + If an import operation fails, the Feature values + returned from reads and exports may be inconsistent. If + consistency is required, the caller must retry the same + import request again and wait till the new operation + returned is marked as successfully done. + There are also scenarios where the caller can cause + inconsistency. + - Source data for import contains multiple distinct + Feature values for the same entity ID and timestamp. + - Source is modified during an import. This includes + adding, updating, or removing source data and/or + metadata. Examples of updating metadata include but are + not limited to changing storage location, storage class, + or retention policy. + - Online serving cluster is under-provisioned. + + Returns: + Callable[[~.ImportFeatureValuesRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "import_feature_values" not in self._stubs: + self._stubs["import_feature_values"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/ImportFeatureValues", + request_serializer=featurestore_service.ImportFeatureValuesRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["import_feature_values"] + + @property + def batch_read_feature_values( + self, + ) -> Callable[ + [featurestore_service.BatchReadFeatureValuesRequest], operations_pb2.Operation + ]: + r"""Return a callable for the batch read feature values method over gRPC. + + Batch reads Feature values from a Featurestore. + This API enables batch reading Feature values, where + each read instance in the batch may read Feature values + of entities from one or more EntityTypes. Point-in-time + correctness is guaranteed for Feature values of each + read instance as of each instance's read timestamp. + + Returns: + Callable[[~.BatchReadFeatureValuesRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "batch_read_feature_values" not in self._stubs: + self._stubs["batch_read_feature_values"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/BatchReadFeatureValues", + request_serializer=featurestore_service.BatchReadFeatureValuesRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["batch_read_feature_values"] + + @property + def export_feature_values( + self, + ) -> Callable[ + [featurestore_service.ExportFeatureValuesRequest], operations_pb2.Operation + ]: + r"""Return a callable for the export feature values method over gRPC. + + Exports Feature values from all the entities of a + target EntityType. + + Returns: + Callable[[~.ExportFeatureValuesRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "export_feature_values" not in self._stubs: + self._stubs["export_feature_values"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/ExportFeatureValues", + request_serializer=featurestore_service.ExportFeatureValuesRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["export_feature_values"] + + @property + def search_features( + self, + ) -> Callable[ + [featurestore_service.SearchFeaturesRequest], + featurestore_service.SearchFeaturesResponse, + ]: + r"""Return a callable for the search features method over gRPC. + + Searches Features matching a query in a given + project. + + Returns: + Callable[[~.SearchFeaturesRequest], + ~.SearchFeaturesResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "search_features" not in self._stubs: + self._stubs["search_features"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/SearchFeatures", + request_serializer=featurestore_service.SearchFeaturesRequest.serialize, + response_deserializer=featurestore_service.SearchFeaturesResponse.deserialize, + ) + return self._stubs["search_features"] + + def close(self): + self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + @property + def kind(self) -> str: + return "grpc" + + +__all__ = ("FeaturestoreServiceGrpcTransport",) diff --git a/google/cloud/aiplatform_v1/services/featurestore_service/transports/grpc_asyncio.py b/google/cloud/aiplatform_v1/services/featurestore_service/transports/grpc_asyncio.py new file mode 100644 index 0000000000..4bcb535a68 --- /dev/null +++ b/google/cloud/aiplatform_v1/services/featurestore_service/transports/grpc_asyncio.py @@ -0,0 +1,1074 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import warnings +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union + +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import operations_v1 +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore + +import grpc # type: ignore +from grpc.experimental import aio # type: ignore + +from google.cloud.aiplatform_v1.types import entity_type +from google.cloud.aiplatform_v1.types import entity_type as gca_entity_type +from google.cloud.aiplatform_v1.types import feature +from google.cloud.aiplatform_v1.types import feature as gca_feature +from google.cloud.aiplatform_v1.types import featurestore +from google.cloud.aiplatform_v1.types import featurestore_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.longrunning import operations_pb2 # type: ignore +from .base import FeaturestoreServiceTransport, DEFAULT_CLIENT_INFO +from .grpc import FeaturestoreServiceGrpcTransport + + +class FeaturestoreServiceGrpcAsyncIOTransport(FeaturestoreServiceTransport): + """gRPC AsyncIO backend transport for FeaturestoreService. + + The service that handles CRUD and List for resources for + Featurestore. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + + _grpc_channel: aio.Channel + _stubs: Dict[str, Callable] = {} + + @classmethod + def create_channel( + cls, + host: str = "aiplatform.googleapis.com", + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs, + ) -> aio.Channel: + """Create and return a gRPC AsyncIO channel object. + Args: + host (Optional[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + aio.Channel: A gRPC AsyncIO channel object. + """ + + return grpc_helpers_async.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + quota_project_id=quota_project_id, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, + **kwargs, + ) + + def __init__( + self, + *, + host: str = "aiplatform.googleapis.com", + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: aio.Channel = None, + api_mtls_endpoint: str = None, + client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, + ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, + quota_project_id=None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + 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. + This argument is ignored if ``channel`` is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + channel (Optional[aio.Channel]): A ``Channel`` instance through + which to make calls. + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or application default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for the grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure a mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + 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. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + + Raises: + google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + self._grpc_channel = None + self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + + if channel: + # Ignore credentials if a channel was passed. + credentials = False + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + self._ssl_channel_credentials = None + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials + + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + ) + + if not self._grpc_channel: + self._grpc_channel = type(self).create_channel( + self._host, + # use the credentials which are saved + credentials=self._credentials, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, + quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) + + @property + def grpc_channel(self) -> aio.Channel: + """Create the channel designed to connect to this service. + + This property caches on the instance; repeated calls return + the same channel. + """ + # Return the channel from cache. + return self._grpc_channel + + @property + def operations_client(self) -> operations_v1.OperationsAsyncClient: + """Create the client designed to process long-running operations. + + This property caches on the instance; repeated calls return the same + client. + """ + # Quick check: Only create a new client if we do not already have one. + if self._operations_client is None: + self._operations_client = operations_v1.OperationsAsyncClient( + self.grpc_channel + ) + + # Return the client from cache. + return self._operations_client + + @property + def create_featurestore( + self, + ) -> Callable[ + [featurestore_service.CreateFeaturestoreRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the create featurestore method over gRPC. + + Creates a new Featurestore in a given project and + location. + + Returns: + Callable[[~.CreateFeaturestoreRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_featurestore" not in self._stubs: + self._stubs["create_featurestore"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/CreateFeaturestore", + request_serializer=featurestore_service.CreateFeaturestoreRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["create_featurestore"] + + @property + def get_featurestore( + self, + ) -> Callable[ + [featurestore_service.GetFeaturestoreRequest], + Awaitable[featurestore.Featurestore], + ]: + r"""Return a callable for the get featurestore method over gRPC. + + Gets details of a single Featurestore. + + Returns: + Callable[[~.GetFeaturestoreRequest], + Awaitable[~.Featurestore]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_featurestore" not in self._stubs: + self._stubs["get_featurestore"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/GetFeaturestore", + request_serializer=featurestore_service.GetFeaturestoreRequest.serialize, + response_deserializer=featurestore.Featurestore.deserialize, + ) + return self._stubs["get_featurestore"] + + @property + def list_featurestores( + self, + ) -> Callable[ + [featurestore_service.ListFeaturestoresRequest], + Awaitable[featurestore_service.ListFeaturestoresResponse], + ]: + r"""Return a callable for the list featurestores method over gRPC. + + Lists Featurestores in a given project and location. + + Returns: + Callable[[~.ListFeaturestoresRequest], + Awaitable[~.ListFeaturestoresResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_featurestores" not in self._stubs: + self._stubs["list_featurestores"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/ListFeaturestores", + request_serializer=featurestore_service.ListFeaturestoresRequest.serialize, + response_deserializer=featurestore_service.ListFeaturestoresResponse.deserialize, + ) + return self._stubs["list_featurestores"] + + @property + def update_featurestore( + self, + ) -> Callable[ + [featurestore_service.UpdateFeaturestoreRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the update featurestore method over gRPC. + + Updates the parameters of a single Featurestore. + + Returns: + Callable[[~.UpdateFeaturestoreRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_featurestore" not in self._stubs: + self._stubs["update_featurestore"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/UpdateFeaturestore", + request_serializer=featurestore_service.UpdateFeaturestoreRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["update_featurestore"] + + @property + def delete_featurestore( + self, + ) -> Callable[ + [featurestore_service.DeleteFeaturestoreRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the delete featurestore method over gRPC. + + Deletes a single Featurestore. The Featurestore must not contain + any EntityTypes or ``force`` must be set to true for the request + to succeed. + + Returns: + Callable[[~.DeleteFeaturestoreRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_featurestore" not in self._stubs: + self._stubs["delete_featurestore"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/DeleteFeaturestore", + request_serializer=featurestore_service.DeleteFeaturestoreRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_featurestore"] + + @property + def create_entity_type( + self, + ) -> Callable[ + [featurestore_service.CreateEntityTypeRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the create entity type method over gRPC. + + Creates a new EntityType in a given Featurestore. + + Returns: + Callable[[~.CreateEntityTypeRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_entity_type" not in self._stubs: + self._stubs["create_entity_type"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/CreateEntityType", + request_serializer=featurestore_service.CreateEntityTypeRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["create_entity_type"] + + @property + def get_entity_type( + self, + ) -> Callable[ + [featurestore_service.GetEntityTypeRequest], Awaitable[entity_type.EntityType] + ]: + r"""Return a callable for the get entity type method over gRPC. + + Gets details of a single EntityType. + + Returns: + Callable[[~.GetEntityTypeRequest], + Awaitable[~.EntityType]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_entity_type" not in self._stubs: + self._stubs["get_entity_type"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/GetEntityType", + request_serializer=featurestore_service.GetEntityTypeRequest.serialize, + response_deserializer=entity_type.EntityType.deserialize, + ) + return self._stubs["get_entity_type"] + + @property + def list_entity_types( + self, + ) -> Callable[ + [featurestore_service.ListEntityTypesRequest], + Awaitable[featurestore_service.ListEntityTypesResponse], + ]: + r"""Return a callable for the list entity types method over gRPC. + + Lists EntityTypes in a given Featurestore. + + Returns: + Callable[[~.ListEntityTypesRequest], + Awaitable[~.ListEntityTypesResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_entity_types" not in self._stubs: + self._stubs["list_entity_types"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/ListEntityTypes", + request_serializer=featurestore_service.ListEntityTypesRequest.serialize, + response_deserializer=featurestore_service.ListEntityTypesResponse.deserialize, + ) + return self._stubs["list_entity_types"] + + @property + def update_entity_type( + self, + ) -> Callable[ + [featurestore_service.UpdateEntityTypeRequest], + Awaitable[gca_entity_type.EntityType], + ]: + r"""Return a callable for the update entity type method over gRPC. + + Updates the parameters of a single EntityType. + + Returns: + Callable[[~.UpdateEntityTypeRequest], + Awaitable[~.EntityType]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_entity_type" not in self._stubs: + self._stubs["update_entity_type"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/UpdateEntityType", + request_serializer=featurestore_service.UpdateEntityTypeRequest.serialize, + response_deserializer=gca_entity_type.EntityType.deserialize, + ) + return self._stubs["update_entity_type"] + + @property + def delete_entity_type( + self, + ) -> Callable[ + [featurestore_service.DeleteEntityTypeRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the delete entity type method over gRPC. + + Deletes a single EntityType. The EntityType must not have any + Features or ``force`` must be set to true for the request to + succeed. + + Returns: + Callable[[~.DeleteEntityTypeRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_entity_type" not in self._stubs: + self._stubs["delete_entity_type"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/DeleteEntityType", + request_serializer=featurestore_service.DeleteEntityTypeRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_entity_type"] + + @property + def create_feature( + self, + ) -> Callable[ + [featurestore_service.CreateFeatureRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the create feature method over gRPC. + + Creates a new Feature in a given EntityType. + + Returns: + Callable[[~.CreateFeatureRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_feature" not in self._stubs: + self._stubs["create_feature"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/CreateFeature", + request_serializer=featurestore_service.CreateFeatureRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["create_feature"] + + @property + def batch_create_features( + self, + ) -> Callable[ + [featurestore_service.BatchCreateFeaturesRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the batch create features method over gRPC. + + Creates a batch of Features in a given EntityType. + + Returns: + Callable[[~.BatchCreateFeaturesRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "batch_create_features" not in self._stubs: + self._stubs["batch_create_features"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/BatchCreateFeatures", + request_serializer=featurestore_service.BatchCreateFeaturesRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["batch_create_features"] + + @property + def get_feature( + self, + ) -> Callable[[featurestore_service.GetFeatureRequest], Awaitable[feature.Feature]]: + r"""Return a callable for the get feature method over gRPC. + + Gets details of a single Feature. + + Returns: + Callable[[~.GetFeatureRequest], + Awaitable[~.Feature]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_feature" not in self._stubs: + self._stubs["get_feature"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/GetFeature", + request_serializer=featurestore_service.GetFeatureRequest.serialize, + response_deserializer=feature.Feature.deserialize, + ) + return self._stubs["get_feature"] + + @property + def list_features( + self, + ) -> Callable[ + [featurestore_service.ListFeaturesRequest], + Awaitable[featurestore_service.ListFeaturesResponse], + ]: + r"""Return a callable for the list features method over gRPC. + + Lists Features in a given EntityType. + + Returns: + Callable[[~.ListFeaturesRequest], + Awaitable[~.ListFeaturesResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_features" not in self._stubs: + self._stubs["list_features"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/ListFeatures", + request_serializer=featurestore_service.ListFeaturesRequest.serialize, + response_deserializer=featurestore_service.ListFeaturesResponse.deserialize, + ) + return self._stubs["list_features"] + + @property + def update_feature( + self, + ) -> Callable[ + [featurestore_service.UpdateFeatureRequest], Awaitable[gca_feature.Feature] + ]: + r"""Return a callable for the update feature method over gRPC. + + Updates the parameters of a single Feature. + + Returns: + Callable[[~.UpdateFeatureRequest], + Awaitable[~.Feature]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_feature" not in self._stubs: + self._stubs["update_feature"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/UpdateFeature", + request_serializer=featurestore_service.UpdateFeatureRequest.serialize, + response_deserializer=gca_feature.Feature.deserialize, + ) + return self._stubs["update_feature"] + + @property + def delete_feature( + self, + ) -> Callable[ + [featurestore_service.DeleteFeatureRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the delete feature method over gRPC. + + Deletes a single Feature. + + Returns: + Callable[[~.DeleteFeatureRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_feature" not in self._stubs: + self._stubs["delete_feature"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/DeleteFeature", + request_serializer=featurestore_service.DeleteFeatureRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_feature"] + + @property + def import_feature_values( + self, + ) -> Callable[ + [featurestore_service.ImportFeatureValuesRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the import feature values method over gRPC. + + Imports Feature values into the Featurestore from a + source storage. + The progress of the import is tracked by the returned + operation. The imported features are guaranteed to be + visible to subsequent read operations after the + operation is marked as successfully done. + If an import operation fails, the Feature values + returned from reads and exports may be inconsistent. If + consistency is required, the caller must retry the same + import request again and wait till the new operation + returned is marked as successfully done. + There are also scenarios where the caller can cause + inconsistency. + - Source data for import contains multiple distinct + Feature values for the same entity ID and timestamp. + - Source is modified during an import. This includes + adding, updating, or removing source data and/or + metadata. Examples of updating metadata include but are + not limited to changing storage location, storage class, + or retention policy. + - Online serving cluster is under-provisioned. + + Returns: + Callable[[~.ImportFeatureValuesRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "import_feature_values" not in self._stubs: + self._stubs["import_feature_values"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/ImportFeatureValues", + request_serializer=featurestore_service.ImportFeatureValuesRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["import_feature_values"] + + @property + def batch_read_feature_values( + self, + ) -> Callable[ + [featurestore_service.BatchReadFeatureValuesRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the batch read feature values method over gRPC. + + Batch reads Feature values from a Featurestore. + This API enables batch reading Feature values, where + each read instance in the batch may read Feature values + of entities from one or more EntityTypes. Point-in-time + correctness is guaranteed for Feature values of each + read instance as of each instance's read timestamp. + + Returns: + Callable[[~.BatchReadFeatureValuesRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "batch_read_feature_values" not in self._stubs: + self._stubs["batch_read_feature_values"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/BatchReadFeatureValues", + request_serializer=featurestore_service.BatchReadFeatureValuesRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["batch_read_feature_values"] + + @property + def export_feature_values( + self, + ) -> Callable[ + [featurestore_service.ExportFeatureValuesRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the export feature values method over gRPC. + + Exports Feature values from all the entities of a + target EntityType. + + Returns: + Callable[[~.ExportFeatureValuesRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "export_feature_values" not in self._stubs: + self._stubs["export_feature_values"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/ExportFeatureValues", + request_serializer=featurestore_service.ExportFeatureValuesRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["export_feature_values"] + + @property + def search_features( + self, + ) -> Callable[ + [featurestore_service.SearchFeaturesRequest], + Awaitable[featurestore_service.SearchFeaturesResponse], + ]: + r"""Return a callable for the search features method over gRPC. + + Searches Features matching a query in a given + project. + + Returns: + Callable[[~.SearchFeaturesRequest], + Awaitable[~.SearchFeaturesResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "search_features" not in self._stubs: + self._stubs["search_features"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.FeaturestoreService/SearchFeatures", + request_serializer=featurestore_service.SearchFeaturesRequest.serialize, + response_deserializer=featurestore_service.SearchFeaturesResponse.deserialize, + ) + return self._stubs["search_features"] + + def close(self): + return self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + +__all__ = ("FeaturestoreServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/aiplatform_v1/services/index_endpoint_service/__init__.py b/google/cloud/aiplatform_v1/services/index_endpoint_service/__init__.py new file mode 100644 index 0000000000..7cde1c0f69 --- /dev/null +++ b/google/cloud/aiplatform_v1/services/index_endpoint_service/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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 .client import IndexEndpointServiceClient +from .async_client import IndexEndpointServiceAsyncClient + +__all__ = ( + "IndexEndpointServiceClient", + "IndexEndpointServiceAsyncClient", +) diff --git a/google/cloud/aiplatform_v1/services/index_endpoint_service/async_client.py b/google/cloud/aiplatform_v1/services/index_endpoint_service/async_client.py new file mode 100644 index 0000000000..9071bce789 --- /dev/null +++ b/google/cloud/aiplatform_v1/services/index_endpoint_service/async_client.py @@ -0,0 +1,1862 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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, Mapping, Optional, Sequence, Tuple, Type, Union +import pkg_resources + +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore + +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + +from google.api_core import operation as gac_operation # type: ignore +from google.api_core import operation_async # type: ignore +from google.cloud.aiplatform_v1.services.index_endpoint_service import pagers +from google.cloud.aiplatform_v1.types import index_endpoint +from google.cloud.aiplatform_v1.types import index_endpoint as gca_index_endpoint +from google.cloud.aiplatform_v1.types import index_endpoint_service +from google.cloud.aiplatform_v1.types import operation as gca_operation +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from .transports.base import IndexEndpointServiceTransport, DEFAULT_CLIENT_INFO +from .transports.grpc_asyncio import IndexEndpointServiceGrpcAsyncIOTransport +from .client import IndexEndpointServiceClient + + +class IndexEndpointServiceAsyncClient: + """A service for managing Vertex AI's IndexEndpoints.""" + + _client: IndexEndpointServiceClient + + DEFAULT_ENDPOINT = IndexEndpointServiceClient.DEFAULT_ENDPOINT + DEFAULT_MTLS_ENDPOINT = IndexEndpointServiceClient.DEFAULT_MTLS_ENDPOINT + + index_path = staticmethod(IndexEndpointServiceClient.index_path) + parse_index_path = staticmethod(IndexEndpointServiceClient.parse_index_path) + index_endpoint_path = staticmethod(IndexEndpointServiceClient.index_endpoint_path) + parse_index_endpoint_path = staticmethod( + IndexEndpointServiceClient.parse_index_endpoint_path + ) + common_billing_account_path = staticmethod( + IndexEndpointServiceClient.common_billing_account_path + ) + parse_common_billing_account_path = staticmethod( + IndexEndpointServiceClient.parse_common_billing_account_path + ) + common_folder_path = staticmethod(IndexEndpointServiceClient.common_folder_path) + parse_common_folder_path = staticmethod( + IndexEndpointServiceClient.parse_common_folder_path + ) + common_organization_path = staticmethod( + IndexEndpointServiceClient.common_organization_path + ) + parse_common_organization_path = staticmethod( + IndexEndpointServiceClient.parse_common_organization_path + ) + common_project_path = staticmethod(IndexEndpointServiceClient.common_project_path) + parse_common_project_path = staticmethod( + IndexEndpointServiceClient.parse_common_project_path + ) + common_location_path = staticmethod(IndexEndpointServiceClient.common_location_path) + parse_common_location_path = staticmethod( + IndexEndpointServiceClient.parse_common_location_path + ) + + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials + info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + IndexEndpointServiceAsyncClient: The constructed client. + """ + return IndexEndpointServiceClient.from_service_account_info.__func__(IndexEndpointServiceAsyncClient, info, *args, **kwargs) # type: ignore + + @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: + IndexEndpointServiceAsyncClient: The constructed client. + """ + return IndexEndpointServiceClient.from_service_account_file.__func__(IndexEndpointServiceAsyncClient, filename, *args, **kwargs) # type: ignore + + from_service_account_json = from_service_account_file + + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return IndexEndpointServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + + @property + def transport(self) -> IndexEndpointServiceTransport: + """Returns the transport used by the client instance. + + Returns: + IndexEndpointServiceTransport: The transport used by the client instance. + """ + return self._client.transport + + get_transport_class = functools.partial( + type(IndexEndpointServiceClient).get_transport_class, + type(IndexEndpointServiceClient), + ) + + def __init__( + self, + *, + credentials: ga_credentials.Credentials = None, + transport: Union[str, IndexEndpointServiceTransport] = "grpc_asyncio", + client_options: ClientOptions = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the index endpoint 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, ~.IndexEndpointServiceTransport]): 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 = IndexEndpointServiceClient( + credentials=credentials, + transport=transport, + client_options=client_options, + client_info=client_info, + ) + + async def create_index_endpoint( + self, + request: Union[index_endpoint_service.CreateIndexEndpointRequest, dict] = None, + *, + parent: str = None, + index_endpoint: gca_index_endpoint.IndexEndpoint = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Creates an IndexEndpoint. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_create_index_endpoint(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + index_endpoint = aiplatform_v1.IndexEndpoint() + index_endpoint.display_name = "display_name_value" + + request = aiplatform_v1.CreateIndexEndpointRequest( + parent="parent_value", + index_endpoint=index_endpoint, + ) + + # Make the request + operation = client.create_index_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CreateIndexEndpointRequest, dict]): + The request object. Request message for + [IndexEndpointService.CreateIndexEndpoint][google.cloud.aiplatform.v1.IndexEndpointService.CreateIndexEndpoint]. + parent (:class:`str`): + Required. The resource name of the Location to create + the IndexEndpoint in. Format: + ``projects/{project}/locations/{location}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + index_endpoint (:class:`google.cloud.aiplatform_v1.types.IndexEndpoint`): + Required. The IndexEndpoint to + create. + + This corresponds to the ``index_endpoint`` 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.cloud.aiplatform_v1.types.IndexEndpoint` Indexes are deployed into it. An IndexEndpoint can have multiple + DeployedIndexes. + + """ + # Create or coerce a protobuf request object. + # Quick 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, index_endpoint]) + 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 = index_endpoint_service.CreateIndexEndpointRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if index_endpoint is not None: + request.index_endpoint = index_endpoint + + # 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_index_endpoint, + default_timeout=None, + 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, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + gca_index_endpoint.IndexEndpoint, + metadata_type=index_endpoint_service.CreateIndexEndpointOperationMetadata, + ) + + # Done; return the response. + return response + + async def get_index_endpoint( + self, + request: Union[index_endpoint_service.GetIndexEndpointRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> index_endpoint.IndexEndpoint: + r"""Gets an IndexEndpoint. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_get_index_endpoint(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetIndexEndpointRequest( + name="name_value", + ) + + # Make the request + response = await client.get_index_endpoint(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetIndexEndpointRequest, dict]): + The request object. Request message for + [IndexEndpointService.GetIndexEndpoint][google.cloud.aiplatform.v1.IndexEndpointService.GetIndexEndpoint] + name (:class:`str`): + Required. The name of the IndexEndpoint resource. + Format: + ``projects/{project}/locations/{location}/indexEndpoints/{index_endpoint}`` + + 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: + google.cloud.aiplatform_v1.types.IndexEndpoint: + Indexes are deployed into it. An + IndexEndpoint can have multiple + DeployedIndexes. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = index_endpoint_service.GetIndexEndpointRequest(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_index_endpoint, + default_timeout=None, + 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 list_index_endpoints( + self, + request: Union[index_endpoint_service.ListIndexEndpointsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListIndexEndpointsAsyncPager: + r"""Lists IndexEndpoints in a Location. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_list_index_endpoints(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListIndexEndpointsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_index_endpoints(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListIndexEndpointsRequest, dict]): + The request object. Request message for + [IndexEndpointService.ListIndexEndpoints][google.cloud.aiplatform.v1.IndexEndpointService.ListIndexEndpoints]. + parent (:class:`str`): + Required. The resource name of the Location from which + to list the IndexEndpoints. Format: + ``projects/{project}/locations/{location}`` + + 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: + google.cloud.aiplatform_v1.services.index_endpoint_service.pagers.ListIndexEndpointsAsyncPager: + Response message for + [IndexEndpointService.ListIndexEndpoints][google.cloud.aiplatform.v1.IndexEndpointService.ListIndexEndpoints]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = index_endpoint_service.ListIndexEndpointsRequest(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_index_endpoints, + default_timeout=None, + 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.ListIndexEndpointsAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def update_index_endpoint( + self, + request: Union[index_endpoint_service.UpdateIndexEndpointRequest, dict] = None, + *, + index_endpoint: gca_index_endpoint.IndexEndpoint = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_index_endpoint.IndexEndpoint: + r"""Updates an IndexEndpoint. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_update_index_endpoint(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + index_endpoint = aiplatform_v1.IndexEndpoint() + index_endpoint.display_name = "display_name_value" + + request = aiplatform_v1.UpdateIndexEndpointRequest( + index_endpoint=index_endpoint, + ) + + # Make the request + response = await client.update_index_endpoint(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.UpdateIndexEndpointRequest, dict]): + The request object. Request message for + [IndexEndpointService.UpdateIndexEndpoint][google.cloud.aiplatform.v1.IndexEndpointService.UpdateIndexEndpoint]. + index_endpoint (:class:`google.cloud.aiplatform_v1.types.IndexEndpoint`): + Required. The IndexEndpoint which + replaces the resource on the server. + + This corresponds to the ``index_endpoint`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + Required. The update mask applies to the resource. See + [google.protobuf.FieldMask][google.protobuf.FieldMask]. + + 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: + google.cloud.aiplatform_v1.types.IndexEndpoint: + Indexes are deployed into it. An + IndexEndpoint can have multiple + DeployedIndexes. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([index_endpoint, 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 = index_endpoint_service.UpdateIndexEndpointRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if index_endpoint is not None: + request.index_endpoint = index_endpoint + 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_index_endpoint, + default_timeout=None, + 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( + (("index_endpoint.name", request.index_endpoint.name),) + ), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def delete_index_endpoint( + self, + request: Union[index_endpoint_service.DeleteIndexEndpointRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Deletes an IndexEndpoint. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_delete_index_endpoint(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteIndexEndpointRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_index_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.DeleteIndexEndpointRequest, dict]): + The request object. Request message for + [IndexEndpointService.DeleteIndexEndpoint][google.cloud.aiplatform.v1.IndexEndpointService.DeleteIndexEndpoint]. + name (:class:`str`): + Required. The name of the IndexEndpoint resource to be + deleted. Format: + ``projects/{project}/locations/{location}/indexEndpoints/{index_endpoint}`` + + 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = index_endpoint_service.DeleteIndexEndpointRequest(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_index_endpoint, + default_timeout=None, + 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, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, + ) + + # Done; return the response. + return response + + async def deploy_index( + self, + request: Union[index_endpoint_service.DeployIndexRequest, dict] = None, + *, + index_endpoint: str = None, + deployed_index: gca_index_endpoint.DeployedIndex = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Deploys an Index into this IndexEndpoint, creating a + DeployedIndex within it. + Only non-empty Indexes can be deployed. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_deploy_index(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + deployed_index = aiplatform_v1.DeployedIndex() + deployed_index.id = "id_value" + deployed_index.index = "index_value" + + request = aiplatform_v1.DeployIndexRequest( + index_endpoint="index_endpoint_value", + deployed_index=deployed_index, + ) + + # Make the request + operation = client.deploy_index(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.DeployIndexRequest, dict]): + The request object. Request message for + [IndexEndpointService.DeployIndex][google.cloud.aiplatform.v1.IndexEndpointService.DeployIndex]. + index_endpoint (:class:`str`): + Required. The name of the IndexEndpoint resource into + which to deploy an Index. Format: + ``projects/{project}/locations/{location}/indexEndpoints/{index_endpoint}`` + + This corresponds to the ``index_endpoint`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + deployed_index (:class:`google.cloud.aiplatform_v1.types.DeployedIndex`): + Required. The DeployedIndex to be + created within the IndexEndpoint. + + This corresponds to the ``deployed_index`` 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.aiplatform_v1.types.DeployIndexResponse` + Response message for + [IndexEndpointService.DeployIndex][google.cloud.aiplatform.v1.IndexEndpointService.DeployIndex]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([index_endpoint, deployed_index]) + 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 = index_endpoint_service.DeployIndexRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if index_endpoint is not None: + request.index_endpoint = index_endpoint + if deployed_index is not None: + request.deployed_index = deployed_index + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.deploy_index, + default_timeout=None, + 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( + (("index_endpoint", request.index_endpoint),) + ), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + index_endpoint_service.DeployIndexResponse, + metadata_type=index_endpoint_service.DeployIndexOperationMetadata, + ) + + # Done; return the response. + return response + + async def undeploy_index( + self, + request: Union[index_endpoint_service.UndeployIndexRequest, dict] = None, + *, + index_endpoint: str = None, + deployed_index_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Undeploys an Index from an IndexEndpoint, removing a + DeployedIndex from it, and freeing all resources it's + using. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_undeploy_index(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.UndeployIndexRequest( + index_endpoint="index_endpoint_value", + deployed_index_id="deployed_index_id_value", + ) + + # Make the request + operation = client.undeploy_index(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.UndeployIndexRequest, dict]): + The request object. Request message for + [IndexEndpointService.UndeployIndex][google.cloud.aiplatform.v1.IndexEndpointService.UndeployIndex]. + index_endpoint (:class:`str`): + Required. The name of the IndexEndpoint resource from + which to undeploy an Index. Format: + ``projects/{project}/locations/{location}/indexEndpoints/{index_endpoint}`` + + This corresponds to the ``index_endpoint`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + deployed_index_id (:class:`str`): + Required. The ID of the DeployedIndex + to be undeployed from the IndexEndpoint. + + This corresponds to the ``deployed_index_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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.aiplatform_v1.types.UndeployIndexResponse` + Response message for + [IndexEndpointService.UndeployIndex][google.cloud.aiplatform.v1.IndexEndpointService.UndeployIndex]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([index_endpoint, deployed_index_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 = index_endpoint_service.UndeployIndexRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if index_endpoint is not None: + request.index_endpoint = index_endpoint + if deployed_index_id is not None: + request.deployed_index_id = deployed_index_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.undeploy_index, + default_timeout=None, + 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( + (("index_endpoint", request.index_endpoint),) + ), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + index_endpoint_service.UndeployIndexResponse, + metadata_type=index_endpoint_service.UndeployIndexOperationMetadata, + ) + + # Done; return the response. + return response + + async def mutate_deployed_index( + self, + request: Union[index_endpoint_service.MutateDeployedIndexRequest, dict] = None, + *, + index_endpoint: str = None, + deployed_index: gca_index_endpoint.DeployedIndex = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Update an existing DeployedIndex under an + IndexEndpoint. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_mutate_deployed_index(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + deployed_index = aiplatform_v1.DeployedIndex() + deployed_index.id = "id_value" + deployed_index.index = "index_value" + + request = aiplatform_v1.MutateDeployedIndexRequest( + index_endpoint="index_endpoint_value", + deployed_index=deployed_index, + ) + + # Make the request + operation = client.mutate_deployed_index(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.MutateDeployedIndexRequest, dict]): + The request object. Request message for + [IndexEndpointService.MutateDeployedIndex][google.cloud.aiplatform.v1.IndexEndpointService.MutateDeployedIndex]. + index_endpoint (:class:`str`): + Required. The name of the IndexEndpoint resource into + which to deploy an Index. Format: + ``projects/{project}/locations/{location}/indexEndpoints/{index_endpoint}`` + + This corresponds to the ``index_endpoint`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + deployed_index (:class:`google.cloud.aiplatform_v1.types.DeployedIndex`): + Required. The DeployedIndex to be updated within the + IndexEndpoint. Currently, the updatable fields are + [DeployedIndex][automatic_resources] and + [DeployedIndex][dedicated_resources] + + This corresponds to the ``deployed_index`` 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.aiplatform_v1.types.MutateDeployedIndexResponse` + Response message for + [IndexEndpointService.MutateDeployedIndex][google.cloud.aiplatform.v1.IndexEndpointService.MutateDeployedIndex]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([index_endpoint, deployed_index]) + 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 = index_endpoint_service.MutateDeployedIndexRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if index_endpoint is not None: + request.index_endpoint = index_endpoint + if deployed_index is not None: + request.deployed_index = deployed_index + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.mutate_deployed_index, + default_timeout=None, + 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( + (("index_endpoint", request.index_endpoint),) + ), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + index_endpoint_service.MutateDeployedIndexResponse, + metadata_type=index_endpoint_service.MutateDeployedIndexOperationMetadata, + ) + + # Done; return the response. + return response + + async def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_operations, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.delete_operation, + default_timeout=None, + 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 cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + 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 wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.wait_operation, + default_timeout=None, + 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 set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_location, + default_timeout=None, + 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 list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_locations, + default_timeout=None, + 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 __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-aiplatform", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ("IndexEndpointServiceAsyncClient",) diff --git a/google/cloud/aiplatform_v1/services/index_endpoint_service/client.py b/google/cloud/aiplatform_v1/services/index_endpoint_service/client.py new file mode 100644 index 0000000000..148733965a --- /dev/null +++ b/google/cloud/aiplatform_v1/services/index_endpoint_service/client.py @@ -0,0 +1,2110 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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 os +import re +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union +import pkg_resources + +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.auth import credentials as ga_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 + +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + +from google.api_core import operation as gac_operation # type: ignore +from google.api_core import operation_async # type: ignore +from google.cloud.aiplatform_v1.services.index_endpoint_service import pagers +from google.cloud.aiplatform_v1.types import index_endpoint +from google.cloud.aiplatform_v1.types import index_endpoint as gca_index_endpoint +from google.cloud.aiplatform_v1.types import index_endpoint_service +from google.cloud.aiplatform_v1.types import operation as gca_operation +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from .transports.base import IndexEndpointServiceTransport, DEFAULT_CLIENT_INFO +from .transports.grpc import IndexEndpointServiceGrpcTransport +from .transports.grpc_asyncio import IndexEndpointServiceGrpcAsyncIOTransport + + +class IndexEndpointServiceClientMeta(type): + """Metaclass for the IndexEndpointService 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[IndexEndpointServiceTransport]] + _transport_registry["grpc"] = IndexEndpointServiceGrpcTransport + _transport_registry["grpc_asyncio"] = IndexEndpointServiceGrpcAsyncIOTransport + + def get_transport_class( + cls, + label: str = None, + ) -> Type[IndexEndpointServiceTransport]: + """Returns 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 IndexEndpointServiceClient(metaclass=IndexEndpointServiceClientMeta): + """A service for managing Vertex AI's IndexEndpoints.""" + + @staticmethod + def _get_default_mtls_endpoint(api_endpoint): + """Converts 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 = "aiplatform.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials + info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + IndexEndpointServiceClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + + @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: + IndexEndpointServiceClient: 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) -> IndexEndpointServiceTransport: + """Returns the transport used by the client instance. + + Returns: + IndexEndpointServiceTransport: The transport used by the client + instance. + """ + return self._transport + + @staticmethod + def index_path( + project: str, + location: str, + index: str, + ) -> str: + """Returns a fully-qualified index string.""" + return "projects/{project}/locations/{location}/indexes/{index}".format( + project=project, + location=location, + index=index, + ) + + @staticmethod + def parse_index_path(path: str) -> Dict[str, str]: + """Parses a index path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/indexes/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def index_endpoint_path( + project: str, + location: str, + index_endpoint: str, + ) -> str: + """Returns a fully-qualified index_endpoint string.""" + return "projects/{project}/locations/{location}/indexEndpoints/{index_endpoint}".format( + project=project, + location=location, + index_endpoint=index_endpoint, + ) + + @staticmethod + def parse_index_endpoint_path(path: str) -> Dict[str, str]: + """Parses a index_endpoint path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/indexEndpoints/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def common_billing_account_path( + billing_account: str, + ) -> str: + """Returns 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: + """Returns 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: + """Returns 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: + """Returns 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: + """Returns 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 {} + + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + + def __init__( + self, + *, + credentials: Optional[ga_credentials.Credentials] = None, + transport: Union[str, IndexEndpointServiceTransport, None] = None, + client_options: Optional[client_options_lib.ClientOptions] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the index endpoint 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, IndexEndpointServiceTransport]): The + transport to use. If set to None, a transport is chosen + automatically. + client_options (google.api_core.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. + 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() + + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options + ) + + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) + + # 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, IndexEndpointServiceTransport): + # transport is a IndexEndpointServiceTransport instance. + if credentials or client_options.credentials_file or api_key_value: + 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: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + + 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, + client_cert_source_for_mtls=client_cert_source_func, + quota_project_id=client_options.quota_project_id, + client_info=client_info, + always_use_jwt_access=True, + ) + + def create_index_endpoint( + self, + request: Union[index_endpoint_service.CreateIndexEndpointRequest, dict] = None, + *, + parent: str = None, + index_endpoint: gca_index_endpoint.IndexEndpoint = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Creates an IndexEndpoint. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_create_index_endpoint(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceClient() + + # Initialize request argument(s) + index_endpoint = aiplatform_v1.IndexEndpoint() + index_endpoint.display_name = "display_name_value" + + request = aiplatform_v1.CreateIndexEndpointRequest( + parent="parent_value", + index_endpoint=index_endpoint, + ) + + # Make the request + operation = client.create_index_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CreateIndexEndpointRequest, dict]): + The request object. Request message for + [IndexEndpointService.CreateIndexEndpoint][google.cloud.aiplatform.v1.IndexEndpointService.CreateIndexEndpoint]. + parent (str): + Required. The resource name of the Location to create + the IndexEndpoint in. Format: + ``projects/{project}/locations/{location}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + index_endpoint (google.cloud.aiplatform_v1.types.IndexEndpoint): + Required. The IndexEndpoint to + create. + + This corresponds to the ``index_endpoint`` 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.cloud.aiplatform_v1.types.IndexEndpoint` Indexes are deployed into it. An IndexEndpoint can have multiple + DeployedIndexes. + + """ + # Create or coerce a protobuf request object. + # Quick 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, index_endpoint]) + 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 index_endpoint_service.CreateIndexEndpointRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, index_endpoint_service.CreateIndexEndpointRequest): + request = index_endpoint_service.CreateIndexEndpointRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if index_endpoint is not None: + request.index_endpoint = index_endpoint + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_index_endpoint] + + # 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, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + gca_index_endpoint.IndexEndpoint, + metadata_type=index_endpoint_service.CreateIndexEndpointOperationMetadata, + ) + + # Done; return the response. + return response + + def get_index_endpoint( + self, + request: Union[index_endpoint_service.GetIndexEndpointRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> index_endpoint.IndexEndpoint: + r"""Gets an IndexEndpoint. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_get_index_endpoint(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetIndexEndpointRequest( + name="name_value", + ) + + # Make the request + response = client.get_index_endpoint(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetIndexEndpointRequest, dict]): + The request object. Request message for + [IndexEndpointService.GetIndexEndpoint][google.cloud.aiplatform.v1.IndexEndpointService.GetIndexEndpoint] + name (str): + Required. The name of the IndexEndpoint resource. + Format: + ``projects/{project}/locations/{location}/indexEndpoints/{index_endpoint}`` + + 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: + google.cloud.aiplatform_v1.types.IndexEndpoint: + Indexes are deployed into it. An + IndexEndpoint can have multiple + DeployedIndexes. + + """ + # Create or coerce a protobuf request object. + # Quick 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 index_endpoint_service.GetIndexEndpointRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, index_endpoint_service.GetIndexEndpointRequest): + request = index_endpoint_service.GetIndexEndpointRequest(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_index_endpoint] + + # 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 list_index_endpoints( + self, + request: Union[index_endpoint_service.ListIndexEndpointsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListIndexEndpointsPager: + r"""Lists IndexEndpoints in a Location. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_list_index_endpoints(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListIndexEndpointsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_index_endpoints(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListIndexEndpointsRequest, dict]): + The request object. Request message for + [IndexEndpointService.ListIndexEndpoints][google.cloud.aiplatform.v1.IndexEndpointService.ListIndexEndpoints]. + parent (str): + Required. The resource name of the Location from which + to list the IndexEndpoints. Format: + ``projects/{project}/locations/{location}`` + + 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: + google.cloud.aiplatform_v1.services.index_endpoint_service.pagers.ListIndexEndpointsPager: + Response message for + [IndexEndpointService.ListIndexEndpoints][google.cloud.aiplatform.v1.IndexEndpointService.ListIndexEndpoints]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 index_endpoint_service.ListIndexEndpointsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, index_endpoint_service.ListIndexEndpointsRequest): + request = index_endpoint_service.ListIndexEndpointsRequest(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_index_endpoints] + + # 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.ListIndexEndpointsPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def update_index_endpoint( + self, + request: Union[index_endpoint_service.UpdateIndexEndpointRequest, dict] = None, + *, + index_endpoint: gca_index_endpoint.IndexEndpoint = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_index_endpoint.IndexEndpoint: + r"""Updates an IndexEndpoint. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_update_index_endpoint(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceClient() + + # Initialize request argument(s) + index_endpoint = aiplatform_v1.IndexEndpoint() + index_endpoint.display_name = "display_name_value" + + request = aiplatform_v1.UpdateIndexEndpointRequest( + index_endpoint=index_endpoint, + ) + + # Make the request + response = client.update_index_endpoint(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.UpdateIndexEndpointRequest, dict]): + The request object. Request message for + [IndexEndpointService.UpdateIndexEndpoint][google.cloud.aiplatform.v1.IndexEndpointService.UpdateIndexEndpoint]. + index_endpoint (google.cloud.aiplatform_v1.types.IndexEndpoint): + Required. The IndexEndpoint which + replaces the resource on the server. + + This corresponds to the ``index_endpoint`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Required. The update mask applies to the resource. See + [google.protobuf.FieldMask][google.protobuf.FieldMask]. + + 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: + google.cloud.aiplatform_v1.types.IndexEndpoint: + Indexes are deployed into it. An + IndexEndpoint can have multiple + DeployedIndexes. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([index_endpoint, 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 index_endpoint_service.UpdateIndexEndpointRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, index_endpoint_service.UpdateIndexEndpointRequest): + request = index_endpoint_service.UpdateIndexEndpointRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if index_endpoint is not None: + request.index_endpoint = index_endpoint + 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_index_endpoint] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("index_endpoint.name", request.index_endpoint.name),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_index_endpoint( + self, + request: Union[index_endpoint_service.DeleteIndexEndpointRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Deletes an IndexEndpoint. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_delete_index_endpoint(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteIndexEndpointRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_index_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.DeleteIndexEndpointRequest, dict]): + The request object. Request message for + [IndexEndpointService.DeleteIndexEndpoint][google.cloud.aiplatform.v1.IndexEndpointService.DeleteIndexEndpoint]. + name (str): + Required. The name of the IndexEndpoint resource to be + deleted. Format: + ``projects/{project}/locations/{location}/indexEndpoints/{index_endpoint}`` + + 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # Create or coerce a protobuf request object. + # Quick 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 index_endpoint_service.DeleteIndexEndpointRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, index_endpoint_service.DeleteIndexEndpointRequest): + request = index_endpoint_service.DeleteIndexEndpointRequest(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_index_endpoint] + + # 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, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, + ) + + # Done; return the response. + return response + + def deploy_index( + self, + request: Union[index_endpoint_service.DeployIndexRequest, dict] = None, + *, + index_endpoint: str = None, + deployed_index: gca_index_endpoint.DeployedIndex = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Deploys an Index into this IndexEndpoint, creating a + DeployedIndex within it. + Only non-empty Indexes can be deployed. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_deploy_index(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceClient() + + # Initialize request argument(s) + deployed_index = aiplatform_v1.DeployedIndex() + deployed_index.id = "id_value" + deployed_index.index = "index_value" + + request = aiplatform_v1.DeployIndexRequest( + index_endpoint="index_endpoint_value", + deployed_index=deployed_index, + ) + + # Make the request + operation = client.deploy_index(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.DeployIndexRequest, dict]): + The request object. Request message for + [IndexEndpointService.DeployIndex][google.cloud.aiplatform.v1.IndexEndpointService.DeployIndex]. + index_endpoint (str): + Required. The name of the IndexEndpoint resource into + which to deploy an Index. Format: + ``projects/{project}/locations/{location}/indexEndpoints/{index_endpoint}`` + + This corresponds to the ``index_endpoint`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + deployed_index (google.cloud.aiplatform_v1.types.DeployedIndex): + Required. The DeployedIndex to be + created within the IndexEndpoint. + + This corresponds to the ``deployed_index`` 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.aiplatform_v1.types.DeployIndexResponse` + Response message for + [IndexEndpointService.DeployIndex][google.cloud.aiplatform.v1.IndexEndpointService.DeployIndex]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([index_endpoint, deployed_index]) + 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 index_endpoint_service.DeployIndexRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, index_endpoint_service.DeployIndexRequest): + request = index_endpoint_service.DeployIndexRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if index_endpoint is not None: + request.index_endpoint = index_endpoint + if deployed_index is not None: + request.deployed_index = deployed_index + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.deploy_index] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("index_endpoint", request.index_endpoint),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + index_endpoint_service.DeployIndexResponse, + metadata_type=index_endpoint_service.DeployIndexOperationMetadata, + ) + + # Done; return the response. + return response + + def undeploy_index( + self, + request: Union[index_endpoint_service.UndeployIndexRequest, dict] = None, + *, + index_endpoint: str = None, + deployed_index_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Undeploys an Index from an IndexEndpoint, removing a + DeployedIndex from it, and freeing all resources it's + using. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_undeploy_index(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.UndeployIndexRequest( + index_endpoint="index_endpoint_value", + deployed_index_id="deployed_index_id_value", + ) + + # Make the request + operation = client.undeploy_index(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.UndeployIndexRequest, dict]): + The request object. Request message for + [IndexEndpointService.UndeployIndex][google.cloud.aiplatform.v1.IndexEndpointService.UndeployIndex]. + index_endpoint (str): + Required. The name of the IndexEndpoint resource from + which to undeploy an Index. Format: + ``projects/{project}/locations/{location}/indexEndpoints/{index_endpoint}`` + + This corresponds to the ``index_endpoint`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + deployed_index_id (str): + Required. The ID of the DeployedIndex + to be undeployed from the IndexEndpoint. + + This corresponds to the ``deployed_index_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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.aiplatform_v1.types.UndeployIndexResponse` + Response message for + [IndexEndpointService.UndeployIndex][google.cloud.aiplatform.v1.IndexEndpointService.UndeployIndex]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([index_endpoint, deployed_index_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 index_endpoint_service.UndeployIndexRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, index_endpoint_service.UndeployIndexRequest): + request = index_endpoint_service.UndeployIndexRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if index_endpoint is not None: + request.index_endpoint = index_endpoint + if deployed_index_id is not None: + request.deployed_index_id = deployed_index_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.undeploy_index] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("index_endpoint", request.index_endpoint),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + index_endpoint_service.UndeployIndexResponse, + metadata_type=index_endpoint_service.UndeployIndexOperationMetadata, + ) + + # Done; return the response. + return response + + def mutate_deployed_index( + self, + request: Union[index_endpoint_service.MutateDeployedIndexRequest, dict] = None, + *, + index_endpoint: str = None, + deployed_index: gca_index_endpoint.DeployedIndex = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Update an existing DeployedIndex under an + IndexEndpoint. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_mutate_deployed_index(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceClient() + + # Initialize request argument(s) + deployed_index = aiplatform_v1.DeployedIndex() + deployed_index.id = "id_value" + deployed_index.index = "index_value" + + request = aiplatform_v1.MutateDeployedIndexRequest( + index_endpoint="index_endpoint_value", + deployed_index=deployed_index, + ) + + # Make the request + operation = client.mutate_deployed_index(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.MutateDeployedIndexRequest, dict]): + The request object. Request message for + [IndexEndpointService.MutateDeployedIndex][google.cloud.aiplatform.v1.IndexEndpointService.MutateDeployedIndex]. + index_endpoint (str): + Required. The name of the IndexEndpoint resource into + which to deploy an Index. Format: + ``projects/{project}/locations/{location}/indexEndpoints/{index_endpoint}`` + + This corresponds to the ``index_endpoint`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + deployed_index (google.cloud.aiplatform_v1.types.DeployedIndex): + Required. The DeployedIndex to be updated within the + IndexEndpoint. Currently, the updatable fields are + [DeployedIndex][automatic_resources] and + [DeployedIndex][dedicated_resources] + + This corresponds to the ``deployed_index`` 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.aiplatform_v1.types.MutateDeployedIndexResponse` + Response message for + [IndexEndpointService.MutateDeployedIndex][google.cloud.aiplatform.v1.IndexEndpointService.MutateDeployedIndex]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([index_endpoint, deployed_index]) + 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 index_endpoint_service.MutateDeployedIndexRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, index_endpoint_service.MutateDeployedIndexRequest): + request = index_endpoint_service.MutateDeployedIndexRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if index_endpoint is not None: + request.index_endpoint = index_endpoint + if deployed_index is not None: + request.deployed_index = deployed_index + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.mutate_deployed_index] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("index_endpoint", request.index_endpoint),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + index_endpoint_service.MutateDeployedIndexResponse, + metadata_type=index_endpoint_service.MutateDeployedIndexOperationMetadata, + ) + + # Done; return the response. + return response + + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_operations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.delete_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.wait_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_location, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_locations, + default_timeout=None, + 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 = 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-aiplatform", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ("IndexEndpointServiceClient",) diff --git a/google/cloud/aiplatform_v1/services/index_endpoint_service/pagers.py b/google/cloud/aiplatform_v1/services/index_endpoint_service/pagers.py new file mode 100644 index 0000000000..eab1c5f503 --- /dev/null +++ b/google/cloud/aiplatform_v1/services/index_endpoint_service/pagers.py @@ -0,0 +1,160 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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 typing import ( + Any, + AsyncIterator, + Awaitable, + Callable, + Sequence, + Tuple, + Optional, + Iterator, +) + +from google.cloud.aiplatform_v1.types import index_endpoint +from google.cloud.aiplatform_v1.types import index_endpoint_service + + +class ListIndexEndpointsPager: + """A pager for iterating through ``list_index_endpoints`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListIndexEndpointsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``index_endpoints`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListIndexEndpoints`` requests and continue to iterate + through the ``index_endpoints`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListIndexEndpointsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., index_endpoint_service.ListIndexEndpointsResponse], + request: index_endpoint_service.ListIndexEndpointsRequest, + response: index_endpoint_service.ListIndexEndpointsResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListIndexEndpointsRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListIndexEndpointsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = index_endpoint_service.ListIndexEndpointsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[index_endpoint_service.ListIndexEndpointsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterator[index_endpoint.IndexEndpoint]: + for page in self.pages: + yield from page.index_endpoints + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListIndexEndpointsAsyncPager: + """A pager for iterating through ``list_index_endpoints`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListIndexEndpointsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``index_endpoints`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListIndexEndpoints`` requests and continue to iterate + through the ``index_endpoints`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListIndexEndpointsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[ + ..., Awaitable[index_endpoint_service.ListIndexEndpointsResponse] + ], + request: index_endpoint_service.ListIndexEndpointsRequest, + response: index_endpoint_service.ListIndexEndpointsResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListIndexEndpointsRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListIndexEndpointsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = index_endpoint_service.ListIndexEndpointsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages( + self, + ) -> AsyncIterator[index_endpoint_service.ListIndexEndpointsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + + def __aiter__(self) -> AsyncIterator[index_endpoint.IndexEndpoint]: + async def async_generator(): + async for page in self.pages: + for response in page.index_endpoints: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) diff --git a/google/cloud/aiplatform_v1/services/index_endpoint_service/transports/__init__.py b/google/cloud/aiplatform_v1/services/index_endpoint_service/transports/__init__.py new file mode 100644 index 0000000000..d41c1630fb --- /dev/null +++ b/google/cloud/aiplatform_v1/services/index_endpoint_service/transports/__init__.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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 typing import Dict, Type + +from .base import IndexEndpointServiceTransport +from .grpc import IndexEndpointServiceGrpcTransport +from .grpc_asyncio import IndexEndpointServiceGrpcAsyncIOTransport + + +# Compile a registry of transports. +_transport_registry = ( + OrderedDict() +) # type: Dict[str, Type[IndexEndpointServiceTransport]] +_transport_registry["grpc"] = IndexEndpointServiceGrpcTransport +_transport_registry["grpc_asyncio"] = IndexEndpointServiceGrpcAsyncIOTransport + +__all__ = ( + "IndexEndpointServiceTransport", + "IndexEndpointServiceGrpcTransport", + "IndexEndpointServiceGrpcAsyncIOTransport", +) diff --git a/google/cloud/aiplatform_v1/services/index_endpoint_service/transports/base.py b/google/cloud/aiplatform_v1/services/index_endpoint_service/transports/base.py new file mode 100644 index 0000000000..245bc90893 --- /dev/null +++ b/google/cloud/aiplatform_v1/services/index_endpoint_service/transports/base.py @@ -0,0 +1,364 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import abc +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +import pkg_resources + +import google.auth # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import operations_v1 +from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore + +from google.cloud.aiplatform_v1.types import index_endpoint +from google.cloud.aiplatform_v1.types import index_endpoint as gca_index_endpoint +from google.cloud.aiplatform_v1.types import index_endpoint_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.longrunning import operations_pb2 # type: ignore + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-aiplatform", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +class IndexEndpointServiceTransport(abc.ABC): + """Abstract transport class for IndexEndpointService.""" + + AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) + + DEFAULT_HOST: str = "aiplatform.googleapis.com" + + def __init__( + self, + *, + host: str = DEFAULT_HOST, + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + **kwargs, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + 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. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is mutually exclusive with credentials. + scopes (Optional[Sequence[str]]): A list of scopes. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + 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. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + """ + + # Save the hostname. Default to port 443 (HTTPS) if none is specified. + if ":" not in host: + host += ":443" + self._host = host + + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} + + # Save the scopes. + self._scopes = scopes + + # If no credentials are provided, then determine the appropriate + # defaults. + if credentials and credentials_file: + raise core_exceptions.DuplicateCredentialArgs( + "'credentials_file' and 'credentials' are mutually exclusive" + ) + + if credentials_file is not None: + credentials, _ = google.auth.load_credentials_from_file( + credentials_file, **scopes_kwargs, quota_project_id=quota_project_id + ) + elif credentials is None: + credentials, _ = google.auth.default( + **scopes_kwargs, quota_project_id=quota_project_id + ) + + # If the credentials are service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + + # Save the credentials. + self._credentials = credentials + + def _prep_wrapped_messages(self, client_info): + # Precompute the wrapped methods. + self._wrapped_methods = { + self.create_index_endpoint: gapic_v1.method.wrap_method( + self.create_index_endpoint, + default_timeout=None, + client_info=client_info, + ), + self.get_index_endpoint: gapic_v1.method.wrap_method( + self.get_index_endpoint, + default_timeout=None, + client_info=client_info, + ), + self.list_index_endpoints: gapic_v1.method.wrap_method( + self.list_index_endpoints, + default_timeout=None, + client_info=client_info, + ), + self.update_index_endpoint: gapic_v1.method.wrap_method( + self.update_index_endpoint, + default_timeout=None, + client_info=client_info, + ), + self.delete_index_endpoint: gapic_v1.method.wrap_method( + self.delete_index_endpoint, + default_timeout=None, + client_info=client_info, + ), + self.deploy_index: gapic_v1.method.wrap_method( + self.deploy_index, + default_timeout=None, + client_info=client_info, + ), + self.undeploy_index: gapic_v1.method.wrap_method( + self.undeploy_index, + default_timeout=None, + client_info=client_info, + ), + self.mutate_deployed_index: gapic_v1.method.wrap_method( + self.mutate_deployed_index, + default_timeout=None, + client_info=client_info, + ), + } + + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + + @property + def operations_client(self): + """Return the client designed to process long-running operations.""" + raise NotImplementedError() + + @property + def create_index_endpoint( + self, + ) -> Callable[ + [index_endpoint_service.CreateIndexEndpointRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def get_index_endpoint( + self, + ) -> Callable[ + [index_endpoint_service.GetIndexEndpointRequest], + Union[index_endpoint.IndexEndpoint, Awaitable[index_endpoint.IndexEndpoint]], + ]: + raise NotImplementedError() + + @property + def list_index_endpoints( + self, + ) -> Callable[ + [index_endpoint_service.ListIndexEndpointsRequest], + Union[ + index_endpoint_service.ListIndexEndpointsResponse, + Awaitable[index_endpoint_service.ListIndexEndpointsResponse], + ], + ]: + raise NotImplementedError() + + @property + def update_index_endpoint( + self, + ) -> Callable[ + [index_endpoint_service.UpdateIndexEndpointRequest], + Union[ + gca_index_endpoint.IndexEndpoint, + Awaitable[gca_index_endpoint.IndexEndpoint], + ], + ]: + raise NotImplementedError() + + @property + def delete_index_endpoint( + self, + ) -> Callable[ + [index_endpoint_service.DeleteIndexEndpointRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def deploy_index( + self, + ) -> Callable[ + [index_endpoint_service.DeployIndexRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def undeploy_index( + self, + ) -> Callable[ + [index_endpoint_service.UndeployIndexRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def mutate_deployed_index( + self, + ) -> Callable[ + [index_endpoint_service.MutateDeployedIndexRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], + Union[ + operations_pb2.ListOperationsResponse, + Awaitable[operations_pb2.ListOperationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None,]: + raise NotImplementedError() + + @property + def wait_operation( + self, + ) -> Callable[ + [operations_pb2.WaitOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def set_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def get_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_location( + self, + ) -> Callable[ + [locations_pb2.GetLocationRequest], + Union[locations_pb2.Location, Awaitable[locations_pb2.Location]], + ]: + raise NotImplementedError() + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], + Union[ + locations_pb2.ListLocationsResponse, + Awaitable[locations_pb2.ListLocationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + + +__all__ = ("IndexEndpointServiceTransport",) diff --git a/google/cloud/aiplatform_v1/services/index_endpoint_service/transports/grpc.py b/google/cloud/aiplatform_v1/services/index_endpoint_service/transports/grpc.py new file mode 100644 index 0000000000..156cf9cf73 --- /dev/null +++ b/google/cloud/aiplatform_v1/services/index_endpoint_service/transports/grpc.py @@ -0,0 +1,695 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import warnings +from typing import Callable, Dict, Optional, Sequence, Tuple, Union + +from google.api_core import grpc_helpers +from google.api_core import operations_v1 +from google.api_core import gapic_v1 +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore + +import grpc # type: ignore + +from google.cloud.aiplatform_v1.types import index_endpoint +from google.cloud.aiplatform_v1.types import index_endpoint as gca_index_endpoint +from google.cloud.aiplatform_v1.types import index_endpoint_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.longrunning import operations_pb2 # type: ignore +from .base import IndexEndpointServiceTransport, DEFAULT_CLIENT_INFO + + +class IndexEndpointServiceGrpcTransport(IndexEndpointServiceTransport): + """gRPC backend transport for IndexEndpointService. + + A service for managing Vertex AI's IndexEndpoints. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + + _stubs: Dict[str, Callable] + + def __init__( + self, + *, + host: str = "aiplatform.googleapis.com", + credentials: ga_credentials.Credentials = None, + credentials_file: str = None, + scopes: Sequence[str] = None, + channel: grpc.Channel = None, + api_mtls_endpoint: str = None, + client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, + ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + 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. + This argument is ignored if ``channel`` is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional(Sequence[str])): A list of scopes. This argument is + ignored if ``channel`` is provided. + channel (Optional[grpc.Channel]): A ``Channel`` instance through + which to make calls. + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or application default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for the grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure a mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + 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. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + self._grpc_channel = None + self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client: Optional[operations_v1.OperationsClient] = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + + if channel: + # Ignore credentials if a channel was passed. + credentials = False + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + self._ssl_channel_credentials = None + + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials + + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + ) + + if not self._grpc_channel: + self._grpc_channel = type(self).create_channel( + self._host, + # use the credentials which are saved + credentials=self._credentials, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, + quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) + + @classmethod + def create_channel( + cls, + host: str = "aiplatform.googleapis.com", + credentials: ga_credentials.Credentials = None, + credentials_file: str = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs, + ) -> grpc.Channel: + """Create and return a gRPC channel object. + Args: + host (Optional[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is mutually exclusive with credentials. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + grpc.Channel: A gRPC channel object. + + Raises: + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + + return grpc_helpers.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + quota_project_id=quota_project_id, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, + **kwargs, + ) + + @property + def grpc_channel(self) -> grpc.Channel: + """Return the channel designed to connect to this service.""" + return self._grpc_channel + + @property + def operations_client(self) -> operations_v1.OperationsClient: + """Create the client designed to process long-running operations. + + This property caches on the instance; repeated calls return the same + client. + """ + # Quick check: Only create a new client if we do not already have one. + if self._operations_client is None: + self._operations_client = operations_v1.OperationsClient(self.grpc_channel) + + # Return the client from cache. + return self._operations_client + + @property + def create_index_endpoint( + self, + ) -> Callable[ + [index_endpoint_service.CreateIndexEndpointRequest], operations_pb2.Operation + ]: + r"""Return a callable for the create index endpoint method over gRPC. + + Creates an IndexEndpoint. + + Returns: + Callable[[~.CreateIndexEndpointRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_index_endpoint" not in self._stubs: + self._stubs["create_index_endpoint"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.IndexEndpointService/CreateIndexEndpoint", + request_serializer=index_endpoint_service.CreateIndexEndpointRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["create_index_endpoint"] + + @property + def get_index_endpoint( + self, + ) -> Callable[ + [index_endpoint_service.GetIndexEndpointRequest], index_endpoint.IndexEndpoint + ]: + r"""Return a callable for the get index endpoint method over gRPC. + + Gets an IndexEndpoint. + + Returns: + Callable[[~.GetIndexEndpointRequest], + ~.IndexEndpoint]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_index_endpoint" not in self._stubs: + self._stubs["get_index_endpoint"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.IndexEndpointService/GetIndexEndpoint", + request_serializer=index_endpoint_service.GetIndexEndpointRequest.serialize, + response_deserializer=index_endpoint.IndexEndpoint.deserialize, + ) + return self._stubs["get_index_endpoint"] + + @property + def list_index_endpoints( + self, + ) -> Callable[ + [index_endpoint_service.ListIndexEndpointsRequest], + index_endpoint_service.ListIndexEndpointsResponse, + ]: + r"""Return a callable for the list index endpoints method over gRPC. + + Lists IndexEndpoints in a Location. + + Returns: + Callable[[~.ListIndexEndpointsRequest], + ~.ListIndexEndpointsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_index_endpoints" not in self._stubs: + self._stubs["list_index_endpoints"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.IndexEndpointService/ListIndexEndpoints", + request_serializer=index_endpoint_service.ListIndexEndpointsRequest.serialize, + response_deserializer=index_endpoint_service.ListIndexEndpointsResponse.deserialize, + ) + return self._stubs["list_index_endpoints"] + + @property + def update_index_endpoint( + self, + ) -> Callable[ + [index_endpoint_service.UpdateIndexEndpointRequest], + gca_index_endpoint.IndexEndpoint, + ]: + r"""Return a callable for the update index endpoint method over gRPC. + + Updates an IndexEndpoint. + + Returns: + Callable[[~.UpdateIndexEndpointRequest], + ~.IndexEndpoint]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_index_endpoint" not in self._stubs: + self._stubs["update_index_endpoint"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.IndexEndpointService/UpdateIndexEndpoint", + request_serializer=index_endpoint_service.UpdateIndexEndpointRequest.serialize, + response_deserializer=gca_index_endpoint.IndexEndpoint.deserialize, + ) + return self._stubs["update_index_endpoint"] + + @property + def delete_index_endpoint( + self, + ) -> Callable[ + [index_endpoint_service.DeleteIndexEndpointRequest], operations_pb2.Operation + ]: + r"""Return a callable for the delete index endpoint method over gRPC. + + Deletes an IndexEndpoint. + + Returns: + Callable[[~.DeleteIndexEndpointRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_index_endpoint" not in self._stubs: + self._stubs["delete_index_endpoint"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.IndexEndpointService/DeleteIndexEndpoint", + request_serializer=index_endpoint_service.DeleteIndexEndpointRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_index_endpoint"] + + @property + def deploy_index( + self, + ) -> Callable[ + [index_endpoint_service.DeployIndexRequest], operations_pb2.Operation + ]: + r"""Return a callable for the deploy index method over gRPC. + + Deploys an Index into this IndexEndpoint, creating a + DeployedIndex within it. + Only non-empty Indexes can be deployed. + + Returns: + Callable[[~.DeployIndexRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "deploy_index" not in self._stubs: + self._stubs["deploy_index"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.IndexEndpointService/DeployIndex", + request_serializer=index_endpoint_service.DeployIndexRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["deploy_index"] + + @property + def undeploy_index( + self, + ) -> Callable[ + [index_endpoint_service.UndeployIndexRequest], operations_pb2.Operation + ]: + r"""Return a callable for the undeploy index method over gRPC. + + Undeploys an Index from an IndexEndpoint, removing a + DeployedIndex from it, and freeing all resources it's + using. + + Returns: + Callable[[~.UndeployIndexRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "undeploy_index" not in self._stubs: + self._stubs["undeploy_index"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.IndexEndpointService/UndeployIndex", + request_serializer=index_endpoint_service.UndeployIndexRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["undeploy_index"] + + @property + def mutate_deployed_index( + self, + ) -> Callable[ + [index_endpoint_service.MutateDeployedIndexRequest], operations_pb2.Operation + ]: + r"""Return a callable for the mutate deployed index method over gRPC. + + Update an existing DeployedIndex under an + IndexEndpoint. + + Returns: + Callable[[~.MutateDeployedIndexRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "mutate_deployed_index" not in self._stubs: + self._stubs["mutate_deployed_index"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.IndexEndpointService/MutateDeployedIndex", + request_serializer=index_endpoint_service.MutateDeployedIndexRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["mutate_deployed_index"] + + def close(self): + self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + @property + def kind(self) -> str: + return "grpc" + + +__all__ = ("IndexEndpointServiceGrpcTransport",) diff --git a/google/cloud/aiplatform_v1/services/index_endpoint_service/transports/grpc_asyncio.py b/google/cloud/aiplatform_v1/services/index_endpoint_service/transports/grpc_asyncio.py new file mode 100644 index 0000000000..8476b32504 --- /dev/null +++ b/google/cloud/aiplatform_v1/services/index_endpoint_service/transports/grpc_asyncio.py @@ -0,0 +1,701 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import warnings +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union + +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import operations_v1 +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore + +import grpc # type: ignore +from grpc.experimental import aio # type: ignore + +from google.cloud.aiplatform_v1.types import index_endpoint +from google.cloud.aiplatform_v1.types import index_endpoint as gca_index_endpoint +from google.cloud.aiplatform_v1.types import index_endpoint_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.longrunning import operations_pb2 # type: ignore +from .base import IndexEndpointServiceTransport, DEFAULT_CLIENT_INFO +from .grpc import IndexEndpointServiceGrpcTransport + + +class IndexEndpointServiceGrpcAsyncIOTransport(IndexEndpointServiceTransport): + """gRPC AsyncIO backend transport for IndexEndpointService. + + A service for managing Vertex AI's IndexEndpoints. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + + _grpc_channel: aio.Channel + _stubs: Dict[str, Callable] = {} + + @classmethod + def create_channel( + cls, + host: str = "aiplatform.googleapis.com", + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs, + ) -> aio.Channel: + """Create and return a gRPC AsyncIO channel object. + Args: + host (Optional[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + aio.Channel: A gRPC AsyncIO channel object. + """ + + return grpc_helpers_async.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + quota_project_id=quota_project_id, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, + **kwargs, + ) + + def __init__( + self, + *, + host: str = "aiplatform.googleapis.com", + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: aio.Channel = None, + api_mtls_endpoint: str = None, + client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, + ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, + quota_project_id=None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + 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. + This argument is ignored if ``channel`` is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + channel (Optional[aio.Channel]): A ``Channel`` instance through + which to make calls. + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or application default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for the grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure a mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + 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. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + + Raises: + google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + self._grpc_channel = None + self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + + if channel: + # Ignore credentials if a channel was passed. + credentials = False + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + self._ssl_channel_credentials = None + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials + + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + ) + + if not self._grpc_channel: + self._grpc_channel = type(self).create_channel( + self._host, + # use the credentials which are saved + credentials=self._credentials, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, + quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) + + @property + def grpc_channel(self) -> aio.Channel: + """Create the channel designed to connect to this service. + + This property caches on the instance; repeated calls return + the same channel. + """ + # Return the channel from cache. + return self._grpc_channel + + @property + def operations_client(self) -> operations_v1.OperationsAsyncClient: + """Create the client designed to process long-running operations. + + This property caches on the instance; repeated calls return the same + client. + """ + # Quick check: Only create a new client if we do not already have one. + if self._operations_client is None: + self._operations_client = operations_v1.OperationsAsyncClient( + self.grpc_channel + ) + + # Return the client from cache. + return self._operations_client + + @property + def create_index_endpoint( + self, + ) -> Callable[ + [index_endpoint_service.CreateIndexEndpointRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the create index endpoint method over gRPC. + + Creates an IndexEndpoint. + + Returns: + Callable[[~.CreateIndexEndpointRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_index_endpoint" not in self._stubs: + self._stubs["create_index_endpoint"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.IndexEndpointService/CreateIndexEndpoint", + request_serializer=index_endpoint_service.CreateIndexEndpointRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["create_index_endpoint"] + + @property + def get_index_endpoint( + self, + ) -> Callable[ + [index_endpoint_service.GetIndexEndpointRequest], + Awaitable[index_endpoint.IndexEndpoint], + ]: + r"""Return a callable for the get index endpoint method over gRPC. + + Gets an IndexEndpoint. + + Returns: + Callable[[~.GetIndexEndpointRequest], + Awaitable[~.IndexEndpoint]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_index_endpoint" not in self._stubs: + self._stubs["get_index_endpoint"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.IndexEndpointService/GetIndexEndpoint", + request_serializer=index_endpoint_service.GetIndexEndpointRequest.serialize, + response_deserializer=index_endpoint.IndexEndpoint.deserialize, + ) + return self._stubs["get_index_endpoint"] + + @property + def list_index_endpoints( + self, + ) -> Callable[ + [index_endpoint_service.ListIndexEndpointsRequest], + Awaitable[index_endpoint_service.ListIndexEndpointsResponse], + ]: + r"""Return a callable for the list index endpoints method over gRPC. + + Lists IndexEndpoints in a Location. + + Returns: + Callable[[~.ListIndexEndpointsRequest], + Awaitable[~.ListIndexEndpointsResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_index_endpoints" not in self._stubs: + self._stubs["list_index_endpoints"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.IndexEndpointService/ListIndexEndpoints", + request_serializer=index_endpoint_service.ListIndexEndpointsRequest.serialize, + response_deserializer=index_endpoint_service.ListIndexEndpointsResponse.deserialize, + ) + return self._stubs["list_index_endpoints"] + + @property + def update_index_endpoint( + self, + ) -> Callable[ + [index_endpoint_service.UpdateIndexEndpointRequest], + Awaitable[gca_index_endpoint.IndexEndpoint], + ]: + r"""Return a callable for the update index endpoint method over gRPC. + + Updates an IndexEndpoint. + + Returns: + Callable[[~.UpdateIndexEndpointRequest], + Awaitable[~.IndexEndpoint]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_index_endpoint" not in self._stubs: + self._stubs["update_index_endpoint"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.IndexEndpointService/UpdateIndexEndpoint", + request_serializer=index_endpoint_service.UpdateIndexEndpointRequest.serialize, + response_deserializer=gca_index_endpoint.IndexEndpoint.deserialize, + ) + return self._stubs["update_index_endpoint"] + + @property + def delete_index_endpoint( + self, + ) -> Callable[ + [index_endpoint_service.DeleteIndexEndpointRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the delete index endpoint method over gRPC. + + Deletes an IndexEndpoint. + + Returns: + Callable[[~.DeleteIndexEndpointRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_index_endpoint" not in self._stubs: + self._stubs["delete_index_endpoint"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.IndexEndpointService/DeleteIndexEndpoint", + request_serializer=index_endpoint_service.DeleteIndexEndpointRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_index_endpoint"] + + @property + def deploy_index( + self, + ) -> Callable[ + [index_endpoint_service.DeployIndexRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the deploy index method over gRPC. + + Deploys an Index into this IndexEndpoint, creating a + DeployedIndex within it. + Only non-empty Indexes can be deployed. + + Returns: + Callable[[~.DeployIndexRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "deploy_index" not in self._stubs: + self._stubs["deploy_index"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.IndexEndpointService/DeployIndex", + request_serializer=index_endpoint_service.DeployIndexRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["deploy_index"] + + @property + def undeploy_index( + self, + ) -> Callable[ + [index_endpoint_service.UndeployIndexRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the undeploy index method over gRPC. + + Undeploys an Index from an IndexEndpoint, removing a + DeployedIndex from it, and freeing all resources it's + using. + + Returns: + Callable[[~.UndeployIndexRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "undeploy_index" not in self._stubs: + self._stubs["undeploy_index"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.IndexEndpointService/UndeployIndex", + request_serializer=index_endpoint_service.UndeployIndexRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["undeploy_index"] + + @property + def mutate_deployed_index( + self, + ) -> Callable[ + [index_endpoint_service.MutateDeployedIndexRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the mutate deployed index method over gRPC. + + Update an existing DeployedIndex under an + IndexEndpoint. + + Returns: + Callable[[~.MutateDeployedIndexRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "mutate_deployed_index" not in self._stubs: + self._stubs["mutate_deployed_index"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.IndexEndpointService/MutateDeployedIndex", + request_serializer=index_endpoint_service.MutateDeployedIndexRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["mutate_deployed_index"] + + def close(self): + return self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + +__all__ = ("IndexEndpointServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/aiplatform_v1/services/index_service/__init__.py b/google/cloud/aiplatform_v1/services/index_service/__init__.py new file mode 100644 index 0000000000..a8323caaf7 --- /dev/null +++ b/google/cloud/aiplatform_v1/services/index_service/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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 .client import IndexServiceClient +from .async_client import IndexServiceAsyncClient + +__all__ = ( + "IndexServiceClient", + "IndexServiceAsyncClient", +) diff --git a/google/cloud/aiplatform_v1/services/index_service/async_client.py b/google/cloud/aiplatform_v1/services/index_service/async_client.py new file mode 100644 index 0000000000..6d40221fd9 --- /dev/null +++ b/google/cloud/aiplatform_v1/services/index_service/async_client.py @@ -0,0 +1,1487 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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, Mapping, Optional, Sequence, Tuple, Type, Union +import pkg_resources + +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore + +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + +from google.api_core import operation as gac_operation # type: ignore +from google.api_core import operation_async # type: ignore +from google.cloud.aiplatform_v1.services.index_service import pagers +from google.cloud.aiplatform_v1.types import deployed_index_ref +from google.cloud.aiplatform_v1.types import index +from google.cloud.aiplatform_v1.types import index as gca_index +from google.cloud.aiplatform_v1.types import index_service +from google.cloud.aiplatform_v1.types import operation as gca_operation +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import struct_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from .transports.base import IndexServiceTransport, DEFAULT_CLIENT_INFO +from .transports.grpc_asyncio import IndexServiceGrpcAsyncIOTransport +from .client import IndexServiceClient + + +class IndexServiceAsyncClient: + """A service for creating and managing Vertex AI's Index + resources. + """ + + _client: IndexServiceClient + + DEFAULT_ENDPOINT = IndexServiceClient.DEFAULT_ENDPOINT + DEFAULT_MTLS_ENDPOINT = IndexServiceClient.DEFAULT_MTLS_ENDPOINT + + index_path = staticmethod(IndexServiceClient.index_path) + parse_index_path = staticmethod(IndexServiceClient.parse_index_path) + index_endpoint_path = staticmethod(IndexServiceClient.index_endpoint_path) + parse_index_endpoint_path = staticmethod( + IndexServiceClient.parse_index_endpoint_path + ) + common_billing_account_path = staticmethod( + IndexServiceClient.common_billing_account_path + ) + parse_common_billing_account_path = staticmethod( + IndexServiceClient.parse_common_billing_account_path + ) + common_folder_path = staticmethod(IndexServiceClient.common_folder_path) + parse_common_folder_path = staticmethod(IndexServiceClient.parse_common_folder_path) + common_organization_path = staticmethod(IndexServiceClient.common_organization_path) + parse_common_organization_path = staticmethod( + IndexServiceClient.parse_common_organization_path + ) + common_project_path = staticmethod(IndexServiceClient.common_project_path) + parse_common_project_path = staticmethod( + IndexServiceClient.parse_common_project_path + ) + common_location_path = staticmethod(IndexServiceClient.common_location_path) + parse_common_location_path = staticmethod( + IndexServiceClient.parse_common_location_path + ) + + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials + info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + IndexServiceAsyncClient: The constructed client. + """ + return IndexServiceClient.from_service_account_info.__func__(IndexServiceAsyncClient, info, *args, **kwargs) # type: ignore + + @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: + IndexServiceAsyncClient: The constructed client. + """ + return IndexServiceClient.from_service_account_file.__func__(IndexServiceAsyncClient, filename, *args, **kwargs) # type: ignore + + from_service_account_json = from_service_account_file + + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return IndexServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + + @property + def transport(self) -> IndexServiceTransport: + """Returns the transport used by the client instance. + + Returns: + IndexServiceTransport: The transport used by the client instance. + """ + return self._client.transport + + get_transport_class = functools.partial( + type(IndexServiceClient).get_transport_class, type(IndexServiceClient) + ) + + def __init__( + self, + *, + credentials: ga_credentials.Credentials = None, + transport: Union[str, IndexServiceTransport] = "grpc_asyncio", + client_options: ClientOptions = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the index 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, ~.IndexServiceTransport]): 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 = IndexServiceClient( + credentials=credentials, + transport=transport, + client_options=client_options, + client_info=client_info, + ) + + async def create_index( + self, + request: Union[index_service.CreateIndexRequest, dict] = None, + *, + parent: str = None, + index: gca_index.Index = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Creates an Index. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_create_index(): + # Create a client + client = aiplatform_v1.IndexServiceAsyncClient() + + # Initialize request argument(s) + index = aiplatform_v1.Index() + index.display_name = "display_name_value" + + request = aiplatform_v1.CreateIndexRequest( + parent="parent_value", + index=index, + ) + + # Make the request + operation = client.create_index(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CreateIndexRequest, dict]): + The request object. Request message for + [IndexService.CreateIndex][google.cloud.aiplatform.v1.IndexService.CreateIndex]. + parent (:class:`str`): + Required. The resource name of the Location to create + the Index in. Format: + ``projects/{project}/locations/{location}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + index (:class:`google.cloud.aiplatform_v1.types.Index`): + Required. The Index to create. + This corresponds to the ``index`` 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.cloud.aiplatform_v1.types.Index` A representation of a collection of database items organized in a way that + allows for approximate nearest neighbor (a.k.a ANN) + algorithms search. + + """ + # Create or coerce a protobuf request object. + # Quick 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, index]) + 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 = index_service.CreateIndexRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if index is not None: + request.index = index + + # 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_index, + default_timeout=None, + 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, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + gca_index.Index, + metadata_type=index_service.CreateIndexOperationMetadata, + ) + + # Done; return the response. + return response + + async def get_index( + self, + request: Union[index_service.GetIndexRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> index.Index: + r"""Gets an Index. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_get_index(): + # Create a client + client = aiplatform_v1.IndexServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetIndexRequest( + name="name_value", + ) + + # Make the request + response = await client.get_index(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetIndexRequest, dict]): + The request object. Request message for + [IndexService.GetIndex][google.cloud.aiplatform.v1.IndexService.GetIndex] + name (:class:`str`): + Required. The name of the Index resource. Format: + ``projects/{project}/locations/{location}/indexes/{index}`` + + 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: + google.cloud.aiplatform_v1.types.Index: + A representation of a collection of + database items organized in a way that + allows for approximate nearest neighbor + (a.k.a ANN) algorithms search. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = index_service.GetIndexRequest(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_index, + default_timeout=None, + 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 list_indexes( + self, + request: Union[index_service.ListIndexesRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListIndexesAsyncPager: + r"""Lists Indexes in a Location. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_list_indexes(): + # Create a client + client = aiplatform_v1.IndexServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListIndexesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_indexes(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListIndexesRequest, dict]): + The request object. Request message for + [IndexService.ListIndexes][google.cloud.aiplatform.v1.IndexService.ListIndexes]. + parent (:class:`str`): + Required. The resource name of the Location from which + to list the Indexes. Format: + ``projects/{project}/locations/{location}`` + + 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: + google.cloud.aiplatform_v1.services.index_service.pagers.ListIndexesAsyncPager: + Response message for + [IndexService.ListIndexes][google.cloud.aiplatform.v1.IndexService.ListIndexes]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = index_service.ListIndexesRequest(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_indexes, + default_timeout=None, + 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.ListIndexesAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def update_index( + self, + request: Union[index_service.UpdateIndexRequest, dict] = None, + *, + index: gca_index.Index = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Updates an Index. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_update_index(): + # Create a client + client = aiplatform_v1.IndexServiceAsyncClient() + + # Initialize request argument(s) + index = aiplatform_v1.Index() + index.display_name = "display_name_value" + + request = aiplatform_v1.UpdateIndexRequest( + index=index, + ) + + # Make the request + operation = client.update_index(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.UpdateIndexRequest, dict]): + The request object. Request message for + [IndexService.UpdateIndex][google.cloud.aiplatform.v1.IndexService.UpdateIndex]. + index (:class:`google.cloud.aiplatform_v1.types.Index`): + Required. The Index which updates the + resource on the server. + + This corresponds to the ``index`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + The update mask applies to the resource. For the + ``FieldMask`` definition, see + [google.protobuf.FieldMask][google.protobuf.FieldMask]. + + 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.cloud.aiplatform_v1.types.Index` A representation of a collection of database items organized in a way that + allows for approximate nearest neighbor (a.k.a ANN) + algorithms search. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([index, 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 = index_service.UpdateIndexRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if index is not None: + request.index = index + 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_index, + default_timeout=None, + 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( + (("index.name", request.index.name),) + ), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + gca_index.Index, + metadata_type=index_service.UpdateIndexOperationMetadata, + ) + + # Done; return the response. + return response + + async def delete_index( + self, + request: Union[index_service.DeleteIndexRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Deletes an Index. An Index can only be deleted when all its + [DeployedIndexes][google.cloud.aiplatform.v1.Index.deployed_indexes] + had been undeployed. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_delete_index(): + # Create a client + client = aiplatform_v1.IndexServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteIndexRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_index(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.DeleteIndexRequest, dict]): + The request object. Request message for + [IndexService.DeleteIndex][google.cloud.aiplatform.v1.IndexService.DeleteIndex]. + name (:class:`str`): + Required. The name of the Index resource to be deleted. + Format: + ``projects/{project}/locations/{location}/indexes/{index}`` + + 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = index_service.DeleteIndexRequest(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_index, + default_timeout=None, + 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, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, + ) + + # Done; return the response. + return response + + async def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_operations, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.delete_operation, + default_timeout=None, + 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 cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + 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 wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.wait_operation, + default_timeout=None, + 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 set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_location, + default_timeout=None, + 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 list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_locations, + default_timeout=None, + 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 __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-aiplatform", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ("IndexServiceAsyncClient",) diff --git a/google/cloud/aiplatform_v1/services/index_service/client.py b/google/cloud/aiplatform_v1/services/index_service/client.py new file mode 100644 index 0000000000..e7fd6a83ed --- /dev/null +++ b/google/cloud/aiplatform_v1/services/index_service/client.py @@ -0,0 +1,1738 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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 os +import re +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union +import pkg_resources + +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.auth import credentials as ga_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 + +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + +from google.api_core import operation as gac_operation # type: ignore +from google.api_core import operation_async # type: ignore +from google.cloud.aiplatform_v1.services.index_service import pagers +from google.cloud.aiplatform_v1.types import deployed_index_ref +from google.cloud.aiplatform_v1.types import index +from google.cloud.aiplatform_v1.types import index as gca_index +from google.cloud.aiplatform_v1.types import index_service +from google.cloud.aiplatform_v1.types import operation as gca_operation +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import struct_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from .transports.base import IndexServiceTransport, DEFAULT_CLIENT_INFO +from .transports.grpc import IndexServiceGrpcTransport +from .transports.grpc_asyncio import IndexServiceGrpcAsyncIOTransport + + +class IndexServiceClientMeta(type): + """Metaclass for the IndexService 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[IndexServiceTransport]] + _transport_registry["grpc"] = IndexServiceGrpcTransport + _transport_registry["grpc_asyncio"] = IndexServiceGrpcAsyncIOTransport + + def get_transport_class( + cls, + label: str = None, + ) -> Type[IndexServiceTransport]: + """Returns 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 IndexServiceClient(metaclass=IndexServiceClientMeta): + """A service for creating and managing Vertex AI's Index + resources. + """ + + @staticmethod + def _get_default_mtls_endpoint(api_endpoint): + """Converts 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 = "aiplatform.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials + info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + IndexServiceClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + + @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: + IndexServiceClient: 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) -> IndexServiceTransport: + """Returns the transport used by the client instance. + + Returns: + IndexServiceTransport: The transport used by the client + instance. + """ + return self._transport + + @staticmethod + def index_path( + project: str, + location: str, + index: str, + ) -> str: + """Returns a fully-qualified index string.""" + return "projects/{project}/locations/{location}/indexes/{index}".format( + project=project, + location=location, + index=index, + ) + + @staticmethod + def parse_index_path(path: str) -> Dict[str, str]: + """Parses a index path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/indexes/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def index_endpoint_path( + project: str, + location: str, + index_endpoint: str, + ) -> str: + """Returns a fully-qualified index_endpoint string.""" + return "projects/{project}/locations/{location}/indexEndpoints/{index_endpoint}".format( + project=project, + location=location, + index_endpoint=index_endpoint, + ) + + @staticmethod + def parse_index_endpoint_path(path: str) -> Dict[str, str]: + """Parses a index_endpoint path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/indexEndpoints/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def common_billing_account_path( + billing_account: str, + ) -> str: + """Returns 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: + """Returns 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: + """Returns 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: + """Returns 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: + """Returns 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 {} + + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + + def __init__( + self, + *, + credentials: Optional[ga_credentials.Credentials] = None, + transport: Union[str, IndexServiceTransport, None] = None, + client_options: Optional[client_options_lib.ClientOptions] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the index 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, IndexServiceTransport]): The + transport to use. If set to None, a transport is chosen + automatically. + client_options (google.api_core.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. + 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() + + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options + ) + + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) + + # 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, IndexServiceTransport): + # transport is a IndexServiceTransport instance. + if credentials or client_options.credentials_file or api_key_value: + 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: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + + 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, + client_cert_source_for_mtls=client_cert_source_func, + quota_project_id=client_options.quota_project_id, + client_info=client_info, + always_use_jwt_access=True, + ) + + def create_index( + self, + request: Union[index_service.CreateIndexRequest, dict] = None, + *, + parent: str = None, + index: gca_index.Index = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Creates an Index. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_create_index(): + # Create a client + client = aiplatform_v1.IndexServiceClient() + + # Initialize request argument(s) + index = aiplatform_v1.Index() + index.display_name = "display_name_value" + + request = aiplatform_v1.CreateIndexRequest( + parent="parent_value", + index=index, + ) + + # Make the request + operation = client.create_index(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CreateIndexRequest, dict]): + The request object. Request message for + [IndexService.CreateIndex][google.cloud.aiplatform.v1.IndexService.CreateIndex]. + parent (str): + Required. The resource name of the Location to create + the Index in. Format: + ``projects/{project}/locations/{location}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + index (google.cloud.aiplatform_v1.types.Index): + Required. The Index to create. + This corresponds to the ``index`` 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.cloud.aiplatform_v1.types.Index` A representation of a collection of database items organized in a way that + allows for approximate nearest neighbor (a.k.a ANN) + algorithms search. + + """ + # Create or coerce a protobuf request object. + # Quick 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, index]) + 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 index_service.CreateIndexRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, index_service.CreateIndexRequest): + request = index_service.CreateIndexRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if index is not None: + request.index = index + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_index] + + # 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, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + gca_index.Index, + metadata_type=index_service.CreateIndexOperationMetadata, + ) + + # Done; return the response. + return response + + def get_index( + self, + request: Union[index_service.GetIndexRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> index.Index: + r"""Gets an Index. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_get_index(): + # Create a client + client = aiplatform_v1.IndexServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetIndexRequest( + name="name_value", + ) + + # Make the request + response = client.get_index(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetIndexRequest, dict]): + The request object. Request message for + [IndexService.GetIndex][google.cloud.aiplatform.v1.IndexService.GetIndex] + name (str): + Required. The name of the Index resource. Format: + ``projects/{project}/locations/{location}/indexes/{index}`` + + 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: + google.cloud.aiplatform_v1.types.Index: + A representation of a collection of + database items organized in a way that + allows for approximate nearest neighbor + (a.k.a ANN) algorithms search. + + """ + # Create or coerce a protobuf request object. + # Quick 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 index_service.GetIndexRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, index_service.GetIndexRequest): + request = index_service.GetIndexRequest(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_index] + + # 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 list_indexes( + self, + request: Union[index_service.ListIndexesRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListIndexesPager: + r"""Lists Indexes in a Location. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_list_indexes(): + # Create a client + client = aiplatform_v1.IndexServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListIndexesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_indexes(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListIndexesRequest, dict]): + The request object. Request message for + [IndexService.ListIndexes][google.cloud.aiplatform.v1.IndexService.ListIndexes]. + parent (str): + Required. The resource name of the Location from which + to list the Indexes. Format: + ``projects/{project}/locations/{location}`` + + 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: + google.cloud.aiplatform_v1.services.index_service.pagers.ListIndexesPager: + Response message for + [IndexService.ListIndexes][google.cloud.aiplatform.v1.IndexService.ListIndexes]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 index_service.ListIndexesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, index_service.ListIndexesRequest): + request = index_service.ListIndexesRequest(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_indexes] + + # 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.ListIndexesPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def update_index( + self, + request: Union[index_service.UpdateIndexRequest, dict] = None, + *, + index: gca_index.Index = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Updates an Index. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_update_index(): + # Create a client + client = aiplatform_v1.IndexServiceClient() + + # Initialize request argument(s) + index = aiplatform_v1.Index() + index.display_name = "display_name_value" + + request = aiplatform_v1.UpdateIndexRequest( + index=index, + ) + + # Make the request + operation = client.update_index(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.UpdateIndexRequest, dict]): + The request object. Request message for + [IndexService.UpdateIndex][google.cloud.aiplatform.v1.IndexService.UpdateIndex]. + index (google.cloud.aiplatform_v1.types.Index): + Required. The Index which updates the + resource on the server. + + This corresponds to the ``index`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + The update mask applies to the resource. For the + ``FieldMask`` definition, see + [google.protobuf.FieldMask][google.protobuf.FieldMask]. + + 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.cloud.aiplatform_v1.types.Index` A representation of a collection of database items organized in a way that + allows for approximate nearest neighbor (a.k.a ANN) + algorithms search. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([index, 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 index_service.UpdateIndexRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, index_service.UpdateIndexRequest): + request = index_service.UpdateIndexRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if index is not None: + request.index = index + 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_index] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("index.name", request.index.name),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + gca_index.Index, + metadata_type=index_service.UpdateIndexOperationMetadata, + ) + + # Done; return the response. + return response + + def delete_index( + self, + request: Union[index_service.DeleteIndexRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Deletes an Index. An Index can only be deleted when all its + [DeployedIndexes][google.cloud.aiplatform.v1.Index.deployed_indexes] + had been undeployed. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_delete_index(): + # Create a client + client = aiplatform_v1.IndexServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteIndexRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_index(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.DeleteIndexRequest, dict]): + The request object. Request message for + [IndexService.DeleteIndex][google.cloud.aiplatform.v1.IndexService.DeleteIndex]. + name (str): + Required. The name of the Index resource to be deleted. + Format: + ``projects/{project}/locations/{location}/indexes/{index}`` + + 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # Create or coerce a protobuf request object. + # Quick 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 index_service.DeleteIndexRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, index_service.DeleteIndexRequest): + request = index_service.DeleteIndexRequest(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_index] + + # 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, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, + ) + + # Done; return the response. + return response + + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_operations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.delete_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.wait_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_location, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_locations, + default_timeout=None, + 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 = 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-aiplatform", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ("IndexServiceClient",) diff --git a/google/cloud/aiplatform_v1/services/index_service/pagers.py b/google/cloud/aiplatform_v1/services/index_service/pagers.py new file mode 100644 index 0000000000..c0690d0e3f --- /dev/null +++ b/google/cloud/aiplatform_v1/services/index_service/pagers.py @@ -0,0 +1,156 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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 typing import ( + Any, + AsyncIterator, + Awaitable, + Callable, + Sequence, + Tuple, + Optional, + Iterator, +) + +from google.cloud.aiplatform_v1.types import index +from google.cloud.aiplatform_v1.types import index_service + + +class ListIndexesPager: + """A pager for iterating through ``list_indexes`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListIndexesResponse` object, and + provides an ``__iter__`` method to iterate through its + ``indexes`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListIndexes`` requests and continue to iterate + through the ``indexes`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListIndexesResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., index_service.ListIndexesResponse], + request: index_service.ListIndexesRequest, + response: index_service.ListIndexesResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListIndexesRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListIndexesResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = index_service.ListIndexesRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[index_service.ListIndexesResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterator[index.Index]: + for page in self.pages: + yield from page.indexes + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListIndexesAsyncPager: + """A pager for iterating through ``list_indexes`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListIndexesResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``indexes`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListIndexes`` requests and continue to iterate + through the ``indexes`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListIndexesResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., Awaitable[index_service.ListIndexesResponse]], + request: index_service.ListIndexesRequest, + response: index_service.ListIndexesResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListIndexesRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListIndexesResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = index_service.ListIndexesRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[index_service.ListIndexesResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + + def __aiter__(self) -> AsyncIterator[index.Index]: + async def async_generator(): + async for page in self.pages: + for response in page.indexes: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) diff --git a/google/cloud/aiplatform_v1/services/index_service/transports/__init__.py b/google/cloud/aiplatform_v1/services/index_service/transports/__init__.py new file mode 100644 index 0000000000..c8bcfc04bf --- /dev/null +++ b/google/cloud/aiplatform_v1/services/index_service/transports/__init__.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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 typing import Dict, Type + +from .base import IndexServiceTransport +from .grpc import IndexServiceGrpcTransport +from .grpc_asyncio import IndexServiceGrpcAsyncIOTransport + + +# Compile a registry of transports. +_transport_registry = OrderedDict() # type: Dict[str, Type[IndexServiceTransport]] +_transport_registry["grpc"] = IndexServiceGrpcTransport +_transport_registry["grpc_asyncio"] = IndexServiceGrpcAsyncIOTransport + +__all__ = ( + "IndexServiceTransport", + "IndexServiceGrpcTransport", + "IndexServiceGrpcAsyncIOTransport", +) diff --git a/google/cloud/aiplatform_v1/services/index_service/transports/base.py b/google/cloud/aiplatform_v1/services/index_service/transports/base.py new file mode 100644 index 0000000000..322c54e78d --- /dev/null +++ b/google/cloud/aiplatform_v1/services/index_service/transports/base.py @@ -0,0 +1,317 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import abc +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +import pkg_resources + +import google.auth # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import operations_v1 +from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore + +from google.cloud.aiplatform_v1.types import index +from google.cloud.aiplatform_v1.types import index_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.longrunning import operations_pb2 # type: ignore + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-aiplatform", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +class IndexServiceTransport(abc.ABC): + """Abstract transport class for IndexService.""" + + AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) + + DEFAULT_HOST: str = "aiplatform.googleapis.com" + + def __init__( + self, + *, + host: str = DEFAULT_HOST, + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + **kwargs, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + 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. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is mutually exclusive with credentials. + scopes (Optional[Sequence[str]]): A list of scopes. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + 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. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + """ + + # Save the hostname. Default to port 443 (HTTPS) if none is specified. + if ":" not in host: + host += ":443" + self._host = host + + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} + + # Save the scopes. + self._scopes = scopes + + # If no credentials are provided, then determine the appropriate + # defaults. + if credentials and credentials_file: + raise core_exceptions.DuplicateCredentialArgs( + "'credentials_file' and 'credentials' are mutually exclusive" + ) + + if credentials_file is not None: + credentials, _ = google.auth.load_credentials_from_file( + credentials_file, **scopes_kwargs, quota_project_id=quota_project_id + ) + elif credentials is None: + credentials, _ = google.auth.default( + **scopes_kwargs, quota_project_id=quota_project_id + ) + + # If the credentials are service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + + # Save the credentials. + self._credentials = credentials + + def _prep_wrapped_messages(self, client_info): + # Precompute the wrapped methods. + self._wrapped_methods = { + self.create_index: gapic_v1.method.wrap_method( + self.create_index, + default_timeout=None, + client_info=client_info, + ), + self.get_index: gapic_v1.method.wrap_method( + self.get_index, + default_timeout=None, + client_info=client_info, + ), + self.list_indexes: gapic_v1.method.wrap_method( + self.list_indexes, + default_timeout=None, + client_info=client_info, + ), + self.update_index: gapic_v1.method.wrap_method( + self.update_index, + default_timeout=None, + client_info=client_info, + ), + self.delete_index: gapic_v1.method.wrap_method( + self.delete_index, + default_timeout=None, + client_info=client_info, + ), + } + + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + + @property + def operations_client(self): + """Return the client designed to process long-running operations.""" + raise NotImplementedError() + + @property + def create_index( + self, + ) -> Callable[ + [index_service.CreateIndexRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def get_index( + self, + ) -> Callable[ + [index_service.GetIndexRequest], Union[index.Index, Awaitable[index.Index]] + ]: + raise NotImplementedError() + + @property + def list_indexes( + self, + ) -> Callable[ + [index_service.ListIndexesRequest], + Union[ + index_service.ListIndexesResponse, + Awaitable[index_service.ListIndexesResponse], + ], + ]: + raise NotImplementedError() + + @property + def update_index( + self, + ) -> Callable[ + [index_service.UpdateIndexRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def delete_index( + self, + ) -> Callable[ + [index_service.DeleteIndexRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], + Union[ + operations_pb2.ListOperationsResponse, + Awaitable[operations_pb2.ListOperationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None,]: + raise NotImplementedError() + + @property + def wait_operation( + self, + ) -> Callable[ + [operations_pb2.WaitOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def set_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def get_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_location( + self, + ) -> Callable[ + [locations_pb2.GetLocationRequest], + Union[locations_pb2.Location, Awaitable[locations_pb2.Location]], + ]: + raise NotImplementedError() + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], + Union[ + locations_pb2.ListLocationsResponse, + Awaitable[locations_pb2.ListLocationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + + +__all__ = ("IndexServiceTransport",) diff --git a/google/cloud/aiplatform_v1/services/index_service/transports/grpc.py b/google/cloud/aiplatform_v1/services/index_service/transports/grpc.py new file mode 100644 index 0000000000..857638755a --- /dev/null +++ b/google/cloud/aiplatform_v1/services/index_service/transports/grpc.py @@ -0,0 +1,596 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import warnings +from typing import Callable, Dict, Optional, Sequence, Tuple, Union + +from google.api_core import grpc_helpers +from google.api_core import operations_v1 +from google.api_core import gapic_v1 +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore + +import grpc # type: ignore + +from google.cloud.aiplatform_v1.types import index +from google.cloud.aiplatform_v1.types import index_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.longrunning import operations_pb2 # type: ignore +from .base import IndexServiceTransport, DEFAULT_CLIENT_INFO + + +class IndexServiceGrpcTransport(IndexServiceTransport): + """gRPC backend transport for IndexService. + + A service for creating and managing Vertex AI's Index + resources. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + + _stubs: Dict[str, Callable] + + def __init__( + self, + *, + host: str = "aiplatform.googleapis.com", + credentials: ga_credentials.Credentials = None, + credentials_file: str = None, + scopes: Sequence[str] = None, + channel: grpc.Channel = None, + api_mtls_endpoint: str = None, + client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, + ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + 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. + This argument is ignored if ``channel`` is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional(Sequence[str])): A list of scopes. This argument is + ignored if ``channel`` is provided. + channel (Optional[grpc.Channel]): A ``Channel`` instance through + which to make calls. + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or application default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for the grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure a mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + 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. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + self._grpc_channel = None + self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client: Optional[operations_v1.OperationsClient] = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + + if channel: + # Ignore credentials if a channel was passed. + credentials = False + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + self._ssl_channel_credentials = None + + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials + + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + ) + + if not self._grpc_channel: + self._grpc_channel = type(self).create_channel( + self._host, + # use the credentials which are saved + credentials=self._credentials, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, + quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) + + @classmethod + def create_channel( + cls, + host: str = "aiplatform.googleapis.com", + credentials: ga_credentials.Credentials = None, + credentials_file: str = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs, + ) -> grpc.Channel: + """Create and return a gRPC channel object. + Args: + host (Optional[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is mutually exclusive with credentials. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + grpc.Channel: A gRPC channel object. + + Raises: + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + + return grpc_helpers.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + quota_project_id=quota_project_id, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, + **kwargs, + ) + + @property + def grpc_channel(self) -> grpc.Channel: + """Return the channel designed to connect to this service.""" + return self._grpc_channel + + @property + def operations_client(self) -> operations_v1.OperationsClient: + """Create the client designed to process long-running operations. + + This property caches on the instance; repeated calls return the same + client. + """ + # Quick check: Only create a new client if we do not already have one. + if self._operations_client is None: + self._operations_client = operations_v1.OperationsClient(self.grpc_channel) + + # Return the client from cache. + return self._operations_client + + @property + def create_index( + self, + ) -> Callable[[index_service.CreateIndexRequest], operations_pb2.Operation]: + r"""Return a callable for the create index method over gRPC. + + Creates an Index. + + Returns: + Callable[[~.CreateIndexRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_index" not in self._stubs: + self._stubs["create_index"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.IndexService/CreateIndex", + request_serializer=index_service.CreateIndexRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["create_index"] + + @property + def get_index(self) -> Callable[[index_service.GetIndexRequest], index.Index]: + r"""Return a callable for the get index method over gRPC. + + Gets an Index. + + Returns: + Callable[[~.GetIndexRequest], + ~.Index]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_index" not in self._stubs: + self._stubs["get_index"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.IndexService/GetIndex", + request_serializer=index_service.GetIndexRequest.serialize, + response_deserializer=index.Index.deserialize, + ) + return self._stubs["get_index"] + + @property + def list_indexes( + self, + ) -> Callable[ + [index_service.ListIndexesRequest], index_service.ListIndexesResponse + ]: + r"""Return a callable for the list indexes method over gRPC. + + Lists Indexes in a Location. + + Returns: + Callable[[~.ListIndexesRequest], + ~.ListIndexesResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_indexes" not in self._stubs: + self._stubs["list_indexes"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.IndexService/ListIndexes", + request_serializer=index_service.ListIndexesRequest.serialize, + response_deserializer=index_service.ListIndexesResponse.deserialize, + ) + return self._stubs["list_indexes"] + + @property + def update_index( + self, + ) -> Callable[[index_service.UpdateIndexRequest], operations_pb2.Operation]: + r"""Return a callable for the update index method over gRPC. + + Updates an Index. + + Returns: + Callable[[~.UpdateIndexRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_index" not in self._stubs: + self._stubs["update_index"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.IndexService/UpdateIndex", + request_serializer=index_service.UpdateIndexRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["update_index"] + + @property + def delete_index( + self, + ) -> Callable[[index_service.DeleteIndexRequest], operations_pb2.Operation]: + r"""Return a callable for the delete index method over gRPC. + + Deletes an Index. An Index can only be deleted when all its + [DeployedIndexes][google.cloud.aiplatform.v1.Index.deployed_indexes] + had been undeployed. + + Returns: + Callable[[~.DeleteIndexRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_index" not in self._stubs: + self._stubs["delete_index"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.IndexService/DeleteIndex", + request_serializer=index_service.DeleteIndexRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_index"] + + def close(self): + self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + @property + def kind(self) -> str: + return "grpc" + + +__all__ = ("IndexServiceGrpcTransport",) diff --git a/google/cloud/aiplatform_v1/services/index_service/transports/grpc_asyncio.py b/google/cloud/aiplatform_v1/services/index_service/transports/grpc_asyncio.py new file mode 100644 index 0000000000..9c1649bffb --- /dev/null +++ b/google/cloud/aiplatform_v1/services/index_service/transports/grpc_asyncio.py @@ -0,0 +1,605 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import warnings +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union + +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import operations_v1 +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore + +import grpc # type: ignore +from grpc.experimental import aio # type: ignore + +from google.cloud.aiplatform_v1.types import index +from google.cloud.aiplatform_v1.types import index_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.longrunning import operations_pb2 # type: ignore +from .base import IndexServiceTransport, DEFAULT_CLIENT_INFO +from .grpc import IndexServiceGrpcTransport + + +class IndexServiceGrpcAsyncIOTransport(IndexServiceTransport): + """gRPC AsyncIO backend transport for IndexService. + + A service for creating and managing Vertex AI's Index + resources. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + + _grpc_channel: aio.Channel + _stubs: Dict[str, Callable] = {} + + @classmethod + def create_channel( + cls, + host: str = "aiplatform.googleapis.com", + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs, + ) -> aio.Channel: + """Create and return a gRPC AsyncIO channel object. + Args: + host (Optional[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + aio.Channel: A gRPC AsyncIO channel object. + """ + + return grpc_helpers_async.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + quota_project_id=quota_project_id, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, + **kwargs, + ) + + def __init__( + self, + *, + host: str = "aiplatform.googleapis.com", + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: aio.Channel = None, + api_mtls_endpoint: str = None, + client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, + ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, + quota_project_id=None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + 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. + This argument is ignored if ``channel`` is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + channel (Optional[aio.Channel]): A ``Channel`` instance through + which to make calls. + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or application default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for the grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure a mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + 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. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + + Raises: + google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + self._grpc_channel = None + self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + + if channel: + # Ignore credentials if a channel was passed. + credentials = False + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + self._ssl_channel_credentials = None + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials + + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + ) + + if not self._grpc_channel: + self._grpc_channel = type(self).create_channel( + self._host, + # use the credentials which are saved + credentials=self._credentials, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, + quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) + + @property + def grpc_channel(self) -> aio.Channel: + """Create the channel designed to connect to this service. + + This property caches on the instance; repeated calls return + the same channel. + """ + # Return the channel from cache. + return self._grpc_channel + + @property + def operations_client(self) -> operations_v1.OperationsAsyncClient: + """Create the client designed to process long-running operations. + + This property caches on the instance; repeated calls return the same + client. + """ + # Quick check: Only create a new client if we do not already have one. + if self._operations_client is None: + self._operations_client = operations_v1.OperationsAsyncClient( + self.grpc_channel + ) + + # Return the client from cache. + return self._operations_client + + @property + def create_index( + self, + ) -> Callable[ + [index_service.CreateIndexRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the create index method over gRPC. + + Creates an Index. + + Returns: + Callable[[~.CreateIndexRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_index" not in self._stubs: + self._stubs["create_index"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.IndexService/CreateIndex", + request_serializer=index_service.CreateIndexRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["create_index"] + + @property + def get_index( + self, + ) -> Callable[[index_service.GetIndexRequest], Awaitable[index.Index]]: + r"""Return a callable for the get index method over gRPC. + + Gets an Index. + + Returns: + Callable[[~.GetIndexRequest], + Awaitable[~.Index]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_index" not in self._stubs: + self._stubs["get_index"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.IndexService/GetIndex", + request_serializer=index_service.GetIndexRequest.serialize, + response_deserializer=index.Index.deserialize, + ) + return self._stubs["get_index"] + + @property + def list_indexes( + self, + ) -> Callable[ + [index_service.ListIndexesRequest], Awaitable[index_service.ListIndexesResponse] + ]: + r"""Return a callable for the list indexes method over gRPC. + + Lists Indexes in a Location. + + Returns: + Callable[[~.ListIndexesRequest], + Awaitable[~.ListIndexesResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_indexes" not in self._stubs: + self._stubs["list_indexes"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.IndexService/ListIndexes", + request_serializer=index_service.ListIndexesRequest.serialize, + response_deserializer=index_service.ListIndexesResponse.deserialize, + ) + return self._stubs["list_indexes"] + + @property + def update_index( + self, + ) -> Callable[ + [index_service.UpdateIndexRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the update index method over gRPC. + + Updates an Index. + + Returns: + Callable[[~.UpdateIndexRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_index" not in self._stubs: + self._stubs["update_index"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.IndexService/UpdateIndex", + request_serializer=index_service.UpdateIndexRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["update_index"] + + @property + def delete_index( + self, + ) -> Callable[ + [index_service.DeleteIndexRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the delete index method over gRPC. + + Deletes an Index. An Index can only be deleted when all its + [DeployedIndexes][google.cloud.aiplatform.v1.Index.deployed_indexes] + had been undeployed. + + Returns: + Callable[[~.DeleteIndexRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_index" not in self._stubs: + self._stubs["delete_index"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.IndexService/DeleteIndex", + request_serializer=index_service.DeleteIndexRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_index"] + + def close(self): + return self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + +__all__ = ("IndexServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/aiplatform_v1/services/job_service/__init__.py b/google/cloud/aiplatform_v1/services/job_service/__init__.py index 3d8d94dbd8..3d88580841 100644 --- a/google/cloud/aiplatform_v1/services/job_service/__init__.py +++ b/google/cloud/aiplatform_v1/services/job_service/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1/services/job_service/async_client.py b/google/cloud/aiplatform_v1/services/job_service/async_client.py index ff31a99af8..40dde742ee 100644 --- a/google/cloud/aiplatform_v1/services/job_service/async_client.py +++ b/google/cloud/aiplatform_v1/services/job_service/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,16 +16,21 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation as gac_operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1.services.job_service import pagers @@ -39,17 +44,31 @@ from google.cloud.aiplatform_v1.types import data_labeling_job from google.cloud.aiplatform_v1.types import data_labeling_job as gca_data_labeling_job from google.cloud.aiplatform_v1.types import encryption_spec +from google.cloud.aiplatform_v1.types import explanation from google.cloud.aiplatform_v1.types import hyperparameter_tuning_job from google.cloud.aiplatform_v1.types import ( hyperparameter_tuning_job as gca_hyperparameter_tuning_job, ) +from google.cloud.aiplatform_v1.types import io from google.cloud.aiplatform_v1.types import job_service from google.cloud.aiplatform_v1.types import job_state from google.cloud.aiplatform_v1.types import machine_resources from google.cloud.aiplatform_v1.types import manual_batch_tuning_parameters +from google.cloud.aiplatform_v1.types import model_deployment_monitoring_job +from google.cloud.aiplatform_v1.types import ( + model_deployment_monitoring_job as gca_model_deployment_monitoring_job, +) +from google.cloud.aiplatform_v1.types import model_monitoring from google.cloud.aiplatform_v1.types import operation as gca_operation from google.cloud.aiplatform_v1.types import study +from google.cloud.aiplatform_v1.types import unmanaged_container_model +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.protobuf import duration_pb2 # type: ignore from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import struct_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore from google.rpc import status_pb2 # type: ignore @@ -60,7 +79,7 @@ class JobServiceAsyncClient: - """A service for creating and managing AI Platform's jobs.""" + """A service for creating and managing Vertex AI's jobs.""" _client: JobServiceClient @@ -79,6 +98,8 @@ class JobServiceAsyncClient: ) dataset_path = staticmethod(JobServiceClient.dataset_path) parse_dataset_path = staticmethod(JobServiceClient.parse_dataset_path) + endpoint_path = staticmethod(JobServiceClient.endpoint_path) + parse_endpoint_path = staticmethod(JobServiceClient.parse_endpoint_path) hyperparameter_tuning_job_path = staticmethod( JobServiceClient.hyperparameter_tuning_job_path ) @@ -87,6 +108,16 @@ class JobServiceAsyncClient: ) model_path = staticmethod(JobServiceClient.model_path) parse_model_path = staticmethod(JobServiceClient.parse_model_path) + model_deployment_monitoring_job_path = staticmethod( + JobServiceClient.model_deployment_monitoring_job_path + ) + parse_model_deployment_monitoring_job_path = staticmethod( + JobServiceClient.parse_model_deployment_monitoring_job_path + ) + network_path = staticmethod(JobServiceClient.network_path) + parse_network_path = staticmethod(JobServiceClient.parse_network_path) + tensorboard_path = staticmethod(JobServiceClient.tensorboard_path) + parse_tensorboard_path = staticmethod(JobServiceClient.parse_tensorboard_path) trial_path = staticmethod(JobServiceClient.trial_path) parse_trial_path = staticmethod(JobServiceClient.parse_trial_path) common_billing_account_path = staticmethod( @@ -110,7 +141,8 @@ class JobServiceAsyncClient: @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -125,7 +157,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -140,9 +172,45 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return JobServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> JobServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: JobServiceTransport: The transport used by the client instance. @@ -161,7 +229,7 @@ def __init__( client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the job service client. + """Instantiates the job service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -202,19 +270,43 @@ def __init__( async def create_custom_job( self, - request: job_service.CreateCustomJobRequest = None, + request: Union[job_service.CreateCustomJobRequest, dict] = None, *, parent: str = None, custom_job: gca_custom_job.CustomJob = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_custom_job.CustomJob: r"""Creates a CustomJob. A created CustomJob right away will be attempted to be run. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_create_custom_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + custom_job = aiplatform_v1.CustomJob() + custom_job.display_name = "display_name_value" + custom_job.job_spec.worker_pool_specs.container_spec.image_uri = "image_uri_value" + + request = aiplatform_v1.CreateCustomJobRequest( + parent="parent_value", + custom_job=custom_job, + ) + + # Make the request + response = await client.create_custom_job(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.CreateCustomJobRequest`): + request (Union[google.cloud.aiplatform_v1.types.CreateCustomJobRequest, dict]): The request object. Request message for [JobService.CreateCustomJob][google.cloud.aiplatform.v1.JobService.CreateCustomJob]. parent (:class:`str`): @@ -249,7 +341,7 @@ async def create_custom_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, custom_job]) if request is not None and has_flattened_params: @@ -271,7 +363,7 @@ async def create_custom_job( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.create_custom_job, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -282,24 +374,48 @@ async def create_custom_job( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def get_custom_job( self, - request: job_service.GetCustomJobRequest = None, + request: Union[job_service.GetCustomJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> custom_job.CustomJob: r"""Gets a CustomJob. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_get_custom_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetCustomJobRequest( + name="name_value", + ) + + # Make the request + response = await client.get_custom_job(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.GetCustomJobRequest`): + request (Union[google.cloud.aiplatform_v1.types.GetCustomJobRequest, dict]): The request object. Request message for [JobService.GetCustomJob][google.cloud.aiplatform.v1.JobService.GetCustomJob]. name (:class:`str`): @@ -328,7 +444,7 @@ async def get_custom_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -348,7 +464,7 @@ async def get_custom_job( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.get_custom_job, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -359,24 +475,49 @@ async def get_custom_job( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_custom_jobs( self, - request: job_service.ListCustomJobsRequest = None, + request: Union[job_service.ListCustomJobsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListCustomJobsAsyncPager: r"""Lists CustomJobs in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_list_custom_jobs(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListCustomJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_custom_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.ListCustomJobsRequest`): + request (Union[google.cloud.aiplatform_v1.types.ListCustomJobsRequest, dict]): The request object. Request message for [JobService.ListCustomJobs][google.cloud.aiplatform.v1.JobService.ListCustomJobs]. parent (:class:`str`): @@ -403,7 +544,7 @@ async def list_custom_jobs( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -423,7 +564,7 @@ async def list_custom_jobs( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.list_custom_jobs, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -434,12 +575,20 @@ async def list_custom_jobs( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListCustomJobsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -447,17 +596,40 @@ async def list_custom_jobs( async def delete_custom_job( self, - request: job_service.DeleteCustomJobRequest = None, + request: Union[job_service.DeleteCustomJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a CustomJob. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_delete_custom_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteCustomJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_custom_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.DeleteCustomJobRequest`): + request (Union[google.cloud.aiplatform_v1.types.DeleteCustomJobRequest, dict]): The request object. Request message for [JobService.DeleteCustomJob][google.cloud.aiplatform.v1.JobService.DeleteCustomJob]. name (:class:`str`): @@ -494,7 +666,7 @@ async def delete_custom_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -514,7 +686,7 @@ async def delete_custom_job( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.delete_custom_job, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -525,7 +697,12 @@ async def delete_custom_job( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -540,10 +717,10 @@ async def delete_custom_job( async def cancel_custom_job( self, - request: job_service.CancelCustomJobRequest = None, + request: Union[job_service.CancelCustomJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -561,8 +738,24 @@ async def cancel_custom_job( [CustomJob.state][google.cloud.aiplatform.v1.CustomJob.state] is set to ``CANCELLED``. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_cancel_custom_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CancelCustomJobRequest( + name="name_value", + ) + + # Make the request + await client.cancel_custom_job(request=request) + Args: - request (:class:`google.cloud.aiplatform_v1.types.CancelCustomJobRequest`): + request (Union[google.cloud.aiplatform_v1.types.CancelCustomJobRequest, dict]): The request object. Request message for [JobService.CancelCustomJob][google.cloud.aiplatform.v1.JobService.CancelCustomJob]. name (:class:`str`): @@ -579,7 +772,7 @@ async def cancel_custom_job( 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 + # Quick 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: @@ -599,7 +792,7 @@ async def cancel_custom_job( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.cancel_custom_job, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -611,25 +804,56 @@ async def cancel_custom_job( # Send the request. await rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) async def create_data_labeling_job( self, - request: job_service.CreateDataLabelingJobRequest = None, + request: Union[job_service.CreateDataLabelingJobRequest, dict] = None, *, parent: str = None, data_labeling_job: gca_data_labeling_job.DataLabelingJob = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_data_labeling_job.DataLabelingJob: r"""Creates a DataLabelingJob. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_create_data_labeling_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + data_labeling_job = aiplatform_v1.DataLabelingJob() + data_labeling_job.display_name = "display_name_value" + data_labeling_job.datasets = ['datasets_value_1', 'datasets_value_2'] + data_labeling_job.labeler_count = 1375 + data_labeling_job.instruction_uri = "instruction_uri_value" + data_labeling_job.inputs_schema_uri = "inputs_schema_uri_value" + data_labeling_job.inputs.null_value = "NULL_VALUE" + + request = aiplatform_v1.CreateDataLabelingJobRequest( + parent="parent_value", + data_labeling_job=data_labeling_job, + ) + + # Make the request + response = await client.create_data_labeling_job(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.CreateDataLabelingJobRequest`): + request (Union[google.cloud.aiplatform_v1.types.CreateDataLabelingJobRequest, dict]): The request object. Request message for - [DataLabelingJobService.CreateDataLabelingJob][]. + [JobService.CreateDataLabelingJob][google.cloud.aiplatform.v1.JobService.CreateDataLabelingJob]. parent (:class:`str`): Required. The parent of the DataLabelingJob. Format: ``projects/{project}/locations/{location}`` @@ -658,7 +882,7 @@ async def create_data_labeling_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, data_labeling_job]) if request is not None and has_flattened_params: @@ -680,7 +904,7 @@ async def create_data_labeling_job( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.create_data_labeling_job, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -691,29 +915,52 @@ async def create_data_labeling_job( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def get_data_labeling_job( self, - request: job_service.GetDataLabelingJobRequest = None, + request: Union[job_service.GetDataLabelingJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> data_labeling_job.DataLabelingJob: r"""Gets a DataLabelingJob. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_get_data_labeling_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetDataLabelingJobRequest( + name="name_value", + ) + + # Make the request + response = await client.get_data_labeling_job(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.GetDataLabelingJobRequest`): + request (Union[google.cloud.aiplatform_v1.types.GetDataLabelingJobRequest, dict]): The request object. Request message for - [DataLabelingJobService.GetDataLabelingJob][]. + [JobService.GetDataLabelingJob][google.cloud.aiplatform.v1.JobService.GetDataLabelingJob]. name (:class:`str`): Required. The name of the DataLabelingJob. Format: - ``projects/{project}/locations/{location}/dataLabelingJobs/{data_labeling_job}`` This corresponds to the ``name`` field @@ -733,7 +980,7 @@ async def get_data_labeling_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -753,7 +1000,7 @@ async def get_data_labeling_job( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.get_data_labeling_job, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -764,26 +1011,51 @@ async def get_data_labeling_job( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_data_labeling_jobs( self, - request: job_service.ListDataLabelingJobsRequest = None, + request: Union[job_service.ListDataLabelingJobsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListDataLabelingJobsAsyncPager: r"""Lists DataLabelingJobs in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_list_data_labeling_jobs(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListDataLabelingJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_data_labeling_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.ListDataLabelingJobsRequest`): + request (Union[google.cloud.aiplatform_v1.types.ListDataLabelingJobsRequest, dict]): The request object. Request message for - [DataLabelingJobService.ListDataLabelingJobs][]. + [JobService.ListDataLabelingJobs][google.cloud.aiplatform.v1.JobService.ListDataLabelingJobs]. parent (:class:`str`): Required. The parent of the DataLabelingJob. Format: ``projects/{project}/locations/{location}`` @@ -807,7 +1079,7 @@ async def list_data_labeling_jobs( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -827,7 +1099,7 @@ async def list_data_labeling_jobs( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.list_data_labeling_jobs, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -838,12 +1110,20 @@ async def list_data_labeling_jobs( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListDataLabelingJobsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -851,23 +1131,45 @@ async def list_data_labeling_jobs( async def delete_data_labeling_job( self, - request: job_service.DeleteDataLabelingJobRequest = None, + request: Union[job_service.DeleteDataLabelingJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a DataLabelingJob. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_delete_data_labeling_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteDataLabelingJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_data_labeling_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.DeleteDataLabelingJobRequest`): + request (Union[google.cloud.aiplatform_v1.types.DeleteDataLabelingJobRequest, dict]): The request object. Request message for [JobService.DeleteDataLabelingJob][google.cloud.aiplatform.v1.JobService.DeleteDataLabelingJob]. name (:class:`str`): Required. The name of the DataLabelingJob to be deleted. Format: - ``projects/{project}/locations/{location}/dataLabelingJobs/{data_labeling_job}`` This corresponds to the ``name`` field @@ -899,7 +1201,7 @@ async def delete_data_labeling_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -919,7 +1221,7 @@ async def delete_data_labeling_job( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.delete_data_labeling_job, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -930,7 +1232,12 @@ async def delete_data_labeling_job( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -945,23 +1252,38 @@ async def delete_data_labeling_job( async def cancel_data_labeling_job( self, - request: job_service.CancelDataLabelingJobRequest = None, + request: Union[job_service.CancelDataLabelingJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Cancels a DataLabelingJob. Success of cancellation is not guaranteed. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_cancel_data_labeling_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CancelDataLabelingJobRequest( + name="name_value", + ) + + # Make the request + await client.cancel_data_labeling_job(request=request) + Args: - request (:class:`google.cloud.aiplatform_v1.types.CancelDataLabelingJobRequest`): + request (Union[google.cloud.aiplatform_v1.types.CancelDataLabelingJobRequest, dict]): The request object. Request message for - [DataLabelingJobService.CancelDataLabelingJob][]. + [JobService.CancelDataLabelingJob][google.cloud.aiplatform.v1.JobService.CancelDataLabelingJob]. name (:class:`str`): Required. The name of the DataLabelingJob. Format: - ``projects/{project}/locations/{location}/dataLabelingJobs/{data_labeling_job}`` This corresponds to the ``name`` field @@ -974,7 +1296,7 @@ async def cancel_data_labeling_job( 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 + # Quick 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: @@ -994,7 +1316,7 @@ async def cancel_data_labeling_job( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.cancel_data_labeling_job, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -1006,23 +1328,57 @@ async def cancel_data_labeling_job( # Send the request. await rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) async def create_hyperparameter_tuning_job( self, - request: job_service.CreateHyperparameterTuningJobRequest = None, + request: Union[job_service.CreateHyperparameterTuningJobRequest, dict] = None, *, parent: str = None, hyperparameter_tuning_job: gca_hyperparameter_tuning_job.HyperparameterTuningJob = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_hyperparameter_tuning_job.HyperparameterTuningJob: r"""Creates a HyperparameterTuningJob + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_create_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + hyperparameter_tuning_job = aiplatform_v1.HyperparameterTuningJob() + hyperparameter_tuning_job.display_name = "display_name_value" + hyperparameter_tuning_job.study_spec.metrics.metric_id = "metric_id_value" + hyperparameter_tuning_job.study_spec.metrics.goal = "MINIMIZE" + hyperparameter_tuning_job.study_spec.parameters.double_value_spec.min_value = 0.96 + hyperparameter_tuning_job.study_spec.parameters.double_value_spec.max_value = 0.962 + hyperparameter_tuning_job.study_spec.parameters.parameter_id = "parameter_id_value" + hyperparameter_tuning_job.max_trial_count = 1609 + hyperparameter_tuning_job.parallel_trial_count = 2128 + hyperparameter_tuning_job.trial_job_spec.worker_pool_specs.container_spec.image_uri = "image_uri_value" + + request = aiplatform_v1.CreateHyperparameterTuningJobRequest( + parent="parent_value", + hyperparameter_tuning_job=hyperparameter_tuning_job, + ) + + # Make the request + response = await client.create_hyperparameter_tuning_job(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.CreateHyperparameterTuningJobRequest`): + request (Union[google.cloud.aiplatform_v1.types.CreateHyperparameterTuningJobRequest, dict]): The request object. Request message for [JobService.CreateHyperparameterTuningJob][google.cloud.aiplatform.v1.JobService.CreateHyperparameterTuningJob]. parent (:class:`str`): @@ -1055,7 +1411,7 @@ async def create_hyperparameter_tuning_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, hyperparameter_tuning_job]) if request is not None and has_flattened_params: @@ -1077,7 +1433,7 @@ async def create_hyperparameter_tuning_job( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.create_hyperparameter_tuning_job, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -1088,30 +1444,53 @@ async def create_hyperparameter_tuning_job( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def get_hyperparameter_tuning_job( self, - request: job_service.GetHyperparameterTuningJobRequest = None, + request: Union[job_service.GetHyperparameterTuningJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> hyperparameter_tuning_job.HyperparameterTuningJob: r"""Gets a HyperparameterTuningJob + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_get_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetHyperparameterTuningJobRequest( + name="name_value", + ) + + # Make the request + response = await client.get_hyperparameter_tuning_job(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.GetHyperparameterTuningJobRequest`): + request (Union[google.cloud.aiplatform_v1.types.GetHyperparameterTuningJobRequest, dict]): The request object. Request message for [JobService.GetHyperparameterTuningJob][google.cloud.aiplatform.v1.JobService.GetHyperparameterTuningJob]. name (:class:`str`): Required. The name of the HyperparameterTuningJob resource. Format: - ``projects/{project}/locations/{location}/hyperparameterTuningJobs/{hyperparameter_tuning_job}`` This corresponds to the ``name`` field @@ -1132,7 +1511,7 @@ async def get_hyperparameter_tuning_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1152,7 +1531,7 @@ async def get_hyperparameter_tuning_job( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.get_hyperparameter_tuning_job, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -1163,24 +1542,49 @@ async def get_hyperparameter_tuning_job( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_hyperparameter_tuning_jobs( self, - request: job_service.ListHyperparameterTuningJobsRequest = None, + request: Union[job_service.ListHyperparameterTuningJobsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListHyperparameterTuningJobsAsyncPager: r"""Lists HyperparameterTuningJobs in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_list_hyperparameter_tuning_jobs(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListHyperparameterTuningJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_hyperparameter_tuning_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.ListHyperparameterTuningJobsRequest`): + request (Union[google.cloud.aiplatform_v1.types.ListHyperparameterTuningJobsRequest, dict]): The request object. Request message for [JobService.ListHyperparameterTuningJobs][google.cloud.aiplatform.v1.JobService.ListHyperparameterTuningJobs]. parent (:class:`str`): @@ -1207,7 +1611,7 @@ async def list_hyperparameter_tuning_jobs( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1227,7 +1631,7 @@ async def list_hyperparameter_tuning_jobs( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.list_hyperparameter_tuning_jobs, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -1238,12 +1642,20 @@ async def list_hyperparameter_tuning_jobs( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListHyperparameterTuningJobsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -1251,23 +1663,45 @@ async def list_hyperparameter_tuning_jobs( async def delete_hyperparameter_tuning_job( self, - request: job_service.DeleteHyperparameterTuningJobRequest = None, + request: Union[job_service.DeleteHyperparameterTuningJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a HyperparameterTuningJob. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_delete_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteHyperparameterTuningJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_hyperparameter_tuning_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.DeleteHyperparameterTuningJobRequest`): + request (Union[google.cloud.aiplatform_v1.types.DeleteHyperparameterTuningJobRequest, dict]): The request object. Request message for [JobService.DeleteHyperparameterTuningJob][google.cloud.aiplatform.v1.JobService.DeleteHyperparameterTuningJob]. name (:class:`str`): Required. The name of the HyperparameterTuningJob resource to be deleted. Format: - ``projects/{project}/locations/{location}/hyperparameterTuningJobs/{hyperparameter_tuning_job}`` This corresponds to the ``name`` field @@ -1299,7 +1733,7 @@ async def delete_hyperparameter_tuning_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1319,7 +1753,7 @@ async def delete_hyperparameter_tuning_job( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.delete_hyperparameter_tuning_job, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -1330,7 +1764,12 @@ async def delete_hyperparameter_tuning_job( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -1345,10 +1784,10 @@ async def delete_hyperparameter_tuning_job( async def cancel_hyperparameter_tuning_job( self, - request: job_service.CancelHyperparameterTuningJobRequest = None, + request: Union[job_service.CancelHyperparameterTuningJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -1367,14 +1806,29 @@ async def cancel_hyperparameter_tuning_job( [HyperparameterTuningJob.state][google.cloud.aiplatform.v1.HyperparameterTuningJob.state] is set to ``CANCELLED``. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_cancel_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CancelHyperparameterTuningJobRequest( + name="name_value", + ) + + # Make the request + await client.cancel_hyperparameter_tuning_job(request=request) + Args: - request (:class:`google.cloud.aiplatform_v1.types.CancelHyperparameterTuningJobRequest`): + request (Union[google.cloud.aiplatform_v1.types.CancelHyperparameterTuningJobRequest, dict]): The request object. Request message for [JobService.CancelHyperparameterTuningJob][google.cloud.aiplatform.v1.JobService.CancelHyperparameterTuningJob]. name (:class:`str`): Required. The name of the HyperparameterTuningJob to cancel. Format: - ``projects/{project}/locations/{location}/hyperparameterTuningJobs/{hyperparameter_tuning_job}`` This corresponds to the ``name`` field @@ -1387,7 +1841,7 @@ async def cancel_hyperparameter_tuning_job( 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 + # Quick 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: @@ -1407,7 +1861,7 @@ async def cancel_hyperparameter_tuning_job( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.cancel_hyperparameter_tuning_job, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -1419,24 +1873,54 @@ async def cancel_hyperparameter_tuning_job( # Send the request. await rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) async def create_batch_prediction_job( self, - request: job_service.CreateBatchPredictionJobRequest = None, + request: Union[job_service.CreateBatchPredictionJobRequest, dict] = None, *, parent: str = None, batch_prediction_job: gca_batch_prediction_job.BatchPredictionJob = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_batch_prediction_job.BatchPredictionJob: r"""Creates a BatchPredictionJob. A BatchPredictionJob once created will right away be attempted to start. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_create_batch_prediction_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + batch_prediction_job = aiplatform_v1.BatchPredictionJob() + batch_prediction_job.display_name = "display_name_value" + batch_prediction_job.input_config.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + batch_prediction_job.input_config.instances_format = "instances_format_value" + batch_prediction_job.output_config.gcs_destination.output_uri_prefix = "output_uri_prefix_value" + batch_prediction_job.output_config.predictions_format = "predictions_format_value" + + request = aiplatform_v1.CreateBatchPredictionJobRequest( + parent="parent_value", + batch_prediction_job=batch_prediction_job, + ) + + # Make the request + response = await client.create_batch_prediction_job(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.CreateBatchPredictionJobRequest`): + request (Union[google.cloud.aiplatform_v1.types.CreateBatchPredictionJobRequest, dict]): The request object. Request message for [JobService.CreateBatchPredictionJob][google.cloud.aiplatform.v1.JobService.CreateBatchPredictionJob]. parent (:class:`str`): @@ -1471,7 +1955,7 @@ async def create_batch_prediction_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, batch_prediction_job]) if request is not None and has_flattened_params: @@ -1493,7 +1977,7 @@ async def create_batch_prediction_job( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.create_batch_prediction_job, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -1504,30 +1988,53 @@ async def create_batch_prediction_job( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def get_batch_prediction_job( self, - request: job_service.GetBatchPredictionJobRequest = None, + request: Union[job_service.GetBatchPredictionJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> batch_prediction_job.BatchPredictionJob: r"""Gets a BatchPredictionJob + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_get_batch_prediction_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetBatchPredictionJobRequest( + name="name_value", + ) + + # Make the request + response = await client.get_batch_prediction_job(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.GetBatchPredictionJobRequest`): + request (Union[google.cloud.aiplatform_v1.types.GetBatchPredictionJobRequest, dict]): The request object. Request message for [JobService.GetBatchPredictionJob][google.cloud.aiplatform.v1.JobService.GetBatchPredictionJob]. name (:class:`str`): Required. The name of the BatchPredictionJob resource. Format: - ``projects/{project}/locations/{location}/batchPredictionJobs/{batch_prediction_job}`` This corresponds to the ``name`` field @@ -1550,7 +2057,7 @@ async def get_batch_prediction_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1570,7 +2077,7 @@ async def get_batch_prediction_job( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.get_batch_prediction_job, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -1581,24 +2088,49 @@ async def get_batch_prediction_job( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_batch_prediction_jobs( self, - request: job_service.ListBatchPredictionJobsRequest = None, + request: Union[job_service.ListBatchPredictionJobsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListBatchPredictionJobsAsyncPager: r"""Lists BatchPredictionJobs in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_list_batch_prediction_jobs(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListBatchPredictionJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_batch_prediction_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.ListBatchPredictionJobsRequest`): + request (Union[google.cloud.aiplatform_v1.types.ListBatchPredictionJobsRequest, dict]): The request object. Request message for [JobService.ListBatchPredictionJobs][google.cloud.aiplatform.v1.JobService.ListBatchPredictionJobs]. parent (:class:`str`): @@ -1625,7 +2157,7 @@ async def list_batch_prediction_jobs( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1645,7 +2177,7 @@ async def list_batch_prediction_jobs( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.list_batch_prediction_jobs, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -1656,12 +2188,20 @@ async def list_batch_prediction_jobs( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListBatchPredictionJobsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -1669,24 +2209,46 @@ async def list_batch_prediction_jobs( async def delete_batch_prediction_job( self, - request: job_service.DeleteBatchPredictionJobRequest = None, + request: Union[job_service.DeleteBatchPredictionJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a BatchPredictionJob. Can only be called on jobs that already finished. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_delete_batch_prediction_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteBatchPredictionJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_batch_prediction_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.DeleteBatchPredictionJobRequest`): + request (Union[google.cloud.aiplatform_v1.types.DeleteBatchPredictionJobRequest, dict]): The request object. Request message for [JobService.DeleteBatchPredictionJob][google.cloud.aiplatform.v1.JobService.DeleteBatchPredictionJob]. name (:class:`str`): Required. The name of the BatchPredictionJob resource to be deleted. Format: - ``projects/{project}/locations/{location}/batchPredictionJobs/{batch_prediction_job}`` This corresponds to the ``name`` field @@ -1718,7 +2280,7 @@ async def delete_batch_prediction_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1738,7 +2300,7 @@ async def delete_batch_prediction_job( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.delete_batch_prediction_job, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -1749,7 +2311,12 @@ async def delete_batch_prediction_job( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -1764,10 +2331,10 @@ async def delete_batch_prediction_job( async def cancel_batch_prediction_job( self, - request: job_service.CancelBatchPredictionJobRequest = None, + request: Union[job_service.CancelBatchPredictionJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -1784,14 +2351,29 @@ async def cancel_batch_prediction_job( is set to ``CANCELLED``. Any files already outputted by the job are not deleted. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_cancel_batch_prediction_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CancelBatchPredictionJobRequest( + name="name_value", + ) + + # Make the request + await client.cancel_batch_prediction_job(request=request) + Args: - request (:class:`google.cloud.aiplatform_v1.types.CancelBatchPredictionJobRequest`): + request (Union[google.cloud.aiplatform_v1.types.CancelBatchPredictionJobRequest, dict]): The request object. Request message for [JobService.CancelBatchPredictionJob][google.cloud.aiplatform.v1.JobService.CancelBatchPredictionJob]. name (:class:`str`): Required. The name of the BatchPredictionJob to cancel. Format: - ``projects/{project}/locations/{location}/batchPredictionJobs/{batch_prediction_job}`` This corresponds to the ``name`` field @@ -1804,7 +2386,7 @@ async def cancel_batch_prediction_job( 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 + # Quick 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: @@ -1824,7 +2406,7 @@ async def cancel_batch_prediction_job( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.cancel_batch_prediction_job, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -1836,9 +2418,1608 @@ async def cancel_batch_prediction_job( # Send the request. await rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + async def create_model_deployment_monitoring_job( + self, + request: Union[ + job_service.CreateModelDeploymentMonitoringJobRequest, dict + ] = None, + *, + parent: str = None, + model_deployment_monitoring_job: gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob: + r"""Creates a ModelDeploymentMonitoringJob. It will run + periodically on a configured interval. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_create_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + model_deployment_monitoring_job = aiplatform_v1.ModelDeploymentMonitoringJob() + model_deployment_monitoring_job.display_name = "display_name_value" + model_deployment_monitoring_job.endpoint = "endpoint_value" + + request = aiplatform_v1.CreateModelDeploymentMonitoringJobRequest( + parent="parent_value", + model_deployment_monitoring_job=model_deployment_monitoring_job, + ) + + # Make the request + response = await client.create_model_deployment_monitoring_job(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CreateModelDeploymentMonitoringJobRequest, dict]): + The request object. Request message for + [JobService.CreateModelDeploymentMonitoringJob][google.cloud.aiplatform.v1.JobService.CreateModelDeploymentMonitoringJob]. + parent (:class:`str`): + Required. The parent of the + ModelDeploymentMonitoringJob. Format: + ``projects/{project}/locations/{location}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + model_deployment_monitoring_job (:class:`google.cloud.aiplatform_v1.types.ModelDeploymentMonitoringJob`): + Required. The + ModelDeploymentMonitoringJob to create + + This corresponds to the ``model_deployment_monitoring_job`` 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: + google.cloud.aiplatform_v1.types.ModelDeploymentMonitoringJob: + Represents a job that runs + periodically to monitor the deployed + models in an endpoint. It will analyze + the logged training & prediction data to + detect any abnormal behaviors. + + """ + # Create or coerce a protobuf request object. + # Quick 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, model_deployment_monitoring_job]) + 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 = job_service.CreateModelDeploymentMonitoringJobRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if model_deployment_monitoring_job is not None: + request.model_deployment_monitoring_job = model_deployment_monitoring_job + + # 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_model_deployment_monitoring_job, + default_timeout=None, + 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 search_model_deployment_monitoring_stats_anomalies( + self, + request: Union[ + job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest, dict + ] = None, + *, + model_deployment_monitoring_job: str = None, + deployed_model_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.SearchModelDeploymentMonitoringStatsAnomaliesAsyncPager: + r"""Searches Model Monitoring Statistics generated within + a given time window. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_search_model_deployment_monitoring_stats_anomalies(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.SearchModelDeploymentMonitoringStatsAnomaliesRequest( + model_deployment_monitoring_job="model_deployment_monitoring_job_value", + deployed_model_id="deployed_model_id_value", + ) + + # Make the request + page_result = client.search_model_deployment_monitoring_stats_anomalies(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.SearchModelDeploymentMonitoringStatsAnomaliesRequest, dict]): + The request object. Request message for + [JobService.SearchModelDeploymentMonitoringStatsAnomalies][google.cloud.aiplatform.v1.JobService.SearchModelDeploymentMonitoringStatsAnomalies]. + model_deployment_monitoring_job (:class:`str`): + Required. ModelDeploymentMonitoring Job resource name. + Format: + ``projects/{project}/locations/{location}/modelDeploymentMonitoringJobs/{model_deployment_monitoring_job}`` + + This corresponds to the ``model_deployment_monitoring_job`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + deployed_model_id (:class:`str`): + Required. The DeployedModel ID of the + [ModelDeploymentMonitoringObjectiveConfig.deployed_model_id]. + + This corresponds to the ``deployed_model_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: + google.cloud.aiplatform_v1.services.job_service.pagers.SearchModelDeploymentMonitoringStatsAnomaliesAsyncPager: + Response message for + [JobService.SearchModelDeploymentMonitoringStatsAnomalies][google.cloud.aiplatform.v1.JobService.SearchModelDeploymentMonitoringStatsAnomalies]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([model_deployment_monitoring_job, deployed_model_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 = job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest( + request + ) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if model_deployment_monitoring_job is not None: + request.model_deployment_monitoring_job = model_deployment_monitoring_job + if deployed_model_id is not None: + request.deployed_model_id = deployed_model_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.search_model_deployment_monitoring_stats_anomalies, + default_timeout=None, + 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( + ( + ( + "model_deployment_monitoring_job", + request.model_deployment_monitoring_job, + ), + ) + ), + ) + + # 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.SearchModelDeploymentMonitoringStatsAnomaliesAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_model_deployment_monitoring_job( + self, + request: Union[job_service.GetModelDeploymentMonitoringJobRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> model_deployment_monitoring_job.ModelDeploymentMonitoringJob: + r"""Gets a ModelDeploymentMonitoringJob. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_get_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + response = await client.get_model_deployment_monitoring_job(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetModelDeploymentMonitoringJobRequest, dict]): + The request object. Request message for + [JobService.GetModelDeploymentMonitoringJob][google.cloud.aiplatform.v1.JobService.GetModelDeploymentMonitoringJob]. + name (:class:`str`): + Required. The resource name of the + ModelDeploymentMonitoringJob. Format: + ``projects/{project}/locations/{location}/modelDeploymentMonitoringJobs/{model_deployment_monitoring_job}`` + + 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: + google.cloud.aiplatform_v1.types.ModelDeploymentMonitoringJob: + Represents a job that runs + periodically to monitor the deployed + models in an endpoint. It will analyze + the logged training & prediction data to + detect any abnormal behaviors. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = job_service.GetModelDeploymentMonitoringJobRequest(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_model_deployment_monitoring_job, + default_timeout=None, + 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 list_model_deployment_monitoring_jobs( + self, + request: Union[ + job_service.ListModelDeploymentMonitoringJobsRequest, dict + ] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListModelDeploymentMonitoringJobsAsyncPager: + r"""Lists ModelDeploymentMonitoringJobs in a Location. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_list_model_deployment_monitoring_jobs(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListModelDeploymentMonitoringJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_model_deployment_monitoring_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListModelDeploymentMonitoringJobsRequest, dict]): + The request object. Request message for + [JobService.ListModelDeploymentMonitoringJobs][google.cloud.aiplatform.v1.JobService.ListModelDeploymentMonitoringJobs]. + parent (:class:`str`): + Required. The parent of the + ModelDeploymentMonitoringJob. Format: + ``projects/{project}/locations/{location}`` + + 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: + google.cloud.aiplatform_v1.services.job_service.pagers.ListModelDeploymentMonitoringJobsAsyncPager: + Response message for + [JobService.ListModelDeploymentMonitoringJobs][google.cloud.aiplatform.v1.JobService.ListModelDeploymentMonitoringJobs]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = job_service.ListModelDeploymentMonitoringJobsRequest(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_model_deployment_monitoring_jobs, + default_timeout=None, + 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.ListModelDeploymentMonitoringJobsAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def update_model_deployment_monitoring_job( + self, + request: Union[ + job_service.UpdateModelDeploymentMonitoringJobRequest, dict + ] = None, + *, + model_deployment_monitoring_job: gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Updates a ModelDeploymentMonitoringJob. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_update_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + model_deployment_monitoring_job = aiplatform_v1.ModelDeploymentMonitoringJob() + model_deployment_monitoring_job.display_name = "display_name_value" + model_deployment_monitoring_job.endpoint = "endpoint_value" + + request = aiplatform_v1.UpdateModelDeploymentMonitoringJobRequest( + model_deployment_monitoring_job=model_deployment_monitoring_job, + ) + + # Make the request + operation = client.update_model_deployment_monitoring_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.UpdateModelDeploymentMonitoringJobRequest, dict]): + The request object. Request message for + [JobService.UpdateModelDeploymentMonitoringJob][google.cloud.aiplatform.v1.JobService.UpdateModelDeploymentMonitoringJob]. + model_deployment_monitoring_job (:class:`google.cloud.aiplatform_v1.types.ModelDeploymentMonitoringJob`): + Required. The model monitoring + configuration which replaces the + resource on the server. + + This corresponds to the ``model_deployment_monitoring_job`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + Required. The update mask is used to specify the fields + to be overwritten in the ModelDeploymentMonitoringJob + resource by the update. The fields specified in the + update_mask are relative to the resource, not the full + request. A field will be overwritten if it is in the + mask. If the user does not provide a mask then only the + non-empty fields present in the request will be + overwritten. Set the update_mask to ``*`` to override + all fields. For the objective config, the user can + either provide the update mask for + model_deployment_monitoring_objective_configs or any + combination of its nested fields, such as: + model_deployment_monitoring_objective_configs.objective_config.training_dataset. + + Updatable fields: + + - ``display_name`` + - ``model_deployment_monitoring_schedule_config`` + - ``model_monitoring_alert_config`` + - ``logging_sampling_strategy`` + - ``labels`` + - ``log_ttl`` + - ``enable_monitoring_pipeline_logs`` . and + - ``model_deployment_monitoring_objective_configs`` . + or + - ``model_deployment_monitoring_objective_configs.objective_config.training_dataset`` + - ``model_deployment_monitoring_objective_configs.objective_config.training_prediction_skew_detection_config`` + - ``model_deployment_monitoring_objective_configs.objective_config.prediction_drift_detection_config`` + + 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.cloud.aiplatform_v1.types.ModelDeploymentMonitoringJob` Represents a job that runs periodically to monitor the deployed models in an + endpoint. It will analyze the logged training & + prediction data to detect any abnormal behaviors. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([model_deployment_monitoring_job, 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 = job_service.UpdateModelDeploymentMonitoringJobRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if model_deployment_monitoring_job is not None: + request.model_deployment_monitoring_job = model_deployment_monitoring_job + 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_model_deployment_monitoring_job, + default_timeout=None, + 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( + ( + ( + "model_deployment_monitoring_job.name", + request.model_deployment_monitoring_job.name, + ), + ) + ), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob, + metadata_type=job_service.UpdateModelDeploymentMonitoringJobOperationMetadata, + ) + + # Done; return the response. + return response + + async def delete_model_deployment_monitoring_job( + self, + request: Union[ + job_service.DeleteModelDeploymentMonitoringJobRequest, dict + ] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Deletes a ModelDeploymentMonitoringJob. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_delete_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_model_deployment_monitoring_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.DeleteModelDeploymentMonitoringJobRequest, dict]): + The request object. Request message for + [JobService.DeleteModelDeploymentMonitoringJob][google.cloud.aiplatform.v1.JobService.DeleteModelDeploymentMonitoringJob]. + name (:class:`str`): + Required. The resource name of the model monitoring job + to delete. Format: + ``projects/{project}/locations/{location}/modelDeploymentMonitoringJobs/{model_deployment_monitoring_job}`` + + 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = job_service.DeleteModelDeploymentMonitoringJobRequest(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_model_deployment_monitoring_job, + default_timeout=None, + 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, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, + ) + + # Done; return the response. + return response + + async def pause_model_deployment_monitoring_job( + self, + request: Union[ + job_service.PauseModelDeploymentMonitoringJobRequest, dict + ] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Pauses a ModelDeploymentMonitoringJob. If the job is running, + the server makes a best effort to cancel the job. Will mark + [ModelDeploymentMonitoringJob.state][google.cloud.aiplatform.v1.ModelDeploymentMonitoringJob.state] + to 'PAUSED'. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_pause_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.PauseModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + await client.pause_model_deployment_monitoring_job(request=request) + + Args: + request (Union[google.cloud.aiplatform_v1.types.PauseModelDeploymentMonitoringJobRequest, dict]): + The request object. Request message for + [JobService.PauseModelDeploymentMonitoringJob][google.cloud.aiplatform.v1.JobService.PauseModelDeploymentMonitoringJob]. + name (:class:`str`): + Required. The resource name of the + ModelDeploymentMonitoringJob to pause. Format: + ``projects/{project}/locations/{location}/modelDeploymentMonitoringJobs/{model_deployment_monitoring_job}`` + + 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. + # Quick 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 = job_service.PauseModelDeploymentMonitoringJobRequest(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.pause_model_deployment_monitoring_job, + default_timeout=None, + 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 resume_model_deployment_monitoring_job( + self, + request: Union[ + job_service.ResumeModelDeploymentMonitoringJobRequest, dict + ] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Resumes a paused ModelDeploymentMonitoringJob. It + will start to run from next scheduled time. A deleted + ModelDeploymentMonitoringJob can't be resumed. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_resume_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ResumeModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + await client.resume_model_deployment_monitoring_job(request=request) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ResumeModelDeploymentMonitoringJobRequest, dict]): + The request object. Request message for + [JobService.ResumeModelDeploymentMonitoringJob][google.cloud.aiplatform.v1.JobService.ResumeModelDeploymentMonitoringJob]. + name (:class:`str`): + Required. The resource name of the + ModelDeploymentMonitoringJob to resume. Format: + ``projects/{project}/locations/{location}/modelDeploymentMonitoringJobs/{model_deployment_monitoring_job}`` + + 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. + # Quick 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 = job_service.ResumeModelDeploymentMonitoringJobRequest(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.resume_model_deployment_monitoring_job, + default_timeout=None, + 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 list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_operations, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.delete_operation, + default_timeout=None, + 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 cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + 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 wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.wait_operation, + default_timeout=None, + 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 set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_location, + default_timeout=None, + 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 list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_locations, + default_timeout=None, + 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 __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/aiplatform_v1/services/job_service/client.py b/google/cloud/aiplatform_v1/services/job_service/client.py index d06dece139..b284d3c873 100644 --- a/google/cloud/aiplatform_v1/services/job_service/client.py +++ b/google/cloud/aiplatform_v1/services/job_service/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,22 +14,26 @@ # 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 +from typing import Dict, Mapping, 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 as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_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 +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation as gac_operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1.services.job_service import pagers @@ -43,17 +47,31 @@ from google.cloud.aiplatform_v1.types import data_labeling_job from google.cloud.aiplatform_v1.types import data_labeling_job as gca_data_labeling_job from google.cloud.aiplatform_v1.types import encryption_spec +from google.cloud.aiplatform_v1.types import explanation from google.cloud.aiplatform_v1.types import hyperparameter_tuning_job from google.cloud.aiplatform_v1.types import ( hyperparameter_tuning_job as gca_hyperparameter_tuning_job, ) +from google.cloud.aiplatform_v1.types import io from google.cloud.aiplatform_v1.types import job_service from google.cloud.aiplatform_v1.types import job_state from google.cloud.aiplatform_v1.types import machine_resources from google.cloud.aiplatform_v1.types import manual_batch_tuning_parameters +from google.cloud.aiplatform_v1.types import model_deployment_monitoring_job +from google.cloud.aiplatform_v1.types import ( + model_deployment_monitoring_job as gca_model_deployment_monitoring_job, +) +from google.cloud.aiplatform_v1.types import model_monitoring from google.cloud.aiplatform_v1.types import operation as gca_operation from google.cloud.aiplatform_v1.types import study +from google.cloud.aiplatform_v1.types import unmanaged_container_model +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.protobuf import duration_pb2 # type: ignore from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import struct_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore from google.rpc import status_pb2 # type: ignore @@ -75,8 +93,11 @@ class JobServiceClientMeta(type): _transport_registry["grpc"] = JobServiceGrpcTransport _transport_registry["grpc_asyncio"] = JobServiceGrpcAsyncIOTransport - def get_transport_class(cls, label: str = None,) -> Type[JobServiceTransport]: - """Return an appropriate transport class. + def get_transport_class( + cls, + label: str = None, + ) -> Type[JobServiceTransport]: + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -95,11 +116,12 @@ def get_transport_class(cls, label: str = None,) -> Type[JobServiceTransport]: class JobServiceClient(metaclass=JobServiceClientMeta): - """A service for creating and managing AI Platform's jobs.""" + """A service for creating and managing Vertex AI's jobs.""" @staticmethod def _get_default_mtls_endpoint(api_endpoint): - """Convert api endpoint to mTLS endpoint. + """Converts api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. Args: @@ -133,7 +155,8 @@ def _get_default_mtls_endpoint(api_endpoint): @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -150,7 +173,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -169,18 +192,21 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> JobServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - JobServiceTransport: The transport used by the client instance. + JobServiceTransport: The transport used by the client + instance. """ return self._transport @staticmethod def batch_prediction_job_path( - project: str, location: str, batch_prediction_job: str, + project: str, + location: str, + batch_prediction_job: str, ) -> str: - """Return a fully-qualified batch_prediction_job string.""" + """Returns a fully-qualified batch_prediction_job string.""" return "projects/{project}/locations/{location}/batchPredictionJobs/{batch_prediction_job}".format( project=project, location=location, @@ -189,7 +215,7 @@ def batch_prediction_job_path( @staticmethod def parse_batch_prediction_job_path(path: str) -> Dict[str, str]: - """Parse a batch_prediction_job path into its component segments.""" + """Parses a batch_prediction_job path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/batchPredictionJobs/(?P.+?)$", path, @@ -197,15 +223,21 @@ def parse_batch_prediction_job_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def custom_job_path(project: str, location: str, custom_job: str,) -> str: - """Return a fully-qualified custom_job string.""" + def custom_job_path( + project: str, + location: str, + custom_job: str, + ) -> str: + """Returns a fully-qualified custom_job string.""" return "projects/{project}/locations/{location}/customJobs/{custom_job}".format( - project=project, location=location, custom_job=custom_job, + project=project, + location=location, + custom_job=custom_job, ) @staticmethod def parse_custom_job_path(path: str) -> Dict[str, str]: - """Parse a custom_job path into its component segments.""" + """Parses a custom_job path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/customJobs/(?P.+?)$", path, @@ -214,16 +246,20 @@ def parse_custom_job_path(path: str) -> Dict[str, str]: @staticmethod def data_labeling_job_path( - project: str, location: str, data_labeling_job: str, + project: str, + location: str, + data_labeling_job: str, ) -> str: - """Return a fully-qualified data_labeling_job string.""" + """Returns a fully-qualified data_labeling_job string.""" return "projects/{project}/locations/{location}/dataLabelingJobs/{data_labeling_job}".format( - project=project, location=location, data_labeling_job=data_labeling_job, + project=project, + location=location, + data_labeling_job=data_labeling_job, ) @staticmethod def parse_data_labeling_job_path(path: str) -> Dict[str, str]: - """Parse a data_labeling_job path into its component segments.""" + """Parses a data_labeling_job path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/dataLabelingJobs/(?P.+?)$", path, @@ -231,26 +267,56 @@ def parse_data_labeling_job_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def dataset_path(project: str, location: str, dataset: str,) -> str: - """Return a fully-qualified dataset string.""" + def dataset_path( + project: str, + location: str, + dataset: str, + ) -> str: + """Returns a fully-qualified dataset string.""" return "projects/{project}/locations/{location}/datasets/{dataset}".format( - project=project, location=location, dataset=dataset, + project=project, + location=location, + dataset=dataset, ) @staticmethod def parse_dataset_path(path: str) -> Dict[str, str]: - """Parse a dataset path into its component segments.""" + """Parses a dataset path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/datasets/(?P.+?)$", path, ) return m.groupdict() if m else {} + @staticmethod + def endpoint_path( + project: str, + location: str, + endpoint: str, + ) -> str: + """Returns a fully-qualified endpoint string.""" + return "projects/{project}/locations/{location}/endpoints/{endpoint}".format( + project=project, + location=location, + endpoint=endpoint, + ) + + @staticmethod + def parse_endpoint_path(path: str) -> Dict[str, str]: + """Parses a endpoint path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/endpoints/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def hyperparameter_tuning_job_path( - project: str, location: str, hyperparameter_tuning_job: str, + project: str, + location: str, + hyperparameter_tuning_job: str, ) -> str: - """Return a fully-qualified hyperparameter_tuning_job string.""" + """Returns a fully-qualified hyperparameter_tuning_job string.""" return "projects/{project}/locations/{location}/hyperparameterTuningJobs/{hyperparameter_tuning_job}".format( project=project, location=location, @@ -259,7 +325,7 @@ def hyperparameter_tuning_job_path( @staticmethod def parse_hyperparameter_tuning_job_path(path: str) -> Dict[str, str]: - """Parse a hyperparameter_tuning_job path into its component segments.""" + """Parses a hyperparameter_tuning_job path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/hyperparameterTuningJobs/(?P.+?)$", path, @@ -267,15 +333,21 @@ def parse_hyperparameter_tuning_job_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def model_path(project: str, location: str, model: str,) -> str: - """Return a fully-qualified model string.""" + def model_path( + project: str, + location: str, + model: str, + ) -> str: + """Returns a fully-qualified model string.""" return "projects/{project}/locations/{location}/models/{model}".format( - project=project, location=location, model=model, + project=project, + location=location, + model=model, ) @staticmethod def parse_model_path(path: str) -> Dict[str, str]: - """Parse a model path into its component segments.""" + """Parses a model path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/models/(?P.+?)$", path, @@ -283,15 +355,88 @@ def parse_model_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def trial_path(project: str, location: str, study: str, trial: str,) -> str: - """Return a fully-qualified trial string.""" + def model_deployment_monitoring_job_path( + project: str, + location: str, + model_deployment_monitoring_job: str, + ) -> str: + """Returns a fully-qualified model_deployment_monitoring_job string.""" + return "projects/{project}/locations/{location}/modelDeploymentMonitoringJobs/{model_deployment_monitoring_job}".format( + project=project, + location=location, + model_deployment_monitoring_job=model_deployment_monitoring_job, + ) + + @staticmethod + def parse_model_deployment_monitoring_job_path(path: str) -> Dict[str, str]: + """Parses a model_deployment_monitoring_job path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/modelDeploymentMonitoringJobs/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def network_path( + project: str, + network: str, + ) -> str: + """Returns a fully-qualified network string.""" + return "projects/{project}/global/networks/{network}".format( + project=project, + network=network, + ) + + @staticmethod + def parse_network_path(path: str) -> Dict[str, str]: + """Parses a network path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/global/networks/(?P.+?)$", path + ) + return m.groupdict() if m else {} + + @staticmethod + def tensorboard_path( + project: str, + location: str, + tensorboard: str, + ) -> str: + """Returns a fully-qualified tensorboard string.""" + return ( + "projects/{project}/locations/{location}/tensorboards/{tensorboard}".format( + project=project, + location=location, + tensorboard=tensorboard, + ) + ) + + @staticmethod + def parse_tensorboard_path(path: str) -> Dict[str, str]: + """Parses a tensorboard path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/tensorboards/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def trial_path( + project: str, + location: str, + study: str, + trial: str, + ) -> str: + """Returns a fully-qualified trial string.""" return "projects/{project}/locations/{location}/studies/{study}/trials/{trial}".format( - project=project, location=location, study=study, trial=trial, + project=project, + location=location, + study=study, + trial=trial, ) @staticmethod def parse_trial_path(path: str) -> Dict[str, str]: - """Parse a trial path into its component segments.""" + """Parses a trial path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/studies/(?P.+?)/trials/(?P.+?)$", path, @@ -299,8 +444,10 @@ def parse_trial_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + def common_billing_account_path( + billing_account: str, + ) -> str: + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -312,9 +459,13 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: 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,) + def common_folder_path( + folder: str, + ) -> str: + """Returns a fully-qualified folder string.""" + return "folders/{folder}".format( + folder=folder, + ) @staticmethod def parse_common_folder_path(path: str) -> Dict[str, str]: @@ -323,9 +474,13 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: 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,) + def common_organization_path( + organization: str, + ) -> str: + """Returns a fully-qualified organization string.""" + return "organizations/{organization}".format( + organization=organization, + ) @staticmethod def parse_common_organization_path(path: str) -> Dict[str, str]: @@ -334,9 +489,13 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: 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,) + def common_project_path( + project: str, + ) -> str: + """Returns a fully-qualified project string.""" + return "projects/{project}".format( + project=project, + ) @staticmethod def parse_common_project_path(path: str) -> Dict[str, str]: @@ -345,10 +504,14 @@ def parse_common_project_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_location_path(project: str, location: str,) -> str: - """Return a fully-qualified location string.""" + def common_location_path( + project: str, + location: str, + ) -> str: + """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) @staticmethod @@ -357,6 +520,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + def __init__( self, *, @@ -365,7 +595,7 @@ def __init__( client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the job service client. + """Instantiates the job service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -407,58 +637,42 @@ def __init__( 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")) + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - client_cert_source_func = ( - mtls.default_client_cert_source() 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" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # 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, JobServiceTransport): # transport is a JobServiceTransport instance. - if credentials or client_options.credentials_file: + if credentials or client_options.credentials_file or api_key_value: 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." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + Transport = type(self).get_transport_class(transport) self._transport = Transport( credentials=credentials, @@ -468,23 +682,48 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, + always_use_jwt_access=True, ) def create_custom_job( self, - request: job_service.CreateCustomJobRequest = None, + request: Union[job_service.CreateCustomJobRequest, dict] = None, *, parent: str = None, custom_job: gca_custom_job.CustomJob = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_custom_job.CustomJob: r"""Creates a CustomJob. A created CustomJob right away will be attempted to be run. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_create_custom_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + custom_job = aiplatform_v1.CustomJob() + custom_job.display_name = "display_name_value" + custom_job.job_spec.worker_pool_specs.container_spec.image_uri = "image_uri_value" + + request = aiplatform_v1.CreateCustomJobRequest( + parent="parent_value", + custom_job=custom_job, + ) + + # Make the request + response = client.create_custom_job(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1.types.CreateCustomJobRequest): + request (Union[google.cloud.aiplatform_v1.types.CreateCustomJobRequest, dict]): The request object. Request message for [JobService.CreateCustomJob][google.cloud.aiplatform.v1.JobService.CreateCustomJob]. parent (str): @@ -519,7 +758,7 @@ def create_custom_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, custom_job]) if request is not None and has_flattened_params: @@ -552,24 +791,48 @@ def create_custom_job( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def get_custom_job( self, - request: job_service.GetCustomJobRequest = None, + request: Union[job_service.GetCustomJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> custom_job.CustomJob: r"""Gets a CustomJob. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_get_custom_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetCustomJobRequest( + name="name_value", + ) + + # Make the request + response = client.get_custom_job(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1.types.GetCustomJobRequest): + request (Union[google.cloud.aiplatform_v1.types.GetCustomJobRequest, dict]): The request object. Request message for [JobService.GetCustomJob][google.cloud.aiplatform.v1.JobService.GetCustomJob]. name (str): @@ -598,7 +861,7 @@ def get_custom_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -629,24 +892,49 @@ def get_custom_job( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_custom_jobs( self, - request: job_service.ListCustomJobsRequest = None, + request: Union[job_service.ListCustomJobsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListCustomJobsPager: r"""Lists CustomJobs in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_list_custom_jobs(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListCustomJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_custom_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1.types.ListCustomJobsRequest): + request (Union[google.cloud.aiplatform_v1.types.ListCustomJobsRequest, dict]): The request object. Request message for [JobService.ListCustomJobs][google.cloud.aiplatform.v1.JobService.ListCustomJobs]. parent (str): @@ -673,7 +961,7 @@ def list_custom_jobs( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -704,12 +992,20 @@ def list_custom_jobs( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListCustomJobsPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -717,17 +1013,40 @@ def list_custom_jobs( def delete_custom_job( self, - request: job_service.DeleteCustomJobRequest = None, + request: Union[job_service.DeleteCustomJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Deletes a CustomJob. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_delete_custom_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteCustomJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_custom_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1.types.DeleteCustomJobRequest): + request (Union[google.cloud.aiplatform_v1.types.DeleteCustomJobRequest, dict]): The request object. Request message for [JobService.DeleteCustomJob][google.cloud.aiplatform.v1.JobService.DeleteCustomJob]. name (str): @@ -764,7 +1083,7 @@ def delete_custom_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -795,7 +1114,12 @@ def delete_custom_job( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -810,10 +1134,10 @@ def delete_custom_job( def cancel_custom_job( self, - request: job_service.CancelCustomJobRequest = None, + request: Union[job_service.CancelCustomJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -831,8 +1155,24 @@ def cancel_custom_job( [CustomJob.state][google.cloud.aiplatform.v1.CustomJob.state] is set to ``CANCELLED``. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_cancel_custom_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CancelCustomJobRequest( + name="name_value", + ) + + # Make the request + client.cancel_custom_job(request=request) + Args: - request (google.cloud.aiplatform_v1.types.CancelCustomJobRequest): + request (Union[google.cloud.aiplatform_v1.types.CancelCustomJobRequest, dict]): The request object. Request message for [JobService.CancelCustomJob][google.cloud.aiplatform.v1.JobService.CancelCustomJob]. name (str): @@ -849,7 +1189,7 @@ def cancel_custom_job( 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 + # Quick 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: @@ -881,25 +1221,56 @@ def cancel_custom_job( # Send the request. rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) def create_data_labeling_job( self, - request: job_service.CreateDataLabelingJobRequest = None, + request: Union[job_service.CreateDataLabelingJobRequest, dict] = None, *, parent: str = None, data_labeling_job: gca_data_labeling_job.DataLabelingJob = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_data_labeling_job.DataLabelingJob: r"""Creates a DataLabelingJob. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_create_data_labeling_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + data_labeling_job = aiplatform_v1.DataLabelingJob() + data_labeling_job.display_name = "display_name_value" + data_labeling_job.datasets = ['datasets_value_1', 'datasets_value_2'] + data_labeling_job.labeler_count = 1375 + data_labeling_job.instruction_uri = "instruction_uri_value" + data_labeling_job.inputs_schema_uri = "inputs_schema_uri_value" + data_labeling_job.inputs.null_value = "NULL_VALUE" + + request = aiplatform_v1.CreateDataLabelingJobRequest( + parent="parent_value", + data_labeling_job=data_labeling_job, + ) + + # Make the request + response = client.create_data_labeling_job(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1.types.CreateDataLabelingJobRequest): + request (Union[google.cloud.aiplatform_v1.types.CreateDataLabelingJobRequest, dict]): The request object. Request message for - [DataLabelingJobService.CreateDataLabelingJob][]. + [JobService.CreateDataLabelingJob][google.cloud.aiplatform.v1.JobService.CreateDataLabelingJob]. parent (str): Required. The parent of the DataLabelingJob. Format: ``projects/{project}/locations/{location}`` @@ -928,7 +1299,7 @@ def create_data_labeling_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, data_labeling_job]) if request is not None and has_flattened_params: @@ -961,29 +1332,52 @@ def create_data_labeling_job( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def get_data_labeling_job( self, - request: job_service.GetDataLabelingJobRequest = None, + request: Union[job_service.GetDataLabelingJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> data_labeling_job.DataLabelingJob: r"""Gets a DataLabelingJob. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_get_data_labeling_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetDataLabelingJobRequest( + name="name_value", + ) + + # Make the request + response = client.get_data_labeling_job(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1.types.GetDataLabelingJobRequest): + request (Union[google.cloud.aiplatform_v1.types.GetDataLabelingJobRequest, dict]): The request object. Request message for - [DataLabelingJobService.GetDataLabelingJob][]. + [JobService.GetDataLabelingJob][google.cloud.aiplatform.v1.JobService.GetDataLabelingJob]. name (str): Required. The name of the DataLabelingJob. Format: - ``projects/{project}/locations/{location}/dataLabelingJobs/{data_labeling_job}`` This corresponds to the ``name`` field @@ -1003,7 +1397,7 @@ def get_data_labeling_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1034,26 +1428,51 @@ def get_data_labeling_job( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_data_labeling_jobs( self, - request: job_service.ListDataLabelingJobsRequest = None, + request: Union[job_service.ListDataLabelingJobsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListDataLabelingJobsPager: r"""Lists DataLabelingJobs in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_list_data_labeling_jobs(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListDataLabelingJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_data_labeling_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1.types.ListDataLabelingJobsRequest): + request (Union[google.cloud.aiplatform_v1.types.ListDataLabelingJobsRequest, dict]): The request object. Request message for - [DataLabelingJobService.ListDataLabelingJobs][]. + [JobService.ListDataLabelingJobs][google.cloud.aiplatform.v1.JobService.ListDataLabelingJobs]. parent (str): Required. The parent of the DataLabelingJob. Format: ``projects/{project}/locations/{location}`` @@ -1077,7 +1496,7 @@ def list_data_labeling_jobs( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1108,12 +1527,20 @@ def list_data_labeling_jobs( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListDataLabelingJobsPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -1121,23 +1548,45 @@ def list_data_labeling_jobs( def delete_data_labeling_job( self, - request: job_service.DeleteDataLabelingJobRequest = None, + request: Union[job_service.DeleteDataLabelingJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Deletes a DataLabelingJob. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_delete_data_labeling_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteDataLabelingJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_data_labeling_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1.types.DeleteDataLabelingJobRequest): + request (Union[google.cloud.aiplatform_v1.types.DeleteDataLabelingJobRequest, dict]): The request object. Request message for [JobService.DeleteDataLabelingJob][google.cloud.aiplatform.v1.JobService.DeleteDataLabelingJob]. name (str): Required. The name of the DataLabelingJob to be deleted. Format: - ``projects/{project}/locations/{location}/dataLabelingJobs/{data_labeling_job}`` This corresponds to the ``name`` field @@ -1169,7 +1618,7 @@ def delete_data_labeling_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1200,7 +1649,12 @@ def delete_data_labeling_job( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -1215,23 +1669,38 @@ def delete_data_labeling_job( def cancel_data_labeling_job( self, - request: job_service.CancelDataLabelingJobRequest = None, + request: Union[job_service.CancelDataLabelingJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Cancels a DataLabelingJob. Success of cancellation is not guaranteed. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_cancel_data_labeling_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CancelDataLabelingJobRequest( + name="name_value", + ) + + # Make the request + client.cancel_data_labeling_job(request=request) + Args: - request (google.cloud.aiplatform_v1.types.CancelDataLabelingJobRequest): + request (Union[google.cloud.aiplatform_v1.types.CancelDataLabelingJobRequest, dict]): The request object. Request message for - [DataLabelingJobService.CancelDataLabelingJob][]. + [JobService.CancelDataLabelingJob][google.cloud.aiplatform.v1.JobService.CancelDataLabelingJob]. name (str): Required. The name of the DataLabelingJob. Format: - ``projects/{project}/locations/{location}/dataLabelingJobs/{data_labeling_job}`` This corresponds to the ``name`` field @@ -1244,7 +1713,7 @@ def cancel_data_labeling_job( 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 + # Quick 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: @@ -1276,23 +1745,57 @@ def cancel_data_labeling_job( # Send the request. rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) def create_hyperparameter_tuning_job( self, - request: job_service.CreateHyperparameterTuningJobRequest = None, + request: Union[job_service.CreateHyperparameterTuningJobRequest, dict] = None, *, parent: str = None, hyperparameter_tuning_job: gca_hyperparameter_tuning_job.HyperparameterTuningJob = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_hyperparameter_tuning_job.HyperparameterTuningJob: r"""Creates a HyperparameterTuningJob + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_create_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + hyperparameter_tuning_job = aiplatform_v1.HyperparameterTuningJob() + hyperparameter_tuning_job.display_name = "display_name_value" + hyperparameter_tuning_job.study_spec.metrics.metric_id = "metric_id_value" + hyperparameter_tuning_job.study_spec.metrics.goal = "MINIMIZE" + hyperparameter_tuning_job.study_spec.parameters.double_value_spec.min_value = 0.96 + hyperparameter_tuning_job.study_spec.parameters.double_value_spec.max_value = 0.962 + hyperparameter_tuning_job.study_spec.parameters.parameter_id = "parameter_id_value" + hyperparameter_tuning_job.max_trial_count = 1609 + hyperparameter_tuning_job.parallel_trial_count = 2128 + hyperparameter_tuning_job.trial_job_spec.worker_pool_specs.container_spec.image_uri = "image_uri_value" + + request = aiplatform_v1.CreateHyperparameterTuningJobRequest( + parent="parent_value", + hyperparameter_tuning_job=hyperparameter_tuning_job, + ) + + # Make the request + response = client.create_hyperparameter_tuning_job(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1.types.CreateHyperparameterTuningJobRequest): + request (Union[google.cloud.aiplatform_v1.types.CreateHyperparameterTuningJobRequest, dict]): The request object. Request message for [JobService.CreateHyperparameterTuningJob][google.cloud.aiplatform.v1.JobService.CreateHyperparameterTuningJob]. parent (str): @@ -1325,7 +1828,7 @@ def create_hyperparameter_tuning_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, hyperparameter_tuning_job]) if request is not None and has_flattened_params: @@ -1360,30 +1863,53 @@ def create_hyperparameter_tuning_job( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def get_hyperparameter_tuning_job( self, - request: job_service.GetHyperparameterTuningJobRequest = None, + request: Union[job_service.GetHyperparameterTuningJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> hyperparameter_tuning_job.HyperparameterTuningJob: r"""Gets a HyperparameterTuningJob + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_get_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetHyperparameterTuningJobRequest( + name="name_value", + ) + + # Make the request + response = client.get_hyperparameter_tuning_job(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1.types.GetHyperparameterTuningJobRequest): + request (Union[google.cloud.aiplatform_v1.types.GetHyperparameterTuningJobRequest, dict]): The request object. Request message for [JobService.GetHyperparameterTuningJob][google.cloud.aiplatform.v1.JobService.GetHyperparameterTuningJob]. name (str): Required. The name of the HyperparameterTuningJob resource. Format: - ``projects/{project}/locations/{location}/hyperparameterTuningJobs/{hyperparameter_tuning_job}`` This corresponds to the ``name`` field @@ -1404,7 +1930,7 @@ def get_hyperparameter_tuning_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1437,24 +1963,49 @@ def get_hyperparameter_tuning_job( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_hyperparameter_tuning_jobs( self, - request: job_service.ListHyperparameterTuningJobsRequest = None, + request: Union[job_service.ListHyperparameterTuningJobsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListHyperparameterTuningJobsPager: r"""Lists HyperparameterTuningJobs in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_list_hyperparameter_tuning_jobs(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListHyperparameterTuningJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_hyperparameter_tuning_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1.types.ListHyperparameterTuningJobsRequest): + request (Union[google.cloud.aiplatform_v1.types.ListHyperparameterTuningJobsRequest, dict]): The request object. Request message for [JobService.ListHyperparameterTuningJobs][google.cloud.aiplatform.v1.JobService.ListHyperparameterTuningJobs]. parent (str): @@ -1481,7 +2032,7 @@ def list_hyperparameter_tuning_jobs( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1514,12 +2065,20 @@ def list_hyperparameter_tuning_jobs( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListHyperparameterTuningJobsPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -1527,23 +2086,45 @@ def list_hyperparameter_tuning_jobs( def delete_hyperparameter_tuning_job( self, - request: job_service.DeleteHyperparameterTuningJobRequest = None, + request: Union[job_service.DeleteHyperparameterTuningJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Deletes a HyperparameterTuningJob. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_delete_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteHyperparameterTuningJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_hyperparameter_tuning_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1.types.DeleteHyperparameterTuningJobRequest): + request (Union[google.cloud.aiplatform_v1.types.DeleteHyperparameterTuningJobRequest, dict]): The request object. Request message for [JobService.DeleteHyperparameterTuningJob][google.cloud.aiplatform.v1.JobService.DeleteHyperparameterTuningJob]. name (str): Required. The name of the HyperparameterTuningJob resource to be deleted. Format: - ``projects/{project}/locations/{location}/hyperparameterTuningJobs/{hyperparameter_tuning_job}`` This corresponds to the ``name`` field @@ -1575,7 +2156,7 @@ def delete_hyperparameter_tuning_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1608,7 +2189,12 @@ def delete_hyperparameter_tuning_job( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -1623,10 +2209,10 @@ def delete_hyperparameter_tuning_job( def cancel_hyperparameter_tuning_job( self, - request: job_service.CancelHyperparameterTuningJobRequest = None, + request: Union[job_service.CancelHyperparameterTuningJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -1645,14 +2231,29 @@ def cancel_hyperparameter_tuning_job( [HyperparameterTuningJob.state][google.cloud.aiplatform.v1.HyperparameterTuningJob.state] is set to ``CANCELLED``. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_cancel_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CancelHyperparameterTuningJobRequest( + name="name_value", + ) + + # Make the request + client.cancel_hyperparameter_tuning_job(request=request) + Args: - request (google.cloud.aiplatform_v1.types.CancelHyperparameterTuningJobRequest): + request (Union[google.cloud.aiplatform_v1.types.CancelHyperparameterTuningJobRequest, dict]): The request object. Request message for [JobService.CancelHyperparameterTuningJob][google.cloud.aiplatform.v1.JobService.CancelHyperparameterTuningJob]. name (str): Required. The name of the HyperparameterTuningJob to cancel. Format: - ``projects/{project}/locations/{location}/hyperparameterTuningJobs/{hyperparameter_tuning_job}`` This corresponds to the ``name`` field @@ -1665,7 +2266,7 @@ def cancel_hyperparameter_tuning_job( 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 + # Quick 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: @@ -1699,24 +2300,54 @@ def cancel_hyperparameter_tuning_job( # Send the request. rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) def create_batch_prediction_job( self, - request: job_service.CreateBatchPredictionJobRequest = None, + request: Union[job_service.CreateBatchPredictionJobRequest, dict] = None, *, parent: str = None, batch_prediction_job: gca_batch_prediction_job.BatchPredictionJob = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_batch_prediction_job.BatchPredictionJob: r"""Creates a BatchPredictionJob. A BatchPredictionJob once created will right away be attempted to start. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_create_batch_prediction_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + batch_prediction_job = aiplatform_v1.BatchPredictionJob() + batch_prediction_job.display_name = "display_name_value" + batch_prediction_job.input_config.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + batch_prediction_job.input_config.instances_format = "instances_format_value" + batch_prediction_job.output_config.gcs_destination.output_uri_prefix = "output_uri_prefix_value" + batch_prediction_job.output_config.predictions_format = "predictions_format_value" + + request = aiplatform_v1.CreateBatchPredictionJobRequest( + parent="parent_value", + batch_prediction_job=batch_prediction_job, + ) + + # Make the request + response = client.create_batch_prediction_job(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1.types.CreateBatchPredictionJobRequest): + request (Union[google.cloud.aiplatform_v1.types.CreateBatchPredictionJobRequest, dict]): The request object. Request message for [JobService.CreateBatchPredictionJob][google.cloud.aiplatform.v1.JobService.CreateBatchPredictionJob]. parent (str): @@ -1751,7 +2382,7 @@ def create_batch_prediction_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, batch_prediction_job]) if request is not None and has_flattened_params: @@ -1786,30 +2417,53 @@ def create_batch_prediction_job( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def get_batch_prediction_job( self, - request: job_service.GetBatchPredictionJobRequest = None, + request: Union[job_service.GetBatchPredictionJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> batch_prediction_job.BatchPredictionJob: r"""Gets a BatchPredictionJob + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_get_batch_prediction_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetBatchPredictionJobRequest( + name="name_value", + ) + + # Make the request + response = client.get_batch_prediction_job(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1.types.GetBatchPredictionJobRequest): + request (Union[google.cloud.aiplatform_v1.types.GetBatchPredictionJobRequest, dict]): The request object. Request message for [JobService.GetBatchPredictionJob][google.cloud.aiplatform.v1.JobService.GetBatchPredictionJob]. name (str): Required. The name of the BatchPredictionJob resource. Format: - ``projects/{project}/locations/{location}/batchPredictionJobs/{batch_prediction_job}`` This corresponds to the ``name`` field @@ -1832,7 +2486,7 @@ def get_batch_prediction_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1863,24 +2517,49 @@ def get_batch_prediction_job( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_batch_prediction_jobs( self, - request: job_service.ListBatchPredictionJobsRequest = None, + request: Union[job_service.ListBatchPredictionJobsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListBatchPredictionJobsPager: r"""Lists BatchPredictionJobs in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_list_batch_prediction_jobs(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListBatchPredictionJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_batch_prediction_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1.types.ListBatchPredictionJobsRequest): + request (Union[google.cloud.aiplatform_v1.types.ListBatchPredictionJobsRequest, dict]): The request object. Request message for [JobService.ListBatchPredictionJobs][google.cloud.aiplatform.v1.JobService.ListBatchPredictionJobs]. parent (str): @@ -1907,7 +2586,7 @@ def list_batch_prediction_jobs( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1940,12 +2619,20 @@ def list_batch_prediction_jobs( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListBatchPredictionJobsPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -1953,24 +2640,46 @@ def list_batch_prediction_jobs( def delete_batch_prediction_job( self, - request: job_service.DeleteBatchPredictionJobRequest = None, + request: Union[job_service.DeleteBatchPredictionJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Deletes a BatchPredictionJob. Can only be called on jobs that already finished. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_delete_batch_prediction_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteBatchPredictionJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_batch_prediction_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1.types.DeleteBatchPredictionJobRequest): + request (Union[google.cloud.aiplatform_v1.types.DeleteBatchPredictionJobRequest, dict]): The request object. Request message for [JobService.DeleteBatchPredictionJob][google.cloud.aiplatform.v1.JobService.DeleteBatchPredictionJob]. name (str): Required. The name of the BatchPredictionJob resource to be deleted. Format: - ``projects/{project}/locations/{location}/batchPredictionJobs/{batch_prediction_job}`` This corresponds to the ``name`` field @@ -2002,7 +2711,7 @@ def delete_batch_prediction_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -2035,7 +2744,12 @@ def delete_batch_prediction_job( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -2050,10 +2764,10 @@ def delete_batch_prediction_job( def cancel_batch_prediction_job( self, - request: job_service.CancelBatchPredictionJobRequest = None, + request: Union[job_service.CancelBatchPredictionJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -2070,14 +2784,29 @@ def cancel_batch_prediction_job( is set to ``CANCELLED``. Any files already outputted by the job are not deleted. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_cancel_batch_prediction_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CancelBatchPredictionJobRequest( + name="name_value", + ) + + # Make the request + client.cancel_batch_prediction_job(request=request) + Args: - request (google.cloud.aiplatform_v1.types.CancelBatchPredictionJobRequest): + request (Union[google.cloud.aiplatform_v1.types.CancelBatchPredictionJobRequest, dict]): The request object. Request message for [JobService.CancelBatchPredictionJob][google.cloud.aiplatform.v1.JobService.CancelBatchPredictionJob]. name (str): Required. The name of the BatchPredictionJob to cancel. Format: - ``projects/{project}/locations/{location}/batchPredictionJobs/{batch_prediction_job}`` This corresponds to the ``name`` field @@ -2090,7 +2819,7 @@ def cancel_batch_prediction_job( 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 + # Quick 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: @@ -2124,9 +2853,1651 @@ def cancel_batch_prediction_job( # Send the request. rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def create_model_deployment_monitoring_job( + self, + request: Union[ + job_service.CreateModelDeploymentMonitoringJobRequest, dict + ] = None, + *, + parent: str = None, + model_deployment_monitoring_job: gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob: + r"""Creates a ModelDeploymentMonitoringJob. It will run + periodically on a configured interval. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_create_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + model_deployment_monitoring_job = aiplatform_v1.ModelDeploymentMonitoringJob() + model_deployment_monitoring_job.display_name = "display_name_value" + model_deployment_monitoring_job.endpoint = "endpoint_value" + + request = aiplatform_v1.CreateModelDeploymentMonitoringJobRequest( + parent="parent_value", + model_deployment_monitoring_job=model_deployment_monitoring_job, + ) + + # Make the request + response = client.create_model_deployment_monitoring_job(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CreateModelDeploymentMonitoringJobRequest, dict]): + The request object. Request message for + [JobService.CreateModelDeploymentMonitoringJob][google.cloud.aiplatform.v1.JobService.CreateModelDeploymentMonitoringJob]. + parent (str): + Required. The parent of the + ModelDeploymentMonitoringJob. Format: + ``projects/{project}/locations/{location}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + model_deployment_monitoring_job (google.cloud.aiplatform_v1.types.ModelDeploymentMonitoringJob): + Required. The + ModelDeploymentMonitoringJob to create + + This corresponds to the ``model_deployment_monitoring_job`` 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: + google.cloud.aiplatform_v1.types.ModelDeploymentMonitoringJob: + Represents a job that runs + periodically to monitor the deployed + models in an endpoint. It will analyze + the logged training & prediction data to + detect any abnormal behaviors. + + """ + # Create or coerce a protobuf request object. + # Quick 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, model_deployment_monitoring_job]) + 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 job_service.CreateModelDeploymentMonitoringJobRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, job_service.CreateModelDeploymentMonitoringJobRequest + ): + request = job_service.CreateModelDeploymentMonitoringJobRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if model_deployment_monitoring_job is not None: + request.model_deployment_monitoring_job = ( + model_deployment_monitoring_job + ) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.create_model_deployment_monitoring_job + ] + + # 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 search_model_deployment_monitoring_stats_anomalies( + self, + request: Union[ + job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest, dict + ] = None, + *, + model_deployment_monitoring_job: str = None, + deployed_model_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.SearchModelDeploymentMonitoringStatsAnomaliesPager: + r"""Searches Model Monitoring Statistics generated within + a given time window. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_search_model_deployment_monitoring_stats_anomalies(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.SearchModelDeploymentMonitoringStatsAnomaliesRequest( + model_deployment_monitoring_job="model_deployment_monitoring_job_value", + deployed_model_id="deployed_model_id_value", + ) + + # Make the request + page_result = client.search_model_deployment_monitoring_stats_anomalies(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.SearchModelDeploymentMonitoringStatsAnomaliesRequest, dict]): + The request object. Request message for + [JobService.SearchModelDeploymentMonitoringStatsAnomalies][google.cloud.aiplatform.v1.JobService.SearchModelDeploymentMonitoringStatsAnomalies]. + model_deployment_monitoring_job (str): + Required. ModelDeploymentMonitoring Job resource name. + Format: + ``projects/{project}/locations/{location}/modelDeploymentMonitoringJobs/{model_deployment_monitoring_job}`` + + This corresponds to the ``model_deployment_monitoring_job`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + deployed_model_id (str): + Required. The DeployedModel ID of the + [ModelDeploymentMonitoringObjectiveConfig.deployed_model_id]. + + This corresponds to the ``deployed_model_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: + google.cloud.aiplatform_v1.services.job_service.pagers.SearchModelDeploymentMonitoringStatsAnomaliesPager: + Response message for + [JobService.SearchModelDeploymentMonitoringStatsAnomalies][google.cloud.aiplatform.v1.JobService.SearchModelDeploymentMonitoringStatsAnomalies]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([model_deployment_monitoring_job, deployed_model_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 job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest + ): + request = job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest( + request + ) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if model_deployment_monitoring_job is not None: + request.model_deployment_monitoring_job = ( + model_deployment_monitoring_job + ) + if deployed_model_id is not None: + request.deployed_model_id = deployed_model_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.search_model_deployment_monitoring_stats_anomalies + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + ( + ( + "model_deployment_monitoring_job", + request.model_deployment_monitoring_job, + ), + ) + ), + ) + + # 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.SearchModelDeploymentMonitoringStatsAnomaliesPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_model_deployment_monitoring_job( + self, + request: Union[job_service.GetModelDeploymentMonitoringJobRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> model_deployment_monitoring_job.ModelDeploymentMonitoringJob: + r"""Gets a ModelDeploymentMonitoringJob. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_get_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + response = client.get_model_deployment_monitoring_job(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetModelDeploymentMonitoringJobRequest, dict]): + The request object. Request message for + [JobService.GetModelDeploymentMonitoringJob][google.cloud.aiplatform.v1.JobService.GetModelDeploymentMonitoringJob]. + name (str): + Required. The resource name of the + ModelDeploymentMonitoringJob. Format: + ``projects/{project}/locations/{location}/modelDeploymentMonitoringJobs/{model_deployment_monitoring_job}`` + + 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: + google.cloud.aiplatform_v1.types.ModelDeploymentMonitoringJob: + Represents a job that runs + periodically to monitor the deployed + models in an endpoint. It will analyze + the logged training & prediction data to + detect any abnormal behaviors. + + """ + # Create or coerce a protobuf request object. + # Quick 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 job_service.GetModelDeploymentMonitoringJobRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, job_service.GetModelDeploymentMonitoringJobRequest): + request = job_service.GetModelDeploymentMonitoringJobRequest(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_model_deployment_monitoring_job + ] + + # 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 list_model_deployment_monitoring_jobs( + self, + request: Union[ + job_service.ListModelDeploymentMonitoringJobsRequest, dict + ] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListModelDeploymentMonitoringJobsPager: + r"""Lists ModelDeploymentMonitoringJobs in a Location. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_list_model_deployment_monitoring_jobs(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListModelDeploymentMonitoringJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_model_deployment_monitoring_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListModelDeploymentMonitoringJobsRequest, dict]): + The request object. Request message for + [JobService.ListModelDeploymentMonitoringJobs][google.cloud.aiplatform.v1.JobService.ListModelDeploymentMonitoringJobs]. + parent (str): + Required. The parent of the + ModelDeploymentMonitoringJob. Format: + ``projects/{project}/locations/{location}`` + + 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: + google.cloud.aiplatform_v1.services.job_service.pagers.ListModelDeploymentMonitoringJobsPager: + Response message for + [JobService.ListModelDeploymentMonitoringJobs][google.cloud.aiplatform.v1.JobService.ListModelDeploymentMonitoringJobs]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 job_service.ListModelDeploymentMonitoringJobsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, job_service.ListModelDeploymentMonitoringJobsRequest + ): + request = job_service.ListModelDeploymentMonitoringJobsRequest(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_model_deployment_monitoring_jobs + ] + + # 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.ListModelDeploymentMonitoringJobsPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def update_model_deployment_monitoring_job( + self, + request: Union[ + job_service.UpdateModelDeploymentMonitoringJobRequest, dict + ] = None, + *, + model_deployment_monitoring_job: gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Updates a ModelDeploymentMonitoringJob. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_update_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + model_deployment_monitoring_job = aiplatform_v1.ModelDeploymentMonitoringJob() + model_deployment_monitoring_job.display_name = "display_name_value" + model_deployment_monitoring_job.endpoint = "endpoint_value" + + request = aiplatform_v1.UpdateModelDeploymentMonitoringJobRequest( + model_deployment_monitoring_job=model_deployment_monitoring_job, + ) + + # Make the request + operation = client.update_model_deployment_monitoring_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.UpdateModelDeploymentMonitoringJobRequest, dict]): + The request object. Request message for + [JobService.UpdateModelDeploymentMonitoringJob][google.cloud.aiplatform.v1.JobService.UpdateModelDeploymentMonitoringJob]. + model_deployment_monitoring_job (google.cloud.aiplatform_v1.types.ModelDeploymentMonitoringJob): + Required. The model monitoring + configuration which replaces the + resource on the server. + + This corresponds to the ``model_deployment_monitoring_job`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Required. The update mask is used to specify the fields + to be overwritten in the ModelDeploymentMonitoringJob + resource by the update. The fields specified in the + update_mask are relative to the resource, not the full + request. A field will be overwritten if it is in the + mask. If the user does not provide a mask then only the + non-empty fields present in the request will be + overwritten. Set the update_mask to ``*`` to override + all fields. For the objective config, the user can + either provide the update mask for + model_deployment_monitoring_objective_configs or any + combination of its nested fields, such as: + model_deployment_monitoring_objective_configs.objective_config.training_dataset. + + Updatable fields: + + - ``display_name`` + - ``model_deployment_monitoring_schedule_config`` + - ``model_monitoring_alert_config`` + - ``logging_sampling_strategy`` + - ``labels`` + - ``log_ttl`` + - ``enable_monitoring_pipeline_logs`` . and + - ``model_deployment_monitoring_objective_configs`` . + or + - ``model_deployment_monitoring_objective_configs.objective_config.training_dataset`` + - ``model_deployment_monitoring_objective_configs.objective_config.training_prediction_skew_detection_config`` + - ``model_deployment_monitoring_objective_configs.objective_config.prediction_drift_detection_config`` + + 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.cloud.aiplatform_v1.types.ModelDeploymentMonitoringJob` Represents a job that runs periodically to monitor the deployed models in an + endpoint. It will analyze the logged training & + prediction data to detect any abnormal behaviors. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([model_deployment_monitoring_job, 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 job_service.UpdateModelDeploymentMonitoringJobRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, job_service.UpdateModelDeploymentMonitoringJobRequest + ): + request = job_service.UpdateModelDeploymentMonitoringJobRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if model_deployment_monitoring_job is not None: + request.model_deployment_monitoring_job = ( + model_deployment_monitoring_job + ) + 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_model_deployment_monitoring_job + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + ( + ( + "model_deployment_monitoring_job.name", + request.model_deployment_monitoring_job.name, + ), + ) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob, + metadata_type=job_service.UpdateModelDeploymentMonitoringJobOperationMetadata, + ) + + # Done; return the response. + return response + + def delete_model_deployment_monitoring_job( + self, + request: Union[ + job_service.DeleteModelDeploymentMonitoringJobRequest, dict + ] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Deletes a ModelDeploymentMonitoringJob. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_delete_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_model_deployment_monitoring_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.DeleteModelDeploymentMonitoringJobRequest, dict]): + The request object. Request message for + [JobService.DeleteModelDeploymentMonitoringJob][google.cloud.aiplatform.v1.JobService.DeleteModelDeploymentMonitoringJob]. + name (str): + Required. The resource name of the model monitoring job + to delete. Format: + ``projects/{project}/locations/{location}/modelDeploymentMonitoringJobs/{model_deployment_monitoring_job}`` + + 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # Create or coerce a protobuf request object. + # Quick 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 job_service.DeleteModelDeploymentMonitoringJobRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, job_service.DeleteModelDeploymentMonitoringJobRequest + ): + request = job_service.DeleteModelDeploymentMonitoringJobRequest(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_model_deployment_monitoring_job + ] + + # 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, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, + ) + + # Done; return the response. + return response + + def pause_model_deployment_monitoring_job( + self, + request: Union[ + job_service.PauseModelDeploymentMonitoringJobRequest, dict + ] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Pauses a ModelDeploymentMonitoringJob. If the job is running, + the server makes a best effort to cancel the job. Will mark + [ModelDeploymentMonitoringJob.state][google.cloud.aiplatform.v1.ModelDeploymentMonitoringJob.state] + to 'PAUSED'. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_pause_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.PauseModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + client.pause_model_deployment_monitoring_job(request=request) + + Args: + request (Union[google.cloud.aiplatform_v1.types.PauseModelDeploymentMonitoringJobRequest, dict]): + The request object. Request message for + [JobService.PauseModelDeploymentMonitoringJob][google.cloud.aiplatform.v1.JobService.PauseModelDeploymentMonitoringJob]. + name (str): + Required. The resource name of the + ModelDeploymentMonitoringJob to pause. Format: + ``projects/{project}/locations/{location}/modelDeploymentMonitoringJobs/{model_deployment_monitoring_job}`` + + 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. + # Quick 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 job_service.PauseModelDeploymentMonitoringJobRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, job_service.PauseModelDeploymentMonitoringJobRequest + ): + request = job_service.PauseModelDeploymentMonitoringJobRequest(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.pause_model_deployment_monitoring_job + ] + + # 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 resume_model_deployment_monitoring_job( + self, + request: Union[ + job_service.ResumeModelDeploymentMonitoringJobRequest, dict + ] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Resumes a paused ModelDeploymentMonitoringJob. It + will start to run from next scheduled time. A deleted + ModelDeploymentMonitoringJob can't be resumed. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_resume_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ResumeModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + client.resume_model_deployment_monitoring_job(request=request) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ResumeModelDeploymentMonitoringJobRequest, dict]): + The request object. Request message for + [JobService.ResumeModelDeploymentMonitoringJob][google.cloud.aiplatform.v1.JobService.ResumeModelDeploymentMonitoringJob]. + name (str): + Required. The resource name of the + ModelDeploymentMonitoringJob to resume. Format: + ``projects/{project}/locations/{location}/modelDeploymentMonitoringJobs/{model_deployment_monitoring_job}`` + + 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. + # Quick 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 job_service.ResumeModelDeploymentMonitoringJobRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, job_service.ResumeModelDeploymentMonitoringJobRequest + ): + request = job_service.ResumeModelDeploymentMonitoringJobRequest(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.resume_model_deployment_monitoring_job + ] + + # 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 __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_operations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.delete_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.wait_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_location, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_locations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/aiplatform_v1/services/job_service/pagers.py b/google/cloud/aiplatform_v1/services/job_service/pagers.py index 53d7a12e57..6ed17ed0e2 100644 --- a/google/cloud/aiplatform_v1/services/job_service/pagers.py +++ b/google/cloud/aiplatform_v1/services/job_service/pagers.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,13 +15,13 @@ # from typing import ( Any, - AsyncIterable, + AsyncIterator, Awaitable, Callable, - Iterable, Sequence, Tuple, Optional, + Iterator, ) from google.cloud.aiplatform_v1.types import batch_prediction_job @@ -29,6 +29,10 @@ from google.cloud.aiplatform_v1.types import data_labeling_job from google.cloud.aiplatform_v1.types import hyperparameter_tuning_job from google.cloud.aiplatform_v1.types import job_service +from google.cloud.aiplatform_v1.types import model_deployment_monitoring_job +from google.cloud.aiplatform_v1.types import ( + model_deployment_monitoring_job as gca_model_deployment_monitoring_job, +) class ListCustomJobsPager: @@ -78,14 +82,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[job_service.ListCustomJobsResponse]: + def pages(self) -> Iterator[job_service.ListCustomJobsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[custom_job.CustomJob]: + def __iter__(self) -> Iterator[custom_job.CustomJob]: for page in self.pages: yield from page.custom_jobs @@ -119,7 +123,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -140,14 +144,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - async def pages(self) -> AsyncIterable[job_service.ListCustomJobsResponse]: + async def pages(self) -> AsyncIterator[job_service.ListCustomJobsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[custom_job.CustomJob]: + def __aiter__(self) -> AsyncIterator[custom_job.CustomJob]: async def async_generator(): async for page in self.pages: for response in page.custom_jobs: @@ -206,14 +210,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[job_service.ListDataLabelingJobsResponse]: + def pages(self) -> Iterator[job_service.ListDataLabelingJobsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[data_labeling_job.DataLabelingJob]: + def __iter__(self) -> Iterator[data_labeling_job.DataLabelingJob]: for page in self.pages: yield from page.data_labeling_jobs @@ -247,7 +251,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -268,14 +272,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - async def pages(self) -> AsyncIterable[job_service.ListDataLabelingJobsResponse]: + async def pages(self) -> AsyncIterator[job_service.ListDataLabelingJobsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[data_labeling_job.DataLabelingJob]: + def __aiter__(self) -> AsyncIterator[data_labeling_job.DataLabelingJob]: async def async_generator(): async for page in self.pages: for response in page.data_labeling_jobs: @@ -334,14 +338,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[job_service.ListHyperparameterTuningJobsResponse]: + def pages(self) -> Iterator[job_service.ListHyperparameterTuningJobsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[hyperparameter_tuning_job.HyperparameterTuningJob]: + def __iter__(self) -> Iterator[hyperparameter_tuning_job.HyperparameterTuningJob]: for page in self.pages: yield from page.hyperparameter_tuning_jobs @@ -377,7 +381,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -400,7 +404,7 @@ def __getattr__(self, name: str) -> Any: @property async def pages( self, - ) -> AsyncIterable[job_service.ListHyperparameterTuningJobsResponse]: + ) -> AsyncIterator[job_service.ListHyperparameterTuningJobsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token @@ -409,7 +413,7 @@ async def pages( def __aiter__( self, - ) -> AsyncIterable[hyperparameter_tuning_job.HyperparameterTuningJob]: + ) -> AsyncIterator[hyperparameter_tuning_job.HyperparameterTuningJob]: async def async_generator(): async for page in self.pages: for response in page.hyperparameter_tuning_jobs: @@ -468,14 +472,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[job_service.ListBatchPredictionJobsResponse]: + def pages(self) -> Iterator[job_service.ListBatchPredictionJobsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[batch_prediction_job.BatchPredictionJob]: + def __iter__(self) -> Iterator[batch_prediction_job.BatchPredictionJob]: for page in self.pages: yield from page.batch_prediction_jobs @@ -509,7 +513,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -530,14 +534,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - async def pages(self) -> AsyncIterable[job_service.ListBatchPredictionJobsResponse]: + async def pages(self) -> AsyncIterator[job_service.ListBatchPredictionJobsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[batch_prediction_job.BatchPredictionJob]: + def __aiter__(self) -> AsyncIterator[batch_prediction_job.BatchPredictionJob]: async def async_generator(): async for page in self.pages: for response in page.batch_prediction_jobs: @@ -547,3 +551,290 @@ async def async_generator(): def __repr__(self) -> str: return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class SearchModelDeploymentMonitoringStatsAnomaliesPager: + """A pager for iterating through ``search_model_deployment_monitoring_stats_anomalies`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.SearchModelDeploymentMonitoringStatsAnomaliesResponse` object, and + provides an ``__iter__`` method to iterate through its + ``monitoring_stats`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``SearchModelDeploymentMonitoringStatsAnomalies`` requests and continue to iterate + through the ``monitoring_stats`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.SearchModelDeploymentMonitoringStatsAnomaliesResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[ + ..., job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse + ], + request: job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest, + response: job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.SearchModelDeploymentMonitoringStatsAnomaliesRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.SearchModelDeploymentMonitoringStatsAnomaliesResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = ( + job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest(request) + ) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages( + self, + ) -> Iterator[job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__( + self, + ) -> Iterator[gca_model_deployment_monitoring_job.ModelMonitoringStatsAnomalies]: + for page in self.pages: + yield from page.monitoring_stats + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class SearchModelDeploymentMonitoringStatsAnomaliesAsyncPager: + """A pager for iterating through ``search_model_deployment_monitoring_stats_anomalies`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.SearchModelDeploymentMonitoringStatsAnomaliesResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``monitoring_stats`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``SearchModelDeploymentMonitoringStatsAnomalies`` requests and continue to iterate + through the ``monitoring_stats`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.SearchModelDeploymentMonitoringStatsAnomaliesResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[ + ..., + Awaitable[ + job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse + ], + ], + request: job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest, + response: job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.SearchModelDeploymentMonitoringStatsAnomaliesRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.SearchModelDeploymentMonitoringStatsAnomaliesResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = ( + job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest(request) + ) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages( + self, + ) -> AsyncIterator[ + job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse + ]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + + def __aiter__( + self, + ) -> AsyncIterator[ + gca_model_deployment_monitoring_job.ModelMonitoringStatsAnomalies + ]: + async def async_generator(): + async for page in self.pages: + for response in page.monitoring_stats: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListModelDeploymentMonitoringJobsPager: + """A pager for iterating through ``list_model_deployment_monitoring_jobs`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListModelDeploymentMonitoringJobsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``model_deployment_monitoring_jobs`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListModelDeploymentMonitoringJobs`` requests and continue to iterate + through the ``model_deployment_monitoring_jobs`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListModelDeploymentMonitoringJobsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., job_service.ListModelDeploymentMonitoringJobsResponse], + request: job_service.ListModelDeploymentMonitoringJobsRequest, + response: job_service.ListModelDeploymentMonitoringJobsResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListModelDeploymentMonitoringJobsRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListModelDeploymentMonitoringJobsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = job_service.ListModelDeploymentMonitoringJobsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[job_service.ListModelDeploymentMonitoringJobsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__( + self, + ) -> Iterator[model_deployment_monitoring_job.ModelDeploymentMonitoringJob]: + for page in self.pages: + yield from page.model_deployment_monitoring_jobs + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListModelDeploymentMonitoringJobsAsyncPager: + """A pager for iterating through ``list_model_deployment_monitoring_jobs`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListModelDeploymentMonitoringJobsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``model_deployment_monitoring_jobs`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListModelDeploymentMonitoringJobs`` requests and continue to iterate + through the ``model_deployment_monitoring_jobs`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListModelDeploymentMonitoringJobsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[ + ..., Awaitable[job_service.ListModelDeploymentMonitoringJobsResponse] + ], + request: job_service.ListModelDeploymentMonitoringJobsRequest, + response: job_service.ListModelDeploymentMonitoringJobsResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListModelDeploymentMonitoringJobsRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListModelDeploymentMonitoringJobsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = job_service.ListModelDeploymentMonitoringJobsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages( + self, + ) -> AsyncIterator[job_service.ListModelDeploymentMonitoringJobsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + + def __aiter__( + self, + ) -> AsyncIterator[model_deployment_monitoring_job.ModelDeploymentMonitoringJob]: + async def async_generator(): + async for page in self.pages: + for response in page.model_deployment_monitoring_jobs: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) diff --git a/google/cloud/aiplatform_v1/services/job_service/transports/__init__.py b/google/cloud/aiplatform_v1/services/job_service/transports/__init__.py index c512946de1..bb641d64c6 100644 --- a/google/cloud/aiplatform_v1/services/job_service/transports/__init__.py +++ b/google/cloud/aiplatform_v1/services/job_service/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1/services/job_service/transports/base.py b/google/cloud/aiplatform_v1/services/job_service/transports/base.py index c8b47f54c6..708310c4be 100644 --- a/google/cloud/aiplatform_v1/services/job_service/transports/base.py +++ b/google/cloud/aiplatform_v1/services/job_service/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,16 +15,16 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.api_core import operations_v1 # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.aiplatform_v1.types import batch_prediction_job from google.cloud.aiplatform_v1.types import ( @@ -39,6 +39,14 @@ hyperparameter_tuning_job as gca_hyperparameter_tuning_job, ) from google.cloud.aiplatform_v1.types import job_service +from google.cloud.aiplatform_v1.types import model_deployment_monitoring_job +from google.cloud.aiplatform_v1.types import ( + model_deployment_monitoring_job as gca_model_deployment_monitoring_job, +) +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from google.protobuf import empty_pb2 # type: ignore @@ -51,17 +59,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - -_API_CORE_VERSION = google.api_core.__version__ - class JobServiceTransport(abc.ABC): """Abstract transport class for JobService.""" @@ -79,6 +76,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -102,16 +100,19 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -124,157 +125,178 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id ) - # Save the credentials. - self._credentials = credentials - - # TODO(busunkim): These two class methods are in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-api-core - # and google-auth are increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") + # If the credentials are service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs + credentials = credentials.with_always_use_jwt_access(True) - # TODO: Remove this function once google-api-core >= 1.26.0 is required - @classmethod - def _get_self_signed_jwt_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Union[Optional[Sequence[str]], str]]: - """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" - - self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} - - if _API_CORE_VERSION and ( - packaging.version.parse(_API_CORE_VERSION) - >= packaging.version.parse("1.26.0") - ): - self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES - self_signed_jwt_kwargs["scopes"] = scopes - self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST - else: - self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES - - return self_signed_jwt_kwargs + # Save the credentials. + self._credentials = credentials def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { self.create_custom_job: gapic_v1.method.wrap_method( - self.create_custom_job, default_timeout=5.0, client_info=client_info, + self.create_custom_job, + default_timeout=None, + client_info=client_info, ), self.get_custom_job: gapic_v1.method.wrap_method( - self.get_custom_job, default_timeout=5.0, client_info=client_info, + self.get_custom_job, + default_timeout=None, + client_info=client_info, ), self.list_custom_jobs: gapic_v1.method.wrap_method( - self.list_custom_jobs, default_timeout=5.0, client_info=client_info, + self.list_custom_jobs, + default_timeout=None, + client_info=client_info, ), self.delete_custom_job: gapic_v1.method.wrap_method( - self.delete_custom_job, default_timeout=5.0, client_info=client_info, + self.delete_custom_job, + default_timeout=None, + client_info=client_info, ), self.cancel_custom_job: gapic_v1.method.wrap_method( - self.cancel_custom_job, default_timeout=5.0, client_info=client_info, + self.cancel_custom_job, + default_timeout=None, + client_info=client_info, ), self.create_data_labeling_job: gapic_v1.method.wrap_method( self.create_data_labeling_job, - default_timeout=5.0, + default_timeout=None, client_info=client_info, ), self.get_data_labeling_job: gapic_v1.method.wrap_method( self.get_data_labeling_job, - default_timeout=5.0, + default_timeout=None, client_info=client_info, ), self.list_data_labeling_jobs: gapic_v1.method.wrap_method( self.list_data_labeling_jobs, - default_timeout=5.0, + default_timeout=None, client_info=client_info, ), self.delete_data_labeling_job: gapic_v1.method.wrap_method( self.delete_data_labeling_job, - default_timeout=5.0, + default_timeout=None, client_info=client_info, ), self.cancel_data_labeling_job: gapic_v1.method.wrap_method( self.cancel_data_labeling_job, - default_timeout=5.0, + default_timeout=None, client_info=client_info, ), self.create_hyperparameter_tuning_job: gapic_v1.method.wrap_method( self.create_hyperparameter_tuning_job, - default_timeout=5.0, + default_timeout=None, client_info=client_info, ), self.get_hyperparameter_tuning_job: gapic_v1.method.wrap_method( self.get_hyperparameter_tuning_job, - default_timeout=5.0, + default_timeout=None, client_info=client_info, ), self.list_hyperparameter_tuning_jobs: gapic_v1.method.wrap_method( self.list_hyperparameter_tuning_jobs, - default_timeout=5.0, + default_timeout=None, client_info=client_info, ), self.delete_hyperparameter_tuning_job: gapic_v1.method.wrap_method( self.delete_hyperparameter_tuning_job, - default_timeout=5.0, + default_timeout=None, client_info=client_info, ), self.cancel_hyperparameter_tuning_job: gapic_v1.method.wrap_method( self.cancel_hyperparameter_tuning_job, - default_timeout=5.0, + default_timeout=None, client_info=client_info, ), self.create_batch_prediction_job: gapic_v1.method.wrap_method( self.create_batch_prediction_job, - default_timeout=5.0, + default_timeout=None, client_info=client_info, ), self.get_batch_prediction_job: gapic_v1.method.wrap_method( self.get_batch_prediction_job, - default_timeout=5.0, + default_timeout=None, client_info=client_info, ), self.list_batch_prediction_jobs: gapic_v1.method.wrap_method( self.list_batch_prediction_jobs, - default_timeout=5.0, + default_timeout=None, client_info=client_info, ), self.delete_batch_prediction_job: gapic_v1.method.wrap_method( self.delete_batch_prediction_job, - default_timeout=5.0, + default_timeout=None, client_info=client_info, ), self.cancel_batch_prediction_job: gapic_v1.method.wrap_method( self.cancel_batch_prediction_job, - default_timeout=5.0, + default_timeout=None, + client_info=client_info, + ), + self.create_model_deployment_monitoring_job: gapic_v1.method.wrap_method( + self.create_model_deployment_monitoring_job, + default_timeout=None, + client_info=client_info, + ), + self.search_model_deployment_monitoring_stats_anomalies: gapic_v1.method.wrap_method( + self.search_model_deployment_monitoring_stats_anomalies, + default_timeout=None, + client_info=client_info, + ), + self.get_model_deployment_monitoring_job: gapic_v1.method.wrap_method( + self.get_model_deployment_monitoring_job, + default_timeout=None, + client_info=client_info, + ), + self.list_model_deployment_monitoring_jobs: gapic_v1.method.wrap_method( + self.list_model_deployment_monitoring_jobs, + default_timeout=None, + client_info=client_info, + ), + self.update_model_deployment_monitoring_job: gapic_v1.method.wrap_method( + self.update_model_deployment_monitoring_job, + default_timeout=None, + client_info=client_info, + ), + self.delete_model_deployment_monitoring_job: gapic_v1.method.wrap_method( + self.delete_model_deployment_monitoring_job, + default_timeout=None, + client_info=client_info, + ), + self.pause_model_deployment_monitoring_job: gapic_v1.method.wrap_method( + self.pause_model_deployment_monitoring_job, + default_timeout=None, + client_info=client_info, + ), + self.resume_model_deployment_monitoring_job: gapic_v1.method.wrap_method( + self.resume_model_deployment_monitoring_job, + default_timeout=None, client_info=client_info, ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() @@ -488,5 +510,188 @@ def cancel_batch_prediction_job( ]: raise NotImplementedError() + @property + def create_model_deployment_monitoring_job( + self, + ) -> Callable[ + [job_service.CreateModelDeploymentMonitoringJobRequest], + Union[ + gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob, + Awaitable[gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob], + ], + ]: + raise NotImplementedError() + + @property + def search_model_deployment_monitoring_stats_anomalies( + self, + ) -> Callable[ + [job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest], + Union[ + job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse, + Awaitable[ + job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse + ], + ], + ]: + raise NotImplementedError() + + @property + def get_model_deployment_monitoring_job( + self, + ) -> Callable[ + [job_service.GetModelDeploymentMonitoringJobRequest], + Union[ + model_deployment_monitoring_job.ModelDeploymentMonitoringJob, + Awaitable[model_deployment_monitoring_job.ModelDeploymentMonitoringJob], + ], + ]: + raise NotImplementedError() + + @property + def list_model_deployment_monitoring_jobs( + self, + ) -> Callable[ + [job_service.ListModelDeploymentMonitoringJobsRequest], + Union[ + job_service.ListModelDeploymentMonitoringJobsResponse, + Awaitable[job_service.ListModelDeploymentMonitoringJobsResponse], + ], + ]: + raise NotImplementedError() + + @property + def update_model_deployment_monitoring_job( + self, + ) -> Callable[ + [job_service.UpdateModelDeploymentMonitoringJobRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def delete_model_deployment_monitoring_job( + self, + ) -> Callable[ + [job_service.DeleteModelDeploymentMonitoringJobRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def pause_model_deployment_monitoring_job( + self, + ) -> Callable[ + [job_service.PauseModelDeploymentMonitoringJobRequest], + Union[empty_pb2.Empty, Awaitable[empty_pb2.Empty]], + ]: + raise NotImplementedError() + + @property + def resume_model_deployment_monitoring_job( + self, + ) -> Callable[ + [job_service.ResumeModelDeploymentMonitoringJobRequest], + Union[empty_pb2.Empty, Awaitable[empty_pb2.Empty]], + ]: + raise NotImplementedError() + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], + Union[ + operations_pb2.ListOperationsResponse, + Awaitable[operations_pb2.ListOperationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None,]: + raise NotImplementedError() + + @property + def wait_operation( + self, + ) -> Callable[ + [operations_pb2.WaitOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def set_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def get_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_location( + self, + ) -> Callable[ + [locations_pb2.GetLocationRequest], + Union[locations_pb2.Location, Awaitable[locations_pb2.Location]], + ]: + raise NotImplementedError() + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], + Union[ + locations_pb2.ListLocationsResponse, + Awaitable[locations_pb2.ListLocationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + __all__ = ("JobServiceTransport",) diff --git a/google/cloud/aiplatform_v1/services/job_service/transports/grpc.py b/google/cloud/aiplatform_v1/services/job_service/transports/grpc.py index 2a74d1c8d6..84d7b4a34e 100644 --- a/google/cloud/aiplatform_v1/services/job_service/transports/grpc.py +++ b/google/cloud/aiplatform_v1/services/job_service/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,9 +16,9 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import operations_v1 +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -38,6 +38,14 @@ hyperparameter_tuning_job as gca_hyperparameter_tuning_job, ) from google.cloud.aiplatform_v1.types import job_service +from google.cloud.aiplatform_v1.types import model_deployment_monitoring_job +from google.cloud.aiplatform_v1.types import ( + model_deployment_monitoring_job as gca_model_deployment_monitoring_job, +) +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from google.protobuf import empty_pb2 # type: ignore from .base import JobServiceTransport, DEFAULT_CLIENT_INFO @@ -46,7 +54,7 @@ class JobServiceGrpcTransport(JobServiceTransport): """gRPC backend transport for JobService. - A service for creating and managing AI Platform's jobs. + A service for creating and managing Vertex AI's jobs. This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation @@ -72,6 +80,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -94,16 +103,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -112,6 +121,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport @@ -122,7 +133,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -165,13 +176,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -220,21 +235,20 @@ def create_channel( and ``credentials_file`` are passed. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @property def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ + """Return the channel designed to connect to this service.""" return self._grpc_channel @property @@ -244,7 +258,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsClient(self.grpc_channel) @@ -857,5 +871,476 @@ def cancel_batch_prediction_job( ) return self._stubs["cancel_batch_prediction_job"] + @property + def create_model_deployment_monitoring_job( + self, + ) -> Callable[ + [job_service.CreateModelDeploymentMonitoringJobRequest], + gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob, + ]: + r"""Return a callable for the create model deployment + monitoring job method over gRPC. + + Creates a ModelDeploymentMonitoringJob. It will run + periodically on a configured interval. + + Returns: + Callable[[~.CreateModelDeploymentMonitoringJobRequest], + ~.ModelDeploymentMonitoringJob]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_model_deployment_monitoring_job" not in self._stubs: + self._stubs[ + "create_model_deployment_monitoring_job" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.JobService/CreateModelDeploymentMonitoringJob", + request_serializer=job_service.CreateModelDeploymentMonitoringJobRequest.serialize, + response_deserializer=gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob.deserialize, + ) + return self._stubs["create_model_deployment_monitoring_job"] + + @property + def search_model_deployment_monitoring_stats_anomalies( + self, + ) -> Callable[ + [job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest], + job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse, + ]: + r"""Return a callable for the search model deployment + monitoring stats anomalies method over gRPC. + + Searches Model Monitoring Statistics generated within + a given time window. + + Returns: + Callable[[~.SearchModelDeploymentMonitoringStatsAnomaliesRequest], + ~.SearchModelDeploymentMonitoringStatsAnomaliesResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "search_model_deployment_monitoring_stats_anomalies" not in self._stubs: + self._stubs[ + "search_model_deployment_monitoring_stats_anomalies" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.JobService/SearchModelDeploymentMonitoringStatsAnomalies", + request_serializer=job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest.serialize, + response_deserializer=job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse.deserialize, + ) + return self._stubs["search_model_deployment_monitoring_stats_anomalies"] + + @property + def get_model_deployment_monitoring_job( + self, + ) -> Callable[ + [job_service.GetModelDeploymentMonitoringJobRequest], + model_deployment_monitoring_job.ModelDeploymentMonitoringJob, + ]: + r"""Return a callable for the get model deployment + monitoring job method over gRPC. + + Gets a ModelDeploymentMonitoringJob. + + Returns: + Callable[[~.GetModelDeploymentMonitoringJobRequest], + ~.ModelDeploymentMonitoringJob]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_model_deployment_monitoring_job" not in self._stubs: + self._stubs[ + "get_model_deployment_monitoring_job" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.JobService/GetModelDeploymentMonitoringJob", + request_serializer=job_service.GetModelDeploymentMonitoringJobRequest.serialize, + response_deserializer=model_deployment_monitoring_job.ModelDeploymentMonitoringJob.deserialize, + ) + return self._stubs["get_model_deployment_monitoring_job"] + + @property + def list_model_deployment_monitoring_jobs( + self, + ) -> Callable[ + [job_service.ListModelDeploymentMonitoringJobsRequest], + job_service.ListModelDeploymentMonitoringJobsResponse, + ]: + r"""Return a callable for the list model deployment + monitoring jobs method over gRPC. + + Lists ModelDeploymentMonitoringJobs in a Location. + + Returns: + Callable[[~.ListModelDeploymentMonitoringJobsRequest], + ~.ListModelDeploymentMonitoringJobsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_model_deployment_monitoring_jobs" not in self._stubs: + self._stubs[ + "list_model_deployment_monitoring_jobs" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.JobService/ListModelDeploymentMonitoringJobs", + request_serializer=job_service.ListModelDeploymentMonitoringJobsRequest.serialize, + response_deserializer=job_service.ListModelDeploymentMonitoringJobsResponse.deserialize, + ) + return self._stubs["list_model_deployment_monitoring_jobs"] + + @property + def update_model_deployment_monitoring_job( + self, + ) -> Callable[ + [job_service.UpdateModelDeploymentMonitoringJobRequest], + operations_pb2.Operation, + ]: + r"""Return a callable for the update model deployment + monitoring job method over gRPC. + + Updates a ModelDeploymentMonitoringJob. + + Returns: + Callable[[~.UpdateModelDeploymentMonitoringJobRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_model_deployment_monitoring_job" not in self._stubs: + self._stubs[ + "update_model_deployment_monitoring_job" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.JobService/UpdateModelDeploymentMonitoringJob", + request_serializer=job_service.UpdateModelDeploymentMonitoringJobRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["update_model_deployment_monitoring_job"] + + @property + def delete_model_deployment_monitoring_job( + self, + ) -> Callable[ + [job_service.DeleteModelDeploymentMonitoringJobRequest], + operations_pb2.Operation, + ]: + r"""Return a callable for the delete model deployment + monitoring job method over gRPC. + + Deletes a ModelDeploymentMonitoringJob. + + Returns: + Callable[[~.DeleteModelDeploymentMonitoringJobRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_model_deployment_monitoring_job" not in self._stubs: + self._stubs[ + "delete_model_deployment_monitoring_job" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.JobService/DeleteModelDeploymentMonitoringJob", + request_serializer=job_service.DeleteModelDeploymentMonitoringJobRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_model_deployment_monitoring_job"] + + @property + def pause_model_deployment_monitoring_job( + self, + ) -> Callable[ + [job_service.PauseModelDeploymentMonitoringJobRequest], empty_pb2.Empty + ]: + r"""Return a callable for the pause model deployment + monitoring job method over gRPC. + + Pauses a ModelDeploymentMonitoringJob. If the job is running, + the server makes a best effort to cancel the job. Will mark + [ModelDeploymentMonitoringJob.state][google.cloud.aiplatform.v1.ModelDeploymentMonitoringJob.state] + to 'PAUSED'. + + Returns: + Callable[[~.PauseModelDeploymentMonitoringJobRequest], + ~.Empty]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "pause_model_deployment_monitoring_job" not in self._stubs: + self._stubs[ + "pause_model_deployment_monitoring_job" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.JobService/PauseModelDeploymentMonitoringJob", + request_serializer=job_service.PauseModelDeploymentMonitoringJobRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs["pause_model_deployment_monitoring_job"] + + @property + def resume_model_deployment_monitoring_job( + self, + ) -> Callable[ + [job_service.ResumeModelDeploymentMonitoringJobRequest], empty_pb2.Empty + ]: + r"""Return a callable for the resume model deployment + monitoring job method over gRPC. + + Resumes a paused ModelDeploymentMonitoringJob. It + will start to run from next scheduled time. A deleted + ModelDeploymentMonitoringJob can't be resumed. + + Returns: + Callable[[~.ResumeModelDeploymentMonitoringJobRequest], + ~.Empty]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "resume_model_deployment_monitoring_job" not in self._stubs: + self._stubs[ + "resume_model_deployment_monitoring_job" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.JobService/ResumeModelDeploymentMonitoringJob", + request_serializer=job_service.ResumeModelDeploymentMonitoringJobRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs["resume_model_deployment_monitoring_job"] + + def close(self): + self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + @property + def kind(self) -> str: + return "grpc" + __all__ = ("JobServiceGrpcTransport",) diff --git a/google/cloud/aiplatform_v1/services/job_service/transports/grpc_asyncio.py b/google/cloud/aiplatform_v1/services/job_service/transports/grpc_asyncio.py index 95c2e34118..b779beabbd 100644 --- a/google/cloud/aiplatform_v1/services/job_service/transports/grpc_asyncio.py +++ b/google/cloud/aiplatform_v1/services/job_service/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,12 +16,11 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore -from google.api_core import operations_v1 # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore @@ -39,6 +38,14 @@ hyperparameter_tuning_job as gca_hyperparameter_tuning_job, ) from google.cloud.aiplatform_v1.types import job_service +from google.cloud.aiplatform_v1.types import model_deployment_monitoring_job +from google.cloud.aiplatform_v1.types import ( + model_deployment_monitoring_job as gca_model_deployment_monitoring_job, +) +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from google.protobuf import empty_pb2 # type: ignore from .base import JobServiceTransport, DEFAULT_CLIENT_INFO @@ -48,7 +55,7 @@ class JobServiceGrpcAsyncIOTransport(JobServiceTransport): """gRPC AsyncIO backend transport for JobService. - A service for creating and managing AI Platform's jobs. + A service for creating and managing Vertex AI's jobs. This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation @@ -93,14 +100,14 @@ def create_channel( aio.Channel: A gRPC AsyncIO channel object. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @@ -118,6 +125,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -141,16 +149,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -159,6 +167,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport @@ -169,7 +179,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -211,13 +221,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -247,7 +261,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel @@ -878,5 +892,474 @@ def cancel_batch_prediction_job( ) return self._stubs["cancel_batch_prediction_job"] + @property + def create_model_deployment_monitoring_job( + self, + ) -> Callable[ + [job_service.CreateModelDeploymentMonitoringJobRequest], + Awaitable[gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob], + ]: + r"""Return a callable for the create model deployment + monitoring job method over gRPC. + + Creates a ModelDeploymentMonitoringJob. It will run + periodically on a configured interval. + + Returns: + Callable[[~.CreateModelDeploymentMonitoringJobRequest], + Awaitable[~.ModelDeploymentMonitoringJob]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_model_deployment_monitoring_job" not in self._stubs: + self._stubs[ + "create_model_deployment_monitoring_job" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.JobService/CreateModelDeploymentMonitoringJob", + request_serializer=job_service.CreateModelDeploymentMonitoringJobRequest.serialize, + response_deserializer=gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob.deserialize, + ) + return self._stubs["create_model_deployment_monitoring_job"] + + @property + def search_model_deployment_monitoring_stats_anomalies( + self, + ) -> Callable[ + [job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest], + Awaitable[job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse], + ]: + r"""Return a callable for the search model deployment + monitoring stats anomalies method over gRPC. + + Searches Model Monitoring Statistics generated within + a given time window. + + Returns: + Callable[[~.SearchModelDeploymentMonitoringStatsAnomaliesRequest], + Awaitable[~.SearchModelDeploymentMonitoringStatsAnomaliesResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "search_model_deployment_monitoring_stats_anomalies" not in self._stubs: + self._stubs[ + "search_model_deployment_monitoring_stats_anomalies" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.JobService/SearchModelDeploymentMonitoringStatsAnomalies", + request_serializer=job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest.serialize, + response_deserializer=job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse.deserialize, + ) + return self._stubs["search_model_deployment_monitoring_stats_anomalies"] + + @property + def get_model_deployment_monitoring_job( + self, + ) -> Callable[ + [job_service.GetModelDeploymentMonitoringJobRequest], + Awaitable[model_deployment_monitoring_job.ModelDeploymentMonitoringJob], + ]: + r"""Return a callable for the get model deployment + monitoring job method over gRPC. + + Gets a ModelDeploymentMonitoringJob. + + Returns: + Callable[[~.GetModelDeploymentMonitoringJobRequest], + Awaitable[~.ModelDeploymentMonitoringJob]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_model_deployment_monitoring_job" not in self._stubs: + self._stubs[ + "get_model_deployment_monitoring_job" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.JobService/GetModelDeploymentMonitoringJob", + request_serializer=job_service.GetModelDeploymentMonitoringJobRequest.serialize, + response_deserializer=model_deployment_monitoring_job.ModelDeploymentMonitoringJob.deserialize, + ) + return self._stubs["get_model_deployment_monitoring_job"] + + @property + def list_model_deployment_monitoring_jobs( + self, + ) -> Callable[ + [job_service.ListModelDeploymentMonitoringJobsRequest], + Awaitable[job_service.ListModelDeploymentMonitoringJobsResponse], + ]: + r"""Return a callable for the list model deployment + monitoring jobs method over gRPC. + + Lists ModelDeploymentMonitoringJobs in a Location. + + Returns: + Callable[[~.ListModelDeploymentMonitoringJobsRequest], + Awaitable[~.ListModelDeploymentMonitoringJobsResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_model_deployment_monitoring_jobs" not in self._stubs: + self._stubs[ + "list_model_deployment_monitoring_jobs" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.JobService/ListModelDeploymentMonitoringJobs", + request_serializer=job_service.ListModelDeploymentMonitoringJobsRequest.serialize, + response_deserializer=job_service.ListModelDeploymentMonitoringJobsResponse.deserialize, + ) + return self._stubs["list_model_deployment_monitoring_jobs"] + + @property + def update_model_deployment_monitoring_job( + self, + ) -> Callable[ + [job_service.UpdateModelDeploymentMonitoringJobRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the update model deployment + monitoring job method over gRPC. + + Updates a ModelDeploymentMonitoringJob. + + Returns: + Callable[[~.UpdateModelDeploymentMonitoringJobRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_model_deployment_monitoring_job" not in self._stubs: + self._stubs[ + "update_model_deployment_monitoring_job" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.JobService/UpdateModelDeploymentMonitoringJob", + request_serializer=job_service.UpdateModelDeploymentMonitoringJobRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["update_model_deployment_monitoring_job"] + + @property + def delete_model_deployment_monitoring_job( + self, + ) -> Callable[ + [job_service.DeleteModelDeploymentMonitoringJobRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the delete model deployment + monitoring job method over gRPC. + + Deletes a ModelDeploymentMonitoringJob. + + Returns: + Callable[[~.DeleteModelDeploymentMonitoringJobRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_model_deployment_monitoring_job" not in self._stubs: + self._stubs[ + "delete_model_deployment_monitoring_job" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.JobService/DeleteModelDeploymentMonitoringJob", + request_serializer=job_service.DeleteModelDeploymentMonitoringJobRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_model_deployment_monitoring_job"] + + @property + def pause_model_deployment_monitoring_job( + self, + ) -> Callable[ + [job_service.PauseModelDeploymentMonitoringJobRequest], + Awaitable[empty_pb2.Empty], + ]: + r"""Return a callable for the pause model deployment + monitoring job method over gRPC. + + Pauses a ModelDeploymentMonitoringJob. If the job is running, + the server makes a best effort to cancel the job. Will mark + [ModelDeploymentMonitoringJob.state][google.cloud.aiplatform.v1.ModelDeploymentMonitoringJob.state] + to 'PAUSED'. + + Returns: + Callable[[~.PauseModelDeploymentMonitoringJobRequest], + Awaitable[~.Empty]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "pause_model_deployment_monitoring_job" not in self._stubs: + self._stubs[ + "pause_model_deployment_monitoring_job" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.JobService/PauseModelDeploymentMonitoringJob", + request_serializer=job_service.PauseModelDeploymentMonitoringJobRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs["pause_model_deployment_monitoring_job"] + + @property + def resume_model_deployment_monitoring_job( + self, + ) -> Callable[ + [job_service.ResumeModelDeploymentMonitoringJobRequest], + Awaitable[empty_pb2.Empty], + ]: + r"""Return a callable for the resume model deployment + monitoring job method over gRPC. + + Resumes a paused ModelDeploymentMonitoringJob. It + will start to run from next scheduled time. A deleted + ModelDeploymentMonitoringJob can't be resumed. + + Returns: + Callable[[~.ResumeModelDeploymentMonitoringJobRequest], + Awaitable[~.Empty]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "resume_model_deployment_monitoring_job" not in self._stubs: + self._stubs[ + "resume_model_deployment_monitoring_job" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.JobService/ResumeModelDeploymentMonitoringJob", + request_serializer=job_service.ResumeModelDeploymentMonitoringJobRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs["resume_model_deployment_monitoring_job"] + + def close(self): + return self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + __all__ = ("JobServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/aiplatform_v1/services/metadata_service/__init__.py b/google/cloud/aiplatform_v1/services/metadata_service/__init__.py new file mode 100644 index 0000000000..090778e891 --- /dev/null +++ b/google/cloud/aiplatform_v1/services/metadata_service/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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 .client import MetadataServiceClient +from .async_client import MetadataServiceAsyncClient + +__all__ = ( + "MetadataServiceClient", + "MetadataServiceAsyncClient", +) diff --git a/google/cloud/aiplatform_v1/services/metadata_service/async_client.py b/google/cloud/aiplatform_v1/services/metadata_service/async_client.py new file mode 100644 index 0000000000..27be98a4c5 --- /dev/null +++ b/google/cloud/aiplatform_v1/services/metadata_service/async_client.py @@ -0,0 +1,4390 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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, Mapping, Optional, Sequence, Tuple, Type, Union +import pkg_resources + +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore + +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + +from google.api_core import operation as gac_operation # type: ignore +from google.api_core import operation_async # type: ignore +from google.cloud.aiplatform_v1.services.metadata_service import pagers +from google.cloud.aiplatform_v1.types import artifact +from google.cloud.aiplatform_v1.types import artifact as gca_artifact +from google.cloud.aiplatform_v1.types import context +from google.cloud.aiplatform_v1.types import context as gca_context +from google.cloud.aiplatform_v1.types import encryption_spec +from google.cloud.aiplatform_v1.types import event +from google.cloud.aiplatform_v1.types import execution +from google.cloud.aiplatform_v1.types import execution as gca_execution +from google.cloud.aiplatform_v1.types import lineage_subgraph +from google.cloud.aiplatform_v1.types import metadata_schema +from google.cloud.aiplatform_v1.types import metadata_schema as gca_metadata_schema +from google.cloud.aiplatform_v1.types import metadata_service +from google.cloud.aiplatform_v1.types import metadata_store +from google.cloud.aiplatform_v1.types import metadata_store as gca_metadata_store +from google.cloud.aiplatform_v1.types import operation as gca_operation +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import struct_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from .transports.base import MetadataServiceTransport, DEFAULT_CLIENT_INFO +from .transports.grpc_asyncio import MetadataServiceGrpcAsyncIOTransport +from .client import MetadataServiceClient + + +class MetadataServiceAsyncClient: + """Service for reading and writing metadata entries.""" + + _client: MetadataServiceClient + + DEFAULT_ENDPOINT = MetadataServiceClient.DEFAULT_ENDPOINT + DEFAULT_MTLS_ENDPOINT = MetadataServiceClient.DEFAULT_MTLS_ENDPOINT + + artifact_path = staticmethod(MetadataServiceClient.artifact_path) + parse_artifact_path = staticmethod(MetadataServiceClient.parse_artifact_path) + context_path = staticmethod(MetadataServiceClient.context_path) + parse_context_path = staticmethod(MetadataServiceClient.parse_context_path) + execution_path = staticmethod(MetadataServiceClient.execution_path) + parse_execution_path = staticmethod(MetadataServiceClient.parse_execution_path) + metadata_schema_path = staticmethod(MetadataServiceClient.metadata_schema_path) + parse_metadata_schema_path = staticmethod( + MetadataServiceClient.parse_metadata_schema_path + ) + metadata_store_path = staticmethod(MetadataServiceClient.metadata_store_path) + parse_metadata_store_path = staticmethod( + MetadataServiceClient.parse_metadata_store_path + ) + common_billing_account_path = staticmethod( + MetadataServiceClient.common_billing_account_path + ) + parse_common_billing_account_path = staticmethod( + MetadataServiceClient.parse_common_billing_account_path + ) + common_folder_path = staticmethod(MetadataServiceClient.common_folder_path) + parse_common_folder_path = staticmethod( + MetadataServiceClient.parse_common_folder_path + ) + common_organization_path = staticmethod( + MetadataServiceClient.common_organization_path + ) + parse_common_organization_path = staticmethod( + MetadataServiceClient.parse_common_organization_path + ) + common_project_path = staticmethod(MetadataServiceClient.common_project_path) + parse_common_project_path = staticmethod( + MetadataServiceClient.parse_common_project_path + ) + common_location_path = staticmethod(MetadataServiceClient.common_location_path) + parse_common_location_path = staticmethod( + MetadataServiceClient.parse_common_location_path + ) + + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials + info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + MetadataServiceAsyncClient: The constructed client. + """ + return MetadataServiceClient.from_service_account_info.__func__(MetadataServiceAsyncClient, info, *args, **kwargs) # type: ignore + + @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: + MetadataServiceAsyncClient: The constructed client. + """ + return MetadataServiceClient.from_service_account_file.__func__(MetadataServiceAsyncClient, filename, *args, **kwargs) # type: ignore + + from_service_account_json = from_service_account_file + + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return MetadataServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + + @property + def transport(self) -> MetadataServiceTransport: + """Returns the transport used by the client instance. + + Returns: + MetadataServiceTransport: The transport used by the client instance. + """ + return self._client.transport + + get_transport_class = functools.partial( + type(MetadataServiceClient).get_transport_class, type(MetadataServiceClient) + ) + + def __init__( + self, + *, + credentials: ga_credentials.Credentials = None, + transport: Union[str, MetadataServiceTransport] = "grpc_asyncio", + client_options: ClientOptions = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the metadata 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, ~.MetadataServiceTransport]): 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 = MetadataServiceClient( + credentials=credentials, + transport=transport, + client_options=client_options, + client_info=client_info, + ) + + async def create_metadata_store( + self, + request: Union[metadata_service.CreateMetadataStoreRequest, dict] = None, + *, + parent: str = None, + metadata_store: gca_metadata_store.MetadataStore = None, + metadata_store_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Initializes a MetadataStore, including allocation of + resources. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_create_metadata_store(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateMetadataStoreRequest( + parent="parent_value", + ) + + # Make the request + operation = client.create_metadata_store(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CreateMetadataStoreRequest, dict]): + The request object. Request message for + [MetadataService.CreateMetadataStore][google.cloud.aiplatform.v1.MetadataService.CreateMetadataStore]. + parent (:class:`str`): + Required. The resource name of the Location where the + MetadataStore should be created. Format: + ``projects/{project}/locations/{location}/`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + metadata_store (:class:`google.cloud.aiplatform_v1.types.MetadataStore`): + Required. The MetadataStore to + create. + + This corresponds to the ``metadata_store`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + metadata_store_id (:class:`str`): + The {metadatastore} portion of the resource name with + the format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + If not provided, the MetadataStore's ID will be a UUID + generated by the service. Must be 4-128 characters in + length. Valid characters are ``/[a-z][0-9]-/``. Must be + unique across all MetadataStores in the parent Location. + (Otherwise the request will fail with ALREADY_EXISTS, or + PERMISSION_DENIED if the caller can't view the + preexisting MetadataStore.) + + This corresponds to the ``metadata_store_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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.cloud.aiplatform_v1.types.MetadataStore` Instance of a metadata store. Contains a set of metadata that can be + queried. + + """ + # Create or coerce a protobuf request object. + # Quick 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, metadata_store, metadata_store_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 = metadata_service.CreateMetadataStoreRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if metadata_store is not None: + request.metadata_store = metadata_store + if metadata_store_id is not None: + request.metadata_store_id = metadata_store_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_metadata_store, + default_timeout=None, + 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, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + gca_metadata_store.MetadataStore, + metadata_type=metadata_service.CreateMetadataStoreOperationMetadata, + ) + + # Done; return the response. + return response + + async def get_metadata_store( + self, + request: Union[metadata_service.GetMetadataStoreRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> metadata_store.MetadataStore: + r"""Retrieves a specific MetadataStore. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_get_metadata_store(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetMetadataStoreRequest( + name="name_value", + ) + + # Make the request + response = await client.get_metadata_store(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetMetadataStoreRequest, dict]): + The request object. Request message for + [MetadataService.GetMetadataStore][google.cloud.aiplatform.v1.MetadataService.GetMetadataStore]. + name (:class:`str`): + Required. The resource name of the MetadataStore to + retrieve. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + + 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: + google.cloud.aiplatform_v1.types.MetadataStore: + Instance of a metadata store. + Contains a set of metadata that can be + queried. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = metadata_service.GetMetadataStoreRequest(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_metadata_store, + default_timeout=None, + 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 list_metadata_stores( + self, + request: Union[metadata_service.ListMetadataStoresRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListMetadataStoresAsyncPager: + r"""Lists MetadataStores for a Location. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_list_metadata_stores(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListMetadataStoresRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_metadata_stores(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListMetadataStoresRequest, dict]): + The request object. Request message for + [MetadataService.ListMetadataStores][google.cloud.aiplatform.v1.MetadataService.ListMetadataStores]. + parent (:class:`str`): + Required. The Location whose MetadataStores should be + listed. Format: + ``projects/{project}/locations/{location}`` + + 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: + google.cloud.aiplatform_v1.services.metadata_service.pagers.ListMetadataStoresAsyncPager: + Response message for + [MetadataService.ListMetadataStores][google.cloud.aiplatform.v1.MetadataService.ListMetadataStores]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = metadata_service.ListMetadataStoresRequest(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_metadata_stores, + default_timeout=None, + 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.ListMetadataStoresAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def delete_metadata_store( + self, + request: Union[metadata_service.DeleteMetadataStoreRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Deletes a single MetadataStore and all its child + resources (Artifacts, Executions, and Contexts). + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_delete_metadata_store(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteMetadataStoreRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_metadata_store(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.DeleteMetadataStoreRequest, dict]): + The request object. Request message for + [MetadataService.DeleteMetadataStore][google.cloud.aiplatform.v1.MetadataService.DeleteMetadataStore]. + name (:class:`str`): + Required. The resource name of the MetadataStore to + delete. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + + 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = metadata_service.DeleteMetadataStoreRequest(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_metadata_store, + default_timeout=None, + 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, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + empty_pb2.Empty, + metadata_type=metadata_service.DeleteMetadataStoreOperationMetadata, + ) + + # Done; return the response. + return response + + async def create_artifact( + self, + request: Union[metadata_service.CreateArtifactRequest, dict] = None, + *, + parent: str = None, + artifact: gca_artifact.Artifact = None, + artifact_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_artifact.Artifact: + r"""Creates an Artifact associated with a MetadataStore. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_create_artifact(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateArtifactRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_artifact(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CreateArtifactRequest, dict]): + The request object. Request message for + [MetadataService.CreateArtifact][google.cloud.aiplatform.v1.MetadataService.CreateArtifact]. + parent (:class:`str`): + Required. The resource name of the MetadataStore where + the Artifact should be created. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + artifact (:class:`google.cloud.aiplatform_v1.types.Artifact`): + Required. The Artifact to create. + This corresponds to the ``artifact`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + artifact_id (:class:`str`): + The {artifact} portion of the resource name with the + format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact}`` + If not provided, the Artifact's ID will be a UUID + generated by the service. Must be 4-128 characters in + length. Valid characters are ``/[a-z][0-9]-/``. Must be + unique across all Artifacts in the parent MetadataStore. + (Otherwise the request will fail with ALREADY_EXISTS, or + PERMISSION_DENIED if the caller can't view the + preexisting Artifact.) + + This corresponds to the ``artifact_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: + google.cloud.aiplatform_v1.types.Artifact: + Instance of a general artifact. + """ + # Create or coerce a protobuf request object. + # Quick 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, artifact, artifact_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 = metadata_service.CreateArtifactRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if artifact is not None: + request.artifact = artifact + if artifact_id is not None: + request.artifact_id = artifact_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_artifact, + default_timeout=None, + 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 get_artifact( + self, + request: Union[metadata_service.GetArtifactRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> artifact.Artifact: + r"""Retrieves a specific Artifact. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_get_artifact(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetArtifactRequest( + name="name_value", + ) + + # Make the request + response = await client.get_artifact(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetArtifactRequest, dict]): + The request object. Request message for + [MetadataService.GetArtifact][google.cloud.aiplatform.v1.MetadataService.GetArtifact]. + name (:class:`str`): + Required. The resource name of the Artifact to retrieve. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact}`` + + 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: + google.cloud.aiplatform_v1.types.Artifact: + Instance of a general artifact. + """ + # Create or coerce a protobuf request object. + # Quick 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 = metadata_service.GetArtifactRequest(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_artifact, + default_timeout=None, + 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 list_artifacts( + self, + request: Union[metadata_service.ListArtifactsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListArtifactsAsyncPager: + r"""Lists Artifacts in the MetadataStore. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_list_artifacts(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListArtifactsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_artifacts(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListArtifactsRequest, dict]): + The request object. Request message for + [MetadataService.ListArtifacts][google.cloud.aiplatform.v1.MetadataService.ListArtifacts]. + parent (:class:`str`): + Required. The MetadataStore whose Artifacts should be + listed. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + + 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: + google.cloud.aiplatform_v1.services.metadata_service.pagers.ListArtifactsAsyncPager: + Response message for + [MetadataService.ListArtifacts][google.cloud.aiplatform.v1.MetadataService.ListArtifacts]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = metadata_service.ListArtifactsRequest(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_artifacts, + default_timeout=None, + 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.ListArtifactsAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def update_artifact( + self, + request: Union[metadata_service.UpdateArtifactRequest, dict] = None, + *, + artifact: gca_artifact.Artifact = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_artifact.Artifact: + r"""Updates a stored Artifact. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_update_artifact(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.UpdateArtifactRequest( + ) + + # Make the request + response = await client.update_artifact(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.UpdateArtifactRequest, dict]): + The request object. Request message for + [MetadataService.UpdateArtifact][google.cloud.aiplatform.v1.MetadataService.UpdateArtifact]. + artifact (:class:`google.cloud.aiplatform_v1.types.Artifact`): + Required. The Artifact containing updates. The + Artifact's + [Artifact.name][google.cloud.aiplatform.v1.Artifact.name] + field is used to identify the Artifact to be updated. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact}`` + + This corresponds to the ``artifact`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + Optional. A FieldMask indicating + which fields should be updated. + Functionality of this field is not yet + supported. + + 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: + google.cloud.aiplatform_v1.types.Artifact: + Instance of a general artifact. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([artifact, 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 = metadata_service.UpdateArtifactRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if artifact is not None: + request.artifact = artifact + 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_artifact, + default_timeout=None, + 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( + (("artifact.name", request.artifact.name),) + ), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def delete_artifact( + self, + request: Union[metadata_service.DeleteArtifactRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Deletes an Artifact. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_delete_artifact(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteArtifactRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_artifact(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.DeleteArtifactRequest, dict]): + The request object. Request message for + [MetadataService.DeleteArtifact][google.cloud.aiplatform.v1.MetadataService.DeleteArtifact]. + name (:class:`str`): + Required. The resource name of the Artifact to delete. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact}`` + + 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = metadata_service.DeleteArtifactRequest(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_artifact, + default_timeout=None, + 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, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, + ) + + # Done; return the response. + return response + + async def purge_artifacts( + self, + request: Union[metadata_service.PurgeArtifactsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Purges Artifacts. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_purge_artifacts(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.PurgeArtifactsRequest( + parent="parent_value", + filter="filter_value", + ) + + # Make the request + operation = client.purge_artifacts(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.PurgeArtifactsRequest, dict]): + The request object. Request message for + [MetadataService.PurgeArtifacts][google.cloud.aiplatform.v1.MetadataService.PurgeArtifacts]. + parent (:class:`str`): + Required. The metadata store to purge Artifacts from. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + + 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.aiplatform_v1.types.PurgeArtifactsResponse` + Response message for + [MetadataService.PurgeArtifacts][google.cloud.aiplatform.v1.MetadataService.PurgeArtifacts]. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = metadata_service.PurgeArtifactsRequest(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.purge_artifacts, + default_timeout=None, + 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, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + metadata_service.PurgeArtifactsResponse, + metadata_type=metadata_service.PurgeArtifactsMetadata, + ) + + # Done; return the response. + return response + + async def create_context( + self, + request: Union[metadata_service.CreateContextRequest, dict] = None, + *, + parent: str = None, + context: gca_context.Context = None, + context_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_context.Context: + r"""Creates a Context associated with a MetadataStore. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_create_context(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateContextRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_context(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CreateContextRequest, dict]): + The request object. Request message for + [MetadataService.CreateContext][google.cloud.aiplatform.v1.MetadataService.CreateContext]. + parent (:class:`str`): + Required. The resource name of the MetadataStore where + the Context should be created. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + context (:class:`google.cloud.aiplatform_v1.types.Context`): + Required. The Context to create. + This corresponds to the ``context`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + context_id (:class:`str`): + The {context} portion of the resource name with the + format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}``. + If not provided, the Context's ID will be a UUID + generated by the service. Must be 4-128 characters in + length. Valid characters are ``/[a-z][0-9]-/``. Must be + unique across all Contexts in the parent MetadataStore. + (Otherwise the request will fail with ALREADY_EXISTS, or + PERMISSION_DENIED if the caller can't view the + preexisting Context.) + + This corresponds to the ``context_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: + google.cloud.aiplatform_v1.types.Context: + Instance of a general context. + """ + # Create or coerce a protobuf request object. + # Quick 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, context, context_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 = metadata_service.CreateContextRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if context is not None: + request.context = context + if context_id is not None: + request.context_id = context_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_context, + default_timeout=None, + 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 get_context( + self, + request: Union[metadata_service.GetContextRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> context.Context: + r"""Retrieves a specific Context. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_get_context(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetContextRequest( + name="name_value", + ) + + # Make the request + response = await client.get_context(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetContextRequest, dict]): + The request object. Request message for + [MetadataService.GetContext][google.cloud.aiplatform.v1.MetadataService.GetContext]. + name (:class:`str`): + Required. The resource name of the Context to retrieve. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` + + 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: + google.cloud.aiplatform_v1.types.Context: + Instance of a general context. + """ + # Create or coerce a protobuf request object. + # Quick 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 = metadata_service.GetContextRequest(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_context, + default_timeout=None, + 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 list_contexts( + self, + request: Union[metadata_service.ListContextsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListContextsAsyncPager: + r"""Lists Contexts on the MetadataStore. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_list_contexts(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListContextsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_contexts(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListContextsRequest, dict]): + The request object. Request message for + [MetadataService.ListContexts][google.cloud.aiplatform.v1.MetadataService.ListContexts] + parent (:class:`str`): + Required. The MetadataStore whose Contexts should be + listed. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + + 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: + google.cloud.aiplatform_v1.services.metadata_service.pagers.ListContextsAsyncPager: + Response message for + [MetadataService.ListContexts][google.cloud.aiplatform.v1.MetadataService.ListContexts]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = metadata_service.ListContextsRequest(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_contexts, + default_timeout=None, + 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.ListContextsAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def update_context( + self, + request: Union[metadata_service.UpdateContextRequest, dict] = None, + *, + context: gca_context.Context = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_context.Context: + r"""Updates a stored Context. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_update_context(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.UpdateContextRequest( + ) + + # Make the request + response = await client.update_context(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.UpdateContextRequest, dict]): + The request object. Request message for + [MetadataService.UpdateContext][google.cloud.aiplatform.v1.MetadataService.UpdateContext]. + context (:class:`google.cloud.aiplatform_v1.types.Context`): + Required. The Context containing updates. The Context's + [Context.name][google.cloud.aiplatform.v1.Context.name] + field is used to identify the Context to be updated. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` + + This corresponds to the ``context`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + Optional. A FieldMask indicating + which fields should be updated. + Functionality of this field is not yet + supported. + + 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: + google.cloud.aiplatform_v1.types.Context: + Instance of a general context. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([context, 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 = metadata_service.UpdateContextRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if context is not None: + request.context = context + 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_context, + default_timeout=None, + 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( + (("context.name", request.context.name),) + ), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def delete_context( + self, + request: Union[metadata_service.DeleteContextRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Deletes a stored Context. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_delete_context(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteContextRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_context(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.DeleteContextRequest, dict]): + The request object. Request message for + [MetadataService.DeleteContext][google.cloud.aiplatform.v1.MetadataService.DeleteContext]. + name (:class:`str`): + Required. The resource name of the Context to delete. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` + + 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = metadata_service.DeleteContextRequest(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_context, + default_timeout=None, + 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, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, + ) + + # Done; return the response. + return response + + async def purge_contexts( + self, + request: Union[metadata_service.PurgeContextsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Purges Contexts. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_purge_contexts(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.PurgeContextsRequest( + parent="parent_value", + filter="filter_value", + ) + + # Make the request + operation = client.purge_contexts(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.PurgeContextsRequest, dict]): + The request object. Request message for + [MetadataService.PurgeContexts][google.cloud.aiplatform.v1.MetadataService.PurgeContexts]. + parent (:class:`str`): + Required. The metadata store to purge Contexts from. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + + 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.aiplatform_v1.types.PurgeContextsResponse` + Response message for + [MetadataService.PurgeContexts][google.cloud.aiplatform.v1.MetadataService.PurgeContexts]. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = metadata_service.PurgeContextsRequest(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.purge_contexts, + default_timeout=None, + 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, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + metadata_service.PurgeContextsResponse, + metadata_type=metadata_service.PurgeContextsMetadata, + ) + + # Done; return the response. + return response + + async def add_context_artifacts_and_executions( + self, + request: Union[ + metadata_service.AddContextArtifactsAndExecutionsRequest, dict + ] = None, + *, + context: str = None, + artifacts: Sequence[str] = None, + executions: Sequence[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> metadata_service.AddContextArtifactsAndExecutionsResponse: + r"""Adds a set of Artifacts and Executions to a Context. + If any of the Artifacts or Executions have already been + added to a Context, they are simply skipped. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_add_context_artifacts_and_executions(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.AddContextArtifactsAndExecutionsRequest( + context="context_value", + ) + + # Make the request + response = await client.add_context_artifacts_and_executions(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.AddContextArtifactsAndExecutionsRequest, dict]): + The request object. Request message for + [MetadataService.AddContextArtifactsAndExecutions][google.cloud.aiplatform.v1.MetadataService.AddContextArtifactsAndExecutions]. + context (:class:`str`): + Required. The resource name of the Context that the + Artifacts and Executions belong to. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` + + This corresponds to the ``context`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + artifacts (:class:`Sequence[str]`): + The resource names of the Artifacts to attribute to the + Context. + + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact}`` + + This corresponds to the ``artifacts`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + executions (:class:`Sequence[str]`): + The resource names of the Executions to associate with + the Context. + + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` + + This corresponds to the ``executions`` 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: + google.cloud.aiplatform_v1.types.AddContextArtifactsAndExecutionsResponse: + Response message for + [MetadataService.AddContextArtifactsAndExecutions][google.cloud.aiplatform.v1.MetadataService.AddContextArtifactsAndExecutions]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([context, artifacts, executions]) + 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 = metadata_service.AddContextArtifactsAndExecutionsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if context is not None: + request.context = context + if artifacts: + request.artifacts.extend(artifacts) + if executions: + request.executions.extend(executions) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.add_context_artifacts_and_executions, + default_timeout=None, + 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((("context", request.context),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def add_context_children( + self, + request: Union[metadata_service.AddContextChildrenRequest, dict] = None, + *, + context: str = None, + child_contexts: Sequence[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> metadata_service.AddContextChildrenResponse: + r"""Adds a set of Contexts as children to a parent Context. If any + of the child Contexts have already been added to the parent + Context, they are simply skipped. If this call would create a + cycle or cause any Context to have more than 10 parents, the + request will fail with an INVALID_ARGUMENT error. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_add_context_children(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.AddContextChildrenRequest( + context="context_value", + ) + + # Make the request + response = await client.add_context_children(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.AddContextChildrenRequest, dict]): + The request object. Request message for + [MetadataService.AddContextChildren][google.cloud.aiplatform.v1.MetadataService.AddContextChildren]. + context (:class:`str`): + Required. The resource name of the parent Context. + + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` + + This corresponds to the ``context`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + child_contexts (:class:`Sequence[str]`): + The resource names of the child + Contexts. + + This corresponds to the ``child_contexts`` 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: + google.cloud.aiplatform_v1.types.AddContextChildrenResponse: + Response message for + [MetadataService.AddContextChildren][google.cloud.aiplatform.v1.MetadataService.AddContextChildren]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([context, child_contexts]) + 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 = metadata_service.AddContextChildrenRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if context is not None: + request.context = context + if child_contexts: + request.child_contexts.extend(child_contexts) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.add_context_children, + default_timeout=None, + 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((("context", request.context),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def query_context_lineage_subgraph( + self, + request: Union[ + metadata_service.QueryContextLineageSubgraphRequest, dict + ] = None, + *, + context: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> lineage_subgraph.LineageSubgraph: + r"""Retrieves Artifacts and Executions within the + specified Context, connected by Event edges and returned + as a LineageSubgraph. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_query_context_lineage_subgraph(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.QueryContextLineageSubgraphRequest( + context="context_value", + ) + + # Make the request + response = await client.query_context_lineage_subgraph(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.QueryContextLineageSubgraphRequest, dict]): + The request object. Request message for + [MetadataService.QueryContextLineageSubgraph][google.cloud.aiplatform.v1.MetadataService.QueryContextLineageSubgraph]. + context (:class:`str`): + Required. The resource name of the Context whose + Artifacts and Executions should be retrieved as a + LineageSubgraph. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` + + The request may error with FAILED_PRECONDITION if the + number of Artifacts, the number of Executions, or the + number of Events that would be returned for the Context + exceeds 1000. + + This corresponds to the ``context`` 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: + google.cloud.aiplatform_v1.types.LineageSubgraph: + A subgraph of the overall lineage + graph. Event edges connect Artifact and + Execution nodes. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([context]) + 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 = metadata_service.QueryContextLineageSubgraphRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if context is not None: + request.context = context + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.query_context_lineage_subgraph, + default_timeout=None, + 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((("context", request.context),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def create_execution( + self, + request: Union[metadata_service.CreateExecutionRequest, dict] = None, + *, + parent: str = None, + execution: gca_execution.Execution = None, + execution_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_execution.Execution: + r"""Creates an Execution associated with a MetadataStore. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_create_execution(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateExecutionRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_execution(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CreateExecutionRequest, dict]): + The request object. Request message for + [MetadataService.CreateExecution][google.cloud.aiplatform.v1.MetadataService.CreateExecution]. + parent (:class:`str`): + Required. The resource name of the MetadataStore where + the Execution should be created. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + execution (:class:`google.cloud.aiplatform_v1.types.Execution`): + Required. The Execution to create. + This corresponds to the ``execution`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + execution_id (:class:`str`): + The {execution} portion of the resource name with the + format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` + If not provided, the Execution's ID will be a UUID + generated by the service. Must be 4-128 characters in + length. Valid characters are ``/[a-z][0-9]-/``. Must be + unique across all Executions in the parent + MetadataStore. (Otherwise the request will fail with + ALREADY_EXISTS, or PERMISSION_DENIED if the caller can't + view the preexisting Execution.) + + This corresponds to the ``execution_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: + google.cloud.aiplatform_v1.types.Execution: + Instance of a general execution. + """ + # Create or coerce a protobuf request object. + # Quick 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, execution, execution_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 = metadata_service.CreateExecutionRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if execution is not None: + request.execution = execution + if execution_id is not None: + request.execution_id = execution_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_execution, + default_timeout=None, + 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 get_execution( + self, + request: Union[metadata_service.GetExecutionRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> execution.Execution: + r"""Retrieves a specific Execution. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_get_execution(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetExecutionRequest( + name="name_value", + ) + + # Make the request + response = await client.get_execution(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetExecutionRequest, dict]): + The request object. Request message for + [MetadataService.GetExecution][google.cloud.aiplatform.v1.MetadataService.GetExecution]. + name (:class:`str`): + Required. The resource name of the Execution to + retrieve. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` + + 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: + google.cloud.aiplatform_v1.types.Execution: + Instance of a general execution. + """ + # Create or coerce a protobuf request object. + # Quick 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 = metadata_service.GetExecutionRequest(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_execution, + default_timeout=None, + 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 list_executions( + self, + request: Union[metadata_service.ListExecutionsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListExecutionsAsyncPager: + r"""Lists Executions in the MetadataStore. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_list_executions(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListExecutionsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_executions(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListExecutionsRequest, dict]): + The request object. Request message for + [MetadataService.ListExecutions][google.cloud.aiplatform.v1.MetadataService.ListExecutions]. + parent (:class:`str`): + Required. The MetadataStore whose Executions should be + listed. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + + 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: + google.cloud.aiplatform_v1.services.metadata_service.pagers.ListExecutionsAsyncPager: + Response message for + [MetadataService.ListExecutions][google.cloud.aiplatform.v1.MetadataService.ListExecutions]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = metadata_service.ListExecutionsRequest(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_executions, + default_timeout=None, + 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.ListExecutionsAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def update_execution( + self, + request: Union[metadata_service.UpdateExecutionRequest, dict] = None, + *, + execution: gca_execution.Execution = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_execution.Execution: + r"""Updates a stored Execution. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_update_execution(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.UpdateExecutionRequest( + ) + + # Make the request + response = await client.update_execution(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.UpdateExecutionRequest, dict]): + The request object. Request message for + [MetadataService.UpdateExecution][google.cloud.aiplatform.v1.MetadataService.UpdateExecution]. + execution (:class:`google.cloud.aiplatform_v1.types.Execution`): + Required. The Execution containing updates. The + Execution's + [Execution.name][google.cloud.aiplatform.v1.Execution.name] + field is used to identify the Execution to be updated. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` + + This corresponds to the ``execution`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + Optional. A FieldMask indicating + which fields should be updated. + Functionality of this field is not yet + supported. + + 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: + google.cloud.aiplatform_v1.types.Execution: + Instance of a general execution. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([execution, 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 = metadata_service.UpdateExecutionRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if execution is not None: + request.execution = execution + 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_execution, + default_timeout=None, + 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( + (("execution.name", request.execution.name),) + ), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def delete_execution( + self, + request: Union[metadata_service.DeleteExecutionRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Deletes an Execution. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_delete_execution(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteExecutionRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_execution(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.DeleteExecutionRequest, dict]): + The request object. Request message for + [MetadataService.DeleteExecution][google.cloud.aiplatform.v1.MetadataService.DeleteExecution]. + name (:class:`str`): + Required. The resource name of the Execution to delete. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` + + 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = metadata_service.DeleteExecutionRequest(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_execution, + default_timeout=None, + 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, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, + ) + + # Done; return the response. + return response + + async def purge_executions( + self, + request: Union[metadata_service.PurgeExecutionsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Purges Executions. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_purge_executions(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.PurgeExecutionsRequest( + parent="parent_value", + filter="filter_value", + ) + + # Make the request + operation = client.purge_executions(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.PurgeExecutionsRequest, dict]): + The request object. Request message for + [MetadataService.PurgeExecutions][google.cloud.aiplatform.v1.MetadataService.PurgeExecutions]. + parent (:class:`str`): + Required. The metadata store to purge Executions from. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + + 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.aiplatform_v1.types.PurgeExecutionsResponse` + Response message for + [MetadataService.PurgeExecutions][google.cloud.aiplatform.v1.MetadataService.PurgeExecutions]. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = metadata_service.PurgeExecutionsRequest(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.purge_executions, + default_timeout=None, + 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, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + metadata_service.PurgeExecutionsResponse, + metadata_type=metadata_service.PurgeExecutionsMetadata, + ) + + # Done; return the response. + return response + + async def add_execution_events( + self, + request: Union[metadata_service.AddExecutionEventsRequest, dict] = None, + *, + execution: str = None, + events: Sequence[event.Event] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> metadata_service.AddExecutionEventsResponse: + r"""Adds Events to the specified Execution. An Event + indicates whether an Artifact was used as an input or + output for an Execution. If an Event already exists + between the Execution and the Artifact, the Event is + skipped. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_add_execution_events(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.AddExecutionEventsRequest( + execution="execution_value", + ) + + # Make the request + response = await client.add_execution_events(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.AddExecutionEventsRequest, dict]): + The request object. Request message for + [MetadataService.AddExecutionEvents][google.cloud.aiplatform.v1.MetadataService.AddExecutionEvents]. + execution (:class:`str`): + Required. The resource name of the Execution that the + Events connect Artifacts with. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` + + This corresponds to the ``execution`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + events (:class:`Sequence[google.cloud.aiplatform_v1.types.Event]`): + The Events to create and add. + This corresponds to the ``events`` 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: + google.cloud.aiplatform_v1.types.AddExecutionEventsResponse: + Response message for + [MetadataService.AddExecutionEvents][google.cloud.aiplatform.v1.MetadataService.AddExecutionEvents]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([execution, events]) + 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 = metadata_service.AddExecutionEventsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if execution is not None: + request.execution = execution + if events: + request.events.extend(events) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.add_execution_events, + default_timeout=None, + 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( + (("execution", request.execution),) + ), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def query_execution_inputs_and_outputs( + self, + request: Union[ + metadata_service.QueryExecutionInputsAndOutputsRequest, dict + ] = None, + *, + execution: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> lineage_subgraph.LineageSubgraph: + r"""Obtains the set of input and output Artifacts for + this Execution, in the form of LineageSubgraph that also + contains the Execution and connecting Events. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_query_execution_inputs_and_outputs(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.QueryExecutionInputsAndOutputsRequest( + execution="execution_value", + ) + + # Make the request + response = await client.query_execution_inputs_and_outputs(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.QueryExecutionInputsAndOutputsRequest, dict]): + The request object. Request message for + [MetadataService.QueryExecutionInputsAndOutputs][google.cloud.aiplatform.v1.MetadataService.QueryExecutionInputsAndOutputs]. + execution (:class:`str`): + Required. The resource name of the Execution whose input + and output Artifacts should be retrieved as a + LineageSubgraph. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` + + This corresponds to the ``execution`` 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: + google.cloud.aiplatform_v1.types.LineageSubgraph: + A subgraph of the overall lineage + graph. Event edges connect Artifact and + Execution nodes. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([execution]) + 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 = metadata_service.QueryExecutionInputsAndOutputsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if execution is not None: + request.execution = execution + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.query_execution_inputs_and_outputs, + default_timeout=None, + 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( + (("execution", request.execution),) + ), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def create_metadata_schema( + self, + request: Union[metadata_service.CreateMetadataSchemaRequest, dict] = None, + *, + parent: str = None, + metadata_schema: gca_metadata_schema.MetadataSchema = None, + metadata_schema_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_metadata_schema.MetadataSchema: + r"""Creates a MetadataSchema. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_create_metadata_schema(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + metadata_schema = aiplatform_v1.MetadataSchema() + metadata_schema.schema = "schema_value" + + request = aiplatform_v1.CreateMetadataSchemaRequest( + parent="parent_value", + metadata_schema=metadata_schema, + ) + + # Make the request + response = await client.create_metadata_schema(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CreateMetadataSchemaRequest, dict]): + The request object. Request message for + [MetadataService.CreateMetadataSchema][google.cloud.aiplatform.v1.MetadataService.CreateMetadataSchema]. + parent (:class:`str`): + Required. The resource name of the MetadataStore where + the MetadataSchema should be created. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + metadata_schema (:class:`google.cloud.aiplatform_v1.types.MetadataSchema`): + Required. The MetadataSchema to + create. + + This corresponds to the ``metadata_schema`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + metadata_schema_id (:class:`str`): + The {metadata_schema} portion of the resource name with + the format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/metadataSchemas/{metadataschema}`` + If not provided, the MetadataStore's ID will be a UUID + generated by the service. Must be 4-128 characters in + length. Valid characters are ``/[a-z][0-9]-/``. Must be + unique across all MetadataSchemas in the parent + Location. (Otherwise the request will fail with + ALREADY_EXISTS, or PERMISSION_DENIED if the caller can't + view the preexisting MetadataSchema.) + + This corresponds to the ``metadata_schema_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: + google.cloud.aiplatform_v1.types.MetadataSchema: + Instance of a general MetadataSchema. + """ + # Create or coerce a protobuf request object. + # Quick 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, metadata_schema, metadata_schema_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 = metadata_service.CreateMetadataSchemaRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if metadata_schema is not None: + request.metadata_schema = metadata_schema + if metadata_schema_id is not None: + request.metadata_schema_id = metadata_schema_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_metadata_schema, + default_timeout=None, + 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 get_metadata_schema( + self, + request: Union[metadata_service.GetMetadataSchemaRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> metadata_schema.MetadataSchema: + r"""Retrieves a specific MetadataSchema. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_get_metadata_schema(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetMetadataSchemaRequest( + name="name_value", + ) + + # Make the request + response = await client.get_metadata_schema(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetMetadataSchemaRequest, dict]): + The request object. Request message for + [MetadataService.GetMetadataSchema][google.cloud.aiplatform.v1.MetadataService.GetMetadataSchema]. + name (:class:`str`): + Required. The resource name of the MetadataSchema to + retrieve. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/metadataSchemas/{metadataschema}`` + + 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: + google.cloud.aiplatform_v1.types.MetadataSchema: + Instance of a general MetadataSchema. + """ + # Create or coerce a protobuf request object. + # Quick 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 = metadata_service.GetMetadataSchemaRequest(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_metadata_schema, + default_timeout=None, + 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 list_metadata_schemas( + self, + request: Union[metadata_service.ListMetadataSchemasRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListMetadataSchemasAsyncPager: + r"""Lists MetadataSchemas. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_list_metadata_schemas(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListMetadataSchemasRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_metadata_schemas(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListMetadataSchemasRequest, dict]): + The request object. Request message for + [MetadataService.ListMetadataSchemas][google.cloud.aiplatform.v1.MetadataService.ListMetadataSchemas]. + parent (:class:`str`): + Required. The MetadataStore whose MetadataSchemas should + be listed. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + + 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: + google.cloud.aiplatform_v1.services.metadata_service.pagers.ListMetadataSchemasAsyncPager: + Response message for + [MetadataService.ListMetadataSchemas][google.cloud.aiplatform.v1.MetadataService.ListMetadataSchemas]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = metadata_service.ListMetadataSchemasRequest(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_metadata_schemas, + default_timeout=None, + 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.ListMetadataSchemasAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def query_artifact_lineage_subgraph( + self, + request: Union[ + metadata_service.QueryArtifactLineageSubgraphRequest, dict + ] = None, + *, + artifact: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> lineage_subgraph.LineageSubgraph: + r"""Retrieves lineage of an Artifact represented through + Artifacts and Executions connected by Event edges and + returned as a LineageSubgraph. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_query_artifact_lineage_subgraph(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.QueryArtifactLineageSubgraphRequest( + artifact="artifact_value", + ) + + # Make the request + response = await client.query_artifact_lineage_subgraph(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.QueryArtifactLineageSubgraphRequest, dict]): + The request object. Request message for + [MetadataService.QueryArtifactLineageSubgraph][google.cloud.aiplatform.v1.MetadataService.QueryArtifactLineageSubgraph]. + artifact (:class:`str`): + Required. The resource name of the Artifact whose + Lineage needs to be retrieved as a LineageSubgraph. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact}`` + + The request may error with FAILED_PRECONDITION if the + number of Artifacts, the number of Executions, or the + number of Events that would be returned for the Context + exceeds 1000. + + This corresponds to the ``artifact`` 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: + google.cloud.aiplatform_v1.types.LineageSubgraph: + A subgraph of the overall lineage + graph. Event edges connect Artifact and + Execution nodes. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([artifact]) + 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 = metadata_service.QueryArtifactLineageSubgraphRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if artifact is not None: + request.artifact = artifact + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.query_artifact_lineage_subgraph, + default_timeout=None, + 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((("artifact", request.artifact),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_operations, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.delete_operation, + default_timeout=None, + 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 cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + 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 wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.wait_operation, + default_timeout=None, + 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 set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_location, + default_timeout=None, + 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 list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_locations, + default_timeout=None, + 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 __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-aiplatform", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ("MetadataServiceAsyncClient",) diff --git a/google/cloud/aiplatform_v1/services/metadata_service/client.py b/google/cloud/aiplatform_v1/services/metadata_service/client.py new file mode 100644 index 0000000000..9b90ce8c69 --- /dev/null +++ b/google/cloud/aiplatform_v1/services/metadata_service/client.py @@ -0,0 +1,4719 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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 os +import re +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union +import pkg_resources + +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.auth import credentials as ga_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 + +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + +from google.api_core import operation as gac_operation # type: ignore +from google.api_core import operation_async # type: ignore +from google.cloud.aiplatform_v1.services.metadata_service import pagers +from google.cloud.aiplatform_v1.types import artifact +from google.cloud.aiplatform_v1.types import artifact as gca_artifact +from google.cloud.aiplatform_v1.types import context +from google.cloud.aiplatform_v1.types import context as gca_context +from google.cloud.aiplatform_v1.types import encryption_spec +from google.cloud.aiplatform_v1.types import event +from google.cloud.aiplatform_v1.types import execution +from google.cloud.aiplatform_v1.types import execution as gca_execution +from google.cloud.aiplatform_v1.types import lineage_subgraph +from google.cloud.aiplatform_v1.types import metadata_schema +from google.cloud.aiplatform_v1.types import metadata_schema as gca_metadata_schema +from google.cloud.aiplatform_v1.types import metadata_service +from google.cloud.aiplatform_v1.types import metadata_store +from google.cloud.aiplatform_v1.types import metadata_store as gca_metadata_store +from google.cloud.aiplatform_v1.types import operation as gca_operation +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import struct_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from .transports.base import MetadataServiceTransport, DEFAULT_CLIENT_INFO +from .transports.grpc import MetadataServiceGrpcTransport +from .transports.grpc_asyncio import MetadataServiceGrpcAsyncIOTransport + + +class MetadataServiceClientMeta(type): + """Metaclass for the MetadataService 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[MetadataServiceTransport]] + _transport_registry["grpc"] = MetadataServiceGrpcTransport + _transport_registry["grpc_asyncio"] = MetadataServiceGrpcAsyncIOTransport + + def get_transport_class( + cls, + label: str = None, + ) -> Type[MetadataServiceTransport]: + """Returns 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 MetadataServiceClient(metaclass=MetadataServiceClientMeta): + """Service for reading and writing metadata entries.""" + + @staticmethod + def _get_default_mtls_endpoint(api_endpoint): + """Converts 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 = "aiplatform.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials + info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + MetadataServiceClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + + @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: + MetadataServiceClient: 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) -> MetadataServiceTransport: + """Returns the transport used by the client instance. + + Returns: + MetadataServiceTransport: The transport used by the client + instance. + """ + return self._transport + + @staticmethod + def artifact_path( + project: str, + location: str, + metadata_store: str, + artifact: str, + ) -> str: + """Returns a fully-qualified artifact string.""" + return "projects/{project}/locations/{location}/metadataStores/{metadata_store}/artifacts/{artifact}".format( + project=project, + location=location, + metadata_store=metadata_store, + artifact=artifact, + ) + + @staticmethod + def parse_artifact_path(path: str) -> Dict[str, str]: + """Parses a artifact path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/metadataStores/(?P.+?)/artifacts/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def context_path( + project: str, + location: str, + metadata_store: str, + context: str, + ) -> str: + """Returns a fully-qualified context string.""" + return "projects/{project}/locations/{location}/metadataStores/{metadata_store}/contexts/{context}".format( + project=project, + location=location, + metadata_store=metadata_store, + context=context, + ) + + @staticmethod + def parse_context_path(path: str) -> Dict[str, str]: + """Parses a context path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/metadataStores/(?P.+?)/contexts/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def execution_path( + project: str, + location: str, + metadata_store: str, + execution: str, + ) -> str: + """Returns a fully-qualified execution string.""" + return "projects/{project}/locations/{location}/metadataStores/{metadata_store}/executions/{execution}".format( + project=project, + location=location, + metadata_store=metadata_store, + execution=execution, + ) + + @staticmethod + def parse_execution_path(path: str) -> Dict[str, str]: + """Parses a execution path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/metadataStores/(?P.+?)/executions/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def metadata_schema_path( + project: str, + location: str, + metadata_store: str, + metadata_schema: str, + ) -> str: + """Returns a fully-qualified metadata_schema string.""" + return "projects/{project}/locations/{location}/metadataStores/{metadata_store}/metadataSchemas/{metadata_schema}".format( + project=project, + location=location, + metadata_store=metadata_store, + metadata_schema=metadata_schema, + ) + + @staticmethod + def parse_metadata_schema_path(path: str) -> Dict[str, str]: + """Parses a metadata_schema path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/metadataStores/(?P.+?)/metadataSchemas/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def metadata_store_path( + project: str, + location: str, + metadata_store: str, + ) -> str: + """Returns a fully-qualified metadata_store string.""" + return "projects/{project}/locations/{location}/metadataStores/{metadata_store}".format( + project=project, + location=location, + metadata_store=metadata_store, + ) + + @staticmethod + def parse_metadata_store_path(path: str) -> Dict[str, str]: + """Parses a metadata_store path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/metadataStores/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def common_billing_account_path( + billing_account: str, + ) -> str: + """Returns 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: + """Returns 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: + """Returns 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: + """Returns 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: + """Returns 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 {} + + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + + def __init__( + self, + *, + credentials: Optional[ga_credentials.Credentials] = None, + transport: Union[str, MetadataServiceTransport, None] = None, + client_options: Optional[client_options_lib.ClientOptions] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the metadata 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, MetadataServiceTransport]): The + transport to use. If set to None, a transport is chosen + automatically. + client_options (google.api_core.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. + 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() + + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options + ) + + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) + + # 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, MetadataServiceTransport): + # transport is a MetadataServiceTransport instance. + if credentials or client_options.credentials_file or api_key_value: + 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: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + + 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, + client_cert_source_for_mtls=client_cert_source_func, + quota_project_id=client_options.quota_project_id, + client_info=client_info, + always_use_jwt_access=True, + ) + + def create_metadata_store( + self, + request: Union[metadata_service.CreateMetadataStoreRequest, dict] = None, + *, + parent: str = None, + metadata_store: gca_metadata_store.MetadataStore = None, + metadata_store_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Initializes a MetadataStore, including allocation of + resources. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_create_metadata_store(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateMetadataStoreRequest( + parent="parent_value", + ) + + # Make the request + operation = client.create_metadata_store(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CreateMetadataStoreRequest, dict]): + The request object. Request message for + [MetadataService.CreateMetadataStore][google.cloud.aiplatform.v1.MetadataService.CreateMetadataStore]. + parent (str): + Required. The resource name of the Location where the + MetadataStore should be created. Format: + ``projects/{project}/locations/{location}/`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + metadata_store (google.cloud.aiplatform_v1.types.MetadataStore): + Required. The MetadataStore to + create. + + This corresponds to the ``metadata_store`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + metadata_store_id (str): + The {metadatastore} portion of the resource name with + the format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + If not provided, the MetadataStore's ID will be a UUID + generated by the service. Must be 4-128 characters in + length. Valid characters are ``/[a-z][0-9]-/``. Must be + unique across all MetadataStores in the parent Location. + (Otherwise the request will fail with ALREADY_EXISTS, or + PERMISSION_DENIED if the caller can't view the + preexisting MetadataStore.) + + This corresponds to the ``metadata_store_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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.cloud.aiplatform_v1.types.MetadataStore` Instance of a metadata store. Contains a set of metadata that can be + queried. + + """ + # Create or coerce a protobuf request object. + # Quick 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, metadata_store, metadata_store_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 metadata_service.CreateMetadataStoreRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, metadata_service.CreateMetadataStoreRequest): + request = metadata_service.CreateMetadataStoreRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if metadata_store is not None: + request.metadata_store = metadata_store + if metadata_store_id is not None: + request.metadata_store_id = metadata_store_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_metadata_store] + + # 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, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + gca_metadata_store.MetadataStore, + metadata_type=metadata_service.CreateMetadataStoreOperationMetadata, + ) + + # Done; return the response. + return response + + def get_metadata_store( + self, + request: Union[metadata_service.GetMetadataStoreRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> metadata_store.MetadataStore: + r"""Retrieves a specific MetadataStore. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_get_metadata_store(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetMetadataStoreRequest( + name="name_value", + ) + + # Make the request + response = client.get_metadata_store(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetMetadataStoreRequest, dict]): + The request object. Request message for + [MetadataService.GetMetadataStore][google.cloud.aiplatform.v1.MetadataService.GetMetadataStore]. + name (str): + Required. The resource name of the MetadataStore to + retrieve. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + + 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: + google.cloud.aiplatform_v1.types.MetadataStore: + Instance of a metadata store. + Contains a set of metadata that can be + queried. + + """ + # Create or coerce a protobuf request object. + # Quick 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 metadata_service.GetMetadataStoreRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, metadata_service.GetMetadataStoreRequest): + request = metadata_service.GetMetadataStoreRequest(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_metadata_store] + + # 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 list_metadata_stores( + self, + request: Union[metadata_service.ListMetadataStoresRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListMetadataStoresPager: + r"""Lists MetadataStores for a Location. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_list_metadata_stores(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListMetadataStoresRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_metadata_stores(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListMetadataStoresRequest, dict]): + The request object. Request message for + [MetadataService.ListMetadataStores][google.cloud.aiplatform.v1.MetadataService.ListMetadataStores]. + parent (str): + Required. The Location whose MetadataStores should be + listed. Format: + ``projects/{project}/locations/{location}`` + + 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: + google.cloud.aiplatform_v1.services.metadata_service.pagers.ListMetadataStoresPager: + Response message for + [MetadataService.ListMetadataStores][google.cloud.aiplatform.v1.MetadataService.ListMetadataStores]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 metadata_service.ListMetadataStoresRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, metadata_service.ListMetadataStoresRequest): + request = metadata_service.ListMetadataStoresRequest(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_metadata_stores] + + # 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.ListMetadataStoresPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_metadata_store( + self, + request: Union[metadata_service.DeleteMetadataStoreRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Deletes a single MetadataStore and all its child + resources (Artifacts, Executions, and Contexts). + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_delete_metadata_store(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteMetadataStoreRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_metadata_store(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.DeleteMetadataStoreRequest, dict]): + The request object. Request message for + [MetadataService.DeleteMetadataStore][google.cloud.aiplatform.v1.MetadataService.DeleteMetadataStore]. + name (str): + Required. The resource name of the MetadataStore to + delete. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + + 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # Create or coerce a protobuf request object. + # Quick 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 metadata_service.DeleteMetadataStoreRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, metadata_service.DeleteMetadataStoreRequest): + request = metadata_service.DeleteMetadataStoreRequest(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_metadata_store] + + # 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, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + empty_pb2.Empty, + metadata_type=metadata_service.DeleteMetadataStoreOperationMetadata, + ) + + # Done; return the response. + return response + + def create_artifact( + self, + request: Union[metadata_service.CreateArtifactRequest, dict] = None, + *, + parent: str = None, + artifact: gca_artifact.Artifact = None, + artifact_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_artifact.Artifact: + r"""Creates an Artifact associated with a MetadataStore. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_create_artifact(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateArtifactRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_artifact(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CreateArtifactRequest, dict]): + The request object. Request message for + [MetadataService.CreateArtifact][google.cloud.aiplatform.v1.MetadataService.CreateArtifact]. + parent (str): + Required. The resource name of the MetadataStore where + the Artifact should be created. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + artifact (google.cloud.aiplatform_v1.types.Artifact): + Required. The Artifact to create. + This corresponds to the ``artifact`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + artifact_id (str): + The {artifact} portion of the resource name with the + format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact}`` + If not provided, the Artifact's ID will be a UUID + generated by the service. Must be 4-128 characters in + length. Valid characters are ``/[a-z][0-9]-/``. Must be + unique across all Artifacts in the parent MetadataStore. + (Otherwise the request will fail with ALREADY_EXISTS, or + PERMISSION_DENIED if the caller can't view the + preexisting Artifact.) + + This corresponds to the ``artifact_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: + google.cloud.aiplatform_v1.types.Artifact: + Instance of a general artifact. + """ + # Create or coerce a protobuf request object. + # Quick 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, artifact, artifact_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 metadata_service.CreateArtifactRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, metadata_service.CreateArtifactRequest): + request = metadata_service.CreateArtifactRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if artifact is not None: + request.artifact = artifact + if artifact_id is not None: + request.artifact_id = artifact_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_artifact] + + # 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 get_artifact( + self, + request: Union[metadata_service.GetArtifactRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> artifact.Artifact: + r"""Retrieves a specific Artifact. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_get_artifact(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetArtifactRequest( + name="name_value", + ) + + # Make the request + response = client.get_artifact(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetArtifactRequest, dict]): + The request object. Request message for + [MetadataService.GetArtifact][google.cloud.aiplatform.v1.MetadataService.GetArtifact]. + name (str): + Required. The resource name of the Artifact to retrieve. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact}`` + + 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: + google.cloud.aiplatform_v1.types.Artifact: + Instance of a general artifact. + """ + # Create or coerce a protobuf request object. + # Quick 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 metadata_service.GetArtifactRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, metadata_service.GetArtifactRequest): + request = metadata_service.GetArtifactRequest(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_artifact] + + # 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 list_artifacts( + self, + request: Union[metadata_service.ListArtifactsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListArtifactsPager: + r"""Lists Artifacts in the MetadataStore. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_list_artifacts(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListArtifactsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_artifacts(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListArtifactsRequest, dict]): + The request object. Request message for + [MetadataService.ListArtifacts][google.cloud.aiplatform.v1.MetadataService.ListArtifacts]. + parent (str): + Required. The MetadataStore whose Artifacts should be + listed. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + + 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: + google.cloud.aiplatform_v1.services.metadata_service.pagers.ListArtifactsPager: + Response message for + [MetadataService.ListArtifacts][google.cloud.aiplatform.v1.MetadataService.ListArtifacts]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 metadata_service.ListArtifactsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, metadata_service.ListArtifactsRequest): + request = metadata_service.ListArtifactsRequest(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_artifacts] + + # 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.ListArtifactsPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def update_artifact( + self, + request: Union[metadata_service.UpdateArtifactRequest, dict] = None, + *, + artifact: gca_artifact.Artifact = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_artifact.Artifact: + r"""Updates a stored Artifact. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_update_artifact(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.UpdateArtifactRequest( + ) + + # Make the request + response = client.update_artifact(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.UpdateArtifactRequest, dict]): + The request object. Request message for + [MetadataService.UpdateArtifact][google.cloud.aiplatform.v1.MetadataService.UpdateArtifact]. + artifact (google.cloud.aiplatform_v1.types.Artifact): + Required. The Artifact containing updates. The + Artifact's + [Artifact.name][google.cloud.aiplatform.v1.Artifact.name] + field is used to identify the Artifact to be updated. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact}`` + + This corresponds to the ``artifact`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Optional. A FieldMask indicating + which fields should be updated. + Functionality of this field is not yet + supported. + + 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: + google.cloud.aiplatform_v1.types.Artifact: + Instance of a general artifact. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([artifact, 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 metadata_service.UpdateArtifactRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, metadata_service.UpdateArtifactRequest): + request = metadata_service.UpdateArtifactRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if artifact is not None: + request.artifact = artifact + 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_artifact] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("artifact.name", request.artifact.name),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_artifact( + self, + request: Union[metadata_service.DeleteArtifactRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Deletes an Artifact. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_delete_artifact(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteArtifactRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_artifact(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.DeleteArtifactRequest, dict]): + The request object. Request message for + [MetadataService.DeleteArtifact][google.cloud.aiplatform.v1.MetadataService.DeleteArtifact]. + name (str): + Required. The resource name of the Artifact to delete. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact}`` + + 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # Create or coerce a protobuf request object. + # Quick 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 metadata_service.DeleteArtifactRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, metadata_service.DeleteArtifactRequest): + request = metadata_service.DeleteArtifactRequest(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_artifact] + + # 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, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, + ) + + # Done; return the response. + return response + + def purge_artifacts( + self, + request: Union[metadata_service.PurgeArtifactsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Purges Artifacts. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_purge_artifacts(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.PurgeArtifactsRequest( + parent="parent_value", + filter="filter_value", + ) + + # Make the request + operation = client.purge_artifacts(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.PurgeArtifactsRequest, dict]): + The request object. Request message for + [MetadataService.PurgeArtifacts][google.cloud.aiplatform.v1.MetadataService.PurgeArtifacts]. + parent (str): + Required. The metadata store to purge Artifacts from. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + + 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.aiplatform_v1.types.PurgeArtifactsResponse` + Response message for + [MetadataService.PurgeArtifacts][google.cloud.aiplatform.v1.MetadataService.PurgeArtifacts]. + + """ + # Create or coerce a protobuf request object. + # Quick 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 metadata_service.PurgeArtifactsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, metadata_service.PurgeArtifactsRequest): + request = metadata_service.PurgeArtifactsRequest(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.purge_artifacts] + + # 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, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + metadata_service.PurgeArtifactsResponse, + metadata_type=metadata_service.PurgeArtifactsMetadata, + ) + + # Done; return the response. + return response + + def create_context( + self, + request: Union[metadata_service.CreateContextRequest, dict] = None, + *, + parent: str = None, + context: gca_context.Context = None, + context_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_context.Context: + r"""Creates a Context associated with a MetadataStore. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_create_context(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateContextRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_context(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CreateContextRequest, dict]): + The request object. Request message for + [MetadataService.CreateContext][google.cloud.aiplatform.v1.MetadataService.CreateContext]. + parent (str): + Required. The resource name of the MetadataStore where + the Context should be created. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + context (google.cloud.aiplatform_v1.types.Context): + Required. The Context to create. + This corresponds to the ``context`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + context_id (str): + The {context} portion of the resource name with the + format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}``. + If not provided, the Context's ID will be a UUID + generated by the service. Must be 4-128 characters in + length. Valid characters are ``/[a-z][0-9]-/``. Must be + unique across all Contexts in the parent MetadataStore. + (Otherwise the request will fail with ALREADY_EXISTS, or + PERMISSION_DENIED if the caller can't view the + preexisting Context.) + + This corresponds to the ``context_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: + google.cloud.aiplatform_v1.types.Context: + Instance of a general context. + """ + # Create or coerce a protobuf request object. + # Quick 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, context, context_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 metadata_service.CreateContextRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, metadata_service.CreateContextRequest): + request = metadata_service.CreateContextRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if context is not None: + request.context = context + if context_id is not None: + request.context_id = context_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_context] + + # 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 get_context( + self, + request: Union[metadata_service.GetContextRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> context.Context: + r"""Retrieves a specific Context. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_get_context(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetContextRequest( + name="name_value", + ) + + # Make the request + response = client.get_context(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetContextRequest, dict]): + The request object. Request message for + [MetadataService.GetContext][google.cloud.aiplatform.v1.MetadataService.GetContext]. + name (str): + Required. The resource name of the Context to retrieve. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` + + 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: + google.cloud.aiplatform_v1.types.Context: + Instance of a general context. + """ + # Create or coerce a protobuf request object. + # Quick 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 metadata_service.GetContextRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, metadata_service.GetContextRequest): + request = metadata_service.GetContextRequest(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_context] + + # 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 list_contexts( + self, + request: Union[metadata_service.ListContextsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListContextsPager: + r"""Lists Contexts on the MetadataStore. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_list_contexts(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListContextsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_contexts(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListContextsRequest, dict]): + The request object. Request message for + [MetadataService.ListContexts][google.cloud.aiplatform.v1.MetadataService.ListContexts] + parent (str): + Required. The MetadataStore whose Contexts should be + listed. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + + 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: + google.cloud.aiplatform_v1.services.metadata_service.pagers.ListContextsPager: + Response message for + [MetadataService.ListContexts][google.cloud.aiplatform.v1.MetadataService.ListContexts]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 metadata_service.ListContextsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, metadata_service.ListContextsRequest): + request = metadata_service.ListContextsRequest(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_contexts] + + # 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.ListContextsPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def update_context( + self, + request: Union[metadata_service.UpdateContextRequest, dict] = None, + *, + context: gca_context.Context = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_context.Context: + r"""Updates a stored Context. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_update_context(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.UpdateContextRequest( + ) + + # Make the request + response = client.update_context(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.UpdateContextRequest, dict]): + The request object. Request message for + [MetadataService.UpdateContext][google.cloud.aiplatform.v1.MetadataService.UpdateContext]. + context (google.cloud.aiplatform_v1.types.Context): + Required. The Context containing updates. The Context's + [Context.name][google.cloud.aiplatform.v1.Context.name] + field is used to identify the Context to be updated. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` + + This corresponds to the ``context`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Optional. A FieldMask indicating + which fields should be updated. + Functionality of this field is not yet + supported. + + 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: + google.cloud.aiplatform_v1.types.Context: + Instance of a general context. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([context, 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 metadata_service.UpdateContextRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, metadata_service.UpdateContextRequest): + request = metadata_service.UpdateContextRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if context is not None: + request.context = context + 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_context] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("context.name", request.context.name),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_context( + self, + request: Union[metadata_service.DeleteContextRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Deletes a stored Context. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_delete_context(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteContextRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_context(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.DeleteContextRequest, dict]): + The request object. Request message for + [MetadataService.DeleteContext][google.cloud.aiplatform.v1.MetadataService.DeleteContext]. + name (str): + Required. The resource name of the Context to delete. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` + + 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # Create or coerce a protobuf request object. + # Quick 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 metadata_service.DeleteContextRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, metadata_service.DeleteContextRequest): + request = metadata_service.DeleteContextRequest(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_context] + + # 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, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, + ) + + # Done; return the response. + return response + + def purge_contexts( + self, + request: Union[metadata_service.PurgeContextsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Purges Contexts. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_purge_contexts(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.PurgeContextsRequest( + parent="parent_value", + filter="filter_value", + ) + + # Make the request + operation = client.purge_contexts(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.PurgeContextsRequest, dict]): + The request object. Request message for + [MetadataService.PurgeContexts][google.cloud.aiplatform.v1.MetadataService.PurgeContexts]. + parent (str): + Required. The metadata store to purge Contexts from. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + + 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.aiplatform_v1.types.PurgeContextsResponse` + Response message for + [MetadataService.PurgeContexts][google.cloud.aiplatform.v1.MetadataService.PurgeContexts]. + + """ + # Create or coerce a protobuf request object. + # Quick 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 metadata_service.PurgeContextsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, metadata_service.PurgeContextsRequest): + request = metadata_service.PurgeContextsRequest(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.purge_contexts] + + # 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, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + metadata_service.PurgeContextsResponse, + metadata_type=metadata_service.PurgeContextsMetadata, + ) + + # Done; return the response. + return response + + def add_context_artifacts_and_executions( + self, + request: Union[ + metadata_service.AddContextArtifactsAndExecutionsRequest, dict + ] = None, + *, + context: str = None, + artifacts: Sequence[str] = None, + executions: Sequence[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> metadata_service.AddContextArtifactsAndExecutionsResponse: + r"""Adds a set of Artifacts and Executions to a Context. + If any of the Artifacts or Executions have already been + added to a Context, they are simply skipped. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_add_context_artifacts_and_executions(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.AddContextArtifactsAndExecutionsRequest( + context="context_value", + ) + + # Make the request + response = client.add_context_artifacts_and_executions(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.AddContextArtifactsAndExecutionsRequest, dict]): + The request object. Request message for + [MetadataService.AddContextArtifactsAndExecutions][google.cloud.aiplatform.v1.MetadataService.AddContextArtifactsAndExecutions]. + context (str): + Required. The resource name of the Context that the + Artifacts and Executions belong to. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` + + This corresponds to the ``context`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + artifacts (Sequence[str]): + The resource names of the Artifacts to attribute to the + Context. + + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact}`` + + This corresponds to the ``artifacts`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + executions (Sequence[str]): + The resource names of the Executions to associate with + the Context. + + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` + + This corresponds to the ``executions`` 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: + google.cloud.aiplatform_v1.types.AddContextArtifactsAndExecutionsResponse: + Response message for + [MetadataService.AddContextArtifactsAndExecutions][google.cloud.aiplatform.v1.MetadataService.AddContextArtifactsAndExecutions]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([context, artifacts, executions]) + 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 metadata_service.AddContextArtifactsAndExecutionsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, metadata_service.AddContextArtifactsAndExecutionsRequest + ): + request = metadata_service.AddContextArtifactsAndExecutionsRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if context is not None: + request.context = context + if artifacts is not None: + request.artifacts = artifacts + if executions is not None: + request.executions = executions + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.add_context_artifacts_and_executions + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("context", request.context),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def add_context_children( + self, + request: Union[metadata_service.AddContextChildrenRequest, dict] = None, + *, + context: str = None, + child_contexts: Sequence[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> metadata_service.AddContextChildrenResponse: + r"""Adds a set of Contexts as children to a parent Context. If any + of the child Contexts have already been added to the parent + Context, they are simply skipped. If this call would create a + cycle or cause any Context to have more than 10 parents, the + request will fail with an INVALID_ARGUMENT error. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_add_context_children(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.AddContextChildrenRequest( + context="context_value", + ) + + # Make the request + response = client.add_context_children(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.AddContextChildrenRequest, dict]): + The request object. Request message for + [MetadataService.AddContextChildren][google.cloud.aiplatform.v1.MetadataService.AddContextChildren]. + context (str): + Required. The resource name of the parent Context. + + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` + + This corresponds to the ``context`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + child_contexts (Sequence[str]): + The resource names of the child + Contexts. + + This corresponds to the ``child_contexts`` 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: + google.cloud.aiplatform_v1.types.AddContextChildrenResponse: + Response message for + [MetadataService.AddContextChildren][google.cloud.aiplatform.v1.MetadataService.AddContextChildren]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([context, child_contexts]) + 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 metadata_service.AddContextChildrenRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, metadata_service.AddContextChildrenRequest): + request = metadata_service.AddContextChildrenRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if context is not None: + request.context = context + if child_contexts is not None: + request.child_contexts = child_contexts + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.add_context_children] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("context", request.context),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def query_context_lineage_subgraph( + self, + request: Union[ + metadata_service.QueryContextLineageSubgraphRequest, dict + ] = None, + *, + context: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> lineage_subgraph.LineageSubgraph: + r"""Retrieves Artifacts and Executions within the + specified Context, connected by Event edges and returned + as a LineageSubgraph. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_query_context_lineage_subgraph(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.QueryContextLineageSubgraphRequest( + context="context_value", + ) + + # Make the request + response = client.query_context_lineage_subgraph(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.QueryContextLineageSubgraphRequest, dict]): + The request object. Request message for + [MetadataService.QueryContextLineageSubgraph][google.cloud.aiplatform.v1.MetadataService.QueryContextLineageSubgraph]. + context (str): + Required. The resource name of the Context whose + Artifacts and Executions should be retrieved as a + LineageSubgraph. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` + + The request may error with FAILED_PRECONDITION if the + number of Artifacts, the number of Executions, or the + number of Events that would be returned for the Context + exceeds 1000. + + This corresponds to the ``context`` 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: + google.cloud.aiplatform_v1.types.LineageSubgraph: + A subgraph of the overall lineage + graph. Event edges connect Artifact and + Execution nodes. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([context]) + 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 metadata_service.QueryContextLineageSubgraphRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, metadata_service.QueryContextLineageSubgraphRequest): + request = metadata_service.QueryContextLineageSubgraphRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if context is not None: + request.context = context + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.query_context_lineage_subgraph + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("context", request.context),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def create_execution( + self, + request: Union[metadata_service.CreateExecutionRequest, dict] = None, + *, + parent: str = None, + execution: gca_execution.Execution = None, + execution_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_execution.Execution: + r"""Creates an Execution associated with a MetadataStore. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_create_execution(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateExecutionRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_execution(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CreateExecutionRequest, dict]): + The request object. Request message for + [MetadataService.CreateExecution][google.cloud.aiplatform.v1.MetadataService.CreateExecution]. + parent (str): + Required. The resource name of the MetadataStore where + the Execution should be created. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + execution (google.cloud.aiplatform_v1.types.Execution): + Required. The Execution to create. + This corresponds to the ``execution`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + execution_id (str): + The {execution} portion of the resource name with the + format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` + If not provided, the Execution's ID will be a UUID + generated by the service. Must be 4-128 characters in + length. Valid characters are ``/[a-z][0-9]-/``. Must be + unique across all Executions in the parent + MetadataStore. (Otherwise the request will fail with + ALREADY_EXISTS, or PERMISSION_DENIED if the caller can't + view the preexisting Execution.) + + This corresponds to the ``execution_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: + google.cloud.aiplatform_v1.types.Execution: + Instance of a general execution. + """ + # Create or coerce a protobuf request object. + # Quick 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, execution, execution_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 metadata_service.CreateExecutionRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, metadata_service.CreateExecutionRequest): + request = metadata_service.CreateExecutionRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if execution is not None: + request.execution = execution + if execution_id is not None: + request.execution_id = execution_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_execution] + + # 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 get_execution( + self, + request: Union[metadata_service.GetExecutionRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> execution.Execution: + r"""Retrieves a specific Execution. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_get_execution(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetExecutionRequest( + name="name_value", + ) + + # Make the request + response = client.get_execution(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetExecutionRequest, dict]): + The request object. Request message for + [MetadataService.GetExecution][google.cloud.aiplatform.v1.MetadataService.GetExecution]. + name (str): + Required. The resource name of the Execution to + retrieve. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` + + 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: + google.cloud.aiplatform_v1.types.Execution: + Instance of a general execution. + """ + # Create or coerce a protobuf request object. + # Quick 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 metadata_service.GetExecutionRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, metadata_service.GetExecutionRequest): + request = metadata_service.GetExecutionRequest(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_execution] + + # 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 list_executions( + self, + request: Union[metadata_service.ListExecutionsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListExecutionsPager: + r"""Lists Executions in the MetadataStore. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_list_executions(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListExecutionsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_executions(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListExecutionsRequest, dict]): + The request object. Request message for + [MetadataService.ListExecutions][google.cloud.aiplatform.v1.MetadataService.ListExecutions]. + parent (str): + Required. The MetadataStore whose Executions should be + listed. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + + 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: + google.cloud.aiplatform_v1.services.metadata_service.pagers.ListExecutionsPager: + Response message for + [MetadataService.ListExecutions][google.cloud.aiplatform.v1.MetadataService.ListExecutions]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 metadata_service.ListExecutionsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, metadata_service.ListExecutionsRequest): + request = metadata_service.ListExecutionsRequest(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_executions] + + # 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.ListExecutionsPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def update_execution( + self, + request: Union[metadata_service.UpdateExecutionRequest, dict] = None, + *, + execution: gca_execution.Execution = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_execution.Execution: + r"""Updates a stored Execution. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_update_execution(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.UpdateExecutionRequest( + ) + + # Make the request + response = client.update_execution(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.UpdateExecutionRequest, dict]): + The request object. Request message for + [MetadataService.UpdateExecution][google.cloud.aiplatform.v1.MetadataService.UpdateExecution]. + execution (google.cloud.aiplatform_v1.types.Execution): + Required. The Execution containing updates. The + Execution's + [Execution.name][google.cloud.aiplatform.v1.Execution.name] + field is used to identify the Execution to be updated. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` + + This corresponds to the ``execution`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Optional. A FieldMask indicating + which fields should be updated. + Functionality of this field is not yet + supported. + + 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: + google.cloud.aiplatform_v1.types.Execution: + Instance of a general execution. + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([execution, 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 metadata_service.UpdateExecutionRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, metadata_service.UpdateExecutionRequest): + request = metadata_service.UpdateExecutionRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if execution is not None: + request.execution = execution + 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_execution] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("execution.name", request.execution.name),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_execution( + self, + request: Union[metadata_service.DeleteExecutionRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Deletes an Execution. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_delete_execution(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteExecutionRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_execution(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.DeleteExecutionRequest, dict]): + The request object. Request message for + [MetadataService.DeleteExecution][google.cloud.aiplatform.v1.MetadataService.DeleteExecution]. + name (str): + Required. The resource name of the Execution to delete. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` + + 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # Create or coerce a protobuf request object. + # Quick 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 metadata_service.DeleteExecutionRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, metadata_service.DeleteExecutionRequest): + request = metadata_service.DeleteExecutionRequest(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_execution] + + # 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, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, + ) + + # Done; return the response. + return response + + def purge_executions( + self, + request: Union[metadata_service.PurgeExecutionsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Purges Executions. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_purge_executions(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.PurgeExecutionsRequest( + parent="parent_value", + filter="filter_value", + ) + + # Make the request + operation = client.purge_executions(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.PurgeExecutionsRequest, dict]): + The request object. Request message for + [MetadataService.PurgeExecutions][google.cloud.aiplatform.v1.MetadataService.PurgeExecutions]. + parent (str): + Required. The metadata store to purge Executions from. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + + 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.aiplatform_v1.types.PurgeExecutionsResponse` + Response message for + [MetadataService.PurgeExecutions][google.cloud.aiplatform.v1.MetadataService.PurgeExecutions]. + + """ + # Create or coerce a protobuf request object. + # Quick 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 metadata_service.PurgeExecutionsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, metadata_service.PurgeExecutionsRequest): + request = metadata_service.PurgeExecutionsRequest(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.purge_executions] + + # 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, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + metadata_service.PurgeExecutionsResponse, + metadata_type=metadata_service.PurgeExecutionsMetadata, + ) + + # Done; return the response. + return response + + def add_execution_events( + self, + request: Union[metadata_service.AddExecutionEventsRequest, dict] = None, + *, + execution: str = None, + events: Sequence[event.Event] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> metadata_service.AddExecutionEventsResponse: + r"""Adds Events to the specified Execution. An Event + indicates whether an Artifact was used as an input or + output for an Execution. If an Event already exists + between the Execution and the Artifact, the Event is + skipped. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_add_execution_events(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.AddExecutionEventsRequest( + execution="execution_value", + ) + + # Make the request + response = client.add_execution_events(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.AddExecutionEventsRequest, dict]): + The request object. Request message for + [MetadataService.AddExecutionEvents][google.cloud.aiplatform.v1.MetadataService.AddExecutionEvents]. + execution (str): + Required. The resource name of the Execution that the + Events connect Artifacts with. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` + + This corresponds to the ``execution`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + events (Sequence[google.cloud.aiplatform_v1.types.Event]): + The Events to create and add. + This corresponds to the ``events`` 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: + google.cloud.aiplatform_v1.types.AddExecutionEventsResponse: + Response message for + [MetadataService.AddExecutionEvents][google.cloud.aiplatform.v1.MetadataService.AddExecutionEvents]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([execution, events]) + 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 metadata_service.AddExecutionEventsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, metadata_service.AddExecutionEventsRequest): + request = metadata_service.AddExecutionEventsRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if execution is not None: + request.execution = execution + if events is not None: + request.events = events + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.add_execution_events] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("execution", request.execution),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def query_execution_inputs_and_outputs( + self, + request: Union[ + metadata_service.QueryExecutionInputsAndOutputsRequest, dict + ] = None, + *, + execution: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> lineage_subgraph.LineageSubgraph: + r"""Obtains the set of input and output Artifacts for + this Execution, in the form of LineageSubgraph that also + contains the Execution and connecting Events. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_query_execution_inputs_and_outputs(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.QueryExecutionInputsAndOutputsRequest( + execution="execution_value", + ) + + # Make the request + response = client.query_execution_inputs_and_outputs(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.QueryExecutionInputsAndOutputsRequest, dict]): + The request object. Request message for + [MetadataService.QueryExecutionInputsAndOutputs][google.cloud.aiplatform.v1.MetadataService.QueryExecutionInputsAndOutputs]. + execution (str): + Required. The resource name of the Execution whose input + and output Artifacts should be retrieved as a + LineageSubgraph. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` + + This corresponds to the ``execution`` 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: + google.cloud.aiplatform_v1.types.LineageSubgraph: + A subgraph of the overall lineage + graph. Event edges connect Artifact and + Execution nodes. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([execution]) + 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 metadata_service.QueryExecutionInputsAndOutputsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, metadata_service.QueryExecutionInputsAndOutputsRequest + ): + request = metadata_service.QueryExecutionInputsAndOutputsRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if execution is not None: + request.execution = execution + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.query_execution_inputs_and_outputs + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("execution", request.execution),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def create_metadata_schema( + self, + request: Union[metadata_service.CreateMetadataSchemaRequest, dict] = None, + *, + parent: str = None, + metadata_schema: gca_metadata_schema.MetadataSchema = None, + metadata_schema_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_metadata_schema.MetadataSchema: + r"""Creates a MetadataSchema. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_create_metadata_schema(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + metadata_schema = aiplatform_v1.MetadataSchema() + metadata_schema.schema = "schema_value" + + request = aiplatform_v1.CreateMetadataSchemaRequest( + parent="parent_value", + metadata_schema=metadata_schema, + ) + + # Make the request + response = client.create_metadata_schema(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CreateMetadataSchemaRequest, dict]): + The request object. Request message for + [MetadataService.CreateMetadataSchema][google.cloud.aiplatform.v1.MetadataService.CreateMetadataSchema]. + parent (str): + Required. The resource name of the MetadataStore where + the MetadataSchema should be created. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + metadata_schema (google.cloud.aiplatform_v1.types.MetadataSchema): + Required. The MetadataSchema to + create. + + This corresponds to the ``metadata_schema`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + metadata_schema_id (str): + The {metadata_schema} portion of the resource name with + the format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/metadataSchemas/{metadataschema}`` + If not provided, the MetadataStore's ID will be a UUID + generated by the service. Must be 4-128 characters in + length. Valid characters are ``/[a-z][0-9]-/``. Must be + unique across all MetadataSchemas in the parent + Location. (Otherwise the request will fail with + ALREADY_EXISTS, or PERMISSION_DENIED if the caller can't + view the preexisting MetadataSchema.) + + This corresponds to the ``metadata_schema_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: + google.cloud.aiplatform_v1.types.MetadataSchema: + Instance of a general MetadataSchema. + """ + # Create or coerce a protobuf request object. + # Quick 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, metadata_schema, metadata_schema_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 metadata_service.CreateMetadataSchemaRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, metadata_service.CreateMetadataSchemaRequest): + request = metadata_service.CreateMetadataSchemaRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if metadata_schema is not None: + request.metadata_schema = metadata_schema + if metadata_schema_id is not None: + request.metadata_schema_id = metadata_schema_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_metadata_schema] + + # 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 get_metadata_schema( + self, + request: Union[metadata_service.GetMetadataSchemaRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> metadata_schema.MetadataSchema: + r"""Retrieves a specific MetadataSchema. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_get_metadata_schema(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetMetadataSchemaRequest( + name="name_value", + ) + + # Make the request + response = client.get_metadata_schema(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetMetadataSchemaRequest, dict]): + The request object. Request message for + [MetadataService.GetMetadataSchema][google.cloud.aiplatform.v1.MetadataService.GetMetadataSchema]. + name (str): + Required. The resource name of the MetadataSchema to + retrieve. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/metadataSchemas/{metadataschema}`` + + 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: + google.cloud.aiplatform_v1.types.MetadataSchema: + Instance of a general MetadataSchema. + """ + # Create or coerce a protobuf request object. + # Quick 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 metadata_service.GetMetadataSchemaRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, metadata_service.GetMetadataSchemaRequest): + request = metadata_service.GetMetadataSchemaRequest(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_metadata_schema] + + # 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 list_metadata_schemas( + self, + request: Union[metadata_service.ListMetadataSchemasRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListMetadataSchemasPager: + r"""Lists MetadataSchemas. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_list_metadata_schemas(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListMetadataSchemasRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_metadata_schemas(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListMetadataSchemasRequest, dict]): + The request object. Request message for + [MetadataService.ListMetadataSchemas][google.cloud.aiplatform.v1.MetadataService.ListMetadataSchemas]. + parent (str): + Required. The MetadataStore whose MetadataSchemas should + be listed. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + + 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: + google.cloud.aiplatform_v1.services.metadata_service.pagers.ListMetadataSchemasPager: + Response message for + [MetadataService.ListMetadataSchemas][google.cloud.aiplatform.v1.MetadataService.ListMetadataSchemas]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 metadata_service.ListMetadataSchemasRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, metadata_service.ListMetadataSchemasRequest): + request = metadata_service.ListMetadataSchemasRequest(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_metadata_schemas] + + # 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.ListMetadataSchemasPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def query_artifact_lineage_subgraph( + self, + request: Union[ + metadata_service.QueryArtifactLineageSubgraphRequest, dict + ] = None, + *, + artifact: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> lineage_subgraph.LineageSubgraph: + r"""Retrieves lineage of an Artifact represented through + Artifacts and Executions connected by Event edges and + returned as a LineageSubgraph. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_query_artifact_lineage_subgraph(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.QueryArtifactLineageSubgraphRequest( + artifact="artifact_value", + ) + + # Make the request + response = client.query_artifact_lineage_subgraph(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.QueryArtifactLineageSubgraphRequest, dict]): + The request object. Request message for + [MetadataService.QueryArtifactLineageSubgraph][google.cloud.aiplatform.v1.MetadataService.QueryArtifactLineageSubgraph]. + artifact (str): + Required. The resource name of the Artifact whose + Lineage needs to be retrieved as a LineageSubgraph. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact}`` + + The request may error with FAILED_PRECONDITION if the + number of Artifacts, the number of Executions, or the + number of Events that would be returned for the Context + exceeds 1000. + + This corresponds to the ``artifact`` 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: + google.cloud.aiplatform_v1.types.LineageSubgraph: + A subgraph of the overall lineage + graph. Event edges connect Artifact and + Execution nodes. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([artifact]) + 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 metadata_service.QueryArtifactLineageSubgraphRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, metadata_service.QueryArtifactLineageSubgraphRequest + ): + request = metadata_service.QueryArtifactLineageSubgraphRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if artifact is not None: + request.artifact = artifact + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.query_artifact_lineage_subgraph + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("artifact", request.artifact),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_operations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.delete_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.wait_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_location, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_locations, + default_timeout=None, + 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 = 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-aiplatform", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ("MetadataServiceClient",) diff --git a/google/cloud/aiplatform_v1/services/metadata_service/pagers.py b/google/cloud/aiplatform_v1/services/metadata_service/pagers.py new file mode 100644 index 0000000000..54c841db98 --- /dev/null +++ b/google/cloud/aiplatform_v1/services/metadata_service/pagers.py @@ -0,0 +1,674 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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 typing import ( + Any, + AsyncIterator, + Awaitable, + Callable, + Sequence, + Tuple, + Optional, + Iterator, +) + +from google.cloud.aiplatform_v1.types import artifact +from google.cloud.aiplatform_v1.types import context +from google.cloud.aiplatform_v1.types import execution +from google.cloud.aiplatform_v1.types import metadata_schema +from google.cloud.aiplatform_v1.types import metadata_service +from google.cloud.aiplatform_v1.types import metadata_store + + +class ListMetadataStoresPager: + """A pager for iterating through ``list_metadata_stores`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListMetadataStoresResponse` object, and + provides an ``__iter__`` method to iterate through its + ``metadata_stores`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListMetadataStores`` requests and continue to iterate + through the ``metadata_stores`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListMetadataStoresResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., metadata_service.ListMetadataStoresResponse], + request: metadata_service.ListMetadataStoresRequest, + response: metadata_service.ListMetadataStoresResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListMetadataStoresRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListMetadataStoresResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = metadata_service.ListMetadataStoresRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[metadata_service.ListMetadataStoresResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterator[metadata_store.MetadataStore]: + for page in self.pages: + yield from page.metadata_stores + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListMetadataStoresAsyncPager: + """A pager for iterating through ``list_metadata_stores`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListMetadataStoresResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``metadata_stores`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListMetadataStores`` requests and continue to iterate + through the ``metadata_stores`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListMetadataStoresResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., Awaitable[metadata_service.ListMetadataStoresResponse]], + request: metadata_service.ListMetadataStoresRequest, + response: metadata_service.ListMetadataStoresResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListMetadataStoresRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListMetadataStoresResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = metadata_service.ListMetadataStoresRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[metadata_service.ListMetadataStoresResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + + def __aiter__(self) -> AsyncIterator[metadata_store.MetadataStore]: + async def async_generator(): + async for page in self.pages: + for response in page.metadata_stores: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListArtifactsPager: + """A pager for iterating through ``list_artifacts`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListArtifactsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``artifacts`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListArtifacts`` requests and continue to iterate + through the ``artifacts`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListArtifactsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., metadata_service.ListArtifactsResponse], + request: metadata_service.ListArtifactsRequest, + response: metadata_service.ListArtifactsResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListArtifactsRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListArtifactsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = metadata_service.ListArtifactsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[metadata_service.ListArtifactsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterator[artifact.Artifact]: + for page in self.pages: + yield from page.artifacts + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListArtifactsAsyncPager: + """A pager for iterating through ``list_artifacts`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListArtifactsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``artifacts`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListArtifacts`` requests and continue to iterate + through the ``artifacts`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListArtifactsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., Awaitable[metadata_service.ListArtifactsResponse]], + request: metadata_service.ListArtifactsRequest, + response: metadata_service.ListArtifactsResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListArtifactsRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListArtifactsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = metadata_service.ListArtifactsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[metadata_service.ListArtifactsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + + def __aiter__(self) -> AsyncIterator[artifact.Artifact]: + async def async_generator(): + async for page in self.pages: + for response in page.artifacts: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListContextsPager: + """A pager for iterating through ``list_contexts`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListContextsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``contexts`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListContexts`` requests and continue to iterate + through the ``contexts`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListContextsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., metadata_service.ListContextsResponse], + request: metadata_service.ListContextsRequest, + response: metadata_service.ListContextsResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListContextsRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListContextsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = metadata_service.ListContextsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[metadata_service.ListContextsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterator[context.Context]: + for page in self.pages: + yield from page.contexts + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListContextsAsyncPager: + """A pager for iterating through ``list_contexts`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListContextsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``contexts`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListContexts`` requests and continue to iterate + through the ``contexts`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListContextsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., Awaitable[metadata_service.ListContextsResponse]], + request: metadata_service.ListContextsRequest, + response: metadata_service.ListContextsResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListContextsRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListContextsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = metadata_service.ListContextsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[metadata_service.ListContextsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + + def __aiter__(self) -> AsyncIterator[context.Context]: + async def async_generator(): + async for page in self.pages: + for response in page.contexts: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListExecutionsPager: + """A pager for iterating through ``list_executions`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListExecutionsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``executions`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListExecutions`` requests and continue to iterate + through the ``executions`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListExecutionsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., metadata_service.ListExecutionsResponse], + request: metadata_service.ListExecutionsRequest, + response: metadata_service.ListExecutionsResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListExecutionsRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListExecutionsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = metadata_service.ListExecutionsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[metadata_service.ListExecutionsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterator[execution.Execution]: + for page in self.pages: + yield from page.executions + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListExecutionsAsyncPager: + """A pager for iterating through ``list_executions`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListExecutionsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``executions`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListExecutions`` requests and continue to iterate + through the ``executions`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListExecutionsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., Awaitable[metadata_service.ListExecutionsResponse]], + request: metadata_service.ListExecutionsRequest, + response: metadata_service.ListExecutionsResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListExecutionsRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListExecutionsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = metadata_service.ListExecutionsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[metadata_service.ListExecutionsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + + def __aiter__(self) -> AsyncIterator[execution.Execution]: + async def async_generator(): + async for page in self.pages: + for response in page.executions: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListMetadataSchemasPager: + """A pager for iterating through ``list_metadata_schemas`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListMetadataSchemasResponse` object, and + provides an ``__iter__`` method to iterate through its + ``metadata_schemas`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListMetadataSchemas`` requests and continue to iterate + through the ``metadata_schemas`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListMetadataSchemasResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., metadata_service.ListMetadataSchemasResponse], + request: metadata_service.ListMetadataSchemasRequest, + response: metadata_service.ListMetadataSchemasResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListMetadataSchemasRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListMetadataSchemasResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = metadata_service.ListMetadataSchemasRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[metadata_service.ListMetadataSchemasResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterator[metadata_schema.MetadataSchema]: + for page in self.pages: + yield from page.metadata_schemas + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListMetadataSchemasAsyncPager: + """A pager for iterating through ``list_metadata_schemas`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListMetadataSchemasResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``metadata_schemas`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListMetadataSchemas`` requests and continue to iterate + through the ``metadata_schemas`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListMetadataSchemasResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., Awaitable[metadata_service.ListMetadataSchemasResponse]], + request: metadata_service.ListMetadataSchemasRequest, + response: metadata_service.ListMetadataSchemasResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListMetadataSchemasRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListMetadataSchemasResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = metadata_service.ListMetadataSchemasRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages( + self, + ) -> AsyncIterator[metadata_service.ListMetadataSchemasResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + + def __aiter__(self) -> AsyncIterator[metadata_schema.MetadataSchema]: + async def async_generator(): + async for page in self.pages: + for response in page.metadata_schemas: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) diff --git a/google/cloud/aiplatform_v1/services/metadata_service/transports/__init__.py b/google/cloud/aiplatform_v1/services/metadata_service/transports/__init__.py new file mode 100644 index 0000000000..afbd5b2f2c --- /dev/null +++ b/google/cloud/aiplatform_v1/services/metadata_service/transports/__init__.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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 typing import Dict, Type + +from .base import MetadataServiceTransport +from .grpc import MetadataServiceGrpcTransport +from .grpc_asyncio import MetadataServiceGrpcAsyncIOTransport + + +# Compile a registry of transports. +_transport_registry = OrderedDict() # type: Dict[str, Type[MetadataServiceTransport]] +_transport_registry["grpc"] = MetadataServiceGrpcTransport +_transport_registry["grpc_asyncio"] = MetadataServiceGrpcAsyncIOTransport + +__all__ = ( + "MetadataServiceTransport", + "MetadataServiceGrpcTransport", + "MetadataServiceGrpcAsyncIOTransport", +) diff --git a/google/cloud/aiplatform_v1/services/metadata_service/transports/base.py b/google/cloud/aiplatform_v1/services/metadata_service/transports/base.py new file mode 100644 index 0000000000..0c69424679 --- /dev/null +++ b/google/cloud/aiplatform_v1/services/metadata_service/transports/base.py @@ -0,0 +1,726 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import abc +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +import pkg_resources + +import google.auth # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import operations_v1 +from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore + +from google.cloud.aiplatform_v1.types import artifact +from google.cloud.aiplatform_v1.types import artifact as gca_artifact +from google.cloud.aiplatform_v1.types import context +from google.cloud.aiplatform_v1.types import context as gca_context +from google.cloud.aiplatform_v1.types import execution +from google.cloud.aiplatform_v1.types import execution as gca_execution +from google.cloud.aiplatform_v1.types import lineage_subgraph +from google.cloud.aiplatform_v1.types import metadata_schema +from google.cloud.aiplatform_v1.types import metadata_schema as gca_metadata_schema +from google.cloud.aiplatform_v1.types import metadata_service +from google.cloud.aiplatform_v1.types import metadata_store +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.longrunning import operations_pb2 # type: ignore + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-aiplatform", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +class MetadataServiceTransport(abc.ABC): + """Abstract transport class for MetadataService.""" + + AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) + + DEFAULT_HOST: str = "aiplatform.googleapis.com" + + def __init__( + self, + *, + host: str = DEFAULT_HOST, + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + **kwargs, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + 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. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is mutually exclusive with credentials. + scopes (Optional[Sequence[str]]): A list of scopes. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + 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. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + """ + + # Save the hostname. Default to port 443 (HTTPS) if none is specified. + if ":" not in host: + host += ":443" + self._host = host + + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} + + # Save the scopes. + self._scopes = scopes + + # If no credentials are provided, then determine the appropriate + # defaults. + if credentials and credentials_file: + raise core_exceptions.DuplicateCredentialArgs( + "'credentials_file' and 'credentials' are mutually exclusive" + ) + + if credentials_file is not None: + credentials, _ = google.auth.load_credentials_from_file( + credentials_file, **scopes_kwargs, quota_project_id=quota_project_id + ) + elif credentials is None: + credentials, _ = google.auth.default( + **scopes_kwargs, quota_project_id=quota_project_id + ) + + # If the credentials are service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + + # Save the credentials. + self._credentials = credentials + + def _prep_wrapped_messages(self, client_info): + # Precompute the wrapped methods. + self._wrapped_methods = { + self.create_metadata_store: gapic_v1.method.wrap_method( + self.create_metadata_store, + default_timeout=None, + client_info=client_info, + ), + self.get_metadata_store: gapic_v1.method.wrap_method( + self.get_metadata_store, + default_timeout=None, + client_info=client_info, + ), + self.list_metadata_stores: gapic_v1.method.wrap_method( + self.list_metadata_stores, + default_timeout=None, + client_info=client_info, + ), + self.delete_metadata_store: gapic_v1.method.wrap_method( + self.delete_metadata_store, + default_timeout=None, + client_info=client_info, + ), + self.create_artifact: gapic_v1.method.wrap_method( + self.create_artifact, + default_timeout=None, + client_info=client_info, + ), + self.get_artifact: gapic_v1.method.wrap_method( + self.get_artifact, + default_timeout=None, + client_info=client_info, + ), + self.list_artifacts: gapic_v1.method.wrap_method( + self.list_artifacts, + default_timeout=None, + client_info=client_info, + ), + self.update_artifact: gapic_v1.method.wrap_method( + self.update_artifact, + default_timeout=None, + client_info=client_info, + ), + self.delete_artifact: gapic_v1.method.wrap_method( + self.delete_artifact, + default_timeout=None, + client_info=client_info, + ), + self.purge_artifacts: gapic_v1.method.wrap_method( + self.purge_artifacts, + default_timeout=None, + client_info=client_info, + ), + self.create_context: gapic_v1.method.wrap_method( + self.create_context, + default_timeout=None, + client_info=client_info, + ), + self.get_context: gapic_v1.method.wrap_method( + self.get_context, + default_timeout=None, + client_info=client_info, + ), + self.list_contexts: gapic_v1.method.wrap_method( + self.list_contexts, + default_timeout=None, + client_info=client_info, + ), + self.update_context: gapic_v1.method.wrap_method( + self.update_context, + default_timeout=None, + client_info=client_info, + ), + self.delete_context: gapic_v1.method.wrap_method( + self.delete_context, + default_timeout=None, + client_info=client_info, + ), + self.purge_contexts: gapic_v1.method.wrap_method( + self.purge_contexts, + default_timeout=None, + client_info=client_info, + ), + self.add_context_artifacts_and_executions: gapic_v1.method.wrap_method( + self.add_context_artifacts_and_executions, + default_timeout=None, + client_info=client_info, + ), + self.add_context_children: gapic_v1.method.wrap_method( + self.add_context_children, + default_timeout=None, + client_info=client_info, + ), + self.query_context_lineage_subgraph: gapic_v1.method.wrap_method( + self.query_context_lineage_subgraph, + default_timeout=None, + client_info=client_info, + ), + self.create_execution: gapic_v1.method.wrap_method( + self.create_execution, + default_timeout=None, + client_info=client_info, + ), + self.get_execution: gapic_v1.method.wrap_method( + self.get_execution, + default_timeout=None, + client_info=client_info, + ), + self.list_executions: gapic_v1.method.wrap_method( + self.list_executions, + default_timeout=None, + client_info=client_info, + ), + self.update_execution: gapic_v1.method.wrap_method( + self.update_execution, + default_timeout=None, + client_info=client_info, + ), + self.delete_execution: gapic_v1.method.wrap_method( + self.delete_execution, + default_timeout=None, + client_info=client_info, + ), + self.purge_executions: gapic_v1.method.wrap_method( + self.purge_executions, + default_timeout=None, + client_info=client_info, + ), + self.add_execution_events: gapic_v1.method.wrap_method( + self.add_execution_events, + default_timeout=None, + client_info=client_info, + ), + self.query_execution_inputs_and_outputs: gapic_v1.method.wrap_method( + self.query_execution_inputs_and_outputs, + default_timeout=None, + client_info=client_info, + ), + self.create_metadata_schema: gapic_v1.method.wrap_method( + self.create_metadata_schema, + default_timeout=None, + client_info=client_info, + ), + self.get_metadata_schema: gapic_v1.method.wrap_method( + self.get_metadata_schema, + default_timeout=None, + client_info=client_info, + ), + self.list_metadata_schemas: gapic_v1.method.wrap_method( + self.list_metadata_schemas, + default_timeout=None, + client_info=client_info, + ), + self.query_artifact_lineage_subgraph: gapic_v1.method.wrap_method( + self.query_artifact_lineage_subgraph, + default_timeout=None, + client_info=client_info, + ), + } + + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + + @property + def operations_client(self): + """Return the client designed to process long-running operations.""" + raise NotImplementedError() + + @property + def create_metadata_store( + self, + ) -> Callable[ + [metadata_service.CreateMetadataStoreRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def get_metadata_store( + self, + ) -> Callable[ + [metadata_service.GetMetadataStoreRequest], + Union[metadata_store.MetadataStore, Awaitable[metadata_store.MetadataStore]], + ]: + raise NotImplementedError() + + @property + def list_metadata_stores( + self, + ) -> Callable[ + [metadata_service.ListMetadataStoresRequest], + Union[ + metadata_service.ListMetadataStoresResponse, + Awaitable[metadata_service.ListMetadataStoresResponse], + ], + ]: + raise NotImplementedError() + + @property + def delete_metadata_store( + self, + ) -> Callable[ + [metadata_service.DeleteMetadataStoreRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def create_artifact( + self, + ) -> Callable[ + [metadata_service.CreateArtifactRequest], + Union[gca_artifact.Artifact, Awaitable[gca_artifact.Artifact]], + ]: + raise NotImplementedError() + + @property + def get_artifact( + self, + ) -> Callable[ + [metadata_service.GetArtifactRequest], + Union[artifact.Artifact, Awaitable[artifact.Artifact]], + ]: + raise NotImplementedError() + + @property + def list_artifacts( + self, + ) -> Callable[ + [metadata_service.ListArtifactsRequest], + Union[ + metadata_service.ListArtifactsResponse, + Awaitable[metadata_service.ListArtifactsResponse], + ], + ]: + raise NotImplementedError() + + @property + def update_artifact( + self, + ) -> Callable[ + [metadata_service.UpdateArtifactRequest], + Union[gca_artifact.Artifact, Awaitable[gca_artifact.Artifact]], + ]: + raise NotImplementedError() + + @property + def delete_artifact( + self, + ) -> Callable[ + [metadata_service.DeleteArtifactRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def purge_artifacts( + self, + ) -> Callable[ + [metadata_service.PurgeArtifactsRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def create_context( + self, + ) -> Callable[ + [metadata_service.CreateContextRequest], + Union[gca_context.Context, Awaitable[gca_context.Context]], + ]: + raise NotImplementedError() + + @property + def get_context( + self, + ) -> Callable[ + [metadata_service.GetContextRequest], + Union[context.Context, Awaitable[context.Context]], + ]: + raise NotImplementedError() + + @property + def list_contexts( + self, + ) -> Callable[ + [metadata_service.ListContextsRequest], + Union[ + metadata_service.ListContextsResponse, + Awaitable[metadata_service.ListContextsResponse], + ], + ]: + raise NotImplementedError() + + @property + def update_context( + self, + ) -> Callable[ + [metadata_service.UpdateContextRequest], + Union[gca_context.Context, Awaitable[gca_context.Context]], + ]: + raise NotImplementedError() + + @property + def delete_context( + self, + ) -> Callable[ + [metadata_service.DeleteContextRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def purge_contexts( + self, + ) -> Callable[ + [metadata_service.PurgeContextsRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def add_context_artifacts_and_executions( + self, + ) -> Callable[ + [metadata_service.AddContextArtifactsAndExecutionsRequest], + Union[ + metadata_service.AddContextArtifactsAndExecutionsResponse, + Awaitable[metadata_service.AddContextArtifactsAndExecutionsResponse], + ], + ]: + raise NotImplementedError() + + @property + def add_context_children( + self, + ) -> Callable[ + [metadata_service.AddContextChildrenRequest], + Union[ + metadata_service.AddContextChildrenResponse, + Awaitable[metadata_service.AddContextChildrenResponse], + ], + ]: + raise NotImplementedError() + + @property + def query_context_lineage_subgraph( + self, + ) -> Callable[ + [metadata_service.QueryContextLineageSubgraphRequest], + Union[ + lineage_subgraph.LineageSubgraph, + Awaitable[lineage_subgraph.LineageSubgraph], + ], + ]: + raise NotImplementedError() + + @property + def create_execution( + self, + ) -> Callable[ + [metadata_service.CreateExecutionRequest], + Union[gca_execution.Execution, Awaitable[gca_execution.Execution]], + ]: + raise NotImplementedError() + + @property + def get_execution( + self, + ) -> Callable[ + [metadata_service.GetExecutionRequest], + Union[execution.Execution, Awaitable[execution.Execution]], + ]: + raise NotImplementedError() + + @property + def list_executions( + self, + ) -> Callable[ + [metadata_service.ListExecutionsRequest], + Union[ + metadata_service.ListExecutionsResponse, + Awaitable[metadata_service.ListExecutionsResponse], + ], + ]: + raise NotImplementedError() + + @property + def update_execution( + self, + ) -> Callable[ + [metadata_service.UpdateExecutionRequest], + Union[gca_execution.Execution, Awaitable[gca_execution.Execution]], + ]: + raise NotImplementedError() + + @property + def delete_execution( + self, + ) -> Callable[ + [metadata_service.DeleteExecutionRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def purge_executions( + self, + ) -> Callable[ + [metadata_service.PurgeExecutionsRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def add_execution_events( + self, + ) -> Callable[ + [metadata_service.AddExecutionEventsRequest], + Union[ + metadata_service.AddExecutionEventsResponse, + Awaitable[metadata_service.AddExecutionEventsResponse], + ], + ]: + raise NotImplementedError() + + @property + def query_execution_inputs_and_outputs( + self, + ) -> Callable[ + [metadata_service.QueryExecutionInputsAndOutputsRequest], + Union[ + lineage_subgraph.LineageSubgraph, + Awaitable[lineage_subgraph.LineageSubgraph], + ], + ]: + raise NotImplementedError() + + @property + def create_metadata_schema( + self, + ) -> Callable[ + [metadata_service.CreateMetadataSchemaRequest], + Union[ + gca_metadata_schema.MetadataSchema, + Awaitable[gca_metadata_schema.MetadataSchema], + ], + ]: + raise NotImplementedError() + + @property + def get_metadata_schema( + self, + ) -> Callable[ + [metadata_service.GetMetadataSchemaRequest], + Union[ + metadata_schema.MetadataSchema, Awaitable[metadata_schema.MetadataSchema] + ], + ]: + raise NotImplementedError() + + @property + def list_metadata_schemas( + self, + ) -> Callable[ + [metadata_service.ListMetadataSchemasRequest], + Union[ + metadata_service.ListMetadataSchemasResponse, + Awaitable[metadata_service.ListMetadataSchemasResponse], + ], + ]: + raise NotImplementedError() + + @property + def query_artifact_lineage_subgraph( + self, + ) -> Callable[ + [metadata_service.QueryArtifactLineageSubgraphRequest], + Union[ + lineage_subgraph.LineageSubgraph, + Awaitable[lineage_subgraph.LineageSubgraph], + ], + ]: + raise NotImplementedError() + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], + Union[ + operations_pb2.ListOperationsResponse, + Awaitable[operations_pb2.ListOperationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None,]: + raise NotImplementedError() + + @property + def wait_operation( + self, + ) -> Callable[ + [operations_pb2.WaitOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def set_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def get_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_location( + self, + ) -> Callable[ + [locations_pb2.GetLocationRequest], + Union[locations_pb2.Location, Awaitable[locations_pb2.Location]], + ]: + raise NotImplementedError() + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], + Union[ + locations_pb2.ListLocationsResponse, + Awaitable[locations_pb2.ListLocationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + + +__all__ = ("MetadataServiceTransport",) diff --git a/google/cloud/aiplatform_v1/services/metadata_service/transports/grpc.py b/google/cloud/aiplatform_v1/services/metadata_service/transports/grpc.py new file mode 100644 index 0000000000..f1eb065f4f --- /dev/null +++ b/google/cloud/aiplatform_v1/services/metadata_service/transports/grpc.py @@ -0,0 +1,1349 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import warnings +from typing import Callable, Dict, Optional, Sequence, Tuple, Union + +from google.api_core import grpc_helpers +from google.api_core import operations_v1 +from google.api_core import gapic_v1 +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore + +import grpc # type: ignore + +from google.cloud.aiplatform_v1.types import artifact +from google.cloud.aiplatform_v1.types import artifact as gca_artifact +from google.cloud.aiplatform_v1.types import context +from google.cloud.aiplatform_v1.types import context as gca_context +from google.cloud.aiplatform_v1.types import execution +from google.cloud.aiplatform_v1.types import execution as gca_execution +from google.cloud.aiplatform_v1.types import lineage_subgraph +from google.cloud.aiplatform_v1.types import metadata_schema +from google.cloud.aiplatform_v1.types import metadata_schema as gca_metadata_schema +from google.cloud.aiplatform_v1.types import metadata_service +from google.cloud.aiplatform_v1.types import metadata_store +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.longrunning import operations_pb2 # type: ignore +from .base import MetadataServiceTransport, DEFAULT_CLIENT_INFO + + +class MetadataServiceGrpcTransport(MetadataServiceTransport): + """gRPC backend transport for MetadataService. + + Service for reading and writing metadata entries. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + + _stubs: Dict[str, Callable] + + def __init__( + self, + *, + host: str = "aiplatform.googleapis.com", + credentials: ga_credentials.Credentials = None, + credentials_file: str = None, + scopes: Sequence[str] = None, + channel: grpc.Channel = None, + api_mtls_endpoint: str = None, + client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, + ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + 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. + This argument is ignored if ``channel`` is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional(Sequence[str])): A list of scopes. This argument is + ignored if ``channel`` is provided. + channel (Optional[grpc.Channel]): A ``Channel`` instance through + which to make calls. + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or application default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for the grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure a mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + 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. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + self._grpc_channel = None + self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client: Optional[operations_v1.OperationsClient] = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + + if channel: + # Ignore credentials if a channel was passed. + credentials = False + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + self._ssl_channel_credentials = None + + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials + + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + ) + + if not self._grpc_channel: + self._grpc_channel = type(self).create_channel( + self._host, + # use the credentials which are saved + credentials=self._credentials, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, + quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) + + @classmethod + def create_channel( + cls, + host: str = "aiplatform.googleapis.com", + credentials: ga_credentials.Credentials = None, + credentials_file: str = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs, + ) -> grpc.Channel: + """Create and return a gRPC channel object. + Args: + host (Optional[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is mutually exclusive with credentials. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + grpc.Channel: A gRPC channel object. + + Raises: + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + + return grpc_helpers.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + quota_project_id=quota_project_id, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, + **kwargs, + ) + + @property + def grpc_channel(self) -> grpc.Channel: + """Return the channel designed to connect to this service.""" + return self._grpc_channel + + @property + def operations_client(self) -> operations_v1.OperationsClient: + """Create the client designed to process long-running operations. + + This property caches on the instance; repeated calls return the same + client. + """ + # Quick check: Only create a new client if we do not already have one. + if self._operations_client is None: + self._operations_client = operations_v1.OperationsClient(self.grpc_channel) + + # Return the client from cache. + return self._operations_client + + @property + def create_metadata_store( + self, + ) -> Callable[ + [metadata_service.CreateMetadataStoreRequest], operations_pb2.Operation + ]: + r"""Return a callable for the create metadata store method over gRPC. + + Initializes a MetadataStore, including allocation of + resources. + + Returns: + Callable[[~.CreateMetadataStoreRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_metadata_store" not in self._stubs: + self._stubs["create_metadata_store"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/CreateMetadataStore", + request_serializer=metadata_service.CreateMetadataStoreRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["create_metadata_store"] + + @property + def get_metadata_store( + self, + ) -> Callable[ + [metadata_service.GetMetadataStoreRequest], metadata_store.MetadataStore + ]: + r"""Return a callable for the get metadata store method over gRPC. + + Retrieves a specific MetadataStore. + + Returns: + Callable[[~.GetMetadataStoreRequest], + ~.MetadataStore]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_metadata_store" not in self._stubs: + self._stubs["get_metadata_store"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/GetMetadataStore", + request_serializer=metadata_service.GetMetadataStoreRequest.serialize, + response_deserializer=metadata_store.MetadataStore.deserialize, + ) + return self._stubs["get_metadata_store"] + + @property + def list_metadata_stores( + self, + ) -> Callable[ + [metadata_service.ListMetadataStoresRequest], + metadata_service.ListMetadataStoresResponse, + ]: + r"""Return a callable for the list metadata stores method over gRPC. + + Lists MetadataStores for a Location. + + Returns: + Callable[[~.ListMetadataStoresRequest], + ~.ListMetadataStoresResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_metadata_stores" not in self._stubs: + self._stubs["list_metadata_stores"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/ListMetadataStores", + request_serializer=metadata_service.ListMetadataStoresRequest.serialize, + response_deserializer=metadata_service.ListMetadataStoresResponse.deserialize, + ) + return self._stubs["list_metadata_stores"] + + @property + def delete_metadata_store( + self, + ) -> Callable[ + [metadata_service.DeleteMetadataStoreRequest], operations_pb2.Operation + ]: + r"""Return a callable for the delete metadata store method over gRPC. + + Deletes a single MetadataStore and all its child + resources (Artifacts, Executions, and Contexts). + + Returns: + Callable[[~.DeleteMetadataStoreRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_metadata_store" not in self._stubs: + self._stubs["delete_metadata_store"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/DeleteMetadataStore", + request_serializer=metadata_service.DeleteMetadataStoreRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_metadata_store"] + + @property + def create_artifact( + self, + ) -> Callable[[metadata_service.CreateArtifactRequest], gca_artifact.Artifact]: + r"""Return a callable for the create artifact method over gRPC. + + Creates an Artifact associated with a MetadataStore. + + Returns: + Callable[[~.CreateArtifactRequest], + ~.Artifact]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_artifact" not in self._stubs: + self._stubs["create_artifact"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/CreateArtifact", + request_serializer=metadata_service.CreateArtifactRequest.serialize, + response_deserializer=gca_artifact.Artifact.deserialize, + ) + return self._stubs["create_artifact"] + + @property + def get_artifact( + self, + ) -> Callable[[metadata_service.GetArtifactRequest], artifact.Artifact]: + r"""Return a callable for the get artifact method over gRPC. + + Retrieves a specific Artifact. + + Returns: + Callable[[~.GetArtifactRequest], + ~.Artifact]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_artifact" not in self._stubs: + self._stubs["get_artifact"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/GetArtifact", + request_serializer=metadata_service.GetArtifactRequest.serialize, + response_deserializer=artifact.Artifact.deserialize, + ) + return self._stubs["get_artifact"] + + @property + def list_artifacts( + self, + ) -> Callable[ + [metadata_service.ListArtifactsRequest], metadata_service.ListArtifactsResponse + ]: + r"""Return a callable for the list artifacts method over gRPC. + + Lists Artifacts in the MetadataStore. + + Returns: + Callable[[~.ListArtifactsRequest], + ~.ListArtifactsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_artifacts" not in self._stubs: + self._stubs["list_artifacts"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/ListArtifacts", + request_serializer=metadata_service.ListArtifactsRequest.serialize, + response_deserializer=metadata_service.ListArtifactsResponse.deserialize, + ) + return self._stubs["list_artifacts"] + + @property + def update_artifact( + self, + ) -> Callable[[metadata_service.UpdateArtifactRequest], gca_artifact.Artifact]: + r"""Return a callable for the update artifact method over gRPC. + + Updates a stored Artifact. + + Returns: + Callable[[~.UpdateArtifactRequest], + ~.Artifact]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_artifact" not in self._stubs: + self._stubs["update_artifact"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/UpdateArtifact", + request_serializer=metadata_service.UpdateArtifactRequest.serialize, + response_deserializer=gca_artifact.Artifact.deserialize, + ) + return self._stubs["update_artifact"] + + @property + def delete_artifact( + self, + ) -> Callable[[metadata_service.DeleteArtifactRequest], operations_pb2.Operation]: + r"""Return a callable for the delete artifact method over gRPC. + + Deletes an Artifact. + + Returns: + Callable[[~.DeleteArtifactRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_artifact" not in self._stubs: + self._stubs["delete_artifact"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/DeleteArtifact", + request_serializer=metadata_service.DeleteArtifactRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_artifact"] + + @property + def purge_artifacts( + self, + ) -> Callable[[metadata_service.PurgeArtifactsRequest], operations_pb2.Operation]: + r"""Return a callable for the purge artifacts method over gRPC. + + Purges Artifacts. + + Returns: + Callable[[~.PurgeArtifactsRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "purge_artifacts" not in self._stubs: + self._stubs["purge_artifacts"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/PurgeArtifacts", + request_serializer=metadata_service.PurgeArtifactsRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["purge_artifacts"] + + @property + def create_context( + self, + ) -> Callable[[metadata_service.CreateContextRequest], gca_context.Context]: + r"""Return a callable for the create context method over gRPC. + + Creates a Context associated with a MetadataStore. + + Returns: + Callable[[~.CreateContextRequest], + ~.Context]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_context" not in self._stubs: + self._stubs["create_context"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/CreateContext", + request_serializer=metadata_service.CreateContextRequest.serialize, + response_deserializer=gca_context.Context.deserialize, + ) + return self._stubs["create_context"] + + @property + def get_context( + self, + ) -> Callable[[metadata_service.GetContextRequest], context.Context]: + r"""Return a callable for the get context method over gRPC. + + Retrieves a specific Context. + + Returns: + Callable[[~.GetContextRequest], + ~.Context]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_context" not in self._stubs: + self._stubs["get_context"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/GetContext", + request_serializer=metadata_service.GetContextRequest.serialize, + response_deserializer=context.Context.deserialize, + ) + return self._stubs["get_context"] + + @property + def list_contexts( + self, + ) -> Callable[ + [metadata_service.ListContextsRequest], metadata_service.ListContextsResponse + ]: + r"""Return a callable for the list contexts method over gRPC. + + Lists Contexts on the MetadataStore. + + Returns: + Callable[[~.ListContextsRequest], + ~.ListContextsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_contexts" not in self._stubs: + self._stubs["list_contexts"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/ListContexts", + request_serializer=metadata_service.ListContextsRequest.serialize, + response_deserializer=metadata_service.ListContextsResponse.deserialize, + ) + return self._stubs["list_contexts"] + + @property + def update_context( + self, + ) -> Callable[[metadata_service.UpdateContextRequest], gca_context.Context]: + r"""Return a callable for the update context method over gRPC. + + Updates a stored Context. + + Returns: + Callable[[~.UpdateContextRequest], + ~.Context]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_context" not in self._stubs: + self._stubs["update_context"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/UpdateContext", + request_serializer=metadata_service.UpdateContextRequest.serialize, + response_deserializer=gca_context.Context.deserialize, + ) + return self._stubs["update_context"] + + @property + def delete_context( + self, + ) -> Callable[[metadata_service.DeleteContextRequest], operations_pb2.Operation]: + r"""Return a callable for the delete context method over gRPC. + + Deletes a stored Context. + + Returns: + Callable[[~.DeleteContextRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_context" not in self._stubs: + self._stubs["delete_context"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/DeleteContext", + request_serializer=metadata_service.DeleteContextRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_context"] + + @property + def purge_contexts( + self, + ) -> Callable[[metadata_service.PurgeContextsRequest], operations_pb2.Operation]: + r"""Return a callable for the purge contexts method over gRPC. + + Purges Contexts. + + Returns: + Callable[[~.PurgeContextsRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "purge_contexts" not in self._stubs: + self._stubs["purge_contexts"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/PurgeContexts", + request_serializer=metadata_service.PurgeContextsRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["purge_contexts"] + + @property + def add_context_artifacts_and_executions( + self, + ) -> Callable[ + [metadata_service.AddContextArtifactsAndExecutionsRequest], + metadata_service.AddContextArtifactsAndExecutionsResponse, + ]: + r"""Return a callable for the add context artifacts and + executions method over gRPC. + + Adds a set of Artifacts and Executions to a Context. + If any of the Artifacts or Executions have already been + added to a Context, they are simply skipped. + + Returns: + Callable[[~.AddContextArtifactsAndExecutionsRequest], + ~.AddContextArtifactsAndExecutionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "add_context_artifacts_and_executions" not in self._stubs: + self._stubs[ + "add_context_artifacts_and_executions" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/AddContextArtifactsAndExecutions", + request_serializer=metadata_service.AddContextArtifactsAndExecutionsRequest.serialize, + response_deserializer=metadata_service.AddContextArtifactsAndExecutionsResponse.deserialize, + ) + return self._stubs["add_context_artifacts_and_executions"] + + @property + def add_context_children( + self, + ) -> Callable[ + [metadata_service.AddContextChildrenRequest], + metadata_service.AddContextChildrenResponse, + ]: + r"""Return a callable for the add context children method over gRPC. + + Adds a set of Contexts as children to a parent Context. If any + of the child Contexts have already been added to the parent + Context, they are simply skipped. If this call would create a + cycle or cause any Context to have more than 10 parents, the + request will fail with an INVALID_ARGUMENT error. + + Returns: + Callable[[~.AddContextChildrenRequest], + ~.AddContextChildrenResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "add_context_children" not in self._stubs: + self._stubs["add_context_children"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/AddContextChildren", + request_serializer=metadata_service.AddContextChildrenRequest.serialize, + response_deserializer=metadata_service.AddContextChildrenResponse.deserialize, + ) + return self._stubs["add_context_children"] + + @property + def query_context_lineage_subgraph( + self, + ) -> Callable[ + [metadata_service.QueryContextLineageSubgraphRequest], + lineage_subgraph.LineageSubgraph, + ]: + r"""Return a callable for the query context lineage subgraph method over gRPC. + + Retrieves Artifacts and Executions within the + specified Context, connected by Event edges and returned + as a LineageSubgraph. + + Returns: + Callable[[~.QueryContextLineageSubgraphRequest], + ~.LineageSubgraph]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "query_context_lineage_subgraph" not in self._stubs: + self._stubs[ + "query_context_lineage_subgraph" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/QueryContextLineageSubgraph", + request_serializer=metadata_service.QueryContextLineageSubgraphRequest.serialize, + response_deserializer=lineage_subgraph.LineageSubgraph.deserialize, + ) + return self._stubs["query_context_lineage_subgraph"] + + @property + def create_execution( + self, + ) -> Callable[[metadata_service.CreateExecutionRequest], gca_execution.Execution]: + r"""Return a callable for the create execution method over gRPC. + + Creates an Execution associated with a MetadataStore. + + Returns: + Callable[[~.CreateExecutionRequest], + ~.Execution]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_execution" not in self._stubs: + self._stubs["create_execution"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/CreateExecution", + request_serializer=metadata_service.CreateExecutionRequest.serialize, + response_deserializer=gca_execution.Execution.deserialize, + ) + return self._stubs["create_execution"] + + @property + def get_execution( + self, + ) -> Callable[[metadata_service.GetExecutionRequest], execution.Execution]: + r"""Return a callable for the get execution method over gRPC. + + Retrieves a specific Execution. + + Returns: + Callable[[~.GetExecutionRequest], + ~.Execution]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_execution" not in self._stubs: + self._stubs["get_execution"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/GetExecution", + request_serializer=metadata_service.GetExecutionRequest.serialize, + response_deserializer=execution.Execution.deserialize, + ) + return self._stubs["get_execution"] + + @property + def list_executions( + self, + ) -> Callable[ + [metadata_service.ListExecutionsRequest], + metadata_service.ListExecutionsResponse, + ]: + r"""Return a callable for the list executions method over gRPC. + + Lists Executions in the MetadataStore. + + Returns: + Callable[[~.ListExecutionsRequest], + ~.ListExecutionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_executions" not in self._stubs: + self._stubs["list_executions"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/ListExecutions", + request_serializer=metadata_service.ListExecutionsRequest.serialize, + response_deserializer=metadata_service.ListExecutionsResponse.deserialize, + ) + return self._stubs["list_executions"] + + @property + def update_execution( + self, + ) -> Callable[[metadata_service.UpdateExecutionRequest], gca_execution.Execution]: + r"""Return a callable for the update execution method over gRPC. + + Updates a stored Execution. + + Returns: + Callable[[~.UpdateExecutionRequest], + ~.Execution]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_execution" not in self._stubs: + self._stubs["update_execution"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/UpdateExecution", + request_serializer=metadata_service.UpdateExecutionRequest.serialize, + response_deserializer=gca_execution.Execution.deserialize, + ) + return self._stubs["update_execution"] + + @property + def delete_execution( + self, + ) -> Callable[[metadata_service.DeleteExecutionRequest], operations_pb2.Operation]: + r"""Return a callable for the delete execution method over gRPC. + + Deletes an Execution. + + Returns: + Callable[[~.DeleteExecutionRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_execution" not in self._stubs: + self._stubs["delete_execution"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/DeleteExecution", + request_serializer=metadata_service.DeleteExecutionRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_execution"] + + @property + def purge_executions( + self, + ) -> Callable[[metadata_service.PurgeExecutionsRequest], operations_pb2.Operation]: + r"""Return a callable for the purge executions method over gRPC. + + Purges Executions. + + Returns: + Callable[[~.PurgeExecutionsRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "purge_executions" not in self._stubs: + self._stubs["purge_executions"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/PurgeExecutions", + request_serializer=metadata_service.PurgeExecutionsRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["purge_executions"] + + @property + def add_execution_events( + self, + ) -> Callable[ + [metadata_service.AddExecutionEventsRequest], + metadata_service.AddExecutionEventsResponse, + ]: + r"""Return a callable for the add execution events method over gRPC. + + Adds Events to the specified Execution. An Event + indicates whether an Artifact was used as an input or + output for an Execution. If an Event already exists + between the Execution and the Artifact, the Event is + skipped. + + Returns: + Callable[[~.AddExecutionEventsRequest], + ~.AddExecutionEventsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "add_execution_events" not in self._stubs: + self._stubs["add_execution_events"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/AddExecutionEvents", + request_serializer=metadata_service.AddExecutionEventsRequest.serialize, + response_deserializer=metadata_service.AddExecutionEventsResponse.deserialize, + ) + return self._stubs["add_execution_events"] + + @property + def query_execution_inputs_and_outputs( + self, + ) -> Callable[ + [metadata_service.QueryExecutionInputsAndOutputsRequest], + lineage_subgraph.LineageSubgraph, + ]: + r"""Return a callable for the query execution inputs and + outputs method over gRPC. + + Obtains the set of input and output Artifacts for + this Execution, in the form of LineageSubgraph that also + contains the Execution and connecting Events. + + Returns: + Callable[[~.QueryExecutionInputsAndOutputsRequest], + ~.LineageSubgraph]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "query_execution_inputs_and_outputs" not in self._stubs: + self._stubs[ + "query_execution_inputs_and_outputs" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/QueryExecutionInputsAndOutputs", + request_serializer=metadata_service.QueryExecutionInputsAndOutputsRequest.serialize, + response_deserializer=lineage_subgraph.LineageSubgraph.deserialize, + ) + return self._stubs["query_execution_inputs_and_outputs"] + + @property + def create_metadata_schema( + self, + ) -> Callable[ + [metadata_service.CreateMetadataSchemaRequest], + gca_metadata_schema.MetadataSchema, + ]: + r"""Return a callable for the create metadata schema method over gRPC. + + Creates a MetadataSchema. + + Returns: + Callable[[~.CreateMetadataSchemaRequest], + ~.MetadataSchema]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_metadata_schema" not in self._stubs: + self._stubs["create_metadata_schema"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/CreateMetadataSchema", + request_serializer=metadata_service.CreateMetadataSchemaRequest.serialize, + response_deserializer=gca_metadata_schema.MetadataSchema.deserialize, + ) + return self._stubs["create_metadata_schema"] + + @property + def get_metadata_schema( + self, + ) -> Callable[ + [metadata_service.GetMetadataSchemaRequest], metadata_schema.MetadataSchema + ]: + r"""Return a callable for the get metadata schema method over gRPC. + + Retrieves a specific MetadataSchema. + + Returns: + Callable[[~.GetMetadataSchemaRequest], + ~.MetadataSchema]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_metadata_schema" not in self._stubs: + self._stubs["get_metadata_schema"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/GetMetadataSchema", + request_serializer=metadata_service.GetMetadataSchemaRequest.serialize, + response_deserializer=metadata_schema.MetadataSchema.deserialize, + ) + return self._stubs["get_metadata_schema"] + + @property + def list_metadata_schemas( + self, + ) -> Callable[ + [metadata_service.ListMetadataSchemasRequest], + metadata_service.ListMetadataSchemasResponse, + ]: + r"""Return a callable for the list metadata schemas method over gRPC. + + Lists MetadataSchemas. + + Returns: + Callable[[~.ListMetadataSchemasRequest], + ~.ListMetadataSchemasResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_metadata_schemas" not in self._stubs: + self._stubs["list_metadata_schemas"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/ListMetadataSchemas", + request_serializer=metadata_service.ListMetadataSchemasRequest.serialize, + response_deserializer=metadata_service.ListMetadataSchemasResponse.deserialize, + ) + return self._stubs["list_metadata_schemas"] + + @property + def query_artifact_lineage_subgraph( + self, + ) -> Callable[ + [metadata_service.QueryArtifactLineageSubgraphRequest], + lineage_subgraph.LineageSubgraph, + ]: + r"""Return a callable for the query artifact lineage + subgraph method over gRPC. + + Retrieves lineage of an Artifact represented through + Artifacts and Executions connected by Event edges and + returned as a LineageSubgraph. + + Returns: + Callable[[~.QueryArtifactLineageSubgraphRequest], + ~.LineageSubgraph]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "query_artifact_lineage_subgraph" not in self._stubs: + self._stubs[ + "query_artifact_lineage_subgraph" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/QueryArtifactLineageSubgraph", + request_serializer=metadata_service.QueryArtifactLineageSubgraphRequest.serialize, + response_deserializer=lineage_subgraph.LineageSubgraph.deserialize, + ) + return self._stubs["query_artifact_lineage_subgraph"] + + def close(self): + self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + @property + def kind(self) -> str: + return "grpc" + + +__all__ = ("MetadataServiceGrpcTransport",) diff --git a/google/cloud/aiplatform_v1/services/metadata_service/transports/grpc_asyncio.py b/google/cloud/aiplatform_v1/services/metadata_service/transports/grpc_asyncio.py new file mode 100644 index 0000000000..a9c80edddc --- /dev/null +++ b/google/cloud/aiplatform_v1/services/metadata_service/transports/grpc_asyncio.py @@ -0,0 +1,1382 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import warnings +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union + +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import operations_v1 +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore + +import grpc # type: ignore +from grpc.experimental import aio # type: ignore + +from google.cloud.aiplatform_v1.types import artifact +from google.cloud.aiplatform_v1.types import artifact as gca_artifact +from google.cloud.aiplatform_v1.types import context +from google.cloud.aiplatform_v1.types import context as gca_context +from google.cloud.aiplatform_v1.types import execution +from google.cloud.aiplatform_v1.types import execution as gca_execution +from google.cloud.aiplatform_v1.types import lineage_subgraph +from google.cloud.aiplatform_v1.types import metadata_schema +from google.cloud.aiplatform_v1.types import metadata_schema as gca_metadata_schema +from google.cloud.aiplatform_v1.types import metadata_service +from google.cloud.aiplatform_v1.types import metadata_store +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.longrunning import operations_pb2 # type: ignore +from .base import MetadataServiceTransport, DEFAULT_CLIENT_INFO +from .grpc import MetadataServiceGrpcTransport + + +class MetadataServiceGrpcAsyncIOTransport(MetadataServiceTransport): + """gRPC AsyncIO backend transport for MetadataService. + + Service for reading and writing metadata entries. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + + _grpc_channel: aio.Channel + _stubs: Dict[str, Callable] = {} + + @classmethod + def create_channel( + cls, + host: str = "aiplatform.googleapis.com", + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs, + ) -> aio.Channel: + """Create and return a gRPC AsyncIO channel object. + Args: + host (Optional[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + aio.Channel: A gRPC AsyncIO channel object. + """ + + return grpc_helpers_async.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + quota_project_id=quota_project_id, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, + **kwargs, + ) + + def __init__( + self, + *, + host: str = "aiplatform.googleapis.com", + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: aio.Channel = None, + api_mtls_endpoint: str = None, + client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, + ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, + quota_project_id=None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + 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. + This argument is ignored if ``channel`` is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + channel (Optional[aio.Channel]): A ``Channel`` instance through + which to make calls. + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or application default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for the grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure a mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + 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. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + + Raises: + google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + self._grpc_channel = None + self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + + if channel: + # Ignore credentials if a channel was passed. + credentials = False + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + self._ssl_channel_credentials = None + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials + + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + ) + + if not self._grpc_channel: + self._grpc_channel = type(self).create_channel( + self._host, + # use the credentials which are saved + credentials=self._credentials, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, + quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) + + @property + def grpc_channel(self) -> aio.Channel: + """Create the channel designed to connect to this service. + + This property caches on the instance; repeated calls return + the same channel. + """ + # Return the channel from cache. + return self._grpc_channel + + @property + def operations_client(self) -> operations_v1.OperationsAsyncClient: + """Create the client designed to process long-running operations. + + This property caches on the instance; repeated calls return the same + client. + """ + # Quick check: Only create a new client if we do not already have one. + if self._operations_client is None: + self._operations_client = operations_v1.OperationsAsyncClient( + self.grpc_channel + ) + + # Return the client from cache. + return self._operations_client + + @property + def create_metadata_store( + self, + ) -> Callable[ + [metadata_service.CreateMetadataStoreRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the create metadata store method over gRPC. + + Initializes a MetadataStore, including allocation of + resources. + + Returns: + Callable[[~.CreateMetadataStoreRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_metadata_store" not in self._stubs: + self._stubs["create_metadata_store"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/CreateMetadataStore", + request_serializer=metadata_service.CreateMetadataStoreRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["create_metadata_store"] + + @property + def get_metadata_store( + self, + ) -> Callable[ + [metadata_service.GetMetadataStoreRequest], + Awaitable[metadata_store.MetadataStore], + ]: + r"""Return a callable for the get metadata store method over gRPC. + + Retrieves a specific MetadataStore. + + Returns: + Callable[[~.GetMetadataStoreRequest], + Awaitable[~.MetadataStore]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_metadata_store" not in self._stubs: + self._stubs["get_metadata_store"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/GetMetadataStore", + request_serializer=metadata_service.GetMetadataStoreRequest.serialize, + response_deserializer=metadata_store.MetadataStore.deserialize, + ) + return self._stubs["get_metadata_store"] + + @property + def list_metadata_stores( + self, + ) -> Callable[ + [metadata_service.ListMetadataStoresRequest], + Awaitable[metadata_service.ListMetadataStoresResponse], + ]: + r"""Return a callable for the list metadata stores method over gRPC. + + Lists MetadataStores for a Location. + + Returns: + Callable[[~.ListMetadataStoresRequest], + Awaitable[~.ListMetadataStoresResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_metadata_stores" not in self._stubs: + self._stubs["list_metadata_stores"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/ListMetadataStores", + request_serializer=metadata_service.ListMetadataStoresRequest.serialize, + response_deserializer=metadata_service.ListMetadataStoresResponse.deserialize, + ) + return self._stubs["list_metadata_stores"] + + @property + def delete_metadata_store( + self, + ) -> Callable[ + [metadata_service.DeleteMetadataStoreRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the delete metadata store method over gRPC. + + Deletes a single MetadataStore and all its child + resources (Artifacts, Executions, and Contexts). + + Returns: + Callable[[~.DeleteMetadataStoreRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_metadata_store" not in self._stubs: + self._stubs["delete_metadata_store"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/DeleteMetadataStore", + request_serializer=metadata_service.DeleteMetadataStoreRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_metadata_store"] + + @property + def create_artifact( + self, + ) -> Callable[ + [metadata_service.CreateArtifactRequest], Awaitable[gca_artifact.Artifact] + ]: + r"""Return a callable for the create artifact method over gRPC. + + Creates an Artifact associated with a MetadataStore. + + Returns: + Callable[[~.CreateArtifactRequest], + Awaitable[~.Artifact]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_artifact" not in self._stubs: + self._stubs["create_artifact"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/CreateArtifact", + request_serializer=metadata_service.CreateArtifactRequest.serialize, + response_deserializer=gca_artifact.Artifact.deserialize, + ) + return self._stubs["create_artifact"] + + @property + def get_artifact( + self, + ) -> Callable[[metadata_service.GetArtifactRequest], Awaitable[artifact.Artifact]]: + r"""Return a callable for the get artifact method over gRPC. + + Retrieves a specific Artifact. + + Returns: + Callable[[~.GetArtifactRequest], + Awaitable[~.Artifact]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_artifact" not in self._stubs: + self._stubs["get_artifact"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/GetArtifact", + request_serializer=metadata_service.GetArtifactRequest.serialize, + response_deserializer=artifact.Artifact.deserialize, + ) + return self._stubs["get_artifact"] + + @property + def list_artifacts( + self, + ) -> Callable[ + [metadata_service.ListArtifactsRequest], + Awaitable[metadata_service.ListArtifactsResponse], + ]: + r"""Return a callable for the list artifacts method over gRPC. + + Lists Artifacts in the MetadataStore. + + Returns: + Callable[[~.ListArtifactsRequest], + Awaitable[~.ListArtifactsResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_artifacts" not in self._stubs: + self._stubs["list_artifacts"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/ListArtifacts", + request_serializer=metadata_service.ListArtifactsRequest.serialize, + response_deserializer=metadata_service.ListArtifactsResponse.deserialize, + ) + return self._stubs["list_artifacts"] + + @property + def update_artifact( + self, + ) -> Callable[ + [metadata_service.UpdateArtifactRequest], Awaitable[gca_artifact.Artifact] + ]: + r"""Return a callable for the update artifact method over gRPC. + + Updates a stored Artifact. + + Returns: + Callable[[~.UpdateArtifactRequest], + Awaitable[~.Artifact]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_artifact" not in self._stubs: + self._stubs["update_artifact"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/UpdateArtifact", + request_serializer=metadata_service.UpdateArtifactRequest.serialize, + response_deserializer=gca_artifact.Artifact.deserialize, + ) + return self._stubs["update_artifact"] + + @property + def delete_artifact( + self, + ) -> Callable[ + [metadata_service.DeleteArtifactRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the delete artifact method over gRPC. + + Deletes an Artifact. + + Returns: + Callable[[~.DeleteArtifactRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_artifact" not in self._stubs: + self._stubs["delete_artifact"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/DeleteArtifact", + request_serializer=metadata_service.DeleteArtifactRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_artifact"] + + @property + def purge_artifacts( + self, + ) -> Callable[ + [metadata_service.PurgeArtifactsRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the purge artifacts method over gRPC. + + Purges Artifacts. + + Returns: + Callable[[~.PurgeArtifactsRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "purge_artifacts" not in self._stubs: + self._stubs["purge_artifacts"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/PurgeArtifacts", + request_serializer=metadata_service.PurgeArtifactsRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["purge_artifacts"] + + @property + def create_context( + self, + ) -> Callable[ + [metadata_service.CreateContextRequest], Awaitable[gca_context.Context] + ]: + r"""Return a callable for the create context method over gRPC. + + Creates a Context associated with a MetadataStore. + + Returns: + Callable[[~.CreateContextRequest], + Awaitable[~.Context]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_context" not in self._stubs: + self._stubs["create_context"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/CreateContext", + request_serializer=metadata_service.CreateContextRequest.serialize, + response_deserializer=gca_context.Context.deserialize, + ) + return self._stubs["create_context"] + + @property + def get_context( + self, + ) -> Callable[[metadata_service.GetContextRequest], Awaitable[context.Context]]: + r"""Return a callable for the get context method over gRPC. + + Retrieves a specific Context. + + Returns: + Callable[[~.GetContextRequest], + Awaitable[~.Context]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_context" not in self._stubs: + self._stubs["get_context"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/GetContext", + request_serializer=metadata_service.GetContextRequest.serialize, + response_deserializer=context.Context.deserialize, + ) + return self._stubs["get_context"] + + @property + def list_contexts( + self, + ) -> Callable[ + [metadata_service.ListContextsRequest], + Awaitable[metadata_service.ListContextsResponse], + ]: + r"""Return a callable for the list contexts method over gRPC. + + Lists Contexts on the MetadataStore. + + Returns: + Callable[[~.ListContextsRequest], + Awaitable[~.ListContextsResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_contexts" not in self._stubs: + self._stubs["list_contexts"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/ListContexts", + request_serializer=metadata_service.ListContextsRequest.serialize, + response_deserializer=metadata_service.ListContextsResponse.deserialize, + ) + return self._stubs["list_contexts"] + + @property + def update_context( + self, + ) -> Callable[ + [metadata_service.UpdateContextRequest], Awaitable[gca_context.Context] + ]: + r"""Return a callable for the update context method over gRPC. + + Updates a stored Context. + + Returns: + Callable[[~.UpdateContextRequest], + Awaitable[~.Context]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_context" not in self._stubs: + self._stubs["update_context"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/UpdateContext", + request_serializer=metadata_service.UpdateContextRequest.serialize, + response_deserializer=gca_context.Context.deserialize, + ) + return self._stubs["update_context"] + + @property + def delete_context( + self, + ) -> Callable[ + [metadata_service.DeleteContextRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the delete context method over gRPC. + + Deletes a stored Context. + + Returns: + Callable[[~.DeleteContextRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_context" not in self._stubs: + self._stubs["delete_context"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/DeleteContext", + request_serializer=metadata_service.DeleteContextRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_context"] + + @property + def purge_contexts( + self, + ) -> Callable[ + [metadata_service.PurgeContextsRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the purge contexts method over gRPC. + + Purges Contexts. + + Returns: + Callable[[~.PurgeContextsRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "purge_contexts" not in self._stubs: + self._stubs["purge_contexts"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/PurgeContexts", + request_serializer=metadata_service.PurgeContextsRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["purge_contexts"] + + @property + def add_context_artifacts_and_executions( + self, + ) -> Callable[ + [metadata_service.AddContextArtifactsAndExecutionsRequest], + Awaitable[metadata_service.AddContextArtifactsAndExecutionsResponse], + ]: + r"""Return a callable for the add context artifacts and + executions method over gRPC. + + Adds a set of Artifacts and Executions to a Context. + If any of the Artifacts or Executions have already been + added to a Context, they are simply skipped. + + Returns: + Callable[[~.AddContextArtifactsAndExecutionsRequest], + Awaitable[~.AddContextArtifactsAndExecutionsResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "add_context_artifacts_and_executions" not in self._stubs: + self._stubs[ + "add_context_artifacts_and_executions" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/AddContextArtifactsAndExecutions", + request_serializer=metadata_service.AddContextArtifactsAndExecutionsRequest.serialize, + response_deserializer=metadata_service.AddContextArtifactsAndExecutionsResponse.deserialize, + ) + return self._stubs["add_context_artifacts_and_executions"] + + @property + def add_context_children( + self, + ) -> Callable[ + [metadata_service.AddContextChildrenRequest], + Awaitable[metadata_service.AddContextChildrenResponse], + ]: + r"""Return a callable for the add context children method over gRPC. + + Adds a set of Contexts as children to a parent Context. If any + of the child Contexts have already been added to the parent + Context, they are simply skipped. If this call would create a + cycle or cause any Context to have more than 10 parents, the + request will fail with an INVALID_ARGUMENT error. + + Returns: + Callable[[~.AddContextChildrenRequest], + Awaitable[~.AddContextChildrenResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "add_context_children" not in self._stubs: + self._stubs["add_context_children"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/AddContextChildren", + request_serializer=metadata_service.AddContextChildrenRequest.serialize, + response_deserializer=metadata_service.AddContextChildrenResponse.deserialize, + ) + return self._stubs["add_context_children"] + + @property + def query_context_lineage_subgraph( + self, + ) -> Callable[ + [metadata_service.QueryContextLineageSubgraphRequest], + Awaitable[lineage_subgraph.LineageSubgraph], + ]: + r"""Return a callable for the query context lineage subgraph method over gRPC. + + Retrieves Artifacts and Executions within the + specified Context, connected by Event edges and returned + as a LineageSubgraph. + + Returns: + Callable[[~.QueryContextLineageSubgraphRequest], + Awaitable[~.LineageSubgraph]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "query_context_lineage_subgraph" not in self._stubs: + self._stubs[ + "query_context_lineage_subgraph" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/QueryContextLineageSubgraph", + request_serializer=metadata_service.QueryContextLineageSubgraphRequest.serialize, + response_deserializer=lineage_subgraph.LineageSubgraph.deserialize, + ) + return self._stubs["query_context_lineage_subgraph"] + + @property + def create_execution( + self, + ) -> Callable[ + [metadata_service.CreateExecutionRequest], Awaitable[gca_execution.Execution] + ]: + r"""Return a callable for the create execution method over gRPC. + + Creates an Execution associated with a MetadataStore. + + Returns: + Callable[[~.CreateExecutionRequest], + Awaitable[~.Execution]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_execution" not in self._stubs: + self._stubs["create_execution"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/CreateExecution", + request_serializer=metadata_service.CreateExecutionRequest.serialize, + response_deserializer=gca_execution.Execution.deserialize, + ) + return self._stubs["create_execution"] + + @property + def get_execution( + self, + ) -> Callable[ + [metadata_service.GetExecutionRequest], Awaitable[execution.Execution] + ]: + r"""Return a callable for the get execution method over gRPC. + + Retrieves a specific Execution. + + Returns: + Callable[[~.GetExecutionRequest], + Awaitable[~.Execution]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_execution" not in self._stubs: + self._stubs["get_execution"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/GetExecution", + request_serializer=metadata_service.GetExecutionRequest.serialize, + response_deserializer=execution.Execution.deserialize, + ) + return self._stubs["get_execution"] + + @property + def list_executions( + self, + ) -> Callable[ + [metadata_service.ListExecutionsRequest], + Awaitable[metadata_service.ListExecutionsResponse], + ]: + r"""Return a callable for the list executions method over gRPC. + + Lists Executions in the MetadataStore. + + Returns: + Callable[[~.ListExecutionsRequest], + Awaitable[~.ListExecutionsResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_executions" not in self._stubs: + self._stubs["list_executions"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/ListExecutions", + request_serializer=metadata_service.ListExecutionsRequest.serialize, + response_deserializer=metadata_service.ListExecutionsResponse.deserialize, + ) + return self._stubs["list_executions"] + + @property + def update_execution( + self, + ) -> Callable[ + [metadata_service.UpdateExecutionRequest], Awaitable[gca_execution.Execution] + ]: + r"""Return a callable for the update execution method over gRPC. + + Updates a stored Execution. + + Returns: + Callable[[~.UpdateExecutionRequest], + Awaitable[~.Execution]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_execution" not in self._stubs: + self._stubs["update_execution"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/UpdateExecution", + request_serializer=metadata_service.UpdateExecutionRequest.serialize, + response_deserializer=gca_execution.Execution.deserialize, + ) + return self._stubs["update_execution"] + + @property + def delete_execution( + self, + ) -> Callable[ + [metadata_service.DeleteExecutionRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the delete execution method over gRPC. + + Deletes an Execution. + + Returns: + Callable[[~.DeleteExecutionRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_execution" not in self._stubs: + self._stubs["delete_execution"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/DeleteExecution", + request_serializer=metadata_service.DeleteExecutionRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_execution"] + + @property + def purge_executions( + self, + ) -> Callable[ + [metadata_service.PurgeExecutionsRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the purge executions method over gRPC. + + Purges Executions. + + Returns: + Callable[[~.PurgeExecutionsRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "purge_executions" not in self._stubs: + self._stubs["purge_executions"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/PurgeExecutions", + request_serializer=metadata_service.PurgeExecutionsRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["purge_executions"] + + @property + def add_execution_events( + self, + ) -> Callable[ + [metadata_service.AddExecutionEventsRequest], + Awaitable[metadata_service.AddExecutionEventsResponse], + ]: + r"""Return a callable for the add execution events method over gRPC. + + Adds Events to the specified Execution. An Event + indicates whether an Artifact was used as an input or + output for an Execution. If an Event already exists + between the Execution and the Artifact, the Event is + skipped. + + Returns: + Callable[[~.AddExecutionEventsRequest], + Awaitable[~.AddExecutionEventsResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "add_execution_events" not in self._stubs: + self._stubs["add_execution_events"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/AddExecutionEvents", + request_serializer=metadata_service.AddExecutionEventsRequest.serialize, + response_deserializer=metadata_service.AddExecutionEventsResponse.deserialize, + ) + return self._stubs["add_execution_events"] + + @property + def query_execution_inputs_and_outputs( + self, + ) -> Callable[ + [metadata_service.QueryExecutionInputsAndOutputsRequest], + Awaitable[lineage_subgraph.LineageSubgraph], + ]: + r"""Return a callable for the query execution inputs and + outputs method over gRPC. + + Obtains the set of input and output Artifacts for + this Execution, in the form of LineageSubgraph that also + contains the Execution and connecting Events. + + Returns: + Callable[[~.QueryExecutionInputsAndOutputsRequest], + Awaitable[~.LineageSubgraph]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "query_execution_inputs_and_outputs" not in self._stubs: + self._stubs[ + "query_execution_inputs_and_outputs" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/QueryExecutionInputsAndOutputs", + request_serializer=metadata_service.QueryExecutionInputsAndOutputsRequest.serialize, + response_deserializer=lineage_subgraph.LineageSubgraph.deserialize, + ) + return self._stubs["query_execution_inputs_and_outputs"] + + @property + def create_metadata_schema( + self, + ) -> Callable[ + [metadata_service.CreateMetadataSchemaRequest], + Awaitable[gca_metadata_schema.MetadataSchema], + ]: + r"""Return a callable for the create metadata schema method over gRPC. + + Creates a MetadataSchema. + + Returns: + Callable[[~.CreateMetadataSchemaRequest], + Awaitable[~.MetadataSchema]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_metadata_schema" not in self._stubs: + self._stubs["create_metadata_schema"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/CreateMetadataSchema", + request_serializer=metadata_service.CreateMetadataSchemaRequest.serialize, + response_deserializer=gca_metadata_schema.MetadataSchema.deserialize, + ) + return self._stubs["create_metadata_schema"] + + @property + def get_metadata_schema( + self, + ) -> Callable[ + [metadata_service.GetMetadataSchemaRequest], + Awaitable[metadata_schema.MetadataSchema], + ]: + r"""Return a callable for the get metadata schema method over gRPC. + + Retrieves a specific MetadataSchema. + + Returns: + Callable[[~.GetMetadataSchemaRequest], + Awaitable[~.MetadataSchema]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_metadata_schema" not in self._stubs: + self._stubs["get_metadata_schema"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/GetMetadataSchema", + request_serializer=metadata_service.GetMetadataSchemaRequest.serialize, + response_deserializer=metadata_schema.MetadataSchema.deserialize, + ) + return self._stubs["get_metadata_schema"] + + @property + def list_metadata_schemas( + self, + ) -> Callable[ + [metadata_service.ListMetadataSchemasRequest], + Awaitable[metadata_service.ListMetadataSchemasResponse], + ]: + r"""Return a callable for the list metadata schemas method over gRPC. + + Lists MetadataSchemas. + + Returns: + Callable[[~.ListMetadataSchemasRequest], + Awaitable[~.ListMetadataSchemasResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_metadata_schemas" not in self._stubs: + self._stubs["list_metadata_schemas"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/ListMetadataSchemas", + request_serializer=metadata_service.ListMetadataSchemasRequest.serialize, + response_deserializer=metadata_service.ListMetadataSchemasResponse.deserialize, + ) + return self._stubs["list_metadata_schemas"] + + @property + def query_artifact_lineage_subgraph( + self, + ) -> Callable[ + [metadata_service.QueryArtifactLineageSubgraphRequest], + Awaitable[lineage_subgraph.LineageSubgraph], + ]: + r"""Return a callable for the query artifact lineage + subgraph method over gRPC. + + Retrieves lineage of an Artifact represented through + Artifacts and Executions connected by Event edges and + returned as a LineageSubgraph. + + Returns: + Callable[[~.QueryArtifactLineageSubgraphRequest], + Awaitable[~.LineageSubgraph]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "query_artifact_lineage_subgraph" not in self._stubs: + self._stubs[ + "query_artifact_lineage_subgraph" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.MetadataService/QueryArtifactLineageSubgraph", + request_serializer=metadata_service.QueryArtifactLineageSubgraphRequest.serialize, + response_deserializer=lineage_subgraph.LineageSubgraph.deserialize, + ) + return self._stubs["query_artifact_lineage_subgraph"] + + def close(self): + return self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + +__all__ = ("MetadataServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/aiplatform_v1/services/migration_service/__init__.py b/google/cloud/aiplatform_v1/services/migration_service/__init__.py index 5af6b09eb3..36329bb27d 100644 --- a/google/cloud/aiplatform_v1/services/migration_service/__init__.py +++ b/google/cloud/aiplatform_v1/services/migration_service/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1/services/migration_service/async_client.py b/google/cloud/aiplatform_v1/services/migration_service/async_client.py index 3895ec95f2..4f32f8c39f 100644 --- a/google/cloud/aiplatform_v1/services/migration_service/async_client.py +++ b/google/cloud/aiplatform_v1/services/migration_service/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,21 +16,30 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1.services.migration_service import pagers from google.cloud.aiplatform_v1.types import migratable_resource from google.cloud.aiplatform_v1.types import migration_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from .transports.base import MigrationServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import MigrationServiceGrpcAsyncIOTransport from .client import MigrationServiceClient @@ -38,8 +47,7 @@ class MigrationServiceAsyncClient: """A service that migrates resources from automl.googleapis.com, - datalabeling.googleapis.com and ml.googleapis.com to AI - Platform. + datalabeling.googleapis.com and ml.googleapis.com to Vertex AI. """ _client: MigrationServiceClient @@ -90,7 +98,8 @@ class MigrationServiceAsyncClient: @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -105,7 +114,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -120,9 +129,45 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return MigrationServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> MigrationServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: MigrationServiceTransport: The transport used by the client instance. @@ -141,7 +186,7 @@ def __init__( client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the migration service client. + """Instantiates the migration service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -182,25 +227,45 @@ def __init__( async def search_migratable_resources( self, - request: migration_service.SearchMigratableResourcesRequest = None, + request: Union[migration_service.SearchMigratableResourcesRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.SearchMigratableResourcesAsyncPager: r"""Searches all of the resources in automl.googleapis.com, datalabeling.googleapis.com and - ml.googleapis.com that can be migrated to AI Platform's + ml.googleapis.com that can be migrated to Vertex AI's given location. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_search_migratable_resources(): + # Create a client + client = aiplatform_v1.MigrationServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.SearchMigratableResourcesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.search_migratable_resources(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.SearchMigratableResourcesRequest`): + request (Union[google.cloud.aiplatform_v1.types.SearchMigratableResourcesRequest, dict]): The request object. Request message for [MigrationService.SearchMigratableResources][google.cloud.aiplatform.v1.MigrationService.SearchMigratableResources]. parent (:class:`str`): Required. The location that the migratable resources - should be searched from. It's the AI Platform location + should be searched from. It's the Vertex AI location that the resources can be migrated to, not the resources' original location. Format: ``projects/{project}/locations/{location}`` @@ -224,7 +289,7 @@ async def search_migratable_resources( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -255,12 +320,20 @@ async def search_migratable_resources( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.SearchMigratableResourcesAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -268,22 +341,51 @@ async def search_migratable_resources( async def batch_migrate_resources( self, - request: migration_service.BatchMigrateResourcesRequest = None, + request: Union[migration_service.BatchMigrateResourcesRequest, dict] = None, *, parent: str = None, migrate_resource_requests: Sequence[ migration_service.MigrateResourceRequest ] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Batch migrates resources from ml.googleapis.com, automl.googleapis.com, and datalabeling.googleapis.com - to AI Platform (Unified). + to Vertex AI. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_batch_migrate_resources(): + # Create a client + client = aiplatform_v1.MigrationServiceAsyncClient() + + # Initialize request argument(s) + migrate_resource_requests = aiplatform_v1.MigrateResourceRequest() + migrate_resource_requests.migrate_ml_engine_model_version_config.endpoint = "endpoint_value" + migrate_resource_requests.migrate_ml_engine_model_version_config.model_version = "model_version_value" + migrate_resource_requests.migrate_ml_engine_model_version_config.model_display_name = "model_display_name_value" + + request = aiplatform_v1.BatchMigrateResourcesRequest( + parent="parent_value", + migrate_resource_requests=migrate_resource_requests, + ) + + # Make the request + operation = client.batch_migrate_resources(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) Args: - request (:class:`google.cloud.aiplatform_v1.types.BatchMigrateResourcesRequest`): + request (Union[google.cloud.aiplatform_v1.types.BatchMigrateResourcesRequest, dict]): The request object. Request message for [MigrationService.BatchMigrateResources][google.cloud.aiplatform.v1.MigrationService.BatchMigrateResources]. parent (:class:`str`): @@ -321,7 +423,7 @@ async def batch_migrate_resources( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, migrate_resource_requests]) if request is not None and has_flattened_params: @@ -354,7 +456,12 @@ async def batch_migrate_resources( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -367,6 +474,683 @@ async def batch_migrate_resources( # Done; return the response. return response + async def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_operations, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.delete_operation, + default_timeout=None, + 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 cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + 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 wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.wait_operation, + default_timeout=None, + 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 set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_location, + default_timeout=None, + 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 list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_locations, + default_timeout=None, + 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 __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/aiplatform_v1/services/migration_service/client.py b/google/cloud/aiplatform_v1/services/migration_service/client.py index 8f91e19bfe..a54c452012 100644 --- a/google/cloud/aiplatform_v1/services/migration_service/client.py +++ b/google/cloud/aiplatform_v1/services/migration_service/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,27 +14,35 @@ # 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 +from typing import Dict, Mapping, 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 as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_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 +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1.services.migration_service import pagers from google.cloud.aiplatform_v1.types import migratable_resource from google.cloud.aiplatform_v1.types import migration_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from .transports.base import MigrationServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc import MigrationServiceGrpcTransport from .transports.grpc_asyncio import MigrationServiceGrpcAsyncIOTransport @@ -54,8 +62,11 @@ class MigrationServiceClientMeta(type): _transport_registry["grpc"] = MigrationServiceGrpcTransport _transport_registry["grpc_asyncio"] = MigrationServiceGrpcAsyncIOTransport - def get_transport_class(cls, label: str = None,) -> Type[MigrationServiceTransport]: - """Return an appropriate transport class. + def get_transport_class( + cls, + label: str = None, + ) -> Type[MigrationServiceTransport]: + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -75,13 +86,13 @@ def get_transport_class(cls, label: str = None,) -> Type[MigrationServiceTranspo class MigrationServiceClient(metaclass=MigrationServiceClientMeta): """A service that migrates resources from automl.googleapis.com, - datalabeling.googleapis.com and ml.googleapis.com to AI - Platform. + datalabeling.googleapis.com and ml.googleapis.com to Vertex AI. """ @staticmethod def _get_default_mtls_endpoint(api_endpoint): - """Convert api endpoint to mTLS endpoint. + """Converts api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. Args: @@ -115,7 +126,8 @@ def _get_default_mtls_endpoint(api_endpoint): @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -132,7 +144,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -151,25 +163,30 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> MigrationServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - MigrationServiceTransport: The transport used by the client instance. + MigrationServiceTransport: The transport used by the client + instance. """ return self._transport @staticmethod def annotated_dataset_path( - project: str, dataset: str, annotated_dataset: str, + project: str, + dataset: str, + annotated_dataset: str, ) -> str: - """Return a fully-qualified annotated_dataset string.""" + """Returns a fully-qualified annotated_dataset string.""" return "projects/{project}/datasets/{dataset}/annotatedDatasets/{annotated_dataset}".format( - project=project, dataset=dataset, annotated_dataset=annotated_dataset, + project=project, + dataset=dataset, + annotated_dataset=annotated_dataset, ) @staticmethod def parse_annotated_dataset_path(path: str) -> Dict[str, str]: - """Parse a annotated_dataset path into its component segments.""" + """Parses a annotated_dataset path into its component segments.""" m = re.match( r"^projects/(?P.+?)/datasets/(?P.+?)/annotatedDatasets/(?P.+?)$", path, @@ -177,15 +194,38 @@ def parse_annotated_dataset_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def dataset_path(project: str, location: str, dataset: str,) -> str: - """Return a fully-qualified dataset string.""" + def dataset_path( + project: str, + dataset: str, + ) -> str: + """Returns a fully-qualified dataset string.""" + return "projects/{project}/datasets/{dataset}".format( + project=project, + dataset=dataset, + ) + + @staticmethod + def parse_dataset_path(path: str) -> Dict[str, str]: + """Parses a dataset path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/datasets/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def dataset_path( + project: str, + location: str, + dataset: str, + ) -> str: + """Returns a fully-qualified dataset string.""" return "projects/{project}/locations/{location}/datasets/{dataset}".format( - project=project, location=location, dataset=dataset, + project=project, + location=location, + dataset=dataset, ) @staticmethod def parse_dataset_path(path: str) -> Dict[str, str]: - """Parse a dataset path into its component segments.""" + """Parses a dataset path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/datasets/(?P.+?)$", path, @@ -193,44 +233,43 @@ def parse_dataset_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def dataset_path(project: str, location: str, dataset: str,) -> str: - """Return a fully-qualified dataset string.""" + def dataset_path( + project: str, + location: str, + dataset: str, + ) -> str: + """Returns a fully-qualified dataset string.""" return "projects/{project}/locations/{location}/datasets/{dataset}".format( - project=project, location=location, dataset=dataset, + project=project, + location=location, + dataset=dataset, ) @staticmethod def parse_dataset_path(path: str) -> Dict[str, str]: - """Parse a dataset path into its component segments.""" + """Parses a dataset path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/datasets/(?P.+?)$", path, ) return m.groupdict() if m else {} - # @staticmethod - # def dataset_path(project: str, dataset: str,) -> str: - # """Return a fully-qualified dataset string.""" - # return "projects/{project}/datasets/{dataset}".format( - # project=project, dataset=dataset, - # ) - - # @staticmethod - # def parse_dataset_path(path: str) -> Dict[str, str]: - # """Parse a dataset path into its component segments.""" - # m = re.match(r"^projects/(?P.+?)/datasets/(?P.+?)$", path) - # return m.groupdict() if m else {} - @staticmethod - def model_path(project: str, location: str, model: str,) -> str: - """Return a fully-qualified model string.""" + def model_path( + project: str, + location: str, + model: str, + ) -> str: + """Returns a fully-qualified model string.""" return "projects/{project}/locations/{location}/models/{model}".format( - project=project, location=location, model=model, + project=project, + location=location, + model=model, ) @staticmethod def parse_model_path(path: str) -> Dict[str, str]: - """Parse a model path into its component segments.""" + """Parses a model path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/models/(?P.+?)$", path, @@ -238,15 +277,21 @@ def parse_model_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def model_path(project: str, location: str, model: str,) -> str: - """Return a fully-qualified model string.""" + def model_path( + project: str, + location: str, + model: str, + ) -> str: + """Returns a fully-qualified model string.""" return "projects/{project}/locations/{location}/models/{model}".format( - project=project, location=location, model=model, + project=project, + location=location, + model=model, ) @staticmethod def parse_model_path(path: str) -> Dict[str, str]: - """Parse a model path into its component segments.""" + """Parses a model path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/models/(?P.+?)$", path, @@ -254,15 +299,21 @@ def parse_model_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def version_path(project: str, model: str, version: str,) -> str: - """Return a fully-qualified version string.""" + def version_path( + project: str, + model: str, + version: str, + ) -> str: + """Returns a fully-qualified version string.""" return "projects/{project}/models/{model}/versions/{version}".format( - project=project, model=model, version=version, + project=project, + model=model, + version=version, ) @staticmethod def parse_version_path(path: str) -> Dict[str, str]: - """Parse a version path into its component segments.""" + """Parses a version path into its component segments.""" m = re.match( r"^projects/(?P.+?)/models/(?P.+?)/versions/(?P.+?)$", path, @@ -270,8 +321,10 @@ def parse_version_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + def common_billing_account_path( + billing_account: str, + ) -> str: + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -283,9 +336,13 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: 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,) + def common_folder_path( + folder: str, + ) -> str: + """Returns a fully-qualified folder string.""" + return "folders/{folder}".format( + folder=folder, + ) @staticmethod def parse_common_folder_path(path: str) -> Dict[str, str]: @@ -294,9 +351,13 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: 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,) + def common_organization_path( + organization: str, + ) -> str: + """Returns a fully-qualified organization string.""" + return "organizations/{organization}".format( + organization=organization, + ) @staticmethod def parse_common_organization_path(path: str) -> Dict[str, str]: @@ -305,9 +366,13 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: 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,) + def common_project_path( + project: str, + ) -> str: + """Returns a fully-qualified project string.""" + return "projects/{project}".format( + project=project, + ) @staticmethod def parse_common_project_path(path: str) -> Dict[str, str]: @@ -316,10 +381,14 @@ def parse_common_project_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_location_path(project: str, location: str,) -> str: - """Return a fully-qualified location string.""" + def common_location_path( + project: str, + location: str, + ) -> str: + """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) @staticmethod @@ -328,6 +397,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + def __init__( self, *, @@ -336,7 +472,7 @@ def __init__( client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the migration service client. + """Instantiates the migration service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -378,58 +514,42 @@ def __init__( 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")) + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - client_cert_source_func = ( - mtls.default_client_cert_source() 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" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # 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, MigrationServiceTransport): # transport is a MigrationServiceTransport instance. - if credentials or client_options.credentials_file: + if credentials or client_options.credentials_file or api_key_value: 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." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + Transport = type(self).get_transport_class(transport) self._transport = Transport( credentials=credentials, @@ -439,29 +559,50 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, + always_use_jwt_access=True, ) def search_migratable_resources( self, - request: migration_service.SearchMigratableResourcesRequest = None, + request: Union[migration_service.SearchMigratableResourcesRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.SearchMigratableResourcesPager: r"""Searches all of the resources in automl.googleapis.com, datalabeling.googleapis.com and - ml.googleapis.com that can be migrated to AI Platform's + ml.googleapis.com that can be migrated to Vertex AI's given location. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_search_migratable_resources(): + # Create a client + client = aiplatform_v1.MigrationServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.SearchMigratableResourcesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.search_migratable_resources(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1.types.SearchMigratableResourcesRequest): + request (Union[google.cloud.aiplatform_v1.types.SearchMigratableResourcesRequest, dict]): The request object. Request message for [MigrationService.SearchMigratableResources][google.cloud.aiplatform.v1.MigrationService.SearchMigratableResources]. parent (str): Required. The location that the migratable resources - should be searched from. It's the AI Platform location + should be searched from. It's the Vertex AI location that the resources can be migrated to, not the resources' original location. Format: ``projects/{project}/locations/{location}`` @@ -485,7 +626,7 @@ def search_migratable_resources( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -518,12 +659,20 @@ def search_migratable_resources( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.SearchMigratableResourcesPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -531,22 +680,51 @@ def search_migratable_resources( def batch_migrate_resources( self, - request: migration_service.BatchMigrateResourcesRequest = None, + request: Union[migration_service.BatchMigrateResourcesRequest, dict] = None, *, parent: str = None, migrate_resource_requests: Sequence[ migration_service.MigrateResourceRequest ] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Batch migrates resources from ml.googleapis.com, automl.googleapis.com, and datalabeling.googleapis.com - to AI Platform (Unified). + to Vertex AI. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_batch_migrate_resources(): + # Create a client + client = aiplatform_v1.MigrationServiceClient() + + # Initialize request argument(s) + migrate_resource_requests = aiplatform_v1.MigrateResourceRequest() + migrate_resource_requests.migrate_ml_engine_model_version_config.endpoint = "endpoint_value" + migrate_resource_requests.migrate_ml_engine_model_version_config.model_version = "model_version_value" + migrate_resource_requests.migrate_ml_engine_model_version_config.model_display_name = "model_display_name_value" + + request = aiplatform_v1.BatchMigrateResourcesRequest( + parent="parent_value", + migrate_resource_requests=migrate_resource_requests, + ) + + # Make the request + operation = client.batch_migrate_resources(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) Args: - request (google.cloud.aiplatform_v1.types.BatchMigrateResourcesRequest): + request (Union[google.cloud.aiplatform_v1.types.BatchMigrateResourcesRequest, dict]): The request object. Request message for [MigrationService.BatchMigrateResources][google.cloud.aiplatform.v1.MigrationService.BatchMigrateResources]. parent (str): @@ -584,7 +762,7 @@ def batch_migrate_resources( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, migrate_resource_requests]) if request is not None and has_flattened_params: @@ -617,7 +795,12 @@ def batch_migrate_resources( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation.from_gapic( @@ -630,6 +813,690 @@ def batch_migrate_resources( # Done; return the response. return response + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_operations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.delete_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.wait_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_location, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_locations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/aiplatform_v1/services/migration_service/pagers.py b/google/cloud/aiplatform_v1/services/migration_service/pagers.py index 331763e599..241b457eba 100644 --- a/google/cloud/aiplatform_v1/services/migration_service/pagers.py +++ b/google/cloud/aiplatform_v1/services/migration_service/pagers.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,13 +15,13 @@ # from typing import ( Any, - AsyncIterable, + AsyncIterator, Awaitable, Callable, - Iterable, Sequence, Tuple, Optional, + Iterator, ) from google.cloud.aiplatform_v1.types import migratable_resource @@ -75,14 +75,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[migration_service.SearchMigratableResourcesResponse]: + def pages(self) -> Iterator[migration_service.SearchMigratableResourcesResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[migratable_resource.MigratableResource]: + def __iter__(self) -> Iterator[migratable_resource.MigratableResource]: for page in self.pages: yield from page.migratable_resources @@ -118,7 +118,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -141,14 +141,14 @@ def __getattr__(self, name: str) -> Any: @property async def pages( self, - ) -> AsyncIterable[migration_service.SearchMigratableResourcesResponse]: + ) -> AsyncIterator[migration_service.SearchMigratableResourcesResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[migratable_resource.MigratableResource]: + def __aiter__(self) -> AsyncIterator[migratable_resource.MigratableResource]: async def async_generator(): async for page in self.pages: for response in page.migratable_resources: diff --git a/google/cloud/aiplatform_v1/services/migration_service/transports/__init__.py b/google/cloud/aiplatform_v1/services/migration_service/transports/__init__.py index 565048f2a3..10ee1426af 100644 --- a/google/cloud/aiplatform_v1/services/migration_service/transports/__init__.py +++ b/google/cloud/aiplatform_v1/services/migration_service/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1/services/migration_service/transports/base.py b/google/cloud/aiplatform_v1/services/migration_service/transports/base.py index 6dc3d69c17..a7ee19ae47 100644 --- a/google/cloud/aiplatform_v1/services/migration_service/transports/base.py +++ b/google/cloud/aiplatform_v1/services/migration_service/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,18 +15,22 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.api_core import operations_v1 # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.aiplatform_v1.types import migration_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore try: @@ -38,17 +42,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - -_API_CORE_VERSION = google.api_core.__version__ - class MigrationServiceTransport(abc.ABC): """Abstract transport class for MigrationService.""" @@ -66,6 +59,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,16 +83,19 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -111,59 +108,21 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id ) - # Save the credentials. - self._credentials = credentials - - # TODO(busunkim): These two class methods are in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-api-core - # and google-auth are increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") + # If the credentials are service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs + credentials = credentials.with_always_use_jwt_access(True) - # TODO: Remove this function once google-api-core >= 1.26.0 is required - @classmethod - def _get_self_signed_jwt_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Union[Optional[Sequence[str]], str]]: - """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" - - self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} - - if _API_CORE_VERSION and ( - packaging.version.parse(_API_CORE_VERSION) - >= packaging.version.parse("1.26.0") - ): - self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES - self_signed_jwt_kwargs["scopes"] = scopes - self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST - else: - self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES - - return self_signed_jwt_kwargs + # Save the credentials. + self._credentials = credentials def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. @@ -180,8 +139,17 @@ def _prep_wrapped_messages(self, client_info): ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() @@ -206,5 +174,102 @@ def batch_migrate_resources( ]: raise NotImplementedError() + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], + Union[ + operations_pb2.ListOperationsResponse, + Awaitable[operations_pb2.ListOperationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None,]: + raise NotImplementedError() + + @property + def wait_operation( + self, + ) -> Callable[ + [operations_pb2.WaitOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def set_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def get_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_location( + self, + ) -> Callable[ + [locations_pb2.GetLocationRequest], + Union[locations_pb2.Location, Awaitable[locations_pb2.Location]], + ]: + raise NotImplementedError() + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], + Union[ + locations_pb2.ListLocationsResponse, + Awaitable[locations_pb2.ListLocationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + __all__ = ("MigrationServiceTransport",) diff --git a/google/cloud/aiplatform_v1/services/migration_service/transports/grpc.py b/google/cloud/aiplatform_v1/services/migration_service/transports/grpc.py index e138cb32c6..ace78d080f 100644 --- a/google/cloud/aiplatform_v1/services/migration_service/transports/grpc.py +++ b/google/cloud/aiplatform_v1/services/migration_service/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,9 +16,9 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import operations_v1 +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -26,6 +26,10 @@ import grpc # type: ignore from google.cloud.aiplatform_v1.types import migration_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from .base import MigrationServiceTransport, DEFAULT_CLIENT_INFO @@ -34,8 +38,7 @@ class MigrationServiceGrpcTransport(MigrationServiceTransport): """gRPC backend transport for MigrationService. A service that migrates resources from automl.googleapis.com, - datalabeling.googleapis.com and ml.googleapis.com to AI - Platform. + datalabeling.googleapis.com and ml.googleapis.com to Vertex AI. This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation @@ -61,6 +64,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -83,16 +87,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -101,6 +105,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport @@ -111,7 +117,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -154,13 +160,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -209,21 +219,20 @@ def create_channel( and ``credentials_file`` are passed. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @property def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ + """Return the channel designed to connect to this service.""" return self._grpc_channel @property @@ -233,7 +242,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsClient(self.grpc_channel) @@ -251,7 +260,7 @@ def search_migratable_resources( Searches all of the resources in automl.googleapis.com, datalabeling.googleapis.com and - ml.googleapis.com that can be migrated to AI Platform's + ml.googleapis.com that can be migrated to Vertex AI's given location. Returns: @@ -282,7 +291,7 @@ def batch_migrate_resources( Batch migrates resources from ml.googleapis.com, automl.googleapis.com, and datalabeling.googleapis.com - to AI Platform (Unified). + to Vertex AI. Returns: Callable[[~.BatchMigrateResourcesRequest], @@ -302,5 +311,215 @@ def batch_migrate_resources( ) return self._stubs["batch_migrate_resources"] + def close(self): + self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + @property + def kind(self) -> str: + return "grpc" + __all__ = ("MigrationServiceGrpcTransport",) diff --git a/google/cloud/aiplatform_v1/services/migration_service/transports/grpc_asyncio.py b/google/cloud/aiplatform_v1/services/migration_service/transports/grpc_asyncio.py index ba8d3a4841..6e6c4cb024 100644 --- a/google/cloud/aiplatform_v1/services/migration_service/transports/grpc_asyncio.py +++ b/google/cloud/aiplatform_v1/services/migration_service/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,17 +16,20 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore -from google.api_core import operations_v1 # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore from google.cloud.aiplatform_v1.types import migration_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from .base import MigrationServiceTransport, DEFAULT_CLIENT_INFO from .grpc import MigrationServiceGrpcTransport @@ -36,8 +39,7 @@ class MigrationServiceGrpcAsyncIOTransport(MigrationServiceTransport): """gRPC AsyncIO backend transport for MigrationService. A service that migrates resources from automl.googleapis.com, - datalabeling.googleapis.com and ml.googleapis.com to AI - Platform. + datalabeling.googleapis.com and ml.googleapis.com to Vertex AI. This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation @@ -82,14 +84,14 @@ def create_channel( aio.Channel: A gRPC AsyncIO channel object. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @@ -107,6 +109,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -130,16 +133,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -148,6 +151,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport @@ -158,7 +163,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -200,13 +205,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -236,7 +245,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel @@ -256,7 +265,7 @@ def search_migratable_resources( Searches all of the resources in automl.googleapis.com, datalabeling.googleapis.com and - ml.googleapis.com that can be migrated to AI Platform's + ml.googleapis.com that can be migrated to Vertex AI's given location. Returns: @@ -288,7 +297,7 @@ def batch_migrate_resources( Batch migrates resources from ml.googleapis.com, automl.googleapis.com, and datalabeling.googleapis.com - to AI Platform (Unified). + to Vertex AI. Returns: Callable[[~.BatchMigrateResourcesRequest], @@ -308,5 +317,211 @@ def batch_migrate_resources( ) return self._stubs["batch_migrate_resources"] + def close(self): + return self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + __all__ = ("MigrationServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/aiplatform_v1/services/model_service/__init__.py b/google/cloud/aiplatform_v1/services/model_service/__init__.py index 7395b28fcb..d5781359f4 100644 --- a/google/cloud/aiplatform_v1/services/model_service/__init__.py +++ b/google/cloud/aiplatform_v1/services/model_service/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1/services/model_service/async_client.py b/google/cloud/aiplatform_v1/services/model_service/async_client.py index d6d932f62f..d939c13ffb 100644 --- a/google/cloud/aiplatform_v1/services/model_service/async_client.py +++ b/google/cloud/aiplatform_v1/services/model_service/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,27 +16,38 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation as gac_operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1.services.model_service import pagers from google.cloud.aiplatform_v1.types import deployed_model_ref from google.cloud.aiplatform_v1.types import encryption_spec +from google.cloud.aiplatform_v1.types import explanation from google.cloud.aiplatform_v1.types import model from google.cloud.aiplatform_v1.types import model as gca_model from google.cloud.aiplatform_v1.types import model_evaluation +from google.cloud.aiplatform_v1.types import model_evaluation as gca_model_evaluation from google.cloud.aiplatform_v1.types import model_evaluation_slice from google.cloud.aiplatform_v1.types import model_service from google.cloud.aiplatform_v1.types import operation as gca_operation +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import struct_pb2 # type: ignore @@ -47,7 +58,7 @@ class ModelServiceAsyncClient: - """A service for managing AI Platform's machine learning Models.""" + """A service for managing Vertex AI's machine learning Models.""" _client: ModelServiceClient @@ -95,7 +106,8 @@ class ModelServiceAsyncClient: @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -110,7 +122,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -125,9 +137,45 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return ModelServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> ModelServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: ModelServiceTransport: The transport used by the client instance. @@ -146,7 +194,7 @@ def __init__( client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the model service client. + """Instantiates the model service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -187,18 +235,45 @@ def __init__( async def upload_model( self, - request: model_service.UploadModelRequest = None, + request: Union[model_service.UploadModelRequest, dict] = None, *, parent: str = None, model: gca_model.Model = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: - r"""Uploads a Model artifact into AI Platform. + r"""Uploads a Model artifact into Vertex AI. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_upload_model(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + model = aiplatform_v1.Model() + model.display_name = "display_name_value" + + request = aiplatform_v1.UploadModelRequest( + parent="parent_value", + model=model, + ) + + # Make the request + operation = client.upload_model(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) Args: - request (:class:`google.cloud.aiplatform_v1.types.UploadModelRequest`): + request (Union[google.cloud.aiplatform_v1.types.UploadModelRequest, dict]): The request object. Request message for [ModelService.UploadModel][google.cloud.aiplatform.v1.ModelService.UploadModel]. parent (:class:`str`): @@ -232,7 +307,7 @@ async def upload_model( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, model]) if request is not None and has_flattened_params: @@ -254,7 +329,7 @@ async def upload_model( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.upload_model, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -265,7 +340,12 @@ async def upload_model( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -280,23 +360,53 @@ async def upload_model( async def get_model( self, - request: model_service.GetModelRequest = None, + request: Union[model_service.GetModelRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> model.Model: r"""Gets a Model. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_get_model(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetModelRequest( + name="name_value", + ) + + # Make the request + response = await client.get_model(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.GetModelRequest`): + request (Union[google.cloud.aiplatform_v1.types.GetModelRequest, dict]): The request object. Request message for [ModelService.GetModel][google.cloud.aiplatform.v1.ModelService.GetModel]. name (:class:`str`): Required. The name of the Model resource. Format: ``projects/{project}/locations/{location}/models/{model}`` + In order to retrieve a specific version of the model, + also provide the version ID or version alias. Example: + ``projects/{project}/locations/{location}/models/{model}@2`` + or + ``projects/{project}/locations/{location}/models/{model}@golden`` + If no version ID or alias is specified, the "default" + version will be returned. The "default" version alias is + created for the first version of the model, and can be + moved to other versions later on. There will be exactly + one default version. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -311,7 +421,7 @@ async def get_model( A trained machine learning Model. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -331,7 +441,7 @@ async def get_model( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.get_model, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -342,24 +452,49 @@ async def get_model( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_models( self, - request: model_service.ListModelsRequest = None, + request: Union[model_service.ListModelsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListModelsAsyncPager: r"""Lists Models in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_list_models(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListModelsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_models(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.ListModelsRequest`): + request (Union[google.cloud.aiplatform_v1.types.ListModelsRequest, dict]): The request object. Request message for [ModelService.ListModels][google.cloud.aiplatform.v1.ModelService.ListModels]. parent (:class:`str`): @@ -386,7 +521,7 @@ async def list_models( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -406,7 +541,7 @@ async def list_models( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.list_models, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -417,12 +552,128 @@ async def list_models( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListModelsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def list_model_versions( + self, + request: Union[model_service.ListModelVersionsRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListModelVersionsAsyncPager: + r"""Lists versions of the specified model. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_list_model_versions(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListModelVersionsRequest( + name="name_value", + ) + + # Make the request + page_result = client.list_model_versions(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListModelVersionsRequest, dict]): + The request object. Request message for + [ModelService.ListModelVersions][google.cloud.aiplatform.v1.ModelService.ListModelVersions]. + name (:class:`str`): + Required. The name of the model to + list versions for. + + 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: + google.cloud.aiplatform_v1.services.model_service.pagers.ListModelVersionsAsyncPager: + Response message for + [ModelService.ListModelVersions][google.cloud.aiplatform.v1.ModelService.ListModelVersions] + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = model_service.ListModelVersionsRequest(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.list_model_versions, + default_timeout=None, + 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, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListModelVersionsAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -430,23 +681,66 @@ async def list_models( async def update_model( self, - request: model_service.UpdateModelRequest = None, + request: Union[model_service.UpdateModelRequest, dict] = None, *, model: gca_model.Model = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_model.Model: r"""Updates a Model. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_update_model(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + model = aiplatform_v1.Model() + model.display_name = "display_name_value" + + request = aiplatform_v1.UpdateModelRequest( + model=model, + ) + + # Make the request + response = await client.update_model(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.UpdateModelRequest`): + request (Union[google.cloud.aiplatform_v1.types.UpdateModelRequest, dict]): The request object. Request message for [ModelService.UpdateModel][google.cloud.aiplatform.v1.ModelService.UpdateModel]. model (:class:`google.cloud.aiplatform_v1.types.Model`): - Required. The Model which replaces - the resource on the server. + Required. The Model which replaces the resource on the + server. When Model Versioning is enabled, the model.name + will be used to determine whether to update the model or + model version. + + 1. model.name with the @ value, e.g. models/123@1, + refers to a version specific update. + 2. model.name without the @ value, e.g. models/123, + refers to a model update. + 3. model.name with @-, e.g. models/123@-, refers to a + model update. + 4. Supported model fields: display_name, description; + supported version-specific fields: + version_description. Labels are supported in both + scenarios. Both the model labels and the version + labels are merged when a model is returned. When + updating labels, if the request is for model-specific + update, model label gets updated. Otherwise, version + labels get updated. + 5. A model name or model version name fields update + mismatch will cause a precondition error. + 6. One request cannot update both the model and the + version fields. You must update them separately. This corresponds to the ``model`` field on the ``request`` instance; if ``request`` is provided, this @@ -454,7 +748,7 @@ async def update_model( update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): Required. The update mask applies to the resource. For the ``FieldMask`` definition, see - `FieldMask `__. + [google.protobuf.FieldMask][google.protobuf.FieldMask]. This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this @@ -470,7 +764,7 @@ async def update_model( A trained machine learning Model. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([model, update_mask]) if request is not None and has_flattened_params: @@ -492,7 +786,7 @@ async def update_model( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.update_model, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -505,26 +799,59 @@ async def update_model( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def delete_model( self, - request: model_service.DeleteModelRequest = None, + request: Union[model_service.DeleteModelRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a Model. - Note: Model can only be deleted if there are no - DeployedModels created from it. + + A model cannot be deleted if any + [Endpoint][google.cloud.aiplatform.v1.Endpoint] resource has a + [DeployedModel][google.cloud.aiplatform.v1.DeployedModel] based + on the model in its + [deployed_models][google.cloud.aiplatform.v1.Endpoint.deployed_models] + field. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_delete_model(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteModelRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_model(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) Args: - request (:class:`google.cloud.aiplatform_v1.types.DeleteModelRequest`): + request (Union[google.cloud.aiplatform_v1.types.DeleteModelRequest, dict]): The request object. Request message for [ModelService.DeleteModel][google.cloud.aiplatform.v1.ModelService.DeleteModel]. name (:class:`str`): @@ -561,7 +888,7 @@ async def delete_model( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -581,7 +908,7 @@ async def delete_model( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.delete_model, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -592,7 +919,12 @@ async def delete_model( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -605,38 +937,58 @@ async def delete_model( # Done; return the response. return response - async def export_model( + async def delete_model_version( self, - request: model_service.ExportModelRequest = None, + request: Union[model_service.DeleteModelVersionRequest, dict] = None, *, name: str = None, - output_config: model_service.ExportModelRequest.OutputConfig = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: - r"""Exports a trained, exportable, Model to a location specified by - the user. A Model is considered to be exportable if it has at - least one [supported export - format][google.cloud.aiplatform.v1.Model.supported_export_formats]. + r"""Deletes a Model version. + + Model version can only be deleted if there are no + [DeployedModels][] created from it. Deleting the only version in + the Model is not allowed. Use + [DeleteModel][google.cloud.aiplatform.v1.ModelService.DeleteModel] + for deleting the Model instead. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_delete_model_version(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteModelVersionRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_model_version(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) Args: - request (:class:`google.cloud.aiplatform_v1.types.ExportModelRequest`): + request (Union[google.cloud.aiplatform_v1.types.DeleteModelVersionRequest, dict]): The request object. Request message for - [ModelService.ExportModel][google.cloud.aiplatform.v1.ModelService.ExportModel]. + [ModelService.DeleteModelVersion][google.cloud.aiplatform.v1.ModelService.DeleteModelVersion]. name (:class:`str`): - Required. The resource name of the Model to export. - Format: - ``projects/{project}/locations/{location}/models/{model}`` + Required. The name of the model version to be deleted, + with a version ID explicitly included. - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - output_config (:class:`google.cloud.aiplatform_v1.types.ExportModelRequest.OutputConfig`): - Required. The desired output location - and configuration. + Example: + ``projects/{project}/locations/{location}/models/{model}@1234`` - This corresponds to the ``output_config`` field + 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, @@ -649,37 +1001,43 @@ async def export_model( google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. - The result type for the operation will be - :class:`google.cloud.aiplatform_v1.types.ExportModelResponse` - Response message of - [ModelService.ExportModel][google.cloud.aiplatform.v1.ModelService.ExportModel] - operation. + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, output_config]) + 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 = model_service.ExportModelRequest(request) + request = model_service.DeleteModelVersionRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if name is not None: request.name = name - if output_config is not None: - request.output_config = output_config # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( - self._client._transport.export_model, - default_timeout=5.0, + self._client._transport.delete_model_version, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -690,43 +1048,90 @@ async def export_model( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( response, self._client._transport.operations_client, - model_service.ExportModelResponse, - metadata_type=model_service.ExportModelOperationMetadata, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, ) # Done; return the response. return response - async def get_model_evaluation( + async def merge_version_aliases( self, - request: model_service.GetModelEvaluationRequest = None, + request: Union[model_service.MergeVersionAliasesRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + version_aliases: Sequence[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> model_evaluation.ModelEvaluation: - r"""Gets a ModelEvaluation. + ) -> model.Model: + r"""Merges a set of aliases for a Model version. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_merge_version_aliases(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.MergeVersionAliasesRequest( + name="name_value", + version_aliases=['version_aliases_value_1', 'version_aliases_value_2'], + ) + + # Make the request + response = await client.merge_version_aliases(request=request) + + # Handle the response + print(response) Args: - request (:class:`google.cloud.aiplatform_v1.types.GetModelEvaluationRequest`): + request (Union[google.cloud.aiplatform_v1.types.MergeVersionAliasesRequest, dict]): The request object. Request message for - [ModelService.GetModelEvaluation][google.cloud.aiplatform.v1.ModelService.GetModelEvaluation]. + [ModelService.MergeVersionAliases][google.cloud.aiplatform.v1.ModelService.MergeVersionAliases]. name (:class:`str`): - Required. The name of the ModelEvaluation resource. - Format: + Required. The name of the model version to merge + aliases, with a version ID explicitly included. - ``projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}`` + Example: + ``projects/{project}/locations/{location}/models/{model}@1234`` This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. + version_aliases (:class:`Sequence[str]`): + Required. The set of version aliases to merge. The alias + should be at most 128 characters, and match + ``[a-z][a-z0-9-]{0,126}[a-z-0-9]``. Add the ``-`` prefix + to an alias means removing that alias from the version. + ``-`` is NOT counted in the 128 characters. Example: + ``-golden`` means removing the ``golden`` alias from the + version. + + There is NO ordering in aliases, which means + + 1) The aliases returned from GetModel API might not have + the exactly same order from this MergeVersionAliases + API. 2) Adding and deleting the same alias in the + request is not recommended, and the 2 operations will + be cancelled out. + + This corresponds to the ``version_aliases`` 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. @@ -734,35 +1139,33 @@ async def get_model_evaluation( sent along with the request as metadata. Returns: - google.cloud.aiplatform_v1.types.ModelEvaluation: - A collection of metrics calculated by - comparing Model's predictions on all of - the test data against annotations from - the test data. - + google.cloud.aiplatform_v1.types.Model: + A trained machine learning Model. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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]) + has_flattened_params = any([name, version_aliases]) 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 = model_service.GetModelEvaluationRequest(request) + request = model_service.MergeVersionAliasesRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if name is not None: request.name = name + if version_aliases: + request.version_aliases.extend(version_aliases) # 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_model_evaluation, - default_timeout=5.0, + self._client._transport.merge_version_aliases, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -773,32 +1176,74 @@ async def get_model_evaluation( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response - async def list_model_evaluations( + async def export_model( self, - request: model_service.ListModelEvaluationsRequest = None, + request: Union[model_service.ExportModelRequest, dict] = None, *, - parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + name: str = None, + output_config: model_service.ExportModelRequest.OutputConfig = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListModelEvaluationsAsyncPager: - r"""Lists ModelEvaluations in a Model. + ) -> operation_async.AsyncOperation: + r"""Exports a trained, exportable Model to a location specified by + the user. A Model is considered to be exportable if it has at + least one [supported export + format][google.cloud.aiplatform.v1.Model.supported_export_formats]. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_export_model(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ExportModelRequest( + name="name_value", + ) + + # Make the request + operation = client.export_model(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) Args: - request (:class:`google.cloud.aiplatform_v1.types.ListModelEvaluationsRequest`): + request (Union[google.cloud.aiplatform_v1.types.ExportModelRequest, dict]): The request object. Request message for - [ModelService.ListModelEvaluations][google.cloud.aiplatform.v1.ModelService.ListModelEvaluations]. - parent (:class:`str`): - Required. The resource name of the Model to list the - ModelEvaluations from. Format: - ``projects/{project}/locations/{location}/models/{model}`` + [ModelService.ExportModel][google.cloud.aiplatform.v1.ModelService.ExportModel]. + name (:class:`str`): + Required. The resource name of the + Model to export. The resource name may + contain version id or version alias to + specify the version, if no version is + specified, the default version will be + exported. - This corresponds to the ``parent`` field + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + output_config (:class:`google.cloud.aiplatform_v1.types.ExportModelRequest.OutputConfig`): + Required. The desired output location + and configuration. + + This corresponds to the ``output_config`` 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, @@ -808,25 +1253,342 @@ async def list_model_evaluations( sent along with the request as metadata. Returns: - google.cloud.aiplatform_v1.services.model_service.pagers.ListModelEvaluationsAsyncPager: - Response message for - [ModelService.ListModelEvaluations][google.cloud.aiplatform.v1.ModelService.ListModelEvaluations]. + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. - Iterating over this object will yield results and - resolve additional pages automatically. + The result type for the operation will be + :class:`google.cloud.aiplatform_v1.types.ExportModelResponse` + Response message of + [ModelService.ExportModel][google.cloud.aiplatform.v1.ModelService.ExportModel] + operation. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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]) + has_flattened_params = any([name, output_config]) 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 = model_service.ListModelEvaluationsRequest(request) + request = model_service.ExportModelRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + if output_config is not None: + request.output_config = output_config + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.export_model, + default_timeout=None, + 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, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + model_service.ExportModelResponse, + metadata_type=model_service.ExportModelOperationMetadata, + ) + + # Done; return the response. + return response + + async def import_model_evaluation( + self, + request: Union[model_service.ImportModelEvaluationRequest, dict] = None, + *, + parent: str = None, + model_evaluation: gca_model_evaluation.ModelEvaluation = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_model_evaluation.ModelEvaluation: + r"""Imports an externally generated ModelEvaluation. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_import_model_evaluation(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ImportModelEvaluationRequest( + parent="parent_value", + ) + + # Make the request + response = await client.import_model_evaluation(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ImportModelEvaluationRequest, dict]): + The request object. Request message for + [ModelService.ImportModelEvaluation][google.cloud.aiplatform.v1.ModelService.ImportModelEvaluation] + parent (:class:`str`): + Required. The name of the parent model resource. Format: + ``projects/{project}/locations/{location}/models/{model}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + model_evaluation (:class:`google.cloud.aiplatform_v1.types.ModelEvaluation`): + Required. Model evaluation resource + to be imported. + + This corresponds to the ``model_evaluation`` 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: + google.cloud.aiplatform_v1.types.ModelEvaluation: + A collection of metrics calculated by + comparing Model's predictions on all of + the test data against annotations from + the test data. + + """ + # Create or coerce a protobuf request object. + # Quick 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, model_evaluation]) + 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 = model_service.ImportModelEvaluationRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if model_evaluation is not None: + request.model_evaluation = model_evaluation + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.import_model_evaluation, + default_timeout=None, + 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 get_model_evaluation( + self, + request: Union[model_service.GetModelEvaluationRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> model_evaluation.ModelEvaluation: + r"""Gets a ModelEvaluation. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_get_model_evaluation(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetModelEvaluationRequest( + name="name_value", + ) + + # Make the request + response = await client.get_model_evaluation(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetModelEvaluationRequest, dict]): + The request object. Request message for + [ModelService.GetModelEvaluation][google.cloud.aiplatform.v1.ModelService.GetModelEvaluation]. + name (:class:`str`): + Required. The name of the ModelEvaluation resource. + Format: + ``projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}`` + + 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: + google.cloud.aiplatform_v1.types.ModelEvaluation: + A collection of metrics calculated by + comparing Model's predictions on all of + the test data against annotations from + the test data. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = model_service.GetModelEvaluationRequest(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_model_evaluation, + default_timeout=None, + 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 list_model_evaluations( + self, + request: Union[model_service.ListModelEvaluationsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListModelEvaluationsAsyncPager: + r"""Lists ModelEvaluations in a Model. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_list_model_evaluations(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListModelEvaluationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_model_evaluations(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListModelEvaluationsRequest, dict]): + The request object. Request message for + [ModelService.ListModelEvaluations][google.cloud.aiplatform.v1.ModelService.ListModelEvaluations]. + parent (:class:`str`): + Required. The resource name of the Model to list the + ModelEvaluations from. Format: + ``projects/{project}/locations/{location}/models/{model}`` + + 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: + google.cloud.aiplatform_v1.services.model_service.pagers.ListModelEvaluationsAsyncPager: + Response message for + [ModelService.ListModelEvaluations][google.cloud.aiplatform.v1.ModelService.ListModelEvaluations]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = model_service.ListModelEvaluationsRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -837,7 +1599,7 @@ async def list_model_evaluations( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.list_model_evaluations, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -848,12 +1610,20 @@ async def list_model_evaluations( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListModelEvaluationsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -861,23 +1631,41 @@ async def list_model_evaluations( async def get_model_evaluation_slice( self, - request: model_service.GetModelEvaluationSliceRequest = None, + request: Union[model_service.GetModelEvaluationSliceRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> model_evaluation_slice.ModelEvaluationSlice: r"""Gets a ModelEvaluationSlice. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_get_model_evaluation_slice(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetModelEvaluationSliceRequest( + name="name_value", + ) + + # Make the request + response = await client.get_model_evaluation_slice(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.GetModelEvaluationSliceRequest`): + request (Union[google.cloud.aiplatform_v1.types.GetModelEvaluationSliceRequest, dict]): The request object. Request message for [ModelService.GetModelEvaluationSlice][google.cloud.aiplatform.v1.ModelService.GetModelEvaluationSlice]. name (:class:`str`): Required. The name of the ModelEvaluationSlice resource. Format: - ``projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}/slices/{slice}`` This corresponds to the ``name`` field @@ -898,7 +1686,7 @@ async def get_model_evaluation_slice( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -918,7 +1706,7 @@ async def get_model_evaluation_slice( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.get_model_evaluation_slice, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -929,30 +1717,54 @@ async def get_model_evaluation_slice( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_model_evaluation_slices( self, - request: model_service.ListModelEvaluationSlicesRequest = None, + request: Union[model_service.ListModelEvaluationSlicesRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListModelEvaluationSlicesAsyncPager: r"""Lists ModelEvaluationSlices in a ModelEvaluation. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_list_model_evaluation_slices(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListModelEvaluationSlicesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_model_evaluation_slices(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.ListModelEvaluationSlicesRequest`): + request (Union[google.cloud.aiplatform_v1.types.ListModelEvaluationSlicesRequest, dict]): The request object. Request message for [ModelService.ListModelEvaluationSlices][google.cloud.aiplatform.v1.ModelService.ListModelEvaluationSlices]. parent (:class:`str`): Required. The resource name of the ModelEvaluation to list the ModelEvaluationSlices from. Format: - ``projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}`` This corresponds to the ``parent`` field @@ -974,7 +1786,7 @@ async def list_model_evaluation_slices( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -994,7 +1806,7 @@ async def list_model_evaluation_slices( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.list_model_evaluation_slices, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -1005,17 +1817,702 @@ async def list_model_evaluation_slices( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListModelEvaluationSlicesAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. return response + async def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_operations, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.delete_operation, + default_timeout=None, + 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 cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + 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 wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.wait_operation, + default_timeout=None, + 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 set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_location, + default_timeout=None, + 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 list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_locations, + default_timeout=None, + 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 __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/aiplatform_v1/services/model_service/client.py b/google/cloud/aiplatform_v1/services/model_service/client.py index 6a1f353dbc..9250ad4cff 100644 --- a/google/cloud/aiplatform_v1/services/model_service/client.py +++ b/google/cloud/aiplatform_v1/services/model_service/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,33 +14,43 @@ # 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 +from typing import Dict, Mapping, 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 as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_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 +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation as gac_operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1.services.model_service import pagers from google.cloud.aiplatform_v1.types import deployed_model_ref from google.cloud.aiplatform_v1.types import encryption_spec +from google.cloud.aiplatform_v1.types import explanation from google.cloud.aiplatform_v1.types import model from google.cloud.aiplatform_v1.types import model as gca_model from google.cloud.aiplatform_v1.types import model_evaluation +from google.cloud.aiplatform_v1.types import model_evaluation as gca_model_evaluation from google.cloud.aiplatform_v1.types import model_evaluation_slice from google.cloud.aiplatform_v1.types import model_service from google.cloud.aiplatform_v1.types import operation as gca_operation +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import struct_pb2 # type: ignore @@ -62,8 +72,11 @@ class ModelServiceClientMeta(type): _transport_registry["grpc"] = ModelServiceGrpcTransport _transport_registry["grpc_asyncio"] = ModelServiceGrpcAsyncIOTransport - def get_transport_class(cls, label: str = None,) -> Type[ModelServiceTransport]: - """Return an appropriate transport class. + def get_transport_class( + cls, + label: str = None, + ) -> Type[ModelServiceTransport]: + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -82,11 +95,12 @@ def get_transport_class(cls, label: str = None,) -> Type[ModelServiceTransport]: class ModelServiceClient(metaclass=ModelServiceClientMeta): - """A service for managing AI Platform's machine learning Models.""" + """A service for managing Vertex AI's machine learning Models.""" @staticmethod def _get_default_mtls_endpoint(api_endpoint): - """Convert api endpoint to mTLS endpoint. + """Converts api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. Args: @@ -120,7 +134,8 @@ def _get_default_mtls_endpoint(api_endpoint): @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -137,7 +152,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -156,23 +171,30 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> ModelServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - ModelServiceTransport: The transport used by the client instance. + ModelServiceTransport: The transport used by the client + instance. """ return self._transport @staticmethod - def endpoint_path(project: str, location: str, endpoint: str,) -> str: - """Return a fully-qualified endpoint string.""" + def endpoint_path( + project: str, + location: str, + endpoint: str, + ) -> str: + """Returns a fully-qualified endpoint string.""" return "projects/{project}/locations/{location}/endpoints/{endpoint}".format( - project=project, location=location, endpoint=endpoint, + project=project, + location=location, + endpoint=endpoint, ) @staticmethod def parse_endpoint_path(path: str) -> Dict[str, str]: - """Parse a endpoint path into its component segments.""" + """Parses a endpoint path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/endpoints/(?P.+?)$", path, @@ -180,15 +202,21 @@ def parse_endpoint_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def model_path(project: str, location: str, model: str,) -> str: - """Return a fully-qualified model string.""" + def model_path( + project: str, + location: str, + model: str, + ) -> str: + """Returns a fully-qualified model string.""" return "projects/{project}/locations/{location}/models/{model}".format( - project=project, location=location, model=model, + project=project, + location=location, + model=model, ) @staticmethod def parse_model_path(path: str) -> Dict[str, str]: - """Parse a model path into its component segments.""" + """Parses a model path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/models/(?P.+?)$", path, @@ -197,16 +225,22 @@ def parse_model_path(path: str) -> Dict[str, str]: @staticmethod def model_evaluation_path( - project: str, location: str, model: str, evaluation: str, + project: str, + location: str, + model: str, + evaluation: str, ) -> str: - """Return a fully-qualified model_evaluation string.""" + """Returns a fully-qualified model_evaluation string.""" return "projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}".format( - project=project, location=location, model=model, evaluation=evaluation, + project=project, + location=location, + model=model, + evaluation=evaluation, ) @staticmethod def parse_model_evaluation_path(path: str) -> Dict[str, str]: - """Parse a model_evaluation path into its component segments.""" + """Parses a model_evaluation path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/models/(?P.+?)/evaluations/(?P.+?)$", path, @@ -215,9 +249,13 @@ def parse_model_evaluation_path(path: str) -> Dict[str, str]: @staticmethod def model_evaluation_slice_path( - project: str, location: str, model: str, evaluation: str, slice: str, + project: str, + location: str, + model: str, + evaluation: str, + slice: str, ) -> str: - """Return a fully-qualified model_evaluation_slice string.""" + """Returns a fully-qualified model_evaluation_slice string.""" return "projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}/slices/{slice}".format( project=project, location=location, @@ -228,7 +266,7 @@ def model_evaluation_slice_path( @staticmethod def parse_model_evaluation_slice_path(path: str) -> Dict[str, str]: - """Parse a model_evaluation_slice path into its component segments.""" + """Parses a model_evaluation_slice path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/models/(?P.+?)/evaluations/(?P.+?)/slices/(?P.+?)$", path, @@ -237,16 +275,20 @@ def parse_model_evaluation_slice_path(path: str) -> Dict[str, str]: @staticmethod def training_pipeline_path( - project: str, location: str, training_pipeline: str, + project: str, + location: str, + training_pipeline: str, ) -> str: - """Return a fully-qualified training_pipeline string.""" + """Returns a fully-qualified training_pipeline string.""" return "projects/{project}/locations/{location}/trainingPipelines/{training_pipeline}".format( - project=project, location=location, training_pipeline=training_pipeline, + project=project, + location=location, + training_pipeline=training_pipeline, ) @staticmethod def parse_training_pipeline_path(path: str) -> Dict[str, str]: - """Parse a training_pipeline path into its component segments.""" + """Parses a training_pipeline path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/trainingPipelines/(?P.+?)$", path, @@ -254,8 +296,10 @@ def parse_training_pipeline_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + def common_billing_account_path( + billing_account: str, + ) -> str: + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -267,9 +311,13 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: 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,) + def common_folder_path( + folder: str, + ) -> str: + """Returns a fully-qualified folder string.""" + return "folders/{folder}".format( + folder=folder, + ) @staticmethod def parse_common_folder_path(path: str) -> Dict[str, str]: @@ -278,9 +326,13 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: 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,) + def common_organization_path( + organization: str, + ) -> str: + """Returns a fully-qualified organization string.""" + return "organizations/{organization}".format( + organization=organization, + ) @staticmethod def parse_common_organization_path(path: str) -> Dict[str, str]: @@ -289,9 +341,13 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: 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,) + def common_project_path( + project: str, + ) -> str: + """Returns a fully-qualified project string.""" + return "projects/{project}".format( + project=project, + ) @staticmethod def parse_common_project_path(path: str) -> Dict[str, str]: @@ -300,10 +356,14 @@ def parse_common_project_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_location_path(project: str, location: str,) -> str: - """Return a fully-qualified location string.""" + def common_location_path( + project: str, + location: str, + ) -> str: + """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) @staticmethod @@ -312,6 +372,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + def __init__( self, *, @@ -320,7 +447,7 @@ def __init__( client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the model service client. + """Instantiates the model service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -362,58 +489,42 @@ def __init__( 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")) + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - client_cert_source_func = ( - mtls.default_client_cert_source() 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" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # 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, ModelServiceTransport): # transport is a ModelServiceTransport instance. - if credentials or client_options.credentials_file: + if credentials or client_options.credentials_file or api_key_value: 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." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + Transport = type(self).get_transport_class(transport) self._transport = Transport( credentials=credentials, @@ -423,22 +534,50 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, + always_use_jwt_access=True, ) def upload_model( self, - request: model_service.UploadModelRequest = None, + request: Union[model_service.UploadModelRequest, dict] = None, *, parent: str = None, model: gca_model.Model = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: - r"""Uploads a Model artifact into AI Platform. + r"""Uploads a Model artifact into Vertex AI. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_upload_model(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + model = aiplatform_v1.Model() + model.display_name = "display_name_value" + + request = aiplatform_v1.UploadModelRequest( + parent="parent_value", + model=model, + ) + + # Make the request + operation = client.upload_model(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) Args: - request (google.cloud.aiplatform_v1.types.UploadModelRequest): + request (Union[google.cloud.aiplatform_v1.types.UploadModelRequest, dict]): The request object. Request message for [ModelService.UploadModel][google.cloud.aiplatform.v1.ModelService.UploadModel]. parent (str): @@ -472,7 +611,7 @@ def upload_model( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, model]) if request is not None and has_flattened_params: @@ -505,7 +644,12 @@ def upload_model( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -520,23 +664,53 @@ def upload_model( def get_model( self, - request: model_service.GetModelRequest = None, + request: Union[model_service.GetModelRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> model.Model: r"""Gets a Model. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_get_model(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetModelRequest( + name="name_value", + ) + + # Make the request + response = client.get_model(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1.types.GetModelRequest): + request (Union[google.cloud.aiplatform_v1.types.GetModelRequest, dict]): The request object. Request message for [ModelService.GetModel][google.cloud.aiplatform.v1.ModelService.GetModel]. name (str): Required. The name of the Model resource. Format: ``projects/{project}/locations/{location}/models/{model}`` + In order to retrieve a specific version of the model, + also provide the version ID or version alias. Example: + ``projects/{project}/locations/{location}/models/{model}@2`` + or + ``projects/{project}/locations/{location}/models/{model}@golden`` + If no version ID or alias is specified, the "default" + version will be returned. The "default" version alias is + created for the first version of the model, and can be + moved to other versions later on. There will be exactly + one default version. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -551,7 +725,7 @@ def get_model( A trained machine learning Model. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -582,24 +756,49 @@ def get_model( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_models( self, - request: model_service.ListModelsRequest = None, + request: Union[model_service.ListModelsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListModelsPager: r"""Lists Models in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_list_models(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListModelsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_models(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1.types.ListModelsRequest): + request (Union[google.cloud.aiplatform_v1.types.ListModelsRequest, dict]): The request object. Request message for [ModelService.ListModels][google.cloud.aiplatform.v1.ModelService.ListModels]. parent (str): @@ -626,7 +825,7 @@ def list_models( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -657,12 +856,128 @@ def list_models( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListModelsPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_model_versions( + self, + request: Union[model_service.ListModelVersionsRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListModelVersionsPager: + r"""Lists versions of the specified model. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_list_model_versions(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListModelVersionsRequest( + name="name_value", + ) + + # Make the request + page_result = client.list_model_versions(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListModelVersionsRequest, dict]): + The request object. Request message for + [ModelService.ListModelVersions][google.cloud.aiplatform.v1.ModelService.ListModelVersions]. + name (str): + Required. The name of the model to + list versions for. + + 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: + google.cloud.aiplatform_v1.services.model_service.pagers.ListModelVersionsPager: + Response message for + [ModelService.ListModelVersions][google.cloud.aiplatform.v1.ModelService.ListModelVersions] + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 model_service.ListModelVersionsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, model_service.ListModelVersionsRequest): + request = model_service.ListModelVersionsRequest(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.list_model_versions] + + # 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, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__iter__` convenience method. + response = pagers.ListModelVersionsPager( + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -670,23 +985,66 @@ def list_models( def update_model( self, - request: model_service.UpdateModelRequest = None, + request: Union[model_service.UpdateModelRequest, dict] = None, *, model: gca_model.Model = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_model.Model: r"""Updates a Model. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_update_model(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + model = aiplatform_v1.Model() + model.display_name = "display_name_value" + + request = aiplatform_v1.UpdateModelRequest( + model=model, + ) + + # Make the request + response = client.update_model(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1.types.UpdateModelRequest): + request (Union[google.cloud.aiplatform_v1.types.UpdateModelRequest, dict]): The request object. Request message for [ModelService.UpdateModel][google.cloud.aiplatform.v1.ModelService.UpdateModel]. model (google.cloud.aiplatform_v1.types.Model): - Required. The Model which replaces - the resource on the server. + Required. The Model which replaces the resource on the + server. When Model Versioning is enabled, the model.name + will be used to determine whether to update the model or + model version. + + 1. model.name with the @ value, e.g. models/123@1, + refers to a version specific update. + 2. model.name without the @ value, e.g. models/123, + refers to a model update. + 3. model.name with @-, e.g. models/123@-, refers to a + model update. + 4. Supported model fields: display_name, description; + supported version-specific fields: + version_description. Labels are supported in both + scenarios. Both the model labels and the version + labels are merged when a model is returned. When + updating labels, if the request is for model-specific + update, model label gets updated. Otherwise, version + labels get updated. + 5. A model name or model version name fields update + mismatch will cause a precondition error. + 6. One request cannot update both the model and the + version fields. You must update them separately. This corresponds to the ``model`` field on the ``request`` instance; if ``request`` is provided, this @@ -694,7 +1052,7 @@ def update_model( update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. The update mask applies to the resource. For the ``FieldMask`` definition, see - `FieldMask `__. + [google.protobuf.FieldMask][google.protobuf.FieldMask]. This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this @@ -710,7 +1068,7 @@ def update_model( A trained machine learning Model. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([model, update_mask]) if request is not None and has_flattened_params: @@ -745,26 +1103,59 @@ def update_model( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def delete_model( self, - request: model_service.DeleteModelRequest = None, + request: Union[model_service.DeleteModelRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Deletes a Model. - Note: Model can only be deleted if there are no - DeployedModels created from it. + + A model cannot be deleted if any + [Endpoint][google.cloud.aiplatform.v1.Endpoint] resource has a + [DeployedModel][google.cloud.aiplatform.v1.DeployedModel] based + on the model in its + [deployed_models][google.cloud.aiplatform.v1.Endpoint.deployed_models] + field. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_delete_model(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteModelRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_model(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) Args: - request (google.cloud.aiplatform_v1.types.DeleteModelRequest): + request (Union[google.cloud.aiplatform_v1.types.DeleteModelRequest, dict]): The request object. Request message for [ModelService.DeleteModel][google.cloud.aiplatform.v1.ModelService.DeleteModel]. name (str): @@ -801,7 +1192,7 @@ def delete_model( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -832,7 +1223,12 @@ def delete_model( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -845,38 +1241,58 @@ def delete_model( # Done; return the response. return response - def export_model( + def delete_model_version( self, - request: model_service.ExportModelRequest = None, + request: Union[model_service.DeleteModelVersionRequest, dict] = None, *, name: str = None, - output_config: model_service.ExportModelRequest.OutputConfig = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: - r"""Exports a trained, exportable, Model to a location specified by - the user. A Model is considered to be exportable if it has at - least one [supported export - format][google.cloud.aiplatform.v1.Model.supported_export_formats]. + r"""Deletes a Model version. + + Model version can only be deleted if there are no + [DeployedModels][] created from it. Deleting the only version in + the Model is not allowed. Use + [DeleteModel][google.cloud.aiplatform.v1.ModelService.DeleteModel] + for deleting the Model instead. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_delete_model_version(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteModelVersionRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_model_version(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) Args: - request (google.cloud.aiplatform_v1.types.ExportModelRequest): + request (Union[google.cloud.aiplatform_v1.types.DeleteModelVersionRequest, dict]): The request object. Request message for - [ModelService.ExportModel][google.cloud.aiplatform.v1.ModelService.ExportModel]. + [ModelService.DeleteModelVersion][google.cloud.aiplatform.v1.ModelService.DeleteModelVersion]. name (str): - Required. The resource name of the Model to export. - Format: - ``projects/{project}/locations/{location}/models/{model}`` + Required. The name of the model version to be deleted, + with a version ID explicitly included. - This corresponds to the ``name`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - output_config (google.cloud.aiplatform_v1.types.ExportModelRequest.OutputConfig): - Required. The desired output location - and configuration. + Example: + ``projects/{project}/locations/{location}/models/{model}@1234`` - This corresponds to the ``output_config`` field + 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, @@ -889,17 +1305,25 @@ def export_model( google.api_core.operation.Operation: An object representing a long-running operation. - The result type for the operation will be - :class:`google.cloud.aiplatform_v1.types.ExportModelResponse` - Response message of - [ModelService.ExportModel][google.cloud.aiplatform.v1.ModelService.ExportModel] - operation. + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, output_config]) + 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 " @@ -907,21 +1331,19 @@ def export_model( ) # Minor optimization to avoid making a copy if the user passes - # in a model_service.ExportModelRequest. + # in a model_service.DeleteModelVersionRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. - if not isinstance(request, model_service.ExportModelRequest): - request = model_service.ExportModelRequest(request) + if not isinstance(request, model_service.DeleteModelVersionRequest): + request = model_service.DeleteModelVersionRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if name is not None: request.name = name - if output_config is not None: - request.output_config = output_config # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.export_model] + rpc = self._transport._wrapped_methods[self._transport.delete_model_version] # Certain fields should be provided within the metadata header; # add these here. @@ -930,61 +1352,225 @@ def export_model( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( response, self._transport.operations_client, - model_service.ExportModelResponse, - metadata_type=model_service.ExportModelOperationMetadata, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, ) # Done; return the response. return response - def get_model_evaluation( + def merge_version_aliases( self, - request: model_service.GetModelEvaluationRequest = None, + request: Union[model_service.MergeVersionAliasesRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + version_aliases: Sequence[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> model_evaluation.ModelEvaluation: - r"""Gets a ModelEvaluation. + ) -> model.Model: + r"""Merges a set of aliases for a Model version. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_merge_version_aliases(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.MergeVersionAliasesRequest( + name="name_value", + version_aliases=['version_aliases_value_1', 'version_aliases_value_2'], + ) + + # Make the request + response = client.merge_version_aliases(request=request) + + # Handle the response + print(response) Args: - request (google.cloud.aiplatform_v1.types.GetModelEvaluationRequest): + request (Union[google.cloud.aiplatform_v1.types.MergeVersionAliasesRequest, dict]): The request object. Request message for - [ModelService.GetModelEvaluation][google.cloud.aiplatform.v1.ModelService.GetModelEvaluation]. + [ModelService.MergeVersionAliases][google.cloud.aiplatform.v1.ModelService.MergeVersionAliases]. name (str): - Required. The name of the ModelEvaluation resource. - Format: + Required. The name of the model version to merge + aliases, with a version ID explicitly included. - ``projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}`` + Example: + ``projects/{project}/locations/{location}/models/{model}@1234`` 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, + version_aliases (Sequence[str]): + Required. The set of version aliases to merge. The alias + should be at most 128 characters, and match + ``[a-z][a-z0-9-]{0,126}[a-z-0-9]``. Add the ``-`` prefix + to an alias means removing that alias from the version. + ``-`` is NOT counted in the 128 characters. Example: + ``-golden`` means removing the ``golden`` alias from the + version. + + There is NO ordering in aliases, which means + + 1) The aliases returned from GetModel API might not have + the exactly same order from this MergeVersionAliases + API. 2) Adding and deleting the same alias in the + request is not recommended, and the 2 operations will + be cancelled out. + + This corresponds to the ``version_aliases`` 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: - google.cloud.aiplatform_v1.types.ModelEvaluation: - A collection of metrics calculated by - comparing Model's predictions on all of - the test data against annotations from - the test data. + google.cloud.aiplatform_v1.types.Model: + A trained machine learning Model. + """ + # Create or coerce a protobuf request object. + # Quick 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, version_aliases]) + 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 model_service.MergeVersionAliasesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, model_service.MergeVersionAliasesRequest): + request = model_service.MergeVersionAliasesRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if name is not None: + request.name = name + if version_aliases is not None: + request.version_aliases = version_aliases + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.merge_version_aliases] + + # 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 export_model( + self, + request: Union[model_service.ExportModelRequest, dict] = None, + *, + name: str = None, + output_config: model_service.ExportModelRequest.OutputConfig = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Exports a trained, exportable Model to a location specified by + the user. A Model is considered to be exportable if it has at + least one [supported export + format][google.cloud.aiplatform.v1.Model.supported_export_formats]. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_export_model(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ExportModelRequest( + name="name_value", + ) + + # Make the request + operation = client.export_model(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ExportModelRequest, dict]): + The request object. Request message for + [ModelService.ExportModel][google.cloud.aiplatform.v1.ModelService.ExportModel]. + name (str): + Required. The resource name of the + Model to export. The resource name may + contain version id or version alias to + specify the version, if no version is + specified, the default version will be + exported. + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + output_config (google.cloud.aiplatform_v1.types.ExportModelRequest.OutputConfig): + Required. The desired output location + and configuration. + + This corresponds to the ``output_config`` 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.aiplatform_v1.types.ExportModelResponse` + Response message of + [ModelService.ExportModel][google.cloud.aiplatform.v1.ModelService.ExportModel] + operation. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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]) + has_flattened_params = any([name, output_config]) if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " @@ -992,19 +1578,21 @@ def get_model_evaluation( ) # Minor optimization to avoid making a copy if the user passes - # in a model_service.GetModelEvaluationRequest. + # in a model_service.ExportModelRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. - if not isinstance(request, model_service.GetModelEvaluationRequest): - request = model_service.GetModelEvaluationRequest(request) + if not isinstance(request, model_service.ExportModelRequest): + request = model_service.ExportModelRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if name is not None: request.name = name + if output_config is not None: + request.output_config = output_config # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.get_model_evaluation] + rpc = self._transport._wrapped_methods[self._transport.export_model] # Certain fields should be provided within the metadata header; # add these here. @@ -1013,34 +1601,73 @@ def get_model_evaluation( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + model_service.ExportModelResponse, + metadata_type=model_service.ExportModelOperationMetadata, + ) # Done; return the response. return response - def list_model_evaluations( + def import_model_evaluation( self, - request: model_service.ListModelEvaluationsRequest = None, + request: Union[model_service.ImportModelEvaluationRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + model_evaluation: gca_model_evaluation.ModelEvaluation = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListModelEvaluationsPager: - r"""Lists ModelEvaluations in a Model. + ) -> gca_model_evaluation.ModelEvaluation: + r"""Imports an externally generated ModelEvaluation. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_import_model_evaluation(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ImportModelEvaluationRequest( + parent="parent_value", + ) + + # Make the request + response = client.import_model_evaluation(request=request) + + # Handle the response + print(response) Args: - request (google.cloud.aiplatform_v1.types.ListModelEvaluationsRequest): + request (Union[google.cloud.aiplatform_v1.types.ImportModelEvaluationRequest, dict]): The request object. Request message for - [ModelService.ListModelEvaluations][google.cloud.aiplatform.v1.ModelService.ListModelEvaluations]. + [ModelService.ImportModelEvaluation][google.cloud.aiplatform.v1.ModelService.ImportModelEvaluation] parent (str): - Required. The resource name of the Model to list the - ModelEvaluations from. Format: + Required. The name of the parent model resource. Format: ``projects/{project}/locations/{location}/models/{model}`` This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. + model_evaluation (google.cloud.aiplatform_v1.types.ModelEvaluation): + Required. Model evaluation resource + to be imported. + + This corresponds to the ``model_evaluation`` 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. @@ -1048,18 +1675,17 @@ def list_model_evaluations( sent along with the request as metadata. Returns: - google.cloud.aiplatform_v1.services.model_service.pagers.ListModelEvaluationsPager: - Response message for - [ModelService.ListModelEvaluations][google.cloud.aiplatform.v1.ModelService.ListModelEvaluations]. - - Iterating over this object will yield results and - resolve additional pages automatically. + google.cloud.aiplatform_v1.types.ModelEvaluation: + A collection of metrics calculated by + comparing Model's predictions on all of + the test data against annotations from + the test data. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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]) + has_flattened_params = any([parent, model_evaluation]) if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " @@ -1067,19 +1693,21 @@ def list_model_evaluations( ) # Minor optimization to avoid making a copy if the user passes - # in a model_service.ListModelEvaluationsRequest. + # in a model_service.ImportModelEvaluationRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. - if not isinstance(request, model_service.ListModelEvaluationsRequest): - request = model_service.ListModelEvaluationsRequest(request) + if not isinstance(request, model_service.ImportModelEvaluationRequest): + request = model_service.ImportModelEvaluationRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if parent is not None: request.parent = parent + if model_evaluation is not None: + request.model_evaluation = model_evaluation # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.list_model_evaluations] + rpc = self._transport._wrapped_methods[self._transport.import_model_evaluation] # Certain fields should be provided within the metadata header; # add these here. @@ -1088,37 +1716,54 @@ def list_model_evaluations( ) # 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.ListModelEvaluationsPager( - method=rpc, request=request, response=response, metadata=metadata, + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) # Done; return the response. return response - def get_model_evaluation_slice( + def get_model_evaluation( self, - request: model_service.GetModelEvaluationSliceRequest = None, + request: Union[model_service.GetModelEvaluationRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> model_evaluation_slice.ModelEvaluationSlice: - r"""Gets a ModelEvaluationSlice. + ) -> model_evaluation.ModelEvaluation: + r"""Gets a ModelEvaluation. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_get_model_evaluation(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetModelEvaluationRequest( + name="name_value", + ) + + # Make the request + response = client.get_model_evaluation(request=request) + + # Handle the response + print(response) Args: - request (google.cloud.aiplatform_v1.types.GetModelEvaluationSliceRequest): + request (Union[google.cloud.aiplatform_v1.types.GetModelEvaluationRequest, dict]): The request object. Request message for - [ModelService.GetModelEvaluationSlice][google.cloud.aiplatform.v1.ModelService.GetModelEvaluationSlice]. + [ModelService.GetModelEvaluation][google.cloud.aiplatform.v1.ModelService.GetModelEvaluation]. name (str): - Required. The name of the ModelEvaluationSlice resource. + Required. The name of the ModelEvaluation resource. Format: - - ``projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}/slices/{slice}`` + ``projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}`` This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -1130,15 +1775,15 @@ def get_model_evaluation_slice( sent along with the request as metadata. Returns: - google.cloud.aiplatform_v1.types.ModelEvaluationSlice: + google.cloud.aiplatform_v1.types.ModelEvaluation: A collection of metrics calculated by - comparing Model's predictions on a slice - of the test data against ground truth - annotations. + comparing Model's predictions on all of + the test data against annotations from + the test data. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1148,11 +1793,11 @@ def get_model_evaluation_slice( ) # Minor optimization to avoid making a copy if the user passes - # in a model_service.GetModelEvaluationSliceRequest. + # in a model_service.GetModelEvaluationRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. - if not isinstance(request, model_service.GetModelEvaluationSliceRequest): - request = model_service.GetModelEvaluationSliceRequest(request) + if not isinstance(request, model_service.GetModelEvaluationRequest): + request = model_service.GetModelEvaluationRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if name is not None: @@ -1160,9 +1805,7 @@ def get_model_evaluation_slice( # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = self._transport._wrapped_methods[ - self._transport.get_model_evaluation_slice - ] + rpc = self._transport._wrapped_methods[self._transport.get_model_evaluation] # Certain fields should be provided within the metadata header; # add these here. @@ -1171,31 +1814,55 @@ def get_model_evaluation_slice( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response - def list_model_evaluation_slices( + def list_model_evaluations( self, - request: model_service.ListModelEvaluationSlicesRequest = None, + request: Union[model_service.ListModelEvaluationsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListModelEvaluationSlicesPager: - r"""Lists ModelEvaluationSlices in a ModelEvaluation. + ) -> pagers.ListModelEvaluationsPager: + r"""Lists ModelEvaluations in a Model. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_list_model_evaluations(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListModelEvaluationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_model_evaluations(request=request) + + # Handle the response + for response in page_result: + print(response) Args: - request (google.cloud.aiplatform_v1.types.ListModelEvaluationSlicesRequest): + request (Union[google.cloud.aiplatform_v1.types.ListModelEvaluationsRequest, dict]): The request object. Request message for - [ModelService.ListModelEvaluationSlices][google.cloud.aiplatform.v1.ModelService.ListModelEvaluationSlices]. + [ModelService.ListModelEvaluations][google.cloud.aiplatform.v1.ModelService.ListModelEvaluations]. parent (str): - Required. The resource name of the ModelEvaluation to - list the ModelEvaluationSlices from. Format: - - ``projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}`` + Required. The resource name of the Model to list the + ModelEvaluations from. Format: + ``projects/{project}/locations/{location}/models/{model}`` This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -1207,16 +1874,16 @@ def list_model_evaluation_slices( sent along with the request as metadata. Returns: - google.cloud.aiplatform_v1.services.model_service.pagers.ListModelEvaluationSlicesPager: + google.cloud.aiplatform_v1.services.model_service.pagers.ListModelEvaluationsPager: Response message for - [ModelService.ListModelEvaluationSlices][google.cloud.aiplatform.v1.ModelService.ListModelEvaluationSlices]. + [ModelService.ListModelEvaluations][google.cloud.aiplatform.v1.ModelService.ListModelEvaluations]. 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 + # Quick 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: @@ -1226,11 +1893,11 @@ def list_model_evaluation_slices( ) # Minor optimization to avoid making a copy if the user passes - # in a model_service.ListModelEvaluationSlicesRequest. + # in a model_service.ListModelEvaluationsRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. - if not isinstance(request, model_service.ListModelEvaluationSlicesRequest): - request = model_service.ListModelEvaluationSlicesRequest(request) + if not isinstance(request, model_service.ListModelEvaluationsRequest): + request = model_service.ListModelEvaluationsRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if parent is not None: @@ -1238,9 +1905,7 @@ def list_model_evaluation_slices( # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = self._transport._wrapped_methods[ - self._transport.list_model_evaluation_slices - ] + rpc = self._transport._wrapped_methods[self._transport.list_model_evaluations] # Certain fields should be provided within the metadata header; # add these here. @@ -1249,12 +1914,915 @@ def list_model_evaluation_slices( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListModelEvaluationSlicesPager( - method=rpc, request=request, response=response, metadata=metadata, + response = pagers.ListModelEvaluationsPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_model_evaluation_slice( + self, + request: Union[model_service.GetModelEvaluationSliceRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> model_evaluation_slice.ModelEvaluationSlice: + r"""Gets a ModelEvaluationSlice. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_get_model_evaluation_slice(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetModelEvaluationSliceRequest( + name="name_value", + ) + + # Make the request + response = client.get_model_evaluation_slice(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetModelEvaluationSliceRequest, dict]): + The request object. Request message for + [ModelService.GetModelEvaluationSlice][google.cloud.aiplatform.v1.ModelService.GetModelEvaluationSlice]. + name (str): + Required. The name of the ModelEvaluationSlice resource. + Format: + ``projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}/slices/{slice}`` + + 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: + google.cloud.aiplatform_v1.types.ModelEvaluationSlice: + A collection of metrics calculated by + comparing Model's predictions on a slice + of the test data against ground truth + annotations. + + """ + # Create or coerce a protobuf request object. + # Quick 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 model_service.GetModelEvaluationSliceRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, model_service.GetModelEvaluationSliceRequest): + request = model_service.GetModelEvaluationSliceRequest(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_model_evaluation_slice + ] + + # 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 list_model_evaluation_slices( + self, + request: Union[model_service.ListModelEvaluationSlicesRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListModelEvaluationSlicesPager: + r"""Lists ModelEvaluationSlices in a ModelEvaluation. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_list_model_evaluation_slices(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListModelEvaluationSlicesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_model_evaluation_slices(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListModelEvaluationSlicesRequest, dict]): + The request object. Request message for + [ModelService.ListModelEvaluationSlices][google.cloud.aiplatform.v1.ModelService.ListModelEvaluationSlices]. + parent (str): + Required. The resource name of the ModelEvaluation to + list the ModelEvaluationSlices from. Format: + ``projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}`` + + 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: + google.cloud.aiplatform_v1.services.model_service.pagers.ListModelEvaluationSlicesPager: + Response message for + [ModelService.ListModelEvaluationSlices][google.cloud.aiplatform.v1.ModelService.ListModelEvaluationSlices]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 model_service.ListModelEvaluationSlicesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, model_service.ListModelEvaluationSlicesRequest): + request = model_service.ListModelEvaluationSlicesRequest(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_model_evaluation_slices + ] + + # 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.ListModelEvaluationSlicesPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_operations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.delete_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.wait_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_location, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_locations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) # Done; return the response. diff --git a/google/cloud/aiplatform_v1/services/model_service/pagers.py b/google/cloud/aiplatform_v1/services/model_service/pagers.py index b178c162d2..5a4abf8b07 100644 --- a/google/cloud/aiplatform_v1/services/model_service/pagers.py +++ b/google/cloud/aiplatform_v1/services/model_service/pagers.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,13 +15,13 @@ # from typing import ( Any, - AsyncIterable, + AsyncIterator, Awaitable, Callable, - Iterable, Sequence, Tuple, Optional, + Iterator, ) from google.cloud.aiplatform_v1.types import model @@ -77,14 +77,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[model_service.ListModelsResponse]: + def pages(self) -> Iterator[model_service.ListModelsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[model.Model]: + def __iter__(self) -> Iterator[model.Model]: for page in self.pages: yield from page.models @@ -118,7 +118,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -139,14 +139,142 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - async def pages(self) -> AsyncIterable[model_service.ListModelsResponse]: + async def pages(self) -> AsyncIterator[model_service.ListModelsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + + def __aiter__(self) -> AsyncIterator[model.Model]: + async def async_generator(): + async for page in self.pages: + for response in page.models: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListModelVersionsPager: + """A pager for iterating through ``list_model_versions`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListModelVersionsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``models`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListModelVersions`` requests and continue to iterate + through the ``models`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListModelVersionsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., model_service.ListModelVersionsResponse], + request: model_service.ListModelVersionsRequest, + response: model_service.ListModelVersionsResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListModelVersionsRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListModelVersionsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = model_service.ListModelVersionsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[model_service.ListModelVersionsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterator[model.Model]: + for page in self.pages: + yield from page.models + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListModelVersionsAsyncPager: + """A pager for iterating through ``list_model_versions`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListModelVersionsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``models`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListModelVersions`` requests and continue to iterate + through the ``models`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListModelVersionsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., Awaitable[model_service.ListModelVersionsResponse]], + request: model_service.ListModelVersionsRequest, + response: model_service.ListModelVersionsResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListModelVersionsRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListModelVersionsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = model_service.ListModelVersionsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[model_service.ListModelVersionsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[model.Model]: + def __aiter__(self) -> AsyncIterator[model.Model]: async def async_generator(): async for page in self.pages: for response in page.models: @@ -205,14 +333,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[model_service.ListModelEvaluationsResponse]: + def pages(self) -> Iterator[model_service.ListModelEvaluationsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[model_evaluation.ModelEvaluation]: + def __iter__(self) -> Iterator[model_evaluation.ModelEvaluation]: for page in self.pages: yield from page.model_evaluations @@ -246,7 +374,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -267,14 +395,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - async def pages(self) -> AsyncIterable[model_service.ListModelEvaluationsResponse]: + async def pages(self) -> AsyncIterator[model_service.ListModelEvaluationsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[model_evaluation.ModelEvaluation]: + def __aiter__(self) -> AsyncIterator[model_evaluation.ModelEvaluation]: async def async_generator(): async for page in self.pages: for response in page.model_evaluations: @@ -333,14 +461,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[model_service.ListModelEvaluationSlicesResponse]: + def pages(self) -> Iterator[model_service.ListModelEvaluationSlicesResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[model_evaluation_slice.ModelEvaluationSlice]: + def __iter__(self) -> Iterator[model_evaluation_slice.ModelEvaluationSlice]: for page in self.pages: yield from page.model_evaluation_slices @@ -376,7 +504,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -399,14 +527,14 @@ def __getattr__(self, name: str) -> Any: @property async def pages( self, - ) -> AsyncIterable[model_service.ListModelEvaluationSlicesResponse]: + ) -> AsyncIterator[model_service.ListModelEvaluationSlicesResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[model_evaluation_slice.ModelEvaluationSlice]: + def __aiter__(self) -> AsyncIterator[model_evaluation_slice.ModelEvaluationSlice]: async def async_generator(): async for page in self.pages: for response in page.model_evaluation_slices: diff --git a/google/cloud/aiplatform_v1/services/model_service/transports/__init__.py b/google/cloud/aiplatform_v1/services/model_service/transports/__init__.py index 656b644033..ab55f592b6 100644 --- a/google/cloud/aiplatform_v1/services/model_service/transports/__init__.py +++ b/google/cloud/aiplatform_v1/services/model_service/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1/services/model_service/transports/base.py b/google/cloud/aiplatform_v1/services/model_service/transports/base.py index 70481a015a..63d3f337a4 100644 --- a/google/cloud/aiplatform_v1/services/model_service/transports/base.py +++ b/google/cloud/aiplatform_v1/services/model_service/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,22 +15,27 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.api_core import operations_v1 # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.aiplatform_v1.types import model from google.cloud.aiplatform_v1.types import model as gca_model from google.cloud.aiplatform_v1.types import model_evaluation +from google.cloud.aiplatform_v1.types import model_evaluation as gca_model_evaluation from google.cloud.aiplatform_v1.types import model_evaluation_slice from google.cloud.aiplatform_v1.types import model_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore try: @@ -42,17 +47,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - -_API_CORE_VERSION = google.api_core.__version__ - class ModelServiceTransport(abc.ABC): """Abstract transport class for ModelService.""" @@ -70,6 +64,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -93,16 +88,19 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -115,103 +113,108 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id ) - # Save the credentials. - self._credentials = credentials - - # TODO(busunkim): These two class methods are in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-api-core - # and google-auth are increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") - ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs - - # TODO: Remove this function once google-api-core >= 1.26.0 is required - @classmethod - def _get_self_signed_jwt_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Union[Optional[Sequence[str]], str]]: - """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" - - self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} - - if _API_CORE_VERSION and ( - packaging.version.parse(_API_CORE_VERSION) - >= packaging.version.parse("1.26.0") + # If the credentials are service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") ): - self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES - self_signed_jwt_kwargs["scopes"] = scopes - self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST - else: - self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES + credentials = credentials.with_always_use_jwt_access(True) - return self_signed_jwt_kwargs + # Save the credentials. + self._credentials = credentials def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { self.upload_model: gapic_v1.method.wrap_method( - self.upload_model, default_timeout=5.0, client_info=client_info, + self.upload_model, + default_timeout=None, + client_info=client_info, ), self.get_model: gapic_v1.method.wrap_method( - self.get_model, default_timeout=5.0, client_info=client_info, + self.get_model, + default_timeout=None, + client_info=client_info, ), self.list_models: gapic_v1.method.wrap_method( - self.list_models, default_timeout=5.0, client_info=client_info, + self.list_models, + default_timeout=None, + client_info=client_info, + ), + self.list_model_versions: gapic_v1.method.wrap_method( + self.list_model_versions, + default_timeout=None, + client_info=client_info, ), self.update_model: gapic_v1.method.wrap_method( - self.update_model, default_timeout=5.0, client_info=client_info, + self.update_model, + default_timeout=None, + client_info=client_info, ), self.delete_model: gapic_v1.method.wrap_method( - self.delete_model, default_timeout=5.0, client_info=client_info, + self.delete_model, + default_timeout=None, + client_info=client_info, + ), + self.delete_model_version: gapic_v1.method.wrap_method( + self.delete_model_version, + default_timeout=None, + client_info=client_info, + ), + self.merge_version_aliases: gapic_v1.method.wrap_method( + self.merge_version_aliases, + default_timeout=None, + client_info=client_info, ), self.export_model: gapic_v1.method.wrap_method( - self.export_model, default_timeout=5.0, client_info=client_info, + self.export_model, + default_timeout=None, + client_info=client_info, + ), + self.import_model_evaluation: gapic_v1.method.wrap_method( + self.import_model_evaluation, + default_timeout=None, + client_info=client_info, ), self.get_model_evaluation: gapic_v1.method.wrap_method( - self.get_model_evaluation, default_timeout=5.0, client_info=client_info, + self.get_model_evaluation, + default_timeout=None, + client_info=client_info, ), self.list_model_evaluations: gapic_v1.method.wrap_method( self.list_model_evaluations, - default_timeout=5.0, + default_timeout=None, client_info=client_info, ), self.get_model_evaluation_slice: gapic_v1.method.wrap_method( self.get_model_evaluation_slice, - default_timeout=5.0, + default_timeout=None, client_info=client_info, ), self.list_model_evaluation_slices: gapic_v1.method.wrap_method( self.list_model_evaluation_slices, - default_timeout=5.0, + default_timeout=None, client_info=client_info, ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() @@ -244,6 +247,18 @@ def list_models( ]: raise NotImplementedError() + @property + def list_model_versions( + self, + ) -> Callable[ + [model_service.ListModelVersionsRequest], + Union[ + model_service.ListModelVersionsResponse, + Awaitable[model_service.ListModelVersionsResponse], + ], + ]: + raise NotImplementedError() + @property def update_model( self, @@ -262,6 +277,24 @@ def delete_model( ]: raise NotImplementedError() + @property + def delete_model_version( + self, + ) -> Callable[ + [model_service.DeleteModelVersionRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def merge_version_aliases( + self, + ) -> Callable[ + [model_service.MergeVersionAliasesRequest], + Union[model.Model, Awaitable[model.Model]], + ]: + raise NotImplementedError() + @property def export_model( self, @@ -271,6 +304,18 @@ def export_model( ]: raise NotImplementedError() + @property + def import_model_evaluation( + self, + ) -> Callable[ + [model_service.ImportModelEvaluationRequest], + Union[ + gca_model_evaluation.ModelEvaluation, + Awaitable[gca_model_evaluation.ModelEvaluation], + ], + ]: + raise NotImplementedError() + @property def get_model_evaluation( self, @@ -319,5 +364,102 @@ def list_model_evaluation_slices( ]: raise NotImplementedError() + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], + Union[ + operations_pb2.ListOperationsResponse, + Awaitable[operations_pb2.ListOperationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None,]: + raise NotImplementedError() + + @property + def wait_operation( + self, + ) -> Callable[ + [operations_pb2.WaitOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def set_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def get_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_location( + self, + ) -> Callable[ + [locations_pb2.GetLocationRequest], + Union[locations_pb2.Location, Awaitable[locations_pb2.Location]], + ]: + raise NotImplementedError() + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], + Union[ + locations_pb2.ListLocationsResponse, + Awaitable[locations_pb2.ListLocationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + __all__ = ("ModelServiceTransport",) diff --git a/google/cloud/aiplatform_v1/services/model_service/transports/grpc.py b/google/cloud/aiplatform_v1/services/model_service/transports/grpc.py index 91479bd3ae..6118ec8fcf 100644 --- a/google/cloud/aiplatform_v1/services/model_service/transports/grpc.py +++ b/google/cloud/aiplatform_v1/services/model_service/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,9 +16,9 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import operations_v1 +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -28,8 +28,13 @@ from google.cloud.aiplatform_v1.types import model from google.cloud.aiplatform_v1.types import model as gca_model from google.cloud.aiplatform_v1.types import model_evaluation +from google.cloud.aiplatform_v1.types import model_evaluation as gca_model_evaluation from google.cloud.aiplatform_v1.types import model_evaluation_slice from google.cloud.aiplatform_v1.types import model_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from .base import ModelServiceTransport, DEFAULT_CLIENT_INFO @@ -37,7 +42,7 @@ class ModelServiceGrpcTransport(ModelServiceTransport): """gRPC backend transport for ModelService. - A service for managing AI Platform's machine learning Models. + A service for managing Vertex AI's machine learning Models. This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation @@ -63,6 +68,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,16 +91,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -103,6 +109,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport @@ -113,7 +121,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -156,13 +164,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -211,21 +223,20 @@ def create_channel( and ``credentials_file`` are passed. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @property def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ + """Return the channel designed to connect to this service.""" return self._grpc_channel @property @@ -235,7 +246,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsClient(self.grpc_channel) @@ -248,7 +259,7 @@ def upload_model( ) -> Callable[[model_service.UploadModelRequest], operations_pb2.Operation]: r"""Return a callable for the upload model method over gRPC. - Uploads a Model artifact into AI Platform. + Uploads a Model artifact into Vertex AI. Returns: Callable[[~.UploadModelRequest], @@ -318,6 +329,35 @@ def list_models( ) return self._stubs["list_models"] + @property + def list_model_versions( + self, + ) -> Callable[ + [model_service.ListModelVersionsRequest], + model_service.ListModelVersionsResponse, + ]: + r"""Return a callable for the list model versions method over gRPC. + + Lists versions of the specified model. + + Returns: + Callable[[~.ListModelVersionsRequest], + ~.ListModelVersionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_model_versions" not in self._stubs: + self._stubs["list_model_versions"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.ModelService/ListModelVersions", + request_serializer=model_service.ListModelVersionsRequest.serialize, + response_deserializer=model_service.ListModelVersionsResponse.deserialize, + ) + return self._stubs["list_model_versions"] + @property def update_model( self, @@ -351,8 +391,13 @@ def delete_model( r"""Return a callable for the delete model method over gRPC. Deletes a Model. - Note: Model can only be deleted if there are no - DeployedModels created from it. + + A model cannot be deleted if any + [Endpoint][google.cloud.aiplatform.v1.Endpoint] resource has a + [DeployedModel][google.cloud.aiplatform.v1.DeployedModel] based + on the model in its + [deployed_models][google.cloud.aiplatform.v1.Endpoint.deployed_models] + field. Returns: Callable[[~.DeleteModelRequest], @@ -372,13 +417,71 @@ def delete_model( ) return self._stubs["delete_model"] + @property + def delete_model_version( + self, + ) -> Callable[[model_service.DeleteModelVersionRequest], operations_pb2.Operation]: + r"""Return a callable for the delete model version method over gRPC. + + Deletes a Model version. + + Model version can only be deleted if there are no + [DeployedModels][] created from it. Deleting the only version in + the Model is not allowed. Use + [DeleteModel][google.cloud.aiplatform.v1.ModelService.DeleteModel] + for deleting the Model instead. + + Returns: + Callable[[~.DeleteModelVersionRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_model_version" not in self._stubs: + self._stubs["delete_model_version"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.ModelService/DeleteModelVersion", + request_serializer=model_service.DeleteModelVersionRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_model_version"] + + @property + def merge_version_aliases( + self, + ) -> Callable[[model_service.MergeVersionAliasesRequest], model.Model]: + r"""Return a callable for the merge version aliases method over gRPC. + + Merges a set of aliases for a Model version. + + Returns: + Callable[[~.MergeVersionAliasesRequest], + ~.Model]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "merge_version_aliases" not in self._stubs: + self._stubs["merge_version_aliases"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.ModelService/MergeVersionAliases", + request_serializer=model_service.MergeVersionAliasesRequest.serialize, + response_deserializer=model.Model.deserialize, + ) + return self._stubs["merge_version_aliases"] + @property def export_model( self, ) -> Callable[[model_service.ExportModelRequest], operations_pb2.Operation]: r"""Return a callable for the export model method over gRPC. - Exports a trained, exportable, Model to a location specified by + Exports a trained, exportable Model to a location specified by the user. A Model is considered to be exportable if it has at least one [supported export format][google.cloud.aiplatform.v1.Model.supported_export_formats]. @@ -401,6 +504,35 @@ def export_model( ) return self._stubs["export_model"] + @property + def import_model_evaluation( + self, + ) -> Callable[ + [model_service.ImportModelEvaluationRequest], + gca_model_evaluation.ModelEvaluation, + ]: + r"""Return a callable for the import model evaluation method over gRPC. + + Imports an externally generated ModelEvaluation. + + Returns: + Callable[[~.ImportModelEvaluationRequest], + ~.ModelEvaluation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "import_model_evaluation" not in self._stubs: + self._stubs["import_model_evaluation"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.ModelService/ImportModelEvaluation", + request_serializer=model_service.ImportModelEvaluationRequest.serialize, + response_deserializer=gca_model_evaluation.ModelEvaluation.deserialize, + ) + return self._stubs["import_model_evaluation"] + @property def get_model_evaluation( self, @@ -516,5 +648,215 @@ def list_model_evaluation_slices( ) return self._stubs["list_model_evaluation_slices"] + def close(self): + self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + @property + def kind(self) -> str: + return "grpc" + __all__ = ("ModelServiceGrpcTransport",) diff --git a/google/cloud/aiplatform_v1/services/model_service/transports/grpc_asyncio.py b/google/cloud/aiplatform_v1/services/model_service/transports/grpc_asyncio.py index 0ce380ad4a..06c276b479 100644 --- a/google/cloud/aiplatform_v1/services/model_service/transports/grpc_asyncio.py +++ b/google/cloud/aiplatform_v1/services/model_service/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,12 +16,11 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore -from google.api_core import operations_v1 # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore @@ -29,8 +28,13 @@ from google.cloud.aiplatform_v1.types import model from google.cloud.aiplatform_v1.types import model as gca_model from google.cloud.aiplatform_v1.types import model_evaluation +from google.cloud.aiplatform_v1.types import model_evaluation as gca_model_evaluation from google.cloud.aiplatform_v1.types import model_evaluation_slice from google.cloud.aiplatform_v1.types import model_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from .base import ModelServiceTransport, DEFAULT_CLIENT_INFO from .grpc import ModelServiceGrpcTransport @@ -39,7 +43,7 @@ class ModelServiceGrpcAsyncIOTransport(ModelServiceTransport): """gRPC AsyncIO backend transport for ModelService. - A service for managing AI Platform's machine learning Models. + A service for managing Vertex AI's machine learning Models. This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation @@ -84,14 +88,14 @@ def create_channel( aio.Channel: A gRPC AsyncIO channel object. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @@ -109,6 +113,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -132,16 +137,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -150,6 +155,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport @@ -160,7 +167,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -202,13 +209,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -238,7 +249,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel @@ -255,7 +266,7 @@ def upload_model( ]: r"""Return a callable for the upload model method over gRPC. - Uploads a Model artifact into AI Platform. + Uploads a Model artifact into Vertex AI. Returns: Callable[[~.UploadModelRequest], @@ -329,6 +340,35 @@ def list_models( ) return self._stubs["list_models"] + @property + def list_model_versions( + self, + ) -> Callable[ + [model_service.ListModelVersionsRequest], + Awaitable[model_service.ListModelVersionsResponse], + ]: + r"""Return a callable for the list model versions method over gRPC. + + Lists versions of the specified model. + + Returns: + Callable[[~.ListModelVersionsRequest], + Awaitable[~.ListModelVersionsResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_model_versions" not in self._stubs: + self._stubs["list_model_versions"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.ModelService/ListModelVersions", + request_serializer=model_service.ListModelVersionsRequest.serialize, + response_deserializer=model_service.ListModelVersionsResponse.deserialize, + ) + return self._stubs["list_model_versions"] + @property def update_model( self, @@ -364,8 +404,13 @@ def delete_model( r"""Return a callable for the delete model method over gRPC. Deletes a Model. - Note: Model can only be deleted if there are no - DeployedModels created from it. + + A model cannot be deleted if any + [Endpoint][google.cloud.aiplatform.v1.Endpoint] resource has a + [DeployedModel][google.cloud.aiplatform.v1.DeployedModel] based + on the model in its + [deployed_models][google.cloud.aiplatform.v1.Endpoint.deployed_models] + field. Returns: Callable[[~.DeleteModelRequest], @@ -385,6 +430,66 @@ def delete_model( ) return self._stubs["delete_model"] + @property + def delete_model_version( + self, + ) -> Callable[ + [model_service.DeleteModelVersionRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the delete model version method over gRPC. + + Deletes a Model version. + + Model version can only be deleted if there are no + [DeployedModels][] created from it. Deleting the only version in + the Model is not allowed. Use + [DeleteModel][google.cloud.aiplatform.v1.ModelService.DeleteModel] + for deleting the Model instead. + + Returns: + Callable[[~.DeleteModelVersionRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_model_version" not in self._stubs: + self._stubs["delete_model_version"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.ModelService/DeleteModelVersion", + request_serializer=model_service.DeleteModelVersionRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_model_version"] + + @property + def merge_version_aliases( + self, + ) -> Callable[[model_service.MergeVersionAliasesRequest], Awaitable[model.Model]]: + r"""Return a callable for the merge version aliases method over gRPC. + + Merges a set of aliases for a Model version. + + Returns: + Callable[[~.MergeVersionAliasesRequest], + Awaitable[~.Model]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "merge_version_aliases" not in self._stubs: + self._stubs["merge_version_aliases"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.ModelService/MergeVersionAliases", + request_serializer=model_service.MergeVersionAliasesRequest.serialize, + response_deserializer=model.Model.deserialize, + ) + return self._stubs["merge_version_aliases"] + @property def export_model( self, @@ -393,7 +498,7 @@ def export_model( ]: r"""Return a callable for the export model method over gRPC. - Exports a trained, exportable, Model to a location specified by + Exports a trained, exportable Model to a location specified by the user. A Model is considered to be exportable if it has at least one [supported export format][google.cloud.aiplatform.v1.Model.supported_export_formats]. @@ -416,6 +521,35 @@ def export_model( ) return self._stubs["export_model"] + @property + def import_model_evaluation( + self, + ) -> Callable[ + [model_service.ImportModelEvaluationRequest], + Awaitable[gca_model_evaluation.ModelEvaluation], + ]: + r"""Return a callable for the import model evaluation method over gRPC. + + Imports an externally generated ModelEvaluation. + + Returns: + Callable[[~.ImportModelEvaluationRequest], + Awaitable[~.ModelEvaluation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "import_model_evaluation" not in self._stubs: + self._stubs["import_model_evaluation"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.ModelService/ImportModelEvaluation", + request_serializer=model_service.ImportModelEvaluationRequest.serialize, + response_deserializer=gca_model_evaluation.ModelEvaluation.deserialize, + ) + return self._stubs["import_model_evaluation"] + @property def get_model_evaluation( self, @@ -532,5 +666,211 @@ def list_model_evaluation_slices( ) return self._stubs["list_model_evaluation_slices"] + def close(self): + return self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + __all__ = ("ModelServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/aiplatform_v1/services/pipeline_service/__init__.py b/google/cloud/aiplatform_v1/services/pipeline_service/__init__.py index f6234690cb..5eea4316a6 100644 --- a/google/cloud/aiplatform_v1/services/pipeline_service/__init__.py +++ b/google/cloud/aiplatform_v1/services/pipeline_service/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1/services/pipeline_service/async_client.py b/google/cloud/aiplatform_v1/services/pipeline_service/async_client.py index 6d3e8ed6ec..1536c04942 100644 --- a/google/cloud/aiplatform_v1/services/pipeline_service/async_client.py +++ b/google/cloud/aiplatform_v1/services/pipeline_service/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,26 +16,37 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation as gac_operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1.services.pipeline_service import pagers from google.cloud.aiplatform_v1.types import encryption_spec from google.cloud.aiplatform_v1.types import model from google.cloud.aiplatform_v1.types import operation as gca_operation +from google.cloud.aiplatform_v1.types import pipeline_job +from google.cloud.aiplatform_v1.types import pipeline_job as gca_pipeline_job from google.cloud.aiplatform_v1.types import pipeline_service from google.cloud.aiplatform_v1.types import pipeline_state from google.cloud.aiplatform_v1.types import training_pipeline from google.cloud.aiplatform_v1.types import training_pipeline as gca_training_pipeline +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore from google.protobuf import struct_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore @@ -46,17 +57,35 @@ class PipelineServiceAsyncClient: - """A service for creating and managing AI Platform's pipelines.""" + """A service for creating and managing Vertex AI's pipelines. This + includes both ``TrainingPipeline`` resources (used for AutoML and + custom training) and ``PipelineJob`` resources (used for Vertex AI + Pipelines). + """ _client: PipelineServiceClient DEFAULT_ENDPOINT = PipelineServiceClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = PipelineServiceClient.DEFAULT_MTLS_ENDPOINT + artifact_path = staticmethod(PipelineServiceClient.artifact_path) + parse_artifact_path = staticmethod(PipelineServiceClient.parse_artifact_path) + context_path = staticmethod(PipelineServiceClient.context_path) + parse_context_path = staticmethod(PipelineServiceClient.parse_context_path) + custom_job_path = staticmethod(PipelineServiceClient.custom_job_path) + parse_custom_job_path = staticmethod(PipelineServiceClient.parse_custom_job_path) endpoint_path = staticmethod(PipelineServiceClient.endpoint_path) parse_endpoint_path = staticmethod(PipelineServiceClient.parse_endpoint_path) + execution_path = staticmethod(PipelineServiceClient.execution_path) + parse_execution_path = staticmethod(PipelineServiceClient.parse_execution_path) model_path = staticmethod(PipelineServiceClient.model_path) parse_model_path = staticmethod(PipelineServiceClient.parse_model_path) + network_path = staticmethod(PipelineServiceClient.network_path) + parse_network_path = staticmethod(PipelineServiceClient.parse_network_path) + pipeline_job_path = staticmethod(PipelineServiceClient.pipeline_job_path) + parse_pipeline_job_path = staticmethod( + PipelineServiceClient.parse_pipeline_job_path + ) training_pipeline_path = staticmethod(PipelineServiceClient.training_pipeline_path) parse_training_pipeline_path = staticmethod( PipelineServiceClient.parse_training_pipeline_path @@ -88,7 +117,8 @@ class PipelineServiceAsyncClient: @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -103,7 +133,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -118,9 +148,45 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return PipelineServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> PipelineServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: PipelineServiceTransport: The transport used by the client instance. @@ -139,7 +205,7 @@ def __init__( client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the pipeline service client. + """Instantiates the pipeline service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -180,19 +246,44 @@ def __init__( async def create_training_pipeline( self, - request: pipeline_service.CreateTrainingPipelineRequest = None, + request: Union[pipeline_service.CreateTrainingPipelineRequest, dict] = None, *, parent: str = None, training_pipeline: gca_training_pipeline.TrainingPipeline = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_training_pipeline.TrainingPipeline: r"""Creates a TrainingPipeline. A created TrainingPipeline right away will be attempted to be run. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_create_training_pipeline(): + # Create a client + client = aiplatform_v1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + training_pipeline = aiplatform_v1.TrainingPipeline() + training_pipeline.display_name = "display_name_value" + training_pipeline.training_task_definition = "training_task_definition_value" + training_pipeline.training_task_inputs.null_value = "NULL_VALUE" + + request = aiplatform_v1.CreateTrainingPipelineRequest( + parent="parent_value", + training_pipeline=training_pipeline, + ) + + # Make the request + response = await client.create_training_pipeline(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.CreateTrainingPipelineRequest`): + request (Union[google.cloud.aiplatform_v1.types.CreateTrainingPipelineRequest, dict]): The request object. Request message for [PipelineService.CreateTrainingPipeline][google.cloud.aiplatform.v1.PipelineService.CreateTrainingPipeline]. parent (:class:`str`): @@ -220,14 +311,14 @@ async def create_training_pipeline( google.cloud.aiplatform_v1.types.TrainingPipeline: The TrainingPipeline orchestrates tasks associated with training a Model. It always executes the training task, and optionally may - also export data from AI Platform's Dataset which + also export data from Vertex AI's Dataset which becomes the training input, [upload][google.cloud.aiplatform.v1.ModelService.UploadModel] - the Model to AI Platform, and evaluate the Model. + the Model to Vertex AI, and evaluate the Model. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, training_pipeline]) if request is not None and has_flattened_params: @@ -249,7 +340,7 @@ async def create_training_pipeline( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.create_training_pipeline, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -260,30 +351,53 @@ async def create_training_pipeline( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def get_training_pipeline( self, - request: pipeline_service.GetTrainingPipelineRequest = None, + request: Union[pipeline_service.GetTrainingPipelineRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> training_pipeline.TrainingPipeline: r"""Gets a TrainingPipeline. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_get_training_pipeline(): + # Create a client + client = aiplatform_v1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetTrainingPipelineRequest( + name="name_value", + ) + + # Make the request + response = await client.get_training_pipeline(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.GetTrainingPipelineRequest`): + request (Union[google.cloud.aiplatform_v1.types.GetTrainingPipelineRequest, dict]): The request object. Request message for [PipelineService.GetTrainingPipeline][google.cloud.aiplatform.v1.PipelineService.GetTrainingPipeline]. name (:class:`str`): Required. The name of the TrainingPipeline resource. Format: - ``projects/{project}/locations/{location}/trainingPipelines/{training_pipeline}`` This corresponds to the ``name`` field @@ -299,14 +413,14 @@ async def get_training_pipeline( google.cloud.aiplatform_v1.types.TrainingPipeline: The TrainingPipeline orchestrates tasks associated with training a Model. It always executes the training task, and optionally may - also export data from AI Platform's Dataset which + also export data from Vertex AI's Dataset which becomes the training input, [upload][google.cloud.aiplatform.v1.ModelService.UploadModel] - the Model to AI Platform, and evaluate the Model. + the Model to Vertex AI, and evaluate the Model. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -326,7 +440,7 @@ async def get_training_pipeline( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.get_training_pipeline, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -337,24 +451,49 @@ async def get_training_pipeline( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_training_pipelines( self, - request: pipeline_service.ListTrainingPipelinesRequest = None, + request: Union[pipeline_service.ListTrainingPipelinesRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListTrainingPipelinesAsyncPager: r"""Lists TrainingPipelines in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_list_training_pipelines(): + # Create a client + client = aiplatform_v1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListTrainingPipelinesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_training_pipelines(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.ListTrainingPipelinesRequest`): + request (Union[google.cloud.aiplatform_v1.types.ListTrainingPipelinesRequest, dict]): The request object. Request message for [PipelineService.ListTrainingPipelines][google.cloud.aiplatform.v1.PipelineService.ListTrainingPipelines]. parent (:class:`str`): @@ -381,7 +520,7 @@ async def list_training_pipelines( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -401,7 +540,7 @@ async def list_training_pipelines( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.list_training_pipelines, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -412,12 +551,20 @@ async def list_training_pipelines( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListTrainingPipelinesAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -425,23 +572,45 @@ async def list_training_pipelines( async def delete_training_pipeline( self, - request: pipeline_service.DeleteTrainingPipelineRequest = None, + request: Union[pipeline_service.DeleteTrainingPipelineRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a TrainingPipeline. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_delete_training_pipeline(): + # Create a client + client = aiplatform_v1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteTrainingPipelineRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_training_pipeline(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.DeleteTrainingPipelineRequest`): + request (Union[google.cloud.aiplatform_v1.types.DeleteTrainingPipelineRequest, dict]): The request object. Request message for [PipelineService.DeleteTrainingPipeline][google.cloud.aiplatform.v1.PipelineService.DeleteTrainingPipeline]. name (:class:`str`): Required. The name of the TrainingPipeline resource to be deleted. Format: - ``projects/{project}/locations/{location}/trainingPipelines/{training_pipeline}`` This corresponds to the ``name`` field @@ -473,7 +642,7 @@ async def delete_training_pipeline( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -493,7 +662,7 @@ async def delete_training_pipeline( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.delete_training_pipeline, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -504,7 +673,12 @@ async def delete_training_pipeline( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -519,10 +693,10 @@ async def delete_training_pipeline( async def cancel_training_pipeline( self, - request: pipeline_service.CancelTrainingPipelineRequest = None, + request: Union[pipeline_service.CancelTrainingPipelineRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -540,14 +714,29 @@ async def cancel_training_pipeline( [TrainingPipeline.state][google.cloud.aiplatform.v1.TrainingPipeline.state] is set to ``CANCELLED``. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_cancel_training_pipeline(): + # Create a client + client = aiplatform_v1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CancelTrainingPipelineRequest( + name="name_value", + ) + + # Make the request + await client.cancel_training_pipeline(request=request) + Args: - request (:class:`google.cloud.aiplatform_v1.types.CancelTrainingPipelineRequest`): + request (Union[google.cloud.aiplatform_v1.types.CancelTrainingPipelineRequest, dict]): The request object. Request message for [PipelineService.CancelTrainingPipeline][google.cloud.aiplatform.v1.PipelineService.CancelTrainingPipeline]. name (:class:`str`): Required. The name of the TrainingPipeline to cancel. Format: - ``projects/{project}/locations/{location}/trainingPipelines/{training_pipeline}`` This corresponds to the ``name`` field @@ -560,7 +749,7 @@ async def cancel_training_pipeline( 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 + # Quick 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: @@ -580,7 +769,7 @@ async def cancel_training_pipeline( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.cancel_training_pipeline, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -592,9 +781,1228 @@ async def cancel_training_pipeline( # Send the request. await rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + async def create_pipeline_job( + self, + request: Union[pipeline_service.CreatePipelineJobRequest, dict] = None, + *, + parent: str = None, + pipeline_job: gca_pipeline_job.PipelineJob = None, + pipeline_job_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_pipeline_job.PipelineJob: + r"""Creates a PipelineJob. A PipelineJob will run + immediately when created. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_create_pipeline_job(): + # Create a client + client = aiplatform_v1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreatePipelineJobRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_pipeline_job(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CreatePipelineJobRequest, dict]): + The request object. Request message for + [PipelineService.CreatePipelineJob][google.cloud.aiplatform.v1.PipelineService.CreatePipelineJob]. + parent (:class:`str`): + Required. The resource name of the Location to create + the PipelineJob in. Format: + ``projects/{project}/locations/{location}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + pipeline_job (:class:`google.cloud.aiplatform_v1.types.PipelineJob`): + Required. The PipelineJob to create. + This corresponds to the ``pipeline_job`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + pipeline_job_id (:class:`str`): + The ID to use for the PipelineJob, which will become the + final component of the PipelineJob name. If not + provided, an ID will be automatically generated. + + This value should be less than 128 characters, and valid + characters are /[a-z][0-9]-/. + + This corresponds to the ``pipeline_job_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: + google.cloud.aiplatform_v1.types.PipelineJob: + An instance of a machine learning + PipelineJob. + + """ + # Create or coerce a protobuf request object. + # Quick 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, pipeline_job, pipeline_job_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 = pipeline_service.CreatePipelineJobRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if pipeline_job is not None: + request.pipeline_job = pipeline_job + if pipeline_job_id is not None: + request.pipeline_job_id = pipeline_job_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_pipeline_job, + default_timeout=None, + 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 get_pipeline_job( + self, + request: Union[pipeline_service.GetPipelineJobRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pipeline_job.PipelineJob: + r"""Gets a PipelineJob. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_get_pipeline_job(): + # Create a client + client = aiplatform_v1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetPipelineJobRequest( + name="name_value", + ) + + # Make the request + response = await client.get_pipeline_job(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetPipelineJobRequest, dict]): + The request object. Request message for + [PipelineService.GetPipelineJob][google.cloud.aiplatform.v1.PipelineService.GetPipelineJob]. + name (:class:`str`): + Required. The name of the PipelineJob resource. Format: + ``projects/{project}/locations/{location}/pipelineJobs/{pipeline_job}`` + + 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: + google.cloud.aiplatform_v1.types.PipelineJob: + An instance of a machine learning + PipelineJob. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = pipeline_service.GetPipelineJobRequest(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_pipeline_job, + default_timeout=None, + 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 list_pipeline_jobs( + self, + request: Union[pipeline_service.ListPipelineJobsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListPipelineJobsAsyncPager: + r"""Lists PipelineJobs in a Location. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_list_pipeline_jobs(): + # Create a client + client = aiplatform_v1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListPipelineJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_pipeline_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListPipelineJobsRequest, dict]): + The request object. Request message for + [PipelineService.ListPipelineJobs][google.cloud.aiplatform.v1.PipelineService.ListPipelineJobs]. + parent (:class:`str`): + Required. The resource name of the Location to list the + PipelineJobs from. Format: + ``projects/{project}/locations/{location}`` + + 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: + google.cloud.aiplatform_v1.services.pipeline_service.pagers.ListPipelineJobsAsyncPager: + Response message for + [PipelineService.ListPipelineJobs][google.cloud.aiplatform.v1.PipelineService.ListPipelineJobs] + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = pipeline_service.ListPipelineJobsRequest(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_pipeline_jobs, + default_timeout=None, + 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.ListPipelineJobsAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, ) + # Done; return the response. + return response + + async def delete_pipeline_job( + self, + request: Union[pipeline_service.DeletePipelineJobRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Deletes a PipelineJob. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_delete_pipeline_job(): + # Create a client + client = aiplatform_v1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeletePipelineJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_pipeline_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.DeletePipelineJobRequest, dict]): + The request object. Request message for + [PipelineService.DeletePipelineJob][google.cloud.aiplatform.v1.PipelineService.DeletePipelineJob]. + name (:class:`str`): + Required. The name of the PipelineJob resource to be + deleted. Format: + ``projects/{project}/locations/{location}/pipelineJobs/{pipeline_job}`` + + 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = pipeline_service.DeletePipelineJobRequest(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_pipeline_job, + default_timeout=None, + 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, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, + ) + + # Done; return the response. + return response + + async def cancel_pipeline_job( + self, + request: Union[pipeline_service.CancelPipelineJobRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Cancels a PipelineJob. Starts asynchronous cancellation on the + PipelineJob. The server makes a best effort to cancel the + pipeline, but success is not guaranteed. Clients can use + [PipelineService.GetPipelineJob][google.cloud.aiplatform.v1.PipelineService.GetPipelineJob] + or other methods to check whether the cancellation succeeded or + whether the pipeline completed despite cancellation. On + successful cancellation, the PipelineJob is not deleted; instead + it becomes a pipeline with a + [PipelineJob.error][google.cloud.aiplatform.v1.PipelineJob.error] + value with a [google.rpc.Status.code][google.rpc.Status.code] of + 1, corresponding to ``Code.CANCELLED``, and + [PipelineJob.state][google.cloud.aiplatform.v1.PipelineJob.state] + is set to ``CANCELLED``. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_cancel_pipeline_job(): + # Create a client + client = aiplatform_v1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CancelPipelineJobRequest( + name="name_value", + ) + + # Make the request + await client.cancel_pipeline_job(request=request) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CancelPipelineJobRequest, dict]): + The request object. Request message for + [PipelineService.CancelPipelineJob][google.cloud.aiplatform.v1.PipelineService.CancelPipelineJob]. + name (:class:`str`): + Required. The name of the PipelineJob to cancel. Format: + ``projects/{project}/locations/{location}/pipelineJobs/{pipeline_job}`` + + 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. + # Quick 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 = pipeline_service.CancelPipelineJobRequest(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.cancel_pipeline_job, + default_timeout=None, + 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 list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_operations, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.delete_operation, + default_timeout=None, + 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 cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + 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 wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.wait_operation, + default_timeout=None, + 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 set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_location, + default_timeout=None, + 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 list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_locations, + default_timeout=None, + 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 __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/aiplatform_v1/services/pipeline_service/client.py b/google/cloud/aiplatform_v1/services/pipeline_service/client.py index 73c1f37a1a..5ea8cb0c96 100644 --- a/google/cloud/aiplatform_v1/services/pipeline_service/client.py +++ b/google/cloud/aiplatform_v1/services/pipeline_service/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,32 +14,42 @@ # 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 +from typing import Dict, Mapping, 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 as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_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 +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation as gac_operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1.services.pipeline_service import pagers from google.cloud.aiplatform_v1.types import encryption_spec from google.cloud.aiplatform_v1.types import model from google.cloud.aiplatform_v1.types import operation as gca_operation +from google.cloud.aiplatform_v1.types import pipeline_job +from google.cloud.aiplatform_v1.types import pipeline_job as gca_pipeline_job from google.cloud.aiplatform_v1.types import pipeline_service from google.cloud.aiplatform_v1.types import pipeline_state from google.cloud.aiplatform_v1.types import training_pipeline from google.cloud.aiplatform_v1.types import training_pipeline as gca_training_pipeline +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore from google.protobuf import struct_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore @@ -63,8 +73,11 @@ class PipelineServiceClientMeta(type): _transport_registry["grpc"] = PipelineServiceGrpcTransport _transport_registry["grpc_asyncio"] = PipelineServiceGrpcAsyncIOTransport - def get_transport_class(cls, label: str = None,) -> Type[PipelineServiceTransport]: - """Return an appropriate transport class. + def get_transport_class( + cls, + label: str = None, + ) -> Type[PipelineServiceTransport]: + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -83,11 +96,16 @@ def get_transport_class(cls, label: str = None,) -> Type[PipelineServiceTranspor class PipelineServiceClient(metaclass=PipelineServiceClientMeta): - """A service for creating and managing AI Platform's pipelines.""" + """A service for creating and managing Vertex AI's pipelines. This + includes both ``TrainingPipeline`` resources (used for AutoML and + custom training) and ``PipelineJob`` resources (used for Vertex AI + Pipelines). + """ @staticmethod def _get_default_mtls_endpoint(api_endpoint): - """Convert api endpoint to mTLS endpoint. + """Converts api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. Args: @@ -121,7 +139,8 @@ def _get_default_mtls_endpoint(api_endpoint): @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -138,7 +157,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -157,23 +176,100 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> PipelineServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - PipelineServiceTransport: The transport used by the client instance. + PipelineServiceTransport: The transport used by the client + instance. """ return self._transport @staticmethod - def endpoint_path(project: str, location: str, endpoint: str,) -> str: - """Return a fully-qualified endpoint string.""" + def artifact_path( + project: str, + location: str, + metadata_store: str, + artifact: str, + ) -> str: + """Returns a fully-qualified artifact string.""" + return "projects/{project}/locations/{location}/metadataStores/{metadata_store}/artifacts/{artifact}".format( + project=project, + location=location, + metadata_store=metadata_store, + artifact=artifact, + ) + + @staticmethod + def parse_artifact_path(path: str) -> Dict[str, str]: + """Parses a artifact path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/metadataStores/(?P.+?)/artifacts/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def context_path( + project: str, + location: str, + metadata_store: str, + context: str, + ) -> str: + """Returns a fully-qualified context string.""" + return "projects/{project}/locations/{location}/metadataStores/{metadata_store}/contexts/{context}".format( + project=project, + location=location, + metadata_store=metadata_store, + context=context, + ) + + @staticmethod + def parse_context_path(path: str) -> Dict[str, str]: + """Parses a context path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/metadataStores/(?P.+?)/contexts/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def custom_job_path( + project: str, + location: str, + custom_job: str, + ) -> str: + """Returns a fully-qualified custom_job string.""" + return "projects/{project}/locations/{location}/customJobs/{custom_job}".format( + project=project, + location=location, + custom_job=custom_job, + ) + + @staticmethod + def parse_custom_job_path(path: str) -> Dict[str, str]: + """Parses a custom_job path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/customJobs/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def endpoint_path( + project: str, + location: str, + endpoint: str, + ) -> str: + """Returns a fully-qualified endpoint string.""" return "projects/{project}/locations/{location}/endpoints/{endpoint}".format( - project=project, location=location, endpoint=endpoint, + project=project, + location=location, + endpoint=endpoint, ) @staticmethod def parse_endpoint_path(path: str) -> Dict[str, str]: - """Parse a endpoint path into its component segments.""" + """Parses a endpoint path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/endpoints/(?P.+?)$", path, @@ -181,33 +277,108 @@ def parse_endpoint_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def model_path(project: str, location: str, model: str,) -> str: - """Return a fully-qualified model string.""" + def execution_path( + project: str, + location: str, + metadata_store: str, + execution: str, + ) -> str: + """Returns a fully-qualified execution string.""" + return "projects/{project}/locations/{location}/metadataStores/{metadata_store}/executions/{execution}".format( + project=project, + location=location, + metadata_store=metadata_store, + execution=execution, + ) + + @staticmethod + def parse_execution_path(path: str) -> Dict[str, str]: + """Parses a execution path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/metadataStores/(?P.+?)/executions/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def model_path( + project: str, + location: str, + model: str, + ) -> str: + """Returns a fully-qualified model string.""" return "projects/{project}/locations/{location}/models/{model}".format( - project=project, location=location, model=model, + project=project, + location=location, + model=model, ) @staticmethod def parse_model_path(path: str) -> Dict[str, str]: - """Parse a model path into its component segments.""" + """Parses a model path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/models/(?P.+?)$", path, ) return m.groupdict() if m else {} + @staticmethod + def network_path( + project: str, + network: str, + ) -> str: + """Returns a fully-qualified network string.""" + return "projects/{project}/global/networks/{network}".format( + project=project, + network=network, + ) + + @staticmethod + def parse_network_path(path: str) -> Dict[str, str]: + """Parses a network path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/global/networks/(?P.+?)$", path + ) + return m.groupdict() if m else {} + + @staticmethod + def pipeline_job_path( + project: str, + location: str, + pipeline_job: str, + ) -> str: + """Returns a fully-qualified pipeline_job string.""" + return "projects/{project}/locations/{location}/pipelineJobs/{pipeline_job}".format( + project=project, + location=location, + pipeline_job=pipeline_job, + ) + + @staticmethod + def parse_pipeline_job_path(path: str) -> Dict[str, str]: + """Parses a pipeline_job path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/pipelineJobs/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def training_pipeline_path( - project: str, location: str, training_pipeline: str, + project: str, + location: str, + training_pipeline: str, ) -> str: - """Return a fully-qualified training_pipeline string.""" + """Returns a fully-qualified training_pipeline string.""" return "projects/{project}/locations/{location}/trainingPipelines/{training_pipeline}".format( - project=project, location=location, training_pipeline=training_pipeline, + project=project, + location=location, + training_pipeline=training_pipeline, ) @staticmethod def parse_training_pipeline_path(path: str) -> Dict[str, str]: - """Parse a training_pipeline path into its component segments.""" + """Parses a training_pipeline path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/trainingPipelines/(?P.+?)$", path, @@ -215,8 +386,10 @@ def parse_training_pipeline_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + def common_billing_account_path( + billing_account: str, + ) -> str: + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -228,9 +401,13 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: 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,) + def common_folder_path( + folder: str, + ) -> str: + """Returns a fully-qualified folder string.""" + return "folders/{folder}".format( + folder=folder, + ) @staticmethod def parse_common_folder_path(path: str) -> Dict[str, str]: @@ -239,9 +416,13 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: 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,) + def common_organization_path( + organization: str, + ) -> str: + """Returns a fully-qualified organization string.""" + return "organizations/{organization}".format( + organization=organization, + ) @staticmethod def parse_common_organization_path(path: str) -> Dict[str, str]: @@ -250,9 +431,13 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: 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,) + def common_project_path( + project: str, + ) -> str: + """Returns a fully-qualified project string.""" + return "projects/{project}".format( + project=project, + ) @staticmethod def parse_common_project_path(path: str) -> Dict[str, str]: @@ -261,10 +446,14 @@ def parse_common_project_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_location_path(project: str, location: str,) -> str: - """Return a fully-qualified location string.""" + def common_location_path( + project: str, + location: str, + ) -> str: + """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) @staticmethod @@ -273,6 +462,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + def __init__( self, *, @@ -281,7 +537,7 @@ def __init__( client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the pipeline service client. + """Instantiates the pipeline service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -323,58 +579,42 @@ def __init__( 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")) + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - client_cert_source_func = ( - mtls.default_client_cert_source() 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" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # 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, PipelineServiceTransport): # transport is a PipelineServiceTransport instance. - if credentials or client_options.credentials_file: + if credentials or client_options.credentials_file or api_key_value: 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." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + Transport = type(self).get_transport_class(transport) self._transport = Transport( credentials=credentials, @@ -384,23 +624,49 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, + always_use_jwt_access=True, ) def create_training_pipeline( self, - request: pipeline_service.CreateTrainingPipelineRequest = None, + request: Union[pipeline_service.CreateTrainingPipelineRequest, dict] = None, *, parent: str = None, training_pipeline: gca_training_pipeline.TrainingPipeline = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_training_pipeline.TrainingPipeline: r"""Creates a TrainingPipeline. A created TrainingPipeline right away will be attempted to be run. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_create_training_pipeline(): + # Create a client + client = aiplatform_v1.PipelineServiceClient() + + # Initialize request argument(s) + training_pipeline = aiplatform_v1.TrainingPipeline() + training_pipeline.display_name = "display_name_value" + training_pipeline.training_task_definition = "training_task_definition_value" + training_pipeline.training_task_inputs.null_value = "NULL_VALUE" + + request = aiplatform_v1.CreateTrainingPipelineRequest( + parent="parent_value", + training_pipeline=training_pipeline, + ) + + # Make the request + response = client.create_training_pipeline(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1.types.CreateTrainingPipelineRequest): + request (Union[google.cloud.aiplatform_v1.types.CreateTrainingPipelineRequest, dict]): The request object. Request message for [PipelineService.CreateTrainingPipeline][google.cloud.aiplatform.v1.PipelineService.CreateTrainingPipeline]. parent (str): @@ -428,14 +694,14 @@ def create_training_pipeline( google.cloud.aiplatform_v1.types.TrainingPipeline: The TrainingPipeline orchestrates tasks associated with training a Model. It always executes the training task, and optionally may - also export data from AI Platform's Dataset which + also export data from Vertex AI's Dataset which becomes the training input, [upload][google.cloud.aiplatform.v1.ModelService.UploadModel] - the Model to AI Platform, and evaluate the Model. + the Model to Vertex AI, and evaluate the Model. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, training_pipeline]) if request is not None and has_flattened_params: @@ -468,30 +734,53 @@ def create_training_pipeline( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def get_training_pipeline( self, - request: pipeline_service.GetTrainingPipelineRequest = None, + request: Union[pipeline_service.GetTrainingPipelineRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> training_pipeline.TrainingPipeline: r"""Gets a TrainingPipeline. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_get_training_pipeline(): + # Create a client + client = aiplatform_v1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetTrainingPipelineRequest( + name="name_value", + ) + + # Make the request + response = client.get_training_pipeline(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1.types.GetTrainingPipelineRequest): + request (Union[google.cloud.aiplatform_v1.types.GetTrainingPipelineRequest, dict]): The request object. Request message for [PipelineService.GetTrainingPipeline][google.cloud.aiplatform.v1.PipelineService.GetTrainingPipeline]. name (str): Required. The name of the TrainingPipeline resource. Format: - ``projects/{project}/locations/{location}/trainingPipelines/{training_pipeline}`` This corresponds to the ``name`` field @@ -507,14 +796,14 @@ def get_training_pipeline( google.cloud.aiplatform_v1.types.TrainingPipeline: The TrainingPipeline orchestrates tasks associated with training a Model. It always executes the training task, and optionally may - also export data from AI Platform's Dataset which + also export data from Vertex AI's Dataset which becomes the training input, [upload][google.cloud.aiplatform.v1.ModelService.UploadModel] - the Model to AI Platform, and evaluate the Model. + the Model to Vertex AI, and evaluate the Model. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -545,24 +834,49 @@ def get_training_pipeline( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_training_pipelines( self, - request: pipeline_service.ListTrainingPipelinesRequest = None, + request: Union[pipeline_service.ListTrainingPipelinesRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListTrainingPipelinesPager: r"""Lists TrainingPipelines in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_list_training_pipelines(): + # Create a client + client = aiplatform_v1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListTrainingPipelinesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_training_pipelines(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1.types.ListTrainingPipelinesRequest): + request (Union[google.cloud.aiplatform_v1.types.ListTrainingPipelinesRequest, dict]): The request object. Request message for [PipelineService.ListTrainingPipelines][google.cloud.aiplatform.v1.PipelineService.ListTrainingPipelines]. parent (str): @@ -589,7 +903,7 @@ def list_training_pipelines( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -620,12 +934,20 @@ def list_training_pipelines( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListTrainingPipelinesPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -633,23 +955,45 @@ def list_training_pipelines( def delete_training_pipeline( self, - request: pipeline_service.DeleteTrainingPipelineRequest = None, + request: Union[pipeline_service.DeleteTrainingPipelineRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Deletes a TrainingPipeline. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_delete_training_pipeline(): + # Create a client + client = aiplatform_v1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteTrainingPipelineRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_training_pipeline(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1.types.DeleteTrainingPipelineRequest): + request (Union[google.cloud.aiplatform_v1.types.DeleteTrainingPipelineRequest, dict]): The request object. Request message for [PipelineService.DeleteTrainingPipeline][google.cloud.aiplatform.v1.PipelineService.DeleteTrainingPipeline]. name (str): Required. The name of the TrainingPipeline resource to be deleted. Format: - ``projects/{project}/locations/{location}/trainingPipelines/{training_pipeline}`` This corresponds to the ``name`` field @@ -681,7 +1025,7 @@ def delete_training_pipeline( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -712,7 +1056,12 @@ def delete_training_pipeline( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -727,10 +1076,10 @@ def delete_training_pipeline( def cancel_training_pipeline( self, - request: pipeline_service.CancelTrainingPipelineRequest = None, + request: Union[pipeline_service.CancelTrainingPipelineRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -748,14 +1097,29 @@ def cancel_training_pipeline( [TrainingPipeline.state][google.cloud.aiplatform.v1.TrainingPipeline.state] is set to ``CANCELLED``. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_cancel_training_pipeline(): + # Create a client + client = aiplatform_v1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CancelTrainingPipelineRequest( + name="name_value", + ) + + # Make the request + client.cancel_training_pipeline(request=request) + Args: - request (google.cloud.aiplatform_v1.types.CancelTrainingPipelineRequest): + request (Union[google.cloud.aiplatform_v1.types.CancelTrainingPipelineRequest, dict]): The request object. Request message for [PipelineService.CancelTrainingPipeline][google.cloud.aiplatform.v1.PipelineService.CancelTrainingPipeline]. name (str): Required. The name of the TrainingPipeline to cancel. Format: - ``projects/{project}/locations/{location}/trainingPipelines/{training_pipeline}`` This corresponds to the ``name`` field @@ -768,7 +1132,7 @@ def cancel_training_pipeline( 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 + # Quick 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: @@ -800,9 +1164,1235 @@ def cancel_training_pipeline( # Send the request. rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def create_pipeline_job( + self, + request: Union[pipeline_service.CreatePipelineJobRequest, dict] = None, + *, + parent: str = None, + pipeline_job: gca_pipeline_job.PipelineJob = None, + pipeline_job_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_pipeline_job.PipelineJob: + r"""Creates a PipelineJob. A PipelineJob will run + immediately when created. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_create_pipeline_job(): + # Create a client + client = aiplatform_v1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreatePipelineJobRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_pipeline_job(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CreatePipelineJobRequest, dict]): + The request object. Request message for + [PipelineService.CreatePipelineJob][google.cloud.aiplatform.v1.PipelineService.CreatePipelineJob]. + parent (str): + Required. The resource name of the Location to create + the PipelineJob in. Format: + ``projects/{project}/locations/{location}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + pipeline_job (google.cloud.aiplatform_v1.types.PipelineJob): + Required. The PipelineJob to create. + This corresponds to the ``pipeline_job`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + pipeline_job_id (str): + The ID to use for the PipelineJob, which will become the + final component of the PipelineJob name. If not + provided, an ID will be automatically generated. + + This value should be less than 128 characters, and valid + characters are /[a-z][0-9]-/. + + This corresponds to the ``pipeline_job_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: + google.cloud.aiplatform_v1.types.PipelineJob: + An instance of a machine learning + PipelineJob. + + """ + # Create or coerce a protobuf request object. + # Quick 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, pipeline_job, pipeline_job_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 pipeline_service.CreatePipelineJobRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, pipeline_service.CreatePipelineJobRequest): + request = pipeline_service.CreatePipelineJobRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if pipeline_job is not None: + request.pipeline_job = pipeline_job + if pipeline_job_id is not None: + request.pipeline_job_id = pipeline_job_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_pipeline_job] + + # 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 get_pipeline_job( + self, + request: Union[pipeline_service.GetPipelineJobRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pipeline_job.PipelineJob: + r"""Gets a PipelineJob. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_get_pipeline_job(): + # Create a client + client = aiplatform_v1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetPipelineJobRequest( + name="name_value", + ) + + # Make the request + response = client.get_pipeline_job(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetPipelineJobRequest, dict]): + The request object. Request message for + [PipelineService.GetPipelineJob][google.cloud.aiplatform.v1.PipelineService.GetPipelineJob]. + name (str): + Required. The name of the PipelineJob resource. Format: + ``projects/{project}/locations/{location}/pipelineJobs/{pipeline_job}`` + + 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: + google.cloud.aiplatform_v1.types.PipelineJob: + An instance of a machine learning + PipelineJob. + + """ + # Create or coerce a protobuf request object. + # Quick 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 pipeline_service.GetPipelineJobRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, pipeline_service.GetPipelineJobRequest): + request = pipeline_service.GetPipelineJobRequest(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_pipeline_job] + + # 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 list_pipeline_jobs( + self, + request: Union[pipeline_service.ListPipelineJobsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListPipelineJobsPager: + r"""Lists PipelineJobs in a Location. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_list_pipeline_jobs(): + # Create a client + client = aiplatform_v1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListPipelineJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_pipeline_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListPipelineJobsRequest, dict]): + The request object. Request message for + [PipelineService.ListPipelineJobs][google.cloud.aiplatform.v1.PipelineService.ListPipelineJobs]. + parent (str): + Required. The resource name of the Location to list the + PipelineJobs from. Format: + ``projects/{project}/locations/{location}`` + + 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: + google.cloud.aiplatform_v1.services.pipeline_service.pagers.ListPipelineJobsPager: + Response message for + [PipelineService.ListPipelineJobs][google.cloud.aiplatform.v1.PipelineService.ListPipelineJobs] + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 pipeline_service.ListPipelineJobsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, pipeline_service.ListPipelineJobsRequest): + request = pipeline_service.ListPipelineJobsRequest(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_pipeline_jobs] + + # 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.ListPipelineJobsPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_pipeline_job( + self, + request: Union[pipeline_service.DeletePipelineJobRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Deletes a PipelineJob. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_delete_pipeline_job(): + # Create a client + client = aiplatform_v1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeletePipelineJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_pipeline_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.DeletePipelineJobRequest, dict]): + The request object. Request message for + [PipelineService.DeletePipelineJob][google.cloud.aiplatform.v1.PipelineService.DeletePipelineJob]. + name (str): + Required. The name of the PipelineJob resource to be + deleted. Format: + ``projects/{project}/locations/{location}/pipelineJobs/{pipeline_job}`` + + 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # Create or coerce a protobuf request object. + # Quick 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 pipeline_service.DeletePipelineJobRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, pipeline_service.DeletePipelineJobRequest): + request = pipeline_service.DeletePipelineJobRequest(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_pipeline_job] + + # 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, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, + ) + + # Done; return the response. + return response + + def cancel_pipeline_job( + self, + request: Union[pipeline_service.CancelPipelineJobRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Cancels a PipelineJob. Starts asynchronous cancellation on the + PipelineJob. The server makes a best effort to cancel the + pipeline, but success is not guaranteed. Clients can use + [PipelineService.GetPipelineJob][google.cloud.aiplatform.v1.PipelineService.GetPipelineJob] + or other methods to check whether the cancellation succeeded or + whether the pipeline completed despite cancellation. On + successful cancellation, the PipelineJob is not deleted; instead + it becomes a pipeline with a + [PipelineJob.error][google.cloud.aiplatform.v1.PipelineJob.error] + value with a [google.rpc.Status.code][google.rpc.Status.code] of + 1, corresponding to ``Code.CANCELLED``, and + [PipelineJob.state][google.cloud.aiplatform.v1.PipelineJob.state] + is set to ``CANCELLED``. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_cancel_pipeline_job(): + # Create a client + client = aiplatform_v1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CancelPipelineJobRequest( + name="name_value", + ) + + # Make the request + client.cancel_pipeline_job(request=request) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CancelPipelineJobRequest, dict]): + The request object. Request message for + [PipelineService.CancelPipelineJob][google.cloud.aiplatform.v1.PipelineService.CancelPipelineJob]. + name (str): + Required. The name of the PipelineJob to cancel. Format: + ``projects/{project}/locations/{location}/pipelineJobs/{pipeline_job}`` + + 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. + # Quick 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 pipeline_service.CancelPipelineJobRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, pipeline_service.CancelPipelineJobRequest): + request = pipeline_service.CancelPipelineJobRequest(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.cancel_pipeline_job] + + # 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 __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_operations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.delete_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.wait_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_location, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_locations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/aiplatform_v1/services/pipeline_service/pagers.py b/google/cloud/aiplatform_v1/services/pipeline_service/pagers.py index cb70e4585b..2b7715b545 100644 --- a/google/cloud/aiplatform_v1/services/pipeline_service/pagers.py +++ b/google/cloud/aiplatform_v1/services/pipeline_service/pagers.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,15 +15,16 @@ # from typing import ( Any, - AsyncIterable, + AsyncIterator, Awaitable, Callable, - Iterable, Sequence, Tuple, Optional, + Iterator, ) +from google.cloud.aiplatform_v1.types import pipeline_job from google.cloud.aiplatform_v1.types import pipeline_service from google.cloud.aiplatform_v1.types import training_pipeline @@ -75,14 +76,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[pipeline_service.ListTrainingPipelinesResponse]: + def pages(self) -> Iterator[pipeline_service.ListTrainingPipelinesResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[training_pipeline.TrainingPipeline]: + def __iter__(self) -> Iterator[training_pipeline.TrainingPipeline]: for page in self.pages: yield from page.training_pipelines @@ -118,7 +119,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -141,14 +142,14 @@ def __getattr__(self, name: str) -> Any: @property async def pages( self, - ) -> AsyncIterable[pipeline_service.ListTrainingPipelinesResponse]: + ) -> AsyncIterator[pipeline_service.ListTrainingPipelinesResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[training_pipeline.TrainingPipeline]: + def __aiter__(self) -> AsyncIterator[training_pipeline.TrainingPipeline]: async def async_generator(): async for page in self.pages: for response in page.training_pipelines: @@ -158,3 +159,131 @@ async def async_generator(): def __repr__(self) -> str: return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListPipelineJobsPager: + """A pager for iterating through ``list_pipeline_jobs`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListPipelineJobsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``pipeline_jobs`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListPipelineJobs`` requests and continue to iterate + through the ``pipeline_jobs`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListPipelineJobsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., pipeline_service.ListPipelineJobsResponse], + request: pipeline_service.ListPipelineJobsRequest, + response: pipeline_service.ListPipelineJobsResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListPipelineJobsRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListPipelineJobsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = pipeline_service.ListPipelineJobsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[pipeline_service.ListPipelineJobsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterator[pipeline_job.PipelineJob]: + for page in self.pages: + yield from page.pipeline_jobs + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListPipelineJobsAsyncPager: + """A pager for iterating through ``list_pipeline_jobs`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListPipelineJobsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``pipeline_jobs`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListPipelineJobs`` requests and continue to iterate + through the ``pipeline_jobs`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListPipelineJobsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., Awaitable[pipeline_service.ListPipelineJobsResponse]], + request: pipeline_service.ListPipelineJobsRequest, + response: pipeline_service.ListPipelineJobsResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListPipelineJobsRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListPipelineJobsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = pipeline_service.ListPipelineJobsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[pipeline_service.ListPipelineJobsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + + def __aiter__(self) -> AsyncIterator[pipeline_job.PipelineJob]: + async def async_generator(): + async for page in self.pages: + for response in page.pipeline_jobs: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) diff --git a/google/cloud/aiplatform_v1/services/pipeline_service/transports/__init__.py b/google/cloud/aiplatform_v1/services/pipeline_service/transports/__init__.py index c7a40586e8..7cf231f6c5 100644 --- a/google/cloud/aiplatform_v1/services/pipeline_service/transports/__init__.py +++ b/google/cloud/aiplatform_v1/services/pipeline_service/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1/services/pipeline_service/transports/base.py b/google/cloud/aiplatform_v1/services/pipeline_service/transports/base.py index 2a1fd56abe..a8fe08abb7 100644 --- a/google/cloud/aiplatform_v1/services/pipeline_service/transports/base.py +++ b/google/cloud/aiplatform_v1/services/pipeline_service/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,20 +15,26 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.api_core import operations_v1 # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore +from google.cloud.aiplatform_v1.types import pipeline_job +from google.cloud.aiplatform_v1.types import pipeline_job as gca_pipeline_job from google.cloud.aiplatform_v1.types import pipeline_service from google.cloud.aiplatform_v1.types import training_pipeline from google.cloud.aiplatform_v1.types import training_pipeline as gca_training_pipeline +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from google.protobuf import empty_pb2 # type: ignore @@ -41,17 +47,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - -_API_CORE_VERSION = google.api_core.__version__ - class PipelineServiceTransport(abc.ABC): """Abstract transport class for PipelineService.""" @@ -69,6 +64,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -92,16 +88,19 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -114,92 +113,88 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id ) - # Save the credentials. - self._credentials = credentials - - # TODO(busunkim): These two class methods are in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-api-core - # and google-auth are increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") - ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs - - # TODO: Remove this function once google-api-core >= 1.26.0 is required - @classmethod - def _get_self_signed_jwt_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Union[Optional[Sequence[str]], str]]: - """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" - - self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} - - if _API_CORE_VERSION and ( - packaging.version.parse(_API_CORE_VERSION) - >= packaging.version.parse("1.26.0") + # If the credentials are service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") ): - self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES - self_signed_jwt_kwargs["scopes"] = scopes - self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST - else: - self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES + credentials = credentials.with_always_use_jwt_access(True) - return self_signed_jwt_kwargs + # Save the credentials. + self._credentials = credentials def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { self.create_training_pipeline: gapic_v1.method.wrap_method( self.create_training_pipeline, - default_timeout=5.0, + default_timeout=None, client_info=client_info, ), self.get_training_pipeline: gapic_v1.method.wrap_method( self.get_training_pipeline, - default_timeout=5.0, + default_timeout=None, client_info=client_info, ), self.list_training_pipelines: gapic_v1.method.wrap_method( self.list_training_pipelines, - default_timeout=5.0, + default_timeout=None, client_info=client_info, ), self.delete_training_pipeline: gapic_v1.method.wrap_method( self.delete_training_pipeline, - default_timeout=5.0, + default_timeout=None, client_info=client_info, ), self.cancel_training_pipeline: gapic_v1.method.wrap_method( self.cancel_training_pipeline, - default_timeout=5.0, + default_timeout=None, + client_info=client_info, + ), + self.create_pipeline_job: gapic_v1.method.wrap_method( + self.create_pipeline_job, + default_timeout=None, + client_info=client_info, + ), + self.get_pipeline_job: gapic_v1.method.wrap_method( + self.get_pipeline_job, + default_timeout=None, + client_info=client_info, + ), + self.list_pipeline_jobs: gapic_v1.method.wrap_method( + self.list_pipeline_jobs, + default_timeout=None, + client_info=client_info, + ), + self.delete_pipeline_job: gapic_v1.method.wrap_method( + self.delete_pipeline_job, + default_timeout=None, + client_info=client_info, + ), + self.cancel_pipeline_job: gapic_v1.method.wrap_method( + self.cancel_pipeline_job, + default_timeout=None, client_info=client_info, ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() @@ -257,5 +252,150 @@ def cancel_training_pipeline( ]: raise NotImplementedError() + @property + def create_pipeline_job( + self, + ) -> Callable[ + [pipeline_service.CreatePipelineJobRequest], + Union[gca_pipeline_job.PipelineJob, Awaitable[gca_pipeline_job.PipelineJob]], + ]: + raise NotImplementedError() + + @property + def get_pipeline_job( + self, + ) -> Callable[ + [pipeline_service.GetPipelineJobRequest], + Union[pipeline_job.PipelineJob, Awaitable[pipeline_job.PipelineJob]], + ]: + raise NotImplementedError() + + @property + def list_pipeline_jobs( + self, + ) -> Callable[ + [pipeline_service.ListPipelineJobsRequest], + Union[ + pipeline_service.ListPipelineJobsResponse, + Awaitable[pipeline_service.ListPipelineJobsResponse], + ], + ]: + raise NotImplementedError() + + @property + def delete_pipeline_job( + self, + ) -> Callable[ + [pipeline_service.DeletePipelineJobRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def cancel_pipeline_job( + self, + ) -> Callable[ + [pipeline_service.CancelPipelineJobRequest], + Union[empty_pb2.Empty, Awaitable[empty_pb2.Empty]], + ]: + raise NotImplementedError() + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], + Union[ + operations_pb2.ListOperationsResponse, + Awaitable[operations_pb2.ListOperationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None,]: + raise NotImplementedError() + + @property + def wait_operation( + self, + ) -> Callable[ + [operations_pb2.WaitOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def set_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def get_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_location( + self, + ) -> Callable[ + [locations_pb2.GetLocationRequest], + Union[locations_pb2.Location, Awaitable[locations_pb2.Location]], + ]: + raise NotImplementedError() + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], + Union[ + locations_pb2.ListLocationsResponse, + Awaitable[locations_pb2.ListLocationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + __all__ = ("PipelineServiceTransport",) diff --git a/google/cloud/aiplatform_v1/services/pipeline_service/transports/grpc.py b/google/cloud/aiplatform_v1/services/pipeline_service/transports/grpc.py index 9c86da69d3..542fe8571e 100644 --- a/google/cloud/aiplatform_v1/services/pipeline_service/transports/grpc.py +++ b/google/cloud/aiplatform_v1/services/pipeline_service/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,18 +16,24 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import operations_v1 +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore import grpc # type: ignore +from google.cloud.aiplatform_v1.types import pipeline_job +from google.cloud.aiplatform_v1.types import pipeline_job as gca_pipeline_job from google.cloud.aiplatform_v1.types import pipeline_service from google.cloud.aiplatform_v1.types import training_pipeline from google.cloud.aiplatform_v1.types import training_pipeline as gca_training_pipeline +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from google.protobuf import empty_pb2 # type: ignore from .base import PipelineServiceTransport, DEFAULT_CLIENT_INFO @@ -36,7 +42,10 @@ class PipelineServiceGrpcTransport(PipelineServiceTransport): """gRPC backend transport for PipelineService. - A service for creating and managing AI Platform's pipelines. + A service for creating and managing Vertex AI's pipelines. This + includes both ``TrainingPipeline`` resources (used for AutoML and + custom training) and ``PipelineJob`` resources (used for Vertex AI + Pipelines). This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation @@ -62,6 +71,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -84,16 +94,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -102,6 +112,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport @@ -112,7 +124,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -155,13 +167,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -210,21 +226,20 @@ def create_channel( and ``credentials_file`` are passed. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @property def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ + """Return the channel designed to connect to this service.""" return self._grpc_channel @property @@ -234,7 +249,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsClient(self.grpc_channel) @@ -395,5 +410,365 @@ def cancel_training_pipeline( ) return self._stubs["cancel_training_pipeline"] + @property + def create_pipeline_job( + self, + ) -> Callable[ + [pipeline_service.CreatePipelineJobRequest], gca_pipeline_job.PipelineJob + ]: + r"""Return a callable for the create pipeline job method over gRPC. + + Creates a PipelineJob. A PipelineJob will run + immediately when created. + + Returns: + Callable[[~.CreatePipelineJobRequest], + ~.PipelineJob]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_pipeline_job" not in self._stubs: + self._stubs["create_pipeline_job"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.PipelineService/CreatePipelineJob", + request_serializer=pipeline_service.CreatePipelineJobRequest.serialize, + response_deserializer=gca_pipeline_job.PipelineJob.deserialize, + ) + return self._stubs["create_pipeline_job"] + + @property + def get_pipeline_job( + self, + ) -> Callable[[pipeline_service.GetPipelineJobRequest], pipeline_job.PipelineJob]: + r"""Return a callable for the get pipeline job method over gRPC. + + Gets a PipelineJob. + + Returns: + Callable[[~.GetPipelineJobRequest], + ~.PipelineJob]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_pipeline_job" not in self._stubs: + self._stubs["get_pipeline_job"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.PipelineService/GetPipelineJob", + request_serializer=pipeline_service.GetPipelineJobRequest.serialize, + response_deserializer=pipeline_job.PipelineJob.deserialize, + ) + return self._stubs["get_pipeline_job"] + + @property + def list_pipeline_jobs( + self, + ) -> Callable[ + [pipeline_service.ListPipelineJobsRequest], + pipeline_service.ListPipelineJobsResponse, + ]: + r"""Return a callable for the list pipeline jobs method over gRPC. + + Lists PipelineJobs in a Location. + + Returns: + Callable[[~.ListPipelineJobsRequest], + ~.ListPipelineJobsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_pipeline_jobs" not in self._stubs: + self._stubs["list_pipeline_jobs"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.PipelineService/ListPipelineJobs", + request_serializer=pipeline_service.ListPipelineJobsRequest.serialize, + response_deserializer=pipeline_service.ListPipelineJobsResponse.deserialize, + ) + return self._stubs["list_pipeline_jobs"] + + @property + def delete_pipeline_job( + self, + ) -> Callable[ + [pipeline_service.DeletePipelineJobRequest], operations_pb2.Operation + ]: + r"""Return a callable for the delete pipeline job method over gRPC. + + Deletes a PipelineJob. + + Returns: + Callable[[~.DeletePipelineJobRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_pipeline_job" not in self._stubs: + self._stubs["delete_pipeline_job"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.PipelineService/DeletePipelineJob", + request_serializer=pipeline_service.DeletePipelineJobRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_pipeline_job"] + + @property + def cancel_pipeline_job( + self, + ) -> Callable[[pipeline_service.CancelPipelineJobRequest], empty_pb2.Empty]: + r"""Return a callable for the cancel pipeline job method over gRPC. + + Cancels a PipelineJob. Starts asynchronous cancellation on the + PipelineJob. The server makes a best effort to cancel the + pipeline, but success is not guaranteed. Clients can use + [PipelineService.GetPipelineJob][google.cloud.aiplatform.v1.PipelineService.GetPipelineJob] + or other methods to check whether the cancellation succeeded or + whether the pipeline completed despite cancellation. On + successful cancellation, the PipelineJob is not deleted; instead + it becomes a pipeline with a + [PipelineJob.error][google.cloud.aiplatform.v1.PipelineJob.error] + value with a [google.rpc.Status.code][google.rpc.Status.code] of + 1, corresponding to ``Code.CANCELLED``, and + [PipelineJob.state][google.cloud.aiplatform.v1.PipelineJob.state] + is set to ``CANCELLED``. + + Returns: + Callable[[~.CancelPipelineJobRequest], + ~.Empty]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_pipeline_job" not in self._stubs: + self._stubs["cancel_pipeline_job"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.PipelineService/CancelPipelineJob", + request_serializer=pipeline_service.CancelPipelineJobRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs["cancel_pipeline_job"] + + def close(self): + self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + @property + def kind(self) -> str: + return "grpc" + __all__ = ("PipelineServiceGrpcTransport",) diff --git a/google/cloud/aiplatform_v1/services/pipeline_service/transports/grpc_asyncio.py b/google/cloud/aiplatform_v1/services/pipeline_service/transports/grpc_asyncio.py index 98ee8ec8c2..a8a4588c14 100644 --- a/google/cloud/aiplatform_v1/services/pipeline_service/transports/grpc_asyncio.py +++ b/google/cloud/aiplatform_v1/services/pipeline_service/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,19 +16,24 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore -from google.api_core import operations_v1 # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore +from google.cloud.aiplatform_v1.types import pipeline_job +from google.cloud.aiplatform_v1.types import pipeline_job as gca_pipeline_job from google.cloud.aiplatform_v1.types import pipeline_service from google.cloud.aiplatform_v1.types import training_pipeline from google.cloud.aiplatform_v1.types import training_pipeline as gca_training_pipeline +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from google.protobuf import empty_pb2 # type: ignore from .base import PipelineServiceTransport, DEFAULT_CLIENT_INFO @@ -38,7 +43,10 @@ class PipelineServiceGrpcAsyncIOTransport(PipelineServiceTransport): """gRPC AsyncIO backend transport for PipelineService. - A service for creating and managing AI Platform's pipelines. + A service for creating and managing Vertex AI's pipelines. This + includes both ``TrainingPipeline`` resources (used for AutoML and + custom training) and ``PipelineJob`` resources (used for Vertex AI + Pipelines). This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation @@ -83,14 +91,14 @@ def create_channel( aio.Channel: A gRPC AsyncIO channel object. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @@ -108,6 +116,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -131,16 +140,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -149,6 +158,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport @@ -159,7 +170,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -201,13 +212,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -237,7 +252,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel @@ -403,5 +418,366 @@ def cancel_training_pipeline( ) return self._stubs["cancel_training_pipeline"] + @property + def create_pipeline_job( + self, + ) -> Callable[ + [pipeline_service.CreatePipelineJobRequest], + Awaitable[gca_pipeline_job.PipelineJob], + ]: + r"""Return a callable for the create pipeline job method over gRPC. + + Creates a PipelineJob. A PipelineJob will run + immediately when created. + + Returns: + Callable[[~.CreatePipelineJobRequest], + Awaitable[~.PipelineJob]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_pipeline_job" not in self._stubs: + self._stubs["create_pipeline_job"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.PipelineService/CreatePipelineJob", + request_serializer=pipeline_service.CreatePipelineJobRequest.serialize, + response_deserializer=gca_pipeline_job.PipelineJob.deserialize, + ) + return self._stubs["create_pipeline_job"] + + @property + def get_pipeline_job( + self, + ) -> Callable[ + [pipeline_service.GetPipelineJobRequest], Awaitable[pipeline_job.PipelineJob] + ]: + r"""Return a callable for the get pipeline job method over gRPC. + + Gets a PipelineJob. + + Returns: + Callable[[~.GetPipelineJobRequest], + Awaitable[~.PipelineJob]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_pipeline_job" not in self._stubs: + self._stubs["get_pipeline_job"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.PipelineService/GetPipelineJob", + request_serializer=pipeline_service.GetPipelineJobRequest.serialize, + response_deserializer=pipeline_job.PipelineJob.deserialize, + ) + return self._stubs["get_pipeline_job"] + + @property + def list_pipeline_jobs( + self, + ) -> Callable[ + [pipeline_service.ListPipelineJobsRequest], + Awaitable[pipeline_service.ListPipelineJobsResponse], + ]: + r"""Return a callable for the list pipeline jobs method over gRPC. + + Lists PipelineJobs in a Location. + + Returns: + Callable[[~.ListPipelineJobsRequest], + Awaitable[~.ListPipelineJobsResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_pipeline_jobs" not in self._stubs: + self._stubs["list_pipeline_jobs"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.PipelineService/ListPipelineJobs", + request_serializer=pipeline_service.ListPipelineJobsRequest.serialize, + response_deserializer=pipeline_service.ListPipelineJobsResponse.deserialize, + ) + return self._stubs["list_pipeline_jobs"] + + @property + def delete_pipeline_job( + self, + ) -> Callable[ + [pipeline_service.DeletePipelineJobRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the delete pipeline job method over gRPC. + + Deletes a PipelineJob. + + Returns: + Callable[[~.DeletePipelineJobRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_pipeline_job" not in self._stubs: + self._stubs["delete_pipeline_job"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.PipelineService/DeletePipelineJob", + request_serializer=pipeline_service.DeletePipelineJobRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_pipeline_job"] + + @property + def cancel_pipeline_job( + self, + ) -> Callable[ + [pipeline_service.CancelPipelineJobRequest], Awaitable[empty_pb2.Empty] + ]: + r"""Return a callable for the cancel pipeline job method over gRPC. + + Cancels a PipelineJob. Starts asynchronous cancellation on the + PipelineJob. The server makes a best effort to cancel the + pipeline, but success is not guaranteed. Clients can use + [PipelineService.GetPipelineJob][google.cloud.aiplatform.v1.PipelineService.GetPipelineJob] + or other methods to check whether the cancellation succeeded or + whether the pipeline completed despite cancellation. On + successful cancellation, the PipelineJob is not deleted; instead + it becomes a pipeline with a + [PipelineJob.error][google.cloud.aiplatform.v1.PipelineJob.error] + value with a [google.rpc.Status.code][google.rpc.Status.code] of + 1, corresponding to ``Code.CANCELLED``, and + [PipelineJob.state][google.cloud.aiplatform.v1.PipelineJob.state] + is set to ``CANCELLED``. + + Returns: + Callable[[~.CancelPipelineJobRequest], + Awaitable[~.Empty]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_pipeline_job" not in self._stubs: + self._stubs["cancel_pipeline_job"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.PipelineService/CancelPipelineJob", + request_serializer=pipeline_service.CancelPipelineJobRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs["cancel_pipeline_job"] + + def close(self): + return self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + __all__ = ("PipelineServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/aiplatform_v1/services/prediction_service/__init__.py b/google/cloud/aiplatform_v1/services/prediction_service/__init__.py index 12491bb171..d5ecd0dd03 100644 --- a/google/cloud/aiplatform_v1/services/prediction_service/__init__.py +++ b/google/cloud/aiplatform_v1/services/prediction_service/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1/services/prediction_service/async_client.py b/google/cloud/aiplatform_v1/services/prediction_service/async_client.py index bec5e54ea1..10ad298f35 100644 --- a/google/cloud/aiplatform_v1/services/prediction_service/async_client.py +++ b/google/cloud/aiplatform_v1/services/prediction_service/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,17 +16,29 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + +from google.api import httpbody_pb2 # type: ignore +from google.cloud.aiplatform_v1.types import explanation from google.cloud.aiplatform_v1.types import prediction_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.protobuf import any_pb2 # type: ignore from google.protobuf import struct_pb2 # type: ignore from .transports.base import PredictionServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import PredictionServiceGrpcAsyncIOTransport @@ -43,6 +55,8 @@ class PredictionServiceAsyncClient: endpoint_path = staticmethod(PredictionServiceClient.endpoint_path) parse_endpoint_path = staticmethod(PredictionServiceClient.parse_endpoint_path) + model_path = staticmethod(PredictionServiceClient.model_path) + parse_model_path = staticmethod(PredictionServiceClient.parse_model_path) common_billing_account_path = staticmethod( PredictionServiceClient.common_billing_account_path ) @@ -70,7 +84,8 @@ class PredictionServiceAsyncClient: @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -85,7 +100,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -100,9 +115,45 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return PredictionServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> PredictionServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: PredictionServiceTransport: The transport used by the client instance. @@ -121,7 +172,7 @@ def __init__( client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the prediction service client. + """Instantiates the prediction service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -162,19 +213,42 @@ def __init__( async def predict( self, - request: prediction_service.PredictRequest = None, + request: Union[prediction_service.PredictRequest, dict] = None, *, endpoint: str = None, instances: Sequence[struct_pb2.Value] = None, parameters: struct_pb2.Value = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> prediction_service.PredictResponse: r"""Perform an online prediction. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_predict(): + # Create a client + client = aiplatform_v1.PredictionServiceAsyncClient() + + # Initialize request argument(s) + instances = aiplatform_v1.Value() + instances.null_value = "NULL_VALUE" + + request = aiplatform_v1.PredictRequest( + endpoint="endpoint_value", + instances=instances, + ) + + # Make the request + response = await client.predict(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.PredictRequest`): + request (Union[google.cloud.aiplatform_v1.types.PredictRequest, dict]): The request object. Request message for [PredictionService.Predict][google.cloud.aiplatform.v1.PredictionService.Predict]. endpoint (:class:`str`): @@ -225,7 +299,7 @@ async def predict( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([endpoint, instances, parameters]) if request is not None and has_flattened_params: @@ -249,7 +323,186 @@ async def predict( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.predict, - default_timeout=5.0, + default_timeout=None, + 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((("endpoint", request.endpoint),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def raw_predict( + self, + request: Union[prediction_service.RawPredictRequest, dict] = None, + *, + endpoint: str = None, + http_body: httpbody_pb2.HttpBody = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> httpbody_pb2.HttpBody: + r"""Perform an online prediction with an arbitrary HTTP payload. + + The response includes the following HTTP headers: + + - ``X-Vertex-AI-Endpoint-Id``: ID of the + [Endpoint][google.cloud.aiplatform.v1.Endpoint] that served + this prediction. + + - ``X-Vertex-AI-Deployed-Model-Id``: ID of the Endpoint's + [DeployedModel][google.cloud.aiplatform.v1.DeployedModel] + that served this prediction. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_raw_predict(): + # Create a client + client = aiplatform_v1.PredictionServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.RawPredictRequest( + endpoint="endpoint_value", + ) + + # Make the request + response = await client.raw_predict(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.RawPredictRequest, dict]): + The request object. Request message for + [PredictionService.RawPredict][google.cloud.aiplatform.v1.PredictionService.RawPredict]. + endpoint (:class:`str`): + Required. The name of the Endpoint requested to serve + the prediction. Format: + ``projects/{project}/locations/{location}/endpoints/{endpoint}`` + + This corresponds to the ``endpoint`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + http_body (:class:`google.api.httpbody_pb2.HttpBody`): + The prediction input. Supports HTTP headers and + arbitrary data payload. + + A + [DeployedModel][google.cloud.aiplatform.v1.DeployedModel] + may have an upper limit on the number of instances it + supports per request. When this limit it is exceeded for + an AutoML model, the + [RawPredict][google.cloud.aiplatform.v1.PredictionService.RawPredict] + method returns an error. When this limit is exceeded for + a custom-trained model, the behavior varies depending on + the model. + + You can specify the schema for each instance in the + [predict_schemata.instance_schema_uri][google.cloud.aiplatform.v1.PredictSchemata.instance_schema_uri] + field when you create a + [Model][google.cloud.aiplatform.v1.Model]. This schema + applies when you deploy the ``Model`` as a + ``DeployedModel`` to an + [Endpoint][google.cloud.aiplatform.v1.Endpoint] and use + the ``RawPredict`` method. + + This corresponds to the ``http_body`` 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: + google.api.httpbody_pb2.HttpBody: + Message that represents an arbitrary HTTP body. It should only be used for + payload formats that can't be represented as JSON, + such as raw binary or an HTML page. + + This message can be used both in streaming and + non-streaming API methods in the request as well as + the response. + + It can be used as a top-level request field, which is + convenient if one wants to extract parameters from + either the URL or HTTP template into the request + fields and also want access to the raw HTTP body. + + Example: + + message GetResourceRequest { + // A unique request id. string request_id = 1; + + // The raw HTTP body is bound to this field. + google.api.HttpBody http_body = 2; + + } + + service ResourceService { + rpc GetResource(GetResourceRequest) + returns (google.api.HttpBody); + + rpc UpdateResource(google.api.HttpBody) + returns (google.protobuf.Empty); + + } + + Example with streaming methods: + + service CaldavService { + rpc GetCalendar(stream google.api.HttpBody) + returns (stream google.api.HttpBody); + + rpc UpdateCalendar(stream google.api.HttpBody) + returns (stream google.api.HttpBody); + + } + + Use of this type only changes how the request and + response bodies are handled, all other features will + continue to work unchanged. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([endpoint, http_body]) + 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 = prediction_service.RawPredictRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if endpoint is not None: + request.endpoint = endpoint + if http_body is not None: + request.http_body = http_body + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.raw_predict, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -260,11 +513,848 @@ async def predict( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response + async def explain( + self, + request: Union[prediction_service.ExplainRequest, dict] = None, + *, + endpoint: str = None, + instances: Sequence[struct_pb2.Value] = None, + parameters: struct_pb2.Value = None, + deployed_model_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> prediction_service.ExplainResponse: + r"""Perform an online explanation. + + If + [deployed_model_id][google.cloud.aiplatform.v1.ExplainRequest.deployed_model_id] + is specified, the corresponding DeployModel must have + [explanation_spec][google.cloud.aiplatform.v1.DeployedModel.explanation_spec] + populated. If + [deployed_model_id][google.cloud.aiplatform.v1.ExplainRequest.deployed_model_id] + is not specified, all DeployedModels must have + [explanation_spec][google.cloud.aiplatform.v1.DeployedModel.explanation_spec] + populated. Only deployed AutoML tabular Models have + explanation_spec. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_explain(): + # Create a client + client = aiplatform_v1.PredictionServiceAsyncClient() + + # Initialize request argument(s) + instances = aiplatform_v1.Value() + instances.null_value = "NULL_VALUE" + + request = aiplatform_v1.ExplainRequest( + endpoint="endpoint_value", + instances=instances, + ) + + # Make the request + response = await client.explain(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ExplainRequest, dict]): + The request object. Request message for + [PredictionService.Explain][google.cloud.aiplatform.v1.PredictionService.Explain]. + endpoint (:class:`str`): + Required. The name of the Endpoint requested to serve + the explanation. Format: + ``projects/{project}/locations/{location}/endpoints/{endpoint}`` + + This corresponds to the ``endpoint`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + instances (:class:`Sequence[google.protobuf.struct_pb2.Value]`): + Required. The instances that are the input to the + explanation call. A DeployedModel may have an upper + limit on the number of instances it supports per + request, and when it is exceeded the explanation call + errors in case of AutoML Models, or, in case of customer + created Models, the behaviour is as documented by that + Model. The schema of any single instance may be + specified via Endpoint's DeployedModels' + [Model's][google.cloud.aiplatform.v1.DeployedModel.model] + [PredictSchemata's][google.cloud.aiplatform.v1.Model.predict_schemata] + [instance_schema_uri][google.cloud.aiplatform.v1.PredictSchemata.instance_schema_uri]. + + This corresponds to the ``instances`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + parameters (:class:`google.protobuf.struct_pb2.Value`): + The parameters that govern the prediction. The schema of + the parameters may be specified via Endpoint's + DeployedModels' [Model's + ][google.cloud.aiplatform.v1.DeployedModel.model] + [PredictSchemata's][google.cloud.aiplatform.v1.Model.predict_schemata] + [parameters_schema_uri][google.cloud.aiplatform.v1.PredictSchemata.parameters_schema_uri]. + + This corresponds to the ``parameters`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + deployed_model_id (:class:`str`): + If specified, this ExplainRequest will be served by the + chosen DeployedModel, overriding + [Endpoint.traffic_split][google.cloud.aiplatform.v1.Endpoint.traffic_split]. + + This corresponds to the ``deployed_model_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: + google.cloud.aiplatform_v1.types.ExplainResponse: + Response message for + [PredictionService.Explain][google.cloud.aiplatform.v1.PredictionService.Explain]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([endpoint, instances, parameters, deployed_model_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 = prediction_service.ExplainRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if endpoint is not None: + request.endpoint = endpoint + if parameters is not None: + request.parameters = parameters + if deployed_model_id is not None: + request.deployed_model_id = deployed_model_id + if instances: + request.instances.extend(instances) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.explain, + default_timeout=None, + 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((("endpoint", request.endpoint),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_operations, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.delete_operation, + default_timeout=None, + 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 cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + 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 wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.wait_operation, + default_timeout=None, + 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 set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_location, + default_timeout=None, + 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 list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_locations, + default_timeout=None, + 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 __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/aiplatform_v1/services/prediction_service/client.py b/google/cloud/aiplatform_v1/services/prediction_service/client.py index 2bbfba4c5c..45ca16a401 100644 --- a/google/cloud/aiplatform_v1/services/prediction_service/client.py +++ b/google/cloud/aiplatform_v1/services/prediction_service/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,23 +14,34 @@ # 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 +from typing import Dict, Mapping, 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 as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_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 +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + +from google.api import httpbody_pb2 # type: ignore +from google.cloud.aiplatform_v1.types import explanation from google.cloud.aiplatform_v1.types import prediction_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.protobuf import any_pb2 # type: ignore from google.protobuf import struct_pb2 # type: ignore from .transports.base import PredictionServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc import PredictionServiceGrpcTransport @@ -52,9 +63,10 @@ class PredictionServiceClientMeta(type): _transport_registry["grpc_asyncio"] = PredictionServiceGrpcAsyncIOTransport def get_transport_class( - cls, label: str = None, + cls, + label: str = None, ) -> Type[PredictionServiceTransport]: - """Return an appropriate transport class. + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -77,7 +89,8 @@ class PredictionServiceClient(metaclass=PredictionServiceClientMeta): @staticmethod def _get_default_mtls_endpoint(api_endpoint): - """Convert api endpoint to mTLS endpoint. + """Converts api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. Args: @@ -111,7 +124,8 @@ def _get_default_mtls_endpoint(api_endpoint): @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -128,7 +142,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -147,23 +161,30 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> PredictionServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - PredictionServiceTransport: The transport used by the client instance. + PredictionServiceTransport: The transport used by the client + instance. """ return self._transport @staticmethod - def endpoint_path(project: str, location: str, endpoint: str,) -> str: - """Return a fully-qualified endpoint string.""" + def endpoint_path( + project: str, + location: str, + endpoint: str, + ) -> str: + """Returns a fully-qualified endpoint string.""" return "projects/{project}/locations/{location}/endpoints/{endpoint}".format( - project=project, location=location, endpoint=endpoint, + project=project, + location=location, + endpoint=endpoint, ) @staticmethod def parse_endpoint_path(path: str) -> Dict[str, str]: - """Parse a endpoint path into its component segments.""" + """Parses a endpoint path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/endpoints/(?P.+?)$", path, @@ -171,8 +192,32 @@ def parse_endpoint_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + def model_path( + project: str, + location: str, + model: str, + ) -> str: + """Returns a fully-qualified model string.""" + return "projects/{project}/locations/{location}/models/{model}".format( + project=project, + location=location, + model=model, + ) + + @staticmethod + def parse_model_path(path: str) -> Dict[str, str]: + """Parses a model path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/models/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def common_billing_account_path( + billing_account: str, + ) -> str: + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -184,9 +229,13 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: 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,) + def common_folder_path( + folder: str, + ) -> str: + """Returns a fully-qualified folder string.""" + return "folders/{folder}".format( + folder=folder, + ) @staticmethod def parse_common_folder_path(path: str) -> Dict[str, str]: @@ -195,9 +244,13 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: 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,) + def common_organization_path( + organization: str, + ) -> str: + """Returns a fully-qualified organization string.""" + return "organizations/{organization}".format( + organization=organization, + ) @staticmethod def parse_common_organization_path(path: str) -> Dict[str, str]: @@ -206,9 +259,13 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: 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,) + def common_project_path( + project: str, + ) -> str: + """Returns a fully-qualified project string.""" + return "projects/{project}".format( + project=project, + ) @staticmethod def parse_common_project_path(path: str) -> Dict[str, str]: @@ -217,10 +274,14 @@ def parse_common_project_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_location_path(project: str, location: str,) -> str: - """Return a fully-qualified location string.""" + def common_location_path( + project: str, + location: str, + ) -> str: + """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) @staticmethod @@ -229,6 +290,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + def __init__( self, *, @@ -237,7 +365,7 @@ def __init__( client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the prediction service client. + """Instantiates the prediction service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -279,58 +407,42 @@ def __init__( 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")) + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - client_cert_source_func = ( - mtls.default_client_cert_source() 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" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # 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, PredictionServiceTransport): # transport is a PredictionServiceTransport instance. - if credentials or client_options.credentials_file: + if credentials or client_options.credentials_file or api_key_value: 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." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + Transport = type(self).get_transport_class(transport) self._transport = Transport( credentials=credentials, @@ -340,23 +452,47 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, + always_use_jwt_access=True, ) def predict( self, - request: prediction_service.PredictRequest = None, + request: Union[prediction_service.PredictRequest, dict] = None, *, endpoint: str = None, instances: Sequence[struct_pb2.Value] = None, parameters: struct_pb2.Value = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> prediction_service.PredictResponse: r"""Perform an online prediction. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_predict(): + # Create a client + client = aiplatform_v1.PredictionServiceClient() + + # Initialize request argument(s) + instances = aiplatform_v1.Value() + instances.null_value = "NULL_VALUE" + + request = aiplatform_v1.PredictRequest( + endpoint="endpoint_value", + instances=instances, + ) + + # Make the request + response = client.predict(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1.types.PredictRequest): + request (Union[google.cloud.aiplatform_v1.types.PredictRequest, dict]): The request object. Request message for [PredictionService.Predict][google.cloud.aiplatform.v1.PredictionService.Predict]. endpoint (str): @@ -407,7 +543,7 @@ def predict( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([endpoint, instances, parameters]) if request is not None and has_flattened_params: @@ -442,7 +578,1030 @@ def predict( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def raw_predict( + self, + request: Union[prediction_service.RawPredictRequest, dict] = None, + *, + endpoint: str = None, + http_body: httpbody_pb2.HttpBody = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> httpbody_pb2.HttpBody: + r"""Perform an online prediction with an arbitrary HTTP payload. + + The response includes the following HTTP headers: + + - ``X-Vertex-AI-Endpoint-Id``: ID of the + [Endpoint][google.cloud.aiplatform.v1.Endpoint] that served + this prediction. + + - ``X-Vertex-AI-Deployed-Model-Id``: ID of the Endpoint's + [DeployedModel][google.cloud.aiplatform.v1.DeployedModel] + that served this prediction. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_raw_predict(): + # Create a client + client = aiplatform_v1.PredictionServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.RawPredictRequest( + endpoint="endpoint_value", + ) + + # Make the request + response = client.raw_predict(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.RawPredictRequest, dict]): + The request object. Request message for + [PredictionService.RawPredict][google.cloud.aiplatform.v1.PredictionService.RawPredict]. + endpoint (str): + Required. The name of the Endpoint requested to serve + the prediction. Format: + ``projects/{project}/locations/{location}/endpoints/{endpoint}`` + + This corresponds to the ``endpoint`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + http_body (google.api.httpbody_pb2.HttpBody): + The prediction input. Supports HTTP headers and + arbitrary data payload. + + A + [DeployedModel][google.cloud.aiplatform.v1.DeployedModel] + may have an upper limit on the number of instances it + supports per request. When this limit it is exceeded for + an AutoML model, the + [RawPredict][google.cloud.aiplatform.v1.PredictionService.RawPredict] + method returns an error. When this limit is exceeded for + a custom-trained model, the behavior varies depending on + the model. + + You can specify the schema for each instance in the + [predict_schemata.instance_schema_uri][google.cloud.aiplatform.v1.PredictSchemata.instance_schema_uri] + field when you create a + [Model][google.cloud.aiplatform.v1.Model]. This schema + applies when you deploy the ``Model`` as a + ``DeployedModel`` to an + [Endpoint][google.cloud.aiplatform.v1.Endpoint] and use + the ``RawPredict`` method. + + This corresponds to the ``http_body`` 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: + google.api.httpbody_pb2.HttpBody: + Message that represents an arbitrary HTTP body. It should only be used for + payload formats that can't be represented as JSON, + such as raw binary or an HTML page. + + This message can be used both in streaming and + non-streaming API methods in the request as well as + the response. + + It can be used as a top-level request field, which is + convenient if one wants to extract parameters from + either the URL or HTTP template into the request + fields and also want access to the raw HTTP body. + + Example: + + message GetResourceRequest { + // A unique request id. string request_id = 1; + + // The raw HTTP body is bound to this field. + google.api.HttpBody http_body = 2; + + } + + service ResourceService { + rpc GetResource(GetResourceRequest) + returns (google.api.HttpBody); + + rpc UpdateResource(google.api.HttpBody) + returns (google.protobuf.Empty); + + } + + Example with streaming methods: + + service CaldavService { + rpc GetCalendar(stream google.api.HttpBody) + returns (stream google.api.HttpBody); + + rpc UpdateCalendar(stream google.api.HttpBody) + returns (stream google.api.HttpBody); + + } + + Use of this type only changes how the request and + response bodies are handled, all other features will + continue to work unchanged. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([endpoint, http_body]) + 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 prediction_service.RawPredictRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, prediction_service.RawPredictRequest): + request = prediction_service.RawPredictRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if endpoint is not None: + request.endpoint = endpoint + if http_body is not None: + request.http_body = http_body + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.raw_predict] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("endpoint", request.endpoint),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def explain( + self, + request: Union[prediction_service.ExplainRequest, dict] = None, + *, + endpoint: str = None, + instances: Sequence[struct_pb2.Value] = None, + parameters: struct_pb2.Value = None, + deployed_model_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> prediction_service.ExplainResponse: + r"""Perform an online explanation. + + If + [deployed_model_id][google.cloud.aiplatform.v1.ExplainRequest.deployed_model_id] + is specified, the corresponding DeployModel must have + [explanation_spec][google.cloud.aiplatform.v1.DeployedModel.explanation_spec] + populated. If + [deployed_model_id][google.cloud.aiplatform.v1.ExplainRequest.deployed_model_id] + is not specified, all DeployedModels must have + [explanation_spec][google.cloud.aiplatform.v1.DeployedModel.explanation_spec] + populated. Only deployed AutoML tabular Models have + explanation_spec. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_explain(): + # Create a client + client = aiplatform_v1.PredictionServiceClient() + + # Initialize request argument(s) + instances = aiplatform_v1.Value() + instances.null_value = "NULL_VALUE" + + request = aiplatform_v1.ExplainRequest( + endpoint="endpoint_value", + instances=instances, + ) + + # Make the request + response = client.explain(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ExplainRequest, dict]): + The request object. Request message for + [PredictionService.Explain][google.cloud.aiplatform.v1.PredictionService.Explain]. + endpoint (str): + Required. The name of the Endpoint requested to serve + the explanation. Format: + ``projects/{project}/locations/{location}/endpoints/{endpoint}`` + + This corresponds to the ``endpoint`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + instances (Sequence[google.protobuf.struct_pb2.Value]): + Required. The instances that are the input to the + explanation call. A DeployedModel may have an upper + limit on the number of instances it supports per + request, and when it is exceeded the explanation call + errors in case of AutoML Models, or, in case of customer + created Models, the behaviour is as documented by that + Model. The schema of any single instance may be + specified via Endpoint's DeployedModels' + [Model's][google.cloud.aiplatform.v1.DeployedModel.model] + [PredictSchemata's][google.cloud.aiplatform.v1.Model.predict_schemata] + [instance_schema_uri][google.cloud.aiplatform.v1.PredictSchemata.instance_schema_uri]. + + This corresponds to the ``instances`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + parameters (google.protobuf.struct_pb2.Value): + The parameters that govern the prediction. The schema of + the parameters may be specified via Endpoint's + DeployedModels' [Model's + ][google.cloud.aiplatform.v1.DeployedModel.model] + [PredictSchemata's][google.cloud.aiplatform.v1.Model.predict_schemata] + [parameters_schema_uri][google.cloud.aiplatform.v1.PredictSchemata.parameters_schema_uri]. + + This corresponds to the ``parameters`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + deployed_model_id (str): + If specified, this ExplainRequest will be served by the + chosen DeployedModel, overriding + [Endpoint.traffic_split][google.cloud.aiplatform.v1.Endpoint.traffic_split]. + + This corresponds to the ``deployed_model_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: + google.cloud.aiplatform_v1.types.ExplainResponse: + Response message for + [PredictionService.Explain][google.cloud.aiplatform.v1.PredictionService.Explain]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([endpoint, instances, parameters, deployed_model_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 prediction_service.ExplainRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, prediction_service.ExplainRequest): + request = prediction_service.ExplainRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if endpoint is not None: + request.endpoint = endpoint + if instances is not None: + request.instances.extend(instances) + if parameters is not None: + request.parameters = parameters + if deployed_model_id is not None: + request.deployed_model_id = deployed_model_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.explain] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("endpoint", request.endpoint),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_operations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.delete_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.wait_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_location, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_locations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response diff --git a/google/cloud/aiplatform_v1/services/prediction_service/transports/__init__.py b/google/cloud/aiplatform_v1/services/prediction_service/transports/__init__.py index 86d2e8a7f3..3b81984dc0 100644 --- a/google/cloud/aiplatform_v1/services/prediction_service/transports/__init__.py +++ b/google/cloud/aiplatform_v1/services/prediction_service/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1/services/prediction_service/transports/base.py b/google/cloud/aiplatform_v1/services/prediction_service/transports/base.py index 804afddd08..dcda4b5987 100644 --- a/google/cloud/aiplatform_v1/services/prediction_service/transports/base.py +++ b/google/cloud/aiplatform_v1/services/prediction_service/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,17 +15,22 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore +from google.api import httpbody_pb2 # type: ignore from google.cloud.aiplatform_v1.types import prediction_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( @@ -36,17 +41,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - -_API_CORE_VERSION = google.api_core.__version__ - class PredictionServiceTransport(abc.ABC): """Abstract transport class for PredictionService.""" @@ -64,6 +58,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -87,16 +82,19 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -109,68 +107,51 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id ) - # Save the credentials. - self._credentials = credentials - - # TODO(busunkim): These two class methods are in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-api-core - # and google-auth are increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") - ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs - - # TODO: Remove this function once google-api-core >= 1.26.0 is required - @classmethod - def _get_self_signed_jwt_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Union[Optional[Sequence[str]], str]]: - """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" - - self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} - - if _API_CORE_VERSION and ( - packaging.version.parse(_API_CORE_VERSION) - >= packaging.version.parse("1.26.0") + # If the credentials are service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") ): - self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES - self_signed_jwt_kwargs["scopes"] = scopes - self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST - else: - self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES + credentials = credentials.with_always_use_jwt_access(True) - return self_signed_jwt_kwargs + # Save the credentials. + self._credentials = credentials def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { self.predict: gapic_v1.method.wrap_method( - self.predict, default_timeout=5.0, client_info=client_info, + self.predict, + default_timeout=None, + client_info=client_info, + ), + self.raw_predict: gapic_v1.method.wrap_method( + self.raw_predict, + default_timeout=None, + client_info=client_info, + ), + self.explain: gapic_v1.method.wrap_method( + self.explain, + default_timeout=None, + client_info=client_info, ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property def predict( self, @@ -183,5 +164,123 @@ def predict( ]: raise NotImplementedError() + @property + def raw_predict( + self, + ) -> Callable[ + [prediction_service.RawPredictRequest], + Union[httpbody_pb2.HttpBody, Awaitable[httpbody_pb2.HttpBody]], + ]: + raise NotImplementedError() + + @property + def explain( + self, + ) -> Callable[ + [prediction_service.ExplainRequest], + Union[ + prediction_service.ExplainResponse, + Awaitable[prediction_service.ExplainResponse], + ], + ]: + raise NotImplementedError() + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], + Union[ + operations_pb2.ListOperationsResponse, + Awaitable[operations_pb2.ListOperationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None,]: + raise NotImplementedError() + + @property + def wait_operation( + self, + ) -> Callable[ + [operations_pb2.WaitOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def set_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def get_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_location( + self, + ) -> Callable[ + [locations_pb2.GetLocationRequest], + Union[locations_pb2.Location, Awaitable[locations_pb2.Location]], + ]: + raise NotImplementedError() + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], + Union[ + locations_pb2.ListLocationsResponse, + Awaitable[locations_pb2.ListLocationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + __all__ = ("PredictionServiceTransport",) diff --git a/google/cloud/aiplatform_v1/services/prediction_service/transports/grpc.py b/google/cloud/aiplatform_v1/services/prediction_service/transports/grpc.py index 5c27627e00..6cec7be274 100644 --- a/google/cloud/aiplatform_v1/services/prediction_service/transports/grpc.py +++ b/google/cloud/aiplatform_v1/services/prediction_service/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,15 +16,20 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore import grpc # type: ignore +from google.api import httpbody_pb2 # type: ignore from google.cloud.aiplatform_v1.types import prediction_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from .base import PredictionServiceTransport, DEFAULT_CLIENT_INFO @@ -57,6 +62,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -79,16 +85,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -97,6 +103,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport @@ -149,13 +157,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -204,21 +216,20 @@ def create_channel( and ``credentials_file`` are passed. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @property def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ + """Return the channel designed to connect to this service.""" return self._grpc_channel @property @@ -249,5 +260,290 @@ def predict( ) return self._stubs["predict"] + @property + def raw_predict( + self, + ) -> Callable[[prediction_service.RawPredictRequest], httpbody_pb2.HttpBody]: + r"""Return a callable for the raw predict method over gRPC. + + Perform an online prediction with an arbitrary HTTP payload. + + The response includes the following HTTP headers: + + - ``X-Vertex-AI-Endpoint-Id``: ID of the + [Endpoint][google.cloud.aiplatform.v1.Endpoint] that served + this prediction. + + - ``X-Vertex-AI-Deployed-Model-Id``: ID of the Endpoint's + [DeployedModel][google.cloud.aiplatform.v1.DeployedModel] + that served this prediction. + + Returns: + Callable[[~.RawPredictRequest], + ~.HttpBody]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "raw_predict" not in self._stubs: + self._stubs["raw_predict"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.PredictionService/RawPredict", + request_serializer=prediction_service.RawPredictRequest.serialize, + response_deserializer=httpbody_pb2.HttpBody.FromString, + ) + return self._stubs["raw_predict"] + + @property + def explain( + self, + ) -> Callable[ + [prediction_service.ExplainRequest], prediction_service.ExplainResponse + ]: + r"""Return a callable for the explain method over gRPC. + + Perform an online explanation. + + If + [deployed_model_id][google.cloud.aiplatform.v1.ExplainRequest.deployed_model_id] + is specified, the corresponding DeployModel must have + [explanation_spec][google.cloud.aiplatform.v1.DeployedModel.explanation_spec] + populated. If + [deployed_model_id][google.cloud.aiplatform.v1.ExplainRequest.deployed_model_id] + is not specified, all DeployedModels must have + [explanation_spec][google.cloud.aiplatform.v1.DeployedModel.explanation_spec] + populated. Only deployed AutoML tabular Models have + explanation_spec. + + Returns: + Callable[[~.ExplainRequest], + ~.ExplainResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "explain" not in self._stubs: + self._stubs["explain"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.PredictionService/Explain", + request_serializer=prediction_service.ExplainRequest.serialize, + response_deserializer=prediction_service.ExplainResponse.deserialize, + ) + return self._stubs["explain"] + + def close(self): + self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + @property + def kind(self) -> str: + return "grpc" + __all__ = ("PredictionServiceGrpcTransport",) diff --git a/google/cloud/aiplatform_v1/services/prediction_service/transports/grpc_asyncio.py b/google/cloud/aiplatform_v1/services/prediction_service/transports/grpc_asyncio.py index e3c927de5b..89ef6d9055 100644 --- a/google/cloud/aiplatform_v1/services/prediction_service/transports/grpc_asyncio.py +++ b/google/cloud/aiplatform_v1/services/prediction_service/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,16 +16,20 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore +from google.api import httpbody_pb2 # type: ignore from google.cloud.aiplatform_v1.types import prediction_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from .base import PredictionServiceTransport, DEFAULT_CLIENT_INFO from .grpc import PredictionServiceGrpcTransport @@ -78,14 +82,14 @@ def create_channel( aio.Channel: A gRPC AsyncIO channel object. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @@ -103,6 +107,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -126,16 +131,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -144,6 +149,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport @@ -195,13 +202,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -253,5 +264,289 @@ def predict( ) return self._stubs["predict"] + @property + def raw_predict( + self, + ) -> Callable[ + [prediction_service.RawPredictRequest], Awaitable[httpbody_pb2.HttpBody] + ]: + r"""Return a callable for the raw predict method over gRPC. + + Perform an online prediction with an arbitrary HTTP payload. + + The response includes the following HTTP headers: + + - ``X-Vertex-AI-Endpoint-Id``: ID of the + [Endpoint][google.cloud.aiplatform.v1.Endpoint] that served + this prediction. + + - ``X-Vertex-AI-Deployed-Model-Id``: ID of the Endpoint's + [DeployedModel][google.cloud.aiplatform.v1.DeployedModel] + that served this prediction. + + Returns: + Callable[[~.RawPredictRequest], + Awaitable[~.HttpBody]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "raw_predict" not in self._stubs: + self._stubs["raw_predict"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.PredictionService/RawPredict", + request_serializer=prediction_service.RawPredictRequest.serialize, + response_deserializer=httpbody_pb2.HttpBody.FromString, + ) + return self._stubs["raw_predict"] + + @property + def explain( + self, + ) -> Callable[ + [prediction_service.ExplainRequest], + Awaitable[prediction_service.ExplainResponse], + ]: + r"""Return a callable for the explain method over gRPC. + + Perform an online explanation. + + If + [deployed_model_id][google.cloud.aiplatform.v1.ExplainRequest.deployed_model_id] + is specified, the corresponding DeployModel must have + [explanation_spec][google.cloud.aiplatform.v1.DeployedModel.explanation_spec] + populated. If + [deployed_model_id][google.cloud.aiplatform.v1.ExplainRequest.deployed_model_id] + is not specified, all DeployedModels must have + [explanation_spec][google.cloud.aiplatform.v1.DeployedModel.explanation_spec] + populated. Only deployed AutoML tabular Models have + explanation_spec. + + Returns: + Callable[[~.ExplainRequest], + Awaitable[~.ExplainResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "explain" not in self._stubs: + self._stubs["explain"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.PredictionService/Explain", + request_serializer=prediction_service.ExplainRequest.serialize, + response_deserializer=prediction_service.ExplainResponse.deserialize, + ) + return self._stubs["explain"] + + def close(self): + return self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + __all__ = ("PredictionServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/aiplatform_v1/services/specialist_pool_service/__init__.py b/google/cloud/aiplatform_v1/services/specialist_pool_service/__init__.py index dea5d1cc17..0f61e0cadc 100644 --- a/google/cloud/aiplatform_v1/services/specialist_pool_service/__init__.py +++ b/google/cloud/aiplatform_v1/services/specialist_pool_service/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1/services/specialist_pool_service/async_client.py b/google/cloud/aiplatform_v1/services/specialist_pool_service/async_client.py index 704ee2ab21..97ebd096bc 100644 --- a/google/cloud/aiplatform_v1/services/specialist_pool_service/async_client.py +++ b/google/cloud/aiplatform_v1/services/specialist_pool_service/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,16 +16,21 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation as gac_operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1.services.specialist_pool_service import pagers @@ -33,6 +38,10 @@ from google.cloud.aiplatform_v1.types import specialist_pool from google.cloud.aiplatform_v1.types import specialist_pool as gca_specialist_pool from google.cloud.aiplatform_v1.types import specialist_pool_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore from .transports.base import SpecialistPoolServiceTransport, DEFAULT_CLIENT_INFO @@ -89,7 +98,8 @@ class SpecialistPoolServiceAsyncClient: @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -104,7 +114,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -119,9 +129,45 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return SpecialistPoolServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> SpecialistPoolServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: SpecialistPoolServiceTransport: The transport used by the client instance. @@ -141,7 +187,7 @@ def __init__( client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the specialist pool service client. + """Instantiates the specialist pool service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -182,18 +228,48 @@ def __init__( async def create_specialist_pool( self, - request: specialist_pool_service.CreateSpecialistPoolRequest = None, + request: Union[ + specialist_pool_service.CreateSpecialistPoolRequest, dict + ] = None, *, parent: str = None, specialist_pool: gca_specialist_pool.SpecialistPool = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Creates a SpecialistPool. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_create_specialist_pool(): + # Create a client + client = aiplatform_v1.SpecialistPoolServiceAsyncClient() + + # Initialize request argument(s) + specialist_pool = aiplatform_v1.SpecialistPool() + specialist_pool.name = "name_value" + specialist_pool.display_name = "display_name_value" + + request = aiplatform_v1.CreateSpecialistPoolRequest( + parent="parent_value", + specialist_pool=specialist_pool, + ) + + # Make the request + operation = client.create_specialist_pool(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.CreateSpecialistPoolRequest`): + request (Union[google.cloud.aiplatform_v1.types.CreateSpecialistPoolRequest, dict]): The request object. Request message for [SpecialistPoolService.CreateSpecialistPool][google.cloud.aiplatform.v1.SpecialistPoolService.CreateSpecialistPool]. parent (:class:`str`): @@ -223,16 +299,16 @@ async def create_specialist_pool( The result type for the operation will be :class:`google.cloud.aiplatform_v1.types.SpecialistPool` SpecialistPool represents customers' own workforce to work on their data labeling jobs. It includes a group of specialist - managers who are responsible for managing the - labelers in this pool as well as customers' data - labeling jobs associated with this pool. Customers - create specialist pool as well as start data labeling - jobs on Cloud, managers and labelers work with the - jobs using CrowdCompute console. + managers and workers. Managers are responsible for + managing the workers in this pool as well as + customers' data labeling jobs associated with this + pool. Customers create specialist pool as well as + start data labeling jobs on Cloud, managers and + workers handle the jobs using CrowdCompute console. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, specialist_pool]) if request is not None and has_flattened_params: @@ -254,7 +330,7 @@ async def create_specialist_pool( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.create_specialist_pool, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -265,7 +341,12 @@ async def create_specialist_pool( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -280,23 +361,41 @@ async def create_specialist_pool( async def get_specialist_pool( self, - request: specialist_pool_service.GetSpecialistPoolRequest = None, + request: Union[specialist_pool_service.GetSpecialistPoolRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> specialist_pool.SpecialistPool: r"""Gets a SpecialistPool. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_get_specialist_pool(): + # Create a client + client = aiplatform_v1.SpecialistPoolServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetSpecialistPoolRequest( + name="name_value", + ) + + # Make the request + response = await client.get_specialist_pool(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.GetSpecialistPoolRequest`): + request (Union[google.cloud.aiplatform_v1.types.GetSpecialistPoolRequest, dict]): The request object. Request message for [SpecialistPoolService.GetSpecialistPool][google.cloud.aiplatform.v1.SpecialistPoolService.GetSpecialistPool]. name (:class:`str`): Required. The name of the SpecialistPool resource. The form is - ``projects/{project}/locations/{location}/specialistPools/{specialist_pool}``. This corresponds to the ``name`` field @@ -313,18 +412,19 @@ async def get_specialist_pool( SpecialistPool represents customers' own workforce to work on their data labeling jobs. It includes a group of - specialist managers who are responsible - for managing the labelers in this pool - as well as customers' data labeling jobs - associated with this pool. - Customers create specialist pool as well - as start data labeling jobs on Cloud, - managers and labelers work with the jobs - using CrowdCompute console. + specialist managers and workers. + Managers are responsible for managing + the workers in this pool as well as + customers' data labeling jobs associated + with this pool. Customers create + specialist pool as well as start data + labeling jobs on Cloud, managers and + workers handle the jobs using + CrowdCompute console. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -344,7 +444,7 @@ async def get_specialist_pool( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.get_specialist_pool, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -355,24 +455,49 @@ async def get_specialist_pool( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_specialist_pools( self, - request: specialist_pool_service.ListSpecialistPoolsRequest = None, + request: Union[specialist_pool_service.ListSpecialistPoolsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListSpecialistPoolsAsyncPager: r"""Lists SpecialistPools in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_list_specialist_pools(): + # Create a client + client = aiplatform_v1.SpecialistPoolServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListSpecialistPoolsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_specialist_pools(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.ListSpecialistPoolsRequest`): + request (Union[google.cloud.aiplatform_v1.types.ListSpecialistPoolsRequest, dict]): The request object. Request message for [SpecialistPoolService.ListSpecialistPools][google.cloud.aiplatform.v1.SpecialistPoolService.ListSpecialistPools]. parent (:class:`str`): @@ -399,7 +524,7 @@ async def list_specialist_pools( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -419,7 +544,7 @@ async def list_specialist_pools( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.list_specialist_pools, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -430,12 +555,20 @@ async def list_specialist_pools( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListSpecialistPoolsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -443,18 +576,43 @@ async def list_specialist_pools( async def delete_specialist_pool( self, - request: specialist_pool_service.DeleteSpecialistPoolRequest = None, + request: Union[ + specialist_pool_service.DeleteSpecialistPoolRequest, dict + ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a SpecialistPool as well as all Specialists in the pool. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_delete_specialist_pool(): + # Create a client + client = aiplatform_v1.SpecialistPoolServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteSpecialistPoolRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_specialist_pool(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.DeleteSpecialistPoolRequest`): + request (Union[google.cloud.aiplatform_v1.types.DeleteSpecialistPoolRequest, dict]): The request object. Request message for [SpecialistPoolService.DeleteSpecialistPool][google.cloud.aiplatform.v1.SpecialistPoolService.DeleteSpecialistPool]. name (:class:`str`): @@ -491,7 +649,7 @@ async def delete_specialist_pool( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -511,7 +669,7 @@ async def delete_specialist_pool( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.delete_specialist_pool, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -522,7 +680,12 @@ async def delete_specialist_pool( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -537,18 +700,47 @@ async def delete_specialist_pool( async def update_specialist_pool( self, - request: specialist_pool_service.UpdateSpecialistPoolRequest = None, + request: Union[ + specialist_pool_service.UpdateSpecialistPoolRequest, dict + ] = None, *, specialist_pool: gca_specialist_pool.SpecialistPool = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Updates a SpecialistPool. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_update_specialist_pool(): + # Create a client + client = aiplatform_v1.SpecialistPoolServiceAsyncClient() + + # Initialize request argument(s) + specialist_pool = aiplatform_v1.SpecialistPool() + specialist_pool.name = "name_value" + specialist_pool.display_name = "display_name_value" + + request = aiplatform_v1.UpdateSpecialistPoolRequest( + specialist_pool=specialist_pool, + ) + + # Make the request + operation = client.update_specialist_pool(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1.types.UpdateSpecialistPoolRequest`): + request (Union[google.cloud.aiplatform_v1.types.UpdateSpecialistPoolRequest, dict]): The request object. Request message for [SpecialistPoolService.UpdateSpecialistPool][google.cloud.aiplatform.v1.SpecialistPoolService.UpdateSpecialistPool]. specialist_pool (:class:`google.cloud.aiplatform_v1.types.SpecialistPool`): @@ -577,16 +769,16 @@ async def update_specialist_pool( The result type for the operation will be :class:`google.cloud.aiplatform_v1.types.SpecialistPool` SpecialistPool represents customers' own workforce to work on their data labeling jobs. It includes a group of specialist - managers who are responsible for managing the - labelers in this pool as well as customers' data - labeling jobs associated with this pool. Customers - create specialist pool as well as start data labeling - jobs on Cloud, managers and labelers work with the - jobs using CrowdCompute console. + managers and workers. Managers are responsible for + managing the workers in this pool as well as + customers' data labeling jobs associated with this + pool. Customers create specialist pool as well as + start data labeling jobs on Cloud, managers and + workers handle the jobs using CrowdCompute console. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([specialist_pool, update_mask]) if request is not None and has_flattened_params: @@ -608,7 +800,7 @@ async def update_specialist_pool( # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.update_specialist_pool, - default_timeout=5.0, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -621,7 +813,12 @@ async def update_specialist_pool( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -634,6 +831,683 @@ async def update_specialist_pool( # Done; return the response. return response + async def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_operations, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.delete_operation, + default_timeout=None, + 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 cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + 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 wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.wait_operation, + default_timeout=None, + 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 set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_location, + default_timeout=None, + 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 list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_locations, + default_timeout=None, + 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 __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/aiplatform_v1/services/specialist_pool_service/client.py b/google/cloud/aiplatform_v1/services/specialist_pool_service/client.py index 310211d4dd..d9dc6244f6 100644 --- a/google/cloud/aiplatform_v1/services/specialist_pool_service/client.py +++ b/google/cloud/aiplatform_v1/services/specialist_pool_service/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,22 +14,26 @@ # 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 +from typing import Dict, Mapping, 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 as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_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 +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation as gac_operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1.services.specialist_pool_service import pagers @@ -37,6 +41,10 @@ from google.cloud.aiplatform_v1.types import specialist_pool from google.cloud.aiplatform_v1.types import specialist_pool as gca_specialist_pool from google.cloud.aiplatform_v1.types import specialist_pool_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore from .transports.base import SpecialistPoolServiceTransport, DEFAULT_CLIENT_INFO @@ -59,9 +67,10 @@ class SpecialistPoolServiceClientMeta(type): _transport_registry["grpc_asyncio"] = SpecialistPoolServiceGrpcAsyncIOTransport def get_transport_class( - cls, label: str = None, + cls, + label: str = None, ) -> Type[SpecialistPoolServiceTransport]: - """Return an appropriate transport class. + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -90,7 +99,8 @@ class SpecialistPoolServiceClient(metaclass=SpecialistPoolServiceClientMeta): @staticmethod def _get_default_mtls_endpoint(api_endpoint): - """Convert api endpoint to mTLS endpoint. + """Converts api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. Args: @@ -124,7 +134,8 @@ def _get_default_mtls_endpoint(api_endpoint): @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -141,7 +152,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -160,23 +171,30 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> SpecialistPoolServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - SpecialistPoolServiceTransport: The transport used by the client instance. + SpecialistPoolServiceTransport: The transport used by the client + instance. """ return self._transport @staticmethod - def specialist_pool_path(project: str, location: str, specialist_pool: str,) -> str: - """Return a fully-qualified specialist_pool string.""" + def specialist_pool_path( + project: str, + location: str, + specialist_pool: str, + ) -> str: + """Returns a fully-qualified specialist_pool string.""" return "projects/{project}/locations/{location}/specialistPools/{specialist_pool}".format( - project=project, location=location, specialist_pool=specialist_pool, + project=project, + location=location, + specialist_pool=specialist_pool, ) @staticmethod def parse_specialist_pool_path(path: str) -> Dict[str, str]: - """Parse a specialist_pool path into its component segments.""" + """Parses a specialist_pool path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/specialistPools/(?P.+?)$", path, @@ -184,8 +202,10 @@ def parse_specialist_pool_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + def common_billing_account_path( + billing_account: str, + ) -> str: + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -197,9 +217,13 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: 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,) + def common_folder_path( + folder: str, + ) -> str: + """Returns a fully-qualified folder string.""" + return "folders/{folder}".format( + folder=folder, + ) @staticmethod def parse_common_folder_path(path: str) -> Dict[str, str]: @@ -208,9 +232,13 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: 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,) + def common_organization_path( + organization: str, + ) -> str: + """Returns a fully-qualified organization string.""" + return "organizations/{organization}".format( + organization=organization, + ) @staticmethod def parse_common_organization_path(path: str) -> Dict[str, str]: @@ -219,9 +247,13 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: 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,) + def common_project_path( + project: str, + ) -> str: + """Returns a fully-qualified project string.""" + return "projects/{project}".format( + project=project, + ) @staticmethod def parse_common_project_path(path: str) -> Dict[str, str]: @@ -230,10 +262,14 @@ def parse_common_project_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_location_path(project: str, location: str,) -> str: - """Return a fully-qualified location string.""" + def common_location_path( + project: str, + location: str, + ) -> str: + """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) @staticmethod @@ -242,6 +278,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + def __init__( self, *, @@ -250,7 +353,7 @@ def __init__( client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the specialist pool service client. + """Instantiates the specialist pool service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -292,58 +395,42 @@ def __init__( 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")) + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - client_cert_source_func = ( - mtls.default_client_cert_source() 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" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # 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, SpecialistPoolServiceTransport): # transport is a SpecialistPoolServiceTransport instance. - if credentials or client_options.credentials_file: + if credentials or client_options.credentials_file or api_key_value: 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." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + Transport = type(self).get_transport_class(transport) self._transport = Transport( credentials=credentials, @@ -353,22 +440,53 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, + always_use_jwt_access=True, ) def create_specialist_pool( self, - request: specialist_pool_service.CreateSpecialistPoolRequest = None, + request: Union[ + specialist_pool_service.CreateSpecialistPoolRequest, dict + ] = None, *, parent: str = None, specialist_pool: gca_specialist_pool.SpecialistPool = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Creates a SpecialistPool. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_create_specialist_pool(): + # Create a client + client = aiplatform_v1.SpecialistPoolServiceClient() + + # Initialize request argument(s) + specialist_pool = aiplatform_v1.SpecialistPool() + specialist_pool.name = "name_value" + specialist_pool.display_name = "display_name_value" + + request = aiplatform_v1.CreateSpecialistPoolRequest( + parent="parent_value", + specialist_pool=specialist_pool, + ) + + # Make the request + operation = client.create_specialist_pool(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1.types.CreateSpecialistPoolRequest): + request (Union[google.cloud.aiplatform_v1.types.CreateSpecialistPoolRequest, dict]): The request object. Request message for [SpecialistPoolService.CreateSpecialistPool][google.cloud.aiplatform.v1.SpecialistPoolService.CreateSpecialistPool]. parent (str): @@ -398,16 +516,16 @@ def create_specialist_pool( The result type for the operation will be :class:`google.cloud.aiplatform_v1.types.SpecialistPool` SpecialistPool represents customers' own workforce to work on their data labeling jobs. It includes a group of specialist - managers who are responsible for managing the - labelers in this pool as well as customers' data - labeling jobs associated with this pool. Customers - create specialist pool as well as start data labeling - jobs on Cloud, managers and labelers work with the - jobs using CrowdCompute console. + managers and workers. Managers are responsible for + managing the workers in this pool as well as + customers' data labeling jobs associated with this + pool. Customers create specialist pool as well as + start data labeling jobs on Cloud, managers and + workers handle the jobs using CrowdCompute console. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, specialist_pool]) if request is not None and has_flattened_params: @@ -440,7 +558,12 @@ def create_specialist_pool( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -455,23 +578,41 @@ def create_specialist_pool( def get_specialist_pool( self, - request: specialist_pool_service.GetSpecialistPoolRequest = None, + request: Union[specialist_pool_service.GetSpecialistPoolRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> specialist_pool.SpecialistPool: r"""Gets a SpecialistPool. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_get_specialist_pool(): + # Create a client + client = aiplatform_v1.SpecialistPoolServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetSpecialistPoolRequest( + name="name_value", + ) + + # Make the request + response = client.get_specialist_pool(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1.types.GetSpecialistPoolRequest): + request (Union[google.cloud.aiplatform_v1.types.GetSpecialistPoolRequest, dict]): The request object. Request message for [SpecialistPoolService.GetSpecialistPool][google.cloud.aiplatform.v1.SpecialistPoolService.GetSpecialistPool]. name (str): Required. The name of the SpecialistPool resource. The form is - ``projects/{project}/locations/{location}/specialistPools/{specialist_pool}``. This corresponds to the ``name`` field @@ -488,18 +629,19 @@ def get_specialist_pool( SpecialistPool represents customers' own workforce to work on their data labeling jobs. It includes a group of - specialist managers who are responsible - for managing the labelers in this pool - as well as customers' data labeling jobs - associated with this pool. - Customers create specialist pool as well - as start data labeling jobs on Cloud, - managers and labelers work with the jobs - using CrowdCompute console. + specialist managers and workers. + Managers are responsible for managing + the workers in this pool as well as + customers' data labeling jobs associated + with this pool. Customers create + specialist pool as well as start data + labeling jobs on Cloud, managers and + workers handle the jobs using + CrowdCompute console. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -530,24 +672,49 @@ def get_specialist_pool( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_specialist_pools( self, - request: specialist_pool_service.ListSpecialistPoolsRequest = None, + request: Union[specialist_pool_service.ListSpecialistPoolsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListSpecialistPoolsPager: r"""Lists SpecialistPools in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_list_specialist_pools(): + # Create a client + client = aiplatform_v1.SpecialistPoolServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListSpecialistPoolsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_specialist_pools(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1.types.ListSpecialistPoolsRequest): + request (Union[google.cloud.aiplatform_v1.types.ListSpecialistPoolsRequest, dict]): The request object. Request message for [SpecialistPoolService.ListSpecialistPools][google.cloud.aiplatform.v1.SpecialistPoolService.ListSpecialistPools]. parent (str): @@ -574,7 +741,7 @@ def list_specialist_pools( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -605,12 +772,20 @@ def list_specialist_pools( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListSpecialistPoolsPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -618,18 +793,43 @@ def list_specialist_pools( def delete_specialist_pool( self, - request: specialist_pool_service.DeleteSpecialistPoolRequest = None, + request: Union[ + specialist_pool_service.DeleteSpecialistPoolRequest, dict + ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Deletes a SpecialistPool as well as all Specialists in the pool. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_delete_specialist_pool(): + # Create a client + client = aiplatform_v1.SpecialistPoolServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteSpecialistPoolRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_specialist_pool(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1.types.DeleteSpecialistPoolRequest): + request (Union[google.cloud.aiplatform_v1.types.DeleteSpecialistPoolRequest, dict]): The request object. Request message for [SpecialistPoolService.DeleteSpecialistPool][google.cloud.aiplatform.v1.SpecialistPoolService.DeleteSpecialistPool]. name (str): @@ -666,7 +866,7 @@ def delete_specialist_pool( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -697,7 +897,12 @@ def delete_specialist_pool( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -712,18 +917,47 @@ def delete_specialist_pool( def update_specialist_pool( self, - request: specialist_pool_service.UpdateSpecialistPoolRequest = None, + request: Union[ + specialist_pool_service.UpdateSpecialistPoolRequest, dict + ] = None, *, specialist_pool: gca_specialist_pool.SpecialistPool = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Updates a SpecialistPool. + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_update_specialist_pool(): + # Create a client + client = aiplatform_v1.SpecialistPoolServiceClient() + + # Initialize request argument(s) + specialist_pool = aiplatform_v1.SpecialistPool() + specialist_pool.name = "name_value" + specialist_pool.display_name = "display_name_value" + + request = aiplatform_v1.UpdateSpecialistPoolRequest( + specialist_pool=specialist_pool, + ) + + # Make the request + operation = client.update_specialist_pool(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1.types.UpdateSpecialistPoolRequest): + request (Union[google.cloud.aiplatform_v1.types.UpdateSpecialistPoolRequest, dict]): The request object. Request message for [SpecialistPoolService.UpdateSpecialistPool][google.cloud.aiplatform.v1.SpecialistPoolService.UpdateSpecialistPool]. specialist_pool (google.cloud.aiplatform_v1.types.SpecialistPool): @@ -752,16 +986,16 @@ def update_specialist_pool( The result type for the operation will be :class:`google.cloud.aiplatform_v1.types.SpecialistPool` SpecialistPool represents customers' own workforce to work on their data labeling jobs. It includes a group of specialist - managers who are responsible for managing the - labelers in this pool as well as customers' data - labeling jobs associated with this pool. Customers - create specialist pool as well as start data labeling - jobs on Cloud, managers and labelers work with the - jobs using CrowdCompute console. + managers and workers. Managers are responsible for + managing the workers in this pool as well as + customers' data labeling jobs associated with this + pool. Customers create specialist pool as well as + start data labeling jobs on Cloud, managers and + workers handle the jobs using CrowdCompute console. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([specialist_pool, update_mask]) if request is not None and has_flattened_params: @@ -796,7 +1030,12 @@ def update_specialist_pool( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -809,6 +1048,690 @@ def update_specialist_pool( # Done; return the response. return response + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_operations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.delete_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.wait_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_location, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_locations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/aiplatform_v1/services/specialist_pool_service/pagers.py b/google/cloud/aiplatform_v1/services/specialist_pool_service/pagers.py index afc17c2fde..c18eb507c8 100644 --- a/google/cloud/aiplatform_v1/services/specialist_pool_service/pagers.py +++ b/google/cloud/aiplatform_v1/services/specialist_pool_service/pagers.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,13 +15,13 @@ # from typing import ( Any, - AsyncIterable, + AsyncIterator, Awaitable, Callable, - Iterable, Sequence, Tuple, Optional, + Iterator, ) from google.cloud.aiplatform_v1.types import specialist_pool @@ -75,14 +75,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[specialist_pool_service.ListSpecialistPoolsResponse]: + def pages(self) -> Iterator[specialist_pool_service.ListSpecialistPoolsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[specialist_pool.SpecialistPool]: + def __iter__(self) -> Iterator[specialist_pool.SpecialistPool]: for page in self.pages: yield from page.specialist_pools @@ -118,7 +118,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -141,14 +141,14 @@ def __getattr__(self, name: str) -> Any: @property async def pages( self, - ) -> AsyncIterable[specialist_pool_service.ListSpecialistPoolsResponse]: + ) -> AsyncIterator[specialist_pool_service.ListSpecialistPoolsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[specialist_pool.SpecialistPool]: + def __aiter__(self) -> AsyncIterator[specialist_pool.SpecialistPool]: async def async_generator(): async for page in self.pages: for response in page.specialist_pools: diff --git a/google/cloud/aiplatform_v1/services/specialist_pool_service/transports/__init__.py b/google/cloud/aiplatform_v1/services/specialist_pool_service/transports/__init__.py index cfdda56eda..c8f1c13419 100644 --- a/google/cloud/aiplatform_v1/services/specialist_pool_service/transports/__init__.py +++ b/google/cloud/aiplatform_v1/services/specialist_pool_service/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1/services/specialist_pool_service/transports/base.py b/google/cloud/aiplatform_v1/services/specialist_pool_service/transports/base.py index b4edeb5a73..d3b9e7b4fb 100644 --- a/google/cloud/aiplatform_v1/services/specialist_pool_service/transports/base.py +++ b/google/cloud/aiplatform_v1/services/specialist_pool_service/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,19 +15,23 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.api_core import operations_v1 # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.aiplatform_v1.types import specialist_pool from google.cloud.aiplatform_v1.types import specialist_pool_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore try: @@ -39,17 +43,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - -_API_CORE_VERSION = google.api_core.__version__ - class SpecialistPoolServiceTransport(abc.ABC): """Abstract transport class for SpecialistPoolService.""" @@ -67,6 +60,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -90,16 +84,19 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -112,90 +109,63 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id ) - # Save the credentials. - self._credentials = credentials - - # TODO(busunkim): These two class methods are in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-api-core - # and google-auth are increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") + # If the credentials are service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs + credentials = credentials.with_always_use_jwt_access(True) - # TODO: Remove this function once google-api-core >= 1.26.0 is required - @classmethod - def _get_self_signed_jwt_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Union[Optional[Sequence[str]], str]]: - """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" - - self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} - - if _API_CORE_VERSION and ( - packaging.version.parse(_API_CORE_VERSION) - >= packaging.version.parse("1.26.0") - ): - self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES - self_signed_jwt_kwargs["scopes"] = scopes - self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST - else: - self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES - - return self_signed_jwt_kwargs + # Save the credentials. + self._credentials = credentials def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { self.create_specialist_pool: gapic_v1.method.wrap_method( self.create_specialist_pool, - default_timeout=5.0, + default_timeout=None, client_info=client_info, ), self.get_specialist_pool: gapic_v1.method.wrap_method( - self.get_specialist_pool, default_timeout=5.0, client_info=client_info, + self.get_specialist_pool, + default_timeout=None, + client_info=client_info, ), self.list_specialist_pools: gapic_v1.method.wrap_method( self.list_specialist_pools, - default_timeout=5.0, + default_timeout=None, client_info=client_info, ), self.delete_specialist_pool: gapic_v1.method.wrap_method( self.delete_specialist_pool, - default_timeout=5.0, + default_timeout=None, client_info=client_info, ), self.update_specialist_pool: gapic_v1.method.wrap_method( self.update_specialist_pool, - default_timeout=5.0, + default_timeout=None, client_info=client_info, ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() @@ -249,5 +219,102 @@ def update_specialist_pool( ]: raise NotImplementedError() + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], + Union[ + operations_pb2.ListOperationsResponse, + Awaitable[operations_pb2.ListOperationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None,]: + raise NotImplementedError() + + @property + def wait_operation( + self, + ) -> Callable[ + [operations_pb2.WaitOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def set_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def get_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_location( + self, + ) -> Callable[ + [locations_pb2.GetLocationRequest], + Union[locations_pb2.Location, Awaitable[locations_pb2.Location]], + ]: + raise NotImplementedError() + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], + Union[ + locations_pb2.ListLocationsResponse, + Awaitable[locations_pb2.ListLocationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + __all__ = ("SpecialistPoolServiceTransport",) diff --git a/google/cloud/aiplatform_v1/services/specialist_pool_service/transports/grpc.py b/google/cloud/aiplatform_v1/services/specialist_pool_service/transports/grpc.py index 1abf96a347..0a75e01c6e 100644 --- a/google/cloud/aiplatform_v1/services/specialist_pool_service/transports/grpc.py +++ b/google/cloud/aiplatform_v1/services/specialist_pool_service/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,9 +16,9 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import operations_v1 +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -27,6 +27,10 @@ from google.cloud.aiplatform_v1.types import specialist_pool from google.cloud.aiplatform_v1.types import specialist_pool_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from .base import SpecialistPoolServiceTransport, DEFAULT_CLIENT_INFO @@ -65,6 +69,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -87,16 +92,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -105,6 +110,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport @@ -115,7 +122,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -158,13 +165,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -213,21 +224,20 @@ def create_channel( and ``credentials_file`` are passed. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @property def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ + """Return the channel designed to connect to this service.""" return self._grpc_channel @property @@ -237,7 +247,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsClient(self.grpc_channel) @@ -387,5 +397,215 @@ def update_specialist_pool( ) return self._stubs["update_specialist_pool"] + def close(self): + self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + @property + def kind(self) -> str: + return "grpc" + __all__ = ("SpecialistPoolServiceGrpcTransport",) diff --git a/google/cloud/aiplatform_v1/services/specialist_pool_service/transports/grpc_asyncio.py b/google/cloud/aiplatform_v1/services/specialist_pool_service/transports/grpc_asyncio.py index 4ff2f8484c..53e9799304 100644 --- a/google/cloud/aiplatform_v1/services/specialist_pool_service/transports/grpc_asyncio.py +++ b/google/cloud/aiplatform_v1/services/specialist_pool_service/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,18 +16,21 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore -from google.api_core import operations_v1 # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore from google.cloud.aiplatform_v1.types import specialist_pool from google.cloud.aiplatform_v1.types import specialist_pool_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from .base import SpecialistPoolServiceTransport, DEFAULT_CLIENT_INFO from .grpc import SpecialistPoolServiceGrpcTransport @@ -86,14 +89,14 @@ def create_channel( aio.Channel: A gRPC AsyncIO channel object. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @@ -111,6 +114,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -134,16 +138,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -152,6 +156,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport @@ -162,7 +168,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -204,13 +210,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -240,7 +250,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel @@ -395,5 +405,211 @@ def update_specialist_pool( ) return self._stubs["update_specialist_pool"] + def close(self): + return self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + __all__ = ("SpecialistPoolServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/aiplatform_v1/services/tensorboard_service/__init__.py b/google/cloud/aiplatform_v1/services/tensorboard_service/__init__.py new file mode 100644 index 0000000000..91397832d2 --- /dev/null +++ b/google/cloud/aiplatform_v1/services/tensorboard_service/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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 .client import TensorboardServiceClient +from .async_client import TensorboardServiceAsyncClient + +__all__ = ( + "TensorboardServiceClient", + "TensorboardServiceAsyncClient", +) diff --git a/google/cloud/aiplatform_v1/services/tensorboard_service/async_client.py b/google/cloud/aiplatform_v1/services/tensorboard_service/async_client.py new file mode 100644 index 0000000000..46eb6e7858 --- /dev/null +++ b/google/cloud/aiplatform_v1/services/tensorboard_service/async_client.py @@ -0,0 +1,4166 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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, + Mapping, + Optional, + AsyncIterable, + Awaitable, + Sequence, + Tuple, + Type, + Union, +) +import pkg_resources + +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore + +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + +from google.api_core import operation as gac_operation # type: ignore +from google.api_core import operation_async # type: ignore +from google.cloud.aiplatform_v1.services.tensorboard_service import pagers +from google.cloud.aiplatform_v1.types import encryption_spec +from google.cloud.aiplatform_v1.types import operation as gca_operation +from google.cloud.aiplatform_v1.types import tensorboard +from google.cloud.aiplatform_v1.types import tensorboard as gca_tensorboard +from google.cloud.aiplatform_v1.types import tensorboard_data +from google.cloud.aiplatform_v1.types import tensorboard_experiment +from google.cloud.aiplatform_v1.types import ( + tensorboard_experiment as gca_tensorboard_experiment, +) +from google.cloud.aiplatform_v1.types import tensorboard_run +from google.cloud.aiplatform_v1.types import tensorboard_run as gca_tensorboard_run +from google.cloud.aiplatform_v1.types import tensorboard_service +from google.cloud.aiplatform_v1.types import tensorboard_time_series +from google.cloud.aiplatform_v1.types import ( + tensorboard_time_series as gca_tensorboard_time_series, +) +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from .transports.base import TensorboardServiceTransport, DEFAULT_CLIENT_INFO +from .transports.grpc_asyncio import TensorboardServiceGrpcAsyncIOTransport +from .client import TensorboardServiceClient + + +class TensorboardServiceAsyncClient: + """TensorboardService""" + + _client: TensorboardServiceClient + + DEFAULT_ENDPOINT = TensorboardServiceClient.DEFAULT_ENDPOINT + DEFAULT_MTLS_ENDPOINT = TensorboardServiceClient.DEFAULT_MTLS_ENDPOINT + + tensorboard_path = staticmethod(TensorboardServiceClient.tensorboard_path) + parse_tensorboard_path = staticmethod( + TensorboardServiceClient.parse_tensorboard_path + ) + tensorboard_experiment_path = staticmethod( + TensorboardServiceClient.tensorboard_experiment_path + ) + parse_tensorboard_experiment_path = staticmethod( + TensorboardServiceClient.parse_tensorboard_experiment_path + ) + tensorboard_run_path = staticmethod(TensorboardServiceClient.tensorboard_run_path) + parse_tensorboard_run_path = staticmethod( + TensorboardServiceClient.parse_tensorboard_run_path + ) + tensorboard_time_series_path = staticmethod( + TensorboardServiceClient.tensorboard_time_series_path + ) + parse_tensorboard_time_series_path = staticmethod( + TensorboardServiceClient.parse_tensorboard_time_series_path + ) + common_billing_account_path = staticmethod( + TensorboardServiceClient.common_billing_account_path + ) + parse_common_billing_account_path = staticmethod( + TensorboardServiceClient.parse_common_billing_account_path + ) + common_folder_path = staticmethod(TensorboardServiceClient.common_folder_path) + parse_common_folder_path = staticmethod( + TensorboardServiceClient.parse_common_folder_path + ) + common_organization_path = staticmethod( + TensorboardServiceClient.common_organization_path + ) + parse_common_organization_path = staticmethod( + TensorboardServiceClient.parse_common_organization_path + ) + common_project_path = staticmethod(TensorboardServiceClient.common_project_path) + parse_common_project_path = staticmethod( + TensorboardServiceClient.parse_common_project_path + ) + common_location_path = staticmethod(TensorboardServiceClient.common_location_path) + parse_common_location_path = staticmethod( + TensorboardServiceClient.parse_common_location_path + ) + + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials + info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + TensorboardServiceAsyncClient: The constructed client. + """ + return TensorboardServiceClient.from_service_account_info.__func__(TensorboardServiceAsyncClient, info, *args, **kwargs) # type: ignore + + @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: + TensorboardServiceAsyncClient: The constructed client. + """ + return TensorboardServiceClient.from_service_account_file.__func__(TensorboardServiceAsyncClient, filename, *args, **kwargs) # type: ignore + + from_service_account_json = from_service_account_file + + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return TensorboardServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + + @property + def transport(self) -> TensorboardServiceTransport: + """Returns the transport used by the client instance. + + Returns: + TensorboardServiceTransport: The transport used by the client instance. + """ + return self._client.transport + + get_transport_class = functools.partial( + type(TensorboardServiceClient).get_transport_class, + type(TensorboardServiceClient), + ) + + def __init__( + self, + *, + credentials: ga_credentials.Credentials = None, + transport: Union[str, TensorboardServiceTransport] = "grpc_asyncio", + client_options: ClientOptions = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the tensorboard 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, ~.TensorboardServiceTransport]): 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 = TensorboardServiceClient( + credentials=credentials, + transport=transport, + client_options=client_options, + client_info=client_info, + ) + + async def create_tensorboard( + self, + request: Union[tensorboard_service.CreateTensorboardRequest, dict] = None, + *, + parent: str = None, + tensorboard: gca_tensorboard.Tensorboard = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Creates a Tensorboard. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_create_tensorboard(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + tensorboard = aiplatform_v1.Tensorboard() + tensorboard.display_name = "display_name_value" + + request = aiplatform_v1.CreateTensorboardRequest( + parent="parent_value", + tensorboard=tensorboard, + ) + + # Make the request + operation = client.create_tensorboard(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CreateTensorboardRequest, dict]): + The request object. Request message for + [TensorboardService.CreateTensorboard][google.cloud.aiplatform.v1.TensorboardService.CreateTensorboard]. + parent (:class:`str`): + Required. The resource name of the Location to create + the Tensorboard in. Format: + ``projects/{project}/locations/{location}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + tensorboard (:class:`google.cloud.aiplatform_v1.types.Tensorboard`): + Required. The Tensorboard to create. + This corresponds to the ``tensorboard`` 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.cloud.aiplatform_v1.types.Tensorboard` Tensorboard is a physical database that stores users' training metrics. + A default Tensorboard is provided in each region of a + GCP project. If needed users can also create extra + Tensorboards in their projects. + + """ + # Create or coerce a protobuf request object. + # Quick 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, tensorboard]) + 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 = tensorboard_service.CreateTensorboardRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if tensorboard is not None: + request.tensorboard = tensorboard + + # 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_tensorboard, + default_timeout=None, + 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, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + gca_tensorboard.Tensorboard, + metadata_type=tensorboard_service.CreateTensorboardOperationMetadata, + ) + + # Done; return the response. + return response + + async def get_tensorboard( + self, + request: Union[tensorboard_service.GetTensorboardRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> tensorboard.Tensorboard: + r"""Gets a Tensorboard. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_get_tensorboard(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetTensorboardRequest( + name="name_value", + ) + + # Make the request + response = await client.get_tensorboard(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetTensorboardRequest, dict]): + The request object. Request message for + [TensorboardService.GetTensorboard][google.cloud.aiplatform.v1.TensorboardService.GetTensorboard]. + name (:class:`str`): + Required. The name of the Tensorboard resource. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}`` + + 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: + google.cloud.aiplatform_v1.types.Tensorboard: + Tensorboard is a physical database + that stores users' training metrics. A + default Tensorboard is provided in each + region of a GCP project. If needed users + can also create extra Tensorboards in + their projects. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = tensorboard_service.GetTensorboardRequest(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_tensorboard, + default_timeout=None, + 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_tensorboard( + self, + request: Union[tensorboard_service.UpdateTensorboardRequest, dict] = None, + *, + tensorboard: gca_tensorboard.Tensorboard = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Updates a Tensorboard. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_update_tensorboard(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + tensorboard = aiplatform_v1.Tensorboard() + tensorboard.display_name = "display_name_value" + + request = aiplatform_v1.UpdateTensorboardRequest( + tensorboard=tensorboard, + ) + + # Make the request + operation = client.update_tensorboard(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.UpdateTensorboardRequest, dict]): + The request object. Request message for + [TensorboardService.UpdateTensorboard][google.cloud.aiplatform.v1.TensorboardService.UpdateTensorboard]. + tensorboard (:class:`google.cloud.aiplatform_v1.types.Tensorboard`): + Required. The Tensorboard's ``name`` field is used to + identify the Tensorboard to be updated. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}`` + + This corresponds to the ``tensorboard`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + Required. Field mask is used to specify the fields to be + overwritten in the Tensorboard resource by the update. + The fields specified in the update_mask are relative to + the resource, not the full request. A field will be + overwritten if it is in the mask. If the user does not + provide a mask then all fields will be overwritten if + new values are specified. + + 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.cloud.aiplatform_v1.types.Tensorboard` Tensorboard is a physical database that stores users' training metrics. + A default Tensorboard is provided in each region of a + GCP project. If needed users can also create extra + Tensorboards in their projects. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([tensorboard, 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 = tensorboard_service.UpdateTensorboardRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if tensorboard is not None: + request.tensorboard = tensorboard + 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_tensorboard, + default_timeout=None, + 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( + (("tensorboard.name", request.tensorboard.name),) + ), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + gca_tensorboard.Tensorboard, + metadata_type=tensorboard_service.UpdateTensorboardOperationMetadata, + ) + + # Done; return the response. + return response + + async def list_tensorboards( + self, + request: Union[tensorboard_service.ListTensorboardsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListTensorboardsAsyncPager: + r"""Lists Tensorboards in a Location. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_list_tensorboards(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListTensorboardsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboards(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListTensorboardsRequest, dict]): + The request object. Request message for + [TensorboardService.ListTensorboards][google.cloud.aiplatform.v1.TensorboardService.ListTensorboards]. + parent (:class:`str`): + Required. The resource name of the Location to list + Tensorboards. Format: + ``projects/{project}/locations/{location}`` + + 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: + google.cloud.aiplatform_v1.services.tensorboard_service.pagers.ListTensorboardsAsyncPager: + Response message for + [TensorboardService.ListTensorboards][google.cloud.aiplatform.v1.TensorboardService.ListTensorboards]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = tensorboard_service.ListTensorboardsRequest(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_tensorboards, + default_timeout=None, + 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.ListTensorboardsAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def delete_tensorboard( + self, + request: Union[tensorboard_service.DeleteTensorboardRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Deletes a Tensorboard. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_delete_tensorboard(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteTensorboardRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.DeleteTensorboardRequest, dict]): + The request object. Request message for + [TensorboardService.DeleteTensorboard][google.cloud.aiplatform.v1.TensorboardService.DeleteTensorboard]. + name (:class:`str`): + Required. The name of the Tensorboard to be deleted. + Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}`` + + 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = tensorboard_service.DeleteTensorboardRequest(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_tensorboard, + default_timeout=None, + 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, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, + ) + + # Done; return the response. + return response + + async def create_tensorboard_experiment( + self, + request: Union[ + tensorboard_service.CreateTensorboardExperimentRequest, dict + ] = None, + *, + parent: str = None, + tensorboard_experiment: gca_tensorboard_experiment.TensorboardExperiment = None, + tensorboard_experiment_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_tensorboard_experiment.TensorboardExperiment: + r"""Creates a TensorboardExperiment. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_create_tensorboard_experiment(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateTensorboardExperimentRequest( + parent="parent_value", + tensorboard_experiment_id="tensorboard_experiment_id_value", + ) + + # Make the request + response = await client.create_tensorboard_experiment(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CreateTensorboardExperimentRequest, dict]): + The request object. Request message for + [TensorboardService.CreateTensorboardExperiment][google.cloud.aiplatform.v1.TensorboardService.CreateTensorboardExperiment]. + parent (:class:`str`): + Required. The resource name of the Tensorboard to create + the TensorboardExperiment in. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + tensorboard_experiment (:class:`google.cloud.aiplatform_v1.types.TensorboardExperiment`): + The TensorboardExperiment to create. + This corresponds to the ``tensorboard_experiment`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + tensorboard_experiment_id (:class:`str`): + Required. The ID to use for the Tensorboard experiment, + which will become the final component of the Tensorboard + experiment's resource name. + + This value should be 1-128 characters, and valid + characters are /[a-z][0-9]-/. + + This corresponds to the ``tensorboard_experiment_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: + google.cloud.aiplatform_v1.types.TensorboardExperiment: + A TensorboardExperiment is a group of + TensorboardRuns, that are typically the + results of a training job run, in a + Tensorboard. + + """ + # Create or coerce a protobuf request object. + # Quick 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, tensorboard_experiment, tensorboard_experiment_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 = tensorboard_service.CreateTensorboardExperimentRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if tensorboard_experiment is not None: + request.tensorboard_experiment = tensorboard_experiment + if tensorboard_experiment_id is not None: + request.tensorboard_experiment_id = tensorboard_experiment_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_tensorboard_experiment, + default_timeout=None, + 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 get_tensorboard_experiment( + self, + request: Union[ + tensorboard_service.GetTensorboardExperimentRequest, dict + ] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> tensorboard_experiment.TensorboardExperiment: + r"""Gets a TensorboardExperiment. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_get_tensorboard_experiment(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetTensorboardExperimentRequest( + name="name_value", + ) + + # Make the request + response = await client.get_tensorboard_experiment(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetTensorboardExperimentRequest, dict]): + The request object. Request message for + [TensorboardService.GetTensorboardExperiment][google.cloud.aiplatform.v1.TensorboardService.GetTensorboardExperiment]. + name (:class:`str`): + Required. The name of the TensorboardExperiment + resource. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` + + 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: + google.cloud.aiplatform_v1.types.TensorboardExperiment: + A TensorboardExperiment is a group of + TensorboardRuns, that are typically the + results of a training job run, in a + Tensorboard. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = tensorboard_service.GetTensorboardExperimentRequest(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_tensorboard_experiment, + default_timeout=None, + 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_tensorboard_experiment( + self, + request: Union[ + tensorboard_service.UpdateTensorboardExperimentRequest, dict + ] = None, + *, + tensorboard_experiment: gca_tensorboard_experiment.TensorboardExperiment = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_tensorboard_experiment.TensorboardExperiment: + r"""Updates a TensorboardExperiment. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_update_tensorboard_experiment(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.UpdateTensorboardExperimentRequest( + ) + + # Make the request + response = await client.update_tensorboard_experiment(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.UpdateTensorboardExperimentRequest, dict]): + The request object. Request message for + [TensorboardService.UpdateTensorboardExperiment][google.cloud.aiplatform.v1.TensorboardService.UpdateTensorboardExperiment]. + tensorboard_experiment (:class:`google.cloud.aiplatform_v1.types.TensorboardExperiment`): + Required. The TensorboardExperiment's ``name`` field is + used to identify the TensorboardExperiment to be + updated. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` + + This corresponds to the ``tensorboard_experiment`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + Required. Field mask is used to specify the fields to be + overwritten in the TensorboardExperiment resource by the + update. The fields specified in the update_mask are + relative to the resource, not the full request. A field + will be overwritten if it is in the mask. If the user + does not provide a mask then all fields will be + overwritten if new values are specified. + + 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: + google.cloud.aiplatform_v1.types.TensorboardExperiment: + A TensorboardExperiment is a group of + TensorboardRuns, that are typically the + results of a training job run, in a + Tensorboard. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([tensorboard_experiment, 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 = tensorboard_service.UpdateTensorboardExperimentRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if tensorboard_experiment is not None: + request.tensorboard_experiment = tensorboard_experiment + 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_tensorboard_experiment, + default_timeout=None, + 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( + (("tensorboard_experiment.name", request.tensorboard_experiment.name),) + ), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def list_tensorboard_experiments( + self, + request: Union[ + tensorboard_service.ListTensorboardExperimentsRequest, dict + ] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListTensorboardExperimentsAsyncPager: + r"""Lists TensorboardExperiments in a Location. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_list_tensorboard_experiments(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListTensorboardExperimentsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboard_experiments(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListTensorboardExperimentsRequest, dict]): + The request object. Request message for + [TensorboardService.ListTensorboardExperiments][google.cloud.aiplatform.v1.TensorboardService.ListTensorboardExperiments]. + parent (:class:`str`): + Required. The resource name of the + Tensorboard to list + TensorboardExperiments. Format: + 'projects/{project}/locations/{location}/tensorboards/{tensorboard}' + + 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: + google.cloud.aiplatform_v1.services.tensorboard_service.pagers.ListTensorboardExperimentsAsyncPager: + Response message for + [TensorboardService.ListTensorboardExperiments][google.cloud.aiplatform.v1.TensorboardService.ListTensorboardExperiments]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = tensorboard_service.ListTensorboardExperimentsRequest(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_tensorboard_experiments, + default_timeout=None, + 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.ListTensorboardExperimentsAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def delete_tensorboard_experiment( + self, + request: Union[ + tensorboard_service.DeleteTensorboardExperimentRequest, dict + ] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Deletes a TensorboardExperiment. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_delete_tensorboard_experiment(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteTensorboardExperimentRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard_experiment(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.DeleteTensorboardExperimentRequest, dict]): + The request object. Request message for + [TensorboardService.DeleteTensorboardExperiment][google.cloud.aiplatform.v1.TensorboardService.DeleteTensorboardExperiment]. + name (:class:`str`): + Required. The name of the TensorboardExperiment to be + deleted. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` + + 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = tensorboard_service.DeleteTensorboardExperimentRequest(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_tensorboard_experiment, + default_timeout=None, + 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, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, + ) + + # Done; return the response. + return response + + async def create_tensorboard_run( + self, + request: Union[tensorboard_service.CreateTensorboardRunRequest, dict] = None, + *, + parent: str = None, + tensorboard_run: gca_tensorboard_run.TensorboardRun = None, + tensorboard_run_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_tensorboard_run.TensorboardRun: + r"""Creates a TensorboardRun. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_create_tensorboard_run(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + tensorboard_run = aiplatform_v1.TensorboardRun() + tensorboard_run.display_name = "display_name_value" + + request = aiplatform_v1.CreateTensorboardRunRequest( + parent="parent_value", + tensorboard_run=tensorboard_run, + tensorboard_run_id="tensorboard_run_id_value", + ) + + # Make the request + response = await client.create_tensorboard_run(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CreateTensorboardRunRequest, dict]): + The request object. Request message for + [TensorboardService.CreateTensorboardRun][google.cloud.aiplatform.v1.TensorboardService.CreateTensorboardRun]. + parent (:class:`str`): + Required. The resource name of the TensorboardExperiment + to create the TensorboardRun in. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + tensorboard_run (:class:`google.cloud.aiplatform_v1.types.TensorboardRun`): + Required. The TensorboardRun to + create. + + This corresponds to the ``tensorboard_run`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + tensorboard_run_id (:class:`str`): + Required. The ID to use for the Tensorboard run, which + will become the final component of the Tensorboard run's + resource name. + + This value should be 1-128 characters, and valid + characters are /[a-z][0-9]-/. + + This corresponds to the ``tensorboard_run_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: + google.cloud.aiplatform_v1.types.TensorboardRun: + TensorboardRun maps to a specific + execution of a training job with a given + set of hyperparameter values, model + definition, dataset, etc + + """ + # Create or coerce a protobuf request object. + # Quick 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, tensorboard_run, tensorboard_run_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 = tensorboard_service.CreateTensorboardRunRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if tensorboard_run is not None: + request.tensorboard_run = tensorboard_run + if tensorboard_run_id is not None: + request.tensorboard_run_id = tensorboard_run_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_tensorboard_run, + default_timeout=None, + 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 batch_create_tensorboard_runs( + self, + request: Union[ + tensorboard_service.BatchCreateTensorboardRunsRequest, dict + ] = None, + *, + parent: str = None, + requests: Sequence[tensorboard_service.CreateTensorboardRunRequest] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> tensorboard_service.BatchCreateTensorboardRunsResponse: + r"""Batch create TensorboardRuns. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_batch_create_tensorboard_runs(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + requests = aiplatform_v1.CreateTensorboardRunRequest() + requests.parent = "parent_value" + requests.tensorboard_run.display_name = "display_name_value" + requests.tensorboard_run_id = "tensorboard_run_id_value" + + request = aiplatform_v1.BatchCreateTensorboardRunsRequest( + parent="parent_value", + requests=requests, + ) + + # Make the request + response = await client.batch_create_tensorboard_runs(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.BatchCreateTensorboardRunsRequest, dict]): + The request object. Request message for + [TensorboardService.BatchCreateTensorboardRuns][google.cloud.aiplatform.v1.TensorboardService.BatchCreateTensorboardRuns]. + parent (:class:`str`): + Required. The resource name of the TensorboardExperiment + to create the TensorboardRuns in. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` + The parent field in the CreateTensorboardRunRequest + messages must match this field. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + requests (:class:`Sequence[google.cloud.aiplatform_v1.types.CreateTensorboardRunRequest]`): + Required. The request message + specifying the TensorboardRuns to + create. A maximum of 1000 + TensorboardRuns can be created in a + batch. + + This corresponds to the ``requests`` 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: + google.cloud.aiplatform_v1.types.BatchCreateTensorboardRunsResponse: + Response message for + [TensorboardService.BatchCreateTensorboardRuns][google.cloud.aiplatform.v1.TensorboardService.BatchCreateTensorboardRuns]. + + """ + # Create or coerce a protobuf request object. + # Quick 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, requests]) + 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 = tensorboard_service.BatchCreateTensorboardRunsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if requests: + request.requests.extend(requests) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.batch_create_tensorboard_runs, + default_timeout=None, + 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 get_tensorboard_run( + self, + request: Union[tensorboard_service.GetTensorboardRunRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> tensorboard_run.TensorboardRun: + r"""Gets a TensorboardRun. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_get_tensorboard_run(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetTensorboardRunRequest( + name="name_value", + ) + + # Make the request + response = await client.get_tensorboard_run(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetTensorboardRunRequest, dict]): + The request object. Request message for + [TensorboardService.GetTensorboardRun][google.cloud.aiplatform.v1.TensorboardService.GetTensorboardRun]. + name (:class:`str`): + Required. The name of the TensorboardRun resource. + Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}`` + + 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: + google.cloud.aiplatform_v1.types.TensorboardRun: + TensorboardRun maps to a specific + execution of a training job with a given + set of hyperparameter values, model + definition, dataset, etc + + """ + # Create or coerce a protobuf request object. + # Quick 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 = tensorboard_service.GetTensorboardRunRequest(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_tensorboard_run, + default_timeout=None, + 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_tensorboard_run( + self, + request: Union[tensorboard_service.UpdateTensorboardRunRequest, dict] = None, + *, + tensorboard_run: gca_tensorboard_run.TensorboardRun = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_tensorboard_run.TensorboardRun: + r"""Updates a TensorboardRun. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_update_tensorboard_run(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + tensorboard_run = aiplatform_v1.TensorboardRun() + tensorboard_run.display_name = "display_name_value" + + request = aiplatform_v1.UpdateTensorboardRunRequest( + tensorboard_run=tensorboard_run, + ) + + # Make the request + response = await client.update_tensorboard_run(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.UpdateTensorboardRunRequest, dict]): + The request object. Request message for + [TensorboardService.UpdateTensorboardRun][google.cloud.aiplatform.v1.TensorboardService.UpdateTensorboardRun]. + tensorboard_run (:class:`google.cloud.aiplatform_v1.types.TensorboardRun`): + Required. The TensorboardRun's ``name`` field is used to + identify the TensorboardRun to be updated. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}`` + + This corresponds to the ``tensorboard_run`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + Required. Field mask is used to specify the fields to be + overwritten in the TensorboardRun resource by the + update. The fields specified in the update_mask are + relative to the resource, not the full request. A field + will be overwritten if it is in the mask. If the user + does not provide a mask then all fields will be + overwritten if new values are specified. + + 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: + google.cloud.aiplatform_v1.types.TensorboardRun: + TensorboardRun maps to a specific + execution of a training job with a given + set of hyperparameter values, model + definition, dataset, etc + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([tensorboard_run, 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 = tensorboard_service.UpdateTensorboardRunRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if tensorboard_run is not None: + request.tensorboard_run = tensorboard_run + 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_tensorboard_run, + default_timeout=None, + 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( + (("tensorboard_run.name", request.tensorboard_run.name),) + ), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def list_tensorboard_runs( + self, + request: Union[tensorboard_service.ListTensorboardRunsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListTensorboardRunsAsyncPager: + r"""Lists TensorboardRuns in a Location. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_list_tensorboard_runs(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListTensorboardRunsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboard_runs(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListTensorboardRunsRequest, dict]): + The request object. Request message for + [TensorboardService.ListTensorboardRuns][google.cloud.aiplatform.v1.TensorboardService.ListTensorboardRuns]. + parent (:class:`str`): + Required. The resource name of the + TensorboardExperiment to list + TensorboardRuns. Format: + 'projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}' + + 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: + google.cloud.aiplatform_v1.services.tensorboard_service.pagers.ListTensorboardRunsAsyncPager: + Response message for + [TensorboardService.ListTensorboardRuns][google.cloud.aiplatform.v1.TensorboardService.ListTensorboardRuns]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = tensorboard_service.ListTensorboardRunsRequest(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_tensorboard_runs, + default_timeout=None, + 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.ListTensorboardRunsAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def delete_tensorboard_run( + self, + request: Union[tensorboard_service.DeleteTensorboardRunRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Deletes a TensorboardRun. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_delete_tensorboard_run(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteTensorboardRunRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard_run(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.DeleteTensorboardRunRequest, dict]): + The request object. Request message for + [TensorboardService.DeleteTensorboardRun][google.cloud.aiplatform.v1.TensorboardService.DeleteTensorboardRun]. + name (:class:`str`): + Required. The name of the TensorboardRun to be deleted. + Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}`` + + 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = tensorboard_service.DeleteTensorboardRunRequest(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_tensorboard_run, + default_timeout=None, + 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, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, + ) + + # Done; return the response. + return response + + async def batch_create_tensorboard_time_series( + self, + request: Union[ + tensorboard_service.BatchCreateTensorboardTimeSeriesRequest, dict + ] = None, + *, + parent: str = None, + requests: Sequence[ + tensorboard_service.CreateTensorboardTimeSeriesRequest + ] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> tensorboard_service.BatchCreateTensorboardTimeSeriesResponse: + r"""Batch create TensorboardTimeSeries that belong to a + TensorboardExperiment. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_batch_create_tensorboard_time_series(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + requests = aiplatform_v1.CreateTensorboardTimeSeriesRequest() + requests.parent = "parent_value" + requests.tensorboard_time_series.display_name = "display_name_value" + requests.tensorboard_time_series.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1.BatchCreateTensorboardTimeSeriesRequest( + parent="parent_value", + requests=requests, + ) + + # Make the request + response = await client.batch_create_tensorboard_time_series(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.BatchCreateTensorboardTimeSeriesRequest, dict]): + The request object. Request message for + [TensorboardService.BatchCreateTensorboardTimeSeries][google.cloud.aiplatform.v1.TensorboardService.BatchCreateTensorboardTimeSeries]. + parent (:class:`str`): + Required. The resource name of the TensorboardExperiment + to create the TensorboardTimeSeries in. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` + The TensorboardRuns referenced by the parent fields in + the CreateTensorboardTimeSeriesRequest messages must be + sub resources of this TensorboardExperiment. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + requests (:class:`Sequence[google.cloud.aiplatform_v1.types.CreateTensorboardTimeSeriesRequest]`): + Required. The request message + specifying the TensorboardTimeSeries to + create. A maximum of 1000 + TensorboardTimeSeries can be created in + a batch. + + This corresponds to the ``requests`` 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: + google.cloud.aiplatform_v1.types.BatchCreateTensorboardTimeSeriesResponse: + Response message for + [TensorboardService.BatchCreateTensorboardTimeSeries][google.cloud.aiplatform.v1.TensorboardService.BatchCreateTensorboardTimeSeries]. + + """ + # Create or coerce a protobuf request object. + # Quick 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, requests]) + 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 = tensorboard_service.BatchCreateTensorboardTimeSeriesRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if requests: + request.requests.extend(requests) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.batch_create_tensorboard_time_series, + default_timeout=None, + 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_tensorboard_time_series( + self, + request: Union[ + tensorboard_service.CreateTensorboardTimeSeriesRequest, dict + ] = None, + *, + parent: str = None, + tensorboard_time_series: gca_tensorboard_time_series.TensorboardTimeSeries = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_tensorboard_time_series.TensorboardTimeSeries: + r"""Creates a TensorboardTimeSeries. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_create_tensorboard_time_series(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + tensorboard_time_series = aiplatform_v1.TensorboardTimeSeries() + tensorboard_time_series.display_name = "display_name_value" + tensorboard_time_series.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1.CreateTensorboardTimeSeriesRequest( + parent="parent_value", + tensorboard_time_series=tensorboard_time_series, + ) + + # Make the request + response = await client.create_tensorboard_time_series(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CreateTensorboardTimeSeriesRequest, dict]): + The request object. Request message for + [TensorboardService.CreateTensorboardTimeSeries][google.cloud.aiplatform.v1.TensorboardService.CreateTensorboardTimeSeries]. + parent (:class:`str`): + Required. The resource name of the TensorboardRun to + create the TensorboardTimeSeries in. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + tensorboard_time_series (:class:`google.cloud.aiplatform_v1.types.TensorboardTimeSeries`): + Required. The TensorboardTimeSeries + to create. + + This corresponds to the ``tensorboard_time_series`` 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: + google.cloud.aiplatform_v1.types.TensorboardTimeSeries: + TensorboardTimeSeries maps to times + series produced in training runs + + """ + # Create or coerce a protobuf request object. + # Quick 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, tensorboard_time_series]) + 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 = tensorboard_service.CreateTensorboardTimeSeriesRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if tensorboard_time_series is not None: + request.tensorboard_time_series = tensorboard_time_series + + # 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_tensorboard_time_series, + default_timeout=None, + 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 get_tensorboard_time_series( + self, + request: Union[ + tensorboard_service.GetTensorboardTimeSeriesRequest, dict + ] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> tensorboard_time_series.TensorboardTimeSeries: + r"""Gets a TensorboardTimeSeries. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_get_tensorboard_time_series(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetTensorboardTimeSeriesRequest( + name="name_value", + ) + + # Make the request + response = await client.get_tensorboard_time_series(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetTensorboardTimeSeriesRequest, dict]): + The request object. Request message for + [TensorboardService.GetTensorboardTimeSeries][google.cloud.aiplatform.v1.TensorboardService.GetTensorboardTimeSeries]. + name (:class:`str`): + Required. The name of the TensorboardTimeSeries + resource. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}/timeSeries/{time_series}`` + + 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: + google.cloud.aiplatform_v1.types.TensorboardTimeSeries: + TensorboardTimeSeries maps to times + series produced in training runs + + """ + # Create or coerce a protobuf request object. + # Quick 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 = tensorboard_service.GetTensorboardTimeSeriesRequest(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_tensorboard_time_series, + default_timeout=None, + 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_tensorboard_time_series( + self, + request: Union[ + tensorboard_service.UpdateTensorboardTimeSeriesRequest, dict + ] = None, + *, + tensorboard_time_series: gca_tensorboard_time_series.TensorboardTimeSeries = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_tensorboard_time_series.TensorboardTimeSeries: + r"""Updates a TensorboardTimeSeries. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_update_tensorboard_time_series(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + tensorboard_time_series = aiplatform_v1.TensorboardTimeSeries() + tensorboard_time_series.display_name = "display_name_value" + tensorboard_time_series.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1.UpdateTensorboardTimeSeriesRequest( + tensorboard_time_series=tensorboard_time_series, + ) + + # Make the request + response = await client.update_tensorboard_time_series(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.UpdateTensorboardTimeSeriesRequest, dict]): + The request object. Request message for + [TensorboardService.UpdateTensorboardTimeSeries][google.cloud.aiplatform.v1.TensorboardService.UpdateTensorboardTimeSeries]. + tensorboard_time_series (:class:`google.cloud.aiplatform_v1.types.TensorboardTimeSeries`): + Required. The TensorboardTimeSeries' ``name`` field is + used to identify the TensorboardTimeSeries to be + updated. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}/timeSeries/{time_series}`` + + This corresponds to the ``tensorboard_time_series`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): + Required. Field mask is used to specify the fields to be + overwritten in the TensorboardTimeSeries resource by the + update. The fields specified in the update_mask are + relative to the resource, not the full request. A field + will be overwritten if it is in the mask. If the user + does not provide a mask then all fields will be + overwritten if new values are specified. + + 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: + google.cloud.aiplatform_v1.types.TensorboardTimeSeries: + TensorboardTimeSeries maps to times + series produced in training runs + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([tensorboard_time_series, 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 = tensorboard_service.UpdateTensorboardTimeSeriesRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if tensorboard_time_series is not None: + request.tensorboard_time_series = tensorboard_time_series + 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_tensorboard_time_series, + default_timeout=None, + 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( + ( + ( + "tensorboard_time_series.name", + request.tensorboard_time_series.name, + ), + ) + ), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def list_tensorboard_time_series( + self, + request: Union[ + tensorboard_service.ListTensorboardTimeSeriesRequest, dict + ] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListTensorboardTimeSeriesAsyncPager: + r"""Lists TensorboardTimeSeries in a Location. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_list_tensorboard_time_series(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListTensorboardTimeSeriesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboard_time_series(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListTensorboardTimeSeriesRequest, dict]): + The request object. Request message for + [TensorboardService.ListTensorboardTimeSeries][google.cloud.aiplatform.v1.TensorboardService.ListTensorboardTimeSeries]. + parent (:class:`str`): + Required. The resource name of the + TensorboardRun to list + TensorboardTimeSeries. Format: + 'projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}' + + 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: + google.cloud.aiplatform_v1.services.tensorboard_service.pagers.ListTensorboardTimeSeriesAsyncPager: + Response message for + [TensorboardService.ListTensorboardTimeSeries][google.cloud.aiplatform.v1.TensorboardService.ListTensorboardTimeSeries]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = tensorboard_service.ListTensorboardTimeSeriesRequest(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_tensorboard_time_series, + default_timeout=None, + 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.ListTensorboardTimeSeriesAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def delete_tensorboard_time_series( + self, + request: Union[ + tensorboard_service.DeleteTensorboardTimeSeriesRequest, dict + ] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Deletes a TensorboardTimeSeries. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_delete_tensorboard_time_series(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteTensorboardTimeSeriesRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard_time_series(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.DeleteTensorboardTimeSeriesRequest, dict]): + The request object. Request message for + [TensorboardService.DeleteTensorboardTimeSeries][google.cloud.aiplatform.v1.TensorboardService.DeleteTensorboardTimeSeries]. + name (:class:`str`): + Required. The name of the TensorboardTimeSeries to be + deleted. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}/timeSeries/{time_series}`` + + 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = tensorboard_service.DeleteTensorboardTimeSeriesRequest(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_tensorboard_time_series, + default_timeout=None, + 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, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, + ) + + # Done; return the response. + return response + + async def batch_read_tensorboard_time_series_data( + self, + request: Union[ + tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest, dict + ] = None, + *, + tensorboard: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> tensorboard_service.BatchReadTensorboardTimeSeriesDataResponse: + r"""Reads multiple TensorboardTimeSeries' data. The data + point number limit is 1000 for scalars, 100 for tensors + and blob references. If the number of data points stored + is less than the limit, all data will be returned. + Otherwise, that limit number of data points will be + randomly selected from this time series and returned. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_batch_read_tensorboard_time_series_data(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.BatchReadTensorboardTimeSeriesDataRequest( + tensorboard="tensorboard_value", + time_series=['time_series_value_1', 'time_series_value_2'], + ) + + # Make the request + response = await client.batch_read_tensorboard_time_series_data(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.BatchReadTensorboardTimeSeriesDataRequest, dict]): + The request object. Request message for + [TensorboardService.BatchReadTensorboardTimeSeriesData][google.cloud.aiplatform.v1.TensorboardService.BatchReadTensorboardTimeSeriesData]. + tensorboard (:class:`str`): + Required. The resource name of the Tensorboard + containing TensorboardTimeSeries to read data from. + Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}``. + The TensorboardTimeSeries referenced by + [time_series][google.cloud.aiplatform.v1.BatchReadTensorboardTimeSeriesDataRequest.time_series] + must be sub resources of this Tensorboard. + + This corresponds to the ``tensorboard`` 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: + google.cloud.aiplatform_v1.types.BatchReadTensorboardTimeSeriesDataResponse: + Response message for + [TensorboardService.BatchReadTensorboardTimeSeriesData][google.cloud.aiplatform.v1.TensorboardService.BatchReadTensorboardTimeSeriesData]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([tensorboard]) + 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 = tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if tensorboard is not None: + request.tensorboard = tensorboard + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.batch_read_tensorboard_time_series_data, + default_timeout=None, + 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( + (("tensorboard", request.tensorboard),) + ), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def read_tensorboard_time_series_data( + self, + request: Union[ + tensorboard_service.ReadTensorboardTimeSeriesDataRequest, dict + ] = None, + *, + tensorboard_time_series: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> tensorboard_service.ReadTensorboardTimeSeriesDataResponse: + r"""Reads a TensorboardTimeSeries' data. By default, if the number + of data points stored is less than 1000, all data will be + returned. Otherwise, 1000 data points will be randomly selected + from this time series and returned. This value can be changed by + changing max_data_points, which can't be greater than 10k. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_read_tensorboard_time_series_data(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ReadTensorboardTimeSeriesDataRequest( + tensorboard_time_series="tensorboard_time_series_value", + ) + + # Make the request + response = await client.read_tensorboard_time_series_data(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ReadTensorboardTimeSeriesDataRequest, dict]): + The request object. Request message for + [TensorboardService.ReadTensorboardTimeSeriesData][google.cloud.aiplatform.v1.TensorboardService.ReadTensorboardTimeSeriesData]. + tensorboard_time_series (:class:`str`): + Required. The resource name of the TensorboardTimeSeries + to read data from. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}/timeSeries/{time_series}`` + + This corresponds to the ``tensorboard_time_series`` 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: + google.cloud.aiplatform_v1.types.ReadTensorboardTimeSeriesDataResponse: + Response message for + [TensorboardService.ReadTensorboardTimeSeriesData][google.cloud.aiplatform.v1.TensorboardService.ReadTensorboardTimeSeriesData]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([tensorboard_time_series]) + 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 = tensorboard_service.ReadTensorboardTimeSeriesDataRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if tensorboard_time_series is not None: + request.tensorboard_time_series = tensorboard_time_series + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.read_tensorboard_time_series_data, + default_timeout=None, + 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( + (("tensorboard_time_series", request.tensorboard_time_series),) + ), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def read_tensorboard_blob_data( + self, + request: Union[tensorboard_service.ReadTensorboardBlobDataRequest, dict] = None, + *, + time_series: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> Awaitable[AsyncIterable[tensorboard_service.ReadTensorboardBlobDataResponse]]: + r"""Gets bytes of TensorboardBlobs. + This is to allow reading blob data stored in consumer + project's Cloud Storage bucket without users having to + obtain Cloud Storage access permission. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_read_tensorboard_blob_data(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ReadTensorboardBlobDataRequest( + time_series="time_series_value", + ) + + # Make the request + stream = await client.read_tensorboard_blob_data(request=request) + + # Handle the response + async for response in stream: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ReadTensorboardBlobDataRequest, dict]): + The request object. Request message for + [TensorboardService.ReadTensorboardBlobData][google.cloud.aiplatform.v1.TensorboardService.ReadTensorboardBlobData]. + time_series (:class:`str`): + Required. The resource name of the TensorboardTimeSeries + to list Blobs. Format: + 'projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}/timeSeries/{time_series}' + + This corresponds to the ``time_series`` 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: + AsyncIterable[google.cloud.aiplatform_v1.types.ReadTensorboardBlobDataResponse]: + Response message for + [TensorboardService.ReadTensorboardBlobData][google.cloud.aiplatform.v1.TensorboardService.ReadTensorboardBlobData]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([time_series]) + 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 = tensorboard_service.ReadTensorboardBlobDataRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if time_series is not None: + request.time_series = time_series + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.read_tensorboard_blob_data, + default_timeout=None, + 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( + (("time_series", request.time_series),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def write_tensorboard_experiment_data( + self, + request: Union[ + tensorboard_service.WriteTensorboardExperimentDataRequest, dict + ] = None, + *, + tensorboard_experiment: str = None, + write_run_data_requests: Sequence[ + tensorboard_service.WriteTensorboardRunDataRequest + ] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> tensorboard_service.WriteTensorboardExperimentDataResponse: + r"""Write time series data points of multiple + TensorboardTimeSeries in multiple TensorboardRun's. If + any data fail to be ingested, an error will be returned. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_write_tensorboard_experiment_data(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + write_run_data_requests = aiplatform_v1.WriteTensorboardRunDataRequest() + write_run_data_requests.tensorboard_run = "tensorboard_run_value" + write_run_data_requests.time_series_data.tensorboard_time_series_id = "tensorboard_time_series_id_value" + write_run_data_requests.time_series_data.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1.WriteTensorboardExperimentDataRequest( + tensorboard_experiment="tensorboard_experiment_value", + write_run_data_requests=write_run_data_requests, + ) + + # Make the request + response = await client.write_tensorboard_experiment_data(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.WriteTensorboardExperimentDataRequest, dict]): + The request object. Request message for + [TensorboardService.WriteTensorboardExperimentData][google.cloud.aiplatform.v1.TensorboardService.WriteTensorboardExperimentData]. + tensorboard_experiment (:class:`str`): + Required. The resource name of the TensorboardExperiment + to write data to. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` + + This corresponds to the ``tensorboard_experiment`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + write_run_data_requests (:class:`Sequence[google.cloud.aiplatform_v1.types.WriteTensorboardRunDataRequest]`): + Required. Requests containing per-run + TensorboardTimeSeries data to write. + + This corresponds to the ``write_run_data_requests`` 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: + google.cloud.aiplatform_v1.types.WriteTensorboardExperimentDataResponse: + Response message for + [TensorboardService.WriteTensorboardExperimentData][google.cloud.aiplatform.v1.TensorboardService.WriteTensorboardExperimentData]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([tensorboard_experiment, write_run_data_requests]) + 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 = tensorboard_service.WriteTensorboardExperimentDataRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if tensorboard_experiment is not None: + request.tensorboard_experiment = tensorboard_experiment + if write_run_data_requests: + request.write_run_data_requests.extend(write_run_data_requests) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.write_tensorboard_experiment_data, + default_timeout=None, + 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( + (("tensorboard_experiment", request.tensorboard_experiment),) + ), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def write_tensorboard_run_data( + self, + request: Union[tensorboard_service.WriteTensorboardRunDataRequest, dict] = None, + *, + tensorboard_run: str = None, + time_series_data: Sequence[tensorboard_data.TimeSeriesData] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> tensorboard_service.WriteTensorboardRunDataResponse: + r"""Write time series data points into multiple + TensorboardTimeSeries under a TensorboardRun. If any + data fail to be ingested, an error will be returned. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_write_tensorboard_run_data(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + time_series_data = aiplatform_v1.TimeSeriesData() + time_series_data.tensorboard_time_series_id = "tensorboard_time_series_id_value" + time_series_data.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1.WriteTensorboardRunDataRequest( + tensorboard_run="tensorboard_run_value", + time_series_data=time_series_data, + ) + + # Make the request + response = await client.write_tensorboard_run_data(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.WriteTensorboardRunDataRequest, dict]): + The request object. Request message for + [TensorboardService.WriteTensorboardRunData][google.cloud.aiplatform.v1.TensorboardService.WriteTensorboardRunData]. + tensorboard_run (:class:`str`): + Required. The resource name of the TensorboardRun to + write data to. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}`` + + This corresponds to the ``tensorboard_run`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + time_series_data (:class:`Sequence[google.cloud.aiplatform_v1.types.TimeSeriesData]`): + Required. The TensorboardTimeSeries + data to write. Values with in a time + series are indexed by their step value. + Repeated writes to the same step will + overwrite the existing value for that + step. + The upper limit of data points per write + request is 5000. + + This corresponds to the ``time_series_data`` 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: + google.cloud.aiplatform_v1.types.WriteTensorboardRunDataResponse: + Response message for + [TensorboardService.WriteTensorboardRunData][google.cloud.aiplatform.v1.TensorboardService.WriteTensorboardRunData]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([tensorboard_run, time_series_data]) + 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 = tensorboard_service.WriteTensorboardRunDataRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if tensorboard_run is not None: + request.tensorboard_run = tensorboard_run + if time_series_data: + request.time_series_data.extend(time_series_data) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.write_tensorboard_run_data, + default_timeout=None, + 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( + (("tensorboard_run", request.tensorboard_run),) + ), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def export_tensorboard_time_series_data( + self, + request: Union[ + tensorboard_service.ExportTensorboardTimeSeriesDataRequest, dict + ] = None, + *, + tensorboard_time_series: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ExportTensorboardTimeSeriesDataAsyncPager: + r"""Exports a TensorboardTimeSeries' data. Data is + returned in paginated responses. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_export_tensorboard_time_series_data(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ExportTensorboardTimeSeriesDataRequest( + tensorboard_time_series="tensorboard_time_series_value", + ) + + # Make the request + page_result = client.export_tensorboard_time_series_data(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ExportTensorboardTimeSeriesDataRequest, dict]): + The request object. Request message for + [TensorboardService.ExportTensorboardTimeSeriesData][google.cloud.aiplatform.v1.TensorboardService.ExportTensorboardTimeSeriesData]. + tensorboard_time_series (:class:`str`): + Required. The resource name of the TensorboardTimeSeries + to export data from. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}/timeSeries/{time_series}`` + + This corresponds to the ``tensorboard_time_series`` 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: + google.cloud.aiplatform_v1.services.tensorboard_service.pagers.ExportTensorboardTimeSeriesDataAsyncPager: + Response message for + [TensorboardService.ExportTensorboardTimeSeriesData][google.cloud.aiplatform.v1.TensorboardService.ExportTensorboardTimeSeriesData]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([tensorboard_time_series]) + 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 = tensorboard_service.ExportTensorboardTimeSeriesDataRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if tensorboard_time_series is not None: + request.tensorboard_time_series = tensorboard_time_series + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.export_tensorboard_time_series_data, + default_timeout=None, + 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( + (("tensorboard_time_series", request.tensorboard_time_series),) + ), + ) + + # 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.ExportTensorboardTimeSeriesDataAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_operations, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.delete_operation, + default_timeout=None, + 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 cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + 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 wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.wait_operation, + default_timeout=None, + 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 set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_location, + default_timeout=None, + 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 list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_locations, + default_timeout=None, + 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 __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-aiplatform", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ("TensorboardServiceAsyncClient",) diff --git a/google/cloud/aiplatform_v1/services/tensorboard_service/client.py b/google/cloud/aiplatform_v1/services/tensorboard_service/client.py new file mode 100644 index 0000000000..db0723f2f6 --- /dev/null +++ b/google/cloud/aiplatform_v1/services/tensorboard_service/client.py @@ -0,0 +1,4518 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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 os +import re +from typing import Dict, Mapping, Optional, Iterable, Sequence, Tuple, Type, Union +import pkg_resources + +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.auth import credentials as ga_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 + +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + +from google.api_core import operation as gac_operation # type: ignore +from google.api_core import operation_async # type: ignore +from google.cloud.aiplatform_v1.services.tensorboard_service import pagers +from google.cloud.aiplatform_v1.types import encryption_spec +from google.cloud.aiplatform_v1.types import operation as gca_operation +from google.cloud.aiplatform_v1.types import tensorboard +from google.cloud.aiplatform_v1.types import tensorboard as gca_tensorboard +from google.cloud.aiplatform_v1.types import tensorboard_data +from google.cloud.aiplatform_v1.types import tensorboard_experiment +from google.cloud.aiplatform_v1.types import ( + tensorboard_experiment as gca_tensorboard_experiment, +) +from google.cloud.aiplatform_v1.types import tensorboard_run +from google.cloud.aiplatform_v1.types import tensorboard_run as gca_tensorboard_run +from google.cloud.aiplatform_v1.types import tensorboard_service +from google.cloud.aiplatform_v1.types import tensorboard_time_series +from google.cloud.aiplatform_v1.types import ( + tensorboard_time_series as gca_tensorboard_time_series, +) +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.protobuf import empty_pb2 # type: ignore +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from .transports.base import TensorboardServiceTransport, DEFAULT_CLIENT_INFO +from .transports.grpc import TensorboardServiceGrpcTransport +from .transports.grpc_asyncio import TensorboardServiceGrpcAsyncIOTransport + + +class TensorboardServiceClientMeta(type): + """Metaclass for the TensorboardService 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[TensorboardServiceTransport]] + _transport_registry["grpc"] = TensorboardServiceGrpcTransport + _transport_registry["grpc_asyncio"] = TensorboardServiceGrpcAsyncIOTransport + + def get_transport_class( + cls, + label: str = None, + ) -> Type[TensorboardServiceTransport]: + """Returns 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 TensorboardServiceClient(metaclass=TensorboardServiceClientMeta): + """TensorboardService""" + + @staticmethod + def _get_default_mtls_endpoint(api_endpoint): + """Converts 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 = "aiplatform.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials + info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + TensorboardServiceClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + + @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: + TensorboardServiceClient: 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) -> TensorboardServiceTransport: + """Returns the transport used by the client instance. + + Returns: + TensorboardServiceTransport: The transport used by the client + instance. + """ + return self._transport + + @staticmethod + def tensorboard_path( + project: str, + location: str, + tensorboard: str, + ) -> str: + """Returns a fully-qualified tensorboard string.""" + return ( + "projects/{project}/locations/{location}/tensorboards/{tensorboard}".format( + project=project, + location=location, + tensorboard=tensorboard, + ) + ) + + @staticmethod + def parse_tensorboard_path(path: str) -> Dict[str, str]: + """Parses a tensorboard path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/tensorboards/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def tensorboard_experiment_path( + project: str, + location: str, + tensorboard: str, + experiment: str, + ) -> str: + """Returns a fully-qualified tensorboard_experiment string.""" + return "projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}".format( + project=project, + location=location, + tensorboard=tensorboard, + experiment=experiment, + ) + + @staticmethod + def parse_tensorboard_experiment_path(path: str) -> Dict[str, str]: + """Parses a tensorboard_experiment path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/tensorboards/(?P.+?)/experiments/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def tensorboard_run_path( + project: str, + location: str, + tensorboard: str, + experiment: str, + run: str, + ) -> str: + """Returns a fully-qualified tensorboard_run string.""" + return "projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}".format( + project=project, + location=location, + tensorboard=tensorboard, + experiment=experiment, + run=run, + ) + + @staticmethod + def parse_tensorboard_run_path(path: str) -> Dict[str, str]: + """Parses a tensorboard_run path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/tensorboards/(?P.+?)/experiments/(?P.+?)/runs/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def tensorboard_time_series_path( + project: str, + location: str, + tensorboard: str, + experiment: str, + run: str, + time_series: str, + ) -> str: + """Returns a fully-qualified tensorboard_time_series string.""" + return "projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}/timeSeries/{time_series}".format( + project=project, + location=location, + tensorboard=tensorboard, + experiment=experiment, + run=run, + time_series=time_series, + ) + + @staticmethod + def parse_tensorboard_time_series_path(path: str) -> Dict[str, str]: + """Parses a tensorboard_time_series path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/tensorboards/(?P.+?)/experiments/(?P.+?)/runs/(?P.+?)/timeSeries/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def common_billing_account_path( + billing_account: str, + ) -> str: + """Returns 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: + """Returns 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: + """Returns 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: + """Returns 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: + """Returns 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 {} + + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + + def __init__( + self, + *, + credentials: Optional[ga_credentials.Credentials] = None, + transport: Union[str, TensorboardServiceTransport, None] = None, + client_options: Optional[client_options_lib.ClientOptions] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the tensorboard 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, TensorboardServiceTransport]): The + transport to use. If set to None, a transport is chosen + automatically. + client_options (google.api_core.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. + 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() + + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options + ) + + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) + + # 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, TensorboardServiceTransport): + # transport is a TensorboardServiceTransport instance. + if credentials or client_options.credentials_file or api_key_value: + 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: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + + 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, + client_cert_source_for_mtls=client_cert_source_func, + quota_project_id=client_options.quota_project_id, + client_info=client_info, + always_use_jwt_access=True, + ) + + def create_tensorboard( + self, + request: Union[tensorboard_service.CreateTensorboardRequest, dict] = None, + *, + parent: str = None, + tensorboard: gca_tensorboard.Tensorboard = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Creates a Tensorboard. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_create_tensorboard(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + tensorboard = aiplatform_v1.Tensorboard() + tensorboard.display_name = "display_name_value" + + request = aiplatform_v1.CreateTensorboardRequest( + parent="parent_value", + tensorboard=tensorboard, + ) + + # Make the request + operation = client.create_tensorboard(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CreateTensorboardRequest, dict]): + The request object. Request message for + [TensorboardService.CreateTensorboard][google.cloud.aiplatform.v1.TensorboardService.CreateTensorboard]. + parent (str): + Required. The resource name of the Location to create + the Tensorboard in. Format: + ``projects/{project}/locations/{location}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + tensorboard (google.cloud.aiplatform_v1.types.Tensorboard): + Required. The Tensorboard to create. + This corresponds to the ``tensorboard`` 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.cloud.aiplatform_v1.types.Tensorboard` Tensorboard is a physical database that stores users' training metrics. + A default Tensorboard is provided in each region of a + GCP project. If needed users can also create extra + Tensorboards in their projects. + + """ + # Create or coerce a protobuf request object. + # Quick 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, tensorboard]) + 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 tensorboard_service.CreateTensorboardRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, tensorboard_service.CreateTensorboardRequest): + request = tensorboard_service.CreateTensorboardRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if tensorboard is not None: + request.tensorboard = tensorboard + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_tensorboard] + + # 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, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + gca_tensorboard.Tensorboard, + metadata_type=tensorboard_service.CreateTensorboardOperationMetadata, + ) + + # Done; return the response. + return response + + def get_tensorboard( + self, + request: Union[tensorboard_service.GetTensorboardRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> tensorboard.Tensorboard: + r"""Gets a Tensorboard. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_get_tensorboard(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetTensorboardRequest( + name="name_value", + ) + + # Make the request + response = client.get_tensorboard(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetTensorboardRequest, dict]): + The request object. Request message for + [TensorboardService.GetTensorboard][google.cloud.aiplatform.v1.TensorboardService.GetTensorboard]. + name (str): + Required. The name of the Tensorboard resource. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}`` + + 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: + google.cloud.aiplatform_v1.types.Tensorboard: + Tensorboard is a physical database + that stores users' training metrics. A + default Tensorboard is provided in each + region of a GCP project. If needed users + can also create extra Tensorboards in + their projects. + + """ + # Create or coerce a protobuf request object. + # Quick 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 tensorboard_service.GetTensorboardRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, tensorboard_service.GetTensorboardRequest): + request = tensorboard_service.GetTensorboardRequest(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_tensorboard] + + # 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_tensorboard( + self, + request: Union[tensorboard_service.UpdateTensorboardRequest, dict] = None, + *, + tensorboard: gca_tensorboard.Tensorboard = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Updates a Tensorboard. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_update_tensorboard(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + tensorboard = aiplatform_v1.Tensorboard() + tensorboard.display_name = "display_name_value" + + request = aiplatform_v1.UpdateTensorboardRequest( + tensorboard=tensorboard, + ) + + # Make the request + operation = client.update_tensorboard(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.UpdateTensorboardRequest, dict]): + The request object. Request message for + [TensorboardService.UpdateTensorboard][google.cloud.aiplatform.v1.TensorboardService.UpdateTensorboard]. + tensorboard (google.cloud.aiplatform_v1.types.Tensorboard): + Required. The Tensorboard's ``name`` field is used to + identify the Tensorboard to be updated. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}`` + + This corresponds to the ``tensorboard`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Required. Field mask is used to specify the fields to be + overwritten in the Tensorboard resource by the update. + The fields specified in the update_mask are relative to + the resource, not the full request. A field will be + overwritten if it is in the mask. If the user does not + provide a mask then all fields will be overwritten if + new values are specified. + + 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.cloud.aiplatform_v1.types.Tensorboard` Tensorboard is a physical database that stores users' training metrics. + A default Tensorboard is provided in each region of a + GCP project. If needed users can also create extra + Tensorboards in their projects. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([tensorboard, 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 tensorboard_service.UpdateTensorboardRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, tensorboard_service.UpdateTensorboardRequest): + request = tensorboard_service.UpdateTensorboardRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if tensorboard is not None: + request.tensorboard = tensorboard + 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_tensorboard] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("tensorboard.name", request.tensorboard.name),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + gca_tensorboard.Tensorboard, + metadata_type=tensorboard_service.UpdateTensorboardOperationMetadata, + ) + + # Done; return the response. + return response + + def list_tensorboards( + self, + request: Union[tensorboard_service.ListTensorboardsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListTensorboardsPager: + r"""Lists Tensorboards in a Location. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_list_tensorboards(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListTensorboardsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboards(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListTensorboardsRequest, dict]): + The request object. Request message for + [TensorboardService.ListTensorboards][google.cloud.aiplatform.v1.TensorboardService.ListTensorboards]. + parent (str): + Required. The resource name of the Location to list + Tensorboards. Format: + ``projects/{project}/locations/{location}`` + + 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: + google.cloud.aiplatform_v1.services.tensorboard_service.pagers.ListTensorboardsPager: + Response message for + [TensorboardService.ListTensorboards][google.cloud.aiplatform.v1.TensorboardService.ListTensorboards]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 tensorboard_service.ListTensorboardsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, tensorboard_service.ListTensorboardsRequest): + request = tensorboard_service.ListTensorboardsRequest(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_tensorboards] + + # 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.ListTensorboardsPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_tensorboard( + self, + request: Union[tensorboard_service.DeleteTensorboardRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Deletes a Tensorboard. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_delete_tensorboard(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteTensorboardRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.DeleteTensorboardRequest, dict]): + The request object. Request message for + [TensorboardService.DeleteTensorboard][google.cloud.aiplatform.v1.TensorboardService.DeleteTensorboard]. + name (str): + Required. The name of the Tensorboard to be deleted. + Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}`` + + 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # Create or coerce a protobuf request object. + # Quick 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 tensorboard_service.DeleteTensorboardRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, tensorboard_service.DeleteTensorboardRequest): + request = tensorboard_service.DeleteTensorboardRequest(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_tensorboard] + + # 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, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, + ) + + # Done; return the response. + return response + + def create_tensorboard_experiment( + self, + request: Union[ + tensorboard_service.CreateTensorboardExperimentRequest, dict + ] = None, + *, + parent: str = None, + tensorboard_experiment: gca_tensorboard_experiment.TensorboardExperiment = None, + tensorboard_experiment_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_tensorboard_experiment.TensorboardExperiment: + r"""Creates a TensorboardExperiment. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_create_tensorboard_experiment(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateTensorboardExperimentRequest( + parent="parent_value", + tensorboard_experiment_id="tensorboard_experiment_id_value", + ) + + # Make the request + response = client.create_tensorboard_experiment(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CreateTensorboardExperimentRequest, dict]): + The request object. Request message for + [TensorboardService.CreateTensorboardExperiment][google.cloud.aiplatform.v1.TensorboardService.CreateTensorboardExperiment]. + parent (str): + Required. The resource name of the Tensorboard to create + the TensorboardExperiment in. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + tensorboard_experiment (google.cloud.aiplatform_v1.types.TensorboardExperiment): + The TensorboardExperiment to create. + This corresponds to the ``tensorboard_experiment`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + tensorboard_experiment_id (str): + Required. The ID to use for the Tensorboard experiment, + which will become the final component of the Tensorboard + experiment's resource name. + + This value should be 1-128 characters, and valid + characters are /[a-z][0-9]-/. + + This corresponds to the ``tensorboard_experiment_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: + google.cloud.aiplatform_v1.types.TensorboardExperiment: + A TensorboardExperiment is a group of + TensorboardRuns, that are typically the + results of a training job run, in a + Tensorboard. + + """ + # Create or coerce a protobuf request object. + # Quick 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, tensorboard_experiment, tensorboard_experiment_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 tensorboard_service.CreateTensorboardExperimentRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, tensorboard_service.CreateTensorboardExperimentRequest + ): + request = tensorboard_service.CreateTensorboardExperimentRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if tensorboard_experiment is not None: + request.tensorboard_experiment = tensorboard_experiment + if tensorboard_experiment_id is not None: + request.tensorboard_experiment_id = tensorboard_experiment_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.create_tensorboard_experiment + ] + + # 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 get_tensorboard_experiment( + self, + request: Union[ + tensorboard_service.GetTensorboardExperimentRequest, dict + ] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> tensorboard_experiment.TensorboardExperiment: + r"""Gets a TensorboardExperiment. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_get_tensorboard_experiment(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetTensorboardExperimentRequest( + name="name_value", + ) + + # Make the request + response = client.get_tensorboard_experiment(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetTensorboardExperimentRequest, dict]): + The request object. Request message for + [TensorboardService.GetTensorboardExperiment][google.cloud.aiplatform.v1.TensorboardService.GetTensorboardExperiment]. + name (str): + Required. The name of the TensorboardExperiment + resource. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` + + 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: + google.cloud.aiplatform_v1.types.TensorboardExperiment: + A TensorboardExperiment is a group of + TensorboardRuns, that are typically the + results of a training job run, in a + Tensorboard. + + """ + # Create or coerce a protobuf request object. + # Quick 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 tensorboard_service.GetTensorboardExperimentRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, tensorboard_service.GetTensorboardExperimentRequest): + request = tensorboard_service.GetTensorboardExperimentRequest(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_tensorboard_experiment + ] + + # 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_tensorboard_experiment( + self, + request: Union[ + tensorboard_service.UpdateTensorboardExperimentRequest, dict + ] = None, + *, + tensorboard_experiment: gca_tensorboard_experiment.TensorboardExperiment = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_tensorboard_experiment.TensorboardExperiment: + r"""Updates a TensorboardExperiment. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_update_tensorboard_experiment(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.UpdateTensorboardExperimentRequest( + ) + + # Make the request + response = client.update_tensorboard_experiment(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.UpdateTensorboardExperimentRequest, dict]): + The request object. Request message for + [TensorboardService.UpdateTensorboardExperiment][google.cloud.aiplatform.v1.TensorboardService.UpdateTensorboardExperiment]. + tensorboard_experiment (google.cloud.aiplatform_v1.types.TensorboardExperiment): + Required. The TensorboardExperiment's ``name`` field is + used to identify the TensorboardExperiment to be + updated. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` + + This corresponds to the ``tensorboard_experiment`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Required. Field mask is used to specify the fields to be + overwritten in the TensorboardExperiment resource by the + update. The fields specified in the update_mask are + relative to the resource, not the full request. A field + will be overwritten if it is in the mask. If the user + does not provide a mask then all fields will be + overwritten if new values are specified. + + 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: + google.cloud.aiplatform_v1.types.TensorboardExperiment: + A TensorboardExperiment is a group of + TensorboardRuns, that are typically the + results of a training job run, in a + Tensorboard. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([tensorboard_experiment, 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 tensorboard_service.UpdateTensorboardExperimentRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, tensorboard_service.UpdateTensorboardExperimentRequest + ): + request = tensorboard_service.UpdateTensorboardExperimentRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if tensorboard_experiment is not None: + request.tensorboard_experiment = tensorboard_experiment + 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_tensorboard_experiment + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("tensorboard_experiment.name", request.tensorboard_experiment.name),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_tensorboard_experiments( + self, + request: Union[ + tensorboard_service.ListTensorboardExperimentsRequest, dict + ] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListTensorboardExperimentsPager: + r"""Lists TensorboardExperiments in a Location. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_list_tensorboard_experiments(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListTensorboardExperimentsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboard_experiments(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListTensorboardExperimentsRequest, dict]): + The request object. Request message for + [TensorboardService.ListTensorboardExperiments][google.cloud.aiplatform.v1.TensorboardService.ListTensorboardExperiments]. + parent (str): + Required. The resource name of the + Tensorboard to list + TensorboardExperiments. Format: + 'projects/{project}/locations/{location}/tensorboards/{tensorboard}' + + 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: + google.cloud.aiplatform_v1.services.tensorboard_service.pagers.ListTensorboardExperimentsPager: + Response message for + [TensorboardService.ListTensorboardExperiments][google.cloud.aiplatform.v1.TensorboardService.ListTensorboardExperiments]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 tensorboard_service.ListTensorboardExperimentsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, tensorboard_service.ListTensorboardExperimentsRequest + ): + request = tensorboard_service.ListTensorboardExperimentsRequest(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_tensorboard_experiments + ] + + # 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.ListTensorboardExperimentsPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_tensorboard_experiment( + self, + request: Union[ + tensorboard_service.DeleteTensorboardExperimentRequest, dict + ] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Deletes a TensorboardExperiment. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_delete_tensorboard_experiment(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteTensorboardExperimentRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard_experiment(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.DeleteTensorboardExperimentRequest, dict]): + The request object. Request message for + [TensorboardService.DeleteTensorboardExperiment][google.cloud.aiplatform.v1.TensorboardService.DeleteTensorboardExperiment]. + name (str): + Required. The name of the TensorboardExperiment to be + deleted. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` + + 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # Create or coerce a protobuf request object. + # Quick 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 tensorboard_service.DeleteTensorboardExperimentRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, tensorboard_service.DeleteTensorboardExperimentRequest + ): + request = tensorboard_service.DeleteTensorboardExperimentRequest(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_tensorboard_experiment + ] + + # 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, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, + ) + + # Done; return the response. + return response + + def create_tensorboard_run( + self, + request: Union[tensorboard_service.CreateTensorboardRunRequest, dict] = None, + *, + parent: str = None, + tensorboard_run: gca_tensorboard_run.TensorboardRun = None, + tensorboard_run_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_tensorboard_run.TensorboardRun: + r"""Creates a TensorboardRun. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_create_tensorboard_run(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + tensorboard_run = aiplatform_v1.TensorboardRun() + tensorboard_run.display_name = "display_name_value" + + request = aiplatform_v1.CreateTensorboardRunRequest( + parent="parent_value", + tensorboard_run=tensorboard_run, + tensorboard_run_id="tensorboard_run_id_value", + ) + + # Make the request + response = client.create_tensorboard_run(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CreateTensorboardRunRequest, dict]): + The request object. Request message for + [TensorboardService.CreateTensorboardRun][google.cloud.aiplatform.v1.TensorboardService.CreateTensorboardRun]. + parent (str): + Required. The resource name of the TensorboardExperiment + to create the TensorboardRun in. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + tensorboard_run (google.cloud.aiplatform_v1.types.TensorboardRun): + Required. The TensorboardRun to + create. + + This corresponds to the ``tensorboard_run`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + tensorboard_run_id (str): + Required. The ID to use for the Tensorboard run, which + will become the final component of the Tensorboard run's + resource name. + + This value should be 1-128 characters, and valid + characters are /[a-z][0-9]-/. + + This corresponds to the ``tensorboard_run_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: + google.cloud.aiplatform_v1.types.TensorboardRun: + TensorboardRun maps to a specific + execution of a training job with a given + set of hyperparameter values, model + definition, dataset, etc + + """ + # Create or coerce a protobuf request object. + # Quick 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, tensorboard_run, tensorboard_run_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 tensorboard_service.CreateTensorboardRunRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, tensorboard_service.CreateTensorboardRunRequest): + request = tensorboard_service.CreateTensorboardRunRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if tensorboard_run is not None: + request.tensorboard_run = tensorboard_run + if tensorboard_run_id is not None: + request.tensorboard_run_id = tensorboard_run_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_tensorboard_run] + + # 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 batch_create_tensorboard_runs( + self, + request: Union[ + tensorboard_service.BatchCreateTensorboardRunsRequest, dict + ] = None, + *, + parent: str = None, + requests: Sequence[tensorboard_service.CreateTensorboardRunRequest] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> tensorboard_service.BatchCreateTensorboardRunsResponse: + r"""Batch create TensorboardRuns. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_batch_create_tensorboard_runs(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + requests = aiplatform_v1.CreateTensorboardRunRequest() + requests.parent = "parent_value" + requests.tensorboard_run.display_name = "display_name_value" + requests.tensorboard_run_id = "tensorboard_run_id_value" + + request = aiplatform_v1.BatchCreateTensorboardRunsRequest( + parent="parent_value", + requests=requests, + ) + + # Make the request + response = client.batch_create_tensorboard_runs(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.BatchCreateTensorboardRunsRequest, dict]): + The request object. Request message for + [TensorboardService.BatchCreateTensorboardRuns][google.cloud.aiplatform.v1.TensorboardService.BatchCreateTensorboardRuns]. + parent (str): + Required. The resource name of the TensorboardExperiment + to create the TensorboardRuns in. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` + The parent field in the CreateTensorboardRunRequest + messages must match this field. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + requests (Sequence[google.cloud.aiplatform_v1.types.CreateTensorboardRunRequest]): + Required. The request message + specifying the TensorboardRuns to + create. A maximum of 1000 + TensorboardRuns can be created in a + batch. + + This corresponds to the ``requests`` 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: + google.cloud.aiplatform_v1.types.BatchCreateTensorboardRunsResponse: + Response message for + [TensorboardService.BatchCreateTensorboardRuns][google.cloud.aiplatform.v1.TensorboardService.BatchCreateTensorboardRuns]. + + """ + # Create or coerce a protobuf request object. + # Quick 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, requests]) + 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 tensorboard_service.BatchCreateTensorboardRunsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, tensorboard_service.BatchCreateTensorboardRunsRequest + ): + request = tensorboard_service.BatchCreateTensorboardRunsRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if requests is not None: + request.requests = requests + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.batch_create_tensorboard_runs + ] + + # 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 get_tensorboard_run( + self, + request: Union[tensorboard_service.GetTensorboardRunRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> tensorboard_run.TensorboardRun: + r"""Gets a TensorboardRun. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_get_tensorboard_run(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetTensorboardRunRequest( + name="name_value", + ) + + # Make the request + response = client.get_tensorboard_run(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetTensorboardRunRequest, dict]): + The request object. Request message for + [TensorboardService.GetTensorboardRun][google.cloud.aiplatform.v1.TensorboardService.GetTensorboardRun]. + name (str): + Required. The name of the TensorboardRun resource. + Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}`` + + 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: + google.cloud.aiplatform_v1.types.TensorboardRun: + TensorboardRun maps to a specific + execution of a training job with a given + set of hyperparameter values, model + definition, dataset, etc + + """ + # Create or coerce a protobuf request object. + # Quick 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 tensorboard_service.GetTensorboardRunRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, tensorboard_service.GetTensorboardRunRequest): + request = tensorboard_service.GetTensorboardRunRequest(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_tensorboard_run] + + # 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_tensorboard_run( + self, + request: Union[tensorboard_service.UpdateTensorboardRunRequest, dict] = None, + *, + tensorboard_run: gca_tensorboard_run.TensorboardRun = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_tensorboard_run.TensorboardRun: + r"""Updates a TensorboardRun. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_update_tensorboard_run(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + tensorboard_run = aiplatform_v1.TensorboardRun() + tensorboard_run.display_name = "display_name_value" + + request = aiplatform_v1.UpdateTensorboardRunRequest( + tensorboard_run=tensorboard_run, + ) + + # Make the request + response = client.update_tensorboard_run(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.UpdateTensorboardRunRequest, dict]): + The request object. Request message for + [TensorboardService.UpdateTensorboardRun][google.cloud.aiplatform.v1.TensorboardService.UpdateTensorboardRun]. + tensorboard_run (google.cloud.aiplatform_v1.types.TensorboardRun): + Required. The TensorboardRun's ``name`` field is used to + identify the TensorboardRun to be updated. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}`` + + This corresponds to the ``tensorboard_run`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Required. Field mask is used to specify the fields to be + overwritten in the TensorboardRun resource by the + update. The fields specified in the update_mask are + relative to the resource, not the full request. A field + will be overwritten if it is in the mask. If the user + does not provide a mask then all fields will be + overwritten if new values are specified. + + 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: + google.cloud.aiplatform_v1.types.TensorboardRun: + TensorboardRun maps to a specific + execution of a training job with a given + set of hyperparameter values, model + definition, dataset, etc + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([tensorboard_run, 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 tensorboard_service.UpdateTensorboardRunRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, tensorboard_service.UpdateTensorboardRunRequest): + request = tensorboard_service.UpdateTensorboardRunRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if tensorboard_run is not None: + request.tensorboard_run = tensorboard_run + 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_tensorboard_run] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("tensorboard_run.name", request.tensorboard_run.name),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_tensorboard_runs( + self, + request: Union[tensorboard_service.ListTensorboardRunsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListTensorboardRunsPager: + r"""Lists TensorboardRuns in a Location. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_list_tensorboard_runs(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListTensorboardRunsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboard_runs(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListTensorboardRunsRequest, dict]): + The request object. Request message for + [TensorboardService.ListTensorboardRuns][google.cloud.aiplatform.v1.TensorboardService.ListTensorboardRuns]. + parent (str): + Required. The resource name of the + TensorboardExperiment to list + TensorboardRuns. Format: + 'projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}' + + 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: + google.cloud.aiplatform_v1.services.tensorboard_service.pagers.ListTensorboardRunsPager: + Response message for + [TensorboardService.ListTensorboardRuns][google.cloud.aiplatform.v1.TensorboardService.ListTensorboardRuns]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 tensorboard_service.ListTensorboardRunsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, tensorboard_service.ListTensorboardRunsRequest): + request = tensorboard_service.ListTensorboardRunsRequest(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_tensorboard_runs] + + # 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.ListTensorboardRunsPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_tensorboard_run( + self, + request: Union[tensorboard_service.DeleteTensorboardRunRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Deletes a TensorboardRun. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_delete_tensorboard_run(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteTensorboardRunRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard_run(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.DeleteTensorboardRunRequest, dict]): + The request object. Request message for + [TensorboardService.DeleteTensorboardRun][google.cloud.aiplatform.v1.TensorboardService.DeleteTensorboardRun]. + name (str): + Required. The name of the TensorboardRun to be deleted. + Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}`` + + 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # Create or coerce a protobuf request object. + # Quick 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 tensorboard_service.DeleteTensorboardRunRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, tensorboard_service.DeleteTensorboardRunRequest): + request = tensorboard_service.DeleteTensorboardRunRequest(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_tensorboard_run] + + # 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, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, + ) + + # Done; return the response. + return response + + def batch_create_tensorboard_time_series( + self, + request: Union[ + tensorboard_service.BatchCreateTensorboardTimeSeriesRequest, dict + ] = None, + *, + parent: str = None, + requests: Sequence[ + tensorboard_service.CreateTensorboardTimeSeriesRequest + ] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> tensorboard_service.BatchCreateTensorboardTimeSeriesResponse: + r"""Batch create TensorboardTimeSeries that belong to a + TensorboardExperiment. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_batch_create_tensorboard_time_series(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + requests = aiplatform_v1.CreateTensorboardTimeSeriesRequest() + requests.parent = "parent_value" + requests.tensorboard_time_series.display_name = "display_name_value" + requests.tensorboard_time_series.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1.BatchCreateTensorboardTimeSeriesRequest( + parent="parent_value", + requests=requests, + ) + + # Make the request + response = client.batch_create_tensorboard_time_series(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.BatchCreateTensorboardTimeSeriesRequest, dict]): + The request object. Request message for + [TensorboardService.BatchCreateTensorboardTimeSeries][google.cloud.aiplatform.v1.TensorboardService.BatchCreateTensorboardTimeSeries]. + parent (str): + Required. The resource name of the TensorboardExperiment + to create the TensorboardTimeSeries in. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` + The TensorboardRuns referenced by the parent fields in + the CreateTensorboardTimeSeriesRequest messages must be + sub resources of this TensorboardExperiment. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + requests (Sequence[google.cloud.aiplatform_v1.types.CreateTensorboardTimeSeriesRequest]): + Required. The request message + specifying the TensorboardTimeSeries to + create. A maximum of 1000 + TensorboardTimeSeries can be created in + a batch. + + This corresponds to the ``requests`` 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: + google.cloud.aiplatform_v1.types.BatchCreateTensorboardTimeSeriesResponse: + Response message for + [TensorboardService.BatchCreateTensorboardTimeSeries][google.cloud.aiplatform.v1.TensorboardService.BatchCreateTensorboardTimeSeries]. + + """ + # Create or coerce a protobuf request object. + # Quick 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, requests]) + 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 tensorboard_service.BatchCreateTensorboardTimeSeriesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, tensorboard_service.BatchCreateTensorboardTimeSeriesRequest + ): + request = tensorboard_service.BatchCreateTensorboardTimeSeriesRequest( + request + ) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if requests is not None: + request.requests = requests + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.batch_create_tensorboard_time_series + ] + + # 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_tensorboard_time_series( + self, + request: Union[ + tensorboard_service.CreateTensorboardTimeSeriesRequest, dict + ] = None, + *, + parent: str = None, + tensorboard_time_series: gca_tensorboard_time_series.TensorboardTimeSeries = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_tensorboard_time_series.TensorboardTimeSeries: + r"""Creates a TensorboardTimeSeries. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_create_tensorboard_time_series(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + tensorboard_time_series = aiplatform_v1.TensorboardTimeSeries() + tensorboard_time_series.display_name = "display_name_value" + tensorboard_time_series.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1.CreateTensorboardTimeSeriesRequest( + parent="parent_value", + tensorboard_time_series=tensorboard_time_series, + ) + + # Make the request + response = client.create_tensorboard_time_series(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CreateTensorboardTimeSeriesRequest, dict]): + The request object. Request message for + [TensorboardService.CreateTensorboardTimeSeries][google.cloud.aiplatform.v1.TensorboardService.CreateTensorboardTimeSeries]. + parent (str): + Required. The resource name of the TensorboardRun to + create the TensorboardTimeSeries in. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + tensorboard_time_series (google.cloud.aiplatform_v1.types.TensorboardTimeSeries): + Required. The TensorboardTimeSeries + to create. + + This corresponds to the ``tensorboard_time_series`` 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: + google.cloud.aiplatform_v1.types.TensorboardTimeSeries: + TensorboardTimeSeries maps to times + series produced in training runs + + """ + # Create or coerce a protobuf request object. + # Quick 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, tensorboard_time_series]) + 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 tensorboard_service.CreateTensorboardTimeSeriesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, tensorboard_service.CreateTensorboardTimeSeriesRequest + ): + request = tensorboard_service.CreateTensorboardTimeSeriesRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if tensorboard_time_series is not None: + request.tensorboard_time_series = tensorboard_time_series + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.create_tensorboard_time_series + ] + + # 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 get_tensorboard_time_series( + self, + request: Union[ + tensorboard_service.GetTensorboardTimeSeriesRequest, dict + ] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> tensorboard_time_series.TensorboardTimeSeries: + r"""Gets a TensorboardTimeSeries. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_get_tensorboard_time_series(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetTensorboardTimeSeriesRequest( + name="name_value", + ) + + # Make the request + response = client.get_tensorboard_time_series(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetTensorboardTimeSeriesRequest, dict]): + The request object. Request message for + [TensorboardService.GetTensorboardTimeSeries][google.cloud.aiplatform.v1.TensorboardService.GetTensorboardTimeSeries]. + name (str): + Required. The name of the TensorboardTimeSeries + resource. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}/timeSeries/{time_series}`` + + 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: + google.cloud.aiplatform_v1.types.TensorboardTimeSeries: + TensorboardTimeSeries maps to times + series produced in training runs + + """ + # Create or coerce a protobuf request object. + # Quick 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 tensorboard_service.GetTensorboardTimeSeriesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, tensorboard_service.GetTensorboardTimeSeriesRequest): + request = tensorboard_service.GetTensorboardTimeSeriesRequest(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_tensorboard_time_series + ] + + # 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_tensorboard_time_series( + self, + request: Union[ + tensorboard_service.UpdateTensorboardTimeSeriesRequest, dict + ] = None, + *, + tensorboard_time_series: gca_tensorboard_time_series.TensorboardTimeSeries = None, + update_mask: field_mask_pb2.FieldMask = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_tensorboard_time_series.TensorboardTimeSeries: + r"""Updates a TensorboardTimeSeries. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_update_tensorboard_time_series(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + tensorboard_time_series = aiplatform_v1.TensorboardTimeSeries() + tensorboard_time_series.display_name = "display_name_value" + tensorboard_time_series.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1.UpdateTensorboardTimeSeriesRequest( + tensorboard_time_series=tensorboard_time_series, + ) + + # Make the request + response = client.update_tensorboard_time_series(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.UpdateTensorboardTimeSeriesRequest, dict]): + The request object. Request message for + [TensorboardService.UpdateTensorboardTimeSeries][google.cloud.aiplatform.v1.TensorboardService.UpdateTensorboardTimeSeries]. + tensorboard_time_series (google.cloud.aiplatform_v1.types.TensorboardTimeSeries): + Required. The TensorboardTimeSeries' ``name`` field is + used to identify the TensorboardTimeSeries to be + updated. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}/timeSeries/{time_series}`` + + This corresponds to the ``tensorboard_time_series`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Required. Field mask is used to specify the fields to be + overwritten in the TensorboardTimeSeries resource by the + update. The fields specified in the update_mask are + relative to the resource, not the full request. A field + will be overwritten if it is in the mask. If the user + does not provide a mask then all fields will be + overwritten if new values are specified. + + 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: + google.cloud.aiplatform_v1.types.TensorboardTimeSeries: + TensorboardTimeSeries maps to times + series produced in training runs + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([tensorboard_time_series, 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 tensorboard_service.UpdateTensorboardTimeSeriesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, tensorboard_service.UpdateTensorboardTimeSeriesRequest + ): + request = tensorboard_service.UpdateTensorboardTimeSeriesRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if tensorboard_time_series is not None: + request.tensorboard_time_series = tensorboard_time_series + 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_tensorboard_time_series + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + ( + ( + "tensorboard_time_series.name", + request.tensorboard_time_series.name, + ), + ) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_tensorboard_time_series( + self, + request: Union[ + tensorboard_service.ListTensorboardTimeSeriesRequest, dict + ] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListTensorboardTimeSeriesPager: + r"""Lists TensorboardTimeSeries in a Location. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_list_tensorboard_time_series(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListTensorboardTimeSeriesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboard_time_series(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListTensorboardTimeSeriesRequest, dict]): + The request object. Request message for + [TensorboardService.ListTensorboardTimeSeries][google.cloud.aiplatform.v1.TensorboardService.ListTensorboardTimeSeries]. + parent (str): + Required. The resource name of the + TensorboardRun to list + TensorboardTimeSeries. Format: + 'projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}' + + 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: + google.cloud.aiplatform_v1.services.tensorboard_service.pagers.ListTensorboardTimeSeriesPager: + Response message for + [TensorboardService.ListTensorboardTimeSeries][google.cloud.aiplatform.v1.TensorboardService.ListTensorboardTimeSeries]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 tensorboard_service.ListTensorboardTimeSeriesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, tensorboard_service.ListTensorboardTimeSeriesRequest + ): + request = tensorboard_service.ListTensorboardTimeSeriesRequest(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_tensorboard_time_series + ] + + # 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.ListTensorboardTimeSeriesPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_tensorboard_time_series( + self, + request: Union[ + tensorboard_service.DeleteTensorboardTimeSeriesRequest, dict + ] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Deletes a TensorboardTimeSeries. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_delete_tensorboard_time_series(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteTensorboardTimeSeriesRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard_time_series(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.DeleteTensorboardTimeSeriesRequest, dict]): + The request object. Request message for + [TensorboardService.DeleteTensorboardTimeSeries][google.cloud.aiplatform.v1.TensorboardService.DeleteTensorboardTimeSeries]. + name (str): + Required. The name of the TensorboardTimeSeries to be + deleted. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}/timeSeries/{time_series}`` + + 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # Create or coerce a protobuf request object. + # Quick 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 tensorboard_service.DeleteTensorboardTimeSeriesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, tensorboard_service.DeleteTensorboardTimeSeriesRequest + ): + request = tensorboard_service.DeleteTensorboardTimeSeriesRequest(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_tensorboard_time_series + ] + + # 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, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, + ) + + # Done; return the response. + return response + + def batch_read_tensorboard_time_series_data( + self, + request: Union[ + tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest, dict + ] = None, + *, + tensorboard: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> tensorboard_service.BatchReadTensorboardTimeSeriesDataResponse: + r"""Reads multiple TensorboardTimeSeries' data. The data + point number limit is 1000 for scalars, 100 for tensors + and blob references. If the number of data points stored + is less than the limit, all data will be returned. + Otherwise, that limit number of data points will be + randomly selected from this time series and returned. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_batch_read_tensorboard_time_series_data(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.BatchReadTensorboardTimeSeriesDataRequest( + tensorboard="tensorboard_value", + time_series=['time_series_value_1', 'time_series_value_2'], + ) + + # Make the request + response = client.batch_read_tensorboard_time_series_data(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.BatchReadTensorboardTimeSeriesDataRequest, dict]): + The request object. Request message for + [TensorboardService.BatchReadTensorboardTimeSeriesData][google.cloud.aiplatform.v1.TensorboardService.BatchReadTensorboardTimeSeriesData]. + tensorboard (str): + Required. The resource name of the Tensorboard + containing TensorboardTimeSeries to read data from. + Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}``. + The TensorboardTimeSeries referenced by + [time_series][google.cloud.aiplatform.v1.BatchReadTensorboardTimeSeriesDataRequest.time_series] + must be sub resources of this Tensorboard. + + This corresponds to the ``tensorboard`` 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: + google.cloud.aiplatform_v1.types.BatchReadTensorboardTimeSeriesDataResponse: + Response message for + [TensorboardService.BatchReadTensorboardTimeSeriesData][google.cloud.aiplatform.v1.TensorboardService.BatchReadTensorboardTimeSeriesData]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([tensorboard]) + 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 tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest + ): + request = tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest( + request + ) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if tensorboard is not None: + request.tensorboard = tensorboard + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.batch_read_tensorboard_time_series_data + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("tensorboard", request.tensorboard),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def read_tensorboard_time_series_data( + self, + request: Union[ + tensorboard_service.ReadTensorboardTimeSeriesDataRequest, dict + ] = None, + *, + tensorboard_time_series: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> tensorboard_service.ReadTensorboardTimeSeriesDataResponse: + r"""Reads a TensorboardTimeSeries' data. By default, if the number + of data points stored is less than 1000, all data will be + returned. Otherwise, 1000 data points will be randomly selected + from this time series and returned. This value can be changed by + changing max_data_points, which can't be greater than 10k. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_read_tensorboard_time_series_data(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ReadTensorboardTimeSeriesDataRequest( + tensorboard_time_series="tensorboard_time_series_value", + ) + + # Make the request + response = client.read_tensorboard_time_series_data(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ReadTensorboardTimeSeriesDataRequest, dict]): + The request object. Request message for + [TensorboardService.ReadTensorboardTimeSeriesData][google.cloud.aiplatform.v1.TensorboardService.ReadTensorboardTimeSeriesData]. + tensorboard_time_series (str): + Required. The resource name of the TensorboardTimeSeries + to read data from. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}/timeSeries/{time_series}`` + + This corresponds to the ``tensorboard_time_series`` 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: + google.cloud.aiplatform_v1.types.ReadTensorboardTimeSeriesDataResponse: + Response message for + [TensorboardService.ReadTensorboardTimeSeriesData][google.cloud.aiplatform.v1.TensorboardService.ReadTensorboardTimeSeriesData]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([tensorboard_time_series]) + 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 tensorboard_service.ReadTensorboardTimeSeriesDataRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, tensorboard_service.ReadTensorboardTimeSeriesDataRequest + ): + request = tensorboard_service.ReadTensorboardTimeSeriesDataRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if tensorboard_time_series is not None: + request.tensorboard_time_series = tensorboard_time_series + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.read_tensorboard_time_series_data + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("tensorboard_time_series", request.tensorboard_time_series),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def read_tensorboard_blob_data( + self, + request: Union[tensorboard_service.ReadTensorboardBlobDataRequest, dict] = None, + *, + time_series: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> Iterable[tensorboard_service.ReadTensorboardBlobDataResponse]: + r"""Gets bytes of TensorboardBlobs. + This is to allow reading blob data stored in consumer + project's Cloud Storage bucket without users having to + obtain Cloud Storage access permission. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_read_tensorboard_blob_data(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ReadTensorboardBlobDataRequest( + time_series="time_series_value", + ) + + # Make the request + stream = client.read_tensorboard_blob_data(request=request) + + # Handle the response + for response in stream: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ReadTensorboardBlobDataRequest, dict]): + The request object. Request message for + [TensorboardService.ReadTensorboardBlobData][google.cloud.aiplatform.v1.TensorboardService.ReadTensorboardBlobData]. + time_series (str): + Required. The resource name of the TensorboardTimeSeries + to list Blobs. Format: + 'projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}/timeSeries/{time_series}' + + This corresponds to the ``time_series`` 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: + Iterable[google.cloud.aiplatform_v1.types.ReadTensorboardBlobDataResponse]: + Response message for + [TensorboardService.ReadTensorboardBlobData][google.cloud.aiplatform.v1.TensorboardService.ReadTensorboardBlobData]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([time_series]) + 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 tensorboard_service.ReadTensorboardBlobDataRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, tensorboard_service.ReadTensorboardBlobDataRequest): + request = tensorboard_service.ReadTensorboardBlobDataRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if time_series is not None: + request.time_series = time_series + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.read_tensorboard_blob_data + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("time_series", request.time_series),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def write_tensorboard_experiment_data( + self, + request: Union[ + tensorboard_service.WriteTensorboardExperimentDataRequest, dict + ] = None, + *, + tensorboard_experiment: str = None, + write_run_data_requests: Sequence[ + tensorboard_service.WriteTensorboardRunDataRequest + ] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> tensorboard_service.WriteTensorboardExperimentDataResponse: + r"""Write time series data points of multiple + TensorboardTimeSeries in multiple TensorboardRun's. If + any data fail to be ingested, an error will be returned. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_write_tensorboard_experiment_data(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + write_run_data_requests = aiplatform_v1.WriteTensorboardRunDataRequest() + write_run_data_requests.tensorboard_run = "tensorboard_run_value" + write_run_data_requests.time_series_data.tensorboard_time_series_id = "tensorboard_time_series_id_value" + write_run_data_requests.time_series_data.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1.WriteTensorboardExperimentDataRequest( + tensorboard_experiment="tensorboard_experiment_value", + write_run_data_requests=write_run_data_requests, + ) + + # Make the request + response = client.write_tensorboard_experiment_data(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.WriteTensorboardExperimentDataRequest, dict]): + The request object. Request message for + [TensorboardService.WriteTensorboardExperimentData][google.cloud.aiplatform.v1.TensorboardService.WriteTensorboardExperimentData]. + tensorboard_experiment (str): + Required. The resource name of the TensorboardExperiment + to write data to. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` + + This corresponds to the ``tensorboard_experiment`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + write_run_data_requests (Sequence[google.cloud.aiplatform_v1.types.WriteTensorboardRunDataRequest]): + Required. Requests containing per-run + TensorboardTimeSeries data to write. + + This corresponds to the ``write_run_data_requests`` 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: + google.cloud.aiplatform_v1.types.WriteTensorboardExperimentDataResponse: + Response message for + [TensorboardService.WriteTensorboardExperimentData][google.cloud.aiplatform.v1.TensorboardService.WriteTensorboardExperimentData]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([tensorboard_experiment, write_run_data_requests]) + 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 tensorboard_service.WriteTensorboardExperimentDataRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, tensorboard_service.WriteTensorboardExperimentDataRequest + ): + request = tensorboard_service.WriteTensorboardExperimentDataRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if tensorboard_experiment is not None: + request.tensorboard_experiment = tensorboard_experiment + if write_run_data_requests is not None: + request.write_run_data_requests = write_run_data_requests + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.write_tensorboard_experiment_data + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("tensorboard_experiment", request.tensorboard_experiment),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def write_tensorboard_run_data( + self, + request: Union[tensorboard_service.WriteTensorboardRunDataRequest, dict] = None, + *, + tensorboard_run: str = None, + time_series_data: Sequence[tensorboard_data.TimeSeriesData] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> tensorboard_service.WriteTensorboardRunDataResponse: + r"""Write time series data points into multiple + TensorboardTimeSeries under a TensorboardRun. If any + data fail to be ingested, an error will be returned. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_write_tensorboard_run_data(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + time_series_data = aiplatform_v1.TimeSeriesData() + time_series_data.tensorboard_time_series_id = "tensorboard_time_series_id_value" + time_series_data.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1.WriteTensorboardRunDataRequest( + tensorboard_run="tensorboard_run_value", + time_series_data=time_series_data, + ) + + # Make the request + response = client.write_tensorboard_run_data(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.WriteTensorboardRunDataRequest, dict]): + The request object. Request message for + [TensorboardService.WriteTensorboardRunData][google.cloud.aiplatform.v1.TensorboardService.WriteTensorboardRunData]. + tensorboard_run (str): + Required. The resource name of the TensorboardRun to + write data to. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}`` + + This corresponds to the ``tensorboard_run`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + time_series_data (Sequence[google.cloud.aiplatform_v1.types.TimeSeriesData]): + Required. The TensorboardTimeSeries + data to write. Values with in a time + series are indexed by their step value. + Repeated writes to the same step will + overwrite the existing value for that + step. + The upper limit of data points per write + request is 5000. + + This corresponds to the ``time_series_data`` 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: + google.cloud.aiplatform_v1.types.WriteTensorboardRunDataResponse: + Response message for + [TensorboardService.WriteTensorboardRunData][google.cloud.aiplatform.v1.TensorboardService.WriteTensorboardRunData]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([tensorboard_run, time_series_data]) + 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 tensorboard_service.WriteTensorboardRunDataRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, tensorboard_service.WriteTensorboardRunDataRequest): + request = tensorboard_service.WriteTensorboardRunDataRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if tensorboard_run is not None: + request.tensorboard_run = tensorboard_run + if time_series_data is not None: + request.time_series_data = time_series_data + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.write_tensorboard_run_data + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("tensorboard_run", request.tensorboard_run),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def export_tensorboard_time_series_data( + self, + request: Union[ + tensorboard_service.ExportTensorboardTimeSeriesDataRequest, dict + ] = None, + *, + tensorboard_time_series: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ExportTensorboardTimeSeriesDataPager: + r"""Exports a TensorboardTimeSeries' data. Data is + returned in paginated responses. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_export_tensorboard_time_series_data(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ExportTensorboardTimeSeriesDataRequest( + tensorboard_time_series="tensorboard_time_series_value", + ) + + # Make the request + page_result = client.export_tensorboard_time_series_data(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ExportTensorboardTimeSeriesDataRequest, dict]): + The request object. Request message for + [TensorboardService.ExportTensorboardTimeSeriesData][google.cloud.aiplatform.v1.TensorboardService.ExportTensorboardTimeSeriesData]. + tensorboard_time_series (str): + Required. The resource name of the TensorboardTimeSeries + to export data from. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}/timeSeries/{time_series}`` + + This corresponds to the ``tensorboard_time_series`` 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: + google.cloud.aiplatform_v1.services.tensorboard_service.pagers.ExportTensorboardTimeSeriesDataPager: + Response message for + [TensorboardService.ExportTensorboardTimeSeriesData][google.cloud.aiplatform.v1.TensorboardService.ExportTensorboardTimeSeriesData]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([tensorboard_time_series]) + 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 tensorboard_service.ExportTensorboardTimeSeriesDataRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, tensorboard_service.ExportTensorboardTimeSeriesDataRequest + ): + request = tensorboard_service.ExportTensorboardTimeSeriesDataRequest( + request + ) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if tensorboard_time_series is not None: + request.tensorboard_time_series = tensorboard_time_series + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.export_tensorboard_time_series_data + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("tensorboard_time_series", request.tensorboard_time_series),) + ), + ) + + # 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.ExportTensorboardTimeSeriesDataPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_operations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.delete_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.wait_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_location, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_locations, + default_timeout=None, + 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 = 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-aiplatform", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ("TensorboardServiceClient",) diff --git a/google/cloud/aiplatform_v1/services/tensorboard_service/pagers.py b/google/cloud/aiplatform_v1/services/tensorboard_service/pagers.py new file mode 100644 index 0000000000..950be52fe4 --- /dev/null +++ b/google/cloud/aiplatform_v1/services/tensorboard_service/pagers.py @@ -0,0 +1,698 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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 typing import ( + Any, + AsyncIterator, + Awaitable, + Callable, + Sequence, + Tuple, + Optional, + Iterator, +) + +from google.cloud.aiplatform_v1.types import tensorboard +from google.cloud.aiplatform_v1.types import tensorboard_data +from google.cloud.aiplatform_v1.types import tensorboard_experiment +from google.cloud.aiplatform_v1.types import tensorboard_run +from google.cloud.aiplatform_v1.types import tensorboard_service +from google.cloud.aiplatform_v1.types import tensorboard_time_series + + +class ListTensorboardsPager: + """A pager for iterating through ``list_tensorboards`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListTensorboardsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``tensorboards`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListTensorboards`` requests and continue to iterate + through the ``tensorboards`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListTensorboardsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., tensorboard_service.ListTensorboardsResponse], + request: tensorboard_service.ListTensorboardsRequest, + response: tensorboard_service.ListTensorboardsResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListTensorboardsRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListTensorboardsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = tensorboard_service.ListTensorboardsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[tensorboard_service.ListTensorboardsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterator[tensorboard.Tensorboard]: + for page in self.pages: + yield from page.tensorboards + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListTensorboardsAsyncPager: + """A pager for iterating through ``list_tensorboards`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListTensorboardsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``tensorboards`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListTensorboards`` requests and continue to iterate + through the ``tensorboards`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListTensorboardsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., Awaitable[tensorboard_service.ListTensorboardsResponse]], + request: tensorboard_service.ListTensorboardsRequest, + response: tensorboard_service.ListTensorboardsResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListTensorboardsRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListTensorboardsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = tensorboard_service.ListTensorboardsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages( + self, + ) -> AsyncIterator[tensorboard_service.ListTensorboardsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + + def __aiter__(self) -> AsyncIterator[tensorboard.Tensorboard]: + async def async_generator(): + async for page in self.pages: + for response in page.tensorboards: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListTensorboardExperimentsPager: + """A pager for iterating through ``list_tensorboard_experiments`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListTensorboardExperimentsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``tensorboard_experiments`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListTensorboardExperiments`` requests and continue to iterate + through the ``tensorboard_experiments`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListTensorboardExperimentsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., tensorboard_service.ListTensorboardExperimentsResponse], + request: tensorboard_service.ListTensorboardExperimentsRequest, + response: tensorboard_service.ListTensorboardExperimentsResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListTensorboardExperimentsRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListTensorboardExperimentsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = tensorboard_service.ListTensorboardExperimentsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[tensorboard_service.ListTensorboardExperimentsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterator[tensorboard_experiment.TensorboardExperiment]: + for page in self.pages: + yield from page.tensorboard_experiments + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListTensorboardExperimentsAsyncPager: + """A pager for iterating through ``list_tensorboard_experiments`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListTensorboardExperimentsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``tensorboard_experiments`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListTensorboardExperiments`` requests and continue to iterate + through the ``tensorboard_experiments`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListTensorboardExperimentsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[ + ..., Awaitable[tensorboard_service.ListTensorboardExperimentsResponse] + ], + request: tensorboard_service.ListTensorboardExperimentsRequest, + response: tensorboard_service.ListTensorboardExperimentsResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListTensorboardExperimentsRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListTensorboardExperimentsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = tensorboard_service.ListTensorboardExperimentsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages( + self, + ) -> AsyncIterator[tensorboard_service.ListTensorboardExperimentsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + + def __aiter__(self) -> AsyncIterator[tensorboard_experiment.TensorboardExperiment]: + async def async_generator(): + async for page in self.pages: + for response in page.tensorboard_experiments: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListTensorboardRunsPager: + """A pager for iterating through ``list_tensorboard_runs`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListTensorboardRunsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``tensorboard_runs`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListTensorboardRuns`` requests and continue to iterate + through the ``tensorboard_runs`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListTensorboardRunsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., tensorboard_service.ListTensorboardRunsResponse], + request: tensorboard_service.ListTensorboardRunsRequest, + response: tensorboard_service.ListTensorboardRunsResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListTensorboardRunsRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListTensorboardRunsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = tensorboard_service.ListTensorboardRunsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[tensorboard_service.ListTensorboardRunsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterator[tensorboard_run.TensorboardRun]: + for page in self.pages: + yield from page.tensorboard_runs + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListTensorboardRunsAsyncPager: + """A pager for iterating through ``list_tensorboard_runs`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListTensorboardRunsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``tensorboard_runs`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListTensorboardRuns`` requests and continue to iterate + through the ``tensorboard_runs`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListTensorboardRunsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[ + ..., Awaitable[tensorboard_service.ListTensorboardRunsResponse] + ], + request: tensorboard_service.ListTensorboardRunsRequest, + response: tensorboard_service.ListTensorboardRunsResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListTensorboardRunsRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListTensorboardRunsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = tensorboard_service.ListTensorboardRunsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages( + self, + ) -> AsyncIterator[tensorboard_service.ListTensorboardRunsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + + def __aiter__(self) -> AsyncIterator[tensorboard_run.TensorboardRun]: + async def async_generator(): + async for page in self.pages: + for response in page.tensorboard_runs: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListTensorboardTimeSeriesPager: + """A pager for iterating through ``list_tensorboard_time_series`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListTensorboardTimeSeriesResponse` object, and + provides an ``__iter__`` method to iterate through its + ``tensorboard_time_series`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListTensorboardTimeSeries`` requests and continue to iterate + through the ``tensorboard_time_series`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListTensorboardTimeSeriesResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., tensorboard_service.ListTensorboardTimeSeriesResponse], + request: tensorboard_service.ListTensorboardTimeSeriesRequest, + response: tensorboard_service.ListTensorboardTimeSeriesResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListTensorboardTimeSeriesRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListTensorboardTimeSeriesResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = tensorboard_service.ListTensorboardTimeSeriesRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[tensorboard_service.ListTensorboardTimeSeriesResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterator[tensorboard_time_series.TensorboardTimeSeries]: + for page in self.pages: + yield from page.tensorboard_time_series + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListTensorboardTimeSeriesAsyncPager: + """A pager for iterating through ``list_tensorboard_time_series`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListTensorboardTimeSeriesResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``tensorboard_time_series`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListTensorboardTimeSeries`` requests and continue to iterate + through the ``tensorboard_time_series`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListTensorboardTimeSeriesResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[ + ..., Awaitable[tensorboard_service.ListTensorboardTimeSeriesResponse] + ], + request: tensorboard_service.ListTensorboardTimeSeriesRequest, + response: tensorboard_service.ListTensorboardTimeSeriesResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListTensorboardTimeSeriesRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListTensorboardTimeSeriesResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = tensorboard_service.ListTensorboardTimeSeriesRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages( + self, + ) -> AsyncIterator[tensorboard_service.ListTensorboardTimeSeriesResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + + def __aiter__(self) -> AsyncIterator[tensorboard_time_series.TensorboardTimeSeries]: + async def async_generator(): + async for page in self.pages: + for response in page.tensorboard_time_series: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ExportTensorboardTimeSeriesDataPager: + """A pager for iterating through ``export_tensorboard_time_series_data`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ExportTensorboardTimeSeriesDataResponse` object, and + provides an ``__iter__`` method to iterate through its + ``time_series_data_points`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ExportTensorboardTimeSeriesData`` requests and continue to iterate + through the ``time_series_data_points`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ExportTensorboardTimeSeriesDataResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[ + ..., tensorboard_service.ExportTensorboardTimeSeriesDataResponse + ], + request: tensorboard_service.ExportTensorboardTimeSeriesDataRequest, + response: tensorboard_service.ExportTensorboardTimeSeriesDataResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ExportTensorboardTimeSeriesDataRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ExportTensorboardTimeSeriesDataResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = tensorboard_service.ExportTensorboardTimeSeriesDataRequest( + request + ) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages( + self, + ) -> Iterator[tensorboard_service.ExportTensorboardTimeSeriesDataResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterator[tensorboard_data.TimeSeriesDataPoint]: + for page in self.pages: + yield from page.time_series_data_points + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ExportTensorboardTimeSeriesDataAsyncPager: + """A pager for iterating through ``export_tensorboard_time_series_data`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ExportTensorboardTimeSeriesDataResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``time_series_data_points`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ExportTensorboardTimeSeriesData`` requests and continue to iterate + through the ``time_series_data_points`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ExportTensorboardTimeSeriesDataResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[ + ..., Awaitable[tensorboard_service.ExportTensorboardTimeSeriesDataResponse] + ], + request: tensorboard_service.ExportTensorboardTimeSeriesDataRequest, + response: tensorboard_service.ExportTensorboardTimeSeriesDataResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ExportTensorboardTimeSeriesDataRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ExportTensorboardTimeSeriesDataResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = tensorboard_service.ExportTensorboardTimeSeriesDataRequest( + request + ) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages( + self, + ) -> AsyncIterator[tensorboard_service.ExportTensorboardTimeSeriesDataResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + + def __aiter__(self) -> AsyncIterator[tensorboard_data.TimeSeriesDataPoint]: + async def async_generator(): + async for page in self.pages: + for response in page.time_series_data_points: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) diff --git a/google/cloud/aiplatform_v1/services/tensorboard_service/transports/__init__.py b/google/cloud/aiplatform_v1/services/tensorboard_service/transports/__init__.py new file mode 100644 index 0000000000..645295a44f --- /dev/null +++ b/google/cloud/aiplatform_v1/services/tensorboard_service/transports/__init__.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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 typing import Dict, Type + +from .base import TensorboardServiceTransport +from .grpc import TensorboardServiceGrpcTransport +from .grpc_asyncio import TensorboardServiceGrpcAsyncIOTransport + + +# Compile a registry of transports. +_transport_registry = ( + OrderedDict() +) # type: Dict[str, Type[TensorboardServiceTransport]] +_transport_registry["grpc"] = TensorboardServiceGrpcTransport +_transport_registry["grpc_asyncio"] = TensorboardServiceGrpcAsyncIOTransport + +__all__ = ( + "TensorboardServiceTransport", + "TensorboardServiceGrpcTransport", + "TensorboardServiceGrpcAsyncIOTransport", +) diff --git a/google/cloud/aiplatform_v1/services/tensorboard_service/transports/base.py b/google/cloud/aiplatform_v1/services/tensorboard_service/transports/base.py new file mode 100644 index 0000000000..2023fffccf --- /dev/null +++ b/google/cloud/aiplatform_v1/services/tensorboard_service/transports/base.py @@ -0,0 +1,712 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import abc +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +import pkg_resources + +import google.auth # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import operations_v1 +from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore + +from google.cloud.aiplatform_v1.types import tensorboard +from google.cloud.aiplatform_v1.types import tensorboard_experiment +from google.cloud.aiplatform_v1.types import ( + tensorboard_experiment as gca_tensorboard_experiment, +) +from google.cloud.aiplatform_v1.types import tensorboard_run +from google.cloud.aiplatform_v1.types import tensorboard_run as gca_tensorboard_run +from google.cloud.aiplatform_v1.types import tensorboard_service +from google.cloud.aiplatform_v1.types import tensorboard_time_series +from google.cloud.aiplatform_v1.types import ( + tensorboard_time_series as gca_tensorboard_time_series, +) +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.longrunning import operations_pb2 # type: ignore + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-aiplatform", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +class TensorboardServiceTransport(abc.ABC): + """Abstract transport class for TensorboardService.""" + + AUTH_SCOPES = ( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/cloud-platform.read-only", + ) + + DEFAULT_HOST: str = "aiplatform.googleapis.com" + + def __init__( + self, + *, + host: str = DEFAULT_HOST, + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + **kwargs, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + 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. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is mutually exclusive with credentials. + scopes (Optional[Sequence[str]]): A list of scopes. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + 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. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + """ + + # Save the hostname. Default to port 443 (HTTPS) if none is specified. + if ":" not in host: + host += ":443" + self._host = host + + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} + + # Save the scopes. + self._scopes = scopes + + # If no credentials are provided, then determine the appropriate + # defaults. + if credentials and credentials_file: + raise core_exceptions.DuplicateCredentialArgs( + "'credentials_file' and 'credentials' are mutually exclusive" + ) + + if credentials_file is not None: + credentials, _ = google.auth.load_credentials_from_file( + credentials_file, **scopes_kwargs, quota_project_id=quota_project_id + ) + elif credentials is None: + credentials, _ = google.auth.default( + **scopes_kwargs, quota_project_id=quota_project_id + ) + + # If the credentials are service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + + # Save the credentials. + self._credentials = credentials + + def _prep_wrapped_messages(self, client_info): + # Precompute the wrapped methods. + self._wrapped_methods = { + self.create_tensorboard: gapic_v1.method.wrap_method( + self.create_tensorboard, + default_timeout=None, + client_info=client_info, + ), + self.get_tensorboard: gapic_v1.method.wrap_method( + self.get_tensorboard, + default_timeout=None, + client_info=client_info, + ), + self.update_tensorboard: gapic_v1.method.wrap_method( + self.update_tensorboard, + default_timeout=None, + client_info=client_info, + ), + self.list_tensorboards: gapic_v1.method.wrap_method( + self.list_tensorboards, + default_timeout=None, + client_info=client_info, + ), + self.delete_tensorboard: gapic_v1.method.wrap_method( + self.delete_tensorboard, + default_timeout=None, + client_info=client_info, + ), + self.create_tensorboard_experiment: gapic_v1.method.wrap_method( + self.create_tensorboard_experiment, + default_timeout=None, + client_info=client_info, + ), + self.get_tensorboard_experiment: gapic_v1.method.wrap_method( + self.get_tensorboard_experiment, + default_timeout=None, + client_info=client_info, + ), + self.update_tensorboard_experiment: gapic_v1.method.wrap_method( + self.update_tensorboard_experiment, + default_timeout=None, + client_info=client_info, + ), + self.list_tensorboard_experiments: gapic_v1.method.wrap_method( + self.list_tensorboard_experiments, + default_timeout=None, + client_info=client_info, + ), + self.delete_tensorboard_experiment: gapic_v1.method.wrap_method( + self.delete_tensorboard_experiment, + default_timeout=None, + client_info=client_info, + ), + self.create_tensorboard_run: gapic_v1.method.wrap_method( + self.create_tensorboard_run, + default_timeout=None, + client_info=client_info, + ), + self.batch_create_tensorboard_runs: gapic_v1.method.wrap_method( + self.batch_create_tensorboard_runs, + default_timeout=None, + client_info=client_info, + ), + self.get_tensorboard_run: gapic_v1.method.wrap_method( + self.get_tensorboard_run, + default_timeout=None, + client_info=client_info, + ), + self.update_tensorboard_run: gapic_v1.method.wrap_method( + self.update_tensorboard_run, + default_timeout=None, + client_info=client_info, + ), + self.list_tensorboard_runs: gapic_v1.method.wrap_method( + self.list_tensorboard_runs, + default_timeout=None, + client_info=client_info, + ), + self.delete_tensorboard_run: gapic_v1.method.wrap_method( + self.delete_tensorboard_run, + default_timeout=None, + client_info=client_info, + ), + self.batch_create_tensorboard_time_series: gapic_v1.method.wrap_method( + self.batch_create_tensorboard_time_series, + default_timeout=None, + client_info=client_info, + ), + self.create_tensorboard_time_series: gapic_v1.method.wrap_method( + self.create_tensorboard_time_series, + default_timeout=None, + client_info=client_info, + ), + self.get_tensorboard_time_series: gapic_v1.method.wrap_method( + self.get_tensorboard_time_series, + default_timeout=None, + client_info=client_info, + ), + self.update_tensorboard_time_series: gapic_v1.method.wrap_method( + self.update_tensorboard_time_series, + default_timeout=None, + client_info=client_info, + ), + self.list_tensorboard_time_series: gapic_v1.method.wrap_method( + self.list_tensorboard_time_series, + default_timeout=None, + client_info=client_info, + ), + self.delete_tensorboard_time_series: gapic_v1.method.wrap_method( + self.delete_tensorboard_time_series, + default_timeout=None, + client_info=client_info, + ), + self.batch_read_tensorboard_time_series_data: gapic_v1.method.wrap_method( + self.batch_read_tensorboard_time_series_data, + default_timeout=None, + client_info=client_info, + ), + self.read_tensorboard_time_series_data: gapic_v1.method.wrap_method( + self.read_tensorboard_time_series_data, + default_timeout=None, + client_info=client_info, + ), + self.read_tensorboard_blob_data: gapic_v1.method.wrap_method( + self.read_tensorboard_blob_data, + default_timeout=None, + client_info=client_info, + ), + self.write_tensorboard_experiment_data: gapic_v1.method.wrap_method( + self.write_tensorboard_experiment_data, + default_timeout=None, + client_info=client_info, + ), + self.write_tensorboard_run_data: gapic_v1.method.wrap_method( + self.write_tensorboard_run_data, + default_timeout=None, + client_info=client_info, + ), + self.export_tensorboard_time_series_data: gapic_v1.method.wrap_method( + self.export_tensorboard_time_series_data, + default_timeout=None, + client_info=client_info, + ), + } + + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + + @property + def operations_client(self): + """Return the client designed to process long-running operations.""" + raise NotImplementedError() + + @property + def create_tensorboard( + self, + ) -> Callable[ + [tensorboard_service.CreateTensorboardRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def get_tensorboard( + self, + ) -> Callable[ + [tensorboard_service.GetTensorboardRequest], + Union[tensorboard.Tensorboard, Awaitable[tensorboard.Tensorboard]], + ]: + raise NotImplementedError() + + @property + def update_tensorboard( + self, + ) -> Callable[ + [tensorboard_service.UpdateTensorboardRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def list_tensorboards( + self, + ) -> Callable[ + [tensorboard_service.ListTensorboardsRequest], + Union[ + tensorboard_service.ListTensorboardsResponse, + Awaitable[tensorboard_service.ListTensorboardsResponse], + ], + ]: + raise NotImplementedError() + + @property + def delete_tensorboard( + self, + ) -> Callable[ + [tensorboard_service.DeleteTensorboardRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def create_tensorboard_experiment( + self, + ) -> Callable[ + [tensorboard_service.CreateTensorboardExperimentRequest], + Union[ + gca_tensorboard_experiment.TensorboardExperiment, + Awaitable[gca_tensorboard_experiment.TensorboardExperiment], + ], + ]: + raise NotImplementedError() + + @property + def get_tensorboard_experiment( + self, + ) -> Callable[ + [tensorboard_service.GetTensorboardExperimentRequest], + Union[ + tensorboard_experiment.TensorboardExperiment, + Awaitable[tensorboard_experiment.TensorboardExperiment], + ], + ]: + raise NotImplementedError() + + @property + def update_tensorboard_experiment( + self, + ) -> Callable[ + [tensorboard_service.UpdateTensorboardExperimentRequest], + Union[ + gca_tensorboard_experiment.TensorboardExperiment, + Awaitable[gca_tensorboard_experiment.TensorboardExperiment], + ], + ]: + raise NotImplementedError() + + @property + def list_tensorboard_experiments( + self, + ) -> Callable[ + [tensorboard_service.ListTensorboardExperimentsRequest], + Union[ + tensorboard_service.ListTensorboardExperimentsResponse, + Awaitable[tensorboard_service.ListTensorboardExperimentsResponse], + ], + ]: + raise NotImplementedError() + + @property + def delete_tensorboard_experiment( + self, + ) -> Callable[ + [tensorboard_service.DeleteTensorboardExperimentRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def create_tensorboard_run( + self, + ) -> Callable[ + [tensorboard_service.CreateTensorboardRunRequest], + Union[ + gca_tensorboard_run.TensorboardRun, + Awaitable[gca_tensorboard_run.TensorboardRun], + ], + ]: + raise NotImplementedError() + + @property + def batch_create_tensorboard_runs( + self, + ) -> Callable[ + [tensorboard_service.BatchCreateTensorboardRunsRequest], + Union[ + tensorboard_service.BatchCreateTensorboardRunsResponse, + Awaitable[tensorboard_service.BatchCreateTensorboardRunsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_tensorboard_run( + self, + ) -> Callable[ + [tensorboard_service.GetTensorboardRunRequest], + Union[ + tensorboard_run.TensorboardRun, Awaitable[tensorboard_run.TensorboardRun] + ], + ]: + raise NotImplementedError() + + @property + def update_tensorboard_run( + self, + ) -> Callable[ + [tensorboard_service.UpdateTensorboardRunRequest], + Union[ + gca_tensorboard_run.TensorboardRun, + Awaitable[gca_tensorboard_run.TensorboardRun], + ], + ]: + raise NotImplementedError() + + @property + def list_tensorboard_runs( + self, + ) -> Callable[ + [tensorboard_service.ListTensorboardRunsRequest], + Union[ + tensorboard_service.ListTensorboardRunsResponse, + Awaitable[tensorboard_service.ListTensorboardRunsResponse], + ], + ]: + raise NotImplementedError() + + @property + def delete_tensorboard_run( + self, + ) -> Callable[ + [tensorboard_service.DeleteTensorboardRunRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def batch_create_tensorboard_time_series( + self, + ) -> Callable[ + [tensorboard_service.BatchCreateTensorboardTimeSeriesRequest], + Union[ + tensorboard_service.BatchCreateTensorboardTimeSeriesResponse, + Awaitable[tensorboard_service.BatchCreateTensorboardTimeSeriesResponse], + ], + ]: + raise NotImplementedError() + + @property + def create_tensorboard_time_series( + self, + ) -> Callable[ + [tensorboard_service.CreateTensorboardTimeSeriesRequest], + Union[ + gca_tensorboard_time_series.TensorboardTimeSeries, + Awaitable[gca_tensorboard_time_series.TensorboardTimeSeries], + ], + ]: + raise NotImplementedError() + + @property + def get_tensorboard_time_series( + self, + ) -> Callable[ + [tensorboard_service.GetTensorboardTimeSeriesRequest], + Union[ + tensorboard_time_series.TensorboardTimeSeries, + Awaitable[tensorboard_time_series.TensorboardTimeSeries], + ], + ]: + raise NotImplementedError() + + @property + def update_tensorboard_time_series( + self, + ) -> Callable[ + [tensorboard_service.UpdateTensorboardTimeSeriesRequest], + Union[ + gca_tensorboard_time_series.TensorboardTimeSeries, + Awaitable[gca_tensorboard_time_series.TensorboardTimeSeries], + ], + ]: + raise NotImplementedError() + + @property + def list_tensorboard_time_series( + self, + ) -> Callable[ + [tensorboard_service.ListTensorboardTimeSeriesRequest], + Union[ + tensorboard_service.ListTensorboardTimeSeriesResponse, + Awaitable[tensorboard_service.ListTensorboardTimeSeriesResponse], + ], + ]: + raise NotImplementedError() + + @property + def delete_tensorboard_time_series( + self, + ) -> Callable[ + [tensorboard_service.DeleteTensorboardTimeSeriesRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def batch_read_tensorboard_time_series_data( + self, + ) -> Callable[ + [tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest], + Union[ + tensorboard_service.BatchReadTensorboardTimeSeriesDataResponse, + Awaitable[tensorboard_service.BatchReadTensorboardTimeSeriesDataResponse], + ], + ]: + raise NotImplementedError() + + @property + def read_tensorboard_time_series_data( + self, + ) -> Callable[ + [tensorboard_service.ReadTensorboardTimeSeriesDataRequest], + Union[ + tensorboard_service.ReadTensorboardTimeSeriesDataResponse, + Awaitable[tensorboard_service.ReadTensorboardTimeSeriesDataResponse], + ], + ]: + raise NotImplementedError() + + @property + def read_tensorboard_blob_data( + self, + ) -> Callable[ + [tensorboard_service.ReadTensorboardBlobDataRequest], + Union[ + tensorboard_service.ReadTensorboardBlobDataResponse, + Awaitable[tensorboard_service.ReadTensorboardBlobDataResponse], + ], + ]: + raise NotImplementedError() + + @property + def write_tensorboard_experiment_data( + self, + ) -> Callable[ + [tensorboard_service.WriteTensorboardExperimentDataRequest], + Union[ + tensorboard_service.WriteTensorboardExperimentDataResponse, + Awaitable[tensorboard_service.WriteTensorboardExperimentDataResponse], + ], + ]: + raise NotImplementedError() + + @property + def write_tensorboard_run_data( + self, + ) -> Callable[ + [tensorboard_service.WriteTensorboardRunDataRequest], + Union[ + tensorboard_service.WriteTensorboardRunDataResponse, + Awaitable[tensorboard_service.WriteTensorboardRunDataResponse], + ], + ]: + raise NotImplementedError() + + @property + def export_tensorboard_time_series_data( + self, + ) -> Callable[ + [tensorboard_service.ExportTensorboardTimeSeriesDataRequest], + Union[ + tensorboard_service.ExportTensorboardTimeSeriesDataResponse, + Awaitable[tensorboard_service.ExportTensorboardTimeSeriesDataResponse], + ], + ]: + raise NotImplementedError() + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], + Union[ + operations_pb2.ListOperationsResponse, + Awaitable[operations_pb2.ListOperationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None,]: + raise NotImplementedError() + + @property + def wait_operation( + self, + ) -> Callable[ + [operations_pb2.WaitOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def set_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def get_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_location( + self, + ) -> Callable[ + [locations_pb2.GetLocationRequest], + Union[locations_pb2.Location, Awaitable[locations_pb2.Location]], + ]: + raise NotImplementedError() + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], + Union[ + locations_pb2.ListLocationsResponse, + Awaitable[locations_pb2.ListLocationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + + +__all__ = ("TensorboardServiceTransport",) diff --git a/google/cloud/aiplatform_v1/services/tensorboard_service/transports/grpc.py b/google/cloud/aiplatform_v1/services/tensorboard_service/transports/grpc.py new file mode 100644 index 0000000000..1f101864c5 --- /dev/null +++ b/google/cloud/aiplatform_v1/services/tensorboard_service/transports/grpc.py @@ -0,0 +1,1324 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import warnings +from typing import Callable, Dict, Optional, Sequence, Tuple, Union + +from google.api_core import grpc_helpers +from google.api_core import operations_v1 +from google.api_core import gapic_v1 +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore + +import grpc # type: ignore + +from google.cloud.aiplatform_v1.types import tensorboard +from google.cloud.aiplatform_v1.types import tensorboard_experiment +from google.cloud.aiplatform_v1.types import ( + tensorboard_experiment as gca_tensorboard_experiment, +) +from google.cloud.aiplatform_v1.types import tensorboard_run +from google.cloud.aiplatform_v1.types import tensorboard_run as gca_tensorboard_run +from google.cloud.aiplatform_v1.types import tensorboard_service +from google.cloud.aiplatform_v1.types import tensorboard_time_series +from google.cloud.aiplatform_v1.types import ( + tensorboard_time_series as gca_tensorboard_time_series, +) +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.longrunning import operations_pb2 # type: ignore +from .base import TensorboardServiceTransport, DEFAULT_CLIENT_INFO + + +class TensorboardServiceGrpcTransport(TensorboardServiceTransport): + """gRPC backend transport for TensorboardService. + + TensorboardService + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + + _stubs: Dict[str, Callable] + + def __init__( + self, + *, + host: str = "aiplatform.googleapis.com", + credentials: ga_credentials.Credentials = None, + credentials_file: str = None, + scopes: Sequence[str] = None, + channel: grpc.Channel = None, + api_mtls_endpoint: str = None, + client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, + ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + 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. + This argument is ignored if ``channel`` is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional(Sequence[str])): A list of scopes. This argument is + ignored if ``channel`` is provided. + channel (Optional[grpc.Channel]): A ``Channel`` instance through + which to make calls. + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or application default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for the grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure a mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + 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. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + self._grpc_channel = None + self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client: Optional[operations_v1.OperationsClient] = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + + if channel: + # Ignore credentials if a channel was passed. + credentials = False + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + self._ssl_channel_credentials = None + + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials + + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + ) + + if not self._grpc_channel: + self._grpc_channel = type(self).create_channel( + self._host, + # use the credentials which are saved + credentials=self._credentials, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, + quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) + + @classmethod + def create_channel( + cls, + host: str = "aiplatform.googleapis.com", + credentials: ga_credentials.Credentials = None, + credentials_file: str = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs, + ) -> grpc.Channel: + """Create and return a gRPC channel object. + Args: + host (Optional[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is mutually exclusive with credentials. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + grpc.Channel: A gRPC channel object. + + Raises: + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + + return grpc_helpers.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + quota_project_id=quota_project_id, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, + **kwargs, + ) + + @property + def grpc_channel(self) -> grpc.Channel: + """Return the channel designed to connect to this service.""" + return self._grpc_channel + + @property + def operations_client(self) -> operations_v1.OperationsClient: + """Create the client designed to process long-running operations. + + This property caches on the instance; repeated calls return the same + client. + """ + # Quick check: Only create a new client if we do not already have one. + if self._operations_client is None: + self._operations_client = operations_v1.OperationsClient(self.grpc_channel) + + # Return the client from cache. + return self._operations_client + + @property + def create_tensorboard( + self, + ) -> Callable[ + [tensorboard_service.CreateTensorboardRequest], operations_pb2.Operation + ]: + r"""Return a callable for the create tensorboard method over gRPC. + + Creates a Tensorboard. + + Returns: + Callable[[~.CreateTensorboardRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_tensorboard" not in self._stubs: + self._stubs["create_tensorboard"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/CreateTensorboard", + request_serializer=tensorboard_service.CreateTensorboardRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["create_tensorboard"] + + @property + def get_tensorboard( + self, + ) -> Callable[[tensorboard_service.GetTensorboardRequest], tensorboard.Tensorboard]: + r"""Return a callable for the get tensorboard method over gRPC. + + Gets a Tensorboard. + + Returns: + Callable[[~.GetTensorboardRequest], + ~.Tensorboard]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_tensorboard" not in self._stubs: + self._stubs["get_tensorboard"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/GetTensorboard", + request_serializer=tensorboard_service.GetTensorboardRequest.serialize, + response_deserializer=tensorboard.Tensorboard.deserialize, + ) + return self._stubs["get_tensorboard"] + + @property + def update_tensorboard( + self, + ) -> Callable[ + [tensorboard_service.UpdateTensorboardRequest], operations_pb2.Operation + ]: + r"""Return a callable for the update tensorboard method over gRPC. + + Updates a Tensorboard. + + Returns: + Callable[[~.UpdateTensorboardRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_tensorboard" not in self._stubs: + self._stubs["update_tensorboard"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/UpdateTensorboard", + request_serializer=tensorboard_service.UpdateTensorboardRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["update_tensorboard"] + + @property + def list_tensorboards( + self, + ) -> Callable[ + [tensorboard_service.ListTensorboardsRequest], + tensorboard_service.ListTensorboardsResponse, + ]: + r"""Return a callable for the list tensorboards method over gRPC. + + Lists Tensorboards in a Location. + + Returns: + Callable[[~.ListTensorboardsRequest], + ~.ListTensorboardsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_tensorboards" not in self._stubs: + self._stubs["list_tensorboards"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/ListTensorboards", + request_serializer=tensorboard_service.ListTensorboardsRequest.serialize, + response_deserializer=tensorboard_service.ListTensorboardsResponse.deserialize, + ) + return self._stubs["list_tensorboards"] + + @property + def delete_tensorboard( + self, + ) -> Callable[ + [tensorboard_service.DeleteTensorboardRequest], operations_pb2.Operation + ]: + r"""Return a callable for the delete tensorboard method over gRPC. + + Deletes a Tensorboard. + + Returns: + Callable[[~.DeleteTensorboardRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_tensorboard" not in self._stubs: + self._stubs["delete_tensorboard"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/DeleteTensorboard", + request_serializer=tensorboard_service.DeleteTensorboardRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_tensorboard"] + + @property + def create_tensorboard_experiment( + self, + ) -> Callable[ + [tensorboard_service.CreateTensorboardExperimentRequest], + gca_tensorboard_experiment.TensorboardExperiment, + ]: + r"""Return a callable for the create tensorboard experiment method over gRPC. + + Creates a TensorboardExperiment. + + Returns: + Callable[[~.CreateTensorboardExperimentRequest], + ~.TensorboardExperiment]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_tensorboard_experiment" not in self._stubs: + self._stubs[ + "create_tensorboard_experiment" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/CreateTensorboardExperiment", + request_serializer=tensorboard_service.CreateTensorboardExperimentRequest.serialize, + response_deserializer=gca_tensorboard_experiment.TensorboardExperiment.deserialize, + ) + return self._stubs["create_tensorboard_experiment"] + + @property + def get_tensorboard_experiment( + self, + ) -> Callable[ + [tensorboard_service.GetTensorboardExperimentRequest], + tensorboard_experiment.TensorboardExperiment, + ]: + r"""Return a callable for the get tensorboard experiment method over gRPC. + + Gets a TensorboardExperiment. + + Returns: + Callable[[~.GetTensorboardExperimentRequest], + ~.TensorboardExperiment]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_tensorboard_experiment" not in self._stubs: + self._stubs["get_tensorboard_experiment"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/GetTensorboardExperiment", + request_serializer=tensorboard_service.GetTensorboardExperimentRequest.serialize, + response_deserializer=tensorboard_experiment.TensorboardExperiment.deserialize, + ) + return self._stubs["get_tensorboard_experiment"] + + @property + def update_tensorboard_experiment( + self, + ) -> Callable[ + [tensorboard_service.UpdateTensorboardExperimentRequest], + gca_tensorboard_experiment.TensorboardExperiment, + ]: + r"""Return a callable for the update tensorboard experiment method over gRPC. + + Updates a TensorboardExperiment. + + Returns: + Callable[[~.UpdateTensorboardExperimentRequest], + ~.TensorboardExperiment]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_tensorboard_experiment" not in self._stubs: + self._stubs[ + "update_tensorboard_experiment" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/UpdateTensorboardExperiment", + request_serializer=tensorboard_service.UpdateTensorboardExperimentRequest.serialize, + response_deserializer=gca_tensorboard_experiment.TensorboardExperiment.deserialize, + ) + return self._stubs["update_tensorboard_experiment"] + + @property + def list_tensorboard_experiments( + self, + ) -> Callable[ + [tensorboard_service.ListTensorboardExperimentsRequest], + tensorboard_service.ListTensorboardExperimentsResponse, + ]: + r"""Return a callable for the list tensorboard experiments method over gRPC. + + Lists TensorboardExperiments in a Location. + + Returns: + Callable[[~.ListTensorboardExperimentsRequest], + ~.ListTensorboardExperimentsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_tensorboard_experiments" not in self._stubs: + self._stubs["list_tensorboard_experiments"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/ListTensorboardExperiments", + request_serializer=tensorboard_service.ListTensorboardExperimentsRequest.serialize, + response_deserializer=tensorboard_service.ListTensorboardExperimentsResponse.deserialize, + ) + return self._stubs["list_tensorboard_experiments"] + + @property + def delete_tensorboard_experiment( + self, + ) -> Callable[ + [tensorboard_service.DeleteTensorboardExperimentRequest], + operations_pb2.Operation, + ]: + r"""Return a callable for the delete tensorboard experiment method over gRPC. + + Deletes a TensorboardExperiment. + + Returns: + Callable[[~.DeleteTensorboardExperimentRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_tensorboard_experiment" not in self._stubs: + self._stubs[ + "delete_tensorboard_experiment" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/DeleteTensorboardExperiment", + request_serializer=tensorboard_service.DeleteTensorboardExperimentRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_tensorboard_experiment"] + + @property + def create_tensorboard_run( + self, + ) -> Callable[ + [tensorboard_service.CreateTensorboardRunRequest], + gca_tensorboard_run.TensorboardRun, + ]: + r"""Return a callable for the create tensorboard run method over gRPC. + + Creates a TensorboardRun. + + Returns: + Callable[[~.CreateTensorboardRunRequest], + ~.TensorboardRun]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_tensorboard_run" not in self._stubs: + self._stubs["create_tensorboard_run"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/CreateTensorboardRun", + request_serializer=tensorboard_service.CreateTensorboardRunRequest.serialize, + response_deserializer=gca_tensorboard_run.TensorboardRun.deserialize, + ) + return self._stubs["create_tensorboard_run"] + + @property + def batch_create_tensorboard_runs( + self, + ) -> Callable[ + [tensorboard_service.BatchCreateTensorboardRunsRequest], + tensorboard_service.BatchCreateTensorboardRunsResponse, + ]: + r"""Return a callable for the batch create tensorboard runs method over gRPC. + + Batch create TensorboardRuns. + + Returns: + Callable[[~.BatchCreateTensorboardRunsRequest], + ~.BatchCreateTensorboardRunsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "batch_create_tensorboard_runs" not in self._stubs: + self._stubs[ + "batch_create_tensorboard_runs" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/BatchCreateTensorboardRuns", + request_serializer=tensorboard_service.BatchCreateTensorboardRunsRequest.serialize, + response_deserializer=tensorboard_service.BatchCreateTensorboardRunsResponse.deserialize, + ) + return self._stubs["batch_create_tensorboard_runs"] + + @property + def get_tensorboard_run( + self, + ) -> Callable[ + [tensorboard_service.GetTensorboardRunRequest], tensorboard_run.TensorboardRun + ]: + r"""Return a callable for the get tensorboard run method over gRPC. + + Gets a TensorboardRun. + + Returns: + Callable[[~.GetTensorboardRunRequest], + ~.TensorboardRun]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_tensorboard_run" not in self._stubs: + self._stubs["get_tensorboard_run"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/GetTensorboardRun", + request_serializer=tensorboard_service.GetTensorboardRunRequest.serialize, + response_deserializer=tensorboard_run.TensorboardRun.deserialize, + ) + return self._stubs["get_tensorboard_run"] + + @property + def update_tensorboard_run( + self, + ) -> Callable[ + [tensorboard_service.UpdateTensorboardRunRequest], + gca_tensorboard_run.TensorboardRun, + ]: + r"""Return a callable for the update tensorboard run method over gRPC. + + Updates a TensorboardRun. + + Returns: + Callable[[~.UpdateTensorboardRunRequest], + ~.TensorboardRun]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_tensorboard_run" not in self._stubs: + self._stubs["update_tensorboard_run"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/UpdateTensorboardRun", + request_serializer=tensorboard_service.UpdateTensorboardRunRequest.serialize, + response_deserializer=gca_tensorboard_run.TensorboardRun.deserialize, + ) + return self._stubs["update_tensorboard_run"] + + @property + def list_tensorboard_runs( + self, + ) -> Callable[ + [tensorboard_service.ListTensorboardRunsRequest], + tensorboard_service.ListTensorboardRunsResponse, + ]: + r"""Return a callable for the list tensorboard runs method over gRPC. + + Lists TensorboardRuns in a Location. + + Returns: + Callable[[~.ListTensorboardRunsRequest], + ~.ListTensorboardRunsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_tensorboard_runs" not in self._stubs: + self._stubs["list_tensorboard_runs"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/ListTensorboardRuns", + request_serializer=tensorboard_service.ListTensorboardRunsRequest.serialize, + response_deserializer=tensorboard_service.ListTensorboardRunsResponse.deserialize, + ) + return self._stubs["list_tensorboard_runs"] + + @property + def delete_tensorboard_run( + self, + ) -> Callable[ + [tensorboard_service.DeleteTensorboardRunRequest], operations_pb2.Operation + ]: + r"""Return a callable for the delete tensorboard run method over gRPC. + + Deletes a TensorboardRun. + + Returns: + Callable[[~.DeleteTensorboardRunRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_tensorboard_run" not in self._stubs: + self._stubs["delete_tensorboard_run"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/DeleteTensorboardRun", + request_serializer=tensorboard_service.DeleteTensorboardRunRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_tensorboard_run"] + + @property + def batch_create_tensorboard_time_series( + self, + ) -> Callable[ + [tensorboard_service.BatchCreateTensorboardTimeSeriesRequest], + tensorboard_service.BatchCreateTensorboardTimeSeriesResponse, + ]: + r"""Return a callable for the batch create tensorboard time + series method over gRPC. + + Batch create TensorboardTimeSeries that belong to a + TensorboardExperiment. + + Returns: + Callable[[~.BatchCreateTensorboardTimeSeriesRequest], + ~.BatchCreateTensorboardTimeSeriesResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "batch_create_tensorboard_time_series" not in self._stubs: + self._stubs[ + "batch_create_tensorboard_time_series" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/BatchCreateTensorboardTimeSeries", + request_serializer=tensorboard_service.BatchCreateTensorboardTimeSeriesRequest.serialize, + response_deserializer=tensorboard_service.BatchCreateTensorboardTimeSeriesResponse.deserialize, + ) + return self._stubs["batch_create_tensorboard_time_series"] + + @property + def create_tensorboard_time_series( + self, + ) -> Callable[ + [tensorboard_service.CreateTensorboardTimeSeriesRequest], + gca_tensorboard_time_series.TensorboardTimeSeries, + ]: + r"""Return a callable for the create tensorboard time series method over gRPC. + + Creates a TensorboardTimeSeries. + + Returns: + Callable[[~.CreateTensorboardTimeSeriesRequest], + ~.TensorboardTimeSeries]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_tensorboard_time_series" not in self._stubs: + self._stubs[ + "create_tensorboard_time_series" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/CreateTensorboardTimeSeries", + request_serializer=tensorboard_service.CreateTensorboardTimeSeriesRequest.serialize, + response_deserializer=gca_tensorboard_time_series.TensorboardTimeSeries.deserialize, + ) + return self._stubs["create_tensorboard_time_series"] + + @property + def get_tensorboard_time_series( + self, + ) -> Callable[ + [tensorboard_service.GetTensorboardTimeSeriesRequest], + tensorboard_time_series.TensorboardTimeSeries, + ]: + r"""Return a callable for the get tensorboard time series method over gRPC. + + Gets a TensorboardTimeSeries. + + Returns: + Callable[[~.GetTensorboardTimeSeriesRequest], + ~.TensorboardTimeSeries]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_tensorboard_time_series" not in self._stubs: + self._stubs["get_tensorboard_time_series"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/GetTensorboardTimeSeries", + request_serializer=tensorboard_service.GetTensorboardTimeSeriesRequest.serialize, + response_deserializer=tensorboard_time_series.TensorboardTimeSeries.deserialize, + ) + return self._stubs["get_tensorboard_time_series"] + + @property + def update_tensorboard_time_series( + self, + ) -> Callable[ + [tensorboard_service.UpdateTensorboardTimeSeriesRequest], + gca_tensorboard_time_series.TensorboardTimeSeries, + ]: + r"""Return a callable for the update tensorboard time series method over gRPC. + + Updates a TensorboardTimeSeries. + + Returns: + Callable[[~.UpdateTensorboardTimeSeriesRequest], + ~.TensorboardTimeSeries]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_tensorboard_time_series" not in self._stubs: + self._stubs[ + "update_tensorboard_time_series" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/UpdateTensorboardTimeSeries", + request_serializer=tensorboard_service.UpdateTensorboardTimeSeriesRequest.serialize, + response_deserializer=gca_tensorboard_time_series.TensorboardTimeSeries.deserialize, + ) + return self._stubs["update_tensorboard_time_series"] + + @property + def list_tensorboard_time_series( + self, + ) -> Callable[ + [tensorboard_service.ListTensorboardTimeSeriesRequest], + tensorboard_service.ListTensorboardTimeSeriesResponse, + ]: + r"""Return a callable for the list tensorboard time series method over gRPC. + + Lists TensorboardTimeSeries in a Location. + + Returns: + Callable[[~.ListTensorboardTimeSeriesRequest], + ~.ListTensorboardTimeSeriesResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_tensorboard_time_series" not in self._stubs: + self._stubs["list_tensorboard_time_series"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/ListTensorboardTimeSeries", + request_serializer=tensorboard_service.ListTensorboardTimeSeriesRequest.serialize, + response_deserializer=tensorboard_service.ListTensorboardTimeSeriesResponse.deserialize, + ) + return self._stubs["list_tensorboard_time_series"] + + @property + def delete_tensorboard_time_series( + self, + ) -> Callable[ + [tensorboard_service.DeleteTensorboardTimeSeriesRequest], + operations_pb2.Operation, + ]: + r"""Return a callable for the delete tensorboard time series method over gRPC. + + Deletes a TensorboardTimeSeries. + + Returns: + Callable[[~.DeleteTensorboardTimeSeriesRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_tensorboard_time_series" not in self._stubs: + self._stubs[ + "delete_tensorboard_time_series" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/DeleteTensorboardTimeSeries", + request_serializer=tensorboard_service.DeleteTensorboardTimeSeriesRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_tensorboard_time_series"] + + @property + def batch_read_tensorboard_time_series_data( + self, + ) -> Callable[ + [tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest], + tensorboard_service.BatchReadTensorboardTimeSeriesDataResponse, + ]: + r"""Return a callable for the batch read tensorboard time + series data method over gRPC. + + Reads multiple TensorboardTimeSeries' data. The data + point number limit is 1000 for scalars, 100 for tensors + and blob references. If the number of data points stored + is less than the limit, all data will be returned. + Otherwise, that limit number of data points will be + randomly selected from this time series and returned. + + Returns: + Callable[[~.BatchReadTensorboardTimeSeriesDataRequest], + ~.BatchReadTensorboardTimeSeriesDataResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "batch_read_tensorboard_time_series_data" not in self._stubs: + self._stubs[ + "batch_read_tensorboard_time_series_data" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/BatchReadTensorboardTimeSeriesData", + request_serializer=tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest.serialize, + response_deserializer=tensorboard_service.BatchReadTensorboardTimeSeriesDataResponse.deserialize, + ) + return self._stubs["batch_read_tensorboard_time_series_data"] + + @property + def read_tensorboard_time_series_data( + self, + ) -> Callable[ + [tensorboard_service.ReadTensorboardTimeSeriesDataRequest], + tensorboard_service.ReadTensorboardTimeSeriesDataResponse, + ]: + r"""Return a callable for the read tensorboard time series + data method over gRPC. + + Reads a TensorboardTimeSeries' data. By default, if the number + of data points stored is less than 1000, all data will be + returned. Otherwise, 1000 data points will be randomly selected + from this time series and returned. This value can be changed by + changing max_data_points, which can't be greater than 10k. + + Returns: + Callable[[~.ReadTensorboardTimeSeriesDataRequest], + ~.ReadTensorboardTimeSeriesDataResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "read_tensorboard_time_series_data" not in self._stubs: + self._stubs[ + "read_tensorboard_time_series_data" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/ReadTensorboardTimeSeriesData", + request_serializer=tensorboard_service.ReadTensorboardTimeSeriesDataRequest.serialize, + response_deserializer=tensorboard_service.ReadTensorboardTimeSeriesDataResponse.deserialize, + ) + return self._stubs["read_tensorboard_time_series_data"] + + @property + def read_tensorboard_blob_data( + self, + ) -> Callable[ + [tensorboard_service.ReadTensorboardBlobDataRequest], + tensorboard_service.ReadTensorboardBlobDataResponse, + ]: + r"""Return a callable for the read tensorboard blob data method over gRPC. + + Gets bytes of TensorboardBlobs. + This is to allow reading blob data stored in consumer + project's Cloud Storage bucket without users having to + obtain Cloud Storage access permission. + + Returns: + Callable[[~.ReadTensorboardBlobDataRequest], + ~.ReadTensorboardBlobDataResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "read_tensorboard_blob_data" not in self._stubs: + self._stubs["read_tensorboard_blob_data"] = self.grpc_channel.unary_stream( + "/google.cloud.aiplatform.v1.TensorboardService/ReadTensorboardBlobData", + request_serializer=tensorboard_service.ReadTensorboardBlobDataRequest.serialize, + response_deserializer=tensorboard_service.ReadTensorboardBlobDataResponse.deserialize, + ) + return self._stubs["read_tensorboard_blob_data"] + + @property + def write_tensorboard_experiment_data( + self, + ) -> Callable[ + [tensorboard_service.WriteTensorboardExperimentDataRequest], + tensorboard_service.WriteTensorboardExperimentDataResponse, + ]: + r"""Return a callable for the write tensorboard experiment + data method over gRPC. + + Write time series data points of multiple + TensorboardTimeSeries in multiple TensorboardRun's. If + any data fail to be ingested, an error will be returned. + + Returns: + Callable[[~.WriteTensorboardExperimentDataRequest], + ~.WriteTensorboardExperimentDataResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "write_tensorboard_experiment_data" not in self._stubs: + self._stubs[ + "write_tensorboard_experiment_data" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/WriteTensorboardExperimentData", + request_serializer=tensorboard_service.WriteTensorboardExperimentDataRequest.serialize, + response_deserializer=tensorboard_service.WriteTensorboardExperimentDataResponse.deserialize, + ) + return self._stubs["write_tensorboard_experiment_data"] + + @property + def write_tensorboard_run_data( + self, + ) -> Callable[ + [tensorboard_service.WriteTensorboardRunDataRequest], + tensorboard_service.WriteTensorboardRunDataResponse, + ]: + r"""Return a callable for the write tensorboard run data method over gRPC. + + Write time series data points into multiple + TensorboardTimeSeries under a TensorboardRun. If any + data fail to be ingested, an error will be returned. + + Returns: + Callable[[~.WriteTensorboardRunDataRequest], + ~.WriteTensorboardRunDataResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "write_tensorboard_run_data" not in self._stubs: + self._stubs["write_tensorboard_run_data"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/WriteTensorboardRunData", + request_serializer=tensorboard_service.WriteTensorboardRunDataRequest.serialize, + response_deserializer=tensorboard_service.WriteTensorboardRunDataResponse.deserialize, + ) + return self._stubs["write_tensorboard_run_data"] + + @property + def export_tensorboard_time_series_data( + self, + ) -> Callable[ + [tensorboard_service.ExportTensorboardTimeSeriesDataRequest], + tensorboard_service.ExportTensorboardTimeSeriesDataResponse, + ]: + r"""Return a callable for the export tensorboard time series + data method over gRPC. + + Exports a TensorboardTimeSeries' data. Data is + returned in paginated responses. + + Returns: + Callable[[~.ExportTensorboardTimeSeriesDataRequest], + ~.ExportTensorboardTimeSeriesDataResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "export_tensorboard_time_series_data" not in self._stubs: + self._stubs[ + "export_tensorboard_time_series_data" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/ExportTensorboardTimeSeriesData", + request_serializer=tensorboard_service.ExportTensorboardTimeSeriesDataRequest.serialize, + response_deserializer=tensorboard_service.ExportTensorboardTimeSeriesDataResponse.deserialize, + ) + return self._stubs["export_tensorboard_time_series_data"] + + def close(self): + self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + @property + def kind(self) -> str: + return "grpc" + + +__all__ = ("TensorboardServiceGrpcTransport",) diff --git a/google/cloud/aiplatform_v1/services/tensorboard_service/transports/grpc_asyncio.py b/google/cloud/aiplatform_v1/services/tensorboard_service/transports/grpc_asyncio.py new file mode 100644 index 0000000000..f6c7192f59 --- /dev/null +++ b/google/cloud/aiplatform_v1/services/tensorboard_service/transports/grpc_asyncio.py @@ -0,0 +1,1332 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import warnings +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union + +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import operations_v1 +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore + +import grpc # type: ignore +from grpc.experimental import aio # type: ignore + +from google.cloud.aiplatform_v1.types import tensorboard +from google.cloud.aiplatform_v1.types import tensorboard_experiment +from google.cloud.aiplatform_v1.types import ( + tensorboard_experiment as gca_tensorboard_experiment, +) +from google.cloud.aiplatform_v1.types import tensorboard_run +from google.cloud.aiplatform_v1.types import tensorboard_run as gca_tensorboard_run +from google.cloud.aiplatform_v1.types import tensorboard_service +from google.cloud.aiplatform_v1.types import tensorboard_time_series +from google.cloud.aiplatform_v1.types import ( + tensorboard_time_series as gca_tensorboard_time_series, +) +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.longrunning import operations_pb2 # type: ignore +from .base import TensorboardServiceTransport, DEFAULT_CLIENT_INFO +from .grpc import TensorboardServiceGrpcTransport + + +class TensorboardServiceGrpcAsyncIOTransport(TensorboardServiceTransport): + """gRPC AsyncIO backend transport for TensorboardService. + + TensorboardService + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + + _grpc_channel: aio.Channel + _stubs: Dict[str, Callable] = {} + + @classmethod + def create_channel( + cls, + host: str = "aiplatform.googleapis.com", + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs, + ) -> aio.Channel: + """Create and return a gRPC AsyncIO channel object. + Args: + host (Optional[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + aio.Channel: A gRPC AsyncIO channel object. + """ + + return grpc_helpers_async.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + quota_project_id=quota_project_id, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, + **kwargs, + ) + + def __init__( + self, + *, + host: str = "aiplatform.googleapis.com", + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: aio.Channel = None, + api_mtls_endpoint: str = None, + client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, + ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, + quota_project_id=None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + 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. + This argument is ignored if ``channel`` is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + channel (Optional[aio.Channel]): A ``Channel`` instance through + which to make calls. + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or application default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for the grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure a mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + 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. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + + Raises: + google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + self._grpc_channel = None + self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + + if channel: + # Ignore credentials if a channel was passed. + credentials = False + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + self._ssl_channel_credentials = None + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials + + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + ) + + if not self._grpc_channel: + self._grpc_channel = type(self).create_channel( + self._host, + # use the credentials which are saved + credentials=self._credentials, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, + quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) + + @property + def grpc_channel(self) -> aio.Channel: + """Create the channel designed to connect to this service. + + This property caches on the instance; repeated calls return + the same channel. + """ + # Return the channel from cache. + return self._grpc_channel + + @property + def operations_client(self) -> operations_v1.OperationsAsyncClient: + """Create the client designed to process long-running operations. + + This property caches on the instance; repeated calls return the same + client. + """ + # Quick check: Only create a new client if we do not already have one. + if self._operations_client is None: + self._operations_client = operations_v1.OperationsAsyncClient( + self.grpc_channel + ) + + # Return the client from cache. + return self._operations_client + + @property + def create_tensorboard( + self, + ) -> Callable[ + [tensorboard_service.CreateTensorboardRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the create tensorboard method over gRPC. + + Creates a Tensorboard. + + Returns: + Callable[[~.CreateTensorboardRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_tensorboard" not in self._stubs: + self._stubs["create_tensorboard"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/CreateTensorboard", + request_serializer=tensorboard_service.CreateTensorboardRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["create_tensorboard"] + + @property + def get_tensorboard( + self, + ) -> Callable[ + [tensorboard_service.GetTensorboardRequest], Awaitable[tensorboard.Tensorboard] + ]: + r"""Return a callable for the get tensorboard method over gRPC. + + Gets a Tensorboard. + + Returns: + Callable[[~.GetTensorboardRequest], + Awaitable[~.Tensorboard]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_tensorboard" not in self._stubs: + self._stubs["get_tensorboard"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/GetTensorboard", + request_serializer=tensorboard_service.GetTensorboardRequest.serialize, + response_deserializer=tensorboard.Tensorboard.deserialize, + ) + return self._stubs["get_tensorboard"] + + @property + def update_tensorboard( + self, + ) -> Callable[ + [tensorboard_service.UpdateTensorboardRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the update tensorboard method over gRPC. + + Updates a Tensorboard. + + Returns: + Callable[[~.UpdateTensorboardRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_tensorboard" not in self._stubs: + self._stubs["update_tensorboard"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/UpdateTensorboard", + request_serializer=tensorboard_service.UpdateTensorboardRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["update_tensorboard"] + + @property + def list_tensorboards( + self, + ) -> Callable[ + [tensorboard_service.ListTensorboardsRequest], + Awaitable[tensorboard_service.ListTensorboardsResponse], + ]: + r"""Return a callable for the list tensorboards method over gRPC. + + Lists Tensorboards in a Location. + + Returns: + Callable[[~.ListTensorboardsRequest], + Awaitable[~.ListTensorboardsResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_tensorboards" not in self._stubs: + self._stubs["list_tensorboards"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/ListTensorboards", + request_serializer=tensorboard_service.ListTensorboardsRequest.serialize, + response_deserializer=tensorboard_service.ListTensorboardsResponse.deserialize, + ) + return self._stubs["list_tensorboards"] + + @property + def delete_tensorboard( + self, + ) -> Callable[ + [tensorboard_service.DeleteTensorboardRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the delete tensorboard method over gRPC. + + Deletes a Tensorboard. + + Returns: + Callable[[~.DeleteTensorboardRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_tensorboard" not in self._stubs: + self._stubs["delete_tensorboard"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/DeleteTensorboard", + request_serializer=tensorboard_service.DeleteTensorboardRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_tensorboard"] + + @property + def create_tensorboard_experiment( + self, + ) -> Callable[ + [tensorboard_service.CreateTensorboardExperimentRequest], + Awaitable[gca_tensorboard_experiment.TensorboardExperiment], + ]: + r"""Return a callable for the create tensorboard experiment method over gRPC. + + Creates a TensorboardExperiment. + + Returns: + Callable[[~.CreateTensorboardExperimentRequest], + Awaitable[~.TensorboardExperiment]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_tensorboard_experiment" not in self._stubs: + self._stubs[ + "create_tensorboard_experiment" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/CreateTensorboardExperiment", + request_serializer=tensorboard_service.CreateTensorboardExperimentRequest.serialize, + response_deserializer=gca_tensorboard_experiment.TensorboardExperiment.deserialize, + ) + return self._stubs["create_tensorboard_experiment"] + + @property + def get_tensorboard_experiment( + self, + ) -> Callable[ + [tensorboard_service.GetTensorboardExperimentRequest], + Awaitable[tensorboard_experiment.TensorboardExperiment], + ]: + r"""Return a callable for the get tensorboard experiment method over gRPC. + + Gets a TensorboardExperiment. + + Returns: + Callable[[~.GetTensorboardExperimentRequest], + Awaitable[~.TensorboardExperiment]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_tensorboard_experiment" not in self._stubs: + self._stubs["get_tensorboard_experiment"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/GetTensorboardExperiment", + request_serializer=tensorboard_service.GetTensorboardExperimentRequest.serialize, + response_deserializer=tensorboard_experiment.TensorboardExperiment.deserialize, + ) + return self._stubs["get_tensorboard_experiment"] + + @property + def update_tensorboard_experiment( + self, + ) -> Callable[ + [tensorboard_service.UpdateTensorboardExperimentRequest], + Awaitable[gca_tensorboard_experiment.TensorboardExperiment], + ]: + r"""Return a callable for the update tensorboard experiment method over gRPC. + + Updates a TensorboardExperiment. + + Returns: + Callable[[~.UpdateTensorboardExperimentRequest], + Awaitable[~.TensorboardExperiment]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_tensorboard_experiment" not in self._stubs: + self._stubs[ + "update_tensorboard_experiment" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/UpdateTensorboardExperiment", + request_serializer=tensorboard_service.UpdateTensorboardExperimentRequest.serialize, + response_deserializer=gca_tensorboard_experiment.TensorboardExperiment.deserialize, + ) + return self._stubs["update_tensorboard_experiment"] + + @property + def list_tensorboard_experiments( + self, + ) -> Callable[ + [tensorboard_service.ListTensorboardExperimentsRequest], + Awaitable[tensorboard_service.ListTensorboardExperimentsResponse], + ]: + r"""Return a callable for the list tensorboard experiments method over gRPC. + + Lists TensorboardExperiments in a Location. + + Returns: + Callable[[~.ListTensorboardExperimentsRequest], + Awaitable[~.ListTensorboardExperimentsResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_tensorboard_experiments" not in self._stubs: + self._stubs["list_tensorboard_experiments"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/ListTensorboardExperiments", + request_serializer=tensorboard_service.ListTensorboardExperimentsRequest.serialize, + response_deserializer=tensorboard_service.ListTensorboardExperimentsResponse.deserialize, + ) + return self._stubs["list_tensorboard_experiments"] + + @property + def delete_tensorboard_experiment( + self, + ) -> Callable[ + [tensorboard_service.DeleteTensorboardExperimentRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the delete tensorboard experiment method over gRPC. + + Deletes a TensorboardExperiment. + + Returns: + Callable[[~.DeleteTensorboardExperimentRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_tensorboard_experiment" not in self._stubs: + self._stubs[ + "delete_tensorboard_experiment" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/DeleteTensorboardExperiment", + request_serializer=tensorboard_service.DeleteTensorboardExperimentRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_tensorboard_experiment"] + + @property + def create_tensorboard_run( + self, + ) -> Callable[ + [tensorboard_service.CreateTensorboardRunRequest], + Awaitable[gca_tensorboard_run.TensorboardRun], + ]: + r"""Return a callable for the create tensorboard run method over gRPC. + + Creates a TensorboardRun. + + Returns: + Callable[[~.CreateTensorboardRunRequest], + Awaitable[~.TensorboardRun]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_tensorboard_run" not in self._stubs: + self._stubs["create_tensorboard_run"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/CreateTensorboardRun", + request_serializer=tensorboard_service.CreateTensorboardRunRequest.serialize, + response_deserializer=gca_tensorboard_run.TensorboardRun.deserialize, + ) + return self._stubs["create_tensorboard_run"] + + @property + def batch_create_tensorboard_runs( + self, + ) -> Callable[ + [tensorboard_service.BatchCreateTensorboardRunsRequest], + Awaitable[tensorboard_service.BatchCreateTensorboardRunsResponse], + ]: + r"""Return a callable for the batch create tensorboard runs method over gRPC. + + Batch create TensorboardRuns. + + Returns: + Callable[[~.BatchCreateTensorboardRunsRequest], + Awaitable[~.BatchCreateTensorboardRunsResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "batch_create_tensorboard_runs" not in self._stubs: + self._stubs[ + "batch_create_tensorboard_runs" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/BatchCreateTensorboardRuns", + request_serializer=tensorboard_service.BatchCreateTensorboardRunsRequest.serialize, + response_deserializer=tensorboard_service.BatchCreateTensorboardRunsResponse.deserialize, + ) + return self._stubs["batch_create_tensorboard_runs"] + + @property + def get_tensorboard_run( + self, + ) -> Callable[ + [tensorboard_service.GetTensorboardRunRequest], + Awaitable[tensorboard_run.TensorboardRun], + ]: + r"""Return a callable for the get tensorboard run method over gRPC. + + Gets a TensorboardRun. + + Returns: + Callable[[~.GetTensorboardRunRequest], + Awaitable[~.TensorboardRun]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_tensorboard_run" not in self._stubs: + self._stubs["get_tensorboard_run"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/GetTensorboardRun", + request_serializer=tensorboard_service.GetTensorboardRunRequest.serialize, + response_deserializer=tensorboard_run.TensorboardRun.deserialize, + ) + return self._stubs["get_tensorboard_run"] + + @property + def update_tensorboard_run( + self, + ) -> Callable[ + [tensorboard_service.UpdateTensorboardRunRequest], + Awaitable[gca_tensorboard_run.TensorboardRun], + ]: + r"""Return a callable for the update tensorboard run method over gRPC. + + Updates a TensorboardRun. + + Returns: + Callable[[~.UpdateTensorboardRunRequest], + Awaitable[~.TensorboardRun]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_tensorboard_run" not in self._stubs: + self._stubs["update_tensorboard_run"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/UpdateTensorboardRun", + request_serializer=tensorboard_service.UpdateTensorboardRunRequest.serialize, + response_deserializer=gca_tensorboard_run.TensorboardRun.deserialize, + ) + return self._stubs["update_tensorboard_run"] + + @property + def list_tensorboard_runs( + self, + ) -> Callable[ + [tensorboard_service.ListTensorboardRunsRequest], + Awaitable[tensorboard_service.ListTensorboardRunsResponse], + ]: + r"""Return a callable for the list tensorboard runs method over gRPC. + + Lists TensorboardRuns in a Location. + + Returns: + Callable[[~.ListTensorboardRunsRequest], + Awaitable[~.ListTensorboardRunsResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_tensorboard_runs" not in self._stubs: + self._stubs["list_tensorboard_runs"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/ListTensorboardRuns", + request_serializer=tensorboard_service.ListTensorboardRunsRequest.serialize, + response_deserializer=tensorboard_service.ListTensorboardRunsResponse.deserialize, + ) + return self._stubs["list_tensorboard_runs"] + + @property + def delete_tensorboard_run( + self, + ) -> Callable[ + [tensorboard_service.DeleteTensorboardRunRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the delete tensorboard run method over gRPC. + + Deletes a TensorboardRun. + + Returns: + Callable[[~.DeleteTensorboardRunRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_tensorboard_run" not in self._stubs: + self._stubs["delete_tensorboard_run"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/DeleteTensorboardRun", + request_serializer=tensorboard_service.DeleteTensorboardRunRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_tensorboard_run"] + + @property + def batch_create_tensorboard_time_series( + self, + ) -> Callable[ + [tensorboard_service.BatchCreateTensorboardTimeSeriesRequest], + Awaitable[tensorboard_service.BatchCreateTensorboardTimeSeriesResponse], + ]: + r"""Return a callable for the batch create tensorboard time + series method over gRPC. + + Batch create TensorboardTimeSeries that belong to a + TensorboardExperiment. + + Returns: + Callable[[~.BatchCreateTensorboardTimeSeriesRequest], + Awaitable[~.BatchCreateTensorboardTimeSeriesResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "batch_create_tensorboard_time_series" not in self._stubs: + self._stubs[ + "batch_create_tensorboard_time_series" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/BatchCreateTensorboardTimeSeries", + request_serializer=tensorboard_service.BatchCreateTensorboardTimeSeriesRequest.serialize, + response_deserializer=tensorboard_service.BatchCreateTensorboardTimeSeriesResponse.deserialize, + ) + return self._stubs["batch_create_tensorboard_time_series"] + + @property + def create_tensorboard_time_series( + self, + ) -> Callable[ + [tensorboard_service.CreateTensorboardTimeSeriesRequest], + Awaitable[gca_tensorboard_time_series.TensorboardTimeSeries], + ]: + r"""Return a callable for the create tensorboard time series method over gRPC. + + Creates a TensorboardTimeSeries. + + Returns: + Callable[[~.CreateTensorboardTimeSeriesRequest], + Awaitable[~.TensorboardTimeSeries]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_tensorboard_time_series" not in self._stubs: + self._stubs[ + "create_tensorboard_time_series" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/CreateTensorboardTimeSeries", + request_serializer=tensorboard_service.CreateTensorboardTimeSeriesRequest.serialize, + response_deserializer=gca_tensorboard_time_series.TensorboardTimeSeries.deserialize, + ) + return self._stubs["create_tensorboard_time_series"] + + @property + def get_tensorboard_time_series( + self, + ) -> Callable[ + [tensorboard_service.GetTensorboardTimeSeriesRequest], + Awaitable[tensorboard_time_series.TensorboardTimeSeries], + ]: + r"""Return a callable for the get tensorboard time series method over gRPC. + + Gets a TensorboardTimeSeries. + + Returns: + Callable[[~.GetTensorboardTimeSeriesRequest], + Awaitable[~.TensorboardTimeSeries]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_tensorboard_time_series" not in self._stubs: + self._stubs["get_tensorboard_time_series"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/GetTensorboardTimeSeries", + request_serializer=tensorboard_service.GetTensorboardTimeSeriesRequest.serialize, + response_deserializer=tensorboard_time_series.TensorboardTimeSeries.deserialize, + ) + return self._stubs["get_tensorboard_time_series"] + + @property + def update_tensorboard_time_series( + self, + ) -> Callable[ + [tensorboard_service.UpdateTensorboardTimeSeriesRequest], + Awaitable[gca_tensorboard_time_series.TensorboardTimeSeries], + ]: + r"""Return a callable for the update tensorboard time series method over gRPC. + + Updates a TensorboardTimeSeries. + + Returns: + Callable[[~.UpdateTensorboardTimeSeriesRequest], + Awaitable[~.TensorboardTimeSeries]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_tensorboard_time_series" not in self._stubs: + self._stubs[ + "update_tensorboard_time_series" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/UpdateTensorboardTimeSeries", + request_serializer=tensorboard_service.UpdateTensorboardTimeSeriesRequest.serialize, + response_deserializer=gca_tensorboard_time_series.TensorboardTimeSeries.deserialize, + ) + return self._stubs["update_tensorboard_time_series"] + + @property + def list_tensorboard_time_series( + self, + ) -> Callable[ + [tensorboard_service.ListTensorboardTimeSeriesRequest], + Awaitable[tensorboard_service.ListTensorboardTimeSeriesResponse], + ]: + r"""Return a callable for the list tensorboard time series method over gRPC. + + Lists TensorboardTimeSeries in a Location. + + Returns: + Callable[[~.ListTensorboardTimeSeriesRequest], + Awaitable[~.ListTensorboardTimeSeriesResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_tensorboard_time_series" not in self._stubs: + self._stubs["list_tensorboard_time_series"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/ListTensorboardTimeSeries", + request_serializer=tensorboard_service.ListTensorboardTimeSeriesRequest.serialize, + response_deserializer=tensorboard_service.ListTensorboardTimeSeriesResponse.deserialize, + ) + return self._stubs["list_tensorboard_time_series"] + + @property + def delete_tensorboard_time_series( + self, + ) -> Callable[ + [tensorboard_service.DeleteTensorboardTimeSeriesRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the delete tensorboard time series method over gRPC. + + Deletes a TensorboardTimeSeries. + + Returns: + Callable[[~.DeleteTensorboardTimeSeriesRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_tensorboard_time_series" not in self._stubs: + self._stubs[ + "delete_tensorboard_time_series" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/DeleteTensorboardTimeSeries", + request_serializer=tensorboard_service.DeleteTensorboardTimeSeriesRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_tensorboard_time_series"] + + @property + def batch_read_tensorboard_time_series_data( + self, + ) -> Callable[ + [tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest], + Awaitable[tensorboard_service.BatchReadTensorboardTimeSeriesDataResponse], + ]: + r"""Return a callable for the batch read tensorboard time + series data method over gRPC. + + Reads multiple TensorboardTimeSeries' data. The data + point number limit is 1000 for scalars, 100 for tensors + and blob references. If the number of data points stored + is less than the limit, all data will be returned. + Otherwise, that limit number of data points will be + randomly selected from this time series and returned. + + Returns: + Callable[[~.BatchReadTensorboardTimeSeriesDataRequest], + Awaitable[~.BatchReadTensorboardTimeSeriesDataResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "batch_read_tensorboard_time_series_data" not in self._stubs: + self._stubs[ + "batch_read_tensorboard_time_series_data" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/BatchReadTensorboardTimeSeriesData", + request_serializer=tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest.serialize, + response_deserializer=tensorboard_service.BatchReadTensorboardTimeSeriesDataResponse.deserialize, + ) + return self._stubs["batch_read_tensorboard_time_series_data"] + + @property + def read_tensorboard_time_series_data( + self, + ) -> Callable[ + [tensorboard_service.ReadTensorboardTimeSeriesDataRequest], + Awaitable[tensorboard_service.ReadTensorboardTimeSeriesDataResponse], + ]: + r"""Return a callable for the read tensorboard time series + data method over gRPC. + + Reads a TensorboardTimeSeries' data. By default, if the number + of data points stored is less than 1000, all data will be + returned. Otherwise, 1000 data points will be randomly selected + from this time series and returned. This value can be changed by + changing max_data_points, which can't be greater than 10k. + + Returns: + Callable[[~.ReadTensorboardTimeSeriesDataRequest], + Awaitable[~.ReadTensorboardTimeSeriesDataResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "read_tensorboard_time_series_data" not in self._stubs: + self._stubs[ + "read_tensorboard_time_series_data" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/ReadTensorboardTimeSeriesData", + request_serializer=tensorboard_service.ReadTensorboardTimeSeriesDataRequest.serialize, + response_deserializer=tensorboard_service.ReadTensorboardTimeSeriesDataResponse.deserialize, + ) + return self._stubs["read_tensorboard_time_series_data"] + + @property + def read_tensorboard_blob_data( + self, + ) -> Callable[ + [tensorboard_service.ReadTensorboardBlobDataRequest], + Awaitable[tensorboard_service.ReadTensorboardBlobDataResponse], + ]: + r"""Return a callable for the read tensorboard blob data method over gRPC. + + Gets bytes of TensorboardBlobs. + This is to allow reading blob data stored in consumer + project's Cloud Storage bucket without users having to + obtain Cloud Storage access permission. + + Returns: + Callable[[~.ReadTensorboardBlobDataRequest], + Awaitable[~.ReadTensorboardBlobDataResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "read_tensorboard_blob_data" not in self._stubs: + self._stubs["read_tensorboard_blob_data"] = self.grpc_channel.unary_stream( + "/google.cloud.aiplatform.v1.TensorboardService/ReadTensorboardBlobData", + request_serializer=tensorboard_service.ReadTensorboardBlobDataRequest.serialize, + response_deserializer=tensorboard_service.ReadTensorboardBlobDataResponse.deserialize, + ) + return self._stubs["read_tensorboard_blob_data"] + + @property + def write_tensorboard_experiment_data( + self, + ) -> Callable[ + [tensorboard_service.WriteTensorboardExperimentDataRequest], + Awaitable[tensorboard_service.WriteTensorboardExperimentDataResponse], + ]: + r"""Return a callable for the write tensorboard experiment + data method over gRPC. + + Write time series data points of multiple + TensorboardTimeSeries in multiple TensorboardRun's. If + any data fail to be ingested, an error will be returned. + + Returns: + Callable[[~.WriteTensorboardExperimentDataRequest], + Awaitable[~.WriteTensorboardExperimentDataResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "write_tensorboard_experiment_data" not in self._stubs: + self._stubs[ + "write_tensorboard_experiment_data" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/WriteTensorboardExperimentData", + request_serializer=tensorboard_service.WriteTensorboardExperimentDataRequest.serialize, + response_deserializer=tensorboard_service.WriteTensorboardExperimentDataResponse.deserialize, + ) + return self._stubs["write_tensorboard_experiment_data"] + + @property + def write_tensorboard_run_data( + self, + ) -> Callable[ + [tensorboard_service.WriteTensorboardRunDataRequest], + Awaitable[tensorboard_service.WriteTensorboardRunDataResponse], + ]: + r"""Return a callable for the write tensorboard run data method over gRPC. + + Write time series data points into multiple + TensorboardTimeSeries under a TensorboardRun. If any + data fail to be ingested, an error will be returned. + + Returns: + Callable[[~.WriteTensorboardRunDataRequest], + Awaitable[~.WriteTensorboardRunDataResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "write_tensorboard_run_data" not in self._stubs: + self._stubs["write_tensorboard_run_data"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/WriteTensorboardRunData", + request_serializer=tensorboard_service.WriteTensorboardRunDataRequest.serialize, + response_deserializer=tensorboard_service.WriteTensorboardRunDataResponse.deserialize, + ) + return self._stubs["write_tensorboard_run_data"] + + @property + def export_tensorboard_time_series_data( + self, + ) -> Callable[ + [tensorboard_service.ExportTensorboardTimeSeriesDataRequest], + Awaitable[tensorboard_service.ExportTensorboardTimeSeriesDataResponse], + ]: + r"""Return a callable for the export tensorboard time series + data method over gRPC. + + Exports a TensorboardTimeSeries' data. Data is + returned in paginated responses. + + Returns: + Callable[[~.ExportTensorboardTimeSeriesDataRequest], + Awaitable[~.ExportTensorboardTimeSeriesDataResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "export_tensorboard_time_series_data" not in self._stubs: + self._stubs[ + "export_tensorboard_time_series_data" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.TensorboardService/ExportTensorboardTimeSeriesData", + request_serializer=tensorboard_service.ExportTensorboardTimeSeriesDataRequest.serialize, + response_deserializer=tensorboard_service.ExportTensorboardTimeSeriesDataResponse.deserialize, + ) + return self._stubs["export_tensorboard_time_series_data"] + + def close(self): + return self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + +__all__ = ("TensorboardServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/aiplatform_v1/services/vizier_service/__init__.py b/google/cloud/aiplatform_v1/services/vizier_service/__init__.py new file mode 100644 index 0000000000..b91bd3c525 --- /dev/null +++ b/google/cloud/aiplatform_v1/services/vizier_service/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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 .client import VizierServiceClient +from .async_client import VizierServiceAsyncClient + +__all__ = ( + "VizierServiceClient", + "VizierServiceAsyncClient", +) diff --git a/google/cloud/aiplatform_v1/services/vizier_service/async_client.py b/google/cloud/aiplatform_v1/services/vizier_service/async_client.py new file mode 100644 index 0000000000..c24eddd596 --- /dev/null +++ b/google/cloud/aiplatform_v1/services/vizier_service/async_client.py @@ -0,0 +1,2323 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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, Mapping, Optional, Sequence, Tuple, Type, Union +import pkg_resources + +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore + +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + +from google.api_core import operation # type: ignore +from google.api_core import operation_async # type: ignore +from google.cloud.aiplatform_v1.services.vizier_service import pagers +from google.cloud.aiplatform_v1.types import study +from google.cloud.aiplatform_v1.types import study as gca_study +from google.cloud.aiplatform_v1.types import vizier_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.protobuf import timestamp_pb2 # type: ignore +from .transports.base import VizierServiceTransport, DEFAULT_CLIENT_INFO +from .transports.grpc_asyncio import VizierServiceGrpcAsyncIOTransport +from .client import VizierServiceClient + + +class VizierServiceAsyncClient: + """Vertex AI Vizier API. + Vertex AI Vizier is a service to solve blackbox optimization + problems, such as tuning machine learning hyperparameters and + searching over deep learning architectures. + """ + + _client: VizierServiceClient + + DEFAULT_ENDPOINT = VizierServiceClient.DEFAULT_ENDPOINT + DEFAULT_MTLS_ENDPOINT = VizierServiceClient.DEFAULT_MTLS_ENDPOINT + + custom_job_path = staticmethod(VizierServiceClient.custom_job_path) + parse_custom_job_path = staticmethod(VizierServiceClient.parse_custom_job_path) + study_path = staticmethod(VizierServiceClient.study_path) + parse_study_path = staticmethod(VizierServiceClient.parse_study_path) + trial_path = staticmethod(VizierServiceClient.trial_path) + parse_trial_path = staticmethod(VizierServiceClient.parse_trial_path) + common_billing_account_path = staticmethod( + VizierServiceClient.common_billing_account_path + ) + parse_common_billing_account_path = staticmethod( + VizierServiceClient.parse_common_billing_account_path + ) + common_folder_path = staticmethod(VizierServiceClient.common_folder_path) + parse_common_folder_path = staticmethod( + VizierServiceClient.parse_common_folder_path + ) + common_organization_path = staticmethod( + VizierServiceClient.common_organization_path + ) + parse_common_organization_path = staticmethod( + VizierServiceClient.parse_common_organization_path + ) + common_project_path = staticmethod(VizierServiceClient.common_project_path) + parse_common_project_path = staticmethod( + VizierServiceClient.parse_common_project_path + ) + common_location_path = staticmethod(VizierServiceClient.common_location_path) + parse_common_location_path = staticmethod( + VizierServiceClient.parse_common_location_path + ) + + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials + info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + VizierServiceAsyncClient: The constructed client. + """ + return VizierServiceClient.from_service_account_info.__func__(VizierServiceAsyncClient, info, *args, **kwargs) # type: ignore + + @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: + VizierServiceAsyncClient: The constructed client. + """ + return VizierServiceClient.from_service_account_file.__func__(VizierServiceAsyncClient, filename, *args, **kwargs) # type: ignore + + from_service_account_json = from_service_account_file + + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return VizierServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + + @property + def transport(self) -> VizierServiceTransport: + """Returns the transport used by the client instance. + + Returns: + VizierServiceTransport: The transport used by the client instance. + """ + return self._client.transport + + get_transport_class = functools.partial( + type(VizierServiceClient).get_transport_class, type(VizierServiceClient) + ) + + def __init__( + self, + *, + credentials: ga_credentials.Credentials = None, + transport: Union[str, VizierServiceTransport] = "grpc_asyncio", + client_options: ClientOptions = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the vizier 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, ~.VizierServiceTransport]): 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 = VizierServiceClient( + credentials=credentials, + transport=transport, + client_options=client_options, + client_info=client_info, + ) + + async def create_study( + self, + request: Union[vizier_service.CreateStudyRequest, dict] = None, + *, + parent: str = None, + study: gca_study.Study = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_study.Study: + r"""Creates a Study. A resource name will be generated + after creation of the Study. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_create_study(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + study = aiplatform_v1.Study() + study.display_name = "display_name_value" + study.study_spec.metrics.metric_id = "metric_id_value" + study.study_spec.metrics.goal = "MINIMIZE" + study.study_spec.parameters.double_value_spec.min_value = 0.96 + study.study_spec.parameters.double_value_spec.max_value = 0.962 + study.study_spec.parameters.parameter_id = "parameter_id_value" + + request = aiplatform_v1.CreateStudyRequest( + parent="parent_value", + study=study, + ) + + # Make the request + response = await client.create_study(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CreateStudyRequest, dict]): + The request object. Request message for + [VizierService.CreateStudy][google.cloud.aiplatform.v1.VizierService.CreateStudy]. + parent (:class:`str`): + Required. The resource name of the Location to create + the CustomJob in. Format: + ``projects/{project}/locations/{location}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + study (:class:`google.cloud.aiplatform_v1.types.Study`): + Required. The Study configuration + used to create the Study. + + This corresponds to the ``study`` 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: + google.cloud.aiplatform_v1.types.Study: + A message representing a Study. + """ + # Create or coerce a protobuf request object. + # Quick 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, study]) + 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 = vizier_service.CreateStudyRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if study is not None: + request.study = study + + # 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_study, + default_timeout=None, + 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 get_study( + self, + request: Union[vizier_service.GetStudyRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> study.Study: + r"""Gets a Study by name. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_get_study(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetStudyRequest( + name="name_value", + ) + + # Make the request + response = await client.get_study(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetStudyRequest, dict]): + The request object. Request message for + [VizierService.GetStudy][google.cloud.aiplatform.v1.VizierService.GetStudy]. + name (:class:`str`): + Required. The name of the Study resource. Format: + ``projects/{project}/locations/{location}/studies/{study}`` + + 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: + google.cloud.aiplatform_v1.types.Study: + A message representing a Study. + """ + # Create or coerce a protobuf request object. + # Quick 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 = vizier_service.GetStudyRequest(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_study, + default_timeout=None, + 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 list_studies( + self, + request: Union[vizier_service.ListStudiesRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListStudiesAsyncPager: + r"""Lists all the studies in a region for an associated + project. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_list_studies(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListStudiesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_studies(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListStudiesRequest, dict]): + The request object. Request message for + [VizierService.ListStudies][google.cloud.aiplatform.v1.VizierService.ListStudies]. + parent (:class:`str`): + Required. The resource name of the Location to list the + Study from. Format: + ``projects/{project}/locations/{location}`` + + 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: + google.cloud.aiplatform_v1.services.vizier_service.pagers.ListStudiesAsyncPager: + Response message for + [VizierService.ListStudies][google.cloud.aiplatform.v1.VizierService.ListStudies]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = vizier_service.ListStudiesRequest(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_studies, + default_timeout=None, + 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.ListStudiesAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def delete_study( + self, + request: Union[vizier_service.DeleteStudyRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a Study. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_delete_study(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteStudyRequest( + name="name_value", + ) + + # Make the request + await client.delete_study(request=request) + + Args: + request (Union[google.cloud.aiplatform_v1.types.DeleteStudyRequest, dict]): + The request object. Request message for + [VizierService.DeleteStudy][google.cloud.aiplatform.v1.VizierService.DeleteStudy]. + name (:class:`str`): + Required. The name of the Study resource to be deleted. + Format: + ``projects/{project}/locations/{location}/studies/{study}`` + + 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. + # Quick 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 = vizier_service.DeleteStudyRequest(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_study, + default_timeout=None, + 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 lookup_study( + self, + request: Union[vizier_service.LookupStudyRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> study.Study: + r"""Looks a study up using the user-defined display_name field + instead of the fully qualified resource name. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_lookup_study(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.LookupStudyRequest( + parent="parent_value", + display_name="display_name_value", + ) + + # Make the request + response = await client.lookup_study(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.LookupStudyRequest, dict]): + The request object. Request message for + [VizierService.LookupStudy][google.cloud.aiplatform.v1.VizierService.LookupStudy]. + parent (:class:`str`): + Required. The resource name of the Location to get the + Study from. Format: + ``projects/{project}/locations/{location}`` + + 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: + google.cloud.aiplatform_v1.types.Study: + A message representing a Study. + """ + # Create or coerce a protobuf request object. + # Quick 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 = vizier_service.LookupStudyRequest(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.lookup_study, + default_timeout=None, + 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 suggest_trials( + self, + request: Union[vizier_service.SuggestTrialsRequest, dict] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Adds one or more Trials to a Study, with parameter values + suggested by Vertex AI Vizier. Returns a long-running operation + associated with the generation of Trial suggestions. When this + long-running operation succeeds, it will contain a + [SuggestTrialsResponse][google.cloud.ml.v1.SuggestTrialsResponse]. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_suggest_trials(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.SuggestTrialsRequest( + parent="parent_value", + suggestion_count=1744, + client_id="client_id_value", + ) + + # Make the request + operation = client.suggest_trials(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.SuggestTrialsRequest, dict]): + The request object. Request message for + [VizierService.SuggestTrials][google.cloud.aiplatform.v1.VizierService.SuggestTrials]. + 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.aiplatform_v1.types.SuggestTrialsResponse` + Response message for + [VizierService.SuggestTrials][google.cloud.aiplatform.v1.VizierService.SuggestTrials]. + + """ + # Create or coerce a protobuf request object. + request = vizier_service.SuggestTrialsRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.suggest_trials, + default_timeout=None, + 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, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + vizier_service.SuggestTrialsResponse, + metadata_type=vizier_service.SuggestTrialsMetadata, + ) + + # Done; return the response. + return response + + async def create_trial( + self, + request: Union[vizier_service.CreateTrialRequest, dict] = None, + *, + parent: str = None, + trial: study.Trial = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> study.Trial: + r"""Adds a user provided Trial to a Study. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_create_trial(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateTrialRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_trial(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CreateTrialRequest, dict]): + The request object. Request message for + [VizierService.CreateTrial][google.cloud.aiplatform.v1.VizierService.CreateTrial]. + parent (:class:`str`): + Required. The resource name of the Study to create the + Trial in. Format: + ``projects/{project}/locations/{location}/studies/{study}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + trial (:class:`google.cloud.aiplatform_v1.types.Trial`): + Required. The Trial to create. + This corresponds to the ``trial`` 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: + google.cloud.aiplatform_v1.types.Trial: + A message representing a Trial. A + Trial contains a unique set of + Parameters that has been or will be + evaluated, along with the objective + metrics got by running the Trial. + + """ + # Create or coerce a protobuf request object. + # Quick 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, trial]) + 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 = vizier_service.CreateTrialRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if trial is not None: + request.trial = trial + + # 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_trial, + default_timeout=None, + 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 get_trial( + self, + request: Union[vizier_service.GetTrialRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> study.Trial: + r"""Gets a Trial. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_get_trial(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetTrialRequest( + name="name_value", + ) + + # Make the request + response = await client.get_trial(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetTrialRequest, dict]): + The request object. Request message for + [VizierService.GetTrial][google.cloud.aiplatform.v1.VizierService.GetTrial]. + name (:class:`str`): + Required. The name of the Trial resource. Format: + ``projects/{project}/locations/{location}/studies/{study}/trials/{trial}`` + + 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: + google.cloud.aiplatform_v1.types.Trial: + A message representing a Trial. A + Trial contains a unique set of + Parameters that has been or will be + evaluated, along with the objective + metrics got by running the Trial. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = vizier_service.GetTrialRequest(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_trial, + default_timeout=None, + 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 list_trials( + self, + request: Union[vizier_service.ListTrialsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListTrialsAsyncPager: + r"""Lists the Trials associated with a Study. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_list_trials(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListTrialsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_trials(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListTrialsRequest, dict]): + The request object. Request message for + [VizierService.ListTrials][google.cloud.aiplatform.v1.VizierService.ListTrials]. + parent (:class:`str`): + Required. The resource name of the Study to list the + Trial from. Format: + ``projects/{project}/locations/{location}/studies/{study}`` + + 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: + google.cloud.aiplatform_v1.services.vizier_service.pagers.ListTrialsAsyncPager: + Response message for + [VizierService.ListTrials][google.cloud.aiplatform.v1.VizierService.ListTrials]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = vizier_service.ListTrialsRequest(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_trials, + default_timeout=None, + 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.ListTrialsAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def add_trial_measurement( + self, + request: Union[vizier_service.AddTrialMeasurementRequest, dict] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> study.Trial: + r"""Adds a measurement of the objective metrics to a + Trial. This measurement is assumed to have been taken + before the Trial is complete. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_add_trial_measurement(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.AddTrialMeasurementRequest( + trial_name="trial_name_value", + ) + + # Make the request + response = await client.add_trial_measurement(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.AddTrialMeasurementRequest, dict]): + The request object. Request message for + [VizierService.AddTrialMeasurement][google.cloud.aiplatform.v1.VizierService.AddTrialMeasurement]. + 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: + google.cloud.aiplatform_v1.types.Trial: + A message representing a Trial. A + Trial contains a unique set of + Parameters that has been or will be + evaluated, along with the objective + metrics got by running the Trial. + + """ + # Create or coerce a protobuf request object. + request = vizier_service.AddTrialMeasurementRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.add_trial_measurement, + default_timeout=None, + 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( + (("trial_name", request.trial_name),) + ), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def complete_trial( + self, + request: Union[vizier_service.CompleteTrialRequest, dict] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> study.Trial: + r"""Marks a Trial as complete. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_complete_trial(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CompleteTrialRequest( + name="name_value", + ) + + # Make the request + response = await client.complete_trial(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CompleteTrialRequest, dict]): + The request object. Request message for + [VizierService.CompleteTrial][google.cloud.aiplatform.v1.VizierService.CompleteTrial]. + 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: + google.cloud.aiplatform_v1.types.Trial: + A message representing a Trial. A + Trial contains a unique set of + Parameters that has been or will be + evaluated, along with the objective + metrics got by running the Trial. + + """ + # Create or coerce a protobuf request object. + request = vizier_service.CompleteTrialRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.complete_trial, + default_timeout=None, + 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_trial( + self, + request: Union[vizier_service.DeleteTrialRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a Trial. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_delete_trial(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteTrialRequest( + name="name_value", + ) + + # Make the request + await client.delete_trial(request=request) + + Args: + request (Union[google.cloud.aiplatform_v1.types.DeleteTrialRequest, dict]): + The request object. Request message for + [VizierService.DeleteTrial][google.cloud.aiplatform.v1.VizierService.DeleteTrial]. + name (:class:`str`): + Required. The Trial's name. Format: + ``projects/{project}/locations/{location}/studies/{study}/trials/{trial}`` + + 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. + # Quick 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 = vizier_service.DeleteTrialRequest(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_trial, + default_timeout=None, + 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 check_trial_early_stopping_state( + self, + request: Union[vizier_service.CheckTrialEarlyStoppingStateRequest, dict] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Checks whether a Trial should stop or not. Returns a + long-running operation. When the operation is successful, it + will contain a + [CheckTrialEarlyStoppingStateResponse][google.cloud.ml.v1.CheckTrialEarlyStoppingStateResponse]. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_check_trial_early_stopping_state(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CheckTrialEarlyStoppingStateRequest( + trial_name="trial_name_value", + ) + + # Make the request + operation = client.check_trial_early_stopping_state(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CheckTrialEarlyStoppingStateRequest, dict]): + The request object. Request message for + [VizierService.CheckTrialEarlyStoppingState][google.cloud.aiplatform.v1.VizierService.CheckTrialEarlyStoppingState]. + 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.aiplatform_v1.types.CheckTrialEarlyStoppingStateResponse` + Response message for + [VizierService.CheckTrialEarlyStoppingState][google.cloud.aiplatform.v1.VizierService.CheckTrialEarlyStoppingState]. + + """ + # Create or coerce a protobuf request object. + request = vizier_service.CheckTrialEarlyStoppingStateRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.check_trial_early_stopping_state, + default_timeout=None, + 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( + (("trial_name", request.trial_name),) + ), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + vizier_service.CheckTrialEarlyStoppingStateResponse, + metadata_type=vizier_service.CheckTrialEarlyStoppingStateMetatdata, + ) + + # Done; return the response. + return response + + async def stop_trial( + self, + request: Union[vizier_service.StopTrialRequest, dict] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> study.Trial: + r"""Stops a Trial. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_stop_trial(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.StopTrialRequest( + name="name_value", + ) + + # Make the request + response = await client.stop_trial(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.StopTrialRequest, dict]): + The request object. Request message for + [VizierService.StopTrial][google.cloud.aiplatform.v1.VizierService.StopTrial]. + 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: + google.cloud.aiplatform_v1.types.Trial: + A message representing a Trial. A + Trial contains a unique set of + Parameters that has been or will be + evaluated, along with the objective + metrics got by running the Trial. + + """ + # Create or coerce a protobuf request object. + request = vizier_service.StopTrialRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.stop_trial, + default_timeout=None, + 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 list_optimal_trials( + self, + request: Union[vizier_service.ListOptimalTrialsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> vizier_service.ListOptimalTrialsResponse: + r"""Lists the pareto-optimal Trials for multi-objective Study or the + optimal Trials for single-objective Study. The definition of + pareto-optimal can be checked in wiki page. + https://en.wikipedia.org/wiki/Pareto_efficiency + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + async def sample_list_optimal_trials(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListOptimalTrialsRequest( + parent="parent_value", + ) + + # Make the request + response = await client.list_optimal_trials(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListOptimalTrialsRequest, dict]): + The request object. Request message for + [VizierService.ListOptimalTrials][google.cloud.aiplatform.v1.VizierService.ListOptimalTrials]. + parent (:class:`str`): + Required. The name of the Study that + the optimal Trial belongs to. + + 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: + google.cloud.aiplatform_v1.types.ListOptimalTrialsResponse: + Response message for + [VizierService.ListOptimalTrials][google.cloud.aiplatform.v1.VizierService.ListOptimalTrials]. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = vizier_service.ListOptimalTrialsRequest(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_optimal_trials, + default_timeout=None, + 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_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_operations, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.delete_operation, + default_timeout=None, + 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 cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + 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 wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.wait_operation, + default_timeout=None, + 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 set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_location, + default_timeout=None, + 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 list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_locations, + default_timeout=None, + 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 __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-aiplatform", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ("VizierServiceAsyncClient",) diff --git a/google/cloud/aiplatform_v1/services/vizier_service/client.py b/google/cloud/aiplatform_v1/services/vizier_service/client.py new file mode 100644 index 0000000000..d43ff45ec2 --- /dev/null +++ b/google/cloud/aiplatform_v1/services/vizier_service/client.py @@ -0,0 +1,2601 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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 os +import re +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union +import pkg_resources + +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.auth import credentials as ga_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 + +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + +from google.api_core import operation # type: ignore +from google.api_core import operation_async # type: ignore +from google.cloud.aiplatform_v1.services.vizier_service import pagers +from google.cloud.aiplatform_v1.types import study +from google.cloud.aiplatform_v1.types import study as gca_study +from google.cloud.aiplatform_v1.types import vizier_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.protobuf import timestamp_pb2 # type: ignore +from .transports.base import VizierServiceTransport, DEFAULT_CLIENT_INFO +from .transports.grpc import VizierServiceGrpcTransport +from .transports.grpc_asyncio import VizierServiceGrpcAsyncIOTransport + + +class VizierServiceClientMeta(type): + """Metaclass for the VizierService 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[VizierServiceTransport]] + _transport_registry["grpc"] = VizierServiceGrpcTransport + _transport_registry["grpc_asyncio"] = VizierServiceGrpcAsyncIOTransport + + def get_transport_class( + cls, + label: str = None, + ) -> Type[VizierServiceTransport]: + """Returns 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 VizierServiceClient(metaclass=VizierServiceClientMeta): + """Vertex AI Vizier API. + Vertex AI Vizier is a service to solve blackbox optimization + problems, such as tuning machine learning hyperparameters and + searching over deep learning architectures. + """ + + @staticmethod + def _get_default_mtls_endpoint(api_endpoint): + """Converts 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 = "aiplatform.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + @classmethod + def from_service_account_info(cls, info: dict, *args, **kwargs): + """Creates an instance of this client using the provided credentials + info. + + Args: + info (dict): The service account private key info. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + VizierServiceClient: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_info(info) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + + @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: + VizierServiceClient: 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) -> VizierServiceTransport: + """Returns the transport used by the client instance. + + Returns: + VizierServiceTransport: The transport used by the client + instance. + """ + return self._transport + + @staticmethod + def custom_job_path( + project: str, + location: str, + custom_job: str, + ) -> str: + """Returns a fully-qualified custom_job string.""" + return "projects/{project}/locations/{location}/customJobs/{custom_job}".format( + project=project, + location=location, + custom_job=custom_job, + ) + + @staticmethod + def parse_custom_job_path(path: str) -> Dict[str, str]: + """Parses a custom_job path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/customJobs/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def study_path( + project: str, + location: str, + study: str, + ) -> str: + """Returns a fully-qualified study string.""" + return "projects/{project}/locations/{location}/studies/{study}".format( + project=project, + location=location, + study=study, + ) + + @staticmethod + def parse_study_path(path: str) -> Dict[str, str]: + """Parses a study path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/studies/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def trial_path( + project: str, + location: str, + study: str, + trial: str, + ) -> str: + """Returns a fully-qualified trial string.""" + return "projects/{project}/locations/{location}/studies/{study}/trials/{trial}".format( + project=project, + location=location, + study=study, + trial=trial, + ) + + @staticmethod + def parse_trial_path(path: str) -> Dict[str, str]: + """Parses a trial path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/studies/(?P.+?)/trials/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def common_billing_account_path( + billing_account: str, + ) -> str: + """Returns 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: + """Returns 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: + """Returns 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: + """Returns 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: + """Returns 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 {} + + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + + def __init__( + self, + *, + credentials: Optional[ga_credentials.Credentials] = None, + transport: Union[str, VizierServiceTransport, None] = None, + client_options: Optional[client_options_lib.ClientOptions] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiates the vizier 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, VizierServiceTransport]): The + transport to use. If set to None, a transport is chosen + automatically. + client_options (google.api_core.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. + 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() + + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options + ) + + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) + + # 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, VizierServiceTransport): + # transport is a VizierServiceTransport instance. + if credentials or client_options.credentials_file or api_key_value: + 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: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + + 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, + client_cert_source_for_mtls=client_cert_source_func, + quota_project_id=client_options.quota_project_id, + client_info=client_info, + always_use_jwt_access=True, + ) + + def create_study( + self, + request: Union[vizier_service.CreateStudyRequest, dict] = None, + *, + parent: str = None, + study: gca_study.Study = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_study.Study: + r"""Creates a Study. A resource name will be generated + after creation of the Study. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_create_study(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + study = aiplatform_v1.Study() + study.display_name = "display_name_value" + study.study_spec.metrics.metric_id = "metric_id_value" + study.study_spec.metrics.goal = "MINIMIZE" + study.study_spec.parameters.double_value_spec.min_value = 0.96 + study.study_spec.parameters.double_value_spec.max_value = 0.962 + study.study_spec.parameters.parameter_id = "parameter_id_value" + + request = aiplatform_v1.CreateStudyRequest( + parent="parent_value", + study=study, + ) + + # Make the request + response = client.create_study(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CreateStudyRequest, dict]): + The request object. Request message for + [VizierService.CreateStudy][google.cloud.aiplatform.v1.VizierService.CreateStudy]. + parent (str): + Required. The resource name of the Location to create + the CustomJob in. Format: + ``projects/{project}/locations/{location}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + study (google.cloud.aiplatform_v1.types.Study): + Required. The Study configuration + used to create the Study. + + This corresponds to the ``study`` 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: + google.cloud.aiplatform_v1.types.Study: + A message representing a Study. + """ + # Create or coerce a protobuf request object. + # Quick 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, study]) + 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 vizier_service.CreateStudyRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, vizier_service.CreateStudyRequest): + request = vizier_service.CreateStudyRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if study is not None: + request.study = study + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_study] + + # 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 get_study( + self, + request: Union[vizier_service.GetStudyRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> study.Study: + r"""Gets a Study by name. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_get_study(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetStudyRequest( + name="name_value", + ) + + # Make the request + response = client.get_study(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetStudyRequest, dict]): + The request object. Request message for + [VizierService.GetStudy][google.cloud.aiplatform.v1.VizierService.GetStudy]. + name (str): + Required. The name of the Study resource. Format: + ``projects/{project}/locations/{location}/studies/{study}`` + + 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: + google.cloud.aiplatform_v1.types.Study: + A message representing a Study. + """ + # Create or coerce a protobuf request object. + # Quick 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 vizier_service.GetStudyRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, vizier_service.GetStudyRequest): + request = vizier_service.GetStudyRequest(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_study] + + # 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 list_studies( + self, + request: Union[vizier_service.ListStudiesRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListStudiesPager: + r"""Lists all the studies in a region for an associated + project. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_list_studies(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListStudiesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_studies(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListStudiesRequest, dict]): + The request object. Request message for + [VizierService.ListStudies][google.cloud.aiplatform.v1.VizierService.ListStudies]. + parent (str): + Required. The resource name of the Location to list the + Study from. Format: + ``projects/{project}/locations/{location}`` + + 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: + google.cloud.aiplatform_v1.services.vizier_service.pagers.ListStudiesPager: + Response message for + [VizierService.ListStudies][google.cloud.aiplatform.v1.VizierService.ListStudies]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 vizier_service.ListStudiesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, vizier_service.ListStudiesRequest): + request = vizier_service.ListStudiesRequest(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_studies] + + # 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.ListStudiesPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_study( + self, + request: Union[vizier_service.DeleteStudyRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a Study. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_delete_study(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteStudyRequest( + name="name_value", + ) + + # Make the request + client.delete_study(request=request) + + Args: + request (Union[google.cloud.aiplatform_v1.types.DeleteStudyRequest, dict]): + The request object. Request message for + [VizierService.DeleteStudy][google.cloud.aiplatform.v1.VizierService.DeleteStudy]. + name (str): + Required. The name of the Study resource to be deleted. + Format: + ``projects/{project}/locations/{location}/studies/{study}`` + + 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. + # Quick 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 vizier_service.DeleteStudyRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, vizier_service.DeleteStudyRequest): + request = vizier_service.DeleteStudyRequest(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_study] + + # 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 lookup_study( + self, + request: Union[vizier_service.LookupStudyRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> study.Study: + r"""Looks a study up using the user-defined display_name field + instead of the fully qualified resource name. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_lookup_study(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.LookupStudyRequest( + parent="parent_value", + display_name="display_name_value", + ) + + # Make the request + response = client.lookup_study(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.LookupStudyRequest, dict]): + The request object. Request message for + [VizierService.LookupStudy][google.cloud.aiplatform.v1.VizierService.LookupStudy]. + parent (str): + Required. The resource name of the Location to get the + Study from. Format: + ``projects/{project}/locations/{location}`` + + 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: + google.cloud.aiplatform_v1.types.Study: + A message representing a Study. + """ + # Create or coerce a protobuf request object. + # Quick 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 vizier_service.LookupStudyRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, vizier_service.LookupStudyRequest): + request = vizier_service.LookupStudyRequest(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.lookup_study] + + # 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 suggest_trials( + self, + request: Union[vizier_service.SuggestTrialsRequest, dict] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Adds one or more Trials to a Study, with parameter values + suggested by Vertex AI Vizier. Returns a long-running operation + associated with the generation of Trial suggestions. When this + long-running operation succeeds, it will contain a + [SuggestTrialsResponse][google.cloud.ml.v1.SuggestTrialsResponse]. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_suggest_trials(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.SuggestTrialsRequest( + parent="parent_value", + suggestion_count=1744, + client_id="client_id_value", + ) + + # Make the request + operation = client.suggest_trials(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.SuggestTrialsRequest, dict]): + The request object. Request message for + [VizierService.SuggestTrials][google.cloud.aiplatform.v1.VizierService.SuggestTrials]. + 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.aiplatform_v1.types.SuggestTrialsResponse` + Response message for + [VizierService.SuggestTrials][google.cloud.aiplatform.v1.VizierService.SuggestTrials]. + + """ + # Create or coerce a protobuf request object. + # Minor optimization to avoid making a copy if the user passes + # in a vizier_service.SuggestTrialsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, vizier_service.SuggestTrialsRequest): + request = vizier_service.SuggestTrialsRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.suggest_trials] + + # 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, + ) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + vizier_service.SuggestTrialsResponse, + metadata_type=vizier_service.SuggestTrialsMetadata, + ) + + # Done; return the response. + return response + + def create_trial( + self, + request: Union[vizier_service.CreateTrialRequest, dict] = None, + *, + parent: str = None, + trial: study.Trial = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> study.Trial: + r"""Adds a user provided Trial to a Study. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_create_trial(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateTrialRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_trial(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CreateTrialRequest, dict]): + The request object. Request message for + [VizierService.CreateTrial][google.cloud.aiplatform.v1.VizierService.CreateTrial]. + parent (str): + Required. The resource name of the Study to create the + Trial in. Format: + ``projects/{project}/locations/{location}/studies/{study}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + trial (google.cloud.aiplatform_v1.types.Trial): + Required. The Trial to create. + This corresponds to the ``trial`` 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: + google.cloud.aiplatform_v1.types.Trial: + A message representing a Trial. A + Trial contains a unique set of + Parameters that has been or will be + evaluated, along with the objective + metrics got by running the Trial. + + """ + # Create or coerce a protobuf request object. + # Quick 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, trial]) + 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 vizier_service.CreateTrialRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, vizier_service.CreateTrialRequest): + request = vizier_service.CreateTrialRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if trial is not None: + request.trial = trial + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_trial] + + # 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 get_trial( + self, + request: Union[vizier_service.GetTrialRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> study.Trial: + r"""Gets a Trial. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_get_trial(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetTrialRequest( + name="name_value", + ) + + # Make the request + response = client.get_trial(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.GetTrialRequest, dict]): + The request object. Request message for + [VizierService.GetTrial][google.cloud.aiplatform.v1.VizierService.GetTrial]. + name (str): + Required. The name of the Trial resource. Format: + ``projects/{project}/locations/{location}/studies/{study}/trials/{trial}`` + + 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: + google.cloud.aiplatform_v1.types.Trial: + A message representing a Trial. A + Trial contains a unique set of + Parameters that has been or will be + evaluated, along with the objective + metrics got by running the Trial. + + """ + # Create or coerce a protobuf request object. + # Quick 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 vizier_service.GetTrialRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, vizier_service.GetTrialRequest): + request = vizier_service.GetTrialRequest(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_trial] + + # 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 list_trials( + self, + request: Union[vizier_service.ListTrialsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListTrialsPager: + r"""Lists the Trials associated with a Study. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_list_trials(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListTrialsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_trials(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListTrialsRequest, dict]): + The request object. Request message for + [VizierService.ListTrials][google.cloud.aiplatform.v1.VizierService.ListTrials]. + parent (str): + Required. The resource name of the Study to list the + Trial from. Format: + ``projects/{project}/locations/{location}/studies/{study}`` + + 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: + google.cloud.aiplatform_v1.services.vizier_service.pagers.ListTrialsPager: + Response message for + [VizierService.ListTrials][google.cloud.aiplatform.v1.VizierService.ListTrials]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 vizier_service.ListTrialsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, vizier_service.ListTrialsRequest): + request = vizier_service.ListTrialsRequest(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_trials] + + # 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.ListTrialsPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def add_trial_measurement( + self, + request: Union[vizier_service.AddTrialMeasurementRequest, dict] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> study.Trial: + r"""Adds a measurement of the objective metrics to a + Trial. This measurement is assumed to have been taken + before the Trial is complete. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_add_trial_measurement(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.AddTrialMeasurementRequest( + trial_name="trial_name_value", + ) + + # Make the request + response = client.add_trial_measurement(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.AddTrialMeasurementRequest, dict]): + The request object. Request message for + [VizierService.AddTrialMeasurement][google.cloud.aiplatform.v1.VizierService.AddTrialMeasurement]. + 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: + google.cloud.aiplatform_v1.types.Trial: + A message representing a Trial. A + Trial contains a unique set of + Parameters that has been or will be + evaluated, along with the objective + metrics got by running the Trial. + + """ + # Create or coerce a protobuf request object. + # Minor optimization to avoid making a copy if the user passes + # in a vizier_service.AddTrialMeasurementRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, vizier_service.AddTrialMeasurementRequest): + request = vizier_service.AddTrialMeasurementRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.add_trial_measurement] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("trial_name", request.trial_name),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def complete_trial( + self, + request: Union[vizier_service.CompleteTrialRequest, dict] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> study.Trial: + r"""Marks a Trial as complete. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_complete_trial(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CompleteTrialRequest( + name="name_value", + ) + + # Make the request + response = client.complete_trial(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CompleteTrialRequest, dict]): + The request object. Request message for + [VizierService.CompleteTrial][google.cloud.aiplatform.v1.VizierService.CompleteTrial]. + 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: + google.cloud.aiplatform_v1.types.Trial: + A message representing a Trial. A + Trial contains a unique set of + Parameters that has been or will be + evaluated, along with the objective + metrics got by running the Trial. + + """ + # Create or coerce a protobuf request object. + # Minor optimization to avoid making a copy if the user passes + # in a vizier_service.CompleteTrialRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, vizier_service.CompleteTrialRequest): + request = vizier_service.CompleteTrialRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.complete_trial] + + # 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_trial( + self, + request: Union[vizier_service.DeleteTrialRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a Trial. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_delete_trial(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteTrialRequest( + name="name_value", + ) + + # Make the request + client.delete_trial(request=request) + + Args: + request (Union[google.cloud.aiplatform_v1.types.DeleteTrialRequest, dict]): + The request object. Request message for + [VizierService.DeleteTrial][google.cloud.aiplatform.v1.VizierService.DeleteTrial]. + name (str): + Required. The Trial's name. Format: + ``projects/{project}/locations/{location}/studies/{study}/trials/{trial}`` + + 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. + # Quick 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 vizier_service.DeleteTrialRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, vizier_service.DeleteTrialRequest): + request = vizier_service.DeleteTrialRequest(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_trial] + + # 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 check_trial_early_stopping_state( + self, + request: Union[vizier_service.CheckTrialEarlyStoppingStateRequest, dict] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation.Operation: + r"""Checks whether a Trial should stop or not. Returns a + long-running operation. When the operation is successful, it + will contain a + [CheckTrialEarlyStoppingStateResponse][google.cloud.ml.v1.CheckTrialEarlyStoppingStateResponse]. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_check_trial_early_stopping_state(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CheckTrialEarlyStoppingStateRequest( + trial_name="trial_name_value", + ) + + # Make the request + operation = client.check_trial_early_stopping_state(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.CheckTrialEarlyStoppingStateRequest, dict]): + The request object. Request message for + [VizierService.CheckTrialEarlyStoppingState][google.cloud.aiplatform.v1.VizierService.CheckTrialEarlyStoppingState]. + 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.aiplatform_v1.types.CheckTrialEarlyStoppingStateResponse` + Response message for + [VizierService.CheckTrialEarlyStoppingState][google.cloud.aiplatform.v1.VizierService.CheckTrialEarlyStoppingState]. + + """ + # Create or coerce a protobuf request object. + # Minor optimization to avoid making a copy if the user passes + # in a vizier_service.CheckTrialEarlyStoppingStateRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, vizier_service.CheckTrialEarlyStoppingStateRequest): + request = vizier_service.CheckTrialEarlyStoppingStateRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.check_trial_early_stopping_state + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("trial_name", request.trial_name),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation.from_gapic( + response, + self._transport.operations_client, + vizier_service.CheckTrialEarlyStoppingStateResponse, + metadata_type=vizier_service.CheckTrialEarlyStoppingStateMetatdata, + ) + + # Done; return the response. + return response + + def stop_trial( + self, + request: Union[vizier_service.StopTrialRequest, dict] = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> study.Trial: + r"""Stops a Trial. + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_stop_trial(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.StopTrialRequest( + name="name_value", + ) + + # Make the request + response = client.stop_trial(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.StopTrialRequest, dict]): + The request object. Request message for + [VizierService.StopTrial][google.cloud.aiplatform.v1.VizierService.StopTrial]. + 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: + google.cloud.aiplatform_v1.types.Trial: + A message representing a Trial. A + Trial contains a unique set of + Parameters that has been or will be + evaluated, along with the objective + metrics got by running the Trial. + + """ + # Create or coerce a protobuf request object. + # Minor optimization to avoid making a copy if the user passes + # in a vizier_service.StopTrialRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, vizier_service.StopTrialRequest): + request = vizier_service.StopTrialRequest(request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.stop_trial] + + # 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 list_optimal_trials( + self, + request: Union[vizier_service.ListOptimalTrialsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> vizier_service.ListOptimalTrialsResponse: + r"""Lists the pareto-optimal Trials for multi-objective Study or the + optimal Trials for single-objective Study. The definition of + pareto-optimal can be checked in wiki page. + https://en.wikipedia.org/wiki/Pareto_efficiency + + .. code-block:: python + + from google.cloud import aiplatform_v1 + + def sample_list_optimal_trials(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListOptimalTrialsRequest( + parent="parent_value", + ) + + # Make the request + response = client.list_optimal_trials(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1.types.ListOptimalTrialsRequest, dict]): + The request object. Request message for + [VizierService.ListOptimalTrials][google.cloud.aiplatform.v1.VizierService.ListOptimalTrials]. + parent (str): + Required. The name of the Study that + the optimal Trial belongs to. + + 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: + google.cloud.aiplatform_v1.types.ListOptimalTrialsResponse: + Response message for + [VizierService.ListOptimalTrials][google.cloud.aiplatform.v1.VizierService.ListOptimalTrials]. + + """ + # Create or coerce a protobuf request object. + # Quick 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 vizier_service.ListOptimalTrialsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, vizier_service.ListOptimalTrialsRequest): + request = vizier_service.ListOptimalTrialsRequest(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_optimal_trials] + + # 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 __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_operations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.delete_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.wait_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_location, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_locations, + default_timeout=None, + 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 = 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-aiplatform", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ("VizierServiceClient",) diff --git a/google/cloud/aiplatform_v1/services/vizier_service/pagers.py b/google/cloud/aiplatform_v1/services/vizier_service/pagers.py new file mode 100644 index 0000000000..b17d3e2759 --- /dev/null +++ b/google/cloud/aiplatform_v1/services/vizier_service/pagers.py @@ -0,0 +1,284 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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 typing import ( + Any, + AsyncIterator, + Awaitable, + Callable, + Sequence, + Tuple, + Optional, + Iterator, +) + +from google.cloud.aiplatform_v1.types import study +from google.cloud.aiplatform_v1.types import vizier_service + + +class ListStudiesPager: + """A pager for iterating through ``list_studies`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListStudiesResponse` object, and + provides an ``__iter__`` method to iterate through its + ``studies`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListStudies`` requests and continue to iterate + through the ``studies`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListStudiesResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., vizier_service.ListStudiesResponse], + request: vizier_service.ListStudiesRequest, + response: vizier_service.ListStudiesResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListStudiesRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListStudiesResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = vizier_service.ListStudiesRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[vizier_service.ListStudiesResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterator[study.Study]: + for page in self.pages: + yield from page.studies + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListStudiesAsyncPager: + """A pager for iterating through ``list_studies`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListStudiesResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``studies`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListStudies`` requests and continue to iterate + through the ``studies`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListStudiesResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., Awaitable[vizier_service.ListStudiesResponse]], + request: vizier_service.ListStudiesRequest, + response: vizier_service.ListStudiesResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListStudiesRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListStudiesResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = vizier_service.ListStudiesRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[vizier_service.ListStudiesResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + + def __aiter__(self) -> AsyncIterator[study.Study]: + async def async_generator(): + async for page in self.pages: + for response in page.studies: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListTrialsPager: + """A pager for iterating through ``list_trials`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListTrialsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``trials`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListTrials`` requests and continue to iterate + through the ``trials`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListTrialsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., vizier_service.ListTrialsResponse], + request: vizier_service.ListTrialsRequest, + response: vizier_service.ListTrialsResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListTrialsRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListTrialsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = vizier_service.ListTrialsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[vizier_service.ListTrialsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterator[study.Trial]: + for page in self.pages: + yield from page.trials + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListTrialsAsyncPager: + """A pager for iterating through ``list_trials`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1.types.ListTrialsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``trials`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListTrials`` requests and continue to iterate + through the ``trials`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1.types.ListTrialsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., Awaitable[vizier_service.ListTrialsResponse]], + request: vizier_service.ListTrialsRequest, + response: vizier_service.ListTrialsResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1.types.ListTrialsRequest): + The initial request object. + response (google.cloud.aiplatform_v1.types.ListTrialsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = vizier_service.ListTrialsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[vizier_service.ListTrialsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + + def __aiter__(self) -> AsyncIterator[study.Trial]: + async def async_generator(): + async for page in self.pages: + for response in page.trials: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) diff --git a/google/cloud/aiplatform_v1/services/vizier_service/transports/__init__.py b/google/cloud/aiplatform_v1/services/vizier_service/transports/__init__.py new file mode 100644 index 0000000000..a4efbdf8d6 --- /dev/null +++ b/google/cloud/aiplatform_v1/services/vizier_service/transports/__init__.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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 typing import Dict, Type + +from .base import VizierServiceTransport +from .grpc import VizierServiceGrpcTransport +from .grpc_asyncio import VizierServiceGrpcAsyncIOTransport + + +# Compile a registry of transports. +_transport_registry = OrderedDict() # type: Dict[str, Type[VizierServiceTransport]] +_transport_registry["grpc"] = VizierServiceGrpcTransport +_transport_registry["grpc_asyncio"] = VizierServiceGrpcAsyncIOTransport + +__all__ = ( + "VizierServiceTransport", + "VizierServiceGrpcTransport", + "VizierServiceGrpcAsyncIOTransport", +) diff --git a/google/cloud/aiplatform_v1/services/vizier_service/transports/base.py b/google/cloud/aiplatform_v1/services/vizier_service/transports/base.py new file mode 100644 index 0000000000..8b906c812f --- /dev/null +++ b/google/cloud/aiplatform_v1/services/vizier_service/transports/base.py @@ -0,0 +1,461 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import abc +from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +import pkg_resources + +import google.auth # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import operations_v1 +from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore + +from google.cloud.aiplatform_v1.types import study +from google.cloud.aiplatform_v1.types import study as gca_study +from google.cloud.aiplatform_v1.types import vizier_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import empty_pb2 # type: ignore + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-aiplatform", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +class VizierServiceTransport(abc.ABC): + """Abstract transport class for VizierService.""" + + AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",) + + DEFAULT_HOST: str = "aiplatform.googleapis.com" + + def __init__( + self, + *, + host: str = DEFAULT_HOST, + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + **kwargs, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + 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. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is mutually exclusive with credentials. + scopes (Optional[Sequence[str]]): A list of scopes. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + 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. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + """ + + # Save the hostname. Default to port 443 (HTTPS) if none is specified. + if ":" not in host: + host += ":443" + self._host = host + + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} + + # Save the scopes. + self._scopes = scopes + + # If no credentials are provided, then determine the appropriate + # defaults. + if credentials and credentials_file: + raise core_exceptions.DuplicateCredentialArgs( + "'credentials_file' and 'credentials' are mutually exclusive" + ) + + if credentials_file is not None: + credentials, _ = google.auth.load_credentials_from_file( + credentials_file, **scopes_kwargs, quota_project_id=quota_project_id + ) + elif credentials is None: + credentials, _ = google.auth.default( + **scopes_kwargs, quota_project_id=quota_project_id + ) + + # If the credentials are service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") + ): + credentials = credentials.with_always_use_jwt_access(True) + + # Save the credentials. + self._credentials = credentials + + def _prep_wrapped_messages(self, client_info): + # Precompute the wrapped methods. + self._wrapped_methods = { + self.create_study: gapic_v1.method.wrap_method( + self.create_study, + default_timeout=None, + client_info=client_info, + ), + self.get_study: gapic_v1.method.wrap_method( + self.get_study, + default_timeout=None, + client_info=client_info, + ), + self.list_studies: gapic_v1.method.wrap_method( + self.list_studies, + default_timeout=None, + client_info=client_info, + ), + self.delete_study: gapic_v1.method.wrap_method( + self.delete_study, + default_timeout=None, + client_info=client_info, + ), + self.lookup_study: gapic_v1.method.wrap_method( + self.lookup_study, + default_timeout=None, + client_info=client_info, + ), + self.suggest_trials: gapic_v1.method.wrap_method( + self.suggest_trials, + default_timeout=None, + client_info=client_info, + ), + self.create_trial: gapic_v1.method.wrap_method( + self.create_trial, + default_timeout=None, + client_info=client_info, + ), + self.get_trial: gapic_v1.method.wrap_method( + self.get_trial, + default_timeout=None, + client_info=client_info, + ), + self.list_trials: gapic_v1.method.wrap_method( + self.list_trials, + default_timeout=None, + client_info=client_info, + ), + self.add_trial_measurement: gapic_v1.method.wrap_method( + self.add_trial_measurement, + default_timeout=None, + client_info=client_info, + ), + self.complete_trial: gapic_v1.method.wrap_method( + self.complete_trial, + default_timeout=None, + client_info=client_info, + ), + self.delete_trial: gapic_v1.method.wrap_method( + self.delete_trial, + default_timeout=None, + client_info=client_info, + ), + self.check_trial_early_stopping_state: gapic_v1.method.wrap_method( + self.check_trial_early_stopping_state, + default_timeout=None, + client_info=client_info, + ), + self.stop_trial: gapic_v1.method.wrap_method( + self.stop_trial, + default_timeout=None, + client_info=client_info, + ), + self.list_optimal_trials: gapic_v1.method.wrap_method( + self.list_optimal_trials, + default_timeout=None, + client_info=client_info, + ), + } + + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + + @property + def operations_client(self): + """Return the client designed to process long-running operations.""" + raise NotImplementedError() + + @property + def create_study( + self, + ) -> Callable[ + [vizier_service.CreateStudyRequest], + Union[gca_study.Study, Awaitable[gca_study.Study]], + ]: + raise NotImplementedError() + + @property + def get_study( + self, + ) -> Callable[ + [vizier_service.GetStudyRequest], Union[study.Study, Awaitable[study.Study]] + ]: + raise NotImplementedError() + + @property + def list_studies( + self, + ) -> Callable[ + [vizier_service.ListStudiesRequest], + Union[ + vizier_service.ListStudiesResponse, + Awaitable[vizier_service.ListStudiesResponse], + ], + ]: + raise NotImplementedError() + + @property + def delete_study( + self, + ) -> Callable[ + [vizier_service.DeleteStudyRequest], + Union[empty_pb2.Empty, Awaitable[empty_pb2.Empty]], + ]: + raise NotImplementedError() + + @property + def lookup_study( + self, + ) -> Callable[ + [vizier_service.LookupStudyRequest], Union[study.Study, Awaitable[study.Study]] + ]: + raise NotImplementedError() + + @property + def suggest_trials( + self, + ) -> Callable[ + [vizier_service.SuggestTrialsRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def create_trial( + self, + ) -> Callable[ + [vizier_service.CreateTrialRequest], Union[study.Trial, Awaitable[study.Trial]] + ]: + raise NotImplementedError() + + @property + def get_trial( + self, + ) -> Callable[ + [vizier_service.GetTrialRequest], Union[study.Trial, Awaitable[study.Trial]] + ]: + raise NotImplementedError() + + @property + def list_trials( + self, + ) -> Callable[ + [vizier_service.ListTrialsRequest], + Union[ + vizier_service.ListTrialsResponse, + Awaitable[vizier_service.ListTrialsResponse], + ], + ]: + raise NotImplementedError() + + @property + def add_trial_measurement( + self, + ) -> Callable[ + [vizier_service.AddTrialMeasurementRequest], + Union[study.Trial, Awaitable[study.Trial]], + ]: + raise NotImplementedError() + + @property + def complete_trial( + self, + ) -> Callable[ + [vizier_service.CompleteTrialRequest], + Union[study.Trial, Awaitable[study.Trial]], + ]: + raise NotImplementedError() + + @property + def delete_trial( + self, + ) -> Callable[ + [vizier_service.DeleteTrialRequest], + Union[empty_pb2.Empty, Awaitable[empty_pb2.Empty]], + ]: + raise NotImplementedError() + + @property + def check_trial_early_stopping_state( + self, + ) -> Callable[ + [vizier_service.CheckTrialEarlyStoppingStateRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def stop_trial( + self, + ) -> Callable[ + [vizier_service.StopTrialRequest], Union[study.Trial, Awaitable[study.Trial]] + ]: + raise NotImplementedError() + + @property + def list_optimal_trials( + self, + ) -> Callable[ + [vizier_service.ListOptimalTrialsRequest], + Union[ + vizier_service.ListOptimalTrialsResponse, + Awaitable[vizier_service.ListOptimalTrialsResponse], + ], + ]: + raise NotImplementedError() + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], + Union[ + operations_pb2.ListOperationsResponse, + Awaitable[operations_pb2.ListOperationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None,]: + raise NotImplementedError() + + @property + def wait_operation( + self, + ) -> Callable[ + [operations_pb2.WaitOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def set_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def get_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_location( + self, + ) -> Callable[ + [locations_pb2.GetLocationRequest], + Union[locations_pb2.Location, Awaitable[locations_pb2.Location]], + ]: + raise NotImplementedError() + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], + Union[ + locations_pb2.ListLocationsResponse, + Awaitable[locations_pb2.ListLocationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + + +__all__ = ("VizierServiceTransport",) diff --git a/google/cloud/aiplatform_v1/services/vizier_service/transports/grpc.py b/google/cloud/aiplatform_v1/services/vizier_service/transports/grpc.py new file mode 100644 index 0000000000..1fdba5d15d --- /dev/null +++ b/google/cloud/aiplatform_v1/services/vizier_service/transports/grpc.py @@ -0,0 +1,879 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import warnings +from typing import Callable, Dict, Optional, Sequence, Tuple, Union + +from google.api_core import grpc_helpers +from google.api_core import operations_v1 +from google.api_core import gapic_v1 +import google.auth # type: ignore +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore + +import grpc # type: ignore + +from google.cloud.aiplatform_v1.types import study +from google.cloud.aiplatform_v1.types import study as gca_study +from google.cloud.aiplatform_v1.types import vizier_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import empty_pb2 # type: ignore +from .base import VizierServiceTransport, DEFAULT_CLIENT_INFO + + +class VizierServiceGrpcTransport(VizierServiceTransport): + """gRPC backend transport for VizierService. + + Vertex AI Vizier API. + Vertex AI Vizier is a service to solve blackbox optimization + problems, such as tuning machine learning hyperparameters and + searching over deep learning architectures. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + + _stubs: Dict[str, Callable] + + def __init__( + self, + *, + host: str = "aiplatform.googleapis.com", + credentials: ga_credentials.Credentials = None, + credentials_file: str = None, + scopes: Sequence[str] = None, + channel: grpc.Channel = None, + api_mtls_endpoint: str = None, + client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, + ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, + quota_project_id: Optional[str] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + 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. + This argument is ignored if ``channel`` is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional(Sequence[str])): A list of scopes. This argument is + ignored if ``channel`` is provided. + channel (Optional[grpc.Channel]): A ``Channel`` instance through + which to make calls. + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or application default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for the grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure a mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + 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. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + self._grpc_channel = None + self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client: Optional[operations_v1.OperationsClient] = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + + if channel: + # Ignore credentials if a channel was passed. + credentials = False + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + self._ssl_channel_credentials = None + + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials + + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + ) + + if not self._grpc_channel: + self._grpc_channel = type(self).create_channel( + self._host, + # use the credentials which are saved + credentials=self._credentials, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, + quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) + + @classmethod + def create_channel( + cls, + host: str = "aiplatform.googleapis.com", + credentials: ga_credentials.Credentials = None, + credentials_file: str = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs, + ) -> grpc.Channel: + """Create and return a gRPC channel object. + Args: + host (Optional[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is mutually exclusive with credentials. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + grpc.Channel: A gRPC channel object. + + Raises: + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + + return grpc_helpers.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + quota_project_id=quota_project_id, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, + **kwargs, + ) + + @property + def grpc_channel(self) -> grpc.Channel: + """Return the channel designed to connect to this service.""" + return self._grpc_channel + + @property + def operations_client(self) -> operations_v1.OperationsClient: + """Create the client designed to process long-running operations. + + This property caches on the instance; repeated calls return the same + client. + """ + # Quick check: Only create a new client if we do not already have one. + if self._operations_client is None: + self._operations_client = operations_v1.OperationsClient(self.grpc_channel) + + # Return the client from cache. + return self._operations_client + + @property + def create_study( + self, + ) -> Callable[[vizier_service.CreateStudyRequest], gca_study.Study]: + r"""Return a callable for the create study method over gRPC. + + Creates a Study. A resource name will be generated + after creation of the Study. + + Returns: + Callable[[~.CreateStudyRequest], + ~.Study]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_study" not in self._stubs: + self._stubs["create_study"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.VizierService/CreateStudy", + request_serializer=vizier_service.CreateStudyRequest.serialize, + response_deserializer=gca_study.Study.deserialize, + ) + return self._stubs["create_study"] + + @property + def get_study(self) -> Callable[[vizier_service.GetStudyRequest], study.Study]: + r"""Return a callable for the get study method over gRPC. + + Gets a Study by name. + + Returns: + Callable[[~.GetStudyRequest], + ~.Study]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_study" not in self._stubs: + self._stubs["get_study"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.VizierService/GetStudy", + request_serializer=vizier_service.GetStudyRequest.serialize, + response_deserializer=study.Study.deserialize, + ) + return self._stubs["get_study"] + + @property + def list_studies( + self, + ) -> Callable[ + [vizier_service.ListStudiesRequest], vizier_service.ListStudiesResponse + ]: + r"""Return a callable for the list studies method over gRPC. + + Lists all the studies in a region for an associated + project. + + Returns: + Callable[[~.ListStudiesRequest], + ~.ListStudiesResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_studies" not in self._stubs: + self._stubs["list_studies"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.VizierService/ListStudies", + request_serializer=vizier_service.ListStudiesRequest.serialize, + response_deserializer=vizier_service.ListStudiesResponse.deserialize, + ) + return self._stubs["list_studies"] + + @property + def delete_study( + self, + ) -> Callable[[vizier_service.DeleteStudyRequest], empty_pb2.Empty]: + r"""Return a callable for the delete study method over gRPC. + + Deletes a Study. + + Returns: + Callable[[~.DeleteStudyRequest], + ~.Empty]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_study" not in self._stubs: + self._stubs["delete_study"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.VizierService/DeleteStudy", + request_serializer=vizier_service.DeleteStudyRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs["delete_study"] + + @property + def lookup_study( + self, + ) -> Callable[[vizier_service.LookupStudyRequest], study.Study]: + r"""Return a callable for the lookup study method over gRPC. + + Looks a study up using the user-defined display_name field + instead of the fully qualified resource name. + + Returns: + Callable[[~.LookupStudyRequest], + ~.Study]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "lookup_study" not in self._stubs: + self._stubs["lookup_study"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.VizierService/LookupStudy", + request_serializer=vizier_service.LookupStudyRequest.serialize, + response_deserializer=study.Study.deserialize, + ) + return self._stubs["lookup_study"] + + @property + def suggest_trials( + self, + ) -> Callable[[vizier_service.SuggestTrialsRequest], operations_pb2.Operation]: + r"""Return a callable for the suggest trials method over gRPC. + + Adds one or more Trials to a Study, with parameter values + suggested by Vertex AI Vizier. Returns a long-running operation + associated with the generation of Trial suggestions. When this + long-running operation succeeds, it will contain a + [SuggestTrialsResponse][google.cloud.ml.v1.SuggestTrialsResponse]. + + Returns: + Callable[[~.SuggestTrialsRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "suggest_trials" not in self._stubs: + self._stubs["suggest_trials"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.VizierService/SuggestTrials", + request_serializer=vizier_service.SuggestTrialsRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["suggest_trials"] + + @property + def create_trial( + self, + ) -> Callable[[vizier_service.CreateTrialRequest], study.Trial]: + r"""Return a callable for the create trial method over gRPC. + + Adds a user provided Trial to a Study. + + Returns: + Callable[[~.CreateTrialRequest], + ~.Trial]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_trial" not in self._stubs: + self._stubs["create_trial"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.VizierService/CreateTrial", + request_serializer=vizier_service.CreateTrialRequest.serialize, + response_deserializer=study.Trial.deserialize, + ) + return self._stubs["create_trial"] + + @property + def get_trial(self) -> Callable[[vizier_service.GetTrialRequest], study.Trial]: + r"""Return a callable for the get trial method over gRPC. + + Gets a Trial. + + Returns: + Callable[[~.GetTrialRequest], + ~.Trial]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_trial" not in self._stubs: + self._stubs["get_trial"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.VizierService/GetTrial", + request_serializer=vizier_service.GetTrialRequest.serialize, + response_deserializer=study.Trial.deserialize, + ) + return self._stubs["get_trial"] + + @property + def list_trials( + self, + ) -> Callable[ + [vizier_service.ListTrialsRequest], vizier_service.ListTrialsResponse + ]: + r"""Return a callable for the list trials method over gRPC. + + Lists the Trials associated with a Study. + + Returns: + Callable[[~.ListTrialsRequest], + ~.ListTrialsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_trials" not in self._stubs: + self._stubs["list_trials"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.VizierService/ListTrials", + request_serializer=vizier_service.ListTrialsRequest.serialize, + response_deserializer=vizier_service.ListTrialsResponse.deserialize, + ) + return self._stubs["list_trials"] + + @property + def add_trial_measurement( + self, + ) -> Callable[[vizier_service.AddTrialMeasurementRequest], study.Trial]: + r"""Return a callable for the add trial measurement method over gRPC. + + Adds a measurement of the objective metrics to a + Trial. This measurement is assumed to have been taken + before the Trial is complete. + + Returns: + Callable[[~.AddTrialMeasurementRequest], + ~.Trial]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "add_trial_measurement" not in self._stubs: + self._stubs["add_trial_measurement"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.VizierService/AddTrialMeasurement", + request_serializer=vizier_service.AddTrialMeasurementRequest.serialize, + response_deserializer=study.Trial.deserialize, + ) + return self._stubs["add_trial_measurement"] + + @property + def complete_trial( + self, + ) -> Callable[[vizier_service.CompleteTrialRequest], study.Trial]: + r"""Return a callable for the complete trial method over gRPC. + + Marks a Trial as complete. + + Returns: + Callable[[~.CompleteTrialRequest], + ~.Trial]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "complete_trial" not in self._stubs: + self._stubs["complete_trial"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.VizierService/CompleteTrial", + request_serializer=vizier_service.CompleteTrialRequest.serialize, + response_deserializer=study.Trial.deserialize, + ) + return self._stubs["complete_trial"] + + @property + def delete_trial( + self, + ) -> Callable[[vizier_service.DeleteTrialRequest], empty_pb2.Empty]: + r"""Return a callable for the delete trial method over gRPC. + + Deletes a Trial. + + Returns: + Callable[[~.DeleteTrialRequest], + ~.Empty]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_trial" not in self._stubs: + self._stubs["delete_trial"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.VizierService/DeleteTrial", + request_serializer=vizier_service.DeleteTrialRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs["delete_trial"] + + @property + def check_trial_early_stopping_state( + self, + ) -> Callable[ + [vizier_service.CheckTrialEarlyStoppingStateRequest], operations_pb2.Operation + ]: + r"""Return a callable for the check trial early stopping + state method over gRPC. + + Checks whether a Trial should stop or not. Returns a + long-running operation. When the operation is successful, it + will contain a + [CheckTrialEarlyStoppingStateResponse][google.cloud.ml.v1.CheckTrialEarlyStoppingStateResponse]. + + Returns: + Callable[[~.CheckTrialEarlyStoppingStateRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "check_trial_early_stopping_state" not in self._stubs: + self._stubs[ + "check_trial_early_stopping_state" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.VizierService/CheckTrialEarlyStoppingState", + request_serializer=vizier_service.CheckTrialEarlyStoppingStateRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["check_trial_early_stopping_state"] + + @property + def stop_trial(self) -> Callable[[vizier_service.StopTrialRequest], study.Trial]: + r"""Return a callable for the stop trial method over gRPC. + + Stops a Trial. + + Returns: + Callable[[~.StopTrialRequest], + ~.Trial]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "stop_trial" not in self._stubs: + self._stubs["stop_trial"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.VizierService/StopTrial", + request_serializer=vizier_service.StopTrialRequest.serialize, + response_deserializer=study.Trial.deserialize, + ) + return self._stubs["stop_trial"] + + @property + def list_optimal_trials( + self, + ) -> Callable[ + [vizier_service.ListOptimalTrialsRequest], + vizier_service.ListOptimalTrialsResponse, + ]: + r"""Return a callable for the list optimal trials method over gRPC. + + Lists the pareto-optimal Trials for multi-objective Study or the + optimal Trials for single-objective Study. The definition of + pareto-optimal can be checked in wiki page. + https://en.wikipedia.org/wiki/Pareto_efficiency + + Returns: + Callable[[~.ListOptimalTrialsRequest], + ~.ListOptimalTrialsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_optimal_trials" not in self._stubs: + self._stubs["list_optimal_trials"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.VizierService/ListOptimalTrials", + request_serializer=vizier_service.ListOptimalTrialsRequest.serialize, + response_deserializer=vizier_service.ListOptimalTrialsResponse.deserialize, + ) + return self._stubs["list_optimal_trials"] + + def close(self): + self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + @property + def kind(self) -> str: + return "grpc" + + +__all__ = ("VizierServiceGrpcTransport",) diff --git a/google/cloud/aiplatform_v1/services/vizier_service/transports/grpc_asyncio.py b/google/cloud/aiplatform_v1/services/vizier_service/transports/grpc_asyncio.py new file mode 100644 index 0000000000..78912c5c90 --- /dev/null +++ b/google/cloud/aiplatform_v1/services/vizier_service/transports/grpc_asyncio.py @@ -0,0 +1,890 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import warnings +from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union + +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import operations_v1 +from google.auth import credentials as ga_credentials # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore + +import grpc # type: ignore +from grpc.experimental import aio # type: ignore + +from google.cloud.aiplatform_v1.types import study +from google.cloud.aiplatform_v1.types import study as gca_study +from google.cloud.aiplatform_v1.types import vizier_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.longrunning import operations_pb2 # type: ignore +from google.protobuf import empty_pb2 # type: ignore +from .base import VizierServiceTransport, DEFAULT_CLIENT_INFO +from .grpc import VizierServiceGrpcTransport + + +class VizierServiceGrpcAsyncIOTransport(VizierServiceTransport): + """gRPC AsyncIO backend transport for VizierService. + + Vertex AI Vizier API. + Vertex AI Vizier is a service to solve blackbox optimization + problems, such as tuning machine learning hyperparameters and + searching over deep learning architectures. + + This class defines the same methods as the primary client, so the + primary client can load the underlying transport implementation + and call it. + + It sends protocol buffers over the wire using gRPC (which is built on + top of HTTP/2); the ``grpcio`` package must be installed. + """ + + _grpc_channel: aio.Channel + _stubs: Dict[str, Callable] = {} + + @classmethod + def create_channel( + cls, + host: str = "aiplatform.googleapis.com", + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + quota_project_id: Optional[str] = None, + **kwargs, + ) -> aio.Channel: + """Create and return a gRPC AsyncIO channel object. + Args: + host (Optional[str]): The host for the channel to use. + credentials (Optional[~.Credentials]): The + authorization credentials to attach to requests. These + credentials identify this application to the service. If + none are specified, the client will attempt to ascertain + the credentials from the environment. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + kwargs (Optional[dict]): Keyword arguments, which are passed to the + channel creation. + Returns: + aio.Channel: A gRPC AsyncIO channel object. + """ + + return grpc_helpers_async.create_channel( + host, + credentials=credentials, + credentials_file=credentials_file, + quota_project_id=quota_project_id, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, + **kwargs, + ) + + def __init__( + self, + *, + host: str = "aiplatform.googleapis.com", + credentials: ga_credentials.Credentials = None, + credentials_file: Optional[str] = None, + scopes: Optional[Sequence[str]] = None, + channel: aio.Channel = None, + api_mtls_endpoint: str = None, + client_cert_source: Callable[[], Tuple[bytes, bytes]] = None, + ssl_channel_credentials: grpc.ChannelCredentials = None, + client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, + quota_project_id=None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, + ) -> None: + """Instantiate the transport. + + Args: + host (Optional[str]): + The hostname to connect to. + 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. + This argument is ignored if ``channel`` is provided. + credentials_file (Optional[str]): A file with credentials that can + be loaded with :func:`google.auth.load_credentials_from_file`. + This argument is ignored if ``channel`` is provided. + scopes (Optional[Sequence[str]]): A optional list of scopes needed for this + service. These are only used when credentials are not specified and + are passed to :func:`google.auth.default`. + channel (Optional[aio.Channel]): A ``Channel`` instance through + which to make calls. + api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. + If provided, it overrides the ``host`` argument and tries to create + a mutual TLS channel with client SSL credentials from + ``client_cert_source`` or application default SSL credentials. + client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): + Deprecated. A callback to provide client SSL certificate bytes and + private key bytes, both in PEM format. It is ignored if + ``api_mtls_endpoint`` is None. + ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials + for the grpc channel. It is ignored if ``channel`` is provided. + client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): + A callback to provide client certificate bytes and private key bytes, + both in PEM format. It is used to configure a mutual TLS channel. It is + ignored if ``channel`` or ``ssl_channel_credentials`` is provided. + quota_project_id (Optional[str]): An optional project to use for billing + and quota. + 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. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. + + Raises: + google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport + creation failed for any reason. + google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` + and ``credentials_file`` are passed. + """ + self._grpc_channel = None + self._ssl_channel_credentials = ssl_channel_credentials + self._stubs: Dict[str, Callable] = {} + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None + + if api_mtls_endpoint: + warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) + if client_cert_source: + warnings.warn("client_cert_source is deprecated", DeprecationWarning) + + if channel: + # Ignore credentials if a channel was passed. + credentials = False + # If a channel was explicitly provided, set it. + self._grpc_channel = channel + self._ssl_channel_credentials = None + else: + if api_mtls_endpoint: + host = api_mtls_endpoint + + # Create SSL credentials with client_cert_source or application + # default SSL credentials. + if client_cert_source: + cert, key = client_cert_source() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + else: + self._ssl_channel_credentials = SslCredentials().ssl_credentials + + else: + if client_cert_source_for_mtls and not ssl_channel_credentials: + cert, key = client_cert_source_for_mtls() + self._ssl_channel_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + + # The base transport sets the host, credentials and scopes + super().__init__( + host=host, + credentials=credentials, + credentials_file=credentials_file, + scopes=scopes, + quota_project_id=quota_project_id, + client_info=client_info, + always_use_jwt_access=always_use_jwt_access, + ) + + if not self._grpc_channel: + self._grpc_channel = type(self).create_channel( + self._host, + # use the credentials which are saved + credentials=self._credentials, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, + scopes=self._scopes, + ssl_credentials=self._ssl_channel_credentials, + quota_project_id=quota_project_id, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Wrap messages. This must be done after self._grpc_channel exists + self._prep_wrapped_messages(client_info) + + @property + def grpc_channel(self) -> aio.Channel: + """Create the channel designed to connect to this service. + + This property caches on the instance; repeated calls return + the same channel. + """ + # Return the channel from cache. + return self._grpc_channel + + @property + def operations_client(self) -> operations_v1.OperationsAsyncClient: + """Create the client designed to process long-running operations. + + This property caches on the instance; repeated calls return the same + client. + """ + # Quick check: Only create a new client if we do not already have one. + if self._operations_client is None: + self._operations_client = operations_v1.OperationsAsyncClient( + self.grpc_channel + ) + + # Return the client from cache. + return self._operations_client + + @property + def create_study( + self, + ) -> Callable[[vizier_service.CreateStudyRequest], Awaitable[gca_study.Study]]: + r"""Return a callable for the create study method over gRPC. + + Creates a Study. A resource name will be generated + after creation of the Study. + + Returns: + Callable[[~.CreateStudyRequest], + Awaitable[~.Study]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_study" not in self._stubs: + self._stubs["create_study"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.VizierService/CreateStudy", + request_serializer=vizier_service.CreateStudyRequest.serialize, + response_deserializer=gca_study.Study.deserialize, + ) + return self._stubs["create_study"] + + @property + def get_study( + self, + ) -> Callable[[vizier_service.GetStudyRequest], Awaitable[study.Study]]: + r"""Return a callable for the get study method over gRPC. + + Gets a Study by name. + + Returns: + Callable[[~.GetStudyRequest], + Awaitable[~.Study]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_study" not in self._stubs: + self._stubs["get_study"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.VizierService/GetStudy", + request_serializer=vizier_service.GetStudyRequest.serialize, + response_deserializer=study.Study.deserialize, + ) + return self._stubs["get_study"] + + @property + def list_studies( + self, + ) -> Callable[ + [vizier_service.ListStudiesRequest], + Awaitable[vizier_service.ListStudiesResponse], + ]: + r"""Return a callable for the list studies method over gRPC. + + Lists all the studies in a region for an associated + project. + + Returns: + Callable[[~.ListStudiesRequest], + Awaitable[~.ListStudiesResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_studies" not in self._stubs: + self._stubs["list_studies"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.VizierService/ListStudies", + request_serializer=vizier_service.ListStudiesRequest.serialize, + response_deserializer=vizier_service.ListStudiesResponse.deserialize, + ) + return self._stubs["list_studies"] + + @property + def delete_study( + self, + ) -> Callable[[vizier_service.DeleteStudyRequest], Awaitable[empty_pb2.Empty]]: + r"""Return a callable for the delete study method over gRPC. + + Deletes a Study. + + Returns: + Callable[[~.DeleteStudyRequest], + Awaitable[~.Empty]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_study" not in self._stubs: + self._stubs["delete_study"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.VizierService/DeleteStudy", + request_serializer=vizier_service.DeleteStudyRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs["delete_study"] + + @property + def lookup_study( + self, + ) -> Callable[[vizier_service.LookupStudyRequest], Awaitable[study.Study]]: + r"""Return a callable for the lookup study method over gRPC. + + Looks a study up using the user-defined display_name field + instead of the fully qualified resource name. + + Returns: + Callable[[~.LookupStudyRequest], + Awaitable[~.Study]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "lookup_study" not in self._stubs: + self._stubs["lookup_study"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.VizierService/LookupStudy", + request_serializer=vizier_service.LookupStudyRequest.serialize, + response_deserializer=study.Study.deserialize, + ) + return self._stubs["lookup_study"] + + @property + def suggest_trials( + self, + ) -> Callable[ + [vizier_service.SuggestTrialsRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the suggest trials method over gRPC. + + Adds one or more Trials to a Study, with parameter values + suggested by Vertex AI Vizier. Returns a long-running operation + associated with the generation of Trial suggestions. When this + long-running operation succeeds, it will contain a + [SuggestTrialsResponse][google.cloud.ml.v1.SuggestTrialsResponse]. + + Returns: + Callable[[~.SuggestTrialsRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "suggest_trials" not in self._stubs: + self._stubs["suggest_trials"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.VizierService/SuggestTrials", + request_serializer=vizier_service.SuggestTrialsRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["suggest_trials"] + + @property + def create_trial( + self, + ) -> Callable[[vizier_service.CreateTrialRequest], Awaitable[study.Trial]]: + r"""Return a callable for the create trial method over gRPC. + + Adds a user provided Trial to a Study. + + Returns: + Callable[[~.CreateTrialRequest], + Awaitable[~.Trial]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "create_trial" not in self._stubs: + self._stubs["create_trial"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.VizierService/CreateTrial", + request_serializer=vizier_service.CreateTrialRequest.serialize, + response_deserializer=study.Trial.deserialize, + ) + return self._stubs["create_trial"] + + @property + def get_trial( + self, + ) -> Callable[[vizier_service.GetTrialRequest], Awaitable[study.Trial]]: + r"""Return a callable for the get trial method over gRPC. + + Gets a Trial. + + Returns: + Callable[[~.GetTrialRequest], + Awaitable[~.Trial]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_trial" not in self._stubs: + self._stubs["get_trial"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.VizierService/GetTrial", + request_serializer=vizier_service.GetTrialRequest.serialize, + response_deserializer=study.Trial.deserialize, + ) + return self._stubs["get_trial"] + + @property + def list_trials( + self, + ) -> Callable[ + [vizier_service.ListTrialsRequest], Awaitable[vizier_service.ListTrialsResponse] + ]: + r"""Return a callable for the list trials method over gRPC. + + Lists the Trials associated with a Study. + + Returns: + Callable[[~.ListTrialsRequest], + Awaitable[~.ListTrialsResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_trials" not in self._stubs: + self._stubs["list_trials"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.VizierService/ListTrials", + request_serializer=vizier_service.ListTrialsRequest.serialize, + response_deserializer=vizier_service.ListTrialsResponse.deserialize, + ) + return self._stubs["list_trials"] + + @property + def add_trial_measurement( + self, + ) -> Callable[[vizier_service.AddTrialMeasurementRequest], Awaitable[study.Trial]]: + r"""Return a callable for the add trial measurement method over gRPC. + + Adds a measurement of the objective metrics to a + Trial. This measurement is assumed to have been taken + before the Trial is complete. + + Returns: + Callable[[~.AddTrialMeasurementRequest], + Awaitable[~.Trial]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "add_trial_measurement" not in self._stubs: + self._stubs["add_trial_measurement"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.VizierService/AddTrialMeasurement", + request_serializer=vizier_service.AddTrialMeasurementRequest.serialize, + response_deserializer=study.Trial.deserialize, + ) + return self._stubs["add_trial_measurement"] + + @property + def complete_trial( + self, + ) -> Callable[[vizier_service.CompleteTrialRequest], Awaitable[study.Trial]]: + r"""Return a callable for the complete trial method over gRPC. + + Marks a Trial as complete. + + Returns: + Callable[[~.CompleteTrialRequest], + Awaitable[~.Trial]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "complete_trial" not in self._stubs: + self._stubs["complete_trial"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.VizierService/CompleteTrial", + request_serializer=vizier_service.CompleteTrialRequest.serialize, + response_deserializer=study.Trial.deserialize, + ) + return self._stubs["complete_trial"] + + @property + def delete_trial( + self, + ) -> Callable[[vizier_service.DeleteTrialRequest], Awaitable[empty_pb2.Empty]]: + r"""Return a callable for the delete trial method over gRPC. + + Deletes a Trial. + + Returns: + Callable[[~.DeleteTrialRequest], + Awaitable[~.Empty]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_trial" not in self._stubs: + self._stubs["delete_trial"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.VizierService/DeleteTrial", + request_serializer=vizier_service.DeleteTrialRequest.serialize, + response_deserializer=empty_pb2.Empty.FromString, + ) + return self._stubs["delete_trial"] + + @property + def check_trial_early_stopping_state( + self, + ) -> Callable[ + [vizier_service.CheckTrialEarlyStoppingStateRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the check trial early stopping + state method over gRPC. + + Checks whether a Trial should stop or not. Returns a + long-running operation. When the operation is successful, it + will contain a + [CheckTrialEarlyStoppingStateResponse][google.cloud.ml.v1.CheckTrialEarlyStoppingStateResponse]. + + Returns: + Callable[[~.CheckTrialEarlyStoppingStateRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "check_trial_early_stopping_state" not in self._stubs: + self._stubs[ + "check_trial_early_stopping_state" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.VizierService/CheckTrialEarlyStoppingState", + request_serializer=vizier_service.CheckTrialEarlyStoppingStateRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["check_trial_early_stopping_state"] + + @property + def stop_trial( + self, + ) -> Callable[[vizier_service.StopTrialRequest], Awaitable[study.Trial]]: + r"""Return a callable for the stop trial method over gRPC. + + Stops a Trial. + + Returns: + Callable[[~.StopTrialRequest], + Awaitable[~.Trial]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "stop_trial" not in self._stubs: + self._stubs["stop_trial"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.VizierService/StopTrial", + request_serializer=vizier_service.StopTrialRequest.serialize, + response_deserializer=study.Trial.deserialize, + ) + return self._stubs["stop_trial"] + + @property + def list_optimal_trials( + self, + ) -> Callable[ + [vizier_service.ListOptimalTrialsRequest], + Awaitable[vizier_service.ListOptimalTrialsResponse], + ]: + r"""Return a callable for the list optimal trials method over gRPC. + + Lists the pareto-optimal Trials for multi-objective Study or the + optimal Trials for single-objective Study. The definition of + pareto-optimal can be checked in wiki page. + https://en.wikipedia.org/wiki/Pareto_efficiency + + Returns: + Callable[[~.ListOptimalTrialsRequest], + Awaitable[~.ListOptimalTrialsResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_optimal_trials" not in self._stubs: + self._stubs["list_optimal_trials"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1.VizierService/ListOptimalTrials", + request_serializer=vizier_service.ListOptimalTrialsRequest.serialize, + response_deserializer=vizier_service.ListOptimalTrialsResponse.deserialize, + ) + return self._stubs["list_optimal_trials"] + + def close(self): + return self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + +__all__ = ("VizierServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/aiplatform_v1/types/__init__.py b/google/cloud/aiplatform_v1/types/__init__.py index 42bab0a05e..9e5a2d0a54 100644 --- a/google/cloud/aiplatform_v1/types/__init__.py +++ b/google/cloud/aiplatform_v1/types/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,10 +13,24 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from .annotation import Annotation -from .annotation_spec import AnnotationSpec -from .batch_prediction_job import BatchPredictionJob -from .completion_stats import CompletionStats +from .annotation import ( + Annotation, +) +from .annotation_spec import ( + AnnotationSpec, +) +from .artifact import ( + Artifact, +) +from .batch_prediction_job import ( + BatchPredictionJob, +) +from .completion_stats import ( + CompletionStats, +) +from .context import ( + Context, +) from .custom_job import ( ContainerSpec, CustomJob, @@ -25,7 +39,9 @@ Scheduling, WorkerPoolSpec, ) -from .data_item import DataItem +from .data_item import ( + DataItem, +) from .data_labeling_job import ( ActiveLearningConfig, DataLabelingJob, @@ -57,11 +73,20 @@ ListDatasetsResponse, UpdateDatasetRequest, ) -from .deployed_model_ref import DeployedModelRef -from .encryption_spec import EncryptionSpec +from .deployed_index_ref import ( + DeployedIndexRef, +) +from .deployed_model_ref import ( + DeployedModelRef, +) +from .encryption_spec import ( + EncryptionSpec, +) from .endpoint import ( DeployedModel, Endpoint, + PredictRequestResponseLoggingConfig, + PrivateEndpoints, ) from .endpoint_service import ( CreateEndpointOperationMetadata, @@ -78,14 +103,153 @@ UndeployModelResponse, UpdateEndpointRequest, ) -from .env_var import EnvVar -from .hyperparameter_tuning_job import HyperparameterTuningJob +from .entity_type import ( + EntityType, +) +from .env_var import ( + EnvVar, +) +from .event import ( + Event, +) +from .execution import ( + Execution, +) +from .explanation import ( + Attribution, + BlurBaselineConfig, + ExamplesOverride, + ExamplesRestrictionsNamespace, + Explanation, + ExplanationMetadataOverride, + ExplanationParameters, + ExplanationSpec, + ExplanationSpecOverride, + FeatureNoiseSigma, + IntegratedGradientsAttribution, + ModelExplanation, + Neighbor, + SampledShapleyAttribution, + SmoothGradConfig, + XraiAttribution, +) +from .explanation_metadata import ( + ExplanationMetadata, +) +from .feature import ( + Feature, +) +from .feature_monitoring_stats import ( + FeatureStatsAnomaly, +) +from .feature_selector import ( + FeatureSelector, + IdMatcher, +) +from .featurestore import ( + Featurestore, +) +from .featurestore_monitoring import ( + FeaturestoreMonitoringConfig, +) +from .featurestore_online_service import ( + FeatureValue, + FeatureValueList, + ReadFeatureValuesRequest, + ReadFeatureValuesResponse, + StreamingReadFeatureValuesRequest, +) +from .featurestore_service import ( + BatchCreateFeaturesOperationMetadata, + BatchCreateFeaturesRequest, + BatchCreateFeaturesResponse, + BatchReadFeatureValuesOperationMetadata, + BatchReadFeatureValuesRequest, + BatchReadFeatureValuesResponse, + CreateEntityTypeOperationMetadata, + CreateEntityTypeRequest, + CreateFeatureOperationMetadata, + CreateFeatureRequest, + CreateFeaturestoreOperationMetadata, + CreateFeaturestoreRequest, + DeleteEntityTypeRequest, + DeleteFeatureRequest, + DeleteFeaturestoreRequest, + DestinationFeatureSetting, + ExportFeatureValuesOperationMetadata, + ExportFeatureValuesRequest, + ExportFeatureValuesResponse, + FeatureValueDestination, + GetEntityTypeRequest, + GetFeatureRequest, + GetFeaturestoreRequest, + ImportFeatureValuesOperationMetadata, + ImportFeatureValuesRequest, + ImportFeatureValuesResponse, + ListEntityTypesRequest, + ListEntityTypesResponse, + ListFeaturesRequest, + ListFeaturesResponse, + ListFeaturestoresRequest, + ListFeaturestoresResponse, + SearchFeaturesRequest, + SearchFeaturesResponse, + UpdateEntityTypeRequest, + UpdateFeatureRequest, + UpdateFeaturestoreOperationMetadata, + UpdateFeaturestoreRequest, +) +from .hyperparameter_tuning_job import ( + HyperparameterTuningJob, +) +from .index import ( + Index, +) +from .index_endpoint import ( + DeployedIndex, + DeployedIndexAuthConfig, + IndexEndpoint, + IndexPrivateEndpoints, +) +from .index_endpoint_service import ( + CreateIndexEndpointOperationMetadata, + CreateIndexEndpointRequest, + DeleteIndexEndpointRequest, + DeployIndexOperationMetadata, + DeployIndexRequest, + DeployIndexResponse, + GetIndexEndpointRequest, + ListIndexEndpointsRequest, + ListIndexEndpointsResponse, + MutateDeployedIndexOperationMetadata, + MutateDeployedIndexRequest, + MutateDeployedIndexResponse, + UndeployIndexOperationMetadata, + UndeployIndexRequest, + UndeployIndexResponse, + UpdateIndexEndpointRequest, +) +from .index_service import ( + CreateIndexOperationMetadata, + CreateIndexRequest, + DeleteIndexRequest, + GetIndexRequest, + ListIndexesRequest, + ListIndexesResponse, + NearestNeighborSearchOperationMetadata, + UpdateIndexOperationMetadata, + UpdateIndexRequest, +) from .io import ( + AvroSource, BigQueryDestination, BigQuerySource, ContainerRegistryDestination, + CsvDestination, + CsvSource, GcsDestination, GcsSource, + TFRecordDestination, ) from .job_service import ( CancelBatchPredictionJobRequest, @@ -96,14 +260,17 @@ CreateCustomJobRequest, CreateDataLabelingJobRequest, CreateHyperparameterTuningJobRequest, + CreateModelDeploymentMonitoringJobRequest, DeleteBatchPredictionJobRequest, DeleteCustomJobRequest, DeleteDataLabelingJobRequest, DeleteHyperparameterTuningJobRequest, + DeleteModelDeploymentMonitoringJobRequest, GetBatchPredictionJobRequest, GetCustomJobRequest, GetDataLabelingJobRequest, GetHyperparameterTuningJobRequest, + GetModelDeploymentMonitoringJobRequest, ListBatchPredictionJobsRequest, ListBatchPredictionJobsResponse, ListCustomJobsRequest, @@ -112,17 +279,89 @@ ListDataLabelingJobsResponse, ListHyperparameterTuningJobsRequest, ListHyperparameterTuningJobsResponse, + ListModelDeploymentMonitoringJobsRequest, + ListModelDeploymentMonitoringJobsResponse, + PauseModelDeploymentMonitoringJobRequest, + ResumeModelDeploymentMonitoringJobRequest, + SearchModelDeploymentMonitoringStatsAnomaliesRequest, + SearchModelDeploymentMonitoringStatsAnomaliesResponse, + UpdateModelDeploymentMonitoringJobOperationMetadata, + UpdateModelDeploymentMonitoringJobRequest, +) +from .lineage_subgraph import ( + LineageSubgraph, ) from .machine_resources import ( AutomaticResources, + AutoscalingMetricSpec, BatchDedicatedResources, DedicatedResources, DiskSpec, MachineSpec, + NfsMount, ResourcesConsumed, ) -from .manual_batch_tuning_parameters import ManualBatchTuningParameters -from .migratable_resource import MigratableResource +from .manual_batch_tuning_parameters import ( + ManualBatchTuningParameters, +) +from .metadata_schema import ( + MetadataSchema, +) +from .metadata_service import ( + AddContextArtifactsAndExecutionsRequest, + AddContextArtifactsAndExecutionsResponse, + AddContextChildrenRequest, + AddContextChildrenResponse, + AddExecutionEventsRequest, + AddExecutionEventsResponse, + CreateArtifactRequest, + CreateContextRequest, + CreateExecutionRequest, + CreateMetadataSchemaRequest, + CreateMetadataStoreOperationMetadata, + CreateMetadataStoreRequest, + DeleteArtifactRequest, + DeleteContextRequest, + DeleteExecutionRequest, + DeleteMetadataStoreOperationMetadata, + DeleteMetadataStoreRequest, + GetArtifactRequest, + GetContextRequest, + GetExecutionRequest, + GetMetadataSchemaRequest, + GetMetadataStoreRequest, + ListArtifactsRequest, + ListArtifactsResponse, + ListContextsRequest, + ListContextsResponse, + ListExecutionsRequest, + ListExecutionsResponse, + ListMetadataSchemasRequest, + ListMetadataSchemasResponse, + ListMetadataStoresRequest, + ListMetadataStoresResponse, + PurgeArtifactsMetadata, + PurgeArtifactsRequest, + PurgeArtifactsResponse, + PurgeContextsMetadata, + PurgeContextsRequest, + PurgeContextsResponse, + PurgeExecutionsMetadata, + PurgeExecutionsRequest, + PurgeExecutionsResponse, + QueryArtifactLineageSubgraphRequest, + QueryContextLineageSubgraphRequest, + QueryExecutionInputsAndOutputsRequest, + UpdateArtifactRequest, + UpdateContextRequest, + UpdateExecutionRequest, +) +from .metadata_store import ( + MetadataStore, +) +from .migratable_resource import ( + MigratableResource, +) from .migration_service import ( BatchMigrateResourcesOperationMetadata, BatchMigrateResourcesRequest, @@ -138,22 +377,45 @@ Port, PredictSchemata, ) -from .model_evaluation import ModelEvaluation -from .model_evaluation_slice import ModelEvaluationSlice +from .model_deployment_monitoring_job import ( + ModelDeploymentMonitoringBigQueryTable, + ModelDeploymentMonitoringJob, + ModelDeploymentMonitoringObjectiveConfig, + ModelDeploymentMonitoringScheduleConfig, + ModelMonitoringStatsAnomalies, + ModelDeploymentMonitoringObjectiveType, +) +from .model_evaluation import ( + ModelEvaluation, +) +from .model_evaluation_slice import ( + ModelEvaluationSlice, +) +from .model_monitoring import ( + ModelMonitoringAlertConfig, + ModelMonitoringObjectiveConfig, + SamplingStrategy, + ThresholdConfig, +) from .model_service import ( DeleteModelRequest, + DeleteModelVersionRequest, ExportModelOperationMetadata, ExportModelRequest, ExportModelResponse, GetModelEvaluationRequest, GetModelEvaluationSliceRequest, GetModelRequest, + ImportModelEvaluationRequest, ListModelEvaluationSlicesRequest, ListModelEvaluationSlicesResponse, ListModelEvaluationsRequest, ListModelEvaluationsResponse, ListModelsRequest, ListModelsResponse, + ListModelVersionsRequest, + ListModelVersionsResponse, + MergeVersionAliasesRequest, UpdateModelRequest, UploadModelOperationMetadata, UploadModelRequest, @@ -163,19 +425,37 @@ DeleteOperationMetadata, GenericOperationMetadata, ) +from .pipeline_job import ( + PipelineJob, + PipelineJobDetail, + PipelineTaskDetail, + PipelineTaskExecutorDetail, + PipelineTemplateMetadata, +) from .pipeline_service import ( + CancelPipelineJobRequest, CancelTrainingPipelineRequest, + CreatePipelineJobRequest, CreateTrainingPipelineRequest, + DeletePipelineJobRequest, DeleteTrainingPipelineRequest, + GetPipelineJobRequest, GetTrainingPipelineRequest, + ListPipelineJobsRequest, + ListPipelineJobsResponse, ListTrainingPipelinesRequest, ListTrainingPipelinesResponse, ) from .prediction_service import ( + ExplainRequest, + ExplainResponse, PredictRequest, PredictResponse, + RawPredictRequest, +) +from .specialist_pool import ( + SpecialistPool, ) -from .specialist_pool import SpecialistPool from .specialist_pool_service import ( CreateSpecialistPoolOperationMetadata, CreateSpecialistPoolRequest, @@ -188,25 +468,131 @@ ) from .study import ( Measurement, + Study, StudySpec, Trial, ) +from .tensorboard import ( + Tensorboard, +) +from .tensorboard_data import ( + Scalar, + TensorboardBlob, + TensorboardBlobSequence, + TensorboardTensor, + TimeSeriesData, + TimeSeriesDataPoint, +) +from .tensorboard_experiment import ( + TensorboardExperiment, +) +from .tensorboard_run import ( + TensorboardRun, +) +from .tensorboard_service import ( + BatchCreateTensorboardRunsRequest, + BatchCreateTensorboardRunsResponse, + BatchCreateTensorboardTimeSeriesRequest, + BatchCreateTensorboardTimeSeriesResponse, + BatchReadTensorboardTimeSeriesDataRequest, + BatchReadTensorboardTimeSeriesDataResponse, + CreateTensorboardExperimentRequest, + CreateTensorboardOperationMetadata, + CreateTensorboardRequest, + CreateTensorboardRunRequest, + CreateTensorboardTimeSeriesRequest, + DeleteTensorboardExperimentRequest, + DeleteTensorboardRequest, + DeleteTensorboardRunRequest, + DeleteTensorboardTimeSeriesRequest, + ExportTensorboardTimeSeriesDataRequest, + ExportTensorboardTimeSeriesDataResponse, + GetTensorboardExperimentRequest, + GetTensorboardRequest, + GetTensorboardRunRequest, + GetTensorboardTimeSeriesRequest, + ListTensorboardExperimentsRequest, + ListTensorboardExperimentsResponse, + ListTensorboardRunsRequest, + ListTensorboardRunsResponse, + ListTensorboardsRequest, + ListTensorboardsResponse, + ListTensorboardTimeSeriesRequest, + ListTensorboardTimeSeriesResponse, + ReadTensorboardBlobDataRequest, + ReadTensorboardBlobDataResponse, + ReadTensorboardTimeSeriesDataRequest, + ReadTensorboardTimeSeriesDataResponse, + UpdateTensorboardExperimentRequest, + UpdateTensorboardOperationMetadata, + UpdateTensorboardRequest, + UpdateTensorboardRunRequest, + UpdateTensorboardTimeSeriesRequest, + WriteTensorboardExperimentDataRequest, + WriteTensorboardExperimentDataResponse, + WriteTensorboardRunDataRequest, + WriteTensorboardRunDataResponse, +) +from .tensorboard_time_series import ( + TensorboardTimeSeries, +) from .training_pipeline import ( FilterSplit, FractionSplit, InputDataConfig, PredefinedSplit, + StratifiedSplit, TimestampSplit, TrainingPipeline, ) -from .user_action_reference import UserActionReference +from .types import ( + BoolArray, + DoubleArray, + Int64Array, + StringArray, +) +from .unmanaged_container_model import ( + UnmanagedContainerModel, +) +from .user_action_reference import ( + UserActionReference, +) +from .value import ( + Value, +) +from .vizier_service import ( + AddTrialMeasurementRequest, + CheckTrialEarlyStoppingStateMetatdata, + CheckTrialEarlyStoppingStateRequest, + CheckTrialEarlyStoppingStateResponse, + CompleteTrialRequest, + CreateStudyRequest, + CreateTrialRequest, + DeleteStudyRequest, + DeleteTrialRequest, + GetStudyRequest, + GetTrialRequest, + ListOptimalTrialsRequest, + ListOptimalTrialsResponse, + ListStudiesRequest, + ListStudiesResponse, + ListTrialsRequest, + ListTrialsResponse, + LookupStudyRequest, + StopTrialRequest, + SuggestTrialsMetadata, + SuggestTrialsRequest, + SuggestTrialsResponse, +) __all__ = ( "AcceleratorType", "Annotation", "AnnotationSpec", + "Artifact", "BatchPredictionJob", "CompletionStats", + "Context", "ContainerSpec", "CustomJob", "CustomJobSpec", @@ -239,10 +625,13 @@ "ListDatasetsRequest", "ListDatasetsResponse", "UpdateDatasetRequest", + "DeployedIndexRef", "DeployedModelRef", "EncryptionSpec", "DeployedModel", "Endpoint", + "PredictRequestResponseLoggingConfig", + "PrivateEndpoints", "CreateEndpointOperationMetadata", "CreateEndpointRequest", "DeleteEndpointRequest", @@ -256,13 +645,116 @@ "UndeployModelRequest", "UndeployModelResponse", "UpdateEndpointRequest", + "EntityType", "EnvVar", + "Event", + "Execution", + "Attribution", + "BlurBaselineConfig", + "ExamplesOverride", + "ExamplesRestrictionsNamespace", + "Explanation", + "ExplanationMetadataOverride", + "ExplanationParameters", + "ExplanationSpec", + "ExplanationSpecOverride", + "FeatureNoiseSigma", + "IntegratedGradientsAttribution", + "ModelExplanation", + "Neighbor", + "SampledShapleyAttribution", + "SmoothGradConfig", + "XraiAttribution", + "ExplanationMetadata", + "Feature", + "FeatureStatsAnomaly", + "FeatureSelector", + "IdMatcher", + "Featurestore", + "FeaturestoreMonitoringConfig", + "FeatureValue", + "FeatureValueList", + "ReadFeatureValuesRequest", + "ReadFeatureValuesResponse", + "StreamingReadFeatureValuesRequest", + "BatchCreateFeaturesOperationMetadata", + "BatchCreateFeaturesRequest", + "BatchCreateFeaturesResponse", + "BatchReadFeatureValuesOperationMetadata", + "BatchReadFeatureValuesRequest", + "BatchReadFeatureValuesResponse", + "CreateEntityTypeOperationMetadata", + "CreateEntityTypeRequest", + "CreateFeatureOperationMetadata", + "CreateFeatureRequest", + "CreateFeaturestoreOperationMetadata", + "CreateFeaturestoreRequest", + "DeleteEntityTypeRequest", + "DeleteFeatureRequest", + "DeleteFeaturestoreRequest", + "DestinationFeatureSetting", + "ExportFeatureValuesOperationMetadata", + "ExportFeatureValuesRequest", + "ExportFeatureValuesResponse", + "FeatureValueDestination", + "GetEntityTypeRequest", + "GetFeatureRequest", + "GetFeaturestoreRequest", + "ImportFeatureValuesOperationMetadata", + "ImportFeatureValuesRequest", + "ImportFeatureValuesResponse", + "ListEntityTypesRequest", + "ListEntityTypesResponse", + "ListFeaturesRequest", + "ListFeaturesResponse", + "ListFeaturestoresRequest", + "ListFeaturestoresResponse", + "SearchFeaturesRequest", + "SearchFeaturesResponse", + "UpdateEntityTypeRequest", + "UpdateFeatureRequest", + "UpdateFeaturestoreOperationMetadata", + "UpdateFeaturestoreRequest", "HyperparameterTuningJob", + "Index", + "DeployedIndex", + "DeployedIndexAuthConfig", + "IndexEndpoint", + "IndexPrivateEndpoints", + "CreateIndexEndpointOperationMetadata", + "CreateIndexEndpointRequest", + "DeleteIndexEndpointRequest", + "DeployIndexOperationMetadata", + "DeployIndexRequest", + "DeployIndexResponse", + "GetIndexEndpointRequest", + "ListIndexEndpointsRequest", + "ListIndexEndpointsResponse", + "MutateDeployedIndexOperationMetadata", + "MutateDeployedIndexRequest", + "MutateDeployedIndexResponse", + "UndeployIndexOperationMetadata", + "UndeployIndexRequest", + "UndeployIndexResponse", + "UpdateIndexEndpointRequest", + "CreateIndexOperationMetadata", + "CreateIndexRequest", + "DeleteIndexRequest", + "GetIndexRequest", + "ListIndexesRequest", + "ListIndexesResponse", + "NearestNeighborSearchOperationMetadata", + "UpdateIndexOperationMetadata", + "UpdateIndexRequest", + "AvroSource", "BigQueryDestination", "BigQuerySource", "ContainerRegistryDestination", + "CsvDestination", + "CsvSource", "GcsDestination", "GcsSource", + "TFRecordDestination", "CancelBatchPredictionJobRequest", "CancelCustomJobRequest", "CancelDataLabelingJobRequest", @@ -271,14 +763,17 @@ "CreateCustomJobRequest", "CreateDataLabelingJobRequest", "CreateHyperparameterTuningJobRequest", + "CreateModelDeploymentMonitoringJobRequest", "DeleteBatchPredictionJobRequest", "DeleteCustomJobRequest", "DeleteDataLabelingJobRequest", "DeleteHyperparameterTuningJobRequest", + "DeleteModelDeploymentMonitoringJobRequest", "GetBatchPredictionJobRequest", "GetCustomJobRequest", "GetDataLabelingJobRequest", "GetHyperparameterTuningJobRequest", + "GetModelDeploymentMonitoringJobRequest", "ListBatchPredictionJobsRequest", "ListBatchPredictionJobsResponse", "ListCustomJobsRequest", @@ -287,14 +782,74 @@ "ListDataLabelingJobsResponse", "ListHyperparameterTuningJobsRequest", "ListHyperparameterTuningJobsResponse", + "ListModelDeploymentMonitoringJobsRequest", + "ListModelDeploymentMonitoringJobsResponse", + "PauseModelDeploymentMonitoringJobRequest", + "ResumeModelDeploymentMonitoringJobRequest", + "SearchModelDeploymentMonitoringStatsAnomaliesRequest", + "SearchModelDeploymentMonitoringStatsAnomaliesResponse", + "UpdateModelDeploymentMonitoringJobOperationMetadata", + "UpdateModelDeploymentMonitoringJobRequest", "JobState", + "LineageSubgraph", "AutomaticResources", + "AutoscalingMetricSpec", "BatchDedicatedResources", "DedicatedResources", "DiskSpec", "MachineSpec", + "NfsMount", "ResourcesConsumed", "ManualBatchTuningParameters", + "MetadataSchema", + "AddContextArtifactsAndExecutionsRequest", + "AddContextArtifactsAndExecutionsResponse", + "AddContextChildrenRequest", + "AddContextChildrenResponse", + "AddExecutionEventsRequest", + "AddExecutionEventsResponse", + "CreateArtifactRequest", + "CreateContextRequest", + "CreateExecutionRequest", + "CreateMetadataSchemaRequest", + "CreateMetadataStoreOperationMetadata", + "CreateMetadataStoreRequest", + "DeleteArtifactRequest", + "DeleteContextRequest", + "DeleteExecutionRequest", + "DeleteMetadataStoreOperationMetadata", + "DeleteMetadataStoreRequest", + "GetArtifactRequest", + "GetContextRequest", + "GetExecutionRequest", + "GetMetadataSchemaRequest", + "GetMetadataStoreRequest", + "ListArtifactsRequest", + "ListArtifactsResponse", + "ListContextsRequest", + "ListContextsResponse", + "ListExecutionsRequest", + "ListExecutionsResponse", + "ListMetadataSchemasRequest", + "ListMetadataSchemasResponse", + "ListMetadataStoresRequest", + "ListMetadataStoresResponse", + "PurgeArtifactsMetadata", + "PurgeArtifactsRequest", + "PurgeArtifactsResponse", + "PurgeContextsMetadata", + "PurgeContextsRequest", + "PurgeContextsResponse", + "PurgeExecutionsMetadata", + "PurgeExecutionsRequest", + "PurgeExecutionsResponse", + "QueryArtifactLineageSubgraphRequest", + "QueryContextLineageSubgraphRequest", + "QueryExecutionInputsAndOutputsRequest", + "UpdateArtifactRequest", + "UpdateContextRequest", + "UpdateExecutionRequest", + "MetadataStore", "MigratableResource", "BatchMigrateResourcesOperationMetadata", "BatchMigrateResourcesRequest", @@ -307,36 +862,66 @@ "ModelContainerSpec", "Port", "PredictSchemata", + "ModelDeploymentMonitoringBigQueryTable", + "ModelDeploymentMonitoringJob", + "ModelDeploymentMonitoringObjectiveConfig", + "ModelDeploymentMonitoringScheduleConfig", + "ModelMonitoringStatsAnomalies", + "ModelDeploymentMonitoringObjectiveType", "ModelEvaluation", "ModelEvaluationSlice", + "ModelMonitoringAlertConfig", + "ModelMonitoringObjectiveConfig", + "SamplingStrategy", + "ThresholdConfig", "DeleteModelRequest", + "DeleteModelVersionRequest", "ExportModelOperationMetadata", "ExportModelRequest", "ExportModelResponse", "GetModelEvaluationRequest", "GetModelEvaluationSliceRequest", "GetModelRequest", + "ImportModelEvaluationRequest", "ListModelEvaluationSlicesRequest", "ListModelEvaluationSlicesResponse", "ListModelEvaluationsRequest", "ListModelEvaluationsResponse", "ListModelsRequest", "ListModelsResponse", + "ListModelVersionsRequest", + "ListModelVersionsResponse", + "MergeVersionAliasesRequest", "UpdateModelRequest", "UploadModelOperationMetadata", "UploadModelRequest", "UploadModelResponse", "DeleteOperationMetadata", "GenericOperationMetadata", + "PipelineFailurePolicy", + "PipelineJob", + "PipelineJobDetail", + "PipelineTaskDetail", + "PipelineTaskExecutorDetail", + "PipelineTemplateMetadata", + "CancelPipelineJobRequest", "CancelTrainingPipelineRequest", + "CreatePipelineJobRequest", "CreateTrainingPipelineRequest", + "DeletePipelineJobRequest", "DeleteTrainingPipelineRequest", + "GetPipelineJobRequest", "GetTrainingPipelineRequest", + "ListPipelineJobsRequest", + "ListPipelineJobsResponse", "ListTrainingPipelinesRequest", "ListTrainingPipelinesResponse", "PipelineState", + "ExplainRequest", + "ExplainResponse", "PredictRequest", "PredictResponse", + "RawPredictRequest", "SpecialistPool", "CreateSpecialistPoolOperationMetadata", "CreateSpecialistPoolRequest", @@ -347,13 +932,95 @@ "UpdateSpecialistPoolOperationMetadata", "UpdateSpecialistPoolRequest", "Measurement", + "Study", "StudySpec", "Trial", + "Tensorboard", + "Scalar", + "TensorboardBlob", + "TensorboardBlobSequence", + "TensorboardTensor", + "TimeSeriesData", + "TimeSeriesDataPoint", + "TensorboardExperiment", + "TensorboardRun", + "BatchCreateTensorboardRunsRequest", + "BatchCreateTensorboardRunsResponse", + "BatchCreateTensorboardTimeSeriesRequest", + "BatchCreateTensorboardTimeSeriesResponse", + "BatchReadTensorboardTimeSeriesDataRequest", + "BatchReadTensorboardTimeSeriesDataResponse", + "CreateTensorboardExperimentRequest", + "CreateTensorboardOperationMetadata", + "CreateTensorboardRequest", + "CreateTensorboardRunRequest", + "CreateTensorboardTimeSeriesRequest", + "DeleteTensorboardExperimentRequest", + "DeleteTensorboardRequest", + "DeleteTensorboardRunRequest", + "DeleteTensorboardTimeSeriesRequest", + "ExportTensorboardTimeSeriesDataRequest", + "ExportTensorboardTimeSeriesDataResponse", + "GetTensorboardExperimentRequest", + "GetTensorboardRequest", + "GetTensorboardRunRequest", + "GetTensorboardTimeSeriesRequest", + "ListTensorboardExperimentsRequest", + "ListTensorboardExperimentsResponse", + "ListTensorboardRunsRequest", + "ListTensorboardRunsResponse", + "ListTensorboardsRequest", + "ListTensorboardsResponse", + "ListTensorboardTimeSeriesRequest", + "ListTensorboardTimeSeriesResponse", + "ReadTensorboardBlobDataRequest", + "ReadTensorboardBlobDataResponse", + "ReadTensorboardTimeSeriesDataRequest", + "ReadTensorboardTimeSeriesDataResponse", + "UpdateTensorboardExperimentRequest", + "UpdateTensorboardOperationMetadata", + "UpdateTensorboardRequest", + "UpdateTensorboardRunRequest", + "UpdateTensorboardTimeSeriesRequest", + "WriteTensorboardExperimentDataRequest", + "WriteTensorboardExperimentDataResponse", + "WriteTensorboardRunDataRequest", + "WriteTensorboardRunDataResponse", + "TensorboardTimeSeries", "FilterSplit", "FractionSplit", "InputDataConfig", "PredefinedSplit", + "StratifiedSplit", "TimestampSplit", "TrainingPipeline", + "BoolArray", + "DoubleArray", + "Int64Array", + "StringArray", + "UnmanagedContainerModel", "UserActionReference", + "Value", + "AddTrialMeasurementRequest", + "CheckTrialEarlyStoppingStateMetatdata", + "CheckTrialEarlyStoppingStateRequest", + "CheckTrialEarlyStoppingStateResponse", + "CompleteTrialRequest", + "CreateStudyRequest", + "CreateTrialRequest", + "DeleteStudyRequest", + "DeleteTrialRequest", + "GetStudyRequest", + "GetTrialRequest", + "ListOptimalTrialsRequest", + "ListOptimalTrialsResponse", + "ListStudiesRequest", + "ListStudiesResponse", + "ListTrialsRequest", + "ListTrialsResponse", + "LookupStudyRequest", + "StopTrialRequest", + "SuggestTrialsMetadata", + "SuggestTrialsRequest", + "SuggestTrialsResponse", ) diff --git a/google/cloud/aiplatform_v1/types/accelerator_type.py b/google/cloud/aiplatform_v1/types/accelerator_type.py index 6728739a23..a43cf4e6cf 100644 --- a/google/cloud/aiplatform_v1/types/accelerator_type.py +++ b/google/cloud/aiplatform_v1/types/accelerator_type.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,7 +17,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1", manifest={"AcceleratorType",}, + package="google.cloud.aiplatform.v1", + manifest={ + "AcceleratorType", + }, ) @@ -29,6 +32,7 @@ class AcceleratorType(proto.Enum): NVIDIA_TESLA_V100 = 3 NVIDIA_TESLA_P4 = 4 NVIDIA_TESLA_T4 = 5 + NVIDIA_TESLA_A100 = 8 TPU_V2 = 6 TPU_V3 = 7 diff --git a/google/cloud/aiplatform_v1/types/annotation.py b/google/cloud/aiplatform_v1/types/annotation.py index 0671829241..db2eb8c3cf 100644 --- a/google/cloud/aiplatform_v1/types/annotation.py +++ b/google/cloud/aiplatform_v1/types/annotation.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,7 +21,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1", manifest={"Annotation",}, + package="google.cloud.aiplatform.v1", + manifest={ + "Annotation", + }, ) @@ -37,8 +40,8 @@ class Annotation(proto.Message): describing [payload][google.cloud.aiplatform.v1.Annotation.payload]. The schema is defined as an `OpenAPI 3.0.2 Schema - Object `__. The schema files - that can be used here are found in + Object `__. + The schema files that can be used here are found in gs://google-cloud-aiplatform/schema/dataset/annotation/, note that the chosen schema must be consistent with the parent Dataset's @@ -53,12 +56,12 @@ class Annotation(proto.Message): Output only. Timestamp when this Annotation was last updated. etag (str): - Optional. Used to perform consistent read- - odify-write updates. If not set, a blind + Optional. Used to perform consistent + read-modify-write updates. If not set, a blind "overwrite" update happens. annotation_source (google.cloud.aiplatform_v1.types.UserActionReference): Output only. The source of the Annotation. - labels (Sequence[google.cloud.aiplatform_v1.types.Annotation.LabelsEntry]): + labels (Mapping[str, str]): Optional. The labels with user-defined metadata to organize your Annotations. @@ -84,16 +87,43 @@ class Annotation(proto.Message): title. """ - name = proto.Field(proto.STRING, number=1,) - payload_schema_uri = proto.Field(proto.STRING, number=2,) - payload = proto.Field(proto.MESSAGE, number=3, message=struct_pb2.Value,) - create_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) - update_time = proto.Field(proto.MESSAGE, number=7, message=timestamp_pb2.Timestamp,) - etag = proto.Field(proto.STRING, number=8,) + name = proto.Field( + proto.STRING, + number=1, + ) + payload_schema_uri = proto.Field( + proto.STRING, + number=2, + ) + payload = proto.Field( + proto.MESSAGE, + number=3, + message=struct_pb2.Value, + ) + create_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=7, + message=timestamp_pb2.Timestamp, + ) + etag = proto.Field( + proto.STRING, + number=8, + ) annotation_source = proto.Field( - proto.MESSAGE, number=5, message=user_action_reference.UserActionReference, + proto.MESSAGE, + number=5, + message=user_action_reference.UserActionReference, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=6, ) - labels = proto.MapField(proto.STRING, proto.STRING, number=6,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/annotation_spec.py b/google/cloud/aiplatform_v1/types/annotation_spec.py index 626db3df7e..08d5644eaf 100644 --- a/google/cloud/aiplatform_v1/types/annotation_spec.py +++ b/google/cloud/aiplatform_v1/types/annotation_spec.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,7 +19,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1", manifest={"AnnotationSpec",}, + package="google.cloud.aiplatform.v1", + manifest={ + "AnnotationSpec", + }, ) @@ -43,16 +46,33 @@ class AnnotationSpec(proto.Message): Output only. Timestamp when AnnotationSpec was last updated. etag (str): - Optional. Used to perform consistent read- - odify-write updates. If not set, a blind + Optional. Used to perform consistent + read-modify-write updates. If not set, a blind "overwrite" update happens. """ - name = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) - create_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) - update_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) - etag = proto.Field(proto.STRING, number=5,) + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + create_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + etag = proto.Field( + proto.STRING, + number=5, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/artifact.py b/google/cloud/aiplatform_v1/types/artifact.py new file mode 100644 index 0000000000..853ae4b0cb --- /dev/null +++ b/google/cloud/aiplatform_v1/types/artifact.py @@ -0,0 +1,154 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + +from google.protobuf import struct_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "Artifact", + }, +) + + +class Artifact(proto.Message): + r"""Instance of a general artifact. + + Attributes: + name (str): + Output only. The resource name of the + Artifact. + display_name (str): + User provided display name of the Artifact. + May be up to 128 Unicode characters. + uri (str): + The uniform resource identifier of the + artifact file. May be empty if there is no + actual artifact file. + etag (str): + An eTag used to perform consistent + read-modify-write updates. If not set, a blind + "overwrite" update happens. + labels (Mapping[str, str]): + The labels with user-defined metadata to + organize your Artifacts. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. No more than 64 user labels can be + associated with one Artifact (System labels are + excluded). + create_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp when this Artifact was + created. + update_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp when this Artifact was + last updated. + state (google.cloud.aiplatform_v1.types.Artifact.State): + The state of this Artifact. This is a + property of the Artifact, and does not imply or + capture any ongoing process. This property is + managed by clients (such as Vertex AI + Pipelines), and the system does not prescribe or + check the validity of state transitions. + schema_title (str): + The title of the schema describing the + metadata. + Schema title and version is expected to be + registered in earlier Create Schema calls. And + both are used together as unique identifiers to + identify schemas within the local metadata + store. + schema_version (str): + The version of the schema in schema_name to use. + + Schema title and version is expected to be registered in + earlier Create Schema calls. And both are used together as + unique identifiers to identify schemas within the local + metadata store. + metadata (google.protobuf.struct_pb2.Struct): + Properties of the Artifact. + The size of this field should not exceed 200KB. + description (str): + Description of the Artifact + """ + + class State(proto.Enum): + r"""Describes the state of the Artifact.""" + STATE_UNSPECIFIED = 0 + PENDING = 1 + LIVE = 2 + + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + uri = proto.Field( + proto.STRING, + number=6, + ) + etag = proto.Field( + proto.STRING, + number=9, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=10, + ) + create_time = proto.Field( + proto.MESSAGE, + number=11, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=12, + message=timestamp_pb2.Timestamp, + ) + state = proto.Field( + proto.ENUM, + number=13, + enum=State, + ) + schema_title = proto.Field( + proto.STRING, + number=14, + ) + schema_version = proto.Field( + proto.STRING, + number=15, + ) + metadata = proto.Field( + proto.MESSAGE, + number=16, + message=struct_pb2.Struct, + ) + description = proto.Field( + proto.STRING, + number=17, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/batch_prediction_job.py b/google/cloud/aiplatform_v1/types/batch_prediction_job.py index 757ee3164e..a98d8feb11 100644 --- a/google/cloud/aiplatform_v1/types/batch_prediction_job.py +++ b/google/cloud/aiplatform_v1/types/batch_prediction_job.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,19 +17,26 @@ from google.cloud.aiplatform_v1.types import completion_stats as gca_completion_stats from google.cloud.aiplatform_v1.types import encryption_spec as gca_encryption_spec +from google.cloud.aiplatform_v1.types import explanation from google.cloud.aiplatform_v1.types import io from google.cloud.aiplatform_v1.types import job_state from google.cloud.aiplatform_v1.types import machine_resources from google.cloud.aiplatform_v1.types import ( manual_batch_tuning_parameters as gca_manual_batch_tuning_parameters, ) +from google.cloud.aiplatform_v1.types import ( + unmanaged_container_model as gca_unmanaged_container_model, +) from google.protobuf import struct_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore from google.rpc import status_pb2 # type: ignore __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1", manifest={"BatchPredictionJob",}, + package="google.cloud.aiplatform.v1", + manifest={ + "BatchPredictionJob", + }, ) @@ -50,11 +57,23 @@ class BatchPredictionJob(proto.Message): Required. The user-defined name of this BatchPredictionJob. model (str): - Required. The name of the Model that produces - the predictions via this job, must share the - same ancestor Location. Starting this job has no - impact on any existing deployments of the Model - and their resources. + The name of the Model resoure that produces the predictions + via this job, must share the same ancestor Location. + Starting this job has no impact on any existing deployments + of the Model and their resources. Exactly one of model and + unmanaged_container_model must be set. + + The model resource name may contain version id or version + alias to specify the version, if no version is specified, + the default version will be used. + model_version_id (str): + Output only. The version ID of the Model that + produces the predictions via this job. + unmanaged_container_model (google.cloud.aiplatform_v1.types.UnmanagedContainerModel): + Contains model information necessary to perform batch + prediction without requiring uploading to model registry. + Exactly one of model and unmanaged_container_model must be + set. input_config (google.cloud.aiplatform_v1.types.BatchPredictionJob.InputConfig): Required. Input configuration of the instances on which predictions are performed. The schema of any single instance @@ -88,8 +107,47 @@ class BatchPredictionJob(proto.Message): Immutable. Parameters configuring the batch behavior. Currently only applicable when [dedicated_resources][google.cloud.aiplatform.v1.BatchPredictionJob.dedicated_resources] - are used (in other cases AI Platform does the tuning - itself). + are used (in other cases Vertex AI does the tuning itself). + generate_explanation (bool): + Generate explanation with the batch prediction results. + + When set to ``true``, the batch prediction output changes + based on the ``predictions_format`` field of the + [BatchPredictionJob.output_config][google.cloud.aiplatform.v1.BatchPredictionJob.output_config] + object: + + - ``bigquery``: output includes a column named + ``explanation``. The value is a struct that conforms to + the [Explanation][google.cloud.aiplatform.v1.Explanation] + object. + - ``jsonl``: The JSON objects on each line include an + additional entry keyed ``explanation``. The value of the + entry is a JSON object that conforms to the + [Explanation][google.cloud.aiplatform.v1.Explanation] + object. + - ``csv``: Generating explanations for CSV format is not + supported. + + If this field is set to true, either the + [Model.explanation_spec][google.cloud.aiplatform.v1.Model.explanation_spec] + or + [explanation_spec][google.cloud.aiplatform.v1.BatchPredictionJob.explanation_spec] + must be populated. + explanation_spec (google.cloud.aiplatform_v1.types.ExplanationSpec): + Explanation configuration for this BatchPredictionJob. Can + be specified only if + [generate_explanation][google.cloud.aiplatform.v1.BatchPredictionJob.generate_explanation] + is set to ``true``. + + This value overrides the value of + [Model.explanation_spec][google.cloud.aiplatform.v1.Model.explanation_spec]. + All fields of + [explanation_spec][google.cloud.aiplatform.v1.BatchPredictionJob.explanation_spec] + are optional in the request. If a field of the + [explanation_spec][google.cloud.aiplatform.v1.BatchPredictionJob.explanation_spec] + object is not populated, the corresponding field of the + [Model.explanation_spec][google.cloud.aiplatform.v1.Model.explanation_spec] + object is inherited. output_info (google.cloud.aiplatform_v1.types.BatchPredictionJob.OutputInfo): Output only. Information further describing the output of this job. @@ -128,7 +186,7 @@ class BatchPredictionJob(proto.Message): update_time (google.protobuf.timestamp_pb2.Timestamp): Output only. Time when the BatchPredictionJob was most recently updated. - labels (Sequence[google.cloud.aiplatform_v1.types.BatchPredictionJob.LabelsEntry]): + labels (Mapping[str, str]): The labels with user-defined metadata to organize BatchPredictionJobs. Label keys and values can be no longer than 64 @@ -153,10 +211,19 @@ class InputConfig(proto.Message): for Model's supported input formats, and how instances should be expressed via any of them. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: gcs_source (google.cloud.aiplatform_v1.types.GcsSource): The Cloud Storage location for the input instances. + + This field is a member of `oneof`_ ``source``. bigquery_source (google.cloud.aiplatform_v1.types.BigQuerySource): The BigQuery location of the input table. The schema of the table should be in the format @@ -164,6 +231,8 @@ class InputConfig(proto.Message): if one is provided. The table may contain additional columns that are not described by the schema, and they will be ignored. + + This field is a member of `oneof`_ ``source``. instances_format (str): Required. The format in which instances are given, must be one of the @@ -172,12 +241,21 @@ class InputConfig(proto.Message): """ gcs_source = proto.Field( - proto.MESSAGE, number=2, oneof="source", message=io.GcsSource, + proto.MESSAGE, + number=2, + oneof="source", + message=io.GcsSource, ) bigquery_source = proto.Field( - proto.MESSAGE, number=3, oneof="source", message=io.BigQuerySource, + proto.MESSAGE, + number=3, + oneof="source", + message=io.BigQuerySource, + ) + instances_format = proto.Field( + proto.STRING, + number=1, ) - instances_format = proto.Field(proto.STRING, number=1,) class OutputConfig(proto.Message): r"""Configures the output of @@ -187,6 +265,13 @@ class OutputConfig(proto.Message): for supported output formats, and how predictions are expressed via any of them. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: gcs_destination (google.cloud.aiplatform_v1.types.GcsDestination): The Cloud Storage location of the directory where the output @@ -213,12 +298,14 @@ class OutputConfig(proto.Message): files are created (N depends on total number of failed predictions). These files contain the failed instances, as per their schema, followed by an additional ``error`` field - which as value has ```google.rpc.Status`` `__ + which as value has [google.rpc.Status][google.rpc.Status] containing only ``code`` and ``message`` fields. + + This field is a member of `oneof`_ ``destination``. bigquery_destination (google.cloud.aiplatform_v1.types.BigQueryDestination): - The BigQuery project location where the output is to be - written to. In the given project a new dataset is created - with name + The BigQuery project or dataset location where the output is + to be written to. If project is provided, a new dataset is + created with name ``prediction__`` where is made BigQuery-dataset-name compatible (for example, most special characters become underscores), and timestamp is in @@ -235,18 +322,22 @@ class OutputConfig(proto.Message): ``errors`` table contains rows for which the prediction has failed, it has instance columns, as per the instance schema, followed by a single "errors" column, which as values has - ```google.rpc.Status`` `__ represented as a STRUCT, - and containing only ``code`` and ``message``. + [google.rpc.Status][google.rpc.Status] represented as a + STRUCT, and containing only ``code`` and ``message``. + + This field is a member of `oneof`_ ``destination``. predictions_format (str): - Required. The format in which AI Platform gives the + Required. The format in which Vertex AI gives the predictions, must be one of the [Model's][google.cloud.aiplatform.v1.BatchPredictionJob.model] - [supported_output_storage_formats][google.cloud.aiplatform.v1.Model.supported_output_storage_formats]. """ gcs_destination = proto.Field( - proto.MESSAGE, number=2, oneof="destination", message=io.GcsDestination, + proto.MESSAGE, + number=2, + oneof="destination", + message=io.GcsDestination, ) bigquery_destination = proto.Field( proto.MESSAGE, @@ -254,67 +345,171 @@ class OutputConfig(proto.Message): oneof="destination", message=io.BigQueryDestination, ) - predictions_format = proto.Field(proto.STRING, number=1,) + predictions_format = proto.Field( + proto.STRING, + number=1, + ) class OutputInfo(proto.Message): r"""Further describes this job's output. Supplements [output_config][google.cloud.aiplatform.v1.BatchPredictionJob.output_config]. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: gcs_output_directory (str): Output only. The full path of the Cloud Storage directory created, into which the prediction output is written. + + This field is a member of `oneof`_ ``output_location``. bigquery_output_dataset (str): Output only. The path of the BigQuery dataset created, in ``bq://projectId.bqDatasetId`` format, into which the prediction output is written. + + This field is a member of `oneof`_ ``output_location``. + bigquery_output_table (str): + Output only. The name of the BigQuery table created, in + ``predictions_`` format, into which the + prediction output is written. Can be used by UI to generate + the BigQuery output path, for example. """ gcs_output_directory = proto.Field( - proto.STRING, number=1, oneof="output_location", + proto.STRING, + number=1, + oneof="output_location", ) bigquery_output_dataset = proto.Field( - proto.STRING, number=2, oneof="output_location", + proto.STRING, + number=2, + oneof="output_location", + ) + bigquery_output_table = proto.Field( + proto.STRING, + number=4, ) - name = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) - model = proto.Field(proto.STRING, number=3,) - input_config = proto.Field(proto.MESSAGE, number=4, message=InputConfig,) - model_parameters = proto.Field(proto.MESSAGE, number=5, message=struct_pb2.Value,) - output_config = proto.Field(proto.MESSAGE, number=6, message=OutputConfig,) + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + model = proto.Field( + proto.STRING, + number=3, + ) + model_version_id = proto.Field( + proto.STRING, + number=30, + ) + unmanaged_container_model = proto.Field( + proto.MESSAGE, + number=28, + message=gca_unmanaged_container_model.UnmanagedContainerModel, + ) + input_config = proto.Field( + proto.MESSAGE, + number=4, + message=InputConfig, + ) + model_parameters = proto.Field( + proto.MESSAGE, + number=5, + message=struct_pb2.Value, + ) + output_config = proto.Field( + proto.MESSAGE, + number=6, + message=OutputConfig, + ) dedicated_resources = proto.Field( - proto.MESSAGE, number=7, message=machine_resources.BatchDedicatedResources, + proto.MESSAGE, + number=7, + message=machine_resources.BatchDedicatedResources, ) manual_batch_tuning_parameters = proto.Field( proto.MESSAGE, number=8, message=gca_manual_batch_tuning_parameters.ManualBatchTuningParameters, ) - output_info = proto.Field(proto.MESSAGE, number=9, message=OutputInfo,) - state = proto.Field(proto.ENUM, number=10, enum=job_state.JobState,) - error = proto.Field(proto.MESSAGE, number=11, message=status_pb2.Status,) + generate_explanation = proto.Field( + proto.BOOL, + number=23, + ) + explanation_spec = proto.Field( + proto.MESSAGE, + number=25, + message=explanation.ExplanationSpec, + ) + output_info = proto.Field( + proto.MESSAGE, + number=9, + message=OutputInfo, + ) + state = proto.Field( + proto.ENUM, + number=10, + enum=job_state.JobState, + ) + error = proto.Field( + proto.MESSAGE, + number=11, + message=status_pb2.Status, + ) partial_failures = proto.RepeatedField( - proto.MESSAGE, number=12, message=status_pb2.Status, + proto.MESSAGE, + number=12, + message=status_pb2.Status, ) resources_consumed = proto.Field( - proto.MESSAGE, number=13, message=machine_resources.ResourcesConsumed, + proto.MESSAGE, + number=13, + message=machine_resources.ResourcesConsumed, ) completion_stats = proto.Field( - proto.MESSAGE, number=14, message=gca_completion_stats.CompletionStats, + proto.MESSAGE, + number=14, + message=gca_completion_stats.CompletionStats, ) create_time = proto.Field( - proto.MESSAGE, number=15, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=15, + message=timestamp_pb2.Timestamp, + ) + start_time = proto.Field( + proto.MESSAGE, + number=16, + message=timestamp_pb2.Timestamp, + ) + end_time = proto.Field( + proto.MESSAGE, + number=17, + message=timestamp_pb2.Timestamp, ) - start_time = proto.Field(proto.MESSAGE, number=16, message=timestamp_pb2.Timestamp,) - end_time = proto.Field(proto.MESSAGE, number=17, message=timestamp_pb2.Timestamp,) update_time = proto.Field( - proto.MESSAGE, number=18, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=18, + message=timestamp_pb2.Timestamp, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=19, ) - labels = proto.MapField(proto.STRING, proto.STRING, number=19,) encryption_spec = proto.Field( - proto.MESSAGE, number=24, message=gca_encryption_spec.EncryptionSpec, + proto.MESSAGE, + number=24, + message=gca_encryption_spec.EncryptionSpec, ) diff --git a/google/cloud/aiplatform_v1/types/completion_stats.py b/google/cloud/aiplatform_v1/types/completion_stats.py index 43a2bff9b7..ebaa4c7a88 100644 --- a/google/cloud/aiplatform_v1/types/completion_stats.py +++ b/google/cloud/aiplatform_v1/types/completion_stats.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,7 +17,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1", manifest={"CompletionStats",}, + package="google.cloud.aiplatform.v1", + manifest={ + "CompletionStats", + }, ) @@ -41,11 +44,29 @@ class CompletionStats(proto.Message): Set to -1 if the number is unknown (for example, the operation failed before the total entity number could be collected). + successful_forecast_point_count (int): + Output only. The number of the successful + forecast points that are generated by the + forecasting model. This is ONLY used by the + forecasting batch prediction. """ - successful_count = proto.Field(proto.INT64, number=1,) - failed_count = proto.Field(proto.INT64, number=2,) - incomplete_count = proto.Field(proto.INT64, number=3,) + successful_count = proto.Field( + proto.INT64, + number=1, + ) + failed_count = proto.Field( + proto.INT64, + number=2, + ) + incomplete_count = proto.Field( + proto.INT64, + number=3, + ) + successful_forecast_point_count = proto.Field( + proto.INT64, + number=5, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/context.py b/google/cloud/aiplatform_v1/types/context.py new file mode 100644 index 0000000000..f65d3613a5 --- /dev/null +++ b/google/cloud/aiplatform_v1/types/context.py @@ -0,0 +1,136 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + +from google.protobuf import struct_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "Context", + }, +) + + +class Context(proto.Message): + r"""Instance of a general context. + + Attributes: + name (str): + Output only. The resource name of the + Context. + display_name (str): + User provided display name of the Context. + May be up to 128 Unicode characters. + etag (str): + An eTag used to perform consistent + read-modify-write updates. If not set, a blind + "overwrite" update happens. + labels (Mapping[str, str]): + The labels with user-defined metadata to + organize your Contexts. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. No more than 64 user labels can be + associated with one Context (System labels are + excluded). + create_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp when this Context was + created. + update_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp when this Context was + last updated. + parent_contexts (Sequence[str]): + Output only. A list of resource names of Contexts that are + parents of this Context. A Context may have at most 10 + parent_contexts. + schema_title (str): + The title of the schema describing the + metadata. + Schema title and version is expected to be + registered in earlier Create Schema calls. And + both are used together as unique identifiers to + identify schemas within the local metadata + store. + schema_version (str): + The version of the schema in schema_name to use. + + Schema title and version is expected to be registered in + earlier Create Schema calls. And both are used together as + unique identifiers to identify schemas within the local + metadata store. + metadata (google.protobuf.struct_pb2.Struct): + Properties of the Context. + The size of this field should not exceed 200KB. + description (str): + Description of the Context + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + etag = proto.Field( + proto.STRING, + number=8, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=9, + ) + create_time = proto.Field( + proto.MESSAGE, + number=10, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=11, + message=timestamp_pb2.Timestamp, + ) + parent_contexts = proto.RepeatedField( + proto.STRING, + number=12, + ) + schema_title = proto.Field( + proto.STRING, + number=13, + ) + schema_version = proto.Field( + proto.STRING, + number=14, + ) + metadata = proto.Field( + proto.MESSAGE, + number=15, + message=struct_pb2.Struct, + ) + description = proto.Field( + proto.STRING, + number=16, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/custom_job.py b/google/cloud/aiplatform_v1/types/custom_job.py index 55fe308c87..1b269d4fc2 100644 --- a/google/cloud/aiplatform_v1/types/custom_job.py +++ b/google/cloud/aiplatform_v1/types/custom_job.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -72,7 +72,7 @@ class CustomJob(proto.Message): error (google.rpc.status_pb2.Status): Output only. Only populated when job's state is ``JOB_STATE_FAILED`` or ``JOB_STATE_CANCELLED``. - labels (Sequence[google.cloud.aiplatform_v1.types.CustomJob.LabelsEntry]): + labels (Mapping[str, str]): The labels with user-defined metadata to organize CustomJobs. Label keys and values can be no longer than 64 @@ -87,37 +87,101 @@ class CustomJob(proto.Message): CustomJob. If this is set, then all resources created by the CustomJob will be encrypted with the provided encryption key. + web_access_uris (Mapping[str, str]): + Output only. URIs for accessing `interactive + shells `__ + (one URI for each training node). Only available if + [job_spec.enable_web_access][google.cloud.aiplatform.v1.CustomJobSpec.enable_web_access] + is ``true``. + + The keys are names of each node in the training job; for + example, ``workerpool0-0`` for the primary node, + ``workerpool1-0`` for the first node in the second worker + pool, and ``workerpool1-1`` for the second node in the + second worker pool. + + The values are the URIs for each node's interactive shell. """ - name = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) - job_spec = proto.Field(proto.MESSAGE, number=4, message="CustomJobSpec",) - state = proto.Field(proto.ENUM, number=5, enum=job_state.JobState,) - create_time = proto.Field(proto.MESSAGE, number=6, message=timestamp_pb2.Timestamp,) - start_time = proto.Field(proto.MESSAGE, number=7, message=timestamp_pb2.Timestamp,) - end_time = proto.Field(proto.MESSAGE, number=8, message=timestamp_pb2.Timestamp,) - update_time = proto.Field(proto.MESSAGE, number=9, message=timestamp_pb2.Timestamp,) - error = proto.Field(proto.MESSAGE, number=10, message=status_pb2.Status,) - labels = proto.MapField(proto.STRING, proto.STRING, number=11,) + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + job_spec = proto.Field( + proto.MESSAGE, + number=4, + message="CustomJobSpec", + ) + state = proto.Field( + proto.ENUM, + number=5, + enum=job_state.JobState, + ) + create_time = proto.Field( + proto.MESSAGE, + number=6, + message=timestamp_pb2.Timestamp, + ) + start_time = proto.Field( + proto.MESSAGE, + number=7, + message=timestamp_pb2.Timestamp, + ) + end_time = proto.Field( + proto.MESSAGE, + number=8, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=9, + message=timestamp_pb2.Timestamp, + ) + error = proto.Field( + proto.MESSAGE, + number=10, + message=status_pb2.Status, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=11, + ) encryption_spec = proto.Field( - proto.MESSAGE, number=12, message=gca_encryption_spec.EncryptionSpec, + proto.MESSAGE, + number=12, + message=gca_encryption_spec.EncryptionSpec, + ) + web_access_uris = proto.MapField( + proto.STRING, + proto.STRING, + number=16, ) class CustomJobSpec(proto.Message): r"""Represents the spec of a CustomJob. + Next Id: 14 + Attributes: worker_pool_specs (Sequence[google.cloud.aiplatform_v1.types.WorkerPoolSpec]): Required. The spec of the worker pools - including machine type and Docker image. + including machine type and Docker image. All + worker pools except the first one are optional + and can be skipped by providing an empty value. scheduling (google.cloud.aiplatform_v1.types.Scheduling): Scheduling options for a CustomJob. service_account (str): - Specifies the service account for workload - run-as account. Users submitting jobs must have - act-as permission on this run-as account. If - unspecified, the AI Platform Custom Code Service - Agent for the CustomJob's project is used. + Specifies the service account for workload run-as account. + Users submitting jobs must have act-as permission on this + run-as account. If unspecified, the `Vertex AI Custom Code + Service + Agent `__ + for the CustomJob's project is used. network (str): The full name of the Compute Engine `network `__ @@ -129,9 +193,21 @@ class CustomJobSpec(proto.Message): {project} is a project number, as in ``12345``, and {network} is a network name. - Private services access must already be configured for the - network. If left unspecified, the job is not peered with any - network. + To specify this field, you must have already `configured VPC + Network Peering for Vertex + AI `__. + + If this field is left unspecified, the job is not peered + with any network. + reserved_ip_ranges (Sequence[str]): + Optional. A list of names for the reserved ip ranges under + the VPC network that can be used for this job. + + If set, we will deploy the job within the provided ip + ranges. Otherwise, the job will be deployed to any ip ranges + under the provided VPC network. + + Example: ['vertex-ai-ip-range']. base_output_directory (google.cloud.aiplatform_v1.types.GcsDestination): The Cloud Storage location to store the output of this CustomJob or HyperparameterTuningJob. For @@ -140,9 +216,8 @@ class CustomJobSpec(proto.Message): name [id][google.cloud.aiplatform.v1.Trial.id] under its parent HyperparameterTuningJob's baseOutputDirectory. - The following AI Platform environment variables will be - passed to containers or python modules when this field is - set: + The following Vertex AI environment variables will be passed + to containers or python modules when this field is set: For CustomJob: @@ -160,53 +235,131 @@ class CustomJobSpec(proto.Message): ``//checkpoints/`` - AIP_TENSORBOARD_LOG_DIR = ``//logs/`` + tensorboard (str): + Optional. The name of a Vertex AI + [Tensorboard][google.cloud.aiplatform.v1.Tensorboard] + resource to which this CustomJob will upload Tensorboard + logs. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}`` + enable_web_access (bool): + Optional. Whether you want Vertex AI to enable `interactive + shell + access `__ + to training containers. + + If set to ``true``, you can access interactive shells at the + URIs given by + [CustomJob.web_access_uris][google.cloud.aiplatform.v1.CustomJob.web_access_uris] + or + [Trial.web_access_uris][google.cloud.aiplatform.v1.Trial.web_access_uris] + (within + [HyperparameterTuningJob.trials][google.cloud.aiplatform.v1.HyperparameterTuningJob.trials]). """ worker_pool_specs = proto.RepeatedField( - proto.MESSAGE, number=1, message="WorkerPoolSpec", + proto.MESSAGE, + number=1, + message="WorkerPoolSpec", + ) + scheduling = proto.Field( + proto.MESSAGE, + number=3, + message="Scheduling", + ) + service_account = proto.Field( + proto.STRING, + number=4, + ) + network = proto.Field( + proto.STRING, + number=5, + ) + reserved_ip_ranges = proto.RepeatedField( + proto.STRING, + number=13, ) - scheduling = proto.Field(proto.MESSAGE, number=3, message="Scheduling",) - service_account = proto.Field(proto.STRING, number=4,) - network = proto.Field(proto.STRING, number=5,) base_output_directory = proto.Field( - proto.MESSAGE, number=6, message=io.GcsDestination, + proto.MESSAGE, + number=6, + message=io.GcsDestination, + ) + tensorboard = proto.Field( + proto.STRING, + number=7, + ) + enable_web_access = proto.Field( + proto.BOOL, + number=10, ) class WorkerPoolSpec(proto.Message): r"""Represents the spec of a worker pool in a job. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: container_spec (google.cloud.aiplatform_v1.types.ContainerSpec): The custom container task. + + This field is a member of `oneof`_ ``task``. python_package_spec (google.cloud.aiplatform_v1.types.PythonPackageSpec): The Python packaged task. + + This field is a member of `oneof`_ ``task``. machine_spec (google.cloud.aiplatform_v1.types.MachineSpec): Optional. Immutable. The specification of a single machine. replica_count (int): Optional. The number of worker replicas to use for this worker pool. + nfs_mounts (Sequence[google.cloud.aiplatform_v1.types.NfsMount]): + Optional. List of NFS mount spec. disk_spec (google.cloud.aiplatform_v1.types.DiskSpec): Disk spec. """ container_spec = proto.Field( - proto.MESSAGE, number=6, oneof="task", message="ContainerSpec", + proto.MESSAGE, + number=6, + oneof="task", + message="ContainerSpec", ) python_package_spec = proto.Field( - proto.MESSAGE, number=7, oneof="task", message="PythonPackageSpec", + proto.MESSAGE, + number=7, + oneof="task", + message="PythonPackageSpec", ) machine_spec = proto.Field( - proto.MESSAGE, number=1, message=machine_resources.MachineSpec, + proto.MESSAGE, + number=1, + message=machine_resources.MachineSpec, + ) + replica_count = proto.Field( + proto.INT64, + number=2, + ) + nfs_mounts = proto.RepeatedField( + proto.MESSAGE, + number=4, + message=machine_resources.NfsMount, ) - replica_count = proto.Field(proto.INT64, number=2,) disk_spec = proto.Field( - proto.MESSAGE, number=5, message=machine_resources.DiskSpec, + proto.MESSAGE, + number=5, + message=machine_resources.DiskSpec, ) class ContainerSpec(proto.Message): r"""The spec of a Container. + Attributes: image_uri (str): Required. The URI of a container image in the @@ -221,25 +374,40 @@ class ContainerSpec(proto.Message): container. env (Sequence[google.cloud.aiplatform_v1.types.EnvVar]): Environment variables to be passed to the - container. + container. Maximum limit is 100. """ - image_uri = proto.Field(proto.STRING, number=1,) - command = proto.RepeatedField(proto.STRING, number=2,) - args = proto.RepeatedField(proto.STRING, number=3,) - env = proto.RepeatedField(proto.MESSAGE, number=4, message=env_var.EnvVar,) + image_uri = proto.Field( + proto.STRING, + number=1, + ) + command = proto.RepeatedField( + proto.STRING, + number=2, + ) + args = proto.RepeatedField( + proto.STRING, + number=3, + ) + env = proto.RepeatedField( + proto.MESSAGE, + number=4, + message=env_var.EnvVar, + ) class PythonPackageSpec(proto.Message): r"""The spec of a Python packaged code. + Attributes: executor_image_uri (str): - Required. The URI of a container image in the - Container Registry that will run the provided - python package. AI Platform provides wide range - of executor images with pre-installed packages - to meet users' various use cases. Only one of - the provided images can be set here. + Required. The URI of a container image in Artifact Registry + that will run the provided Python package. Vertex AI + provides a wide range of executor images with pre-installed + packages to meet users' various use cases. See the list of + `pre-built containers for + training `__. + You must use an image from this list. package_uris (Sequence[str]): Required. The Google Cloud Storage location of the Python package files which are the @@ -253,14 +421,30 @@ class PythonPackageSpec(proto.Message): Python task. env (Sequence[google.cloud.aiplatform_v1.types.EnvVar]): Environment variables to be passed to the - python module. + python module. Maximum limit is 100. """ - executor_image_uri = proto.Field(proto.STRING, number=1,) - package_uris = proto.RepeatedField(proto.STRING, number=2,) - python_module = proto.Field(proto.STRING, number=3,) - args = proto.RepeatedField(proto.STRING, number=4,) - env = proto.RepeatedField(proto.MESSAGE, number=5, message=env_var.EnvVar,) + executor_image_uri = proto.Field( + proto.STRING, + number=1, + ) + package_uris = proto.RepeatedField( + proto.STRING, + number=2, + ) + python_module = proto.Field( + proto.STRING, + number=3, + ) + args = proto.RepeatedField( + proto.STRING, + number=4, + ) + env = proto.RepeatedField( + proto.MESSAGE, + number=5, + message=env_var.EnvVar, + ) class Scheduling(proto.Message): @@ -278,8 +462,15 @@ class Scheduling(proto.Message): to workers leaving and joining a job. """ - timeout = proto.Field(proto.MESSAGE, number=1, message=duration_pb2.Duration,) - restart_job_on_worker_restart = proto.Field(proto.BOOL, number=3,) + timeout = proto.Field( + proto.MESSAGE, + number=1, + message=duration_pb2.Duration, + ) + restart_job_on_worker_restart = proto.Field( + proto.BOOL, + number=3, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/data_item.py b/google/cloud/aiplatform_v1/types/data_item.py index 447850e95e..d97d22360e 100644 --- a/google/cloud/aiplatform_v1/types/data_item.py +++ b/google/cloud/aiplatform_v1/types/data_item.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,7 +20,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1", manifest={"DataItem",}, + package="google.cloud.aiplatform.v1", + manifest={ + "DataItem", + }, ) @@ -38,7 +41,7 @@ class DataItem(proto.Message): update_time (google.protobuf.timestamp_pb2.Timestamp): Output only. Timestamp when this DataItem was last updated. - labels (Sequence[google.cloud.aiplatform_v1.types.DataItem.LabelsEntry]): + labels (Mapping[str, str]): Optional. The labels with user-defined metadata to organize your DataItems. Label keys and values can be no longer than 64 @@ -60,17 +63,39 @@ class DataItem(proto.Message): schema's][google.cloud.aiplatform.v1.Dataset.metadata_schema_uri] dataItemSchemaUri field. etag (str): - Optional. Used to perform consistent read- - odify-write updates. If not set, a blind + Optional. Used to perform consistent + read-modify-write updates. If not set, a blind "overwrite" update happens. """ - name = proto.Field(proto.STRING, number=1,) - create_time = proto.Field(proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp,) - update_time = proto.Field(proto.MESSAGE, number=6, message=timestamp_pb2.Timestamp,) - labels = proto.MapField(proto.STRING, proto.STRING, number=3,) - payload = proto.Field(proto.MESSAGE, number=4, message=struct_pb2.Value,) - etag = proto.Field(proto.STRING, number=7,) + name = proto.Field( + proto.STRING, + number=1, + ) + create_time = proto.Field( + proto.MESSAGE, + number=2, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=6, + message=timestamp_pb2.Timestamp, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=3, + ) + payload = proto.Field( + proto.MESSAGE, + number=4, + message=struct_pb2.Value, + ) + etag = proto.Field( + proto.STRING, + number=7, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/data_labeling_job.py b/google/cloud/aiplatform_v1/types/data_labeling_job.py index 988b283a77..0799b0e85d 100644 --- a/google/cloud/aiplatform_v1/types/data_labeling_job.py +++ b/google/cloud/aiplatform_v1/types/data_labeling_job.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -52,7 +52,7 @@ class DataLabelingJob(proto.Message): Required. Dataset resource names. Right now we only support labeling from a single Dataset. Format: ``projects/{project}/locations/{location}/datasets/{dataset}`` - annotation_labels (Sequence[google.cloud.aiplatform_v1.types.DataLabelingJob.AnnotationLabelsEntry]): + annotation_labels (Mapping[str, str]): Labels to assign to annotations generated by this DataLabelingJob. Label keys and values can be no longer than 64 @@ -76,9 +76,9 @@ class DataLabelingJob(proto.Message): Google Cloud Storage describing the config for a specific type of DataLabelingJob. The schema files that can be used here are found in the - https://storage.googleapis.com/google-cloud- - aiplatform bucket in the - /schema/datalabelingjob/inputs/ folder. + https://storage.googleapis.com/google-cloud-aiplatform + bucket in the /schema/datalabelingjob/inputs/ + folder. inputs (google.protobuf.struct_pb2.Value): Required. Input config parameters for the DataLabelingJob. @@ -101,7 +101,7 @@ class DataLabelingJob(proto.Message): Output only. DataLabelingJob errors. It is only populated when job's state is ``JOB_STATE_FAILED`` or ``JOB_STATE_CANCELLED``. - labels (Sequence[google.cloud.aiplatform_v1.types.DataLabelingJob.LabelsEntry]): + labels (Mapping[str, str]): The labels with user-defined metadata to organize your DataLabelingJobs. @@ -137,29 +137,87 @@ class DataLabelingJob(proto.Message): on the sampling strategy. """ - name = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) - datasets = proto.RepeatedField(proto.STRING, number=3,) - annotation_labels = proto.MapField(proto.STRING, proto.STRING, number=12,) - labeler_count = proto.Field(proto.INT32, number=4,) - instruction_uri = proto.Field(proto.STRING, number=5,) - inputs_schema_uri = proto.Field(proto.STRING, number=6,) - inputs = proto.Field(proto.MESSAGE, number=7, message=struct_pb2.Value,) - state = proto.Field(proto.ENUM, number=8, enum=job_state.JobState,) - labeling_progress = proto.Field(proto.INT32, number=13,) - current_spend = proto.Field(proto.MESSAGE, number=14, message=money_pb2.Money,) - create_time = proto.Field(proto.MESSAGE, number=9, message=timestamp_pb2.Timestamp,) + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + datasets = proto.RepeatedField( + proto.STRING, + number=3, + ) + annotation_labels = proto.MapField( + proto.STRING, + proto.STRING, + number=12, + ) + labeler_count = proto.Field( + proto.INT32, + number=4, + ) + instruction_uri = proto.Field( + proto.STRING, + number=5, + ) + inputs_schema_uri = proto.Field( + proto.STRING, + number=6, + ) + inputs = proto.Field( + proto.MESSAGE, + number=7, + message=struct_pb2.Value, + ) + state = proto.Field( + proto.ENUM, + number=8, + enum=job_state.JobState, + ) + labeling_progress = proto.Field( + proto.INT32, + number=13, + ) + current_spend = proto.Field( + proto.MESSAGE, + number=14, + message=money_pb2.Money, + ) + create_time = proto.Field( + proto.MESSAGE, + number=9, + message=timestamp_pb2.Timestamp, + ) update_time = proto.Field( - proto.MESSAGE, number=10, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=10, + message=timestamp_pb2.Timestamp, + ) + error = proto.Field( + proto.MESSAGE, + number=22, + message=status_pb2.Status, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=11, + ) + specialist_pools = proto.RepeatedField( + proto.STRING, + number=16, ) - error = proto.Field(proto.MESSAGE, number=22, message=status_pb2.Status,) - labels = proto.MapField(proto.STRING, proto.STRING, number=11,) - specialist_pools = proto.RepeatedField(proto.STRING, number=16,) encryption_spec = proto.Field( - proto.MESSAGE, number=20, message=gca_encryption_spec.EncryptionSpec, + proto.MESSAGE, + number=20, + message=gca_encryption_spec.EncryptionSpec, ) active_learning_config = proto.Field( - proto.MESSAGE, number=21, message="ActiveLearningConfig", + proto.MESSAGE, + number=21, + message="ActiveLearningConfig", ) @@ -169,12 +227,23 @@ class ActiveLearningConfig(proto.Message): iterations. For every iteration, it will select a batch of data based on the sampling strategy. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: max_data_item_count (int): Max number of human labeled DataItems. + + This field is a member of `oneof`_ ``human_labeling_budget``. max_data_item_percentage (int): Max percent of total DataItems for human labeling. + + This field is a member of `oneof`_ ``human_labeling_budget``. sample_config (google.cloud.aiplatform_v1.types.SampleConfig): Active learning data sampling config. For every active learning labeling iteration, it @@ -189,13 +258,25 @@ class ActiveLearningConfig(proto.Message): """ max_data_item_count = proto.Field( - proto.INT64, number=1, oneof="human_labeling_budget", + proto.INT64, + number=1, + oneof="human_labeling_budget", ) max_data_item_percentage = proto.Field( - proto.INT32, number=2, oneof="human_labeling_budget", + proto.INT32, + number=2, + oneof="human_labeling_budget", + ) + sample_config = proto.Field( + proto.MESSAGE, + number=3, + message="SampleConfig", + ) + training_config = proto.Field( + proto.MESSAGE, + number=4, + message="TrainingConfig", ) - sample_config = proto.Field(proto.MESSAGE, number=3, message="SampleConfig",) - training_config = proto.Field(proto.MESSAGE, number=4, message="TrainingConfig",) class SampleConfig(proto.Message): @@ -203,14 +284,21 @@ class SampleConfig(proto.Message): learning labeling iteration, it will select a batch of data based on the sampling strategy. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: initial_batch_sample_percentage (int): The percentage of data needed to be labeled in the first batch. + + This field is a member of `oneof`_ ``initial_batch_sample_size``. following_batch_sample_percentage (int): The percentage of data needed to be labeled in each following batch (except the first batch). + + This field is a member of `oneof`_ ``following_batch_sample_size``. sample_strategy (google.cloud.aiplatform_v1.types.SampleConfig.SampleStrategy): Field to choose sampling strategy. Sampling strategy will decide which data should be @@ -225,12 +313,20 @@ class SampleStrategy(proto.Enum): UNCERTAINTY = 1 initial_batch_sample_percentage = proto.Field( - proto.INT32, number=1, oneof="initial_batch_sample_size", + proto.INT32, + number=1, + oneof="initial_batch_sample_size", ) following_batch_sample_percentage = proto.Field( - proto.INT32, number=3, oneof="following_batch_sample_size", + proto.INT32, + number=3, + oneof="following_batch_sample_size", + ) + sample_strategy = proto.Field( + proto.ENUM, + number=5, + enum=SampleStrategy, ) - sample_strategy = proto.Field(proto.ENUM, number=5, enum=SampleStrategy,) class TrainingConfig(proto.Message): @@ -246,7 +342,10 @@ class TrainingConfig(proto.Message): this field means 1 hour. """ - timeout_training_milli_hours = proto.Field(proto.INT64, number=1,) + timeout_training_milli_hours = proto.Field( + proto.INT64, + number=1, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/dataset.py b/google/cloud/aiplatform_v1/types/dataset.py index d1d8f8f363..3eeaa861d2 100644 --- a/google/cloud/aiplatform_v1/types/dataset.py +++ b/google/cloud/aiplatform_v1/types/dataset.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,12 +23,17 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1", - manifest={"Dataset", "ImportDataConfig", "ExportDataConfig",}, + manifest={ + "Dataset", + "ImportDataConfig", + "ExportDataConfig", + }, ) class Dataset(proto.Message): r"""A collection of DataItems and Annotations on them. + Attributes: name (str): Output only. The resource name of the @@ -37,14 +42,15 @@ class Dataset(proto.Message): Required. The user-defined name of the Dataset. The name can be up to 128 characters long and can be consist of any UTF-8 characters. + description (str): + Optional. The description of the Dataset. metadata_schema_uri (str): Required. Points to a YAML file stored on Google Cloud Storage describing additional information about the Dataset. The schema is defined as an OpenAPI 3.0.2 Schema Object. The schema files that can be used here are found in - gs://google-cloud- - aiplatform/schema/dataset/metadata/. + gs://google-cloud-aiplatform/schema/dataset/metadata/. metadata (google.protobuf.struct_pb2.Value): Required. Additional information about the Dataset. @@ -58,7 +64,7 @@ class Dataset(proto.Message): Used to perform consistent read-modify-write updates. If not set, a blind "overwrite" update happens. - labels (Sequence[google.cloud.aiplatform_v1.types.Dataset.LabelsEntry]): + labels (Mapping[str, str]): The labels with user-defined metadata to organize your Datasets. @@ -79,21 +85,55 @@ class Dataset(proto.Message): title. encryption_spec (google.cloud.aiplatform_v1.types.EncryptionSpec): Customer-managed encryption key spec for a - Dataset. If set, this Dataset and all sub- - resources of this Dataset will be secured by + Dataset. If set, this Dataset and all + sub-resources of this Dataset will be secured by this key. """ - name = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) - metadata_schema_uri = proto.Field(proto.STRING, number=3,) - metadata = proto.Field(proto.MESSAGE, number=8, message=struct_pb2.Value,) - create_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) - update_time = proto.Field(proto.MESSAGE, number=5, message=timestamp_pb2.Timestamp,) - etag = proto.Field(proto.STRING, number=6,) - labels = proto.MapField(proto.STRING, proto.STRING, number=7,) + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + description = proto.Field( + proto.STRING, + number=16, + ) + metadata_schema_uri = proto.Field( + proto.STRING, + number=3, + ) + metadata = proto.Field( + proto.MESSAGE, + number=8, + message=struct_pb2.Value, + ) + create_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=5, + message=timestamp_pb2.Timestamp, + ) + etag = proto.Field( + proto.STRING, + number=6, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=7, + ) encryption_spec = proto.Field( - proto.MESSAGE, number=11, message=gca_encryption_spec.EncryptionSpec, + proto.MESSAGE, + number=11, + message=gca_encryption_spec.EncryptionSpec, ) @@ -102,11 +142,16 @@ class ImportDataConfig(proto.Message): Dataset, together with the labels that will be applied to the DataItems and the Annotations. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: gcs_source (google.cloud.aiplatform_v1.types.GcsSource): The Google Cloud Storage location for the input content. - data_item_labels (Sequence[google.cloud.aiplatform_v1.types.ImportDataConfig.DataItemLabelsEntry]): + + This field is a member of `oneof`_ ``source``. + data_item_labels (Mapping[str, str]): Labels that will be applied to newly imported DataItems. If an identical DataItem as one being imported already exists in the Dataset, then these labels will be appended to these @@ -126,20 +171,33 @@ class ImportDataConfig(proto.Message): Storage describing the import format. Validation will be done against the schema. The schema is defined as an `OpenAPI 3.0.2 Schema - Object `__. + Object `__. """ gcs_source = proto.Field( - proto.MESSAGE, number=1, oneof="source", message=io.GcsSource, + proto.MESSAGE, + number=1, + oneof="source", + message=io.GcsSource, + ) + data_item_labels = proto.MapField( + proto.STRING, + proto.STRING, + number=2, + ) + import_schema_uri = proto.Field( + proto.STRING, + number=4, ) - data_item_labels = proto.MapField(proto.STRING, proto.STRING, number=2,) - import_schema_uri = proto.Field(proto.STRING, number=4,) class ExportDataConfig(proto.Message): r"""Describes what part of the Dataset is to be exported, the destination of the export and how to export. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: gcs_destination (google.cloud.aiplatform_v1.types.GcsDestination): The Google Cloud Storage location where the output is to be @@ -153,6 +211,8 @@ class ExportDataConfig(proto.Message): with the corresponding annotations' schema title. Inside these sub directories, a schema.yaml will be created to describe the output format. + + This field is a member of `oneof`_ ``destination``. annotations_filter (str): A filter on Annotations of the Dataset. Only Annotations on to-be-exported DataItems(specified by [data_items_filter][]) @@ -162,9 +222,15 @@ class ExportDataConfig(proto.Message): """ gcs_destination = proto.Field( - proto.MESSAGE, number=1, oneof="destination", message=io.GcsDestination, + proto.MESSAGE, + number=1, + oneof="destination", + message=io.GcsDestination, + ) + annotations_filter = proto.Field( + proto.STRING, + number=2, ) - annotations_filter = proto.Field(proto.STRING, number=2,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/dataset_service.py b/google/cloud/aiplatform_v1/types/dataset_service.py index 3305dc7268..92aa06face 100644 --- a/google/cloud/aiplatform_v1/types/dataset_service.py +++ b/google/cloud/aiplatform_v1/types/dataset_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -60,8 +60,15 @@ class CreateDatasetRequest(proto.Message): Required. The Dataset to create. """ - parent = proto.Field(proto.STRING, number=1,) - dataset = proto.Field(proto.MESSAGE, number=2, message=gca_dataset.Dataset,) + parent = proto.Field( + proto.STRING, + number=1, + ) + dataset = proto.Field( + proto.MESSAGE, + number=2, + message=gca_dataset.Dataset, + ) class CreateDatasetOperationMetadata(proto.Message): @@ -74,7 +81,9 @@ class CreateDatasetOperationMetadata(proto.Message): """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, ) @@ -89,8 +98,15 @@ class GetDatasetRequest(proto.Message): Mask specifying which fields to read. """ - name = proto.Field(proto.STRING, number=1,) - read_mask = proto.Field(proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask,) + name = proto.Field( + proto.STRING, + number=1, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) class UpdateDatasetRequest(proto.Message): @@ -104,7 +120,7 @@ class UpdateDatasetRequest(proto.Message): update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. The update mask applies to the resource. For the ``FieldMask`` definition, see - `FieldMask `__. + [google.protobuf.FieldMask][google.protobuf.FieldMask]. Updatable fields: - ``display_name`` @@ -112,9 +128,15 @@ class UpdateDatasetRequest(proto.Message): - ``labels`` """ - dataset = proto.Field(proto.MESSAGE, number=1, message=gca_dataset.Dataset,) + dataset = proto.Field( + proto.MESSAGE, + number=1, + message=gca_dataset.Dataset, + ) update_mask = proto.Field( - proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, ) @@ -159,12 +181,31 @@ class ListDatasetsRequest(proto.Message): - ``update_time`` """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) - read_mask = proto.Field(proto.MESSAGE, number=5, message=field_mask_pb2.FieldMask,) - order_by = proto.Field(proto.STRING, number=6,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=5, + message=field_mask_pb2.FieldMask, + ) + order_by = proto.Field( + proto.STRING, + number=6, + ) class ListDatasetsResponse(proto.Message): @@ -184,9 +225,14 @@ def raw_page(self): return self datasets = proto.RepeatedField( - proto.MESSAGE, number=1, message=gca_dataset.Dataset, + proto.MESSAGE, + number=1, + message=gca_dataset.Dataset, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class DeleteDatasetRequest(proto.Message): @@ -200,7 +246,10 @@ class DeleteDatasetRequest(proto.Message): ``projects/{project}/locations/{location}/datasets/{dataset}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ImportDataRequest(proto.Message): @@ -217,16 +266,22 @@ class ImportDataRequest(proto.Message): in one batch. """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) import_configs = proto.RepeatedField( - proto.MESSAGE, number=2, message=gca_dataset.ImportDataConfig, + proto.MESSAGE, + number=2, + message=gca_dataset.ImportDataConfig, ) class ImportDataResponse(proto.Message): r"""Response message for [DatasetService.ImportData][google.cloud.aiplatform.v1.DatasetService.ImportData]. - """ + + """ class ImportDataOperationMetadata(proto.Message): @@ -239,7 +294,9 @@ class ImportDataOperationMetadata(proto.Message): """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, ) @@ -255,9 +312,14 @@ class ExportDataRequest(proto.Message): Required. The desired output location. """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) export_config = proto.Field( - proto.MESSAGE, number=2, message=gca_dataset.ExportDataConfig, + proto.MESSAGE, + number=2, + message=gca_dataset.ExportDataConfig, ) @@ -271,7 +333,10 @@ class ExportDataResponse(proto.Message): export operation. """ - exported_files = proto.RepeatedField(proto.STRING, number=1,) + exported_files = proto.RepeatedField( + proto.STRING, + number=1, + ) class ExportDataOperationMetadata(proto.Message): @@ -288,9 +353,14 @@ class ExportDataOperationMetadata(proto.Message): """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, + ) + gcs_output_directory = proto.Field( + proto.STRING, + number=2, ) - gcs_output_directory = proto.Field(proto.STRING, number=2,) class ListDataItemsRequest(proto.Message): @@ -316,12 +386,31 @@ class ListDataItemsRequest(proto.Message): field name for descending. """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) - read_mask = proto.Field(proto.MESSAGE, number=5, message=field_mask_pb2.FieldMask,) - order_by = proto.Field(proto.STRING, number=6,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=5, + message=field_mask_pb2.FieldMask, + ) + order_by = proto.Field( + proto.STRING, + number=6, + ) class ListDataItemsResponse(proto.Message): @@ -341,9 +430,14 @@ def raw_page(self): return self data_items = proto.RepeatedField( - proto.MESSAGE, number=1, message=data_item.DataItem, + proto.MESSAGE, + number=1, + message=data_item.DataItem, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class GetAnnotationSpecRequest(proto.Message): @@ -353,14 +447,20 @@ class GetAnnotationSpecRequest(proto.Message): Attributes: name (str): Required. The name of the AnnotationSpec resource. Format: - ``projects/{project}/locations/{location}/datasets/{dataset}/annotationSpecs/{annotation_spec}`` read_mask (google.protobuf.field_mask_pb2.FieldMask): Mask specifying which fields to read. """ - name = proto.Field(proto.STRING, number=1,) - read_mask = proto.Field(proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask,) + name = proto.Field( + proto.STRING, + number=1, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) class ListAnnotationsRequest(proto.Message): @@ -371,7 +471,6 @@ class ListAnnotationsRequest(proto.Message): parent (str): Required. The resource name of the DataItem to list Annotations from. Format: - ``projects/{project}/locations/{location}/datasets/{dataset}/dataItems/{data_item}`` filter (str): The standard list filter. @@ -387,12 +486,31 @@ class ListAnnotationsRequest(proto.Message): field name for descending. """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) - read_mask = proto.Field(proto.MESSAGE, number=5, message=field_mask_pb2.FieldMask,) - order_by = proto.Field(proto.STRING, number=6,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=5, + message=field_mask_pb2.FieldMask, + ) + order_by = proto.Field( + proto.STRING, + number=6, + ) class ListAnnotationsResponse(proto.Message): @@ -412,9 +530,14 @@ def raw_page(self): return self annotations = proto.RepeatedField( - proto.MESSAGE, number=1, message=annotation.Annotation, + proto.MESSAGE, + number=1, + message=annotation.Annotation, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/deployed_index_ref.py b/google/cloud/aiplatform_v1/types/deployed_index_ref.py new file mode 100644 index 0000000000..d014f6bb47 --- /dev/null +++ b/google/cloud/aiplatform_v1/types/deployed_index_ref.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "DeployedIndexRef", + }, +) + + +class DeployedIndexRef(proto.Message): + r"""Points to a DeployedIndex. + + Attributes: + index_endpoint (str): + Immutable. A resource name of the + IndexEndpoint. + deployed_index_id (str): + Immutable. The ID of the DeployedIndex in the + above IndexEndpoint. + """ + + index_endpoint = proto.Field( + proto.STRING, + number=1, + ) + deployed_index_id = proto.Field( + proto.STRING, + number=2, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/deployed_model_ref.py b/google/cloud/aiplatform_v1/types/deployed_model_ref.py index f95a292a8a..c3ed2c3157 100644 --- a/google/cloud/aiplatform_v1/types/deployed_model_ref.py +++ b/google/cloud/aiplatform_v1/types/deployed_model_ref.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,12 +17,16 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1", manifest={"DeployedModelRef",}, + package="google.cloud.aiplatform.v1", + manifest={ + "DeployedModelRef", + }, ) class DeployedModelRef(proto.Message): r"""Points to a DeployedModel. + Attributes: endpoint (str): Immutable. A resource name of an Endpoint. @@ -31,8 +35,14 @@ class DeployedModelRef(proto.Message): above Endpoint. """ - endpoint = proto.Field(proto.STRING, number=1,) - deployed_model_id = proto.Field(proto.STRING, number=2,) + endpoint = proto.Field( + proto.STRING, + number=1, + ) + deployed_model_id = proto.Field( + proto.STRING, + number=2, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/encryption_spec.py b/google/cloud/aiplatform_v1/types/encryption_spec.py index 74a553b82d..43762d48b5 100644 --- a/google/cloud/aiplatform_v1/types/encryption_spec.py +++ b/google/cloud/aiplatform_v1/types/encryption_spec.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,7 +17,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1", manifest={"EncryptionSpec",}, + package="google.cloud.aiplatform.v1", + manifest={ + "EncryptionSpec", + }, ) @@ -35,7 +38,10 @@ class EncryptionSpec(proto.Message): resource is created. """ - kms_key_name = proto.Field(proto.STRING, number=1,) + kms_key_name = proto.Field( + proto.STRING, + number=1, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/endpoint.py b/google/cloud/aiplatform_v1/types/endpoint.py index ea035eef5d..653f25e515 100644 --- a/google/cloud/aiplatform_v1/types/endpoint.py +++ b/google/cloud/aiplatform_v1/types/endpoint.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,12 +16,20 @@ import proto # type: ignore from google.cloud.aiplatform_v1.types import encryption_spec as gca_encryption_spec +from google.cloud.aiplatform_v1.types import explanation +from google.cloud.aiplatform_v1.types import io from google.cloud.aiplatform_v1.types import machine_resources from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1", manifest={"Endpoint", "DeployedModel",}, + package="google.cloud.aiplatform.v1", + manifest={ + "Endpoint", + "DeployedModel", + "PrivateEndpoints", + "PredictRequestResponseLoggingConfig", + }, ) @@ -46,7 +54,7 @@ class Endpoint(proto.Message): and [EndpointService.UndeployModel][google.cloud.aiplatform.v1.EndpointService.UndeployModel] respectively. - traffic_split (Sequence[google.cloud.aiplatform_v1.types.Endpoint.TrafficSplitEntry]): + traffic_split (Mapping[str, int]): A map from a DeployedModel's ID to the percentage of this Endpoint's traffic that should be forwarded to that DeployedModel. @@ -60,7 +68,7 @@ class Endpoint(proto.Message): Used to perform consistent read-modify-write updates. If not set, a blind "overwrite" update happens. - labels (Sequence[google.cloud.aiplatform_v1.types.Endpoint.LabelsEntry]): + labels (Mapping[str, str]): The labels with user-defined metadata to organize your Endpoints. Label keys and values can be no longer than 64 @@ -78,24 +86,107 @@ class Endpoint(proto.Message): last updated. encryption_spec (google.cloud.aiplatform_v1.types.EncryptionSpec): Customer-managed encryption key spec for an - Endpoint. If set, this Endpoint and all sub- - resources of this Endpoint will be secured by - this key. + Endpoint. If set, this Endpoint and all + sub-resources of this Endpoint will be secured + by this key. + network (str): + The full name of the Google Compute Engine + `network `__ + to which the Endpoint should be peered. + + Private services access must already be configured for the + network. If left unspecified, the Endpoint is not peered + with any network. + + Only one of the fields, + [network][google.cloud.aiplatform.v1.Endpoint.network] or + [enable_private_service_connect][google.cloud.aiplatform.v1.Endpoint.enable_private_service_connect], + can be set. + + `Format `__: + ``projects/{project}/global/networks/{network}``. Where + ``{project}`` is a project number, as in ``12345``, and + ``{network}`` is network name. + enable_private_service_connect (bool): + Deprecated: If true, expose the Endpoint via private service + connect. + + Only one of the fields, + [network][google.cloud.aiplatform.v1.Endpoint.network] or + [enable_private_service_connect][google.cloud.aiplatform.v1.Endpoint.enable_private_service_connect], + can be set. + model_deployment_monitoring_job (str): + Output only. Resource name of the Model Monitoring job + associated with this Endpoint if monitoring is enabled by + [CreateModelDeploymentMonitoringJob][]. Format: + ``projects/{project}/locations/{location}/modelDeploymentMonitoringJobs/{model_deployment_monitoring_job}`` + predict_request_response_logging_config (google.cloud.aiplatform_v1.types.PredictRequestResponseLoggingConfig): + Configures the request-response logging for + online prediction. """ - name = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) - description = proto.Field(proto.STRING, number=3,) + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + description = proto.Field( + proto.STRING, + number=3, + ) deployed_models = proto.RepeatedField( - proto.MESSAGE, number=4, message="DeployedModel", + proto.MESSAGE, + number=4, + message="DeployedModel", + ) + traffic_split = proto.MapField( + proto.STRING, + proto.INT32, + number=5, + ) + etag = proto.Field( + proto.STRING, + number=6, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=7, + ) + create_time = proto.Field( + proto.MESSAGE, + number=8, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=9, + message=timestamp_pb2.Timestamp, ) - traffic_split = proto.MapField(proto.STRING, proto.INT32, number=5,) - etag = proto.Field(proto.STRING, number=6,) - labels = proto.MapField(proto.STRING, proto.STRING, number=7,) - create_time = proto.Field(proto.MESSAGE, number=8, message=timestamp_pb2.Timestamp,) - update_time = proto.Field(proto.MESSAGE, number=9, message=timestamp_pb2.Timestamp,) encryption_spec = proto.Field( - proto.MESSAGE, number=10, message=gca_encryption_spec.EncryptionSpec, + proto.MESSAGE, + number=10, + message=gca_encryption_spec.EncryptionSpec, + ) + network = proto.Field( + proto.STRING, + number=13, + ) + enable_private_service_connect = proto.Field( + proto.BOOL, + number=17, + ) + model_deployment_monitoring_job = proto.Field( + proto.STRING, + number=14, + ) + predict_request_response_logging_config = proto.Field( + proto.MESSAGE, + number=18, + message="PredictRequestResponseLoggingConfig", ) @@ -103,28 +194,68 @@ class DeployedModel(proto.Message): r"""A deployment of a Model. Endpoints contain one or more DeployedModels. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: dedicated_resources (google.cloud.aiplatform_v1.types.DedicatedResources): A description of resources that are dedicated to the DeployedModel, and that need a higher degree of manual configuration. + + This field is a member of `oneof`_ ``prediction_resources``. automatic_resources (google.cloud.aiplatform_v1.types.AutomaticResources): A description of resources that to large - degree are decided by AI Platform, and require + degree are decided by Vertex AI, and require only a modest additional configuration. + + This field is a member of `oneof`_ ``prediction_resources``. id (str): - Output only. The ID of the DeployedModel. + Immutable. The ID of the DeployedModel. If not provided upon + deployment, Vertex AI will generate a value for this ID. + + This value should be 1-10 characters, and valid characters + are /[0-9]/. model (str): - Required. The name of the Model that this is - the deployment of. Note that the Model may be in - a different location than the DeployedModel's - Endpoint. + Required. The resource name of the Model that + this is the deployment of. Note that the Model + may be in a different location than the + DeployedModel's Endpoint. + The resource name may contain version id or + version alias to specify the version, if no + version is specified, the default version will + be deployed. + model_version_id (str): + Output only. The version ID of the model that + is deployed. display_name (str): The display name of the DeployedModel. If not provided upon creation, the Model's display_name is used. create_time (google.protobuf.timestamp_pb2.Timestamp): Output only. Timestamp when the DeployedModel was created. + explanation_spec (google.cloud.aiplatform_v1.types.ExplanationSpec): + Explanation configuration for this DeployedModel. + + When deploying a Model using + [EndpointService.DeployModel][google.cloud.aiplatform.v1.EndpointService.DeployModel], + this value overrides the value of + [Model.explanation_spec][google.cloud.aiplatform.v1.Model.explanation_spec]. + All fields of + [explanation_spec][google.cloud.aiplatform.v1.DeployedModel.explanation_spec] + are optional in the request. If a field of + [explanation_spec][google.cloud.aiplatform.v1.DeployedModel.explanation_spec] + is not populated, the value of the same field of + [Model.explanation_spec][google.cloud.aiplatform.v1.Model.explanation_spec] + is inherited. If the corresponding + [Model.explanation_spec][google.cloud.aiplatform.v1.Model.explanation_spec] + is not populated, all fields of the + [explanation_spec][google.cloud.aiplatform.v1.DeployedModel.explanation_spec] + will be used for the explanation configuration. service_account (str): The service account that the DeployedModel's container runs as. Specify the email address of the service account. If @@ -154,6 +285,13 @@ class DeployedModel(proto.Message): requests at a high queries per second rate (QPS). Estimate your costs before enabling this option. + private_endpoints (google.cloud.aiplatform_v1.types.PrivateEndpoints): + Output only. Provide paths for users to send + predict/explain/health requests directly to the deployed + model services running on Cloud via private services access. + This field is populated if + [network][google.cloud.aiplatform.v1.Endpoint.network] is + configured. """ dedicated_resources = proto.Field( @@ -168,13 +306,124 @@ class DeployedModel(proto.Message): oneof="prediction_resources", message=machine_resources.AutomaticResources, ) - id = proto.Field(proto.STRING, number=1,) - model = proto.Field(proto.STRING, number=2,) - display_name = proto.Field(proto.STRING, number=3,) - create_time = proto.Field(proto.MESSAGE, number=6, message=timestamp_pb2.Timestamp,) - service_account = proto.Field(proto.STRING, number=11,) - disable_container_logging = proto.Field(proto.BOOL, number=15,) - enable_access_logging = proto.Field(proto.BOOL, number=13,) + id = proto.Field( + proto.STRING, + number=1, + ) + model = proto.Field( + proto.STRING, + number=2, + ) + model_version_id = proto.Field( + proto.STRING, + number=18, + ) + display_name = proto.Field( + proto.STRING, + number=3, + ) + create_time = proto.Field( + proto.MESSAGE, + number=6, + message=timestamp_pb2.Timestamp, + ) + explanation_spec = proto.Field( + proto.MESSAGE, + number=9, + message=explanation.ExplanationSpec, + ) + service_account = proto.Field( + proto.STRING, + number=11, + ) + disable_container_logging = proto.Field( + proto.BOOL, + number=15, + ) + enable_access_logging = proto.Field( + proto.BOOL, + number=13, + ) + private_endpoints = proto.Field( + proto.MESSAGE, + number=14, + message="PrivateEndpoints", + ) + + +class PrivateEndpoints(proto.Message): + r"""PrivateEndpoints proto is used to provide paths for users to send + requests privately. To send request via private service access, use + predict_http_uri, explain_http_uri or health_http_uri. To send + request via private service connect, use service_attachment. + + Attributes: + predict_http_uri (str): + Output only. Http(s) path to send prediction + requests. + explain_http_uri (str): + Output only. Http(s) path to send explain + requests. + health_http_uri (str): + Output only. Http(s) path to send health + check requests. + service_attachment (str): + Output only. The name of the service + attachment resource. Populated if private + service connect is enabled. + """ + + predict_http_uri = proto.Field( + proto.STRING, + number=1, + ) + explain_http_uri = proto.Field( + proto.STRING, + number=2, + ) + health_http_uri = proto.Field( + proto.STRING, + number=3, + ) + service_attachment = proto.Field( + proto.STRING, + number=4, + ) + + +class PredictRequestResponseLoggingConfig(proto.Message): + r"""Configuration for logging request-response to a BigQuery + table. + + Attributes: + enabled (bool): + If logging is enabled or not. + sampling_rate (float): + Percentage of requests to be logged, expressed as a fraction + in range(0,1]. + bigquery_destination (google.cloud.aiplatform_v1.types.BigQueryDestination): + BigQuery table for logging. If only given a project, a new + dataset will be created with name + ``logging__`` where will + be made BigQuery-dataset-name compatible (e.g. most special + characters will become underscores). If no table name is + given, a new table will be created with name + ``request_response_logging`` + """ + + enabled = proto.Field( + proto.BOOL, + number=1, + ) + sampling_rate = proto.Field( + proto.DOUBLE, + number=2, + ) + bigquery_destination = proto.Field( + proto.MESSAGE, + number=3, + message=io.BigQueryDestination, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/endpoint_service.py b/google/cloud/aiplatform_v1/types/endpoint_service.py index 688336ab71..04a0870e23 100644 --- a/google/cloud/aiplatform_v1/types/endpoint_service.py +++ b/google/cloud/aiplatform_v1/types/endpoint_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -51,10 +51,31 @@ class CreateEndpointRequest(proto.Message): ``projects/{project}/locations/{location}`` endpoint (google.cloud.aiplatform_v1.types.Endpoint): Required. The Endpoint to create. + endpoint_id (str): + Immutable. The ID to use for endpoint, which will become the + final component of the endpoint resource name. If not + provided, Vertex AI will generate a value for this ID. + + This value should be 1-10 characters, and valid characters + are /[0-9]/. When using HTTP/JSON, this field is populated + based on a query string argument, such as + ``?endpoint_id=12345``. This is the fallback for fields that + are not included in either the URI or the body. """ - parent = proto.Field(proto.STRING, number=1,) - endpoint = proto.Field(proto.MESSAGE, number=2, message=gca_endpoint.Endpoint,) + parent = proto.Field( + proto.STRING, + number=1, + ) + endpoint = proto.Field( + proto.MESSAGE, + number=2, + message=gca_endpoint.Endpoint, + ) + endpoint_id = proto.Field( + proto.STRING, + number=4, + ) class CreateEndpointOperationMetadata(proto.Message): @@ -67,7 +88,9 @@ class CreateEndpointOperationMetadata(proto.Message): """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, ) @@ -81,7 +104,10 @@ class GetEndpointRequest(proto.Message): ``projects/{project}/locations/{location}/endpoints/{endpoint}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListEndpointsRequest(proto.Message): @@ -139,12 +165,31 @@ class ListEndpointsRequest(proto.Message): Example: ``display_name, create_time desc``. """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) - read_mask = proto.Field(proto.MESSAGE, number=5, message=field_mask_pb2.FieldMask,) - order_by = proto.Field(proto.STRING, number=6,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=5, + message=field_mask_pb2.FieldMask, + ) + order_by = proto.Field( + proto.STRING, + number=6, + ) class ListEndpointsResponse(proto.Message): @@ -165,9 +210,14 @@ def raw_page(self): return self endpoints = proto.RepeatedField( - proto.MESSAGE, number=1, message=gca_endpoint.Endpoint, + proto.MESSAGE, + number=1, + message=gca_endpoint.Endpoint, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class UpdateEndpointRequest(proto.Message): @@ -180,12 +230,18 @@ class UpdateEndpointRequest(proto.Message): resource on the server. update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. The update mask applies to the resource. See - `FieldMask `__. + [google.protobuf.FieldMask][google.protobuf.FieldMask]. """ - endpoint = proto.Field(proto.MESSAGE, number=1, message=gca_endpoint.Endpoint,) + endpoint = proto.Field( + proto.MESSAGE, + number=1, + message=gca_endpoint.Endpoint, + ) update_mask = proto.Field( - proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, ) @@ -200,7 +256,10 @@ class DeleteEndpointRequest(proto.Message): ``projects/{project}/locations/{location}/endpoints/{endpoint}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class DeployModelRequest(proto.Message): @@ -219,7 +278,7 @@ class DeployModelRequest(proto.Message): must be updated for the DeployedModel to start receiving traffic, either as part of this call, or via [EndpointService.UpdateEndpoint][google.cloud.aiplatform.v1.EndpointService.UpdateEndpoint]. - traffic_split (Sequence[google.cloud.aiplatform_v1.types.DeployModelRequest.TrafficSplitEntry]): + traffic_split (Mapping[str, int]): A map from a DeployedModel's ID to the percentage of this Endpoint's traffic that should be forwarded to that DeployedModel. @@ -237,11 +296,20 @@ class DeployModelRequest(proto.Message): is not updated. """ - endpoint = proto.Field(proto.STRING, number=1,) + endpoint = proto.Field( + proto.STRING, + number=1, + ) deployed_model = proto.Field( - proto.MESSAGE, number=2, message=gca_endpoint.DeployedModel, + proto.MESSAGE, + number=2, + message=gca_endpoint.DeployedModel, + ) + traffic_split = proto.MapField( + proto.STRING, + proto.INT32, + number=3, ) - traffic_split = proto.MapField(proto.STRING, proto.INT32, number=3,) class DeployModelResponse(proto.Message): @@ -255,7 +323,9 @@ class DeployModelResponse(proto.Message): """ deployed_model = proto.Field( - proto.MESSAGE, number=1, message=gca_endpoint.DeployedModel, + proto.MESSAGE, + number=1, + message=gca_endpoint.DeployedModel, ) @@ -269,7 +339,9 @@ class DeployModelOperationMetadata(proto.Message): """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, ) @@ -285,7 +357,7 @@ class UndeployModelRequest(proto.Message): deployed_model_id (str): Required. The ID of the DeployedModel to be undeployed from the Endpoint. - traffic_split (Sequence[google.cloud.aiplatform_v1.types.UndeployModelRequest.TrafficSplitEntry]): + traffic_split (Mapping[str, int]): If this field is provided, then the Endpoint's [traffic_split][google.cloud.aiplatform.v1.Endpoint.traffic_split] will be overwritten with it. If last DeployedModel is being @@ -296,15 +368,26 @@ class UndeployModelRequest(proto.Message): executes, or if this field unassigns any traffic to it. """ - endpoint = proto.Field(proto.STRING, number=1,) - deployed_model_id = proto.Field(proto.STRING, number=2,) - traffic_split = proto.MapField(proto.STRING, proto.INT32, number=3,) + endpoint = proto.Field( + proto.STRING, + number=1, + ) + deployed_model_id = proto.Field( + proto.STRING, + number=2, + ) + traffic_split = proto.MapField( + proto.STRING, + proto.INT32, + number=3, + ) class UndeployModelResponse(proto.Message): r"""Response message for [EndpointService.UndeployModel][google.cloud.aiplatform.v1.EndpointService.UndeployModel]. - """ + + """ class UndeployModelOperationMetadata(proto.Message): @@ -317,7 +400,9 @@ class UndeployModelOperationMetadata(proto.Message): """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, ) diff --git a/google/cloud/aiplatform_v1/types/entity_type.py b/google/cloud/aiplatform_v1/types/entity_type.py new file mode 100644 index 0000000000..7b30f812b8 --- /dev/null +++ b/google/cloud/aiplatform_v1/types/entity_type.py @@ -0,0 +1,118 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + +from google.cloud.aiplatform_v1.types import featurestore_monitoring +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "EntityType", + }, +) + + +class EntityType(proto.Message): + r"""An entity type is a type of object in a system that needs to + be modeled and have stored information about. For example, + driver is an entity type, and driver0 is an instance of an + entity type driver. + + Attributes: + name (str): + Immutable. Name of the EntityType. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}`` + + The last part entity_type is assigned by the client. The + entity_type can be up to 64 characters long and can consist + only of ASCII Latin letters A-Z and a-z and underscore(_), + and ASCII digits 0-9 starting with a letter. The value will + be unique given a featurestore. + description (str): + Optional. Description of the EntityType. + create_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp when this EntityType + was created. + update_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp when this EntityType + was most recently updated. + labels (Mapping[str, str]): + Optional. The labels with user-defined + metadata to organize your EntityTypes. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + on and examples of labels. No more than 64 user + labels can be associated with one EntityType + (System labels are excluded)." + System reserved label keys are prefixed with + "aiplatform.googleapis.com/" and are immutable. + etag (str): + Optional. Used to perform a consistent + read-modify-write updates. If not set, a blind + "overwrite" update happens. + monitoring_config (google.cloud.aiplatform_v1.types.FeaturestoreMonitoringConfig): + Optional. The default monitoring configuration for all + Features with value type + ([Feature.ValueType][google.cloud.aiplatform.v1.Feature.ValueType]) + BOOL, STRING, DOUBLE or INT64 under this EntityType. + + If this is populated with + [FeaturestoreMonitoringConfig.monitoring_interval] + specified, snapshot analysis monitoring is enabled. + Otherwise, snapshot analysis monitoring is disabled. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + description = proto.Field( + proto.STRING, + number=2, + ) + create_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=6, + ) + etag = proto.Field( + proto.STRING, + number=7, + ) + monitoring_config = proto.Field( + proto.MESSAGE, + number=8, + message=featurestore_monitoring.FeaturestoreMonitoringConfig, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/env_var.py b/google/cloud/aiplatform_v1/types/env_var.py index 8c6160b49f..d7c6c88365 100644 --- a/google/cloud/aiplatform_v1/types/env_var.py +++ b/google/cloud/aiplatform_v1/types/env_var.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,7 +16,12 @@ import proto # type: ignore -__protobuf__ = proto.module(package="google.cloud.aiplatform.v1", manifest={"EnvVar",},) +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "EnvVar", + }, +) class EnvVar(proto.Message): @@ -38,8 +43,14 @@ class EnvVar(proto.Message): variable exists or not. """ - name = proto.Field(proto.STRING, number=1,) - value = proto.Field(proto.STRING, number=2,) + name = proto.Field( + proto.STRING, + number=1, + ) + value = proto.Field( + proto.STRING, + number=2, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/event.py b/google/cloud/aiplatform_v1/types/event.py new file mode 100644 index 0000000000..89e76ae748 --- /dev/null +++ b/google/cloud/aiplatform_v1/types/event.py @@ -0,0 +1,94 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "Event", + }, +) + + +class Event(proto.Message): + r"""An edge describing the relationship between an Artifact and + an Execution in a lineage graph. + + Attributes: + artifact (str): + Required. The relative resource name of the + Artifact in the Event. + execution (str): + Output only. The relative resource name of + the Execution in the Event. + event_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Time the Event occurred. + type_ (google.cloud.aiplatform_v1.types.Event.Type): + Required. The type of the Event. + labels (Mapping[str, str]): + The labels with user-defined metadata to + annotate Events. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. No more than 64 user labels can be + associated with one Event (System labels are + excluded). + + See https://goo.gl/xmQnxf for more information + and examples of labels. System reserved label + keys are prefixed with + "aiplatform.googleapis.com/" and are immutable. + """ + + class Type(proto.Enum): + r"""Describes whether an Event's Artifact is the Execution's + input or output. + """ + TYPE_UNSPECIFIED = 0 + INPUT = 1 + OUTPUT = 2 + + artifact = proto.Field( + proto.STRING, + number=1, + ) + execution = proto.Field( + proto.STRING, + number=2, + ) + event_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + type_ = proto.Field( + proto.ENUM, + number=4, + enum=Type, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=5, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/execution.py b/google/cloud/aiplatform_v1/types/execution.py new file mode 100644 index 0000000000..9d157b8ba2 --- /dev/null +++ b/google/cloud/aiplatform_v1/types/execution.py @@ -0,0 +1,150 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + +from google.protobuf import struct_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "Execution", + }, +) + + +class Execution(proto.Message): + r"""Instance of a general execution. + + Attributes: + name (str): + Output only. The resource name of the + Execution. + display_name (str): + User provided display name of the Execution. + May be up to 128 Unicode characters. + state (google.cloud.aiplatform_v1.types.Execution.State): + The state of this Execution. This is a + property of the Execution, and does not imply or + capture any ongoing process. This property is + managed by clients (such as Vertex AI Pipelines) + and the system does not prescribe or check the + validity of state transitions. + etag (str): + An eTag used to perform consistent + read-modify-write updates. If not set, a blind + "overwrite" update happens. + labels (Mapping[str, str]): + The labels with user-defined metadata to + organize your Executions. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. No more than 64 user labels can be + associated with one Execution (System labels are + excluded). + create_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp when this Execution + was created. + update_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp when this Execution + was last updated. + schema_title (str): + The title of the schema describing the + metadata. + Schema title and version is expected to be + registered in earlier Create Schema calls. And + both are used together as unique identifiers to + identify schemas within the local metadata + store. + schema_version (str): + The version of the schema in ``schema_title`` to use. + + Schema title and version is expected to be registered in + earlier Create Schema calls. And both are used together as + unique identifiers to identify schemas within the local + metadata store. + metadata (google.protobuf.struct_pb2.Struct): + Properties of the Execution. + The size of this field should not exceed 200KB. + description (str): + Description of the Execution + """ + + class State(proto.Enum): + r"""Describes the state of the Execution.""" + STATE_UNSPECIFIED = 0 + NEW = 1 + RUNNING = 2 + COMPLETE = 3 + FAILED = 4 + CACHED = 5 + CANCELLED = 6 + + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + state = proto.Field( + proto.ENUM, + number=6, + enum=State, + ) + etag = proto.Field( + proto.STRING, + number=9, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=10, + ) + create_time = proto.Field( + proto.MESSAGE, + number=11, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=12, + message=timestamp_pb2.Timestamp, + ) + schema_title = proto.Field( + proto.STRING, + number=13, + ) + schema_version = proto.Field( + proto.STRING, + number=14, + ) + metadata = proto.Field( + proto.MESSAGE, + number=15, + message=struct_pb2.Struct, + ) + description = proto.Field( + proto.STRING, + number=16, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/explanation.py b/google/cloud/aiplatform_v1/types/explanation.py new file mode 100644 index 0000000000..22ceae1252 --- /dev/null +++ b/google/cloud/aiplatform_v1/types/explanation.py @@ -0,0 +1,839 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + +from google.cloud.aiplatform_v1.types import explanation_metadata +from google.protobuf import struct_pb2 # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "Explanation", + "ModelExplanation", + "Attribution", + "Neighbor", + "ExplanationSpec", + "ExplanationParameters", + "SampledShapleyAttribution", + "IntegratedGradientsAttribution", + "XraiAttribution", + "SmoothGradConfig", + "FeatureNoiseSigma", + "BlurBaselineConfig", + "ExplanationSpecOverride", + "ExplanationMetadataOverride", + "ExamplesOverride", + "ExamplesRestrictionsNamespace", + }, +) + + +class Explanation(proto.Message): + r"""Explanation of a prediction (provided in + [PredictResponse.predictions][google.cloud.aiplatform.v1.PredictResponse.predictions]) + produced by the Model on a given + [instance][google.cloud.aiplatform.v1.ExplainRequest.instances]. + + Attributes: + attributions (Sequence[google.cloud.aiplatform_v1.types.Attribution]): + Output only. Feature attributions grouped by predicted + outputs. + + For Models that predict only one output, such as regression + Models that predict only one score, there is only one + attibution that explains the predicted output. For Models + that predict multiple outputs, such as multiclass Models + that predict multiple classes, each element explains one + specific item. + [Attribution.output_index][google.cloud.aiplatform.v1.Attribution.output_index] + can be used to identify which output this attribution is + explaining. + + If users set + [ExplanationParameters.top_k][google.cloud.aiplatform.v1.ExplanationParameters.top_k], + the attributions are sorted by + [instance_output_value][Attributions.instance_output_value] + in descending order. If + [ExplanationParameters.output_indices][google.cloud.aiplatform.v1.ExplanationParameters.output_indices] + is specified, the attributions are stored by + [Attribution.output_index][google.cloud.aiplatform.v1.Attribution.output_index] + in the same order as they appear in the output_indices. + neighbors (Sequence[google.cloud.aiplatform_v1.types.Neighbor]): + Output only. List of the nearest neighbors + for example-based explanations. + For models deployed with the examples + explanations feature enabled, the attributions + field is empty and instead the neighbors field + is populated. + """ + + attributions = proto.RepeatedField( + proto.MESSAGE, + number=1, + message="Attribution", + ) + neighbors = proto.RepeatedField( + proto.MESSAGE, + number=2, + message="Neighbor", + ) + + +class ModelExplanation(proto.Message): + r"""Aggregated explanation metrics for a Model over a set of + instances. + + Attributes: + mean_attributions (Sequence[google.cloud.aiplatform_v1.types.Attribution]): + Output only. Aggregated attributions explaining the Model's + prediction outputs over the set of instances. The + attributions are grouped by outputs. + + For Models that predict only one output, such as regression + Models that predict only one score, there is only one + attibution that explains the predicted output. For Models + that predict multiple outputs, such as multiclass Models + that predict multiple classes, each element explains one + specific item. + [Attribution.output_index][google.cloud.aiplatform.v1.Attribution.output_index] + can be used to identify which output this attribution is + explaining. + + The + [baselineOutputValue][google.cloud.aiplatform.v1.Attribution.baseline_output_value], + [instanceOutputValue][google.cloud.aiplatform.v1.Attribution.instance_output_value] + and + [featureAttributions][google.cloud.aiplatform.v1.Attribution.feature_attributions] + fields are averaged over the test data. + + NOTE: Currently AutoML tabular classification Models produce + only one attribution, which averages attributions over all + the classes it predicts. + [Attribution.approximation_error][google.cloud.aiplatform.v1.Attribution.approximation_error] + is not populated. + """ + + mean_attributions = proto.RepeatedField( + proto.MESSAGE, + number=1, + message="Attribution", + ) + + +class Attribution(proto.Message): + r"""Attribution that explains a particular prediction output. + + Attributes: + baseline_output_value (float): + Output only. Model predicted output if the input instance is + constructed from the baselines of all the features defined + in + [ExplanationMetadata.inputs][google.cloud.aiplatform.v1.ExplanationMetadata.inputs]. + The field name of the output is determined by the key in + [ExplanationMetadata.outputs][google.cloud.aiplatform.v1.ExplanationMetadata.outputs]. + + If the Model's predicted output has multiple dimensions + (rank > 1), this is the value in the output located by + [output_index][google.cloud.aiplatform.v1.Attribution.output_index]. + + If there are multiple baselines, their output values are + averaged. + instance_output_value (float): + Output only. Model predicted output on the corresponding + [explanation instance][ExplainRequest.instances]. The field + name of the output is determined by the key in + [ExplanationMetadata.outputs][google.cloud.aiplatform.v1.ExplanationMetadata.outputs]. + + If the Model predicted output has multiple dimensions, this + is the value in the output located by + [output_index][google.cloud.aiplatform.v1.Attribution.output_index]. + feature_attributions (google.protobuf.struct_pb2.Value): + Output only. Attributions of each explained feature. + Features are extracted from the [prediction + instances][google.cloud.aiplatform.v1.ExplainRequest.instances] + according to [explanation metadata for + inputs][google.cloud.aiplatform.v1.ExplanationMetadata.inputs]. + + The value is a struct, whose keys are the name of the + feature. The values are how much the feature in the + [instance][google.cloud.aiplatform.v1.ExplainRequest.instances] + contributed to the predicted result. + + The format of the value is determined by the feature's input + format: + + - If the feature is a scalar value, the attribution value + is a [floating + number][google.protobuf.Value.number_value]. + + - If the feature is an array of scalar values, the + attribution value is an + [array][google.protobuf.Value.list_value]. + + - If the feature is a struct, the attribution value is a + [struct][google.protobuf.Value.struct_value]. The keys in + the attribution value struct are the same as the keys in + the feature struct. The formats of the values in the + attribution struct are determined by the formats of the + values in the feature struct. + + The + [ExplanationMetadata.feature_attributions_schema_uri][google.cloud.aiplatform.v1.ExplanationMetadata.feature_attributions_schema_uri] + field, pointed to by the + [ExplanationSpec][google.cloud.aiplatform.v1.ExplanationSpec] + field of the + [Endpoint.deployed_models][google.cloud.aiplatform.v1.Endpoint.deployed_models] + object, points to the schema file that describes the + features and their attribution values (if it is populated). + output_index (Sequence[int]): + Output only. The index that locates the explained prediction + output. + + If the prediction output is a scalar value, output_index is + not populated. If the prediction output has multiple + dimensions, the length of the output_index list is the same + as the number of dimensions of the output. The i-th element + in output_index is the element index of the i-th dimension + of the output vector. Indices start from 0. + output_display_name (str): + Output only. The display name of the output identified by + [output_index][google.cloud.aiplatform.v1.Attribution.output_index]. + For example, the predicted class name by a + multi-classification Model. + + This field is only populated iff the Model predicts display + names as a separate field along with the explained output. + The predicted display name must has the same shape of the + explained output, and can be located using output_index. + approximation_error (float): + Output only. Error of + [feature_attributions][google.cloud.aiplatform.v1.Attribution.feature_attributions] + caused by approximation used in the explanation method. + Lower value means more precise attributions. + + - For Sampled Shapley + [attribution][google.cloud.aiplatform.v1.ExplanationParameters.sampled_shapley_attribution], + increasing + [path_count][google.cloud.aiplatform.v1.SampledShapleyAttribution.path_count] + might reduce the error. + - For Integrated Gradients + [attribution][google.cloud.aiplatform.v1.ExplanationParameters.integrated_gradients_attribution], + increasing + [step_count][google.cloud.aiplatform.v1.IntegratedGradientsAttribution.step_count] + might reduce the error. + - For [XRAI + attribution][google.cloud.aiplatform.v1.ExplanationParameters.xrai_attribution], + increasing + [step_count][google.cloud.aiplatform.v1.XraiAttribution.step_count] + might reduce the error. + + See `this + introduction `__ + for more information. + output_name (str): + Output only. Name of the explain output. Specified as the + key in + [ExplanationMetadata.outputs][google.cloud.aiplatform.v1.ExplanationMetadata.outputs]. + """ + + baseline_output_value = proto.Field( + proto.DOUBLE, + number=1, + ) + instance_output_value = proto.Field( + proto.DOUBLE, + number=2, + ) + feature_attributions = proto.Field( + proto.MESSAGE, + number=3, + message=struct_pb2.Value, + ) + output_index = proto.RepeatedField( + proto.INT32, + number=4, + ) + output_display_name = proto.Field( + proto.STRING, + number=5, + ) + approximation_error = proto.Field( + proto.DOUBLE, + number=6, + ) + output_name = proto.Field( + proto.STRING, + number=7, + ) + + +class Neighbor(proto.Message): + r"""Neighbors for example-based explanations. + + Attributes: + neighbor_id (str): + Output only. The neighbor id. + neighbor_distance (float): + Output only. The neighbor distance. + """ + + neighbor_id = proto.Field( + proto.STRING, + number=1, + ) + neighbor_distance = proto.Field( + proto.DOUBLE, + number=2, + ) + + +class ExplanationSpec(proto.Message): + r"""Specification of Model explanation. + + Attributes: + parameters (google.cloud.aiplatform_v1.types.ExplanationParameters): + Required. Parameters that configure + explaining of the Model's predictions. + metadata (google.cloud.aiplatform_v1.types.ExplanationMetadata): + Required. Metadata describing the Model's + input and output for explanation. + """ + + parameters = proto.Field( + proto.MESSAGE, + number=1, + message="ExplanationParameters", + ) + metadata = proto.Field( + proto.MESSAGE, + number=2, + message=explanation_metadata.ExplanationMetadata, + ) + + +class ExplanationParameters(proto.Message): + r"""Parameters to configure explaining for Model's predictions. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + sampled_shapley_attribution (google.cloud.aiplatform_v1.types.SampledShapleyAttribution): + An attribution method that approximates + Shapley values for features that contribute to + the label being predicted. A sampling strategy + is used to approximate the value rather than + considering all subsets of features. Refer to + this paper for model details: + https://arxiv.org/abs/1306.4265. + + This field is a member of `oneof`_ ``method``. + integrated_gradients_attribution (google.cloud.aiplatform_v1.types.IntegratedGradientsAttribution): + An attribution method that computes + Aumann-Shapley values taking advantage of the + model's fully differentiable structure. Refer to + this paper for more details: + https://arxiv.org/abs/1703.01365 + + This field is a member of `oneof`_ ``method``. + xrai_attribution (google.cloud.aiplatform_v1.types.XraiAttribution): + An attribution method that redistributes + Integrated Gradients attribution to segmented + regions, taking advantage of the model's fully + differentiable structure. Refer to this paper + for more details: + https://arxiv.org/abs/1906.02825 + XRAI currently performs better on natural + images, like a picture of a house or an animal. + If the images are taken in artificial + environments, like a lab or manufacturing line, + or from diagnostic equipment, like x-rays or + quality-control cameras, use Integrated + Gradients instead. + + This field is a member of `oneof`_ ``method``. + top_k (int): + If populated, returns attributions for top K + indices of outputs (defaults to 1). Only applies + to Models that predicts more than one outputs + (e,g, multi-class Models). When set to -1, + returns explanations for all outputs. + output_indices (google.protobuf.struct_pb2.ListValue): + If populated, only returns attributions that have + [output_index][google.cloud.aiplatform.v1.Attribution.output_index] + contained in output_indices. It must be an ndarray of + integers, with the same shape of the output it's explaining. + + If not populated, returns attributions for + [top_k][google.cloud.aiplatform.v1.ExplanationParameters.top_k] + indices of outputs. If neither top_k nor output_indeices is + populated, returns the argmax index of the outputs. + + Only applicable to Models that predict multiple outputs + (e,g, multi-class Models that predict multiple classes). + """ + + sampled_shapley_attribution = proto.Field( + proto.MESSAGE, + number=1, + oneof="method", + message="SampledShapleyAttribution", + ) + integrated_gradients_attribution = proto.Field( + proto.MESSAGE, + number=2, + oneof="method", + message="IntegratedGradientsAttribution", + ) + xrai_attribution = proto.Field( + proto.MESSAGE, + number=3, + oneof="method", + message="XraiAttribution", + ) + top_k = proto.Field( + proto.INT32, + number=4, + ) + output_indices = proto.Field( + proto.MESSAGE, + number=5, + message=struct_pb2.ListValue, + ) + + +class SampledShapleyAttribution(proto.Message): + r"""An attribution method that approximates Shapley values for + features that contribute to the label being predicted. A + sampling strategy is used to approximate the value rather than + considering all subsets of features. + + Attributes: + path_count (int): + Required. The number of feature permutations to consider + when approximating the Shapley values. + + Valid range of its value is [1, 50], inclusively. + """ + + path_count = proto.Field( + proto.INT32, + number=1, + ) + + +class IntegratedGradientsAttribution(proto.Message): + r"""An attribution method that computes the Aumann-Shapley value + taking advantage of the model's fully differentiable structure. + Refer to this paper for more details: + https://arxiv.org/abs/1703.01365 + + Attributes: + step_count (int): + Required. The number of steps for approximating the path + integral. A good value to start is 50 and gradually increase + until the sum to diff property is within the desired error + range. + + Valid range of its value is [1, 100], inclusively. + smooth_grad_config (google.cloud.aiplatform_v1.types.SmoothGradConfig): + Config for SmoothGrad approximation of + gradients. + When enabled, the gradients are approximated by + averaging the gradients from noisy samples in + the vicinity of the inputs. Adding noise can + help improve the computed gradients. Refer to + this paper for more details: + https://arxiv.org/pdf/1706.03825.pdf + blur_baseline_config (google.cloud.aiplatform_v1.types.BlurBaselineConfig): + Config for IG with blur baseline. + When enabled, a linear path from the maximally + blurred image to the input image is created. + Using a blurred baseline instead of zero (black + image) is motivated by the BlurIG approach + explained here: https://arxiv.org/abs/2004.03383 + """ + + step_count = proto.Field( + proto.INT32, + number=1, + ) + smooth_grad_config = proto.Field( + proto.MESSAGE, + number=2, + message="SmoothGradConfig", + ) + blur_baseline_config = proto.Field( + proto.MESSAGE, + number=3, + message="BlurBaselineConfig", + ) + + +class XraiAttribution(proto.Message): + r"""An explanation method that redistributes Integrated Gradients + attributions to segmented regions, taking advantage of the + model's fully differentiable structure. Refer to this paper for + more details: https://arxiv.org/abs/1906.02825 + + Supported only by image Models. + + Attributes: + step_count (int): + Required. The number of steps for approximating the path + integral. A good value to start is 50 and gradually increase + until the sum to diff property is met within the desired + error range. + + Valid range of its value is [1, 100], inclusively. + smooth_grad_config (google.cloud.aiplatform_v1.types.SmoothGradConfig): + Config for SmoothGrad approximation of + gradients. + When enabled, the gradients are approximated by + averaging the gradients from noisy samples in + the vicinity of the inputs. Adding noise can + help improve the computed gradients. Refer to + this paper for more details: + https://arxiv.org/pdf/1706.03825.pdf + blur_baseline_config (google.cloud.aiplatform_v1.types.BlurBaselineConfig): + Config for XRAI with blur baseline. + When enabled, a linear path from the maximally + blurred image to the input image is created. + Using a blurred baseline instead of zero (black + image) is motivated by the BlurIG approach + explained here: https://arxiv.org/abs/2004.03383 + """ + + step_count = proto.Field( + proto.INT32, + number=1, + ) + smooth_grad_config = proto.Field( + proto.MESSAGE, + number=2, + message="SmoothGradConfig", + ) + blur_baseline_config = proto.Field( + proto.MESSAGE, + number=3, + message="BlurBaselineConfig", + ) + + +class SmoothGradConfig(proto.Message): + r"""Config for SmoothGrad approximation of gradients. + When enabled, the gradients are approximated by averaging the + gradients from noisy samples in the vicinity of the inputs. + Adding noise can help improve the computed gradients. Refer to + this paper for more details: + https://arxiv.org/pdf/1706.03825.pdf + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + noise_sigma (float): + This is a single float value and will be used to add noise + to all the features. Use this field when all features are + normalized to have the same distribution: scale to range [0, + 1], [-1, 1] or z-scoring, where features are normalized to + have 0-mean and 1-variance. Learn more about + `normalization `__. + + For best results the recommended value is about 10% - 20% of + the standard deviation of the input feature. Refer to + section 3.2 of the SmoothGrad paper: + https://arxiv.org/pdf/1706.03825.pdf. Defaults to 0.1. + + If the distribution is different per feature, set + [feature_noise_sigma][google.cloud.aiplatform.v1.SmoothGradConfig.feature_noise_sigma] + instead for each feature. + + This field is a member of `oneof`_ ``GradientNoiseSigma``. + feature_noise_sigma (google.cloud.aiplatform_v1.types.FeatureNoiseSigma): + This is similar to + [noise_sigma][google.cloud.aiplatform.v1.SmoothGradConfig.noise_sigma], + but provides additional flexibility. A separate noise sigma + can be provided for each feature, which is useful if their + distributions are different. No noise is added to features + that are not set. If this field is unset, + [noise_sigma][google.cloud.aiplatform.v1.SmoothGradConfig.noise_sigma] + will be used for all features. + + This field is a member of `oneof`_ ``GradientNoiseSigma``. + noisy_sample_count (int): + The number of gradient samples to use for approximation. The + higher this number, the more accurate the gradient is, but + the runtime complexity increases by this factor as well. + Valid range of its value is [1, 50]. Defaults to 3. + """ + + noise_sigma = proto.Field( + proto.FLOAT, + number=1, + oneof="GradientNoiseSigma", + ) + feature_noise_sigma = proto.Field( + proto.MESSAGE, + number=2, + oneof="GradientNoiseSigma", + message="FeatureNoiseSigma", + ) + noisy_sample_count = proto.Field( + proto.INT32, + number=3, + ) + + +class FeatureNoiseSigma(proto.Message): + r"""Noise sigma by features. Noise sigma represents the standard + deviation of the gaussian kernel that will be used to add noise + to interpolated inputs prior to computing gradients. + + Attributes: + noise_sigma (Sequence[google.cloud.aiplatform_v1.types.FeatureNoiseSigma.NoiseSigmaForFeature]): + Noise sigma per feature. No noise is added to + features that are not set. + """ + + class NoiseSigmaForFeature(proto.Message): + r"""Noise sigma for a single feature. + + Attributes: + name (str): + The name of the input feature for which noise sigma is + provided. The features are defined in [explanation metadata + inputs][google.cloud.aiplatform.v1.ExplanationMetadata.inputs]. + sigma (float): + This represents the standard deviation of the Gaussian + kernel that will be used to add noise to the feature prior + to computing gradients. Similar to + [noise_sigma][google.cloud.aiplatform.v1.SmoothGradConfig.noise_sigma] + but represents the noise added to the current feature. + Defaults to 0.1. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + sigma = proto.Field( + proto.FLOAT, + number=2, + ) + + noise_sigma = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=NoiseSigmaForFeature, + ) + + +class BlurBaselineConfig(proto.Message): + r"""Config for blur baseline. + When enabled, a linear path from the maximally blurred image to + the input image is created. Using a blurred baseline instead of + zero (black image) is motivated by the BlurIG approach explained + here: + https://arxiv.org/abs/2004.03383 + + Attributes: + max_blur_sigma (float): + The standard deviation of the blur kernel for + the blurred baseline. The same blurring + parameter is used for both the height and the + width dimension. If not set, the method defaults + to the zero (i.e. black for images) baseline. + """ + + max_blur_sigma = proto.Field( + proto.FLOAT, + number=1, + ) + + +class ExplanationSpecOverride(proto.Message): + r"""The [ExplanationSpec][google.cloud.aiplatform.v1.ExplanationSpec] + entries that can be overridden at [online + explanation][google.cloud.aiplatform.v1.PredictionService.Explain] + time. + + Attributes: + parameters (google.cloud.aiplatform_v1.types.ExplanationParameters): + The parameters to be overridden. Note that the + [method][google.cloud.aiplatform.v1.ExplanationParameters.method] + cannot be changed. If not specified, no parameter is + overridden. + metadata (google.cloud.aiplatform_v1.types.ExplanationMetadataOverride): + The metadata to be overridden. If not + specified, no metadata is overridden. + examples_override (google.cloud.aiplatform_v1.types.ExamplesOverride): + The example-based explanations parameter + overrides. + """ + + parameters = proto.Field( + proto.MESSAGE, + number=1, + message="ExplanationParameters", + ) + metadata = proto.Field( + proto.MESSAGE, + number=2, + message="ExplanationMetadataOverride", + ) + examples_override = proto.Field( + proto.MESSAGE, + number=3, + message="ExamplesOverride", + ) + + +class ExplanationMetadataOverride(proto.Message): + r"""The + [ExplanationMetadata][google.cloud.aiplatform.v1.ExplanationMetadata] + entries that can be overridden at [online + explanation][google.cloud.aiplatform.v1.PredictionService.Explain] + time. + + Attributes: + inputs (Mapping[str, google.cloud.aiplatform_v1.types.ExplanationMetadataOverride.InputMetadataOverride]): + Required. Overrides the [input + metadata][google.cloud.aiplatform.v1.ExplanationMetadata.inputs] + of the features. The key is the name of the feature to be + overridden. The keys specified here must exist in the input + metadata to be overridden. If a feature is not specified + here, the corresponding feature's input metadata is not + overridden. + """ + + class InputMetadataOverride(proto.Message): + r"""The [input + metadata][google.cloud.aiplatform.v1.ExplanationMetadata.InputMetadata] + entries to be overridden. + + Attributes: + input_baselines (Sequence[google.protobuf.struct_pb2.Value]): + Baseline inputs for this feature. + + This overrides the ``input_baseline`` field of the + [ExplanationMetadata.InputMetadata][google.cloud.aiplatform.v1.ExplanationMetadata.InputMetadata] + object of the corresponding feature's input metadata. If + it's not specified, the original baselines are not + overridden. + """ + + input_baselines = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=struct_pb2.Value, + ) + + inputs = proto.MapField( + proto.STRING, + proto.MESSAGE, + number=1, + message=InputMetadataOverride, + ) + + +class ExamplesOverride(proto.Message): + r"""Overrides for example-based explanations. + + Attributes: + neighbor_count (int): + The number of neighbors to return. + crowding_count (int): + The number of neighbors to return that have + the same crowding tag. + restrictions (Sequence[google.cloud.aiplatform_v1.types.ExamplesRestrictionsNamespace]): + Restrict the resulting nearest neighbors to + respect these constraints. + return_embeddings (bool): + If true, return the embeddings instead of + neighbors. + data_format (google.cloud.aiplatform_v1.types.ExamplesOverride.DataFormat): + The format of the data being provided with + each call. + """ + + class DataFormat(proto.Enum): + r"""Data format enum.""" + DATA_FORMAT_UNSPECIFIED = 0 + INSTANCES = 1 + EMBEDDINGS = 2 + + neighbor_count = proto.Field( + proto.INT32, + number=1, + ) + crowding_count = proto.Field( + proto.INT32, + number=2, + ) + restrictions = proto.RepeatedField( + proto.MESSAGE, + number=3, + message="ExamplesRestrictionsNamespace", + ) + return_embeddings = proto.Field( + proto.BOOL, + number=4, + ) + data_format = proto.Field( + proto.ENUM, + number=5, + enum=DataFormat, + ) + + +class ExamplesRestrictionsNamespace(proto.Message): + r"""Restrictions namespace for example-based explanations + overrides. + + Attributes: + namespace_name (str): + The namespace name. + allow (Sequence[str]): + The list of allowed tags. + deny (Sequence[str]): + The list of deny tags. + """ + + namespace_name = proto.Field( + proto.STRING, + number=1, + ) + allow = proto.RepeatedField( + proto.STRING, + number=2, + ) + deny = proto.RepeatedField( + proto.STRING, + number=3, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/explanation_metadata.py b/google/cloud/aiplatform_v1/types/explanation_metadata.py new file mode 100644 index 0000000000..5d9dcca392 --- /dev/null +++ b/google/cloud/aiplatform_v1/types/explanation_metadata.py @@ -0,0 +1,469 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + +from google.protobuf import struct_pb2 # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "ExplanationMetadata", + }, +) + + +class ExplanationMetadata(proto.Message): + r"""Metadata describing the Model's input and output for + explanation. + + Attributes: + inputs (Mapping[str, google.cloud.aiplatform_v1.types.ExplanationMetadata.InputMetadata]): + Required. Map from feature names to feature input metadata. + Keys are the name of the features. Values are the + specification of the feature. + + An empty InputMetadata is valid. It describes a text feature + which has the name specified as the key in + [ExplanationMetadata.inputs][google.cloud.aiplatform.v1.ExplanationMetadata.inputs]. + The baseline of the empty feature is chosen by Vertex AI. + + For Vertex AI-provided Tensorflow images, the key can be any + friendly name of the feature. Once specified, + [featureAttributions][google.cloud.aiplatform.v1.Attribution.feature_attributions] + are keyed by this key (if not grouped with another feature). + + For custom images, the key must match with the key in + [instance][google.cloud.aiplatform.v1.ExplainRequest.instances]. + outputs (Mapping[str, google.cloud.aiplatform_v1.types.ExplanationMetadata.OutputMetadata]): + Required. Map from output names to output + metadata. + For Vertex AI-provided Tensorflow images, keys + can be any user defined string that consists of + any UTF-8 characters. + For custom images, keys are the name of the + output field in the prediction to be explained. + + Currently only one key is allowed. + feature_attributions_schema_uri (str): + Points to a YAML file stored on Google Cloud Storage + describing the format of the [feature + attributions][google.cloud.aiplatform.v1.Attribution.feature_attributions]. + The schema is defined as an OpenAPI 3.0.2 `Schema + Object `__. + AutoML tabular Models always have this field populated by + Vertex AI. Note: The URI given on output may be different, + including the URI scheme, than the one given on input. The + output URI will point to a location where the user only has + a read access. + latent_space_source (str): + Name of the source to generate embeddings for + example based explanations. + """ + + class InputMetadata(proto.Message): + r"""Metadata of the input of a feature. + + Fields other than + [InputMetadata.input_baselines][google.cloud.aiplatform.v1.ExplanationMetadata.InputMetadata.input_baselines] + are applicable only for Models that are using Vertex AI-provided + images for Tensorflow. + + Attributes: + input_baselines (Sequence[google.protobuf.struct_pb2.Value]): + Baseline inputs for this feature. + + If no baseline is specified, Vertex AI chooses the baseline + for this feature. If multiple baselines are specified, + Vertex AI returns the average attributions across them in + [Attribution.feature_attributions][google.cloud.aiplatform.v1.Attribution.feature_attributions]. + + For Vertex AI-provided Tensorflow images (both 1.x and 2.x), + the shape of each baseline must match the shape of the input + tensor. If a scalar is provided, we broadcast to the same + shape as the input tensor. + + For custom images, the element of the baselines must be in + the same format as the feature's input in the + [instance][google.cloud.aiplatform.v1.ExplainRequest.instances][]. + The schema of any single instance may be specified via + Endpoint's DeployedModels' + [Model's][google.cloud.aiplatform.v1.DeployedModel.model] + [PredictSchemata's][google.cloud.aiplatform.v1.Model.predict_schemata] + [instance_schema_uri][google.cloud.aiplatform.v1.PredictSchemata.instance_schema_uri]. + input_tensor_name (str): + Name of the input tensor for this feature. + Required and is only applicable to Vertex + AI-provided images for Tensorflow. + encoding (google.cloud.aiplatform_v1.types.ExplanationMetadata.InputMetadata.Encoding): + Defines how the feature is encoded into the + input tensor. Defaults to IDENTITY. + modality (str): + Modality of the feature. Valid values are: + numeric, image. Defaults to numeric. + feature_value_domain (google.cloud.aiplatform_v1.types.ExplanationMetadata.InputMetadata.FeatureValueDomain): + The domain details of the input feature + value. Like min/max, original mean or standard + deviation if normalized. + indices_tensor_name (str): + Specifies the index of the values of the input tensor. + Required when the input tensor is a sparse representation. + Refer to Tensorflow documentation for more details: + https://www.tensorflow.org/api_docs/python/tf/sparse/SparseTensor. + dense_shape_tensor_name (str): + Specifies the shape of the values of the input if the input + is a sparse representation. Refer to Tensorflow + documentation for more details: + https://www.tensorflow.org/api_docs/python/tf/sparse/SparseTensor. + index_feature_mapping (Sequence[str]): + A list of feature names for each index in the input tensor. + Required when the input + [InputMetadata.encoding][google.cloud.aiplatform.v1.ExplanationMetadata.InputMetadata.encoding] + is BAG_OF_FEATURES, BAG_OF_FEATURES_SPARSE, INDICATOR. + encoded_tensor_name (str): + Encoded tensor is a transformation of the input tensor. Must + be provided if choosing [Integrated Gradients + attribution][google.cloud.aiplatform.v1.ExplanationParameters.integrated_gradients_attribution] + or [XRAI + attribution][google.cloud.aiplatform.v1.ExplanationParameters.xrai_attribution] + and the input tensor is not differentiable. + + An encoded tensor is generated if the input tensor is + encoded by a lookup table. + encoded_baselines (Sequence[google.protobuf.struct_pb2.Value]): + A list of baselines for the encoded tensor. + The shape of each baseline should match the + shape of the encoded tensor. If a scalar is + provided, Vertex AI broadcasts to the same shape + as the encoded tensor. + visualization (google.cloud.aiplatform_v1.types.ExplanationMetadata.InputMetadata.Visualization): + Visualization configurations for image + explanation. + group_name (str): + Name of the group that the input belongs to. Features with + the same group name will be treated as one feature when + computing attributions. Features grouped together can have + different shapes in value. If provided, there will be one + single attribution generated in + [Attribution.feature_attributions][google.cloud.aiplatform.v1.Attribution.feature_attributions], + keyed by the group name. + """ + + class Encoding(proto.Enum): + r"""Defines how a feature is encoded. Defaults to IDENTITY.""" + ENCODING_UNSPECIFIED = 0 + IDENTITY = 1 + BAG_OF_FEATURES = 2 + BAG_OF_FEATURES_SPARSE = 3 + INDICATOR = 4 + COMBINED_EMBEDDING = 5 + CONCAT_EMBEDDING = 6 + + class FeatureValueDomain(proto.Message): + r"""Domain details of the input feature value. Provides numeric + information about the feature, such as its range (min, max). If the + feature has been pre-processed, for example with z-scoring, then it + provides information about how to recover the original feature. For + example, if the input feature is an image and it has been + pre-processed to obtain 0-mean and stddev = 1 values, then + original_mean, and original_stddev refer to the mean and stddev of + the original feature (e.g. image tensor) from which input feature + (with mean = 0 and stddev = 1) was obtained. + + Attributes: + min_value (float): + The minimum permissible value for this + feature. + max_value (float): + The maximum permissible value for this + feature. + original_mean (float): + If this input feature has been normalized to a mean value of + 0, the original_mean specifies the mean value of the domain + prior to normalization. + original_stddev (float): + If this input feature has been normalized to a standard + deviation of 1.0, the original_stddev specifies the standard + deviation of the domain prior to normalization. + """ + + min_value = proto.Field( + proto.FLOAT, + number=1, + ) + max_value = proto.Field( + proto.FLOAT, + number=2, + ) + original_mean = proto.Field( + proto.FLOAT, + number=3, + ) + original_stddev = proto.Field( + proto.FLOAT, + number=4, + ) + + class Visualization(proto.Message): + r"""Visualization configurations for image explanation. + + Attributes: + type_ (google.cloud.aiplatform_v1.types.ExplanationMetadata.InputMetadata.Visualization.Type): + Type of the image visualization. Only applicable to + [Integrated Gradients + attribution][google.cloud.aiplatform.v1.ExplanationParameters.integrated_gradients_attribution]. + OUTLINES shows regions of attribution, while PIXELS shows + per-pixel attribution. Defaults to OUTLINES. + polarity (google.cloud.aiplatform_v1.types.ExplanationMetadata.InputMetadata.Visualization.Polarity): + Whether to only highlight pixels with + positive contributions, negative or both. + Defaults to POSITIVE. + color_map (google.cloud.aiplatform_v1.types.ExplanationMetadata.InputMetadata.Visualization.ColorMap): + The color scheme used for the highlighted areas. + + Defaults to PINK_GREEN for [Integrated Gradients + attribution][google.cloud.aiplatform.v1.ExplanationParameters.integrated_gradients_attribution], + which shows positive attributions in green and negative in + pink. + + Defaults to VIRIDIS for [XRAI + attribution][google.cloud.aiplatform.v1.ExplanationParameters.xrai_attribution], + which highlights the most influential regions in yellow and + the least influential in blue. + clip_percent_upperbound (float): + Excludes attributions above the specified percentile from + the highlighted areas. Using the clip_percent_upperbound and + clip_percent_lowerbound together can be useful for filtering + out noise and making it easier to see areas of strong + attribution. Defaults to 99.9. + clip_percent_lowerbound (float): + Excludes attributions below the specified + percentile, from the highlighted areas. Defaults + to 62. + overlay_type (google.cloud.aiplatform_v1.types.ExplanationMetadata.InputMetadata.Visualization.OverlayType): + How the original image is displayed in the + visualization. Adjusting the overlay can help + increase visual clarity if the original image + makes it difficult to view the visualization. + Defaults to NONE. + """ + + class Type(proto.Enum): + r"""Type of the image visualization. Only applicable to [Integrated + Gradients + attribution][google.cloud.aiplatform.v1.ExplanationParameters.integrated_gradients_attribution]. + """ + TYPE_UNSPECIFIED = 0 + PIXELS = 1 + OUTLINES = 2 + + class Polarity(proto.Enum): + r"""Whether to only highlight pixels with positive contributions, + negative or both. Defaults to POSITIVE. + """ + POLARITY_UNSPECIFIED = 0 + POSITIVE = 1 + NEGATIVE = 2 + BOTH = 3 + + class ColorMap(proto.Enum): + r"""The color scheme used for highlighting areas.""" + COLOR_MAP_UNSPECIFIED = 0 + PINK_GREEN = 1 + VIRIDIS = 2 + RED = 3 + GREEN = 4 + RED_GREEN = 6 + PINK_WHITE_GREEN = 5 + + class OverlayType(proto.Enum): + r"""How the original image is displayed in the visualization.""" + OVERLAY_TYPE_UNSPECIFIED = 0 + NONE = 1 + ORIGINAL = 2 + GRAYSCALE = 3 + MASK_BLACK = 4 + + type_ = proto.Field( + proto.ENUM, + number=1, + enum="ExplanationMetadata.InputMetadata.Visualization.Type", + ) + polarity = proto.Field( + proto.ENUM, + number=2, + enum="ExplanationMetadata.InputMetadata.Visualization.Polarity", + ) + color_map = proto.Field( + proto.ENUM, + number=3, + enum="ExplanationMetadata.InputMetadata.Visualization.ColorMap", + ) + clip_percent_upperbound = proto.Field( + proto.FLOAT, + number=4, + ) + clip_percent_lowerbound = proto.Field( + proto.FLOAT, + number=5, + ) + overlay_type = proto.Field( + proto.ENUM, + number=6, + enum="ExplanationMetadata.InputMetadata.Visualization.OverlayType", + ) + + input_baselines = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=struct_pb2.Value, + ) + input_tensor_name = proto.Field( + proto.STRING, + number=2, + ) + encoding = proto.Field( + proto.ENUM, + number=3, + enum="ExplanationMetadata.InputMetadata.Encoding", + ) + modality = proto.Field( + proto.STRING, + number=4, + ) + feature_value_domain = proto.Field( + proto.MESSAGE, + number=5, + message="ExplanationMetadata.InputMetadata.FeatureValueDomain", + ) + indices_tensor_name = proto.Field( + proto.STRING, + number=6, + ) + dense_shape_tensor_name = proto.Field( + proto.STRING, + number=7, + ) + index_feature_mapping = proto.RepeatedField( + proto.STRING, + number=8, + ) + encoded_tensor_name = proto.Field( + proto.STRING, + number=9, + ) + encoded_baselines = proto.RepeatedField( + proto.MESSAGE, + number=10, + message=struct_pb2.Value, + ) + visualization = proto.Field( + proto.MESSAGE, + number=11, + message="ExplanationMetadata.InputMetadata.Visualization", + ) + group_name = proto.Field( + proto.STRING, + number=12, + ) + + class OutputMetadata(proto.Message): + r"""Metadata of the prediction output to be explained. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + index_display_name_mapping (google.protobuf.struct_pb2.Value): + Static mapping between the index and display name. + + Use this if the outputs are a deterministic n-dimensional + array, e.g. a list of scores of all the classes in a + pre-defined order for a multi-classification Model. It's not + feasible if the outputs are non-deterministic, e.g. the + Model produces top-k classes or sort the outputs by their + values. + + The shape of the value must be an n-dimensional array of + strings. The number of dimensions must match that of the + outputs to be explained. The + [Attribution.output_display_name][google.cloud.aiplatform.v1.Attribution.output_display_name] + is populated by locating in the mapping with + [Attribution.output_index][google.cloud.aiplatform.v1.Attribution.output_index]. + + This field is a member of `oneof`_ ``display_name_mapping``. + display_name_mapping_key (str): + Specify a field name in the prediction to look for the + display name. + + Use this if the prediction contains the display names for + the outputs. + + The display names in the prediction must have the same shape + of the outputs, so that it can be located by + [Attribution.output_index][google.cloud.aiplatform.v1.Attribution.output_index] + for a specific output. + + This field is a member of `oneof`_ ``display_name_mapping``. + output_tensor_name (str): + Name of the output tensor. Required and is + only applicable to Vertex AI provided images for + Tensorflow. + """ + + index_display_name_mapping = proto.Field( + proto.MESSAGE, + number=1, + oneof="display_name_mapping", + message=struct_pb2.Value, + ) + display_name_mapping_key = proto.Field( + proto.STRING, + number=2, + oneof="display_name_mapping", + ) + output_tensor_name = proto.Field( + proto.STRING, + number=3, + ) + + inputs = proto.MapField( + proto.STRING, + proto.MESSAGE, + number=1, + message=InputMetadata, + ) + outputs = proto.MapField( + proto.STRING, + proto.MESSAGE, + number=2, + message=OutputMetadata, + ) + feature_attributions_schema_uri = proto.Field( + proto.STRING, + number=3, + ) + latent_space_source = proto.Field( + proto.STRING, + number=5, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/feature.py b/google/cloud/aiplatform_v1/types/feature.py new file mode 100644 index 0000000000..e86df5b6ed --- /dev/null +++ b/google/cloud/aiplatform_v1/types/feature.py @@ -0,0 +1,181 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + +from google.cloud.aiplatform_v1.types import feature_monitoring_stats +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "Feature", + }, +) + + +class Feature(proto.Message): + r"""Feature Metadata information that describes an attribute of + an entity type. For example, apple is an entity type, and color + is a feature that describes apple. + + Attributes: + name (str): + Immutable. Name of the Feature. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}/features/{feature}`` + + The last part feature is assigned by the client. The feature + can be up to 64 characters long and can consist only of + ASCII Latin letters A-Z and a-z, underscore(_), and ASCII + digits 0-9 starting with a letter. The value will be unique + given an entity type. + description (str): + Description of the Feature. + value_type (google.cloud.aiplatform_v1.types.Feature.ValueType): + Required. Immutable. Type of Feature value. + create_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp when this EntityType + was created. + update_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp when this EntityType + was most recently updated. + labels (Mapping[str, str]): + Optional. The labels with user-defined + metadata to organize your Features. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + on and examples of labels. No more than 64 user + labels can be associated with one Feature + (System labels are excluded)." + System reserved label keys are prefixed with + "aiplatform.googleapis.com/" and are immutable. + etag (str): + Used to perform a consistent + read-modify-write updates. If not set, a blind + "overwrite" update happens. + disable_monitoring (bool): + Optional. If not set, use the monitoring_config defined for + the EntityType this Feature belongs to. Only Features with + type + ([Feature.ValueType][google.cloud.aiplatform.v1.Feature.ValueType]) + BOOL, STRING, DOUBLE or INT64 can enable monitoring. + + If set to true, all types of data monitoring are disabled + despite the config on EntityType. + monitoring_stats_anomalies (Sequence[google.cloud.aiplatform_v1.types.Feature.MonitoringStatsAnomaly]): + Output only. The list of historical stats and + anomalies with specified objectives. + """ + + class ValueType(proto.Enum): + r"""An enum representing the value type of a feature.""" + VALUE_TYPE_UNSPECIFIED = 0 + BOOL = 1 + BOOL_ARRAY = 2 + DOUBLE = 3 + DOUBLE_ARRAY = 4 + INT64 = 9 + INT64_ARRAY = 10 + STRING = 11 + STRING_ARRAY = 12 + BYTES = 13 + + class MonitoringStatsAnomaly(proto.Message): + r"""A list of historical [Snapshot + Analysis][FeaturestoreMonitoringConfig.SnapshotAnalysis] or [Import + Feature Analysis] + [FeaturestoreMonitoringConfig.ImportFeatureAnalysis] stats requested + by user, sorted by + [FeatureStatsAnomaly.start_time][google.cloud.aiplatform.v1.FeatureStatsAnomaly.start_time] + descending. + + Attributes: + objective (google.cloud.aiplatform_v1.types.Feature.MonitoringStatsAnomaly.Objective): + Output only. The objective for each stats. + feature_stats_anomaly (google.cloud.aiplatform_v1.types.FeatureStatsAnomaly): + Output only. The stats and anomalies + generated at specific timestamp. + """ + + class Objective(proto.Enum): + r"""If the objective in the request is both + Import Feature Analysis and Snapshot Analysis, this objective + could be one of them. Otherwise, this objective should be the + same as the objective in the request. + """ + OBJECTIVE_UNSPECIFIED = 0 + IMPORT_FEATURE_ANALYSIS = 1 + SNAPSHOT_ANALYSIS = 2 + + objective = proto.Field( + proto.ENUM, + number=1, + enum="Feature.MonitoringStatsAnomaly.Objective", + ) + feature_stats_anomaly = proto.Field( + proto.MESSAGE, + number=2, + message=feature_monitoring_stats.FeatureStatsAnomaly, + ) + + name = proto.Field( + proto.STRING, + number=1, + ) + description = proto.Field( + proto.STRING, + number=2, + ) + value_type = proto.Field( + proto.ENUM, + number=3, + enum=ValueType, + ) + create_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=5, + message=timestamp_pb2.Timestamp, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=6, + ) + etag = proto.Field( + proto.STRING, + number=7, + ) + disable_monitoring = proto.Field( + proto.BOOL, + number=12, + ) + monitoring_stats_anomalies = proto.RepeatedField( + proto.MESSAGE, + number=11, + message=MonitoringStatsAnomaly, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/feature_monitoring_stats.py b/google/cloud/aiplatform_v1/types/feature_monitoring_stats.py new file mode 100644 index 0000000000..6e55614217 --- /dev/null +++ b/google/cloud/aiplatform_v1/types/feature_monitoring_stats.py @@ -0,0 +1,124 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "FeatureStatsAnomaly", + }, +) + + +class FeatureStatsAnomaly(proto.Message): + r"""Stats and Anomaly generated at specific timestamp for specific + Feature. The start_time and end_time are used to define the time + range of the dataset that current stats belongs to, e.g. prediction + traffic is bucketed into prediction datasets by time window. If the + Dataset is not defined by time window, start_time = end_time. + Timestamp of the stats and anomalies always refers to end_time. Raw + stats and anomalies are stored in stats_uri or anomaly_uri in the + tensorflow defined protos. Field data_stats contains almost + identical information with the raw stats in Vertex AI defined proto, + for UI to display. + + Attributes: + score (float): + Feature importance score, only populated when cross-feature + monitoring is enabled. For now only used to represent + feature attribution score within range [0, 1] for + [ModelDeploymentMonitoringObjectiveType.FEATURE_ATTRIBUTION_SKEW][google.cloud.aiplatform.v1.ModelDeploymentMonitoringObjectiveType.FEATURE_ATTRIBUTION_SKEW] + and + [ModelDeploymentMonitoringObjectiveType.FEATURE_ATTRIBUTION_DRIFT][google.cloud.aiplatform.v1.ModelDeploymentMonitoringObjectiveType.FEATURE_ATTRIBUTION_DRIFT]. + stats_uri (str): + Path of the stats file for current feature values in Cloud + Storage bucket. Format: + gs:////stats. Example: + gs://monitoring_bucket/feature_name/stats. Stats are stored + as binary format with Protobuf message + `tensorflow.metadata.v0.FeatureNameStatistics `__. + anomaly_uri (str): + Path of the anomaly file for current feature values in Cloud + Storage bucket. Format: + gs:////anomalies. Example: + gs://monitoring_bucket/feature_name/anomalies. Stats are + stored as binary format with Protobuf message Anoamlies are + stored as binary format with Protobuf message + [tensorflow.metadata.v0.AnomalyInfo] + (https://github.com/tensorflow/metadata/blob/master/tensorflow_metadata/proto/v0/anomalies.proto). + distribution_deviation (float): + Deviation from the current stats to baseline + stats. 1. For categorical feature, the + distribution distance is calculated by + L-inifinity norm. + 2. For numerical feature, the distribution + distance is calculated by Jensen–Shannon + divergence. + anomaly_detection_threshold (float): + This is the threshold used when detecting anomalies. The + threshold can be changed by user, so this one might be + different from + [ThresholdConfig.value][google.cloud.aiplatform.v1.ThresholdConfig.value]. + start_time (google.protobuf.timestamp_pb2.Timestamp): + The start timestamp of window where stats were generated. + For objectives where time window doesn't make sense (e.g. + Featurestore Snapshot Monitoring), start_time is only used + to indicate the monitoring intervals, so it always equals to + (end_time - monitoring_interval). + end_time (google.protobuf.timestamp_pb2.Timestamp): + The end timestamp of window where stats were generated. For + objectives where time window doesn't make sense (e.g. + Featurestore Snapshot Monitoring), end_time indicates the + timestamp of the data used to generate stats (e.g. timestamp + we take snapshots for feature values). + """ + + score = proto.Field( + proto.DOUBLE, + number=1, + ) + stats_uri = proto.Field( + proto.STRING, + number=3, + ) + anomaly_uri = proto.Field( + proto.STRING, + number=4, + ) + distribution_deviation = proto.Field( + proto.DOUBLE, + number=5, + ) + anomaly_detection_threshold = proto.Field( + proto.DOUBLE, + number=9, + ) + start_time = proto.Field( + proto.MESSAGE, + number=7, + message=timestamp_pb2.Timestamp, + ) + end_time = proto.Field( + proto.MESSAGE, + number=8, + message=timestamp_pb2.Timestamp, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/feature_selector.py b/google/cloud/aiplatform_v1/types/feature_selector.py new file mode 100644 index 0000000000..7a6ff08b98 --- /dev/null +++ b/google/cloud/aiplatform_v1/types/feature_selector.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "IdMatcher", + "FeatureSelector", + }, +) + + +class IdMatcher(proto.Message): + r"""Matcher for Features of an EntityType by Feature ID. + + Attributes: + ids (Sequence[str]): + Required. The following are accepted as ``ids``: + + - A single-element list containing only ``*``, which + selects all Features in the target EntityType, or + - A list containing only Feature IDs, which selects only + Features with those IDs in the target EntityType. + """ + + ids = proto.RepeatedField( + proto.STRING, + number=1, + ) + + +class FeatureSelector(proto.Message): + r"""Selector for Features of an EntityType. + + Attributes: + id_matcher (google.cloud.aiplatform_v1.types.IdMatcher): + Required. Matches Features based on ID. + """ + + id_matcher = proto.Field( + proto.MESSAGE, + number=1, + message="IdMatcher", + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/featurestore.py b/google/cloud/aiplatform_v1/types/featurestore.py new file mode 100644 index 0000000000..e88b5c17bc --- /dev/null +++ b/google/cloud/aiplatform_v1/types/featurestore.py @@ -0,0 +1,176 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + +from google.cloud.aiplatform_v1.types import encryption_spec as gca_encryption_spec +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "Featurestore", + }, +) + + +class Featurestore(proto.Message): + r"""Vertex AI Feature Store provides a centralized repository for + organizing, storing, and serving ML features. The Featurestore + is a top-level container for your features and their values. + + Attributes: + name (str): + Output only. Name of the Featurestore. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}`` + create_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp when this Featurestore + was created. + update_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp when this Featurestore + was last updated. + etag (str): + Optional. Used to perform consistent + read-modify-write updates. If not set, a blind + "overwrite" update happens. + labels (Mapping[str, str]): + Optional. The labels with user-defined + metadata to organize your Featurestore. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + on and examples of labels. No more than 64 user + labels can be associated with one + Featurestore(System labels are excluded)." + System reserved label keys are prefixed with + "aiplatform.googleapis.com/" and are immutable. + online_serving_config (google.cloud.aiplatform_v1.types.Featurestore.OnlineServingConfig): + Optional. Config for online storage + resources. If unset, the featurestore will not + have an online store and cannot be used for + online serving. + state (google.cloud.aiplatform_v1.types.Featurestore.State): + Output only. State of the featurestore. + encryption_spec (google.cloud.aiplatform_v1.types.EncryptionSpec): + Optional. Customer-managed encryption key + spec for data storage. If set, both of the + online and offline data storage will be secured + by this key. + """ + + class State(proto.Enum): + r"""Possible states a featurestore can have.""" + STATE_UNSPECIFIED = 0 + STABLE = 1 + UPDATING = 2 + + class OnlineServingConfig(proto.Message): + r"""OnlineServingConfig specifies the details for provisioning + online serving resources. + + Attributes: + fixed_node_count (int): + The number of nodes for the online store. The + number of nodes doesn't scale automatically, but + you can manually update the number of nodes. If + set to 0, the featurestore will not have an + online store and cannot be used for online + serving. + scaling (google.cloud.aiplatform_v1.types.Featurestore.OnlineServingConfig.Scaling): + Online serving scaling configuration. Only one of + ``fixed_node_count`` and ``scaling`` can be set. Setting one + will reset the other. + """ + + class Scaling(proto.Message): + r"""Online serving scaling configuration. If min_node_count and + max_node_count are set to the same value, the cluster will be + configured with the fixed number of node (no auto-scaling). + + Attributes: + min_node_count (int): + Required. The minimum number of nodes to + scale down to. Must be greater than or equal to + 1. + max_node_count (int): + The maximum number of nodes to scale up to. Must be greater + than min_node_count, and less than or equal to 10 times of + 'min_node_count'. + """ + + min_node_count = proto.Field( + proto.INT32, + number=1, + ) + max_node_count = proto.Field( + proto.INT32, + number=2, + ) + + fixed_node_count = proto.Field( + proto.INT32, + number=2, + ) + scaling = proto.Field( + proto.MESSAGE, + number=4, + message="Featurestore.OnlineServingConfig.Scaling", + ) + + name = proto.Field( + proto.STRING, + number=1, + ) + create_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + etag = proto.Field( + proto.STRING, + number=5, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=6, + ) + online_serving_config = proto.Field( + proto.MESSAGE, + number=7, + message=OnlineServingConfig, + ) + state = proto.Field( + proto.ENUM, + number=8, + enum=State, + ) + encryption_spec = proto.Field( + proto.MESSAGE, + number=10, + message=gca_encryption_spec.EncryptionSpec, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/featurestore_monitoring.py b/google/cloud/aiplatform_v1/types/featurestore_monitoring.py new file mode 100644 index 0000000000..303911b0f0 --- /dev/null +++ b/google/cloud/aiplatform_v1/types/featurestore_monitoring.py @@ -0,0 +1,191 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "FeaturestoreMonitoringConfig", + }, +) + + +class FeaturestoreMonitoringConfig(proto.Message): + r"""Configuration of how features in Featurestore are monitored. + + Attributes: + snapshot_analysis (google.cloud.aiplatform_v1.types.FeaturestoreMonitoringConfig.SnapshotAnalysis): + The config for Snapshot Analysis Based + Feature Monitoring. + import_features_analysis (google.cloud.aiplatform_v1.types.FeaturestoreMonitoringConfig.ImportFeaturesAnalysis): + The config for ImportFeatures Analysis Based + Feature Monitoring. + numerical_threshold_config (google.cloud.aiplatform_v1.types.FeaturestoreMonitoringConfig.ThresholdConfig): + Threshold for numerical features of anomaly detection. This + is shared by all objectives of Featurestore Monitoring for + numerical features (i.e. Features with type + ([Feature.ValueType][google.cloud.aiplatform.v1.Feature.ValueType]) + DOUBLE or INT64). + categorical_threshold_config (google.cloud.aiplatform_v1.types.FeaturestoreMonitoringConfig.ThresholdConfig): + Threshold for categorical features of anomaly detection. + This is shared by all types of Featurestore Monitoring for + categorical features (i.e. Features with type + ([Feature.ValueType][google.cloud.aiplatform.v1.Feature.ValueType]) + BOOL or STRING). + """ + + class SnapshotAnalysis(proto.Message): + r"""Configuration of the Featurestore's Snapshot Analysis Based + Monitoring. This type of analysis generates statistics for each + Feature based on a snapshot of the latest feature value of each + entities every monitoring_interval. + + Attributes: + disabled (bool): + The monitoring schedule for snapshot analysis. For + EntityType-level config: unset / disabled = true indicates + disabled by default for Features under it; otherwise by + default enable snapshot analysis monitoring with + monitoring_interval for Features under it. Feature-level + config: disabled = true indicates disabled regardless of the + EntityType-level config; unset monitoring_interval indicates + going with EntityType-level config; otherwise run snapshot + analysis monitoring with monitoring_interval regardless of + the EntityType-level config. Explicitly Disable the snapshot + analysis based monitoring. + monitoring_interval_days (int): + Configuration of the snapshot analysis based monitoring + pipeline running interval. The value indicates number of + days. If both + [FeaturestoreMonitoringConfig.SnapshotAnalysis.monitoring_interval_days][google.cloud.aiplatform.v1.FeaturestoreMonitoringConfig.SnapshotAnalysis.monitoring_interval_days] + and + [FeaturestoreMonitoringConfig.SnapshotAnalysis.monitoring_interval][] + are set when creating/updating EntityTypes/Features, + [FeaturestoreMonitoringConfig.SnapshotAnalysis.monitoring_interval_days][google.cloud.aiplatform.v1.FeaturestoreMonitoringConfig.SnapshotAnalysis.monitoring_interval_days] + will be used. + staleness_days (int): + Customized export features time window for + snapshot analysis. Unit is one day. Default + value is 3 weeks. Minimum value is 1 day. + Maximum value is 4000 days. + """ + + disabled = proto.Field( + proto.BOOL, + number=1, + ) + monitoring_interval_days = proto.Field( + proto.INT32, + number=3, + ) + staleness_days = proto.Field( + proto.INT32, + number=4, + ) + + class ImportFeaturesAnalysis(proto.Message): + r"""Configuration of the Featurestore's ImportFeature Analysis Based + Monitoring. This type of analysis generates statistics for values of + each Feature imported by every [ImportFeatureValues][] operation. + + Attributes: + state (google.cloud.aiplatform_v1.types.FeaturestoreMonitoringConfig.ImportFeaturesAnalysis.State): + Whether to enable / disable / inherite + default hebavior for import features analysis. + anomaly_detection_baseline (google.cloud.aiplatform_v1.types.FeaturestoreMonitoringConfig.ImportFeaturesAnalysis.Baseline): + The baseline used to do anomaly detection for + the statistics generated by import features + analysis. + """ + + class State(proto.Enum): + r"""The state defines whether to enable ImportFeature analysis.""" + STATE_UNSPECIFIED = 0 + DEFAULT = 1 + ENABLED = 2 + DISABLED = 3 + + class Baseline(proto.Enum): + r"""Defines the baseline to do anomaly detection for feature values + imported by each [ImportFeatureValues][] operation. + """ + BASELINE_UNSPECIFIED = 0 + LATEST_STATS = 1 + MOST_RECENT_SNAPSHOT_STATS = 2 + PREVIOUS_IMPORT_FEATURES_STATS = 3 + + state = proto.Field( + proto.ENUM, + number=1, + enum="FeaturestoreMonitoringConfig.ImportFeaturesAnalysis.State", + ) + anomaly_detection_baseline = proto.Field( + proto.ENUM, + number=2, + enum="FeaturestoreMonitoringConfig.ImportFeaturesAnalysis.Baseline", + ) + + class ThresholdConfig(proto.Message): + r"""The config for Featurestore Monitoring threshold. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + value (float): + Specify a threshold value that can trigger + the alert. 1. For categorical feature, the + distribution distance is calculated by + L-inifinity norm. + 2. For numerical feature, the distribution + distance is calculated by Jensen–Shannon + divergence. Each feature must have a non-zero + threshold if they need to be monitored. + Otherwise no alert will be triggered for that + feature. + + This field is a member of `oneof`_ ``threshold``. + """ + + value = proto.Field( + proto.DOUBLE, + number=1, + oneof="threshold", + ) + + snapshot_analysis = proto.Field( + proto.MESSAGE, + number=1, + message=SnapshotAnalysis, + ) + import_features_analysis = proto.Field( + proto.MESSAGE, + number=2, + message=ImportFeaturesAnalysis, + ) + numerical_threshold_config = proto.Field( + proto.MESSAGE, + number=3, + message=ThresholdConfig, + ) + categorical_threshold_config = proto.Field( + proto.MESSAGE, + number=4, + message=ThresholdConfig, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/featurestore_online_service.py b/google/cloud/aiplatform_v1/types/featurestore_online_service.py new file mode 100644 index 0000000000..19b88981f5 --- /dev/null +++ b/google/cloud/aiplatform_v1/types/featurestore_online_service.py @@ -0,0 +1,381 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + +from google.cloud.aiplatform_v1.types import feature_selector as gca_feature_selector +from google.cloud.aiplatform_v1.types import types +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "ReadFeatureValuesRequest", + "ReadFeatureValuesResponse", + "StreamingReadFeatureValuesRequest", + "FeatureValue", + "FeatureValueList", + }, +) + + +class ReadFeatureValuesRequest(proto.Message): + r"""Request message for + [FeaturestoreOnlineServingService.ReadFeatureValues][google.cloud.aiplatform.v1.FeaturestoreOnlineServingService.ReadFeatureValues]. + + Attributes: + entity_type (str): + Required. The resource name of the EntityType for the entity + being read. Value format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entityType}``. + For example, for a machine learning model predicting user + clicks on a website, an EntityType ID could be ``user``. + entity_id (str): + Required. ID for a specific entity. For example, for a + machine learning model predicting user clicks on a website, + an entity ID could be ``user_123``. + feature_selector (google.cloud.aiplatform_v1.types.FeatureSelector): + Required. Selector choosing Features of the + target EntityType. + """ + + entity_type = proto.Field( + proto.STRING, + number=1, + ) + entity_id = proto.Field( + proto.STRING, + number=2, + ) + feature_selector = proto.Field( + proto.MESSAGE, + number=3, + message=gca_feature_selector.FeatureSelector, + ) + + +class ReadFeatureValuesResponse(proto.Message): + r"""Response message for + [FeaturestoreOnlineServingService.ReadFeatureValues][google.cloud.aiplatform.v1.FeaturestoreOnlineServingService.ReadFeatureValues]. + + Attributes: + header (google.cloud.aiplatform_v1.types.ReadFeatureValuesResponse.Header): + Response header. + entity_view (google.cloud.aiplatform_v1.types.ReadFeatureValuesResponse.EntityView): + Entity view with Feature values. This may be + the entity in the Featurestore if values for all + Features were requested, or a projection of the + entity in the Featurestore if values for only + some Features were requested. + """ + + class FeatureDescriptor(proto.Message): + r"""Metadata for requested Features. + + Attributes: + id (str): + Feature ID. + """ + + id = proto.Field( + proto.STRING, + number=1, + ) + + class Header(proto.Message): + r"""Response header with metadata for the requested + [ReadFeatureValuesRequest.entity_type][google.cloud.aiplatform.v1.ReadFeatureValuesRequest.entity_type] + and Features. + + Attributes: + entity_type (str): + The resource name of the EntityType from the + [ReadFeatureValuesRequest][google.cloud.aiplatform.v1.ReadFeatureValuesRequest]. + Value format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entityType}``. + feature_descriptors (Sequence[google.cloud.aiplatform_v1.types.ReadFeatureValuesResponse.FeatureDescriptor]): + List of Feature metadata corresponding to each piece of + [ReadFeatureValuesResponse.data][]. + """ + + entity_type = proto.Field( + proto.STRING, + number=1, + ) + feature_descriptors = proto.RepeatedField( + proto.MESSAGE, + number=2, + message="ReadFeatureValuesResponse.FeatureDescriptor", + ) + + class EntityView(proto.Message): + r"""Entity view with Feature values. + + Attributes: + entity_id (str): + ID of the requested entity. + data (Sequence[google.cloud.aiplatform_v1.types.ReadFeatureValuesResponse.EntityView.Data]): + Each piece of data holds the k requested values for one + requested Feature. If no values for the requested Feature + exist, the corresponding cell will be empty. This has the + same size and is in the same order as the features from the + header + [ReadFeatureValuesResponse.header][google.cloud.aiplatform.v1.ReadFeatureValuesResponse.header]. + """ + + class Data(proto.Message): + r"""Container to hold value(s), successive in time, for one + Feature from the request. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + value (google.cloud.aiplatform_v1.types.FeatureValue): + Feature value if a single value is requested. + + This field is a member of `oneof`_ ``data``. + values (google.cloud.aiplatform_v1.types.FeatureValueList): + Feature values list if values, successive in + time, are requested. If the requested number of + values is greater than the number of existing + Feature values, nonexistent values are omitted + instead of being returned as empty. + + This field is a member of `oneof`_ ``data``. + """ + + value = proto.Field( + proto.MESSAGE, + number=1, + oneof="data", + message="FeatureValue", + ) + values = proto.Field( + proto.MESSAGE, + number=2, + oneof="data", + message="FeatureValueList", + ) + + entity_id = proto.Field( + proto.STRING, + number=1, + ) + data = proto.RepeatedField( + proto.MESSAGE, + number=2, + message="ReadFeatureValuesResponse.EntityView.Data", + ) + + header = proto.Field( + proto.MESSAGE, + number=1, + message=Header, + ) + entity_view = proto.Field( + proto.MESSAGE, + number=2, + message=EntityView, + ) + + +class StreamingReadFeatureValuesRequest(proto.Message): + r"""Request message for + [FeaturestoreOnlineServingService.StreamingFeatureValuesRead][]. + + Attributes: + entity_type (str): + Required. The resource name of the entities' type. Value + format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entityType}``. + For example, for a machine learning model predicting user + clicks on a website, an EntityType ID could be ``user``. + entity_ids (Sequence[str]): + Required. IDs of entities to read Feature values of. The + maximum number of IDs is 100. For example, for a machine + learning model predicting user clicks on a website, an + entity ID could be ``user_123``. + feature_selector (google.cloud.aiplatform_v1.types.FeatureSelector): + Required. Selector choosing Features of the + target EntityType. Feature IDs will be + deduplicated. + """ + + entity_type = proto.Field( + proto.STRING, + number=1, + ) + entity_ids = proto.RepeatedField( + proto.STRING, + number=2, + ) + feature_selector = proto.Field( + proto.MESSAGE, + number=3, + message=gca_feature_selector.FeatureSelector, + ) + + +class FeatureValue(proto.Message): + r"""Value for a feature. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + bool_value (bool): + Bool type feature value. + + This field is a member of `oneof`_ ``value``. + double_value (float): + Double type feature value. + + This field is a member of `oneof`_ ``value``. + int64_value (int): + Int64 feature value. + + This field is a member of `oneof`_ ``value``. + string_value (str): + String feature value. + + This field is a member of `oneof`_ ``value``. + bool_array_value (google.cloud.aiplatform_v1.types.BoolArray): + A list of bool type feature value. + + This field is a member of `oneof`_ ``value``. + double_array_value (google.cloud.aiplatform_v1.types.DoubleArray): + A list of double type feature value. + + This field is a member of `oneof`_ ``value``. + int64_array_value (google.cloud.aiplatform_v1.types.Int64Array): + A list of int64 type feature value. + + This field is a member of `oneof`_ ``value``. + string_array_value (google.cloud.aiplatform_v1.types.StringArray): + A list of string type feature value. + + This field is a member of `oneof`_ ``value``. + bytes_value (bytes): + Bytes feature value. + + This field is a member of `oneof`_ ``value``. + metadata (google.cloud.aiplatform_v1.types.FeatureValue.Metadata): + Metadata of feature value. + """ + + class Metadata(proto.Message): + r"""Metadata of feature value. + + Attributes: + generate_time (google.protobuf.timestamp_pb2.Timestamp): + Feature generation timestamp. Typically, it + is provided by user at feature ingestion time. + If not, feature store will use the system + timestamp when the data is ingested into feature + store. For streaming ingestion, the time, + aligned by days, must be no older than five + years (1825 days) and no later than one year + (366 days) in the future. + """ + + generate_time = proto.Field( + proto.MESSAGE, + number=1, + message=timestamp_pb2.Timestamp, + ) + + bool_value = proto.Field( + proto.BOOL, + number=1, + oneof="value", + ) + double_value = proto.Field( + proto.DOUBLE, + number=2, + oneof="value", + ) + int64_value = proto.Field( + proto.INT64, + number=5, + oneof="value", + ) + string_value = proto.Field( + proto.STRING, + number=6, + oneof="value", + ) + bool_array_value = proto.Field( + proto.MESSAGE, + number=7, + oneof="value", + message=types.BoolArray, + ) + double_array_value = proto.Field( + proto.MESSAGE, + number=8, + oneof="value", + message=types.DoubleArray, + ) + int64_array_value = proto.Field( + proto.MESSAGE, + number=11, + oneof="value", + message=types.Int64Array, + ) + string_array_value = proto.Field( + proto.MESSAGE, + number=12, + oneof="value", + message=types.StringArray, + ) + bytes_value = proto.Field( + proto.BYTES, + number=13, + oneof="value", + ) + metadata = proto.Field( + proto.MESSAGE, + number=14, + message=Metadata, + ) + + +class FeatureValueList(proto.Message): + r"""Container for list of values. + + Attributes: + values (Sequence[google.cloud.aiplatform_v1.types.FeatureValue]): + A list of feature values. All of them should + be the same data type. + """ + + values = proto.RepeatedField( + proto.MESSAGE, + number=1, + message="FeatureValue", + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/featurestore_service.py b/google/cloud/aiplatform_v1/types/featurestore_service.py new file mode 100644 index 0000000000..0fb47545cb --- /dev/null +++ b/google/cloud/aiplatform_v1/types/featurestore_service.py @@ -0,0 +1,1665 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + +from google.cloud.aiplatform_v1.types import entity_type as gca_entity_type +from google.cloud.aiplatform_v1.types import feature as gca_feature +from google.cloud.aiplatform_v1.types import feature_selector as gca_feature_selector +from google.cloud.aiplatform_v1.types import featurestore as gca_featurestore +from google.cloud.aiplatform_v1.types import io +from google.cloud.aiplatform_v1.types import operation +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "CreateFeaturestoreRequest", + "GetFeaturestoreRequest", + "ListFeaturestoresRequest", + "ListFeaturestoresResponse", + "UpdateFeaturestoreRequest", + "DeleteFeaturestoreRequest", + "ImportFeatureValuesRequest", + "ImportFeatureValuesResponse", + "BatchReadFeatureValuesRequest", + "ExportFeatureValuesRequest", + "DestinationFeatureSetting", + "FeatureValueDestination", + "ExportFeatureValuesResponse", + "BatchReadFeatureValuesResponse", + "CreateEntityTypeRequest", + "GetEntityTypeRequest", + "ListEntityTypesRequest", + "ListEntityTypesResponse", + "UpdateEntityTypeRequest", + "DeleteEntityTypeRequest", + "CreateFeatureRequest", + "BatchCreateFeaturesRequest", + "BatchCreateFeaturesResponse", + "GetFeatureRequest", + "ListFeaturesRequest", + "ListFeaturesResponse", + "SearchFeaturesRequest", + "SearchFeaturesResponse", + "UpdateFeatureRequest", + "DeleteFeatureRequest", + "CreateFeaturestoreOperationMetadata", + "UpdateFeaturestoreOperationMetadata", + "ImportFeatureValuesOperationMetadata", + "ExportFeatureValuesOperationMetadata", + "BatchReadFeatureValuesOperationMetadata", + "CreateEntityTypeOperationMetadata", + "CreateFeatureOperationMetadata", + "BatchCreateFeaturesOperationMetadata", + }, +) + + +class CreateFeaturestoreRequest(proto.Message): + r"""Request message for + [FeaturestoreService.CreateFeaturestore][google.cloud.aiplatform.v1.FeaturestoreService.CreateFeaturestore]. + + Attributes: + parent (str): + Required. The resource name of the Location to create + Featurestores. Format: + ``projects/{project}/locations/{location}'`` + featurestore (google.cloud.aiplatform_v1.types.Featurestore): + Required. The Featurestore to create. + featurestore_id (str): + Required. The ID to use for this Featurestore, which will + become the final component of the Featurestore's resource + name. + + This value may be up to 60 characters, and valid characters + are ``[a-z0-9_]``. The first character cannot be a number. + + The value must be unique within the project and location. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + featurestore = proto.Field( + proto.MESSAGE, + number=2, + message=gca_featurestore.Featurestore, + ) + featurestore_id = proto.Field( + proto.STRING, + number=3, + ) + + +class GetFeaturestoreRequest(proto.Message): + r"""Request message for + [FeaturestoreService.GetFeaturestore][google.cloud.aiplatform.v1.FeaturestoreService.GetFeaturestore]. + + Attributes: + name (str): + Required. The name of the Featurestore + resource. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class ListFeaturestoresRequest(proto.Message): + r"""Request message for + [FeaturestoreService.ListFeaturestores][google.cloud.aiplatform.v1.FeaturestoreService.ListFeaturestores]. + + Attributes: + parent (str): + Required. The resource name of the Location to list + Featurestores. Format: + ``projects/{project}/locations/{location}`` + filter (str): + Lists the featurestores that match the filter expression. + The following fields are supported: + + - ``create_time``: Supports ``=``, ``!=``, ``<``, ``>``, + ``<=``, and ``>=`` comparisons. Values must be in RFC + 3339 format. + - ``update_time``: Supports ``=``, ``!=``, ``<``, ``>``, + ``<=``, and ``>=`` comparisons. Values must be in RFC + 3339 format. + - ``online_serving_config.fixed_node_count``: Supports + ``=``, ``!=``, ``<``, ``>``, ``<=``, and ``>=`` + comparisons. + - ``labels``: Supports key-value equality and key presence. + + Examples: + + - ``create_time > "2020-01-01" OR update_time > "2020-01-01"`` + Featurestores created or updated after 2020-01-01. + - ``labels.env = "prod"`` Featurestores with label "env" + set to "prod". + page_size (int): + The maximum number of Featurestores to + return. The service may return fewer than this + value. If unspecified, at most 100 Featurestores + will be returned. The maximum value is 100; any + value greater than 100 will be coerced to 100. + page_token (str): + A page token, received from a previous + [FeaturestoreService.ListFeaturestores][google.cloud.aiplatform.v1.FeaturestoreService.ListFeaturestores] + call. Provide this to retrieve the subsequent page. + + When paginating, all other parameters provided to + [FeaturestoreService.ListFeaturestores][google.cloud.aiplatform.v1.FeaturestoreService.ListFeaturestores] + must match the call that provided the page token. + order_by (str): + A comma-separated list of fields to order by, sorted in + ascending order. Use "desc" after a field name for + descending. Supported Fields: + + - ``create_time`` + - ``update_time`` + - ``online_serving_config.fixed_node_count`` + read_mask (google.protobuf.field_mask_pb2.FieldMask): + Mask specifying which fields to read. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + order_by = proto.Field( + proto.STRING, + number=5, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=6, + message=field_mask_pb2.FieldMask, + ) + + +class ListFeaturestoresResponse(proto.Message): + r"""Response message for + [FeaturestoreService.ListFeaturestores][google.cloud.aiplatform.v1.FeaturestoreService.ListFeaturestores]. + + Attributes: + featurestores (Sequence[google.cloud.aiplatform_v1.types.Featurestore]): + The Featurestores matching the request. + next_page_token (str): + A token, which can be sent as + [ListFeaturestoresRequest.page_token][google.cloud.aiplatform.v1.ListFeaturestoresRequest.page_token] + to retrieve the next page. If this field is omitted, there + are no subsequent pages. + """ + + @property + def raw_page(self): + return self + + featurestores = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gca_featurestore.Featurestore, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) + + +class UpdateFeaturestoreRequest(proto.Message): + r"""Request message for + [FeaturestoreService.UpdateFeaturestore][google.cloud.aiplatform.v1.FeaturestoreService.UpdateFeaturestore]. + + Attributes: + featurestore (google.cloud.aiplatform_v1.types.Featurestore): + Required. The Featurestore's ``name`` field is used to + identify the Featurestore to be updated. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}`` + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Field mask is used to specify the fields to be overwritten + in the Featurestore resource by the update. The fields + specified in the update_mask are relative to the resource, + not the full request. A field will be overwritten if it is + in the mask. If the user does not provide a mask then only + the non-empty fields present in the request will be + overwritten. Set the update_mask to ``*`` to override all + fields. + + Updatable fields: + + - ``labels`` + - ``online_serving_config.fixed_node_count`` + - ``online_serving_config.scaling`` + """ + + featurestore = proto.Field( + proto.MESSAGE, + number=1, + message=gca_featurestore.Featurestore, + ) + update_mask = proto.Field( + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) + + +class DeleteFeaturestoreRequest(proto.Message): + r"""Request message for + [FeaturestoreService.DeleteFeaturestore][google.cloud.aiplatform.v1.FeaturestoreService.DeleteFeaturestore]. + + Attributes: + name (str): + Required. The name of the Featurestore to be deleted. + Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}`` + force (bool): + If set to true, any EntityTypes and Features + for this Featurestore will also be deleted. + (Otherwise, the request will only work if the + Featurestore has no EntityTypes.) + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + force = proto.Field( + proto.BOOL, + number=2, + ) + + +class ImportFeatureValuesRequest(proto.Message): + r"""Request message for + [FeaturestoreService.ImportFeatureValues][google.cloud.aiplatform.v1.FeaturestoreService.ImportFeatureValues]. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + avro_source (google.cloud.aiplatform_v1.types.AvroSource): + + This field is a member of `oneof`_ ``source``. + bigquery_source (google.cloud.aiplatform_v1.types.BigQuerySource): + + This field is a member of `oneof`_ ``source``. + csv_source (google.cloud.aiplatform_v1.types.CsvSource): + + This field is a member of `oneof`_ ``source``. + feature_time_field (str): + Source column that holds the Feature + timestamp for all Feature values in each entity. + + This field is a member of `oneof`_ ``feature_time_source``. + feature_time (google.protobuf.timestamp_pb2.Timestamp): + Single Feature timestamp for all entities + being imported. The timestamp must not have + higher than millisecond precision. + + This field is a member of `oneof`_ ``feature_time_source``. + entity_type (str): + Required. The resource name of the EntityType grouping the + Features for which values are being imported. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entityType}`` + entity_id_field (str): + Source column that holds entity IDs. If not provided, entity + IDs are extracted from the column named ``entity_id``. + feature_specs (Sequence[google.cloud.aiplatform_v1.types.ImportFeatureValuesRequest.FeatureSpec]): + Required. Specifications defining which Feature values to + import from the entity. The request fails if no + feature_specs are provided, and having multiple + feature_specs for one Feature is not allowed. + disable_online_serving (bool): + If set, data will not be imported for online + serving. This is typically used for backfilling, + where Feature generation timestamps are not in + the timestamp range needed for online serving. + worker_count (int): + Specifies the number of workers that are used + to write data to the Featurestore. Consider the + online serving capacity that you require to + achieve the desired import throughput without + interfering with online serving. The value must + be positive, and less than or equal to 100. If + not set, defaults to using 1 worker. The low + count ensures minimal impact on online serving + performance. + disable_ingestion_analysis (bool): + If true, API doesn't start ingestion analysis + pipeline. + """ + + class FeatureSpec(proto.Message): + r"""Defines the Feature value(s) to import. + + Attributes: + id (str): + Required. ID of the Feature to import values + of. This Feature must exist in the target + EntityType, or the request will fail. + source_field (str): + Source column to get the Feature values from. + If not set, uses the column with the same name + as the Feature ID. + """ + + id = proto.Field( + proto.STRING, + number=1, + ) + source_field = proto.Field( + proto.STRING, + number=2, + ) + + avro_source = proto.Field( + proto.MESSAGE, + number=2, + oneof="source", + message=io.AvroSource, + ) + bigquery_source = proto.Field( + proto.MESSAGE, + number=3, + oneof="source", + message=io.BigQuerySource, + ) + csv_source = proto.Field( + proto.MESSAGE, + number=4, + oneof="source", + message=io.CsvSource, + ) + feature_time_field = proto.Field( + proto.STRING, + number=6, + oneof="feature_time_source", + ) + feature_time = proto.Field( + proto.MESSAGE, + number=7, + oneof="feature_time_source", + message=timestamp_pb2.Timestamp, + ) + entity_type = proto.Field( + proto.STRING, + number=1, + ) + entity_id_field = proto.Field( + proto.STRING, + number=5, + ) + feature_specs = proto.RepeatedField( + proto.MESSAGE, + number=8, + message=FeatureSpec, + ) + disable_online_serving = proto.Field( + proto.BOOL, + number=9, + ) + worker_count = proto.Field( + proto.INT32, + number=11, + ) + disable_ingestion_analysis = proto.Field( + proto.BOOL, + number=12, + ) + + +class ImportFeatureValuesResponse(proto.Message): + r"""Response message for + [FeaturestoreService.ImportFeatureValues][google.cloud.aiplatform.v1.FeaturestoreService.ImportFeatureValues]. + + Attributes: + imported_entity_count (int): + Number of entities that have been imported by + the operation. + imported_feature_value_count (int): + Number of Feature values that have been + imported by the operation. + invalid_row_count (int): + The number of rows in input source that weren't imported due + to either + + - Not having any featureValues. + - Having a null entityId. + - Having a null timestamp. + - Not being parsable (applicable for CSV sources). + """ + + imported_entity_count = proto.Field( + proto.INT64, + number=1, + ) + imported_feature_value_count = proto.Field( + proto.INT64, + number=2, + ) + invalid_row_count = proto.Field( + proto.INT64, + number=6, + ) + + +class BatchReadFeatureValuesRequest(proto.Message): + r"""Request message for + [FeaturestoreService.BatchReadFeatureValues][google.cloud.aiplatform.v1.FeaturestoreService.BatchReadFeatureValues]. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + csv_read_instances (google.cloud.aiplatform_v1.types.CsvSource): + Each read instance consists of exactly one read timestamp + and one or more entity IDs identifying entities of the + corresponding EntityTypes whose Features are requested. + + Each output instance contains Feature values of requested + entities concatenated together as of the read time. + + An example read instance may be + ``foo_entity_id, bar_entity_id, 2020-01-01T10:00:00.123Z``. + + An example output instance may be + ``foo_entity_id, bar_entity_id, 2020-01-01T10:00:00.123Z, foo_entity_feature1_value, bar_entity_feature2_value``. + + Timestamp in each read instance must be millisecond-aligned. + + ``csv_read_instances`` are read instances stored in a + plain-text CSV file. The header should be: + [ENTITY_TYPE_ID1], [ENTITY_TYPE_ID2], ..., timestamp + + The columns can be in any order. + + Values in the timestamp column must use the RFC 3339 format, + e.g. ``2012-07-30T10:43:17.123Z``. + + This field is a member of `oneof`_ ``read_option``. + bigquery_read_instances (google.cloud.aiplatform_v1.types.BigQuerySource): + Similar to csv_read_instances, but from BigQuery source. + + This field is a member of `oneof`_ ``read_option``. + featurestore (str): + Required. The resource name of the Featurestore from which + to query Feature values. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}`` + destination (google.cloud.aiplatform_v1.types.FeatureValueDestination): + Required. Specifies output location and + format. + pass_through_fields (Sequence[google.cloud.aiplatform_v1.types.BatchReadFeatureValuesRequest.PassThroughField]): + When not empty, the specified fields in the + \*_read_instances source will be joined as-is in the output, + in addition to those fields from the Featurestore Entity. + + For BigQuery source, the type of the pass-through values + will be automatically inferred. For CSV source, the + pass-through values will be passed as opaque bytes. + entity_type_specs (Sequence[google.cloud.aiplatform_v1.types.BatchReadFeatureValuesRequest.EntityTypeSpec]): + Required. Specifies EntityType grouping Features to read + values of and settings. Each EntityType referenced in + [BatchReadFeatureValuesRequest.entity_type_specs] must have + a column specifying entity IDs in the EntityType in + [BatchReadFeatureValuesRequest.request][] . + """ + + class PassThroughField(proto.Message): + r"""Describe pass-through fields in read_instance source. + + Attributes: + field_name (str): + Required. The name of the field in the CSV header or the + name of the column in BigQuery table. The naming restriction + is the same as + [Feature.name][google.cloud.aiplatform.v1.Feature.name]. + """ + + field_name = proto.Field( + proto.STRING, + number=1, + ) + + class EntityTypeSpec(proto.Message): + r"""Selects Features of an EntityType to read values of and + specifies read settings. + + Attributes: + entity_type_id (str): + Required. ID of the EntityType to select Features. The + EntityType id is the + [entity_type_id][google.cloud.aiplatform.v1.CreateEntityTypeRequest.entity_type_id] + specified during EntityType creation. + feature_selector (google.cloud.aiplatform_v1.types.FeatureSelector): + Required. Selectors choosing which Feature + values to read from the EntityType. + settings (Sequence[google.cloud.aiplatform_v1.types.DestinationFeatureSetting]): + Per-Feature settings for the batch read. + """ + + entity_type_id = proto.Field( + proto.STRING, + number=1, + ) + feature_selector = proto.Field( + proto.MESSAGE, + number=2, + message=gca_feature_selector.FeatureSelector, + ) + settings = proto.RepeatedField( + proto.MESSAGE, + number=3, + message="DestinationFeatureSetting", + ) + + csv_read_instances = proto.Field( + proto.MESSAGE, + number=3, + oneof="read_option", + message=io.CsvSource, + ) + bigquery_read_instances = proto.Field( + proto.MESSAGE, + number=5, + oneof="read_option", + message=io.BigQuerySource, + ) + featurestore = proto.Field( + proto.STRING, + number=1, + ) + destination = proto.Field( + proto.MESSAGE, + number=4, + message="FeatureValueDestination", + ) + pass_through_fields = proto.RepeatedField( + proto.MESSAGE, + number=8, + message=PassThroughField, + ) + entity_type_specs = proto.RepeatedField( + proto.MESSAGE, + number=7, + message=EntityTypeSpec, + ) + + +class ExportFeatureValuesRequest(proto.Message): + r"""Request message for + [FeaturestoreService.ExportFeatureValues][google.cloud.aiplatform.v1.FeaturestoreService.ExportFeatureValues]. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + snapshot_export (google.cloud.aiplatform_v1.types.ExportFeatureValuesRequest.SnapshotExport): + Exports the latest Feature values of all + entities of the EntityType within a time range. + + This field is a member of `oneof`_ ``mode``. + full_export (google.cloud.aiplatform_v1.types.ExportFeatureValuesRequest.FullExport): + Exports all historical values of all entities + of the EntityType within a time range + + This field is a member of `oneof`_ ``mode``. + entity_type (str): + Required. The resource name of the EntityType from which to + export Feature values. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}`` + destination (google.cloud.aiplatform_v1.types.FeatureValueDestination): + Required. Specifies destination location and + format. + feature_selector (google.cloud.aiplatform_v1.types.FeatureSelector): + Required. Selects Features to export values + of. + settings (Sequence[google.cloud.aiplatform_v1.types.DestinationFeatureSetting]): + Per-Feature export settings. + """ + + class SnapshotExport(proto.Message): + r"""Describes exporting the latest Feature values of all entities of the + EntityType between [start_time, snapshot_time]. + + Attributes: + snapshot_time (google.protobuf.timestamp_pb2.Timestamp): + Exports Feature values as of this timestamp. + If not set, retrieve values as of now. + Timestamp, if present, must not have higher than + millisecond precision. + start_time (google.protobuf.timestamp_pb2.Timestamp): + Excludes Feature values with feature + generation timestamp before this timestamp. If + not set, retrieve oldest values kept in Feature + Store. Timestamp, if present, must not have + higher than millisecond precision. + """ + + snapshot_time = proto.Field( + proto.MESSAGE, + number=1, + message=timestamp_pb2.Timestamp, + ) + start_time = proto.Field( + proto.MESSAGE, + number=2, + message=timestamp_pb2.Timestamp, + ) + + class FullExport(proto.Message): + r"""Describes exporting all historical Feature values of all entities of + the EntityType between [start_time, end_time]. + + Attributes: + start_time (google.protobuf.timestamp_pb2.Timestamp): + Excludes Feature values with feature + generation timestamp before this timestamp. If + not set, retrieve oldest values kept in Feature + Store. Timestamp, if present, must not have + higher than millisecond precision. + end_time (google.protobuf.timestamp_pb2.Timestamp): + Exports Feature values as of this timestamp. + If not set, retrieve values as of now. + Timestamp, if present, must not have higher than + millisecond precision. + """ + + start_time = proto.Field( + proto.MESSAGE, + number=2, + message=timestamp_pb2.Timestamp, + ) + end_time = proto.Field( + proto.MESSAGE, + number=1, + message=timestamp_pb2.Timestamp, + ) + + snapshot_export = proto.Field( + proto.MESSAGE, + number=3, + oneof="mode", + message=SnapshotExport, + ) + full_export = proto.Field( + proto.MESSAGE, + number=7, + oneof="mode", + message=FullExport, + ) + entity_type = proto.Field( + proto.STRING, + number=1, + ) + destination = proto.Field( + proto.MESSAGE, + number=4, + message="FeatureValueDestination", + ) + feature_selector = proto.Field( + proto.MESSAGE, + number=5, + message=gca_feature_selector.FeatureSelector, + ) + settings = proto.RepeatedField( + proto.MESSAGE, + number=6, + message="DestinationFeatureSetting", + ) + + +class DestinationFeatureSetting(proto.Message): + r""" + + Attributes: + feature_id (str): + Required. The ID of the Feature to apply the + setting to. + destination_field (str): + Specify the field name in the export + destination. If not specified, Feature ID is + used. + """ + + feature_id = proto.Field( + proto.STRING, + number=1, + ) + destination_field = proto.Field( + proto.STRING, + number=2, + ) + + +class FeatureValueDestination(proto.Message): + r"""A destination location for Feature values and format. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + bigquery_destination (google.cloud.aiplatform_v1.types.BigQueryDestination): + Output in BigQuery format. + [BigQueryDestination.output_uri][google.cloud.aiplatform.v1.BigQueryDestination.output_uri] + in + [FeatureValueDestination.bigquery_destination][google.cloud.aiplatform.v1.FeatureValueDestination.bigquery_destination] + must refer to a table. + + This field is a member of `oneof`_ ``destination``. + tfrecord_destination (google.cloud.aiplatform_v1.types.TFRecordDestination): + Output in TFRecord format. + + Below are the mapping from Feature value type in + Featurestore to Feature value type in TFRecord: + + :: + + Value type in Featurestore | Value type in TFRecord + DOUBLE, DOUBLE_ARRAY | FLOAT_LIST + INT64, INT64_ARRAY | INT64_LIST + STRING, STRING_ARRAY, BYTES | BYTES_LIST + true -> byte_string("true"), false -> byte_string("false") + BOOL, BOOL_ARRAY (true, false) | BYTES_LIST + + This field is a member of `oneof`_ ``destination``. + csv_destination (google.cloud.aiplatform_v1.types.CsvDestination): + Output in CSV format. Array Feature value + types are not allowed in CSV format. + + This field is a member of `oneof`_ ``destination``. + """ + + bigquery_destination = proto.Field( + proto.MESSAGE, + number=1, + oneof="destination", + message=io.BigQueryDestination, + ) + tfrecord_destination = proto.Field( + proto.MESSAGE, + number=2, + oneof="destination", + message=io.TFRecordDestination, + ) + csv_destination = proto.Field( + proto.MESSAGE, + number=3, + oneof="destination", + message=io.CsvDestination, + ) + + +class ExportFeatureValuesResponse(proto.Message): + r"""Response message for + [FeaturestoreService.ExportFeatureValues][google.cloud.aiplatform.v1.FeaturestoreService.ExportFeatureValues]. + + """ + + +class BatchReadFeatureValuesResponse(proto.Message): + r"""Response message for + [FeaturestoreService.BatchReadFeatureValues][google.cloud.aiplatform.v1.FeaturestoreService.BatchReadFeatureValues]. + + """ + + +class CreateEntityTypeRequest(proto.Message): + r"""Request message for + [FeaturestoreService.CreateEntityType][google.cloud.aiplatform.v1.FeaturestoreService.CreateEntityType]. + + Attributes: + parent (str): + Required. The resource name of the Featurestore to create + EntityTypes. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}`` + entity_type (google.cloud.aiplatform_v1.types.EntityType): + The EntityType to create. + entity_type_id (str): + Required. The ID to use for the EntityType, which will + become the final component of the EntityType's resource + name. + + This value may be up to 60 characters, and valid characters + are ``[a-z0-9_]``. The first character cannot be a number. + + The value must be unique within a featurestore. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + entity_type = proto.Field( + proto.MESSAGE, + number=2, + message=gca_entity_type.EntityType, + ) + entity_type_id = proto.Field( + proto.STRING, + number=3, + ) + + +class GetEntityTypeRequest(proto.Message): + r"""Request message for + [FeaturestoreService.GetEntityType][google.cloud.aiplatform.v1.FeaturestoreService.GetEntityType]. + + Attributes: + name (str): + Required. The name of the EntityType resource. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class ListEntityTypesRequest(proto.Message): + r"""Request message for + [FeaturestoreService.ListEntityTypes][google.cloud.aiplatform.v1.FeaturestoreService.ListEntityTypes]. + + Attributes: + parent (str): + Required. The resource name of the Featurestore to list + EntityTypes. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}`` + filter (str): + Lists the EntityTypes that match the filter expression. The + following filters are supported: + + - ``create_time``: Supports ``=``, ``!=``, ``<``, ``>``, + ``>=``, and ``<=`` comparisons. Values must be in RFC + 3339 format. + - ``update_time``: Supports ``=``, ``!=``, ``<``, ``>``, + ``>=``, and ``<=`` comparisons. Values must be in RFC + 3339 format. + - ``labels``: Supports key-value equality as well as key + presence. + + Examples: + + - ``create_time > \"2020-01-31T15:30:00.000000Z\" OR update_time > \"2020-01-31T15:30:00.000000Z\"`` + --> EntityTypes created or updated after + 2020-01-31T15:30:00.000000Z. + - ``labels.active = yes AND labels.env = prod`` --> + EntityTypes having both (active: yes) and (env: prod) + labels. + - ``labels.env: *`` --> Any EntityType which has a label + with 'env' as the key. + page_size (int): + The maximum number of EntityTypes to return. + The service may return fewer than this value. If + unspecified, at most 1000 EntityTypes will be + returned. The maximum value is 1000; any value + greater than 1000 will be coerced to 1000. + page_token (str): + A page token, received from a previous + [FeaturestoreService.ListEntityTypes][google.cloud.aiplatform.v1.FeaturestoreService.ListEntityTypes] + call. Provide this to retrieve the subsequent page. + + When paginating, all other parameters provided to + [FeaturestoreService.ListEntityTypes][google.cloud.aiplatform.v1.FeaturestoreService.ListEntityTypes] + must match the call that provided the page token. + order_by (str): + A comma-separated list of fields to order by, sorted in + ascending order. Use "desc" after a field name for + descending. + + Supported fields: + + - ``entity_type_id`` + - ``create_time`` + - ``update_time`` + read_mask (google.protobuf.field_mask_pb2.FieldMask): + Mask specifying which fields to read. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + order_by = proto.Field( + proto.STRING, + number=5, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=6, + message=field_mask_pb2.FieldMask, + ) + + +class ListEntityTypesResponse(proto.Message): + r"""Response message for + [FeaturestoreService.ListEntityTypes][google.cloud.aiplatform.v1.FeaturestoreService.ListEntityTypes]. + + Attributes: + entity_types (Sequence[google.cloud.aiplatform_v1.types.EntityType]): + The EntityTypes matching the request. + next_page_token (str): + A token, which can be sent as + [ListEntityTypesRequest.page_token][google.cloud.aiplatform.v1.ListEntityTypesRequest.page_token] + to retrieve the next page. If this field is omitted, there + are no subsequent pages. + """ + + @property + def raw_page(self): + return self + + entity_types = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gca_entity_type.EntityType, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) + + +class UpdateEntityTypeRequest(proto.Message): + r"""Request message for + [FeaturestoreService.UpdateEntityType][google.cloud.aiplatform.v1.FeaturestoreService.UpdateEntityType]. + + Attributes: + entity_type (google.cloud.aiplatform_v1.types.EntityType): + Required. The EntityType's ``name`` field is used to + identify the EntityType to be updated. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}`` + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Field mask is used to specify the fields to be overwritten + in the EntityType resource by the update. The fields + specified in the update_mask are relative to the resource, + not the full request. A field will be overwritten if it is + in the mask. If the user does not provide a mask then only + the non-empty fields present in the request will be + overwritten. Set the update_mask to ``*`` to override all + fields. + + Updatable fields: + + - ``description`` + - ``labels`` + - ``monitoring_config.snapshot_analysis.disabled`` + - ``monitoring_config.snapshot_analysis.monitoring_interval_days`` + - ``monitoring_config.snapshot_analysis.staleness_days`` + - ``monitoring_config.import_features_analysis.state`` + - ``monitoring_config.import_features_analysis.anomaly_detection_baseline`` + - ``monitoring_config.numerical_threshold_config.value`` + - ``monitoring_config.categorical_threshold_config.value`` + """ + + entity_type = proto.Field( + proto.MESSAGE, + number=1, + message=gca_entity_type.EntityType, + ) + update_mask = proto.Field( + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) + + +class DeleteEntityTypeRequest(proto.Message): + r"""Request message for [FeaturestoreService.DeleteEntityTypes][]. + + Attributes: + name (str): + Required. The name of the EntityType to be deleted. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}`` + force (bool): + If set to true, any Features for this + EntityType will also be deleted. (Otherwise, the + request will only work if the EntityType has no + Features.) + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + force = proto.Field( + proto.BOOL, + number=2, + ) + + +class CreateFeatureRequest(proto.Message): + r"""Request message for + [FeaturestoreService.CreateFeature][google.cloud.aiplatform.v1.FeaturestoreService.CreateFeature]. + + Attributes: + parent (str): + Required. The resource name of the EntityType to create a + Feature. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}`` + feature (google.cloud.aiplatform_v1.types.Feature): + Required. The Feature to create. + feature_id (str): + Required. The ID to use for the Feature, which will become + the final component of the Feature's resource name. + + This value may be up to 60 characters, and valid characters + are ``[a-z0-9_]``. The first character cannot be a number. + + The value must be unique within an EntityType. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + feature = proto.Field( + proto.MESSAGE, + number=2, + message=gca_feature.Feature, + ) + feature_id = proto.Field( + proto.STRING, + number=3, + ) + + +class BatchCreateFeaturesRequest(proto.Message): + r"""Request message for + [FeaturestoreService.BatchCreateFeatures][google.cloud.aiplatform.v1.FeaturestoreService.BatchCreateFeatures]. + + Attributes: + parent (str): + Required. The resource name of the EntityType to create the + batch of Features under. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}`` + requests (Sequence[google.cloud.aiplatform_v1.types.CreateFeatureRequest]): + Required. The request message specifying the Features to + create. All Features must be created under the same parent + EntityType. The ``parent`` field in each child request + message can be omitted. If ``parent`` is set in a child + request, then the value must match the ``parent`` value in + this request message. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + requests = proto.RepeatedField( + proto.MESSAGE, + number=2, + message="CreateFeatureRequest", + ) + + +class BatchCreateFeaturesResponse(proto.Message): + r"""Response message for + [FeaturestoreService.BatchCreateFeatures][google.cloud.aiplatform.v1.FeaturestoreService.BatchCreateFeatures]. + + Attributes: + features (Sequence[google.cloud.aiplatform_v1.types.Feature]): + The Features created. + """ + + features = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gca_feature.Feature, + ) + + +class GetFeatureRequest(proto.Message): + r"""Request message for + [FeaturestoreService.GetFeature][google.cloud.aiplatform.v1.FeaturestoreService.GetFeature]. + + Attributes: + name (str): + Required. The name of the Feature resource. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class ListFeaturesRequest(proto.Message): + r"""Request message for + [FeaturestoreService.ListFeatures][google.cloud.aiplatform.v1.FeaturestoreService.ListFeatures]. + + Attributes: + parent (str): + Required. The resource name of the Location to list + Features. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}`` + filter (str): + Lists the Features that match the filter expression. The + following filters are supported: + + - ``value_type``: Supports = and != comparisons. + - ``create_time``: Supports =, !=, <, >, >=, and <= + comparisons. Values must be in RFC 3339 format. + - ``update_time``: Supports =, !=, <, >, >=, and <= + comparisons. Values must be in RFC 3339 format. + - ``labels``: Supports key-value equality as well as key + presence. + + Examples: + + - ``value_type = DOUBLE`` --> Features whose type is + DOUBLE. + - ``create_time > \"2020-01-31T15:30:00.000000Z\" OR update_time > \"2020-01-31T15:30:00.000000Z\"`` + --> EntityTypes created or updated after + 2020-01-31T15:30:00.000000Z. + - ``labels.active = yes AND labels.env = prod`` --> + Features having both (active: yes) and (env: prod) + labels. + - ``labels.env: *`` --> Any Feature which has a label with + 'env' as the key. + page_size (int): + The maximum number of Features to return. The + service may return fewer than this value. If + unspecified, at most 1000 Features will be + returned. The maximum value is 1000; any value + greater than 1000 will be coerced to 1000. + page_token (str): + A page token, received from a previous + [FeaturestoreService.ListFeatures][google.cloud.aiplatform.v1.FeaturestoreService.ListFeatures] + call. Provide this to retrieve the subsequent page. + + When paginating, all other parameters provided to + [FeaturestoreService.ListFeatures][google.cloud.aiplatform.v1.FeaturestoreService.ListFeatures] + must match the call that provided the page token. + order_by (str): + A comma-separated list of fields to order by, sorted in + ascending order. Use "desc" after a field name for + descending. Supported fields: + + - ``feature_id`` + - ``value_type`` + - ``create_time`` + - ``update_time`` + read_mask (google.protobuf.field_mask_pb2.FieldMask): + Mask specifying which fields to read. + latest_stats_count (int): + If set, return the most recent + [ListFeaturesRequest.latest_stats_count][google.cloud.aiplatform.v1.ListFeaturesRequest.latest_stats_count] + of stats for each Feature in response. Valid value is [0, + 10]. If number of stats exists < + [ListFeaturesRequest.latest_stats_count][google.cloud.aiplatform.v1.ListFeaturesRequest.latest_stats_count], + return all existing stats. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + order_by = proto.Field( + proto.STRING, + number=5, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=6, + message=field_mask_pb2.FieldMask, + ) + latest_stats_count = proto.Field( + proto.INT32, + number=7, + ) + + +class ListFeaturesResponse(proto.Message): + r"""Response message for + [FeaturestoreService.ListFeatures][google.cloud.aiplatform.v1.FeaturestoreService.ListFeatures]. + + Attributes: + features (Sequence[google.cloud.aiplatform_v1.types.Feature]): + The Features matching the request. + next_page_token (str): + A token, which can be sent as + [ListFeaturesRequest.page_token][google.cloud.aiplatform.v1.ListFeaturesRequest.page_token] + to retrieve the next page. If this field is omitted, there + are no subsequent pages. + """ + + @property + def raw_page(self): + return self + + features = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gca_feature.Feature, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) + + +class SearchFeaturesRequest(proto.Message): + r"""Request message for + [FeaturestoreService.SearchFeatures][google.cloud.aiplatform.v1.FeaturestoreService.SearchFeatures]. + + Attributes: + location (str): + Required. The resource name of the Location to search + Features. Format: + ``projects/{project}/locations/{location}`` + query (str): + Query string that is a conjunction of field-restricted + queries and/or field-restricted filters. Field-restricted + queries and filters can be combined using ``AND`` to form a + conjunction. + + A field query is in the form FIELD:QUERY. This implicitly + checks if QUERY exists as a substring within Feature's + FIELD. The QUERY and the FIELD are converted to a sequence + of words (i.e. tokens) for comparison. This is done by: + + - Removing leading/trailing whitespace and tokenizing the + search value. Characters that are not one of alphanumeric + ``[a-zA-Z0-9]``, underscore ``_``, or asterisk ``*`` are + treated as delimiters for tokens. ``*`` is treated as a + wildcard that matches characters within a token. + - Ignoring case. + - Prepending an asterisk to the first and appending an + asterisk to the last token in QUERY. + + A QUERY must be either a singular token or a phrase. A + phrase is one or multiple words enclosed in double quotation + marks ("). With phrases, the order of the words is + important. Words in the phrase must be matching in order and + consecutively. + + Supported FIELDs for field-restricted queries: + + - ``feature_id`` + - ``description`` + - ``entity_type_id`` + + Examples: + + - ``feature_id: foo`` --> Matches a Feature with ID + containing the substring ``foo`` (eg. ``foo``, + ``foofeature``, ``barfoo``). + - ``feature_id: foo*feature`` --> Matches a Feature with ID + containing the substring ``foo*feature`` (eg. + ``foobarfeature``). + - ``feature_id: foo AND description: bar`` --> Matches a + Feature with ID containing the substring ``foo`` and + description containing the substring ``bar``. + + Besides field queries, the following exact-match filters are + supported. The exact-match filters do not support wildcards. + Unlike field-restricted queries, exact-match filters are + case-sensitive. + + - ``feature_id``: Supports = comparisons. + - ``description``: Supports = comparisons. Multi-token + filters should be enclosed in quotes. + - ``entity_type_id``: Supports = comparisons. + - ``value_type``: Supports = and != comparisons. + - ``labels``: Supports key-value equality as well as key + presence. + - ``featurestore_id``: Supports = comparisons. + + Examples: + + - ``description = "foo bar"`` --> Any Feature with + description exactly equal to ``foo bar`` + - ``value_type = DOUBLE`` --> Features whose type is + DOUBLE. + - ``labels.active = yes AND labels.env = prod`` --> + Features having both (active: yes) and (env: prod) + labels. + - ``labels.env: *`` --> Any Feature which has a label with + ``env`` as the key. + page_size (int): + The maximum number of Features to return. The + service may return fewer than this value. If + unspecified, at most 100 Features will be + returned. The maximum value is 100; any value + greater than 100 will be coerced to 100. + page_token (str): + A page token, received from a previous + [FeaturestoreService.SearchFeatures][google.cloud.aiplatform.v1.FeaturestoreService.SearchFeatures] + call. Provide this to retrieve the subsequent page. + + When paginating, all other parameters provided to + [FeaturestoreService.SearchFeatures][google.cloud.aiplatform.v1.FeaturestoreService.SearchFeatures], + except ``page_size``, must match the call that provided the + page token. + """ + + location = proto.Field( + proto.STRING, + number=1, + ) + query = proto.Field( + proto.STRING, + number=3, + ) + page_size = proto.Field( + proto.INT32, + number=4, + ) + page_token = proto.Field( + proto.STRING, + number=5, + ) + + +class SearchFeaturesResponse(proto.Message): + r"""Response message for + [FeaturestoreService.SearchFeatures][google.cloud.aiplatform.v1.FeaturestoreService.SearchFeatures]. + + Attributes: + features (Sequence[google.cloud.aiplatform_v1.types.Feature]): + The Features matching the request. + + Fields returned: + + - ``name`` + - ``description`` + - ``labels`` + - ``create_time`` + - ``update_time`` + next_page_token (str): + A token, which can be sent as + [SearchFeaturesRequest.page_token][google.cloud.aiplatform.v1.SearchFeaturesRequest.page_token] + to retrieve the next page. If this field is omitted, there + are no subsequent pages. + """ + + @property + def raw_page(self): + return self + + features = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gca_feature.Feature, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) + + +class UpdateFeatureRequest(proto.Message): + r"""Request message for + [FeaturestoreService.UpdateFeature][google.cloud.aiplatform.v1.FeaturestoreService.UpdateFeature]. + + Attributes: + feature (google.cloud.aiplatform_v1.types.Feature): + Required. The Feature's ``name`` field is used to identify + the Feature to be updated. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}/features/{feature}`` + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Field mask is used to specify the fields to be overwritten + in the Features resource by the update. The fields specified + in the update_mask are relative to the resource, not the + full request. A field will be overwritten if it is in the + mask. If the user does not provide a mask then only the + non-empty fields present in the request will be overwritten. + Set the update_mask to ``*`` to override all fields. + + Updatable fields: + + - ``description`` + - ``labels`` + - ``disable_monitoring`` + """ + + feature = proto.Field( + proto.MESSAGE, + number=1, + message=gca_feature.Feature, + ) + update_mask = proto.Field( + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) + + +class DeleteFeatureRequest(proto.Message): + r"""Request message for + [FeaturestoreService.DeleteFeature][google.cloud.aiplatform.v1.FeaturestoreService.DeleteFeature]. + + Attributes: + name (str): + Required. The name of the Features to be deleted. Format: + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}/features/{feature}`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class CreateFeaturestoreOperationMetadata(proto.Message): + r"""Details of operations that perform create Featurestore. + + Attributes: + generic_metadata (google.cloud.aiplatform_v1.types.GenericOperationMetadata): + Operation metadata for Featurestore. + """ + + generic_metadata = proto.Field( + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, + ) + + +class UpdateFeaturestoreOperationMetadata(proto.Message): + r"""Details of operations that perform update Featurestore. + + Attributes: + generic_metadata (google.cloud.aiplatform_v1.types.GenericOperationMetadata): + Operation metadata for Featurestore. + """ + + generic_metadata = proto.Field( + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, + ) + + +class ImportFeatureValuesOperationMetadata(proto.Message): + r"""Details of operations that perform import Feature values. + + Attributes: + generic_metadata (google.cloud.aiplatform_v1.types.GenericOperationMetadata): + Operation metadata for Featurestore import + Feature values. + imported_entity_count (int): + Number of entities that have been imported by + the operation. + imported_feature_value_count (int): + Number of Feature values that have been + imported by the operation. + invalid_row_count (int): + The number of rows in input source that weren't imported due + to either + + - Not having any featureValues. + - Having a null entityId. + - Having a null timestamp. + - Not being parsable (applicable for CSV sources). + """ + + generic_metadata = proto.Field( + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, + ) + imported_entity_count = proto.Field( + proto.INT64, + number=2, + ) + imported_feature_value_count = proto.Field( + proto.INT64, + number=3, + ) + invalid_row_count = proto.Field( + proto.INT64, + number=6, + ) + + +class ExportFeatureValuesOperationMetadata(proto.Message): + r"""Details of operations that exports Features values. + + Attributes: + generic_metadata (google.cloud.aiplatform_v1.types.GenericOperationMetadata): + Operation metadata for Featurestore export + Feature values. + """ + + generic_metadata = proto.Field( + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, + ) + + +class BatchReadFeatureValuesOperationMetadata(proto.Message): + r"""Details of operations that batch reads Feature values. + + Attributes: + generic_metadata (google.cloud.aiplatform_v1.types.GenericOperationMetadata): + Operation metadata for Featurestore batch + read Features values. + """ + + generic_metadata = proto.Field( + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, + ) + + +class CreateEntityTypeOperationMetadata(proto.Message): + r"""Details of operations that perform create EntityType. + + Attributes: + generic_metadata (google.cloud.aiplatform_v1.types.GenericOperationMetadata): + Operation metadata for EntityType. + """ + + generic_metadata = proto.Field( + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, + ) + + +class CreateFeatureOperationMetadata(proto.Message): + r"""Details of operations that perform create Feature. + + Attributes: + generic_metadata (google.cloud.aiplatform_v1.types.GenericOperationMetadata): + Operation metadata for Feature. + """ + + generic_metadata = proto.Field( + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, + ) + + +class BatchCreateFeaturesOperationMetadata(proto.Message): + r"""Details of operations that perform batch create Features. + + Attributes: + generic_metadata (google.cloud.aiplatform_v1.types.GenericOperationMetadata): + Operation metadata for Feature. + """ + + generic_metadata = proto.Field( + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/hyperparameter_tuning_job.py b/google/cloud/aiplatform_v1/types/hyperparameter_tuning_job.py index d5485873a6..55aa325755 100644 --- a/google/cloud/aiplatform_v1/types/hyperparameter_tuning_job.py +++ b/google/cloud/aiplatform_v1/types/hyperparameter_tuning_job.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -24,7 +24,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1", manifest={"HyperparameterTuningJob",}, + package="google.cloud.aiplatform.v1", + manifest={ + "HyperparameterTuningJob", + }, ) @@ -53,7 +56,7 @@ class HyperparameterTuningJob(proto.Message): max_failed_trial_count (int): The number of failed Trials that need to be seen before failing the HyperparameterTuningJob. - If set to 0, AI Platform decides how many Trials + If set to 0, Vertex AI decides how many Trials must fail before the whole job fails. trial_job_spec (google.cloud.aiplatform_v1.types.CustomJobSpec): Required. The spec of a trial job. The same @@ -81,7 +84,7 @@ class HyperparameterTuningJob(proto.Message): error (google.rpc.status_pb2.Status): Output only. Only populated when job's state is JOB_STATE_FAILED or JOB_STATE_CANCELLED. - labels (Sequence[google.cloud.aiplatform_v1.types.HyperparameterTuningJob.LabelsEntry]): + labels (Mapping[str, str]): The labels with user-defined metadata to organize HyperparameterTuningJobs. Label keys and values can be no longer than 64 @@ -99,29 +102,80 @@ class HyperparameterTuningJob(proto.Message): the provided encryption key. """ - name = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) - study_spec = proto.Field(proto.MESSAGE, number=4, message=study.StudySpec,) - max_trial_count = proto.Field(proto.INT32, number=5,) - parallel_trial_count = proto.Field(proto.INT32, number=6,) - max_failed_trial_count = proto.Field(proto.INT32, number=7,) + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + study_spec = proto.Field( + proto.MESSAGE, + number=4, + message=study.StudySpec, + ) + max_trial_count = proto.Field( + proto.INT32, + number=5, + ) + parallel_trial_count = proto.Field( + proto.INT32, + number=6, + ) + max_failed_trial_count = proto.Field( + proto.INT32, + number=7, + ) trial_job_spec = proto.Field( - proto.MESSAGE, number=8, message=custom_job.CustomJobSpec, + proto.MESSAGE, + number=8, + message=custom_job.CustomJobSpec, + ) + trials = proto.RepeatedField( + proto.MESSAGE, + number=9, + message=study.Trial, + ) + state = proto.Field( + proto.ENUM, + number=10, + enum=job_state.JobState, ) - trials = proto.RepeatedField(proto.MESSAGE, number=9, message=study.Trial,) - state = proto.Field(proto.ENUM, number=10, enum=job_state.JobState,) create_time = proto.Field( - proto.MESSAGE, number=11, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=11, + message=timestamp_pb2.Timestamp, + ) + start_time = proto.Field( + proto.MESSAGE, + number=12, + message=timestamp_pb2.Timestamp, + ) + end_time = proto.Field( + proto.MESSAGE, + number=13, + message=timestamp_pb2.Timestamp, ) - start_time = proto.Field(proto.MESSAGE, number=12, message=timestamp_pb2.Timestamp,) - end_time = proto.Field(proto.MESSAGE, number=13, message=timestamp_pb2.Timestamp,) update_time = proto.Field( - proto.MESSAGE, number=14, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=14, + message=timestamp_pb2.Timestamp, + ) + error = proto.Field( + proto.MESSAGE, + number=15, + message=status_pb2.Status, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=16, ) - error = proto.Field(proto.MESSAGE, number=15, message=status_pb2.Status,) - labels = proto.MapField(proto.STRING, proto.STRING, number=16,) encryption_spec = proto.Field( - proto.MESSAGE, number=17, message=gca_encryption_spec.EncryptionSpec, + proto.MESSAGE, + number=17, + message=gca_encryption_spec.EncryptionSpec, ) diff --git a/google/cloud/aiplatform_v1/types/index.py b/google/cloud/aiplatform_v1/types/index.py new file mode 100644 index 0000000000..c119df7780 --- /dev/null +++ b/google/cloud/aiplatform_v1/types/index.py @@ -0,0 +1,142 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + +from google.cloud.aiplatform_v1.types import deployed_index_ref +from google.protobuf import struct_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "Index", + }, +) + + +class Index(proto.Message): + r"""A representation of a collection of database items organized + in a way that allows for approximate nearest neighbor (a.k.a + ANN) algorithms search. + + Attributes: + name (str): + Output only. The resource name of the Index. + display_name (str): + Required. The display name of the Index. + The name can be up to 128 characters long and + can be consist of any UTF-8 characters. + description (str): + The description of the Index. + metadata_schema_uri (str): + Immutable. Points to a YAML file stored on Google Cloud + Storage describing additional information about the Index, + that is specific to it. Unset if the Index does not have any + additional information. The schema is defined as an OpenAPI + 3.0.2 `Schema + Object `__. + Note: The URI given on output will be immutable and probably + different, including the URI scheme, than the one given on + input. The output URI will point to a location where the + user only has a read access. + metadata (google.protobuf.struct_pb2.Value): + An additional information about the Index; the schema of the + metadata can be found in + [metadata_schema][google.cloud.aiplatform.v1.Index.metadata_schema_uri]. + deployed_indexes (Sequence[google.cloud.aiplatform_v1.types.DeployedIndexRef]): + Output only. The pointers to DeployedIndexes + created from this Index. An Index can be only + deleted if all its DeployedIndexes had been + undeployed first. + etag (str): + Used to perform consistent read-modify-write + updates. If not set, a blind "overwrite" update + happens. + labels (Mapping[str, str]): + The labels with user-defined metadata to + organize your Indexes. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + and examples of labels. + create_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp when this Index was + created. + update_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp when this Index was most recently + updated. This also includes any update to the contents of + the Index. Note that Operations working on this Index may + have their + [Operations.metadata.generic_metadata.update_time] + [google.cloud.aiplatform.v1.GenericOperationMetadata.update_time] + a little after the value of this timestamp, yet that does + not mean their results are not already reflected in the + Index. Result of any successfully completed Operation on the + Index is reflected in it. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + description = proto.Field( + proto.STRING, + number=3, + ) + metadata_schema_uri = proto.Field( + proto.STRING, + number=4, + ) + metadata = proto.Field( + proto.MESSAGE, + number=6, + message=struct_pb2.Value, + ) + deployed_indexes = proto.RepeatedField( + proto.MESSAGE, + number=7, + message=deployed_index_ref.DeployedIndexRef, + ) + etag = proto.Field( + proto.STRING, + number=8, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=9, + ) + create_time = proto.Field( + proto.MESSAGE, + number=10, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=11, + message=timestamp_pb2.Timestamp, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/index_endpoint.py b/google/cloud/aiplatform_v1/types/index_endpoint.py new file mode 100644 index 0000000000..6cfbc20e44 --- /dev/null +++ b/google/cloud/aiplatform_v1/types/index_endpoint.py @@ -0,0 +1,384 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + +from google.cloud.aiplatform_v1.types import machine_resources +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "IndexEndpoint", + "DeployedIndex", + "DeployedIndexAuthConfig", + "IndexPrivateEndpoints", + }, +) + + +class IndexEndpoint(proto.Message): + r"""Indexes are deployed into it. An IndexEndpoint can have + multiple DeployedIndexes. + + Attributes: + name (str): + Output only. The resource name of the + IndexEndpoint. + display_name (str): + Required. The display name of the + IndexEndpoint. The name can be up to 128 + characters long and can consist of any UTF-8 + characters. + description (str): + The description of the IndexEndpoint. + deployed_indexes (Sequence[google.cloud.aiplatform_v1.types.DeployedIndex]): + Output only. The indexes deployed in this + endpoint. + etag (str): + Used to perform consistent read-modify-write + updates. If not set, a blind "overwrite" update + happens. + labels (Mapping[str, str]): + The labels with user-defined metadata to + organize your IndexEndpoints. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + and examples of labels. + create_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp when this + IndexEndpoint was created. + update_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp when this + IndexEndpoint was last updated. This timestamp + is not updated when the endpoint's + DeployedIndexes are updated, e.g. due to updates + of the original Indexes they are the deployments + of. + network (str): + Optional. The full name of the Google Compute Engine + `network `__ + to which the IndexEndpoint should be peered. + + Private services access must already be configured for the + network. If left unspecified, the Endpoint is not peered + with any network. + + [network][google.cloud.aiplatform.v1.IndexEndpoint.network] + and + [private_service_connect_config][google.cloud.aiplatform.v1.IndexEndpoint.private_service_connect_config] + are mutually exclusive. + + `Format `__: + projects/{project}/global/networks/{network}. Where + {project} is a project number, as in '12345', and {network} + is network name. + enable_private_service_connect (bool): + Optional. Deprecated: If true, expose the IndexEndpoint via + private service connect. + + Only one of the fields, + [network][google.cloud.aiplatform.v1.IndexEndpoint.network] + or + [enable_private_service_connect][google.cloud.aiplatform.v1.IndexEndpoint.enable_private_service_connect], + can be set. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + description = proto.Field( + proto.STRING, + number=3, + ) + deployed_indexes = proto.RepeatedField( + proto.MESSAGE, + number=4, + message="DeployedIndex", + ) + etag = proto.Field( + proto.STRING, + number=5, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=6, + ) + create_time = proto.Field( + proto.MESSAGE, + number=7, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=8, + message=timestamp_pb2.Timestamp, + ) + network = proto.Field( + proto.STRING, + number=9, + ) + enable_private_service_connect = proto.Field( + proto.BOOL, + number=10, + ) + + +class DeployedIndex(proto.Message): + r"""A deployment of an Index. IndexEndpoints contain one or more + DeployedIndexes. + + Attributes: + id (str): + Required. The user specified ID of the + DeployedIndex. The ID can be up to 128 + characters long and must start with a letter and + only contain letters, numbers, and underscores. + The ID must be unique within the project it is + created in. + index (str): + Required. The name of the Index this is the + deployment of. We may refer to this Index as the + DeployedIndex's "original" Index. + display_name (str): + The display name of the DeployedIndex. If not provided upon + creation, the Index's display_name is used. + create_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp when the DeployedIndex + was created. + private_endpoints (google.cloud.aiplatform_v1.types.IndexPrivateEndpoints): + Output only. Provides paths for users to send requests + directly to the deployed index services running on Cloud via + private services access. This field is populated if + [network][google.cloud.aiplatform.v1.IndexEndpoint.network] + is configured. + index_sync_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. The DeployedIndex may depend on various data on + its original Index. Additionally when certain changes to the + original Index are being done (e.g. when what the Index + contains is being changed) the DeployedIndex may be + asynchronously updated in the background to reflect this + changes. If this timestamp's value is at least the + [Index.update_time][google.cloud.aiplatform.v1.Index.update_time] + of the original Index, it means that this DeployedIndex and + the original Index are in sync. If this timestamp is older, + then to see which updates this DeployedIndex already + contains (and which not), one must + [list][Operations.ListOperations] [Operations][Operation] + [working][Operation.name] on the original Index. Only the + successfully completed Operations with + [Operations.metadata.generic_metadata.update_time] + [google.cloud.aiplatform.v1.GenericOperationMetadata.update_time] + equal or before this sync time are contained in this + DeployedIndex. + automatic_resources (google.cloud.aiplatform_v1.types.AutomaticResources): + Optional. A description of resources that the DeployedIndex + uses, which to large degree are decided by Vertex AI, and + optionally allows only a modest additional configuration. If + min_replica_count is not set, the default value is 2 (we + don't provide SLA when min_replica_count=1). If + max_replica_count is not set, the default value is + min_replica_count. The max allowed replica count is 1000. + dedicated_resources (google.cloud.aiplatform_v1.types.DedicatedResources): + Optional. A description of resources that are dedicated to + the DeployedIndex, and that need a higher degree of manual + configuration. If min_replica_count is not set, the default + value is 2 (we don't provide SLA when min_replica_count=1). + If max_replica_count is not set, the default value is + min_replica_count. The max allowed replica count is 1000. + + Available machine types: n1-standard-16 n1-standard-32 + enable_access_logging (bool): + Optional. If true, private endpoint's access + logs are sent to StackDriver Logging. + These logs are like standard server access logs, + containing information like timestamp and + latency for each MatchRequest. + Note that Stackdriver logs may incur a cost, + especially if the deployed index receives a high + queries per second rate (QPS). Estimate your + costs before enabling this option. + deployed_index_auth_config (google.cloud.aiplatform_v1.types.DeployedIndexAuthConfig): + Optional. If set, the authentication is + enabled for the private endpoint. + reserved_ip_ranges (Sequence[str]): + Optional. A list of reserved ip ranges under + the VPC network that can be used for this + DeployedIndex. + If set, we will deploy the index within the + provided ip ranges. Otherwise, the index might + be deployed to any ip ranges under the provided + VPC network. + + The value sohuld be the name of the address + (https://cloud.google.com/compute/docs/reference/rest/v1/addresses) + Example: 'vertex-ai-ip-range'. + deployment_group (str): + Optional. The deployment group can be no longer than 64 + characters (eg: 'test', 'prod'). If not set, we will use the + 'default' deployment group. + + Creating ``deployment_groups`` with ``reserved_ip_ranges`` + is a recommended practice when the peered network has + multiple peering ranges. This creates your deployments from + predictable IP spaces for easier traffic administration. + Also, one deployment_group (except 'default') can only be + used with the same reserved_ip_ranges which means if the + deployment_group has been used with reserved_ip_ranges: [a, + b, c], using it with [a, b] or [d, e] is disallowed. + + Note: we only support up to 5 deployment groups(not + including 'default'). + """ + + id = proto.Field( + proto.STRING, + number=1, + ) + index = proto.Field( + proto.STRING, + number=2, + ) + display_name = proto.Field( + proto.STRING, + number=3, + ) + create_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + private_endpoints = proto.Field( + proto.MESSAGE, + number=5, + message="IndexPrivateEndpoints", + ) + index_sync_time = proto.Field( + proto.MESSAGE, + number=6, + message=timestamp_pb2.Timestamp, + ) + automatic_resources = proto.Field( + proto.MESSAGE, + number=7, + message=machine_resources.AutomaticResources, + ) + dedicated_resources = proto.Field( + proto.MESSAGE, + number=16, + message=machine_resources.DedicatedResources, + ) + enable_access_logging = proto.Field( + proto.BOOL, + number=8, + ) + deployed_index_auth_config = proto.Field( + proto.MESSAGE, + number=9, + message="DeployedIndexAuthConfig", + ) + reserved_ip_ranges = proto.RepeatedField( + proto.STRING, + number=10, + ) + deployment_group = proto.Field( + proto.STRING, + number=11, + ) + + +class DeployedIndexAuthConfig(proto.Message): + r"""Used to set up the auth on the DeployedIndex's private + endpoint. + + Attributes: + auth_provider (google.cloud.aiplatform_v1.types.DeployedIndexAuthConfig.AuthProvider): + Defines the authentication provider that the + DeployedIndex uses. + """ + + class AuthProvider(proto.Message): + r"""Configuration for an authentication provider, including support for + `JSON Web Token + (JWT) `__. + + Attributes: + audiences (Sequence[str]): + The list of JWT + `audiences `__. + that are allowed to access. A JWT containing any of these + audiences will be accepted. + allowed_issuers (Sequence[str]): + A list of allowed JWT issuers. Each entry must be a valid + Google service account, in the following format: + + ``service-account-name@project-id.iam.gserviceaccount.com`` + """ + + audiences = proto.RepeatedField( + proto.STRING, + number=1, + ) + allowed_issuers = proto.RepeatedField( + proto.STRING, + number=2, + ) + + auth_provider = proto.Field( + proto.MESSAGE, + number=1, + message=AuthProvider, + ) + + +class IndexPrivateEndpoints(proto.Message): + r"""IndexPrivateEndpoints proto is used to provide paths for users to + send requests via private endpoints (e.g. private service access, + private service connect). To send request via private service + access, use match_grpc_address. To send request via private service + connect, use service_attachment. + + Attributes: + match_grpc_address (str): + Output only. The ip address used to send + match gRPC requests. + service_attachment (str): + Output only. The name of the service + attachment resource. Populated if private + service connect is enabled. + """ + + match_grpc_address = proto.Field( + proto.STRING, + number=1, + ) + service_attachment = proto.Field( + proto.STRING, + number=2, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/index_endpoint_service.py b/google/cloud/aiplatform_v1/types/index_endpoint_service.py new file mode 100644 index 0000000000..9abafa6784 --- /dev/null +++ b/google/cloud/aiplatform_v1/types/index_endpoint_service.py @@ -0,0 +1,419 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + +from google.cloud.aiplatform_v1.types import index_endpoint as gca_index_endpoint +from google.cloud.aiplatform_v1.types import operation +from google.protobuf import field_mask_pb2 # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "CreateIndexEndpointRequest", + "CreateIndexEndpointOperationMetadata", + "GetIndexEndpointRequest", + "ListIndexEndpointsRequest", + "ListIndexEndpointsResponse", + "UpdateIndexEndpointRequest", + "DeleteIndexEndpointRequest", + "DeployIndexRequest", + "DeployIndexResponse", + "DeployIndexOperationMetadata", + "UndeployIndexRequest", + "UndeployIndexResponse", + "UndeployIndexOperationMetadata", + "MutateDeployedIndexRequest", + "MutateDeployedIndexResponse", + "MutateDeployedIndexOperationMetadata", + }, +) + + +class CreateIndexEndpointRequest(proto.Message): + r"""Request message for + [IndexEndpointService.CreateIndexEndpoint][google.cloud.aiplatform.v1.IndexEndpointService.CreateIndexEndpoint]. + + Attributes: + parent (str): + Required. The resource name of the Location to create the + IndexEndpoint in. Format: + ``projects/{project}/locations/{location}`` + index_endpoint (google.cloud.aiplatform_v1.types.IndexEndpoint): + Required. The IndexEndpoint to create. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + index_endpoint = proto.Field( + proto.MESSAGE, + number=2, + message=gca_index_endpoint.IndexEndpoint, + ) + + +class CreateIndexEndpointOperationMetadata(proto.Message): + r"""Runtime operation information for + [IndexEndpointService.CreateIndexEndpoint][google.cloud.aiplatform.v1.IndexEndpointService.CreateIndexEndpoint]. + + Attributes: + generic_metadata (google.cloud.aiplatform_v1.types.GenericOperationMetadata): + The operation generic information. + """ + + generic_metadata = proto.Field( + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, + ) + + +class GetIndexEndpointRequest(proto.Message): + r"""Request message for + [IndexEndpointService.GetIndexEndpoint][google.cloud.aiplatform.v1.IndexEndpointService.GetIndexEndpoint] + + Attributes: + name (str): + Required. The name of the IndexEndpoint resource. Format: + ``projects/{project}/locations/{location}/indexEndpoints/{index_endpoint}`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class ListIndexEndpointsRequest(proto.Message): + r"""Request message for + [IndexEndpointService.ListIndexEndpoints][google.cloud.aiplatform.v1.IndexEndpointService.ListIndexEndpoints]. + + Attributes: + parent (str): + Required. The resource name of the Location from which to + list the IndexEndpoints. Format: + ``projects/{project}/locations/{location}`` + filter (str): + Optional. An expression for filtering the results of the + request. For field names both snake_case and camelCase are + supported. + + - ``index_endpoint`` supports = and !=. ``index_endpoint`` + represents the IndexEndpoint ID, ie. the last segment of + the IndexEndpoint's + [resourcename][google.cloud.aiplatform.v1.IndexEndpoint.name]. + - ``display_name`` supports =, != and regex() (uses + `re2 `__ + syntax) + - ``labels`` supports general map functions that is: + ``labels.key=value`` - key:value equality + ``labels.key:* or labels:key - key existence A key including a space must be quoted.``\ labels."a + key"`. + + Some examples: + + - ``index_endpoint="1"`` + - ``display_name="myDisplayName"`` + - \`regex(display_name, "^A") -> The display name starts + with an A. + - ``labels.myKey="myValue"`` + page_size (int): + Optional. The standard list page size. + page_token (str): + Optional. The standard list page token. Typically obtained + via + [ListIndexEndpointsResponse.next_page_token][google.cloud.aiplatform.v1.ListIndexEndpointsResponse.next_page_token] + of the previous + [IndexEndpointService.ListIndexEndpoints][google.cloud.aiplatform.v1.IndexEndpointService.ListIndexEndpoints] + call. + read_mask (google.protobuf.field_mask_pb2.FieldMask): + Optional. Mask specifying which fields to + read. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=5, + message=field_mask_pb2.FieldMask, + ) + + +class ListIndexEndpointsResponse(proto.Message): + r"""Response message for + [IndexEndpointService.ListIndexEndpoints][google.cloud.aiplatform.v1.IndexEndpointService.ListIndexEndpoints]. + + Attributes: + index_endpoints (Sequence[google.cloud.aiplatform_v1.types.IndexEndpoint]): + List of IndexEndpoints in the requested page. + next_page_token (str): + A token to retrieve next page of results. Pass to + [ListIndexEndpointsRequest.page_token][google.cloud.aiplatform.v1.ListIndexEndpointsRequest.page_token] + to obtain that page. + """ + + @property + def raw_page(self): + return self + + index_endpoints = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gca_index_endpoint.IndexEndpoint, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) + + +class UpdateIndexEndpointRequest(proto.Message): + r"""Request message for + [IndexEndpointService.UpdateIndexEndpoint][google.cloud.aiplatform.v1.IndexEndpointService.UpdateIndexEndpoint]. + + Attributes: + index_endpoint (google.cloud.aiplatform_v1.types.IndexEndpoint): + Required. The IndexEndpoint which replaces + the resource on the server. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Required. The update mask applies to the resource. See + [google.protobuf.FieldMask][google.protobuf.FieldMask]. + """ + + index_endpoint = proto.Field( + proto.MESSAGE, + number=1, + message=gca_index_endpoint.IndexEndpoint, + ) + update_mask = proto.Field( + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) + + +class DeleteIndexEndpointRequest(proto.Message): + r"""Request message for + [IndexEndpointService.DeleteIndexEndpoint][google.cloud.aiplatform.v1.IndexEndpointService.DeleteIndexEndpoint]. + + Attributes: + name (str): + Required. The name of the IndexEndpoint resource to be + deleted. Format: + ``projects/{project}/locations/{location}/indexEndpoints/{index_endpoint}`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class DeployIndexRequest(proto.Message): + r"""Request message for + [IndexEndpointService.DeployIndex][google.cloud.aiplatform.v1.IndexEndpointService.DeployIndex]. + + Attributes: + index_endpoint (str): + Required. The name of the IndexEndpoint resource into which + to deploy an Index. Format: + ``projects/{project}/locations/{location}/indexEndpoints/{index_endpoint}`` + deployed_index (google.cloud.aiplatform_v1.types.DeployedIndex): + Required. The DeployedIndex to be created + within the IndexEndpoint. + """ + + index_endpoint = proto.Field( + proto.STRING, + number=1, + ) + deployed_index = proto.Field( + proto.MESSAGE, + number=2, + message=gca_index_endpoint.DeployedIndex, + ) + + +class DeployIndexResponse(proto.Message): + r"""Response message for + [IndexEndpointService.DeployIndex][google.cloud.aiplatform.v1.IndexEndpointService.DeployIndex]. + + Attributes: + deployed_index (google.cloud.aiplatform_v1.types.DeployedIndex): + The DeployedIndex that had been deployed in + the IndexEndpoint. + """ + + deployed_index = proto.Field( + proto.MESSAGE, + number=1, + message=gca_index_endpoint.DeployedIndex, + ) + + +class DeployIndexOperationMetadata(proto.Message): + r"""Runtime operation information for + [IndexEndpointService.DeployIndex][google.cloud.aiplatform.v1.IndexEndpointService.DeployIndex]. + + Attributes: + generic_metadata (google.cloud.aiplatform_v1.types.GenericOperationMetadata): + The operation generic information. + deployed_index_id (str): + The unique index id specified by user + """ + + generic_metadata = proto.Field( + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, + ) + deployed_index_id = proto.Field( + proto.STRING, + number=2, + ) + + +class UndeployIndexRequest(proto.Message): + r"""Request message for + [IndexEndpointService.UndeployIndex][google.cloud.aiplatform.v1.IndexEndpointService.UndeployIndex]. + + Attributes: + index_endpoint (str): + Required. The name of the IndexEndpoint resource from which + to undeploy an Index. Format: + ``projects/{project}/locations/{location}/indexEndpoints/{index_endpoint}`` + deployed_index_id (str): + Required. The ID of the DeployedIndex to be + undeployed from the IndexEndpoint. + """ + + index_endpoint = proto.Field( + proto.STRING, + number=1, + ) + deployed_index_id = proto.Field( + proto.STRING, + number=2, + ) + + +class UndeployIndexResponse(proto.Message): + r"""Response message for + [IndexEndpointService.UndeployIndex][google.cloud.aiplatform.v1.IndexEndpointService.UndeployIndex]. + + """ + + +class UndeployIndexOperationMetadata(proto.Message): + r"""Runtime operation information for + [IndexEndpointService.UndeployIndex][google.cloud.aiplatform.v1.IndexEndpointService.UndeployIndex]. + + Attributes: + generic_metadata (google.cloud.aiplatform_v1.types.GenericOperationMetadata): + The operation generic information. + """ + + generic_metadata = proto.Field( + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, + ) + + +class MutateDeployedIndexRequest(proto.Message): + r"""Request message for + [IndexEndpointService.MutateDeployedIndex][google.cloud.aiplatform.v1.IndexEndpointService.MutateDeployedIndex]. + + Attributes: + index_endpoint (str): + Required. The name of the IndexEndpoint resource into which + to deploy an Index. Format: + ``projects/{project}/locations/{location}/indexEndpoints/{index_endpoint}`` + deployed_index (google.cloud.aiplatform_v1.types.DeployedIndex): + Required. The DeployedIndex to be updated within the + IndexEndpoint. Currently, the updatable fields are + [DeployedIndex][automatic_resources] and + [DeployedIndex][dedicated_resources] + """ + + index_endpoint = proto.Field( + proto.STRING, + number=1, + ) + deployed_index = proto.Field( + proto.MESSAGE, + number=2, + message=gca_index_endpoint.DeployedIndex, + ) + + +class MutateDeployedIndexResponse(proto.Message): + r"""Response message for + [IndexEndpointService.MutateDeployedIndex][google.cloud.aiplatform.v1.IndexEndpointService.MutateDeployedIndex]. + + Attributes: + deployed_index (google.cloud.aiplatform_v1.types.DeployedIndex): + The DeployedIndex that had been updated in + the IndexEndpoint. + """ + + deployed_index = proto.Field( + proto.MESSAGE, + number=1, + message=gca_index_endpoint.DeployedIndex, + ) + + +class MutateDeployedIndexOperationMetadata(proto.Message): + r"""Runtime operation information for + [IndexEndpointService.MutateDeployedIndex][google.cloud.aiplatform.v1.IndexEndpointService.MutateDeployedIndex]. + + Attributes: + generic_metadata (google.cloud.aiplatform_v1.types.GenericOperationMetadata): + The operation generic information. + deployed_index_id (str): + The unique index id specified by user + """ + + generic_metadata = proto.Field( + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, + ) + deployed_index_id = proto.Field( + proto.STRING, + number=2, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/index_service.py b/google/cloud/aiplatform_v1/types/index_service.py new file mode 100644 index 0000000000..2e77fa43be --- /dev/null +++ b/google/cloud/aiplatform_v1/types/index_service.py @@ -0,0 +1,363 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + +from google.cloud.aiplatform_v1.types import index as gca_index +from google.cloud.aiplatform_v1.types import operation +from google.protobuf import field_mask_pb2 # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "CreateIndexRequest", + "CreateIndexOperationMetadata", + "GetIndexRequest", + "ListIndexesRequest", + "ListIndexesResponse", + "UpdateIndexRequest", + "UpdateIndexOperationMetadata", + "DeleteIndexRequest", + "NearestNeighborSearchOperationMetadata", + }, +) + + +class CreateIndexRequest(proto.Message): + r"""Request message for + [IndexService.CreateIndex][google.cloud.aiplatform.v1.IndexService.CreateIndex]. + + Attributes: + parent (str): + Required. The resource name of the Location to create the + Index in. Format: + ``projects/{project}/locations/{location}`` + index (google.cloud.aiplatform_v1.types.Index): + Required. The Index to create. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + index = proto.Field( + proto.MESSAGE, + number=2, + message=gca_index.Index, + ) + + +class CreateIndexOperationMetadata(proto.Message): + r"""Runtime operation information for + [IndexService.CreateIndex][google.cloud.aiplatform.v1.IndexService.CreateIndex]. + + Attributes: + generic_metadata (google.cloud.aiplatform_v1.types.GenericOperationMetadata): + The operation generic information. + nearest_neighbor_search_operation_metadata (google.cloud.aiplatform_v1.types.NearestNeighborSearchOperationMetadata): + The operation metadata with regard to + Matching Engine Index operation. + """ + + generic_metadata = proto.Field( + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, + ) + nearest_neighbor_search_operation_metadata = proto.Field( + proto.MESSAGE, + number=2, + message="NearestNeighborSearchOperationMetadata", + ) + + +class GetIndexRequest(proto.Message): + r"""Request message for + [IndexService.GetIndex][google.cloud.aiplatform.v1.IndexService.GetIndex] + + Attributes: + name (str): + Required. The name of the Index resource. Format: + ``projects/{project}/locations/{location}/indexes/{index}`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class ListIndexesRequest(proto.Message): + r"""Request message for + [IndexService.ListIndexes][google.cloud.aiplatform.v1.IndexService.ListIndexes]. + + Attributes: + parent (str): + Required. The resource name of the Location from which to + list the Indexes. Format: + ``projects/{project}/locations/{location}`` + filter (str): + The standard list filter. + page_size (int): + The standard list page size. + page_token (str): + The standard list page token. Typically obtained via + [ListIndexesResponse.next_page_token][google.cloud.aiplatform.v1.ListIndexesResponse.next_page_token] + of the previous + [IndexService.ListIndexes][google.cloud.aiplatform.v1.IndexService.ListIndexes] + call. + read_mask (google.protobuf.field_mask_pb2.FieldMask): + Mask specifying which fields to read. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=5, + message=field_mask_pb2.FieldMask, + ) + + +class ListIndexesResponse(proto.Message): + r"""Response message for + [IndexService.ListIndexes][google.cloud.aiplatform.v1.IndexService.ListIndexes]. + + Attributes: + indexes (Sequence[google.cloud.aiplatform_v1.types.Index]): + List of indexes in the requested page. + next_page_token (str): + A token to retrieve next page of results. Pass to + [ListIndexesRequest.page_token][google.cloud.aiplatform.v1.ListIndexesRequest.page_token] + to obtain that page. + """ + + @property + def raw_page(self): + return self + + indexes = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gca_index.Index, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) + + +class UpdateIndexRequest(proto.Message): + r"""Request message for + [IndexService.UpdateIndex][google.cloud.aiplatform.v1.IndexService.UpdateIndex]. + + Attributes: + index (google.cloud.aiplatform_v1.types.Index): + Required. The Index which updates the + resource on the server. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + The update mask applies to the resource. For the + ``FieldMask`` definition, see + [google.protobuf.FieldMask][google.protobuf.FieldMask]. + """ + + index = proto.Field( + proto.MESSAGE, + number=1, + message=gca_index.Index, + ) + update_mask = proto.Field( + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) + + +class UpdateIndexOperationMetadata(proto.Message): + r"""Runtime operation information for + [IndexService.UpdateIndex][google.cloud.aiplatform.v1.IndexService.UpdateIndex]. + + Attributes: + generic_metadata (google.cloud.aiplatform_v1.types.GenericOperationMetadata): + The operation generic information. + nearest_neighbor_search_operation_metadata (google.cloud.aiplatform_v1.types.NearestNeighborSearchOperationMetadata): + The operation metadata with regard to + Matching Engine Index operation. + """ + + generic_metadata = proto.Field( + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, + ) + nearest_neighbor_search_operation_metadata = proto.Field( + proto.MESSAGE, + number=2, + message="NearestNeighborSearchOperationMetadata", + ) + + +class DeleteIndexRequest(proto.Message): + r"""Request message for + [IndexService.DeleteIndex][google.cloud.aiplatform.v1.IndexService.DeleteIndex]. + + Attributes: + name (str): + Required. The name of the Index resource to be deleted. + Format: + ``projects/{project}/locations/{location}/indexes/{index}`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class NearestNeighborSearchOperationMetadata(proto.Message): + r"""Runtime operation metadata with regard to Matching Engine + Index. + + Attributes: + content_validation_stats (Sequence[google.cloud.aiplatform_v1.types.NearestNeighborSearchOperationMetadata.ContentValidationStats]): + The validation stats of the content (per file) to be + inserted or updated on the Matching Engine Index resource. + Populated if contentsDeltaUri is provided as part of + [Index.metadata][google.cloud.aiplatform.v1.Index.metadata]. + Please note that, currently for those files that are broken + or has unsupported file format, we will not have the stats + for those files. + data_bytes_count (int): + The ingested data size in bytes. + """ + + class RecordError(proto.Message): + r""" + + Attributes: + error_type (google.cloud.aiplatform_v1.types.NearestNeighborSearchOperationMetadata.RecordError.RecordErrorType): + The error type of this record. + error_message (str): + A human-readable message that is shown to the user to help + them fix the error. Note that this message may change from + time to time, your code should check against error_type as + the source of truth. + source_gcs_uri (str): + Cloud Storage URI pointing to the original + file in user's bucket. + embedding_id (str): + Empty if the embedding id is failed to parse. + raw_record (str): + The original content of this record. + """ + + class RecordErrorType(proto.Enum): + r"""""" + ERROR_TYPE_UNSPECIFIED = 0 + EMPTY_LINE = 1 + INVALID_JSON_SYNTAX = 2 + INVALID_CSV_SYNTAX = 3 + INVALID_AVRO_SYNTAX = 4 + INVALID_EMBEDDING_ID = 5 + EMBEDDING_SIZE_MISMATCH = 6 + NAMESPACE_MISSING = 7 + + error_type = proto.Field( + proto.ENUM, + number=1, + enum="NearestNeighborSearchOperationMetadata.RecordError.RecordErrorType", + ) + error_message = proto.Field( + proto.STRING, + number=2, + ) + source_gcs_uri = proto.Field( + proto.STRING, + number=3, + ) + embedding_id = proto.Field( + proto.STRING, + number=4, + ) + raw_record = proto.Field( + proto.STRING, + number=5, + ) + + class ContentValidationStats(proto.Message): + r""" + + Attributes: + source_gcs_uri (str): + Cloud Storage URI pointing to the original + file in user's bucket. + valid_record_count (int): + Number of records in this file that were + successfully processed. + invalid_record_count (int): + Number of records in this file we skipped due + to validate errors. + partial_errors (Sequence[google.cloud.aiplatform_v1.types.NearestNeighborSearchOperationMetadata.RecordError]): + The detail information of the partial + failures encountered for those invalid records + that couldn't be parsed. Up to 50 partial errors + will be reported. + """ + + source_gcs_uri = proto.Field( + proto.STRING, + number=1, + ) + valid_record_count = proto.Field( + proto.INT64, + number=2, + ) + invalid_record_count = proto.Field( + proto.INT64, + number=3, + ) + partial_errors = proto.RepeatedField( + proto.MESSAGE, + number=4, + message="NearestNeighborSearchOperationMetadata.RecordError", + ) + + content_validation_stats = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=ContentValidationStats, + ) + data_bytes_count = proto.Field( + proto.INT64, + number=2, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/io.py b/google/cloud/aiplatform_v1/types/io.py index 243ec1a745..582c733b3a 100644 --- a/google/cloud/aiplatform_v1/types/io.py +++ b/google/cloud/aiplatform_v1/types/io.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,17 +19,52 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1", manifest={ + "AvroSource", + "CsvSource", "GcsSource", "GcsDestination", "BigQuerySource", "BigQueryDestination", + "CsvDestination", + "TFRecordDestination", "ContainerRegistryDestination", }, ) +class AvroSource(proto.Message): + r"""The storage details for Avro input content. + + Attributes: + gcs_source (google.cloud.aiplatform_v1.types.GcsSource): + Required. Google Cloud Storage location. + """ + + gcs_source = proto.Field( + proto.MESSAGE, + number=1, + message="GcsSource", + ) + + +class CsvSource(proto.Message): + r"""The storage details for CSV input content. + + Attributes: + gcs_source (google.cloud.aiplatform_v1.types.GcsSource): + Required. Google Cloud Storage location. + """ + + gcs_source = proto.Field( + proto.MESSAGE, + number=1, + message="GcsSource", + ) + + class GcsSource(proto.Message): r"""The Google Cloud Storage location for the input content. + Attributes: uris (Sequence[str]): Required. Google Cloud Storage URI(-s) to the @@ -38,7 +73,10 @@ class GcsSource(proto.Message): https://cloud.google.com/storage/docs/gsutil/addlhelp/WildcardNames. """ - uris = proto.RepeatedField(proto.STRING, number=1,) + uris = proto.RepeatedField( + proto.STRING, + number=1, + ) class GcsDestination(proto.Message): @@ -53,11 +91,15 @@ class GcsDestination(proto.Message): directory is created if it doesn't exist. """ - output_uri_prefix = proto.Field(proto.STRING, number=1,) + output_uri_prefix = proto.Field( + proto.STRING, + number=1, + ) class BigQuerySource(proto.Message): r"""The BigQuery location for the input content. + Attributes: input_uri (str): Required. BigQuery URI to a table, up to 2000 characters @@ -67,31 +109,70 @@ class BigQuerySource(proto.Message): ``bq://projectId.bqDatasetId.bqTableId``. """ - input_uri = proto.Field(proto.STRING, number=1,) + input_uri = proto.Field( + proto.STRING, + number=1, + ) class BigQueryDestination(proto.Message): r"""The BigQuery location for the output content. + Attributes: output_uri (str): Required. BigQuery URI to a project or table, up to 2000 characters long. - When only the project is specified, the Dataset and Table - are created. When the full table reference is specified, the + When only the project is specified, the Dataset and Table is + created. When the full table reference is specified, the Dataset must exist and table must not exist. Accepted forms: - BigQuery path. For example: ``bq://projectId`` or + ``bq://projectId.bqDatasetId`` or ``bq://projectId.bqDatasetId.bqTableId``. """ - output_uri = proto.Field(proto.STRING, number=1,) + output_uri = proto.Field( + proto.STRING, + number=1, + ) + + +class CsvDestination(proto.Message): + r"""The storage details for CSV output content. + + Attributes: + gcs_destination (google.cloud.aiplatform_v1.types.GcsDestination): + Required. Google Cloud Storage location. + """ + + gcs_destination = proto.Field( + proto.MESSAGE, + number=1, + message="GcsDestination", + ) + + +class TFRecordDestination(proto.Message): + r"""The storage details for TFRecord output content. + + Attributes: + gcs_destination (google.cloud.aiplatform_v1.types.GcsDestination): + Required. Google Cloud Storage location. + """ + + gcs_destination = proto.Field( + proto.MESSAGE, + number=1, + message="GcsDestination", + ) class ContainerRegistryDestination(proto.Message): r"""The Container Registry location for the container image. + Attributes: output_uri (str): Required. Container Registry URI of a container image. Only @@ -108,7 +189,10 @@ class ContainerRegistryDestination(proto.Message): default tag. """ - output_uri = proto.Field(proto.STRING, number=1,) + output_uri = proto.Field( + proto.STRING, + number=1, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/job_service.py b/google/cloud/aiplatform_v1/types/job_service.py index 331b91d6e4..483c046086 100644 --- a/google/cloud/aiplatform_v1/types/job_service.py +++ b/google/cloud/aiplatform_v1/types/job_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,7 +23,12 @@ from google.cloud.aiplatform_v1.types import ( hyperparameter_tuning_job as gca_hyperparameter_tuning_job, ) +from google.cloud.aiplatform_v1.types import ( + model_deployment_monitoring_job as gca_model_deployment_monitoring_job, +) +from google.cloud.aiplatform_v1.types import operation from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module( @@ -53,6 +58,17 @@ "ListBatchPredictionJobsResponse", "DeleteBatchPredictionJobRequest", "CancelBatchPredictionJobRequest", + "CreateModelDeploymentMonitoringJobRequest", + "SearchModelDeploymentMonitoringStatsAnomaliesRequest", + "SearchModelDeploymentMonitoringStatsAnomaliesResponse", + "GetModelDeploymentMonitoringJobRequest", + "ListModelDeploymentMonitoringJobsRequest", + "ListModelDeploymentMonitoringJobsResponse", + "UpdateModelDeploymentMonitoringJobRequest", + "DeleteModelDeploymentMonitoringJobRequest", + "PauseModelDeploymentMonitoringJobRequest", + "ResumeModelDeploymentMonitoringJobRequest", + "UpdateModelDeploymentMonitoringJobOperationMetadata", }, ) @@ -70,8 +86,15 @@ class CreateCustomJobRequest(proto.Message): Required. The CustomJob to create. """ - parent = proto.Field(proto.STRING, number=1,) - custom_job = proto.Field(proto.MESSAGE, number=2, message=gca_custom_job.CustomJob,) + parent = proto.Field( + proto.STRING, + number=1, + ) + custom_job = proto.Field( + proto.MESSAGE, + number=2, + message=gca_custom_job.CustomJob, + ) class GetCustomJobRequest(proto.Message): @@ -84,7 +107,10 @@ class GetCustomJobRequest(proto.Message): ``projects/{project}/locations/{location}/customJobs/{custom_job}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListCustomJobsRequest(proto.Message): @@ -126,11 +152,27 @@ class ListCustomJobsRequest(proto.Message): Mask specifying which fields to read. """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) - read_mask = proto.Field(proto.MESSAGE, number=5, message=field_mask_pb2.FieldMask,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=5, + message=field_mask_pb2.FieldMask, + ) class ListCustomJobsResponse(proto.Message): @@ -151,9 +193,14 @@ def raw_page(self): return self custom_jobs = proto.RepeatedField( - proto.MESSAGE, number=1, message=gca_custom_job.CustomJob, + proto.MESSAGE, + number=1, + message=gca_custom_job.CustomJob, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class DeleteCustomJobRequest(proto.Message): @@ -167,7 +214,10 @@ class DeleteCustomJobRequest(proto.Message): ``projects/{project}/locations/{location}/customJobs/{custom_job}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class CancelCustomJobRequest(proto.Message): @@ -180,12 +230,15 @@ class CancelCustomJobRequest(proto.Message): ``projects/{project}/locations/{location}/customJobs/{custom_job}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class CreateDataLabelingJobRequest(proto.Message): r"""Request message for - [DataLabelingJobService.CreateDataLabelingJob][]. + [JobService.CreateDataLabelingJob][google.cloud.aiplatform.v1.JobService.CreateDataLabelingJob]. Attributes: parent (str): @@ -195,26 +248,37 @@ class CreateDataLabelingJobRequest(proto.Message): Required. The DataLabelingJob to create. """ - parent = proto.Field(proto.STRING, number=1,) + parent = proto.Field( + proto.STRING, + number=1, + ) data_labeling_job = proto.Field( - proto.MESSAGE, number=2, message=gca_data_labeling_job.DataLabelingJob, + proto.MESSAGE, + number=2, + message=gca_data_labeling_job.DataLabelingJob, ) class GetDataLabelingJobRequest(proto.Message): - r"""Request message for [DataLabelingJobService.GetDataLabelingJob][]. + r"""Request message for + [JobService.GetDataLabelingJob][google.cloud.aiplatform.v1.JobService.GetDataLabelingJob]. + Attributes: name (str): Required. The name of the DataLabelingJob. Format: - ``projects/{project}/locations/{location}/dataLabelingJobs/{data_labeling_job}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListDataLabelingJobsRequest(proto.Message): - r"""Request message for [DataLabelingJobService.ListDataLabelingJobs][]. + r"""Request message for + [JobService.ListDataLabelingJobs][google.cloud.aiplatform.v1.JobService.ListDataLabelingJobs]. + Attributes: parent (str): Required. The parent of the DataLabelingJob. Format: @@ -253,12 +317,31 @@ class ListDataLabelingJobsRequest(proto.Message): for descending. """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) - read_mask = proto.Field(proto.MESSAGE, number=5, message=field_mask_pb2.FieldMask,) - order_by = proto.Field(proto.STRING, number=6,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=5, + message=field_mask_pb2.FieldMask, + ) + order_by = proto.Field( + proto.STRING, + number=6, + ) class ListDataLabelingJobsResponse(proto.Message): @@ -278,9 +361,14 @@ def raw_page(self): return self data_labeling_jobs = proto.RepeatedField( - proto.MESSAGE, number=1, message=gca_data_labeling_job.DataLabelingJob, + proto.MESSAGE, + number=1, + message=gca_data_labeling_job.DataLabelingJob, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class DeleteDataLabelingJobRequest(proto.Message): @@ -291,25 +379,29 @@ class DeleteDataLabelingJobRequest(proto.Message): name (str): Required. The name of the DataLabelingJob to be deleted. Format: - ``projects/{project}/locations/{location}/dataLabelingJobs/{data_labeling_job}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class CancelDataLabelingJobRequest(proto.Message): r"""Request message for - [DataLabelingJobService.CancelDataLabelingJob][]. + [JobService.CancelDataLabelingJob][google.cloud.aiplatform.v1.JobService.CancelDataLabelingJob]. Attributes: name (str): Required. The name of the DataLabelingJob. Format: - ``projects/{project}/locations/{location}/dataLabelingJobs/{data_labeling_job}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class CreateHyperparameterTuningJobRequest(proto.Message): @@ -326,7 +418,10 @@ class CreateHyperparameterTuningJobRequest(proto.Message): create. """ - parent = proto.Field(proto.STRING, number=1,) + parent = proto.Field( + proto.STRING, + number=1, + ) hyperparameter_tuning_job = proto.Field( proto.MESSAGE, number=2, @@ -342,11 +437,13 @@ class GetHyperparameterTuningJobRequest(proto.Message): name (str): Required. The name of the HyperparameterTuningJob resource. Format: - ``projects/{project}/locations/{location}/hyperparameterTuningJobs/{hyperparameter_tuning_job}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListHyperparameterTuningJobsRequest(proto.Message): @@ -388,11 +485,27 @@ class ListHyperparameterTuningJobsRequest(proto.Message): Mask specifying which fields to read. """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) - read_mask = proto.Field(proto.MESSAGE, number=5, message=field_mask_pb2.FieldMask,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=5, + message=field_mask_pb2.FieldMask, + ) class ListHyperparameterTuningJobsResponse(proto.Message): @@ -419,7 +532,10 @@ def raw_page(self): number=1, message=gca_hyperparameter_tuning_job.HyperparameterTuningJob, ) - next_page_token = proto.Field(proto.STRING, number=2,) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) class DeleteHyperparameterTuningJobRequest(proto.Message): @@ -430,11 +546,13 @@ class DeleteHyperparameterTuningJobRequest(proto.Message): name (str): Required. The name of the HyperparameterTuningJob resource to be deleted. Format: - ``projects/{project}/locations/{location}/hyperparameterTuningJobs/{hyperparameter_tuning_job}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class CancelHyperparameterTuningJobRequest(proto.Message): @@ -445,11 +563,13 @@ class CancelHyperparameterTuningJobRequest(proto.Message): name (str): Required. The name of the HyperparameterTuningJob to cancel. Format: - ``projects/{project}/locations/{location}/hyperparameterTuningJobs/{hyperparameter_tuning_job}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class CreateBatchPredictionJobRequest(proto.Message): @@ -465,9 +585,14 @@ class CreateBatchPredictionJobRequest(proto.Message): Required. The BatchPredictionJob to create. """ - parent = proto.Field(proto.STRING, number=1,) + parent = proto.Field( + proto.STRING, + number=1, + ) batch_prediction_job = proto.Field( - proto.MESSAGE, number=2, message=gca_batch_prediction_job.BatchPredictionJob, + proto.MESSAGE, + number=2, + message=gca_batch_prediction_job.BatchPredictionJob, ) @@ -479,11 +604,13 @@ class GetBatchPredictionJobRequest(proto.Message): name (str): Required. The name of the BatchPredictionJob resource. Format: - ``projects/{project}/locations/{location}/batchPredictionJobs/{batch_prediction_job}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListBatchPredictionJobsRequest(proto.Message): @@ -504,6 +631,8 @@ class ListBatchPredictionJobsRequest(proto.Message): - ``state`` supports = and !=. + - ``model_display_name`` supports = and != + Some examples of using the filter are: - ``state="JOB_STATE_SUCCEEDED" AND display_name="my_job"`` @@ -525,11 +654,27 @@ class ListBatchPredictionJobsRequest(proto.Message): Mask specifying which fields to read. """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) - read_mask = proto.Field(proto.MESSAGE, number=5, message=field_mask_pb2.FieldMask,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=5, + message=field_mask_pb2.FieldMask, + ) class ListBatchPredictionJobsResponse(proto.Message): @@ -551,9 +696,14 @@ def raw_page(self): return self batch_prediction_jobs = proto.RepeatedField( - proto.MESSAGE, number=1, message=gca_batch_prediction_job.BatchPredictionJob, + proto.MESSAGE, + number=1, + message=gca_batch_prediction_job.BatchPredictionJob, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class DeleteBatchPredictionJobRequest(proto.Message): @@ -564,11 +714,13 @@ class DeleteBatchPredictionJobRequest(proto.Message): name (str): Required. The name of the BatchPredictionJob resource to be deleted. Format: - ``projects/{project}/locations/{location}/batchPredictionJobs/{batch_prediction_job}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class CancelBatchPredictionJobRequest(proto.Message): @@ -579,11 +731,369 @@ class CancelBatchPredictionJobRequest(proto.Message): name (str): Required. The name of the BatchPredictionJob to cancel. Format: - ``projects/{project}/locations/{location}/batchPredictionJobs/{batch_prediction_job}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) + + +class CreateModelDeploymentMonitoringJobRequest(proto.Message): + r"""Request message for + [JobService.CreateModelDeploymentMonitoringJob][google.cloud.aiplatform.v1.JobService.CreateModelDeploymentMonitoringJob]. + + Attributes: + parent (str): + Required. The parent of the ModelDeploymentMonitoringJob. + Format: ``projects/{project}/locations/{location}`` + model_deployment_monitoring_job (google.cloud.aiplatform_v1.types.ModelDeploymentMonitoringJob): + Required. The ModelDeploymentMonitoringJob to + create + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + model_deployment_monitoring_job = proto.Field( + proto.MESSAGE, + number=2, + message=gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob, + ) + + +class SearchModelDeploymentMonitoringStatsAnomaliesRequest(proto.Message): + r"""Request message for + [JobService.SearchModelDeploymentMonitoringStatsAnomalies][google.cloud.aiplatform.v1.JobService.SearchModelDeploymentMonitoringStatsAnomalies]. + + Attributes: + model_deployment_monitoring_job (str): + Required. ModelDeploymentMonitoring Job resource name. + Format: + ``projects/{project}/locations/{location}/modelDeploymentMonitoringJobs/{model_deployment_monitoring_job}`` + deployed_model_id (str): + Required. The DeployedModel ID of the + [ModelDeploymentMonitoringObjectiveConfig.deployed_model_id]. + feature_display_name (str): + The feature display name. If specified, only return the + stats belonging to this feature. Format: + [ModelMonitoringStatsAnomalies.FeatureHistoricStatsAnomalies.feature_display_name][google.cloud.aiplatform.v1.ModelMonitoringStatsAnomalies.FeatureHistoricStatsAnomalies.feature_display_name], + example: "user_destination". + objectives (Sequence[google.cloud.aiplatform_v1.types.SearchModelDeploymentMonitoringStatsAnomaliesRequest.StatsAnomaliesObjective]): + Required. Objectives of the stats to + retrieve. + page_size (int): + The standard list page size. + page_token (str): + A page token received from a previous + [JobService.SearchModelDeploymentMonitoringStatsAnomalies][google.cloud.aiplatform.v1.JobService.SearchModelDeploymentMonitoringStatsAnomalies] + call. + start_time (google.protobuf.timestamp_pb2.Timestamp): + The earliest timestamp of stats being + generated. If not set, indicates fetching stats + till the earliest possible one. + end_time (google.protobuf.timestamp_pb2.Timestamp): + The latest timestamp of stats being + generated. If not set, indicates feching stats + till the latest possible one. + """ + + class StatsAnomaliesObjective(proto.Message): + r"""Stats requested for specific objective. + + Attributes: + type_ (google.cloud.aiplatform_v1.types.ModelDeploymentMonitoringObjectiveType): + + top_feature_count (int): + If set, all attribution scores between + [SearchModelDeploymentMonitoringStatsAnomaliesRequest.start_time][google.cloud.aiplatform.v1.SearchModelDeploymentMonitoringStatsAnomaliesRequest.start_time] + and + [SearchModelDeploymentMonitoringStatsAnomaliesRequest.end_time][google.cloud.aiplatform.v1.SearchModelDeploymentMonitoringStatsAnomaliesRequest.end_time] + are fetched, and page token doesn't take affect in this + case. Only used to retrieve attribution score for the top + Features which has the highest attribution score in the + latest monitoring run. + """ + + type_ = proto.Field( + proto.ENUM, + number=1, + enum=gca_model_deployment_monitoring_job.ModelDeploymentMonitoringObjectiveType, + ) + top_feature_count = proto.Field( + proto.INT32, + number=4, + ) + + model_deployment_monitoring_job = proto.Field( + proto.STRING, + number=1, + ) + deployed_model_id = proto.Field( + proto.STRING, + number=2, + ) + feature_display_name = proto.Field( + proto.STRING, + number=3, + ) + objectives = proto.RepeatedField( + proto.MESSAGE, + number=4, + message=StatsAnomaliesObjective, + ) + page_size = proto.Field( + proto.INT32, + number=5, + ) + page_token = proto.Field( + proto.STRING, + number=6, + ) + start_time = proto.Field( + proto.MESSAGE, + number=7, + message=timestamp_pb2.Timestamp, + ) + end_time = proto.Field( + proto.MESSAGE, + number=8, + message=timestamp_pb2.Timestamp, + ) + + +class SearchModelDeploymentMonitoringStatsAnomaliesResponse(proto.Message): + r"""Response message for + [JobService.SearchModelDeploymentMonitoringStatsAnomalies][google.cloud.aiplatform.v1.JobService.SearchModelDeploymentMonitoringStatsAnomalies]. + + Attributes: + monitoring_stats (Sequence[google.cloud.aiplatform_v1.types.ModelMonitoringStatsAnomalies]): + Stats retrieved for requested objectives. There are at most + 1000 + [ModelMonitoringStatsAnomalies.FeatureHistoricStatsAnomalies.prediction_stats][google.cloud.aiplatform.v1.ModelMonitoringStatsAnomalies.FeatureHistoricStatsAnomalies.prediction_stats] + in the response. + next_page_token (str): + The page token that can be used by the next + [JobService.SearchModelDeploymentMonitoringStatsAnomalies][google.cloud.aiplatform.v1.JobService.SearchModelDeploymentMonitoringStatsAnomalies] + call. + """ + + @property + def raw_page(self): + return self + + monitoring_stats = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gca_model_deployment_monitoring_job.ModelMonitoringStatsAnomalies, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) + + +class GetModelDeploymentMonitoringJobRequest(proto.Message): + r"""Request message for + [JobService.GetModelDeploymentMonitoringJob][google.cloud.aiplatform.v1.JobService.GetModelDeploymentMonitoringJob]. + + Attributes: + name (str): + Required. The resource name of the + ModelDeploymentMonitoringJob. Format: + ``projects/{project}/locations/{location}/modelDeploymentMonitoringJobs/{model_deployment_monitoring_job}`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class ListModelDeploymentMonitoringJobsRequest(proto.Message): + r"""Request message for + [JobService.ListModelDeploymentMonitoringJobs][google.cloud.aiplatform.v1.JobService.ListModelDeploymentMonitoringJobs]. + + Attributes: + parent (str): + Required. The parent of the ModelDeploymentMonitoringJob. + Format: ``projects/{project}/locations/{location}`` + filter (str): + The standard list filter. + page_size (int): + The standard list page size. + page_token (str): + The standard list page token. + read_mask (google.protobuf.field_mask_pb2.FieldMask): + Mask specifying which fields to read + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=5, + message=field_mask_pb2.FieldMask, + ) + + +class ListModelDeploymentMonitoringJobsResponse(proto.Message): + r"""Response message for + [JobService.ListModelDeploymentMonitoringJobs][google.cloud.aiplatform.v1.JobService.ListModelDeploymentMonitoringJobs]. + + Attributes: + model_deployment_monitoring_jobs (Sequence[google.cloud.aiplatform_v1.types.ModelDeploymentMonitoringJob]): + A list of ModelDeploymentMonitoringJobs that + matches the specified filter in the request. + next_page_token (str): + The standard List next-page token. + """ + + @property + def raw_page(self): + return self + + model_deployment_monitoring_jobs = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) + + +class UpdateModelDeploymentMonitoringJobRequest(proto.Message): + r"""Request message for + [JobService.UpdateModelDeploymentMonitoringJob][google.cloud.aiplatform.v1.JobService.UpdateModelDeploymentMonitoringJob]. + + Attributes: + model_deployment_monitoring_job (google.cloud.aiplatform_v1.types.ModelDeploymentMonitoringJob): + Required. The model monitoring configuration + which replaces the resource on the server. + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Required. The update mask is used to specify the fields to + be overwritten in the ModelDeploymentMonitoringJob resource + by the update. The fields specified in the update_mask are + relative to the resource, not the full request. A field will + be overwritten if it is in the mask. If the user does not + provide a mask then only the non-empty fields present in the + request will be overwritten. Set the update_mask to ``*`` to + override all fields. For the objective config, the user can + either provide the update mask for + model_deployment_monitoring_objective_configs or any + combination of its nested fields, such as: + model_deployment_monitoring_objective_configs.objective_config.training_dataset. + + Updatable fields: + + - ``display_name`` + - ``model_deployment_monitoring_schedule_config`` + - ``model_monitoring_alert_config`` + - ``logging_sampling_strategy`` + - ``labels`` + - ``log_ttl`` + - ``enable_monitoring_pipeline_logs`` . and + - ``model_deployment_monitoring_objective_configs`` . or + - ``model_deployment_monitoring_objective_configs.objective_config.training_dataset`` + - ``model_deployment_monitoring_objective_configs.objective_config.training_prediction_skew_detection_config`` + - ``model_deployment_monitoring_objective_configs.objective_config.prediction_drift_detection_config`` + """ + + model_deployment_monitoring_job = proto.Field( + proto.MESSAGE, + number=1, + message=gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob, + ) + update_mask = proto.Field( + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) + + +class DeleteModelDeploymentMonitoringJobRequest(proto.Message): + r"""Request message for + [JobService.DeleteModelDeploymentMonitoringJob][google.cloud.aiplatform.v1.JobService.DeleteModelDeploymentMonitoringJob]. + + Attributes: + name (str): + Required. The resource name of the model monitoring job to + delete. Format: + ``projects/{project}/locations/{location}/modelDeploymentMonitoringJobs/{model_deployment_monitoring_job}`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class PauseModelDeploymentMonitoringJobRequest(proto.Message): + r"""Request message for + [JobService.PauseModelDeploymentMonitoringJob][google.cloud.aiplatform.v1.JobService.PauseModelDeploymentMonitoringJob]. + + Attributes: + name (str): + Required. The resource name of the + ModelDeploymentMonitoringJob to pause. Format: + ``projects/{project}/locations/{location}/modelDeploymentMonitoringJobs/{model_deployment_monitoring_job}`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class ResumeModelDeploymentMonitoringJobRequest(proto.Message): + r"""Request message for + [JobService.ResumeModelDeploymentMonitoringJob][google.cloud.aiplatform.v1.JobService.ResumeModelDeploymentMonitoringJob]. + + Attributes: + name (str): + Required. The resource name of the + ModelDeploymentMonitoringJob to resume. Format: + ``projects/{project}/locations/{location}/modelDeploymentMonitoringJobs/{model_deployment_monitoring_job}`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class UpdateModelDeploymentMonitoringJobOperationMetadata(proto.Message): + r"""Runtime operation information for + [JobService.UpdateModelDeploymentMonitoringJob][google.cloud.aiplatform.v1.JobService.UpdateModelDeploymentMonitoringJob]. + + Attributes: + generic_metadata (google.cloud.aiplatform_v1.types.GenericOperationMetadata): + The operation generic information. + """ + + generic_metadata = proto.Field( + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/job_state.py b/google/cloud/aiplatform_v1/types/job_state.py index 59c0949844..db3ee682c3 100644 --- a/google/cloud/aiplatform_v1/types/job_state.py +++ b/google/cloud/aiplatform_v1/types/job_state.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,7 +17,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1", manifest={"JobState",}, + package="google.cloud.aiplatform.v1", + manifest={ + "JobState", + }, ) @@ -32,6 +35,8 @@ class JobState(proto.Enum): JOB_STATE_CANCELLING = 6 JOB_STATE_CANCELLED = 7 JOB_STATE_PAUSED = 8 + JOB_STATE_EXPIRED = 9 + JOB_STATE_UPDATING = 10 __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/lineage_subgraph.py b/google/cloud/aiplatform_v1/types/lineage_subgraph.py new file mode 100644 index 0000000000..1f4d3e53e4 --- /dev/null +++ b/google/cloud/aiplatform_v1/types/lineage_subgraph.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + +from google.cloud.aiplatform_v1.types import artifact +from google.cloud.aiplatform_v1.types import event +from google.cloud.aiplatform_v1.types import execution + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "LineageSubgraph", + }, +) + + +class LineageSubgraph(proto.Message): + r"""A subgraph of the overall lineage graph. Event edges connect + Artifact and Execution nodes. + + Attributes: + artifacts (Sequence[google.cloud.aiplatform_v1.types.Artifact]): + The Artifact nodes in the subgraph. + executions (Sequence[google.cloud.aiplatform_v1.types.Execution]): + The Execution nodes in the subgraph. + events (Sequence[google.cloud.aiplatform_v1.types.Event]): + The Event edges between Artifacts and + Executions in the subgraph. + """ + + artifacts = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=artifact.Artifact, + ) + executions = proto.RepeatedField( + proto.MESSAGE, + number=2, + message=execution.Execution, + ) + events = proto.RepeatedField( + proto.MESSAGE, + number=3, + message=event.Event, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/machine_resources.py b/google/cloud/aiplatform_v1/types/machine_resources.py index 8f76f04416..23a5bb2187 100644 --- a/google/cloud/aiplatform_v1/types/machine_resources.py +++ b/google/cloud/aiplatform_v1/types/machine_resources.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -27,19 +27,24 @@ "BatchDedicatedResources", "ResourcesConsumed", "DiskSpec", + "NfsMount", + "AutoscalingMetricSpec", }, ) class MachineSpec(proto.Message): r"""Specification of a single machine. + Attributes: machine_type (str): - Immutable. The type of the machine. For the machine types - supported for prediction, see - https://tinyurl.com/aip-docs/predictions/machine-types. For - machine types supported for creating a custom training job, - see https://tinyurl.com/aip-docs/training/configure-compute. + Immutable. The type of the machine. + + See the `list of machine types supported for + prediction `__ + + See the `list of machine types supported for custom + training `__. For [DeployedModel][google.cloud.aiplatform.v1.DeployedModel] @@ -58,11 +63,19 @@ class MachineSpec(proto.Message): machine. """ - machine_type = proto.Field(proto.STRING, number=1,) + machine_type = proto.Field( + proto.STRING, + number=1, + ) accelerator_type = proto.Field( - proto.ENUM, number=2, enum=gca_accelerator_type.AcceleratorType, + proto.ENUM, + number=2, + enum=gca_accelerator_type.AcceleratorType, + ) + accelerator_count = proto.Field( + proto.INT32, + number=3, ) - accelerator_count = proto.Field(proto.INT32, number=3,) class DedicatedResources(proto.Message): @@ -75,15 +88,14 @@ class DedicatedResources(proto.Message): Required. Immutable. The specification of a single machine used by the prediction. min_replica_count (int): - Required. Immutable. The minimum number of machine replicas - this DeployedModel will be always deployed on. If traffic - against it increases, it may dynamically be deployed onto - more replicas, and as traffic decreases, some of these extra - replicas may be freed. Note: if - [machine_spec.accelerator_count][google.cloud.aiplatform.v1.MachineSpec.accelerator_count] - is above 0, currently the model will be always deployed - precisely on - [min_replica_count][google.cloud.aiplatform.v1.DedicatedResources.min_replica_count]. + Required. Immutable. The minimum number of + machine replicas this DeployedModel will be + always deployed on. This value must be greater + than or equal to 1. + If traffic against the DeployedModel increases, + it may dynamically be deployed onto more + replicas, and as traffic decreases, some of + these extra replicas may be freed. max_replica_count (int): Immutable. The maximum number of replicas this DeployedModel may be deployed on when the traffic against it increases. If @@ -96,16 +108,65 @@ class DedicatedResources(proto.Message): will use [min_replica_count][google.cloud.aiplatform.v1.DedicatedResources.min_replica_count] as the default value. + + The value of this field impacts the charge against Vertex + CPU and GPU quotas. Specifically, you will be charged for + (max_replica_count \* number of cores in the selected + machine type) and (max_replica_count \* number of GPUs per + replica in the selected machine type). + autoscaling_metric_specs (Sequence[google.cloud.aiplatform_v1.types.AutoscalingMetricSpec]): + Immutable. The metric specifications that overrides a + resource utilization metric (CPU utilization, accelerator's + duty cycle, and so on) target value (default to 60 if not + set). At most one entry is allowed per metric. + + If + [machine_spec.accelerator_count][google.cloud.aiplatform.v1.MachineSpec.accelerator_count] + is above 0, the autoscaling will be based on both CPU + utilization and accelerator's duty cycle metrics and scale + up when either metrics exceeds its target value while scale + down if both metrics are under their target value. The + default target value is 60 for both metrics. + + If + [machine_spec.accelerator_count][google.cloud.aiplatform.v1.MachineSpec.accelerator_count] + is 0, the autoscaling will be based on CPU utilization + metric only with default target value 60 if not explicitly + set. + + For example, in the case of Online Prediction, if you want + to override target CPU utilization to 80, you should set + [autoscaling_metric_specs.metric_name][google.cloud.aiplatform.v1.AutoscalingMetricSpec.metric_name] + to + ``aiplatform.googleapis.com/prediction/online/cpu/utilization`` + and + [autoscaling_metric_specs.target][google.cloud.aiplatform.v1.AutoscalingMetricSpec.target] + to ``80``. """ - machine_spec = proto.Field(proto.MESSAGE, number=1, message="MachineSpec",) - min_replica_count = proto.Field(proto.INT32, number=2,) - max_replica_count = proto.Field(proto.INT32, number=3,) + machine_spec = proto.Field( + proto.MESSAGE, + number=1, + message="MachineSpec", + ) + min_replica_count = proto.Field( + proto.INT32, + number=2, + ) + max_replica_count = proto.Field( + proto.INT32, + number=3, + ) + autoscaling_metric_specs = proto.RepeatedField( + proto.MESSAGE, + number=4, + message="AutoscalingMetricSpec", + ) class AutomaticResources(proto.Message): r"""A description of resources that to large degree are decided - by AI Platform, and require only a modest additional + by Vertex AI, and require only a modest additional configuration. Each Model supporting these resources documents its specific guidelines. @@ -130,13 +191,19 @@ class AutomaticResources(proto.Message): its replicas at maximum may handle, a portion of the traffic will be dropped. If this value is not provided, a no upper bound for scaling under - heavy traffic will be assume, though AI Platform + heavy traffic will be assume, though Vertex AI may be unable to scale beyond certain replica number. """ - min_replica_count = proto.Field(proto.INT32, number=1,) - max_replica_count = proto.Field(proto.INT32, number=2,) + min_replica_count = proto.Field( + proto.INT32, + number=1, + ) + max_replica_count = proto.Field( + proto.INT32, + number=2, + ) class BatchDedicatedResources(proto.Message): @@ -150,7 +217,7 @@ class BatchDedicatedResources(proto.Message): single machine. starting_replica_count (int): Immutable. The number of machine replicas used at the start - of the batch operation. If not set, AI Platform decides + of the batch operation. If not set, Vertex AI decides starting number, not greater than [max_replica_count][google.cloud.aiplatform.v1.BatchDedicatedResources.max_replica_count] max_replica_count (int): @@ -159,13 +226,24 @@ class BatchDedicatedResources(proto.Message): The default value is 10. """ - machine_spec = proto.Field(proto.MESSAGE, number=1, message="MachineSpec",) - starting_replica_count = proto.Field(proto.INT32, number=2,) - max_replica_count = proto.Field(proto.INT32, number=3,) + machine_spec = proto.Field( + proto.MESSAGE, + number=1, + message="MachineSpec", + ) + starting_replica_count = proto.Field( + proto.INT32, + number=2, + ) + max_replica_count = proto.Field( + proto.INT32, + number=3, + ) class ResourcesConsumed(proto.Message): r"""Statistics information about resource consumption. + Attributes: replica_hours (float): Output only. The number of replica hours @@ -175,11 +253,15 @@ class ResourcesConsumed(proto.Message): not strictly related to wall time. """ - replica_hours = proto.Field(proto.DOUBLE, number=1,) + replica_hours = proto.Field( + proto.DOUBLE, + number=1, + ) class DiskSpec(proto.Message): r"""Represents the spec of disk options. + Attributes: boot_disk_type (str): Type of the boot disk (default is "pd-ssd"). @@ -191,8 +273,75 @@ class DiskSpec(proto.Message): 100GB). """ - boot_disk_type = proto.Field(proto.STRING, number=1,) - boot_disk_size_gb = proto.Field(proto.INT32, number=2,) + boot_disk_type = proto.Field( + proto.STRING, + number=1, + ) + boot_disk_size_gb = proto.Field( + proto.INT32, + number=2, + ) + + +class NfsMount(proto.Message): + r"""Represents a mount configuration for Network File System + (NFS) to mount. + + Attributes: + server (str): + Required. IP address of the NFS server. + path (str): + Required. Source path exported from NFS server. Has to start + with '/', and combined with the ip address, it indicates the + source mount path in the form of ``server:path`` + mount_point (str): + Required. Destination mount path. The NFS will be mounted + for the user under /mnt/nfs/ + """ + + server = proto.Field( + proto.STRING, + number=1, + ) + path = proto.Field( + proto.STRING, + number=2, + ) + mount_point = proto.Field( + proto.STRING, + number=3, + ) + + +class AutoscalingMetricSpec(proto.Message): + r"""The metric specification that defines the target resource + utilization (CPU utilization, accelerator's duty cycle, and so + on) for calculating the desired replica count. + + Attributes: + metric_name (str): + Required. The resource metric name. Supported metrics: + + - For Online Prediction: + - ``aiplatform.googleapis.com/prediction/online/accelerator/duty_cycle`` + - ``aiplatform.googleapis.com/prediction/online/cpu/utilization`` + target (int): + The target resource utilization in percentage + (1% - 100%) for the given metric; once the real + usage deviates from the target by a certain + percentage, the machine replicas change. The + default value is 60 (representing 60%) if not + provided. + """ + + metric_name = proto.Field( + proto.STRING, + number=1, + ) + target = proto.Field( + proto.INT32, + number=2, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/manual_batch_tuning_parameters.py b/google/cloud/aiplatform_v1/types/manual_batch_tuning_parameters.py index b5d2465b36..9d1d396059 100644 --- a/google/cloud/aiplatform_v1/types/manual_batch_tuning_parameters.py +++ b/google/cloud/aiplatform_v1/types/manual_batch_tuning_parameters.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,12 +17,16 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1", manifest={"ManualBatchTuningParameters",}, + package="google.cloud.aiplatform.v1", + manifest={ + "ManualBatchTuningParameters", + }, ) class ManualBatchTuningParameters(proto.Message): r"""Manual batch tuning parameters. + Attributes: batch_size (int): Immutable. The number of the records (e.g. @@ -34,10 +38,13 @@ class ManualBatchTuningParameters(proto.Message): value will result in a whole batch not fitting in a machine's memory, and the whole operation will fail. - The default value is 4. + The default value is 64. """ - batch_size = proto.Field(proto.INT32, number=1,) + batch_size = proto.Field( + proto.INT32, + number=1, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/metadata_schema.py b/google/cloud/aiplatform_v1/types/metadata_schema.py new file mode 100644 index 0000000000..00836001fd --- /dev/null +++ b/google/cloud/aiplatform_v1/types/metadata_schema.py @@ -0,0 +1,97 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "MetadataSchema", + }, +) + + +class MetadataSchema(proto.Message): + r"""Instance of a general MetadataSchema. + + Attributes: + name (str): + Output only. The resource name of the + MetadataSchema. + schema_version (str): + The version of the MetadataSchema. The version's format must + match the following regular expression: + ``^[0-9]+[.][0-9]+[.][0-9]+$``, which would allow to + order/compare different versions. Example: 1.0.0, 1.0.1, + etc. + schema (str): + Required. The raw YAML string representation of the + MetadataSchema. The combination of [MetadataSchema.version] + and the schema name given by ``title`` in + [MetadataSchema.schema] must be unique within a + MetadataStore. + + The schema is defined as an OpenAPI 3.0.2 `MetadataSchema + Object `__ + schema_type (google.cloud.aiplatform_v1.types.MetadataSchema.MetadataSchemaType): + The type of the MetadataSchema. This is a + property that identifies which metadata types + will use the MetadataSchema. + create_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp when this + MetadataSchema was created. + description (str): + Description of the Metadata Schema + """ + + class MetadataSchemaType(proto.Enum): + r"""Describes the type of the MetadataSchema.""" + METADATA_SCHEMA_TYPE_UNSPECIFIED = 0 + ARTIFACT_TYPE = 1 + EXECUTION_TYPE = 2 + CONTEXT_TYPE = 3 + + name = proto.Field( + proto.STRING, + number=1, + ) + schema_version = proto.Field( + proto.STRING, + number=2, + ) + schema = proto.Field( + proto.STRING, + number=3, + ) + schema_type = proto.Field( + proto.ENUM, + number=4, + enum=MetadataSchemaType, + ) + create_time = proto.Field( + proto.MESSAGE, + number=5, + message=timestamp_pb2.Timestamp, + ) + description = proto.Field( + proto.STRING, + number=6, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/metadata_service.py b/google/cloud/aiplatform_v1/types/metadata_service.py new file mode 100644 index 0000000000..30a48e00f3 --- /dev/null +++ b/google/cloud/aiplatform_v1/types/metadata_service.py @@ -0,0 +1,1477 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + +from google.cloud.aiplatform_v1.types import artifact as gca_artifact +from google.cloud.aiplatform_v1.types import context as gca_context +from google.cloud.aiplatform_v1.types import event +from google.cloud.aiplatform_v1.types import execution as gca_execution +from google.cloud.aiplatform_v1.types import metadata_schema as gca_metadata_schema +from google.cloud.aiplatform_v1.types import metadata_store as gca_metadata_store +from google.cloud.aiplatform_v1.types import operation +from google.protobuf import field_mask_pb2 # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "CreateMetadataStoreRequest", + "CreateMetadataStoreOperationMetadata", + "GetMetadataStoreRequest", + "ListMetadataStoresRequest", + "ListMetadataStoresResponse", + "DeleteMetadataStoreRequest", + "DeleteMetadataStoreOperationMetadata", + "CreateArtifactRequest", + "GetArtifactRequest", + "ListArtifactsRequest", + "ListArtifactsResponse", + "UpdateArtifactRequest", + "DeleteArtifactRequest", + "PurgeArtifactsRequest", + "PurgeArtifactsResponse", + "PurgeArtifactsMetadata", + "CreateContextRequest", + "GetContextRequest", + "ListContextsRequest", + "ListContextsResponse", + "UpdateContextRequest", + "DeleteContextRequest", + "PurgeContextsRequest", + "PurgeContextsResponse", + "PurgeContextsMetadata", + "AddContextArtifactsAndExecutionsRequest", + "AddContextArtifactsAndExecutionsResponse", + "AddContextChildrenRequest", + "AddContextChildrenResponse", + "QueryContextLineageSubgraphRequest", + "CreateExecutionRequest", + "GetExecutionRequest", + "ListExecutionsRequest", + "ListExecutionsResponse", + "UpdateExecutionRequest", + "DeleteExecutionRequest", + "PurgeExecutionsRequest", + "PurgeExecutionsResponse", + "PurgeExecutionsMetadata", + "AddExecutionEventsRequest", + "AddExecutionEventsResponse", + "QueryExecutionInputsAndOutputsRequest", + "CreateMetadataSchemaRequest", + "GetMetadataSchemaRequest", + "ListMetadataSchemasRequest", + "ListMetadataSchemasResponse", + "QueryArtifactLineageSubgraphRequest", + }, +) + + +class CreateMetadataStoreRequest(proto.Message): + r"""Request message for + [MetadataService.CreateMetadataStore][google.cloud.aiplatform.v1.MetadataService.CreateMetadataStore]. + + Attributes: + parent (str): + Required. The resource name of the Location where the + MetadataStore should be created. Format: + ``projects/{project}/locations/{location}/`` + metadata_store (google.cloud.aiplatform_v1.types.MetadataStore): + Required. The MetadataStore to create. + metadata_store_id (str): + The {metadatastore} portion of the resource name with the + format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + If not provided, the MetadataStore's ID will be a UUID + generated by the service. Must be 4-128 characters in + length. Valid characters are ``/[a-z][0-9]-/``. Must be + unique across all MetadataStores in the parent Location. + (Otherwise the request will fail with ALREADY_EXISTS, or + PERMISSION_DENIED if the caller can't view the preexisting + MetadataStore.) + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + metadata_store = proto.Field( + proto.MESSAGE, + number=2, + message=gca_metadata_store.MetadataStore, + ) + metadata_store_id = proto.Field( + proto.STRING, + number=3, + ) + + +class CreateMetadataStoreOperationMetadata(proto.Message): + r"""Details of operations that perform + [MetadataService.CreateMetadataStore][google.cloud.aiplatform.v1.MetadataService.CreateMetadataStore]. + + Attributes: + generic_metadata (google.cloud.aiplatform_v1.types.GenericOperationMetadata): + Operation metadata for creating a + MetadataStore. + """ + + generic_metadata = proto.Field( + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, + ) + + +class GetMetadataStoreRequest(proto.Message): + r"""Request message for + [MetadataService.GetMetadataStore][google.cloud.aiplatform.v1.MetadataService.GetMetadataStore]. + + Attributes: + name (str): + Required. The resource name of the MetadataStore to + retrieve. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class ListMetadataStoresRequest(proto.Message): + r"""Request message for + [MetadataService.ListMetadataStores][google.cloud.aiplatform.v1.MetadataService.ListMetadataStores]. + + Attributes: + parent (str): + Required. The Location whose MetadataStores should be + listed. Format: ``projects/{project}/locations/{location}`` + page_size (int): + The maximum number of Metadata Stores to + return. The service may return fewer. + Must be in range 1-1000, inclusive. Defaults to + 100. + page_token (str): + A page token, received from a previous + [MetadataService.ListMetadataStores][google.cloud.aiplatform.v1.MetadataService.ListMetadataStores] + call. Provide this to retrieve the subsequent page. + + When paginating, all other provided parameters must match + the call that provided the page token. (Otherwise the + request will fail with INVALID_ARGUMENT error.) + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + page_size = proto.Field( + proto.INT32, + number=2, + ) + page_token = proto.Field( + proto.STRING, + number=3, + ) + + +class ListMetadataStoresResponse(proto.Message): + r"""Response message for + [MetadataService.ListMetadataStores][google.cloud.aiplatform.v1.MetadataService.ListMetadataStores]. + + Attributes: + metadata_stores (Sequence[google.cloud.aiplatform_v1.types.MetadataStore]): + The MetadataStores found for the Location. + next_page_token (str): + A token, which can be sent as + [ListMetadataStoresRequest.page_token][google.cloud.aiplatform.v1.ListMetadataStoresRequest.page_token] + to retrieve the next page. If this field is not populated, + there are no subsequent pages. + """ + + @property + def raw_page(self): + return self + + metadata_stores = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gca_metadata_store.MetadataStore, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) + + +class DeleteMetadataStoreRequest(proto.Message): + r"""Request message for + [MetadataService.DeleteMetadataStore][google.cloud.aiplatform.v1.MetadataService.DeleteMetadataStore]. + + Attributes: + name (str): + Required. The resource name of the MetadataStore to delete. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + force (bool): + Deprecated: Field is no longer supported. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + force = proto.Field( + proto.BOOL, + number=2, + ) + + +class DeleteMetadataStoreOperationMetadata(proto.Message): + r"""Details of operations that perform + [MetadataService.DeleteMetadataStore][google.cloud.aiplatform.v1.MetadataService.DeleteMetadataStore]. + + Attributes: + generic_metadata (google.cloud.aiplatform_v1.types.GenericOperationMetadata): + Operation metadata for deleting a + MetadataStore. + """ + + generic_metadata = proto.Field( + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, + ) + + +class CreateArtifactRequest(proto.Message): + r"""Request message for + [MetadataService.CreateArtifact][google.cloud.aiplatform.v1.MetadataService.CreateArtifact]. + + Attributes: + parent (str): + Required. The resource name of the MetadataStore where the + Artifact should be created. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + artifact (google.cloud.aiplatform_v1.types.Artifact): + Required. The Artifact to create. + artifact_id (str): + The {artifact} portion of the resource name with the format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact}`` + If not provided, the Artifact's ID will be a UUID generated + by the service. Must be 4-128 characters in length. Valid + characters are ``/[a-z][0-9]-/``. Must be unique across all + Artifacts in the parent MetadataStore. (Otherwise the + request will fail with ALREADY_EXISTS, or PERMISSION_DENIED + if the caller can't view the preexisting Artifact.) + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + artifact = proto.Field( + proto.MESSAGE, + number=2, + message=gca_artifact.Artifact, + ) + artifact_id = proto.Field( + proto.STRING, + number=3, + ) + + +class GetArtifactRequest(proto.Message): + r"""Request message for + [MetadataService.GetArtifact][google.cloud.aiplatform.v1.MetadataService.GetArtifact]. + + Attributes: + name (str): + Required. The resource name of the Artifact to retrieve. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact}`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class ListArtifactsRequest(proto.Message): + r"""Request message for + [MetadataService.ListArtifacts][google.cloud.aiplatform.v1.MetadataService.ListArtifacts]. + + Attributes: + parent (str): + Required. The MetadataStore whose Artifacts should be + listed. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + page_size (int): + The maximum number of Artifacts to return. + The service may return fewer. Must be in range + 1-1000, inclusive. Defaults to 100. + page_token (str): + A page token, received from a previous + [MetadataService.ListArtifacts][google.cloud.aiplatform.v1.MetadataService.ListArtifacts] + call. Provide this to retrieve the subsequent page. + + When paginating, all other provided parameters must match + the call that provided the page token. (Otherwise the + request will fail with INVALID_ARGUMENT error.) + filter (str): + Filter specifying the boolean condition for the Artifacts to + satisfy in order to be part of the result set. The syntax to + define filter query is based on https://google.aip.dev/160. + The supported set of filters include the following: + + - **Attribute filtering**: For example: + ``display_name = "test"``. Supported fields include: + ``name``, ``display_name``, ``uri``, ``state``, + ``schema_title``, ``create_time``, and ``update_time``. + Time fields, such as ``create_time`` and ``update_time``, + require values specified in RFC-3339 format. For example: + ``create_time = "2020-11-19T11:30:00-04:00"`` + - **Metadata field**: To filter on metadata fields use + traversal operation as follows: + ``metadata..``. For example: + ``metadata.field_1.number_value = 10.0`` + - **Context based filtering**: To filter Artifacts based on + the contexts to which they belong, use the function + operator with the full resource name + ``in_context()``. For example: + ``in_context("projects//locations//metadataStores//contexts/")`` + + Each of the above supported filter types can be combined + together using logical operators (``AND`` & ``OR``). + + For example: + ``display_name = "test" AND metadata.field1.bool_value = true``. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + page_size = proto.Field( + proto.INT32, + number=2, + ) + page_token = proto.Field( + proto.STRING, + number=3, + ) + filter = proto.Field( + proto.STRING, + number=4, + ) + + +class ListArtifactsResponse(proto.Message): + r"""Response message for + [MetadataService.ListArtifacts][google.cloud.aiplatform.v1.MetadataService.ListArtifacts]. + + Attributes: + artifacts (Sequence[google.cloud.aiplatform_v1.types.Artifact]): + The Artifacts retrieved from the + MetadataStore. + next_page_token (str): + A token, which can be sent as + [ListArtifactsRequest.page_token][google.cloud.aiplatform.v1.ListArtifactsRequest.page_token] + to retrieve the next page. If this field is not populated, + there are no subsequent pages. + """ + + @property + def raw_page(self): + return self + + artifacts = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gca_artifact.Artifact, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) + + +class UpdateArtifactRequest(proto.Message): + r"""Request message for + [MetadataService.UpdateArtifact][google.cloud.aiplatform.v1.MetadataService.UpdateArtifact]. + + Attributes: + artifact (google.cloud.aiplatform_v1.types.Artifact): + Required. The Artifact containing updates. The Artifact's + [Artifact.name][google.cloud.aiplatform.v1.Artifact.name] + field is used to identify the Artifact to be updated. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact}`` + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Optional. A FieldMask indicating which fields + should be updated. Functionality of this field + is not yet supported. + allow_missing (bool): + If set to true, and the + [Artifact][google.cloud.aiplatform.v1.Artifact] is not + found, a new [Artifact][google.cloud.aiplatform.v1.Artifact] + is created. + """ + + artifact = proto.Field( + proto.MESSAGE, + number=1, + message=gca_artifact.Artifact, + ) + update_mask = proto.Field( + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) + allow_missing = proto.Field( + proto.BOOL, + number=3, + ) + + +class DeleteArtifactRequest(proto.Message): + r"""Request message for + [MetadataService.DeleteArtifact][google.cloud.aiplatform.v1.MetadataService.DeleteArtifact]. + + Attributes: + name (str): + Required. The resource name of the Artifact to delete. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact}`` + etag (str): + Optional. The etag of the Artifact to delete. If this is + provided, it must match the server's etag. Otherwise, the + request will fail with a FAILED_PRECONDITION. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + etag = proto.Field( + proto.STRING, + number=2, + ) + + +class PurgeArtifactsRequest(proto.Message): + r"""Request message for + [MetadataService.PurgeArtifacts][google.cloud.aiplatform.v1.MetadataService.PurgeArtifacts]. + + Attributes: + parent (str): + Required. The metadata store to purge Artifacts from. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + filter (str): + Required. A required filter matching the Artifacts to be + purged. E.g., ``update_time <= 2020-11-19T11:30:00-04:00``. + force (bool): + Optional. Flag to indicate to actually perform the purge. If + ``force`` is set to false, the method will return a sample + of Artifact names that would be deleted. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + force = proto.Field( + proto.BOOL, + number=3, + ) + + +class PurgeArtifactsResponse(proto.Message): + r"""Response message for + [MetadataService.PurgeArtifacts][google.cloud.aiplatform.v1.MetadataService.PurgeArtifacts]. + + Attributes: + purge_count (int): + The number of Artifacts that this request deleted (or, if + ``force`` is false, the number of Artifacts that will be + deleted). This can be an estimate. + purge_sample (Sequence[str]): + A sample of the Artifact names that will be deleted. Only + populated if ``force`` is set to false. The maximum number + of samples is 100 (it is possible to return fewer). + """ + + purge_count = proto.Field( + proto.INT64, + number=1, + ) + purge_sample = proto.RepeatedField( + proto.STRING, + number=2, + ) + + +class PurgeArtifactsMetadata(proto.Message): + r"""Details of operations that perform + [MetadataService.PurgeArtifacts][google.cloud.aiplatform.v1.MetadataService.PurgeArtifacts]. + + Attributes: + generic_metadata (google.cloud.aiplatform_v1.types.GenericOperationMetadata): + Operation metadata for purging Artifacts. + """ + + generic_metadata = proto.Field( + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, + ) + + +class CreateContextRequest(proto.Message): + r"""Request message for + [MetadataService.CreateContext][google.cloud.aiplatform.v1.MetadataService.CreateContext]. + + Attributes: + parent (str): + Required. The resource name of the MetadataStore where the + Context should be created. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + context (google.cloud.aiplatform_v1.types.Context): + Required. The Context to create. + context_id (str): + The {context} portion of the resource name with the format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}``. + If not provided, the Context's ID will be a UUID generated + by the service. Must be 4-128 characters in length. Valid + characters are ``/[a-z][0-9]-/``. Must be unique across all + Contexts in the parent MetadataStore. (Otherwise the request + will fail with ALREADY_EXISTS, or PERMISSION_DENIED if the + caller can't view the preexisting Context.) + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + context = proto.Field( + proto.MESSAGE, + number=2, + message=gca_context.Context, + ) + context_id = proto.Field( + proto.STRING, + number=3, + ) + + +class GetContextRequest(proto.Message): + r"""Request message for + [MetadataService.GetContext][google.cloud.aiplatform.v1.MetadataService.GetContext]. + + Attributes: + name (str): + Required. The resource name of the Context to retrieve. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class ListContextsRequest(proto.Message): + r"""Request message for + [MetadataService.ListContexts][google.cloud.aiplatform.v1.MetadataService.ListContexts] + + Attributes: + parent (str): + Required. The MetadataStore whose Contexts should be listed. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + page_size (int): + The maximum number of Contexts to return. The + service may return fewer. Must be in range + 1-1000, inclusive. Defaults to 100. + page_token (str): + A page token, received from a previous + [MetadataService.ListContexts][google.cloud.aiplatform.v1.MetadataService.ListContexts] + call. Provide this to retrieve the subsequent page. + + When paginating, all other provided parameters must match + the call that provided the page token. (Otherwise the + request will fail with INVALID_ARGUMENT error.) + filter (str): + Filter specifying the boolean condition for the Contexts to + satisfy in order to be part of the result set. The syntax to + define filter query is based on https://google.aip.dev/160. + Following are the supported set of filters: + + - **Attribute filtering**: For example: + ``display_name = "test"``. Supported fields include: + ``name``, ``display_name``, ``schema_title``, + ``create_time``, and ``update_time``. Time fields, such + as ``create_time`` and ``update_time``, require values + specified in RFC-3339 format. For example: + ``create_time = "2020-11-19T11:30:00-04:00"``. + + - **Metadata field**: To filter on metadata fields use + traversal operation as follows: + ``metadata..``. For example: + ``metadata.field_1.number_value = 10.0``. + + - **Parent Child filtering**: To filter Contexts based on + parent-child relationship use the HAS operator as + follows: + + :: + + parent_contexts: + "projects//locations//metadataStores//contexts/" + child_contexts: + "projects//locations//metadataStores//contexts/" + + Each of the above supported filters can be combined together + using logical operators (``AND`` & ``OR``). + + For example: + ``display_name = "test" AND metadata.field1.bool_value = true``. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + page_size = proto.Field( + proto.INT32, + number=2, + ) + page_token = proto.Field( + proto.STRING, + number=3, + ) + filter = proto.Field( + proto.STRING, + number=4, + ) + + +class ListContextsResponse(proto.Message): + r"""Response message for + [MetadataService.ListContexts][google.cloud.aiplatform.v1.MetadataService.ListContexts]. + + Attributes: + contexts (Sequence[google.cloud.aiplatform_v1.types.Context]): + The Contexts retrieved from the + MetadataStore. + next_page_token (str): + A token, which can be sent as + [ListContextsRequest.page_token][google.cloud.aiplatform.v1.ListContextsRequest.page_token] + to retrieve the next page. If this field is not populated, + there are no subsequent pages. + """ + + @property + def raw_page(self): + return self + + contexts = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gca_context.Context, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) + + +class UpdateContextRequest(proto.Message): + r"""Request message for + [MetadataService.UpdateContext][google.cloud.aiplatform.v1.MetadataService.UpdateContext]. + + Attributes: + context (google.cloud.aiplatform_v1.types.Context): + Required. The Context containing updates. The Context's + [Context.name][google.cloud.aiplatform.v1.Context.name] + field is used to identify the Context to be updated. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Optional. A FieldMask indicating which fields + should be updated. Functionality of this field + is not yet supported. + allow_missing (bool): + If set to true, and the + [Context][google.cloud.aiplatform.v1.Context] is not found, + a new [Context][google.cloud.aiplatform.v1.Context] is + created. + """ + + context = proto.Field( + proto.MESSAGE, + number=1, + message=gca_context.Context, + ) + update_mask = proto.Field( + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) + allow_missing = proto.Field( + proto.BOOL, + number=3, + ) + + +class DeleteContextRequest(proto.Message): + r"""Request message for + [MetadataService.DeleteContext][google.cloud.aiplatform.v1.MetadataService.DeleteContext]. + + Attributes: + name (str): + Required. The resource name of the Context to delete. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` + force (bool): + The force deletion semantics is still + undefined. Users should not use this field. + etag (str): + Optional. The etag of the Context to delete. If this is + provided, it must match the server's etag. Otherwise, the + request will fail with a FAILED_PRECONDITION. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + force = proto.Field( + proto.BOOL, + number=2, + ) + etag = proto.Field( + proto.STRING, + number=3, + ) + + +class PurgeContextsRequest(proto.Message): + r"""Request message for + [MetadataService.PurgeContexts][google.cloud.aiplatform.v1.MetadataService.PurgeContexts]. + + Attributes: + parent (str): + Required. The metadata store to purge Contexts from. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + filter (str): + Required. A required filter matching the Contexts to be + purged. E.g., ``update_time <= 2020-11-19T11:30:00-04:00``. + force (bool): + Optional. Flag to indicate to actually perform the purge. If + ``force`` is set to false, the method will return a sample + of Context names that would be deleted. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + force = proto.Field( + proto.BOOL, + number=3, + ) + + +class PurgeContextsResponse(proto.Message): + r"""Response message for + [MetadataService.PurgeContexts][google.cloud.aiplatform.v1.MetadataService.PurgeContexts]. + + Attributes: + purge_count (int): + The number of Contexts that this request deleted (or, if + ``force`` is false, the number of Contexts that will be + deleted). This can be an estimate. + purge_sample (Sequence[str]): + A sample of the Context names that will be deleted. Only + populated if ``force`` is set to false. The maximum number + of samples is 100 (it is possible to return fewer). + """ + + purge_count = proto.Field( + proto.INT64, + number=1, + ) + purge_sample = proto.RepeatedField( + proto.STRING, + number=2, + ) + + +class PurgeContextsMetadata(proto.Message): + r"""Details of operations that perform + [MetadataService.PurgeContexts][google.cloud.aiplatform.v1.MetadataService.PurgeContexts]. + + Attributes: + generic_metadata (google.cloud.aiplatform_v1.types.GenericOperationMetadata): + Operation metadata for purging Contexts. + """ + + generic_metadata = proto.Field( + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, + ) + + +class AddContextArtifactsAndExecutionsRequest(proto.Message): + r"""Request message for + [MetadataService.AddContextArtifactsAndExecutions][google.cloud.aiplatform.v1.MetadataService.AddContextArtifactsAndExecutions]. + + Attributes: + context (str): + Required. The resource name of the Context that the + Artifacts and Executions belong to. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` + artifacts (Sequence[str]): + The resource names of the Artifacts to attribute to the + Context. + + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact}`` + executions (Sequence[str]): + The resource names of the Executions to associate with the + Context. + + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` + """ + + context = proto.Field( + proto.STRING, + number=1, + ) + artifacts = proto.RepeatedField( + proto.STRING, + number=2, + ) + executions = proto.RepeatedField( + proto.STRING, + number=3, + ) + + +class AddContextArtifactsAndExecutionsResponse(proto.Message): + r"""Response message for + [MetadataService.AddContextArtifactsAndExecutions][google.cloud.aiplatform.v1.MetadataService.AddContextArtifactsAndExecutions]. + + """ + + +class AddContextChildrenRequest(proto.Message): + r"""Request message for + [MetadataService.AddContextChildren][google.cloud.aiplatform.v1.MetadataService.AddContextChildren]. + + Attributes: + context (str): + Required. The resource name of the parent Context. + + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` + child_contexts (Sequence[str]): + The resource names of the child Contexts. + """ + + context = proto.Field( + proto.STRING, + number=1, + ) + child_contexts = proto.RepeatedField( + proto.STRING, + number=2, + ) + + +class AddContextChildrenResponse(proto.Message): + r"""Response message for + [MetadataService.AddContextChildren][google.cloud.aiplatform.v1.MetadataService.AddContextChildren]. + + """ + + +class QueryContextLineageSubgraphRequest(proto.Message): + r"""Request message for + [MetadataService.QueryContextLineageSubgraph][google.cloud.aiplatform.v1.MetadataService.QueryContextLineageSubgraph]. + + Attributes: + context (str): + Required. The resource name of the Context whose Artifacts + and Executions should be retrieved as a LineageSubgraph. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` + + The request may error with FAILED_PRECONDITION if the number + of Artifacts, the number of Executions, or the number of + Events that would be returned for the Context exceeds 1000. + """ + + context = proto.Field( + proto.STRING, + number=1, + ) + + +class CreateExecutionRequest(proto.Message): + r"""Request message for + [MetadataService.CreateExecution][google.cloud.aiplatform.v1.MetadataService.CreateExecution]. + + Attributes: + parent (str): + Required. The resource name of the MetadataStore where the + Execution should be created. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + execution (google.cloud.aiplatform_v1.types.Execution): + Required. The Execution to create. + execution_id (str): + The {execution} portion of the resource name with the + format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` + If not provided, the Execution's ID will be a UUID generated + by the service. Must be 4-128 characters in length. Valid + characters are ``/[a-z][0-9]-/``. Must be unique across all + Executions in the parent MetadataStore. (Otherwise the + request will fail with ALREADY_EXISTS, or PERMISSION_DENIED + if the caller can't view the preexisting Execution.) + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + execution = proto.Field( + proto.MESSAGE, + number=2, + message=gca_execution.Execution, + ) + execution_id = proto.Field( + proto.STRING, + number=3, + ) + + +class GetExecutionRequest(proto.Message): + r"""Request message for + [MetadataService.GetExecution][google.cloud.aiplatform.v1.MetadataService.GetExecution]. + + Attributes: + name (str): + Required. The resource name of the Execution to retrieve. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class ListExecutionsRequest(proto.Message): + r"""Request message for + [MetadataService.ListExecutions][google.cloud.aiplatform.v1.MetadataService.ListExecutions]. + + Attributes: + parent (str): + Required. The MetadataStore whose Executions should be + listed. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + page_size (int): + The maximum number of Executions to return. + The service may return fewer. Must be in range + 1-1000, inclusive. Defaults to 100. + page_token (str): + A page token, received from a previous + [MetadataService.ListExecutions][google.cloud.aiplatform.v1.MetadataService.ListExecutions] + call. Provide this to retrieve the subsequent page. + + When paginating, all other provided parameters must match + the call that provided the page token. (Otherwise the + request will fail with an INVALID_ARGUMENT error.) + filter (str): + Filter specifying the boolean condition for the Executions + to satisfy in order to be part of the result set. The syntax + to define filter query is based on + https://google.aip.dev/160. Following are the supported set + of filters: + + - **Attribute filtering**: For example: + ``display_name = "test"``. Supported fields include: + ``name``, ``display_name``, ``state``, ``schema_title``, + ``create_time``, and ``update_time``. Time fields, such + as ``create_time`` and ``update_time``, require values + specified in RFC-3339 format. For example: + ``create_time = "2020-11-19T11:30:00-04:00"``. + - **Metadata field**: To filter on metadata fields use + traversal operation as follows: + ``metadata..`` For example: + ``metadata.field_1.number_value = 10.0`` + - **Context based filtering**: To filter Executions based + on the contexts to which they belong use the function + operator with the full resource name: + ``in_context()``. For example: + ``in_context("projects//locations//metadataStores//contexts/")`` + + Each of the above supported filters can be combined together + using logical operators (``AND`` & ``OR``). For example: + ``display_name = "test" AND metadata.field1.bool_value = true``. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + page_size = proto.Field( + proto.INT32, + number=2, + ) + page_token = proto.Field( + proto.STRING, + number=3, + ) + filter = proto.Field( + proto.STRING, + number=4, + ) + + +class ListExecutionsResponse(proto.Message): + r"""Response message for + [MetadataService.ListExecutions][google.cloud.aiplatform.v1.MetadataService.ListExecutions]. + + Attributes: + executions (Sequence[google.cloud.aiplatform_v1.types.Execution]): + The Executions retrieved from the + MetadataStore. + next_page_token (str): + A token, which can be sent as + [ListExecutionsRequest.page_token][google.cloud.aiplatform.v1.ListExecutionsRequest.page_token] + to retrieve the next page. If this field is not populated, + there are no subsequent pages. + """ + + @property + def raw_page(self): + return self + + executions = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gca_execution.Execution, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) + + +class UpdateExecutionRequest(proto.Message): + r"""Request message for + [MetadataService.UpdateExecution][google.cloud.aiplatform.v1.MetadataService.UpdateExecution]. + + Attributes: + execution (google.cloud.aiplatform_v1.types.Execution): + Required. The Execution containing updates. The Execution's + [Execution.name][google.cloud.aiplatform.v1.Execution.name] + field is used to identify the Execution to be updated. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Optional. A FieldMask indicating which fields + should be updated. Functionality of this field + is not yet supported. + allow_missing (bool): + If set to true, and the + [Execution][google.cloud.aiplatform.v1.Execution] is not + found, a new + [Execution][google.cloud.aiplatform.v1.Execution] is + created. + """ + + execution = proto.Field( + proto.MESSAGE, + number=1, + message=gca_execution.Execution, + ) + update_mask = proto.Field( + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) + allow_missing = proto.Field( + proto.BOOL, + number=3, + ) + + +class DeleteExecutionRequest(proto.Message): + r"""Request message for + [MetadataService.DeleteExecution][google.cloud.aiplatform.v1.MetadataService.DeleteExecution]. + + Attributes: + name (str): + Required. The resource name of the Execution to delete. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` + etag (str): + Optional. The etag of the Execution to delete. If this is + provided, it must match the server's etag. Otherwise, the + request will fail with a FAILED_PRECONDITION. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + etag = proto.Field( + proto.STRING, + number=2, + ) + + +class PurgeExecutionsRequest(proto.Message): + r"""Request message for + [MetadataService.PurgeExecutions][google.cloud.aiplatform.v1.MetadataService.PurgeExecutions]. + + Attributes: + parent (str): + Required. The metadata store to purge Executions from. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + filter (str): + Required. A required filter matching the Executions to be + purged. E.g., ``update_time <= 2020-11-19T11:30:00-04:00``. + force (bool): + Optional. Flag to indicate to actually perform the purge. If + ``force`` is set to false, the method will return a sample + of Execution names that would be deleted. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + force = proto.Field( + proto.BOOL, + number=3, + ) + + +class PurgeExecutionsResponse(proto.Message): + r"""Response message for + [MetadataService.PurgeExecutions][google.cloud.aiplatform.v1.MetadataService.PurgeExecutions]. + + Attributes: + purge_count (int): + The number of Executions that this request deleted (or, if + ``force`` is false, the number of Executions that will be + deleted). This can be an estimate. + purge_sample (Sequence[str]): + A sample of the Execution names that will be deleted. Only + populated if ``force`` is set to false. The maximum number + of samples is 100 (it is possible to return fewer). + """ + + purge_count = proto.Field( + proto.INT64, + number=1, + ) + purge_sample = proto.RepeatedField( + proto.STRING, + number=2, + ) + + +class PurgeExecutionsMetadata(proto.Message): + r"""Details of operations that perform + [MetadataService.PurgeExecutions][google.cloud.aiplatform.v1.MetadataService.PurgeExecutions]. + + Attributes: + generic_metadata (google.cloud.aiplatform_v1.types.GenericOperationMetadata): + Operation metadata for purging Executions. + """ + + generic_metadata = proto.Field( + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, + ) + + +class AddExecutionEventsRequest(proto.Message): + r"""Request message for + [MetadataService.AddExecutionEvents][google.cloud.aiplatform.v1.MetadataService.AddExecutionEvents]. + + Attributes: + execution (str): + Required. The resource name of the Execution that the Events + connect Artifacts with. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` + events (Sequence[google.cloud.aiplatform_v1.types.Event]): + The Events to create and add. + """ + + execution = proto.Field( + proto.STRING, + number=1, + ) + events = proto.RepeatedField( + proto.MESSAGE, + number=2, + message=event.Event, + ) + + +class AddExecutionEventsResponse(proto.Message): + r"""Response message for + [MetadataService.AddExecutionEvents][google.cloud.aiplatform.v1.MetadataService.AddExecutionEvents]. + + """ + + +class QueryExecutionInputsAndOutputsRequest(proto.Message): + r"""Request message for + [MetadataService.QueryExecutionInputsAndOutputs][google.cloud.aiplatform.v1.MetadataService.QueryExecutionInputsAndOutputs]. + + Attributes: + execution (str): + Required. The resource name of the Execution whose input and + output Artifacts should be retrieved as a LineageSubgraph. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` + """ + + execution = proto.Field( + proto.STRING, + number=1, + ) + + +class CreateMetadataSchemaRequest(proto.Message): + r"""Request message for + [MetadataService.CreateMetadataSchema][google.cloud.aiplatform.v1.MetadataService.CreateMetadataSchema]. + + Attributes: + parent (str): + Required. The resource name of the MetadataStore where the + MetadataSchema should be created. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + metadata_schema (google.cloud.aiplatform_v1.types.MetadataSchema): + Required. The MetadataSchema to create. + metadata_schema_id (str): + The {metadata_schema} portion of the resource name with the + format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/metadataSchemas/{metadataschema}`` + If not provided, the MetadataStore's ID will be a UUID + generated by the service. Must be 4-128 characters in + length. Valid characters are ``/[a-z][0-9]-/``. Must be + unique across all MetadataSchemas in the parent Location. + (Otherwise the request will fail with ALREADY_EXISTS, or + PERMISSION_DENIED if the caller can't view the preexisting + MetadataSchema.) + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + metadata_schema = proto.Field( + proto.MESSAGE, + number=2, + message=gca_metadata_schema.MetadataSchema, + ) + metadata_schema_id = proto.Field( + proto.STRING, + number=3, + ) + + +class GetMetadataSchemaRequest(proto.Message): + r"""Request message for + [MetadataService.GetMetadataSchema][google.cloud.aiplatform.v1.MetadataService.GetMetadataSchema]. + + Attributes: + name (str): + Required. The resource name of the MetadataSchema to + retrieve. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/metadataSchemas/{metadataschema}`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class ListMetadataSchemasRequest(proto.Message): + r"""Request message for + [MetadataService.ListMetadataSchemas][google.cloud.aiplatform.v1.MetadataService.ListMetadataSchemas]. + + Attributes: + parent (str): + Required. The MetadataStore whose MetadataSchemas should be + listed. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + page_size (int): + The maximum number of MetadataSchemas to + return. The service may return fewer. + Must be in range 1-1000, inclusive. Defaults to + 100. + page_token (str): + A page token, received from a previous + [MetadataService.ListMetadataSchemas][google.cloud.aiplatform.v1.MetadataService.ListMetadataSchemas] + call. Provide this to retrieve the next page. + + When paginating, all other provided parameters must match + the call that provided the page token. (Otherwise the + request will fail with INVALID_ARGUMENT error.) + filter (str): + A query to filter available MetadataSchemas + for matching results. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + page_size = proto.Field( + proto.INT32, + number=2, + ) + page_token = proto.Field( + proto.STRING, + number=3, + ) + filter = proto.Field( + proto.STRING, + number=4, + ) + + +class ListMetadataSchemasResponse(proto.Message): + r"""Response message for + [MetadataService.ListMetadataSchemas][google.cloud.aiplatform.v1.MetadataService.ListMetadataSchemas]. + + Attributes: + metadata_schemas (Sequence[google.cloud.aiplatform_v1.types.MetadataSchema]): + The MetadataSchemas found for the + MetadataStore. + next_page_token (str): + A token, which can be sent as + [ListMetadataSchemasRequest.page_token][google.cloud.aiplatform.v1.ListMetadataSchemasRequest.page_token] + to retrieve the next page. If this field is not populated, + there are no subsequent pages. + """ + + @property + def raw_page(self): + return self + + metadata_schemas = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gca_metadata_schema.MetadataSchema, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) + + +class QueryArtifactLineageSubgraphRequest(proto.Message): + r"""Request message for + [MetadataService.QueryArtifactLineageSubgraph][google.cloud.aiplatform.v1.MetadataService.QueryArtifactLineageSubgraph]. + + Attributes: + artifact (str): + Required. The resource name of the Artifact whose Lineage + needs to be retrieved as a LineageSubgraph. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact}`` + + The request may error with FAILED_PRECONDITION if the number + of Artifacts, the number of Executions, or the number of + Events that would be returned for the Context exceeds 1000. + max_hops (int): + Specifies the size of the lineage graph in terms of number + of hops from the specified artifact. Negative Value: + INVALID_ARGUMENT error is returned 0: Only input artifact is + returned. No value: Transitive closure is performed to + return the complete graph. + filter (str): + Filter specifying the boolean condition for the Artifacts to + satisfy in order to be part of the Lineage Subgraph. The + syntax to define filter query is based on + https://google.aip.dev/160. The supported set of filters + include the following: + + - **Attribute filtering**: For example: + ``display_name = "test"`` Supported fields include: + ``name``, ``display_name``, ``uri``, ``state``, + ``schema_title``, ``create_time``, and ``update_time``. + Time fields, such as ``create_time`` and ``update_time``, + require values specified in RFC-3339 format. For example: + ``create_time = "2020-11-19T11:30:00-04:00"`` + - **Metadata field**: To filter on metadata fields use + traversal operation as follows: + ``metadata..``. For example: + ``metadata.field_1.number_value = 10.0`` + + Each of the above supported filter types can be combined + together using logical operators (``AND`` & ``OR``). + + For example: + ``display_name = "test" AND metadata.field1.bool_value = true``. + """ + + artifact = proto.Field( + proto.STRING, + number=1, + ) + max_hops = proto.Field( + proto.INT32, + number=2, + ) + filter = proto.Field( + proto.STRING, + number=3, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/metadata_store.py b/google/cloud/aiplatform_v1/types/metadata_store.py new file mode 100644 index 0000000000..2bac3ea737 --- /dev/null +++ b/google/cloud/aiplatform_v1/types/metadata_store.py @@ -0,0 +1,100 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + +from google.cloud.aiplatform_v1.types import encryption_spec as gca_encryption_spec +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "MetadataStore", + }, +) + + +class MetadataStore(proto.Message): + r"""Instance of a metadata store. Contains a set of metadata that + can be queried. + + Attributes: + name (str): + Output only. The resource name of the + MetadataStore instance. + create_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp when this + MetadataStore was created. + update_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp when this + MetadataStore was last updated. + encryption_spec (google.cloud.aiplatform_v1.types.EncryptionSpec): + Customer-managed encryption key spec for a + Metadata Store. If set, this Metadata Store and + all sub-resources of this Metadata Store are + secured using this key. + description (str): + Description of the MetadataStore. + state (google.cloud.aiplatform_v1.types.MetadataStore.MetadataStoreState): + Output only. State information of the + MetadataStore. + """ + + class MetadataStoreState(proto.Message): + r"""Represents state information for a MetadataStore. + + Attributes: + disk_utilization_bytes (int): + The disk utilization of the MetadataStore in + bytes. + """ + + disk_utilization_bytes = proto.Field( + proto.INT64, + number=1, + ) + + name = proto.Field( + proto.STRING, + number=1, + ) + create_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + encryption_spec = proto.Field( + proto.MESSAGE, + number=5, + message=gca_encryption_spec.EncryptionSpec, + ) + description = proto.Field( + proto.STRING, + number=6, + ) + state = proto.Field( + proto.MESSAGE, + number=7, + message=MetadataStoreState, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/migratable_resource.py b/google/cloud/aiplatform_v1/types/migratable_resource.py index 2ea22001c6..d3f8866621 100644 --- a/google/cloud/aiplatform_v1/types/migratable_resource.py +++ b/google/cloud/aiplatform_v1/types/migratable_resource.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,7 +19,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1", manifest={"MigratableResource",}, + package="google.cloud.aiplatform.v1", + manifest={ + "MigratableResource", + }, ) @@ -27,19 +30,34 @@ class MigratableResource(proto.Message): r"""Represents one resource that exists in automl.googleapis.com, datalabeling.googleapis.com or ml.googleapis.com. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: ml_engine_model_version (google.cloud.aiplatform_v1.types.MigratableResource.MlEngineModelVersion): Output only. Represents one Version in ml.googleapis.com. + + This field is a member of `oneof`_ ``resource``. automl_model (google.cloud.aiplatform_v1.types.MigratableResource.AutomlModel): Output only. Represents one Model in automl.googleapis.com. + + This field is a member of `oneof`_ ``resource``. automl_dataset (google.cloud.aiplatform_v1.types.MigratableResource.AutomlDataset): Output only. Represents one Dataset in automl.googleapis.com. + + This field is a member of `oneof`_ ``resource``. data_labeling_dataset (google.cloud.aiplatform_v1.types.MigratableResource.DataLabelingDataset): Output only. Represents one Dataset in datalabeling.googleapis.com. + + This field is a member of `oneof`_ ``resource``. last_migrate_time (google.protobuf.timestamp_pb2.Timestamp): Output only. Timestamp when the last migration attempt on this MigratableResource @@ -52,6 +70,7 @@ class MigratableResource(proto.Message): class MlEngineModelVersion(proto.Message): r"""Represents one model Version in ml.googleapis.com. + Attributes: endpoint (str): The ml.googleapis.com endpoint that this model Version @@ -66,11 +85,18 @@ class MlEngineModelVersion(proto.Message): ``projects/{project}/models/{model}/versions/{version}``. """ - endpoint = proto.Field(proto.STRING, number=1,) - version = proto.Field(proto.STRING, number=2,) + endpoint = proto.Field( + proto.STRING, + number=1, + ) + version = proto.Field( + proto.STRING, + number=2, + ) class AutomlModel(proto.Message): r"""Represents one Model in automl.googleapis.com. + Attributes: model (str): Full resource name of automl Model. Format: @@ -80,11 +106,18 @@ class AutomlModel(proto.Message): automl.googleapis.com. """ - model = proto.Field(proto.STRING, number=1,) - model_display_name = proto.Field(proto.STRING, number=3,) + model = proto.Field( + proto.STRING, + number=1, + ) + model_display_name = proto.Field( + proto.STRING, + number=3, + ) class AutomlDataset(proto.Message): r"""Represents one Dataset in automl.googleapis.com. + Attributes: dataset (str): Full resource name of automl Dataset. Format: @@ -94,11 +127,18 @@ class AutomlDataset(proto.Message): automl.googleapis.com. """ - dataset = proto.Field(proto.STRING, number=1,) - dataset_display_name = proto.Field(proto.STRING, number=4,) + dataset = proto.Field( + proto.STRING, + number=1, + ) + dataset_display_name = proto.Field( + proto.STRING, + number=4, + ) class DataLabelingDataset(proto.Message): r"""Represents one Dataset in datalabeling.googleapis.com. + Attributes: dataset (str): Full resource name of data labeling Dataset. Format: @@ -120,18 +160,29 @@ class DataLabelingAnnotatedDataset(proto.Message): annotated_dataset (str): Full resource name of data labeling AnnotatedDataset. Format: - ``projects/{project}/datasets/{dataset}/annotatedDatasets/{annotated_dataset}``. annotated_dataset_display_name (str): The AnnotatedDataset's display name in datalabeling.googleapis.com. """ - annotated_dataset = proto.Field(proto.STRING, number=1,) - annotated_dataset_display_name = proto.Field(proto.STRING, number=3,) - - dataset = proto.Field(proto.STRING, number=1,) - dataset_display_name = proto.Field(proto.STRING, number=4,) + annotated_dataset = proto.Field( + proto.STRING, + number=1, + ) + annotated_dataset_display_name = proto.Field( + proto.STRING, + number=3, + ) + + dataset = proto.Field( + proto.STRING, + number=1, + ) + dataset_display_name = proto.Field( + proto.STRING, + number=4, + ) data_labeling_annotated_datasets = proto.RepeatedField( proto.MESSAGE, number=3, @@ -139,22 +190,38 @@ class DataLabelingAnnotatedDataset(proto.Message): ) ml_engine_model_version = proto.Field( - proto.MESSAGE, number=1, oneof="resource", message=MlEngineModelVersion, + proto.MESSAGE, + number=1, + oneof="resource", + message=MlEngineModelVersion, ) automl_model = proto.Field( - proto.MESSAGE, number=2, oneof="resource", message=AutomlModel, + proto.MESSAGE, + number=2, + oneof="resource", + message=AutomlModel, ) automl_dataset = proto.Field( - proto.MESSAGE, number=3, oneof="resource", message=AutomlDataset, + proto.MESSAGE, + number=3, + oneof="resource", + message=AutomlDataset, ) data_labeling_dataset = proto.Field( - proto.MESSAGE, number=4, oneof="resource", message=DataLabelingDataset, + proto.MESSAGE, + number=4, + oneof="resource", + message=DataLabelingDataset, ) last_migrate_time = proto.Field( - proto.MESSAGE, number=5, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=5, + message=timestamp_pb2.Timestamp, ) last_update_time = proto.Field( - proto.MESSAGE, number=6, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=6, + message=timestamp_pb2.Timestamp, ) diff --git a/google/cloud/aiplatform_v1/types/migration_service.py b/google/cloud/aiplatform_v1/types/migration_service.py index 6a9d231aaf..c7263d7c48 100644 --- a/google/cloud/aiplatform_v1/types/migration_service.py +++ b/google/cloud/aiplatform_v1/types/migration_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -43,7 +43,7 @@ class SearchMigratableResourcesRequest(proto.Message): Attributes: parent (str): Required. The location that the migratable resources should - be searched from. It's the AI Platform location that the + be searched from. It's the Vertex AI location that the resources can be migrated to, not the resources' original location. Format: ``projects/{project}/locations/{location}`` @@ -53,28 +53,44 @@ class SearchMigratableResourcesRequest(proto.Message): page_token (str): The standard page token. filter (str): - Supported filters are: + A filter for your search. You can use the following types of + filters: - - Resource type: For a specific type of MigratableResource. + - Resource type filters. The following strings filter for a + specific type of + [MigratableResource][google.cloud.aiplatform.v1.MigratableResource]: - ``ml_engine_model_version:*`` - - ``automl_model:*``, + - ``automl_model:*`` - ``automl_dataset:*`` - - ``data_labeling_dataset:*``. + - ``data_labeling_dataset:*`` - - Migrated or not: Filter migrated resource or not by - last_migrate_time. + - "Migrated or not" filters. The following strings filter + for resources that either have or have not already been + migrated: - - ``last_migrate_time:*`` will filter migrated + - ``last_migrate_time:*`` filters for migrated resources. - - ``NOT last_migrate_time:*`` will filter not yet + - ``NOT last_migrate_time:*`` filters for not yet migrated resources. """ - parent = proto.Field(proto.STRING, number=1,) - page_size = proto.Field(proto.INT32, number=2,) - page_token = proto.Field(proto.STRING, number=3,) - filter = proto.Field(proto.STRING, number=4,) + parent = proto.Field( + proto.STRING, + number=1, + ) + page_size = proto.Field( + proto.INT32, + number=2, + ) + page_token = proto.Field( + proto.STRING, + number=3, + ) + filter = proto.Field( + proto.STRING, + number=4, + ) class SearchMigratableResourcesResponse(proto.Message): @@ -96,9 +112,14 @@ def raw_page(self): return self migratable_resources = proto.RepeatedField( - proto.MESSAGE, number=1, message=gca_migratable_resource.MigratableResource, + proto.MESSAGE, + number=1, + message=gca_migratable_resource.MigratableResource, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class BatchMigrateResourcesRequest(proto.Message): @@ -116,36 +137,55 @@ class BatchMigrateResourcesRequest(proto.Message): can be migrated in one batch. """ - parent = proto.Field(proto.STRING, number=1,) + parent = proto.Field( + proto.STRING, + number=1, + ) migrate_resource_requests = proto.RepeatedField( - proto.MESSAGE, number=2, message="MigrateResourceRequest", + proto.MESSAGE, + number=2, + message="MigrateResourceRequest", ) class MigrateResourceRequest(proto.Message): r"""Config of migrating one resource from automl.googleapis.com, - datalabeling.googleapis.com and ml.googleapis.com to AI - Platform. + datalabeling.googleapis.com and ml.googleapis.com to Vertex AI. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields Attributes: migrate_ml_engine_model_version_config (google.cloud.aiplatform_v1.types.MigrateResourceRequest.MigrateMlEngineModelVersionConfig): Config for migrating Version in - ml.googleapis.com to AI Platform's Model. + ml.googleapis.com to Vertex AI's Model. + + This field is a member of `oneof`_ ``request``. migrate_automl_model_config (google.cloud.aiplatform_v1.types.MigrateResourceRequest.MigrateAutomlModelConfig): Config for migrating Model in - automl.googleapis.com to AI Platform's Model. + automl.googleapis.com to Vertex AI's Model. + + This field is a member of `oneof`_ ``request``. migrate_automl_dataset_config (google.cloud.aiplatform_v1.types.MigrateResourceRequest.MigrateAutomlDatasetConfig): Config for migrating Dataset in - automl.googleapis.com to AI Platform's Dataset. + automl.googleapis.com to Vertex AI's Dataset. + + This field is a member of `oneof`_ ``request``. migrate_data_labeling_dataset_config (google.cloud.aiplatform_v1.types.MigrateResourceRequest.MigrateDataLabelingDatasetConfig): Config for migrating Dataset in - datalabeling.googleapis.com to AI Platform's + datalabeling.googleapis.com to Vertex AI's Dataset. + + This field is a member of `oneof`_ ``request``. """ class MigrateMlEngineModelVersionConfig(proto.Message): - r"""Config for migrating version in ml.googleapis.com to AI - Platform's Model. + r"""Config for migrating version in ml.googleapis.com to Vertex + AI's Model. Attributes: endpoint (str): @@ -164,85 +204,114 @@ class MigrateMlEngineModelVersionConfig(proto.Message): Format: ``projects/{project}/models/{model}/versions/{version}``. model_display_name (str): - Required. Display name of the model in AI - Platform. System will pick a display name if + Required. Display name of the model in Vertex + AI. System will pick a display name if unspecified. """ - endpoint = proto.Field(proto.STRING, number=1,) - model_version = proto.Field(proto.STRING, number=2,) - model_display_name = proto.Field(proto.STRING, number=3,) + endpoint = proto.Field( + proto.STRING, + number=1, + ) + model_version = proto.Field( + proto.STRING, + number=2, + ) + model_display_name = proto.Field( + proto.STRING, + number=3, + ) class MigrateAutomlModelConfig(proto.Message): - r"""Config for migrating Model in automl.googleapis.com to AI - Platform's Model. + r"""Config for migrating Model in automl.googleapis.com to Vertex + AI's Model. Attributes: model (str): Required. Full resource name of automl Model. Format: ``projects/{project}/locations/{location}/models/{model}``. model_display_name (str): - Optional. Display name of the model in AI - Platform. System will pick a display name if + Optional. Display name of the model in Vertex + AI. System will pick a display name if unspecified. """ - model = proto.Field(proto.STRING, number=1,) - model_display_name = proto.Field(proto.STRING, number=2,) + model = proto.Field( + proto.STRING, + number=1, + ) + model_display_name = proto.Field( + proto.STRING, + number=2, + ) class MigrateAutomlDatasetConfig(proto.Message): - r"""Config for migrating Dataset in automl.googleapis.com to AI - Platform's Dataset. + r"""Config for migrating Dataset in automl.googleapis.com to + Vertex AI's Dataset. Attributes: dataset (str): Required. Full resource name of automl Dataset. Format: ``projects/{project}/locations/{location}/datasets/{dataset}``. dataset_display_name (str): - Required. Display name of the Dataset in AI - Platform. System will pick a display name if + Required. Display name of the Dataset in + Vertex AI. System will pick a display name if unspecified. """ - dataset = proto.Field(proto.STRING, number=1,) - dataset_display_name = proto.Field(proto.STRING, number=2,) + dataset = proto.Field( + proto.STRING, + number=1, + ) + dataset_display_name = proto.Field( + proto.STRING, + number=2, + ) class MigrateDataLabelingDatasetConfig(proto.Message): r"""Config for migrating Dataset in datalabeling.googleapis.com - to AI Platform's Dataset. + to Vertex AI's Dataset. Attributes: dataset (str): Required. Full resource name of data labeling Dataset. Format: ``projects/{project}/datasets/{dataset}``. dataset_display_name (str): - Optional. Display name of the Dataset in AI - Platform. System will pick a display name if + Optional. Display name of the Dataset in + Vertex AI. System will pick a display name if unspecified. migrate_data_labeling_annotated_dataset_configs (Sequence[google.cloud.aiplatform_v1.types.MigrateResourceRequest.MigrateDataLabelingDatasetConfig.MigrateDataLabelingAnnotatedDatasetConfig]): Optional. Configs for migrating AnnotatedDataset in datalabeling.googleapis.com - to AI Platform's SavedQuery. The specified + to Vertex AI's SavedQuery. The specified AnnotatedDatasets have to belong to the datalabeling Dataset. """ class MigrateDataLabelingAnnotatedDatasetConfig(proto.Message): r"""Config for migrating AnnotatedDataset in - datalabeling.googleapis.com to AI Platform's SavedQuery. + datalabeling.googleapis.com to Vertex AI's SavedQuery. Attributes: annotated_dataset (str): Required. Full resource name of data labeling AnnotatedDataset. Format: - ``projects/{project}/datasets/{dataset}/annotatedDatasets/{annotated_dataset}``. """ - annotated_dataset = proto.Field(proto.STRING, number=1,) + annotated_dataset = proto.Field( + proto.STRING, + number=1, + ) - dataset = proto.Field(proto.STRING, number=1,) - dataset_display_name = proto.Field(proto.STRING, number=2,) + dataset = proto.Field( + proto.STRING, + number=1, + ) + dataset_display_name = proto.Field( + proto.STRING, + number=2, + ) migrate_data_labeling_annotated_dataset_configs = proto.RepeatedField( proto.MESSAGE, number=3, @@ -256,10 +325,16 @@ class MigrateDataLabelingAnnotatedDatasetConfig(proto.Message): message=MigrateMlEngineModelVersionConfig, ) migrate_automl_model_config = proto.Field( - proto.MESSAGE, number=2, oneof="request", message=MigrateAutomlModelConfig, + proto.MESSAGE, + number=2, + oneof="request", + message=MigrateAutomlModelConfig, ) migrate_automl_dataset_config = proto.Field( - proto.MESSAGE, number=3, oneof="request", message=MigrateAutomlDatasetConfig, + proto.MESSAGE, + number=3, + oneof="request", + message=MigrateAutomlDatasetConfig, ) migrate_data_labeling_dataset_config = proto.Field( proto.MESSAGE, @@ -279,27 +354,51 @@ class BatchMigrateResourcesResponse(proto.Message): """ migrate_resource_responses = proto.RepeatedField( - proto.MESSAGE, number=1, message="MigrateResourceResponse", + proto.MESSAGE, + number=1, + message="MigrateResourceResponse", ) class MigrateResourceResponse(proto.Message): r"""Describes a successfully migrated resource. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: dataset (str): Migrated Dataset's resource name. + + This field is a member of `oneof`_ ``migrated_resource``. model (str): Migrated Model's resource name. + + This field is a member of `oneof`_ ``migrated_resource``. migratable_resource (google.cloud.aiplatform_v1.types.MigratableResource): Before migration, the identifier in ml.googleapis.com, automl.googleapis.com or datalabeling.googleapis.com. """ - dataset = proto.Field(proto.STRING, number=1, oneof="migrated_resource",) - model = proto.Field(proto.STRING, number=2, oneof="migrated_resource",) + dataset = proto.Field( + proto.STRING, + number=1, + oneof="migrated_resource", + ) + model = proto.Field( + proto.STRING, + number=2, + oneof="migrated_resource", + ) migratable_resource = proto.Field( - proto.MESSAGE, number=3, message=gca_migratable_resource.MigratableResource, + proto.MESSAGE, + number=3, + message=gca_migratable_resource.MigratableResource, ) @@ -319,33 +418,63 @@ class PartialResult(proto.Message): r"""Represents a partial result in batch migration operation for one [MigrateResourceRequest][google.cloud.aiplatform.v1.MigrateResourceRequest]. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: error (google.rpc.status_pb2.Status): The error result of the migration request in case of failure. + + This field is a member of `oneof`_ ``result``. model (str): Migrated model resource name. + + This field is a member of `oneof`_ ``result``. dataset (str): Migrated dataset resource name. + + This field is a member of `oneof`_ ``result``. request (google.cloud.aiplatform_v1.types.MigrateResourceRequest): It's the same as the value in [MigrateResourceRequest.migrate_resource_requests][]. """ error = proto.Field( - proto.MESSAGE, number=2, oneof="result", message=status_pb2.Status, + proto.MESSAGE, + number=2, + oneof="result", + message=status_pb2.Status, + ) + model = proto.Field( + proto.STRING, + number=3, + oneof="result", + ) + dataset = proto.Field( + proto.STRING, + number=4, + oneof="result", ) - model = proto.Field(proto.STRING, number=3, oneof="result",) - dataset = proto.Field(proto.STRING, number=4, oneof="result",) request = proto.Field( - proto.MESSAGE, number=1, message="MigrateResourceRequest", + proto.MESSAGE, + number=1, + message="MigrateResourceRequest", ) generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, ) partial_results = proto.RepeatedField( - proto.MESSAGE, number=2, message=PartialResult, + proto.MESSAGE, + number=2, + message=PartialResult, ) diff --git a/google/cloud/aiplatform_v1/types/model.py b/google/cloud/aiplatform_v1/types/model.py index 6a6f4043b7..8c3ca651c5 100644 --- a/google/cloud/aiplatform_v1/types/model.py +++ b/google/cloud/aiplatform_v1/types/model.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,45 +18,77 @@ from google.cloud.aiplatform_v1.types import deployed_model_ref from google.cloud.aiplatform_v1.types import encryption_spec as gca_encryption_spec from google.cloud.aiplatform_v1.types import env_var +from google.cloud.aiplatform_v1.types import explanation from google.protobuf import struct_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module( package="google.cloud.aiplatform.v1", - manifest={"Model", "PredictSchemata", "ModelContainerSpec", "Port",}, + manifest={ + "Model", + "PredictSchemata", + "ModelContainerSpec", + "Port", + }, ) class Model(proto.Message): r"""A trained machine learning Model. + Attributes: name (str): The resource name of the Model. + version_id (str): + Output only. Immutable. The version ID of the + model. A new version is committed when a new + model version is uploaded or trained under an + existing model id. It is an auto-incrementing + decimal number in string representation. + version_aliases (Sequence[str]): + User provided version aliases so that a model version can be + referenced via alias (i.e. + projects/{project}/locations/{location}/models/{model_id}@{version_alias} + instead of auto-generated version id (i.e. + projects/{project}/locations/{location}/models/{model_id}@{version_id}). + The format is [a-z][a-zA-Z0-9-]{0,126}[a-z0-9] to + distinguish from version_id. A default version alias will be + created for the first version of the model, and there must + be exactly one default version alias for a model. + version_create_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp when this version was + created. + version_update_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp when this version was + most recently updated. display_name (str): Required. The display name of the Model. The name can be up to 128 characters long and can be consist of any UTF-8 characters. description (str): The description of the Model. + version_description (str): + The description of this version. predict_schemata (google.cloud.aiplatform_v1.types.PredictSchemata): The schemata that describe formats of the Model's predictions and explanations as given and returned via [PredictionService.Predict][google.cloud.aiplatform.v1.PredictionService.Predict] - and [PredictionService.Explain][]. + and + [PredictionService.Explain][google.cloud.aiplatform.v1.PredictionService.Explain]. metadata_schema_uri (str): Immutable. Points to a YAML file stored on Google Cloud Storage describing additional information about the Model, that is specific to it. Unset if the Model does not have any additional information. The schema is defined as an OpenAPI 3.0.2 `Schema - Object `__. - AutoML Models always have this field populated by AI - Platform, if no additional metadata is needed, this field is - set to an empty string. Note: The URI given on output will - be immutable and probably different, including the URI - scheme, than the one given on input. The output URI will - point to a location where the user only has a read access. + Object `__. + AutoML Models always have this field populated by Vertex AI, + if no additional metadata is needed, this field is set to an + empty string. Note: The URI given on output will be + immutable and probably different, including the URI scheme, + than the one given on input. The output URI will point to a + location where the user only has a read access. metadata (google.protobuf.struct_pb2.Value): Immutable. An additional information about the Model; the schema of the metadata can be found in @@ -76,7 +108,7 @@ class Model(proto.Message): ingested upon [ModelService.UploadModel][google.cloud.aiplatform.v1.ModelService.UploadModel], and all binaries it contains are copied and stored - internally by AI Platform. Not present for AutoML Models. + internally by Vertex AI. Not present for AutoML Models. artifact_uri (str): Immutable. The path to the directory containing the Model artifact and any of its @@ -93,8 +125,9 @@ class Model(proto.Message): [Endpoint][google.cloud.aiplatform.v1.Endpoint] and does not support online predictions ([PredictionService.Predict][google.cloud.aiplatform.v1.PredictionService.Predict] - or [PredictionService.Explain][]). Such a Model can serve - predictions by using a + or + [PredictionService.Explain][google.cloud.aiplatform.v1.PredictionService.Explain]). + Such a Model can serve predictions by using a [BatchPredictionJob][google.cloud.aiplatform.v1.BatchPredictionJob], if it has at least one entry each in [supported_input_storage_formats][google.cloud.aiplatform.v1.Model.supported_input_storage_formats] @@ -142,7 +175,8 @@ class Model(proto.Message): [supported_deployment_resources_types][google.cloud.aiplatform.v1.Model.supported_deployment_resources_types], it could serve online predictions by using [PredictionService.Predict][google.cloud.aiplatform.v1.PredictionService.Predict] - or [PredictionService.Explain][]. + or + [PredictionService.Explain][google.cloud.aiplatform.v1.PredictionService.Explain]. supported_output_storage_formats (Sequence[str]): Output only. The formats this Model supports in [BatchPredictionJob.output_config][google.cloud.aiplatform.v1.BatchPredictionJob.output_config]. @@ -178,10 +212,11 @@ class Model(proto.Message): [supported_deployment_resources_types][google.cloud.aiplatform.v1.Model.supported_deployment_resources_types], it could serve online predictions by using [PredictionService.Predict][google.cloud.aiplatform.v1.PredictionService.Predict] - or [PredictionService.Explain][]. + or + [PredictionService.Explain][google.cloud.aiplatform.v1.PredictionService.Explain]. create_time (google.protobuf.timestamp_pb2.Timestamp): Output only. Timestamp when this Model was - uploaded into AI Platform. + uploaded into Vertex AI. update_time (google.protobuf.timestamp_pb2.Timestamp): Output only. Timestamp when this Model was most recently updated. @@ -190,11 +225,42 @@ class Model(proto.Message): created from this Model. Note that Model could have been deployed to Endpoints in different Locations. + explanation_spec (google.cloud.aiplatform_v1.types.ExplanationSpec): + The default explanation specification for this Model. + + The Model can be used for [requesting + explanation][PredictionService.Explain] after being + [deployed][google.cloud.aiplatform.v1.EndpointService.DeployModel] + if it is populated. The Model can be used for [batch + explanation][BatchPredictionJob.generate_explanation] if it + is populated. + + All fields of the explanation_spec can be overridden by + [explanation_spec][google.cloud.aiplatform.v1.DeployedModel.explanation_spec] + of + [DeployModelRequest.deployed_model][google.cloud.aiplatform.v1.DeployModelRequest.deployed_model], + or + [explanation_spec][google.cloud.aiplatform.v1.BatchPredictionJob.explanation_spec] + of + [BatchPredictionJob][google.cloud.aiplatform.v1.BatchPredictionJob]. + + If the default explanation specification is not set for this + Model, this Model can still be used for [requesting + explanation][PredictionService.Explain] by setting + [explanation_spec][google.cloud.aiplatform.v1.DeployedModel.explanation_spec] + of + [DeployModelRequest.deployed_model][google.cloud.aiplatform.v1.DeployModelRequest.deployed_model] + and for [batch + explanation][BatchPredictionJob.generate_explanation] by + setting + [explanation_spec][google.cloud.aiplatform.v1.BatchPredictionJob.explanation_spec] + of + [BatchPredictionJob][google.cloud.aiplatform.v1.BatchPredictionJob]. etag (str): Used to perform consistent read-modify-write updates. If not set, a blind "overwrite" update happens. - labels (Sequence[google.cloud.aiplatform_v1.types.Model.LabelsEntry]): + labels (Mapping[str, str]): The labels with user-defined metadata to organize your Models. Label keys and values can be no longer than 64 @@ -253,41 +319,128 @@ class ExportableContent(proto.Enum): ARTIFACT = 1 IMAGE = 2 - id = proto.Field(proto.STRING, number=1,) + id = proto.Field( + proto.STRING, + number=1, + ) exportable_contents = proto.RepeatedField( - proto.ENUM, number=2, enum="Model.ExportFormat.ExportableContent", + proto.ENUM, + number=2, + enum="Model.ExportFormat.ExportableContent", ) - name = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) - description = proto.Field(proto.STRING, number=3,) - predict_schemata = proto.Field(proto.MESSAGE, number=4, message="PredictSchemata",) - metadata_schema_uri = proto.Field(proto.STRING, number=5,) - metadata = proto.Field(proto.MESSAGE, number=6, message=struct_pb2.Value,) + name = proto.Field( + proto.STRING, + number=1, + ) + version_id = proto.Field( + proto.STRING, + number=28, + ) + version_aliases = proto.RepeatedField( + proto.STRING, + number=29, + ) + version_create_time = proto.Field( + proto.MESSAGE, + number=31, + message=timestamp_pb2.Timestamp, + ) + version_update_time = proto.Field( + proto.MESSAGE, + number=32, + message=timestamp_pb2.Timestamp, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + description = proto.Field( + proto.STRING, + number=3, + ) + version_description = proto.Field( + proto.STRING, + number=30, + ) + predict_schemata = proto.Field( + proto.MESSAGE, + number=4, + message="PredictSchemata", + ) + metadata_schema_uri = proto.Field( + proto.STRING, + number=5, + ) + metadata = proto.Field( + proto.MESSAGE, + number=6, + message=struct_pb2.Value, + ) supported_export_formats = proto.RepeatedField( - proto.MESSAGE, number=20, message=ExportFormat, + proto.MESSAGE, + number=20, + message=ExportFormat, + ) + training_pipeline = proto.Field( + proto.STRING, + number=7, + ) + container_spec = proto.Field( + proto.MESSAGE, + number=9, + message="ModelContainerSpec", + ) + artifact_uri = proto.Field( + proto.STRING, + number=26, ) - training_pipeline = proto.Field(proto.STRING, number=7,) - container_spec = proto.Field(proto.MESSAGE, number=9, message="ModelContainerSpec",) - artifact_uri = proto.Field(proto.STRING, number=26,) supported_deployment_resources_types = proto.RepeatedField( - proto.ENUM, number=10, enum=DeploymentResourcesType, + proto.ENUM, + number=10, + enum=DeploymentResourcesType, + ) + supported_input_storage_formats = proto.RepeatedField( + proto.STRING, + number=11, + ) + supported_output_storage_formats = proto.RepeatedField( + proto.STRING, + number=12, ) - supported_input_storage_formats = proto.RepeatedField(proto.STRING, number=11,) - supported_output_storage_formats = proto.RepeatedField(proto.STRING, number=12,) create_time = proto.Field( - proto.MESSAGE, number=13, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=13, + message=timestamp_pb2.Timestamp, ) update_time = proto.Field( - proto.MESSAGE, number=14, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=14, + message=timestamp_pb2.Timestamp, ) deployed_models = proto.RepeatedField( - proto.MESSAGE, number=15, message=deployed_model_ref.DeployedModelRef, + proto.MESSAGE, + number=15, + message=deployed_model_ref.DeployedModelRef, + ) + explanation_spec = proto.Field( + proto.MESSAGE, + number=23, + message=explanation.ExplanationSpec, + ) + etag = proto.Field( + proto.STRING, + number=16, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=17, ) - etag = proto.Field(proto.STRING, number=16,) - labels = proto.MapField(proto.STRING, proto.STRING, number=17,) encryption_spec = proto.Field( - proto.MESSAGE, number=24, message=gca_encryption_spec.EncryptionSpec, + proto.MESSAGE, + number=24, + message=gca_encryption_spec.EncryptionSpec, ) @@ -295,7 +448,8 @@ class PredictSchemata(proto.Message): r"""Contains the schemata used in Model's predictions and explanations via [PredictionService.Predict][google.cloud.aiplatform.v1.PredictionService.Predict], - [PredictionService.Explain][] and + [PredictionService.Explain][google.cloud.aiplatform.v1.PredictionService.Explain] + and [BatchPredictionJob][google.cloud.aiplatform.v1.BatchPredictionJob]. Attributes: @@ -304,65 +458,78 @@ class PredictSchemata(proto.Message): Storage describing the format of a single instance, which are used in [PredictRequest.instances][google.cloud.aiplatform.v1.PredictRequest.instances], - [ExplainRequest.instances][] and + [ExplainRequest.instances][google.cloud.aiplatform.v1.ExplainRequest.instances] + and [BatchPredictionJob.input_config][google.cloud.aiplatform.v1.BatchPredictionJob.input_config]. The schema is defined as an OpenAPI 3.0.2 `Schema - Object `__. - AutoML Models always have this field populated by AI - Platform. Note: The URI given on output will be immutable - and probably different, including the URI scheme, than the - one given on input. The output URI will point to a location - where the user only has a read access. + Object `__. + AutoML Models always have this field populated by Vertex AI. + Note: The URI given on output will be immutable and probably + different, including the URI scheme, than the one given on + input. The output URI will point to a location where the + user only has a read access. parameters_schema_uri (str): Immutable. Points to a YAML file stored on Google Cloud Storage describing the parameters of prediction and explanation via [PredictRequest.parameters][google.cloud.aiplatform.v1.PredictRequest.parameters], - [ExplainRequest.parameters][] and + [ExplainRequest.parameters][google.cloud.aiplatform.v1.ExplainRequest.parameters] + and [BatchPredictionJob.model_parameters][google.cloud.aiplatform.v1.BatchPredictionJob.model_parameters]. The schema is defined as an OpenAPI 3.0.2 `Schema - Object `__. - AutoML Models always have this field populated by AI - Platform, if no parameters are supported, then it is set to - an empty string. Note: The URI given on output will be - immutable and probably different, including the URI scheme, - than the one given on input. The output URI will point to a - location where the user only has a read access. + Object `__. + AutoML Models always have this field populated by Vertex AI, + if no parameters are supported, then it is set to an empty + string. Note: The URI given on output will be immutable and + probably different, including the URI scheme, than the one + given on input. The output URI will point to a location + where the user only has a read access. prediction_schema_uri (str): Immutable. Points to a YAML file stored on Google Cloud Storage describing the format of a single prediction produced by this Model, which are returned via [PredictResponse.predictions][google.cloud.aiplatform.v1.PredictResponse.predictions], - [ExplainResponse.explanations][], and + [ExplainResponse.explanations][google.cloud.aiplatform.v1.ExplainResponse.explanations], + and [BatchPredictionJob.output_config][google.cloud.aiplatform.v1.BatchPredictionJob.output_config]. The schema is defined as an OpenAPI 3.0.2 `Schema - Object `__. - AutoML Models always have this field populated by AI - Platform. Note: The URI given on output will be immutable - and probably different, including the URI scheme, than the - one given on input. The output URI will point to a location - where the user only has a read access. + Object `__. + AutoML Models always have this field populated by Vertex AI. + Note: The URI given on output will be immutable and probably + different, including the URI scheme, than the one given on + input. The output URI will point to a location where the + user only has a read access. """ - instance_schema_uri = proto.Field(proto.STRING, number=1,) - parameters_schema_uri = proto.Field(proto.STRING, number=2,) - prediction_schema_uri = proto.Field(proto.STRING, number=3,) + instance_schema_uri = proto.Field( + proto.STRING, + number=1, + ) + parameters_schema_uri = proto.Field( + proto.STRING, + number=2, + ) + prediction_schema_uri = proto.Field( + proto.STRING, + number=3, + ) class ModelContainerSpec(proto.Message): - r"""Specification of a container for serving predictions. This message - is a subset of the Kubernetes Container v1 core - `specification `__. + r"""Specification of a container for serving predictions. Some fields in + this message correspond to fields in the `Kubernetes Container v1 + core + specification `__. Attributes: image_uri (str): Required. Immutable. URI of the Docker image to be used as the custom container for serving predictions. This URI must identify an image in Artifact Registry or Container - Registry. Learn more about the container publishing - requirements, including permissions requirements for the AI - Platform Service Agent, - `here `__. + Registry. Learn more about the `container publishing + requirements `__, + including permissions requirements for the Vertex AI Service + Agent. The container image is ingested upon [ModelService.UploadModel][google.cloud.aiplatform.v1.ModelService.UploadModel], @@ -371,7 +538,12 @@ class ModelContainerSpec(proto.Message): To learn about the requirements for the Docker image itself, see `Custom container - requirements `__. + requirements `__. + + You can use the URI to one of Vertex AI's `pre-built + container images for + prediction `__ + in this field. command (Sequence[str]): Immutable. Specifies the command that runs when the container starts. This overrides the container's @@ -387,20 +559,20 @@ class ModelContainerSpec(proto.Message): ```CMD`` `__, if either exists. If this field is not specified and the container does not have an ``ENTRYPOINT``, then refer to the - Docker documentation about how ``CMD`` and ``ENTRYPOINT`` - `interact `__. + Docker documentation about `how ``CMD`` and ``ENTRYPOINT`` + interact `__. If you specify this field, then you can also specify the ``args`` field to provide additional arguments for this command. However, if you specify this field, then the container's ``CMD`` is ignored. See the `Kubernetes - documentation `__ about how - the ``command`` and ``args`` fields interact with a - container's ``ENTRYPOINT`` and ``CMD``. + documentation about how the ``command`` and ``args`` fields + interact with a container's ``ENTRYPOINT`` and + ``CMD`` `__. - In this field, you can reference environment variables `set - by AI - Platform `__ + In this field, you can reference `environment variables set + by Vertex + AI `__ and environment variables set in the [env][google.cloud.aiplatform.v1.ModelContainerSpec.env] field. You cannot reference environment variables set in the @@ -413,7 +585,7 @@ class ModelContainerSpec(proto.Message): this syntax with ``$$``; for example: $$(VARIABLE_NAME) This field corresponds to the ``command`` field of the Kubernetes Containers `v1 core - API `__. + API `__. args (Sequence[str]): Immutable. Specifies arguments for the command that runs when the container starts. This overrides the container's @@ -425,20 +597,21 @@ class ModelContainerSpec(proto.Message): [command][google.cloud.aiplatform.v1.ModelContainerSpec.command] field, then the command from the ``command`` field runs without any additional arguments. See the `Kubernetes - documentation `__ about how - the ``command`` and ``args`` fields interact with a - container's ``ENTRYPOINT`` and ``CMD``. + documentation about how the ``command`` and ``args`` fields + interact with a container's ``ENTRYPOINT`` and + ``CMD`` `__. If you don't specify this field and don't specify the ``command`` field, then the container's ```ENTRYPOINT`` `__ and ``CMD`` determine what runs based on their default - behavior. See the Docker documentation about how ``CMD`` and - ``ENTRYPOINT`` `interact `__. + behavior. See the Docker documentation about `how ``CMD`` + and ``ENTRYPOINT`` + interact `__. - In this field, you can reference environment variables `set - by AI - Platform `__ + In this field, you can reference `environment variables set + by Vertex + AI `__ and environment variables set in the [env][google.cloud.aiplatform.v1.ModelContainerSpec.env] field. You cannot reference environment variables set in the @@ -451,7 +624,7 @@ class ModelContainerSpec(proto.Message): this syntax with ``$$``; for example: $$(VARIABLE_NAME) This field corresponds to the ``args`` field of the Kubernetes Containers `v1 core - API `__. + API `__. env (Sequence[google.cloud.aiplatform_v1.types.EnvVar]): Immutable. List of environment variables to set in the container. After the container starts running, code running @@ -484,14 +657,14 @@ class ModelContainerSpec(proto.Message): This field corresponds to the ``env`` field of the Kubernetes Containers `v1 core - API `__. + API `__. ports (Sequence[google.cloud.aiplatform_v1.types.Port]): - Immutable. List of ports to expose from the container. AI - Platform sends any prediction requests that it receives to - the first port on this list. AI Platform also sends - `liveness and health - checks `__ to - this port. + Immutable. List of ports to expose from the container. + Vertex AI sends any prediction requests that it receives to + the first port on this list. Vertex AI also sends `liveness + and health + checks `__ + to this port. If you do not specify this field, it defaults to following value: @@ -504,20 +677,20 @@ class ModelContainerSpec(proto.Message): } ] - AI Platform does not use ports other than the first one + Vertex AI does not use ports other than the first one listed. This field corresponds to the ``ports`` field of the Kubernetes Containers `v1 core - API `__. + API `__. predict_route (str): Immutable. HTTP path on the container to send prediction - requests to. AI Platform forwards requests sent using + requests to. Vertex AI forwards requests sent using [projects.locations.endpoints.predict][google.cloud.aiplatform.v1.PredictionService.Predict] - to this path on the container's IP address and port. AI - Platform then returns the container's response in the API + to this path on the container's IP address and port. Vertex + AI then returns the container's response in the API response. - For example, if you set this field to ``/foo``, then when AI - Platform receives a prediction request, it forwards the + For example, if you set this field to ``/foo``, then when + Vertex AI receives a prediction request, it forwards the request body in a POST request to the ``/foo`` path on the port of your container specified by the first value of this ``ModelContainerSpec``'s @@ -532,28 +705,28 @@ class ModelContainerSpec(proto.Message): - ENDPOINT: The last segment (following ``endpoints/``)of the Endpoint.name][] field of the Endpoint where this - Model has been deployed. (AI Platform makes this value + Model has been deployed. (Vertex AI makes this value available to your container code as the - ```AIP_ENDPOINT_ID`` `__ - environment variable.) + ```AIP_ENDPOINT_ID`` environment + variable `__.) - DEPLOYED_MODEL: [DeployedModel.id][google.cloud.aiplatform.v1.DeployedModel.id] - of the ``DeployedModel``. (AI Platform makes this value + of the ``DeployedModel``. (Vertex AI makes this value available to your container code as the ```AIP_DEPLOYED_MODEL_ID`` environment - variable `__.) + variable `__.) health_route (str): Immutable. HTTP path on the container to send health checks - to. AI Platform intermittently sends GET requests to this - path on the container's IP address and port to check that - the container is healthy. Read more about `health - checks `__. - - For example, if you set this field to ``/bar``, then AI - Platform intermittently sends a GET request to the ``/bar`` - path on the port of your container specified by the first - value of this ``ModelContainerSpec``'s + to. Vertex AI intermittently sends GET requests to this path + on the container's IP address and port to check that the + container is healthy. Read more about `health + checks `__. + + For example, if you set this field to ``/bar``, then Vertex + AI intermittently sends a GET request to the ``/bar`` path + on the port of your container specified by the first value + of this ``ModelContainerSpec``'s [ports][google.cloud.aiplatform.v1.ModelContainerSpec.ports] field. @@ -565,30 +738,54 @@ class ModelContainerSpec(proto.Message): - ENDPOINT: The last segment (following ``endpoints/``)of the Endpoint.name][] field of the Endpoint where this - Model has been deployed. (AI Platform makes this value + Model has been deployed. (Vertex AI makes this value available to your container code as the - ```AIP_ENDPOINT_ID`` `__ - environment variable.) + ```AIP_ENDPOINT_ID`` environment + variable `__.) - DEPLOYED_MODEL: [DeployedModel.id][google.cloud.aiplatform.v1.DeployedModel.id] - of the ``DeployedModel``. (AI Platform makes this value + of the ``DeployedModel``. (Vertex AI makes this value available to your container code as the - ```AIP_DEPLOYED_MODEL_ID`` `__ - environment variable.) + ```AIP_DEPLOYED_MODEL_ID`` environment + variable `__.) """ - image_uri = proto.Field(proto.STRING, number=1,) - command = proto.RepeatedField(proto.STRING, number=2,) - args = proto.RepeatedField(proto.STRING, number=3,) - env = proto.RepeatedField(proto.MESSAGE, number=4, message=env_var.EnvVar,) - ports = proto.RepeatedField(proto.MESSAGE, number=5, message="Port",) - predict_route = proto.Field(proto.STRING, number=6,) - health_route = proto.Field(proto.STRING, number=7,) + image_uri = proto.Field( + proto.STRING, + number=1, + ) + command = proto.RepeatedField( + proto.STRING, + number=2, + ) + args = proto.RepeatedField( + proto.STRING, + number=3, + ) + env = proto.RepeatedField( + proto.MESSAGE, + number=4, + message=env_var.EnvVar, + ) + ports = proto.RepeatedField( + proto.MESSAGE, + number=5, + message="Port", + ) + predict_route = proto.Field( + proto.STRING, + number=6, + ) + health_route = proto.Field( + proto.STRING, + number=7, + ) class Port(proto.Message): r"""Represents a network port in a container. + Attributes: container_port (int): The number of the port to expose on the pod's @@ -596,7 +793,10 @@ class Port(proto.Message): 1 and 65535 inclusive. """ - container_port = proto.Field(proto.INT32, number=3,) + container_port = proto.Field( + proto.INT32, + number=3, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/model_deployment_monitoring_job.py b/google/cloud/aiplatform_v1/types/model_deployment_monitoring_job.py new file mode 100644 index 0000000000..53f1dbe735 --- /dev/null +++ b/google/cloud/aiplatform_v1/types/model_deployment_monitoring_job.py @@ -0,0 +1,492 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + +from google.cloud.aiplatform_v1.types import encryption_spec as gca_encryption_spec +from google.cloud.aiplatform_v1.types import feature_monitoring_stats +from google.cloud.aiplatform_v1.types import io +from google.cloud.aiplatform_v1.types import job_state +from google.cloud.aiplatform_v1.types import model_monitoring +from google.protobuf import duration_pb2 # type: ignore +from google.protobuf import struct_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from google.rpc import status_pb2 # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "ModelDeploymentMonitoringObjectiveType", + "ModelDeploymentMonitoringJob", + "ModelDeploymentMonitoringBigQueryTable", + "ModelDeploymentMonitoringObjectiveConfig", + "ModelDeploymentMonitoringScheduleConfig", + "ModelMonitoringStatsAnomalies", + }, +) + + +class ModelDeploymentMonitoringObjectiveType(proto.Enum): + r"""The Model Monitoring Objective types.""" + MODEL_DEPLOYMENT_MONITORING_OBJECTIVE_TYPE_UNSPECIFIED = 0 + RAW_FEATURE_SKEW = 1 + RAW_FEATURE_DRIFT = 2 + FEATURE_ATTRIBUTION_SKEW = 3 + FEATURE_ATTRIBUTION_DRIFT = 4 + + +class ModelDeploymentMonitoringJob(proto.Message): + r"""Represents a job that runs periodically to monitor the + deployed models in an endpoint. It will analyze the logged + training & prediction data to detect any abnormal behaviors. + + Attributes: + name (str): + Output only. Resource name of a + ModelDeploymentMonitoringJob. + display_name (str): + Required. The user-defined name of the + ModelDeploymentMonitoringJob. The name can be up + to 128 characters long and can be consist of any + UTF-8 characters. + Display name of a ModelDeploymentMonitoringJob. + endpoint (str): + Required. Endpoint resource name. Format: + ``projects/{project}/locations/{location}/endpoints/{endpoint}`` + state (google.cloud.aiplatform_v1.types.JobState): + Output only. The detailed state of the + monitoring job. When the job is still creating, + the state will be 'PENDING'. Once the job is + successfully created, the state will be + 'RUNNING'. Pause the job, the state will be + 'PAUSED'. + Resume the job, the state will return to + 'RUNNING'. + schedule_state (google.cloud.aiplatform_v1.types.ModelDeploymentMonitoringJob.MonitoringScheduleState): + Output only. Schedule state when the + monitoring job is in Running state. + latest_monitoring_pipeline_metadata (google.cloud.aiplatform_v1.types.ModelDeploymentMonitoringJob.LatestMonitoringPipelineMetadata): + Output only. Latest triggered monitoring + pipeline metadata. + model_deployment_monitoring_objective_configs (Sequence[google.cloud.aiplatform_v1.types.ModelDeploymentMonitoringObjectiveConfig]): + Required. The config for monitoring + objectives. This is a per DeployedModel config. + Each DeployedModel needs to be configured + separately. + model_deployment_monitoring_schedule_config (google.cloud.aiplatform_v1.types.ModelDeploymentMonitoringScheduleConfig): + Required. Schedule config for running the + monitoring job. + logging_sampling_strategy (google.cloud.aiplatform_v1.types.SamplingStrategy): + Required. Sample Strategy for logging. + model_monitoring_alert_config (google.cloud.aiplatform_v1.types.ModelMonitoringAlertConfig): + Alert config for model monitoring. + predict_instance_schema_uri (str): + YAML schema file uri describing the format of + a single instance, which are given to format + this Endpoint's prediction (and explanation). If + not set, we will generate predict schema from + collected predict requests. + sample_predict_instance (google.protobuf.struct_pb2.Value): + Sample Predict instance, same format as + [PredictRequest.instances][google.cloud.aiplatform.v1.PredictRequest.instances], + this can be set as a replacement of + [ModelDeploymentMonitoringJob.predict_instance_schema_uri][google.cloud.aiplatform.v1.ModelDeploymentMonitoringJob.predict_instance_schema_uri]. + If not set, we will generate predict schema from collected + predict requests. + analysis_instance_schema_uri (str): + YAML schema file uri describing the format of a single + instance that you want Tensorflow Data Validation (TFDV) to + analyze. + + If this field is empty, all the feature data types are + inferred from + [predict_instance_schema_uri][google.cloud.aiplatform.v1.ModelDeploymentMonitoringJob.predict_instance_schema_uri], + meaning that TFDV will use the data in the exact format(data + type) as prediction request/response. If there are any data + type differences between predict instance and TFDV instance, + this field can be used to override the schema. For models + trained with Vertex AI, this field must be set as all the + fields in predict instance formatted as string. + bigquery_tables (Sequence[google.cloud.aiplatform_v1.types.ModelDeploymentMonitoringBigQueryTable]): + Output only. The created bigquery tables for + the job under customer project. Customer could + do their own query & analysis. There could be 4 + log tables in maximum: + 1. Training data logging predict + request/response 2. Serving data logging predict + request/response + log_ttl (google.protobuf.duration_pb2.Duration): + The TTL of BigQuery tables in user projects + which stores logs. A day is the basic unit of + the TTL and we take the ceil of TTL/86400(a + day). e.g. { second: 3600} indicates ttl = 1 + day. + labels (Mapping[str, str]): + The labels with user-defined metadata to + organize your ModelDeploymentMonitoringJob. + + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + and examples of labels. + create_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp when this + ModelDeploymentMonitoringJob was created. + update_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp when this + ModelDeploymentMonitoringJob was updated most + recently. + next_schedule_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp when this monitoring + pipeline will be scheduled to run for the next + round. + stats_anomalies_base_directory (google.cloud.aiplatform_v1.types.GcsDestination): + Stats anomalies base folder path. + encryption_spec (google.cloud.aiplatform_v1.types.EncryptionSpec): + Customer-managed encryption key spec for a + ModelDeploymentMonitoringJob. If set, this + ModelDeploymentMonitoringJob and all + sub-resources of this + ModelDeploymentMonitoringJob will be secured by + this key. + enable_monitoring_pipeline_logs (bool): + If true, the scheduled monitoring pipeline logs are sent to + Google Cloud Logging, including pipeline status and + anomalies detected. Please note the logs incur cost, which + are subject to `Cloud Logging + pricing `__. + error (google.rpc.status_pb2.Status): + Output only. Only populated when the job's state is + ``JOB_STATE_FAILED`` or ``JOB_STATE_CANCELLED``. + """ + + class MonitoringScheduleState(proto.Enum): + r"""The state to Specify the monitoring pipeline.""" + MONITORING_SCHEDULE_STATE_UNSPECIFIED = 0 + PENDING = 1 + OFFLINE = 2 + RUNNING = 3 + + class LatestMonitoringPipelineMetadata(proto.Message): + r"""All metadata of most recent monitoring pipelines. + + Attributes: + run_time (google.protobuf.timestamp_pb2.Timestamp): + The time that most recent monitoring + pipelines that is related to this run. + status (google.rpc.status_pb2.Status): + The status of the most recent monitoring + pipeline. + """ + + run_time = proto.Field( + proto.MESSAGE, + number=1, + message=timestamp_pb2.Timestamp, + ) + status = proto.Field( + proto.MESSAGE, + number=2, + message=status_pb2.Status, + ) + + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + endpoint = proto.Field( + proto.STRING, + number=3, + ) + state = proto.Field( + proto.ENUM, + number=4, + enum=job_state.JobState, + ) + schedule_state = proto.Field( + proto.ENUM, + number=5, + enum=MonitoringScheduleState, + ) + latest_monitoring_pipeline_metadata = proto.Field( + proto.MESSAGE, + number=25, + message=LatestMonitoringPipelineMetadata, + ) + model_deployment_monitoring_objective_configs = proto.RepeatedField( + proto.MESSAGE, + number=6, + message="ModelDeploymentMonitoringObjectiveConfig", + ) + model_deployment_monitoring_schedule_config = proto.Field( + proto.MESSAGE, + number=7, + message="ModelDeploymentMonitoringScheduleConfig", + ) + logging_sampling_strategy = proto.Field( + proto.MESSAGE, + number=8, + message=model_monitoring.SamplingStrategy, + ) + model_monitoring_alert_config = proto.Field( + proto.MESSAGE, + number=15, + message=model_monitoring.ModelMonitoringAlertConfig, + ) + predict_instance_schema_uri = proto.Field( + proto.STRING, + number=9, + ) + sample_predict_instance = proto.Field( + proto.MESSAGE, + number=19, + message=struct_pb2.Value, + ) + analysis_instance_schema_uri = proto.Field( + proto.STRING, + number=16, + ) + bigquery_tables = proto.RepeatedField( + proto.MESSAGE, + number=10, + message="ModelDeploymentMonitoringBigQueryTable", + ) + log_ttl = proto.Field( + proto.MESSAGE, + number=17, + message=duration_pb2.Duration, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=11, + ) + create_time = proto.Field( + proto.MESSAGE, + number=12, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=13, + message=timestamp_pb2.Timestamp, + ) + next_schedule_time = proto.Field( + proto.MESSAGE, + number=14, + message=timestamp_pb2.Timestamp, + ) + stats_anomalies_base_directory = proto.Field( + proto.MESSAGE, + number=20, + message=io.GcsDestination, + ) + encryption_spec = proto.Field( + proto.MESSAGE, + number=21, + message=gca_encryption_spec.EncryptionSpec, + ) + enable_monitoring_pipeline_logs = proto.Field( + proto.BOOL, + number=22, + ) + error = proto.Field( + proto.MESSAGE, + number=23, + message=status_pb2.Status, + ) + + +class ModelDeploymentMonitoringBigQueryTable(proto.Message): + r"""ModelDeploymentMonitoringBigQueryTable specifies the BigQuery + table name as well as some information of the logs stored in + this table. + + Attributes: + log_source (google.cloud.aiplatform_v1.types.ModelDeploymentMonitoringBigQueryTable.LogSource): + The source of log. + log_type (google.cloud.aiplatform_v1.types.ModelDeploymentMonitoringBigQueryTable.LogType): + The type of log. + bigquery_table_path (str): + The created BigQuery table to store logs. Customer could do + their own query & analysis. Format: + ``bq://.model_deployment_monitoring_._`` + """ + + class LogSource(proto.Enum): + r"""Indicates where does the log come from.""" + LOG_SOURCE_UNSPECIFIED = 0 + TRAINING = 1 + SERVING = 2 + + class LogType(proto.Enum): + r"""Indicates what type of traffic does the log belong to.""" + LOG_TYPE_UNSPECIFIED = 0 + PREDICT = 1 + EXPLAIN = 2 + + log_source = proto.Field( + proto.ENUM, + number=1, + enum=LogSource, + ) + log_type = proto.Field( + proto.ENUM, + number=2, + enum=LogType, + ) + bigquery_table_path = proto.Field( + proto.STRING, + number=3, + ) + + +class ModelDeploymentMonitoringObjectiveConfig(proto.Message): + r"""ModelDeploymentMonitoringObjectiveConfig contains the pair of + deployed_model_id to ModelMonitoringObjectiveConfig. + + Attributes: + deployed_model_id (str): + The DeployedModel ID of the objective config. + objective_config (google.cloud.aiplatform_v1.types.ModelMonitoringObjectiveConfig): + The objective config of for the + modelmonitoring job of this deployed model. + """ + + deployed_model_id = proto.Field( + proto.STRING, + number=1, + ) + objective_config = proto.Field( + proto.MESSAGE, + number=2, + message=model_monitoring.ModelMonitoringObjectiveConfig, + ) + + +class ModelDeploymentMonitoringScheduleConfig(proto.Message): + r"""The config for scheduling monitoring job. + + Attributes: + monitor_interval (google.protobuf.duration_pb2.Duration): + Required. The model monitoring job scheduling + interval. It will be rounded up to next full + hour. This defines how often the monitoring jobs + are triggered. + monitor_window (google.protobuf.duration_pb2.Duration): + The time window of the prediction data being included in + each prediction dataset. This window specifies how long the + data should be collected from historical model results for + each run. If not set, + [ModelDeploymentMonitoringScheduleConfig.monitor_interval][google.cloud.aiplatform.v1.ModelDeploymentMonitoringScheduleConfig.monitor_interval] + will be used. e.g. If currently the cutoff time is + 2022-01-08 14:30:00 and the monitor_window is set to be + 3600, then data from 2022-01-08 13:30:00 to 2022-01-08 + 14:30:00 will be retrieved and aggregated to calculate the + monitoring statistics. + """ + + monitor_interval = proto.Field( + proto.MESSAGE, + number=1, + message=duration_pb2.Duration, + ) + monitor_window = proto.Field( + proto.MESSAGE, + number=2, + message=duration_pb2.Duration, + ) + + +class ModelMonitoringStatsAnomalies(proto.Message): + r"""Statistics and anomalies generated by Model Monitoring. + + Attributes: + objective (google.cloud.aiplatform_v1.types.ModelDeploymentMonitoringObjectiveType): + Model Monitoring Objective those stats and + anomalies belonging to. + deployed_model_id (str): + Deployed Model ID. + anomaly_count (int): + Number of anomalies within all stats. + feature_stats (Sequence[google.cloud.aiplatform_v1.types.ModelMonitoringStatsAnomalies.FeatureHistoricStatsAnomalies]): + A list of historical Stats and Anomalies + generated for all Features. + """ + + class FeatureHistoricStatsAnomalies(proto.Message): + r"""Historical Stats (and Anomalies) for a specific Feature. + + Attributes: + feature_display_name (str): + Display Name of the Feature. + threshold (google.cloud.aiplatform_v1.types.ThresholdConfig): + Threshold for anomaly detection. + training_stats (google.cloud.aiplatform_v1.types.FeatureStatsAnomaly): + Stats calculated for the Training Dataset. + prediction_stats (Sequence[google.cloud.aiplatform_v1.types.FeatureStatsAnomaly]): + A list of historical stats generated by + different time window's Prediction Dataset. + """ + + feature_display_name = proto.Field( + proto.STRING, + number=1, + ) + threshold = proto.Field( + proto.MESSAGE, + number=3, + message=model_monitoring.ThresholdConfig, + ) + training_stats = proto.Field( + proto.MESSAGE, + number=4, + message=feature_monitoring_stats.FeatureStatsAnomaly, + ) + prediction_stats = proto.RepeatedField( + proto.MESSAGE, + number=5, + message=feature_monitoring_stats.FeatureStatsAnomaly, + ) + + objective = proto.Field( + proto.ENUM, + number=1, + enum="ModelDeploymentMonitoringObjectiveType", + ) + deployed_model_id = proto.Field( + proto.STRING, + number=2, + ) + anomaly_count = proto.Field( + proto.INT32, + number=3, + ) + feature_stats = proto.RepeatedField( + proto.MESSAGE, + number=4, + message=FeatureHistoricStatsAnomalies, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/model_evaluation.py b/google/cloud/aiplatform_v1/types/model_evaluation.py index 51c11de4f2..026d719282 100644 --- a/google/cloud/aiplatform_v1/types/model_evaluation.py +++ b/google/cloud/aiplatform_v1/types/model_evaluation.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,12 +15,16 @@ # import proto # type: ignore +from google.cloud.aiplatform_v1.types import explanation from google.protobuf import struct_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1", manifest={"ModelEvaluation",}, + package="google.cloud.aiplatform.v1", + manifest={ + "ModelEvaluation", + }, ) @@ -33,34 +37,144 @@ class ModelEvaluation(proto.Message): name (str): Output only. The resource name of the ModelEvaluation. + display_name (str): + The display name of the ModelEvaluation. metrics_schema_uri (str): - Output only. Points to a YAML file stored on Google Cloud - Storage describing the + Points to a YAML file stored on Google Cloud Storage + describing the [metrics][google.cloud.aiplatform.v1.ModelEvaluation.metrics] of this ModelEvaluation. The schema is defined as an OpenAPI 3.0.2 `Schema - Object `__. + Object `__. metrics (google.protobuf.struct_pb2.Value): - Output only. Evaluation metrics of the Model. The schema of - the metrics is stored in + Evaluation metrics of the Model. The schema of the metrics + is stored in [metrics_schema_uri][google.cloud.aiplatform.v1.ModelEvaluation.metrics_schema_uri] create_time (google.protobuf.timestamp_pb2.Timestamp): Output only. Timestamp when this ModelEvaluation was created. slice_dimensions (Sequence[str]): - Output only. All possible + All possible [dimensions][ModelEvaluationSlice.slice.dimension] of ModelEvaluationSlices. The dimensions can be used as the filter of the [ModelService.ListModelEvaluationSlices][google.cloud.aiplatform.v1.ModelService.ListModelEvaluationSlices] request, in the form of ``slice.dimension = ``. + data_item_schema_uri (str): + Points to a YAML file stored on Google Cloud Storage + describing [EvaluatedDataItemView.data_item_payload][] and + [EvaluatedAnnotation.data_item_payload][]. The schema is + defined as an OpenAPI 3.0.2 `Schema + Object `__. + + This field is not populated if there are neither + EvaluatedDataItemViews nor EvaluatedAnnotations under this + ModelEvaluation. + annotation_schema_uri (str): + Points to a YAML file stored on Google Cloud Storage + describing [EvaluatedDataItemView.predictions][], + [EvaluatedDataItemView.ground_truths][], + [EvaluatedAnnotation.predictions][], and + [EvaluatedAnnotation.ground_truths][]. The schema is defined + as an OpenAPI 3.0.2 `Schema + Object `__. + + This field is not populated if there are neither + EvaluatedDataItemViews nor EvaluatedAnnotations under this + ModelEvaluation. + model_explanation (google.cloud.aiplatform_v1.types.ModelExplanation): + Aggregated explanation metrics for the + Model's prediction output over the data this + ModelEvaluation uses. This field is populated + only if the Model is evaluated with + explanations, and only for AutoML tabular + Models. + explanation_specs (Sequence[google.cloud.aiplatform_v1.types.ModelEvaluation.ModelEvaluationExplanationSpec]): + Describes the values of + [ExplanationSpec][google.cloud.aiplatform.v1.ExplanationSpec] + that are used for explaining the predicted values on the + evaluated data. + metadata (google.protobuf.struct_pb2.Value): + The metadata of the ModelEvaluation. For the ModelEvaluation + uploaded from Managed Pipeline, metadata contains a + structured value with keys of "pipeline_job_id", + "evaluation_dataset_type", "evaluation_dataset_path". """ - name = proto.Field(proto.STRING, number=1,) - metrics_schema_uri = proto.Field(proto.STRING, number=2,) - metrics = proto.Field(proto.MESSAGE, number=3, message=struct_pb2.Value,) - create_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) - slice_dimensions = proto.RepeatedField(proto.STRING, number=5,) + class ModelEvaluationExplanationSpec(proto.Message): + r""" + + Attributes: + explanation_type (str): + Explanation type. + + For AutoML Image Classification models, possible values are: + + - ``image-integrated-gradients`` + - ``image-xrai`` + explanation_spec (google.cloud.aiplatform_v1.types.ExplanationSpec): + Explanation spec details. + """ + + explanation_type = proto.Field( + proto.STRING, + number=1, + ) + explanation_spec = proto.Field( + proto.MESSAGE, + number=2, + message=explanation.ExplanationSpec, + ) + + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=10, + ) + metrics_schema_uri = proto.Field( + proto.STRING, + number=2, + ) + metrics = proto.Field( + proto.MESSAGE, + number=3, + message=struct_pb2.Value, + ) + create_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + slice_dimensions = proto.RepeatedField( + proto.STRING, + number=5, + ) + data_item_schema_uri = proto.Field( + proto.STRING, + number=6, + ) + annotation_schema_uri = proto.Field( + proto.STRING, + number=7, + ) + model_explanation = proto.Field( + proto.MESSAGE, + number=8, + message=explanation.ModelExplanation, + ) + explanation_specs = proto.RepeatedField( + proto.MESSAGE, + number=9, + message=ModelEvaluationExplanationSpec, + ) + metadata = proto.Field( + proto.MESSAGE, + number=11, + message=struct_pb2.Value, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/model_evaluation_slice.py b/google/cloud/aiplatform_v1/types/model_evaluation_slice.py index 4edf4acac3..3e6a0339b9 100644 --- a/google/cloud/aiplatform_v1/types/model_evaluation_slice.py +++ b/google/cloud/aiplatform_v1/types/model_evaluation_slice.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,7 +20,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1", manifest={"ModelEvaluationSlice",}, + package="google.cloud.aiplatform.v1", + manifest={ + "ModelEvaluationSlice", + }, ) @@ -42,7 +45,7 @@ class ModelEvaluationSlice(proto.Message): [metrics][google.cloud.aiplatform.v1.ModelEvaluationSlice.metrics] of this ModelEvaluationSlice. The schema is defined as an OpenAPI 3.0.2 `Schema - Object `__. + Object `__. metrics (google.protobuf.struct_pb2.Value): Output only. Sliced evaluation metrics of the Model. The schema of the metrics is stored in @@ -54,6 +57,7 @@ class ModelEvaluationSlice(proto.Message): class Slice(proto.Message): r"""Definition of a slice. + Attributes: dimension (str): Output only. The dimension of the slice. Well-known @@ -69,14 +73,38 @@ class Slice(proto.Message): this slice. """ - dimension = proto.Field(proto.STRING, number=1,) - value = proto.Field(proto.STRING, number=2,) + dimension = proto.Field( + proto.STRING, + number=1, + ) + value = proto.Field( + proto.STRING, + number=2, + ) - name = proto.Field(proto.STRING, number=1,) - slice_ = proto.Field(proto.MESSAGE, number=2, message=Slice,) - metrics_schema_uri = proto.Field(proto.STRING, number=3,) - metrics = proto.Field(proto.MESSAGE, number=4, message=struct_pb2.Value,) - create_time = proto.Field(proto.MESSAGE, number=5, message=timestamp_pb2.Timestamp,) + name = proto.Field( + proto.STRING, + number=1, + ) + slice_ = proto.Field( + proto.MESSAGE, + number=2, + message=Slice, + ) + metrics_schema_uri = proto.Field( + proto.STRING, + number=3, + ) + metrics = proto.Field( + proto.MESSAGE, + number=4, + message=struct_pb2.Value, + ) + create_time = proto.Field( + proto.MESSAGE, + number=5, + message=timestamp_pb2.Timestamp, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/model_monitoring.py b/google/cloud/aiplatform_v1/types/model_monitoring.py new file mode 100644 index 0000000000..f861e37162 --- /dev/null +++ b/google/cloud/aiplatform_v1/types/model_monitoring.py @@ -0,0 +1,421 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + +from google.cloud.aiplatform_v1.types import io + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "ModelMonitoringObjectiveConfig", + "ModelMonitoringAlertConfig", + "ThresholdConfig", + "SamplingStrategy", + }, +) + + +class ModelMonitoringObjectiveConfig(proto.Message): + r"""Next ID: 8 + + Attributes: + training_dataset (google.cloud.aiplatform_v1.types.ModelMonitoringObjectiveConfig.TrainingDataset): + Training dataset for models. This field has + to be set only if + TrainingPredictionSkewDetectionConfig is + specified. + training_prediction_skew_detection_config (google.cloud.aiplatform_v1.types.ModelMonitoringObjectiveConfig.TrainingPredictionSkewDetectionConfig): + The config for skew between training data and + prediction data. + prediction_drift_detection_config (google.cloud.aiplatform_v1.types.ModelMonitoringObjectiveConfig.PredictionDriftDetectionConfig): + The config for drift of prediction data. + explanation_config (google.cloud.aiplatform_v1.types.ModelMonitoringObjectiveConfig.ExplanationConfig): + The config for integrating with Vertex + Explainable AI. + """ + + class TrainingDataset(proto.Message): + r"""Training Dataset information. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + dataset (str): + The resource name of the Dataset used to + train this Model. + + This field is a member of `oneof`_ ``data_source``. + gcs_source (google.cloud.aiplatform_v1.types.GcsSource): + The Google Cloud Storage uri of the unmanaged + Dataset used to train this Model. + + This field is a member of `oneof`_ ``data_source``. + bigquery_source (google.cloud.aiplatform_v1.types.BigQuerySource): + The BigQuery table of the unmanaged Dataset + used to train this Model. + + This field is a member of `oneof`_ ``data_source``. + data_format (str): + Data format of the dataset, only applicable + if the input is from Google Cloud Storage. + The possible formats are: + + "tf-record" + The source file is a TFRecord file. + + "csv" + The source file is a CSV file. + "jsonl" + The source file is a JSONL file. + target_field (str): + The target field name the model is to + predict. This field will be excluded when doing + Predict and (or) Explain for the training data. + logging_sampling_strategy (google.cloud.aiplatform_v1.types.SamplingStrategy): + Strategy to sample data from Training + Dataset. If not set, we process the whole + dataset. + """ + + dataset = proto.Field( + proto.STRING, + number=3, + oneof="data_source", + ) + gcs_source = proto.Field( + proto.MESSAGE, + number=4, + oneof="data_source", + message=io.GcsSource, + ) + bigquery_source = proto.Field( + proto.MESSAGE, + number=5, + oneof="data_source", + message=io.BigQuerySource, + ) + data_format = proto.Field( + proto.STRING, + number=2, + ) + target_field = proto.Field( + proto.STRING, + number=6, + ) + logging_sampling_strategy = proto.Field( + proto.MESSAGE, + number=7, + message="SamplingStrategy", + ) + + class TrainingPredictionSkewDetectionConfig(proto.Message): + r"""The config for Training & Prediction data skew detection. It + specifies the training dataset sources and the skew detection + parameters. + + Attributes: + skew_thresholds (Mapping[str, google.cloud.aiplatform_v1.types.ThresholdConfig]): + Key is the feature name and value is the + threshold. If a feature needs to be monitored + for skew, a value threshold must be configured + for that feature. The threshold here is against + feature distribution distance between the + training and prediction feature. + attribution_score_skew_thresholds (Mapping[str, google.cloud.aiplatform_v1.types.ThresholdConfig]): + Key is the feature name and value is the + threshold. The threshold here is against + attribution score distance between the training + and prediction feature. + default_skew_threshold (google.cloud.aiplatform_v1.types.ThresholdConfig): + Skew anomaly detection threshold used by all + features. When the per-feature thresholds are + not set, this field can be used to specify a + threshold for all features. + """ + + skew_thresholds = proto.MapField( + proto.STRING, + proto.MESSAGE, + number=1, + message="ThresholdConfig", + ) + attribution_score_skew_thresholds = proto.MapField( + proto.STRING, + proto.MESSAGE, + number=2, + message="ThresholdConfig", + ) + default_skew_threshold = proto.Field( + proto.MESSAGE, + number=6, + message="ThresholdConfig", + ) + + class PredictionDriftDetectionConfig(proto.Message): + r"""The config for Prediction data drift detection. + + Attributes: + drift_thresholds (Mapping[str, google.cloud.aiplatform_v1.types.ThresholdConfig]): + Key is the feature name and value is the + threshold. If a feature needs to be monitored + for drift, a value threshold must be configured + for that feature. The threshold here is against + feature distribution distance between different + time windws. + attribution_score_drift_thresholds (Mapping[str, google.cloud.aiplatform_v1.types.ThresholdConfig]): + Key is the feature name and value is the + threshold. The threshold here is against + attribution score distance between different + time windows. + default_drift_threshold (google.cloud.aiplatform_v1.types.ThresholdConfig): + Drift anomaly detection threshold used by all + features. When the per-feature thresholds are + not set, this field can be used to specify a + threshold for all features. + """ + + drift_thresholds = proto.MapField( + proto.STRING, + proto.MESSAGE, + number=1, + message="ThresholdConfig", + ) + attribution_score_drift_thresholds = proto.MapField( + proto.STRING, + proto.MESSAGE, + number=2, + message="ThresholdConfig", + ) + default_drift_threshold = proto.Field( + proto.MESSAGE, + number=5, + message="ThresholdConfig", + ) + + class ExplanationConfig(proto.Message): + r"""The config for integrating with Vertex Explainable AI. Only + applicable if the Model has explanation_spec populated. + + Attributes: + enable_feature_attributes (bool): + If want to analyze the Vertex Explainable AI + feature attribute scores or not. If set to true, + Vertex AI will log the feature attributions from + explain response and do the skew/drift detection + for them. + explanation_baseline (google.cloud.aiplatform_v1.types.ModelMonitoringObjectiveConfig.ExplanationConfig.ExplanationBaseline): + Predictions generated by the + BatchPredictionJob using baseline dataset. + """ + + class ExplanationBaseline(proto.Message): + r"""Output from + [BatchPredictionJob][google.cloud.aiplatform.v1.BatchPredictionJob] + for Model Monitoring baseline dataset, which can be used to generate + baseline attribution scores. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + gcs (google.cloud.aiplatform_v1.types.GcsDestination): + Cloud Storage location for BatchExplain + output. + + This field is a member of `oneof`_ ``destination``. + bigquery (google.cloud.aiplatform_v1.types.BigQueryDestination): + BigQuery location for BatchExplain output. + + This field is a member of `oneof`_ ``destination``. + prediction_format (google.cloud.aiplatform_v1.types.ModelMonitoringObjectiveConfig.ExplanationConfig.ExplanationBaseline.PredictionFormat): + The storage format of the predictions + generated BatchPrediction job. + """ + + class PredictionFormat(proto.Enum): + r"""The storage format of the predictions generated + BatchPrediction job. + """ + PREDICTION_FORMAT_UNSPECIFIED = 0 + JSONL = 2 + BIGQUERY = 3 + + gcs = proto.Field( + proto.MESSAGE, + number=2, + oneof="destination", + message=io.GcsDestination, + ) + bigquery = proto.Field( + proto.MESSAGE, + number=3, + oneof="destination", + message=io.BigQueryDestination, + ) + prediction_format = proto.Field( + proto.ENUM, + number=1, + enum="ModelMonitoringObjectiveConfig.ExplanationConfig.ExplanationBaseline.PredictionFormat", + ) + + enable_feature_attributes = proto.Field( + proto.BOOL, + number=1, + ) + explanation_baseline = proto.Field( + proto.MESSAGE, + number=2, + message="ModelMonitoringObjectiveConfig.ExplanationConfig.ExplanationBaseline", + ) + + training_dataset = proto.Field( + proto.MESSAGE, + number=1, + message=TrainingDataset, + ) + training_prediction_skew_detection_config = proto.Field( + proto.MESSAGE, + number=2, + message=TrainingPredictionSkewDetectionConfig, + ) + prediction_drift_detection_config = proto.Field( + proto.MESSAGE, + number=3, + message=PredictionDriftDetectionConfig, + ) + explanation_config = proto.Field( + proto.MESSAGE, + number=5, + message=ExplanationConfig, + ) + + +class ModelMonitoringAlertConfig(proto.Message): + r"""Next ID: 3 + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + email_alert_config (google.cloud.aiplatform_v1.types.ModelMonitoringAlertConfig.EmailAlertConfig): + Email alert config. + + This field is a member of `oneof`_ ``alert``. + enable_logging (bool): + Dump the anomalies to Cloud Logging. The anomalies will be + put to json payload encoded from proto + [google.cloud.aiplatform.logging.ModelMonitoringAnomaliesLogEntry][]. + This can be further sinked to Pub/Sub or any other services + supported by Cloud Logging. + """ + + class EmailAlertConfig(proto.Message): + r"""The config for email alert. + + Attributes: + user_emails (Sequence[str]): + The email addresses to send the alert. + """ + + user_emails = proto.RepeatedField( + proto.STRING, + number=1, + ) + + email_alert_config = proto.Field( + proto.MESSAGE, + number=1, + oneof="alert", + message=EmailAlertConfig, + ) + enable_logging = proto.Field( + proto.BOOL, + number=2, + ) + + +class ThresholdConfig(proto.Message): + r"""The config for feature monitoring threshold. + Next ID: 3 + + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + value (float): + Specify a threshold value that can trigger + the alert. If this threshold config is for + feature distribution distance: 1. For + categorical feature, the distribution distance + is calculated by L-inifinity norm. + 2. For numerical feature, the distribution + distance is calculated by Jensen–Shannon + divergence. + Each feature must have a non-zero threshold if + they need to be monitored. Otherwise no alert + will be triggered for that feature. + + This field is a member of `oneof`_ ``threshold``. + """ + + value = proto.Field( + proto.DOUBLE, + number=1, + oneof="threshold", + ) + + +class SamplingStrategy(proto.Message): + r"""Sampling Strategy for logging, can be for both training and + prediction dataset. + Next ID: 2 + + Attributes: + random_sample_config (google.cloud.aiplatform_v1.types.SamplingStrategy.RandomSampleConfig): + Random sample config. Will support more + sampling strategies later. + """ + + class RandomSampleConfig(proto.Message): + r"""Requests are randomly selected. + + Attributes: + sample_rate (float): + Sample rate (0, 1] + """ + + sample_rate = proto.Field( + proto.DOUBLE, + number=1, + ) + + random_sample_config = proto.Field( + proto.MESSAGE, + number=1, + message=RandomSampleConfig, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/model_service.py b/google/cloud/aiplatform_v1/types/model_service.py index aca2817dbe..27c6d2b1d2 100644 --- a/google/cloud/aiplatform_v1/types/model_service.py +++ b/google/cloud/aiplatform_v1/types/model_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ from google.cloud.aiplatform_v1.types import io from google.cloud.aiplatform_v1.types import model as gca_model -from google.cloud.aiplatform_v1.types import model_evaluation +from google.cloud.aiplatform_v1.types import model_evaluation as gca_model_evaluation from google.cloud.aiplatform_v1.types import model_evaluation_slice from google.cloud.aiplatform_v1.types import operation from google.protobuf import field_mask_pb2 # type: ignore @@ -32,11 +32,16 @@ "GetModelRequest", "ListModelsRequest", "ListModelsResponse", + "ListModelVersionsRequest", + "ListModelVersionsResponse", "UpdateModelRequest", "DeleteModelRequest", + "DeleteModelVersionRequest", + "MergeVersionAliasesRequest", "ExportModelRequest", "ExportModelOperationMetadata", "ExportModelResponse", + "ImportModelEvaluationRequest", "GetModelEvaluationRequest", "ListModelEvaluationsRequest", "ListModelEvaluationsResponse", @@ -56,12 +61,38 @@ class UploadModelRequest(proto.Message): Required. The resource name of the Location into which to upload the Model. Format: ``projects/{project}/locations/{location}`` + parent_model (str): + Optional. The resource name of the model into + which to upload the version. Only specify this + field when uploading a new version. + model_id (str): + Optional. The ID to use for the uploaded Model, which will + become the final component of the model resource name. + + This value may be up to 63 characters, and valid characters + are ``[a-z0-9_-]``. The first character cannot be a number + or hyphen. model (google.cloud.aiplatform_v1.types.Model): Required. The Model to create. """ - parent = proto.Field(proto.STRING, number=1,) - model = proto.Field(proto.MESSAGE, number=2, message=gca_model.Model,) + parent = proto.Field( + proto.STRING, + number=1, + ) + parent_model = proto.Field( + proto.STRING, + number=4, + ) + model_id = proto.Field( + proto.STRING, + number=5, + ) + model = proto.Field( + proto.MESSAGE, + number=2, + message=gca_model.Model, + ) class UploadModelOperationMetadata(proto.Message): @@ -75,7 +106,9 @@ class UploadModelOperationMetadata(proto.Message): """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, ) @@ -88,9 +121,19 @@ class UploadModelResponse(proto.Message): model (str): The name of the uploaded Model resource. Format: ``projects/{project}/locations/{location}/models/{model}`` + model_version_id (str): + Output only. The version ID of the model that + is uploaded. """ - model = proto.Field(proto.STRING, number=1,) + model = proto.Field( + proto.STRING, + number=1, + ) + model_version_id = proto.Field( + proto.STRING, + number=2, + ) class GetModelRequest(proto.Message): @@ -101,9 +144,23 @@ class GetModelRequest(proto.Message): name (str): Required. The name of the Model resource. Format: ``projects/{project}/locations/{location}/models/{model}`` + + In order to retrieve a specific version of the model, also + provide the version ID or version alias. Example: + ``projects/{project}/locations/{location}/models/{model}@2`` + or + ``projects/{project}/locations/{location}/models/{model}@golden`` + If no version ID or alias is specified, the "default" + version will be returned. The "default" version alias is + created for the first version of the model, and can be moved + to other versions later on. There will be exactly one + default version. """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListModelsRequest(proto.Message): @@ -157,12 +214,31 @@ class ListModelsRequest(proto.Message): Example: ``display_name, create_time desc``. """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) - read_mask = proto.Field(proto.MESSAGE, number=5, message=field_mask_pb2.FieldMask,) - order_by = proto.Field(proto.STRING, number=6,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=5, + message=field_mask_pb2.FieldMask, + ) + order_by = proto.Field( + proto.STRING, + number=6, + ) class ListModelsResponse(proto.Message): @@ -182,8 +258,100 @@ class ListModelsResponse(proto.Message): def raw_page(self): return self - models = proto.RepeatedField(proto.MESSAGE, number=1, message=gca_model.Model,) - next_page_token = proto.Field(proto.STRING, number=2,) + models = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gca_model.Model, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) + + +class ListModelVersionsRequest(proto.Message): + r"""Request message for + [ModelService.ListModelVersions][google.cloud.aiplatform.v1.ModelService.ListModelVersions]. + + Attributes: + name (str): + Required. The name of the model to list + versions for. + page_size (int): + The standard list page size. + page_token (str): + The standard list page token. Typically obtained via + [ListModelVersionsResponse.next_page_token][google.cloud.aiplatform.v1.ListModelVersionsResponse.next_page_token] + of the previous [ModelService.ListModelversions][] call. + filter (str): + An expression for filtering the results of the request. For + field names both snake_case and camelCase are supported. + + - ``labels`` supports general map functions that is: + + - ``labels.key=value`` - key:value equality + - \`labels.key:\* or labels:key - key existence + - A key including a space must be quoted. + ``labels."a key"``. + + Some examples: + + - ``labels.myKey="myValue"`` + read_mask (google.protobuf.field_mask_pb2.FieldMask): + Mask specifying which fields to read. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + page_size = proto.Field( + proto.INT32, + number=2, + ) + page_token = proto.Field( + proto.STRING, + number=3, + ) + filter = proto.Field( + proto.STRING, + number=4, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=5, + message=field_mask_pb2.FieldMask, + ) + + +class ListModelVersionsResponse(proto.Message): + r"""Response message for + [ModelService.ListModelVersions][google.cloud.aiplatform.v1.ModelService.ListModelVersions] + + Attributes: + models (Sequence[google.cloud.aiplatform_v1.types.Model]): + List of Model versions in the requested page. + In the returned Model name field, version ID + instead of regvision tag will be included. + next_page_token (str): + A token to retrieve the next page of results. Pass to + [ListModelVersionsRequest.page_token][google.cloud.aiplatform.v1.ListModelVersionsRequest.page_token] + to obtain that page. + """ + + @property + def raw_page(self): + return self + + models = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gca_model.Model, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) class UpdateModelRequest(proto.Message): @@ -192,17 +360,43 @@ class UpdateModelRequest(proto.Message): Attributes: model (google.cloud.aiplatform_v1.types.Model): - Required. The Model which replaces the - resource on the server. + Required. The Model which replaces the resource on the + server. When Model Versioning is enabled, the model.name + will be used to determine whether to update the model or + model version. + + 1. model.name with the @ value, e.g. models/123@1, refers to + a version specific update. + 2. model.name without the @ value, e.g. models/123, refers + to a model update. + 3. model.name with @-, e.g. models/123@-, refers to a model + update. + 4. Supported model fields: display_name, description; + supported version-specific fields: version_description. + Labels are supported in both scenarios. Both the model + labels and the version labels are merged when a model is + returned. When updating labels, if the request is for + model-specific update, model label gets updated. + Otherwise, version labels get updated. + 5. A model name or model version name fields update mismatch + will cause a precondition error. + 6. One request cannot update both the model and the version + fields. You must update them separately. update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. The update mask applies to the resource. For the ``FieldMask`` definition, see - `FieldMask `__. + [google.protobuf.FieldMask][google.protobuf.FieldMask]. """ - model = proto.Field(proto.MESSAGE, number=1, message=gca_model.Model,) + model = proto.Field( + proto.MESSAGE, + number=1, + message=gca_model.Model, + ) update_mask = proto.Field( - proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, ) @@ -217,7 +411,66 @@ class DeleteModelRequest(proto.Message): ``projects/{project}/locations/{location}/models/{model}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) + + +class DeleteModelVersionRequest(proto.Message): + r"""Request message for + [ModelService.DeleteModelVersion][google.cloud.aiplatform.v1.ModelService.DeleteModelVersion]. + + Attributes: + name (str): + Required. The name of the model version to be deleted, with + a version ID explicitly included. + + Example: + ``projects/{project}/locations/{location}/models/{model}@1234`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class MergeVersionAliasesRequest(proto.Message): + r"""Request message for + [ModelService.MergeVersionAliases][google.cloud.aiplatform.v1.ModelService.MergeVersionAliases]. + + Attributes: + name (str): + Required. The name of the model version to merge aliases, + with a version ID explicitly included. + + Example: + ``projects/{project}/locations/{location}/models/{model}@1234`` + version_aliases (Sequence[str]): + Required. The set of version aliases to merge. The alias + should be at most 128 characters, and match + ``[a-z][a-z0-9-]{0,126}[a-z-0-9]``. Add the ``-`` prefix to + an alias means removing that alias from the version. ``-`` + is NOT counted in the 128 characters. Example: ``-golden`` + means removing the ``golden`` alias from the version. + + There is NO ordering in aliases, which means + + 1) The aliases returned from GetModel API might not have the + exactly same order from this MergeVersionAliases API. 2) + Adding and deleting the same alias in the request is not + recommended, and the 2 operations will be cancelled out. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + version_aliases = proto.RepeatedField( + proto.STRING, + number=2, + ) class ExportModelRequest(proto.Message): @@ -226,8 +479,11 @@ class ExportModelRequest(proto.Message): Attributes: name (str): - Required. The resource name of the Model to export. Format: - ``projects/{project}/locations/{location}/models/{model}`` + Required. The resource name of the Model to + export. The resource name may contain version id + or version alias to specify the version, if no + version is specified, the default version will + be exported. output_config (google.cloud.aiplatform_v1.types.ExportModelRequest.OutputConfig): Required. The desired output location and configuration. @@ -235,6 +491,7 @@ class ExportModelRequest(proto.Message): class OutputConfig(proto.Message): r"""Output configuration for the Model export. + Attributes: export_format_id (str): The ID of the format in which the Model must be exported. @@ -261,16 +518,30 @@ class OutputConfig(proto.Message): ``IMAGE``. """ - export_format_id = proto.Field(proto.STRING, number=1,) + export_format_id = proto.Field( + proto.STRING, + number=1, + ) artifact_destination = proto.Field( - proto.MESSAGE, number=3, message=io.GcsDestination, + proto.MESSAGE, + number=3, + message=io.GcsDestination, ) image_destination = proto.Field( - proto.MESSAGE, number=4, message=io.ContainerRegistryDestination, + proto.MESSAGE, + number=4, + message=io.ContainerRegistryDestination, ) - name = proto.Field(proto.STRING, number=1,) - output_config = proto.Field(proto.MESSAGE, number=2, message=OutputConfig,) + name = proto.Field( + proto.STRING, + number=1, + ) + output_config = proto.Field( + proto.MESSAGE, + number=2, + message=OutputConfig, + ) class ExportModelOperationMetadata(proto.Message): @@ -303,20 +574,57 @@ class OutputInfo(proto.Message): image created. """ - artifact_output_uri = proto.Field(proto.STRING, number=2,) - image_output_uri = proto.Field(proto.STRING, number=3,) + artifact_output_uri = proto.Field( + proto.STRING, + number=2, + ) + image_output_uri = proto.Field( + proto.STRING, + number=3, + ) generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, + ) + output_info = proto.Field( + proto.MESSAGE, + number=2, + message=OutputInfo, ) - output_info = proto.Field(proto.MESSAGE, number=2, message=OutputInfo,) class ExportModelResponse(proto.Message): r"""Response message of [ModelService.ExportModel][google.cloud.aiplatform.v1.ModelService.ExportModel] operation. - """ + + """ + + +class ImportModelEvaluationRequest(proto.Message): + r"""Request message for + [ModelService.ImportModelEvaluation][google.cloud.aiplatform.v1.ModelService.ImportModelEvaluation] + + Attributes: + parent (str): + Required. The name of the parent model resource. Format: + ``projects/{project}/locations/{location}/models/{model}`` + model_evaluation (google.cloud.aiplatform_v1.types.ModelEvaluation): + Required. Model evaluation resource to be + imported. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + model_evaluation = proto.Field( + proto.MESSAGE, + number=2, + message=gca_model_evaluation.ModelEvaluation, + ) class GetModelEvaluationRequest(proto.Message): @@ -326,11 +634,13 @@ class GetModelEvaluationRequest(proto.Message): Attributes: name (str): Required. The name of the ModelEvaluation resource. Format: - ``projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListModelEvaluationsRequest(proto.Message): @@ -356,11 +666,27 @@ class ListModelEvaluationsRequest(proto.Message): Mask specifying which fields to read. """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) - read_mask = proto.Field(proto.MESSAGE, number=5, message=field_mask_pb2.FieldMask,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=5, + message=field_mask_pb2.FieldMask, + ) class ListModelEvaluationsResponse(proto.Message): @@ -382,9 +708,14 @@ def raw_page(self): return self model_evaluations = proto.RepeatedField( - proto.MESSAGE, number=1, message=model_evaluation.ModelEvaluation, + proto.MESSAGE, + number=1, + message=gca_model_evaluation.ModelEvaluation, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class GetModelEvaluationSliceRequest(proto.Message): @@ -395,11 +726,13 @@ class GetModelEvaluationSliceRequest(proto.Message): name (str): Required. The name of the ModelEvaluationSlice resource. Format: - ``projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}/slices/{slice}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListModelEvaluationSlicesRequest(proto.Message): @@ -410,7 +743,6 @@ class ListModelEvaluationSlicesRequest(proto.Message): parent (str): Required. The resource name of the ModelEvaluation to list the ModelEvaluationSlices from. Format: - ``projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}`` filter (str): The standard list filter. @@ -428,11 +760,27 @@ class ListModelEvaluationSlicesRequest(proto.Message): Mask specifying which fields to read. """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) - read_mask = proto.Field(proto.MESSAGE, number=5, message=field_mask_pb2.FieldMask,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=5, + message=field_mask_pb2.FieldMask, + ) class ListModelEvaluationSlicesResponse(proto.Message): @@ -454,9 +802,14 @@ def raw_page(self): return self model_evaluation_slices = proto.RepeatedField( - proto.MESSAGE, number=1, message=model_evaluation_slice.ModelEvaluationSlice, + proto.MESSAGE, + number=1, + message=model_evaluation_slice.ModelEvaluationSlice, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/operation.py b/google/cloud/aiplatform_v1/types/operation.py index 4c28709808..c6841e6db9 100644 --- a/google/cloud/aiplatform_v1/types/operation.py +++ b/google/cloud/aiplatform_v1/types/operation.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,12 +21,16 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1", - manifest={"GenericOperationMetadata", "DeleteOperationMetadata",}, + manifest={ + "GenericOperationMetadata", + "DeleteOperationMetadata", + }, ) class GenericOperationMetadata(proto.Message): r"""Generic Metadata shared by all operations. + Attributes: partial_failures (Sequence[google.rpc.status_pb2.Status]): Output only. Partial failures encountered. @@ -45,21 +49,34 @@ class GenericOperationMetadata(proto.Message): """ partial_failures = proto.RepeatedField( - proto.MESSAGE, number=1, message=status_pb2.Status, + proto.MESSAGE, + number=1, + message=status_pb2.Status, + ) + create_time = proto.Field( + proto.MESSAGE, + number=2, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, ) - create_time = proto.Field(proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp,) - update_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) class DeleteOperationMetadata(proto.Message): r"""Details of operations that perform deletes of any entities. + Attributes: generic_metadata (google.cloud.aiplatform_v1.types.GenericOperationMetadata): The common part of the operation metadata. """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message="GenericOperationMetadata", + proto.MESSAGE, + number=1, + message="GenericOperationMetadata", ) diff --git a/google/cloud/aiplatform_v1/types/pipeline_failure_policy.py b/google/cloud/aiplatform_v1/types/pipeline_failure_policy.py new file mode 100644 index 0000000000..4daa1d41f6 --- /dev/null +++ b/google/cloud/aiplatform_v1/types/pipeline_failure_policy.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "PipelineFailurePolicy", + }, +) + + +class PipelineFailurePolicy(proto.Enum): + r"""Reperesents the failure policy of a pipeline. Currently, the default + of a pipeline is that the pipeline will continue to run until no + more tasks can be executed, also known as + PIPELINE_FAILURE_POLICY_FAIL_SLOW. However, if a pipeline is set to + PIPELINE_FAILURE_POLICY_FAIL_FAST, it will stop scheduling any new + tasks when a task has failed. Any scheduled tasks will continue to + completion. + """ + PIPELINE_FAILURE_POLICY_UNSPECIFIED = 0 + PIPELINE_FAILURE_POLICY_FAIL_SLOW = 1 + PIPELINE_FAILURE_POLICY_FAIL_FAST = 2 + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/pipeline_job.py b/google/cloud/aiplatform_v1/types/pipeline_job.py new file mode 100644 index 0000000000..3e2152b65e --- /dev/null +++ b/google/cloud/aiplatform_v1/types/pipeline_job.py @@ -0,0 +1,575 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + +from google.cloud.aiplatform_v1.types import artifact +from google.cloud.aiplatform_v1.types import context +from google.cloud.aiplatform_v1.types import encryption_spec as gca_encryption_spec +from google.cloud.aiplatform_v1.types import execution as gca_execution +from google.cloud.aiplatform_v1.types import pipeline_failure_policy +from google.cloud.aiplatform_v1.types import pipeline_state +from google.cloud.aiplatform_v1.types import value as gca_value +from google.protobuf import struct_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +from google.rpc import status_pb2 # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "PipelineJob", + "PipelineTemplateMetadata", + "PipelineJobDetail", + "PipelineTaskDetail", + "PipelineTaskExecutorDetail", + }, +) + + +class PipelineJob(proto.Message): + r"""An instance of a machine learning PipelineJob. + + Attributes: + name (str): + Output only. The resource name of the + PipelineJob. + display_name (str): + The display name of the Pipeline. + The name can be up to 128 characters long and + can be consist of any UTF-8 characters. + create_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Pipeline creation time. + start_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Pipeline start time. + end_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Pipeline end time. + update_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp when this PipelineJob + was most recently updated. + pipeline_spec (google.protobuf.struct_pb2.Struct): + The spec of the pipeline. + state (google.cloud.aiplatform_v1.types.PipelineState): + Output only. The detailed state of the job. + job_detail (google.cloud.aiplatform_v1.types.PipelineJobDetail): + Output only. The details of pipeline run. Not + available in the list view. + error (google.rpc.status_pb2.Status): + Output only. The error that occurred during + pipeline execution. Only populated when the + pipeline's state is FAILED or CANCELLED. + labels (Mapping[str, str]): + The labels with user-defined metadata to + organize PipelineJob. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. + See https://goo.gl/xmQnxf for more information + and examples of labels. + runtime_config (google.cloud.aiplatform_v1.types.PipelineJob.RuntimeConfig): + Runtime config of the pipeline. + encryption_spec (google.cloud.aiplatform_v1.types.EncryptionSpec): + Customer-managed encryption key spec for a + pipelineJob. If set, this PipelineJob and all of + its sub-resources will be secured by this key. + service_account (str): + The service account that the pipeline workload runs as. If + not specified, the Compute Engine default service account in + the project will be used. See + https://cloud.google.com/compute/docs/access/service-accounts#default_service_account + + Users starting the pipeline must have the + ``iam.serviceAccounts.actAs`` permission on this service + account. + network (str): + The full name of the Compute Engine + `network `__ + to which the Pipeline Job's workload should be peered. For + example, ``projects/12345/global/networks/myVPC``. + `Format `__ + is of the form + ``projects/{project}/global/networks/{network}``. Where + {project} is a project number, as in ``12345``, and + {network} is a network name. + + Private services access must already be configured for the + network. Pipeline job will apply the network configuration + to the GCP resources being launched, if applied, such as + Vertex AI Training or Dataflow job. If left unspecified, the + workload is not peered with any network. + template_uri (str): + A template uri from where the + [PipelineJob.pipeline_spec][google.cloud.aiplatform.v1.PipelineJob.pipeline_spec], + if empty, will be downloaded. + template_metadata (google.cloud.aiplatform_v1.types.PipelineTemplateMetadata): + Output only. Pipeline template metadata. Will fill up fields + if + [PipelineJob.template_uri][google.cloud.aiplatform.v1.PipelineJob.template_uri] + is from supported template registry. + """ + + class RuntimeConfig(proto.Message): + r"""The runtime config of a PipelineJob. + + Attributes: + parameters (Mapping[str, google.cloud.aiplatform_v1.types.Value]): + Deprecated. Use + [RuntimeConfig.parameter_values][google.cloud.aiplatform.v1.PipelineJob.RuntimeConfig.parameter_values] + instead. The runtime parameters of the PipelineJob. The + parameters will be passed into + [PipelineJob.pipeline_spec][google.cloud.aiplatform.v1.PipelineJob.pipeline_spec] + to replace the placeholders at runtime. This field is used + by pipelines built using + ``PipelineJob.pipeline_spec.schema_version`` 2.0.0 or lower, + such as pipelines built using Kubeflow Pipelines SDK 1.8 or + lower. + gcs_output_directory (str): + Required. A path in a Cloud Storage bucket, which will be + treated as the root output directory of the pipeline. It is + used by the system to generate the paths of output + artifacts. The artifact paths are generated with a sub-path + pattern ``{job_id}/{task_id}/{output_key}`` under the + specified output directory. The service account specified in + this pipeline must have the ``storage.objects.get`` and + ``storage.objects.create`` permissions for this bucket. + parameter_values (Mapping[str, google.protobuf.struct_pb2.Value]): + The runtime parameters of the PipelineJob. The parameters + will be passed into + [PipelineJob.pipeline_spec][google.cloud.aiplatform.v1.PipelineJob.pipeline_spec] + to replace the placeholders at runtime. This field is used + by pipelines built using + ``PipelineJob.pipeline_spec.schema_version`` 2.1.0, such as + pipelines built using Kubeflow Pipelines SDK 1.9 or higher + and the v2 DSL. + failure_policy (google.cloud.aiplatform_v1.types.PipelineFailurePolicy): + Represents the failure policy of a pipeline. Currently, the + default of a pipeline is that the pipeline will continue to + run until no more tasks can be executed, also known as + PIPELINE_FAILURE_POLICY_FAIL_SLOW. However, if a pipeline is + set to PIPELINE_FAILURE_POLICY_FAIL_FAST, it will stop + scheduling any new tasks when a task has failed. Any + scheduled tasks will continue to completion. + """ + + parameters = proto.MapField( + proto.STRING, + proto.MESSAGE, + number=1, + message=gca_value.Value, + ) + gcs_output_directory = proto.Field( + proto.STRING, + number=2, + ) + parameter_values = proto.MapField( + proto.STRING, + proto.MESSAGE, + number=3, + message=struct_pb2.Value, + ) + failure_policy = proto.Field( + proto.ENUM, + number=4, + enum=pipeline_failure_policy.PipelineFailurePolicy, + ) + + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + create_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + start_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + end_time = proto.Field( + proto.MESSAGE, + number=5, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=6, + message=timestamp_pb2.Timestamp, + ) + pipeline_spec = proto.Field( + proto.MESSAGE, + number=7, + message=struct_pb2.Struct, + ) + state = proto.Field( + proto.ENUM, + number=8, + enum=pipeline_state.PipelineState, + ) + job_detail = proto.Field( + proto.MESSAGE, + number=9, + message="PipelineJobDetail", + ) + error = proto.Field( + proto.MESSAGE, + number=10, + message=status_pb2.Status, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=11, + ) + runtime_config = proto.Field( + proto.MESSAGE, + number=12, + message=RuntimeConfig, + ) + encryption_spec = proto.Field( + proto.MESSAGE, + number=16, + message=gca_encryption_spec.EncryptionSpec, + ) + service_account = proto.Field( + proto.STRING, + number=17, + ) + network = proto.Field( + proto.STRING, + number=18, + ) + template_uri = proto.Field( + proto.STRING, + number=19, + ) + template_metadata = proto.Field( + proto.MESSAGE, + number=20, + message="PipelineTemplateMetadata", + ) + + +class PipelineTemplateMetadata(proto.Message): + r"""Pipeline template metadata if + [PipelineJob.template_uri][google.cloud.aiplatform.v1.PipelineJob.template_uri] + is from supported template registry. Currently, the only supported + registry is Artifact Registry. + + Attributes: + version (str): + The version_name in artifact registry. + + Will always be presented in output if the + [PipelineJob.template_uri][google.cloud.aiplatform.v1.PipelineJob.template_uri] + is from supported template registry. + + Format is "sha256:abcdef123456...". + """ + + version = proto.Field( + proto.STRING, + number=3, + ) + + +class PipelineJobDetail(proto.Message): + r"""The runtime detail of PipelineJob. + + Attributes: + pipeline_context (google.cloud.aiplatform_v1.types.Context): + Output only. The context of the pipeline. + pipeline_run_context (google.cloud.aiplatform_v1.types.Context): + Output only. The context of the current + pipeline run. + task_details (Sequence[google.cloud.aiplatform_v1.types.PipelineTaskDetail]): + Output only. The runtime details of the tasks + under the pipeline. + """ + + pipeline_context = proto.Field( + proto.MESSAGE, + number=1, + message=context.Context, + ) + pipeline_run_context = proto.Field( + proto.MESSAGE, + number=2, + message=context.Context, + ) + task_details = proto.RepeatedField( + proto.MESSAGE, + number=3, + message="PipelineTaskDetail", + ) + + +class PipelineTaskDetail(proto.Message): + r"""The runtime detail of a task execution. + + Attributes: + task_id (int): + Output only. The system generated ID of the + task. + parent_task_id (int): + Output only. The id of the parent task if the + task is within a component scope. Empty if the + task is at the root level. + task_name (str): + Output only. The user specified name of the task that is + defined in [PipelineJob.spec][]. + create_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Task create time. + start_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Task start time. + end_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Task end time. + executor_detail (google.cloud.aiplatform_v1.types.PipelineTaskExecutorDetail): + Output only. The detailed execution info. + state (google.cloud.aiplatform_v1.types.PipelineTaskDetail.State): + Output only. State of the task. + execution (google.cloud.aiplatform_v1.types.Execution): + Output only. The execution metadata of the + task. + error (google.rpc.status_pb2.Status): + Output only. The error that occurred during + task execution. Only populated when the task's + state is FAILED or CANCELLED. + pipeline_task_status (Sequence[google.cloud.aiplatform_v1.types.PipelineTaskDetail.PipelineTaskStatus]): + Output only. A list of task status. This + field keeps a record of task status evolving + over time. + inputs (Mapping[str, google.cloud.aiplatform_v1.types.PipelineTaskDetail.ArtifactList]): + Output only. The runtime input artifacts of + the task. + outputs (Mapping[str, google.cloud.aiplatform_v1.types.PipelineTaskDetail.ArtifactList]): + Output only. The runtime output artifacts of + the task. + """ + + class State(proto.Enum): + r"""Specifies state of TaskExecution""" + STATE_UNSPECIFIED = 0 + PENDING = 1 + RUNNING = 2 + SUCCEEDED = 3 + CANCEL_PENDING = 4 + CANCELLING = 5 + CANCELLED = 6 + FAILED = 7 + SKIPPED = 8 + NOT_TRIGGERED = 9 + + class PipelineTaskStatus(proto.Message): + r"""A single record of the task status. + + Attributes: + update_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Update time of this status. + state (google.cloud.aiplatform_v1.types.PipelineTaskDetail.State): + Output only. The state of the task. + error (google.rpc.status_pb2.Status): + Output only. The error that occurred during + the state. May be set when the state is any of + the non-final state (PENDING/RUNNING/CANCELLING) + or FAILED state. If the state is FAILED, the + error here is final and not going to be retried. + If the state is a non-final state, the error + indicates a system-error being retried. + """ + + update_time = proto.Field( + proto.MESSAGE, + number=1, + message=timestamp_pb2.Timestamp, + ) + state = proto.Field( + proto.ENUM, + number=2, + enum="PipelineTaskDetail.State", + ) + error = proto.Field( + proto.MESSAGE, + number=3, + message=status_pb2.Status, + ) + + class ArtifactList(proto.Message): + r"""A list of artifact metadata. + + Attributes: + artifacts (Sequence[google.cloud.aiplatform_v1.types.Artifact]): + Output only. A list of artifact metadata. + """ + + artifacts = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=artifact.Artifact, + ) + + task_id = proto.Field( + proto.INT64, + number=1, + ) + parent_task_id = proto.Field( + proto.INT64, + number=12, + ) + task_name = proto.Field( + proto.STRING, + number=2, + ) + create_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + start_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + end_time = proto.Field( + proto.MESSAGE, + number=5, + message=timestamp_pb2.Timestamp, + ) + executor_detail = proto.Field( + proto.MESSAGE, + number=6, + message="PipelineTaskExecutorDetail", + ) + state = proto.Field( + proto.ENUM, + number=7, + enum=State, + ) + execution = proto.Field( + proto.MESSAGE, + number=8, + message=gca_execution.Execution, + ) + error = proto.Field( + proto.MESSAGE, + number=9, + message=status_pb2.Status, + ) + pipeline_task_status = proto.RepeatedField( + proto.MESSAGE, + number=13, + message=PipelineTaskStatus, + ) + inputs = proto.MapField( + proto.STRING, + proto.MESSAGE, + number=10, + message=ArtifactList, + ) + outputs = proto.MapField( + proto.STRING, + proto.MESSAGE, + number=11, + message=ArtifactList, + ) + + +class PipelineTaskExecutorDetail(proto.Message): + r"""The runtime detail of a pipeline executor. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + container_detail (google.cloud.aiplatform_v1.types.PipelineTaskExecutorDetail.ContainerDetail): + Output only. The detailed info for a + container executor. + + This field is a member of `oneof`_ ``details``. + custom_job_detail (google.cloud.aiplatform_v1.types.PipelineTaskExecutorDetail.CustomJobDetail): + Output only. The detailed info for a custom + job executor. + + This field is a member of `oneof`_ ``details``. + """ + + class ContainerDetail(proto.Message): + r"""The detail of a container execution. It contains the job + names of the lifecycle of a container execution. + + Attributes: + main_job (str): + Output only. The name of the + [CustomJob][google.cloud.aiplatform.v1.CustomJob] for the + main container execution. + pre_caching_check_job (str): + Output only. The name of the + [CustomJob][google.cloud.aiplatform.v1.CustomJob] for the + pre-caching-check container execution. This job will be + available if the + [PipelineJob.pipeline_spec][google.cloud.aiplatform.v1.PipelineJob.pipeline_spec] + specifies the ``pre_caching_check`` hook in the lifecycle + events. + """ + + main_job = proto.Field( + proto.STRING, + number=1, + ) + pre_caching_check_job = proto.Field( + proto.STRING, + number=2, + ) + + class CustomJobDetail(proto.Message): + r"""The detailed info for a custom job executor. + + Attributes: + job (str): + Output only. The name of the + [CustomJob][google.cloud.aiplatform.v1.CustomJob]. + """ + + job = proto.Field( + proto.STRING, + number=1, + ) + + container_detail = proto.Field( + proto.MESSAGE, + number=1, + oneof="details", + message=ContainerDetail, + ) + custom_job_detail = proto.Field( + proto.MESSAGE, + number=2, + oneof="details", + message=CustomJobDetail, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/pipeline_service.py b/google/cloud/aiplatform_v1/types/pipeline_service.py index 0f659285e2..4e197a08e1 100644 --- a/google/cloud/aiplatform_v1/types/pipeline_service.py +++ b/google/cloud/aiplatform_v1/types/pipeline_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,6 +15,7 @@ # import proto # type: ignore +from google.cloud.aiplatform_v1.types import pipeline_job as gca_pipeline_job from google.cloud.aiplatform_v1.types import training_pipeline as gca_training_pipeline from google.protobuf import field_mask_pb2 # type: ignore @@ -28,6 +29,12 @@ "ListTrainingPipelinesResponse", "DeleteTrainingPipelineRequest", "CancelTrainingPipelineRequest", + "CreatePipelineJobRequest", + "GetPipelineJobRequest", + "ListPipelineJobsRequest", + "ListPipelineJobsResponse", + "DeletePipelineJobRequest", + "CancelPipelineJobRequest", }, ) @@ -45,9 +52,14 @@ class CreateTrainingPipelineRequest(proto.Message): Required. The TrainingPipeline to create. """ - parent = proto.Field(proto.STRING, number=1,) + parent = proto.Field( + proto.STRING, + number=1, + ) training_pipeline = proto.Field( - proto.MESSAGE, number=2, message=gca_training_pipeline.TrainingPipeline, + proto.MESSAGE, + number=2, + message=gca_training_pipeline.TrainingPipeline, ) @@ -58,11 +70,13 @@ class GetTrainingPipelineRequest(proto.Message): Attributes: name (str): Required. The name of the TrainingPipeline resource. Format: - ``projects/{project}/locations/{location}/trainingPipelines/{training_pipeline}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListTrainingPipelinesRequest(proto.Message): @@ -102,11 +116,27 @@ class ListTrainingPipelinesRequest(proto.Message): Mask specifying which fields to read. """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) - read_mask = proto.Field(proto.MESSAGE, number=5, message=field_mask_pb2.FieldMask,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=5, + message=field_mask_pb2.FieldMask, + ) class ListTrainingPipelinesResponse(proto.Message): @@ -128,9 +158,14 @@ def raw_page(self): return self training_pipelines = proto.RepeatedField( - proto.MESSAGE, number=1, message=gca_training_pipeline.TrainingPipeline, + proto.MESSAGE, + number=1, + message=gca_training_pipeline.TrainingPipeline, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class DeleteTrainingPipelineRequest(proto.Message): @@ -141,11 +176,13 @@ class DeleteTrainingPipelineRequest(proto.Message): name (str): Required. The name of the TrainingPipeline resource to be deleted. Format: - ``projects/{project}/locations/{location}/trainingPipelines/{training_pipeline}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class CancelTrainingPipelineRequest(proto.Message): @@ -156,11 +193,224 @@ class CancelTrainingPipelineRequest(proto.Message): name (str): Required. The name of the TrainingPipeline to cancel. Format: - ``projects/{project}/locations/{location}/trainingPipelines/{training_pipeline}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) + + +class CreatePipelineJobRequest(proto.Message): + r"""Request message for + [PipelineService.CreatePipelineJob][google.cloud.aiplatform.v1.PipelineService.CreatePipelineJob]. + + Attributes: + parent (str): + Required. The resource name of the Location to create the + PipelineJob in. Format: + ``projects/{project}/locations/{location}`` + pipeline_job (google.cloud.aiplatform_v1.types.PipelineJob): + Required. The PipelineJob to create. + pipeline_job_id (str): + The ID to use for the PipelineJob, which will become the + final component of the PipelineJob name. If not provided, an + ID will be automatically generated. + + This value should be less than 128 characters, and valid + characters are /[a-z][0-9]-/. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + pipeline_job = proto.Field( + proto.MESSAGE, + number=2, + message=gca_pipeline_job.PipelineJob, + ) + pipeline_job_id = proto.Field( + proto.STRING, + number=3, + ) + + +class GetPipelineJobRequest(proto.Message): + r"""Request message for + [PipelineService.GetPipelineJob][google.cloud.aiplatform.v1.PipelineService.GetPipelineJob]. + + Attributes: + name (str): + Required. The name of the PipelineJob resource. Format: + ``projects/{project}/locations/{location}/pipelineJobs/{pipeline_job}`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class ListPipelineJobsRequest(proto.Message): + r"""Request message for + [PipelineService.ListPipelineJobs][google.cloud.aiplatform.v1.PipelineService.ListPipelineJobs]. + + Attributes: + parent (str): + Required. The resource name of the Location to list the + PipelineJobs from. Format: + ``projects/{project}/locations/{location}`` + filter (str): + Lists the PipelineJobs that match the filter expression. The + following fields are supported: + + - ``pipeline_name``: Supports ``=`` and ``!=`` comparisons. + - ``display_name``: Supports ``=``, ``!=`` comparisons, and + ``:`` wildcard. + - ``pipeline_job_user_id``: Supports ``=``, ``!=`` + comparisons, and ``:`` wildcard. for example, can check + if pipeline's display_name contains *step* by doing + display_name:"*step*" + - ``state``: Supports ``=`` and ``!=`` comparisons. + - ``create_time``: Supports ``=``, ``!=``, ``<``, ``>``, + ``<=``, and ``>=`` comparisons. Values must be in RFC + 3339 format. + - ``update_time``: Supports ``=``, ``!=``, ``<``, ``>``, + ``<=``, and ``>=`` comparisons. Values must be in RFC + 3339 format. + - ``end_time``: Supports ``=``, ``!=``, ``<``, ``>``, + ``<=``, and ``>=`` comparisons. Values must be in RFC + 3339 format. + - ``labels``: Supports key-value equality and key presence. + - ``template_uri``: Supports ``=``, ``!=`` comparisons, and + ``:`` wildcard. + - ``template_metadata.version``: Supports ``=``, ``!=`` + comparisons, and ``:`` wildcard. + + Filter expressions can be combined together using logical + operators (``AND`` & ``OR``). For example: + ``pipeline_name="test" AND create_time>"2020-05-18T13:30:00Z"``. + + The syntax to define filter expression is based on + https://google.aip.dev/160. + + Examples: + + - ``create_time>"2021-05-18T00:00:00Z" OR update_time>"2020-05-18T00:00:00Z"`` + PipelineJobs created or updated after 2020-05-18 00:00:00 + UTC. + - ``labels.env = "prod"`` PipelineJobs with label "env" set + to "prod". + page_size (int): + The standard list page size. + page_token (str): + The standard list page token. Typically obtained via + [ListPipelineJobsResponse.next_page_token][google.cloud.aiplatform.v1.ListPipelineJobsResponse.next_page_token] + of the previous + [PipelineService.ListPipelineJobs][google.cloud.aiplatform.v1.PipelineService.ListPipelineJobs] + call. + order_by (str): + A comma-separated list of fields to order by. The default + sort order is in ascending order. Use "desc" after a field + name for descending. You can have multiple order_by fields + provided e.g. "create_time desc, end_time", "end_time, + start_time, update_time" For example, using "create_time + desc, end_time" will order results by create time in + descending order, and if there are multiple jobs having the + same create time, order them by the end time in ascending + order. if order_by is not specified, it will order by + default order is create time in descending order. Supported + fields: + + - ``create_time`` + - ``update_time`` + - ``end_time`` + - ``start_time`` + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + order_by = proto.Field( + proto.STRING, + number=6, + ) + + +class ListPipelineJobsResponse(proto.Message): + r"""Response message for + [PipelineService.ListPipelineJobs][google.cloud.aiplatform.v1.PipelineService.ListPipelineJobs] + + Attributes: + pipeline_jobs (Sequence[google.cloud.aiplatform_v1.types.PipelineJob]): + List of PipelineJobs in the requested page. + next_page_token (str): + A token to retrieve the next page of results. Pass to + [ListPipelineJobsRequest.page_token][google.cloud.aiplatform.v1.ListPipelineJobsRequest.page_token] + to obtain that page. + """ + + @property + def raw_page(self): + return self + + pipeline_jobs = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gca_pipeline_job.PipelineJob, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) + + +class DeletePipelineJobRequest(proto.Message): + r"""Request message for + [PipelineService.DeletePipelineJob][google.cloud.aiplatform.v1.PipelineService.DeletePipelineJob]. + + Attributes: + name (str): + Required. The name of the PipelineJob resource to be + deleted. Format: + ``projects/{project}/locations/{location}/pipelineJobs/{pipeline_job}`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class CancelPipelineJobRequest(proto.Message): + r"""Request message for + [PipelineService.CancelPipelineJob][google.cloud.aiplatform.v1.PipelineService.CancelPipelineJob]. + + Attributes: + name (str): + Required. The name of the PipelineJob to cancel. Format: + ``projects/{project}/locations/{location}/pipelineJobs/{pipeline_job}`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/pipeline_state.py b/google/cloud/aiplatform_v1/types/pipeline_state.py index 1966b4b033..f491b590db 100644 --- a/google/cloud/aiplatform_v1/types/pipeline_state.py +++ b/google/cloud/aiplatform_v1/types/pipeline_state.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,7 +17,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1", manifest={"PipelineState",}, + package="google.cloud.aiplatform.v1", + manifest={ + "PipelineState", + }, ) diff --git a/google/cloud/aiplatform_v1/types/prediction_service.py b/google/cloud/aiplatform_v1/types/prediction_service.py index 40b6aefd8e..ce24215d66 100644 --- a/google/cloud/aiplatform_v1/types/prediction_service.py +++ b/google/cloud/aiplatform_v1/types/prediction_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,12 +15,20 @@ # import proto # type: ignore +from google.api import httpbody_pb2 # type: ignore +from google.cloud.aiplatform_v1.types import explanation from google.protobuf import struct_pb2 # type: ignore __protobuf__ = proto.module( package="google.cloud.aiplatform.v1", - manifest={"PredictRequest", "PredictResponse",}, + manifest={ + "PredictRequest", + "PredictResponse", + "RawPredictRequest", + "ExplainRequest", + "ExplainResponse", + }, ) @@ -53,9 +61,20 @@ class PredictRequest(proto.Message): [parameters_schema_uri][google.cloud.aiplatform.v1.PredictSchemata.parameters_schema_uri]. """ - endpoint = proto.Field(proto.STRING, number=1,) - instances = proto.RepeatedField(proto.MESSAGE, number=2, message=struct_pb2.Value,) - parameters = proto.Field(proto.MESSAGE, number=3, message=struct_pb2.Value,) + endpoint = proto.Field( + proto.STRING, + number=1, + ) + instances = proto.RepeatedField( + proto.MESSAGE, + number=2, + message=struct_pb2.Value, + ) + parameters = proto.Field( + proto.MESSAGE, + number=3, + message=struct_pb2.Value, + ) class PredictResponse(proto.Message): @@ -73,12 +92,190 @@ class PredictResponse(proto.Message): deployed_model_id (str): ID of the Endpoint's DeployedModel that served this prediction. + model (str): + Output only. The resource name of the Model + which is deployed as the DeployedModel that this + prediction hits. + model_version_id (str): + Output only. The version ID of the Model + which is deployed as the DeployedModel that this + prediction hits. + model_display_name (str): + Output only. The [display + name][google.cloud.aiplatform.v1.Model.display_name] of the + Model which is deployed as the DeployedModel that this + prediction hits. """ predictions = proto.RepeatedField( - proto.MESSAGE, number=1, message=struct_pb2.Value, + proto.MESSAGE, + number=1, + message=struct_pb2.Value, + ) + deployed_model_id = proto.Field( + proto.STRING, + number=2, + ) + model = proto.Field( + proto.STRING, + number=3, + ) + model_version_id = proto.Field( + proto.STRING, + number=5, + ) + model_display_name = proto.Field( + proto.STRING, + number=4, + ) + + +class RawPredictRequest(proto.Message): + r"""Request message for + [PredictionService.RawPredict][google.cloud.aiplatform.v1.PredictionService.RawPredict]. + + Attributes: + endpoint (str): + Required. The name of the Endpoint requested to serve the + prediction. Format: + ``projects/{project}/locations/{location}/endpoints/{endpoint}`` + http_body (google.api.httpbody_pb2.HttpBody): + The prediction input. Supports HTTP headers and arbitrary + data payload. + + A [DeployedModel][google.cloud.aiplatform.v1.DeployedModel] + may have an upper limit on the number of instances it + supports per request. When this limit it is exceeded for an + AutoML model, the + [RawPredict][google.cloud.aiplatform.v1.PredictionService.RawPredict] + method returns an error. When this limit is exceeded for a + custom-trained model, the behavior varies depending on the + model. + + You can specify the schema for each instance in the + [predict_schemata.instance_schema_uri][google.cloud.aiplatform.v1.PredictSchemata.instance_schema_uri] + field when you create a + [Model][google.cloud.aiplatform.v1.Model]. This schema + applies when you deploy the ``Model`` as a ``DeployedModel`` + to an [Endpoint][google.cloud.aiplatform.v1.Endpoint] and + use the ``RawPredict`` method. + """ + + endpoint = proto.Field( + proto.STRING, + number=1, + ) + http_body = proto.Field( + proto.MESSAGE, + number=2, + message=httpbody_pb2.HttpBody, + ) + + +class ExplainRequest(proto.Message): + r"""Request message for + [PredictionService.Explain][google.cloud.aiplatform.v1.PredictionService.Explain]. + + Attributes: + endpoint (str): + Required. The name of the Endpoint requested to serve the + explanation. Format: + ``projects/{project}/locations/{location}/endpoints/{endpoint}`` + instances (Sequence[google.protobuf.struct_pb2.Value]): + Required. The instances that are the input to the + explanation call. A DeployedModel may have an upper limit on + the number of instances it supports per request, and when it + is exceeded the explanation call errors in case of AutoML + Models, or, in case of customer created Models, the + behaviour is as documented by that Model. The schema of any + single instance may be specified via Endpoint's + DeployedModels' + [Model's][google.cloud.aiplatform.v1.DeployedModel.model] + [PredictSchemata's][google.cloud.aiplatform.v1.Model.predict_schemata] + [instance_schema_uri][google.cloud.aiplatform.v1.PredictSchemata.instance_schema_uri]. + parameters (google.protobuf.struct_pb2.Value): + The parameters that govern the prediction. The schema of the + parameters may be specified via Endpoint's DeployedModels' + [Model's ][google.cloud.aiplatform.v1.DeployedModel.model] + [PredictSchemata's][google.cloud.aiplatform.v1.Model.predict_schemata] + [parameters_schema_uri][google.cloud.aiplatform.v1.PredictSchemata.parameters_schema_uri]. + explanation_spec_override (google.cloud.aiplatform_v1.types.ExplanationSpecOverride): + If specified, overrides the + [explanation_spec][google.cloud.aiplatform.v1.DeployedModel.explanation_spec] + of the DeployedModel. Can be used for explaining prediction + results with different configurations, such as: + + - Explaining top-5 predictions results as opposed to top-1; + - Increasing path count or step count of the attribution + methods to reduce approximate errors; + - Using different baselines for explaining the prediction + results. + deployed_model_id (str): + If specified, this ExplainRequest will be served by the + chosen DeployedModel, overriding + [Endpoint.traffic_split][google.cloud.aiplatform.v1.Endpoint.traffic_split]. + """ + + endpoint = proto.Field( + proto.STRING, + number=1, + ) + instances = proto.RepeatedField( + proto.MESSAGE, + number=2, + message=struct_pb2.Value, + ) + parameters = proto.Field( + proto.MESSAGE, + number=4, + message=struct_pb2.Value, + ) + explanation_spec_override = proto.Field( + proto.MESSAGE, + number=5, + message=explanation.ExplanationSpecOverride, + ) + deployed_model_id = proto.Field( + proto.STRING, + number=3, + ) + + +class ExplainResponse(proto.Message): + r"""Response message for + [PredictionService.Explain][google.cloud.aiplatform.v1.PredictionService.Explain]. + + Attributes: + explanations (Sequence[google.cloud.aiplatform_v1.types.Explanation]): + The explanations of the Model's + [PredictResponse.predictions][google.cloud.aiplatform.v1.PredictResponse.predictions]. + + It has the same number of elements as + [instances][google.cloud.aiplatform.v1.ExplainRequest.instances] + to be explained. + deployed_model_id (str): + ID of the Endpoint's DeployedModel that + served this explanation. + predictions (Sequence[google.protobuf.struct_pb2.Value]): + The predictions that are the output of the predictions call. + Same as + [PredictResponse.predictions][google.cloud.aiplatform.v1.PredictResponse.predictions]. + """ + + explanations = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=explanation.Explanation, + ) + deployed_model_id = proto.Field( + proto.STRING, + number=2, + ) + predictions = proto.RepeatedField( + proto.MESSAGE, + number=3, + message=struct_pb2.Value, ) - deployed_model_id = proto.Field(proto.STRING, number=2,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/specialist_pool.py b/google/cloud/aiplatform_v1/types/specialist_pool.py index 0f5de963fb..76d49a9334 100644 --- a/google/cloud/aiplatform_v1/types/specialist_pool.py +++ b/google/cloud/aiplatform_v1/types/specialist_pool.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,19 +17,21 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1", manifest={"SpecialistPool",}, + package="google.cloud.aiplatform.v1", + manifest={ + "SpecialistPool", + }, ) class SpecialistPool(proto.Message): r"""SpecialistPool represents customers' own workforce to work on their data labeling jobs. It includes a group of specialist - managers who are responsible for managing the labelers in this - pool as well as customers' data labeling jobs associated with - this pool. - Customers create specialist pool as well as start data labeling - jobs on Cloud, managers and labelers work with the jobs using - CrowdCompute console. + managers and workers. Managers are responsible for managing the + workers in this pool as well as customers' data labeling jobs + associated with this pool. Customers create specialist pool as + well as start data labeling jobs on Cloud, managers and workers + handle the jobs using CrowdCompute console. Attributes: name (str): @@ -42,21 +44,43 @@ class SpecialistPool(proto.Message): characters. This field should be unique on project-level. specialist_managers_count (int): - Output only. The number of Specialists in - this SpecialistPool. + Output only. The number of managers in this + SpecialistPool. specialist_manager_emails (Sequence[str]): - The email addresses of the specialists in the + The email addresses of the managers in the SpecialistPool. pending_data_labeling_jobs (Sequence[str]): Output only. The resource name of the pending data labeling jobs. + specialist_worker_emails (Sequence[str]): + The email addresses of workers in the + SpecialistPool. """ - name = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) - specialist_managers_count = proto.Field(proto.INT32, number=3,) - specialist_manager_emails = proto.RepeatedField(proto.STRING, number=4,) - pending_data_labeling_jobs = proto.RepeatedField(proto.STRING, number=5,) + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + specialist_managers_count = proto.Field( + proto.INT32, + number=3, + ) + specialist_manager_emails = proto.RepeatedField( + proto.STRING, + number=4, + ) + pending_data_labeling_jobs = proto.RepeatedField( + proto.STRING, + number=5, + ) + specialist_worker_emails = proto.RepeatedField( + proto.STRING, + number=7, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/specialist_pool_service.py b/google/cloud/aiplatform_v1/types/specialist_pool_service.py index d7b5f33f75..6257a81055 100644 --- a/google/cloud/aiplatform_v1/types/specialist_pool_service.py +++ b/google/cloud/aiplatform_v1/types/specialist_pool_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -48,9 +48,14 @@ class CreateSpecialistPoolRequest(proto.Message): Required. The SpecialistPool to create. """ - parent = proto.Field(proto.STRING, number=1,) + parent = proto.Field( + proto.STRING, + number=1, + ) specialist_pool = proto.Field( - proto.MESSAGE, number=2, message=gca_specialist_pool.SpecialistPool, + proto.MESSAGE, + number=2, + message=gca_specialist_pool.SpecialistPool, ) @@ -64,7 +69,9 @@ class CreateSpecialistPoolOperationMetadata(proto.Message): """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, ) @@ -76,11 +83,13 @@ class GetSpecialistPoolRequest(proto.Message): name (str): Required. The name of the SpecialistPool resource. The form is - ``projects/{project}/locations/{location}/specialistPools/{specialist_pool}``. """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListSpecialistPoolsRequest(proto.Message): @@ -104,10 +113,23 @@ class ListSpecialistPoolsRequest(proto.Message): FieldMask represents a set of """ - parent = proto.Field(proto.STRING, number=1,) - page_size = proto.Field(proto.INT32, number=2,) - page_token = proto.Field(proto.STRING, number=3,) - read_mask = proto.Field(proto.MESSAGE, number=4, message=field_mask_pb2.FieldMask,) + parent = proto.Field( + proto.STRING, + number=1, + ) + page_size = proto.Field( + proto.INT32, + number=2, + ) + page_token = proto.Field( + proto.STRING, + number=3, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=4, + message=field_mask_pb2.FieldMask, + ) class ListSpecialistPoolsResponse(proto.Message): @@ -127,9 +149,14 @@ def raw_page(self): return self specialist_pools = proto.RepeatedField( - proto.MESSAGE, number=1, message=gca_specialist_pool.SpecialistPool, + proto.MESSAGE, + number=1, + message=gca_specialist_pool.SpecialistPool, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class DeleteSpecialistPoolRequest(proto.Message): @@ -148,8 +175,14 @@ class DeleteSpecialistPoolRequest(proto.Message): SpecialistPool has no specialist managers.) """ - name = proto.Field(proto.STRING, number=1,) - force = proto.Field(proto.BOOL, number=2,) + name = proto.Field( + proto.STRING, + number=1, + ) + force = proto.Field( + proto.BOOL, + number=2, + ) class UpdateSpecialistPoolRequest(proto.Message): @@ -166,10 +199,14 @@ class UpdateSpecialistPoolRequest(proto.Message): """ specialist_pool = proto.Field( - proto.MESSAGE, number=1, message=gca_specialist_pool.SpecialistPool, + proto.MESSAGE, + number=1, + message=gca_specialist_pool.SpecialistPool, ) update_mask = proto.Field( - proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, ) @@ -181,15 +218,19 @@ class UpdateSpecialistPoolOperationMetadata(proto.Message): specialist_pool (str): Output only. The name of the SpecialistPool to which the specialists are being added. Format: - ``projects/{project_id}/locations/{location_id}/specialistPools/{specialist_pool}`` generic_metadata (google.cloud.aiplatform_v1.types.GenericOperationMetadata): The operation generic information. """ - specialist_pool = proto.Field(proto.STRING, number=1,) + specialist_pool = proto.Field( + proto.STRING, + number=1, + ) generic_metadata = proto.Field( - proto.MESSAGE, number=2, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=2, + message=operation.GenericOperationMetadata, ) diff --git a/google/cloud/aiplatform_v1/types/study.py b/google/cloud/aiplatform_v1/types/study.py index 40a6c84ce5..329b499d5d 100644 --- a/google/cloud/aiplatform_v1/types/study.py +++ b/google/cloud/aiplatform_v1/types/study.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,22 +15,91 @@ # import proto # type: ignore +from google.protobuf import duration_pb2 # type: ignore from google.protobuf import struct_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module( package="google.cloud.aiplatform.v1", - manifest={"Trial", "StudySpec", "Measurement",}, + manifest={ + "Study", + "Trial", + "StudySpec", + "Measurement", + }, ) +class Study(proto.Message): + r"""A message representing a Study. + + Attributes: + name (str): + Output only. The name of a study. The study's globally + unique identifier. Format: + ``projects/{project}/locations/{location}/studies/{study}`` + display_name (str): + Required. Describes the Study, default value + is empty string. + study_spec (google.cloud.aiplatform_v1.types.StudySpec): + Required. Configuration of the Study. + state (google.cloud.aiplatform_v1.types.Study.State): + Output only. The detailed state of a Study. + create_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Time at which the study was + created. + inactive_reason (str): + Output only. A human readable reason why the + Study is inactive. This should be empty if a + study is ACTIVE or COMPLETED. + """ + + class State(proto.Enum): + r"""Describes the Study state.""" + STATE_UNSPECIFIED = 0 + ACTIVE = 1 + INACTIVE = 2 + COMPLETED = 3 + + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + study_spec = proto.Field( + proto.MESSAGE, + number=3, + message="StudySpec", + ) + state = proto.Field( + proto.ENUM, + number=4, + enum=State, + ) + create_time = proto.Field( + proto.MESSAGE, + number=5, + message=timestamp_pb2.Timestamp, + ) + inactive_reason = proto.Field( + proto.STRING, + number=6, + ) + + class Trial(proto.Message): r"""A message representing a Trial. A Trial contains a unique set of Parameters that has been or will be evaluated, along with the objective metrics got by running the Trial. Attributes: + name (str): + Output only. Resource name of the Trial + assigned by the service. id (str): Output only. The identifier of the Trial assigned by the service. @@ -41,15 +110,52 @@ class Trial(proto.Message): final_measurement (google.cloud.aiplatform_v1.types.Measurement): Output only. The final measurement containing the objective value. + measurements (Sequence[google.cloud.aiplatform_v1.types.Measurement]): + Output only. A list of measurements that are strictly + lexicographically ordered by their induced tuples (steps, + elapsed_duration). These are used for early stopping + computations. start_time (google.protobuf.timestamp_pb2.Timestamp): Output only. Time when the Trial was started. end_time (google.protobuf.timestamp_pb2.Timestamp): Output only. Time when the Trial's status changed to ``SUCCEEDED`` or ``INFEASIBLE``. + client_id (str): + Output only. The identifier of the client that originally + requested this Trial. Each client is identified by a unique + client_id. When a client asks for a suggestion, Vertex AI + Vizier will assign it a Trial. The client should evaluate + the Trial, complete it, and report back to Vertex AI Vizier. + If suggestion is asked again by same client_id before the + Trial is completed, the same Trial will be returned. + Multiple clients with different client_ids can ask for + suggestions simultaneously, each of them will get their own + Trial. + infeasible_reason (str): + Output only. A human readable string describing why the + Trial is infeasible. This is set only if Trial state is + ``INFEASIBLE``. custom_job (str): Output only. The CustomJob name linked to the Trial. It's set for a HyperparameterTuningJob's Trial. + web_access_uris (Mapping[str, str]): + Output only. URIs for accessing `interactive + shells `__ + (one URI for each training node). Only available if this + trial is part of a + [HyperparameterTuningJob][google.cloud.aiplatform.v1.HyperparameterTuningJob] + and the job's + [trial_job_spec.enable_web_access][google.cloud.aiplatform.v1.CustomJobSpec.enable_web_access] + field is ``true``. + + The keys are names of each node used for the trial; for + example, ``workerpool0-0`` for the primary node, + ``workerpool1-0`` for the first node in the second worker + pool, and ``workerpool1-1`` for the second node in the + second worker pool. + + The values are the URIs for each node's interactive shell. """ class State(proto.Enum): @@ -63,6 +169,7 @@ class State(proto.Enum): class Parameter(proto.Message): r"""A message representing a parameter to be tuned. + Attributes: parameter_id (str): Output only. The ID of the parameter. The parameter should @@ -76,21 +183,99 @@ class Parameter(proto.Message): 'CATEGORICAL'. """ - parameter_id = proto.Field(proto.STRING, number=1,) - value = proto.Field(proto.MESSAGE, number=2, message=struct_pb2.Value,) + parameter_id = proto.Field( + proto.STRING, + number=1, + ) + value = proto.Field( + proto.MESSAGE, + number=2, + message=struct_pb2.Value, + ) - id = proto.Field(proto.STRING, number=2,) - state = proto.Field(proto.ENUM, number=3, enum=State,) - parameters = proto.RepeatedField(proto.MESSAGE, number=4, message=Parameter,) - final_measurement = proto.Field(proto.MESSAGE, number=5, message="Measurement",) - start_time = proto.Field(proto.MESSAGE, number=7, message=timestamp_pb2.Timestamp,) - end_time = proto.Field(proto.MESSAGE, number=8, message=timestamp_pb2.Timestamp,) - custom_job = proto.Field(proto.STRING, number=11,) + name = proto.Field( + proto.STRING, + number=1, + ) + id = proto.Field( + proto.STRING, + number=2, + ) + state = proto.Field( + proto.ENUM, + number=3, + enum=State, + ) + parameters = proto.RepeatedField( + proto.MESSAGE, + number=4, + message=Parameter, + ) + final_measurement = proto.Field( + proto.MESSAGE, + number=5, + message="Measurement", + ) + measurements = proto.RepeatedField( + proto.MESSAGE, + number=6, + message="Measurement", + ) + start_time = proto.Field( + proto.MESSAGE, + number=7, + message=timestamp_pb2.Timestamp, + ) + end_time = proto.Field( + proto.MESSAGE, + number=8, + message=timestamp_pb2.Timestamp, + ) + client_id = proto.Field( + proto.STRING, + number=9, + ) + infeasible_reason = proto.Field( + proto.STRING, + number=10, + ) + custom_job = proto.Field( + proto.STRING, + number=11, + ) + web_access_uris = proto.MapField( + proto.STRING, + proto.STRING, + number=12, + ) class StudySpec(proto.Message): r"""Represents specification of a Study. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: + decay_curve_stopping_spec (google.cloud.aiplatform_v1.types.StudySpec.DecayCurveAutomatedStoppingSpec): + The automated early stopping spec using decay + curve rule. + + This field is a member of `oneof`_ ``automated_stopping_spec``. + median_automated_stopping_spec (google.cloud.aiplatform_v1.types.StudySpec.MedianAutomatedStoppingSpec): + The automated early stopping spec using + median rule. + + This field is a member of `oneof`_ ``automated_stopping_spec``. + convex_automated_stopping_spec (google.cloud.aiplatform_v1.types.StudySpec.ConvexAutomatedStoppingSpec): + The automated early stopping spec using + convex stopping rule. + + This field is a member of `oneof`_ ``automated_stopping_spec``. metrics (Sequence[google.cloud.aiplatform_v1.types.StudySpec.MetricSpec]): Required. Metric specs for the Study. parameters (Sequence[google.cloud.aiplatform_v1.types.StudySpec.ParameterSpec]): @@ -99,9 +284,9 @@ class StudySpec(proto.Message): The search algorithm specified for the Study. observation_noise (google.cloud.aiplatform_v1.types.StudySpec.ObservationNoise): The observation noise level of the study. - Currently only supported by the Vizier service. - Not supported by HyperparamterTuningJob or - TrainingPipeline. + Currently only supported by the Vertex AI Vizier + service. Not supported by HyperparamterTuningJob + or TrainingPipeline. measurement_selection_type (google.cloud.aiplatform_v1.types.StudySpec.MeasurementSelectionType): Describe which measurement selection type will be used @@ -142,6 +327,7 @@ class MeasurementSelectionType(proto.Enum): class MetricSpec(proto.Message): r"""Represents a metric to optimize. + Attributes: metric_id (str): Required. The ID of the metric. Must not @@ -158,20 +344,43 @@ class GoalType(proto.Enum): MAXIMIZE = 1 MINIMIZE = 2 - metric_id = proto.Field(proto.STRING, number=1,) - goal = proto.Field(proto.ENUM, number=2, enum="StudySpec.MetricSpec.GoalType",) + metric_id = proto.Field( + proto.STRING, + number=1, + ) + goal = proto.Field( + proto.ENUM, + number=2, + enum="StudySpec.MetricSpec.GoalType", + ) class ParameterSpec(proto.Message): r"""Represents a single parameter to optimize. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: double_value_spec (google.cloud.aiplatform_v1.types.StudySpec.ParameterSpec.DoubleValueSpec): The value spec for a 'DOUBLE' parameter. + + This field is a member of `oneof`_ ``parameter_value_spec``. integer_value_spec (google.cloud.aiplatform_v1.types.StudySpec.ParameterSpec.IntegerValueSpec): The value spec for an 'INTEGER' parameter. + + This field is a member of `oneof`_ ``parameter_value_spec``. categorical_value_spec (google.cloud.aiplatform_v1.types.StudySpec.ParameterSpec.CategoricalValueSpec): The value spec for a 'CATEGORICAL' parameter. + + This field is a member of `oneof`_ ``parameter_value_spec``. discrete_value_spec (google.cloud.aiplatform_v1.types.StudySpec.ParameterSpec.DiscreteValueSpec): The value spec for a 'DISCRETE' parameter. + + This field is a member of `oneof`_ ``parameter_value_spec``. parameter_id (str): Required. The ID of the parameter. Must not contain whitespaces and must be unique amongst @@ -196,6 +405,7 @@ class ScaleType(proto.Enum): class DoubleValueSpec(proto.Message): r"""Value specification for a parameter in ``DOUBLE`` type. + Attributes: min_value (float): Required. Inclusive minimum value of the @@ -203,13 +413,34 @@ class DoubleValueSpec(proto.Message): max_value (float): Required. Inclusive maximum value of the parameter. + default_value (float): + A default value for a ``DOUBLE`` parameter that is assumed + to be a relatively good starting point. Unset value signals + that there is no offered starting point. + + Currently only supported by the Vertex AI Vizier service. + Not supported by HyperparamterTuningJob or TrainingPipeline. + + This field is a member of `oneof`_ ``_default_value``. """ - min_value = proto.Field(proto.DOUBLE, number=1,) - max_value = proto.Field(proto.DOUBLE, number=2,) + min_value = proto.Field( + proto.DOUBLE, + number=1, + ) + max_value = proto.Field( + proto.DOUBLE, + number=2, + ) + default_value = proto.Field( + proto.DOUBLE, + number=4, + optional=True, + ) class IntegerValueSpec(proto.Message): r"""Value specification for a parameter in ``INTEGER`` type. + Attributes: min_value (int): Required. Inclusive minimum value of the @@ -217,22 +448,61 @@ class IntegerValueSpec(proto.Message): max_value (int): Required. Inclusive maximum value of the parameter. + default_value (int): + A default value for an ``INTEGER`` parameter that is assumed + to be a relatively good starting point. Unset value signals + that there is no offered starting point. + + Currently only supported by the Vertex AI Vizier service. + Not supported by HyperparamterTuningJob or TrainingPipeline. + + This field is a member of `oneof`_ ``_default_value``. """ - min_value = proto.Field(proto.INT64, number=1,) - max_value = proto.Field(proto.INT64, number=2,) + min_value = proto.Field( + proto.INT64, + number=1, + ) + max_value = proto.Field( + proto.INT64, + number=2, + ) + default_value = proto.Field( + proto.INT64, + number=4, + optional=True, + ) class CategoricalValueSpec(proto.Message): r"""Value specification for a parameter in ``CATEGORICAL`` type. + Attributes: values (Sequence[str]): Required. The list of possible categories. + default_value (str): + A default value for a ``CATEGORICAL`` parameter that is + assumed to be a relatively good starting point. Unset value + signals that there is no offered starting point. + + Currently only supported by the Vizier service. Not + supported by HyperparamterTuningJob or TrainingPipeline. + + This field is a member of `oneof`_ ``_default_value``. """ - values = proto.RepeatedField(proto.STRING, number=1,) + values = proto.RepeatedField( + proto.STRING, + number=1, + ) + default_value = proto.Field( + proto.STRING, + number=3, + optional=True, + ) class DiscreteValueSpec(proto.Message): r"""Value specification for a parameter in ``DISCRETE`` type. + Attributes: values (Sequence[float]): Required. A list of possible values. @@ -241,24 +511,55 @@ class DiscreteValueSpec(proto.Message): might have possible settings of 1.5, 2.5, and 4.0. This list should not contain more than 1,000 values. + default_value (float): + A default value for a ``DISCRETE`` parameter that is assumed + to be a relatively good starting point. Unset value signals + that there is no offered starting point. It automatically + rounds to the nearest feasible discrete point. + + Currently only supported by the Vizier service. Not + supported by HyperparamterTuningJob or TrainingPipeline. + + This field is a member of `oneof`_ ``_default_value``. """ - values = proto.RepeatedField(proto.DOUBLE, number=1,) + values = proto.RepeatedField( + proto.DOUBLE, + number=1, + ) + default_value = proto.Field( + proto.DOUBLE, + number=3, + optional=True, + ) class ConditionalParameterSpec(proto.Message): r"""Represents a parameter spec with condition from its parent parameter. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: parent_discrete_values (google.cloud.aiplatform_v1.types.StudySpec.ParameterSpec.ConditionalParameterSpec.DiscreteValueCondition): The spec for matching values from a parent parameter of ``DISCRETE`` type. + + This field is a member of `oneof`_ ``parent_value_condition``. parent_int_values (google.cloud.aiplatform_v1.types.StudySpec.ParameterSpec.ConditionalParameterSpec.IntValueCondition): The spec for matching values from a parent parameter of ``INTEGER`` type. + + This field is a member of `oneof`_ ``parent_value_condition``. parent_categorical_values (google.cloud.aiplatform_v1.types.StudySpec.ParameterSpec.ConditionalParameterSpec.CategoricalValueCondition): The spec for matching values from a parent parameter of ``CATEGORICAL`` type. + + This field is a member of `oneof`_ ``parent_value_condition``. parameter_spec (google.cloud.aiplatform_v1.types.StudySpec.ParameterSpec): Required. The spec for a conditional parameter. @@ -277,7 +578,10 @@ class DiscreteValueCondition(proto.Message): The Epsilon of the value matching is 1e-10. """ - values = proto.RepeatedField(proto.DOUBLE, number=1,) + values = proto.RepeatedField( + proto.DOUBLE, + number=1, + ) class IntValueCondition(proto.Message): r"""Represents the spec to match integer values from parent @@ -290,7 +594,10 @@ class IntValueCondition(proto.Message): ``integer_value_spec`` of parent parameter. """ - values = proto.RepeatedField(proto.INT64, number=1,) + values = proto.RepeatedField( + proto.INT64, + number=1, + ) class CategoricalValueCondition(proto.Message): r"""Represents the spec to match categorical values from parent @@ -303,7 +610,10 @@ class CategoricalValueCondition(proto.Message): ``categorical_value_spec`` of parent parameter. """ - values = proto.RepeatedField(proto.STRING, number=1,) + values = proto.RepeatedField( + proto.STRING, + number=1, + ) parent_discrete_values = proto.Field( proto.MESSAGE, @@ -324,7 +634,9 @@ class CategoricalValueCondition(proto.Message): message="StudySpec.ParameterSpec.ConditionalParameterSpec.CategoricalValueCondition", ) parameter_spec = proto.Field( - proto.MESSAGE, number=1, message="StudySpec.ParameterSpec", + proto.MESSAGE, + number=1, + message="StudySpec.ParameterSpec", ) double_value_spec = proto.Field( @@ -351,9 +663,14 @@ class CategoricalValueCondition(proto.Message): oneof="parameter_value_spec", message="StudySpec.ParameterSpec.DiscreteValueSpec", ) - parameter_id = proto.Field(proto.STRING, number=1,) + parameter_id = proto.Field( + proto.STRING, + number=1, + ) scale_type = proto.Field( - proto.ENUM, number=6, enum="StudySpec.ParameterSpec.ScaleType", + proto.ENUM, + number=6, + enum="StudySpec.ParameterSpec.ScaleType", ) conditional_parameter_specs = proto.RepeatedField( proto.MESSAGE, @@ -361,12 +678,163 @@ class CategoricalValueCondition(proto.Message): message="StudySpec.ParameterSpec.ConditionalParameterSpec", ) - metrics = proto.RepeatedField(proto.MESSAGE, number=1, message=MetricSpec,) - parameters = proto.RepeatedField(proto.MESSAGE, number=2, message=ParameterSpec,) - algorithm = proto.Field(proto.ENUM, number=3, enum=Algorithm,) - observation_noise = proto.Field(proto.ENUM, number=6, enum=ObservationNoise,) + class DecayCurveAutomatedStoppingSpec(proto.Message): + r"""The decay curve automated stopping rule builds a Gaussian + Process Regressor to predict the final objective value of a + Trial based on the already completed Trials and the intermediate + measurements of the current Trial. Early stopping is requested + for the current Trial if there is very low probability to exceed + the optimal value found so far. + + Attributes: + use_elapsed_duration (bool): + True if + [Measurement.elapsed_duration][google.cloud.aiplatform.v1.Measurement.elapsed_duration] + is used as the x-axis of each Trials Decay Curve. Otherwise, + [Measurement.step_count][google.cloud.aiplatform.v1.Measurement.step_count] + will be used as the x-axis. + """ + + use_elapsed_duration = proto.Field( + proto.BOOL, + number=1, + ) + + class MedianAutomatedStoppingSpec(proto.Message): + r"""The median automated stopping rule stops a pending Trial if the + Trial's best objective_value is strictly below the median + 'performance' of all completed Trials reported up to the Trial's + last measurement. Currently, 'performance' refers to the running + average of the objective values reported by the Trial in each + measurement. + + Attributes: + use_elapsed_duration (bool): + True if median automated stopping rule applies on + [Measurement.elapsed_duration][google.cloud.aiplatform.v1.Measurement.elapsed_duration]. + It means that elapsed_duration field of latest measurement + of current Trial is used to compute median objective value + for each completed Trials. + """ + + use_elapsed_duration = proto.Field( + proto.BOOL, + number=1, + ) + + class ConvexAutomatedStoppingSpec(proto.Message): + r"""Configuration for ConvexAutomatedStoppingSpec. When there are enough + completed trials (configured by min_measurement_count), for pending + trials with enough measurements and steps, the policy first computes + an overestimate of the objective value at max_num_steps according to + the slope of the incomplete objective value curve. No prediction can + be made if the curve is completely flat. If the overestimation is + worse than the best objective value of the completed trials, this + pending trial will be early-stopped, but a last measurement will be + added to the pending trial with max_num_steps and predicted + objective value from the autoregression model. + + Attributes: + max_step_count (int): + Steps used in predicting the final objective for early + stopped trials. In general, it's set to be the same as the + defined steps in training / tuning. If not defined, it will + learn it from the completed trials. When use_steps is false, + this field is set to the maximum elapsed seconds. + min_step_count (int): + Minimum number of steps for a trial to complete. Trials + which do not have a measurement with step_count > + min_step_count won't be considered for early stopping. It's + ok to set it to 0, and a trial can be early stopped at any + stage. By default, min_step_count is set to be one-tenth of + the max_step_count. When use_elapsed_duration is true, this + field is set to the minimum elapsed seconds. + min_measurement_count (int): + The minimal number of measurements in a Trial. + Early-stopping checks will not trigger if less than + min_measurement_count+1 completed trials or pending trials + with less than min_measurement_count measurements. If not + defined, the default value is 5. + learning_rate_parameter_name (str): + The hyper-parameter name used in the tuning job that stands + for learning rate. Leave it blank if learning rate is not in + a parameter in tuning. The learning_rate is used to estimate + the objective value of the ongoing trial. + use_elapsed_duration (bool): + This bool determines whether or not the rule is applied + based on elapsed_secs or steps. If + use_elapsed_duration==false, the early stopping decision is + made according to the predicted objective values according + to the target steps. If use_elapsed_duration==true, + elapsed_secs is used instead of steps. Also, in this case, + the parameters max_num_steps and min_num_steps are + overloaded to contain max_elapsed_seconds and + min_elapsed_seconds. + """ + + max_step_count = proto.Field( + proto.INT64, + number=1, + ) + min_step_count = proto.Field( + proto.INT64, + number=2, + ) + min_measurement_count = proto.Field( + proto.INT64, + number=3, + ) + learning_rate_parameter_name = proto.Field( + proto.STRING, + number=4, + ) + use_elapsed_duration = proto.Field( + proto.BOOL, + number=5, + ) + + decay_curve_stopping_spec = proto.Field( + proto.MESSAGE, + number=4, + oneof="automated_stopping_spec", + message=DecayCurveAutomatedStoppingSpec, + ) + median_automated_stopping_spec = proto.Field( + proto.MESSAGE, + number=5, + oneof="automated_stopping_spec", + message=MedianAutomatedStoppingSpec, + ) + convex_automated_stopping_spec = proto.Field( + proto.MESSAGE, + number=9, + oneof="automated_stopping_spec", + message=ConvexAutomatedStoppingSpec, + ) + metrics = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=MetricSpec, + ) + parameters = proto.RepeatedField( + proto.MESSAGE, + number=2, + message=ParameterSpec, + ) + algorithm = proto.Field( + proto.ENUM, + number=3, + enum=Algorithm, + ) + observation_noise = proto.Field( + proto.ENUM, + number=6, + enum=ObservationNoise, + ) measurement_selection_type = proto.Field( - proto.ENUM, number=7, enum=MeasurementSelectionType, + proto.ENUM, + number=7, + enum=MeasurementSelectionType, ) @@ -376,6 +844,9 @@ class Measurement(proto.Message): suggested hyperparameter values. Attributes: + elapsed_duration (google.protobuf.duration_pb2.Duration): + Output only. Time that the Trial has been + running at the point of this Measurement. step_count (int): Output only. The number of steps the machine learning model has been trained for. Must be @@ -388,6 +859,7 @@ class Measurement(proto.Message): class Metric(proto.Message): r"""A message representing a metric in the measurement. + Attributes: metric_id (str): Output only. The ID of the Metric. The Metric should be @@ -397,11 +869,29 @@ class Metric(proto.Message): Output only. The value for this metric. """ - metric_id = proto.Field(proto.STRING, number=1,) - value = proto.Field(proto.DOUBLE, number=2,) + metric_id = proto.Field( + proto.STRING, + number=1, + ) + value = proto.Field( + proto.DOUBLE, + number=2, + ) - step_count = proto.Field(proto.INT64, number=2,) - metrics = proto.RepeatedField(proto.MESSAGE, number=3, message=Metric,) + elapsed_duration = proto.Field( + proto.MESSAGE, + number=1, + message=duration_pb2.Duration, + ) + step_count = proto.Field( + proto.INT64, + number=2, + ) + metrics = proto.RepeatedField( + proto.MESSAGE, + number=3, + message=Metric, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/tensorboard.py b/google/cloud/aiplatform_v1/types/tensorboard.py new file mode 100644 index 0000000000..c50d38acf5 --- /dev/null +++ b/google/cloud/aiplatform_v1/types/tensorboard.py @@ -0,0 +1,131 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + +from google.cloud.aiplatform_v1.types import encryption_spec as gca_encryption_spec +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "Tensorboard", + }, +) + + +class Tensorboard(proto.Message): + r"""Tensorboard is a physical database that stores users' + training metrics. A default Tensorboard is provided in each + region of a GCP project. If needed users can also create extra + Tensorboards in their projects. + + Attributes: + name (str): + Output only. Name of the Tensorboard. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}`` + display_name (str): + Required. User provided name of this + Tensorboard. + description (str): + Description of this Tensorboard. + encryption_spec (google.cloud.aiplatform_v1.types.EncryptionSpec): + Customer-managed encryption key spec for a + Tensorboard. If set, this Tensorboard and all + sub-resources of this Tensorboard will be + secured by this key. + blob_storage_path_prefix (str): + Output only. Consumer project Cloud Storage + path prefix used to store blob data, which can + either be a bucket or directory. Does not end + with a '/'. + run_count (int): + Output only. The number of Runs stored in + this Tensorboard. + create_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp when this Tensorboard + was created. + update_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp when this Tensorboard + was last updated. + labels (Mapping[str, str]): + The labels with user-defined metadata to + organize your Tensorboards. + Label keys and values can be no longer than 64 + characters (Unicode codepoints), can only + contain lowercase letters, numeric characters, + underscores and dashes. International characters + are allowed. No more than 64 user labels can be + associated with one Tensorboard (System labels + are excluded). + + See https://goo.gl/xmQnxf for more information + and examples of labels. System reserved label + keys are prefixed with + "aiplatform.googleapis.com/" and are immutable. + etag (str): + Used to perform a consistent + read-modify-write updates. If not set, a blind + "overwrite" update happens. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + description = proto.Field( + proto.STRING, + number=3, + ) + encryption_spec = proto.Field( + proto.MESSAGE, + number=11, + message=gca_encryption_spec.EncryptionSpec, + ) + blob_storage_path_prefix = proto.Field( + proto.STRING, + number=10, + ) + run_count = proto.Field( + proto.INT32, + number=5, + ) + create_time = proto.Field( + proto.MESSAGE, + number=6, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=7, + message=timestamp_pb2.Timestamp, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=8, + ) + etag = proto.Field( + proto.STRING, + number=9, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/tensorboard_data.py b/google/cloud/aiplatform_v1/types/tensorboard_data.py new file mode 100644 index 0000000000..0e31e0f05b --- /dev/null +++ b/google/cloud/aiplatform_v1/types/tensorboard_data.py @@ -0,0 +1,205 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + +from google.cloud.aiplatform_v1.types import tensorboard_time_series +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "TimeSeriesData", + "TimeSeriesDataPoint", + "Scalar", + "TensorboardTensor", + "TensorboardBlobSequence", + "TensorboardBlob", + }, +) + + +class TimeSeriesData(proto.Message): + r"""All the data stored in a TensorboardTimeSeries. + + Attributes: + tensorboard_time_series_id (str): + Required. The ID of the + TensorboardTimeSeries, which will become the + final component of the TensorboardTimeSeries' + resource name + value_type (google.cloud.aiplatform_v1.types.TensorboardTimeSeries.ValueType): + Required. Immutable. The value type of this + time series. All the values in this time series + data must match this value type. + values (Sequence[google.cloud.aiplatform_v1.types.TimeSeriesDataPoint]): + Required. Data points in this time series. + """ + + tensorboard_time_series_id = proto.Field( + proto.STRING, + number=1, + ) + value_type = proto.Field( + proto.ENUM, + number=2, + enum=tensorboard_time_series.TensorboardTimeSeries.ValueType, + ) + values = proto.RepeatedField( + proto.MESSAGE, + number=3, + message="TimeSeriesDataPoint", + ) + + +class TimeSeriesDataPoint(proto.Message): + r"""A TensorboardTimeSeries data point. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + scalar (google.cloud.aiplatform_v1.types.Scalar): + A scalar value. + + This field is a member of `oneof`_ ``value``. + tensor (google.cloud.aiplatform_v1.types.TensorboardTensor): + A tensor value. + + This field is a member of `oneof`_ ``value``. + blobs (google.cloud.aiplatform_v1.types.TensorboardBlobSequence): + A blob sequence value. + + This field is a member of `oneof`_ ``value``. + wall_time (google.protobuf.timestamp_pb2.Timestamp): + Wall clock timestamp when this data point is + generated by the end user. + step (int): + Step index of this data point within the run. + """ + + scalar = proto.Field( + proto.MESSAGE, + number=3, + oneof="value", + message="Scalar", + ) + tensor = proto.Field( + proto.MESSAGE, + number=4, + oneof="value", + message="TensorboardTensor", + ) + blobs = proto.Field( + proto.MESSAGE, + number=5, + oneof="value", + message="TensorboardBlobSequence", + ) + wall_time = proto.Field( + proto.MESSAGE, + number=1, + message=timestamp_pb2.Timestamp, + ) + step = proto.Field( + proto.INT64, + number=2, + ) + + +class Scalar(proto.Message): + r"""One point viewable on a scalar metric plot. + + Attributes: + value (float): + Value of the point at this step / timestamp. + """ + + value = proto.Field( + proto.DOUBLE, + number=1, + ) + + +class TensorboardTensor(proto.Message): + r"""One point viewable on a tensor metric plot. + + Attributes: + value (bytes): + Required. Serialized form of + https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/framework/tensor.proto + version_number (int): + Optional. Version number of TensorProto used to serialize + [value][google.cloud.aiplatform.v1.TensorboardTensor.value]. + """ + + value = proto.Field( + proto.BYTES, + number=1, + ) + version_number = proto.Field( + proto.INT32, + number=2, + ) + + +class TensorboardBlobSequence(proto.Message): + r"""One point viewable on a blob metric plot, but mostly just a wrapper + message to work around repeated fields can't be used directly within + ``oneof`` fields. + + Attributes: + values (Sequence[google.cloud.aiplatform_v1.types.TensorboardBlob]): + List of blobs contained within the sequence. + """ + + values = proto.RepeatedField( + proto.MESSAGE, + number=1, + message="TensorboardBlob", + ) + + +class TensorboardBlob(proto.Message): + r"""One blob (e.g, image, graph) viewable on a blob metric plot. + + Attributes: + id (str): + Output only. A URI safe key uniquely + identifying a blob. Can be used to locate the + blob stored in the Cloud Storage bucket of the + consumer project. + data (bytes): + Optional. The bytes of the blob is not + present unless it's returned by the + ReadTensorboardBlobData endpoint. + """ + + id = proto.Field( + proto.STRING, + number=1, + ) + data = proto.Field( + proto.BYTES, + number=2, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/tensorboard_experiment.py b/google/cloud/aiplatform_v1/types/tensorboard_experiment.py new file mode 100644 index 0000000000..a4d7d49db2 --- /dev/null +++ b/google/cloud/aiplatform_v1/types/tensorboard_experiment.py @@ -0,0 +1,115 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "TensorboardExperiment", + }, +) + + +class TensorboardExperiment(proto.Message): + r"""A TensorboardExperiment is a group of TensorboardRuns, that + are typically the results of a training job run, in a + Tensorboard. + + Attributes: + name (str): + Output only. Name of the TensorboardExperiment. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` + display_name (str): + User provided name of this + TensorboardExperiment. + description (str): + Description of this TensorboardExperiment. + create_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp when this + TensorboardExperiment was created. + update_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp when this + TensorboardExperiment was last updated. + labels (Mapping[str, str]): + The labels with user-defined metadata to organize your + Datasets. + + Label keys and values can be no longer than 64 characters + (Unicode codepoints), can only contain lowercase letters, + numeric characters, underscores and dashes. International + characters are allowed. No more than 64 user labels can be + associated with one Dataset (System labels are excluded). + + See https://goo.gl/xmQnxf for more information and examples + of labels. System reserved label keys are prefixed with + "aiplatform.googleapis.com/" and are immutable. Following + system labels exist for each Dataset: + + - "aiplatform.googleapis.com/dataset_metadata_schema": + + - output only, its value is the + [metadata_schema's][metadata_schema_uri] title. + etag (str): + Used to perform consistent read-modify-write + updates. If not set, a blind "overwrite" update + happens. + source (str): + Immutable. Source of the + TensorboardExperiment. Example: a custom + training job. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + description = proto.Field( + proto.STRING, + number=3, + ) + create_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=5, + message=timestamp_pb2.Timestamp, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=6, + ) + etag = proto.Field( + proto.STRING, + number=7, + ) + source = proto.Field( + proto.STRING, + number=8, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/tensorboard_run.py b/google/cloud/aiplatform_v1/types/tensorboard_run.py new file mode 100644 index 0000000000..c8ca4bc3be --- /dev/null +++ b/google/cloud/aiplatform_v1/types/tensorboard_run.py @@ -0,0 +1,112 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "TensorboardRun", + }, +) + + +class TensorboardRun(proto.Message): + r"""TensorboardRun maps to a specific execution of a training job + with a given set of hyperparameter values, model definition, + dataset, etc + + Attributes: + name (str): + Output only. Name of the TensorboardRun. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}`` + display_name (str): + Required. User provided name of this + TensorboardRun. This value must be unique among + all TensorboardRuns belonging to the same parent + TensorboardExperiment. + description (str): + Description of this TensorboardRun. + create_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp when this + TensorboardRun was created. + update_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp when this + TensorboardRun was last updated. + labels (Mapping[str, str]): + The labels with user-defined metadata to organize your + TensorboardRuns. + + This field will be used to filter and visualize Runs in the + Tensorboard UI. For example, a Vertex AI training job can + set a label aiplatform.googleapis.com/training_job_id=xxxxx + to all the runs created within that job. An end user can set + a label experiment_id=xxxxx for all the runs produced in a + Jupyter notebook. These runs can be grouped by a label value + and visualized together in the Tensorboard UI. + + Label keys and values can be no longer than 64 characters + (Unicode codepoints), can only contain lowercase letters, + numeric characters, underscores and dashes. International + characters are allowed. No more than 64 user labels can be + associated with one TensorboardRun (System labels are + excluded). + + See https://goo.gl/xmQnxf for more information and examples + of labels. System reserved label keys are prefixed with + "aiplatform.googleapis.com/" and are immutable. + etag (str): + Used to perform a consistent + read-modify-write updates. If not set, a blind + "overwrite" update happens. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + description = proto.Field( + proto.STRING, + number=3, + ) + create_time = proto.Field( + proto.MESSAGE, + number=6, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=7, + message=timestamp_pb2.Timestamp, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=8, + ) + etag = proto.Field( + proto.STRING, + number=9, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/tensorboard_service.py b/google/cloud/aiplatform_v1/types/tensorboard_service.py new file mode 100644 index 0000000000..ccecccb39f --- /dev/null +++ b/google/cloud/aiplatform_v1/types/tensorboard_service.py @@ -0,0 +1,1228 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + +from google.cloud.aiplatform_v1.types import operation +from google.cloud.aiplatform_v1.types import tensorboard as gca_tensorboard +from google.cloud.aiplatform_v1.types import tensorboard_data +from google.cloud.aiplatform_v1.types import ( + tensorboard_experiment as gca_tensorboard_experiment, +) +from google.cloud.aiplatform_v1.types import tensorboard_run as gca_tensorboard_run +from google.cloud.aiplatform_v1.types import ( + tensorboard_time_series as gca_tensorboard_time_series, +) +from google.protobuf import field_mask_pb2 # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "CreateTensorboardRequest", + "GetTensorboardRequest", + "ListTensorboardsRequest", + "ListTensorboardsResponse", + "UpdateTensorboardRequest", + "DeleteTensorboardRequest", + "CreateTensorboardExperimentRequest", + "GetTensorboardExperimentRequest", + "ListTensorboardExperimentsRequest", + "ListTensorboardExperimentsResponse", + "UpdateTensorboardExperimentRequest", + "DeleteTensorboardExperimentRequest", + "BatchCreateTensorboardRunsRequest", + "BatchCreateTensorboardRunsResponse", + "CreateTensorboardRunRequest", + "GetTensorboardRunRequest", + "ReadTensorboardBlobDataRequest", + "ReadTensorboardBlobDataResponse", + "ListTensorboardRunsRequest", + "ListTensorboardRunsResponse", + "UpdateTensorboardRunRequest", + "DeleteTensorboardRunRequest", + "BatchCreateTensorboardTimeSeriesRequest", + "BatchCreateTensorboardTimeSeriesResponse", + "CreateTensorboardTimeSeriesRequest", + "GetTensorboardTimeSeriesRequest", + "ListTensorboardTimeSeriesRequest", + "ListTensorboardTimeSeriesResponse", + "UpdateTensorboardTimeSeriesRequest", + "DeleteTensorboardTimeSeriesRequest", + "BatchReadTensorboardTimeSeriesDataRequest", + "BatchReadTensorboardTimeSeriesDataResponse", + "ReadTensorboardTimeSeriesDataRequest", + "ReadTensorboardTimeSeriesDataResponse", + "WriteTensorboardExperimentDataRequest", + "WriteTensorboardExperimentDataResponse", + "WriteTensorboardRunDataRequest", + "WriteTensorboardRunDataResponse", + "ExportTensorboardTimeSeriesDataRequest", + "ExportTensorboardTimeSeriesDataResponse", + "CreateTensorboardOperationMetadata", + "UpdateTensorboardOperationMetadata", + }, +) + + +class CreateTensorboardRequest(proto.Message): + r"""Request message for + [TensorboardService.CreateTensorboard][google.cloud.aiplatform.v1.TensorboardService.CreateTensorboard]. + + Attributes: + parent (str): + Required. The resource name of the Location to create the + Tensorboard in. Format: + ``projects/{project}/locations/{location}`` + tensorboard (google.cloud.aiplatform_v1.types.Tensorboard): + Required. The Tensorboard to create. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + tensorboard = proto.Field( + proto.MESSAGE, + number=2, + message=gca_tensorboard.Tensorboard, + ) + + +class GetTensorboardRequest(proto.Message): + r"""Request message for + [TensorboardService.GetTensorboard][google.cloud.aiplatform.v1.TensorboardService.GetTensorboard]. + + Attributes: + name (str): + Required. The name of the Tensorboard resource. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class ListTensorboardsRequest(proto.Message): + r"""Request message for + [TensorboardService.ListTensorboards][google.cloud.aiplatform.v1.TensorboardService.ListTensorboards]. + + Attributes: + parent (str): + Required. The resource name of the Location to list + Tensorboards. Format: + ``projects/{project}/locations/{location}`` + filter (str): + Lists the Tensorboards that match the filter + expression. + page_size (int): + The maximum number of Tensorboards to return. + The service may return fewer than this value. If + unspecified, at most 100 Tensorboards will be + returned. The maximum value is 100; values above + 100 will be coerced to 100. + page_token (str): + A page token, received from a previous + [TensorboardService.ListTensorboards][google.cloud.aiplatform.v1.TensorboardService.ListTensorboards] + call. Provide this to retrieve the subsequent page. + + When paginating, all other parameters provided to + [TensorboardService.ListTensorboards][google.cloud.aiplatform.v1.TensorboardService.ListTensorboards] + must match the call that provided the page token. + order_by (str): + Field to use to sort the list. + read_mask (google.protobuf.field_mask_pb2.FieldMask): + Mask specifying which fields to read. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + order_by = proto.Field( + proto.STRING, + number=5, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=6, + message=field_mask_pb2.FieldMask, + ) + + +class ListTensorboardsResponse(proto.Message): + r"""Response message for + [TensorboardService.ListTensorboards][google.cloud.aiplatform.v1.TensorboardService.ListTensorboards]. + + Attributes: + tensorboards (Sequence[google.cloud.aiplatform_v1.types.Tensorboard]): + The Tensorboards mathching the request. + next_page_token (str): + A token, which can be sent as + [ListTensorboardsRequest.page_token][google.cloud.aiplatform.v1.ListTensorboardsRequest.page_token] + to retrieve the next page. If this field is omitted, there + are no subsequent pages. + """ + + @property + def raw_page(self): + return self + + tensorboards = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gca_tensorboard.Tensorboard, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) + + +class UpdateTensorboardRequest(proto.Message): + r"""Request message for + [TensorboardService.UpdateTensorboard][google.cloud.aiplatform.v1.TensorboardService.UpdateTensorboard]. + + Attributes: + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Required. Field mask is used to specify the fields to be + overwritten in the Tensorboard resource by the update. The + fields specified in the update_mask are relative to the + resource, not the full request. A field will be overwritten + if it is in the mask. If the user does not provide a mask + then all fields will be overwritten if new values are + specified. + tensorboard (google.cloud.aiplatform_v1.types.Tensorboard): + Required. The Tensorboard's ``name`` field is used to + identify the Tensorboard to be updated. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}`` + """ + + update_mask = proto.Field( + proto.MESSAGE, + number=1, + message=field_mask_pb2.FieldMask, + ) + tensorboard = proto.Field( + proto.MESSAGE, + number=2, + message=gca_tensorboard.Tensorboard, + ) + + +class DeleteTensorboardRequest(proto.Message): + r"""Request message for + [TensorboardService.DeleteTensorboard][google.cloud.aiplatform.v1.TensorboardService.DeleteTensorboard]. + + Attributes: + name (str): + Required. The name of the Tensorboard to be deleted. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class CreateTensorboardExperimentRequest(proto.Message): + r"""Request message for + [TensorboardService.CreateTensorboardExperiment][google.cloud.aiplatform.v1.TensorboardService.CreateTensorboardExperiment]. + + Attributes: + parent (str): + Required. The resource name of the Tensorboard to create the + TensorboardExperiment in. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}`` + tensorboard_experiment (google.cloud.aiplatform_v1.types.TensorboardExperiment): + The TensorboardExperiment to create. + tensorboard_experiment_id (str): + Required. The ID to use for the Tensorboard experiment, + which will become the final component of the Tensorboard + experiment's resource name. + + This value should be 1-128 characters, and valid characters + are /[a-z][0-9]-/. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + tensorboard_experiment = proto.Field( + proto.MESSAGE, + number=2, + message=gca_tensorboard_experiment.TensorboardExperiment, + ) + tensorboard_experiment_id = proto.Field( + proto.STRING, + number=3, + ) + + +class GetTensorboardExperimentRequest(proto.Message): + r"""Request message for + [TensorboardService.GetTensorboardExperiment][google.cloud.aiplatform.v1.TensorboardService.GetTensorboardExperiment]. + + Attributes: + name (str): + Required. The name of the TensorboardExperiment resource. + Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class ListTensorboardExperimentsRequest(proto.Message): + r"""Request message for + [TensorboardService.ListTensorboardExperiments][google.cloud.aiplatform.v1.TensorboardService.ListTensorboardExperiments]. + + Attributes: + parent (str): + Required. The resource name of the + Tensorboard to list TensorboardExperiments. + Format: + 'projects/{project}/locations/{location}/tensorboards/{tensorboard}' + filter (str): + Lists the TensorboardExperiments that match + the filter expression. + page_size (int): + The maximum number of TensorboardExperiments + to return. The service may return fewer than + this value. If unspecified, at most 50 + TensorboardExperiments will be returned. The + maximum value is 1000; values above 1000 will be + coerced to 1000. + page_token (str): + A page token, received from a previous + [TensorboardService.ListTensorboardExperiments][google.cloud.aiplatform.v1.TensorboardService.ListTensorboardExperiments] + call. Provide this to retrieve the subsequent page. + + When paginating, all other parameters provided to + [TensorboardService.ListTensorboardExperiments][google.cloud.aiplatform.v1.TensorboardService.ListTensorboardExperiments] + must match the call that provided the page token. + order_by (str): + Field to use to sort the list. + read_mask (google.protobuf.field_mask_pb2.FieldMask): + Mask specifying which fields to read. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + order_by = proto.Field( + proto.STRING, + number=5, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=6, + message=field_mask_pb2.FieldMask, + ) + + +class ListTensorboardExperimentsResponse(proto.Message): + r"""Response message for + [TensorboardService.ListTensorboardExperiments][google.cloud.aiplatform.v1.TensorboardService.ListTensorboardExperiments]. + + Attributes: + tensorboard_experiments (Sequence[google.cloud.aiplatform_v1.types.TensorboardExperiment]): + The TensorboardExperiments mathching the + request. + next_page_token (str): + A token, which can be sent as + [ListTensorboardExperimentsRequest.page_token][google.cloud.aiplatform.v1.ListTensorboardExperimentsRequest.page_token] + to retrieve the next page. If this field is omitted, there + are no subsequent pages. + """ + + @property + def raw_page(self): + return self + + tensorboard_experiments = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gca_tensorboard_experiment.TensorboardExperiment, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) + + +class UpdateTensorboardExperimentRequest(proto.Message): + r"""Request message for + [TensorboardService.UpdateTensorboardExperiment][google.cloud.aiplatform.v1.TensorboardService.UpdateTensorboardExperiment]. + + Attributes: + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Required. Field mask is used to specify the fields to be + overwritten in the TensorboardExperiment resource by the + update. The fields specified in the update_mask are relative + to the resource, not the full request. A field will be + overwritten if it is in the mask. If the user does not + provide a mask then all fields will be overwritten if new + values are specified. + tensorboard_experiment (google.cloud.aiplatform_v1.types.TensorboardExperiment): + Required. The TensorboardExperiment's ``name`` field is used + to identify the TensorboardExperiment to be updated. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` + """ + + update_mask = proto.Field( + proto.MESSAGE, + number=1, + message=field_mask_pb2.FieldMask, + ) + tensorboard_experiment = proto.Field( + proto.MESSAGE, + number=2, + message=gca_tensorboard_experiment.TensorboardExperiment, + ) + + +class DeleteTensorboardExperimentRequest(proto.Message): + r"""Request message for + [TensorboardService.DeleteTensorboardExperiment][google.cloud.aiplatform.v1.TensorboardService.DeleteTensorboardExperiment]. + + Attributes: + name (str): + Required. The name of the TensorboardExperiment to be + deleted. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class BatchCreateTensorboardRunsRequest(proto.Message): + r"""Request message for + [TensorboardService.BatchCreateTensorboardRuns][google.cloud.aiplatform.v1.TensorboardService.BatchCreateTensorboardRuns]. + + Attributes: + parent (str): + Required. The resource name of the TensorboardExperiment to + create the TensorboardRuns in. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` + The parent field in the CreateTensorboardRunRequest messages + must match this field. + requests (Sequence[google.cloud.aiplatform_v1.types.CreateTensorboardRunRequest]): + Required. The request message specifying the + TensorboardRuns to create. A maximum of 1000 + TensorboardRuns can be created in a batch. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + requests = proto.RepeatedField( + proto.MESSAGE, + number=2, + message="CreateTensorboardRunRequest", + ) + + +class BatchCreateTensorboardRunsResponse(proto.Message): + r"""Response message for + [TensorboardService.BatchCreateTensorboardRuns][google.cloud.aiplatform.v1.TensorboardService.BatchCreateTensorboardRuns]. + + Attributes: + tensorboard_runs (Sequence[google.cloud.aiplatform_v1.types.TensorboardRun]): + The created TensorboardRuns. + """ + + tensorboard_runs = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gca_tensorboard_run.TensorboardRun, + ) + + +class CreateTensorboardRunRequest(proto.Message): + r"""Request message for + [TensorboardService.CreateTensorboardRun][google.cloud.aiplatform.v1.TensorboardService.CreateTensorboardRun]. + + Attributes: + parent (str): + Required. The resource name of the TensorboardExperiment to + create the TensorboardRun in. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` + tensorboard_run (google.cloud.aiplatform_v1.types.TensorboardRun): + Required. The TensorboardRun to create. + tensorboard_run_id (str): + Required. The ID to use for the Tensorboard run, which will + become the final component of the Tensorboard run's resource + name. + + This value should be 1-128 characters, and valid characters + are /[a-z][0-9]-/. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + tensorboard_run = proto.Field( + proto.MESSAGE, + number=2, + message=gca_tensorboard_run.TensorboardRun, + ) + tensorboard_run_id = proto.Field( + proto.STRING, + number=3, + ) + + +class GetTensorboardRunRequest(proto.Message): + r"""Request message for + [TensorboardService.GetTensorboardRun][google.cloud.aiplatform.v1.TensorboardService.GetTensorboardRun]. + + Attributes: + name (str): + Required. The name of the TensorboardRun resource. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class ReadTensorboardBlobDataRequest(proto.Message): + r"""Request message for + [TensorboardService.ReadTensorboardBlobData][google.cloud.aiplatform.v1.TensorboardService.ReadTensorboardBlobData]. + + Attributes: + time_series (str): + Required. The resource name of the TensorboardTimeSeries to + list Blobs. Format: + 'projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}/timeSeries/{time_series}' + blob_ids (Sequence[str]): + IDs of the blobs to read. + """ + + time_series = proto.Field( + proto.STRING, + number=1, + ) + blob_ids = proto.RepeatedField( + proto.STRING, + number=2, + ) + + +class ReadTensorboardBlobDataResponse(proto.Message): + r"""Response message for + [TensorboardService.ReadTensorboardBlobData][google.cloud.aiplatform.v1.TensorboardService.ReadTensorboardBlobData]. + + Attributes: + blobs (Sequence[google.cloud.aiplatform_v1.types.TensorboardBlob]): + Blob messages containing blob bytes. + """ + + blobs = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=tensorboard_data.TensorboardBlob, + ) + + +class ListTensorboardRunsRequest(proto.Message): + r"""Request message for + [TensorboardService.ListTensorboardRuns][google.cloud.aiplatform.v1.TensorboardService.ListTensorboardRuns]. + + Attributes: + parent (str): + Required. The resource name of the + TensorboardExperiment to list TensorboardRuns. + Format: + 'projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}' + filter (str): + Lists the TensorboardRuns that match the + filter expression. + page_size (int): + The maximum number of TensorboardRuns to + return. The service may return fewer than this + value. If unspecified, at most 50 + TensorboardRuns will be returned. The maximum + value is 1000; values above 1000 will be coerced + to 1000. + page_token (str): + A page token, received from a previous + [TensorboardService.ListTensorboardRuns][google.cloud.aiplatform.v1.TensorboardService.ListTensorboardRuns] + call. Provide this to retrieve the subsequent page. + + When paginating, all other parameters provided to + [TensorboardService.ListTensorboardRuns][google.cloud.aiplatform.v1.TensorboardService.ListTensorboardRuns] + must match the call that provided the page token. + order_by (str): + Field to use to sort the list. + read_mask (google.protobuf.field_mask_pb2.FieldMask): + Mask specifying which fields to read. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + order_by = proto.Field( + proto.STRING, + number=5, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=6, + message=field_mask_pb2.FieldMask, + ) + + +class ListTensorboardRunsResponse(proto.Message): + r"""Response message for + [TensorboardService.ListTensorboardRuns][google.cloud.aiplatform.v1.TensorboardService.ListTensorboardRuns]. + + Attributes: + tensorboard_runs (Sequence[google.cloud.aiplatform_v1.types.TensorboardRun]): + The TensorboardRuns mathching the request. + next_page_token (str): + A token, which can be sent as + [ListTensorboardRunsRequest.page_token][google.cloud.aiplatform.v1.ListTensorboardRunsRequest.page_token] + to retrieve the next page. If this field is omitted, there + are no subsequent pages. + """ + + @property + def raw_page(self): + return self + + tensorboard_runs = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gca_tensorboard_run.TensorboardRun, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) + + +class UpdateTensorboardRunRequest(proto.Message): + r"""Request message for + [TensorboardService.UpdateTensorboardRun][google.cloud.aiplatform.v1.TensorboardService.UpdateTensorboardRun]. + + Attributes: + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Required. Field mask is used to specify the fields to be + overwritten in the TensorboardRun resource by the update. + The fields specified in the update_mask are relative to the + resource, not the full request. A field will be overwritten + if it is in the mask. If the user does not provide a mask + then all fields will be overwritten if new values are + specified. + tensorboard_run (google.cloud.aiplatform_v1.types.TensorboardRun): + Required. The TensorboardRun's ``name`` field is used to + identify the TensorboardRun to be updated. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}`` + """ + + update_mask = proto.Field( + proto.MESSAGE, + number=1, + message=field_mask_pb2.FieldMask, + ) + tensorboard_run = proto.Field( + proto.MESSAGE, + number=2, + message=gca_tensorboard_run.TensorboardRun, + ) + + +class DeleteTensorboardRunRequest(proto.Message): + r"""Request message for + [TensorboardService.DeleteTensorboardRun][google.cloud.aiplatform.v1.TensorboardService.DeleteTensorboardRun]. + + Attributes: + name (str): + Required. The name of the TensorboardRun to be deleted. + Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class BatchCreateTensorboardTimeSeriesRequest(proto.Message): + r"""Request message for + [TensorboardService.BatchCreateTensorboardTimeSeries][google.cloud.aiplatform.v1.TensorboardService.BatchCreateTensorboardTimeSeries]. + + Attributes: + parent (str): + Required. The resource name of the TensorboardExperiment to + create the TensorboardTimeSeries in. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` + The TensorboardRuns referenced by the parent fields in the + CreateTensorboardTimeSeriesRequest messages must be sub + resources of this TensorboardExperiment. + requests (Sequence[google.cloud.aiplatform_v1.types.CreateTensorboardTimeSeriesRequest]): + Required. The request message specifying the + TensorboardTimeSeries to create. A maximum of + 1000 TensorboardTimeSeries can be created in a + batch. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + requests = proto.RepeatedField( + proto.MESSAGE, + number=2, + message="CreateTensorboardTimeSeriesRequest", + ) + + +class BatchCreateTensorboardTimeSeriesResponse(proto.Message): + r"""Response message for + [TensorboardService.BatchCreateTensorboardTimeSeries][google.cloud.aiplatform.v1.TensorboardService.BatchCreateTensorboardTimeSeries]. + + Attributes: + tensorboard_time_series (Sequence[google.cloud.aiplatform_v1.types.TensorboardTimeSeries]): + The created TensorboardTimeSeries. + """ + + tensorboard_time_series = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gca_tensorboard_time_series.TensorboardTimeSeries, + ) + + +class CreateTensorboardTimeSeriesRequest(proto.Message): + r"""Request message for + [TensorboardService.CreateTensorboardTimeSeries][google.cloud.aiplatform.v1.TensorboardService.CreateTensorboardTimeSeries]. + + Attributes: + parent (str): + Required. The resource name of the TensorboardRun to create + the TensorboardTimeSeries in. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}`` + tensorboard_time_series_id (str): + Optional. The user specified unique ID to use for the + TensorboardTimeSeries, which will become the final component + of the TensorboardTimeSeries's resource name. This value + should match "[a-z0-9][a-z0-9-]{0, 127}". + tensorboard_time_series (google.cloud.aiplatform_v1.types.TensorboardTimeSeries): + Required. The TensorboardTimeSeries to + create. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + tensorboard_time_series_id = proto.Field( + proto.STRING, + number=3, + ) + tensorboard_time_series = proto.Field( + proto.MESSAGE, + number=2, + message=gca_tensorboard_time_series.TensorboardTimeSeries, + ) + + +class GetTensorboardTimeSeriesRequest(proto.Message): + r"""Request message for + [TensorboardService.GetTensorboardTimeSeries][google.cloud.aiplatform.v1.TensorboardService.GetTensorboardTimeSeries]. + + Attributes: + name (str): + Required. The name of the TensorboardTimeSeries resource. + Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}/timeSeries/{time_series}`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class ListTensorboardTimeSeriesRequest(proto.Message): + r"""Request message for + [TensorboardService.ListTensorboardTimeSeries][google.cloud.aiplatform.v1.TensorboardService.ListTensorboardTimeSeries]. + + Attributes: + parent (str): + Required. The resource name of the + TensorboardRun to list TensorboardTimeSeries. + Format: + 'projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}' + filter (str): + Lists the TensorboardTimeSeries that match + the filter expression. + page_size (int): + The maximum number of TensorboardTimeSeries + to return. The service may return fewer than + this value. If unspecified, at most 50 + TensorboardTimeSeries will be returned. The + maximum value is 1000; values above 1000 will be + coerced to 1000. + page_token (str): + A page token, received from a previous + [TensorboardService.ListTensorboardTimeSeries][google.cloud.aiplatform.v1.TensorboardService.ListTensorboardTimeSeries] + call. Provide this to retrieve the subsequent page. + + When paginating, all other parameters provided to + [TensorboardService.ListTensorboardTimeSeries][google.cloud.aiplatform.v1.TensorboardService.ListTensorboardTimeSeries] + must match the call that provided the page token. + order_by (str): + Field to use to sort the list. + read_mask (google.protobuf.field_mask_pb2.FieldMask): + Mask specifying which fields to read. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + order_by = proto.Field( + proto.STRING, + number=5, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=6, + message=field_mask_pb2.FieldMask, + ) + + +class ListTensorboardTimeSeriesResponse(proto.Message): + r"""Response message for + [TensorboardService.ListTensorboardTimeSeries][google.cloud.aiplatform.v1.TensorboardService.ListTensorboardTimeSeries]. + + Attributes: + tensorboard_time_series (Sequence[google.cloud.aiplatform_v1.types.TensorboardTimeSeries]): + The TensorboardTimeSeries mathching the + request. + next_page_token (str): + A token, which can be sent as + [ListTensorboardTimeSeriesRequest.page_token][google.cloud.aiplatform.v1.ListTensorboardTimeSeriesRequest.page_token] + to retrieve the next page. If this field is omitted, there + are no subsequent pages. + """ + + @property + def raw_page(self): + return self + + tensorboard_time_series = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gca_tensorboard_time_series.TensorboardTimeSeries, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) + + +class UpdateTensorboardTimeSeriesRequest(proto.Message): + r"""Request message for + [TensorboardService.UpdateTensorboardTimeSeries][google.cloud.aiplatform.v1.TensorboardService.UpdateTensorboardTimeSeries]. + + Attributes: + update_mask (google.protobuf.field_mask_pb2.FieldMask): + Required. Field mask is used to specify the fields to be + overwritten in the TensorboardTimeSeries resource by the + update. The fields specified in the update_mask are relative + to the resource, not the full request. A field will be + overwritten if it is in the mask. If the user does not + provide a mask then all fields will be overwritten if new + values are specified. + tensorboard_time_series (google.cloud.aiplatform_v1.types.TensorboardTimeSeries): + Required. The TensorboardTimeSeries' ``name`` field is used + to identify the TensorboardTimeSeries to be updated. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}/timeSeries/{time_series}`` + """ + + update_mask = proto.Field( + proto.MESSAGE, + number=1, + message=field_mask_pb2.FieldMask, + ) + tensorboard_time_series = proto.Field( + proto.MESSAGE, + number=2, + message=gca_tensorboard_time_series.TensorboardTimeSeries, + ) + + +class DeleteTensorboardTimeSeriesRequest(proto.Message): + r"""Request message for + [TensorboardService.DeleteTensorboardTimeSeries][google.cloud.aiplatform.v1.TensorboardService.DeleteTensorboardTimeSeries]. + + Attributes: + name (str): + Required. The name of the TensorboardTimeSeries to be + deleted. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}/timeSeries/{time_series}`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class BatchReadTensorboardTimeSeriesDataRequest(proto.Message): + r"""Request message for + [TensorboardService.BatchReadTensorboardTimeSeriesData][google.cloud.aiplatform.v1.TensorboardService.BatchReadTensorboardTimeSeriesData]. + + Attributes: + tensorboard (str): + Required. The resource name of the Tensorboard containing + TensorboardTimeSeries to read data from. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}``. + The TensorboardTimeSeries referenced by + [time_series][google.cloud.aiplatform.v1.BatchReadTensorboardTimeSeriesDataRequest.time_series] + must be sub resources of this Tensorboard. + time_series (Sequence[str]): + Required. The resource names of the TensorboardTimeSeries to + read data from. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}/timeSeries/{time_series}`` + """ + + tensorboard = proto.Field( + proto.STRING, + number=1, + ) + time_series = proto.RepeatedField( + proto.STRING, + number=2, + ) + + +class BatchReadTensorboardTimeSeriesDataResponse(proto.Message): + r"""Response message for + [TensorboardService.BatchReadTensorboardTimeSeriesData][google.cloud.aiplatform.v1.TensorboardService.BatchReadTensorboardTimeSeriesData]. + + Attributes: + time_series_data (Sequence[google.cloud.aiplatform_v1.types.TimeSeriesData]): + The returned time series data. + """ + + time_series_data = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=tensorboard_data.TimeSeriesData, + ) + + +class ReadTensorboardTimeSeriesDataRequest(proto.Message): + r"""Request message for + [TensorboardService.ReadTensorboardTimeSeriesData][google.cloud.aiplatform.v1.TensorboardService.ReadTensorboardTimeSeriesData]. + + Attributes: + tensorboard_time_series (str): + Required. The resource name of the TensorboardTimeSeries to + read data from. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}/timeSeries/{time_series}`` + max_data_points (int): + The maximum number of TensorboardTimeSeries' + data to return. + This value should be a positive integer. + This value can be set to -1 to return all data. + filter (str): + Reads the TensorboardTimeSeries' data that + match the filter expression. + """ + + tensorboard_time_series = proto.Field( + proto.STRING, + number=1, + ) + max_data_points = proto.Field( + proto.INT32, + number=2, + ) + filter = proto.Field( + proto.STRING, + number=3, + ) + + +class ReadTensorboardTimeSeriesDataResponse(proto.Message): + r"""Response message for + [TensorboardService.ReadTensorboardTimeSeriesData][google.cloud.aiplatform.v1.TensorboardService.ReadTensorboardTimeSeriesData]. + + Attributes: + time_series_data (google.cloud.aiplatform_v1.types.TimeSeriesData): + The returned time series data. + """ + + time_series_data = proto.Field( + proto.MESSAGE, + number=1, + message=tensorboard_data.TimeSeriesData, + ) + + +class WriteTensorboardExperimentDataRequest(proto.Message): + r"""Request message for + [TensorboardService.WriteTensorboardExperimentData][google.cloud.aiplatform.v1.TensorboardService.WriteTensorboardExperimentData]. + + Attributes: + tensorboard_experiment (str): + Required. The resource name of the TensorboardExperiment to + write data to. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` + write_run_data_requests (Sequence[google.cloud.aiplatform_v1.types.WriteTensorboardRunDataRequest]): + Required. Requests containing per-run + TensorboardTimeSeries data to write. + """ + + tensorboard_experiment = proto.Field( + proto.STRING, + number=1, + ) + write_run_data_requests = proto.RepeatedField( + proto.MESSAGE, + number=2, + message="WriteTensorboardRunDataRequest", + ) + + +class WriteTensorboardExperimentDataResponse(proto.Message): + r"""Response message for + [TensorboardService.WriteTensorboardExperimentData][google.cloud.aiplatform.v1.TensorboardService.WriteTensorboardExperimentData]. + + """ + + +class WriteTensorboardRunDataRequest(proto.Message): + r"""Request message for + [TensorboardService.WriteTensorboardRunData][google.cloud.aiplatform.v1.TensorboardService.WriteTensorboardRunData]. + + Attributes: + tensorboard_run (str): + Required. The resource name of the TensorboardRun to write + data to. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}`` + time_series_data (Sequence[google.cloud.aiplatform_v1.types.TimeSeriesData]): + Required. The TensorboardTimeSeries data to + write. Values with in a time series are indexed + by their step value. Repeated writes to the same + step will overwrite the existing value for that + step. + The upper limit of data points per write request + is 5000. + """ + + tensorboard_run = proto.Field( + proto.STRING, + number=1, + ) + time_series_data = proto.RepeatedField( + proto.MESSAGE, + number=2, + message=tensorboard_data.TimeSeriesData, + ) + + +class WriteTensorboardRunDataResponse(proto.Message): + r"""Response message for + [TensorboardService.WriteTensorboardRunData][google.cloud.aiplatform.v1.TensorboardService.WriteTensorboardRunData]. + + """ + + +class ExportTensorboardTimeSeriesDataRequest(proto.Message): + r"""Request message for + [TensorboardService.ExportTensorboardTimeSeriesData][google.cloud.aiplatform.v1.TensorboardService.ExportTensorboardTimeSeriesData]. + + Attributes: + tensorboard_time_series (str): + Required. The resource name of the TensorboardTimeSeries to + export data from. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}/timeSeries/{time_series}`` + filter (str): + Exports the TensorboardTimeSeries' data that + match the filter expression. + page_size (int): + The maximum number of data points to return per page. The + default page_size will be 1000. Values must be between 1 and + 10000. Values above 10000 will be coerced to 10000. + page_token (str): + A page token, received from a previous + [TensorboardService.ExportTensorboardTimeSeries][] call. + Provide this to retrieve the subsequent page. + + When paginating, all other parameters provided to + [TensorboardService.ExportTensorboardTimeSeries][] must + match the call that provided the page token. + order_by (str): + Field to use to sort the + TensorboardTimeSeries' data. By default, + TensorboardTimeSeries' data will be returned in + a pseudo random order. + """ + + tensorboard_time_series = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + order_by = proto.Field( + proto.STRING, + number=5, + ) + + +class ExportTensorboardTimeSeriesDataResponse(proto.Message): + r"""Response message for + [TensorboardService.ExportTensorboardTimeSeriesData][google.cloud.aiplatform.v1.TensorboardService.ExportTensorboardTimeSeriesData]. + + Attributes: + time_series_data_points (Sequence[google.cloud.aiplatform_v1.types.TimeSeriesDataPoint]): + The returned time series data points. + next_page_token (str): + A token, which can be sent as + [ExportTensorboardTimeSeriesRequest.page_token][] to + retrieve the next page. If this field is omitted, there are + no subsequent pages. + """ + + @property + def raw_page(self): + return self + + time_series_data_points = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=tensorboard_data.TimeSeriesDataPoint, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) + + +class CreateTensorboardOperationMetadata(proto.Message): + r"""Details of operations that perform create Tensorboard. + + Attributes: + generic_metadata (google.cloud.aiplatform_v1.types.GenericOperationMetadata): + Operation metadata for Tensorboard. + """ + + generic_metadata = proto.Field( + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, + ) + + +class UpdateTensorboardOperationMetadata(proto.Message): + r"""Details of operations that perform update Tensorboard. + + Attributes: + generic_metadata (google.cloud.aiplatform_v1.types.GenericOperationMetadata): + Operation metadata for Tensorboard. + """ + + generic_metadata = proto.Field( + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/tensorboard_time_series.py b/google/cloud/aiplatform_v1/types/tensorboard_time_series.py new file mode 100644 index 0000000000..80d4bcd1b7 --- /dev/null +++ b/google/cloud/aiplatform_v1/types/tensorboard_time_series.py @@ -0,0 +1,154 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "TensorboardTimeSeries", + }, +) + + +class TensorboardTimeSeries(proto.Message): + r"""TensorboardTimeSeries maps to times series produced in + training runs + + Attributes: + name (str): + Output only. Name of the + TensorboardTimeSeries. + display_name (str): + Required. User provided name of this + TensorboardTimeSeries. This value should be + unique among all TensorboardTimeSeries resources + belonging to the same TensorboardRun resource + (parent resource). + description (str): + Description of this TensorboardTimeSeries. + value_type (google.cloud.aiplatform_v1.types.TensorboardTimeSeries.ValueType): + Required. Immutable. Type of + TensorboardTimeSeries value. + create_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp when this + TensorboardTimeSeries was created. + update_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp when this + TensorboardTimeSeries was last updated. + etag (str): + Used to perform a consistent + read-modify-write updates. If not set, a blind + "overwrite" update happens. + plugin_name (str): + Immutable. Name of the plugin this time + series pertain to. Such as Scalar, Tensor, Blob + plugin_data (bytes): + Data of the current plugin, with the size + limited to 65KB. + metadata (google.cloud.aiplatform_v1.types.TensorboardTimeSeries.Metadata): + Output only. Scalar, Tensor, or Blob metadata + for this TensorboardTimeSeries. + """ + + class ValueType(proto.Enum): + r"""An enum representing the value type of a + TensorboardTimeSeries. + """ + VALUE_TYPE_UNSPECIFIED = 0 + SCALAR = 1 + TENSOR = 2 + BLOB_SEQUENCE = 3 + + class Metadata(proto.Message): + r"""Describes metadata for a TensorboardTimeSeries. + + Attributes: + max_step (int): + Output only. Max step index of all data + points within a TensorboardTimeSeries. + max_wall_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Max wall clock timestamp of all + data points within a TensorboardTimeSeries. + max_blob_sequence_length (int): + Output only. The largest blob sequence length (number of + blobs) of all data points in this time series, if its + ValueType is BLOB_SEQUENCE. + """ + + max_step = proto.Field( + proto.INT64, + number=1, + ) + max_wall_time = proto.Field( + proto.MESSAGE, + number=2, + message=timestamp_pb2.Timestamp, + ) + max_blob_sequence_length = proto.Field( + proto.INT64, + number=3, + ) + + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + description = proto.Field( + proto.STRING, + number=3, + ) + value_type = proto.Field( + proto.ENUM, + number=4, + enum=ValueType, + ) + create_time = proto.Field( + proto.MESSAGE, + number=5, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=6, + message=timestamp_pb2.Timestamp, + ) + etag = proto.Field( + proto.STRING, + number=7, + ) + plugin_name = proto.Field( + proto.STRING, + number=8, + ) + plugin_data = proto.Field( + proto.BYTES, + number=9, + ) + metadata = proto.Field( + proto.MESSAGE, + number=10, + message=Metadata, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/training_pipeline.py b/google/cloud/aiplatform_v1/types/training_pipeline.py index acd18f7b2e..288cdbe9dd 100644 --- a/google/cloud/aiplatform_v1/types/training_pipeline.py +++ b/google/cloud/aiplatform_v1/types/training_pipeline.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -33,6 +33,7 @@ "FilterSplit", "PredefinedSplit", "TimestampSplit", + "StratifiedSplit", }, ) @@ -40,9 +41,9 @@ class TrainingPipeline(proto.Message): r"""The TrainingPipeline orchestrates tasks associated with training a Model. It always executes the training task, and optionally may also - export data from AI Platform's Dataset which becomes the training + export data from Vertex AI's Dataset which becomes the training input, [upload][google.cloud.aiplatform.v1.ModelService.UploadModel] - the Model to AI Platform, and evaluate the Model. + the Model to Vertex AI, and evaluate the Model. Attributes: name (str): @@ -52,7 +53,7 @@ class TrainingPipeline(proto.Message): Required. The user-defined name of this TrainingPipeline. input_data_config (google.cloud.aiplatform_v1.types.InputDataConfig): - Specifies AI Platform owned input data that may be used for + Specifies Vertex AI owned input data that may be used for training the Model. The TrainingPipeline's [training_task_definition][google.cloud.aiplatform.v1.TrainingPipeline.training_task_definition] should make clear whether this config is used and if there @@ -67,13 +68,13 @@ class TrainingPipeline(proto.Message): is responsible for producing the model artifact, and may also include additional auxiliary work. The definition files that can be used here are - found in gs://google-cloud- - aiplatform/schema/trainingjob/definition/. Note: - The URI given on output will be immutable and - probably different, including the URI scheme, - than the one given on input. The output URI will - point to a location where the user only has a - read access. + found in + gs://google-cloud-aiplatform/schema/trainingjob/definition/. + Note: The URI given on output will be immutable + and probably different, including the URI + scheme, than the one given on input. The output + URI will point to a location where the user only + has a read access. training_task_inputs (google.protobuf.struct_pb2.Value): Required. The training task's parameter(s), as specified in the @@ -104,10 +105,21 @@ class TrainingPipeline(proto.Message): does not support uploading a Model as part of the pipeline. When the Pipeline's state becomes ``PIPELINE_STATE_SUCCEEDED`` and the trained Model had been - uploaded into AI Platform, then the model_to_upload's - resource [name][google.cloud.aiplatform.v1.Model.name] is - populated. The Model is always uploaded into the Project and - Location in which this pipeline is. + uploaded into Vertex AI, then the model_to_upload's resource + [name][google.cloud.aiplatform.v1.Model.name] is populated. + The Model is always uploaded into the Project and Location + in which this pipeline is. + model_id (str): + Optional. The ID to use for the uploaded Model, which will + become the final component of the model resource name. + + This value may be up to 63 characters, and valid characters + are ``[a-z0-9_-]``. The first character cannot be a number + or hyphen. + parent_model (str): + Optional. When specify this field, the ``model_to_upload`` + will not be uploaded as a new model, instead, it will become + a new version of this ``parent_model``. state (google.cloud.aiplatform_v1.types.PipelineState): Output only. The detailed state of the pipeline. @@ -127,7 +139,7 @@ class TrainingPipeline(proto.Message): update_time (google.protobuf.timestamp_pb2.Timestamp): Output only. Time when the TrainingPipeline was most recently updated. - labels (Sequence[google.cloud.aiplatform_v1.types.TrainingPipeline.LabelsEntry]): + labels (Mapping[str, str]): The labels with user-defined metadata to organize TrainingPipelines. Label keys and values can be no longer than 64 @@ -147,51 +159,127 @@ class TrainingPipeline(proto.Message): is not set separately. """ - name = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) - input_data_config = proto.Field(proto.MESSAGE, number=3, message="InputDataConfig",) - training_task_definition = proto.Field(proto.STRING, number=4,) + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + input_data_config = proto.Field( + proto.MESSAGE, + number=3, + message="InputDataConfig", + ) + training_task_definition = proto.Field( + proto.STRING, + number=4, + ) training_task_inputs = proto.Field( - proto.MESSAGE, number=5, message=struct_pb2.Value, + proto.MESSAGE, + number=5, + message=struct_pb2.Value, ) training_task_metadata = proto.Field( - proto.MESSAGE, number=6, message=struct_pb2.Value, + proto.MESSAGE, + number=6, + message=struct_pb2.Value, + ) + model_to_upload = proto.Field( + proto.MESSAGE, + number=7, + message=model.Model, + ) + model_id = proto.Field( + proto.STRING, + number=22, + ) + parent_model = proto.Field( + proto.STRING, + number=21, + ) + state = proto.Field( + proto.ENUM, + number=9, + enum=pipeline_state.PipelineState, + ) + error = proto.Field( + proto.MESSAGE, + number=10, + message=status_pb2.Status, ) - model_to_upload = proto.Field(proto.MESSAGE, number=7, message=model.Model,) - state = proto.Field(proto.ENUM, number=9, enum=pipeline_state.PipelineState,) - error = proto.Field(proto.MESSAGE, number=10, message=status_pb2.Status,) create_time = proto.Field( - proto.MESSAGE, number=11, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=11, + message=timestamp_pb2.Timestamp, + ) + start_time = proto.Field( + proto.MESSAGE, + number=12, + message=timestamp_pb2.Timestamp, + ) + end_time = proto.Field( + proto.MESSAGE, + number=13, + message=timestamp_pb2.Timestamp, ) - start_time = proto.Field(proto.MESSAGE, number=12, message=timestamp_pb2.Timestamp,) - end_time = proto.Field(proto.MESSAGE, number=13, message=timestamp_pb2.Timestamp,) update_time = proto.Field( - proto.MESSAGE, number=14, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=14, + message=timestamp_pb2.Timestamp, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=15, ) - labels = proto.MapField(proto.STRING, proto.STRING, number=15,) encryption_spec = proto.Field( - proto.MESSAGE, number=18, message=gca_encryption_spec.EncryptionSpec, + proto.MESSAGE, + number=18, + message=gca_encryption_spec.EncryptionSpec, ) class InputDataConfig(proto.Message): - r"""Specifies AI Platform owned input data to be used for - training, and possibly evaluating, the Model. + r"""Specifies Vertex AI owned input data to be used for training, + and possibly evaluating, the Model. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields Attributes: fraction_split (google.cloud.aiplatform_v1.types.FractionSplit): Split based on fractions defining the size of each set. + + This field is a member of `oneof`_ ``split``. filter_split (google.cloud.aiplatform_v1.types.FilterSplit): Split based on the provided filters for each set. + + This field is a member of `oneof`_ ``split``. predefined_split (google.cloud.aiplatform_v1.types.PredefinedSplit): Supported only for tabular Datasets. Split based on a predefined key. + + This field is a member of `oneof`_ ``split``. timestamp_split (google.cloud.aiplatform_v1.types.TimestampSplit): Supported only for tabular Datasets. Split based on the timestamp of the input data pieces. + + This field is a member of `oneof`_ ``split``. + stratified_split (google.cloud.aiplatform_v1.types.StratifiedSplit): + Supported only for tabular Datasets. + Split based on the distribution of the specified + column. + + This field is a member of `oneof`_ ``split``. gcs_destination (google.cloud.aiplatform_v1.types.GcsDestination): The Cloud Storage location where the training data is to be written to. In the given directory a new directory is @@ -201,24 +289,24 @@ class InputDataConfig(proto.Message): format. All training input data is written into that directory. - The AI Platform environment variables representing Cloud + The Vertex AI environment variables representing Cloud Storage data URIs are represented in the Cloud Storage wildcard format to support sharded data. e.g.: "gs://.../training-*.jsonl" - AIP_DATA_FORMAT = "jsonl" for non-tabular data, "csv" for tabular data - - AIP_TRAINING_DATA_URI = - "gcs_destination/dataset---/training-*.${AIP_DATA_FORMAT}" + - AIP_TRAINING_DATA_URI = + "gcs_destination/dataset---/training-*.${AIP_DATA_FORMAT}" - AIP_VALIDATION_DATA_URI = - - "gcs_destination/dataset---/validation-*.${AIP_DATA_FORMAT}" + "gcs_destination/dataset---/validation-*.${AIP_DATA_FORMAT}" - AIP_TEST_DATA_URI = + "gcs_destination/dataset---/test-*.${AIP_DATA_FORMAT}". - "gcs_destination/dataset---/test-*.${AIP_DATA_FORMAT}". + This field is a member of `oneof`_ ``destination``. bigquery_destination (google.cloud.aiplatform_v1.types.BigQueryDestination): Only applicable to custom training with tabular Dataset with BigQuery source. @@ -233,16 +321,17 @@ class InputDataConfig(proto.Message): ``validation`` and ``test``. - AIP_DATA_FORMAT = "bigquery". - - AIP_TRAINING_DATA_URI = - "bigquery_destination.dataset\_\ **\ .training" + - AIP_TRAINING_DATA_URI = + "bigquery_destination.dataset\_\ **\ .training" - AIP_VALIDATION_DATA_URI = - - "bigquery_destination.dataset\_\ **\ .validation" + "bigquery_destination.dataset\_\ **\ .validation" - AIP_TEST_DATA_URI = "bigquery_destination.dataset\_\ **\ .test". + + This field is a member of `oneof`_ ``destination``. dataset_id (str): Required. The ID of the Dataset in the same Project and Location which data will be used to train the Model. The @@ -261,8 +350,8 @@ class InputDataConfig(proto.Message): ignored by the split method are used in respectively training, validation or test role, depending on the role of the DataItem they are on (for the auto-assigned that role is - decided by AI Platform). A filter with same syntax as the - one used in + decided by Vertex AI). A filter with same syntax as the one + used in [ListAnnotations][google.cloud.aiplatform.v1.DatasetService.ListAnnotations] may be used, but note here it filters across all Annotations of the Dataset, and not just within a single DataItem. @@ -273,8 +362,8 @@ class InputDataConfig(proto.Message): Cloud Storage URI that points to a YAML file describing the annotation schema. The schema is defined as an OpenAPI 3.0.2 `Schema - Object `__. The - schema files that can be used here are found in + Object `__. + The schema files that can be used here are found in gs://google-cloud-aiplatform/schema/dataset/annotation/ , note that the chosen schema must be consistent with [metadata][google.cloud.aiplatform.v1.Dataset.metadata_schema_uri] @@ -295,26 +384,59 @@ class InputDataConfig(proto.Message): """ fraction_split = proto.Field( - proto.MESSAGE, number=2, oneof="split", message="FractionSplit", + proto.MESSAGE, + number=2, + oneof="split", + message="FractionSplit", ) filter_split = proto.Field( - proto.MESSAGE, number=3, oneof="split", message="FilterSplit", + proto.MESSAGE, + number=3, + oneof="split", + message="FilterSplit", ) predefined_split = proto.Field( - proto.MESSAGE, number=4, oneof="split", message="PredefinedSplit", + proto.MESSAGE, + number=4, + oneof="split", + message="PredefinedSplit", ) timestamp_split = proto.Field( - proto.MESSAGE, number=5, oneof="split", message="TimestampSplit", + proto.MESSAGE, + number=5, + oneof="split", + message="TimestampSplit", + ) + stratified_split = proto.Field( + proto.MESSAGE, + number=12, + oneof="split", + message="StratifiedSplit", ) gcs_destination = proto.Field( - proto.MESSAGE, number=8, oneof="destination", message=io.GcsDestination, + proto.MESSAGE, + number=8, + oneof="destination", + message=io.GcsDestination, ) bigquery_destination = proto.Field( - proto.MESSAGE, number=10, oneof="destination", message=io.BigQueryDestination, + proto.MESSAGE, + number=10, + oneof="destination", + message=io.BigQueryDestination, + ) + dataset_id = proto.Field( + proto.STRING, + number=1, + ) + annotations_filter = proto.Field( + proto.STRING, + number=6, + ) + annotation_schema_uri = proto.Field( + proto.STRING, + number=9, ) - dataset_id = proto.Field(proto.STRING, number=1,) - annotations_filter = proto.Field(proto.STRING, number=6,) - annotation_schema_uri = proto.Field(proto.STRING, number=9,) class FractionSplit(proto.Message): @@ -322,7 +444,7 @@ class FractionSplit(proto.Message): the given fractions. Any of ``training_fraction``, ``validation_fraction`` and ``test_fraction`` may optionally be provided, they must sum to up to 1. If the provided ones sum to less - than 1, the remainder is assigned to sets as decided by AI Platform. + than 1, the remainder is assigned to sets as decided by Vertex AI. If none of the fractions are set, by default roughly 80% of data is used for training, 10% for validation, and 10% for test. @@ -338,9 +460,18 @@ class FractionSplit(proto.Message): used to evaluate the Model. """ - training_fraction = proto.Field(proto.DOUBLE, number=1,) - validation_fraction = proto.Field(proto.DOUBLE, number=2,) - test_fraction = proto.Field(proto.DOUBLE, number=3,) + training_fraction = proto.Field( + proto.DOUBLE, + number=1, + ) + validation_fraction = proto.Field( + proto.DOUBLE, + number=2, + ) + test_fraction = proto.Field( + proto.DOUBLE, + number=3, + ) class FilterSplit(proto.Message): @@ -383,9 +514,18 @@ class FilterSplit(proto.Message): test order. """ - training_filter = proto.Field(proto.STRING, number=1,) - validation_filter = proto.Field(proto.STRING, number=2,) - test_filter = proto.Field(proto.STRING, number=3,) + training_filter = proto.Field( + proto.STRING, + number=1, + ) + validation_filter = proto.Field( + proto.STRING, + number=2, + ) + test_filter = proto.Field( + proto.STRING, + number=3, + ) class PredefinedSplit(proto.Message): @@ -405,7 +545,10 @@ class PredefinedSplit(proto.Message): ignored by the pipeline. """ - key = proto.Field(proto.STRING, number=1,) + key = proto.Field( + proto.STRING, + number=1, + ) class TimestampSplit(proto.Message): @@ -434,10 +577,75 @@ class TimestampSplit(proto.Message): value, that piece is ignored by the pipeline. """ - training_fraction = proto.Field(proto.DOUBLE, number=1,) - validation_fraction = proto.Field(proto.DOUBLE, number=2,) - test_fraction = proto.Field(proto.DOUBLE, number=3,) - key = proto.Field(proto.STRING, number=4,) + training_fraction = proto.Field( + proto.DOUBLE, + number=1, + ) + validation_fraction = proto.Field( + proto.DOUBLE, + number=2, + ) + test_fraction = proto.Field( + proto.DOUBLE, + number=3, + ) + key = proto.Field( + proto.STRING, + number=4, + ) + + +class StratifiedSplit(proto.Message): + r"""Assigns input data to the training, validation, and test sets so + that the distribution of values found in the categorical column (as + specified by the ``key`` field) is mirrored within each split. The + fraction values determine the relative sizes of the splits. + + For example, if the specified column has three values, with 50% of + the rows having value "A", 25% value "B", and 25% value "C", and the + split fractions are specified as 80/10/10, then the training set + will constitute 80% of the training data, with about 50% of the + training set rows having the value "A" for the specified column, + about 25% having the value "B", and about 25% having the value "C". + + Only the top 500 occurring values are used; any values not in the + top 500 values are randomly assigned to a split. If less than three + rows contain a specific value, those rows are randomly assigned. + + Supported only for tabular Datasets. + + Attributes: + training_fraction (float): + The fraction of the input data that is to be + used to train the Model. + validation_fraction (float): + The fraction of the input data that is to be + used to validate the Model. + test_fraction (float): + The fraction of the input data that is to be + used to evaluate the Model. + key (str): + Required. The key is a name of one of the + Dataset's data columns. The key provided must be + for a categorical column. + """ + + training_fraction = proto.Field( + proto.DOUBLE, + number=1, + ) + validation_fraction = proto.Field( + proto.DOUBLE, + number=2, + ) + test_fraction = proto.Field( + proto.DOUBLE, + number=3, + ) + key = proto.Field( + proto.STRING, + number=4, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/types.py b/google/cloud/aiplatform_v1/types/types.py new file mode 100644 index 0000000000..6e660c00ef --- /dev/null +++ b/google/cloud/aiplatform_v1/types/types.py @@ -0,0 +1,86 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "BoolArray", + "DoubleArray", + "Int64Array", + "StringArray", + }, +) + + +class BoolArray(proto.Message): + r"""A list of boolean values. + + Attributes: + values (Sequence[bool]): + A list of bool values. + """ + + values = proto.RepeatedField( + proto.BOOL, + number=1, + ) + + +class DoubleArray(proto.Message): + r"""A list of double values. + + Attributes: + values (Sequence[float]): + A list of bool values. + """ + + values = proto.RepeatedField( + proto.DOUBLE, + number=1, + ) + + +class Int64Array(proto.Message): + r"""A list of int64 values. + + Attributes: + values (Sequence[int]): + A list of int64 values. + """ + + values = proto.RepeatedField( + proto.INT64, + number=1, + ) + + +class StringArray(proto.Message): + r"""A list of string values. + + Attributes: + values (Sequence[str]): + A list of string values. + """ + + values = proto.RepeatedField( + proto.STRING, + number=1, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/unmanaged_container_model.py b/google/cloud/aiplatform_v1/types/unmanaged_container_model.py new file mode 100644 index 0000000000..f37237ab4c --- /dev/null +++ b/google/cloud/aiplatform_v1/types/unmanaged_container_model.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + +from google.cloud.aiplatform_v1.types import model + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "UnmanagedContainerModel", + }, +) + + +class UnmanagedContainerModel(proto.Message): + r"""Contains model information necessary to perform batch + prediction without requiring a full model import. + + Attributes: + artifact_uri (str): + The path to the directory containing the + Model artifact and any of its supporting files. + predict_schemata (google.cloud.aiplatform_v1.types.PredictSchemata): + Contains the schemata used in Model's + predictions and explanations + container_spec (google.cloud.aiplatform_v1.types.ModelContainerSpec): + Input only. The specification of the + container that is to be used when deploying this + Model. + """ + + artifact_uri = proto.Field( + proto.STRING, + number=1, + ) + predict_schemata = proto.Field( + proto.MESSAGE, + number=2, + message=model.PredictSchemata, + ) + container_spec = proto.Field( + proto.MESSAGE, + number=3, + message=model.ModelContainerSpec, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/user_action_reference.py b/google/cloud/aiplatform_v1/types/user_action_reference.py index 203b604ae2..539d958f1d 100644 --- a/google/cloud/aiplatform_v1/types/user_action_reference.py +++ b/google/cloud/aiplatform_v1/types/user_action_reference.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,7 +17,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1", manifest={"UserActionReference",}, + package="google.cloud.aiplatform.v1", + manifest={ + "UserActionReference", + }, ) @@ -26,25 +29,47 @@ class UserActionReference(proto.Message): long running operation and Jobs that are triggered by the API call. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: operation (str): For API calls that return a long running operation. Resource name of the long running operation. Format: 'projects/{project}/locations/{location}/operations/{operation}' + + This field is a member of `oneof`_ ``reference``. data_labeling_job (str): For API calls that start a LabelingJob. Resource name of the LabelingJob. Format: - 'projects/{project}/locations/{location}/dataLabelingJobs/{data_labeling_job}' + + This field is a member of `oneof`_ ``reference``. method (str): - The method name of the API call. For example, - "/google.cloud.aiplatform.v1alpha1.DatasetService.CreateDataset". + The method name of the API RPC call. For + example, + "/google.cloud.aiplatform.{apiVersion}.DatasetService.CreateDataset". """ - operation = proto.Field(proto.STRING, number=1, oneof="reference",) - data_labeling_job = proto.Field(proto.STRING, number=2, oneof="reference",) - method = proto.Field(proto.STRING, number=3,) + operation = proto.Field( + proto.STRING, + number=1, + oneof="reference", + ) + data_labeling_job = proto.Field( + proto.STRING, + number=2, + oneof="reference", + ) + method = proto.Field( + proto.STRING, + number=3, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/value.py b/google/cloud/aiplatform_v1/types/value.py new file mode 100644 index 0000000000..cbf314cd39 --- /dev/null +++ b/google/cloud/aiplatform_v1/types/value.py @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "Value", + }, +) + + +class Value(proto.Message): + r"""Value is the value of the field. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + int_value (int): + An integer value. + + This field is a member of `oneof`_ ``value``. + double_value (float): + A double value. + + This field is a member of `oneof`_ ``value``. + string_value (str): + A string value. + + This field is a member of `oneof`_ ``value``. + """ + + int_value = proto.Field( + proto.INT64, + number=1, + oneof="value", + ) + double_value = proto.Field( + proto.DOUBLE, + number=2, + oneof="value", + ) + string_value = proto.Field( + proto.STRING, + number=3, + oneof="value", + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1/types/vizier_service.py b/google/cloud/aiplatform_v1/types/vizier_service.py new file mode 100644 index 0000000000..916be3b3de --- /dev/null +++ b/google/cloud/aiplatform_v1/types/vizier_service.py @@ -0,0 +1,589 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + +from google.cloud.aiplatform_v1.types import operation +from google.cloud.aiplatform_v1.types import study as gca_study +from google.protobuf import timestamp_pb2 # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1", + manifest={ + "GetStudyRequest", + "CreateStudyRequest", + "ListStudiesRequest", + "ListStudiesResponse", + "DeleteStudyRequest", + "LookupStudyRequest", + "SuggestTrialsRequest", + "SuggestTrialsResponse", + "SuggestTrialsMetadata", + "CreateTrialRequest", + "GetTrialRequest", + "ListTrialsRequest", + "ListTrialsResponse", + "AddTrialMeasurementRequest", + "CompleteTrialRequest", + "DeleteTrialRequest", + "CheckTrialEarlyStoppingStateRequest", + "CheckTrialEarlyStoppingStateResponse", + "CheckTrialEarlyStoppingStateMetatdata", + "StopTrialRequest", + "ListOptimalTrialsRequest", + "ListOptimalTrialsResponse", + }, +) + + +class GetStudyRequest(proto.Message): + r"""Request message for + [VizierService.GetStudy][google.cloud.aiplatform.v1.VizierService.GetStudy]. + + Attributes: + name (str): + Required. The name of the Study resource. Format: + ``projects/{project}/locations/{location}/studies/{study}`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class CreateStudyRequest(proto.Message): + r"""Request message for + [VizierService.CreateStudy][google.cloud.aiplatform.v1.VizierService.CreateStudy]. + + Attributes: + parent (str): + Required. The resource name of the Location to create the + CustomJob in. Format: + ``projects/{project}/locations/{location}`` + study (google.cloud.aiplatform_v1.types.Study): + Required. The Study configuration used to + create the Study. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + study = proto.Field( + proto.MESSAGE, + number=2, + message=gca_study.Study, + ) + + +class ListStudiesRequest(proto.Message): + r"""Request message for + [VizierService.ListStudies][google.cloud.aiplatform.v1.VizierService.ListStudies]. + + Attributes: + parent (str): + Required. The resource name of the Location to list the + Study from. Format: + ``projects/{project}/locations/{location}`` + page_token (str): + Optional. A page token to request the next + page of results. If unspecified, there are no + subsequent pages. + page_size (int): + Optional. The maximum number of studies to + return per "page" of results. If unspecified, + service will pick an appropriate default. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + page_token = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + + +class ListStudiesResponse(proto.Message): + r"""Response message for + [VizierService.ListStudies][google.cloud.aiplatform.v1.VizierService.ListStudies]. + + Attributes: + studies (Sequence[google.cloud.aiplatform_v1.types.Study]): + The studies associated with the project. + next_page_token (str): + Passes this token as the ``page_token`` field of the request + for a subsequent call. If this field is omitted, there are + no subsequent pages. + """ + + @property + def raw_page(self): + return self + + studies = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gca_study.Study, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) + + +class DeleteStudyRequest(proto.Message): + r"""Request message for + [VizierService.DeleteStudy][google.cloud.aiplatform.v1.VizierService.DeleteStudy]. + + Attributes: + name (str): + Required. The name of the Study resource to be deleted. + Format: + ``projects/{project}/locations/{location}/studies/{study}`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class LookupStudyRequest(proto.Message): + r"""Request message for + [VizierService.LookupStudy][google.cloud.aiplatform.v1.VizierService.LookupStudy]. + + Attributes: + parent (str): + Required. The resource name of the Location to get the Study + from. Format: ``projects/{project}/locations/{location}`` + display_name (str): + Required. The user-defined display name of + the Study + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + + +class SuggestTrialsRequest(proto.Message): + r"""Request message for + [VizierService.SuggestTrials][google.cloud.aiplatform.v1.VizierService.SuggestTrials]. + + Attributes: + parent (str): + Required. The project and location that the Study belongs + to. Format: + ``projects/{project}/locations/{location}/studies/{study}`` + suggestion_count (int): + Required. The number of suggestions + requested. + client_id (str): + Required. The identifier of the client that is requesting + the suggestion. + + If multiple SuggestTrialsRequests have the same + ``client_id``, the service will return the identical + suggested Trial if the Trial is pending, and provide a new + Trial if the last suggested Trial was completed. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + suggestion_count = proto.Field( + proto.INT32, + number=2, + ) + client_id = proto.Field( + proto.STRING, + number=3, + ) + + +class SuggestTrialsResponse(proto.Message): + r"""Response message for + [VizierService.SuggestTrials][google.cloud.aiplatform.v1.VizierService.SuggestTrials]. + + Attributes: + trials (Sequence[google.cloud.aiplatform_v1.types.Trial]): + A list of Trials. + study_state (google.cloud.aiplatform_v1.types.Study.State): + The state of the Study. + start_time (google.protobuf.timestamp_pb2.Timestamp): + The time at which the operation was started. + end_time (google.protobuf.timestamp_pb2.Timestamp): + The time at which operation processing + completed. + """ + + trials = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gca_study.Trial, + ) + study_state = proto.Field( + proto.ENUM, + number=2, + enum=gca_study.Study.State, + ) + start_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + end_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + + +class SuggestTrialsMetadata(proto.Message): + r"""Details of operations that perform Trials suggestion. + + Attributes: + generic_metadata (google.cloud.aiplatform_v1.types.GenericOperationMetadata): + Operation metadata for suggesting Trials. + client_id (str): + The identifier of the client that is requesting the + suggestion. + + If multiple SuggestTrialsRequests have the same + ``client_id``, the service will return the identical + suggested Trial if the Trial is pending, and provide a new + Trial if the last suggested Trial was completed. + """ + + generic_metadata = proto.Field( + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, + ) + client_id = proto.Field( + proto.STRING, + number=2, + ) + + +class CreateTrialRequest(proto.Message): + r"""Request message for + [VizierService.CreateTrial][google.cloud.aiplatform.v1.VizierService.CreateTrial]. + + Attributes: + parent (str): + Required. The resource name of the Study to create the Trial + in. Format: + ``projects/{project}/locations/{location}/studies/{study}`` + trial (google.cloud.aiplatform_v1.types.Trial): + Required. The Trial to create. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + trial = proto.Field( + proto.MESSAGE, + number=2, + message=gca_study.Trial, + ) + + +class GetTrialRequest(proto.Message): + r"""Request message for + [VizierService.GetTrial][google.cloud.aiplatform.v1.VizierService.GetTrial]. + + Attributes: + name (str): + Required. The name of the Trial resource. Format: + ``projects/{project}/locations/{location}/studies/{study}/trials/{trial}`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class ListTrialsRequest(proto.Message): + r"""Request message for + [VizierService.ListTrials][google.cloud.aiplatform.v1.VizierService.ListTrials]. + + Attributes: + parent (str): + Required. The resource name of the Study to list the Trial + from. Format: + ``projects/{project}/locations/{location}/studies/{study}`` + page_token (str): + Optional. A page token to request the next + page of results. If unspecified, there are no + subsequent pages. + page_size (int): + Optional. The number of Trials to retrieve + per "page" of results. If unspecified, the + service will pick an appropriate default. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + page_token = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + + +class ListTrialsResponse(proto.Message): + r"""Response message for + [VizierService.ListTrials][google.cloud.aiplatform.v1.VizierService.ListTrials]. + + Attributes: + trials (Sequence[google.cloud.aiplatform_v1.types.Trial]): + The Trials associated with the Study. + next_page_token (str): + Pass this token as the ``page_token`` field of the request + for a subsequent call. If this field is omitted, there are + no subsequent pages. + """ + + @property + def raw_page(self): + return self + + trials = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gca_study.Trial, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) + + +class AddTrialMeasurementRequest(proto.Message): + r"""Request message for + [VizierService.AddTrialMeasurement][google.cloud.aiplatform.v1.VizierService.AddTrialMeasurement]. + + Attributes: + trial_name (str): + Required. The name of the trial to add measurement. Format: + ``projects/{project}/locations/{location}/studies/{study}/trials/{trial}`` + measurement (google.cloud.aiplatform_v1.types.Measurement): + Required. The measurement to be added to a + Trial. + """ + + trial_name = proto.Field( + proto.STRING, + number=1, + ) + measurement = proto.Field( + proto.MESSAGE, + number=3, + message=gca_study.Measurement, + ) + + +class CompleteTrialRequest(proto.Message): + r"""Request message for + [VizierService.CompleteTrial][google.cloud.aiplatform.v1.VizierService.CompleteTrial]. + + Attributes: + name (str): + Required. The Trial's name. Format: + ``projects/{project}/locations/{location}/studies/{study}/trials/{trial}`` + final_measurement (google.cloud.aiplatform_v1.types.Measurement): + Optional. If provided, it will be used as the completed + Trial's final_measurement; Otherwise, the service will + auto-select a previously reported measurement as the + final-measurement + trial_infeasible (bool): + Optional. True if the Trial cannot be run with the given + Parameter, and final_measurement will be ignored. + infeasible_reason (str): + Optional. A human readable reason why the trial was + infeasible. This should only be provided if + ``trial_infeasible`` is true. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + final_measurement = proto.Field( + proto.MESSAGE, + number=2, + message=gca_study.Measurement, + ) + trial_infeasible = proto.Field( + proto.BOOL, + number=3, + ) + infeasible_reason = proto.Field( + proto.STRING, + number=4, + ) + + +class DeleteTrialRequest(proto.Message): + r"""Request message for + [VizierService.DeleteTrial][google.cloud.aiplatform.v1.VizierService.DeleteTrial]. + + Attributes: + name (str): + Required. The Trial's name. Format: + ``projects/{project}/locations/{location}/studies/{study}/trials/{trial}`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class CheckTrialEarlyStoppingStateRequest(proto.Message): + r"""Request message for + [VizierService.CheckTrialEarlyStoppingState][google.cloud.aiplatform.v1.VizierService.CheckTrialEarlyStoppingState]. + + Attributes: + trial_name (str): + Required. The Trial's name. Format: + ``projects/{project}/locations/{location}/studies/{study}/trials/{trial}`` + """ + + trial_name = proto.Field( + proto.STRING, + number=1, + ) + + +class CheckTrialEarlyStoppingStateResponse(proto.Message): + r"""Response message for + [VizierService.CheckTrialEarlyStoppingState][google.cloud.aiplatform.v1.VizierService.CheckTrialEarlyStoppingState]. + + Attributes: + should_stop (bool): + True if the Trial should stop. + """ + + should_stop = proto.Field( + proto.BOOL, + number=1, + ) + + +class CheckTrialEarlyStoppingStateMetatdata(proto.Message): + r"""This message will be placed in the metadata field of a + google.longrunning.Operation associated with a + CheckTrialEarlyStoppingState request. + + Attributes: + generic_metadata (google.cloud.aiplatform_v1.types.GenericOperationMetadata): + Operation metadata for suggesting Trials. + study (str): + The name of the Study that the Trial belongs + to. + trial (str): + The Trial name. + """ + + generic_metadata = proto.Field( + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, + ) + study = proto.Field( + proto.STRING, + number=2, + ) + trial = proto.Field( + proto.STRING, + number=3, + ) + + +class StopTrialRequest(proto.Message): + r"""Request message for + [VizierService.StopTrial][google.cloud.aiplatform.v1.VizierService.StopTrial]. + + Attributes: + name (str): + Required. The Trial's name. Format: + ``projects/{project}/locations/{location}/studies/{study}/trials/{trial}`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class ListOptimalTrialsRequest(proto.Message): + r"""Request message for + [VizierService.ListOptimalTrials][google.cloud.aiplatform.v1.VizierService.ListOptimalTrials]. + + Attributes: + parent (str): + Required. The name of the Study that the + optimal Trial belongs to. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + + +class ListOptimalTrialsResponse(proto.Message): + r"""Response message for + [VizierService.ListOptimalTrials][google.cloud.aiplatform.v1.VizierService.ListOptimalTrials]. + + Attributes: + optimal_trials (Sequence[google.cloud.aiplatform_v1.types.Trial]): + The pareto-optimal Trials for multiple objective Study or + the optimal trial for single objective Study. The definition + of pareto-optimal can be checked in wiki page. + https://en.wikipedia.org/wiki/Pareto_efficiency + """ + + optimal_trials = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gca_study.Trial, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/__init__.py b/google/cloud/aiplatform_v1beta1/__init__.py index a9c7df2b17..0934eacc19 100644 --- a/google/cloud/aiplatform_v1beta1/__init__.py +++ b/google/cloud/aiplatform_v1beta1/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -93,6 +93,8 @@ from .types.encryption_spec import EncryptionSpec from .types.endpoint import DeployedModel from .types.endpoint import Endpoint +from .types.endpoint import PredictRequestResponseLoggingConfig +from .types.endpoint import PrivateEndpoints from .types.endpoint_service import CreateEndpointOperationMetadata from .types.endpoint_service import CreateEndpointRequest from .types.endpoint_service import DeleteEndpointRequest @@ -111,6 +113,10 @@ from .types.event import Event from .types.execution import Execution from .types.explanation import Attribution +from .types.explanation import BlurBaselineConfig +from .types.explanation import Examples +from .types.explanation import ExamplesOverride +from .types.explanation import ExamplesRestrictionsNamespace from .types.explanation import Explanation from .types.explanation import ExplanationMetadataOverride from .types.explanation import ExplanationParameters @@ -119,6 +125,8 @@ from .types.explanation import FeatureNoiseSigma from .types.explanation import IntegratedGradientsAttribution from .types.explanation import ModelExplanation +from .types.explanation import Neighbor +from .types.explanation import Presets from .types.explanation import SampledShapleyAttribution from .types.explanation import SmoothGradConfig from .types.explanation import XraiAttribution @@ -187,6 +195,9 @@ from .types.index_endpoint_service import GetIndexEndpointRequest from .types.index_endpoint_service import ListIndexEndpointsRequest from .types.index_endpoint_service import ListIndexEndpointsResponse +from .types.index_endpoint_service import MutateDeployedIndexOperationMetadata +from .types.index_endpoint_service import MutateDeployedIndexRequest +from .types.index_endpoint_service import MutateDeployedIndexResponse from .types.index_endpoint_service import UndeployIndexOperationMetadata from .types.index_endpoint_service import UndeployIndexRequest from .types.index_endpoint_service import UndeployIndexResponse @@ -252,6 +263,7 @@ from .types.machine_resources import DedicatedResources from .types.machine_resources import DiskSpec from .types.machine_resources import MachineSpec +from .types.machine_resources import NfsMount from .types.machine_resources import ResourcesConsumed from .types.manual_batch_tuning_parameters import ManualBatchTuningParameters from .types.metadata_schema import MetadataSchema @@ -267,7 +279,9 @@ from .types.metadata_service import CreateMetadataSchemaRequest from .types.metadata_service import CreateMetadataStoreOperationMetadata from .types.metadata_service import CreateMetadataStoreRequest +from .types.metadata_service import DeleteArtifactRequest from .types.metadata_service import DeleteContextRequest +from .types.metadata_service import DeleteExecutionRequest from .types.metadata_service import DeleteMetadataStoreOperationMetadata from .types.metadata_service import DeleteMetadataStoreRequest from .types.metadata_service import GetArtifactRequest @@ -285,6 +299,15 @@ from .types.metadata_service import ListMetadataSchemasResponse from .types.metadata_service import ListMetadataStoresRequest from .types.metadata_service import ListMetadataStoresResponse +from .types.metadata_service import PurgeArtifactsMetadata +from .types.metadata_service import PurgeArtifactsRequest +from .types.metadata_service import PurgeArtifactsResponse +from .types.metadata_service import PurgeContextsMetadata +from .types.metadata_service import PurgeContextsRequest +from .types.metadata_service import PurgeContextsResponse +from .types.metadata_service import PurgeExecutionsMetadata +from .types.metadata_service import PurgeExecutionsRequest +from .types.metadata_service import PurgeExecutionsResponse from .types.metadata_service import QueryArtifactLineageSubgraphRequest from .types.metadata_service import QueryContextLineageSubgraphRequest from .types.metadata_service import QueryExecutionInputsAndOutputsRequest @@ -321,32 +344,45 @@ from .types.model_evaluation import ModelEvaluation from .types.model_evaluation_slice import ModelEvaluationSlice from .types.model_monitoring import ModelMonitoringAlertConfig +from .types.model_monitoring import ModelMonitoringConfig from .types.model_monitoring import ModelMonitoringObjectiveConfig from .types.model_monitoring import SamplingStrategy from .types.model_monitoring import ThresholdConfig +from .types.model_service import BatchImportModelEvaluationSlicesRequest +from .types.model_service import BatchImportModelEvaluationSlicesResponse from .types.model_service import DeleteModelRequest +from .types.model_service import DeleteModelVersionRequest from .types.model_service import ExportModelOperationMetadata from .types.model_service import ExportModelRequest from .types.model_service import ExportModelResponse from .types.model_service import GetModelEvaluationRequest from .types.model_service import GetModelEvaluationSliceRequest from .types.model_service import GetModelRequest +from .types.model_service import ImportModelEvaluationRequest from .types.model_service import ListModelEvaluationSlicesRequest from .types.model_service import ListModelEvaluationSlicesResponse from .types.model_service import ListModelEvaluationsRequest from .types.model_service import ListModelEvaluationsResponse from .types.model_service import ListModelsRequest from .types.model_service import ListModelsResponse +from .types.model_service import ListModelVersionsRequest +from .types.model_service import ListModelVersionsResponse +from .types.model_service import MergeVersionAliasesRequest +from .types.model_service import UpdateExplanationDatasetOperationMetadata +from .types.model_service import UpdateExplanationDatasetRequest +from .types.model_service import UpdateExplanationDatasetResponse from .types.model_service import UpdateModelRequest from .types.model_service import UploadModelOperationMetadata from .types.model_service import UploadModelRequest from .types.model_service import UploadModelResponse from .types.operation import DeleteOperationMetadata from .types.operation import GenericOperationMetadata +from .types.pipeline_failure_policy import PipelineFailurePolicy from .types.pipeline_job import PipelineJob from .types.pipeline_job import PipelineJobDetail from .types.pipeline_job import PipelineTaskDetail from .types.pipeline_job import PipelineTaskExecutorDetail +from .types.pipeline_job import PipelineTemplateMetadata from .types.pipeline_service import CancelPipelineJobRequest from .types.pipeline_service import CancelTrainingPipelineRequest from .types.pipeline_service import CreatePipelineJobRequest @@ -364,6 +400,7 @@ from .types.prediction_service import ExplainResponse from .types.prediction_service import PredictRequest from .types.prediction_service import PredictResponse +from .types.prediction_service import RawPredictRequest from .types.specialist_pool import SpecialistPool from .types.specialist_pool_service import CreateSpecialistPoolOperationMetadata from .types.specialist_pool_service import CreateSpecialistPoolRequest @@ -386,6 +423,12 @@ from .types.tensorboard_data import TimeSeriesDataPoint from .types.tensorboard_experiment import TensorboardExperiment from .types.tensorboard_run import TensorboardRun +from .types.tensorboard_service import BatchCreateTensorboardRunsRequest +from .types.tensorboard_service import BatchCreateTensorboardRunsResponse +from .types.tensorboard_service import BatchCreateTensorboardTimeSeriesRequest +from .types.tensorboard_service import BatchCreateTensorboardTimeSeriesResponse +from .types.tensorboard_service import BatchReadTensorboardTimeSeriesDataRequest +from .types.tensorboard_service import BatchReadTensorboardTimeSeriesDataResponse from .types.tensorboard_service import CreateTensorboardExperimentRequest from .types.tensorboard_service import CreateTensorboardOperationMetadata from .types.tensorboard_service import CreateTensorboardRequest @@ -418,6 +461,8 @@ from .types.tensorboard_service import UpdateTensorboardRequest from .types.tensorboard_service import UpdateTensorboardRunRequest from .types.tensorboard_service import UpdateTensorboardTimeSeriesRequest +from .types.tensorboard_service import WriteTensorboardExperimentDataRequest +from .types.tensorboard_service import WriteTensorboardExperimentDataResponse from .types.tensorboard_service import WriteTensorboardRunDataRequest from .types.tensorboard_service import WriteTensorboardRunDataResponse from .types.tensorboard_time_series import TensorboardTimeSeries @@ -425,12 +470,14 @@ from .types.training_pipeline import FractionSplit from .types.training_pipeline import InputDataConfig from .types.training_pipeline import PredefinedSplit +from .types.training_pipeline import StratifiedSplit from .types.training_pipeline import TimestampSplit from .types.training_pipeline import TrainingPipeline from .types.types import BoolArray from .types.types import DoubleArray from .types.types import Int64Array from .types.types import StringArray +from .types.unmanaged_container_model import UnmanagedContainerModel from .types.user_action_reference import UserActionReference from .types.value import Value from .types.vizier_service import AddTrialMeasurementRequest @@ -491,7 +538,13 @@ "BatchCreateFeaturesOperationMetadata", "BatchCreateFeaturesRequest", "BatchCreateFeaturesResponse", + "BatchCreateTensorboardRunsRequest", + "BatchCreateTensorboardRunsResponse", + "BatchCreateTensorboardTimeSeriesRequest", + "BatchCreateTensorboardTimeSeriesResponse", "BatchDedicatedResources", + "BatchImportModelEvaluationSlicesRequest", + "BatchImportModelEvaluationSlicesResponse", "BatchMigrateResourcesOperationMetadata", "BatchMigrateResourcesRequest", "BatchMigrateResourcesResponse", @@ -499,8 +552,11 @@ "BatchReadFeatureValuesOperationMetadata", "BatchReadFeatureValuesRequest", "BatchReadFeatureValuesResponse", + "BatchReadTensorboardTimeSeriesDataRequest", + "BatchReadTensorboardTimeSeriesDataResponse", "BigQueryDestination", "BigQuerySource", + "BlurBaselineConfig", "BoolArray", "CancelBatchPredictionJobRequest", "CancelCustomJobRequest", @@ -561,6 +617,7 @@ "Dataset", "DatasetServiceClient", "DedicatedResources", + "DeleteArtifactRequest", "DeleteBatchPredictionJobRequest", "DeleteContextRequest", "DeleteCustomJobRequest", @@ -568,6 +625,7 @@ "DeleteDatasetRequest", "DeleteEndpointRequest", "DeleteEntityTypeRequest", + "DeleteExecutionRequest", "DeleteFeatureRequest", "DeleteFeaturestoreRequest", "DeleteHyperparameterTuningJobRequest", @@ -577,6 +635,7 @@ "DeleteMetadataStoreRequest", "DeleteModelDeploymentMonitoringJobRequest", "DeleteModelRequest", + "DeleteModelVersionRequest", "DeleteOperationMetadata", "DeletePipelineJobRequest", "DeleteSpecialistPoolRequest", @@ -607,6 +666,9 @@ "EntityType", "EnvVar", "Event", + "Examples", + "ExamplesOverride", + "ExamplesRestrictionsNamespace", "Execution", "ExplainRequest", "ExplainResponse", @@ -683,6 +745,7 @@ "ImportFeatureValuesOperationMetadata", "ImportFeatureValuesRequest", "ImportFeatureValuesResponse", + "ImportModelEvaluationRequest", "Index", "IndexEndpoint", "IndexEndpointServiceClient", @@ -736,6 +799,8 @@ "ListModelEvaluationSlicesResponse", "ListModelEvaluationsRequest", "ListModelEvaluationsResponse", + "ListModelVersionsRequest", + "ListModelVersionsResponse", "ListModelsRequest", "ListModelsResponse", "ListOptimalTrialsRequest", @@ -762,6 +827,7 @@ "MachineSpec", "ManualBatchTuningParameters", "Measurement", + "MergeVersionAliasesRequest", "MetadataSchema", "MetadataServiceClient", "MetadataStore", @@ -780,27 +846,48 @@ "ModelEvaluationSlice", "ModelExplanation", "ModelMonitoringAlertConfig", + "ModelMonitoringConfig", "ModelMonitoringObjectiveConfig", "ModelMonitoringStatsAnomalies", "ModelServiceClient", + "MutateDeployedIndexOperationMetadata", + "MutateDeployedIndexRequest", + "MutateDeployedIndexResponse", "NearestNeighborSearchOperationMetadata", + "Neighbor", + "NfsMount", "PauseModelDeploymentMonitoringJobRequest", + "PipelineFailurePolicy", "PipelineJob", "PipelineJobDetail", "PipelineServiceClient", "PipelineState", "PipelineTaskDetail", "PipelineTaskExecutorDetail", + "PipelineTemplateMetadata", "Port", "PredefinedSplit", "PredictRequest", + "PredictRequestResponseLoggingConfig", "PredictResponse", "PredictSchemata", "PredictionServiceClient", + "Presets", + "PrivateEndpoints", + "PurgeArtifactsMetadata", + "PurgeArtifactsRequest", + "PurgeArtifactsResponse", + "PurgeContextsMetadata", + "PurgeContextsRequest", + "PurgeContextsResponse", + "PurgeExecutionsMetadata", + "PurgeExecutionsRequest", + "PurgeExecutionsResponse", "PythonPackageSpec", "QueryArtifactLineageSubgraphRequest", "QueryContextLineageSubgraphRequest", "QueryExecutionInputsAndOutputsRequest", + "RawPredictRequest", "ReadFeatureValuesRequest", "ReadFeatureValuesResponse", "ReadTensorboardBlobDataRequest", @@ -824,6 +911,7 @@ "SpecialistPool", "SpecialistPoolServiceClient", "StopTrialRequest", + "StratifiedSplit", "StreamingReadFeatureValuesRequest", "StringArray", "Study", @@ -853,12 +941,16 @@ "UndeployModelOperationMetadata", "UndeployModelRequest", "UndeployModelResponse", + "UnmanagedContainerModel", "UpdateArtifactRequest", "UpdateContextRequest", "UpdateDatasetRequest", "UpdateEndpointRequest", "UpdateEntityTypeRequest", "UpdateExecutionRequest", + "UpdateExplanationDatasetOperationMetadata", + "UpdateExplanationDatasetRequest", + "UpdateExplanationDatasetResponse", "UpdateFeatureRequest", "UpdateFeaturestoreOperationMetadata", "UpdateFeaturestoreRequest", @@ -882,6 +974,8 @@ "Value", "VizierServiceClient", "WorkerPoolSpec", + "WriteTensorboardExperimentDataRequest", + "WriteTensorboardExperimentDataResponse", "WriteTensorboardRunDataRequest", "WriteTensorboardRunDataResponse", "XraiAttribution", diff --git a/google/cloud/aiplatform_v1beta1/gapic_metadata.json b/google/cloud/aiplatform_v1beta1/gapic_metadata.json index 605e95582d..6eb4cbcead 100644 --- a/google/cloud/aiplatform_v1beta1/gapic_metadata.json +++ b/google/cloud/aiplatform_v1beta1/gapic_metadata.json @@ -481,6 +481,11 @@ "list_index_endpoints" ] }, + "MutateDeployedIndex": { + "methods": [ + "mutate_deployed_index" + ] + }, "UndeployIndex": { "methods": [ "undeploy_index" @@ -521,6 +526,11 @@ "list_index_endpoints" ] }, + "MutateDeployedIndex": { + "methods": [ + "mutate_deployed_index" + ] + }, "UndeployIndex": { "methods": [ "undeploy_index" @@ -938,11 +948,21 @@ "create_metadata_store" ] }, + "DeleteArtifact": { + "methods": [ + "delete_artifact" + ] + }, "DeleteContext": { "methods": [ "delete_context" ] }, + "DeleteExecution": { + "methods": [ + "delete_execution" + ] + }, "DeleteMetadataStore": { "methods": [ "delete_metadata_store" @@ -998,6 +1018,21 @@ "list_metadata_stores" ] }, + "PurgeArtifacts": { + "methods": [ + "purge_artifacts" + ] + }, + "PurgeContexts": { + "methods": [ + "purge_contexts" + ] + }, + "PurgeExecutions": { + "methods": [ + "purge_executions" + ] + }, "QueryArtifactLineageSubgraph": { "methods": [ "query_artifact_lineage_subgraph" @@ -1073,11 +1108,21 @@ "create_metadata_store" ] }, + "DeleteArtifact": { + "methods": [ + "delete_artifact" + ] + }, "DeleteContext": { "methods": [ "delete_context" ] }, + "DeleteExecution": { + "methods": [ + "delete_execution" + ] + }, "DeleteMetadataStore": { "methods": [ "delete_metadata_store" @@ -1133,6 +1178,21 @@ "list_metadata_stores" ] }, + "PurgeArtifacts": { + "methods": [ + "purge_artifacts" + ] + }, + "PurgeContexts": { + "methods": [ + "purge_contexts" + ] + }, + "PurgeExecutions": { + "methods": [ + "purge_executions" + ] + }, "QueryArtifactLineageSubgraph": { "methods": [ "query_artifact_lineage_subgraph" @@ -1206,11 +1266,21 @@ "grpc": { "libraryClient": "ModelServiceClient", "rpcs": { + "BatchImportModelEvaluationSlices": { + "methods": [ + "batch_import_model_evaluation_slices" + ] + }, "DeleteModel": { "methods": [ "delete_model" ] }, + "DeleteModelVersion": { + "methods": [ + "delete_model_version" + ] + }, "ExportModel": { "methods": [ "export_model" @@ -1231,6 +1301,11 @@ "get_model_evaluation_slice" ] }, + "ImportModelEvaluation": { + "methods": [ + "import_model_evaluation" + ] + }, "ListModelEvaluationSlices": { "methods": [ "list_model_evaluation_slices" @@ -1241,11 +1316,26 @@ "list_model_evaluations" ] }, + "ListModelVersions": { + "methods": [ + "list_model_versions" + ] + }, "ListModels": { "methods": [ "list_models" ] }, + "MergeVersionAliases": { + "methods": [ + "merge_version_aliases" + ] + }, + "UpdateExplanationDataset": { + "methods": [ + "update_explanation_dataset" + ] + }, "UpdateModel": { "methods": [ "update_model" @@ -1261,11 +1351,21 @@ "grpc-async": { "libraryClient": "ModelServiceAsyncClient", "rpcs": { + "BatchImportModelEvaluationSlices": { + "methods": [ + "batch_import_model_evaluation_slices" + ] + }, "DeleteModel": { "methods": [ "delete_model" ] }, + "DeleteModelVersion": { + "methods": [ + "delete_model_version" + ] + }, "ExportModel": { "methods": [ "export_model" @@ -1286,6 +1386,11 @@ "get_model_evaluation_slice" ] }, + "ImportModelEvaluation": { + "methods": [ + "import_model_evaluation" + ] + }, "ListModelEvaluationSlices": { "methods": [ "list_model_evaluation_slices" @@ -1296,11 +1401,26 @@ "list_model_evaluations" ] }, + "ListModelVersions": { + "methods": [ + "list_model_versions" + ] + }, "ListModels": { "methods": [ "list_models" ] }, + "MergeVersionAliases": { + "methods": [ + "merge_version_aliases" + ] + }, + "UpdateExplanationDataset": { + "methods": [ + "update_explanation_dataset" + ] + }, "UpdateModel": { "methods": [ "update_model" @@ -1443,6 +1563,11 @@ "methods": [ "predict" ] + }, + "RawPredict": { + "methods": [ + "raw_predict" + ] } } }, @@ -1458,6 +1583,11 @@ "methods": [ "predict" ] + }, + "RawPredict": { + "methods": [ + "raw_predict" + ] } } } @@ -1532,6 +1662,21 @@ "grpc": { "libraryClient": "TensorboardServiceClient", "rpcs": { + "BatchCreateTensorboardRuns": { + "methods": [ + "batch_create_tensorboard_runs" + ] + }, + "BatchCreateTensorboardTimeSeries": { + "methods": [ + "batch_create_tensorboard_time_series" + ] + }, + "BatchReadTensorboardTimeSeriesData": { + "methods": [ + "batch_read_tensorboard_time_series_data" + ] + }, "CreateTensorboard": { "methods": [ "create_tensorboard" @@ -1647,6 +1792,11 @@ "update_tensorboard_time_series" ] }, + "WriteTensorboardExperimentData": { + "methods": [ + "write_tensorboard_experiment_data" + ] + }, "WriteTensorboardRunData": { "methods": [ "write_tensorboard_run_data" @@ -1657,6 +1807,21 @@ "grpc-async": { "libraryClient": "TensorboardServiceAsyncClient", "rpcs": { + "BatchCreateTensorboardRuns": { + "methods": [ + "batch_create_tensorboard_runs" + ] + }, + "BatchCreateTensorboardTimeSeries": { + "methods": [ + "batch_create_tensorboard_time_series" + ] + }, + "BatchReadTensorboardTimeSeriesData": { + "methods": [ + "batch_read_tensorboard_time_series_data" + ] + }, "CreateTensorboard": { "methods": [ "create_tensorboard" @@ -1772,6 +1937,11 @@ "update_tensorboard_time_series" ] }, + "WriteTensorboardExperimentData": { + "methods": [ + "write_tensorboard_experiment_data" + ] + }, "WriteTensorboardRunData": { "methods": [ "write_tensorboard_run_data" diff --git a/google/cloud/aiplatform_v1beta1/services/__init__.py b/google/cloud/aiplatform_v1beta1/services/__init__.py index 4de65971c2..e8e1c3845d 100644 --- a/google/cloud/aiplatform_v1beta1/services/__init__.py +++ b/google/cloud/aiplatform_v1beta1/services/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1beta1/services/dataset_service/__init__.py b/google/cloud/aiplatform_v1beta1/services/dataset_service/__init__.py index 42adf5e5af..163172b9a0 100644 --- a/google/cloud/aiplatform_v1beta1/services/dataset_service/__init__.py +++ b/google/cloud/aiplatform_v1beta1/services/dataset_service/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1beta1/services/dataset_service/async_client.py b/google/cloud/aiplatform_v1beta1/services/dataset_service/async_client.py index 1ef85adee3..aaca9b3088 100644 --- a/google/cloud/aiplatform_v1beta1/services/dataset_service/async_client.py +++ b/google/cloud/aiplatform_v1beta1/services/dataset_service/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,16 +16,21 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation as gac_operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1beta1.services.dataset_service import pagers @@ -37,6 +42,10 @@ from google.cloud.aiplatform_v1beta1.types import dataset_service from google.cloud.aiplatform_v1beta1.types import encryption_spec from google.cloud.aiplatform_v1beta1.types import operation as gca_operation +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import struct_pb2 # type: ignore @@ -47,7 +56,9 @@ class DatasetServiceAsyncClient: - """""" + """The service that handles the CRUD of Vertex AI Dataset and + its child resources. + """ _client: DatasetServiceClient @@ -91,7 +102,8 @@ class DatasetServiceAsyncClient: @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -106,7 +118,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -121,9 +133,45 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return DatasetServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> DatasetServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: DatasetServiceTransport: The transport used by the client instance. @@ -142,7 +190,7 @@ def __init__( client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the dataset service client. + """Instantiates the dataset service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -183,18 +231,47 @@ def __init__( async def create_dataset( self, - request: dataset_service.CreateDatasetRequest = None, + request: Union[dataset_service.CreateDatasetRequest, dict] = None, *, parent: str = None, dataset: gca_dataset.Dataset = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Creates a Dataset. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_create_dataset(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + dataset = aiplatform_v1beta1.Dataset() + dataset.display_name = "display_name_value" + dataset.metadata_schema_uri = "metadata_schema_uri_value" + dataset.metadata.null_value = "NULL_VALUE" + + request = aiplatform_v1beta1.CreateDatasetRequest( + parent="parent_value", + dataset=dataset, + ) + + # Make the request + operation = client.create_dataset(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.CreateDatasetRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateDatasetRequest, dict]): The request object. Request message for [DatasetService.CreateDataset][google.cloud.aiplatform.v1beta1.DatasetService.CreateDataset]. parent (:class:`str`): @@ -226,7 +303,7 @@ async def create_dataset( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, dataset]) if request is not None and has_flattened_params: @@ -259,7 +336,12 @@ async def create_dataset( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -274,17 +356,36 @@ async def create_dataset( async def get_dataset( self, - request: dataset_service.GetDatasetRequest = None, + request: Union[dataset_service.GetDatasetRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> dataset.Dataset: r"""Gets a Dataset. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_get_dataset(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetDatasetRequest( + name="name_value", + ) + + # Make the request + response = await client.get_dataset(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.GetDatasetRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.GetDatasetRequest, dict]): The request object. Request message for [DatasetService.GetDataset][google.cloud.aiplatform.v1beta1.DatasetService.GetDataset]. name (:class:`str`): @@ -307,7 +408,7 @@ async def get_dataset( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -338,25 +439,54 @@ async def get_dataset( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def update_dataset( self, - request: dataset_service.UpdateDatasetRequest = None, + request: Union[dataset_service.UpdateDatasetRequest, dict] = None, *, dataset: gca_dataset.Dataset = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_dataset.Dataset: r"""Updates a Dataset. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_update_dataset(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + dataset = aiplatform_v1beta1.Dataset() + dataset.display_name = "display_name_value" + dataset.metadata_schema_uri = "metadata_schema_uri_value" + dataset.metadata.null_value = "NULL_VALUE" + + request = aiplatform_v1beta1.UpdateDatasetRequest( + dataset=dataset, + ) + + # Make the request + response = await client.update_dataset(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.UpdateDatasetRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.UpdateDatasetRequest, dict]): The request object. Request message for [DatasetService.UpdateDataset][google.cloud.aiplatform.v1beta1.DatasetService.UpdateDataset]. dataset (:class:`google.cloud.aiplatform_v1beta1.types.Dataset`): @@ -369,7 +499,7 @@ async def update_dataset( update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): Required. The update mask applies to the resource. For the ``FieldMask`` definition, see - `FieldMask `__. + [google.protobuf.FieldMask][google.protobuf.FieldMask]. Updatable fields: - ``display_name`` @@ -392,7 +522,7 @@ async def update_dataset( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([dataset, update_mask]) if request is not None and has_flattened_params: @@ -427,24 +557,49 @@ async def update_dataset( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_datasets( self, - request: dataset_service.ListDatasetsRequest = None, + request: Union[dataset_service.ListDatasetsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListDatasetsAsyncPager: r"""Lists Datasets in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_list_datasets(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListDatasetsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_datasets(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ListDatasetsRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ListDatasetsRequest, dict]): The request object. Request message for [DatasetService.ListDatasets][google.cloud.aiplatform.v1beta1.DatasetService.ListDatasets]. parent (:class:`str`): @@ -470,7 +625,7 @@ async def list_datasets( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -501,12 +656,20 @@ async def list_datasets( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListDatasetsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -514,17 +677,40 @@ async def list_datasets( async def delete_dataset( self, - request: dataset_service.DeleteDatasetRequest = None, + request: Union[dataset_service.DeleteDatasetRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a Dataset. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_delete_dataset(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteDatasetRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_dataset(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.DeleteDatasetRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteDatasetRequest, dict]): The request object. Request message for [DatasetService.DeleteDataset][google.cloud.aiplatform.v1beta1.DatasetService.DeleteDataset]. name (:class:`str`): @@ -561,7 +747,7 @@ async def delete_dataset( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -592,7 +778,12 @@ async def delete_dataset( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -607,18 +798,46 @@ async def delete_dataset( async def import_data( self, - request: dataset_service.ImportDataRequest = None, + request: Union[dataset_service.ImportDataRequest, dict] = None, *, name: str = None, import_configs: Sequence[dataset.ImportDataConfig] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Imports data into a Dataset. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_import_data(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + import_configs = aiplatform_v1beta1.ImportDataConfig() + import_configs.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + import_configs.import_schema_uri = "import_schema_uri_value" + + request = aiplatform_v1beta1.ImportDataRequest( + name="name_value", + import_configs=import_configs, + ) + + # Make the request + operation = client.import_data(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ImportDataRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ImportDataRequest, dict]): The request object. Request message for [DatasetService.ImportData][google.cloud.aiplatform.v1beta1.DatasetService.ImportData]. name (:class:`str`): @@ -653,7 +872,7 @@ async def import_data( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, import_configs]) if request is not None and has_flattened_params: @@ -686,7 +905,12 @@ async def import_data( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -701,18 +925,45 @@ async def import_data( async def export_data( self, - request: dataset_service.ExportDataRequest = None, + request: Union[dataset_service.ExportDataRequest, dict] = None, *, name: str = None, export_config: dataset.ExportDataConfig = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Exports data from a Dataset. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_export_data(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + export_config = aiplatform_v1beta1.ExportDataConfig() + export_config.gcs_destination.output_uri_prefix = "output_uri_prefix_value" + + request = aiplatform_v1beta1.ExportDataRequest( + name="name_value", + export_config=export_config, + ) + + # Make the request + operation = client.export_data(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ExportDataRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ExportDataRequest, dict]): The request object. Request message for [DatasetService.ExportData][google.cloud.aiplatform.v1beta1.DatasetService.ExportData]. name (:class:`str`): @@ -746,7 +997,7 @@ async def export_data( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, export_config]) if request is not None and has_flattened_params: @@ -779,7 +1030,12 @@ async def export_data( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -794,17 +1050,37 @@ async def export_data( async def list_data_items( self, - request: dataset_service.ListDataItemsRequest = None, + request: Union[dataset_service.ListDataItemsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListDataItemsAsyncPager: r"""Lists DataItems in a Dataset. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_list_data_items(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListDataItemsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_data_items(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ListDataItemsRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ListDataItemsRequest, dict]): The request object. Request message for [DatasetService.ListDataItems][google.cloud.aiplatform.v1beta1.DatasetService.ListDataItems]. parent (:class:`str`): @@ -831,7 +1107,7 @@ async def list_data_items( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -862,12 +1138,20 @@ async def list_data_items( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListDataItemsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -875,17 +1159,36 @@ async def list_data_items( async def get_annotation_spec( self, - request: dataset_service.GetAnnotationSpecRequest = None, + request: Union[dataset_service.GetAnnotationSpecRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> annotation_spec.AnnotationSpec: r"""Gets an AnnotationSpec. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_get_annotation_spec(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetAnnotationSpecRequest( + name="name_value", + ) + + # Make the request + response = await client.get_annotation_spec(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.GetAnnotationSpecRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.GetAnnotationSpecRequest, dict]): The request object. Request message for [DatasetService.GetAnnotationSpec][google.cloud.aiplatform.v1beta1.DatasetService.GetAnnotationSpec]. name (:class:`str`): @@ -909,7 +1212,7 @@ async def get_annotation_spec( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -940,24 +1243,49 @@ async def get_annotation_spec( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_annotations( self, - request: dataset_service.ListAnnotationsRequest = None, + request: Union[dataset_service.ListAnnotationsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListAnnotationsAsyncPager: r"""Lists Annotations belongs to a dataitem + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_list_annotations(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListAnnotationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_annotations(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ListAnnotationsRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ListAnnotationsRequest, dict]): The request object. Request message for [DatasetService.ListAnnotations][google.cloud.aiplatform.v1beta1.DatasetService.ListAnnotations]. parent (:class:`str`): @@ -984,7 +1312,7 @@ async def list_annotations( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1015,17 +1343,702 @@ async def list_annotations( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListAnnotationsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_operations, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.delete_operation, + default_timeout=None, + 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 cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + 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 wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.wait_operation, + default_timeout=None, + 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 set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_location, + default_timeout=None, + 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 list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_locations, + default_timeout=None, + 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 __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/aiplatform_v1beta1/services/dataset_service/client.py b/google/cloud/aiplatform_v1beta1/services/dataset_service/client.py index 140646f861..0042848cd5 100644 --- a/google/cloud/aiplatform_v1beta1/services/dataset_service/client.py +++ b/google/cloud/aiplatform_v1beta1/services/dataset_service/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,22 +14,26 @@ # 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 +from typing import Dict, Mapping, 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 as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_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 +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation as gac_operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1beta1.services.dataset_service import pagers @@ -41,6 +45,10 @@ from google.cloud.aiplatform_v1beta1.types import dataset_service from google.cloud.aiplatform_v1beta1.types import encryption_spec from google.cloud.aiplatform_v1beta1.types import operation as gca_operation +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import struct_pb2 # type: ignore @@ -64,8 +72,11 @@ class DatasetServiceClientMeta(type): _transport_registry["grpc"] = DatasetServiceGrpcTransport _transport_registry["grpc_asyncio"] = DatasetServiceGrpcAsyncIOTransport - def get_transport_class(cls, label: str = None,) -> Type[DatasetServiceTransport]: - """Return an appropriate transport class. + def get_transport_class( + cls, + label: str = None, + ) -> Type[DatasetServiceTransport]: + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -84,11 +95,14 @@ def get_transport_class(cls, label: str = None,) -> Type[DatasetServiceTransport class DatasetServiceClient(metaclass=DatasetServiceClientMeta): - """""" + """The service that handles the CRUD of Vertex AI Dataset and + its child resources. + """ @staticmethod def _get_default_mtls_endpoint(api_endpoint): - """Convert api endpoint to mTLS endpoint. + """Converts api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. Args: @@ -122,7 +136,8 @@ def _get_default_mtls_endpoint(api_endpoint): @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -139,7 +154,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -158,18 +173,23 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> DatasetServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - DatasetServiceTransport: The transport used by the client instance. + DatasetServiceTransport: The transport used by the client + instance. """ return self._transport @staticmethod def annotation_path( - project: str, location: str, dataset: str, data_item: str, annotation: str, + project: str, + location: str, + dataset: str, + data_item: str, + annotation: str, ) -> str: - """Return a fully-qualified annotation string.""" + """Returns a fully-qualified annotation string.""" return "projects/{project}/locations/{location}/datasets/{dataset}/dataItems/{data_item}/annotations/{annotation}".format( project=project, location=location, @@ -180,7 +200,7 @@ def annotation_path( @staticmethod def parse_annotation_path(path: str) -> Dict[str, str]: - """Parse a annotation path into its component segments.""" + """Parses a annotation path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/datasets/(?P.+?)/dataItems/(?P.+?)/annotations/(?P.+?)$", path, @@ -189,9 +209,12 @@ def parse_annotation_path(path: str) -> Dict[str, str]: @staticmethod def annotation_spec_path( - project: str, location: str, dataset: str, annotation_spec: str, + project: str, + location: str, + dataset: str, + annotation_spec: str, ) -> str: - """Return a fully-qualified annotation_spec string.""" + """Returns a fully-qualified annotation_spec string.""" return "projects/{project}/locations/{location}/datasets/{dataset}/annotationSpecs/{annotation_spec}".format( project=project, location=location, @@ -201,7 +224,7 @@ def annotation_spec_path( @staticmethod def parse_annotation_spec_path(path: str) -> Dict[str, str]: - """Parse a annotation_spec path into its component segments.""" + """Parses a annotation_spec path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/datasets/(?P.+?)/annotationSpecs/(?P.+?)$", path, @@ -210,16 +233,22 @@ def parse_annotation_spec_path(path: str) -> Dict[str, str]: @staticmethod def data_item_path( - project: str, location: str, dataset: str, data_item: str, + project: str, + location: str, + dataset: str, + data_item: str, ) -> str: - """Return a fully-qualified data_item string.""" + """Returns a fully-qualified data_item string.""" return "projects/{project}/locations/{location}/datasets/{dataset}/dataItems/{data_item}".format( - project=project, location=location, dataset=dataset, data_item=data_item, + project=project, + location=location, + dataset=dataset, + data_item=data_item, ) @staticmethod def parse_data_item_path(path: str) -> Dict[str, str]: - """Parse a data_item path into its component segments.""" + """Parses a data_item path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/datasets/(?P.+?)/dataItems/(?P.+?)$", path, @@ -227,15 +256,21 @@ def parse_data_item_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def dataset_path(project: str, location: str, dataset: str,) -> str: - """Return a fully-qualified dataset string.""" + def dataset_path( + project: str, + location: str, + dataset: str, + ) -> str: + """Returns a fully-qualified dataset string.""" return "projects/{project}/locations/{location}/datasets/{dataset}".format( - project=project, location=location, dataset=dataset, + project=project, + location=location, + dataset=dataset, ) @staticmethod def parse_dataset_path(path: str) -> Dict[str, str]: - """Parse a dataset path into its component segments.""" + """Parses a dataset path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/datasets/(?P.+?)$", path, @@ -243,8 +278,10 @@ def parse_dataset_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + def common_billing_account_path( + billing_account: str, + ) -> str: + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -256,9 +293,13 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: 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,) + def common_folder_path( + folder: str, + ) -> str: + """Returns a fully-qualified folder string.""" + return "folders/{folder}".format( + folder=folder, + ) @staticmethod def parse_common_folder_path(path: str) -> Dict[str, str]: @@ -267,9 +308,13 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: 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,) + def common_organization_path( + organization: str, + ) -> str: + """Returns a fully-qualified organization string.""" + return "organizations/{organization}".format( + organization=organization, + ) @staticmethod def parse_common_organization_path(path: str) -> Dict[str, str]: @@ -278,9 +323,13 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: 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,) + def common_project_path( + project: str, + ) -> str: + """Returns a fully-qualified project string.""" + return "projects/{project}".format( + project=project, + ) @staticmethod def parse_common_project_path(path: str) -> Dict[str, str]: @@ -289,10 +338,14 @@ def parse_common_project_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_location_path(project: str, location: str,) -> str: - """Return a fully-qualified location string.""" + def common_location_path( + project: str, + location: str, + ) -> str: + """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) @staticmethod @@ -301,6 +354,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + def __init__( self, *, @@ -309,7 +429,7 @@ def __init__( client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the dataset service client. + """Instantiates the dataset service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -351,58 +471,42 @@ def __init__( 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")) + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - client_cert_source_func = ( - mtls.default_client_cert_source() 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" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # 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, DatasetServiceTransport): # transport is a DatasetServiceTransport instance. - if credentials or client_options.credentials_file: + if credentials or client_options.credentials_file or api_key_value: 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." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + Transport = type(self).get_transport_class(transport) self._transport = Transport( credentials=credentials, @@ -412,22 +516,52 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, + always_use_jwt_access=True, ) def create_dataset( self, - request: dataset_service.CreateDatasetRequest = None, + request: Union[dataset_service.CreateDatasetRequest, dict] = None, *, parent: str = None, dataset: gca_dataset.Dataset = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Creates a Dataset. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_create_dataset(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceClient() + + # Initialize request argument(s) + dataset = aiplatform_v1beta1.Dataset() + dataset.display_name = "display_name_value" + dataset.metadata_schema_uri = "metadata_schema_uri_value" + dataset.metadata.null_value = "NULL_VALUE" + + request = aiplatform_v1beta1.CreateDatasetRequest( + parent="parent_value", + dataset=dataset, + ) + + # Make the request + operation = client.create_dataset(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.CreateDatasetRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateDatasetRequest, dict]): The request object. Request message for [DatasetService.CreateDataset][google.cloud.aiplatform.v1beta1.DatasetService.CreateDataset]. parent (str): @@ -459,7 +593,7 @@ def create_dataset( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, dataset]) if request is not None and has_flattened_params: @@ -492,7 +626,12 @@ def create_dataset( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -507,17 +646,36 @@ def create_dataset( def get_dataset( self, - request: dataset_service.GetDatasetRequest = None, + request: Union[dataset_service.GetDatasetRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> dataset.Dataset: r"""Gets a Dataset. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_get_dataset(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetDatasetRequest( + name="name_value", + ) + + # Make the request + response = client.get_dataset(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.GetDatasetRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.GetDatasetRequest, dict]): The request object. Request message for [DatasetService.GetDataset][google.cloud.aiplatform.v1beta1.DatasetService.GetDataset]. name (str): @@ -540,7 +698,7 @@ def get_dataset( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -571,25 +729,54 @@ def get_dataset( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def update_dataset( self, - request: dataset_service.UpdateDatasetRequest = None, + request: Union[dataset_service.UpdateDatasetRequest, dict] = None, *, dataset: gca_dataset.Dataset = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_dataset.Dataset: r"""Updates a Dataset. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_update_dataset(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceClient() + + # Initialize request argument(s) + dataset = aiplatform_v1beta1.Dataset() + dataset.display_name = "display_name_value" + dataset.metadata_schema_uri = "metadata_schema_uri_value" + dataset.metadata.null_value = "NULL_VALUE" + + request = aiplatform_v1beta1.UpdateDatasetRequest( + dataset=dataset, + ) + + # Make the request + response = client.update_dataset(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.UpdateDatasetRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.UpdateDatasetRequest, dict]): The request object. Request message for [DatasetService.UpdateDataset][google.cloud.aiplatform.v1beta1.DatasetService.UpdateDataset]. dataset (google.cloud.aiplatform_v1beta1.types.Dataset): @@ -602,7 +789,7 @@ def update_dataset( update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. The update mask applies to the resource. For the ``FieldMask`` definition, see - `FieldMask `__. + [google.protobuf.FieldMask][google.protobuf.FieldMask]. Updatable fields: - ``display_name`` @@ -625,7 +812,7 @@ def update_dataset( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([dataset, update_mask]) if request is not None and has_flattened_params: @@ -660,24 +847,49 @@ def update_dataset( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_datasets( self, - request: dataset_service.ListDatasetsRequest = None, + request: Union[dataset_service.ListDatasetsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListDatasetsPager: r"""Lists Datasets in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_list_datasets(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListDatasetsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_datasets(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ListDatasetsRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ListDatasetsRequest, dict]): The request object. Request message for [DatasetService.ListDatasets][google.cloud.aiplatform.v1beta1.DatasetService.ListDatasets]. parent (str): @@ -703,7 +915,7 @@ def list_datasets( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -734,12 +946,20 @@ def list_datasets( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListDatasetsPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -747,17 +967,40 @@ def list_datasets( def delete_dataset( self, - request: dataset_service.DeleteDatasetRequest = None, + request: Union[dataset_service.DeleteDatasetRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Deletes a Dataset. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_delete_dataset(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteDatasetRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_dataset(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.DeleteDatasetRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteDatasetRequest, dict]): The request object. Request message for [DatasetService.DeleteDataset][google.cloud.aiplatform.v1beta1.DatasetService.DeleteDataset]. name (str): @@ -794,7 +1037,7 @@ def delete_dataset( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -825,7 +1068,12 @@ def delete_dataset( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -840,18 +1088,46 @@ def delete_dataset( def import_data( self, - request: dataset_service.ImportDataRequest = None, + request: Union[dataset_service.ImportDataRequest, dict] = None, *, name: str = None, import_configs: Sequence[dataset.ImportDataConfig] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Imports data into a Dataset. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_import_data(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceClient() + + # Initialize request argument(s) + import_configs = aiplatform_v1beta1.ImportDataConfig() + import_configs.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + import_configs.import_schema_uri = "import_schema_uri_value" + + request = aiplatform_v1beta1.ImportDataRequest( + name="name_value", + import_configs=import_configs, + ) + + # Make the request + operation = client.import_data(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ImportDataRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ImportDataRequest, dict]): The request object. Request message for [DatasetService.ImportData][google.cloud.aiplatform.v1beta1.DatasetService.ImportData]. name (str): @@ -886,7 +1162,7 @@ def import_data( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, import_configs]) if request is not None and has_flattened_params: @@ -919,7 +1195,12 @@ def import_data( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -934,18 +1215,45 @@ def import_data( def export_data( self, - request: dataset_service.ExportDataRequest = None, + request: Union[dataset_service.ExportDataRequest, dict] = None, *, name: str = None, export_config: dataset.ExportDataConfig = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Exports data from a Dataset. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_export_data(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceClient() + + # Initialize request argument(s) + export_config = aiplatform_v1beta1.ExportDataConfig() + export_config.gcs_destination.output_uri_prefix = "output_uri_prefix_value" + + request = aiplatform_v1beta1.ExportDataRequest( + name="name_value", + export_config=export_config, + ) + + # Make the request + operation = client.export_data(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ExportDataRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ExportDataRequest, dict]): The request object. Request message for [DatasetService.ExportData][google.cloud.aiplatform.v1beta1.DatasetService.ExportData]. name (str): @@ -979,7 +1287,7 @@ def export_data( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, export_config]) if request is not None and has_flattened_params: @@ -1012,7 +1320,12 @@ def export_data( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -1027,17 +1340,37 @@ def export_data( def list_data_items( self, - request: dataset_service.ListDataItemsRequest = None, + request: Union[dataset_service.ListDataItemsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListDataItemsPager: r"""Lists DataItems in a Dataset. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_list_data_items(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListDataItemsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_data_items(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ListDataItemsRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ListDataItemsRequest, dict]): The request object. Request message for [DatasetService.ListDataItems][google.cloud.aiplatform.v1beta1.DatasetService.ListDataItems]. parent (str): @@ -1064,7 +1397,7 @@ def list_data_items( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1095,12 +1428,20 @@ def list_data_items( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListDataItemsPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -1108,17 +1449,36 @@ def list_data_items( def get_annotation_spec( self, - request: dataset_service.GetAnnotationSpecRequest = None, + request: Union[dataset_service.GetAnnotationSpecRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> annotation_spec.AnnotationSpec: r"""Gets an AnnotationSpec. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_get_annotation_spec(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetAnnotationSpecRequest( + name="name_value", + ) + + # Make the request + response = client.get_annotation_spec(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.GetAnnotationSpecRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.GetAnnotationSpecRequest, dict]): The request object. Request message for [DatasetService.GetAnnotationSpec][google.cloud.aiplatform.v1beta1.DatasetService.GetAnnotationSpec]. name (str): @@ -1142,7 +1502,7 @@ def get_annotation_spec( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1173,24 +1533,49 @@ def get_annotation_spec( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_annotations( self, - request: dataset_service.ListAnnotationsRequest = None, + request: Union[dataset_service.ListAnnotationsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListAnnotationsPager: r"""Lists Annotations belongs to a dataitem + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_list_annotations(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListAnnotationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_annotations(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ListAnnotationsRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ListAnnotationsRequest, dict]): The request object. Request message for [DatasetService.ListAnnotations][google.cloud.aiplatform.v1beta1.DatasetService.ListAnnotations]. parent (str): @@ -1217,7 +1602,7 @@ def list_annotations( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1248,12 +1633,704 @@ def list_annotations( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListAnnotationsPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_operations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.delete_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.wait_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_location, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_locations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) # Done; return the response. diff --git a/google/cloud/aiplatform_v1beta1/services/dataset_service/pagers.py b/google/cloud/aiplatform_v1beta1/services/dataset_service/pagers.py index f57caea0a6..3aa11a54bb 100644 --- a/google/cloud/aiplatform_v1beta1/services/dataset_service/pagers.py +++ b/google/cloud/aiplatform_v1beta1/services/dataset_service/pagers.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,13 +15,13 @@ # from typing import ( Any, - AsyncIterable, + AsyncIterator, Awaitable, Callable, - Iterable, Sequence, Tuple, Optional, + Iterator, ) from google.cloud.aiplatform_v1beta1.types import annotation @@ -77,14 +77,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[dataset_service.ListDatasetsResponse]: + def pages(self) -> Iterator[dataset_service.ListDatasetsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[dataset.Dataset]: + def __iter__(self) -> Iterator[dataset.Dataset]: for page in self.pages: yield from page.datasets @@ -118,7 +118,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -139,14 +139,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - async def pages(self) -> AsyncIterable[dataset_service.ListDatasetsResponse]: + async def pages(self) -> AsyncIterator[dataset_service.ListDatasetsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[dataset.Dataset]: + def __aiter__(self) -> AsyncIterator[dataset.Dataset]: async def async_generator(): async for page in self.pages: for response in page.datasets: @@ -205,14 +205,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[dataset_service.ListDataItemsResponse]: + def pages(self) -> Iterator[dataset_service.ListDataItemsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[data_item.DataItem]: + def __iter__(self) -> Iterator[data_item.DataItem]: for page in self.pages: yield from page.data_items @@ -246,7 +246,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -267,14 +267,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - async def pages(self) -> AsyncIterable[dataset_service.ListDataItemsResponse]: + async def pages(self) -> AsyncIterator[dataset_service.ListDataItemsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[data_item.DataItem]: + def __aiter__(self) -> AsyncIterator[data_item.DataItem]: async def async_generator(): async for page in self.pages: for response in page.data_items: @@ -333,14 +333,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[dataset_service.ListAnnotationsResponse]: + def pages(self) -> Iterator[dataset_service.ListAnnotationsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[annotation.Annotation]: + def __iter__(self) -> Iterator[annotation.Annotation]: for page in self.pages: yield from page.annotations @@ -374,7 +374,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -395,14 +395,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - async def pages(self) -> AsyncIterable[dataset_service.ListAnnotationsResponse]: + async def pages(self) -> AsyncIterator[dataset_service.ListAnnotationsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[annotation.Annotation]: + def __aiter__(self) -> AsyncIterator[annotation.Annotation]: async def async_generator(): async for page in self.pages: for response in page.annotations: diff --git a/google/cloud/aiplatform_v1beta1/services/dataset_service/transports/__init__.py b/google/cloud/aiplatform_v1beta1/services/dataset_service/transports/__init__.py index 902a4fb01f..07bc11c0c8 100644 --- a/google/cloud/aiplatform_v1beta1/services/dataset_service/transports/__init__.py +++ b/google/cloud/aiplatform_v1beta1/services/dataset_service/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1beta1/services/dataset_service/transports/base.py b/google/cloud/aiplatform_v1beta1/services/dataset_service/transports/base.py index f7998abdf1..81a62ded26 100644 --- a/google/cloud/aiplatform_v1beta1/services/dataset_service/transports/base.py +++ b/google/cloud/aiplatform_v1beta1/services/dataset_service/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,21 +15,25 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.api_core import operations_v1 # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.aiplatform_v1beta1.types import annotation_spec from google.cloud.aiplatform_v1beta1.types import dataset from google.cloud.aiplatform_v1beta1.types import dataset as gca_dataset from google.cloud.aiplatform_v1beta1.types import dataset_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore try: @@ -41,17 +45,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - -_API_CORE_VERSION = google.api_core.__version__ - class DatasetServiceTransport(abc.ABC): """Abstract transport class for DatasetService.""" @@ -69,6 +62,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -92,16 +86,19 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -114,97 +111,88 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id ) - # Save the credentials. - self._credentials = credentials - - # TODO(busunkim): These two class methods are in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-api-core - # and google-auth are increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") + # If the credentials are service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs + credentials = credentials.with_always_use_jwt_access(True) - # TODO: Remove this function once google-api-core >= 1.26.0 is required - @classmethod - def _get_self_signed_jwt_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Union[Optional[Sequence[str]], str]]: - """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" - - self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} - - if _API_CORE_VERSION and ( - packaging.version.parse(_API_CORE_VERSION) - >= packaging.version.parse("1.26.0") - ): - self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES - self_signed_jwt_kwargs["scopes"] = scopes - self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST - else: - self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES - - return self_signed_jwt_kwargs + # Save the credentials. + self._credentials = credentials def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { self.create_dataset: gapic_v1.method.wrap_method( - self.create_dataset, default_timeout=5.0, client_info=client_info, + self.create_dataset, + default_timeout=5.0, + client_info=client_info, ), self.get_dataset: gapic_v1.method.wrap_method( - self.get_dataset, default_timeout=5.0, client_info=client_info, + self.get_dataset, + default_timeout=5.0, + client_info=client_info, ), self.update_dataset: gapic_v1.method.wrap_method( - self.update_dataset, default_timeout=5.0, client_info=client_info, + self.update_dataset, + default_timeout=5.0, + client_info=client_info, ), self.list_datasets: gapic_v1.method.wrap_method( - self.list_datasets, default_timeout=5.0, client_info=client_info, + self.list_datasets, + default_timeout=5.0, + client_info=client_info, ), self.delete_dataset: gapic_v1.method.wrap_method( - self.delete_dataset, default_timeout=5.0, client_info=client_info, + self.delete_dataset, + default_timeout=5.0, + client_info=client_info, ), self.import_data: gapic_v1.method.wrap_method( - self.import_data, default_timeout=5.0, client_info=client_info, + self.import_data, + default_timeout=5.0, + client_info=client_info, ), self.export_data: gapic_v1.method.wrap_method( - self.export_data, default_timeout=5.0, client_info=client_info, + self.export_data, + default_timeout=5.0, + client_info=client_info, ), self.list_data_items: gapic_v1.method.wrap_method( - self.list_data_items, default_timeout=5.0, client_info=client_info, + self.list_data_items, + default_timeout=5.0, + client_info=client_info, ), self.get_annotation_spec: gapic_v1.method.wrap_method( - self.get_annotation_spec, default_timeout=5.0, client_info=client_info, + self.get_annotation_spec, + default_timeout=5.0, + client_info=client_info, ), self.list_annotations: gapic_v1.method.wrap_method( - self.list_annotations, default_timeout=5.0, client_info=client_info, + self.list_annotations, + default_timeout=5.0, + client_info=client_info, ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() @@ -309,5 +297,102 @@ def list_annotations( ]: raise NotImplementedError() + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], + Union[ + operations_pb2.ListOperationsResponse, + Awaitable[operations_pb2.ListOperationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None,]: + raise NotImplementedError() + + @property + def wait_operation( + self, + ) -> Callable[ + [operations_pb2.WaitOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def set_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def get_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_location( + self, + ) -> Callable[ + [locations_pb2.GetLocationRequest], + Union[locations_pb2.Location, Awaitable[locations_pb2.Location]], + ]: + raise NotImplementedError() + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], + Union[ + locations_pb2.ListLocationsResponse, + Awaitable[locations_pb2.ListLocationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + __all__ = ("DatasetServiceTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/dataset_service/transports/grpc.py b/google/cloud/aiplatform_v1beta1/services/dataset_service/transports/grpc.py index acadef836f..034a7e2c38 100644 --- a/google/cloud/aiplatform_v1beta1/services/dataset_service/transports/grpc.py +++ b/google/cloud/aiplatform_v1beta1/services/dataset_service/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,9 +16,9 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import operations_v1 +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -29,6 +29,10 @@ from google.cloud.aiplatform_v1beta1.types import dataset from google.cloud.aiplatform_v1beta1.types import dataset as gca_dataset from google.cloud.aiplatform_v1beta1.types import dataset_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from .base import DatasetServiceTransport, DEFAULT_CLIENT_INFO @@ -36,6 +40,9 @@ class DatasetServiceGrpcTransport(DatasetServiceTransport): """gRPC backend transport for DatasetService. + The service that handles the CRUD of Vertex AI Dataset and + its child resources. + This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation and call it. @@ -60,6 +67,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -82,16 +90,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -100,6 +108,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport @@ -110,7 +120,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -153,13 +163,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -208,21 +222,20 @@ def create_channel( and ``credentials_file`` are passed. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @property def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ + """Return the channel designed to connect to this service.""" return self._grpc_channel @property @@ -232,7 +245,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsClient(self.grpc_channel) @@ -508,5 +521,215 @@ def list_annotations( ) return self._stubs["list_annotations"] + def close(self): + self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + @property + def kind(self) -> str: + return "grpc" + __all__ = ("DatasetServiceGrpcTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/dataset_service/transports/grpc_asyncio.py b/google/cloud/aiplatform_v1beta1/services/dataset_service/transports/grpc_asyncio.py index adee8b98ea..551a034250 100644 --- a/google/cloud/aiplatform_v1beta1/services/dataset_service/transports/grpc_asyncio.py +++ b/google/cloud/aiplatform_v1beta1/services/dataset_service/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,12 +16,11 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore -from google.api_core import operations_v1 # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore @@ -30,6 +29,10 @@ from google.cloud.aiplatform_v1beta1.types import dataset from google.cloud.aiplatform_v1beta1.types import dataset as gca_dataset from google.cloud.aiplatform_v1beta1.types import dataset_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from .base import DatasetServiceTransport, DEFAULT_CLIENT_INFO from .grpc import DatasetServiceGrpcTransport @@ -38,6 +41,9 @@ class DatasetServiceGrpcAsyncIOTransport(DatasetServiceTransport): """gRPC AsyncIO backend transport for DatasetService. + The service that handles the CRUD of Vertex AI Dataset and + its child resources. + This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation and call it. @@ -81,14 +87,14 @@ def create_channel( aio.Channel: A gRPC AsyncIO channel object. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @@ -106,6 +112,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -129,16 +136,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -147,6 +154,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport @@ -157,7 +166,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -199,13 +208,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -235,7 +248,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel @@ -526,5 +539,211 @@ def list_annotations( ) return self._stubs["list_annotations"] + def close(self): + return self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + __all__ = ("DatasetServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/endpoint_service/__init__.py b/google/cloud/aiplatform_v1beta1/services/endpoint_service/__init__.py index 96fb4ad6d6..3c37159f9d 100644 --- a/google/cloud/aiplatform_v1beta1/services/endpoint_service/__init__.py +++ b/google/cloud/aiplatform_v1beta1/services/endpoint_service/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1beta1/services/endpoint_service/async_client.py b/google/cloud/aiplatform_v1beta1/services/endpoint_service/async_client.py index fc38381f98..7bf281970f 100644 --- a/google/cloud/aiplatform_v1beta1/services/endpoint_service/async_client.py +++ b/google/cloud/aiplatform_v1beta1/services/endpoint_service/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,16 +16,21 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation as gac_operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1beta1.services.endpoint_service import pagers @@ -34,6 +39,10 @@ from google.cloud.aiplatform_v1beta1.types import endpoint as gca_endpoint from google.cloud.aiplatform_v1beta1.types import endpoint_service from google.cloud.aiplatform_v1beta1.types import operation as gca_operation +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore @@ -43,7 +52,7 @@ class EndpointServiceAsyncClient: - """""" + """A service for managing Vertex AI's Endpoints.""" _client: EndpointServiceClient @@ -54,6 +63,14 @@ class EndpointServiceAsyncClient: parse_endpoint_path = staticmethod(EndpointServiceClient.parse_endpoint_path) model_path = staticmethod(EndpointServiceClient.model_path) parse_model_path = staticmethod(EndpointServiceClient.parse_model_path) + model_deployment_monitoring_job_path = staticmethod( + EndpointServiceClient.model_deployment_monitoring_job_path + ) + parse_model_deployment_monitoring_job_path = staticmethod( + EndpointServiceClient.parse_model_deployment_monitoring_job_path + ) + network_path = staticmethod(EndpointServiceClient.network_path) + parse_network_path = staticmethod(EndpointServiceClient.parse_network_path) common_billing_account_path = staticmethod( EndpointServiceClient.common_billing_account_path ) @@ -81,7 +98,8 @@ class EndpointServiceAsyncClient: @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -96,7 +114,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -111,9 +129,45 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return EndpointServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> EndpointServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: EndpointServiceTransport: The transport used by the client instance. @@ -132,7 +186,7 @@ def __init__( client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the endpoint service client. + """Instantiates the endpoint service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -173,18 +227,46 @@ def __init__( async def create_endpoint( self, - request: endpoint_service.CreateEndpointRequest = None, + request: Union[endpoint_service.CreateEndpointRequest, dict] = None, *, parent: str = None, endpoint: gca_endpoint.Endpoint = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + endpoint_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Creates an Endpoint. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_create_endpoint(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + endpoint = aiplatform_v1beta1.Endpoint() + endpoint.display_name = "display_name_value" + + request = aiplatform_v1beta1.CreateEndpointRequest( + parent="parent_value", + endpoint=endpoint, + ) + + # Make the request + operation = client.create_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.CreateEndpointRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateEndpointRequest, dict]): The request object. Request message for [EndpointService.CreateEndpoint][google.cloud.aiplatform.v1beta1.EndpointService.CreateEndpoint]. parent (:class:`str`): @@ -200,6 +282,21 @@ async def create_endpoint( This corresponds to the ``endpoint`` field on the ``request`` instance; if ``request`` is provided, this should not be set. + endpoint_id (:class:`str`): + Immutable. The ID to use for endpoint, which will become + the final component of the endpoint resource name. If + not provided, Vertex AI will generate a value for this + ID. + + This value should be 1-10 characters, and valid + characters are /[0-9]/. When using HTTP/JSON, this field + is populated based on a query string argument, such as + ``?endpoint_id=12345``. This is the fallback for fields + that are not included in either the URI or the body. + + This corresponds to the ``endpoint_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. @@ -215,9 +312,9 @@ async def create_endpoint( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, endpoint]) + has_flattened_params = any([parent, endpoint, endpoint_id]) if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " @@ -232,6 +329,8 @@ async def create_endpoint( request.parent = parent if endpoint is not None: request.endpoint = endpoint + if endpoint_id is not None: + request.endpoint_id = endpoint_id # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -248,7 +347,12 @@ async def create_endpoint( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -263,17 +367,36 @@ async def create_endpoint( async def get_endpoint( self, - request: endpoint_service.GetEndpointRequest = None, + request: Union[endpoint_service.GetEndpointRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> endpoint.Endpoint: r"""Gets an Endpoint. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_get_endpoint(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetEndpointRequest( + name="name_value", + ) + + # Make the request + response = await client.get_endpoint(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.GetEndpointRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.GetEndpointRequest, dict]): The request object. Request message for [EndpointService.GetEndpoint][google.cloud.aiplatform.v1beta1.EndpointService.GetEndpoint] name (:class:`str`): @@ -297,7 +420,7 @@ async def get_endpoint( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -328,24 +451,49 @@ async def get_endpoint( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_endpoints( self, - request: endpoint_service.ListEndpointsRequest = None, + request: Union[endpoint_service.ListEndpointsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListEndpointsAsyncPager: r"""Lists Endpoints in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_list_endpoints(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListEndpointsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_endpoints(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ListEndpointsRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ListEndpointsRequest, dict]): The request object. Request message for [EndpointService.ListEndpoints][google.cloud.aiplatform.v1beta1.EndpointService.ListEndpoints]. parent (:class:`str`): @@ -372,7 +520,7 @@ async def list_endpoints( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -403,12 +551,20 @@ async def list_endpoints( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListEndpointsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -416,18 +572,40 @@ async def list_endpoints( async def update_endpoint( self, - request: endpoint_service.UpdateEndpointRequest = None, + request: Union[endpoint_service.UpdateEndpointRequest, dict] = None, *, endpoint: gca_endpoint.Endpoint = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_endpoint.Endpoint: r"""Updates an Endpoint. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_update_endpoint(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + endpoint = aiplatform_v1beta1.Endpoint() + endpoint.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateEndpointRequest( + endpoint=endpoint, + ) + + # Make the request + response = await client.update_endpoint(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.UpdateEndpointRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.UpdateEndpointRequest, dict]): The request object. Request message for [EndpointService.UpdateEndpoint][google.cloud.aiplatform.v1beta1.EndpointService.UpdateEndpoint]. endpoint (:class:`google.cloud.aiplatform_v1beta1.types.Endpoint`): @@ -439,7 +617,7 @@ async def update_endpoint( should not be set. update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): Required. The update mask applies to the resource. See - `FieldMask `__. + [google.protobuf.FieldMask][google.protobuf.FieldMask]. This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this @@ -458,7 +636,7 @@ async def update_endpoint( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([endpoint, update_mask]) if request is not None and has_flattened_params: @@ -493,24 +671,52 @@ async def update_endpoint( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def delete_endpoint( self, - request: endpoint_service.DeleteEndpointRequest = None, + request: Union[endpoint_service.DeleteEndpointRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes an Endpoint. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_delete_endpoint(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteEndpointRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.DeleteEndpointRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteEndpointRequest, dict]): The request object. Request message for [EndpointService.DeleteEndpoint][google.cloud.aiplatform.v1beta1.EndpointService.DeleteEndpoint]. name (:class:`str`): @@ -547,7 +753,7 @@ async def delete_endpoint( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -578,7 +784,12 @@ async def delete_endpoint( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -593,22 +804,48 @@ async def delete_endpoint( async def deploy_model( self, - request: endpoint_service.DeployModelRequest = None, + request: Union[endpoint_service.DeployModelRequest, dict] = None, *, endpoint: str = None, deployed_model: gca_endpoint.DeployedModel = None, - traffic_split: Sequence[ - endpoint_service.DeployModelRequest.TrafficSplitEntry - ] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + traffic_split: Mapping[str, int] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deploys a Model into this Endpoint, creating a DeployedModel within it. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_deploy_model(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + deployed_model = aiplatform_v1beta1.DeployedModel() + deployed_model.dedicated_resources.min_replica_count = 1803 + deployed_model.model = "model_value" + + request = aiplatform_v1beta1.DeployModelRequest( + endpoint="endpoint_value", + deployed_model=deployed_model, + ) + + # Make the request + operation = client.deploy_model(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.DeployModelRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.DeployModelRequest, dict]): The request object. Request message for [EndpointService.DeployModel][google.cloud.aiplatform.v1beta1.EndpointService.DeployModel]. endpoint (:class:`str`): @@ -630,7 +867,7 @@ async def deploy_model( This corresponds to the ``deployed_model`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - traffic_split (:class:`Sequence[google.cloud.aiplatform_v1beta1.types.DeployModelRequest.TrafficSplitEntry]`): + traffic_split (:class:`Mapping[str, int]`): A map from a DeployedModel's ID to the percentage of this Endpoint's traffic that should be forwarded to that DeployedModel. @@ -667,7 +904,7 @@ async def deploy_model( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([endpoint, deployed_model, traffic_split]) if request is not None and has_flattened_params: @@ -703,7 +940,12 @@ async def deploy_model( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -718,14 +960,12 @@ async def deploy_model( async def undeploy_model( self, - request: endpoint_service.UndeployModelRequest = None, + request: Union[endpoint_service.UndeployModelRequest, dict] = None, *, endpoint: str = None, deployed_model_id: str = None, - traffic_split: Sequence[ - endpoint_service.UndeployModelRequest.TrafficSplitEntry - ] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + traffic_split: Mapping[str, int] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -733,8 +973,32 @@ async def undeploy_model( DeployedModel from it, and freeing all resources it's using. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_undeploy_model(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UndeployModelRequest( + endpoint="endpoint_value", + deployed_model_id="deployed_model_id_value", + ) + + # Make the request + operation = client.undeploy_model(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.UndeployModelRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.UndeployModelRequest, dict]): The request object. Request message for [EndpointService.UndeployModel][google.cloud.aiplatform.v1beta1.EndpointService.UndeployModel]. endpoint (:class:`str`): @@ -752,7 +1016,7 @@ async def undeploy_model( This corresponds to the ``deployed_model_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - traffic_split (:class:`Sequence[google.cloud.aiplatform_v1beta1.types.UndeployModelRequest.TrafficSplitEntry]`): + traffic_split (:class:`Mapping[str, int]`): If this field is provided, then the Endpoint's [traffic_split][google.cloud.aiplatform.v1beta1.Endpoint.traffic_split] will be overwritten with it. If last DeployedModel is @@ -783,7 +1047,7 @@ async def undeploy_model( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([endpoint, deployed_model_id, traffic_split]) if request is not None and has_flattened_params: @@ -819,7 +1083,12 @@ async def undeploy_model( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -832,6 +1101,683 @@ async def undeploy_model( # Done; return the response. return response + async def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_operations, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.delete_operation, + default_timeout=None, + 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 cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + 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 wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.wait_operation, + default_timeout=None, + 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 set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_location, + default_timeout=None, + 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 list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_locations, + default_timeout=None, + 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 __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/aiplatform_v1beta1/services/endpoint_service/client.py b/google/cloud/aiplatform_v1beta1/services/endpoint_service/client.py index 2b9b6b1146..2092d51e6a 100644 --- a/google/cloud/aiplatform_v1beta1/services/endpoint_service/client.py +++ b/google/cloud/aiplatform_v1beta1/services/endpoint_service/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,22 +14,26 @@ # 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 +from typing import Dict, Mapping, 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 as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_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 +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation as gac_operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1beta1.services.endpoint_service import pagers @@ -38,6 +42,10 @@ from google.cloud.aiplatform_v1beta1.types import endpoint as gca_endpoint from google.cloud.aiplatform_v1beta1.types import endpoint_service from google.cloud.aiplatform_v1beta1.types import operation as gca_operation +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore @@ -60,8 +68,11 @@ class EndpointServiceClientMeta(type): _transport_registry["grpc"] = EndpointServiceGrpcTransport _transport_registry["grpc_asyncio"] = EndpointServiceGrpcAsyncIOTransport - def get_transport_class(cls, label: str = None,) -> Type[EndpointServiceTransport]: - """Return an appropriate transport class. + def get_transport_class( + cls, + label: str = None, + ) -> Type[EndpointServiceTransport]: + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -80,11 +91,12 @@ def get_transport_class(cls, label: str = None,) -> Type[EndpointServiceTranspor class EndpointServiceClient(metaclass=EndpointServiceClientMeta): - """""" + """A service for managing Vertex AI's Endpoints.""" @staticmethod def _get_default_mtls_endpoint(api_endpoint): - """Convert api endpoint to mTLS endpoint. + """Converts api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. Args: @@ -118,7 +130,8 @@ def _get_default_mtls_endpoint(api_endpoint): @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -135,7 +148,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -154,23 +167,30 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> EndpointServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - EndpointServiceTransport: The transport used by the client instance. + EndpointServiceTransport: The transport used by the client + instance. """ return self._transport @staticmethod - def endpoint_path(project: str, location: str, endpoint: str,) -> str: - """Return a fully-qualified endpoint string.""" + def endpoint_path( + project: str, + location: str, + endpoint: str, + ) -> str: + """Returns a fully-qualified endpoint string.""" return "projects/{project}/locations/{location}/endpoints/{endpoint}".format( - project=project, location=location, endpoint=endpoint, + project=project, + location=location, + endpoint=endpoint, ) @staticmethod def parse_endpoint_path(path: str) -> Dict[str, str]: - """Parse a endpoint path into its component segments.""" + """Parses a endpoint path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/endpoints/(?P.+?)$", path, @@ -178,15 +198,21 @@ def parse_endpoint_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def model_path(project: str, location: str, model: str,) -> str: - """Return a fully-qualified model string.""" + def model_path( + project: str, + location: str, + model: str, + ) -> str: + """Returns a fully-qualified model string.""" return "projects/{project}/locations/{location}/models/{model}".format( - project=project, location=location, model=model, + project=project, + location=location, + model=model, ) @staticmethod def parse_model_path(path: str) -> Dict[str, str]: - """Parse a model path into its component segments.""" + """Parses a model path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/models/(?P.+?)$", path, @@ -194,8 +220,51 @@ def parse_model_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + def model_deployment_monitoring_job_path( + project: str, + location: str, + model_deployment_monitoring_job: str, + ) -> str: + """Returns a fully-qualified model_deployment_monitoring_job string.""" + return "projects/{project}/locations/{location}/modelDeploymentMonitoringJobs/{model_deployment_monitoring_job}".format( + project=project, + location=location, + model_deployment_monitoring_job=model_deployment_monitoring_job, + ) + + @staticmethod + def parse_model_deployment_monitoring_job_path(path: str) -> Dict[str, str]: + """Parses a model_deployment_monitoring_job path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/modelDeploymentMonitoringJobs/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def network_path( + project: str, + network: str, + ) -> str: + """Returns a fully-qualified network string.""" + return "projects/{project}/global/networks/{network}".format( + project=project, + network=network, + ) + + @staticmethod + def parse_network_path(path: str) -> Dict[str, str]: + """Parses a network path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/global/networks/(?P.+?)$", path + ) + return m.groupdict() if m else {} + + @staticmethod + def common_billing_account_path( + billing_account: str, + ) -> str: + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -207,9 +276,13 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: 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,) + def common_folder_path( + folder: str, + ) -> str: + """Returns a fully-qualified folder string.""" + return "folders/{folder}".format( + folder=folder, + ) @staticmethod def parse_common_folder_path(path: str) -> Dict[str, str]: @@ -218,9 +291,13 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: 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,) + def common_organization_path( + organization: str, + ) -> str: + """Returns a fully-qualified organization string.""" + return "organizations/{organization}".format( + organization=organization, + ) @staticmethod def parse_common_organization_path(path: str) -> Dict[str, str]: @@ -229,9 +306,13 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: 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,) + def common_project_path( + project: str, + ) -> str: + """Returns a fully-qualified project string.""" + return "projects/{project}".format( + project=project, + ) @staticmethod def parse_common_project_path(path: str) -> Dict[str, str]: @@ -240,10 +321,14 @@ def parse_common_project_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_location_path(project: str, location: str,) -> str: - """Return a fully-qualified location string.""" + def common_location_path( + project: str, + location: str, + ) -> str: + """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) @staticmethod @@ -252,6 +337,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + def __init__( self, *, @@ -260,7 +412,7 @@ def __init__( client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the endpoint service client. + """Instantiates the endpoint service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -302,58 +454,42 @@ def __init__( 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")) + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - client_cert_source_func = ( - mtls.default_client_cert_source() 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" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # 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, EndpointServiceTransport): # transport is a EndpointServiceTransport instance. - if credentials or client_options.credentials_file: + if credentials or client_options.credentials_file or api_key_value: 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." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + Transport = type(self).get_transport_class(transport) self._transport = Transport( credentials=credentials, @@ -363,22 +499,51 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, + always_use_jwt_access=True, ) def create_endpoint( self, - request: endpoint_service.CreateEndpointRequest = None, + request: Union[endpoint_service.CreateEndpointRequest, dict] = None, *, parent: str = None, endpoint: gca_endpoint.Endpoint = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + endpoint_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Creates an Endpoint. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_create_endpoint(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceClient() + + # Initialize request argument(s) + endpoint = aiplatform_v1beta1.Endpoint() + endpoint.display_name = "display_name_value" + + request = aiplatform_v1beta1.CreateEndpointRequest( + parent="parent_value", + endpoint=endpoint, + ) + + # Make the request + operation = client.create_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.CreateEndpointRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateEndpointRequest, dict]): The request object. Request message for [EndpointService.CreateEndpoint][google.cloud.aiplatform.v1beta1.EndpointService.CreateEndpoint]. parent (str): @@ -394,6 +559,21 @@ def create_endpoint( This corresponds to the ``endpoint`` field on the ``request`` instance; if ``request`` is provided, this should not be set. + endpoint_id (str): + Immutable. The ID to use for endpoint, which will become + the final component of the endpoint resource name. If + not provided, Vertex AI will generate a value for this + ID. + + This value should be 1-10 characters, and valid + characters are /[0-9]/. When using HTTP/JSON, this field + is populated based on a query string argument, such as + ``?endpoint_id=12345``. This is the fallback for fields + that are not included in either the URI or the body. + + This corresponds to the ``endpoint_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. @@ -409,9 +589,9 @@ def create_endpoint( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, endpoint]) + has_flattened_params = any([parent, endpoint, endpoint_id]) if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " @@ -430,6 +610,8 @@ def create_endpoint( request.parent = parent if endpoint is not None: request.endpoint = endpoint + if endpoint_id is not None: + request.endpoint_id = endpoint_id # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -442,7 +624,12 @@ def create_endpoint( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -457,17 +644,36 @@ def create_endpoint( def get_endpoint( self, - request: endpoint_service.GetEndpointRequest = None, + request: Union[endpoint_service.GetEndpointRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> endpoint.Endpoint: r"""Gets an Endpoint. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_get_endpoint(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetEndpointRequest( + name="name_value", + ) + + # Make the request + response = client.get_endpoint(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.GetEndpointRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.GetEndpointRequest, dict]): The request object. Request message for [EndpointService.GetEndpoint][google.cloud.aiplatform.v1beta1.EndpointService.GetEndpoint] name (str): @@ -491,7 +697,7 @@ def get_endpoint( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -522,24 +728,49 @@ def get_endpoint( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_endpoints( self, - request: endpoint_service.ListEndpointsRequest = None, + request: Union[endpoint_service.ListEndpointsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListEndpointsPager: r"""Lists Endpoints in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_list_endpoints(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListEndpointsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_endpoints(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ListEndpointsRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ListEndpointsRequest, dict]): The request object. Request message for [EndpointService.ListEndpoints][google.cloud.aiplatform.v1beta1.EndpointService.ListEndpoints]. parent (str): @@ -566,7 +797,7 @@ def list_endpoints( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -597,12 +828,20 @@ def list_endpoints( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListEndpointsPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -610,18 +849,40 @@ def list_endpoints( def update_endpoint( self, - request: endpoint_service.UpdateEndpointRequest = None, + request: Union[endpoint_service.UpdateEndpointRequest, dict] = None, *, endpoint: gca_endpoint.Endpoint = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_endpoint.Endpoint: r"""Updates an Endpoint. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_update_endpoint(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceClient() + + # Initialize request argument(s) + endpoint = aiplatform_v1beta1.Endpoint() + endpoint.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateEndpointRequest( + endpoint=endpoint, + ) + + # Make the request + response = client.update_endpoint(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.UpdateEndpointRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.UpdateEndpointRequest, dict]): The request object. Request message for [EndpointService.UpdateEndpoint][google.cloud.aiplatform.v1beta1.EndpointService.UpdateEndpoint]. endpoint (google.cloud.aiplatform_v1beta1.types.Endpoint): @@ -633,7 +894,7 @@ def update_endpoint( should not be set. update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. The update mask applies to the resource. See - `FieldMask `__. + [google.protobuf.FieldMask][google.protobuf.FieldMask]. This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this @@ -652,7 +913,7 @@ def update_endpoint( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([endpoint, update_mask]) if request is not None and has_flattened_params: @@ -687,24 +948,52 @@ def update_endpoint( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def delete_endpoint( self, - request: endpoint_service.DeleteEndpointRequest = None, + request: Union[endpoint_service.DeleteEndpointRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Deletes an Endpoint. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_delete_endpoint(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteEndpointRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.DeleteEndpointRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteEndpointRequest, dict]): The request object. Request message for [EndpointService.DeleteEndpoint][google.cloud.aiplatform.v1beta1.EndpointService.DeleteEndpoint]. name (str): @@ -741,7 +1030,7 @@ def delete_endpoint( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -772,7 +1061,12 @@ def delete_endpoint( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -787,22 +1081,48 @@ def delete_endpoint( def deploy_model( self, - request: endpoint_service.DeployModelRequest = None, + request: Union[endpoint_service.DeployModelRequest, dict] = None, *, endpoint: str = None, deployed_model: gca_endpoint.DeployedModel = None, - traffic_split: Sequence[ - endpoint_service.DeployModelRequest.TrafficSplitEntry - ] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + traffic_split: Mapping[str, int] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Deploys a Model into this Endpoint, creating a DeployedModel within it. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_deploy_model(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceClient() + + # Initialize request argument(s) + deployed_model = aiplatform_v1beta1.DeployedModel() + deployed_model.dedicated_resources.min_replica_count = 1803 + deployed_model.model = "model_value" + + request = aiplatform_v1beta1.DeployModelRequest( + endpoint="endpoint_value", + deployed_model=deployed_model, + ) + + # Make the request + operation = client.deploy_model(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.DeployModelRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.DeployModelRequest, dict]): The request object. Request message for [EndpointService.DeployModel][google.cloud.aiplatform.v1beta1.EndpointService.DeployModel]. endpoint (str): @@ -824,7 +1144,7 @@ def deploy_model( This corresponds to the ``deployed_model`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - traffic_split (Sequence[google.cloud.aiplatform_v1beta1.types.DeployModelRequest.TrafficSplitEntry]): + traffic_split (Mapping[str, int]): A map from a DeployedModel's ID to the percentage of this Endpoint's traffic that should be forwarded to that DeployedModel. @@ -861,7 +1181,7 @@ def deploy_model( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([endpoint, deployed_model, traffic_split]) if request is not None and has_flattened_params: @@ -896,7 +1216,12 @@ def deploy_model( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -911,14 +1236,12 @@ def deploy_model( def undeploy_model( self, - request: endpoint_service.UndeployModelRequest = None, + request: Union[endpoint_service.UndeployModelRequest, dict] = None, *, endpoint: str = None, deployed_model_id: str = None, - traffic_split: Sequence[ - endpoint_service.UndeployModelRequest.TrafficSplitEntry - ] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + traffic_split: Mapping[str, int] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: @@ -926,8 +1249,32 @@ def undeploy_model( DeployedModel from it, and freeing all resources it's using. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_undeploy_model(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UndeployModelRequest( + endpoint="endpoint_value", + deployed_model_id="deployed_model_id_value", + ) + + # Make the request + operation = client.undeploy_model(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.UndeployModelRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.UndeployModelRequest, dict]): The request object. Request message for [EndpointService.UndeployModel][google.cloud.aiplatform.v1beta1.EndpointService.UndeployModel]. endpoint (str): @@ -945,7 +1292,7 @@ def undeploy_model( This corresponds to the ``deployed_model_id`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - traffic_split (Sequence[google.cloud.aiplatform_v1beta1.types.UndeployModelRequest.TrafficSplitEntry]): + traffic_split (Mapping[str, int]): If this field is provided, then the Endpoint's [traffic_split][google.cloud.aiplatform.v1beta1.Endpoint.traffic_split] will be overwritten with it. If last DeployedModel is @@ -976,7 +1323,7 @@ def undeploy_model( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([endpoint, deployed_model_id, traffic_split]) if request is not None and has_flattened_params: @@ -1011,7 +1358,12 @@ def undeploy_model( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -1024,6 +1376,690 @@ def undeploy_model( # Done; return the response. return response + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_operations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.delete_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.wait_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_location, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_locations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/aiplatform_v1beta1/services/endpoint_service/pagers.py b/google/cloud/aiplatform_v1beta1/services/endpoint_service/pagers.py index b16d1cf1a1..8397eeb7b8 100644 --- a/google/cloud/aiplatform_v1beta1/services/endpoint_service/pagers.py +++ b/google/cloud/aiplatform_v1beta1/services/endpoint_service/pagers.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,13 +15,13 @@ # from typing import ( Any, - AsyncIterable, + AsyncIterator, Awaitable, Callable, - Iterable, Sequence, Tuple, Optional, + Iterator, ) from google.cloud.aiplatform_v1beta1.types import endpoint @@ -75,14 +75,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[endpoint_service.ListEndpointsResponse]: + def pages(self) -> Iterator[endpoint_service.ListEndpointsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[endpoint.Endpoint]: + def __iter__(self) -> Iterator[endpoint.Endpoint]: for page in self.pages: yield from page.endpoints @@ -116,7 +116,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -137,14 +137,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - async def pages(self) -> AsyncIterable[endpoint_service.ListEndpointsResponse]: + async def pages(self) -> AsyncIterator[endpoint_service.ListEndpointsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[endpoint.Endpoint]: + def __aiter__(self) -> AsyncIterator[endpoint.Endpoint]: async def async_generator(): async for page in self.pages: for response in page.endpoints: diff --git a/google/cloud/aiplatform_v1beta1/services/endpoint_service/transports/__init__.py b/google/cloud/aiplatform_v1beta1/services/endpoint_service/transports/__init__.py index 4d336c5875..92f3485150 100644 --- a/google/cloud/aiplatform_v1beta1/services/endpoint_service/transports/__init__.py +++ b/google/cloud/aiplatform_v1beta1/services/endpoint_service/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1beta1/services/endpoint_service/transports/base.py b/google/cloud/aiplatform_v1beta1/services/endpoint_service/transports/base.py index 12d5e3d32b..7787c8fb54 100644 --- a/google/cloud/aiplatform_v1beta1/services/endpoint_service/transports/base.py +++ b/google/cloud/aiplatform_v1beta1/services/endpoint_service/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,20 +15,24 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.api_core import operations_v1 # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.aiplatform_v1beta1.types import endpoint from google.cloud.aiplatform_v1beta1.types import endpoint as gca_endpoint from google.cloud.aiplatform_v1beta1.types import endpoint_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore try: @@ -40,17 +44,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - -_API_CORE_VERSION = google.api_core.__version__ - class EndpointServiceTransport(abc.ABC): """Abstract transport class for EndpointService.""" @@ -68,6 +61,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -91,16 +85,19 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -113,88 +110,73 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id ) - # Save the credentials. - self._credentials = credentials - - # TODO(busunkim): These two class methods are in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-api-core - # and google-auth are increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") + # If the credentials are service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs + credentials = credentials.with_always_use_jwt_access(True) - # TODO: Remove this function once google-api-core >= 1.26.0 is required - @classmethod - def _get_self_signed_jwt_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Union[Optional[Sequence[str]], str]]: - """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" - - self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} - - if _API_CORE_VERSION and ( - packaging.version.parse(_API_CORE_VERSION) - >= packaging.version.parse("1.26.0") - ): - self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES - self_signed_jwt_kwargs["scopes"] = scopes - self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST - else: - self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES - - return self_signed_jwt_kwargs + # Save the credentials. + self._credentials = credentials def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { self.create_endpoint: gapic_v1.method.wrap_method( - self.create_endpoint, default_timeout=5.0, client_info=client_info, + self.create_endpoint, + default_timeout=5.0, + client_info=client_info, ), self.get_endpoint: gapic_v1.method.wrap_method( - self.get_endpoint, default_timeout=5.0, client_info=client_info, + self.get_endpoint, + default_timeout=5.0, + client_info=client_info, ), self.list_endpoints: gapic_v1.method.wrap_method( - self.list_endpoints, default_timeout=5.0, client_info=client_info, + self.list_endpoints, + default_timeout=5.0, + client_info=client_info, ), self.update_endpoint: gapic_v1.method.wrap_method( - self.update_endpoint, default_timeout=5.0, client_info=client_info, + self.update_endpoint, + default_timeout=5.0, + client_info=client_info, ), self.delete_endpoint: gapic_v1.method.wrap_method( - self.delete_endpoint, default_timeout=5.0, client_info=client_info, + self.delete_endpoint, + default_timeout=5.0, + client_info=client_info, ), self.deploy_model: gapic_v1.method.wrap_method( - self.deploy_model, default_timeout=5.0, client_info=client_info, + self.deploy_model, + default_timeout=5.0, + client_info=client_info, ), self.undeploy_model: gapic_v1.method.wrap_method( - self.undeploy_model, default_timeout=5.0, client_info=client_info, + self.undeploy_model, + default_timeout=5.0, + client_info=client_info, ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() @@ -264,5 +246,102 @@ def undeploy_model( ]: raise NotImplementedError() + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], + Union[ + operations_pb2.ListOperationsResponse, + Awaitable[operations_pb2.ListOperationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None,]: + raise NotImplementedError() + + @property + def wait_operation( + self, + ) -> Callable[ + [operations_pb2.WaitOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def set_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def get_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_location( + self, + ) -> Callable[ + [locations_pb2.GetLocationRequest], + Union[locations_pb2.Location, Awaitable[locations_pb2.Location]], + ]: + raise NotImplementedError() + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], + Union[ + locations_pb2.ListLocationsResponse, + Awaitable[locations_pb2.ListLocationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + __all__ = ("EndpointServiceTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/endpoint_service/transports/grpc.py b/google/cloud/aiplatform_v1beta1/services/endpoint_service/transports/grpc.py index be43928032..2c7cdf23dc 100644 --- a/google/cloud/aiplatform_v1beta1/services/endpoint_service/transports/grpc.py +++ b/google/cloud/aiplatform_v1beta1/services/endpoint_service/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,9 +16,9 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import operations_v1 +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -28,6 +28,10 @@ from google.cloud.aiplatform_v1beta1.types import endpoint from google.cloud.aiplatform_v1beta1.types import endpoint as gca_endpoint from google.cloud.aiplatform_v1beta1.types import endpoint_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from .base import EndpointServiceTransport, DEFAULT_CLIENT_INFO @@ -35,6 +39,8 @@ class EndpointServiceGrpcTransport(EndpointServiceTransport): """gRPC backend transport for EndpointService. + A service for managing Vertex AI's Endpoints. + This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation and call it. @@ -59,6 +65,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -81,16 +88,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -99,6 +106,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport @@ -109,7 +118,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -152,13 +161,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -207,21 +220,20 @@ def create_channel( and ``credentials_file`` are passed. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @property def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ + """Return the channel designed to connect to this service.""" return self._grpc_channel @property @@ -231,7 +243,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsClient(self.grpc_channel) @@ -425,5 +437,215 @@ def undeploy_model( ) return self._stubs["undeploy_model"] + def close(self): + self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + @property + def kind(self) -> str: + return "grpc" + __all__ = ("EndpointServiceGrpcTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/endpoint_service/transports/grpc_asyncio.py b/google/cloud/aiplatform_v1beta1/services/endpoint_service/transports/grpc_asyncio.py index d4273fd3be..179c45572d 100644 --- a/google/cloud/aiplatform_v1beta1/services/endpoint_service/transports/grpc_asyncio.py +++ b/google/cloud/aiplatform_v1beta1/services/endpoint_service/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,12 +16,11 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore -from google.api_core import operations_v1 # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore @@ -29,6 +28,10 @@ from google.cloud.aiplatform_v1beta1.types import endpoint from google.cloud.aiplatform_v1beta1.types import endpoint as gca_endpoint from google.cloud.aiplatform_v1beta1.types import endpoint_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from .base import EndpointServiceTransport, DEFAULT_CLIENT_INFO from .grpc import EndpointServiceGrpcTransport @@ -37,6 +40,8 @@ class EndpointServiceGrpcAsyncIOTransport(EndpointServiceTransport): """gRPC AsyncIO backend transport for EndpointService. + A service for managing Vertex AI's Endpoints. + This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation and call it. @@ -80,14 +85,14 @@ def create_channel( aio.Channel: A gRPC AsyncIO channel object. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @@ -105,6 +110,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -128,16 +134,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -146,6 +152,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport @@ -156,7 +164,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -198,13 +206,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -234,7 +246,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel @@ -441,5 +453,211 @@ def undeploy_model( ) return self._stubs["undeploy_model"] + def close(self): + return self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + __all__ = ("EndpointServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/featurestore_online_serving_service/__init__.py b/google/cloud/aiplatform_v1beta1/services/featurestore_online_serving_service/__init__.py index d2acffa98a..a2f6b5fa66 100644 --- a/google/cloud/aiplatform_v1beta1/services/featurestore_online_serving_service/__init__.py +++ b/google/cloud/aiplatform_v1beta1/services/featurestore_online_serving_service/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1beta1/services/featurestore_online_serving_service/async_client.py b/google/cloud/aiplatform_v1beta1/services/featurestore_online_serving_service/async_client.py index 270ad60e8f..f7625f45b0 100644 --- a/google/cloud/aiplatform_v1beta1/services/featurestore_online_serving_service/async_client.py +++ b/google/cloud/aiplatform_v1beta1/services/featurestore_online_serving_service/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,17 +16,36 @@ from collections import OrderedDict import functools import re -from typing import Dict, AsyncIterable, Awaitable, Sequence, Tuple, Type, Union +from typing import ( + Dict, + Mapping, + Optional, + AsyncIterable, + Awaitable, + Sequence, + Tuple, + Type, + Union, +) import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.cloud.aiplatform_v1beta1.types import featurestore_online_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from .transports.base import ( FeaturestoreOnlineServingServiceTransport, DEFAULT_CLIENT_INFO, @@ -84,7 +103,8 @@ class FeaturestoreOnlineServingServiceAsyncClient: @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -99,7 +119,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -114,9 +134,45 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return FeaturestoreOnlineServingServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> FeaturestoreOnlineServingServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: FeaturestoreOnlineServingServiceTransport: The transport used by the client instance. @@ -138,7 +194,7 @@ def __init__( client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the featurestore online serving service client. + """Instantiates the featurestore online serving service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -179,10 +235,12 @@ def __init__( async def read_feature_values( self, - request: featurestore_online_service.ReadFeatureValuesRequest = None, + request: Union[ + featurestore_online_service.ReadFeatureValuesRequest, dict + ] = None, *, entity_type: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> featurestore_online_service.ReadFeatureValuesResponse: @@ -191,17 +249,41 @@ async def read_feature_values( entities of an EntityType, please use StreamingReadFeatureValues. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_read_feature_values(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreOnlineServingServiceAsyncClient() + + # Initialize request argument(s) + feature_selector = aiplatform_v1beta1.FeatureSelector() + feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1beta1.ReadFeatureValuesRequest( + entity_type="entity_type_value", + entity_id="entity_id_value", + feature_selector=feature_selector, + ) + + # Make the request + response = await client.read_feature_values(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ReadFeatureValuesRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ReadFeatureValuesRequest, dict]): The request object. Request message for [FeaturestoreOnlineServingService.ReadFeatureValues][google.cloud.aiplatform.v1beta1.FeaturestoreOnlineServingService.ReadFeatureValues]. entity_type (:class:`str`): Required. The resource name of the EntityType for the entity being read. Value format: - ``projects/{project}/locations/{location}/featurestores/ {featurestore}/entityTypes/{entityType}``. + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entityType}``. For example, for a machine learning model predicting user clicks on a website, an EntityType ID could be - "user". + ``user``. This corresponds to the ``entity_type`` field on the ``request`` instance; if ``request`` is provided, this @@ -219,7 +301,7 @@ async def read_feature_values( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([entity_type]) if request is not None and has_flattened_params: @@ -252,17 +334,24 @@ async def read_feature_values( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def streaming_read_feature_values( self, - request: featurestore_online_service.StreamingReadFeatureValuesRequest = None, + request: Union[ + featurestore_online_service.StreamingReadFeatureValuesRequest, dict + ] = None, *, entity_type: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> Awaitable[ @@ -272,17 +361,42 @@ def streaming_read_feature_values( on their size, data for different entities may be broken up across multiple responses. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_streaming_read_feature_values(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreOnlineServingServiceAsyncClient() + + # Initialize request argument(s) + feature_selector = aiplatform_v1beta1.FeatureSelector() + feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1beta1.StreamingReadFeatureValuesRequest( + entity_type="entity_type_value", + entity_ids=['entity_ids_value_1', 'entity_ids_value_2'], + feature_selector=feature_selector, + ) + + # Make the request + stream = await client.streaming_read_feature_values(request=request) + + # Handle the response + async for response in stream: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.StreamingReadFeatureValuesRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.StreamingReadFeatureValuesRequest, dict]): The request object. Request message for [FeaturestoreOnlineServingService.StreamingFeatureValuesRead][]. entity_type (:class:`str`): Required. The resource name of the entities' type. Value format: - ``projects/{project}/locations/{location}/featurestores/ {featurestore}/entityTypes/{entityType}``. + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entityType}``. For example, for a machine learning model predicting user clicks on a website, an EntityType ID could be - "user". + ``user``. This corresponds to the ``entity_type`` field on the ``request`` instance; if ``request`` is provided, this @@ -300,7 +414,7 @@ def streaming_read_feature_values( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([entity_type]) if request is not None and has_flattened_params: @@ -333,11 +447,693 @@ def streaming_read_feature_values( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_operations, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.delete_operation, + default_timeout=None, + 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 cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + 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 wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.wait_operation, + default_timeout=None, + 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 set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_location, + default_timeout=None, + 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 list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_locations, + default_timeout=None, + 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 __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/aiplatform_v1beta1/services/featurestore_online_serving_service/client.py b/google/cloud/aiplatform_v1beta1/services/featurestore_online_serving_service/client.py index 9389db9195..34e83666f3 100644 --- a/google/cloud/aiplatform_v1beta1/services/featurestore_online_serving_service/client.py +++ b/google/cloud/aiplatform_v1beta1/services/featurestore_online_serving_service/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,23 +14,31 @@ # limitations under the License. # from collections import OrderedDict -from distutils import util import os import re -from typing import Callable, Dict, Optional, Iterable, Sequence, Tuple, Type, Union +from typing import Dict, Mapping, Optional, Iterable, 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 as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_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 +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.cloud.aiplatform_v1beta1.types import featurestore_online_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from .transports.base import ( FeaturestoreOnlineServingServiceTransport, DEFAULT_CLIENT_INFO, @@ -58,9 +66,10 @@ class FeaturestoreOnlineServingServiceClientMeta(type): ] = FeaturestoreOnlineServingServiceGrpcAsyncIOTransport def get_transport_class( - cls, label: str = None, + cls, + label: str = None, ) -> Type[FeaturestoreOnlineServingServiceTransport]: - """Return an appropriate transport class. + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -85,7 +94,8 @@ class FeaturestoreOnlineServingServiceClient( @staticmethod def _get_default_mtls_endpoint(api_endpoint): - """Convert api endpoint to mTLS endpoint. + """Converts api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. Args: @@ -119,7 +129,8 @@ def _get_default_mtls_endpoint(api_endpoint): @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -136,7 +147,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -155,18 +166,22 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> FeaturestoreOnlineServingServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - FeaturestoreOnlineServingServiceTransport: The transport used by the client instance. + FeaturestoreOnlineServingServiceTransport: The transport used by the client + instance. """ return self._transport @staticmethod def entity_type_path( - project: str, location: str, featurestore: str, entity_type: str, + project: str, + location: str, + featurestore: str, + entity_type: str, ) -> str: - """Return a fully-qualified entity_type string.""" + """Returns a fully-qualified entity_type string.""" return "projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}".format( project=project, location=location, @@ -176,7 +191,7 @@ def entity_type_path( @staticmethod def parse_entity_type_path(path: str) -> Dict[str, str]: - """Parse a entity_type path into its component segments.""" + """Parses a entity_type path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/featurestores/(?P.+?)/entityTypes/(?P.+?)$", path, @@ -184,8 +199,10 @@ def parse_entity_type_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + def common_billing_account_path( + billing_account: str, + ) -> str: + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -197,9 +214,13 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: 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,) + def common_folder_path( + folder: str, + ) -> str: + """Returns a fully-qualified folder string.""" + return "folders/{folder}".format( + folder=folder, + ) @staticmethod def parse_common_folder_path(path: str) -> Dict[str, str]: @@ -208,9 +229,13 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: 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,) + def common_organization_path( + organization: str, + ) -> str: + """Returns a fully-qualified organization string.""" + return "organizations/{organization}".format( + organization=organization, + ) @staticmethod def parse_common_organization_path(path: str) -> Dict[str, str]: @@ -219,9 +244,13 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: 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,) + def common_project_path( + project: str, + ) -> str: + """Returns a fully-qualified project string.""" + return "projects/{project}".format( + project=project, + ) @staticmethod def parse_common_project_path(path: str) -> Dict[str, str]: @@ -230,10 +259,14 @@ def parse_common_project_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_location_path(project: str, location: str,) -> str: - """Return a fully-qualified location string.""" + def common_location_path( + project: str, + location: str, + ) -> str: + """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) @staticmethod @@ -242,6 +275,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + def __init__( self, *, @@ -250,7 +350,7 @@ def __init__( client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the featurestore online serving service client. + """Instantiates the featurestore online serving service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -292,58 +392,42 @@ def __init__( 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")) + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - client_cert_source_func = ( - mtls.default_client_cert_source() 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" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # 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, FeaturestoreOnlineServingServiceTransport): # transport is a FeaturestoreOnlineServingServiceTransport instance. - if credentials or client_options.credentials_file: + if credentials or client_options.credentials_file or api_key_value: 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." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + Transport = type(self).get_transport_class(transport) self._transport = Transport( credentials=credentials, @@ -353,14 +437,17 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, + always_use_jwt_access=True, ) def read_feature_values( self, - request: featurestore_online_service.ReadFeatureValuesRequest = None, + request: Union[ + featurestore_online_service.ReadFeatureValuesRequest, dict + ] = None, *, entity_type: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> featurestore_online_service.ReadFeatureValuesResponse: @@ -369,17 +456,41 @@ def read_feature_values( entities of an EntityType, please use StreamingReadFeatureValues. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_read_feature_values(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreOnlineServingServiceClient() + + # Initialize request argument(s) + feature_selector = aiplatform_v1beta1.FeatureSelector() + feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1beta1.ReadFeatureValuesRequest( + entity_type="entity_type_value", + entity_id="entity_id_value", + feature_selector=feature_selector, + ) + + # Make the request + response = client.read_feature_values(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ReadFeatureValuesRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ReadFeatureValuesRequest, dict]): The request object. Request message for [FeaturestoreOnlineServingService.ReadFeatureValues][google.cloud.aiplatform.v1beta1.FeaturestoreOnlineServingService.ReadFeatureValues]. entity_type (str): Required. The resource name of the EntityType for the entity being read. Value format: - ``projects/{project}/locations/{location}/featurestores/ {featurestore}/entityTypes/{entityType}``. + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entityType}``. For example, for a machine learning model predicting user clicks on a website, an EntityType ID could be - "user". + ``user``. This corresponds to the ``entity_type`` field on the ``request`` instance; if ``request`` is provided, this @@ -397,7 +508,7 @@ def read_feature_values( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([entity_type]) if request is not None and has_flattened_params: @@ -432,17 +543,24 @@ def read_feature_values( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def streaming_read_feature_values( self, - request: featurestore_online_service.StreamingReadFeatureValuesRequest = None, + request: Union[ + featurestore_online_service.StreamingReadFeatureValuesRequest, dict + ] = None, *, entity_type: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> Iterable[featurestore_online_service.ReadFeatureValuesResponse]: @@ -450,17 +568,42 @@ def streaming_read_feature_values( on their size, data for different entities may be broken up across multiple responses. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_streaming_read_feature_values(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreOnlineServingServiceClient() + + # Initialize request argument(s) + feature_selector = aiplatform_v1beta1.FeatureSelector() + feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1beta1.StreamingReadFeatureValuesRequest( + entity_type="entity_type_value", + entity_ids=['entity_ids_value_1', 'entity_ids_value_2'], + feature_selector=feature_selector, + ) + + # Make the request + stream = client.streaming_read_feature_values(request=request) + + # Handle the response + for response in stream: + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.StreamingReadFeatureValuesRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.StreamingReadFeatureValuesRequest, dict]): The request object. Request message for [FeaturestoreOnlineServingService.StreamingFeatureValuesRead][]. entity_type (str): Required. The resource name of the entities' type. Value format: - ``projects/{project}/locations/{location}/featurestores/ {featurestore}/entityTypes/{entityType}``. + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entityType}``. For example, for a machine learning model predicting user clicks on a website, an EntityType ID could be - "user". + ``user``. This corresponds to the ``entity_type`` field on the ``request`` instance; if ``request`` is provided, this @@ -478,7 +621,7 @@ def streaming_read_feature_values( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([entity_type]) if request is not None and has_flattened_params: @@ -517,7 +660,696 @@ def streaming_read_feature_values( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_operations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.delete_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.wait_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_location, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_locations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response diff --git a/google/cloud/aiplatform_v1beta1/services/featurestore_online_serving_service/transports/__init__.py b/google/cloud/aiplatform_v1beta1/services/featurestore_online_serving_service/transports/__init__.py index cc2c0278fb..c929d350e6 100644 --- a/google/cloud/aiplatform_v1beta1/services/featurestore_online_serving_service/transports/__init__.py +++ b/google/cloud/aiplatform_v1beta1/services/featurestore_online_serving_service/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1beta1/services/featurestore_online_serving_service/transports/base.py b/google/cloud/aiplatform_v1beta1/services/featurestore_online_serving_service/transports/base.py index b4e26a18c0..e10a0f95e6 100644 --- a/google/cloud/aiplatform_v1beta1/services/featurestore_online_serving_service/transports/base.py +++ b/google/cloud/aiplatform_v1beta1/services/featurestore_online_serving_service/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,17 +15,21 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.aiplatform_v1beta1.types import featurestore_online_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( @@ -36,17 +40,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - -_API_CORE_VERSION = google.api_core.__version__ - class FeaturestoreOnlineServingServiceTransport(abc.ABC): """Abstract transport class for FeaturestoreOnlineServingService.""" @@ -64,6 +57,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -87,16 +81,19 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -109,65 +106,29 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id ) - # Save the credentials. - self._credentials = credentials - - # TODO(busunkim): These two class methods are in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-api-core - # and google-auth are increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") + # If the credentials are service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs + credentials = credentials.with_always_use_jwt_access(True) - # TODO: Remove this function once google-api-core >= 1.26.0 is required - @classmethod - def _get_self_signed_jwt_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Union[Optional[Sequence[str]], str]]: - """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" - - self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} - - if _API_CORE_VERSION and ( - packaging.version.parse(_API_CORE_VERSION) - >= packaging.version.parse("1.26.0") - ): - self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES - self_signed_jwt_kwargs["scopes"] = scopes - self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST - else: - self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES - - return self_signed_jwt_kwargs + # Save the credentials. + self._credentials = credentials def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { self.read_feature_values: gapic_v1.method.wrap_method( - self.read_feature_values, default_timeout=5.0, client_info=client_info, + self.read_feature_values, + default_timeout=5.0, + client_info=client_info, ), self.streaming_read_feature_values: gapic_v1.method.wrap_method( self.streaming_read_feature_values, @@ -176,6 +137,15 @@ def _prep_wrapped_messages(self, client_info): ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property def read_feature_values( self, @@ -200,5 +170,102 @@ def streaming_read_feature_values( ]: raise NotImplementedError() + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], + Union[ + operations_pb2.ListOperationsResponse, + Awaitable[operations_pb2.ListOperationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None,]: + raise NotImplementedError() + + @property + def wait_operation( + self, + ) -> Callable[ + [operations_pb2.WaitOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def set_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def get_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_location( + self, + ) -> Callable[ + [locations_pb2.GetLocationRequest], + Union[locations_pb2.Location, Awaitable[locations_pb2.Location]], + ]: + raise NotImplementedError() + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], + Union[ + locations_pb2.ListLocationsResponse, + Awaitable[locations_pb2.ListLocationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + __all__ = ("FeaturestoreOnlineServingServiceTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/featurestore_online_serving_service/transports/grpc.py b/google/cloud/aiplatform_v1beta1/services/featurestore_online_serving_service/transports/grpc.py index d13e69eda0..d402f79ef4 100644 --- a/google/cloud/aiplatform_v1beta1/services/featurestore_online_serving_service/transports/grpc.py +++ b/google/cloud/aiplatform_v1beta1/services/featurestore_online_serving_service/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,8 +16,8 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -25,6 +25,10 @@ import grpc # type: ignore from google.cloud.aiplatform_v1beta1.types import featurestore_online_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from .base import FeaturestoreOnlineServingServiceTransport, DEFAULT_CLIENT_INFO @@ -59,6 +63,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -81,16 +86,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -99,6 +104,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport @@ -151,13 +158,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -206,21 +217,20 @@ def create_channel( and ``credentials_file`` are passed. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @property def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ + """Return the channel designed to connect to this service.""" return self._grpc_channel @property @@ -288,5 +298,215 @@ def streaming_read_feature_values( ) return self._stubs["streaming_read_feature_values"] + def close(self): + self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + @property + def kind(self) -> str: + return "grpc" + __all__ = ("FeaturestoreOnlineServingServiceGrpcTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/featurestore_online_serving_service/transports/grpc_asyncio.py b/google/cloud/aiplatform_v1beta1/services/featurestore_online_serving_service/transports/grpc_asyncio.py index 229f6c7ce9..79d08e7cf2 100644 --- a/google/cloud/aiplatform_v1beta1/services/featurestore_online_serving_service/transports/grpc_asyncio.py +++ b/google/cloud/aiplatform_v1beta1/services/featurestore_online_serving_service/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,16 +16,19 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore from google.cloud.aiplatform_v1beta1.types import featurestore_online_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from .base import FeaturestoreOnlineServingServiceTransport, DEFAULT_CLIENT_INFO from .grpc import FeaturestoreOnlineServingServiceGrpcTransport @@ -80,14 +83,14 @@ def create_channel( aio.Channel: A gRPC AsyncIO channel object. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @@ -105,6 +108,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -128,16 +132,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -146,6 +150,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport @@ -197,13 +203,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -291,5 +301,211 @@ def streaming_read_feature_values( ) return self._stubs["streaming_read_feature_values"] + def close(self): + return self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + __all__ = ("FeaturestoreOnlineServingServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/featurestore_service/__init__.py b/google/cloud/aiplatform_v1beta1/services/featurestore_service/__init__.py index 192c1fc2a0..3f53c57568 100644 --- a/google/cloud/aiplatform_v1beta1/services/featurestore_service/__init__.py +++ b/google/cloud/aiplatform_v1beta1/services/featurestore_service/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1beta1/services/featurestore_service/async_client.py b/google/cloud/aiplatform_v1beta1/services/featurestore_service/async_client.py index 6ab5b3cc7f..54aa120a85 100644 --- a/google/cloud/aiplatform_v1beta1/services/featurestore_service/async_client.py +++ b/google/cloud/aiplatform_v1beta1/services/featurestore_service/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,19 +16,25 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation as gac_operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1beta1.services.featurestore_service import pagers +from google.cloud.aiplatform_v1beta1.types import encryption_spec from google.cloud.aiplatform_v1beta1.types import entity_type from google.cloud.aiplatform_v1beta1.types import entity_type as gca_entity_type from google.cloud.aiplatform_v1beta1.types import feature @@ -39,6 +45,10 @@ from google.cloud.aiplatform_v1beta1.types import featurestore_monitoring from google.cloud.aiplatform_v1beta1.types import featurestore_service from google.cloud.aiplatform_v1beta1.types import operation as gca_operation +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore @@ -94,7 +104,8 @@ class FeaturestoreServiceAsyncClient: @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -109,7 +120,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -124,9 +135,45 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return FeaturestoreServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> FeaturestoreServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: FeaturestoreServiceTransport: The transport used by the client instance. @@ -146,7 +193,7 @@ def __init__( client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the featurestore service client. + """Instantiates the featurestore service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -187,19 +234,44 @@ def __init__( async def create_featurestore( self, - request: featurestore_service.CreateFeaturestoreRequest = None, + request: Union[featurestore_service.CreateFeaturestoreRequest, dict] = None, *, parent: str = None, featurestore: gca_featurestore.Featurestore = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + featurestore_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Creates a new Featurestore in a given project and location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_create_featurestore(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateFeaturestoreRequest( + parent="parent_value", + featurestore_id="featurestore_id_value", + ) + + # Make the request + operation = client.create_featurestore(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.CreateFeaturestoreRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateFeaturestoreRequest, dict]): The request object. Request message for [FeaturestoreService.CreateFeaturestore][google.cloud.aiplatform.v1beta1.FeaturestoreService.CreateFeaturestore]. parent (:class:`str`): @@ -215,6 +287,21 @@ async def create_featurestore( This corresponds to the ``featurestore`` field on the ``request`` instance; if ``request`` is provided, this should not be set. + featurestore_id (:class:`str`): + Required. The ID to use for this Featurestore, which + will become the final component of the Featurestore's + resource name. + + This value may be up to 60 characters, and valid + characters are ``[a-z0-9_]``. The first character cannot + be a number. + + The value must be unique within the project and + location. + + This corresponds to the ``featurestore_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. @@ -225,16 +312,16 @@ async def create_featurestore( google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. - The result type for the operation will be - :class:`google.cloud.aiplatform_v1beta1.types.Featurestore` - Featurestore configuration information on how the - Featurestore is configured. + The result type for the operation will be :class:`google.cloud.aiplatform_v1beta1.types.Featurestore` Vertex AI Feature Store provides a centralized repository for organizing, + storing, and serving ML features. The Featurestore is + a top-level container for your features and their + values. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, featurestore]) + has_flattened_params = any([parent, featurestore, featurestore_id]) if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " @@ -249,6 +336,8 @@ async def create_featurestore( request.parent = parent if featurestore is not None: request.featurestore = featurestore + if featurestore_id is not None: + request.featurestore_id = featurestore_id # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -265,7 +354,12 @@ async def create_featurestore( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -280,17 +374,36 @@ async def create_featurestore( async def get_featurestore( self, - request: featurestore_service.GetFeaturestoreRequest = None, + request: Union[featurestore_service.GetFeaturestoreRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> featurestore.Featurestore: r"""Gets details of a single Featurestore. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_get_featurestore(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetFeaturestoreRequest( + name="name_value", + ) + + # Make the request + response = await client.get_featurestore(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.GetFeaturestoreRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.GetFeaturestoreRequest, dict]): The request object. Request message for [FeaturestoreService.GetFeaturestore][google.cloud.aiplatform.v1beta1.FeaturestoreService.GetFeaturestore]. name (:class:`str`): @@ -308,13 +421,15 @@ async def get_featurestore( Returns: google.cloud.aiplatform_v1beta1.types.Featurestore: - Featurestore configuration - information on how the Featurestore is - configured. + Vertex AI Feature Store provides a + centralized repository for organizing, + storing, and serving ML features. The + Featurestore is a top-level container + for your features and their values. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -345,24 +460,49 @@ async def get_featurestore( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_featurestores( self, - request: featurestore_service.ListFeaturestoresRequest = None, + request: Union[featurestore_service.ListFeaturestoresRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListFeaturestoresAsyncPager: r"""Lists Featurestores in a given project and location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_list_featurestores(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListFeaturestoresRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_featurestores(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ListFeaturestoresRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ListFeaturestoresRequest, dict]): The request object. Request message for [FeaturestoreService.ListFeaturestores][google.cloud.aiplatform.v1beta1.FeaturestoreService.ListFeaturestores]. parent (:class:`str`): @@ -389,7 +529,7 @@ async def list_featurestores( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -420,12 +560,20 @@ async def list_featurestores( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListFeaturestoresAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -433,18 +581,40 @@ async def list_featurestores( async def update_featurestore( self, - request: featurestore_service.UpdateFeaturestoreRequest = None, + request: Union[featurestore_service.UpdateFeaturestoreRequest, dict] = None, *, featurestore: gca_featurestore.Featurestore = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Updates the parameters of a single Featurestore. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_update_featurestore(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateFeaturestoreRequest( + ) + + # Make the request + operation = client.update_featurestore(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.UpdateFeaturestoreRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.UpdateFeaturestoreRequest, dict]): The request object. Request message for [FeaturestoreService.UpdateFeaturestore][google.cloud.aiplatform.v1beta1.FeaturestoreService.UpdateFeaturestore]. featurestore (:class:`google.cloud.aiplatform_v1beta1.types.Featurestore`): @@ -467,10 +637,9 @@ async def update_featurestore( Updatable fields: - - ``display_name`` - ``labels`` - ``online_serving_config.fixed_node_count`` - - ``retention_policy.online_storage_ttl_days`` + - ``online_serving_config.scaling`` This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this @@ -485,14 +654,14 @@ async def update_featurestore( google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. - The result type for the operation will be - :class:`google.cloud.aiplatform_v1beta1.types.Featurestore` - Featurestore configuration information on how the - Featurestore is configured. + The result type for the operation will be :class:`google.cloud.aiplatform_v1beta1.types.Featurestore` Vertex AI Feature Store provides a centralized repository for organizing, + storing, and serving ML features. The Featurestore is + a top-level container for your features and their + values. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([featurestore, update_mask]) if request is not None and has_flattened_params: @@ -527,7 +696,12 @@ async def update_featurestore( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -542,10 +716,11 @@ async def update_featurestore( async def delete_featurestore( self, - request: featurestore_service.DeleteFeaturestoreRequest = None, + request: Union[featurestore_service.DeleteFeaturestoreRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + force: bool = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -553,8 +728,31 @@ async def delete_featurestore( any EntityTypes or ``force`` must be set to true for the request to succeed. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_delete_featurestore(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteFeaturestoreRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_featurestore(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.DeleteFeaturestoreRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteFeaturestoreRequest, dict]): The request object. Request message for [FeaturestoreService.DeleteFeaturestore][google.cloud.aiplatform.v1beta1.FeaturestoreService.DeleteFeaturestore]. name (:class:`str`): @@ -565,6 +763,16 @@ async def delete_featurestore( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. + force (:class:`bool`): + If set to true, any EntityTypes and + Features for this Featurestore will also + be deleted. (Otherwise, the request will + only work if the Featurestore has no + EntityTypes.) + + This corresponds to the ``force`` 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. @@ -591,9 +799,9 @@ async def delete_featurestore( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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]) + has_flattened_params = any([name, force]) if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " @@ -606,6 +814,8 @@ async def delete_featurestore( # request, apply these. if name is not None: request.name = name + if force is not None: + request.force = force # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -622,7 +832,12 @@ async def delete_featurestore( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -637,18 +852,43 @@ async def delete_featurestore( async def create_entity_type( self, - request: featurestore_service.CreateEntityTypeRequest = None, + request: Union[featurestore_service.CreateEntityTypeRequest, dict] = None, *, parent: str = None, entity_type: gca_entity_type.EntityType = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + entity_type_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Creates a new EntityType in a given Featurestore. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_create_entity_type(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateEntityTypeRequest( + parent="parent_value", + entity_type_id="entity_type_id_value", + ) + + # Make the request + operation = client.create_entity_type(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.CreateEntityTypeRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateEntityTypeRequest, dict]): The request object. Request message for [FeaturestoreService.CreateEntityType][google.cloud.aiplatform.v1beta1.FeaturestoreService.CreateEntityType]. parent (:class:`str`): @@ -664,6 +904,20 @@ async def create_entity_type( This corresponds to the ``entity_type`` field on the ``request`` instance; if ``request`` is provided, this should not be set. + entity_type_id (:class:`str`): + Required. The ID to use for the EntityType, which will + become the final component of the EntityType's resource + name. + + This value may be up to 60 characters, and valid + characters are ``[a-z0-9_]``. The first character cannot + be a number. + + The value must be unique within a featurestore. + + This corresponds to the ``entity_type_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. @@ -681,9 +935,9 @@ async def create_entity_type( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, entity_type]) + has_flattened_params = any([parent, entity_type, entity_type_id]) if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " @@ -698,6 +952,8 @@ async def create_entity_type( request.parent = parent if entity_type is not None: request.entity_type = entity_type + if entity_type_id is not None: + request.entity_type_id = entity_type_id # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -714,7 +970,12 @@ async def create_entity_type( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -729,17 +990,36 @@ async def create_entity_type( async def get_entity_type( self, - request: featurestore_service.GetEntityTypeRequest = None, + request: Union[featurestore_service.GetEntityTypeRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> entity_type.EntityType: r"""Gets details of a single EntityType. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_get_entity_type(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetEntityTypeRequest( + name="name_value", + ) + + # Make the request + response = await client.get_entity_type(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.GetEntityTypeRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.GetEntityTypeRequest, dict]): The request object. Request message for [FeaturestoreService.GetEntityType][google.cloud.aiplatform.v1beta1.FeaturestoreService.GetEntityType]. name (:class:`str`): @@ -766,7 +1046,7 @@ async def get_entity_type( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -797,24 +1077,49 @@ async def get_entity_type( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_entity_types( self, - request: featurestore_service.ListEntityTypesRequest = None, + request: Union[featurestore_service.ListEntityTypesRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListEntityTypesAsyncPager: r"""Lists EntityTypes in a given Featurestore. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_list_entity_types(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListEntityTypesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_entity_types(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ListEntityTypesRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ListEntityTypesRequest, dict]): The request object. Request message for [FeaturestoreService.ListEntityTypes][google.cloud.aiplatform.v1beta1.FeaturestoreService.ListEntityTypes]. parent (:class:`str`): @@ -841,7 +1146,7 @@ async def list_entity_types( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -872,12 +1177,20 @@ async def list_entity_types( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListEntityTypesAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -885,18 +1198,36 @@ async def list_entity_types( async def update_entity_type( self, - request: featurestore_service.UpdateEntityTypeRequest = None, + request: Union[featurestore_service.UpdateEntityTypeRequest, dict] = None, *, entity_type: gca_entity_type.EntityType = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_entity_type.EntityType: r"""Updates the parameters of a single EntityType. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_update_entity_type(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateEntityTypeRequest( + ) + + # Make the request + response = await client.update_entity_type(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.UpdateEntityTypeRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.UpdateEntityTypeRequest, dict]): The request object. Request message for [FeaturestoreService.UpdateEntityType][google.cloud.aiplatform.v1beta1.FeaturestoreService.UpdateEntityType]. entity_type (:class:`google.cloud.aiplatform_v1beta1.types.EntityType`): @@ -922,7 +1253,12 @@ async def update_entity_type( - ``description`` - ``labels`` - ``monitoring_config.snapshot_analysis.disabled`` - - ``monitoring_config.snapshot_analysis.monitoring_interval`` + - ``monitoring_config.snapshot_analysis.monitoring_interval_days`` + - ``monitoring_config.snapshot_analysis.staleness_days`` + - ``monitoring_config.import_features_analysis.state`` + - ``monitoring_config.import_features_analysis.anomaly_detection_baseline`` + - ``monitoring_config.numerical_threshold_config.value`` + - ``monitoring_config.categorical_threshold_config.value`` This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this @@ -944,7 +1280,7 @@ async def update_entity_type( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([entity_type, update_mask]) if request is not None and has_flattened_params: @@ -979,17 +1315,23 @@ async def update_entity_type( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def delete_entity_type( self, - request: featurestore_service.DeleteEntityTypeRequest = None, + request: Union[featurestore_service.DeleteEntityTypeRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + force: bool = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -997,8 +1339,31 @@ async def delete_entity_type( Features or ``force`` must be set to true for the request to succeed. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_delete_entity_type(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteEntityTypeRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_entity_type(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.DeleteEntityTypeRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteEntityTypeRequest, dict]): The request object. Request message for [FeaturestoreService.DeleteEntityTypes][]. name (:class:`str`): @@ -1009,6 +1374,15 @@ async def delete_entity_type( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. + force (:class:`bool`): + If set to true, any Features for this + EntityType will also be deleted. + (Otherwise, the request will only work + if the EntityType has no Features.) + + This corresponds to the ``force`` 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. @@ -1035,9 +1409,9 @@ async def delete_entity_type( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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]) + has_flattened_params = any([name, force]) if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " @@ -1050,6 +1424,8 @@ async def delete_entity_type( # request, apply these. if name is not None: request.name = name + if force is not None: + request.force = force # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1066,7 +1442,12 @@ async def delete_entity_type( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -1081,18 +1462,47 @@ async def delete_entity_type( async def create_feature( self, - request: featurestore_service.CreateFeatureRequest = None, + request: Union[featurestore_service.CreateFeatureRequest, dict] = None, *, parent: str = None, feature: gca_feature.Feature = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + feature_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Creates a new Feature in a given EntityType. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_create_feature(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + feature = aiplatform_v1beta1.Feature() + feature.value_type = "BYTES" + + request = aiplatform_v1beta1.CreateFeatureRequest( + parent="parent_value", + feature=feature, + feature_id="feature_id_value", + ) + + # Make the request + operation = client.create_feature(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.CreateFeatureRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateFeatureRequest, dict]): The request object. Request message for [FeaturestoreService.CreateFeature][google.cloud.aiplatform.v1beta1.FeaturestoreService.CreateFeature]. parent (:class:`str`): @@ -1108,6 +1518,20 @@ async def create_feature( This corresponds to the ``feature`` field on the ``request`` instance; if ``request`` is provided, this should not be set. + feature_id (:class:`str`): + Required. The ID to use for the Feature, which will + become the final component of the Feature's resource + name. + + This value may be up to 60 characters, and valid + characters are ``[a-z0-9_]``. The first character cannot + be a number. + + The value must be unique within an EntityType. + + This corresponds to the ``feature_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. @@ -1124,9 +1548,9 @@ async def create_feature( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, feature]) + has_flattened_params = any([parent, feature, feature_id]) if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " @@ -1141,6 +1565,8 @@ async def create_feature( request.parent = parent if feature is not None: request.feature = feature + if feature_id is not None: + request.feature_id = feature_id # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1157,7 +1583,12 @@ async def create_feature( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -1172,18 +1603,47 @@ async def create_feature( async def batch_create_features( self, - request: featurestore_service.BatchCreateFeaturesRequest = None, + request: Union[featurestore_service.BatchCreateFeaturesRequest, dict] = None, *, parent: str = None, requests: Sequence[featurestore_service.CreateFeatureRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Creates a batch of Features in a given EntityType. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_batch_create_features(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + requests = aiplatform_v1beta1.CreateFeatureRequest() + requests.parent = "parent_value" + requests.feature.value_type = "BYTES" + requests.feature_id = "feature_id_value" + + request = aiplatform_v1beta1.BatchCreateFeaturesRequest( + parent="parent_value", + requests=requests, + ) + + # Make the request + operation = client.batch_create_features(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.BatchCreateFeaturesRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.BatchCreateFeaturesRequest, dict]): The request object. Request message for [FeaturestoreService.BatchCreateFeatures][google.cloud.aiplatform.v1beta1.FeaturestoreService.BatchCreateFeatures]. parent (:class:`str`): @@ -1222,7 +1682,7 @@ async def batch_create_features( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, requests]) if request is not None and has_flattened_params: @@ -1255,7 +1715,12 @@ async def batch_create_features( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -1270,17 +1735,36 @@ async def batch_create_features( async def get_feature( self, - request: featurestore_service.GetFeatureRequest = None, + request: Union[featurestore_service.GetFeatureRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> feature.Feature: r"""Gets details of a single Feature. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_get_feature(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetFeatureRequest( + name="name_value", + ) + + # Make the request + response = await client.get_feature(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.GetFeatureRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.GetFeatureRequest, dict]): The request object. Request message for [FeaturestoreService.GetFeature][google.cloud.aiplatform.v1beta1.FeaturestoreService.GetFeature]. name (:class:`str`): @@ -1306,7 +1790,7 @@ async def get_feature( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1337,24 +1821,49 @@ async def get_feature( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_features( self, - request: featurestore_service.ListFeaturesRequest = None, + request: Union[featurestore_service.ListFeaturesRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListFeaturesAsyncPager: r"""Lists Features in a given EntityType. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_list_features(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListFeaturesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_features(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ListFeaturesRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ListFeaturesRequest, dict]): The request object. Request message for [FeaturestoreService.ListFeatures][google.cloud.aiplatform.v1beta1.FeaturestoreService.ListFeatures]. parent (:class:`str`): @@ -1381,7 +1890,7 @@ async def list_features( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1412,12 +1921,20 @@ async def list_features( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListFeaturesAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -1425,18 +1942,40 @@ async def list_features( async def update_feature( self, - request: featurestore_service.UpdateFeatureRequest = None, + request: Union[featurestore_service.UpdateFeatureRequest, dict] = None, *, feature: gca_feature.Feature = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_feature.Feature: r"""Updates the parameters of a single Feature. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_update_feature(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + feature = aiplatform_v1beta1.Feature() + feature.value_type = "BYTES" + + request = aiplatform_v1beta1.UpdateFeatureRequest( + feature=feature, + ) + + # Make the request + response = await client.update_feature(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.UpdateFeatureRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.UpdateFeatureRequest, dict]): The request object. Request message for [FeaturestoreService.UpdateFeature][google.cloud.aiplatform.v1beta1.FeaturestoreService.UpdateFeature]. feature (:class:`google.cloud.aiplatform_v1beta1.types.Feature`): @@ -1461,8 +2000,7 @@ async def update_feature( - ``description`` - ``labels`` - - ``monitoring_config.snapshot_analysis.disabled`` - - ``monitoring_config.snapshot_analysis.monitoring_interval`` + - ``disable_monitoring`` This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this @@ -1483,7 +2021,7 @@ async def update_feature( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([feature, update_mask]) if request is not None and has_flattened_params: @@ -1518,24 +2056,52 @@ async def update_feature( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def delete_feature( self, - request: featurestore_service.DeleteFeatureRequest = None, + request: Union[featurestore_service.DeleteFeatureRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a single Feature. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_delete_feature(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteFeatureRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_feature(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.DeleteFeatureRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteFeatureRequest, dict]): The request object. Request message for [FeaturestoreService.DeleteFeature][google.cloud.aiplatform.v1beta1.FeaturestoreService.DeleteFeature]. name (:class:`str`): @@ -1572,7 +2138,7 @@ async def delete_feature( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1603,7 +2169,12 @@ async def delete_feature( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -1618,10 +2189,10 @@ async def delete_feature( async def import_feature_values( self, - request: featurestore_service.ImportFeatureValuesRequest = None, + request: Union[featurestore_service.ImportFeatureValuesRequest, dict] = None, *, entity_type: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -1647,8 +2218,40 @@ async def import_feature_values( or retention policy. - Online serving cluster is under-provisioned. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_import_feature_values(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + avro_source = aiplatform_v1beta1.AvroSource() + avro_source.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + + feature_specs = aiplatform_v1beta1.FeatureSpec() + feature_specs.id = "id_value" + + request = aiplatform_v1beta1.ImportFeatureValuesRequest( + avro_source=avro_source, + feature_time_field="feature_time_field_value", + entity_type="entity_type_value", + feature_specs=feature_specs, + ) + + # Make the request + operation = client.import_feature_values(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ImportFeatureValuesRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ImportFeatureValuesRequest, dict]): The request object. Request message for [FeaturestoreService.ImportFeatureValues][google.cloud.aiplatform.v1beta1.FeaturestoreService.ImportFeatureValues]. entity_type (:class:`str`): @@ -1677,7 +2280,7 @@ async def import_feature_values( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([entity_type]) if request is not None and has_flattened_params: @@ -1710,7 +2313,12 @@ async def import_feature_values( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -1725,10 +2333,10 @@ async def import_feature_values( async def batch_read_feature_values( self, - request: featurestore_service.BatchReadFeatureValuesRequest = None, + request: Union[featurestore_service.BatchReadFeatureValuesRequest, dict] = None, *, featurestore: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -1739,11 +2347,46 @@ async def batch_read_feature_values( correctness is guaranteed for Feature values of each read instance as of each instance's read timestamp. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_batch_read_feature_values(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + csv_read_instances = aiplatform_v1beta1.CsvSource() + csv_read_instances.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + + destination = aiplatform_v1beta1.FeatureValueDestination() + destination.bigquery_destination.output_uri = "output_uri_value" + + entity_type_specs = aiplatform_v1beta1.EntityTypeSpec() + entity_type_specs.entity_type_id = "entity_type_id_value" + entity_type_specs.feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1beta1.BatchReadFeatureValuesRequest( + csv_read_instances=csv_read_instances, + featurestore="featurestore_value", + destination=destination, + entity_type_specs=entity_type_specs, + ) + + # Make the request + operation = client.batch_read_feature_values(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.BatchReadFeatureValuesRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.BatchReadFeatureValuesRequest, dict]): The request object. Request message for [FeaturestoreService.BatchReadFeatureValues][google.cloud.aiplatform.v1beta1.FeaturestoreService.BatchReadFeatureValues]. - (- Next Id: 6 -) featurestore (:class:`str`): Required. The resource name of the Featurestore from which to query Feature values. Format: @@ -1769,7 +2412,7 @@ async def batch_read_feature_values( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([featurestore]) if request is not None and has_flattened_params: @@ -1802,7 +2445,12 @@ async def batch_read_feature_values( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -1817,18 +2465,49 @@ async def batch_read_feature_values( async def export_feature_values( self, - request: featurestore_service.ExportFeatureValuesRequest = None, + request: Union[featurestore_service.ExportFeatureValuesRequest, dict] = None, *, entity_type: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Exports Feature values from all the entities of a target EntityType. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_export_feature_values(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + destination = aiplatform_v1beta1.FeatureValueDestination() + destination.bigquery_destination.output_uri = "output_uri_value" + + feature_selector = aiplatform_v1beta1.FeatureSelector() + feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1beta1.ExportFeatureValuesRequest( + entity_type="entity_type_value", + destination=destination, + feature_selector=feature_selector, + ) + + # Make the request + operation = client.export_feature_values(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ExportFeatureValuesRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ExportFeatureValuesRequest, dict]): The request object. Request message for [FeaturestoreService.ExportFeatureValues][google.cloud.aiplatform.v1beta1.FeaturestoreService.ExportFeatureValues]. entity_type (:class:`str`): @@ -1856,7 +2535,7 @@ async def export_feature_values( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([entity_type]) if request is not None and has_flattened_params: @@ -1889,7 +2568,12 @@ async def export_feature_values( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -1904,18 +2588,39 @@ async def export_feature_values( async def search_features( self, - request: featurestore_service.SearchFeaturesRequest = None, + request: Union[featurestore_service.SearchFeaturesRequest, dict] = None, *, location: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + query: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.SearchFeaturesAsyncPager: r"""Searches Features matching a query in a given project. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_search_features(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.SearchFeaturesRequest( + location="location_value", + ) + + # Make the request + page_result = client.search_features(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.SearchFeaturesRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.SearchFeaturesRequest, dict]): The request object. Request message for [FeaturestoreService.SearchFeatures][google.cloud.aiplatform.v1beta1.FeaturestoreService.SearchFeatures]. location (:class:`str`): @@ -1926,6 +2631,81 @@ async def search_features( This corresponds to the ``location`` field on the ``request`` instance; if ``request`` is provided, this should not be set. + query (:class:`str`): + Query string that is a conjunction of field-restricted + queries and/or field-restricted filters. + Field-restricted queries and filters can be combined + using ``AND`` to form a conjunction. + + A field query is in the form FIELD:QUERY. This + implicitly checks if QUERY exists as a substring within + Feature's FIELD. The QUERY and the FIELD are converted + to a sequence of words (i.e. tokens) for comparison. + This is done by: + + - Removing leading/trailing whitespace and tokenizing + the search value. Characters that are not one of + alphanumeric ``[a-zA-Z0-9]``, underscore ``_``, or + asterisk ``*`` are treated as delimiters for tokens. + ``*`` is treated as a wildcard that matches + characters within a token. + - Ignoring case. + - Prepending an asterisk to the first and appending an + asterisk to the last token in QUERY. + + A QUERY must be either a singular token or a phrase. A + phrase is one or multiple words enclosed in double + quotation marks ("). With phrases, the order of the + words is important. Words in the phrase must be matching + in order and consecutively. + + Supported FIELDs for field-restricted queries: + + - ``feature_id`` + - ``description`` + - ``entity_type_id`` + + Examples: + + - ``feature_id: foo`` --> Matches a Feature with ID + containing the substring ``foo`` (eg. ``foo``, + ``foofeature``, ``barfoo``). + - ``feature_id: foo*feature`` --> Matches a Feature + with ID containing the substring ``foo*feature`` (eg. + ``foobarfeature``). + - ``feature_id: foo AND description: bar`` --> Matches + a Feature with ID containing the substring ``foo`` + and description containing the substring ``bar``. + + Besides field queries, the following exact-match filters + are supported. The exact-match filters do not support + wildcards. Unlike field-restricted queries, exact-match + filters are case-sensitive. + + - ``feature_id``: Supports = comparisons. + - ``description``: Supports = comparisons. Multi-token + filters should be enclosed in quotes. + - ``entity_type_id``: Supports = comparisons. + - ``value_type``: Supports = and != comparisons. + - ``labels``: Supports key-value equality as well as + key presence. + - ``featurestore_id``: Supports = comparisons. + + Examples: + + - ``description = "foo bar"`` --> Any Feature with + description exactly equal to ``foo bar`` + - ``value_type = DOUBLE`` --> Features whose type is + DOUBLE. + - ``labels.active = yes AND labels.env = prod`` --> + Features having both (active: yes) and (env: prod) + labels. + - ``labels.env: *`` --> Any Feature which has a label + with ``env`` as the key. + + 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. @@ -1942,9 +2722,9 @@ async def search_features( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - has_flattened_params = any([location]) + has_flattened_params = any([location, query]) if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " @@ -1957,6 +2737,8 @@ async def search_features( # request, apply these. if location is not None: request.location = location + if query is not None: + request.query = query # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1973,17 +2755,702 @@ async def search_features( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.SearchFeaturesAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_operations, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.delete_operation, + default_timeout=None, + 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 cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + 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 wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.wait_operation, + default_timeout=None, + 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 set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_location, + default_timeout=None, + 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 list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_locations, + default_timeout=None, + 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 __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/aiplatform_v1beta1/services/featurestore_service/client.py b/google/cloud/aiplatform_v1beta1/services/featurestore_service/client.py index 97d26b0d3f..a98c3fe404 100644 --- a/google/cloud/aiplatform_v1beta1/services/featurestore_service/client.py +++ b/google/cloud/aiplatform_v1beta1/services/featurestore_service/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,25 +14,30 @@ # 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 +from typing import Dict, Mapping, 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 as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_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 +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation as gac_operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1beta1.services.featurestore_service import pagers +from google.cloud.aiplatform_v1beta1.types import encryption_spec from google.cloud.aiplatform_v1beta1.types import entity_type from google.cloud.aiplatform_v1beta1.types import entity_type as gca_entity_type from google.cloud.aiplatform_v1beta1.types import feature @@ -43,6 +48,10 @@ from google.cloud.aiplatform_v1beta1.types import featurestore_monitoring from google.cloud.aiplatform_v1beta1.types import featurestore_service from google.cloud.aiplatform_v1beta1.types import operation as gca_operation +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore @@ -66,9 +75,10 @@ class FeaturestoreServiceClientMeta(type): _transport_registry["grpc_asyncio"] = FeaturestoreServiceGrpcAsyncIOTransport def get_transport_class( - cls, label: str = None, + cls, + label: str = None, ) -> Type[FeaturestoreServiceTransport]: - """Return an appropriate transport class. + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -93,7 +103,8 @@ class FeaturestoreServiceClient(metaclass=FeaturestoreServiceClientMeta): @staticmethod def _get_default_mtls_endpoint(api_endpoint): - """Convert api endpoint to mTLS endpoint. + """Converts api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. Args: @@ -127,7 +138,8 @@ def _get_default_mtls_endpoint(api_endpoint): @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -144,7 +156,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -163,18 +175,22 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> FeaturestoreServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - FeaturestoreServiceTransport: The transport used by the client instance. + FeaturestoreServiceTransport: The transport used by the client + instance. """ return self._transport @staticmethod def entity_type_path( - project: str, location: str, featurestore: str, entity_type: str, + project: str, + location: str, + featurestore: str, + entity_type: str, ) -> str: - """Return a fully-qualified entity_type string.""" + """Returns a fully-qualified entity_type string.""" return "projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}".format( project=project, location=location, @@ -184,7 +200,7 @@ def entity_type_path( @staticmethod def parse_entity_type_path(path: str) -> Dict[str, str]: - """Parse a entity_type path into its component segments.""" + """Parses a entity_type path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/featurestores/(?P.+?)/entityTypes/(?P.+?)$", path, @@ -193,9 +209,13 @@ def parse_entity_type_path(path: str) -> Dict[str, str]: @staticmethod def feature_path( - project: str, location: str, featurestore: str, entity_type: str, feature: str, + project: str, + location: str, + featurestore: str, + entity_type: str, + feature: str, ) -> str: - """Return a fully-qualified feature string.""" + """Returns a fully-qualified feature string.""" return "projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}/features/{feature}".format( project=project, location=location, @@ -206,7 +226,7 @@ def feature_path( @staticmethod def parse_feature_path(path: str) -> Dict[str, str]: - """Parse a feature path into its component segments.""" + """Parses a feature path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/featurestores/(?P.+?)/entityTypes/(?P.+?)/features/(?P.+?)$", path, @@ -214,15 +234,21 @@ def parse_feature_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def featurestore_path(project: str, location: str, featurestore: str,) -> str: - """Return a fully-qualified featurestore string.""" + def featurestore_path( + project: str, + location: str, + featurestore: str, + ) -> str: + """Returns a fully-qualified featurestore string.""" return "projects/{project}/locations/{location}/featurestores/{featurestore}".format( - project=project, location=location, featurestore=featurestore, + project=project, + location=location, + featurestore=featurestore, ) @staticmethod def parse_featurestore_path(path: str) -> Dict[str, str]: - """Parse a featurestore path into its component segments.""" + """Parses a featurestore path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/featurestores/(?P.+?)$", path, @@ -230,8 +256,10 @@ def parse_featurestore_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + def common_billing_account_path( + billing_account: str, + ) -> str: + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -243,9 +271,13 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: 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,) + def common_folder_path( + folder: str, + ) -> str: + """Returns a fully-qualified folder string.""" + return "folders/{folder}".format( + folder=folder, + ) @staticmethod def parse_common_folder_path(path: str) -> Dict[str, str]: @@ -254,9 +286,13 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: 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,) + def common_organization_path( + organization: str, + ) -> str: + """Returns a fully-qualified organization string.""" + return "organizations/{organization}".format( + organization=organization, + ) @staticmethod def parse_common_organization_path(path: str) -> Dict[str, str]: @@ -265,9 +301,13 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: 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,) + def common_project_path( + project: str, + ) -> str: + """Returns a fully-qualified project string.""" + return "projects/{project}".format( + project=project, + ) @staticmethod def parse_common_project_path(path: str) -> Dict[str, str]: @@ -276,10 +316,14 @@ def parse_common_project_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_location_path(project: str, location: str,) -> str: - """Return a fully-qualified location string.""" + def common_location_path( + project: str, + location: str, + ) -> str: + """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) @staticmethod @@ -288,6 +332,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + def __init__( self, *, @@ -296,7 +407,7 @@ def __init__( client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the featurestore service client. + """Instantiates the featurestore service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -338,58 +449,42 @@ def __init__( 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")) + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - client_cert_source_func = ( - mtls.default_client_cert_source() 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" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # 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, FeaturestoreServiceTransport): # transport is a FeaturestoreServiceTransport instance. - if credentials or client_options.credentials_file: + if credentials or client_options.credentials_file or api_key_value: 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." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + Transport = type(self).get_transport_class(transport) self._transport = Transport( credentials=credentials, @@ -399,23 +494,49 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, + always_use_jwt_access=True, ) def create_featurestore( self, - request: featurestore_service.CreateFeaturestoreRequest = None, + request: Union[featurestore_service.CreateFeaturestoreRequest, dict] = None, *, parent: str = None, featurestore: gca_featurestore.Featurestore = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + featurestore_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Creates a new Featurestore in a given project and location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_create_featurestore(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateFeaturestoreRequest( + parent="parent_value", + featurestore_id="featurestore_id_value", + ) + + # Make the request + operation = client.create_featurestore(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.CreateFeaturestoreRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateFeaturestoreRequest, dict]): The request object. Request message for [FeaturestoreService.CreateFeaturestore][google.cloud.aiplatform.v1beta1.FeaturestoreService.CreateFeaturestore]. parent (str): @@ -431,6 +552,21 @@ def create_featurestore( This corresponds to the ``featurestore`` field on the ``request`` instance; if ``request`` is provided, this should not be set. + featurestore_id (str): + Required. The ID to use for this Featurestore, which + will become the final component of the Featurestore's + resource name. + + This value may be up to 60 characters, and valid + characters are ``[a-z0-9_]``. The first character cannot + be a number. + + The value must be unique within the project and + location. + + This corresponds to the ``featurestore_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. @@ -441,16 +577,16 @@ def create_featurestore( google.api_core.operation.Operation: An object representing a long-running operation. - The result type for the operation will be - :class:`google.cloud.aiplatform_v1beta1.types.Featurestore` - Featurestore configuration information on how the - Featurestore is configured. + The result type for the operation will be :class:`google.cloud.aiplatform_v1beta1.types.Featurestore` Vertex AI Feature Store provides a centralized repository for organizing, + storing, and serving ML features. The Featurestore is + a top-level container for your features and their + values. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, featurestore]) + has_flattened_params = any([parent, featurestore, featurestore_id]) if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " @@ -469,6 +605,8 @@ def create_featurestore( request.parent = parent if featurestore is not None: request.featurestore = featurestore + if featurestore_id is not None: + request.featurestore_id = featurestore_id # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -481,7 +619,12 @@ def create_featurestore( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -496,17 +639,36 @@ def create_featurestore( def get_featurestore( self, - request: featurestore_service.GetFeaturestoreRequest = None, + request: Union[featurestore_service.GetFeaturestoreRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> featurestore.Featurestore: r"""Gets details of a single Featurestore. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_get_featurestore(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetFeaturestoreRequest( + name="name_value", + ) + + # Make the request + response = client.get_featurestore(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.GetFeaturestoreRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.GetFeaturestoreRequest, dict]): The request object. Request message for [FeaturestoreService.GetFeaturestore][google.cloud.aiplatform.v1beta1.FeaturestoreService.GetFeaturestore]. name (str): @@ -524,13 +686,15 @@ def get_featurestore( Returns: google.cloud.aiplatform_v1beta1.types.Featurestore: - Featurestore configuration - information on how the Featurestore is - configured. + Vertex AI Feature Store provides a + centralized repository for organizing, + storing, and serving ML features. The + Featurestore is a top-level container + for your features and their values. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -561,24 +725,49 @@ def get_featurestore( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_featurestores( self, - request: featurestore_service.ListFeaturestoresRequest = None, + request: Union[featurestore_service.ListFeaturestoresRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListFeaturestoresPager: r"""Lists Featurestores in a given project and location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_list_featurestores(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListFeaturestoresRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_featurestores(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ListFeaturestoresRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ListFeaturestoresRequest, dict]): The request object. Request message for [FeaturestoreService.ListFeaturestores][google.cloud.aiplatform.v1beta1.FeaturestoreService.ListFeaturestores]. parent (str): @@ -605,7 +794,7 @@ def list_featurestores( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -636,12 +825,20 @@ def list_featurestores( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListFeaturestoresPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -649,18 +846,40 @@ def list_featurestores( def update_featurestore( self, - request: featurestore_service.UpdateFeaturestoreRequest = None, + request: Union[featurestore_service.UpdateFeaturestoreRequest, dict] = None, *, featurestore: gca_featurestore.Featurestore = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Updates the parameters of a single Featurestore. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_update_featurestore(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateFeaturestoreRequest( + ) + + # Make the request + operation = client.update_featurestore(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.UpdateFeaturestoreRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.UpdateFeaturestoreRequest, dict]): The request object. Request message for [FeaturestoreService.UpdateFeaturestore][google.cloud.aiplatform.v1beta1.FeaturestoreService.UpdateFeaturestore]. featurestore (google.cloud.aiplatform_v1beta1.types.Featurestore): @@ -683,10 +902,9 @@ def update_featurestore( Updatable fields: - - ``display_name`` - ``labels`` - ``online_serving_config.fixed_node_count`` - - ``retention_policy.online_storage_ttl_days`` + - ``online_serving_config.scaling`` This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this @@ -701,14 +919,14 @@ def update_featurestore( google.api_core.operation.Operation: An object representing a long-running operation. - The result type for the operation will be - :class:`google.cloud.aiplatform_v1beta1.types.Featurestore` - Featurestore configuration information on how the - Featurestore is configured. + The result type for the operation will be :class:`google.cloud.aiplatform_v1beta1.types.Featurestore` Vertex AI Feature Store provides a centralized repository for organizing, + storing, and serving ML features. The Featurestore is + a top-level container for your features and their + values. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([featurestore, update_mask]) if request is not None and has_flattened_params: @@ -743,7 +961,12 @@ def update_featurestore( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -758,10 +981,11 @@ def update_featurestore( def delete_featurestore( self, - request: featurestore_service.DeleteFeaturestoreRequest = None, + request: Union[featurestore_service.DeleteFeaturestoreRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + force: bool = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: @@ -769,8 +993,31 @@ def delete_featurestore( any EntityTypes or ``force`` must be set to true for the request to succeed. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_delete_featurestore(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteFeaturestoreRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_featurestore(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.DeleteFeaturestoreRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteFeaturestoreRequest, dict]): The request object. Request message for [FeaturestoreService.DeleteFeaturestore][google.cloud.aiplatform.v1beta1.FeaturestoreService.DeleteFeaturestore]. name (str): @@ -781,6 +1028,16 @@ def delete_featurestore( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. + force (bool): + If set to true, any EntityTypes and + Features for this Featurestore will also + be deleted. (Otherwise, the request will + only work if the Featurestore has no + EntityTypes.) + + This corresponds to the ``force`` 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. @@ -807,9 +1064,9 @@ def delete_featurestore( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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]) + has_flattened_params = any([name, force]) if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " @@ -826,6 +1083,8 @@ def delete_featurestore( # request, apply these. if name is not None: request.name = name + if force is not None: + request.force = force # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -838,7 +1097,12 @@ def delete_featurestore( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -853,18 +1117,43 @@ def delete_featurestore( def create_entity_type( self, - request: featurestore_service.CreateEntityTypeRequest = None, + request: Union[featurestore_service.CreateEntityTypeRequest, dict] = None, *, parent: str = None, entity_type: gca_entity_type.EntityType = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + entity_type_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Creates a new EntityType in a given Featurestore. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_create_entity_type(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateEntityTypeRequest( + parent="parent_value", + entity_type_id="entity_type_id_value", + ) + + # Make the request + operation = client.create_entity_type(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.CreateEntityTypeRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateEntityTypeRequest, dict]): The request object. Request message for [FeaturestoreService.CreateEntityType][google.cloud.aiplatform.v1beta1.FeaturestoreService.CreateEntityType]. parent (str): @@ -880,6 +1169,20 @@ def create_entity_type( This corresponds to the ``entity_type`` field on the ``request`` instance; if ``request`` is provided, this should not be set. + entity_type_id (str): + Required. The ID to use for the EntityType, which will + become the final component of the EntityType's resource + name. + + This value may be up to 60 characters, and valid + characters are ``[a-z0-9_]``. The first character cannot + be a number. + + The value must be unique within a featurestore. + + This corresponds to the ``entity_type_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. @@ -897,9 +1200,9 @@ def create_entity_type( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, entity_type]) + has_flattened_params = any([parent, entity_type, entity_type_id]) if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " @@ -918,6 +1221,8 @@ def create_entity_type( request.parent = parent if entity_type is not None: request.entity_type = entity_type + if entity_type_id is not None: + request.entity_type_id = entity_type_id # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -930,7 +1235,12 @@ def create_entity_type( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -945,17 +1255,36 @@ def create_entity_type( def get_entity_type( self, - request: featurestore_service.GetEntityTypeRequest = None, + request: Union[featurestore_service.GetEntityTypeRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> entity_type.EntityType: r"""Gets details of a single EntityType. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_get_entity_type(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetEntityTypeRequest( + name="name_value", + ) + + # Make the request + response = client.get_entity_type(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.GetEntityTypeRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.GetEntityTypeRequest, dict]): The request object. Request message for [FeaturestoreService.GetEntityType][google.cloud.aiplatform.v1beta1.FeaturestoreService.GetEntityType]. name (str): @@ -982,7 +1311,7 @@ def get_entity_type( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1013,24 +1342,49 @@ def get_entity_type( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_entity_types( self, - request: featurestore_service.ListEntityTypesRequest = None, + request: Union[featurestore_service.ListEntityTypesRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListEntityTypesPager: r"""Lists EntityTypes in a given Featurestore. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_list_entity_types(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListEntityTypesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_entity_types(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ListEntityTypesRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ListEntityTypesRequest, dict]): The request object. Request message for [FeaturestoreService.ListEntityTypes][google.cloud.aiplatform.v1beta1.FeaturestoreService.ListEntityTypes]. parent (str): @@ -1057,7 +1411,7 @@ def list_entity_types( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1088,12 +1442,20 @@ def list_entity_types( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListEntityTypesPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -1101,18 +1463,36 @@ def list_entity_types( def update_entity_type( self, - request: featurestore_service.UpdateEntityTypeRequest = None, + request: Union[featurestore_service.UpdateEntityTypeRequest, dict] = None, *, entity_type: gca_entity_type.EntityType = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_entity_type.EntityType: r"""Updates the parameters of a single EntityType. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_update_entity_type(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateEntityTypeRequest( + ) + + # Make the request + response = client.update_entity_type(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.UpdateEntityTypeRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.UpdateEntityTypeRequest, dict]): The request object. Request message for [FeaturestoreService.UpdateEntityType][google.cloud.aiplatform.v1beta1.FeaturestoreService.UpdateEntityType]. entity_type (google.cloud.aiplatform_v1beta1.types.EntityType): @@ -1138,7 +1518,12 @@ def update_entity_type( - ``description`` - ``labels`` - ``monitoring_config.snapshot_analysis.disabled`` - - ``monitoring_config.snapshot_analysis.monitoring_interval`` + - ``monitoring_config.snapshot_analysis.monitoring_interval_days`` + - ``monitoring_config.snapshot_analysis.staleness_days`` + - ``monitoring_config.import_features_analysis.state`` + - ``monitoring_config.import_features_analysis.anomaly_detection_baseline`` + - ``monitoring_config.numerical_threshold_config.value`` + - ``monitoring_config.categorical_threshold_config.value`` This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this @@ -1160,7 +1545,7 @@ def update_entity_type( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([entity_type, update_mask]) if request is not None and has_flattened_params: @@ -1195,17 +1580,23 @@ def update_entity_type( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def delete_entity_type( self, - request: featurestore_service.DeleteEntityTypeRequest = None, + request: Union[featurestore_service.DeleteEntityTypeRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + force: bool = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: @@ -1213,8 +1604,31 @@ def delete_entity_type( Features or ``force`` must be set to true for the request to succeed. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_delete_entity_type(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteEntityTypeRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_entity_type(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.DeleteEntityTypeRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteEntityTypeRequest, dict]): The request object. Request message for [FeaturestoreService.DeleteEntityTypes][]. name (str): @@ -1225,6 +1639,15 @@ def delete_entity_type( This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. + force (bool): + If set to true, any Features for this + EntityType will also be deleted. + (Otherwise, the request will only work + if the EntityType has no Features.) + + This corresponds to the ``force`` 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. @@ -1251,9 +1674,9 @@ def delete_entity_type( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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]) + has_flattened_params = any([name, force]) if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " @@ -1270,6 +1693,8 @@ def delete_entity_type( # request, apply these. if name is not None: request.name = name + if force is not None: + request.force = force # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1282,7 +1707,12 @@ def delete_entity_type( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -1297,18 +1727,47 @@ def delete_entity_type( def create_feature( self, - request: featurestore_service.CreateFeatureRequest = None, + request: Union[featurestore_service.CreateFeatureRequest, dict] = None, *, parent: str = None, feature: gca_feature.Feature = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + feature_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Creates a new Feature in a given EntityType. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_create_feature(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + feature = aiplatform_v1beta1.Feature() + feature.value_type = "BYTES" + + request = aiplatform_v1beta1.CreateFeatureRequest( + parent="parent_value", + feature=feature, + feature_id="feature_id_value", + ) + + # Make the request + operation = client.create_feature(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.CreateFeatureRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateFeatureRequest, dict]): The request object. Request message for [FeaturestoreService.CreateFeature][google.cloud.aiplatform.v1beta1.FeaturestoreService.CreateFeature]. parent (str): @@ -1324,6 +1783,20 @@ def create_feature( This corresponds to the ``feature`` field on the ``request`` instance; if ``request`` is provided, this should not be set. + feature_id (str): + Required. The ID to use for the Feature, which will + become the final component of the Feature's resource + name. + + This value may be up to 60 characters, and valid + characters are ``[a-z0-9_]``. The first character cannot + be a number. + + The value must be unique within an EntityType. + + This corresponds to the ``feature_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. @@ -1340,9 +1813,9 @@ def create_feature( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, feature]) + has_flattened_params = any([parent, feature, feature_id]) if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " @@ -1361,6 +1834,8 @@ def create_feature( request.parent = parent if feature is not None: request.feature = feature + if feature_id is not None: + request.feature_id = feature_id # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1373,7 +1848,12 @@ def create_feature( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -1388,18 +1868,47 @@ def create_feature( def batch_create_features( self, - request: featurestore_service.BatchCreateFeaturesRequest = None, + request: Union[featurestore_service.BatchCreateFeaturesRequest, dict] = None, *, parent: str = None, requests: Sequence[featurestore_service.CreateFeatureRequest] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Creates a batch of Features in a given EntityType. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_batch_create_features(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + requests = aiplatform_v1beta1.CreateFeatureRequest() + requests.parent = "parent_value" + requests.feature.value_type = "BYTES" + requests.feature_id = "feature_id_value" + + request = aiplatform_v1beta1.BatchCreateFeaturesRequest( + parent="parent_value", + requests=requests, + ) + + # Make the request + operation = client.batch_create_features(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.BatchCreateFeaturesRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.BatchCreateFeaturesRequest, dict]): The request object. Request message for [FeaturestoreService.BatchCreateFeatures][google.cloud.aiplatform.v1beta1.FeaturestoreService.BatchCreateFeatures]. parent (str): @@ -1438,7 +1947,7 @@ def batch_create_features( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, requests]) if request is not None and has_flattened_params: @@ -1471,7 +1980,12 @@ def batch_create_features( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -1486,17 +2000,36 @@ def batch_create_features( def get_feature( self, - request: featurestore_service.GetFeatureRequest = None, + request: Union[featurestore_service.GetFeatureRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> feature.Feature: r"""Gets details of a single Feature. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_get_feature(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetFeatureRequest( + name="name_value", + ) + + # Make the request + response = client.get_feature(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.GetFeatureRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.GetFeatureRequest, dict]): The request object. Request message for [FeaturestoreService.GetFeature][google.cloud.aiplatform.v1beta1.FeaturestoreService.GetFeature]. name (str): @@ -1522,7 +2055,7 @@ def get_feature( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1553,24 +2086,49 @@ def get_feature( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_features( self, - request: featurestore_service.ListFeaturesRequest = None, + request: Union[featurestore_service.ListFeaturesRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListFeaturesPager: r"""Lists Features in a given EntityType. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_list_features(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListFeaturesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_features(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ListFeaturesRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ListFeaturesRequest, dict]): The request object. Request message for [FeaturestoreService.ListFeatures][google.cloud.aiplatform.v1beta1.FeaturestoreService.ListFeatures]. parent (str): @@ -1597,7 +2155,7 @@ def list_features( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1628,12 +2186,20 @@ def list_features( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListFeaturesPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -1641,18 +2207,40 @@ def list_features( def update_feature( self, - request: featurestore_service.UpdateFeatureRequest = None, + request: Union[featurestore_service.UpdateFeatureRequest, dict] = None, *, feature: gca_feature.Feature = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_feature.Feature: r"""Updates the parameters of a single Feature. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_update_feature(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + feature = aiplatform_v1beta1.Feature() + feature.value_type = "BYTES" + + request = aiplatform_v1beta1.UpdateFeatureRequest( + feature=feature, + ) + + # Make the request + response = client.update_feature(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.UpdateFeatureRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.UpdateFeatureRequest, dict]): The request object. Request message for [FeaturestoreService.UpdateFeature][google.cloud.aiplatform.v1beta1.FeaturestoreService.UpdateFeature]. feature (google.cloud.aiplatform_v1beta1.types.Feature): @@ -1677,8 +2265,7 @@ def update_feature( - ``description`` - ``labels`` - - ``monitoring_config.snapshot_analysis.disabled`` - - ``monitoring_config.snapshot_analysis.monitoring_interval`` + - ``disable_monitoring`` This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this @@ -1699,7 +2286,7 @@ def update_feature( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([feature, update_mask]) if request is not None and has_flattened_params: @@ -1734,24 +2321,52 @@ def update_feature( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def delete_feature( self, - request: featurestore_service.DeleteFeatureRequest = None, + request: Union[featurestore_service.DeleteFeatureRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Deletes a single Feature. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_delete_feature(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteFeatureRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_feature(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.DeleteFeatureRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteFeatureRequest, dict]): The request object. Request message for [FeaturestoreService.DeleteFeature][google.cloud.aiplatform.v1beta1.FeaturestoreService.DeleteFeature]. name (str): @@ -1788,7 +2403,7 @@ def delete_feature( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1819,7 +2434,12 @@ def delete_feature( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -1834,10 +2454,10 @@ def delete_feature( def import_feature_values( self, - request: featurestore_service.ImportFeatureValuesRequest = None, + request: Union[featurestore_service.ImportFeatureValuesRequest, dict] = None, *, entity_type: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: @@ -1863,8 +2483,40 @@ def import_feature_values( or retention policy. - Online serving cluster is under-provisioned. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_import_feature_values(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + avro_source = aiplatform_v1beta1.AvroSource() + avro_source.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + + feature_specs = aiplatform_v1beta1.FeatureSpec() + feature_specs.id = "id_value" + + request = aiplatform_v1beta1.ImportFeatureValuesRequest( + avro_source=avro_source, + feature_time_field="feature_time_field_value", + entity_type="entity_type_value", + feature_specs=feature_specs, + ) + + # Make the request + operation = client.import_feature_values(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ImportFeatureValuesRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ImportFeatureValuesRequest, dict]): The request object. Request message for [FeaturestoreService.ImportFeatureValues][google.cloud.aiplatform.v1beta1.FeaturestoreService.ImportFeatureValues]. entity_type (str): @@ -1893,7 +2545,7 @@ def import_feature_values( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([entity_type]) if request is not None and has_flattened_params: @@ -1926,7 +2578,12 @@ def import_feature_values( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -1941,10 +2598,10 @@ def import_feature_values( def batch_read_feature_values( self, - request: featurestore_service.BatchReadFeatureValuesRequest = None, + request: Union[featurestore_service.BatchReadFeatureValuesRequest, dict] = None, *, featurestore: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: @@ -1955,11 +2612,46 @@ def batch_read_feature_values( correctness is guaranteed for Feature values of each read instance as of each instance's read timestamp. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_batch_read_feature_values(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + csv_read_instances = aiplatform_v1beta1.CsvSource() + csv_read_instances.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + + destination = aiplatform_v1beta1.FeatureValueDestination() + destination.bigquery_destination.output_uri = "output_uri_value" + + entity_type_specs = aiplatform_v1beta1.EntityTypeSpec() + entity_type_specs.entity_type_id = "entity_type_id_value" + entity_type_specs.feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1beta1.BatchReadFeatureValuesRequest( + csv_read_instances=csv_read_instances, + featurestore="featurestore_value", + destination=destination, + entity_type_specs=entity_type_specs, + ) + + # Make the request + operation = client.batch_read_feature_values(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.BatchReadFeatureValuesRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.BatchReadFeatureValuesRequest, dict]): The request object. Request message for [FeaturestoreService.BatchReadFeatureValues][google.cloud.aiplatform.v1beta1.FeaturestoreService.BatchReadFeatureValues]. - (- Next Id: 6 -) featurestore (str): Required. The resource name of the Featurestore from which to query Feature values. Format: @@ -1985,7 +2677,7 @@ def batch_read_feature_values( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([featurestore]) if request is not None and has_flattened_params: @@ -2020,7 +2712,12 @@ def batch_read_feature_values( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -2035,19 +2732,50 @@ def batch_read_feature_values( def export_feature_values( self, - request: featurestore_service.ExportFeatureValuesRequest = None, + request: Union[featurestore_service.ExportFeatureValuesRequest, dict] = None, *, entity_type: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Exports Feature values from all the entities of a target EntityType. - Args: - request (google.cloud.aiplatform_v1beta1.types.ExportFeatureValuesRequest): - The request object. Request message for + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_export_feature_values(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + destination = aiplatform_v1beta1.FeatureValueDestination() + destination.bigquery_destination.output_uri = "output_uri_value" + + feature_selector = aiplatform_v1beta1.FeatureSelector() + feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1beta1.ExportFeatureValuesRequest( + entity_type="entity_type_value", + destination=destination, + feature_selector=feature_selector, + ) + + # Make the request + operation = client.export_feature_values(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.ExportFeatureValuesRequest, dict]): + The request object. Request message for [FeaturestoreService.ExportFeatureValues][google.cloud.aiplatform.v1beta1.FeaturestoreService.ExportFeatureValues]. entity_type (str): Required. The resource name of the EntityType from which @@ -2074,7 +2802,7 @@ def export_feature_values( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([entity_type]) if request is not None and has_flattened_params: @@ -2107,7 +2835,12 @@ def export_feature_values( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -2122,18 +2855,39 @@ def export_feature_values( def search_features( self, - request: featurestore_service.SearchFeaturesRequest = None, + request: Union[featurestore_service.SearchFeaturesRequest, dict] = None, *, location: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + query: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.SearchFeaturesPager: r"""Searches Features matching a query in a given project. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_search_features(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.SearchFeaturesRequest( + location="location_value", + ) + + # Make the request + page_result = client.search_features(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.SearchFeaturesRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.SearchFeaturesRequest, dict]): The request object. Request message for [FeaturestoreService.SearchFeatures][google.cloud.aiplatform.v1beta1.FeaturestoreService.SearchFeatures]. location (str): @@ -2144,6 +2898,81 @@ def search_features( This corresponds to the ``location`` field on the ``request`` instance; if ``request`` is provided, this should not be set. + query (str): + Query string that is a conjunction of field-restricted + queries and/or field-restricted filters. + Field-restricted queries and filters can be combined + using ``AND`` to form a conjunction. + + A field query is in the form FIELD:QUERY. This + implicitly checks if QUERY exists as a substring within + Feature's FIELD. The QUERY and the FIELD are converted + to a sequence of words (i.e. tokens) for comparison. + This is done by: + + - Removing leading/trailing whitespace and tokenizing + the search value. Characters that are not one of + alphanumeric ``[a-zA-Z0-9]``, underscore ``_``, or + asterisk ``*`` are treated as delimiters for tokens. + ``*`` is treated as a wildcard that matches + characters within a token. + - Ignoring case. + - Prepending an asterisk to the first and appending an + asterisk to the last token in QUERY. + + A QUERY must be either a singular token or a phrase. A + phrase is one or multiple words enclosed in double + quotation marks ("). With phrases, the order of the + words is important. Words in the phrase must be matching + in order and consecutively. + + Supported FIELDs for field-restricted queries: + + - ``feature_id`` + - ``description`` + - ``entity_type_id`` + + Examples: + + - ``feature_id: foo`` --> Matches a Feature with ID + containing the substring ``foo`` (eg. ``foo``, + ``foofeature``, ``barfoo``). + - ``feature_id: foo*feature`` --> Matches a Feature + with ID containing the substring ``foo*feature`` (eg. + ``foobarfeature``). + - ``feature_id: foo AND description: bar`` --> Matches + a Feature with ID containing the substring ``foo`` + and description containing the substring ``bar``. + + Besides field queries, the following exact-match filters + are supported. The exact-match filters do not support + wildcards. Unlike field-restricted queries, exact-match + filters are case-sensitive. + + - ``feature_id``: Supports = comparisons. + - ``description``: Supports = comparisons. Multi-token + filters should be enclosed in quotes. + - ``entity_type_id``: Supports = comparisons. + - ``value_type``: Supports = and != comparisons. + - ``labels``: Supports key-value equality as well as + key presence. + - ``featurestore_id``: Supports = comparisons. + + Examples: + + - ``description = "foo bar"`` --> Any Feature with + description exactly equal to ``foo bar`` + - ``value_type = DOUBLE`` --> Features whose type is + DOUBLE. + - ``labels.active = yes AND labels.env = prod`` --> + Features having both (active: yes) and (env: prod) + labels. + - ``labels.env: *`` --> Any Feature which has a label + with ``env`` as the key. + + 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. @@ -2160,9 +2989,9 @@ def search_features( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - has_flattened_params = any([location]) + has_flattened_params = any([location, query]) if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " @@ -2179,6 +3008,8 @@ def search_features( # request, apply these. if location is not None: request.location = location + if query is not None: + request.query = query # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2191,12 +3022,704 @@ def search_features( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.SearchFeaturesPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_operations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.delete_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.wait_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_location, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_locations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) # Done; return the response. diff --git a/google/cloud/aiplatform_v1beta1/services/featurestore_service/pagers.py b/google/cloud/aiplatform_v1beta1/services/featurestore_service/pagers.py index 26ba8e31d2..71fcd1f863 100644 --- a/google/cloud/aiplatform_v1beta1/services/featurestore_service/pagers.py +++ b/google/cloud/aiplatform_v1beta1/services/featurestore_service/pagers.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,13 +15,13 @@ # from typing import ( Any, - AsyncIterable, + AsyncIterator, Awaitable, Callable, - Iterable, Sequence, Tuple, Optional, + Iterator, ) from google.cloud.aiplatform_v1beta1.types import entity_type @@ -77,14 +77,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[featurestore_service.ListFeaturestoresResponse]: + def pages(self) -> Iterator[featurestore_service.ListFeaturestoresResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[featurestore.Featurestore]: + def __iter__(self) -> Iterator[featurestore.Featurestore]: for page in self.pages: yield from page.featurestores @@ -120,7 +120,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -143,14 +143,14 @@ def __getattr__(self, name: str) -> Any: @property async def pages( self, - ) -> AsyncIterable[featurestore_service.ListFeaturestoresResponse]: + ) -> AsyncIterator[featurestore_service.ListFeaturestoresResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[featurestore.Featurestore]: + def __aiter__(self) -> AsyncIterator[featurestore.Featurestore]: async def async_generator(): async for page in self.pages: for response in page.featurestores: @@ -209,14 +209,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[featurestore_service.ListEntityTypesResponse]: + def pages(self) -> Iterator[featurestore_service.ListEntityTypesResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[entity_type.EntityType]: + def __iter__(self) -> Iterator[entity_type.EntityType]: for page in self.pages: yield from page.entity_types @@ -250,7 +250,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -273,14 +273,14 @@ def __getattr__(self, name: str) -> Any: @property async def pages( self, - ) -> AsyncIterable[featurestore_service.ListEntityTypesResponse]: + ) -> AsyncIterator[featurestore_service.ListEntityTypesResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[entity_type.EntityType]: + def __aiter__(self) -> AsyncIterator[entity_type.EntityType]: async def async_generator(): async for page in self.pages: for response in page.entity_types: @@ -339,14 +339,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[featurestore_service.ListFeaturesResponse]: + def pages(self) -> Iterator[featurestore_service.ListFeaturesResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[feature.Feature]: + def __iter__(self) -> Iterator[feature.Feature]: for page in self.pages: yield from page.features @@ -380,7 +380,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -401,14 +401,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - async def pages(self) -> AsyncIterable[featurestore_service.ListFeaturesResponse]: + async def pages(self) -> AsyncIterator[featurestore_service.ListFeaturesResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[feature.Feature]: + def __aiter__(self) -> AsyncIterator[feature.Feature]: async def async_generator(): async for page in self.pages: for response in page.features: @@ -467,14 +467,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[featurestore_service.SearchFeaturesResponse]: + def pages(self) -> Iterator[featurestore_service.SearchFeaturesResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[feature.Feature]: + def __iter__(self) -> Iterator[feature.Feature]: for page in self.pages: yield from page.features @@ -508,7 +508,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -529,14 +529,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - async def pages(self) -> AsyncIterable[featurestore_service.SearchFeaturesResponse]: + async def pages(self) -> AsyncIterator[featurestore_service.SearchFeaturesResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[feature.Feature]: + def __aiter__(self) -> AsyncIterator[feature.Feature]: async def async_generator(): async for page in self.pages: for response in page.features: diff --git a/google/cloud/aiplatform_v1beta1/services/featurestore_service/transports/__init__.py b/google/cloud/aiplatform_v1beta1/services/featurestore_service/transports/__init__.py index 5c30b22b43..640a209314 100644 --- a/google/cloud/aiplatform_v1beta1/services/featurestore_service/transports/__init__.py +++ b/google/cloud/aiplatform_v1beta1/services/featurestore_service/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1beta1/services/featurestore_service/transports/base.py b/google/cloud/aiplatform_v1beta1/services/featurestore_service/transports/base.py index 7d9162a2fa..859eac4aa7 100644 --- a/google/cloud/aiplatform_v1beta1/services/featurestore_service/transports/base.py +++ b/google/cloud/aiplatform_v1beta1/services/featurestore_service/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,16 +15,16 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.api_core import operations_v1 # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.aiplatform_v1beta1.types import entity_type from google.cloud.aiplatform_v1beta1.types import entity_type as gca_entity_type @@ -32,6 +32,10 @@ from google.cloud.aiplatform_v1beta1.types import feature as gca_feature from google.cloud.aiplatform_v1beta1.types import featurestore from google.cloud.aiplatform_v1beta1.types import featurestore_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore try: @@ -43,17 +47,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - -_API_CORE_VERSION = google.api_core.__version__ - class FeaturestoreServiceTransport(abc.ABC): """Abstract transport class for FeaturestoreService.""" @@ -71,6 +64,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -94,16 +88,19 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -116,95 +113,79 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id ) - # Save the credentials. - self._credentials = credentials - - # TODO(busunkim): These two class methods are in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-api-core - # and google-auth are increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") - ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs - - # TODO: Remove this function once google-api-core >= 1.26.0 is required - @classmethod - def _get_self_signed_jwt_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Union[Optional[Sequence[str]], str]]: - """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" - - self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} - - if _API_CORE_VERSION and ( - packaging.version.parse(_API_CORE_VERSION) - >= packaging.version.parse("1.26.0") + # If the credentials are service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") ): - self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES - self_signed_jwt_kwargs["scopes"] = scopes - self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST - else: - self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES + credentials = credentials.with_always_use_jwt_access(True) - return self_signed_jwt_kwargs + # Save the credentials. + self._credentials = credentials def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { self.create_featurestore: gapic_v1.method.wrap_method( - self.create_featurestore, default_timeout=5.0, client_info=client_info, + self.create_featurestore, + default_timeout=5.0, + client_info=client_info, ), self.get_featurestore: gapic_v1.method.wrap_method( - self.get_featurestore, default_timeout=5.0, client_info=client_info, + self.get_featurestore, + default_timeout=5.0, + client_info=client_info, ), self.list_featurestores: gapic_v1.method.wrap_method( - self.list_featurestores, default_timeout=5.0, client_info=client_info, + self.list_featurestores, + default_timeout=5.0, + client_info=client_info, ), self.update_featurestore: gapic_v1.method.wrap_method( - self.update_featurestore, default_timeout=5.0, client_info=client_info, + self.update_featurestore, + default_timeout=5.0, + client_info=client_info, ), self.delete_featurestore: gapic_v1.method.wrap_method( - self.delete_featurestore, default_timeout=5.0, client_info=client_info, + self.delete_featurestore, + default_timeout=5.0, + client_info=client_info, ), self.create_entity_type: gapic_v1.method.wrap_method( - self.create_entity_type, default_timeout=5.0, client_info=client_info, + self.create_entity_type, + default_timeout=5.0, + client_info=client_info, ), self.get_entity_type: gapic_v1.method.wrap_method( - self.get_entity_type, default_timeout=5.0, client_info=client_info, + self.get_entity_type, + default_timeout=5.0, + client_info=client_info, ), self.list_entity_types: gapic_v1.method.wrap_method( - self.list_entity_types, default_timeout=5.0, client_info=client_info, + self.list_entity_types, + default_timeout=5.0, + client_info=client_info, ), self.update_entity_type: gapic_v1.method.wrap_method( - self.update_entity_type, default_timeout=5.0, client_info=client_info, + self.update_entity_type, + default_timeout=5.0, + client_info=client_info, ), self.delete_entity_type: gapic_v1.method.wrap_method( - self.delete_entity_type, default_timeout=5.0, client_info=client_info, + self.delete_entity_type, + default_timeout=5.0, + client_info=client_info, ), self.create_feature: gapic_v1.method.wrap_method( - self.create_feature, default_timeout=5.0, client_info=client_info, + self.create_feature, + default_timeout=5.0, + client_info=client_info, ), self.batch_create_features: gapic_v1.method.wrap_method( self.batch_create_features, @@ -212,16 +193,24 @@ def _prep_wrapped_messages(self, client_info): client_info=client_info, ), self.get_feature: gapic_v1.method.wrap_method( - self.get_feature, default_timeout=5.0, client_info=client_info, + self.get_feature, + default_timeout=5.0, + client_info=client_info, ), self.list_features: gapic_v1.method.wrap_method( - self.list_features, default_timeout=5.0, client_info=client_info, + self.list_features, + default_timeout=5.0, + client_info=client_info, ), self.update_feature: gapic_v1.method.wrap_method( - self.update_feature, default_timeout=5.0, client_info=client_info, + self.update_feature, + default_timeout=5.0, + client_info=client_info, ), self.delete_feature: gapic_v1.method.wrap_method( - self.delete_feature, default_timeout=5.0, client_info=client_info, + self.delete_feature, + default_timeout=5.0, + client_info=client_info, ), self.import_feature_values: gapic_v1.method.wrap_method( self.import_feature_values, @@ -239,12 +228,23 @@ def _prep_wrapped_messages(self, client_info): client_info=client_info, ), self.search_features: gapic_v1.method.wrap_method( - self.search_features, default_timeout=5.0, client_info=client_info, + self.search_features, + default_timeout=5.0, + client_info=client_info, ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() @@ -440,5 +440,102 @@ def search_features( ]: raise NotImplementedError() + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], + Union[ + operations_pb2.ListOperationsResponse, + Awaitable[operations_pb2.ListOperationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None,]: + raise NotImplementedError() + + @property + def wait_operation( + self, + ) -> Callable[ + [operations_pb2.WaitOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def set_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def get_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_location( + self, + ) -> Callable[ + [locations_pb2.GetLocationRequest], + Union[locations_pb2.Location, Awaitable[locations_pb2.Location]], + ]: + raise NotImplementedError() + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], + Union[ + locations_pb2.ListLocationsResponse, + Awaitable[locations_pb2.ListLocationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + __all__ = ("FeaturestoreServiceTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/featurestore_service/transports/grpc.py b/google/cloud/aiplatform_v1beta1/services/featurestore_service/transports/grpc.py index 4eb99eab64..6eafb7b60a 100644 --- a/google/cloud/aiplatform_v1beta1/services/featurestore_service/transports/grpc.py +++ b/google/cloud/aiplatform_v1beta1/services/featurestore_service/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,9 +16,9 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import operations_v1 +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -31,6 +31,10 @@ from google.cloud.aiplatform_v1beta1.types import feature as gca_feature from google.cloud.aiplatform_v1beta1.types import featurestore from google.cloud.aiplatform_v1beta1.types import featurestore_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from .base import FeaturestoreServiceTransport, DEFAULT_CLIENT_INFO @@ -65,6 +69,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -87,16 +92,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -105,6 +110,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport @@ -115,7 +122,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -158,13 +165,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -213,21 +224,20 @@ def create_channel( and ``credentials_file`` are passed. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @property def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ + """Return the channel designed to connect to this service.""" return self._grpc_channel @property @@ -237,7 +247,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsClient(self.grpc_channel) @@ -834,5 +844,215 @@ def search_features( ) return self._stubs["search_features"] + def close(self): + self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + @property + def kind(self) -> str: + return "grpc" + __all__ = ("FeaturestoreServiceGrpcTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/featurestore_service/transports/grpc_asyncio.py b/google/cloud/aiplatform_v1beta1/services/featurestore_service/transports/grpc_asyncio.py index 3c4cb14910..30d2970a8a 100644 --- a/google/cloud/aiplatform_v1beta1/services/featurestore_service/transports/grpc_asyncio.py +++ b/google/cloud/aiplatform_v1beta1/services/featurestore_service/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,12 +16,11 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore -from google.api_core import operations_v1 # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore @@ -32,6 +31,10 @@ from google.cloud.aiplatform_v1beta1.types import feature as gca_feature from google.cloud.aiplatform_v1beta1.types import featurestore from google.cloud.aiplatform_v1beta1.types import featurestore_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from .base import FeaturestoreServiceTransport, DEFAULT_CLIENT_INFO from .grpc import FeaturestoreServiceGrpcTransport @@ -86,14 +89,14 @@ def create_channel( aio.Channel: A gRPC AsyncIO channel object. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @@ -111,6 +114,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -134,16 +138,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -152,6 +156,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport @@ -162,7 +168,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -204,13 +210,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -240,7 +250,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel @@ -854,5 +864,211 @@ def search_features( ) return self._stubs["search_features"] + def close(self): + return self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + __all__ = ("FeaturestoreServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/index_endpoint_service/__init__.py b/google/cloud/aiplatform_v1beta1/services/index_endpoint_service/__init__.py index 499311d96c..7cde1c0f69 100644 --- a/google/cloud/aiplatform_v1beta1/services/index_endpoint_service/__init__.py +++ b/google/cloud/aiplatform_v1beta1/services/index_endpoint_service/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1beta1/services/index_endpoint_service/async_client.py b/google/cloud/aiplatform_v1beta1/services/index_endpoint_service/async_client.py index ef4ee399c0..36e86f2ee1 100644 --- a/google/cloud/aiplatform_v1beta1/services/index_endpoint_service/async_client.py +++ b/google/cloud/aiplatform_v1beta1/services/index_endpoint_service/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,16 +16,21 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation as gac_operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1beta1.services.index_endpoint_service import pagers @@ -33,6 +38,10 @@ from google.cloud.aiplatform_v1beta1.types import index_endpoint as gca_index_endpoint from google.cloud.aiplatform_v1beta1.types import index_endpoint_service from google.cloud.aiplatform_v1beta1.types import operation as gca_operation +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore @@ -42,7 +51,7 @@ class IndexEndpointServiceAsyncClient: - """A service for managing AI Platform's IndexEndpoints.""" + """A service for managing Vertex AI's IndexEndpoints.""" _client: IndexEndpointServiceClient @@ -82,7 +91,8 @@ class IndexEndpointServiceAsyncClient: @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -97,7 +107,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -112,9 +122,45 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return IndexEndpointServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> IndexEndpointServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: IndexEndpointServiceTransport: The transport used by the client instance. @@ -134,7 +180,7 @@ def __init__( client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the index endpoint service client. + """Instantiates the index endpoint service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -175,18 +221,45 @@ def __init__( async def create_index_endpoint( self, - request: index_endpoint_service.CreateIndexEndpointRequest = None, + request: Union[index_endpoint_service.CreateIndexEndpointRequest, dict] = None, *, parent: str = None, index_endpoint: gca_index_endpoint.IndexEndpoint = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Creates an IndexEndpoint. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_create_index_endpoint(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + index_endpoint = aiplatform_v1beta1.IndexEndpoint() + index_endpoint.display_name = "display_name_value" + + request = aiplatform_v1beta1.CreateIndexEndpointRequest( + parent="parent_value", + index_endpoint=index_endpoint, + ) + + # Make the request + operation = client.create_index_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.CreateIndexEndpointRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateIndexEndpointRequest, dict]): The request object. Request message for [IndexEndpointService.CreateIndexEndpoint][google.cloud.aiplatform.v1beta1.IndexEndpointService.CreateIndexEndpoint]. parent (:class:`str`): @@ -219,7 +292,7 @@ async def create_index_endpoint( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, index_endpoint]) if request is not None and has_flattened_params: @@ -252,7 +325,12 @@ async def create_index_endpoint( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -267,17 +345,36 @@ async def create_index_endpoint( async def get_index_endpoint( self, - request: index_endpoint_service.GetIndexEndpointRequest = None, + request: Union[index_endpoint_service.GetIndexEndpointRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> index_endpoint.IndexEndpoint: r"""Gets an IndexEndpoint. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_get_index_endpoint(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetIndexEndpointRequest( + name="name_value", + ) + + # Make the request + response = await client.get_index_endpoint(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.GetIndexEndpointRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.GetIndexEndpointRequest, dict]): The request object. Request message for [IndexEndpointService.GetIndexEndpoint][google.cloud.aiplatform.v1beta1.IndexEndpointService.GetIndexEndpoint] name (:class:`str`): @@ -302,7 +399,7 @@ async def get_index_endpoint( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -333,24 +430,49 @@ async def get_index_endpoint( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_index_endpoints( self, - request: index_endpoint_service.ListIndexEndpointsRequest = None, + request: Union[index_endpoint_service.ListIndexEndpointsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListIndexEndpointsAsyncPager: r"""Lists IndexEndpoints in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_list_index_endpoints(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListIndexEndpointsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_index_endpoints(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ListIndexEndpointsRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ListIndexEndpointsRequest, dict]): The request object. Request message for [IndexEndpointService.ListIndexEndpoints][google.cloud.aiplatform.v1beta1.IndexEndpointService.ListIndexEndpoints]. parent (:class:`str`): @@ -377,7 +499,7 @@ async def list_index_endpoints( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -408,12 +530,20 @@ async def list_index_endpoints( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListIndexEndpointsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -421,18 +551,40 @@ async def list_index_endpoints( async def update_index_endpoint( self, - request: index_endpoint_service.UpdateIndexEndpointRequest = None, + request: Union[index_endpoint_service.UpdateIndexEndpointRequest, dict] = None, *, index_endpoint: gca_index_endpoint.IndexEndpoint = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_index_endpoint.IndexEndpoint: r"""Updates an IndexEndpoint. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_update_index_endpoint(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + index_endpoint = aiplatform_v1beta1.IndexEndpoint() + index_endpoint.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateIndexEndpointRequest( + index_endpoint=index_endpoint, + ) + + # Make the request + response = await client.update_index_endpoint(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.UpdateIndexEndpointRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.UpdateIndexEndpointRequest, dict]): The request object. Request message for [IndexEndpointService.UpdateIndexEndpoint][google.cloud.aiplatform.v1beta1.IndexEndpointService.UpdateIndexEndpoint]. index_endpoint (:class:`google.cloud.aiplatform_v1beta1.types.IndexEndpoint`): @@ -444,7 +596,7 @@ async def update_index_endpoint( should not be set. update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): Required. The update mask applies to the resource. See - `FieldMask `__. + [google.protobuf.FieldMask][google.protobuf.FieldMask]. This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this @@ -463,7 +615,7 @@ async def update_index_endpoint( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([index_endpoint, update_mask]) if request is not None and has_flattened_params: @@ -498,24 +650,52 @@ async def update_index_endpoint( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def delete_index_endpoint( self, - request: index_endpoint_service.DeleteIndexEndpointRequest = None, + request: Union[index_endpoint_service.DeleteIndexEndpointRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes an IndexEndpoint. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_delete_index_endpoint(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteIndexEndpointRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_index_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.DeleteIndexEndpointRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteIndexEndpointRequest, dict]): The request object. Request message for [IndexEndpointService.DeleteIndexEndpoint][google.cloud.aiplatform.v1beta1.IndexEndpointService.DeleteIndexEndpoint]. name (:class:`str`): @@ -552,7 +732,7 @@ async def delete_index_endpoint( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -583,7 +763,12 @@ async def delete_index_endpoint( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -598,11 +783,11 @@ async def delete_index_endpoint( async def deploy_index( self, - request: index_endpoint_service.DeployIndexRequest = None, + request: Union[index_endpoint_service.DeployIndexRequest, dict] = None, *, index_endpoint: str = None, deployed_index: gca_index_endpoint.DeployedIndex = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -610,8 +795,36 @@ async def deploy_index( DeployedIndex within it. Only non-empty Indexes can be deployed. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_deploy_index(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + deployed_index = aiplatform_v1beta1.DeployedIndex() + deployed_index.id = "id_value" + deployed_index.index = "index_value" + + request = aiplatform_v1beta1.DeployIndexRequest( + index_endpoint="index_endpoint_value", + deployed_index=deployed_index, + ) + + # Make the request + operation = client.deploy_index(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.DeployIndexRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.DeployIndexRequest, dict]): The request object. Request message for [IndexEndpointService.DeployIndex][google.cloud.aiplatform.v1beta1.IndexEndpointService.DeployIndex]. index_endpoint (:class:`str`): @@ -646,7 +859,7 @@ async def deploy_index( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([index_endpoint, deployed_index]) if request is not None and has_flattened_params: @@ -681,7 +894,12 @@ async def deploy_index( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -696,11 +914,11 @@ async def deploy_index( async def undeploy_index( self, - request: index_endpoint_service.UndeployIndexRequest = None, + request: Union[index_endpoint_service.UndeployIndexRequest, dict] = None, *, index_endpoint: str = None, deployed_index_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -708,8 +926,32 @@ async def undeploy_index( DeployedIndex from it, and freeing all resources it's using. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_undeploy_index(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UndeployIndexRequest( + index_endpoint="index_endpoint_value", + deployed_index_id="deployed_index_id_value", + ) + + # Make the request + operation = client.undeploy_index(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.UndeployIndexRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.UndeployIndexRequest, dict]): The request object. Request message for [IndexEndpointService.UndeployIndex][google.cloud.aiplatform.v1beta1.IndexEndpointService.UndeployIndex]. index_endpoint (:class:`str`): @@ -744,7 +986,7 @@ async def undeploy_index( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([index_endpoint, deployed_index_id]) if request is not None and has_flattened_params: @@ -779,7 +1021,12 @@ async def undeploy_index( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -792,6 +1039,815 @@ async def undeploy_index( # Done; return the response. return response + async def mutate_deployed_index( + self, + request: Union[index_endpoint_service.MutateDeployedIndexRequest, dict] = None, + *, + index_endpoint: str = None, + deployed_index: gca_index_endpoint.DeployedIndex = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Update an existing DeployedIndex under an + IndexEndpoint. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_mutate_deployed_index(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + deployed_index = aiplatform_v1beta1.DeployedIndex() + deployed_index.id = "id_value" + deployed_index.index = "index_value" + + request = aiplatform_v1beta1.MutateDeployedIndexRequest( + index_endpoint="index_endpoint_value", + deployed_index=deployed_index, + ) + + # Make the request + operation = client.mutate_deployed_index(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.MutateDeployedIndexRequest, dict]): + The request object. Request message for + [IndexEndpointService.MutateDeployedIndex][google.cloud.aiplatform.v1beta1.IndexEndpointService.MutateDeployedIndex]. + index_endpoint (:class:`str`): + Required. The name of the IndexEndpoint resource into + which to deploy an Index. Format: + ``projects/{project}/locations/{location}/indexEndpoints/{index_endpoint}`` + + This corresponds to the ``index_endpoint`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + deployed_index (:class:`google.cloud.aiplatform_v1beta1.types.DeployedIndex`): + Required. The DeployedIndex to be updated within the + IndexEndpoint. Currently, the updatable fields are + [DeployedIndex][automatic_resources] and + [DeployedIndex][dedicated_resources] + + This corresponds to the ``deployed_index`` 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.aiplatform_v1beta1.types.MutateDeployedIndexResponse` + Response message for + [IndexEndpointService.MutateDeployedIndex][google.cloud.aiplatform.v1beta1.IndexEndpointService.MutateDeployedIndex]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([index_endpoint, deployed_index]) + 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 = index_endpoint_service.MutateDeployedIndexRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if index_endpoint is not None: + request.index_endpoint = index_endpoint + if deployed_index is not None: + request.deployed_index = deployed_index + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.mutate_deployed_index, + default_timeout=None, + 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( + (("index_endpoint", request.index_endpoint),) + ), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + index_endpoint_service.MutateDeployedIndexResponse, + metadata_type=index_endpoint_service.MutateDeployedIndexOperationMetadata, + ) + + # Done; return the response. + return response + + async def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_operations, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.delete_operation, + default_timeout=None, + 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 cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + 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 wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.wait_operation, + default_timeout=None, + 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 set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_location, + default_timeout=None, + 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 list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_locations, + default_timeout=None, + 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 __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/aiplatform_v1beta1/services/index_endpoint_service/client.py b/google/cloud/aiplatform_v1beta1/services/index_endpoint_service/client.py index 6d37fc13fd..5ba49563a8 100644 --- a/google/cloud/aiplatform_v1beta1/services/index_endpoint_service/client.py +++ b/google/cloud/aiplatform_v1beta1/services/index_endpoint_service/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,22 +14,26 @@ # 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 +from typing import Dict, Mapping, 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 as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_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 +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation as gac_operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1beta1.services.index_endpoint_service import pagers @@ -37,6 +41,10 @@ from google.cloud.aiplatform_v1beta1.types import index_endpoint as gca_index_endpoint from google.cloud.aiplatform_v1beta1.types import index_endpoint_service from google.cloud.aiplatform_v1beta1.types import operation as gca_operation +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore @@ -60,9 +68,10 @@ class IndexEndpointServiceClientMeta(type): _transport_registry["grpc_asyncio"] = IndexEndpointServiceGrpcAsyncIOTransport def get_transport_class( - cls, label: str = None, + cls, + label: str = None, ) -> Type[IndexEndpointServiceTransport]: - """Return an appropriate transport class. + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -81,11 +90,12 @@ def get_transport_class( class IndexEndpointServiceClient(metaclass=IndexEndpointServiceClientMeta): - """A service for managing AI Platform's IndexEndpoints.""" + """A service for managing Vertex AI's IndexEndpoints.""" @staticmethod def _get_default_mtls_endpoint(api_endpoint): - """Convert api endpoint to mTLS endpoint. + """Converts api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. Args: @@ -119,7 +129,8 @@ def _get_default_mtls_endpoint(api_endpoint): @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -136,7 +147,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -155,23 +166,30 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> IndexEndpointServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - IndexEndpointServiceTransport: The transport used by the client instance. + IndexEndpointServiceTransport: The transport used by the client + instance. """ return self._transport @staticmethod - def index_path(project: str, location: str, index: str,) -> str: - """Return a fully-qualified index string.""" + def index_path( + project: str, + location: str, + index: str, + ) -> str: + """Returns a fully-qualified index string.""" return "projects/{project}/locations/{location}/indexes/{index}".format( - project=project, location=location, index=index, + project=project, + location=location, + index=index, ) @staticmethod def parse_index_path(path: str) -> Dict[str, str]: - """Parse a index path into its component segments.""" + """Parses a index path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/indexes/(?P.+?)$", path, @@ -179,15 +197,21 @@ def parse_index_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def index_endpoint_path(project: str, location: str, index_endpoint: str,) -> str: - """Return a fully-qualified index_endpoint string.""" + def index_endpoint_path( + project: str, + location: str, + index_endpoint: str, + ) -> str: + """Returns a fully-qualified index_endpoint string.""" return "projects/{project}/locations/{location}/indexEndpoints/{index_endpoint}".format( - project=project, location=location, index_endpoint=index_endpoint, + project=project, + location=location, + index_endpoint=index_endpoint, ) @staticmethod def parse_index_endpoint_path(path: str) -> Dict[str, str]: - """Parse a index_endpoint path into its component segments.""" + """Parses a index_endpoint path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/indexEndpoints/(?P.+?)$", path, @@ -195,8 +219,10 @@ def parse_index_endpoint_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + def common_billing_account_path( + billing_account: str, + ) -> str: + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -208,9 +234,13 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: 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,) + def common_folder_path( + folder: str, + ) -> str: + """Returns a fully-qualified folder string.""" + return "folders/{folder}".format( + folder=folder, + ) @staticmethod def parse_common_folder_path(path: str) -> Dict[str, str]: @@ -219,9 +249,13 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: 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,) + def common_organization_path( + organization: str, + ) -> str: + """Returns a fully-qualified organization string.""" + return "organizations/{organization}".format( + organization=organization, + ) @staticmethod def parse_common_organization_path(path: str) -> Dict[str, str]: @@ -230,9 +264,13 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: 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,) + def common_project_path( + project: str, + ) -> str: + """Returns a fully-qualified project string.""" + return "projects/{project}".format( + project=project, + ) @staticmethod def parse_common_project_path(path: str) -> Dict[str, str]: @@ -241,10 +279,14 @@ def parse_common_project_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_location_path(project: str, location: str,) -> str: - """Return a fully-qualified location string.""" + def common_location_path( + project: str, + location: str, + ) -> str: + """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) @staticmethod @@ -253,6 +295,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + def __init__( self, *, @@ -261,7 +370,7 @@ def __init__( client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the index endpoint service client. + """Instantiates the index endpoint service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -303,58 +412,42 @@ def __init__( 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")) + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - client_cert_source_func = ( - mtls.default_client_cert_source() 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" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # 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, IndexEndpointServiceTransport): # transport is a IndexEndpointServiceTransport instance. - if credentials or client_options.credentials_file: + if credentials or client_options.credentials_file or api_key_value: 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." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + Transport = type(self).get_transport_class(transport) self._transport = Transport( credentials=credentials, @@ -364,22 +457,50 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, + always_use_jwt_access=True, ) def create_index_endpoint( self, - request: index_endpoint_service.CreateIndexEndpointRequest = None, + request: Union[index_endpoint_service.CreateIndexEndpointRequest, dict] = None, *, parent: str = None, index_endpoint: gca_index_endpoint.IndexEndpoint = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Creates an IndexEndpoint. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_create_index_endpoint(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceClient() + + # Initialize request argument(s) + index_endpoint = aiplatform_v1beta1.IndexEndpoint() + index_endpoint.display_name = "display_name_value" + + request = aiplatform_v1beta1.CreateIndexEndpointRequest( + parent="parent_value", + index_endpoint=index_endpoint, + ) + + # Make the request + operation = client.create_index_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.CreateIndexEndpointRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateIndexEndpointRequest, dict]): The request object. Request message for [IndexEndpointService.CreateIndexEndpoint][google.cloud.aiplatform.v1beta1.IndexEndpointService.CreateIndexEndpoint]. parent (str): @@ -412,7 +533,7 @@ def create_index_endpoint( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, index_endpoint]) if request is not None and has_flattened_params: @@ -445,7 +566,12 @@ def create_index_endpoint( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -460,17 +586,36 @@ def create_index_endpoint( def get_index_endpoint( self, - request: index_endpoint_service.GetIndexEndpointRequest = None, + request: Union[index_endpoint_service.GetIndexEndpointRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> index_endpoint.IndexEndpoint: r"""Gets an IndexEndpoint. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_get_index_endpoint(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetIndexEndpointRequest( + name="name_value", + ) + + # Make the request + response = client.get_index_endpoint(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.GetIndexEndpointRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.GetIndexEndpointRequest, dict]): The request object. Request message for [IndexEndpointService.GetIndexEndpoint][google.cloud.aiplatform.v1beta1.IndexEndpointService.GetIndexEndpoint] name (str): @@ -495,7 +640,7 @@ def get_index_endpoint( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -526,24 +671,49 @@ def get_index_endpoint( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_index_endpoints( self, - request: index_endpoint_service.ListIndexEndpointsRequest = None, + request: Union[index_endpoint_service.ListIndexEndpointsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListIndexEndpointsPager: r"""Lists IndexEndpoints in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_list_index_endpoints(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListIndexEndpointsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_index_endpoints(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ListIndexEndpointsRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ListIndexEndpointsRequest, dict]): The request object. Request message for [IndexEndpointService.ListIndexEndpoints][google.cloud.aiplatform.v1beta1.IndexEndpointService.ListIndexEndpoints]. parent (str): @@ -570,7 +740,7 @@ def list_index_endpoints( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -601,12 +771,20 @@ def list_index_endpoints( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListIndexEndpointsPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -614,18 +792,40 @@ def list_index_endpoints( def update_index_endpoint( self, - request: index_endpoint_service.UpdateIndexEndpointRequest = None, + request: Union[index_endpoint_service.UpdateIndexEndpointRequest, dict] = None, *, index_endpoint: gca_index_endpoint.IndexEndpoint = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_index_endpoint.IndexEndpoint: r"""Updates an IndexEndpoint. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_update_index_endpoint(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceClient() + + # Initialize request argument(s) + index_endpoint = aiplatform_v1beta1.IndexEndpoint() + index_endpoint.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateIndexEndpointRequest( + index_endpoint=index_endpoint, + ) + + # Make the request + response = client.update_index_endpoint(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.UpdateIndexEndpointRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.UpdateIndexEndpointRequest, dict]): The request object. Request message for [IndexEndpointService.UpdateIndexEndpoint][google.cloud.aiplatform.v1beta1.IndexEndpointService.UpdateIndexEndpoint]. index_endpoint (google.cloud.aiplatform_v1beta1.types.IndexEndpoint): @@ -637,7 +837,7 @@ def update_index_endpoint( should not be set. update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. The update mask applies to the resource. See - `FieldMask `__. + [google.protobuf.FieldMask][google.protobuf.FieldMask]. This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this @@ -656,7 +856,7 @@ def update_index_endpoint( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([index_endpoint, update_mask]) if request is not None and has_flattened_params: @@ -691,24 +891,52 @@ def update_index_endpoint( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def delete_index_endpoint( self, - request: index_endpoint_service.DeleteIndexEndpointRequest = None, + request: Union[index_endpoint_service.DeleteIndexEndpointRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Deletes an IndexEndpoint. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_delete_index_endpoint(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteIndexEndpointRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_index_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.DeleteIndexEndpointRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteIndexEndpointRequest, dict]): The request object. Request message for [IndexEndpointService.DeleteIndexEndpoint][google.cloud.aiplatform.v1beta1.IndexEndpointService.DeleteIndexEndpoint]. name (str): @@ -745,7 +973,7 @@ def delete_index_endpoint( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -776,7 +1004,12 @@ def delete_index_endpoint( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -791,11 +1024,11 @@ def delete_index_endpoint( def deploy_index( self, - request: index_endpoint_service.DeployIndexRequest = None, + request: Union[index_endpoint_service.DeployIndexRequest, dict] = None, *, index_endpoint: str = None, deployed_index: gca_index_endpoint.DeployedIndex = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: @@ -803,8 +1036,36 @@ def deploy_index( DeployedIndex within it. Only non-empty Indexes can be deployed. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_deploy_index(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceClient() + + # Initialize request argument(s) + deployed_index = aiplatform_v1beta1.DeployedIndex() + deployed_index.id = "id_value" + deployed_index.index = "index_value" + + request = aiplatform_v1beta1.DeployIndexRequest( + index_endpoint="index_endpoint_value", + deployed_index=deployed_index, + ) + + # Make the request + operation = client.deploy_index(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.DeployIndexRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.DeployIndexRequest, dict]): The request object. Request message for [IndexEndpointService.DeployIndex][google.cloud.aiplatform.v1beta1.IndexEndpointService.DeployIndex]. index_endpoint (str): @@ -839,7 +1100,7 @@ def deploy_index( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([index_endpoint, deployed_index]) if request is not None and has_flattened_params: @@ -874,7 +1135,12 @@ def deploy_index( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -889,11 +1155,11 @@ def deploy_index( def undeploy_index( self, - request: index_endpoint_service.UndeployIndexRequest = None, + request: Union[index_endpoint_service.UndeployIndexRequest, dict] = None, *, index_endpoint: str = None, deployed_index_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: @@ -901,8 +1167,32 @@ def undeploy_index( DeployedIndex from it, and freeing all resources it's using. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_undeploy_index(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UndeployIndexRequest( + index_endpoint="index_endpoint_value", + deployed_index_id="deployed_index_id_value", + ) + + # Make the request + operation = client.undeploy_index(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.UndeployIndexRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.UndeployIndexRequest, dict]): The request object. Request message for [IndexEndpointService.UndeployIndex][google.cloud.aiplatform.v1beta1.IndexEndpointService.UndeployIndex]. index_endpoint (str): @@ -937,7 +1227,7 @@ def undeploy_index( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([index_endpoint, deployed_index_id]) if request is not None and has_flattened_params: @@ -972,7 +1262,12 @@ def undeploy_index( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -985,6 +1280,822 @@ def undeploy_index( # Done; return the response. return response + def mutate_deployed_index( + self, + request: Union[index_endpoint_service.MutateDeployedIndexRequest, dict] = None, + *, + index_endpoint: str = None, + deployed_index: gca_index_endpoint.DeployedIndex = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gac_operation.Operation: + r"""Update an existing DeployedIndex under an + IndexEndpoint. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_mutate_deployed_index(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceClient() + + # Initialize request argument(s) + deployed_index = aiplatform_v1beta1.DeployedIndex() + deployed_index.id = "id_value" + deployed_index.index = "index_value" + + request = aiplatform_v1beta1.MutateDeployedIndexRequest( + index_endpoint="index_endpoint_value", + deployed_index=deployed_index, + ) + + # Make the request + operation = client.mutate_deployed_index(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.MutateDeployedIndexRequest, dict]): + The request object. Request message for + [IndexEndpointService.MutateDeployedIndex][google.cloud.aiplatform.v1beta1.IndexEndpointService.MutateDeployedIndex]. + index_endpoint (str): + Required. The name of the IndexEndpoint resource into + which to deploy an Index. Format: + ``projects/{project}/locations/{location}/indexEndpoints/{index_endpoint}`` + + This corresponds to the ``index_endpoint`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + deployed_index (google.cloud.aiplatform_v1beta1.types.DeployedIndex): + Required. The DeployedIndex to be updated within the + IndexEndpoint. Currently, the updatable fields are + [DeployedIndex][automatic_resources] and + [DeployedIndex][dedicated_resources] + + This corresponds to the ``deployed_index`` 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: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.aiplatform_v1beta1.types.MutateDeployedIndexResponse` + Response message for + [IndexEndpointService.MutateDeployedIndex][google.cloud.aiplatform.v1beta1.IndexEndpointService.MutateDeployedIndex]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([index_endpoint, deployed_index]) + 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 index_endpoint_service.MutateDeployedIndexRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, index_endpoint_service.MutateDeployedIndexRequest): + request = index_endpoint_service.MutateDeployedIndexRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if index_endpoint is not None: + request.index_endpoint = index_endpoint + if deployed_index is not None: + request.deployed_index = deployed_index + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.mutate_deployed_index] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("index_endpoint", request.index_endpoint),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + index_endpoint_service.MutateDeployedIndexResponse, + metadata_type=index_endpoint_service.MutateDeployedIndexOperationMetadata, + ) + + # Done; return the response. + return response + + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_operations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.delete_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.wait_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_location, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_locations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/aiplatform_v1beta1/services/index_endpoint_service/pagers.py b/google/cloud/aiplatform_v1beta1/services/index_endpoint_service/pagers.py index f85618275b..375e54edee 100644 --- a/google/cloud/aiplatform_v1beta1/services/index_endpoint_service/pagers.py +++ b/google/cloud/aiplatform_v1beta1/services/index_endpoint_service/pagers.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,13 +15,13 @@ # from typing import ( Any, - AsyncIterable, + AsyncIterator, Awaitable, Callable, - Iterable, Sequence, Tuple, Optional, + Iterator, ) from google.cloud.aiplatform_v1beta1.types import index_endpoint @@ -75,14 +75,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[index_endpoint_service.ListIndexEndpointsResponse]: + def pages(self) -> Iterator[index_endpoint_service.ListIndexEndpointsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[index_endpoint.IndexEndpoint]: + def __iter__(self) -> Iterator[index_endpoint.IndexEndpoint]: for page in self.pages: yield from page.index_endpoints @@ -118,7 +118,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -141,14 +141,14 @@ def __getattr__(self, name: str) -> Any: @property async def pages( self, - ) -> AsyncIterable[index_endpoint_service.ListIndexEndpointsResponse]: + ) -> AsyncIterator[index_endpoint_service.ListIndexEndpointsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[index_endpoint.IndexEndpoint]: + def __aiter__(self) -> AsyncIterator[index_endpoint.IndexEndpoint]: async def async_generator(): async for page in self.pages: for response in page.index_endpoints: diff --git a/google/cloud/aiplatform_v1beta1/services/index_endpoint_service/transports/__init__.py b/google/cloud/aiplatform_v1beta1/services/index_endpoint_service/transports/__init__.py index cae6e2f624..d41c1630fb 100644 --- a/google/cloud/aiplatform_v1beta1/services/index_endpoint_service/transports/__init__.py +++ b/google/cloud/aiplatform_v1beta1/services/index_endpoint_service/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1beta1/services/index_endpoint_service/transports/base.py b/google/cloud/aiplatform_v1beta1/services/index_endpoint_service/transports/base.py index cbc16d1221..1cce447b4f 100644 --- a/google/cloud/aiplatform_v1beta1/services/index_endpoint_service/transports/base.py +++ b/google/cloud/aiplatform_v1beta1/services/index_endpoint_service/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,20 +15,24 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.api_core import operations_v1 # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.aiplatform_v1beta1.types import index_endpoint from google.cloud.aiplatform_v1beta1.types import index_endpoint as gca_index_endpoint from google.cloud.aiplatform_v1beta1.types import index_endpoint_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore try: @@ -40,17 +44,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - -_API_CORE_VERSION = google.api_core.__version__ - class IndexEndpointServiceTransport(abc.ABC): """Abstract transport class for IndexEndpointService.""" @@ -68,6 +61,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -91,16 +85,19 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -113,59 +110,21 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id ) - # Save the credentials. - self._credentials = credentials - - # TODO(busunkim): These two class methods are in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-api-core - # and google-auth are increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") + # If the credentials are service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs - - # TODO: Remove this function once google-api-core >= 1.26.0 is required - @classmethod - def _get_self_signed_jwt_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Union[Optional[Sequence[str]], str]]: - """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" - - self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} + credentials = credentials.with_always_use_jwt_access(True) - if _API_CORE_VERSION and ( - packaging.version.parse(_API_CORE_VERSION) - >= packaging.version.parse("1.26.0") - ): - self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES - self_signed_jwt_kwargs["scopes"] = scopes - self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST - else: - self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES - - return self_signed_jwt_kwargs + # Save the credentials. + self._credentials = credentials def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. @@ -176,10 +135,14 @@ def _prep_wrapped_messages(self, client_info): client_info=client_info, ), self.get_index_endpoint: gapic_v1.method.wrap_method( - self.get_index_endpoint, default_timeout=5.0, client_info=client_info, + self.get_index_endpoint, + default_timeout=5.0, + client_info=client_info, ), self.list_index_endpoints: gapic_v1.method.wrap_method( - self.list_index_endpoints, default_timeout=5.0, client_info=client_info, + self.list_index_endpoints, + default_timeout=5.0, + client_info=client_info, ), self.update_index_endpoint: gapic_v1.method.wrap_method( self.update_index_endpoint, @@ -192,15 +155,33 @@ def _prep_wrapped_messages(self, client_info): client_info=client_info, ), self.deploy_index: gapic_v1.method.wrap_method( - self.deploy_index, default_timeout=5.0, client_info=client_info, + self.deploy_index, + default_timeout=5.0, + client_info=client_info, ), self.undeploy_index: gapic_v1.method.wrap_method( - self.undeploy_index, default_timeout=5.0, client_info=client_info, + self.undeploy_index, + default_timeout=5.0, + client_info=client_info, + ), + self.mutate_deployed_index: gapic_v1.method.wrap_method( + self.mutate_deployed_index, + default_timeout=None, + client_info=client_info, ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() @@ -273,5 +254,111 @@ def undeploy_index( ]: raise NotImplementedError() + @property + def mutate_deployed_index( + self, + ) -> Callable[ + [index_endpoint_service.MutateDeployedIndexRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], + Union[ + operations_pb2.ListOperationsResponse, + Awaitable[operations_pb2.ListOperationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None,]: + raise NotImplementedError() + + @property + def wait_operation( + self, + ) -> Callable[ + [operations_pb2.WaitOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def set_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def get_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_location( + self, + ) -> Callable[ + [locations_pb2.GetLocationRequest], + Union[locations_pb2.Location, Awaitable[locations_pb2.Location]], + ]: + raise NotImplementedError() + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], + Union[ + locations_pb2.ListLocationsResponse, + Awaitable[locations_pb2.ListLocationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + __all__ = ("IndexEndpointServiceTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/index_endpoint_service/transports/grpc.py b/google/cloud/aiplatform_v1beta1/services/index_endpoint_service/transports/grpc.py index 7bd67d7b25..b02be2ed9f 100644 --- a/google/cloud/aiplatform_v1beta1/services/index_endpoint_service/transports/grpc.py +++ b/google/cloud/aiplatform_v1beta1/services/index_endpoint_service/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,9 +16,9 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import operations_v1 +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -28,6 +28,10 @@ from google.cloud.aiplatform_v1beta1.types import index_endpoint from google.cloud.aiplatform_v1beta1.types import index_endpoint as gca_index_endpoint from google.cloud.aiplatform_v1beta1.types import index_endpoint_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from .base import IndexEndpointServiceTransport, DEFAULT_CLIENT_INFO @@ -35,7 +39,7 @@ class IndexEndpointServiceGrpcTransport(IndexEndpointServiceTransport): """gRPC backend transport for IndexEndpointService. - A service for managing AI Platform's IndexEndpoints. + A service for managing Vertex AI's IndexEndpoints. This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation @@ -61,6 +65,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -83,16 +88,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -101,6 +106,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport @@ -111,7 +118,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -154,13 +161,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -209,21 +220,20 @@ def create_channel( and ``credentials_file`` are passed. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @property def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ + """Return the channel designed to connect to this service.""" return self._grpc_channel @property @@ -233,7 +243,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsClient(self.grpc_channel) @@ -442,5 +452,244 @@ def undeploy_index( ) return self._stubs["undeploy_index"] + @property + def mutate_deployed_index( + self, + ) -> Callable[ + [index_endpoint_service.MutateDeployedIndexRequest], operations_pb2.Operation + ]: + r"""Return a callable for the mutate deployed index method over gRPC. + + Update an existing DeployedIndex under an + IndexEndpoint. + + Returns: + Callable[[~.MutateDeployedIndexRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "mutate_deployed_index" not in self._stubs: + self._stubs["mutate_deployed_index"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1beta1.IndexEndpointService/MutateDeployedIndex", + request_serializer=index_endpoint_service.MutateDeployedIndexRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["mutate_deployed_index"] + + def close(self): + self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + @property + def kind(self) -> str: + return "grpc" + __all__ = ("IndexEndpointServiceGrpcTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/index_endpoint_service/transports/grpc_asyncio.py b/google/cloud/aiplatform_v1beta1/services/index_endpoint_service/transports/grpc_asyncio.py index 81891f2497..84c48b16bc 100644 --- a/google/cloud/aiplatform_v1beta1/services/index_endpoint_service/transports/grpc_asyncio.py +++ b/google/cloud/aiplatform_v1beta1/services/index_endpoint_service/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,12 +16,11 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore -from google.api_core import operations_v1 # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore @@ -29,6 +28,10 @@ from google.cloud.aiplatform_v1beta1.types import index_endpoint from google.cloud.aiplatform_v1beta1.types import index_endpoint as gca_index_endpoint from google.cloud.aiplatform_v1beta1.types import index_endpoint_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from .base import IndexEndpointServiceTransport, DEFAULT_CLIENT_INFO from .grpc import IndexEndpointServiceGrpcTransport @@ -37,7 +40,7 @@ class IndexEndpointServiceGrpcAsyncIOTransport(IndexEndpointServiceTransport): """gRPC AsyncIO backend transport for IndexEndpointService. - A service for managing AI Platform's IndexEndpoints. + A service for managing Vertex AI's IndexEndpoints. This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation @@ -82,14 +85,14 @@ def create_channel( aio.Channel: A gRPC AsyncIO channel object. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @@ -107,6 +110,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -130,16 +134,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -148,6 +152,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport @@ -158,7 +164,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -200,13 +206,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -236,7 +246,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel @@ -451,5 +461,241 @@ def undeploy_index( ) return self._stubs["undeploy_index"] + @property + def mutate_deployed_index( + self, + ) -> Callable[ + [index_endpoint_service.MutateDeployedIndexRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the mutate deployed index method over gRPC. + + Update an existing DeployedIndex under an + IndexEndpoint. + + Returns: + Callable[[~.MutateDeployedIndexRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "mutate_deployed_index" not in self._stubs: + self._stubs["mutate_deployed_index"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1beta1.IndexEndpointService/MutateDeployedIndex", + request_serializer=index_endpoint_service.MutateDeployedIndexRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["mutate_deployed_index"] + + def close(self): + return self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + __all__ = ("IndexEndpointServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/index_service/__init__.py b/google/cloud/aiplatform_v1beta1/services/index_service/__init__.py index c7eb9ed32d..a8323caaf7 100644 --- a/google/cloud/aiplatform_v1beta1/services/index_service/__init__.py +++ b/google/cloud/aiplatform_v1beta1/services/index_service/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1beta1/services/index_service/async_client.py b/google/cloud/aiplatform_v1beta1/services/index_service/async_client.py index 6dc98adec8..4c58c9e354 100644 --- a/google/cloud/aiplatform_v1beta1/services/index_service/async_client.py +++ b/google/cloud/aiplatform_v1beta1/services/index_service/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,16 +16,21 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation as gac_operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1beta1.services.index_service import pagers @@ -34,6 +39,10 @@ from google.cloud.aiplatform_v1beta1.types import index as gca_index from google.cloud.aiplatform_v1beta1.types import index_service from google.cloud.aiplatform_v1beta1.types import operation as gca_operation +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import struct_pb2 # type: ignore @@ -44,7 +53,7 @@ class IndexServiceAsyncClient: - """A service for creating and managing AI Platform's Index + """A service for creating and managing Vertex AI's Index resources. """ @@ -82,7 +91,8 @@ class IndexServiceAsyncClient: @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -97,7 +107,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -112,9 +122,45 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return IndexServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> IndexServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: IndexServiceTransport: The transport used by the client instance. @@ -133,7 +179,7 @@ def __init__( client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the index service client. + """Instantiates the index service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -174,18 +220,45 @@ def __init__( async def create_index( self, - request: index_service.CreateIndexRequest = None, + request: Union[index_service.CreateIndexRequest, dict] = None, *, parent: str = None, index: gca_index.Index = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Creates an Index. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_create_index(): + # Create a client + client = aiplatform_v1beta1.IndexServiceAsyncClient() + + # Initialize request argument(s) + index = aiplatform_v1beta1.Index() + index.display_name = "display_name_value" + + request = aiplatform_v1beta1.CreateIndexRequest( + parent="parent_value", + index=index, + ) + + # Make the request + operation = client.create_index(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.CreateIndexRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateIndexRequest, dict]): The request object. Request message for [IndexService.CreateIndex][google.cloud.aiplatform.v1beta1.IndexService.CreateIndex]. parent (:class:`str`): @@ -217,7 +290,7 @@ async def create_index( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, index]) if request is not None and has_flattened_params: @@ -250,7 +323,12 @@ async def create_index( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -265,17 +343,36 @@ async def create_index( async def get_index( self, - request: index_service.GetIndexRequest = None, + request: Union[index_service.GetIndexRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> index.Index: r"""Gets an Index. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_get_index(): + # Create a client + client = aiplatform_v1beta1.IndexServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetIndexRequest( + name="name_value", + ) + + # Make the request + response = await client.get_index(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.GetIndexRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.GetIndexRequest, dict]): The request object. Request message for [IndexService.GetIndex][google.cloud.aiplatform.v1beta1.IndexService.GetIndex] name (:class:`str`): @@ -300,7 +397,7 @@ async def get_index( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -331,24 +428,49 @@ async def get_index( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_indexes( self, - request: index_service.ListIndexesRequest = None, + request: Union[index_service.ListIndexesRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListIndexesAsyncPager: r"""Lists Indexes in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_list_indexes(): + # Create a client + client = aiplatform_v1beta1.IndexServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListIndexesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_indexes(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ListIndexesRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ListIndexesRequest, dict]): The request object. Request message for [IndexService.ListIndexes][google.cloud.aiplatform.v1beta1.IndexService.ListIndexes]. parent (:class:`str`): @@ -375,7 +497,7 @@ async def list_indexes( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -406,12 +528,20 @@ async def list_indexes( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListIndexesAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -419,18 +549,44 @@ async def list_indexes( async def update_index( self, - request: index_service.UpdateIndexRequest = None, + request: Union[index_service.UpdateIndexRequest, dict] = None, *, index: gca_index.Index = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Updates an Index. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_update_index(): + # Create a client + client = aiplatform_v1beta1.IndexServiceAsyncClient() + + # Initialize request argument(s) + index = aiplatform_v1beta1.Index() + index.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateIndexRequest( + index=index, + ) + + # Make the request + operation = client.update_index(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.UpdateIndexRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.UpdateIndexRequest, dict]): The request object. Request message for [IndexService.UpdateIndex][google.cloud.aiplatform.v1beta1.IndexService.UpdateIndex]. index (:class:`google.cloud.aiplatform_v1beta1.types.Index`): @@ -443,7 +599,7 @@ async def update_index( update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): The update mask applies to the resource. For the ``FieldMask`` definition, see - `FieldMask `__. + [google.protobuf.FieldMask][google.protobuf.FieldMask]. This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this @@ -464,7 +620,7 @@ async def update_index( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([index, update_mask]) if request is not None and has_flattened_params: @@ -499,7 +655,12 @@ async def update_index( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -514,10 +675,10 @@ async def update_index( async def delete_index( self, - request: index_service.DeleteIndexRequest = None, + request: Union[index_service.DeleteIndexRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -525,8 +686,31 @@ async def delete_index( [DeployedIndexes][google.cloud.aiplatform.v1beta1.Index.deployed_indexes] had been undeployed. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_delete_index(): + # Create a client + client = aiplatform_v1beta1.IndexServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteIndexRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_index(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.DeleteIndexRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteIndexRequest, dict]): The request object. Request message for [IndexService.DeleteIndex][google.cloud.aiplatform.v1beta1.IndexService.DeleteIndex]. name (:class:`str`): @@ -563,7 +747,7 @@ async def delete_index( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -594,7 +778,12 @@ async def delete_index( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -607,6 +796,683 @@ async def delete_index( # Done; return the response. return response + async def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_operations, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.delete_operation, + default_timeout=None, + 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 cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + 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 wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.wait_operation, + default_timeout=None, + 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 set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_location, + default_timeout=None, + 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 list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_locations, + default_timeout=None, + 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 __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/aiplatform_v1beta1/services/index_service/client.py b/google/cloud/aiplatform_v1beta1/services/index_service/client.py index d30489ea3f..24934b43f5 100644 --- a/google/cloud/aiplatform_v1beta1/services/index_service/client.py +++ b/google/cloud/aiplatform_v1beta1/services/index_service/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,22 +14,26 @@ # 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 +from typing import Dict, Mapping, 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 as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_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 +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation as gac_operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1beta1.services.index_service import pagers @@ -38,6 +42,10 @@ from google.cloud.aiplatform_v1beta1.types import index as gca_index from google.cloud.aiplatform_v1beta1.types import index_service from google.cloud.aiplatform_v1beta1.types import operation as gca_operation +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import struct_pb2 # type: ignore @@ -59,8 +67,11 @@ class IndexServiceClientMeta(type): _transport_registry["grpc"] = IndexServiceGrpcTransport _transport_registry["grpc_asyncio"] = IndexServiceGrpcAsyncIOTransport - def get_transport_class(cls, label: str = None,) -> Type[IndexServiceTransport]: - """Return an appropriate transport class. + def get_transport_class( + cls, + label: str = None, + ) -> Type[IndexServiceTransport]: + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -79,13 +90,14 @@ def get_transport_class(cls, label: str = None,) -> Type[IndexServiceTransport]: class IndexServiceClient(metaclass=IndexServiceClientMeta): - """A service for creating and managing AI Platform's Index + """A service for creating and managing Vertex AI's Index resources. """ @staticmethod def _get_default_mtls_endpoint(api_endpoint): - """Convert api endpoint to mTLS endpoint. + """Converts api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. Args: @@ -119,7 +131,8 @@ def _get_default_mtls_endpoint(api_endpoint): @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -136,7 +149,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -155,23 +168,30 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> IndexServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - IndexServiceTransport: The transport used by the client instance. + IndexServiceTransport: The transport used by the client + instance. """ return self._transport @staticmethod - def index_path(project: str, location: str, index: str,) -> str: - """Return a fully-qualified index string.""" + def index_path( + project: str, + location: str, + index: str, + ) -> str: + """Returns a fully-qualified index string.""" return "projects/{project}/locations/{location}/indexes/{index}".format( - project=project, location=location, index=index, + project=project, + location=location, + index=index, ) @staticmethod def parse_index_path(path: str) -> Dict[str, str]: - """Parse a index path into its component segments.""" + """Parses a index path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/indexes/(?P.+?)$", path, @@ -179,15 +199,21 @@ def parse_index_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def index_endpoint_path(project: str, location: str, index_endpoint: str,) -> str: - """Return a fully-qualified index_endpoint string.""" + def index_endpoint_path( + project: str, + location: str, + index_endpoint: str, + ) -> str: + """Returns a fully-qualified index_endpoint string.""" return "projects/{project}/locations/{location}/indexEndpoints/{index_endpoint}".format( - project=project, location=location, index_endpoint=index_endpoint, + project=project, + location=location, + index_endpoint=index_endpoint, ) @staticmethod def parse_index_endpoint_path(path: str) -> Dict[str, str]: - """Parse a index_endpoint path into its component segments.""" + """Parses a index_endpoint path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/indexEndpoints/(?P.+?)$", path, @@ -195,8 +221,10 @@ def parse_index_endpoint_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + def common_billing_account_path( + billing_account: str, + ) -> str: + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -208,9 +236,13 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: 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,) + def common_folder_path( + folder: str, + ) -> str: + """Returns a fully-qualified folder string.""" + return "folders/{folder}".format( + folder=folder, + ) @staticmethod def parse_common_folder_path(path: str) -> Dict[str, str]: @@ -219,9 +251,13 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: 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,) + def common_organization_path( + organization: str, + ) -> str: + """Returns a fully-qualified organization string.""" + return "organizations/{organization}".format( + organization=organization, + ) @staticmethod def parse_common_organization_path(path: str) -> Dict[str, str]: @@ -230,9 +266,13 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: 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,) + def common_project_path( + project: str, + ) -> str: + """Returns a fully-qualified project string.""" + return "projects/{project}".format( + project=project, + ) @staticmethod def parse_common_project_path(path: str) -> Dict[str, str]: @@ -241,10 +281,14 @@ def parse_common_project_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_location_path(project: str, location: str,) -> str: - """Return a fully-qualified location string.""" + def common_location_path( + project: str, + location: str, + ) -> str: + """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) @staticmethod @@ -253,6 +297,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + def __init__( self, *, @@ -261,7 +372,7 @@ def __init__( client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the index service client. + """Instantiates the index service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -303,58 +414,42 @@ def __init__( 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")) + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - client_cert_source_func = ( - mtls.default_client_cert_source() 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" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # 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, IndexServiceTransport): # transport is a IndexServiceTransport instance. - if credentials or client_options.credentials_file: + if credentials or client_options.credentials_file or api_key_value: 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." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + Transport = type(self).get_transport_class(transport) self._transport = Transport( credentials=credentials, @@ -364,22 +459,50 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, + always_use_jwt_access=True, ) def create_index( self, - request: index_service.CreateIndexRequest = None, + request: Union[index_service.CreateIndexRequest, dict] = None, *, parent: str = None, index: gca_index.Index = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Creates an Index. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_create_index(): + # Create a client + client = aiplatform_v1beta1.IndexServiceClient() + + # Initialize request argument(s) + index = aiplatform_v1beta1.Index() + index.display_name = "display_name_value" + + request = aiplatform_v1beta1.CreateIndexRequest( + parent="parent_value", + index=index, + ) + + # Make the request + operation = client.create_index(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.CreateIndexRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateIndexRequest, dict]): The request object. Request message for [IndexService.CreateIndex][google.cloud.aiplatform.v1beta1.IndexService.CreateIndex]. parent (str): @@ -411,7 +534,7 @@ def create_index( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, index]) if request is not None and has_flattened_params: @@ -444,7 +567,12 @@ def create_index( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -459,17 +587,36 @@ def create_index( def get_index( self, - request: index_service.GetIndexRequest = None, + request: Union[index_service.GetIndexRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> index.Index: r"""Gets an Index. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_get_index(): + # Create a client + client = aiplatform_v1beta1.IndexServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetIndexRequest( + name="name_value", + ) + + # Make the request + response = client.get_index(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.GetIndexRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.GetIndexRequest, dict]): The request object. Request message for [IndexService.GetIndex][google.cloud.aiplatform.v1beta1.IndexService.GetIndex] name (str): @@ -494,7 +641,7 @@ def get_index( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -525,24 +672,49 @@ def get_index( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_indexes( self, - request: index_service.ListIndexesRequest = None, + request: Union[index_service.ListIndexesRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListIndexesPager: r"""Lists Indexes in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_list_indexes(): + # Create a client + client = aiplatform_v1beta1.IndexServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListIndexesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_indexes(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ListIndexesRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ListIndexesRequest, dict]): The request object. Request message for [IndexService.ListIndexes][google.cloud.aiplatform.v1beta1.IndexService.ListIndexes]. parent (str): @@ -569,7 +741,7 @@ def list_indexes( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -600,12 +772,20 @@ def list_indexes( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListIndexesPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -613,18 +793,44 @@ def list_indexes( def update_index( self, - request: index_service.UpdateIndexRequest = None, + request: Union[index_service.UpdateIndexRequest, dict] = None, *, index: gca_index.Index = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Updates an Index. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_update_index(): + # Create a client + client = aiplatform_v1beta1.IndexServiceClient() + + # Initialize request argument(s) + index = aiplatform_v1beta1.Index() + index.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateIndexRequest( + index=index, + ) + + # Make the request + operation = client.update_index(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.UpdateIndexRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.UpdateIndexRequest, dict]): The request object. Request message for [IndexService.UpdateIndex][google.cloud.aiplatform.v1beta1.IndexService.UpdateIndex]. index (google.cloud.aiplatform_v1beta1.types.Index): @@ -637,7 +843,7 @@ def update_index( update_mask (google.protobuf.field_mask_pb2.FieldMask): The update mask applies to the resource. For the ``FieldMask`` definition, see - `FieldMask `__. + [google.protobuf.FieldMask][google.protobuf.FieldMask]. This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this @@ -658,7 +864,7 @@ def update_index( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([index, update_mask]) if request is not None and has_flattened_params: @@ -693,7 +899,12 @@ def update_index( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -708,10 +919,10 @@ def update_index( def delete_index( self, - request: index_service.DeleteIndexRequest = None, + request: Union[index_service.DeleteIndexRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: @@ -719,8 +930,31 @@ def delete_index( [DeployedIndexes][google.cloud.aiplatform.v1beta1.Index.deployed_indexes] had been undeployed. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_delete_index(): + # Create a client + client = aiplatform_v1beta1.IndexServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteIndexRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_index(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.DeleteIndexRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteIndexRequest, dict]): The request object. Request message for [IndexService.DeleteIndex][google.cloud.aiplatform.v1beta1.IndexService.DeleteIndex]. name (str): @@ -757,7 +991,7 @@ def delete_index( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -788,7 +1022,12 @@ def delete_index( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -801,6 +1040,690 @@ def delete_index( # Done; return the response. return response + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_operations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.delete_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.wait_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_location, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_locations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/aiplatform_v1beta1/services/index_service/pagers.py b/google/cloud/aiplatform_v1beta1/services/index_service/pagers.py index 010745adb4..e47b08bf94 100644 --- a/google/cloud/aiplatform_v1beta1/services/index_service/pagers.py +++ b/google/cloud/aiplatform_v1beta1/services/index_service/pagers.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,13 +15,13 @@ # from typing import ( Any, - AsyncIterable, + AsyncIterator, Awaitable, Callable, - Iterable, Sequence, Tuple, Optional, + Iterator, ) from google.cloud.aiplatform_v1beta1.types import index @@ -75,14 +75,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[index_service.ListIndexesResponse]: + def pages(self) -> Iterator[index_service.ListIndexesResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[index.Index]: + def __iter__(self) -> Iterator[index.Index]: for page in self.pages: yield from page.indexes @@ -116,7 +116,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -137,14 +137,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - async def pages(self) -> AsyncIterable[index_service.ListIndexesResponse]: + async def pages(self) -> AsyncIterator[index_service.ListIndexesResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[index.Index]: + def __aiter__(self) -> AsyncIterator[index.Index]: async def async_generator(): async for page in self.pages: for response in page.indexes: diff --git a/google/cloud/aiplatform_v1beta1/services/index_service/transports/__init__.py b/google/cloud/aiplatform_v1beta1/services/index_service/transports/__init__.py index 3d0c32ac92..c8bcfc04bf 100644 --- a/google/cloud/aiplatform_v1beta1/services/index_service/transports/__init__.py +++ b/google/cloud/aiplatform_v1beta1/services/index_service/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1beta1/services/index_service/transports/base.py b/google/cloud/aiplatform_v1beta1/services/index_service/transports/base.py index 731cd90024..7d01db68a4 100644 --- a/google/cloud/aiplatform_v1beta1/services/index_service/transports/base.py +++ b/google/cloud/aiplatform_v1beta1/services/index_service/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,19 +15,23 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.api_core import operations_v1 # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.aiplatform_v1beta1.types import index from google.cloud.aiplatform_v1beta1.types import index_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore try: @@ -39,17 +43,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - -_API_CORE_VERSION = google.api_core.__version__ - class IndexServiceTransport(abc.ABC): """Abstract transport class for IndexService.""" @@ -67,6 +60,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -90,16 +84,19 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -112,82 +109,63 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id ) - # Save the credentials. - self._credentials = credentials - - # TODO(busunkim): These two class methods are in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-api-core - # and google-auth are increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") + # If the credentials are service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs + credentials = credentials.with_always_use_jwt_access(True) - # TODO: Remove this function once google-api-core >= 1.26.0 is required - @classmethod - def _get_self_signed_jwt_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Union[Optional[Sequence[str]], str]]: - """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" - - self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} - - if _API_CORE_VERSION and ( - packaging.version.parse(_API_CORE_VERSION) - >= packaging.version.parse("1.26.0") - ): - self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES - self_signed_jwt_kwargs["scopes"] = scopes - self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST - else: - self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES - - return self_signed_jwt_kwargs + # Save the credentials. + self._credentials = credentials def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { self.create_index: gapic_v1.method.wrap_method( - self.create_index, default_timeout=5.0, client_info=client_info, + self.create_index, + default_timeout=5.0, + client_info=client_info, ), self.get_index: gapic_v1.method.wrap_method( - self.get_index, default_timeout=5.0, client_info=client_info, + self.get_index, + default_timeout=5.0, + client_info=client_info, ), self.list_indexes: gapic_v1.method.wrap_method( - self.list_indexes, default_timeout=5.0, client_info=client_info, + self.list_indexes, + default_timeout=5.0, + client_info=client_info, ), self.update_index: gapic_v1.method.wrap_method( - self.update_index, default_timeout=5.0, client_info=client_info, + self.update_index, + default_timeout=5.0, + client_info=client_info, ), self.delete_index: gapic_v1.method.wrap_method( - self.delete_index, default_timeout=5.0, client_info=client_info, + self.delete_index, + default_timeout=5.0, + client_info=client_info, ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() @@ -238,5 +216,102 @@ def delete_index( ]: raise NotImplementedError() + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], + Union[ + operations_pb2.ListOperationsResponse, + Awaitable[operations_pb2.ListOperationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None,]: + raise NotImplementedError() + + @property + def wait_operation( + self, + ) -> Callable[ + [operations_pb2.WaitOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def set_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def get_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_location( + self, + ) -> Callable[ + [locations_pb2.GetLocationRequest], + Union[locations_pb2.Location, Awaitable[locations_pb2.Location]], + ]: + raise NotImplementedError() + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], + Union[ + locations_pb2.ListLocationsResponse, + Awaitable[locations_pb2.ListLocationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + __all__ = ("IndexServiceTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/index_service/transports/grpc.py b/google/cloud/aiplatform_v1beta1/services/index_service/transports/grpc.py index 9178f1d61a..e4d3d77731 100644 --- a/google/cloud/aiplatform_v1beta1/services/index_service/transports/grpc.py +++ b/google/cloud/aiplatform_v1beta1/services/index_service/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,9 +16,9 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import operations_v1 +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -27,6 +27,10 @@ from google.cloud.aiplatform_v1beta1.types import index from google.cloud.aiplatform_v1beta1.types import index_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from .base import IndexServiceTransport, DEFAULT_CLIENT_INFO @@ -34,7 +38,7 @@ class IndexServiceGrpcTransport(IndexServiceTransport): """gRPC backend transport for IndexService. - A service for creating and managing AI Platform's Index + A service for creating and managing Vertex AI's Index resources. This class defines the same methods as the primary client, so the @@ -61,6 +65,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -83,16 +88,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -101,6 +106,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport @@ -111,7 +118,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -154,13 +161,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -209,21 +220,20 @@ def create_channel( and ``credentials_file`` are passed. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @property def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ + """Return the channel designed to connect to this service.""" return self._grpc_channel @property @@ -233,7 +243,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsClient(self.grpc_channel) @@ -372,5 +382,215 @@ def delete_index( ) return self._stubs["delete_index"] + def close(self): + self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + @property + def kind(self) -> str: + return "grpc" + __all__ = ("IndexServiceGrpcTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/index_service/transports/grpc_asyncio.py b/google/cloud/aiplatform_v1beta1/services/index_service/transports/grpc_asyncio.py index c17e033b7c..df0675d43d 100644 --- a/google/cloud/aiplatform_v1beta1/services/index_service/transports/grpc_asyncio.py +++ b/google/cloud/aiplatform_v1beta1/services/index_service/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,18 +16,21 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore -from google.api_core import operations_v1 # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore from google.cloud.aiplatform_v1beta1.types import index from google.cloud.aiplatform_v1beta1.types import index_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from .base import IndexServiceTransport, DEFAULT_CLIENT_INFO from .grpc import IndexServiceGrpcTransport @@ -36,7 +39,7 @@ class IndexServiceGrpcAsyncIOTransport(IndexServiceTransport): """gRPC AsyncIO backend transport for IndexService. - A service for creating and managing AI Platform's Index + A service for creating and managing Vertex AI's Index resources. This class defines the same methods as the primary client, so the @@ -82,14 +85,14 @@ def create_channel( aio.Channel: A gRPC AsyncIO channel object. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @@ -107,6 +110,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -130,16 +134,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -148,6 +152,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport @@ -158,7 +164,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -200,13 +206,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -236,7 +246,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel @@ -385,5 +395,211 @@ def delete_index( ) return self._stubs["delete_index"] + def close(self): + return self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + __all__ = ("IndexServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/job_service/__init__.py b/google/cloud/aiplatform_v1beta1/services/job_service/__init__.py index 3d8d94dbd8..3d88580841 100644 --- a/google/cloud/aiplatform_v1beta1/services/job_service/__init__.py +++ b/google/cloud/aiplatform_v1beta1/services/job_service/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1beta1/services/job_service/async_client.py b/google/cloud/aiplatform_v1beta1/services/job_service/async_client.py index 0396f4db64..49d8400fd1 100644 --- a/google/cloud/aiplatform_v1beta1/services/job_service/async_client.py +++ b/google/cloud/aiplatform_v1beta1/services/job_service/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,16 +16,21 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation as gac_operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1beta1.services.job_service import pagers @@ -58,6 +63,11 @@ from google.cloud.aiplatform_v1beta1.types import model_monitoring from google.cloud.aiplatform_v1beta1.types import operation as gca_operation from google.cloud.aiplatform_v1beta1.types import study +from google.cloud.aiplatform_v1beta1.types import unmanaged_container_model +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import duration_pb2 # type: ignore from google.protobuf import empty_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore @@ -71,7 +81,7 @@ class JobServiceAsyncClient: - """A service for creating and managing AI Platform's jobs.""" + """A service for creating and managing Vertex AI's jobs.""" _client: JobServiceClient @@ -133,7 +143,8 @@ class JobServiceAsyncClient: @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -148,7 +159,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -163,9 +174,45 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return JobServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> JobServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: JobServiceTransport: The transport used by the client instance. @@ -184,7 +231,7 @@ def __init__( client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the job service client. + """Instantiates the job service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -225,19 +272,43 @@ def __init__( async def create_custom_job( self, - request: job_service.CreateCustomJobRequest = None, + request: Union[job_service.CreateCustomJobRequest, dict] = None, *, parent: str = None, custom_job: gca_custom_job.CustomJob = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_custom_job.CustomJob: r"""Creates a CustomJob. A created CustomJob right away will be attempted to be run. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_create_custom_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + custom_job = aiplatform_v1beta1.CustomJob() + custom_job.display_name = "display_name_value" + custom_job.job_spec.worker_pool_specs.container_spec.image_uri = "image_uri_value" + + request = aiplatform_v1beta1.CreateCustomJobRequest( + parent="parent_value", + custom_job=custom_job, + ) + + # Make the request + response = await client.create_custom_job(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.CreateCustomJobRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateCustomJobRequest, dict]): The request object. Request message for [JobService.CreateCustomJob][google.cloud.aiplatform.v1beta1.JobService.CreateCustomJob]. parent (:class:`str`): @@ -272,7 +343,7 @@ async def create_custom_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, custom_job]) if request is not None and has_flattened_params: @@ -305,24 +376,48 @@ async def create_custom_job( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def get_custom_job( self, - request: job_service.GetCustomJobRequest = None, + request: Union[job_service.GetCustomJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> custom_job.CustomJob: r"""Gets a CustomJob. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_get_custom_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetCustomJobRequest( + name="name_value", + ) + + # Make the request + response = await client.get_custom_job(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.GetCustomJobRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.GetCustomJobRequest, dict]): The request object. Request message for [JobService.GetCustomJob][google.cloud.aiplatform.v1beta1.JobService.GetCustomJob]. name (:class:`str`): @@ -351,7 +446,7 @@ async def get_custom_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -382,24 +477,49 @@ async def get_custom_job( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_custom_jobs( self, - request: job_service.ListCustomJobsRequest = None, + request: Union[job_service.ListCustomJobsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListCustomJobsAsyncPager: r"""Lists CustomJobs in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_list_custom_jobs(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListCustomJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_custom_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ListCustomJobsRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ListCustomJobsRequest, dict]): The request object. Request message for [JobService.ListCustomJobs][google.cloud.aiplatform.v1beta1.JobService.ListCustomJobs]. parent (:class:`str`): @@ -426,7 +546,7 @@ async def list_custom_jobs( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -457,12 +577,20 @@ async def list_custom_jobs( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListCustomJobsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -470,17 +598,40 @@ async def list_custom_jobs( async def delete_custom_job( self, - request: job_service.DeleteCustomJobRequest = None, + request: Union[job_service.DeleteCustomJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a CustomJob. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_delete_custom_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteCustomJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_custom_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.DeleteCustomJobRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteCustomJobRequest, dict]): The request object. Request message for [JobService.DeleteCustomJob][google.cloud.aiplatform.v1beta1.JobService.DeleteCustomJob]. name (:class:`str`): @@ -517,7 +668,7 @@ async def delete_custom_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -548,7 +699,12 @@ async def delete_custom_job( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -563,10 +719,10 @@ async def delete_custom_job( async def cancel_custom_job( self, - request: job_service.CancelCustomJobRequest = None, + request: Union[job_service.CancelCustomJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -584,8 +740,24 @@ async def cancel_custom_job( [CustomJob.state][google.cloud.aiplatform.v1beta1.CustomJob.state] is set to ``CANCELLED``. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_cancel_custom_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CancelCustomJobRequest( + name="name_value", + ) + + # Make the request + await client.cancel_custom_job(request=request) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.CancelCustomJobRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.CancelCustomJobRequest, dict]): The request object. Request message for [JobService.CancelCustomJob][google.cloud.aiplatform.v1beta1.JobService.CancelCustomJob]. name (:class:`str`): @@ -602,7 +774,7 @@ async def cancel_custom_job( 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 + # Quick 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: @@ -634,23 +806,54 @@ async def cancel_custom_job( # Send the request. await rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) async def create_data_labeling_job( self, - request: job_service.CreateDataLabelingJobRequest = None, + request: Union[job_service.CreateDataLabelingJobRequest, dict] = None, *, parent: str = None, data_labeling_job: gca_data_labeling_job.DataLabelingJob = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_data_labeling_job.DataLabelingJob: r"""Creates a DataLabelingJob. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_create_data_labeling_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + data_labeling_job = aiplatform_v1beta1.DataLabelingJob() + data_labeling_job.display_name = "display_name_value" + data_labeling_job.datasets = ['datasets_value_1', 'datasets_value_2'] + data_labeling_job.labeler_count = 1375 + data_labeling_job.instruction_uri = "instruction_uri_value" + data_labeling_job.inputs_schema_uri = "inputs_schema_uri_value" + data_labeling_job.inputs.null_value = "NULL_VALUE" + + request = aiplatform_v1beta1.CreateDataLabelingJobRequest( + parent="parent_value", + data_labeling_job=data_labeling_job, + ) + + # Make the request + response = await client.create_data_labeling_job(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.CreateDataLabelingJobRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateDataLabelingJobRequest, dict]): The request object. Request message for [JobService.CreateDataLabelingJob][google.cloud.aiplatform.v1beta1.JobService.CreateDataLabelingJob]. parent (:class:`str`): @@ -681,7 +884,7 @@ async def create_data_labeling_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, data_labeling_job]) if request is not None and has_flattened_params: @@ -714,24 +917,48 @@ async def create_data_labeling_job( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def get_data_labeling_job( self, - request: job_service.GetDataLabelingJobRequest = None, + request: Union[job_service.GetDataLabelingJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> data_labeling_job.DataLabelingJob: r"""Gets a DataLabelingJob. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_get_data_labeling_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetDataLabelingJobRequest( + name="name_value", + ) + + # Make the request + response = await client.get_data_labeling_job(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.GetDataLabelingJobRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.GetDataLabelingJobRequest, dict]): The request object. Request message for [JobService.GetDataLabelingJob][google.cloud.aiplatform.v1beta1.JobService.GetDataLabelingJob]. name (:class:`str`): @@ -755,7 +982,7 @@ async def get_data_labeling_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -786,24 +1013,49 @@ async def get_data_labeling_job( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_data_labeling_jobs( self, - request: job_service.ListDataLabelingJobsRequest = None, + request: Union[job_service.ListDataLabelingJobsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListDataLabelingJobsAsyncPager: r"""Lists DataLabelingJobs in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_list_data_labeling_jobs(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListDataLabelingJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_data_labeling_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ListDataLabelingJobsRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ListDataLabelingJobsRequest, dict]): The request object. Request message for [JobService.ListDataLabelingJobs][google.cloud.aiplatform.v1beta1.JobService.ListDataLabelingJobs]. parent (:class:`str`): @@ -829,7 +1081,7 @@ async def list_data_labeling_jobs( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -860,12 +1112,20 @@ async def list_data_labeling_jobs( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListDataLabelingJobsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -873,17 +1133,40 @@ async def list_data_labeling_jobs( async def delete_data_labeling_job( self, - request: job_service.DeleteDataLabelingJobRequest = None, + request: Union[job_service.DeleteDataLabelingJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a DataLabelingJob. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_delete_data_labeling_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteDataLabelingJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_data_labeling_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.DeleteDataLabelingJobRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteDataLabelingJobRequest, dict]): The request object. Request message for [JobService.DeleteDataLabelingJob][google.cloud.aiplatform.v1beta1.JobService.DeleteDataLabelingJob]. name (:class:`str`): @@ -920,7 +1203,7 @@ async def delete_data_labeling_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -951,7 +1234,12 @@ async def delete_data_labeling_job( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -966,18 +1254,34 @@ async def delete_data_labeling_job( async def cancel_data_labeling_job( self, - request: job_service.CancelDataLabelingJobRequest = None, + request: Union[job_service.CancelDataLabelingJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Cancels a DataLabelingJob. Success of cancellation is not guaranteed. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_cancel_data_labeling_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CancelDataLabelingJobRequest( + name="name_value", + ) + + # Make the request + await client.cancel_data_labeling_job(request=request) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.CancelDataLabelingJobRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.CancelDataLabelingJobRequest, dict]): The request object. Request message for [JobService.CancelDataLabelingJob][google.cloud.aiplatform.v1beta1.JobService.CancelDataLabelingJob]. name (:class:`str`): @@ -994,7 +1298,7 @@ async def cancel_data_labeling_job( 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 + # Quick 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: @@ -1026,23 +1330,57 @@ async def cancel_data_labeling_job( # Send the request. await rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) async def create_hyperparameter_tuning_job( self, - request: job_service.CreateHyperparameterTuningJobRequest = None, + request: Union[job_service.CreateHyperparameterTuningJobRequest, dict] = None, *, parent: str = None, hyperparameter_tuning_job: gca_hyperparameter_tuning_job.HyperparameterTuningJob = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_hyperparameter_tuning_job.HyperparameterTuningJob: r"""Creates a HyperparameterTuningJob + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_create_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + hyperparameter_tuning_job = aiplatform_v1beta1.HyperparameterTuningJob() + hyperparameter_tuning_job.display_name = "display_name_value" + hyperparameter_tuning_job.study_spec.metrics.metric_id = "metric_id_value" + hyperparameter_tuning_job.study_spec.metrics.goal = "MINIMIZE" + hyperparameter_tuning_job.study_spec.parameters.double_value_spec.min_value = 0.96 + hyperparameter_tuning_job.study_spec.parameters.double_value_spec.max_value = 0.962 + hyperparameter_tuning_job.study_spec.parameters.parameter_id = "parameter_id_value" + hyperparameter_tuning_job.max_trial_count = 1609 + hyperparameter_tuning_job.parallel_trial_count = 2128 + hyperparameter_tuning_job.trial_job_spec.worker_pool_specs.container_spec.image_uri = "image_uri_value" + + request = aiplatform_v1beta1.CreateHyperparameterTuningJobRequest( + parent="parent_value", + hyperparameter_tuning_job=hyperparameter_tuning_job, + ) + + # Make the request + response = await client.create_hyperparameter_tuning_job(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.CreateHyperparameterTuningJobRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateHyperparameterTuningJobRequest, dict]): The request object. Request message for [JobService.CreateHyperparameterTuningJob][google.cloud.aiplatform.v1beta1.JobService.CreateHyperparameterTuningJob]. parent (:class:`str`): @@ -1075,7 +1413,7 @@ async def create_hyperparameter_tuning_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, hyperparameter_tuning_job]) if request is not None and has_flattened_params: @@ -1108,24 +1446,48 @@ async def create_hyperparameter_tuning_job( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def get_hyperparameter_tuning_job( self, - request: job_service.GetHyperparameterTuningJobRequest = None, + request: Union[job_service.GetHyperparameterTuningJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> hyperparameter_tuning_job.HyperparameterTuningJob: r"""Gets a HyperparameterTuningJob + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_get_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetHyperparameterTuningJobRequest( + name="name_value", + ) + + # Make the request + response = await client.get_hyperparameter_tuning_job(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.GetHyperparameterTuningJobRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.GetHyperparameterTuningJobRequest, dict]): The request object. Request message for [JobService.GetHyperparameterTuningJob][google.cloud.aiplatform.v1beta1.JobService.GetHyperparameterTuningJob]. name (:class:`str`): @@ -1151,7 +1513,7 @@ async def get_hyperparameter_tuning_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1182,24 +1544,49 @@ async def get_hyperparameter_tuning_job( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_hyperparameter_tuning_jobs( self, - request: job_service.ListHyperparameterTuningJobsRequest = None, + request: Union[job_service.ListHyperparameterTuningJobsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListHyperparameterTuningJobsAsyncPager: r"""Lists HyperparameterTuningJobs in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_list_hyperparameter_tuning_jobs(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListHyperparameterTuningJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_hyperparameter_tuning_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ListHyperparameterTuningJobsRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ListHyperparameterTuningJobsRequest, dict]): The request object. Request message for [JobService.ListHyperparameterTuningJobs][google.cloud.aiplatform.v1beta1.JobService.ListHyperparameterTuningJobs]. parent (:class:`str`): @@ -1226,7 +1613,7 @@ async def list_hyperparameter_tuning_jobs( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1257,12 +1644,20 @@ async def list_hyperparameter_tuning_jobs( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListHyperparameterTuningJobsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -1270,17 +1665,40 @@ async def list_hyperparameter_tuning_jobs( async def delete_hyperparameter_tuning_job( self, - request: job_service.DeleteHyperparameterTuningJobRequest = None, + request: Union[job_service.DeleteHyperparameterTuningJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a HyperparameterTuningJob. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_delete_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteHyperparameterTuningJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_hyperparameter_tuning_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.DeleteHyperparameterTuningJobRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteHyperparameterTuningJobRequest, dict]): The request object. Request message for [JobService.DeleteHyperparameterTuningJob][google.cloud.aiplatform.v1beta1.JobService.DeleteHyperparameterTuningJob]. name (:class:`str`): @@ -1317,7 +1735,7 @@ async def delete_hyperparameter_tuning_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1348,7 +1766,12 @@ async def delete_hyperparameter_tuning_job( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -1363,10 +1786,10 @@ async def delete_hyperparameter_tuning_job( async def cancel_hyperparameter_tuning_job( self, - request: job_service.CancelHyperparameterTuningJobRequest = None, + request: Union[job_service.CancelHyperparameterTuningJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -1385,8 +1808,24 @@ async def cancel_hyperparameter_tuning_job( [HyperparameterTuningJob.state][google.cloud.aiplatform.v1beta1.HyperparameterTuningJob.state] is set to ``CANCELLED``. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_cancel_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CancelHyperparameterTuningJobRequest( + name="name_value", + ) + + # Make the request + await client.cancel_hyperparameter_tuning_job(request=request) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.CancelHyperparameterTuningJobRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.CancelHyperparameterTuningJobRequest, dict]): The request object. Request message for [JobService.CancelHyperparameterTuningJob][google.cloud.aiplatform.v1beta1.JobService.CancelHyperparameterTuningJob]. name (:class:`str`): @@ -1404,7 +1843,7 @@ async def cancel_hyperparameter_tuning_job( 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 + # Quick 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: @@ -1436,24 +1875,54 @@ async def cancel_hyperparameter_tuning_job( # Send the request. await rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) async def create_batch_prediction_job( self, - request: job_service.CreateBatchPredictionJobRequest = None, + request: Union[job_service.CreateBatchPredictionJobRequest, dict] = None, *, parent: str = None, batch_prediction_job: gca_batch_prediction_job.BatchPredictionJob = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_batch_prediction_job.BatchPredictionJob: r"""Creates a BatchPredictionJob. A BatchPredictionJob once created will right away be attempted to start. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_create_batch_prediction_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + batch_prediction_job = aiplatform_v1beta1.BatchPredictionJob() + batch_prediction_job.display_name = "display_name_value" + batch_prediction_job.input_config.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + batch_prediction_job.input_config.instances_format = "instances_format_value" + batch_prediction_job.output_config.gcs_destination.output_uri_prefix = "output_uri_prefix_value" + batch_prediction_job.output_config.predictions_format = "predictions_format_value" + + request = aiplatform_v1beta1.CreateBatchPredictionJobRequest( + parent="parent_value", + batch_prediction_job=batch_prediction_job, + ) + + # Make the request + response = await client.create_batch_prediction_job(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.CreateBatchPredictionJobRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateBatchPredictionJobRequest, dict]): The request object. Request message for [JobService.CreateBatchPredictionJob][google.cloud.aiplatform.v1beta1.JobService.CreateBatchPredictionJob]. parent (:class:`str`): @@ -1488,7 +1957,7 @@ async def create_batch_prediction_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, batch_prediction_job]) if request is not None and has_flattened_params: @@ -1521,24 +1990,48 @@ async def create_batch_prediction_job( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def get_batch_prediction_job( self, - request: job_service.GetBatchPredictionJobRequest = None, + request: Union[job_service.GetBatchPredictionJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> batch_prediction_job.BatchPredictionJob: r"""Gets a BatchPredictionJob + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_get_batch_prediction_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetBatchPredictionJobRequest( + name="name_value", + ) + + # Make the request + response = await client.get_batch_prediction_job(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.GetBatchPredictionJobRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.GetBatchPredictionJobRequest, dict]): The request object. Request message for [JobService.GetBatchPredictionJob][google.cloud.aiplatform.v1beta1.JobService.GetBatchPredictionJob]. name (:class:`str`): @@ -1566,7 +2059,7 @@ async def get_batch_prediction_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1597,24 +2090,49 @@ async def get_batch_prediction_job( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_batch_prediction_jobs( self, - request: job_service.ListBatchPredictionJobsRequest = None, + request: Union[job_service.ListBatchPredictionJobsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListBatchPredictionJobsAsyncPager: r"""Lists BatchPredictionJobs in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_list_batch_prediction_jobs(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListBatchPredictionJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_batch_prediction_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ListBatchPredictionJobsRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ListBatchPredictionJobsRequest, dict]): The request object. Request message for [JobService.ListBatchPredictionJobs][google.cloud.aiplatform.v1beta1.JobService.ListBatchPredictionJobs]. parent (:class:`str`): @@ -1641,7 +2159,7 @@ async def list_batch_prediction_jobs( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1672,12 +2190,20 @@ async def list_batch_prediction_jobs( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListBatchPredictionJobsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -1685,18 +2211,41 @@ async def list_batch_prediction_jobs( async def delete_batch_prediction_job( self, - request: job_service.DeleteBatchPredictionJobRequest = None, + request: Union[job_service.DeleteBatchPredictionJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a BatchPredictionJob. Can only be called on jobs that already finished. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_delete_batch_prediction_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteBatchPredictionJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_batch_prediction_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.DeleteBatchPredictionJobRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteBatchPredictionJobRequest, dict]): The request object. Request message for [JobService.DeleteBatchPredictionJob][google.cloud.aiplatform.v1beta1.JobService.DeleteBatchPredictionJob]. name (:class:`str`): @@ -1733,7 +2282,7 @@ async def delete_batch_prediction_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1764,7 +2313,12 @@ async def delete_batch_prediction_job( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -1779,10 +2333,10 @@ async def delete_batch_prediction_job( async def cancel_batch_prediction_job( self, - request: job_service.CancelBatchPredictionJobRequest = None, + request: Union[job_service.CancelBatchPredictionJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -1799,8 +2353,24 @@ async def cancel_batch_prediction_job( is set to ``CANCELLED``. Any files already outputted by the job are not deleted. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_cancel_batch_prediction_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CancelBatchPredictionJobRequest( + name="name_value", + ) + + # Make the request + await client.cancel_batch_prediction_job(request=request) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.CancelBatchPredictionJobRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.CancelBatchPredictionJobRequest, dict]): The request object. Request message for [JobService.CancelBatchPredictionJob][google.cloud.aiplatform.v1beta1.JobService.CancelBatchPredictionJob]. name (:class:`str`): @@ -1818,7 +2388,7 @@ async def cancel_batch_prediction_job( 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 + # Quick 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: @@ -1850,24 +2420,53 @@ async def cancel_batch_prediction_job( # Send the request. await rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) async def create_model_deployment_monitoring_job( self, - request: job_service.CreateModelDeploymentMonitoringJobRequest = None, + request: Union[ + job_service.CreateModelDeploymentMonitoringJobRequest, dict + ] = None, *, parent: str = None, model_deployment_monitoring_job: gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob: r"""Creates a ModelDeploymentMonitoringJob. It will run periodically on a configured interval. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_create_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + model_deployment_monitoring_job = aiplatform_v1beta1.ModelDeploymentMonitoringJob() + model_deployment_monitoring_job.display_name = "display_name_value" + model_deployment_monitoring_job.endpoint = "endpoint_value" + + request = aiplatform_v1beta1.CreateModelDeploymentMonitoringJobRequest( + parent="parent_value", + model_deployment_monitoring_job=model_deployment_monitoring_job, + ) + + # Make the request + response = await client.create_model_deployment_monitoring_job(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.CreateModelDeploymentMonitoringJobRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateModelDeploymentMonitoringJobRequest, dict]): The request object. Request message for [JobService.CreateModelDeploymentMonitoringJob][google.cloud.aiplatform.v1beta1.JobService.CreateModelDeploymentMonitoringJob]. parent (:class:`str`): @@ -1901,7 +2500,7 @@ async def create_model_deployment_monitoring_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, model_deployment_monitoring_job]) if request is not None and has_flattened_params: @@ -1934,39 +2533,67 @@ async def create_model_deployment_monitoring_job( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def search_model_deployment_monitoring_stats_anomalies( self, - request: job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest = None, + request: Union[ + job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest, dict + ] = None, *, model_deployment_monitoring_job: str = None, deployed_model_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.SearchModelDeploymentMonitoringStatsAnomaliesAsyncPager: r"""Searches Model Monitoring Statistics generated within a given time window. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_search_model_deployment_monitoring_stats_anomalies(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.SearchModelDeploymentMonitoringStatsAnomaliesRequest( + model_deployment_monitoring_job="model_deployment_monitoring_job_value", + deployed_model_id="deployed_model_id_value", + ) + + # Make the request + page_result = client.search_model_deployment_monitoring_stats_anomalies(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.SearchModelDeploymentMonitoringStatsAnomaliesRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.SearchModelDeploymentMonitoringStatsAnomaliesRequest, dict]): The request object. Request message for [JobService.SearchModelDeploymentMonitoringStatsAnomalies][google.cloud.aiplatform.v1beta1.JobService.SearchModelDeploymentMonitoringStatsAnomalies]. model_deployment_monitoring_job (:class:`str`): Required. ModelDeploymentMonitoring Job resource name. Format: - \`projects/{project}/locations/{location}/modelDeploymentMonitoringJobs/{model_deployment_monitoring_job} + ``projects/{project}/locations/{location}/modelDeploymentMonitoringJobs/{model_deployment_monitoring_job}`` This corresponds to the ``model_deployment_monitoring_job`` field on the ``request`` instance; if ``request`` is provided, this should not be set. deployed_model_id (:class:`str`): Required. The DeployedModel ID of the - [google.cloud.aiplatform.master.ModelDeploymentMonitoringObjectiveConfig.deployed_model_id]. + [ModelDeploymentMonitoringObjectiveConfig.deployed_model_id]. This corresponds to the ``deployed_model_id`` field on the ``request`` instance; if ``request`` is provided, this @@ -1987,7 +2614,7 @@ async def search_model_deployment_monitoring_stats_anomalies( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([model_deployment_monitoring_job, deployed_model_id]) if request is not None and has_flattened_params: @@ -2029,12 +2656,20 @@ async def search_model_deployment_monitoring_stats_anomalies( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.SearchModelDeploymentMonitoringStatsAnomaliesAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -2042,17 +2677,36 @@ async def search_model_deployment_monitoring_stats_anomalies( async def get_model_deployment_monitoring_job( self, - request: job_service.GetModelDeploymentMonitoringJobRequest = None, + request: Union[job_service.GetModelDeploymentMonitoringJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> model_deployment_monitoring_job.ModelDeploymentMonitoringJob: r"""Gets a ModelDeploymentMonitoringJob. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_get_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + response = await client.get_model_deployment_monitoring_job(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.GetModelDeploymentMonitoringJobRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.GetModelDeploymentMonitoringJobRequest, dict]): The request object. Request message for [JobService.GetModelDeploymentMonitoringJob][google.cloud.aiplatform.v1beta1.JobService.GetModelDeploymentMonitoringJob]. name (:class:`str`): @@ -2079,7 +2733,7 @@ async def get_model_deployment_monitoring_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -2110,24 +2764,51 @@ async def get_model_deployment_monitoring_job( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_model_deployment_monitoring_jobs( self, - request: job_service.ListModelDeploymentMonitoringJobsRequest = None, + request: Union[ + job_service.ListModelDeploymentMonitoringJobsRequest, dict + ] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListModelDeploymentMonitoringJobsAsyncPager: r"""Lists ModelDeploymentMonitoringJobs in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_list_model_deployment_monitoring_jobs(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListModelDeploymentMonitoringJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_model_deployment_monitoring_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ListModelDeploymentMonitoringJobsRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ListModelDeploymentMonitoringJobsRequest, dict]): The request object. Request message for [JobService.ListModelDeploymentMonitoringJobs][google.cloud.aiplatform.v1beta1.JobService.ListModelDeploymentMonitoringJobs]. parent (:class:`str`): @@ -2154,7 +2835,7 @@ async def list_model_deployment_monitoring_jobs( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -2185,12 +2866,20 @@ async def list_model_deployment_monitoring_jobs( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListModelDeploymentMonitoringJobsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -2198,18 +2887,47 @@ async def list_model_deployment_monitoring_jobs( async def update_model_deployment_monitoring_job( self, - request: job_service.UpdateModelDeploymentMonitoringJobRequest = None, + request: Union[ + job_service.UpdateModelDeploymentMonitoringJobRequest, dict + ] = None, *, model_deployment_monitoring_job: gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Updates a ModelDeploymentMonitoringJob. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_update_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + model_deployment_monitoring_job = aiplatform_v1beta1.ModelDeploymentMonitoringJob() + model_deployment_monitoring_job.display_name = "display_name_value" + model_deployment_monitoring_job.endpoint = "endpoint_value" + + request = aiplatform_v1beta1.UpdateModelDeploymentMonitoringJobRequest( + model_deployment_monitoring_job=model_deployment_monitoring_job, + ) + + # Make the request + operation = client.update_model_deployment_monitoring_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.UpdateModelDeploymentMonitoringJobRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.UpdateModelDeploymentMonitoringJobRequest, dict]): The request object. Request message for [JobService.UpdateModelDeploymentMonitoringJob][google.cloud.aiplatform.v1beta1.JobService.UpdateModelDeploymentMonitoringJob]. model_deployment_monitoring_job (:class:`google.cloud.aiplatform_v1beta1.types.ModelDeploymentMonitoringJob`): @@ -2221,8 +2939,34 @@ async def update_model_deployment_monitoring_job( on the ``request`` instance; if ``request`` is provided, this should not be set. update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): - Required. The update mask applies to - the resource. + Required. The update mask is used to specify the fields + to be overwritten in the ModelDeploymentMonitoringJob + resource by the update. The fields specified in the + update_mask are relative to the resource, not the full + request. A field will be overwritten if it is in the + mask. If the user does not provide a mask then only the + non-empty fields present in the request will be + overwritten. Set the update_mask to ``*`` to override + all fields. For the objective config, the user can + either provide the update mask for + model_deployment_monitoring_objective_configs or any + combination of its nested fields, such as: + model_deployment_monitoring_objective_configs.objective_config.training_dataset. + + Updatable fields: + + - ``display_name`` + - ``model_deployment_monitoring_schedule_config`` + - ``model_monitoring_alert_config`` + - ``logging_sampling_strategy`` + - ``labels`` + - ``log_ttl`` + - ``enable_monitoring_pipeline_logs`` . and + - ``model_deployment_monitoring_objective_configs`` . + or + - ``model_deployment_monitoring_objective_configs.objective_config.training_dataset`` + - ``model_deployment_monitoring_objective_configs.objective_config.training_prediction_skew_detection_config`` + - ``model_deployment_monitoring_objective_configs.objective_config.prediction_drift_detection_config`` This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this @@ -2243,7 +2987,7 @@ async def update_model_deployment_monitoring_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([model_deployment_monitoring_job, update_mask]) if request is not None and has_flattened_params: @@ -2283,7 +3027,12 @@ async def update_model_deployment_monitoring_job( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -2298,17 +3047,42 @@ async def update_model_deployment_monitoring_job( async def delete_model_deployment_monitoring_job( self, - request: job_service.DeleteModelDeploymentMonitoringJobRequest = None, + request: Union[ + job_service.DeleteModelDeploymentMonitoringJobRequest, dict + ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a ModelDeploymentMonitoringJob. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_delete_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_model_deployment_monitoring_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.DeleteModelDeploymentMonitoringJobRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteModelDeploymentMonitoringJobRequest, dict]): The request object. Request message for [JobService.DeleteModelDeploymentMonitoringJob][google.cloud.aiplatform.v1beta1.JobService.DeleteModelDeploymentMonitoringJob]. name (:class:`str`): @@ -2345,7 +3119,7 @@ async def delete_model_deployment_monitoring_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -2376,7 +3150,12 @@ async def delete_model_deployment_monitoring_job( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -2391,10 +3170,12 @@ async def delete_model_deployment_monitoring_job( async def pause_model_deployment_monitoring_job( self, - request: job_service.PauseModelDeploymentMonitoringJobRequest = None, + request: Union[ + job_service.PauseModelDeploymentMonitoringJobRequest, dict + ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -2403,8 +3184,24 @@ async def pause_model_deployment_monitoring_job( [ModelDeploymentMonitoringJob.state][google.cloud.aiplatform.v1beta1.ModelDeploymentMonitoringJob.state] to 'PAUSED'. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_pause_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.PauseModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + await client.pause_model_deployment_monitoring_job(request=request) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.PauseModelDeploymentMonitoringJobRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.PauseModelDeploymentMonitoringJobRequest, dict]): The request object. Request message for [JobService.PauseModelDeploymentMonitoringJob][google.cloud.aiplatform.v1beta1.JobService.PauseModelDeploymentMonitoringJob]. name (:class:`str`): @@ -2422,7 +3219,7 @@ async def pause_model_deployment_monitoring_job( 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 + # Quick 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: @@ -2454,15 +3251,20 @@ async def pause_model_deployment_monitoring_job( # Send the request. await rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) async def resume_model_deployment_monitoring_job( self, - request: job_service.ResumeModelDeploymentMonitoringJobRequest = None, + request: Union[ + job_service.ResumeModelDeploymentMonitoringJobRequest, dict + ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -2470,8 +3272,24 @@ async def resume_model_deployment_monitoring_job( will start to run from next scheduled time. A deleted ModelDeploymentMonitoringJob can't be resumed. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_resume_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ResumeModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + await client.resume_model_deployment_monitoring_job(request=request) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ResumeModelDeploymentMonitoringJobRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ResumeModelDeploymentMonitoringJobRequest, dict]): The request object. Request message for [JobService.ResumeModelDeploymentMonitoringJob][google.cloud.aiplatform.v1beta1.JobService.ResumeModelDeploymentMonitoringJob]. name (:class:`str`): @@ -2489,7 +3307,7 @@ async def resume_model_deployment_monitoring_job( 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 + # Quick 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: @@ -2521,9 +3339,689 @@ async def resume_model_deployment_monitoring_job( # Send the request. await rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) + async def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_operations, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.delete_operation, + default_timeout=None, + 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 cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + 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 wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.wait_operation, + default_timeout=None, + 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 set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_location, + default_timeout=None, + 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 list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_locations, + default_timeout=None, + 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 __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/aiplatform_v1beta1/services/job_service/client.py b/google/cloud/aiplatform_v1beta1/services/job_service/client.py index c802dfd25a..b18c0b6eb0 100644 --- a/google/cloud/aiplatform_v1beta1/services/job_service/client.py +++ b/google/cloud/aiplatform_v1beta1/services/job_service/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,22 +14,26 @@ # 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 +from typing import Dict, Mapping, 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 as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_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 +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation as gac_operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1beta1.services.job_service import pagers @@ -62,6 +66,11 @@ from google.cloud.aiplatform_v1beta1.types import model_monitoring from google.cloud.aiplatform_v1beta1.types import operation as gca_operation from google.cloud.aiplatform_v1beta1.types import study +from google.cloud.aiplatform_v1beta1.types import unmanaged_container_model +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import duration_pb2 # type: ignore from google.protobuf import empty_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore @@ -86,8 +95,11 @@ class JobServiceClientMeta(type): _transport_registry["grpc"] = JobServiceGrpcTransport _transport_registry["grpc_asyncio"] = JobServiceGrpcAsyncIOTransport - def get_transport_class(cls, label: str = None,) -> Type[JobServiceTransport]: - """Return an appropriate transport class. + def get_transport_class( + cls, + label: str = None, + ) -> Type[JobServiceTransport]: + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -106,11 +118,12 @@ def get_transport_class(cls, label: str = None,) -> Type[JobServiceTransport]: class JobServiceClient(metaclass=JobServiceClientMeta): - """A service for creating and managing AI Platform's jobs.""" + """A service for creating and managing Vertex AI's jobs.""" @staticmethod def _get_default_mtls_endpoint(api_endpoint): - """Convert api endpoint to mTLS endpoint. + """Converts api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. Args: @@ -144,7 +157,8 @@ def _get_default_mtls_endpoint(api_endpoint): @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -161,7 +175,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -180,18 +194,21 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> JobServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - JobServiceTransport: The transport used by the client instance. + JobServiceTransport: The transport used by the client + instance. """ return self._transport @staticmethod def batch_prediction_job_path( - project: str, location: str, batch_prediction_job: str, + project: str, + location: str, + batch_prediction_job: str, ) -> str: - """Return a fully-qualified batch_prediction_job string.""" + """Returns a fully-qualified batch_prediction_job string.""" return "projects/{project}/locations/{location}/batchPredictionJobs/{batch_prediction_job}".format( project=project, location=location, @@ -200,7 +217,7 @@ def batch_prediction_job_path( @staticmethod def parse_batch_prediction_job_path(path: str) -> Dict[str, str]: - """Parse a batch_prediction_job path into its component segments.""" + """Parses a batch_prediction_job path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/batchPredictionJobs/(?P.+?)$", path, @@ -208,15 +225,21 @@ def parse_batch_prediction_job_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def custom_job_path(project: str, location: str, custom_job: str,) -> str: - """Return a fully-qualified custom_job string.""" + def custom_job_path( + project: str, + location: str, + custom_job: str, + ) -> str: + """Returns a fully-qualified custom_job string.""" return "projects/{project}/locations/{location}/customJobs/{custom_job}".format( - project=project, location=location, custom_job=custom_job, + project=project, + location=location, + custom_job=custom_job, ) @staticmethod def parse_custom_job_path(path: str) -> Dict[str, str]: - """Parse a custom_job path into its component segments.""" + """Parses a custom_job path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/customJobs/(?P.+?)$", path, @@ -225,16 +248,20 @@ def parse_custom_job_path(path: str) -> Dict[str, str]: @staticmethod def data_labeling_job_path( - project: str, location: str, data_labeling_job: str, + project: str, + location: str, + data_labeling_job: str, ) -> str: - """Return a fully-qualified data_labeling_job string.""" + """Returns a fully-qualified data_labeling_job string.""" return "projects/{project}/locations/{location}/dataLabelingJobs/{data_labeling_job}".format( - project=project, location=location, data_labeling_job=data_labeling_job, + project=project, + location=location, + data_labeling_job=data_labeling_job, ) @staticmethod def parse_data_labeling_job_path(path: str) -> Dict[str, str]: - """Parse a data_labeling_job path into its component segments.""" + """Parses a data_labeling_job path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/dataLabelingJobs/(?P.+?)$", path, @@ -242,15 +269,21 @@ def parse_data_labeling_job_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def dataset_path(project: str, location: str, dataset: str,) -> str: - """Return a fully-qualified dataset string.""" + def dataset_path( + project: str, + location: str, + dataset: str, + ) -> str: + """Returns a fully-qualified dataset string.""" return "projects/{project}/locations/{location}/datasets/{dataset}".format( - project=project, location=location, dataset=dataset, + project=project, + location=location, + dataset=dataset, ) @staticmethod def parse_dataset_path(path: str) -> Dict[str, str]: - """Parse a dataset path into its component segments.""" + """Parses a dataset path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/datasets/(?P.+?)$", path, @@ -258,15 +291,21 @@ def parse_dataset_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def endpoint_path(project: str, location: str, endpoint: str,) -> str: - """Return a fully-qualified endpoint string.""" + def endpoint_path( + project: str, + location: str, + endpoint: str, + ) -> str: + """Returns a fully-qualified endpoint string.""" return "projects/{project}/locations/{location}/endpoints/{endpoint}".format( - project=project, location=location, endpoint=endpoint, + project=project, + location=location, + endpoint=endpoint, ) @staticmethod def parse_endpoint_path(path: str) -> Dict[str, str]: - """Parse a endpoint path into its component segments.""" + """Parses a endpoint path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/endpoints/(?P.+?)$", path, @@ -275,9 +314,11 @@ def parse_endpoint_path(path: str) -> Dict[str, str]: @staticmethod def hyperparameter_tuning_job_path( - project: str, location: str, hyperparameter_tuning_job: str, + project: str, + location: str, + hyperparameter_tuning_job: str, ) -> str: - """Return a fully-qualified hyperparameter_tuning_job string.""" + """Returns a fully-qualified hyperparameter_tuning_job string.""" return "projects/{project}/locations/{location}/hyperparameterTuningJobs/{hyperparameter_tuning_job}".format( project=project, location=location, @@ -286,7 +327,7 @@ def hyperparameter_tuning_job_path( @staticmethod def parse_hyperparameter_tuning_job_path(path: str) -> Dict[str, str]: - """Parse a hyperparameter_tuning_job path into its component segments.""" + """Parses a hyperparameter_tuning_job path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/hyperparameterTuningJobs/(?P.+?)$", path, @@ -294,15 +335,21 @@ def parse_hyperparameter_tuning_job_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def model_path(project: str, location: str, model: str,) -> str: - """Return a fully-qualified model string.""" + def model_path( + project: str, + location: str, + model: str, + ) -> str: + """Returns a fully-qualified model string.""" return "projects/{project}/locations/{location}/models/{model}".format( - project=project, location=location, model=model, + project=project, + location=location, + model=model, ) @staticmethod def parse_model_path(path: str) -> Dict[str, str]: - """Parse a model path into its component segments.""" + """Parses a model path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/models/(?P.+?)$", path, @@ -311,9 +358,11 @@ def parse_model_path(path: str) -> Dict[str, str]: @staticmethod def model_deployment_monitoring_job_path( - project: str, location: str, model_deployment_monitoring_job: str, + project: str, + location: str, + model_deployment_monitoring_job: str, ) -> str: - """Return a fully-qualified model_deployment_monitoring_job string.""" + """Returns a fully-qualified model_deployment_monitoring_job string.""" return "projects/{project}/locations/{location}/modelDeploymentMonitoringJobs/{model_deployment_monitoring_job}".format( project=project, location=location, @@ -322,7 +371,7 @@ def model_deployment_monitoring_job_path( @staticmethod def parse_model_deployment_monitoring_job_path(path: str) -> Dict[str, str]: - """Parse a model_deployment_monitoring_job path into its component segments.""" + """Parses a model_deployment_monitoring_job path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/modelDeploymentMonitoringJobs/(?P.+?)$", path, @@ -330,30 +379,42 @@ def parse_model_deployment_monitoring_job_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def network_path(project: str, network: str,) -> str: - """Return a fully-qualified network string.""" + def network_path( + project: str, + network: str, + ) -> str: + """Returns a fully-qualified network string.""" return "projects/{project}/global/networks/{network}".format( - project=project, network=network, + project=project, + network=network, ) @staticmethod def parse_network_path(path: str) -> Dict[str, str]: - """Parse a network path into its component segments.""" + """Parses a network path into its component segments.""" m = re.match( r"^projects/(?P.+?)/global/networks/(?P.+?)$", path ) return m.groupdict() if m else {} @staticmethod - def tensorboard_path(project: str, location: str, tensorboard: str,) -> str: - """Return a fully-qualified tensorboard string.""" - return "projects/{project}/locations/{location}/tensorboards/{tensorboard}".format( - project=project, location=location, tensorboard=tensorboard, + def tensorboard_path( + project: str, + location: str, + tensorboard: str, + ) -> str: + """Returns a fully-qualified tensorboard string.""" + return ( + "projects/{project}/locations/{location}/tensorboards/{tensorboard}".format( + project=project, + location=location, + tensorboard=tensorboard, + ) ) @staticmethod def parse_tensorboard_path(path: str) -> Dict[str, str]: - """Parse a tensorboard path into its component segments.""" + """Parses a tensorboard path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/tensorboards/(?P.+?)$", path, @@ -361,15 +422,23 @@ def parse_tensorboard_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def trial_path(project: str, location: str, study: str, trial: str,) -> str: - """Return a fully-qualified trial string.""" + def trial_path( + project: str, + location: str, + study: str, + trial: str, + ) -> str: + """Returns a fully-qualified trial string.""" return "projects/{project}/locations/{location}/studies/{study}/trials/{trial}".format( - project=project, location=location, study=study, trial=trial, + project=project, + location=location, + study=study, + trial=trial, ) @staticmethod def parse_trial_path(path: str) -> Dict[str, str]: - """Parse a trial path into its component segments.""" + """Parses a trial path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/studies/(?P.+?)/trials/(?P.+?)$", path, @@ -377,8 +446,10 @@ def parse_trial_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + def common_billing_account_path( + billing_account: str, + ) -> str: + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -390,9 +461,13 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: 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,) + def common_folder_path( + folder: str, + ) -> str: + """Returns a fully-qualified folder string.""" + return "folders/{folder}".format( + folder=folder, + ) @staticmethod def parse_common_folder_path(path: str) -> Dict[str, str]: @@ -401,9 +476,13 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: 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,) + def common_organization_path( + organization: str, + ) -> str: + """Returns a fully-qualified organization string.""" + return "organizations/{organization}".format( + organization=organization, + ) @staticmethod def parse_common_organization_path(path: str) -> Dict[str, str]: @@ -412,9 +491,13 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: 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,) + def common_project_path( + project: str, + ) -> str: + """Returns a fully-qualified project string.""" + return "projects/{project}".format( + project=project, + ) @staticmethod def parse_common_project_path(path: str) -> Dict[str, str]: @@ -423,10 +506,14 @@ def parse_common_project_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_location_path(project: str, location: str,) -> str: - """Return a fully-qualified location string.""" + def common_location_path( + project: str, + location: str, + ) -> str: + """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) @staticmethod @@ -435,6 +522,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + def __init__( self, *, @@ -443,7 +597,7 @@ def __init__( client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the job service client. + """Instantiates the job service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -485,58 +639,42 @@ def __init__( 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")) + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - client_cert_source_func = ( - mtls.default_client_cert_source() 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" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # 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, JobServiceTransport): # transport is a JobServiceTransport instance. - if credentials or client_options.credentials_file: + if credentials or client_options.credentials_file or api_key_value: 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." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + Transport = type(self).get_transport_class(transport) self._transport = Transport( credentials=credentials, @@ -546,23 +684,48 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, + always_use_jwt_access=True, ) def create_custom_job( self, - request: job_service.CreateCustomJobRequest = None, + request: Union[job_service.CreateCustomJobRequest, dict] = None, *, parent: str = None, custom_job: gca_custom_job.CustomJob = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_custom_job.CustomJob: r"""Creates a CustomJob. A created CustomJob right away will be attempted to be run. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_create_custom_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + custom_job = aiplatform_v1beta1.CustomJob() + custom_job.display_name = "display_name_value" + custom_job.job_spec.worker_pool_specs.container_spec.image_uri = "image_uri_value" + + request = aiplatform_v1beta1.CreateCustomJobRequest( + parent="parent_value", + custom_job=custom_job, + ) + + # Make the request + response = client.create_custom_job(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.CreateCustomJobRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateCustomJobRequest, dict]): The request object. Request message for [JobService.CreateCustomJob][google.cloud.aiplatform.v1beta1.JobService.CreateCustomJob]. parent (str): @@ -597,7 +760,7 @@ def create_custom_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, custom_job]) if request is not None and has_flattened_params: @@ -630,24 +793,48 @@ def create_custom_job( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def get_custom_job( self, - request: job_service.GetCustomJobRequest = None, + request: Union[job_service.GetCustomJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> custom_job.CustomJob: r"""Gets a CustomJob. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_get_custom_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetCustomJobRequest( + name="name_value", + ) + + # Make the request + response = client.get_custom_job(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.GetCustomJobRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.GetCustomJobRequest, dict]): The request object. Request message for [JobService.GetCustomJob][google.cloud.aiplatform.v1beta1.JobService.GetCustomJob]. name (str): @@ -676,7 +863,7 @@ def get_custom_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -707,24 +894,49 @@ def get_custom_job( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_custom_jobs( self, - request: job_service.ListCustomJobsRequest = None, + request: Union[job_service.ListCustomJobsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListCustomJobsPager: r"""Lists CustomJobs in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_list_custom_jobs(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListCustomJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_custom_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ListCustomJobsRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ListCustomJobsRequest, dict]): The request object. Request message for [JobService.ListCustomJobs][google.cloud.aiplatform.v1beta1.JobService.ListCustomJobs]. parent (str): @@ -751,7 +963,7 @@ def list_custom_jobs( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -782,12 +994,20 @@ def list_custom_jobs( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListCustomJobsPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -795,17 +1015,40 @@ def list_custom_jobs( def delete_custom_job( self, - request: job_service.DeleteCustomJobRequest = None, + request: Union[job_service.DeleteCustomJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Deletes a CustomJob. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_delete_custom_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteCustomJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_custom_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.DeleteCustomJobRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteCustomJobRequest, dict]): The request object. Request message for [JobService.DeleteCustomJob][google.cloud.aiplatform.v1beta1.JobService.DeleteCustomJob]. name (str): @@ -842,7 +1085,7 @@ def delete_custom_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -873,7 +1116,12 @@ def delete_custom_job( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -888,10 +1136,10 @@ def delete_custom_job( def cancel_custom_job( self, - request: job_service.CancelCustomJobRequest = None, + request: Union[job_service.CancelCustomJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -909,8 +1157,24 @@ def cancel_custom_job( [CustomJob.state][google.cloud.aiplatform.v1beta1.CustomJob.state] is set to ``CANCELLED``. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_cancel_custom_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CancelCustomJobRequest( + name="name_value", + ) + + # Make the request + client.cancel_custom_job(request=request) + Args: - request (google.cloud.aiplatform_v1beta1.types.CancelCustomJobRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.CancelCustomJobRequest, dict]): The request object. Request message for [JobService.CancelCustomJob][google.cloud.aiplatform.v1beta1.JobService.CancelCustomJob]. name (str): @@ -927,7 +1191,7 @@ def cancel_custom_job( 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 + # Quick 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: @@ -959,23 +1223,54 @@ def cancel_custom_job( # Send the request. rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) def create_data_labeling_job( self, - request: job_service.CreateDataLabelingJobRequest = None, + request: Union[job_service.CreateDataLabelingJobRequest, dict] = None, *, parent: str = None, data_labeling_job: gca_data_labeling_job.DataLabelingJob = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_data_labeling_job.DataLabelingJob: r"""Creates a DataLabelingJob. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_create_data_labeling_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + data_labeling_job = aiplatform_v1beta1.DataLabelingJob() + data_labeling_job.display_name = "display_name_value" + data_labeling_job.datasets = ['datasets_value_1', 'datasets_value_2'] + data_labeling_job.labeler_count = 1375 + data_labeling_job.instruction_uri = "instruction_uri_value" + data_labeling_job.inputs_schema_uri = "inputs_schema_uri_value" + data_labeling_job.inputs.null_value = "NULL_VALUE" + + request = aiplatform_v1beta1.CreateDataLabelingJobRequest( + parent="parent_value", + data_labeling_job=data_labeling_job, + ) + + # Make the request + response = client.create_data_labeling_job(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.CreateDataLabelingJobRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateDataLabelingJobRequest, dict]): The request object. Request message for [JobService.CreateDataLabelingJob][google.cloud.aiplatform.v1beta1.JobService.CreateDataLabelingJob]. parent (str): @@ -1006,7 +1301,7 @@ def create_data_labeling_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, data_labeling_job]) if request is not None and has_flattened_params: @@ -1039,24 +1334,48 @@ def create_data_labeling_job( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def get_data_labeling_job( self, - request: job_service.GetDataLabelingJobRequest = None, + request: Union[job_service.GetDataLabelingJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> data_labeling_job.DataLabelingJob: r"""Gets a DataLabelingJob. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_get_data_labeling_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetDataLabelingJobRequest( + name="name_value", + ) + + # Make the request + response = client.get_data_labeling_job(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.GetDataLabelingJobRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.GetDataLabelingJobRequest, dict]): The request object. Request message for [JobService.GetDataLabelingJob][google.cloud.aiplatform.v1beta1.JobService.GetDataLabelingJob]. name (str): @@ -1080,7 +1399,7 @@ def get_data_labeling_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1111,24 +1430,49 @@ def get_data_labeling_job( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_data_labeling_jobs( self, - request: job_service.ListDataLabelingJobsRequest = None, + request: Union[job_service.ListDataLabelingJobsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListDataLabelingJobsPager: r"""Lists DataLabelingJobs in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_list_data_labeling_jobs(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListDataLabelingJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_data_labeling_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ListDataLabelingJobsRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ListDataLabelingJobsRequest, dict]): The request object. Request message for [JobService.ListDataLabelingJobs][google.cloud.aiplatform.v1beta1.JobService.ListDataLabelingJobs]. parent (str): @@ -1154,7 +1498,7 @@ def list_data_labeling_jobs( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1185,12 +1529,20 @@ def list_data_labeling_jobs( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListDataLabelingJobsPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -1198,17 +1550,40 @@ def list_data_labeling_jobs( def delete_data_labeling_job( self, - request: job_service.DeleteDataLabelingJobRequest = None, + request: Union[job_service.DeleteDataLabelingJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Deletes a DataLabelingJob. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_delete_data_labeling_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteDataLabelingJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_data_labeling_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.DeleteDataLabelingJobRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteDataLabelingJobRequest, dict]): The request object. Request message for [JobService.DeleteDataLabelingJob][google.cloud.aiplatform.v1beta1.JobService.DeleteDataLabelingJob]. name (str): @@ -1245,7 +1620,7 @@ def delete_data_labeling_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1276,7 +1651,12 @@ def delete_data_labeling_job( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -1291,18 +1671,34 @@ def delete_data_labeling_job( def cancel_data_labeling_job( self, - request: job_service.CancelDataLabelingJobRequest = None, + request: Union[job_service.CancelDataLabelingJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Cancels a DataLabelingJob. Success of cancellation is not guaranteed. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_cancel_data_labeling_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CancelDataLabelingJobRequest( + name="name_value", + ) + + # Make the request + client.cancel_data_labeling_job(request=request) + Args: - request (google.cloud.aiplatform_v1beta1.types.CancelDataLabelingJobRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.CancelDataLabelingJobRequest, dict]): The request object. Request message for [JobService.CancelDataLabelingJob][google.cloud.aiplatform.v1beta1.JobService.CancelDataLabelingJob]. name (str): @@ -1319,7 +1715,7 @@ def cancel_data_labeling_job( 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 + # Quick 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: @@ -1351,23 +1747,57 @@ def cancel_data_labeling_job( # Send the request. rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) def create_hyperparameter_tuning_job( self, - request: job_service.CreateHyperparameterTuningJobRequest = None, + request: Union[job_service.CreateHyperparameterTuningJobRequest, dict] = None, *, parent: str = None, hyperparameter_tuning_job: gca_hyperparameter_tuning_job.HyperparameterTuningJob = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_hyperparameter_tuning_job.HyperparameterTuningJob: r"""Creates a HyperparameterTuningJob + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_create_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + hyperparameter_tuning_job = aiplatform_v1beta1.HyperparameterTuningJob() + hyperparameter_tuning_job.display_name = "display_name_value" + hyperparameter_tuning_job.study_spec.metrics.metric_id = "metric_id_value" + hyperparameter_tuning_job.study_spec.metrics.goal = "MINIMIZE" + hyperparameter_tuning_job.study_spec.parameters.double_value_spec.min_value = 0.96 + hyperparameter_tuning_job.study_spec.parameters.double_value_spec.max_value = 0.962 + hyperparameter_tuning_job.study_spec.parameters.parameter_id = "parameter_id_value" + hyperparameter_tuning_job.max_trial_count = 1609 + hyperparameter_tuning_job.parallel_trial_count = 2128 + hyperparameter_tuning_job.trial_job_spec.worker_pool_specs.container_spec.image_uri = "image_uri_value" + + request = aiplatform_v1beta1.CreateHyperparameterTuningJobRequest( + parent="parent_value", + hyperparameter_tuning_job=hyperparameter_tuning_job, + ) + + # Make the request + response = client.create_hyperparameter_tuning_job(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.CreateHyperparameterTuningJobRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateHyperparameterTuningJobRequest, dict]): The request object. Request message for [JobService.CreateHyperparameterTuningJob][google.cloud.aiplatform.v1beta1.JobService.CreateHyperparameterTuningJob]. parent (str): @@ -1400,7 +1830,7 @@ def create_hyperparameter_tuning_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, hyperparameter_tuning_job]) if request is not None and has_flattened_params: @@ -1435,24 +1865,48 @@ def create_hyperparameter_tuning_job( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def get_hyperparameter_tuning_job( self, - request: job_service.GetHyperparameterTuningJobRequest = None, + request: Union[job_service.GetHyperparameterTuningJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> hyperparameter_tuning_job.HyperparameterTuningJob: r"""Gets a HyperparameterTuningJob + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_get_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetHyperparameterTuningJobRequest( + name="name_value", + ) + + # Make the request + response = client.get_hyperparameter_tuning_job(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.GetHyperparameterTuningJobRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.GetHyperparameterTuningJobRequest, dict]): The request object. Request message for [JobService.GetHyperparameterTuningJob][google.cloud.aiplatform.v1beta1.JobService.GetHyperparameterTuningJob]. name (str): @@ -1478,7 +1932,7 @@ def get_hyperparameter_tuning_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1511,24 +1965,49 @@ def get_hyperparameter_tuning_job( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_hyperparameter_tuning_jobs( self, - request: job_service.ListHyperparameterTuningJobsRequest = None, + request: Union[job_service.ListHyperparameterTuningJobsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListHyperparameterTuningJobsPager: r"""Lists HyperparameterTuningJobs in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_list_hyperparameter_tuning_jobs(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListHyperparameterTuningJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_hyperparameter_tuning_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ListHyperparameterTuningJobsRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ListHyperparameterTuningJobsRequest, dict]): The request object. Request message for [JobService.ListHyperparameterTuningJobs][google.cloud.aiplatform.v1beta1.JobService.ListHyperparameterTuningJobs]. parent (str): @@ -1555,7 +2034,7 @@ def list_hyperparameter_tuning_jobs( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1588,12 +2067,20 @@ def list_hyperparameter_tuning_jobs( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListHyperparameterTuningJobsPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -1601,17 +2088,40 @@ def list_hyperparameter_tuning_jobs( def delete_hyperparameter_tuning_job( self, - request: job_service.DeleteHyperparameterTuningJobRequest = None, + request: Union[job_service.DeleteHyperparameterTuningJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Deletes a HyperparameterTuningJob. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_delete_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteHyperparameterTuningJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_hyperparameter_tuning_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.DeleteHyperparameterTuningJobRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteHyperparameterTuningJobRequest, dict]): The request object. Request message for [JobService.DeleteHyperparameterTuningJob][google.cloud.aiplatform.v1beta1.JobService.DeleteHyperparameterTuningJob]. name (str): @@ -1648,7 +2158,7 @@ def delete_hyperparameter_tuning_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1681,7 +2191,12 @@ def delete_hyperparameter_tuning_job( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -1696,10 +2211,10 @@ def delete_hyperparameter_tuning_job( def cancel_hyperparameter_tuning_job( self, - request: job_service.CancelHyperparameterTuningJobRequest = None, + request: Union[job_service.CancelHyperparameterTuningJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -1718,8 +2233,24 @@ def cancel_hyperparameter_tuning_job( [HyperparameterTuningJob.state][google.cloud.aiplatform.v1beta1.HyperparameterTuningJob.state] is set to ``CANCELLED``. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_cancel_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CancelHyperparameterTuningJobRequest( + name="name_value", + ) + + # Make the request + client.cancel_hyperparameter_tuning_job(request=request) + Args: - request (google.cloud.aiplatform_v1beta1.types.CancelHyperparameterTuningJobRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.CancelHyperparameterTuningJobRequest, dict]): The request object. Request message for [JobService.CancelHyperparameterTuningJob][google.cloud.aiplatform.v1beta1.JobService.CancelHyperparameterTuningJob]. name (str): @@ -1737,7 +2268,7 @@ def cancel_hyperparameter_tuning_job( 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 + # Quick 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: @@ -1771,24 +2302,54 @@ def cancel_hyperparameter_tuning_job( # Send the request. rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) def create_batch_prediction_job( self, - request: job_service.CreateBatchPredictionJobRequest = None, + request: Union[job_service.CreateBatchPredictionJobRequest, dict] = None, *, parent: str = None, batch_prediction_job: gca_batch_prediction_job.BatchPredictionJob = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_batch_prediction_job.BatchPredictionJob: r"""Creates a BatchPredictionJob. A BatchPredictionJob once created will right away be attempted to start. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_create_batch_prediction_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + batch_prediction_job = aiplatform_v1beta1.BatchPredictionJob() + batch_prediction_job.display_name = "display_name_value" + batch_prediction_job.input_config.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + batch_prediction_job.input_config.instances_format = "instances_format_value" + batch_prediction_job.output_config.gcs_destination.output_uri_prefix = "output_uri_prefix_value" + batch_prediction_job.output_config.predictions_format = "predictions_format_value" + + request = aiplatform_v1beta1.CreateBatchPredictionJobRequest( + parent="parent_value", + batch_prediction_job=batch_prediction_job, + ) + + # Make the request + response = client.create_batch_prediction_job(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.CreateBatchPredictionJobRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateBatchPredictionJobRequest, dict]): The request object. Request message for [JobService.CreateBatchPredictionJob][google.cloud.aiplatform.v1beta1.JobService.CreateBatchPredictionJob]. parent (str): @@ -1823,7 +2384,7 @@ def create_batch_prediction_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, batch_prediction_job]) if request is not None and has_flattened_params: @@ -1858,24 +2419,48 @@ def create_batch_prediction_job( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def get_batch_prediction_job( self, - request: job_service.GetBatchPredictionJobRequest = None, + request: Union[job_service.GetBatchPredictionJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> batch_prediction_job.BatchPredictionJob: r"""Gets a BatchPredictionJob + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_get_batch_prediction_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetBatchPredictionJobRequest( + name="name_value", + ) + + # Make the request + response = client.get_batch_prediction_job(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.GetBatchPredictionJobRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.GetBatchPredictionJobRequest, dict]): The request object. Request message for [JobService.GetBatchPredictionJob][google.cloud.aiplatform.v1beta1.JobService.GetBatchPredictionJob]. name (str): @@ -1903,7 +2488,7 @@ def get_batch_prediction_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1934,24 +2519,49 @@ def get_batch_prediction_job( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_batch_prediction_jobs( self, - request: job_service.ListBatchPredictionJobsRequest = None, + request: Union[job_service.ListBatchPredictionJobsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListBatchPredictionJobsPager: r"""Lists BatchPredictionJobs in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_list_batch_prediction_jobs(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListBatchPredictionJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_batch_prediction_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ListBatchPredictionJobsRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ListBatchPredictionJobsRequest, dict]): The request object. Request message for [JobService.ListBatchPredictionJobs][google.cloud.aiplatform.v1beta1.JobService.ListBatchPredictionJobs]. parent (str): @@ -1978,7 +2588,7 @@ def list_batch_prediction_jobs( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -2011,12 +2621,20 @@ def list_batch_prediction_jobs( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListBatchPredictionJobsPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -2024,18 +2642,41 @@ def list_batch_prediction_jobs( def delete_batch_prediction_job( self, - request: job_service.DeleteBatchPredictionJobRequest = None, + request: Union[job_service.DeleteBatchPredictionJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Deletes a BatchPredictionJob. Can only be called on jobs that already finished. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_delete_batch_prediction_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteBatchPredictionJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_batch_prediction_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.DeleteBatchPredictionJobRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteBatchPredictionJobRequest, dict]): The request object. Request message for [JobService.DeleteBatchPredictionJob][google.cloud.aiplatform.v1beta1.JobService.DeleteBatchPredictionJob]. name (str): @@ -2072,7 +2713,7 @@ def delete_batch_prediction_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -2105,7 +2746,12 @@ def delete_batch_prediction_job( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -2120,10 +2766,10 @@ def delete_batch_prediction_job( def cancel_batch_prediction_job( self, - request: job_service.CancelBatchPredictionJobRequest = None, + request: Union[job_service.CancelBatchPredictionJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -2140,8 +2786,24 @@ def cancel_batch_prediction_job( is set to ``CANCELLED``. Any files already outputted by the job are not deleted. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_cancel_batch_prediction_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CancelBatchPredictionJobRequest( + name="name_value", + ) + + # Make the request + client.cancel_batch_prediction_job(request=request) + Args: - request (google.cloud.aiplatform_v1beta1.types.CancelBatchPredictionJobRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.CancelBatchPredictionJobRequest, dict]): The request object. Request message for [JobService.CancelBatchPredictionJob][google.cloud.aiplatform.v1beta1.JobService.CancelBatchPredictionJob]. name (str): @@ -2159,7 +2821,7 @@ def cancel_batch_prediction_job( 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 + # Quick 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: @@ -2193,24 +2855,53 @@ def cancel_batch_prediction_job( # Send the request. rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) def create_model_deployment_monitoring_job( self, - request: job_service.CreateModelDeploymentMonitoringJobRequest = None, + request: Union[ + job_service.CreateModelDeploymentMonitoringJobRequest, dict + ] = None, *, parent: str = None, model_deployment_monitoring_job: gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob: r"""Creates a ModelDeploymentMonitoringJob. It will run periodically on a configured interval. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_create_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + model_deployment_monitoring_job = aiplatform_v1beta1.ModelDeploymentMonitoringJob() + model_deployment_monitoring_job.display_name = "display_name_value" + model_deployment_monitoring_job.endpoint = "endpoint_value" + + request = aiplatform_v1beta1.CreateModelDeploymentMonitoringJobRequest( + parent="parent_value", + model_deployment_monitoring_job=model_deployment_monitoring_job, + ) + + # Make the request + response = client.create_model_deployment_monitoring_job(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.CreateModelDeploymentMonitoringJobRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateModelDeploymentMonitoringJobRequest, dict]): The request object. Request message for [JobService.CreateModelDeploymentMonitoringJob][google.cloud.aiplatform.v1beta1.JobService.CreateModelDeploymentMonitoringJob]. parent (str): @@ -2244,7 +2935,7 @@ def create_model_deployment_monitoring_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, model_deployment_monitoring_job]) if request is not None and has_flattened_params: @@ -2283,39 +2974,67 @@ def create_model_deployment_monitoring_job( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def search_model_deployment_monitoring_stats_anomalies( self, - request: job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest = None, + request: Union[ + job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest, dict + ] = None, *, model_deployment_monitoring_job: str = None, deployed_model_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.SearchModelDeploymentMonitoringStatsAnomaliesPager: r"""Searches Model Monitoring Statistics generated within a given time window. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_search_model_deployment_monitoring_stats_anomalies(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.SearchModelDeploymentMonitoringStatsAnomaliesRequest( + model_deployment_monitoring_job="model_deployment_monitoring_job_value", + deployed_model_id="deployed_model_id_value", + ) + + # Make the request + page_result = client.search_model_deployment_monitoring_stats_anomalies(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.SearchModelDeploymentMonitoringStatsAnomaliesRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.SearchModelDeploymentMonitoringStatsAnomaliesRequest, dict]): The request object. Request message for [JobService.SearchModelDeploymentMonitoringStatsAnomalies][google.cloud.aiplatform.v1beta1.JobService.SearchModelDeploymentMonitoringStatsAnomalies]. model_deployment_monitoring_job (str): Required. ModelDeploymentMonitoring Job resource name. Format: - \`projects/{project}/locations/{location}/modelDeploymentMonitoringJobs/{model_deployment_monitoring_job} + ``projects/{project}/locations/{location}/modelDeploymentMonitoringJobs/{model_deployment_monitoring_job}`` This corresponds to the ``model_deployment_monitoring_job`` field on the ``request`` instance; if ``request`` is provided, this should not be set. deployed_model_id (str): Required. The DeployedModel ID of the - [google.cloud.aiplatform.master.ModelDeploymentMonitoringObjectiveConfig.deployed_model_id]. + [ModelDeploymentMonitoringObjectiveConfig.deployed_model_id]. This corresponds to the ``deployed_model_id`` field on the ``request`` instance; if ``request`` is provided, this @@ -2336,7 +3055,7 @@ def search_model_deployment_monitoring_stats_anomalies( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([model_deployment_monitoring_job, deployed_model_id]) if request is not None and has_flattened_params: @@ -2384,12 +3103,20 @@ def search_model_deployment_monitoring_stats_anomalies( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.SearchModelDeploymentMonitoringStatsAnomaliesPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -2397,19 +3124,38 @@ def search_model_deployment_monitoring_stats_anomalies( def get_model_deployment_monitoring_job( self, - request: job_service.GetModelDeploymentMonitoringJobRequest = None, + request: Union[job_service.GetModelDeploymentMonitoringJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> model_deployment_monitoring_job.ModelDeploymentMonitoringJob: r"""Gets a ModelDeploymentMonitoringJob. - Args: - request (google.cloud.aiplatform_v1beta1.types.GetModelDeploymentMonitoringJobRequest): - The request object. Request message for - [JobService.GetModelDeploymentMonitoringJob][google.cloud.aiplatform.v1beta1.JobService.GetModelDeploymentMonitoringJob]. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_get_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + response = client.get_model_deployment_monitoring_job(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.GetModelDeploymentMonitoringJobRequest, dict]): + The request object. Request message for + [JobService.GetModelDeploymentMonitoringJob][google.cloud.aiplatform.v1beta1.JobService.GetModelDeploymentMonitoringJob]. name (str): Required. The resource name of the ModelDeploymentMonitoringJob. Format: @@ -2434,7 +3180,7 @@ def get_model_deployment_monitoring_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -2467,24 +3213,51 @@ def get_model_deployment_monitoring_job( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_model_deployment_monitoring_jobs( self, - request: job_service.ListModelDeploymentMonitoringJobsRequest = None, + request: Union[ + job_service.ListModelDeploymentMonitoringJobsRequest, dict + ] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListModelDeploymentMonitoringJobsPager: r"""Lists ModelDeploymentMonitoringJobs in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_list_model_deployment_monitoring_jobs(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListModelDeploymentMonitoringJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_model_deployment_monitoring_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ListModelDeploymentMonitoringJobsRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ListModelDeploymentMonitoringJobsRequest, dict]): The request object. Request message for [JobService.ListModelDeploymentMonitoringJobs][google.cloud.aiplatform.v1beta1.JobService.ListModelDeploymentMonitoringJobs]. parent (str): @@ -2511,7 +3284,7 @@ def list_model_deployment_monitoring_jobs( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -2546,12 +3319,20 @@ def list_model_deployment_monitoring_jobs( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListModelDeploymentMonitoringJobsPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -2559,18 +3340,47 @@ def list_model_deployment_monitoring_jobs( def update_model_deployment_monitoring_job( self, - request: job_service.UpdateModelDeploymentMonitoringJobRequest = None, + request: Union[ + job_service.UpdateModelDeploymentMonitoringJobRequest, dict + ] = None, *, model_deployment_monitoring_job: gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Updates a ModelDeploymentMonitoringJob. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_update_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + model_deployment_monitoring_job = aiplatform_v1beta1.ModelDeploymentMonitoringJob() + model_deployment_monitoring_job.display_name = "display_name_value" + model_deployment_monitoring_job.endpoint = "endpoint_value" + + request = aiplatform_v1beta1.UpdateModelDeploymentMonitoringJobRequest( + model_deployment_monitoring_job=model_deployment_monitoring_job, + ) + + # Make the request + operation = client.update_model_deployment_monitoring_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.UpdateModelDeploymentMonitoringJobRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.UpdateModelDeploymentMonitoringJobRequest, dict]): The request object. Request message for [JobService.UpdateModelDeploymentMonitoringJob][google.cloud.aiplatform.v1beta1.JobService.UpdateModelDeploymentMonitoringJob]. model_deployment_monitoring_job (google.cloud.aiplatform_v1beta1.types.ModelDeploymentMonitoringJob): @@ -2582,8 +3392,34 @@ def update_model_deployment_monitoring_job( on the ``request`` instance; if ``request`` is provided, this should not be set. update_mask (google.protobuf.field_mask_pb2.FieldMask): - Required. The update mask applies to - the resource. + Required. The update mask is used to specify the fields + to be overwritten in the ModelDeploymentMonitoringJob + resource by the update. The fields specified in the + update_mask are relative to the resource, not the full + request. A field will be overwritten if it is in the + mask. If the user does not provide a mask then only the + non-empty fields present in the request will be + overwritten. Set the update_mask to ``*`` to override + all fields. For the objective config, the user can + either provide the update mask for + model_deployment_monitoring_objective_configs or any + combination of its nested fields, such as: + model_deployment_monitoring_objective_configs.objective_config.training_dataset. + + Updatable fields: + + - ``display_name`` + - ``model_deployment_monitoring_schedule_config`` + - ``model_monitoring_alert_config`` + - ``logging_sampling_strategy`` + - ``labels`` + - ``log_ttl`` + - ``enable_monitoring_pipeline_logs`` . and + - ``model_deployment_monitoring_objective_configs`` . + or + - ``model_deployment_monitoring_objective_configs.objective_config.training_dataset`` + - ``model_deployment_monitoring_objective_configs.objective_config.training_prediction_skew_detection_config`` + - ``model_deployment_monitoring_objective_configs.objective_config.prediction_drift_detection_config`` This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this @@ -2604,7 +3440,7 @@ def update_model_deployment_monitoring_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([model_deployment_monitoring_job, update_mask]) if request is not None and has_flattened_params: @@ -2650,7 +3486,12 @@ def update_model_deployment_monitoring_job( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -2665,17 +3506,42 @@ def update_model_deployment_monitoring_job( def delete_model_deployment_monitoring_job( self, - request: job_service.DeleteModelDeploymentMonitoringJobRequest = None, + request: Union[ + job_service.DeleteModelDeploymentMonitoringJobRequest, dict + ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Deletes a ModelDeploymentMonitoringJob. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_delete_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_model_deployment_monitoring_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.DeleteModelDeploymentMonitoringJobRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteModelDeploymentMonitoringJobRequest, dict]): The request object. Request message for [JobService.DeleteModelDeploymentMonitoringJob][google.cloud.aiplatform.v1beta1.JobService.DeleteModelDeploymentMonitoringJob]. name (str): @@ -2712,7 +3578,7 @@ def delete_model_deployment_monitoring_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -2747,7 +3613,12 @@ def delete_model_deployment_monitoring_job( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -2762,10 +3633,12 @@ def delete_model_deployment_monitoring_job( def pause_model_deployment_monitoring_job( self, - request: job_service.PauseModelDeploymentMonitoringJobRequest = None, + request: Union[ + job_service.PauseModelDeploymentMonitoringJobRequest, dict + ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -2774,8 +3647,24 @@ def pause_model_deployment_monitoring_job( [ModelDeploymentMonitoringJob.state][google.cloud.aiplatform.v1beta1.ModelDeploymentMonitoringJob.state] to 'PAUSED'. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_pause_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.PauseModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + client.pause_model_deployment_monitoring_job(request=request) + Args: - request (google.cloud.aiplatform_v1beta1.types.PauseModelDeploymentMonitoringJobRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.PauseModelDeploymentMonitoringJobRequest, dict]): The request object. Request message for [JobService.PauseModelDeploymentMonitoringJob][google.cloud.aiplatform.v1beta1.JobService.PauseModelDeploymentMonitoringJob]. name (str): @@ -2793,7 +3682,7 @@ def pause_model_deployment_monitoring_job( 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 + # Quick 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: @@ -2829,15 +3718,20 @@ def pause_model_deployment_monitoring_job( # Send the request. rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) def resume_model_deployment_monitoring_job( self, - request: job_service.ResumeModelDeploymentMonitoringJobRequest = None, + request: Union[ + job_service.ResumeModelDeploymentMonitoringJobRequest, dict + ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -2845,8 +3739,24 @@ def resume_model_deployment_monitoring_job( will start to run from next scheduled time. A deleted ModelDeploymentMonitoringJob can't be resumed. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_resume_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ResumeModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + client.resume_model_deployment_monitoring_job(request=request) + Args: - request (google.cloud.aiplatform_v1beta1.types.ResumeModelDeploymentMonitoringJobRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ResumeModelDeploymentMonitoringJobRequest, dict]): The request object. Request message for [JobService.ResumeModelDeploymentMonitoringJob][google.cloud.aiplatform.v1beta1.JobService.ResumeModelDeploymentMonitoringJob]. name (str): @@ -2864,7 +3774,7 @@ def resume_model_deployment_monitoring_job( 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 + # Quick 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: @@ -2900,9 +3810,696 @@ def resume_model_deployment_monitoring_job( # Send the request. rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_operations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.delete_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.wait_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_location, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) + # Done; return the response. + return response + + def list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_locations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/aiplatform_v1beta1/services/job_service/pagers.py b/google/cloud/aiplatform_v1beta1/services/job_service/pagers.py index cc1d17b38b..8907b3d212 100644 --- a/google/cloud/aiplatform_v1beta1/services/job_service/pagers.py +++ b/google/cloud/aiplatform_v1beta1/services/job_service/pagers.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,13 +15,13 @@ # from typing import ( Any, - AsyncIterable, + AsyncIterator, Awaitable, Callable, - Iterable, Sequence, Tuple, Optional, + Iterator, ) from google.cloud.aiplatform_v1beta1.types import batch_prediction_job @@ -82,14 +82,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[job_service.ListCustomJobsResponse]: + def pages(self) -> Iterator[job_service.ListCustomJobsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[custom_job.CustomJob]: + def __iter__(self) -> Iterator[custom_job.CustomJob]: for page in self.pages: yield from page.custom_jobs @@ -123,7 +123,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -144,14 +144,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - async def pages(self) -> AsyncIterable[job_service.ListCustomJobsResponse]: + async def pages(self) -> AsyncIterator[job_service.ListCustomJobsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[custom_job.CustomJob]: + def __aiter__(self) -> AsyncIterator[custom_job.CustomJob]: async def async_generator(): async for page in self.pages: for response in page.custom_jobs: @@ -210,14 +210,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[job_service.ListDataLabelingJobsResponse]: + def pages(self) -> Iterator[job_service.ListDataLabelingJobsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[data_labeling_job.DataLabelingJob]: + def __iter__(self) -> Iterator[data_labeling_job.DataLabelingJob]: for page in self.pages: yield from page.data_labeling_jobs @@ -251,7 +251,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -272,14 +272,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - async def pages(self) -> AsyncIterable[job_service.ListDataLabelingJobsResponse]: + async def pages(self) -> AsyncIterator[job_service.ListDataLabelingJobsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[data_labeling_job.DataLabelingJob]: + def __aiter__(self) -> AsyncIterator[data_labeling_job.DataLabelingJob]: async def async_generator(): async for page in self.pages: for response in page.data_labeling_jobs: @@ -338,14 +338,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[job_service.ListHyperparameterTuningJobsResponse]: + def pages(self) -> Iterator[job_service.ListHyperparameterTuningJobsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[hyperparameter_tuning_job.HyperparameterTuningJob]: + def __iter__(self) -> Iterator[hyperparameter_tuning_job.HyperparameterTuningJob]: for page in self.pages: yield from page.hyperparameter_tuning_jobs @@ -381,7 +381,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -404,7 +404,7 @@ def __getattr__(self, name: str) -> Any: @property async def pages( self, - ) -> AsyncIterable[job_service.ListHyperparameterTuningJobsResponse]: + ) -> AsyncIterator[job_service.ListHyperparameterTuningJobsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token @@ -413,7 +413,7 @@ async def pages( def __aiter__( self, - ) -> AsyncIterable[hyperparameter_tuning_job.HyperparameterTuningJob]: + ) -> AsyncIterator[hyperparameter_tuning_job.HyperparameterTuningJob]: async def async_generator(): async for page in self.pages: for response in page.hyperparameter_tuning_jobs: @@ -472,14 +472,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[job_service.ListBatchPredictionJobsResponse]: + def pages(self) -> Iterator[job_service.ListBatchPredictionJobsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[batch_prediction_job.BatchPredictionJob]: + def __iter__(self) -> Iterator[batch_prediction_job.BatchPredictionJob]: for page in self.pages: yield from page.batch_prediction_jobs @@ -513,7 +513,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -534,14 +534,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - async def pages(self) -> AsyncIterable[job_service.ListBatchPredictionJobsResponse]: + async def pages(self) -> AsyncIterator[job_service.ListBatchPredictionJobsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[batch_prediction_job.BatchPredictionJob]: + def __aiter__(self) -> AsyncIterator[batch_prediction_job.BatchPredictionJob]: async def async_generator(): async for page in self.pages: for response in page.batch_prediction_jobs: @@ -594,8 +594,8 @@ def __init__( sent along with the request as metadata. """ self._method = method - self._request = job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest( - request + self._request = ( + job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest(request) ) self._response = response self._metadata = metadata @@ -606,7 +606,7 @@ def __getattr__(self, name: str) -> Any: @property def pages( self, - ) -> Iterable[job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse]: + ) -> Iterator[job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token @@ -615,7 +615,7 @@ def pages( def __iter__( self, - ) -> Iterable[gca_model_deployment_monitoring_job.ModelMonitoringStatsAnomalies]: + ) -> Iterator[gca_model_deployment_monitoring_job.ModelMonitoringStatsAnomalies]: for page in self.pages: yield from page.monitoring_stats @@ -654,7 +654,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -667,8 +667,8 @@ def __init__( sent along with the request as metadata. """ self._method = method - self._request = job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest( - request + self._request = ( + job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest(request) ) self._response = response self._metadata = metadata @@ -679,7 +679,7 @@ def __getattr__(self, name: str) -> Any: @property async def pages( self, - ) -> AsyncIterable[ + ) -> AsyncIterator[ job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse ]: yield self._response @@ -690,7 +690,7 @@ async def pages( def __aiter__( self, - ) -> AsyncIterable[ + ) -> AsyncIterator[ gca_model_deployment_monitoring_job.ModelMonitoringStatsAnomalies ]: async def async_generator(): @@ -751,7 +751,7 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[job_service.ListModelDeploymentMonitoringJobsResponse]: + def pages(self) -> Iterator[job_service.ListModelDeploymentMonitoringJobsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token @@ -760,7 +760,7 @@ def pages(self) -> Iterable[job_service.ListModelDeploymentMonitoringJobsRespons def __iter__( self, - ) -> Iterable[model_deployment_monitoring_job.ModelDeploymentMonitoringJob]: + ) -> Iterator[model_deployment_monitoring_job.ModelDeploymentMonitoringJob]: for page in self.pages: yield from page.model_deployment_monitoring_jobs @@ -796,7 +796,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -819,7 +819,7 @@ def __getattr__(self, name: str) -> Any: @property async def pages( self, - ) -> AsyncIterable[job_service.ListModelDeploymentMonitoringJobsResponse]: + ) -> AsyncIterator[job_service.ListModelDeploymentMonitoringJobsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token @@ -828,7 +828,7 @@ async def pages( def __aiter__( self, - ) -> AsyncIterable[model_deployment_monitoring_job.ModelDeploymentMonitoringJob]: + ) -> AsyncIterator[model_deployment_monitoring_job.ModelDeploymentMonitoringJob]: async def async_generator(): async for page in self.pages: for response in page.model_deployment_monitoring_jobs: diff --git a/google/cloud/aiplatform_v1beta1/services/job_service/transports/__init__.py b/google/cloud/aiplatform_v1beta1/services/job_service/transports/__init__.py index c512946de1..bb641d64c6 100644 --- a/google/cloud/aiplatform_v1beta1/services/job_service/transports/__init__.py +++ b/google/cloud/aiplatform_v1beta1/services/job_service/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1beta1/services/job_service/transports/base.py b/google/cloud/aiplatform_v1beta1/services/job_service/transports/base.py index f4adf20483..117443312c 100644 --- a/google/cloud/aiplatform_v1beta1/services/job_service/transports/base.py +++ b/google/cloud/aiplatform_v1beta1/services/job_service/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,16 +15,16 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.api_core import operations_v1 # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.aiplatform_v1beta1.types import batch_prediction_job from google.cloud.aiplatform_v1beta1.types import ( @@ -45,6 +45,10 @@ from google.cloud.aiplatform_v1beta1.types import ( model_deployment_monitoring_job as gca_model_deployment_monitoring_job, ) +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from google.protobuf import empty_pb2 # type: ignore @@ -57,17 +61,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - -_API_CORE_VERSION = google.api_core.__version__ - class JobServiceTransport(abc.ABC): """Abstract transport class for JobService.""" @@ -85,6 +78,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -108,16 +102,19 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -130,77 +127,49 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id ) - # Save the credentials. - self._credentials = credentials - - # TODO(busunkim): These two class methods are in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-api-core - # and google-auth are increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") + # If the credentials are service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs - - # TODO: Remove this function once google-api-core >= 1.26.0 is required - @classmethod - def _get_self_signed_jwt_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Union[Optional[Sequence[str]], str]]: - """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" + credentials = credentials.with_always_use_jwt_access(True) - self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} - - if _API_CORE_VERSION and ( - packaging.version.parse(_API_CORE_VERSION) - >= packaging.version.parse("1.26.0") - ): - self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES - self_signed_jwt_kwargs["scopes"] = scopes - self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST - else: - self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES - - return self_signed_jwt_kwargs + # Save the credentials. + self._credentials = credentials def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { self.create_custom_job: gapic_v1.method.wrap_method( - self.create_custom_job, default_timeout=5.0, client_info=client_info, + self.create_custom_job, + default_timeout=5.0, + client_info=client_info, ), self.get_custom_job: gapic_v1.method.wrap_method( - self.get_custom_job, default_timeout=5.0, client_info=client_info, + self.get_custom_job, + default_timeout=5.0, + client_info=client_info, ), self.list_custom_jobs: gapic_v1.method.wrap_method( - self.list_custom_jobs, default_timeout=5.0, client_info=client_info, + self.list_custom_jobs, + default_timeout=5.0, + client_info=client_info, ), self.delete_custom_job: gapic_v1.method.wrap_method( - self.delete_custom_job, default_timeout=5.0, client_info=client_info, + self.delete_custom_job, + default_timeout=5.0, + client_info=client_info, ), self.cancel_custom_job: gapic_v1.method.wrap_method( - self.cancel_custom_job, default_timeout=5.0, client_info=client_info, + self.cancel_custom_job, + default_timeout=5.0, + client_info=client_info, ), self.create_data_labeling_job: gapic_v1.method.wrap_method( self.create_data_labeling_job, @@ -319,8 +288,17 @@ def _prep_wrapped_messages(self, client_info): ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() @@ -620,5 +598,102 @@ def resume_model_deployment_monitoring_job( ]: raise NotImplementedError() + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], + Union[ + operations_pb2.ListOperationsResponse, + Awaitable[operations_pb2.ListOperationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None,]: + raise NotImplementedError() + + @property + def wait_operation( + self, + ) -> Callable[ + [operations_pb2.WaitOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def set_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def get_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_location( + self, + ) -> Callable[ + [locations_pb2.GetLocationRequest], + Union[locations_pb2.Location, Awaitable[locations_pb2.Location]], + ]: + raise NotImplementedError() + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], + Union[ + locations_pb2.ListLocationsResponse, + Awaitable[locations_pb2.ListLocationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + __all__ = ("JobServiceTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/job_service/transports/grpc.py b/google/cloud/aiplatform_v1beta1/services/job_service/transports/grpc.py index 797420d74a..a259658c15 100644 --- a/google/cloud/aiplatform_v1beta1/services/job_service/transports/grpc.py +++ b/google/cloud/aiplatform_v1beta1/services/job_service/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,9 +16,9 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import operations_v1 +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -44,6 +44,10 @@ from google.cloud.aiplatform_v1beta1.types import ( model_deployment_monitoring_job as gca_model_deployment_monitoring_job, ) +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from google.protobuf import empty_pb2 # type: ignore from .base import JobServiceTransport, DEFAULT_CLIENT_INFO @@ -52,7 +56,7 @@ class JobServiceGrpcTransport(JobServiceTransport): """gRPC backend transport for JobService. - A service for creating and managing AI Platform's jobs. + A service for creating and managing Vertex AI's jobs. This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation @@ -78,6 +82,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -100,16 +105,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -118,6 +123,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport @@ -128,7 +135,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -171,13 +178,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -226,21 +237,20 @@ def create_channel( and ``credentials_file`` are passed. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @property def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ + """Return the channel designed to connect to this service.""" return self._grpc_channel @property @@ -250,7 +260,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsClient(self.grpc_channel) @@ -1124,5 +1134,215 @@ def resume_model_deployment_monitoring_job( ) return self._stubs["resume_model_deployment_monitoring_job"] + def close(self): + self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + @property + def kind(self) -> str: + return "grpc" + __all__ = ("JobServiceGrpcTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/job_service/transports/grpc_asyncio.py b/google/cloud/aiplatform_v1beta1/services/job_service/transports/grpc_asyncio.py index 93f5416555..611cee3f37 100644 --- a/google/cloud/aiplatform_v1beta1/services/job_service/transports/grpc_asyncio.py +++ b/google/cloud/aiplatform_v1beta1/services/job_service/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,12 +16,11 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore -from google.api_core import operations_v1 # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore @@ -45,6 +44,10 @@ from google.cloud.aiplatform_v1beta1.types import ( model_deployment_monitoring_job as gca_model_deployment_monitoring_job, ) +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from google.protobuf import empty_pb2 # type: ignore from .base import JobServiceTransport, DEFAULT_CLIENT_INFO @@ -54,7 +57,7 @@ class JobServiceGrpcAsyncIOTransport(JobServiceTransport): """gRPC AsyncIO backend transport for JobService. - A service for creating and managing AI Platform's jobs. + A service for creating and managing Vertex AI's jobs. This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation @@ -99,14 +102,14 @@ def create_channel( aio.Channel: A gRPC AsyncIO channel object. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @@ -124,6 +127,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -147,16 +151,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -165,6 +169,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport @@ -175,7 +181,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -217,13 +223,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -253,7 +263,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel @@ -1147,5 +1157,211 @@ def resume_model_deployment_monitoring_job( ) return self._stubs["resume_model_deployment_monitoring_job"] + def close(self): + return self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + __all__ = ("JobServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/metadata_service/__init__.py b/google/cloud/aiplatform_v1beta1/services/metadata_service/__init__.py index 656a64511b..090778e891 100644 --- a/google/cloud/aiplatform_v1beta1/services/metadata_service/__init__.py +++ b/google/cloud/aiplatform_v1beta1/services/metadata_service/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1beta1/services/metadata_service/async_client.py b/google/cloud/aiplatform_v1beta1/services/metadata_service/async_client.py index 18488133ce..e72901e551 100644 --- a/google/cloud/aiplatform_v1beta1/services/metadata_service/async_client.py +++ b/google/cloud/aiplatform_v1beta1/services/metadata_service/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,16 +16,21 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation as gac_operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1beta1.services.metadata_service import pagers @@ -44,6 +49,10 @@ from google.cloud.aiplatform_v1beta1.types import metadata_store from google.cloud.aiplatform_v1beta1.types import metadata_store as gca_metadata_store from google.cloud.aiplatform_v1beta1.types import operation as gca_operation +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import struct_pb2 # type: ignore @@ -102,7 +111,8 @@ class MetadataServiceAsyncClient: @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -117,7 +127,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -132,9 +142,45 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return MetadataServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> MetadataServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: MetadataServiceTransport: The transport used by the client instance. @@ -153,7 +199,7 @@ def __init__( client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the metadata service client. + """Instantiates the metadata service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -194,27 +240,49 @@ def __init__( async def create_metadata_store( self, - request: metadata_service.CreateMetadataStoreRequest = None, + request: Union[metadata_service.CreateMetadataStoreRequest, dict] = None, *, parent: str = None, metadata_store: gca_metadata_store.MetadataStore = None, metadata_store_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Initializes a MetadataStore, including allocation of resources. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_create_metadata_store(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateMetadataStoreRequest( + parent="parent_value", + ) + + # Make the request + operation = client.create_metadata_store(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.CreateMetadataStoreRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateMetadataStoreRequest, dict]): The request object. Request message for [MetadataService.CreateMetadataStore][google.cloud.aiplatform.v1beta1.MetadataService.CreateMetadataStore]. parent (:class:`str`): - Required. The resource name of the - Location where the MetadataStore should - be created. Format: - projects/{project}/locations/{location}/ + Required. The resource name of the Location where the + MetadataStore should be created. Format: + ``projects/{project}/locations/{location}/`` This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -229,10 +297,10 @@ async def create_metadata_store( metadata_store_id (:class:`str`): The {metadatastore} portion of the resource name with the format: - projects/{project}/locations/{location}/metadataStores/{metadatastore} + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` If not provided, the MetadataStore's ID will be a UUID generated by the service. Must be 4-128 characters in - length. Valid characters are /[a-z][0-9]-/. Must be + length. Valid characters are ``/[a-z][0-9]-/``. Must be unique across all MetadataStores in the parent Location. (Otherwise the request will fail with ALREADY_EXISTS, or PERMISSION_DENIED if the caller can't view the @@ -256,7 +324,7 @@ async def create_metadata_store( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, metadata_store, metadata_store_id]) if request is not None and has_flattened_params: @@ -291,7 +359,12 @@ async def create_metadata_store( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -306,23 +379,42 @@ async def create_metadata_store( async def get_metadata_store( self, - request: metadata_service.GetMetadataStoreRequest = None, + request: Union[metadata_service.GetMetadataStoreRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> metadata_store.MetadataStore: r"""Retrieves a specific MetadataStore. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_get_metadata_store(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetMetadataStoreRequest( + name="name_value", + ) + + # Make the request + response = await client.get_metadata_store(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.GetMetadataStoreRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.GetMetadataStoreRequest, dict]): The request object. Request message for [MetadataService.GetMetadataStore][google.cloud.aiplatform.v1beta1.MetadataService.GetMetadataStore]. name (:class:`str`): - Required. The resource name of the - MetadataStore to retrieve. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore} + Required. The resource name of the MetadataStore to + retrieve. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -341,7 +433,7 @@ async def get_metadata_store( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -372,30 +464,55 @@ async def get_metadata_store( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_metadata_stores( self, - request: metadata_service.ListMetadataStoresRequest = None, + request: Union[metadata_service.ListMetadataStoresRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListMetadataStoresAsyncPager: r"""Lists MetadataStores for a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_list_metadata_stores(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListMetadataStoresRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_metadata_stores(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ListMetadataStoresRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ListMetadataStoresRequest, dict]): The request object. Request message for [MetadataService.ListMetadataStores][google.cloud.aiplatform.v1beta1.MetadataService.ListMetadataStores]. parent (:class:`str`): - Required. The Location whose - MetadataStores should be listed. Format: - projects/{project}/locations/{location} + Required. The Location whose MetadataStores should be + listed. Format: + ``projects/{project}/locations/{location}`` This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -416,7 +533,7 @@ async def list_metadata_stores( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -447,12 +564,20 @@ async def list_metadata_stores( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListMetadataStoresAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -460,23 +585,47 @@ async def list_metadata_stores( async def delete_metadata_store( self, - request: metadata_service.DeleteMetadataStoreRequest = None, + request: Union[metadata_service.DeleteMetadataStoreRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: - r"""Deletes a single MetadataStore. + r"""Deletes a single MetadataStore and all its child + resources (Artifacts, Executions, and Contexts). + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_delete_metadata_store(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteMetadataStoreRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_metadata_store(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.DeleteMetadataStoreRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteMetadataStoreRequest, dict]): The request object. Request message for [MetadataService.DeleteMetadataStore][google.cloud.aiplatform.v1beta1.MetadataService.DeleteMetadataStore]. name (:class:`str`): - Required. The resource name of the - MetadataStore to delete. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore} + Required. The resource name of the MetadataStore to + delete. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -507,7 +656,7 @@ async def delete_metadata_store( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -538,7 +687,12 @@ async def delete_metadata_store( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -553,26 +707,44 @@ async def delete_metadata_store( async def create_artifact( self, - request: metadata_service.CreateArtifactRequest = None, + request: Union[metadata_service.CreateArtifactRequest, dict] = None, *, parent: str = None, artifact: gca_artifact.Artifact = None, artifact_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_artifact.Artifact: r"""Creates an Artifact associated with a MetadataStore. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_create_artifact(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateArtifactRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_artifact(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.CreateArtifactRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateArtifactRequest, dict]): The request object. Request message for [MetadataService.CreateArtifact][google.cloud.aiplatform.v1beta1.MetadataService.CreateArtifact]. parent (:class:`str`): - Required. The resource name of the - MetadataStore where the Artifact should - be created. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore} + Required. The resource name of the MetadataStore where + the Artifact should be created. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -585,10 +757,10 @@ async def create_artifact( artifact_id (:class:`str`): The {artifact} portion of the resource name with the format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact} + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact}`` If not provided, the Artifact's ID will be a UUID generated by the service. Must be 4-128 characters in - length. Valid characters are /[a-z][0-9]-/. Must be + length. Valid characters are ``/[a-z][0-9]-/``. Must be unique across all Artifacts in the parent MetadataStore. (Otherwise the request will fail with ALREADY_EXISTS, or PERMISSION_DENIED if the caller can't view the @@ -608,7 +780,7 @@ async def create_artifact( Instance of a general artifact. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, artifact, artifact_id]) if request is not None and has_flattened_params: @@ -643,30 +815,54 @@ async def create_artifact( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def get_artifact( self, - request: metadata_service.GetArtifactRequest = None, + request: Union[metadata_service.GetArtifactRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> artifact.Artifact: r"""Retrieves a specific Artifact. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_get_artifact(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetArtifactRequest( + name="name_value", + ) + + # Make the request + response = await client.get_artifact(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.GetArtifactRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.GetArtifactRequest, dict]): The request object. Request message for [MetadataService.GetArtifact][google.cloud.aiplatform.v1beta1.MetadataService.GetArtifact]. name (:class:`str`): - Required. The resource name of the - Artifact to retrieve. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact} + Required. The resource name of the Artifact to retrieve. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact}`` This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -682,7 +878,7 @@ async def get_artifact( Instance of a general artifact. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -713,30 +909,55 @@ async def get_artifact( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_artifacts( self, - request: metadata_service.ListArtifactsRequest = None, + request: Union[metadata_service.ListArtifactsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListArtifactsAsyncPager: r"""Lists Artifacts in the MetadataStore. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_list_artifacts(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListArtifactsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_artifacts(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ListArtifactsRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ListArtifactsRequest, dict]): The request object. Request message for [MetadataService.ListArtifacts][google.cloud.aiplatform.v1beta1.MetadataService.ListArtifacts]. parent (:class:`str`): - Required. The MetadataStore whose - Artifacts should be listed. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore} + Required. The MetadataStore whose Artifacts should be + listed. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -757,7 +978,7 @@ async def list_artifacts( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -788,12 +1009,20 @@ async def list_artifacts( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListArtifactsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -801,18 +1030,36 @@ async def list_artifacts( async def update_artifact( self, - request: metadata_service.UpdateArtifactRequest = None, + request: Union[metadata_service.UpdateArtifactRequest, dict] = None, *, artifact: gca_artifact.Artifact = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_artifact.Artifact: r"""Updates a stored Artifact. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_update_artifact(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateArtifactRequest( + ) + + # Make the request + response = await client.update_artifact(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.UpdateArtifactRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.UpdateArtifactRequest, dict]): The request object. Request message for [MetadataService.UpdateArtifact][google.cloud.aiplatform.v1beta1.MetadataService.UpdateArtifact]. artifact (:class:`google.cloud.aiplatform_v1beta1.types.Artifact`): @@ -821,14 +1068,16 @@ async def update_artifact( [Artifact.name][google.cloud.aiplatform.v1beta1.Artifact.name] field is used to identify the Artifact to be updated. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact} + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact}`` This corresponds to the ``artifact`` field on the ``request`` instance; if ``request`` is provided, this should not be set. update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): - Required. A FieldMask indicating + Optional. A FieldMask indicating which fields should be updated. + Functionality of this field is not yet + supported. This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this @@ -844,7 +1093,7 @@ async def update_artifact( Instance of a general artifact. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([artifact, update_mask]) if request is not None and has_flattened_params: @@ -879,33 +1128,290 @@ async def update_artifact( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def delete_artifact( + self, + request: Union[metadata_service.DeleteArtifactRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Deletes an Artifact. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_delete_artifact(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteArtifactRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_artifact(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteArtifactRequest, dict]): + The request object. Request message for + [MetadataService.DeleteArtifact][google.cloud.aiplatform.v1beta1.MetadataService.DeleteArtifact]. + name (:class:`str`): + Required. The resource name of the Artifact to delete. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact}`` + + 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = metadata_service.DeleteArtifactRequest(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_artifact, + default_timeout=None, + 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, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, + ) + + # Done; return the response. + return response + + async def purge_artifacts( + self, + request: Union[metadata_service.PurgeArtifactsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Purges Artifacts. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_purge_artifacts(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.PurgeArtifactsRequest( + parent="parent_value", + filter="filter_value", + ) + + # Make the request + operation = client.purge_artifacts(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.PurgeArtifactsRequest, dict]): + The request object. Request message for + [MetadataService.PurgeArtifacts][google.cloud.aiplatform.v1beta1.MetadataService.PurgeArtifacts]. + parent (:class:`str`): + Required. The metadata store to purge Artifacts from. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + + 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.aiplatform_v1beta1.types.PurgeArtifactsResponse` + Response message for + [MetadataService.PurgeArtifacts][google.cloud.aiplatform.v1beta1.MetadataService.PurgeArtifacts]. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = metadata_service.PurgeArtifactsRequest(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.purge_artifacts, + default_timeout=None, + 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, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + metadata_service.PurgeArtifactsResponse, + metadata_type=metadata_service.PurgeArtifactsMetadata, + ) # Done; return the response. return response async def create_context( self, - request: metadata_service.CreateContextRequest = None, + request: Union[metadata_service.CreateContextRequest, dict] = None, *, parent: str = None, context: gca_context.Context = None, context_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_context.Context: r"""Creates a Context associated with a MetadataStore. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_create_context(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateContextRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_context(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.CreateContextRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateContextRequest, dict]): The request object. Request message for [MetadataService.CreateContext][google.cloud.aiplatform.v1beta1.MetadataService.CreateContext]. parent (:class:`str`): - Required. The resource name of the - MetadataStore where the Context should - be created. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore} + Required. The resource name of the MetadataStore where + the Context should be created. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -918,10 +1424,10 @@ async def create_context( context_id (:class:`str`): The {context} portion of the resource name with the format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context} + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}``. If not provided, the Context's ID will be a UUID generated by the service. Must be 4-128 characters in - length. Valid characters are /[a-z][0-9]-/. Must be + length. Valid characters are ``/[a-z][0-9]-/``. Must be unique across all Contexts in the parent MetadataStore. (Otherwise the request will fail with ALREADY_EXISTS, or PERMISSION_DENIED if the caller can't view the @@ -941,7 +1447,7 @@ async def create_context( Instance of a general context. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, context, context_id]) if request is not None and has_flattened_params: @@ -976,30 +1482,54 @@ async def create_context( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def get_context( self, - request: metadata_service.GetContextRequest = None, + request: Union[metadata_service.GetContextRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> context.Context: r"""Retrieves a specific Context. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_get_context(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetContextRequest( + name="name_value", + ) + + # Make the request + response = await client.get_context(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.GetContextRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.GetContextRequest, dict]): The request object. Request message for [MetadataService.GetContext][google.cloud.aiplatform.v1beta1.MetadataService.GetContext]. name (:class:`str`): - Required. The resource name of the - Context to retrieve. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context} + Required. The resource name of the Context to retrieve. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -1015,7 +1545,7 @@ async def get_context( Instance of a general context. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1046,30 +1576,55 @@ async def get_context( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_contexts( self, - request: metadata_service.ListContextsRequest = None, + request: Union[metadata_service.ListContextsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListContextsAsyncPager: r"""Lists Contexts on the MetadataStore. - Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ListContextsRequest`): - The request object. Request message for + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_list_contexts(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListContextsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_contexts(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.ListContextsRequest, dict]): + The request object. Request message for [MetadataService.ListContexts][google.cloud.aiplatform.v1beta1.MetadataService.ListContexts] parent (:class:`str`): - Required. The MetadataStore whose - Contexts should be listed. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore} + Required. The MetadataStore whose Contexts should be + listed. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -1090,7 +1645,7 @@ async def list_contexts( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1121,12 +1676,20 @@ async def list_contexts( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListContextsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -1134,18 +1697,36 @@ async def list_contexts( async def update_context( self, - request: metadata_service.UpdateContextRequest = None, + request: Union[metadata_service.UpdateContextRequest, dict] = None, *, context: gca_context.Context = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_context.Context: r"""Updates a stored Context. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_update_context(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateContextRequest( + ) + + # Make the request + response = await client.update_context(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.UpdateContextRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.UpdateContextRequest, dict]): The request object. Request message for [MetadataService.UpdateContext][google.cloud.aiplatform.v1beta1.MetadataService.UpdateContext]. context (:class:`google.cloud.aiplatform_v1beta1.types.Context`): @@ -1153,14 +1734,16 @@ async def update_context( [Context.name][google.cloud.aiplatform.v1beta1.Context.name] field is used to identify the Context to be updated. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context} + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` This corresponds to the ``context`` field on the ``request`` instance; if ``request`` is provided, this should not be set. update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): - Required. A FieldMask indicating + Optional. A FieldMask indicating which fields should be updated. + Functionality of this field is not yet + supported. This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this @@ -1176,7 +1759,7 @@ async def update_context( Instance of a general context. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([context, update_mask]) if request is not None and has_flattened_params: @@ -1211,30 +1794,58 @@ async def update_context( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def delete_context( self, - request: metadata_service.DeleteContextRequest = None, + request: Union[metadata_service.DeleteContextRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a stored Context. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_delete_context(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteContextRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_context(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.DeleteContextRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteContextRequest, dict]): The request object. Request message for [MetadataService.DeleteContext][google.cloud.aiplatform.v1beta1.MetadataService.DeleteContext]. name (:class:`str`): - Required. The resource name of the - Context to retrieve. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context} + Required. The resource name of the Context to delete. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -1265,7 +1876,7 @@ async def delete_context( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1296,7 +1907,12 @@ async def delete_context( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -1309,14 +1925,129 @@ async def delete_context( # Done; return the response. return response + async def purge_contexts( + self, + request: Union[metadata_service.PurgeContextsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operation_async.AsyncOperation: + r"""Purges Contexts. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_purge_contexts(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.PurgeContextsRequest( + parent="parent_value", + filter="filter_value", + ) + + # Make the request + operation = client.purge_contexts(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.PurgeContextsRequest, dict]): + The request object. Request message for + [MetadataService.PurgeContexts][google.cloud.aiplatform.v1beta1.MetadataService.PurgeContexts]. + parent (:class:`str`): + Required. The metadata store to purge Contexts from. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + + 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: + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.aiplatform_v1beta1.types.PurgeContextsResponse` + Response message for + [MetadataService.PurgeContexts][google.cloud.aiplatform.v1beta1.MetadataService.PurgeContexts]. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = metadata_service.PurgeContextsRequest(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.purge_contexts, + default_timeout=None, + 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, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + metadata_service.PurgeContextsResponse, + metadata_type=metadata_service.PurgeContextsMetadata, + ) + + # Done; return the response. + return response + async def add_context_artifacts_and_executions( self, - request: metadata_service.AddContextArtifactsAndExecutionsRequest = None, + request: Union[ + metadata_service.AddContextArtifactsAndExecutionsRequest, dict + ] = None, *, context: str = None, artifacts: Sequence[str] = None, executions: Sequence[str] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> metadata_service.AddContextArtifactsAndExecutionsResponse: @@ -1324,29 +2055,53 @@ async def add_context_artifacts_and_executions( If any of the Artifacts or Executions have already been added to a Context, they are simply skipped. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_add_context_artifacts_and_executions(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.AddContextArtifactsAndExecutionsRequest( + context="context_value", + ) + + # Make the request + response = await client.add_context_artifacts_and_executions(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.AddContextArtifactsAndExecutionsRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.AddContextArtifactsAndExecutionsRequest, dict]): The request object. Request message for [MetadataService.AddContextArtifactsAndExecutions][google.cloud.aiplatform.v1beta1.MetadataService.AddContextArtifactsAndExecutions]. context (:class:`str`): - Required. The resource name of the - Context that the Artifacts and - Executions belong to. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context} + Required. The resource name of the Context that the + Artifacts and Executions belong to. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` This corresponds to the ``context`` field on the ``request`` instance; if ``request`` is provided, this should not be set. artifacts (:class:`Sequence[str]`): - The resource names of the Artifacts - to attribute to the Context. + The resource names of the Artifacts to attribute to the + Context. + + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact}`` This corresponds to the ``artifacts`` field on the ``request`` instance; if ``request`` is provided, this should not be set. executions (:class:`Sequence[str]`): - The resource names of the Executions - to associate with the Context. + The resource names of the Executions to associate with + the Context. + + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` This corresponds to the ``executions`` field on the ``request`` instance; if ``request`` is provided, this @@ -1364,7 +2119,7 @@ async def add_context_artifacts_and_executions( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([context, artifacts, executions]) if request is not None and has_flattened_params: @@ -1399,18 +2154,23 @@ async def add_context_artifacts_and_executions( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def add_context_children( self, - request: metadata_service.AddContextChildrenRequest = None, + request: Union[metadata_service.AddContextChildrenRequest, dict] = None, *, context: str = None, child_contexts: Sequence[str] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> metadata_service.AddContextChildrenResponse: @@ -1418,16 +2178,36 @@ async def add_context_children( of the child Contexts have already been added to the parent Context, they are simply skipped. If this call would create a cycle or cause any Context to have more than 10 parents, the - request will fail with INVALID_ARGUMENT error. + request will fail with an INVALID_ARGUMENT error. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_add_context_children(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.AddContextChildrenRequest( + context="context_value", + ) + + # Make the request + response = await client.add_context_children(request=request) + + # Handle the response + print(response) Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.AddContextChildrenRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.AddContextChildrenRequest, dict]): The request object. Request message for [MetadataService.AddContextChildren][google.cloud.aiplatform.v1beta1.MetadataService.AddContextChildren]. context (:class:`str`): - Required. The resource name of the - parent Context. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context} + Required. The resource name of the parent Context. + + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` This corresponds to the ``context`` field on the ``request`` instance; if ``request`` is provided, this @@ -1452,7 +2232,7 @@ async def add_context_children( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([context, child_contexts]) if request is not None and has_flattened_params: @@ -1485,17 +2265,24 @@ async def add_context_children( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def query_context_lineage_subgraph( self, - request: metadata_service.QueryContextLineageSubgraphRequest = None, + request: Union[ + metadata_service.QueryContextLineageSubgraphRequest, dict + ] = None, *, context: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> lineage_subgraph.LineageSubgraph: @@ -1503,15 +2290,34 @@ async def query_context_lineage_subgraph( specified Context, connected by Event edges and returned as a LineageSubgraph. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_query_context_lineage_subgraph(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.QueryContextLineageSubgraphRequest( + context="context_value", + ) + + # Make the request + response = await client.query_context_lineage_subgraph(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.QueryContextLineageSubgraphRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.QueryContextLineageSubgraphRequest, dict]): The request object. Request message for [MetadataService.QueryContextLineageSubgraph][google.cloud.aiplatform.v1beta1.MetadataService.QueryContextLineageSubgraph]. context (:class:`str`): Required. The resource name of the Context whose Artifacts and Executions should be retrieved as a LineageSubgraph. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context} + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` The request may error with FAILED_PRECONDITION if the number of Artifacts, the number of Executions, or the @@ -1535,7 +2341,7 @@ async def query_context_lineage_subgraph( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([context]) if request is not None and has_flattened_params: @@ -1566,33 +2372,56 @@ async def query_context_lineage_subgraph( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def create_execution( self, - request: metadata_service.CreateExecutionRequest = None, + request: Union[metadata_service.CreateExecutionRequest, dict] = None, *, parent: str = None, execution: gca_execution.Execution = None, execution_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_execution.Execution: r"""Creates an Execution associated with a MetadataStore. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_create_execution(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateExecutionRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_execution(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.CreateExecutionRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateExecutionRequest, dict]): The request object. Request message for [MetadataService.CreateExecution][google.cloud.aiplatform.v1beta1.MetadataService.CreateExecution]. parent (:class:`str`): - Required. The resource name of the - MetadataStore where the Execution should - be created. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore} + Required. The resource name of the MetadataStore where + the Execution should be created. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -1605,10 +2434,10 @@ async def create_execution( execution_id (:class:`str`): The {execution} portion of the resource name with the format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution} + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` If not provided, the Execution's ID will be a UUID generated by the service. Must be 4-128 characters in - length. Valid characters are /[a-z][0-9]-/. Must be + length. Valid characters are ``/[a-z][0-9]-/``. Must be unique across all Executions in the parent MetadataStore. (Otherwise the request will fail with ALREADY_EXISTS, or PERMISSION_DENIED if the caller can't @@ -1628,7 +2457,7 @@ async def create_execution( Instance of a general execution. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, execution, execution_id]) if request is not None and has_flattened_params: @@ -1663,30 +2492,54 @@ async def create_execution( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def get_execution( self, - request: metadata_service.GetExecutionRequest = None, + request: Union[metadata_service.GetExecutionRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> execution.Execution: r"""Retrieves a specific Execution. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_get_execution(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetExecutionRequest( + name="name_value", + ) + + # Make the request + response = await client.get_execution(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.GetExecutionRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.GetExecutionRequest, dict]): The request object. Request message for [MetadataService.GetExecution][google.cloud.aiplatform.v1beta1.MetadataService.GetExecution]. name (:class:`str`): - Required. The resource name of the - Execution to retrieve. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution} + Required. The resource name of the Execution to + retrieve. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -1702,7 +2555,7 @@ async def get_execution( Instance of a general execution. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1733,30 +2586,55 @@ async def get_execution( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_executions( self, - request: metadata_service.ListExecutionsRequest = None, + request: Union[metadata_service.ListExecutionsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListExecutionsAsyncPager: r"""Lists Executions in the MetadataStore. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_list_executions(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListExecutionsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_executions(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ListExecutionsRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ListExecutionsRequest, dict]): The request object. Request message for [MetadataService.ListExecutions][google.cloud.aiplatform.v1beta1.MetadataService.ListExecutions]. parent (:class:`str`): - Required. The MetadataStore whose - Executions should be listed. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore} + Required. The MetadataStore whose Executions should be + listed. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -1777,7 +2655,7 @@ async def list_executions( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1808,12 +2686,20 @@ async def list_executions( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListExecutionsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -1821,18 +2707,36 @@ async def list_executions( async def update_execution( self, - request: metadata_service.UpdateExecutionRequest = None, + request: Union[metadata_service.UpdateExecutionRequest, dict] = None, *, execution: gca_execution.Execution = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_execution.Execution: r"""Updates a stored Execution. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_update_execution(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateExecutionRequest( + ) + + # Make the request + response = await client.update_execution(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.UpdateExecutionRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.UpdateExecutionRequest, dict]): The request object. Request message for [MetadataService.UpdateExecution][google.cloud.aiplatform.v1beta1.MetadataService.UpdateExecution]. execution (:class:`google.cloud.aiplatform_v1beta1.types.Execution`): @@ -1841,14 +2745,16 @@ async def update_execution( [Execution.name][google.cloud.aiplatform.v1beta1.Execution.name] field is used to identify the Execution to be updated. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution} + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` This corresponds to the ``execution`` field on the ``request`` instance; if ``request`` is provided, this should not be set. update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): - Required. A FieldMask indicating + Optional. A FieldMask indicating which fields should be updated. + Functionality of this field is not yet + supported. This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this @@ -1864,7 +2770,7 @@ async def update_execution( Instance of a general execution. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([execution, update_mask]) if request is not None and has_flattened_params: @@ -1899,42 +2805,60 @@ async def update_execution( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response - async def add_execution_events( + async def delete_execution( self, - request: metadata_service.AddExecutionEventsRequest = None, + request: Union[metadata_service.DeleteExecutionRequest, dict] = None, *, - execution: str = None, - events: Sequence[event.Event] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> metadata_service.AddExecutionEventsResponse: - r"""Adds Events for denoting whether each Artifact was an - input or output for a given Execution. If any Events - already exist between the Execution and any of the - specified Artifacts they are simply skipped. + ) -> operation_async.AsyncOperation: + r"""Deletes an Execution. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_delete_execution(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteExecutionRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_execution(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.AddExecutionEventsRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteExecutionRequest, dict]): The request object. Request message for - [MetadataService.AddExecutionEvents][google.cloud.aiplatform.v1beta1.MetadataService.AddExecutionEvents]. - execution (:class:`str`): - Required. The resource name of the - Execution that the Events connect - Artifacts with. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution} + [MetadataService.DeleteExecution][google.cloud.aiplatform.v1beta1.MetadataService.DeleteExecution]. + name (:class:`str`): + Required. The resource name of the Execution to delete. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` - This corresponds to the ``execution`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - events (:class:`Sequence[google.cloud.aiplatform_v1beta1.types.Event]`): - The Events to create and add. - This corresponds to the ``events`` field + 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, @@ -1944,77 +2868,119 @@ async def add_execution_events( sent along with the request as metadata. Returns: - google.cloud.aiplatform_v1beta1.types.AddExecutionEventsResponse: - Response message for - [MetadataService.AddExecutionEvents][google.cloud.aiplatform.v1beta1.MetadataService.AddExecutionEvents]. + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - has_flattened_params = any([execution, events]) + 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 = metadata_service.AddExecutionEventsRequest(request) + request = metadata_service.DeleteExecutionRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. - if execution is not None: - request.execution = execution - if events: - request.events.extend(events) + 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.add_execution_events, - default_timeout=5.0, + self._client._transport.delete_execution, + default_timeout=None, 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( - (("execution", request.execution),) - ), + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, + ) # Done; return the response. return response - async def query_execution_inputs_and_outputs( + async def purge_executions( self, - request: metadata_service.QueryExecutionInputsAndOutputsRequest = None, + request: Union[metadata_service.PurgeExecutionsRequest, dict] = None, *, - execution: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> lineage_subgraph.LineageSubgraph: - r"""Obtains the set of input and output Artifacts for - this Execution, in the form of LineageSubgraph that also - contains the Execution and connecting Events. + ) -> operation_async.AsyncOperation: + r"""Purges Executions. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_purge_executions(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.PurgeExecutionsRequest( + parent="parent_value", + filter="filter_value", + ) + + # Make the request + operation = client.purge_executions(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.QueryExecutionInputsAndOutputsRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.PurgeExecutionsRequest, dict]): The request object. Request message for - [MetadataService.QueryExecutionInputsAndOutputs][google.cloud.aiplatform.v1beta1.MetadataService.QueryExecutionInputsAndOutputs]. - execution (:class:`str`): - Required. The resource name of the - Execution whose input and output - Artifacts should be retrieved as a - LineageSubgraph. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution} + [MetadataService.PurgeExecutions][google.cloud.aiplatform.v1beta1.MetadataService.PurgeExecutions]. + parent (:class:`str`): + Required. The metadata store to purge Executions from. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` - This corresponds to the ``execution`` field + 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, @@ -2024,14 +2990,237 @@ async def query_execution_inputs_and_outputs( sent along with the request as metadata. Returns: - google.cloud.aiplatform_v1beta1.types.LineageSubgraph: - A subgraph of the overall lineage - graph. Event edges connect Artifact and - Execution nodes. + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. - """ + The result type for the operation will be + :class:`google.cloud.aiplatform_v1beta1.types.PurgeExecutionsResponse` + Response message for + [MetadataService.PurgeExecutions][google.cloud.aiplatform.v1beta1.MetadataService.PurgeExecutions]. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = metadata_service.PurgeExecutionsRequest(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.purge_executions, + default_timeout=None, + 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, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + metadata_service.PurgeExecutionsResponse, + metadata_type=metadata_service.PurgeExecutionsMetadata, + ) + + # Done; return the response. + return response + + async def add_execution_events( + self, + request: Union[metadata_service.AddExecutionEventsRequest, dict] = None, + *, + execution: str = None, + events: Sequence[event.Event] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> metadata_service.AddExecutionEventsResponse: + r"""Adds Events to the specified Execution. An Event + indicates whether an Artifact was used as an input or + output for an Execution. If an Event already exists + between the Execution and the Artifact, the Event is + skipped. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_add_execution_events(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.AddExecutionEventsRequest( + execution="execution_value", + ) + + # Make the request + response = await client.add_execution_events(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.AddExecutionEventsRequest, dict]): + The request object. Request message for + [MetadataService.AddExecutionEvents][google.cloud.aiplatform.v1beta1.MetadataService.AddExecutionEvents]. + execution (:class:`str`): + Required. The resource name of the Execution that the + Events connect Artifacts with. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` + + This corresponds to the ``execution`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + events (:class:`Sequence[google.cloud.aiplatform_v1beta1.types.Event]`): + The Events to create and add. + This corresponds to the ``events`` 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: + google.cloud.aiplatform_v1beta1.types.AddExecutionEventsResponse: + Response message for + [MetadataService.AddExecutionEvents][google.cloud.aiplatform.v1beta1.MetadataService.AddExecutionEvents]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([execution, events]) + 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 = metadata_service.AddExecutionEventsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if execution is not None: + request.execution = execution + if events: + request.events.extend(events) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.add_execution_events, + default_timeout=5.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( + (("execution", request.execution),) + ), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def query_execution_inputs_and_outputs( + self, + request: Union[ + metadata_service.QueryExecutionInputsAndOutputsRequest, dict + ] = None, + *, + execution: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> lineage_subgraph.LineageSubgraph: + r"""Obtains the set of input and output Artifacts for + this Execution, in the form of LineageSubgraph that also + contains the Execution and connecting Events. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_query_execution_inputs_and_outputs(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.QueryExecutionInputsAndOutputsRequest( + execution="execution_value", + ) + + # Make the request + response = await client.query_execution_inputs_and_outputs(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.QueryExecutionInputsAndOutputsRequest, dict]): + The request object. Request message for + [MetadataService.QueryExecutionInputsAndOutputs][google.cloud.aiplatform.v1beta1.MetadataService.QueryExecutionInputsAndOutputs]. + execution (:class:`str`): + Required. The resource name of the Execution whose input + and output Artifacts should be retrieved as a + LineageSubgraph. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` + + This corresponds to the ``execution`` 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: + google.cloud.aiplatform_v1beta1.types.LineageSubgraph: + A subgraph of the overall lineage + graph. Event edges connect Artifact and + Execution nodes. + + """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([execution]) if request is not None and has_flattened_params: @@ -2064,33 +3253,60 @@ async def query_execution_inputs_and_outputs( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def create_metadata_schema( self, - request: metadata_service.CreateMetadataSchemaRequest = None, + request: Union[metadata_service.CreateMetadataSchemaRequest, dict] = None, *, parent: str = None, metadata_schema: gca_metadata_schema.MetadataSchema = None, metadata_schema_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_metadata_schema.MetadataSchema: - r"""Creates an MetadataSchema. + r"""Creates a MetadataSchema. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_create_metadata_schema(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + metadata_schema = aiplatform_v1beta1.MetadataSchema() + metadata_schema.schema = "schema_value" + + request = aiplatform_v1beta1.CreateMetadataSchemaRequest( + parent="parent_value", + metadata_schema=metadata_schema, + ) + + # Make the request + response = await client.create_metadata_schema(request=request) + + # Handle the response + print(response) Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.CreateMetadataSchemaRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateMetadataSchemaRequest, dict]): The request object. Request message for [MetadataService.CreateMetadataSchema][google.cloud.aiplatform.v1beta1.MetadataService.CreateMetadataSchema]. parent (:class:`str`): - Required. The resource name of the - MetadataStore where the MetadataSchema - should be created. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore} + Required. The resource name of the MetadataStore where + the MetadataSchema should be created. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -2105,10 +3321,10 @@ async def create_metadata_schema( metadata_schema_id (:class:`str`): The {metadata_schema} portion of the resource name with the format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/metadataSchemas/{metadataschema} + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/metadataSchemas/{metadataschema}`` If not provided, the MetadataStore's ID will be a UUID generated by the service. Must be 4-128 characters in - length. Valid characters are /[a-z][0-9]-/. Must be + length. Valid characters are ``/[a-z][0-9]-/``. Must be unique across all MetadataSchemas in the parent Location. (Otherwise the request will fail with ALREADY_EXISTS, or PERMISSION_DENIED if the caller can't @@ -2128,7 +3344,7 @@ async def create_metadata_schema( Instance of a general MetadataSchema. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, metadata_schema, metadata_schema_id]) if request is not None and has_flattened_params: @@ -2163,30 +3379,54 @@ async def create_metadata_schema( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def get_metadata_schema( self, - request: metadata_service.GetMetadataSchemaRequest = None, + request: Union[metadata_service.GetMetadataSchemaRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> metadata_schema.MetadataSchema: r"""Retrieves a specific MetadataSchema. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_get_metadata_schema(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetMetadataSchemaRequest( + name="name_value", + ) + + # Make the request + response = await client.get_metadata_schema(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.GetMetadataSchemaRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.GetMetadataSchemaRequest, dict]): The request object. Request message for [MetadataService.GetMetadataSchema][google.cloud.aiplatform.v1beta1.MetadataService.GetMetadataSchema]. name (:class:`str`): - Required. The resource name of the - MetadataSchema to retrieve. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/metadataSchemas/{metadataschema} + Required. The resource name of the MetadataSchema to + retrieve. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/metadataSchemas/{metadataschema}`` This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -2202,7 +3442,7 @@ async def get_metadata_schema( Instance of a general MetadataSchema. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -2233,31 +3473,55 @@ async def get_metadata_schema( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_metadata_schemas( self, - request: metadata_service.ListMetadataSchemasRequest = None, + request: Union[metadata_service.ListMetadataSchemasRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListMetadataSchemasAsyncPager: r"""Lists MetadataSchemas. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_list_metadata_schemas(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListMetadataSchemasRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_metadata_schemas(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ListMetadataSchemasRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ListMetadataSchemasRequest, dict]): The request object. Request message for [MetadataService.ListMetadataSchemas][google.cloud.aiplatform.v1beta1.MetadataService.ListMetadataSchemas]. parent (:class:`str`): - Required. The MetadataStore whose - MetadataSchemas should be listed. - Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore} + Required. The MetadataStore whose MetadataSchemas should + be listed. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -2278,7 +3542,7 @@ async def list_metadata_schemas( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -2309,12 +3573,20 @@ async def list_metadata_schemas( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListMetadataSchemasAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -2322,10 +3594,12 @@ async def list_metadata_schemas( async def query_artifact_lineage_subgraph( self, - request: metadata_service.QueryArtifactLineageSubgraphRequest = None, + request: Union[ + metadata_service.QueryArtifactLineageSubgraphRequest, dict + ] = None, *, artifact: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> lineage_subgraph.LineageSubgraph: @@ -2333,15 +3607,34 @@ async def query_artifact_lineage_subgraph( Artifacts and Executions connected by Event edges and returned as a LineageSubgraph. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_query_artifact_lineage_subgraph(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.QueryArtifactLineageSubgraphRequest( + artifact="artifact_value", + ) + + # Make the request + response = await client.query_artifact_lineage_subgraph(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.QueryArtifactLineageSubgraphRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.QueryArtifactLineageSubgraphRequest, dict]): The request object. Request message for [MetadataService.QueryArtifactLineageSubgraph][google.cloud.aiplatform.v1beta1.MetadataService.QueryArtifactLineageSubgraph]. artifact (:class:`str`): Required. The resource name of the Artifact whose Lineage needs to be retrieved as a LineageSubgraph. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact} + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact}`` The request may error with FAILED_PRECONDITION if the number of Artifacts, the number of Executions, or the @@ -2365,7 +3658,7 @@ async def query_artifact_lineage_subgraph( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([artifact]) if request is not None and has_flattened_params: @@ -2396,11 +3689,693 @@ async def query_artifact_lineage_subgraph( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_operations, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.delete_operation, + default_timeout=None, + 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 cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + 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 wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.wait_operation, + default_timeout=None, + 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 set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_location, + default_timeout=None, + 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 list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_locations, + default_timeout=None, + 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 __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/aiplatform_v1beta1/services/metadata_service/client.py b/google/cloud/aiplatform_v1beta1/services/metadata_service/client.py index 5c3a8871cc..06319e58f0 100644 --- a/google/cloud/aiplatform_v1beta1/services/metadata_service/client.py +++ b/google/cloud/aiplatform_v1beta1/services/metadata_service/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,22 +14,26 @@ # 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 +from typing import Dict, Mapping, 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 as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_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 +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation as gac_operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1beta1.services.metadata_service import pagers @@ -48,6 +52,10 @@ from google.cloud.aiplatform_v1beta1.types import metadata_store from google.cloud.aiplatform_v1beta1.types import metadata_store as gca_metadata_store from google.cloud.aiplatform_v1beta1.types import operation as gca_operation +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import struct_pb2 # type: ignore @@ -71,8 +79,11 @@ class MetadataServiceClientMeta(type): _transport_registry["grpc"] = MetadataServiceGrpcTransport _transport_registry["grpc_asyncio"] = MetadataServiceGrpcAsyncIOTransport - def get_transport_class(cls, label: str = None,) -> Type[MetadataServiceTransport]: - """Return an appropriate transport class. + def get_transport_class( + cls, + label: str = None, + ) -> Type[MetadataServiceTransport]: + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -95,7 +106,8 @@ class MetadataServiceClient(metaclass=MetadataServiceClientMeta): @staticmethod def _get_default_mtls_endpoint(api_endpoint): - """Convert api endpoint to mTLS endpoint. + """Converts api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. Args: @@ -129,7 +141,8 @@ def _get_default_mtls_endpoint(api_endpoint): @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -146,7 +159,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -165,18 +178,22 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> MetadataServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - MetadataServiceTransport: The transport used by the client instance. + MetadataServiceTransport: The transport used by the client + instance. """ return self._transport @staticmethod def artifact_path( - project: str, location: str, metadata_store: str, artifact: str, + project: str, + location: str, + metadata_store: str, + artifact: str, ) -> str: - """Return a fully-qualified artifact string.""" + """Returns a fully-qualified artifact string.""" return "projects/{project}/locations/{location}/metadataStores/{metadata_store}/artifacts/{artifact}".format( project=project, location=location, @@ -186,7 +203,7 @@ def artifact_path( @staticmethod def parse_artifact_path(path: str) -> Dict[str, str]: - """Parse a artifact path into its component segments.""" + """Parses a artifact path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/metadataStores/(?P.+?)/artifacts/(?P.+?)$", path, @@ -195,9 +212,12 @@ def parse_artifact_path(path: str) -> Dict[str, str]: @staticmethod def context_path( - project: str, location: str, metadata_store: str, context: str, + project: str, + location: str, + metadata_store: str, + context: str, ) -> str: - """Return a fully-qualified context string.""" + """Returns a fully-qualified context string.""" return "projects/{project}/locations/{location}/metadataStores/{metadata_store}/contexts/{context}".format( project=project, location=location, @@ -207,7 +227,7 @@ def context_path( @staticmethod def parse_context_path(path: str) -> Dict[str, str]: - """Parse a context path into its component segments.""" + """Parses a context path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/metadataStores/(?P.+?)/contexts/(?P.+?)$", path, @@ -216,9 +236,12 @@ def parse_context_path(path: str) -> Dict[str, str]: @staticmethod def execution_path( - project: str, location: str, metadata_store: str, execution: str, + project: str, + location: str, + metadata_store: str, + execution: str, ) -> str: - """Return a fully-qualified execution string.""" + """Returns a fully-qualified execution string.""" return "projects/{project}/locations/{location}/metadataStores/{metadata_store}/executions/{execution}".format( project=project, location=location, @@ -228,7 +251,7 @@ def execution_path( @staticmethod def parse_execution_path(path: str) -> Dict[str, str]: - """Parse a execution path into its component segments.""" + """Parses a execution path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/metadataStores/(?P.+?)/executions/(?P.+?)$", path, @@ -237,9 +260,12 @@ def parse_execution_path(path: str) -> Dict[str, str]: @staticmethod def metadata_schema_path( - project: str, location: str, metadata_store: str, metadata_schema: str, + project: str, + location: str, + metadata_store: str, + metadata_schema: str, ) -> str: - """Return a fully-qualified metadata_schema string.""" + """Returns a fully-qualified metadata_schema string.""" return "projects/{project}/locations/{location}/metadataStores/{metadata_store}/metadataSchemas/{metadata_schema}".format( project=project, location=location, @@ -249,7 +275,7 @@ def metadata_schema_path( @staticmethod def parse_metadata_schema_path(path: str) -> Dict[str, str]: - """Parse a metadata_schema path into its component segments.""" + """Parses a metadata_schema path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/metadataStores/(?P.+?)/metadataSchemas/(?P.+?)$", path, @@ -257,15 +283,21 @@ def parse_metadata_schema_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def metadata_store_path(project: str, location: str, metadata_store: str,) -> str: - """Return a fully-qualified metadata_store string.""" + def metadata_store_path( + project: str, + location: str, + metadata_store: str, + ) -> str: + """Returns a fully-qualified metadata_store string.""" return "projects/{project}/locations/{location}/metadataStores/{metadata_store}".format( - project=project, location=location, metadata_store=metadata_store, + project=project, + location=location, + metadata_store=metadata_store, ) @staticmethod def parse_metadata_store_path(path: str) -> Dict[str, str]: - """Parse a metadata_store path into its component segments.""" + """Parses a metadata_store path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/metadataStores/(?P.+?)$", path, @@ -273,8 +305,10 @@ def parse_metadata_store_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + def common_billing_account_path( + billing_account: str, + ) -> str: + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -286,9 +320,13 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: 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,) + def common_folder_path( + folder: str, + ) -> str: + """Returns a fully-qualified folder string.""" + return "folders/{folder}".format( + folder=folder, + ) @staticmethod def parse_common_folder_path(path: str) -> Dict[str, str]: @@ -297,9 +335,13 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: 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,) + def common_organization_path( + organization: str, + ) -> str: + """Returns a fully-qualified organization string.""" + return "organizations/{organization}".format( + organization=organization, + ) @staticmethod def parse_common_organization_path(path: str) -> Dict[str, str]: @@ -308,9 +350,13 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: 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,) + def common_project_path( + project: str, + ) -> str: + """Returns a fully-qualified project string.""" + return "projects/{project}".format( + project=project, + ) @staticmethod def parse_common_project_path(path: str) -> Dict[str, str]: @@ -319,10 +365,14 @@ def parse_common_project_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_location_path(project: str, location: str,) -> str: - """Return a fully-qualified location string.""" + def common_location_path( + project: str, + location: str, + ) -> str: + """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) @staticmethod @@ -331,6 +381,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + def __init__( self, *, @@ -339,7 +456,7 @@ def __init__( client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the metadata service client. + """Instantiates the metadata service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -381,58 +498,42 @@ def __init__( 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")) + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - client_cert_source_func = ( - mtls.default_client_cert_source() 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" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # 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, MetadataServiceTransport): # transport is a MetadataServiceTransport instance. - if credentials or client_options.credentials_file: + if credentials or client_options.credentials_file or api_key_value: 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." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + Transport = type(self).get_transport_class(transport) self._transport = Transport( credentials=credentials, @@ -442,31 +543,54 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, + always_use_jwt_access=True, ) def create_metadata_store( self, - request: metadata_service.CreateMetadataStoreRequest = None, + request: Union[metadata_service.CreateMetadataStoreRequest, dict] = None, *, parent: str = None, metadata_store: gca_metadata_store.MetadataStore = None, metadata_store_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Initializes a MetadataStore, including allocation of resources. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_create_metadata_store(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateMetadataStoreRequest( + parent="parent_value", + ) + + # Make the request + operation = client.create_metadata_store(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.CreateMetadataStoreRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateMetadataStoreRequest, dict]): The request object. Request message for [MetadataService.CreateMetadataStore][google.cloud.aiplatform.v1beta1.MetadataService.CreateMetadataStore]. parent (str): - Required. The resource name of the - Location where the MetadataStore should - be created. Format: - projects/{project}/locations/{location}/ + Required. The resource name of the Location where the + MetadataStore should be created. Format: + ``projects/{project}/locations/{location}/`` This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -481,10 +605,10 @@ def create_metadata_store( metadata_store_id (str): The {metadatastore} portion of the resource name with the format: - projects/{project}/locations/{location}/metadataStores/{metadatastore} + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` If not provided, the MetadataStore's ID will be a UUID generated by the service. Must be 4-128 characters in - length. Valid characters are /[a-z][0-9]-/. Must be + length. Valid characters are ``/[a-z][0-9]-/``. Must be unique across all MetadataStores in the parent Location. (Otherwise the request will fail with ALREADY_EXISTS, or PERMISSION_DENIED if the caller can't view the @@ -508,7 +632,7 @@ def create_metadata_store( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, metadata_store, metadata_store_id]) if request is not None and has_flattened_params: @@ -543,7 +667,12 @@ def create_metadata_store( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -558,23 +687,42 @@ def create_metadata_store( def get_metadata_store( self, - request: metadata_service.GetMetadataStoreRequest = None, + request: Union[metadata_service.GetMetadataStoreRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> metadata_store.MetadataStore: r"""Retrieves a specific MetadataStore. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_get_metadata_store(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetMetadataStoreRequest( + name="name_value", + ) + + # Make the request + response = client.get_metadata_store(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.GetMetadataStoreRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.GetMetadataStoreRequest, dict]): The request object. Request message for [MetadataService.GetMetadataStore][google.cloud.aiplatform.v1beta1.MetadataService.GetMetadataStore]. name (str): - Required. The resource name of the - MetadataStore to retrieve. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore} + Required. The resource name of the MetadataStore to + retrieve. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -593,7 +741,7 @@ def get_metadata_store( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -624,30 +772,55 @@ def get_metadata_store( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_metadata_stores( self, - request: metadata_service.ListMetadataStoresRequest = None, + request: Union[metadata_service.ListMetadataStoresRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListMetadataStoresPager: r"""Lists MetadataStores for a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_list_metadata_stores(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListMetadataStoresRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_metadata_stores(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ListMetadataStoresRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ListMetadataStoresRequest, dict]): The request object. Request message for [MetadataService.ListMetadataStores][google.cloud.aiplatform.v1beta1.MetadataService.ListMetadataStores]. parent (str): - Required. The Location whose - MetadataStores should be listed. Format: - projects/{project}/locations/{location} + Required. The Location whose MetadataStores should be + listed. Format: + ``projects/{project}/locations/{location}`` This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -668,7 +841,7 @@ def list_metadata_stores( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -699,12 +872,20 @@ def list_metadata_stores( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListMetadataStoresPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -712,23 +893,47 @@ def list_metadata_stores( def delete_metadata_store( self, - request: metadata_service.DeleteMetadataStoreRequest = None, + request: Union[metadata_service.DeleteMetadataStoreRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: - r"""Deletes a single MetadataStore. + r"""Deletes a single MetadataStore and all its child + resources (Artifacts, Executions, and Contexts). + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_delete_metadata_store(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteMetadataStoreRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_metadata_store(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) Args: - request (google.cloud.aiplatform_v1beta1.types.DeleteMetadataStoreRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteMetadataStoreRequest, dict]): The request object. Request message for [MetadataService.DeleteMetadataStore][google.cloud.aiplatform.v1beta1.MetadataService.DeleteMetadataStore]. name (str): - Required. The resource name of the - MetadataStore to delete. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore} + Required. The resource name of the MetadataStore to + delete. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -759,7 +964,7 @@ def delete_metadata_store( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -790,7 +995,12 @@ def delete_metadata_store( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -805,26 +1015,44 @@ def delete_metadata_store( def create_artifact( self, - request: metadata_service.CreateArtifactRequest = None, + request: Union[metadata_service.CreateArtifactRequest, dict] = None, *, parent: str = None, artifact: gca_artifact.Artifact = None, artifact_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_artifact.Artifact: r"""Creates an Artifact associated with a MetadataStore. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_create_artifact(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateArtifactRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_artifact(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.CreateArtifactRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateArtifactRequest, dict]): The request object. Request message for [MetadataService.CreateArtifact][google.cloud.aiplatform.v1beta1.MetadataService.CreateArtifact]. parent (str): - Required. The resource name of the - MetadataStore where the Artifact should - be created. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore} + Required. The resource name of the MetadataStore where + the Artifact should be created. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -837,10 +1065,10 @@ def create_artifact( artifact_id (str): The {artifact} portion of the resource name with the format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact} + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact}`` If not provided, the Artifact's ID will be a UUID generated by the service. Must be 4-128 characters in - length. Valid characters are /[a-z][0-9]-/. Must be + length. Valid characters are ``/[a-z][0-9]-/``. Must be unique across all Artifacts in the parent MetadataStore. (Otherwise the request will fail with ALREADY_EXISTS, or PERMISSION_DENIED if the caller can't view the @@ -860,7 +1088,7 @@ def create_artifact( Instance of a general artifact. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, artifact, artifact_id]) if request is not None and has_flattened_params: @@ -895,30 +1123,54 @@ def create_artifact( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def get_artifact( self, - request: metadata_service.GetArtifactRequest = None, + request: Union[metadata_service.GetArtifactRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> artifact.Artifact: r"""Retrieves a specific Artifact. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_get_artifact(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetArtifactRequest( + name="name_value", + ) + + # Make the request + response = client.get_artifact(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.GetArtifactRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.GetArtifactRequest, dict]): The request object. Request message for [MetadataService.GetArtifact][google.cloud.aiplatform.v1beta1.MetadataService.GetArtifact]. name (str): - Required. The resource name of the - Artifact to retrieve. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact} + Required. The resource name of the Artifact to retrieve. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact}`` This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -934,7 +1186,7 @@ def get_artifact( Instance of a general artifact. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -965,30 +1217,55 @@ def get_artifact( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_artifacts( self, - request: metadata_service.ListArtifactsRequest = None, + request: Union[metadata_service.ListArtifactsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListArtifactsPager: r"""Lists Artifacts in the MetadataStore. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_list_artifacts(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListArtifactsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_artifacts(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ListArtifactsRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ListArtifactsRequest, dict]): The request object. Request message for [MetadataService.ListArtifacts][google.cloud.aiplatform.v1beta1.MetadataService.ListArtifacts]. parent (str): - Required. The MetadataStore whose - Artifacts should be listed. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore} + Required. The MetadataStore whose Artifacts should be + listed. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -1009,7 +1286,7 @@ def list_artifacts( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1040,12 +1317,20 @@ def list_artifacts( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListArtifactsPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -1053,18 +1338,36 @@ def list_artifacts( def update_artifact( self, - request: metadata_service.UpdateArtifactRequest = None, + request: Union[metadata_service.UpdateArtifactRequest, dict] = None, *, artifact: gca_artifact.Artifact = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_artifact.Artifact: r"""Updates a stored Artifact. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_update_artifact(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateArtifactRequest( + ) + + # Make the request + response = client.update_artifact(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.UpdateArtifactRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.UpdateArtifactRequest, dict]): The request object. Request message for [MetadataService.UpdateArtifact][google.cloud.aiplatform.v1beta1.MetadataService.UpdateArtifact]. artifact (google.cloud.aiplatform_v1beta1.types.Artifact): @@ -1073,14 +1376,16 @@ def update_artifact( [Artifact.name][google.cloud.aiplatform.v1beta1.Artifact.name] field is used to identify the Artifact to be updated. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact} + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact}`` This corresponds to the ``artifact`` field on the ``request`` instance; if ``request`` is provided, this should not be set. update_mask (google.protobuf.field_mask_pb2.FieldMask): - Required. A FieldMask indicating + Optional. A FieldMask indicating which fields should be updated. + Functionality of this field is not yet + supported. This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this @@ -1096,7 +1401,7 @@ def update_artifact( Instance of a general artifact. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([artifact, update_mask]) if request is not None and has_flattened_params: @@ -1131,55 +1436,60 @@ def update_artifact( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response - def create_context( + def delete_artifact( self, - request: metadata_service.CreateContextRequest = None, + request: Union[metadata_service.DeleteArtifactRequest, dict] = None, *, - parent: str = None, - context: gca_context.Context = None, - context_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> gca_context.Context: - r"""Creates a Context associated with a MetadataStore. + ) -> gac_operation.Operation: + r"""Deletes an Artifact. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_delete_artifact(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteArtifactRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_artifact(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) Args: - request (google.cloud.aiplatform_v1beta1.types.CreateContextRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteArtifactRequest, dict]): The request object. Request message for - [MetadataService.CreateContext][google.cloud.aiplatform.v1beta1.MetadataService.CreateContext]. - parent (str): - Required. The resource name of the - MetadataStore where the Context should - be created. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore} - - This corresponds to the ``parent`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - context (google.cloud.aiplatform_v1beta1.types.Context): - Required. The Context to create. - This corresponds to the ``context`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - context_id (str): - The {context} portion of the resource name with the - format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context} - If not provided, the Context's ID will be a UUID - generated by the service. Must be 4-128 characters in - length. Valid characters are /[a-z][0-9]-/. Must be - unique across all Contexts in the parent MetadataStore. - (Otherwise the request will fail with ALREADY_EXISTS, or - PERMISSION_DENIED if the caller can't view the - preexisting Context.) + [MetadataService.DeleteArtifact][google.cloud.aiplatform.v1beta1.MetadataService.DeleteArtifact]. + name (str): + Required. The resource name of the Artifact to delete. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact}`` - This corresponds to the ``context_id`` field + 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, @@ -1189,13 +1499,28 @@ def create_context( sent along with the request as metadata. Returns: - google.cloud.aiplatform_v1beta1.types.Context: - Instance of a general context. + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. + """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, context, context_id]) + 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 " @@ -1203,57 +1528,90 @@ def create_context( ) # Minor optimization to avoid making a copy if the user passes - # in a metadata_service.CreateContextRequest. + # in a metadata_service.DeleteArtifactRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. - if not isinstance(request, metadata_service.CreateContextRequest): - request = metadata_service.CreateContextRequest(request) + if not isinstance(request, metadata_service.DeleteArtifactRequest): + request = metadata_service.DeleteArtifactRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: - request.parent = parent - if context is not None: - request.context = context - if context_id is not None: - request.context_id = context_id + 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.create_context] + rpc = self._transport._wrapped_methods[self._transport.delete_artifact] # 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),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, + ) # Done; return the response. return response - def get_context( + def purge_artifacts( self, - request: metadata_service.GetContextRequest = None, + request: Union[metadata_service.PurgeArtifactsRequest, dict] = None, *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> context.Context: - r"""Retrieves a specific Context. + ) -> gac_operation.Operation: + r"""Purges Artifacts. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_purge_artifacts(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.PurgeArtifactsRequest( + parent="parent_value", + filter="filter_value", + ) + + # Make the request + operation = client.purge_artifacts(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) Args: - request (google.cloud.aiplatform_v1beta1.types.GetContextRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.PurgeArtifactsRequest, dict]): The request object. Request message for - [MetadataService.GetContext][google.cloud.aiplatform.v1beta1.MetadataService.GetContext]. - name (str): - Required. The resource name of the - Context to retrieve. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context} + [MetadataService.PurgeArtifacts][google.cloud.aiplatform.v1beta1.MetadataService.PurgeArtifacts]. + parent (str): + Required. The metadata store to purge Artifacts from. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` - This corresponds to the ``name`` field + 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, @@ -1263,13 +1621,19 @@ def get_context( sent along with the request as metadata. Returns: - google.cloud.aiplatform_v1beta1.types.Context: - Instance of a general context. + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.aiplatform_v1beta1.types.PurgeArtifactsResponse` + Response message for + [MetadataService.PurgeArtifacts][google.cloud.aiplatform.v1beta1.MetadataService.PurgeArtifacts]. + """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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]) + 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 " @@ -1277,51 +1641,298 @@ def get_context( ) # Minor optimization to avoid making a copy if the user passes - # in a metadata_service.GetContextRequest. + # in a metadata_service.PurgeArtifactsRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. - if not isinstance(request, metadata_service.GetContextRequest): - request = metadata_service.GetContextRequest(request) + if not isinstance(request, metadata_service.PurgeArtifactsRequest): + request = metadata_service.PurgeArtifactsRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: - request.name = name + 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.get_context] + rpc = self._transport._wrapped_methods[self._transport.purge_artifacts] # 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),)), + 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 + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + metadata_service.PurgeArtifactsResponse, + metadata_type=metadata_service.PurgeArtifactsMetadata, + ) + + # Done; return the response. + return response + + def create_context( + self, + request: Union[metadata_service.CreateContextRequest, dict] = None, + *, + parent: str = None, + context: gca_context.Context = None, + context_id: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gca_context.Context: + r"""Creates a Context associated with a MetadataStore. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_create_context(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateContextRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_context(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.CreateContextRequest, dict]): + The request object. Request message for + [MetadataService.CreateContext][google.cloud.aiplatform.v1beta1.MetadataService.CreateContext]. + parent (str): + Required. The resource name of the MetadataStore where + the Context should be created. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + context (google.cloud.aiplatform_v1beta1.types.Context): + Required. The Context to create. + This corresponds to the ``context`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + context_id (str): + The {context} portion of the resource name with the + format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}``. + If not provided, the Context's ID will be a UUID + generated by the service. Must be 4-128 characters in + length. Valid characters are ``/[a-z][0-9]-/``. Must be + unique across all Contexts in the parent MetadataStore. + (Otherwise the request will fail with ALREADY_EXISTS, or + PERMISSION_DENIED if the caller can't view the + preexisting Context.) + + This corresponds to the ``context_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: + google.cloud.aiplatform_v1beta1.types.Context: + Instance of a general context. + """ + # Create or coerce a protobuf request object. + # Quick 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, context, context_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 metadata_service.CreateContextRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, metadata_service.CreateContextRequest): + request = metadata_service.CreateContextRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if context is not None: + request.context = context + if context_id is not None: + request.context_id = context_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_context] + + # 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 get_context( + self, + request: Union[metadata_service.GetContextRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> context.Context: + r"""Retrieves a specific Context. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_get_context(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetContextRequest( + name="name_value", + ) + + # Make the request + response = client.get_context(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.GetContextRequest, dict]): + The request object. Request message for + [MetadataService.GetContext][google.cloud.aiplatform.v1beta1.MetadataService.GetContext]. + name (str): + Required. The resource name of the Context to retrieve. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` + + 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: + google.cloud.aiplatform_v1beta1.types.Context: + Instance of a general context. + """ + # Create or coerce a protobuf request object. + # Quick 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 metadata_service.GetContextRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, metadata_service.GetContextRequest): + request = metadata_service.GetContextRequest(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_context] + + # 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 list_contexts( self, - request: metadata_service.ListContextsRequest = None, + request: Union[metadata_service.ListContextsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListContextsPager: r"""Lists Contexts on the MetadataStore. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_list_contexts(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListContextsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_contexts(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ListContextsRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ListContextsRequest, dict]): The request object. Request message for [MetadataService.ListContexts][google.cloud.aiplatform.v1beta1.MetadataService.ListContexts] parent (str): - Required. The MetadataStore whose - Contexts should be listed. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore} + Required. The MetadataStore whose Contexts should be + listed. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -1342,7 +1953,7 @@ def list_contexts( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1373,12 +1984,20 @@ def list_contexts( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListContextsPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -1386,18 +2005,36 @@ def list_contexts( def update_context( self, - request: metadata_service.UpdateContextRequest = None, + request: Union[metadata_service.UpdateContextRequest, dict] = None, *, context: gca_context.Context = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_context.Context: r"""Updates a stored Context. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_update_context(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateContextRequest( + ) + + # Make the request + response = client.update_context(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.UpdateContextRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.UpdateContextRequest, dict]): The request object. Request message for [MetadataService.UpdateContext][google.cloud.aiplatform.v1beta1.MetadataService.UpdateContext]. context (google.cloud.aiplatform_v1beta1.types.Context): @@ -1405,14 +2042,16 @@ def update_context( [Context.name][google.cloud.aiplatform.v1beta1.Context.name] field is used to identify the Context to be updated. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context} + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` This corresponds to the ``context`` field on the ``request`` instance; if ``request`` is provided, this should not be set. update_mask (google.protobuf.field_mask_pb2.FieldMask): - Required. A FieldMask indicating + Optional. A FieldMask indicating which fields should be updated. + Functionality of this field is not yet + supported. This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this @@ -1428,7 +2067,7 @@ def update_context( Instance of a general context. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([context, update_mask]) if request is not None and has_flattened_params: @@ -1463,30 +2102,58 @@ def update_context( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def delete_context( self, - request: metadata_service.DeleteContextRequest = None, + request: Union[metadata_service.DeleteContextRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Deletes a stored Context. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_delete_context(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteContextRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_context(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.DeleteContextRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteContextRequest, dict]): The request object. Request message for [MetadataService.DeleteContext][google.cloud.aiplatform.v1beta1.MetadataService.DeleteContext]. name (str): - Required. The resource name of the - Context to retrieve. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context} + Required. The resource name of the Context to delete. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -1517,7 +2184,7 @@ def delete_context( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1548,7 +2215,12 @@ def delete_context( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -1561,46 +2233,51 @@ def delete_context( # Done; return the response. return response - def add_context_artifacts_and_executions( + def purge_contexts( self, - request: metadata_service.AddContextArtifactsAndExecutionsRequest = None, + request: Union[metadata_service.PurgeContextsRequest, dict] = None, *, - context: str = None, - artifacts: Sequence[str] = None, - executions: Sequence[str] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> metadata_service.AddContextArtifactsAndExecutionsResponse: - r"""Adds a set of Artifacts and Executions to a Context. - If any of the Artifacts or Executions have already been - added to a Context, they are simply skipped. + ) -> gac_operation.Operation: + r"""Purges Contexts. - Args: - request (google.cloud.aiplatform_v1beta1.types.AddContextArtifactsAndExecutionsRequest): - The request object. Request message for - [MetadataService.AddContextArtifactsAndExecutions][google.cloud.aiplatform.v1beta1.MetadataService.AddContextArtifactsAndExecutions]. - context (str): - Required. The resource name of the - Context that the Artifacts and - Executions belong to. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context} + .. code-block:: python - This corresponds to the ``context`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - artifacts (Sequence[str]): - The resource names of the Artifacts - to attribute to the Context. + from google.cloud import aiplatform_v1beta1 - This corresponds to the ``artifacts`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - executions (Sequence[str]): - The resource names of the Executions - to associate with the Context. + def sample_purge_contexts(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() - This corresponds to the ``executions`` field + # Initialize request argument(s) + request = aiplatform_v1beta1.PurgeContextsRequest( + parent="parent_value", + filter="filter_value", + ) + + # Make the request + operation = client.purge_contexts(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.PurgeContextsRequest, dict]): + The request object. Request message for + [MetadataService.PurgeContexts][google.cloud.aiplatform.v1beta1.MetadataService.PurgeContexts]. + parent (str): + Required. The metadata store to purge Contexts from. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + + 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, @@ -1610,15 +2287,19 @@ def add_context_artifacts_and_executions( sent along with the request as metadata. Returns: - google.cloud.aiplatform_v1beta1.types.AddContextArtifactsAndExecutionsResponse: + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.aiplatform_v1beta1.types.PurgeContextsResponse` Response message for - [MetadataService.AddContextArtifactsAndExecutions][google.cloud.aiplatform.v1beta1.MetadataService.AddContextArtifactsAndExecutions]. + [MetadataService.PurgeContexts][google.cloud.aiplatform.v1beta1.MetadataService.PurgeContexts]. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - has_flattened_params = any([context, artifacts, executions]) + 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 " @@ -1626,21 +2307,151 @@ def add_context_artifacts_and_executions( ) # Minor optimization to avoid making a copy if the user passes - # in a metadata_service.AddContextArtifactsAndExecutionsRequest. + # in a metadata_service.PurgeContextsRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. - if not isinstance( - request, metadata_service.AddContextArtifactsAndExecutionsRequest - ): - request = metadata_service.AddContextArtifactsAndExecutionsRequest(request) + if not isinstance(request, metadata_service.PurgeContextsRequest): + request = metadata_service.PurgeContextsRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. - if context is not None: - request.context = context - if artifacts is not None: - request.artifacts = artifacts - if executions is not None: - request.executions = executions + 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.purge_contexts] + + # 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, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + metadata_service.PurgeContextsResponse, + metadata_type=metadata_service.PurgeContextsMetadata, + ) + + # Done; return the response. + return response + + def add_context_artifacts_and_executions( + self, + request: Union[ + metadata_service.AddContextArtifactsAndExecutionsRequest, dict + ] = None, + *, + context: str = None, + artifacts: Sequence[str] = None, + executions: Sequence[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> metadata_service.AddContextArtifactsAndExecutionsResponse: + r"""Adds a set of Artifacts and Executions to a Context. + If any of the Artifacts or Executions have already been + added to a Context, they are simply skipped. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_add_context_artifacts_and_executions(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.AddContextArtifactsAndExecutionsRequest( + context="context_value", + ) + + # Make the request + response = client.add_context_artifacts_and_executions(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.AddContextArtifactsAndExecutionsRequest, dict]): + The request object. Request message for + [MetadataService.AddContextArtifactsAndExecutions][google.cloud.aiplatform.v1beta1.MetadataService.AddContextArtifactsAndExecutions]. + context (str): + Required. The resource name of the Context that the + Artifacts and Executions belong to. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` + + This corresponds to the ``context`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + artifacts (Sequence[str]): + The resource names of the Artifacts to attribute to the + Context. + + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact}`` + + This corresponds to the ``artifacts`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + executions (Sequence[str]): + The resource names of the Executions to associate with + the Context. + + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` + + This corresponds to the ``executions`` 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: + google.cloud.aiplatform_v1beta1.types.AddContextArtifactsAndExecutionsResponse: + Response message for + [MetadataService.AddContextArtifactsAndExecutions][google.cloud.aiplatform.v1beta1.MetadataService.AddContextArtifactsAndExecutions]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([context, artifacts, executions]) + 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 metadata_service.AddContextArtifactsAndExecutionsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, metadata_service.AddContextArtifactsAndExecutionsRequest + ): + request = metadata_service.AddContextArtifactsAndExecutionsRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if context is not None: + request.context = context + if artifacts is not None: + request.artifacts = artifacts + if executions is not None: + request.executions = executions # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1655,18 +2466,23 @@ def add_context_artifacts_and_executions( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def add_context_children( self, - request: metadata_service.AddContextChildrenRequest = None, + request: Union[metadata_service.AddContextChildrenRequest, dict] = None, *, context: str = None, child_contexts: Sequence[str] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> metadata_service.AddContextChildrenResponse: @@ -1674,16 +2490,36 @@ def add_context_children( of the child Contexts have already been added to the parent Context, they are simply skipped. If this call would create a cycle or cause any Context to have more than 10 parents, the - request will fail with INVALID_ARGUMENT error. + request will fail with an INVALID_ARGUMENT error. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_add_context_children(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.AddContextChildrenRequest( + context="context_value", + ) + + # Make the request + response = client.add_context_children(request=request) + + # Handle the response + print(response) Args: - request (google.cloud.aiplatform_v1beta1.types.AddContextChildrenRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.AddContextChildrenRequest, dict]): The request object. Request message for [MetadataService.AddContextChildren][google.cloud.aiplatform.v1beta1.MetadataService.AddContextChildren]. context (str): - Required. The resource name of the - parent Context. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context} + Required. The resource name of the parent Context. + + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` This corresponds to the ``context`` field on the ``request`` instance; if ``request`` is provided, this @@ -1708,7 +2544,7 @@ def add_context_children( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([context, child_contexts]) if request is not None and has_flattened_params: @@ -1741,17 +2577,24 @@ def add_context_children( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def query_context_lineage_subgraph( self, - request: metadata_service.QueryContextLineageSubgraphRequest = None, + request: Union[ + metadata_service.QueryContextLineageSubgraphRequest, dict + ] = None, *, context: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> lineage_subgraph.LineageSubgraph: @@ -1759,15 +2602,34 @@ def query_context_lineage_subgraph( specified Context, connected by Event edges and returned as a LineageSubgraph. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_query_context_lineage_subgraph(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.QueryContextLineageSubgraphRequest( + context="context_value", + ) + + # Make the request + response = client.query_context_lineage_subgraph(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.QueryContextLineageSubgraphRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.QueryContextLineageSubgraphRequest, dict]): The request object. Request message for [MetadataService.QueryContextLineageSubgraph][google.cloud.aiplatform.v1beta1.MetadataService.QueryContextLineageSubgraph]. context (str): Required. The resource name of the Context whose Artifacts and Executions should be retrieved as a LineageSubgraph. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context} + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` The request may error with FAILED_PRECONDITION if the number of Artifacts, the number of Executions, or the @@ -1791,7 +2653,7 @@ def query_context_lineage_subgraph( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([context]) if request is not None and has_flattened_params: @@ -1824,33 +2686,56 @@ def query_context_lineage_subgraph( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def create_execution( self, - request: metadata_service.CreateExecutionRequest = None, + request: Union[metadata_service.CreateExecutionRequest, dict] = None, *, parent: str = None, execution: gca_execution.Execution = None, execution_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_execution.Execution: r"""Creates an Execution associated with a MetadataStore. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_create_execution(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateExecutionRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_execution(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.CreateExecutionRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateExecutionRequest, dict]): The request object. Request message for [MetadataService.CreateExecution][google.cloud.aiplatform.v1beta1.MetadataService.CreateExecution]. parent (str): - Required. The resource name of the - MetadataStore where the Execution should - be created. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore} + Required. The resource name of the MetadataStore where + the Execution should be created. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -1863,10 +2748,10 @@ def create_execution( execution_id (str): The {execution} portion of the resource name with the format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution} + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` If not provided, the Execution's ID will be a UUID generated by the service. Must be 4-128 characters in - length. Valid characters are /[a-z][0-9]-/. Must be + length. Valid characters are ``/[a-z][0-9]-/``. Must be unique across all Executions in the parent MetadataStore. (Otherwise the request will fail with ALREADY_EXISTS, or PERMISSION_DENIED if the caller can't @@ -1886,7 +2771,7 @@ def create_execution( Instance of a general execution. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, execution, execution_id]) if request is not None and has_flattened_params: @@ -1921,30 +2806,54 @@ def create_execution( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def get_execution( self, - request: metadata_service.GetExecutionRequest = None, + request: Union[metadata_service.GetExecutionRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> execution.Execution: r"""Retrieves a specific Execution. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_get_execution(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetExecutionRequest( + name="name_value", + ) + + # Make the request + response = client.get_execution(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.GetExecutionRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.GetExecutionRequest, dict]): The request object. Request message for [MetadataService.GetExecution][google.cloud.aiplatform.v1beta1.MetadataService.GetExecution]. name (str): - Required. The resource name of the - Execution to retrieve. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution} + Required. The resource name of the Execution to + retrieve. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -1960,7 +2869,7 @@ def get_execution( Instance of a general execution. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1991,30 +2900,55 @@ def get_execution( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_executions( self, - request: metadata_service.ListExecutionsRequest = None, + request: Union[metadata_service.ListExecutionsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListExecutionsPager: r"""Lists Executions in the MetadataStore. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_list_executions(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListExecutionsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_executions(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ListExecutionsRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ListExecutionsRequest, dict]): The request object. Request message for [MetadataService.ListExecutions][google.cloud.aiplatform.v1beta1.MetadataService.ListExecutions]. parent (str): - Required. The MetadataStore whose - Executions should be listed. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore} + Required. The MetadataStore whose Executions should be + listed. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -2035,7 +2969,7 @@ def list_executions( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -2066,12 +3000,20 @@ def list_executions( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListExecutionsPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -2079,18 +3021,36 @@ def list_executions( def update_execution( self, - request: metadata_service.UpdateExecutionRequest = None, + request: Union[metadata_service.UpdateExecutionRequest, dict] = None, *, execution: gca_execution.Execution = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_execution.Execution: r"""Updates a stored Execution. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_update_execution(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateExecutionRequest( + ) + + # Make the request + response = client.update_execution(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.UpdateExecutionRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.UpdateExecutionRequest, dict]): The request object. Request message for [MetadataService.UpdateExecution][google.cloud.aiplatform.v1beta1.MetadataService.UpdateExecution]. execution (google.cloud.aiplatform_v1beta1.types.Execution): @@ -2099,14 +3059,16 @@ def update_execution( [Execution.name][google.cloud.aiplatform.v1beta1.Execution.name] field is used to identify the Execution to be updated. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution} + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` This corresponds to the ``execution`` field on the ``request`` instance; if ``request`` is provided, this should not be set. update_mask (google.protobuf.field_mask_pb2.FieldMask): - Required. A FieldMask indicating + Optional. A FieldMask indicating which fields should be updated. + Functionality of this field is not yet + supported. This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this @@ -2122,7 +3084,7 @@ def update_execution( Instance of a general execution. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([execution, update_mask]) if request is not None and has_flattened_params: @@ -2157,42 +3119,60 @@ def update_execution( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response - def add_execution_events( + def delete_execution( self, - request: metadata_service.AddExecutionEventsRequest = None, + request: Union[metadata_service.DeleteExecutionRequest, dict] = None, *, - execution: str = None, - events: Sequence[event.Event] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> metadata_service.AddExecutionEventsResponse: - r"""Adds Events for denoting whether each Artifact was an - input or output for a given Execution. If any Events - already exist between the Execution and any of the - specified Artifacts they are simply skipped. + ) -> gac_operation.Operation: + r"""Deletes an Execution. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_delete_execution(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteExecutionRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_execution(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) Args: - request (google.cloud.aiplatform_v1beta1.types.AddExecutionEventsRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteExecutionRequest, dict]): The request object. Request message for - [MetadataService.AddExecutionEvents][google.cloud.aiplatform.v1beta1.MetadataService.AddExecutionEvents]. - execution (str): - Required. The resource name of the - Execution that the Events connect - Artifacts with. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution} + [MetadataService.DeleteExecution][google.cloud.aiplatform.v1beta1.MetadataService.DeleteExecution]. + name (str): + Required. The resource name of the Execution to delete. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` - This corresponds to the ``execution`` field - on the ``request`` instance; if ``request`` is provided, this - should not be set. - events (Sequence[google.cloud.aiplatform_v1beta1.types.Event]): - The Events to create and add. - This corresponds to the ``events`` field + 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, @@ -2202,15 +3182,28 @@ def add_execution_events( sent along with the request as metadata. Returns: - google.cloud.aiplatform_v1beta1.types.AddExecutionEventsResponse: - Response message for - [MetadataService.AddExecutionEvents][google.cloud.aiplatform.v1beta1.MetadataService.AddExecutionEvents]. + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - has_flattened_params = any([execution, events]) + 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 " @@ -2218,61 +3211,90 @@ def add_execution_events( ) # Minor optimization to avoid making a copy if the user passes - # in a metadata_service.AddExecutionEventsRequest. + # in a metadata_service.DeleteExecutionRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. - if not isinstance(request, metadata_service.AddExecutionEventsRequest): - request = metadata_service.AddExecutionEventsRequest(request) + if not isinstance(request, metadata_service.DeleteExecutionRequest): + request = metadata_service.DeleteExecutionRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. - if execution is not None: - request.execution = execution - if events is not None: - request.events = events + 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.add_execution_events] + rpc = self._transport._wrapped_methods[self._transport.delete_execution] # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("execution", request.execution),) - ), + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, + ) # Done; return the response. return response - def query_execution_inputs_and_outputs( + def purge_executions( self, - request: metadata_service.QueryExecutionInputsAndOutputsRequest = None, + request: Union[metadata_service.PurgeExecutionsRequest, dict] = None, *, - execution: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> lineage_subgraph.LineageSubgraph: - r"""Obtains the set of input and output Artifacts for - this Execution, in the form of LineageSubgraph that also - contains the Execution and connecting Events. + ) -> gac_operation.Operation: + r"""Purges Executions. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_purge_executions(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.PurgeExecutionsRequest( + parent="parent_value", + filter="filter_value", + ) + + # Make the request + operation = client.purge_executions(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) Args: - request (google.cloud.aiplatform_v1beta1.types.QueryExecutionInputsAndOutputsRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.PurgeExecutionsRequest, dict]): The request object. Request message for - [MetadataService.QueryExecutionInputsAndOutputs][google.cloud.aiplatform.v1beta1.MetadataService.QueryExecutionInputsAndOutputs]. - execution (str): - Required. The resource name of the - Execution whose input and output - Artifacts should be retrieved as a - LineageSubgraph. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution} + [MetadataService.PurgeExecutions][google.cloud.aiplatform.v1beta1.MetadataService.PurgeExecutions]. + parent (str): + Required. The metadata store to purge Executions from. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` - This corresponds to the ``execution`` field + 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, @@ -2282,16 +3304,239 @@ def query_execution_inputs_and_outputs( sent along with the request as metadata. Returns: - google.cloud.aiplatform_v1beta1.types.LineageSubgraph: - A subgraph of the overall lineage - graph. Event edges connect Artifact and - Execution nodes. + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.aiplatform_v1beta1.types.PurgeExecutionsResponse` + Response message for + [MetadataService.PurgeExecutions][google.cloud.aiplatform.v1beta1.MetadataService.PurgeExecutions]. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - has_flattened_params = any([execution]) + 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 metadata_service.PurgeExecutionsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, metadata_service.PurgeExecutionsRequest): + request = metadata_service.PurgeExecutionsRequest(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.purge_executions] + + # 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, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + metadata_service.PurgeExecutionsResponse, + metadata_type=metadata_service.PurgeExecutionsMetadata, + ) + + # Done; return the response. + return response + + def add_execution_events( + self, + request: Union[metadata_service.AddExecutionEventsRequest, dict] = None, + *, + execution: str = None, + events: Sequence[event.Event] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> metadata_service.AddExecutionEventsResponse: + r"""Adds Events to the specified Execution. An Event + indicates whether an Artifact was used as an input or + output for an Execution. If an Event already exists + between the Execution and the Artifact, the Event is + skipped. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_add_execution_events(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.AddExecutionEventsRequest( + execution="execution_value", + ) + + # Make the request + response = client.add_execution_events(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.AddExecutionEventsRequest, dict]): + The request object. Request message for + [MetadataService.AddExecutionEvents][google.cloud.aiplatform.v1beta1.MetadataService.AddExecutionEvents]. + execution (str): + Required. The resource name of the Execution that the + Events connect Artifacts with. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` + + This corresponds to the ``execution`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + events (Sequence[google.cloud.aiplatform_v1beta1.types.Event]): + The Events to create and add. + This corresponds to the ``events`` 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: + google.cloud.aiplatform_v1beta1.types.AddExecutionEventsResponse: + Response message for + [MetadataService.AddExecutionEvents][google.cloud.aiplatform.v1beta1.MetadataService.AddExecutionEvents]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([execution, events]) + 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 metadata_service.AddExecutionEventsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, metadata_service.AddExecutionEventsRequest): + request = metadata_service.AddExecutionEventsRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if execution is not None: + request.execution = execution + if events is not None: + request.events = events + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.add_execution_events] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("execution", request.execution),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def query_execution_inputs_and_outputs( + self, + request: Union[ + metadata_service.QueryExecutionInputsAndOutputsRequest, dict + ] = None, + *, + execution: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> lineage_subgraph.LineageSubgraph: + r"""Obtains the set of input and output Artifacts for + this Execution, in the form of LineageSubgraph that also + contains the Execution and connecting Events. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_query_execution_inputs_and_outputs(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.QueryExecutionInputsAndOutputsRequest( + execution="execution_value", + ) + + # Make the request + response = client.query_execution_inputs_and_outputs(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.QueryExecutionInputsAndOutputsRequest, dict]): + The request object. Request message for + [MetadataService.QueryExecutionInputsAndOutputs][google.cloud.aiplatform.v1beta1.MetadataService.QueryExecutionInputsAndOutputs]. + execution (str): + Required. The resource name of the Execution whose input + and output Artifacts should be retrieved as a + LineageSubgraph. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` + + This corresponds to the ``execution`` 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: + google.cloud.aiplatform_v1beta1.types.LineageSubgraph: + A subgraph of the overall lineage + graph. Event edges connect Artifact and + Execution nodes. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([execution]) if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " @@ -2326,33 +3571,60 @@ def query_execution_inputs_and_outputs( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def create_metadata_schema( self, - request: metadata_service.CreateMetadataSchemaRequest = None, + request: Union[metadata_service.CreateMetadataSchemaRequest, dict] = None, *, parent: str = None, metadata_schema: gca_metadata_schema.MetadataSchema = None, metadata_schema_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_metadata_schema.MetadataSchema: - r"""Creates an MetadataSchema. + r"""Creates a MetadataSchema. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_create_metadata_schema(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + metadata_schema = aiplatform_v1beta1.MetadataSchema() + metadata_schema.schema = "schema_value" + + request = aiplatform_v1beta1.CreateMetadataSchemaRequest( + parent="parent_value", + metadata_schema=metadata_schema, + ) + + # Make the request + response = client.create_metadata_schema(request=request) + + # Handle the response + print(response) Args: - request (google.cloud.aiplatform_v1beta1.types.CreateMetadataSchemaRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateMetadataSchemaRequest, dict]): The request object. Request message for [MetadataService.CreateMetadataSchema][google.cloud.aiplatform.v1beta1.MetadataService.CreateMetadataSchema]. parent (str): - Required. The resource name of the - MetadataStore where the MetadataSchema - should be created. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore} + Required. The resource name of the MetadataStore where + the MetadataSchema should be created. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -2367,10 +3639,10 @@ def create_metadata_schema( metadata_schema_id (str): The {metadata_schema} portion of the resource name with the format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/metadataSchemas/{metadataschema} + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/metadataSchemas/{metadataschema}`` If not provided, the MetadataStore's ID will be a UUID generated by the service. Must be 4-128 characters in - length. Valid characters are /[a-z][0-9]-/. Must be + length. Valid characters are ``/[a-z][0-9]-/``. Must be unique across all MetadataSchemas in the parent Location. (Otherwise the request will fail with ALREADY_EXISTS, or PERMISSION_DENIED if the caller can't @@ -2390,7 +3662,7 @@ def create_metadata_schema( Instance of a general MetadataSchema. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, metadata_schema, metadata_schema_id]) if request is not None and has_flattened_params: @@ -2425,30 +3697,54 @@ def create_metadata_schema( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def get_metadata_schema( self, - request: metadata_service.GetMetadataSchemaRequest = None, + request: Union[metadata_service.GetMetadataSchemaRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> metadata_schema.MetadataSchema: r"""Retrieves a specific MetadataSchema. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_get_metadata_schema(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetMetadataSchemaRequest( + name="name_value", + ) + + # Make the request + response = client.get_metadata_schema(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.GetMetadataSchemaRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.GetMetadataSchemaRequest, dict]): The request object. Request message for [MetadataService.GetMetadataSchema][google.cloud.aiplatform.v1beta1.MetadataService.GetMetadataSchema]. name (str): - Required. The resource name of the - MetadataSchema to retrieve. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/metadataSchemas/{metadataschema} + Required. The resource name of the MetadataSchema to + retrieve. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/metadataSchemas/{metadataschema}`` This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -2464,7 +3760,7 @@ def get_metadata_schema( Instance of a general MetadataSchema. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -2495,31 +3791,55 @@ def get_metadata_schema( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_metadata_schemas( self, - request: metadata_service.ListMetadataSchemasRequest = None, + request: Union[metadata_service.ListMetadataSchemasRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListMetadataSchemasPager: r"""Lists MetadataSchemas. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_list_metadata_schemas(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListMetadataSchemasRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_metadata_schemas(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ListMetadataSchemasRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ListMetadataSchemasRequest, dict]): The request object. Request message for [MetadataService.ListMetadataSchemas][google.cloud.aiplatform.v1beta1.MetadataService.ListMetadataSchemas]. parent (str): - Required. The MetadataStore whose - MetadataSchemas should be listed. - Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore} + Required. The MetadataStore whose MetadataSchemas should + be listed. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -2540,7 +3860,7 @@ def list_metadata_schemas( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -2571,12 +3891,20 @@ def list_metadata_schemas( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListMetadataSchemasPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -2584,10 +3912,12 @@ def list_metadata_schemas( def query_artifact_lineage_subgraph( self, - request: metadata_service.QueryArtifactLineageSubgraphRequest = None, + request: Union[ + metadata_service.QueryArtifactLineageSubgraphRequest, dict + ] = None, *, artifact: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> lineage_subgraph.LineageSubgraph: @@ -2595,15 +3925,34 @@ def query_artifact_lineage_subgraph( Artifacts and Executions connected by Event edges and returned as a LineageSubgraph. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_query_artifact_lineage_subgraph(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.QueryArtifactLineageSubgraphRequest( + artifact="artifact_value", + ) + + # Make the request + response = client.query_artifact_lineage_subgraph(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.QueryArtifactLineageSubgraphRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.QueryArtifactLineageSubgraphRequest, dict]): The request object. Request message for [MetadataService.QueryArtifactLineageSubgraph][google.cloud.aiplatform.v1beta1.MetadataService.QueryArtifactLineageSubgraph]. artifact (str): Required. The resource name of the Artifact whose Lineage needs to be retrieved as a LineageSubgraph. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact} + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact}`` The request may error with FAILED_PRECONDITION if the number of Artifacts, the number of Executions, or the @@ -2627,7 +3976,7 @@ def query_artifact_lineage_subgraph( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([artifact]) if request is not None and has_flattened_params: @@ -2662,7 +4011,696 @@ def query_artifact_lineage_subgraph( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_operations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.delete_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.wait_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_location, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_locations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response diff --git a/google/cloud/aiplatform_v1beta1/services/metadata_service/pagers.py b/google/cloud/aiplatform_v1beta1/services/metadata_service/pagers.py index 1366829837..4cf3e58c29 100644 --- a/google/cloud/aiplatform_v1beta1/services/metadata_service/pagers.py +++ b/google/cloud/aiplatform_v1beta1/services/metadata_service/pagers.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,13 +15,13 @@ # from typing import ( Any, - AsyncIterable, + AsyncIterator, Awaitable, Callable, - Iterable, Sequence, Tuple, Optional, + Iterator, ) from google.cloud.aiplatform_v1beta1.types import artifact @@ -79,14 +79,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[metadata_service.ListMetadataStoresResponse]: + def pages(self) -> Iterator[metadata_service.ListMetadataStoresResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[metadata_store.MetadataStore]: + def __iter__(self) -> Iterator[metadata_store.MetadataStore]: for page in self.pages: yield from page.metadata_stores @@ -120,7 +120,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -141,14 +141,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - async def pages(self) -> AsyncIterable[metadata_service.ListMetadataStoresResponse]: + async def pages(self) -> AsyncIterator[metadata_service.ListMetadataStoresResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[metadata_store.MetadataStore]: + def __aiter__(self) -> AsyncIterator[metadata_store.MetadataStore]: async def async_generator(): async for page in self.pages: for response in page.metadata_stores: @@ -207,14 +207,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[metadata_service.ListArtifactsResponse]: + def pages(self) -> Iterator[metadata_service.ListArtifactsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[artifact.Artifact]: + def __iter__(self) -> Iterator[artifact.Artifact]: for page in self.pages: yield from page.artifacts @@ -248,7 +248,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -269,14 +269,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - async def pages(self) -> AsyncIterable[metadata_service.ListArtifactsResponse]: + async def pages(self) -> AsyncIterator[metadata_service.ListArtifactsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[artifact.Artifact]: + def __aiter__(self) -> AsyncIterator[artifact.Artifact]: async def async_generator(): async for page in self.pages: for response in page.artifacts: @@ -335,14 +335,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[metadata_service.ListContextsResponse]: + def pages(self) -> Iterator[metadata_service.ListContextsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[context.Context]: + def __iter__(self) -> Iterator[context.Context]: for page in self.pages: yield from page.contexts @@ -376,7 +376,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -397,14 +397,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - async def pages(self) -> AsyncIterable[metadata_service.ListContextsResponse]: + async def pages(self) -> AsyncIterator[metadata_service.ListContextsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[context.Context]: + def __aiter__(self) -> AsyncIterator[context.Context]: async def async_generator(): async for page in self.pages: for response in page.contexts: @@ -463,14 +463,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[metadata_service.ListExecutionsResponse]: + def pages(self) -> Iterator[metadata_service.ListExecutionsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[execution.Execution]: + def __iter__(self) -> Iterator[execution.Execution]: for page in self.pages: yield from page.executions @@ -504,7 +504,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -525,14 +525,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - async def pages(self) -> AsyncIterable[metadata_service.ListExecutionsResponse]: + async def pages(self) -> AsyncIterator[metadata_service.ListExecutionsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[execution.Execution]: + def __aiter__(self) -> AsyncIterator[execution.Execution]: async def async_generator(): async for page in self.pages: for response in page.executions: @@ -591,14 +591,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[metadata_service.ListMetadataSchemasResponse]: + def pages(self) -> Iterator[metadata_service.ListMetadataSchemasResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[metadata_schema.MetadataSchema]: + def __iter__(self) -> Iterator[metadata_schema.MetadataSchema]: for page in self.pages: yield from page.metadata_schemas @@ -632,7 +632,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -655,14 +655,14 @@ def __getattr__(self, name: str) -> Any: @property async def pages( self, - ) -> AsyncIterable[metadata_service.ListMetadataSchemasResponse]: + ) -> AsyncIterator[metadata_service.ListMetadataSchemasResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[metadata_schema.MetadataSchema]: + def __aiter__(self) -> AsyncIterator[metadata_schema.MetadataSchema]: async def async_generator(): async for page in self.pages: for response in page.metadata_schemas: diff --git a/google/cloud/aiplatform_v1beta1/services/metadata_service/transports/__init__.py b/google/cloud/aiplatform_v1beta1/services/metadata_service/transports/__init__.py index f9e669122a..afbd5b2f2c 100644 --- a/google/cloud/aiplatform_v1beta1/services/metadata_service/transports/__init__.py +++ b/google/cloud/aiplatform_v1beta1/services/metadata_service/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1beta1/services/metadata_service/transports/base.py b/google/cloud/aiplatform_v1beta1/services/metadata_service/transports/base.py index 284a96558e..fc15675882 100644 --- a/google/cloud/aiplatform_v1beta1/services/metadata_service/transports/base.py +++ b/google/cloud/aiplatform_v1beta1/services/metadata_service/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,16 +15,16 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.api_core import operations_v1 # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.aiplatform_v1beta1.types import artifact from google.cloud.aiplatform_v1beta1.types import artifact as gca_artifact @@ -37,6 +37,10 @@ from google.cloud.aiplatform_v1beta1.types import metadata_schema as gca_metadata_schema from google.cloud.aiplatform_v1beta1.types import metadata_service from google.cloud.aiplatform_v1beta1.types import metadata_store +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore try: @@ -48,17 +52,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - -_API_CORE_VERSION = google.api_core.__version__ - class MetadataServiceTransport(abc.ABC): """Abstract transport class for MetadataService.""" @@ -76,6 +69,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -99,16 +93,19 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -121,59 +118,21 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id ) - # Save the credentials. - self._credentials = credentials - - # TODO(busunkim): These two class methods are in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-api-core - # and google-auth are increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") + # If the credentials are service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} + credentials = credentials.with_always_use_jwt_access(True) - return scopes_kwargs - - # TODO: Remove this function once google-api-core >= 1.26.0 is required - @classmethod - def _get_self_signed_jwt_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Union[Optional[Sequence[str]], str]]: - """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" - - self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} - - if _API_CORE_VERSION and ( - packaging.version.parse(_API_CORE_VERSION) - >= packaging.version.parse("1.26.0") - ): - self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES - self_signed_jwt_kwargs["scopes"] = scopes - self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST - else: - self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES - - return self_signed_jwt_kwargs + # Save the credentials. + self._credentials = credentials def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. @@ -184,10 +143,14 @@ def _prep_wrapped_messages(self, client_info): client_info=client_info, ), self.get_metadata_store: gapic_v1.method.wrap_method( - self.get_metadata_store, default_timeout=5.0, client_info=client_info, + self.get_metadata_store, + default_timeout=5.0, + client_info=client_info, ), self.list_metadata_stores: gapic_v1.method.wrap_method( - self.list_metadata_stores, default_timeout=5.0, client_info=client_info, + self.list_metadata_stores, + default_timeout=5.0, + client_info=client_info, ), self.delete_metadata_store: gapic_v1.method.wrap_method( self.delete_metadata_store, @@ -195,31 +158,64 @@ def _prep_wrapped_messages(self, client_info): client_info=client_info, ), self.create_artifact: gapic_v1.method.wrap_method( - self.create_artifact, default_timeout=5.0, client_info=client_info, + self.create_artifact, + default_timeout=5.0, + client_info=client_info, ), self.get_artifact: gapic_v1.method.wrap_method( - self.get_artifact, default_timeout=5.0, client_info=client_info, + self.get_artifact, + default_timeout=5.0, + client_info=client_info, ), self.list_artifacts: gapic_v1.method.wrap_method( - self.list_artifacts, default_timeout=5.0, client_info=client_info, + self.list_artifacts, + default_timeout=5.0, + client_info=client_info, ), self.update_artifact: gapic_v1.method.wrap_method( - self.update_artifact, default_timeout=5.0, client_info=client_info, + self.update_artifact, + default_timeout=5.0, + client_info=client_info, + ), + self.delete_artifact: gapic_v1.method.wrap_method( + self.delete_artifact, + default_timeout=None, + client_info=client_info, + ), + self.purge_artifacts: gapic_v1.method.wrap_method( + self.purge_artifacts, + default_timeout=None, + client_info=client_info, ), self.create_context: gapic_v1.method.wrap_method( - self.create_context, default_timeout=5.0, client_info=client_info, + self.create_context, + default_timeout=5.0, + client_info=client_info, ), self.get_context: gapic_v1.method.wrap_method( - self.get_context, default_timeout=5.0, client_info=client_info, + self.get_context, + default_timeout=5.0, + client_info=client_info, ), self.list_contexts: gapic_v1.method.wrap_method( - self.list_contexts, default_timeout=5.0, client_info=client_info, + self.list_contexts, + default_timeout=5.0, + client_info=client_info, ), self.update_context: gapic_v1.method.wrap_method( - self.update_context, default_timeout=5.0, client_info=client_info, + self.update_context, + default_timeout=5.0, + client_info=client_info, ), self.delete_context: gapic_v1.method.wrap_method( - self.delete_context, default_timeout=5.0, client_info=client_info, + self.delete_context, + default_timeout=5.0, + client_info=client_info, + ), + self.purge_contexts: gapic_v1.method.wrap_method( + self.purge_contexts, + default_timeout=None, + client_info=client_info, ), self.add_context_artifacts_and_executions: gapic_v1.method.wrap_method( self.add_context_artifacts_and_executions, @@ -227,7 +223,9 @@ def _prep_wrapped_messages(self, client_info): client_info=client_info, ), self.add_context_children: gapic_v1.method.wrap_method( - self.add_context_children, default_timeout=5.0, client_info=client_info, + self.add_context_children, + default_timeout=5.0, + client_info=client_info, ), self.query_context_lineage_subgraph: gapic_v1.method.wrap_method( self.query_context_lineage_subgraph, @@ -235,19 +233,39 @@ def _prep_wrapped_messages(self, client_info): client_info=client_info, ), self.create_execution: gapic_v1.method.wrap_method( - self.create_execution, default_timeout=5.0, client_info=client_info, + self.create_execution, + default_timeout=5.0, + client_info=client_info, ), self.get_execution: gapic_v1.method.wrap_method( - self.get_execution, default_timeout=5.0, client_info=client_info, + self.get_execution, + default_timeout=5.0, + client_info=client_info, ), self.list_executions: gapic_v1.method.wrap_method( - self.list_executions, default_timeout=5.0, client_info=client_info, + self.list_executions, + default_timeout=5.0, + client_info=client_info, ), self.update_execution: gapic_v1.method.wrap_method( - self.update_execution, default_timeout=5.0, client_info=client_info, + self.update_execution, + default_timeout=5.0, + client_info=client_info, + ), + self.delete_execution: gapic_v1.method.wrap_method( + self.delete_execution, + default_timeout=None, + client_info=client_info, + ), + self.purge_executions: gapic_v1.method.wrap_method( + self.purge_executions, + default_timeout=None, + client_info=client_info, ), self.add_execution_events: gapic_v1.method.wrap_method( - self.add_execution_events, default_timeout=5.0, client_info=client_info, + self.add_execution_events, + default_timeout=5.0, + client_info=client_info, ), self.query_execution_inputs_and_outputs: gapic_v1.method.wrap_method( self.query_execution_inputs_and_outputs, @@ -260,7 +278,9 @@ def _prep_wrapped_messages(self, client_info): client_info=client_info, ), self.get_metadata_schema: gapic_v1.method.wrap_method( - self.get_metadata_schema, default_timeout=5.0, client_info=client_info, + self.get_metadata_schema, + default_timeout=5.0, + client_info=client_info, ), self.list_metadata_schemas: gapic_v1.method.wrap_method( self.list_metadata_schemas, @@ -274,8 +294,17 @@ def _prep_wrapped_messages(self, client_info): ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() @@ -357,6 +386,24 @@ def update_artifact( ]: raise NotImplementedError() + @property + def delete_artifact( + self, + ) -> Callable[ + [metadata_service.DeleteArtifactRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def purge_artifacts( + self, + ) -> Callable[ + [metadata_service.PurgeArtifactsRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + @property def create_context( self, @@ -405,6 +452,15 @@ def delete_context( ]: raise NotImplementedError() + @property + def purge_contexts( + self, + ) -> Callable[ + [metadata_service.PurgeContextsRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + @property def add_context_artifacts_and_executions( self, @@ -480,6 +536,24 @@ def update_execution( ]: raise NotImplementedError() + @property + def delete_execution( + self, + ) -> Callable[ + [metadata_service.DeleteExecutionRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def purge_executions( + self, + ) -> Callable[ + [metadata_service.PurgeExecutionsRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + @property def add_execution_events( self, @@ -551,5 +625,102 @@ def query_artifact_lineage_subgraph( ]: raise NotImplementedError() + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], + Union[ + operations_pb2.ListOperationsResponse, + Awaitable[operations_pb2.ListOperationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None,]: + raise NotImplementedError() + + @property + def wait_operation( + self, + ) -> Callable[ + [operations_pb2.WaitOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def set_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def get_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_location( + self, + ) -> Callable[ + [locations_pb2.GetLocationRequest], + Union[locations_pb2.Location, Awaitable[locations_pb2.Location]], + ]: + raise NotImplementedError() + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], + Union[ + locations_pb2.ListLocationsResponse, + Awaitable[locations_pb2.ListLocationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + __all__ = ("MetadataServiceTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/metadata_service/transports/grpc.py b/google/cloud/aiplatform_v1beta1/services/metadata_service/transports/grpc.py index 0ad440d8c6..05070979f0 100644 --- a/google/cloud/aiplatform_v1beta1/services/metadata_service/transports/grpc.py +++ b/google/cloud/aiplatform_v1beta1/services/metadata_service/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,9 +16,9 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import operations_v1 +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -36,6 +36,10 @@ from google.cloud.aiplatform_v1beta1.types import metadata_schema as gca_metadata_schema from google.cloud.aiplatform_v1beta1.types import metadata_service from google.cloud.aiplatform_v1beta1.types import metadata_store +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from .base import MetadataServiceTransport, DEFAULT_CLIENT_INFO @@ -69,6 +73,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -91,16 +96,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -109,6 +114,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport @@ -119,7 +126,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -162,13 +169,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -217,21 +228,20 @@ def create_channel( and ``credentials_file`` are passed. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @property def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ + """Return the channel designed to connect to this service.""" return self._grpc_channel @property @@ -241,7 +251,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsClient(self.grpc_channel) @@ -342,7 +352,8 @@ def delete_metadata_store( ]: r"""Return a callable for the delete metadata store method over gRPC. - Deletes a single MetadataStore. + Deletes a single MetadataStore and all its child + resources (Artifacts, Executions, and Contexts). Returns: Callable[[~.DeleteMetadataStoreRequest], @@ -468,6 +479,58 @@ def update_artifact( ) return self._stubs["update_artifact"] + @property + def delete_artifact( + self, + ) -> Callable[[metadata_service.DeleteArtifactRequest], operations_pb2.Operation]: + r"""Return a callable for the delete artifact method over gRPC. + + Deletes an Artifact. + + Returns: + Callable[[~.DeleteArtifactRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_artifact" not in self._stubs: + self._stubs["delete_artifact"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1beta1.MetadataService/DeleteArtifact", + request_serializer=metadata_service.DeleteArtifactRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_artifact"] + + @property + def purge_artifacts( + self, + ) -> Callable[[metadata_service.PurgeArtifactsRequest], operations_pb2.Operation]: + r"""Return a callable for the purge artifacts method over gRPC. + + Purges Artifacts. + + Returns: + Callable[[~.PurgeArtifactsRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "purge_artifacts" not in self._stubs: + self._stubs["purge_artifacts"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1beta1.MetadataService/PurgeArtifacts", + request_serializer=metadata_service.PurgeArtifactsRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["purge_artifacts"] + @property def create_context( self, @@ -600,6 +663,32 @@ def delete_context( ) return self._stubs["delete_context"] + @property + def purge_contexts( + self, + ) -> Callable[[metadata_service.PurgeContextsRequest], operations_pb2.Operation]: + r"""Return a callable for the purge contexts method over gRPC. + + Purges Contexts. + + Returns: + Callable[[~.PurgeContextsRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "purge_contexts" not in self._stubs: + self._stubs["purge_contexts"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1beta1.MetadataService/PurgeContexts", + request_serializer=metadata_service.PurgeContextsRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["purge_contexts"] + @property def add_context_artifacts_and_executions( self, @@ -647,7 +736,7 @@ def add_context_children( of the child Contexts have already been added to the parent Context, they are simply skipped. If this call would create a cycle or cause any Context to have more than 10 parents, the - request will fail with INVALID_ARGUMENT error. + request will fail with an INVALID_ARGUMENT error. Returns: Callable[[~.AddContextChildrenRequest], @@ -807,6 +896,58 @@ def update_execution( ) return self._stubs["update_execution"] + @property + def delete_execution( + self, + ) -> Callable[[metadata_service.DeleteExecutionRequest], operations_pb2.Operation]: + r"""Return a callable for the delete execution method over gRPC. + + Deletes an Execution. + + Returns: + Callable[[~.DeleteExecutionRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_execution" not in self._stubs: + self._stubs["delete_execution"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1beta1.MetadataService/DeleteExecution", + request_serializer=metadata_service.DeleteExecutionRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_execution"] + + @property + def purge_executions( + self, + ) -> Callable[[metadata_service.PurgeExecutionsRequest], operations_pb2.Operation]: + r"""Return a callable for the purge executions method over gRPC. + + Purges Executions. + + Returns: + Callable[[~.PurgeExecutionsRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "purge_executions" not in self._stubs: + self._stubs["purge_executions"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1beta1.MetadataService/PurgeExecutions", + request_serializer=metadata_service.PurgeExecutionsRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["purge_executions"] + @property def add_execution_events( self, @@ -816,10 +957,11 @@ def add_execution_events( ]: r"""Return a callable for the add execution events method over gRPC. - Adds Events for denoting whether each Artifact was an - input or output for a given Execution. If any Events - already exist between the Execution and any of the - specified Artifacts they are simply skipped. + Adds Events to the specified Execution. An Event + indicates whether an Artifact was used as an input or + output for an Execution. If an Event already exists + between the Execution and the Artifact, the Event is + skipped. Returns: Callable[[~.AddExecutionEventsRequest], @@ -882,7 +1024,7 @@ def create_metadata_schema( ]: r"""Return a callable for the create metadata schema method over gRPC. - Creates an MetadataSchema. + Creates a MetadataSchema. Returns: Callable[[~.CreateMetadataSchemaRequest], @@ -993,5 +1135,215 @@ def query_artifact_lineage_subgraph( ) return self._stubs["query_artifact_lineage_subgraph"] + def close(self): + self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + @property + def kind(self) -> str: + return "grpc" + __all__ = ("MetadataServiceGrpcTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/metadata_service/transports/grpc_asyncio.py b/google/cloud/aiplatform_v1beta1/services/metadata_service/transports/grpc_asyncio.py index c9020e1101..74670276e7 100644 --- a/google/cloud/aiplatform_v1beta1/services/metadata_service/transports/grpc_asyncio.py +++ b/google/cloud/aiplatform_v1beta1/services/metadata_service/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,12 +16,11 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore -from google.api_core import operations_v1 # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore @@ -37,6 +36,10 @@ from google.cloud.aiplatform_v1beta1.types import metadata_schema as gca_metadata_schema from google.cloud.aiplatform_v1beta1.types import metadata_service from google.cloud.aiplatform_v1beta1.types import metadata_store +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from .base import MetadataServiceTransport, DEFAULT_CLIENT_INFO from .grpc import MetadataServiceGrpcTransport @@ -90,14 +93,14 @@ def create_channel( aio.Channel: A gRPC AsyncIO channel object. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @@ -115,6 +118,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -138,16 +142,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -156,6 +160,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport @@ -166,7 +172,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -208,13 +214,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -244,7 +254,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel @@ -350,7 +360,8 @@ def delete_metadata_store( ]: r"""Return a callable for the delete metadata store method over gRPC. - Deletes a single MetadataStore. + Deletes a single MetadataStore and all its child + resources (Artifacts, Executions, and Contexts). Returns: Callable[[~.DeleteMetadataStoreRequest], @@ -481,6 +492,62 @@ def update_artifact( ) return self._stubs["update_artifact"] + @property + def delete_artifact( + self, + ) -> Callable[ + [metadata_service.DeleteArtifactRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the delete artifact method over gRPC. + + Deletes an Artifact. + + Returns: + Callable[[~.DeleteArtifactRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_artifact" not in self._stubs: + self._stubs["delete_artifact"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1beta1.MetadataService/DeleteArtifact", + request_serializer=metadata_service.DeleteArtifactRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_artifact"] + + @property + def purge_artifacts( + self, + ) -> Callable[ + [metadata_service.PurgeArtifactsRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the purge artifacts method over gRPC. + + Purges Artifacts. + + Returns: + Callable[[~.PurgeArtifactsRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "purge_artifacts" not in self._stubs: + self._stubs["purge_artifacts"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1beta1.MetadataService/PurgeArtifacts", + request_serializer=metadata_service.PurgeArtifactsRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["purge_artifacts"] + @property def create_context( self, @@ -620,6 +687,34 @@ def delete_context( ) return self._stubs["delete_context"] + @property + def purge_contexts( + self, + ) -> Callable[ + [metadata_service.PurgeContextsRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the purge contexts method over gRPC. + + Purges Contexts. + + Returns: + Callable[[~.PurgeContextsRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "purge_contexts" not in self._stubs: + self._stubs["purge_contexts"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1beta1.MetadataService/PurgeContexts", + request_serializer=metadata_service.PurgeContextsRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["purge_contexts"] + @property def add_context_artifacts_and_executions( self, @@ -667,7 +762,7 @@ def add_context_children( of the child Contexts have already been added to the parent Context, they are simply skipped. If this call would create a cycle or cause any Context to have more than 10 parents, the - request will fail with INVALID_ARGUMENT error. + request will fail with an INVALID_ARGUMENT error. Returns: Callable[[~.AddContextChildrenRequest], @@ -833,6 +928,62 @@ def update_execution( ) return self._stubs["update_execution"] + @property + def delete_execution( + self, + ) -> Callable[ + [metadata_service.DeleteExecutionRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the delete execution method over gRPC. + + Deletes an Execution. + + Returns: + Callable[[~.DeleteExecutionRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_execution" not in self._stubs: + self._stubs["delete_execution"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1beta1.MetadataService/DeleteExecution", + request_serializer=metadata_service.DeleteExecutionRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_execution"] + + @property + def purge_executions( + self, + ) -> Callable[ + [metadata_service.PurgeExecutionsRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the purge executions method over gRPC. + + Purges Executions. + + Returns: + Callable[[~.PurgeExecutionsRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "purge_executions" not in self._stubs: + self._stubs["purge_executions"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1beta1.MetadataService/PurgeExecutions", + request_serializer=metadata_service.PurgeExecutionsRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["purge_executions"] + @property def add_execution_events( self, @@ -842,10 +993,11 @@ def add_execution_events( ]: r"""Return a callable for the add execution events method over gRPC. - Adds Events for denoting whether each Artifact was an - input or output for a given Execution. If any Events - already exist between the Execution and any of the - specified Artifacts they are simply skipped. + Adds Events to the specified Execution. An Event + indicates whether an Artifact was used as an input or + output for an Execution. If an Event already exists + between the Execution and the Artifact, the Event is + skipped. Returns: Callable[[~.AddExecutionEventsRequest], @@ -908,7 +1060,7 @@ def create_metadata_schema( ]: r"""Return a callable for the create metadata schema method over gRPC. - Creates an MetadataSchema. + Creates a MetadataSchema. Returns: Callable[[~.CreateMetadataSchemaRequest], @@ -1020,5 +1172,211 @@ def query_artifact_lineage_subgraph( ) return self._stubs["query_artifact_lineage_subgraph"] + def close(self): + return self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + __all__ = ("MetadataServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/migration_service/__init__.py b/google/cloud/aiplatform_v1beta1/services/migration_service/__init__.py index 5af6b09eb3..36329bb27d 100644 --- a/google/cloud/aiplatform_v1beta1/services/migration_service/__init__.py +++ b/google/cloud/aiplatform_v1beta1/services/migration_service/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1beta1/services/migration_service/async_client.py b/google/cloud/aiplatform_v1beta1/services/migration_service/async_client.py index 5549e1c870..ef1b557946 100644 --- a/google/cloud/aiplatform_v1beta1/services/migration_service/async_client.py +++ b/google/cloud/aiplatform_v1beta1/services/migration_service/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,21 +16,30 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1beta1.services.migration_service import pagers from google.cloud.aiplatform_v1beta1.types import migratable_resource from google.cloud.aiplatform_v1beta1.types import migration_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from .transports.base import MigrationServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import MigrationServiceGrpcAsyncIOTransport from .client import MigrationServiceClient @@ -38,8 +47,7 @@ class MigrationServiceAsyncClient: """A service that migrates resources from automl.googleapis.com, - datalabeling.googleapis.com and ml.googleapis.com to AI - Platform. + datalabeling.googleapis.com and ml.googleapis.com to Vertex AI. """ _client: MigrationServiceClient @@ -90,7 +98,8 @@ class MigrationServiceAsyncClient: @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -105,7 +114,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -120,9 +129,45 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return MigrationServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> MigrationServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: MigrationServiceTransport: The transport used by the client instance. @@ -141,7 +186,7 @@ def __init__( client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the migration service client. + """Instantiates the migration service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -182,25 +227,45 @@ def __init__( async def search_migratable_resources( self, - request: migration_service.SearchMigratableResourcesRequest = None, + request: Union[migration_service.SearchMigratableResourcesRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.SearchMigratableResourcesAsyncPager: r"""Searches all of the resources in automl.googleapis.com, datalabeling.googleapis.com and - ml.googleapis.com that can be migrated to AI Platform's + ml.googleapis.com that can be migrated to Vertex AI's given location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_search_migratable_resources(): + # Create a client + client = aiplatform_v1beta1.MigrationServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.SearchMigratableResourcesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.search_migratable_resources(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.SearchMigratableResourcesRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.SearchMigratableResourcesRequest, dict]): The request object. Request message for [MigrationService.SearchMigratableResources][google.cloud.aiplatform.v1beta1.MigrationService.SearchMigratableResources]. parent (:class:`str`): Required. The location that the migratable resources - should be searched from. It's the AI Platform location + should be searched from. It's the Vertex AI location that the resources can be migrated to, not the resources' original location. Format: ``projects/{project}/locations/{location}`` @@ -224,7 +289,7 @@ async def search_migratable_resources( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -255,12 +320,20 @@ async def search_migratable_resources( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.SearchMigratableResourcesAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -268,22 +341,51 @@ async def search_migratable_resources( async def batch_migrate_resources( self, - request: migration_service.BatchMigrateResourcesRequest = None, + request: Union[migration_service.BatchMigrateResourcesRequest, dict] = None, *, parent: str = None, migrate_resource_requests: Sequence[ migration_service.MigrateResourceRequest ] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Batch migrates resources from ml.googleapis.com, automl.googleapis.com, and datalabeling.googleapis.com - to AI Platform (Unified). + to Vertex AI. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_batch_migrate_resources(): + # Create a client + client = aiplatform_v1beta1.MigrationServiceAsyncClient() + + # Initialize request argument(s) + migrate_resource_requests = aiplatform_v1beta1.MigrateResourceRequest() + migrate_resource_requests.migrate_ml_engine_model_version_config.endpoint = "endpoint_value" + migrate_resource_requests.migrate_ml_engine_model_version_config.model_version = "model_version_value" + migrate_resource_requests.migrate_ml_engine_model_version_config.model_display_name = "model_display_name_value" + + request = aiplatform_v1beta1.BatchMigrateResourcesRequest( + parent="parent_value", + migrate_resource_requests=migrate_resource_requests, + ) + + # Make the request + operation = client.batch_migrate_resources(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.BatchMigrateResourcesRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.BatchMigrateResourcesRequest, dict]): The request object. Request message for [MigrationService.BatchMigrateResources][google.cloud.aiplatform.v1beta1.MigrationService.BatchMigrateResources]. parent (:class:`str`): @@ -321,7 +423,7 @@ async def batch_migrate_resources( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, migrate_resource_requests]) if request is not None and has_flattened_params: @@ -354,7 +456,12 @@ async def batch_migrate_resources( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -367,6 +474,683 @@ async def batch_migrate_resources( # Done; return the response. return response + async def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_operations, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.delete_operation, + default_timeout=None, + 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 cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + 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 wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.wait_operation, + default_timeout=None, + 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 set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_location, + default_timeout=None, + 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 list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_locations, + default_timeout=None, + 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 __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/aiplatform_v1beta1/services/migration_service/client.py b/google/cloud/aiplatform_v1beta1/services/migration_service/client.py index 7167f186ae..0728f77974 100644 --- a/google/cloud/aiplatform_v1beta1/services/migration_service/client.py +++ b/google/cloud/aiplatform_v1beta1/services/migration_service/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,27 +14,35 @@ # 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 +from typing import Dict, Mapping, 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 as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_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 +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1beta1.services.migration_service import pagers from google.cloud.aiplatform_v1beta1.types import migratable_resource from google.cloud.aiplatform_v1beta1.types import migration_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from .transports.base import MigrationServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc import MigrationServiceGrpcTransport from .transports.grpc_asyncio import MigrationServiceGrpcAsyncIOTransport @@ -54,8 +62,11 @@ class MigrationServiceClientMeta(type): _transport_registry["grpc"] = MigrationServiceGrpcTransport _transport_registry["grpc_asyncio"] = MigrationServiceGrpcAsyncIOTransport - def get_transport_class(cls, label: str = None,) -> Type[MigrationServiceTransport]: - """Return an appropriate transport class. + def get_transport_class( + cls, + label: str = None, + ) -> Type[MigrationServiceTransport]: + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -75,13 +86,13 @@ def get_transport_class(cls, label: str = None,) -> Type[MigrationServiceTranspo class MigrationServiceClient(metaclass=MigrationServiceClientMeta): """A service that migrates resources from automl.googleapis.com, - datalabeling.googleapis.com and ml.googleapis.com to AI - Platform. + datalabeling.googleapis.com and ml.googleapis.com to Vertex AI. """ @staticmethod def _get_default_mtls_endpoint(api_endpoint): - """Convert api endpoint to mTLS endpoint. + """Converts api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. Args: @@ -115,7 +126,8 @@ def _get_default_mtls_endpoint(api_endpoint): @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -132,7 +144,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -151,25 +163,30 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> MigrationServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - MigrationServiceTransport: The transport used by the client instance. + MigrationServiceTransport: The transport used by the client + instance. """ return self._transport @staticmethod def annotated_dataset_path( - project: str, dataset: str, annotated_dataset: str, + project: str, + dataset: str, + annotated_dataset: str, ) -> str: - """Return a fully-qualified annotated_dataset string.""" + """Returns a fully-qualified annotated_dataset string.""" return "projects/{project}/datasets/{dataset}/annotatedDatasets/{annotated_dataset}".format( - project=project, dataset=dataset, annotated_dataset=annotated_dataset, + project=project, + dataset=dataset, + annotated_dataset=annotated_dataset, ) @staticmethod def parse_annotated_dataset_path(path: str) -> Dict[str, str]: - """Parse a annotated_dataset path into its component segments.""" + """Parses a annotated_dataset path into its component segments.""" m = re.match( r"^projects/(?P.+?)/datasets/(?P.+?)/annotatedDatasets/(?P.+?)$", path, @@ -177,15 +194,21 @@ def parse_annotated_dataset_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def dataset_path(project: str, location: str, dataset: str,) -> str: - """Return a fully-qualified dataset string.""" + def dataset_path( + project: str, + location: str, + dataset: str, + ) -> str: + """Returns a fully-qualified dataset string.""" return "projects/{project}/locations/{location}/datasets/{dataset}".format( - project=project, location=location, dataset=dataset, + project=project, + location=location, + dataset=dataset, ) @staticmethod def parse_dataset_path(path: str) -> Dict[str, str]: - """Parse a dataset path into its component segments.""" + """Parses a dataset path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/datasets/(?P.+?)$", path, @@ -193,28 +216,38 @@ def parse_dataset_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def dataset_path(project: str, dataset: str,) -> str: - """Return a fully-qualified dataset string.""" + def dataset_path( + project: str, + dataset: str, + ) -> str: + """Returns a fully-qualified dataset string.""" return "projects/{project}/datasets/{dataset}".format( - project=project, dataset=dataset, + project=project, + dataset=dataset, ) @staticmethod def parse_dataset_path(path: str) -> Dict[str, str]: - """Parse a dataset path into its component segments.""" + """Parses a dataset path into its component segments.""" m = re.match(r"^projects/(?P.+?)/datasets/(?P.+?)$", path) return m.groupdict() if m else {} @staticmethod - def dataset_path(project: str, location: str, dataset: str,) -> str: - """Return a fully-qualified dataset string.""" + def dataset_path( + project: str, + location: str, + dataset: str, + ) -> str: + """Returns a fully-qualified dataset string.""" return "projects/{project}/locations/{location}/datasets/{dataset}".format( - project=project, location=location, dataset=dataset, + project=project, + location=location, + dataset=dataset, ) @staticmethod def parse_dataset_path(path: str) -> Dict[str, str]: - """Parse a dataset path into its component segments.""" + """Parses a dataset path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/datasets/(?P.+?)$", path, @@ -222,15 +255,21 @@ def parse_dataset_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def model_path(project: str, location: str, model: str,) -> str: - """Return a fully-qualified model string.""" + def model_path( + project: str, + location: str, + model: str, + ) -> str: + """Returns a fully-qualified model string.""" return "projects/{project}/locations/{location}/models/{model}".format( - project=project, location=location, model=model, + project=project, + location=location, + model=model, ) @staticmethod def parse_model_path(path: str) -> Dict[str, str]: - """Parse a model path into its component segments.""" + """Parses a model path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/models/(?P.+?)$", path, @@ -238,15 +277,21 @@ def parse_model_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def model_path(project: str, location: str, model: str,) -> str: - """Return a fully-qualified model string.""" + def model_path( + project: str, + location: str, + model: str, + ) -> str: + """Returns a fully-qualified model string.""" return "projects/{project}/locations/{location}/models/{model}".format( - project=project, location=location, model=model, + project=project, + location=location, + model=model, ) @staticmethod def parse_model_path(path: str) -> Dict[str, str]: - """Parse a model path into its component segments.""" + """Parses a model path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/models/(?P.+?)$", path, @@ -254,15 +299,21 @@ def parse_model_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def version_path(project: str, model: str, version: str,) -> str: - """Return a fully-qualified version string.""" + def version_path( + project: str, + model: str, + version: str, + ) -> str: + """Returns a fully-qualified version string.""" return "projects/{project}/models/{model}/versions/{version}".format( - project=project, model=model, version=version, + project=project, + model=model, + version=version, ) @staticmethod def parse_version_path(path: str) -> Dict[str, str]: - """Parse a version path into its component segments.""" + """Parses a version path into its component segments.""" m = re.match( r"^projects/(?P.+?)/models/(?P.+?)/versions/(?P.+?)$", path, @@ -270,8 +321,10 @@ def parse_version_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + def common_billing_account_path( + billing_account: str, + ) -> str: + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -283,9 +336,13 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: 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,) + def common_folder_path( + folder: str, + ) -> str: + """Returns a fully-qualified folder string.""" + return "folders/{folder}".format( + folder=folder, + ) @staticmethod def parse_common_folder_path(path: str) -> Dict[str, str]: @@ -294,9 +351,13 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: 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,) + def common_organization_path( + organization: str, + ) -> str: + """Returns a fully-qualified organization string.""" + return "organizations/{organization}".format( + organization=organization, + ) @staticmethod def parse_common_organization_path(path: str) -> Dict[str, str]: @@ -305,9 +366,13 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: 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,) + def common_project_path( + project: str, + ) -> str: + """Returns a fully-qualified project string.""" + return "projects/{project}".format( + project=project, + ) @staticmethod def parse_common_project_path(path: str) -> Dict[str, str]: @@ -316,10 +381,14 @@ def parse_common_project_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_location_path(project: str, location: str,) -> str: - """Return a fully-qualified location string.""" + def common_location_path( + project: str, + location: str, + ) -> str: + """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) @staticmethod @@ -328,6 +397,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + def __init__( self, *, @@ -336,7 +472,7 @@ def __init__( client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the migration service client. + """Instantiates the migration service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -378,58 +514,42 @@ def __init__( 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")) + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - client_cert_source_func = ( - mtls.default_client_cert_source() 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" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # 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, MigrationServiceTransport): # transport is a MigrationServiceTransport instance. - if credentials or client_options.credentials_file: + if credentials or client_options.credentials_file or api_key_value: 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." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + Transport = type(self).get_transport_class(transport) self._transport = Transport( credentials=credentials, @@ -439,29 +559,50 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, + always_use_jwt_access=True, ) def search_migratable_resources( self, - request: migration_service.SearchMigratableResourcesRequest = None, + request: Union[migration_service.SearchMigratableResourcesRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.SearchMigratableResourcesPager: r"""Searches all of the resources in automl.googleapis.com, datalabeling.googleapis.com and - ml.googleapis.com that can be migrated to AI Platform's + ml.googleapis.com that can be migrated to Vertex AI's given location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_search_migratable_resources(): + # Create a client + client = aiplatform_v1beta1.MigrationServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.SearchMigratableResourcesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.search_migratable_resources(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.SearchMigratableResourcesRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.SearchMigratableResourcesRequest, dict]): The request object. Request message for [MigrationService.SearchMigratableResources][google.cloud.aiplatform.v1beta1.MigrationService.SearchMigratableResources]. parent (str): Required. The location that the migratable resources - should be searched from. It's the AI Platform location + should be searched from. It's the Vertex AI location that the resources can be migrated to, not the resources' original location. Format: ``projects/{project}/locations/{location}`` @@ -485,7 +626,7 @@ def search_migratable_resources( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -518,12 +659,20 @@ def search_migratable_resources( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.SearchMigratableResourcesPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -531,22 +680,51 @@ def search_migratable_resources( def batch_migrate_resources( self, - request: migration_service.BatchMigrateResourcesRequest = None, + request: Union[migration_service.BatchMigrateResourcesRequest, dict] = None, *, parent: str = None, migrate_resource_requests: Sequence[ migration_service.MigrateResourceRequest ] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Batch migrates resources from ml.googleapis.com, automl.googleapis.com, and datalabeling.googleapis.com - to AI Platform (Unified). + to Vertex AI. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_batch_migrate_resources(): + # Create a client + client = aiplatform_v1beta1.MigrationServiceClient() + + # Initialize request argument(s) + migrate_resource_requests = aiplatform_v1beta1.MigrateResourceRequest() + migrate_resource_requests.migrate_ml_engine_model_version_config.endpoint = "endpoint_value" + migrate_resource_requests.migrate_ml_engine_model_version_config.model_version = "model_version_value" + migrate_resource_requests.migrate_ml_engine_model_version_config.model_display_name = "model_display_name_value" + + request = aiplatform_v1beta1.BatchMigrateResourcesRequest( + parent="parent_value", + migrate_resource_requests=migrate_resource_requests, + ) + + # Make the request + operation = client.batch_migrate_resources(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) Args: - request (google.cloud.aiplatform_v1beta1.types.BatchMigrateResourcesRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.BatchMigrateResourcesRequest, dict]): The request object. Request message for [MigrationService.BatchMigrateResources][google.cloud.aiplatform.v1beta1.MigrationService.BatchMigrateResources]. parent (str): @@ -584,7 +762,7 @@ def batch_migrate_resources( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, migrate_resource_requests]) if request is not None and has_flattened_params: @@ -617,7 +795,12 @@ def batch_migrate_resources( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation.from_gapic( @@ -630,6 +813,690 @@ def batch_migrate_resources( # Done; return the response. return response + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_operations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.delete_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.wait_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_location, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_locations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/aiplatform_v1beta1/services/migration_service/pagers.py b/google/cloud/aiplatform_v1beta1/services/migration_service/pagers.py index 0756f5b1c4..225555e555 100644 --- a/google/cloud/aiplatform_v1beta1/services/migration_service/pagers.py +++ b/google/cloud/aiplatform_v1beta1/services/migration_service/pagers.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,13 +15,13 @@ # from typing import ( Any, - AsyncIterable, + AsyncIterator, Awaitable, Callable, - Iterable, Sequence, Tuple, Optional, + Iterator, ) from google.cloud.aiplatform_v1beta1.types import migratable_resource @@ -75,14 +75,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[migration_service.SearchMigratableResourcesResponse]: + def pages(self) -> Iterator[migration_service.SearchMigratableResourcesResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[migratable_resource.MigratableResource]: + def __iter__(self) -> Iterator[migratable_resource.MigratableResource]: for page in self.pages: yield from page.migratable_resources @@ -118,7 +118,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -141,14 +141,14 @@ def __getattr__(self, name: str) -> Any: @property async def pages( self, - ) -> AsyncIterable[migration_service.SearchMigratableResourcesResponse]: + ) -> AsyncIterator[migration_service.SearchMigratableResourcesResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[migratable_resource.MigratableResource]: + def __aiter__(self) -> AsyncIterator[migratable_resource.MigratableResource]: async def async_generator(): async for page in self.pages: for response in page.migratable_resources: diff --git a/google/cloud/aiplatform_v1beta1/services/migration_service/transports/__init__.py b/google/cloud/aiplatform_v1beta1/services/migration_service/transports/__init__.py index 565048f2a3..10ee1426af 100644 --- a/google/cloud/aiplatform_v1beta1/services/migration_service/transports/__init__.py +++ b/google/cloud/aiplatform_v1beta1/services/migration_service/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1beta1/services/migration_service/transports/base.py b/google/cloud/aiplatform_v1beta1/services/migration_service/transports/base.py index d2b54f2c66..f9ad2c3506 100644 --- a/google/cloud/aiplatform_v1beta1/services/migration_service/transports/base.py +++ b/google/cloud/aiplatform_v1beta1/services/migration_service/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,18 +15,22 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.api_core import operations_v1 # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.aiplatform_v1beta1.types import migration_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore try: @@ -38,17 +42,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - -_API_CORE_VERSION = google.api_core.__version__ - class MigrationServiceTransport(abc.ABC): """Abstract transport class for MigrationService.""" @@ -66,6 +59,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -89,16 +83,19 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -111,59 +108,21 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id ) - # Save the credentials. - self._credentials = credentials - - # TODO(busunkim): These two class methods are in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-api-core - # and google-auth are increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") + # If the credentials are service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs + credentials = credentials.with_always_use_jwt_access(True) - # TODO: Remove this function once google-api-core >= 1.26.0 is required - @classmethod - def _get_self_signed_jwt_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Union[Optional[Sequence[str]], str]]: - """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" - - self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} - - if _API_CORE_VERSION and ( - packaging.version.parse(_API_CORE_VERSION) - >= packaging.version.parse("1.26.0") - ): - self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES - self_signed_jwt_kwargs["scopes"] = scopes - self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST - else: - self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES - - return self_signed_jwt_kwargs + # Save the credentials. + self._credentials = credentials def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. @@ -180,8 +139,17 @@ def _prep_wrapped_messages(self, client_info): ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() @@ -206,5 +174,102 @@ def batch_migrate_resources( ]: raise NotImplementedError() + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], + Union[ + operations_pb2.ListOperationsResponse, + Awaitable[operations_pb2.ListOperationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None,]: + raise NotImplementedError() + + @property + def wait_operation( + self, + ) -> Callable[ + [operations_pb2.WaitOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def set_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def get_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_location( + self, + ) -> Callable[ + [locations_pb2.GetLocationRequest], + Union[locations_pb2.Location, Awaitable[locations_pb2.Location]], + ]: + raise NotImplementedError() + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], + Union[ + locations_pb2.ListLocationsResponse, + Awaitable[locations_pb2.ListLocationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + __all__ = ("MigrationServiceTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/migration_service/transports/grpc.py b/google/cloud/aiplatform_v1beta1/services/migration_service/transports/grpc.py index 372e413534..3553ef095c 100644 --- a/google/cloud/aiplatform_v1beta1/services/migration_service/transports/grpc.py +++ b/google/cloud/aiplatform_v1beta1/services/migration_service/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,9 +16,9 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import operations_v1 +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -26,6 +26,10 @@ import grpc # type: ignore from google.cloud.aiplatform_v1beta1.types import migration_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from .base import MigrationServiceTransport, DEFAULT_CLIENT_INFO @@ -34,8 +38,7 @@ class MigrationServiceGrpcTransport(MigrationServiceTransport): """gRPC backend transport for MigrationService. A service that migrates resources from automl.googleapis.com, - datalabeling.googleapis.com and ml.googleapis.com to AI - Platform. + datalabeling.googleapis.com and ml.googleapis.com to Vertex AI. This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation @@ -61,6 +64,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -83,16 +87,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -101,6 +105,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport @@ -111,7 +117,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -154,13 +160,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -209,21 +219,20 @@ def create_channel( and ``credentials_file`` are passed. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @property def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ + """Return the channel designed to connect to this service.""" return self._grpc_channel @property @@ -233,7 +242,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsClient(self.grpc_channel) @@ -251,7 +260,7 @@ def search_migratable_resources( Searches all of the resources in automl.googleapis.com, datalabeling.googleapis.com and - ml.googleapis.com that can be migrated to AI Platform's + ml.googleapis.com that can be migrated to Vertex AI's given location. Returns: @@ -282,7 +291,7 @@ def batch_migrate_resources( Batch migrates resources from ml.googleapis.com, automl.googleapis.com, and datalabeling.googleapis.com - to AI Platform (Unified). + to Vertex AI. Returns: Callable[[~.BatchMigrateResourcesRequest], @@ -302,5 +311,215 @@ def batch_migrate_resources( ) return self._stubs["batch_migrate_resources"] + def close(self): + self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + @property + def kind(self) -> str: + return "grpc" + __all__ = ("MigrationServiceGrpcTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/migration_service/transports/grpc_asyncio.py b/google/cloud/aiplatform_v1beta1/services/migration_service/transports/grpc_asyncio.py index e98ea4d789..c5d5eaf6d7 100644 --- a/google/cloud/aiplatform_v1beta1/services/migration_service/transports/grpc_asyncio.py +++ b/google/cloud/aiplatform_v1beta1/services/migration_service/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,17 +16,20 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore -from google.api_core import operations_v1 # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore from google.cloud.aiplatform_v1beta1.types import migration_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from .base import MigrationServiceTransport, DEFAULT_CLIENT_INFO from .grpc import MigrationServiceGrpcTransport @@ -36,8 +39,7 @@ class MigrationServiceGrpcAsyncIOTransport(MigrationServiceTransport): """gRPC AsyncIO backend transport for MigrationService. A service that migrates resources from automl.googleapis.com, - datalabeling.googleapis.com and ml.googleapis.com to AI - Platform. + datalabeling.googleapis.com and ml.googleapis.com to Vertex AI. This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation @@ -82,14 +84,14 @@ def create_channel( aio.Channel: A gRPC AsyncIO channel object. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @@ -107,6 +109,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -130,16 +133,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -148,6 +151,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport @@ -158,7 +163,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -200,13 +205,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -236,7 +245,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel @@ -256,7 +265,7 @@ def search_migratable_resources( Searches all of the resources in automl.googleapis.com, datalabeling.googleapis.com and - ml.googleapis.com that can be migrated to AI Platform's + ml.googleapis.com that can be migrated to Vertex AI's given location. Returns: @@ -288,7 +297,7 @@ def batch_migrate_resources( Batch migrates resources from ml.googleapis.com, automl.googleapis.com, and datalabeling.googleapis.com - to AI Platform (Unified). + to Vertex AI. Returns: Callable[[~.BatchMigrateResourcesRequest], @@ -308,5 +317,211 @@ def batch_migrate_resources( ) return self._stubs["batch_migrate_resources"] + def close(self): + return self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + __all__ = ("MigrationServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/model_service/__init__.py b/google/cloud/aiplatform_v1beta1/services/model_service/__init__.py index 7395b28fcb..d5781359f4 100644 --- a/google/cloud/aiplatform_v1beta1/services/model_service/__init__.py +++ b/google/cloud/aiplatform_v1beta1/services/model_service/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1beta1/services/model_service/async_client.py b/google/cloud/aiplatform_v1beta1/services/model_service/async_client.py index d4b8081ed8..882cec2da7 100644 --- a/google/cloud/aiplatform_v1beta1/services/model_service/async_client.py +++ b/google/cloud/aiplatform_v1beta1/services/model_service/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,16 +16,21 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation as gac_operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1beta1.services.model_service import pagers @@ -35,9 +40,16 @@ from google.cloud.aiplatform_v1beta1.types import model from google.cloud.aiplatform_v1beta1.types import model as gca_model from google.cloud.aiplatform_v1beta1.types import model_evaluation +from google.cloud.aiplatform_v1beta1.types import ( + model_evaluation as gca_model_evaluation, +) from google.cloud.aiplatform_v1beta1.types import model_evaluation_slice from google.cloud.aiplatform_v1beta1.types import model_service from google.cloud.aiplatform_v1beta1.types import operation as gca_operation +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import struct_pb2 # type: ignore @@ -48,7 +60,7 @@ class ModelServiceAsyncClient: - """A service for managing AI Platform's machine learning Models.""" + """A service for managing Vertex AI's machine learning Models.""" _client: ModelServiceClient @@ -96,7 +108,8 @@ class ModelServiceAsyncClient: @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -111,7 +124,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -126,9 +139,45 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return ModelServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> ModelServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: ModelServiceTransport: The transport used by the client instance. @@ -147,7 +196,7 @@ def __init__( client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the model service client. + """Instantiates the model service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -188,18 +237,45 @@ def __init__( async def upload_model( self, - request: model_service.UploadModelRequest = None, + request: Union[model_service.UploadModelRequest, dict] = None, *, parent: str = None, model: gca_model.Model = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: - r"""Uploads a Model artifact into AI Platform. + r"""Uploads a Model artifact into Vertex AI. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_upload_model(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + model = aiplatform_v1beta1.Model() + model.display_name = "display_name_value" + + request = aiplatform_v1beta1.UploadModelRequest( + parent="parent_value", + model=model, + ) + + # Make the request + operation = client.upload_model(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.UploadModelRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.UploadModelRequest, dict]): The request object. Request message for [ModelService.UploadModel][google.cloud.aiplatform.v1beta1.ModelService.UploadModel]. parent (:class:`str`): @@ -233,7 +309,7 @@ async def upload_model( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, model]) if request is not None and has_flattened_params: @@ -266,7 +342,12 @@ async def upload_model( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -281,23 +362,53 @@ async def upload_model( async def get_model( self, - request: model_service.GetModelRequest = None, + request: Union[model_service.GetModelRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> model.Model: r"""Gets a Model. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_get_model(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetModelRequest( + name="name_value", + ) + + # Make the request + response = await client.get_model(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.GetModelRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.GetModelRequest, dict]): The request object. Request message for [ModelService.GetModel][google.cloud.aiplatform.v1beta1.ModelService.GetModel]. name (:class:`str`): Required. The name of the Model resource. Format: ``projects/{project}/locations/{location}/models/{model}`` + In order to retrieve a specific version of the model, + also provide the version ID or version alias. Example: + ``projects/{project}/locations/{location}/models/{model}@2`` + or + ``projects/{project}/locations/{location}/models/{model}@golden`` + If no version ID or alias is specified, the "default" + version will be returned. The "default" version alias is + created for the first version of the model, and can be + moved to other versions later on. There will be exactly + one default version. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -312,7 +423,7 @@ async def get_model( A trained machine learning Model. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -343,24 +454,49 @@ async def get_model( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_models( self, - request: model_service.ListModelsRequest = None, + request: Union[model_service.ListModelsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListModelsAsyncPager: r"""Lists Models in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_list_models(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListModelsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_models(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ListModelsRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ListModelsRequest, dict]): The request object. Request message for [ModelService.ListModels][google.cloud.aiplatform.v1beta1.ModelService.ListModels]. parent (:class:`str`): @@ -387,7 +523,7 @@ async def list_models( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -418,12 +554,128 @@ async def list_models( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListModelsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def list_model_versions( + self, + request: Union[model_service.ListModelVersionsRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListModelVersionsAsyncPager: + r"""Lists versions of the specified model. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_list_model_versions(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListModelVersionsRequest( + name="name_value", + ) + + # Make the request + page_result = client.list_model_versions(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.ListModelVersionsRequest, dict]): + The request object. Request message for + [ModelService.ListModelVersions][google.cloud.aiplatform.v1beta1.ModelService.ListModelVersions]. + name (:class:`str`): + Required. The name of the model to + list versions for. + + 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: + google.cloud.aiplatform_v1beta1.services.model_service.pagers.ListModelVersionsAsyncPager: + Response message for + [ModelService.ListModelVersions][google.cloud.aiplatform.v1beta1.ModelService.ListModelVersions] + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = model_service.ListModelVersionsRequest(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.list_model_versions, + default_timeout=None, + 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, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListModelVersionsAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -431,23 +683,66 @@ async def list_models( async def update_model( self, - request: model_service.UpdateModelRequest = None, + request: Union[model_service.UpdateModelRequest, dict] = None, *, model: gca_model.Model = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_model.Model: r"""Updates a Model. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_update_model(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + model = aiplatform_v1beta1.Model() + model.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateModelRequest( + model=model, + ) + + # Make the request + response = await client.update_model(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.UpdateModelRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.UpdateModelRequest, dict]): The request object. Request message for [ModelService.UpdateModel][google.cloud.aiplatform.v1beta1.ModelService.UpdateModel]. model (:class:`google.cloud.aiplatform_v1beta1.types.Model`): - Required. The Model which replaces - the resource on the server. + Required. The Model which replaces the resource on the + server. When Model Versioning is enabled, the model.name + will be used to determine whether to update the model or + model version. + + 1. model.name with the @ value, e.g. models/123@1, + refers to a version specific update. + 2. model.name without the @ value, e.g. models/123, + refers to a model update. + 3. model.name with @-, e.g. models/123@-, refers to a + model update. + 4. Supported model fields: display_name, description; + supported version-specific fields: + version_description. Labels are supported in both + scenarios. Both the model labels and the version + labels are merged when a model is returned. When + updating labels, if the request is for model-specific + update, model label gets updated. Otherwise, version + labels get updated. + 5. A model name or model version name fields update + mismatch will cause a precondition error. + 6. One request cannot update both the model and the + version fields. You must update them separately. This corresponds to the ``model`` field on the ``request`` instance; if ``request`` is provided, this @@ -455,7 +750,7 @@ async def update_model( update_mask (:class:`google.protobuf.field_mask_pb2.FieldMask`): Required. The update mask applies to the resource. For the ``FieldMask`` definition, see - `FieldMask `__. + [google.protobuf.FieldMask][google.protobuf.FieldMask]. This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this @@ -471,7 +766,7 @@ async def update_model( A trained machine learning Model. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([model, update_mask]) if request is not None and has_flattened_params: @@ -506,34 +801,61 @@ async def update_model( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response - async def delete_model( + async def update_explanation_dataset( self, - request: model_service.DeleteModelRequest = None, + request: Union[model_service.UpdateExplanationDatasetRequest, dict] = None, *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + model: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: - r"""Deletes a Model. - Note: Model can only be deleted if there are no - DeployedModels created from it. + r"""Incrementally update the dataset used for an examples + model. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_update_explanation_dataset(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateExplanationDatasetRequest( + model="model_value", + ) + + # Make the request + operation = client.update_explanation_dataset(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.DeleteModelRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.UpdateExplanationDatasetRequest, dict]): The request object. Request message for - [ModelService.DeleteModel][google.cloud.aiplatform.v1beta1.ModelService.DeleteModel]. - name (:class:`str`): - Required. The name of the Model resource to be deleted. + [ModelService.UpdateExplanationDataset][google.cloud.aiplatform.v1beta1.ModelService.UpdateExplanationDataset]. + model (:class:`str`): + Required. The resource name of the Model to update. Format: ``projects/{project}/locations/{location}/models/{model}`` - This corresponds to the ``name`` field + This corresponds to the ``model`` 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, @@ -546,100 +868,117 @@ async def delete_model( google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. - The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated - empty messages in your APIs. A typical example is to - use it as the request or the response type of an API - method. For instance: - - service Foo { - rpc Bar(google.protobuf.Empty) returns - (google.protobuf.Empty); - - } - - The JSON representation for Empty is empty JSON - object {}. + The result type for the operation will be + :class:`google.cloud.aiplatform_v1beta1.types.UpdateExplanationDatasetResponse` + Response message of + [ModelService.UpdateExplanationDataset][google.cloud.aiplatform.v1beta1.ModelService.UpdateExplanationDataset] + operation. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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]) + has_flattened_params = any([model]) 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 = model_service.DeleteModelRequest(request) + request = model_service.UpdateExplanationDatasetRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: - request.name = name + if model is not None: + request.model = model # 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_model, - default_timeout=5.0, + self._client._transport.update_explanation_dataset, + default_timeout=None, 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),)), + gapic_v1.routing_header.to_grpc_metadata((("model", request.model),)), ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( response, self._client._transport.operations_client, - empty_pb2.Empty, - metadata_type=gca_operation.DeleteOperationMetadata, + model_service.UpdateExplanationDatasetResponse, + metadata_type=model_service.UpdateExplanationDatasetOperationMetadata, ) # Done; return the response. return response - async def export_model( + async def delete_model( self, - request: model_service.ExportModelRequest = None, + request: Union[model_service.DeleteModelRequest, dict] = None, *, name: str = None, - output_config: model_service.ExportModelRequest.OutputConfig = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: - r"""Exports a trained, exportable, Model to a location specified by - the user. A Model is considered to be exportable if it has at - least one [supported export - format][google.cloud.aiplatform.v1beta1.Model.supported_export_formats]. + r"""Deletes a Model. + + A model cannot be deleted if any + [Endpoint][google.cloud.aiplatform.v1beta1.Endpoint] resource + has a + [DeployedModel][google.cloud.aiplatform.v1beta1.DeployedModel] + based on the model in its + [deployed_models][google.cloud.aiplatform.v1beta1.Endpoint.deployed_models] + field. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_delete_model(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteModelRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_model(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ExportModelRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteModelRequest, dict]): The request object. Request message for - [ModelService.ExportModel][google.cloud.aiplatform.v1beta1.ModelService.ExportModel]. + [ModelService.DeleteModel][google.cloud.aiplatform.v1beta1.ModelService.DeleteModel]. name (:class:`str`): - Required. The resource name of the Model to export. + Required. The name of the Model resource to be deleted. Format: ``projects/{project}/locations/{location}/models/{model}`` This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - output_config (:class:`google.cloud.aiplatform_v1beta1.types.ExportModelRequest.OutputConfig`): - Required. The desired output location - and configuration. - - This corresponds to the ``output_config`` 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. @@ -650,36 +989,42 @@ async def export_model( google.api_core.operation_async.AsyncOperation: An object representing a long-running operation. - The result type for the operation will be - :class:`google.cloud.aiplatform_v1beta1.types.ExportModelResponse` - Response message of - [ModelService.ExportModel][google.cloud.aiplatform.v1beta1.ModelService.ExportModel] - operation. + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, output_config]) + 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 = model_service.ExportModelRequest(request) + request = model_service.DeleteModelRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if name is not None: request.name = name - if output_config is not None: - request.output_config = output_config # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( - self._client._transport.export_model, + self._client._transport.delete_model, default_timeout=5.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -691,38 +1036,74 @@ async def export_model( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( response, self._client._transport.operations_client, - model_service.ExportModelResponse, - metadata_type=model_service.ExportModelOperationMetadata, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, ) # Done; return the response. return response - async def get_model_evaluation( + async def delete_model_version( self, - request: model_service.GetModelEvaluationRequest = None, + request: Union[model_service.DeleteModelVersionRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> model_evaluation.ModelEvaluation: - r"""Gets a ModelEvaluation. + ) -> operation_async.AsyncOperation: + r"""Deletes a Model version. + + Model version can only be deleted if there are no + [DeployedModels][] created from it. Deleting the only version in + the Model is not allowed. Use + [DeleteModel][google.cloud.aiplatform.v1beta1.ModelService.DeleteModel] + for deleting the Model instead. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_delete_model_version(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteModelVersionRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_model_version(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.GetModelEvaluationRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteModelVersionRequest, dict]): The request object. Request message for - [ModelService.GetModelEvaluation][google.cloud.aiplatform.v1beta1.ModelService.GetModelEvaluation]. + [ModelService.DeleteModelVersion][google.cloud.aiplatform.v1beta1.ModelService.DeleteModelVersion]. name (:class:`str`): - Required. The name of the ModelEvaluation resource. - Format: - ``projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}`` + Required. The name of the model version to be deleted, + with a version ID explicitly included. + + Example: + ``projects/{project}/locations/{location}/models/{model}@1234`` This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -734,15 +1115,26 @@ async def get_model_evaluation( sent along with the request as metadata. Returns: - google.cloud.aiplatform_v1beta1.types.ModelEvaluation: - A collection of metrics calculated by - comparing Model's predictions on all of - the test data against annotations from - the test data. + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -751,7 +1143,7 @@ async def get_model_evaluation( "the individual field arguments should be set." ) - request = model_service.GetModelEvaluationRequest(request) + request = model_service.DeleteModelVersionRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. @@ -761,8 +1153,8 @@ async def get_model_evaluation( # 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_model_evaluation, - default_timeout=5.0, + self._client._transport.delete_model_version, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -773,32 +1165,88 @@ async def get_model_evaluation( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, + ) # Done; return the response. return response - async def list_model_evaluations( + async def merge_version_aliases( self, - request: model_service.ListModelEvaluationsRequest = None, + request: Union[model_service.MergeVersionAliasesRequest, dict] = None, *, - parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + name: str = None, + version_aliases: Sequence[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListModelEvaluationsAsyncPager: - r"""Lists ModelEvaluations in a Model. + ) -> model.Model: + r"""Merges a set of aliases for a Model version. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_merge_version_aliases(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.MergeVersionAliasesRequest( + name="name_value", + version_aliases=['version_aliases_value_1', 'version_aliases_value_2'], + ) + + # Make the request + response = await client.merge_version_aliases(request=request) + + # Handle the response + print(response) Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ListModelEvaluationsRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.MergeVersionAliasesRequest, dict]): The request object. Request message for - [ModelService.ListModelEvaluations][google.cloud.aiplatform.v1beta1.ModelService.ListModelEvaluations]. - parent (:class:`str`): - Required. The resource name of the Model to list the - ModelEvaluations from. Format: - ``projects/{project}/locations/{location}/models/{model}`` + [ModelService.MergeVersionAliases][google.cloud.aiplatform.v1beta1.ModelService.MergeVersionAliases]. + name (:class:`str`): + Required. The name of the model version to merge + aliases, with a version ID explicitly included. - This corresponds to the ``parent`` field + Example: + ``projects/{project}/locations/{location}/models/{model}@1234`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + version_aliases (:class:`Sequence[str]`): + Required. The set of version aliases to merge. The alias + should be at most 128 characters, and match + ``[a-z][a-z0-9-]{0,126}[a-z-0-9]``. Add the ``-`` prefix + to an alias means removing that alias from the version. + ``-`` is NOT counted in the 128 characters. Example: + ``-golden`` means removing the ``golden`` alias from the + version. + + There is NO ordering in aliases, which means + + 1) The aliases returned from GetModel API might not have + the exactly same order from this MergeVersionAliases + API. 2) Adding and deleting the same alias in the + request is not recommended, and the 2 operations will + be cancelled out. + + This corresponds to the ``version_aliases`` 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, @@ -808,80 +1256,113 @@ async def list_model_evaluations( sent along with the request as metadata. Returns: - google.cloud.aiplatform_v1beta1.services.model_service.pagers.ListModelEvaluationsAsyncPager: - Response message for - [ModelService.ListModelEvaluations][google.cloud.aiplatform.v1beta1.ModelService.ListModelEvaluations]. - - Iterating over this object will yield results and - resolve additional pages automatically. - + google.cloud.aiplatform_v1beta1.types.Model: + A trained machine learning Model. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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]) + has_flattened_params = any([name, version_aliases]) 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 = model_service.ListModelEvaluationsRequest(request) + request = model_service.MergeVersionAliasesRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: - request.parent = parent + if name is not None: + request.name = name + if version_aliases: + request.version_aliases.extend(version_aliases) # 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_model_evaluations, - default_timeout=5.0, + self._client._transport.merge_version_aliases, + default_timeout=None, 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),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) # 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.ListModelEvaluationsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) # Done; return the response. return response - async def get_model_evaluation_slice( + async def export_model( self, - request: model_service.GetModelEvaluationSliceRequest = None, + request: Union[model_service.ExportModelRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + output_config: model_service.ExportModelRequest.OutputConfig = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> model_evaluation_slice.ModelEvaluationSlice: - r"""Gets a ModelEvaluationSlice. + ) -> operation_async.AsyncOperation: + r"""Exports a trained, exportable Model to a location specified by + the user. A Model is considered to be exportable if it has at + least one [supported export + format][google.cloud.aiplatform.v1beta1.Model.supported_export_formats]. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_export_model(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ExportModelRequest( + name="name_value", + ) + + # Make the request + operation = client.export_model(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.GetModelEvaluationSliceRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ExportModelRequest, dict]): The request object. Request message for - [ModelService.GetModelEvaluationSlice][google.cloud.aiplatform.v1beta1.ModelService.GetModelEvaluationSlice]. + [ModelService.ExportModel][google.cloud.aiplatform.v1beta1.ModelService.ExportModel]. name (:class:`str`): - Required. The name of the ModelEvaluationSlice resource. - Format: - ``projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}/slices/{slice}`` + Required. The resource name of the + Model to export. The resource name may + contain version id or version alias to + specify the version, if no version is + specified, the default version will be + exported. This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. + output_config (:class:`google.cloud.aiplatform_v1beta1.types.ExportModelRequest.OutputConfig`): + Required. The desired output location + and configuration. + + This corresponds to the ``output_config`` 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. @@ -889,34 +1370,39 @@ async def get_model_evaluation_slice( sent along with the request as metadata. Returns: - google.cloud.aiplatform_v1beta1.types.ModelEvaluationSlice: - A collection of metrics calculated by - comparing Model's predictions on a slice - of the test data against ground truth - annotations. + google.api_core.operation_async.AsyncOperation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.aiplatform_v1beta1.types.ExportModelResponse` + Response message of + [ModelService.ExportModel][google.cloud.aiplatform.v1beta1.ModelService.ExportModel] + operation. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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]) + has_flattened_params = any([name, output_config]) 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 = model_service.GetModelEvaluationSliceRequest(request) + request = model_service.ExportModelRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if name is not None: request.name = name + if output_config is not None: + request.output_config = output_config # 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_model_evaluation_slice, + self._client._transport.export_model, default_timeout=5.0, client_info=DEFAULT_CLIENT_INFO, ) @@ -928,34 +1414,186 @@ async def get_model_evaluation_slice( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = operation_async.from_gapic( + response, + self._client._transport.operations_client, + model_service.ExportModelResponse, + metadata_type=model_service.ExportModelOperationMetadata, + ) # Done; return the response. return response - async def list_model_evaluation_slices( + async def import_model_evaluation( self, - request: model_service.ListModelEvaluationSlicesRequest = None, + request: Union[model_service.ImportModelEvaluationRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + model_evaluation: gca_model_evaluation.ModelEvaluation = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListModelEvaluationSlicesAsyncPager: - r"""Lists ModelEvaluationSlices in a ModelEvaluation. + ) -> gca_model_evaluation.ModelEvaluation: + r"""Imports an externally generated ModelEvaluation. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_import_model_evaluation(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ImportModelEvaluationRequest( + parent="parent_value", + ) + + # Make the request + response = await client.import_model_evaluation(request=request) + + # Handle the response + print(response) Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ListModelEvaluationSlicesRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ImportModelEvaluationRequest, dict]): The request object. Request message for - [ModelService.ListModelEvaluationSlices][google.cloud.aiplatform.v1beta1.ModelService.ListModelEvaluationSlices]. + [ModelService.ImportModelEvaluation][google.cloud.aiplatform.v1beta1.ModelService.ImportModelEvaluation] parent (:class:`str`): - Required. The resource name of the ModelEvaluation to - list the ModelEvaluationSlices from. Format: + Required. The name of the parent model resource. Format: + ``projects/{project}/locations/{location}/models/{model}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + model_evaluation (:class:`google.cloud.aiplatform_v1beta1.types.ModelEvaluation`): + Required. Model evaluation resource + to be imported. + + This corresponds to the ``model_evaluation`` 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: + google.cloud.aiplatform_v1beta1.types.ModelEvaluation: + A collection of metrics calculated by + comparing Model's predictions on all of + the test data against annotations from + the test data. + + """ + # Create or coerce a protobuf request object. + # Quick 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, model_evaluation]) + 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 = model_service.ImportModelEvaluationRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if model_evaluation is not None: + request.model_evaluation = model_evaluation + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.import_model_evaluation, + default_timeout=None, + 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 batch_import_model_evaluation_slices( + self, + request: Union[ + model_service.BatchImportModelEvaluationSlicesRequest, dict + ] = None, + *, + parent: str = None, + model_evaluation_slices: Sequence[ + model_evaluation_slice.ModelEvaluationSlice + ] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> model_service.BatchImportModelEvaluationSlicesResponse: + r"""Imports a list of externally generated + ModelEvaluationSlice. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_batch_import_model_evaluation_slices(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.BatchImportModelEvaluationSlicesRequest( + parent="parent_value", + ) + + # Make the request + response = await client.batch_import_model_evaluation_slices(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.BatchImportModelEvaluationSlicesRequest, dict]): + The request object. Request message for + [ModelService.BatchImportModelEvaluationSlices][google.cloud.aiplatform.v1beta1.ModelService.BatchImportModelEvaluationSlices] + parent (:class:`str`): + Required. The name of the parent ModelEvaluation + resource. Format: ``projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}`` This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. + model_evaluation_slices (:class:`Sequence[google.cloud.aiplatform_v1beta1.types.ModelEvaluationSlice]`): + Required. Model evaluation slice + resource to be imported. + + This corresponds to the ``model_evaluation_slices`` 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. @@ -963,36 +1601,35 @@ async def list_model_evaluation_slices( sent along with the request as metadata. Returns: - google.cloud.aiplatform_v1beta1.services.model_service.pagers.ListModelEvaluationSlicesAsyncPager: + google.cloud.aiplatform_v1beta1.types.BatchImportModelEvaluationSlicesResponse: Response message for - [ModelService.ListModelEvaluationSlices][google.cloud.aiplatform.v1beta1.ModelService.ListModelEvaluationSlices]. - - Iterating over this object will yield results and - resolve additional pages automatically. + [ModelService.BatchImportModelEvaluationSlices][google.cloud.aiplatform.v1beta1.ModelService.BatchImportModelEvaluationSlices] """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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]) + has_flattened_params = any([parent, model_evaluation_slices]) 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 = model_service.ListModelEvaluationSlicesRequest(request) + request = model_service.BatchImportModelEvaluationSlicesRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if parent is not None: request.parent = parent + if model_evaluation_slices: + request.model_evaluation_slices.extend(model_evaluation_slices) # 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_model_evaluation_slices, - default_timeout=5.0, + self._client._transport.batch_import_model_evaluation_slices, + default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -1003,17 +1640,1107 @@ async def list_model_evaluation_slices( ) # 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.ListModelEvaluationSlicesAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) # Done; return the response. return response + async def get_model_evaluation( + self, + request: Union[model_service.GetModelEvaluationRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> model_evaluation.ModelEvaluation: + r"""Gets a ModelEvaluation. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_get_model_evaluation(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetModelEvaluationRequest( + name="name_value", + ) + + # Make the request + response = await client.get_model_evaluation(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.GetModelEvaluationRequest, dict]): + The request object. Request message for + [ModelService.GetModelEvaluation][google.cloud.aiplatform.v1beta1.ModelService.GetModelEvaluation]. + name (:class:`str`): + Required. The name of the ModelEvaluation resource. + Format: + ``projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}`` + + 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: + google.cloud.aiplatform_v1beta1.types.ModelEvaluation: + A collection of metrics calculated by + comparing Model's predictions on all of + the test data against annotations from + the test data. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = model_service.GetModelEvaluationRequest(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_model_evaluation, + default_timeout=5.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 list_model_evaluations( + self, + request: Union[model_service.ListModelEvaluationsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListModelEvaluationsAsyncPager: + r"""Lists ModelEvaluations in a Model. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_list_model_evaluations(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListModelEvaluationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_model_evaluations(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.ListModelEvaluationsRequest, dict]): + The request object. Request message for + [ModelService.ListModelEvaluations][google.cloud.aiplatform.v1beta1.ModelService.ListModelEvaluations]. + parent (:class:`str`): + Required. The resource name of the Model to list the + ModelEvaluations from. Format: + ``projects/{project}/locations/{location}/models/{model}`` + + 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: + google.cloud.aiplatform_v1beta1.services.model_service.pagers.ListModelEvaluationsAsyncPager: + Response message for + [ModelService.ListModelEvaluations][google.cloud.aiplatform.v1beta1.ModelService.ListModelEvaluations]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = model_service.ListModelEvaluationsRequest(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_model_evaluations, + default_timeout=5.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.ListModelEvaluationsAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_model_evaluation_slice( + self, + request: Union[model_service.GetModelEvaluationSliceRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> model_evaluation_slice.ModelEvaluationSlice: + r"""Gets a ModelEvaluationSlice. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_get_model_evaluation_slice(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetModelEvaluationSliceRequest( + name="name_value", + ) + + # Make the request + response = await client.get_model_evaluation_slice(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.GetModelEvaluationSliceRequest, dict]): + The request object. Request message for + [ModelService.GetModelEvaluationSlice][google.cloud.aiplatform.v1beta1.ModelService.GetModelEvaluationSlice]. + name (:class:`str`): + Required. The name of the ModelEvaluationSlice resource. + Format: + ``projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}/slices/{slice}`` + + 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: + google.cloud.aiplatform_v1beta1.types.ModelEvaluationSlice: + A collection of metrics calculated by + comparing Model's predictions on a slice + of the test data against ground truth + annotations. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = model_service.GetModelEvaluationSliceRequest(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_model_evaluation_slice, + default_timeout=5.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 list_model_evaluation_slices( + self, + request: Union[model_service.ListModelEvaluationSlicesRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListModelEvaluationSlicesAsyncPager: + r"""Lists ModelEvaluationSlices in a ModelEvaluation. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_list_model_evaluation_slices(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListModelEvaluationSlicesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_model_evaluation_slices(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.ListModelEvaluationSlicesRequest, dict]): + The request object. Request message for + [ModelService.ListModelEvaluationSlices][google.cloud.aiplatform.v1beta1.ModelService.ListModelEvaluationSlices]. + parent (:class:`str`): + Required. The resource name of the ModelEvaluation to + list the ModelEvaluationSlices from. Format: + ``projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}`` + + 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: + google.cloud.aiplatform_v1beta1.services.model_service.pagers.ListModelEvaluationSlicesAsyncPager: + Response message for + [ModelService.ListModelEvaluationSlices][google.cloud.aiplatform.v1beta1.ModelService.ListModelEvaluationSlices]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 = model_service.ListModelEvaluationSlicesRequest(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_model_evaluation_slices, + default_timeout=5.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.ListModelEvaluationSlicesAsyncPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_operations, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.delete_operation, + default_timeout=None, + 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 cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + 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 wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.wait_operation, + default_timeout=None, + 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 set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_location, + default_timeout=None, + 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 list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_locations, + default_timeout=None, + 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 __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/aiplatform_v1beta1/services/model_service/client.py b/google/cloud/aiplatform_v1beta1/services/model_service/client.py index 413426bcba..8ea3b0e4d2 100644 --- a/google/cloud/aiplatform_v1beta1/services/model_service/client.py +++ b/google/cloud/aiplatform_v1beta1/services/model_service/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,22 +14,26 @@ # 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 +from typing import Dict, Mapping, 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 as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_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 +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation as gac_operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1beta1.services.model_service import pagers @@ -39,9 +43,16 @@ from google.cloud.aiplatform_v1beta1.types import model from google.cloud.aiplatform_v1beta1.types import model as gca_model from google.cloud.aiplatform_v1beta1.types import model_evaluation +from google.cloud.aiplatform_v1beta1.types import ( + model_evaluation as gca_model_evaluation, +) from google.cloud.aiplatform_v1beta1.types import model_evaluation_slice from google.cloud.aiplatform_v1beta1.types import model_service from google.cloud.aiplatform_v1beta1.types import operation as gca_operation +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import struct_pb2 # type: ignore @@ -63,8 +74,11 @@ class ModelServiceClientMeta(type): _transport_registry["grpc"] = ModelServiceGrpcTransport _transport_registry["grpc_asyncio"] = ModelServiceGrpcAsyncIOTransport - def get_transport_class(cls, label: str = None,) -> Type[ModelServiceTransport]: - """Return an appropriate transport class. + def get_transport_class( + cls, + label: str = None, + ) -> Type[ModelServiceTransport]: + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -83,11 +97,12 @@ def get_transport_class(cls, label: str = None,) -> Type[ModelServiceTransport]: class ModelServiceClient(metaclass=ModelServiceClientMeta): - """A service for managing AI Platform's machine learning Models.""" + """A service for managing Vertex AI's machine learning Models.""" @staticmethod def _get_default_mtls_endpoint(api_endpoint): - """Convert api endpoint to mTLS endpoint. + """Converts api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. Args: @@ -121,7 +136,8 @@ def _get_default_mtls_endpoint(api_endpoint): @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -138,7 +154,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -157,23 +173,30 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> ModelServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - ModelServiceTransport: The transport used by the client instance. + ModelServiceTransport: The transport used by the client + instance. """ return self._transport @staticmethod - def endpoint_path(project: str, location: str, endpoint: str,) -> str: - """Return a fully-qualified endpoint string.""" + def endpoint_path( + project: str, + location: str, + endpoint: str, + ) -> str: + """Returns a fully-qualified endpoint string.""" return "projects/{project}/locations/{location}/endpoints/{endpoint}".format( - project=project, location=location, endpoint=endpoint, + project=project, + location=location, + endpoint=endpoint, ) @staticmethod def parse_endpoint_path(path: str) -> Dict[str, str]: - """Parse a endpoint path into its component segments.""" + """Parses a endpoint path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/endpoints/(?P.+?)$", path, @@ -181,15 +204,21 @@ def parse_endpoint_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def model_path(project: str, location: str, model: str,) -> str: - """Return a fully-qualified model string.""" + def model_path( + project: str, + location: str, + model: str, + ) -> str: + """Returns a fully-qualified model string.""" return "projects/{project}/locations/{location}/models/{model}".format( - project=project, location=location, model=model, + project=project, + location=location, + model=model, ) @staticmethod def parse_model_path(path: str) -> Dict[str, str]: - """Parse a model path into its component segments.""" + """Parses a model path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/models/(?P.+?)$", path, @@ -198,16 +227,22 @@ def parse_model_path(path: str) -> Dict[str, str]: @staticmethod def model_evaluation_path( - project: str, location: str, model: str, evaluation: str, + project: str, + location: str, + model: str, + evaluation: str, ) -> str: - """Return a fully-qualified model_evaluation string.""" + """Returns a fully-qualified model_evaluation string.""" return "projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}".format( - project=project, location=location, model=model, evaluation=evaluation, + project=project, + location=location, + model=model, + evaluation=evaluation, ) @staticmethod def parse_model_evaluation_path(path: str) -> Dict[str, str]: - """Parse a model_evaluation path into its component segments.""" + """Parses a model_evaluation path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/models/(?P.+?)/evaluations/(?P.+?)$", path, @@ -216,9 +251,13 @@ def parse_model_evaluation_path(path: str) -> Dict[str, str]: @staticmethod def model_evaluation_slice_path( - project: str, location: str, model: str, evaluation: str, slice: str, + project: str, + location: str, + model: str, + evaluation: str, + slice: str, ) -> str: - """Return a fully-qualified model_evaluation_slice string.""" + """Returns a fully-qualified model_evaluation_slice string.""" return "projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}/slices/{slice}".format( project=project, location=location, @@ -229,7 +268,7 @@ def model_evaluation_slice_path( @staticmethod def parse_model_evaluation_slice_path(path: str) -> Dict[str, str]: - """Parse a model_evaluation_slice path into its component segments.""" + """Parses a model_evaluation_slice path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/models/(?P.+?)/evaluations/(?P.+?)/slices/(?P.+?)$", path, @@ -238,16 +277,20 @@ def parse_model_evaluation_slice_path(path: str) -> Dict[str, str]: @staticmethod def training_pipeline_path( - project: str, location: str, training_pipeline: str, + project: str, + location: str, + training_pipeline: str, ) -> str: - """Return a fully-qualified training_pipeline string.""" + """Returns a fully-qualified training_pipeline string.""" return "projects/{project}/locations/{location}/trainingPipelines/{training_pipeline}".format( - project=project, location=location, training_pipeline=training_pipeline, + project=project, + location=location, + training_pipeline=training_pipeline, ) @staticmethod def parse_training_pipeline_path(path: str) -> Dict[str, str]: - """Parse a training_pipeline path into its component segments.""" + """Parses a training_pipeline path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/trainingPipelines/(?P.+?)$", path, @@ -255,8 +298,10 @@ def parse_training_pipeline_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + def common_billing_account_path( + billing_account: str, + ) -> str: + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -268,9 +313,13 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: 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,) + def common_folder_path( + folder: str, + ) -> str: + """Returns a fully-qualified folder string.""" + return "folders/{folder}".format( + folder=folder, + ) @staticmethod def parse_common_folder_path(path: str) -> Dict[str, str]: @@ -279,9 +328,13 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: 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,) + def common_organization_path( + organization: str, + ) -> str: + """Returns a fully-qualified organization string.""" + return "organizations/{organization}".format( + organization=organization, + ) @staticmethod def parse_common_organization_path(path: str) -> Dict[str, str]: @@ -290,9 +343,13 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: 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,) + def common_project_path( + project: str, + ) -> str: + """Returns a fully-qualified project string.""" + return "projects/{project}".format( + project=project, + ) @staticmethod def parse_common_project_path(path: str) -> Dict[str, str]: @@ -301,10 +358,14 @@ def parse_common_project_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_location_path(project: str, location: str,) -> str: - """Return a fully-qualified location string.""" + def common_location_path( + project: str, + location: str, + ) -> str: + """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) @staticmethod @@ -313,6 +374,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + def __init__( self, *, @@ -321,7 +449,7 @@ def __init__( client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the model service client. + """Instantiates the model service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -363,58 +491,42 @@ def __init__( 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")) + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - client_cert_source_func = ( - mtls.default_client_cert_source() 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" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # 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, ModelServiceTransport): # transport is a ModelServiceTransport instance. - if credentials or client_options.credentials_file: + if credentials or client_options.credentials_file or api_key_value: 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." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + Transport = type(self).get_transport_class(transport) self._transport = Transport( credentials=credentials, @@ -424,22 +536,50 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, + always_use_jwt_access=True, ) def upload_model( self, - request: model_service.UploadModelRequest = None, + request: Union[model_service.UploadModelRequest, dict] = None, *, parent: str = None, model: gca_model.Model = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: - r"""Uploads a Model artifact into AI Platform. + r"""Uploads a Model artifact into Vertex AI. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_upload_model(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + model = aiplatform_v1beta1.Model() + model.display_name = "display_name_value" + + request = aiplatform_v1beta1.UploadModelRequest( + parent="parent_value", + model=model, + ) + + # Make the request + operation = client.upload_model(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) Args: - request (google.cloud.aiplatform_v1beta1.types.UploadModelRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.UploadModelRequest, dict]): The request object. Request message for [ModelService.UploadModel][google.cloud.aiplatform.v1beta1.ModelService.UploadModel]. parent (str): @@ -473,7 +613,7 @@ def upload_model( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, model]) if request is not None and has_flattened_params: @@ -506,7 +646,12 @@ def upload_model( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -521,23 +666,53 @@ def upload_model( def get_model( self, - request: model_service.GetModelRequest = None, + request: Union[model_service.GetModelRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> model.Model: r"""Gets a Model. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_get_model(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetModelRequest( + name="name_value", + ) + + # Make the request + response = client.get_model(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.GetModelRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.GetModelRequest, dict]): The request object. Request message for [ModelService.GetModel][google.cloud.aiplatform.v1beta1.ModelService.GetModel]. name (str): Required. The name of the Model resource. Format: ``projects/{project}/locations/{location}/models/{model}`` + In order to retrieve a specific version of the model, + also provide the version ID or version alias. Example: + ``projects/{project}/locations/{location}/models/{model}@2`` + or + ``projects/{project}/locations/{location}/models/{model}@golden`` + If no version ID or alias is specified, the "default" + version will be returned. The "default" version alias is + created for the first version of the model, and can be + moved to other versions later on. There will be exactly + one default version. + This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. @@ -552,7 +727,7 @@ def get_model( A trained machine learning Model. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -583,24 +758,49 @@ def get_model( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_models( self, - request: model_service.ListModelsRequest = None, + request: Union[model_service.ListModelsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListModelsPager: r"""Lists Models in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_list_models(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListModelsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_models(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ListModelsRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ListModelsRequest, dict]): The request object. Request message for [ModelService.ListModels][google.cloud.aiplatform.v1beta1.ModelService.ListModels]. parent (str): @@ -627,7 +827,7 @@ def list_models( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -658,12 +858,128 @@ def list_models( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListModelsPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_model_versions( + self, + request: Union[model_service.ListModelVersionsRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListModelVersionsPager: + r"""Lists versions of the specified model. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_list_model_versions(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListModelVersionsRequest( + name="name_value", + ) + + # Make the request + page_result = client.list_model_versions(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.ListModelVersionsRequest, dict]): + The request object. Request message for + [ModelService.ListModelVersions][google.cloud.aiplatform.v1beta1.ModelService.ListModelVersions]. + name (str): + Required. The name of the model to + list versions for. + + 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: + google.cloud.aiplatform_v1beta1.services.model_service.pagers.ListModelVersionsPager: + Response message for + [ModelService.ListModelVersions][google.cloud.aiplatform.v1beta1.ModelService.ListModelVersions] + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 model_service.ListModelVersionsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, model_service.ListModelVersionsRequest): + request = model_service.ListModelVersionsRequest(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.list_model_versions] + + # 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, + ) + + # This method is paged; wrap the response in a pager, which provides + # an `__iter__` convenience method. + response = pagers.ListModelVersionsPager( + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -671,23 +987,66 @@ def list_models( def update_model( self, - request: model_service.UpdateModelRequest = None, + request: Union[model_service.UpdateModelRequest, dict] = None, *, model: gca_model.Model = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_model.Model: r"""Updates a Model. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_update_model(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + model = aiplatform_v1beta1.Model() + model.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateModelRequest( + model=model, + ) + + # Make the request + response = client.update_model(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.UpdateModelRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.UpdateModelRequest, dict]): The request object. Request message for [ModelService.UpdateModel][google.cloud.aiplatform.v1beta1.ModelService.UpdateModel]. model (google.cloud.aiplatform_v1beta1.types.Model): - Required. The Model which replaces - the resource on the server. + Required. The Model which replaces the resource on the + server. When Model Versioning is enabled, the model.name + will be used to determine whether to update the model or + model version. + + 1. model.name with the @ value, e.g. models/123@1, + refers to a version specific update. + 2. model.name without the @ value, e.g. models/123, + refers to a model update. + 3. model.name with @-, e.g. models/123@-, refers to a + model update. + 4. Supported model fields: display_name, description; + supported version-specific fields: + version_description. Labels are supported in both + scenarios. Both the model labels and the version + labels are merged when a model is returned. When + updating labels, if the request is for model-specific + update, model label gets updated. Otherwise, version + labels get updated. + 5. A model name or model version name fields update + mismatch will cause a precondition error. + 6. One request cannot update both the model and the + version fields. You must update them separately. This corresponds to the ``model`` field on the ``request`` instance; if ``request`` is provided, this @@ -695,7 +1054,7 @@ def update_model( update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. The update mask applies to the resource. For the ``FieldMask`` definition, see - `FieldMask `__. + [google.protobuf.FieldMask][google.protobuf.FieldMask]. This corresponds to the ``update_mask`` field on the ``request`` instance; if ``request`` is provided, this @@ -711,7 +1070,7 @@ def update_model( A trained machine learning Model. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([model, update_mask]) if request is not None and has_flattened_params: @@ -746,34 +1105,61 @@ def update_model( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response - def delete_model( + def update_explanation_dataset( self, - request: model_service.DeleteModelRequest = None, + request: Union[model_service.UpdateExplanationDatasetRequest, dict] = None, *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + model: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: - r"""Deletes a Model. - Note: Model can only be deleted if there are no - DeployedModels created from it. + r"""Incrementally update the dataset used for an examples + model. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_update_explanation_dataset(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateExplanationDatasetRequest( + model="model_value", + ) + + # Make the request + operation = client.update_explanation_dataset(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) Args: - request (google.cloud.aiplatform_v1beta1.types.DeleteModelRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.UpdateExplanationDatasetRequest, dict]): The request object. Request message for - [ModelService.DeleteModel][google.cloud.aiplatform.v1beta1.ModelService.DeleteModel]. - name (str): - Required. The name of the Model resource to be deleted. + [ModelService.UpdateExplanationDataset][google.cloud.aiplatform.v1beta1.ModelService.UpdateExplanationDataset]. + model (str): + Required. The resource name of the Model to update. Format: ``projects/{project}/locations/{location}/models/{model}`` - This corresponds to the ``name`` field + This corresponds to the ``model`` 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, @@ -786,25 +1172,17 @@ def delete_model( google.api_core.operation.Operation: An object representing a long-running operation. - The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated - empty messages in your APIs. A typical example is to - use it as the request or the response type of an API - method. For instance: - - service Foo { - rpc Bar(google.protobuf.Empty) returns - (google.protobuf.Empty); - - } - - The JSON representation for Empty is empty JSON - object {}. + The result type for the operation will be + :class:`google.cloud.aiplatform_v1beta1.types.UpdateExplanationDatasetResponse` + Response message of + [ModelService.UpdateExplanationDataset][google.cloud.aiplatform.v1beta1.ModelService.UpdateExplanationDataset] + operation. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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]) + has_flattened_params = any([model]) if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " @@ -812,74 +1190,101 @@ def delete_model( ) # Minor optimization to avoid making a copy if the user passes - # in a model_service.DeleteModelRequest. + # in a model_service.UpdateExplanationDatasetRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. - if not isinstance(request, model_service.DeleteModelRequest): - request = model_service.DeleteModelRequest(request) + if not isinstance(request, model_service.UpdateExplanationDatasetRequest): + request = model_service.UpdateExplanationDatasetRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. - if name is not None: - request.name = name + if model is not None: + request.model = model # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.delete_model] + rpc = self._transport._wrapped_methods[ + self._transport.update_explanation_dataset + ] # 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),)), + gapic_v1.routing_header.to_grpc_metadata((("model", request.model),)), ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( response, self._transport.operations_client, - empty_pb2.Empty, - metadata_type=gca_operation.DeleteOperationMetadata, + model_service.UpdateExplanationDatasetResponse, + metadata_type=model_service.UpdateExplanationDatasetOperationMetadata, ) # Done; return the response. return response - def export_model( + def delete_model( self, - request: model_service.ExportModelRequest = None, + request: Union[model_service.DeleteModelRequest, dict] = None, *, name: str = None, - output_config: model_service.ExportModelRequest.OutputConfig = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: - r"""Exports a trained, exportable, Model to a location specified by - the user. A Model is considered to be exportable if it has at - least one [supported export - format][google.cloud.aiplatform.v1beta1.Model.supported_export_formats]. + r"""Deletes a Model. + + A model cannot be deleted if any + [Endpoint][google.cloud.aiplatform.v1beta1.Endpoint] resource + has a + [DeployedModel][google.cloud.aiplatform.v1beta1.DeployedModel] + based on the model in its + [deployed_models][google.cloud.aiplatform.v1beta1.Endpoint.deployed_models] + field. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_delete_model(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteModelRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_model(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) Args: - request (google.cloud.aiplatform_v1beta1.types.ExportModelRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteModelRequest, dict]): The request object. Request message for - [ModelService.ExportModel][google.cloud.aiplatform.v1beta1.ModelService.ExportModel]. + [ModelService.DeleteModel][google.cloud.aiplatform.v1beta1.ModelService.DeleteModel]. name (str): - Required. The resource name of the Model to export. + Required. The name of the Model resource to be deleted. Format: ``projects/{project}/locations/{location}/models/{model}`` This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - output_config (google.cloud.aiplatform_v1beta1.types.ExportModelRequest.OutputConfig): - Required. The desired output location - and configuration. - - This corresponds to the ``output_config`` 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. @@ -890,17 +1295,25 @@ def export_model( google.api_core.operation.Operation: An object representing a long-running operation. - The result type for the operation will be - :class:`google.cloud.aiplatform_v1beta1.types.ExportModelResponse` - Response message of - [ModelService.ExportModel][google.cloud.aiplatform.v1beta1.ModelService.ExportModel] - operation. + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, output_config]) + 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 " @@ -908,21 +1321,19 @@ def export_model( ) # Minor optimization to avoid making a copy if the user passes - # in a model_service.ExportModelRequest. + # in a model_service.DeleteModelRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. - if not isinstance(request, model_service.ExportModelRequest): - request = model_service.ExportModelRequest(request) + if not isinstance(request, model_service.DeleteModelRequest): + request = model_service.DeleteModelRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if name is not None: request.name = name - if output_config is not None: - request.output_config = output_config # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.export_model] + rpc = self._transport._wrapped_methods[self._transport.delete_model] # Certain fields should be provided within the metadata header; # add these here. @@ -931,38 +1342,74 @@ def export_model( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( response, self._transport.operations_client, - model_service.ExportModelResponse, - metadata_type=model_service.ExportModelOperationMetadata, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, ) # Done; return the response. return response - def get_model_evaluation( + def delete_model_version( self, - request: model_service.GetModelEvaluationRequest = None, + request: Union[model_service.DeleteModelVersionRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> model_evaluation.ModelEvaluation: - r"""Gets a ModelEvaluation. + ) -> gac_operation.Operation: + r"""Deletes a Model version. + + Model version can only be deleted if there are no + [DeployedModels][] created from it. Deleting the only version in + the Model is not allowed. Use + [DeleteModel][google.cloud.aiplatform.v1beta1.ModelService.DeleteModel] + for deleting the Model instead. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_delete_model_version(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteModelVersionRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_model_version(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) Args: - request (google.cloud.aiplatform_v1beta1.types.GetModelEvaluationRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteModelVersionRequest, dict]): The request object. Request message for - [ModelService.GetModelEvaluation][google.cloud.aiplatform.v1beta1.ModelService.GetModelEvaluation]. + [ModelService.DeleteModelVersion][google.cloud.aiplatform.v1beta1.ModelService.DeleteModelVersion]. name (str): - Required. The name of the ModelEvaluation resource. - Format: - ``projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}`` + Required. The name of the model version to be deleted, + with a version ID explicitly included. + + Example: + ``projects/{project}/locations/{location}/models/{model}@1234`` This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this @@ -974,15 +1421,26 @@ def get_model_evaluation( sent along with the request as metadata. Returns: - google.cloud.aiplatform_v1beta1.types.ModelEvaluation: - A collection of metrics calculated by - comparing Model's predictions on all of - the test data against annotations from - the test data. + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be :class:`google.protobuf.empty_pb2.Empty` A generic empty message that you can re-use to avoid defining duplicated + empty messages in your APIs. A typical example is to + use it as the request or the response type of an API + method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns + (google.protobuf.Empty); + + } + + The JSON representation for Empty is empty JSON + object {}. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -992,11 +1450,11 @@ def get_model_evaluation( ) # Minor optimization to avoid making a copy if the user passes - # in a model_service.GetModelEvaluationRequest. + # in a model_service.DeleteModelVersionRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. - if not isinstance(request, model_service.GetModelEvaluationRequest): - request = model_service.GetModelEvaluationRequest(request) + if not isinstance(request, model_service.DeleteModelVersionRequest): + request = model_service.DeleteModelVersionRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if name is not None: @@ -1004,7 +1462,7 @@ def get_model_evaluation( # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.get_model_evaluation] + rpc = self._transport._wrapped_methods[self._transport.delete_model_version] # Certain fields should be provided within the metadata header; # add these here. @@ -1013,32 +1471,88 @@ def get_model_evaluation( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + empty_pb2.Empty, + metadata_type=gca_operation.DeleteOperationMetadata, + ) # Done; return the response. return response - def list_model_evaluations( + def merge_version_aliases( self, - request: model_service.ListModelEvaluationsRequest = None, + request: Union[model_service.MergeVersionAliasesRequest, dict] = None, *, - parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + name: str = None, + version_aliases: Sequence[str] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListModelEvaluationsPager: - r"""Lists ModelEvaluations in a Model. + ) -> model.Model: + r"""Merges a set of aliases for a Model version. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_merge_version_aliases(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.MergeVersionAliasesRequest( + name="name_value", + version_aliases=['version_aliases_value_1', 'version_aliases_value_2'], + ) + + # Make the request + response = client.merge_version_aliases(request=request) + + # Handle the response + print(response) Args: - request (google.cloud.aiplatform_v1beta1.types.ListModelEvaluationsRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.MergeVersionAliasesRequest, dict]): The request object. Request message for - [ModelService.ListModelEvaluations][google.cloud.aiplatform.v1beta1.ModelService.ListModelEvaluations]. - parent (str): - Required. The resource name of the Model to list the - ModelEvaluations from. Format: - ``projects/{project}/locations/{location}/models/{model}`` + [ModelService.MergeVersionAliases][google.cloud.aiplatform.v1beta1.ModelService.MergeVersionAliases]. + name (str): + Required. The name of the model version to merge + aliases, with a version ID explicitly included. - This corresponds to the ``parent`` field + Example: + ``projects/{project}/locations/{location}/models/{model}@1234`` + + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + version_aliases (Sequence[str]): + Required. The set of version aliases to merge. The alias + should be at most 128 characters, and match + ``[a-z][a-z0-9-]{0,126}[a-z-0-9]``. Add the ``-`` prefix + to an alias means removing that alias from the version. + ``-`` is NOT counted in the 128 characters. Example: + ``-golden`` means removing the ``golden`` alias from the + version. + + There is NO ordering in aliases, which means + + 1) The aliases returned from GetModel API might not have + the exactly same order from this MergeVersionAliases + API. 2) Adding and deleting the same alias in the + request is not recommended, and the 2 operations will + be cancelled out. + + This corresponds to the ``version_aliases`` 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, @@ -1048,18 +1562,13 @@ def list_model_evaluations( sent along with the request as metadata. Returns: - google.cloud.aiplatform_v1beta1.services.model_service.pagers.ListModelEvaluationsPager: - Response message for - [ModelService.ListModelEvaluations][google.cloud.aiplatform.v1beta1.ModelService.ListModelEvaluations]. - - Iterating over this object will yield results and - resolve additional pages automatically. - + google.cloud.aiplatform_v1beta1.types.Model: + A trained machine learning Model. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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]) + has_flattened_params = any([name, version_aliases]) if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " @@ -1067,61 +1576,99 @@ def list_model_evaluations( ) # Minor optimization to avoid making a copy if the user passes - # in a model_service.ListModelEvaluationsRequest. + # in a model_service.MergeVersionAliasesRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. - if not isinstance(request, model_service.ListModelEvaluationsRequest): - request = model_service.ListModelEvaluationsRequest(request) + if not isinstance(request, model_service.MergeVersionAliasesRequest): + request = model_service.MergeVersionAliasesRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. - if parent is not None: - request.parent = parent + if name is not None: + request.name = name + if version_aliases is not None: + request.version_aliases = version_aliases # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = self._transport._wrapped_methods[self._transport.list_model_evaluations] + rpc = self._transport._wrapped_methods[self._transport.merge_version_aliases] # 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),)), + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), ) # 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.ListModelEvaluationsPager( - method=rpc, request=request, response=response, metadata=metadata, + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) # Done; return the response. return response - def get_model_evaluation_slice( + def export_model( self, - request: model_service.GetModelEvaluationSliceRequest = None, + request: Union[model_service.ExportModelRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + output_config: model_service.ExportModelRequest.OutputConfig = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> model_evaluation_slice.ModelEvaluationSlice: - r"""Gets a ModelEvaluationSlice. + ) -> gac_operation.Operation: + r"""Exports a trained, exportable Model to a location specified by + the user. A Model is considered to be exportable if it has at + least one [supported export + format][google.cloud.aiplatform.v1beta1.Model.supported_export_formats]. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_export_model(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ExportModelRequest( + name="name_value", + ) + + # Make the request + operation = client.export_model(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) Args: - request (google.cloud.aiplatform_v1beta1.types.GetModelEvaluationSliceRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ExportModelRequest, dict]): The request object. Request message for - [ModelService.GetModelEvaluationSlice][google.cloud.aiplatform.v1beta1.ModelService.GetModelEvaluationSlice]. + [ModelService.ExportModel][google.cloud.aiplatform.v1beta1.ModelService.ExportModel]. name (str): - Required. The name of the ModelEvaluationSlice resource. - Format: - ``projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}/slices/{slice}`` + Required. The resource name of the + Model to export. The resource name may + contain version id or version alias to + specify the version, if no version is + specified, the default version will be + exported. This corresponds to the ``name`` field on the ``request`` instance; if ``request`` is provided, this should not be set. + output_config (google.cloud.aiplatform_v1beta1.types.ExportModelRequest.OutputConfig): + Required. The desired output location + and configuration. + + This corresponds to the ``output_config`` 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. @@ -1129,17 +1676,20 @@ def get_model_evaluation_slice( sent along with the request as metadata. Returns: - google.cloud.aiplatform_v1beta1.types.ModelEvaluationSlice: - A collection of metrics calculated by - comparing Model's predictions on a slice - of the test data against ground truth - annotations. + google.api_core.operation.Operation: + An object representing a long-running operation. + + The result type for the operation will be + :class:`google.cloud.aiplatform_v1beta1.types.ExportModelResponse` + Response message of + [ModelService.ExportModel][google.cloud.aiplatform.v1beta1.ModelService.ExportModel] + operation. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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]) + has_flattened_params = any([name, output_config]) if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " @@ -1147,21 +1697,21 @@ def get_model_evaluation_slice( ) # Minor optimization to avoid making a copy if the user passes - # in a model_service.GetModelEvaluationSliceRequest. + # in a model_service.ExportModelRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. - if not isinstance(request, model_service.GetModelEvaluationSliceRequest): - request = model_service.GetModelEvaluationSliceRequest(request) + if not isinstance(request, model_service.ExportModelRequest): + request = model_service.ExportModelRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if name is not None: request.name = name + if output_config is not None: + request.output_config = output_config # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = self._transport._wrapped_methods[ - self._transport.get_model_evaluation_slice - ] + rpc = self._transport._wrapped_methods[self._transport.export_model] # Certain fields should be provided within the metadata header; # add these here. @@ -1170,34 +1720,73 @@ def get_model_evaluation_slice( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Wrap the response in an operation future. + response = gac_operation.from_gapic( + response, + self._transport.operations_client, + model_service.ExportModelResponse, + metadata_type=model_service.ExportModelOperationMetadata, + ) # Done; return the response. return response - def list_model_evaluation_slices( + def import_model_evaluation( self, - request: model_service.ListModelEvaluationSlicesRequest = None, + request: Union[model_service.ImportModelEvaluationRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + model_evaluation: gca_model_evaluation.ModelEvaluation = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ListModelEvaluationSlicesPager: - r"""Lists ModelEvaluationSlices in a ModelEvaluation. + ) -> gca_model_evaluation.ModelEvaluation: + r"""Imports an externally generated ModelEvaluation. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_import_model_evaluation(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ImportModelEvaluationRequest( + parent="parent_value", + ) + + # Make the request + response = client.import_model_evaluation(request=request) + + # Handle the response + print(response) Args: - request (google.cloud.aiplatform_v1beta1.types.ListModelEvaluationSlicesRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ImportModelEvaluationRequest, dict]): The request object. Request message for - [ModelService.ListModelEvaluationSlices][google.cloud.aiplatform.v1beta1.ModelService.ListModelEvaluationSlices]. + [ModelService.ImportModelEvaluation][google.cloud.aiplatform.v1beta1.ModelService.ImportModelEvaluation] parent (str): - Required. The resource name of the ModelEvaluation to - list the ModelEvaluationSlices from. Format: - ``projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}`` + Required. The name of the parent model resource. Format: + ``projects/{project}/locations/{location}/models/{model}`` This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. + model_evaluation (google.cloud.aiplatform_v1beta1.types.ModelEvaluation): + Required. Model evaluation resource + to be imported. + + This corresponds to the ``model_evaluation`` 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. @@ -1205,18 +1794,17 @@ def list_model_evaluation_slices( sent along with the request as metadata. Returns: - google.cloud.aiplatform_v1beta1.services.model_service.pagers.ListModelEvaluationSlicesPager: - Response message for - [ModelService.ListModelEvaluationSlices][google.cloud.aiplatform.v1beta1.ModelService.ListModelEvaluationSlices]. - - Iterating over this object will yield results and - resolve additional pages automatically. + google.cloud.aiplatform_v1beta1.types.ModelEvaluation: + A collection of metrics calculated by + comparing Model's predictions on all of + the test data against annotations from + the test data. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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]) + has_flattened_params = any([parent, model_evaluation]) if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " @@ -1224,21 +1812,21 @@ def list_model_evaluation_slices( ) # Minor optimization to avoid making a copy if the user passes - # in a model_service.ListModelEvaluationSlicesRequest. + # in a model_service.ImportModelEvaluationRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. - if not isinstance(request, model_service.ListModelEvaluationSlicesRequest): - request = model_service.ListModelEvaluationSlicesRequest(request) + if not isinstance(request, model_service.ImportModelEvaluationRequest): + request = model_service.ImportModelEvaluationRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if parent is not None: request.parent = parent + if model_evaluation is not None: + request.model_evaluation = model_evaluation # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. - rpc = self._transport._wrapped_methods[ - self._transport.list_model_evaluation_slices - ] + rpc = self._transport._wrapped_methods[self._transport.import_model_evaluation] # Certain fields should be provided within the metadata header; # add these here. @@ -1247,12 +1835,1228 @@ def list_model_evaluation_slices( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListModelEvaluationSlicesPager( - method=rpc, request=request, response=response, metadata=metadata, + # Done; return the response. + return response + + def batch_import_model_evaluation_slices( + self, + request: Union[ + model_service.BatchImportModelEvaluationSlicesRequest, dict + ] = None, + *, + parent: str = None, + model_evaluation_slices: Sequence[ + model_evaluation_slice.ModelEvaluationSlice + ] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> model_service.BatchImportModelEvaluationSlicesResponse: + r"""Imports a list of externally generated + ModelEvaluationSlice. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_batch_import_model_evaluation_slices(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.BatchImportModelEvaluationSlicesRequest( + parent="parent_value", + ) + + # Make the request + response = client.batch_import_model_evaluation_slices(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.BatchImportModelEvaluationSlicesRequest, dict]): + The request object. Request message for + [ModelService.BatchImportModelEvaluationSlices][google.cloud.aiplatform.v1beta1.ModelService.BatchImportModelEvaluationSlices] + parent (str): + Required. The name of the parent ModelEvaluation + resource. Format: + ``projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + model_evaluation_slices (Sequence[google.cloud.aiplatform_v1beta1.types.ModelEvaluationSlice]): + Required. Model evaluation slice + resource to be imported. + + This corresponds to the ``model_evaluation_slices`` 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: + google.cloud.aiplatform_v1beta1.types.BatchImportModelEvaluationSlicesResponse: + Response message for + [ModelService.BatchImportModelEvaluationSlices][google.cloud.aiplatform.v1beta1.ModelService.BatchImportModelEvaluationSlices] + + """ + # Create or coerce a protobuf request object. + # Quick 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, model_evaluation_slices]) + 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 model_service.BatchImportModelEvaluationSlicesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, model_service.BatchImportModelEvaluationSlicesRequest + ): + request = model_service.BatchImportModelEvaluationSlicesRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if model_evaluation_slices is not None: + request.model_evaluation_slices = model_evaluation_slices + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.batch_import_model_evaluation_slices + ] + + # 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 get_model_evaluation( + self, + request: Union[model_service.GetModelEvaluationRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> model_evaluation.ModelEvaluation: + r"""Gets a ModelEvaluation. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_get_model_evaluation(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetModelEvaluationRequest( + name="name_value", + ) + + # Make the request + response = client.get_model_evaluation(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.GetModelEvaluationRequest, dict]): + The request object. Request message for + [ModelService.GetModelEvaluation][google.cloud.aiplatform.v1beta1.ModelService.GetModelEvaluation]. + name (str): + Required. The name of the ModelEvaluation resource. + Format: + ``projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}`` + + 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: + google.cloud.aiplatform_v1beta1.types.ModelEvaluation: + A collection of metrics calculated by + comparing Model's predictions on all of + the test data against annotations from + the test data. + + """ + # Create or coerce a protobuf request object. + # Quick 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 model_service.GetModelEvaluationRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, model_service.GetModelEvaluationRequest): + request = model_service.GetModelEvaluationRequest(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_model_evaluation] + + # 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 list_model_evaluations( + self, + request: Union[model_service.ListModelEvaluationsRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListModelEvaluationsPager: + r"""Lists ModelEvaluations in a Model. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_list_model_evaluations(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListModelEvaluationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_model_evaluations(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.ListModelEvaluationsRequest, dict]): + The request object. Request message for + [ModelService.ListModelEvaluations][google.cloud.aiplatform.v1beta1.ModelService.ListModelEvaluations]. + parent (str): + Required. The resource name of the Model to list the + ModelEvaluations from. Format: + ``projects/{project}/locations/{location}/models/{model}`` + + 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: + google.cloud.aiplatform_v1beta1.services.model_service.pagers.ListModelEvaluationsPager: + Response message for + [ModelService.ListModelEvaluations][google.cloud.aiplatform.v1beta1.ModelService.ListModelEvaluations]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 model_service.ListModelEvaluationsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, model_service.ListModelEvaluationsRequest): + request = model_service.ListModelEvaluationsRequest(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_model_evaluations] + + # 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.ListModelEvaluationsPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_model_evaluation_slice( + self, + request: Union[model_service.GetModelEvaluationSliceRequest, dict] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> model_evaluation_slice.ModelEvaluationSlice: + r"""Gets a ModelEvaluationSlice. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_get_model_evaluation_slice(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetModelEvaluationSliceRequest( + name="name_value", + ) + + # Make the request + response = client.get_model_evaluation_slice(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.GetModelEvaluationSliceRequest, dict]): + The request object. Request message for + [ModelService.GetModelEvaluationSlice][google.cloud.aiplatform.v1beta1.ModelService.GetModelEvaluationSlice]. + name (str): + Required. The name of the ModelEvaluationSlice resource. + Format: + ``projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}/slices/{slice}`` + + 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: + google.cloud.aiplatform_v1beta1.types.ModelEvaluationSlice: + A collection of metrics calculated by + comparing Model's predictions on a slice + of the test data against ground truth + annotations. + + """ + # Create or coerce a protobuf request object. + # Quick 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 model_service.GetModelEvaluationSliceRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, model_service.GetModelEvaluationSliceRequest): + request = model_service.GetModelEvaluationSliceRequest(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_model_evaluation_slice + ] + + # 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 list_model_evaluation_slices( + self, + request: Union[model_service.ListModelEvaluationSlicesRequest, dict] = None, + *, + parent: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListModelEvaluationSlicesPager: + r"""Lists ModelEvaluationSlices in a ModelEvaluation. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_list_model_evaluation_slices(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListModelEvaluationSlicesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_model_evaluation_slices(request=request) + + # Handle the response + for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.ListModelEvaluationSlicesRequest, dict]): + The request object. Request message for + [ModelService.ListModelEvaluationSlices][google.cloud.aiplatform.v1beta1.ModelService.ListModelEvaluationSlices]. + parent (str): + Required. The resource name of the ModelEvaluation to + list the ModelEvaluationSlices from. Format: + ``projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}`` + + 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: + google.cloud.aiplatform_v1beta1.services.model_service.pagers.ListModelEvaluationSlicesPager: + Response message for + [ModelService.ListModelEvaluationSlices][google.cloud.aiplatform.v1beta1.ModelService.ListModelEvaluationSlices]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Quick 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 model_service.ListModelEvaluationSlicesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, model_service.ListModelEvaluationSlicesRequest): + request = model_service.ListModelEvaluationSlicesRequest(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_model_evaluation_slices + ] + + # 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.ListModelEvaluationSlicesPager( + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_operations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.delete_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.wait_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_location, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_locations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) # Done; return the response. diff --git a/google/cloud/aiplatform_v1beta1/services/model_service/pagers.py b/google/cloud/aiplatform_v1beta1/services/model_service/pagers.py index ea9f49f5ab..5c6dd885ff 100644 --- a/google/cloud/aiplatform_v1beta1/services/model_service/pagers.py +++ b/google/cloud/aiplatform_v1beta1/services/model_service/pagers.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,13 +15,13 @@ # from typing import ( Any, - AsyncIterable, + AsyncIterator, Awaitable, Callable, - Iterable, Sequence, Tuple, Optional, + Iterator, ) from google.cloud.aiplatform_v1beta1.types import model @@ -77,14 +77,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[model_service.ListModelsResponse]: + def pages(self) -> Iterator[model_service.ListModelsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[model.Model]: + def __iter__(self) -> Iterator[model.Model]: for page in self.pages: yield from page.models @@ -118,7 +118,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -139,14 +139,142 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - async def pages(self) -> AsyncIterable[model_service.ListModelsResponse]: + async def pages(self) -> AsyncIterator[model_service.ListModelsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = await self._method(self._request, metadata=self._metadata) + yield self._response + + def __aiter__(self) -> AsyncIterator[model.Model]: + async def async_generator(): + async for page in self.pages: + for response in page.models: + yield response + + return async_generator() + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListModelVersionsPager: + """A pager for iterating through ``list_model_versions`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1beta1.types.ListModelVersionsResponse` object, and + provides an ``__iter__`` method to iterate through its + ``models`` field. + + If there are more pages, the ``__iter__`` method will make additional + ``ListModelVersions`` requests and continue to iterate + through the ``models`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1beta1.types.ListModelVersionsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., model_service.ListModelVersionsResponse], + request: model_service.ListModelVersionsRequest, + response: model_service.ListModelVersionsResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiate the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1beta1.types.ListModelVersionsRequest): + The initial request object. + response (google.cloud.aiplatform_v1beta1.types.ListModelVersionsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = model_service.ListModelVersionsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + def pages(self) -> Iterator[model_service.ListModelVersionsResponse]: + yield self._response + while self._response.next_page_token: + self._request.page_token = self._response.next_page_token + self._response = self._method(self._request, metadata=self._metadata) + yield self._response + + def __iter__(self) -> Iterator[model.Model]: + for page in self.pages: + yield from page.models + + def __repr__(self) -> str: + return "{0}<{1!r}>".format(self.__class__.__name__, self._response) + + +class ListModelVersionsAsyncPager: + """A pager for iterating through ``list_model_versions`` requests. + + This class thinly wraps an initial + :class:`google.cloud.aiplatform_v1beta1.types.ListModelVersionsResponse` object, and + provides an ``__aiter__`` method to iterate through its + ``models`` field. + + If there are more pages, the ``__aiter__`` method will make additional + ``ListModelVersions`` requests and continue to iterate + through the ``models`` field on the + corresponding responses. + + All the usual :class:`google.cloud.aiplatform_v1beta1.types.ListModelVersionsResponse` + attributes are available on the pager. If multiple requests are made, only + the most recent response is retained, and thus used for attribute lookup. + """ + + def __init__( + self, + method: Callable[..., Awaitable[model_service.ListModelVersionsResponse]], + request: model_service.ListModelVersionsRequest, + response: model_service.ListModelVersionsResponse, + *, + metadata: Sequence[Tuple[str, str]] = () + ): + """Instantiates the pager. + + Args: + method (Callable): The method that was originally called, and + which instantiated this pager. + request (google.cloud.aiplatform_v1beta1.types.ListModelVersionsRequest): + The initial request object. + response (google.cloud.aiplatform_v1beta1.types.ListModelVersionsResponse): + The initial response object. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + self._method = method + self._request = model_service.ListModelVersionsRequest(request) + self._response = response + self._metadata = metadata + + def __getattr__(self, name: str) -> Any: + return getattr(self._response, name) + + @property + async def pages(self) -> AsyncIterator[model_service.ListModelVersionsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[model.Model]: + def __aiter__(self) -> AsyncIterator[model.Model]: async def async_generator(): async for page in self.pages: for response in page.models: @@ -205,14 +333,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[model_service.ListModelEvaluationsResponse]: + def pages(self) -> Iterator[model_service.ListModelEvaluationsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[model_evaluation.ModelEvaluation]: + def __iter__(self) -> Iterator[model_evaluation.ModelEvaluation]: for page in self.pages: yield from page.model_evaluations @@ -246,7 +374,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -267,14 +395,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - async def pages(self) -> AsyncIterable[model_service.ListModelEvaluationsResponse]: + async def pages(self) -> AsyncIterator[model_service.ListModelEvaluationsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[model_evaluation.ModelEvaluation]: + def __aiter__(self) -> AsyncIterator[model_evaluation.ModelEvaluation]: async def async_generator(): async for page in self.pages: for response in page.model_evaluations: @@ -333,14 +461,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[model_service.ListModelEvaluationSlicesResponse]: + def pages(self) -> Iterator[model_service.ListModelEvaluationSlicesResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[model_evaluation_slice.ModelEvaluationSlice]: + def __iter__(self) -> Iterator[model_evaluation_slice.ModelEvaluationSlice]: for page in self.pages: yield from page.model_evaluation_slices @@ -376,7 +504,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -399,14 +527,14 @@ def __getattr__(self, name: str) -> Any: @property async def pages( self, - ) -> AsyncIterable[model_service.ListModelEvaluationSlicesResponse]: + ) -> AsyncIterator[model_service.ListModelEvaluationSlicesResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[model_evaluation_slice.ModelEvaluationSlice]: + def __aiter__(self) -> AsyncIterator[model_evaluation_slice.ModelEvaluationSlice]: async def async_generator(): async for page in self.pages: for response in page.model_evaluation_slices: diff --git a/google/cloud/aiplatform_v1beta1/services/model_service/transports/__init__.py b/google/cloud/aiplatform_v1beta1/services/model_service/transports/__init__.py index 656b644033..ab55f592b6 100644 --- a/google/cloud/aiplatform_v1beta1/services/model_service/transports/__init__.py +++ b/google/cloud/aiplatform_v1beta1/services/model_service/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1beta1/services/model_service/transports/base.py b/google/cloud/aiplatform_v1beta1/services/model_service/transports/base.py index 3dd6e890c7..49271a4fdc 100644 --- a/google/cloud/aiplatform_v1beta1/services/model_service/transports/base.py +++ b/google/cloud/aiplatform_v1beta1/services/model_service/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,22 +15,29 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.api_core import operations_v1 # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.aiplatform_v1beta1.types import model from google.cloud.aiplatform_v1beta1.types import model as gca_model from google.cloud.aiplatform_v1beta1.types import model_evaluation +from google.cloud.aiplatform_v1beta1.types import ( + model_evaluation as gca_model_evaluation, +) from google.cloud.aiplatform_v1beta1.types import model_evaluation_slice from google.cloud.aiplatform_v1beta1.types import model_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore try: @@ -42,17 +49,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - -_API_CORE_VERSION = google.api_core.__version__ - class ModelServiceTransport(abc.ABC): """Abstract transport class for ModelService.""" @@ -70,6 +66,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -93,16 +90,19 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -115,83 +115,89 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id ) - # Save the credentials. - self._credentials = credentials - - # TODO(busunkim): These two class methods are in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-api-core - # and google-auth are increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") - ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs - - # TODO: Remove this function once google-api-core >= 1.26.0 is required - @classmethod - def _get_self_signed_jwt_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Union[Optional[Sequence[str]], str]]: - """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" - - self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} - - if _API_CORE_VERSION and ( - packaging.version.parse(_API_CORE_VERSION) - >= packaging.version.parse("1.26.0") + # If the credentials are service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") ): - self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES - self_signed_jwt_kwargs["scopes"] = scopes - self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST - else: - self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES + credentials = credentials.with_always_use_jwt_access(True) - return self_signed_jwt_kwargs + # Save the credentials. + self._credentials = credentials def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { self.upload_model: gapic_v1.method.wrap_method( - self.upload_model, default_timeout=5.0, client_info=client_info, + self.upload_model, + default_timeout=5.0, + client_info=client_info, ), self.get_model: gapic_v1.method.wrap_method( - self.get_model, default_timeout=5.0, client_info=client_info, + self.get_model, + default_timeout=5.0, + client_info=client_info, ), self.list_models: gapic_v1.method.wrap_method( - self.list_models, default_timeout=5.0, client_info=client_info, + self.list_models, + default_timeout=5.0, + client_info=client_info, + ), + self.list_model_versions: gapic_v1.method.wrap_method( + self.list_model_versions, + default_timeout=None, + client_info=client_info, ), self.update_model: gapic_v1.method.wrap_method( - self.update_model, default_timeout=5.0, client_info=client_info, + self.update_model, + default_timeout=5.0, + client_info=client_info, + ), + self.update_explanation_dataset: gapic_v1.method.wrap_method( + self.update_explanation_dataset, + default_timeout=None, + client_info=client_info, ), self.delete_model: gapic_v1.method.wrap_method( - self.delete_model, default_timeout=5.0, client_info=client_info, + self.delete_model, + default_timeout=5.0, + client_info=client_info, + ), + self.delete_model_version: gapic_v1.method.wrap_method( + self.delete_model_version, + default_timeout=None, + client_info=client_info, + ), + self.merge_version_aliases: gapic_v1.method.wrap_method( + self.merge_version_aliases, + default_timeout=None, + client_info=client_info, ), self.export_model: gapic_v1.method.wrap_method( - self.export_model, default_timeout=5.0, client_info=client_info, + self.export_model, + default_timeout=5.0, + client_info=client_info, + ), + self.import_model_evaluation: gapic_v1.method.wrap_method( + self.import_model_evaluation, + default_timeout=None, + client_info=client_info, + ), + self.batch_import_model_evaluation_slices: gapic_v1.method.wrap_method( + self.batch_import_model_evaluation_slices, + default_timeout=None, + client_info=client_info, ), self.get_model_evaluation: gapic_v1.method.wrap_method( - self.get_model_evaluation, default_timeout=5.0, client_info=client_info, + self.get_model_evaluation, + default_timeout=5.0, + client_info=client_info, ), self.list_model_evaluations: gapic_v1.method.wrap_method( self.list_model_evaluations, @@ -210,8 +216,17 @@ def _prep_wrapped_messages(self, client_info): ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() @@ -244,6 +259,18 @@ def list_models( ]: raise NotImplementedError() + @property + def list_model_versions( + self, + ) -> Callable[ + [model_service.ListModelVersionsRequest], + Union[ + model_service.ListModelVersionsResponse, + Awaitable[model_service.ListModelVersionsResponse], + ], + ]: + raise NotImplementedError() + @property def update_model( self, @@ -253,6 +280,15 @@ def update_model( ]: raise NotImplementedError() + @property + def update_explanation_dataset( + self, + ) -> Callable[ + [model_service.UpdateExplanationDatasetRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + @property def delete_model( self, @@ -262,6 +298,24 @@ def delete_model( ]: raise NotImplementedError() + @property + def delete_model_version( + self, + ) -> Callable[ + [model_service.DeleteModelVersionRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def merge_version_aliases( + self, + ) -> Callable[ + [model_service.MergeVersionAliasesRequest], + Union[model.Model, Awaitable[model.Model]], + ]: + raise NotImplementedError() + @property def export_model( self, @@ -271,6 +325,30 @@ def export_model( ]: raise NotImplementedError() + @property + def import_model_evaluation( + self, + ) -> Callable[ + [model_service.ImportModelEvaluationRequest], + Union[ + gca_model_evaluation.ModelEvaluation, + Awaitable[gca_model_evaluation.ModelEvaluation], + ], + ]: + raise NotImplementedError() + + @property + def batch_import_model_evaluation_slices( + self, + ) -> Callable[ + [model_service.BatchImportModelEvaluationSlicesRequest], + Union[ + model_service.BatchImportModelEvaluationSlicesResponse, + Awaitable[model_service.BatchImportModelEvaluationSlicesResponse], + ], + ]: + raise NotImplementedError() + @property def get_model_evaluation( self, @@ -319,5 +397,102 @@ def list_model_evaluation_slices( ]: raise NotImplementedError() + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], + Union[ + operations_pb2.ListOperationsResponse, + Awaitable[operations_pb2.ListOperationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None,]: + raise NotImplementedError() + + @property + def wait_operation( + self, + ) -> Callable[ + [operations_pb2.WaitOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def set_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def get_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_location( + self, + ) -> Callable[ + [locations_pb2.GetLocationRequest], + Union[locations_pb2.Location, Awaitable[locations_pb2.Location]], + ]: + raise NotImplementedError() + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], + Union[ + locations_pb2.ListLocationsResponse, + Awaitable[locations_pb2.ListLocationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + __all__ = ("ModelServiceTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/model_service/transports/grpc.py b/google/cloud/aiplatform_v1beta1/services/model_service/transports/grpc.py index 1fe74c535e..7ece07df70 100644 --- a/google/cloud/aiplatform_v1beta1/services/model_service/transports/grpc.py +++ b/google/cloud/aiplatform_v1beta1/services/model_service/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,9 +16,9 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import operations_v1 +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -28,8 +28,15 @@ from google.cloud.aiplatform_v1beta1.types import model from google.cloud.aiplatform_v1beta1.types import model as gca_model from google.cloud.aiplatform_v1beta1.types import model_evaluation +from google.cloud.aiplatform_v1beta1.types import ( + model_evaluation as gca_model_evaluation, +) from google.cloud.aiplatform_v1beta1.types import model_evaluation_slice from google.cloud.aiplatform_v1beta1.types import model_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from .base import ModelServiceTransport, DEFAULT_CLIENT_INFO @@ -37,7 +44,7 @@ class ModelServiceGrpcTransport(ModelServiceTransport): """gRPC backend transport for ModelService. - A service for managing AI Platform's machine learning Models. + A service for managing Vertex AI's machine learning Models. This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation @@ -63,6 +70,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -85,16 +93,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -103,6 +111,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport @@ -113,7 +123,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -156,13 +166,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -211,21 +225,20 @@ def create_channel( and ``credentials_file`` are passed. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @property def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ + """Return the channel designed to connect to this service.""" return self._grpc_channel @property @@ -235,7 +248,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsClient(self.grpc_channel) @@ -248,7 +261,7 @@ def upload_model( ) -> Callable[[model_service.UploadModelRequest], operations_pb2.Operation]: r"""Return a callable for the upload model method over gRPC. - Uploads a Model artifact into AI Platform. + Uploads a Model artifact into Vertex AI. Returns: Callable[[~.UploadModelRequest], @@ -318,6 +331,35 @@ def list_models( ) return self._stubs["list_models"] + @property + def list_model_versions( + self, + ) -> Callable[ + [model_service.ListModelVersionsRequest], + model_service.ListModelVersionsResponse, + ]: + r"""Return a callable for the list model versions method over gRPC. + + Lists versions of the specified model. + + Returns: + Callable[[~.ListModelVersionsRequest], + ~.ListModelVersionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_model_versions" not in self._stubs: + self._stubs["list_model_versions"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1beta1.ModelService/ListModelVersions", + request_serializer=model_service.ListModelVersionsRequest.serialize, + response_deserializer=model_service.ListModelVersionsResponse.deserialize, + ) + return self._stubs["list_model_versions"] + @property def update_model( self, @@ -344,6 +386,35 @@ def update_model( ) return self._stubs["update_model"] + @property + def update_explanation_dataset( + self, + ) -> Callable[ + [model_service.UpdateExplanationDatasetRequest], operations_pb2.Operation + ]: + r"""Return a callable for the update explanation dataset method over gRPC. + + Incrementally update the dataset used for an examples + model. + + Returns: + Callable[[~.UpdateExplanationDatasetRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_explanation_dataset" not in self._stubs: + self._stubs["update_explanation_dataset"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1beta1.ModelService/UpdateExplanationDataset", + request_serializer=model_service.UpdateExplanationDatasetRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["update_explanation_dataset"] + @property def delete_model( self, @@ -351,8 +422,14 @@ def delete_model( r"""Return a callable for the delete model method over gRPC. Deletes a Model. - Note: Model can only be deleted if there are no - DeployedModels created from it. + + A model cannot be deleted if any + [Endpoint][google.cloud.aiplatform.v1beta1.Endpoint] resource + has a + [DeployedModel][google.cloud.aiplatform.v1beta1.DeployedModel] + based on the model in its + [deployed_models][google.cloud.aiplatform.v1beta1.Endpoint.deployed_models] + field. Returns: Callable[[~.DeleteModelRequest], @@ -372,13 +449,71 @@ def delete_model( ) return self._stubs["delete_model"] + @property + def delete_model_version( + self, + ) -> Callable[[model_service.DeleteModelVersionRequest], operations_pb2.Operation]: + r"""Return a callable for the delete model version method over gRPC. + + Deletes a Model version. + + Model version can only be deleted if there are no + [DeployedModels][] created from it. Deleting the only version in + the Model is not allowed. Use + [DeleteModel][google.cloud.aiplatform.v1beta1.ModelService.DeleteModel] + for deleting the Model instead. + + Returns: + Callable[[~.DeleteModelVersionRequest], + ~.Operation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_model_version" not in self._stubs: + self._stubs["delete_model_version"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1beta1.ModelService/DeleteModelVersion", + request_serializer=model_service.DeleteModelVersionRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_model_version"] + + @property + def merge_version_aliases( + self, + ) -> Callable[[model_service.MergeVersionAliasesRequest], model.Model]: + r"""Return a callable for the merge version aliases method over gRPC. + + Merges a set of aliases for a Model version. + + Returns: + Callable[[~.MergeVersionAliasesRequest], + ~.Model]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "merge_version_aliases" not in self._stubs: + self._stubs["merge_version_aliases"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1beta1.ModelService/MergeVersionAliases", + request_serializer=model_service.MergeVersionAliasesRequest.serialize, + response_deserializer=model.Model.deserialize, + ) + return self._stubs["merge_version_aliases"] + @property def export_model( self, ) -> Callable[[model_service.ExportModelRequest], operations_pb2.Operation]: r"""Return a callable for the export model method over gRPC. - Exports a trained, exportable, Model to a location specified by + Exports a trained, exportable Model to a location specified by the user. A Model is considered to be exportable if it has at least one [supported export format][google.cloud.aiplatform.v1beta1.Model.supported_export_formats]. @@ -401,6 +536,68 @@ def export_model( ) return self._stubs["export_model"] + @property + def import_model_evaluation( + self, + ) -> Callable[ + [model_service.ImportModelEvaluationRequest], + gca_model_evaluation.ModelEvaluation, + ]: + r"""Return a callable for the import model evaluation method over gRPC. + + Imports an externally generated ModelEvaluation. + + Returns: + Callable[[~.ImportModelEvaluationRequest], + ~.ModelEvaluation]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "import_model_evaluation" not in self._stubs: + self._stubs["import_model_evaluation"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1beta1.ModelService/ImportModelEvaluation", + request_serializer=model_service.ImportModelEvaluationRequest.serialize, + response_deserializer=gca_model_evaluation.ModelEvaluation.deserialize, + ) + return self._stubs["import_model_evaluation"] + + @property + def batch_import_model_evaluation_slices( + self, + ) -> Callable[ + [model_service.BatchImportModelEvaluationSlicesRequest], + model_service.BatchImportModelEvaluationSlicesResponse, + ]: + r"""Return a callable for the batch import model evaluation + slices method over gRPC. + + Imports a list of externally generated + ModelEvaluationSlice. + + Returns: + Callable[[~.BatchImportModelEvaluationSlicesRequest], + ~.BatchImportModelEvaluationSlicesResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "batch_import_model_evaluation_slices" not in self._stubs: + self._stubs[ + "batch_import_model_evaluation_slices" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1beta1.ModelService/BatchImportModelEvaluationSlices", + request_serializer=model_service.BatchImportModelEvaluationSlicesRequest.serialize, + response_deserializer=model_service.BatchImportModelEvaluationSlicesResponse.deserialize, + ) + return self._stubs["batch_import_model_evaluation_slices"] + @property def get_model_evaluation( self, @@ -516,5 +713,215 @@ def list_model_evaluation_slices( ) return self._stubs["list_model_evaluation_slices"] + def close(self): + self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + @property + def kind(self) -> str: + return "grpc" + __all__ = ("ModelServiceGrpcTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/model_service/transports/grpc_asyncio.py b/google/cloud/aiplatform_v1beta1/services/model_service/transports/grpc_asyncio.py index 3e56398431..730ab1d150 100644 --- a/google/cloud/aiplatform_v1beta1/services/model_service/transports/grpc_asyncio.py +++ b/google/cloud/aiplatform_v1beta1/services/model_service/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,12 +16,11 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore -from google.api_core import operations_v1 # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore @@ -29,8 +28,15 @@ from google.cloud.aiplatform_v1beta1.types import model from google.cloud.aiplatform_v1beta1.types import model as gca_model from google.cloud.aiplatform_v1beta1.types import model_evaluation +from google.cloud.aiplatform_v1beta1.types import ( + model_evaluation as gca_model_evaluation, +) from google.cloud.aiplatform_v1beta1.types import model_evaluation_slice from google.cloud.aiplatform_v1beta1.types import model_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from .base import ModelServiceTransport, DEFAULT_CLIENT_INFO from .grpc import ModelServiceGrpcTransport @@ -39,7 +45,7 @@ class ModelServiceGrpcAsyncIOTransport(ModelServiceTransport): """gRPC AsyncIO backend transport for ModelService. - A service for managing AI Platform's machine learning Models. + A service for managing Vertex AI's machine learning Models. This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation @@ -84,14 +90,14 @@ def create_channel( aio.Channel: A gRPC AsyncIO channel object. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @@ -109,6 +115,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -132,16 +139,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -150,6 +157,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport @@ -160,7 +169,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -202,13 +211,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -238,7 +251,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel @@ -255,7 +268,7 @@ def upload_model( ]: r"""Return a callable for the upload model method over gRPC. - Uploads a Model artifact into AI Platform. + Uploads a Model artifact into Vertex AI. Returns: Callable[[~.UploadModelRequest], @@ -329,6 +342,35 @@ def list_models( ) return self._stubs["list_models"] + @property + def list_model_versions( + self, + ) -> Callable[ + [model_service.ListModelVersionsRequest], + Awaitable[model_service.ListModelVersionsResponse], + ]: + r"""Return a callable for the list model versions method over gRPC. + + Lists versions of the specified model. + + Returns: + Callable[[~.ListModelVersionsRequest], + Awaitable[~.ListModelVersionsResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_model_versions" not in self._stubs: + self._stubs["list_model_versions"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1beta1.ModelService/ListModelVersions", + request_serializer=model_service.ListModelVersionsRequest.serialize, + response_deserializer=model_service.ListModelVersionsResponse.deserialize, + ) + return self._stubs["list_model_versions"] + @property def update_model( self, @@ -355,6 +397,36 @@ def update_model( ) return self._stubs["update_model"] + @property + def update_explanation_dataset( + self, + ) -> Callable[ + [model_service.UpdateExplanationDatasetRequest], + Awaitable[operations_pb2.Operation], + ]: + r"""Return a callable for the update explanation dataset method over gRPC. + + Incrementally update the dataset used for an examples + model. + + Returns: + Callable[[~.UpdateExplanationDatasetRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "update_explanation_dataset" not in self._stubs: + self._stubs["update_explanation_dataset"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1beta1.ModelService/UpdateExplanationDataset", + request_serializer=model_service.UpdateExplanationDatasetRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["update_explanation_dataset"] + @property def delete_model( self, @@ -364,8 +436,14 @@ def delete_model( r"""Return a callable for the delete model method over gRPC. Deletes a Model. - Note: Model can only be deleted if there are no - DeployedModels created from it. + + A model cannot be deleted if any + [Endpoint][google.cloud.aiplatform.v1beta1.Endpoint] resource + has a + [DeployedModel][google.cloud.aiplatform.v1beta1.DeployedModel] + based on the model in its + [deployed_models][google.cloud.aiplatform.v1beta1.Endpoint.deployed_models] + field. Returns: Callable[[~.DeleteModelRequest], @@ -385,6 +463,66 @@ def delete_model( ) return self._stubs["delete_model"] + @property + def delete_model_version( + self, + ) -> Callable[ + [model_service.DeleteModelVersionRequest], Awaitable[operations_pb2.Operation] + ]: + r"""Return a callable for the delete model version method over gRPC. + + Deletes a Model version. + + Model version can only be deleted if there are no + [DeployedModels][] created from it. Deleting the only version in + the Model is not allowed. Use + [DeleteModel][google.cloud.aiplatform.v1beta1.ModelService.DeleteModel] + for deleting the Model instead. + + Returns: + Callable[[~.DeleteModelVersionRequest], + Awaitable[~.Operation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_model_version" not in self._stubs: + self._stubs["delete_model_version"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1beta1.ModelService/DeleteModelVersion", + request_serializer=model_service.DeleteModelVersionRequest.serialize, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["delete_model_version"] + + @property + def merge_version_aliases( + self, + ) -> Callable[[model_service.MergeVersionAliasesRequest], Awaitable[model.Model]]: + r"""Return a callable for the merge version aliases method over gRPC. + + Merges a set of aliases for a Model version. + + Returns: + Callable[[~.MergeVersionAliasesRequest], + Awaitable[~.Model]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "merge_version_aliases" not in self._stubs: + self._stubs["merge_version_aliases"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1beta1.ModelService/MergeVersionAliases", + request_serializer=model_service.MergeVersionAliasesRequest.serialize, + response_deserializer=model.Model.deserialize, + ) + return self._stubs["merge_version_aliases"] + @property def export_model( self, @@ -393,7 +531,7 @@ def export_model( ]: r"""Return a callable for the export model method over gRPC. - Exports a trained, exportable, Model to a location specified by + Exports a trained, exportable Model to a location specified by the user. A Model is considered to be exportable if it has at least one [supported export format][google.cloud.aiplatform.v1beta1.Model.supported_export_formats]. @@ -416,6 +554,68 @@ def export_model( ) return self._stubs["export_model"] + @property + def import_model_evaluation( + self, + ) -> Callable[ + [model_service.ImportModelEvaluationRequest], + Awaitable[gca_model_evaluation.ModelEvaluation], + ]: + r"""Return a callable for the import model evaluation method over gRPC. + + Imports an externally generated ModelEvaluation. + + Returns: + Callable[[~.ImportModelEvaluationRequest], + Awaitable[~.ModelEvaluation]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "import_model_evaluation" not in self._stubs: + self._stubs["import_model_evaluation"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1beta1.ModelService/ImportModelEvaluation", + request_serializer=model_service.ImportModelEvaluationRequest.serialize, + response_deserializer=gca_model_evaluation.ModelEvaluation.deserialize, + ) + return self._stubs["import_model_evaluation"] + + @property + def batch_import_model_evaluation_slices( + self, + ) -> Callable[ + [model_service.BatchImportModelEvaluationSlicesRequest], + Awaitable[model_service.BatchImportModelEvaluationSlicesResponse], + ]: + r"""Return a callable for the batch import model evaluation + slices method over gRPC. + + Imports a list of externally generated + ModelEvaluationSlice. + + Returns: + Callable[[~.BatchImportModelEvaluationSlicesRequest], + Awaitable[~.BatchImportModelEvaluationSlicesResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "batch_import_model_evaluation_slices" not in self._stubs: + self._stubs[ + "batch_import_model_evaluation_slices" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1beta1.ModelService/BatchImportModelEvaluationSlices", + request_serializer=model_service.BatchImportModelEvaluationSlicesRequest.serialize, + response_deserializer=model_service.BatchImportModelEvaluationSlicesResponse.deserialize, + ) + return self._stubs["batch_import_model_evaluation_slices"] + @property def get_model_evaluation( self, @@ -532,5 +732,211 @@ def list_model_evaluation_slices( ) return self._stubs["list_model_evaluation_slices"] + def close(self): + return self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + __all__ = ("ModelServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/pipeline_service/__init__.py b/google/cloud/aiplatform_v1beta1/services/pipeline_service/__init__.py index f6234690cb..5eea4316a6 100644 --- a/google/cloud/aiplatform_v1beta1/services/pipeline_service/__init__.py +++ b/google/cloud/aiplatform_v1beta1/services/pipeline_service/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1beta1/services/pipeline_service/async_client.py b/google/cloud/aiplatform_v1beta1/services/pipeline_service/async_client.py index 9c368150ab..c56a856faf 100644 --- a/google/cloud/aiplatform_v1beta1/services/pipeline_service/async_client.py +++ b/google/cloud/aiplatform_v1beta1/services/pipeline_service/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,16 +16,21 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation as gac_operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1beta1.services.pipeline_service import pagers @@ -40,6 +45,10 @@ from google.cloud.aiplatform_v1beta1.types import ( training_pipeline as gca_training_pipeline, ) +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore from google.protobuf import struct_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore @@ -50,7 +59,11 @@ class PipelineServiceAsyncClient: - """A service for creating and managing AI Platform's pipelines.""" + """A service for creating and managing Vertex AI's pipelines. This + includes both ``TrainingPipeline`` resources (used for AutoML and + custom training) and ``PipelineJob`` resources (used for Vertex AI + Pipelines). + """ _client: PipelineServiceClient @@ -106,7 +119,8 @@ class PipelineServiceAsyncClient: @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -121,7 +135,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -136,9 +150,45 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return PipelineServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> PipelineServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: PipelineServiceTransport: The transport used by the client instance. @@ -157,7 +207,7 @@ def __init__( client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the pipeline service client. + """Instantiates the pipeline service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -198,19 +248,44 @@ def __init__( async def create_training_pipeline( self, - request: pipeline_service.CreateTrainingPipelineRequest = None, + request: Union[pipeline_service.CreateTrainingPipelineRequest, dict] = None, *, parent: str = None, training_pipeline: gca_training_pipeline.TrainingPipeline = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_training_pipeline.TrainingPipeline: r"""Creates a TrainingPipeline. A created TrainingPipeline right away will be attempted to be run. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_create_training_pipeline(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + training_pipeline = aiplatform_v1beta1.TrainingPipeline() + training_pipeline.display_name = "display_name_value" + training_pipeline.training_task_definition = "training_task_definition_value" + training_pipeline.training_task_inputs.null_value = "NULL_VALUE" + + request = aiplatform_v1beta1.CreateTrainingPipelineRequest( + parent="parent_value", + training_pipeline=training_pipeline, + ) + + # Make the request + response = await client.create_training_pipeline(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.CreateTrainingPipelineRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateTrainingPipelineRequest, dict]): The request object. Request message for [PipelineService.CreateTrainingPipeline][google.cloud.aiplatform.v1beta1.PipelineService.CreateTrainingPipeline]. parent (:class:`str`): @@ -238,14 +313,14 @@ async def create_training_pipeline( google.cloud.aiplatform_v1beta1.types.TrainingPipeline: The TrainingPipeline orchestrates tasks associated with training a Model. It always executes the training task, and optionally may - also export data from AI Platform's Dataset which + also export data from Vertex AI's Dataset which becomes the training input, [upload][google.cloud.aiplatform.v1beta1.ModelService.UploadModel] - the Model to AI Platform, and evaluate the Model. + the Model to Vertex AI, and evaluate the Model. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, training_pipeline]) if request is not None and has_flattened_params: @@ -278,24 +353,48 @@ async def create_training_pipeline( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def get_training_pipeline( self, - request: pipeline_service.GetTrainingPipelineRequest = None, + request: Union[pipeline_service.GetTrainingPipelineRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> training_pipeline.TrainingPipeline: r"""Gets a TrainingPipeline. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_get_training_pipeline(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetTrainingPipelineRequest( + name="name_value", + ) + + # Make the request + response = await client.get_training_pipeline(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.GetTrainingPipelineRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.GetTrainingPipelineRequest, dict]): The request object. Request message for [PipelineService.GetTrainingPipeline][google.cloud.aiplatform.v1beta1.PipelineService.GetTrainingPipeline]. name (:class:`str`): @@ -316,14 +415,14 @@ async def get_training_pipeline( google.cloud.aiplatform_v1beta1.types.TrainingPipeline: The TrainingPipeline orchestrates tasks associated with training a Model. It always executes the training task, and optionally may - also export data from AI Platform's Dataset which + also export data from Vertex AI's Dataset which becomes the training input, [upload][google.cloud.aiplatform.v1beta1.ModelService.UploadModel] - the Model to AI Platform, and evaluate the Model. + the Model to Vertex AI, and evaluate the Model. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -354,24 +453,49 @@ async def get_training_pipeline( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_training_pipelines( self, - request: pipeline_service.ListTrainingPipelinesRequest = None, + request: Union[pipeline_service.ListTrainingPipelinesRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListTrainingPipelinesAsyncPager: r"""Lists TrainingPipelines in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_list_training_pipelines(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListTrainingPipelinesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_training_pipelines(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ListTrainingPipelinesRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ListTrainingPipelinesRequest, dict]): The request object. Request message for [PipelineService.ListTrainingPipelines][google.cloud.aiplatform.v1beta1.PipelineService.ListTrainingPipelines]. parent (:class:`str`): @@ -398,7 +522,7 @@ async def list_training_pipelines( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -429,12 +553,20 @@ async def list_training_pipelines( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListTrainingPipelinesAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -442,17 +574,40 @@ async def list_training_pipelines( async def delete_training_pipeline( self, - request: pipeline_service.DeleteTrainingPipelineRequest = None, + request: Union[pipeline_service.DeleteTrainingPipelineRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a TrainingPipeline. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_delete_training_pipeline(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteTrainingPipelineRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_training_pipeline(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.DeleteTrainingPipelineRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteTrainingPipelineRequest, dict]): The request object. Request message for [PipelineService.DeleteTrainingPipeline][google.cloud.aiplatform.v1beta1.PipelineService.DeleteTrainingPipeline]. name (:class:`str`): @@ -489,7 +644,7 @@ async def delete_training_pipeline( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -520,7 +675,12 @@ async def delete_training_pipeline( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -535,10 +695,10 @@ async def delete_training_pipeline( async def cancel_training_pipeline( self, - request: pipeline_service.CancelTrainingPipelineRequest = None, + request: Union[pipeline_service.CancelTrainingPipelineRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -556,8 +716,24 @@ async def cancel_training_pipeline( [TrainingPipeline.state][google.cloud.aiplatform.v1beta1.TrainingPipeline.state] is set to ``CANCELLED``. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_cancel_training_pipeline(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CancelTrainingPipelineRequest( + name="name_value", + ) + + # Make the request + await client.cancel_training_pipeline(request=request) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.CancelTrainingPipelineRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.CancelTrainingPipelineRequest, dict]): The request object. Request message for [PipelineService.CancelTrainingPipeline][google.cloud.aiplatform.v1beta1.PipelineService.CancelTrainingPipeline]. name (:class:`str`): @@ -575,7 +751,7 @@ async def cancel_training_pipeline( 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 + # Quick 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: @@ -607,25 +783,47 @@ async def cancel_training_pipeline( # Send the request. await rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) async def create_pipeline_job( self, - request: pipeline_service.CreatePipelineJobRequest = None, + request: Union[pipeline_service.CreatePipelineJobRequest, dict] = None, *, parent: str = None, pipeline_job: gca_pipeline_job.PipelineJob = None, pipeline_job_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_pipeline_job.PipelineJob: r"""Creates a PipelineJob. A PipelineJob will run immediately when created. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_create_pipeline_job(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreatePipelineJobRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_pipeline_job(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.CreatePipelineJobRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.CreatePipelineJobRequest, dict]): The request object. Request message for [PipelineService.CreatePipelineJob][google.cloud.aiplatform.v1beta1.PipelineService.CreatePipelineJob]. parent (:class:`str`): @@ -665,7 +863,7 @@ async def create_pipeline_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, pipeline_job, pipeline_job_id]) if request is not None and has_flattened_params: @@ -700,24 +898,48 @@ async def create_pipeline_job( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def get_pipeline_job( self, - request: pipeline_service.GetPipelineJobRequest = None, + request: Union[pipeline_service.GetPipelineJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pipeline_job.PipelineJob: r"""Gets a PipelineJob. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_get_pipeline_job(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetPipelineJobRequest( + name="name_value", + ) + + # Make the request + response = await client.get_pipeline_job(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.GetPipelineJobRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.GetPipelineJobRequest, dict]): The request object. Request message for [PipelineService.GetPipelineJob][google.cloud.aiplatform.v1beta1.PipelineService.GetPipelineJob]. name (:class:`str`): @@ -740,7 +962,7 @@ async def get_pipeline_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -771,24 +993,49 @@ async def get_pipeline_job( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_pipeline_jobs( self, - request: pipeline_service.ListPipelineJobsRequest = None, + request: Union[pipeline_service.ListPipelineJobsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListPipelineJobsAsyncPager: r"""Lists PipelineJobs in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_list_pipeline_jobs(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListPipelineJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_pipeline_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ListPipelineJobsRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ListPipelineJobsRequest, dict]): The request object. Request message for [PipelineService.ListPipelineJobs][google.cloud.aiplatform.v1beta1.PipelineService.ListPipelineJobs]. parent (:class:`str`): @@ -815,7 +1062,7 @@ async def list_pipeline_jobs( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -846,12 +1093,20 @@ async def list_pipeline_jobs( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListPipelineJobsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -859,17 +1114,40 @@ async def list_pipeline_jobs( async def delete_pipeline_job( self, - request: pipeline_service.DeletePipelineJobRequest = None, + request: Union[pipeline_service.DeletePipelineJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a PipelineJob. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_delete_pipeline_job(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeletePipelineJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_pipeline_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.DeletePipelineJobRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.DeletePipelineJobRequest, dict]): The request object. Request message for [PipelineService.DeletePipelineJob][google.cloud.aiplatform.v1beta1.PipelineService.DeletePipelineJob]. name (:class:`str`): @@ -906,7 +1184,7 @@ async def delete_pipeline_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -937,7 +1215,12 @@ async def delete_pipeline_job( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -952,10 +1235,10 @@ async def delete_pipeline_job( async def cancel_pipeline_job( self, - request: pipeline_service.CancelPipelineJobRequest = None, + request: Union[pipeline_service.CancelPipelineJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -973,8 +1256,24 @@ async def cancel_pipeline_job( [PipelineJob.state][google.cloud.aiplatform.v1beta1.PipelineJob.state] is set to ``CANCELLED``. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_cancel_pipeline_job(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CancelPipelineJobRequest( + name="name_value", + ) + + # Make the request + await client.cancel_pipeline_job(request=request) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.CancelPipelineJobRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.CancelPipelineJobRequest, dict]): The request object. Request message for [PipelineService.CancelPipelineJob][google.cloud.aiplatform.v1beta1.PipelineService.CancelPipelineJob]. name (:class:`str`): @@ -991,7 +1290,7 @@ async def cancel_pipeline_job( 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 + # Quick 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: @@ -1023,9 +1322,689 @@ async def cancel_pipeline_job( # Send the request. await rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + async def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_operations, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.delete_operation, + default_timeout=None, + 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 cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + 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 wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.wait_operation, + default_timeout=None, + 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 set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_location, + default_timeout=None, + 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 list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_locations, + default_timeout=None, + 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 __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/aiplatform_v1beta1/services/pipeline_service/client.py b/google/cloud/aiplatform_v1beta1/services/pipeline_service/client.py index 106452a82b..0d38ae361a 100644 --- a/google/cloud/aiplatform_v1beta1/services/pipeline_service/client.py +++ b/google/cloud/aiplatform_v1beta1/services/pipeline_service/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,22 +14,26 @@ # 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 +from typing import Dict, Mapping, 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 as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_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 +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation as gac_operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1beta1.services.pipeline_service import pagers @@ -44,6 +48,10 @@ from google.cloud.aiplatform_v1beta1.types import ( training_pipeline as gca_training_pipeline, ) +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore from google.protobuf import struct_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore @@ -67,8 +75,11 @@ class PipelineServiceClientMeta(type): _transport_registry["grpc"] = PipelineServiceGrpcTransport _transport_registry["grpc_asyncio"] = PipelineServiceGrpcAsyncIOTransport - def get_transport_class(cls, label: str = None,) -> Type[PipelineServiceTransport]: - """Return an appropriate transport class. + def get_transport_class( + cls, + label: str = None, + ) -> Type[PipelineServiceTransport]: + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -87,11 +98,16 @@ def get_transport_class(cls, label: str = None,) -> Type[PipelineServiceTranspor class PipelineServiceClient(metaclass=PipelineServiceClientMeta): - """A service for creating and managing AI Platform's pipelines.""" + """A service for creating and managing Vertex AI's pipelines. This + includes both ``TrainingPipeline`` resources (used for AutoML and + custom training) and ``PipelineJob`` resources (used for Vertex AI + Pipelines). + """ @staticmethod def _get_default_mtls_endpoint(api_endpoint): - """Convert api endpoint to mTLS endpoint. + """Converts api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. Args: @@ -125,7 +141,8 @@ def _get_default_mtls_endpoint(api_endpoint): @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -142,7 +159,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -161,18 +178,22 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> PipelineServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - PipelineServiceTransport: The transport used by the client instance. + PipelineServiceTransport: The transport used by the client + instance. """ return self._transport @staticmethod def artifact_path( - project: str, location: str, metadata_store: str, artifact: str, + project: str, + location: str, + metadata_store: str, + artifact: str, ) -> str: - """Return a fully-qualified artifact string.""" + """Returns a fully-qualified artifact string.""" return "projects/{project}/locations/{location}/metadataStores/{metadata_store}/artifacts/{artifact}".format( project=project, location=location, @@ -182,7 +203,7 @@ def artifact_path( @staticmethod def parse_artifact_path(path: str) -> Dict[str, str]: - """Parse a artifact path into its component segments.""" + """Parses a artifact path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/metadataStores/(?P.+?)/artifacts/(?P.+?)$", path, @@ -191,9 +212,12 @@ def parse_artifact_path(path: str) -> Dict[str, str]: @staticmethod def context_path( - project: str, location: str, metadata_store: str, context: str, + project: str, + location: str, + metadata_store: str, + context: str, ) -> str: - """Return a fully-qualified context string.""" + """Returns a fully-qualified context string.""" return "projects/{project}/locations/{location}/metadataStores/{metadata_store}/contexts/{context}".format( project=project, location=location, @@ -203,7 +227,7 @@ def context_path( @staticmethod def parse_context_path(path: str) -> Dict[str, str]: - """Parse a context path into its component segments.""" + """Parses a context path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/metadataStores/(?P.+?)/contexts/(?P.+?)$", path, @@ -211,15 +235,21 @@ def parse_context_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def custom_job_path(project: str, location: str, custom_job: str,) -> str: - """Return a fully-qualified custom_job string.""" + def custom_job_path( + project: str, + location: str, + custom_job: str, + ) -> str: + """Returns a fully-qualified custom_job string.""" return "projects/{project}/locations/{location}/customJobs/{custom_job}".format( - project=project, location=location, custom_job=custom_job, + project=project, + location=location, + custom_job=custom_job, ) @staticmethod def parse_custom_job_path(path: str) -> Dict[str, str]: - """Parse a custom_job path into its component segments.""" + """Parses a custom_job path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/customJobs/(?P.+?)$", path, @@ -227,15 +257,21 @@ def parse_custom_job_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def endpoint_path(project: str, location: str, endpoint: str,) -> str: - """Return a fully-qualified endpoint string.""" + def endpoint_path( + project: str, + location: str, + endpoint: str, + ) -> str: + """Returns a fully-qualified endpoint string.""" return "projects/{project}/locations/{location}/endpoints/{endpoint}".format( - project=project, location=location, endpoint=endpoint, + project=project, + location=location, + endpoint=endpoint, ) @staticmethod def parse_endpoint_path(path: str) -> Dict[str, str]: - """Parse a endpoint path into its component segments.""" + """Parses a endpoint path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/endpoints/(?P.+?)$", path, @@ -244,9 +280,12 @@ def parse_endpoint_path(path: str) -> Dict[str, str]: @staticmethod def execution_path( - project: str, location: str, metadata_store: str, execution: str, + project: str, + location: str, + metadata_store: str, + execution: str, ) -> str: - """Return a fully-qualified execution string.""" + """Returns a fully-qualified execution string.""" return "projects/{project}/locations/{location}/metadataStores/{metadata_store}/executions/{execution}".format( project=project, location=location, @@ -256,7 +295,7 @@ def execution_path( @staticmethod def parse_execution_path(path: str) -> Dict[str, str]: - """Parse a execution path into its component segments.""" + """Parses a execution path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/metadataStores/(?P.+?)/executions/(?P.+?)$", path, @@ -264,15 +303,21 @@ def parse_execution_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def model_path(project: str, location: str, model: str,) -> str: - """Return a fully-qualified model string.""" + def model_path( + project: str, + location: str, + model: str, + ) -> str: + """Returns a fully-qualified model string.""" return "projects/{project}/locations/{location}/models/{model}".format( - project=project, location=location, model=model, + project=project, + location=location, + model=model, ) @staticmethod def parse_model_path(path: str) -> Dict[str, str]: - """Parse a model path into its component segments.""" + """Parses a model path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/models/(?P.+?)$", path, @@ -280,30 +325,40 @@ def parse_model_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def network_path(project: str, network: str,) -> str: - """Return a fully-qualified network string.""" + def network_path( + project: str, + network: str, + ) -> str: + """Returns a fully-qualified network string.""" return "projects/{project}/global/networks/{network}".format( - project=project, network=network, + project=project, + network=network, ) @staticmethod def parse_network_path(path: str) -> Dict[str, str]: - """Parse a network path into its component segments.""" + """Parses a network path into its component segments.""" m = re.match( r"^projects/(?P.+?)/global/networks/(?P.+?)$", path ) return m.groupdict() if m else {} @staticmethod - def pipeline_job_path(project: str, location: str, pipeline_job: str,) -> str: - """Return a fully-qualified pipeline_job string.""" + def pipeline_job_path( + project: str, + location: str, + pipeline_job: str, + ) -> str: + """Returns a fully-qualified pipeline_job string.""" return "projects/{project}/locations/{location}/pipelineJobs/{pipeline_job}".format( - project=project, location=location, pipeline_job=pipeline_job, + project=project, + location=location, + pipeline_job=pipeline_job, ) @staticmethod def parse_pipeline_job_path(path: str) -> Dict[str, str]: - """Parse a pipeline_job path into its component segments.""" + """Parses a pipeline_job path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/pipelineJobs/(?P.+?)$", path, @@ -312,16 +367,20 @@ def parse_pipeline_job_path(path: str) -> Dict[str, str]: @staticmethod def training_pipeline_path( - project: str, location: str, training_pipeline: str, + project: str, + location: str, + training_pipeline: str, ) -> str: - """Return a fully-qualified training_pipeline string.""" + """Returns a fully-qualified training_pipeline string.""" return "projects/{project}/locations/{location}/trainingPipelines/{training_pipeline}".format( - project=project, location=location, training_pipeline=training_pipeline, + project=project, + location=location, + training_pipeline=training_pipeline, ) @staticmethod def parse_training_pipeline_path(path: str) -> Dict[str, str]: - """Parse a training_pipeline path into its component segments.""" + """Parses a training_pipeline path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/trainingPipelines/(?P.+?)$", path, @@ -329,8 +388,10 @@ def parse_training_pipeline_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + def common_billing_account_path( + billing_account: str, + ) -> str: + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -342,9 +403,13 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: 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,) + def common_folder_path( + folder: str, + ) -> str: + """Returns a fully-qualified folder string.""" + return "folders/{folder}".format( + folder=folder, + ) @staticmethod def parse_common_folder_path(path: str) -> Dict[str, str]: @@ -353,9 +418,13 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: 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,) + def common_organization_path( + organization: str, + ) -> str: + """Returns a fully-qualified organization string.""" + return "organizations/{organization}".format( + organization=organization, + ) @staticmethod def parse_common_organization_path(path: str) -> Dict[str, str]: @@ -364,9 +433,13 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: 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,) + def common_project_path( + project: str, + ) -> str: + """Returns a fully-qualified project string.""" + return "projects/{project}".format( + project=project, + ) @staticmethod def parse_common_project_path(path: str) -> Dict[str, str]: @@ -375,10 +448,14 @@ def parse_common_project_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_location_path(project: str, location: str,) -> str: - """Return a fully-qualified location string.""" + def common_location_path( + project: str, + location: str, + ) -> str: + """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) @staticmethod @@ -387,6 +464,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + def __init__( self, *, @@ -395,7 +539,7 @@ def __init__( client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the pipeline service client. + """Instantiates the pipeline service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -437,58 +581,42 @@ def __init__( 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")) + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - client_cert_source_func = ( - mtls.default_client_cert_source() 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" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # 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, PipelineServiceTransport): # transport is a PipelineServiceTransport instance. - if credentials or client_options.credentials_file: + if credentials or client_options.credentials_file or api_key_value: 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." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + Transport = type(self).get_transport_class(transport) self._transport = Transport( credentials=credentials, @@ -498,23 +626,49 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, + always_use_jwt_access=True, ) def create_training_pipeline( self, - request: pipeline_service.CreateTrainingPipelineRequest = None, + request: Union[pipeline_service.CreateTrainingPipelineRequest, dict] = None, *, parent: str = None, training_pipeline: gca_training_pipeline.TrainingPipeline = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_training_pipeline.TrainingPipeline: r"""Creates a TrainingPipeline. A created TrainingPipeline right away will be attempted to be run. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_create_training_pipeline(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceClient() + + # Initialize request argument(s) + training_pipeline = aiplatform_v1beta1.TrainingPipeline() + training_pipeline.display_name = "display_name_value" + training_pipeline.training_task_definition = "training_task_definition_value" + training_pipeline.training_task_inputs.null_value = "NULL_VALUE" + + request = aiplatform_v1beta1.CreateTrainingPipelineRequest( + parent="parent_value", + training_pipeline=training_pipeline, + ) + + # Make the request + response = client.create_training_pipeline(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.CreateTrainingPipelineRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateTrainingPipelineRequest, dict]): The request object. Request message for [PipelineService.CreateTrainingPipeline][google.cloud.aiplatform.v1beta1.PipelineService.CreateTrainingPipeline]. parent (str): @@ -542,14 +696,14 @@ def create_training_pipeline( google.cloud.aiplatform_v1beta1.types.TrainingPipeline: The TrainingPipeline orchestrates tasks associated with training a Model. It always executes the training task, and optionally may - also export data from AI Platform's Dataset which + also export data from Vertex AI's Dataset which becomes the training input, [upload][google.cloud.aiplatform.v1beta1.ModelService.UploadModel] - the Model to AI Platform, and evaluate the Model. + the Model to Vertex AI, and evaluate the Model. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, training_pipeline]) if request is not None and has_flattened_params: @@ -582,24 +736,48 @@ def create_training_pipeline( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def get_training_pipeline( self, - request: pipeline_service.GetTrainingPipelineRequest = None, + request: Union[pipeline_service.GetTrainingPipelineRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> training_pipeline.TrainingPipeline: r"""Gets a TrainingPipeline. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_get_training_pipeline(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetTrainingPipelineRequest( + name="name_value", + ) + + # Make the request + response = client.get_training_pipeline(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.GetTrainingPipelineRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.GetTrainingPipelineRequest, dict]): The request object. Request message for [PipelineService.GetTrainingPipeline][google.cloud.aiplatform.v1beta1.PipelineService.GetTrainingPipeline]. name (str): @@ -620,14 +798,14 @@ def get_training_pipeline( google.cloud.aiplatform_v1beta1.types.TrainingPipeline: The TrainingPipeline orchestrates tasks associated with training a Model. It always executes the training task, and optionally may - also export data from AI Platform's Dataset which + also export data from Vertex AI's Dataset which becomes the training input, [upload][google.cloud.aiplatform.v1beta1.ModelService.UploadModel] - the Model to AI Platform, and evaluate the Model. + the Model to Vertex AI, and evaluate the Model. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -658,24 +836,49 @@ def get_training_pipeline( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_training_pipelines( self, - request: pipeline_service.ListTrainingPipelinesRequest = None, + request: Union[pipeline_service.ListTrainingPipelinesRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListTrainingPipelinesPager: r"""Lists TrainingPipelines in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_list_training_pipelines(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListTrainingPipelinesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_training_pipelines(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ListTrainingPipelinesRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ListTrainingPipelinesRequest, dict]): The request object. Request message for [PipelineService.ListTrainingPipelines][google.cloud.aiplatform.v1beta1.PipelineService.ListTrainingPipelines]. parent (str): @@ -702,7 +905,7 @@ def list_training_pipelines( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -733,12 +936,20 @@ def list_training_pipelines( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListTrainingPipelinesPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -746,17 +957,40 @@ def list_training_pipelines( def delete_training_pipeline( self, - request: pipeline_service.DeleteTrainingPipelineRequest = None, + request: Union[pipeline_service.DeleteTrainingPipelineRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Deletes a TrainingPipeline. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_delete_training_pipeline(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteTrainingPipelineRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_training_pipeline(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.DeleteTrainingPipelineRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteTrainingPipelineRequest, dict]): The request object. Request message for [PipelineService.DeleteTrainingPipeline][google.cloud.aiplatform.v1beta1.PipelineService.DeleteTrainingPipeline]. name (str): @@ -793,7 +1027,7 @@ def delete_training_pipeline( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -824,7 +1058,12 @@ def delete_training_pipeline( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -839,10 +1078,10 @@ def delete_training_pipeline( def cancel_training_pipeline( self, - request: pipeline_service.CancelTrainingPipelineRequest = None, + request: Union[pipeline_service.CancelTrainingPipelineRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -860,8 +1099,24 @@ def cancel_training_pipeline( [TrainingPipeline.state][google.cloud.aiplatform.v1beta1.TrainingPipeline.state] is set to ``CANCELLED``. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_cancel_training_pipeline(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CancelTrainingPipelineRequest( + name="name_value", + ) + + # Make the request + client.cancel_training_pipeline(request=request) + Args: - request (google.cloud.aiplatform_v1beta1.types.CancelTrainingPipelineRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.CancelTrainingPipelineRequest, dict]): The request object. Request message for [PipelineService.CancelTrainingPipeline][google.cloud.aiplatform.v1beta1.PipelineService.CancelTrainingPipeline]. name (str): @@ -879,7 +1134,7 @@ def cancel_training_pipeline( 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 + # Quick 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: @@ -911,25 +1166,47 @@ def cancel_training_pipeline( # Send the request. rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) def create_pipeline_job( self, - request: pipeline_service.CreatePipelineJobRequest = None, + request: Union[pipeline_service.CreatePipelineJobRequest, dict] = None, *, parent: str = None, pipeline_job: gca_pipeline_job.PipelineJob = None, pipeline_job_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_pipeline_job.PipelineJob: r"""Creates a PipelineJob. A PipelineJob will run immediately when created. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_create_pipeline_job(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreatePipelineJobRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_pipeline_job(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.CreatePipelineJobRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.CreatePipelineJobRequest, dict]): The request object. Request message for [PipelineService.CreatePipelineJob][google.cloud.aiplatform.v1beta1.PipelineService.CreatePipelineJob]. parent (str): @@ -969,7 +1246,7 @@ def create_pipeline_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, pipeline_job, pipeline_job_id]) if request is not None and has_flattened_params: @@ -1004,24 +1281,48 @@ def create_pipeline_job( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def get_pipeline_job( self, - request: pipeline_service.GetPipelineJobRequest = None, + request: Union[pipeline_service.GetPipelineJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pipeline_job.PipelineJob: r"""Gets a PipelineJob. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_get_pipeline_job(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetPipelineJobRequest( + name="name_value", + ) + + # Make the request + response = client.get_pipeline_job(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.GetPipelineJobRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.GetPipelineJobRequest, dict]): The request object. Request message for [PipelineService.GetPipelineJob][google.cloud.aiplatform.v1beta1.PipelineService.GetPipelineJob]. name (str): @@ -1044,7 +1345,7 @@ def get_pipeline_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1075,24 +1376,49 @@ def get_pipeline_job( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_pipeline_jobs( self, - request: pipeline_service.ListPipelineJobsRequest = None, + request: Union[pipeline_service.ListPipelineJobsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListPipelineJobsPager: r"""Lists PipelineJobs in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_list_pipeline_jobs(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListPipelineJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_pipeline_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ListPipelineJobsRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ListPipelineJobsRequest, dict]): The request object. Request message for [PipelineService.ListPipelineJobs][google.cloud.aiplatform.v1beta1.PipelineService.ListPipelineJobs]. parent (str): @@ -1119,7 +1445,7 @@ def list_pipeline_jobs( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1150,12 +1476,20 @@ def list_pipeline_jobs( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListPipelineJobsPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -1163,17 +1497,40 @@ def list_pipeline_jobs( def delete_pipeline_job( self, - request: pipeline_service.DeletePipelineJobRequest = None, + request: Union[pipeline_service.DeletePipelineJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Deletes a PipelineJob. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_delete_pipeline_job(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeletePipelineJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_pipeline_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.DeletePipelineJobRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.DeletePipelineJobRequest, dict]): The request object. Request message for [PipelineService.DeletePipelineJob][google.cloud.aiplatform.v1beta1.PipelineService.DeletePipelineJob]. name (str): @@ -1210,7 +1567,7 @@ def delete_pipeline_job( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1241,7 +1598,12 @@ def delete_pipeline_job( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -1256,10 +1618,10 @@ def delete_pipeline_job( def cancel_pipeline_job( self, - request: pipeline_service.CancelPipelineJobRequest = None, + request: Union[pipeline_service.CancelPipelineJobRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -1277,8 +1639,24 @@ def cancel_pipeline_job( [PipelineJob.state][google.cloud.aiplatform.v1beta1.PipelineJob.state] is set to ``CANCELLED``. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_cancel_pipeline_job(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CancelPipelineJobRequest( + name="name_value", + ) + + # Make the request + client.cancel_pipeline_job(request=request) + Args: - request (google.cloud.aiplatform_v1beta1.types.CancelPipelineJobRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.CancelPipelineJobRequest, dict]): The request object. Request message for [PipelineService.CancelPipelineJob][google.cloud.aiplatform.v1beta1.PipelineService.CancelPipelineJob]. name (str): @@ -1295,7 +1673,7 @@ def cancel_pipeline_job( 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 + # Quick 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: @@ -1327,9 +1705,696 @@ def cancel_pipeline_job( # Send the request. rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_operations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.delete_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.wait_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_location, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_locations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/aiplatform_v1beta1/services/pipeline_service/pagers.py b/google/cloud/aiplatform_v1beta1/services/pipeline_service/pagers.py index c56f01985c..ca4cea801d 100644 --- a/google/cloud/aiplatform_v1beta1/services/pipeline_service/pagers.py +++ b/google/cloud/aiplatform_v1beta1/services/pipeline_service/pagers.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,13 +15,13 @@ # from typing import ( Any, - AsyncIterable, + AsyncIterator, Awaitable, Callable, - Iterable, Sequence, Tuple, Optional, + Iterator, ) from google.cloud.aiplatform_v1beta1.types import pipeline_job @@ -76,14 +76,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[pipeline_service.ListTrainingPipelinesResponse]: + def pages(self) -> Iterator[pipeline_service.ListTrainingPipelinesResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[training_pipeline.TrainingPipeline]: + def __iter__(self) -> Iterator[training_pipeline.TrainingPipeline]: for page in self.pages: yield from page.training_pipelines @@ -119,7 +119,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -142,14 +142,14 @@ def __getattr__(self, name: str) -> Any: @property async def pages( self, - ) -> AsyncIterable[pipeline_service.ListTrainingPipelinesResponse]: + ) -> AsyncIterator[pipeline_service.ListTrainingPipelinesResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[training_pipeline.TrainingPipeline]: + def __aiter__(self) -> AsyncIterator[training_pipeline.TrainingPipeline]: async def async_generator(): async for page in self.pages: for response in page.training_pipelines: @@ -208,14 +208,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[pipeline_service.ListPipelineJobsResponse]: + def pages(self) -> Iterator[pipeline_service.ListPipelineJobsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[pipeline_job.PipelineJob]: + def __iter__(self) -> Iterator[pipeline_job.PipelineJob]: for page in self.pages: yield from page.pipeline_jobs @@ -249,7 +249,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -270,14 +270,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - async def pages(self) -> AsyncIterable[pipeline_service.ListPipelineJobsResponse]: + async def pages(self) -> AsyncIterator[pipeline_service.ListPipelineJobsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[pipeline_job.PipelineJob]: + def __aiter__(self) -> AsyncIterator[pipeline_job.PipelineJob]: async def async_generator(): async for page in self.pages: for response in page.pipeline_jobs: diff --git a/google/cloud/aiplatform_v1beta1/services/pipeline_service/transports/__init__.py b/google/cloud/aiplatform_v1beta1/services/pipeline_service/transports/__init__.py index c7a40586e8..7cf231f6c5 100644 --- a/google/cloud/aiplatform_v1beta1/services/pipeline_service/transports/__init__.py +++ b/google/cloud/aiplatform_v1beta1/services/pipeline_service/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1beta1/services/pipeline_service/transports/base.py b/google/cloud/aiplatform_v1beta1/services/pipeline_service/transports/base.py index cc09aa7551..f918c88192 100644 --- a/google/cloud/aiplatform_v1beta1/services/pipeline_service/transports/base.py +++ b/google/cloud/aiplatform_v1beta1/services/pipeline_service/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,16 +15,16 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.api_core import operations_v1 # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.aiplatform_v1beta1.types import pipeline_job from google.cloud.aiplatform_v1beta1.types import pipeline_job as gca_pipeline_job @@ -33,6 +33,10 @@ from google.cloud.aiplatform_v1beta1.types import ( training_pipeline as gca_training_pipeline, ) +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from google.protobuf import empty_pb2 # type: ignore @@ -45,17 +49,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - -_API_CORE_VERSION = google.api_core.__version__ - class PipelineServiceTransport(abc.ABC): """Abstract transport class for PipelineService.""" @@ -73,6 +66,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -96,16 +90,19 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -118,59 +115,21 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id ) - # Save the credentials. - self._credentials = credentials - - # TODO(busunkim): These two class methods are in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-api-core - # and google-auth are increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") - ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs - - # TODO: Remove this function once google-api-core >= 1.26.0 is required - @classmethod - def _get_self_signed_jwt_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Union[Optional[Sequence[str]], str]]: - """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" - - self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} - - if _API_CORE_VERSION and ( - packaging.version.parse(_API_CORE_VERSION) - >= packaging.version.parse("1.26.0") + # If the credentials are service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") ): - self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES - self_signed_jwt_kwargs["scopes"] = scopes - self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST - else: - self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES + credentials = credentials.with_always_use_jwt_access(True) - return self_signed_jwt_kwargs + # Save the credentials. + self._credentials = credentials def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. @@ -201,24 +160,43 @@ def _prep_wrapped_messages(self, client_info): client_info=client_info, ), self.create_pipeline_job: gapic_v1.method.wrap_method( - self.create_pipeline_job, default_timeout=None, client_info=client_info, + self.create_pipeline_job, + default_timeout=None, + client_info=client_info, ), self.get_pipeline_job: gapic_v1.method.wrap_method( - self.get_pipeline_job, default_timeout=None, client_info=client_info, + self.get_pipeline_job, + default_timeout=None, + client_info=client_info, ), self.list_pipeline_jobs: gapic_v1.method.wrap_method( - self.list_pipeline_jobs, default_timeout=None, client_info=client_info, + self.list_pipeline_jobs, + default_timeout=None, + client_info=client_info, ), self.delete_pipeline_job: gapic_v1.method.wrap_method( - self.delete_pipeline_job, default_timeout=None, client_info=client_info, + self.delete_pipeline_job, + default_timeout=None, + client_info=client_info, ), self.cancel_pipeline_job: gapic_v1.method.wrap_method( - self.cancel_pipeline_job, default_timeout=None, client_info=client_info, + self.cancel_pipeline_job, + default_timeout=None, + client_info=client_info, ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() @@ -324,5 +302,102 @@ def cancel_pipeline_job( ]: raise NotImplementedError() + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], + Union[ + operations_pb2.ListOperationsResponse, + Awaitable[operations_pb2.ListOperationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None,]: + raise NotImplementedError() + + @property + def wait_operation( + self, + ) -> Callable[ + [operations_pb2.WaitOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def set_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def get_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_location( + self, + ) -> Callable[ + [locations_pb2.GetLocationRequest], + Union[locations_pb2.Location, Awaitable[locations_pb2.Location]], + ]: + raise NotImplementedError() + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], + Union[ + locations_pb2.ListLocationsResponse, + Awaitable[locations_pb2.ListLocationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + __all__ = ("PipelineServiceTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/pipeline_service/transports/grpc.py b/google/cloud/aiplatform_v1beta1/services/pipeline_service/transports/grpc.py index 029bd62656..ef402c409f 100644 --- a/google/cloud/aiplatform_v1beta1/services/pipeline_service/transports/grpc.py +++ b/google/cloud/aiplatform_v1beta1/services/pipeline_service/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,9 +16,9 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import operations_v1 +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -32,6 +32,10 @@ from google.cloud.aiplatform_v1beta1.types import ( training_pipeline as gca_training_pipeline, ) +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from google.protobuf import empty_pb2 # type: ignore from .base import PipelineServiceTransport, DEFAULT_CLIENT_INFO @@ -40,7 +44,10 @@ class PipelineServiceGrpcTransport(PipelineServiceTransport): """gRPC backend transport for PipelineService. - A service for creating and managing AI Platform's pipelines. + A service for creating and managing Vertex AI's pipelines. This + includes both ``TrainingPipeline`` resources (used for AutoML and + custom training) and ``PipelineJob`` resources (used for Vertex AI + Pipelines). This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation @@ -66,6 +73,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -88,16 +96,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -106,6 +114,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport @@ -116,7 +126,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -159,13 +169,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -214,21 +228,20 @@ def create_channel( and ``credentials_file`` are passed. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @property def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ + """Return the channel designed to connect to this service.""" return self._grpc_channel @property @@ -238,7 +251,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsClient(self.grpc_channel) @@ -549,5 +562,215 @@ def cancel_pipeline_job( ) return self._stubs["cancel_pipeline_job"] + def close(self): + self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + @property + def kind(self) -> str: + return "grpc" + __all__ = ("PipelineServiceGrpcTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/pipeline_service/transports/grpc_asyncio.py b/google/cloud/aiplatform_v1beta1/services/pipeline_service/transports/grpc_asyncio.py index c12da6ea8c..459fc44d0e 100644 --- a/google/cloud/aiplatform_v1beta1/services/pipeline_service/transports/grpc_asyncio.py +++ b/google/cloud/aiplatform_v1beta1/services/pipeline_service/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,12 +16,11 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore -from google.api_core import operations_v1 # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore @@ -33,6 +32,10 @@ from google.cloud.aiplatform_v1beta1.types import ( training_pipeline as gca_training_pipeline, ) +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from google.protobuf import empty_pb2 # type: ignore from .base import PipelineServiceTransport, DEFAULT_CLIENT_INFO @@ -42,7 +45,10 @@ class PipelineServiceGrpcAsyncIOTransport(PipelineServiceTransport): """gRPC AsyncIO backend transport for PipelineService. - A service for creating and managing AI Platform's pipelines. + A service for creating and managing Vertex AI's pipelines. This + includes both ``TrainingPipeline`` resources (used for AutoML and + custom training) and ``PipelineJob`` resources (used for Vertex AI + Pipelines). This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation @@ -87,14 +93,14 @@ def create_channel( aio.Channel: A gRPC AsyncIO channel object. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @@ -112,6 +118,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -135,16 +142,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -153,6 +160,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport @@ -163,7 +172,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -205,13 +214,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -241,7 +254,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel @@ -562,5 +575,211 @@ def cancel_pipeline_job( ) return self._stubs["cancel_pipeline_job"] + def close(self): + return self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + __all__ = ("PipelineServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/prediction_service/__init__.py b/google/cloud/aiplatform_v1beta1/services/prediction_service/__init__.py index 12491bb171..d5ecd0dd03 100644 --- a/google/cloud/aiplatform_v1beta1/services/prediction_service/__init__.py +++ b/google/cloud/aiplatform_v1beta1/services/prediction_service/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1beta1/services/prediction_service/async_client.py b/google/cloud/aiplatform_v1beta1/services/prediction_service/async_client.py index 9872aa3fb3..2a4467854d 100644 --- a/google/cloud/aiplatform_v1beta1/services/prediction_service/async_client.py +++ b/google/cloud/aiplatform_v1beta1/services/prediction_service/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,18 +16,29 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + +from google.api import httpbody_pb2 # type: ignore from google.cloud.aiplatform_v1beta1.types import explanation from google.cloud.aiplatform_v1beta1.types import prediction_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.protobuf import any_pb2 # type: ignore from google.protobuf import struct_pb2 # type: ignore from .transports.base import PredictionServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import PredictionServiceGrpcAsyncIOTransport @@ -44,6 +55,8 @@ class PredictionServiceAsyncClient: endpoint_path = staticmethod(PredictionServiceClient.endpoint_path) parse_endpoint_path = staticmethod(PredictionServiceClient.parse_endpoint_path) + model_path = staticmethod(PredictionServiceClient.model_path) + parse_model_path = staticmethod(PredictionServiceClient.parse_model_path) common_billing_account_path = staticmethod( PredictionServiceClient.common_billing_account_path ) @@ -71,7 +84,8 @@ class PredictionServiceAsyncClient: @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -86,7 +100,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -101,9 +115,45 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return PredictionServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> PredictionServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: PredictionServiceTransport: The transport used by the client instance. @@ -122,7 +172,7 @@ def __init__( client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the prediction service client. + """Instantiates the prediction service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -163,19 +213,42 @@ def __init__( async def predict( self, - request: prediction_service.PredictRequest = None, + request: Union[prediction_service.PredictRequest, dict] = None, *, endpoint: str = None, instances: Sequence[struct_pb2.Value] = None, parameters: struct_pb2.Value = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> prediction_service.PredictResponse: r"""Perform an online prediction. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_predict(): + # Create a client + client = aiplatform_v1beta1.PredictionServiceAsyncClient() + + # Initialize request argument(s) + instances = aiplatform_v1beta1.Value() + instances.null_value = "NULL_VALUE" + + request = aiplatform_v1beta1.PredictRequest( + endpoint="endpoint_value", + instances=instances, + ) + + # Make the request + response = await client.predict(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.PredictRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.PredictRequest, dict]): The request object. Request message for [PredictionService.Predict][google.cloud.aiplatform.v1beta1.PredictionService.Predict]. endpoint (:class:`str`): @@ -226,7 +299,7 @@ async def predict( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([endpoint, instances, parameters]) if request is not None and has_flattened_params: @@ -261,20 +334,204 @@ async def predict( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def raw_predict( + self, + request: Union[prediction_service.RawPredictRequest, dict] = None, + *, + endpoint: str = None, + http_body: httpbody_pb2.HttpBody = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> httpbody_pb2.HttpBody: + r"""Perform an online prediction with an arbitrary HTTP payload. + + The response includes the following HTTP headers: + + - ``X-Vertex-AI-Endpoint-Id``: ID of the + [Endpoint][google.cloud.aiplatform.v1beta1.Endpoint] that + served this prediction. + + - ``X-Vertex-AI-Deployed-Model-Id``: ID of the Endpoint's + [DeployedModel][google.cloud.aiplatform.v1beta1.DeployedModel] + that served this prediction. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_raw_predict(): + # Create a client + client = aiplatform_v1beta1.PredictionServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.RawPredictRequest( + endpoint="endpoint_value", + ) + + # Make the request + response = await client.raw_predict(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.RawPredictRequest, dict]): + The request object. Request message for + [PredictionService.RawPredict][google.cloud.aiplatform.v1beta1.PredictionService.RawPredict]. + endpoint (:class:`str`): + Required. The name of the Endpoint requested to serve + the prediction. Format: + ``projects/{project}/locations/{location}/endpoints/{endpoint}`` + + This corresponds to the ``endpoint`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + http_body (:class:`google.api.httpbody_pb2.HttpBody`): + The prediction input. Supports HTTP headers and + arbitrary data payload. + + A + [DeployedModel][google.cloud.aiplatform.v1beta1.DeployedModel] + may have an upper limit on the number of instances it + supports per request. When this limit it is exceeded for + an AutoML model, the + [RawPredict][google.cloud.aiplatform.v1beta1.PredictionService.RawPredict] + method returns an error. When this limit is exceeded for + a custom-trained model, the behavior varies depending on + the model. + + You can specify the schema for each instance in the + [predict_schemata.instance_schema_uri][google.cloud.aiplatform.v1beta1.PredictSchemata.instance_schema_uri] + field when you create a + [Model][google.cloud.aiplatform.v1beta1.Model]. This + schema applies when you deploy the ``Model`` as a + ``DeployedModel`` to an + [Endpoint][google.cloud.aiplatform.v1beta1.Endpoint] and + use the ``RawPredict`` method. + + This corresponds to the ``http_body`` 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: + google.api.httpbody_pb2.HttpBody: + Message that represents an arbitrary HTTP body. It should only be used for + payload formats that can't be represented as JSON, + such as raw binary or an HTML page. + + This message can be used both in streaming and + non-streaming API methods in the request as well as + the response. + + It can be used as a top-level request field, which is + convenient if one wants to extract parameters from + either the URL or HTTP template into the request + fields and also want access to the raw HTTP body. + + Example: + + message GetResourceRequest { + // A unique request id. string request_id = 1; + + // The raw HTTP body is bound to this field. + google.api.HttpBody http_body = 2; + + } + + service ResourceService { + rpc GetResource(GetResourceRequest) + returns (google.api.HttpBody); + + rpc UpdateResource(google.api.HttpBody) + returns (google.protobuf.Empty); + + } + + Example with streaming methods: + + service CaldavService { + rpc GetCalendar(stream google.api.HttpBody) + returns (stream google.api.HttpBody); + + rpc UpdateCalendar(stream google.api.HttpBody) + returns (stream google.api.HttpBody); + + } + + Use of this type only changes how the request and + response bodies are handled, all other features will + continue to work unchanged. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([endpoint, http_body]) + 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 = prediction_service.RawPredictRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if endpoint is not None: + request.endpoint = endpoint + if http_body is not None: + request.http_body = http_body + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.raw_predict, + default_timeout=None, + 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((("endpoint", request.endpoint),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def explain( self, - request: prediction_service.ExplainRequest = None, + request: Union[prediction_service.ExplainRequest, dict] = None, *, endpoint: str = None, instances: Sequence[struct_pb2.Value] = None, parameters: struct_pb2.Value = None, deployed_model_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> prediction_service.ExplainResponse: @@ -291,8 +548,31 @@ async def explain( populated. Only deployed AutoML tabular Models have explanation_spec. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_explain(): + # Create a client + client = aiplatform_v1beta1.PredictionServiceAsyncClient() + + # Initialize request argument(s) + instances = aiplatform_v1beta1.Value() + instances.null_value = "NULL_VALUE" + + request = aiplatform_v1beta1.ExplainRequest( + endpoint="endpoint_value", + instances=instances, + ) + + # Make the request + response = await client.explain(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ExplainRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ExplainRequest, dict]): The request object. Request message for [PredictionService.Explain][google.cloud.aiplatform.v1beta1.PredictionService.Explain]. endpoint (:class:`str`): @@ -351,7 +631,7 @@ async def explain( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([endpoint, instances, parameters, deployed_model_id]) if request is not None and has_flattened_params: @@ -388,11 +668,693 @@ async def explain( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_operations, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.delete_operation, + default_timeout=None, + 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 cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + 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 wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.wait_operation, + default_timeout=None, + 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 set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_location, + default_timeout=None, + 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 list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_locations, + default_timeout=None, + 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 __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/aiplatform_v1beta1/services/prediction_service/client.py b/google/cloud/aiplatform_v1beta1/services/prediction_service/client.py index c7852e2805..50d02d3c9c 100644 --- a/google/cloud/aiplatform_v1beta1/services/prediction_service/client.py +++ b/google/cloud/aiplatform_v1beta1/services/prediction_service/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,24 +14,34 @@ # 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 +from typing import Dict, Mapping, 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 as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_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 +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + +from google.api import httpbody_pb2 # type: ignore from google.cloud.aiplatform_v1beta1.types import explanation from google.cloud.aiplatform_v1beta1.types import prediction_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.protobuf import any_pb2 # type: ignore from google.protobuf import struct_pb2 # type: ignore from .transports.base import PredictionServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc import PredictionServiceGrpcTransport @@ -53,9 +63,10 @@ class PredictionServiceClientMeta(type): _transport_registry["grpc_asyncio"] = PredictionServiceGrpcAsyncIOTransport def get_transport_class( - cls, label: str = None, + cls, + label: str = None, ) -> Type[PredictionServiceTransport]: - """Return an appropriate transport class. + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -78,7 +89,8 @@ class PredictionServiceClient(metaclass=PredictionServiceClientMeta): @staticmethod def _get_default_mtls_endpoint(api_endpoint): - """Convert api endpoint to mTLS endpoint. + """Converts api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. Args: @@ -112,7 +124,8 @@ def _get_default_mtls_endpoint(api_endpoint): @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -129,7 +142,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -148,23 +161,30 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> PredictionServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - PredictionServiceTransport: The transport used by the client instance. + PredictionServiceTransport: The transport used by the client + instance. """ return self._transport @staticmethod - def endpoint_path(project: str, location: str, endpoint: str,) -> str: - """Return a fully-qualified endpoint string.""" + def endpoint_path( + project: str, + location: str, + endpoint: str, + ) -> str: + """Returns a fully-qualified endpoint string.""" return "projects/{project}/locations/{location}/endpoints/{endpoint}".format( - project=project, location=location, endpoint=endpoint, + project=project, + location=location, + endpoint=endpoint, ) @staticmethod def parse_endpoint_path(path: str) -> Dict[str, str]: - """Parse a endpoint path into its component segments.""" + """Parses a endpoint path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/endpoints/(?P.+?)$", path, @@ -172,8 +192,32 @@ def parse_endpoint_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + def model_path( + project: str, + location: str, + model: str, + ) -> str: + """Returns a fully-qualified model string.""" + return "projects/{project}/locations/{location}/models/{model}".format( + project=project, + location=location, + model=model, + ) + + @staticmethod + def parse_model_path(path: str) -> Dict[str, str]: + """Parses a model path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/models/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def common_billing_account_path( + billing_account: str, + ) -> str: + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -185,9 +229,13 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: 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,) + def common_folder_path( + folder: str, + ) -> str: + """Returns a fully-qualified folder string.""" + return "folders/{folder}".format( + folder=folder, + ) @staticmethod def parse_common_folder_path(path: str) -> Dict[str, str]: @@ -196,9 +244,13 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: 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,) + def common_organization_path( + organization: str, + ) -> str: + """Returns a fully-qualified organization string.""" + return "organizations/{organization}".format( + organization=organization, + ) @staticmethod def parse_common_organization_path(path: str) -> Dict[str, str]: @@ -207,9 +259,13 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: 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,) + def common_project_path( + project: str, + ) -> str: + """Returns a fully-qualified project string.""" + return "projects/{project}".format( + project=project, + ) @staticmethod def parse_common_project_path(path: str) -> Dict[str, str]: @@ -218,10 +274,14 @@ def parse_common_project_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_location_path(project: str, location: str,) -> str: - """Return a fully-qualified location string.""" + def common_location_path( + project: str, + location: str, + ) -> str: + """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) @staticmethod @@ -230,6 +290,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + def __init__( self, *, @@ -238,7 +365,7 @@ def __init__( client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the prediction service client. + """Instantiates the prediction service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -280,58 +407,42 @@ def __init__( 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")) + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - client_cert_source_func = ( - mtls.default_client_cert_source() 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" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # 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, PredictionServiceTransport): # transport is a PredictionServiceTransport instance. - if credentials or client_options.credentials_file: + if credentials or client_options.credentials_file or api_key_value: 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." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + Transport = type(self).get_transport_class(transport) self._transport = Transport( credentials=credentials, @@ -341,23 +452,47 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, + always_use_jwt_access=True, ) def predict( self, - request: prediction_service.PredictRequest = None, + request: Union[prediction_service.PredictRequest, dict] = None, *, endpoint: str = None, instances: Sequence[struct_pb2.Value] = None, parameters: struct_pb2.Value = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> prediction_service.PredictResponse: r"""Perform an online prediction. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_predict(): + # Create a client + client = aiplatform_v1beta1.PredictionServiceClient() + + # Initialize request argument(s) + instances = aiplatform_v1beta1.Value() + instances.null_value = "NULL_VALUE" + + request = aiplatform_v1beta1.PredictRequest( + endpoint="endpoint_value", + instances=instances, + ) + + # Make the request + response = client.predict(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.PredictRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.PredictRequest, dict]): The request object. Request message for [PredictionService.Predict][google.cloud.aiplatform.v1beta1.PredictionService.Predict]. endpoint (str): @@ -408,7 +543,7 @@ def predict( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([endpoint, instances, parameters]) if request is not None and has_flattened_params: @@ -443,20 +578,204 @@ def predict( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def raw_predict( + self, + request: Union[prediction_service.RawPredictRequest, dict] = None, + *, + endpoint: str = None, + http_body: httpbody_pb2.HttpBody = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> httpbody_pb2.HttpBody: + r"""Perform an online prediction with an arbitrary HTTP payload. + + The response includes the following HTTP headers: + + - ``X-Vertex-AI-Endpoint-Id``: ID of the + [Endpoint][google.cloud.aiplatform.v1beta1.Endpoint] that + served this prediction. + + - ``X-Vertex-AI-Deployed-Model-Id``: ID of the Endpoint's + [DeployedModel][google.cloud.aiplatform.v1beta1.DeployedModel] + that served this prediction. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_raw_predict(): + # Create a client + client = aiplatform_v1beta1.PredictionServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.RawPredictRequest( + endpoint="endpoint_value", + ) + + # Make the request + response = client.raw_predict(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.RawPredictRequest, dict]): + The request object. Request message for + [PredictionService.RawPredict][google.cloud.aiplatform.v1beta1.PredictionService.RawPredict]. + endpoint (str): + Required. The name of the Endpoint requested to serve + the prediction. Format: + ``projects/{project}/locations/{location}/endpoints/{endpoint}`` + + This corresponds to the ``endpoint`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + http_body (google.api.httpbody_pb2.HttpBody): + The prediction input. Supports HTTP headers and + arbitrary data payload. + + A + [DeployedModel][google.cloud.aiplatform.v1beta1.DeployedModel] + may have an upper limit on the number of instances it + supports per request. When this limit it is exceeded for + an AutoML model, the + [RawPredict][google.cloud.aiplatform.v1beta1.PredictionService.RawPredict] + method returns an error. When this limit is exceeded for + a custom-trained model, the behavior varies depending on + the model. + + You can specify the schema for each instance in the + [predict_schemata.instance_schema_uri][google.cloud.aiplatform.v1beta1.PredictSchemata.instance_schema_uri] + field when you create a + [Model][google.cloud.aiplatform.v1beta1.Model]. This + schema applies when you deploy the ``Model`` as a + ``DeployedModel`` to an + [Endpoint][google.cloud.aiplatform.v1beta1.Endpoint] and + use the ``RawPredict`` method. + + This corresponds to the ``http_body`` 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: + google.api.httpbody_pb2.HttpBody: + Message that represents an arbitrary HTTP body. It should only be used for + payload formats that can't be represented as JSON, + such as raw binary or an HTML page. + + This message can be used both in streaming and + non-streaming API methods in the request as well as + the response. + + It can be used as a top-level request field, which is + convenient if one wants to extract parameters from + either the URL or HTTP template into the request + fields and also want access to the raw HTTP body. + + Example: + + message GetResourceRequest { + // A unique request id. string request_id = 1; + + // The raw HTTP body is bound to this field. + google.api.HttpBody http_body = 2; + + } + + service ResourceService { + rpc GetResource(GetResourceRequest) + returns (google.api.HttpBody); + + rpc UpdateResource(google.api.HttpBody) + returns (google.protobuf.Empty); + + } + + Example with streaming methods: + + service CaldavService { + rpc GetCalendar(stream google.api.HttpBody) + returns (stream google.api.HttpBody); + + rpc UpdateCalendar(stream google.api.HttpBody) + returns (stream google.api.HttpBody); + + } + + Use of this type only changes how the request and + response bodies are handled, all other features will + continue to work unchanged. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([endpoint, http_body]) + 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 prediction_service.RawPredictRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, prediction_service.RawPredictRequest): + request = prediction_service.RawPredictRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if endpoint is not None: + request.endpoint = endpoint + if http_body is not None: + request.http_body = http_body + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.raw_predict] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("endpoint", request.endpoint),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def explain( self, - request: prediction_service.ExplainRequest = None, + request: Union[prediction_service.ExplainRequest, dict] = None, *, endpoint: str = None, instances: Sequence[struct_pb2.Value] = None, parameters: struct_pb2.Value = None, deployed_model_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> prediction_service.ExplainResponse: @@ -473,8 +792,31 @@ def explain( populated. Only deployed AutoML tabular Models have explanation_spec. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_explain(): + # Create a client + client = aiplatform_v1beta1.PredictionServiceClient() + + # Initialize request argument(s) + instances = aiplatform_v1beta1.Value() + instances.null_value = "NULL_VALUE" + + request = aiplatform_v1beta1.ExplainRequest( + endpoint="endpoint_value", + instances=instances, + ) + + # Make the request + response = client.explain(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ExplainRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ExplainRequest, dict]): The request object. Request message for [PredictionService.Explain][google.cloud.aiplatform.v1beta1.PredictionService.Explain]. endpoint (str): @@ -533,7 +875,7 @@ def explain( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([endpoint, instances, parameters, deployed_model_id]) if request is not None and has_flattened_params: @@ -570,7 +912,696 @@ def explain( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_operations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.delete_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.wait_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_location, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_locations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response diff --git a/google/cloud/aiplatform_v1beta1/services/prediction_service/transports/__init__.py b/google/cloud/aiplatform_v1beta1/services/prediction_service/transports/__init__.py index 86d2e8a7f3..3b81984dc0 100644 --- a/google/cloud/aiplatform_v1beta1/services/prediction_service/transports/__init__.py +++ b/google/cloud/aiplatform_v1beta1/services/prediction_service/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1beta1/services/prediction_service/transports/base.py b/google/cloud/aiplatform_v1beta1/services/prediction_service/transports/base.py index 9006c8335a..d395f632c3 100644 --- a/google/cloud/aiplatform_v1beta1/services/prediction_service/transports/base.py +++ b/google/cloud/aiplatform_v1beta1/services/prediction_service/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,17 +15,22 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore +from google.api import httpbody_pb2 # type: ignore from google.cloud.aiplatform_v1beta1.types import prediction_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( @@ -36,17 +41,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - -_API_CORE_VERSION = google.api_core.__version__ - class PredictionServiceTransport(abc.ABC): """Abstract transport class for PredictionService.""" @@ -64,6 +58,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -87,16 +82,19 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -109,71 +107,51 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id ) - # Save the credentials. - self._credentials = credentials - - # TODO(busunkim): These two class methods are in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-api-core - # and google-auth are increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") - ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs - - # TODO: Remove this function once google-api-core >= 1.26.0 is required - @classmethod - def _get_self_signed_jwt_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Union[Optional[Sequence[str]], str]]: - """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" - - self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} - - if _API_CORE_VERSION and ( - packaging.version.parse(_API_CORE_VERSION) - >= packaging.version.parse("1.26.0") + # If the credentials are service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") ): - self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES - self_signed_jwt_kwargs["scopes"] = scopes - self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST - else: - self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES + credentials = credentials.with_always_use_jwt_access(True) - return self_signed_jwt_kwargs + # Save the credentials. + self._credentials = credentials def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { self.predict: gapic_v1.method.wrap_method( - self.predict, default_timeout=5.0, client_info=client_info, + self.predict, + default_timeout=5.0, + client_info=client_info, + ), + self.raw_predict: gapic_v1.method.wrap_method( + self.raw_predict, + default_timeout=None, + client_info=client_info, ), self.explain: gapic_v1.method.wrap_method( - self.explain, default_timeout=5.0, client_info=client_info, + self.explain, + default_timeout=5.0, + client_info=client_info, ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property def predict( self, @@ -186,6 +164,15 @@ def predict( ]: raise NotImplementedError() + @property + def raw_predict( + self, + ) -> Callable[ + [prediction_service.RawPredictRequest], + Union[httpbody_pb2.HttpBody, Awaitable[httpbody_pb2.HttpBody]], + ]: + raise NotImplementedError() + @property def explain( self, @@ -198,5 +185,102 @@ def explain( ]: raise NotImplementedError() + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], + Union[ + operations_pb2.ListOperationsResponse, + Awaitable[operations_pb2.ListOperationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None,]: + raise NotImplementedError() + + @property + def wait_operation( + self, + ) -> Callable[ + [operations_pb2.WaitOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def set_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def get_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_location( + self, + ) -> Callable[ + [locations_pb2.GetLocationRequest], + Union[locations_pb2.Location, Awaitable[locations_pb2.Location]], + ]: + raise NotImplementedError() + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], + Union[ + locations_pb2.ListLocationsResponse, + Awaitable[locations_pb2.ListLocationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + __all__ = ("PredictionServiceTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/prediction_service/transports/grpc.py b/google/cloud/aiplatform_v1beta1/services/prediction_service/transports/grpc.py index 1abce01400..4663d79b5c 100644 --- a/google/cloud/aiplatform_v1beta1/services/prediction_service/transports/grpc.py +++ b/google/cloud/aiplatform_v1beta1/services/prediction_service/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,15 +16,20 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore import grpc # type: ignore +from google.api import httpbody_pb2 # type: ignore from google.cloud.aiplatform_v1beta1.types import prediction_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from .base import PredictionServiceTransport, DEFAULT_CLIENT_INFO @@ -57,6 +62,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -79,16 +85,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -97,6 +103,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport @@ -149,13 +157,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -204,21 +216,20 @@ def create_channel( and ``credentials_file`` are passed. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @property def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ + """Return the channel designed to connect to this service.""" return self._grpc_channel @property @@ -249,6 +260,42 @@ def predict( ) return self._stubs["predict"] + @property + def raw_predict( + self, + ) -> Callable[[prediction_service.RawPredictRequest], httpbody_pb2.HttpBody]: + r"""Return a callable for the raw predict method over gRPC. + + Perform an online prediction with an arbitrary HTTP payload. + + The response includes the following HTTP headers: + + - ``X-Vertex-AI-Endpoint-Id``: ID of the + [Endpoint][google.cloud.aiplatform.v1beta1.Endpoint] that + served this prediction. + + - ``X-Vertex-AI-Deployed-Model-Id``: ID of the Endpoint's + [DeployedModel][google.cloud.aiplatform.v1beta1.DeployedModel] + that served this prediction. + + Returns: + Callable[[~.RawPredictRequest], + ~.HttpBody]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "raw_predict" not in self._stubs: + self._stubs["raw_predict"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1beta1.PredictionService/RawPredict", + request_serializer=prediction_service.RawPredictRequest.serialize, + response_deserializer=httpbody_pb2.HttpBody.FromString, + ) + return self._stubs["raw_predict"] + @property def explain( self, @@ -288,5 +335,215 @@ def explain( ) return self._stubs["explain"] + def close(self): + self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + @property + def kind(self) -> str: + return "grpc" + __all__ = ("PredictionServiceGrpcTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/prediction_service/transports/grpc_asyncio.py b/google/cloud/aiplatform_v1beta1/services/prediction_service/transports/grpc_asyncio.py index 631b0d7ec4..2048cf6a9d 100644 --- a/google/cloud/aiplatform_v1beta1/services/prediction_service/transports/grpc_asyncio.py +++ b/google/cloud/aiplatform_v1beta1/services/prediction_service/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,16 +16,20 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore +from google.api import httpbody_pb2 # type: ignore from google.cloud.aiplatform_v1beta1.types import prediction_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from .base import PredictionServiceTransport, DEFAULT_CLIENT_INFO from .grpc import PredictionServiceGrpcTransport @@ -78,14 +82,14 @@ def create_channel( aio.Channel: A gRPC AsyncIO channel object. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @@ -103,6 +107,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -126,16 +131,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -144,6 +149,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport @@ -195,13 +202,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -253,6 +264,44 @@ def predict( ) return self._stubs["predict"] + @property + def raw_predict( + self, + ) -> Callable[ + [prediction_service.RawPredictRequest], Awaitable[httpbody_pb2.HttpBody] + ]: + r"""Return a callable for the raw predict method over gRPC. + + Perform an online prediction with an arbitrary HTTP payload. + + The response includes the following HTTP headers: + + - ``X-Vertex-AI-Endpoint-Id``: ID of the + [Endpoint][google.cloud.aiplatform.v1beta1.Endpoint] that + served this prediction. + + - ``X-Vertex-AI-Deployed-Model-Id``: ID of the Endpoint's + [DeployedModel][google.cloud.aiplatform.v1beta1.DeployedModel] + that served this prediction. + + Returns: + Callable[[~.RawPredictRequest], + Awaitable[~.HttpBody]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "raw_predict" not in self._stubs: + self._stubs["raw_predict"] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1beta1.PredictionService/RawPredict", + request_serializer=prediction_service.RawPredictRequest.serialize, + response_deserializer=httpbody_pb2.HttpBody.FromString, + ) + return self._stubs["raw_predict"] + @property def explain( self, @@ -293,5 +342,211 @@ def explain( ) return self._stubs["explain"] + def close(self): + return self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + __all__ = ("PredictionServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/specialist_pool_service/__init__.py b/google/cloud/aiplatform_v1beta1/services/specialist_pool_service/__init__.py index dea5d1cc17..0f61e0cadc 100644 --- a/google/cloud/aiplatform_v1beta1/services/specialist_pool_service/__init__.py +++ b/google/cloud/aiplatform_v1beta1/services/specialist_pool_service/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1beta1/services/specialist_pool_service/async_client.py b/google/cloud/aiplatform_v1beta1/services/specialist_pool_service/async_client.py index 9bbde22def..bc0e75d038 100644 --- a/google/cloud/aiplatform_v1beta1/services/specialist_pool_service/async_client.py +++ b/google/cloud/aiplatform_v1beta1/services/specialist_pool_service/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,16 +16,21 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation as gac_operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1beta1.services.specialist_pool_service import pagers @@ -33,6 +38,10 @@ from google.cloud.aiplatform_v1beta1.types import specialist_pool from google.cloud.aiplatform_v1beta1.types import specialist_pool as gca_specialist_pool from google.cloud.aiplatform_v1beta1.types import specialist_pool_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore from .transports.base import SpecialistPoolServiceTransport, DEFAULT_CLIENT_INFO @@ -89,7 +98,8 @@ class SpecialistPoolServiceAsyncClient: @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -104,7 +114,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -119,9 +129,45 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return SpecialistPoolServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> SpecialistPoolServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: SpecialistPoolServiceTransport: The transport used by the client instance. @@ -141,7 +187,7 @@ def __init__( client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the specialist pool service client. + """Instantiates the specialist pool service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -182,18 +228,48 @@ def __init__( async def create_specialist_pool( self, - request: specialist_pool_service.CreateSpecialistPoolRequest = None, + request: Union[ + specialist_pool_service.CreateSpecialistPoolRequest, dict + ] = None, *, parent: str = None, specialist_pool: gca_specialist_pool.SpecialistPool = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Creates a SpecialistPool. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_create_specialist_pool(): + # Create a client + client = aiplatform_v1beta1.SpecialistPoolServiceAsyncClient() + + # Initialize request argument(s) + specialist_pool = aiplatform_v1beta1.SpecialistPool() + specialist_pool.name = "name_value" + specialist_pool.display_name = "display_name_value" + + request = aiplatform_v1beta1.CreateSpecialistPoolRequest( + parent="parent_value", + specialist_pool=specialist_pool, + ) + + # Make the request + operation = client.create_specialist_pool(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.CreateSpecialistPoolRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateSpecialistPoolRequest, dict]): The request object. Request message for [SpecialistPoolService.CreateSpecialistPool][google.cloud.aiplatform.v1beta1.SpecialistPoolService.CreateSpecialistPool]. parent (:class:`str`): @@ -223,16 +299,16 @@ async def create_specialist_pool( The result type for the operation will be :class:`google.cloud.aiplatform_v1beta1.types.SpecialistPool` SpecialistPool represents customers' own workforce to work on their data labeling jobs. It includes a group of specialist - managers who are responsible for managing the - labelers in this pool as well as customers' data - labeling jobs associated with this pool. Customers - create specialist pool as well as start data labeling - jobs on Cloud, managers and labelers work with the - jobs using CrowdCompute console. + managers and workers. Managers are responsible for + managing the workers in this pool as well as + customers' data labeling jobs associated with this + pool. Customers create specialist pool as well as + start data labeling jobs on Cloud, managers and + workers handle the jobs using CrowdCompute console. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, specialist_pool]) if request is not None and has_flattened_params: @@ -265,7 +341,12 @@ async def create_specialist_pool( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -280,17 +361,36 @@ async def create_specialist_pool( async def get_specialist_pool( self, - request: specialist_pool_service.GetSpecialistPoolRequest = None, + request: Union[specialist_pool_service.GetSpecialistPoolRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> specialist_pool.SpecialistPool: r"""Gets a SpecialistPool. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_get_specialist_pool(): + # Create a client + client = aiplatform_v1beta1.SpecialistPoolServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetSpecialistPoolRequest( + name="name_value", + ) + + # Make the request + response = await client.get_specialist_pool(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.GetSpecialistPoolRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.GetSpecialistPoolRequest, dict]): The request object. Request message for [SpecialistPoolService.GetSpecialistPool][google.cloud.aiplatform.v1beta1.SpecialistPoolService.GetSpecialistPool]. name (:class:`str`): @@ -312,18 +412,19 @@ async def get_specialist_pool( SpecialistPool represents customers' own workforce to work on their data labeling jobs. It includes a group of - specialist managers who are responsible - for managing the labelers in this pool - as well as customers' data labeling jobs - associated with this pool. - Customers create specialist pool as well - as start data labeling jobs on Cloud, - managers and labelers work with the jobs - using CrowdCompute console. + specialist managers and workers. + Managers are responsible for managing + the workers in this pool as well as + customers' data labeling jobs associated + with this pool. Customers create + specialist pool as well as start data + labeling jobs on Cloud, managers and + workers handle the jobs using + CrowdCompute console. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -354,24 +455,49 @@ async def get_specialist_pool( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_specialist_pools( self, - request: specialist_pool_service.ListSpecialistPoolsRequest = None, + request: Union[specialist_pool_service.ListSpecialistPoolsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListSpecialistPoolsAsyncPager: r"""Lists SpecialistPools in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_list_specialist_pools(): + # Create a client + client = aiplatform_v1beta1.SpecialistPoolServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListSpecialistPoolsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_specialist_pools(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ListSpecialistPoolsRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ListSpecialistPoolsRequest, dict]): The request object. Request message for [SpecialistPoolService.ListSpecialistPools][google.cloud.aiplatform.v1beta1.SpecialistPoolService.ListSpecialistPools]. parent (:class:`str`): @@ -398,7 +524,7 @@ async def list_specialist_pools( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -429,12 +555,20 @@ async def list_specialist_pools( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListSpecialistPoolsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -442,18 +576,43 @@ async def list_specialist_pools( async def delete_specialist_pool( self, - request: specialist_pool_service.DeleteSpecialistPoolRequest = None, + request: Union[ + specialist_pool_service.DeleteSpecialistPoolRequest, dict + ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a SpecialistPool as well as all Specialists in the pool. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_delete_specialist_pool(): + # Create a client + client = aiplatform_v1beta1.SpecialistPoolServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteSpecialistPoolRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_specialist_pool(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.DeleteSpecialistPoolRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteSpecialistPoolRequest, dict]): The request object. Request message for [SpecialistPoolService.DeleteSpecialistPool][google.cloud.aiplatform.v1beta1.SpecialistPoolService.DeleteSpecialistPool]. name (:class:`str`): @@ -490,7 +649,7 @@ async def delete_specialist_pool( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -521,7 +680,12 @@ async def delete_specialist_pool( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -536,18 +700,47 @@ async def delete_specialist_pool( async def update_specialist_pool( self, - request: specialist_pool_service.UpdateSpecialistPoolRequest = None, + request: Union[ + specialist_pool_service.UpdateSpecialistPoolRequest, dict + ] = None, *, specialist_pool: gca_specialist_pool.SpecialistPool = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Updates a SpecialistPool. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_update_specialist_pool(): + # Create a client + client = aiplatform_v1beta1.SpecialistPoolServiceAsyncClient() + + # Initialize request argument(s) + specialist_pool = aiplatform_v1beta1.SpecialistPool() + specialist_pool.name = "name_value" + specialist_pool.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateSpecialistPoolRequest( + specialist_pool=specialist_pool, + ) + + # Make the request + operation = client.update_specialist_pool(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.UpdateSpecialistPoolRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.UpdateSpecialistPoolRequest, dict]): The request object. Request message for [SpecialistPoolService.UpdateSpecialistPool][google.cloud.aiplatform.v1beta1.SpecialistPoolService.UpdateSpecialistPool]. specialist_pool (:class:`google.cloud.aiplatform_v1beta1.types.SpecialistPool`): @@ -576,16 +769,16 @@ async def update_specialist_pool( The result type for the operation will be :class:`google.cloud.aiplatform_v1beta1.types.SpecialistPool` SpecialistPool represents customers' own workforce to work on their data labeling jobs. It includes a group of specialist - managers who are responsible for managing the - labelers in this pool as well as customers' data - labeling jobs associated with this pool. Customers - create specialist pool as well as start data labeling - jobs on Cloud, managers and labelers work with the - jobs using CrowdCompute console. + managers and workers. Managers are responsible for + managing the workers in this pool as well as + customers' data labeling jobs associated with this + pool. Customers create specialist pool as well as + start data labeling jobs on Cloud, managers and + workers handle the jobs using CrowdCompute console. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([specialist_pool, update_mask]) if request is not None and has_flattened_params: @@ -620,7 +813,12 @@ async def update_specialist_pool( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -633,6 +831,683 @@ async def update_specialist_pool( # Done; return the response. return response + async def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_operations, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.delete_operation, + default_timeout=None, + 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 cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + 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 wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.wait_operation, + default_timeout=None, + 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 set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_location, + default_timeout=None, + 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 list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_locations, + default_timeout=None, + 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 __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/aiplatform_v1beta1/services/specialist_pool_service/client.py b/google/cloud/aiplatform_v1beta1/services/specialist_pool_service/client.py index 8b5a23c39f..2c9ca39645 100644 --- a/google/cloud/aiplatform_v1beta1/services/specialist_pool_service/client.py +++ b/google/cloud/aiplatform_v1beta1/services/specialist_pool_service/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,22 +14,26 @@ # 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 +from typing import Dict, Mapping, 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 as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_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 +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation as gac_operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1beta1.services.specialist_pool_service import pagers @@ -37,6 +41,10 @@ from google.cloud.aiplatform_v1beta1.types import specialist_pool from google.cloud.aiplatform_v1beta1.types import specialist_pool as gca_specialist_pool from google.cloud.aiplatform_v1beta1.types import specialist_pool_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore from .transports.base import SpecialistPoolServiceTransport, DEFAULT_CLIENT_INFO @@ -59,9 +67,10 @@ class SpecialistPoolServiceClientMeta(type): _transport_registry["grpc_asyncio"] = SpecialistPoolServiceGrpcAsyncIOTransport def get_transport_class( - cls, label: str = None, + cls, + label: str = None, ) -> Type[SpecialistPoolServiceTransport]: - """Return an appropriate transport class. + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -90,7 +99,8 @@ class SpecialistPoolServiceClient(metaclass=SpecialistPoolServiceClientMeta): @staticmethod def _get_default_mtls_endpoint(api_endpoint): - """Convert api endpoint to mTLS endpoint. + """Converts api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. Args: @@ -124,7 +134,8 @@ def _get_default_mtls_endpoint(api_endpoint): @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -141,7 +152,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -160,23 +171,30 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> SpecialistPoolServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - SpecialistPoolServiceTransport: The transport used by the client instance. + SpecialistPoolServiceTransport: The transport used by the client + instance. """ return self._transport @staticmethod - def specialist_pool_path(project: str, location: str, specialist_pool: str,) -> str: - """Return a fully-qualified specialist_pool string.""" + def specialist_pool_path( + project: str, + location: str, + specialist_pool: str, + ) -> str: + """Returns a fully-qualified specialist_pool string.""" return "projects/{project}/locations/{location}/specialistPools/{specialist_pool}".format( - project=project, location=location, specialist_pool=specialist_pool, + project=project, + location=location, + specialist_pool=specialist_pool, ) @staticmethod def parse_specialist_pool_path(path: str) -> Dict[str, str]: - """Parse a specialist_pool path into its component segments.""" + """Parses a specialist_pool path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/specialistPools/(?P.+?)$", path, @@ -184,8 +202,10 @@ def parse_specialist_pool_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + def common_billing_account_path( + billing_account: str, + ) -> str: + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -197,9 +217,13 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: 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,) + def common_folder_path( + folder: str, + ) -> str: + """Returns a fully-qualified folder string.""" + return "folders/{folder}".format( + folder=folder, + ) @staticmethod def parse_common_folder_path(path: str) -> Dict[str, str]: @@ -208,9 +232,13 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: 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,) + def common_organization_path( + organization: str, + ) -> str: + """Returns a fully-qualified organization string.""" + return "organizations/{organization}".format( + organization=organization, + ) @staticmethod def parse_common_organization_path(path: str) -> Dict[str, str]: @@ -219,9 +247,13 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: 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,) + def common_project_path( + project: str, + ) -> str: + """Returns a fully-qualified project string.""" + return "projects/{project}".format( + project=project, + ) @staticmethod def parse_common_project_path(path: str) -> Dict[str, str]: @@ -230,10 +262,14 @@ def parse_common_project_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_location_path(project: str, location: str,) -> str: - """Return a fully-qualified location string.""" + def common_location_path( + project: str, + location: str, + ) -> str: + """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) @staticmethod @@ -242,6 +278,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + def __init__( self, *, @@ -250,7 +353,7 @@ def __init__( client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the specialist pool service client. + """Instantiates the specialist pool service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -292,58 +395,42 @@ def __init__( 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")) + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - client_cert_source_func = ( - mtls.default_client_cert_source() 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" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # 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, SpecialistPoolServiceTransport): # transport is a SpecialistPoolServiceTransport instance. - if credentials or client_options.credentials_file: + if credentials or client_options.credentials_file or api_key_value: 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." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + Transport = type(self).get_transport_class(transport) self._transport = Transport( credentials=credentials, @@ -353,22 +440,53 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, + always_use_jwt_access=True, ) def create_specialist_pool( self, - request: specialist_pool_service.CreateSpecialistPoolRequest = None, + request: Union[ + specialist_pool_service.CreateSpecialistPoolRequest, dict + ] = None, *, parent: str = None, specialist_pool: gca_specialist_pool.SpecialistPool = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Creates a SpecialistPool. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_create_specialist_pool(): + # Create a client + client = aiplatform_v1beta1.SpecialistPoolServiceClient() + + # Initialize request argument(s) + specialist_pool = aiplatform_v1beta1.SpecialistPool() + specialist_pool.name = "name_value" + specialist_pool.display_name = "display_name_value" + + request = aiplatform_v1beta1.CreateSpecialistPoolRequest( + parent="parent_value", + specialist_pool=specialist_pool, + ) + + # Make the request + operation = client.create_specialist_pool(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.CreateSpecialistPoolRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateSpecialistPoolRequest, dict]): The request object. Request message for [SpecialistPoolService.CreateSpecialistPool][google.cloud.aiplatform.v1beta1.SpecialistPoolService.CreateSpecialistPool]. parent (str): @@ -398,16 +516,16 @@ def create_specialist_pool( The result type for the operation will be :class:`google.cloud.aiplatform_v1beta1.types.SpecialistPool` SpecialistPool represents customers' own workforce to work on their data labeling jobs. It includes a group of specialist - managers who are responsible for managing the - labelers in this pool as well as customers' data - labeling jobs associated with this pool. Customers - create specialist pool as well as start data labeling - jobs on Cloud, managers and labelers work with the - jobs using CrowdCompute console. + managers and workers. Managers are responsible for + managing the workers in this pool as well as + customers' data labeling jobs associated with this + pool. Customers create specialist pool as well as + start data labeling jobs on Cloud, managers and + workers handle the jobs using CrowdCompute console. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, specialist_pool]) if request is not None and has_flattened_params: @@ -440,7 +558,12 @@ def create_specialist_pool( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -455,17 +578,36 @@ def create_specialist_pool( def get_specialist_pool( self, - request: specialist_pool_service.GetSpecialistPoolRequest = None, + request: Union[specialist_pool_service.GetSpecialistPoolRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> specialist_pool.SpecialistPool: r"""Gets a SpecialistPool. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_get_specialist_pool(): + # Create a client + client = aiplatform_v1beta1.SpecialistPoolServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetSpecialistPoolRequest( + name="name_value", + ) + + # Make the request + response = client.get_specialist_pool(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.GetSpecialistPoolRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.GetSpecialistPoolRequest, dict]): The request object. Request message for [SpecialistPoolService.GetSpecialistPool][google.cloud.aiplatform.v1beta1.SpecialistPoolService.GetSpecialistPool]. name (str): @@ -487,18 +629,19 @@ def get_specialist_pool( SpecialistPool represents customers' own workforce to work on their data labeling jobs. It includes a group of - specialist managers who are responsible - for managing the labelers in this pool - as well as customers' data labeling jobs - associated with this pool. - Customers create specialist pool as well - as start data labeling jobs on Cloud, - managers and labelers work with the jobs - using CrowdCompute console. + specialist managers and workers. + Managers are responsible for managing + the workers in this pool as well as + customers' data labeling jobs associated + with this pool. Customers create + specialist pool as well as start data + labeling jobs on Cloud, managers and + workers handle the jobs using + CrowdCompute console. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -529,24 +672,49 @@ def get_specialist_pool( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_specialist_pools( self, - request: specialist_pool_service.ListSpecialistPoolsRequest = None, + request: Union[specialist_pool_service.ListSpecialistPoolsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListSpecialistPoolsPager: r"""Lists SpecialistPools in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_list_specialist_pools(): + # Create a client + client = aiplatform_v1beta1.SpecialistPoolServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListSpecialistPoolsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_specialist_pools(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ListSpecialistPoolsRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ListSpecialistPoolsRequest, dict]): The request object. Request message for [SpecialistPoolService.ListSpecialistPools][google.cloud.aiplatform.v1beta1.SpecialistPoolService.ListSpecialistPools]. parent (str): @@ -573,7 +741,7 @@ def list_specialist_pools( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -604,12 +772,20 @@ def list_specialist_pools( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListSpecialistPoolsPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -617,18 +793,43 @@ def list_specialist_pools( def delete_specialist_pool( self, - request: specialist_pool_service.DeleteSpecialistPoolRequest = None, + request: Union[ + specialist_pool_service.DeleteSpecialistPoolRequest, dict + ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Deletes a SpecialistPool as well as all Specialists in the pool. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_delete_specialist_pool(): + # Create a client + client = aiplatform_v1beta1.SpecialistPoolServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteSpecialistPoolRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_specialist_pool(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.DeleteSpecialistPoolRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteSpecialistPoolRequest, dict]): The request object. Request message for [SpecialistPoolService.DeleteSpecialistPool][google.cloud.aiplatform.v1beta1.SpecialistPoolService.DeleteSpecialistPool]. name (str): @@ -665,7 +866,7 @@ def delete_specialist_pool( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -696,7 +897,12 @@ def delete_specialist_pool( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -711,18 +917,47 @@ def delete_specialist_pool( def update_specialist_pool( self, - request: specialist_pool_service.UpdateSpecialistPoolRequest = None, + request: Union[ + specialist_pool_service.UpdateSpecialistPoolRequest, dict + ] = None, *, specialist_pool: gca_specialist_pool.SpecialistPool = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Updates a SpecialistPool. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_update_specialist_pool(): + # Create a client + client = aiplatform_v1beta1.SpecialistPoolServiceClient() + + # Initialize request argument(s) + specialist_pool = aiplatform_v1beta1.SpecialistPool() + specialist_pool.name = "name_value" + specialist_pool.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateSpecialistPoolRequest( + specialist_pool=specialist_pool, + ) + + # Make the request + operation = client.update_specialist_pool(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.UpdateSpecialistPoolRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.UpdateSpecialistPoolRequest, dict]): The request object. Request message for [SpecialistPoolService.UpdateSpecialistPool][google.cloud.aiplatform.v1beta1.SpecialistPoolService.UpdateSpecialistPool]. specialist_pool (google.cloud.aiplatform_v1beta1.types.SpecialistPool): @@ -751,16 +986,16 @@ def update_specialist_pool( The result type for the operation will be :class:`google.cloud.aiplatform_v1beta1.types.SpecialistPool` SpecialistPool represents customers' own workforce to work on their data labeling jobs. It includes a group of specialist - managers who are responsible for managing the - labelers in this pool as well as customers' data - labeling jobs associated with this pool. Customers - create specialist pool as well as start data labeling - jobs on Cloud, managers and labelers work with the - jobs using CrowdCompute console. + managers and workers. Managers are responsible for + managing the workers in this pool as well as + customers' data labeling jobs associated with this + pool. Customers create specialist pool as well as + start data labeling jobs on Cloud, managers and + workers handle the jobs using CrowdCompute console. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([specialist_pool, update_mask]) if request is not None and has_flattened_params: @@ -795,7 +1030,12 @@ def update_specialist_pool( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -808,6 +1048,690 @@ def update_specialist_pool( # Done; return the response. return response + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_operations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.delete_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.wait_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_location, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_locations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/aiplatform_v1beta1/services/specialist_pool_service/pagers.py b/google/cloud/aiplatform_v1beta1/services/specialist_pool_service/pagers.py index cba513a4b9..d55b692e33 100644 --- a/google/cloud/aiplatform_v1beta1/services/specialist_pool_service/pagers.py +++ b/google/cloud/aiplatform_v1beta1/services/specialist_pool_service/pagers.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,13 +15,13 @@ # from typing import ( Any, - AsyncIterable, + AsyncIterator, Awaitable, Callable, - Iterable, Sequence, Tuple, Optional, + Iterator, ) from google.cloud.aiplatform_v1beta1.types import specialist_pool @@ -75,14 +75,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[specialist_pool_service.ListSpecialistPoolsResponse]: + def pages(self) -> Iterator[specialist_pool_service.ListSpecialistPoolsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[specialist_pool.SpecialistPool]: + def __iter__(self) -> Iterator[specialist_pool.SpecialistPool]: for page in self.pages: yield from page.specialist_pools @@ -118,7 +118,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -141,14 +141,14 @@ def __getattr__(self, name: str) -> Any: @property async def pages( self, - ) -> AsyncIterable[specialist_pool_service.ListSpecialistPoolsResponse]: + ) -> AsyncIterator[specialist_pool_service.ListSpecialistPoolsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[specialist_pool.SpecialistPool]: + def __aiter__(self) -> AsyncIterator[specialist_pool.SpecialistPool]: async def async_generator(): async for page in self.pages: for response in page.specialist_pools: diff --git a/google/cloud/aiplatform_v1beta1/services/specialist_pool_service/transports/__init__.py b/google/cloud/aiplatform_v1beta1/services/specialist_pool_service/transports/__init__.py index cfdda56eda..c8f1c13419 100644 --- a/google/cloud/aiplatform_v1beta1/services/specialist_pool_service/transports/__init__.py +++ b/google/cloud/aiplatform_v1beta1/services/specialist_pool_service/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1beta1/services/specialist_pool_service/transports/base.py b/google/cloud/aiplatform_v1beta1/services/specialist_pool_service/transports/base.py index cbb0dee1cf..a5f7d44ca5 100644 --- a/google/cloud/aiplatform_v1beta1/services/specialist_pool_service/transports/base.py +++ b/google/cloud/aiplatform_v1beta1/services/specialist_pool_service/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,19 +15,23 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.api_core import operations_v1 # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.aiplatform_v1beta1.types import specialist_pool from google.cloud.aiplatform_v1beta1.types import specialist_pool_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore try: @@ -39,17 +43,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - -_API_CORE_VERSION = google.api_core.__version__ - class SpecialistPoolServiceTransport(abc.ABC): """Abstract transport class for SpecialistPoolService.""" @@ -67,6 +60,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -90,16 +84,19 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -112,59 +109,21 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id ) - # Save the credentials. - self._credentials = credentials - - # TODO(busunkim): These two class methods are in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-api-core - # and google-auth are increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") + # If the credentials are service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs + credentials = credentials.with_always_use_jwt_access(True) - # TODO: Remove this function once google-api-core >= 1.26.0 is required - @classmethod - def _get_self_signed_jwt_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Union[Optional[Sequence[str]], str]]: - """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" - - self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} - - if _API_CORE_VERSION and ( - packaging.version.parse(_API_CORE_VERSION) - >= packaging.version.parse("1.26.0") - ): - self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES - self_signed_jwt_kwargs["scopes"] = scopes - self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST - else: - self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES - - return self_signed_jwt_kwargs + # Save the credentials. + self._credentials = credentials def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. @@ -175,7 +134,9 @@ def _prep_wrapped_messages(self, client_info): client_info=client_info, ), self.get_specialist_pool: gapic_v1.method.wrap_method( - self.get_specialist_pool, default_timeout=5.0, client_info=client_info, + self.get_specialist_pool, + default_timeout=5.0, + client_info=client_info, ), self.list_specialist_pools: gapic_v1.method.wrap_method( self.list_specialist_pools, @@ -194,8 +155,17 @@ def _prep_wrapped_messages(self, client_info): ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() @@ -249,5 +219,102 @@ def update_specialist_pool( ]: raise NotImplementedError() + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], + Union[ + operations_pb2.ListOperationsResponse, + Awaitable[operations_pb2.ListOperationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None,]: + raise NotImplementedError() + + @property + def wait_operation( + self, + ) -> Callable[ + [operations_pb2.WaitOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def set_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def get_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_location( + self, + ) -> Callable[ + [locations_pb2.GetLocationRequest], + Union[locations_pb2.Location, Awaitable[locations_pb2.Location]], + ]: + raise NotImplementedError() + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], + Union[ + locations_pb2.ListLocationsResponse, + Awaitable[locations_pb2.ListLocationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + __all__ = ("SpecialistPoolServiceTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/specialist_pool_service/transports/grpc.py b/google/cloud/aiplatform_v1beta1/services/specialist_pool_service/transports/grpc.py index 07f6bb1665..59d3c3e236 100644 --- a/google/cloud/aiplatform_v1beta1/services/specialist_pool_service/transports/grpc.py +++ b/google/cloud/aiplatform_v1beta1/services/specialist_pool_service/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,9 +16,9 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import operations_v1 +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -27,6 +27,10 @@ from google.cloud.aiplatform_v1beta1.types import specialist_pool from google.cloud.aiplatform_v1beta1.types import specialist_pool_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from .base import SpecialistPoolServiceTransport, DEFAULT_CLIENT_INFO @@ -65,6 +69,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -87,16 +92,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -105,6 +110,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport @@ -115,7 +122,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -158,13 +165,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -213,21 +224,20 @@ def create_channel( and ``credentials_file`` are passed. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @property def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ + """Return the channel designed to connect to this service.""" return self._grpc_channel @property @@ -237,7 +247,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsClient(self.grpc_channel) @@ -387,5 +397,215 @@ def update_specialist_pool( ) return self._stubs["update_specialist_pool"] + def close(self): + self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + @property + def kind(self) -> str: + return "grpc" + __all__ = ("SpecialistPoolServiceGrpcTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/specialist_pool_service/transports/grpc_asyncio.py b/google/cloud/aiplatform_v1beta1/services/specialist_pool_service/transports/grpc_asyncio.py index d2fb93a822..b4e75cbdb8 100644 --- a/google/cloud/aiplatform_v1beta1/services/specialist_pool_service/transports/grpc_asyncio.py +++ b/google/cloud/aiplatform_v1beta1/services/specialist_pool_service/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,18 +16,21 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore -from google.api_core import operations_v1 # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore from google.cloud.aiplatform_v1beta1.types import specialist_pool from google.cloud.aiplatform_v1beta1.types import specialist_pool_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from .base import SpecialistPoolServiceTransport, DEFAULT_CLIENT_INFO from .grpc import SpecialistPoolServiceGrpcTransport @@ -86,14 +89,14 @@ def create_channel( aio.Channel: A gRPC AsyncIO channel object. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @@ -111,6 +114,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -134,16 +138,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -152,6 +156,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport @@ -162,7 +168,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -204,13 +210,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -240,7 +250,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel @@ -395,5 +405,211 @@ def update_specialist_pool( ) return self._stubs["update_specialist_pool"] + def close(self): + return self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + __all__ = ("SpecialistPoolServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/tensorboard_service/__init__.py b/google/cloud/aiplatform_v1beta1/services/tensorboard_service/__init__.py index 5a3d5fc22e..91397832d2 100644 --- a/google/cloud/aiplatform_v1beta1/services/tensorboard_service/__init__.py +++ b/google/cloud/aiplatform_v1beta1/services/tensorboard_service/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1beta1/services/tensorboard_service/async_client.py b/google/cloud/aiplatform_v1beta1/services/tensorboard_service/async_client.py index 347535c785..ebfebeb5af 100644 --- a/google/cloud/aiplatform_v1beta1/services/tensorboard_service/async_client.py +++ b/google/cloud/aiplatform_v1beta1/services/tensorboard_service/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,16 +16,31 @@ from collections import OrderedDict import functools import re -from typing import Dict, AsyncIterable, Awaitable, Sequence, Tuple, Type, Union +from typing import ( + Dict, + Mapping, + Optional, + AsyncIterable, + Awaitable, + Sequence, + Tuple, + Type, + Union, +) import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation as gac_operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1beta1.services.tensorboard_service import pagers @@ -45,6 +60,10 @@ from google.cloud.aiplatform_v1beta1.types import ( tensorboard_time_series as gca_tensorboard_time_series, ) +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore @@ -108,7 +127,8 @@ class TensorboardServiceAsyncClient: @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -123,7 +143,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -138,9 +158,45 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return TensorboardServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> TensorboardServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: TensorboardServiceTransport: The transport used by the client instance. @@ -160,7 +216,7 @@ def __init__( client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the tensorboard service client. + """Instantiates the tensorboard service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -201,18 +257,45 @@ def __init__( async def create_tensorboard( self, - request: tensorboard_service.CreateTensorboardRequest = None, + request: Union[tensorboard_service.CreateTensorboardRequest, dict] = None, *, parent: str = None, tensorboard: gca_tensorboard.Tensorboard = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Creates a Tensorboard. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_create_tensorboard(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + tensorboard = aiplatform_v1beta1.Tensorboard() + tensorboard.display_name = "display_name_value" + + request = aiplatform_v1beta1.CreateTensorboardRequest( + parent="parent_value", + tensorboard=tensorboard, + ) + + # Make the request + operation = client.create_tensorboard(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.CreateTensorboardRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateTensorboardRequest, dict]): The request object. Request message for [TensorboardService.CreateTensorboard][google.cloud.aiplatform.v1beta1.TensorboardService.CreateTensorboard]. parent (:class:`str`): @@ -245,7 +328,7 @@ async def create_tensorboard( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, tensorboard]) if request is not None and has_flattened_params: @@ -278,7 +361,12 @@ async def create_tensorboard( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -293,17 +381,36 @@ async def create_tensorboard( async def get_tensorboard( self, - request: tensorboard_service.GetTensorboardRequest = None, + request: Union[tensorboard_service.GetTensorboardRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> tensorboard.Tensorboard: r"""Gets a Tensorboard. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_get_tensorboard(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetTensorboardRequest( + name="name_value", + ) + + # Make the request + response = await client.get_tensorboard(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.GetTensorboardRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.GetTensorboardRequest, dict]): The request object. Request message for [TensorboardService.GetTensorboard][google.cloud.aiplatform.v1beta1.TensorboardService.GetTensorboard]. name (:class:`str`): @@ -330,7 +437,7 @@ async def get_tensorboard( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -361,25 +468,56 @@ async def get_tensorboard( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def update_tensorboard( self, - request: tensorboard_service.UpdateTensorboardRequest = None, + request: Union[tensorboard_service.UpdateTensorboardRequest, dict] = None, *, tensorboard: gca_tensorboard.Tensorboard = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Updates a Tensorboard. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_update_tensorboard(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + tensorboard = aiplatform_v1beta1.Tensorboard() + tensorboard.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateTensorboardRequest( + tensorboard=tensorboard, + ) + + # Make the request + operation = client.update_tensorboard(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.UpdateTensorboardRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.UpdateTensorboardRequest, dict]): The request object. Request message for [TensorboardService.UpdateTensorboard][google.cloud.aiplatform.v1beta1.TensorboardService.UpdateTensorboard]. tensorboard (:class:`google.cloud.aiplatform_v1beta1.types.Tensorboard`): @@ -419,7 +557,7 @@ async def update_tensorboard( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([tensorboard, update_mask]) if request is not None and has_flattened_params: @@ -454,7 +592,12 @@ async def update_tensorboard( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -469,23 +612,43 @@ async def update_tensorboard( async def list_tensorboards( self, - request: tensorboard_service.ListTensorboardsRequest = None, + request: Union[tensorboard_service.ListTensorboardsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListTensorboardsAsyncPager: r"""Lists Tensorboards in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_list_tensorboards(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListTensorboardsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboards(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ListTensorboardsRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ListTensorboardsRequest, dict]): The request object. Request message for [TensorboardService.ListTensorboards][google.cloud.aiplatform.v1beta1.TensorboardService.ListTensorboards]. parent (:class:`str`): - Required. The resource name of the - Location to list Tensorboards. Format: - 'projects/{project}/locations/{location}' + Required. The resource name of the Location to list + Tensorboards. Format: + ``projects/{project}/locations/{location}`` This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -506,7 +669,7 @@ async def list_tensorboards( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -537,12 +700,20 @@ async def list_tensorboards( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListTensorboardsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -550,17 +721,40 @@ async def list_tensorboards( async def delete_tensorboard( self, - request: tensorboard_service.DeleteTensorboardRequest = None, + request: Union[tensorboard_service.DeleteTensorboardRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a Tensorboard. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_delete_tensorboard(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteTensorboardRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.DeleteTensorboardRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteTensorboardRequest, dict]): The request object. Request message for [TensorboardService.DeleteTensorboard][google.cloud.aiplatform.v1beta1.TensorboardService.DeleteTensorboard]. name (:class:`str`): @@ -597,7 +791,7 @@ async def delete_tensorboard( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -628,7 +822,12 @@ async def delete_tensorboard( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -643,19 +842,41 @@ async def delete_tensorboard( async def create_tensorboard_experiment( self, - request: tensorboard_service.CreateTensorboardExperimentRequest = None, + request: Union[ + tensorboard_service.CreateTensorboardExperimentRequest, dict + ] = None, *, parent: str = None, tensorboard_experiment: gca_tensorboard_experiment.TensorboardExperiment = None, tensorboard_experiment_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_tensorboard_experiment.TensorboardExperiment: r"""Creates a TensorboardExperiment. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_create_tensorboard_experiment(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateTensorboardExperimentRequest( + parent="parent_value", + tensorboard_experiment_id="tensorboard_experiment_id_value", + ) + + # Make the request + response = await client.create_tensorboard_experiment(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.CreateTensorboardExperimentRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateTensorboardExperimentRequest, dict]): The request object. Request message for [TensorboardService.CreateTensorboardExperiment][google.cloud.aiplatform.v1beta1.TensorboardService.CreateTensorboardExperiment]. parent (:class:`str`): @@ -697,7 +918,7 @@ async def create_tensorboard_experiment( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, tensorboard_experiment, tensorboard_experiment_id] @@ -734,24 +955,50 @@ async def create_tensorboard_experiment( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def get_tensorboard_experiment( self, - request: tensorboard_service.GetTensorboardExperimentRequest = None, + request: Union[ + tensorboard_service.GetTensorboardExperimentRequest, dict + ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> tensorboard_experiment.TensorboardExperiment: r"""Gets a TensorboardExperiment. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_get_tensorboard_experiment(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetTensorboardExperimentRequest( + name="name_value", + ) + + # Make the request + response = await client.get_tensorboard_experiment(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.GetTensorboardExperimentRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.GetTensorboardExperimentRequest, dict]): The request object. Request message for [TensorboardService.GetTensorboardExperiment][google.cloud.aiplatform.v1beta1.TensorboardService.GetTensorboardExperiment]. name (:class:`str`): @@ -777,7 +1024,7 @@ async def get_tensorboard_experiment( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -808,25 +1055,50 @@ async def get_tensorboard_experiment( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def update_tensorboard_experiment( self, - request: tensorboard_service.UpdateTensorboardExperimentRequest = None, + request: Union[ + tensorboard_service.UpdateTensorboardExperimentRequest, dict + ] = None, *, tensorboard_experiment: gca_tensorboard_experiment.TensorboardExperiment = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_tensorboard_experiment.TensorboardExperiment: r"""Updates a TensorboardExperiment. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_update_tensorboard_experiment(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateTensorboardExperimentRequest( + ) + + # Make the request + response = await client.update_tensorboard_experiment(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.UpdateTensorboardExperimentRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.UpdateTensorboardExperimentRequest, dict]): The request object. Request message for [TensorboardService.UpdateTensorboardExperiment][google.cloud.aiplatform.v1beta1.TensorboardService.UpdateTensorboardExperiment]. tensorboard_experiment (:class:`google.cloud.aiplatform_v1beta1.types.TensorboardExperiment`): @@ -865,7 +1137,7 @@ async def update_tensorboard_experiment( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([tensorboard_experiment, update_mask]) if request is not None and has_flattened_params: @@ -900,24 +1172,51 @@ async def update_tensorboard_experiment( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_tensorboard_experiments( self, - request: tensorboard_service.ListTensorboardExperimentsRequest = None, + request: Union[ + tensorboard_service.ListTensorboardExperimentsRequest, dict + ] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListTensorboardExperimentsAsyncPager: r"""Lists TensorboardExperiments in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_list_tensorboard_experiments(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListTensorboardExperimentsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboard_experiments(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ListTensorboardExperimentsRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ListTensorboardExperimentsRequest, dict]): The request object. Request message for [TensorboardService.ListTensorboardExperiments][google.cloud.aiplatform.v1beta1.TensorboardService.ListTensorboardExperiments]. parent (:class:`str`): @@ -945,7 +1244,7 @@ async def list_tensorboard_experiments( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -976,12 +1275,20 @@ async def list_tensorboard_experiments( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListTensorboardExperimentsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -989,17 +1296,42 @@ async def list_tensorboard_experiments( async def delete_tensorboard_experiment( self, - request: tensorboard_service.DeleteTensorboardExperimentRequest = None, + request: Union[ + tensorboard_service.DeleteTensorboardExperimentRequest, dict + ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a TensorboardExperiment. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_delete_tensorboard_experiment(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteTensorboardExperimentRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard_experiment(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.DeleteTensorboardExperimentRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteTensorboardExperimentRequest, dict]): The request object. Request message for [TensorboardService.DeleteTensorboardExperiment][google.cloud.aiplatform.v1beta1.TensorboardService.DeleteTensorboardExperiment]. name (:class:`str`): @@ -1036,7 +1368,7 @@ async def delete_tensorboard_experiment( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1067,7 +1399,12 @@ async def delete_tensorboard_experiment( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -1082,24 +1419,48 @@ async def delete_tensorboard_experiment( async def create_tensorboard_run( self, - request: tensorboard_service.CreateTensorboardRunRequest = None, + request: Union[tensorboard_service.CreateTensorboardRunRequest, dict] = None, *, parent: str = None, tensorboard_run: gca_tensorboard_run.TensorboardRun = None, tensorboard_run_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_tensorboard_run.TensorboardRun: r"""Creates a TensorboardRun. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_create_tensorboard_run(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + tensorboard_run = aiplatform_v1beta1.TensorboardRun() + tensorboard_run.display_name = "display_name_value" + + request = aiplatform_v1beta1.CreateTensorboardRunRequest( + parent="parent_value", + tensorboard_run=tensorboard_run, + tensorboard_run_id="tensorboard_run_id_value", + ) + + # Make the request + response = await client.create_tensorboard_run(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.CreateTensorboardRunRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateTensorboardRunRequest, dict]): The request object. Request message for [TensorboardService.CreateTensorboardRun][google.cloud.aiplatform.v1beta1.TensorboardService.CreateTensorboardRun]. parent (:class:`str`): - Required. The resource name of the Tensorboard to create - the TensorboardRun in. Format: + Required. The resource name of the TensorboardExperiment + to create the TensorboardRun in. Format: ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` This corresponds to the ``parent`` field @@ -1138,7 +1499,7 @@ async def create_tensorboard_run( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, tensorboard_run, tensorboard_run_id]) if request is not None and has_flattened_params: @@ -1173,24 +1534,167 @@ async def create_tensorboard_run( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def batch_create_tensorboard_runs( + self, + request: Union[ + tensorboard_service.BatchCreateTensorboardRunsRequest, dict + ] = None, + *, + parent: str = None, + requests: Sequence[tensorboard_service.CreateTensorboardRunRequest] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> tensorboard_service.BatchCreateTensorboardRunsResponse: + r"""Batch create TensorboardRuns. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_batch_create_tensorboard_runs(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + requests = aiplatform_v1beta1.CreateTensorboardRunRequest() + requests.parent = "parent_value" + requests.tensorboard_run.display_name = "display_name_value" + requests.tensorboard_run_id = "tensorboard_run_id_value" + + request = aiplatform_v1beta1.BatchCreateTensorboardRunsRequest( + parent="parent_value", + requests=requests, + ) + + # Make the request + response = await client.batch_create_tensorboard_runs(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.BatchCreateTensorboardRunsRequest, dict]): + The request object. Request message for + [TensorboardService.BatchCreateTensorboardRuns][google.cloud.aiplatform.v1beta1.TensorboardService.BatchCreateTensorboardRuns]. + parent (:class:`str`): + Required. The resource name of the TensorboardExperiment + to create the TensorboardRuns in. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` + The parent field in the CreateTensorboardRunRequest + messages must match this field. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + requests (:class:`Sequence[google.cloud.aiplatform_v1beta1.types.CreateTensorboardRunRequest]`): + Required. The request message + specifying the TensorboardRuns to + create. A maximum of 1000 + TensorboardRuns can be created in a + batch. + + This corresponds to the ``requests`` 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: + google.cloud.aiplatform_v1beta1.types.BatchCreateTensorboardRunsResponse: + Response message for + [TensorboardService.BatchCreateTensorboardRuns][google.cloud.aiplatform.v1beta1.TensorboardService.BatchCreateTensorboardRuns]. + + """ + # Create or coerce a protobuf request object. + # Quick 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, requests]) + 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 = tensorboard_service.BatchCreateTensorboardRunsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if requests: + request.requests.extend(requests) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.batch_create_tensorboard_runs, + default_timeout=None, + 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 get_tensorboard_run( self, - request: tensorboard_service.GetTensorboardRunRequest = None, + request: Union[tensorboard_service.GetTensorboardRunRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> tensorboard_run.TensorboardRun: r"""Gets a TensorboardRun. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_get_tensorboard_run(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetTensorboardRunRequest( + name="name_value", + ) + + # Make the request + response = await client.get_tensorboard_run(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.GetTensorboardRunRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.GetTensorboardRunRequest, dict]): The request object. Request message for [TensorboardService.GetTensorboardRun][google.cloud.aiplatform.v1beta1.TensorboardService.GetTensorboardRun]. name (:class:`str`): @@ -1216,7 +1720,7 @@ async def get_tensorboard_run( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1247,25 +1751,52 @@ async def get_tensorboard_run( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def update_tensorboard_run( self, - request: tensorboard_service.UpdateTensorboardRunRequest = None, + request: Union[tensorboard_service.UpdateTensorboardRunRequest, dict] = None, *, tensorboard_run: gca_tensorboard_run.TensorboardRun = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_tensorboard_run.TensorboardRun: r"""Updates a TensorboardRun. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_update_tensorboard_run(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + tensorboard_run = aiplatform_v1beta1.TensorboardRun() + tensorboard_run.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateTensorboardRunRequest( + tensorboard_run=tensorboard_run, + ) + + # Make the request + response = await client.update_tensorboard_run(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.UpdateTensorboardRunRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.UpdateTensorboardRunRequest, dict]): The request object. Request message for [TensorboardService.UpdateTensorboardRun][google.cloud.aiplatform.v1beta1.TensorboardService.UpdateTensorboardRun]. tensorboard_run (:class:`google.cloud.aiplatform_v1beta1.types.TensorboardRun`): @@ -1303,7 +1834,7 @@ async def update_tensorboard_run( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([tensorboard_run, update_mask]) if request is not None and has_flattened_params: @@ -1338,30 +1869,55 @@ async def update_tensorboard_run( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_tensorboard_runs( self, - request: tensorboard_service.ListTensorboardRunsRequest = None, + request: Union[tensorboard_service.ListTensorboardRunsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListTensorboardRunsAsyncPager: r"""Lists TensorboardRuns in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_list_tensorboard_runs(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListTensorboardRunsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboard_runs(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ListTensorboardRunsRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ListTensorboardRunsRequest, dict]): The request object. Request message for [TensorboardService.ListTensorboardRuns][google.cloud.aiplatform.v1beta1.TensorboardService.ListTensorboardRuns]. parent (:class:`str`): Required. The resource name of the - Tensorboard to list TensorboardRuns. - Format: + TensorboardExperiment to list + TensorboardRuns. Format: 'projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}' This corresponds to the ``parent`` field @@ -1383,7 +1939,7 @@ async def list_tensorboard_runs( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1414,12 +1970,20 @@ async def list_tensorboard_runs( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListTensorboardRunsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -1427,17 +1991,40 @@ async def list_tensorboard_runs( async def delete_tensorboard_run( self, - request: tensorboard_service.DeleteTensorboardRunRequest = None, + request: Union[tensorboard_service.DeleteTensorboardRunRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a TensorboardRun. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_delete_tensorboard_run(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteTensorboardRunRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard_run(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.DeleteTensorboardRunRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteTensorboardRunRequest, dict]): The request object. Request message for [TensorboardService.DeleteTensorboardRun][google.cloud.aiplatform.v1beta1.TensorboardService.DeleteTensorboardRun]. name (:class:`str`): @@ -1474,7 +2061,7 @@ async def delete_tensorboard_run( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1505,7 +2092,12 @@ async def delete_tensorboard_run( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -1518,35 +2110,71 @@ async def delete_tensorboard_run( # Done; return the response. return response - async def create_tensorboard_time_series( + async def batch_create_tensorboard_time_series( self, - request: tensorboard_service.CreateTensorboardTimeSeriesRequest = None, + request: Union[ + tensorboard_service.BatchCreateTensorboardTimeSeriesRequest, dict + ] = None, *, parent: str = None, - tensorboard_time_series: gca_tensorboard_time_series.TensorboardTimeSeries = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + requests: Sequence[ + tensorboard_service.CreateTensorboardTimeSeriesRequest + ] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> gca_tensorboard_time_series.TensorboardTimeSeries: - r"""Creates a TensorboardTimeSeries. + ) -> tensorboard_service.BatchCreateTensorboardTimeSeriesResponse: + r"""Batch create TensorboardTimeSeries that belong to a + TensorboardExperiment. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_batch_create_tensorboard_time_series(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + requests = aiplatform_v1beta1.CreateTensorboardTimeSeriesRequest() + requests.parent = "parent_value" + requests.tensorboard_time_series.display_name = "display_name_value" + requests.tensorboard_time_series.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1beta1.BatchCreateTensorboardTimeSeriesRequest( + parent="parent_value", + requests=requests, + ) + + # Make the request + response = await client.batch_create_tensorboard_time_series(request=request) + + # Handle the response + print(response) Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.CreateTensorboardTimeSeriesRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.BatchCreateTensorboardTimeSeriesRequest, dict]): The request object. Request message for - [TensorboardService.CreateTensorboardTimeSeries][google.cloud.aiplatform.v1beta1.TensorboardService.CreateTensorboardTimeSeries]. + [TensorboardService.BatchCreateTensorboardTimeSeries][google.cloud.aiplatform.v1beta1.TensorboardService.BatchCreateTensorboardTimeSeries]. parent (:class:`str`): - Required. The resource name of the TensorboardRun to - create the TensorboardTimeSeries in. Format: - ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}`` + Required. The resource name of the TensorboardExperiment + to create the TensorboardTimeSeries in. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` + The TensorboardRuns referenced by the parent fields in + the CreateTensorboardTimeSeriesRequest messages must be + sub resources of this TensorboardExperiment. This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - tensorboard_time_series (:class:`google.cloud.aiplatform_v1beta1.types.TensorboardTimeSeries`): - Required. The TensorboardTimeSeries - to create. - - This corresponds to the ``tensorboard_time_series`` field + requests (:class:`Sequence[google.cloud.aiplatform_v1beta1.types.CreateTensorboardTimeSeriesRequest]`): + Required. The request message + specifying the TensorboardTimeSeries to + create. A maximum of 1000 + TensorboardTimeSeries can be created in + a batch. + + This corresponds to the ``requests`` 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, @@ -1556,34 +2184,34 @@ async def create_tensorboard_time_series( sent along with the request as metadata. Returns: - google.cloud.aiplatform_v1beta1.types.TensorboardTimeSeries: - TensorboardTimeSeries maps to times - series produced in training runs + google.cloud.aiplatform_v1beta1.types.BatchCreateTensorboardTimeSeriesResponse: + Response message for + [TensorboardService.BatchCreateTensorboardTimeSeries][google.cloud.aiplatform.v1beta1.TensorboardService.BatchCreateTensorboardTimeSeries]. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, tensorboard_time_series]) + has_flattened_params = any([parent, requests]) 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 = tensorboard_service.CreateTensorboardTimeSeriesRequest(request) + request = tensorboard_service.BatchCreateTensorboardTimeSeriesRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if parent is not None: request.parent = parent - if tensorboard_time_series is not None: - request.tensorboard_time_series = tensorboard_time_series + if requests: + request.requests.extend(requests) # 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_tensorboard_time_series, + self._client._transport.batch_create_tensorboard_time_series, default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -1595,24 +2223,163 @@ async def create_tensorboard_time_series( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response - async def get_tensorboard_time_series( + async def create_tensorboard_time_series( self, - request: tensorboard_service.GetTensorboardTimeSeriesRequest = None, + request: Union[ + tensorboard_service.CreateTensorboardTimeSeriesRequest, dict + ] = None, *, - name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + parent: str = None, + tensorboard_time_series: gca_tensorboard_time_series.TensorboardTimeSeries = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> tensorboard_time_series.TensorboardTimeSeries: + ) -> gca_tensorboard_time_series.TensorboardTimeSeries: + r"""Creates a TensorboardTimeSeries. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_create_tensorboard_time_series(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + tensorboard_time_series = aiplatform_v1beta1.TensorboardTimeSeries() + tensorboard_time_series.display_name = "display_name_value" + tensorboard_time_series.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1beta1.CreateTensorboardTimeSeriesRequest( + parent="parent_value", + tensorboard_time_series=tensorboard_time_series, + ) + + # Make the request + response = await client.create_tensorboard_time_series(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.CreateTensorboardTimeSeriesRequest, dict]): + The request object. Request message for + [TensorboardService.CreateTensorboardTimeSeries][google.cloud.aiplatform.v1beta1.TensorboardService.CreateTensorboardTimeSeries]. + parent (:class:`str`): + Required. The resource name of the TensorboardRun to + create the TensorboardTimeSeries in. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}`` + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + tensorboard_time_series (:class:`google.cloud.aiplatform_v1beta1.types.TensorboardTimeSeries`): + Required. The TensorboardTimeSeries + to create. + + This corresponds to the ``tensorboard_time_series`` 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: + google.cloud.aiplatform_v1beta1.types.TensorboardTimeSeries: + TensorboardTimeSeries maps to times + series produced in training runs + + """ + # Create or coerce a protobuf request object. + # Quick 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, tensorboard_time_series]) + 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 = tensorboard_service.CreateTensorboardTimeSeriesRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if tensorboard_time_series is not None: + request.tensorboard_time_series = tensorboard_time_series + + # 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_tensorboard_time_series, + default_timeout=None, + 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 get_tensorboard_time_series( + self, + request: Union[ + tensorboard_service.GetTensorboardTimeSeriesRequest, dict + ] = None, + *, + name: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> tensorboard_time_series.TensorboardTimeSeries: r"""Gets a TensorboardTimeSeries. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_get_tensorboard_time_series(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetTensorboardTimeSeriesRequest( + name="name_value", + ) + + # Make the request + response = await client.get_tensorboard_time_series(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.GetTensorboardTimeSeriesRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.GetTensorboardTimeSeriesRequest, dict]): The request object. Request message for [TensorboardService.GetTensorboardTimeSeries][google.cloud.aiplatform.v1beta1.TensorboardService.GetTensorboardTimeSeries]. name (:class:`str`): @@ -1636,7 +2403,7 @@ async def get_tensorboard_time_series( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1667,25 +2434,55 @@ async def get_tensorboard_time_series( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def update_tensorboard_time_series( self, - request: tensorboard_service.UpdateTensorboardTimeSeriesRequest = None, + request: Union[ + tensorboard_service.UpdateTensorboardTimeSeriesRequest, dict + ] = None, *, tensorboard_time_series: gca_tensorboard_time_series.TensorboardTimeSeries = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_tensorboard_time_series.TensorboardTimeSeries: r"""Updates a TensorboardTimeSeries. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_update_tensorboard_time_series(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + tensorboard_time_series = aiplatform_v1beta1.TensorboardTimeSeries() + tensorboard_time_series.display_name = "display_name_value" + tensorboard_time_series.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1beta1.UpdateTensorboardTimeSeriesRequest( + tensorboard_time_series=tensorboard_time_series, + ) + + # Make the request + response = await client.update_tensorboard_time_series(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.UpdateTensorboardTimeSeriesRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.UpdateTensorboardTimeSeriesRequest, dict]): The request object. Request message for [TensorboardService.UpdateTensorboardTimeSeries][google.cloud.aiplatform.v1beta1.TensorboardService.UpdateTensorboardTimeSeries]. tensorboard_time_series (:class:`google.cloud.aiplatform_v1beta1.types.TensorboardTimeSeries`): @@ -1722,7 +2519,7 @@ async def update_tensorboard_time_series( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([tensorboard_time_series, update_mask]) if request is not None and has_flattened_params: @@ -1762,24 +2559,51 @@ async def update_tensorboard_time_series( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_tensorboard_time_series( self, - request: tensorboard_service.ListTensorboardTimeSeriesRequest = None, + request: Union[ + tensorboard_service.ListTensorboardTimeSeriesRequest, dict + ] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListTensorboardTimeSeriesAsyncPager: r"""Lists TensorboardTimeSeries in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_list_tensorboard_time_series(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListTensorboardTimeSeriesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboard_time_series(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ListTensorboardTimeSeriesRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ListTensorboardTimeSeriesRequest, dict]): The request object. Request message for [TensorboardService.ListTensorboardTimeSeries][google.cloud.aiplatform.v1beta1.TensorboardService.ListTensorboardTimeSeries]. parent (:class:`str`): @@ -1807,7 +2631,7 @@ async def list_tensorboard_time_series( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1838,12 +2662,20 @@ async def list_tensorboard_time_series( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListTensorboardTimeSeriesAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -1851,17 +2683,42 @@ async def list_tensorboard_time_series( async def delete_tensorboard_time_series( self, - request: tensorboard_service.DeleteTensorboardTimeSeriesRequest = None, + request: Union[ + tensorboard_service.DeleteTensorboardTimeSeriesRequest, dict + ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Deletes a TensorboardTimeSeries. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_delete_tensorboard_time_series(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteTensorboardTimeSeriesRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard_time_series(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.DeleteTensorboardTimeSeriesRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteTensorboardTimeSeriesRequest, dict]): The request object. Request message for [TensorboardService.DeleteTensorboardTimeSeries][google.cloud.aiplatform.v1beta1.TensorboardService.DeleteTensorboardTimeSeries]. name (:class:`str`): @@ -1898,7 +2755,7 @@ async def delete_tensorboard_time_series( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1929,7 +2786,12 @@ async def delete_tensorboard_time_series( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -1942,24 +2804,154 @@ async def delete_tensorboard_time_series( # Done; return the response. return response + async def batch_read_tensorboard_time_series_data( + self, + request: Union[ + tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest, dict + ] = None, + *, + tensorboard: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> tensorboard_service.BatchReadTensorboardTimeSeriesDataResponse: + r"""Reads multiple TensorboardTimeSeries' data. The data + point number limit is 1000 for scalars, 100 for tensors + and blob references. If the number of data points stored + is less than the limit, all data will be returned. + Otherwise, that limit number of data points will be + randomly selected from this time series and returned. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_batch_read_tensorboard_time_series_data(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.BatchReadTensorboardTimeSeriesDataRequest( + tensorboard="tensorboard_value", + time_series=['time_series_value_1', 'time_series_value_2'], + ) + + # Make the request + response = await client.batch_read_tensorboard_time_series_data(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.BatchReadTensorboardTimeSeriesDataRequest, dict]): + The request object. Request message for + [TensorboardService.BatchReadTensorboardTimeSeriesData][google.cloud.aiplatform.v1beta1.TensorboardService.BatchReadTensorboardTimeSeriesData]. + tensorboard (:class:`str`): + Required. The resource name of the Tensorboard + containing TensorboardTimeSeries to read data from. + Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}``. + The TensorboardTimeSeries referenced by + [time_series][google.cloud.aiplatform.v1beta1.BatchReadTensorboardTimeSeriesDataRequest.time_series] + must be sub resources of this Tensorboard. + + This corresponds to the ``tensorboard`` 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: + google.cloud.aiplatform_v1beta1.types.BatchReadTensorboardTimeSeriesDataResponse: + Response message for + [TensorboardService.BatchReadTensorboardTimeSeriesData][google.cloud.aiplatform.v1beta1.TensorboardService.BatchReadTensorboardTimeSeriesData]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([tensorboard]) + 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 = tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if tensorboard is not None: + request.tensorboard = tensorboard + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.batch_read_tensorboard_time_series_data, + default_timeout=None, + 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( + (("tensorboard", request.tensorboard),) + ), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + async def read_tensorboard_time_series_data( self, - request: tensorboard_service.ReadTensorboardTimeSeriesDataRequest = None, + request: Union[ + tensorboard_service.ReadTensorboardTimeSeriesDataRequest, dict + ] = None, *, tensorboard_time_series: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> tensorboard_service.ReadTensorboardTimeSeriesDataResponse: - r"""Reads a TensorboardTimeSeries' data. Data is returned in - paginated responses. By default, if the number of data points - stored is less than 1000, all data will be returned. Otherwise, - 1000 data points will be randomly selected from this time series - and returned. This value can be changed by changing - max_data_points. + r"""Reads a TensorboardTimeSeries' data. By default, if the number + of data points stored is less than 1000, all data will be + returned. Otherwise, 1000 data points will be randomly selected + from this time series and returned. This value can be changed by + changing max_data_points, which can't be greater than 10k. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_read_tensorboard_time_series_data(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ReadTensorboardTimeSeriesDataRequest( + tensorboard_time_series="tensorboard_time_series_value", + ) + + # Make the request + response = await client.read_tensorboard_time_series_data(request=request) + + # Handle the response + print(response) Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ReadTensorboardTimeSeriesDataRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ReadTensorboardTimeSeriesDataRequest, dict]): The request object. Request message for [TensorboardService.ReadTensorboardTimeSeriesData][google.cloud.aiplatform.v1beta1.TensorboardService.ReadTensorboardTimeSeriesData]. tensorboard_time_series (:class:`str`): @@ -1983,7 +2975,7 @@ async def read_tensorboard_time_series_data( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([tensorboard_time_series]) if request is not None and has_flattened_params: @@ -2016,17 +3008,22 @@ async def read_tensorboard_time_series_data( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def read_tensorboard_blob_data( self, - request: tensorboard_service.ReadTensorboardBlobDataRequest = None, + request: Union[tensorboard_service.ReadTensorboardBlobDataRequest, dict] = None, *, time_series: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> Awaitable[AsyncIterable[tensorboard_service.ReadTensorboardBlobDataResponse]]: @@ -2035,8 +3032,28 @@ def read_tensorboard_blob_data( project's Cloud Storage bucket without users having to obtain Cloud Storage access permission. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_read_tensorboard_blob_data(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ReadTensorboardBlobDataRequest( + time_series="time_series_value", + ) + + # Make the request + stream = await client.read_tensorboard_blob_data(request=request) + + # Handle the response + async for response in stream: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ReadTensorboardBlobDataRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ReadTensorboardBlobDataRequest, dict]): The request object. Request message for [TensorboardService.ReadTensorboardBlobData][google.cloud.aiplatform.v1beta1.TensorboardService.ReadTensorboardBlobData]. time_series (:class:`str`): @@ -2060,7 +3077,7 @@ def read_tensorboard_blob_data( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([time_series]) if request is not None and has_flattened_params: @@ -2093,48 +3110,76 @@ def read_tensorboard_blob_data( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response - async def write_tensorboard_run_data( + async def write_tensorboard_experiment_data( self, - request: tensorboard_service.WriteTensorboardRunDataRequest = None, + request: Union[ + tensorboard_service.WriteTensorboardExperimentDataRequest, dict + ] = None, *, - tensorboard_run: str = None, - time_series_data: Sequence[tensorboard_data.TimeSeriesData] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + tensorboard_experiment: str = None, + write_run_data_requests: Sequence[ + tensorboard_service.WriteTensorboardRunDataRequest + ] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> tensorboard_service.WriteTensorboardRunDataResponse: - r"""Write time series data points into multiple - TensorboardTimeSeries under a TensorboardRun. If any - data fail to be ingested, an error will be returned. + ) -> tensorboard_service.WriteTensorboardExperimentDataResponse: + r"""Write time series data points of multiple + TensorboardTimeSeries in multiple TensorboardRun's. If + any data fail to be ingested, an error will be returned. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_write_tensorboard_experiment_data(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + write_run_data_requests = aiplatform_v1beta1.WriteTensorboardRunDataRequest() + write_run_data_requests.tensorboard_run = "tensorboard_run_value" + write_run_data_requests.time_series_data.tensorboard_time_series_id = "tensorboard_time_series_id_value" + write_run_data_requests.time_series_data.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1beta1.WriteTensorboardExperimentDataRequest( + tensorboard_experiment="tensorboard_experiment_value", + write_run_data_requests=write_run_data_requests, + ) + + # Make the request + response = await client.write_tensorboard_experiment_data(request=request) + + # Handle the response + print(response) Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.WriteTensorboardRunDataRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.WriteTensorboardExperimentDataRequest, dict]): The request object. Request message for - [TensorboardService.WriteTensorboardRunData][google.cloud.aiplatform.v1beta1.TensorboardService.WriteTensorboardRunData]. - tensorboard_run (:class:`str`): - Required. The resource name of the TensorboardRun to - write data to. Format: - ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}`` + [TensorboardService.WriteTensorboardExperimentData][google.cloud.aiplatform.v1beta1.TensorboardService.WriteTensorboardExperimentData]. + tensorboard_experiment (:class:`str`): + Required. The resource name of the TensorboardExperiment + to write data to. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` - This corresponds to the ``tensorboard_run`` field + This corresponds to the ``tensorboard_experiment`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - time_series_data (:class:`Sequence[google.cloud.aiplatform_v1beta1.types.TimeSeriesData]`): - Required. The TensorboardTimeSeries - data to write. Values with in a time - series are indexed by their step value. - Repeated writes to the same step will - overwrite the existing value for that - step. - The upper limit of data points per write - request is 5000. + write_run_data_requests (:class:`Sequence[google.cloud.aiplatform_v1beta1.types.WriteTensorboardRunDataRequest]`): + Required. Requests containing per-run + TensorboardTimeSeries data to write. - This corresponds to the ``time_series_data`` field + This corresponds to the ``write_run_data_requests`` 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, @@ -2144,34 +3189,34 @@ async def write_tensorboard_run_data( sent along with the request as metadata. Returns: - google.cloud.aiplatform_v1beta1.types.WriteTensorboardRunDataResponse: + google.cloud.aiplatform_v1beta1.types.WriteTensorboardExperimentDataResponse: Response message for - [TensorboardService.WriteTensorboardRunData][google.cloud.aiplatform.v1beta1.TensorboardService.WriteTensorboardRunData]. + [TensorboardService.WriteTensorboardExperimentData][google.cloud.aiplatform.v1beta1.TensorboardService.WriteTensorboardExperimentData]. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - has_flattened_params = any([tensorboard_run, time_series_data]) + has_flattened_params = any([tensorboard_experiment, write_run_data_requests]) 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 = tensorboard_service.WriteTensorboardRunDataRequest(request) + request = tensorboard_service.WriteTensorboardExperimentDataRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. - if tensorboard_run is not None: - request.tensorboard_run = tensorboard_run - if time_series_data: - request.time_series_data.extend(time_series_data) + if tensorboard_experiment is not None: + request.tensorboard_experiment = tensorboard_experiment + if write_run_data_requests: + request.write_run_data_requests.extend(write_run_data_requests) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( - self._client._transport.write_tensorboard_run_data, + self._client._transport.write_tensorboard_experiment_data, default_timeout=None, client_info=DEFAULT_CLIENT_INFO, ) @@ -2180,31 +3225,179 @@ async def write_tensorboard_run_data( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("tensorboard_run", request.tensorboard_run),) + (("tensorboard_experiment", request.tensorboard_experiment),) ), ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response - async def export_tensorboard_time_series_data( + async def write_tensorboard_run_data( self, - request: tensorboard_service.ExportTensorboardTimeSeriesDataRequest = None, + request: Union[tensorboard_service.WriteTensorboardRunDataRequest, dict] = None, *, - tensorboard_time_series: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + tensorboard_run: str = None, + time_series_data: Sequence[tensorboard_data.TimeSeriesData] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> pagers.ExportTensorboardTimeSeriesDataAsyncPager: - r"""Exports a TensorboardTimeSeries' data. Data is - returned in paginated responses. + ) -> tensorboard_service.WriteTensorboardRunDataResponse: + r"""Write time series data points into multiple + TensorboardTimeSeries under a TensorboardRun. If any + data fail to be ingested, an error will be returned. - Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ExportTensorboardTimeSeriesDataRequest`): - The request object. Request message for + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_write_tensorboard_run_data(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + time_series_data = aiplatform_v1beta1.TimeSeriesData() + time_series_data.tensorboard_time_series_id = "tensorboard_time_series_id_value" + time_series_data.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1beta1.WriteTensorboardRunDataRequest( + tensorboard_run="tensorboard_run_value", + time_series_data=time_series_data, + ) + + # Make the request + response = await client.write_tensorboard_run_data(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.WriteTensorboardRunDataRequest, dict]): + The request object. Request message for + [TensorboardService.WriteTensorboardRunData][google.cloud.aiplatform.v1beta1.TensorboardService.WriteTensorboardRunData]. + tensorboard_run (:class:`str`): + Required. The resource name of the TensorboardRun to + write data to. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}`` + + This corresponds to the ``tensorboard_run`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + time_series_data (:class:`Sequence[google.cloud.aiplatform_v1beta1.types.TimeSeriesData]`): + Required. The TensorboardTimeSeries + data to write. Values with in a time + series are indexed by their step value. + Repeated writes to the same step will + overwrite the existing value for that + step. + The upper limit of data points per write + request is 5000. + + This corresponds to the ``time_series_data`` 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: + google.cloud.aiplatform_v1beta1.types.WriteTensorboardRunDataResponse: + Response message for + [TensorboardService.WriteTensorboardRunData][google.cloud.aiplatform.v1beta1.TensorboardService.WriteTensorboardRunData]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([tensorboard_run, time_series_data]) + 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 = tensorboard_service.WriteTensorboardRunDataRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if tensorboard_run is not None: + request.tensorboard_run = tensorboard_run + if time_series_data: + request.time_series_data.extend(time_series_data) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.write_tensorboard_run_data, + default_timeout=None, + 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( + (("tensorboard_run", request.tensorboard_run),) + ), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def export_tensorboard_time_series_data( + self, + request: Union[ + tensorboard_service.ExportTensorboardTimeSeriesDataRequest, dict + ] = None, + *, + tensorboard_time_series: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ExportTensorboardTimeSeriesDataAsyncPager: + r"""Exports a TensorboardTimeSeries' data. Data is + returned in paginated responses. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_export_tensorboard_time_series_data(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ExportTensorboardTimeSeriesDataRequest( + tensorboard_time_series="tensorboard_time_series_value", + ) + + # Make the request + page_result = client.export_tensorboard_time_series_data(request=request) + + # Handle the response + async for response in page_result: + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.ExportTensorboardTimeSeriesDataRequest, dict]): + The request object. Request message for [TensorboardService.ExportTensorboardTimeSeriesData][google.cloud.aiplatform.v1beta1.TensorboardService.ExportTensorboardTimeSeriesData]. tensorboard_time_series (:class:`str`): Required. The resource name of the TensorboardTimeSeries @@ -2230,7 +3423,7 @@ async def export_tensorboard_time_series_data( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([tensorboard_time_series]) if request is not None and has_flattened_params: @@ -2263,17 +3456,702 @@ async def export_tensorboard_time_series_data( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ExportTensorboardTimeSeriesDataAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_operations, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.delete_operation, + default_timeout=None, + 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 cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + 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 wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.wait_operation, + default_timeout=None, + 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 set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) # Done; return the response. return response + async def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_location, + default_timeout=None, + 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 list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_locations, + default_timeout=None, + 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 __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/aiplatform_v1beta1/services/tensorboard_service/client.py b/google/cloud/aiplatform_v1beta1/services/tensorboard_service/client.py index 4899e0e60c..2270040762 100644 --- a/google/cloud/aiplatform_v1beta1/services/tensorboard_service/client.py +++ b/google/cloud/aiplatform_v1beta1/services/tensorboard_service/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,22 +14,26 @@ # limitations under the License. # from collections import OrderedDict -from distutils import util import os import re -from typing import Callable, Dict, Optional, Iterable, Sequence, Tuple, Type, Union +from typing import Dict, Mapping, Optional, Iterable, 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 as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_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 +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation as gac_operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1beta1.services.tensorboard_service import pagers @@ -49,6 +53,10 @@ from google.cloud.aiplatform_v1beta1.types import ( tensorboard_time_series as gca_tensorboard_time_series, ) +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import empty_pb2 # type: ignore from google.protobuf import field_mask_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore @@ -72,9 +80,10 @@ class TensorboardServiceClientMeta(type): _transport_registry["grpc_asyncio"] = TensorboardServiceGrpcAsyncIOTransport def get_transport_class( - cls, label: str = None, + cls, + label: str = None, ) -> Type[TensorboardServiceTransport]: - """Return an appropriate transport class. + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -97,7 +106,8 @@ class TensorboardServiceClient(metaclass=TensorboardServiceClientMeta): @staticmethod def _get_default_mtls_endpoint(api_endpoint): - """Convert api endpoint to mTLS endpoint. + """Converts api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. Args: @@ -131,7 +141,8 @@ def _get_default_mtls_endpoint(api_endpoint): @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -148,7 +159,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -167,23 +178,32 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> TensorboardServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - TensorboardServiceTransport: The transport used by the client instance. + TensorboardServiceTransport: The transport used by the client + instance. """ return self._transport @staticmethod - def tensorboard_path(project: str, location: str, tensorboard: str,) -> str: - """Return a fully-qualified tensorboard string.""" - return "projects/{project}/locations/{location}/tensorboards/{tensorboard}".format( - project=project, location=location, tensorboard=tensorboard, + def tensorboard_path( + project: str, + location: str, + tensorboard: str, + ) -> str: + """Returns a fully-qualified tensorboard string.""" + return ( + "projects/{project}/locations/{location}/tensorboards/{tensorboard}".format( + project=project, + location=location, + tensorboard=tensorboard, + ) ) @staticmethod def parse_tensorboard_path(path: str) -> Dict[str, str]: - """Parse a tensorboard path into its component segments.""" + """Parses a tensorboard path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/tensorboards/(?P.+?)$", path, @@ -192,9 +212,12 @@ def parse_tensorboard_path(path: str) -> Dict[str, str]: @staticmethod def tensorboard_experiment_path( - project: str, location: str, tensorboard: str, experiment: str, + project: str, + location: str, + tensorboard: str, + experiment: str, ) -> str: - """Return a fully-qualified tensorboard_experiment string.""" + """Returns a fully-qualified tensorboard_experiment string.""" return "projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}".format( project=project, location=location, @@ -204,7 +227,7 @@ def tensorboard_experiment_path( @staticmethod def parse_tensorboard_experiment_path(path: str) -> Dict[str, str]: - """Parse a tensorboard_experiment path into its component segments.""" + """Parses a tensorboard_experiment path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/tensorboards/(?P.+?)/experiments/(?P.+?)$", path, @@ -213,9 +236,13 @@ def parse_tensorboard_experiment_path(path: str) -> Dict[str, str]: @staticmethod def tensorboard_run_path( - project: str, location: str, tensorboard: str, experiment: str, run: str, + project: str, + location: str, + tensorboard: str, + experiment: str, + run: str, ) -> str: - """Return a fully-qualified tensorboard_run string.""" + """Returns a fully-qualified tensorboard_run string.""" return "projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}".format( project=project, location=location, @@ -226,7 +253,7 @@ def tensorboard_run_path( @staticmethod def parse_tensorboard_run_path(path: str) -> Dict[str, str]: - """Parse a tensorboard_run path into its component segments.""" + """Parses a tensorboard_run path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/tensorboards/(?P.+?)/experiments/(?P.+?)/runs/(?P.+?)$", path, @@ -242,7 +269,7 @@ def tensorboard_time_series_path( run: str, time_series: str, ) -> str: - """Return a fully-qualified tensorboard_time_series string.""" + """Returns a fully-qualified tensorboard_time_series string.""" return "projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}/timeSeries/{time_series}".format( project=project, location=location, @@ -254,7 +281,7 @@ def tensorboard_time_series_path( @staticmethod def parse_tensorboard_time_series_path(path: str) -> Dict[str, str]: - """Parse a tensorboard_time_series path into its component segments.""" + """Parses a tensorboard_time_series path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/tensorboards/(?P.+?)/experiments/(?P.+?)/runs/(?P.+?)/timeSeries/(?P.+?)$", path, @@ -262,8 +289,10 @@ def parse_tensorboard_time_series_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + def common_billing_account_path( + billing_account: str, + ) -> str: + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -275,9 +304,13 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: 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,) + def common_folder_path( + folder: str, + ) -> str: + """Returns a fully-qualified folder string.""" + return "folders/{folder}".format( + folder=folder, + ) @staticmethod def parse_common_folder_path(path: str) -> Dict[str, str]: @@ -286,9 +319,13 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: 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,) + def common_organization_path( + organization: str, + ) -> str: + """Returns a fully-qualified organization string.""" + return "organizations/{organization}".format( + organization=organization, + ) @staticmethod def parse_common_organization_path(path: str) -> Dict[str, str]: @@ -297,9 +334,13 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: 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,) + def common_project_path( + project: str, + ) -> str: + """Returns a fully-qualified project string.""" + return "projects/{project}".format( + project=project, + ) @staticmethod def parse_common_project_path(path: str) -> Dict[str, str]: @@ -308,10 +349,14 @@ def parse_common_project_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_location_path(project: str, location: str,) -> str: - """Return a fully-qualified location string.""" + def common_location_path( + project: str, + location: str, + ) -> str: + """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) @staticmethod @@ -320,6 +365,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + def __init__( self, *, @@ -328,7 +440,7 @@ def __init__( client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the tensorboard service client. + """Instantiates the tensorboard service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -370,58 +482,42 @@ def __init__( 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")) + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - client_cert_source_func = ( - mtls.default_client_cert_source() 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" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # 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, TensorboardServiceTransport): # transport is a TensorboardServiceTransport instance. - if credentials or client_options.credentials_file: + if credentials or client_options.credentials_file or api_key_value: 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." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + Transport = type(self).get_transport_class(transport) self._transport = Transport( credentials=credentials, @@ -431,22 +527,50 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, + always_use_jwt_access=True, ) def create_tensorboard( self, - request: tensorboard_service.CreateTensorboardRequest = None, + request: Union[tensorboard_service.CreateTensorboardRequest, dict] = None, *, parent: str = None, tensorboard: gca_tensorboard.Tensorboard = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Creates a Tensorboard. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_create_tensorboard(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + tensorboard = aiplatform_v1beta1.Tensorboard() + tensorboard.display_name = "display_name_value" + + request = aiplatform_v1beta1.CreateTensorboardRequest( + parent="parent_value", + tensorboard=tensorboard, + ) + + # Make the request + operation = client.create_tensorboard(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.CreateTensorboardRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateTensorboardRequest, dict]): The request object. Request message for [TensorboardService.CreateTensorboard][google.cloud.aiplatform.v1beta1.TensorboardService.CreateTensorboard]. parent (str): @@ -479,7 +603,7 @@ def create_tensorboard( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, tensorboard]) if request is not None and has_flattened_params: @@ -512,7 +636,12 @@ def create_tensorboard( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -527,17 +656,36 @@ def create_tensorboard( def get_tensorboard( self, - request: tensorboard_service.GetTensorboardRequest = None, + request: Union[tensorboard_service.GetTensorboardRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> tensorboard.Tensorboard: r"""Gets a Tensorboard. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_get_tensorboard(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetTensorboardRequest( + name="name_value", + ) + + # Make the request + response = client.get_tensorboard(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.GetTensorboardRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.GetTensorboardRequest, dict]): The request object. Request message for [TensorboardService.GetTensorboard][google.cloud.aiplatform.v1beta1.TensorboardService.GetTensorboard]. name (str): @@ -564,7 +712,7 @@ def get_tensorboard( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -595,25 +743,56 @@ def get_tensorboard( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def update_tensorboard( self, - request: tensorboard_service.UpdateTensorboardRequest = None, + request: Union[tensorboard_service.UpdateTensorboardRequest, dict] = None, *, tensorboard: gca_tensorboard.Tensorboard = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Updates a Tensorboard. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_update_tensorboard(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + tensorboard = aiplatform_v1beta1.Tensorboard() + tensorboard.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateTensorboardRequest( + tensorboard=tensorboard, + ) + + # Make the request + operation = client.update_tensorboard(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.UpdateTensorboardRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.UpdateTensorboardRequest, dict]): The request object. Request message for [TensorboardService.UpdateTensorboard][google.cloud.aiplatform.v1beta1.TensorboardService.UpdateTensorboard]. tensorboard (google.cloud.aiplatform_v1beta1.types.Tensorboard): @@ -653,7 +832,7 @@ def update_tensorboard( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([tensorboard, update_mask]) if request is not None and has_flattened_params: @@ -688,7 +867,12 @@ def update_tensorboard( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -703,23 +887,43 @@ def update_tensorboard( def list_tensorboards( self, - request: tensorboard_service.ListTensorboardsRequest = None, + request: Union[tensorboard_service.ListTensorboardsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListTensorboardsPager: r"""Lists Tensorboards in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_list_tensorboards(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListTensorboardsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboards(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ListTensorboardsRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ListTensorboardsRequest, dict]): The request object. Request message for [TensorboardService.ListTensorboards][google.cloud.aiplatform.v1beta1.TensorboardService.ListTensorboards]. parent (str): - Required. The resource name of the - Location to list Tensorboards. Format: - 'projects/{project}/locations/{location}' + Required. The resource name of the Location to list + Tensorboards. Format: + ``projects/{project}/locations/{location}`` This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this @@ -740,7 +944,7 @@ def list_tensorboards( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -771,12 +975,20 @@ def list_tensorboards( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListTensorboardsPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -784,17 +996,40 @@ def list_tensorboards( def delete_tensorboard( self, - request: tensorboard_service.DeleteTensorboardRequest = None, + request: Union[tensorboard_service.DeleteTensorboardRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Deletes a Tensorboard. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_delete_tensorboard(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteTensorboardRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.DeleteTensorboardRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteTensorboardRequest, dict]): The request object. Request message for [TensorboardService.DeleteTensorboard][google.cloud.aiplatform.v1beta1.TensorboardService.DeleteTensorboard]. name (str): @@ -831,7 +1066,7 @@ def delete_tensorboard( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -862,7 +1097,12 @@ def delete_tensorboard( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -877,19 +1117,41 @@ def delete_tensorboard( def create_tensorboard_experiment( self, - request: tensorboard_service.CreateTensorboardExperimentRequest = None, + request: Union[ + tensorboard_service.CreateTensorboardExperimentRequest, dict + ] = None, *, parent: str = None, tensorboard_experiment: gca_tensorboard_experiment.TensorboardExperiment = None, tensorboard_experiment_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_tensorboard_experiment.TensorboardExperiment: r"""Creates a TensorboardExperiment. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_create_tensorboard_experiment(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateTensorboardExperimentRequest( + parent="parent_value", + tensorboard_experiment_id="tensorboard_experiment_id_value", + ) + + # Make the request + response = client.create_tensorboard_experiment(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.CreateTensorboardExperimentRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateTensorboardExperimentRequest, dict]): The request object. Request message for [TensorboardService.CreateTensorboardExperiment][google.cloud.aiplatform.v1beta1.TensorboardService.CreateTensorboardExperiment]. parent (str): @@ -931,7 +1193,7 @@ def create_tensorboard_experiment( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, tensorboard_experiment, tensorboard_experiment_id] @@ -972,24 +1234,50 @@ def create_tensorboard_experiment( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def get_tensorboard_experiment( self, - request: tensorboard_service.GetTensorboardExperimentRequest = None, + request: Union[ + tensorboard_service.GetTensorboardExperimentRequest, dict + ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> tensorboard_experiment.TensorboardExperiment: r"""Gets a TensorboardExperiment. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_get_tensorboard_experiment(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetTensorboardExperimentRequest( + name="name_value", + ) + + # Make the request + response = client.get_tensorboard_experiment(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.GetTensorboardExperimentRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.GetTensorboardExperimentRequest, dict]): The request object. Request message for [TensorboardService.GetTensorboardExperiment][google.cloud.aiplatform.v1beta1.TensorboardService.GetTensorboardExperiment]. name (str): @@ -1015,7 +1303,7 @@ def get_tensorboard_experiment( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1048,25 +1336,50 @@ def get_tensorboard_experiment( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def update_tensorboard_experiment( self, - request: tensorboard_service.UpdateTensorboardExperimentRequest = None, + request: Union[ + tensorboard_service.UpdateTensorboardExperimentRequest, dict + ] = None, *, tensorboard_experiment: gca_tensorboard_experiment.TensorboardExperiment = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_tensorboard_experiment.TensorboardExperiment: r"""Updates a TensorboardExperiment. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_update_tensorboard_experiment(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateTensorboardExperimentRequest( + ) + + # Make the request + response = client.update_tensorboard_experiment(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.UpdateTensorboardExperimentRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.UpdateTensorboardExperimentRequest, dict]): The request object. Request message for [TensorboardService.UpdateTensorboardExperiment][google.cloud.aiplatform.v1beta1.TensorboardService.UpdateTensorboardExperiment]. tensorboard_experiment (google.cloud.aiplatform_v1beta1.types.TensorboardExperiment): @@ -1105,7 +1418,7 @@ def update_tensorboard_experiment( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([tensorboard_experiment, update_mask]) if request is not None and has_flattened_params: @@ -1144,24 +1457,51 @@ def update_tensorboard_experiment( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_tensorboard_experiments( self, - request: tensorboard_service.ListTensorboardExperimentsRequest = None, + request: Union[ + tensorboard_service.ListTensorboardExperimentsRequest, dict + ] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListTensorboardExperimentsPager: r"""Lists TensorboardExperiments in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_list_tensorboard_experiments(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListTensorboardExperimentsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboard_experiments(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ListTensorboardExperimentsRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ListTensorboardExperimentsRequest, dict]): The request object. Request message for [TensorboardService.ListTensorboardExperiments][google.cloud.aiplatform.v1beta1.TensorboardService.ListTensorboardExperiments]. parent (str): @@ -1189,7 +1529,7 @@ def list_tensorboard_experiments( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1224,12 +1564,20 @@ def list_tensorboard_experiments( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListTensorboardExperimentsPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -1237,17 +1585,42 @@ def list_tensorboard_experiments( def delete_tensorboard_experiment( self, - request: tensorboard_service.DeleteTensorboardExperimentRequest = None, + request: Union[ + tensorboard_service.DeleteTensorboardExperimentRequest, dict + ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Deletes a TensorboardExperiment. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_delete_tensorboard_experiment(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteTensorboardExperimentRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard_experiment(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.DeleteTensorboardExperimentRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteTensorboardExperimentRequest, dict]): The request object. Request message for [TensorboardService.DeleteTensorboardExperiment][google.cloud.aiplatform.v1beta1.TensorboardService.DeleteTensorboardExperiment]. name (str): @@ -1284,7 +1657,7 @@ def delete_tensorboard_experiment( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1319,7 +1692,12 @@ def delete_tensorboard_experiment( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -1334,24 +1712,48 @@ def delete_tensorboard_experiment( def create_tensorboard_run( self, - request: tensorboard_service.CreateTensorboardRunRequest = None, + request: Union[tensorboard_service.CreateTensorboardRunRequest, dict] = None, *, parent: str = None, tensorboard_run: gca_tensorboard_run.TensorboardRun = None, tensorboard_run_id: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_tensorboard_run.TensorboardRun: r"""Creates a TensorboardRun. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_create_tensorboard_run(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + tensorboard_run = aiplatform_v1beta1.TensorboardRun() + tensorboard_run.display_name = "display_name_value" + + request = aiplatform_v1beta1.CreateTensorboardRunRequest( + parent="parent_value", + tensorboard_run=tensorboard_run, + tensorboard_run_id="tensorboard_run_id_value", + ) + + # Make the request + response = client.create_tensorboard_run(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.CreateTensorboardRunRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateTensorboardRunRequest, dict]): The request object. Request message for [TensorboardService.CreateTensorboardRun][google.cloud.aiplatform.v1beta1.TensorboardService.CreateTensorboardRun]. parent (str): - Required. The resource name of the Tensorboard to create - the TensorboardRun in. Format: + Required. The resource name of the TensorboardExperiment + to create the TensorboardRun in. Format: ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` This corresponds to the ``parent`` field @@ -1390,7 +1792,7 @@ def create_tensorboard_run( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, tensorboard_run, tensorboard_run_id]) if request is not None and has_flattened_params: @@ -1425,24 +1827,171 @@ def create_tensorboard_run( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def batch_create_tensorboard_runs( + self, + request: Union[ + tensorboard_service.BatchCreateTensorboardRunsRequest, dict + ] = None, + *, + parent: str = None, + requests: Sequence[tensorboard_service.CreateTensorboardRunRequest] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> tensorboard_service.BatchCreateTensorboardRunsResponse: + r"""Batch create TensorboardRuns. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_batch_create_tensorboard_runs(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + requests = aiplatform_v1beta1.CreateTensorboardRunRequest() + requests.parent = "parent_value" + requests.tensorboard_run.display_name = "display_name_value" + requests.tensorboard_run_id = "tensorboard_run_id_value" + + request = aiplatform_v1beta1.BatchCreateTensorboardRunsRequest( + parent="parent_value", + requests=requests, + ) + + # Make the request + response = client.batch_create_tensorboard_runs(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.BatchCreateTensorboardRunsRequest, dict]): + The request object. Request message for + [TensorboardService.BatchCreateTensorboardRuns][google.cloud.aiplatform.v1beta1.TensorboardService.BatchCreateTensorboardRuns]. + parent (str): + Required. The resource name of the TensorboardExperiment + to create the TensorboardRuns in. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` + The parent field in the CreateTensorboardRunRequest + messages must match this field. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + requests (Sequence[google.cloud.aiplatform_v1beta1.types.CreateTensorboardRunRequest]): + Required. The request message + specifying the TensorboardRuns to + create. A maximum of 1000 + TensorboardRuns can be created in a + batch. + + This corresponds to the ``requests`` 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: + google.cloud.aiplatform_v1beta1.types.BatchCreateTensorboardRunsResponse: + Response message for + [TensorboardService.BatchCreateTensorboardRuns][google.cloud.aiplatform.v1beta1.TensorboardService.BatchCreateTensorboardRuns]. + + """ + # Create or coerce a protobuf request object. + # Quick 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, requests]) + 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 tensorboard_service.BatchCreateTensorboardRunsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, tensorboard_service.BatchCreateTensorboardRunsRequest + ): + request = tensorboard_service.BatchCreateTensorboardRunsRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if requests is not None: + request.requests = requests + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.batch_create_tensorboard_runs + ] + + # 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 get_tensorboard_run( self, - request: tensorboard_service.GetTensorboardRunRequest = None, + request: Union[tensorboard_service.GetTensorboardRunRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> tensorboard_run.TensorboardRun: r"""Gets a TensorboardRun. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_get_tensorboard_run(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetTensorboardRunRequest( + name="name_value", + ) + + # Make the request + response = client.get_tensorboard_run(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.GetTensorboardRunRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.GetTensorboardRunRequest, dict]): The request object. Request message for [TensorboardService.GetTensorboardRun][google.cloud.aiplatform.v1beta1.TensorboardService.GetTensorboardRun]. name (str): @@ -1468,7 +2017,7 @@ def get_tensorboard_run( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1499,30 +2048,57 @@ def get_tensorboard_run( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def update_tensorboard_run( self, - request: tensorboard_service.UpdateTensorboardRunRequest = None, + request: Union[tensorboard_service.UpdateTensorboardRunRequest, dict] = None, *, tensorboard_run: gca_tensorboard_run.TensorboardRun = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_tensorboard_run.TensorboardRun: r"""Updates a TensorboardRun. - Args: - request (google.cloud.aiplatform_v1beta1.types.UpdateTensorboardRunRequest): - The request object. Request message for - [TensorboardService.UpdateTensorboardRun][google.cloud.aiplatform.v1beta1.TensorboardService.UpdateTensorboardRun]. - tensorboard_run (google.cloud.aiplatform_v1beta1.types.TensorboardRun): - Required. The TensorboardRun's ``name`` field is used to - identify the TensorboardRun to be updated. Format: + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_update_tensorboard_run(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + tensorboard_run = aiplatform_v1beta1.TensorboardRun() + tensorboard_run.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateTensorboardRunRequest( + tensorboard_run=tensorboard_run, + ) + + # Make the request + response = client.update_tensorboard_run(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.UpdateTensorboardRunRequest, dict]): + The request object. Request message for + [TensorboardService.UpdateTensorboardRun][google.cloud.aiplatform.v1beta1.TensorboardService.UpdateTensorboardRun]. + tensorboard_run (google.cloud.aiplatform_v1beta1.types.TensorboardRun): + Required. The TensorboardRun's ``name`` field is used to + identify the TensorboardRun to be updated. Format: ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}`` This corresponds to the ``tensorboard_run`` field @@ -1555,7 +2131,7 @@ def update_tensorboard_run( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([tensorboard_run, update_mask]) if request is not None and has_flattened_params: @@ -1590,30 +2166,55 @@ def update_tensorboard_run( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_tensorboard_runs( self, - request: tensorboard_service.ListTensorboardRunsRequest = None, + request: Union[tensorboard_service.ListTensorboardRunsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListTensorboardRunsPager: r"""Lists TensorboardRuns in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_list_tensorboard_runs(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListTensorboardRunsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboard_runs(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ListTensorboardRunsRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ListTensorboardRunsRequest, dict]): The request object. Request message for [TensorboardService.ListTensorboardRuns][google.cloud.aiplatform.v1beta1.TensorboardService.ListTensorboardRuns]. parent (str): Required. The resource name of the - Tensorboard to list TensorboardRuns. - Format: + TensorboardExperiment to list + TensorboardRuns. Format: 'projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}' This corresponds to the ``parent`` field @@ -1635,7 +2236,7 @@ def list_tensorboard_runs( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1666,12 +2267,20 @@ def list_tensorboard_runs( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListTensorboardRunsPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -1679,17 +2288,40 @@ def list_tensorboard_runs( def delete_tensorboard_run( self, - request: tensorboard_service.DeleteTensorboardRunRequest = None, + request: Union[tensorboard_service.DeleteTensorboardRunRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Deletes a TensorboardRun. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_delete_tensorboard_run(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteTensorboardRunRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard_run(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.DeleteTensorboardRunRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteTensorboardRunRequest, dict]): The request object. Request message for [TensorboardService.DeleteTensorboardRun][google.cloud.aiplatform.v1beta1.TensorboardService.DeleteTensorboardRun]. name (str): @@ -1726,7 +2358,7 @@ def delete_tensorboard_run( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1757,7 +2389,12 @@ def delete_tensorboard_run( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -1770,20 +2407,175 @@ def delete_tensorboard_run( # Done; return the response. return response + def batch_create_tensorboard_time_series( + self, + request: Union[ + tensorboard_service.BatchCreateTensorboardTimeSeriesRequest, dict + ] = None, + *, + parent: str = None, + requests: Sequence[ + tensorboard_service.CreateTensorboardTimeSeriesRequest + ] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> tensorboard_service.BatchCreateTensorboardTimeSeriesResponse: + r"""Batch create TensorboardTimeSeries that belong to a + TensorboardExperiment. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_batch_create_tensorboard_time_series(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + requests = aiplatform_v1beta1.CreateTensorboardTimeSeriesRequest() + requests.parent = "parent_value" + requests.tensorboard_time_series.display_name = "display_name_value" + requests.tensorboard_time_series.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1beta1.BatchCreateTensorboardTimeSeriesRequest( + parent="parent_value", + requests=requests, + ) + + # Make the request + response = client.batch_create_tensorboard_time_series(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.BatchCreateTensorboardTimeSeriesRequest, dict]): + The request object. Request message for + [TensorboardService.BatchCreateTensorboardTimeSeries][google.cloud.aiplatform.v1beta1.TensorboardService.BatchCreateTensorboardTimeSeries]. + parent (str): + Required. The resource name of the TensorboardExperiment + to create the TensorboardTimeSeries in. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` + The TensorboardRuns referenced by the parent fields in + the CreateTensorboardTimeSeriesRequest messages must be + sub resources of this TensorboardExperiment. + + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + requests (Sequence[google.cloud.aiplatform_v1beta1.types.CreateTensorboardTimeSeriesRequest]): + Required. The request message + specifying the TensorboardTimeSeries to + create. A maximum of 1000 + TensorboardTimeSeries can be created in + a batch. + + This corresponds to the ``requests`` 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: + google.cloud.aiplatform_v1beta1.types.BatchCreateTensorboardTimeSeriesResponse: + Response message for + [TensorboardService.BatchCreateTensorboardTimeSeries][google.cloud.aiplatform.v1beta1.TensorboardService.BatchCreateTensorboardTimeSeries]. + + """ + # Create or coerce a protobuf request object. + # Quick 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, requests]) + 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 tensorboard_service.BatchCreateTensorboardTimeSeriesRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, tensorboard_service.BatchCreateTensorboardTimeSeriesRequest + ): + request = tensorboard_service.BatchCreateTensorboardTimeSeriesRequest( + request + ) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if parent is not None: + request.parent = parent + if requests is not None: + request.requests = requests + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.batch_create_tensorboard_time_series + ] + + # 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_tensorboard_time_series( self, - request: tensorboard_service.CreateTensorboardTimeSeriesRequest = None, + request: Union[ + tensorboard_service.CreateTensorboardTimeSeriesRequest, dict + ] = None, *, parent: str = None, tensorboard_time_series: gca_tensorboard_time_series.TensorboardTimeSeries = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_tensorboard_time_series.TensorboardTimeSeries: r"""Creates a TensorboardTimeSeries. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_create_tensorboard_time_series(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + tensorboard_time_series = aiplatform_v1beta1.TensorboardTimeSeries() + tensorboard_time_series.display_name = "display_name_value" + tensorboard_time_series.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1beta1.CreateTensorboardTimeSeriesRequest( + parent="parent_value", + tensorboard_time_series=tensorboard_time_series, + ) + + # Make the request + response = client.create_tensorboard_time_series(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.CreateTensorboardTimeSeriesRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateTensorboardTimeSeriesRequest, dict]): The request object. Request message for [TensorboardService.CreateTensorboardTimeSeries][google.cloud.aiplatform.v1beta1.TensorboardService.CreateTensorboardTimeSeries]. parent (str): @@ -1814,7 +2606,7 @@ def create_tensorboard_time_series( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, tensorboard_time_series]) if request is not None and has_flattened_params: @@ -1851,24 +2643,50 @@ def create_tensorboard_time_series( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def get_tensorboard_time_series( self, - request: tensorboard_service.GetTensorboardTimeSeriesRequest = None, + request: Union[ + tensorboard_service.GetTensorboardTimeSeriesRequest, dict + ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> tensorboard_time_series.TensorboardTimeSeries: r"""Gets a TensorboardTimeSeries. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_get_tensorboard_time_series(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetTensorboardTimeSeriesRequest( + name="name_value", + ) + + # Make the request + response = client.get_tensorboard_time_series(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.GetTensorboardTimeSeriesRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.GetTensorboardTimeSeriesRequest, dict]): The request object. Request message for [TensorboardService.GetTensorboardTimeSeries][google.cloud.aiplatform.v1beta1.TensorboardService.GetTensorboardTimeSeries]. name (str): @@ -1892,7 +2710,7 @@ def get_tensorboard_time_series( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1925,25 +2743,55 @@ def get_tensorboard_time_series( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def update_tensorboard_time_series( self, - request: tensorboard_service.UpdateTensorboardTimeSeriesRequest = None, + request: Union[ + tensorboard_service.UpdateTensorboardTimeSeriesRequest, dict + ] = None, *, tensorboard_time_series: gca_tensorboard_time_series.TensorboardTimeSeries = None, update_mask: field_mask_pb2.FieldMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_tensorboard_time_series.TensorboardTimeSeries: r"""Updates a TensorboardTimeSeries. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_update_tensorboard_time_series(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + tensorboard_time_series = aiplatform_v1beta1.TensorboardTimeSeries() + tensorboard_time_series.display_name = "display_name_value" + tensorboard_time_series.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1beta1.UpdateTensorboardTimeSeriesRequest( + tensorboard_time_series=tensorboard_time_series, + ) + + # Make the request + response = client.update_tensorboard_time_series(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.UpdateTensorboardTimeSeriesRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.UpdateTensorboardTimeSeriesRequest, dict]): The request object. Request message for [TensorboardService.UpdateTensorboardTimeSeries][google.cloud.aiplatform.v1beta1.TensorboardService.UpdateTensorboardTimeSeries]. tensorboard_time_series (google.cloud.aiplatform_v1beta1.types.TensorboardTimeSeries): @@ -1980,7 +2828,7 @@ def update_tensorboard_time_series( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([tensorboard_time_series, update_mask]) if request is not None and has_flattened_params: @@ -2024,24 +2872,51 @@ def update_tensorboard_time_series( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_tensorboard_time_series( self, - request: tensorboard_service.ListTensorboardTimeSeriesRequest = None, + request: Union[ + tensorboard_service.ListTensorboardTimeSeriesRequest, dict + ] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListTensorboardTimeSeriesPager: r"""Lists TensorboardTimeSeries in a Location. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_list_tensorboard_time_series(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListTensorboardTimeSeriesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboard_time_series(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ListTensorboardTimeSeriesRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ListTensorboardTimeSeriesRequest, dict]): The request object. Request message for [TensorboardService.ListTensorboardTimeSeries][google.cloud.aiplatform.v1beta1.TensorboardService.ListTensorboardTimeSeries]. parent (str): @@ -2069,7 +2944,7 @@ def list_tensorboard_time_series( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -2104,12 +2979,20 @@ def list_tensorboard_time_series( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListTensorboardTimeSeriesPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -2117,17 +3000,42 @@ def list_tensorboard_time_series( def delete_tensorboard_time_series( self, - request: tensorboard_service.DeleteTensorboardTimeSeriesRequest = None, + request: Union[ + tensorboard_service.DeleteTensorboardTimeSeriesRequest, dict + ] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: r"""Deletes a TensorboardTimeSeries. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_delete_tensorboard_time_series(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteTensorboardTimeSeriesRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard_time_series(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.DeleteTensorboardTimeSeriesRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteTensorboardTimeSeriesRequest, dict]): The request object. Request message for [TensorboardService.DeleteTensorboardTimeSeries][google.cloud.aiplatform.v1beta1.TensorboardService.DeleteTensorboardTimeSeries]. name (str): @@ -2164,7 +3072,7 @@ def delete_tensorboard_time_series( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -2199,7 +3107,12 @@ def delete_tensorboard_time_series( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = gac_operation.from_gapic( @@ -2212,24 +3125,160 @@ def delete_tensorboard_time_series( # Done; return the response. return response + def batch_read_tensorboard_time_series_data( + self, + request: Union[ + tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest, dict + ] = None, + *, + tensorboard: str = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> tensorboard_service.BatchReadTensorboardTimeSeriesDataResponse: + r"""Reads multiple TensorboardTimeSeries' data. The data + point number limit is 1000 for scalars, 100 for tensors + and blob references. If the number of data points stored + is less than the limit, all data will be returned. + Otherwise, that limit number of data points will be + randomly selected from this time series and returned. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_batch_read_tensorboard_time_series_data(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.BatchReadTensorboardTimeSeriesDataRequest( + tensorboard="tensorboard_value", + time_series=['time_series_value_1', 'time_series_value_2'], + ) + + # Make the request + response = client.batch_read_tensorboard_time_series_data(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.BatchReadTensorboardTimeSeriesDataRequest, dict]): + The request object. Request message for + [TensorboardService.BatchReadTensorboardTimeSeriesData][google.cloud.aiplatform.v1beta1.TensorboardService.BatchReadTensorboardTimeSeriesData]. + tensorboard (str): + Required. The resource name of the Tensorboard + containing TensorboardTimeSeries to read data from. + Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}``. + The TensorboardTimeSeries referenced by + [time_series][google.cloud.aiplatform.v1beta1.BatchReadTensorboardTimeSeriesDataRequest.time_series] + must be sub resources of this Tensorboard. + + This corresponds to the ``tensorboard`` 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: + google.cloud.aiplatform_v1beta1.types.BatchReadTensorboardTimeSeriesDataResponse: + Response message for + [TensorboardService.BatchReadTensorboardTimeSeriesData][google.cloud.aiplatform.v1beta1.TensorboardService.BatchReadTensorboardTimeSeriesData]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([tensorboard]) + 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 tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest + ): + request = tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest( + request + ) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if tensorboard is not None: + request.tensorboard = tensorboard + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.batch_read_tensorboard_time_series_data + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("tensorboard", request.tensorboard),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + def read_tensorboard_time_series_data( self, - request: tensorboard_service.ReadTensorboardTimeSeriesDataRequest = None, + request: Union[ + tensorboard_service.ReadTensorboardTimeSeriesDataRequest, dict + ] = None, *, tensorboard_time_series: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> tensorboard_service.ReadTensorboardTimeSeriesDataResponse: - r"""Reads a TensorboardTimeSeries' data. Data is returned in - paginated responses. By default, if the number of data points - stored is less than 1000, all data will be returned. Otherwise, - 1000 data points will be randomly selected from this time series - and returned. This value can be changed by changing - max_data_points. + r"""Reads a TensorboardTimeSeries' data. By default, if the number + of data points stored is less than 1000, all data will be + returned. Otherwise, 1000 data points will be randomly selected + from this time series and returned. This value can be changed by + changing max_data_points, which can't be greater than 10k. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_read_tensorboard_time_series_data(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ReadTensorboardTimeSeriesDataRequest( + tensorboard_time_series="tensorboard_time_series_value", + ) + + # Make the request + response = client.read_tensorboard_time_series_data(request=request) + + # Handle the response + print(response) Args: - request (google.cloud.aiplatform_v1beta1.types.ReadTensorboardTimeSeriesDataRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ReadTensorboardTimeSeriesDataRequest, dict]): The request object. Request message for [TensorboardService.ReadTensorboardTimeSeriesData][google.cloud.aiplatform.v1beta1.TensorboardService.ReadTensorboardTimeSeriesData]. tensorboard_time_series (str): @@ -2253,7 +3302,7 @@ def read_tensorboard_time_series_data( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([tensorboard_time_series]) if request is not None and has_flattened_params: @@ -2290,17 +3339,22 @@ def read_tensorboard_time_series_data( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def read_tensorboard_blob_data( self, - request: tensorboard_service.ReadTensorboardBlobDataRequest = None, + request: Union[tensorboard_service.ReadTensorboardBlobDataRequest, dict] = None, *, time_series: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> Iterable[tensorboard_service.ReadTensorboardBlobDataResponse]: @@ -2309,8 +3363,28 @@ def read_tensorboard_blob_data( project's Cloud Storage bucket without users having to obtain Cloud Storage access permission. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_read_tensorboard_blob_data(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ReadTensorboardBlobDataRequest( + time_series="time_series_value", + ) + + # Make the request + stream = client.read_tensorboard_blob_data(request=request) + + # Handle the response + for response in stream: + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ReadTensorboardBlobDataRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ReadTensorboardBlobDataRequest, dict]): The request object. Request message for [TensorboardService.ReadTensorboardBlobData][google.cloud.aiplatform.v1beta1.TensorboardService.ReadTensorboardBlobData]. time_series (str): @@ -2334,7 +3408,7 @@ def read_tensorboard_blob_data( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([time_series]) if request is not None and has_flattened_params: @@ -2369,42 +3443,195 @@ def read_tensorboard_blob_data( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response - def write_tensorboard_run_data( + def write_tensorboard_experiment_data( self, - request: tensorboard_service.WriteTensorboardRunDataRequest = None, + request: Union[ + tensorboard_service.WriteTensorboardExperimentDataRequest, dict + ] = None, *, - tensorboard_run: str = None, - time_series_data: Sequence[tensorboard_data.TimeSeriesData] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + tensorboard_experiment: str = None, + write_run_data_requests: Sequence[ + tensorboard_service.WriteTensorboardRunDataRequest + ] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> tensorboard_service.WriteTensorboardRunDataResponse: - r"""Write time series data points into multiple - TensorboardTimeSeries under a TensorboardRun. If any - data fail to be ingested, an error will be returned. + ) -> tensorboard_service.WriteTensorboardExperimentDataResponse: + r"""Write time series data points of multiple + TensorboardTimeSeries in multiple TensorboardRun's. If + any data fail to be ingested, an error will be returned. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_write_tensorboard_experiment_data(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + write_run_data_requests = aiplatform_v1beta1.WriteTensorboardRunDataRequest() + write_run_data_requests.tensorboard_run = "tensorboard_run_value" + write_run_data_requests.time_series_data.tensorboard_time_series_id = "tensorboard_time_series_id_value" + write_run_data_requests.time_series_data.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1beta1.WriteTensorboardExperimentDataRequest( + tensorboard_experiment="tensorboard_experiment_value", + write_run_data_requests=write_run_data_requests, + ) + + # Make the request + response = client.write_tensorboard_experiment_data(request=request) + + # Handle the response + print(response) Args: - request (google.cloud.aiplatform_v1beta1.types.WriteTensorboardRunDataRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.WriteTensorboardExperimentDataRequest, dict]): The request object. Request message for - [TensorboardService.WriteTensorboardRunData][google.cloud.aiplatform.v1beta1.TensorboardService.WriteTensorboardRunData]. - tensorboard_run (str): - Required. The resource name of the TensorboardRun to - write data to. Format: - ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}`` + [TensorboardService.WriteTensorboardExperimentData][google.cloud.aiplatform.v1beta1.TensorboardService.WriteTensorboardExperimentData]. + tensorboard_experiment (str): + Required. The resource name of the TensorboardExperiment + to write data to. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` - This corresponds to the ``tensorboard_run`` field + This corresponds to the ``tensorboard_experiment`` field on the ``request`` instance; if ``request`` is provided, this should not be set. - time_series_data (Sequence[google.cloud.aiplatform_v1beta1.types.TimeSeriesData]): - Required. The TensorboardTimeSeries - data to write. Values with in a time - series are indexed by their step value. - Repeated writes to the same step will + write_run_data_requests (Sequence[google.cloud.aiplatform_v1beta1.types.WriteTensorboardRunDataRequest]): + Required. Requests containing per-run + TensorboardTimeSeries data to write. + + This corresponds to the ``write_run_data_requests`` 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: + google.cloud.aiplatform_v1beta1.types.WriteTensorboardExperimentDataResponse: + Response message for + [TensorboardService.WriteTensorboardExperimentData][google.cloud.aiplatform.v1beta1.TensorboardService.WriteTensorboardExperimentData]. + + """ + # Create or coerce a protobuf request object. + # Quick check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([tensorboard_experiment, write_run_data_requests]) + 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 tensorboard_service.WriteTensorboardExperimentDataRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance( + request, tensorboard_service.WriteTensorboardExperimentDataRequest + ): + request = tensorboard_service.WriteTensorboardExperimentDataRequest(request) + # If we have keyword arguments corresponding to fields on the + # request, apply these. + if tensorboard_experiment is not None: + request.tensorboard_experiment = tensorboard_experiment + if write_run_data_requests is not None: + request.write_run_data_requests = write_run_data_requests + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.write_tensorboard_experiment_data + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("tensorboard_experiment", request.tensorboard_experiment),) + ), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def write_tensorboard_run_data( + self, + request: Union[tensorboard_service.WriteTensorboardRunDataRequest, dict] = None, + *, + tensorboard_run: str = None, + time_series_data: Sequence[tensorboard_data.TimeSeriesData] = None, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> tensorboard_service.WriteTensorboardRunDataResponse: + r"""Write time series data points into multiple + TensorboardTimeSeries under a TensorboardRun. If any + data fail to be ingested, an error will be returned. + + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_write_tensorboard_run_data(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + time_series_data = aiplatform_v1beta1.TimeSeriesData() + time_series_data.tensorboard_time_series_id = "tensorboard_time_series_id_value" + time_series_data.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1beta1.WriteTensorboardRunDataRequest( + tensorboard_run="tensorboard_run_value", + time_series_data=time_series_data, + ) + + # Make the request + response = client.write_tensorboard_run_data(request=request) + + # Handle the response + print(response) + + Args: + request (Union[google.cloud.aiplatform_v1beta1.types.WriteTensorboardRunDataRequest, dict]): + The request object. Request message for + [TensorboardService.WriteTensorboardRunData][google.cloud.aiplatform.v1beta1.TensorboardService.WriteTensorboardRunData]. + tensorboard_run (str): + Required. The resource name of the TensorboardRun to + write data to. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}`` + + This corresponds to the ``tensorboard_run`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + time_series_data (Sequence[google.cloud.aiplatform_v1beta1.types.TimeSeriesData]): + Required. The TensorboardTimeSeries + data to write. Values with in a time + series are indexed by their step value. + Repeated writes to the same step will overwrite the existing value for that step. The upper limit of data points per write @@ -2426,7 +3653,7 @@ def write_tensorboard_run_data( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([tensorboard_run, time_series_data]) if request is not None and has_flattened_params: @@ -2463,25 +3690,52 @@ def write_tensorboard_run_data( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def export_tensorboard_time_series_data( self, - request: tensorboard_service.ExportTensorboardTimeSeriesDataRequest = None, + request: Union[ + tensorboard_service.ExportTensorboardTimeSeriesDataRequest, dict + ] = None, *, tensorboard_time_series: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ExportTensorboardTimeSeriesDataPager: r"""Exports a TensorboardTimeSeries' data. Data is returned in paginated responses. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_export_tensorboard_time_series_data(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ExportTensorboardTimeSeriesDataRequest( + tensorboard_time_series="tensorboard_time_series_value", + ) + + # Make the request + page_result = client.export_tensorboard_time_series_data(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ExportTensorboardTimeSeriesDataRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ExportTensorboardTimeSeriesDataRequest, dict]): The request object. Request message for [TensorboardService.ExportTensorboardTimeSeriesData][google.cloud.aiplatform.v1beta1.TensorboardService.ExportTensorboardTimeSeriesData]. tensorboard_time_series (str): @@ -2508,7 +3762,7 @@ def export_tensorboard_time_series_data( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([tensorboard_time_series]) if request is not None and has_flattened_params: @@ -2547,12 +3801,704 @@ def export_tensorboard_time_series_data( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ExportTensorboardTimeSeriesDataPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, + ) + + # Done; return the response. + return response + + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_operations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.delete_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.wait_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_location, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_locations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) # Done; return the response. diff --git a/google/cloud/aiplatform_v1beta1/services/tensorboard_service/pagers.py b/google/cloud/aiplatform_v1beta1/services/tensorboard_service/pagers.py index 8200c9c237..3cae76e446 100644 --- a/google/cloud/aiplatform_v1beta1/services/tensorboard_service/pagers.py +++ b/google/cloud/aiplatform_v1beta1/services/tensorboard_service/pagers.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,13 +15,13 @@ # from typing import ( Any, - AsyncIterable, + AsyncIterator, Awaitable, Callable, - Iterable, Sequence, Tuple, Optional, + Iterator, ) from google.cloud.aiplatform_v1beta1.types import tensorboard @@ -79,14 +79,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[tensorboard_service.ListTensorboardsResponse]: + def pages(self) -> Iterator[tensorboard_service.ListTensorboardsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[tensorboard.Tensorboard]: + def __iter__(self) -> Iterator[tensorboard.Tensorboard]: for page in self.pages: yield from page.tensorboards @@ -120,7 +120,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -143,14 +143,14 @@ def __getattr__(self, name: str) -> Any: @property async def pages( self, - ) -> AsyncIterable[tensorboard_service.ListTensorboardsResponse]: + ) -> AsyncIterator[tensorboard_service.ListTensorboardsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[tensorboard.Tensorboard]: + def __aiter__(self) -> AsyncIterator[tensorboard.Tensorboard]: async def async_generator(): async for page in self.pages: for response in page.tensorboards: @@ -209,14 +209,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[tensorboard_service.ListTensorboardExperimentsResponse]: + def pages(self) -> Iterator[tensorboard_service.ListTensorboardExperimentsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[tensorboard_experiment.TensorboardExperiment]: + def __iter__(self) -> Iterator[tensorboard_experiment.TensorboardExperiment]: for page in self.pages: yield from page.tensorboard_experiments @@ -252,7 +252,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -275,14 +275,14 @@ def __getattr__(self, name: str) -> Any: @property async def pages( self, - ) -> AsyncIterable[tensorboard_service.ListTensorboardExperimentsResponse]: + ) -> AsyncIterator[tensorboard_service.ListTensorboardExperimentsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[tensorboard_experiment.TensorboardExperiment]: + def __aiter__(self) -> AsyncIterator[tensorboard_experiment.TensorboardExperiment]: async def async_generator(): async for page in self.pages: for response in page.tensorboard_experiments: @@ -341,14 +341,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[tensorboard_service.ListTensorboardRunsResponse]: + def pages(self) -> Iterator[tensorboard_service.ListTensorboardRunsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[tensorboard_run.TensorboardRun]: + def __iter__(self) -> Iterator[tensorboard_run.TensorboardRun]: for page in self.pages: yield from page.tensorboard_runs @@ -384,7 +384,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -407,14 +407,14 @@ def __getattr__(self, name: str) -> Any: @property async def pages( self, - ) -> AsyncIterable[tensorboard_service.ListTensorboardRunsResponse]: + ) -> AsyncIterator[tensorboard_service.ListTensorboardRunsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[tensorboard_run.TensorboardRun]: + def __aiter__(self) -> AsyncIterator[tensorboard_run.TensorboardRun]: async def async_generator(): async for page in self.pages: for response in page.tensorboard_runs: @@ -473,14 +473,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[tensorboard_service.ListTensorboardTimeSeriesResponse]: + def pages(self) -> Iterator[tensorboard_service.ListTensorboardTimeSeriesResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[tensorboard_time_series.TensorboardTimeSeries]: + def __iter__(self) -> Iterator[tensorboard_time_series.TensorboardTimeSeries]: for page in self.pages: yield from page.tensorboard_time_series @@ -516,7 +516,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -539,14 +539,14 @@ def __getattr__(self, name: str) -> Any: @property async def pages( self, - ) -> AsyncIterable[tensorboard_service.ListTensorboardTimeSeriesResponse]: + ) -> AsyncIterator[tensorboard_service.ListTensorboardTimeSeriesResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[tensorboard_time_series.TensorboardTimeSeries]: + def __aiter__(self) -> AsyncIterator[tensorboard_time_series.TensorboardTimeSeries]: async def async_generator(): async for page in self.pages: for response in page.tensorboard_time_series: @@ -611,14 +611,14 @@ def __getattr__(self, name: str) -> Any: @property def pages( self, - ) -> Iterable[tensorboard_service.ExportTensorboardTimeSeriesDataResponse]: + ) -> Iterator[tensorboard_service.ExportTensorboardTimeSeriesDataResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[tensorboard_data.TimeSeriesDataPoint]: + def __iter__(self) -> Iterator[tensorboard_data.TimeSeriesDataPoint]: for page in self.pages: yield from page.time_series_data_points @@ -654,7 +654,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -679,14 +679,14 @@ def __getattr__(self, name: str) -> Any: @property async def pages( self, - ) -> AsyncIterable[tensorboard_service.ExportTensorboardTimeSeriesDataResponse]: + ) -> AsyncIterator[tensorboard_service.ExportTensorboardTimeSeriesDataResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[tensorboard_data.TimeSeriesDataPoint]: + def __aiter__(self) -> AsyncIterator[tensorboard_data.TimeSeriesDataPoint]: async def async_generator(): async for page in self.pages: for response in page.time_series_data_points: diff --git a/google/cloud/aiplatform_v1beta1/services/tensorboard_service/transports/__init__.py b/google/cloud/aiplatform_v1beta1/services/tensorboard_service/transports/__init__.py index 50612ea154..645295a44f 100644 --- a/google/cloud/aiplatform_v1beta1/services/tensorboard_service/transports/__init__.py +++ b/google/cloud/aiplatform_v1beta1/services/tensorboard_service/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1beta1/services/tensorboard_service/transports/base.py b/google/cloud/aiplatform_v1beta1/services/tensorboard_service/transports/base.py index 71b612167c..9ee8096966 100644 --- a/google/cloud/aiplatform_v1beta1/services/tensorboard_service/transports/base.py +++ b/google/cloud/aiplatform_v1beta1/services/tensorboard_service/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,16 +15,16 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.api_core import operations_v1 # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.aiplatform_v1beta1.types import tensorboard from google.cloud.aiplatform_v1beta1.types import tensorboard_experiment @@ -38,6 +38,10 @@ from google.cloud.aiplatform_v1beta1.types import ( tensorboard_time_series as gca_tensorboard_time_series, ) +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore try: @@ -49,17 +53,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - -_API_CORE_VERSION = google.api_core.__version__ - class TensorboardServiceTransport(abc.ABC): """Abstract transport class for TensorboardService.""" @@ -77,6 +70,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -100,16 +94,19 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -122,77 +119,49 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id ) - # Save the credentials. - self._credentials = credentials - - # TODO(busunkim): These two class methods are in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-api-core - # and google-auth are increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") + # If the credentials are service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs - - # TODO: Remove this function once google-api-core >= 1.26.0 is required - @classmethod - def _get_self_signed_jwt_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Union[Optional[Sequence[str]], str]]: - """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" + credentials = credentials.with_always_use_jwt_access(True) - self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} - - if _API_CORE_VERSION and ( - packaging.version.parse(_API_CORE_VERSION) - >= packaging.version.parse("1.26.0") - ): - self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES - self_signed_jwt_kwargs["scopes"] = scopes - self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST - else: - self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES - - return self_signed_jwt_kwargs + # Save the credentials. + self._credentials = credentials def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { self.create_tensorboard: gapic_v1.method.wrap_method( - self.create_tensorboard, default_timeout=None, client_info=client_info, + self.create_tensorboard, + default_timeout=None, + client_info=client_info, ), self.get_tensorboard: gapic_v1.method.wrap_method( - self.get_tensorboard, default_timeout=None, client_info=client_info, + self.get_tensorboard, + default_timeout=None, + client_info=client_info, ), self.update_tensorboard: gapic_v1.method.wrap_method( - self.update_tensorboard, default_timeout=None, client_info=client_info, + self.update_tensorboard, + default_timeout=None, + client_info=client_info, ), self.list_tensorboards: gapic_v1.method.wrap_method( - self.list_tensorboards, default_timeout=None, client_info=client_info, + self.list_tensorboards, + default_timeout=None, + client_info=client_info, ), self.delete_tensorboard: gapic_v1.method.wrap_method( - self.delete_tensorboard, default_timeout=None, client_info=client_info, + self.delete_tensorboard, + default_timeout=None, + client_info=client_info, ), self.create_tensorboard_experiment: gapic_v1.method.wrap_method( self.create_tensorboard_experiment, @@ -224,8 +193,15 @@ def _prep_wrapped_messages(self, client_info): default_timeout=None, client_info=client_info, ), + self.batch_create_tensorboard_runs: gapic_v1.method.wrap_method( + self.batch_create_tensorboard_runs, + default_timeout=None, + client_info=client_info, + ), self.get_tensorboard_run: gapic_v1.method.wrap_method( - self.get_tensorboard_run, default_timeout=None, client_info=client_info, + self.get_tensorboard_run, + default_timeout=None, + client_info=client_info, ), self.update_tensorboard_run: gapic_v1.method.wrap_method( self.update_tensorboard_run, @@ -242,6 +218,11 @@ def _prep_wrapped_messages(self, client_info): default_timeout=None, client_info=client_info, ), + self.batch_create_tensorboard_time_series: gapic_v1.method.wrap_method( + self.batch_create_tensorboard_time_series, + default_timeout=None, + client_info=client_info, + ), self.create_tensorboard_time_series: gapic_v1.method.wrap_method( self.create_tensorboard_time_series, default_timeout=None, @@ -267,6 +248,11 @@ def _prep_wrapped_messages(self, client_info): default_timeout=None, client_info=client_info, ), + self.batch_read_tensorboard_time_series_data: gapic_v1.method.wrap_method( + self.batch_read_tensorboard_time_series_data, + default_timeout=None, + client_info=client_info, + ), self.read_tensorboard_time_series_data: gapic_v1.method.wrap_method( self.read_tensorboard_time_series_data, default_timeout=None, @@ -277,6 +263,11 @@ def _prep_wrapped_messages(self, client_info): default_timeout=None, client_info=client_info, ), + self.write_tensorboard_experiment_data: gapic_v1.method.wrap_method( + self.write_tensorboard_experiment_data, + default_timeout=None, + client_info=client_info, + ), self.write_tensorboard_run_data: gapic_v1.method.wrap_method( self.write_tensorboard_run_data, default_timeout=None, @@ -289,8 +280,17 @@ def _prep_wrapped_messages(self, client_info): ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() @@ -411,6 +411,18 @@ def create_tensorboard_run( ]: raise NotImplementedError() + @property + def batch_create_tensorboard_runs( + self, + ) -> Callable[ + [tensorboard_service.BatchCreateTensorboardRunsRequest], + Union[ + tensorboard_service.BatchCreateTensorboardRunsResponse, + Awaitable[tensorboard_service.BatchCreateTensorboardRunsResponse], + ], + ]: + raise NotImplementedError() + @property def get_tensorboard_run( self, @@ -455,6 +467,18 @@ def delete_tensorboard_run( ]: raise NotImplementedError() + @property + def batch_create_tensorboard_time_series( + self, + ) -> Callable[ + [tensorboard_service.BatchCreateTensorboardTimeSeriesRequest], + Union[ + tensorboard_service.BatchCreateTensorboardTimeSeriesResponse, + Awaitable[tensorboard_service.BatchCreateTensorboardTimeSeriesResponse], + ], + ]: + raise NotImplementedError() + @property def create_tensorboard_time_series( self, @@ -512,6 +536,18 @@ def delete_tensorboard_time_series( ]: raise NotImplementedError() + @property + def batch_read_tensorboard_time_series_data( + self, + ) -> Callable[ + [tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest], + Union[ + tensorboard_service.BatchReadTensorboardTimeSeriesDataResponse, + Awaitable[tensorboard_service.BatchReadTensorboardTimeSeriesDataResponse], + ], + ]: + raise NotImplementedError() + @property def read_tensorboard_time_series_data( self, @@ -536,6 +572,18 @@ def read_tensorboard_blob_data( ]: raise NotImplementedError() + @property + def write_tensorboard_experiment_data( + self, + ) -> Callable[ + [tensorboard_service.WriteTensorboardExperimentDataRequest], + Union[ + tensorboard_service.WriteTensorboardExperimentDataResponse, + Awaitable[tensorboard_service.WriteTensorboardExperimentDataResponse], + ], + ]: + raise NotImplementedError() + @property def write_tensorboard_run_data( self, @@ -560,5 +608,102 @@ def export_tensorboard_time_series_data( ]: raise NotImplementedError() + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], + Union[ + operations_pb2.ListOperationsResponse, + Awaitable[operations_pb2.ListOperationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None,]: + raise NotImplementedError() + + @property + def wait_operation( + self, + ) -> Callable[ + [operations_pb2.WaitOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def set_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def get_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_location( + self, + ) -> Callable[ + [locations_pb2.GetLocationRequest], + Union[locations_pb2.Location, Awaitable[locations_pb2.Location]], + ]: + raise NotImplementedError() + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], + Union[ + locations_pb2.ListLocationsResponse, + Awaitable[locations_pb2.ListLocationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + __all__ = ("TensorboardServiceTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/tensorboard_service/transports/grpc.py b/google/cloud/aiplatform_v1beta1/services/tensorboard_service/transports/grpc.py index c2490cf083..8c39ec49f5 100644 --- a/google/cloud/aiplatform_v1beta1/services/tensorboard_service/transports/grpc.py +++ b/google/cloud/aiplatform_v1beta1/services/tensorboard_service/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,9 +16,9 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import operations_v1 +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -37,6 +37,10 @@ from google.cloud.aiplatform_v1beta1.types import ( tensorboard_time_series as gca_tensorboard_time_series, ) +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from .base import TensorboardServiceTransport, DEFAULT_CLIENT_INFO @@ -70,6 +74,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -92,16 +97,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -110,6 +115,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport @@ -120,7 +127,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -163,13 +170,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -218,21 +229,20 @@ def create_channel( and ``credentials_file`` are passed. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @property def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ + """Return the channel designed to connect to this service.""" return self._grpc_channel @property @@ -242,7 +252,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsClient(self.grpc_channel) @@ -568,6 +578,37 @@ def create_tensorboard_run( ) return self._stubs["create_tensorboard_run"] + @property + def batch_create_tensorboard_runs( + self, + ) -> Callable[ + [tensorboard_service.BatchCreateTensorboardRunsRequest], + tensorboard_service.BatchCreateTensorboardRunsResponse, + ]: + r"""Return a callable for the batch create tensorboard runs method over gRPC. + + Batch create TensorboardRuns. + + Returns: + Callable[[~.BatchCreateTensorboardRunsRequest], + ~.BatchCreateTensorboardRunsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "batch_create_tensorboard_runs" not in self._stubs: + self._stubs[ + "batch_create_tensorboard_runs" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1beta1.TensorboardService/BatchCreateTensorboardRuns", + request_serializer=tensorboard_service.BatchCreateTensorboardRunsRequest.serialize, + response_deserializer=tensorboard_service.BatchCreateTensorboardRunsResponse.deserialize, + ) + return self._stubs["batch_create_tensorboard_runs"] + @property def get_tensorboard_run( self, @@ -682,6 +723,39 @@ def delete_tensorboard_run( ) return self._stubs["delete_tensorboard_run"] + @property + def batch_create_tensorboard_time_series( + self, + ) -> Callable[ + [tensorboard_service.BatchCreateTensorboardTimeSeriesRequest], + tensorboard_service.BatchCreateTensorboardTimeSeriesResponse, + ]: + r"""Return a callable for the batch create tensorboard time + series method over gRPC. + + Batch create TensorboardTimeSeries that belong to a + TensorboardExperiment. + + Returns: + Callable[[~.BatchCreateTensorboardTimeSeriesRequest], + ~.BatchCreateTensorboardTimeSeriesResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "batch_create_tensorboard_time_series" not in self._stubs: + self._stubs[ + "batch_create_tensorboard_time_series" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1beta1.TensorboardService/BatchCreateTensorboardTimeSeries", + request_serializer=tensorboard_service.BatchCreateTensorboardTimeSeriesRequest.serialize, + response_deserializer=tensorboard_service.BatchCreateTensorboardTimeSeriesResponse.deserialize, + ) + return self._stubs["batch_create_tensorboard_time_series"] + @property def create_tensorboard_time_series( self, @@ -833,6 +907,43 @@ def delete_tensorboard_time_series( ) return self._stubs["delete_tensorboard_time_series"] + @property + def batch_read_tensorboard_time_series_data( + self, + ) -> Callable[ + [tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest], + tensorboard_service.BatchReadTensorboardTimeSeriesDataResponse, + ]: + r"""Return a callable for the batch read tensorboard time + series data method over gRPC. + + Reads multiple TensorboardTimeSeries' data. The data + point number limit is 1000 for scalars, 100 for tensors + and blob references. If the number of data points stored + is less than the limit, all data will be returned. + Otherwise, that limit number of data points will be + randomly selected from this time series and returned. + + Returns: + Callable[[~.BatchReadTensorboardTimeSeriesDataRequest], + ~.BatchReadTensorboardTimeSeriesDataResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "batch_read_tensorboard_time_series_data" not in self._stubs: + self._stubs[ + "batch_read_tensorboard_time_series_data" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1beta1.TensorboardService/BatchReadTensorboardTimeSeriesData", + request_serializer=tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest.serialize, + response_deserializer=tensorboard_service.BatchReadTensorboardTimeSeriesDataResponse.deserialize, + ) + return self._stubs["batch_read_tensorboard_time_series_data"] + @property def read_tensorboard_time_series_data( self, @@ -843,12 +954,11 @@ def read_tensorboard_time_series_data( r"""Return a callable for the read tensorboard time series data method over gRPC. - Reads a TensorboardTimeSeries' data. Data is returned in - paginated responses. By default, if the number of data points - stored is less than 1000, all data will be returned. Otherwise, - 1000 data points will be randomly selected from this time series - and returned. This value can be changed by changing - max_data_points. + Reads a TensorboardTimeSeries' data. By default, if the number + of data points stored is less than 1000, all data will be + returned. Otherwise, 1000 data points will be randomly selected + from this time series and returned. This value can be changed by + changing max_data_points, which can't be greater than 10k. Returns: Callable[[~.ReadTensorboardTimeSeriesDataRequest], @@ -902,6 +1012,40 @@ def read_tensorboard_blob_data( ) return self._stubs["read_tensorboard_blob_data"] + @property + def write_tensorboard_experiment_data( + self, + ) -> Callable[ + [tensorboard_service.WriteTensorboardExperimentDataRequest], + tensorboard_service.WriteTensorboardExperimentDataResponse, + ]: + r"""Return a callable for the write tensorboard experiment + data method over gRPC. + + Write time series data points of multiple + TensorboardTimeSeries in multiple TensorboardRun's. If + any data fail to be ingested, an error will be returned. + + Returns: + Callable[[~.WriteTensorboardExperimentDataRequest], + ~.WriteTensorboardExperimentDataResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "write_tensorboard_experiment_data" not in self._stubs: + self._stubs[ + "write_tensorboard_experiment_data" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1beta1.TensorboardService/WriteTensorboardExperimentData", + request_serializer=tensorboard_service.WriteTensorboardExperimentDataRequest.serialize, + response_deserializer=tensorboard_service.WriteTensorboardExperimentDataResponse.deserialize, + ) + return self._stubs["write_tensorboard_experiment_data"] + @property def write_tensorboard_run_data( self, @@ -966,5 +1110,215 @@ def export_tensorboard_time_series_data( ) return self._stubs["export_tensorboard_time_series_data"] + def close(self): + self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + @property + def kind(self) -> str: + return "grpc" + __all__ = ("TensorboardServiceGrpcTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/tensorboard_service/transports/grpc_asyncio.py b/google/cloud/aiplatform_v1beta1/services/tensorboard_service/transports/grpc_asyncio.py index 6824b6ebdf..418b16da7d 100644 --- a/google/cloud/aiplatform_v1beta1/services/tensorboard_service/transports/grpc_asyncio.py +++ b/google/cloud/aiplatform_v1beta1/services/tensorboard_service/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,12 +16,11 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore -from google.api_core import operations_v1 # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore @@ -38,6 +37,10 @@ from google.cloud.aiplatform_v1beta1.types import ( tensorboard_time_series as gca_tensorboard_time_series, ) +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from .base import TensorboardServiceTransport, DEFAULT_CLIENT_INFO from .grpc import TensorboardServiceGrpcTransport @@ -91,14 +94,14 @@ def create_channel( aio.Channel: A gRPC AsyncIO channel object. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @@ -116,6 +119,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -139,16 +143,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -157,6 +161,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport @@ -167,7 +173,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -209,13 +215,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -245,7 +255,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel @@ -578,6 +588,37 @@ def create_tensorboard_run( ) return self._stubs["create_tensorboard_run"] + @property + def batch_create_tensorboard_runs( + self, + ) -> Callable[ + [tensorboard_service.BatchCreateTensorboardRunsRequest], + Awaitable[tensorboard_service.BatchCreateTensorboardRunsResponse], + ]: + r"""Return a callable for the batch create tensorboard runs method over gRPC. + + Batch create TensorboardRuns. + + Returns: + Callable[[~.BatchCreateTensorboardRunsRequest], + Awaitable[~.BatchCreateTensorboardRunsResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "batch_create_tensorboard_runs" not in self._stubs: + self._stubs[ + "batch_create_tensorboard_runs" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1beta1.TensorboardService/BatchCreateTensorboardRuns", + request_serializer=tensorboard_service.BatchCreateTensorboardRunsRequest.serialize, + response_deserializer=tensorboard_service.BatchCreateTensorboardRunsResponse.deserialize, + ) + return self._stubs["batch_create_tensorboard_runs"] + @property def get_tensorboard_run( self, @@ -694,6 +735,39 @@ def delete_tensorboard_run( ) return self._stubs["delete_tensorboard_run"] + @property + def batch_create_tensorboard_time_series( + self, + ) -> Callable[ + [tensorboard_service.BatchCreateTensorboardTimeSeriesRequest], + Awaitable[tensorboard_service.BatchCreateTensorboardTimeSeriesResponse], + ]: + r"""Return a callable for the batch create tensorboard time + series method over gRPC. + + Batch create TensorboardTimeSeries that belong to a + TensorboardExperiment. + + Returns: + Callable[[~.BatchCreateTensorboardTimeSeriesRequest], + Awaitable[~.BatchCreateTensorboardTimeSeriesResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "batch_create_tensorboard_time_series" not in self._stubs: + self._stubs[ + "batch_create_tensorboard_time_series" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1beta1.TensorboardService/BatchCreateTensorboardTimeSeries", + request_serializer=tensorboard_service.BatchCreateTensorboardTimeSeriesRequest.serialize, + response_deserializer=tensorboard_service.BatchCreateTensorboardTimeSeriesResponse.deserialize, + ) + return self._stubs["batch_create_tensorboard_time_series"] + @property def create_tensorboard_time_series( self, @@ -845,6 +919,43 @@ def delete_tensorboard_time_series( ) return self._stubs["delete_tensorboard_time_series"] + @property + def batch_read_tensorboard_time_series_data( + self, + ) -> Callable[ + [tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest], + Awaitable[tensorboard_service.BatchReadTensorboardTimeSeriesDataResponse], + ]: + r"""Return a callable for the batch read tensorboard time + series data method over gRPC. + + Reads multiple TensorboardTimeSeries' data. The data + point number limit is 1000 for scalars, 100 for tensors + and blob references. If the number of data points stored + is less than the limit, all data will be returned. + Otherwise, that limit number of data points will be + randomly selected from this time series and returned. + + Returns: + Callable[[~.BatchReadTensorboardTimeSeriesDataRequest], + Awaitable[~.BatchReadTensorboardTimeSeriesDataResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "batch_read_tensorboard_time_series_data" not in self._stubs: + self._stubs[ + "batch_read_tensorboard_time_series_data" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1beta1.TensorboardService/BatchReadTensorboardTimeSeriesData", + request_serializer=tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest.serialize, + response_deserializer=tensorboard_service.BatchReadTensorboardTimeSeriesDataResponse.deserialize, + ) + return self._stubs["batch_read_tensorboard_time_series_data"] + @property def read_tensorboard_time_series_data( self, @@ -855,12 +966,11 @@ def read_tensorboard_time_series_data( r"""Return a callable for the read tensorboard time series data method over gRPC. - Reads a TensorboardTimeSeries' data. Data is returned in - paginated responses. By default, if the number of data points - stored is less than 1000, all data will be returned. Otherwise, - 1000 data points will be randomly selected from this time series - and returned. This value can be changed by changing - max_data_points. + Reads a TensorboardTimeSeries' data. By default, if the number + of data points stored is less than 1000, all data will be + returned. Otherwise, 1000 data points will be randomly selected + from this time series and returned. This value can be changed by + changing max_data_points, which can't be greater than 10k. Returns: Callable[[~.ReadTensorboardTimeSeriesDataRequest], @@ -914,6 +1024,40 @@ def read_tensorboard_blob_data( ) return self._stubs["read_tensorboard_blob_data"] + @property + def write_tensorboard_experiment_data( + self, + ) -> Callable[ + [tensorboard_service.WriteTensorboardExperimentDataRequest], + Awaitable[tensorboard_service.WriteTensorboardExperimentDataResponse], + ]: + r"""Return a callable for the write tensorboard experiment + data method over gRPC. + + Write time series data points of multiple + TensorboardTimeSeries in multiple TensorboardRun's. If + any data fail to be ingested, an error will be returned. + + Returns: + Callable[[~.WriteTensorboardExperimentDataRequest], + Awaitable[~.WriteTensorboardExperimentDataResponse]]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "write_tensorboard_experiment_data" not in self._stubs: + self._stubs[ + "write_tensorboard_experiment_data" + ] = self.grpc_channel.unary_unary( + "/google.cloud.aiplatform.v1beta1.TensorboardService/WriteTensorboardExperimentData", + request_serializer=tensorboard_service.WriteTensorboardExperimentDataRequest.serialize, + response_deserializer=tensorboard_service.WriteTensorboardExperimentDataResponse.deserialize, + ) + return self._stubs["write_tensorboard_experiment_data"] + @property def write_tensorboard_run_data( self, @@ -978,5 +1122,211 @@ def export_tensorboard_time_series_data( ) return self._stubs["export_tensorboard_time_series_data"] + def close(self): + return self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + __all__ = ("TensorboardServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/vizier_service/__init__.py b/google/cloud/aiplatform_v1beta1/services/vizier_service/__init__.py index 5586edbbe2..b91bd3c525 100644 --- a/google/cloud/aiplatform_v1beta1/services/vizier_service/__init__.py +++ b/google/cloud/aiplatform_v1beta1/services/vizier_service/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1beta1/services/vizier_service/async_client.py b/google/cloud/aiplatform_v1beta1/services/vizier_service/async_client.py index d76f7aa64e..6a4b2788b4 100644 --- a/google/cloud/aiplatform_v1beta1/services/vizier_service/async_client.py +++ b/google/cloud/aiplatform_v1beta1/services/vizier_service/async_client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,22 +16,31 @@ from collections import OrderedDict import functools import re -from typing import Dict, Sequence, Tuple, Type, Union +from typing import Dict, Mapping, Optional, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core.client_options import ClientOptions +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1beta1.services.vizier_service import pagers from google.cloud.aiplatform_v1beta1.types import study from google.cloud.aiplatform_v1beta1.types import study as gca_study from google.cloud.aiplatform_v1beta1.types import vizier_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import VizierServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc_asyncio import VizierServiceGrpcAsyncIOTransport @@ -39,8 +48,8 @@ class VizierServiceAsyncClient: - """Cloud AI Platform Vizier API. - Vizier service is a GCP service to solve blackbox optimization + """Vertex AI Vizier API. + Vertex AI Vizier is a service to solve blackbox optimization problems, such as tuning machine learning hyperparameters and searching over deep learning architectures. """ @@ -83,7 +92,8 @@ class VizierServiceAsyncClient: @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -98,7 +108,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -113,9 +123,45 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + return VizierServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore + @property def transport(self) -> VizierServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: VizierServiceTransport: The transport used by the client instance. @@ -134,7 +180,7 @@ def __init__( client_options: ClientOptions = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the vizier service client. + """Instantiates the vizier service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -175,19 +221,47 @@ def __init__( async def create_study( self, - request: vizier_service.CreateStudyRequest = None, + request: Union[vizier_service.CreateStudyRequest, dict] = None, *, parent: str = None, study: gca_study.Study = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_study.Study: r"""Creates a Study. A resource name will be generated after creation of the Study. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_create_study(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + study = aiplatform_v1beta1.Study() + study.display_name = "display_name_value" + study.study_spec.metrics.metric_id = "metric_id_value" + study.study_spec.metrics.goal = "MINIMIZE" + study.study_spec.parameters.double_value_spec.min_value = 0.96 + study.study_spec.parameters.double_value_spec.max_value = 0.962 + study.study_spec.parameters.parameter_id = "parameter_id_value" + + request = aiplatform_v1beta1.CreateStudyRequest( + parent="parent_value", + study=study, + ) + + # Make the request + response = await client.create_study(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.CreateStudyRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateStudyRequest, dict]): The request object. Request message for [VizierService.CreateStudy][google.cloud.aiplatform.v1beta1.VizierService.CreateStudy]. parent (:class:`str`): @@ -216,7 +290,7 @@ async def create_study( A message representing a Study. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, study]) if request is not None and has_flattened_params: @@ -249,24 +323,48 @@ async def create_study( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def get_study( self, - request: vizier_service.GetStudyRequest = None, + request: Union[vizier_service.GetStudyRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> study.Study: r"""Gets a Study by name. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_get_study(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetStudyRequest( + name="name_value", + ) + + # Make the request + response = await client.get_study(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.GetStudyRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.GetStudyRequest, dict]): The request object. Request message for [VizierService.GetStudy][google.cloud.aiplatform.v1beta1.VizierService.GetStudy]. name (:class:`str`): @@ -287,7 +385,7 @@ async def get_study( A message representing a Study. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -318,25 +416,50 @@ async def get_study( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_studies( self, - request: vizier_service.ListStudiesRequest = None, + request: Union[vizier_service.ListStudiesRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListStudiesAsyncPager: r"""Lists all the studies in a region for an associated project. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_list_studies(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListStudiesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_studies(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ListStudiesRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ListStudiesRequest, dict]): The request object. Request message for [VizierService.ListStudies][google.cloud.aiplatform.v1beta1.VizierService.ListStudies]. parent (:class:`str`): @@ -363,7 +486,7 @@ async def list_studies( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -394,12 +517,20 @@ async def list_studies( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListStudiesAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -407,17 +538,33 @@ async def list_studies( async def delete_study( self, - request: vizier_service.DeleteStudyRequest = None, + request: Union[vizier_service.DeleteStudyRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Deletes a Study. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_delete_study(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteStudyRequest( + name="name_value", + ) + + # Make the request + await client.delete_study(request=request) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.DeleteStudyRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteStudyRequest, dict]): The request object. Request message for [VizierService.DeleteStudy][google.cloud.aiplatform.v1beta1.VizierService.DeleteStudy]. name (:class:`str`): @@ -435,7 +582,7 @@ async def delete_study( 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 + # Quick 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: @@ -467,23 +614,46 @@ async def delete_study( # Send the request. await rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) async def lookup_study( self, - request: vizier_service.LookupStudyRequest = None, + request: Union[vizier_service.LookupStudyRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> study.Study: r"""Looks a study up using the user-defined display_name field instead of the fully qualified resource name. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_lookup_study(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.LookupStudyRequest( + parent="parent_value", + display_name="display_name_value", + ) + + # Make the request + response = await client.lookup_study(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.LookupStudyRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.LookupStudyRequest, dict]): The request object. Request message for [VizierService.LookupStudy][google.cloud.aiplatform.v1beta1.VizierService.LookupStudy]. parent (:class:`str`): @@ -505,7 +675,7 @@ async def lookup_study( A message representing a Study. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -536,27 +706,57 @@ async def lookup_study( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def suggest_trials( self, - request: vizier_service.SuggestTrialsRequest = None, + request: Union[vizier_service.SuggestTrialsRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: r"""Adds one or more Trials to a Study, with parameter values - suggested by AI Platform Vizier. Returns a long-running - operation associated with the generation of Trial suggestions. - When this long-running operation succeeds, it will contain a + suggested by Vertex AI Vizier. Returns a long-running operation + associated with the generation of Trial suggestions. When this + long-running operation succeeds, it will contain a [SuggestTrialsResponse][google.cloud.ml.v1.SuggestTrialsResponse]. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_suggest_trials(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.SuggestTrialsRequest( + parent="parent_value", + suggestion_count=1744, + client_id="client_id_value", + ) + + # Make the request + operation = client.suggest_trials(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.SuggestTrialsRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.SuggestTrialsRequest, dict]): The request object. Request message for [VizierService.SuggestTrials][google.cloud.aiplatform.v1beta1.VizierService.SuggestTrials]. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -593,7 +793,12 @@ async def suggest_trials( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -608,18 +813,37 @@ async def suggest_trials( async def create_trial( self, - request: vizier_service.CreateTrialRequest = None, + request: Union[vizier_service.CreateTrialRequest, dict] = None, *, parent: str = None, trial: study.Trial = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> study.Trial: r"""Adds a user provided Trial to a Study. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_create_trial(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateTrialRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_trial(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.CreateTrialRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateTrialRequest, dict]): The request object. Request message for [VizierService.CreateTrial][google.cloud.aiplatform.v1beta1.VizierService.CreateTrial]. parent (:class:`str`): @@ -651,7 +875,7 @@ async def create_trial( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, trial]) if request is not None and has_flattened_params: @@ -684,24 +908,48 @@ async def create_trial( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def get_trial( self, - request: vizier_service.GetTrialRequest = None, + request: Union[vizier_service.GetTrialRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> study.Trial: r"""Gets a Trial. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_get_trial(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetTrialRequest( + name="name_value", + ) + + # Make the request + response = await client.get_trial(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.GetTrialRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.GetTrialRequest, dict]): The request object. Request message for [VizierService.GetTrial][google.cloud.aiplatform.v1beta1.VizierService.GetTrial]. name (:class:`str`): @@ -727,7 +975,7 @@ async def get_trial( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -758,24 +1006,49 @@ async def get_trial( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_trials( self, - request: vizier_service.ListTrialsRequest = None, + request: Union[vizier_service.ListTrialsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListTrialsAsyncPager: r"""Lists the Trials associated with a Study. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_list_trials(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListTrialsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_trials(request=request) + + # Handle the response + async for response in page_result: + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ListTrialsRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ListTrialsRequest, dict]): The request object. Request message for [VizierService.ListTrials][google.cloud.aiplatform.v1beta1.VizierService.ListTrials]. parent (:class:`str`): @@ -802,7 +1075,7 @@ async def list_trials( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -833,12 +1106,20 @@ async def list_trials( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListTrialsAsyncPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -846,9 +1127,9 @@ async def list_trials( async def add_trial_measurement( self, - request: vizier_service.AddTrialMeasurementRequest = None, + request: Union[vizier_service.AddTrialMeasurementRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> study.Trial: @@ -856,8 +1137,27 @@ async def add_trial_measurement( Trial. This measurement is assumed to have been taken before the Trial is complete. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_add_trial_measurement(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.AddTrialMeasurementRequest( + trial_name="trial_name_value", + ) + + # Make the request + response = await client.add_trial_measurement(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.AddTrialMeasurementRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.AddTrialMeasurementRequest, dict]): The request object. Request message for [VizierService.AddTrialMeasurement][google.cloud.aiplatform.v1beta1.VizierService.AddTrialMeasurement]. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -895,23 +1195,47 @@ async def add_trial_measurement( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def complete_trial( self, - request: vizier_service.CompleteTrialRequest = None, + request: Union[vizier_service.CompleteTrialRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> study.Trial: r"""Marks a Trial as complete. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_complete_trial(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CompleteTrialRequest( + name="name_value", + ) + + # Make the request + response = await client.complete_trial(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.CompleteTrialRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.CompleteTrialRequest, dict]): The request object. Request message for [VizierService.CompleteTrial][google.cloud.aiplatform.v1beta1.VizierService.CompleteTrial]. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -947,24 +1271,45 @@ async def complete_trial( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def delete_trial( self, - request: vizier_service.DeleteTrialRequest = None, + request: Union[vizier_service.DeleteTrialRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Deletes a Trial. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_delete_trial(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteTrialRequest( + name="name_value", + ) + + # Make the request + await client.delete_trial(request=request) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.DeleteTrialRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteTrialRequest, dict]): The request object. Request message for [VizierService.DeleteTrial][google.cloud.aiplatform.v1beta1.VizierService.DeleteTrial]. name (:class:`str`): @@ -981,7 +1326,7 @@ async def delete_trial( 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 + # Quick 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: @@ -1013,14 +1358,17 @@ async def delete_trial( # Send the request. await rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) async def check_trial_early_stopping_state( self, - request: vizier_service.CheckTrialEarlyStoppingStateRequest = None, + request: Union[vizier_service.CheckTrialEarlyStoppingStateRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -1029,8 +1377,31 @@ async def check_trial_early_stopping_state( will contain a [CheckTrialEarlyStoppingStateResponse][google.cloud.ml.v1.CheckTrialEarlyStoppingStateResponse]. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_check_trial_early_stopping_state(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CheckTrialEarlyStoppingStateRequest( + trial_name="trial_name_value", + ) + + # Make the request + operation = client.check_trial_early_stopping_state(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.CheckTrialEarlyStoppingStateRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.CheckTrialEarlyStoppingStateRequest, dict]): The request object. Request message for [VizierService.CheckTrialEarlyStoppingState][google.cloud.aiplatform.v1beta1.VizierService.CheckTrialEarlyStoppingState]. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -1069,7 +1440,12 @@ async def check_trial_early_stopping_state( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation_async.from_gapic( @@ -1084,16 +1460,35 @@ async def check_trial_early_stopping_state( async def stop_trial( self, - request: vizier_service.StopTrialRequest = None, + request: Union[vizier_service.StopTrialRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> study.Trial: r"""Stops a Trial. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_stop_trial(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.StopTrialRequest( + name="name_value", + ) + + # Make the request + response = await client.stop_trial(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.StopTrialRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.StopTrialRequest, dict]): The request object. Request message for [VizierService.StopTrial][google.cloud.aiplatform.v1beta1.VizierService.StopTrial]. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -1129,17 +1524,22 @@ async def stop_trial( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response async def list_optimal_trials( self, - request: vizier_service.ListOptimalTrialsRequest = None, + request: Union[vizier_service.ListOptimalTrialsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> vizier_service.ListOptimalTrialsResponse: @@ -1148,8 +1548,27 @@ async def list_optimal_trials( pareto-optimal can be checked in wiki page. https://en.wikipedia.org/wiki/Pareto_efficiency + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + async def sample_list_optimal_trials(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListOptimalTrialsRequest( + parent="parent_value", + ) + + # Make the request + response = await client.list_optimal_trials(request=request) + + # Handle the response + print(response) + Args: - request (:class:`google.cloud.aiplatform_v1beta1.types.ListOptimalTrialsRequest`): + request (Union[google.cloud.aiplatform_v1beta1.types.ListOptimalTrialsRequest, dict]): The request object. Request message for [VizierService.ListOptimalTrials][google.cloud.aiplatform.v1beta1.VizierService.ListOptimalTrials]. parent (:class:`str`): @@ -1172,7 +1591,7 @@ async def list_optimal_trials( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1203,11 +1622,693 @@ async def list_optimal_trials( ) # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_operations, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_operation, + default_timeout=None, + 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_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.delete_operation, + default_timeout=None, + 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 cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.cancel_operation, + default_timeout=None, + 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 wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.wait_operation, + default_timeout=None, + 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 set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response + async def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = await rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.get_location, + default_timeout=None, + 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 list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._client._transport.list_locations, + default_timeout=None, + 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 __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc, tb): + await self.transport.close() + try: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( diff --git a/google/cloud/aiplatform_v1beta1/services/vizier_service/client.py b/google/cloud/aiplatform_v1beta1/services/vizier_service/client.py index c6f834add7..5ec3a810e8 100644 --- a/google/cloud/aiplatform_v1beta1/services/vizier_service/client.py +++ b/google/cloud/aiplatform_v1beta1/services/vizier_service/client.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,28 +14,36 @@ # 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 +from typing import Dict, Mapping, 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 as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore +from google.api_core import client_options as client_options_lib +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries from google.auth import credentials as ga_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 +try: + OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] +except AttributeError: # pragma: NO COVER + OptionalRetry = Union[retries.Retry, object] # type: ignore + from google.api_core import operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.aiplatform_v1beta1.services.vizier_service import pagers from google.cloud.aiplatform_v1beta1.types import study from google.cloud.aiplatform_v1beta1.types import study as gca_study from google.cloud.aiplatform_v1beta1.types import vizier_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.protobuf import timestamp_pb2 # type: ignore from .transports.base import VizierServiceTransport, DEFAULT_CLIENT_INFO from .transports.grpc import VizierServiceGrpcTransport @@ -54,8 +62,11 @@ class VizierServiceClientMeta(type): _transport_registry["grpc"] = VizierServiceGrpcTransport _transport_registry["grpc_asyncio"] = VizierServiceGrpcAsyncIOTransport - def get_transport_class(cls, label: str = None,) -> Type[VizierServiceTransport]: - """Return an appropriate transport class. + def get_transport_class( + cls, + label: str = None, + ) -> Type[VizierServiceTransport]: + """Returns an appropriate transport class. Args: label: The name of the desired transport. If none is @@ -74,15 +85,16 @@ def get_transport_class(cls, label: str = None,) -> Type[VizierServiceTransport] class VizierServiceClient(metaclass=VizierServiceClientMeta): - """Cloud AI Platform Vizier API. - Vizier service is a GCP service to solve blackbox optimization + """Vertex AI Vizier API. + Vertex AI Vizier is a service to solve blackbox optimization problems, such as tuning machine learning hyperparameters and searching over deep learning architectures. """ @staticmethod def _get_default_mtls_endpoint(api_endpoint): - """Convert api endpoint to mTLS endpoint. + """Converts api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. Args: @@ -116,7 +128,8 @@ def _get_default_mtls_endpoint(api_endpoint): @classmethod def from_service_account_info(cls, info: dict, *args, **kwargs): - """Creates an instance of this client using the provided credentials info. + """Creates an instance of this client using the provided credentials + info. Args: info (dict): The service account private key info. @@ -133,7 +146,7 @@ def from_service_account_info(cls, info: dict, *args, **kwargs): @classmethod def from_service_account_file(cls, filename: str, *args, **kwargs): """Creates an instance of this client using the provided credentials - file. + file. Args: filename (str): The path to the service account private key json @@ -152,23 +165,30 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): @property def transport(self) -> VizierServiceTransport: - """Return the transport used by the client instance. + """Returns the transport used by the client instance. Returns: - VizierServiceTransport: The transport used by the client instance. + VizierServiceTransport: The transport used by the client + instance. """ return self._transport @staticmethod - def custom_job_path(project: str, location: str, custom_job: str,) -> str: - """Return a fully-qualified custom_job string.""" + def custom_job_path( + project: str, + location: str, + custom_job: str, + ) -> str: + """Returns a fully-qualified custom_job string.""" return "projects/{project}/locations/{location}/customJobs/{custom_job}".format( - project=project, location=location, custom_job=custom_job, + project=project, + location=location, + custom_job=custom_job, ) @staticmethod def parse_custom_job_path(path: str) -> Dict[str, str]: - """Parse a custom_job path into its component segments.""" + """Parses a custom_job path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/customJobs/(?P.+?)$", path, @@ -176,15 +196,21 @@ def parse_custom_job_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def study_path(project: str, location: str, study: str,) -> str: - """Return a fully-qualified study string.""" + def study_path( + project: str, + location: str, + study: str, + ) -> str: + """Returns a fully-qualified study string.""" return "projects/{project}/locations/{location}/studies/{study}".format( - project=project, location=location, study=study, + project=project, + location=location, + study=study, ) @staticmethod def parse_study_path(path: str) -> Dict[str, str]: - """Parse a study path into its component segments.""" + """Parses a study path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/studies/(?P.+?)$", path, @@ -192,15 +218,23 @@ def parse_study_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def trial_path(project: str, location: str, study: str, trial: str,) -> str: - """Return a fully-qualified trial string.""" + def trial_path( + project: str, + location: str, + study: str, + trial: str, + ) -> str: + """Returns a fully-qualified trial string.""" return "projects/{project}/locations/{location}/studies/{study}/trials/{trial}".format( - project=project, location=location, study=study, trial=trial, + project=project, + location=location, + study=study, + trial=trial, ) @staticmethod def parse_trial_path(path: str) -> Dict[str, str]: - """Parse a trial path into its component segments.""" + """Parses a trial path into its component segments.""" m = re.match( r"^projects/(?P.+?)/locations/(?P.+?)/studies/(?P.+?)/trials/(?P.+?)$", path, @@ -208,8 +242,10 @@ def parse_trial_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_billing_account_path(billing_account: str,) -> str: - """Return a fully-qualified billing_account string.""" + def common_billing_account_path( + billing_account: str, + ) -> str: + """Returns a fully-qualified billing_account string.""" return "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -221,9 +257,13 @@ def parse_common_billing_account_path(path: str) -> Dict[str, str]: 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,) + def common_folder_path( + folder: str, + ) -> str: + """Returns a fully-qualified folder string.""" + return "folders/{folder}".format( + folder=folder, + ) @staticmethod def parse_common_folder_path(path: str) -> Dict[str, str]: @@ -232,9 +272,13 @@ def parse_common_folder_path(path: str) -> Dict[str, str]: 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,) + def common_organization_path( + organization: str, + ) -> str: + """Returns a fully-qualified organization string.""" + return "organizations/{organization}".format( + organization=organization, + ) @staticmethod def parse_common_organization_path(path: str) -> Dict[str, str]: @@ -243,9 +287,13 @@ def parse_common_organization_path(path: str) -> Dict[str, str]: 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,) + def common_project_path( + project: str, + ) -> str: + """Returns a fully-qualified project string.""" + return "projects/{project}".format( + project=project, + ) @staticmethod def parse_common_project_path(path: str) -> Dict[str, str]: @@ -254,10 +302,14 @@ def parse_common_project_path(path: str) -> Dict[str, str]: return m.groupdict() if m else {} @staticmethod - def common_location_path(project: str, location: str,) -> str: - """Return a fully-qualified location string.""" + def common_location_path( + project: str, + location: str, + ) -> str: + """Returns a fully-qualified location string.""" return "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) @staticmethod @@ -266,6 +318,73 @@ def parse_common_location_path(path: str) -> Dict[str, str]: m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) return m.groupdict() if m else {} + @classmethod + def get_mtls_endpoint_and_cert_source( + cls, client_options: Optional[client_options_lib.ClientOptions] = None + ): + """Return the API endpoint and client cert source for mutual TLS. + + The client cert source is determined in the following order: + (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the + client cert source is None. + (2) if `client_options.client_cert_source` is provided, use the provided one; if the + default client cert source exists, use the default one; otherwise the client cert + source is None. + + The API endpoint is determined in the following order: + (1) if `client_options.api_endpoint` if provided, use the provided one. + (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the + default mTLS endpoint; if the environment variabel is "never", use the default API + endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise + use the default API endpoint. + + More details can be found at https://google.aip.dev/auth/4114. + + Args: + client_options (google.api_core.client_options.ClientOptions): Custom options for the + client. Only the `api_endpoint` and `client_cert_source` properties may be used + in this method. + + Returns: + Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the + client cert source to use. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If any errors happen. + """ + if client_options is None: + client_options = client_options_lib.ClientOptions() + use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") + use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_client_cert not in ("true", "false"): + raise ValueError( + "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" + ) + if use_mtls_endpoint not in ("auto", "never", "always"): + raise MutualTLSChannelError( + "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" + ) + + # Figure out the client cert source to use. + client_cert_source = None + if use_client_cert == "true": + if client_options.client_cert_source: + client_cert_source = client_options.client_cert_source + elif mtls.has_default_client_cert_source(): + client_cert_source = mtls.default_client_cert_source() + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + elif use_mtls_endpoint == "always" or ( + use_mtls_endpoint == "auto" and client_cert_source + ): + api_endpoint = cls.DEFAULT_MTLS_ENDPOINT + else: + api_endpoint = cls.DEFAULT_ENDPOINT + + return api_endpoint, client_cert_source + def __init__( self, *, @@ -274,7 +393,7 @@ def __init__( client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: - """Instantiate the vizier service client. + """Instantiates the vizier service client. Args: credentials (Optional[google.auth.credentials.Credentials]): The @@ -316,58 +435,42 @@ def __init__( 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")) + api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( + client_options ) - client_cert_source_func = None - is_mtls = False - if use_client_cert: - if client_options.client_cert_source: - is_mtls = True - client_cert_source_func = client_options.client_cert_source - else: - is_mtls = mtls.has_default_client_cert_source() - client_cert_source_func = ( - mtls.default_client_cert_source() 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" - ) + api_key_value = getattr(client_options, "api_key", None) + if api_key_value and credentials: + raise ValueError( + "client_options.api_key and credentials are mutually exclusive" + ) # 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, VizierServiceTransport): # transport is a VizierServiceTransport instance. - if credentials or client_options.credentials_file: + if credentials or client_options.credentials_file or api_key_value: 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." + "When providing a transport instance, provide its scopes " + "directly." ) self._transport = transport else: + import google.auth._default # type: ignore + + if api_key_value and hasattr( + google.auth._default, "get_api_key_credentials" + ): + credentials = google.auth._default.get_api_key_credentials( + api_key_value + ) + Transport = type(self).get_transport_class(transport) self._transport = Transport( credentials=credentials, @@ -377,23 +480,52 @@ def __init__( client_cert_source_for_mtls=client_cert_source_func, quota_project_id=client_options.quota_project_id, client_info=client_info, + always_use_jwt_access=True, ) def create_study( self, - request: vizier_service.CreateStudyRequest = None, + request: Union[vizier_service.CreateStudyRequest, dict] = None, *, parent: str = None, study: gca_study.Study = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gca_study.Study: r"""Creates a Study. A resource name will be generated after creation of the Study. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_create_study(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + study = aiplatform_v1beta1.Study() + study.display_name = "display_name_value" + study.study_spec.metrics.metric_id = "metric_id_value" + study.study_spec.metrics.goal = "MINIMIZE" + study.study_spec.parameters.double_value_spec.min_value = 0.96 + study.study_spec.parameters.double_value_spec.max_value = 0.962 + study.study_spec.parameters.parameter_id = "parameter_id_value" + + request = aiplatform_v1beta1.CreateStudyRequest( + parent="parent_value", + study=study, + ) + + # Make the request + response = client.create_study(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.CreateStudyRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateStudyRequest, dict]): The request object. Request message for [VizierService.CreateStudy][google.cloud.aiplatform.v1beta1.VizierService.CreateStudy]. parent (str): @@ -422,7 +554,7 @@ def create_study( A message representing a Study. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, study]) if request is not None and has_flattened_params: @@ -455,24 +587,48 @@ def create_study( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def get_study( self, - request: vizier_service.GetStudyRequest = None, + request: Union[vizier_service.GetStudyRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> study.Study: r"""Gets a Study by name. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_get_study(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetStudyRequest( + name="name_value", + ) + + # Make the request + response = client.get_study(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.GetStudyRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.GetStudyRequest, dict]): The request object. Request message for [VizierService.GetStudy][google.cloud.aiplatform.v1beta1.VizierService.GetStudy]. name (str): @@ -493,7 +649,7 @@ def get_study( A message representing a Study. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -524,25 +680,50 @@ def get_study( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_studies( self, - request: vizier_service.ListStudiesRequest = None, + request: Union[vizier_service.ListStudiesRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListStudiesPager: r"""Lists all the studies in a region for an associated project. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_list_studies(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListStudiesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_studies(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ListStudiesRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ListStudiesRequest, dict]): The request object. Request message for [VizierService.ListStudies][google.cloud.aiplatform.v1beta1.VizierService.ListStudies]. parent (str): @@ -569,7 +750,7 @@ def list_studies( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -600,12 +781,20 @@ def list_studies( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListStudiesPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -613,17 +802,33 @@ def list_studies( def delete_study( self, - request: vizier_service.DeleteStudyRequest = None, + request: Union[vizier_service.DeleteStudyRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Deletes a Study. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_delete_study(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteStudyRequest( + name="name_value", + ) + + # Make the request + client.delete_study(request=request) + Args: - request (google.cloud.aiplatform_v1beta1.types.DeleteStudyRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteStudyRequest, dict]): The request object. Request message for [VizierService.DeleteStudy][google.cloud.aiplatform.v1beta1.VizierService.DeleteStudy]. name (str): @@ -641,7 +846,7 @@ def delete_study( 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 + # Quick 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: @@ -673,23 +878,46 @@ def delete_study( # Send the request. rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) def lookup_study( self, - request: vizier_service.LookupStudyRequest = None, + request: Union[vizier_service.LookupStudyRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> study.Study: r"""Looks a study up using the user-defined display_name field instead of the fully qualified resource name. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_lookup_study(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.LookupStudyRequest( + parent="parent_value", + display_name="display_name_value", + ) + + # Make the request + response = client.lookup_study(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.LookupStudyRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.LookupStudyRequest, dict]): The request object. Request message for [VizierService.LookupStudy][google.cloud.aiplatform.v1beta1.VizierService.LookupStudy]. parent (str): @@ -711,7 +939,7 @@ def lookup_study( A message representing a Study. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -742,27 +970,57 @@ def lookup_study( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def suggest_trials( self, - request: vizier_service.SuggestTrialsRequest = None, + request: Union[vizier_service.SuggestTrialsRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: r"""Adds one or more Trials to a Study, with parameter values - suggested by AI Platform Vizier. Returns a long-running - operation associated with the generation of Trial suggestions. - When this long-running operation succeeds, it will contain a + suggested by Vertex AI Vizier. Returns a long-running operation + associated with the generation of Trial suggestions. When this + long-running operation succeeds, it will contain a [SuggestTrialsResponse][google.cloud.ml.v1.SuggestTrialsResponse]. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_suggest_trials(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.SuggestTrialsRequest( + parent="parent_value", + suggestion_count=1744, + client_id="client_id_value", + ) + + # Make the request + operation = client.suggest_trials(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.SuggestTrialsRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.SuggestTrialsRequest, dict]): The request object. Request message for [VizierService.SuggestTrials][google.cloud.aiplatform.v1beta1.VizierService.SuggestTrials]. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -800,7 +1058,12 @@ def suggest_trials( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation.from_gapic( @@ -815,18 +1078,37 @@ def suggest_trials( def create_trial( self, - request: vizier_service.CreateTrialRequest = None, + request: Union[vizier_service.CreateTrialRequest, dict] = None, *, parent: str = None, trial: study.Trial = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> study.Trial: r"""Adds a user provided Trial to a Study. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_create_trial(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateTrialRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_trial(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.CreateTrialRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.CreateTrialRequest, dict]): The request object. Request message for [VizierService.CreateTrial][google.cloud.aiplatform.v1beta1.VizierService.CreateTrial]. parent (str): @@ -858,7 +1140,7 @@ def create_trial( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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, trial]) if request is not None and has_flattened_params: @@ -891,24 +1173,48 @@ def create_trial( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def get_trial( self, - request: vizier_service.GetTrialRequest = None, + request: Union[vizier_service.GetTrialRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> study.Trial: r"""Gets a Trial. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_get_trial(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetTrialRequest( + name="name_value", + ) + + # Make the request + response = client.get_trial(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.GetTrialRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.GetTrialRequest, dict]): The request object. Request message for [VizierService.GetTrial][google.cloud.aiplatform.v1beta1.VizierService.GetTrial]. name (str): @@ -934,7 +1240,7 @@ def get_trial( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -965,24 +1271,49 @@ def get_trial( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_trials( self, - request: vizier_service.ListTrialsRequest = None, + request: Union[vizier_service.ListTrialsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListTrialsPager: r"""Lists the Trials associated with a Study. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_list_trials(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListTrialsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_trials(request=request) + + # Handle the response + for response in page_result: + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ListTrialsRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ListTrialsRequest, dict]): The request object. Request message for [VizierService.ListTrials][google.cloud.aiplatform.v1beta1.VizierService.ListTrials]. parent (str): @@ -1009,7 +1340,7 @@ def list_trials( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1040,12 +1371,20 @@ def list_trials( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + 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.ListTrialsPager( - method=rpc, request=request, response=response, metadata=metadata, + method=rpc, + request=request, + response=response, + metadata=metadata, ) # Done; return the response. @@ -1053,9 +1392,9 @@ def list_trials( def add_trial_measurement( self, - request: vizier_service.AddTrialMeasurementRequest = None, + request: Union[vizier_service.AddTrialMeasurementRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> study.Trial: @@ -1063,8 +1402,27 @@ def add_trial_measurement( Trial. This measurement is assumed to have been taken before the Trial is complete. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_add_trial_measurement(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.AddTrialMeasurementRequest( + trial_name="trial_name_value", + ) + + # Make the request + response = client.add_trial_measurement(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.AddTrialMeasurementRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.AddTrialMeasurementRequest, dict]): The request object. Request message for [VizierService.AddTrialMeasurement][google.cloud.aiplatform.v1beta1.VizierService.AddTrialMeasurement]. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -1103,23 +1461,47 @@ def add_trial_measurement( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def complete_trial( self, - request: vizier_service.CompleteTrialRequest = None, + request: Union[vizier_service.CompleteTrialRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> study.Trial: r"""Marks a Trial as complete. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_complete_trial(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CompleteTrialRequest( + name="name_value", + ) + + # Make the request + response = client.complete_trial(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.CompleteTrialRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.CompleteTrialRequest, dict]): The request object. Request message for [VizierService.CompleteTrial][google.cloud.aiplatform.v1beta1.VizierService.CompleteTrial]. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -1156,24 +1538,45 @@ def complete_trial( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def delete_trial( self, - request: vizier_service.DeleteTrialRequest = None, + request: Union[vizier_service.DeleteTrialRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Deletes a Trial. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_delete_trial(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteTrialRequest( + name="name_value", + ) + + # Make the request + client.delete_trial(request=request) + Args: - request (google.cloud.aiplatform_v1beta1.types.DeleteTrialRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.DeleteTrialRequest, dict]): The request object. Request message for [VizierService.DeleteTrial][google.cloud.aiplatform.v1beta1.VizierService.DeleteTrial]. name (str): @@ -1190,7 +1593,7 @@ def delete_trial( 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 + # Quick 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: @@ -1222,14 +1625,17 @@ def delete_trial( # Send the request. rpc( - request, retry=retry, timeout=timeout, metadata=metadata, + request, + retry=retry, + timeout=timeout, + metadata=metadata, ) def check_trial_early_stopping_state( self, - request: vizier_service.CheckTrialEarlyStoppingStateRequest = None, + request: Union[vizier_service.CheckTrialEarlyStoppingStateRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation.Operation: @@ -1238,8 +1644,31 @@ def check_trial_early_stopping_state( will contain a [CheckTrialEarlyStoppingStateResponse][google.cloud.ml.v1.CheckTrialEarlyStoppingStateResponse]. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_check_trial_early_stopping_state(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CheckTrialEarlyStoppingStateRequest( + trial_name="trial_name_value", + ) + + # Make the request + operation = client.check_trial_early_stopping_state(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.CheckTrialEarlyStoppingStateRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.CheckTrialEarlyStoppingStateRequest, dict]): The request object. Request message for [VizierService.CheckTrialEarlyStoppingState][google.cloud.aiplatform.v1beta1.VizierService.CheckTrialEarlyStoppingState]. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -1281,7 +1710,12 @@ def check_trial_early_stopping_state( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Wrap the response in an operation future. response = operation.from_gapic( @@ -1296,16 +1730,35 @@ def check_trial_early_stopping_state( def stop_trial( self, - request: vizier_service.StopTrialRequest = None, + request: Union[vizier_service.StopTrialRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> study.Trial: r"""Stops a Trial. + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_stop_trial(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.StopTrialRequest( + name="name_value", + ) + + # Make the request + response = client.stop_trial(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.StopTrialRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.StopTrialRequest, dict]): The request object. Request message for [VizierService.StopTrial][google.cloud.aiplatform.v1beta1.VizierService.StopTrial]. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -1342,17 +1795,22 @@ def stop_trial( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response def list_optimal_trials( self, - request: vizier_service.ListOptimalTrialsRequest = None, + request: Union[vizier_service.ListOptimalTrialsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> vizier_service.ListOptimalTrialsResponse: @@ -1361,8 +1819,27 @@ def list_optimal_trials( pareto-optimal can be checked in wiki page. https://en.wikipedia.org/wiki/Pareto_efficiency + .. code-block:: python + + from google.cloud import aiplatform_v1beta1 + + def sample_list_optimal_trials(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListOptimalTrialsRequest( + parent="parent_value", + ) + + # Make the request + response = client.list_optimal_trials(request=request) + + # Handle the response + print(response) + Args: - request (google.cloud.aiplatform_v1beta1.types.ListOptimalTrialsRequest): + request (Union[google.cloud.aiplatform_v1beta1.types.ListOptimalTrialsRequest, dict]): The request object. Request message for [VizierService.ListOptimalTrials][google.cloud.aiplatform.v1beta1.VizierService.ListOptimalTrials]. parent (str): @@ -1385,7 +1862,7 @@ def list_optimal_trials( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick 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: @@ -1416,7 +1893,696 @@ def list_optimal_trials( ) # Send the request. - response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def __enter__(self): + return self + + def __exit__(self, type, value, traceback): + """Releases underlying transport's resources. + + .. warning:: + ONLY use as a context manager if the transport is NOT shared + with other clients! Exiting the with block will CLOSE the transport + and may cause errors in other clients! + """ + self.transport.close() + + def list_operations( + self, + request: operations_pb2.ListOperationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.ListOperationsResponse: + r"""Lists operations that match the specified filter in the request. + + Args: + request (:class:`~.operations_pb2.ListOperationsRequest`): + The request object. Request message for + `ListOperations` method. + 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: + ~.operations_pb2.ListOperationsResponse: + Response message for ``ListOperations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.ListOperationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_operations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_operation( + self, + request: operations_pb2.GetOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Gets the latest state of a long-running operation. + + Args: + request (:class:`~.operations_pb2.GetOperationRequest`): + The request object. Request message for + `GetOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.GetOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_operation( + self, + request: operations_pb2.DeleteOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a long-running operation. + + This method indicates that the client is no longer interested + in the operation result. It does not cancel the operation. + If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.DeleteOperationRequest`): + The request object. Request message for + `DeleteOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.DeleteOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.delete_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def cancel_operation( + self, + request: operations_pb2.CancelOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Starts asynchronous cancellation on a long-running operation. + + The server makes a best effort to cancel the operation, but success + is not guaranteed. If the server doesn't support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.CancelOperationRequest`): + The request object. Request message for + `CancelOperation` method. + 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: + None + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.CancelOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.cancel_operation, + default_timeout=None, + 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. + rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + def wait_operation( + self, + request: operations_pb2.WaitOperationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> operations_pb2.Operation: + r"""Waits until the specified long-running operation is done or reaches at most + a specified timeout, returning the latest state. + + If the operation is already done, the latest state is immediately returned. + If the timeout specified is greater than the default HTTP/RPC timeout, the HTTP/RPC + timeout is used. If the server does not support this method, it returns + `google.rpc.Code.UNIMPLEMENTED`. + + Args: + request (:class:`~.operations_pb2.WaitOperationRequest`): + The request object. Request message for + `WaitOperation` method. + 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: + ~.operations_pb2.Operation: + An ``Operation`` object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = operations_pb2.WaitOperationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.wait_operation, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def set_iam_policy( + self, + request: iam_policy_pb2.SetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Sets the IAM access control policy on the specified function. + + Replaces any existing policy. + + Args: + request (:class:`~.iam_policy_pb2.SetIamPolicyRequest`): + The request object. Request message for `SetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.SetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.set_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_iam_policy( + self, + request: iam_policy_pb2.GetIamPolicyRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> policy_pb2.Policy: + r"""Gets the IAM access control policy for a function. + + Returns an empty policy if the function exists and does not have a + policy set. + + Args: + request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`): + The request object. Request message for `GetIamPolicy` + method. + 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: + ~.policy_pb2.Policy: + Defines an Identity and Access Management (IAM) policy. + It is used to specify access control policies for Cloud + Platform resources. + A ``Policy`` is a collection of ``bindings``. A + ``binding`` binds one or more ``members`` to a single + ``role``. Members can be user accounts, service + accounts, Google groups, and domains (such as G Suite). + A ``role`` is a named list of permissions (defined by + IAM or configured by users). A ``binding`` can + optionally specify a ``condition``, which is a logic + expression that further constrains the role binding + based on attributes about the request and/or target + resource. + **JSON Example** + :: + { + "bindings": [ + { + "role": "roles/resourcemanager.organizationAdmin", + "members": [ + "user:mike@example.com", + "group:admins@example.com", + "domain:google.com", + "serviceAccount:my-project-id@appspot.gserviceaccount.com" + ] + }, + { + "role": "roles/resourcemanager.organizationViewer", + "members": ["user:eve@example.com"], + "condition": { + "title": "expirable access", + "description": "Does not grant access after Sep 2020", + "expression": "request.time < + timestamp('2020-10-01T00:00:00.000Z')", + } + } + ] + } + **YAML Example** + :: + bindings: + - members: + - user:mike@example.com + - group:admins@example.com + - domain:google.com + - serviceAccount:my-project-id@appspot.gserviceaccount.com + role: roles/resourcemanager.organizationAdmin + - members: + - user:eve@example.com + role: roles/resourcemanager.organizationViewer + condition: + title: expirable access + description: Does not grant access after Sep 2020 + expression: request.time < timestamp('2020-10-01T00:00:00.000Z') + For a description of IAM and its features, see the `IAM + developer's + guide `__. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.GetIamPolicyRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_iam_policy, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def test_iam_permissions( + self, + request: iam_policy_pb2.TestIamPermissionsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> iam_policy_pb2.TestIamPermissionsResponse: + r"""Tests the specified IAM permissions against the IAM access control + policy for a function. + + If the function does not exist, this will return an empty set + of permissions, not a NOT_FOUND error. + + Args: + request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`): + The request object. Request message for + `TestIamPermissions` method. + 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: + ~.iam_policy_pb2.TestIamPermissionsResponse: + Response message for ``TestIamPermissions`` method. + """ + # Create or coerce a protobuf request object. + + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = iam_policy_pb2.TestIamPermissionsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.test_iam_permissions, + default_timeout=None, + 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((("resource", request.resource),)), + ) + + # Send the request. + response = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def get_location( + self, + request: locations_pb2.GetLocationRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.Location: + r"""Gets information about a location. + + Args: + request (:class:`~.location_pb2.GetLocationRequest`): + The request object. Request message for + `GetLocation` method. + 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: + ~.location_pb2.Location: + Location object. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.GetLocationRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.get_location, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) + + # Done; return the response. + return response + + def list_locations( + self, + request: locations_pb2.ListLocationsRequest = None, + *, + retry: OptionalRetry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> locations_pb2.ListLocationsResponse: + r"""Lists information about the supported locations for this service. + + Args: + request (:class:`~.location_pb2.ListLocationsRequest`): + The request object. Request message for + `ListLocations` method. + 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: + ~.location_pb2.ListLocationsResponse: + Response message for ``ListLocations`` method. + """ + # Create or coerce a protobuf request object. + # The request isn't a proto-plus wrapped type, + # so it must be constructed via keyword expansion. + if isinstance(request, dict): + request = locations_pb2.ListLocationsRequest(**request) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method.wrap_method( + self._transport.list_locations, + default_timeout=None, + 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 = rpc( + request, + retry=retry, + timeout=timeout, + metadata=metadata, + ) # Done; return the response. return response diff --git a/google/cloud/aiplatform_v1beta1/services/vizier_service/pagers.py b/google/cloud/aiplatform_v1beta1/services/vizier_service/pagers.py index 39d956e6be..4261312e22 100644 --- a/google/cloud/aiplatform_v1beta1/services/vizier_service/pagers.py +++ b/google/cloud/aiplatform_v1beta1/services/vizier_service/pagers.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,13 +15,13 @@ # from typing import ( Any, - AsyncIterable, + AsyncIterator, Awaitable, Callable, - Iterable, Sequence, Tuple, Optional, + Iterator, ) from google.cloud.aiplatform_v1beta1.types import study @@ -75,14 +75,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[vizier_service.ListStudiesResponse]: + def pages(self) -> Iterator[vizier_service.ListStudiesResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[study.Study]: + def __iter__(self) -> Iterator[study.Study]: for page in self.pages: yield from page.studies @@ -116,7 +116,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -137,14 +137,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - async def pages(self) -> AsyncIterable[vizier_service.ListStudiesResponse]: + async def pages(self) -> AsyncIterator[vizier_service.ListStudiesResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[study.Study]: + def __aiter__(self) -> AsyncIterator[study.Study]: async def async_generator(): async for page in self.pages: for response in page.studies: @@ -203,14 +203,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - def pages(self) -> Iterable[vizier_service.ListTrialsResponse]: + def pages(self) -> Iterator[vizier_service.ListTrialsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = self._method(self._request, metadata=self._metadata) yield self._response - def __iter__(self) -> Iterable[study.Trial]: + def __iter__(self) -> Iterator[study.Trial]: for page in self.pages: yield from page.trials @@ -244,7 +244,7 @@ def __init__( *, metadata: Sequence[Tuple[str, str]] = () ): - """Instantiate the pager. + """Instantiates the pager. Args: method (Callable): The method that was originally called, and @@ -265,14 +265,14 @@ def __getattr__(self, name: str) -> Any: return getattr(self._response, name) @property - async def pages(self) -> AsyncIterable[vizier_service.ListTrialsResponse]: + async def pages(self) -> AsyncIterator[vizier_service.ListTrialsResponse]: yield self._response while self._response.next_page_token: self._request.page_token = self._response.next_page_token self._response = await self._method(self._request, metadata=self._metadata) yield self._response - def __aiter__(self) -> AsyncIterable[study.Trial]: + def __aiter__(self) -> AsyncIterator[study.Trial]: async def async_generator(): async for page in self.pages: for response in page.trials: diff --git a/google/cloud/aiplatform_v1beta1/services/vizier_service/transports/__init__.py b/google/cloud/aiplatform_v1beta1/services/vizier_service/transports/__init__.py index 4fdc0272ee..a4efbdf8d6 100644 --- a/google/cloud/aiplatform_v1beta1/services/vizier_service/transports/__init__.py +++ b/google/cloud/aiplatform_v1beta1/services/vizier_service/transports/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/google/cloud/aiplatform_v1beta1/services/vizier_service/transports/base.py b/google/cloud/aiplatform_v1beta1/services/vizier_service/transports/base.py index 45cd82c0ab..f4450daefc 100644 --- a/google/cloud/aiplatform_v1beta1/services/vizier_service/transports/base.py +++ b/google/cloud/aiplatform_v1beta1/services/vizier_service/transports/base.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,20 +15,24 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore -import google.api_core # type: ignore -from google.api_core import exceptions as core_exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.api_core import operations_v1 # type: ignore +import google.api_core +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import retry as retries +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore +from google.oauth2 import service_account # type: ignore from google.cloud.aiplatform_v1beta1.types import study from google.cloud.aiplatform_v1beta1.types import study as gca_study from google.cloud.aiplatform_v1beta1.types import vizier_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from google.protobuf import empty_pb2 # type: ignore @@ -41,17 +45,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - -_API_CORE_VERSION = google.api_core.__version__ - class VizierServiceTransport(abc.ABC): """Abstract transport class for VizierService.""" @@ -69,6 +62,7 @@ def __init__( scopes: Optional[Sequence[str]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, **kwargs, ) -> None: """Instantiate the transport. @@ -92,16 +86,19 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. """ + # Save the hostname. Default to port 443 (HTTPS) if none is specified. if ":" not in host: host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. - self._scopes = scopes or self.AUTH_SCOPES + self._scopes = scopes # If no credentials are provided, then determine the appropriate # defaults. @@ -114,89 +111,69 @@ def __init__( credentials, _ = google.auth.load_credentials_from_file( credentials_file, **scopes_kwargs, quota_project_id=quota_project_id ) - elif credentials is None: credentials, _ = google.auth.default( **scopes_kwargs, quota_project_id=quota_project_id ) - # Save the credentials. - self._credentials = credentials - - # TODO(busunkim): These two class methods are in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-api-core - # and google-auth are increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") + # If the credentials are service account credentials, then always try to use self signed JWT. + if ( + always_use_jwt_access + and isinstance(credentials, service_account.Credentials) + and hasattr(service_account.Credentials, "with_always_use_jwt_access") ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs + credentials = credentials.with_always_use_jwt_access(True) - # TODO: Remove this function once google-api-core >= 1.26.0 is required - @classmethod - def _get_self_signed_jwt_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Union[Optional[Sequence[str]], str]]: - """Returns kwargs to pass to grpc_helpers.create_channel depending on the google-api-core version""" - - self_signed_jwt_kwargs: Dict[str, Union[Optional[Sequence[str]], str]] = {} - - if _API_CORE_VERSION and ( - packaging.version.parse(_API_CORE_VERSION) - >= packaging.version.parse("1.26.0") - ): - self_signed_jwt_kwargs["default_scopes"] = cls.AUTH_SCOPES - self_signed_jwt_kwargs["scopes"] = scopes - self_signed_jwt_kwargs["default_host"] = cls.DEFAULT_HOST - else: - self_signed_jwt_kwargs["scopes"] = scopes or cls.AUTH_SCOPES - - return self_signed_jwt_kwargs + # Save the credentials. + self._credentials = credentials def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { self.create_study: gapic_v1.method.wrap_method( - self.create_study, default_timeout=5.0, client_info=client_info, + self.create_study, + default_timeout=5.0, + client_info=client_info, ), self.get_study: gapic_v1.method.wrap_method( - self.get_study, default_timeout=5.0, client_info=client_info, + self.get_study, + default_timeout=5.0, + client_info=client_info, ), self.list_studies: gapic_v1.method.wrap_method( - self.list_studies, default_timeout=5.0, client_info=client_info, + self.list_studies, + default_timeout=5.0, + client_info=client_info, ), self.delete_study: gapic_v1.method.wrap_method( - self.delete_study, default_timeout=5.0, client_info=client_info, + self.delete_study, + default_timeout=5.0, + client_info=client_info, ), self.lookup_study: gapic_v1.method.wrap_method( - self.lookup_study, default_timeout=5.0, client_info=client_info, + self.lookup_study, + default_timeout=5.0, + client_info=client_info, ), self.suggest_trials: gapic_v1.method.wrap_method( - self.suggest_trials, default_timeout=5.0, client_info=client_info, + self.suggest_trials, + default_timeout=5.0, + client_info=client_info, ), self.create_trial: gapic_v1.method.wrap_method( - self.create_trial, default_timeout=5.0, client_info=client_info, + self.create_trial, + default_timeout=5.0, + client_info=client_info, ), self.get_trial: gapic_v1.method.wrap_method( - self.get_trial, default_timeout=5.0, client_info=client_info, + self.get_trial, + default_timeout=5.0, + client_info=client_info, ), self.list_trials: gapic_v1.method.wrap_method( - self.list_trials, default_timeout=5.0, client_info=client_info, + self.list_trials, + default_timeout=5.0, + client_info=client_info, ), self.add_trial_measurement: gapic_v1.method.wrap_method( self.add_trial_measurement, @@ -204,10 +181,14 @@ def _prep_wrapped_messages(self, client_info): client_info=client_info, ), self.complete_trial: gapic_v1.method.wrap_method( - self.complete_trial, default_timeout=5.0, client_info=client_info, + self.complete_trial, + default_timeout=5.0, + client_info=client_info, ), self.delete_trial: gapic_v1.method.wrap_method( - self.delete_trial, default_timeout=5.0, client_info=client_info, + self.delete_trial, + default_timeout=5.0, + client_info=client_info, ), self.check_trial_early_stopping_state: gapic_v1.method.wrap_method( self.check_trial_early_stopping_state, @@ -215,15 +196,28 @@ def _prep_wrapped_messages(self, client_info): client_info=client_info, ), self.stop_trial: gapic_v1.method.wrap_method( - self.stop_trial, default_timeout=5.0, client_info=client_info, + self.stop_trial, + default_timeout=5.0, + client_info=client_info, ), self.list_optimal_trials: gapic_v1.method.wrap_method( - self.list_optimal_trials, default_timeout=5.0, client_info=client_info, + self.list_optimal_trials, + default_timeout=5.0, + client_info=client_info, ), } + def close(self): + """Closes resources associated with the transport. + + .. warning:: + Only call this method if the transport is NOT shared + with other clients - this may cause errors in other clients! + """ + raise NotImplementedError() + @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() @@ -366,5 +360,102 @@ def list_optimal_trials( ]: raise NotImplementedError() + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], + Union[ + operations_pb2.ListOperationsResponse, + Awaitable[operations_pb2.ListOperationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_operation( + self, + ) -> Callable[ + [operations_pb2.GetOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None,]: + raise NotImplementedError() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None,]: + raise NotImplementedError() + + @property + def wait_operation( + self, + ) -> Callable[ + [operations_pb2.WaitOperationRequest], + Union[operations_pb2.Operation, Awaitable[operations_pb2.Operation]], + ]: + raise NotImplementedError() + + @property + def set_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.SetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def get_iam_policy( + self, + ) -> Callable[ + [iam_policy_pb2.GetIamPolicyRequest], + Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]], + ]: + raise NotImplementedError() + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + Union[ + iam_policy_pb2.TestIamPermissionsResponse, + Awaitable[iam_policy_pb2.TestIamPermissionsResponse], + ], + ]: + raise NotImplementedError() + + @property + def get_location( + self, + ) -> Callable[ + [locations_pb2.GetLocationRequest], + Union[locations_pb2.Location, Awaitable[locations_pb2.Location]], + ]: + raise NotImplementedError() + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], + Union[ + locations_pb2.ListLocationsResponse, + Awaitable[locations_pb2.ListLocationsResponse], + ], + ]: + raise NotImplementedError() + + @property + def kind(self) -> str: + raise NotImplementedError() + __all__ = ("VizierServiceTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/vizier_service/transports/grpc.py b/google/cloud/aiplatform_v1beta1/services/vizier_service/transports/grpc.py index 48aac6a6c1..fd76a37ca3 100644 --- a/google/cloud/aiplatform_v1beta1/services/vizier_service/transports/grpc.py +++ b/google/cloud/aiplatform_v1beta1/services/vizier_service/transports/grpc.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,9 +16,9 @@ import warnings from typing import Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import grpc_helpers # type: ignore -from google.api_core import operations_v1 # type: ignore -from google.api_core import gapic_v1 # type: ignore +from google.api_core import grpc_helpers +from google.api_core import operations_v1 +from google.api_core import gapic_v1 import google.auth # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore @@ -28,6 +28,10 @@ from google.cloud.aiplatform_v1beta1.types import study from google.cloud.aiplatform_v1beta1.types import study as gca_study from google.cloud.aiplatform_v1beta1.types import vizier_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from google.protobuf import empty_pb2 # type: ignore from .base import VizierServiceTransport, DEFAULT_CLIENT_INFO @@ -36,8 +40,8 @@ class VizierServiceGrpcTransport(VizierServiceTransport): """gRPC backend transport for VizierService. - Cloud AI Platform Vizier API. - Vizier service is a GCP service to solve blackbox optimization + Vertex AI Vizier API. + Vertex AI Vizier is a service to solve blackbox optimization problems, such as tuning machine learning hyperparameters and searching over deep learning architectures. @@ -65,6 +69,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id: Optional[str] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -87,16 +92,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -105,6 +110,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport @@ -115,7 +122,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -158,13 +165,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -213,21 +224,20 @@ def create_channel( and ``credentials_file`` are passed. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @property def grpc_channel(self) -> grpc.Channel: - """Return the channel designed to connect to this service. - """ + """Return the channel designed to connect to this service.""" return self._grpc_channel @property @@ -237,7 +247,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsClient(self.grpc_channel) @@ -384,9 +394,9 @@ def suggest_trials( r"""Return a callable for the suggest trials method over gRPC. Adds one or more Trials to a Study, with parameter values - suggested by AI Platform Vizier. Returns a long-running - operation associated with the generation of Trial suggestions. - When this long-running operation succeeds, it will contain a + suggested by Vertex AI Vizier. Returns a long-running operation + associated with the generation of Trial suggestions. When this + long-running operation succeeds, it will contain a [SuggestTrialsResponse][google.cloud.ml.v1.SuggestTrialsResponse]. Returns: @@ -655,5 +665,215 @@ def list_optimal_trials( ) return self._stubs["list_optimal_trials"] + def close(self): + self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + + @property + def kind(self) -> str: + return "grpc" + __all__ = ("VizierServiceGrpcTransport",) diff --git a/google/cloud/aiplatform_v1beta1/services/vizier_service/transports/grpc_asyncio.py b/google/cloud/aiplatform_v1beta1/services/vizier_service/transports/grpc_asyncio.py index f26ef1a02c..e630286551 100644 --- a/google/cloud/aiplatform_v1beta1/services/vizier_service/transports/grpc_asyncio.py +++ b/google/cloud/aiplatform_v1beta1/services/vizier_service/transports/grpc_asyncio.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,12 +16,11 @@ import warnings from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union -from google.api_core import gapic_v1 # type: ignore -from google.api_core import grpc_helpers_async # type: ignore -from google.api_core import operations_v1 # type: ignore +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers_async +from google.api_core import operations_v1 from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore @@ -29,6 +28,10 @@ from google.cloud.aiplatform_v1beta1.types import study from google.cloud.aiplatform_v1beta1.types import study as gca_study from google.cloud.aiplatform_v1beta1.types import vizier_service +from google.cloud.location import locations_pb2 # type: ignore +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.longrunning import operations_pb2 # type: ignore from google.protobuf import empty_pb2 # type: ignore from .base import VizierServiceTransport, DEFAULT_CLIENT_INFO @@ -38,8 +41,8 @@ class VizierServiceGrpcAsyncIOTransport(VizierServiceTransport): """gRPC AsyncIO backend transport for VizierService. - Cloud AI Platform Vizier API. - Vizier service is a GCP service to solve blackbox optimization + Vertex AI Vizier API. + Vertex AI Vizier is a service to solve blackbox optimization problems, such as tuning machine learning hyperparameters and searching over deep learning architectures. @@ -86,14 +89,14 @@ def create_channel( aio.Channel: A gRPC AsyncIO channel object. """ - self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes) - return grpc_helpers_async.create_channel( host, credentials=credentials, credentials_file=credentials_file, quota_project_id=quota_project_id, - **self_signed_jwt_kwargs, + default_scopes=cls.AUTH_SCOPES, + scopes=scopes, + default_host=cls.DEFAULT_HOST, **kwargs, ) @@ -111,6 +114,7 @@ def __init__( client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None, quota_project_id=None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + always_use_jwt_access: Optional[bool] = False, ) -> None: """Instantiate the transport. @@ -134,16 +138,16 @@ def __init__( api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint. If provided, it overrides the ``host`` argument and tries to create a mutual TLS channel with client SSL credentials from - ``client_cert_source`` or applicatin default SSL credentials. + ``client_cert_source`` or application default SSL credentials. client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]): Deprecated. A callback to provide client SSL certificate bytes and private key bytes, both in PEM format. It is ignored if ``api_mtls_endpoint`` is None. ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials - for grpc channel. It is ignored if ``channel`` is provided. + for the grpc channel. It is ignored if ``channel`` is provided. client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]): A callback to provide client certificate bytes and private key bytes, - both in PEM format. It is used to configure mutual TLS channel. It is + both in PEM format. It is used to configure a mutual TLS channel. It is ignored if ``channel`` or ``ssl_channel_credentials`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. @@ -152,6 +156,8 @@ def __init__( API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. + always_use_jwt_access (Optional[bool]): Whether self signed JWT should + be used for service account credentials. Raises: google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport @@ -162,7 +168,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) @@ -204,13 +210,17 @@ def __init__( scopes=scopes, quota_project_id=quota_project_id, client_info=client_info, + always_use_jwt_access=always_use_jwt_access, ) if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -240,7 +250,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel @@ -394,9 +404,9 @@ def suggest_trials( r"""Return a callable for the suggest trials method over gRPC. Adds one or more Trials to a Study, with parameter values - suggested by AI Platform Vizier. Returns a long-running - operation associated with the generation of Trial suggestions. - When this long-running operation succeeds, it will contain a + suggested by Vertex AI Vizier. Returns a long-running operation + associated with the generation of Trial suggestions. When this + long-running operation succeeds, it will contain a [SuggestTrialsResponse][google.cloud.ml.v1.SuggestTrialsResponse]. Returns: @@ -670,5 +680,211 @@ def list_optimal_trials( ) return self._stubs["list_optimal_trials"] + def close(self): + return self.grpc_channel.close() + + @property + def delete_operation( + self, + ) -> Callable[[operations_pb2.DeleteOperationRequest], None]: + r"""Return a callable for the delete_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["delete_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/DeleteOperation", + request_serializer=operations_pb2.DeleteOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["delete_operation"] + + @property + def cancel_operation( + self, + ) -> Callable[[operations_pb2.CancelOperationRequest], None]: + r"""Return a callable for the cancel_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "cancel_operation" not in self._stubs: + self._stubs["cancel_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/CancelOperation", + request_serializer=operations_pb2.CancelOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["cancel_operation"] + + @property + def wait_operation( + self, + ) -> Callable[[operations_pb2.WaitOperationRequest], None]: + r"""Return a callable for the wait_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "delete_operation" not in self._stubs: + self._stubs["wait_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/WaitOperation", + request_serializer=operations_pb2.WaitOperationRequest.SerializeToString, + response_deserializer=None, + ) + return self._stubs["wait_operation"] + + @property + def get_operation( + self, + ) -> Callable[[operations_pb2.GetOperationRequest], operations_pb2.Operation]: + r"""Return a callable for the get_operation method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_operation" not in self._stubs: + self._stubs["get_operation"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/GetOperation", + request_serializer=operations_pb2.GetOperationRequest.SerializeToString, + response_deserializer=operations_pb2.Operation.FromString, + ) + return self._stubs["get_operation"] + + @property + def list_operations( + self, + ) -> Callable[ + [operations_pb2.ListOperationsRequest], operations_pb2.ListOperationsResponse + ]: + r"""Return a callable for the list_operations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_operations" not in self._stubs: + self._stubs["list_operations"] = self.grpc_channel.unary_unary( + "/google.longrunning.Operations/ListOperations", + request_serializer=operations_pb2.ListOperationsRequest.SerializeToString, + response_deserializer=operations_pb2.ListOperationsResponse.FromString, + ) + return self._stubs["list_operations"] + + @property + def list_locations( + self, + ) -> Callable[ + [locations_pb2.ListLocationsRequest], locations_pb2.ListLocationsResponse + ]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "list_locations" not in self._stubs: + self._stubs["list_locations"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/ListLocations", + request_serializer=locations_pb2.ListLocationsRequest.SerializeToString, + response_deserializer=locations_pb2.ListLocationsResponse.FromString, + ) + return self._stubs["list_locations"] + + @property + def get_location( + self, + ) -> Callable[[locations_pb2.GetLocationRequest], locations_pb2.Location]: + r"""Return a callable for the list locations method over gRPC.""" + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_location" not in self._stubs: + self._stubs["get_location"] = self.grpc_channel.unary_unary( + "/google.cloud.location.Locations/GetLocation", + request_serializer=locations_pb2.GetLocationRequest.SerializeToString, + response_deserializer=locations_pb2.Location.FromString, + ) + return self._stubs["get_location"] + + @property + def set_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.SetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the set iam policy method over gRPC. + Sets the IAM access control policy on the specified + function. Replaces any existing policy. + Returns: + Callable[[~.SetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "set_iam_policy" not in self._stubs: + self._stubs["set_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/SetIamPolicy", + request_serializer=iam_policy_pb2.SetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["set_iam_policy"] + + @property + def get_iam_policy( + self, + ) -> Callable[[iam_policy_pb2.GetIamPolicyRequest], policy_pb2.Policy]: + r"""Return a callable for the get iam policy method over gRPC. + Gets the IAM access control policy for a function. + Returns an empty policy if the function exists and does + not have a policy set. + Returns: + Callable[[~.GetIamPolicyRequest], + ~.Policy]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "get_iam_policy" not in self._stubs: + self._stubs["get_iam_policy"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/GetIamPolicy", + request_serializer=iam_policy_pb2.GetIamPolicyRequest.SerializeToString, + response_deserializer=policy_pb2.Policy.FromString, + ) + return self._stubs["get_iam_policy"] + + @property + def test_iam_permissions( + self, + ) -> Callable[ + [iam_policy_pb2.TestIamPermissionsRequest], + iam_policy_pb2.TestIamPermissionsResponse, + ]: + r"""Return a callable for the test iam permissions method over gRPC. + Tests the specified permissions against the IAM access control + policy for a function. If the function does not exist, this will + return an empty set of permissions, not a NOT_FOUND error. + Returns: + Callable[[~.TestIamPermissionsRequest], + ~.TestIamPermissionsResponse]: + A function that, when called, will call the underlying RPC + on the server. + """ + # Generate a "stub function" on-the-fly which will actually make + # the request. + # gRPC handles serialization and deserialization, so we just need + # to pass in the functions for each. + if "test_iam_permissions" not in self._stubs: + self._stubs["test_iam_permissions"] = self.grpc_channel.unary_unary( + "/google.iam.v1.IAMPolicy/TestIamPermissions", + request_serializer=iam_policy_pb2.TestIamPermissionsRequest.SerializeToString, + response_deserializer=iam_policy_pb2.TestIamPermissionsResponse.FromString, + ) + return self._stubs["test_iam_permissions"] + __all__ = ("VizierServiceGrpcAsyncIOTransport",) diff --git a/google/cloud/aiplatform_v1beta1/types/__init__.py b/google/cloud/aiplatform_v1beta1/types/__init__.py index 7b54b4f06d..825150ea23 100644 --- a/google/cloud/aiplatform_v1beta1/types/__init__.py +++ b/google/cloud/aiplatform_v1beta1/types/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,12 +13,24 @@ # See the License for the specific language governing permissions and # limitations under the License. # -from .annotation import Annotation -from .annotation_spec import AnnotationSpec -from .artifact import Artifact -from .batch_prediction_job import BatchPredictionJob -from .completion_stats import CompletionStats -from .context import Context +from .annotation import ( + Annotation, +) +from .annotation_spec import ( + AnnotationSpec, +) +from .artifact import ( + Artifact, +) +from .batch_prediction_job import ( + BatchPredictionJob, +) +from .completion_stats import ( + CompletionStats, +) +from .context import ( + Context, +) from .custom_job import ( ContainerSpec, CustomJob, @@ -27,7 +39,9 @@ Scheduling, WorkerPoolSpec, ) -from .data_item import DataItem +from .data_item import ( + DataItem, +) from .data_labeling_job import ( ActiveLearningConfig, DataLabelingJob, @@ -59,12 +73,20 @@ ListDatasetsResponse, UpdateDatasetRequest, ) -from .deployed_index_ref import DeployedIndexRef -from .deployed_model_ref import DeployedModelRef -from .encryption_spec import EncryptionSpec +from .deployed_index_ref import ( + DeployedIndexRef, +) +from .deployed_model_ref import ( + DeployedModelRef, +) +from .encryption_spec import ( + EncryptionSpec, +) from .endpoint import ( DeployedModel, Endpoint, + PredictRequestResponseLoggingConfig, + PrivateEndpoints, ) from .endpoint_service import ( CreateEndpointOperationMetadata, @@ -81,12 +103,24 @@ UndeployModelResponse, UpdateEndpointRequest, ) -from .entity_type import EntityType -from .env_var import EnvVar -from .event import Event -from .execution import Execution +from .entity_type import ( + EntityType, +) +from .env_var import ( + EnvVar, +) +from .event import ( + Event, +) +from .execution import ( + Execution, +) from .explanation import ( Attribution, + BlurBaselineConfig, + Examples, + ExamplesOverride, + ExamplesRestrictionsNamespace, Explanation, ExplanationMetadataOverride, ExplanationParameters, @@ -95,19 +129,31 @@ FeatureNoiseSigma, IntegratedGradientsAttribution, ModelExplanation, + Neighbor, + Presets, SampledShapleyAttribution, SmoothGradConfig, XraiAttribution, ) -from .explanation_metadata import ExplanationMetadata -from .feature import Feature -from .feature_monitoring_stats import FeatureStatsAnomaly +from .explanation_metadata import ( + ExplanationMetadata, +) +from .feature import ( + Feature, +) +from .feature_monitoring_stats import ( + FeatureStatsAnomaly, +) from .feature_selector import ( FeatureSelector, IdMatcher, ) -from .featurestore import Featurestore -from .featurestore_monitoring import FeaturestoreMonitoringConfig +from .featurestore import ( + Featurestore, +) +from .featurestore_monitoring import ( + FeaturestoreMonitoringConfig, +) from .featurestore_online_service import ( FeatureValue, FeatureValueList, @@ -155,8 +201,12 @@ UpdateFeaturestoreOperationMetadata, UpdateFeaturestoreRequest, ) -from .hyperparameter_tuning_job import HyperparameterTuningJob -from .index import Index +from .hyperparameter_tuning_job import ( + HyperparameterTuningJob, +) +from .index import ( + Index, +) from .index_endpoint import ( DeployedIndex, DeployedIndexAuthConfig, @@ -173,6 +223,9 @@ GetIndexEndpointRequest, ListIndexEndpointsRequest, ListIndexEndpointsResponse, + MutateDeployedIndexOperationMetadata, + MutateDeployedIndexRequest, + MutateDeployedIndexResponse, UndeployIndexOperationMetadata, UndeployIndexRequest, UndeployIndexResponse, @@ -237,7 +290,9 @@ UpdateModelDeploymentMonitoringJobOperationMetadata, UpdateModelDeploymentMonitoringJobRequest, ) -from .lineage_subgraph import LineageSubgraph +from .lineage_subgraph import ( + LineageSubgraph, +) from .machine_resources import ( AutomaticResources, AutoscalingMetricSpec, @@ -245,10 +300,15 @@ DedicatedResources, DiskSpec, MachineSpec, + NfsMount, ResourcesConsumed, ) -from .manual_batch_tuning_parameters import ManualBatchTuningParameters -from .metadata_schema import MetadataSchema +from .manual_batch_tuning_parameters import ( + ManualBatchTuningParameters, +) +from .metadata_schema import ( + MetadataSchema, +) from .metadata_service import ( AddContextArtifactsAndExecutionsRequest, AddContextArtifactsAndExecutionsResponse, @@ -262,7 +322,9 @@ CreateMetadataSchemaRequest, CreateMetadataStoreOperationMetadata, CreateMetadataStoreRequest, + DeleteArtifactRequest, DeleteContextRequest, + DeleteExecutionRequest, DeleteMetadataStoreOperationMetadata, DeleteMetadataStoreRequest, GetArtifactRequest, @@ -280,6 +342,15 @@ ListMetadataSchemasResponse, ListMetadataStoresRequest, ListMetadataStoresResponse, + PurgeArtifactsMetadata, + PurgeArtifactsRequest, + PurgeArtifactsResponse, + PurgeContextsMetadata, + PurgeContextsRequest, + PurgeContextsResponse, + PurgeExecutionsMetadata, + PurgeExecutionsRequest, + PurgeExecutionsResponse, QueryArtifactLineageSubgraphRequest, QueryContextLineageSubgraphRequest, QueryExecutionInputsAndOutputsRequest, @@ -287,8 +358,12 @@ UpdateContextRequest, UpdateExecutionRequest, ) -from .metadata_store import MetadataStore -from .migratable_resource import MigratableResource +from .metadata_store import ( + MetadataStore, +) +from .migratable_resource import ( + MigratableResource, +) from .migration_service import ( BatchMigrateResourcesOperationMetadata, BatchMigrateResourcesRequest, @@ -312,28 +387,43 @@ ModelMonitoringStatsAnomalies, ModelDeploymentMonitoringObjectiveType, ) -from .model_evaluation import ModelEvaluation -from .model_evaluation_slice import ModelEvaluationSlice +from .model_evaluation import ( + ModelEvaluation, +) +from .model_evaluation_slice import ( + ModelEvaluationSlice, +) from .model_monitoring import ( ModelMonitoringAlertConfig, + ModelMonitoringConfig, ModelMonitoringObjectiveConfig, SamplingStrategy, ThresholdConfig, ) from .model_service import ( + BatchImportModelEvaluationSlicesRequest, + BatchImportModelEvaluationSlicesResponse, DeleteModelRequest, + DeleteModelVersionRequest, ExportModelOperationMetadata, ExportModelRequest, ExportModelResponse, GetModelEvaluationRequest, GetModelEvaluationSliceRequest, GetModelRequest, + ImportModelEvaluationRequest, ListModelEvaluationSlicesRequest, ListModelEvaluationSlicesResponse, ListModelEvaluationsRequest, ListModelEvaluationsResponse, ListModelsRequest, ListModelsResponse, + ListModelVersionsRequest, + ListModelVersionsResponse, + MergeVersionAliasesRequest, + UpdateExplanationDatasetOperationMetadata, + UpdateExplanationDatasetRequest, + UpdateExplanationDatasetResponse, UpdateModelRequest, UploadModelOperationMetadata, UploadModelRequest, @@ -348,6 +438,7 @@ PipelineJobDetail, PipelineTaskDetail, PipelineTaskExecutorDetail, + PipelineTemplateMetadata, ) from .pipeline_service import ( CancelPipelineJobRequest, @@ -368,8 +459,11 @@ ExplainResponse, PredictRequest, PredictResponse, + RawPredictRequest, +) +from .specialist_pool import ( + SpecialistPool, ) -from .specialist_pool import SpecialistPool from .specialist_pool_service import ( CreateSpecialistPoolOperationMetadata, CreateSpecialistPoolRequest, @@ -386,7 +480,9 @@ StudySpec, Trial, ) -from .tensorboard import Tensorboard +from .tensorboard import ( + Tensorboard, +) from .tensorboard_data import ( Scalar, TensorboardBlob, @@ -395,9 +491,19 @@ TimeSeriesData, TimeSeriesDataPoint, ) -from .tensorboard_experiment import TensorboardExperiment -from .tensorboard_run import TensorboardRun +from .tensorboard_experiment import ( + TensorboardExperiment, +) +from .tensorboard_run import ( + TensorboardRun, +) from .tensorboard_service import ( + BatchCreateTensorboardRunsRequest, + BatchCreateTensorboardRunsResponse, + BatchCreateTensorboardTimeSeriesRequest, + BatchCreateTensorboardTimeSeriesResponse, + BatchReadTensorboardTimeSeriesDataRequest, + BatchReadTensorboardTimeSeriesDataResponse, CreateTensorboardExperimentRequest, CreateTensorboardOperationMetadata, CreateTensorboardRequest, @@ -430,15 +536,20 @@ UpdateTensorboardRequest, UpdateTensorboardRunRequest, UpdateTensorboardTimeSeriesRequest, + WriteTensorboardExperimentDataRequest, + WriteTensorboardExperimentDataResponse, WriteTensorboardRunDataRequest, WriteTensorboardRunDataResponse, ) -from .tensorboard_time_series import TensorboardTimeSeries +from .tensorboard_time_series import ( + TensorboardTimeSeries, +) from .training_pipeline import ( FilterSplit, FractionSplit, InputDataConfig, PredefinedSplit, + StratifiedSplit, TimestampSplit, TrainingPipeline, ) @@ -448,8 +559,15 @@ Int64Array, StringArray, ) -from .user_action_reference import UserActionReference -from .value import Value +from .unmanaged_container_model import ( + UnmanagedContainerModel, +) +from .user_action_reference import ( + UserActionReference, +) +from .value import ( + Value, +) from .vizier_service import ( AddTrialMeasurementRequest, CheckTrialEarlyStoppingStateMetatdata, @@ -520,6 +638,8 @@ "EncryptionSpec", "DeployedModel", "Endpoint", + "PredictRequestResponseLoggingConfig", + "PrivateEndpoints", "CreateEndpointOperationMetadata", "CreateEndpointRequest", "DeleteEndpointRequest", @@ -538,6 +658,10 @@ "Event", "Execution", "Attribution", + "BlurBaselineConfig", + "Examples", + "ExamplesOverride", + "ExamplesRestrictionsNamespace", "Explanation", "ExplanationMetadataOverride", "ExplanationParameters", @@ -546,6 +670,8 @@ "FeatureNoiseSigma", "IntegratedGradientsAttribution", "ModelExplanation", + "Neighbor", + "Presets", "SampledShapleyAttribution", "SmoothGradConfig", "XraiAttribution", @@ -614,6 +740,9 @@ "GetIndexEndpointRequest", "ListIndexEndpointsRequest", "ListIndexEndpointsResponse", + "MutateDeployedIndexOperationMetadata", + "MutateDeployedIndexRequest", + "MutateDeployedIndexResponse", "UndeployIndexOperationMetadata", "UndeployIndexRequest", "UndeployIndexResponse", @@ -679,6 +808,7 @@ "DedicatedResources", "DiskSpec", "MachineSpec", + "NfsMount", "ResourcesConsumed", "ManualBatchTuningParameters", "MetadataSchema", @@ -694,7 +824,9 @@ "CreateMetadataSchemaRequest", "CreateMetadataStoreOperationMetadata", "CreateMetadataStoreRequest", + "DeleteArtifactRequest", "DeleteContextRequest", + "DeleteExecutionRequest", "DeleteMetadataStoreOperationMetadata", "DeleteMetadataStoreRequest", "GetArtifactRequest", @@ -712,6 +844,15 @@ "ListMetadataSchemasResponse", "ListMetadataStoresRequest", "ListMetadataStoresResponse", + "PurgeArtifactsMetadata", + "PurgeArtifactsRequest", + "PurgeArtifactsResponse", + "PurgeContextsMetadata", + "PurgeContextsRequest", + "PurgeContextsResponse", + "PurgeExecutionsMetadata", + "PurgeExecutionsRequest", + "PurgeExecutionsResponse", "QueryArtifactLineageSubgraphRequest", "QueryContextLineageSubgraphRequest", "QueryExecutionInputsAndOutputsRequest", @@ -740,32 +881,45 @@ "ModelEvaluation", "ModelEvaluationSlice", "ModelMonitoringAlertConfig", + "ModelMonitoringConfig", "ModelMonitoringObjectiveConfig", "SamplingStrategy", "ThresholdConfig", + "BatchImportModelEvaluationSlicesRequest", + "BatchImportModelEvaluationSlicesResponse", "DeleteModelRequest", + "DeleteModelVersionRequest", "ExportModelOperationMetadata", "ExportModelRequest", "ExportModelResponse", "GetModelEvaluationRequest", "GetModelEvaluationSliceRequest", "GetModelRequest", + "ImportModelEvaluationRequest", "ListModelEvaluationSlicesRequest", "ListModelEvaluationSlicesResponse", "ListModelEvaluationsRequest", "ListModelEvaluationsResponse", "ListModelsRequest", "ListModelsResponse", + "ListModelVersionsRequest", + "ListModelVersionsResponse", + "MergeVersionAliasesRequest", + "UpdateExplanationDatasetOperationMetadata", + "UpdateExplanationDatasetRequest", + "UpdateExplanationDatasetResponse", "UpdateModelRequest", "UploadModelOperationMetadata", "UploadModelRequest", "UploadModelResponse", "DeleteOperationMetadata", "GenericOperationMetadata", + "PipelineFailurePolicy", "PipelineJob", "PipelineJobDetail", "PipelineTaskDetail", "PipelineTaskExecutorDetail", + "PipelineTemplateMetadata", "CancelPipelineJobRequest", "CancelTrainingPipelineRequest", "CreatePipelineJobRequest", @@ -783,6 +937,7 @@ "ExplainResponse", "PredictRequest", "PredictResponse", + "RawPredictRequest", "SpecialistPool", "CreateSpecialistPoolOperationMetadata", "CreateSpecialistPoolRequest", @@ -805,6 +960,12 @@ "TimeSeriesDataPoint", "TensorboardExperiment", "TensorboardRun", + "BatchCreateTensorboardRunsRequest", + "BatchCreateTensorboardRunsResponse", + "BatchCreateTensorboardTimeSeriesRequest", + "BatchCreateTensorboardTimeSeriesResponse", + "BatchReadTensorboardTimeSeriesDataRequest", + "BatchReadTensorboardTimeSeriesDataResponse", "CreateTensorboardExperimentRequest", "CreateTensorboardOperationMetadata", "CreateTensorboardRequest", @@ -837,6 +998,8 @@ "UpdateTensorboardRequest", "UpdateTensorboardRunRequest", "UpdateTensorboardTimeSeriesRequest", + "WriteTensorboardExperimentDataRequest", + "WriteTensorboardExperimentDataResponse", "WriteTensorboardRunDataRequest", "WriteTensorboardRunDataResponse", "TensorboardTimeSeries", @@ -844,12 +1007,14 @@ "FractionSplit", "InputDataConfig", "PredefinedSplit", + "StratifiedSplit", "TimestampSplit", "TrainingPipeline", "BoolArray", "DoubleArray", "Int64Array", "StringArray", + "UnmanagedContainerModel", "UserActionReference", "Value", "AddTrialMeasurementRequest", diff --git a/google/cloud/aiplatform_v1beta1/types/accelerator_type.py b/google/cloud/aiplatform_v1beta1/types/accelerator_type.py index 6fb2d8899d..5f80e5be03 100644 --- a/google/cloud/aiplatform_v1beta1/types/accelerator_type.py +++ b/google/cloud/aiplatform_v1beta1/types/accelerator_type.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,7 +17,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"AcceleratorType",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "AcceleratorType", + }, ) @@ -30,6 +33,8 @@ class AcceleratorType(proto.Enum): NVIDIA_TESLA_P4 = 4 NVIDIA_TESLA_T4 = 5 NVIDIA_TESLA_A100 = 8 + TPU_V2 = 6 + TPU_V3 = 7 __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/annotation.py b/google/cloud/aiplatform_v1beta1/types/annotation.py index 07c5769df3..0af30d2e8d 100644 --- a/google/cloud/aiplatform_v1beta1/types/annotation.py +++ b/google/cloud/aiplatform_v1beta1/types/annotation.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,7 +21,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"Annotation",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "Annotation", + }, ) @@ -37,8 +40,8 @@ class Annotation(proto.Message): describing [payload][google.cloud.aiplatform.v1beta1.Annotation.payload]. The schema is defined as an `OpenAPI 3.0.2 Schema - Object `__. The schema files - that can be used here are found in + Object `__. + The schema files that can be used here are found in gs://google-cloud-aiplatform/schema/dataset/annotation/, note that the chosen schema must be consistent with the parent Dataset's @@ -53,12 +56,12 @@ class Annotation(proto.Message): Output only. Timestamp when this Annotation was last updated. etag (str): - Optional. Used to perform consistent read- - odify-write updates. If not set, a blind + Optional. Used to perform consistent + read-modify-write updates. If not set, a blind "overwrite" update happens. annotation_source (google.cloud.aiplatform_v1beta1.types.UserActionReference): Output only. The source of the Annotation. - labels (Sequence[google.cloud.aiplatform_v1beta1.types.Annotation.LabelsEntry]): + labels (Mapping[str, str]): Optional. The labels with user-defined metadata to organize your Annotations. @@ -84,16 +87,43 @@ class Annotation(proto.Message): title. """ - name = proto.Field(proto.STRING, number=1,) - payload_schema_uri = proto.Field(proto.STRING, number=2,) - payload = proto.Field(proto.MESSAGE, number=3, message=struct_pb2.Value,) - create_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) - update_time = proto.Field(proto.MESSAGE, number=7, message=timestamp_pb2.Timestamp,) - etag = proto.Field(proto.STRING, number=8,) + name = proto.Field( + proto.STRING, + number=1, + ) + payload_schema_uri = proto.Field( + proto.STRING, + number=2, + ) + payload = proto.Field( + proto.MESSAGE, + number=3, + message=struct_pb2.Value, + ) + create_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=7, + message=timestamp_pb2.Timestamp, + ) + etag = proto.Field( + proto.STRING, + number=8, + ) annotation_source = proto.Field( - proto.MESSAGE, number=5, message=user_action_reference.UserActionReference, + proto.MESSAGE, + number=5, + message=user_action_reference.UserActionReference, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=6, ) - labels = proto.MapField(proto.STRING, proto.STRING, number=6,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/annotation_spec.py b/google/cloud/aiplatform_v1beta1/types/annotation_spec.py index 9cd90b4dc1..1f950d298a 100644 --- a/google/cloud/aiplatform_v1beta1/types/annotation_spec.py +++ b/google/cloud/aiplatform_v1beta1/types/annotation_spec.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,7 +19,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"AnnotationSpec",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "AnnotationSpec", + }, ) @@ -43,16 +46,33 @@ class AnnotationSpec(proto.Message): Output only. Timestamp when AnnotationSpec was last updated. etag (str): - Optional. Used to perform consistent read- - odify-write updates. If not set, a blind + Optional. Used to perform consistent + read-modify-write updates. If not set, a blind "overwrite" update happens. """ - name = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) - create_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) - update_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) - etag = proto.Field(proto.STRING, number=5,) + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + create_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + etag = proto.Field( + proto.STRING, + number=5, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/artifact.py b/google/cloud/aiplatform_v1beta1/types/artifact.py index 88914edc58..df2e59b99e 100644 --- a/google/cloud/aiplatform_v1beta1/types/artifact.py +++ b/google/cloud/aiplatform_v1beta1/types/artifact.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,12 +20,16 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"Artifact",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "Artifact", + }, ) class Artifact(proto.Message): r"""Instance of a general artifact. + Attributes: name (str): Output only. The resource name of the @@ -38,10 +42,10 @@ class Artifact(proto.Message): artifact file. May be empty if there is no actual artifact file. etag (str): - An eTag used to perform consistent read- - odify-write updates. If not set, a blind + An eTag used to perform consistent + read-modify-write updates. If not set, a blind "overwrite" update happens. - labels (Sequence[google.cloud.aiplatform_v1beta1.types.Artifact.LabelsEntry]): + labels (Mapping[str, str]): The labels with user-defined metadata to organize your Artifacts. Label keys and values can be no longer than 64 @@ -61,7 +65,7 @@ class Artifact(proto.Message): The state of this Artifact. This is a property of the Artifact, and does not imply or capture any ongoing process. This property is - managed by clients (such as AI Platform + managed by clients (such as Vertex AI Pipelines), and the system does not prescribe or check the validity of state transitions. schema_title (str): @@ -81,6 +85,7 @@ class Artifact(proto.Message): metadata store. metadata (google.protobuf.struct_pb2.Struct): Properties of the Artifact. + The size of this field should not exceed 200KB. description (str): Description of the Artifact """ @@ -91,22 +96,59 @@ class State(proto.Enum): PENDING = 1 LIVE = 2 - name = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) - uri = proto.Field(proto.STRING, number=6,) - etag = proto.Field(proto.STRING, number=9,) - labels = proto.MapField(proto.STRING, proto.STRING, number=10,) + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + uri = proto.Field( + proto.STRING, + number=6, + ) + etag = proto.Field( + proto.STRING, + number=9, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=10, + ) create_time = proto.Field( - proto.MESSAGE, number=11, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=11, + message=timestamp_pb2.Timestamp, ) update_time = proto.Field( - proto.MESSAGE, number=12, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=12, + message=timestamp_pb2.Timestamp, + ) + state = proto.Field( + proto.ENUM, + number=13, + enum=State, + ) + schema_title = proto.Field( + proto.STRING, + number=14, + ) + schema_version = proto.Field( + proto.STRING, + number=15, + ) + metadata = proto.Field( + proto.MESSAGE, + number=16, + message=struct_pb2.Struct, + ) + description = proto.Field( + proto.STRING, + number=17, ) - state = proto.Field(proto.ENUM, number=13, enum=State,) - schema_title = proto.Field(proto.STRING, number=14,) - schema_version = proto.Field(proto.STRING, number=15,) - metadata = proto.Field(proto.MESSAGE, number=16, message=struct_pb2.Struct,) - description = proto.Field(proto.STRING, number=17,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/batch_prediction_job.py b/google/cloud/aiplatform_v1beta1/types/batch_prediction_job.py index 1e0d364c4f..dd1d9b40e9 100644 --- a/google/cloud/aiplatform_v1beta1/types/batch_prediction_job.py +++ b/google/cloud/aiplatform_v1beta1/types/batch_prediction_job.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -26,13 +26,20 @@ from google.cloud.aiplatform_v1beta1.types import ( manual_batch_tuning_parameters as gca_manual_batch_tuning_parameters, ) +from google.cloud.aiplatform_v1beta1.types import model_monitoring +from google.cloud.aiplatform_v1beta1.types import ( + unmanaged_container_model as gca_unmanaged_container_model, +) from google.protobuf import struct_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore from google.rpc import status_pb2 # type: ignore __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"BatchPredictionJob",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "BatchPredictionJob", + }, ) @@ -53,11 +60,23 @@ class BatchPredictionJob(proto.Message): Required. The user-defined name of this BatchPredictionJob. model (str): - Required. The name of the Model that produces - the predictions via this job, must share the - same ancestor Location. Starting this job has no - impact on any existing deployments of the Model - and their resources. + The name of the Model resoure that produces the predictions + via this job, must share the same ancestor Location. + Starting this job has no impact on any existing deployments + of the Model and their resources. Exactly one of model and + unmanaged_container_model must be set. + + The model resource name may contain version id or version + alias to specify the version, if no version is specified, + the default version will be used. + model_version_id (str): + Output only. The version ID of the Model that + produces the predictions via this job. + unmanaged_container_model (google.cloud.aiplatform_v1beta1.types.UnmanagedContainerModel): + Contains model information necessary to perform batch + prediction without requiring uploading to model registry. + Exactly one of model and unmanaged_container_model must be + set. input_config (google.cloud.aiplatform_v1beta1.types.BatchPredictionJob.InputConfig): Required. Input configuration of the instances on which predictions are performed. The schema of any single instance @@ -87,12 +106,21 @@ class BatchPredictionJob(proto.Message): DEDICATED_RESOURCES this config may be provided (and the job will use these resources), if the Model doesn't support AUTOMATIC_RESOURCES, this config must be provided. + service_account (str): + The service account that the DeployedModel's container runs + as. If not specified, a system generated one will be used, + which has minimal permissions and the custom container, if + used, may not have enough permission to access other GCP + resources. + + Users deploying the Model must have the + ``iam.serviceAccounts.actAs`` permission on this service + account. manual_batch_tuning_parameters (google.cloud.aiplatform_v1beta1.types.ManualBatchTuningParameters): Immutable. Parameters configuring the batch behavior. Currently only applicable when [dedicated_resources][google.cloud.aiplatform.v1beta1.BatchPredictionJob.dedicated_resources] - are used (in other cases AI Platform does the tuning - itself). + are used (in other cases Vertex AI does the tuning itself). generate_explanation (bool): Generate explanation with the batch prediction results. @@ -172,7 +200,7 @@ class BatchPredictionJob(proto.Message): update_time (google.protobuf.timestamp_pb2.Timestamp): Output only. Time when the BatchPredictionJob was most recently updated. - labels (Sequence[google.cloud.aiplatform_v1beta1.types.BatchPredictionJob.LabelsEntry]): + labels (Mapping[str, str]): The labels with user-defined metadata to organize BatchPredictionJobs. Label keys and values can be no longer than 64 @@ -187,6 +215,11 @@ class BatchPredictionJob(proto.Message): BatchPredictionJob. If this is set, then all resources created by the BatchPredictionJob will be encrypted with the provided encryption key. + model_monitoring_config (google.cloud.aiplatform_v1beta1.types.ModelMonitoringConfig): + Model monitoring config will be used for + analysis model behaviors, based on the input and + output to the batch prediction job, as well as + the provided training dataset. """ class InputConfig(proto.Message): @@ -197,10 +230,19 @@ class InputConfig(proto.Message): for Model's supported input formats, and how instances should be expressed via any of them. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: gcs_source (google.cloud.aiplatform_v1beta1.types.GcsSource): The Cloud Storage location for the input instances. + + This field is a member of `oneof`_ ``source``. bigquery_source (google.cloud.aiplatform_v1beta1.types.BigQuerySource): The BigQuery location of the input table. The schema of the table should be in the format @@ -208,6 +250,8 @@ class InputConfig(proto.Message): if one is provided. The table may contain additional columns that are not described by the schema, and they will be ignored. + + This field is a member of `oneof`_ ``source``. instances_format (str): Required. The format in which instances are given, must be one of the @@ -216,12 +260,21 @@ class InputConfig(proto.Message): """ gcs_source = proto.Field( - proto.MESSAGE, number=2, oneof="source", message=io.GcsSource, + proto.MESSAGE, + number=2, + oneof="source", + message=io.GcsSource, ) bigquery_source = proto.Field( - proto.MESSAGE, number=3, oneof="source", message=io.BigQuerySource, + proto.MESSAGE, + number=3, + oneof="source", + message=io.BigQuerySource, + ) + instances_format = proto.Field( + proto.STRING, + number=1, ) - instances_format = proto.Field(proto.STRING, number=1,) class OutputConfig(proto.Message): r"""Configures the output of @@ -231,6 +284,13 @@ class OutputConfig(proto.Message): for supported output formats, and how predictions are expressed via any of them. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: gcs_destination (google.cloud.aiplatform_v1beta1.types.GcsDestination): The Cloud Storage location of the directory where the output @@ -257,8 +317,10 @@ class OutputConfig(proto.Message): files are created (N depends on total number of failed predictions). These files contain the failed instances, as per their schema, followed by an additional ``error`` field - which as value has ```google.rpc.Status`` `__ + which as value has [google.rpc.Status][google.rpc.Status] containing only ``code`` and ``message`` fields. + + This field is a member of `oneof`_ ``destination``. bigquery_destination (google.cloud.aiplatform_v1beta1.types.BigQueryDestination): The BigQuery project or dataset location where the output is to be written to. If project is provided, a new dataset is @@ -279,17 +341,22 @@ class OutputConfig(proto.Message): ``errors`` table contains rows for which the prediction has failed, it has instance columns, as per the instance schema, followed by a single "errors" column, which as values has - ```google.rpc.Status`` `__ represented as a STRUCT, - and containing only ``code`` and ``message``. + [google.rpc.Status][google.rpc.Status] represented as a + STRUCT, and containing only ``code`` and ``message``. + + This field is a member of `oneof`_ ``destination``. predictions_format (str): - Required. The format in which AI Platform gives the + Required. The format in which Vertex AI gives the predictions, must be one of the [Model's][google.cloud.aiplatform.v1beta1.BatchPredictionJob.model] [supported_output_storage_formats][google.cloud.aiplatform.v1beta1.Model.supported_output_storage_formats]. """ gcs_destination = proto.Field( - proto.MESSAGE, number=2, oneof="destination", message=io.GcsDestination, + proto.MESSAGE, + number=2, + oneof="destination", + message=io.GcsDestination, ) bigquery_destination = proto.Field( proto.MESSAGE, @@ -297,71 +364,180 @@ class OutputConfig(proto.Message): oneof="destination", message=io.BigQueryDestination, ) - predictions_format = proto.Field(proto.STRING, number=1,) + predictions_format = proto.Field( + proto.STRING, + number=1, + ) class OutputInfo(proto.Message): r"""Further describes this job's output. Supplements [output_config][google.cloud.aiplatform.v1beta1.BatchPredictionJob.output_config]. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: gcs_output_directory (str): Output only. The full path of the Cloud Storage directory created, into which the prediction output is written. + + This field is a member of `oneof`_ ``output_location``. bigquery_output_dataset (str): Output only. The path of the BigQuery dataset created, in ``bq://projectId.bqDatasetId`` format, into which the prediction output is written. + + This field is a member of `oneof`_ ``output_location``. + bigquery_output_table (str): + Output only. The name of the BigQuery table created, in + ``predictions_`` format, into which the + prediction output is written. Can be used by UI to generate + the BigQuery output path, for example. """ gcs_output_directory = proto.Field( - proto.STRING, number=1, oneof="output_location", + proto.STRING, + number=1, + oneof="output_location", ) bigquery_output_dataset = proto.Field( - proto.STRING, number=2, oneof="output_location", + proto.STRING, + number=2, + oneof="output_location", + ) + bigquery_output_table = proto.Field( + proto.STRING, + number=4, ) - name = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) - model = proto.Field(proto.STRING, number=3,) - input_config = proto.Field(proto.MESSAGE, number=4, message=InputConfig,) - model_parameters = proto.Field(proto.MESSAGE, number=5, message=struct_pb2.Value,) - output_config = proto.Field(proto.MESSAGE, number=6, message=OutputConfig,) + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + model = proto.Field( + proto.STRING, + number=3, + ) + model_version_id = proto.Field( + proto.STRING, + number=30, + ) + unmanaged_container_model = proto.Field( + proto.MESSAGE, + number=28, + message=gca_unmanaged_container_model.UnmanagedContainerModel, + ) + input_config = proto.Field( + proto.MESSAGE, + number=4, + message=InputConfig, + ) + model_parameters = proto.Field( + proto.MESSAGE, + number=5, + message=struct_pb2.Value, + ) + output_config = proto.Field( + proto.MESSAGE, + number=6, + message=OutputConfig, + ) dedicated_resources = proto.Field( - proto.MESSAGE, number=7, message=machine_resources.BatchDedicatedResources, + proto.MESSAGE, + number=7, + message=machine_resources.BatchDedicatedResources, + ) + service_account = proto.Field( + proto.STRING, + number=29, ) manual_batch_tuning_parameters = proto.Field( proto.MESSAGE, number=8, message=gca_manual_batch_tuning_parameters.ManualBatchTuningParameters, ) - generate_explanation = proto.Field(proto.BOOL, number=23,) + generate_explanation = proto.Field( + proto.BOOL, + number=23, + ) explanation_spec = proto.Field( - proto.MESSAGE, number=25, message=explanation.ExplanationSpec, + proto.MESSAGE, + number=25, + message=explanation.ExplanationSpec, + ) + output_info = proto.Field( + proto.MESSAGE, + number=9, + message=OutputInfo, + ) + state = proto.Field( + proto.ENUM, + number=10, + enum=job_state.JobState, + ) + error = proto.Field( + proto.MESSAGE, + number=11, + message=status_pb2.Status, ) - output_info = proto.Field(proto.MESSAGE, number=9, message=OutputInfo,) - state = proto.Field(proto.ENUM, number=10, enum=job_state.JobState,) - error = proto.Field(proto.MESSAGE, number=11, message=status_pb2.Status,) partial_failures = proto.RepeatedField( - proto.MESSAGE, number=12, message=status_pb2.Status, + proto.MESSAGE, + number=12, + message=status_pb2.Status, ) resources_consumed = proto.Field( - proto.MESSAGE, number=13, message=machine_resources.ResourcesConsumed, + proto.MESSAGE, + number=13, + message=machine_resources.ResourcesConsumed, ) completion_stats = proto.Field( - proto.MESSAGE, number=14, message=gca_completion_stats.CompletionStats, + proto.MESSAGE, + number=14, + message=gca_completion_stats.CompletionStats, ) create_time = proto.Field( - proto.MESSAGE, number=15, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=15, + message=timestamp_pb2.Timestamp, + ) + start_time = proto.Field( + proto.MESSAGE, + number=16, + message=timestamp_pb2.Timestamp, + ) + end_time = proto.Field( + proto.MESSAGE, + number=17, + message=timestamp_pb2.Timestamp, ) - start_time = proto.Field(proto.MESSAGE, number=16, message=timestamp_pb2.Timestamp,) - end_time = proto.Field(proto.MESSAGE, number=17, message=timestamp_pb2.Timestamp,) update_time = proto.Field( - proto.MESSAGE, number=18, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=18, + message=timestamp_pb2.Timestamp, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=19, ) - labels = proto.MapField(proto.STRING, proto.STRING, number=19,) encryption_spec = proto.Field( - proto.MESSAGE, number=24, message=gca_encryption_spec.EncryptionSpec, + proto.MESSAGE, + number=24, + message=gca_encryption_spec.EncryptionSpec, + ) + model_monitoring_config = proto.Field( + proto.MESSAGE, + number=26, + message=model_monitoring.ModelMonitoringConfig, ) diff --git a/google/cloud/aiplatform_v1beta1/types/completion_stats.py b/google/cloud/aiplatform_v1beta1/types/completion_stats.py index 9cee99a5a8..3ab6b8dc1a 100644 --- a/google/cloud/aiplatform_v1beta1/types/completion_stats.py +++ b/google/cloud/aiplatform_v1beta1/types/completion_stats.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,7 +17,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"CompletionStats",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "CompletionStats", + }, ) @@ -41,11 +44,29 @@ class CompletionStats(proto.Message): Set to -1 if the number is unknown (for example, the operation failed before the total entity number could be collected). + successful_forecast_point_count (int): + Output only. The number of the successful + forecast points that are generated by the + forecasting model. This is ONLY used by the + forecasting batch prediction. """ - successful_count = proto.Field(proto.INT64, number=1,) - failed_count = proto.Field(proto.INT64, number=2,) - incomplete_count = proto.Field(proto.INT64, number=3,) + successful_count = proto.Field( + proto.INT64, + number=1, + ) + failed_count = proto.Field( + proto.INT64, + number=2, + ) + incomplete_count = proto.Field( + proto.INT64, + number=3, + ) + successful_forecast_point_count = proto.Field( + proto.INT64, + number=5, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/context.py b/google/cloud/aiplatform_v1beta1/types/context.py index 412b6b462a..40d271bba2 100644 --- a/google/cloud/aiplatform_v1beta1/types/context.py +++ b/google/cloud/aiplatform_v1beta1/types/context.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,12 +20,16 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"Context",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "Context", + }, ) class Context(proto.Message): r"""Instance of a general context. + Attributes: name (str): Output only. The resource name of the @@ -34,10 +38,10 @@ class Context(proto.Message): User provided display name of the Context. May be up to 128 Unicode characters. etag (str): - An eTag used to perform consistent read- - odify-write updates. If not set, a blind + An eTag used to perform consistent + read-modify-write updates. If not set, a blind "overwrite" update happens. - labels (Sequence[google.cloud.aiplatform_v1beta1.types.Context.LabelsEntry]): + labels (Mapping[str, str]): The labels with user-defined metadata to organize your Contexts. Label keys and values can be no longer than 64 @@ -74,25 +78,59 @@ class Context(proto.Message): metadata store. metadata (google.protobuf.struct_pb2.Struct): Properties of the Context. + The size of this field should not exceed 200KB. description (str): Description of the Context """ - name = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) - etag = proto.Field(proto.STRING, number=8,) - labels = proto.MapField(proto.STRING, proto.STRING, number=9,) + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + etag = proto.Field( + proto.STRING, + number=8, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=9, + ) create_time = proto.Field( - proto.MESSAGE, number=10, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=10, + message=timestamp_pb2.Timestamp, ) update_time = proto.Field( - proto.MESSAGE, number=11, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=11, + message=timestamp_pb2.Timestamp, + ) + parent_contexts = proto.RepeatedField( + proto.STRING, + number=12, + ) + schema_title = proto.Field( + proto.STRING, + number=13, + ) + schema_version = proto.Field( + proto.STRING, + number=14, + ) + metadata = proto.Field( + proto.MESSAGE, + number=15, + message=struct_pb2.Struct, + ) + description = proto.Field( + proto.STRING, + number=16, ) - parent_contexts = proto.RepeatedField(proto.STRING, number=12,) - schema_title = proto.Field(proto.STRING, number=13,) - schema_version = proto.Field(proto.STRING, number=14,) - metadata = proto.Field(proto.MESSAGE, number=15, message=struct_pb2.Struct,) - description = proto.Field(proto.STRING, number=16,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/custom_job.py b/google/cloud/aiplatform_v1beta1/types/custom_job.py index 3900a6bd26..d04ddb4856 100644 --- a/google/cloud/aiplatform_v1beta1/types/custom_job.py +++ b/google/cloud/aiplatform_v1beta1/types/custom_job.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ import proto # type: ignore from google.cloud.aiplatform_v1beta1.types import encryption_spec as gca_encryption_spec +from google.cloud.aiplatform_v1beta1.types import env_var from google.cloud.aiplatform_v1beta1.types import io from google.cloud.aiplatform_v1beta1.types import job_state from google.cloud.aiplatform_v1beta1.types import machine_resources @@ -71,7 +72,7 @@ class CustomJob(proto.Message): error (google.rpc.status_pb2.Status): Output only. Only populated when job's state is ``JOB_STATE_FAILED`` or ``JOB_STATE_CANCELLED``. - labels (Sequence[google.cloud.aiplatform_v1beta1.types.CustomJob.LabelsEntry]): + labels (Mapping[str, str]): The labels with user-defined metadata to organize CustomJobs. Label keys and values can be no longer than 64 @@ -86,25 +87,86 @@ class CustomJob(proto.Message): CustomJob. If this is set, then all resources created by the CustomJob will be encrypted with the provided encryption key. + web_access_uris (Mapping[str, str]): + Output only. URIs for accessing `interactive + shells `__ + (one URI for each training node). Only available if + [job_spec.enable_web_access][google.cloud.aiplatform.v1beta1.CustomJobSpec.enable_web_access] + is ``true``. + + The keys are names of each node in the training job; for + example, ``workerpool0-0`` for the primary node, + ``workerpool1-0`` for the first node in the second worker + pool, and ``workerpool1-1`` for the second node in the + second worker pool. + + The values are the URIs for each node's interactive shell. """ - name = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) - job_spec = proto.Field(proto.MESSAGE, number=4, message="CustomJobSpec",) - state = proto.Field(proto.ENUM, number=5, enum=job_state.JobState,) - create_time = proto.Field(proto.MESSAGE, number=6, message=timestamp_pb2.Timestamp,) - start_time = proto.Field(proto.MESSAGE, number=7, message=timestamp_pb2.Timestamp,) - end_time = proto.Field(proto.MESSAGE, number=8, message=timestamp_pb2.Timestamp,) - update_time = proto.Field(proto.MESSAGE, number=9, message=timestamp_pb2.Timestamp,) - error = proto.Field(proto.MESSAGE, number=10, message=status_pb2.Status,) - labels = proto.MapField(proto.STRING, proto.STRING, number=11,) + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + job_spec = proto.Field( + proto.MESSAGE, + number=4, + message="CustomJobSpec", + ) + state = proto.Field( + proto.ENUM, + number=5, + enum=job_state.JobState, + ) + create_time = proto.Field( + proto.MESSAGE, + number=6, + message=timestamp_pb2.Timestamp, + ) + start_time = proto.Field( + proto.MESSAGE, + number=7, + message=timestamp_pb2.Timestamp, + ) + end_time = proto.Field( + proto.MESSAGE, + number=8, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=9, + message=timestamp_pb2.Timestamp, + ) + error = proto.Field( + proto.MESSAGE, + number=10, + message=status_pb2.Status, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=11, + ) encryption_spec = proto.Field( - proto.MESSAGE, number=12, message=gca_encryption_spec.EncryptionSpec, + proto.MESSAGE, + number=12, + message=gca_encryption_spec.EncryptionSpec, + ) + web_access_uris = proto.MapField( + proto.STRING, + proto.STRING, + number=16, ) class CustomJobSpec(proto.Message): r"""Represents the spec of a CustomJob. + Next Id: 14 + Attributes: worker_pool_specs (Sequence[google.cloud.aiplatform_v1beta1.types.WorkerPoolSpec]): Required. The spec of the worker pools @@ -114,11 +176,12 @@ class CustomJobSpec(proto.Message): scheduling (google.cloud.aiplatform_v1beta1.types.Scheduling): Scheduling options for a CustomJob. service_account (str): - Specifies the service account for workload - run-as account. Users submitting jobs must have - act-as permission on this run-as account. If - unspecified, the AI Platform Custom Code Service - Agent for the CustomJob's project is used. + Specifies the service account for workload run-as account. + Users submitting jobs must have act-as permission on this + run-as account. If unspecified, the `Vertex AI Custom Code + Service + Agent `__ + for the CustomJob's project is used. network (str): The full name of the Compute Engine `network `__ @@ -130,9 +193,21 @@ class CustomJobSpec(proto.Message): {project} is a project number, as in ``12345``, and {network} is a network name. - Private services access must already be configured for the - network. If left unspecified, the job is not peered with any - network. + To specify this field, you must have already `configured VPC + Network Peering for Vertex + AI `__. + + If this field is left unspecified, the job is not peered + with any network. + reserved_ip_ranges (Sequence[str]): + Optional. A list of names for the reserved ip ranges under + the VPC network that can be used for this job. + + If set, we will deploy the job within the provided ip + ranges. Otherwise, the job will be deployed to any ip ranges + under the provided VPC network. + + Example: ['vertex-ai-ip-range']. base_output_directory (google.cloud.aiplatform_v1beta1.types.GcsDestination): The Cloud Storage location to store the output of this CustomJob or HyperparameterTuningJob. For @@ -141,9 +216,8 @@ class CustomJobSpec(proto.Message): name [id][google.cloud.aiplatform.v1beta1.Trial.id] under its parent HyperparameterTuningJob's baseOutputDirectory. - The following AI Platform environment variables will be - passed to containers or python modules when this field is - set: + The following Vertex AI environment variables will be passed + to containers or python modules when this field is set: For CustomJob: @@ -162,59 +236,130 @@ class CustomJobSpec(proto.Message): - AIP_TENSORBOARD_LOG_DIR = ``//logs/`` tensorboard (str): - Optional. The name of an AI Platform + Optional. The name of a Vertex AI [Tensorboard][google.cloud.aiplatform.v1beta1.Tensorboard] resource to which this CustomJob will upload Tensorboard logs. Format: ``projects/{project}/locations/{location}/tensorboards/{tensorboard}`` + enable_web_access (bool): + Optional. Whether you want Vertex AI to enable `interactive + shell + access `__ + to training containers. + + If set to ``true``, you can access interactive shells at the + URIs given by + [CustomJob.web_access_uris][google.cloud.aiplatform.v1beta1.CustomJob.web_access_uris] + or + [Trial.web_access_uris][google.cloud.aiplatform.v1beta1.Trial.web_access_uris] + (within + [HyperparameterTuningJob.trials][google.cloud.aiplatform.v1beta1.HyperparameterTuningJob.trials]). """ worker_pool_specs = proto.RepeatedField( - proto.MESSAGE, number=1, message="WorkerPoolSpec", + proto.MESSAGE, + number=1, + message="WorkerPoolSpec", + ) + scheduling = proto.Field( + proto.MESSAGE, + number=3, + message="Scheduling", + ) + service_account = proto.Field( + proto.STRING, + number=4, + ) + network = proto.Field( + proto.STRING, + number=5, + ) + reserved_ip_ranges = proto.RepeatedField( + proto.STRING, + number=13, ) - scheduling = proto.Field(proto.MESSAGE, number=3, message="Scheduling",) - service_account = proto.Field(proto.STRING, number=4,) - network = proto.Field(proto.STRING, number=5,) base_output_directory = proto.Field( - proto.MESSAGE, number=6, message=io.GcsDestination, + proto.MESSAGE, + number=6, + message=io.GcsDestination, + ) + tensorboard = proto.Field( + proto.STRING, + number=7, + ) + enable_web_access = proto.Field( + proto.BOOL, + number=10, ) - tensorboard = proto.Field(proto.STRING, number=7,) class WorkerPoolSpec(proto.Message): r"""Represents the spec of a worker pool in a job. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: container_spec (google.cloud.aiplatform_v1beta1.types.ContainerSpec): The custom container task. + + This field is a member of `oneof`_ ``task``. python_package_spec (google.cloud.aiplatform_v1beta1.types.PythonPackageSpec): The Python packaged task. + + This field is a member of `oneof`_ ``task``. machine_spec (google.cloud.aiplatform_v1beta1.types.MachineSpec): Optional. Immutable. The specification of a single machine. replica_count (int): Optional. The number of worker replicas to use for this worker pool. + nfs_mounts (Sequence[google.cloud.aiplatform_v1beta1.types.NfsMount]): + Optional. List of NFS mount spec. disk_spec (google.cloud.aiplatform_v1beta1.types.DiskSpec): Disk spec. """ container_spec = proto.Field( - proto.MESSAGE, number=6, oneof="task", message="ContainerSpec", + proto.MESSAGE, + number=6, + oneof="task", + message="ContainerSpec", ) python_package_spec = proto.Field( - proto.MESSAGE, number=7, oneof="task", message="PythonPackageSpec", + proto.MESSAGE, + number=7, + oneof="task", + message="PythonPackageSpec", ) machine_spec = proto.Field( - proto.MESSAGE, number=1, message=machine_resources.MachineSpec, + proto.MESSAGE, + number=1, + message=machine_resources.MachineSpec, + ) + replica_count = proto.Field( + proto.INT64, + number=2, + ) + nfs_mounts = proto.RepeatedField( + proto.MESSAGE, + number=4, + message=machine_resources.NfsMount, ) - replica_count = proto.Field(proto.INT64, number=2,) disk_spec = proto.Field( - proto.MESSAGE, number=5, message=machine_resources.DiskSpec, + proto.MESSAGE, + number=5, + message=machine_resources.DiskSpec, ) class ContainerSpec(proto.Message): r"""The spec of a Container. + Attributes: image_uri (str): Required. The URI of a container image in the @@ -227,23 +372,41 @@ class ContainerSpec(proto.Message): args (Sequence[str]): The arguments to be passed when starting the container. + env (Sequence[google.cloud.aiplatform_v1beta1.types.EnvVar]): + Environment variables to be passed to the + container. Maximum limit is 100. """ - image_uri = proto.Field(proto.STRING, number=1,) - command = proto.RepeatedField(proto.STRING, number=2,) - args = proto.RepeatedField(proto.STRING, number=3,) + image_uri = proto.Field( + proto.STRING, + number=1, + ) + command = proto.RepeatedField( + proto.STRING, + number=2, + ) + args = proto.RepeatedField( + proto.STRING, + number=3, + ) + env = proto.RepeatedField( + proto.MESSAGE, + number=4, + message=env_var.EnvVar, + ) class PythonPackageSpec(proto.Message): r"""The spec of a Python packaged code. + Attributes: executor_image_uri (str): Required. The URI of a container image in Artifact Registry - that will run the provided Python package. AI Platform + that will run the provided Python package. Vertex AI provides a wide range of executor images with pre-installed packages to meet users' various use cases. See the list of `pre-built containers for - training `__. + training `__. You must use an image from this list. package_uris (Sequence[str]): Required. The Google Cloud Storage location @@ -256,12 +419,32 @@ class PythonPackageSpec(proto.Message): args (Sequence[str]): Command line arguments to be passed to the Python task. + env (Sequence[google.cloud.aiplatform_v1beta1.types.EnvVar]): + Environment variables to be passed to the + python module. Maximum limit is 100. """ - executor_image_uri = proto.Field(proto.STRING, number=1,) - package_uris = proto.RepeatedField(proto.STRING, number=2,) - python_module = proto.Field(proto.STRING, number=3,) - args = proto.RepeatedField(proto.STRING, number=4,) + executor_image_uri = proto.Field( + proto.STRING, + number=1, + ) + package_uris = proto.RepeatedField( + proto.STRING, + number=2, + ) + python_module = proto.Field( + proto.STRING, + number=3, + ) + args = proto.RepeatedField( + proto.STRING, + number=4, + ) + env = proto.RepeatedField( + proto.MESSAGE, + number=5, + message=env_var.EnvVar, + ) class Scheduling(proto.Message): @@ -279,8 +462,15 @@ class Scheduling(proto.Message): to workers leaving and joining a job. """ - timeout = proto.Field(proto.MESSAGE, number=1, message=duration_pb2.Duration,) - restart_job_on_worker_restart = proto.Field(proto.BOOL, number=3,) + timeout = proto.Field( + proto.MESSAGE, + number=1, + message=duration_pb2.Duration, + ) + restart_job_on_worker_restart = proto.Field( + proto.BOOL, + number=3, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/data_item.py b/google/cloud/aiplatform_v1beta1/types/data_item.py index 8d43b2b478..b8e464b9dd 100644 --- a/google/cloud/aiplatform_v1beta1/types/data_item.py +++ b/google/cloud/aiplatform_v1beta1/types/data_item.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,7 +20,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"DataItem",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "DataItem", + }, ) @@ -38,7 +41,7 @@ class DataItem(proto.Message): update_time (google.protobuf.timestamp_pb2.Timestamp): Output only. Timestamp when this DataItem was last updated. - labels (Sequence[google.cloud.aiplatform_v1beta1.types.DataItem.LabelsEntry]): + labels (Mapping[str, str]): Optional. The labels with user-defined metadata to organize your DataItems. Label keys and values can be no longer than 64 @@ -60,17 +63,39 @@ class DataItem(proto.Message): schema's][google.cloud.aiplatform.v1beta1.Dataset.metadata_schema_uri] dataItemSchemaUri field. etag (str): - Optional. Used to perform consistent read- - odify-write updates. If not set, a blind + Optional. Used to perform consistent + read-modify-write updates. If not set, a blind "overwrite" update happens. """ - name = proto.Field(proto.STRING, number=1,) - create_time = proto.Field(proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp,) - update_time = proto.Field(proto.MESSAGE, number=6, message=timestamp_pb2.Timestamp,) - labels = proto.MapField(proto.STRING, proto.STRING, number=3,) - payload = proto.Field(proto.MESSAGE, number=4, message=struct_pb2.Value,) - etag = proto.Field(proto.STRING, number=7,) + name = proto.Field( + proto.STRING, + number=1, + ) + create_time = proto.Field( + proto.MESSAGE, + number=2, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=6, + message=timestamp_pb2.Timestamp, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=3, + ) + payload = proto.Field( + proto.MESSAGE, + number=4, + message=struct_pb2.Value, + ) + etag = proto.Field( + proto.STRING, + number=7, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/data_labeling_job.py b/google/cloud/aiplatform_v1beta1/types/data_labeling_job.py index 1e541afe71..fcf727b3fb 100644 --- a/google/cloud/aiplatform_v1beta1/types/data_labeling_job.py +++ b/google/cloud/aiplatform_v1beta1/types/data_labeling_job.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -52,7 +52,7 @@ class DataLabelingJob(proto.Message): Required. Dataset resource names. Right now we only support labeling from a single Dataset. Format: ``projects/{project}/locations/{location}/datasets/{dataset}`` - annotation_labels (Sequence[google.cloud.aiplatform_v1beta1.types.DataLabelingJob.AnnotationLabelsEntry]): + annotation_labels (Mapping[str, str]): Labels to assign to annotations generated by this DataLabelingJob. Label keys and values can be no longer than 64 @@ -76,9 +76,9 @@ class DataLabelingJob(proto.Message): Google Cloud Storage describing the config for a specific type of DataLabelingJob. The schema files that can be used here are found in the - https://storage.googleapis.com/google-cloud- - aiplatform bucket in the - /schema/datalabelingjob/inputs/ folder. + https://storage.googleapis.com/google-cloud-aiplatform + bucket in the /schema/datalabelingjob/inputs/ + folder. inputs (google.protobuf.struct_pb2.Value): Required. Input config parameters for the DataLabelingJob. @@ -101,7 +101,7 @@ class DataLabelingJob(proto.Message): Output only. DataLabelingJob errors. It is only populated when job's state is ``JOB_STATE_FAILED`` or ``JOB_STATE_CANCELLED``. - labels (Sequence[google.cloud.aiplatform_v1beta1.types.DataLabelingJob.LabelsEntry]): + labels (Mapping[str, str]): The labels with user-defined metadata to organize your DataLabelingJobs. @@ -137,29 +137,87 @@ class DataLabelingJob(proto.Message): on the sampling strategy. """ - name = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) - datasets = proto.RepeatedField(proto.STRING, number=3,) - annotation_labels = proto.MapField(proto.STRING, proto.STRING, number=12,) - labeler_count = proto.Field(proto.INT32, number=4,) - instruction_uri = proto.Field(proto.STRING, number=5,) - inputs_schema_uri = proto.Field(proto.STRING, number=6,) - inputs = proto.Field(proto.MESSAGE, number=7, message=struct_pb2.Value,) - state = proto.Field(proto.ENUM, number=8, enum=job_state.JobState,) - labeling_progress = proto.Field(proto.INT32, number=13,) - current_spend = proto.Field(proto.MESSAGE, number=14, message=money_pb2.Money,) - create_time = proto.Field(proto.MESSAGE, number=9, message=timestamp_pb2.Timestamp,) + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + datasets = proto.RepeatedField( + proto.STRING, + number=3, + ) + annotation_labels = proto.MapField( + proto.STRING, + proto.STRING, + number=12, + ) + labeler_count = proto.Field( + proto.INT32, + number=4, + ) + instruction_uri = proto.Field( + proto.STRING, + number=5, + ) + inputs_schema_uri = proto.Field( + proto.STRING, + number=6, + ) + inputs = proto.Field( + proto.MESSAGE, + number=7, + message=struct_pb2.Value, + ) + state = proto.Field( + proto.ENUM, + number=8, + enum=job_state.JobState, + ) + labeling_progress = proto.Field( + proto.INT32, + number=13, + ) + current_spend = proto.Field( + proto.MESSAGE, + number=14, + message=money_pb2.Money, + ) + create_time = proto.Field( + proto.MESSAGE, + number=9, + message=timestamp_pb2.Timestamp, + ) update_time = proto.Field( - proto.MESSAGE, number=10, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=10, + message=timestamp_pb2.Timestamp, + ) + error = proto.Field( + proto.MESSAGE, + number=22, + message=status_pb2.Status, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=11, + ) + specialist_pools = proto.RepeatedField( + proto.STRING, + number=16, ) - error = proto.Field(proto.MESSAGE, number=22, message=status_pb2.Status,) - labels = proto.MapField(proto.STRING, proto.STRING, number=11,) - specialist_pools = proto.RepeatedField(proto.STRING, number=16,) encryption_spec = proto.Field( - proto.MESSAGE, number=20, message=gca_encryption_spec.EncryptionSpec, + proto.MESSAGE, + number=20, + message=gca_encryption_spec.EncryptionSpec, ) active_learning_config = proto.Field( - proto.MESSAGE, number=21, message="ActiveLearningConfig", + proto.MESSAGE, + number=21, + message="ActiveLearningConfig", ) @@ -169,12 +227,23 @@ class ActiveLearningConfig(proto.Message): iterations. For every iteration, it will select a batch of data based on the sampling strategy. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: max_data_item_count (int): Max number of human labeled DataItems. + + This field is a member of `oneof`_ ``human_labeling_budget``. max_data_item_percentage (int): Max percent of total DataItems for human labeling. + + This field is a member of `oneof`_ ``human_labeling_budget``. sample_config (google.cloud.aiplatform_v1beta1.types.SampleConfig): Active learning data sampling config. For every active learning labeling iteration, it @@ -189,13 +258,25 @@ class ActiveLearningConfig(proto.Message): """ max_data_item_count = proto.Field( - proto.INT64, number=1, oneof="human_labeling_budget", + proto.INT64, + number=1, + oneof="human_labeling_budget", ) max_data_item_percentage = proto.Field( - proto.INT32, number=2, oneof="human_labeling_budget", + proto.INT32, + number=2, + oneof="human_labeling_budget", + ) + sample_config = proto.Field( + proto.MESSAGE, + number=3, + message="SampleConfig", + ) + training_config = proto.Field( + proto.MESSAGE, + number=4, + message="TrainingConfig", ) - sample_config = proto.Field(proto.MESSAGE, number=3, message="SampleConfig",) - training_config = proto.Field(proto.MESSAGE, number=4, message="TrainingConfig",) class SampleConfig(proto.Message): @@ -203,14 +284,21 @@ class SampleConfig(proto.Message): learning labeling iteration, it will select a batch of data based on the sampling strategy. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: initial_batch_sample_percentage (int): The percentage of data needed to be labeled in the first batch. + + This field is a member of `oneof`_ ``initial_batch_sample_size``. following_batch_sample_percentage (int): The percentage of data needed to be labeled in each following batch (except the first batch). + + This field is a member of `oneof`_ ``following_batch_sample_size``. sample_strategy (google.cloud.aiplatform_v1beta1.types.SampleConfig.SampleStrategy): Field to choose sampling strategy. Sampling strategy will decide which data should be @@ -225,12 +313,20 @@ class SampleStrategy(proto.Enum): UNCERTAINTY = 1 initial_batch_sample_percentage = proto.Field( - proto.INT32, number=1, oneof="initial_batch_sample_size", + proto.INT32, + number=1, + oneof="initial_batch_sample_size", ) following_batch_sample_percentage = proto.Field( - proto.INT32, number=3, oneof="following_batch_sample_size", + proto.INT32, + number=3, + oneof="following_batch_sample_size", + ) + sample_strategy = proto.Field( + proto.ENUM, + number=5, + enum=SampleStrategy, ) - sample_strategy = proto.Field(proto.ENUM, number=5, enum=SampleStrategy,) class TrainingConfig(proto.Message): @@ -246,7 +342,10 @@ class TrainingConfig(proto.Message): this field means 1 hour. """ - timeout_training_milli_hours = proto.Field(proto.INT64, number=1,) + timeout_training_milli_hours = proto.Field( + proto.INT64, + number=1, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/dataset.py b/google/cloud/aiplatform_v1beta1/types/dataset.py index 1d659c3bd0..10fc9c1320 100644 --- a/google/cloud/aiplatform_v1beta1/types/dataset.py +++ b/google/cloud/aiplatform_v1beta1/types/dataset.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -23,12 +23,17 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1", - manifest={"Dataset", "ImportDataConfig", "ExportDataConfig",}, + manifest={ + "Dataset", + "ImportDataConfig", + "ExportDataConfig", + }, ) class Dataset(proto.Message): r"""A collection of DataItems and Annotations on them. + Attributes: name (str): Output only. The resource name of the @@ -37,14 +42,15 @@ class Dataset(proto.Message): Required. The user-defined name of the Dataset. The name can be up to 128 characters long and can be consist of any UTF-8 characters. + description (str): + Optional. The description of the Dataset. metadata_schema_uri (str): Required. Points to a YAML file stored on Google Cloud Storage describing additional information about the Dataset. The schema is defined as an OpenAPI 3.0.2 Schema Object. The schema files that can be used here are found in - gs://google-cloud- - aiplatform/schema/dataset/metadata/. + gs://google-cloud-aiplatform/schema/dataset/metadata/. metadata (google.protobuf.struct_pb2.Value): Required. Additional information about the Dataset. @@ -58,7 +64,7 @@ class Dataset(proto.Message): Used to perform consistent read-modify-write updates. If not set, a blind "overwrite" update happens. - labels (Sequence[google.cloud.aiplatform_v1beta1.types.Dataset.LabelsEntry]): + labels (Mapping[str, str]): The labels with user-defined metadata to organize your Datasets. @@ -79,21 +85,55 @@ class Dataset(proto.Message): title. encryption_spec (google.cloud.aiplatform_v1beta1.types.EncryptionSpec): Customer-managed encryption key spec for a - Dataset. If set, this Dataset and all sub- - resources of this Dataset will be secured by + Dataset. If set, this Dataset and all + sub-resources of this Dataset will be secured by this key. """ - name = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) - metadata_schema_uri = proto.Field(proto.STRING, number=3,) - metadata = proto.Field(proto.MESSAGE, number=8, message=struct_pb2.Value,) - create_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) - update_time = proto.Field(proto.MESSAGE, number=5, message=timestamp_pb2.Timestamp,) - etag = proto.Field(proto.STRING, number=6,) - labels = proto.MapField(proto.STRING, proto.STRING, number=7,) + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + description = proto.Field( + proto.STRING, + number=16, + ) + metadata_schema_uri = proto.Field( + proto.STRING, + number=3, + ) + metadata = proto.Field( + proto.MESSAGE, + number=8, + message=struct_pb2.Value, + ) + create_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=5, + message=timestamp_pb2.Timestamp, + ) + etag = proto.Field( + proto.STRING, + number=6, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=7, + ) encryption_spec = proto.Field( - proto.MESSAGE, number=11, message=gca_encryption_spec.EncryptionSpec, + proto.MESSAGE, + number=11, + message=gca_encryption_spec.EncryptionSpec, ) @@ -102,11 +142,16 @@ class ImportDataConfig(proto.Message): Dataset, together with the labels that will be applied to the DataItems and the Annotations. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: gcs_source (google.cloud.aiplatform_v1beta1.types.GcsSource): The Google Cloud Storage location for the input content. - data_item_labels (Sequence[google.cloud.aiplatform_v1beta1.types.ImportDataConfig.DataItemLabelsEntry]): + + This field is a member of `oneof`_ ``source``. + data_item_labels (Mapping[str, str]): Labels that will be applied to newly imported DataItems. If an identical DataItem as one being imported already exists in the Dataset, then these labels will be appended to these @@ -126,20 +171,33 @@ class ImportDataConfig(proto.Message): Storage describing the import format. Validation will be done against the schema. The schema is defined as an `OpenAPI 3.0.2 Schema - Object `__. + Object `__. """ gcs_source = proto.Field( - proto.MESSAGE, number=1, oneof="source", message=io.GcsSource, + proto.MESSAGE, + number=1, + oneof="source", + message=io.GcsSource, + ) + data_item_labels = proto.MapField( + proto.STRING, + proto.STRING, + number=2, + ) + import_schema_uri = proto.Field( + proto.STRING, + number=4, ) - data_item_labels = proto.MapField(proto.STRING, proto.STRING, number=2,) - import_schema_uri = proto.Field(proto.STRING, number=4,) class ExportDataConfig(proto.Message): r"""Describes what part of the Dataset is to be exported, the destination of the export and how to export. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: gcs_destination (google.cloud.aiplatform_v1beta1.types.GcsDestination): The Google Cloud Storage location where the output is to be @@ -153,6 +211,8 @@ class ExportDataConfig(proto.Message): with the corresponding annotations' schema title. Inside these sub directories, a schema.yaml will be created to describe the output format. + + This field is a member of `oneof`_ ``destination``. annotations_filter (str): A filter on Annotations of the Dataset. Only Annotations on to-be-exported DataItems(specified by [data_items_filter][]) @@ -162,9 +222,15 @@ class ExportDataConfig(proto.Message): """ gcs_destination = proto.Field( - proto.MESSAGE, number=1, oneof="destination", message=io.GcsDestination, + proto.MESSAGE, + number=1, + oneof="destination", + message=io.GcsDestination, + ) + annotations_filter = proto.Field( + proto.STRING, + number=2, ) - annotations_filter = proto.Field(proto.STRING, number=2,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/dataset_service.py b/google/cloud/aiplatform_v1beta1/types/dataset_service.py index b1458c7a78..22a99eb769 100644 --- a/google/cloud/aiplatform_v1beta1/types/dataset_service.py +++ b/google/cloud/aiplatform_v1beta1/types/dataset_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -60,8 +60,15 @@ class CreateDatasetRequest(proto.Message): Required. The Dataset to create. """ - parent = proto.Field(proto.STRING, number=1,) - dataset = proto.Field(proto.MESSAGE, number=2, message=gca_dataset.Dataset,) + parent = proto.Field( + proto.STRING, + number=1, + ) + dataset = proto.Field( + proto.MESSAGE, + number=2, + message=gca_dataset.Dataset, + ) class CreateDatasetOperationMetadata(proto.Message): @@ -74,7 +81,9 @@ class CreateDatasetOperationMetadata(proto.Message): """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, ) @@ -89,8 +98,15 @@ class GetDatasetRequest(proto.Message): Mask specifying which fields to read. """ - name = proto.Field(proto.STRING, number=1,) - read_mask = proto.Field(proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask,) + name = proto.Field( + proto.STRING, + number=1, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) class UpdateDatasetRequest(proto.Message): @@ -104,7 +120,7 @@ class UpdateDatasetRequest(proto.Message): update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. The update mask applies to the resource. For the ``FieldMask`` definition, see - `FieldMask `__. + [google.protobuf.FieldMask][google.protobuf.FieldMask]. Updatable fields: - ``display_name`` @@ -112,9 +128,15 @@ class UpdateDatasetRequest(proto.Message): - ``labels`` """ - dataset = proto.Field(proto.MESSAGE, number=1, message=gca_dataset.Dataset,) + dataset = proto.Field( + proto.MESSAGE, + number=1, + message=gca_dataset.Dataset, + ) update_mask = proto.Field( - proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, ) @@ -159,12 +181,31 @@ class ListDatasetsRequest(proto.Message): - ``update_time`` """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) - read_mask = proto.Field(proto.MESSAGE, number=5, message=field_mask_pb2.FieldMask,) - order_by = proto.Field(proto.STRING, number=6,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=5, + message=field_mask_pb2.FieldMask, + ) + order_by = proto.Field( + proto.STRING, + number=6, + ) class ListDatasetsResponse(proto.Message): @@ -184,9 +225,14 @@ def raw_page(self): return self datasets = proto.RepeatedField( - proto.MESSAGE, number=1, message=gca_dataset.Dataset, + proto.MESSAGE, + number=1, + message=gca_dataset.Dataset, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class DeleteDatasetRequest(proto.Message): @@ -200,7 +246,10 @@ class DeleteDatasetRequest(proto.Message): ``projects/{project}/locations/{location}/datasets/{dataset}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ImportDataRequest(proto.Message): @@ -217,16 +266,22 @@ class ImportDataRequest(proto.Message): in one batch. """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) import_configs = proto.RepeatedField( - proto.MESSAGE, number=2, message=gca_dataset.ImportDataConfig, + proto.MESSAGE, + number=2, + message=gca_dataset.ImportDataConfig, ) class ImportDataResponse(proto.Message): r"""Response message for [DatasetService.ImportData][google.cloud.aiplatform.v1beta1.DatasetService.ImportData]. - """ + + """ class ImportDataOperationMetadata(proto.Message): @@ -239,7 +294,9 @@ class ImportDataOperationMetadata(proto.Message): """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, ) @@ -255,9 +312,14 @@ class ExportDataRequest(proto.Message): Required. The desired output location. """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) export_config = proto.Field( - proto.MESSAGE, number=2, message=gca_dataset.ExportDataConfig, + proto.MESSAGE, + number=2, + message=gca_dataset.ExportDataConfig, ) @@ -271,7 +333,10 @@ class ExportDataResponse(proto.Message): export operation. """ - exported_files = proto.RepeatedField(proto.STRING, number=1,) + exported_files = proto.RepeatedField( + proto.STRING, + number=1, + ) class ExportDataOperationMetadata(proto.Message): @@ -288,9 +353,14 @@ class ExportDataOperationMetadata(proto.Message): """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, + ) + gcs_output_directory = proto.Field( + proto.STRING, + number=2, ) - gcs_output_directory = proto.Field(proto.STRING, number=2,) class ListDataItemsRequest(proto.Message): @@ -316,12 +386,31 @@ class ListDataItemsRequest(proto.Message): field name for descending. """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) - read_mask = proto.Field(proto.MESSAGE, number=5, message=field_mask_pb2.FieldMask,) - order_by = proto.Field(proto.STRING, number=6,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=5, + message=field_mask_pb2.FieldMask, + ) + order_by = proto.Field( + proto.STRING, + number=6, + ) class ListDataItemsResponse(proto.Message): @@ -341,9 +430,14 @@ def raw_page(self): return self data_items = proto.RepeatedField( - proto.MESSAGE, number=1, message=data_item.DataItem, + proto.MESSAGE, + number=1, + message=data_item.DataItem, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class GetAnnotationSpecRequest(proto.Message): @@ -358,8 +452,15 @@ class GetAnnotationSpecRequest(proto.Message): Mask specifying which fields to read. """ - name = proto.Field(proto.STRING, number=1,) - read_mask = proto.Field(proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask,) + name = proto.Field( + proto.STRING, + number=1, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) class ListAnnotationsRequest(proto.Message): @@ -385,12 +486,31 @@ class ListAnnotationsRequest(proto.Message): field name for descending. """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) - read_mask = proto.Field(proto.MESSAGE, number=5, message=field_mask_pb2.FieldMask,) - order_by = proto.Field(proto.STRING, number=6,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=5, + message=field_mask_pb2.FieldMask, + ) + order_by = proto.Field( + proto.STRING, + number=6, + ) class ListAnnotationsResponse(proto.Message): @@ -410,9 +530,14 @@ def raw_page(self): return self annotations = proto.RepeatedField( - proto.MESSAGE, number=1, message=annotation.Annotation, + proto.MESSAGE, + number=1, + message=annotation.Annotation, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/deployed_index_ref.py b/google/cloud/aiplatform_v1beta1/types/deployed_index_ref.py index aa7f6edb67..a0b0df8f1d 100644 --- a/google/cloud/aiplatform_v1beta1/types/deployed_index_ref.py +++ b/google/cloud/aiplatform_v1beta1/types/deployed_index_ref.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,12 +17,16 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"DeployedIndexRef",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "DeployedIndexRef", + }, ) class DeployedIndexRef(proto.Message): r"""Points to a DeployedIndex. + Attributes: index_endpoint (str): Immutable. A resource name of the @@ -32,8 +36,14 @@ class DeployedIndexRef(proto.Message): above IndexEndpoint. """ - index_endpoint = proto.Field(proto.STRING, number=1,) - deployed_index_id = proto.Field(proto.STRING, number=2,) + index_endpoint = proto.Field( + proto.STRING, + number=1, + ) + deployed_index_id = proto.Field( + proto.STRING, + number=2, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/deployed_model_ref.py b/google/cloud/aiplatform_v1beta1/types/deployed_model_ref.py index da7e8bf211..b8bf44a76a 100644 --- a/google/cloud/aiplatform_v1beta1/types/deployed_model_ref.py +++ b/google/cloud/aiplatform_v1beta1/types/deployed_model_ref.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,12 +17,16 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"DeployedModelRef",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "DeployedModelRef", + }, ) class DeployedModelRef(proto.Message): r"""Points to a DeployedModel. + Attributes: endpoint (str): Immutable. A resource name of an Endpoint. @@ -31,8 +35,14 @@ class DeployedModelRef(proto.Message): above Endpoint. """ - endpoint = proto.Field(proto.STRING, number=1,) - deployed_model_id = proto.Field(proto.STRING, number=2,) + endpoint = proto.Field( + proto.STRING, + number=1, + ) + deployed_model_id = proto.Field( + proto.STRING, + number=2, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/encryption_spec.py b/google/cloud/aiplatform_v1beta1/types/encryption_spec.py index afe91ca5ac..e329a9b9f2 100644 --- a/google/cloud/aiplatform_v1beta1/types/encryption_spec.py +++ b/google/cloud/aiplatform_v1beta1/types/encryption_spec.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,7 +17,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"EncryptionSpec",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "EncryptionSpec", + }, ) @@ -35,7 +38,10 @@ class EncryptionSpec(proto.Message): resource is created. """ - kms_key_name = proto.Field(proto.STRING, number=1,) + kms_key_name = proto.Field( + proto.STRING, + number=1, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/endpoint.py b/google/cloud/aiplatform_v1beta1/types/endpoint.py index 7b35657bcc..fc4fabb8e0 100644 --- a/google/cloud/aiplatform_v1beta1/types/endpoint.py +++ b/google/cloud/aiplatform_v1beta1/types/endpoint.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,12 +17,19 @@ from google.cloud.aiplatform_v1beta1.types import encryption_spec as gca_encryption_spec from google.cloud.aiplatform_v1beta1.types import explanation +from google.cloud.aiplatform_v1beta1.types import io from google.cloud.aiplatform_v1beta1.types import machine_resources from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"Endpoint", "DeployedModel",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "Endpoint", + "DeployedModel", + "PrivateEndpoints", + "PredictRequestResponseLoggingConfig", + }, ) @@ -47,7 +54,7 @@ class Endpoint(proto.Message): and [EndpointService.UndeployModel][google.cloud.aiplatform.v1beta1.EndpointService.UndeployModel] respectively. - traffic_split (Sequence[google.cloud.aiplatform_v1beta1.types.Endpoint.TrafficSplitEntry]): + traffic_split (Mapping[str, int]): A map from a DeployedModel's ID to the percentage of this Endpoint's traffic that should be forwarded to that DeployedModel. @@ -61,7 +68,7 @@ class Endpoint(proto.Message): Used to perform consistent read-modify-write updates. If not set, a blind "overwrite" update happens. - labels (Sequence[google.cloud.aiplatform_v1beta1.types.Endpoint.LabelsEntry]): + labels (Mapping[str, str]): The labels with user-defined metadata to organize your Endpoints. Label keys and values can be no longer than 64 @@ -79,24 +86,109 @@ class Endpoint(proto.Message): last updated. encryption_spec (google.cloud.aiplatform_v1beta1.types.EncryptionSpec): Customer-managed encryption key spec for an - Endpoint. If set, this Endpoint and all sub- - resources of this Endpoint will be secured by - this key. + Endpoint. If set, this Endpoint and all + sub-resources of this Endpoint will be secured + by this key. + network (str): + The full name of the Google Compute Engine + `network `__ + to which the Endpoint should be peered. + + Private services access must already be configured for the + network. If left unspecified, the Endpoint is not peered + with any network. + + Only one of the fields, + [network][google.cloud.aiplatform.v1beta1.Endpoint.network] + or + [enable_private_service_connect][google.cloud.aiplatform.v1beta1.Endpoint.enable_private_service_connect], + can be set. + + `Format `__: + ``projects/{project}/global/networks/{network}``. Where + ``{project}`` is a project number, as in ``12345``, and + ``{network}`` is network name. + enable_private_service_connect (bool): + Deprecated: If true, expose the Endpoint via private service + connect. + + Only one of the fields, + [network][google.cloud.aiplatform.v1beta1.Endpoint.network] + or + [enable_private_service_connect][google.cloud.aiplatform.v1beta1.Endpoint.enable_private_service_connect], + can be set. + model_deployment_monitoring_job (str): + Output only. Resource name of the Model Monitoring job + associated with this Endpoint if monitoring is enabled by + [CreateModelDeploymentMonitoringJob][]. Format: + ``projects/{project}/locations/{location}/modelDeploymentMonitoringJobs/{model_deployment_monitoring_job}`` + predict_request_response_logging_config (google.cloud.aiplatform_v1beta1.types.PredictRequestResponseLoggingConfig): + Configures the request-response logging for + online prediction. """ - name = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) - description = proto.Field(proto.STRING, number=3,) + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + description = proto.Field( + proto.STRING, + number=3, + ) deployed_models = proto.RepeatedField( - proto.MESSAGE, number=4, message="DeployedModel", + proto.MESSAGE, + number=4, + message="DeployedModel", + ) + traffic_split = proto.MapField( + proto.STRING, + proto.INT32, + number=5, + ) + etag = proto.Field( + proto.STRING, + number=6, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=7, + ) + create_time = proto.Field( + proto.MESSAGE, + number=8, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=9, + message=timestamp_pb2.Timestamp, ) - traffic_split = proto.MapField(proto.STRING, proto.INT32, number=5,) - etag = proto.Field(proto.STRING, number=6,) - labels = proto.MapField(proto.STRING, proto.STRING, number=7,) - create_time = proto.Field(proto.MESSAGE, number=8, message=timestamp_pb2.Timestamp,) - update_time = proto.Field(proto.MESSAGE, number=9, message=timestamp_pb2.Timestamp,) encryption_spec = proto.Field( - proto.MESSAGE, number=10, message=gca_encryption_spec.EncryptionSpec, + proto.MESSAGE, + number=10, + message=gca_encryption_spec.EncryptionSpec, + ) + network = proto.Field( + proto.STRING, + number=13, + ) + enable_private_service_connect = proto.Field( + proto.BOOL, + number=17, + ) + model_deployment_monitoring_job = proto.Field( + proto.STRING, + number=14, + ) + predict_request_response_logging_config = proto.Field( + proto.MESSAGE, + number=18, + message="PredictRequestResponseLoggingConfig", ) @@ -104,22 +196,44 @@ class DeployedModel(proto.Message): r"""A deployment of a Model. Endpoints contain one or more DeployedModels. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: dedicated_resources (google.cloud.aiplatform_v1beta1.types.DedicatedResources): A description of resources that are dedicated to the DeployedModel, and that need a higher degree of manual configuration. + + This field is a member of `oneof`_ ``prediction_resources``. automatic_resources (google.cloud.aiplatform_v1beta1.types.AutomaticResources): A description of resources that to large - degree are decided by AI Platform, and require + degree are decided by Vertex AI, and require only a modest additional configuration. + + This field is a member of `oneof`_ ``prediction_resources``. id (str): - Output only. The ID of the DeployedModel. + Immutable. The ID of the DeployedModel. If not provided upon + deployment, Vertex AI will generate a value for this ID. + + This value should be 1-10 characters, and valid characters + are /[0-9]/. model (str): - Required. The name of the Model that this is - the deployment of. Note that the Model may be in - a different location than the DeployedModel's - Endpoint. + Required. The resource name of the Model that + this is the deployment of. Note that the Model + may be in a different location than the + DeployedModel's Endpoint. + The resource name may contain version id or + version alias to specify the version, if no + version is specified, the default version will + be deployed. + model_version_id (str): + Output only. The version ID of the model that + is deployed. display_name (str): The display name of the DeployedModel. If not provided upon creation, the Model's display_name is used. @@ -170,6 +284,13 @@ class DeployedModel(proto.Message): requests at a high queries per second rate (QPS). Estimate your costs before enabling this option. + private_endpoints (google.cloud.aiplatform_v1beta1.types.PrivateEndpoints): + Output only. Provide paths for users to send + predict/explain/health requests directly to the deployed + model services running on Cloud via private services access. + This field is populated if + [network][google.cloud.aiplatform.v1beta1.Endpoint.network] + is configured. """ dedicated_resources = proto.Field( @@ -184,16 +305,124 @@ class DeployedModel(proto.Message): oneof="prediction_resources", message=machine_resources.AutomaticResources, ) - id = proto.Field(proto.STRING, number=1,) - model = proto.Field(proto.STRING, number=2,) - display_name = proto.Field(proto.STRING, number=3,) - create_time = proto.Field(proto.MESSAGE, number=6, message=timestamp_pb2.Timestamp,) + id = proto.Field( + proto.STRING, + number=1, + ) + model = proto.Field( + proto.STRING, + number=2, + ) + model_version_id = proto.Field( + proto.STRING, + number=18, + ) + display_name = proto.Field( + proto.STRING, + number=3, + ) + create_time = proto.Field( + proto.MESSAGE, + number=6, + message=timestamp_pb2.Timestamp, + ) explanation_spec = proto.Field( - proto.MESSAGE, number=9, message=explanation.ExplanationSpec, + proto.MESSAGE, + number=9, + message=explanation.ExplanationSpec, + ) + service_account = proto.Field( + proto.STRING, + number=11, + ) + enable_container_logging = proto.Field( + proto.BOOL, + number=12, + ) + enable_access_logging = proto.Field( + proto.BOOL, + number=13, + ) + private_endpoints = proto.Field( + proto.MESSAGE, + number=14, + message="PrivateEndpoints", + ) + + +class PrivateEndpoints(proto.Message): + r"""PrivateEndpoints proto is used to provide paths for users to send + requests privately. To send request via private service access, use + predict_http_uri, explain_http_uri or health_http_uri. To send + request via private service connect, use service_attachment. + + Attributes: + predict_http_uri (str): + Output only. Http(s) path to send prediction + requests. + explain_http_uri (str): + Output only. Http(s) path to send explain + requests. + health_http_uri (str): + Output only. Http(s) path to send health + check requests. + service_attachment (str): + Output only. The name of the service + attachment resource. Populated if private + service connect is enabled. + """ + + predict_http_uri = proto.Field( + proto.STRING, + number=1, + ) + explain_http_uri = proto.Field( + proto.STRING, + number=2, + ) + health_http_uri = proto.Field( + proto.STRING, + number=3, + ) + service_attachment = proto.Field( + proto.STRING, + number=4, + ) + + +class PredictRequestResponseLoggingConfig(proto.Message): + r"""Configuration for logging request-response to a BigQuery + table. + + Attributes: + enabled (bool): + If logging is enabled or not. + sampling_rate (float): + Percentage of requests to be logged, expressed as a fraction + in range(0,1]. + bigquery_destination (google.cloud.aiplatform_v1beta1.types.BigQueryDestination): + BigQuery table for logging. If only given a project, a new + dataset will be created with name + ``logging__`` where will + be made BigQuery-dataset-name compatible (e.g. most special + characters will become underscores). If no table name is + given, a new table will be created with name + ``request_response_logging`` + """ + + enabled = proto.Field( + proto.BOOL, + number=1, + ) + sampling_rate = proto.Field( + proto.DOUBLE, + number=2, + ) + bigquery_destination = proto.Field( + proto.MESSAGE, + number=3, + message=io.BigQueryDestination, ) - service_account = proto.Field(proto.STRING, number=11,) - enable_container_logging = proto.Field(proto.BOOL, number=12,) - enable_access_logging = proto.Field(proto.BOOL, number=13,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/endpoint_service.py b/google/cloud/aiplatform_v1beta1/types/endpoint_service.py index 943c05c6e8..2eeebec5ff 100644 --- a/google/cloud/aiplatform_v1beta1/types/endpoint_service.py +++ b/google/cloud/aiplatform_v1beta1/types/endpoint_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -51,10 +51,31 @@ class CreateEndpointRequest(proto.Message): ``projects/{project}/locations/{location}`` endpoint (google.cloud.aiplatform_v1beta1.types.Endpoint): Required. The Endpoint to create. + endpoint_id (str): + Immutable. The ID to use for endpoint, which will become the + final component of the endpoint resource name. If not + provided, Vertex AI will generate a value for this ID. + + This value should be 1-10 characters, and valid characters + are /[0-9]/. When using HTTP/JSON, this field is populated + based on a query string argument, such as + ``?endpoint_id=12345``. This is the fallback for fields that + are not included in either the URI or the body. """ - parent = proto.Field(proto.STRING, number=1,) - endpoint = proto.Field(proto.MESSAGE, number=2, message=gca_endpoint.Endpoint,) + parent = proto.Field( + proto.STRING, + number=1, + ) + endpoint = proto.Field( + proto.MESSAGE, + number=2, + message=gca_endpoint.Endpoint, + ) + endpoint_id = proto.Field( + proto.STRING, + number=4, + ) class CreateEndpointOperationMetadata(proto.Message): @@ -67,7 +88,9 @@ class CreateEndpointOperationMetadata(proto.Message): """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, ) @@ -81,7 +104,10 @@ class GetEndpointRequest(proto.Message): ``projects/{project}/locations/{location}/endpoints/{endpoint}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListEndpointsRequest(proto.Message): @@ -129,11 +155,27 @@ class ListEndpointsRequest(proto.Message): read. """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) - read_mask = proto.Field(proto.MESSAGE, number=5, message=field_mask_pb2.FieldMask,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=5, + message=field_mask_pb2.FieldMask, + ) class ListEndpointsResponse(proto.Message): @@ -154,9 +196,14 @@ def raw_page(self): return self endpoints = proto.RepeatedField( - proto.MESSAGE, number=1, message=gca_endpoint.Endpoint, + proto.MESSAGE, + number=1, + message=gca_endpoint.Endpoint, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class UpdateEndpointRequest(proto.Message): @@ -169,12 +216,18 @@ class UpdateEndpointRequest(proto.Message): resource on the server. update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. The update mask applies to the resource. See - `FieldMask `__. + [google.protobuf.FieldMask][google.protobuf.FieldMask]. """ - endpoint = proto.Field(proto.MESSAGE, number=1, message=gca_endpoint.Endpoint,) + endpoint = proto.Field( + proto.MESSAGE, + number=1, + message=gca_endpoint.Endpoint, + ) update_mask = proto.Field( - proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, ) @@ -189,7 +242,10 @@ class DeleteEndpointRequest(proto.Message): ``projects/{project}/locations/{location}/endpoints/{endpoint}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class DeployModelRequest(proto.Message): @@ -208,7 +264,7 @@ class DeployModelRequest(proto.Message): must be updated for the DeployedModel to start receiving traffic, either as part of this call, or via [EndpointService.UpdateEndpoint][google.cloud.aiplatform.v1beta1.EndpointService.UpdateEndpoint]. - traffic_split (Sequence[google.cloud.aiplatform_v1beta1.types.DeployModelRequest.TrafficSplitEntry]): + traffic_split (Mapping[str, int]): A map from a DeployedModel's ID to the percentage of this Endpoint's traffic that should be forwarded to that DeployedModel. @@ -226,11 +282,20 @@ class DeployModelRequest(proto.Message): is not updated. """ - endpoint = proto.Field(proto.STRING, number=1,) + endpoint = proto.Field( + proto.STRING, + number=1, + ) deployed_model = proto.Field( - proto.MESSAGE, number=2, message=gca_endpoint.DeployedModel, + proto.MESSAGE, + number=2, + message=gca_endpoint.DeployedModel, + ) + traffic_split = proto.MapField( + proto.STRING, + proto.INT32, + number=3, ) - traffic_split = proto.MapField(proto.STRING, proto.INT32, number=3,) class DeployModelResponse(proto.Message): @@ -244,7 +309,9 @@ class DeployModelResponse(proto.Message): """ deployed_model = proto.Field( - proto.MESSAGE, number=1, message=gca_endpoint.DeployedModel, + proto.MESSAGE, + number=1, + message=gca_endpoint.DeployedModel, ) @@ -258,7 +325,9 @@ class DeployModelOperationMetadata(proto.Message): """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, ) @@ -274,7 +343,7 @@ class UndeployModelRequest(proto.Message): deployed_model_id (str): Required. The ID of the DeployedModel to be undeployed from the Endpoint. - traffic_split (Sequence[google.cloud.aiplatform_v1beta1.types.UndeployModelRequest.TrafficSplitEntry]): + traffic_split (Mapping[str, int]): If this field is provided, then the Endpoint's [traffic_split][google.cloud.aiplatform.v1beta1.Endpoint.traffic_split] will be overwritten with it. If last DeployedModel is being @@ -285,15 +354,26 @@ class UndeployModelRequest(proto.Message): executes, or if this field unassigns any traffic to it. """ - endpoint = proto.Field(proto.STRING, number=1,) - deployed_model_id = proto.Field(proto.STRING, number=2,) - traffic_split = proto.MapField(proto.STRING, proto.INT32, number=3,) + endpoint = proto.Field( + proto.STRING, + number=1, + ) + deployed_model_id = proto.Field( + proto.STRING, + number=2, + ) + traffic_split = proto.MapField( + proto.STRING, + proto.INT32, + number=3, + ) class UndeployModelResponse(proto.Message): r"""Response message for [EndpointService.UndeployModel][google.cloud.aiplatform.v1beta1.EndpointService.UndeployModel]. - """ + + """ class UndeployModelOperationMetadata(proto.Message): @@ -306,7 +386,9 @@ class UndeployModelOperationMetadata(proto.Message): """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, ) diff --git a/google/cloud/aiplatform_v1beta1/types/entity_type.py b/google/cloud/aiplatform_v1beta1/types/entity_type.py index 2900f05fae..2e29d24000 100644 --- a/google/cloud/aiplatform_v1beta1/types/entity_type.py +++ b/google/cloud/aiplatform_v1beta1/types/entity_type.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,7 +20,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"EntityType",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "EntityType", + }, ) @@ -48,7 +51,7 @@ class EntityType(proto.Message): update_time (google.protobuf.timestamp_pb2.Timestamp): Output only. Timestamp when this EntityType was most recently updated. - labels (Sequence[google.cloud.aiplatform_v1beta1.types.EntityType.LabelsEntry]): + labels (Mapping[str, str]): Optional. The labels with user-defined metadata to organize your EntityTypes. Label keys and values can be no longer than 64 @@ -63,12 +66,14 @@ class EntityType(proto.Message): System reserved label keys are prefixed with "aiplatform.googleapis.com/" and are immutable. etag (str): - Optional. Used to perform a consistent read- - odify-write updates. If not set, a blind + Optional. Used to perform a consistent + read-modify-write updates. If not set, a blind "overwrite" update happens. monitoring_config (google.cloud.aiplatform_v1beta1.types.FeaturestoreMonitoringConfig): Optional. The default monitoring configuration for all - Features under this EntityType. + Features with value type + ([Feature.ValueType][google.cloud.aiplatform.v1beta1.Feature.ValueType]) + BOOL, STRING, DOUBLE or INT64 under this EntityType. If this is populated with [FeaturestoreMonitoringConfig.monitoring_interval] @@ -76,12 +81,33 @@ class EntityType(proto.Message): Otherwise, snapshot analysis monitoring is disabled. """ - name = proto.Field(proto.STRING, number=1,) - description = proto.Field(proto.STRING, number=2,) - create_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) - update_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) - labels = proto.MapField(proto.STRING, proto.STRING, number=6,) - etag = proto.Field(proto.STRING, number=7,) + name = proto.Field( + proto.STRING, + number=1, + ) + description = proto.Field( + proto.STRING, + number=2, + ) + create_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=6, + ) + etag = proto.Field( + proto.STRING, + number=7, + ) monitoring_config = proto.Field( proto.MESSAGE, number=8, diff --git a/google/cloud/aiplatform_v1beta1/types/env_var.py b/google/cloud/aiplatform_v1beta1/types/env_var.py index ae40154685..527251215e 100644 --- a/google/cloud/aiplatform_v1beta1/types/env_var.py +++ b/google/cloud/aiplatform_v1beta1/types/env_var.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,7 +17,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"EnvVar",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "EnvVar", + }, ) @@ -40,8 +43,14 @@ class EnvVar(proto.Message): variable exists or not. """ - name = proto.Field(proto.STRING, number=1,) - value = proto.Field(proto.STRING, number=2,) + name = proto.Field( + proto.STRING, + number=1, + ) + value = proto.Field( + proto.STRING, + number=2, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/event.py b/google/cloud/aiplatform_v1beta1/types/event.py index fc48ff6710..747f55ccd2 100644 --- a/google/cloud/aiplatform_v1beta1/types/event.py +++ b/google/cloud/aiplatform_v1beta1/types/event.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,7 +19,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"Event",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "Event", + }, ) @@ -38,7 +41,7 @@ class Event(proto.Message): Output only. Time the Event occurred. type_ (google.cloud.aiplatform_v1beta1.types.Event.Type): Required. The type of the Event. - labels (Sequence[google.cloud.aiplatform_v1beta1.types.Event.LabelsEntry]): + labels (Mapping[str, str]): The labels with user-defined metadata to annotate Events. Label keys and values can be no longer than 64 @@ -63,11 +66,29 @@ class Type(proto.Enum): INPUT = 1 OUTPUT = 2 - artifact = proto.Field(proto.STRING, number=1,) - execution = proto.Field(proto.STRING, number=2,) - event_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) - type_ = proto.Field(proto.ENUM, number=4, enum=Type,) - labels = proto.MapField(proto.STRING, proto.STRING, number=5,) + artifact = proto.Field( + proto.STRING, + number=1, + ) + execution = proto.Field( + proto.STRING, + number=2, + ) + event_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + type_ = proto.Field( + proto.ENUM, + number=4, + enum=Type, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=5, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/execution.py b/google/cloud/aiplatform_v1beta1/types/execution.py index a564e1122b..937c7a4041 100644 --- a/google/cloud/aiplatform_v1beta1/types/execution.py +++ b/google/cloud/aiplatform_v1beta1/types/execution.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,12 +20,16 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"Execution",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "Execution", + }, ) class Execution(proto.Message): r"""Instance of a general execution. + Attributes: name (str): Output only. The resource name of the @@ -37,14 +41,14 @@ class Execution(proto.Message): The state of this Execution. This is a property of the Execution, and does not imply or capture any ongoing process. This property is - managed by clients (such as AI Platform - Pipelines) and the system does not prescribe or - check the validity of state transitions. + managed by clients (such as Vertex AI Pipelines) + and the system does not prescribe or check the + validity of state transitions. etag (str): - An eTag used to perform consistent read- - odify-write updates. If not set, a blind + An eTag used to perform consistent + read-modify-write updates. If not set, a blind "overwrite" update happens. - labels (Sequence[google.cloud.aiplatform_v1beta1.types.Execution.LabelsEntry]): + labels (Mapping[str, str]): The labels with user-defined metadata to organize your Executions. Label keys and values can be no longer than 64 @@ -69,7 +73,7 @@ class Execution(proto.Message): identify schemas within the local metadata store. schema_version (str): - The version of the schema in schema_name to use. + The version of the schema in ``schema_title`` to use. Schema title and version is expected to be registered in earlier Create Schema calls. And both are used together as @@ -77,6 +81,7 @@ class Execution(proto.Message): metadata store. metadata (google.protobuf.struct_pb2.Struct): Properties of the Execution. + The size of this field should not exceed 200KB. description (str): Description of the Execution """ @@ -88,22 +93,58 @@ class State(proto.Enum): RUNNING = 2 COMPLETE = 3 FAILED = 4 + CACHED = 5 + CANCELLED = 6 - name = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) - state = proto.Field(proto.ENUM, number=6, enum=State,) - etag = proto.Field(proto.STRING, number=9,) - labels = proto.MapField(proto.STRING, proto.STRING, number=10,) + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + state = proto.Field( + proto.ENUM, + number=6, + enum=State, + ) + etag = proto.Field( + proto.STRING, + number=9, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=10, + ) create_time = proto.Field( - proto.MESSAGE, number=11, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=11, + message=timestamp_pb2.Timestamp, ) update_time = proto.Field( - proto.MESSAGE, number=12, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=12, + message=timestamp_pb2.Timestamp, + ) + schema_title = proto.Field( + proto.STRING, + number=13, + ) + schema_version = proto.Field( + proto.STRING, + number=14, + ) + metadata = proto.Field( + proto.MESSAGE, + number=15, + message=struct_pb2.Struct, + ) + description = proto.Field( + proto.STRING, + number=16, ) - schema_title = proto.Field(proto.STRING, number=13,) - schema_version = proto.Field(proto.STRING, number=14,) - metadata = proto.Field(proto.MESSAGE, number=15, message=struct_pb2.Struct,) - description = proto.Field(proto.STRING, number=16,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/explanation.py b/google/cloud/aiplatform_v1beta1/types/explanation.py index d1c94d1d83..a276c39b41 100644 --- a/google/cloud/aiplatform_v1beta1/types/explanation.py +++ b/google/cloud/aiplatform_v1beta1/types/explanation.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ import proto # type: ignore from google.cloud.aiplatform_v1beta1.types import explanation_metadata +from google.cloud.aiplatform_v1beta1.types import io from google.protobuf import struct_pb2 # type: ignore @@ -25,6 +26,7 @@ "Explanation", "ModelExplanation", "Attribution", + "Neighbor", "ExplanationSpec", "ExplanationParameters", "SampledShapleyAttribution", @@ -32,8 +34,13 @@ "XraiAttribution", "SmoothGradConfig", "FeatureNoiseSigma", + "BlurBaselineConfig", + "Examples", + "Presets", "ExplanationSpecOverride", "ExplanationMetadataOverride", + "ExamplesOverride", + "ExamplesRestrictionsNamespace", }, ) @@ -68,9 +75,25 @@ class Explanation(proto.Message): is specified, the attributions are stored by [Attribution.output_index][google.cloud.aiplatform.v1beta1.Attribution.output_index] in the same order as they appear in the output_indices. + neighbors (Sequence[google.cloud.aiplatform_v1beta1.types.Neighbor]): + Output only. List of the nearest neighbors + for example-based explanations. + For models deployed with the examples + explanations feature enabled, the attributions + field is empty and instead the neighbors field + is populated. """ - attributions = proto.RepeatedField(proto.MESSAGE, number=1, message="Attribution",) + attributions = proto.RepeatedField( + proto.MESSAGE, + number=1, + message="Attribution", + ) + neighbors = proto.RepeatedField( + proto.MESSAGE, + number=2, + message="Neighbor", + ) class ModelExplanation(proto.Message): @@ -108,12 +131,15 @@ class ModelExplanation(proto.Message): """ mean_attributions = proto.RepeatedField( - proto.MESSAGE, number=1, message="Attribution", + proto.MESSAGE, + number=1, + message="Attribution", ) class Attribution(proto.Message): r"""Attribution that explains a particular prediction output. + Attributes: baseline_output_value (float): Output only. Model predicted output if the input instance is @@ -219,7 +245,7 @@ class Attribution(proto.Message): might reduce the error. See `this - introduction `__ + introduction `__ for more information. output_name (str): Output only. Name of the explain output. Specified as the @@ -227,19 +253,60 @@ class Attribution(proto.Message): [ExplanationMetadata.outputs][google.cloud.aiplatform.v1beta1.ExplanationMetadata.outputs]. """ - baseline_output_value = proto.Field(proto.DOUBLE, number=1,) - instance_output_value = proto.Field(proto.DOUBLE, number=2,) + baseline_output_value = proto.Field( + proto.DOUBLE, + number=1, + ) + instance_output_value = proto.Field( + proto.DOUBLE, + number=2, + ) feature_attributions = proto.Field( - proto.MESSAGE, number=3, message=struct_pb2.Value, + proto.MESSAGE, + number=3, + message=struct_pb2.Value, + ) + output_index = proto.RepeatedField( + proto.INT32, + number=4, + ) + output_display_name = proto.Field( + proto.STRING, + number=5, + ) + approximation_error = proto.Field( + proto.DOUBLE, + number=6, + ) + output_name = proto.Field( + proto.STRING, + number=7, + ) + + +class Neighbor(proto.Message): + r"""Neighbors for example-based explanations. + + Attributes: + neighbor_id (str): + Output only. The neighbor id. + neighbor_distance (float): + Output only. The neighbor distance. + """ + + neighbor_id = proto.Field( + proto.STRING, + number=1, + ) + neighbor_distance = proto.Field( + proto.DOUBLE, + number=2, ) - output_index = proto.RepeatedField(proto.INT32, number=4,) - output_display_name = proto.Field(proto.STRING, number=5,) - approximation_error = proto.Field(proto.DOUBLE, number=6,) - output_name = proto.Field(proto.STRING, number=7,) class ExplanationSpec(proto.Message): r"""Specification of Model explanation. + Attributes: parameters (google.cloud.aiplatform_v1beta1.types.ExplanationParameters): Required. Parameters that configure @@ -249,14 +316,28 @@ class ExplanationSpec(proto.Message): input and output for explanation. """ - parameters = proto.Field(proto.MESSAGE, number=1, message="ExplanationParameters",) + parameters = proto.Field( + proto.MESSAGE, + number=1, + message="ExplanationParameters", + ) metadata = proto.Field( - proto.MESSAGE, number=2, message=explanation_metadata.ExplanationMetadata, + proto.MESSAGE, + number=2, + message=explanation_metadata.ExplanationMetadata, ) class ExplanationParameters(proto.Message): r"""Parameters to configure explaining for Model's predictions. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: sampled_shapley_attribution (google.cloud.aiplatform_v1beta1.types.SampledShapleyAttribution): An attribution method that approximates @@ -266,12 +347,16 @@ class ExplanationParameters(proto.Message): considering all subsets of features. Refer to this paper for model details: https://arxiv.org/abs/1306.4265. + + This field is a member of `oneof`_ ``method``. integrated_gradients_attribution (google.cloud.aiplatform_v1beta1.types.IntegratedGradientsAttribution): - An attribution method that computes Aumann- - hapley values taking advantage of the model's - fully differentiable structure. Refer to this - paper for more details: + An attribution method that computes + Aumann-Shapley values taking advantage of the + model's fully differentiable structure. Refer to + this paper for more details: https://arxiv.org/abs/1703.01365 + + This field is a member of `oneof`_ ``method``. xrai_attribution (google.cloud.aiplatform_v1beta1.types.XraiAttribution): An attribution method that redistributes Integrated Gradients attribution to segmented @@ -286,6 +371,13 @@ class ExplanationParameters(proto.Message): or from diagnostic equipment, like x-rays or quality-control cameras, use Integrated Gradients instead. + + This field is a member of `oneof`_ ``method``. + examples (google.cloud.aiplatform_v1beta1.types.Examples): + Example-based explanations that returns the + nearest neighbors from the provided dataset. + + This field is a member of `oneof`_ ``method``. top_k (int): If populated, returns attributions for top K indices of outputs (defaults to 1). Only applies @@ -308,7 +400,10 @@ class ExplanationParameters(proto.Message): """ sampled_shapley_attribution = proto.Field( - proto.MESSAGE, number=1, oneof="method", message="SampledShapleyAttribution", + proto.MESSAGE, + number=1, + oneof="method", + message="SampledShapleyAttribution", ) integrated_gradients_attribution = proto.Field( proto.MESSAGE, @@ -317,10 +412,26 @@ class ExplanationParameters(proto.Message): message="IntegratedGradientsAttribution", ) xrai_attribution = proto.Field( - proto.MESSAGE, number=3, oneof="method", message="XraiAttribution", + proto.MESSAGE, + number=3, + oneof="method", + message="XraiAttribution", + ) + examples = proto.Field( + proto.MESSAGE, + number=7, + oneof="method", + message="Examples", + ) + top_k = proto.Field( + proto.INT32, + number=4, + ) + output_indices = proto.Field( + proto.MESSAGE, + number=5, + message=struct_pb2.ListValue, ) - top_k = proto.Field(proto.INT32, number=4,) - output_indices = proto.Field(proto.MESSAGE, number=5, message=struct_pb2.ListValue,) class SampledShapleyAttribution(proto.Message): @@ -337,7 +448,10 @@ class SampledShapleyAttribution(proto.Message): Valid range of its value is [1, 50], inclusively. """ - path_count = proto.Field(proto.INT32, number=1,) + path_count = proto.Field( + proto.INT32, + number=1, + ) class IntegratedGradientsAttribution(proto.Message): @@ -363,11 +477,28 @@ class IntegratedGradientsAttribution(proto.Message): help improve the computed gradients. Refer to this paper for more details: https://arxiv.org/pdf/1706.03825.pdf + blur_baseline_config (google.cloud.aiplatform_v1beta1.types.BlurBaselineConfig): + Config for IG with blur baseline. + When enabled, a linear path from the maximally + blurred image to the input image is created. + Using a blurred baseline instead of zero (black + image) is motivated by the BlurIG approach + explained here: https://arxiv.org/abs/2004.03383 """ - step_count = proto.Field(proto.INT32, number=1,) + step_count = proto.Field( + proto.INT32, + number=1, + ) smooth_grad_config = proto.Field( - proto.MESSAGE, number=2, message="SmoothGradConfig", + proto.MESSAGE, + number=2, + message="SmoothGradConfig", + ) + blur_baseline_config = proto.Field( + proto.MESSAGE, + number=3, + message="BlurBaselineConfig", ) @@ -396,11 +527,28 @@ class XraiAttribution(proto.Message): help improve the computed gradients. Refer to this paper for more details: https://arxiv.org/pdf/1706.03825.pdf + blur_baseline_config (google.cloud.aiplatform_v1beta1.types.BlurBaselineConfig): + Config for XRAI with blur baseline. + When enabled, a linear path from the maximally + blurred image to the input image is created. + Using a blurred baseline instead of zero (black + image) is motivated by the BlurIG approach + explained here: https://arxiv.org/abs/2004.03383 """ - step_count = proto.Field(proto.INT32, number=1,) + step_count = proto.Field( + proto.INT32, + number=1, + ) smooth_grad_config = proto.Field( - proto.MESSAGE, number=2, message="SmoothGradConfig", + proto.MESSAGE, + number=2, + message="SmoothGradConfig", + ) + blur_baseline_config = proto.Field( + proto.MESSAGE, + number=3, + message="BlurBaselineConfig", ) @@ -412,14 +560,21 @@ class SmoothGradConfig(proto.Message): this paper for more details: https://arxiv.org/pdf/1706.03825.pdf + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: noise_sigma (float): This is a single float value and will be used to add noise to all the features. Use this field when all features are normalized to have the same distribution: scale to range [0, 1], [-1, 1] or z-scoring, where features are normalized to - have 0-mean and 1-variance. For more details about - normalization: https://tinyurl.com/dgc-normalization. + have 0-mean and 1-variance. Learn more about + `normalization `__. For best results the recommended value is about 10% - 20% of the standard deviation of the input feature. Refer to @@ -429,6 +584,8 @@ class SmoothGradConfig(proto.Message): If the distribution is different per feature, set [feature_noise_sigma][google.cloud.aiplatform.v1beta1.SmoothGradConfig.feature_noise_sigma] instead for each feature. + + This field is a member of `oneof`_ ``GradientNoiseSigma``. feature_noise_sigma (google.cloud.aiplatform_v1beta1.types.FeatureNoiseSigma): This is similar to [noise_sigma][google.cloud.aiplatform.v1beta1.SmoothGradConfig.noise_sigma], @@ -438,6 +595,8 @@ class SmoothGradConfig(proto.Message): that are not set. If this field is unset, [noise_sigma][google.cloud.aiplatform.v1beta1.SmoothGradConfig.noise_sigma] will be used for all features. + + This field is a member of `oneof`_ ``GradientNoiseSigma``. noisy_sample_count (int): The number of gradient samples to use for approximation. The higher this number, the more accurate the gradient is, but @@ -445,14 +604,21 @@ class SmoothGradConfig(proto.Message): Valid range of its value is [1, 50]. Defaults to 3. """ - noise_sigma = proto.Field(proto.FLOAT, number=1, oneof="GradientNoiseSigma",) + noise_sigma = proto.Field( + proto.FLOAT, + number=1, + oneof="GradientNoiseSigma", + ) feature_noise_sigma = proto.Field( proto.MESSAGE, number=2, oneof="GradientNoiseSigma", message="FeatureNoiseSigma", ) - noisy_sample_count = proto.Field(proto.INT32, number=3,) + noisy_sample_count = proto.Field( + proto.INT32, + number=3, + ) class FeatureNoiseSigma(proto.Message): @@ -468,6 +634,7 @@ class FeatureNoiseSigma(proto.Message): class NoiseSigmaForFeature(proto.Message): r"""Noise sigma for a single feature. + Attributes: name (str): The name of the input feature for which noise sigma is @@ -482,11 +649,137 @@ class NoiseSigmaForFeature(proto.Message): Defaults to 0.1. """ - name = proto.Field(proto.STRING, number=1,) - sigma = proto.Field(proto.FLOAT, number=2,) + name = proto.Field( + proto.STRING, + number=1, + ) + sigma = proto.Field( + proto.FLOAT, + number=2, + ) noise_sigma = proto.RepeatedField( - proto.MESSAGE, number=1, message=NoiseSigmaForFeature, + proto.MESSAGE, + number=1, + message=NoiseSigmaForFeature, + ) + + +class BlurBaselineConfig(proto.Message): + r"""Config for blur baseline. + When enabled, a linear path from the maximally blurred image to + the input image is created. Using a blurred baseline instead of + zero (black image) is motivated by the BlurIG approach explained + here: + https://arxiv.org/abs/2004.03383 + + Attributes: + max_blur_sigma (float): + The standard deviation of the blur kernel for + the blurred baseline. The same blurring + parameter is used for both the height and the + width dimension. If not set, the method defaults + to the zero (i.e. black for images) baseline. + """ + + max_blur_sigma = proto.Field( + proto.FLOAT, + number=1, + ) + + +class Examples(proto.Message): + r"""Example-based explainability that returns the nearest + neighbors from the provided dataset. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + nearest_neighbor_search_config (google.protobuf.struct_pb2.Value): + The configuration for the generated index, the semantics are + the same as + [metadata][google.cloud.aiplatform.v1beta1.Index.metadata] + and should match NearestNeighborSearchConfig. + + This field is a member of `oneof`_ ``config``. + presets (google.cloud.aiplatform_v1beta1.types.Presets): + Preset config based on the desired query + speed-precision trade-off and modality + + This field is a member of `oneof`_ ``config``. + gcs_source (google.cloud.aiplatform_v1beta1.types.GcsSource): + The Cloud Storage location for the input + instances. + neighbor_count (int): + The number of neighbors to return. + """ + + nearest_neighbor_search_config = proto.Field( + proto.MESSAGE, + number=2, + oneof="config", + message=struct_pb2.Value, + ) + presets = proto.Field( + proto.MESSAGE, + number=4, + oneof="config", + message="Presets", + ) + gcs_source = proto.Field( + proto.MESSAGE, + number=1, + message=io.GcsSource, + ) + neighbor_count = proto.Field( + proto.INT32, + number=3, + ) + + +class Presets(proto.Message): + r"""Preset configuration for example-based explanations + + Attributes: + query (google.cloud.aiplatform_v1beta1.types.Presets.Query): + Preset option controlling parameters for + query speed-precision trade-off + + This field is a member of `oneof`_ ``_query``. + modality (google.cloud.aiplatform_v1beta1.types.Presets.Modality): + Preset option controlling parameters for + different modalities + """ + + class Query(proto.Enum): + r"""Preset option controlling parameters for query + speed-precision trade-off + """ + PRECISE = 0 + FAST = 1 + + class Modality(proto.Enum): + r"""Preset option controlling parameters for different modalities""" + MODALITY_UNSPECIFIED = 0 + IMAGE = 1 + TEXT = 2 + TABULAR = 3 + + query = proto.Field( + proto.ENUM, + number=1, + optional=True, + enum=Query, + ) + modality = proto.Field( + proto.ENUM, + number=2, + enum=Modality, ) @@ -494,7 +787,7 @@ class ExplanationSpecOverride(proto.Message): r"""The [ExplanationSpec][google.cloud.aiplatform.v1beta1.ExplanationSpec] entries that can be overridden at [online - explanation][PredictionService.Explain][google.cloud.aiplatform.v1beta1.PredictionService.Explain] + explanation][google.cloud.aiplatform.v1beta1.PredictionService.Explain] time. Attributes: @@ -506,11 +799,25 @@ class ExplanationSpecOverride(proto.Message): metadata (google.cloud.aiplatform_v1beta1.types.ExplanationMetadataOverride): The metadata to be overridden. If not specified, no metadata is overridden. + examples_override (google.cloud.aiplatform_v1beta1.types.ExamplesOverride): + The example-based explanations parameter + overrides. """ - parameters = proto.Field(proto.MESSAGE, number=1, message="ExplanationParameters",) + parameters = proto.Field( + proto.MESSAGE, + number=1, + message="ExplanationParameters", + ) metadata = proto.Field( - proto.MESSAGE, number=2, message="ExplanationMetadataOverride", + proto.MESSAGE, + number=2, + message="ExplanationMetadataOverride", + ) + examples_override = proto.Field( + proto.MESSAGE, + number=3, + message="ExamplesOverride", ) @@ -522,7 +829,7 @@ class ExplanationMetadataOverride(proto.Message): time. Attributes: - inputs (Sequence[google.cloud.aiplatform_v1beta1.types.ExplanationMetadataOverride.InputsEntry]): + inputs (Mapping[str, google.cloud.aiplatform_v1beta1.types.ExplanationMetadataOverride.InputMetadataOverride]): Required. Overrides the [input metadata][google.cloud.aiplatform.v1beta1.ExplanationMetadata.inputs] of the features. The key is the name of the feature to be @@ -549,11 +856,93 @@ class InputMetadataOverride(proto.Message): """ input_baselines = proto.RepeatedField( - proto.MESSAGE, number=1, message=struct_pb2.Value, + proto.MESSAGE, + number=1, + message=struct_pb2.Value, ) inputs = proto.MapField( - proto.STRING, proto.MESSAGE, number=1, message=InputMetadataOverride, + proto.STRING, + proto.MESSAGE, + number=1, + message=InputMetadataOverride, + ) + + +class ExamplesOverride(proto.Message): + r"""Overrides for example-based explanations. + + Attributes: + neighbor_count (int): + The number of neighbors to return. + crowding_count (int): + The number of neighbors to return that have + the same crowding tag. + restrictions (Sequence[google.cloud.aiplatform_v1beta1.types.ExamplesRestrictionsNamespace]): + Restrict the resulting nearest neighbors to + respect these constraints. + return_embeddings (bool): + If true, return the embeddings instead of + neighbors. + data_format (google.cloud.aiplatform_v1beta1.types.ExamplesOverride.DataFormat): + The format of the data being provided with + each call. + """ + + class DataFormat(proto.Enum): + r"""Data format enum.""" + DATA_FORMAT_UNSPECIFIED = 0 + INSTANCES = 1 + EMBEDDINGS = 2 + + neighbor_count = proto.Field( + proto.INT32, + number=1, + ) + crowding_count = proto.Field( + proto.INT32, + number=2, + ) + restrictions = proto.RepeatedField( + proto.MESSAGE, + number=3, + message="ExamplesRestrictionsNamespace", + ) + return_embeddings = proto.Field( + proto.BOOL, + number=4, + ) + data_format = proto.Field( + proto.ENUM, + number=5, + enum=DataFormat, + ) + + +class ExamplesRestrictionsNamespace(proto.Message): + r"""Restrictions namespace for example-based explanations + overrides. + + Attributes: + namespace_name (str): + The namespace name. + allow (Sequence[str]): + The list of allowed tags. + deny (Sequence[str]): + The list of deny tags. + """ + + namespace_name = proto.Field( + proto.STRING, + number=1, + ) + allow = proto.RepeatedField( + proto.STRING, + number=2, + ) + deny = proto.RepeatedField( + proto.STRING, + number=3, ) diff --git a/google/cloud/aiplatform_v1beta1/types/explanation_metadata.py b/google/cloud/aiplatform_v1beta1/types/explanation_metadata.py index 70f1a5339c..e70c882d50 100644 --- a/google/cloud/aiplatform_v1beta1/types/explanation_metadata.py +++ b/google/cloud/aiplatform_v1beta1/types/explanation_metadata.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,7 +19,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"ExplanationMetadata",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "ExplanationMetadata", + }, ) @@ -28,7 +31,7 @@ class ExplanationMetadata(proto.Message): explanation. Attributes: - inputs (Sequence[google.cloud.aiplatform_v1beta1.types.ExplanationMetadata.InputsEntry]): + inputs (Mapping[str, google.cloud.aiplatform_v1beta1.types.ExplanationMetadata.InputMetadata]): Required. Map from feature names to feature input metadata. Keys are the name of the features. Values are the specification of the feature. @@ -36,19 +39,19 @@ class ExplanationMetadata(proto.Message): An empty InputMetadata is valid. It describes a text feature which has the name specified as the key in [ExplanationMetadata.inputs][google.cloud.aiplatform.v1beta1.ExplanationMetadata.inputs]. - The baseline of the empty feature is chosen by AI Platform. + The baseline of the empty feature is chosen by Vertex AI. - For AI Platform provided Tensorflow images, the key can be - any friendly name of the feature. Once specified, + For Vertex AI-provided Tensorflow images, the key can be any + friendly name of the feature. Once specified, [featureAttributions][google.cloud.aiplatform.v1beta1.Attribution.feature_attributions] are keyed by this key (if not grouped with another feature). For custom images, the key must match with the key in [instance][google.cloud.aiplatform.v1beta1.ExplainRequest.instances]. - outputs (Sequence[google.cloud.aiplatform_v1beta1.types.ExplanationMetadata.OutputsEntry]): + outputs (Mapping[str, google.cloud.aiplatform_v1beta1.types.ExplanationMetadata.OutputMetadata]): Required. Map from output names to output metadata. - For AI Platform provided Tensorflow images, keys + For Vertex AI-provided Tensorflow images, keys can be any user defined string that consists of any UTF-8 characters. For custom images, keys are the name of the @@ -60,12 +63,15 @@ class ExplanationMetadata(proto.Message): describing the format of the [feature attributions][google.cloud.aiplatform.v1beta1.Attribution.feature_attributions]. The schema is defined as an OpenAPI 3.0.2 `Schema - Object `__. - AutoML tabular Models always have this field populated by AI - Platform. Note: The URI given on output may be different, + Object `__. + AutoML tabular Models always have this field populated by + Vertex AI. Note: The URI given on output may be different, including the URI scheme, than the one given on input. The output URI will point to a location where the user only has a read access. + latent_space_source (str): + Name of the source to generate embeddings for + example based explanations. """ class InputMetadata(proto.Message): @@ -73,22 +79,22 @@ class InputMetadata(proto.Message): Fields other than [InputMetadata.input_baselines][google.cloud.aiplatform.v1beta1.ExplanationMetadata.InputMetadata.input_baselines] - are applicable only for Models that are using AI Platform-provided + are applicable only for Models that are using Vertex AI-provided images for Tensorflow. Attributes: input_baselines (Sequence[google.protobuf.struct_pb2.Value]): Baseline inputs for this feature. - If no baseline is specified, AI Platform chooses the - baseline for this feature. If multiple baselines are - specified, AI Platform returns the average attributions - across them in [Attributions.baseline_attribution][]. + If no baseline is specified, Vertex AI chooses the baseline + for this feature. If multiple baselines are specified, + Vertex AI returns the average attributions across them in + [Attribution.feature_attributions][google.cloud.aiplatform.v1beta1.Attribution.feature_attributions]. - For AI Platform provided Tensorflow images (both 1.x and - 2.x), the shape of each baseline must match the shape of the - input tensor. If a scalar is provided, we broadcast to the - same shape as the input tensor. + For Vertex AI-provided Tensorflow images (both 1.x and 2.x), + the shape of each baseline must match the shape of the input + tensor. If a scalar is provided, we broadcast to the same + shape as the input tensor. For custom images, the element of the baselines must be in the same format as the feature's input in the @@ -100,8 +106,8 @@ class InputMetadata(proto.Message): [instance_schema_uri][google.cloud.aiplatform.v1beta1.PredictSchemata.instance_schema_uri]. input_tensor_name (str): Name of the input tensor for this feature. - Required and is only applicable to AI Platform - provided images for Tensorflow. + Required and is only applicable to Vertex + AI-provided images for Tensorflow. encoding (google.cloud.aiplatform_v1beta1.types.ExplanationMetadata.InputMetadata.Encoding): Defines how the feature is encoded into the input tensor. Defaults to IDENTITY. @@ -130,7 +136,7 @@ class InputMetadata(proto.Message): encoded_tensor_name (str): Encoded tensor is a transformation of the input tensor. Must be provided if choosing [Integrated Gradients - attribution][ExplanationParameters.integrated_gradients_attribution] + attribution][google.cloud.aiplatform.v1beta1.ExplanationParameters.integrated_gradients_attribution] or [XRAI attribution][google.cloud.aiplatform.v1beta1.ExplanationParameters.xrai_attribution] and the input tensor is not differentiable. @@ -141,8 +147,8 @@ class InputMetadata(proto.Message): A list of baselines for the encoded tensor. The shape of each baseline should match the shape of the encoded tensor. If a scalar is - provided, AI Platform broadcast to the same - shape as the encoded tensor. + provided, Vertex AI broadcasts to the same shape + as the encoded tensor. visualization (google.cloud.aiplatform_v1beta1.types.ExplanationMetadata.InputMetadata.Visualization): Visualization configurations for image explanation. @@ -151,15 +157,13 @@ class InputMetadata(proto.Message): the same group name will be treated as one feature when computing attributions. Features grouped together can have different shapes in value. If provided, there will be one - single attribution generated in [ - featureAttributions][Attribution.feature_attributions], + single attribution generated in + [Attribution.feature_attributions][google.cloud.aiplatform.v1beta1.Attribution.feature_attributions], keyed by the group name. """ class Encoding(proto.Enum): - r"""Defines how the feature is encoded to [encoded_tensor][]. Defaults - to IDENTITY. - """ + r"""Defines how a feature is encoded. Defaults to IDENTITY.""" ENCODING_UNSPECIFIED = 0 IDENTITY = 1 BAG_OF_FEATURES = 2 @@ -196,18 +200,31 @@ class FeatureValueDomain(proto.Message): deviation of the domain prior to normalization. """ - min_value = proto.Field(proto.FLOAT, number=1,) - max_value = proto.Field(proto.FLOAT, number=2,) - original_mean = proto.Field(proto.FLOAT, number=3,) - original_stddev = proto.Field(proto.FLOAT, number=4,) + min_value = proto.Field( + proto.FLOAT, + number=1, + ) + max_value = proto.Field( + proto.FLOAT, + number=2, + ) + original_mean = proto.Field( + proto.FLOAT, + number=3, + ) + original_stddev = proto.Field( + proto.FLOAT, + number=4, + ) class Visualization(proto.Message): r"""Visualization configurations for image explanation. + Attributes: type_ (google.cloud.aiplatform_v1beta1.types.ExplanationMetadata.InputMetadata.Visualization.Type): Type of the image visualization. Only applicable to - [Integrated Gradients attribution] - [ExplanationParameters.integrated_gradients_attribution]. + [Integrated Gradients + attribution][google.cloud.aiplatform.v1beta1.ExplanationParameters.integrated_gradients_attribution]. OUTLINES shows regions of attribution, while PIXELS shows per-pixel attribution. Defaults to OUTLINES. polarity (google.cloud.aiplatform_v1beta1.types.ExplanationMetadata.InputMetadata.Visualization.Polarity): @@ -218,7 +235,7 @@ class Visualization(proto.Message): The color scheme used for the highlighted areas. Defaults to PINK_GREEN for [Integrated Gradients - attribution][ExplanationParameters.integrated_gradients_attribution], + attribution][google.cloud.aiplatform.v1beta1.ExplanationParameters.integrated_gradients_attribution], which shows positive attributions in green and negative in pink. @@ -246,8 +263,8 @@ class Visualization(proto.Message): class Type(proto.Enum): r"""Type of the image visualization. Only applicable to [Integrated - Gradients attribution] - [ExplanationParameters.integrated_gradients_attribution]. + Gradients + attribution][google.cloud.aiplatform.v1beta1.ExplanationParameters.integrated_gradients_attribution]. """ TYPE_UNSPECIFIED = 0 PIXELS = 1 @@ -295,8 +312,14 @@ class OverlayType(proto.Enum): number=3, enum="ExplanationMetadata.InputMetadata.Visualization.ColorMap", ) - clip_percent_upperbound = proto.Field(proto.FLOAT, number=4,) - clip_percent_lowerbound = proto.Field(proto.FLOAT, number=5,) + clip_percent_upperbound = proto.Field( + proto.FLOAT, + number=4, + ) + clip_percent_lowerbound = proto.Field( + proto.FLOAT, + number=5, + ) overlay_type = proto.Field( proto.ENUM, number=6, @@ -304,34 +327,69 @@ class OverlayType(proto.Enum): ) input_baselines = proto.RepeatedField( - proto.MESSAGE, number=1, message=struct_pb2.Value, + proto.MESSAGE, + number=1, + message=struct_pb2.Value, + ) + input_tensor_name = proto.Field( + proto.STRING, + number=2, ) - input_tensor_name = proto.Field(proto.STRING, number=2,) encoding = proto.Field( - proto.ENUM, number=3, enum="ExplanationMetadata.InputMetadata.Encoding", + proto.ENUM, + number=3, + enum="ExplanationMetadata.InputMetadata.Encoding", + ) + modality = proto.Field( + proto.STRING, + number=4, ) - modality = proto.Field(proto.STRING, number=4,) feature_value_domain = proto.Field( proto.MESSAGE, number=5, message="ExplanationMetadata.InputMetadata.FeatureValueDomain", ) - indices_tensor_name = proto.Field(proto.STRING, number=6,) - dense_shape_tensor_name = proto.Field(proto.STRING, number=7,) - index_feature_mapping = proto.RepeatedField(proto.STRING, number=8,) - encoded_tensor_name = proto.Field(proto.STRING, number=9,) + indices_tensor_name = proto.Field( + proto.STRING, + number=6, + ) + dense_shape_tensor_name = proto.Field( + proto.STRING, + number=7, + ) + index_feature_mapping = proto.RepeatedField( + proto.STRING, + number=8, + ) + encoded_tensor_name = proto.Field( + proto.STRING, + number=9, + ) encoded_baselines = proto.RepeatedField( - proto.MESSAGE, number=10, message=struct_pb2.Value, + proto.MESSAGE, + number=10, + message=struct_pb2.Value, ) visualization = proto.Field( proto.MESSAGE, number=11, message="ExplanationMetadata.InputMetadata.Visualization", ) - group_name = proto.Field(proto.STRING, number=12,) + group_name = proto.Field( + proto.STRING, + number=12, + ) class OutputMetadata(proto.Message): r"""Metadata of the prediction output to be explained. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: index_display_name_mapping (google.protobuf.struct_pb2.Value): Static mapping between the index and display name. @@ -349,6 +407,8 @@ class OutputMetadata(proto.Message): [Attribution.output_display_name][google.cloud.aiplatform.v1beta1.Attribution.output_display_name] is populated by locating in the mapping with [Attribution.output_index][google.cloud.aiplatform.v1beta1.Attribution.output_index]. + + This field is a member of `oneof`_ ``display_name_mapping``. display_name_mapping_key (str): Specify a field name in the prediction to look for the display name. @@ -360,10 +420,12 @@ class OutputMetadata(proto.Message): of the outputs, so that it can be located by [Attribution.output_index][google.cloud.aiplatform.v1beta1.Attribution.output_index] for a specific output. + + This field is a member of `oneof`_ ``display_name_mapping``. output_tensor_name (str): Name of the output tensor. Required and is - only applicable to AI Platform provided images - for Tensorflow. + only applicable to Vertex AI provided images for + Tensorflow. """ index_display_name_mapping = proto.Field( @@ -373,17 +435,35 @@ class OutputMetadata(proto.Message): message=struct_pb2.Value, ) display_name_mapping_key = proto.Field( - proto.STRING, number=2, oneof="display_name_mapping", + proto.STRING, + number=2, + oneof="display_name_mapping", + ) + output_tensor_name = proto.Field( + proto.STRING, + number=3, ) - output_tensor_name = proto.Field(proto.STRING, number=3,) inputs = proto.MapField( - proto.STRING, proto.MESSAGE, number=1, message=InputMetadata, + proto.STRING, + proto.MESSAGE, + number=1, + message=InputMetadata, ) outputs = proto.MapField( - proto.STRING, proto.MESSAGE, number=2, message=OutputMetadata, + proto.STRING, + proto.MESSAGE, + number=2, + message=OutputMetadata, + ) + feature_attributions_schema_uri = proto.Field( + proto.STRING, + number=3, + ) + latent_space_source = proto.Field( + proto.STRING, + number=5, ) - feature_attributions_schema_uri = proto.Field(proto.STRING, number=3,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/feature.py b/google/cloud/aiplatform_v1beta1/types/feature.py index 448b972cba..6b6a6f5dfc 100644 --- a/google/cloud/aiplatform_v1beta1/types/feature.py +++ b/google/cloud/aiplatform_v1beta1/types/feature.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,7 +21,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"Feature",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "Feature", + }, ) @@ -50,7 +53,7 @@ class Feature(proto.Message): update_time (google.protobuf.timestamp_pb2.Timestamp): Output only. Timestamp when this EntityType was most recently updated. - labels (Sequence[google.cloud.aiplatform_v1beta1.types.Feature.LabelsEntry]): + labels (Mapping[str, str]): Optional. The labels with user-defined metadata to organize your Features. Label keys and values can be no longer than 64 @@ -65,13 +68,16 @@ class Feature(proto.Message): System reserved label keys are prefixed with "aiplatform.googleapis.com/" and are immutable. etag (str): - Used to perform a consistent read-modify- - rite updates. If not set, a blind "overwrite" - update happens. + Used to perform a consistent + read-modify-write updates. If not set, a blind + "overwrite" update happens. monitoring_config (google.cloud.aiplatform_v1beta1.types.FeaturestoreMonitoringConfig): - Optional. The custom monitoring configuration for this - Feature, if not set, use the monitoring_config defined for - the EntityType this Feature belongs to. + Optional. Deprecated: The custom monitoring configuration + for this Feature, if not set, use the monitoring_config + defined for the EntityType this Feature belongs to. Only + Features with type + ([Feature.ValueType][google.cloud.aiplatform.v1beta1.Feature.ValueType]) + BOOL, STRING, DOUBLE or INT64 can enable monitoring. If this is populated with [FeaturestoreMonitoringConfig.disabled][] = true, snapshot @@ -80,12 +86,24 @@ class Feature(proto.Message): specified, snapshot analysis monitoring is enabled. Otherwise, snapshot analysis monitoring config is same as the EntityType's this Feature belongs to. + disable_monitoring (bool): + Optional. If not set, use the monitoring_config defined for + the EntityType this Feature belongs to. Only Features with + type + ([Feature.ValueType][google.cloud.aiplatform.v1beta1.Feature.ValueType]) + BOOL, STRING, DOUBLE or INT64 can enable monitoring. + + If set to true, all types of data monitoring are disabled + despite the config on EntityType. monitoring_stats (Sequence[google.cloud.aiplatform_v1beta1.types.FeatureStatsAnomaly]): Output only. A list of historical [Snapshot - Analysis][google.cloud.aiplatform.master.FeaturestoreMonitoringConfig.SnapshotAnalysis] + Analysis][FeaturestoreMonitoringConfig.SnapshotAnalysis] stats requested by user, sorted by [FeatureStatsAnomaly.start_time][google.cloud.aiplatform.v1beta1.FeatureStatsAnomaly.start_time] descending. + monitoring_stats_anomalies (Sequence[google.cloud.aiplatform_v1beta1.types.Feature.MonitoringStatsAnomaly]): + Output only. The list of historical stats and + anomalies with specified objectives. """ class ValueType(proto.Enum): @@ -101,20 +119,94 @@ class ValueType(proto.Enum): STRING_ARRAY = 12 BYTES = 13 - name = proto.Field(proto.STRING, number=1,) - description = proto.Field(proto.STRING, number=2,) - value_type = proto.Field(proto.ENUM, number=3, enum=ValueType,) - create_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) - update_time = proto.Field(proto.MESSAGE, number=5, message=timestamp_pb2.Timestamp,) - labels = proto.MapField(proto.STRING, proto.STRING, number=6,) - etag = proto.Field(proto.STRING, number=7,) + class MonitoringStatsAnomaly(proto.Message): + r"""A list of historical [Snapshot + Analysis][FeaturestoreMonitoringConfig.SnapshotAnalysis] or [Import + Feature Analysis] + [FeaturestoreMonitoringConfig.ImportFeatureAnalysis] stats requested + by user, sorted by + [FeatureStatsAnomaly.start_time][google.cloud.aiplatform.v1beta1.FeatureStatsAnomaly.start_time] + descending. + + Attributes: + objective (google.cloud.aiplatform_v1beta1.types.Feature.MonitoringStatsAnomaly.Objective): + Output only. The objective for each stats. + feature_stats_anomaly (google.cloud.aiplatform_v1beta1.types.FeatureStatsAnomaly): + Output only. The stats and anomalies + generated at specific timestamp. + """ + + class Objective(proto.Enum): + r"""If the objective in the request is both + Import Feature Analysis and Snapshot Analysis, this objective + could be one of them. Otherwise, this objective should be the + same as the objective in the request. + """ + OBJECTIVE_UNSPECIFIED = 0 + IMPORT_FEATURE_ANALYSIS = 1 + SNAPSHOT_ANALYSIS = 2 + + objective = proto.Field( + proto.ENUM, + number=1, + enum="Feature.MonitoringStatsAnomaly.Objective", + ) + feature_stats_anomaly = proto.Field( + proto.MESSAGE, + number=2, + message=feature_monitoring_stats.FeatureStatsAnomaly, + ) + + name = proto.Field( + proto.STRING, + number=1, + ) + description = proto.Field( + proto.STRING, + number=2, + ) + value_type = proto.Field( + proto.ENUM, + number=3, + enum=ValueType, + ) + create_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=5, + message=timestamp_pb2.Timestamp, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=6, + ) + etag = proto.Field( + proto.STRING, + number=7, + ) monitoring_config = proto.Field( proto.MESSAGE, number=9, message=featurestore_monitoring.FeaturestoreMonitoringConfig, ) + disable_monitoring = proto.Field( + proto.BOOL, + number=12, + ) monitoring_stats = proto.RepeatedField( - proto.MESSAGE, number=10, message=feature_monitoring_stats.FeatureStatsAnomaly, + proto.MESSAGE, + number=10, + message=feature_monitoring_stats.FeatureStatsAnomaly, + ) + monitoring_stats_anomalies = proto.RepeatedField( + proto.MESSAGE, + number=11, + message=MonitoringStatsAnomaly, ) diff --git a/google/cloud/aiplatform_v1beta1/types/feature_monitoring_stats.py b/google/cloud/aiplatform_v1beta1/types/feature_monitoring_stats.py index b966a5edb9..5c4bc65274 100644 --- a/google/cloud/aiplatform_v1beta1/types/feature_monitoring_stats.py +++ b/google/cloud/aiplatform_v1beta1/types/feature_monitoring_stats.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,7 +19,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"FeatureStatsAnomaly",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "FeatureStatsAnomaly", + }, ) @@ -32,8 +35,8 @@ class FeatureStatsAnomaly(proto.Message): Timestamp of the stats and anomalies always refers to end_time. Raw stats and anomalies are stored in stats_uri or anomaly_uri in the tensorflow defined protos. Field data_stats contains almost - identical information with the raw stats in AI Platform defined - proto, for UI to display. + identical information with the raw stats in Vertex AI defined proto, + for UI to display. Attributes: score (float): @@ -86,13 +89,36 @@ class FeatureStatsAnomaly(proto.Message): we take snapshots for feature values). """ - score = proto.Field(proto.DOUBLE, number=1,) - stats_uri = proto.Field(proto.STRING, number=3,) - anomaly_uri = proto.Field(proto.STRING, number=4,) - distribution_deviation = proto.Field(proto.DOUBLE, number=5,) - anomaly_detection_threshold = proto.Field(proto.DOUBLE, number=9,) - start_time = proto.Field(proto.MESSAGE, number=7, message=timestamp_pb2.Timestamp,) - end_time = proto.Field(proto.MESSAGE, number=8, message=timestamp_pb2.Timestamp,) + score = proto.Field( + proto.DOUBLE, + number=1, + ) + stats_uri = proto.Field( + proto.STRING, + number=3, + ) + anomaly_uri = proto.Field( + proto.STRING, + number=4, + ) + distribution_deviation = proto.Field( + proto.DOUBLE, + number=5, + ) + anomaly_detection_threshold = proto.Field( + proto.DOUBLE, + number=9, + ) + start_time = proto.Field( + proto.MESSAGE, + number=7, + message=timestamp_pb2.Timestamp, + ) + end_time = proto.Field( + proto.MESSAGE, + number=8, + message=timestamp_pb2.Timestamp, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/feature_selector.py b/google/cloud/aiplatform_v1beta1/types/feature_selector.py index f876c43103..02bfe095d7 100644 --- a/google/cloud/aiplatform_v1beta1/types/feature_selector.py +++ b/google/cloud/aiplatform_v1beta1/types/feature_selector.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,16 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1", - manifest={"IdMatcher", "FeatureSelector",}, + manifest={ + "IdMatcher", + "FeatureSelector", + }, ) class IdMatcher(proto.Message): r"""Matcher for Features of an EntityType by Feature ID. + Attributes: ids (Sequence[str]): Required. The following are accepted as ``ids``: @@ -34,17 +38,25 @@ class IdMatcher(proto.Message): Features with those IDs in the target EntityType. """ - ids = proto.RepeatedField(proto.STRING, number=1,) + ids = proto.RepeatedField( + proto.STRING, + number=1, + ) class FeatureSelector(proto.Message): r"""Selector for Features of an EntityType. + Attributes: id_matcher (google.cloud.aiplatform_v1beta1.types.IdMatcher): Required. Matches Features based on ID. """ - id_matcher = proto.Field(proto.MESSAGE, number=1, message="IdMatcher",) + id_matcher = proto.Field( + proto.MESSAGE, + number=1, + message="IdMatcher", + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/featurestore.py b/google/cloud/aiplatform_v1beta1/types/featurestore.py index 9a3e71157e..e10503041f 100644 --- a/google/cloud/aiplatform_v1beta1/types/featurestore.py +++ b/google/cloud/aiplatform_v1beta1/types/featurestore.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,17 +15,22 @@ # import proto # type: ignore +from google.cloud.aiplatform_v1beta1.types import encryption_spec as gca_encryption_spec from google.protobuf import timestamp_pb2 # type: ignore __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"Featurestore",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "Featurestore", + }, ) class Featurestore(proto.Message): - r"""Featurestore configuration information on how the - Featurestore is configured. + r"""Vertex AI Feature Store provides a centralized repository for + organizing, storing, and serving ML features. The Featurestore + is a top-level container for your features and their values. Attributes: name (str): @@ -38,10 +43,10 @@ class Featurestore(proto.Message): Output only. Timestamp when this Featurestore was last updated. etag (str): - Optional. Used to perform consistent read- - odify-write updates. If not set, a blind + Optional. Used to perform consistent + read-modify-write updates. If not set, a blind "overwrite" update happens. - labels (Sequence[google.cloud.aiplatform_v1beta1.types.Featurestore.LabelsEntry]): + labels (Mapping[str, str]): Optional. The labels with user-defined metadata to organize your Featurestore. Label keys and values can be no longer than 64 @@ -56,14 +61,21 @@ class Featurestore(proto.Message): System reserved label keys are prefixed with "aiplatform.googleapis.com/" and are immutable. online_serving_config (google.cloud.aiplatform_v1beta1.types.Featurestore.OnlineServingConfig): - Required. Config for online serving - resources. + Optional. Config for online storage + resources. If unset, the featurestore will not + have an online store and cannot be used for + online serving. state (google.cloud.aiplatform_v1beta1.types.Featurestore.State): Output only. State of the featurestore. + encryption_spec (google.cloud.aiplatform_v1beta1.types.EncryptionSpec): + Optional. Customer-managed encryption key + spec for data storage. If set, both of the + online and offline data storage will be secured + by this key. """ class State(proto.Enum): - r"""Possible states a Featurestore can have.""" + r"""Possible states a featurestore can have.""" STATE_UNSPECIFIED = 0 STABLE = 1 UPDATING = 2 @@ -74,23 +86,91 @@ class OnlineServingConfig(proto.Message): Attributes: fixed_node_count (int): - Required. The number of nodes for each - cluster. The number of nodes will not scale - automatically but can be scaled manually by - providing different values when updating. + The number of nodes for the online store. The + number of nodes doesn't scale automatically, but + you can manually update the number of nodes. If + set to 0, the featurestore will not have an + online store and cannot be used for online + serving. + scaling (google.cloud.aiplatform_v1beta1.types.Featurestore.OnlineServingConfig.Scaling): + Online serving scaling configuration. Only one of + ``fixed_node_count`` and ``scaling`` can be set. Setting one + will reset the other. """ - fixed_node_count = proto.Field(proto.INT32, number=2,) + class Scaling(proto.Message): + r"""Online serving scaling configuration. If min_node_count and + max_node_count are set to the same value, the cluster will be + configured with the fixed number of node (no auto-scaling). - name = proto.Field(proto.STRING, number=1,) - create_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) - update_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) - etag = proto.Field(proto.STRING, number=5,) - labels = proto.MapField(proto.STRING, proto.STRING, number=6,) + Attributes: + min_node_count (int): + Required. The minimum number of nodes to + scale down to. Must be greater than or equal to + 1. + max_node_count (int): + The maximum number of nodes to scale up to. Must be greater + than min_node_count, and less than or equal to 10 times of + 'min_node_count'. + """ + + min_node_count = proto.Field( + proto.INT32, + number=1, + ) + max_node_count = proto.Field( + proto.INT32, + number=2, + ) + + fixed_node_count = proto.Field( + proto.INT32, + number=2, + ) + scaling = proto.Field( + proto.MESSAGE, + number=4, + message="Featurestore.OnlineServingConfig.Scaling", + ) + + name = proto.Field( + proto.STRING, + number=1, + ) + create_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + etag = proto.Field( + proto.STRING, + number=5, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=6, + ) online_serving_config = proto.Field( - proto.MESSAGE, number=7, message=OnlineServingConfig, + proto.MESSAGE, + number=7, + message=OnlineServingConfig, + ) + state = proto.Field( + proto.ENUM, + number=8, + enum=State, + ) + encryption_spec = proto.Field( + proto.MESSAGE, + number=10, + message=gca_encryption_spec.EncryptionSpec, ) - state = proto.Field(proto.ENUM, number=8, enum=State,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/featurestore_monitoring.py b/google/cloud/aiplatform_v1beta1/types/featurestore_monitoring.py index 76e6f6b5a4..ecb23aaf2f 100644 --- a/google/cloud/aiplatform_v1beta1/types/featurestore_monitoring.py +++ b/google/cloud/aiplatform_v1beta1/types/featurestore_monitoring.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,16 +20,34 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1", - manifest={"FeaturestoreMonitoringConfig",}, + manifest={ + "FeaturestoreMonitoringConfig", + }, ) class FeaturestoreMonitoringConfig(proto.Message): r"""Configuration of how features in Featurestore are monitored. + Attributes: snapshot_analysis (google.cloud.aiplatform_v1beta1.types.FeaturestoreMonitoringConfig.SnapshotAnalysis): The config for Snapshot Analysis Based Feature Monitoring. + import_features_analysis (google.cloud.aiplatform_v1beta1.types.FeaturestoreMonitoringConfig.ImportFeaturesAnalysis): + The config for ImportFeatures Analysis Based + Feature Monitoring. + numerical_threshold_config (google.cloud.aiplatform_v1beta1.types.FeaturestoreMonitoringConfig.ThresholdConfig): + Threshold for numerical features of anomaly detection. This + is shared by all objectives of Featurestore Monitoring for + numerical features (i.e. Features with type + ([Feature.ValueType][google.cloud.aiplatform.v1beta1.Feature.ValueType]) + DOUBLE or INT64). + categorical_threshold_config (google.cloud.aiplatform_v1beta1.types.FeaturestoreMonitoringConfig.ThresholdConfig): + Threshold for categorical features of anomaly detection. + This is shared by all types of Featurestore Monitoring for + categorical features (i.e. Features with type + ([Feature.ValueType][google.cloud.aiplatform.v1beta1.Feature.ValueType]) + BOOL or STRING). """ class SnapshotAnalysis(proto.Message): @@ -55,14 +73,130 @@ class SnapshotAnalysis(proto.Message): Configuration of the snapshot analysis based monitoring pipeline running interval. The value is rolled up to full day. + monitoring_interval_days (int): + Configuration of the snapshot analysis based monitoring + pipeline running interval. The value indicates number of + days. If both + [FeaturestoreMonitoringConfig.SnapshotAnalysis.monitoring_interval_days][google.cloud.aiplatform.v1beta1.FeaturestoreMonitoringConfig.SnapshotAnalysis.monitoring_interval_days] + and + [FeaturestoreMonitoringConfig.SnapshotAnalysis.monitoring_interval][google.cloud.aiplatform.v1beta1.FeaturestoreMonitoringConfig.SnapshotAnalysis.monitoring_interval] + are set when creating/updating EntityTypes/Features, + [FeaturestoreMonitoringConfig.SnapshotAnalysis.monitoring_interval_days][google.cloud.aiplatform.v1beta1.FeaturestoreMonitoringConfig.SnapshotAnalysis.monitoring_interval_days] + will be used. + staleness_days (int): + Customized export features time window for + snapshot analysis. Unit is one day. Default + value is 3 weeks. Minimum value is 1 day. + Maximum value is 4000 days. """ - disabled = proto.Field(proto.BOOL, number=1,) + disabled = proto.Field( + proto.BOOL, + number=1, + ) monitoring_interval = proto.Field( - proto.MESSAGE, number=2, message=duration_pb2.Duration, + proto.MESSAGE, + number=2, + message=duration_pb2.Duration, + ) + monitoring_interval_days = proto.Field( + proto.INT32, + number=3, + ) + staleness_days = proto.Field( + proto.INT32, + number=4, + ) + + class ImportFeaturesAnalysis(proto.Message): + r"""Configuration of the Featurestore's ImportFeature Analysis Based + Monitoring. This type of analysis generates statistics for values of + each Feature imported by every [ImportFeatureValues][] operation. + + Attributes: + state (google.cloud.aiplatform_v1beta1.types.FeaturestoreMonitoringConfig.ImportFeaturesAnalysis.State): + Whether to enable / disable / inherite + default hebavior for import features analysis. + anomaly_detection_baseline (google.cloud.aiplatform_v1beta1.types.FeaturestoreMonitoringConfig.ImportFeaturesAnalysis.Baseline): + The baseline used to do anomaly detection for + the statistics generated by import features + analysis. + """ + + class State(proto.Enum): + r"""The state defines whether to enable ImportFeature analysis.""" + STATE_UNSPECIFIED = 0 + DEFAULT = 1 + ENABLED = 2 + DISABLED = 3 + + class Baseline(proto.Enum): + r"""Defines the baseline to do anomaly detection for feature values + imported by each [ImportFeatureValues][] operation. + """ + BASELINE_UNSPECIFIED = 0 + LATEST_STATS = 1 + MOST_RECENT_SNAPSHOT_STATS = 2 + PREVIOUS_IMPORT_FEATURES_STATS = 3 + + state = proto.Field( + proto.ENUM, + number=1, + enum="FeaturestoreMonitoringConfig.ImportFeaturesAnalysis.State", + ) + anomaly_detection_baseline = proto.Field( + proto.ENUM, + number=2, + enum="FeaturestoreMonitoringConfig.ImportFeaturesAnalysis.Baseline", + ) + + class ThresholdConfig(proto.Message): + r"""The config for Featurestore Monitoring threshold. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + value (float): + Specify a threshold value that can trigger + the alert. 1. For categorical feature, the + distribution distance is calculated by + L-inifinity norm. + 2. For numerical feature, the distribution + distance is calculated by Jensen–Shannon + divergence. Each feature must have a non-zero + threshold if they need to be monitored. + Otherwise no alert will be triggered for that + feature. + + This field is a member of `oneof`_ ``threshold``. + """ + + value = proto.Field( + proto.DOUBLE, + number=1, + oneof="threshold", ) - snapshot_analysis = proto.Field(proto.MESSAGE, number=1, message=SnapshotAnalysis,) + snapshot_analysis = proto.Field( + proto.MESSAGE, + number=1, + message=SnapshotAnalysis, + ) + import_features_analysis = proto.Field( + proto.MESSAGE, + number=2, + message=ImportFeaturesAnalysis, + ) + numerical_threshold_config = proto.Field( + proto.MESSAGE, + number=3, + message=ThresholdConfig, + ) + categorical_threshold_config = proto.Field( + proto.MESSAGE, + number=4, + message=ThresholdConfig, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/featurestore_online_service.py b/google/cloud/aiplatform_v1beta1/types/featurestore_online_service.py index 87688e56e5..b153d6be49 100644 --- a/google/cloud/aiplatform_v1beta1/types/featurestore_online_service.py +++ b/google/cloud/aiplatform_v1beta1/types/featurestore_online_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -42,22 +42,30 @@ class ReadFeatureValuesRequest(proto.Message): entity_type (str): Required. The resource name of the EntityType for the entity being read. Value format: - ``projects/{project}/locations/{location}/featurestores/ {featurestore}/entityTypes/{entityType}``. + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entityType}``. For example, for a machine learning model predicting user - clicks on a website, an EntityType ID could be "user". + clicks on a website, an EntityType ID could be ``user``. entity_id (str): Required. ID for a specific entity. For example, for a machine learning model predicting user clicks on a website, - an entity ID could be "user_123". + an entity ID could be ``user_123``. feature_selector (google.cloud.aiplatform_v1beta1.types.FeatureSelector): Required. Selector choosing Features of the target EntityType. """ - entity_type = proto.Field(proto.STRING, number=1,) - entity_id = proto.Field(proto.STRING, number=2,) + entity_type = proto.Field( + proto.STRING, + number=1, + ) + entity_id = proto.Field( + proto.STRING, + number=2, + ) feature_selector = proto.Field( - proto.MESSAGE, number=3, message=gca_feature_selector.FeatureSelector, + proto.MESSAGE, + number=3, + message=gca_feature_selector.FeatureSelector, ) @@ -78,12 +86,16 @@ class ReadFeatureValuesResponse(proto.Message): class FeatureDescriptor(proto.Message): r"""Metadata for requested Features. + Attributes: id (str): Feature ID. """ - id = proto.Field(proto.STRING, number=1,) + id = proto.Field( + proto.STRING, + number=1, + ) class Header(proto.Message): r"""Response header with metadata for the requested @@ -95,13 +107,16 @@ class Header(proto.Message): The resource name of the EntityType from the [ReadFeatureValuesRequest][google.cloud.aiplatform.v1beta1.ReadFeatureValuesRequest]. Value format: - ``projects/{project}/locations/{location}/featurestores/ {featurestore}/entityTypes/{entityType}``. + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entityType}``. feature_descriptors (Sequence[google.cloud.aiplatform_v1beta1.types.ReadFeatureValuesResponse.FeatureDescriptor]): List of Feature metadata corresponding to each piece of [ReadFeatureValuesResponse.data][]. """ - entity_type = proto.Field(proto.STRING, number=1,) + entity_type = proto.Field( + proto.STRING, + number=1, + ) feature_descriptors = proto.RepeatedField( proto.MESSAGE, number=2, @@ -110,6 +125,7 @@ class Header(proto.Message): class EntityView(proto.Message): r"""Entity view with Feature values. + Attributes: entity_id (str): ID of the requested entity. @@ -126,33 +142,61 @@ class Data(proto.Message): r"""Container to hold value(s), successive in time, for one Feature from the request. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: value (google.cloud.aiplatform_v1beta1.types.FeatureValue): Feature value if a single value is requested. + + This field is a member of `oneof`_ ``data``. values (google.cloud.aiplatform_v1beta1.types.FeatureValueList): Feature values list if values, successive in time, are requested. If the requested number of values is greater than the number of existing Feature values, nonexistent values are omitted instead of being returned as empty. + + This field is a member of `oneof`_ ``data``. """ value = proto.Field( - proto.MESSAGE, number=1, oneof="data", message="FeatureValue", + proto.MESSAGE, + number=1, + oneof="data", + message="FeatureValue", ) values = proto.Field( - proto.MESSAGE, number=2, oneof="data", message="FeatureValueList", + proto.MESSAGE, + number=2, + oneof="data", + message="FeatureValueList", ) - entity_id = proto.Field(proto.STRING, number=1,) + entity_id = proto.Field( + proto.STRING, + number=1, + ) data = proto.RepeatedField( proto.MESSAGE, number=2, message="ReadFeatureValuesResponse.EntityView.Data", ) - header = proto.Field(proto.MESSAGE, number=1, message=Header,) - entity_view = proto.Field(proto.MESSAGE, number=2, message=EntityView,) + header = proto.Field( + proto.MESSAGE, + number=1, + message=Header, + ) + entity_view = proto.Field( + proto.MESSAGE, + number=2, + message=EntityView, + ) class StreamingReadFeatureValuesRequest(proto.Message): @@ -163,96 +207,177 @@ class StreamingReadFeatureValuesRequest(proto.Message): entity_type (str): Required. The resource name of the entities' type. Value format: - ``projects/{project}/locations/{location}/featurestores/ {featurestore}/entityTypes/{entityType}``. + ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entityType}``. For example, for a machine learning model predicting user - clicks on a website, an EntityType ID could be "user". + clicks on a website, an EntityType ID could be ``user``. entity_ids (Sequence[str]): - Required. IDs of entities to read Feature values of. For - example, for a machine learning model predicting user clicks - on a website, an entity ID could be "user_123". + Required. IDs of entities to read Feature values of. The + maximum number of IDs is 100. For example, for a machine + learning model predicting user clicks on a website, an + entity ID could be ``user_123``. feature_selector (google.cloud.aiplatform_v1beta1.types.FeatureSelector): Required. Selector choosing Features of the - target EntityType. + target EntityType. Feature IDs will be + deduplicated. """ - entity_type = proto.Field(proto.STRING, number=1,) - entity_ids = proto.RepeatedField(proto.STRING, number=2,) + entity_type = proto.Field( + proto.STRING, + number=1, + ) + entity_ids = proto.RepeatedField( + proto.STRING, + number=2, + ) feature_selector = proto.Field( - proto.MESSAGE, number=3, message=gca_feature_selector.FeatureSelector, + proto.MESSAGE, + number=3, + message=gca_feature_selector.FeatureSelector, ) class FeatureValue(proto.Message): r"""Value for a feature. - NEXT ID: 15 + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields Attributes: bool_value (bool): Bool type feature value. + + This field is a member of `oneof`_ ``value``. double_value (float): Double type feature value. + + This field is a member of `oneof`_ ``value``. int64_value (int): Int64 feature value. + + This field is a member of `oneof`_ ``value``. string_value (str): String feature value. + + This field is a member of `oneof`_ ``value``. bool_array_value (google.cloud.aiplatform_v1beta1.types.BoolArray): A list of bool type feature value. + + This field is a member of `oneof`_ ``value``. double_array_value (google.cloud.aiplatform_v1beta1.types.DoubleArray): A list of double type feature value. + + This field is a member of `oneof`_ ``value``. int64_array_value (google.cloud.aiplatform_v1beta1.types.Int64Array): A list of int64 type feature value. + + This field is a member of `oneof`_ ``value``. string_array_value (google.cloud.aiplatform_v1beta1.types.StringArray): A list of string type feature value. + + This field is a member of `oneof`_ ``value``. bytes_value (bytes): Bytes feature value. + + This field is a member of `oneof`_ ``value``. metadata (google.cloud.aiplatform_v1beta1.types.FeatureValue.Metadata): - Output only. Metadata of feature value. + Metadata of feature value. """ class Metadata(proto.Message): r"""Metadata of feature value. + Attributes: generate_time (google.protobuf.timestamp_pb2.Timestamp): Feature generation timestamp. Typically, it is provided by user at feature ingestion time. If not, feature store will use the system timestamp when the data is ingested into feature - store. + store. For streaming ingestion, the time, + aligned by days, must be no older than five + years (1825 days) and no later than one year + (366 days) in the future. """ generate_time = proto.Field( - proto.MESSAGE, number=1, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=1, + message=timestamp_pb2.Timestamp, ) - bool_value = proto.Field(proto.BOOL, number=1, oneof="value",) - double_value = proto.Field(proto.DOUBLE, number=2, oneof="value",) - int64_value = proto.Field(proto.INT64, number=5, oneof="value",) - string_value = proto.Field(proto.STRING, number=6, oneof="value",) + bool_value = proto.Field( + proto.BOOL, + number=1, + oneof="value", + ) + double_value = proto.Field( + proto.DOUBLE, + number=2, + oneof="value", + ) + int64_value = proto.Field( + proto.INT64, + number=5, + oneof="value", + ) + string_value = proto.Field( + proto.STRING, + number=6, + oneof="value", + ) bool_array_value = proto.Field( - proto.MESSAGE, number=7, oneof="value", message=types.BoolArray, + proto.MESSAGE, + number=7, + oneof="value", + message=types.BoolArray, ) double_array_value = proto.Field( - proto.MESSAGE, number=8, oneof="value", message=types.DoubleArray, + proto.MESSAGE, + number=8, + oneof="value", + message=types.DoubleArray, ) int64_array_value = proto.Field( - proto.MESSAGE, number=11, oneof="value", message=types.Int64Array, + proto.MESSAGE, + number=11, + oneof="value", + message=types.Int64Array, ) string_array_value = proto.Field( - proto.MESSAGE, number=12, oneof="value", message=types.StringArray, + proto.MESSAGE, + number=12, + oneof="value", + message=types.StringArray, + ) + bytes_value = proto.Field( + proto.BYTES, + number=13, + oneof="value", + ) + metadata = proto.Field( + proto.MESSAGE, + number=14, + message=Metadata, ) - bytes_value = proto.Field(proto.BYTES, number=13, oneof="value",) - metadata = proto.Field(proto.MESSAGE, number=14, message=Metadata,) class FeatureValueList(proto.Message): r"""Container for list of values. + Attributes: values (Sequence[google.cloud.aiplatform_v1beta1.types.FeatureValue]): A list of feature values. All of them should be the same data type. """ - values = proto.RepeatedField(proto.MESSAGE, number=1, message="FeatureValue",) + values = proto.RepeatedField( + proto.MESSAGE, + number=1, + message="FeatureValue", + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/featurestore_service.py b/google/cloud/aiplatform_v1beta1/types/featurestore_service.py index 747a588046..b3c75486ae 100644 --- a/google/cloud/aiplatform_v1beta1/types/featurestore_service.py +++ b/google/cloud/aiplatform_v1beta1/types/featurestore_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -94,11 +94,19 @@ class CreateFeaturestoreRequest(proto.Message): The value must be unique within the project and location. """ - parent = proto.Field(proto.STRING, number=1,) + parent = proto.Field( + proto.STRING, + number=1, + ) featurestore = proto.Field( - proto.MESSAGE, number=2, message=gca_featurestore.Featurestore, + proto.MESSAGE, + number=2, + message=gca_featurestore.Featurestore, + ) + featurestore_id = proto.Field( + proto.STRING, + number=3, ) - featurestore_id = proto.Field(proto.STRING, number=3,) class GetFeaturestoreRequest(proto.Message): @@ -111,7 +119,10 @@ class GetFeaturestoreRequest(proto.Message): resource. """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListFeaturestoresRequest(proto.Message): @@ -127,13 +138,15 @@ class ListFeaturestoresRequest(proto.Message): Lists the featurestores that match the filter expression. The following fields are supported: - - ``display_name``: Supports =, != comparisons. - - ``create_time``: Supports =, !=, <, >, <=, and >= - comparisons. Values must be in RFC 3339 format. - - ``update_time``: Supports =, !=, <, >, <=, and >= - comparisons. Values must be in RFC 3339 format. - - ``online_serving_config.fixed_node_count``: Supports =, - !=, <, >, <=, and >= comparisons. + - ``create_time``: Supports ``=``, ``!=``, ``<``, ``>``, + ``<=``, and ``>=`` comparisons. Values must be in RFC + 3339 format. + - ``update_time``: Supports ``=``, ``!=``, ``<``, ``>``, + ``<=``, and ``>=`` comparisons. Values must be in RFC + 3339 format. + - ``online_serving_config.fixed_node_count``: Supports + ``=``, ``!=``, ``<``, ``>``, ``<=``, and ``>=`` + comparisons. - ``labels``: Supports key-value equality and key presence. Examples: @@ -161,7 +174,6 @@ class ListFeaturestoresRequest(proto.Message): ascending order. Use "desc" after a field name for descending. Supported Fields: - - ``display_name`` - ``create_time`` - ``update_time`` - ``online_serving_config.fixed_node_count`` @@ -169,12 +181,31 @@ class ListFeaturestoresRequest(proto.Message): Mask specifying which fields to read. """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) - order_by = proto.Field(proto.STRING, number=5,) - read_mask = proto.Field(proto.MESSAGE, number=6, message=field_mask_pb2.FieldMask,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + order_by = proto.Field( + proto.STRING, + number=5, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=6, + message=field_mask_pb2.FieldMask, + ) class ListFeaturestoresResponse(proto.Message): @@ -196,9 +227,14 @@ def raw_page(self): return self featurestores = proto.RepeatedField( - proto.MESSAGE, number=1, message=gca_featurestore.Featurestore, + proto.MESSAGE, + number=1, + message=gca_featurestore.Featurestore, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class UpdateFeaturestoreRequest(proto.Message): @@ -222,17 +258,20 @@ class UpdateFeaturestoreRequest(proto.Message): Updatable fields: - - ``display_name`` - ``labels`` - ``online_serving_config.fixed_node_count`` - - ``retention_policy.online_storage_ttl_days`` + - ``online_serving_config.scaling`` """ featurestore = proto.Field( - proto.MESSAGE, number=1, message=gca_featurestore.Featurestore, + proto.MESSAGE, + number=1, + message=gca_featurestore.Featurestore, ) update_mask = proto.Field( - proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, ) @@ -252,28 +291,48 @@ class DeleteFeaturestoreRequest(proto.Message): Featurestore has no EntityTypes.) """ - name = proto.Field(proto.STRING, number=1,) - force = proto.Field(proto.BOOL, number=2,) + name = proto.Field( + proto.STRING, + number=1, + ) + force = proto.Field( + proto.BOOL, + number=2, + ) class ImportFeatureValuesRequest(proto.Message): r"""Request message for [FeaturestoreService.ImportFeatureValues][google.cloud.aiplatform.v1beta1.FeaturestoreService.ImportFeatureValues]. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: avro_source (google.cloud.aiplatform_v1beta1.types.AvroSource): + This field is a member of `oneof`_ ``source``. bigquery_source (google.cloud.aiplatform_v1beta1.types.BigQuerySource): + This field is a member of `oneof`_ ``source``. csv_source (google.cloud.aiplatform_v1beta1.types.CsvSource): + This field is a member of `oneof`_ ``source``. feature_time_field (str): Source column that holds the Feature timestamp for all Feature values in each entity. + + This field is a member of `oneof`_ ``feature_time_source``. feature_time (google.protobuf.timestamp_pb2.Timestamp): Single Feature timestamp for all entities being imported. The timestamp must not have higher than millisecond precision. + + This field is a member of `oneof`_ ``feature_time_source``. entity_type (str): Required. The resource name of the EntityType grouping the Features for which values are being imported. Format: @@ -301,10 +360,14 @@ class ImportFeatureValuesRequest(proto.Message): not set, defaults to using 1 worker. The low count ensures minimal impact on online serving performance. + disable_ingestion_analysis (bool): + If true, API doesn't start ingestion analysis + pipeline. """ class FeatureSpec(proto.Message): r"""Defines the Feature value(s) to import. + Attributes: id (str): Required. ID of the Feature to import values @@ -316,20 +379,37 @@ class FeatureSpec(proto.Message): as the Feature ID. """ - id = proto.Field(proto.STRING, number=1,) - source_field = proto.Field(proto.STRING, number=2,) + id = proto.Field( + proto.STRING, + number=1, + ) + source_field = proto.Field( + proto.STRING, + number=2, + ) avro_source = proto.Field( - proto.MESSAGE, number=2, oneof="source", message=io.AvroSource, + proto.MESSAGE, + number=2, + oneof="source", + message=io.AvroSource, ) bigquery_source = proto.Field( - proto.MESSAGE, number=3, oneof="source", message=io.BigQuerySource, + proto.MESSAGE, + number=3, + oneof="source", + message=io.BigQuerySource, ) csv_source = proto.Field( - proto.MESSAGE, number=4, oneof="source", message=io.CsvSource, + proto.MESSAGE, + number=4, + oneof="source", + message=io.CsvSource, ) feature_time_field = proto.Field( - proto.STRING, number=6, oneof="feature_time_source", + proto.STRING, + number=6, + oneof="feature_time_source", ) feature_time = proto.Field( proto.MESSAGE, @@ -337,11 +417,31 @@ class FeatureSpec(proto.Message): oneof="feature_time_source", message=timestamp_pb2.Timestamp, ) - entity_type = proto.Field(proto.STRING, number=1,) - entity_id_field = proto.Field(proto.STRING, number=5,) - feature_specs = proto.RepeatedField(proto.MESSAGE, number=8, message=FeatureSpec,) - disable_online_serving = proto.Field(proto.BOOL, number=9,) - worker_count = proto.Field(proto.INT32, number=11,) + entity_type = proto.Field( + proto.STRING, + number=1, + ) + entity_id_field = proto.Field( + proto.STRING, + number=5, + ) + feature_specs = proto.RepeatedField( + proto.MESSAGE, + number=8, + message=FeatureSpec, + ) + disable_online_serving = proto.Field( + proto.BOOL, + number=9, + ) + worker_count = proto.Field( + proto.INT32, + number=11, + ) + disable_ingestion_analysis = proto.Field( + proto.BOOL, + number=12, + ) class ImportFeatureValuesResponse(proto.Message): @@ -365,15 +465,30 @@ class ImportFeatureValuesResponse(proto.Message): - Not being parsable (applicable for CSV sources). """ - imported_entity_count = proto.Field(proto.INT64, number=1,) - imported_feature_value_count = proto.Field(proto.INT64, number=2,) - invalid_row_count = proto.Field(proto.INT64, number=6,) + imported_entity_count = proto.Field( + proto.INT64, + number=1, + ) + imported_feature_value_count = proto.Field( + proto.INT64, + number=2, + ) + invalid_row_count = proto.Field( + proto.INT64, + number=6, + ) class BatchReadFeatureValuesRequest(proto.Message): r"""Request message for [FeaturestoreService.BatchReadFeatureValues][google.cloud.aiplatform.v1beta1.FeaturestoreService.BatchReadFeatureValues]. - (- Next Id: 6 -) + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields Attributes: csv_read_instances (google.cloud.aiplatform_v1beta1.types.CsvSource): @@ -400,6 +515,12 @@ class BatchReadFeatureValuesRequest(proto.Message): Values in the timestamp column must use the RFC 3339 format, e.g. ``2012-07-30T10:43:17.123Z``. + + This field is a member of `oneof`_ ``read_option``. + bigquery_read_instances (google.cloud.aiplatform_v1beta1.types.BigQuerySource): + Similar to csv_read_instances, but from BigQuery source. + + This field is a member of `oneof`_ ``read_option``. featurestore (str): Required. The resource name of the Featurestore from which to query Feature values. Format: @@ -407,14 +528,38 @@ class BatchReadFeatureValuesRequest(proto.Message): destination (google.cloud.aiplatform_v1beta1.types.FeatureValueDestination): Required. Specifies output location and format. + pass_through_fields (Sequence[google.cloud.aiplatform_v1beta1.types.BatchReadFeatureValuesRequest.PassThroughField]): + When not empty, the specified fields in the + \*_read_instances source will be joined as-is in the output, + in addition to those fields from the Featurestore Entity. + + For BigQuery source, the type of the pass-through values + will be automatically inferred. For CSV source, the + pass-through values will be passed as opaque bytes. entity_type_specs (Sequence[google.cloud.aiplatform_v1beta1.types.BatchReadFeatureValuesRequest.EntityTypeSpec]): Required. Specifies EntityType grouping Features to read values of and settings. Each EntityType referenced in [BatchReadFeatureValuesRequest.entity_type_specs] must have - a column specifying entity IDs in tha EntityType in + a column specifying entity IDs in the EntityType in [BatchReadFeatureValuesRequest.request][] . """ + class PassThroughField(proto.Message): + r"""Describe pass-through fields in read_instance source. + + Attributes: + field_name (str): + Required. The name of the field in the CSV header or the + name of the column in BigQuery table. The naming restriction + is the same as + [Feature.name][google.cloud.aiplatform.v1beta1.Feature.name]. + """ + + field_name = proto.Field( + proto.STRING, + number=1, + ) + class EntityTypeSpec(proto.Message): r"""Selects Features of an EntityType to read values of and specifies read settings. @@ -432,23 +577,51 @@ class EntityTypeSpec(proto.Message): Per-Feature settings for the batch read. """ - entity_type_id = proto.Field(proto.STRING, number=1,) + entity_type_id = proto.Field( + proto.STRING, + number=1, + ) feature_selector = proto.Field( - proto.MESSAGE, number=2, message=gca_feature_selector.FeatureSelector, + proto.MESSAGE, + number=2, + message=gca_feature_selector.FeatureSelector, ) settings = proto.RepeatedField( - proto.MESSAGE, number=3, message="DestinationFeatureSetting", + proto.MESSAGE, + number=3, + message="DestinationFeatureSetting", ) csv_read_instances = proto.Field( - proto.MESSAGE, number=3, oneof="read_option", message=io.CsvSource, + proto.MESSAGE, + number=3, + oneof="read_option", + message=io.CsvSource, + ) + bigquery_read_instances = proto.Field( + proto.MESSAGE, + number=5, + oneof="read_option", + message=io.BigQuerySource, + ) + featurestore = proto.Field( + proto.STRING, + number=1, ) - featurestore = proto.Field(proto.STRING, number=1,) destination = proto.Field( - proto.MESSAGE, number=4, message="FeatureValueDestination", + proto.MESSAGE, + number=4, + message="FeatureValueDestination", + ) + pass_through_fields = proto.RepeatedField( + proto.MESSAGE, + number=8, + message=PassThroughField, ) entity_type_specs = proto.RepeatedField( - proto.MESSAGE, number=7, message=EntityTypeSpec, + proto.MESSAGE, + number=7, + message=EntityTypeSpec, ) @@ -456,10 +629,24 @@ class ExportFeatureValuesRequest(proto.Message): r"""Request message for [FeaturestoreService.ExportFeatureValues][google.cloud.aiplatform.v1beta1.FeaturestoreService.ExportFeatureValues]. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: snapshot_export (google.cloud.aiplatform_v1beta1.types.ExportFeatureValuesRequest.SnapshotExport): - Exports Feature values of all entities of the - EntityType as of a snapshot time. + Exports the latest Feature values of all + entities of the EntityType within a time range. + + This field is a member of `oneof`_ ``mode``. + full_export (google.cloud.aiplatform_v1beta1.types.ExportFeatureValuesRequest.FullExport): + Exports all historical values of all entities + of the EntityType within a time range + + This field is a member of `oneof`_ ``mode``. entity_type (str): Required. The resource name of the EntityType from which to export Feature values. Format: @@ -475,8 +662,8 @@ class ExportFeatureValuesRequest(proto.Message): """ class SnapshotExport(proto.Message): - r"""Describes exporting Feature values as of the snapshot - timestamp. + r"""Describes exporting the latest Feature values of all entities of the + EntityType between [start_time, snapshot_time]. Attributes: snapshot_time (google.protobuf.timestamp_pb2.Timestamp): @@ -484,29 +671,90 @@ class SnapshotExport(proto.Message): If not set, retrieve values as of now. Timestamp, if present, must not have higher than millisecond precision. + start_time (google.protobuf.timestamp_pb2.Timestamp): + Excludes Feature values with feature + generation timestamp before this timestamp. If + not set, retrieve oldest values kept in Feature + Store. Timestamp, if present, must not have + higher than millisecond precision. """ snapshot_time = proto.Field( - proto.MESSAGE, number=1, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=1, + message=timestamp_pb2.Timestamp, + ) + start_time = proto.Field( + proto.MESSAGE, + number=2, + message=timestamp_pb2.Timestamp, + ) + + class FullExport(proto.Message): + r"""Describes exporting all historical Feature values of all entities of + the EntityType between [start_time, end_time]. + + Attributes: + start_time (google.protobuf.timestamp_pb2.Timestamp): + Excludes Feature values with feature + generation timestamp before this timestamp. If + not set, retrieve oldest values kept in Feature + Store. Timestamp, if present, must not have + higher than millisecond precision. + end_time (google.protobuf.timestamp_pb2.Timestamp): + Exports Feature values as of this timestamp. + If not set, retrieve values as of now. + Timestamp, if present, must not have higher than + millisecond precision. + """ + + start_time = proto.Field( + proto.MESSAGE, + number=2, + message=timestamp_pb2.Timestamp, + ) + end_time = proto.Field( + proto.MESSAGE, + number=1, + message=timestamp_pb2.Timestamp, ) snapshot_export = proto.Field( - proto.MESSAGE, number=3, oneof="mode", message=SnapshotExport, + proto.MESSAGE, + number=3, + oneof="mode", + message=SnapshotExport, + ) + full_export = proto.Field( + proto.MESSAGE, + number=7, + oneof="mode", + message=FullExport, + ) + entity_type = proto.Field( + proto.STRING, + number=1, ) - entity_type = proto.Field(proto.STRING, number=1,) destination = proto.Field( - proto.MESSAGE, number=4, message="FeatureValueDestination", + proto.MESSAGE, + number=4, + message="FeatureValueDestination", ) feature_selector = proto.Field( - proto.MESSAGE, number=5, message=gca_feature_selector.FeatureSelector, + proto.MESSAGE, + number=5, + message=gca_feature_selector.FeatureSelector, ) settings = proto.RepeatedField( - proto.MESSAGE, number=6, message="DestinationFeatureSetting", + proto.MESSAGE, + number=6, + message="DestinationFeatureSetting", ) class DestinationFeatureSetting(proto.Message): r""" + Attributes: feature_id (str): Required. The ID of the Feature to apply the @@ -517,12 +765,26 @@ class DestinationFeatureSetting(proto.Message): used. """ - feature_id = proto.Field(proto.STRING, number=1,) - destination_field = proto.Field(proto.STRING, number=2,) + feature_id = proto.Field( + proto.STRING, + number=1, + ) + destination_field = proto.Field( + proto.STRING, + number=2, + ) class FeatureValueDestination(proto.Message): r"""A destination location for Feature values and format. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: bigquery_destination (google.cloud.aiplatform_v1beta1.types.BigQueryDestination): Output in BigQuery format. @@ -530,6 +792,8 @@ class FeatureValueDestination(proto.Message): in [FeatureValueDestination.bigquery_destination][google.cloud.aiplatform.v1beta1.FeatureValueDestination.bigquery_destination] must refer to a table. + + This field is a member of `oneof`_ ``destination``. tfrecord_destination (google.cloud.aiplatform_v1beta1.types.TFRecordDestination): Output in TFRecord format. @@ -544,32 +808,47 @@ class FeatureValueDestination(proto.Message): STRING, STRING_ARRAY, BYTES | BYTES_LIST true -> byte_string("true"), false -> byte_string("false") BOOL, BOOL_ARRAY (true, false) | BYTES_LIST + + This field is a member of `oneof`_ ``destination``. csv_destination (google.cloud.aiplatform_v1beta1.types.CsvDestination): Output in CSV format. Array Feature value types are not allowed in CSV format. + + This field is a member of `oneof`_ ``destination``. """ bigquery_destination = proto.Field( - proto.MESSAGE, number=1, oneof="destination", message=io.BigQueryDestination, + proto.MESSAGE, + number=1, + oneof="destination", + message=io.BigQueryDestination, ) tfrecord_destination = proto.Field( - proto.MESSAGE, number=2, oneof="destination", message=io.TFRecordDestination, + proto.MESSAGE, + number=2, + oneof="destination", + message=io.TFRecordDestination, ) csv_destination = proto.Field( - proto.MESSAGE, number=3, oneof="destination", message=io.CsvDestination, + proto.MESSAGE, + number=3, + oneof="destination", + message=io.CsvDestination, ) class ExportFeatureValuesResponse(proto.Message): r"""Response message for [FeaturestoreService.ExportFeatureValues][google.cloud.aiplatform.v1beta1.FeaturestoreService.ExportFeatureValues]. - """ + + """ class BatchReadFeatureValuesResponse(proto.Message): r"""Response message for [FeaturestoreService.BatchReadFeatureValues][google.cloud.aiplatform.v1beta1.FeaturestoreService.BatchReadFeatureValues]. - """ + + """ class CreateEntityTypeRequest(proto.Message): @@ -594,11 +873,19 @@ class CreateEntityTypeRequest(proto.Message): The value must be unique within a featurestore. """ - parent = proto.Field(proto.STRING, number=1,) + parent = proto.Field( + proto.STRING, + number=1, + ) entity_type = proto.Field( - proto.MESSAGE, number=2, message=gca_entity_type.EntityType, + proto.MESSAGE, + number=2, + message=gca_entity_type.EntityType, + ) + entity_type_id = proto.Field( + proto.STRING, + number=3, ) - entity_type_id = proto.Field(proto.STRING, number=3,) class GetEntityTypeRequest(proto.Message): @@ -611,7 +898,10 @@ class GetEntityTypeRequest(proto.Message): ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListEntityTypesRequest(proto.Message): @@ -627,10 +917,12 @@ class ListEntityTypesRequest(proto.Message): Lists the EntityTypes that match the filter expression. The following filters are supported: - - ``create_time``: Supports =, !=, <, >, >=, and <= - comparisons. Values must be in RFC 3339 format. - - ``update_time``: Supports =, !=, <, >, >=, and <= - comparisons. Values must be in RFC 3339 format. + - ``create_time``: Supports ``=``, ``!=``, ``<``, ``>``, + ``>=``, and ``<=`` comparisons. Values must be in RFC + 3339 format. + - ``update_time``: Supports ``=``, ``!=``, ``<``, ``>``, + ``>=``, and ``<=`` comparisons. Values must be in RFC + 3339 format. - ``labels``: Supports key-value equality as well as key presence. @@ -672,12 +964,31 @@ class ListEntityTypesRequest(proto.Message): Mask specifying which fields to read. """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) - order_by = proto.Field(proto.STRING, number=5,) - read_mask = proto.Field(proto.MESSAGE, number=6, message=field_mask_pb2.FieldMask,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + order_by = proto.Field( + proto.STRING, + number=5, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=6, + message=field_mask_pb2.FieldMask, + ) class ListEntityTypesResponse(proto.Message): @@ -699,9 +1010,14 @@ def raw_page(self): return self entity_types = proto.RepeatedField( - proto.MESSAGE, number=1, message=gca_entity_type.EntityType, + proto.MESSAGE, + number=1, + message=gca_entity_type.EntityType, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class UpdateEntityTypeRequest(proto.Message): @@ -728,19 +1044,29 @@ class UpdateEntityTypeRequest(proto.Message): - ``description`` - ``labels`` - ``monitoring_config.snapshot_analysis.disabled`` - - ``monitoring_config.snapshot_analysis.monitoring_interval`` + - ``monitoring_config.snapshot_analysis.monitoring_interval_days`` + - ``monitoring_config.snapshot_analysis.staleness_days`` + - ``monitoring_config.import_features_analysis.state`` + - ``monitoring_config.import_features_analysis.anomaly_detection_baseline`` + - ``monitoring_config.numerical_threshold_config.value`` + - ``monitoring_config.categorical_threshold_config.value`` """ entity_type = proto.Field( - proto.MESSAGE, number=1, message=gca_entity_type.EntityType, + proto.MESSAGE, + number=1, + message=gca_entity_type.EntityType, ) update_mask = proto.Field( - proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, ) class DeleteEntityTypeRequest(proto.Message): r"""Request message for [FeaturestoreService.DeleteEntityTypes][]. + Attributes: name (str): Required. The name of the EntityType to be deleted. Format: @@ -752,8 +1078,14 @@ class DeleteEntityTypeRequest(proto.Message): Features.) """ - name = proto.Field(proto.STRING, number=1,) - force = proto.Field(proto.BOOL, number=2,) + name = proto.Field( + proto.STRING, + number=1, + ) + force = proto.Field( + proto.BOOL, + number=2, + ) class CreateFeatureRequest(proto.Message): @@ -777,9 +1109,19 @@ class CreateFeatureRequest(proto.Message): The value must be unique within an EntityType. """ - parent = proto.Field(proto.STRING, number=1,) - feature = proto.Field(proto.MESSAGE, number=2, message=gca_feature.Feature,) - feature_id = proto.Field(proto.STRING, number=3,) + parent = proto.Field( + proto.STRING, + number=1, + ) + feature = proto.Field( + proto.MESSAGE, + number=2, + message=gca_feature.Feature, + ) + feature_id = proto.Field( + proto.STRING, + number=3, + ) class BatchCreateFeaturesRequest(proto.Message): @@ -800,9 +1142,14 @@ class BatchCreateFeaturesRequest(proto.Message): this request message. """ - parent = proto.Field(proto.STRING, number=1,) + parent = proto.Field( + proto.STRING, + number=1, + ) requests = proto.RepeatedField( - proto.MESSAGE, number=2, message="CreateFeatureRequest", + proto.MESSAGE, + number=2, + message="CreateFeatureRequest", ) @@ -816,7 +1163,9 @@ class BatchCreateFeaturesResponse(proto.Message): """ features = proto.RepeatedField( - proto.MESSAGE, number=1, message=gca_feature.Feature, + proto.MESSAGE, + number=1, + message=gca_feature.Feature, ) @@ -830,7 +1179,10 @@ class GetFeatureRequest(proto.Message): ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListFeaturesRequest(proto.Message): @@ -900,13 +1252,35 @@ class ListFeaturesRequest(proto.Message): return all existing stats. """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) - order_by = proto.Field(proto.STRING, number=5,) - read_mask = proto.Field(proto.MESSAGE, number=6, message=field_mask_pb2.FieldMask,) - latest_stats_count = proto.Field(proto.INT32, number=7,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + order_by = proto.Field( + proto.STRING, + number=5, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=6, + message=field_mask_pb2.FieldMask, + ) + latest_stats_count = proto.Field( + proto.INT32, + number=7, + ) class ListFeaturesResponse(proto.Message): @@ -928,9 +1302,14 @@ def raw_page(self): return self features = proto.RepeatedField( - proto.MESSAGE, number=1, message=gca_feature.Feature, + proto.MESSAGE, + number=1, + message=gca_feature.Feature, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class SearchFeaturesRequest(proto.Message): @@ -955,9 +1334,9 @@ class SearchFeaturesRequest(proto.Message): - Removing leading/trailing whitespace and tokenizing the search value. Characters that are not one of alphanumeric - [a-zA-Z0-9], underscore [_], or asterisk [*] are treated - as delimiters for tokens. (*) is treated as a wildcard - that matches characters within a token. + ``[a-zA-Z0-9]``, underscore ``_``, or asterisk ``*`` are + treated as delimiters for tokens. ``*`` is treated as a + wildcard that matches characters within a token. - Ignoring case. - Prepending an asterisk to the first and appending an asterisk to the last token in QUERY. @@ -1028,10 +1407,22 @@ class SearchFeaturesRequest(proto.Message): page token. """ - location = proto.Field(proto.STRING, number=1,) - query = proto.Field(proto.STRING, number=3,) - page_size = proto.Field(proto.INT32, number=4,) - page_token = proto.Field(proto.STRING, number=5,) + location = proto.Field( + proto.STRING, + number=1, + ) + query = proto.Field( + proto.STRING, + number=3, + ) + page_size = proto.Field( + proto.INT32, + number=4, + ) + page_token = proto.Field( + proto.STRING, + number=5, + ) class SearchFeaturesResponse(proto.Message): @@ -1061,9 +1452,14 @@ def raw_page(self): return self features = proto.RepeatedField( - proto.MESSAGE, number=1, message=gca_feature.Feature, + proto.MESSAGE, + number=1, + message=gca_feature.Feature, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class UpdateFeatureRequest(proto.Message): @@ -1088,13 +1484,18 @@ class UpdateFeatureRequest(proto.Message): - ``description`` - ``labels`` - - ``monitoring_config.snapshot_analysis.disabled`` - - ``monitoring_config.snapshot_analysis.monitoring_interval`` + - ``disable_monitoring`` """ - feature = proto.Field(proto.MESSAGE, number=1, message=gca_feature.Feature,) + feature = proto.Field( + proto.MESSAGE, + number=1, + message=gca_feature.Feature, + ) update_mask = proto.Field( - proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, ) @@ -1108,44 +1509,54 @@ class DeleteFeatureRequest(proto.Message): ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}/features/{feature}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class CreateFeaturestoreOperationMetadata(proto.Message): r"""Details of operations that perform create Featurestore. + Attributes: generic_metadata (google.cloud.aiplatform_v1beta1.types.GenericOperationMetadata): Operation metadata for Featurestore. """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, ) class UpdateFeaturestoreOperationMetadata(proto.Message): r"""Details of operations that perform update Featurestore. + Attributes: generic_metadata (google.cloud.aiplatform_v1beta1.types.GenericOperationMetadata): Operation metadata for Featurestore. """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, ) class ImportFeatureValuesOperationMetadata(proto.Message): - r"""Details of operations that perform import feature values. + r"""Details of operations that perform import Feature values. + Attributes: generic_metadata (google.cloud.aiplatform_v1beta1.types.GenericOperationMetadata): Operation metadata for Featurestore import - feature values. + Feature values. imported_entity_count (int): Number of entities that have been imported by the operation. imported_feature_value_count (int): - Number of feature values that have been + Number of Feature values that have been imported by the operation. invalid_row_count (int): The number of rows in input source that weren't imported due @@ -1158,15 +1569,27 @@ class ImportFeatureValuesOperationMetadata(proto.Message): """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, + ) + imported_entity_count = proto.Field( + proto.INT64, + number=2, + ) + imported_feature_value_count = proto.Field( + proto.INT64, + number=3, + ) + invalid_row_count = proto.Field( + proto.INT64, + number=6, ) - imported_entity_count = proto.Field(proto.INT64, number=2,) - imported_feature_value_count = proto.Field(proto.INT64, number=3,) - invalid_row_count = proto.Field(proto.INT64, number=6,) class ExportFeatureValuesOperationMetadata(proto.Message): r"""Details of operations that exports Features values. + Attributes: generic_metadata (google.cloud.aiplatform_v1beta1.types.GenericOperationMetadata): Operation metadata for Featurestore export @@ -1174,12 +1597,15 @@ class ExportFeatureValuesOperationMetadata(proto.Message): """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, ) class BatchReadFeatureValuesOperationMetadata(proto.Message): r"""Details of operations that batch reads Feature values. + Attributes: generic_metadata (google.cloud.aiplatform_v1beta1.types.GenericOperationMetadata): Operation metadata for Featurestore batch @@ -1187,43 +1613,54 @@ class BatchReadFeatureValuesOperationMetadata(proto.Message): """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, ) class CreateEntityTypeOperationMetadata(proto.Message): r"""Details of operations that perform create EntityType. + Attributes: generic_metadata (google.cloud.aiplatform_v1beta1.types.GenericOperationMetadata): Operation metadata for EntityType. """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, ) class CreateFeatureOperationMetadata(proto.Message): r"""Details of operations that perform create Feature. + Attributes: generic_metadata (google.cloud.aiplatform_v1beta1.types.GenericOperationMetadata): Operation metadata for Feature. """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, ) class BatchCreateFeaturesOperationMetadata(proto.Message): r"""Details of operations that perform batch create Features. + Attributes: generic_metadata (google.cloud.aiplatform_v1beta1.types.GenericOperationMetadata): Operation metadata for Feature. """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, ) diff --git a/google/cloud/aiplatform_v1beta1/types/hyperparameter_tuning_job.py b/google/cloud/aiplatform_v1beta1/types/hyperparameter_tuning_job.py index 1344489d7d..11c88fdfa4 100644 --- a/google/cloud/aiplatform_v1beta1/types/hyperparameter_tuning_job.py +++ b/google/cloud/aiplatform_v1beta1/types/hyperparameter_tuning_job.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -24,7 +24,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"HyperparameterTuningJob",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "HyperparameterTuningJob", + }, ) @@ -53,7 +56,7 @@ class HyperparameterTuningJob(proto.Message): max_failed_trial_count (int): The number of failed Trials that need to be seen before failing the HyperparameterTuningJob. - If set to 0, AI Platform decides how many Trials + If set to 0, Vertex AI decides how many Trials must fail before the whole job fails. trial_job_spec (google.cloud.aiplatform_v1beta1.types.CustomJobSpec): Required. The spec of a trial job. The same @@ -81,7 +84,7 @@ class HyperparameterTuningJob(proto.Message): error (google.rpc.status_pb2.Status): Output only. Only populated when job's state is JOB_STATE_FAILED or JOB_STATE_CANCELLED. - labels (Sequence[google.cloud.aiplatform_v1beta1.types.HyperparameterTuningJob.LabelsEntry]): + labels (Mapping[str, str]): The labels with user-defined metadata to organize HyperparameterTuningJobs. Label keys and values can be no longer than 64 @@ -99,29 +102,80 @@ class HyperparameterTuningJob(proto.Message): the provided encryption key. """ - name = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) - study_spec = proto.Field(proto.MESSAGE, number=4, message=study.StudySpec,) - max_trial_count = proto.Field(proto.INT32, number=5,) - parallel_trial_count = proto.Field(proto.INT32, number=6,) - max_failed_trial_count = proto.Field(proto.INT32, number=7,) + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + study_spec = proto.Field( + proto.MESSAGE, + number=4, + message=study.StudySpec, + ) + max_trial_count = proto.Field( + proto.INT32, + number=5, + ) + parallel_trial_count = proto.Field( + proto.INT32, + number=6, + ) + max_failed_trial_count = proto.Field( + proto.INT32, + number=7, + ) trial_job_spec = proto.Field( - proto.MESSAGE, number=8, message=custom_job.CustomJobSpec, + proto.MESSAGE, + number=8, + message=custom_job.CustomJobSpec, + ) + trials = proto.RepeatedField( + proto.MESSAGE, + number=9, + message=study.Trial, + ) + state = proto.Field( + proto.ENUM, + number=10, + enum=job_state.JobState, ) - trials = proto.RepeatedField(proto.MESSAGE, number=9, message=study.Trial,) - state = proto.Field(proto.ENUM, number=10, enum=job_state.JobState,) create_time = proto.Field( - proto.MESSAGE, number=11, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=11, + message=timestamp_pb2.Timestamp, + ) + start_time = proto.Field( + proto.MESSAGE, + number=12, + message=timestamp_pb2.Timestamp, + ) + end_time = proto.Field( + proto.MESSAGE, + number=13, + message=timestamp_pb2.Timestamp, ) - start_time = proto.Field(proto.MESSAGE, number=12, message=timestamp_pb2.Timestamp,) - end_time = proto.Field(proto.MESSAGE, number=13, message=timestamp_pb2.Timestamp,) update_time = proto.Field( - proto.MESSAGE, number=14, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=14, + message=timestamp_pb2.Timestamp, + ) + error = proto.Field( + proto.MESSAGE, + number=15, + message=status_pb2.Status, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=16, ) - error = proto.Field(proto.MESSAGE, number=15, message=status_pb2.Status,) - labels = proto.MapField(proto.STRING, proto.STRING, number=16,) encryption_spec = proto.Field( - proto.MESSAGE, number=17, message=gca_encryption_spec.EncryptionSpec, + proto.MESSAGE, + number=17, + message=gca_encryption_spec.EncryptionSpec, ) diff --git a/google/cloud/aiplatform_v1beta1/types/index.py b/google/cloud/aiplatform_v1beta1/types/index.py index 47341bbe06..96efd0f02d 100644 --- a/google/cloud/aiplatform_v1beta1/types/index.py +++ b/google/cloud/aiplatform_v1beta1/types/index.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,7 +21,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"Index",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "Index", + }, ) @@ -45,7 +48,7 @@ class Index(proto.Message): that is specific to it. Unset if the Index does not have any additional information. The schema is defined as an OpenAPI 3.0.2 `Schema - Object `__. + Object `__. Note: The URI given on output will be immutable and probably different, including the URI scheme, than the one given on input. The output URI will point to a location where the @@ -63,7 +66,7 @@ class Index(proto.Message): Used to perform consistent read-modify-write updates. If not set, a blind "overwrite" update happens. - labels (Sequence[google.cloud.aiplatform_v1beta1.types.Index.LabelsEntry]): + labels (Mapping[str, str]): The labels with user-defined metadata to organize your Indexes. Label keys and values can be no longer than 64 @@ -89,21 +92,50 @@ class Index(proto.Message): Index is reflected in it. """ - name = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) - description = proto.Field(proto.STRING, number=3,) - metadata_schema_uri = proto.Field(proto.STRING, number=4,) - metadata = proto.Field(proto.MESSAGE, number=6, message=struct_pb2.Value,) + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + description = proto.Field( + proto.STRING, + number=3, + ) + metadata_schema_uri = proto.Field( + proto.STRING, + number=4, + ) + metadata = proto.Field( + proto.MESSAGE, + number=6, + message=struct_pb2.Value, + ) deployed_indexes = proto.RepeatedField( - proto.MESSAGE, number=7, message=deployed_index_ref.DeployedIndexRef, + proto.MESSAGE, + number=7, + message=deployed_index_ref.DeployedIndexRef, + ) + etag = proto.Field( + proto.STRING, + number=8, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=9, ) - etag = proto.Field(proto.STRING, number=8,) - labels = proto.MapField(proto.STRING, proto.STRING, number=9,) create_time = proto.Field( - proto.MESSAGE, number=10, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=10, + message=timestamp_pb2.Timestamp, ) update_time = proto.Field( - proto.MESSAGE, number=11, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=11, + message=timestamp_pb2.Timestamp, ) diff --git a/google/cloud/aiplatform_v1beta1/types/index_endpoint.py b/google/cloud/aiplatform_v1beta1/types/index_endpoint.py index ae7d3cfb6b..593aa01378 100644 --- a/google/cloud/aiplatform_v1beta1/types/index_endpoint.py +++ b/google/cloud/aiplatform_v1beta1/types/index_endpoint.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -52,7 +52,7 @@ class IndexEndpoint(proto.Message): Used to perform consistent read-modify-write updates. If not set, a blind "overwrite" update happens. - labels (Sequence[google.cloud.aiplatform_v1beta1.types.IndexEndpoint.LabelsEntry]): + labels (Mapping[str, str]): The labels with user-defined metadata to organize your IndexEndpoints. Label keys and values can be no longer than 64 @@ -73,8 +73,7 @@ class IndexEndpoint(proto.Message): of the original Indexes they are the deployments of. network (str): - Required. Immutable. The full name of the Google Compute - Engine + Optional. The full name of the Google Compute Engine `network `__ to which the IndexEndpoint should be peered. @@ -82,23 +81,70 @@ class IndexEndpoint(proto.Message): network. If left unspecified, the Endpoint is not peered with any network. + [network][google.cloud.aiplatform.v1beta1.IndexEndpoint.network] + and + [private_service_connect_config][google.cloud.aiplatform.v1beta1.IndexEndpoint.private_service_connect_config] + are mutually exclusive. + `Format `__: projects/{project}/global/networks/{network}. Where {project} is a project number, as in '12345', and {network} is network name. + enable_private_service_connect (bool): + Optional. Deprecated: If true, expose the IndexEndpoint via + private service connect. + + Only one of the fields, + [network][google.cloud.aiplatform.v1beta1.IndexEndpoint.network] + or + [enable_private_service_connect][google.cloud.aiplatform.v1beta1.IndexEndpoint.enable_private_service_connect], + can be set. """ - name = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) - description = proto.Field(proto.STRING, number=3,) + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + description = proto.Field( + proto.STRING, + number=3, + ) deployed_indexes = proto.RepeatedField( - proto.MESSAGE, number=4, message="DeployedIndex", + proto.MESSAGE, + number=4, + message="DeployedIndex", + ) + etag = proto.Field( + proto.STRING, + number=5, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=6, + ) + create_time = proto.Field( + proto.MESSAGE, + number=7, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=8, + message=timestamp_pb2.Timestamp, + ) + network = proto.Field( + proto.STRING, + number=9, + ) + enable_private_service_connect = proto.Field( + proto.BOOL, + number=10, ) - etag = proto.Field(proto.STRING, number=5,) - labels = proto.MapField(proto.STRING, proto.STRING, number=6,) - create_time = proto.Field(proto.MESSAGE, number=7, message=timestamp_pb2.Timestamp,) - update_time = proto.Field(proto.MESSAGE, number=8, message=timestamp_pb2.Timestamp,) - network = proto.Field(proto.STRING, number=9,) class DeployedIndex(proto.Message): @@ -150,14 +196,21 @@ class DeployedIndex(proto.Message): DeployedIndex. automatic_resources (google.cloud.aiplatform_v1beta1.types.AutomaticResources): Optional. A description of resources that the DeployedIndex - uses, which to large degree are decided by AI Platform, and + uses, which to large degree are decided by Vertex AI, and optionally allows only a modest additional configuration. If - min_replica_count is not set, the default value is 1. If + min_replica_count is not set, the default value is 2 (we + don't provide SLA when min_replica_count=1). If max_replica_count is not set, the default value is min_replica_count. The max allowed replica count is 1000. + dedicated_resources (google.cloud.aiplatform_v1beta1.types.DedicatedResources): + Optional. A description of resources that are dedicated to + the DeployedIndex, and that need a higher degree of manual + configuration. If min_replica_count is not set, the default + value is 2 (we don't provide SLA when min_replica_count=1). + If max_replica_count is not set, the default value is + min_replica_count. The max allowed replica count is 1000. - The user is billed for the resources (at least their minimal - amount) even if the DeployedIndex receives no traffic. + Available machine types: n1-standard-16 n1-standard-32 enable_access_logging (bool): Optional. If true, private endpoint's access logs are sent to StackDriver Logging. @@ -171,24 +224,89 @@ class DeployedIndex(proto.Message): deployed_index_auth_config (google.cloud.aiplatform_v1beta1.types.DeployedIndexAuthConfig): Optional. If set, the authentication is enabled for the private endpoint. + reserved_ip_ranges (Sequence[str]): + Optional. A list of reserved ip ranges under + the VPC network that can be used for this + DeployedIndex. + If set, we will deploy the index within the + provided ip ranges. Otherwise, the index might + be deployed to any ip ranges under the provided + VPC network. + + The value sohuld be the name of the address + (https://cloud.google.com/compute/docs/reference/rest/v1/addresses) + Example: 'vertex-ai-ip-range'. + deployment_group (str): + Optional. The deployment group can be no longer than 64 + characters (eg: 'test', 'prod'). If not set, we will use the + 'default' deployment group. + + Creating ``deployment_groups`` with ``reserved_ip_ranges`` + is a recommended practice when the peered network has + multiple peering ranges. This creates your deployments from + predictable IP spaces for easier traffic administration. + Also, one deployment_group (except 'default') can only be + used with the same reserved_ip_ranges which means if the + deployment_group has been used with reserved_ip_ranges: [a, + b, c], using it with [a, b] or [d, e] is disallowed. + + Note: we only support up to 5 deployment groups(not + including 'default'). """ - id = proto.Field(proto.STRING, number=1,) - index = proto.Field(proto.STRING, number=2,) - display_name = proto.Field(proto.STRING, number=3,) - create_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) + id = proto.Field( + proto.STRING, + number=1, + ) + index = proto.Field( + proto.STRING, + number=2, + ) + display_name = proto.Field( + proto.STRING, + number=3, + ) + create_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) private_endpoints = proto.Field( - proto.MESSAGE, number=5, message="IndexPrivateEndpoints", + proto.MESSAGE, + number=5, + message="IndexPrivateEndpoints", ) index_sync_time = proto.Field( - proto.MESSAGE, number=6, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=6, + message=timestamp_pb2.Timestamp, ) automatic_resources = proto.Field( - proto.MESSAGE, number=7, message=machine_resources.AutomaticResources, + proto.MESSAGE, + number=7, + message=machine_resources.AutomaticResources, + ) + dedicated_resources = proto.Field( + proto.MESSAGE, + number=16, + message=machine_resources.DedicatedResources, + ) + enable_access_logging = proto.Field( + proto.BOOL, + number=8, ) - enable_access_logging = proto.Field(proto.BOOL, number=8,) deployed_index_auth_config = proto.Field( - proto.MESSAGE, number=9, message="DeployedIndexAuthConfig", + proto.MESSAGE, + number=9, + message="DeployedIndexAuthConfig", + ) + reserved_ip_ranges = proto.RepeatedField( + proto.STRING, + number=10, + ) + deployment_group = proto.Field( + proto.STRING, + number=11, ) @@ -220,23 +338,47 @@ class AuthProvider(proto.Message): ``service-account-name@project-id.iam.gserviceaccount.com`` """ - audiences = proto.RepeatedField(proto.STRING, number=1,) - allowed_issuers = proto.RepeatedField(proto.STRING, number=2,) + audiences = proto.RepeatedField( + proto.STRING, + number=1, + ) + allowed_issuers = proto.RepeatedField( + proto.STRING, + number=2, + ) - auth_provider = proto.Field(proto.MESSAGE, number=1, message=AuthProvider,) + auth_provider = proto.Field( + proto.MESSAGE, + number=1, + message=AuthProvider, + ) class IndexPrivateEndpoints(proto.Message): - r"""IndexPrivateEndpoints proto is used to provide paths for - users to send requests via private services access. + r"""IndexPrivateEndpoints proto is used to provide paths for users to + send requests via private endpoints (e.g. private service access, + private service connect). To send request via private service + access, use match_grpc_address. To send request via private service + connect, use service_attachment. Attributes: match_grpc_address (str): Output only. The ip address used to send match gRPC requests. + service_attachment (str): + Output only. The name of the service + attachment resource. Populated if private + service connect is enabled. """ - match_grpc_address = proto.Field(proto.STRING, number=1,) + match_grpc_address = proto.Field( + proto.STRING, + number=1, + ) + service_attachment = proto.Field( + proto.STRING, + number=2, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/index_endpoint_service.py b/google/cloud/aiplatform_v1beta1/types/index_endpoint_service.py index 7703e02883..4b7017ee61 100644 --- a/google/cloud/aiplatform_v1beta1/types/index_endpoint_service.py +++ b/google/cloud/aiplatform_v1beta1/types/index_endpoint_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -36,6 +36,9 @@ "UndeployIndexRequest", "UndeployIndexResponse", "UndeployIndexOperationMetadata", + "MutateDeployedIndexRequest", + "MutateDeployedIndexResponse", + "MutateDeployedIndexOperationMetadata", }, ) @@ -53,9 +56,14 @@ class CreateIndexEndpointRequest(proto.Message): Required. The IndexEndpoint to create. """ - parent = proto.Field(proto.STRING, number=1,) + parent = proto.Field( + proto.STRING, + number=1, + ) index_endpoint = proto.Field( - proto.MESSAGE, number=2, message=gca_index_endpoint.IndexEndpoint, + proto.MESSAGE, + number=2, + message=gca_index_endpoint.IndexEndpoint, ) @@ -69,7 +77,9 @@ class CreateIndexEndpointOperationMetadata(proto.Message): """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, ) @@ -83,7 +93,10 @@ class GetIndexEndpointRequest(proto.Message): ``projects/{project}/locations/{location}/indexEndpoints/{index_endpoint}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListIndexEndpointsRequest(proto.Message): @@ -133,11 +146,27 @@ class ListIndexEndpointsRequest(proto.Message): read. """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) - read_mask = proto.Field(proto.MESSAGE, number=5, message=field_mask_pb2.FieldMask,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=5, + message=field_mask_pb2.FieldMask, + ) class ListIndexEndpointsResponse(proto.Message): @@ -158,9 +187,14 @@ def raw_page(self): return self index_endpoints = proto.RepeatedField( - proto.MESSAGE, number=1, message=gca_index_endpoint.IndexEndpoint, + proto.MESSAGE, + number=1, + message=gca_index_endpoint.IndexEndpoint, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class UpdateIndexEndpointRequest(proto.Message): @@ -173,14 +207,18 @@ class UpdateIndexEndpointRequest(proto.Message): the resource on the server. update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. The update mask applies to the resource. See - `FieldMask `__. + [google.protobuf.FieldMask][google.protobuf.FieldMask]. """ index_endpoint = proto.Field( - proto.MESSAGE, number=1, message=gca_index_endpoint.IndexEndpoint, + proto.MESSAGE, + number=1, + message=gca_index_endpoint.IndexEndpoint, ) update_mask = proto.Field( - proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, ) @@ -195,7 +233,10 @@ class DeleteIndexEndpointRequest(proto.Message): ``projects/{project}/locations/{location}/indexEndpoints/{index_endpoint}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class DeployIndexRequest(proto.Message): @@ -212,9 +253,14 @@ class DeployIndexRequest(proto.Message): within the IndexEndpoint. """ - index_endpoint = proto.Field(proto.STRING, number=1,) + index_endpoint = proto.Field( + proto.STRING, + number=1, + ) deployed_index = proto.Field( - proto.MESSAGE, number=2, message=gca_index_endpoint.DeployedIndex, + proto.MESSAGE, + number=2, + message=gca_index_endpoint.DeployedIndex, ) @@ -229,7 +275,9 @@ class DeployIndexResponse(proto.Message): """ deployed_index = proto.Field( - proto.MESSAGE, number=1, message=gca_index_endpoint.DeployedIndex, + proto.MESSAGE, + number=1, + message=gca_index_endpoint.DeployedIndex, ) @@ -240,10 +288,18 @@ class DeployIndexOperationMetadata(proto.Message): Attributes: generic_metadata (google.cloud.aiplatform_v1beta1.types.GenericOperationMetadata): The operation generic information. + deployed_index_id (str): + The unique index id specified by user """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, + ) + deployed_index_id = proto.Field( + proto.STRING, + number=2, ) @@ -261,14 +317,21 @@ class UndeployIndexRequest(proto.Message): undeployed from the IndexEndpoint. """ - index_endpoint = proto.Field(proto.STRING, number=1,) - deployed_index_id = proto.Field(proto.STRING, number=2,) + index_endpoint = proto.Field( + proto.STRING, + number=1, + ) + deployed_index_id = proto.Field( + proto.STRING, + number=2, + ) class UndeployIndexResponse(proto.Message): r"""Response message for [IndexEndpointService.UndeployIndex][google.cloud.aiplatform.v1beta1.IndexEndpointService.UndeployIndex]. - """ + + """ class UndeployIndexOperationMetadata(proto.Message): @@ -281,7 +344,75 @@ class UndeployIndexOperationMetadata(proto.Message): """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, + ) + + +class MutateDeployedIndexRequest(proto.Message): + r"""Request message for + [IndexEndpointService.MutateDeployedIndex][google.cloud.aiplatform.v1beta1.IndexEndpointService.MutateDeployedIndex]. + + Attributes: + index_endpoint (str): + Required. The name of the IndexEndpoint resource into which + to deploy an Index. Format: + ``projects/{project}/locations/{location}/indexEndpoints/{index_endpoint}`` + deployed_index (google.cloud.aiplatform_v1beta1.types.DeployedIndex): + Required. The DeployedIndex to be updated within the + IndexEndpoint. Currently, the updatable fields are + [DeployedIndex][automatic_resources] and + [DeployedIndex][dedicated_resources] + """ + + index_endpoint = proto.Field( + proto.STRING, + number=1, + ) + deployed_index = proto.Field( + proto.MESSAGE, + number=2, + message=gca_index_endpoint.DeployedIndex, + ) + + +class MutateDeployedIndexResponse(proto.Message): + r"""Response message for + [IndexEndpointService.MutateDeployedIndex][google.cloud.aiplatform.v1beta1.IndexEndpointService.MutateDeployedIndex]. + + Attributes: + deployed_index (google.cloud.aiplatform_v1beta1.types.DeployedIndex): + The DeployedIndex that had been updated in + the IndexEndpoint. + """ + + deployed_index = proto.Field( + proto.MESSAGE, + number=1, + message=gca_index_endpoint.DeployedIndex, + ) + + +class MutateDeployedIndexOperationMetadata(proto.Message): + r"""Runtime operation information for + [IndexEndpointService.MutateDeployedIndex][google.cloud.aiplatform.v1beta1.IndexEndpointService.MutateDeployedIndex]. + + Attributes: + generic_metadata (google.cloud.aiplatform_v1beta1.types.GenericOperationMetadata): + The operation generic information. + deployed_index_id (str): + The unique index id specified by user + """ + + generic_metadata = proto.Field( + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, + ) + deployed_index_id = proto.Field( + proto.STRING, + number=2, ) diff --git a/google/cloud/aiplatform_v1beta1/types/index_service.py b/google/cloud/aiplatform_v1beta1/types/index_service.py index 73335e18e2..375b381c82 100644 --- a/google/cloud/aiplatform_v1beta1/types/index_service.py +++ b/google/cloud/aiplatform_v1beta1/types/index_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -49,8 +49,15 @@ class CreateIndexRequest(proto.Message): Required. The Index to create. """ - parent = proto.Field(proto.STRING, number=1,) - index = proto.Field(proto.MESSAGE, number=2, message=gca_index.Index,) + parent = proto.Field( + proto.STRING, + number=1, + ) + index = proto.Field( + proto.MESSAGE, + number=2, + message=gca_index.Index, + ) class CreateIndexOperationMetadata(proto.Message): @@ -66,10 +73,14 @@ class CreateIndexOperationMetadata(proto.Message): """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, ) nearest_neighbor_search_operation_metadata = proto.Field( - proto.MESSAGE, number=2, message="NearestNeighborSearchOperationMetadata", + proto.MESSAGE, + number=2, + message="NearestNeighborSearchOperationMetadata", ) @@ -83,7 +94,10 @@ class GetIndexRequest(proto.Message): ``projects/{project}/locations/{location}/indexes/{index}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListIndexesRequest(proto.Message): @@ -109,11 +123,27 @@ class ListIndexesRequest(proto.Message): Mask specifying which fields to read. """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) - read_mask = proto.Field(proto.MESSAGE, number=5, message=field_mask_pb2.FieldMask,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=5, + message=field_mask_pb2.FieldMask, + ) class ListIndexesResponse(proto.Message): @@ -133,8 +163,15 @@ class ListIndexesResponse(proto.Message): def raw_page(self): return self - indexes = proto.RepeatedField(proto.MESSAGE, number=1, message=gca_index.Index,) - next_page_token = proto.Field(proto.STRING, number=2,) + indexes = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gca_index.Index, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) class UpdateIndexRequest(proto.Message): @@ -148,12 +185,18 @@ class UpdateIndexRequest(proto.Message): update_mask (google.protobuf.field_mask_pb2.FieldMask): The update mask applies to the resource. For the ``FieldMask`` definition, see - `FieldMask `__. + [google.protobuf.FieldMask][google.protobuf.FieldMask]. """ - index = proto.Field(proto.MESSAGE, number=1, message=gca_index.Index,) + index = proto.Field( + proto.MESSAGE, + number=1, + message=gca_index.Index, + ) update_mask = proto.Field( - proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, ) @@ -170,10 +213,14 @@ class UpdateIndexOperationMetadata(proto.Message): """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, ) nearest_neighbor_search_operation_metadata = proto.Field( - proto.MESSAGE, number=2, message="NearestNeighborSearchOperationMetadata", + proto.MESSAGE, + number=2, + message="NearestNeighborSearchOperationMetadata", ) @@ -188,7 +235,10 @@ class DeleteIndexRequest(proto.Message): ``projects/{project}/locations/{location}/indexes/{index}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class NearestNeighborSearchOperationMetadata(proto.Message): @@ -204,10 +254,13 @@ class NearestNeighborSearchOperationMetadata(proto.Message): Please note that, currently for those files that are broken or has unsupported file format, we will not have the stats for those files. + data_bytes_count (int): + The ingested data size in bytes. """ class RecordError(proto.Message): r""" + Attributes: error_type (google.cloud.aiplatform_v1beta1.types.NearestNeighborSearchOperationMetadata.RecordError.RecordErrorType): The error type of this record. @@ -241,13 +294,26 @@ class RecordErrorType(proto.Enum): number=1, enum="NearestNeighborSearchOperationMetadata.RecordError.RecordErrorType", ) - error_message = proto.Field(proto.STRING, number=2,) - source_gcs_uri = proto.Field(proto.STRING, number=3,) - embedding_id = proto.Field(proto.STRING, number=4,) - raw_record = proto.Field(proto.STRING, number=5,) + error_message = proto.Field( + proto.STRING, + number=2, + ) + source_gcs_uri = proto.Field( + proto.STRING, + number=3, + ) + embedding_id = proto.Field( + proto.STRING, + number=4, + ) + raw_record = proto.Field( + proto.STRING, + number=5, + ) class ContentValidationStats(proto.Message): r""" + Attributes: source_gcs_uri (str): Cloud Storage URI pointing to the original @@ -265,9 +331,18 @@ class ContentValidationStats(proto.Message): will be reported. """ - source_gcs_uri = proto.Field(proto.STRING, number=1,) - valid_record_count = proto.Field(proto.INT64, number=2,) - invalid_record_count = proto.Field(proto.INT64, number=3,) + source_gcs_uri = proto.Field( + proto.STRING, + number=1, + ) + valid_record_count = proto.Field( + proto.INT64, + number=2, + ) + invalid_record_count = proto.Field( + proto.INT64, + number=3, + ) partial_errors = proto.RepeatedField( proto.MESSAGE, number=4, @@ -275,7 +350,13 @@ class ContentValidationStats(proto.Message): ) content_validation_stats = proto.RepeatedField( - proto.MESSAGE, number=1, message=ContentValidationStats, + proto.MESSAGE, + number=1, + message=ContentValidationStats, + ) + data_bytes_count = proto.Field( + proto.INT64, + number=2, ) diff --git a/google/cloud/aiplatform_v1beta1/types/io.py b/google/cloud/aiplatform_v1beta1/types/io.py index 6d456e7b6b..dbe475e605 100644 --- a/google/cloud/aiplatform_v1beta1/types/io.py +++ b/google/cloud/aiplatform_v1beta1/types/io.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -34,26 +34,37 @@ class AvroSource(proto.Message): r"""The storage details for Avro input content. + Attributes: gcs_source (google.cloud.aiplatform_v1beta1.types.GcsSource): Required. Google Cloud Storage location. """ - gcs_source = proto.Field(proto.MESSAGE, number=1, message="GcsSource",) + gcs_source = proto.Field( + proto.MESSAGE, + number=1, + message="GcsSource", + ) class CsvSource(proto.Message): r"""The storage details for CSV input content. + Attributes: gcs_source (google.cloud.aiplatform_v1beta1.types.GcsSource): Required. Google Cloud Storage location. """ - gcs_source = proto.Field(proto.MESSAGE, number=1, message="GcsSource",) + gcs_source = proto.Field( + proto.MESSAGE, + number=1, + message="GcsSource", + ) class GcsSource(proto.Message): r"""The Google Cloud Storage location for the input content. + Attributes: uris (Sequence[str]): Required. Google Cloud Storage URI(-s) to the @@ -62,7 +73,10 @@ class GcsSource(proto.Message): https://cloud.google.com/storage/docs/gsutil/addlhelp/WildcardNames. """ - uris = proto.RepeatedField(proto.STRING, number=1,) + uris = proto.RepeatedField( + proto.STRING, + number=1, + ) class GcsDestination(proto.Message): @@ -77,11 +91,15 @@ class GcsDestination(proto.Message): directory is created if it doesn't exist. """ - output_uri_prefix = proto.Field(proto.STRING, number=1,) + output_uri_prefix = proto.Field( + proto.STRING, + number=1, + ) class BigQuerySource(proto.Message): r"""The BigQuery location for the input content. + Attributes: input_uri (str): Required. BigQuery URI to a table, up to 2000 characters @@ -91,11 +109,15 @@ class BigQuerySource(proto.Message): ``bq://projectId.bqDatasetId.bqTableId``. """ - input_uri = proto.Field(proto.STRING, number=1,) + input_uri = proto.Field( + proto.STRING, + number=1, + ) class BigQueryDestination(proto.Message): r"""The BigQuery location for the output content. + Attributes: output_uri (str): Required. BigQuery URI to a project or table, up to 2000 @@ -108,34 +130,49 @@ class BigQueryDestination(proto.Message): Accepted forms: - BigQuery path. For example: ``bq://projectId`` or + ``bq://projectId.bqDatasetId`` or ``bq://projectId.bqDatasetId.bqTableId``. """ - output_uri = proto.Field(proto.STRING, number=1,) + output_uri = proto.Field( + proto.STRING, + number=1, + ) class CsvDestination(proto.Message): r"""The storage details for CSV output content. + Attributes: gcs_destination (google.cloud.aiplatform_v1beta1.types.GcsDestination): Required. Google Cloud Storage location. """ - gcs_destination = proto.Field(proto.MESSAGE, number=1, message="GcsDestination",) + gcs_destination = proto.Field( + proto.MESSAGE, + number=1, + message="GcsDestination", + ) class TFRecordDestination(proto.Message): r"""The storage details for TFRecord output content. + Attributes: gcs_destination (google.cloud.aiplatform_v1beta1.types.GcsDestination): Required. Google Cloud Storage location. """ - gcs_destination = proto.Field(proto.MESSAGE, number=1, message="GcsDestination",) + gcs_destination = proto.Field( + proto.MESSAGE, + number=1, + message="GcsDestination", + ) class ContainerRegistryDestination(proto.Message): r"""The Container Registry location for the container image. + Attributes: output_uri (str): Required. Container Registry URI of a container image. Only @@ -152,7 +189,10 @@ class ContainerRegistryDestination(proto.Message): default tag. """ - output_uri = proto.Field(proto.STRING, number=1,) + output_uri = proto.Field( + proto.STRING, + number=1, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/job_service.py b/google/cloud/aiplatform_v1beta1/types/job_service.py index 52fe9b14b8..73e25db33d 100644 --- a/google/cloud/aiplatform_v1beta1/types/job_service.py +++ b/google/cloud/aiplatform_v1beta1/types/job_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -88,8 +88,15 @@ class CreateCustomJobRequest(proto.Message): Required. The CustomJob to create. """ - parent = proto.Field(proto.STRING, number=1,) - custom_job = proto.Field(proto.MESSAGE, number=2, message=gca_custom_job.CustomJob,) + parent = proto.Field( + proto.STRING, + number=1, + ) + custom_job = proto.Field( + proto.MESSAGE, + number=2, + message=gca_custom_job.CustomJob, + ) class GetCustomJobRequest(proto.Message): @@ -102,7 +109,10 @@ class GetCustomJobRequest(proto.Message): ``projects/{project}/locations/{location}/customJobs/{custom_job}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListCustomJobsRequest(proto.Message): @@ -144,11 +154,27 @@ class ListCustomJobsRequest(proto.Message): Mask specifying which fields to read. """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) - read_mask = proto.Field(proto.MESSAGE, number=5, message=field_mask_pb2.FieldMask,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=5, + message=field_mask_pb2.FieldMask, + ) class ListCustomJobsResponse(proto.Message): @@ -169,9 +195,14 @@ def raw_page(self): return self custom_jobs = proto.RepeatedField( - proto.MESSAGE, number=1, message=gca_custom_job.CustomJob, + proto.MESSAGE, + number=1, + message=gca_custom_job.CustomJob, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class DeleteCustomJobRequest(proto.Message): @@ -185,7 +216,10 @@ class DeleteCustomJobRequest(proto.Message): ``projects/{project}/locations/{location}/customJobs/{custom_job}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class CancelCustomJobRequest(proto.Message): @@ -198,7 +232,10 @@ class CancelCustomJobRequest(proto.Message): ``projects/{project}/locations/{location}/customJobs/{custom_job}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class CreateDataLabelingJobRequest(proto.Message): @@ -213,9 +250,14 @@ class CreateDataLabelingJobRequest(proto.Message): Required. The DataLabelingJob to create. """ - parent = proto.Field(proto.STRING, number=1,) + parent = proto.Field( + proto.STRING, + number=1, + ) data_labeling_job = proto.Field( - proto.MESSAGE, number=2, message=gca_data_labeling_job.DataLabelingJob, + proto.MESSAGE, + number=2, + message=gca_data_labeling_job.DataLabelingJob, ) @@ -229,7 +271,10 @@ class GetDataLabelingJobRequest(proto.Message): ``projects/{project}/locations/{location}/dataLabelingJobs/{data_labeling_job}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListDataLabelingJobsRequest(proto.Message): @@ -274,12 +319,31 @@ class ListDataLabelingJobsRequest(proto.Message): for descending. """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) - read_mask = proto.Field(proto.MESSAGE, number=5, message=field_mask_pb2.FieldMask,) - order_by = proto.Field(proto.STRING, number=6,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=5, + message=field_mask_pb2.FieldMask, + ) + order_by = proto.Field( + proto.STRING, + number=6, + ) class ListDataLabelingJobsResponse(proto.Message): @@ -299,9 +363,14 @@ def raw_page(self): return self data_labeling_jobs = proto.RepeatedField( - proto.MESSAGE, number=1, message=gca_data_labeling_job.DataLabelingJob, + proto.MESSAGE, + number=1, + message=gca_data_labeling_job.DataLabelingJob, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class DeleteDataLabelingJobRequest(proto.Message): @@ -315,7 +384,10 @@ class DeleteDataLabelingJobRequest(proto.Message): ``projects/{project}/locations/{location}/dataLabelingJobs/{data_labeling_job}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class CancelDataLabelingJobRequest(proto.Message): @@ -328,7 +400,10 @@ class CancelDataLabelingJobRequest(proto.Message): ``projects/{project}/locations/{location}/dataLabelingJobs/{data_labeling_job}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class CreateHyperparameterTuningJobRequest(proto.Message): @@ -345,7 +420,10 @@ class CreateHyperparameterTuningJobRequest(proto.Message): create. """ - parent = proto.Field(proto.STRING, number=1,) + parent = proto.Field( + proto.STRING, + number=1, + ) hyperparameter_tuning_job = proto.Field( proto.MESSAGE, number=2, @@ -364,7 +442,10 @@ class GetHyperparameterTuningJobRequest(proto.Message): ``projects/{project}/locations/{location}/hyperparameterTuningJobs/{hyperparameter_tuning_job}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListHyperparameterTuningJobsRequest(proto.Message): @@ -406,11 +487,27 @@ class ListHyperparameterTuningJobsRequest(proto.Message): Mask specifying which fields to read. """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) - read_mask = proto.Field(proto.MESSAGE, number=5, message=field_mask_pb2.FieldMask,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=5, + message=field_mask_pb2.FieldMask, + ) class ListHyperparameterTuningJobsResponse(proto.Message): @@ -437,7 +534,10 @@ def raw_page(self): number=1, message=gca_hyperparameter_tuning_job.HyperparameterTuningJob, ) - next_page_token = proto.Field(proto.STRING, number=2,) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) class DeleteHyperparameterTuningJobRequest(proto.Message): @@ -451,7 +551,10 @@ class DeleteHyperparameterTuningJobRequest(proto.Message): ``projects/{project}/locations/{location}/hyperparameterTuningJobs/{hyperparameter_tuning_job}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class CancelHyperparameterTuningJobRequest(proto.Message): @@ -465,7 +568,10 @@ class CancelHyperparameterTuningJobRequest(proto.Message): ``projects/{project}/locations/{location}/hyperparameterTuningJobs/{hyperparameter_tuning_job}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class CreateBatchPredictionJobRequest(proto.Message): @@ -481,9 +587,14 @@ class CreateBatchPredictionJobRequest(proto.Message): Required. The BatchPredictionJob to create. """ - parent = proto.Field(proto.STRING, number=1,) + parent = proto.Field( + proto.STRING, + number=1, + ) batch_prediction_job = proto.Field( - proto.MESSAGE, number=2, message=gca_batch_prediction_job.BatchPredictionJob, + proto.MESSAGE, + number=2, + message=gca_batch_prediction_job.BatchPredictionJob, ) @@ -498,7 +609,10 @@ class GetBatchPredictionJobRequest(proto.Message): ``projects/{project}/locations/{location}/batchPredictionJobs/{batch_prediction_job}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListBatchPredictionJobsRequest(proto.Message): @@ -542,11 +656,27 @@ class ListBatchPredictionJobsRequest(proto.Message): Mask specifying which fields to read. """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) - read_mask = proto.Field(proto.MESSAGE, number=5, message=field_mask_pb2.FieldMask,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=5, + message=field_mask_pb2.FieldMask, + ) class ListBatchPredictionJobsResponse(proto.Message): @@ -568,9 +698,14 @@ def raw_page(self): return self batch_prediction_jobs = proto.RepeatedField( - proto.MESSAGE, number=1, message=gca_batch_prediction_job.BatchPredictionJob, + proto.MESSAGE, + number=1, + message=gca_batch_prediction_job.BatchPredictionJob, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class DeleteBatchPredictionJobRequest(proto.Message): @@ -584,7 +719,10 @@ class DeleteBatchPredictionJobRequest(proto.Message): ``projects/{project}/locations/{location}/batchPredictionJobs/{batch_prediction_job}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class CancelBatchPredictionJobRequest(proto.Message): @@ -598,7 +736,10 @@ class CancelBatchPredictionJobRequest(proto.Message): ``projects/{project}/locations/{location}/batchPredictionJobs/{batch_prediction_job}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class CreateModelDeploymentMonitoringJobRequest(proto.Message): @@ -614,7 +755,10 @@ class CreateModelDeploymentMonitoringJobRequest(proto.Message): create """ - parent = proto.Field(proto.STRING, number=1,) + parent = proto.Field( + proto.STRING, + number=1, + ) model_deployment_monitoring_job = proto.Field( proto.MESSAGE, number=2, @@ -630,10 +774,10 @@ class SearchModelDeploymentMonitoringStatsAnomaliesRequest(proto.Message): model_deployment_monitoring_job (str): Required. ModelDeploymentMonitoring Job resource name. Format: - \`projects/{project}/locations/{location}/modelDeploymentMonitoringJobs/{model_deployment_monitoring_job} + ``projects/{project}/locations/{location}/modelDeploymentMonitoringJobs/{model_deployment_monitoring_job}`` deployed_model_id (str): Required. The DeployedModel ID of the - [google.cloud.aiplatform.master.ModelDeploymentMonitoringObjectiveConfig.deployed_model_id]. + [ModelDeploymentMonitoringObjectiveConfig.deployed_model_id]. feature_display_name (str): The feature display name. If specified, only return the stats belonging to this feature. Format: @@ -660,6 +804,7 @@ class SearchModelDeploymentMonitoringStatsAnomaliesRequest(proto.Message): class StatsAnomaliesObjective(proto.Message): r"""Stats requested for specific objective. + Attributes: type_ (google.cloud.aiplatform_v1beta1.types.ModelDeploymentMonitoringObjectiveType): @@ -679,18 +824,46 @@ class StatsAnomaliesObjective(proto.Message): number=1, enum=gca_model_deployment_monitoring_job.ModelDeploymentMonitoringObjectiveType, ) - top_feature_count = proto.Field(proto.INT32, number=4,) + top_feature_count = proto.Field( + proto.INT32, + number=4, + ) - model_deployment_monitoring_job = proto.Field(proto.STRING, number=1,) - deployed_model_id = proto.Field(proto.STRING, number=2,) - feature_display_name = proto.Field(proto.STRING, number=3,) + model_deployment_monitoring_job = proto.Field( + proto.STRING, + number=1, + ) + deployed_model_id = proto.Field( + proto.STRING, + number=2, + ) + feature_display_name = proto.Field( + proto.STRING, + number=3, + ) objectives = proto.RepeatedField( - proto.MESSAGE, number=4, message=StatsAnomaliesObjective, + proto.MESSAGE, + number=4, + message=StatsAnomaliesObjective, + ) + page_size = proto.Field( + proto.INT32, + number=5, + ) + page_token = proto.Field( + proto.STRING, + number=6, + ) + start_time = proto.Field( + proto.MESSAGE, + number=7, + message=timestamp_pb2.Timestamp, + ) + end_time = proto.Field( + proto.MESSAGE, + number=8, + message=timestamp_pb2.Timestamp, ) - page_size = proto.Field(proto.INT32, number=5,) - page_token = proto.Field(proto.STRING, number=6,) - start_time = proto.Field(proto.MESSAGE, number=7, message=timestamp_pb2.Timestamp,) - end_time = proto.Field(proto.MESSAGE, number=8, message=timestamp_pb2.Timestamp,) class SearchModelDeploymentMonitoringStatsAnomaliesResponse(proto.Message): @@ -718,7 +891,10 @@ def raw_page(self): number=1, message=gca_model_deployment_monitoring_job.ModelMonitoringStatsAnomalies, ) - next_page_token = proto.Field(proto.STRING, number=2,) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) class GetModelDeploymentMonitoringJobRequest(proto.Message): @@ -732,7 +908,10 @@ class GetModelDeploymentMonitoringJobRequest(proto.Message): ``projects/{project}/locations/{location}/modelDeploymentMonitoringJobs/{model_deployment_monitoring_job}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListModelDeploymentMonitoringJobsRequest(proto.Message): @@ -753,11 +932,27 @@ class ListModelDeploymentMonitoringJobsRequest(proto.Message): Mask specifying which fields to read """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) - read_mask = proto.Field(proto.MESSAGE, number=5, message=field_mask_pb2.FieldMask,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=5, + message=field_mask_pb2.FieldMask, + ) class ListModelDeploymentMonitoringJobsResponse(proto.Message): @@ -781,7 +976,10 @@ def raw_page(self): number=1, message=gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob, ) - next_page_token = proto.Field(proto.STRING, number=2,) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) class UpdateModelDeploymentMonitoringJobRequest(proto.Message): @@ -793,8 +991,32 @@ class UpdateModelDeploymentMonitoringJobRequest(proto.Message): Required. The model monitoring configuration which replaces the resource on the server. update_mask (google.protobuf.field_mask_pb2.FieldMask): - Required. The update mask applies to the - resource. + Required. The update mask is used to specify the fields to + be overwritten in the ModelDeploymentMonitoringJob resource + by the update. The fields specified in the update_mask are + relative to the resource, not the full request. A field will + be overwritten if it is in the mask. If the user does not + provide a mask then only the non-empty fields present in the + request will be overwritten. Set the update_mask to ``*`` to + override all fields. For the objective config, the user can + either provide the update mask for + model_deployment_monitoring_objective_configs or any + combination of its nested fields, such as: + model_deployment_monitoring_objective_configs.objective_config.training_dataset. + + Updatable fields: + + - ``display_name`` + - ``model_deployment_monitoring_schedule_config`` + - ``model_monitoring_alert_config`` + - ``logging_sampling_strategy`` + - ``labels`` + - ``log_ttl`` + - ``enable_monitoring_pipeline_logs`` . and + - ``model_deployment_monitoring_objective_configs`` . or + - ``model_deployment_monitoring_objective_configs.objective_config.training_dataset`` + - ``model_deployment_monitoring_objective_configs.objective_config.training_prediction_skew_detection_config`` + - ``model_deployment_monitoring_objective_configs.objective_config.prediction_drift_detection_config`` """ model_deployment_monitoring_job = proto.Field( @@ -803,7 +1025,9 @@ class UpdateModelDeploymentMonitoringJobRequest(proto.Message): message=gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob, ) update_mask = proto.Field( - proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, ) @@ -818,7 +1042,10 @@ class DeleteModelDeploymentMonitoringJobRequest(proto.Message): ``projects/{project}/locations/{location}/modelDeploymentMonitoringJobs/{model_deployment_monitoring_job}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class PauseModelDeploymentMonitoringJobRequest(proto.Message): @@ -832,7 +1059,10 @@ class PauseModelDeploymentMonitoringJobRequest(proto.Message): ``projects/{project}/locations/{location}/modelDeploymentMonitoringJobs/{model_deployment_monitoring_job}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ResumeModelDeploymentMonitoringJobRequest(proto.Message): @@ -846,7 +1076,10 @@ class ResumeModelDeploymentMonitoringJobRequest(proto.Message): ``projects/{project}/locations/{location}/modelDeploymentMonitoringJobs/{model_deployment_monitoring_job}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class UpdateModelDeploymentMonitoringJobOperationMetadata(proto.Message): @@ -859,7 +1092,9 @@ class UpdateModelDeploymentMonitoringJobOperationMetadata(proto.Message): """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, ) diff --git a/google/cloud/aiplatform_v1beta1/types/job_state.py b/google/cloud/aiplatform_v1beta1/types/job_state.py index dd05f8e0c5..937f6b9baa 100644 --- a/google/cloud/aiplatform_v1beta1/types/job_state.py +++ b/google/cloud/aiplatform_v1beta1/types/job_state.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,7 +17,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"JobState",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "JobState", + }, ) @@ -33,6 +36,7 @@ class JobState(proto.Enum): JOB_STATE_CANCELLED = 7 JOB_STATE_PAUSED = 8 JOB_STATE_EXPIRED = 9 + JOB_STATE_UPDATING = 10 __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/lineage_subgraph.py b/google/cloud/aiplatform_v1beta1/types/lineage_subgraph.py index 23df024ffd..79429b3f55 100644 --- a/google/cloud/aiplatform_v1beta1/types/lineage_subgraph.py +++ b/google/cloud/aiplatform_v1beta1/types/lineage_subgraph.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,7 +21,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"LineageSubgraph",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "LineageSubgraph", + }, ) @@ -39,11 +42,21 @@ class LineageSubgraph(proto.Message): Executions in the subgraph. """ - artifacts = proto.RepeatedField(proto.MESSAGE, number=1, message=artifact.Artifact,) + artifacts = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=artifact.Artifact, + ) executions = proto.RepeatedField( - proto.MESSAGE, number=2, message=execution.Execution, + proto.MESSAGE, + number=2, + message=execution.Execution, + ) + events = proto.RepeatedField( + proto.MESSAGE, + number=3, + message=event.Event, ) - events = proto.RepeatedField(proto.MESSAGE, number=3, message=event.Event,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/machine_resources.py b/google/cloud/aiplatform_v1beta1/types/machine_resources.py index abd28b68c4..4cd48fdad3 100644 --- a/google/cloud/aiplatform_v1beta1/types/machine_resources.py +++ b/google/cloud/aiplatform_v1beta1/types/machine_resources.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -29,6 +29,7 @@ "BatchDedicatedResources", "ResourcesConsumed", "DiskSpec", + "NfsMount", "AutoscalingMetricSpec", }, ) @@ -36,13 +37,16 @@ class MachineSpec(proto.Message): r"""Specification of a single machine. + Attributes: machine_type (str): - Immutable. The type of the machine. For the machine types - supported for prediction, see - https://tinyurl.com/aip-docs/predictions/machine-types. For - machine types supported for creating a custom training job, - see https://tinyurl.com/aip-docs/training/configure-compute. + Immutable. The type of the machine. + + See the `list of machine types supported for + prediction `__ + + See the `list of machine types supported for custom + training `__. For [DeployedModel][google.cloud.aiplatform.v1beta1.DeployedModel] @@ -61,11 +65,19 @@ class MachineSpec(proto.Message): machine. """ - machine_type = proto.Field(proto.STRING, number=1,) + machine_type = proto.Field( + proto.STRING, + number=1, + ) accelerator_type = proto.Field( - proto.ENUM, number=2, enum=gca_accelerator_type.AcceleratorType, + proto.ENUM, + number=2, + enum=gca_accelerator_type.AcceleratorType, + ) + accelerator_count = proto.Field( + proto.INT32, + number=3, ) - accelerator_count = proto.Field(proto.INT32, number=3,) class DedicatedResources(proto.Message): @@ -78,15 +90,14 @@ class DedicatedResources(proto.Message): Required. Immutable. The specification of a single machine used by the prediction. min_replica_count (int): - Required. Immutable. The minimum number of machine replicas - this DeployedModel will be always deployed on. If traffic - against it increases, it may dynamically be deployed onto - more replicas, and as traffic decreases, some of these extra - replicas may be freed. Note: if - [machine_spec.accelerator_count][google.cloud.aiplatform.v1beta1.MachineSpec.accelerator_count] - is above 0, currently the model will be always deployed - precisely on - [min_replica_count][google.cloud.aiplatform.v1beta1.DedicatedResources.min_replica_count]. + Required. Immutable. The minimum number of + machine replicas this DeployedModel will be + always deployed on. This value must be greater + than or equal to 1. + If traffic against the DeployedModel increases, + it may dynamically be deployed onto more + replicas, and as traffic decreases, some of + these extra replicas may be freed. max_replica_count (int): Immutable. The maximum number of replicas this DeployedModel may be deployed on when the traffic against it increases. If @@ -99,6 +110,12 @@ class DedicatedResources(proto.Message): will use [min_replica_count][google.cloud.aiplatform.v1beta1.DedicatedResources.min_replica_count] as the default value. + + The value of this field impacts the charge against Vertex + CPU and GPU quotas. Specifically, you will be charged for + (max_replica_count \* number of cores in the selected + machine type) and (max_replica_count \* number of GPUs per + replica in the selected machine type). autoscaling_metric_specs (Sequence[google.cloud.aiplatform_v1beta1.types.AutoscalingMetricSpec]): Immutable. The metric specifications that overrides a resource utilization metric (CPU utilization, accelerator's @@ -129,17 +146,29 @@ class DedicatedResources(proto.Message): to ``80``. """ - machine_spec = proto.Field(proto.MESSAGE, number=1, message="MachineSpec",) - min_replica_count = proto.Field(proto.INT32, number=2,) - max_replica_count = proto.Field(proto.INT32, number=3,) + machine_spec = proto.Field( + proto.MESSAGE, + number=1, + message="MachineSpec", + ) + min_replica_count = proto.Field( + proto.INT32, + number=2, + ) + max_replica_count = proto.Field( + proto.INT32, + number=3, + ) autoscaling_metric_specs = proto.RepeatedField( - proto.MESSAGE, number=4, message="AutoscalingMetricSpec", + proto.MESSAGE, + number=4, + message="AutoscalingMetricSpec", ) class AutomaticResources(proto.Message): r"""A description of resources that to large degree are decided - by AI Platform, and require only a modest additional + by Vertex AI, and require only a modest additional configuration. Each Model supporting these resources documents its specific guidelines. @@ -164,13 +193,19 @@ class AutomaticResources(proto.Message): its replicas at maximum may handle, a portion of the traffic will be dropped. If this value is not provided, a no upper bound for scaling under - heavy traffic will be assume, though AI Platform + heavy traffic will be assume, though Vertex AI may be unable to scale beyond certain replica number. """ - min_replica_count = proto.Field(proto.INT32, number=1,) - max_replica_count = proto.Field(proto.INT32, number=2,) + min_replica_count = proto.Field( + proto.INT32, + number=1, + ) + max_replica_count = proto.Field( + proto.INT32, + number=2, + ) class BatchDedicatedResources(proto.Message): @@ -184,7 +219,7 @@ class BatchDedicatedResources(proto.Message): single machine. starting_replica_count (int): Immutable. The number of machine replicas used at the start - of the batch operation. If not set, AI Platform decides + of the batch operation. If not set, Vertex AI decides starting number, not greater than [max_replica_count][google.cloud.aiplatform.v1beta1.BatchDedicatedResources.max_replica_count] max_replica_count (int): @@ -193,13 +228,24 @@ class BatchDedicatedResources(proto.Message): The default value is 10. """ - machine_spec = proto.Field(proto.MESSAGE, number=1, message="MachineSpec",) - starting_replica_count = proto.Field(proto.INT32, number=2,) - max_replica_count = proto.Field(proto.INT32, number=3,) + machine_spec = proto.Field( + proto.MESSAGE, + number=1, + message="MachineSpec", + ) + starting_replica_count = proto.Field( + proto.INT32, + number=2, + ) + max_replica_count = proto.Field( + proto.INT32, + number=3, + ) class ResourcesConsumed(proto.Message): r"""Statistics information about resource consumption. + Attributes: replica_hours (float): Output only. The number of replica hours @@ -209,11 +255,15 @@ class ResourcesConsumed(proto.Message): not strictly related to wall time. """ - replica_hours = proto.Field(proto.DOUBLE, number=1,) + replica_hours = proto.Field( + proto.DOUBLE, + number=1, + ) class DiskSpec(proto.Message): r"""Represents the spec of disk options. + Attributes: boot_disk_type (str): Type of the boot disk (default is "pd-ssd"). @@ -225,8 +275,44 @@ class DiskSpec(proto.Message): 100GB). """ - boot_disk_type = proto.Field(proto.STRING, number=1,) - boot_disk_size_gb = proto.Field(proto.INT32, number=2,) + boot_disk_type = proto.Field( + proto.STRING, + number=1, + ) + boot_disk_size_gb = proto.Field( + proto.INT32, + number=2, + ) + + +class NfsMount(proto.Message): + r"""Represents a mount configuration for Network File System + (NFS) to mount. + + Attributes: + server (str): + Required. IP address of the NFS server. + path (str): + Required. Source path exported from NFS server. Has to start + with '/', and combined with the ip address, it indicates the + source mount path in the form of ``server:path`` + mount_point (str): + Required. Destination mount path. The NFS will be mounted + for the user under /mnt/nfs/ + """ + + server = proto.Field( + proto.STRING, + number=1, + ) + path = proto.Field( + proto.STRING, + number=2, + ) + mount_point = proto.Field( + proto.STRING, + number=3, + ) class AutoscalingMetricSpec(proto.Message): @@ -250,8 +336,14 @@ class AutoscalingMetricSpec(proto.Message): provided. """ - metric_name = proto.Field(proto.STRING, number=1,) - target = proto.Field(proto.INT32, number=2,) + metric_name = proto.Field( + proto.STRING, + number=1, + ) + target = proto.Field( + proto.INT32, + number=2, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/manual_batch_tuning_parameters.py b/google/cloud/aiplatform_v1beta1/types/manual_batch_tuning_parameters.py index a26ab13237..13fc2ace35 100644 --- a/google/cloud/aiplatform_v1beta1/types/manual_batch_tuning_parameters.py +++ b/google/cloud/aiplatform_v1beta1/types/manual_batch_tuning_parameters.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,12 +18,15 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1", - manifest={"ManualBatchTuningParameters",}, + manifest={ + "ManualBatchTuningParameters", + }, ) class ManualBatchTuningParameters(proto.Message): r"""Manual batch tuning parameters. + Attributes: batch_size (int): Immutable. The number of the records (e.g. @@ -35,10 +38,13 @@ class ManualBatchTuningParameters(proto.Message): value will result in a whole batch not fitting in a machine's memory, and the whole operation will fail. - The default value is 4. + The default value is 64. """ - batch_size = proto.Field(proto.INT32, number=1,) + batch_size = proto.Field( + proto.INT32, + number=1, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/metadata_schema.py b/google/cloud/aiplatform_v1beta1/types/metadata_schema.py index 41ad5806df..fccef555af 100644 --- a/google/cloud/aiplatform_v1beta1/types/metadata_schema.py +++ b/google/cloud/aiplatform_v1beta1/types/metadata_schema.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,12 +19,16 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"MetadataSchema",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "MetadataSchema", + }, ) class MetadataSchema(proto.Message): r"""Instance of a general MetadataSchema. + Attributes: name (str): Output only. The resource name of the @@ -33,7 +37,8 @@ class MetadataSchema(proto.Message): The version of the MetadataSchema. The version's format must match the following regular expression: ``^[0-9]+[.][0-9]+[.][0-9]+$``, which would allow to - order/compare different versions.Example: 1.0.0, 1.0.1, etc. + order/compare different versions. Example: 1.0.0, 1.0.1, + etc. schema (str): Required. The raw YAML string representation of the MetadataSchema. The combination of [MetadataSchema.version] @@ -61,12 +66,32 @@ class MetadataSchemaType(proto.Enum): EXECUTION_TYPE = 2 CONTEXT_TYPE = 3 - name = proto.Field(proto.STRING, number=1,) - schema_version = proto.Field(proto.STRING, number=2,) - schema = proto.Field(proto.STRING, number=3,) - schema_type = proto.Field(proto.ENUM, number=4, enum=MetadataSchemaType,) - create_time = proto.Field(proto.MESSAGE, number=5, message=timestamp_pb2.Timestamp,) - description = proto.Field(proto.STRING, number=6,) + name = proto.Field( + proto.STRING, + number=1, + ) + schema_version = proto.Field( + proto.STRING, + number=2, + ) + schema = proto.Field( + proto.STRING, + number=3, + ) + schema_type = proto.Field( + proto.ENUM, + number=4, + enum=MetadataSchemaType, + ) + create_time = proto.Field( + proto.MESSAGE, + number=5, + message=timestamp_pb2.Timestamp, + ) + description = proto.Field( + proto.STRING, + number=6, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/metadata_service.py b/google/cloud/aiplatform_v1beta1/types/metadata_service.py index 84b46c1bfd..db995197b6 100644 --- a/google/cloud/aiplatform_v1beta1/types/metadata_service.py +++ b/google/cloud/aiplatform_v1beta1/types/metadata_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -40,12 +40,19 @@ "ListArtifactsRequest", "ListArtifactsResponse", "UpdateArtifactRequest", + "DeleteArtifactRequest", + "PurgeArtifactsRequest", + "PurgeArtifactsResponse", + "PurgeArtifactsMetadata", "CreateContextRequest", "GetContextRequest", "ListContextsRequest", "ListContextsResponse", "UpdateContextRequest", "DeleteContextRequest", + "PurgeContextsRequest", + "PurgeContextsResponse", + "PurgeContextsMetadata", "AddContextArtifactsAndExecutionsRequest", "AddContextArtifactsAndExecutionsResponse", "AddContextChildrenRequest", @@ -56,6 +63,10 @@ "ListExecutionsRequest", "ListExecutionsResponse", "UpdateExecutionRequest", + "DeleteExecutionRequest", + "PurgeExecutionsRequest", + "PurgeExecutionsResponse", + "PurgeExecutionsMetadata", "AddExecutionEventsRequest", "AddExecutionEventsResponse", "QueryExecutionInputsAndOutputsRequest", @@ -74,29 +85,37 @@ class CreateMetadataStoreRequest(proto.Message): Attributes: parent (str): - Required. The resource name of the Location - where the MetadataStore should be created. - Format: projects/{project}/locations/{location}/ + Required. The resource name of the Location where the + MetadataStore should be created. Format: + ``projects/{project}/locations/{location}/`` metadata_store (google.cloud.aiplatform_v1beta1.types.MetadataStore): Required. The MetadataStore to create. metadata_store_id (str): The {metadatastore} portion of the resource name with the format: - projects/{project}/locations/{location}/metadataStores/{metadatastore} + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` If not provided, the MetadataStore's ID will be a UUID generated by the service. Must be 4-128 characters in - length. Valid characters are /[a-z][0-9]-/. Must be unique - across all MetadataStores in the parent Location. (Otherwise - the request will fail with ALREADY_EXISTS, or + length. Valid characters are ``/[a-z][0-9]-/``. Must be + unique across all MetadataStores in the parent Location. + (Otherwise the request will fail with ALREADY_EXISTS, or PERMISSION_DENIED if the caller can't view the preexisting MetadataStore.) """ - parent = proto.Field(proto.STRING, number=1,) + parent = proto.Field( + proto.STRING, + number=1, + ) metadata_store = proto.Field( - proto.MESSAGE, number=2, message=gca_metadata_store.MetadataStore, + proto.MESSAGE, + number=2, + message=gca_metadata_store.MetadataStore, + ) + metadata_store_id = proto.Field( + proto.STRING, + number=3, ) - metadata_store_id = proto.Field(proto.STRING, number=3,) class CreateMetadataStoreOperationMetadata(proto.Message): @@ -110,7 +129,9 @@ class CreateMetadataStoreOperationMetadata(proto.Message): """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, ) @@ -120,12 +141,15 @@ class GetMetadataStoreRequest(proto.Message): Attributes: name (str): - Required. The resource name of the - MetadataStore to retrieve. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore} + Required. The resource name of the MetadataStore to + retrieve. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListMetadataStoresRequest(proto.Message): @@ -134,9 +158,8 @@ class ListMetadataStoresRequest(proto.Message): Attributes: parent (str): - Required. The Location whose MetadataStores - should be listed. Format: - projects/{project}/locations/{location} + Required. The Location whose MetadataStores should be + listed. Format: ``projects/{project}/locations/{location}`` page_size (int): The maximum number of Metadata Stores to return. The service may return fewer. @@ -152,9 +175,18 @@ class ListMetadataStoresRequest(proto.Message): request will fail with INVALID_ARGUMENT error.) """ - parent = proto.Field(proto.STRING, number=1,) - page_size = proto.Field(proto.INT32, number=2,) - page_token = proto.Field(proto.STRING, number=3,) + parent = proto.Field( + proto.STRING, + number=1, + ) + page_size = proto.Field( + proto.INT32, + number=2, + ) + page_token = proto.Field( + proto.STRING, + number=3, + ) class ListMetadataStoresResponse(proto.Message): @@ -176,9 +208,14 @@ def raw_page(self): return self metadata_stores = proto.RepeatedField( - proto.MESSAGE, number=1, message=gca_metadata_store.MetadataStore, + proto.MESSAGE, + number=1, + message=gca_metadata_store.MetadataStore, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class DeleteMetadataStoreRequest(proto.Message): @@ -187,18 +224,21 @@ class DeleteMetadataStoreRequest(proto.Message): Attributes: name (str): - Required. The resource name of the - MetadataStore to delete. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore} + Required. The resource name of the MetadataStore to delete. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` force (bool): - If set to true, any child resources of this MetadataStore - will be deleted. (Otherwise, the request will fail with a - FAILED_PRECONDITION error if the MetadataStore has any child - resources.) + Deprecated: Field is no longer supported. """ - name = proto.Field(proto.STRING, number=1,) - force = proto.Field(proto.BOOL, number=2,) + name = proto.Field( + proto.STRING, + number=1, + ) + force = proto.Field( + proto.BOOL, + number=2, + ) class DeleteMetadataStoreOperationMetadata(proto.Message): @@ -212,7 +252,9 @@ class DeleteMetadataStoreOperationMetadata(proto.Message): """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, ) @@ -222,26 +264,35 @@ class CreateArtifactRequest(proto.Message): Attributes: parent (str): - Required. The resource name of the - MetadataStore where the Artifact should be - created. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore} + Required. The resource name of the MetadataStore where the + Artifact should be created. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` artifact (google.cloud.aiplatform_v1beta1.types.Artifact): Required. The Artifact to create. artifact_id (str): The {artifact} portion of the resource name with the format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact} + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact}`` If not provided, the Artifact's ID will be a UUID generated by the service. Must be 4-128 characters in length. Valid - characters are /[a-z][0-9]-/. Must be unique across all + characters are ``/[a-z][0-9]-/``. Must be unique across all Artifacts in the parent MetadataStore. (Otherwise the request will fail with ALREADY_EXISTS, or PERMISSION_DENIED if the caller can't view the preexisting Artifact.) """ - parent = proto.Field(proto.STRING, number=1,) - artifact = proto.Field(proto.MESSAGE, number=2, message=gca_artifact.Artifact,) - artifact_id = proto.Field(proto.STRING, number=3,) + parent = proto.Field( + proto.STRING, + number=1, + ) + artifact = proto.Field( + proto.MESSAGE, + number=2, + message=gca_artifact.Artifact, + ) + artifact_id = proto.Field( + proto.STRING, + number=3, + ) class GetArtifactRequest(proto.Message): @@ -250,12 +301,15 @@ class GetArtifactRequest(proto.Message): Attributes: name (str): - Required. The resource name of the Artifact - to retrieve. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact} + Required. The resource name of the Artifact to retrieve. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListArtifactsRequest(proto.Message): @@ -264,9 +318,9 @@ class ListArtifactsRequest(proto.Message): Attributes: parent (str): - Required. The MetadataStore whose Artifacts - should be listed. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore} + Required. The MetadataStore whose Artifacts should be + listed. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` page_size (int): The maximum number of Artifacts to return. The service may return fewer. Must be in range @@ -285,32 +339,46 @@ class ListArtifactsRequest(proto.Message): define filter query is based on https://google.aip.dev/160. The supported set of filters include the following: - 1. Attributes filtering e.g. display_name = "test" - - Supported fields include: name, display_name, uri, state, - schema_title, create_time and update_time. Time fields, - i.e. create_time and update_time, require values to - specified in RFC-3339 format. e.g. create_time = - "2020-11-19T11:30:00-04:00" - - 2. Metadata field To filter on metadata fields use traversal - operation as follows: metadata.. - e.g. metadata.field_1.number_value = 10.0 - - 3. Context based filtering To filter Artifacts based on the - contexts to which they belong use the function operator - with the full resource name "in_context()" e.g. - in_context("projects//locations//metadataStores//contexts/") + - **Attribute filtering**: For example: + ``display_name = "test"``. Supported fields include: + ``name``, ``display_name``, ``uri``, ``state``, + ``schema_title``, ``create_time``, and ``update_time``. + Time fields, such as ``create_time`` and ``update_time``, + require values specified in RFC-3339 format. For example: + ``create_time = "2020-11-19T11:30:00-04:00"`` + - **Metadata field**: To filter on metadata fields use + traversal operation as follows: + ``metadata..``. For example: + ``metadata.field_1.number_value = 10.0`` + - **Context based filtering**: To filter Artifacts based on + the contexts to which they belong, use the function + operator with the full resource name + ``in_context()``. For example: + ``in_context("projects//locations//metadataStores//contexts/")`` Each of the above supported filter types can be combined - together using Logical operators (AND & OR). e.g. - display_name = "test" AND metadata.field1.bool_value = true. + together using logical operators (``AND`` & ``OR``). + + For example: + ``display_name = "test" AND metadata.field1.bool_value = true``. """ - parent = proto.Field(proto.STRING, number=1,) - page_size = proto.Field(proto.INT32, number=2,) - page_token = proto.Field(proto.STRING, number=3,) - filter = proto.Field(proto.STRING, number=4,) + parent = proto.Field( + proto.STRING, + number=1, + ) + page_size = proto.Field( + proto.INT32, + number=2, + ) + page_token = proto.Field( + proto.STRING, + number=3, + ) + filter = proto.Field( + proto.STRING, + number=4, + ) class ListArtifactsResponse(proto.Message): @@ -333,9 +401,14 @@ def raw_page(self): return self artifacts = proto.RepeatedField( - proto.MESSAGE, number=1, message=gca_artifact.Artifact, + proto.MESSAGE, + number=1, + message=gca_artifact.Artifact, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class UpdateArtifactRequest(proto.Message): @@ -348,23 +421,131 @@ class UpdateArtifactRequest(proto.Message): [Artifact.name][google.cloud.aiplatform.v1beta1.Artifact.name] field is used to identify the Artifact to be updated. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact} + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact}`` update_mask (google.protobuf.field_mask_pb2.FieldMask): - Required. A FieldMask indicating which fields - should be updated. + Optional. A FieldMask indicating which fields + should be updated. Functionality of this field + is not yet supported. allow_missing (bool): If set to true, and the [Artifact][google.cloud.aiplatform.v1beta1.Artifact] is not found, a new - [Artifact][google.cloud.aiplatform.v1beta1.Artifact] will be - created. In this situation, ``update_mask`` is ignored. + [Artifact][google.cloud.aiplatform.v1beta1.Artifact] is + created. """ - artifact = proto.Field(proto.MESSAGE, number=1, message=gca_artifact.Artifact,) + artifact = proto.Field( + proto.MESSAGE, + number=1, + message=gca_artifact.Artifact, + ) update_mask = proto.Field( - proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) + allow_missing = proto.Field( + proto.BOOL, + number=3, + ) + + +class DeleteArtifactRequest(proto.Message): + r"""Request message for + [MetadataService.DeleteArtifact][google.cloud.aiplatform.v1beta1.MetadataService.DeleteArtifact]. + + Attributes: + name (str): + Required. The resource name of the Artifact to delete. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact}`` + etag (str): + Optional. The etag of the Artifact to delete. If this is + provided, it must match the server's etag. Otherwise, the + request will fail with a FAILED_PRECONDITION. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + etag = proto.Field( + proto.STRING, + number=2, + ) + + +class PurgeArtifactsRequest(proto.Message): + r"""Request message for + [MetadataService.PurgeArtifacts][google.cloud.aiplatform.v1beta1.MetadataService.PurgeArtifacts]. + + Attributes: + parent (str): + Required. The metadata store to purge Artifacts from. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + filter (str): + Required. A required filter matching the Artifacts to be + purged. E.g., ``update_time <= 2020-11-19T11:30:00-04:00``. + force (bool): + Optional. Flag to indicate to actually perform the purge. If + ``force`` is set to false, the method will return a sample + of Artifact names that would be deleted. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + force = proto.Field( + proto.BOOL, + number=3, + ) + + +class PurgeArtifactsResponse(proto.Message): + r"""Response message for + [MetadataService.PurgeArtifacts][google.cloud.aiplatform.v1beta1.MetadataService.PurgeArtifacts]. + + Attributes: + purge_count (int): + The number of Artifacts that this request deleted (or, if + ``force`` is false, the number of Artifacts that will be + deleted). This can be an estimate. + purge_sample (Sequence[str]): + A sample of the Artifact names that will be deleted. Only + populated if ``force`` is set to false. The maximum number + of samples is 100 (it is possible to return fewer). + """ + + purge_count = proto.Field( + proto.INT64, + number=1, + ) + purge_sample = proto.RepeatedField( + proto.STRING, + number=2, + ) + + +class PurgeArtifactsMetadata(proto.Message): + r"""Details of operations that perform + [MetadataService.PurgeArtifacts][google.cloud.aiplatform.v1beta1.MetadataService.PurgeArtifacts]. + + Attributes: + generic_metadata (google.cloud.aiplatform_v1beta1.types.GenericOperationMetadata): + Operation metadata for purging Artifacts. + """ + + generic_metadata = proto.Field( + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, ) - allow_missing = proto.Field(proto.BOOL, number=3,) class CreateContextRequest(proto.Message): @@ -373,26 +554,35 @@ class CreateContextRequest(proto.Message): Attributes: parent (str): - Required. The resource name of the - MetadataStore where the Context should be - created. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore} + Required. The resource name of the MetadataStore where the + Context should be created. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` context (google.cloud.aiplatform_v1beta1.types.Context): Required. The Context to create. context_id (str): The {context} portion of the resource name with the format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context} + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}``. If not provided, the Context's ID will be a UUID generated by the service. Must be 4-128 characters in length. Valid - characters are /[a-z][0-9]-/. Must be unique across all + characters are ``/[a-z][0-9]-/``. Must be unique across all Contexts in the parent MetadataStore. (Otherwise the request will fail with ALREADY_EXISTS, or PERMISSION_DENIED if the caller can't view the preexisting Context.) """ - parent = proto.Field(proto.STRING, number=1,) - context = proto.Field(proto.MESSAGE, number=2, message=gca_context.Context,) - context_id = proto.Field(proto.STRING, number=3,) + parent = proto.Field( + proto.STRING, + number=1, + ) + context = proto.Field( + proto.MESSAGE, + number=2, + message=gca_context.Context, + ) + context_id = proto.Field( + proto.STRING, + number=3, + ) class GetContextRequest(proto.Message): @@ -401,12 +591,15 @@ class GetContextRequest(proto.Message): Attributes: name (str): - Required. The resource name of the Context to - retrieve. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context} + Required. The resource name of the Context to retrieve. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListContextsRequest(proto.Message): @@ -415,9 +608,9 @@ class ListContextsRequest(proto.Message): Attributes: parent (str): - Required. The MetadataStore whose Contexts - should be listed. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore} + Required. The MetadataStore whose Contexts should be listed. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` page_size (int): The maximum number of Contexts to return. The service may return fewer. Must be in range @@ -431,13 +624,58 @@ class ListContextsRequest(proto.Message): the call that provided the page token. (Otherwise the request will fail with INVALID_ARGUMENT error.) filter (str): + Filter specifying the boolean condition for the Contexts to + satisfy in order to be part of the result set. The syntax to + define filter query is based on https://google.aip.dev/160. + Following are the supported set of filters: + + - **Attribute filtering**: For example: + ``display_name = "test"``. Supported fields include: + ``name``, ``display_name``, ``schema_title``, + ``create_time``, and ``update_time``. Time fields, such + as ``create_time`` and ``update_time``, require values + specified in RFC-3339 format. For example: + ``create_time = "2020-11-19T11:30:00-04:00"``. + - **Metadata field**: To filter on metadata fields use + traversal operation as follows: + ``metadata..``. For example: + ``metadata.field_1.number_value = 10.0``. + + - **Parent Child filtering**: To filter Contexts based on + parent-child relationship use the HAS operator as + follows: + + :: + + parent_contexts: + "projects//locations//metadataStores//contexts/" + child_contexts: + "projects//locations//metadataStores//contexts/" + + Each of the above supported filters can be combined together + using logical operators (``AND`` & ``OR``). + + For example: + ``display_name = "test" AND metadata.field1.bool_value = true``. """ - parent = proto.Field(proto.STRING, number=1,) - page_size = proto.Field(proto.INT32, number=2,) - page_token = proto.Field(proto.STRING, number=3,) - filter = proto.Field(proto.STRING, number=4,) + parent = proto.Field( + proto.STRING, + number=1, + ) + page_size = proto.Field( + proto.INT32, + number=2, + ) + page_token = proto.Field( + proto.STRING, + number=3, + ) + filter = proto.Field( + proto.STRING, + number=4, + ) class ListContextsResponse(proto.Message): @@ -460,9 +698,14 @@ def raw_page(self): return self contexts = proto.RepeatedField( - proto.MESSAGE, number=1, message=gca_context.Context, + proto.MESSAGE, + number=1, + message=gca_context.Context, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class UpdateContextRequest(proto.Message): @@ -474,23 +717,33 @@ class UpdateContextRequest(proto.Message): Required. The Context containing updates. The Context's [Context.name][google.cloud.aiplatform.v1beta1.Context.name] field is used to identify the Context to be updated. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context} + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` update_mask (google.protobuf.field_mask_pb2.FieldMask): - Required. A FieldMask indicating which fields - should be updated. + Optional. A FieldMask indicating which fields + should be updated. Functionality of this field + is not yet supported. allow_missing (bool): If set to true, and the [Context][google.cloud.aiplatform.v1beta1.Context] is not found, a new - [Context][google.cloud.aiplatform.v1beta1.Context] will be - created. In this situation, ``update_mask`` is ignored. + [Context][google.cloud.aiplatform.v1beta1.Context] is + created. """ - context = proto.Field(proto.MESSAGE, number=1, message=gca_context.Context,) + context = proto.Field( + proto.MESSAGE, + number=1, + message=gca_context.Context, + ) update_mask = proto.Field( - proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) + allow_missing = proto.Field( + proto.BOOL, + number=3, ) - allow_missing = proto.Field(proto.BOOL, number=3,) class DeleteContextRequest(proto.Message): @@ -499,18 +752,102 @@ class DeleteContextRequest(proto.Message): Attributes: name (str): - Required. The resource name of the Context to - retrieve. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context} + Required. The resource name of the Context to delete. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` force (bool): - If set to true, any child resources of this Context will be - deleted. (Otherwise, the request will fail with a - FAILED_PRECONDITION error if the Context has any child - resources, such as another Context, Artifact, or Execution). + The force deletion semantics is still + undefined. Users should not use this field. + etag (str): + Optional. The etag of the Context to delete. If this is + provided, it must match the server's etag. Otherwise, the + request will fail with a FAILED_PRECONDITION. """ - name = proto.Field(proto.STRING, number=1,) - force = proto.Field(proto.BOOL, number=2,) + name = proto.Field( + proto.STRING, + number=1, + ) + force = proto.Field( + proto.BOOL, + number=2, + ) + etag = proto.Field( + proto.STRING, + number=3, + ) + + +class PurgeContextsRequest(proto.Message): + r"""Request message for + [MetadataService.PurgeContexts][google.cloud.aiplatform.v1beta1.MetadataService.PurgeContexts]. + + Attributes: + parent (str): + Required. The metadata store to purge Contexts from. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + filter (str): + Required. A required filter matching the Contexts to be + purged. E.g., ``update_time <= 2020-11-19T11:30:00-04:00``. + force (bool): + Optional. Flag to indicate to actually perform the purge. If + ``force`` is set to false, the method will return a sample + of Context names that would be deleted. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + force = proto.Field( + proto.BOOL, + number=3, + ) + + +class PurgeContextsResponse(proto.Message): + r"""Response message for + [MetadataService.PurgeContexts][google.cloud.aiplatform.v1beta1.MetadataService.PurgeContexts]. + + Attributes: + purge_count (int): + The number of Contexts that this request deleted (or, if + ``force`` is false, the number of Contexts that will be + deleted). This can be an estimate. + purge_sample (Sequence[str]): + A sample of the Context names that will be deleted. Only + populated if ``force`` is set to false. The maximum number + of samples is 100 (it is possible to return fewer). + """ + + purge_count = proto.Field( + proto.INT64, + number=1, + ) + purge_sample = proto.RepeatedField( + proto.STRING, + number=2, + ) + + +class PurgeContextsMetadata(proto.Message): + r"""Details of operations that perform + [MetadataService.PurgeContexts][google.cloud.aiplatform.v1beta1.MetadataService.PurgeContexts]. + + Attributes: + generic_metadata (google.cloud.aiplatform_v1beta1.types.GenericOperationMetadata): + Operation metadata for purging Contexts. + """ + + generic_metadata = proto.Field( + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, + ) class AddContextArtifactsAndExecutionsRequest(proto.Message): @@ -519,27 +856,42 @@ class AddContextArtifactsAndExecutionsRequest(proto.Message): Attributes: context (str): - Required. The resource name of the Context - that the Artifacts and Executions belong to. - Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context} + Required. The resource name of the Context that the + Artifacts and Executions belong to. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` artifacts (Sequence[str]): - The resource names of the Artifacts to - attribute to the Context. + The resource names of the Artifacts to attribute to the + Context. + + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact}`` executions (Sequence[str]): - The resource names of the Executions to - associate with the Context. + The resource names of the Executions to associate with the + Context. + + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` """ - context = proto.Field(proto.STRING, number=1,) - artifacts = proto.RepeatedField(proto.STRING, number=2,) - executions = proto.RepeatedField(proto.STRING, number=3,) + context = proto.Field( + proto.STRING, + number=1, + ) + artifacts = proto.RepeatedField( + proto.STRING, + number=2, + ) + executions = proto.RepeatedField( + proto.STRING, + number=3, + ) class AddContextArtifactsAndExecutionsResponse(proto.Message): r"""Response message for [MetadataService.AddContextArtifactsAndExecutions][google.cloud.aiplatform.v1beta1.MetadataService.AddContextArtifactsAndExecutions]. - """ + + """ class AddContextChildrenRequest(proto.Message): @@ -548,21 +900,29 @@ class AddContextChildrenRequest(proto.Message): Attributes: context (str): - Required. The resource name of the parent - Context. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context} + Required. The resource name of the parent Context. + + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` child_contexts (Sequence[str]): The resource names of the child Contexts. """ - context = proto.Field(proto.STRING, number=1,) - child_contexts = proto.RepeatedField(proto.STRING, number=2,) + context = proto.Field( + proto.STRING, + number=1, + ) + child_contexts = proto.RepeatedField( + proto.STRING, + number=2, + ) class AddContextChildrenResponse(proto.Message): r"""Response message for [MetadataService.AddContextChildren][google.cloud.aiplatform.v1beta1.MetadataService.AddContextChildren]. - """ + + """ class QueryContextLineageSubgraphRequest(proto.Message): @@ -574,14 +934,17 @@ class QueryContextLineageSubgraphRequest(proto.Message): Required. The resource name of the Context whose Artifacts and Executions should be retrieved as a LineageSubgraph. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context} + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/contexts/{context}`` The request may error with FAILED_PRECONDITION if the number of Artifacts, the number of Executions, or the number of Events that would be returned for the Context exceeds 1000. """ - context = proto.Field(proto.STRING, number=1,) + context = proto.Field( + proto.STRING, + number=1, + ) class CreateExecutionRequest(proto.Message): @@ -590,27 +953,36 @@ class CreateExecutionRequest(proto.Message): Attributes: parent (str): - Required. The resource name of the - MetadataStore where the Execution should be - created. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore} + Required. The resource name of the MetadataStore where the + Execution should be created. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` execution (google.cloud.aiplatform_v1beta1.types.Execution): Required. The Execution to create. execution_id (str): The {execution} portion of the resource name with the format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution} + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` If not provided, the Execution's ID will be a UUID generated by the service. Must be 4-128 characters in length. Valid - characters are /[a-z][0-9]-/. Must be unique across all + characters are ``/[a-z][0-9]-/``. Must be unique across all Executions in the parent MetadataStore. (Otherwise the request will fail with ALREADY_EXISTS, or PERMISSION_DENIED if the caller can't view the preexisting Execution.) """ - parent = proto.Field(proto.STRING, number=1,) - execution = proto.Field(proto.MESSAGE, number=2, message=gca_execution.Execution,) - execution_id = proto.Field(proto.STRING, number=3,) + parent = proto.Field( + proto.STRING, + number=1, + ) + execution = proto.Field( + proto.MESSAGE, + number=2, + message=gca_execution.Execution, + ) + execution_id = proto.Field( + proto.STRING, + number=3, + ) class GetExecutionRequest(proto.Message): @@ -619,12 +991,15 @@ class GetExecutionRequest(proto.Message): Attributes: name (str): - Required. The resource name of the Execution - to retrieve. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution} + Required. The resource name of the Execution to retrieve. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListExecutionsRequest(proto.Message): @@ -633,9 +1008,9 @@ class ListExecutionsRequest(proto.Message): Attributes: parent (str): - Required. The MetadataStore whose Executions - should be listed. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore} + Required. The MetadataStore whose Executions should be + listed. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` page_size (int): The maximum number of Executions to return. The service may return fewer. Must be in range @@ -647,7 +1022,7 @@ class ListExecutionsRequest(proto.Message): When paginating, all other provided parameters must match the call that provided the page token. (Otherwise the - request will fail with INVALID_ARGUMENT error.) + request will fail with an INVALID_ARGUMENT error.) filter (str): Filter specifying the boolean condition for the Executions to satisfy in order to be part of the result set. The syntax @@ -655,32 +1030,44 @@ class ListExecutionsRequest(proto.Message): https://google.aip.dev/160. Following are the supported set of filters: - 1. Attributes filtering e.g. display_name = "test" - - supported fields include: name, display_name, state, - schema_title, create_time and update_time. Time fields, - i.e. create_time and update_time, require values to - specified in RFC-3339 format. e.g. create_time = - "2020-11-19T11:30:00-04:00" - - 2. Metadata field To filter on metadata fields use traversal - operation as follows: metadata.. - e.g. metadata.field_1.number_value = 10.0 - - 3. Context based filtering To filter Executions based on the - contexts to which they belong use the function operator - with the full resource name "in_context()" e.g. - in_context("projects//locations//metadataStores//contexts/") + - **Attribute filtering**: For example: + ``display_name = "test"``. Supported fields include: + ``name``, ``display_name``, ``state``, ``schema_title``, + ``create_time``, and ``update_time``. Time fields, such + as ``create_time`` and ``update_time``, require values + specified in RFC-3339 format. For example: + ``create_time = "2020-11-19T11:30:00-04:00"``. + - **Metadata field**: To filter on metadata fields use + traversal operation as follows: + ``metadata..`` For example: + ``metadata.field_1.number_value = 10.0`` + - **Context based filtering**: To filter Executions based + on the contexts to which they belong use the function + operator with the full resource name: + ``in_context()``. For example: + ``in_context("projects//locations//metadataStores//contexts/")`` Each of the above supported filters can be combined together - using Logical operators (AND & OR). e.g. display_name = - "test" AND metadata.field1.bool_value = true. + using logical operators (``AND`` & ``OR``). For example: + ``display_name = "test" AND metadata.field1.bool_value = true``. """ - parent = proto.Field(proto.STRING, number=1,) - page_size = proto.Field(proto.INT32, number=2,) - page_token = proto.Field(proto.STRING, number=3,) - filter = proto.Field(proto.STRING, number=4,) + parent = proto.Field( + proto.STRING, + number=1, + ) + page_size = proto.Field( + proto.INT32, + number=2, + ) + page_token = proto.Field( + proto.STRING, + number=3, + ) + filter = proto.Field( + proto.STRING, + number=4, + ) class ListExecutionsResponse(proto.Message): @@ -703,9 +1090,14 @@ def raw_page(self): return self executions = proto.RepeatedField( - proto.MESSAGE, number=1, message=gca_execution.Execution, + proto.MESSAGE, + number=1, + message=gca_execution.Execution, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class UpdateExecutionRequest(proto.Message): @@ -718,23 +1110,131 @@ class UpdateExecutionRequest(proto.Message): [Execution.name][google.cloud.aiplatform.v1beta1.Execution.name] field is used to identify the Execution to be updated. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution} + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` update_mask (google.protobuf.field_mask_pb2.FieldMask): - Required. A FieldMask indicating which fields - should be updated. + Optional. A FieldMask indicating which fields + should be updated. Functionality of this field + is not yet supported. allow_missing (bool): If set to true, and the [Execution][google.cloud.aiplatform.v1beta1.Execution] is not found, a new - [Execution][google.cloud.aiplatform.v1beta1.Execution] will - be created. In this situation, ``update_mask`` is ignored. + [Execution][google.cloud.aiplatform.v1beta1.Execution] is + created. """ - execution = proto.Field(proto.MESSAGE, number=1, message=gca_execution.Execution,) + execution = proto.Field( + proto.MESSAGE, + number=1, + message=gca_execution.Execution, + ) update_mask = proto.Field( - proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) + allow_missing = proto.Field( + proto.BOOL, + number=3, + ) + + +class DeleteExecutionRequest(proto.Message): + r"""Request message for + [MetadataService.DeleteExecution][google.cloud.aiplatform.v1beta1.MetadataService.DeleteExecution]. + + Attributes: + name (str): + Required. The resource name of the Execution to delete. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` + etag (str): + Optional. The etag of the Execution to delete. If this is + provided, it must match the server's etag. Otherwise, the + request will fail with a FAILED_PRECONDITION. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + etag = proto.Field( + proto.STRING, + number=2, + ) + + +class PurgeExecutionsRequest(proto.Message): + r"""Request message for + [MetadataService.PurgeExecutions][google.cloud.aiplatform.v1beta1.MetadataService.PurgeExecutions]. + + Attributes: + parent (str): + Required. The metadata store to purge Executions from. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` + filter (str): + Required. A required filter matching the Executions to be + purged. E.g., ``update_time <= 2020-11-19T11:30:00-04:00``. + force (bool): + Optional. Flag to indicate to actually perform the purge. If + ``force`` is set to false, the method will return a sample + of Execution names that would be deleted. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + force = proto.Field( + proto.BOOL, + number=3, + ) + + +class PurgeExecutionsResponse(proto.Message): + r"""Response message for + [MetadataService.PurgeExecutions][google.cloud.aiplatform.v1beta1.MetadataService.PurgeExecutions]. + + Attributes: + purge_count (int): + The number of Executions that this request deleted (or, if + ``force`` is false, the number of Executions that will be + deleted). This can be an estimate. + purge_sample (Sequence[str]): + A sample of the Execution names that will be deleted. Only + populated if ``force`` is set to false. The maximum number + of samples is 100 (it is possible to return fewer). + """ + + purge_count = proto.Field( + proto.INT64, + number=1, + ) + purge_sample = proto.RepeatedField( + proto.STRING, + number=2, + ) + + +class PurgeExecutionsMetadata(proto.Message): + r"""Details of operations that perform + [MetadataService.PurgeExecutions][google.cloud.aiplatform.v1beta1.MetadataService.PurgeExecutions]. + + Attributes: + generic_metadata (google.cloud.aiplatform_v1beta1.types.GenericOperationMetadata): + Operation metadata for purging Executions. + """ + + generic_metadata = proto.Field( + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, ) - allow_missing = proto.Field(proto.BOOL, number=3,) class AddExecutionEventsRequest(proto.Message): @@ -743,22 +1243,29 @@ class AddExecutionEventsRequest(proto.Message): Attributes: execution (str): - Required. The resource name of the Execution - that the Events connect Artifacts with. - Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution} + Required. The resource name of the Execution that the Events + connect Artifacts with. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` events (Sequence[google.cloud.aiplatform_v1beta1.types.Event]): The Events to create and add. """ - execution = proto.Field(proto.STRING, number=1,) - events = proto.RepeatedField(proto.MESSAGE, number=2, message=event.Event,) + execution = proto.Field( + proto.STRING, + number=1, + ) + events = proto.RepeatedField( + proto.MESSAGE, + number=2, + message=event.Event, + ) class AddExecutionEventsResponse(proto.Message): r"""Response message for [MetadataService.AddExecutionEvents][google.cloud.aiplatform.v1beta1.MetadataService.AddExecutionEvents]. - """ + + """ class QueryExecutionInputsAndOutputsRequest(proto.Message): @@ -767,13 +1274,16 @@ class QueryExecutionInputsAndOutputsRequest(proto.Message): Attributes: execution (str): - Required. The resource name of the Execution - whose input and output Artifacts should be - retrieved as a LineageSubgraph. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution} + Required. The resource name of the Execution whose input and + output Artifacts should be retrieved as a LineageSubgraph. + Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/executions/{execution}`` """ - execution = proto.Field(proto.STRING, number=1,) + execution = proto.Field( + proto.STRING, + number=1, + ) class CreateMetadataSchemaRequest(proto.Message): @@ -782,30 +1292,37 @@ class CreateMetadataSchemaRequest(proto.Message): Attributes: parent (str): - Required. The resource name of the - MetadataStore where the MetadataSchema should be - created. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore} + Required. The resource name of the MetadataStore where the + MetadataSchema should be created. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` metadata_schema (google.cloud.aiplatform_v1beta1.types.MetadataSchema): Required. The MetadataSchema to create. metadata_schema_id (str): The {metadata_schema} portion of the resource name with the format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/metadataSchemas/{metadataschema} + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/metadataSchemas/{metadataschema}`` If not provided, the MetadataStore's ID will be a UUID generated by the service. Must be 4-128 characters in - length. Valid characters are /[a-z][0-9]-/. Must be unique - across all MetadataSchemas in the parent Location. + length. Valid characters are ``/[a-z][0-9]-/``. Must be + unique across all MetadataSchemas in the parent Location. (Otherwise the request will fail with ALREADY_EXISTS, or PERMISSION_DENIED if the caller can't view the preexisting MetadataSchema.) """ - parent = proto.Field(proto.STRING, number=1,) + parent = proto.Field( + proto.STRING, + number=1, + ) metadata_schema = proto.Field( - proto.MESSAGE, number=2, message=gca_metadata_schema.MetadataSchema, + proto.MESSAGE, + number=2, + message=gca_metadata_schema.MetadataSchema, + ) + metadata_schema_id = proto.Field( + proto.STRING, + number=3, ) - metadata_schema_id = proto.Field(proto.STRING, number=3,) class GetMetadataSchemaRequest(proto.Message): @@ -814,12 +1331,15 @@ class GetMetadataSchemaRequest(proto.Message): Attributes: name (str): - Required. The resource name of the - MetadataSchema to retrieve. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/metadataSchemas/{metadataschema} + Required. The resource name of the MetadataSchema to + retrieve. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/metadataSchemas/{metadataschema}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListMetadataSchemasRequest(proto.Message): @@ -828,9 +1348,9 @@ class ListMetadataSchemasRequest(proto.Message): Attributes: parent (str): - Required. The MetadataStore whose - MetadataSchemas should be listed. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore} + Required. The MetadataStore whose MetadataSchemas should be + listed. Format: + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}`` page_size (int): The maximum number of MetadataSchemas to return. The service may return fewer. @@ -839,7 +1359,7 @@ class ListMetadataSchemasRequest(proto.Message): page_token (str): A page token, received from a previous [MetadataService.ListMetadataSchemas][google.cloud.aiplatform.v1beta1.MetadataService.ListMetadataSchemas] - call. Provide this to retrieve the subsequent page. + call. Provide this to retrieve the next page. When paginating, all other provided parameters must match the call that provided the page token. (Otherwise the @@ -849,10 +1369,22 @@ class ListMetadataSchemasRequest(proto.Message): for matching results. """ - parent = proto.Field(proto.STRING, number=1,) - page_size = proto.Field(proto.INT32, number=2,) - page_token = proto.Field(proto.STRING, number=3,) - filter = proto.Field(proto.STRING, number=4,) + parent = proto.Field( + proto.STRING, + number=1, + ) + page_size = proto.Field( + proto.INT32, + number=2, + ) + page_token = proto.Field( + proto.STRING, + number=3, + ) + filter = proto.Field( + proto.STRING, + number=4, + ) class ListMetadataSchemasResponse(proto.Message): @@ -875,9 +1407,14 @@ def raw_page(self): return self metadata_schemas = proto.RepeatedField( - proto.MESSAGE, number=1, message=gca_metadata_schema.MetadataSchema, + proto.MESSAGE, + number=1, + message=gca_metadata_schema.MetadataSchema, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class QueryArtifactLineageSubgraphRequest(proto.Message): @@ -888,7 +1425,7 @@ class QueryArtifactLineageSubgraphRequest(proto.Message): artifact (str): Required. The resource name of the Artifact whose Lineage needs to be retrieved as a LineageSubgraph. Format: - projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact} + ``projects/{project}/locations/{location}/metadataStores/{metadatastore}/artifacts/{artifact}`` The request may error with FAILED_PRECONDITION if the number of Artifacts, the number of Executions, or the number of @@ -906,26 +1443,37 @@ class QueryArtifactLineageSubgraphRequest(proto.Message): https://google.aip.dev/160. The supported set of filters include the following: - 1. Attributes filtering e.g. display_name = "test" - - supported fields include: name, display_name, uri, state, - schema_title, create_time and update_time. Time fields, - i.e. create_time and update_time, require values to - specified in RFC-3339 format. e.g. create_time = - "2020-11-19T11:30:00-04:00" - - 2. Metadata field To filter on metadata fields use traversal - operation as follows: metadata.. - e.g. metadata.field_1.number_value = 10.0 + - **Attribute filtering**: For example: + ``display_name = "test"`` Supported fields include: + ``name``, ``display_name``, ``uri``, ``state``, + ``schema_title``, ``create_time``, and ``update_time``. + Time fields, such as ``create_time`` and ``update_time``, + require values specified in RFC-3339 format. For example: + ``create_time = "2020-11-19T11:30:00-04:00"`` + - **Metadata field**: To filter on metadata fields use + traversal operation as follows: + ``metadata..``. For example: + ``metadata.field_1.number_value = 10.0`` Each of the above supported filter types can be combined - together using Logical operators (AND & OR). e.g. - display_name = "test" AND metadata.field1.bool_value = true. + together using logical operators (``AND`` & ``OR``). + + For example: + ``display_name = "test" AND metadata.field1.bool_value = true``. """ - artifact = proto.Field(proto.STRING, number=1,) - max_hops = proto.Field(proto.INT32, number=2,) - filter = proto.Field(proto.STRING, number=3,) + artifact = proto.Field( + proto.STRING, + number=1, + ) + max_hops = proto.Field( + proto.INT32, + number=2, + ) + filter = proto.Field( + proto.STRING, + number=3, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/metadata_store.py b/google/cloud/aiplatform_v1beta1/types/metadata_store.py index ac39fde5f0..bdd419a6cf 100644 --- a/google/cloud/aiplatform_v1beta1/types/metadata_store.py +++ b/google/cloud/aiplatform_v1beta1/types/metadata_store.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,7 +20,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"MetadataStore",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "MetadataStore", + }, ) @@ -39,10 +42,10 @@ class MetadataStore(proto.Message): Output only. Timestamp when this MetadataStore was last updated. encryption_spec (google.cloud.aiplatform_v1beta1.types.EncryptionSpec): - Customer-managed encryption key spec for an + Customer-managed encryption key spec for a Metadata Store. If set, this Metadata Store and - all sub-resources of this Metadata Store will be - secured by this key. + all sub-resources of this Metadata Store are + secured using this key. description (str): Description of the MetadataStore. state (google.cloud.aiplatform_v1beta1.types.MetadataStore.MetadataStoreState): @@ -51,23 +54,47 @@ class MetadataStore(proto.Message): """ class MetadataStoreState(proto.Message): - r"""Represent state information for a MetadataStore. + r"""Represents state information for a MetadataStore. + Attributes: disk_utilization_bytes (int): The disk utilization of the MetadataStore in bytes. """ - disk_utilization_bytes = proto.Field(proto.INT64, number=1,) + disk_utilization_bytes = proto.Field( + proto.INT64, + number=1, + ) - name = proto.Field(proto.STRING, number=1,) - create_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) - update_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) + name = proto.Field( + proto.STRING, + number=1, + ) + create_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) encryption_spec = proto.Field( - proto.MESSAGE, number=5, message=gca_encryption_spec.EncryptionSpec, + proto.MESSAGE, + number=5, + message=gca_encryption_spec.EncryptionSpec, + ) + description = proto.Field( + proto.STRING, + number=6, + ) + state = proto.Field( + proto.MESSAGE, + number=7, + message=MetadataStoreState, ) - description = proto.Field(proto.STRING, number=6,) - state = proto.Field(proto.MESSAGE, number=7, message=MetadataStoreState,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/migratable_resource.py b/google/cloud/aiplatform_v1beta1/types/migratable_resource.py index 4a35c5f8d0..ab535c9a9e 100644 --- a/google/cloud/aiplatform_v1beta1/types/migratable_resource.py +++ b/google/cloud/aiplatform_v1beta1/types/migratable_resource.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,7 +19,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"MigratableResource",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "MigratableResource", + }, ) @@ -27,19 +30,34 @@ class MigratableResource(proto.Message): r"""Represents one resource that exists in automl.googleapis.com, datalabeling.googleapis.com or ml.googleapis.com. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: ml_engine_model_version (google.cloud.aiplatform_v1beta1.types.MigratableResource.MlEngineModelVersion): Output only. Represents one Version in ml.googleapis.com. + + This field is a member of `oneof`_ ``resource``. automl_model (google.cloud.aiplatform_v1beta1.types.MigratableResource.AutomlModel): Output only. Represents one Model in automl.googleapis.com. + + This field is a member of `oneof`_ ``resource``. automl_dataset (google.cloud.aiplatform_v1beta1.types.MigratableResource.AutomlDataset): Output only. Represents one Dataset in automl.googleapis.com. + + This field is a member of `oneof`_ ``resource``. data_labeling_dataset (google.cloud.aiplatform_v1beta1.types.MigratableResource.DataLabelingDataset): Output only. Represents one Dataset in datalabeling.googleapis.com. + + This field is a member of `oneof`_ ``resource``. last_migrate_time (google.protobuf.timestamp_pb2.Timestamp): Output only. Timestamp when the last migration attempt on this MigratableResource @@ -52,6 +70,7 @@ class MigratableResource(proto.Message): class MlEngineModelVersion(proto.Message): r"""Represents one model Version in ml.googleapis.com. + Attributes: endpoint (str): The ml.googleapis.com endpoint that this model Version @@ -66,11 +85,18 @@ class MlEngineModelVersion(proto.Message): ``projects/{project}/models/{model}/versions/{version}``. """ - endpoint = proto.Field(proto.STRING, number=1,) - version = proto.Field(proto.STRING, number=2,) + endpoint = proto.Field( + proto.STRING, + number=1, + ) + version = proto.Field( + proto.STRING, + number=2, + ) class AutomlModel(proto.Message): r"""Represents one Model in automl.googleapis.com. + Attributes: model (str): Full resource name of automl Model. Format: @@ -80,11 +106,18 @@ class AutomlModel(proto.Message): automl.googleapis.com. """ - model = proto.Field(proto.STRING, number=1,) - model_display_name = proto.Field(proto.STRING, number=3,) + model = proto.Field( + proto.STRING, + number=1, + ) + model_display_name = proto.Field( + proto.STRING, + number=3, + ) class AutomlDataset(proto.Message): r"""Represents one Dataset in automl.googleapis.com. + Attributes: dataset (str): Full resource name of automl Dataset. Format: @@ -94,11 +127,18 @@ class AutomlDataset(proto.Message): automl.googleapis.com. """ - dataset = proto.Field(proto.STRING, number=1,) - dataset_display_name = proto.Field(proto.STRING, number=4,) + dataset = proto.Field( + proto.STRING, + number=1, + ) + dataset_display_name = proto.Field( + proto.STRING, + number=4, + ) class DataLabelingDataset(proto.Message): r"""Represents one Dataset in datalabeling.googleapis.com. + Attributes: dataset (str): Full resource name of data labeling Dataset. Format: @@ -126,11 +166,23 @@ class DataLabelingAnnotatedDataset(proto.Message): datalabeling.googleapis.com. """ - annotated_dataset = proto.Field(proto.STRING, number=1,) - annotated_dataset_display_name = proto.Field(proto.STRING, number=3,) - - dataset = proto.Field(proto.STRING, number=1,) - dataset_display_name = proto.Field(proto.STRING, number=4,) + annotated_dataset = proto.Field( + proto.STRING, + number=1, + ) + annotated_dataset_display_name = proto.Field( + proto.STRING, + number=3, + ) + + dataset = proto.Field( + proto.STRING, + number=1, + ) + dataset_display_name = proto.Field( + proto.STRING, + number=4, + ) data_labeling_annotated_datasets = proto.RepeatedField( proto.MESSAGE, number=3, @@ -138,22 +190,38 @@ class DataLabelingAnnotatedDataset(proto.Message): ) ml_engine_model_version = proto.Field( - proto.MESSAGE, number=1, oneof="resource", message=MlEngineModelVersion, + proto.MESSAGE, + number=1, + oneof="resource", + message=MlEngineModelVersion, ) automl_model = proto.Field( - proto.MESSAGE, number=2, oneof="resource", message=AutomlModel, + proto.MESSAGE, + number=2, + oneof="resource", + message=AutomlModel, ) automl_dataset = proto.Field( - proto.MESSAGE, number=3, oneof="resource", message=AutomlDataset, + proto.MESSAGE, + number=3, + oneof="resource", + message=AutomlDataset, ) data_labeling_dataset = proto.Field( - proto.MESSAGE, number=4, oneof="resource", message=DataLabelingDataset, + proto.MESSAGE, + number=4, + oneof="resource", + message=DataLabelingDataset, ) last_migrate_time = proto.Field( - proto.MESSAGE, number=5, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=5, + message=timestamp_pb2.Timestamp, ) last_update_time = proto.Field( - proto.MESSAGE, number=6, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=6, + message=timestamp_pb2.Timestamp, ) diff --git a/google/cloud/aiplatform_v1beta1/types/migration_service.py b/google/cloud/aiplatform_v1beta1/types/migration_service.py index 1bc2d2432a..6f1e492dc3 100644 --- a/google/cloud/aiplatform_v1beta1/types/migration_service.py +++ b/google/cloud/aiplatform_v1beta1/types/migration_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -43,7 +43,7 @@ class SearchMigratableResourcesRequest(proto.Message): Attributes: parent (str): Required. The location that the migratable resources should - be searched from. It's the AI Platform location that the + be searched from. It's the Vertex AI location that the resources can be migrated to, not the resources' original location. Format: ``projects/{project}/locations/{location}`` @@ -75,10 +75,22 @@ class SearchMigratableResourcesRequest(proto.Message): migrated resources. """ - parent = proto.Field(proto.STRING, number=1,) - page_size = proto.Field(proto.INT32, number=2,) - page_token = proto.Field(proto.STRING, number=3,) - filter = proto.Field(proto.STRING, number=4,) + parent = proto.Field( + proto.STRING, + number=1, + ) + page_size = proto.Field( + proto.INT32, + number=2, + ) + page_token = proto.Field( + proto.STRING, + number=3, + ) + filter = proto.Field( + proto.STRING, + number=4, + ) class SearchMigratableResourcesResponse(proto.Message): @@ -100,9 +112,14 @@ def raw_page(self): return self migratable_resources = proto.RepeatedField( - proto.MESSAGE, number=1, message=gca_migratable_resource.MigratableResource, + proto.MESSAGE, + number=1, + message=gca_migratable_resource.MigratableResource, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class BatchMigrateResourcesRequest(proto.Message): @@ -120,36 +137,55 @@ class BatchMigrateResourcesRequest(proto.Message): can be migrated in one batch. """ - parent = proto.Field(proto.STRING, number=1,) + parent = proto.Field( + proto.STRING, + number=1, + ) migrate_resource_requests = proto.RepeatedField( - proto.MESSAGE, number=2, message="MigrateResourceRequest", + proto.MESSAGE, + number=2, + message="MigrateResourceRequest", ) class MigrateResourceRequest(proto.Message): r"""Config of migrating one resource from automl.googleapis.com, - datalabeling.googleapis.com and ml.googleapis.com to AI - Platform. + datalabeling.googleapis.com and ml.googleapis.com to Vertex AI. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields Attributes: migrate_ml_engine_model_version_config (google.cloud.aiplatform_v1beta1.types.MigrateResourceRequest.MigrateMlEngineModelVersionConfig): Config for migrating Version in - ml.googleapis.com to AI Platform's Model. + ml.googleapis.com to Vertex AI's Model. + + This field is a member of `oneof`_ ``request``. migrate_automl_model_config (google.cloud.aiplatform_v1beta1.types.MigrateResourceRequest.MigrateAutomlModelConfig): Config for migrating Model in - automl.googleapis.com to AI Platform's Model. + automl.googleapis.com to Vertex AI's Model. + + This field is a member of `oneof`_ ``request``. migrate_automl_dataset_config (google.cloud.aiplatform_v1beta1.types.MigrateResourceRequest.MigrateAutomlDatasetConfig): Config for migrating Dataset in - automl.googleapis.com to AI Platform's Dataset. + automl.googleapis.com to Vertex AI's Dataset. + + This field is a member of `oneof`_ ``request``. migrate_data_labeling_dataset_config (google.cloud.aiplatform_v1beta1.types.MigrateResourceRequest.MigrateDataLabelingDatasetConfig): Config for migrating Dataset in - datalabeling.googleapis.com to AI Platform's + datalabeling.googleapis.com to Vertex AI's Dataset. + + This field is a member of `oneof`_ ``request``. """ class MigrateMlEngineModelVersionConfig(proto.Message): - r"""Config for migrating version in ml.googleapis.com to AI - Platform's Model. + r"""Config for migrating version in ml.googleapis.com to Vertex + AI's Model. Attributes: endpoint (str): @@ -168,72 +204,93 @@ class MigrateMlEngineModelVersionConfig(proto.Message): Format: ``projects/{project}/models/{model}/versions/{version}``. model_display_name (str): - Required. Display name of the model in AI - Platform. System will pick a display name if + Required. Display name of the model in Vertex + AI. System will pick a display name if unspecified. """ - endpoint = proto.Field(proto.STRING, number=1,) - model_version = proto.Field(proto.STRING, number=2,) - model_display_name = proto.Field(proto.STRING, number=3,) + endpoint = proto.Field( + proto.STRING, + number=1, + ) + model_version = proto.Field( + proto.STRING, + number=2, + ) + model_display_name = proto.Field( + proto.STRING, + number=3, + ) class MigrateAutomlModelConfig(proto.Message): - r"""Config for migrating Model in automl.googleapis.com to AI - Platform's Model. + r"""Config for migrating Model in automl.googleapis.com to Vertex + AI's Model. Attributes: model (str): Required. Full resource name of automl Model. Format: ``projects/{project}/locations/{location}/models/{model}``. model_display_name (str): - Optional. Display name of the model in AI - Platform. System will pick a display name if + Optional. Display name of the model in Vertex + AI. System will pick a display name if unspecified. """ - model = proto.Field(proto.STRING, number=1,) - model_display_name = proto.Field(proto.STRING, number=2,) + model = proto.Field( + proto.STRING, + number=1, + ) + model_display_name = proto.Field( + proto.STRING, + number=2, + ) class MigrateAutomlDatasetConfig(proto.Message): - r"""Config for migrating Dataset in automl.googleapis.com to AI - Platform's Dataset. + r"""Config for migrating Dataset in automl.googleapis.com to + Vertex AI's Dataset. Attributes: dataset (str): Required. Full resource name of automl Dataset. Format: ``projects/{project}/locations/{location}/datasets/{dataset}``. dataset_display_name (str): - Required. Display name of the Dataset in AI - Platform. System will pick a display name if + Required. Display name of the Dataset in + Vertex AI. System will pick a display name if unspecified. """ - dataset = proto.Field(proto.STRING, number=1,) - dataset_display_name = proto.Field(proto.STRING, number=2,) + dataset = proto.Field( + proto.STRING, + number=1, + ) + dataset_display_name = proto.Field( + proto.STRING, + number=2, + ) class MigrateDataLabelingDatasetConfig(proto.Message): r"""Config for migrating Dataset in datalabeling.googleapis.com - to AI Platform's Dataset. + to Vertex AI's Dataset. Attributes: dataset (str): Required. Full resource name of data labeling Dataset. Format: ``projects/{project}/datasets/{dataset}``. dataset_display_name (str): - Optional. Display name of the Dataset in AI - Platform. System will pick a display name if + Optional. Display name of the Dataset in + Vertex AI. System will pick a display name if unspecified. migrate_data_labeling_annotated_dataset_configs (Sequence[google.cloud.aiplatform_v1beta1.types.MigrateResourceRequest.MigrateDataLabelingDatasetConfig.MigrateDataLabelingAnnotatedDatasetConfig]): Optional. Configs for migrating AnnotatedDataset in datalabeling.googleapis.com - to AI Platform's SavedQuery. The specified + to Vertex AI's SavedQuery. The specified AnnotatedDatasets have to belong to the datalabeling Dataset. """ class MigrateDataLabelingAnnotatedDatasetConfig(proto.Message): r"""Config for migrating AnnotatedDataset in - datalabeling.googleapis.com to AI Platform's SavedQuery. + datalabeling.googleapis.com to Vertex AI's SavedQuery. Attributes: annotated_dataset (str): @@ -242,10 +299,19 @@ class MigrateDataLabelingAnnotatedDatasetConfig(proto.Message): ``projects/{project}/datasets/{dataset}/annotatedDatasets/{annotated_dataset}``. """ - annotated_dataset = proto.Field(proto.STRING, number=1,) + annotated_dataset = proto.Field( + proto.STRING, + number=1, + ) - dataset = proto.Field(proto.STRING, number=1,) - dataset_display_name = proto.Field(proto.STRING, number=2,) + dataset = proto.Field( + proto.STRING, + number=1, + ) + dataset_display_name = proto.Field( + proto.STRING, + number=2, + ) migrate_data_labeling_annotated_dataset_configs = proto.RepeatedField( proto.MESSAGE, number=3, @@ -259,10 +325,16 @@ class MigrateDataLabelingAnnotatedDatasetConfig(proto.Message): message=MigrateMlEngineModelVersionConfig, ) migrate_automl_model_config = proto.Field( - proto.MESSAGE, number=2, oneof="request", message=MigrateAutomlModelConfig, + proto.MESSAGE, + number=2, + oneof="request", + message=MigrateAutomlModelConfig, ) migrate_automl_dataset_config = proto.Field( - proto.MESSAGE, number=3, oneof="request", message=MigrateAutomlDatasetConfig, + proto.MESSAGE, + number=3, + oneof="request", + message=MigrateAutomlDatasetConfig, ) migrate_data_labeling_dataset_config = proto.Field( proto.MESSAGE, @@ -282,27 +354,51 @@ class BatchMigrateResourcesResponse(proto.Message): """ migrate_resource_responses = proto.RepeatedField( - proto.MESSAGE, number=1, message="MigrateResourceResponse", + proto.MESSAGE, + number=1, + message="MigrateResourceResponse", ) class MigrateResourceResponse(proto.Message): r"""Describes a successfully migrated resource. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: dataset (str): Migrated Dataset's resource name. + + This field is a member of `oneof`_ ``migrated_resource``. model (str): Migrated Model's resource name. + + This field is a member of `oneof`_ ``migrated_resource``. migratable_resource (google.cloud.aiplatform_v1beta1.types.MigratableResource): Before migration, the identifier in ml.googleapis.com, automl.googleapis.com or datalabeling.googleapis.com. """ - dataset = proto.Field(proto.STRING, number=1, oneof="migrated_resource",) - model = proto.Field(proto.STRING, number=2, oneof="migrated_resource",) + dataset = proto.Field( + proto.STRING, + number=1, + oneof="migrated_resource", + ) + model = proto.Field( + proto.STRING, + number=2, + oneof="migrated_resource", + ) migratable_resource = proto.Field( - proto.MESSAGE, number=3, message=gca_migratable_resource.MigratableResource, + proto.MESSAGE, + number=3, + message=gca_migratable_resource.MigratableResource, ) @@ -322,33 +418,63 @@ class PartialResult(proto.Message): r"""Represents a partial result in batch migration operation for one [MigrateResourceRequest][google.cloud.aiplatform.v1beta1.MigrateResourceRequest]. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: error (google.rpc.status_pb2.Status): The error result of the migration request in case of failure. + + This field is a member of `oneof`_ ``result``. model (str): Migrated model resource name. + + This field is a member of `oneof`_ ``result``. dataset (str): Migrated dataset resource name. + + This field is a member of `oneof`_ ``result``. request (google.cloud.aiplatform_v1beta1.types.MigrateResourceRequest): It's the same as the value in [MigrateResourceRequest.migrate_resource_requests][]. """ error = proto.Field( - proto.MESSAGE, number=2, oneof="result", message=status_pb2.Status, + proto.MESSAGE, + number=2, + oneof="result", + message=status_pb2.Status, + ) + model = proto.Field( + proto.STRING, + number=3, + oneof="result", + ) + dataset = proto.Field( + proto.STRING, + number=4, + oneof="result", ) - model = proto.Field(proto.STRING, number=3, oneof="result",) - dataset = proto.Field(proto.STRING, number=4, oneof="result",) request = proto.Field( - proto.MESSAGE, number=1, message="MigrateResourceRequest", + proto.MESSAGE, + number=1, + message="MigrateResourceRequest", ) generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, ) partial_results = proto.RepeatedField( - proto.MESSAGE, number=2, message=PartialResult, + proto.MESSAGE, + number=2, + message=PartialResult, ) diff --git a/google/cloud/aiplatform_v1beta1/types/model.py b/google/cloud/aiplatform_v1beta1/types/model.py index 2363d22fe3..d315d2952e 100644 --- a/google/cloud/aiplatform_v1beta1/types/model.py +++ b/google/cloud/aiplatform_v1beta1/types/model.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -25,21 +25,51 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1", - manifest={"Model", "PredictSchemata", "ModelContainerSpec", "Port",}, + manifest={ + "Model", + "PredictSchemata", + "ModelContainerSpec", + "Port", + }, ) class Model(proto.Message): r"""A trained machine learning Model. + Attributes: name (str): The resource name of the Model. + version_id (str): + Output only. Immutable. The version ID of the + model. A new version is committed when a new + model version is uploaded or trained under an + existing model id. It is an auto-incrementing + decimal number in string representation. + version_aliases (Sequence[str]): + User provided version aliases so that a model version can be + referenced via alias (i.e. + projects/{project}/locations/{location}/models/{model_id}@{version_alias} + instead of auto-generated version id (i.e. + projects/{project}/locations/{location}/models/{model_id}@{version_id}). + The format is [a-z][a-zA-Z0-9-]{0,126}[a-z0-9] to + distinguish from version_id. A default version alias will be + created for the first version of the model, and there must + be exactly one default version alias for a model. + version_create_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp when this version was + created. + version_update_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Timestamp when this version was + most recently updated. display_name (str): Required. The display name of the Model. The name can be up to 128 characters long and can be consist of any UTF-8 characters. description (str): The description of the Model. + version_description (str): + The description of this version. predict_schemata (google.cloud.aiplatform_v1beta1.types.PredictSchemata): The schemata that describe formats of the Model's predictions and explanations as given and returned via @@ -52,13 +82,13 @@ class Model(proto.Message): that is specific to it. Unset if the Model does not have any additional information. The schema is defined as an OpenAPI 3.0.2 `Schema - Object `__. - AutoML Models always have this field populated by AI - Platform, if no additional metadata is needed, this field is - set to an empty string. Note: The URI given on output will - be immutable and probably different, including the URI - scheme, than the one given on input. The output URI will - point to a location where the user only has a read access. + Object `__. + AutoML Models always have this field populated by Vertex AI, + if no additional metadata is needed, this field is set to an + empty string. Note: The URI given on output will be + immutable and probably different, including the URI scheme, + than the one given on input. The output URI will point to a + location where the user only has a read access. metadata (google.protobuf.struct_pb2.Value): Immutable. An additional information about the Model; the schema of the metadata can be found in @@ -78,7 +108,7 @@ class Model(proto.Message): ingested upon [ModelService.UploadModel][google.cloud.aiplatform.v1beta1.ModelService.UploadModel], and all binaries it contains are copied and stored - internally by AI Platform. Not present for AutoML Models. + internally by Vertex AI. Not present for AutoML Models. artifact_uri (str): Immutable. The path to the directory containing the Model artifact and any of its @@ -186,7 +216,7 @@ class Model(proto.Message): [PredictionService.Explain][google.cloud.aiplatform.v1beta1.PredictionService.Explain]. create_time (google.protobuf.timestamp_pb2.Timestamp): Output only. Timestamp when this Model was - uploaded into AI Platform. + uploaded into Vertex AI. update_time (google.protobuf.timestamp_pb2.Timestamp): Output only. Timestamp when this Model was most recently updated. @@ -230,7 +260,7 @@ class Model(proto.Message): Used to perform consistent read-modify-write updates. If not set, a blind "overwrite" update happens. - labels (Sequence[google.cloud.aiplatform_v1beta1.types.Model.LabelsEntry]): + labels (Mapping[str, str]): The labels with user-defined metadata to organize your Models. Label keys and values can be no longer than 64 @@ -289,44 +319,128 @@ class ExportableContent(proto.Enum): ARTIFACT = 1 IMAGE = 2 - id = proto.Field(proto.STRING, number=1,) + id = proto.Field( + proto.STRING, + number=1, + ) exportable_contents = proto.RepeatedField( - proto.ENUM, number=2, enum="Model.ExportFormat.ExportableContent", + proto.ENUM, + number=2, + enum="Model.ExportFormat.ExportableContent", ) - name = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) - description = proto.Field(proto.STRING, number=3,) - predict_schemata = proto.Field(proto.MESSAGE, number=4, message="PredictSchemata",) - metadata_schema_uri = proto.Field(proto.STRING, number=5,) - metadata = proto.Field(proto.MESSAGE, number=6, message=struct_pb2.Value,) + name = proto.Field( + proto.STRING, + number=1, + ) + version_id = proto.Field( + proto.STRING, + number=28, + ) + version_aliases = proto.RepeatedField( + proto.STRING, + number=29, + ) + version_create_time = proto.Field( + proto.MESSAGE, + number=31, + message=timestamp_pb2.Timestamp, + ) + version_update_time = proto.Field( + proto.MESSAGE, + number=32, + message=timestamp_pb2.Timestamp, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + description = proto.Field( + proto.STRING, + number=3, + ) + version_description = proto.Field( + proto.STRING, + number=30, + ) + predict_schemata = proto.Field( + proto.MESSAGE, + number=4, + message="PredictSchemata", + ) + metadata_schema_uri = proto.Field( + proto.STRING, + number=5, + ) + metadata = proto.Field( + proto.MESSAGE, + number=6, + message=struct_pb2.Value, + ) supported_export_formats = proto.RepeatedField( - proto.MESSAGE, number=20, message=ExportFormat, + proto.MESSAGE, + number=20, + message=ExportFormat, + ) + training_pipeline = proto.Field( + proto.STRING, + number=7, + ) + container_spec = proto.Field( + proto.MESSAGE, + number=9, + message="ModelContainerSpec", + ) + artifact_uri = proto.Field( + proto.STRING, + number=26, ) - training_pipeline = proto.Field(proto.STRING, number=7,) - container_spec = proto.Field(proto.MESSAGE, number=9, message="ModelContainerSpec",) - artifact_uri = proto.Field(proto.STRING, number=26,) supported_deployment_resources_types = proto.RepeatedField( - proto.ENUM, number=10, enum=DeploymentResourcesType, + proto.ENUM, + number=10, + enum=DeploymentResourcesType, + ) + supported_input_storage_formats = proto.RepeatedField( + proto.STRING, + number=11, + ) + supported_output_storage_formats = proto.RepeatedField( + proto.STRING, + number=12, ) - supported_input_storage_formats = proto.RepeatedField(proto.STRING, number=11,) - supported_output_storage_formats = proto.RepeatedField(proto.STRING, number=12,) create_time = proto.Field( - proto.MESSAGE, number=13, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=13, + message=timestamp_pb2.Timestamp, ) update_time = proto.Field( - proto.MESSAGE, number=14, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=14, + message=timestamp_pb2.Timestamp, ) deployed_models = proto.RepeatedField( - proto.MESSAGE, number=15, message=deployed_model_ref.DeployedModelRef, + proto.MESSAGE, + number=15, + message=deployed_model_ref.DeployedModelRef, ) explanation_spec = proto.Field( - proto.MESSAGE, number=23, message=explanation.ExplanationSpec, + proto.MESSAGE, + number=23, + message=explanation.ExplanationSpec, + ) + etag = proto.Field( + proto.STRING, + number=16, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=17, ) - etag = proto.Field(proto.STRING, number=16,) - labels = proto.MapField(proto.STRING, proto.STRING, number=17,) encryption_spec = proto.Field( - proto.MESSAGE, number=24, message=gca_encryption_spec.EncryptionSpec, + proto.MESSAGE, + number=24, + message=gca_encryption_spec.EncryptionSpec, ) @@ -348,12 +462,12 @@ class PredictSchemata(proto.Message): and [BatchPredictionJob.input_config][google.cloud.aiplatform.v1beta1.BatchPredictionJob.input_config]. The schema is defined as an OpenAPI 3.0.2 `Schema - Object `__. - AutoML Models always have this field populated by AI - Platform. Note: The URI given on output will be immutable - and probably different, including the URI scheme, than the - one given on input. The output URI will point to a location - where the user only has a read access. + Object `__. + AutoML Models always have this field populated by Vertex AI. + Note: The URI given on output will be immutable and probably + different, including the URI scheme, than the one given on + input. The output URI will point to a location where the + user only has a read access. parameters_schema_uri (str): Immutable. Points to a YAML file stored on Google Cloud Storage describing the parameters of prediction and @@ -363,13 +477,13 @@ class PredictSchemata(proto.Message): and [BatchPredictionJob.model_parameters][google.cloud.aiplatform.v1beta1.BatchPredictionJob.model_parameters]. The schema is defined as an OpenAPI 3.0.2 `Schema - Object `__. - AutoML Models always have this field populated by AI - Platform, if no parameters are supported, then it is set to - an empty string. Note: The URI given on output will be - immutable and probably different, including the URI scheme, - than the one given on input. The output URI will point to a - location where the user only has a read access. + Object `__. + AutoML Models always have this field populated by Vertex AI, + if no parameters are supported, then it is set to an empty + string. Note: The URI given on output will be immutable and + probably different, including the URI scheme, than the one + given on input. The output URI will point to a location + where the user only has a read access. prediction_schema_uri (str): Immutable. Points to a YAML file stored on Google Cloud Storage describing the format of a single prediction @@ -379,34 +493,43 @@ class PredictSchemata(proto.Message): and [BatchPredictionJob.output_config][google.cloud.aiplatform.v1beta1.BatchPredictionJob.output_config]. The schema is defined as an OpenAPI 3.0.2 `Schema - Object `__. - AutoML Models always have this field populated by AI - Platform. Note: The URI given on output will be immutable - and probably different, including the URI scheme, than the - one given on input. The output URI will point to a location - where the user only has a read access. + Object `__. + AutoML Models always have this field populated by Vertex AI. + Note: The URI given on output will be immutable and probably + different, including the URI scheme, than the one given on + input. The output URI will point to a location where the + user only has a read access. """ - instance_schema_uri = proto.Field(proto.STRING, number=1,) - parameters_schema_uri = proto.Field(proto.STRING, number=2,) - prediction_schema_uri = proto.Field(proto.STRING, number=3,) + instance_schema_uri = proto.Field( + proto.STRING, + number=1, + ) + parameters_schema_uri = proto.Field( + proto.STRING, + number=2, + ) + prediction_schema_uri = proto.Field( + proto.STRING, + number=3, + ) class ModelContainerSpec(proto.Message): r"""Specification of a container for serving predictions. Some fields in - this message correspond to fields in the Kubernetes Container v1 + this message correspond to fields in the `Kubernetes Container v1 core - `specification `__. + specification `__. Attributes: image_uri (str): Required. Immutable. URI of the Docker image to be used as the custom container for serving predictions. This URI must identify an image in Artifact Registry or Container - Registry. Learn more about the container publishing - requirements, including permissions requirements for the AI - Platform Service Agent, - `here `__. + Registry. Learn more about the `container publishing + requirements `__, + including permissions requirements for the Vertex AI Service + Agent. The container image is ingested upon [ModelService.UploadModel][google.cloud.aiplatform.v1beta1.ModelService.UploadModel], @@ -415,11 +538,11 @@ class ModelContainerSpec(proto.Message): To learn about the requirements for the Docker image itself, see `Custom container - requirements `__. + requirements `__. - You can use the URI to one of AI Platform's `pre-built + You can use the URI to one of Vertex AI's `pre-built container images for - prediction `__ + prediction `__ in this field. command (Sequence[str]): Immutable. Specifies the command that runs when the @@ -436,20 +559,20 @@ class ModelContainerSpec(proto.Message): ```CMD`` `__, if either exists. If this field is not specified and the container does not have an ``ENTRYPOINT``, then refer to the - Docker documentation about how ``CMD`` and ``ENTRYPOINT`` - `interact `__. + Docker documentation about `how ``CMD`` and ``ENTRYPOINT`` + interact `__. If you specify this field, then you can also specify the ``args`` field to provide additional arguments for this command. However, if you specify this field, then the container's ``CMD`` is ignored. See the `Kubernetes - documentation `__ about how - the ``command`` and ``args`` fields interact with a - container's ``ENTRYPOINT`` and ``CMD``. + documentation about how the ``command`` and ``args`` fields + interact with a container's ``ENTRYPOINT`` and + ``CMD`` `__. - In this field, you can reference environment variables `set - by AI - Platform `__ + In this field, you can reference `environment variables set + by Vertex + AI `__ and environment variables set in the [env][google.cloud.aiplatform.v1beta1.ModelContainerSpec.env] field. You cannot reference environment variables set in the @@ -462,7 +585,7 @@ class ModelContainerSpec(proto.Message): this syntax with ``$$``; for example: $$(VARIABLE_NAME) This field corresponds to the ``command`` field of the Kubernetes Containers `v1 core - API `__. + API `__. args (Sequence[str]): Immutable. Specifies arguments for the command that runs when the container starts. This overrides the container's @@ -474,20 +597,21 @@ class ModelContainerSpec(proto.Message): [command][google.cloud.aiplatform.v1beta1.ModelContainerSpec.command] field, then the command from the ``command`` field runs without any additional arguments. See the `Kubernetes - documentation `__ about how - the ``command`` and ``args`` fields interact with a - container's ``ENTRYPOINT`` and ``CMD``. + documentation about how the ``command`` and ``args`` fields + interact with a container's ``ENTRYPOINT`` and + ``CMD`` `__. If you don't specify this field and don't specify the ``command`` field, then the container's ```ENTRYPOINT`` `__ and ``CMD`` determine what runs based on their default - behavior. See the Docker documentation about how ``CMD`` and - ``ENTRYPOINT`` `interact `__. + behavior. See the Docker documentation about `how ``CMD`` + and ``ENTRYPOINT`` + interact `__. - In this field, you can reference environment variables `set - by AI - Platform `__ + In this field, you can reference `environment variables set + by Vertex + AI `__ and environment variables set in the [env][google.cloud.aiplatform.v1beta1.ModelContainerSpec.env] field. You cannot reference environment variables set in the @@ -500,7 +624,7 @@ class ModelContainerSpec(proto.Message): this syntax with ``$$``; for example: $$(VARIABLE_NAME) This field corresponds to the ``args`` field of the Kubernetes Containers `v1 core - API `__. + API `__. env (Sequence[google.cloud.aiplatform_v1beta1.types.EnvVar]): Immutable. List of environment variables to set in the container. After the container starts running, code running @@ -533,14 +657,14 @@ class ModelContainerSpec(proto.Message): This field corresponds to the ``env`` field of the Kubernetes Containers `v1 core - API `__. + API `__. ports (Sequence[google.cloud.aiplatform_v1beta1.types.Port]): - Immutable. List of ports to expose from the container. AI - Platform sends any prediction requests that it receives to - the first port on this list. AI Platform also sends - `liveness and health - checks `__ to - this port. + Immutable. List of ports to expose from the container. + Vertex AI sends any prediction requests that it receives to + the first port on this list. Vertex AI also sends `liveness + and health + checks `__ + to this port. If you do not specify this field, it defaults to following value: @@ -553,20 +677,20 @@ class ModelContainerSpec(proto.Message): } ] - AI Platform does not use ports other than the first one + Vertex AI does not use ports other than the first one listed. This field corresponds to the ``ports`` field of the Kubernetes Containers `v1 core - API `__. + API `__. predict_route (str): Immutable. HTTP path on the container to send prediction - requests to. AI Platform forwards requests sent using + requests to. Vertex AI forwards requests sent using [projects.locations.endpoints.predict][google.cloud.aiplatform.v1beta1.PredictionService.Predict] - to this path on the container's IP address and port. AI - Platform then returns the container's response in the API + to this path on the container's IP address and port. Vertex + AI then returns the container's response in the API response. - For example, if you set this field to ``/foo``, then when AI - Platform receives a prediction request, it forwards the + For example, if you set this field to ``/foo``, then when + Vertex AI receives a prediction request, it forwards the request body in a POST request to the ``/foo`` path on the port of your container specified by the first value of this ``ModelContainerSpec``'s @@ -581,28 +705,28 @@ class ModelContainerSpec(proto.Message): - ENDPOINT: The last segment (following ``endpoints/``)of the Endpoint.name][] field of the Endpoint where this - Model has been deployed. (AI Platform makes this value + Model has been deployed. (Vertex AI makes this value available to your container code as the - ```AIP_ENDPOINT_ID`` `__ - environment variable.) + ```AIP_ENDPOINT_ID`` environment + variable `__.) - DEPLOYED_MODEL: [DeployedModel.id][google.cloud.aiplatform.v1beta1.DeployedModel.id] - of the ``DeployedModel``. (AI Platform makes this value + of the ``DeployedModel``. (Vertex AI makes this value available to your container code as the ```AIP_DEPLOYED_MODEL_ID`` environment - variable `__.) + variable `__.) health_route (str): Immutable. HTTP path on the container to send health checks - to. AI Platform intermittently sends GET requests to this - path on the container's IP address and port to check that - the container is healthy. Read more about `health - checks `__. - - For example, if you set this field to ``/bar``, then AI - Platform intermittently sends a GET request to the ``/bar`` - path on the port of your container specified by the first - value of this ``ModelContainerSpec``'s + to. Vertex AI intermittently sends GET requests to this path + on the container's IP address and port to check that the + container is healthy. Read more about `health + checks `__. + + For example, if you set this field to ``/bar``, then Vertex + AI intermittently sends a GET request to the ``/bar`` path + on the port of your container specified by the first value + of this ``ModelContainerSpec``'s [ports][google.cloud.aiplatform.v1beta1.ModelContainerSpec.ports] field. @@ -614,30 +738,54 @@ class ModelContainerSpec(proto.Message): - ENDPOINT: The last segment (following ``endpoints/``)of the Endpoint.name][] field of the Endpoint where this - Model has been deployed. (AI Platform makes this value + Model has been deployed. (Vertex AI makes this value available to your container code as the - ```AIP_ENDPOINT_ID`` `__ - environment variable.) + ```AIP_ENDPOINT_ID`` environment + variable `__.) - DEPLOYED_MODEL: [DeployedModel.id][google.cloud.aiplatform.v1beta1.DeployedModel.id] - of the ``DeployedModel``. (AI Platform makes this value + of the ``DeployedModel``. (Vertex AI makes this value available to your container code as the - ```AIP_DEPLOYED_MODEL_ID`` `__ - environment variable.) + ```AIP_DEPLOYED_MODEL_ID`` environment + variable `__.) """ - image_uri = proto.Field(proto.STRING, number=1,) - command = proto.RepeatedField(proto.STRING, number=2,) - args = proto.RepeatedField(proto.STRING, number=3,) - env = proto.RepeatedField(proto.MESSAGE, number=4, message=env_var.EnvVar,) - ports = proto.RepeatedField(proto.MESSAGE, number=5, message="Port",) - predict_route = proto.Field(proto.STRING, number=6,) - health_route = proto.Field(proto.STRING, number=7,) + image_uri = proto.Field( + proto.STRING, + number=1, + ) + command = proto.RepeatedField( + proto.STRING, + number=2, + ) + args = proto.RepeatedField( + proto.STRING, + number=3, + ) + env = proto.RepeatedField( + proto.MESSAGE, + number=4, + message=env_var.EnvVar, + ) + ports = proto.RepeatedField( + proto.MESSAGE, + number=5, + message="Port", + ) + predict_route = proto.Field( + proto.STRING, + number=6, + ) + health_route = proto.Field( + proto.STRING, + number=7, + ) class Port(proto.Message): r"""Represents a network port in a container. + Attributes: container_port (int): The number of the port to expose on the pod's @@ -645,7 +793,10 @@ class Port(proto.Message): 1 and 65535 inclusive. """ - container_port = proto.Field(proto.INT32, number=3,) + container_port = proto.Field( + proto.INT32, + number=3, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/model_deployment_monitoring_job.py b/google/cloud/aiplatform_v1beta1/types/model_deployment_monitoring_job.py index 0a05808db9..64d4d2bf7e 100644 --- a/google/cloud/aiplatform_v1beta1/types/model_deployment_monitoring_job.py +++ b/google/cloud/aiplatform_v1beta1/types/model_deployment_monitoring_job.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,6 +15,7 @@ # import proto # type: ignore +from google.cloud.aiplatform_v1beta1.types import encryption_spec as gca_encryption_spec from google.cloud.aiplatform_v1beta1.types import feature_monitoring_stats from google.cloud.aiplatform_v1beta1.types import io from google.cloud.aiplatform_v1beta1.types import job_state @@ -22,6 +23,7 @@ from google.protobuf import duration_pb2 # type: ignore from google.protobuf import struct_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore +from google.rpc import status_pb2 # type: ignore __protobuf__ = proto.module( @@ -76,10 +78,13 @@ class ModelDeploymentMonitoringJob(proto.Message): schedule_state (google.cloud.aiplatform_v1beta1.types.ModelDeploymentMonitoringJob.MonitoringScheduleState): Output only. Schedule state when the monitoring job is in Running state. + latest_monitoring_pipeline_metadata (google.cloud.aiplatform_v1beta1.types.ModelDeploymentMonitoringJob.LatestMonitoringPipelineMetadata): + Output only. Latest triggered monitoring + pipeline metadata. model_deployment_monitoring_objective_configs (Sequence[google.cloud.aiplatform_v1beta1.types.ModelDeploymentMonitoringObjectiveConfig]): Required. The config for monitoring objectives. This is a per DeployedModel config. - Each DeployedModel needs to be configed + Each DeployedModel needs to be configured separately. model_deployment_monitoring_schedule_config (google.cloud.aiplatform_v1beta1.types.ModelDeploymentMonitoringScheduleConfig): Required. Schedule config for running the @@ -113,7 +118,7 @@ class ModelDeploymentMonitoringJob(proto.Message): type) as prediction request/response. If there are any data type differences between predict instance and TFDV instance, this field can be used to override the schema. For models - trained with AI Platform, this field must be set as all the + trained with Vertex AI, this field must be set as all the fields in predict instance formatted as string. bigquery_tables (Sequence[google.cloud.aiplatform_v1beta1.types.ModelDeploymentMonitoringBigQueryTable]): Output only. The created bigquery tables for @@ -129,7 +134,7 @@ class ModelDeploymentMonitoringJob(proto.Message): the TTL and we take the ceil of TTL/86400(a day). e.g. { second: 3600} indicates ttl = 1 day. - labels (Sequence[google.cloud.aiplatform_v1beta1.types.ModelDeploymentMonitoringJob.LabelsEntry]): + labels (Mapping[str, str]): The labels with user-defined metadata to organize your ModelDeploymentMonitoringJob. @@ -153,6 +158,22 @@ class ModelDeploymentMonitoringJob(proto.Message): round. stats_anomalies_base_directory (google.cloud.aiplatform_v1beta1.types.GcsDestination): Stats anomalies base folder path. + encryption_spec (google.cloud.aiplatform_v1beta1.types.EncryptionSpec): + Customer-managed encryption key spec for a + ModelDeploymentMonitoringJob. If set, this + ModelDeploymentMonitoringJob and all + sub-resources of this + ModelDeploymentMonitoringJob will be secured by + this key. + enable_monitoring_pipeline_logs (bool): + If true, the scheduled monitoring pipeline logs are sent to + Google Cloud Logging, including pipeline status and + anomalies detected. Please note the logs incur cost, which + are subject to `Cloud Logging + pricing `__. + error (google.rpc.status_pb2.Status): + Output only. Only populated when the job's state is + ``JOB_STATE_FAILED`` or ``JOB_STATE_CANCELLED``. """ class MonitoringScheduleState(proto.Enum): @@ -162,44 +183,137 @@ class MonitoringScheduleState(proto.Enum): OFFLINE = 2 RUNNING = 3 - name = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) - endpoint = proto.Field(proto.STRING, number=3,) - state = proto.Field(proto.ENUM, number=4, enum=job_state.JobState,) - schedule_state = proto.Field(proto.ENUM, number=5, enum=MonitoringScheduleState,) + class LatestMonitoringPipelineMetadata(proto.Message): + r"""All metadata of most recent monitoring pipelines. + + Attributes: + run_time (google.protobuf.timestamp_pb2.Timestamp): + The time that most recent monitoring + pipelines that is related to this run. + status (google.rpc.status_pb2.Status): + The status of the most recent monitoring + pipeline. + """ + + run_time = proto.Field( + proto.MESSAGE, + number=1, + message=timestamp_pb2.Timestamp, + ) + status = proto.Field( + proto.MESSAGE, + number=2, + message=status_pb2.Status, + ) + + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + endpoint = proto.Field( + proto.STRING, + number=3, + ) + state = proto.Field( + proto.ENUM, + number=4, + enum=job_state.JobState, + ) + schedule_state = proto.Field( + proto.ENUM, + number=5, + enum=MonitoringScheduleState, + ) + latest_monitoring_pipeline_metadata = proto.Field( + proto.MESSAGE, + number=25, + message=LatestMonitoringPipelineMetadata, + ) model_deployment_monitoring_objective_configs = proto.RepeatedField( - proto.MESSAGE, number=6, message="ModelDeploymentMonitoringObjectiveConfig", + proto.MESSAGE, + number=6, + message="ModelDeploymentMonitoringObjectiveConfig", ) model_deployment_monitoring_schedule_config = proto.Field( - proto.MESSAGE, number=7, message="ModelDeploymentMonitoringScheduleConfig", + proto.MESSAGE, + number=7, + message="ModelDeploymentMonitoringScheduleConfig", ) logging_sampling_strategy = proto.Field( - proto.MESSAGE, number=8, message=model_monitoring.SamplingStrategy, + proto.MESSAGE, + number=8, + message=model_monitoring.SamplingStrategy, ) model_monitoring_alert_config = proto.Field( - proto.MESSAGE, number=15, message=model_monitoring.ModelMonitoringAlertConfig, + proto.MESSAGE, + number=15, + message=model_monitoring.ModelMonitoringAlertConfig, + ) + predict_instance_schema_uri = proto.Field( + proto.STRING, + number=9, ) - predict_instance_schema_uri = proto.Field(proto.STRING, number=9,) sample_predict_instance = proto.Field( - proto.MESSAGE, number=19, message=struct_pb2.Value, + proto.MESSAGE, + number=19, + message=struct_pb2.Value, + ) + analysis_instance_schema_uri = proto.Field( + proto.STRING, + number=16, ) - analysis_instance_schema_uri = proto.Field(proto.STRING, number=16,) bigquery_tables = proto.RepeatedField( - proto.MESSAGE, number=10, message="ModelDeploymentMonitoringBigQueryTable", + proto.MESSAGE, + number=10, + message="ModelDeploymentMonitoringBigQueryTable", + ) + log_ttl = proto.Field( + proto.MESSAGE, + number=17, + message=duration_pb2.Duration, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=11, ) - log_ttl = proto.Field(proto.MESSAGE, number=17, message=duration_pb2.Duration,) - labels = proto.MapField(proto.STRING, proto.STRING, number=11,) create_time = proto.Field( - proto.MESSAGE, number=12, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=12, + message=timestamp_pb2.Timestamp, ) update_time = proto.Field( - proto.MESSAGE, number=13, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=13, + message=timestamp_pb2.Timestamp, ) next_schedule_time = proto.Field( - proto.MESSAGE, number=14, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=14, + message=timestamp_pb2.Timestamp, ) stats_anomalies_base_directory = proto.Field( - proto.MESSAGE, number=20, message=io.GcsDestination, + proto.MESSAGE, + number=20, + message=io.GcsDestination, + ) + encryption_spec = proto.Field( + proto.MESSAGE, + number=21, + message=gca_encryption_spec.EncryptionSpec, + ) + enable_monitoring_pipeline_logs = proto.Field( + proto.BOOL, + number=22, + ) + error = proto.Field( + proto.MESSAGE, + number=23, + message=status_pb2.Status, ) @@ -231,9 +345,20 @@ class LogType(proto.Enum): PREDICT = 1 EXPLAIN = 2 - log_source = proto.Field(proto.ENUM, number=1, enum=LogSource,) - log_type = proto.Field(proto.ENUM, number=2, enum=LogType,) - bigquery_table_path = proto.Field(proto.STRING, number=3,) + log_source = proto.Field( + proto.ENUM, + number=1, + enum=LogSource, + ) + log_type = proto.Field( + proto.ENUM, + number=2, + enum=LogType, + ) + bigquery_table_path = proto.Field( + proto.STRING, + number=3, + ) class ModelDeploymentMonitoringObjectiveConfig(proto.Message): @@ -248,7 +373,10 @@ class ModelDeploymentMonitoringObjectiveConfig(proto.Message): modelmonitoring job of this deployed model. """ - deployed_model_id = proto.Field(proto.STRING, number=1,) + deployed_model_id = proto.Field( + proto.STRING, + number=1, + ) objective_config = proto.Field( proto.MESSAGE, number=2, @@ -258,20 +386,41 @@ class ModelDeploymentMonitoringObjectiveConfig(proto.Message): class ModelDeploymentMonitoringScheduleConfig(proto.Message): r"""The config for scheduling monitoring job. + Attributes: monitor_interval (google.protobuf.duration_pb2.Duration): - Required. The model monitoring job running + Required. The model monitoring job scheduling interval. It will be rounded up to next full - hour. + hour. This defines how often the monitoring jobs + are triggered. + monitor_window (google.protobuf.duration_pb2.Duration): + The time window of the prediction data being included in + each prediction dataset. This window specifies how long the + data should be collected from historical model results for + each run. If not set, + [ModelDeploymentMonitoringScheduleConfig.monitor_interval][google.cloud.aiplatform.v1beta1.ModelDeploymentMonitoringScheduleConfig.monitor_interval] + will be used. e.g. If currently the cutoff time is + 2022-01-08 14:30:00 and the monitor_window is set to be + 3600, then data from 2022-01-08 13:30:00 to 2022-01-08 + 14:30:00 will be retrieved and aggregated to calculate the + monitoring statistics. """ monitor_interval = proto.Field( - proto.MESSAGE, number=1, message=duration_pb2.Duration, + proto.MESSAGE, + number=1, + message=duration_pb2.Duration, + ) + monitor_window = proto.Field( + proto.MESSAGE, + number=2, + message=duration_pb2.Duration, ) class ModelMonitoringStatsAnomalies(proto.Message): r"""Statistics and anomalies generated by Model Monitoring. + Attributes: objective (google.cloud.aiplatform_v1beta1.types.ModelDeploymentMonitoringObjectiveType): Model Monitoring Objective those stats and @@ -287,6 +436,7 @@ class ModelMonitoringStatsAnomalies(proto.Message): class FeatureHistoricStatsAnomalies(proto.Message): r"""Historical Stats (and Anomalies) for a specific Feature. + Attributes: feature_display_name (str): Display Name of the Feature. @@ -299,9 +449,14 @@ class FeatureHistoricStatsAnomalies(proto.Message): different time window's Prediction Dataset. """ - feature_display_name = proto.Field(proto.STRING, number=1,) + feature_display_name = proto.Field( + proto.STRING, + number=1, + ) threshold = proto.Field( - proto.MESSAGE, number=3, message=model_monitoring.ThresholdConfig, + proto.MESSAGE, + number=3, + message=model_monitoring.ThresholdConfig, ) training_stats = proto.Field( proto.MESSAGE, @@ -315,12 +470,22 @@ class FeatureHistoricStatsAnomalies(proto.Message): ) objective = proto.Field( - proto.ENUM, number=1, enum="ModelDeploymentMonitoringObjectiveType", + proto.ENUM, + number=1, + enum="ModelDeploymentMonitoringObjectiveType", + ) + deployed_model_id = proto.Field( + proto.STRING, + number=2, + ) + anomaly_count = proto.Field( + proto.INT32, + number=3, ) - deployed_model_id = proto.Field(proto.STRING, number=2,) - anomaly_count = proto.Field(proto.INT32, number=3,) feature_stats = proto.RepeatedField( - proto.MESSAGE, number=4, message=FeatureHistoricStatsAnomalies, + proto.MESSAGE, + number=4, + message=FeatureHistoricStatsAnomalies, ) diff --git a/google/cloud/aiplatform_v1beta1/types/model_evaluation.py b/google/cloud/aiplatform_v1beta1/types/model_evaluation.py index d7ef59b8f9..f1da0263e7 100644 --- a/google/cloud/aiplatform_v1beta1/types/model_evaluation.py +++ b/google/cloud/aiplatform_v1beta1/types/model_evaluation.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,7 +21,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"ModelEvaluation",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "ModelEvaluation", + }, ) @@ -34,43 +37,51 @@ class ModelEvaluation(proto.Message): name (str): Output only. The resource name of the ModelEvaluation. + display_name (str): + The display name of the ModelEvaluation. metrics_schema_uri (str): - Output only. Points to a YAML file stored on Google Cloud - Storage describing the + Points to a YAML file stored on Google Cloud Storage + describing the [metrics][google.cloud.aiplatform.v1beta1.ModelEvaluation.metrics] of this ModelEvaluation. The schema is defined as an OpenAPI 3.0.2 `Schema - Object `__. + Object `__. metrics (google.protobuf.struct_pb2.Value): - Output only. Evaluation metrics of the Model. The schema of - the metrics is stored in + Evaluation metrics of the Model. The schema of the metrics + is stored in [metrics_schema_uri][google.cloud.aiplatform.v1beta1.ModelEvaluation.metrics_schema_uri] create_time (google.protobuf.timestamp_pb2.Timestamp): Output only. Timestamp when this ModelEvaluation was created. slice_dimensions (Sequence[str]): - Output only. All possible + All possible [dimensions][ModelEvaluationSlice.slice.dimension] of ModelEvaluationSlices. The dimensions can be used as the filter of the [ModelService.ListModelEvaluationSlices][google.cloud.aiplatform.v1beta1.ModelService.ListModelEvaluationSlices] request, in the form of ``slice.dimension = ``. model_explanation (google.cloud.aiplatform_v1beta1.types.ModelExplanation): - Output only. Aggregated explanation metrics - for the Model's prediction output over the data - this ModelEvaluation uses. This field is - populated only if the Model is evaluated with + Aggregated explanation metrics for the + Model's prediction output over the data this + ModelEvaluation uses. This field is populated + only if the Model is evaluated with explanations, and only for AutoML tabular Models. explanation_specs (Sequence[google.cloud.aiplatform_v1beta1.types.ModelEvaluation.ModelEvaluationExplanationSpec]): - Output only. Describes the values of + Describes the values of [ExplanationSpec][google.cloud.aiplatform.v1beta1.ExplanationSpec] that are used for explaining the predicted values on the evaluated data. + metadata (google.protobuf.struct_pb2.Value): + The metadata of the ModelEvaluation. For the ModelEvaluation + uploaded from Managed Pipeline, metadata contains a + structured value with keys of "pipeline_job_id", + "evaluation_dataset_type", "evaluation_dataset_path". """ class ModelEvaluationExplanationSpec(proto.Message): r""" + Attributes: explanation_type (str): Explanation type. @@ -83,21 +94,56 @@ class ModelEvaluationExplanationSpec(proto.Message): Explanation spec details. """ - explanation_type = proto.Field(proto.STRING, number=1,) + explanation_type = proto.Field( + proto.STRING, + number=1, + ) explanation_spec = proto.Field( - proto.MESSAGE, number=2, message=explanation.ExplanationSpec, + proto.MESSAGE, + number=2, + message=explanation.ExplanationSpec, ) - name = proto.Field(proto.STRING, number=1,) - metrics_schema_uri = proto.Field(proto.STRING, number=2,) - metrics = proto.Field(proto.MESSAGE, number=3, message=struct_pb2.Value,) - create_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) - slice_dimensions = proto.RepeatedField(proto.STRING, number=5,) + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=10, + ) + metrics_schema_uri = proto.Field( + proto.STRING, + number=2, + ) + metrics = proto.Field( + proto.MESSAGE, + number=3, + message=struct_pb2.Value, + ) + create_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + slice_dimensions = proto.RepeatedField( + proto.STRING, + number=5, + ) model_explanation = proto.Field( - proto.MESSAGE, number=8, message=explanation.ModelExplanation, + proto.MESSAGE, + number=8, + message=explanation.ModelExplanation, ) explanation_specs = proto.RepeatedField( - proto.MESSAGE, number=9, message=ModelEvaluationExplanationSpec, + proto.MESSAGE, + number=9, + message=ModelEvaluationExplanationSpec, + ) + metadata = proto.Field( + proto.MESSAGE, + number=11, + message=struct_pb2.Value, ) diff --git a/google/cloud/aiplatform_v1beta1/types/model_evaluation_slice.py b/google/cloud/aiplatform_v1beta1/types/model_evaluation_slice.py index 94066203c6..0a4fd5c8ed 100644 --- a/google/cloud/aiplatform_v1beta1/types/model_evaluation_slice.py +++ b/google/cloud/aiplatform_v1beta1/types/model_evaluation_slice.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,7 +20,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"ModelEvaluationSlice",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "ModelEvaluationSlice", + }, ) @@ -42,7 +45,7 @@ class ModelEvaluationSlice(proto.Message): [metrics][google.cloud.aiplatform.v1beta1.ModelEvaluationSlice.metrics] of this ModelEvaluationSlice. The schema is defined as an OpenAPI 3.0.2 `Schema - Object `__. + Object `__. metrics (google.protobuf.struct_pb2.Value): Output only. Sliced evaluation metrics of the Model. The schema of the metrics is stored in @@ -54,6 +57,7 @@ class ModelEvaluationSlice(proto.Message): class Slice(proto.Message): r"""Definition of a slice. + Attributes: dimension (str): Output only. The dimension of the slice. Well-known @@ -69,14 +73,38 @@ class Slice(proto.Message): this slice. """ - dimension = proto.Field(proto.STRING, number=1,) - value = proto.Field(proto.STRING, number=2,) + dimension = proto.Field( + proto.STRING, + number=1, + ) + value = proto.Field( + proto.STRING, + number=2, + ) - name = proto.Field(proto.STRING, number=1,) - slice_ = proto.Field(proto.MESSAGE, number=2, message=Slice,) - metrics_schema_uri = proto.Field(proto.STRING, number=3,) - metrics = proto.Field(proto.MESSAGE, number=4, message=struct_pb2.Value,) - create_time = proto.Field(proto.MESSAGE, number=5, message=timestamp_pb2.Timestamp,) + name = proto.Field( + proto.STRING, + number=1, + ) + slice_ = proto.Field( + proto.MESSAGE, + number=2, + message=Slice, + ) + metrics_schema_uri = proto.Field( + proto.STRING, + number=3, + ) + metrics = proto.Field( + proto.MESSAGE, + number=4, + message=struct_pb2.Value, + ) + create_time = proto.Field( + proto.MESSAGE, + number=5, + message=timestamp_pb2.Timestamp, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/model_monitoring.py b/google/cloud/aiplatform_v1beta1/types/model_monitoring.py index 30d8375934..79bb1357cd 100644 --- a/google/cloud/aiplatform_v1beta1/types/model_monitoring.py +++ b/google/cloud/aiplatform_v1beta1/types/model_monitoring.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1", manifest={ + "ModelMonitoringConfig", "ModelMonitoringObjectiveConfig", "ModelMonitoringAlertConfig", "ThresholdConfig", @@ -29,8 +30,46 @@ ) +class ModelMonitoringConfig(proto.Message): + r"""Next ID: 5 + + Attributes: + objective_configs (Sequence[google.cloud.aiplatform_v1beta1.types.ModelMonitoringObjectiveConfig]): + Model monitoring objective config. + alert_config (google.cloud.aiplatform_v1beta1.types.ModelMonitoringAlertConfig): + Model monitoring alert config. + analysis_instance_schema_uri (str): + YAML schema file uri in Cloud Storage + describing the format of a single instance that + you want Tensorflow Data Validation (TFDV) to + analyze. + If there are any data type differences between + predict instance and TFDV instance, this field + can be used to override the schema. For models + trained with Vertex AI, this field must be set + as all the fields in predict instance formatted + as string. + """ + + objective_configs = proto.RepeatedField( + proto.MESSAGE, + number=3, + message="ModelMonitoringObjectiveConfig", + ) + alert_config = proto.Field( + proto.MESSAGE, + number=2, + message="ModelMonitoringAlertConfig", + ) + analysis_instance_schema_uri = proto.Field( + proto.STRING, + number=4, + ) + + class ModelMonitoringObjectiveConfig(proto.Message): - r"""Next ID: 6 + r"""Next ID: 8 + Attributes: training_dataset (google.cloud.aiplatform_v1beta1.types.ModelMonitoringObjectiveConfig.TrainingDataset): Training dataset for models. This field has @@ -42,20 +81,37 @@ class ModelMonitoringObjectiveConfig(proto.Message): prediction data. prediction_drift_detection_config (google.cloud.aiplatform_v1beta1.types.ModelMonitoringObjectiveConfig.PredictionDriftDetectionConfig): The config for drift of prediction data. + explanation_config (google.cloud.aiplatform_v1beta1.types.ModelMonitoringObjectiveConfig.ExplanationConfig): + The config for integrating with Vertex + Explainable AI. """ class TrainingDataset(proto.Message): r"""Training Dataset information. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: dataset (str): The resource name of the Dataset used to train this Model. + + This field is a member of `oneof`_ ``data_source``. gcs_source (google.cloud.aiplatform_v1beta1.types.GcsSource): The Google Cloud Storage uri of the unmanaged Dataset used to train this Model. + + This field is a member of `oneof`_ ``data_source``. bigquery_source (google.cloud.aiplatform_v1beta1.types.BigQuerySource): The BigQuery table of the unmanaged Dataset used to train this Model. + + This field is a member of `oneof`_ ``data_source``. data_format (str): Data format of the dataset, only applicable if the input is from Google Cloud Storage. @@ -66,6 +122,8 @@ class TrainingDataset(proto.Message): "csv" The source file is a CSV file. + "jsonl" + The source file is a JSONL file. target_field (str): The target field name the model is to predict. This field will be excluded when doing @@ -76,17 +134,35 @@ class TrainingDataset(proto.Message): dataset. """ - dataset = proto.Field(proto.STRING, number=3, oneof="data_source",) + dataset = proto.Field( + proto.STRING, + number=3, + oneof="data_source", + ) gcs_source = proto.Field( - proto.MESSAGE, number=4, oneof="data_source", message=io.GcsSource, + proto.MESSAGE, + number=4, + oneof="data_source", + message=io.GcsSource, ) bigquery_source = proto.Field( - proto.MESSAGE, number=5, oneof="data_source", message=io.BigQuerySource, + proto.MESSAGE, + number=5, + oneof="data_source", + message=io.BigQuerySource, + ) + data_format = proto.Field( + proto.STRING, + number=2, + ) + target_field = proto.Field( + proto.STRING, + number=6, ) - data_format = proto.Field(proto.STRING, number=2,) - target_field = proto.Field(proto.STRING, number=6,) logging_sampling_strategy = proto.Field( - proto.MESSAGE, number=7, message="SamplingStrategy", + proto.MESSAGE, + number=7, + message="SamplingStrategy", ) class TrainingPredictionSkewDetectionConfig(proto.Message): @@ -95,62 +171,226 @@ class TrainingPredictionSkewDetectionConfig(proto.Message): parameters. Attributes: - skew_thresholds (Sequence[google.cloud.aiplatform_v1beta1.types.ModelMonitoringObjectiveConfig.TrainingPredictionSkewDetectionConfig.SkewThresholdsEntry]): + skew_thresholds (Mapping[str, google.cloud.aiplatform_v1beta1.types.ThresholdConfig]): Key is the feature name and value is the threshold. If a feature needs to be monitored - for skew, a value threshold must be configed for - that feature. The threshold here is against + for skew, a value threshold must be configured + for that feature. The threshold here is against feature distribution distance between the training and prediction feature. + attribution_score_skew_thresholds (Mapping[str, google.cloud.aiplatform_v1beta1.types.ThresholdConfig]): + Key is the feature name and value is the + threshold. The threshold here is against + attribution score distance between the training + and prediction feature. + default_skew_threshold (google.cloud.aiplatform_v1beta1.types.ThresholdConfig): + Skew anomaly detection threshold used by all + features. When the per-feature thresholds are + not set, this field can be used to specify a + threshold for all features. """ skew_thresholds = proto.MapField( - proto.STRING, proto.MESSAGE, number=1, message="ThresholdConfig", + proto.STRING, + proto.MESSAGE, + number=1, + message="ThresholdConfig", + ) + attribution_score_skew_thresholds = proto.MapField( + proto.STRING, + proto.MESSAGE, + number=2, + message="ThresholdConfig", + ) + default_skew_threshold = proto.Field( + proto.MESSAGE, + number=6, + message="ThresholdConfig", ) class PredictionDriftDetectionConfig(proto.Message): r"""The config for Prediction data drift detection. + Attributes: - drift_thresholds (Sequence[google.cloud.aiplatform_v1beta1.types.ModelMonitoringObjectiveConfig.PredictionDriftDetectionConfig.DriftThresholdsEntry]): + drift_thresholds (Mapping[str, google.cloud.aiplatform_v1beta1.types.ThresholdConfig]): Key is the feature name and value is the threshold. If a feature needs to be monitored - for drift, a value threshold must be configed + for drift, a value threshold must be configured for that feature. The threshold here is against feature distribution distance between different time windws. + attribution_score_drift_thresholds (Mapping[str, google.cloud.aiplatform_v1beta1.types.ThresholdConfig]): + Key is the feature name and value is the + threshold. The threshold here is against + attribution score distance between different + time windows. + default_drift_threshold (google.cloud.aiplatform_v1beta1.types.ThresholdConfig): + Drift anomaly detection threshold used by all + features. When the per-feature thresholds are + not set, this field can be used to specify a + threshold for all features. """ drift_thresholds = proto.MapField( - proto.STRING, proto.MESSAGE, number=1, message="ThresholdConfig", + proto.STRING, + proto.MESSAGE, + number=1, + message="ThresholdConfig", + ) + attribution_score_drift_thresholds = proto.MapField( + proto.STRING, + proto.MESSAGE, + number=2, + message="ThresholdConfig", + ) + default_drift_threshold = proto.Field( + proto.MESSAGE, + number=5, + message="ThresholdConfig", + ) + + class ExplanationConfig(proto.Message): + r"""The config for integrating with Vertex Explainable AI. Only + applicable if the Model has explanation_spec populated. + + Attributes: + enable_feature_attributes (bool): + If want to analyze the Vertex Explainable AI + feature attribute scores or not. If set to true, + Vertex AI will log the feature attributions from + explain response and do the skew/drift detection + for them. + explanation_baseline (google.cloud.aiplatform_v1beta1.types.ModelMonitoringObjectiveConfig.ExplanationConfig.ExplanationBaseline): + Predictions generated by the + BatchPredictionJob using baseline dataset. + """ + + class ExplanationBaseline(proto.Message): + r"""Output from + [BatchPredictionJob][google.cloud.aiplatform.v1beta1.BatchPredictionJob] + for Model Monitoring baseline dataset, which can be used to generate + baseline attribution scores. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + gcs (google.cloud.aiplatform_v1beta1.types.GcsDestination): + Cloud Storage location for BatchExplain + output. + + This field is a member of `oneof`_ ``destination``. + bigquery (google.cloud.aiplatform_v1beta1.types.BigQueryDestination): + BigQuery location for BatchExplain output. + + This field is a member of `oneof`_ ``destination``. + prediction_format (google.cloud.aiplatform_v1beta1.types.ModelMonitoringObjectiveConfig.ExplanationConfig.ExplanationBaseline.PredictionFormat): + The storage format of the predictions + generated BatchPrediction job. + """ + + class PredictionFormat(proto.Enum): + r"""The storage format of the predictions generated + BatchPrediction job. + """ + PREDICTION_FORMAT_UNSPECIFIED = 0 + JSONL = 2 + BIGQUERY = 3 + + gcs = proto.Field( + proto.MESSAGE, + number=2, + oneof="destination", + message=io.GcsDestination, + ) + bigquery = proto.Field( + proto.MESSAGE, + number=3, + oneof="destination", + message=io.BigQueryDestination, + ) + prediction_format = proto.Field( + proto.ENUM, + number=1, + enum="ModelMonitoringObjectiveConfig.ExplanationConfig.ExplanationBaseline.PredictionFormat", + ) + + enable_feature_attributes = proto.Field( + proto.BOOL, + number=1, + ) + explanation_baseline = proto.Field( + proto.MESSAGE, + number=2, + message="ModelMonitoringObjectiveConfig.ExplanationConfig.ExplanationBaseline", ) - training_dataset = proto.Field(proto.MESSAGE, number=1, message=TrainingDataset,) + training_dataset = proto.Field( + proto.MESSAGE, + number=1, + message=TrainingDataset, + ) training_prediction_skew_detection_config = proto.Field( - proto.MESSAGE, number=2, message=TrainingPredictionSkewDetectionConfig, + proto.MESSAGE, + number=2, + message=TrainingPredictionSkewDetectionConfig, ) prediction_drift_detection_config = proto.Field( - proto.MESSAGE, number=3, message=PredictionDriftDetectionConfig, + proto.MESSAGE, + number=3, + message=PredictionDriftDetectionConfig, + ) + explanation_config = proto.Field( + proto.MESSAGE, + number=5, + message=ExplanationConfig, ) class ModelMonitoringAlertConfig(proto.Message): - r"""Next ID: 2 + r"""Next ID: 3 + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: email_alert_config (google.cloud.aiplatform_v1beta1.types.ModelMonitoringAlertConfig.EmailAlertConfig): Email alert config. + + This field is a member of `oneof`_ ``alert``. + enable_logging (bool): + Dump the anomalies to Cloud Logging. The anomalies will be + put to json payload encoded from proto + [google.cloud.aiplatform.logging.ModelMonitoringAnomaliesLogEntry][]. + This can be further sinked to Pub/Sub or any other services + supported by Cloud Logging. """ class EmailAlertConfig(proto.Message): r"""The config for email alert. + Attributes: user_emails (Sequence[str]): The email addresses to send the alert. """ - user_emails = proto.RepeatedField(proto.STRING, number=1,) + user_emails = proto.RepeatedField( + proto.STRING, + number=1, + ) email_alert_config = proto.Field( - proto.MESSAGE, number=1, oneof="alert", message=EmailAlertConfig, + proto.MESSAGE, + number=1, + oneof="alert", + message=EmailAlertConfig, + ) + enable_logging = proto.Field( + proto.BOOL, + number=2, ) @@ -158,6 +398,9 @@ class ThresholdConfig(proto.Message): r"""The config for feature monitoring threshold. Next ID: 3 + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: value (float): Specify a threshold value that can trigger @@ -171,9 +414,15 @@ class ThresholdConfig(proto.Message): Each feature must have a non-zero threshold if they need to be monitored. Otherwise no alert will be triggered for that feature. + + This field is a member of `oneof`_ ``threshold``. """ - value = proto.Field(proto.DOUBLE, number=1, oneof="threshold",) + value = proto.Field( + proto.DOUBLE, + number=1, + oneof="threshold", + ) class SamplingStrategy(proto.Message): @@ -189,15 +438,21 @@ class SamplingStrategy(proto.Message): class RandomSampleConfig(proto.Message): r"""Requests are randomly selected. + Attributes: sample_rate (float): Sample rate (0, 1] """ - sample_rate = proto.Field(proto.DOUBLE, number=1,) + sample_rate = proto.Field( + proto.DOUBLE, + number=1, + ) random_sample_config = proto.Field( - proto.MESSAGE, number=1, message=RandomSampleConfig, + proto.MESSAGE, + number=1, + message=RandomSampleConfig, ) diff --git a/google/cloud/aiplatform_v1beta1/types/model_service.py b/google/cloud/aiplatform_v1beta1/types/model_service.py index 9f94a8fed9..ec9137affa 100644 --- a/google/cloud/aiplatform_v1beta1/types/model_service.py +++ b/google/cloud/aiplatform_v1beta1/types/model_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,9 +15,12 @@ # import proto # type: ignore +from google.cloud.aiplatform_v1beta1.types import explanation from google.cloud.aiplatform_v1beta1.types import io from google.cloud.aiplatform_v1beta1.types import model as gca_model -from google.cloud.aiplatform_v1beta1.types import model_evaluation +from google.cloud.aiplatform_v1beta1.types import ( + model_evaluation as gca_model_evaluation, +) from google.cloud.aiplatform_v1beta1.types import model_evaluation_slice from google.cloud.aiplatform_v1beta1.types import operation from google.protobuf import field_mask_pb2 # type: ignore @@ -32,11 +35,21 @@ "GetModelRequest", "ListModelsRequest", "ListModelsResponse", + "ListModelVersionsRequest", + "ListModelVersionsResponse", "UpdateModelRequest", + "UpdateExplanationDatasetRequest", + "UpdateExplanationDatasetOperationMetadata", "DeleteModelRequest", + "DeleteModelVersionRequest", + "MergeVersionAliasesRequest", "ExportModelRequest", "ExportModelOperationMetadata", + "UpdateExplanationDatasetResponse", "ExportModelResponse", + "ImportModelEvaluationRequest", + "BatchImportModelEvaluationSlicesRequest", + "BatchImportModelEvaluationSlicesResponse", "GetModelEvaluationRequest", "ListModelEvaluationsRequest", "ListModelEvaluationsResponse", @@ -56,12 +69,38 @@ class UploadModelRequest(proto.Message): Required. The resource name of the Location into which to upload the Model. Format: ``projects/{project}/locations/{location}`` + parent_model (str): + Optional. The resource name of the model into + which to upload the version. Only specify this + field when uploading a new version. + model_id (str): + Optional. The ID to use for the uploaded Model, which will + become the final component of the model resource name. + + This value may be up to 63 characters, and valid characters + are ``[a-z0-9_-]``. The first character cannot be a number + or hyphen. model (google.cloud.aiplatform_v1beta1.types.Model): Required. The Model to create. """ - parent = proto.Field(proto.STRING, number=1,) - model = proto.Field(proto.MESSAGE, number=2, message=gca_model.Model,) + parent = proto.Field( + proto.STRING, + number=1, + ) + parent_model = proto.Field( + proto.STRING, + number=4, + ) + model_id = proto.Field( + proto.STRING, + number=5, + ) + model = proto.Field( + proto.MESSAGE, + number=2, + message=gca_model.Model, + ) class UploadModelOperationMetadata(proto.Message): @@ -75,7 +114,9 @@ class UploadModelOperationMetadata(proto.Message): """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, ) @@ -88,9 +129,19 @@ class UploadModelResponse(proto.Message): model (str): The name of the uploaded Model resource. Format: ``projects/{project}/locations/{location}/models/{model}`` + model_version_id (str): + Output only. The version ID of the model that + is uploaded. """ - model = proto.Field(proto.STRING, number=1,) + model = proto.Field( + proto.STRING, + number=1, + ) + model_version_id = proto.Field( + proto.STRING, + number=2, + ) class GetModelRequest(proto.Message): @@ -101,9 +152,23 @@ class GetModelRequest(proto.Message): name (str): Required. The name of the Model resource. Format: ``projects/{project}/locations/{location}/models/{model}`` + + In order to retrieve a specific version of the model, also + provide the version ID or version alias. Example: + ``projects/{project}/locations/{location}/models/{model}@2`` + or + ``projects/{project}/locations/{location}/models/{model}@golden`` + If no version ID or alias is specified, the "default" + version will be returned. The "default" version alias is + created for the first version of the model, and can be moved + to other versions later on. There will be exactly one + default version. """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListModelsRequest(proto.Message): @@ -147,11 +212,27 @@ class ListModelsRequest(proto.Message): Mask specifying which fields to read. """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) - read_mask = proto.Field(proto.MESSAGE, number=5, message=field_mask_pb2.FieldMask,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=5, + message=field_mask_pb2.FieldMask, + ) class ListModelsResponse(proto.Message): @@ -171,8 +252,100 @@ class ListModelsResponse(proto.Message): def raw_page(self): return self - models = proto.RepeatedField(proto.MESSAGE, number=1, message=gca_model.Model,) - next_page_token = proto.Field(proto.STRING, number=2,) + models = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gca_model.Model, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) + + +class ListModelVersionsRequest(proto.Message): + r"""Request message for + [ModelService.ListModelVersions][google.cloud.aiplatform.v1beta1.ModelService.ListModelVersions]. + + Attributes: + name (str): + Required. The name of the model to list + versions for. + page_size (int): + The standard list page size. + page_token (str): + The standard list page token. Typically obtained via + [ListModelVersionsResponse.next_page_token][google.cloud.aiplatform.v1beta1.ListModelVersionsResponse.next_page_token] + of the previous [ModelService.ListModelversions][] call. + filter (str): + An expression for filtering the results of the request. For + field names both snake_case and camelCase are supported. + + - ``labels`` supports general map functions that is: + + - ``labels.key=value`` - key:value equality + - \`labels.key:\* or labels:key - key existence + - A key including a space must be quoted. + ``labels."a key"``. + + Some examples: + + - ``labels.myKey="myValue"`` + read_mask (google.protobuf.field_mask_pb2.FieldMask): + Mask specifying which fields to read. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + page_size = proto.Field( + proto.INT32, + number=2, + ) + page_token = proto.Field( + proto.STRING, + number=3, + ) + filter = proto.Field( + proto.STRING, + number=4, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=5, + message=field_mask_pb2.FieldMask, + ) + + +class ListModelVersionsResponse(proto.Message): + r"""Response message for + [ModelService.ListModelVersions][google.cloud.aiplatform.v1beta1.ModelService.ListModelVersions] + + Attributes: + models (Sequence[google.cloud.aiplatform_v1beta1.types.Model]): + List of Model versions in the requested page. + In the returned Model name field, version ID + instead of regvision tag will be included. + next_page_token (str): + A token to retrieve the next page of results. Pass to + [ListModelVersionsRequest.page_token][google.cloud.aiplatform.v1beta1.ListModelVersionsRequest.page_token] + to obtain that page. + """ + + @property + def raw_page(self): + return self + + models = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gca_model.Model, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) class UpdateModelRequest(proto.Message): @@ -181,17 +354,83 @@ class UpdateModelRequest(proto.Message): Attributes: model (google.cloud.aiplatform_v1beta1.types.Model): - Required. The Model which replaces the - resource on the server. + Required. The Model which replaces the resource on the + server. When Model Versioning is enabled, the model.name + will be used to determine whether to update the model or + model version. + + 1. model.name with the @ value, e.g. models/123@1, refers to + a version specific update. + 2. model.name without the @ value, e.g. models/123, refers + to a model update. + 3. model.name with @-, e.g. models/123@-, refers to a model + update. + 4. Supported model fields: display_name, description; + supported version-specific fields: version_description. + Labels are supported in both scenarios. Both the model + labels and the version labels are merged when a model is + returned. When updating labels, if the request is for + model-specific update, model label gets updated. + Otherwise, version labels get updated. + 5. A model name or model version name fields update mismatch + will cause a precondition error. + 6. One request cannot update both the model and the version + fields. You must update them separately. update_mask (google.protobuf.field_mask_pb2.FieldMask): Required. The update mask applies to the resource. For the ``FieldMask`` definition, see - `FieldMask `__. + [google.protobuf.FieldMask][google.protobuf.FieldMask]. """ - model = proto.Field(proto.MESSAGE, number=1, message=gca_model.Model,) + model = proto.Field( + proto.MESSAGE, + number=1, + message=gca_model.Model, + ) update_mask = proto.Field( - proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, + ) + + +class UpdateExplanationDatasetRequest(proto.Message): + r"""Request message for + [ModelService.UpdateExplanationDataset][google.cloud.aiplatform.v1beta1.ModelService.UpdateExplanationDataset]. + + Attributes: + model (str): + Required. The resource name of the Model to update. Format: + ``projects/{project}/locations/{location}/models/{model}`` + examples (google.cloud.aiplatform_v1beta1.types.Examples): + The example config containing the location of + the dataset. + """ + + model = proto.Field( + proto.STRING, + number=1, + ) + examples = proto.Field( + proto.MESSAGE, + number=2, + message=explanation.Examples, + ) + + +class UpdateExplanationDatasetOperationMetadata(proto.Message): + r"""Runtime operation information for + [ModelService.UpdateExplanationDataset][google.cloud.aiplatform.v1beta1.ModelService.UpdateExplanationDataset]. + + Attributes: + generic_metadata (google.cloud.aiplatform_v1beta1.types.GenericOperationMetadata): + The common part of the operation metadata. + """ + + generic_metadata = proto.Field( + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, ) @@ -206,7 +445,66 @@ class DeleteModelRequest(proto.Message): ``projects/{project}/locations/{location}/models/{model}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) + + +class DeleteModelVersionRequest(proto.Message): + r"""Request message for + [ModelService.DeleteModelVersion][google.cloud.aiplatform.v1beta1.ModelService.DeleteModelVersion]. + + Attributes: + name (str): + Required. The name of the model version to be deleted, with + a version ID explicitly included. + + Example: + ``projects/{project}/locations/{location}/models/{model}@1234`` + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + + +class MergeVersionAliasesRequest(proto.Message): + r"""Request message for + [ModelService.MergeVersionAliases][google.cloud.aiplatform.v1beta1.ModelService.MergeVersionAliases]. + + Attributes: + name (str): + Required. The name of the model version to merge aliases, + with a version ID explicitly included. + + Example: + ``projects/{project}/locations/{location}/models/{model}@1234`` + version_aliases (Sequence[str]): + Required. The set of version aliases to merge. The alias + should be at most 128 characters, and match + ``[a-z][a-z0-9-]{0,126}[a-z-0-9]``. Add the ``-`` prefix to + an alias means removing that alias from the version. ``-`` + is NOT counted in the 128 characters. Example: ``-golden`` + means removing the ``golden`` alias from the version. + + There is NO ordering in aliases, which means + + 1) The aliases returned from GetModel API might not have the + exactly same order from this MergeVersionAliases API. 2) + Adding and deleting the same alias in the request is not + recommended, and the 2 operations will be cancelled out. + """ + + name = proto.Field( + proto.STRING, + number=1, + ) + version_aliases = proto.RepeatedField( + proto.STRING, + number=2, + ) class ExportModelRequest(proto.Message): @@ -215,8 +513,11 @@ class ExportModelRequest(proto.Message): Attributes: name (str): - Required. The resource name of the Model to export. Format: - ``projects/{project}/locations/{location}/models/{model}`` + Required. The resource name of the Model to + export. The resource name may contain version id + or version alias to specify the version, if no + version is specified, the default version will + be exported. output_config (google.cloud.aiplatform_v1beta1.types.ExportModelRequest.OutputConfig): Required. The desired output location and configuration. @@ -224,6 +525,7 @@ class ExportModelRequest(proto.Message): class OutputConfig(proto.Message): r"""Output configuration for the Model export. + Attributes: export_format_id (str): The ID of the format in which the Model must be exported. @@ -250,16 +552,30 @@ class OutputConfig(proto.Message): ``IMAGE``. """ - export_format_id = proto.Field(proto.STRING, number=1,) + export_format_id = proto.Field( + proto.STRING, + number=1, + ) artifact_destination = proto.Field( - proto.MESSAGE, number=3, message=io.GcsDestination, + proto.MESSAGE, + number=3, + message=io.GcsDestination, ) image_destination = proto.Field( - proto.MESSAGE, number=4, message=io.ContainerRegistryDestination, + proto.MESSAGE, + number=4, + message=io.ContainerRegistryDestination, ) - name = proto.Field(proto.STRING, number=1,) - output_config = proto.Field(proto.MESSAGE, number=2, message=OutputConfig,) + name = proto.Field( + proto.STRING, + number=1, + ) + output_config = proto.Field( + proto.MESSAGE, + number=2, + message=OutputConfig, + ) class ExportModelOperationMetadata(proto.Message): @@ -292,20 +608,106 @@ class OutputInfo(proto.Message): image created. """ - artifact_output_uri = proto.Field(proto.STRING, number=2,) - image_output_uri = proto.Field(proto.STRING, number=3,) + artifact_output_uri = proto.Field( + proto.STRING, + number=2, + ) + image_output_uri = proto.Field( + proto.STRING, + number=3, + ) generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, + ) + output_info = proto.Field( + proto.MESSAGE, + number=2, + message=OutputInfo, ) - output_info = proto.Field(proto.MESSAGE, number=2, message=OutputInfo,) + + +class UpdateExplanationDatasetResponse(proto.Message): + r"""Response message of + [ModelService.UpdateExplanationDataset][google.cloud.aiplatform.v1beta1.ModelService.UpdateExplanationDataset] + operation. + + """ class ExportModelResponse(proto.Message): r"""Response message of [ModelService.ExportModel][google.cloud.aiplatform.v1beta1.ModelService.ExportModel] operation. - """ + + """ + + +class ImportModelEvaluationRequest(proto.Message): + r"""Request message for + [ModelService.ImportModelEvaluation][google.cloud.aiplatform.v1beta1.ModelService.ImportModelEvaluation] + + Attributes: + parent (str): + Required. The name of the parent model resource. Format: + ``projects/{project}/locations/{location}/models/{model}`` + model_evaluation (google.cloud.aiplatform_v1beta1.types.ModelEvaluation): + Required. Model evaluation resource to be + imported. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + model_evaluation = proto.Field( + proto.MESSAGE, + number=2, + message=gca_model_evaluation.ModelEvaluation, + ) + + +class BatchImportModelEvaluationSlicesRequest(proto.Message): + r"""Request message for + [ModelService.BatchImportModelEvaluationSlices][google.cloud.aiplatform.v1beta1.ModelService.BatchImportModelEvaluationSlices] + + Attributes: + parent (str): + Required. The name of the parent ModelEvaluation resource. + Format: + ``projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}`` + model_evaluation_slices (Sequence[google.cloud.aiplatform_v1beta1.types.ModelEvaluationSlice]): + Required. Model evaluation slice resource to + be imported. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + model_evaluation_slices = proto.RepeatedField( + proto.MESSAGE, + number=2, + message=model_evaluation_slice.ModelEvaluationSlice, + ) + + +class BatchImportModelEvaluationSlicesResponse(proto.Message): + r"""Response message for + [ModelService.BatchImportModelEvaluationSlices][google.cloud.aiplatform.v1beta1.ModelService.BatchImportModelEvaluationSlices] + + Attributes: + imported_model_evaluation_slices (Sequence[str]): + Output only. List of imported + [ModelEvaluationSlice.name][google.cloud.aiplatform.v1beta1.ModelEvaluationSlice.name]. + """ + + imported_model_evaluation_slices = proto.RepeatedField( + proto.STRING, + number=1, + ) class GetModelEvaluationRequest(proto.Message): @@ -318,7 +720,10 @@ class GetModelEvaluationRequest(proto.Message): ``projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListModelEvaluationsRequest(proto.Message): @@ -344,11 +749,27 @@ class ListModelEvaluationsRequest(proto.Message): Mask specifying which fields to read. """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) - read_mask = proto.Field(proto.MESSAGE, number=5, message=field_mask_pb2.FieldMask,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=5, + message=field_mask_pb2.FieldMask, + ) class ListModelEvaluationsResponse(proto.Message): @@ -370,9 +791,14 @@ def raw_page(self): return self model_evaluations = proto.RepeatedField( - proto.MESSAGE, number=1, message=model_evaluation.ModelEvaluation, + proto.MESSAGE, + number=1, + message=gca_model_evaluation.ModelEvaluation, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class GetModelEvaluationSliceRequest(proto.Message): @@ -386,7 +812,10 @@ class GetModelEvaluationSliceRequest(proto.Message): ``projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}/slices/{slice}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListModelEvaluationSlicesRequest(proto.Message): @@ -414,11 +843,27 @@ class ListModelEvaluationSlicesRequest(proto.Message): Mask specifying which fields to read. """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) - read_mask = proto.Field(proto.MESSAGE, number=5, message=field_mask_pb2.FieldMask,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=5, + message=field_mask_pb2.FieldMask, + ) class ListModelEvaluationSlicesResponse(proto.Message): @@ -440,9 +885,14 @@ def raw_page(self): return self model_evaluation_slices = proto.RepeatedField( - proto.MESSAGE, number=1, message=model_evaluation_slice.ModelEvaluationSlice, + proto.MESSAGE, + number=1, + message=model_evaluation_slice.ModelEvaluationSlice, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/operation.py b/google/cloud/aiplatform_v1beta1/types/operation.py index 637c8cd951..2ca36d9504 100644 --- a/google/cloud/aiplatform_v1beta1/types/operation.py +++ b/google/cloud/aiplatform_v1beta1/types/operation.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -21,12 +21,16 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1", - manifest={"GenericOperationMetadata", "DeleteOperationMetadata",}, + manifest={ + "GenericOperationMetadata", + "DeleteOperationMetadata", + }, ) class GenericOperationMetadata(proto.Message): r"""Generic Metadata shared by all operations. + Attributes: partial_failures (Sequence[google.rpc.status_pb2.Status]): Output only. Partial failures encountered. @@ -45,21 +49,34 @@ class GenericOperationMetadata(proto.Message): """ partial_failures = proto.RepeatedField( - proto.MESSAGE, number=1, message=status_pb2.Status, + proto.MESSAGE, + number=1, + message=status_pb2.Status, + ) + create_time = proto.Field( + proto.MESSAGE, + number=2, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, ) - create_time = proto.Field(proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp,) - update_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) class DeleteOperationMetadata(proto.Message): r"""Details of operations that perform deletes of any entities. + Attributes: generic_metadata (google.cloud.aiplatform_v1beta1.types.GenericOperationMetadata): The common part of the operation metadata. """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message="GenericOperationMetadata", + proto.MESSAGE, + number=1, + message="GenericOperationMetadata", ) diff --git a/google/cloud/aiplatform_v1beta1/types/pipeline_failure_policy.py b/google/cloud/aiplatform_v1beta1/types/pipeline_failure_policy.py new file mode 100644 index 0000000000..d528bce8a1 --- /dev/null +++ b/google/cloud/aiplatform_v1beta1/types/pipeline_failure_policy.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1beta1", + manifest={ + "PipelineFailurePolicy", + }, +) + + +class PipelineFailurePolicy(proto.Enum): + r"""Represents the failure policy of a pipeline. Currently, the default + of a pipeline is that the pipeline will continue to run until no + more tasks can be executed, also known as + PIPELINE_FAILURE_POLICY_FAIL_SLOW. However, if a pipeline is set to + PIPELINE_FAILURE_POLICY_FAIL_FAST, it will stop scheduling any new + tasks when a task has failed. Any scheduled tasks will continue to + completion. + """ + PIPELINE_FAILURE_POLICY_UNSPECIFIED = 0 + PIPELINE_FAILURE_POLICY_FAIL_SLOW = 1 + PIPELINE_FAILURE_POLICY_FAIL_FAST = 2 + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/pipeline_job.py b/google/cloud/aiplatform_v1beta1/types/pipeline_job.py index 120d2ce71f..8b0e7d37a1 100644 --- a/google/cloud/aiplatform_v1beta1/types/pipeline_job.py +++ b/google/cloud/aiplatform_v1beta1/types/pipeline_job.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ from google.cloud.aiplatform_v1beta1.types import context from google.cloud.aiplatform_v1beta1.types import encryption_spec as gca_encryption_spec from google.cloud.aiplatform_v1beta1.types import execution as gca_execution +from google.cloud.aiplatform_v1beta1.types import pipeline_failure_policy from google.cloud.aiplatform_v1beta1.types import pipeline_state from google.cloud.aiplatform_v1beta1.types import value as gca_value from google.protobuf import struct_pb2 # type: ignore @@ -30,6 +31,7 @@ package="google.cloud.aiplatform.v1beta1", manifest={ "PipelineJob", + "PipelineTemplateMetadata", "PipelineJobDetail", "PipelineTaskDetail", "PipelineTaskExecutorDetail", @@ -39,6 +41,7 @@ class PipelineJob(proto.Message): r"""An instance of a machine learning PipelineJob. + Attributes: name (str): Output only. The resource name of the @@ -57,9 +60,7 @@ class PipelineJob(proto.Message): Output only. Timestamp when this PipelineJob was most recently updated. pipeline_spec (google.protobuf.struct_pb2.Struct): - Required. The spec of the pipeline. The spec contains a - ``schema_version`` field which indicates the Kubeflow - Pipeline schema version to decode the struct. + The spec of the pipeline. state (google.cloud.aiplatform_v1beta1.types.PipelineState): Output only. The detailed state of the job. job_detail (google.cloud.aiplatform_v1beta1.types.PipelineJobDetail): @@ -69,7 +70,7 @@ class PipelineJob(proto.Message): Output only. The error that occurred during pipeline execution. Only populated when the pipeline's state is FAILED or CANCELLED. - labels (Sequence[google.cloud.aiplatform_v1beta1.types.PipelineJob.LabelsEntry]): + labels (Mapping[str, str]): The labels with user-defined metadata to organize PipelineJob. Label keys and values can be no longer than 64 @@ -108,18 +109,34 @@ class PipelineJob(proto.Message): Private services access must already be configured for the network. Pipeline job will apply the network configuration to the GCP resources being launched, if applied, such as - Cloud AI Platform Training or Dataflow job. If left - unspecified, the workload is not peered with any network. + Vertex AI Training or Dataflow job. If left unspecified, the + workload is not peered with any network. + template_uri (str): + A template uri from where the + [PipelineJob.pipeline_spec][google.cloud.aiplatform.v1beta1.PipelineJob.pipeline_spec], + if empty, will be downloaded. + template_metadata (google.cloud.aiplatform_v1beta1.types.PipelineTemplateMetadata): + Output only. Pipeline template metadata. Will fill up fields + if + [PipelineJob.template_uri][google.cloud.aiplatform.v1beta1.PipelineJob.template_uri] + is from supported template registry. """ class RuntimeConfig(proto.Message): r"""The runtime config of a PipelineJob. + Attributes: - parameters (Sequence[google.cloud.aiplatform_v1beta1.types.PipelineJob.RuntimeConfig.ParametersEntry]): - The runtime parameters of the PipelineJob. The parameters - will be passed into + parameters (Mapping[str, google.cloud.aiplatform_v1beta1.types.Value]): + Deprecated. Use + [RuntimeConfig.parameter_values][google.cloud.aiplatform.v1beta1.PipelineJob.RuntimeConfig.parameter_values] + instead. The runtime parameters of the PipelineJob. The + parameters will be passed into [PipelineJob.pipeline_spec][google.cloud.aiplatform.v1beta1.PipelineJob.pipeline_spec] - to replace the placeholders at runtime. + to replace the placeholders at runtime. This field is used + by pipelines built using + ``PipelineJob.pipeline_spec.schema_version`` 2.0.0 or lower, + such as pipelines built using Kubeflow Pipelines SDK 1.8 or + lower. gcs_output_directory (str): Required. A path in a Cloud Storage bucket, which will be treated as the root output directory of the pipeline. It is @@ -129,34 +146,155 @@ class RuntimeConfig(proto.Message): specified output directory. The service account specified in this pipeline must have the ``storage.objects.get`` and ``storage.objects.create`` permissions for this bucket. + parameter_values (Mapping[str, google.protobuf.struct_pb2.Value]): + The runtime parameters of the PipelineJob. The parameters + will be passed into + [PipelineJob.pipeline_spec][google.cloud.aiplatform.v1beta1.PipelineJob.pipeline_spec] + to replace the placeholders at runtime. This field is used + by pipelines built using + ``PipelineJob.pipeline_spec.schema_version`` 2.1.0, such as + pipelines built using Kubeflow Pipelines SDK 1.9 or higher + and the v2 DSL. + failure_policy (google.cloud.aiplatform_v1beta1.types.PipelineFailurePolicy): + Represents the failure policy of a pipeline. Currently, the + default of a pipeline is that the pipeline will continue to + run until no more tasks can be executed, also known as + PIPELINE_FAILURE_POLICY_FAIL_SLOW. However, if a pipeline is + set to PIPELINE_FAILURE_POLICY_FAIL_FAST, it will stop + scheduling any new tasks when a task has failed. Any + scheduled tasks will continue to completion. """ parameters = proto.MapField( - proto.STRING, proto.MESSAGE, number=1, message=gca_value.Value, + proto.STRING, + proto.MESSAGE, + number=1, + message=gca_value.Value, + ) + gcs_output_directory = proto.Field( + proto.STRING, + number=2, + ) + parameter_values = proto.MapField( + proto.STRING, + proto.MESSAGE, + number=3, + message=struct_pb2.Value, ) - gcs_output_directory = proto.Field(proto.STRING, number=2,) - - name = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) - create_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) - start_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) - end_time = proto.Field(proto.MESSAGE, number=5, message=timestamp_pb2.Timestamp,) - update_time = proto.Field(proto.MESSAGE, number=6, message=timestamp_pb2.Timestamp,) - pipeline_spec = proto.Field(proto.MESSAGE, number=7, message=struct_pb2.Struct,) - state = proto.Field(proto.ENUM, number=8, enum=pipeline_state.PipelineState,) - job_detail = proto.Field(proto.MESSAGE, number=9, message="PipelineJobDetail",) - error = proto.Field(proto.MESSAGE, number=10, message=status_pb2.Status,) - labels = proto.MapField(proto.STRING, proto.STRING, number=11,) - runtime_config = proto.Field(proto.MESSAGE, number=12, message=RuntimeConfig,) + failure_policy = proto.Field( + proto.ENUM, + number=4, + enum=pipeline_failure_policy.PipelineFailurePolicy, + ) + + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + create_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + start_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + end_time = proto.Field( + proto.MESSAGE, + number=5, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=6, + message=timestamp_pb2.Timestamp, + ) + pipeline_spec = proto.Field( + proto.MESSAGE, + number=7, + message=struct_pb2.Struct, + ) + state = proto.Field( + proto.ENUM, + number=8, + enum=pipeline_state.PipelineState, + ) + job_detail = proto.Field( + proto.MESSAGE, + number=9, + message="PipelineJobDetail", + ) + error = proto.Field( + proto.MESSAGE, + number=10, + message=status_pb2.Status, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=11, + ) + runtime_config = proto.Field( + proto.MESSAGE, + number=12, + message=RuntimeConfig, + ) encryption_spec = proto.Field( - proto.MESSAGE, number=16, message=gca_encryption_spec.EncryptionSpec, + proto.MESSAGE, + number=16, + message=gca_encryption_spec.EncryptionSpec, + ) + service_account = proto.Field( + proto.STRING, + number=17, + ) + network = proto.Field( + proto.STRING, + number=18, + ) + template_uri = proto.Field( + proto.STRING, + number=19, + ) + template_metadata = proto.Field( + proto.MESSAGE, + number=20, + message="PipelineTemplateMetadata", + ) + + +class PipelineTemplateMetadata(proto.Message): + r"""Pipeline template metadata if + [PipelineJob.template_uri][google.cloud.aiplatform.v1beta1.PipelineJob.template_uri] + is from supported template registry. Currently, the only supported + registry is Artifact Registry. + + Attributes: + version (str): + The version_name in artifact registry. + + Will always be presented in output if the + [PipelineJob.template_uri][google.cloud.aiplatform.v1beta1.PipelineJob.template_uri] + is from supported template registry. + + Format is "sha256:abcdef123456...". + """ + + version = proto.Field( + proto.STRING, + number=3, ) - service_account = proto.Field(proto.STRING, number=17,) - network = proto.Field(proto.STRING, number=18,) class PipelineJobDetail(proto.Message): r"""The runtime detail of PipelineJob. + Attributes: pipeline_context (google.cloud.aiplatform_v1beta1.types.Context): Output only. The context of the pipeline. @@ -168,17 +306,26 @@ class PipelineJobDetail(proto.Message): under the pipeline. """ - pipeline_context = proto.Field(proto.MESSAGE, number=1, message=context.Context,) + pipeline_context = proto.Field( + proto.MESSAGE, + number=1, + message=context.Context, + ) pipeline_run_context = proto.Field( - proto.MESSAGE, number=2, message=context.Context, + proto.MESSAGE, + number=2, + message=context.Context, ) task_details = proto.RepeatedField( - proto.MESSAGE, number=3, message="PipelineTaskDetail", + proto.MESSAGE, + number=3, + message="PipelineTaskDetail", ) class PipelineTaskDetail(proto.Message): r"""The runtime detail of a task execution. + Attributes: task_id (int): Output only. The system generated ID of the @@ -207,10 +354,14 @@ class PipelineTaskDetail(proto.Message): Output only. The error that occurred during task execution. Only populated when the task's state is FAILED or CANCELLED. - inputs (Sequence[google.cloud.aiplatform_v1beta1.types.PipelineTaskDetail.InputsEntry]): + pipeline_task_status (Sequence[google.cloud.aiplatform_v1beta1.types.PipelineTaskDetail.PipelineTaskStatus]): + Output only. A list of task status. This + field keeps a record of task status evolving + over time. + inputs (Mapping[str, google.cloud.aiplatform_v1beta1.types.PipelineTaskDetail.ArtifactList]): Output only. The runtime input artifacts of the task. - outputs (Sequence[google.cloud.aiplatform_v1beta1.types.PipelineTaskDetail.OutputsEntry]): + outputs (Mapping[str, google.cloud.aiplatform_v1beta1.types.PipelineTaskDetail.ArtifactList]): Output only. The runtime output artifacts of the task. """ @@ -228,46 +379,141 @@ class State(proto.Enum): SKIPPED = 8 NOT_TRIGGERED = 9 + class PipelineTaskStatus(proto.Message): + r"""A single record of the task status. + + Attributes: + update_time (google.protobuf.timestamp_pb2.Timestamp): + Output only. Update time of this status. + state (google.cloud.aiplatform_v1beta1.types.PipelineTaskDetail.State): + Output only. The state of the task. + error (google.rpc.status_pb2.Status): + Output only. The error that occurred during + the state. May be set when the state is any of + the non-final state (PENDING/RUNNING/CANCELLING) + or FAILED state. If the state is FAILED, the + error here is final and not going to be retried. + If the state is a non-final state, the error + indicates a system-error being retried. + """ + + update_time = proto.Field( + proto.MESSAGE, + number=1, + message=timestamp_pb2.Timestamp, + ) + state = proto.Field( + proto.ENUM, + number=2, + enum="PipelineTaskDetail.State", + ) + error = proto.Field( + proto.MESSAGE, + number=3, + message=status_pb2.Status, + ) + class ArtifactList(proto.Message): r"""A list of artifact metadata. + Attributes: artifacts (Sequence[google.cloud.aiplatform_v1beta1.types.Artifact]): Output only. A list of artifact metadata. """ artifacts = proto.RepeatedField( - proto.MESSAGE, number=1, message=artifact.Artifact, + proto.MESSAGE, + number=1, + message=artifact.Artifact, ) - task_id = proto.Field(proto.INT64, number=1,) - parent_task_id = proto.Field(proto.INT64, number=12,) - task_name = proto.Field(proto.STRING, number=2,) - create_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) - start_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) - end_time = proto.Field(proto.MESSAGE, number=5, message=timestamp_pb2.Timestamp,) + task_id = proto.Field( + proto.INT64, + number=1, + ) + parent_task_id = proto.Field( + proto.INT64, + number=12, + ) + task_name = proto.Field( + proto.STRING, + number=2, + ) + create_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + start_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + end_time = proto.Field( + proto.MESSAGE, + number=5, + message=timestamp_pb2.Timestamp, + ) executor_detail = proto.Field( - proto.MESSAGE, number=6, message="PipelineTaskExecutorDetail", + proto.MESSAGE, + number=6, + message="PipelineTaskExecutorDetail", + ) + state = proto.Field( + proto.ENUM, + number=7, + enum=State, + ) + execution = proto.Field( + proto.MESSAGE, + number=8, + message=gca_execution.Execution, + ) + error = proto.Field( + proto.MESSAGE, + number=9, + message=status_pb2.Status, + ) + pipeline_task_status = proto.RepeatedField( + proto.MESSAGE, + number=13, + message=PipelineTaskStatus, ) - state = proto.Field(proto.ENUM, number=7, enum=State,) - execution = proto.Field(proto.MESSAGE, number=8, message=gca_execution.Execution,) - error = proto.Field(proto.MESSAGE, number=9, message=status_pb2.Status,) inputs = proto.MapField( - proto.STRING, proto.MESSAGE, number=10, message=ArtifactList, + proto.STRING, + proto.MESSAGE, + number=10, + message=ArtifactList, ) outputs = proto.MapField( - proto.STRING, proto.MESSAGE, number=11, message=ArtifactList, + proto.STRING, + proto.MESSAGE, + number=11, + message=ArtifactList, ) class PipelineTaskExecutorDetail(proto.Message): r"""The runtime detail of a pipeline executor. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: container_detail (google.cloud.aiplatform_v1beta1.types.PipelineTaskExecutorDetail.ContainerDetail): Output only. The detailed info for a container executor. + + This field is a member of `oneof`_ ``details``. custom_job_detail (google.cloud.aiplatform_v1beta1.types.PipelineTaskExecutorDetail.CustomJobDetail): Output only. The detailed info for a custom job executor. + + This field is a member of `oneof`_ ``details``. """ class ContainerDetail(proto.Message): @@ -289,24 +535,40 @@ class ContainerDetail(proto.Message): events. """ - main_job = proto.Field(proto.STRING, number=1,) - pre_caching_check_job = proto.Field(proto.STRING, number=2,) + main_job = proto.Field( + proto.STRING, + number=1, + ) + pre_caching_check_job = proto.Field( + proto.STRING, + number=2, + ) class CustomJobDetail(proto.Message): r"""The detailed info for a custom job executor. + Attributes: job (str): Output only. The name of the [CustomJob][google.cloud.aiplatform.v1beta1.CustomJob]. """ - job = proto.Field(proto.STRING, number=1,) + job = proto.Field( + proto.STRING, + number=1, + ) container_detail = proto.Field( - proto.MESSAGE, number=1, oneof="details", message=ContainerDetail, + proto.MESSAGE, + number=1, + oneof="details", + message=ContainerDetail, ) custom_job_detail = proto.Field( - proto.MESSAGE, number=2, oneof="details", message=CustomJobDetail, + proto.MESSAGE, + number=2, + oneof="details", + message=CustomJobDetail, ) diff --git a/google/cloud/aiplatform_v1beta1/types/pipeline_service.py b/google/cloud/aiplatform_v1beta1/types/pipeline_service.py index f2ba495371..3a084f10b6 100644 --- a/google/cloud/aiplatform_v1beta1/types/pipeline_service.py +++ b/google/cloud/aiplatform_v1beta1/types/pipeline_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -54,9 +54,14 @@ class CreateTrainingPipelineRequest(proto.Message): Required. The TrainingPipeline to create. """ - parent = proto.Field(proto.STRING, number=1,) + parent = proto.Field( + proto.STRING, + number=1, + ) training_pipeline = proto.Field( - proto.MESSAGE, number=2, message=gca_training_pipeline.TrainingPipeline, + proto.MESSAGE, + number=2, + message=gca_training_pipeline.TrainingPipeline, ) @@ -70,7 +75,10 @@ class GetTrainingPipelineRequest(proto.Message): ``projects/{project}/locations/{location}/trainingPipelines/{training_pipeline}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListTrainingPipelinesRequest(proto.Message): @@ -110,11 +118,27 @@ class ListTrainingPipelinesRequest(proto.Message): Mask specifying which fields to read. """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) - read_mask = proto.Field(proto.MESSAGE, number=5, message=field_mask_pb2.FieldMask,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=5, + message=field_mask_pb2.FieldMask, + ) class ListTrainingPipelinesResponse(proto.Message): @@ -136,9 +160,14 @@ def raw_page(self): return self training_pipelines = proto.RepeatedField( - proto.MESSAGE, number=1, message=gca_training_pipeline.TrainingPipeline, + proto.MESSAGE, + number=1, + message=gca_training_pipeline.TrainingPipeline, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class DeleteTrainingPipelineRequest(proto.Message): @@ -152,7 +181,10 @@ class DeleteTrainingPipelineRequest(proto.Message): ``projects/{project}/locations/{location}/trainingPipelines/{training_pipeline}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class CancelTrainingPipelineRequest(proto.Message): @@ -166,7 +198,10 @@ class CancelTrainingPipelineRequest(proto.Message): ``projects/{project}/locations/{location}/trainingPipelines/{training_pipeline}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class CreatePipelineJobRequest(proto.Message): @@ -189,11 +224,19 @@ class CreatePipelineJobRequest(proto.Message): characters are /[a-z][0-9]-/. """ - parent = proto.Field(proto.STRING, number=1,) + parent = proto.Field( + proto.STRING, + number=1, + ) pipeline_job = proto.Field( - proto.MESSAGE, number=2, message=gca_pipeline_job.PipelineJob, + proto.MESSAGE, + number=2, + message=gca_pipeline_job.PipelineJob, + ) + pipeline_job_id = proto.Field( + proto.STRING, + number=3, ) - pipeline_job_id = proto.Field(proto.STRING, number=3,) class GetPipelineJobRequest(proto.Message): @@ -206,7 +249,10 @@ class GetPipelineJobRequest(proto.Message): ``projects/{project}/locations/{location}/pipelineJobs/{pipeline_job}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListPipelineJobsRequest(proto.Message): @@ -219,17 +265,46 @@ class ListPipelineJobsRequest(proto.Message): PipelineJobs from. Format: ``projects/{project}/locations/{location}`` filter (str): - The standard list filter. Supported fields: - - - ``display_name`` supports = and !=. - - ``state`` supports = and !=. - - Some examples of using the filter are: - - - ``state="PIPELINE_STATE_SUCCEEDED" AND display_name="my_pipeline"`` - - ``state="PIPELINE_STATE_RUNNING" OR display_name="my_pipeline"`` - - ``NOT display_name="my_pipeline"`` - - ``state="PIPELINE_STATE_FAILED"`` + Lists the PipelineJobs that match the filter expression. The + following fields are supported: + + - ``pipeline_name``: Supports ``=`` and ``!=`` comparisons. + - ``display_name``: Supports ``=``, ``!=`` comparisons, and + ``:`` wildcard. + - ``pipeline_job_user_id``: Supports ``=``, ``!=`` + comparisons, and ``:`` wildcard. for example, can check + if pipeline's display_name contains *step* by doing + display_name:"*step*" + - ``state``: Supports ``=`` and ``!=`` comparisons. + - ``create_time``: Supports ``=``, ``!=``, ``<``, ``>``, + ``<=``, and ``>=`` comparisons. Values must be in RFC + 3339 format. + - ``update_time``: Supports ``=``, ``!=``, ``<``, ``>``, + ``<=``, and ``>=`` comparisons. Values must be in RFC + 3339 format. + - ``end_time``: Supports ``=``, ``!=``, ``<``, ``>``, + ``<=``, and ``>=`` comparisons. Values must be in RFC + 3339 format. + - ``labels``: Supports key-value equality and key presence. + - ``template_uri``: Supports ``=``, ``!=`` comparisons, and + ``:`` wildcard. + - ``template_metadata.version``: Supports ``=``, ``!=`` + comparisons, and ``:`` wildcard. + + Filter expressions can be combined together using logical + operators (``AND`` & ``OR``). For example: + ``pipeline_name="test" AND create_time>"2020-05-18T13:30:00Z"``. + + The syntax to define filter expression is based on + https://google.aip.dev/160. + + Examples: + + - ``create_time>"2021-05-18T00:00:00Z" OR update_time>"2020-05-18T00:00:00Z"`` + PipelineJobs created or updated after 2020-05-18 00:00:00 + UTC. + - ``labels.env = "prod"`` PipelineJobs with label "env" set + to "prod". page_size (int): The standard list page size. page_token (str): @@ -238,12 +313,45 @@ class ListPipelineJobsRequest(proto.Message): of the previous [PipelineService.ListPipelineJobs][google.cloud.aiplatform.v1beta1.PipelineService.ListPipelineJobs] call. + order_by (str): + A comma-separated list of fields to order by. The default + sort order is in ascending order. Use "desc" after a field + name for descending. You can have multiple order_by fields + provided e.g. "create_time desc, end_time", "end_time, + start_time, update_time" For example, using "create_time + desc, end_time" will order results by create time in + descending order, and if there are multiple jobs having the + same create time, order them by the end time in ascending + order. if order_by is not specified, it will order by + default order is create time in descending order. Supported + fields: + + - ``create_time`` + - ``update_time`` + - ``end_time`` + - ``start_time`` """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + order_by = proto.Field( + proto.STRING, + number=6, + ) class ListPipelineJobsResponse(proto.Message): @@ -264,9 +372,14 @@ def raw_page(self): return self pipeline_jobs = proto.RepeatedField( - proto.MESSAGE, number=1, message=gca_pipeline_job.PipelineJob, + proto.MESSAGE, + number=1, + message=gca_pipeline_job.PipelineJob, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class DeletePipelineJobRequest(proto.Message): @@ -280,7 +393,10 @@ class DeletePipelineJobRequest(proto.Message): ``projects/{project}/locations/{location}/pipelineJobs/{pipeline_job}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class CancelPipelineJobRequest(proto.Message): @@ -293,7 +409,10 @@ class CancelPipelineJobRequest(proto.Message): ``projects/{project}/locations/{location}/pipelineJobs/{pipeline_job}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/pipeline_state.py b/google/cloud/aiplatform_v1beta1/types/pipeline_state.py index c8e864640e..2d2659b344 100644 --- a/google/cloud/aiplatform_v1beta1/types/pipeline_state.py +++ b/google/cloud/aiplatform_v1beta1/types/pipeline_state.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,7 +17,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"PipelineState",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "PipelineState", + }, ) diff --git a/google/cloud/aiplatform_v1beta1/types/prediction_service.py b/google/cloud/aiplatform_v1beta1/types/prediction_service.py index 669b28a66a..3d9a520ad9 100644 --- a/google/cloud/aiplatform_v1beta1/types/prediction_service.py +++ b/google/cloud/aiplatform_v1beta1/types/prediction_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,6 +15,7 @@ # import proto # type: ignore +from google.api import httpbody_pb2 # type: ignore from google.cloud.aiplatform_v1beta1.types import explanation from google.protobuf import struct_pb2 # type: ignore @@ -24,6 +25,7 @@ manifest={ "PredictRequest", "PredictResponse", + "RawPredictRequest", "ExplainRequest", "ExplainResponse", }, @@ -60,9 +62,20 @@ class PredictRequest(proto.Message): [parameters_schema_uri][google.cloud.aiplatform.v1beta1.PredictSchemata.parameters_schema_uri]. """ - endpoint = proto.Field(proto.STRING, number=1,) - instances = proto.RepeatedField(proto.MESSAGE, number=2, message=struct_pb2.Value,) - parameters = proto.Field(proto.MESSAGE, number=3, message=struct_pb2.Value,) + endpoint = proto.Field( + proto.STRING, + number=1, + ) + instances = proto.RepeatedField( + proto.MESSAGE, + number=2, + message=struct_pb2.Value, + ) + parameters = proto.Field( + proto.MESSAGE, + number=3, + message=struct_pb2.Value, + ) class PredictResponse(proto.Message): @@ -80,12 +93,85 @@ class PredictResponse(proto.Message): deployed_model_id (str): ID of the Endpoint's DeployedModel that served this prediction. + model (str): + Output only. The resource name of the Model + which is deployed as the DeployedModel that this + prediction hits. + model_version_id (str): + Output only. The version ID of the Model + which is deployed as the DeployedModel that this + prediction hits. + model_display_name (str): + Output only. The [display + name][google.cloud.aiplatform.v1beta1.Model.display_name] of + the Model which is deployed as the DeployedModel that this + prediction hits. """ predictions = proto.RepeatedField( - proto.MESSAGE, number=1, message=struct_pb2.Value, + proto.MESSAGE, + number=1, + message=struct_pb2.Value, + ) + deployed_model_id = proto.Field( + proto.STRING, + number=2, + ) + model = proto.Field( + proto.STRING, + number=3, + ) + model_version_id = proto.Field( + proto.STRING, + number=5, + ) + model_display_name = proto.Field( + proto.STRING, + number=4, + ) + + +class RawPredictRequest(proto.Message): + r"""Request message for + [PredictionService.RawPredict][google.cloud.aiplatform.v1beta1.PredictionService.RawPredict]. + + Attributes: + endpoint (str): + Required. The name of the Endpoint requested to serve the + prediction. Format: + ``projects/{project}/locations/{location}/endpoints/{endpoint}`` + http_body (google.api.httpbody_pb2.HttpBody): + The prediction input. Supports HTTP headers and arbitrary + data payload. + + A + [DeployedModel][google.cloud.aiplatform.v1beta1.DeployedModel] + may have an upper limit on the number of instances it + supports per request. When this limit it is exceeded for an + AutoML model, the + [RawPredict][google.cloud.aiplatform.v1beta1.PredictionService.RawPredict] + method returns an error. When this limit is exceeded for a + custom-trained model, the behavior varies depending on the + model. + + You can specify the schema for each instance in the + [predict_schemata.instance_schema_uri][google.cloud.aiplatform.v1beta1.PredictSchemata.instance_schema_uri] + field when you create a + [Model][google.cloud.aiplatform.v1beta1.Model]. This schema + applies when you deploy the ``Model`` as a ``DeployedModel`` + to an [Endpoint][google.cloud.aiplatform.v1beta1.Endpoint] + and use the ``RawPredict`` method. + """ + + endpoint = proto.Field( + proto.STRING, + number=1, + ) + http_body = proto.Field( + proto.MESSAGE, + number=2, + message=httpbody_pb2.HttpBody, ) - deployed_model_id = proto.Field(proto.STRING, number=2,) class ExplainRequest(proto.Message): @@ -133,13 +219,29 @@ class ExplainRequest(proto.Message): [Endpoint.traffic_split][google.cloud.aiplatform.v1beta1.Endpoint.traffic_split]. """ - endpoint = proto.Field(proto.STRING, number=1,) - instances = proto.RepeatedField(proto.MESSAGE, number=2, message=struct_pb2.Value,) - parameters = proto.Field(proto.MESSAGE, number=4, message=struct_pb2.Value,) + endpoint = proto.Field( + proto.STRING, + number=1, + ) + instances = proto.RepeatedField( + proto.MESSAGE, + number=2, + message=struct_pb2.Value, + ) + parameters = proto.Field( + proto.MESSAGE, + number=4, + message=struct_pb2.Value, + ) explanation_spec_override = proto.Field( - proto.MESSAGE, number=5, message=explanation.ExplanationSpecOverride, + proto.MESSAGE, + number=5, + message=explanation.ExplanationSpecOverride, + ) + deployed_model_id = proto.Field( + proto.STRING, + number=3, ) - deployed_model_id = proto.Field(proto.STRING, number=3,) class ExplainResponse(proto.Message): @@ -164,11 +266,18 @@ class ExplainResponse(proto.Message): """ explanations = proto.RepeatedField( - proto.MESSAGE, number=1, message=explanation.Explanation, + proto.MESSAGE, + number=1, + message=explanation.Explanation, + ) + deployed_model_id = proto.Field( + proto.STRING, + number=2, ) - deployed_model_id = proto.Field(proto.STRING, number=2,) predictions = proto.RepeatedField( - proto.MESSAGE, number=3, message=struct_pb2.Value, + proto.MESSAGE, + number=3, + message=struct_pb2.Value, ) diff --git a/google/cloud/aiplatform_v1beta1/types/specialist_pool.py b/google/cloud/aiplatform_v1beta1/types/specialist_pool.py index 0e7fe971e9..ae31ca518e 100644 --- a/google/cloud/aiplatform_v1beta1/types/specialist_pool.py +++ b/google/cloud/aiplatform_v1beta1/types/specialist_pool.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,19 +17,21 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"SpecialistPool",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "SpecialistPool", + }, ) class SpecialistPool(proto.Message): r"""SpecialistPool represents customers' own workforce to work on their data labeling jobs. It includes a group of specialist - managers who are responsible for managing the labelers in this - pool as well as customers' data labeling jobs associated with - this pool. - Customers create specialist pool as well as start data labeling - jobs on Cloud, managers and labelers work with the jobs using - CrowdCompute console. + managers and workers. Managers are responsible for managing the + workers in this pool as well as customers' data labeling jobs + associated with this pool. Customers create specialist pool as + well as start data labeling jobs on Cloud, managers and workers + handle the jobs using CrowdCompute console. Attributes: name (str): @@ -42,21 +44,43 @@ class SpecialistPool(proto.Message): characters. This field should be unique on project-level. specialist_managers_count (int): - Output only. The number of Specialists in - this SpecialistPool. + Output only. The number of managers in this + SpecialistPool. specialist_manager_emails (Sequence[str]): - The email addresses of the specialists in the + The email addresses of the managers in the SpecialistPool. pending_data_labeling_jobs (Sequence[str]): Output only. The resource name of the pending data labeling jobs. + specialist_worker_emails (Sequence[str]): + The email addresses of workers in the + SpecialistPool. """ - name = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) - specialist_managers_count = proto.Field(proto.INT32, number=3,) - specialist_manager_emails = proto.RepeatedField(proto.STRING, number=4,) - pending_data_labeling_jobs = proto.RepeatedField(proto.STRING, number=5,) + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + specialist_managers_count = proto.Field( + proto.INT32, + number=3, + ) + specialist_manager_emails = proto.RepeatedField( + proto.STRING, + number=4, + ) + pending_data_labeling_jobs = proto.RepeatedField( + proto.STRING, + number=5, + ) + specialist_worker_emails = proto.RepeatedField( + proto.STRING, + number=7, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/specialist_pool_service.py b/google/cloud/aiplatform_v1beta1/types/specialist_pool_service.py index 09d93d1c16..c8b24caff4 100644 --- a/google/cloud/aiplatform_v1beta1/types/specialist_pool_service.py +++ b/google/cloud/aiplatform_v1beta1/types/specialist_pool_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -48,9 +48,14 @@ class CreateSpecialistPoolRequest(proto.Message): Required. The SpecialistPool to create. """ - parent = proto.Field(proto.STRING, number=1,) + parent = proto.Field( + proto.STRING, + number=1, + ) specialist_pool = proto.Field( - proto.MESSAGE, number=2, message=gca_specialist_pool.SpecialistPool, + proto.MESSAGE, + number=2, + message=gca_specialist_pool.SpecialistPool, ) @@ -64,7 +69,9 @@ class CreateSpecialistPoolOperationMetadata(proto.Message): """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, ) @@ -79,7 +86,10 @@ class GetSpecialistPoolRequest(proto.Message): ``projects/{project}/locations/{location}/specialistPools/{specialist_pool}``. """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListSpecialistPoolsRequest(proto.Message): @@ -103,10 +113,23 @@ class ListSpecialistPoolsRequest(proto.Message): FieldMask represents a set of """ - parent = proto.Field(proto.STRING, number=1,) - page_size = proto.Field(proto.INT32, number=2,) - page_token = proto.Field(proto.STRING, number=3,) - read_mask = proto.Field(proto.MESSAGE, number=4, message=field_mask_pb2.FieldMask,) + parent = proto.Field( + proto.STRING, + number=1, + ) + page_size = proto.Field( + proto.INT32, + number=2, + ) + page_token = proto.Field( + proto.STRING, + number=3, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=4, + message=field_mask_pb2.FieldMask, + ) class ListSpecialistPoolsResponse(proto.Message): @@ -126,9 +149,14 @@ def raw_page(self): return self specialist_pools = proto.RepeatedField( - proto.MESSAGE, number=1, message=gca_specialist_pool.SpecialistPool, + proto.MESSAGE, + number=1, + message=gca_specialist_pool.SpecialistPool, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class DeleteSpecialistPoolRequest(proto.Message): @@ -147,8 +175,14 @@ class DeleteSpecialistPoolRequest(proto.Message): SpecialistPool has no specialist managers.) """ - name = proto.Field(proto.STRING, number=1,) - force = proto.Field(proto.BOOL, number=2,) + name = proto.Field( + proto.STRING, + number=1, + ) + force = proto.Field( + proto.BOOL, + number=2, + ) class UpdateSpecialistPoolRequest(proto.Message): @@ -165,10 +199,14 @@ class UpdateSpecialistPoolRequest(proto.Message): """ specialist_pool = proto.Field( - proto.MESSAGE, number=1, message=gca_specialist_pool.SpecialistPool, + proto.MESSAGE, + number=1, + message=gca_specialist_pool.SpecialistPool, ) update_mask = proto.Field( - proto.MESSAGE, number=2, message=field_mask_pb2.FieldMask, + proto.MESSAGE, + number=2, + message=field_mask_pb2.FieldMask, ) @@ -185,9 +223,14 @@ class UpdateSpecialistPoolOperationMetadata(proto.Message): The operation generic information. """ - specialist_pool = proto.Field(proto.STRING, number=1,) + specialist_pool = proto.Field( + proto.STRING, + number=1, + ) generic_metadata = proto.Field( - proto.MESSAGE, number=2, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=2, + message=operation.GenericOperationMetadata, ) diff --git a/google/cloud/aiplatform_v1beta1/types/study.py b/google/cloud/aiplatform_v1beta1/types/study.py index 63e58e5f42..8e122d12a4 100644 --- a/google/cloud/aiplatform_v1beta1/types/study.py +++ b/google/cloud/aiplatform_v1beta1/types/study.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -22,12 +22,18 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1", - manifest={"Study", "Trial", "StudySpec", "Measurement",}, + manifest={ + "Study", + "Trial", + "StudySpec", + "Measurement", + }, ) class Study(proto.Message): r"""A message representing a Study. + Attributes: name (str): Output only. The name of a study. The study's globally @@ -56,12 +62,33 @@ class State(proto.Enum): INACTIVE = 2 COMPLETED = 3 - name = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) - study_spec = proto.Field(proto.MESSAGE, number=3, message="StudySpec",) - state = proto.Field(proto.ENUM, number=4, enum=State,) - create_time = proto.Field(proto.MESSAGE, number=5, message=timestamp_pb2.Timestamp,) - inactive_reason = proto.Field(proto.STRING, number=6,) + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + study_spec = proto.Field( + proto.MESSAGE, + number=3, + message="StudySpec", + ) + state = proto.Field( + proto.ENUM, + number=4, + enum=State, + ) + create_time = proto.Field( + proto.MESSAGE, + number=5, + message=timestamp_pb2.Timestamp, + ) + inactive_reason = proto.Field( + proto.STRING, + number=6, + ) class Trial(proto.Message): @@ -96,13 +123,14 @@ class Trial(proto.Message): client_id (str): Output only. The identifier of the client that originally requested this Trial. Each client is identified by a unique - client_id. When a client asks for a suggestion, Vizier will - assign it a Trial. The client should evaluate the Trial, - complete it, and report back to Vizier. If suggestion is - asked again by same client_id before the Trial is completed, - the same Trial will be returned. Multiple clients with - different client_ids can ask for suggestions simultaneously, - each of them will get their own Trial. + client_id. When a client asks for a suggestion, Vertex AI + Vizier will assign it a Trial. The client should evaluate + the Trial, complete it, and report back to Vertex AI Vizier. + If suggestion is asked again by same client_id before the + Trial is completed, the same Trial will be returned. + Multiple clients with different client_ids can ask for + suggestions simultaneously, each of them will get their own + Trial. infeasible_reason (str): Output only. A human readable string describing why the Trial is infeasible. This is set only if Trial state is @@ -111,6 +139,23 @@ class Trial(proto.Message): Output only. The CustomJob name linked to the Trial. It's set for a HyperparameterTuningJob's Trial. + web_access_uris (Mapping[str, str]): + Output only. URIs for accessing `interactive + shells `__ + (one URI for each training node). Only available if this + trial is part of a + [HyperparameterTuningJob][google.cloud.aiplatform.v1beta1.HyperparameterTuningJob] + and the job's + [trial_job_spec.enable_web_access][google.cloud.aiplatform.v1beta1.CustomJobSpec.enable_web_access] + field is ``true``. + + The keys are names of each node used for the trial; for + example, ``workerpool0-0`` for the primary node, + ``workerpool1-0`` for the first node in the second worker + pool, and ``workerpool1-1`` for the second node in the + second worker pool. + + The values are the URIs for each node's interactive shell. """ class State(proto.Enum): @@ -124,6 +169,7 @@ class State(proto.Enum): class Parameter(proto.Message): r"""A message representing a parameter to be tuned. + Attributes: parameter_id (str): Output only. The ID of the parameter. The parameter should @@ -137,34 +183,105 @@ class Parameter(proto.Message): 'CATEGORICAL'. """ - parameter_id = proto.Field(proto.STRING, number=1,) - value = proto.Field(proto.MESSAGE, number=2, message=struct_pb2.Value,) + parameter_id = proto.Field( + proto.STRING, + number=1, + ) + value = proto.Field( + proto.MESSAGE, + number=2, + message=struct_pb2.Value, + ) - name = proto.Field(proto.STRING, number=1,) - id = proto.Field(proto.STRING, number=2,) - state = proto.Field(proto.ENUM, number=3, enum=State,) - parameters = proto.RepeatedField(proto.MESSAGE, number=4, message=Parameter,) - final_measurement = proto.Field(proto.MESSAGE, number=5, message="Measurement",) - measurements = proto.RepeatedField(proto.MESSAGE, number=6, message="Measurement",) - start_time = proto.Field(proto.MESSAGE, number=7, message=timestamp_pb2.Timestamp,) - end_time = proto.Field(proto.MESSAGE, number=8, message=timestamp_pb2.Timestamp,) - client_id = proto.Field(proto.STRING, number=9,) - infeasible_reason = proto.Field(proto.STRING, number=10,) - custom_job = proto.Field(proto.STRING, number=11,) + name = proto.Field( + proto.STRING, + number=1, + ) + id = proto.Field( + proto.STRING, + number=2, + ) + state = proto.Field( + proto.ENUM, + number=3, + enum=State, + ) + parameters = proto.RepeatedField( + proto.MESSAGE, + number=4, + message=Parameter, + ) + final_measurement = proto.Field( + proto.MESSAGE, + number=5, + message="Measurement", + ) + measurements = proto.RepeatedField( + proto.MESSAGE, + number=6, + message="Measurement", + ) + start_time = proto.Field( + proto.MESSAGE, + number=7, + message=timestamp_pb2.Timestamp, + ) + end_time = proto.Field( + proto.MESSAGE, + number=8, + message=timestamp_pb2.Timestamp, + ) + client_id = proto.Field( + proto.STRING, + number=9, + ) + infeasible_reason = proto.Field( + proto.STRING, + number=10, + ) + custom_job = proto.Field( + proto.STRING, + number=11, + ) + web_access_uris = proto.MapField( + proto.STRING, + proto.STRING, + number=12, + ) class StudySpec(proto.Message): r"""Represents specification of a Study. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: decay_curve_stopping_spec (google.cloud.aiplatform_v1beta1.types.StudySpec.DecayCurveAutomatedStoppingSpec): The automated early stopping spec using decay curve rule. + + This field is a member of `oneof`_ ``automated_stopping_spec``. median_automated_stopping_spec (google.cloud.aiplatform_v1beta1.types.StudySpec.MedianAutomatedStoppingSpec): The automated early stopping spec using median rule. + + This field is a member of `oneof`_ ``automated_stopping_spec``. convex_stop_config (google.cloud.aiplatform_v1beta1.types.StudySpec.ConvexStopConfig): + Deprecated. The automated early stopping using convex stopping rule. + + This field is a member of `oneof`_ ``automated_stopping_spec``. + convex_automated_stopping_spec (google.cloud.aiplatform_v1beta1.types.StudySpec.ConvexAutomatedStoppingSpec): + The automated early stopping spec using + convex stopping rule. + + This field is a member of `oneof`_ ``automated_stopping_spec``. metrics (Sequence[google.cloud.aiplatform_v1beta1.types.StudySpec.MetricSpec]): Required. Metric specs for the Study. parameters (Sequence[google.cloud.aiplatform_v1beta1.types.StudySpec.ParameterSpec]): @@ -173,9 +290,9 @@ class StudySpec(proto.Message): The search algorithm specified for the Study. observation_noise (google.cloud.aiplatform_v1beta1.types.StudySpec.ObservationNoise): The observation noise level of the study. - Currently only supported by the Vizier service. - Not supported by HyperparamterTuningJob or - TrainingPipeline. + Currently only supported by the Vertex AI Vizier + service. Not supported by HyperparamterTuningJob + or TrainingPipeline. measurement_selection_type (google.cloud.aiplatform_v1beta1.types.StudySpec.MeasurementSelectionType): Describe which measurement selection type will be used @@ -216,6 +333,7 @@ class MeasurementSelectionType(proto.Enum): class MetricSpec(proto.Message): r"""Represents a metric to optimize. + Attributes: metric_id (str): Required. The ID of the metric. Must not @@ -232,20 +350,43 @@ class GoalType(proto.Enum): MAXIMIZE = 1 MINIMIZE = 2 - metric_id = proto.Field(proto.STRING, number=1,) - goal = proto.Field(proto.ENUM, number=2, enum="StudySpec.MetricSpec.GoalType",) + metric_id = proto.Field( + proto.STRING, + number=1, + ) + goal = proto.Field( + proto.ENUM, + number=2, + enum="StudySpec.MetricSpec.GoalType", + ) class ParameterSpec(proto.Message): r"""Represents a single parameter to optimize. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: double_value_spec (google.cloud.aiplatform_v1beta1.types.StudySpec.ParameterSpec.DoubleValueSpec): The value spec for a 'DOUBLE' parameter. + + This field is a member of `oneof`_ ``parameter_value_spec``. integer_value_spec (google.cloud.aiplatform_v1beta1.types.StudySpec.ParameterSpec.IntegerValueSpec): The value spec for an 'INTEGER' parameter. + + This field is a member of `oneof`_ ``parameter_value_spec``. categorical_value_spec (google.cloud.aiplatform_v1beta1.types.StudySpec.ParameterSpec.CategoricalValueSpec): The value spec for a 'CATEGORICAL' parameter. + + This field is a member of `oneof`_ ``parameter_value_spec``. discrete_value_spec (google.cloud.aiplatform_v1beta1.types.StudySpec.ParameterSpec.DiscreteValueSpec): The value spec for a 'DISCRETE' parameter. + + This field is a member of `oneof`_ ``parameter_value_spec``. parameter_id (str): Required. The ID of the parameter. Must not contain whitespaces and must be unique amongst @@ -270,6 +411,7 @@ class ScaleType(proto.Enum): class DoubleValueSpec(proto.Message): r"""Value specification for a parameter in ``DOUBLE`` type. + Attributes: min_value (float): Required. Inclusive minimum value of the @@ -277,13 +419,34 @@ class DoubleValueSpec(proto.Message): max_value (float): Required. Inclusive maximum value of the parameter. + default_value (float): + A default value for a ``DOUBLE`` parameter that is assumed + to be a relatively good starting point. Unset value signals + that there is no offered starting point. + + Currently only supported by the Vertex AI Vizier service. + Not supported by HyperparamterTuningJob or TrainingPipeline. + + This field is a member of `oneof`_ ``_default_value``. """ - min_value = proto.Field(proto.DOUBLE, number=1,) - max_value = proto.Field(proto.DOUBLE, number=2,) + min_value = proto.Field( + proto.DOUBLE, + number=1, + ) + max_value = proto.Field( + proto.DOUBLE, + number=2, + ) + default_value = proto.Field( + proto.DOUBLE, + number=4, + optional=True, + ) class IntegerValueSpec(proto.Message): r"""Value specification for a parameter in ``INTEGER`` type. + Attributes: min_value (int): Required. Inclusive minimum value of the @@ -291,22 +454,61 @@ class IntegerValueSpec(proto.Message): max_value (int): Required. Inclusive maximum value of the parameter. + default_value (int): + A default value for an ``INTEGER`` parameter that is assumed + to be a relatively good starting point. Unset value signals + that there is no offered starting point. + + Currently only supported by the Vertex AI Vizier service. + Not supported by HyperparamterTuningJob or TrainingPipeline. + + This field is a member of `oneof`_ ``_default_value``. """ - min_value = proto.Field(proto.INT64, number=1,) - max_value = proto.Field(proto.INT64, number=2,) + min_value = proto.Field( + proto.INT64, + number=1, + ) + max_value = proto.Field( + proto.INT64, + number=2, + ) + default_value = proto.Field( + proto.INT64, + number=4, + optional=True, + ) class CategoricalValueSpec(proto.Message): r"""Value specification for a parameter in ``CATEGORICAL`` type. + Attributes: values (Sequence[str]): Required. The list of possible categories. + default_value (str): + A default value for a ``CATEGORICAL`` parameter that is + assumed to be a relatively good starting point. Unset value + signals that there is no offered starting point. + + Currently only supported by the Vizier service. Not + supported by HyperparamterTuningJob or TrainingPipeline. + + This field is a member of `oneof`_ ``_default_value``. """ - values = proto.RepeatedField(proto.STRING, number=1,) + values = proto.RepeatedField( + proto.STRING, + number=1, + ) + default_value = proto.Field( + proto.STRING, + number=3, + optional=True, + ) class DiscreteValueSpec(proto.Message): r"""Value specification for a parameter in ``DISCRETE`` type. + Attributes: values (Sequence[float]): Required. A list of possible values. @@ -315,24 +517,55 @@ class DiscreteValueSpec(proto.Message): might have possible settings of 1.5, 2.5, and 4.0. This list should not contain more than 1,000 values. + default_value (float): + A default value for a ``DISCRETE`` parameter that is assumed + to be a relatively good starting point. Unset value signals + that there is no offered starting point. It automatically + rounds to the nearest feasible discrete point. + + Currently only supported by the Vizier service. Not + supported by HyperparamterTuningJob or TrainingPipeline. + + This field is a member of `oneof`_ ``_default_value``. """ - values = proto.RepeatedField(proto.DOUBLE, number=1,) + values = proto.RepeatedField( + proto.DOUBLE, + number=1, + ) + default_value = proto.Field( + proto.DOUBLE, + number=3, + optional=True, + ) class ConditionalParameterSpec(proto.Message): r"""Represents a parameter spec with condition from its parent parameter. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: parent_discrete_values (google.cloud.aiplatform_v1beta1.types.StudySpec.ParameterSpec.ConditionalParameterSpec.DiscreteValueCondition): The spec for matching values from a parent parameter of ``DISCRETE`` type. + + This field is a member of `oneof`_ ``parent_value_condition``. parent_int_values (google.cloud.aiplatform_v1beta1.types.StudySpec.ParameterSpec.ConditionalParameterSpec.IntValueCondition): The spec for matching values from a parent parameter of ``INTEGER`` type. + + This field is a member of `oneof`_ ``parent_value_condition``. parent_categorical_values (google.cloud.aiplatform_v1beta1.types.StudySpec.ParameterSpec.ConditionalParameterSpec.CategoricalValueCondition): The spec for matching values from a parent parameter of ``CATEGORICAL`` type. + + This field is a member of `oneof`_ ``parent_value_condition``. parameter_spec (google.cloud.aiplatform_v1beta1.types.StudySpec.ParameterSpec): Required. The spec for a conditional parameter. @@ -351,7 +584,10 @@ class DiscreteValueCondition(proto.Message): The Epsilon of the value matching is 1e-10. """ - values = proto.RepeatedField(proto.DOUBLE, number=1,) + values = proto.RepeatedField( + proto.DOUBLE, + number=1, + ) class IntValueCondition(proto.Message): r"""Represents the spec to match integer values from parent @@ -364,7 +600,10 @@ class IntValueCondition(proto.Message): ``integer_value_spec`` of parent parameter. """ - values = proto.RepeatedField(proto.INT64, number=1,) + values = proto.RepeatedField( + proto.INT64, + number=1, + ) class CategoricalValueCondition(proto.Message): r"""Represents the spec to match categorical values from parent @@ -377,7 +616,10 @@ class CategoricalValueCondition(proto.Message): ``categorical_value_spec`` of parent parameter. """ - values = proto.RepeatedField(proto.STRING, number=1,) + values = proto.RepeatedField( + proto.STRING, + number=1, + ) parent_discrete_values = proto.Field( proto.MESSAGE, @@ -398,7 +640,9 @@ class CategoricalValueCondition(proto.Message): message="StudySpec.ParameterSpec.ConditionalParameterSpec.CategoricalValueCondition", ) parameter_spec = proto.Field( - proto.MESSAGE, number=1, message="StudySpec.ParameterSpec", + proto.MESSAGE, + number=1, + message="StudySpec.ParameterSpec", ) double_value_spec = proto.Field( @@ -425,9 +669,14 @@ class CategoricalValueCondition(proto.Message): oneof="parameter_value_spec", message="StudySpec.ParameterSpec.DiscreteValueSpec", ) - parameter_id = proto.Field(proto.STRING, number=1,) + parameter_id = proto.Field( + proto.STRING, + number=1, + ) scale_type = proto.Field( - proto.ENUM, number=6, enum="StudySpec.ParameterSpec.ScaleType", + proto.ENUM, + number=6, + enum="StudySpec.ParameterSpec.ScaleType", ) conditional_parameter_specs = proto.RepeatedField( proto.MESSAGE, @@ -452,7 +701,10 @@ class DecayCurveAutomatedStoppingSpec(proto.Message): will be used as the x-axis. """ - use_elapsed_duration = proto.Field(proto.BOOL, number=1,) + use_elapsed_duration = proto.Field( + proto.BOOL, + number=1, + ) class MedianAutomatedStoppingSpec(proto.Message): r"""The median automated stopping rule stops a pending Trial if the @@ -471,10 +723,85 @@ class MedianAutomatedStoppingSpec(proto.Message): for each completed Trials. """ - use_elapsed_duration = proto.Field(proto.BOOL, number=1,) + use_elapsed_duration = proto.Field( + proto.BOOL, + number=1, + ) + + class ConvexAutomatedStoppingSpec(proto.Message): + r"""Configuration for ConvexAutomatedStoppingSpec. When there are enough + completed trials (configured by min_measurement_count), for pending + trials with enough measurements and steps, the policy first computes + an overestimate of the objective value at max_num_steps according to + the slope of the incomplete objective value curve. No prediction can + be made if the curve is completely flat. If the overestimation is + worse than the best objective value of the completed trials, this + pending trial will be early-stopped, but a last measurement will be + added to the pending trial with max_num_steps and predicted + objective value from the autoregression model. + + Attributes: + max_step_count (int): + Steps used in predicting the final objective for early + stopped trials. In general, it's set to be the same as the + defined steps in training / tuning. If not defined, it will + learn it from the completed trials. When use_steps is false, + this field is set to the maximum elapsed seconds. + min_step_count (int): + Minimum number of steps for a trial to complete. Trials + which do not have a measurement with step_count > + min_step_count won't be considered for early stopping. It's + ok to set it to 0, and a trial can be early stopped at any + stage. By default, min_step_count is set to be one-tenth of + the max_step_count. When use_elapsed_duration is true, this + field is set to the minimum elapsed seconds. + min_measurement_count (int): + The minimal number of measurements in a Trial. + Early-stopping checks will not trigger if less than + min_measurement_count+1 completed trials or pending trials + with less than min_measurement_count measurements. If not + defined, the default value is 5. + learning_rate_parameter_name (str): + The hyper-parameter name used in the tuning job that stands + for learning rate. Leave it blank if learning rate is not in + a parameter in tuning. The learning_rate is used to estimate + the objective value of the ongoing trial. + use_elapsed_duration (bool): + This bool determines whether or not the rule is applied + based on elapsed_secs or steps. If + use_elapsed_duration==false, the early stopping decision is + made according to the predicted objective values according + to the target steps. If use_elapsed_duration==true, + elapsed_secs is used instead of steps. Also, in this case, + the parameters max_num_steps and min_num_steps are + overloaded to contain max_elapsed_seconds and + min_elapsed_seconds. + """ + + max_step_count = proto.Field( + proto.INT64, + number=1, + ) + min_step_count = proto.Field( + proto.INT64, + number=2, + ) + min_measurement_count = proto.Field( + proto.INT64, + number=3, + ) + learning_rate_parameter_name = proto.Field( + proto.STRING, + number=4, + ) + use_elapsed_duration = proto.Field( + proto.BOOL, + number=5, + ) class ConvexStopConfig(proto.Message): r"""Configuration for ConvexStopPolicy. + Attributes: max_num_steps (int): Steps used in predicting the final objective for early @@ -510,11 +837,26 @@ class ConvexStopConfig(proto.Message): and min_elapsed_seconds. """ - max_num_steps = proto.Field(proto.INT64, number=1,) - min_num_steps = proto.Field(proto.INT64, number=2,) - autoregressive_order = proto.Field(proto.INT64, number=3,) - learning_rate_parameter_name = proto.Field(proto.STRING, number=4,) - use_seconds = proto.Field(proto.BOOL, number=5,) + max_num_steps = proto.Field( + proto.INT64, + number=1, + ) + min_num_steps = proto.Field( + proto.INT64, + number=2, + ) + autoregressive_order = proto.Field( + proto.INT64, + number=3, + ) + learning_rate_parameter_name = proto.Field( + proto.STRING, + number=4, + ) + use_seconds = proto.Field( + proto.BOOL, + number=5, + ) decay_curve_stopping_spec = proto.Field( proto.MESSAGE, @@ -534,12 +876,36 @@ class ConvexStopConfig(proto.Message): oneof="automated_stopping_spec", message=ConvexStopConfig, ) - metrics = proto.RepeatedField(proto.MESSAGE, number=1, message=MetricSpec,) - parameters = proto.RepeatedField(proto.MESSAGE, number=2, message=ParameterSpec,) - algorithm = proto.Field(proto.ENUM, number=3, enum=Algorithm,) - observation_noise = proto.Field(proto.ENUM, number=6, enum=ObservationNoise,) + convex_automated_stopping_spec = proto.Field( + proto.MESSAGE, + number=9, + oneof="automated_stopping_spec", + message=ConvexAutomatedStoppingSpec, + ) + metrics = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=MetricSpec, + ) + parameters = proto.RepeatedField( + proto.MESSAGE, + number=2, + message=ParameterSpec, + ) + algorithm = proto.Field( + proto.ENUM, + number=3, + enum=Algorithm, + ) + observation_noise = proto.Field( + proto.ENUM, + number=6, + enum=ObservationNoise, + ) measurement_selection_type = proto.Field( - proto.ENUM, number=7, enum=MeasurementSelectionType, + proto.ENUM, + number=7, + enum=MeasurementSelectionType, ) @@ -564,6 +930,7 @@ class Measurement(proto.Message): class Metric(proto.Message): r"""A message representing a metric in the measurement. + Attributes: metric_id (str): Output only. The ID of the Metric. The Metric should be @@ -573,14 +940,29 @@ class Metric(proto.Message): Output only. The value for this metric. """ - metric_id = proto.Field(proto.STRING, number=1,) - value = proto.Field(proto.DOUBLE, number=2,) + metric_id = proto.Field( + proto.STRING, + number=1, + ) + value = proto.Field( + proto.DOUBLE, + number=2, + ) elapsed_duration = proto.Field( - proto.MESSAGE, number=1, message=duration_pb2.Duration, + proto.MESSAGE, + number=1, + message=duration_pb2.Duration, + ) + step_count = proto.Field( + proto.INT64, + number=2, + ) + metrics = proto.RepeatedField( + proto.MESSAGE, + number=3, + message=Metric, ) - step_count = proto.Field(proto.INT64, number=2,) - metrics = proto.RepeatedField(proto.MESSAGE, number=3, message=Metric,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/tensorboard.py b/google/cloud/aiplatform_v1beta1/types/tensorboard.py index aa04ae2551..d84252fe4a 100644 --- a/google/cloud/aiplatform_v1beta1/types/tensorboard.py +++ b/google/cloud/aiplatform_v1beta1/types/tensorboard.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,7 +20,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"Tensorboard",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "Tensorboard", + }, ) @@ -58,7 +61,7 @@ class Tensorboard(proto.Message): update_time (google.protobuf.timestamp_pb2.Timestamp): Output only. Timestamp when this Tensorboard was last updated. - labels (Sequence[google.cloud.aiplatform_v1beta1.types.Tensorboard.LabelsEntry]): + labels (Mapping[str, str]): The labels with user-defined metadata to organize your Tensorboards. Label keys and values can be no longer than 64 @@ -74,23 +77,55 @@ class Tensorboard(proto.Message): keys are prefixed with "aiplatform.googleapis.com/" and are immutable. etag (str): - Used to perform a consistent read-modify- - rite updates. If not set, a blind "overwrite" - update happens. + Used to perform a consistent + read-modify-write updates. If not set, a blind + "overwrite" update happens. """ - name = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) - description = proto.Field(proto.STRING, number=3,) + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + description = proto.Field( + proto.STRING, + number=3, + ) encryption_spec = proto.Field( - proto.MESSAGE, number=11, message=gca_encryption_spec.EncryptionSpec, + proto.MESSAGE, + number=11, + message=gca_encryption_spec.EncryptionSpec, + ) + blob_storage_path_prefix = proto.Field( + proto.STRING, + number=10, + ) + run_count = proto.Field( + proto.INT32, + number=5, + ) + create_time = proto.Field( + proto.MESSAGE, + number=6, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=7, + message=timestamp_pb2.Timestamp, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=8, + ) + etag = proto.Field( + proto.STRING, + number=9, ) - blob_storage_path_prefix = proto.Field(proto.STRING, number=10,) - run_count = proto.Field(proto.INT32, number=5,) - create_time = proto.Field(proto.MESSAGE, number=6, message=timestamp_pb2.Timestamp,) - update_time = proto.Field(proto.MESSAGE, number=7, message=timestamp_pb2.Timestamp,) - labels = proto.MapField(proto.STRING, proto.STRING, number=8,) - etag = proto.Field(proto.STRING, number=9,) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/tensorboard_data.py b/google/cloud/aiplatform_v1beta1/types/tensorboard_data.py index 30e9e4a749..f14123278c 100644 --- a/google/cloud/aiplatform_v1beta1/types/tensorboard_data.py +++ b/google/cloud/aiplatform_v1beta1/types/tensorboard_data.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -34,6 +34,7 @@ class TimeSeriesData(proto.Message): r"""All the data stored in a TensorboardTimeSeries. + Attributes: tensorboard_time_series_id (str): Required. The ID of the @@ -48,26 +49,45 @@ class TimeSeriesData(proto.Message): Required. Data points in this time series. """ - tensorboard_time_series_id = proto.Field(proto.STRING, number=1,) + tensorboard_time_series_id = proto.Field( + proto.STRING, + number=1, + ) value_type = proto.Field( proto.ENUM, number=2, enum=tensorboard_time_series.TensorboardTimeSeries.ValueType, ) values = proto.RepeatedField( - proto.MESSAGE, number=3, message="TimeSeriesDataPoint", + proto.MESSAGE, + number=3, + message="TimeSeriesDataPoint", ) class TimeSeriesDataPoint(proto.Message): r"""A TensorboardTimeSeries data point. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: scalar (google.cloud.aiplatform_v1beta1.types.Scalar): A scalar value. + + This field is a member of `oneof`_ ``value``. tensor (google.cloud.aiplatform_v1beta1.types.TensorboardTensor): A tensor value. + + This field is a member of `oneof`_ ``value``. blobs (google.cloud.aiplatform_v1beta1.types.TensorboardBlobSequence): A blob sequence value. + + This field is a member of `oneof`_ ``value``. wall_time (google.protobuf.timestamp_pb2.Timestamp): Wall clock timestamp when this data point is generated by the end user. @@ -75,29 +95,52 @@ class TimeSeriesDataPoint(proto.Message): Step index of this data point within the run. """ - scalar = proto.Field(proto.MESSAGE, number=3, oneof="value", message="Scalar",) + scalar = proto.Field( + proto.MESSAGE, + number=3, + oneof="value", + message="Scalar", + ) tensor = proto.Field( - proto.MESSAGE, number=4, oneof="value", message="TensorboardTensor", + proto.MESSAGE, + number=4, + oneof="value", + message="TensorboardTensor", ) blobs = proto.Field( - proto.MESSAGE, number=5, oneof="value", message="TensorboardBlobSequence", + proto.MESSAGE, + number=5, + oneof="value", + message="TensorboardBlobSequence", + ) + wall_time = proto.Field( + proto.MESSAGE, + number=1, + message=timestamp_pb2.Timestamp, + ) + step = proto.Field( + proto.INT64, + number=2, ) - wall_time = proto.Field(proto.MESSAGE, number=1, message=timestamp_pb2.Timestamp,) - step = proto.Field(proto.INT64, number=2,) class Scalar(proto.Message): r"""One point viewable on a scalar metric plot. + Attributes: value (float): Value of the point at this step / timestamp. """ - value = proto.Field(proto.DOUBLE, number=1,) + value = proto.Field( + proto.DOUBLE, + number=1, + ) class TensorboardTensor(proto.Message): r"""One point viewable on a tensor metric plot. + Attributes: value (bytes): Required. Serialized form of @@ -107,8 +150,14 @@ class TensorboardTensor(proto.Message): [value][google.cloud.aiplatform.v1beta1.TensorboardTensor.value]. """ - value = proto.Field(proto.BYTES, number=1,) - version_number = proto.Field(proto.INT32, number=2,) + value = proto.Field( + proto.BYTES, + number=1, + ) + version_number = proto.Field( + proto.INT32, + number=2, + ) class TensorboardBlobSequence(proto.Message): @@ -121,11 +170,16 @@ class TensorboardBlobSequence(proto.Message): List of blobs contained within the sequence. """ - values = proto.RepeatedField(proto.MESSAGE, number=1, message="TensorboardBlob",) + values = proto.RepeatedField( + proto.MESSAGE, + number=1, + message="TensorboardBlob", + ) class TensorboardBlob(proto.Message): r"""One blob (e.g, image, graph) viewable on a blob metric plot. + Attributes: id (str): Output only. A URI safe key uniquely @@ -138,8 +192,14 @@ class TensorboardBlob(proto.Message): ReadTensorboardBlobData endpoint. """ - id = proto.Field(proto.STRING, number=1,) - data = proto.Field(proto.BYTES, number=2,) + id = proto.Field( + proto.STRING, + number=1, + ) + data = proto.Field( + proto.BYTES, + number=2, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/tensorboard_experiment.py b/google/cloud/aiplatform_v1beta1/types/tensorboard_experiment.py index 0703252eca..d09e35c6d8 100644 --- a/google/cloud/aiplatform_v1beta1/types/tensorboard_experiment.py +++ b/google/cloud/aiplatform_v1beta1/types/tensorboard_experiment.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,7 +19,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"TensorboardExperiment",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "TensorboardExperiment", + }, ) @@ -43,7 +46,7 @@ class TensorboardExperiment(proto.Message): update_time (google.protobuf.timestamp_pb2.Timestamp): Output only. Timestamp when this TensorboardExperiment was last updated. - labels (Sequence[google.cloud.aiplatform_v1beta1.types.TensorboardExperiment.LabelsEntry]): + labels (Mapping[str, str]): The labels with user-defined metadata to organize your Datasets. @@ -72,14 +75,41 @@ class TensorboardExperiment(proto.Message): training job. """ - name = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) - description = proto.Field(proto.STRING, number=3,) - create_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) - update_time = proto.Field(proto.MESSAGE, number=5, message=timestamp_pb2.Timestamp,) - labels = proto.MapField(proto.STRING, proto.STRING, number=6,) - etag = proto.Field(proto.STRING, number=7,) - source = proto.Field(proto.STRING, number=8,) + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + description = proto.Field( + proto.STRING, + number=3, + ) + create_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=5, + message=timestamp_pb2.Timestamp, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=6, + ) + etag = proto.Field( + proto.STRING, + number=7, + ) + source = proto.Field( + proto.STRING, + number=8, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/tensorboard_run.py b/google/cloud/aiplatform_v1beta1/types/tensorboard_run.py index 030d8de1cf..17f38512b0 100644 --- a/google/cloud/aiplatform_v1beta1/types/tensorboard_run.py +++ b/google/cloud/aiplatform_v1beta1/types/tensorboard_run.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,7 +19,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"TensorboardRun",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "TensorboardRun", + }, ) @@ -45,21 +48,65 @@ class TensorboardRun(proto.Message): update_time (google.protobuf.timestamp_pb2.Timestamp): Output only. Timestamp when this TensorboardRun was last updated. - labels (Sequence[google.cloud.aiplatform_v1beta1.types.TensorboardRun.LabelsEntry]): + labels (Mapping[str, str]): + The labels with user-defined metadata to organize your + TensorboardRuns. + This field will be used to filter and visualize Runs in the + Tensorboard UI. For example, a Vertex AI training job can + set a label aiplatform.googleapis.com/training_job_id=xxxxx + to all the runs created within that job. An end user can set + a label experiment_id=xxxxx for all the runs produced in a + Jupyter notebook. These runs can be grouped by a label value + and visualized together in the Tensorboard UI. + + Label keys and values can be no longer than 64 characters + (Unicode codepoints), can only contain lowercase letters, + numeric characters, underscores and dashes. International + characters are allowed. No more than 64 user labels can be + associated with one TensorboardRun (System labels are + excluded). + + See https://goo.gl/xmQnxf for more information and examples + of labels. System reserved label keys are prefixed with + "aiplatform.googleapis.com/" and are immutable. etag (str): - Used to perform a consistent read-modify- - rite updates. If not set, a blind "overwrite" - update happens. + Used to perform a consistent + read-modify-write updates. If not set, a blind + "overwrite" update happens. """ - name = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) - description = proto.Field(proto.STRING, number=3,) - create_time = proto.Field(proto.MESSAGE, number=6, message=timestamp_pb2.Timestamp,) - update_time = proto.Field(proto.MESSAGE, number=7, message=timestamp_pb2.Timestamp,) - labels = proto.MapField(proto.STRING, proto.STRING, number=8,) - etag = proto.Field(proto.STRING, number=9,) + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + description = proto.Field( + proto.STRING, + number=3, + ) + create_time = proto.Field( + proto.MESSAGE, + number=6, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=7, + message=timestamp_pb2.Timestamp, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=8, + ) + etag = proto.Field( + proto.STRING, + number=9, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/tensorboard_service.py b/google/cloud/aiplatform_v1beta1/types/tensorboard_service.py index 0691fd97d3..04103dddfe 100644 --- a/google/cloud/aiplatform_v1beta1/types/tensorboard_service.py +++ b/google/cloud/aiplatform_v1beta1/types/tensorboard_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -43,6 +43,8 @@ "ListTensorboardExperimentsResponse", "UpdateTensorboardExperimentRequest", "DeleteTensorboardExperimentRequest", + "BatchCreateTensorboardRunsRequest", + "BatchCreateTensorboardRunsResponse", "CreateTensorboardRunRequest", "GetTensorboardRunRequest", "ReadTensorboardBlobDataRequest", @@ -51,14 +53,20 @@ "ListTensorboardRunsResponse", "UpdateTensorboardRunRequest", "DeleteTensorboardRunRequest", + "BatchCreateTensorboardTimeSeriesRequest", + "BatchCreateTensorboardTimeSeriesResponse", "CreateTensorboardTimeSeriesRequest", "GetTensorboardTimeSeriesRequest", "ListTensorboardTimeSeriesRequest", "ListTensorboardTimeSeriesResponse", "UpdateTensorboardTimeSeriesRequest", "DeleteTensorboardTimeSeriesRequest", + "BatchReadTensorboardTimeSeriesDataRequest", + "BatchReadTensorboardTimeSeriesDataResponse", "ReadTensorboardTimeSeriesDataRequest", "ReadTensorboardTimeSeriesDataResponse", + "WriteTensorboardExperimentDataRequest", + "WriteTensorboardExperimentDataResponse", "WriteTensorboardRunDataRequest", "WriteTensorboardRunDataResponse", "ExportTensorboardTimeSeriesDataRequest", @@ -82,9 +90,14 @@ class CreateTensorboardRequest(proto.Message): Required. The Tensorboard to create. """ - parent = proto.Field(proto.STRING, number=1,) + parent = proto.Field( + proto.STRING, + number=1, + ) tensorboard = proto.Field( - proto.MESSAGE, number=2, message=gca_tensorboard.Tensorboard, + proto.MESSAGE, + number=2, + message=gca_tensorboard.Tensorboard, ) @@ -98,7 +111,10 @@ class GetTensorboardRequest(proto.Message): ``projects/{project}/locations/{location}/tensorboards/{tensorboard}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListTensorboardsRequest(proto.Message): @@ -107,9 +123,9 @@ class ListTensorboardsRequest(proto.Message): Attributes: parent (str): - Required. The resource name of the Location - to list Tensorboards. Format: - 'projects/{project}/locations/{location}' + Required. The resource name of the Location to list + Tensorboards. Format: + ``projects/{project}/locations/{location}`` filter (str): Lists the Tensorboards that match the filter expression. @@ -133,12 +149,31 @@ class ListTensorboardsRequest(proto.Message): Mask specifying which fields to read. """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) - order_by = proto.Field(proto.STRING, number=5,) - read_mask = proto.Field(proto.MESSAGE, number=6, message=field_mask_pb2.FieldMask,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + order_by = proto.Field( + proto.STRING, + number=5, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=6, + message=field_mask_pb2.FieldMask, + ) class ListTensorboardsResponse(proto.Message): @@ -160,9 +195,14 @@ def raw_page(self): return self tensorboards = proto.RepeatedField( - proto.MESSAGE, number=1, message=gca_tensorboard.Tensorboard, + proto.MESSAGE, + number=1, + message=gca_tensorboard.Tensorboard, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class UpdateTensorboardRequest(proto.Message): @@ -185,10 +225,14 @@ class UpdateTensorboardRequest(proto.Message): """ update_mask = proto.Field( - proto.MESSAGE, number=1, message=field_mask_pb2.FieldMask, + proto.MESSAGE, + number=1, + message=field_mask_pb2.FieldMask, ) tensorboard = proto.Field( - proto.MESSAGE, number=2, message=gca_tensorboard.Tensorboard, + proto.MESSAGE, + number=2, + message=gca_tensorboard.Tensorboard, ) @@ -202,7 +246,10 @@ class DeleteTensorboardRequest(proto.Message): ``projects/{project}/locations/{location}/tensorboards/{tensorboard}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class CreateTensorboardExperimentRequest(proto.Message): @@ -225,13 +272,19 @@ class CreateTensorboardExperimentRequest(proto.Message): are /[a-z][0-9]-/. """ - parent = proto.Field(proto.STRING, number=1,) + parent = proto.Field( + proto.STRING, + number=1, + ) tensorboard_experiment = proto.Field( proto.MESSAGE, number=2, message=gca_tensorboard_experiment.TensorboardExperiment, ) - tensorboard_experiment_id = proto.Field(proto.STRING, number=3,) + tensorboard_experiment_id = proto.Field( + proto.STRING, + number=3, + ) class GetTensorboardExperimentRequest(proto.Message): @@ -245,7 +298,10 @@ class GetTensorboardExperimentRequest(proto.Message): ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListTensorboardExperimentsRequest(proto.Message): @@ -282,12 +338,31 @@ class ListTensorboardExperimentsRequest(proto.Message): Mask specifying which fields to read. """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) - order_by = proto.Field(proto.STRING, number=5,) - read_mask = proto.Field(proto.MESSAGE, number=6, message=field_mask_pb2.FieldMask,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + order_by = proto.Field( + proto.STRING, + number=5, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=6, + message=field_mask_pb2.FieldMask, + ) class ListTensorboardExperimentsResponse(proto.Message): @@ -314,7 +389,10 @@ def raw_page(self): number=1, message=gca_tensorboard_experiment.TensorboardExperiment, ) - next_page_token = proto.Field(proto.STRING, number=2,) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) class UpdateTensorboardExperimentRequest(proto.Message): @@ -337,7 +415,9 @@ class UpdateTensorboardExperimentRequest(proto.Message): """ update_mask = proto.Field( - proto.MESSAGE, number=1, message=field_mask_pb2.FieldMask, + proto.MESSAGE, + number=1, + message=field_mask_pb2.FieldMask, ) tensorboard_experiment = proto.Field( proto.MESSAGE, @@ -357,7 +437,54 @@ class DeleteTensorboardExperimentRequest(proto.Message): ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) + + +class BatchCreateTensorboardRunsRequest(proto.Message): + r"""Request message for + [TensorboardService.BatchCreateTensorboardRuns][google.cloud.aiplatform.v1beta1.TensorboardService.BatchCreateTensorboardRuns]. + + Attributes: + parent (str): + Required. The resource name of the TensorboardExperiment to + create the TensorboardRuns in. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` + The parent field in the CreateTensorboardRunRequest messages + must match this field. + requests (Sequence[google.cloud.aiplatform_v1beta1.types.CreateTensorboardRunRequest]): + Required. The request message specifying the + TensorboardRuns to create. A maximum of 1000 + TensorboardRuns can be created in a batch. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + requests = proto.RepeatedField( + proto.MESSAGE, + number=2, + message="CreateTensorboardRunRequest", + ) + + +class BatchCreateTensorboardRunsResponse(proto.Message): + r"""Response message for + [TensorboardService.BatchCreateTensorboardRuns][google.cloud.aiplatform.v1beta1.TensorboardService.BatchCreateTensorboardRuns]. + + Attributes: + tensorboard_runs (Sequence[google.cloud.aiplatform_v1beta1.types.TensorboardRun]): + The created TensorboardRuns. + """ + + tensorboard_runs = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gca_tensorboard_run.TensorboardRun, + ) class CreateTensorboardRunRequest(proto.Message): @@ -366,8 +493,8 @@ class CreateTensorboardRunRequest(proto.Message): Attributes: parent (str): - Required. The resource name of the Tensorboard to create the - TensorboardRun in. Format: + Required. The resource name of the TensorboardExperiment to + create the TensorboardRun in. Format: ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` tensorboard_run (google.cloud.aiplatform_v1beta1.types.TensorboardRun): Required. The TensorboardRun to create. @@ -380,11 +507,19 @@ class CreateTensorboardRunRequest(proto.Message): are /[a-z][0-9]-/. """ - parent = proto.Field(proto.STRING, number=1,) + parent = proto.Field( + proto.STRING, + number=1, + ) tensorboard_run = proto.Field( - proto.MESSAGE, number=2, message=gca_tensorboard_run.TensorboardRun, + proto.MESSAGE, + number=2, + message=gca_tensorboard_run.TensorboardRun, + ) + tensorboard_run_id = proto.Field( + proto.STRING, + number=3, ) - tensorboard_run_id = proto.Field(proto.STRING, number=3,) class GetTensorboardRunRequest(proto.Message): @@ -397,7 +532,10 @@ class GetTensorboardRunRequest(proto.Message): ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ReadTensorboardBlobDataRequest(proto.Message): @@ -413,8 +551,14 @@ class ReadTensorboardBlobDataRequest(proto.Message): IDs of the blobs to read. """ - time_series = proto.Field(proto.STRING, number=1,) - blob_ids = proto.RepeatedField(proto.STRING, number=2,) + time_series = proto.Field( + proto.STRING, + number=1, + ) + blob_ids = proto.RepeatedField( + proto.STRING, + number=2, + ) class ReadTensorboardBlobDataResponse(proto.Message): @@ -427,7 +571,9 @@ class ReadTensorboardBlobDataResponse(proto.Message): """ blobs = proto.RepeatedField( - proto.MESSAGE, number=1, message=tensorboard_data.TensorboardBlob, + proto.MESSAGE, + number=1, + message=tensorboard_data.TensorboardBlob, ) @@ -438,7 +584,8 @@ class ListTensorboardRunsRequest(proto.Message): Attributes: parent (str): Required. The resource name of the - Tensorboard to list TensorboardRuns. Format: + TensorboardExperiment to list TensorboardRuns. + Format: 'projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}' filter (str): Lists the TensorboardRuns that match the @@ -464,12 +611,31 @@ class ListTensorboardRunsRequest(proto.Message): Mask specifying which fields to read. """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) - order_by = proto.Field(proto.STRING, number=5,) - read_mask = proto.Field(proto.MESSAGE, number=6, message=field_mask_pb2.FieldMask,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + order_by = proto.Field( + proto.STRING, + number=5, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=6, + message=field_mask_pb2.FieldMask, + ) class ListTensorboardRunsResponse(proto.Message): @@ -491,9 +657,14 @@ def raw_page(self): return self tensorboard_runs = proto.RepeatedField( - proto.MESSAGE, number=1, message=gca_tensorboard_run.TensorboardRun, + proto.MESSAGE, + number=1, + message=gca_tensorboard_run.TensorboardRun, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class UpdateTensorboardRunRequest(proto.Message): @@ -516,10 +687,14 @@ class UpdateTensorboardRunRequest(proto.Message): """ update_mask = proto.Field( - proto.MESSAGE, number=1, message=field_mask_pb2.FieldMask, + proto.MESSAGE, + number=1, + message=field_mask_pb2.FieldMask, ) tensorboard_run = proto.Field( - proto.MESSAGE, number=2, message=gca_tensorboard_run.TensorboardRun, + proto.MESSAGE, + number=2, + message=gca_tensorboard_run.TensorboardRun, ) @@ -534,7 +709,56 @@ class DeleteTensorboardRunRequest(proto.Message): ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) + + +class BatchCreateTensorboardTimeSeriesRequest(proto.Message): + r"""Request message for + [TensorboardService.BatchCreateTensorboardTimeSeries][google.cloud.aiplatform.v1beta1.TensorboardService.BatchCreateTensorboardTimeSeries]. + + Attributes: + parent (str): + Required. The resource name of the TensorboardExperiment to + create the TensorboardTimeSeries in. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` + The TensorboardRuns referenced by the parent fields in the + CreateTensorboardTimeSeriesRequest messages must be sub + resources of this TensorboardExperiment. + requests (Sequence[google.cloud.aiplatform_v1beta1.types.CreateTensorboardTimeSeriesRequest]): + Required. The request message specifying the + TensorboardTimeSeries to create. A maximum of + 1000 TensorboardTimeSeries can be created in a + batch. + """ + + parent = proto.Field( + proto.STRING, + number=1, + ) + requests = proto.RepeatedField( + proto.MESSAGE, + number=2, + message="CreateTensorboardTimeSeriesRequest", + ) + + +class BatchCreateTensorboardTimeSeriesResponse(proto.Message): + r"""Response message for + [TensorboardService.BatchCreateTensorboardTimeSeries][google.cloud.aiplatform.v1beta1.TensorboardService.BatchCreateTensorboardTimeSeries]. + + Attributes: + tensorboard_time_series (Sequence[google.cloud.aiplatform_v1beta1.types.TensorboardTimeSeries]): + The created TensorboardTimeSeries. + """ + + tensorboard_time_series = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gca_tensorboard_time_series.TensorboardTimeSeries, + ) class CreateTensorboardTimeSeriesRequest(proto.Message): @@ -549,17 +773,21 @@ class CreateTensorboardTimeSeriesRequest(proto.Message): tensorboard_time_series_id (str): Optional. The user specified unique ID to use for the TensorboardTimeSeries, which will become the final component - of the TensorboardTimeSeries's resource name. Ref: - go/ucaip-user-specified-id - - This value should match "[a-z0-9][a-z0-9-]{0, 127}". + of the TensorboardTimeSeries's resource name. This value + should match "[a-z0-9][a-z0-9-]{0, 127}". tensorboard_time_series (google.cloud.aiplatform_v1beta1.types.TensorboardTimeSeries): Required. The TensorboardTimeSeries to create. """ - parent = proto.Field(proto.STRING, number=1,) - tensorboard_time_series_id = proto.Field(proto.STRING, number=3,) + parent = proto.Field( + proto.STRING, + number=1, + ) + tensorboard_time_series_id = proto.Field( + proto.STRING, + number=3, + ) tensorboard_time_series = proto.Field( proto.MESSAGE, number=2, @@ -578,7 +806,10 @@ class GetTensorboardTimeSeriesRequest(proto.Message): ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}/timeSeries/{time_series}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListTensorboardTimeSeriesRequest(proto.Message): @@ -615,12 +846,31 @@ class ListTensorboardTimeSeriesRequest(proto.Message): Mask specifying which fields to read. """ - parent = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) - order_by = proto.Field(proto.STRING, number=5,) - read_mask = proto.Field(proto.MESSAGE, number=6, message=field_mask_pb2.FieldMask,) + parent = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + order_by = proto.Field( + proto.STRING, + number=5, + ) + read_mask = proto.Field( + proto.MESSAGE, + number=6, + message=field_mask_pb2.FieldMask, + ) class ListTensorboardTimeSeriesResponse(proto.Message): @@ -647,7 +897,10 @@ def raw_page(self): number=1, message=gca_tensorboard_time_series.TensorboardTimeSeries, ) - next_page_token = proto.Field(proto.STRING, number=2,) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) class UpdateTensorboardTimeSeriesRequest(proto.Message): @@ -670,7 +923,9 @@ class UpdateTensorboardTimeSeriesRequest(proto.Message): """ update_mask = proto.Field( - proto.MESSAGE, number=1, message=field_mask_pb2.FieldMask, + proto.MESSAGE, + number=1, + message=field_mask_pb2.FieldMask, ) tensorboard_time_series = proto.Field( proto.MESSAGE, @@ -690,7 +945,54 @@ class DeleteTensorboardTimeSeriesRequest(proto.Message): ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}/timeSeries/{time_series}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) + + +class BatchReadTensorboardTimeSeriesDataRequest(proto.Message): + r"""Request message for + [TensorboardService.BatchReadTensorboardTimeSeriesData][google.cloud.aiplatform.v1beta1.TensorboardService.BatchReadTensorboardTimeSeriesData]. + + Attributes: + tensorboard (str): + Required. The resource name of the Tensorboard containing + TensorboardTimeSeries to read data from. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}``. + The TensorboardTimeSeries referenced by + [time_series][google.cloud.aiplatform.v1beta1.BatchReadTensorboardTimeSeriesDataRequest.time_series] + must be sub resources of this Tensorboard. + time_series (Sequence[str]): + Required. The resource names of the TensorboardTimeSeries to + read data from. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}/timeSeries/{time_series}`` + """ + + tensorboard = proto.Field( + proto.STRING, + number=1, + ) + time_series = proto.RepeatedField( + proto.STRING, + number=2, + ) + + +class BatchReadTensorboardTimeSeriesDataResponse(proto.Message): + r"""Response message for + [TensorboardService.BatchReadTensorboardTimeSeriesData][google.cloud.aiplatform.v1beta1.TensorboardService.BatchReadTensorboardTimeSeriesData]. + + Attributes: + time_series_data (Sequence[google.cloud.aiplatform_v1beta1.types.TimeSeriesData]): + The returned time series data. + """ + + time_series_data = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=tensorboard_data.TimeSeriesData, + ) class ReadTensorboardTimeSeriesDataRequest(proto.Message): @@ -712,9 +1014,18 @@ class ReadTensorboardTimeSeriesDataRequest(proto.Message): match the filter expression. """ - tensorboard_time_series = proto.Field(proto.STRING, number=1,) - max_data_points = proto.Field(proto.INT32, number=2,) - filter = proto.Field(proto.STRING, number=3,) + tensorboard_time_series = proto.Field( + proto.STRING, + number=1, + ) + max_data_points = proto.Field( + proto.INT32, + number=2, + ) + filter = proto.Field( + proto.STRING, + number=3, + ) class ReadTensorboardTimeSeriesDataResponse(proto.Message): @@ -727,10 +1038,44 @@ class ReadTensorboardTimeSeriesDataResponse(proto.Message): """ time_series_data = proto.Field( - proto.MESSAGE, number=1, message=tensorboard_data.TimeSeriesData, + proto.MESSAGE, + number=1, + message=tensorboard_data.TimeSeriesData, ) +class WriteTensorboardExperimentDataRequest(proto.Message): + r"""Request message for + [TensorboardService.WriteTensorboardExperimentData][google.cloud.aiplatform.v1beta1.TensorboardService.WriteTensorboardExperimentData]. + + Attributes: + tensorboard_experiment (str): + Required. The resource name of the TensorboardExperiment to + write data to. Format: + ``projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}`` + write_run_data_requests (Sequence[google.cloud.aiplatform_v1beta1.types.WriteTensorboardRunDataRequest]): + Required. Requests containing per-run + TensorboardTimeSeries data to write. + """ + + tensorboard_experiment = proto.Field( + proto.STRING, + number=1, + ) + write_run_data_requests = proto.RepeatedField( + proto.MESSAGE, + number=2, + message="WriteTensorboardRunDataRequest", + ) + + +class WriteTensorboardExperimentDataResponse(proto.Message): + r"""Response message for + [TensorboardService.WriteTensorboardExperimentData][google.cloud.aiplatform.v1beta1.TensorboardService.WriteTensorboardExperimentData]. + + """ + + class WriteTensorboardRunDataRequest(proto.Message): r"""Request message for [TensorboardService.WriteTensorboardRunData][google.cloud.aiplatform.v1beta1.TensorboardService.WriteTensorboardRunData]. @@ -750,16 +1095,22 @@ class WriteTensorboardRunDataRequest(proto.Message): is 5000. """ - tensorboard_run = proto.Field(proto.STRING, number=1,) + tensorboard_run = proto.Field( + proto.STRING, + number=1, + ) time_series_data = proto.RepeatedField( - proto.MESSAGE, number=2, message=tensorboard_data.TimeSeriesData, + proto.MESSAGE, + number=2, + message=tensorboard_data.TimeSeriesData, ) class WriteTensorboardRunDataResponse(proto.Message): r"""Response message for [TensorboardService.WriteTensorboardRunData][google.cloud.aiplatform.v1beta1.TensorboardService.WriteTensorboardRunData]. - """ + + """ class ExportTensorboardTimeSeriesDataRequest(proto.Message): @@ -793,11 +1144,26 @@ class ExportTensorboardTimeSeriesDataRequest(proto.Message): a pseudo random order. """ - tensorboard_time_series = proto.Field(proto.STRING, number=1,) - filter = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) - page_token = proto.Field(proto.STRING, number=4,) - order_by = proto.Field(proto.STRING, number=5,) + tensorboard_time_series = proto.Field( + proto.STRING, + number=1, + ) + filter = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) + page_token = proto.Field( + proto.STRING, + number=4, + ) + order_by = proto.Field( + proto.STRING, + number=5, + ) class ExportTensorboardTimeSeriesDataResponse(proto.Message): @@ -819,32 +1185,43 @@ def raw_page(self): return self time_series_data_points = proto.RepeatedField( - proto.MESSAGE, number=1, message=tensorboard_data.TimeSeriesDataPoint, + proto.MESSAGE, + number=1, + message=tensorboard_data.TimeSeriesDataPoint, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, ) - next_page_token = proto.Field(proto.STRING, number=2,) class CreateTensorboardOperationMetadata(proto.Message): r"""Details of operations that perform create Tensorboard. + Attributes: generic_metadata (google.cloud.aiplatform_v1beta1.types.GenericOperationMetadata): Operation metadata for Tensorboard. """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, ) class UpdateTensorboardOperationMetadata(proto.Message): r"""Details of operations that perform update Tensorboard. + Attributes: generic_metadata (google.cloud.aiplatform_v1beta1.types.GenericOperationMetadata): Operation metadata for Tensorboard. """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, ) diff --git a/google/cloud/aiplatform_v1beta1/types/tensorboard_time_series.py b/google/cloud/aiplatform_v1beta1/types/tensorboard_time_series.py index 1eb895ae36..72a9bcf495 100644 --- a/google/cloud/aiplatform_v1beta1/types/tensorboard_time_series.py +++ b/google/cloud/aiplatform_v1beta1/types/tensorboard_time_series.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -19,7 +19,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"TensorboardTimeSeries",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "TensorboardTimeSeries", + }, ) @@ -49,9 +52,9 @@ class TensorboardTimeSeries(proto.Message): Output only. Timestamp when this TensorboardTimeSeries was last updated. etag (str): - Used to perform a consistent read-modify- - rite updates. If not set, a blind "overwrite" - update happens. + Used to perform a consistent + read-modify-write updates. If not set, a blind + "overwrite" update happens. plugin_name (str): Immutable. Name of the plugin this time series pertain to. Such as Scalar, Tensor, Blob @@ -74,6 +77,7 @@ class ValueType(proto.Enum): class Metadata(proto.Message): r"""Describes metadata for a TensorboardTimeSeries. + Attributes: max_step (int): Output only. Max step index of all data @@ -87,22 +91,64 @@ class Metadata(proto.Message): ValueType is BLOB_SEQUENCE. """ - max_step = proto.Field(proto.INT64, number=1,) + max_step = proto.Field( + proto.INT64, + number=1, + ) max_wall_time = proto.Field( - proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=2, + message=timestamp_pb2.Timestamp, + ) + max_blob_sequence_length = proto.Field( + proto.INT64, + number=3, ) - max_blob_sequence_length = proto.Field(proto.INT64, number=3,) - name = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) - description = proto.Field(proto.STRING, number=3,) - value_type = proto.Field(proto.ENUM, number=4, enum=ValueType,) - create_time = proto.Field(proto.MESSAGE, number=5, message=timestamp_pb2.Timestamp,) - update_time = proto.Field(proto.MESSAGE, number=6, message=timestamp_pb2.Timestamp,) - etag = proto.Field(proto.STRING, number=7,) - plugin_name = proto.Field(proto.STRING, number=8,) - plugin_data = proto.Field(proto.BYTES, number=9,) - metadata = proto.Field(proto.MESSAGE, number=10, message=Metadata,) + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + description = proto.Field( + proto.STRING, + number=3, + ) + value_type = proto.Field( + proto.ENUM, + number=4, + enum=ValueType, + ) + create_time = proto.Field( + proto.MESSAGE, + number=5, + message=timestamp_pb2.Timestamp, + ) + update_time = proto.Field( + proto.MESSAGE, + number=6, + message=timestamp_pb2.Timestamp, + ) + etag = proto.Field( + proto.STRING, + number=7, + ) + plugin_name = proto.Field( + proto.STRING, + number=8, + ) + plugin_data = proto.Field( + proto.BYTES, + number=9, + ) + metadata = proto.Field( + proto.MESSAGE, + number=10, + message=Metadata, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/training_pipeline.py b/google/cloud/aiplatform_v1beta1/types/training_pipeline.py index 4313865bac..2190b1bae0 100644 --- a/google/cloud/aiplatform_v1beta1/types/training_pipeline.py +++ b/google/cloud/aiplatform_v1beta1/types/training_pipeline.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -33,6 +33,7 @@ "FilterSplit", "PredefinedSplit", "TimestampSplit", + "StratifiedSplit", }, ) @@ -40,10 +41,10 @@ class TrainingPipeline(proto.Message): r"""The TrainingPipeline orchestrates tasks associated with training a Model. It always executes the training task, and optionally may also - export data from AI Platform's Dataset which becomes the training + export data from Vertex AI's Dataset which becomes the training input, [upload][google.cloud.aiplatform.v1beta1.ModelService.UploadModel] - the Model to AI Platform, and evaluate the Model. + the Model to Vertex AI, and evaluate the Model. Attributes: name (str): @@ -53,7 +54,7 @@ class TrainingPipeline(proto.Message): Required. The user-defined name of this TrainingPipeline. input_data_config (google.cloud.aiplatform_v1beta1.types.InputDataConfig): - Specifies AI Platform owned input data that may be used for + Specifies Vertex AI owned input data that may be used for training the Model. The TrainingPipeline's [training_task_definition][google.cloud.aiplatform.v1beta1.TrainingPipeline.training_task_definition] should make clear whether this config is used and if there @@ -68,13 +69,13 @@ class TrainingPipeline(proto.Message): is responsible for producing the model artifact, and may also include additional auxiliary work. The definition files that can be used here are - found in gs://google-cloud- - aiplatform/schema/trainingjob/definition/. Note: - The URI given on output will be immutable and - probably different, including the URI scheme, - than the one given on input. The output URI will - point to a location where the user only has a - read access. + found in + gs://google-cloud-aiplatform/schema/trainingjob/definition/. + Note: The URI given on output will be immutable + and probably different, including the URI + scheme, than the one given on input. The output + URI will point to a location where the user only + has a read access. training_task_inputs (google.protobuf.struct_pb2.Value): Required. The training task's parameter(s), as specified in the @@ -105,10 +106,21 @@ class TrainingPipeline(proto.Message): does not support uploading a Model as part of the pipeline. When the Pipeline's state becomes ``PIPELINE_STATE_SUCCEEDED`` and the trained Model had been - uploaded into AI Platform, then the model_to_upload's - resource [name][google.cloud.aiplatform.v1beta1.Model.name] - is populated. The Model is always uploaded into the Project - and Location in which this pipeline is. + uploaded into Vertex AI, then the model_to_upload's resource + [name][google.cloud.aiplatform.v1beta1.Model.name] is + populated. The Model is always uploaded into the Project and + Location in which this pipeline is. + model_id (str): + Optional. The ID to use for the uploaded Model, which will + become the final component of the model resource name. + + This value may be up to 63 characters, and valid characters + are ``[a-z0-9_-]``. The first character cannot be a number + or hyphen. + parent_model (str): + Optional. When specify this field, the ``model_to_upload`` + will not be uploaded as a new model, instead, it will become + a new version of this ``parent_model``. state (google.cloud.aiplatform_v1beta1.types.PipelineState): Output only. The detailed state of the pipeline. @@ -128,7 +140,7 @@ class TrainingPipeline(proto.Message): update_time (google.protobuf.timestamp_pb2.Timestamp): Output only. Time when the TrainingPipeline was most recently updated. - labels (Sequence[google.cloud.aiplatform_v1beta1.types.TrainingPipeline.LabelsEntry]): + labels (Mapping[str, str]): The labels with user-defined metadata to organize TrainingPipelines. Label keys and values can be no longer than 64 @@ -148,51 +160,127 @@ class TrainingPipeline(proto.Message): is not set separately. """ - name = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) - input_data_config = proto.Field(proto.MESSAGE, number=3, message="InputDataConfig",) - training_task_definition = proto.Field(proto.STRING, number=4,) + name = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) + input_data_config = proto.Field( + proto.MESSAGE, + number=3, + message="InputDataConfig", + ) + training_task_definition = proto.Field( + proto.STRING, + number=4, + ) training_task_inputs = proto.Field( - proto.MESSAGE, number=5, message=struct_pb2.Value, + proto.MESSAGE, + number=5, + message=struct_pb2.Value, ) training_task_metadata = proto.Field( - proto.MESSAGE, number=6, message=struct_pb2.Value, + proto.MESSAGE, + number=6, + message=struct_pb2.Value, + ) + model_to_upload = proto.Field( + proto.MESSAGE, + number=7, + message=model.Model, + ) + model_id = proto.Field( + proto.STRING, + number=22, + ) + parent_model = proto.Field( + proto.STRING, + number=21, + ) + state = proto.Field( + proto.ENUM, + number=9, + enum=pipeline_state.PipelineState, + ) + error = proto.Field( + proto.MESSAGE, + number=10, + message=status_pb2.Status, ) - model_to_upload = proto.Field(proto.MESSAGE, number=7, message=model.Model,) - state = proto.Field(proto.ENUM, number=9, enum=pipeline_state.PipelineState,) - error = proto.Field(proto.MESSAGE, number=10, message=status_pb2.Status,) create_time = proto.Field( - proto.MESSAGE, number=11, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=11, + message=timestamp_pb2.Timestamp, + ) + start_time = proto.Field( + proto.MESSAGE, + number=12, + message=timestamp_pb2.Timestamp, + ) + end_time = proto.Field( + proto.MESSAGE, + number=13, + message=timestamp_pb2.Timestamp, ) - start_time = proto.Field(proto.MESSAGE, number=12, message=timestamp_pb2.Timestamp,) - end_time = proto.Field(proto.MESSAGE, number=13, message=timestamp_pb2.Timestamp,) update_time = proto.Field( - proto.MESSAGE, number=14, message=timestamp_pb2.Timestamp, + proto.MESSAGE, + number=14, + message=timestamp_pb2.Timestamp, + ) + labels = proto.MapField( + proto.STRING, + proto.STRING, + number=15, ) - labels = proto.MapField(proto.STRING, proto.STRING, number=15,) encryption_spec = proto.Field( - proto.MESSAGE, number=18, message=gca_encryption_spec.EncryptionSpec, + proto.MESSAGE, + number=18, + message=gca_encryption_spec.EncryptionSpec, ) class InputDataConfig(proto.Message): - r"""Specifies AI Platform owned input data to be used for - training, and possibly evaluating, the Model. + r"""Specifies Vertex AI owned input data to be used for training, + and possibly evaluating, the Model. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields Attributes: fraction_split (google.cloud.aiplatform_v1beta1.types.FractionSplit): Split based on fractions defining the size of each set. + + This field is a member of `oneof`_ ``split``. filter_split (google.cloud.aiplatform_v1beta1.types.FilterSplit): Split based on the provided filters for each set. + + This field is a member of `oneof`_ ``split``. predefined_split (google.cloud.aiplatform_v1beta1.types.PredefinedSplit): Supported only for tabular Datasets. Split based on a predefined key. + + This field is a member of `oneof`_ ``split``. timestamp_split (google.cloud.aiplatform_v1beta1.types.TimestampSplit): Supported only for tabular Datasets. Split based on the timestamp of the input data pieces. + + This field is a member of `oneof`_ ``split``. + stratified_split (google.cloud.aiplatform_v1beta1.types.StratifiedSplit): + Supported only for tabular Datasets. + Split based on the distribution of the specified + column. + + This field is a member of `oneof`_ ``split``. gcs_destination (google.cloud.aiplatform_v1beta1.types.GcsDestination): The Cloud Storage location where the training data is to be written to. In the given directory a new directory is @@ -202,7 +290,7 @@ class InputDataConfig(proto.Message): format. All training input data is written into that directory. - The AI Platform environment variables representing Cloud + The Vertex AI environment variables representing Cloud Storage data URIs are represented in the Cloud Storage wildcard format to support sharded data. e.g.: "gs://.../training-*.jsonl" @@ -218,6 +306,8 @@ class InputDataConfig(proto.Message): - AIP_TEST_DATA_URI = "gcs_destination/dataset---/test-*.${AIP_DATA_FORMAT}". + + This field is a member of `oneof`_ ``destination``. bigquery_destination (google.cloud.aiplatform_v1beta1.types.BigQueryDestination): Only applicable to custom training with tabular Dataset with BigQuery source. @@ -241,6 +331,8 @@ class InputDataConfig(proto.Message): - AIP_TEST_DATA_URI = "bigquery_destination.dataset\_\ **\ .test". + + This field is a member of `oneof`_ ``destination``. dataset_id (str): Required. The ID of the Dataset in the same Project and Location which data will be used to train the Model. The @@ -259,8 +351,8 @@ class InputDataConfig(proto.Message): ignored by the split method are used in respectively training, validation or test role, depending on the role of the DataItem they are on (for the auto-assigned that role is - decided by AI Platform). A filter with same syntax as the - one used in + decided by Vertex AI). A filter with same syntax as the one + used in [ListAnnotations][google.cloud.aiplatform.v1beta1.DatasetService.ListAnnotations] may be used, but note here it filters across all Annotations of the Dataset, and not just within a single DataItem. @@ -271,8 +363,8 @@ class InputDataConfig(proto.Message): Cloud Storage URI that points to a YAML file describing the annotation schema. The schema is defined as an OpenAPI 3.0.2 `Schema - Object `__. The - schema files that can be used here are found in + Object `__. + The schema files that can be used here are found in gs://google-cloud-aiplatform/schema/dataset/annotation/ , note that the chosen schema must be consistent with [metadata][google.cloud.aiplatform.v1beta1.Dataset.metadata_schema_uri] @@ -293,26 +385,59 @@ class InputDataConfig(proto.Message): """ fraction_split = proto.Field( - proto.MESSAGE, number=2, oneof="split", message="FractionSplit", + proto.MESSAGE, + number=2, + oneof="split", + message="FractionSplit", ) filter_split = proto.Field( - proto.MESSAGE, number=3, oneof="split", message="FilterSplit", + proto.MESSAGE, + number=3, + oneof="split", + message="FilterSplit", ) predefined_split = proto.Field( - proto.MESSAGE, number=4, oneof="split", message="PredefinedSplit", + proto.MESSAGE, + number=4, + oneof="split", + message="PredefinedSplit", ) timestamp_split = proto.Field( - proto.MESSAGE, number=5, oneof="split", message="TimestampSplit", + proto.MESSAGE, + number=5, + oneof="split", + message="TimestampSplit", + ) + stratified_split = proto.Field( + proto.MESSAGE, + number=12, + oneof="split", + message="StratifiedSplit", ) gcs_destination = proto.Field( - proto.MESSAGE, number=8, oneof="destination", message=io.GcsDestination, + proto.MESSAGE, + number=8, + oneof="destination", + message=io.GcsDestination, ) bigquery_destination = proto.Field( - proto.MESSAGE, number=10, oneof="destination", message=io.BigQueryDestination, + proto.MESSAGE, + number=10, + oneof="destination", + message=io.BigQueryDestination, + ) + dataset_id = proto.Field( + proto.STRING, + number=1, + ) + annotations_filter = proto.Field( + proto.STRING, + number=6, + ) + annotation_schema_uri = proto.Field( + proto.STRING, + number=9, ) - dataset_id = proto.Field(proto.STRING, number=1,) - annotations_filter = proto.Field(proto.STRING, number=6,) - annotation_schema_uri = proto.Field(proto.STRING, number=9,) class FractionSplit(proto.Message): @@ -320,7 +445,7 @@ class FractionSplit(proto.Message): the given fractions. Any of ``training_fraction``, ``validation_fraction`` and ``test_fraction`` may optionally be provided, they must sum to up to 1. If the provided ones sum to less - than 1, the remainder is assigned to sets as decided by AI Platform. + than 1, the remainder is assigned to sets as decided by Vertex AI. If none of the fractions are set, by default roughly 80% of data is used for training, 10% for validation, and 10% for test. @@ -336,9 +461,18 @@ class FractionSplit(proto.Message): used to evaluate the Model. """ - training_fraction = proto.Field(proto.DOUBLE, number=1,) - validation_fraction = proto.Field(proto.DOUBLE, number=2,) - test_fraction = proto.Field(proto.DOUBLE, number=3,) + training_fraction = proto.Field( + proto.DOUBLE, + number=1, + ) + validation_fraction = proto.Field( + proto.DOUBLE, + number=2, + ) + test_fraction = proto.Field( + proto.DOUBLE, + number=3, + ) class FilterSplit(proto.Message): @@ -381,9 +515,18 @@ class FilterSplit(proto.Message): test order. """ - training_filter = proto.Field(proto.STRING, number=1,) - validation_filter = proto.Field(proto.STRING, number=2,) - test_filter = proto.Field(proto.STRING, number=3,) + training_filter = proto.Field( + proto.STRING, + number=1, + ) + validation_filter = proto.Field( + proto.STRING, + number=2, + ) + test_filter = proto.Field( + proto.STRING, + number=3, + ) class PredefinedSplit(proto.Message): @@ -403,7 +546,10 @@ class PredefinedSplit(proto.Message): ignored by the pipeline. """ - key = proto.Field(proto.STRING, number=1,) + key = proto.Field( + proto.STRING, + number=1, + ) class TimestampSplit(proto.Message): @@ -432,10 +578,75 @@ class TimestampSplit(proto.Message): value, that piece is ignored by the pipeline. """ - training_fraction = proto.Field(proto.DOUBLE, number=1,) - validation_fraction = proto.Field(proto.DOUBLE, number=2,) - test_fraction = proto.Field(proto.DOUBLE, number=3,) - key = proto.Field(proto.STRING, number=4,) + training_fraction = proto.Field( + proto.DOUBLE, + number=1, + ) + validation_fraction = proto.Field( + proto.DOUBLE, + number=2, + ) + test_fraction = proto.Field( + proto.DOUBLE, + number=3, + ) + key = proto.Field( + proto.STRING, + number=4, + ) + + +class StratifiedSplit(proto.Message): + r"""Assigns input data to the training, validation, and test sets so + that the distribution of values found in the categorical column (as + specified by the ``key`` field) is mirrored within each split. The + fraction values determine the relative sizes of the splits. + + For example, if the specified column has three values, with 50% of + the rows having value "A", 25% value "B", and 25% value "C", and the + split fractions are specified as 80/10/10, then the training set + will constitute 80% of the training data, with about 50% of the + training set rows having the value "A" for the specified column, + about 25% having the value "B", and about 25% having the value "C". + + Only the top 500 occurring values are used; any values not in the + top 500 values are randomly assigned to a split. If less than three + rows contain a specific value, those rows are randomly assigned. + + Supported only for tabular Datasets. + + Attributes: + training_fraction (float): + The fraction of the input data that is to be + used to train the Model. + validation_fraction (float): + The fraction of the input data that is to be + used to validate the Model. + test_fraction (float): + The fraction of the input data that is to be + used to evaluate the Model. + key (str): + Required. The key is a name of one of the + Dataset's data columns. The key provided must be + for a categorical column. + """ + + training_fraction = proto.Field( + proto.DOUBLE, + number=1, + ) + validation_fraction = proto.Field( + proto.DOUBLE, + number=2, + ) + test_fraction = proto.Field( + proto.DOUBLE, + number=3, + ) + key = proto.Field( + proto.STRING, + number=4, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/types.py b/google/cloud/aiplatform_v1beta1/types/types.py index dc46a25c25..1ca3bb86ef 100644 --- a/google/cloud/aiplatform_v1beta1/types/types.py +++ b/google/cloud/aiplatform_v1beta1/types/types.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,48 +18,69 @@ __protobuf__ = proto.module( package="google.cloud.aiplatform.v1beta1", - manifest={"BoolArray", "DoubleArray", "Int64Array", "StringArray",}, + manifest={ + "BoolArray", + "DoubleArray", + "Int64Array", + "StringArray", + }, ) class BoolArray(proto.Message): r"""A list of boolean values. + Attributes: values (Sequence[bool]): A list of bool values. """ - values = proto.RepeatedField(proto.BOOL, number=1,) + values = proto.RepeatedField( + proto.BOOL, + number=1, + ) class DoubleArray(proto.Message): r"""A list of double values. + Attributes: values (Sequence[float]): A list of bool values. """ - values = proto.RepeatedField(proto.DOUBLE, number=1,) + values = proto.RepeatedField( + proto.DOUBLE, + number=1, + ) class Int64Array(proto.Message): r"""A list of int64 values. + Attributes: values (Sequence[int]): A list of int64 values. """ - values = proto.RepeatedField(proto.INT64, number=1,) + values = proto.RepeatedField( + proto.INT64, + number=1, + ) class StringArray(proto.Message): r"""A list of string values. + Attributes: values (Sequence[str]): A list of string values. """ - values = proto.RepeatedField(proto.STRING, number=1,) + values = proto.RepeatedField( + proto.STRING, + number=1, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/unmanaged_container_model.py b/google/cloud/aiplatform_v1beta1/types/unmanaged_container_model.py new file mode 100644 index 0000000000..2ce6819c74 --- /dev/null +++ b/google/cloud/aiplatform_v1beta1/types/unmanaged_container_model.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import proto # type: ignore + +from google.cloud.aiplatform_v1beta1.types import model + + +__protobuf__ = proto.module( + package="google.cloud.aiplatform.v1beta1", + manifest={ + "UnmanagedContainerModel", + }, +) + + +class UnmanagedContainerModel(proto.Message): + r"""Contains model information necessary to perform batch + prediction without requiring a full model import. + + Attributes: + artifact_uri (str): + The path to the directory containing the + Model artifact and any of its supporting files. + predict_schemata (google.cloud.aiplatform_v1beta1.types.PredictSchemata): + Contains the schemata used in Model's + predictions and explanations + container_spec (google.cloud.aiplatform_v1beta1.types.ModelContainerSpec): + Input only. The specification of the + container that is to be used when deploying this + Model. + """ + + artifact_uri = proto.Field( + proto.STRING, + number=1, + ) + predict_schemata = proto.Field( + proto.MESSAGE, + number=2, + message=model.PredictSchemata, + ) + container_spec = proto.Field( + proto.MESSAGE, + number=3, + message=model.ModelContainerSpec, + ) + + +__all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/user_action_reference.py b/google/cloud/aiplatform_v1beta1/types/user_action_reference.py index a67f6bb2a0..0b1676026c 100644 --- a/google/cloud/aiplatform_v1beta1/types/user_action_reference.py +++ b/google/cloud/aiplatform_v1beta1/types/user_action_reference.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,7 +17,10 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"UserActionReference",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "UserActionReference", + }, ) @@ -26,25 +29,47 @@ class UserActionReference(proto.Message): long running operation and Jobs that are triggered by the API call. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: operation (str): For API calls that return a long running operation. Resource name of the long running operation. Format: 'projects/{project}/locations/{location}/operations/{operation}' + + This field is a member of `oneof`_ ``reference``. data_labeling_job (str): For API calls that start a LabelingJob. Resource name of the LabelingJob. Format: 'projects/{project}/locations/{location}/dataLabelingJobs/{data_labeling_job}' + + This field is a member of `oneof`_ ``reference``. method (str): The method name of the API RPC call. For example, "/google.cloud.aiplatform.{apiVersion}.DatasetService.CreateDataset". """ - operation = proto.Field(proto.STRING, number=1, oneof="reference",) - data_labeling_job = proto.Field(proto.STRING, number=2, oneof="reference",) - method = proto.Field(proto.STRING, number=3,) + operation = proto.Field( + proto.STRING, + number=1, + oneof="reference", + ) + data_labeling_job = proto.Field( + proto.STRING, + number=2, + oneof="reference", + ) + method = proto.Field( + proto.STRING, + number=3, + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/value.py b/google/cloud/aiplatform_v1beta1/types/value.py index 0ebcb60c30..d8861f9198 100644 --- a/google/cloud/aiplatform_v1beta1/types/value.py +++ b/google/cloud/aiplatform_v1beta1/types/value.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,24 +17,53 @@ __protobuf__ = proto.module( - package="google.cloud.aiplatform.v1beta1", manifest={"Value",}, + package="google.cloud.aiplatform.v1beta1", + manifest={ + "Value", + }, ) class Value(proto.Message): r"""Value is the value of the field. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: int_value (int): An integer value. + + This field is a member of `oneof`_ ``value``. double_value (float): A double value. + + This field is a member of `oneof`_ ``value``. string_value (str): A string value. + + This field is a member of `oneof`_ ``value``. """ - int_value = proto.Field(proto.INT64, number=1, oneof="value",) - double_value = proto.Field(proto.DOUBLE, number=2, oneof="value",) - string_value = proto.Field(proto.STRING, number=3, oneof="value",) + int_value = proto.Field( + proto.INT64, + number=1, + oneof="value", + ) + double_value = proto.Field( + proto.DOUBLE, + number=2, + oneof="value", + ) + string_value = proto.Field( + proto.STRING, + number=3, + oneof="value", + ) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/google/cloud/aiplatform_v1beta1/types/vizier_service.py b/google/cloud/aiplatform_v1beta1/types/vizier_service.py index 2952d92c7e..d1e50bd957 100644 --- a/google/cloud/aiplatform_v1beta1/types/vizier_service.py +++ b/google/cloud/aiplatform_v1beta1/types/vizier_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -59,7 +59,10 @@ class GetStudyRequest(proto.Message): ``projects/{project}/locations/{location}/studies/{study}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class CreateStudyRequest(proto.Message): @@ -76,8 +79,15 @@ class CreateStudyRequest(proto.Message): create the Study. """ - parent = proto.Field(proto.STRING, number=1,) - study = proto.Field(proto.MESSAGE, number=2, message=gca_study.Study,) + parent = proto.Field( + proto.STRING, + number=1, + ) + study = proto.Field( + proto.MESSAGE, + number=2, + message=gca_study.Study, + ) class ListStudiesRequest(proto.Message): @@ -99,9 +109,18 @@ class ListStudiesRequest(proto.Message): service will pick an appropriate default. """ - parent = proto.Field(proto.STRING, number=1,) - page_token = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) + parent = proto.Field( + proto.STRING, + number=1, + ) + page_token = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) class ListStudiesResponse(proto.Message): @@ -121,8 +140,15 @@ class ListStudiesResponse(proto.Message): def raw_page(self): return self - studies = proto.RepeatedField(proto.MESSAGE, number=1, message=gca_study.Study,) - next_page_token = proto.Field(proto.STRING, number=2,) + studies = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gca_study.Study, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) class DeleteStudyRequest(proto.Message): @@ -136,7 +162,10 @@ class DeleteStudyRequest(proto.Message): ``projects/{project}/locations/{location}/studies/{study}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class LookupStudyRequest(proto.Message): @@ -152,8 +181,14 @@ class LookupStudyRequest(proto.Message): the Study """ - parent = proto.Field(proto.STRING, number=1,) - display_name = proto.Field(proto.STRING, number=2,) + parent = proto.Field( + proto.STRING, + number=1, + ) + display_name = proto.Field( + proto.STRING, + number=2, + ) class SuggestTrialsRequest(proto.Message): @@ -178,9 +213,18 @@ class SuggestTrialsRequest(proto.Message): Trial if the last suggested Trial was completed. """ - parent = proto.Field(proto.STRING, number=1,) - suggestion_count = proto.Field(proto.INT32, number=2,) - client_id = proto.Field(proto.STRING, number=3,) + parent = proto.Field( + proto.STRING, + number=1, + ) + suggestion_count = proto.Field( + proto.INT32, + number=2, + ) + client_id = proto.Field( + proto.STRING, + number=3, + ) class SuggestTrialsResponse(proto.Message): @@ -199,14 +243,31 @@ class SuggestTrialsResponse(proto.Message): completed. """ - trials = proto.RepeatedField(proto.MESSAGE, number=1, message=gca_study.Trial,) - study_state = proto.Field(proto.ENUM, number=2, enum=gca_study.Study.State,) - start_time = proto.Field(proto.MESSAGE, number=3, message=timestamp_pb2.Timestamp,) - end_time = proto.Field(proto.MESSAGE, number=4, message=timestamp_pb2.Timestamp,) + trials = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gca_study.Trial, + ) + study_state = proto.Field( + proto.ENUM, + number=2, + enum=gca_study.Study.State, + ) + start_time = proto.Field( + proto.MESSAGE, + number=3, + message=timestamp_pb2.Timestamp, + ) + end_time = proto.Field( + proto.MESSAGE, + number=4, + message=timestamp_pb2.Timestamp, + ) class SuggestTrialsMetadata(proto.Message): r"""Details of operations that perform Trials suggestion. + Attributes: generic_metadata (google.cloud.aiplatform_v1beta1.types.GenericOperationMetadata): Operation metadata for suggesting Trials. @@ -221,9 +282,14 @@ class SuggestTrialsMetadata(proto.Message): """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, + ) + client_id = proto.Field( + proto.STRING, + number=2, ) - client_id = proto.Field(proto.STRING, number=2,) class CreateTrialRequest(proto.Message): @@ -239,8 +305,15 @@ class CreateTrialRequest(proto.Message): Required. The Trial to create. """ - parent = proto.Field(proto.STRING, number=1,) - trial = proto.Field(proto.MESSAGE, number=2, message=gca_study.Trial,) + parent = proto.Field( + proto.STRING, + number=1, + ) + trial = proto.Field( + proto.MESSAGE, + number=2, + message=gca_study.Trial, + ) class GetTrialRequest(proto.Message): @@ -253,7 +326,10 @@ class GetTrialRequest(proto.Message): ``projects/{project}/locations/{location}/studies/{study}/trials/{trial}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListTrialsRequest(proto.Message): @@ -275,9 +351,18 @@ class ListTrialsRequest(proto.Message): service will pick an appropriate default. """ - parent = proto.Field(proto.STRING, number=1,) - page_token = proto.Field(proto.STRING, number=2,) - page_size = proto.Field(proto.INT32, number=3,) + parent = proto.Field( + proto.STRING, + number=1, + ) + page_token = proto.Field( + proto.STRING, + number=2, + ) + page_size = proto.Field( + proto.INT32, + number=3, + ) class ListTrialsResponse(proto.Message): @@ -297,8 +382,15 @@ class ListTrialsResponse(proto.Message): def raw_page(self): return self - trials = proto.RepeatedField(proto.MESSAGE, number=1, message=gca_study.Trial,) - next_page_token = proto.Field(proto.STRING, number=2,) + trials = proto.RepeatedField( + proto.MESSAGE, + number=1, + message=gca_study.Trial, + ) + next_page_token = proto.Field( + proto.STRING, + number=2, + ) class AddTrialMeasurementRequest(proto.Message): @@ -314,8 +406,15 @@ class AddTrialMeasurementRequest(proto.Message): Trial. """ - trial_name = proto.Field(proto.STRING, number=1,) - measurement = proto.Field(proto.MESSAGE, number=3, message=gca_study.Measurement,) + trial_name = proto.Field( + proto.STRING, + number=1, + ) + measurement = proto.Field( + proto.MESSAGE, + number=3, + message=gca_study.Measurement, + ) class CompleteTrialRequest(proto.Message): @@ -340,12 +439,23 @@ class CompleteTrialRequest(proto.Message): ``trial_infeasible`` is true. """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) final_measurement = proto.Field( - proto.MESSAGE, number=2, message=gca_study.Measurement, + proto.MESSAGE, + number=2, + message=gca_study.Measurement, + ) + trial_infeasible = proto.Field( + proto.BOOL, + number=3, + ) + infeasible_reason = proto.Field( + proto.STRING, + number=4, ) - trial_infeasible = proto.Field(proto.BOOL, number=3,) - infeasible_reason = proto.Field(proto.STRING, number=4,) class DeleteTrialRequest(proto.Message): @@ -358,7 +468,10 @@ class DeleteTrialRequest(proto.Message): ``projects/{project}/locations/{location}/studies/{study}/trials/{trial}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class CheckTrialEarlyStoppingStateRequest(proto.Message): @@ -371,7 +484,10 @@ class CheckTrialEarlyStoppingStateRequest(proto.Message): ``projects/{project}/locations/{location}/studies/{study}/trials/{trial}`` """ - trial_name = proto.Field(proto.STRING, number=1,) + trial_name = proto.Field( + proto.STRING, + number=1, + ) class CheckTrialEarlyStoppingStateResponse(proto.Message): @@ -383,7 +499,10 @@ class CheckTrialEarlyStoppingStateResponse(proto.Message): True if the Trial should stop. """ - should_stop = proto.Field(proto.BOOL, number=1,) + should_stop = proto.Field( + proto.BOOL, + number=1, + ) class CheckTrialEarlyStoppingStateMetatdata(proto.Message): @@ -402,10 +521,18 @@ class CheckTrialEarlyStoppingStateMetatdata(proto.Message): """ generic_metadata = proto.Field( - proto.MESSAGE, number=1, message=operation.GenericOperationMetadata, + proto.MESSAGE, + number=1, + message=operation.GenericOperationMetadata, + ) + study = proto.Field( + proto.STRING, + number=2, + ) + trial = proto.Field( + proto.STRING, + number=3, ) - study = proto.Field(proto.STRING, number=2,) - trial = proto.Field(proto.STRING, number=3,) class StopTrialRequest(proto.Message): @@ -418,7 +545,10 @@ class StopTrialRequest(proto.Message): ``projects/{project}/locations/{location}/studies/{study}/trials/{trial}`` """ - name = proto.Field(proto.STRING, number=1,) + name = proto.Field( + proto.STRING, + number=1, + ) class ListOptimalTrialsRequest(proto.Message): @@ -431,7 +561,10 @@ class ListOptimalTrialsRequest(proto.Message): optimal Trial belongs to. """ - parent = proto.Field(proto.STRING, number=1,) + parent = proto.Field( + proto.STRING, + number=1, + ) class ListOptimalTrialsResponse(proto.Message): @@ -447,7 +580,9 @@ class ListOptimalTrialsResponse(proto.Message): """ optimal_trials = proto.RepeatedField( - proto.MESSAGE, number=1, message=gca_study.Trial, + proto.MESSAGE, + number=1, + message=gca_study.Trial, ) diff --git a/noxfile.py b/noxfile.py index cd85c2b17e..81f1bcb16c 100644 --- a/noxfile.py +++ b/noxfile.py @@ -20,16 +20,45 @@ import os import pathlib import shutil +import warnings import nox - -BLACK_VERSION = "black==19.10b0" -BLACK_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"] +BLACK_VERSION = "black==22.3.0" +ISORT_VERSION = "isort==5.10.1" +LINT_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"] DEFAULT_PYTHON_VERSION = "3.8" + +UNIT_TEST_PYTHON_VERSIONS = ["3.7", "3.8", "3.9"] +UNIT_TEST_STANDARD_DEPENDENCIES = [ + "mock", + "asyncmock", + "pytest", + "pytest-cov", + "pytest-asyncio", +] +UNIT_TEST_EXTERNAL_DEPENDENCIES = [] +UNIT_TEST_LOCAL_DEPENDENCIES = [] +UNIT_TEST_DEPENDENCIES = [] +UNIT_TEST_EXTRAS = [ + "testing", +] +UNIT_TEST_EXTRAS_BY_PYTHON = {} + SYSTEM_TEST_PYTHON_VERSIONS = ["3.8"] -UNIT_TEST_PYTHON_VERSIONS = ["3.6", "3.7", "3.8", "3.9"] +SYSTEM_TEST_STANDARD_DEPENDENCIES = [ + "mock", + "pytest", + "google-cloud-testutils", +] +SYSTEM_TEST_EXTERNAL_DEPENDENCIES = [] +SYSTEM_TEST_LOCAL_DEPENDENCIES = [] +SYSTEM_TEST_DEPENDENCIES = [] +SYSTEM_TEST_EXTRAS = [ + "testing", +] +SYSTEM_TEST_EXTRAS_BY_PYTHON = {} CURRENT_DIRECTORY = pathlib.Path(__file__).parent.absolute() @@ -57,7 +86,9 @@ def lint(session): """ session.install("flake8", BLACK_VERSION) session.run( - "black", "--check", *BLACK_PATHS, + "black", + "--check", + *LINT_PATHS, ) session.run("flake8", "google", "tests") @@ -67,7 +98,28 @@ def blacken(session): """Run black. Format code to uniform standard.""" session.install(BLACK_VERSION) session.run( - "black", *BLACK_PATHS, + "black", + *LINT_PATHS, + ) + + +@nox.session(python=DEFAULT_PYTHON_VERSION) +def format(session): + """ + Run isort to sort imports. Then run black + to format code to uniform standard. + """ + session.install(BLACK_VERSION, ISORT_VERSION) + # Use the --fss option to sort imports using strict alphabetical order. + # See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections + session.run( + "isort", + "--fss", + *LINT_PATHS, + ) + session.run( + "black", + *LINT_PATHS, ) @@ -78,25 +130,48 @@ def lint_setup_py(session): session.run("python", "setup.py", "check", "--restructuredtext", "--strict") +def install_unittest_dependencies(session, *constraints): + standard_deps = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_DEPENDENCIES + session.install(*standard_deps, *constraints) + + if UNIT_TEST_EXTERNAL_DEPENDENCIES: + warnings.warn( + "'unit_test_external_dependencies' is deprecated. Instead, please " + "use 'unit_test_dependencies' or 'unit_test_local_dependencies'.", + DeprecationWarning, + ) + session.install(*UNIT_TEST_EXTERNAL_DEPENDENCIES, *constraints) + + if UNIT_TEST_LOCAL_DEPENDENCIES: + session.install(*UNIT_TEST_LOCAL_DEPENDENCIES, *constraints) + + if UNIT_TEST_EXTRAS_BY_PYTHON: + extras = UNIT_TEST_EXTRAS_BY_PYTHON.get(session.python, []) + elif UNIT_TEST_EXTRAS: + extras = UNIT_TEST_EXTRAS + else: + extras = [] + + if extras: + session.install("-e", f".[{','.join(extras)}]", *constraints) + else: + session.install("-e", ".", *constraints) + + def default(session): # Install all test dependencies, then install this package in-place. constraints_path = str( CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" ) - session.install("asyncmock", "pytest-asyncio", "-c", constraints_path) - - session.install("mock", "pytest", "pytest-cov", "-c", constraints_path) - - session.install("-e", ".[testing]", "-c", constraints_path) + install_unittest_dependencies(session, "-c", constraints_path) # Run py.test against the unit tests. session.run( "py.test", "--quiet", f"--junitxml=unit_{session.python}_sponge_log.xml", - "--cov=google/cloud", - "--cov=tests/unit", + "--cov=google", "--cov-append", "--cov-config=.coveragerc", "--cov-report=", @@ -112,6 +187,35 @@ def unit(session): default(session) +def install_systemtest_dependencies(session, *constraints): + + # Use pre-release gRPC for system tests. + session.install("--pre", "grpcio") + + session.install(*SYSTEM_TEST_STANDARD_DEPENDENCIES, *constraints) + + if SYSTEM_TEST_EXTERNAL_DEPENDENCIES: + session.install(*SYSTEM_TEST_EXTERNAL_DEPENDENCIES, *constraints) + + if SYSTEM_TEST_LOCAL_DEPENDENCIES: + session.install("-e", *SYSTEM_TEST_LOCAL_DEPENDENCIES, *constraints) + + if SYSTEM_TEST_DEPENDENCIES: + session.install("-e", *SYSTEM_TEST_DEPENDENCIES, *constraints) + + if SYSTEM_TEST_EXTRAS_BY_PYTHON: + extras = SYSTEM_TEST_EXTRAS_BY_PYTHON.get(session.python, []) + elif SYSTEM_TEST_EXTRAS: + extras = SYSTEM_TEST_EXTRAS + else: + extras = [] + + if extras: + session.install("-e", f".[{','.join(extras)}]", *constraints) + else: + session.install("-e", ".", *constraints) + + @nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS) def system(session): """Run the system test suite.""" @@ -134,13 +238,7 @@ def system(session): if not system_test_exists and not system_test_folder_exists: session.skip("System tests were not found") - # Use pre-release gRPC for system tests. - session.install("--pre", "grpcio") - - # Install all test dependencies, then install this package into the - # virtualenv's dist-packages. - session.install("mock", "pytest", "google-cloud-testutils", "-c", constraints_path) - session.install("-e", ".", "-c", constraints_path) + install_systemtest_dependencies(session, "-c", constraints_path) # Run py.test against the system tests. if system_test_exists: @@ -169,7 +267,7 @@ def cover(session): test runs (not system test runs), and then erases coverage data. """ session.install("coverage", "pytest-cov") - session.run("coverage", "report", "--show-missing", "--fail-under=95") + session.run("coverage", "report", "--show-missing", "--fail-under=98") session.run("coverage", "erase") @@ -179,7 +277,7 @@ def docs(session): """Build the docs for this library.""" session.install("-e", ".") - session.install("sphinx", "alabaster", "recommonmark") + session.install("sphinx==4.0.1", "alabaster", "recommonmark") shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) session.run( @@ -200,7 +298,9 @@ def docfx(session): """Build the docfx yaml files for this library.""" session.install("-e", ".") - session.install("sphinx", "alabaster", "recommonmark", "gcp-sphinx-docfx-yaml") + session.install( + "sphinx==4.0.1", "alabaster", "recommonmark", "gcp-sphinx-docfx-yaml" + ) shutil.rmtree(os.path.join("docs", "_build"), ignore_errors=True) session.run( diff --git a/owlbot.py b/owlbot.py new file mode 100644 index 0000000000..b93de98baa --- /dev/null +++ b/owlbot.py @@ -0,0 +1,136 @@ +# 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. + +"""This script is used to synthesize generated parts of this library.""" + +import re + +import synthtool as s +import synthtool.gcp as gcp +from synthtool.languages import python + +common = gcp.CommonTemplates() + +default_version = "v1" + +for library in s.get_staging_dirs(default_version): + # --------------------------------------------------------------------- + # Patch each version of the library + # --------------------------------------------------------------------- + + # https://github.com/googleapis/gapic-generator-python/issues/413 + s.replace( + library + / f"google/cloud/aiplatform_{library.name}/services/prediction_service/client.py", + "request.instances = instances", + "request.instances.extend(instances)", + ) + + # Remove test_predict_flattened/test_predict_flattened_async due to gapic generator bug + # https://github.com/googleapis/gapic-generator-python/issues/414 + s.replace( + library + / f"tests/unit/gapic/aiplatform_{library.name}/test_prediction_service.py", + """def test_predict_flattened.*?def test_predict_flattened_error""", + "def test_predict_flattened_error", + flags=re.MULTILINE | re.DOTALL, + ) + + # Remove test_explain_flattened/test_explain_flattened_async due to gapic generator bug + # https://github.com/googleapis/gapic-generator-python/issues/414 + s.replace( + library + / f"tests/unit/gapic/aiplatform_{library.name}/test_prediction_service.py", + """def test_explain_flattened.*?def test_explain_flattened_error""", + "def test_explain_flattened_error", + flags=re.MULTILINE | re.DOTALL, + ) + + s.move( + library, + excludes=[ + ".pre-commit-config.yaml", + "setup.py", + "README.rst", + "docs/index.rst", + f"docs/definition_{library.name}/services.rst", + f"docs/instance_{library.name}/services.rst", + f"docs/params_{library.name}/services.rst", + f"docs/prediction_{library.name}/services.rst", + f"scripts/fixup_aiplatform_{library.name}_keywords.py", + f"scripts/fixup_definition_{library.name}_keywords.py", + f"scripts/fixup_instance_{library.name}_keywords.py", + f"scripts/fixup_params_{library.name}_keywords.py", + f"scripts/fixup_prediction_{library.name}_keywords.py", + "google/cloud/aiplatform/__init__.py", + f"google/cloud/aiplatform/{library.name}/schema/**/services/", + ], + ) + +s.remove_staging_dirs() + +# ---------------------------------------------------------------------------- +# Add templated files +# ---------------------------------------------------------------------------- + +templated_files = common.py_library( + cov_level=98, + system_test_python_versions=["3.8"], + unit_test_python_versions=["3.7", "3.8", "3.9"], + unit_test_extras=["testing"], + system_test_extras=["testing"], + microgenerator=True, +) +s.move( + templated_files, + excludes=[ + ".coveragerc", + ".kokoro/continuous/common.cfg", + ".kokoro/presubmit/presubmit.cfg", + # exclude sample configs so periodic samples are tested against main + # instead of pypi + ".kokoro/samples/python3.6/periodic.cfg", + ".kokoro/samples/python3.7/periodic.cfg", + ".kokoro/samples/python3.8/periodic.cfg", + ".kokoro/samples/python3.9/periodic.cfg", + ".kokoro/samples/python3.10/periodic.cfg", + ".github/CODEOWNERS", + ".github/workflows", # exclude gh actions as credentials are needed for tests + ], +) # the microgenerator has a good coveragerc file + +python.py_samples(skip_readmes=True) + +python.configure_previous_major_version_branches() + +# Update samples config to use `ucaip-sample-tests` project +s.replace( + ".kokoro/samples/python3.*/common.cfg", + """env_vars: \{ + key: "BUILD_SPECIFIC_GCLOUD_PROJECT" + value: "python-docs-samples-tests-.*?" +\}""", + """env_vars: { + key: "BUILD_SPECIFIC_GCLOUD_PROJECT" + value: "ucaip-sample-tests" +}""", +) + +# Don't treat docs warnings as errors +s.replace("noxfile.py", """["']-W["'], # warnings as errors""", "") + +# Don't include tests in calculation of test coverage +s.replace("noxfile.py", """ \"--cov=tests/unit\",""", "") + +s.shell.run(["nox", "-s", "blacken"], hide_output=False) diff --git a/renovate.json b/renovate.json index c04895563e..c21036d385 100644 --- a/renovate.json +++ b/renovate.json @@ -1,6 +1,9 @@ { "extends": [ - "config:base", ":preserveSemverRanges" + "config:base", + "group:all", + ":preserveSemverRanges", + ":disableDependencyDashboard" ], "ignorePaths": [".pre-commit-config.yaml"], "pip_requirements": { diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_create_dataset_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_create_dataset_async.py new file mode 100644 index 0000000000..17d0fc381d --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_create_dataset_async.py @@ -0,0 +1,55 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateDataset +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_DatasetService_CreateDataset_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_dataset(): + # Create a client + client = aiplatform_v1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + dataset = aiplatform_v1.Dataset() + dataset.display_name = "display_name_value" + dataset.metadata_schema_uri = "metadata_schema_uri_value" + dataset.metadata.null_value = "NULL_VALUE" + + request = aiplatform_v1.CreateDatasetRequest( + parent="parent_value", + dataset=dataset, + ) + + # Make the request + operation = client.create_dataset(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_DatasetService_CreateDataset_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_create_dataset_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_create_dataset_sync.py new file mode 100644 index 0000000000..e0f69bb8db --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_create_dataset_sync.py @@ -0,0 +1,55 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateDataset +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_DatasetService_CreateDataset_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_dataset(): + # Create a client + client = aiplatform_v1.DatasetServiceClient() + + # Initialize request argument(s) + dataset = aiplatform_v1.Dataset() + dataset.display_name = "display_name_value" + dataset.metadata_schema_uri = "metadata_schema_uri_value" + dataset.metadata.null_value = "NULL_VALUE" + + request = aiplatform_v1.CreateDatasetRequest( + parent="parent_value", + dataset=dataset, + ) + + # Make the request + operation = client.create_dataset(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_DatasetService_CreateDataset_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_delete_dataset_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_delete_dataset_async.py new file mode 100644 index 0000000000..fdb4fb4133 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_delete_dataset_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteDataset +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_DatasetService_DeleteDataset_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_dataset(): + # Create a client + client = aiplatform_v1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteDatasetRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_dataset(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_DatasetService_DeleteDataset_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_delete_dataset_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_delete_dataset_sync.py new file mode 100644 index 0000000000..92fa79532c --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_delete_dataset_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteDataset +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_DatasetService_DeleteDataset_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_dataset(): + # Create a client + client = aiplatform_v1.DatasetServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteDatasetRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_dataset(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_DatasetService_DeleteDataset_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_export_data_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_export_data_async.py new file mode 100644 index 0000000000..fd1820a6c3 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_export_data_async.py @@ -0,0 +1,53 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_DatasetService_ExportData_async] +from google.cloud import aiplatform_v1 + + +async def sample_export_data(): + # Create a client + client = aiplatform_v1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + export_config = aiplatform_v1.ExportDataConfig() + export_config.gcs_destination.output_uri_prefix = "output_uri_prefix_value" + + request = aiplatform_v1.ExportDataRequest( + name="name_value", + export_config=export_config, + ) + + # Make the request + operation = client.export_data(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_DatasetService_ExportData_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_export_data_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_export_data_sync.py new file mode 100644 index 0000000000..2f5e55af10 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_export_data_sync.py @@ -0,0 +1,53 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_DatasetService_ExportData_sync] +from google.cloud import aiplatform_v1 + + +def sample_export_data(): + # Create a client + client = aiplatform_v1.DatasetServiceClient() + + # Initialize request argument(s) + export_config = aiplatform_v1.ExportDataConfig() + export_config.gcs_destination.output_uri_prefix = "output_uri_prefix_value" + + request = aiplatform_v1.ExportDataRequest( + name="name_value", + export_config=export_config, + ) + + # Make the request + operation = client.export_data(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_DatasetService_ExportData_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_get_annotation_spec_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_get_annotation_spec_async.py new file mode 100644 index 0000000000..2e120b46f0 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_get_annotation_spec_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetAnnotationSpec +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_DatasetService_GetAnnotationSpec_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_annotation_spec(): + # Create a client + client = aiplatform_v1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetAnnotationSpecRequest( + name="name_value", + ) + + # Make the request + response = await client.get_annotation_spec(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_DatasetService_GetAnnotationSpec_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_get_annotation_spec_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_get_annotation_spec_sync.py new file mode 100644 index 0000000000..54384727d1 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_get_annotation_spec_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetAnnotationSpec +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_DatasetService_GetAnnotationSpec_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_annotation_spec(): + # Create a client + client = aiplatform_v1.DatasetServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetAnnotationSpecRequest( + name="name_value", + ) + + # Make the request + response = client.get_annotation_spec(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_DatasetService_GetAnnotationSpec_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_get_dataset_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_get_dataset_async.py new file mode 100644 index 0000000000..79f64616c8 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_get_dataset_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetDataset +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_DatasetService_GetDataset_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_dataset(): + # Create a client + client = aiplatform_v1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetDatasetRequest( + name="name_value", + ) + + # Make the request + response = await client.get_dataset(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_DatasetService_GetDataset_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_get_dataset_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_get_dataset_sync.py new file mode 100644 index 0000000000..04c1a00317 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_get_dataset_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetDataset +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_DatasetService_GetDataset_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_dataset(): + # Create a client + client = aiplatform_v1.DatasetServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetDatasetRequest( + name="name_value", + ) + + # Make the request + response = client.get_dataset(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_DatasetService_GetDataset_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_import_data_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_import_data_async.py new file mode 100644 index 0000000000..bd3635f7cb --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_import_data_async.py @@ -0,0 +1,54 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ImportData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_DatasetService_ImportData_async] +from google.cloud import aiplatform_v1 + + +async def sample_import_data(): + # Create a client + client = aiplatform_v1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + import_configs = aiplatform_v1.ImportDataConfig() + import_configs.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + import_configs.import_schema_uri = "import_schema_uri_value" + + request = aiplatform_v1.ImportDataRequest( + name="name_value", + import_configs=import_configs, + ) + + # Make the request + operation = client.import_data(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_DatasetService_ImportData_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_import_data_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_import_data_sync.py new file mode 100644 index 0000000000..377cccfdc3 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_import_data_sync.py @@ -0,0 +1,54 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ImportData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_DatasetService_ImportData_sync] +from google.cloud import aiplatform_v1 + + +def sample_import_data(): + # Create a client + client = aiplatform_v1.DatasetServiceClient() + + # Initialize request argument(s) + import_configs = aiplatform_v1.ImportDataConfig() + import_configs.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + import_configs.import_schema_uri = "import_schema_uri_value" + + request = aiplatform_v1.ImportDataRequest( + name="name_value", + import_configs=import_configs, + ) + + # Make the request + operation = client.import_data(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_DatasetService_ImportData_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_list_annotations_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_list_annotations_async.py new file mode 100644 index 0000000000..a543d8fc1e --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_list_annotations_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListAnnotations +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_DatasetService_ListAnnotations_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_annotations(): + # Create a client + client = aiplatform_v1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListAnnotationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_annotations(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_DatasetService_ListAnnotations_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_list_annotations_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_list_annotations_sync.py new file mode 100644 index 0000000000..139e5925d6 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_list_annotations_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListAnnotations +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_DatasetService_ListAnnotations_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_annotations(): + # Create a client + client = aiplatform_v1.DatasetServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListAnnotationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_annotations(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_DatasetService_ListAnnotations_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_list_data_items_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_list_data_items_async.py new file mode 100644 index 0000000000..e881a176c0 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_list_data_items_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDataItems +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_DatasetService_ListDataItems_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_data_items(): + # Create a client + client = aiplatform_v1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListDataItemsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_data_items(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_DatasetService_ListDataItems_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_list_data_items_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_list_data_items_sync.py new file mode 100644 index 0000000000..c573f677c6 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_list_data_items_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDataItems +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_DatasetService_ListDataItems_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_data_items(): + # Create a client + client = aiplatform_v1.DatasetServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListDataItemsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_data_items(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_DatasetService_ListDataItems_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_list_datasets_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_list_datasets_async.py new file mode 100644 index 0000000000..8f28f87efa --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_list_datasets_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDatasets +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_DatasetService_ListDatasets_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_datasets(): + # Create a client + client = aiplatform_v1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListDatasetsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_datasets(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_DatasetService_ListDatasets_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_list_datasets_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_list_datasets_sync.py new file mode 100644 index 0000000000..146812d6ce --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_list_datasets_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDatasets +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_DatasetService_ListDatasets_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_datasets(): + # Create a client + client = aiplatform_v1.DatasetServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListDatasetsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_datasets(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_DatasetService_ListDatasets_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_update_dataset_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_update_dataset_async.py new file mode 100644 index 0000000000..7288d8cf61 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_update_dataset_async.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateDataset +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_DatasetService_UpdateDataset_async] +from google.cloud import aiplatform_v1 + + +async def sample_update_dataset(): + # Create a client + client = aiplatform_v1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + dataset = aiplatform_v1.Dataset() + dataset.display_name = "display_name_value" + dataset.metadata_schema_uri = "metadata_schema_uri_value" + dataset.metadata.null_value = "NULL_VALUE" + + request = aiplatform_v1.UpdateDatasetRequest( + dataset=dataset, + ) + + # Make the request + response = await client.update_dataset(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_DatasetService_UpdateDataset_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_update_dataset_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_update_dataset_sync.py new file mode 100644 index 0000000000..31b939d21f --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_dataset_service_update_dataset_sync.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateDataset +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_DatasetService_UpdateDataset_sync] +from google.cloud import aiplatform_v1 + + +def sample_update_dataset(): + # Create a client + client = aiplatform_v1.DatasetServiceClient() + + # Initialize request argument(s) + dataset = aiplatform_v1.Dataset() + dataset.display_name = "display_name_value" + dataset.metadata_schema_uri = "metadata_schema_uri_value" + dataset.metadata.null_value = "NULL_VALUE" + + request = aiplatform_v1.UpdateDatasetRequest( + dataset=dataset, + ) + + # Make the request + response = client.update_dataset(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_DatasetService_UpdateDataset_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_create_endpoint_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_create_endpoint_async.py new file mode 100644 index 0000000000..dcddb236df --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_create_endpoint_async.py @@ -0,0 +1,53 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_EndpointService_CreateEndpoint_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_endpoint(): + # Create a client + client = aiplatform_v1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + endpoint = aiplatform_v1.Endpoint() + endpoint.display_name = "display_name_value" + + request = aiplatform_v1.CreateEndpointRequest( + parent="parent_value", + endpoint=endpoint, + ) + + # Make the request + operation = client.create_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_EndpointService_CreateEndpoint_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_create_endpoint_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_create_endpoint_sync.py new file mode 100644 index 0000000000..edd8136cf5 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_create_endpoint_sync.py @@ -0,0 +1,53 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_EndpointService_CreateEndpoint_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_endpoint(): + # Create a client + client = aiplatform_v1.EndpointServiceClient() + + # Initialize request argument(s) + endpoint = aiplatform_v1.Endpoint() + endpoint.display_name = "display_name_value" + + request = aiplatform_v1.CreateEndpointRequest( + parent="parent_value", + endpoint=endpoint, + ) + + # Make the request + operation = client.create_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_EndpointService_CreateEndpoint_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_delete_endpoint_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_delete_endpoint_async.py new file mode 100644 index 0000000000..845111ab9f --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_delete_endpoint_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_EndpointService_DeleteEndpoint_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_endpoint(): + # Create a client + client = aiplatform_v1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteEndpointRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_EndpointService_DeleteEndpoint_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_delete_endpoint_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_delete_endpoint_sync.py new file mode 100644 index 0000000000..3f0c12ec1f --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_delete_endpoint_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_EndpointService_DeleteEndpoint_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_endpoint(): + # Create a client + client = aiplatform_v1.EndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteEndpointRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_EndpointService_DeleteEndpoint_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_deploy_model_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_deploy_model_async.py new file mode 100644 index 0000000000..1fd06264cb --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_deploy_model_async.py @@ -0,0 +1,54 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeployModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_EndpointService_DeployModel_async] +from google.cloud import aiplatform_v1 + + +async def sample_deploy_model(): + # Create a client + client = aiplatform_v1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + deployed_model = aiplatform_v1.DeployedModel() + deployed_model.dedicated_resources.min_replica_count = 1803 + deployed_model.model = "model_value" + + request = aiplatform_v1.DeployModelRequest( + endpoint="endpoint_value", + deployed_model=deployed_model, + ) + + # Make the request + operation = client.deploy_model(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_EndpointService_DeployModel_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_deploy_model_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_deploy_model_sync.py new file mode 100644 index 0000000000..3e865c8bd6 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_deploy_model_sync.py @@ -0,0 +1,54 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeployModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_EndpointService_DeployModel_sync] +from google.cloud import aiplatform_v1 + + +def sample_deploy_model(): + # Create a client + client = aiplatform_v1.EndpointServiceClient() + + # Initialize request argument(s) + deployed_model = aiplatform_v1.DeployedModel() + deployed_model.dedicated_resources.min_replica_count = 1803 + deployed_model.model = "model_value" + + request = aiplatform_v1.DeployModelRequest( + endpoint="endpoint_value", + deployed_model=deployed_model, + ) + + # Make the request + operation = client.deploy_model(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_EndpointService_DeployModel_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_get_endpoint_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_get_endpoint_async.py new file mode 100644 index 0000000000..9a2a1b7c10 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_get_endpoint_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_EndpointService_GetEndpoint_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_endpoint(): + # Create a client + client = aiplatform_v1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetEndpointRequest( + name="name_value", + ) + + # Make the request + response = await client.get_endpoint(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_EndpointService_GetEndpoint_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_get_endpoint_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_get_endpoint_sync.py new file mode 100644 index 0000000000..37ce3ff0c2 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_get_endpoint_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_EndpointService_GetEndpoint_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_endpoint(): + # Create a client + client = aiplatform_v1.EndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetEndpointRequest( + name="name_value", + ) + + # Make the request + response = client.get_endpoint(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_EndpointService_GetEndpoint_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_list_endpoints_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_list_endpoints_async.py new file mode 100644 index 0000000000..e017e79dd7 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_list_endpoints_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListEndpoints +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_EndpointService_ListEndpoints_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_endpoints(): + # Create a client + client = aiplatform_v1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListEndpointsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_endpoints(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_EndpointService_ListEndpoints_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_list_endpoints_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_list_endpoints_sync.py new file mode 100644 index 0000000000..4a06c86195 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_list_endpoints_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListEndpoints +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_EndpointService_ListEndpoints_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_endpoints(): + # Create a client + client = aiplatform_v1.EndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListEndpointsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_endpoints(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_EndpointService_ListEndpoints_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_undeploy_model_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_undeploy_model_async.py new file mode 100644 index 0000000000..84465cd3c8 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_undeploy_model_async.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UndeployModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_EndpointService_UndeployModel_async] +from google.cloud import aiplatform_v1 + + +async def sample_undeploy_model(): + # Create a client + client = aiplatform_v1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.UndeployModelRequest( + endpoint="endpoint_value", + deployed_model_id="deployed_model_id_value", + ) + + # Make the request + operation = client.undeploy_model(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_EndpointService_UndeployModel_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_undeploy_model_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_undeploy_model_sync.py new file mode 100644 index 0000000000..e147edf7b7 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_undeploy_model_sync.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UndeployModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_EndpointService_UndeployModel_sync] +from google.cloud import aiplatform_v1 + + +def sample_undeploy_model(): + # Create a client + client = aiplatform_v1.EndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.UndeployModelRequest( + endpoint="endpoint_value", + deployed_model_id="deployed_model_id_value", + ) + + # Make the request + operation = client.undeploy_model(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_EndpointService_UndeployModel_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_update_endpoint_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_update_endpoint_async.py new file mode 100644 index 0000000000..55bc233f38 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_update_endpoint_async.py @@ -0,0 +1,48 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_EndpointService_UpdateEndpoint_async] +from google.cloud import aiplatform_v1 + + +async def sample_update_endpoint(): + # Create a client + client = aiplatform_v1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + endpoint = aiplatform_v1.Endpoint() + endpoint.display_name = "display_name_value" + + request = aiplatform_v1.UpdateEndpointRequest( + endpoint=endpoint, + ) + + # Make the request + response = await client.update_endpoint(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_EndpointService_UpdateEndpoint_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_update_endpoint_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_update_endpoint_sync.py new file mode 100644 index 0000000000..0fd6421bca --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_endpoint_service_update_endpoint_sync.py @@ -0,0 +1,48 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_EndpointService_UpdateEndpoint_sync] +from google.cloud import aiplatform_v1 + + +def sample_update_endpoint(): + # Create a client + client = aiplatform_v1.EndpointServiceClient() + + # Initialize request argument(s) + endpoint = aiplatform_v1.Endpoint() + endpoint.display_name = "display_name_value" + + request = aiplatform_v1.UpdateEndpointRequest( + endpoint=endpoint, + ) + + # Make the request + response = client.update_endpoint(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_EndpointService_UpdateEndpoint_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_online_serving_service_read_feature_values_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_online_serving_service_read_feature_values_async.py new file mode 100644 index 0000000000..9764dc1636 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_online_serving_service_read_feature_values_async.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ReadFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreOnlineServingService_ReadFeatureValues_async] +from google.cloud import aiplatform_v1 + + +async def sample_read_feature_values(): + # Create a client + client = aiplatform_v1.FeaturestoreOnlineServingServiceAsyncClient() + + # Initialize request argument(s) + feature_selector = aiplatform_v1.FeatureSelector() + feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1.ReadFeatureValuesRequest( + entity_type="entity_type_value", + entity_id="entity_id_value", + feature_selector=feature_selector, + ) + + # Make the request + response = await client.read_feature_values(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreOnlineServingService_ReadFeatureValues_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_online_serving_service_read_feature_values_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_online_serving_service_read_feature_values_sync.py new file mode 100644 index 0000000000..649e818369 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_online_serving_service_read_feature_values_sync.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ReadFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreOnlineServingService_ReadFeatureValues_sync] +from google.cloud import aiplatform_v1 + + +def sample_read_feature_values(): + # Create a client + client = aiplatform_v1.FeaturestoreOnlineServingServiceClient() + + # Initialize request argument(s) + feature_selector = aiplatform_v1.FeatureSelector() + feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1.ReadFeatureValuesRequest( + entity_type="entity_type_value", + entity_id="entity_id_value", + feature_selector=feature_selector, + ) + + # Make the request + response = client.read_feature_values(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreOnlineServingService_ReadFeatureValues_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_online_serving_service_streaming_read_feature_values_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_online_serving_service_streaming_read_feature_values_async.py new file mode 100644 index 0000000000..1d3d272c4a --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_online_serving_service_streaming_read_feature_values_async.py @@ -0,0 +1,51 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for StreamingReadFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreOnlineServingService_StreamingReadFeatureValues_async] +from google.cloud import aiplatform_v1 + + +async def sample_streaming_read_feature_values(): + # Create a client + client = aiplatform_v1.FeaturestoreOnlineServingServiceAsyncClient() + + # Initialize request argument(s) + feature_selector = aiplatform_v1.FeatureSelector() + feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1.StreamingReadFeatureValuesRequest( + entity_type="entity_type_value", + entity_ids=['entity_ids_value_1', 'entity_ids_value_2'], + feature_selector=feature_selector, + ) + + # Make the request + stream = await client.streaming_read_feature_values(request=request) + + # Handle the response + async for response in stream: + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreOnlineServingService_StreamingReadFeatureValues_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_online_serving_service_streaming_read_feature_values_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_online_serving_service_streaming_read_feature_values_sync.py new file mode 100644 index 0000000000..9b9f9ecda1 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_online_serving_service_streaming_read_feature_values_sync.py @@ -0,0 +1,51 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for StreamingReadFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreOnlineServingService_StreamingReadFeatureValues_sync] +from google.cloud import aiplatform_v1 + + +def sample_streaming_read_feature_values(): + # Create a client + client = aiplatform_v1.FeaturestoreOnlineServingServiceClient() + + # Initialize request argument(s) + feature_selector = aiplatform_v1.FeatureSelector() + feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1.StreamingReadFeatureValuesRequest( + entity_type="entity_type_value", + entity_ids=['entity_ids_value_1', 'entity_ids_value_2'], + feature_selector=feature_selector, + ) + + # Make the request + stream = client.streaming_read_feature_values(request=request) + + # Handle the response + for response in stream: + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreOnlineServingService_StreamingReadFeatureValues_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_batch_create_features_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_batch_create_features_async.py new file mode 100644 index 0000000000..be00835750 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_batch_create_features_async.py @@ -0,0 +1,55 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchCreateFeatures +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_BatchCreateFeatures_async] +from google.cloud import aiplatform_v1 + + +async def sample_batch_create_features(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + requests = aiplatform_v1.CreateFeatureRequest() + requests.parent = "parent_value" + requests.feature.value_type = "BYTES" + requests.feature_id = "feature_id_value" + + request = aiplatform_v1.BatchCreateFeaturesRequest( + parent="parent_value", + requests=requests, + ) + + # Make the request + operation = client.batch_create_features(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_BatchCreateFeatures_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_batch_create_features_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_batch_create_features_sync.py new file mode 100644 index 0000000000..673bf9a41e --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_batch_create_features_sync.py @@ -0,0 +1,55 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchCreateFeatures +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_BatchCreateFeatures_sync] +from google.cloud import aiplatform_v1 + + +def sample_batch_create_features(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + requests = aiplatform_v1.CreateFeatureRequest() + requests.parent = "parent_value" + requests.feature.value_type = "BYTES" + requests.feature_id = "feature_id_value" + + request = aiplatform_v1.BatchCreateFeaturesRequest( + parent="parent_value", + requests=requests, + ) + + # Make the request + operation = client.batch_create_features(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_BatchCreateFeatures_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_batch_read_feature_values_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_batch_read_feature_values_async.py new file mode 100644 index 0000000000..e3f9141441 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_batch_read_feature_values_async.py @@ -0,0 +1,62 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchReadFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_BatchReadFeatureValues_async] +from google.cloud import aiplatform_v1 + + +async def sample_batch_read_feature_values(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + csv_read_instances = aiplatform_v1.CsvSource() + csv_read_instances.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + + destination = aiplatform_v1.FeatureValueDestination() + destination.bigquery_destination.output_uri = "output_uri_value" + + entity_type_specs = aiplatform_v1.EntityTypeSpec() + entity_type_specs.entity_type_id = "entity_type_id_value" + entity_type_specs.feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1.BatchReadFeatureValuesRequest( + csv_read_instances=csv_read_instances, + featurestore="featurestore_value", + destination=destination, + entity_type_specs=entity_type_specs, + ) + + # Make the request + operation = client.batch_read_feature_values(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_BatchReadFeatureValues_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_batch_read_feature_values_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_batch_read_feature_values_sync.py new file mode 100644 index 0000000000..9a6a2b222c --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_batch_read_feature_values_sync.py @@ -0,0 +1,62 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchReadFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_BatchReadFeatureValues_sync] +from google.cloud import aiplatform_v1 + + +def sample_batch_read_feature_values(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + csv_read_instances = aiplatform_v1.CsvSource() + csv_read_instances.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + + destination = aiplatform_v1.FeatureValueDestination() + destination.bigquery_destination.output_uri = "output_uri_value" + + entity_type_specs = aiplatform_v1.EntityTypeSpec() + entity_type_specs.entity_type_id = "entity_type_id_value" + entity_type_specs.feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1.BatchReadFeatureValuesRequest( + csv_read_instances=csv_read_instances, + featurestore="featurestore_value", + destination=destination, + entity_type_specs=entity_type_specs, + ) + + # Make the request + operation = client.batch_read_feature_values(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_BatchReadFeatureValues_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_create_entity_type_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_create_entity_type_async.py new file mode 100644 index 0000000000..817d3c1f57 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_create_entity_type_async.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateEntityType +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_CreateEntityType_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_entity_type(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateEntityTypeRequest( + parent="parent_value", + entity_type_id="entity_type_id_value", + ) + + # Make the request + operation = client.create_entity_type(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_CreateEntityType_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_create_entity_type_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_create_entity_type_sync.py new file mode 100644 index 0000000000..bc39909b48 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_create_entity_type_sync.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateEntityType +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_CreateEntityType_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_entity_type(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateEntityTypeRequest( + parent="parent_value", + entity_type_id="entity_type_id_value", + ) + + # Make the request + operation = client.create_entity_type(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_CreateEntityType_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_create_feature_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_create_feature_async.py new file mode 100644 index 0000000000..bb7fc8dd07 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_create_feature_async.py @@ -0,0 +1,54 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateFeature +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_CreateFeature_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_feature(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + feature = aiplatform_v1.Feature() + feature.value_type = "BYTES" + + request = aiplatform_v1.CreateFeatureRequest( + parent="parent_value", + feature=feature, + feature_id="feature_id_value", + ) + + # Make the request + operation = client.create_feature(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_CreateFeature_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_create_feature_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_create_feature_sync.py new file mode 100644 index 0000000000..5ea40980e2 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_create_feature_sync.py @@ -0,0 +1,54 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateFeature +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_CreateFeature_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_feature(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + feature = aiplatform_v1.Feature() + feature.value_type = "BYTES" + + request = aiplatform_v1.CreateFeatureRequest( + parent="parent_value", + feature=feature, + feature_id="feature_id_value", + ) + + # Make the request + operation = client.create_feature(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_CreateFeature_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_create_featurestore_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_create_featurestore_async.py new file mode 100644 index 0000000000..4e72359647 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_create_featurestore_async.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateFeaturestore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_CreateFeaturestore_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_featurestore(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateFeaturestoreRequest( + parent="parent_value", + featurestore_id="featurestore_id_value", + ) + + # Make the request + operation = client.create_featurestore(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_CreateFeaturestore_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_create_featurestore_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_create_featurestore_sync.py new file mode 100644 index 0000000000..0d79df38f0 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_create_featurestore_sync.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateFeaturestore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_CreateFeaturestore_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_featurestore(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateFeaturestoreRequest( + parent="parent_value", + featurestore_id="featurestore_id_value", + ) + + # Make the request + operation = client.create_featurestore(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_CreateFeaturestore_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_delete_entity_type_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_delete_entity_type_async.py new file mode 100644 index 0000000000..323b33a8f0 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_delete_entity_type_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteEntityType +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_DeleteEntityType_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_entity_type(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteEntityTypeRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_entity_type(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_DeleteEntityType_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_delete_entity_type_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_delete_entity_type_sync.py new file mode 100644 index 0000000000..43e88d2f0b --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_delete_entity_type_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteEntityType +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_DeleteEntityType_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_entity_type(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteEntityTypeRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_entity_type(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_DeleteEntityType_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_delete_feature_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_delete_feature_async.py new file mode 100644 index 0000000000..ab4c6314f1 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_delete_feature_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteFeature +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_DeleteFeature_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_feature(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteFeatureRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_feature(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_DeleteFeature_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_delete_feature_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_delete_feature_sync.py new file mode 100644 index 0000000000..c2efc05690 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_delete_feature_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteFeature +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_DeleteFeature_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_feature(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteFeatureRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_feature(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_DeleteFeature_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_delete_featurestore_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_delete_featurestore_async.py new file mode 100644 index 0000000000..e8257380e4 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_delete_featurestore_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteFeaturestore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_DeleteFeaturestore_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_featurestore(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteFeaturestoreRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_featurestore(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_DeleteFeaturestore_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_delete_featurestore_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_delete_featurestore_sync.py new file mode 100644 index 0000000000..241bde9b2a --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_delete_featurestore_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteFeaturestore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_DeleteFeaturestore_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_featurestore(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteFeaturestoreRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_featurestore(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_DeleteFeaturestore_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_export_feature_values_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_export_feature_values_async.py new file mode 100644 index 0000000000..5023b2e41f --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_export_feature_values_async.py @@ -0,0 +1,57 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_ExportFeatureValues_async] +from google.cloud import aiplatform_v1 + + +async def sample_export_feature_values(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + destination = aiplatform_v1.FeatureValueDestination() + destination.bigquery_destination.output_uri = "output_uri_value" + + feature_selector = aiplatform_v1.FeatureSelector() + feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1.ExportFeatureValuesRequest( + entity_type="entity_type_value", + destination=destination, + feature_selector=feature_selector, + ) + + # Make the request + operation = client.export_feature_values(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_ExportFeatureValues_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_export_feature_values_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_export_feature_values_sync.py new file mode 100644 index 0000000000..25f376bef4 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_export_feature_values_sync.py @@ -0,0 +1,57 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_ExportFeatureValues_sync] +from google.cloud import aiplatform_v1 + + +def sample_export_feature_values(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + destination = aiplatform_v1.FeatureValueDestination() + destination.bigquery_destination.output_uri = "output_uri_value" + + feature_selector = aiplatform_v1.FeatureSelector() + feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1.ExportFeatureValuesRequest( + entity_type="entity_type_value", + destination=destination, + feature_selector=feature_selector, + ) + + # Make the request + operation = client.export_feature_values(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_ExportFeatureValues_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_get_entity_type_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_get_entity_type_async.py new file mode 100644 index 0000000000..3880543111 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_get_entity_type_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetEntityType +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_GetEntityType_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_entity_type(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetEntityTypeRequest( + name="name_value", + ) + + # Make the request + response = await client.get_entity_type(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_GetEntityType_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_get_entity_type_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_get_entity_type_sync.py new file mode 100644 index 0000000000..61f9b7b083 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_get_entity_type_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetEntityType +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_GetEntityType_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_entity_type(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetEntityTypeRequest( + name="name_value", + ) + + # Make the request + response = client.get_entity_type(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_GetEntityType_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_get_feature_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_get_feature_async.py new file mode 100644 index 0000000000..4ac406bb48 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_get_feature_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetFeature +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_GetFeature_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_feature(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetFeatureRequest( + name="name_value", + ) + + # Make the request + response = await client.get_feature(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_GetFeature_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_get_feature_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_get_feature_sync.py new file mode 100644 index 0000000000..0268415d7b --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_get_feature_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetFeature +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_GetFeature_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_feature(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetFeatureRequest( + name="name_value", + ) + + # Make the request + response = client.get_feature(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_GetFeature_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_get_featurestore_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_get_featurestore_async.py new file mode 100644 index 0000000000..212100105d --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_get_featurestore_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetFeaturestore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_GetFeaturestore_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_featurestore(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetFeaturestoreRequest( + name="name_value", + ) + + # Make the request + response = await client.get_featurestore(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_GetFeaturestore_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_get_featurestore_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_get_featurestore_sync.py new file mode 100644 index 0000000000..f02e9d9c5a --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_get_featurestore_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetFeaturestore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_GetFeaturestore_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_featurestore(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetFeaturestoreRequest( + name="name_value", + ) + + # Make the request + response = client.get_featurestore(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_GetFeaturestore_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_import_feature_values_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_import_feature_values_async.py new file mode 100644 index 0000000000..fb38d59f8b --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_import_feature_values_async.py @@ -0,0 +1,58 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ImportFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_ImportFeatureValues_async] +from google.cloud import aiplatform_v1 + + +async def sample_import_feature_values(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + avro_source = aiplatform_v1.AvroSource() + avro_source.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + + feature_specs = aiplatform_v1.FeatureSpec() + feature_specs.id = "id_value" + + request = aiplatform_v1.ImportFeatureValuesRequest( + avro_source=avro_source, + feature_time_field="feature_time_field_value", + entity_type="entity_type_value", + feature_specs=feature_specs, + ) + + # Make the request + operation = client.import_feature_values(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_ImportFeatureValues_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_import_feature_values_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_import_feature_values_sync.py new file mode 100644 index 0000000000..7cf027567e --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_import_feature_values_sync.py @@ -0,0 +1,58 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ImportFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_ImportFeatureValues_sync] +from google.cloud import aiplatform_v1 + + +def sample_import_feature_values(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + avro_source = aiplatform_v1.AvroSource() + avro_source.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + + feature_specs = aiplatform_v1.FeatureSpec() + feature_specs.id = "id_value" + + request = aiplatform_v1.ImportFeatureValuesRequest( + avro_source=avro_source, + feature_time_field="feature_time_field_value", + entity_type="entity_type_value", + feature_specs=feature_specs, + ) + + # Make the request + operation = client.import_feature_values(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_ImportFeatureValues_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_list_entity_types_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_list_entity_types_async.py new file mode 100644 index 0000000000..2fa1182336 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_list_entity_types_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListEntityTypes +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_ListEntityTypes_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_entity_types(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListEntityTypesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_entity_types(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_ListEntityTypes_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_list_entity_types_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_list_entity_types_sync.py new file mode 100644 index 0000000000..c25ca9824d --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_list_entity_types_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListEntityTypes +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_ListEntityTypes_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_entity_types(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListEntityTypesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_entity_types(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_ListEntityTypes_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_list_features_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_list_features_async.py new file mode 100644 index 0000000000..f91fff3725 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_list_features_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListFeatures +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_ListFeatures_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_features(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListFeaturesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_features(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_ListFeatures_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_list_features_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_list_features_sync.py new file mode 100644 index 0000000000..cb26aec168 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_list_features_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListFeatures +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_ListFeatures_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_features(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListFeaturesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_features(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_ListFeatures_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_list_featurestores_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_list_featurestores_async.py new file mode 100644 index 0000000000..7c11ffcb3b --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_list_featurestores_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListFeaturestores +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_ListFeaturestores_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_featurestores(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListFeaturestoresRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_featurestores(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_ListFeaturestores_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_list_featurestores_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_list_featurestores_sync.py new file mode 100644 index 0000000000..76c4789a2a --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_list_featurestores_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListFeaturestores +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_ListFeaturestores_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_featurestores(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListFeaturestoresRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_featurestores(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_ListFeaturestores_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_search_features_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_search_features_async.py new file mode 100644 index 0000000000..f69587c7c1 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_search_features_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SearchFeatures +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_SearchFeatures_async] +from google.cloud import aiplatform_v1 + + +async def sample_search_features(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.SearchFeaturesRequest( + location="location_value", + ) + + # Make the request + page_result = client.search_features(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_SearchFeatures_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_search_features_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_search_features_sync.py new file mode 100644 index 0000000000..9ca48fcf9b --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_search_features_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SearchFeatures +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_SearchFeatures_sync] +from google.cloud import aiplatform_v1 + + +def sample_search_features(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.SearchFeaturesRequest( + location="location_value", + ) + + # Make the request + page_result = client.search_features(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_SearchFeatures_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_update_entity_type_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_update_entity_type_async.py new file mode 100644 index 0000000000..2b7c77857e --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_update_entity_type_async.py @@ -0,0 +1,44 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateEntityType +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_UpdateEntityType_async] +from google.cloud import aiplatform_v1 + + +async def sample_update_entity_type(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.UpdateEntityTypeRequest( + ) + + # Make the request + response = await client.update_entity_type(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_UpdateEntityType_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_update_entity_type_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_update_entity_type_sync.py new file mode 100644 index 0000000000..b44432172a --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_update_entity_type_sync.py @@ -0,0 +1,44 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateEntityType +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_UpdateEntityType_sync] +from google.cloud import aiplatform_v1 + + +def sample_update_entity_type(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.UpdateEntityTypeRequest( + ) + + # Make the request + response = client.update_entity_type(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_UpdateEntityType_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_update_feature_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_update_feature_async.py new file mode 100644 index 0000000000..3fee9302ba --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_update_feature_async.py @@ -0,0 +1,48 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateFeature +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_UpdateFeature_async] +from google.cloud import aiplatform_v1 + + +async def sample_update_feature(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + feature = aiplatform_v1.Feature() + feature.value_type = "BYTES" + + request = aiplatform_v1.UpdateFeatureRequest( + feature=feature, + ) + + # Make the request + response = await client.update_feature(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_UpdateFeature_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_update_feature_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_update_feature_sync.py new file mode 100644 index 0000000000..5e8945aa58 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_update_feature_sync.py @@ -0,0 +1,48 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateFeature +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_UpdateFeature_sync] +from google.cloud import aiplatform_v1 + + +def sample_update_feature(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + feature = aiplatform_v1.Feature() + feature.value_type = "BYTES" + + request = aiplatform_v1.UpdateFeatureRequest( + feature=feature, + ) + + # Make the request + response = client.update_feature(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_UpdateFeature_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_update_featurestore_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_update_featurestore_async.py new file mode 100644 index 0000000000..98c69688de --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_update_featurestore_async.py @@ -0,0 +1,48 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateFeaturestore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_UpdateFeaturestore_async] +from google.cloud import aiplatform_v1 + + +async def sample_update_featurestore(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.UpdateFeaturestoreRequest( + ) + + # Make the request + operation = client.update_featurestore(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_UpdateFeaturestore_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_update_featurestore_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_update_featurestore_sync.py new file mode 100644 index 0000000000..44922e7a70 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_featurestore_service_update_featurestore_sync.py @@ -0,0 +1,48 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateFeaturestore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_FeaturestoreService_UpdateFeaturestore_sync] +from google.cloud import aiplatform_v1 + + +def sample_update_featurestore(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.UpdateFeaturestoreRequest( + ) + + # Make the request + operation = client.update_featurestore(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_FeaturestoreService_UpdateFeaturestore_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_create_index_endpoint_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_create_index_endpoint_async.py new file mode 100644 index 0000000000..ba85235ef1 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_create_index_endpoint_async.py @@ -0,0 +1,53 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateIndexEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_IndexEndpointService_CreateIndexEndpoint_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_index_endpoint(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + index_endpoint = aiplatform_v1.IndexEndpoint() + index_endpoint.display_name = "display_name_value" + + request = aiplatform_v1.CreateIndexEndpointRequest( + parent="parent_value", + index_endpoint=index_endpoint, + ) + + # Make the request + operation = client.create_index_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_IndexEndpointService_CreateIndexEndpoint_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_create_index_endpoint_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_create_index_endpoint_sync.py new file mode 100644 index 0000000000..d2f92fcd45 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_create_index_endpoint_sync.py @@ -0,0 +1,53 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateIndexEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_IndexEndpointService_CreateIndexEndpoint_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_index_endpoint(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceClient() + + # Initialize request argument(s) + index_endpoint = aiplatform_v1.IndexEndpoint() + index_endpoint.display_name = "display_name_value" + + request = aiplatform_v1.CreateIndexEndpointRequest( + parent="parent_value", + index_endpoint=index_endpoint, + ) + + # Make the request + operation = client.create_index_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_IndexEndpointService_CreateIndexEndpoint_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_delete_index_endpoint_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_delete_index_endpoint_async.py new file mode 100644 index 0000000000..fe53ef9440 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_delete_index_endpoint_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteIndexEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_IndexEndpointService_DeleteIndexEndpoint_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_index_endpoint(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteIndexEndpointRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_index_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_IndexEndpointService_DeleteIndexEndpoint_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_delete_index_endpoint_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_delete_index_endpoint_sync.py new file mode 100644 index 0000000000..cd9e08c984 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_delete_index_endpoint_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteIndexEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_IndexEndpointService_DeleteIndexEndpoint_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_index_endpoint(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteIndexEndpointRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_index_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_IndexEndpointService_DeleteIndexEndpoint_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_deploy_index_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_deploy_index_async.py new file mode 100644 index 0000000000..fca1fdb808 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_deploy_index_async.py @@ -0,0 +1,54 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeployIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_IndexEndpointService_DeployIndex_async] +from google.cloud import aiplatform_v1 + + +async def sample_deploy_index(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + deployed_index = aiplatform_v1.DeployedIndex() + deployed_index.id = "id_value" + deployed_index.index = "index_value" + + request = aiplatform_v1.DeployIndexRequest( + index_endpoint="index_endpoint_value", + deployed_index=deployed_index, + ) + + # Make the request + operation = client.deploy_index(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_IndexEndpointService_DeployIndex_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_deploy_index_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_deploy_index_sync.py new file mode 100644 index 0000000000..be29db6888 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_deploy_index_sync.py @@ -0,0 +1,54 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeployIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_IndexEndpointService_DeployIndex_sync] +from google.cloud import aiplatform_v1 + + +def sample_deploy_index(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceClient() + + # Initialize request argument(s) + deployed_index = aiplatform_v1.DeployedIndex() + deployed_index.id = "id_value" + deployed_index.index = "index_value" + + request = aiplatform_v1.DeployIndexRequest( + index_endpoint="index_endpoint_value", + deployed_index=deployed_index, + ) + + # Make the request + operation = client.deploy_index(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_IndexEndpointService_DeployIndex_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_get_index_endpoint_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_get_index_endpoint_async.py new file mode 100644 index 0000000000..128a504b27 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_get_index_endpoint_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetIndexEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_IndexEndpointService_GetIndexEndpoint_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_index_endpoint(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetIndexEndpointRequest( + name="name_value", + ) + + # Make the request + response = await client.get_index_endpoint(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_IndexEndpointService_GetIndexEndpoint_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_get_index_endpoint_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_get_index_endpoint_sync.py new file mode 100644 index 0000000000..4112a20993 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_get_index_endpoint_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetIndexEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_IndexEndpointService_GetIndexEndpoint_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_index_endpoint(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetIndexEndpointRequest( + name="name_value", + ) + + # Make the request + response = client.get_index_endpoint(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_IndexEndpointService_GetIndexEndpoint_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_list_index_endpoints_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_list_index_endpoints_async.py new file mode 100644 index 0000000000..9f867ba780 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_list_index_endpoints_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListIndexEndpoints +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_IndexEndpointService_ListIndexEndpoints_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_index_endpoints(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListIndexEndpointsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_index_endpoints(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_IndexEndpointService_ListIndexEndpoints_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_list_index_endpoints_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_list_index_endpoints_sync.py new file mode 100644 index 0000000000..a763694f2b --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_list_index_endpoints_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListIndexEndpoints +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_IndexEndpointService_ListIndexEndpoints_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_index_endpoints(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListIndexEndpointsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_index_endpoints(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_IndexEndpointService_ListIndexEndpoints_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_mutate_deployed_index_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_mutate_deployed_index_async.py new file mode 100644 index 0000000000..18f833840f --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_mutate_deployed_index_async.py @@ -0,0 +1,54 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for MutateDeployedIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_IndexEndpointService_MutateDeployedIndex_async] +from google.cloud import aiplatform_v1 + + +async def sample_mutate_deployed_index(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + deployed_index = aiplatform_v1.DeployedIndex() + deployed_index.id = "id_value" + deployed_index.index = "index_value" + + request = aiplatform_v1.MutateDeployedIndexRequest( + index_endpoint="index_endpoint_value", + deployed_index=deployed_index, + ) + + # Make the request + operation = client.mutate_deployed_index(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_IndexEndpointService_MutateDeployedIndex_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_mutate_deployed_index_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_mutate_deployed_index_sync.py new file mode 100644 index 0000000000..f2c8a7956f --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_mutate_deployed_index_sync.py @@ -0,0 +1,54 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for MutateDeployedIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_IndexEndpointService_MutateDeployedIndex_sync] +from google.cloud import aiplatform_v1 + + +def sample_mutate_deployed_index(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceClient() + + # Initialize request argument(s) + deployed_index = aiplatform_v1.DeployedIndex() + deployed_index.id = "id_value" + deployed_index.index = "index_value" + + request = aiplatform_v1.MutateDeployedIndexRequest( + index_endpoint="index_endpoint_value", + deployed_index=deployed_index, + ) + + # Make the request + operation = client.mutate_deployed_index(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_IndexEndpointService_MutateDeployedIndex_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_undeploy_index_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_undeploy_index_async.py new file mode 100644 index 0000000000..d87bd75490 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_undeploy_index_async.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UndeployIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_IndexEndpointService_UndeployIndex_async] +from google.cloud import aiplatform_v1 + + +async def sample_undeploy_index(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.UndeployIndexRequest( + index_endpoint="index_endpoint_value", + deployed_index_id="deployed_index_id_value", + ) + + # Make the request + operation = client.undeploy_index(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_IndexEndpointService_UndeployIndex_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_undeploy_index_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_undeploy_index_sync.py new file mode 100644 index 0000000000..b3fa439c81 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_undeploy_index_sync.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UndeployIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_IndexEndpointService_UndeployIndex_sync] +from google.cloud import aiplatform_v1 + + +def sample_undeploy_index(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.UndeployIndexRequest( + index_endpoint="index_endpoint_value", + deployed_index_id="deployed_index_id_value", + ) + + # Make the request + operation = client.undeploy_index(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_IndexEndpointService_UndeployIndex_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_update_index_endpoint_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_update_index_endpoint_async.py new file mode 100644 index 0000000000..44000606a9 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_update_index_endpoint_async.py @@ -0,0 +1,48 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateIndexEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_IndexEndpointService_UpdateIndexEndpoint_async] +from google.cloud import aiplatform_v1 + + +async def sample_update_index_endpoint(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + index_endpoint = aiplatform_v1.IndexEndpoint() + index_endpoint.display_name = "display_name_value" + + request = aiplatform_v1.UpdateIndexEndpointRequest( + index_endpoint=index_endpoint, + ) + + # Make the request + response = await client.update_index_endpoint(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_IndexEndpointService_UpdateIndexEndpoint_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_update_index_endpoint_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_update_index_endpoint_sync.py new file mode 100644 index 0000000000..dbde72ae6f --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_endpoint_service_update_index_endpoint_sync.py @@ -0,0 +1,48 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateIndexEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_IndexEndpointService_UpdateIndexEndpoint_sync] +from google.cloud import aiplatform_v1 + + +def sample_update_index_endpoint(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceClient() + + # Initialize request argument(s) + index_endpoint = aiplatform_v1.IndexEndpoint() + index_endpoint.display_name = "display_name_value" + + request = aiplatform_v1.UpdateIndexEndpointRequest( + index_endpoint=index_endpoint, + ) + + # Make the request + response = client.update_index_endpoint(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_IndexEndpointService_UpdateIndexEndpoint_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_service_create_index_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_service_create_index_async.py new file mode 100644 index 0000000000..ff75fd6c7c --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_service_create_index_async.py @@ -0,0 +1,53 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_IndexService_CreateIndex_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_index(): + # Create a client + client = aiplatform_v1.IndexServiceAsyncClient() + + # Initialize request argument(s) + index = aiplatform_v1.Index() + index.display_name = "display_name_value" + + request = aiplatform_v1.CreateIndexRequest( + parent="parent_value", + index=index, + ) + + # Make the request + operation = client.create_index(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_IndexService_CreateIndex_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_service_create_index_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_service_create_index_sync.py new file mode 100644 index 0000000000..59bf750980 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_service_create_index_sync.py @@ -0,0 +1,53 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_IndexService_CreateIndex_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_index(): + # Create a client + client = aiplatform_v1.IndexServiceClient() + + # Initialize request argument(s) + index = aiplatform_v1.Index() + index.display_name = "display_name_value" + + request = aiplatform_v1.CreateIndexRequest( + parent="parent_value", + index=index, + ) + + # Make the request + operation = client.create_index(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_IndexService_CreateIndex_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_service_delete_index_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_service_delete_index_async.py new file mode 100644 index 0000000000..c28b31a8dd --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_service_delete_index_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_IndexService_DeleteIndex_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_index(): + # Create a client + client = aiplatform_v1.IndexServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteIndexRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_index(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_IndexService_DeleteIndex_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_service_delete_index_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_service_delete_index_sync.py new file mode 100644 index 0000000000..867b0ca5f2 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_service_delete_index_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_IndexService_DeleteIndex_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_index(): + # Create a client + client = aiplatform_v1.IndexServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteIndexRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_index(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_IndexService_DeleteIndex_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_service_get_index_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_service_get_index_async.py new file mode 100644 index 0000000000..d394cc0c91 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_service_get_index_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_IndexService_GetIndex_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_index(): + # Create a client + client = aiplatform_v1.IndexServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetIndexRequest( + name="name_value", + ) + + # Make the request + response = await client.get_index(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_IndexService_GetIndex_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_service_get_index_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_service_get_index_sync.py new file mode 100644 index 0000000000..f59aa54913 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_service_get_index_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_IndexService_GetIndex_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_index(): + # Create a client + client = aiplatform_v1.IndexServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetIndexRequest( + name="name_value", + ) + + # Make the request + response = client.get_index(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_IndexService_GetIndex_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_service_list_indexes_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_service_list_indexes_async.py new file mode 100644 index 0000000000..5aa51a9aea --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_service_list_indexes_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListIndexes +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_IndexService_ListIndexes_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_indexes(): + # Create a client + client = aiplatform_v1.IndexServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListIndexesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_indexes(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_IndexService_ListIndexes_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_service_list_indexes_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_service_list_indexes_sync.py new file mode 100644 index 0000000000..4d09207b88 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_service_list_indexes_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListIndexes +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_IndexService_ListIndexes_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_indexes(): + # Create a client + client = aiplatform_v1.IndexServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListIndexesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_indexes(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_IndexService_ListIndexes_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_service_update_index_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_service_update_index_async.py new file mode 100644 index 0000000000..c9b77e9c73 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_service_update_index_async.py @@ -0,0 +1,52 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_IndexService_UpdateIndex_async] +from google.cloud import aiplatform_v1 + + +async def sample_update_index(): + # Create a client + client = aiplatform_v1.IndexServiceAsyncClient() + + # Initialize request argument(s) + index = aiplatform_v1.Index() + index.display_name = "display_name_value" + + request = aiplatform_v1.UpdateIndexRequest( + index=index, + ) + + # Make the request + operation = client.update_index(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_IndexService_UpdateIndex_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_service_update_index_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_service_update_index_sync.py new file mode 100644 index 0000000000..77f0a34dd6 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_index_service_update_index_sync.py @@ -0,0 +1,52 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_IndexService_UpdateIndex_sync] +from google.cloud import aiplatform_v1 + + +def sample_update_index(): + # Create a client + client = aiplatform_v1.IndexServiceClient() + + # Initialize request argument(s) + index = aiplatform_v1.Index() + index.display_name = "display_name_value" + + request = aiplatform_v1.UpdateIndexRequest( + index=index, + ) + + # Make the request + operation = client.update_index(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_IndexService_UpdateIndex_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_cancel_batch_prediction_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_cancel_batch_prediction_job_async.py new file mode 100644 index 0000000000..3851a47fdb --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_cancel_batch_prediction_job_async.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelBatchPredictionJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_CancelBatchPredictionJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_cancel_batch_prediction_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CancelBatchPredictionJobRequest( + name="name_value", + ) + + # Make the request + await client.cancel_batch_prediction_job(request=request) + + +# [END aiplatform_generated_aiplatform_v1_JobService_CancelBatchPredictionJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_cancel_batch_prediction_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_cancel_batch_prediction_job_sync.py new file mode 100644 index 0000000000..b1b77354c5 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_cancel_batch_prediction_job_sync.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelBatchPredictionJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_CancelBatchPredictionJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_cancel_batch_prediction_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CancelBatchPredictionJobRequest( + name="name_value", + ) + + # Make the request + client.cancel_batch_prediction_job(request=request) + + +# [END aiplatform_generated_aiplatform_v1_JobService_CancelBatchPredictionJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_cancel_custom_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_cancel_custom_job_async.py new file mode 100644 index 0000000000..1ab12e6b03 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_cancel_custom_job_async.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelCustomJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_CancelCustomJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_cancel_custom_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CancelCustomJobRequest( + name="name_value", + ) + + # Make the request + await client.cancel_custom_job(request=request) + + +# [END aiplatform_generated_aiplatform_v1_JobService_CancelCustomJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_cancel_custom_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_cancel_custom_job_sync.py new file mode 100644 index 0000000000..b246ad41b5 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_cancel_custom_job_sync.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelCustomJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_CancelCustomJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_cancel_custom_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CancelCustomJobRequest( + name="name_value", + ) + + # Make the request + client.cancel_custom_job(request=request) + + +# [END aiplatform_generated_aiplatform_v1_JobService_CancelCustomJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_cancel_data_labeling_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_cancel_data_labeling_job_async.py new file mode 100644 index 0000000000..619e954758 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_cancel_data_labeling_job_async.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelDataLabelingJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_CancelDataLabelingJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_cancel_data_labeling_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CancelDataLabelingJobRequest( + name="name_value", + ) + + # Make the request + await client.cancel_data_labeling_job(request=request) + + +# [END aiplatform_generated_aiplatform_v1_JobService_CancelDataLabelingJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_cancel_data_labeling_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_cancel_data_labeling_job_sync.py new file mode 100644 index 0000000000..a76ac1e90a --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_cancel_data_labeling_job_sync.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelDataLabelingJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_CancelDataLabelingJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_cancel_data_labeling_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CancelDataLabelingJobRequest( + name="name_value", + ) + + # Make the request + client.cancel_data_labeling_job(request=request) + + +# [END aiplatform_generated_aiplatform_v1_JobService_CancelDataLabelingJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_cancel_hyperparameter_tuning_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_cancel_hyperparameter_tuning_job_async.py new file mode 100644 index 0000000000..f39141a8ef --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_cancel_hyperparameter_tuning_job_async.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelHyperparameterTuningJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_CancelHyperparameterTuningJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_cancel_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CancelHyperparameterTuningJobRequest( + name="name_value", + ) + + # Make the request + await client.cancel_hyperparameter_tuning_job(request=request) + + +# [END aiplatform_generated_aiplatform_v1_JobService_CancelHyperparameterTuningJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_cancel_hyperparameter_tuning_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_cancel_hyperparameter_tuning_job_sync.py new file mode 100644 index 0000000000..e4cdce1b63 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_cancel_hyperparameter_tuning_job_sync.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelHyperparameterTuningJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_CancelHyperparameterTuningJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_cancel_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CancelHyperparameterTuningJobRequest( + name="name_value", + ) + + # Make the request + client.cancel_hyperparameter_tuning_job(request=request) + + +# [END aiplatform_generated_aiplatform_v1_JobService_CancelHyperparameterTuningJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_create_batch_prediction_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_create_batch_prediction_job_async.py new file mode 100644 index 0000000000..71d8d78dfe --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_create_batch_prediction_job_async.py @@ -0,0 +1,53 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateBatchPredictionJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_CreateBatchPredictionJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_batch_prediction_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + batch_prediction_job = aiplatform_v1.BatchPredictionJob() + batch_prediction_job.display_name = "display_name_value" + batch_prediction_job.input_config.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + batch_prediction_job.input_config.instances_format = "instances_format_value" + batch_prediction_job.output_config.gcs_destination.output_uri_prefix = "output_uri_prefix_value" + batch_prediction_job.output_config.predictions_format = "predictions_format_value" + + request = aiplatform_v1.CreateBatchPredictionJobRequest( + parent="parent_value", + batch_prediction_job=batch_prediction_job, + ) + + # Make the request + response = await client.create_batch_prediction_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_CreateBatchPredictionJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_create_batch_prediction_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_create_batch_prediction_job_sync.py new file mode 100644 index 0000000000..f5a8add5b9 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_create_batch_prediction_job_sync.py @@ -0,0 +1,53 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateBatchPredictionJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_CreateBatchPredictionJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_batch_prediction_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + batch_prediction_job = aiplatform_v1.BatchPredictionJob() + batch_prediction_job.display_name = "display_name_value" + batch_prediction_job.input_config.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + batch_prediction_job.input_config.instances_format = "instances_format_value" + batch_prediction_job.output_config.gcs_destination.output_uri_prefix = "output_uri_prefix_value" + batch_prediction_job.output_config.predictions_format = "predictions_format_value" + + request = aiplatform_v1.CreateBatchPredictionJobRequest( + parent="parent_value", + batch_prediction_job=batch_prediction_job, + ) + + # Make the request + response = client.create_batch_prediction_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_CreateBatchPredictionJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_create_custom_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_create_custom_job_async.py new file mode 100644 index 0000000000..1240d3adf9 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_create_custom_job_async.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateCustomJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_CreateCustomJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_custom_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + custom_job = aiplatform_v1.CustomJob() + custom_job.display_name = "display_name_value" + custom_job.job_spec.worker_pool_specs.container_spec.image_uri = "image_uri_value" + + request = aiplatform_v1.CreateCustomJobRequest( + parent="parent_value", + custom_job=custom_job, + ) + + # Make the request + response = await client.create_custom_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_CreateCustomJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_create_custom_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_create_custom_job_sync.py new file mode 100644 index 0000000000..6df33d3d86 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_create_custom_job_sync.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateCustomJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_CreateCustomJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_custom_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + custom_job = aiplatform_v1.CustomJob() + custom_job.display_name = "display_name_value" + custom_job.job_spec.worker_pool_specs.container_spec.image_uri = "image_uri_value" + + request = aiplatform_v1.CreateCustomJobRequest( + parent="parent_value", + custom_job=custom_job, + ) + + # Make the request + response = client.create_custom_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_CreateCustomJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_create_data_labeling_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_create_data_labeling_job_async.py new file mode 100644 index 0000000000..40b4b2717f --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_create_data_labeling_job_async.py @@ -0,0 +1,54 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateDataLabelingJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_CreateDataLabelingJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_data_labeling_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + data_labeling_job = aiplatform_v1.DataLabelingJob() + data_labeling_job.display_name = "display_name_value" + data_labeling_job.datasets = ['datasets_value_1', 'datasets_value_2'] + data_labeling_job.labeler_count = 1375 + data_labeling_job.instruction_uri = "instruction_uri_value" + data_labeling_job.inputs_schema_uri = "inputs_schema_uri_value" + data_labeling_job.inputs.null_value = "NULL_VALUE" + + request = aiplatform_v1.CreateDataLabelingJobRequest( + parent="parent_value", + data_labeling_job=data_labeling_job, + ) + + # Make the request + response = await client.create_data_labeling_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_CreateDataLabelingJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_create_data_labeling_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_create_data_labeling_job_sync.py new file mode 100644 index 0000000000..8e363825e0 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_create_data_labeling_job_sync.py @@ -0,0 +1,54 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateDataLabelingJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_CreateDataLabelingJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_data_labeling_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + data_labeling_job = aiplatform_v1.DataLabelingJob() + data_labeling_job.display_name = "display_name_value" + data_labeling_job.datasets = ['datasets_value_1', 'datasets_value_2'] + data_labeling_job.labeler_count = 1375 + data_labeling_job.instruction_uri = "instruction_uri_value" + data_labeling_job.inputs_schema_uri = "inputs_schema_uri_value" + data_labeling_job.inputs.null_value = "NULL_VALUE" + + request = aiplatform_v1.CreateDataLabelingJobRequest( + parent="parent_value", + data_labeling_job=data_labeling_job, + ) + + # Make the request + response = client.create_data_labeling_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_CreateDataLabelingJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_create_hyperparameter_tuning_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_create_hyperparameter_tuning_job_async.py new file mode 100644 index 0000000000..edf9bcc230 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_create_hyperparameter_tuning_job_async.py @@ -0,0 +1,57 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateHyperparameterTuningJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_CreateHyperparameterTuningJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + hyperparameter_tuning_job = aiplatform_v1.HyperparameterTuningJob() + hyperparameter_tuning_job.display_name = "display_name_value" + hyperparameter_tuning_job.study_spec.metrics.metric_id = "metric_id_value" + hyperparameter_tuning_job.study_spec.metrics.goal = "MINIMIZE" + hyperparameter_tuning_job.study_spec.parameters.double_value_spec.min_value = 0.96 + hyperparameter_tuning_job.study_spec.parameters.double_value_spec.max_value = 0.962 + hyperparameter_tuning_job.study_spec.parameters.parameter_id = "parameter_id_value" + hyperparameter_tuning_job.max_trial_count = 1609 + hyperparameter_tuning_job.parallel_trial_count = 2128 + hyperparameter_tuning_job.trial_job_spec.worker_pool_specs.container_spec.image_uri = "image_uri_value" + + request = aiplatform_v1.CreateHyperparameterTuningJobRequest( + parent="parent_value", + hyperparameter_tuning_job=hyperparameter_tuning_job, + ) + + # Make the request + response = await client.create_hyperparameter_tuning_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_CreateHyperparameterTuningJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_create_hyperparameter_tuning_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_create_hyperparameter_tuning_job_sync.py new file mode 100644 index 0000000000..99948bcb86 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_create_hyperparameter_tuning_job_sync.py @@ -0,0 +1,57 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateHyperparameterTuningJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_CreateHyperparameterTuningJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + hyperparameter_tuning_job = aiplatform_v1.HyperparameterTuningJob() + hyperparameter_tuning_job.display_name = "display_name_value" + hyperparameter_tuning_job.study_spec.metrics.metric_id = "metric_id_value" + hyperparameter_tuning_job.study_spec.metrics.goal = "MINIMIZE" + hyperparameter_tuning_job.study_spec.parameters.double_value_spec.min_value = 0.96 + hyperparameter_tuning_job.study_spec.parameters.double_value_spec.max_value = 0.962 + hyperparameter_tuning_job.study_spec.parameters.parameter_id = "parameter_id_value" + hyperparameter_tuning_job.max_trial_count = 1609 + hyperparameter_tuning_job.parallel_trial_count = 2128 + hyperparameter_tuning_job.trial_job_spec.worker_pool_specs.container_spec.image_uri = "image_uri_value" + + request = aiplatform_v1.CreateHyperparameterTuningJobRequest( + parent="parent_value", + hyperparameter_tuning_job=hyperparameter_tuning_job, + ) + + # Make the request + response = client.create_hyperparameter_tuning_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_CreateHyperparameterTuningJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_create_model_deployment_monitoring_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_create_model_deployment_monitoring_job_async.py new file mode 100644 index 0000000000..77f8f678ee --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_create_model_deployment_monitoring_job_async.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_CreateModelDeploymentMonitoringJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + model_deployment_monitoring_job = aiplatform_v1.ModelDeploymentMonitoringJob() + model_deployment_monitoring_job.display_name = "display_name_value" + model_deployment_monitoring_job.endpoint = "endpoint_value" + + request = aiplatform_v1.CreateModelDeploymentMonitoringJobRequest( + parent="parent_value", + model_deployment_monitoring_job=model_deployment_monitoring_job, + ) + + # Make the request + response = await client.create_model_deployment_monitoring_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_CreateModelDeploymentMonitoringJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_create_model_deployment_monitoring_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_create_model_deployment_monitoring_job_sync.py new file mode 100644 index 0000000000..981fff73f8 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_create_model_deployment_monitoring_job_sync.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_CreateModelDeploymentMonitoringJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + model_deployment_monitoring_job = aiplatform_v1.ModelDeploymentMonitoringJob() + model_deployment_monitoring_job.display_name = "display_name_value" + model_deployment_monitoring_job.endpoint = "endpoint_value" + + request = aiplatform_v1.CreateModelDeploymentMonitoringJobRequest( + parent="parent_value", + model_deployment_monitoring_job=model_deployment_monitoring_job, + ) + + # Make the request + response = client.create_model_deployment_monitoring_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_CreateModelDeploymentMonitoringJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_delete_batch_prediction_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_delete_batch_prediction_job_async.py new file mode 100644 index 0000000000..72452a4c15 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_delete_batch_prediction_job_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteBatchPredictionJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_DeleteBatchPredictionJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_batch_prediction_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteBatchPredictionJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_batch_prediction_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_DeleteBatchPredictionJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_delete_batch_prediction_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_delete_batch_prediction_job_sync.py new file mode 100644 index 0000000000..0360478193 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_delete_batch_prediction_job_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteBatchPredictionJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_DeleteBatchPredictionJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_batch_prediction_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteBatchPredictionJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_batch_prediction_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_DeleteBatchPredictionJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_delete_custom_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_delete_custom_job_async.py new file mode 100644 index 0000000000..91d285d624 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_delete_custom_job_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteCustomJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_DeleteCustomJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_custom_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteCustomJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_custom_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_DeleteCustomJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_delete_custom_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_delete_custom_job_sync.py new file mode 100644 index 0000000000..a56d0b00ac --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_delete_custom_job_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteCustomJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_DeleteCustomJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_custom_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteCustomJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_custom_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_DeleteCustomJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_delete_data_labeling_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_delete_data_labeling_job_async.py new file mode 100644 index 0000000000..5393c94865 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_delete_data_labeling_job_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteDataLabelingJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_DeleteDataLabelingJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_data_labeling_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteDataLabelingJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_data_labeling_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_DeleteDataLabelingJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_delete_data_labeling_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_delete_data_labeling_job_sync.py new file mode 100644 index 0000000000..387353458d --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_delete_data_labeling_job_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteDataLabelingJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_DeleteDataLabelingJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_data_labeling_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteDataLabelingJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_data_labeling_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_DeleteDataLabelingJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_delete_hyperparameter_tuning_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_delete_hyperparameter_tuning_job_async.py new file mode 100644 index 0000000000..27bcb19af7 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_delete_hyperparameter_tuning_job_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteHyperparameterTuningJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_DeleteHyperparameterTuningJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteHyperparameterTuningJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_hyperparameter_tuning_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_DeleteHyperparameterTuningJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_delete_hyperparameter_tuning_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_delete_hyperparameter_tuning_job_sync.py new file mode 100644 index 0000000000..944c9dc2c5 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_delete_hyperparameter_tuning_job_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteHyperparameterTuningJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_DeleteHyperparameterTuningJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteHyperparameterTuningJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_hyperparameter_tuning_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_DeleteHyperparameterTuningJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_delete_model_deployment_monitoring_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_delete_model_deployment_monitoring_job_async.py new file mode 100644 index 0000000000..cad9752aa4 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_delete_model_deployment_monitoring_job_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_DeleteModelDeploymentMonitoringJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_model_deployment_monitoring_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_DeleteModelDeploymentMonitoringJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_delete_model_deployment_monitoring_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_delete_model_deployment_monitoring_job_sync.py new file mode 100644 index 0000000000..546970c9c3 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_delete_model_deployment_monitoring_job_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_DeleteModelDeploymentMonitoringJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_model_deployment_monitoring_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_DeleteModelDeploymentMonitoringJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_get_batch_prediction_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_get_batch_prediction_job_async.py new file mode 100644 index 0000000000..0dd8d0e2e1 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_get_batch_prediction_job_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetBatchPredictionJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_GetBatchPredictionJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_batch_prediction_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetBatchPredictionJobRequest( + name="name_value", + ) + + # Make the request + response = await client.get_batch_prediction_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_GetBatchPredictionJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_get_batch_prediction_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_get_batch_prediction_job_sync.py new file mode 100644 index 0000000000..506ad84155 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_get_batch_prediction_job_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetBatchPredictionJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_GetBatchPredictionJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_batch_prediction_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetBatchPredictionJobRequest( + name="name_value", + ) + + # Make the request + response = client.get_batch_prediction_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_GetBatchPredictionJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_get_custom_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_get_custom_job_async.py new file mode 100644 index 0000000000..b027f52650 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_get_custom_job_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetCustomJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_GetCustomJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_custom_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetCustomJobRequest( + name="name_value", + ) + + # Make the request + response = await client.get_custom_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_GetCustomJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_get_custom_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_get_custom_job_sync.py new file mode 100644 index 0000000000..9591f6553b --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_get_custom_job_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetCustomJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_GetCustomJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_custom_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetCustomJobRequest( + name="name_value", + ) + + # Make the request + response = client.get_custom_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_GetCustomJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_get_data_labeling_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_get_data_labeling_job_async.py new file mode 100644 index 0000000000..cf32bc0082 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_get_data_labeling_job_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetDataLabelingJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_GetDataLabelingJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_data_labeling_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetDataLabelingJobRequest( + name="name_value", + ) + + # Make the request + response = await client.get_data_labeling_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_GetDataLabelingJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_get_data_labeling_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_get_data_labeling_job_sync.py new file mode 100644 index 0000000000..c964904b77 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_get_data_labeling_job_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetDataLabelingJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_GetDataLabelingJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_data_labeling_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetDataLabelingJobRequest( + name="name_value", + ) + + # Make the request + response = client.get_data_labeling_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_GetDataLabelingJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_get_hyperparameter_tuning_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_get_hyperparameter_tuning_job_async.py new file mode 100644 index 0000000000..629fb743ed --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_get_hyperparameter_tuning_job_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetHyperparameterTuningJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_GetHyperparameterTuningJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetHyperparameterTuningJobRequest( + name="name_value", + ) + + # Make the request + response = await client.get_hyperparameter_tuning_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_GetHyperparameterTuningJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_get_hyperparameter_tuning_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_get_hyperparameter_tuning_job_sync.py new file mode 100644 index 0000000000..924e49ed61 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_get_hyperparameter_tuning_job_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetHyperparameterTuningJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_GetHyperparameterTuningJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetHyperparameterTuningJobRequest( + name="name_value", + ) + + # Make the request + response = client.get_hyperparameter_tuning_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_GetHyperparameterTuningJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_get_model_deployment_monitoring_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_get_model_deployment_monitoring_job_async.py new file mode 100644 index 0000000000..1597729f3a --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_get_model_deployment_monitoring_job_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_GetModelDeploymentMonitoringJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + response = await client.get_model_deployment_monitoring_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_GetModelDeploymentMonitoringJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_get_model_deployment_monitoring_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_get_model_deployment_monitoring_job_sync.py new file mode 100644 index 0000000000..42253ebf34 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_get_model_deployment_monitoring_job_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_GetModelDeploymentMonitoringJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + response = client.get_model_deployment_monitoring_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_GetModelDeploymentMonitoringJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_list_batch_prediction_jobs_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_list_batch_prediction_jobs_async.py new file mode 100644 index 0000000000..562dc0c864 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_list_batch_prediction_jobs_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListBatchPredictionJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_ListBatchPredictionJobs_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_batch_prediction_jobs(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListBatchPredictionJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_batch_prediction_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_ListBatchPredictionJobs_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_list_batch_prediction_jobs_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_list_batch_prediction_jobs_sync.py new file mode 100644 index 0000000000..5714048d83 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_list_batch_prediction_jobs_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListBatchPredictionJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_ListBatchPredictionJobs_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_batch_prediction_jobs(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListBatchPredictionJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_batch_prediction_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_ListBatchPredictionJobs_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_list_custom_jobs_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_list_custom_jobs_async.py new file mode 100644 index 0000000000..4c611c4983 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_list_custom_jobs_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListCustomJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_ListCustomJobs_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_custom_jobs(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListCustomJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_custom_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_ListCustomJobs_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_list_custom_jobs_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_list_custom_jobs_sync.py new file mode 100644 index 0000000000..028b11b299 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_list_custom_jobs_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListCustomJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_ListCustomJobs_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_custom_jobs(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListCustomJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_custom_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_ListCustomJobs_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_list_data_labeling_jobs_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_list_data_labeling_jobs_async.py new file mode 100644 index 0000000000..1bec068aa6 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_list_data_labeling_jobs_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDataLabelingJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_ListDataLabelingJobs_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_data_labeling_jobs(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListDataLabelingJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_data_labeling_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_ListDataLabelingJobs_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_list_data_labeling_jobs_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_list_data_labeling_jobs_sync.py new file mode 100644 index 0000000000..d43010fc93 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_list_data_labeling_jobs_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDataLabelingJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_ListDataLabelingJobs_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_data_labeling_jobs(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListDataLabelingJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_data_labeling_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_ListDataLabelingJobs_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_list_hyperparameter_tuning_jobs_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_list_hyperparameter_tuning_jobs_async.py new file mode 100644 index 0000000000..4d27244601 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_list_hyperparameter_tuning_jobs_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListHyperparameterTuningJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_ListHyperparameterTuningJobs_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_hyperparameter_tuning_jobs(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListHyperparameterTuningJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_hyperparameter_tuning_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_ListHyperparameterTuningJobs_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_list_hyperparameter_tuning_jobs_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_list_hyperparameter_tuning_jobs_sync.py new file mode 100644 index 0000000000..fbbb0fedec --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_list_hyperparameter_tuning_jobs_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListHyperparameterTuningJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_ListHyperparameterTuningJobs_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_hyperparameter_tuning_jobs(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListHyperparameterTuningJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_hyperparameter_tuning_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_ListHyperparameterTuningJobs_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_list_model_deployment_monitoring_jobs_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_list_model_deployment_monitoring_jobs_async.py new file mode 100644 index 0000000000..c00b05efb1 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_list_model_deployment_monitoring_jobs_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListModelDeploymentMonitoringJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_ListModelDeploymentMonitoringJobs_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_model_deployment_monitoring_jobs(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListModelDeploymentMonitoringJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_model_deployment_monitoring_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_ListModelDeploymentMonitoringJobs_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_list_model_deployment_monitoring_jobs_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_list_model_deployment_monitoring_jobs_sync.py new file mode 100644 index 0000000000..85b5955418 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_list_model_deployment_monitoring_jobs_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListModelDeploymentMonitoringJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_ListModelDeploymentMonitoringJobs_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_model_deployment_monitoring_jobs(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListModelDeploymentMonitoringJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_model_deployment_monitoring_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_ListModelDeploymentMonitoringJobs_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_pause_model_deployment_monitoring_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_pause_model_deployment_monitoring_job_async.py new file mode 100644 index 0000000000..710c96708e --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_pause_model_deployment_monitoring_job_async.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PauseModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_PauseModelDeploymentMonitoringJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_pause_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.PauseModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + await client.pause_model_deployment_monitoring_job(request=request) + + +# [END aiplatform_generated_aiplatform_v1_JobService_PauseModelDeploymentMonitoringJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_pause_model_deployment_monitoring_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_pause_model_deployment_monitoring_job_sync.py new file mode 100644 index 0000000000..66619dc233 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_pause_model_deployment_monitoring_job_sync.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PauseModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_PauseModelDeploymentMonitoringJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_pause_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.PauseModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + client.pause_model_deployment_monitoring_job(request=request) + + +# [END aiplatform_generated_aiplatform_v1_JobService_PauseModelDeploymentMonitoringJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_resume_model_deployment_monitoring_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_resume_model_deployment_monitoring_job_async.py new file mode 100644 index 0000000000..0d22122bf2 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_resume_model_deployment_monitoring_job_async.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ResumeModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_ResumeModelDeploymentMonitoringJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_resume_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ResumeModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + await client.resume_model_deployment_monitoring_job(request=request) + + +# [END aiplatform_generated_aiplatform_v1_JobService_ResumeModelDeploymentMonitoringJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_resume_model_deployment_monitoring_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_resume_model_deployment_monitoring_job_sync.py new file mode 100644 index 0000000000..7459123558 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_resume_model_deployment_monitoring_job_sync.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ResumeModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_ResumeModelDeploymentMonitoringJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_resume_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ResumeModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + client.resume_model_deployment_monitoring_job(request=request) + + +# [END aiplatform_generated_aiplatform_v1_JobService_ResumeModelDeploymentMonitoringJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_search_model_deployment_monitoring_stats_anomalies_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_search_model_deployment_monitoring_stats_anomalies_async.py new file mode 100644 index 0000000000..9d11316c95 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_search_model_deployment_monitoring_stats_anomalies_async.py @@ -0,0 +1,47 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SearchModelDeploymentMonitoringStatsAnomalies +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_SearchModelDeploymentMonitoringStatsAnomalies_async] +from google.cloud import aiplatform_v1 + + +async def sample_search_model_deployment_monitoring_stats_anomalies(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.SearchModelDeploymentMonitoringStatsAnomaliesRequest( + model_deployment_monitoring_job="model_deployment_monitoring_job_value", + deployed_model_id="deployed_model_id_value", + ) + + # Make the request + page_result = client.search_model_deployment_monitoring_stats_anomalies(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_SearchModelDeploymentMonitoringStatsAnomalies_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_search_model_deployment_monitoring_stats_anomalies_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_search_model_deployment_monitoring_stats_anomalies_sync.py new file mode 100644 index 0000000000..f816c5854b --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_search_model_deployment_monitoring_stats_anomalies_sync.py @@ -0,0 +1,47 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SearchModelDeploymentMonitoringStatsAnomalies +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_SearchModelDeploymentMonitoringStatsAnomalies_sync] +from google.cloud import aiplatform_v1 + + +def sample_search_model_deployment_monitoring_stats_anomalies(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.SearchModelDeploymentMonitoringStatsAnomaliesRequest( + model_deployment_monitoring_job="model_deployment_monitoring_job_value", + deployed_model_id="deployed_model_id_value", + ) + + # Make the request + page_result = client.search_model_deployment_monitoring_stats_anomalies(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_SearchModelDeploymentMonitoringStatsAnomalies_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_update_model_deployment_monitoring_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_update_model_deployment_monitoring_job_async.py new file mode 100644 index 0000000000..1ecb21cc25 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_update_model_deployment_monitoring_job_async.py @@ -0,0 +1,53 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_UpdateModelDeploymentMonitoringJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_update_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + model_deployment_monitoring_job = aiplatform_v1.ModelDeploymentMonitoringJob() + model_deployment_monitoring_job.display_name = "display_name_value" + model_deployment_monitoring_job.endpoint = "endpoint_value" + + request = aiplatform_v1.UpdateModelDeploymentMonitoringJobRequest( + model_deployment_monitoring_job=model_deployment_monitoring_job, + ) + + # Make the request + operation = client.update_model_deployment_monitoring_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_UpdateModelDeploymentMonitoringJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_update_model_deployment_monitoring_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_update_model_deployment_monitoring_job_sync.py new file mode 100644 index 0000000000..8e0761b616 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_job_service_update_model_deployment_monitoring_job_sync.py @@ -0,0 +1,53 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_JobService_UpdateModelDeploymentMonitoringJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_update_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + model_deployment_monitoring_job = aiplatform_v1.ModelDeploymentMonitoringJob() + model_deployment_monitoring_job.display_name = "display_name_value" + model_deployment_monitoring_job.endpoint = "endpoint_value" + + request = aiplatform_v1.UpdateModelDeploymentMonitoringJobRequest( + model_deployment_monitoring_job=model_deployment_monitoring_job, + ) + + # Make the request + operation = client.update_model_deployment_monitoring_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_JobService_UpdateModelDeploymentMonitoringJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_add_context_artifacts_and_executions_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_add_context_artifacts_and_executions_async.py new file mode 100644 index 0000000000..12192b766f --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_add_context_artifacts_and_executions_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddContextArtifactsAndExecutions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_AddContextArtifactsAndExecutions_async] +from google.cloud import aiplatform_v1 + + +async def sample_add_context_artifacts_and_executions(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.AddContextArtifactsAndExecutionsRequest( + context="context_value", + ) + + # Make the request + response = await client.add_context_artifacts_and_executions(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_AddContextArtifactsAndExecutions_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_add_context_artifacts_and_executions_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_add_context_artifacts_and_executions_sync.py new file mode 100644 index 0000000000..9d5d582497 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_add_context_artifacts_and_executions_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddContextArtifactsAndExecutions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_AddContextArtifactsAndExecutions_sync] +from google.cloud import aiplatform_v1 + + +def sample_add_context_artifacts_and_executions(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.AddContextArtifactsAndExecutionsRequest( + context="context_value", + ) + + # Make the request + response = client.add_context_artifacts_and_executions(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_AddContextArtifactsAndExecutions_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_add_context_children_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_add_context_children_async.py new file mode 100644 index 0000000000..f013bfc95d --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_add_context_children_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddContextChildren +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_AddContextChildren_async] +from google.cloud import aiplatform_v1 + + +async def sample_add_context_children(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.AddContextChildrenRequest( + context="context_value", + ) + + # Make the request + response = await client.add_context_children(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_AddContextChildren_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_add_context_children_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_add_context_children_sync.py new file mode 100644 index 0000000000..d97708f980 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_add_context_children_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddContextChildren +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_AddContextChildren_sync] +from google.cloud import aiplatform_v1 + + +def sample_add_context_children(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.AddContextChildrenRequest( + context="context_value", + ) + + # Make the request + response = client.add_context_children(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_AddContextChildren_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_add_execution_events_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_add_execution_events_async.py new file mode 100644 index 0000000000..5ea3920fbd --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_add_execution_events_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddExecutionEvents +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_AddExecutionEvents_async] +from google.cloud import aiplatform_v1 + + +async def sample_add_execution_events(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.AddExecutionEventsRequest( + execution="execution_value", + ) + + # Make the request + response = await client.add_execution_events(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_AddExecutionEvents_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_add_execution_events_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_add_execution_events_sync.py new file mode 100644 index 0000000000..b6b14e7038 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_add_execution_events_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddExecutionEvents +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_AddExecutionEvents_sync] +from google.cloud import aiplatform_v1 + + +def sample_add_execution_events(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.AddExecutionEventsRequest( + execution="execution_value", + ) + + # Make the request + response = client.add_execution_events(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_AddExecutionEvents_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_create_artifact_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_create_artifact_async.py new file mode 100644 index 0000000000..6ae63ca292 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_create_artifact_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateArtifact +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_CreateArtifact_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_artifact(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateArtifactRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_artifact(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_CreateArtifact_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_create_artifact_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_create_artifact_sync.py new file mode 100644 index 0000000000..6b911877e3 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_create_artifact_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateArtifact +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_CreateArtifact_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_artifact(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateArtifactRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_artifact(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_CreateArtifact_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_create_context_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_create_context_async.py new file mode 100644 index 0000000000..9a7209e72d --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_create_context_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateContext +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_CreateContext_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_context(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateContextRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_context(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_CreateContext_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_create_context_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_create_context_sync.py new file mode 100644 index 0000000000..551302e07c --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_create_context_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateContext +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_CreateContext_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_context(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateContextRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_context(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_CreateContext_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_create_execution_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_create_execution_async.py new file mode 100644 index 0000000000..7368effc6a --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_create_execution_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_CreateExecution_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_execution(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateExecutionRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_execution(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_CreateExecution_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_create_execution_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_create_execution_sync.py new file mode 100644 index 0000000000..7dc066993f --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_create_execution_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_CreateExecution_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_execution(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateExecutionRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_execution(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_CreateExecution_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_create_metadata_schema_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_create_metadata_schema_async.py new file mode 100644 index 0000000000..5ce36ffe98 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_create_metadata_schema_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateMetadataSchema +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_CreateMetadataSchema_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_metadata_schema(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + metadata_schema = aiplatform_v1.MetadataSchema() + metadata_schema.schema = "schema_value" + + request = aiplatform_v1.CreateMetadataSchemaRequest( + parent="parent_value", + metadata_schema=metadata_schema, + ) + + # Make the request + response = await client.create_metadata_schema(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_CreateMetadataSchema_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_create_metadata_schema_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_create_metadata_schema_sync.py new file mode 100644 index 0000000000..e0be93e55f --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_create_metadata_schema_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateMetadataSchema +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_CreateMetadataSchema_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_metadata_schema(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + metadata_schema = aiplatform_v1.MetadataSchema() + metadata_schema.schema = "schema_value" + + request = aiplatform_v1.CreateMetadataSchemaRequest( + parent="parent_value", + metadata_schema=metadata_schema, + ) + + # Make the request + response = client.create_metadata_schema(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_CreateMetadataSchema_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_create_metadata_store_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_create_metadata_store_async.py new file mode 100644 index 0000000000..b7be47eeea --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_create_metadata_store_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateMetadataStore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_CreateMetadataStore_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_metadata_store(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateMetadataStoreRequest( + parent="parent_value", + ) + + # Make the request + operation = client.create_metadata_store(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_CreateMetadataStore_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_create_metadata_store_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_create_metadata_store_sync.py new file mode 100644 index 0000000000..f665da6651 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_create_metadata_store_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateMetadataStore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_CreateMetadataStore_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_metadata_store(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateMetadataStoreRequest( + parent="parent_value", + ) + + # Make the request + operation = client.create_metadata_store(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_CreateMetadataStore_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_delete_artifact_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_delete_artifact_async.py new file mode 100644 index 0000000000..a4d579e2d8 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_delete_artifact_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteArtifact +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_DeleteArtifact_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_artifact(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteArtifactRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_artifact(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_DeleteArtifact_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_delete_artifact_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_delete_artifact_sync.py new file mode 100644 index 0000000000..6cd9ef7474 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_delete_artifact_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteArtifact +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_DeleteArtifact_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_artifact(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteArtifactRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_artifact(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_DeleteArtifact_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_delete_context_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_delete_context_async.py new file mode 100644 index 0000000000..23c94c67ca --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_delete_context_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteContext +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_DeleteContext_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_context(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteContextRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_context(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_DeleteContext_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_delete_context_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_delete_context_sync.py new file mode 100644 index 0000000000..35870a01cd --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_delete_context_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteContext +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_DeleteContext_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_context(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteContextRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_context(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_DeleteContext_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_delete_execution_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_delete_execution_async.py new file mode 100644 index 0000000000..1ced3d0705 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_delete_execution_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_DeleteExecution_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_execution(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteExecutionRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_execution(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_DeleteExecution_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_delete_execution_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_delete_execution_sync.py new file mode 100644 index 0000000000..1e68780482 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_delete_execution_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_DeleteExecution_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_execution(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteExecutionRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_execution(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_DeleteExecution_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_delete_metadata_store_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_delete_metadata_store_async.py new file mode 100644 index 0000000000..f1c5d2254c --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_delete_metadata_store_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteMetadataStore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_DeleteMetadataStore_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_metadata_store(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteMetadataStoreRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_metadata_store(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_DeleteMetadataStore_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_delete_metadata_store_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_delete_metadata_store_sync.py new file mode 100644 index 0000000000..3b454bfd74 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_delete_metadata_store_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteMetadataStore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_DeleteMetadataStore_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_metadata_store(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteMetadataStoreRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_metadata_store(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_DeleteMetadataStore_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_get_artifact_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_get_artifact_async.py new file mode 100644 index 0000000000..d57eecda9d --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_get_artifact_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetArtifact +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_GetArtifact_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_artifact(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetArtifactRequest( + name="name_value", + ) + + # Make the request + response = await client.get_artifact(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_GetArtifact_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_get_artifact_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_get_artifact_sync.py new file mode 100644 index 0000000000..3affb7c382 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_get_artifact_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetArtifact +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_GetArtifact_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_artifact(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetArtifactRequest( + name="name_value", + ) + + # Make the request + response = client.get_artifact(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_GetArtifact_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_get_context_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_get_context_async.py new file mode 100644 index 0000000000..8c91b57836 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_get_context_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetContext +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_GetContext_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_context(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetContextRequest( + name="name_value", + ) + + # Make the request + response = await client.get_context(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_GetContext_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_get_context_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_get_context_sync.py new file mode 100644 index 0000000000..3d9538c77f --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_get_context_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetContext +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_GetContext_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_context(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetContextRequest( + name="name_value", + ) + + # Make the request + response = client.get_context(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_GetContext_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_get_execution_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_get_execution_async.py new file mode 100644 index 0000000000..eef639bd00 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_get_execution_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_GetExecution_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_execution(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetExecutionRequest( + name="name_value", + ) + + # Make the request + response = await client.get_execution(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_GetExecution_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_get_execution_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_get_execution_sync.py new file mode 100644 index 0000000000..fd14f04d5a --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_get_execution_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_GetExecution_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_execution(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetExecutionRequest( + name="name_value", + ) + + # Make the request + response = client.get_execution(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_GetExecution_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_get_metadata_schema_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_get_metadata_schema_async.py new file mode 100644 index 0000000000..58ce65d902 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_get_metadata_schema_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetMetadataSchema +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_GetMetadataSchema_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_metadata_schema(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetMetadataSchemaRequest( + name="name_value", + ) + + # Make the request + response = await client.get_metadata_schema(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_GetMetadataSchema_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_get_metadata_schema_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_get_metadata_schema_sync.py new file mode 100644 index 0000000000..b13a484b79 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_get_metadata_schema_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetMetadataSchema +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_GetMetadataSchema_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_metadata_schema(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetMetadataSchemaRequest( + name="name_value", + ) + + # Make the request + response = client.get_metadata_schema(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_GetMetadataSchema_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_get_metadata_store_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_get_metadata_store_async.py new file mode 100644 index 0000000000..204457a3fd --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_get_metadata_store_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetMetadataStore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_GetMetadataStore_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_metadata_store(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetMetadataStoreRequest( + name="name_value", + ) + + # Make the request + response = await client.get_metadata_store(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_GetMetadataStore_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_get_metadata_store_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_get_metadata_store_sync.py new file mode 100644 index 0000000000..51f537a8c1 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_get_metadata_store_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetMetadataStore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_GetMetadataStore_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_metadata_store(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetMetadataStoreRequest( + name="name_value", + ) + + # Make the request + response = client.get_metadata_store(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_GetMetadataStore_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_list_artifacts_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_list_artifacts_async.py new file mode 100644 index 0000000000..3e08fe2549 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_list_artifacts_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListArtifacts +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_ListArtifacts_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_artifacts(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListArtifactsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_artifacts(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_ListArtifacts_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_list_artifacts_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_list_artifacts_sync.py new file mode 100644 index 0000000000..e0e6a9da8c --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_list_artifacts_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListArtifacts +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_ListArtifacts_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_artifacts(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListArtifactsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_artifacts(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_ListArtifacts_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_list_contexts_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_list_contexts_async.py new file mode 100644 index 0000000000..c9a70c3ff5 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_list_contexts_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListContexts +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_ListContexts_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_contexts(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListContextsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_contexts(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_ListContexts_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_list_contexts_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_list_contexts_sync.py new file mode 100644 index 0000000000..78e4260f8f --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_list_contexts_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListContexts +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_ListContexts_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_contexts(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListContextsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_contexts(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_ListContexts_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_list_executions_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_list_executions_async.py new file mode 100644 index 0000000000..6666626b41 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_list_executions_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListExecutions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_ListExecutions_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_executions(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListExecutionsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_executions(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_ListExecutions_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_list_executions_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_list_executions_sync.py new file mode 100644 index 0000000000..9aed0c6952 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_list_executions_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListExecutions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_ListExecutions_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_executions(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListExecutionsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_executions(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_ListExecutions_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_list_metadata_schemas_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_list_metadata_schemas_async.py new file mode 100644 index 0000000000..526cf87717 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_list_metadata_schemas_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListMetadataSchemas +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_ListMetadataSchemas_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_metadata_schemas(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListMetadataSchemasRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_metadata_schemas(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_ListMetadataSchemas_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_list_metadata_schemas_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_list_metadata_schemas_sync.py new file mode 100644 index 0000000000..ef69c9bfe9 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_list_metadata_schemas_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListMetadataSchemas +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_ListMetadataSchemas_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_metadata_schemas(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListMetadataSchemasRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_metadata_schemas(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_ListMetadataSchemas_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_list_metadata_stores_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_list_metadata_stores_async.py new file mode 100644 index 0000000000..75e6946a26 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_list_metadata_stores_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListMetadataStores +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_ListMetadataStores_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_metadata_stores(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListMetadataStoresRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_metadata_stores(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_ListMetadataStores_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_list_metadata_stores_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_list_metadata_stores_sync.py new file mode 100644 index 0000000000..b1c2cc8631 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_list_metadata_stores_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListMetadataStores +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_ListMetadataStores_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_metadata_stores(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListMetadataStoresRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_metadata_stores(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_ListMetadataStores_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_purge_artifacts_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_purge_artifacts_async.py new file mode 100644 index 0000000000..9569f78266 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_purge_artifacts_async.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PurgeArtifacts +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_PurgeArtifacts_async] +from google.cloud import aiplatform_v1 + + +async def sample_purge_artifacts(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.PurgeArtifactsRequest( + parent="parent_value", + filter="filter_value", + ) + + # Make the request + operation = client.purge_artifacts(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_PurgeArtifacts_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_purge_artifacts_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_purge_artifacts_sync.py new file mode 100644 index 0000000000..f5786af370 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_purge_artifacts_sync.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PurgeArtifacts +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_PurgeArtifacts_sync] +from google.cloud import aiplatform_v1 + + +def sample_purge_artifacts(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.PurgeArtifactsRequest( + parent="parent_value", + filter="filter_value", + ) + + # Make the request + operation = client.purge_artifacts(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_PurgeArtifacts_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_purge_contexts_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_purge_contexts_async.py new file mode 100644 index 0000000000..1adb2abf21 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_purge_contexts_async.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PurgeContexts +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_PurgeContexts_async] +from google.cloud import aiplatform_v1 + + +async def sample_purge_contexts(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.PurgeContextsRequest( + parent="parent_value", + filter="filter_value", + ) + + # Make the request + operation = client.purge_contexts(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_PurgeContexts_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_purge_contexts_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_purge_contexts_sync.py new file mode 100644 index 0000000000..c62d7880da --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_purge_contexts_sync.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PurgeContexts +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_PurgeContexts_sync] +from google.cloud import aiplatform_v1 + + +def sample_purge_contexts(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.PurgeContextsRequest( + parent="parent_value", + filter="filter_value", + ) + + # Make the request + operation = client.purge_contexts(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_PurgeContexts_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_purge_executions_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_purge_executions_async.py new file mode 100644 index 0000000000..5453ac7d04 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_purge_executions_async.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PurgeExecutions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_PurgeExecutions_async] +from google.cloud import aiplatform_v1 + + +async def sample_purge_executions(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.PurgeExecutionsRequest( + parent="parent_value", + filter="filter_value", + ) + + # Make the request + operation = client.purge_executions(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_PurgeExecutions_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_purge_executions_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_purge_executions_sync.py new file mode 100644 index 0000000000..2efdf10c66 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_purge_executions_sync.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PurgeExecutions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_PurgeExecutions_sync] +from google.cloud import aiplatform_v1 + + +def sample_purge_executions(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.PurgeExecutionsRequest( + parent="parent_value", + filter="filter_value", + ) + + # Make the request + operation = client.purge_executions(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_PurgeExecutions_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_query_artifact_lineage_subgraph_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_query_artifact_lineage_subgraph_async.py new file mode 100644 index 0000000000..0409c4db63 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_query_artifact_lineage_subgraph_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for QueryArtifactLineageSubgraph +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_QueryArtifactLineageSubgraph_async] +from google.cloud import aiplatform_v1 + + +async def sample_query_artifact_lineage_subgraph(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.QueryArtifactLineageSubgraphRequest( + artifact="artifact_value", + ) + + # Make the request + response = await client.query_artifact_lineage_subgraph(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_QueryArtifactLineageSubgraph_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_query_artifact_lineage_subgraph_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_query_artifact_lineage_subgraph_sync.py new file mode 100644 index 0000000000..96b0a97a1d --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_query_artifact_lineage_subgraph_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for QueryArtifactLineageSubgraph +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_QueryArtifactLineageSubgraph_sync] +from google.cloud import aiplatform_v1 + + +def sample_query_artifact_lineage_subgraph(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.QueryArtifactLineageSubgraphRequest( + artifact="artifact_value", + ) + + # Make the request + response = client.query_artifact_lineage_subgraph(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_QueryArtifactLineageSubgraph_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_query_context_lineage_subgraph_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_query_context_lineage_subgraph_async.py new file mode 100644 index 0000000000..981ffc002a --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_query_context_lineage_subgraph_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for QueryContextLineageSubgraph +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_QueryContextLineageSubgraph_async] +from google.cloud import aiplatform_v1 + + +async def sample_query_context_lineage_subgraph(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.QueryContextLineageSubgraphRequest( + context="context_value", + ) + + # Make the request + response = await client.query_context_lineage_subgraph(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_QueryContextLineageSubgraph_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_query_context_lineage_subgraph_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_query_context_lineage_subgraph_sync.py new file mode 100644 index 0000000000..da42b7ffed --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_query_context_lineage_subgraph_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for QueryContextLineageSubgraph +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_QueryContextLineageSubgraph_sync] +from google.cloud import aiplatform_v1 + + +def sample_query_context_lineage_subgraph(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.QueryContextLineageSubgraphRequest( + context="context_value", + ) + + # Make the request + response = client.query_context_lineage_subgraph(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_QueryContextLineageSubgraph_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_query_execution_inputs_and_outputs_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_query_execution_inputs_and_outputs_async.py new file mode 100644 index 0000000000..2c9d36daf9 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_query_execution_inputs_and_outputs_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for QueryExecutionInputsAndOutputs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_QueryExecutionInputsAndOutputs_async] +from google.cloud import aiplatform_v1 + + +async def sample_query_execution_inputs_and_outputs(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.QueryExecutionInputsAndOutputsRequest( + execution="execution_value", + ) + + # Make the request + response = await client.query_execution_inputs_and_outputs(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_QueryExecutionInputsAndOutputs_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_query_execution_inputs_and_outputs_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_query_execution_inputs_and_outputs_sync.py new file mode 100644 index 0000000000..6ef3c5e597 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_query_execution_inputs_and_outputs_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for QueryExecutionInputsAndOutputs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_QueryExecutionInputsAndOutputs_sync] +from google.cloud import aiplatform_v1 + + +def sample_query_execution_inputs_and_outputs(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.QueryExecutionInputsAndOutputsRequest( + execution="execution_value", + ) + + # Make the request + response = client.query_execution_inputs_and_outputs(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_QueryExecutionInputsAndOutputs_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_update_artifact_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_update_artifact_async.py new file mode 100644 index 0000000000..2f7bec2157 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_update_artifact_async.py @@ -0,0 +1,44 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateArtifact +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_UpdateArtifact_async] +from google.cloud import aiplatform_v1 + + +async def sample_update_artifact(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.UpdateArtifactRequest( + ) + + # Make the request + response = await client.update_artifact(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_UpdateArtifact_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_update_artifact_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_update_artifact_sync.py new file mode 100644 index 0000000000..b1f75e2ca5 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_update_artifact_sync.py @@ -0,0 +1,44 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateArtifact +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_UpdateArtifact_sync] +from google.cloud import aiplatform_v1 + + +def sample_update_artifact(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.UpdateArtifactRequest( + ) + + # Make the request + response = client.update_artifact(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_UpdateArtifact_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_update_context_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_update_context_async.py new file mode 100644 index 0000000000..ef003070c9 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_update_context_async.py @@ -0,0 +1,44 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateContext +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_UpdateContext_async] +from google.cloud import aiplatform_v1 + + +async def sample_update_context(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.UpdateContextRequest( + ) + + # Make the request + response = await client.update_context(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_UpdateContext_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_update_context_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_update_context_sync.py new file mode 100644 index 0000000000..d289f59a91 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_update_context_sync.py @@ -0,0 +1,44 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateContext +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_UpdateContext_sync] +from google.cloud import aiplatform_v1 + + +def sample_update_context(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.UpdateContextRequest( + ) + + # Make the request + response = client.update_context(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_UpdateContext_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_update_execution_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_update_execution_async.py new file mode 100644 index 0000000000..16062f9146 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_update_execution_async.py @@ -0,0 +1,44 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_UpdateExecution_async] +from google.cloud import aiplatform_v1 + + +async def sample_update_execution(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.UpdateExecutionRequest( + ) + + # Make the request + response = await client.update_execution(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_UpdateExecution_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_update_execution_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_update_execution_sync.py new file mode 100644 index 0000000000..6681dad63e --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_metadata_service_update_execution_sync.py @@ -0,0 +1,44 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MetadataService_UpdateExecution_sync] +from google.cloud import aiplatform_v1 + + +def sample_update_execution(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.UpdateExecutionRequest( + ) + + # Make the request + response = client.update_execution(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MetadataService_UpdateExecution_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_migration_service_batch_migrate_resources_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_migration_service_batch_migrate_resources_async.py new file mode 100644 index 0000000000..21d019478c --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_migration_service_batch_migrate_resources_async.py @@ -0,0 +1,55 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchMigrateResources +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MigrationService_BatchMigrateResources_async] +from google.cloud import aiplatform_v1 + + +async def sample_batch_migrate_resources(): + # Create a client + client = aiplatform_v1.MigrationServiceAsyncClient() + + # Initialize request argument(s) + migrate_resource_requests = aiplatform_v1.MigrateResourceRequest() + migrate_resource_requests.migrate_ml_engine_model_version_config.endpoint = "endpoint_value" + migrate_resource_requests.migrate_ml_engine_model_version_config.model_version = "model_version_value" + migrate_resource_requests.migrate_ml_engine_model_version_config.model_display_name = "model_display_name_value" + + request = aiplatform_v1.BatchMigrateResourcesRequest( + parent="parent_value", + migrate_resource_requests=migrate_resource_requests, + ) + + # Make the request + operation = client.batch_migrate_resources(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MigrationService_BatchMigrateResources_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_migration_service_batch_migrate_resources_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_migration_service_batch_migrate_resources_sync.py new file mode 100644 index 0000000000..cf895368f0 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_migration_service_batch_migrate_resources_sync.py @@ -0,0 +1,55 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchMigrateResources +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MigrationService_BatchMigrateResources_sync] +from google.cloud import aiplatform_v1 + + +def sample_batch_migrate_resources(): + # Create a client + client = aiplatform_v1.MigrationServiceClient() + + # Initialize request argument(s) + migrate_resource_requests = aiplatform_v1.MigrateResourceRequest() + migrate_resource_requests.migrate_ml_engine_model_version_config.endpoint = "endpoint_value" + migrate_resource_requests.migrate_ml_engine_model_version_config.model_version = "model_version_value" + migrate_resource_requests.migrate_ml_engine_model_version_config.model_display_name = "model_display_name_value" + + request = aiplatform_v1.BatchMigrateResourcesRequest( + parent="parent_value", + migrate_resource_requests=migrate_resource_requests, + ) + + # Make the request + operation = client.batch_migrate_resources(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_MigrationService_BatchMigrateResources_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_migration_service_search_migratable_resources_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_migration_service_search_migratable_resources_async.py new file mode 100644 index 0000000000..f9d2d6fa7f --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_migration_service_search_migratable_resources_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SearchMigratableResources +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MigrationService_SearchMigratableResources_async] +from google.cloud import aiplatform_v1 + + +async def sample_search_migratable_resources(): + # Create a client + client = aiplatform_v1.MigrationServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.SearchMigratableResourcesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.search_migratable_resources(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_MigrationService_SearchMigratableResources_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_migration_service_search_migratable_resources_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_migration_service_search_migratable_resources_sync.py new file mode 100644 index 0000000000..bd66673263 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_migration_service_search_migratable_resources_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SearchMigratableResources +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_MigrationService_SearchMigratableResources_sync] +from google.cloud import aiplatform_v1 + + +def sample_search_migratable_resources(): + # Create a client + client = aiplatform_v1.MigrationServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.SearchMigratableResourcesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.search_migratable_resources(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_MigrationService_SearchMigratableResources_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_delete_model_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_delete_model_async.py new file mode 100644 index 0000000000..9e4fd4238d --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_delete_model_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_ModelService_DeleteModel_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_model(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteModelRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_model(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_ModelService_DeleteModel_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_delete_model_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_delete_model_sync.py new file mode 100644 index 0000000000..5c5a1446eb --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_delete_model_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_ModelService_DeleteModel_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_model(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteModelRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_model(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_ModelService_DeleteModel_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_export_model_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_export_model_async.py new file mode 100644 index 0000000000..cadf958cba --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_export_model_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_ModelService_ExportModel_async] +from google.cloud import aiplatform_v1 + + +async def sample_export_model(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ExportModelRequest( + name="name_value", + ) + + # Make the request + operation = client.export_model(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_ModelService_ExportModel_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_export_model_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_export_model_sync.py new file mode 100644 index 0000000000..92ed15c14b --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_export_model_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_ModelService_ExportModel_sync] +from google.cloud import aiplatform_v1 + + +def sample_export_model(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ExportModelRequest( + name="name_value", + ) + + # Make the request + operation = client.export_model(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_ModelService_ExportModel_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_get_model_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_get_model_async.py new file mode 100644 index 0000000000..7bbe9e1e12 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_get_model_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_ModelService_GetModel_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_model(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetModelRequest( + name="name_value", + ) + + # Make the request + response = await client.get_model(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_ModelService_GetModel_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_get_model_evaluation_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_get_model_evaluation_async.py new file mode 100644 index 0000000000..0ca6b8fd76 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_get_model_evaluation_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetModelEvaluation +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_ModelService_GetModelEvaluation_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_model_evaluation(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetModelEvaluationRequest( + name="name_value", + ) + + # Make the request + response = await client.get_model_evaluation(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_ModelService_GetModelEvaluation_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_get_model_evaluation_slice_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_get_model_evaluation_slice_async.py new file mode 100644 index 0000000000..d06448b804 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_get_model_evaluation_slice_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetModelEvaluationSlice +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_ModelService_GetModelEvaluationSlice_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_model_evaluation_slice(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetModelEvaluationSliceRequest( + name="name_value", + ) + + # Make the request + response = await client.get_model_evaluation_slice(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_ModelService_GetModelEvaluationSlice_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_get_model_evaluation_slice_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_get_model_evaluation_slice_sync.py new file mode 100644 index 0000000000..7bf4ba1df9 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_get_model_evaluation_slice_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetModelEvaluationSlice +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_ModelService_GetModelEvaluationSlice_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_model_evaluation_slice(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetModelEvaluationSliceRequest( + name="name_value", + ) + + # Make the request + response = client.get_model_evaluation_slice(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_ModelService_GetModelEvaluationSlice_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_get_model_evaluation_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_get_model_evaluation_sync.py new file mode 100644 index 0000000000..1f2fb5a5a2 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_get_model_evaluation_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetModelEvaluation +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_ModelService_GetModelEvaluation_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_model_evaluation(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetModelEvaluationRequest( + name="name_value", + ) + + # Make the request + response = client.get_model_evaluation(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_ModelService_GetModelEvaluation_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_get_model_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_get_model_sync.py new file mode 100644 index 0000000000..f1fb3a459a --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_get_model_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_ModelService_GetModel_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_model(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetModelRequest( + name="name_value", + ) + + # Make the request + response = client.get_model(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_ModelService_GetModel_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_list_model_evaluation_slices_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_list_model_evaluation_slices_async.py new file mode 100644 index 0000000000..e4f30ed545 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_list_model_evaluation_slices_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListModelEvaluationSlices +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_ModelService_ListModelEvaluationSlices_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_model_evaluation_slices(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListModelEvaluationSlicesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_model_evaluation_slices(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_ModelService_ListModelEvaluationSlices_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_list_model_evaluation_slices_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_list_model_evaluation_slices_sync.py new file mode 100644 index 0000000000..4b69b05762 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_list_model_evaluation_slices_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListModelEvaluationSlices +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_ModelService_ListModelEvaluationSlices_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_model_evaluation_slices(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListModelEvaluationSlicesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_model_evaluation_slices(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_ModelService_ListModelEvaluationSlices_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_list_model_evaluations_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_list_model_evaluations_async.py new file mode 100644 index 0000000000..ecca3b784f --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_list_model_evaluations_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListModelEvaluations +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_ModelService_ListModelEvaluations_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_model_evaluations(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListModelEvaluationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_model_evaluations(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_ModelService_ListModelEvaluations_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_list_model_evaluations_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_list_model_evaluations_sync.py new file mode 100644 index 0000000000..cb78d024c8 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_list_model_evaluations_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListModelEvaluations +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_ModelService_ListModelEvaluations_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_model_evaluations(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListModelEvaluationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_model_evaluations(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_ModelService_ListModelEvaluations_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_list_models_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_list_models_async.py new file mode 100644 index 0000000000..bcda61b8d6 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_list_models_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListModels +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_ModelService_ListModels_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_models(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListModelsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_models(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_ModelService_ListModels_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_list_models_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_list_models_sync.py new file mode 100644 index 0000000000..d837b9267e --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_list_models_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListModels +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_ModelService_ListModels_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_models(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListModelsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_models(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_ModelService_ListModels_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_update_model_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_update_model_async.py new file mode 100644 index 0000000000..efaa389d96 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_update_model_async.py @@ -0,0 +1,48 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_ModelService_UpdateModel_async] +from google.cloud import aiplatform_v1 + + +async def sample_update_model(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + model = aiplatform_v1.Model() + model.display_name = "display_name_value" + + request = aiplatform_v1.UpdateModelRequest( + model=model, + ) + + # Make the request + response = await client.update_model(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_ModelService_UpdateModel_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_update_model_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_update_model_sync.py new file mode 100644 index 0000000000..9cd7e28ba3 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_update_model_sync.py @@ -0,0 +1,48 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_ModelService_UpdateModel_sync] +from google.cloud import aiplatform_v1 + + +def sample_update_model(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + model = aiplatform_v1.Model() + model.display_name = "display_name_value" + + request = aiplatform_v1.UpdateModelRequest( + model=model, + ) + + # Make the request + response = client.update_model(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_ModelService_UpdateModel_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_upload_model_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_upload_model_async.py new file mode 100644 index 0000000000..46fb755edb --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_upload_model_async.py @@ -0,0 +1,53 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UploadModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_ModelService_UploadModel_async] +from google.cloud import aiplatform_v1 + + +async def sample_upload_model(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + model = aiplatform_v1.Model() + model.display_name = "display_name_value" + + request = aiplatform_v1.UploadModelRequest( + parent="parent_value", + model=model, + ) + + # Make the request + operation = client.upload_model(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_ModelService_UploadModel_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_upload_model_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_upload_model_sync.py new file mode 100644 index 0000000000..880ea1114d --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_model_service_upload_model_sync.py @@ -0,0 +1,53 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UploadModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_ModelService_UploadModel_sync] +from google.cloud import aiplatform_v1 + + +def sample_upload_model(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + model = aiplatform_v1.Model() + model.display_name = "display_name_value" + + request = aiplatform_v1.UploadModelRequest( + parent="parent_value", + model=model, + ) + + # Make the request + operation = client.upload_model(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_ModelService_UploadModel_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_cancel_pipeline_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_cancel_pipeline_job_async.py new file mode 100644 index 0000000000..7c4cef8bb9 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_cancel_pipeline_job_async.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelPipelineJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_PipelineService_CancelPipelineJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_cancel_pipeline_job(): + # Create a client + client = aiplatform_v1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CancelPipelineJobRequest( + name="name_value", + ) + + # Make the request + await client.cancel_pipeline_job(request=request) + + +# [END aiplatform_generated_aiplatform_v1_PipelineService_CancelPipelineJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_cancel_pipeline_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_cancel_pipeline_job_sync.py new file mode 100644 index 0000000000..f3add9bcea --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_cancel_pipeline_job_sync.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelPipelineJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_PipelineService_CancelPipelineJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_cancel_pipeline_job(): + # Create a client + client = aiplatform_v1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CancelPipelineJobRequest( + name="name_value", + ) + + # Make the request + client.cancel_pipeline_job(request=request) + + +# [END aiplatform_generated_aiplatform_v1_PipelineService_CancelPipelineJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_cancel_training_pipeline_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_cancel_training_pipeline_async.py new file mode 100644 index 0000000000..75969857c4 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_cancel_training_pipeline_async.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelTrainingPipeline +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_PipelineService_CancelTrainingPipeline_async] +from google.cloud import aiplatform_v1 + + +async def sample_cancel_training_pipeline(): + # Create a client + client = aiplatform_v1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CancelTrainingPipelineRequest( + name="name_value", + ) + + # Make the request + await client.cancel_training_pipeline(request=request) + + +# [END aiplatform_generated_aiplatform_v1_PipelineService_CancelTrainingPipeline_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_cancel_training_pipeline_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_cancel_training_pipeline_sync.py new file mode 100644 index 0000000000..2cfd8c5a29 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_cancel_training_pipeline_sync.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelTrainingPipeline +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_PipelineService_CancelTrainingPipeline_sync] +from google.cloud import aiplatform_v1 + + +def sample_cancel_training_pipeline(): + # Create a client + client = aiplatform_v1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CancelTrainingPipelineRequest( + name="name_value", + ) + + # Make the request + client.cancel_training_pipeline(request=request) + + +# [END aiplatform_generated_aiplatform_v1_PipelineService_CancelTrainingPipeline_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_create_pipeline_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_create_pipeline_job_async.py new file mode 100644 index 0000000000..0ea8f783ef --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_create_pipeline_job_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreatePipelineJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_PipelineService_CreatePipelineJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_pipeline_job(): + # Create a client + client = aiplatform_v1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreatePipelineJobRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_pipeline_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_PipelineService_CreatePipelineJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_create_pipeline_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_create_pipeline_job_sync.py new file mode 100644 index 0000000000..4c40a7a3d7 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_create_pipeline_job_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreatePipelineJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_PipelineService_CreatePipelineJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_pipeline_job(): + # Create a client + client = aiplatform_v1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreatePipelineJobRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_pipeline_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_PipelineService_CreatePipelineJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_create_training_pipeline_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_create_training_pipeline_async.py new file mode 100644 index 0000000000..0278845dc9 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_create_training_pipeline_async.py @@ -0,0 +1,51 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTrainingPipeline +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_PipelineService_CreateTrainingPipeline_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_training_pipeline(): + # Create a client + client = aiplatform_v1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + training_pipeline = aiplatform_v1.TrainingPipeline() + training_pipeline.display_name = "display_name_value" + training_pipeline.training_task_definition = "training_task_definition_value" + training_pipeline.training_task_inputs.null_value = "NULL_VALUE" + + request = aiplatform_v1.CreateTrainingPipelineRequest( + parent="parent_value", + training_pipeline=training_pipeline, + ) + + # Make the request + response = await client.create_training_pipeline(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_PipelineService_CreateTrainingPipeline_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_create_training_pipeline_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_create_training_pipeline_sync.py new file mode 100644 index 0000000000..ff4ab02c66 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_create_training_pipeline_sync.py @@ -0,0 +1,51 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTrainingPipeline +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_PipelineService_CreateTrainingPipeline_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_training_pipeline(): + # Create a client + client = aiplatform_v1.PipelineServiceClient() + + # Initialize request argument(s) + training_pipeline = aiplatform_v1.TrainingPipeline() + training_pipeline.display_name = "display_name_value" + training_pipeline.training_task_definition = "training_task_definition_value" + training_pipeline.training_task_inputs.null_value = "NULL_VALUE" + + request = aiplatform_v1.CreateTrainingPipelineRequest( + parent="parent_value", + training_pipeline=training_pipeline, + ) + + # Make the request + response = client.create_training_pipeline(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_PipelineService_CreateTrainingPipeline_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_delete_pipeline_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_delete_pipeline_job_async.py new file mode 100644 index 0000000000..fc29d57550 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_delete_pipeline_job_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeletePipelineJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_PipelineService_DeletePipelineJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_pipeline_job(): + # Create a client + client = aiplatform_v1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeletePipelineJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_pipeline_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_PipelineService_DeletePipelineJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_delete_pipeline_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_delete_pipeline_job_sync.py new file mode 100644 index 0000000000..48404a7bde --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_delete_pipeline_job_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeletePipelineJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_PipelineService_DeletePipelineJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_pipeline_job(): + # Create a client + client = aiplatform_v1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeletePipelineJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_pipeline_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_PipelineService_DeletePipelineJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_delete_training_pipeline_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_delete_training_pipeline_async.py new file mode 100644 index 0000000000..0a778f00ed --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_delete_training_pipeline_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTrainingPipeline +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_PipelineService_DeleteTrainingPipeline_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_training_pipeline(): + # Create a client + client = aiplatform_v1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteTrainingPipelineRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_training_pipeline(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_PipelineService_DeleteTrainingPipeline_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_delete_training_pipeline_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_delete_training_pipeline_sync.py new file mode 100644 index 0000000000..9f7fcfa042 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_delete_training_pipeline_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTrainingPipeline +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_PipelineService_DeleteTrainingPipeline_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_training_pipeline(): + # Create a client + client = aiplatform_v1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteTrainingPipelineRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_training_pipeline(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_PipelineService_DeleteTrainingPipeline_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_get_pipeline_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_get_pipeline_job_async.py new file mode 100644 index 0000000000..d848a3dc17 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_get_pipeline_job_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetPipelineJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_PipelineService_GetPipelineJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_pipeline_job(): + # Create a client + client = aiplatform_v1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetPipelineJobRequest( + name="name_value", + ) + + # Make the request + response = await client.get_pipeline_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_PipelineService_GetPipelineJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_get_pipeline_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_get_pipeline_job_sync.py new file mode 100644 index 0000000000..63a4297594 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_get_pipeline_job_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetPipelineJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_PipelineService_GetPipelineJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_pipeline_job(): + # Create a client + client = aiplatform_v1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetPipelineJobRequest( + name="name_value", + ) + + # Make the request + response = client.get_pipeline_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_PipelineService_GetPipelineJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_get_training_pipeline_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_get_training_pipeline_async.py new file mode 100644 index 0000000000..41b88979e6 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_get_training_pipeline_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTrainingPipeline +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_PipelineService_GetTrainingPipeline_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_training_pipeline(): + # Create a client + client = aiplatform_v1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetTrainingPipelineRequest( + name="name_value", + ) + + # Make the request + response = await client.get_training_pipeline(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_PipelineService_GetTrainingPipeline_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_get_training_pipeline_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_get_training_pipeline_sync.py new file mode 100644 index 0000000000..ab97bf6546 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_get_training_pipeline_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTrainingPipeline +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_PipelineService_GetTrainingPipeline_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_training_pipeline(): + # Create a client + client = aiplatform_v1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetTrainingPipelineRequest( + name="name_value", + ) + + # Make the request + response = client.get_training_pipeline(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_PipelineService_GetTrainingPipeline_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_list_pipeline_jobs_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_list_pipeline_jobs_async.py new file mode 100644 index 0000000000..c177f976f3 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_list_pipeline_jobs_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListPipelineJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_PipelineService_ListPipelineJobs_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_pipeline_jobs(): + # Create a client + client = aiplatform_v1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListPipelineJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_pipeline_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_PipelineService_ListPipelineJobs_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_list_pipeline_jobs_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_list_pipeline_jobs_sync.py new file mode 100644 index 0000000000..8a0853fcbb --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_list_pipeline_jobs_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListPipelineJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_PipelineService_ListPipelineJobs_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_pipeline_jobs(): + # Create a client + client = aiplatform_v1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListPipelineJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_pipeline_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_PipelineService_ListPipelineJobs_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_list_training_pipelines_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_list_training_pipelines_async.py new file mode 100644 index 0000000000..785927f3c2 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_list_training_pipelines_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTrainingPipelines +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_PipelineService_ListTrainingPipelines_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_training_pipelines(): + # Create a client + client = aiplatform_v1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListTrainingPipelinesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_training_pipelines(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_PipelineService_ListTrainingPipelines_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_list_training_pipelines_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_list_training_pipelines_sync.py new file mode 100644 index 0000000000..e752a91599 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_pipeline_service_list_training_pipelines_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTrainingPipelines +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_PipelineService_ListTrainingPipelines_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_training_pipelines(): + # Create a client + client = aiplatform_v1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListTrainingPipelinesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_training_pipelines(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_PipelineService_ListTrainingPipelines_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_prediction_service_explain_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_prediction_service_explain_async.py new file mode 100644 index 0000000000..8a75e04569 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_prediction_service_explain_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for Explain +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_PredictionService_Explain_async] +from google.cloud import aiplatform_v1 + + +async def sample_explain(): + # Create a client + client = aiplatform_v1.PredictionServiceAsyncClient() + + # Initialize request argument(s) + instances = aiplatform_v1.Value() + instances.null_value = "NULL_VALUE" + + request = aiplatform_v1.ExplainRequest( + endpoint="endpoint_value", + instances=instances, + ) + + # Make the request + response = await client.explain(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_PredictionService_Explain_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_prediction_service_explain_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_prediction_service_explain_sync.py new file mode 100644 index 0000000000..2a46d842b2 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_prediction_service_explain_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for Explain +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_PredictionService_Explain_sync] +from google.cloud import aiplatform_v1 + + +def sample_explain(): + # Create a client + client = aiplatform_v1.PredictionServiceClient() + + # Initialize request argument(s) + instances = aiplatform_v1.Value() + instances.null_value = "NULL_VALUE" + + request = aiplatform_v1.ExplainRequest( + endpoint="endpoint_value", + instances=instances, + ) + + # Make the request + response = client.explain(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_PredictionService_Explain_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_prediction_service_predict_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_prediction_service_predict_async.py new file mode 100644 index 0000000000..c255068ae6 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_prediction_service_predict_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for Predict +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_PredictionService_Predict_async] +from google.cloud import aiplatform_v1 + + +async def sample_predict(): + # Create a client + client = aiplatform_v1.PredictionServiceAsyncClient() + + # Initialize request argument(s) + instances = aiplatform_v1.Value() + instances.null_value = "NULL_VALUE" + + request = aiplatform_v1.PredictRequest( + endpoint="endpoint_value", + instances=instances, + ) + + # Make the request + response = await client.predict(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_PredictionService_Predict_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_prediction_service_predict_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_prediction_service_predict_sync.py new file mode 100644 index 0000000000..268eeb8d3b --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_prediction_service_predict_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for Predict +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_PredictionService_Predict_sync] +from google.cloud import aiplatform_v1 + + +def sample_predict(): + # Create a client + client = aiplatform_v1.PredictionServiceClient() + + # Initialize request argument(s) + instances = aiplatform_v1.Value() + instances.null_value = "NULL_VALUE" + + request = aiplatform_v1.PredictRequest( + endpoint="endpoint_value", + instances=instances, + ) + + # Make the request + response = client.predict(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_PredictionService_Predict_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_prediction_service_raw_predict_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_prediction_service_raw_predict_async.py new file mode 100644 index 0000000000..6733db3d6c --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_prediction_service_raw_predict_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for RawPredict +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_PredictionService_RawPredict_async] +from google.cloud import aiplatform_v1 + + +async def sample_raw_predict(): + # Create a client + client = aiplatform_v1.PredictionServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.RawPredictRequest( + endpoint="endpoint_value", + ) + + # Make the request + response = await client.raw_predict(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_PredictionService_RawPredict_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_prediction_service_raw_predict_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_prediction_service_raw_predict_sync.py new file mode 100644 index 0000000000..ee69a2fef3 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_prediction_service_raw_predict_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for RawPredict +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_PredictionService_RawPredict_sync] +from google.cloud import aiplatform_v1 + + +def sample_raw_predict(): + # Create a client + client = aiplatform_v1.PredictionServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.RawPredictRequest( + endpoint="endpoint_value", + ) + + # Make the request + response = client.raw_predict(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_PredictionService_RawPredict_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_specialist_pool_service_create_specialist_pool_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_specialist_pool_service_create_specialist_pool_async.py new file mode 100644 index 0000000000..b229a9bc71 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_specialist_pool_service_create_specialist_pool_async.py @@ -0,0 +1,54 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateSpecialistPool +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_SpecialistPoolService_CreateSpecialistPool_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_specialist_pool(): + # Create a client + client = aiplatform_v1.SpecialistPoolServiceAsyncClient() + + # Initialize request argument(s) + specialist_pool = aiplatform_v1.SpecialistPool() + specialist_pool.name = "name_value" + specialist_pool.display_name = "display_name_value" + + request = aiplatform_v1.CreateSpecialistPoolRequest( + parent="parent_value", + specialist_pool=specialist_pool, + ) + + # Make the request + operation = client.create_specialist_pool(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_SpecialistPoolService_CreateSpecialistPool_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_specialist_pool_service_create_specialist_pool_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_specialist_pool_service_create_specialist_pool_sync.py new file mode 100644 index 0000000000..74dc071a48 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_specialist_pool_service_create_specialist_pool_sync.py @@ -0,0 +1,54 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateSpecialistPool +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_SpecialistPoolService_CreateSpecialistPool_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_specialist_pool(): + # Create a client + client = aiplatform_v1.SpecialistPoolServiceClient() + + # Initialize request argument(s) + specialist_pool = aiplatform_v1.SpecialistPool() + specialist_pool.name = "name_value" + specialist_pool.display_name = "display_name_value" + + request = aiplatform_v1.CreateSpecialistPoolRequest( + parent="parent_value", + specialist_pool=specialist_pool, + ) + + # Make the request + operation = client.create_specialist_pool(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_SpecialistPoolService_CreateSpecialistPool_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_specialist_pool_service_delete_specialist_pool_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_specialist_pool_service_delete_specialist_pool_async.py new file mode 100644 index 0000000000..558ea7ed13 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_specialist_pool_service_delete_specialist_pool_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteSpecialistPool +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_SpecialistPoolService_DeleteSpecialistPool_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_specialist_pool(): + # Create a client + client = aiplatform_v1.SpecialistPoolServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteSpecialistPoolRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_specialist_pool(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_SpecialistPoolService_DeleteSpecialistPool_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_specialist_pool_service_delete_specialist_pool_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_specialist_pool_service_delete_specialist_pool_sync.py new file mode 100644 index 0000000000..69ce2ddd2b --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_specialist_pool_service_delete_specialist_pool_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteSpecialistPool +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_SpecialistPoolService_DeleteSpecialistPool_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_specialist_pool(): + # Create a client + client = aiplatform_v1.SpecialistPoolServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteSpecialistPoolRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_specialist_pool(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_SpecialistPoolService_DeleteSpecialistPool_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_specialist_pool_service_get_specialist_pool_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_specialist_pool_service_get_specialist_pool_async.py new file mode 100644 index 0000000000..0c07bd6c58 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_specialist_pool_service_get_specialist_pool_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetSpecialistPool +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_SpecialistPoolService_GetSpecialistPool_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_specialist_pool(): + # Create a client + client = aiplatform_v1.SpecialistPoolServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetSpecialistPoolRequest( + name="name_value", + ) + + # Make the request + response = await client.get_specialist_pool(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_SpecialistPoolService_GetSpecialistPool_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_specialist_pool_service_get_specialist_pool_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_specialist_pool_service_get_specialist_pool_sync.py new file mode 100644 index 0000000000..41408bc876 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_specialist_pool_service_get_specialist_pool_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetSpecialistPool +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_SpecialistPoolService_GetSpecialistPool_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_specialist_pool(): + # Create a client + client = aiplatform_v1.SpecialistPoolServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetSpecialistPoolRequest( + name="name_value", + ) + + # Make the request + response = client.get_specialist_pool(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_SpecialistPoolService_GetSpecialistPool_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_specialist_pool_service_list_specialist_pools_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_specialist_pool_service_list_specialist_pools_async.py new file mode 100644 index 0000000000..53b6537503 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_specialist_pool_service_list_specialist_pools_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListSpecialistPools +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_SpecialistPoolService_ListSpecialistPools_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_specialist_pools(): + # Create a client + client = aiplatform_v1.SpecialistPoolServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListSpecialistPoolsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_specialist_pools(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_SpecialistPoolService_ListSpecialistPools_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_specialist_pool_service_list_specialist_pools_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_specialist_pool_service_list_specialist_pools_sync.py new file mode 100644 index 0000000000..8b6d07fa0f --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_specialist_pool_service_list_specialist_pools_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListSpecialistPools +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_SpecialistPoolService_ListSpecialistPools_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_specialist_pools(): + # Create a client + client = aiplatform_v1.SpecialistPoolServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListSpecialistPoolsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_specialist_pools(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_SpecialistPoolService_ListSpecialistPools_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_specialist_pool_service_update_specialist_pool_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_specialist_pool_service_update_specialist_pool_async.py new file mode 100644 index 0000000000..a7a37310cc --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_specialist_pool_service_update_specialist_pool_async.py @@ -0,0 +1,53 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateSpecialistPool +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_SpecialistPoolService_UpdateSpecialistPool_async] +from google.cloud import aiplatform_v1 + + +async def sample_update_specialist_pool(): + # Create a client + client = aiplatform_v1.SpecialistPoolServiceAsyncClient() + + # Initialize request argument(s) + specialist_pool = aiplatform_v1.SpecialistPool() + specialist_pool.name = "name_value" + specialist_pool.display_name = "display_name_value" + + request = aiplatform_v1.UpdateSpecialistPoolRequest( + specialist_pool=specialist_pool, + ) + + # Make the request + operation = client.update_specialist_pool(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_SpecialistPoolService_UpdateSpecialistPool_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_specialist_pool_service_update_specialist_pool_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_specialist_pool_service_update_specialist_pool_sync.py new file mode 100644 index 0000000000..c49446bb60 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_specialist_pool_service_update_specialist_pool_sync.py @@ -0,0 +1,53 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateSpecialistPool +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_SpecialistPoolService_UpdateSpecialistPool_sync] +from google.cloud import aiplatform_v1 + + +def sample_update_specialist_pool(): + # Create a client + client = aiplatform_v1.SpecialistPoolServiceClient() + + # Initialize request argument(s) + specialist_pool = aiplatform_v1.SpecialistPool() + specialist_pool.name = "name_value" + specialist_pool.display_name = "display_name_value" + + request = aiplatform_v1.UpdateSpecialistPoolRequest( + specialist_pool=specialist_pool, + ) + + # Make the request + operation = client.update_specialist_pool(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_SpecialistPoolService_UpdateSpecialistPool_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_batch_create_tensorboard_runs_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_batch_create_tensorboard_runs_async.py new file mode 100644 index 0000000000..71a29f27dc --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_batch_create_tensorboard_runs_async.py @@ -0,0 +1,51 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchCreateTensorboardRuns +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_BatchCreateTensorboardRuns_async] +from google.cloud import aiplatform_v1 + + +async def sample_batch_create_tensorboard_runs(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + requests = aiplatform_v1.CreateTensorboardRunRequest() + requests.parent = "parent_value" + requests.tensorboard_run.display_name = "display_name_value" + requests.tensorboard_run_id = "tensorboard_run_id_value" + + request = aiplatform_v1.BatchCreateTensorboardRunsRequest( + parent="parent_value", + requests=requests, + ) + + # Make the request + response = await client.batch_create_tensorboard_runs(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_BatchCreateTensorboardRuns_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_batch_create_tensorboard_runs_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_batch_create_tensorboard_runs_sync.py new file mode 100644 index 0000000000..3dd77f1d3d --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_batch_create_tensorboard_runs_sync.py @@ -0,0 +1,51 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchCreateTensorboardRuns +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_BatchCreateTensorboardRuns_sync] +from google.cloud import aiplatform_v1 + + +def sample_batch_create_tensorboard_runs(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + requests = aiplatform_v1.CreateTensorboardRunRequest() + requests.parent = "parent_value" + requests.tensorboard_run.display_name = "display_name_value" + requests.tensorboard_run_id = "tensorboard_run_id_value" + + request = aiplatform_v1.BatchCreateTensorboardRunsRequest( + parent="parent_value", + requests=requests, + ) + + # Make the request + response = client.batch_create_tensorboard_runs(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_BatchCreateTensorboardRuns_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_batch_create_tensorboard_time_series_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_batch_create_tensorboard_time_series_async.py new file mode 100644 index 0000000000..e653039e53 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_batch_create_tensorboard_time_series_async.py @@ -0,0 +1,51 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchCreateTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_BatchCreateTensorboardTimeSeries_async] +from google.cloud import aiplatform_v1 + + +async def sample_batch_create_tensorboard_time_series(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + requests = aiplatform_v1.CreateTensorboardTimeSeriesRequest() + requests.parent = "parent_value" + requests.tensorboard_time_series.display_name = "display_name_value" + requests.tensorboard_time_series.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1.BatchCreateTensorboardTimeSeriesRequest( + parent="parent_value", + requests=requests, + ) + + # Make the request + response = await client.batch_create_tensorboard_time_series(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_BatchCreateTensorboardTimeSeries_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_batch_create_tensorboard_time_series_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_batch_create_tensorboard_time_series_sync.py new file mode 100644 index 0000000000..b0e438caa3 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_batch_create_tensorboard_time_series_sync.py @@ -0,0 +1,51 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchCreateTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_BatchCreateTensorboardTimeSeries_sync] +from google.cloud import aiplatform_v1 + + +def sample_batch_create_tensorboard_time_series(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + requests = aiplatform_v1.CreateTensorboardTimeSeriesRequest() + requests.parent = "parent_value" + requests.tensorboard_time_series.display_name = "display_name_value" + requests.tensorboard_time_series.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1.BatchCreateTensorboardTimeSeriesRequest( + parent="parent_value", + requests=requests, + ) + + # Make the request + response = client.batch_create_tensorboard_time_series(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_BatchCreateTensorboardTimeSeries_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_batch_read_tensorboard_time_series_data_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_batch_read_tensorboard_time_series_data_async.py new file mode 100644 index 0000000000..9313b76440 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_batch_read_tensorboard_time_series_data_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchReadTensorboardTimeSeriesData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_BatchReadTensorboardTimeSeriesData_async] +from google.cloud import aiplatform_v1 + + +async def sample_batch_read_tensorboard_time_series_data(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.BatchReadTensorboardTimeSeriesDataRequest( + tensorboard="tensorboard_value", + time_series=['time_series_value_1', 'time_series_value_2'], + ) + + # Make the request + response = await client.batch_read_tensorboard_time_series_data(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_BatchReadTensorboardTimeSeriesData_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_batch_read_tensorboard_time_series_data_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_batch_read_tensorboard_time_series_data_sync.py new file mode 100644 index 0000000000..916b2fe0ac --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_batch_read_tensorboard_time_series_data_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchReadTensorboardTimeSeriesData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_BatchReadTensorboardTimeSeriesData_sync] +from google.cloud import aiplatform_v1 + + +def sample_batch_read_tensorboard_time_series_data(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.BatchReadTensorboardTimeSeriesDataRequest( + tensorboard="tensorboard_value", + time_series=['time_series_value_1', 'time_series_value_2'], + ) + + # Make the request + response = client.batch_read_tensorboard_time_series_data(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_BatchReadTensorboardTimeSeriesData_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_create_tensorboard_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_create_tensorboard_async.py new file mode 100644 index 0000000000..69325d83bc --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_create_tensorboard_async.py @@ -0,0 +1,53 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTensorboard +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_CreateTensorboard_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_tensorboard(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + tensorboard = aiplatform_v1.Tensorboard() + tensorboard.display_name = "display_name_value" + + request = aiplatform_v1.CreateTensorboardRequest( + parent="parent_value", + tensorboard=tensorboard, + ) + + # Make the request + operation = client.create_tensorboard(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_CreateTensorboard_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_create_tensorboard_experiment_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_create_tensorboard_experiment_async.py new file mode 100644 index 0000000000..65cb1f8338 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_create_tensorboard_experiment_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTensorboardExperiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_CreateTensorboardExperiment_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_tensorboard_experiment(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateTensorboardExperimentRequest( + parent="parent_value", + tensorboard_experiment_id="tensorboard_experiment_id_value", + ) + + # Make the request + response = await client.create_tensorboard_experiment(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_CreateTensorboardExperiment_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_create_tensorboard_experiment_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_create_tensorboard_experiment_sync.py new file mode 100644 index 0000000000..1a41e2342a --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_create_tensorboard_experiment_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTensorboardExperiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_CreateTensorboardExperiment_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_tensorboard_experiment(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateTensorboardExperimentRequest( + parent="parent_value", + tensorboard_experiment_id="tensorboard_experiment_id_value", + ) + + # Make the request + response = client.create_tensorboard_experiment(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_CreateTensorboardExperiment_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_create_tensorboard_run_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_create_tensorboard_run_async.py new file mode 100644 index 0000000000..943526a805 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_create_tensorboard_run_async.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTensorboardRun +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_CreateTensorboardRun_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_tensorboard_run(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + tensorboard_run = aiplatform_v1.TensorboardRun() + tensorboard_run.display_name = "display_name_value" + + request = aiplatform_v1.CreateTensorboardRunRequest( + parent="parent_value", + tensorboard_run=tensorboard_run, + tensorboard_run_id="tensorboard_run_id_value", + ) + + # Make the request + response = await client.create_tensorboard_run(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_CreateTensorboardRun_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_create_tensorboard_run_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_create_tensorboard_run_sync.py new file mode 100644 index 0000000000..009bb07540 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_create_tensorboard_run_sync.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTensorboardRun +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_CreateTensorboardRun_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_tensorboard_run(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + tensorboard_run = aiplatform_v1.TensorboardRun() + tensorboard_run.display_name = "display_name_value" + + request = aiplatform_v1.CreateTensorboardRunRequest( + parent="parent_value", + tensorboard_run=tensorboard_run, + tensorboard_run_id="tensorboard_run_id_value", + ) + + # Make the request + response = client.create_tensorboard_run(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_CreateTensorboardRun_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_create_tensorboard_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_create_tensorboard_sync.py new file mode 100644 index 0000000000..2f73d76774 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_create_tensorboard_sync.py @@ -0,0 +1,53 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTensorboard +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_CreateTensorboard_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_tensorboard(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + tensorboard = aiplatform_v1.Tensorboard() + tensorboard.display_name = "display_name_value" + + request = aiplatform_v1.CreateTensorboardRequest( + parent="parent_value", + tensorboard=tensorboard, + ) + + # Make the request + operation = client.create_tensorboard(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_CreateTensorboard_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_create_tensorboard_time_series_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_create_tensorboard_time_series_async.py new file mode 100644 index 0000000000..9996992c76 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_create_tensorboard_time_series_async.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_CreateTensorboardTimeSeries_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_tensorboard_time_series(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + tensorboard_time_series = aiplatform_v1.TensorboardTimeSeries() + tensorboard_time_series.display_name = "display_name_value" + tensorboard_time_series.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1.CreateTensorboardTimeSeriesRequest( + parent="parent_value", + tensorboard_time_series=tensorboard_time_series, + ) + + # Make the request + response = await client.create_tensorboard_time_series(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_CreateTensorboardTimeSeries_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_create_tensorboard_time_series_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_create_tensorboard_time_series_sync.py new file mode 100644 index 0000000000..935c268b60 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_create_tensorboard_time_series_sync.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_CreateTensorboardTimeSeries_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_tensorboard_time_series(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + tensorboard_time_series = aiplatform_v1.TensorboardTimeSeries() + tensorboard_time_series.display_name = "display_name_value" + tensorboard_time_series.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1.CreateTensorboardTimeSeriesRequest( + parent="parent_value", + tensorboard_time_series=tensorboard_time_series, + ) + + # Make the request + response = client.create_tensorboard_time_series(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_CreateTensorboardTimeSeries_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_delete_tensorboard_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_delete_tensorboard_async.py new file mode 100644 index 0000000000..c77bcde03c --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_delete_tensorboard_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTensorboard +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_DeleteTensorboard_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_tensorboard(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteTensorboardRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_DeleteTensorboard_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_delete_tensorboard_experiment_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_delete_tensorboard_experiment_async.py new file mode 100644 index 0000000000..54d8dd34db --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_delete_tensorboard_experiment_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTensorboardExperiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_DeleteTensorboardExperiment_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_tensorboard_experiment(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteTensorboardExperimentRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard_experiment(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_DeleteTensorboardExperiment_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_delete_tensorboard_experiment_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_delete_tensorboard_experiment_sync.py new file mode 100644 index 0000000000..d24488c736 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_delete_tensorboard_experiment_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTensorboardExperiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_DeleteTensorboardExperiment_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_tensorboard_experiment(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteTensorboardExperimentRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard_experiment(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_DeleteTensorboardExperiment_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_delete_tensorboard_run_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_delete_tensorboard_run_async.py new file mode 100644 index 0000000000..b99937d851 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_delete_tensorboard_run_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTensorboardRun +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_DeleteTensorboardRun_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_tensorboard_run(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteTensorboardRunRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard_run(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_DeleteTensorboardRun_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_delete_tensorboard_run_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_delete_tensorboard_run_sync.py new file mode 100644 index 0000000000..61f28f0748 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_delete_tensorboard_run_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTensorboardRun +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_DeleteTensorboardRun_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_tensorboard_run(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteTensorboardRunRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard_run(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_DeleteTensorboardRun_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_delete_tensorboard_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_delete_tensorboard_sync.py new file mode 100644 index 0000000000..13c9e69ebd --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_delete_tensorboard_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTensorboard +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_DeleteTensorboard_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_tensorboard(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteTensorboardRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_DeleteTensorboard_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_delete_tensorboard_time_series_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_delete_tensorboard_time_series_async.py new file mode 100644 index 0000000000..4c235bf17f --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_delete_tensorboard_time_series_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_DeleteTensorboardTimeSeries_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_tensorboard_time_series(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteTensorboardTimeSeriesRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard_time_series(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_DeleteTensorboardTimeSeries_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_delete_tensorboard_time_series_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_delete_tensorboard_time_series_sync.py new file mode 100644 index 0000000000..5cae0cc839 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_delete_tensorboard_time_series_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_DeleteTensorboardTimeSeries_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_tensorboard_time_series(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteTensorboardTimeSeriesRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard_time_series(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_DeleteTensorboardTimeSeries_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_export_tensorboard_time_series_data_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_export_tensorboard_time_series_data_async.py new file mode 100644 index 0000000000..19d50ba50e --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_export_tensorboard_time_series_data_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportTensorboardTimeSeriesData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_ExportTensorboardTimeSeriesData_async] +from google.cloud import aiplatform_v1 + + +async def sample_export_tensorboard_time_series_data(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ExportTensorboardTimeSeriesDataRequest( + tensorboard_time_series="tensorboard_time_series_value", + ) + + # Make the request + page_result = client.export_tensorboard_time_series_data(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_ExportTensorboardTimeSeriesData_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_export_tensorboard_time_series_data_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_export_tensorboard_time_series_data_sync.py new file mode 100644 index 0000000000..0513c1d6ab --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_export_tensorboard_time_series_data_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportTensorboardTimeSeriesData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_ExportTensorboardTimeSeriesData_sync] +from google.cloud import aiplatform_v1 + + +def sample_export_tensorboard_time_series_data(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ExportTensorboardTimeSeriesDataRequest( + tensorboard_time_series="tensorboard_time_series_value", + ) + + # Make the request + page_result = client.export_tensorboard_time_series_data(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_ExportTensorboardTimeSeriesData_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_get_tensorboard_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_get_tensorboard_async.py new file mode 100644 index 0000000000..0dffe60e2d --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_get_tensorboard_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTensorboard +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_GetTensorboard_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_tensorboard(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetTensorboardRequest( + name="name_value", + ) + + # Make the request + response = await client.get_tensorboard(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_GetTensorboard_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_get_tensorboard_experiment_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_get_tensorboard_experiment_async.py new file mode 100644 index 0000000000..51df65ff18 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_get_tensorboard_experiment_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTensorboardExperiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_GetTensorboardExperiment_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_tensorboard_experiment(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetTensorboardExperimentRequest( + name="name_value", + ) + + # Make the request + response = await client.get_tensorboard_experiment(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_GetTensorboardExperiment_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_get_tensorboard_experiment_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_get_tensorboard_experiment_sync.py new file mode 100644 index 0000000000..99d8b725e9 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_get_tensorboard_experiment_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTensorboardExperiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_GetTensorboardExperiment_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_tensorboard_experiment(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetTensorboardExperimentRequest( + name="name_value", + ) + + # Make the request + response = client.get_tensorboard_experiment(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_GetTensorboardExperiment_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_get_tensorboard_run_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_get_tensorboard_run_async.py new file mode 100644 index 0000000000..7a504549d1 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_get_tensorboard_run_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTensorboardRun +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_GetTensorboardRun_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_tensorboard_run(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetTensorboardRunRequest( + name="name_value", + ) + + # Make the request + response = await client.get_tensorboard_run(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_GetTensorboardRun_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_get_tensorboard_run_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_get_tensorboard_run_sync.py new file mode 100644 index 0000000000..47558e19ba --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_get_tensorboard_run_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTensorboardRun +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_GetTensorboardRun_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_tensorboard_run(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetTensorboardRunRequest( + name="name_value", + ) + + # Make the request + response = client.get_tensorboard_run(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_GetTensorboardRun_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_get_tensorboard_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_get_tensorboard_sync.py new file mode 100644 index 0000000000..5d84ccbe1f --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_get_tensorboard_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTensorboard +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_GetTensorboard_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_tensorboard(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetTensorboardRequest( + name="name_value", + ) + + # Make the request + response = client.get_tensorboard(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_GetTensorboard_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_get_tensorboard_time_series_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_get_tensorboard_time_series_async.py new file mode 100644 index 0000000000..67220f3fac --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_get_tensorboard_time_series_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_GetTensorboardTimeSeries_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_tensorboard_time_series(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetTensorboardTimeSeriesRequest( + name="name_value", + ) + + # Make the request + response = await client.get_tensorboard_time_series(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_GetTensorboardTimeSeries_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_get_tensorboard_time_series_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_get_tensorboard_time_series_sync.py new file mode 100644 index 0000000000..463c9f08c0 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_get_tensorboard_time_series_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_GetTensorboardTimeSeries_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_tensorboard_time_series(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetTensorboardTimeSeriesRequest( + name="name_value", + ) + + # Make the request + response = client.get_tensorboard_time_series(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_GetTensorboardTimeSeries_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_list_tensorboard_experiments_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_list_tensorboard_experiments_async.py new file mode 100644 index 0000000000..69356691fa --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_list_tensorboard_experiments_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTensorboardExperiments +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_ListTensorboardExperiments_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_tensorboard_experiments(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListTensorboardExperimentsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboard_experiments(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_ListTensorboardExperiments_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_list_tensorboard_experiments_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_list_tensorboard_experiments_sync.py new file mode 100644 index 0000000000..34605714e4 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_list_tensorboard_experiments_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTensorboardExperiments +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_ListTensorboardExperiments_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_tensorboard_experiments(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListTensorboardExperimentsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboard_experiments(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_ListTensorboardExperiments_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_list_tensorboard_runs_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_list_tensorboard_runs_async.py new file mode 100644 index 0000000000..4737c272b5 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_list_tensorboard_runs_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTensorboardRuns +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_ListTensorboardRuns_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_tensorboard_runs(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListTensorboardRunsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboard_runs(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_ListTensorboardRuns_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_list_tensorboard_runs_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_list_tensorboard_runs_sync.py new file mode 100644 index 0000000000..15fb4eaaf3 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_list_tensorboard_runs_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTensorboardRuns +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_ListTensorboardRuns_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_tensorboard_runs(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListTensorboardRunsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboard_runs(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_ListTensorboardRuns_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_list_tensorboard_time_series_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_list_tensorboard_time_series_async.py new file mode 100644 index 0000000000..2193c537e2 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_list_tensorboard_time_series_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_ListTensorboardTimeSeries_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_tensorboard_time_series(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListTensorboardTimeSeriesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboard_time_series(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_ListTensorboardTimeSeries_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_list_tensorboard_time_series_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_list_tensorboard_time_series_sync.py new file mode 100644 index 0000000000..030e03cfc9 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_list_tensorboard_time_series_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_ListTensorboardTimeSeries_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_tensorboard_time_series(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListTensorboardTimeSeriesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboard_time_series(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_ListTensorboardTimeSeries_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_list_tensorboards_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_list_tensorboards_async.py new file mode 100644 index 0000000000..5266200c44 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_list_tensorboards_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTensorboards +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_ListTensorboards_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_tensorboards(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListTensorboardsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboards(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_ListTensorboards_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_list_tensorboards_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_list_tensorboards_sync.py new file mode 100644 index 0000000000..09c97d3155 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_list_tensorboards_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTensorboards +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_ListTensorboards_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_tensorboards(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListTensorboardsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboards(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_ListTensorboards_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_read_tensorboard_blob_data_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_read_tensorboard_blob_data_async.py new file mode 100644 index 0000000000..6d9ff861a3 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_read_tensorboard_blob_data_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ReadTensorboardBlobData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_ReadTensorboardBlobData_async] +from google.cloud import aiplatform_v1 + + +async def sample_read_tensorboard_blob_data(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ReadTensorboardBlobDataRequest( + time_series="time_series_value", + ) + + # Make the request + stream = await client.read_tensorboard_blob_data(request=request) + + # Handle the response + async for response in stream: + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_ReadTensorboardBlobData_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_read_tensorboard_blob_data_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_read_tensorboard_blob_data_sync.py new file mode 100644 index 0000000000..6f45a63423 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_read_tensorboard_blob_data_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ReadTensorboardBlobData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_ReadTensorboardBlobData_sync] +from google.cloud import aiplatform_v1 + + +def sample_read_tensorboard_blob_data(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ReadTensorboardBlobDataRequest( + time_series="time_series_value", + ) + + # Make the request + stream = client.read_tensorboard_blob_data(request=request) + + # Handle the response + for response in stream: + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_ReadTensorboardBlobData_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_read_tensorboard_time_series_data_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_read_tensorboard_time_series_data_async.py new file mode 100644 index 0000000000..4d8f1970e4 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_read_tensorboard_time_series_data_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ReadTensorboardTimeSeriesData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_ReadTensorboardTimeSeriesData_async] +from google.cloud import aiplatform_v1 + + +async def sample_read_tensorboard_time_series_data(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ReadTensorboardTimeSeriesDataRequest( + tensorboard_time_series="tensorboard_time_series_value", + ) + + # Make the request + response = await client.read_tensorboard_time_series_data(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_ReadTensorboardTimeSeriesData_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_read_tensorboard_time_series_data_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_read_tensorboard_time_series_data_sync.py new file mode 100644 index 0000000000..c22c96855b --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_read_tensorboard_time_series_data_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ReadTensorboardTimeSeriesData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_ReadTensorboardTimeSeriesData_sync] +from google.cloud import aiplatform_v1 + + +def sample_read_tensorboard_time_series_data(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ReadTensorboardTimeSeriesDataRequest( + tensorboard_time_series="tensorboard_time_series_value", + ) + + # Make the request + response = client.read_tensorboard_time_series_data(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_ReadTensorboardTimeSeriesData_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_update_tensorboard_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_update_tensorboard_async.py new file mode 100644 index 0000000000..21b41292af --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_update_tensorboard_async.py @@ -0,0 +1,52 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateTensorboard +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_UpdateTensorboard_async] +from google.cloud import aiplatform_v1 + + +async def sample_update_tensorboard(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + tensorboard = aiplatform_v1.Tensorboard() + tensorboard.display_name = "display_name_value" + + request = aiplatform_v1.UpdateTensorboardRequest( + tensorboard=tensorboard, + ) + + # Make the request + operation = client.update_tensorboard(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_UpdateTensorboard_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_update_tensorboard_experiment_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_update_tensorboard_experiment_async.py new file mode 100644 index 0000000000..e4ccc12a0a --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_update_tensorboard_experiment_async.py @@ -0,0 +1,44 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateTensorboardExperiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_UpdateTensorboardExperiment_async] +from google.cloud import aiplatform_v1 + + +async def sample_update_tensorboard_experiment(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.UpdateTensorboardExperimentRequest( + ) + + # Make the request + response = await client.update_tensorboard_experiment(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_UpdateTensorboardExperiment_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_update_tensorboard_experiment_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_update_tensorboard_experiment_sync.py new file mode 100644 index 0000000000..a914538833 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_update_tensorboard_experiment_sync.py @@ -0,0 +1,44 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateTensorboardExperiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_UpdateTensorboardExperiment_sync] +from google.cloud import aiplatform_v1 + + +def sample_update_tensorboard_experiment(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.UpdateTensorboardExperimentRequest( + ) + + # Make the request + response = client.update_tensorboard_experiment(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_UpdateTensorboardExperiment_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_update_tensorboard_run_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_update_tensorboard_run_async.py new file mode 100644 index 0000000000..c847c93f84 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_update_tensorboard_run_async.py @@ -0,0 +1,48 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateTensorboardRun +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_UpdateTensorboardRun_async] +from google.cloud import aiplatform_v1 + + +async def sample_update_tensorboard_run(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + tensorboard_run = aiplatform_v1.TensorboardRun() + tensorboard_run.display_name = "display_name_value" + + request = aiplatform_v1.UpdateTensorboardRunRequest( + tensorboard_run=tensorboard_run, + ) + + # Make the request + response = await client.update_tensorboard_run(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_UpdateTensorboardRun_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_update_tensorboard_run_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_update_tensorboard_run_sync.py new file mode 100644 index 0000000000..0333b8997a --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_update_tensorboard_run_sync.py @@ -0,0 +1,48 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateTensorboardRun +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_UpdateTensorboardRun_sync] +from google.cloud import aiplatform_v1 + + +def sample_update_tensorboard_run(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + tensorboard_run = aiplatform_v1.TensorboardRun() + tensorboard_run.display_name = "display_name_value" + + request = aiplatform_v1.UpdateTensorboardRunRequest( + tensorboard_run=tensorboard_run, + ) + + # Make the request + response = client.update_tensorboard_run(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_UpdateTensorboardRun_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_update_tensorboard_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_update_tensorboard_sync.py new file mode 100644 index 0000000000..5c95bc1313 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_update_tensorboard_sync.py @@ -0,0 +1,52 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateTensorboard +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_UpdateTensorboard_sync] +from google.cloud import aiplatform_v1 + + +def sample_update_tensorboard(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + tensorboard = aiplatform_v1.Tensorboard() + tensorboard.display_name = "display_name_value" + + request = aiplatform_v1.UpdateTensorboardRequest( + tensorboard=tensorboard, + ) + + # Make the request + operation = client.update_tensorboard(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_UpdateTensorboard_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_update_tensorboard_time_series_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_update_tensorboard_time_series_async.py new file mode 100644 index 0000000000..88cc10bbfc --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_update_tensorboard_time_series_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_UpdateTensorboardTimeSeries_async] +from google.cloud import aiplatform_v1 + + +async def sample_update_tensorboard_time_series(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + tensorboard_time_series = aiplatform_v1.TensorboardTimeSeries() + tensorboard_time_series.display_name = "display_name_value" + tensorboard_time_series.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1.UpdateTensorboardTimeSeriesRequest( + tensorboard_time_series=tensorboard_time_series, + ) + + # Make the request + response = await client.update_tensorboard_time_series(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_UpdateTensorboardTimeSeries_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_update_tensorboard_time_series_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_update_tensorboard_time_series_sync.py new file mode 100644 index 0000000000..312becd505 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_update_tensorboard_time_series_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_UpdateTensorboardTimeSeries_sync] +from google.cloud import aiplatform_v1 + + +def sample_update_tensorboard_time_series(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + tensorboard_time_series = aiplatform_v1.TensorboardTimeSeries() + tensorboard_time_series.display_name = "display_name_value" + tensorboard_time_series.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1.UpdateTensorboardTimeSeriesRequest( + tensorboard_time_series=tensorboard_time_series, + ) + + # Make the request + response = client.update_tensorboard_time_series(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_UpdateTensorboardTimeSeries_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_write_tensorboard_experiment_data_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_write_tensorboard_experiment_data_async.py new file mode 100644 index 0000000000..df22a35021 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_write_tensorboard_experiment_data_async.py @@ -0,0 +1,51 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for WriteTensorboardExperimentData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_WriteTensorboardExperimentData_async] +from google.cloud import aiplatform_v1 + + +async def sample_write_tensorboard_experiment_data(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + write_run_data_requests = aiplatform_v1.WriteTensorboardRunDataRequest() + write_run_data_requests.tensorboard_run = "tensorboard_run_value" + write_run_data_requests.time_series_data.tensorboard_time_series_id = "tensorboard_time_series_id_value" + write_run_data_requests.time_series_data.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1.WriteTensorboardExperimentDataRequest( + tensorboard_experiment="tensorboard_experiment_value", + write_run_data_requests=write_run_data_requests, + ) + + # Make the request + response = await client.write_tensorboard_experiment_data(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_WriteTensorboardExperimentData_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_write_tensorboard_experiment_data_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_write_tensorboard_experiment_data_sync.py new file mode 100644 index 0000000000..2f40a16f87 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_write_tensorboard_experiment_data_sync.py @@ -0,0 +1,51 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for WriteTensorboardExperimentData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_WriteTensorboardExperimentData_sync] +from google.cloud import aiplatform_v1 + + +def sample_write_tensorboard_experiment_data(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + write_run_data_requests = aiplatform_v1.WriteTensorboardRunDataRequest() + write_run_data_requests.tensorboard_run = "tensorboard_run_value" + write_run_data_requests.time_series_data.tensorboard_time_series_id = "tensorboard_time_series_id_value" + write_run_data_requests.time_series_data.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1.WriteTensorboardExperimentDataRequest( + tensorboard_experiment="tensorboard_experiment_value", + write_run_data_requests=write_run_data_requests, + ) + + # Make the request + response = client.write_tensorboard_experiment_data(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_WriteTensorboardExperimentData_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_write_tensorboard_run_data_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_write_tensorboard_run_data_async.py new file mode 100644 index 0000000000..c4b4680f7a --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_write_tensorboard_run_data_async.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for WriteTensorboardRunData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_WriteTensorboardRunData_async] +from google.cloud import aiplatform_v1 + + +async def sample_write_tensorboard_run_data(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + time_series_data = aiplatform_v1.TimeSeriesData() + time_series_data.tensorboard_time_series_id = "tensorboard_time_series_id_value" + time_series_data.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1.WriteTensorboardRunDataRequest( + tensorboard_run="tensorboard_run_value", + time_series_data=time_series_data, + ) + + # Make the request + response = await client.write_tensorboard_run_data(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_WriteTensorboardRunData_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_write_tensorboard_run_data_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_write_tensorboard_run_data_sync.py new file mode 100644 index 0000000000..b29147d3fc --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_tensorboard_service_write_tensorboard_run_data_sync.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for WriteTensorboardRunData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_TensorboardService_WriteTensorboardRunData_sync] +from google.cloud import aiplatform_v1 + + +def sample_write_tensorboard_run_data(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + time_series_data = aiplatform_v1.TimeSeriesData() + time_series_data.tensorboard_time_series_id = "tensorboard_time_series_id_value" + time_series_data.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1.WriteTensorboardRunDataRequest( + tensorboard_run="tensorboard_run_value", + time_series_data=time_series_data, + ) + + # Make the request + response = client.write_tensorboard_run_data(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_TensorboardService_WriteTensorboardRunData_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_add_trial_measurement_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_add_trial_measurement_async.py new file mode 100644 index 0000000000..bba7fee36d --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_add_trial_measurement_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddTrialMeasurement +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_VizierService_AddTrialMeasurement_async] +from google.cloud import aiplatform_v1 + + +async def sample_add_trial_measurement(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.AddTrialMeasurementRequest( + trial_name="trial_name_value", + ) + + # Make the request + response = await client.add_trial_measurement(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_VizierService_AddTrialMeasurement_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_add_trial_measurement_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_add_trial_measurement_sync.py new file mode 100644 index 0000000000..f507fe23e1 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_add_trial_measurement_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddTrialMeasurement +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_VizierService_AddTrialMeasurement_sync] +from google.cloud import aiplatform_v1 + + +def sample_add_trial_measurement(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.AddTrialMeasurementRequest( + trial_name="trial_name_value", + ) + + # Make the request + response = client.add_trial_measurement(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_VizierService_AddTrialMeasurement_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_check_trial_early_stopping_state_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_check_trial_early_stopping_state_async.py new file mode 100644 index 0000000000..b6e5c4a5aa --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_check_trial_early_stopping_state_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CheckTrialEarlyStoppingState +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_VizierService_CheckTrialEarlyStoppingState_async] +from google.cloud import aiplatform_v1 + + +async def sample_check_trial_early_stopping_state(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CheckTrialEarlyStoppingStateRequest( + trial_name="trial_name_value", + ) + + # Make the request + operation = client.check_trial_early_stopping_state(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_VizierService_CheckTrialEarlyStoppingState_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_check_trial_early_stopping_state_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_check_trial_early_stopping_state_sync.py new file mode 100644 index 0000000000..b3dad28e79 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_check_trial_early_stopping_state_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CheckTrialEarlyStoppingState +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_VizierService_CheckTrialEarlyStoppingState_sync] +from google.cloud import aiplatform_v1 + + +def sample_check_trial_early_stopping_state(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CheckTrialEarlyStoppingStateRequest( + trial_name="trial_name_value", + ) + + # Make the request + operation = client.check_trial_early_stopping_state(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_VizierService_CheckTrialEarlyStoppingState_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_complete_trial_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_complete_trial_async.py new file mode 100644 index 0000000000..681460ce51 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_complete_trial_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CompleteTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_VizierService_CompleteTrial_async] +from google.cloud import aiplatform_v1 + + +async def sample_complete_trial(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CompleteTrialRequest( + name="name_value", + ) + + # Make the request + response = await client.complete_trial(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_VizierService_CompleteTrial_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_complete_trial_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_complete_trial_sync.py new file mode 100644 index 0000000000..846dbe337e --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_complete_trial_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CompleteTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_VizierService_CompleteTrial_sync] +from google.cloud import aiplatform_v1 + + +def sample_complete_trial(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CompleteTrialRequest( + name="name_value", + ) + + # Make the request + response = client.complete_trial(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_VizierService_CompleteTrial_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_create_study_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_create_study_async.py new file mode 100644 index 0000000000..f4b17517af --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_create_study_async.py @@ -0,0 +1,54 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateStudy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_VizierService_CreateStudy_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_study(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + study = aiplatform_v1.Study() + study.display_name = "display_name_value" + study.study_spec.metrics.metric_id = "metric_id_value" + study.study_spec.metrics.goal = "MINIMIZE" + study.study_spec.parameters.double_value_spec.min_value = 0.96 + study.study_spec.parameters.double_value_spec.max_value = 0.962 + study.study_spec.parameters.parameter_id = "parameter_id_value" + + request = aiplatform_v1.CreateStudyRequest( + parent="parent_value", + study=study, + ) + + # Make the request + response = await client.create_study(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_VizierService_CreateStudy_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_create_study_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_create_study_sync.py new file mode 100644 index 0000000000..18ab422f10 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_create_study_sync.py @@ -0,0 +1,54 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateStudy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_VizierService_CreateStudy_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_study(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + study = aiplatform_v1.Study() + study.display_name = "display_name_value" + study.study_spec.metrics.metric_id = "metric_id_value" + study.study_spec.metrics.goal = "MINIMIZE" + study.study_spec.parameters.double_value_spec.min_value = 0.96 + study.study_spec.parameters.double_value_spec.max_value = 0.962 + study.study_spec.parameters.parameter_id = "parameter_id_value" + + request = aiplatform_v1.CreateStudyRequest( + parent="parent_value", + study=study, + ) + + # Make the request + response = client.create_study(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_VizierService_CreateStudy_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_create_trial_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_create_trial_async.py new file mode 100644 index 0000000000..c3c33b93e5 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_create_trial_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_VizierService_CreateTrial_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_trial(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateTrialRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_trial(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_VizierService_CreateTrial_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_create_trial_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_create_trial_sync.py new file mode 100644 index 0000000000..d6ca08c7be --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_create_trial_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_VizierService_CreateTrial_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_trial(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateTrialRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_trial(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_VizierService_CreateTrial_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_delete_study_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_delete_study_async.py new file mode 100644 index 0000000000..39c48de3df --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_delete_study_async.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteStudy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_VizierService_DeleteStudy_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_study(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteStudyRequest( + name="name_value", + ) + + # Make the request + await client.delete_study(request=request) + + +# [END aiplatform_generated_aiplatform_v1_VizierService_DeleteStudy_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_delete_study_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_delete_study_sync.py new file mode 100644 index 0000000000..46f7929357 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_delete_study_sync.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteStudy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_VizierService_DeleteStudy_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_study(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteStudyRequest( + name="name_value", + ) + + # Make the request + client.delete_study(request=request) + + +# [END aiplatform_generated_aiplatform_v1_VizierService_DeleteStudy_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_delete_trial_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_delete_trial_async.py new file mode 100644 index 0000000000..052f351c55 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_delete_trial_async.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_VizierService_DeleteTrial_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_trial(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteTrialRequest( + name="name_value", + ) + + # Make the request + await client.delete_trial(request=request) + + +# [END aiplatform_generated_aiplatform_v1_VizierService_DeleteTrial_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_delete_trial_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_delete_trial_sync.py new file mode 100644 index 0000000000..1c7b2a85b2 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_delete_trial_sync.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_VizierService_DeleteTrial_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_trial(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteTrialRequest( + name="name_value", + ) + + # Make the request + client.delete_trial(request=request) + + +# [END aiplatform_generated_aiplatform_v1_VizierService_DeleteTrial_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_get_study_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_get_study_async.py new file mode 100644 index 0000000000..4b23e34234 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_get_study_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetStudy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_VizierService_GetStudy_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_study(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetStudyRequest( + name="name_value", + ) + + # Make the request + response = await client.get_study(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_VizierService_GetStudy_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_get_study_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_get_study_sync.py new file mode 100644 index 0000000000..f7566610b3 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_get_study_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetStudy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_VizierService_GetStudy_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_study(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetStudyRequest( + name="name_value", + ) + + # Make the request + response = client.get_study(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_VizierService_GetStudy_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_get_trial_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_get_trial_async.py new file mode 100644 index 0000000000..61e9c6be57 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_get_trial_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_VizierService_GetTrial_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_trial(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetTrialRequest( + name="name_value", + ) + + # Make the request + response = await client.get_trial(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_VizierService_GetTrial_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_get_trial_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_get_trial_sync.py new file mode 100644 index 0000000000..1eb2d2717b --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_get_trial_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_VizierService_GetTrial_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_trial(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetTrialRequest( + name="name_value", + ) + + # Make the request + response = client.get_trial(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_VizierService_GetTrial_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_list_optimal_trials_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_list_optimal_trials_async.py new file mode 100644 index 0000000000..e8f5c108ad --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_list_optimal_trials_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListOptimalTrials +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_VizierService_ListOptimalTrials_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_optimal_trials(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListOptimalTrialsRequest( + parent="parent_value", + ) + + # Make the request + response = await client.list_optimal_trials(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_VizierService_ListOptimalTrials_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_list_optimal_trials_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_list_optimal_trials_sync.py new file mode 100644 index 0000000000..c6745dff6d --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_list_optimal_trials_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListOptimalTrials +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_VizierService_ListOptimalTrials_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_optimal_trials(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListOptimalTrialsRequest( + parent="parent_value", + ) + + # Make the request + response = client.list_optimal_trials(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_VizierService_ListOptimalTrials_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_list_studies_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_list_studies_async.py new file mode 100644 index 0000000000..a207937ebf --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_list_studies_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListStudies +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_VizierService_ListStudies_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_studies(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListStudiesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_studies(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_VizierService_ListStudies_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_list_studies_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_list_studies_sync.py new file mode 100644 index 0000000000..6d164d05a6 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_list_studies_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListStudies +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_VizierService_ListStudies_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_studies(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListStudiesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_studies(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_VizierService_ListStudies_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_list_trials_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_list_trials_async.py new file mode 100644 index 0000000000..bd24ba88c9 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_list_trials_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTrials +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_VizierService_ListTrials_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_trials(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListTrialsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_trials(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_VizierService_ListTrials_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_list_trials_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_list_trials_sync.py new file mode 100644 index 0000000000..24e2d84709 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_list_trials_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTrials +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_VizierService_ListTrials_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_trials(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListTrialsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_trials(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1_VizierService_ListTrials_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_lookup_study_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_lookup_study_async.py new file mode 100644 index 0000000000..4f87a235fd --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_lookup_study_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for LookupStudy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_VizierService_LookupStudy_async] +from google.cloud import aiplatform_v1 + + +async def sample_lookup_study(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.LookupStudyRequest( + parent="parent_value", + display_name="display_name_value", + ) + + # Make the request + response = await client.lookup_study(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_VizierService_LookupStudy_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_lookup_study_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_lookup_study_sync.py new file mode 100644 index 0000000000..daed7351d1 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_lookup_study_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for LookupStudy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_VizierService_LookupStudy_sync] +from google.cloud import aiplatform_v1 + + +def sample_lookup_study(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.LookupStudyRequest( + parent="parent_value", + display_name="display_name_value", + ) + + # Make the request + response = client.lookup_study(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_VizierService_LookupStudy_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_stop_trial_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_stop_trial_async.py new file mode 100644 index 0000000000..0a29c0e484 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_stop_trial_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for StopTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_VizierService_StopTrial_async] +from google.cloud import aiplatform_v1 + + +async def sample_stop_trial(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.StopTrialRequest( + name="name_value", + ) + + # Make the request + response = await client.stop_trial(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_VizierService_StopTrial_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_stop_trial_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_stop_trial_sync.py new file mode 100644 index 0000000000..0d1c45a2e4 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_stop_trial_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for StopTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_VizierService_StopTrial_sync] +from google.cloud import aiplatform_v1 + + +def sample_stop_trial(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.StopTrialRequest( + name="name_value", + ) + + # Make the request + response = client.stop_trial(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_VizierService_StopTrial_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_suggest_trials_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_suggest_trials_async.py new file mode 100644 index 0000000000..5a604672c3 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_suggest_trials_async.py @@ -0,0 +1,51 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SuggestTrials +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_VizierService_SuggestTrials_async] +from google.cloud import aiplatform_v1 + + +async def sample_suggest_trials(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.SuggestTrialsRequest( + parent="parent_value", + suggestion_count=1744, + client_id="client_id_value", + ) + + # Make the request + operation = client.suggest_trials(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_VizierService_SuggestTrials_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_suggest_trials_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_suggest_trials_sync.py new file mode 100644 index 0000000000..1b733b2f9f --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1_vizier_service_suggest_trials_sync.py @@ -0,0 +1,51 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SuggestTrials +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1_VizierService_SuggestTrials_sync] +from google.cloud import aiplatform_v1 + + +def sample_suggest_trials(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.SuggestTrialsRequest( + parent="parent_value", + suggestion_count=1744, + client_id="client_id_value", + ) + + # Make the request + operation = client.suggest_trials(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1_VizierService_SuggestTrials_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_create_dataset_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_create_dataset_async.py new file mode 100644 index 0000000000..8790a59835 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_create_dataset_async.py @@ -0,0 +1,55 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateDataset +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_DatasetService_CreateDataset_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_dataset(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + dataset = aiplatform_v1beta1.Dataset() + dataset.display_name = "display_name_value" + dataset.metadata_schema_uri = "metadata_schema_uri_value" + dataset.metadata.null_value = "NULL_VALUE" + + request = aiplatform_v1beta1.CreateDatasetRequest( + parent="parent_value", + dataset=dataset, + ) + + # Make the request + operation = client.create_dataset(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_DatasetService_CreateDataset_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_create_dataset_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_create_dataset_sync.py new file mode 100644 index 0000000000..9dd9ca09e5 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_create_dataset_sync.py @@ -0,0 +1,55 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateDataset +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_DatasetService_CreateDataset_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_dataset(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceClient() + + # Initialize request argument(s) + dataset = aiplatform_v1beta1.Dataset() + dataset.display_name = "display_name_value" + dataset.metadata_schema_uri = "metadata_schema_uri_value" + dataset.metadata.null_value = "NULL_VALUE" + + request = aiplatform_v1beta1.CreateDatasetRequest( + parent="parent_value", + dataset=dataset, + ) + + # Make the request + operation = client.create_dataset(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_DatasetService_CreateDataset_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_delete_dataset_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_delete_dataset_async.py new file mode 100644 index 0000000000..1d048a5531 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_delete_dataset_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteDataset +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_DatasetService_DeleteDataset_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_dataset(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteDatasetRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_dataset(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_DatasetService_DeleteDataset_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_delete_dataset_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_delete_dataset_sync.py new file mode 100644 index 0000000000..956a153c3e --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_delete_dataset_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteDataset +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_DatasetService_DeleteDataset_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_dataset(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteDatasetRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_dataset(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_DatasetService_DeleteDataset_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_export_data_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_export_data_async.py new file mode 100644 index 0000000000..b439cc0712 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_export_data_async.py @@ -0,0 +1,53 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_DatasetService_ExportData_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_export_data(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + export_config = aiplatform_v1beta1.ExportDataConfig() + export_config.gcs_destination.output_uri_prefix = "output_uri_prefix_value" + + request = aiplatform_v1beta1.ExportDataRequest( + name="name_value", + export_config=export_config, + ) + + # Make the request + operation = client.export_data(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_DatasetService_ExportData_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_export_data_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_export_data_sync.py new file mode 100644 index 0000000000..abba28b612 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_export_data_sync.py @@ -0,0 +1,53 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_DatasetService_ExportData_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_export_data(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceClient() + + # Initialize request argument(s) + export_config = aiplatform_v1beta1.ExportDataConfig() + export_config.gcs_destination.output_uri_prefix = "output_uri_prefix_value" + + request = aiplatform_v1beta1.ExportDataRequest( + name="name_value", + export_config=export_config, + ) + + # Make the request + operation = client.export_data(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_DatasetService_ExportData_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_get_annotation_spec_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_get_annotation_spec_async.py new file mode 100644 index 0000000000..66bc7074f9 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_get_annotation_spec_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetAnnotationSpec +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_DatasetService_GetAnnotationSpec_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_annotation_spec(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetAnnotationSpecRequest( + name="name_value", + ) + + # Make the request + response = await client.get_annotation_spec(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_DatasetService_GetAnnotationSpec_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_get_annotation_spec_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_get_annotation_spec_sync.py new file mode 100644 index 0000000000..b6ae993cea --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_get_annotation_spec_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetAnnotationSpec +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_DatasetService_GetAnnotationSpec_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_annotation_spec(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetAnnotationSpecRequest( + name="name_value", + ) + + # Make the request + response = client.get_annotation_spec(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_DatasetService_GetAnnotationSpec_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_get_dataset_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_get_dataset_async.py new file mode 100644 index 0000000000..ded49f4cdb --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_get_dataset_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetDataset +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_DatasetService_GetDataset_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_dataset(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetDatasetRequest( + name="name_value", + ) + + # Make the request + response = await client.get_dataset(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_DatasetService_GetDataset_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_get_dataset_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_get_dataset_sync.py new file mode 100644 index 0000000000..2b13c32dc4 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_get_dataset_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetDataset +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_DatasetService_GetDataset_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_dataset(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetDatasetRequest( + name="name_value", + ) + + # Make the request + response = client.get_dataset(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_DatasetService_GetDataset_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_import_data_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_import_data_async.py new file mode 100644 index 0000000000..fdfe38150e --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_import_data_async.py @@ -0,0 +1,54 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ImportData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_DatasetService_ImportData_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_import_data(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + import_configs = aiplatform_v1beta1.ImportDataConfig() + import_configs.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + import_configs.import_schema_uri = "import_schema_uri_value" + + request = aiplatform_v1beta1.ImportDataRequest( + name="name_value", + import_configs=import_configs, + ) + + # Make the request + operation = client.import_data(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_DatasetService_ImportData_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_import_data_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_import_data_sync.py new file mode 100644 index 0000000000..241133d149 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_import_data_sync.py @@ -0,0 +1,54 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ImportData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_DatasetService_ImportData_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_import_data(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceClient() + + # Initialize request argument(s) + import_configs = aiplatform_v1beta1.ImportDataConfig() + import_configs.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + import_configs.import_schema_uri = "import_schema_uri_value" + + request = aiplatform_v1beta1.ImportDataRequest( + name="name_value", + import_configs=import_configs, + ) + + # Make the request + operation = client.import_data(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_DatasetService_ImportData_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_list_annotations_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_list_annotations_async.py new file mode 100644 index 0000000000..d138891541 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_list_annotations_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListAnnotations +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_DatasetService_ListAnnotations_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_annotations(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListAnnotationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_annotations(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_DatasetService_ListAnnotations_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_list_annotations_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_list_annotations_sync.py new file mode 100644 index 0000000000..e73c42f8e8 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_list_annotations_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListAnnotations +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_DatasetService_ListAnnotations_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_annotations(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListAnnotationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_annotations(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_DatasetService_ListAnnotations_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_list_data_items_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_list_data_items_async.py new file mode 100644 index 0000000000..91e2690ef1 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_list_data_items_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDataItems +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_DatasetService_ListDataItems_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_data_items(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListDataItemsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_data_items(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_DatasetService_ListDataItems_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_list_data_items_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_list_data_items_sync.py new file mode 100644 index 0000000000..1f5063fcc0 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_list_data_items_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDataItems +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_DatasetService_ListDataItems_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_data_items(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListDataItemsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_data_items(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_DatasetService_ListDataItems_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_list_datasets_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_list_datasets_async.py new file mode 100644 index 0000000000..fbce88bf42 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_list_datasets_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDatasets +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_DatasetService_ListDatasets_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_datasets(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListDatasetsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_datasets(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_DatasetService_ListDatasets_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_list_datasets_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_list_datasets_sync.py new file mode 100644 index 0000000000..4f4c1ff9fe --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_list_datasets_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDatasets +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_DatasetService_ListDatasets_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_datasets(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListDatasetsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_datasets(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_DatasetService_ListDatasets_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_update_dataset_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_update_dataset_async.py new file mode 100644 index 0000000000..50420cea12 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_update_dataset_async.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateDataset +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_DatasetService_UpdateDataset_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_update_dataset(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + dataset = aiplatform_v1beta1.Dataset() + dataset.display_name = "display_name_value" + dataset.metadata_schema_uri = "metadata_schema_uri_value" + dataset.metadata.null_value = "NULL_VALUE" + + request = aiplatform_v1beta1.UpdateDatasetRequest( + dataset=dataset, + ) + + # Make the request + response = await client.update_dataset(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_DatasetService_UpdateDataset_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_update_dataset_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_update_dataset_sync.py new file mode 100644 index 0000000000..96bbc05459 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_dataset_service_update_dataset_sync.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateDataset +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_DatasetService_UpdateDataset_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_update_dataset(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceClient() + + # Initialize request argument(s) + dataset = aiplatform_v1beta1.Dataset() + dataset.display_name = "display_name_value" + dataset.metadata_schema_uri = "metadata_schema_uri_value" + dataset.metadata.null_value = "NULL_VALUE" + + request = aiplatform_v1beta1.UpdateDatasetRequest( + dataset=dataset, + ) + + # Make the request + response = client.update_dataset(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_DatasetService_UpdateDataset_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_create_endpoint_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_create_endpoint_async.py new file mode 100644 index 0000000000..1b93540a90 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_create_endpoint_async.py @@ -0,0 +1,53 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_EndpointService_CreateEndpoint_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_endpoint(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + endpoint = aiplatform_v1beta1.Endpoint() + endpoint.display_name = "display_name_value" + + request = aiplatform_v1beta1.CreateEndpointRequest( + parent="parent_value", + endpoint=endpoint, + ) + + # Make the request + operation = client.create_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_EndpointService_CreateEndpoint_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_create_endpoint_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_create_endpoint_sync.py new file mode 100644 index 0000000000..9c7b1693f4 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_create_endpoint_sync.py @@ -0,0 +1,53 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_EndpointService_CreateEndpoint_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_endpoint(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceClient() + + # Initialize request argument(s) + endpoint = aiplatform_v1beta1.Endpoint() + endpoint.display_name = "display_name_value" + + request = aiplatform_v1beta1.CreateEndpointRequest( + parent="parent_value", + endpoint=endpoint, + ) + + # Make the request + operation = client.create_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_EndpointService_CreateEndpoint_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_delete_endpoint_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_delete_endpoint_async.py new file mode 100644 index 0000000000..0711fcf13a --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_delete_endpoint_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_EndpointService_DeleteEndpoint_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_endpoint(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteEndpointRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_EndpointService_DeleteEndpoint_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_delete_endpoint_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_delete_endpoint_sync.py new file mode 100644 index 0000000000..c32aebd9e0 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_delete_endpoint_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_EndpointService_DeleteEndpoint_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_endpoint(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteEndpointRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_EndpointService_DeleteEndpoint_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_deploy_model_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_deploy_model_async.py new file mode 100644 index 0000000000..6e47bd0d84 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_deploy_model_async.py @@ -0,0 +1,54 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeployModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_EndpointService_DeployModel_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_deploy_model(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + deployed_model = aiplatform_v1beta1.DeployedModel() + deployed_model.dedicated_resources.min_replica_count = 1803 + deployed_model.model = "model_value" + + request = aiplatform_v1beta1.DeployModelRequest( + endpoint="endpoint_value", + deployed_model=deployed_model, + ) + + # Make the request + operation = client.deploy_model(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_EndpointService_DeployModel_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_deploy_model_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_deploy_model_sync.py new file mode 100644 index 0000000000..e42d116949 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_deploy_model_sync.py @@ -0,0 +1,54 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeployModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_EndpointService_DeployModel_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_deploy_model(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceClient() + + # Initialize request argument(s) + deployed_model = aiplatform_v1beta1.DeployedModel() + deployed_model.dedicated_resources.min_replica_count = 1803 + deployed_model.model = "model_value" + + request = aiplatform_v1beta1.DeployModelRequest( + endpoint="endpoint_value", + deployed_model=deployed_model, + ) + + # Make the request + operation = client.deploy_model(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_EndpointService_DeployModel_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_get_endpoint_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_get_endpoint_async.py new file mode 100644 index 0000000000..7a9ecc6ff2 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_get_endpoint_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_EndpointService_GetEndpoint_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_endpoint(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetEndpointRequest( + name="name_value", + ) + + # Make the request + response = await client.get_endpoint(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_EndpointService_GetEndpoint_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_get_endpoint_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_get_endpoint_sync.py new file mode 100644 index 0000000000..89a2781f64 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_get_endpoint_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_EndpointService_GetEndpoint_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_endpoint(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetEndpointRequest( + name="name_value", + ) + + # Make the request + response = client.get_endpoint(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_EndpointService_GetEndpoint_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_list_endpoints_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_list_endpoints_async.py new file mode 100644 index 0000000000..bc579602be --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_list_endpoints_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListEndpoints +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_EndpointService_ListEndpoints_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_endpoints(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListEndpointsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_endpoints(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_EndpointService_ListEndpoints_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_list_endpoints_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_list_endpoints_sync.py new file mode 100644 index 0000000000..e4bd7f3250 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_list_endpoints_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListEndpoints +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_EndpointService_ListEndpoints_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_endpoints(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListEndpointsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_endpoints(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_EndpointService_ListEndpoints_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_undeploy_model_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_undeploy_model_async.py new file mode 100644 index 0000000000..f4c87cd294 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_undeploy_model_async.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UndeployModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_EndpointService_UndeployModel_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_undeploy_model(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UndeployModelRequest( + endpoint="endpoint_value", + deployed_model_id="deployed_model_id_value", + ) + + # Make the request + operation = client.undeploy_model(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_EndpointService_UndeployModel_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_undeploy_model_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_undeploy_model_sync.py new file mode 100644 index 0000000000..9107fe1553 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_undeploy_model_sync.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UndeployModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_EndpointService_UndeployModel_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_undeploy_model(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UndeployModelRequest( + endpoint="endpoint_value", + deployed_model_id="deployed_model_id_value", + ) + + # Make the request + operation = client.undeploy_model(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_EndpointService_UndeployModel_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_update_endpoint_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_update_endpoint_async.py new file mode 100644 index 0000000000..18325685dd --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_update_endpoint_async.py @@ -0,0 +1,48 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_EndpointService_UpdateEndpoint_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_update_endpoint(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + endpoint = aiplatform_v1beta1.Endpoint() + endpoint.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateEndpointRequest( + endpoint=endpoint, + ) + + # Make the request + response = await client.update_endpoint(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_EndpointService_UpdateEndpoint_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_update_endpoint_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_update_endpoint_sync.py new file mode 100644 index 0000000000..b9c7e60334 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_endpoint_service_update_endpoint_sync.py @@ -0,0 +1,48 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_EndpointService_UpdateEndpoint_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_update_endpoint(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceClient() + + # Initialize request argument(s) + endpoint = aiplatform_v1beta1.Endpoint() + endpoint.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateEndpointRequest( + endpoint=endpoint, + ) + + # Make the request + response = client.update_endpoint(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_EndpointService_UpdateEndpoint_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_online_serving_service_read_feature_values_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_online_serving_service_read_feature_values_async.py new file mode 100644 index 0000000000..695faa816a --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_online_serving_service_read_feature_values_async.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ReadFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreOnlineServingService_ReadFeatureValues_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_read_feature_values(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreOnlineServingServiceAsyncClient() + + # Initialize request argument(s) + feature_selector = aiplatform_v1beta1.FeatureSelector() + feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1beta1.ReadFeatureValuesRequest( + entity_type="entity_type_value", + entity_id="entity_id_value", + feature_selector=feature_selector, + ) + + # Make the request + response = await client.read_feature_values(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreOnlineServingService_ReadFeatureValues_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_online_serving_service_read_feature_values_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_online_serving_service_read_feature_values_sync.py new file mode 100644 index 0000000000..a5aa640a7f --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_online_serving_service_read_feature_values_sync.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ReadFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreOnlineServingService_ReadFeatureValues_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_read_feature_values(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreOnlineServingServiceClient() + + # Initialize request argument(s) + feature_selector = aiplatform_v1beta1.FeatureSelector() + feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1beta1.ReadFeatureValuesRequest( + entity_type="entity_type_value", + entity_id="entity_id_value", + feature_selector=feature_selector, + ) + + # Make the request + response = client.read_feature_values(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreOnlineServingService_ReadFeatureValues_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_online_serving_service_streaming_read_feature_values_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_online_serving_service_streaming_read_feature_values_async.py new file mode 100644 index 0000000000..f094c89a90 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_online_serving_service_streaming_read_feature_values_async.py @@ -0,0 +1,51 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for StreamingReadFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreOnlineServingService_StreamingReadFeatureValues_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_streaming_read_feature_values(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreOnlineServingServiceAsyncClient() + + # Initialize request argument(s) + feature_selector = aiplatform_v1beta1.FeatureSelector() + feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1beta1.StreamingReadFeatureValuesRequest( + entity_type="entity_type_value", + entity_ids=['entity_ids_value_1', 'entity_ids_value_2'], + feature_selector=feature_selector, + ) + + # Make the request + stream = await client.streaming_read_feature_values(request=request) + + # Handle the response + async for response in stream: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreOnlineServingService_StreamingReadFeatureValues_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_online_serving_service_streaming_read_feature_values_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_online_serving_service_streaming_read_feature_values_sync.py new file mode 100644 index 0000000000..1e434b1afc --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_online_serving_service_streaming_read_feature_values_sync.py @@ -0,0 +1,51 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for StreamingReadFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreOnlineServingService_StreamingReadFeatureValues_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_streaming_read_feature_values(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreOnlineServingServiceClient() + + # Initialize request argument(s) + feature_selector = aiplatform_v1beta1.FeatureSelector() + feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1beta1.StreamingReadFeatureValuesRequest( + entity_type="entity_type_value", + entity_ids=['entity_ids_value_1', 'entity_ids_value_2'], + feature_selector=feature_selector, + ) + + # Make the request + stream = client.streaming_read_feature_values(request=request) + + # Handle the response + for response in stream: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreOnlineServingService_StreamingReadFeatureValues_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_batch_create_features_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_batch_create_features_async.py new file mode 100644 index 0000000000..27a1bc6243 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_batch_create_features_async.py @@ -0,0 +1,55 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchCreateFeatures +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_BatchCreateFeatures_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_batch_create_features(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + requests = aiplatform_v1beta1.CreateFeatureRequest() + requests.parent = "parent_value" + requests.feature.value_type = "BYTES" + requests.feature_id = "feature_id_value" + + request = aiplatform_v1beta1.BatchCreateFeaturesRequest( + parent="parent_value", + requests=requests, + ) + + # Make the request + operation = client.batch_create_features(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_BatchCreateFeatures_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_batch_create_features_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_batch_create_features_sync.py new file mode 100644 index 0000000000..a6066d929f --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_batch_create_features_sync.py @@ -0,0 +1,55 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchCreateFeatures +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_BatchCreateFeatures_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_batch_create_features(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + requests = aiplatform_v1beta1.CreateFeatureRequest() + requests.parent = "parent_value" + requests.feature.value_type = "BYTES" + requests.feature_id = "feature_id_value" + + request = aiplatform_v1beta1.BatchCreateFeaturesRequest( + parent="parent_value", + requests=requests, + ) + + # Make the request + operation = client.batch_create_features(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_BatchCreateFeatures_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_batch_read_feature_values_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_batch_read_feature_values_async.py new file mode 100644 index 0000000000..7e4569fe25 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_batch_read_feature_values_async.py @@ -0,0 +1,62 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchReadFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_BatchReadFeatureValues_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_batch_read_feature_values(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + csv_read_instances = aiplatform_v1beta1.CsvSource() + csv_read_instances.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + + destination = aiplatform_v1beta1.FeatureValueDestination() + destination.bigquery_destination.output_uri = "output_uri_value" + + entity_type_specs = aiplatform_v1beta1.EntityTypeSpec() + entity_type_specs.entity_type_id = "entity_type_id_value" + entity_type_specs.feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1beta1.BatchReadFeatureValuesRequest( + csv_read_instances=csv_read_instances, + featurestore="featurestore_value", + destination=destination, + entity_type_specs=entity_type_specs, + ) + + # Make the request + operation = client.batch_read_feature_values(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_BatchReadFeatureValues_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_batch_read_feature_values_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_batch_read_feature_values_sync.py new file mode 100644 index 0000000000..47809efd99 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_batch_read_feature_values_sync.py @@ -0,0 +1,62 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchReadFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_BatchReadFeatureValues_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_batch_read_feature_values(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + csv_read_instances = aiplatform_v1beta1.CsvSource() + csv_read_instances.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + + destination = aiplatform_v1beta1.FeatureValueDestination() + destination.bigquery_destination.output_uri = "output_uri_value" + + entity_type_specs = aiplatform_v1beta1.EntityTypeSpec() + entity_type_specs.entity_type_id = "entity_type_id_value" + entity_type_specs.feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1beta1.BatchReadFeatureValuesRequest( + csv_read_instances=csv_read_instances, + featurestore="featurestore_value", + destination=destination, + entity_type_specs=entity_type_specs, + ) + + # Make the request + operation = client.batch_read_feature_values(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_BatchReadFeatureValues_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_create_entity_type_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_create_entity_type_async.py new file mode 100644 index 0000000000..b03e1032a4 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_create_entity_type_async.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateEntityType +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_CreateEntityType_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_entity_type(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateEntityTypeRequest( + parent="parent_value", + entity_type_id="entity_type_id_value", + ) + + # Make the request + operation = client.create_entity_type(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_CreateEntityType_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_create_entity_type_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_create_entity_type_sync.py new file mode 100644 index 0000000000..b22044fd75 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_create_entity_type_sync.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateEntityType +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_CreateEntityType_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_entity_type(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateEntityTypeRequest( + parent="parent_value", + entity_type_id="entity_type_id_value", + ) + + # Make the request + operation = client.create_entity_type(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_CreateEntityType_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_create_feature_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_create_feature_async.py new file mode 100644 index 0000000000..3551c949a0 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_create_feature_async.py @@ -0,0 +1,54 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateFeature +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_CreateFeature_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_feature(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + feature = aiplatform_v1beta1.Feature() + feature.value_type = "BYTES" + + request = aiplatform_v1beta1.CreateFeatureRequest( + parent="parent_value", + feature=feature, + feature_id="feature_id_value", + ) + + # Make the request + operation = client.create_feature(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_CreateFeature_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_create_feature_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_create_feature_sync.py new file mode 100644 index 0000000000..07018ad808 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_create_feature_sync.py @@ -0,0 +1,54 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateFeature +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_CreateFeature_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_feature(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + feature = aiplatform_v1beta1.Feature() + feature.value_type = "BYTES" + + request = aiplatform_v1beta1.CreateFeatureRequest( + parent="parent_value", + feature=feature, + feature_id="feature_id_value", + ) + + # Make the request + operation = client.create_feature(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_CreateFeature_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_create_featurestore_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_create_featurestore_async.py new file mode 100644 index 0000000000..8375d2d81d --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_create_featurestore_async.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateFeaturestore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_CreateFeaturestore_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_featurestore(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateFeaturestoreRequest( + parent="parent_value", + featurestore_id="featurestore_id_value", + ) + + # Make the request + operation = client.create_featurestore(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_CreateFeaturestore_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_create_featurestore_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_create_featurestore_sync.py new file mode 100644 index 0000000000..d41efa59c7 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_create_featurestore_sync.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateFeaturestore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_CreateFeaturestore_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_featurestore(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateFeaturestoreRequest( + parent="parent_value", + featurestore_id="featurestore_id_value", + ) + + # Make the request + operation = client.create_featurestore(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_CreateFeaturestore_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_delete_entity_type_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_delete_entity_type_async.py new file mode 100644 index 0000000000..a00c7f7c45 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_delete_entity_type_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteEntityType +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_DeleteEntityType_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_entity_type(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteEntityTypeRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_entity_type(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_DeleteEntityType_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_delete_entity_type_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_delete_entity_type_sync.py new file mode 100644 index 0000000000..13a25df43c --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_delete_entity_type_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteEntityType +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_DeleteEntityType_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_entity_type(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteEntityTypeRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_entity_type(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_DeleteEntityType_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_delete_feature_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_delete_feature_async.py new file mode 100644 index 0000000000..4a53587ece --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_delete_feature_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteFeature +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_DeleteFeature_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_feature(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteFeatureRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_feature(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_DeleteFeature_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_delete_feature_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_delete_feature_sync.py new file mode 100644 index 0000000000..f70e14360c --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_delete_feature_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteFeature +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_DeleteFeature_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_feature(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteFeatureRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_feature(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_DeleteFeature_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_delete_featurestore_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_delete_featurestore_async.py new file mode 100644 index 0000000000..bff7359bce --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_delete_featurestore_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteFeaturestore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_DeleteFeaturestore_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_featurestore(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteFeaturestoreRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_featurestore(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_DeleteFeaturestore_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_delete_featurestore_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_delete_featurestore_sync.py new file mode 100644 index 0000000000..a8a5ec56d1 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_delete_featurestore_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteFeaturestore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_DeleteFeaturestore_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_featurestore(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteFeaturestoreRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_featurestore(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_DeleteFeaturestore_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_export_feature_values_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_export_feature_values_async.py new file mode 100644 index 0000000000..3fb5566916 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_export_feature_values_async.py @@ -0,0 +1,57 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_ExportFeatureValues_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_export_feature_values(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + destination = aiplatform_v1beta1.FeatureValueDestination() + destination.bigquery_destination.output_uri = "output_uri_value" + + feature_selector = aiplatform_v1beta1.FeatureSelector() + feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1beta1.ExportFeatureValuesRequest( + entity_type="entity_type_value", + destination=destination, + feature_selector=feature_selector, + ) + + # Make the request + operation = client.export_feature_values(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_ExportFeatureValues_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_export_feature_values_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_export_feature_values_sync.py new file mode 100644 index 0000000000..0fed7b17e8 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_export_feature_values_sync.py @@ -0,0 +1,57 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_ExportFeatureValues_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_export_feature_values(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + destination = aiplatform_v1beta1.FeatureValueDestination() + destination.bigquery_destination.output_uri = "output_uri_value" + + feature_selector = aiplatform_v1beta1.FeatureSelector() + feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1beta1.ExportFeatureValuesRequest( + entity_type="entity_type_value", + destination=destination, + feature_selector=feature_selector, + ) + + # Make the request + operation = client.export_feature_values(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_ExportFeatureValues_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_get_entity_type_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_get_entity_type_async.py new file mode 100644 index 0000000000..319d5993c2 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_get_entity_type_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetEntityType +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_GetEntityType_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_entity_type(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetEntityTypeRequest( + name="name_value", + ) + + # Make the request + response = await client.get_entity_type(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_GetEntityType_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_get_entity_type_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_get_entity_type_sync.py new file mode 100644 index 0000000000..b9c22b201a --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_get_entity_type_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetEntityType +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_GetEntityType_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_entity_type(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetEntityTypeRequest( + name="name_value", + ) + + # Make the request + response = client.get_entity_type(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_GetEntityType_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_get_feature_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_get_feature_async.py new file mode 100644 index 0000000000..2fc8940f23 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_get_feature_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetFeature +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_GetFeature_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_feature(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetFeatureRequest( + name="name_value", + ) + + # Make the request + response = await client.get_feature(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_GetFeature_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_get_feature_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_get_feature_sync.py new file mode 100644 index 0000000000..e34fd9dca0 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_get_feature_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetFeature +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_GetFeature_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_feature(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetFeatureRequest( + name="name_value", + ) + + # Make the request + response = client.get_feature(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_GetFeature_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_get_featurestore_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_get_featurestore_async.py new file mode 100644 index 0000000000..b025ddb1b4 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_get_featurestore_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetFeaturestore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_GetFeaturestore_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_featurestore(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetFeaturestoreRequest( + name="name_value", + ) + + # Make the request + response = await client.get_featurestore(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_GetFeaturestore_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_get_featurestore_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_get_featurestore_sync.py new file mode 100644 index 0000000000..d445f4dee3 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_get_featurestore_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetFeaturestore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_GetFeaturestore_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_featurestore(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetFeaturestoreRequest( + name="name_value", + ) + + # Make the request + response = client.get_featurestore(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_GetFeaturestore_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_import_feature_values_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_import_feature_values_async.py new file mode 100644 index 0000000000..701f1b7fbb --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_import_feature_values_async.py @@ -0,0 +1,58 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ImportFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_ImportFeatureValues_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_import_feature_values(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + avro_source = aiplatform_v1beta1.AvroSource() + avro_source.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + + feature_specs = aiplatform_v1beta1.FeatureSpec() + feature_specs.id = "id_value" + + request = aiplatform_v1beta1.ImportFeatureValuesRequest( + avro_source=avro_source, + feature_time_field="feature_time_field_value", + entity_type="entity_type_value", + feature_specs=feature_specs, + ) + + # Make the request + operation = client.import_feature_values(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_ImportFeatureValues_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_import_feature_values_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_import_feature_values_sync.py new file mode 100644 index 0000000000..8db8247482 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_import_feature_values_sync.py @@ -0,0 +1,58 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ImportFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_ImportFeatureValues_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_import_feature_values(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + avro_source = aiplatform_v1beta1.AvroSource() + avro_source.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + + feature_specs = aiplatform_v1beta1.FeatureSpec() + feature_specs.id = "id_value" + + request = aiplatform_v1beta1.ImportFeatureValuesRequest( + avro_source=avro_source, + feature_time_field="feature_time_field_value", + entity_type="entity_type_value", + feature_specs=feature_specs, + ) + + # Make the request + operation = client.import_feature_values(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_ImportFeatureValues_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_list_entity_types_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_list_entity_types_async.py new file mode 100644 index 0000000000..4d487faaaf --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_list_entity_types_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListEntityTypes +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_ListEntityTypes_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_entity_types(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListEntityTypesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_entity_types(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_ListEntityTypes_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_list_entity_types_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_list_entity_types_sync.py new file mode 100644 index 0000000000..7cb144224d --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_list_entity_types_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListEntityTypes +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_ListEntityTypes_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_entity_types(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListEntityTypesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_entity_types(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_ListEntityTypes_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_list_features_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_list_features_async.py new file mode 100644 index 0000000000..0086aa091f --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_list_features_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListFeatures +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_ListFeatures_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_features(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListFeaturesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_features(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_ListFeatures_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_list_features_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_list_features_sync.py new file mode 100644 index 0000000000..c721a29bc4 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_list_features_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListFeatures +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_ListFeatures_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_features(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListFeaturesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_features(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_ListFeatures_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_list_featurestores_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_list_featurestores_async.py new file mode 100644 index 0000000000..020ec74245 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_list_featurestores_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListFeaturestores +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_ListFeaturestores_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_featurestores(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListFeaturestoresRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_featurestores(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_ListFeaturestores_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_list_featurestores_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_list_featurestores_sync.py new file mode 100644 index 0000000000..66088ea771 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_list_featurestores_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListFeaturestores +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_ListFeaturestores_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_featurestores(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListFeaturestoresRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_featurestores(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_ListFeaturestores_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_search_features_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_search_features_async.py new file mode 100644 index 0000000000..2f7bb2b229 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_search_features_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SearchFeatures +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_SearchFeatures_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_search_features(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.SearchFeaturesRequest( + location="location_value", + ) + + # Make the request + page_result = client.search_features(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_SearchFeatures_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_search_features_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_search_features_sync.py new file mode 100644 index 0000000000..654cbe4137 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_search_features_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SearchFeatures +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_SearchFeatures_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_search_features(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.SearchFeaturesRequest( + location="location_value", + ) + + # Make the request + page_result = client.search_features(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_SearchFeatures_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_update_entity_type_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_update_entity_type_async.py new file mode 100644 index 0000000000..c1a1297247 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_update_entity_type_async.py @@ -0,0 +1,44 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateEntityType +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_UpdateEntityType_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_update_entity_type(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateEntityTypeRequest( + ) + + # Make the request + response = await client.update_entity_type(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_UpdateEntityType_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_update_entity_type_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_update_entity_type_sync.py new file mode 100644 index 0000000000..612279a558 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_update_entity_type_sync.py @@ -0,0 +1,44 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateEntityType +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_UpdateEntityType_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_update_entity_type(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateEntityTypeRequest( + ) + + # Make the request + response = client.update_entity_type(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_UpdateEntityType_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_update_feature_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_update_feature_async.py new file mode 100644 index 0000000000..69dccf4786 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_update_feature_async.py @@ -0,0 +1,48 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateFeature +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_UpdateFeature_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_update_feature(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + feature = aiplatform_v1beta1.Feature() + feature.value_type = "BYTES" + + request = aiplatform_v1beta1.UpdateFeatureRequest( + feature=feature, + ) + + # Make the request + response = await client.update_feature(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_UpdateFeature_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_update_feature_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_update_feature_sync.py new file mode 100644 index 0000000000..171428cfaa --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_update_feature_sync.py @@ -0,0 +1,48 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateFeature +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_UpdateFeature_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_update_feature(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + feature = aiplatform_v1beta1.Feature() + feature.value_type = "BYTES" + + request = aiplatform_v1beta1.UpdateFeatureRequest( + feature=feature, + ) + + # Make the request + response = client.update_feature(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_UpdateFeature_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_update_featurestore_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_update_featurestore_async.py new file mode 100644 index 0000000000..4a8d2d238c --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_update_featurestore_async.py @@ -0,0 +1,48 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateFeaturestore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_UpdateFeaturestore_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_update_featurestore(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateFeaturestoreRequest( + ) + + # Make the request + operation = client.update_featurestore(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_UpdateFeaturestore_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_update_featurestore_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_update_featurestore_sync.py new file mode 100644 index 0000000000..e219f5751a --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_featurestore_service_update_featurestore_sync.py @@ -0,0 +1,48 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateFeaturestore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_UpdateFeaturestore_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_update_featurestore(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateFeaturestoreRequest( + ) + + # Make the request + operation = client.update_featurestore(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_FeaturestoreService_UpdateFeaturestore_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_create_index_endpoint_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_create_index_endpoint_async.py new file mode 100644 index 0000000000..7879d75029 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_create_index_endpoint_async.py @@ -0,0 +1,53 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateIndexEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_IndexEndpointService_CreateIndexEndpoint_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_index_endpoint(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + index_endpoint = aiplatform_v1beta1.IndexEndpoint() + index_endpoint.display_name = "display_name_value" + + request = aiplatform_v1beta1.CreateIndexEndpointRequest( + parent="parent_value", + index_endpoint=index_endpoint, + ) + + # Make the request + operation = client.create_index_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_IndexEndpointService_CreateIndexEndpoint_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_create_index_endpoint_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_create_index_endpoint_sync.py new file mode 100644 index 0000000000..da9b3c3f71 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_create_index_endpoint_sync.py @@ -0,0 +1,53 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateIndexEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_IndexEndpointService_CreateIndexEndpoint_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_index_endpoint(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceClient() + + # Initialize request argument(s) + index_endpoint = aiplatform_v1beta1.IndexEndpoint() + index_endpoint.display_name = "display_name_value" + + request = aiplatform_v1beta1.CreateIndexEndpointRequest( + parent="parent_value", + index_endpoint=index_endpoint, + ) + + # Make the request + operation = client.create_index_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_IndexEndpointService_CreateIndexEndpoint_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_delete_index_endpoint_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_delete_index_endpoint_async.py new file mode 100644 index 0000000000..f6d8715a74 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_delete_index_endpoint_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteIndexEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_IndexEndpointService_DeleteIndexEndpoint_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_index_endpoint(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteIndexEndpointRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_index_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_IndexEndpointService_DeleteIndexEndpoint_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_delete_index_endpoint_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_delete_index_endpoint_sync.py new file mode 100644 index 0000000000..af13bf8dea --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_delete_index_endpoint_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteIndexEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_IndexEndpointService_DeleteIndexEndpoint_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_index_endpoint(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteIndexEndpointRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_index_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_IndexEndpointService_DeleteIndexEndpoint_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_deploy_index_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_deploy_index_async.py new file mode 100644 index 0000000000..e4b2d1067b --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_deploy_index_async.py @@ -0,0 +1,54 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeployIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_IndexEndpointService_DeployIndex_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_deploy_index(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + deployed_index = aiplatform_v1beta1.DeployedIndex() + deployed_index.id = "id_value" + deployed_index.index = "index_value" + + request = aiplatform_v1beta1.DeployIndexRequest( + index_endpoint="index_endpoint_value", + deployed_index=deployed_index, + ) + + # Make the request + operation = client.deploy_index(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_IndexEndpointService_DeployIndex_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_deploy_index_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_deploy_index_sync.py new file mode 100644 index 0000000000..918e758546 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_deploy_index_sync.py @@ -0,0 +1,54 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeployIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_IndexEndpointService_DeployIndex_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_deploy_index(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceClient() + + # Initialize request argument(s) + deployed_index = aiplatform_v1beta1.DeployedIndex() + deployed_index.id = "id_value" + deployed_index.index = "index_value" + + request = aiplatform_v1beta1.DeployIndexRequest( + index_endpoint="index_endpoint_value", + deployed_index=deployed_index, + ) + + # Make the request + operation = client.deploy_index(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_IndexEndpointService_DeployIndex_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_get_index_endpoint_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_get_index_endpoint_async.py new file mode 100644 index 0000000000..626f412f3d --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_get_index_endpoint_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetIndexEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_IndexEndpointService_GetIndexEndpoint_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_index_endpoint(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetIndexEndpointRequest( + name="name_value", + ) + + # Make the request + response = await client.get_index_endpoint(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_IndexEndpointService_GetIndexEndpoint_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_get_index_endpoint_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_get_index_endpoint_sync.py new file mode 100644 index 0000000000..ac824a106b --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_get_index_endpoint_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetIndexEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_IndexEndpointService_GetIndexEndpoint_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_index_endpoint(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetIndexEndpointRequest( + name="name_value", + ) + + # Make the request + response = client.get_index_endpoint(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_IndexEndpointService_GetIndexEndpoint_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_list_index_endpoints_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_list_index_endpoints_async.py new file mode 100644 index 0000000000..05836f5a8d --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_list_index_endpoints_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListIndexEndpoints +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_IndexEndpointService_ListIndexEndpoints_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_index_endpoints(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListIndexEndpointsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_index_endpoints(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_IndexEndpointService_ListIndexEndpoints_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_list_index_endpoints_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_list_index_endpoints_sync.py new file mode 100644 index 0000000000..8f4784b0d4 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_list_index_endpoints_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListIndexEndpoints +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_IndexEndpointService_ListIndexEndpoints_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_index_endpoints(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListIndexEndpointsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_index_endpoints(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_IndexEndpointService_ListIndexEndpoints_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_mutate_deployed_index_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_mutate_deployed_index_async.py new file mode 100644 index 0000000000..a7d431f9e8 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_mutate_deployed_index_async.py @@ -0,0 +1,54 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for MutateDeployedIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_IndexEndpointService_MutateDeployedIndex_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_mutate_deployed_index(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + deployed_index = aiplatform_v1beta1.DeployedIndex() + deployed_index.id = "id_value" + deployed_index.index = "index_value" + + request = aiplatform_v1beta1.MutateDeployedIndexRequest( + index_endpoint="index_endpoint_value", + deployed_index=deployed_index, + ) + + # Make the request + operation = client.mutate_deployed_index(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_IndexEndpointService_MutateDeployedIndex_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_mutate_deployed_index_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_mutate_deployed_index_sync.py new file mode 100644 index 0000000000..e6009bae68 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_mutate_deployed_index_sync.py @@ -0,0 +1,54 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for MutateDeployedIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_IndexEndpointService_MutateDeployedIndex_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_mutate_deployed_index(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceClient() + + # Initialize request argument(s) + deployed_index = aiplatform_v1beta1.DeployedIndex() + deployed_index.id = "id_value" + deployed_index.index = "index_value" + + request = aiplatform_v1beta1.MutateDeployedIndexRequest( + index_endpoint="index_endpoint_value", + deployed_index=deployed_index, + ) + + # Make the request + operation = client.mutate_deployed_index(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_IndexEndpointService_MutateDeployedIndex_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_undeploy_index_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_undeploy_index_async.py new file mode 100644 index 0000000000..65a5a90845 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_undeploy_index_async.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UndeployIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_IndexEndpointService_UndeployIndex_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_undeploy_index(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UndeployIndexRequest( + index_endpoint="index_endpoint_value", + deployed_index_id="deployed_index_id_value", + ) + + # Make the request + operation = client.undeploy_index(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_IndexEndpointService_UndeployIndex_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_undeploy_index_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_undeploy_index_sync.py new file mode 100644 index 0000000000..028654de1a --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_undeploy_index_sync.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UndeployIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_IndexEndpointService_UndeployIndex_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_undeploy_index(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UndeployIndexRequest( + index_endpoint="index_endpoint_value", + deployed_index_id="deployed_index_id_value", + ) + + # Make the request + operation = client.undeploy_index(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_IndexEndpointService_UndeployIndex_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_update_index_endpoint_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_update_index_endpoint_async.py new file mode 100644 index 0000000000..8836d2c41b --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_update_index_endpoint_async.py @@ -0,0 +1,48 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateIndexEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_IndexEndpointService_UpdateIndexEndpoint_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_update_index_endpoint(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + index_endpoint = aiplatform_v1beta1.IndexEndpoint() + index_endpoint.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateIndexEndpointRequest( + index_endpoint=index_endpoint, + ) + + # Make the request + response = await client.update_index_endpoint(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_IndexEndpointService_UpdateIndexEndpoint_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_update_index_endpoint_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_update_index_endpoint_sync.py new file mode 100644 index 0000000000..f019321a1c --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_endpoint_service_update_index_endpoint_sync.py @@ -0,0 +1,48 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateIndexEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_IndexEndpointService_UpdateIndexEndpoint_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_update_index_endpoint(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceClient() + + # Initialize request argument(s) + index_endpoint = aiplatform_v1beta1.IndexEndpoint() + index_endpoint.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateIndexEndpointRequest( + index_endpoint=index_endpoint, + ) + + # Make the request + response = client.update_index_endpoint(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_IndexEndpointService_UpdateIndexEndpoint_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_service_create_index_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_service_create_index_async.py new file mode 100644 index 0000000000..e83453a6dd --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_service_create_index_async.py @@ -0,0 +1,53 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_IndexService_CreateIndex_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_index(): + # Create a client + client = aiplatform_v1beta1.IndexServiceAsyncClient() + + # Initialize request argument(s) + index = aiplatform_v1beta1.Index() + index.display_name = "display_name_value" + + request = aiplatform_v1beta1.CreateIndexRequest( + parent="parent_value", + index=index, + ) + + # Make the request + operation = client.create_index(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_IndexService_CreateIndex_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_service_create_index_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_service_create_index_sync.py new file mode 100644 index 0000000000..f926793a50 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_service_create_index_sync.py @@ -0,0 +1,53 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_IndexService_CreateIndex_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_index(): + # Create a client + client = aiplatform_v1beta1.IndexServiceClient() + + # Initialize request argument(s) + index = aiplatform_v1beta1.Index() + index.display_name = "display_name_value" + + request = aiplatform_v1beta1.CreateIndexRequest( + parent="parent_value", + index=index, + ) + + # Make the request + operation = client.create_index(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_IndexService_CreateIndex_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_service_delete_index_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_service_delete_index_async.py new file mode 100644 index 0000000000..639eb277aa --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_service_delete_index_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_IndexService_DeleteIndex_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_index(): + # Create a client + client = aiplatform_v1beta1.IndexServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteIndexRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_index(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_IndexService_DeleteIndex_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_service_delete_index_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_service_delete_index_sync.py new file mode 100644 index 0000000000..b93c644d66 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_service_delete_index_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_IndexService_DeleteIndex_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_index(): + # Create a client + client = aiplatform_v1beta1.IndexServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteIndexRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_index(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_IndexService_DeleteIndex_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_service_get_index_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_service_get_index_async.py new file mode 100644 index 0000000000..22c6536b7d --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_service_get_index_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_IndexService_GetIndex_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_index(): + # Create a client + client = aiplatform_v1beta1.IndexServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetIndexRequest( + name="name_value", + ) + + # Make the request + response = await client.get_index(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_IndexService_GetIndex_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_service_get_index_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_service_get_index_sync.py new file mode 100644 index 0000000000..dbc394267c --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_service_get_index_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_IndexService_GetIndex_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_index(): + # Create a client + client = aiplatform_v1beta1.IndexServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetIndexRequest( + name="name_value", + ) + + # Make the request + response = client.get_index(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_IndexService_GetIndex_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_service_list_indexes_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_service_list_indexes_async.py new file mode 100644 index 0000000000..e7fa031e5f --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_service_list_indexes_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListIndexes +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_IndexService_ListIndexes_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_indexes(): + # Create a client + client = aiplatform_v1beta1.IndexServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListIndexesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_indexes(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_IndexService_ListIndexes_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_service_list_indexes_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_service_list_indexes_sync.py new file mode 100644 index 0000000000..496c01157b --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_service_list_indexes_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListIndexes +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_IndexService_ListIndexes_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_indexes(): + # Create a client + client = aiplatform_v1beta1.IndexServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListIndexesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_indexes(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_IndexService_ListIndexes_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_service_update_index_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_service_update_index_async.py new file mode 100644 index 0000000000..5cbec63edf --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_service_update_index_async.py @@ -0,0 +1,52 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_IndexService_UpdateIndex_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_update_index(): + # Create a client + client = aiplatform_v1beta1.IndexServiceAsyncClient() + + # Initialize request argument(s) + index = aiplatform_v1beta1.Index() + index.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateIndexRequest( + index=index, + ) + + # Make the request + operation = client.update_index(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_IndexService_UpdateIndex_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_service_update_index_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_service_update_index_sync.py new file mode 100644 index 0000000000..49b25c19c8 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_index_service_update_index_sync.py @@ -0,0 +1,52 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_IndexService_UpdateIndex_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_update_index(): + # Create a client + client = aiplatform_v1beta1.IndexServiceClient() + + # Initialize request argument(s) + index = aiplatform_v1beta1.Index() + index.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateIndexRequest( + index=index, + ) + + # Make the request + operation = client.update_index(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_IndexService_UpdateIndex_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_cancel_batch_prediction_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_cancel_batch_prediction_job_async.py new file mode 100644 index 0000000000..88c1a65a09 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_cancel_batch_prediction_job_async.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelBatchPredictionJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_CancelBatchPredictionJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_cancel_batch_prediction_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CancelBatchPredictionJobRequest( + name="name_value", + ) + + # Make the request + await client.cancel_batch_prediction_job(request=request) + + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_CancelBatchPredictionJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_cancel_batch_prediction_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_cancel_batch_prediction_job_sync.py new file mode 100644 index 0000000000..a80c7d6b1c --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_cancel_batch_prediction_job_sync.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelBatchPredictionJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_CancelBatchPredictionJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_cancel_batch_prediction_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CancelBatchPredictionJobRequest( + name="name_value", + ) + + # Make the request + client.cancel_batch_prediction_job(request=request) + + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_CancelBatchPredictionJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_cancel_custom_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_cancel_custom_job_async.py new file mode 100644 index 0000000000..fe455645db --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_cancel_custom_job_async.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelCustomJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_CancelCustomJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_cancel_custom_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CancelCustomJobRequest( + name="name_value", + ) + + # Make the request + await client.cancel_custom_job(request=request) + + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_CancelCustomJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_cancel_custom_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_cancel_custom_job_sync.py new file mode 100644 index 0000000000..00d98b0459 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_cancel_custom_job_sync.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelCustomJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_CancelCustomJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_cancel_custom_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CancelCustomJobRequest( + name="name_value", + ) + + # Make the request + client.cancel_custom_job(request=request) + + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_CancelCustomJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_cancel_data_labeling_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_cancel_data_labeling_job_async.py new file mode 100644 index 0000000000..811aa785da --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_cancel_data_labeling_job_async.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelDataLabelingJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_CancelDataLabelingJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_cancel_data_labeling_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CancelDataLabelingJobRequest( + name="name_value", + ) + + # Make the request + await client.cancel_data_labeling_job(request=request) + + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_CancelDataLabelingJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_cancel_data_labeling_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_cancel_data_labeling_job_sync.py new file mode 100644 index 0000000000..0fb43a243c --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_cancel_data_labeling_job_sync.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelDataLabelingJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_CancelDataLabelingJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_cancel_data_labeling_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CancelDataLabelingJobRequest( + name="name_value", + ) + + # Make the request + client.cancel_data_labeling_job(request=request) + + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_CancelDataLabelingJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_cancel_hyperparameter_tuning_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_cancel_hyperparameter_tuning_job_async.py new file mode 100644 index 0000000000..ec4dba8581 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_cancel_hyperparameter_tuning_job_async.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelHyperparameterTuningJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_CancelHyperparameterTuningJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_cancel_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CancelHyperparameterTuningJobRequest( + name="name_value", + ) + + # Make the request + await client.cancel_hyperparameter_tuning_job(request=request) + + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_CancelHyperparameterTuningJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_cancel_hyperparameter_tuning_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_cancel_hyperparameter_tuning_job_sync.py new file mode 100644 index 0000000000..6513407b1e --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_cancel_hyperparameter_tuning_job_sync.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelHyperparameterTuningJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_CancelHyperparameterTuningJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_cancel_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CancelHyperparameterTuningJobRequest( + name="name_value", + ) + + # Make the request + client.cancel_hyperparameter_tuning_job(request=request) + + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_CancelHyperparameterTuningJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_create_batch_prediction_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_create_batch_prediction_job_async.py new file mode 100644 index 0000000000..56d6151eed --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_create_batch_prediction_job_async.py @@ -0,0 +1,53 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateBatchPredictionJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_CreateBatchPredictionJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_batch_prediction_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + batch_prediction_job = aiplatform_v1beta1.BatchPredictionJob() + batch_prediction_job.display_name = "display_name_value" + batch_prediction_job.input_config.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + batch_prediction_job.input_config.instances_format = "instances_format_value" + batch_prediction_job.output_config.gcs_destination.output_uri_prefix = "output_uri_prefix_value" + batch_prediction_job.output_config.predictions_format = "predictions_format_value" + + request = aiplatform_v1beta1.CreateBatchPredictionJobRequest( + parent="parent_value", + batch_prediction_job=batch_prediction_job, + ) + + # Make the request + response = await client.create_batch_prediction_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_CreateBatchPredictionJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_create_batch_prediction_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_create_batch_prediction_job_sync.py new file mode 100644 index 0000000000..5e131a03e8 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_create_batch_prediction_job_sync.py @@ -0,0 +1,53 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateBatchPredictionJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_CreateBatchPredictionJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_batch_prediction_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + batch_prediction_job = aiplatform_v1beta1.BatchPredictionJob() + batch_prediction_job.display_name = "display_name_value" + batch_prediction_job.input_config.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + batch_prediction_job.input_config.instances_format = "instances_format_value" + batch_prediction_job.output_config.gcs_destination.output_uri_prefix = "output_uri_prefix_value" + batch_prediction_job.output_config.predictions_format = "predictions_format_value" + + request = aiplatform_v1beta1.CreateBatchPredictionJobRequest( + parent="parent_value", + batch_prediction_job=batch_prediction_job, + ) + + # Make the request + response = client.create_batch_prediction_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_CreateBatchPredictionJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_create_custom_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_create_custom_job_async.py new file mode 100644 index 0000000000..f96886e80a --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_create_custom_job_async.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateCustomJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_CreateCustomJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_custom_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + custom_job = aiplatform_v1beta1.CustomJob() + custom_job.display_name = "display_name_value" + custom_job.job_spec.worker_pool_specs.container_spec.image_uri = "image_uri_value" + + request = aiplatform_v1beta1.CreateCustomJobRequest( + parent="parent_value", + custom_job=custom_job, + ) + + # Make the request + response = await client.create_custom_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_CreateCustomJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_create_custom_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_create_custom_job_sync.py new file mode 100644 index 0000000000..69f2fee8fd --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_create_custom_job_sync.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateCustomJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_CreateCustomJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_custom_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + custom_job = aiplatform_v1beta1.CustomJob() + custom_job.display_name = "display_name_value" + custom_job.job_spec.worker_pool_specs.container_spec.image_uri = "image_uri_value" + + request = aiplatform_v1beta1.CreateCustomJobRequest( + parent="parent_value", + custom_job=custom_job, + ) + + # Make the request + response = client.create_custom_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_CreateCustomJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_create_data_labeling_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_create_data_labeling_job_async.py new file mode 100644 index 0000000000..e2da99e739 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_create_data_labeling_job_async.py @@ -0,0 +1,54 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateDataLabelingJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_CreateDataLabelingJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_data_labeling_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + data_labeling_job = aiplatform_v1beta1.DataLabelingJob() + data_labeling_job.display_name = "display_name_value" + data_labeling_job.datasets = ['datasets_value_1', 'datasets_value_2'] + data_labeling_job.labeler_count = 1375 + data_labeling_job.instruction_uri = "instruction_uri_value" + data_labeling_job.inputs_schema_uri = "inputs_schema_uri_value" + data_labeling_job.inputs.null_value = "NULL_VALUE" + + request = aiplatform_v1beta1.CreateDataLabelingJobRequest( + parent="parent_value", + data_labeling_job=data_labeling_job, + ) + + # Make the request + response = await client.create_data_labeling_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_CreateDataLabelingJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_create_data_labeling_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_create_data_labeling_job_sync.py new file mode 100644 index 0000000000..c09042dd79 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_create_data_labeling_job_sync.py @@ -0,0 +1,54 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateDataLabelingJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_CreateDataLabelingJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_data_labeling_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + data_labeling_job = aiplatform_v1beta1.DataLabelingJob() + data_labeling_job.display_name = "display_name_value" + data_labeling_job.datasets = ['datasets_value_1', 'datasets_value_2'] + data_labeling_job.labeler_count = 1375 + data_labeling_job.instruction_uri = "instruction_uri_value" + data_labeling_job.inputs_schema_uri = "inputs_schema_uri_value" + data_labeling_job.inputs.null_value = "NULL_VALUE" + + request = aiplatform_v1beta1.CreateDataLabelingJobRequest( + parent="parent_value", + data_labeling_job=data_labeling_job, + ) + + # Make the request + response = client.create_data_labeling_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_CreateDataLabelingJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_create_hyperparameter_tuning_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_create_hyperparameter_tuning_job_async.py new file mode 100644 index 0000000000..9425ee2de4 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_create_hyperparameter_tuning_job_async.py @@ -0,0 +1,57 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateHyperparameterTuningJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_CreateHyperparameterTuningJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + hyperparameter_tuning_job = aiplatform_v1beta1.HyperparameterTuningJob() + hyperparameter_tuning_job.display_name = "display_name_value" + hyperparameter_tuning_job.study_spec.metrics.metric_id = "metric_id_value" + hyperparameter_tuning_job.study_spec.metrics.goal = "MINIMIZE" + hyperparameter_tuning_job.study_spec.parameters.double_value_spec.min_value = 0.96 + hyperparameter_tuning_job.study_spec.parameters.double_value_spec.max_value = 0.962 + hyperparameter_tuning_job.study_spec.parameters.parameter_id = "parameter_id_value" + hyperparameter_tuning_job.max_trial_count = 1609 + hyperparameter_tuning_job.parallel_trial_count = 2128 + hyperparameter_tuning_job.trial_job_spec.worker_pool_specs.container_spec.image_uri = "image_uri_value" + + request = aiplatform_v1beta1.CreateHyperparameterTuningJobRequest( + parent="parent_value", + hyperparameter_tuning_job=hyperparameter_tuning_job, + ) + + # Make the request + response = await client.create_hyperparameter_tuning_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_CreateHyperparameterTuningJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_create_hyperparameter_tuning_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_create_hyperparameter_tuning_job_sync.py new file mode 100644 index 0000000000..c5f3794604 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_create_hyperparameter_tuning_job_sync.py @@ -0,0 +1,57 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateHyperparameterTuningJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_CreateHyperparameterTuningJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + hyperparameter_tuning_job = aiplatform_v1beta1.HyperparameterTuningJob() + hyperparameter_tuning_job.display_name = "display_name_value" + hyperparameter_tuning_job.study_spec.metrics.metric_id = "metric_id_value" + hyperparameter_tuning_job.study_spec.metrics.goal = "MINIMIZE" + hyperparameter_tuning_job.study_spec.parameters.double_value_spec.min_value = 0.96 + hyperparameter_tuning_job.study_spec.parameters.double_value_spec.max_value = 0.962 + hyperparameter_tuning_job.study_spec.parameters.parameter_id = "parameter_id_value" + hyperparameter_tuning_job.max_trial_count = 1609 + hyperparameter_tuning_job.parallel_trial_count = 2128 + hyperparameter_tuning_job.trial_job_spec.worker_pool_specs.container_spec.image_uri = "image_uri_value" + + request = aiplatform_v1beta1.CreateHyperparameterTuningJobRequest( + parent="parent_value", + hyperparameter_tuning_job=hyperparameter_tuning_job, + ) + + # Make the request + response = client.create_hyperparameter_tuning_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_CreateHyperparameterTuningJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_create_model_deployment_monitoring_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_create_model_deployment_monitoring_job_async.py new file mode 100644 index 0000000000..b32cda7730 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_create_model_deployment_monitoring_job_async.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_CreateModelDeploymentMonitoringJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + model_deployment_monitoring_job = aiplatform_v1beta1.ModelDeploymentMonitoringJob() + model_deployment_monitoring_job.display_name = "display_name_value" + model_deployment_monitoring_job.endpoint = "endpoint_value" + + request = aiplatform_v1beta1.CreateModelDeploymentMonitoringJobRequest( + parent="parent_value", + model_deployment_monitoring_job=model_deployment_monitoring_job, + ) + + # Make the request + response = await client.create_model_deployment_monitoring_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_CreateModelDeploymentMonitoringJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_create_model_deployment_monitoring_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_create_model_deployment_monitoring_job_sync.py new file mode 100644 index 0000000000..2989d2b893 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_create_model_deployment_monitoring_job_sync.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_CreateModelDeploymentMonitoringJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + model_deployment_monitoring_job = aiplatform_v1beta1.ModelDeploymentMonitoringJob() + model_deployment_monitoring_job.display_name = "display_name_value" + model_deployment_monitoring_job.endpoint = "endpoint_value" + + request = aiplatform_v1beta1.CreateModelDeploymentMonitoringJobRequest( + parent="parent_value", + model_deployment_monitoring_job=model_deployment_monitoring_job, + ) + + # Make the request + response = client.create_model_deployment_monitoring_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_CreateModelDeploymentMonitoringJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_delete_batch_prediction_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_delete_batch_prediction_job_async.py new file mode 100644 index 0000000000..ee33e7c117 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_delete_batch_prediction_job_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteBatchPredictionJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_DeleteBatchPredictionJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_batch_prediction_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteBatchPredictionJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_batch_prediction_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_DeleteBatchPredictionJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_delete_batch_prediction_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_delete_batch_prediction_job_sync.py new file mode 100644 index 0000000000..889ba74224 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_delete_batch_prediction_job_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteBatchPredictionJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_DeleteBatchPredictionJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_batch_prediction_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteBatchPredictionJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_batch_prediction_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_DeleteBatchPredictionJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_delete_custom_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_delete_custom_job_async.py new file mode 100644 index 0000000000..c423d213a0 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_delete_custom_job_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteCustomJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_DeleteCustomJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_custom_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteCustomJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_custom_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_DeleteCustomJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_delete_custom_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_delete_custom_job_sync.py new file mode 100644 index 0000000000..49ccd3a3ac --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_delete_custom_job_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteCustomJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_DeleteCustomJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_custom_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteCustomJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_custom_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_DeleteCustomJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_delete_data_labeling_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_delete_data_labeling_job_async.py new file mode 100644 index 0000000000..a1a46199e7 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_delete_data_labeling_job_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteDataLabelingJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_DeleteDataLabelingJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_data_labeling_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteDataLabelingJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_data_labeling_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_DeleteDataLabelingJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_delete_data_labeling_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_delete_data_labeling_job_sync.py new file mode 100644 index 0000000000..deae42b8a7 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_delete_data_labeling_job_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteDataLabelingJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_DeleteDataLabelingJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_data_labeling_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteDataLabelingJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_data_labeling_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_DeleteDataLabelingJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_delete_hyperparameter_tuning_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_delete_hyperparameter_tuning_job_async.py new file mode 100644 index 0000000000..f9be687ef7 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_delete_hyperparameter_tuning_job_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteHyperparameterTuningJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_DeleteHyperparameterTuningJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteHyperparameterTuningJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_hyperparameter_tuning_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_DeleteHyperparameterTuningJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_delete_hyperparameter_tuning_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_delete_hyperparameter_tuning_job_sync.py new file mode 100644 index 0000000000..65ae82fdfc --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_delete_hyperparameter_tuning_job_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteHyperparameterTuningJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_DeleteHyperparameterTuningJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteHyperparameterTuningJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_hyperparameter_tuning_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_DeleteHyperparameterTuningJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_delete_model_deployment_monitoring_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_delete_model_deployment_monitoring_job_async.py new file mode 100644 index 0000000000..7ec9cba1e5 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_delete_model_deployment_monitoring_job_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_DeleteModelDeploymentMonitoringJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_model_deployment_monitoring_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_DeleteModelDeploymentMonitoringJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_delete_model_deployment_monitoring_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_delete_model_deployment_monitoring_job_sync.py new file mode 100644 index 0000000000..954715a8a6 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_delete_model_deployment_monitoring_job_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_DeleteModelDeploymentMonitoringJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_model_deployment_monitoring_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_DeleteModelDeploymentMonitoringJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_get_batch_prediction_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_get_batch_prediction_job_async.py new file mode 100644 index 0000000000..54e9236368 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_get_batch_prediction_job_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetBatchPredictionJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_GetBatchPredictionJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_batch_prediction_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetBatchPredictionJobRequest( + name="name_value", + ) + + # Make the request + response = await client.get_batch_prediction_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_GetBatchPredictionJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_get_batch_prediction_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_get_batch_prediction_job_sync.py new file mode 100644 index 0000000000..636accd7f6 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_get_batch_prediction_job_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetBatchPredictionJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_GetBatchPredictionJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_batch_prediction_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetBatchPredictionJobRequest( + name="name_value", + ) + + # Make the request + response = client.get_batch_prediction_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_GetBatchPredictionJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_get_custom_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_get_custom_job_async.py new file mode 100644 index 0000000000..4c2733a99e --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_get_custom_job_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetCustomJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_GetCustomJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_custom_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetCustomJobRequest( + name="name_value", + ) + + # Make the request + response = await client.get_custom_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_GetCustomJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_get_custom_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_get_custom_job_sync.py new file mode 100644 index 0000000000..debf01cbd8 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_get_custom_job_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetCustomJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_GetCustomJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_custom_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetCustomJobRequest( + name="name_value", + ) + + # Make the request + response = client.get_custom_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_GetCustomJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_get_data_labeling_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_get_data_labeling_job_async.py new file mode 100644 index 0000000000..276eab20d4 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_get_data_labeling_job_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetDataLabelingJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_GetDataLabelingJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_data_labeling_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetDataLabelingJobRequest( + name="name_value", + ) + + # Make the request + response = await client.get_data_labeling_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_GetDataLabelingJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_get_data_labeling_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_get_data_labeling_job_sync.py new file mode 100644 index 0000000000..a81359e925 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_get_data_labeling_job_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetDataLabelingJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_GetDataLabelingJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_data_labeling_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetDataLabelingJobRequest( + name="name_value", + ) + + # Make the request + response = client.get_data_labeling_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_GetDataLabelingJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_get_hyperparameter_tuning_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_get_hyperparameter_tuning_job_async.py new file mode 100644 index 0000000000..3e77372039 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_get_hyperparameter_tuning_job_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetHyperparameterTuningJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_GetHyperparameterTuningJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetHyperparameterTuningJobRequest( + name="name_value", + ) + + # Make the request + response = await client.get_hyperparameter_tuning_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_GetHyperparameterTuningJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_get_hyperparameter_tuning_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_get_hyperparameter_tuning_job_sync.py new file mode 100644 index 0000000000..a8c5ff55ad --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_get_hyperparameter_tuning_job_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetHyperparameterTuningJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_GetHyperparameterTuningJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetHyperparameterTuningJobRequest( + name="name_value", + ) + + # Make the request + response = client.get_hyperparameter_tuning_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_GetHyperparameterTuningJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_get_model_deployment_monitoring_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_get_model_deployment_monitoring_job_async.py new file mode 100644 index 0000000000..a7b8d6b9fd --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_get_model_deployment_monitoring_job_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_GetModelDeploymentMonitoringJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + response = await client.get_model_deployment_monitoring_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_GetModelDeploymentMonitoringJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_get_model_deployment_monitoring_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_get_model_deployment_monitoring_job_sync.py new file mode 100644 index 0000000000..8e7f5451b6 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_get_model_deployment_monitoring_job_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_GetModelDeploymentMonitoringJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + response = client.get_model_deployment_monitoring_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_GetModelDeploymentMonitoringJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_list_batch_prediction_jobs_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_list_batch_prediction_jobs_async.py new file mode 100644 index 0000000000..7e915444d1 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_list_batch_prediction_jobs_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListBatchPredictionJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_ListBatchPredictionJobs_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_batch_prediction_jobs(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListBatchPredictionJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_batch_prediction_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_ListBatchPredictionJobs_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_list_batch_prediction_jobs_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_list_batch_prediction_jobs_sync.py new file mode 100644 index 0000000000..33b7c9b80b --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_list_batch_prediction_jobs_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListBatchPredictionJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_ListBatchPredictionJobs_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_batch_prediction_jobs(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListBatchPredictionJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_batch_prediction_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_ListBatchPredictionJobs_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_list_custom_jobs_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_list_custom_jobs_async.py new file mode 100644 index 0000000000..8066776bac --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_list_custom_jobs_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListCustomJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_ListCustomJobs_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_custom_jobs(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListCustomJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_custom_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_ListCustomJobs_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_list_custom_jobs_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_list_custom_jobs_sync.py new file mode 100644 index 0000000000..26b81653e7 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_list_custom_jobs_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListCustomJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_ListCustomJobs_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_custom_jobs(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListCustomJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_custom_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_ListCustomJobs_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_list_data_labeling_jobs_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_list_data_labeling_jobs_async.py new file mode 100644 index 0000000000..32cad8d354 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_list_data_labeling_jobs_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDataLabelingJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_ListDataLabelingJobs_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_data_labeling_jobs(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListDataLabelingJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_data_labeling_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_ListDataLabelingJobs_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_list_data_labeling_jobs_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_list_data_labeling_jobs_sync.py new file mode 100644 index 0000000000..d50459bc24 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_list_data_labeling_jobs_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDataLabelingJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_ListDataLabelingJobs_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_data_labeling_jobs(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListDataLabelingJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_data_labeling_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_ListDataLabelingJobs_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_list_hyperparameter_tuning_jobs_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_list_hyperparameter_tuning_jobs_async.py new file mode 100644 index 0000000000..bbee13435b --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_list_hyperparameter_tuning_jobs_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListHyperparameterTuningJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_ListHyperparameterTuningJobs_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_hyperparameter_tuning_jobs(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListHyperparameterTuningJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_hyperparameter_tuning_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_ListHyperparameterTuningJobs_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_list_hyperparameter_tuning_jobs_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_list_hyperparameter_tuning_jobs_sync.py new file mode 100644 index 0000000000..bfe8aa8624 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_list_hyperparameter_tuning_jobs_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListHyperparameterTuningJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_ListHyperparameterTuningJobs_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_hyperparameter_tuning_jobs(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListHyperparameterTuningJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_hyperparameter_tuning_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_ListHyperparameterTuningJobs_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_list_model_deployment_monitoring_jobs_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_list_model_deployment_monitoring_jobs_async.py new file mode 100644 index 0000000000..b063ed071c --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_list_model_deployment_monitoring_jobs_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListModelDeploymentMonitoringJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_ListModelDeploymentMonitoringJobs_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_model_deployment_monitoring_jobs(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListModelDeploymentMonitoringJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_model_deployment_monitoring_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_ListModelDeploymentMonitoringJobs_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_list_model_deployment_monitoring_jobs_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_list_model_deployment_monitoring_jobs_sync.py new file mode 100644 index 0000000000..9533d98066 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_list_model_deployment_monitoring_jobs_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListModelDeploymentMonitoringJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_ListModelDeploymentMonitoringJobs_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_model_deployment_monitoring_jobs(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListModelDeploymentMonitoringJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_model_deployment_monitoring_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_ListModelDeploymentMonitoringJobs_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_pause_model_deployment_monitoring_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_pause_model_deployment_monitoring_job_async.py new file mode 100644 index 0000000000..200e177350 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_pause_model_deployment_monitoring_job_async.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PauseModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_PauseModelDeploymentMonitoringJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_pause_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.PauseModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + await client.pause_model_deployment_monitoring_job(request=request) + + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_PauseModelDeploymentMonitoringJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_pause_model_deployment_monitoring_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_pause_model_deployment_monitoring_job_sync.py new file mode 100644 index 0000000000..d73462b5df --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_pause_model_deployment_monitoring_job_sync.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PauseModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_PauseModelDeploymentMonitoringJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_pause_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.PauseModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + client.pause_model_deployment_monitoring_job(request=request) + + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_PauseModelDeploymentMonitoringJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_resume_model_deployment_monitoring_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_resume_model_deployment_monitoring_job_async.py new file mode 100644 index 0000000000..e88878037c --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_resume_model_deployment_monitoring_job_async.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ResumeModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_ResumeModelDeploymentMonitoringJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_resume_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ResumeModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + await client.resume_model_deployment_monitoring_job(request=request) + + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_ResumeModelDeploymentMonitoringJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_resume_model_deployment_monitoring_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_resume_model_deployment_monitoring_job_sync.py new file mode 100644 index 0000000000..7061d47a9f --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_resume_model_deployment_monitoring_job_sync.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ResumeModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_ResumeModelDeploymentMonitoringJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_resume_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ResumeModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + client.resume_model_deployment_monitoring_job(request=request) + + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_ResumeModelDeploymentMonitoringJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_search_model_deployment_monitoring_stats_anomalies_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_search_model_deployment_monitoring_stats_anomalies_async.py new file mode 100644 index 0000000000..4d80cd94b7 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_search_model_deployment_monitoring_stats_anomalies_async.py @@ -0,0 +1,47 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SearchModelDeploymentMonitoringStatsAnomalies +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_SearchModelDeploymentMonitoringStatsAnomalies_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_search_model_deployment_monitoring_stats_anomalies(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.SearchModelDeploymentMonitoringStatsAnomaliesRequest( + model_deployment_monitoring_job="model_deployment_monitoring_job_value", + deployed_model_id="deployed_model_id_value", + ) + + # Make the request + page_result = client.search_model_deployment_monitoring_stats_anomalies(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_SearchModelDeploymentMonitoringStatsAnomalies_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_search_model_deployment_monitoring_stats_anomalies_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_search_model_deployment_monitoring_stats_anomalies_sync.py new file mode 100644 index 0000000000..cf7d678475 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_search_model_deployment_monitoring_stats_anomalies_sync.py @@ -0,0 +1,47 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SearchModelDeploymentMonitoringStatsAnomalies +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_SearchModelDeploymentMonitoringStatsAnomalies_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_search_model_deployment_monitoring_stats_anomalies(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.SearchModelDeploymentMonitoringStatsAnomaliesRequest( + model_deployment_monitoring_job="model_deployment_monitoring_job_value", + deployed_model_id="deployed_model_id_value", + ) + + # Make the request + page_result = client.search_model_deployment_monitoring_stats_anomalies(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_SearchModelDeploymentMonitoringStatsAnomalies_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_update_model_deployment_monitoring_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_update_model_deployment_monitoring_job_async.py new file mode 100644 index 0000000000..d5b40ae443 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_update_model_deployment_monitoring_job_async.py @@ -0,0 +1,53 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_UpdateModelDeploymentMonitoringJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_update_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + model_deployment_monitoring_job = aiplatform_v1beta1.ModelDeploymentMonitoringJob() + model_deployment_monitoring_job.display_name = "display_name_value" + model_deployment_monitoring_job.endpoint = "endpoint_value" + + request = aiplatform_v1beta1.UpdateModelDeploymentMonitoringJobRequest( + model_deployment_monitoring_job=model_deployment_monitoring_job, + ) + + # Make the request + operation = client.update_model_deployment_monitoring_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_UpdateModelDeploymentMonitoringJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_update_model_deployment_monitoring_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_update_model_deployment_monitoring_job_sync.py new file mode 100644 index 0000000000..0e51eb816b --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_job_service_update_model_deployment_monitoring_job_sync.py @@ -0,0 +1,53 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_JobService_UpdateModelDeploymentMonitoringJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_update_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + model_deployment_monitoring_job = aiplatform_v1beta1.ModelDeploymentMonitoringJob() + model_deployment_monitoring_job.display_name = "display_name_value" + model_deployment_monitoring_job.endpoint = "endpoint_value" + + request = aiplatform_v1beta1.UpdateModelDeploymentMonitoringJobRequest( + model_deployment_monitoring_job=model_deployment_monitoring_job, + ) + + # Make the request + operation = client.update_model_deployment_monitoring_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_JobService_UpdateModelDeploymentMonitoringJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_add_context_artifacts_and_executions_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_add_context_artifacts_and_executions_async.py new file mode 100644 index 0000000000..4f3fee2c3c --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_add_context_artifacts_and_executions_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddContextArtifactsAndExecutions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_AddContextArtifactsAndExecutions_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_add_context_artifacts_and_executions(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.AddContextArtifactsAndExecutionsRequest( + context="context_value", + ) + + # Make the request + response = await client.add_context_artifacts_and_executions(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_AddContextArtifactsAndExecutions_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_add_context_artifacts_and_executions_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_add_context_artifacts_and_executions_sync.py new file mode 100644 index 0000000000..7485ed98cb --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_add_context_artifacts_and_executions_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddContextArtifactsAndExecutions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_AddContextArtifactsAndExecutions_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_add_context_artifacts_and_executions(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.AddContextArtifactsAndExecutionsRequest( + context="context_value", + ) + + # Make the request + response = client.add_context_artifacts_and_executions(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_AddContextArtifactsAndExecutions_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_add_context_children_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_add_context_children_async.py new file mode 100644 index 0000000000..2697d870be --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_add_context_children_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddContextChildren +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_AddContextChildren_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_add_context_children(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.AddContextChildrenRequest( + context="context_value", + ) + + # Make the request + response = await client.add_context_children(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_AddContextChildren_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_add_context_children_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_add_context_children_sync.py new file mode 100644 index 0000000000..635d4dea4b --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_add_context_children_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddContextChildren +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_AddContextChildren_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_add_context_children(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.AddContextChildrenRequest( + context="context_value", + ) + + # Make the request + response = client.add_context_children(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_AddContextChildren_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_add_execution_events_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_add_execution_events_async.py new file mode 100644 index 0000000000..4b68d55c0f --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_add_execution_events_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddExecutionEvents +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_AddExecutionEvents_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_add_execution_events(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.AddExecutionEventsRequest( + execution="execution_value", + ) + + # Make the request + response = await client.add_execution_events(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_AddExecutionEvents_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_add_execution_events_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_add_execution_events_sync.py new file mode 100644 index 0000000000..3a2b11d7f1 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_add_execution_events_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddExecutionEvents +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_AddExecutionEvents_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_add_execution_events(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.AddExecutionEventsRequest( + execution="execution_value", + ) + + # Make the request + response = client.add_execution_events(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_AddExecutionEvents_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_create_artifact_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_create_artifact_async.py new file mode 100644 index 0000000000..8d4a133daa --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_create_artifact_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateArtifact +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_CreateArtifact_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_artifact(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateArtifactRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_artifact(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_CreateArtifact_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_create_artifact_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_create_artifact_sync.py new file mode 100644 index 0000000000..55527bf840 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_create_artifact_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateArtifact +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_CreateArtifact_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_artifact(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateArtifactRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_artifact(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_CreateArtifact_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_create_context_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_create_context_async.py new file mode 100644 index 0000000000..44b800e67b --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_create_context_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateContext +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_CreateContext_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_context(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateContextRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_context(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_CreateContext_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_create_context_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_create_context_sync.py new file mode 100644 index 0000000000..8ec94f0832 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_create_context_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateContext +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_CreateContext_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_context(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateContextRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_context(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_CreateContext_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_create_execution_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_create_execution_async.py new file mode 100644 index 0000000000..32dd1ccabd --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_create_execution_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_CreateExecution_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_execution(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateExecutionRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_execution(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_CreateExecution_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_create_execution_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_create_execution_sync.py new file mode 100644 index 0000000000..05d3270f35 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_create_execution_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_CreateExecution_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_execution(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateExecutionRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_execution(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_CreateExecution_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_create_metadata_schema_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_create_metadata_schema_async.py new file mode 100644 index 0000000000..36a18859cb --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_create_metadata_schema_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateMetadataSchema +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_CreateMetadataSchema_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_metadata_schema(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + metadata_schema = aiplatform_v1beta1.MetadataSchema() + metadata_schema.schema = "schema_value" + + request = aiplatform_v1beta1.CreateMetadataSchemaRequest( + parent="parent_value", + metadata_schema=metadata_schema, + ) + + # Make the request + response = await client.create_metadata_schema(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_CreateMetadataSchema_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_create_metadata_schema_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_create_metadata_schema_sync.py new file mode 100644 index 0000000000..2d4afec703 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_create_metadata_schema_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateMetadataSchema +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_CreateMetadataSchema_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_metadata_schema(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + metadata_schema = aiplatform_v1beta1.MetadataSchema() + metadata_schema.schema = "schema_value" + + request = aiplatform_v1beta1.CreateMetadataSchemaRequest( + parent="parent_value", + metadata_schema=metadata_schema, + ) + + # Make the request + response = client.create_metadata_schema(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_CreateMetadataSchema_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_create_metadata_store_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_create_metadata_store_async.py new file mode 100644 index 0000000000..887b34a2d4 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_create_metadata_store_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateMetadataStore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_CreateMetadataStore_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_metadata_store(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateMetadataStoreRequest( + parent="parent_value", + ) + + # Make the request + operation = client.create_metadata_store(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_CreateMetadataStore_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_create_metadata_store_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_create_metadata_store_sync.py new file mode 100644 index 0000000000..baf3ca0899 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_create_metadata_store_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateMetadataStore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_CreateMetadataStore_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_metadata_store(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateMetadataStoreRequest( + parent="parent_value", + ) + + # Make the request + operation = client.create_metadata_store(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_CreateMetadataStore_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_delete_artifact_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_delete_artifact_async.py new file mode 100644 index 0000000000..d680920684 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_delete_artifact_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteArtifact +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_DeleteArtifact_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_artifact(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteArtifactRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_artifact(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_DeleteArtifact_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_delete_artifact_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_delete_artifact_sync.py new file mode 100644 index 0000000000..a6c0e861e7 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_delete_artifact_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteArtifact +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_DeleteArtifact_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_artifact(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteArtifactRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_artifact(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_DeleteArtifact_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_delete_context_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_delete_context_async.py new file mode 100644 index 0000000000..e883988bdb --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_delete_context_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteContext +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_DeleteContext_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_context(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteContextRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_context(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_DeleteContext_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_delete_context_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_delete_context_sync.py new file mode 100644 index 0000000000..5c28cd649a --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_delete_context_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteContext +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_DeleteContext_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_context(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteContextRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_context(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_DeleteContext_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_delete_execution_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_delete_execution_async.py new file mode 100644 index 0000000000..e015618490 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_delete_execution_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_DeleteExecution_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_execution(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteExecutionRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_execution(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_DeleteExecution_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_delete_execution_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_delete_execution_sync.py new file mode 100644 index 0000000000..f064292d9a --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_delete_execution_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_DeleteExecution_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_execution(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteExecutionRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_execution(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_DeleteExecution_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_delete_metadata_store_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_delete_metadata_store_async.py new file mode 100644 index 0000000000..f43235b370 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_delete_metadata_store_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteMetadataStore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_DeleteMetadataStore_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_metadata_store(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteMetadataStoreRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_metadata_store(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_DeleteMetadataStore_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_delete_metadata_store_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_delete_metadata_store_sync.py new file mode 100644 index 0000000000..43551170ed --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_delete_metadata_store_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteMetadataStore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_DeleteMetadataStore_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_metadata_store(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteMetadataStoreRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_metadata_store(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_DeleteMetadataStore_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_get_artifact_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_get_artifact_async.py new file mode 100644 index 0000000000..d7ac573e0b --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_get_artifact_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetArtifact +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_GetArtifact_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_artifact(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetArtifactRequest( + name="name_value", + ) + + # Make the request + response = await client.get_artifact(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_GetArtifact_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_get_artifact_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_get_artifact_sync.py new file mode 100644 index 0000000000..c128c880ca --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_get_artifact_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetArtifact +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_GetArtifact_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_artifact(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetArtifactRequest( + name="name_value", + ) + + # Make the request + response = client.get_artifact(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_GetArtifact_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_get_context_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_get_context_async.py new file mode 100644 index 0000000000..4253527cf6 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_get_context_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetContext +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_GetContext_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_context(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetContextRequest( + name="name_value", + ) + + # Make the request + response = await client.get_context(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_GetContext_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_get_context_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_get_context_sync.py new file mode 100644 index 0000000000..a5e4694049 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_get_context_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetContext +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_GetContext_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_context(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetContextRequest( + name="name_value", + ) + + # Make the request + response = client.get_context(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_GetContext_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_get_execution_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_get_execution_async.py new file mode 100644 index 0000000000..66012f9e20 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_get_execution_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_GetExecution_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_execution(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetExecutionRequest( + name="name_value", + ) + + # Make the request + response = await client.get_execution(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_GetExecution_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_get_execution_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_get_execution_sync.py new file mode 100644 index 0000000000..b99ff65e70 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_get_execution_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_GetExecution_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_execution(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetExecutionRequest( + name="name_value", + ) + + # Make the request + response = client.get_execution(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_GetExecution_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_get_metadata_schema_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_get_metadata_schema_async.py new file mode 100644 index 0000000000..0bb95638a7 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_get_metadata_schema_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetMetadataSchema +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_GetMetadataSchema_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_metadata_schema(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetMetadataSchemaRequest( + name="name_value", + ) + + # Make the request + response = await client.get_metadata_schema(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_GetMetadataSchema_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_get_metadata_schema_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_get_metadata_schema_sync.py new file mode 100644 index 0000000000..ab4a6eb4ec --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_get_metadata_schema_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetMetadataSchema +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_GetMetadataSchema_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_metadata_schema(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetMetadataSchemaRequest( + name="name_value", + ) + + # Make the request + response = client.get_metadata_schema(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_GetMetadataSchema_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_get_metadata_store_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_get_metadata_store_async.py new file mode 100644 index 0000000000..b3158af01f --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_get_metadata_store_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetMetadataStore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_GetMetadataStore_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_metadata_store(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetMetadataStoreRequest( + name="name_value", + ) + + # Make the request + response = await client.get_metadata_store(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_GetMetadataStore_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_get_metadata_store_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_get_metadata_store_sync.py new file mode 100644 index 0000000000..ed2d24bac9 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_get_metadata_store_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetMetadataStore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_GetMetadataStore_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_metadata_store(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetMetadataStoreRequest( + name="name_value", + ) + + # Make the request + response = client.get_metadata_store(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_GetMetadataStore_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_list_artifacts_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_list_artifacts_async.py new file mode 100644 index 0000000000..33aa02602f --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_list_artifacts_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListArtifacts +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_ListArtifacts_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_artifacts(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListArtifactsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_artifacts(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_ListArtifacts_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_list_artifacts_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_list_artifacts_sync.py new file mode 100644 index 0000000000..b7bd5732f6 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_list_artifacts_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListArtifacts +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_ListArtifacts_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_artifacts(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListArtifactsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_artifacts(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_ListArtifacts_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_list_contexts_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_list_contexts_async.py new file mode 100644 index 0000000000..f4abd107cb --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_list_contexts_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListContexts +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_ListContexts_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_contexts(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListContextsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_contexts(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_ListContexts_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_list_contexts_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_list_contexts_sync.py new file mode 100644 index 0000000000..ff137fd1ea --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_list_contexts_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListContexts +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_ListContexts_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_contexts(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListContextsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_contexts(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_ListContexts_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_list_executions_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_list_executions_async.py new file mode 100644 index 0000000000..5c4bf9b143 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_list_executions_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListExecutions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_ListExecutions_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_executions(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListExecutionsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_executions(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_ListExecutions_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_list_executions_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_list_executions_sync.py new file mode 100644 index 0000000000..10d0bb5440 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_list_executions_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListExecutions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_ListExecutions_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_executions(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListExecutionsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_executions(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_ListExecutions_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_list_metadata_schemas_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_list_metadata_schemas_async.py new file mode 100644 index 0000000000..a23444802c --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_list_metadata_schemas_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListMetadataSchemas +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_ListMetadataSchemas_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_metadata_schemas(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListMetadataSchemasRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_metadata_schemas(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_ListMetadataSchemas_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_list_metadata_schemas_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_list_metadata_schemas_sync.py new file mode 100644 index 0000000000..cbb41bea60 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_list_metadata_schemas_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListMetadataSchemas +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_ListMetadataSchemas_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_metadata_schemas(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListMetadataSchemasRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_metadata_schemas(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_ListMetadataSchemas_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_list_metadata_stores_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_list_metadata_stores_async.py new file mode 100644 index 0000000000..77d498e68e --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_list_metadata_stores_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListMetadataStores +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_ListMetadataStores_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_metadata_stores(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListMetadataStoresRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_metadata_stores(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_ListMetadataStores_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_list_metadata_stores_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_list_metadata_stores_sync.py new file mode 100644 index 0000000000..58134f72d9 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_list_metadata_stores_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListMetadataStores +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_ListMetadataStores_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_metadata_stores(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListMetadataStoresRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_metadata_stores(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_ListMetadataStores_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_purge_artifacts_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_purge_artifacts_async.py new file mode 100644 index 0000000000..43800959ee --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_purge_artifacts_async.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PurgeArtifacts +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_PurgeArtifacts_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_purge_artifacts(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.PurgeArtifactsRequest( + parent="parent_value", + filter="filter_value", + ) + + # Make the request + operation = client.purge_artifacts(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_PurgeArtifacts_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_purge_artifacts_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_purge_artifacts_sync.py new file mode 100644 index 0000000000..02f3b56add --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_purge_artifacts_sync.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PurgeArtifacts +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_PurgeArtifacts_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_purge_artifacts(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.PurgeArtifactsRequest( + parent="parent_value", + filter="filter_value", + ) + + # Make the request + operation = client.purge_artifacts(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_PurgeArtifacts_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_purge_contexts_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_purge_contexts_async.py new file mode 100644 index 0000000000..af235473c0 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_purge_contexts_async.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PurgeContexts +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_PurgeContexts_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_purge_contexts(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.PurgeContextsRequest( + parent="parent_value", + filter="filter_value", + ) + + # Make the request + operation = client.purge_contexts(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_PurgeContexts_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_purge_contexts_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_purge_contexts_sync.py new file mode 100644 index 0000000000..59539f26c1 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_purge_contexts_sync.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PurgeContexts +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_PurgeContexts_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_purge_contexts(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.PurgeContextsRequest( + parent="parent_value", + filter="filter_value", + ) + + # Make the request + operation = client.purge_contexts(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_PurgeContexts_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_purge_executions_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_purge_executions_async.py new file mode 100644 index 0000000000..34e4d6035c --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_purge_executions_async.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PurgeExecutions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_PurgeExecutions_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_purge_executions(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.PurgeExecutionsRequest( + parent="parent_value", + filter="filter_value", + ) + + # Make the request + operation = client.purge_executions(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_PurgeExecutions_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_purge_executions_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_purge_executions_sync.py new file mode 100644 index 0000000000..38471613ed --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_purge_executions_sync.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PurgeExecutions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_PurgeExecutions_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_purge_executions(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.PurgeExecutionsRequest( + parent="parent_value", + filter="filter_value", + ) + + # Make the request + operation = client.purge_executions(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_PurgeExecutions_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_query_artifact_lineage_subgraph_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_query_artifact_lineage_subgraph_async.py new file mode 100644 index 0000000000..f18acb2d4f --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_query_artifact_lineage_subgraph_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for QueryArtifactLineageSubgraph +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_QueryArtifactLineageSubgraph_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_query_artifact_lineage_subgraph(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.QueryArtifactLineageSubgraphRequest( + artifact="artifact_value", + ) + + # Make the request + response = await client.query_artifact_lineage_subgraph(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_QueryArtifactLineageSubgraph_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_query_artifact_lineage_subgraph_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_query_artifact_lineage_subgraph_sync.py new file mode 100644 index 0000000000..e703c3aca2 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_query_artifact_lineage_subgraph_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for QueryArtifactLineageSubgraph +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_QueryArtifactLineageSubgraph_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_query_artifact_lineage_subgraph(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.QueryArtifactLineageSubgraphRequest( + artifact="artifact_value", + ) + + # Make the request + response = client.query_artifact_lineage_subgraph(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_QueryArtifactLineageSubgraph_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_query_context_lineage_subgraph_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_query_context_lineage_subgraph_async.py new file mode 100644 index 0000000000..ec19c145f1 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_query_context_lineage_subgraph_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for QueryContextLineageSubgraph +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_QueryContextLineageSubgraph_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_query_context_lineage_subgraph(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.QueryContextLineageSubgraphRequest( + context="context_value", + ) + + # Make the request + response = await client.query_context_lineage_subgraph(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_QueryContextLineageSubgraph_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_query_context_lineage_subgraph_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_query_context_lineage_subgraph_sync.py new file mode 100644 index 0000000000..cf83d420a0 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_query_context_lineage_subgraph_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for QueryContextLineageSubgraph +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_QueryContextLineageSubgraph_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_query_context_lineage_subgraph(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.QueryContextLineageSubgraphRequest( + context="context_value", + ) + + # Make the request + response = client.query_context_lineage_subgraph(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_QueryContextLineageSubgraph_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_query_execution_inputs_and_outputs_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_query_execution_inputs_and_outputs_async.py new file mode 100644 index 0000000000..1be132fbb2 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_query_execution_inputs_and_outputs_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for QueryExecutionInputsAndOutputs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_QueryExecutionInputsAndOutputs_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_query_execution_inputs_and_outputs(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.QueryExecutionInputsAndOutputsRequest( + execution="execution_value", + ) + + # Make the request + response = await client.query_execution_inputs_and_outputs(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_QueryExecutionInputsAndOutputs_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_query_execution_inputs_and_outputs_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_query_execution_inputs_and_outputs_sync.py new file mode 100644 index 0000000000..35fb23c58b --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_query_execution_inputs_and_outputs_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for QueryExecutionInputsAndOutputs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_QueryExecutionInputsAndOutputs_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_query_execution_inputs_and_outputs(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.QueryExecutionInputsAndOutputsRequest( + execution="execution_value", + ) + + # Make the request + response = client.query_execution_inputs_and_outputs(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_QueryExecutionInputsAndOutputs_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_update_artifact_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_update_artifact_async.py new file mode 100644 index 0000000000..e9ad64048d --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_update_artifact_async.py @@ -0,0 +1,44 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateArtifact +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_UpdateArtifact_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_update_artifact(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateArtifactRequest( + ) + + # Make the request + response = await client.update_artifact(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_UpdateArtifact_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_update_artifact_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_update_artifact_sync.py new file mode 100644 index 0000000000..6a26a780db --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_update_artifact_sync.py @@ -0,0 +1,44 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateArtifact +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_UpdateArtifact_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_update_artifact(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateArtifactRequest( + ) + + # Make the request + response = client.update_artifact(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_UpdateArtifact_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_update_context_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_update_context_async.py new file mode 100644 index 0000000000..71371049f5 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_update_context_async.py @@ -0,0 +1,44 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateContext +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_UpdateContext_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_update_context(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateContextRequest( + ) + + # Make the request + response = await client.update_context(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_UpdateContext_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_update_context_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_update_context_sync.py new file mode 100644 index 0000000000..0d26ef7e5f --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_update_context_sync.py @@ -0,0 +1,44 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateContext +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_UpdateContext_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_update_context(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateContextRequest( + ) + + # Make the request + response = client.update_context(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_UpdateContext_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_update_execution_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_update_execution_async.py new file mode 100644 index 0000000000..64a945b87b --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_update_execution_async.py @@ -0,0 +1,44 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_UpdateExecution_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_update_execution(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateExecutionRequest( + ) + + # Make the request + response = await client.update_execution(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_UpdateExecution_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_update_execution_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_update_execution_sync.py new file mode 100644 index 0000000000..45df9ca2e6 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_metadata_service_update_execution_sync.py @@ -0,0 +1,44 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MetadataService_UpdateExecution_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_update_execution(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateExecutionRequest( + ) + + # Make the request + response = client.update_execution(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MetadataService_UpdateExecution_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_migration_service_batch_migrate_resources_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_migration_service_batch_migrate_resources_async.py new file mode 100644 index 0000000000..4f8646ee30 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_migration_service_batch_migrate_resources_async.py @@ -0,0 +1,55 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchMigrateResources +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MigrationService_BatchMigrateResources_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_batch_migrate_resources(): + # Create a client + client = aiplatform_v1beta1.MigrationServiceAsyncClient() + + # Initialize request argument(s) + migrate_resource_requests = aiplatform_v1beta1.MigrateResourceRequest() + migrate_resource_requests.migrate_ml_engine_model_version_config.endpoint = "endpoint_value" + migrate_resource_requests.migrate_ml_engine_model_version_config.model_version = "model_version_value" + migrate_resource_requests.migrate_ml_engine_model_version_config.model_display_name = "model_display_name_value" + + request = aiplatform_v1beta1.BatchMigrateResourcesRequest( + parent="parent_value", + migrate_resource_requests=migrate_resource_requests, + ) + + # Make the request + operation = client.batch_migrate_resources(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MigrationService_BatchMigrateResources_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_migration_service_batch_migrate_resources_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_migration_service_batch_migrate_resources_sync.py new file mode 100644 index 0000000000..556e1a9a24 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_migration_service_batch_migrate_resources_sync.py @@ -0,0 +1,55 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchMigrateResources +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MigrationService_BatchMigrateResources_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_batch_migrate_resources(): + # Create a client + client = aiplatform_v1beta1.MigrationServiceClient() + + # Initialize request argument(s) + migrate_resource_requests = aiplatform_v1beta1.MigrateResourceRequest() + migrate_resource_requests.migrate_ml_engine_model_version_config.endpoint = "endpoint_value" + migrate_resource_requests.migrate_ml_engine_model_version_config.model_version = "model_version_value" + migrate_resource_requests.migrate_ml_engine_model_version_config.model_display_name = "model_display_name_value" + + request = aiplatform_v1beta1.BatchMigrateResourcesRequest( + parent="parent_value", + migrate_resource_requests=migrate_resource_requests, + ) + + # Make the request + operation = client.batch_migrate_resources(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MigrationService_BatchMigrateResources_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_migration_service_search_migratable_resources_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_migration_service_search_migratable_resources_async.py new file mode 100644 index 0000000000..1c5e64a794 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_migration_service_search_migratable_resources_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SearchMigratableResources +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MigrationService_SearchMigratableResources_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_search_migratable_resources(): + # Create a client + client = aiplatform_v1beta1.MigrationServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.SearchMigratableResourcesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.search_migratable_resources(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MigrationService_SearchMigratableResources_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_migration_service_search_migratable_resources_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_migration_service_search_migratable_resources_sync.py new file mode 100644 index 0000000000..a849bd9c48 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_migration_service_search_migratable_resources_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SearchMigratableResources +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_MigrationService_SearchMigratableResources_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_search_migratable_resources(): + # Create a client + client = aiplatform_v1beta1.MigrationServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.SearchMigratableResourcesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.search_migratable_resources(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_MigrationService_SearchMigratableResources_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_delete_model_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_delete_model_async.py new file mode 100644 index 0000000000..9ba1768819 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_delete_model_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_ModelService_DeleteModel_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_model(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteModelRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_model(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_ModelService_DeleteModel_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_delete_model_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_delete_model_sync.py new file mode 100644 index 0000000000..e3813f14d0 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_delete_model_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_ModelService_DeleteModel_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_model(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteModelRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_model(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_ModelService_DeleteModel_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_export_model_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_export_model_async.py new file mode 100644 index 0000000000..5b3a1f5831 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_export_model_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_ModelService_ExportModel_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_export_model(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ExportModelRequest( + name="name_value", + ) + + # Make the request + operation = client.export_model(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_ModelService_ExportModel_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_export_model_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_export_model_sync.py new file mode 100644 index 0000000000..db7eab2ae4 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_export_model_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_ModelService_ExportModel_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_export_model(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ExportModelRequest( + name="name_value", + ) + + # Make the request + operation = client.export_model(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_ModelService_ExportModel_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_get_model_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_get_model_async.py new file mode 100644 index 0000000000..6deba97ad6 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_get_model_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_ModelService_GetModel_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_model(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetModelRequest( + name="name_value", + ) + + # Make the request + response = await client.get_model(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_ModelService_GetModel_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_get_model_evaluation_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_get_model_evaluation_async.py new file mode 100644 index 0000000000..4ac204dd82 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_get_model_evaluation_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetModelEvaluation +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_ModelService_GetModelEvaluation_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_model_evaluation(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetModelEvaluationRequest( + name="name_value", + ) + + # Make the request + response = await client.get_model_evaluation(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_ModelService_GetModelEvaluation_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_get_model_evaluation_slice_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_get_model_evaluation_slice_async.py new file mode 100644 index 0000000000..5ed989e347 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_get_model_evaluation_slice_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetModelEvaluationSlice +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_ModelService_GetModelEvaluationSlice_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_model_evaluation_slice(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetModelEvaluationSliceRequest( + name="name_value", + ) + + # Make the request + response = await client.get_model_evaluation_slice(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_ModelService_GetModelEvaluationSlice_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_get_model_evaluation_slice_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_get_model_evaluation_slice_sync.py new file mode 100644 index 0000000000..8a416aaca9 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_get_model_evaluation_slice_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetModelEvaluationSlice +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_ModelService_GetModelEvaluationSlice_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_model_evaluation_slice(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetModelEvaluationSliceRequest( + name="name_value", + ) + + # Make the request + response = client.get_model_evaluation_slice(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_ModelService_GetModelEvaluationSlice_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_get_model_evaluation_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_get_model_evaluation_sync.py new file mode 100644 index 0000000000..2025e2c541 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_get_model_evaluation_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetModelEvaluation +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_ModelService_GetModelEvaluation_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_model_evaluation(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetModelEvaluationRequest( + name="name_value", + ) + + # Make the request + response = client.get_model_evaluation(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_ModelService_GetModelEvaluation_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_get_model_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_get_model_sync.py new file mode 100644 index 0000000000..b6d579bc0d --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_get_model_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_ModelService_GetModel_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_model(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetModelRequest( + name="name_value", + ) + + # Make the request + response = client.get_model(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_ModelService_GetModel_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_list_model_evaluation_slices_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_list_model_evaluation_slices_async.py new file mode 100644 index 0000000000..fc5bc559b8 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_list_model_evaluation_slices_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListModelEvaluationSlices +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_ModelService_ListModelEvaluationSlices_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_model_evaluation_slices(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListModelEvaluationSlicesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_model_evaluation_slices(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_ModelService_ListModelEvaluationSlices_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_list_model_evaluation_slices_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_list_model_evaluation_slices_sync.py new file mode 100644 index 0000000000..7349ca505f --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_list_model_evaluation_slices_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListModelEvaluationSlices +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_ModelService_ListModelEvaluationSlices_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_model_evaluation_slices(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListModelEvaluationSlicesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_model_evaluation_slices(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_ModelService_ListModelEvaluationSlices_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_list_model_evaluations_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_list_model_evaluations_async.py new file mode 100644 index 0000000000..6337ddf930 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_list_model_evaluations_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListModelEvaluations +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_ModelService_ListModelEvaluations_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_model_evaluations(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListModelEvaluationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_model_evaluations(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_ModelService_ListModelEvaluations_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_list_model_evaluations_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_list_model_evaluations_sync.py new file mode 100644 index 0000000000..83b8313d1d --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_list_model_evaluations_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListModelEvaluations +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_ModelService_ListModelEvaluations_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_model_evaluations(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListModelEvaluationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_model_evaluations(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_ModelService_ListModelEvaluations_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_list_models_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_list_models_async.py new file mode 100644 index 0000000000..ed585472d5 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_list_models_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListModels +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_ModelService_ListModels_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_models(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListModelsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_models(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_ModelService_ListModels_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_list_models_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_list_models_sync.py new file mode 100644 index 0000000000..95be3acdea --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_list_models_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListModels +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_ModelService_ListModels_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_models(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListModelsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_models(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_ModelService_ListModels_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_update_model_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_update_model_async.py new file mode 100644 index 0000000000..90e3df5378 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_update_model_async.py @@ -0,0 +1,48 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_ModelService_UpdateModel_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_update_model(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + model = aiplatform_v1beta1.Model() + model.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateModelRequest( + model=model, + ) + + # Make the request + response = await client.update_model(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_ModelService_UpdateModel_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_update_model_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_update_model_sync.py new file mode 100644 index 0000000000..c88c1b6bc3 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_update_model_sync.py @@ -0,0 +1,48 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_ModelService_UpdateModel_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_update_model(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + model = aiplatform_v1beta1.Model() + model.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateModelRequest( + model=model, + ) + + # Make the request + response = client.update_model(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_ModelService_UpdateModel_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_upload_model_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_upload_model_async.py new file mode 100644 index 0000000000..ba797eecba --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_upload_model_async.py @@ -0,0 +1,53 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UploadModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_ModelService_UploadModel_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_upload_model(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + model = aiplatform_v1beta1.Model() + model.display_name = "display_name_value" + + request = aiplatform_v1beta1.UploadModelRequest( + parent="parent_value", + model=model, + ) + + # Make the request + operation = client.upload_model(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_ModelService_UploadModel_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_upload_model_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_upload_model_sync.py new file mode 100644 index 0000000000..a7356ba37a --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_model_service_upload_model_sync.py @@ -0,0 +1,53 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UploadModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_ModelService_UploadModel_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_upload_model(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + model = aiplatform_v1beta1.Model() + model.display_name = "display_name_value" + + request = aiplatform_v1beta1.UploadModelRequest( + parent="parent_value", + model=model, + ) + + # Make the request + operation = client.upload_model(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_ModelService_UploadModel_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_cancel_pipeline_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_cancel_pipeline_job_async.py new file mode 100644 index 0000000000..7cada005a0 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_cancel_pipeline_job_async.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelPipelineJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_PipelineService_CancelPipelineJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_cancel_pipeline_job(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CancelPipelineJobRequest( + name="name_value", + ) + + # Make the request + await client.cancel_pipeline_job(request=request) + + +# [END aiplatform_generated_aiplatform_v1beta1_PipelineService_CancelPipelineJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_cancel_pipeline_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_cancel_pipeline_job_sync.py new file mode 100644 index 0000000000..5375706ada --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_cancel_pipeline_job_sync.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelPipelineJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_PipelineService_CancelPipelineJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_cancel_pipeline_job(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CancelPipelineJobRequest( + name="name_value", + ) + + # Make the request + client.cancel_pipeline_job(request=request) + + +# [END aiplatform_generated_aiplatform_v1beta1_PipelineService_CancelPipelineJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_cancel_training_pipeline_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_cancel_training_pipeline_async.py new file mode 100644 index 0000000000..6d5e072c32 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_cancel_training_pipeline_async.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelTrainingPipeline +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_PipelineService_CancelTrainingPipeline_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_cancel_training_pipeline(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CancelTrainingPipelineRequest( + name="name_value", + ) + + # Make the request + await client.cancel_training_pipeline(request=request) + + +# [END aiplatform_generated_aiplatform_v1beta1_PipelineService_CancelTrainingPipeline_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_cancel_training_pipeline_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_cancel_training_pipeline_sync.py new file mode 100644 index 0000000000..53057bf1fb --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_cancel_training_pipeline_sync.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelTrainingPipeline +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_PipelineService_CancelTrainingPipeline_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_cancel_training_pipeline(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CancelTrainingPipelineRequest( + name="name_value", + ) + + # Make the request + client.cancel_training_pipeline(request=request) + + +# [END aiplatform_generated_aiplatform_v1beta1_PipelineService_CancelTrainingPipeline_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_create_pipeline_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_create_pipeline_job_async.py new file mode 100644 index 0000000000..1267b7299e --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_create_pipeline_job_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreatePipelineJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_PipelineService_CreatePipelineJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_pipeline_job(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreatePipelineJobRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_pipeline_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_PipelineService_CreatePipelineJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_create_pipeline_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_create_pipeline_job_sync.py new file mode 100644 index 0000000000..a4e688126d --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_create_pipeline_job_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreatePipelineJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_PipelineService_CreatePipelineJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_pipeline_job(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreatePipelineJobRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_pipeline_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_PipelineService_CreatePipelineJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_create_training_pipeline_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_create_training_pipeline_async.py new file mode 100644 index 0000000000..2db5d45d03 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_create_training_pipeline_async.py @@ -0,0 +1,51 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTrainingPipeline +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_PipelineService_CreateTrainingPipeline_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_training_pipeline(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + training_pipeline = aiplatform_v1beta1.TrainingPipeline() + training_pipeline.display_name = "display_name_value" + training_pipeline.training_task_definition = "training_task_definition_value" + training_pipeline.training_task_inputs.null_value = "NULL_VALUE" + + request = aiplatform_v1beta1.CreateTrainingPipelineRequest( + parent="parent_value", + training_pipeline=training_pipeline, + ) + + # Make the request + response = await client.create_training_pipeline(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_PipelineService_CreateTrainingPipeline_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_create_training_pipeline_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_create_training_pipeline_sync.py new file mode 100644 index 0000000000..1529fa505b --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_create_training_pipeline_sync.py @@ -0,0 +1,51 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTrainingPipeline +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_PipelineService_CreateTrainingPipeline_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_training_pipeline(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceClient() + + # Initialize request argument(s) + training_pipeline = aiplatform_v1beta1.TrainingPipeline() + training_pipeline.display_name = "display_name_value" + training_pipeline.training_task_definition = "training_task_definition_value" + training_pipeline.training_task_inputs.null_value = "NULL_VALUE" + + request = aiplatform_v1beta1.CreateTrainingPipelineRequest( + parent="parent_value", + training_pipeline=training_pipeline, + ) + + # Make the request + response = client.create_training_pipeline(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_PipelineService_CreateTrainingPipeline_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_delete_pipeline_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_delete_pipeline_job_async.py new file mode 100644 index 0000000000..2edd009275 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_delete_pipeline_job_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeletePipelineJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_PipelineService_DeletePipelineJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_pipeline_job(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeletePipelineJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_pipeline_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_PipelineService_DeletePipelineJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_delete_pipeline_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_delete_pipeline_job_sync.py new file mode 100644 index 0000000000..f0722c88ac --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_delete_pipeline_job_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeletePipelineJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_PipelineService_DeletePipelineJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_pipeline_job(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeletePipelineJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_pipeline_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_PipelineService_DeletePipelineJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_delete_training_pipeline_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_delete_training_pipeline_async.py new file mode 100644 index 0000000000..28afc78ed2 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_delete_training_pipeline_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTrainingPipeline +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_PipelineService_DeleteTrainingPipeline_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_training_pipeline(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteTrainingPipelineRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_training_pipeline(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_PipelineService_DeleteTrainingPipeline_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_delete_training_pipeline_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_delete_training_pipeline_sync.py new file mode 100644 index 0000000000..098b704abe --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_delete_training_pipeline_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTrainingPipeline +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_PipelineService_DeleteTrainingPipeline_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_training_pipeline(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteTrainingPipelineRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_training_pipeline(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_PipelineService_DeleteTrainingPipeline_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_get_pipeline_job_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_get_pipeline_job_async.py new file mode 100644 index 0000000000..2f4230c051 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_get_pipeline_job_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetPipelineJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_PipelineService_GetPipelineJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_pipeline_job(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetPipelineJobRequest( + name="name_value", + ) + + # Make the request + response = await client.get_pipeline_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_PipelineService_GetPipelineJob_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_get_pipeline_job_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_get_pipeline_job_sync.py new file mode 100644 index 0000000000..d1c3fd29a0 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_get_pipeline_job_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetPipelineJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_PipelineService_GetPipelineJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_pipeline_job(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetPipelineJobRequest( + name="name_value", + ) + + # Make the request + response = client.get_pipeline_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_PipelineService_GetPipelineJob_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_get_training_pipeline_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_get_training_pipeline_async.py new file mode 100644 index 0000000000..6848da3dea --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_get_training_pipeline_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTrainingPipeline +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_PipelineService_GetTrainingPipeline_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_training_pipeline(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetTrainingPipelineRequest( + name="name_value", + ) + + # Make the request + response = await client.get_training_pipeline(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_PipelineService_GetTrainingPipeline_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_get_training_pipeline_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_get_training_pipeline_sync.py new file mode 100644 index 0000000000..a9bda5bcb1 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_get_training_pipeline_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTrainingPipeline +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_PipelineService_GetTrainingPipeline_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_training_pipeline(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetTrainingPipelineRequest( + name="name_value", + ) + + # Make the request + response = client.get_training_pipeline(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_PipelineService_GetTrainingPipeline_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_list_pipeline_jobs_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_list_pipeline_jobs_async.py new file mode 100644 index 0000000000..1b2e66e233 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_list_pipeline_jobs_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListPipelineJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_PipelineService_ListPipelineJobs_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_pipeline_jobs(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListPipelineJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_pipeline_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_PipelineService_ListPipelineJobs_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_list_pipeline_jobs_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_list_pipeline_jobs_sync.py new file mode 100644 index 0000000000..313773eeea --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_list_pipeline_jobs_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListPipelineJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_PipelineService_ListPipelineJobs_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_pipeline_jobs(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListPipelineJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_pipeline_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_PipelineService_ListPipelineJobs_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_list_training_pipelines_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_list_training_pipelines_async.py new file mode 100644 index 0000000000..6696e8ab27 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_list_training_pipelines_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTrainingPipelines +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_PipelineService_ListTrainingPipelines_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_training_pipelines(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListTrainingPipelinesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_training_pipelines(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_PipelineService_ListTrainingPipelines_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_list_training_pipelines_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_list_training_pipelines_sync.py new file mode 100644 index 0000000000..30b874d6dc --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_pipeline_service_list_training_pipelines_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTrainingPipelines +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_PipelineService_ListTrainingPipelines_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_training_pipelines(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListTrainingPipelinesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_training_pipelines(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_PipelineService_ListTrainingPipelines_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_prediction_service_explain_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_prediction_service_explain_async.py new file mode 100644 index 0000000000..02d9abe0bf --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_prediction_service_explain_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for Explain +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_PredictionService_Explain_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_explain(): + # Create a client + client = aiplatform_v1beta1.PredictionServiceAsyncClient() + + # Initialize request argument(s) + instances = aiplatform_v1beta1.Value() + instances.null_value = "NULL_VALUE" + + request = aiplatform_v1beta1.ExplainRequest( + endpoint="endpoint_value", + instances=instances, + ) + + # Make the request + response = await client.explain(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_PredictionService_Explain_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_prediction_service_explain_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_prediction_service_explain_sync.py new file mode 100644 index 0000000000..d0993cb167 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_prediction_service_explain_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for Explain +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_PredictionService_Explain_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_explain(): + # Create a client + client = aiplatform_v1beta1.PredictionServiceClient() + + # Initialize request argument(s) + instances = aiplatform_v1beta1.Value() + instances.null_value = "NULL_VALUE" + + request = aiplatform_v1beta1.ExplainRequest( + endpoint="endpoint_value", + instances=instances, + ) + + # Make the request + response = client.explain(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_PredictionService_Explain_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_prediction_service_predict_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_prediction_service_predict_async.py new file mode 100644 index 0000000000..013e9b6ad4 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_prediction_service_predict_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for Predict +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_PredictionService_Predict_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_predict(): + # Create a client + client = aiplatform_v1beta1.PredictionServiceAsyncClient() + + # Initialize request argument(s) + instances = aiplatform_v1beta1.Value() + instances.null_value = "NULL_VALUE" + + request = aiplatform_v1beta1.PredictRequest( + endpoint="endpoint_value", + instances=instances, + ) + + # Make the request + response = await client.predict(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_PredictionService_Predict_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_prediction_service_predict_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_prediction_service_predict_sync.py new file mode 100644 index 0000000000..9683fc0060 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_prediction_service_predict_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for Predict +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_PredictionService_Predict_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_predict(): + # Create a client + client = aiplatform_v1beta1.PredictionServiceClient() + + # Initialize request argument(s) + instances = aiplatform_v1beta1.Value() + instances.null_value = "NULL_VALUE" + + request = aiplatform_v1beta1.PredictRequest( + endpoint="endpoint_value", + instances=instances, + ) + + # Make the request + response = client.predict(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_PredictionService_Predict_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_prediction_service_raw_predict_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_prediction_service_raw_predict_async.py new file mode 100644 index 0000000000..f32c62bb08 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_prediction_service_raw_predict_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for RawPredict +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_PredictionService_RawPredict_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_raw_predict(): + # Create a client + client = aiplatform_v1beta1.PredictionServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.RawPredictRequest( + endpoint="endpoint_value", + ) + + # Make the request + response = await client.raw_predict(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_PredictionService_RawPredict_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_prediction_service_raw_predict_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_prediction_service_raw_predict_sync.py new file mode 100644 index 0000000000..5517055e9b --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_prediction_service_raw_predict_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for RawPredict +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_PredictionService_RawPredict_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_raw_predict(): + # Create a client + client = aiplatform_v1beta1.PredictionServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.RawPredictRequest( + endpoint="endpoint_value", + ) + + # Make the request + response = client.raw_predict(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_PredictionService_RawPredict_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_specialist_pool_service_create_specialist_pool_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_specialist_pool_service_create_specialist_pool_async.py new file mode 100644 index 0000000000..c731adc24b --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_specialist_pool_service_create_specialist_pool_async.py @@ -0,0 +1,54 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateSpecialistPool +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_SpecialistPoolService_CreateSpecialistPool_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_specialist_pool(): + # Create a client + client = aiplatform_v1beta1.SpecialistPoolServiceAsyncClient() + + # Initialize request argument(s) + specialist_pool = aiplatform_v1beta1.SpecialistPool() + specialist_pool.name = "name_value" + specialist_pool.display_name = "display_name_value" + + request = aiplatform_v1beta1.CreateSpecialistPoolRequest( + parent="parent_value", + specialist_pool=specialist_pool, + ) + + # Make the request + operation = client.create_specialist_pool(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_SpecialistPoolService_CreateSpecialistPool_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_specialist_pool_service_create_specialist_pool_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_specialist_pool_service_create_specialist_pool_sync.py new file mode 100644 index 0000000000..2f76f71f9e --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_specialist_pool_service_create_specialist_pool_sync.py @@ -0,0 +1,54 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateSpecialistPool +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_SpecialistPoolService_CreateSpecialistPool_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_specialist_pool(): + # Create a client + client = aiplatform_v1beta1.SpecialistPoolServiceClient() + + # Initialize request argument(s) + specialist_pool = aiplatform_v1beta1.SpecialistPool() + specialist_pool.name = "name_value" + specialist_pool.display_name = "display_name_value" + + request = aiplatform_v1beta1.CreateSpecialistPoolRequest( + parent="parent_value", + specialist_pool=specialist_pool, + ) + + # Make the request + operation = client.create_specialist_pool(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_SpecialistPoolService_CreateSpecialistPool_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_specialist_pool_service_delete_specialist_pool_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_specialist_pool_service_delete_specialist_pool_async.py new file mode 100644 index 0000000000..54902aeeef --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_specialist_pool_service_delete_specialist_pool_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteSpecialistPool +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_SpecialistPoolService_DeleteSpecialistPool_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_specialist_pool(): + # Create a client + client = aiplatform_v1beta1.SpecialistPoolServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteSpecialistPoolRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_specialist_pool(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_SpecialistPoolService_DeleteSpecialistPool_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_specialist_pool_service_delete_specialist_pool_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_specialist_pool_service_delete_specialist_pool_sync.py new file mode 100644 index 0000000000..40581a02c8 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_specialist_pool_service_delete_specialist_pool_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteSpecialistPool +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_SpecialistPoolService_DeleteSpecialistPool_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_specialist_pool(): + # Create a client + client = aiplatform_v1beta1.SpecialistPoolServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteSpecialistPoolRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_specialist_pool(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_SpecialistPoolService_DeleteSpecialistPool_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_specialist_pool_service_get_specialist_pool_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_specialist_pool_service_get_specialist_pool_async.py new file mode 100644 index 0000000000..ad4d8ca6ac --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_specialist_pool_service_get_specialist_pool_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetSpecialistPool +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_SpecialistPoolService_GetSpecialistPool_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_specialist_pool(): + # Create a client + client = aiplatform_v1beta1.SpecialistPoolServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetSpecialistPoolRequest( + name="name_value", + ) + + # Make the request + response = await client.get_specialist_pool(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_SpecialistPoolService_GetSpecialistPool_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_specialist_pool_service_get_specialist_pool_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_specialist_pool_service_get_specialist_pool_sync.py new file mode 100644 index 0000000000..4bc71e0a3d --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_specialist_pool_service_get_specialist_pool_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetSpecialistPool +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_SpecialistPoolService_GetSpecialistPool_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_specialist_pool(): + # Create a client + client = aiplatform_v1beta1.SpecialistPoolServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetSpecialistPoolRequest( + name="name_value", + ) + + # Make the request + response = client.get_specialist_pool(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_SpecialistPoolService_GetSpecialistPool_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_specialist_pool_service_list_specialist_pools_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_specialist_pool_service_list_specialist_pools_async.py new file mode 100644 index 0000000000..729ff7aa78 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_specialist_pool_service_list_specialist_pools_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListSpecialistPools +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_SpecialistPoolService_ListSpecialistPools_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_specialist_pools(): + # Create a client + client = aiplatform_v1beta1.SpecialistPoolServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListSpecialistPoolsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_specialist_pools(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_SpecialistPoolService_ListSpecialistPools_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_specialist_pool_service_list_specialist_pools_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_specialist_pool_service_list_specialist_pools_sync.py new file mode 100644 index 0000000000..bfbf0edfe4 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_specialist_pool_service_list_specialist_pools_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListSpecialistPools +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_SpecialistPoolService_ListSpecialistPools_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_specialist_pools(): + # Create a client + client = aiplatform_v1beta1.SpecialistPoolServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListSpecialistPoolsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_specialist_pools(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_SpecialistPoolService_ListSpecialistPools_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_specialist_pool_service_update_specialist_pool_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_specialist_pool_service_update_specialist_pool_async.py new file mode 100644 index 0000000000..1fccb2c7f4 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_specialist_pool_service_update_specialist_pool_async.py @@ -0,0 +1,53 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateSpecialistPool +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_SpecialistPoolService_UpdateSpecialistPool_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_update_specialist_pool(): + # Create a client + client = aiplatform_v1beta1.SpecialistPoolServiceAsyncClient() + + # Initialize request argument(s) + specialist_pool = aiplatform_v1beta1.SpecialistPool() + specialist_pool.name = "name_value" + specialist_pool.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateSpecialistPoolRequest( + specialist_pool=specialist_pool, + ) + + # Make the request + operation = client.update_specialist_pool(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_SpecialistPoolService_UpdateSpecialistPool_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_specialist_pool_service_update_specialist_pool_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_specialist_pool_service_update_specialist_pool_sync.py new file mode 100644 index 0000000000..cf4841db68 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_specialist_pool_service_update_specialist_pool_sync.py @@ -0,0 +1,53 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateSpecialistPool +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_SpecialistPoolService_UpdateSpecialistPool_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_update_specialist_pool(): + # Create a client + client = aiplatform_v1beta1.SpecialistPoolServiceClient() + + # Initialize request argument(s) + specialist_pool = aiplatform_v1beta1.SpecialistPool() + specialist_pool.name = "name_value" + specialist_pool.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateSpecialistPoolRequest( + specialist_pool=specialist_pool, + ) + + # Make the request + operation = client.update_specialist_pool(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_SpecialistPoolService_UpdateSpecialistPool_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_batch_create_tensorboard_runs_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_batch_create_tensorboard_runs_async.py new file mode 100644 index 0000000000..0499deb0a8 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_batch_create_tensorboard_runs_async.py @@ -0,0 +1,51 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchCreateTensorboardRuns +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_BatchCreateTensorboardRuns_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_batch_create_tensorboard_runs(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + requests = aiplatform_v1beta1.CreateTensorboardRunRequest() + requests.parent = "parent_value" + requests.tensorboard_run.display_name = "display_name_value" + requests.tensorboard_run_id = "tensorboard_run_id_value" + + request = aiplatform_v1beta1.BatchCreateTensorboardRunsRequest( + parent="parent_value", + requests=requests, + ) + + # Make the request + response = await client.batch_create_tensorboard_runs(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_BatchCreateTensorboardRuns_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_batch_create_tensorboard_runs_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_batch_create_tensorboard_runs_sync.py new file mode 100644 index 0000000000..c6827d7a4a --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_batch_create_tensorboard_runs_sync.py @@ -0,0 +1,51 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchCreateTensorboardRuns +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_BatchCreateTensorboardRuns_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_batch_create_tensorboard_runs(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + requests = aiplatform_v1beta1.CreateTensorboardRunRequest() + requests.parent = "parent_value" + requests.tensorboard_run.display_name = "display_name_value" + requests.tensorboard_run_id = "tensorboard_run_id_value" + + request = aiplatform_v1beta1.BatchCreateTensorboardRunsRequest( + parent="parent_value", + requests=requests, + ) + + # Make the request + response = client.batch_create_tensorboard_runs(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_BatchCreateTensorboardRuns_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_batch_create_tensorboard_time_series_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_batch_create_tensorboard_time_series_async.py new file mode 100644 index 0000000000..87213a466a --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_batch_create_tensorboard_time_series_async.py @@ -0,0 +1,51 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchCreateTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_BatchCreateTensorboardTimeSeries_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_batch_create_tensorboard_time_series(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + requests = aiplatform_v1beta1.CreateTensorboardTimeSeriesRequest() + requests.parent = "parent_value" + requests.tensorboard_time_series.display_name = "display_name_value" + requests.tensorboard_time_series.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1beta1.BatchCreateTensorboardTimeSeriesRequest( + parent="parent_value", + requests=requests, + ) + + # Make the request + response = await client.batch_create_tensorboard_time_series(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_BatchCreateTensorboardTimeSeries_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_batch_create_tensorboard_time_series_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_batch_create_tensorboard_time_series_sync.py new file mode 100644 index 0000000000..dff96e34e4 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_batch_create_tensorboard_time_series_sync.py @@ -0,0 +1,51 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchCreateTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_BatchCreateTensorboardTimeSeries_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_batch_create_tensorboard_time_series(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + requests = aiplatform_v1beta1.CreateTensorboardTimeSeriesRequest() + requests.parent = "parent_value" + requests.tensorboard_time_series.display_name = "display_name_value" + requests.tensorboard_time_series.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1beta1.BatchCreateTensorboardTimeSeriesRequest( + parent="parent_value", + requests=requests, + ) + + # Make the request + response = client.batch_create_tensorboard_time_series(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_BatchCreateTensorboardTimeSeries_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_batch_read_tensorboard_time_series_data_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_batch_read_tensorboard_time_series_data_async.py new file mode 100644 index 0000000000..49945f7b54 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_batch_read_tensorboard_time_series_data_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchReadTensorboardTimeSeriesData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_BatchReadTensorboardTimeSeriesData_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_batch_read_tensorboard_time_series_data(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.BatchReadTensorboardTimeSeriesDataRequest( + tensorboard="tensorboard_value", + time_series=['time_series_value_1', 'time_series_value_2'], + ) + + # Make the request + response = await client.batch_read_tensorboard_time_series_data(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_BatchReadTensorboardTimeSeriesData_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_batch_read_tensorboard_time_series_data_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_batch_read_tensorboard_time_series_data_sync.py new file mode 100644 index 0000000000..a90b7a75b2 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_batch_read_tensorboard_time_series_data_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchReadTensorboardTimeSeriesData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_BatchReadTensorboardTimeSeriesData_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_batch_read_tensorboard_time_series_data(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.BatchReadTensorboardTimeSeriesDataRequest( + tensorboard="tensorboard_value", + time_series=['time_series_value_1', 'time_series_value_2'], + ) + + # Make the request + response = client.batch_read_tensorboard_time_series_data(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_BatchReadTensorboardTimeSeriesData_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_create_tensorboard_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_create_tensorboard_async.py new file mode 100644 index 0000000000..fe5403e89d --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_create_tensorboard_async.py @@ -0,0 +1,53 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTensorboard +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_CreateTensorboard_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_tensorboard(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + tensorboard = aiplatform_v1beta1.Tensorboard() + tensorboard.display_name = "display_name_value" + + request = aiplatform_v1beta1.CreateTensorboardRequest( + parent="parent_value", + tensorboard=tensorboard, + ) + + # Make the request + operation = client.create_tensorboard(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_CreateTensorboard_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_create_tensorboard_experiment_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_create_tensorboard_experiment_async.py new file mode 100644 index 0000000000..32a1e3f31c --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_create_tensorboard_experiment_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTensorboardExperiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_CreateTensorboardExperiment_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_tensorboard_experiment(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateTensorboardExperimentRequest( + parent="parent_value", + tensorboard_experiment_id="tensorboard_experiment_id_value", + ) + + # Make the request + response = await client.create_tensorboard_experiment(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_CreateTensorboardExperiment_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_create_tensorboard_experiment_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_create_tensorboard_experiment_sync.py new file mode 100644 index 0000000000..2cf3eebfdd --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_create_tensorboard_experiment_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTensorboardExperiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_CreateTensorboardExperiment_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_tensorboard_experiment(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateTensorboardExperimentRequest( + parent="parent_value", + tensorboard_experiment_id="tensorboard_experiment_id_value", + ) + + # Make the request + response = client.create_tensorboard_experiment(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_CreateTensorboardExperiment_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_create_tensorboard_run_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_create_tensorboard_run_async.py new file mode 100644 index 0000000000..2ffdf1e9ff --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_create_tensorboard_run_async.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTensorboardRun +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_CreateTensorboardRun_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_tensorboard_run(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + tensorboard_run = aiplatform_v1beta1.TensorboardRun() + tensorboard_run.display_name = "display_name_value" + + request = aiplatform_v1beta1.CreateTensorboardRunRequest( + parent="parent_value", + tensorboard_run=tensorboard_run, + tensorboard_run_id="tensorboard_run_id_value", + ) + + # Make the request + response = await client.create_tensorboard_run(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_CreateTensorboardRun_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_create_tensorboard_run_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_create_tensorboard_run_sync.py new file mode 100644 index 0000000000..4565687250 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_create_tensorboard_run_sync.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTensorboardRun +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_CreateTensorboardRun_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_tensorboard_run(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + tensorboard_run = aiplatform_v1beta1.TensorboardRun() + tensorboard_run.display_name = "display_name_value" + + request = aiplatform_v1beta1.CreateTensorboardRunRequest( + parent="parent_value", + tensorboard_run=tensorboard_run, + tensorboard_run_id="tensorboard_run_id_value", + ) + + # Make the request + response = client.create_tensorboard_run(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_CreateTensorboardRun_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_create_tensorboard_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_create_tensorboard_sync.py new file mode 100644 index 0000000000..a6efda2c4c --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_create_tensorboard_sync.py @@ -0,0 +1,53 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTensorboard +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_CreateTensorboard_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_tensorboard(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + tensorboard = aiplatform_v1beta1.Tensorboard() + tensorboard.display_name = "display_name_value" + + request = aiplatform_v1beta1.CreateTensorboardRequest( + parent="parent_value", + tensorboard=tensorboard, + ) + + # Make the request + operation = client.create_tensorboard(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_CreateTensorboard_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_create_tensorboard_time_series_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_create_tensorboard_time_series_async.py new file mode 100644 index 0000000000..e1a431e5b6 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_create_tensorboard_time_series_async.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_CreateTensorboardTimeSeries_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_tensorboard_time_series(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + tensorboard_time_series = aiplatform_v1beta1.TensorboardTimeSeries() + tensorboard_time_series.display_name = "display_name_value" + tensorboard_time_series.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1beta1.CreateTensorboardTimeSeriesRequest( + parent="parent_value", + tensorboard_time_series=tensorboard_time_series, + ) + + # Make the request + response = await client.create_tensorboard_time_series(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_CreateTensorboardTimeSeries_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_create_tensorboard_time_series_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_create_tensorboard_time_series_sync.py new file mode 100644 index 0000000000..3be4868fdc --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_create_tensorboard_time_series_sync.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_CreateTensorboardTimeSeries_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_tensorboard_time_series(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + tensorboard_time_series = aiplatform_v1beta1.TensorboardTimeSeries() + tensorboard_time_series.display_name = "display_name_value" + tensorboard_time_series.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1beta1.CreateTensorboardTimeSeriesRequest( + parent="parent_value", + tensorboard_time_series=tensorboard_time_series, + ) + + # Make the request + response = client.create_tensorboard_time_series(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_CreateTensorboardTimeSeries_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_delete_tensorboard_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_delete_tensorboard_async.py new file mode 100644 index 0000000000..a4ee230dc7 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_delete_tensorboard_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTensorboard +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_DeleteTensorboard_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_tensorboard(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteTensorboardRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_DeleteTensorboard_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_delete_tensorboard_experiment_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_delete_tensorboard_experiment_async.py new file mode 100644 index 0000000000..963d006bb7 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_delete_tensorboard_experiment_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTensorboardExperiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_DeleteTensorboardExperiment_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_tensorboard_experiment(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteTensorboardExperimentRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard_experiment(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_DeleteTensorboardExperiment_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_delete_tensorboard_experiment_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_delete_tensorboard_experiment_sync.py new file mode 100644 index 0000000000..177d6794ed --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_delete_tensorboard_experiment_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTensorboardExperiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_DeleteTensorboardExperiment_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_tensorboard_experiment(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteTensorboardExperimentRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard_experiment(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_DeleteTensorboardExperiment_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_delete_tensorboard_run_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_delete_tensorboard_run_async.py new file mode 100644 index 0000000000..cb348a4d32 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_delete_tensorboard_run_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTensorboardRun +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_DeleteTensorboardRun_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_tensorboard_run(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteTensorboardRunRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard_run(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_DeleteTensorboardRun_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_delete_tensorboard_run_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_delete_tensorboard_run_sync.py new file mode 100644 index 0000000000..568ca24fe7 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_delete_tensorboard_run_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTensorboardRun +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_DeleteTensorboardRun_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_tensorboard_run(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteTensorboardRunRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard_run(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_DeleteTensorboardRun_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_delete_tensorboard_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_delete_tensorboard_sync.py new file mode 100644 index 0000000000..6acad89fed --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_delete_tensorboard_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTensorboard +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_DeleteTensorboard_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_tensorboard(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteTensorboardRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_DeleteTensorboard_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_delete_tensorboard_time_series_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_delete_tensorboard_time_series_async.py new file mode 100644 index 0000000000..d2835d55a8 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_delete_tensorboard_time_series_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_DeleteTensorboardTimeSeries_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_tensorboard_time_series(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteTensorboardTimeSeriesRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard_time_series(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_DeleteTensorboardTimeSeries_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_delete_tensorboard_time_series_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_delete_tensorboard_time_series_sync.py new file mode 100644 index 0000000000..d2889174eb --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_delete_tensorboard_time_series_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_DeleteTensorboardTimeSeries_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_tensorboard_time_series(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteTensorboardTimeSeriesRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard_time_series(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_DeleteTensorboardTimeSeries_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_export_tensorboard_time_series_data_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_export_tensorboard_time_series_data_async.py new file mode 100644 index 0000000000..cbe98ec9eb --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_export_tensorboard_time_series_data_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportTensorboardTimeSeriesData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_ExportTensorboardTimeSeriesData_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_export_tensorboard_time_series_data(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ExportTensorboardTimeSeriesDataRequest( + tensorboard_time_series="tensorboard_time_series_value", + ) + + # Make the request + page_result = client.export_tensorboard_time_series_data(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_ExportTensorboardTimeSeriesData_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_export_tensorboard_time_series_data_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_export_tensorboard_time_series_data_sync.py new file mode 100644 index 0000000000..61fa177cb8 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_export_tensorboard_time_series_data_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportTensorboardTimeSeriesData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_ExportTensorboardTimeSeriesData_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_export_tensorboard_time_series_data(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ExportTensorboardTimeSeriesDataRequest( + tensorboard_time_series="tensorboard_time_series_value", + ) + + # Make the request + page_result = client.export_tensorboard_time_series_data(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_ExportTensorboardTimeSeriesData_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_get_tensorboard_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_get_tensorboard_async.py new file mode 100644 index 0000000000..29ae4e3b08 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_get_tensorboard_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTensorboard +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_GetTensorboard_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_tensorboard(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetTensorboardRequest( + name="name_value", + ) + + # Make the request + response = await client.get_tensorboard(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_GetTensorboard_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_get_tensorboard_experiment_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_get_tensorboard_experiment_async.py new file mode 100644 index 0000000000..73870435e6 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_get_tensorboard_experiment_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTensorboardExperiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_GetTensorboardExperiment_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_tensorboard_experiment(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetTensorboardExperimentRequest( + name="name_value", + ) + + # Make the request + response = await client.get_tensorboard_experiment(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_GetTensorboardExperiment_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_get_tensorboard_experiment_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_get_tensorboard_experiment_sync.py new file mode 100644 index 0000000000..f9f2d042c6 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_get_tensorboard_experiment_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTensorboardExperiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_GetTensorboardExperiment_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_tensorboard_experiment(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetTensorboardExperimentRequest( + name="name_value", + ) + + # Make the request + response = client.get_tensorboard_experiment(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_GetTensorboardExperiment_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_get_tensorboard_run_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_get_tensorboard_run_async.py new file mode 100644 index 0000000000..5887016fc0 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_get_tensorboard_run_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTensorboardRun +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_GetTensorboardRun_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_tensorboard_run(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetTensorboardRunRequest( + name="name_value", + ) + + # Make the request + response = await client.get_tensorboard_run(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_GetTensorboardRun_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_get_tensorboard_run_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_get_tensorboard_run_sync.py new file mode 100644 index 0000000000..d8633272c3 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_get_tensorboard_run_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTensorboardRun +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_GetTensorboardRun_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_tensorboard_run(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetTensorboardRunRequest( + name="name_value", + ) + + # Make the request + response = client.get_tensorboard_run(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_GetTensorboardRun_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_get_tensorboard_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_get_tensorboard_sync.py new file mode 100644 index 0000000000..73b338d694 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_get_tensorboard_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTensorboard +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_GetTensorboard_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_tensorboard(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetTensorboardRequest( + name="name_value", + ) + + # Make the request + response = client.get_tensorboard(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_GetTensorboard_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_get_tensorboard_time_series_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_get_tensorboard_time_series_async.py new file mode 100644 index 0000000000..6777dde535 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_get_tensorboard_time_series_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_GetTensorboardTimeSeries_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_tensorboard_time_series(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetTensorboardTimeSeriesRequest( + name="name_value", + ) + + # Make the request + response = await client.get_tensorboard_time_series(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_GetTensorboardTimeSeries_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_get_tensorboard_time_series_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_get_tensorboard_time_series_sync.py new file mode 100644 index 0000000000..6a022fe9ff --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_get_tensorboard_time_series_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_GetTensorboardTimeSeries_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_tensorboard_time_series(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetTensorboardTimeSeriesRequest( + name="name_value", + ) + + # Make the request + response = client.get_tensorboard_time_series(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_GetTensorboardTimeSeries_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_list_tensorboard_experiments_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_list_tensorboard_experiments_async.py new file mode 100644 index 0000000000..ad45c40c17 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_list_tensorboard_experiments_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTensorboardExperiments +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_ListTensorboardExperiments_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_tensorboard_experiments(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListTensorboardExperimentsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboard_experiments(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_ListTensorboardExperiments_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_list_tensorboard_experiments_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_list_tensorboard_experiments_sync.py new file mode 100644 index 0000000000..4a35d020a3 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_list_tensorboard_experiments_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTensorboardExperiments +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_ListTensorboardExperiments_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_tensorboard_experiments(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListTensorboardExperimentsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboard_experiments(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_ListTensorboardExperiments_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_list_tensorboard_runs_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_list_tensorboard_runs_async.py new file mode 100644 index 0000000000..87a767c8f5 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_list_tensorboard_runs_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTensorboardRuns +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_ListTensorboardRuns_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_tensorboard_runs(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListTensorboardRunsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboard_runs(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_ListTensorboardRuns_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_list_tensorboard_runs_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_list_tensorboard_runs_sync.py new file mode 100644 index 0000000000..de8bc437e6 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_list_tensorboard_runs_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTensorboardRuns +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_ListTensorboardRuns_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_tensorboard_runs(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListTensorboardRunsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboard_runs(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_ListTensorboardRuns_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_list_tensorboard_time_series_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_list_tensorboard_time_series_async.py new file mode 100644 index 0000000000..a2c1694e5f --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_list_tensorboard_time_series_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_ListTensorboardTimeSeries_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_tensorboard_time_series(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListTensorboardTimeSeriesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboard_time_series(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_ListTensorboardTimeSeries_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_list_tensorboard_time_series_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_list_tensorboard_time_series_sync.py new file mode 100644 index 0000000000..fe73e6e77b --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_list_tensorboard_time_series_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_ListTensorboardTimeSeries_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_tensorboard_time_series(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListTensorboardTimeSeriesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboard_time_series(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_ListTensorboardTimeSeries_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_list_tensorboards_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_list_tensorboards_async.py new file mode 100644 index 0000000000..35ddbfac55 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_list_tensorboards_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTensorboards +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_ListTensorboards_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_tensorboards(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListTensorboardsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboards(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_ListTensorboards_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_list_tensorboards_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_list_tensorboards_sync.py new file mode 100644 index 0000000000..7a6ceb37d0 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_list_tensorboards_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTensorboards +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_ListTensorboards_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_tensorboards(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListTensorboardsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboards(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_ListTensorboards_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_read_tensorboard_blob_data_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_read_tensorboard_blob_data_async.py new file mode 100644 index 0000000000..cd8b5648c4 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_read_tensorboard_blob_data_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ReadTensorboardBlobData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_ReadTensorboardBlobData_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_read_tensorboard_blob_data(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ReadTensorboardBlobDataRequest( + time_series="time_series_value", + ) + + # Make the request + stream = await client.read_tensorboard_blob_data(request=request) + + # Handle the response + async for response in stream: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_ReadTensorboardBlobData_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_read_tensorboard_blob_data_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_read_tensorboard_blob_data_sync.py new file mode 100644 index 0000000000..fa0bca6c36 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_read_tensorboard_blob_data_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ReadTensorboardBlobData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_ReadTensorboardBlobData_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_read_tensorboard_blob_data(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ReadTensorboardBlobDataRequest( + time_series="time_series_value", + ) + + # Make the request + stream = client.read_tensorboard_blob_data(request=request) + + # Handle the response + for response in stream: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_ReadTensorboardBlobData_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_read_tensorboard_time_series_data_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_read_tensorboard_time_series_data_async.py new file mode 100644 index 0000000000..4c2e200cc6 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_read_tensorboard_time_series_data_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ReadTensorboardTimeSeriesData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_ReadTensorboardTimeSeriesData_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_read_tensorboard_time_series_data(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ReadTensorboardTimeSeriesDataRequest( + tensorboard_time_series="tensorboard_time_series_value", + ) + + # Make the request + response = await client.read_tensorboard_time_series_data(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_ReadTensorboardTimeSeriesData_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_read_tensorboard_time_series_data_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_read_tensorboard_time_series_data_sync.py new file mode 100644 index 0000000000..23c4720b26 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_read_tensorboard_time_series_data_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ReadTensorboardTimeSeriesData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_ReadTensorboardTimeSeriesData_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_read_tensorboard_time_series_data(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ReadTensorboardTimeSeriesDataRequest( + tensorboard_time_series="tensorboard_time_series_value", + ) + + # Make the request + response = client.read_tensorboard_time_series_data(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_ReadTensorboardTimeSeriesData_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_update_tensorboard_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_update_tensorboard_async.py new file mode 100644 index 0000000000..1aac60a34c --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_update_tensorboard_async.py @@ -0,0 +1,52 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateTensorboard +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_UpdateTensorboard_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_update_tensorboard(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + tensorboard = aiplatform_v1beta1.Tensorboard() + tensorboard.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateTensorboardRequest( + tensorboard=tensorboard, + ) + + # Make the request + operation = client.update_tensorboard(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_UpdateTensorboard_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_update_tensorboard_experiment_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_update_tensorboard_experiment_async.py new file mode 100644 index 0000000000..b547eab8af --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_update_tensorboard_experiment_async.py @@ -0,0 +1,44 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateTensorboardExperiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_UpdateTensorboardExperiment_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_update_tensorboard_experiment(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateTensorboardExperimentRequest( + ) + + # Make the request + response = await client.update_tensorboard_experiment(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_UpdateTensorboardExperiment_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_update_tensorboard_experiment_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_update_tensorboard_experiment_sync.py new file mode 100644 index 0000000000..1e02a6a159 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_update_tensorboard_experiment_sync.py @@ -0,0 +1,44 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateTensorboardExperiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_UpdateTensorboardExperiment_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_update_tensorboard_experiment(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateTensorboardExperimentRequest( + ) + + # Make the request + response = client.update_tensorboard_experiment(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_UpdateTensorboardExperiment_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_update_tensorboard_run_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_update_tensorboard_run_async.py new file mode 100644 index 0000000000..c4d780773e --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_update_tensorboard_run_async.py @@ -0,0 +1,48 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateTensorboardRun +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_UpdateTensorboardRun_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_update_tensorboard_run(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + tensorboard_run = aiplatform_v1beta1.TensorboardRun() + tensorboard_run.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateTensorboardRunRequest( + tensorboard_run=tensorboard_run, + ) + + # Make the request + response = await client.update_tensorboard_run(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_UpdateTensorboardRun_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_update_tensorboard_run_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_update_tensorboard_run_sync.py new file mode 100644 index 0000000000..2e0c73249d --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_update_tensorboard_run_sync.py @@ -0,0 +1,48 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateTensorboardRun +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_UpdateTensorboardRun_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_update_tensorboard_run(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + tensorboard_run = aiplatform_v1beta1.TensorboardRun() + tensorboard_run.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateTensorboardRunRequest( + tensorboard_run=tensorboard_run, + ) + + # Make the request + response = client.update_tensorboard_run(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_UpdateTensorboardRun_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_update_tensorboard_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_update_tensorboard_sync.py new file mode 100644 index 0000000000..60a15a42aa --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_update_tensorboard_sync.py @@ -0,0 +1,52 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateTensorboard +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_UpdateTensorboard_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_update_tensorboard(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + tensorboard = aiplatform_v1beta1.Tensorboard() + tensorboard.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateTensorboardRequest( + tensorboard=tensorboard, + ) + + # Make the request + operation = client.update_tensorboard(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_UpdateTensorboard_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_update_tensorboard_time_series_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_update_tensorboard_time_series_async.py new file mode 100644 index 0000000000..702d5aa37c --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_update_tensorboard_time_series_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_UpdateTensorboardTimeSeries_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_update_tensorboard_time_series(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + tensorboard_time_series = aiplatform_v1beta1.TensorboardTimeSeries() + tensorboard_time_series.display_name = "display_name_value" + tensorboard_time_series.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1beta1.UpdateTensorboardTimeSeriesRequest( + tensorboard_time_series=tensorboard_time_series, + ) + + # Make the request + response = await client.update_tensorboard_time_series(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_UpdateTensorboardTimeSeries_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_update_tensorboard_time_series_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_update_tensorboard_time_series_sync.py new file mode 100644 index 0000000000..4828d30d3e --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_update_tensorboard_time_series_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_UpdateTensorboardTimeSeries_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_update_tensorboard_time_series(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + tensorboard_time_series = aiplatform_v1beta1.TensorboardTimeSeries() + tensorboard_time_series.display_name = "display_name_value" + tensorboard_time_series.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1beta1.UpdateTensorboardTimeSeriesRequest( + tensorboard_time_series=tensorboard_time_series, + ) + + # Make the request + response = client.update_tensorboard_time_series(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_UpdateTensorboardTimeSeries_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_write_tensorboard_experiment_data_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_write_tensorboard_experiment_data_async.py new file mode 100644 index 0000000000..a8922a6150 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_write_tensorboard_experiment_data_async.py @@ -0,0 +1,51 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for WriteTensorboardExperimentData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_WriteTensorboardExperimentData_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_write_tensorboard_experiment_data(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + write_run_data_requests = aiplatform_v1beta1.WriteTensorboardRunDataRequest() + write_run_data_requests.tensorboard_run = "tensorboard_run_value" + write_run_data_requests.time_series_data.tensorboard_time_series_id = "tensorboard_time_series_id_value" + write_run_data_requests.time_series_data.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1beta1.WriteTensorboardExperimentDataRequest( + tensorboard_experiment="tensorboard_experiment_value", + write_run_data_requests=write_run_data_requests, + ) + + # Make the request + response = await client.write_tensorboard_experiment_data(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_WriteTensorboardExperimentData_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_write_tensorboard_experiment_data_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_write_tensorboard_experiment_data_sync.py new file mode 100644 index 0000000000..a88f5f049c --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_write_tensorboard_experiment_data_sync.py @@ -0,0 +1,51 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for WriteTensorboardExperimentData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_WriteTensorboardExperimentData_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_write_tensorboard_experiment_data(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + write_run_data_requests = aiplatform_v1beta1.WriteTensorboardRunDataRequest() + write_run_data_requests.tensorboard_run = "tensorboard_run_value" + write_run_data_requests.time_series_data.tensorboard_time_series_id = "tensorboard_time_series_id_value" + write_run_data_requests.time_series_data.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1beta1.WriteTensorboardExperimentDataRequest( + tensorboard_experiment="tensorboard_experiment_value", + write_run_data_requests=write_run_data_requests, + ) + + # Make the request + response = client.write_tensorboard_experiment_data(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_WriteTensorboardExperimentData_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_write_tensorboard_run_data_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_write_tensorboard_run_data_async.py new file mode 100644 index 0000000000..384cd87687 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_write_tensorboard_run_data_async.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for WriteTensorboardRunData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_WriteTensorboardRunData_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_write_tensorboard_run_data(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + time_series_data = aiplatform_v1beta1.TimeSeriesData() + time_series_data.tensorboard_time_series_id = "tensorboard_time_series_id_value" + time_series_data.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1beta1.WriteTensorboardRunDataRequest( + tensorboard_run="tensorboard_run_value", + time_series_data=time_series_data, + ) + + # Make the request + response = await client.write_tensorboard_run_data(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_WriteTensorboardRunData_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_write_tensorboard_run_data_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_write_tensorboard_run_data_sync.py new file mode 100644 index 0000000000..95ef91910e --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_tensorboard_service_write_tensorboard_run_data_sync.py @@ -0,0 +1,50 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for WriteTensorboardRunData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_TensorboardService_WriteTensorboardRunData_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_write_tensorboard_run_data(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + time_series_data = aiplatform_v1beta1.TimeSeriesData() + time_series_data.tensorboard_time_series_id = "tensorboard_time_series_id_value" + time_series_data.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1beta1.WriteTensorboardRunDataRequest( + tensorboard_run="tensorboard_run_value", + time_series_data=time_series_data, + ) + + # Make the request + response = client.write_tensorboard_run_data(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_TensorboardService_WriteTensorboardRunData_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_add_trial_measurement_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_add_trial_measurement_async.py new file mode 100644 index 0000000000..6c6a275975 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_add_trial_measurement_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddTrialMeasurement +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_VizierService_AddTrialMeasurement_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_add_trial_measurement(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.AddTrialMeasurementRequest( + trial_name="trial_name_value", + ) + + # Make the request + response = await client.add_trial_measurement(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_VizierService_AddTrialMeasurement_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_add_trial_measurement_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_add_trial_measurement_sync.py new file mode 100644 index 0000000000..4af1238908 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_add_trial_measurement_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddTrialMeasurement +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_VizierService_AddTrialMeasurement_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_add_trial_measurement(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.AddTrialMeasurementRequest( + trial_name="trial_name_value", + ) + + # Make the request + response = client.add_trial_measurement(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_VizierService_AddTrialMeasurement_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_check_trial_early_stopping_state_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_check_trial_early_stopping_state_async.py new file mode 100644 index 0000000000..9fa6315e86 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_check_trial_early_stopping_state_async.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CheckTrialEarlyStoppingState +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_VizierService_CheckTrialEarlyStoppingState_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_check_trial_early_stopping_state(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CheckTrialEarlyStoppingStateRequest( + trial_name="trial_name_value", + ) + + # Make the request + operation = client.check_trial_early_stopping_state(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_VizierService_CheckTrialEarlyStoppingState_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_check_trial_early_stopping_state_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_check_trial_early_stopping_state_sync.py new file mode 100644 index 0000000000..46227517cc --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_check_trial_early_stopping_state_sync.py @@ -0,0 +1,49 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CheckTrialEarlyStoppingState +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_VizierService_CheckTrialEarlyStoppingState_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_check_trial_early_stopping_state(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CheckTrialEarlyStoppingStateRequest( + trial_name="trial_name_value", + ) + + # Make the request + operation = client.check_trial_early_stopping_state(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_VizierService_CheckTrialEarlyStoppingState_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_complete_trial_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_complete_trial_async.py new file mode 100644 index 0000000000..0ce1d74398 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_complete_trial_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CompleteTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_VizierService_CompleteTrial_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_complete_trial(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CompleteTrialRequest( + name="name_value", + ) + + # Make the request + response = await client.complete_trial(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_VizierService_CompleteTrial_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_complete_trial_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_complete_trial_sync.py new file mode 100644 index 0000000000..9be064f14e --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_complete_trial_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CompleteTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_VizierService_CompleteTrial_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_complete_trial(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CompleteTrialRequest( + name="name_value", + ) + + # Make the request + response = client.complete_trial(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_VizierService_CompleteTrial_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_create_study_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_create_study_async.py new file mode 100644 index 0000000000..54e6276554 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_create_study_async.py @@ -0,0 +1,54 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateStudy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_VizierService_CreateStudy_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_study(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + study = aiplatform_v1beta1.Study() + study.display_name = "display_name_value" + study.study_spec.metrics.metric_id = "metric_id_value" + study.study_spec.metrics.goal = "MINIMIZE" + study.study_spec.parameters.double_value_spec.min_value = 0.96 + study.study_spec.parameters.double_value_spec.max_value = 0.962 + study.study_spec.parameters.parameter_id = "parameter_id_value" + + request = aiplatform_v1beta1.CreateStudyRequest( + parent="parent_value", + study=study, + ) + + # Make the request + response = await client.create_study(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_VizierService_CreateStudy_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_create_study_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_create_study_sync.py new file mode 100644 index 0000000000..490f7a685e --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_create_study_sync.py @@ -0,0 +1,54 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateStudy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_VizierService_CreateStudy_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_study(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + study = aiplatform_v1beta1.Study() + study.display_name = "display_name_value" + study.study_spec.metrics.metric_id = "metric_id_value" + study.study_spec.metrics.goal = "MINIMIZE" + study.study_spec.parameters.double_value_spec.min_value = 0.96 + study.study_spec.parameters.double_value_spec.max_value = 0.962 + study.study_spec.parameters.parameter_id = "parameter_id_value" + + request = aiplatform_v1beta1.CreateStudyRequest( + parent="parent_value", + study=study, + ) + + # Make the request + response = client.create_study(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_VizierService_CreateStudy_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_create_trial_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_create_trial_async.py new file mode 100644 index 0000000000..63141263c7 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_create_trial_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_VizierService_CreateTrial_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_trial(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateTrialRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_trial(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_VizierService_CreateTrial_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_create_trial_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_create_trial_sync.py new file mode 100644 index 0000000000..d4c3826f27 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_create_trial_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_VizierService_CreateTrial_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_trial(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateTrialRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_trial(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_VizierService_CreateTrial_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_delete_study_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_delete_study_async.py new file mode 100644 index 0000000000..64e39de371 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_delete_study_async.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteStudy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_VizierService_DeleteStudy_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_study(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteStudyRequest( + name="name_value", + ) + + # Make the request + await client.delete_study(request=request) + + +# [END aiplatform_generated_aiplatform_v1beta1_VizierService_DeleteStudy_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_delete_study_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_delete_study_sync.py new file mode 100644 index 0000000000..1e7f9f76dc --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_delete_study_sync.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteStudy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_VizierService_DeleteStudy_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_study(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteStudyRequest( + name="name_value", + ) + + # Make the request + client.delete_study(request=request) + + +# [END aiplatform_generated_aiplatform_v1beta1_VizierService_DeleteStudy_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_delete_trial_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_delete_trial_async.py new file mode 100644 index 0000000000..9be5bdc1ed --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_delete_trial_async.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_VizierService_DeleteTrial_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_trial(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteTrialRequest( + name="name_value", + ) + + # Make the request + await client.delete_trial(request=request) + + +# [END aiplatform_generated_aiplatform_v1beta1_VizierService_DeleteTrial_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_delete_trial_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_delete_trial_sync.py new file mode 100644 index 0000000000..34fce74d4d --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_delete_trial_sync.py @@ -0,0 +1,43 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_VizierService_DeleteTrial_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_trial(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteTrialRequest( + name="name_value", + ) + + # Make the request + client.delete_trial(request=request) + + +# [END aiplatform_generated_aiplatform_v1beta1_VizierService_DeleteTrial_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_get_study_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_get_study_async.py new file mode 100644 index 0000000000..7752bfaa85 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_get_study_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetStudy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_VizierService_GetStudy_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_study(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetStudyRequest( + name="name_value", + ) + + # Make the request + response = await client.get_study(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_VizierService_GetStudy_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_get_study_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_get_study_sync.py new file mode 100644 index 0000000000..c7e2477bf4 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_get_study_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetStudy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_VizierService_GetStudy_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_study(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetStudyRequest( + name="name_value", + ) + + # Make the request + response = client.get_study(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_VizierService_GetStudy_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_get_trial_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_get_trial_async.py new file mode 100644 index 0000000000..9dc6b493e8 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_get_trial_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_VizierService_GetTrial_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_trial(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetTrialRequest( + name="name_value", + ) + + # Make the request + response = await client.get_trial(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_VizierService_GetTrial_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_get_trial_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_get_trial_sync.py new file mode 100644 index 0000000000..298c5c4e6d --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_get_trial_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_VizierService_GetTrial_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_trial(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetTrialRequest( + name="name_value", + ) + + # Make the request + response = client.get_trial(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_VizierService_GetTrial_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_list_optimal_trials_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_list_optimal_trials_async.py new file mode 100644 index 0000000000..51560cd7b2 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_list_optimal_trials_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListOptimalTrials +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_VizierService_ListOptimalTrials_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_optimal_trials(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListOptimalTrialsRequest( + parent="parent_value", + ) + + # Make the request + response = await client.list_optimal_trials(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_VizierService_ListOptimalTrials_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_list_optimal_trials_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_list_optimal_trials_sync.py new file mode 100644 index 0000000000..110990e99b --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_list_optimal_trials_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListOptimalTrials +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_VizierService_ListOptimalTrials_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_optimal_trials(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListOptimalTrialsRequest( + parent="parent_value", + ) + + # Make the request + response = client.list_optimal_trials(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_VizierService_ListOptimalTrials_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_list_studies_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_list_studies_async.py new file mode 100644 index 0000000000..a09c7c410b --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_list_studies_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListStudies +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_VizierService_ListStudies_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_studies(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListStudiesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_studies(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_VizierService_ListStudies_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_list_studies_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_list_studies_sync.py new file mode 100644 index 0000000000..12285eb733 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_list_studies_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListStudies +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_VizierService_ListStudies_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_studies(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListStudiesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_studies(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_VizierService_ListStudies_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_list_trials_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_list_trials_async.py new file mode 100644 index 0000000000..c61bbc499b --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_list_trials_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTrials +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_VizierService_ListTrials_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_trials(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListTrialsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_trials(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_VizierService_ListTrials_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_list_trials_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_list_trials_sync.py new file mode 100644 index 0000000000..fdc006231a --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_list_trials_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTrials +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_VizierService_ListTrials_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_trials(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListTrialsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_trials(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_VizierService_ListTrials_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_lookup_study_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_lookup_study_async.py new file mode 100644 index 0000000000..08261c53f1 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_lookup_study_async.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for LookupStudy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_VizierService_LookupStudy_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_lookup_study(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.LookupStudyRequest( + parent="parent_value", + display_name="display_name_value", + ) + + # Make the request + response = await client.lookup_study(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_VizierService_LookupStudy_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_lookup_study_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_lookup_study_sync.py new file mode 100644 index 0000000000..fb7242f8a5 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_lookup_study_sync.py @@ -0,0 +1,46 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for LookupStudy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_VizierService_LookupStudy_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_lookup_study(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.LookupStudyRequest( + parent="parent_value", + display_name="display_name_value", + ) + + # Make the request + response = client.lookup_study(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_VizierService_LookupStudy_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_stop_trial_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_stop_trial_async.py new file mode 100644 index 0000000000..3f87e48b7d --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_stop_trial_async.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for StopTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_VizierService_StopTrial_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_stop_trial(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.StopTrialRequest( + name="name_value", + ) + + # Make the request + response = await client.stop_trial(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_VizierService_StopTrial_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_stop_trial_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_stop_trial_sync.py new file mode 100644 index 0000000000..6ccc3ed2fa --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_stop_trial_sync.py @@ -0,0 +1,45 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for StopTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_VizierService_StopTrial_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_stop_trial(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.StopTrialRequest( + name="name_value", + ) + + # Make the request + response = client.stop_trial(request=request) + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_VizierService_StopTrial_sync] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_suggest_trials_async.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_suggest_trials_async.py new file mode 100644 index 0000000000..87910c8156 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_suggest_trials_async.py @@ -0,0 +1,51 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SuggestTrials +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_VizierService_SuggestTrials_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_suggest_trials(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.SuggestTrialsRequest( + parent="parent_value", + suggestion_count=1744, + client_id="client_id_value", + ) + + # Make the request + operation = client.suggest_trials(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_VizierService_SuggestTrials_async] diff --git a/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_suggest_trials_sync.py b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_suggest_trials_sync.py new file mode 100644 index 0000000000..2ed4076392 --- /dev/null +++ b/samples/generated_samples/aiplatform_generated_aiplatform_v1beta1_vizier_service_suggest_trials_sync.py @@ -0,0 +1,51 @@ +# -*- 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SuggestTrials +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_generated_aiplatform_v1beta1_VizierService_SuggestTrials_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_suggest_trials(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.SuggestTrialsRequest( + parent="parent_value", + suggestion_count=1744, + client_id="client_id_value", + ) + + # Make the request + operation = client.suggest_trials(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_generated_aiplatform_v1beta1_VizierService_SuggestTrials_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_dataset_service_create_dataset_async.py b/samples/generated_samples/aiplatform_v1_generated_dataset_service_create_dataset_async.py new file mode 100644 index 0000000000..34d2c2cb05 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_dataset_service_create_dataset_async.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateDataset +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_DatasetService_CreateDataset_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_dataset(): + # Create a client + client = aiplatform_v1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + dataset = aiplatform_v1.Dataset() + dataset.display_name = "display_name_value" + dataset.metadata_schema_uri = "metadata_schema_uri_value" + dataset.metadata.null_value = "NULL_VALUE" + + request = aiplatform_v1.CreateDatasetRequest( + parent="parent_value", + dataset=dataset, + ) + + # Make the request + operation = client.create_dataset(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_DatasetService_CreateDataset_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_dataset_service_create_dataset_sync.py b/samples/generated_samples/aiplatform_v1_generated_dataset_service_create_dataset_sync.py new file mode 100644 index 0000000000..d8756ab0e7 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_dataset_service_create_dataset_sync.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateDataset +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_DatasetService_CreateDataset_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_dataset(): + # Create a client + client = aiplatform_v1.DatasetServiceClient() + + # Initialize request argument(s) + dataset = aiplatform_v1.Dataset() + dataset.display_name = "display_name_value" + dataset.metadata_schema_uri = "metadata_schema_uri_value" + dataset.metadata.null_value = "NULL_VALUE" + + request = aiplatform_v1.CreateDatasetRequest( + parent="parent_value", + dataset=dataset, + ) + + # Make the request + operation = client.create_dataset(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_DatasetService_CreateDataset_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_dataset_service_delete_dataset_async.py b/samples/generated_samples/aiplatform_v1_generated_dataset_service_delete_dataset_async.py new file mode 100644 index 0000000000..8a9f058d17 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_dataset_service_delete_dataset_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteDataset +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_DatasetService_DeleteDataset_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_dataset(): + # Create a client + client = aiplatform_v1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteDatasetRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_dataset(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_DatasetService_DeleteDataset_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_dataset_service_delete_dataset_sync.py b/samples/generated_samples/aiplatform_v1_generated_dataset_service_delete_dataset_sync.py new file mode 100644 index 0000000000..b8d91fac1f --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_dataset_service_delete_dataset_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteDataset +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_DatasetService_DeleteDataset_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_dataset(): + # Create a client + client = aiplatform_v1.DatasetServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteDatasetRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_dataset(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_DatasetService_DeleteDataset_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_dataset_service_export_data_async.py b/samples/generated_samples/aiplatform_v1_generated_dataset_service_export_data_async.py new file mode 100644 index 0000000000..c3f18a5e52 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_dataset_service_export_data_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_DatasetService_ExportData_async] +from google.cloud import aiplatform_v1 + + +async def sample_export_data(): + # Create a client + client = aiplatform_v1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + export_config = aiplatform_v1.ExportDataConfig() + export_config.gcs_destination.output_uri_prefix = "output_uri_prefix_value" + + request = aiplatform_v1.ExportDataRequest( + name="name_value", + export_config=export_config, + ) + + # Make the request + operation = client.export_data(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_DatasetService_ExportData_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_dataset_service_export_data_sync.py b/samples/generated_samples/aiplatform_v1_generated_dataset_service_export_data_sync.py new file mode 100644 index 0000000000..bf501e1f3f --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_dataset_service_export_data_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_DatasetService_ExportData_sync] +from google.cloud import aiplatform_v1 + + +def sample_export_data(): + # Create a client + client = aiplatform_v1.DatasetServiceClient() + + # Initialize request argument(s) + export_config = aiplatform_v1.ExportDataConfig() + export_config.gcs_destination.output_uri_prefix = "output_uri_prefix_value" + + request = aiplatform_v1.ExportDataRequest( + name="name_value", + export_config=export_config, + ) + + # Make the request + operation = client.export_data(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_DatasetService_ExportData_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_dataset_service_get_annotation_spec_async.py b/samples/generated_samples/aiplatform_v1_generated_dataset_service_get_annotation_spec_async.py new file mode 100644 index 0000000000..1e56b2e25b --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_dataset_service_get_annotation_spec_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetAnnotationSpec +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_DatasetService_GetAnnotationSpec_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_annotation_spec(): + # Create a client + client = aiplatform_v1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetAnnotationSpecRequest( + name="name_value", + ) + + # Make the request + response = await client.get_annotation_spec(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_DatasetService_GetAnnotationSpec_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_dataset_service_get_annotation_spec_sync.py b/samples/generated_samples/aiplatform_v1_generated_dataset_service_get_annotation_spec_sync.py new file mode 100644 index 0000000000..74ace5d895 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_dataset_service_get_annotation_spec_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetAnnotationSpec +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_DatasetService_GetAnnotationSpec_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_annotation_spec(): + # Create a client + client = aiplatform_v1.DatasetServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetAnnotationSpecRequest( + name="name_value", + ) + + # Make the request + response = client.get_annotation_spec(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_DatasetService_GetAnnotationSpec_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_dataset_service_get_dataset_async.py b/samples/generated_samples/aiplatform_v1_generated_dataset_service_get_dataset_async.py new file mode 100644 index 0000000000..3f8f590106 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_dataset_service_get_dataset_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetDataset +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_DatasetService_GetDataset_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_dataset(): + # Create a client + client = aiplatform_v1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetDatasetRequest( + name="name_value", + ) + + # Make the request + response = await client.get_dataset(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_DatasetService_GetDataset_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_dataset_service_get_dataset_sync.py b/samples/generated_samples/aiplatform_v1_generated_dataset_service_get_dataset_sync.py new file mode 100644 index 0000000000..21ded79723 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_dataset_service_get_dataset_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetDataset +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_DatasetService_GetDataset_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_dataset(): + # Create a client + client = aiplatform_v1.DatasetServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetDatasetRequest( + name="name_value", + ) + + # Make the request + response = client.get_dataset(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_DatasetService_GetDataset_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_dataset_service_import_data_async.py b/samples/generated_samples/aiplatform_v1_generated_dataset_service_import_data_async.py new file mode 100644 index 0000000000..7ecfbdb59d --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_dataset_service_import_data_async.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ImportData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_DatasetService_ImportData_async] +from google.cloud import aiplatform_v1 + + +async def sample_import_data(): + # Create a client + client = aiplatform_v1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + import_configs = aiplatform_v1.ImportDataConfig() + import_configs.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + import_configs.import_schema_uri = "import_schema_uri_value" + + request = aiplatform_v1.ImportDataRequest( + name="name_value", + import_configs=import_configs, + ) + + # Make the request + operation = client.import_data(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_DatasetService_ImportData_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_dataset_service_import_data_sync.py b/samples/generated_samples/aiplatform_v1_generated_dataset_service_import_data_sync.py new file mode 100644 index 0000000000..2e0cced2ad --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_dataset_service_import_data_sync.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ImportData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_DatasetService_ImportData_sync] +from google.cloud import aiplatform_v1 + + +def sample_import_data(): + # Create a client + client = aiplatform_v1.DatasetServiceClient() + + # Initialize request argument(s) + import_configs = aiplatform_v1.ImportDataConfig() + import_configs.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + import_configs.import_schema_uri = "import_schema_uri_value" + + request = aiplatform_v1.ImportDataRequest( + name="name_value", + import_configs=import_configs, + ) + + # Make the request + operation = client.import_data(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_DatasetService_ImportData_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_dataset_service_list_annotations_async.py b/samples/generated_samples/aiplatform_v1_generated_dataset_service_list_annotations_async.py new file mode 100644 index 0000000000..3d0ee2fc8d --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_dataset_service_list_annotations_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListAnnotations +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_DatasetService_ListAnnotations_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_annotations(): + # Create a client + client = aiplatform_v1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListAnnotationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_annotations(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1_generated_DatasetService_ListAnnotations_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_dataset_service_list_annotations_sync.py b/samples/generated_samples/aiplatform_v1_generated_dataset_service_list_annotations_sync.py new file mode 100644 index 0000000000..e476b1c5f5 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_dataset_service_list_annotations_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListAnnotations +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_DatasetService_ListAnnotations_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_annotations(): + # Create a client + client = aiplatform_v1.DatasetServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListAnnotationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_annotations(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1_generated_DatasetService_ListAnnotations_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_dataset_service_list_data_items_async.py b/samples/generated_samples/aiplatform_v1_generated_dataset_service_list_data_items_async.py new file mode 100644 index 0000000000..2de31c8715 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_dataset_service_list_data_items_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDataItems +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_DatasetService_ListDataItems_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_data_items(): + # Create a client + client = aiplatform_v1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListDataItemsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_data_items(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1_generated_DatasetService_ListDataItems_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_dataset_service_list_data_items_sync.py b/samples/generated_samples/aiplatform_v1_generated_dataset_service_list_data_items_sync.py new file mode 100644 index 0000000000..2cb7f59d01 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_dataset_service_list_data_items_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDataItems +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_DatasetService_ListDataItems_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_data_items(): + # Create a client + client = aiplatform_v1.DatasetServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListDataItemsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_data_items(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1_generated_DatasetService_ListDataItems_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_dataset_service_list_datasets_async.py b/samples/generated_samples/aiplatform_v1_generated_dataset_service_list_datasets_async.py new file mode 100644 index 0000000000..7a634e82b2 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_dataset_service_list_datasets_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDatasets +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_DatasetService_ListDatasets_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_datasets(): + # Create a client + client = aiplatform_v1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListDatasetsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_datasets(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1_generated_DatasetService_ListDatasets_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_dataset_service_list_datasets_sync.py b/samples/generated_samples/aiplatform_v1_generated_dataset_service_list_datasets_sync.py new file mode 100644 index 0000000000..5934bde144 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_dataset_service_list_datasets_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDatasets +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_DatasetService_ListDatasets_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_datasets(): + # Create a client + client = aiplatform_v1.DatasetServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListDatasetsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_datasets(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1_generated_DatasetService_ListDatasets_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_dataset_service_update_dataset_async.py b/samples/generated_samples/aiplatform_v1_generated_dataset_service_update_dataset_async.py new file mode 100644 index 0000000000..1fea8b45c3 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_dataset_service_update_dataset_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateDataset +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_DatasetService_UpdateDataset_async] +from google.cloud import aiplatform_v1 + + +async def sample_update_dataset(): + # Create a client + client = aiplatform_v1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + dataset = aiplatform_v1.Dataset() + dataset.display_name = "display_name_value" + dataset.metadata_schema_uri = "metadata_schema_uri_value" + dataset.metadata.null_value = "NULL_VALUE" + + request = aiplatform_v1.UpdateDatasetRequest( + dataset=dataset, + ) + + # Make the request + response = await client.update_dataset(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_DatasetService_UpdateDataset_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_dataset_service_update_dataset_sync.py b/samples/generated_samples/aiplatform_v1_generated_dataset_service_update_dataset_sync.py new file mode 100644 index 0000000000..170b3939d8 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_dataset_service_update_dataset_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateDataset +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_DatasetService_UpdateDataset_sync] +from google.cloud import aiplatform_v1 + + +def sample_update_dataset(): + # Create a client + client = aiplatform_v1.DatasetServiceClient() + + # Initialize request argument(s) + dataset = aiplatform_v1.Dataset() + dataset.display_name = "display_name_value" + dataset.metadata_schema_uri = "metadata_schema_uri_value" + dataset.metadata.null_value = "NULL_VALUE" + + request = aiplatform_v1.UpdateDatasetRequest( + dataset=dataset, + ) + + # Make the request + response = client.update_dataset(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_DatasetService_UpdateDataset_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_endpoint_service_create_endpoint_async.py b/samples/generated_samples/aiplatform_v1_generated_endpoint_service_create_endpoint_async.py new file mode 100644 index 0000000000..bc238c831a --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_endpoint_service_create_endpoint_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_EndpointService_CreateEndpoint_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_endpoint(): + # Create a client + client = aiplatform_v1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + endpoint = aiplatform_v1.Endpoint() + endpoint.display_name = "display_name_value" + + request = aiplatform_v1.CreateEndpointRequest( + parent="parent_value", + endpoint=endpoint, + ) + + # Make the request + operation = client.create_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_EndpointService_CreateEndpoint_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_endpoint_service_create_endpoint_sync.py b/samples/generated_samples/aiplatform_v1_generated_endpoint_service_create_endpoint_sync.py new file mode 100644 index 0000000000..81a24e5df0 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_endpoint_service_create_endpoint_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_EndpointService_CreateEndpoint_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_endpoint(): + # Create a client + client = aiplatform_v1.EndpointServiceClient() + + # Initialize request argument(s) + endpoint = aiplatform_v1.Endpoint() + endpoint.display_name = "display_name_value" + + request = aiplatform_v1.CreateEndpointRequest( + parent="parent_value", + endpoint=endpoint, + ) + + # Make the request + operation = client.create_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_EndpointService_CreateEndpoint_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_endpoint_service_delete_endpoint_async.py b/samples/generated_samples/aiplatform_v1_generated_endpoint_service_delete_endpoint_async.py new file mode 100644 index 0000000000..da1f35430b --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_endpoint_service_delete_endpoint_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_EndpointService_DeleteEndpoint_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_endpoint(): + # Create a client + client = aiplatform_v1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteEndpointRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_EndpointService_DeleteEndpoint_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_endpoint_service_delete_endpoint_sync.py b/samples/generated_samples/aiplatform_v1_generated_endpoint_service_delete_endpoint_sync.py new file mode 100644 index 0000000000..7042baedf8 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_endpoint_service_delete_endpoint_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_EndpointService_DeleteEndpoint_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_endpoint(): + # Create a client + client = aiplatform_v1.EndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteEndpointRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_EndpointService_DeleteEndpoint_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_endpoint_service_deploy_model_async.py b/samples/generated_samples/aiplatform_v1_generated_endpoint_service_deploy_model_async.py new file mode 100644 index 0000000000..9610eae986 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_endpoint_service_deploy_model_async.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeployModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_EndpointService_DeployModel_async] +from google.cloud import aiplatform_v1 + + +async def sample_deploy_model(): + # Create a client + client = aiplatform_v1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + deployed_model = aiplatform_v1.DeployedModel() + deployed_model.dedicated_resources.min_replica_count = 1803 + deployed_model.model = "model_value" + + request = aiplatform_v1.DeployModelRequest( + endpoint="endpoint_value", + deployed_model=deployed_model, + ) + + # Make the request + operation = client.deploy_model(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_EndpointService_DeployModel_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_endpoint_service_deploy_model_sync.py b/samples/generated_samples/aiplatform_v1_generated_endpoint_service_deploy_model_sync.py new file mode 100644 index 0000000000..448585048b --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_endpoint_service_deploy_model_sync.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeployModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_EndpointService_DeployModel_sync] +from google.cloud import aiplatform_v1 + + +def sample_deploy_model(): + # Create a client + client = aiplatform_v1.EndpointServiceClient() + + # Initialize request argument(s) + deployed_model = aiplatform_v1.DeployedModel() + deployed_model.dedicated_resources.min_replica_count = 1803 + deployed_model.model = "model_value" + + request = aiplatform_v1.DeployModelRequest( + endpoint="endpoint_value", + deployed_model=deployed_model, + ) + + # Make the request + operation = client.deploy_model(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_EndpointService_DeployModel_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_endpoint_service_get_endpoint_async.py b/samples/generated_samples/aiplatform_v1_generated_endpoint_service_get_endpoint_async.py new file mode 100644 index 0000000000..741a75dbdd --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_endpoint_service_get_endpoint_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_EndpointService_GetEndpoint_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_endpoint(): + # Create a client + client = aiplatform_v1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetEndpointRequest( + name="name_value", + ) + + # Make the request + response = await client.get_endpoint(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_EndpointService_GetEndpoint_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_endpoint_service_get_endpoint_sync.py b/samples/generated_samples/aiplatform_v1_generated_endpoint_service_get_endpoint_sync.py new file mode 100644 index 0000000000..7a39004427 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_endpoint_service_get_endpoint_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_EndpointService_GetEndpoint_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_endpoint(): + # Create a client + client = aiplatform_v1.EndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetEndpointRequest( + name="name_value", + ) + + # Make the request + response = client.get_endpoint(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_EndpointService_GetEndpoint_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_endpoint_service_list_endpoints_async.py b/samples/generated_samples/aiplatform_v1_generated_endpoint_service_list_endpoints_async.py new file mode 100644 index 0000000000..297abfff5a --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_endpoint_service_list_endpoints_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListEndpoints +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_EndpointService_ListEndpoints_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_endpoints(): + # Create a client + client = aiplatform_v1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListEndpointsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_endpoints(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1_generated_EndpointService_ListEndpoints_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_endpoint_service_list_endpoints_sync.py b/samples/generated_samples/aiplatform_v1_generated_endpoint_service_list_endpoints_sync.py new file mode 100644 index 0000000000..5c4faf7931 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_endpoint_service_list_endpoints_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListEndpoints +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_EndpointService_ListEndpoints_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_endpoints(): + # Create a client + client = aiplatform_v1.EndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListEndpointsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_endpoints(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1_generated_EndpointService_ListEndpoints_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_endpoint_service_undeploy_model_async.py b/samples/generated_samples/aiplatform_v1_generated_endpoint_service_undeploy_model_async.py new file mode 100644 index 0000000000..88258ff0b7 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_endpoint_service_undeploy_model_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UndeployModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_EndpointService_UndeployModel_async] +from google.cloud import aiplatform_v1 + + +async def sample_undeploy_model(): + # Create a client + client = aiplatform_v1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.UndeployModelRequest( + endpoint="endpoint_value", + deployed_model_id="deployed_model_id_value", + ) + + # Make the request + operation = client.undeploy_model(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_EndpointService_UndeployModel_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_endpoint_service_undeploy_model_sync.py b/samples/generated_samples/aiplatform_v1_generated_endpoint_service_undeploy_model_sync.py new file mode 100644 index 0000000000..2178e3340f --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_endpoint_service_undeploy_model_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UndeployModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_EndpointService_UndeployModel_sync] +from google.cloud import aiplatform_v1 + + +def sample_undeploy_model(): + # Create a client + client = aiplatform_v1.EndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.UndeployModelRequest( + endpoint="endpoint_value", + deployed_model_id="deployed_model_id_value", + ) + + # Make the request + operation = client.undeploy_model(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_EndpointService_UndeployModel_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_endpoint_service_update_endpoint_async.py b/samples/generated_samples/aiplatform_v1_generated_endpoint_service_update_endpoint_async.py new file mode 100644 index 0000000000..c1039cda24 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_endpoint_service_update_endpoint_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_EndpointService_UpdateEndpoint_async] +from google.cloud import aiplatform_v1 + + +async def sample_update_endpoint(): + # Create a client + client = aiplatform_v1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + endpoint = aiplatform_v1.Endpoint() + endpoint.display_name = "display_name_value" + + request = aiplatform_v1.UpdateEndpointRequest( + endpoint=endpoint, + ) + + # Make the request + response = await client.update_endpoint(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_EndpointService_UpdateEndpoint_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_endpoint_service_update_endpoint_sync.py b/samples/generated_samples/aiplatform_v1_generated_endpoint_service_update_endpoint_sync.py new file mode 100644 index 0000000000..8b717bf344 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_endpoint_service_update_endpoint_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_EndpointService_UpdateEndpoint_sync] +from google.cloud import aiplatform_v1 + + +def sample_update_endpoint(): + # Create a client + client = aiplatform_v1.EndpointServiceClient() + + # Initialize request argument(s) + endpoint = aiplatform_v1.Endpoint() + endpoint.display_name = "display_name_value" + + request = aiplatform_v1.UpdateEndpointRequest( + endpoint=endpoint, + ) + + # Make the request + response = client.update_endpoint(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_EndpointService_UpdateEndpoint_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_online_serving_service_read_feature_values_async.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_online_serving_service_read_feature_values_async.py new file mode 100644 index 0000000000..7de0f610c9 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_online_serving_service_read_feature_values_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ReadFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreOnlineServingService_ReadFeatureValues_async] +from google.cloud import aiplatform_v1 + + +async def sample_read_feature_values(): + # Create a client + client = aiplatform_v1.FeaturestoreOnlineServingServiceAsyncClient() + + # Initialize request argument(s) + feature_selector = aiplatform_v1.FeatureSelector() + feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1.ReadFeatureValuesRequest( + entity_type="entity_type_value", + entity_id="entity_id_value", + feature_selector=feature_selector, + ) + + # Make the request + response = await client.read_feature_values(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_FeaturestoreOnlineServingService_ReadFeatureValues_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_online_serving_service_read_feature_values_sync.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_online_serving_service_read_feature_values_sync.py new file mode 100644 index 0000000000..9693bb1a66 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_online_serving_service_read_feature_values_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ReadFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreOnlineServingService_ReadFeatureValues_sync] +from google.cloud import aiplatform_v1 + + +def sample_read_feature_values(): + # Create a client + client = aiplatform_v1.FeaturestoreOnlineServingServiceClient() + + # Initialize request argument(s) + feature_selector = aiplatform_v1.FeatureSelector() + feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1.ReadFeatureValuesRequest( + entity_type="entity_type_value", + entity_id="entity_id_value", + feature_selector=feature_selector, + ) + + # Make the request + response = client.read_feature_values(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_FeaturestoreOnlineServingService_ReadFeatureValues_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_online_serving_service_streaming_read_feature_values_async.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_online_serving_service_streaming_read_feature_values_async.py new file mode 100644 index 0000000000..91e74ea89c --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_online_serving_service_streaming_read_feature_values_async.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for StreamingReadFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreOnlineServingService_StreamingReadFeatureValues_async] +from google.cloud import aiplatform_v1 + + +async def sample_streaming_read_feature_values(): + # Create a client + client = aiplatform_v1.FeaturestoreOnlineServingServiceAsyncClient() + + # Initialize request argument(s) + feature_selector = aiplatform_v1.FeatureSelector() + feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1.StreamingReadFeatureValuesRequest( + entity_type="entity_type_value", + entity_ids=['entity_ids_value_1', 'entity_ids_value_2'], + feature_selector=feature_selector, + ) + + # Make the request + stream = await client.streaming_read_feature_values(request=request) + + # Handle the response + async for response in stream: + print(response) + +# [END aiplatform_v1_generated_FeaturestoreOnlineServingService_StreamingReadFeatureValues_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_online_serving_service_streaming_read_feature_values_sync.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_online_serving_service_streaming_read_feature_values_sync.py new file mode 100644 index 0000000000..927a65a41b --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_online_serving_service_streaming_read_feature_values_sync.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for StreamingReadFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreOnlineServingService_StreamingReadFeatureValues_sync] +from google.cloud import aiplatform_v1 + + +def sample_streaming_read_feature_values(): + # Create a client + client = aiplatform_v1.FeaturestoreOnlineServingServiceClient() + + # Initialize request argument(s) + feature_selector = aiplatform_v1.FeatureSelector() + feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1.StreamingReadFeatureValuesRequest( + entity_type="entity_type_value", + entity_ids=['entity_ids_value_1', 'entity_ids_value_2'], + feature_selector=feature_selector, + ) + + # Make the request + stream = client.streaming_read_feature_values(request=request) + + # Handle the response + for response in stream: + print(response) + +# [END aiplatform_v1_generated_FeaturestoreOnlineServingService_StreamingReadFeatureValues_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_batch_create_features_async.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_batch_create_features_async.py new file mode 100644 index 0000000000..446f602cb6 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_batch_create_features_async.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchCreateFeatures +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_BatchCreateFeatures_async] +from google.cloud import aiplatform_v1 + + +async def sample_batch_create_features(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + requests = aiplatform_v1.CreateFeatureRequest() + requests.parent = "parent_value" + requests.feature.value_type = "BYTES" + requests.feature_id = "feature_id_value" + + request = aiplatform_v1.BatchCreateFeaturesRequest( + parent="parent_value", + requests=requests, + ) + + # Make the request + operation = client.batch_create_features(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_BatchCreateFeatures_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_batch_create_features_sync.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_batch_create_features_sync.py new file mode 100644 index 0000000000..96f958a186 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_batch_create_features_sync.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchCreateFeatures +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_BatchCreateFeatures_sync] +from google.cloud import aiplatform_v1 + + +def sample_batch_create_features(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + requests = aiplatform_v1.CreateFeatureRequest() + requests.parent = "parent_value" + requests.feature.value_type = "BYTES" + requests.feature_id = "feature_id_value" + + request = aiplatform_v1.BatchCreateFeaturesRequest( + parent="parent_value", + requests=requests, + ) + + # Make the request + operation = client.batch_create_features(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_BatchCreateFeatures_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_batch_read_feature_values_async.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_batch_read_feature_values_async.py new file mode 100644 index 0000000000..6f471a7d5e --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_batch_read_feature_values_async.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchReadFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_BatchReadFeatureValues_async] +from google.cloud import aiplatform_v1 + + +async def sample_batch_read_feature_values(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + csv_read_instances = aiplatform_v1.CsvSource() + csv_read_instances.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + + destination = aiplatform_v1.FeatureValueDestination() + destination.bigquery_destination.output_uri = "output_uri_value" + + entity_type_specs = aiplatform_v1.EntityTypeSpec() + entity_type_specs.entity_type_id = "entity_type_id_value" + entity_type_specs.feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1.BatchReadFeatureValuesRequest( + csv_read_instances=csv_read_instances, + featurestore="featurestore_value", + destination=destination, + entity_type_specs=entity_type_specs, + ) + + # Make the request + operation = client.batch_read_feature_values(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_BatchReadFeatureValues_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_batch_read_feature_values_sync.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_batch_read_feature_values_sync.py new file mode 100644 index 0000000000..4926d5a69f --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_batch_read_feature_values_sync.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchReadFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_BatchReadFeatureValues_sync] +from google.cloud import aiplatform_v1 + + +def sample_batch_read_feature_values(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + csv_read_instances = aiplatform_v1.CsvSource() + csv_read_instances.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + + destination = aiplatform_v1.FeatureValueDestination() + destination.bigquery_destination.output_uri = "output_uri_value" + + entity_type_specs = aiplatform_v1.EntityTypeSpec() + entity_type_specs.entity_type_id = "entity_type_id_value" + entity_type_specs.feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1.BatchReadFeatureValuesRequest( + csv_read_instances=csv_read_instances, + featurestore="featurestore_value", + destination=destination, + entity_type_specs=entity_type_specs, + ) + + # Make the request + operation = client.batch_read_feature_values(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_BatchReadFeatureValues_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_create_entity_type_async.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_create_entity_type_async.py new file mode 100644 index 0000000000..3015072317 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_create_entity_type_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateEntityType +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_CreateEntityType_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_entity_type(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateEntityTypeRequest( + parent="parent_value", + entity_type_id="entity_type_id_value", + ) + + # Make the request + operation = client.create_entity_type(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_CreateEntityType_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_create_entity_type_sync.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_create_entity_type_sync.py new file mode 100644 index 0000000000..29189412d3 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_create_entity_type_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateEntityType +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_CreateEntityType_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_entity_type(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateEntityTypeRequest( + parent="parent_value", + entity_type_id="entity_type_id_value", + ) + + # Make the request + operation = client.create_entity_type(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_CreateEntityType_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_create_feature_async.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_create_feature_async.py new file mode 100644 index 0000000000..671177a883 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_create_feature_async.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateFeature +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_CreateFeature_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_feature(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + feature = aiplatform_v1.Feature() + feature.value_type = "BYTES" + + request = aiplatform_v1.CreateFeatureRequest( + parent="parent_value", + feature=feature, + feature_id="feature_id_value", + ) + + # Make the request + operation = client.create_feature(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_CreateFeature_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_create_feature_sync.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_create_feature_sync.py new file mode 100644 index 0000000000..cdf4b5e9ad --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_create_feature_sync.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateFeature +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_CreateFeature_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_feature(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + feature = aiplatform_v1.Feature() + feature.value_type = "BYTES" + + request = aiplatform_v1.CreateFeatureRequest( + parent="parent_value", + feature=feature, + feature_id="feature_id_value", + ) + + # Make the request + operation = client.create_feature(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_CreateFeature_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_create_featurestore_async.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_create_featurestore_async.py new file mode 100644 index 0000000000..fd5fdcda77 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_create_featurestore_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateFeaturestore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_CreateFeaturestore_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_featurestore(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateFeaturestoreRequest( + parent="parent_value", + featurestore_id="featurestore_id_value", + ) + + # Make the request + operation = client.create_featurestore(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_CreateFeaturestore_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_create_featurestore_sync.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_create_featurestore_sync.py new file mode 100644 index 0000000000..7457a55007 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_create_featurestore_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateFeaturestore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_CreateFeaturestore_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_featurestore(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateFeaturestoreRequest( + parent="parent_value", + featurestore_id="featurestore_id_value", + ) + + # Make the request + operation = client.create_featurestore(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_CreateFeaturestore_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_delete_entity_type_async.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_delete_entity_type_async.py new file mode 100644 index 0000000000..09672d6404 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_delete_entity_type_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteEntityType +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_DeleteEntityType_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_entity_type(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteEntityTypeRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_entity_type(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_DeleteEntityType_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_delete_entity_type_sync.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_delete_entity_type_sync.py new file mode 100644 index 0000000000..0a4bbe5610 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_delete_entity_type_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteEntityType +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_DeleteEntityType_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_entity_type(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteEntityTypeRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_entity_type(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_DeleteEntityType_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_delete_feature_async.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_delete_feature_async.py new file mode 100644 index 0000000000..53e60c17f5 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_delete_feature_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteFeature +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_DeleteFeature_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_feature(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteFeatureRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_feature(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_DeleteFeature_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_delete_feature_sync.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_delete_feature_sync.py new file mode 100644 index 0000000000..f03ea625be --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_delete_feature_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteFeature +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_DeleteFeature_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_feature(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteFeatureRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_feature(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_DeleteFeature_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_delete_featurestore_async.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_delete_featurestore_async.py new file mode 100644 index 0000000000..52de9bc84c --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_delete_featurestore_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteFeaturestore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_DeleteFeaturestore_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_featurestore(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteFeaturestoreRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_featurestore(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_DeleteFeaturestore_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_delete_featurestore_sync.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_delete_featurestore_sync.py new file mode 100644 index 0000000000..8556329614 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_delete_featurestore_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteFeaturestore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_DeleteFeaturestore_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_featurestore(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteFeaturestoreRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_featurestore(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_DeleteFeaturestore_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_export_feature_values_async.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_export_feature_values_async.py new file mode 100644 index 0000000000..f60187c790 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_export_feature_values_async.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_ExportFeatureValues_async] +from google.cloud import aiplatform_v1 + + +async def sample_export_feature_values(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + destination = aiplatform_v1.FeatureValueDestination() + destination.bigquery_destination.output_uri = "output_uri_value" + + feature_selector = aiplatform_v1.FeatureSelector() + feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1.ExportFeatureValuesRequest( + entity_type="entity_type_value", + destination=destination, + feature_selector=feature_selector, + ) + + # Make the request + operation = client.export_feature_values(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_ExportFeatureValues_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_export_feature_values_sync.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_export_feature_values_sync.py new file mode 100644 index 0000000000..916830e11e --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_export_feature_values_sync.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_ExportFeatureValues_sync] +from google.cloud import aiplatform_v1 + + +def sample_export_feature_values(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + destination = aiplatform_v1.FeatureValueDestination() + destination.bigquery_destination.output_uri = "output_uri_value" + + feature_selector = aiplatform_v1.FeatureSelector() + feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1.ExportFeatureValuesRequest( + entity_type="entity_type_value", + destination=destination, + feature_selector=feature_selector, + ) + + # Make the request + operation = client.export_feature_values(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_ExportFeatureValues_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_get_entity_type_async.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_get_entity_type_async.py new file mode 100644 index 0000000000..795c12d50b --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_get_entity_type_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetEntityType +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_GetEntityType_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_entity_type(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetEntityTypeRequest( + name="name_value", + ) + + # Make the request + response = await client.get_entity_type(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_GetEntityType_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_get_entity_type_sync.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_get_entity_type_sync.py new file mode 100644 index 0000000000..322f1a8c66 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_get_entity_type_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetEntityType +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_GetEntityType_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_entity_type(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetEntityTypeRequest( + name="name_value", + ) + + # Make the request + response = client.get_entity_type(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_GetEntityType_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_get_feature_async.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_get_feature_async.py new file mode 100644 index 0000000000..c3274b019b --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_get_feature_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetFeature +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_GetFeature_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_feature(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetFeatureRequest( + name="name_value", + ) + + # Make the request + response = await client.get_feature(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_GetFeature_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_get_feature_sync.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_get_feature_sync.py new file mode 100644 index 0000000000..ea59add0ad --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_get_feature_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetFeature +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_GetFeature_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_feature(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetFeatureRequest( + name="name_value", + ) + + # Make the request + response = client.get_feature(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_GetFeature_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_get_featurestore_async.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_get_featurestore_async.py new file mode 100644 index 0000000000..16a332c6fa --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_get_featurestore_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetFeaturestore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_GetFeaturestore_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_featurestore(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetFeaturestoreRequest( + name="name_value", + ) + + # Make the request + response = await client.get_featurestore(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_GetFeaturestore_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_get_featurestore_sync.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_get_featurestore_sync.py new file mode 100644 index 0000000000..1de46d7414 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_get_featurestore_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetFeaturestore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_GetFeaturestore_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_featurestore(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetFeaturestoreRequest( + name="name_value", + ) + + # Make the request + response = client.get_featurestore(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_GetFeaturestore_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_import_feature_values_async.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_import_feature_values_async.py new file mode 100644 index 0000000000..2c6c0dfd7d --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_import_feature_values_async.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ImportFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_ImportFeatureValues_async] +from google.cloud import aiplatform_v1 + + +async def sample_import_feature_values(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + avro_source = aiplatform_v1.AvroSource() + avro_source.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + + feature_specs = aiplatform_v1.FeatureSpec() + feature_specs.id = "id_value" + + request = aiplatform_v1.ImportFeatureValuesRequest( + avro_source=avro_source, + feature_time_field="feature_time_field_value", + entity_type="entity_type_value", + feature_specs=feature_specs, + ) + + # Make the request + operation = client.import_feature_values(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_ImportFeatureValues_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_import_feature_values_sync.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_import_feature_values_sync.py new file mode 100644 index 0000000000..1bb06697f3 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_import_feature_values_sync.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ImportFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_ImportFeatureValues_sync] +from google.cloud import aiplatform_v1 + + +def sample_import_feature_values(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + avro_source = aiplatform_v1.AvroSource() + avro_source.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + + feature_specs = aiplatform_v1.FeatureSpec() + feature_specs.id = "id_value" + + request = aiplatform_v1.ImportFeatureValuesRequest( + avro_source=avro_source, + feature_time_field="feature_time_field_value", + entity_type="entity_type_value", + feature_specs=feature_specs, + ) + + # Make the request + operation = client.import_feature_values(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_ImportFeatureValues_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_list_entity_types_async.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_list_entity_types_async.py new file mode 100644 index 0000000000..36fa20d54c --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_list_entity_types_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListEntityTypes +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_ListEntityTypes_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_entity_types(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListEntityTypesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_entity_types(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_ListEntityTypes_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_list_entity_types_sync.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_list_entity_types_sync.py new file mode 100644 index 0000000000..a7a97fa236 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_list_entity_types_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListEntityTypes +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_ListEntityTypes_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_entity_types(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListEntityTypesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_entity_types(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_ListEntityTypes_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_list_features_async.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_list_features_async.py new file mode 100644 index 0000000000..493cf3b272 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_list_features_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListFeatures +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_ListFeatures_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_features(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListFeaturesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_features(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_ListFeatures_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_list_features_sync.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_list_features_sync.py new file mode 100644 index 0000000000..67e53820f2 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_list_features_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListFeatures +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_ListFeatures_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_features(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListFeaturesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_features(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_ListFeatures_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_list_featurestores_async.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_list_featurestores_async.py new file mode 100644 index 0000000000..a6e7fdda8f --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_list_featurestores_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListFeaturestores +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_ListFeaturestores_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_featurestores(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListFeaturestoresRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_featurestores(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_ListFeaturestores_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_list_featurestores_sync.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_list_featurestores_sync.py new file mode 100644 index 0000000000..21bafb70b3 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_list_featurestores_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListFeaturestores +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_ListFeaturestores_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_featurestores(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListFeaturestoresRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_featurestores(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_ListFeaturestores_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_search_features_async.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_search_features_async.py new file mode 100644 index 0000000000..bf9ec39b73 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_search_features_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SearchFeatures +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_SearchFeatures_async] +from google.cloud import aiplatform_v1 + + +async def sample_search_features(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.SearchFeaturesRequest( + location="location_value", + ) + + # Make the request + page_result = client.search_features(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_SearchFeatures_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_search_features_sync.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_search_features_sync.py new file mode 100644 index 0000000000..41892e64b4 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_search_features_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SearchFeatures +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_SearchFeatures_sync] +from google.cloud import aiplatform_v1 + + +def sample_search_features(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.SearchFeaturesRequest( + location="location_value", + ) + + # Make the request + page_result = client.search_features(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_SearchFeatures_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_update_entity_type_async.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_update_entity_type_async.py new file mode 100644 index 0000000000..97e48bcbbf --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_update_entity_type_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateEntityType +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_UpdateEntityType_async] +from google.cloud import aiplatform_v1 + + +async def sample_update_entity_type(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.UpdateEntityTypeRequest( + ) + + # Make the request + response = await client.update_entity_type(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_UpdateEntityType_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_update_entity_type_sync.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_update_entity_type_sync.py new file mode 100644 index 0000000000..431c93fa91 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_update_entity_type_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateEntityType +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_UpdateEntityType_sync] +from google.cloud import aiplatform_v1 + + +def sample_update_entity_type(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.UpdateEntityTypeRequest( + ) + + # Make the request + response = client.update_entity_type(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_UpdateEntityType_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_update_feature_async.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_update_feature_async.py new file mode 100644 index 0000000000..609b6e9e61 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_update_feature_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateFeature +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_UpdateFeature_async] +from google.cloud import aiplatform_v1 + + +async def sample_update_feature(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + feature = aiplatform_v1.Feature() + feature.value_type = "BYTES" + + request = aiplatform_v1.UpdateFeatureRequest( + feature=feature, + ) + + # Make the request + response = await client.update_feature(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_UpdateFeature_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_update_feature_sync.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_update_feature_sync.py new file mode 100644 index 0000000000..d86da09498 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_update_feature_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateFeature +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_UpdateFeature_sync] +from google.cloud import aiplatform_v1 + + +def sample_update_feature(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + feature = aiplatform_v1.Feature() + feature.value_type = "BYTES" + + request = aiplatform_v1.UpdateFeatureRequest( + feature=feature, + ) + + # Make the request + response = client.update_feature(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_UpdateFeature_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_update_featurestore_async.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_update_featurestore_async.py new file mode 100644 index 0000000000..83501ffe96 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_update_featurestore_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateFeaturestore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_UpdateFeaturestore_async] +from google.cloud import aiplatform_v1 + + +async def sample_update_featurestore(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.UpdateFeaturestoreRequest( + ) + + # Make the request + operation = client.update_featurestore(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_UpdateFeaturestore_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_featurestore_service_update_featurestore_sync.py b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_update_featurestore_sync.py new file mode 100644 index 0000000000..64c6fd147a --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_featurestore_service_update_featurestore_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateFeaturestore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_FeaturestoreService_UpdateFeaturestore_sync] +from google.cloud import aiplatform_v1 + + +def sample_update_featurestore(): + # Create a client + client = aiplatform_v1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.UpdateFeaturestoreRequest( + ) + + # Make the request + operation = client.update_featurestore(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_FeaturestoreService_UpdateFeaturestore_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_create_index_endpoint_async.py b/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_create_index_endpoint_async.py new file mode 100644 index 0000000000..0b77503e53 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_create_index_endpoint_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateIndexEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_IndexEndpointService_CreateIndexEndpoint_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_index_endpoint(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + index_endpoint = aiplatform_v1.IndexEndpoint() + index_endpoint.display_name = "display_name_value" + + request = aiplatform_v1.CreateIndexEndpointRequest( + parent="parent_value", + index_endpoint=index_endpoint, + ) + + # Make the request + operation = client.create_index_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_IndexEndpointService_CreateIndexEndpoint_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_create_index_endpoint_sync.py b/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_create_index_endpoint_sync.py new file mode 100644 index 0000000000..bfee5ecfce --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_create_index_endpoint_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateIndexEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_IndexEndpointService_CreateIndexEndpoint_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_index_endpoint(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceClient() + + # Initialize request argument(s) + index_endpoint = aiplatform_v1.IndexEndpoint() + index_endpoint.display_name = "display_name_value" + + request = aiplatform_v1.CreateIndexEndpointRequest( + parent="parent_value", + index_endpoint=index_endpoint, + ) + + # Make the request + operation = client.create_index_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_IndexEndpointService_CreateIndexEndpoint_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_delete_index_endpoint_async.py b/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_delete_index_endpoint_async.py new file mode 100644 index 0000000000..0bec262cd3 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_delete_index_endpoint_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteIndexEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_IndexEndpointService_DeleteIndexEndpoint_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_index_endpoint(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteIndexEndpointRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_index_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_IndexEndpointService_DeleteIndexEndpoint_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_delete_index_endpoint_sync.py b/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_delete_index_endpoint_sync.py new file mode 100644 index 0000000000..885aa0c4d2 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_delete_index_endpoint_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteIndexEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_IndexEndpointService_DeleteIndexEndpoint_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_index_endpoint(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteIndexEndpointRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_index_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_IndexEndpointService_DeleteIndexEndpoint_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_deploy_index_async.py b/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_deploy_index_async.py new file mode 100644 index 0000000000..45b23cf1bd --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_deploy_index_async.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeployIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_IndexEndpointService_DeployIndex_async] +from google.cloud import aiplatform_v1 + + +async def sample_deploy_index(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + deployed_index = aiplatform_v1.DeployedIndex() + deployed_index.id = "id_value" + deployed_index.index = "index_value" + + request = aiplatform_v1.DeployIndexRequest( + index_endpoint="index_endpoint_value", + deployed_index=deployed_index, + ) + + # Make the request + operation = client.deploy_index(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_IndexEndpointService_DeployIndex_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_deploy_index_sync.py b/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_deploy_index_sync.py new file mode 100644 index 0000000000..0c9402d026 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_deploy_index_sync.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeployIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_IndexEndpointService_DeployIndex_sync] +from google.cloud import aiplatform_v1 + + +def sample_deploy_index(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceClient() + + # Initialize request argument(s) + deployed_index = aiplatform_v1.DeployedIndex() + deployed_index.id = "id_value" + deployed_index.index = "index_value" + + request = aiplatform_v1.DeployIndexRequest( + index_endpoint="index_endpoint_value", + deployed_index=deployed_index, + ) + + # Make the request + operation = client.deploy_index(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_IndexEndpointService_DeployIndex_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_get_index_endpoint_async.py b/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_get_index_endpoint_async.py new file mode 100644 index 0000000000..db0f322dce --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_get_index_endpoint_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetIndexEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_IndexEndpointService_GetIndexEndpoint_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_index_endpoint(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetIndexEndpointRequest( + name="name_value", + ) + + # Make the request + response = await client.get_index_endpoint(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_IndexEndpointService_GetIndexEndpoint_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_get_index_endpoint_sync.py b/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_get_index_endpoint_sync.py new file mode 100644 index 0000000000..5935ec4363 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_get_index_endpoint_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetIndexEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_IndexEndpointService_GetIndexEndpoint_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_index_endpoint(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetIndexEndpointRequest( + name="name_value", + ) + + # Make the request + response = client.get_index_endpoint(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_IndexEndpointService_GetIndexEndpoint_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_list_index_endpoints_async.py b/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_list_index_endpoints_async.py new file mode 100644 index 0000000000..61510c311e --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_list_index_endpoints_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListIndexEndpoints +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_IndexEndpointService_ListIndexEndpoints_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_index_endpoints(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListIndexEndpointsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_index_endpoints(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1_generated_IndexEndpointService_ListIndexEndpoints_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_list_index_endpoints_sync.py b/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_list_index_endpoints_sync.py new file mode 100644 index 0000000000..05c733d458 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_list_index_endpoints_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListIndexEndpoints +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_IndexEndpointService_ListIndexEndpoints_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_index_endpoints(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListIndexEndpointsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_index_endpoints(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1_generated_IndexEndpointService_ListIndexEndpoints_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_mutate_deployed_index_async.py b/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_mutate_deployed_index_async.py new file mode 100644 index 0000000000..032e0807a0 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_mutate_deployed_index_async.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for MutateDeployedIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_IndexEndpointService_MutateDeployedIndex_async] +from google.cloud import aiplatform_v1 + + +async def sample_mutate_deployed_index(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + deployed_index = aiplatform_v1.DeployedIndex() + deployed_index.id = "id_value" + deployed_index.index = "index_value" + + request = aiplatform_v1.MutateDeployedIndexRequest( + index_endpoint="index_endpoint_value", + deployed_index=deployed_index, + ) + + # Make the request + operation = client.mutate_deployed_index(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_IndexEndpointService_MutateDeployedIndex_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_mutate_deployed_index_sync.py b/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_mutate_deployed_index_sync.py new file mode 100644 index 0000000000..033699b684 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_mutate_deployed_index_sync.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for MutateDeployedIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_IndexEndpointService_MutateDeployedIndex_sync] +from google.cloud import aiplatform_v1 + + +def sample_mutate_deployed_index(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceClient() + + # Initialize request argument(s) + deployed_index = aiplatform_v1.DeployedIndex() + deployed_index.id = "id_value" + deployed_index.index = "index_value" + + request = aiplatform_v1.MutateDeployedIndexRequest( + index_endpoint="index_endpoint_value", + deployed_index=deployed_index, + ) + + # Make the request + operation = client.mutate_deployed_index(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_IndexEndpointService_MutateDeployedIndex_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_undeploy_index_async.py b/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_undeploy_index_async.py new file mode 100644 index 0000000000..725285529b --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_undeploy_index_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UndeployIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_IndexEndpointService_UndeployIndex_async] +from google.cloud import aiplatform_v1 + + +async def sample_undeploy_index(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.UndeployIndexRequest( + index_endpoint="index_endpoint_value", + deployed_index_id="deployed_index_id_value", + ) + + # Make the request + operation = client.undeploy_index(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_IndexEndpointService_UndeployIndex_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_undeploy_index_sync.py b/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_undeploy_index_sync.py new file mode 100644 index 0000000000..efd09cfeda --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_undeploy_index_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UndeployIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_IndexEndpointService_UndeployIndex_sync] +from google.cloud import aiplatform_v1 + + +def sample_undeploy_index(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.UndeployIndexRequest( + index_endpoint="index_endpoint_value", + deployed_index_id="deployed_index_id_value", + ) + + # Make the request + operation = client.undeploy_index(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_IndexEndpointService_UndeployIndex_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_update_index_endpoint_async.py b/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_update_index_endpoint_async.py new file mode 100644 index 0000000000..c670d1cb32 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_update_index_endpoint_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateIndexEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_IndexEndpointService_UpdateIndexEndpoint_async] +from google.cloud import aiplatform_v1 + + +async def sample_update_index_endpoint(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + index_endpoint = aiplatform_v1.IndexEndpoint() + index_endpoint.display_name = "display_name_value" + + request = aiplatform_v1.UpdateIndexEndpointRequest( + index_endpoint=index_endpoint, + ) + + # Make the request + response = await client.update_index_endpoint(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_IndexEndpointService_UpdateIndexEndpoint_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_update_index_endpoint_sync.py b/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_update_index_endpoint_sync.py new file mode 100644 index 0000000000..98669d086c --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_index_endpoint_service_update_index_endpoint_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateIndexEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_IndexEndpointService_UpdateIndexEndpoint_sync] +from google.cloud import aiplatform_v1 + + +def sample_update_index_endpoint(): + # Create a client + client = aiplatform_v1.IndexEndpointServiceClient() + + # Initialize request argument(s) + index_endpoint = aiplatform_v1.IndexEndpoint() + index_endpoint.display_name = "display_name_value" + + request = aiplatform_v1.UpdateIndexEndpointRequest( + index_endpoint=index_endpoint, + ) + + # Make the request + response = client.update_index_endpoint(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_IndexEndpointService_UpdateIndexEndpoint_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_index_service_create_index_async.py b/samples/generated_samples/aiplatform_v1_generated_index_service_create_index_async.py new file mode 100644 index 0000000000..f4b9614d41 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_index_service_create_index_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_IndexService_CreateIndex_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_index(): + # Create a client + client = aiplatform_v1.IndexServiceAsyncClient() + + # Initialize request argument(s) + index = aiplatform_v1.Index() + index.display_name = "display_name_value" + + request = aiplatform_v1.CreateIndexRequest( + parent="parent_value", + index=index, + ) + + # Make the request + operation = client.create_index(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_IndexService_CreateIndex_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_index_service_create_index_sync.py b/samples/generated_samples/aiplatform_v1_generated_index_service_create_index_sync.py new file mode 100644 index 0000000000..60dcc20299 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_index_service_create_index_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_IndexService_CreateIndex_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_index(): + # Create a client + client = aiplatform_v1.IndexServiceClient() + + # Initialize request argument(s) + index = aiplatform_v1.Index() + index.display_name = "display_name_value" + + request = aiplatform_v1.CreateIndexRequest( + parent="parent_value", + index=index, + ) + + # Make the request + operation = client.create_index(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_IndexService_CreateIndex_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_index_service_delete_index_async.py b/samples/generated_samples/aiplatform_v1_generated_index_service_delete_index_async.py new file mode 100644 index 0000000000..6f8ab5eae7 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_index_service_delete_index_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_IndexService_DeleteIndex_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_index(): + # Create a client + client = aiplatform_v1.IndexServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteIndexRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_index(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_IndexService_DeleteIndex_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_index_service_delete_index_sync.py b/samples/generated_samples/aiplatform_v1_generated_index_service_delete_index_sync.py new file mode 100644 index 0000000000..68d981526c --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_index_service_delete_index_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_IndexService_DeleteIndex_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_index(): + # Create a client + client = aiplatform_v1.IndexServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteIndexRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_index(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_IndexService_DeleteIndex_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_index_service_get_index_async.py b/samples/generated_samples/aiplatform_v1_generated_index_service_get_index_async.py new file mode 100644 index 0000000000..7d01bf3a29 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_index_service_get_index_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_IndexService_GetIndex_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_index(): + # Create a client + client = aiplatform_v1.IndexServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetIndexRequest( + name="name_value", + ) + + # Make the request + response = await client.get_index(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_IndexService_GetIndex_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_index_service_get_index_sync.py b/samples/generated_samples/aiplatform_v1_generated_index_service_get_index_sync.py new file mode 100644 index 0000000000..662e8c9bb0 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_index_service_get_index_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_IndexService_GetIndex_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_index(): + # Create a client + client = aiplatform_v1.IndexServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetIndexRequest( + name="name_value", + ) + + # Make the request + response = client.get_index(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_IndexService_GetIndex_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_index_service_list_indexes_async.py b/samples/generated_samples/aiplatform_v1_generated_index_service_list_indexes_async.py new file mode 100644 index 0000000000..df114f1694 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_index_service_list_indexes_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListIndexes +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_IndexService_ListIndexes_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_indexes(): + # Create a client + client = aiplatform_v1.IndexServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListIndexesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_indexes(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1_generated_IndexService_ListIndexes_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_index_service_list_indexes_sync.py b/samples/generated_samples/aiplatform_v1_generated_index_service_list_indexes_sync.py new file mode 100644 index 0000000000..9048e9b3cd --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_index_service_list_indexes_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListIndexes +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_IndexService_ListIndexes_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_indexes(): + # Create a client + client = aiplatform_v1.IndexServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListIndexesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_indexes(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1_generated_IndexService_ListIndexes_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_index_service_update_index_async.py b/samples/generated_samples/aiplatform_v1_generated_index_service_update_index_async.py new file mode 100644 index 0000000000..a7845d43a7 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_index_service_update_index_async.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_IndexService_UpdateIndex_async] +from google.cloud import aiplatform_v1 + + +async def sample_update_index(): + # Create a client + client = aiplatform_v1.IndexServiceAsyncClient() + + # Initialize request argument(s) + index = aiplatform_v1.Index() + index.display_name = "display_name_value" + + request = aiplatform_v1.UpdateIndexRequest( + index=index, + ) + + # Make the request + operation = client.update_index(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_IndexService_UpdateIndex_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_index_service_update_index_sync.py b/samples/generated_samples/aiplatform_v1_generated_index_service_update_index_sync.py new file mode 100644 index 0000000000..315e5aface --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_index_service_update_index_sync.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_IndexService_UpdateIndex_sync] +from google.cloud import aiplatform_v1 + + +def sample_update_index(): + # Create a client + client = aiplatform_v1.IndexServiceClient() + + # Initialize request argument(s) + index = aiplatform_v1.Index() + index.display_name = "display_name_value" + + request = aiplatform_v1.UpdateIndexRequest( + index=index, + ) + + # Make the request + operation = client.update_index(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_IndexService_UpdateIndex_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_cancel_batch_prediction_job_async.py b/samples/generated_samples/aiplatform_v1_generated_job_service_cancel_batch_prediction_job_async.py new file mode 100644 index 0000000000..99f2d28b9b --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_cancel_batch_prediction_job_async.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelBatchPredictionJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_CancelBatchPredictionJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_cancel_batch_prediction_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CancelBatchPredictionJobRequest( + name="name_value", + ) + + # Make the request + await client.cancel_batch_prediction_job(request=request) + + +# [END aiplatform_v1_generated_JobService_CancelBatchPredictionJob_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_cancel_batch_prediction_job_sync.py b/samples/generated_samples/aiplatform_v1_generated_job_service_cancel_batch_prediction_job_sync.py new file mode 100644 index 0000000000..b22147b454 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_cancel_batch_prediction_job_sync.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelBatchPredictionJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_CancelBatchPredictionJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_cancel_batch_prediction_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CancelBatchPredictionJobRequest( + name="name_value", + ) + + # Make the request + client.cancel_batch_prediction_job(request=request) + + +# [END aiplatform_v1_generated_JobService_CancelBatchPredictionJob_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_cancel_custom_job_async.py b/samples/generated_samples/aiplatform_v1_generated_job_service_cancel_custom_job_async.py new file mode 100644 index 0000000000..aedd92111b --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_cancel_custom_job_async.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelCustomJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_CancelCustomJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_cancel_custom_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CancelCustomJobRequest( + name="name_value", + ) + + # Make the request + await client.cancel_custom_job(request=request) + + +# [END aiplatform_v1_generated_JobService_CancelCustomJob_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_cancel_custom_job_sync.py b/samples/generated_samples/aiplatform_v1_generated_job_service_cancel_custom_job_sync.py new file mode 100644 index 0000000000..4f30c4a526 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_cancel_custom_job_sync.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelCustomJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_CancelCustomJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_cancel_custom_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CancelCustomJobRequest( + name="name_value", + ) + + # Make the request + client.cancel_custom_job(request=request) + + +# [END aiplatform_v1_generated_JobService_CancelCustomJob_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_cancel_data_labeling_job_async.py b/samples/generated_samples/aiplatform_v1_generated_job_service_cancel_data_labeling_job_async.py new file mode 100644 index 0000000000..bc23ab2ebb --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_cancel_data_labeling_job_async.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelDataLabelingJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_CancelDataLabelingJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_cancel_data_labeling_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CancelDataLabelingJobRequest( + name="name_value", + ) + + # Make the request + await client.cancel_data_labeling_job(request=request) + + +# [END aiplatform_v1_generated_JobService_CancelDataLabelingJob_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_cancel_data_labeling_job_sync.py b/samples/generated_samples/aiplatform_v1_generated_job_service_cancel_data_labeling_job_sync.py new file mode 100644 index 0000000000..0e474f9c72 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_cancel_data_labeling_job_sync.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelDataLabelingJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_CancelDataLabelingJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_cancel_data_labeling_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CancelDataLabelingJobRequest( + name="name_value", + ) + + # Make the request + client.cancel_data_labeling_job(request=request) + + +# [END aiplatform_v1_generated_JobService_CancelDataLabelingJob_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_cancel_hyperparameter_tuning_job_async.py b/samples/generated_samples/aiplatform_v1_generated_job_service_cancel_hyperparameter_tuning_job_async.py new file mode 100644 index 0000000000..48deaf9ec9 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_cancel_hyperparameter_tuning_job_async.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelHyperparameterTuningJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_CancelHyperparameterTuningJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_cancel_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CancelHyperparameterTuningJobRequest( + name="name_value", + ) + + # Make the request + await client.cancel_hyperparameter_tuning_job(request=request) + + +# [END aiplatform_v1_generated_JobService_CancelHyperparameterTuningJob_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_cancel_hyperparameter_tuning_job_sync.py b/samples/generated_samples/aiplatform_v1_generated_job_service_cancel_hyperparameter_tuning_job_sync.py new file mode 100644 index 0000000000..d0928e186f --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_cancel_hyperparameter_tuning_job_sync.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelHyperparameterTuningJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_CancelHyperparameterTuningJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_cancel_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CancelHyperparameterTuningJobRequest( + name="name_value", + ) + + # Make the request + client.cancel_hyperparameter_tuning_job(request=request) + + +# [END aiplatform_v1_generated_JobService_CancelHyperparameterTuningJob_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_create_batch_prediction_job_async.py b/samples/generated_samples/aiplatform_v1_generated_job_service_create_batch_prediction_job_async.py new file mode 100644 index 0000000000..aa968a2d42 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_create_batch_prediction_job_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateBatchPredictionJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_CreateBatchPredictionJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_batch_prediction_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + batch_prediction_job = aiplatform_v1.BatchPredictionJob() + batch_prediction_job.display_name = "display_name_value" + batch_prediction_job.input_config.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + batch_prediction_job.input_config.instances_format = "instances_format_value" + batch_prediction_job.output_config.gcs_destination.output_uri_prefix = "output_uri_prefix_value" + batch_prediction_job.output_config.predictions_format = "predictions_format_value" + + request = aiplatform_v1.CreateBatchPredictionJobRequest( + parent="parent_value", + batch_prediction_job=batch_prediction_job, + ) + + # Make the request + response = await client.create_batch_prediction_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_JobService_CreateBatchPredictionJob_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_create_batch_prediction_job_sync.py b/samples/generated_samples/aiplatform_v1_generated_job_service_create_batch_prediction_job_sync.py new file mode 100644 index 0000000000..b178256c10 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_create_batch_prediction_job_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateBatchPredictionJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_CreateBatchPredictionJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_batch_prediction_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + batch_prediction_job = aiplatform_v1.BatchPredictionJob() + batch_prediction_job.display_name = "display_name_value" + batch_prediction_job.input_config.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + batch_prediction_job.input_config.instances_format = "instances_format_value" + batch_prediction_job.output_config.gcs_destination.output_uri_prefix = "output_uri_prefix_value" + batch_prediction_job.output_config.predictions_format = "predictions_format_value" + + request = aiplatform_v1.CreateBatchPredictionJobRequest( + parent="parent_value", + batch_prediction_job=batch_prediction_job, + ) + + # Make the request + response = client.create_batch_prediction_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_JobService_CreateBatchPredictionJob_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_create_custom_job_async.py b/samples/generated_samples/aiplatform_v1_generated_job_service_create_custom_job_async.py new file mode 100644 index 0000000000..0964e4a2ea --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_create_custom_job_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateCustomJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_CreateCustomJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_custom_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + custom_job = aiplatform_v1.CustomJob() + custom_job.display_name = "display_name_value" + custom_job.job_spec.worker_pool_specs.container_spec.image_uri = "image_uri_value" + + request = aiplatform_v1.CreateCustomJobRequest( + parent="parent_value", + custom_job=custom_job, + ) + + # Make the request + response = await client.create_custom_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_JobService_CreateCustomJob_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_create_custom_job_sync.py b/samples/generated_samples/aiplatform_v1_generated_job_service_create_custom_job_sync.py new file mode 100644 index 0000000000..577f365f97 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_create_custom_job_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateCustomJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_CreateCustomJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_custom_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + custom_job = aiplatform_v1.CustomJob() + custom_job.display_name = "display_name_value" + custom_job.job_spec.worker_pool_specs.container_spec.image_uri = "image_uri_value" + + request = aiplatform_v1.CreateCustomJobRequest( + parent="parent_value", + custom_job=custom_job, + ) + + # Make the request + response = client.create_custom_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_JobService_CreateCustomJob_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_create_data_labeling_job_async.py b/samples/generated_samples/aiplatform_v1_generated_job_service_create_data_labeling_job_async.py new file mode 100644 index 0000000000..810ee2a58a --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_create_data_labeling_job_async.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateDataLabelingJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_CreateDataLabelingJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_data_labeling_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + data_labeling_job = aiplatform_v1.DataLabelingJob() + data_labeling_job.display_name = "display_name_value" + data_labeling_job.datasets = ['datasets_value_1', 'datasets_value_2'] + data_labeling_job.labeler_count = 1375 + data_labeling_job.instruction_uri = "instruction_uri_value" + data_labeling_job.inputs_schema_uri = "inputs_schema_uri_value" + data_labeling_job.inputs.null_value = "NULL_VALUE" + + request = aiplatform_v1.CreateDataLabelingJobRequest( + parent="parent_value", + data_labeling_job=data_labeling_job, + ) + + # Make the request + response = await client.create_data_labeling_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_JobService_CreateDataLabelingJob_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_create_data_labeling_job_sync.py b/samples/generated_samples/aiplatform_v1_generated_job_service_create_data_labeling_job_sync.py new file mode 100644 index 0000000000..841de30638 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_create_data_labeling_job_sync.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateDataLabelingJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_CreateDataLabelingJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_data_labeling_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + data_labeling_job = aiplatform_v1.DataLabelingJob() + data_labeling_job.display_name = "display_name_value" + data_labeling_job.datasets = ['datasets_value_1', 'datasets_value_2'] + data_labeling_job.labeler_count = 1375 + data_labeling_job.instruction_uri = "instruction_uri_value" + data_labeling_job.inputs_schema_uri = "inputs_schema_uri_value" + data_labeling_job.inputs.null_value = "NULL_VALUE" + + request = aiplatform_v1.CreateDataLabelingJobRequest( + parent="parent_value", + data_labeling_job=data_labeling_job, + ) + + # Make the request + response = client.create_data_labeling_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_JobService_CreateDataLabelingJob_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_create_hyperparameter_tuning_job_async.py b/samples/generated_samples/aiplatform_v1_generated_job_service_create_hyperparameter_tuning_job_async.py new file mode 100644 index 0000000000..7e86e06a07 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_create_hyperparameter_tuning_job_async.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateHyperparameterTuningJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_CreateHyperparameterTuningJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + hyperparameter_tuning_job = aiplatform_v1.HyperparameterTuningJob() + hyperparameter_tuning_job.display_name = "display_name_value" + hyperparameter_tuning_job.study_spec.metrics.metric_id = "metric_id_value" + hyperparameter_tuning_job.study_spec.metrics.goal = "MINIMIZE" + hyperparameter_tuning_job.study_spec.parameters.double_value_spec.min_value = 0.96 + hyperparameter_tuning_job.study_spec.parameters.double_value_spec.max_value = 0.962 + hyperparameter_tuning_job.study_spec.parameters.parameter_id = "parameter_id_value" + hyperparameter_tuning_job.max_trial_count = 1609 + hyperparameter_tuning_job.parallel_trial_count = 2128 + hyperparameter_tuning_job.trial_job_spec.worker_pool_specs.container_spec.image_uri = "image_uri_value" + + request = aiplatform_v1.CreateHyperparameterTuningJobRequest( + parent="parent_value", + hyperparameter_tuning_job=hyperparameter_tuning_job, + ) + + # Make the request + response = await client.create_hyperparameter_tuning_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_JobService_CreateHyperparameterTuningJob_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_create_hyperparameter_tuning_job_sync.py b/samples/generated_samples/aiplatform_v1_generated_job_service_create_hyperparameter_tuning_job_sync.py new file mode 100644 index 0000000000..e18b9f5944 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_create_hyperparameter_tuning_job_sync.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateHyperparameterTuningJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_CreateHyperparameterTuningJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + hyperparameter_tuning_job = aiplatform_v1.HyperparameterTuningJob() + hyperparameter_tuning_job.display_name = "display_name_value" + hyperparameter_tuning_job.study_spec.metrics.metric_id = "metric_id_value" + hyperparameter_tuning_job.study_spec.metrics.goal = "MINIMIZE" + hyperparameter_tuning_job.study_spec.parameters.double_value_spec.min_value = 0.96 + hyperparameter_tuning_job.study_spec.parameters.double_value_spec.max_value = 0.962 + hyperparameter_tuning_job.study_spec.parameters.parameter_id = "parameter_id_value" + hyperparameter_tuning_job.max_trial_count = 1609 + hyperparameter_tuning_job.parallel_trial_count = 2128 + hyperparameter_tuning_job.trial_job_spec.worker_pool_specs.container_spec.image_uri = "image_uri_value" + + request = aiplatform_v1.CreateHyperparameterTuningJobRequest( + parent="parent_value", + hyperparameter_tuning_job=hyperparameter_tuning_job, + ) + + # Make the request + response = client.create_hyperparameter_tuning_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_JobService_CreateHyperparameterTuningJob_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_create_model_deployment_monitoring_job_async.py b/samples/generated_samples/aiplatform_v1_generated_job_service_create_model_deployment_monitoring_job_async.py new file mode 100644 index 0000000000..ce1e65948c --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_create_model_deployment_monitoring_job_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_CreateModelDeploymentMonitoringJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + model_deployment_monitoring_job = aiplatform_v1.ModelDeploymentMonitoringJob() + model_deployment_monitoring_job.display_name = "display_name_value" + model_deployment_monitoring_job.endpoint = "endpoint_value" + + request = aiplatform_v1.CreateModelDeploymentMonitoringJobRequest( + parent="parent_value", + model_deployment_monitoring_job=model_deployment_monitoring_job, + ) + + # Make the request + response = await client.create_model_deployment_monitoring_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_JobService_CreateModelDeploymentMonitoringJob_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_create_model_deployment_monitoring_job_sync.py b/samples/generated_samples/aiplatform_v1_generated_job_service_create_model_deployment_monitoring_job_sync.py new file mode 100644 index 0000000000..c31da8eb9b --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_create_model_deployment_monitoring_job_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_CreateModelDeploymentMonitoringJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + model_deployment_monitoring_job = aiplatform_v1.ModelDeploymentMonitoringJob() + model_deployment_monitoring_job.display_name = "display_name_value" + model_deployment_monitoring_job.endpoint = "endpoint_value" + + request = aiplatform_v1.CreateModelDeploymentMonitoringJobRequest( + parent="parent_value", + model_deployment_monitoring_job=model_deployment_monitoring_job, + ) + + # Make the request + response = client.create_model_deployment_monitoring_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_JobService_CreateModelDeploymentMonitoringJob_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_delete_batch_prediction_job_async.py b/samples/generated_samples/aiplatform_v1_generated_job_service_delete_batch_prediction_job_async.py new file mode 100644 index 0000000000..67f4b93ab9 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_delete_batch_prediction_job_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteBatchPredictionJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_DeleteBatchPredictionJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_batch_prediction_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteBatchPredictionJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_batch_prediction_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_JobService_DeleteBatchPredictionJob_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_delete_batch_prediction_job_sync.py b/samples/generated_samples/aiplatform_v1_generated_job_service_delete_batch_prediction_job_sync.py new file mode 100644 index 0000000000..ddf9ce0a02 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_delete_batch_prediction_job_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteBatchPredictionJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_DeleteBatchPredictionJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_batch_prediction_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteBatchPredictionJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_batch_prediction_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_JobService_DeleteBatchPredictionJob_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_delete_custom_job_async.py b/samples/generated_samples/aiplatform_v1_generated_job_service_delete_custom_job_async.py new file mode 100644 index 0000000000..c9b9eb72b2 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_delete_custom_job_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteCustomJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_DeleteCustomJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_custom_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteCustomJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_custom_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_JobService_DeleteCustomJob_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_delete_custom_job_sync.py b/samples/generated_samples/aiplatform_v1_generated_job_service_delete_custom_job_sync.py new file mode 100644 index 0000000000..e4b929844c --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_delete_custom_job_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteCustomJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_DeleteCustomJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_custom_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteCustomJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_custom_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_JobService_DeleteCustomJob_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_delete_data_labeling_job_async.py b/samples/generated_samples/aiplatform_v1_generated_job_service_delete_data_labeling_job_async.py new file mode 100644 index 0000000000..32bd9e7ebf --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_delete_data_labeling_job_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteDataLabelingJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_DeleteDataLabelingJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_data_labeling_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteDataLabelingJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_data_labeling_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_JobService_DeleteDataLabelingJob_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_delete_data_labeling_job_sync.py b/samples/generated_samples/aiplatform_v1_generated_job_service_delete_data_labeling_job_sync.py new file mode 100644 index 0000000000..3bab4949b3 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_delete_data_labeling_job_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteDataLabelingJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_DeleteDataLabelingJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_data_labeling_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteDataLabelingJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_data_labeling_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_JobService_DeleteDataLabelingJob_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_delete_hyperparameter_tuning_job_async.py b/samples/generated_samples/aiplatform_v1_generated_job_service_delete_hyperparameter_tuning_job_async.py new file mode 100644 index 0000000000..2eb5320f44 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_delete_hyperparameter_tuning_job_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteHyperparameterTuningJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_DeleteHyperparameterTuningJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteHyperparameterTuningJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_hyperparameter_tuning_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_JobService_DeleteHyperparameterTuningJob_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_delete_hyperparameter_tuning_job_sync.py b/samples/generated_samples/aiplatform_v1_generated_job_service_delete_hyperparameter_tuning_job_sync.py new file mode 100644 index 0000000000..17ba4828fa --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_delete_hyperparameter_tuning_job_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteHyperparameterTuningJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_DeleteHyperparameterTuningJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteHyperparameterTuningJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_hyperparameter_tuning_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_JobService_DeleteHyperparameterTuningJob_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_delete_model_deployment_monitoring_job_async.py b/samples/generated_samples/aiplatform_v1_generated_job_service_delete_model_deployment_monitoring_job_async.py new file mode 100644 index 0000000000..4522605729 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_delete_model_deployment_monitoring_job_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_DeleteModelDeploymentMonitoringJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_model_deployment_monitoring_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_JobService_DeleteModelDeploymentMonitoringJob_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_delete_model_deployment_monitoring_job_sync.py b/samples/generated_samples/aiplatform_v1_generated_job_service_delete_model_deployment_monitoring_job_sync.py new file mode 100644 index 0000000000..6a78a8973f --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_delete_model_deployment_monitoring_job_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_DeleteModelDeploymentMonitoringJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_model_deployment_monitoring_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_JobService_DeleteModelDeploymentMonitoringJob_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_get_batch_prediction_job_async.py b/samples/generated_samples/aiplatform_v1_generated_job_service_get_batch_prediction_job_async.py new file mode 100644 index 0000000000..4efd8ca1b8 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_get_batch_prediction_job_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetBatchPredictionJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_GetBatchPredictionJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_batch_prediction_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetBatchPredictionJobRequest( + name="name_value", + ) + + # Make the request + response = await client.get_batch_prediction_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_JobService_GetBatchPredictionJob_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_get_batch_prediction_job_sync.py b/samples/generated_samples/aiplatform_v1_generated_job_service_get_batch_prediction_job_sync.py new file mode 100644 index 0000000000..5a6ecb7dbb --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_get_batch_prediction_job_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetBatchPredictionJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_GetBatchPredictionJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_batch_prediction_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetBatchPredictionJobRequest( + name="name_value", + ) + + # Make the request + response = client.get_batch_prediction_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_JobService_GetBatchPredictionJob_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_get_custom_job_async.py b/samples/generated_samples/aiplatform_v1_generated_job_service_get_custom_job_async.py new file mode 100644 index 0000000000..0d7abd11c8 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_get_custom_job_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetCustomJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_GetCustomJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_custom_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetCustomJobRequest( + name="name_value", + ) + + # Make the request + response = await client.get_custom_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_JobService_GetCustomJob_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_get_custom_job_sync.py b/samples/generated_samples/aiplatform_v1_generated_job_service_get_custom_job_sync.py new file mode 100644 index 0000000000..9dc3ba468b --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_get_custom_job_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetCustomJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_GetCustomJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_custom_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetCustomJobRequest( + name="name_value", + ) + + # Make the request + response = client.get_custom_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_JobService_GetCustomJob_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_get_data_labeling_job_async.py b/samples/generated_samples/aiplatform_v1_generated_job_service_get_data_labeling_job_async.py new file mode 100644 index 0000000000..2050601b23 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_get_data_labeling_job_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetDataLabelingJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_GetDataLabelingJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_data_labeling_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetDataLabelingJobRequest( + name="name_value", + ) + + # Make the request + response = await client.get_data_labeling_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_JobService_GetDataLabelingJob_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_get_data_labeling_job_sync.py b/samples/generated_samples/aiplatform_v1_generated_job_service_get_data_labeling_job_sync.py new file mode 100644 index 0000000000..89b82894bf --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_get_data_labeling_job_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetDataLabelingJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_GetDataLabelingJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_data_labeling_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetDataLabelingJobRequest( + name="name_value", + ) + + # Make the request + response = client.get_data_labeling_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_JobService_GetDataLabelingJob_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_get_hyperparameter_tuning_job_async.py b/samples/generated_samples/aiplatform_v1_generated_job_service_get_hyperparameter_tuning_job_async.py new file mode 100644 index 0000000000..6a409e7d31 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_get_hyperparameter_tuning_job_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetHyperparameterTuningJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_GetHyperparameterTuningJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetHyperparameterTuningJobRequest( + name="name_value", + ) + + # Make the request + response = await client.get_hyperparameter_tuning_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_JobService_GetHyperparameterTuningJob_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_get_hyperparameter_tuning_job_sync.py b/samples/generated_samples/aiplatform_v1_generated_job_service_get_hyperparameter_tuning_job_sync.py new file mode 100644 index 0000000000..0931ff5419 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_get_hyperparameter_tuning_job_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetHyperparameterTuningJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_GetHyperparameterTuningJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetHyperparameterTuningJobRequest( + name="name_value", + ) + + # Make the request + response = client.get_hyperparameter_tuning_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_JobService_GetHyperparameterTuningJob_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_get_model_deployment_monitoring_job_async.py b/samples/generated_samples/aiplatform_v1_generated_job_service_get_model_deployment_monitoring_job_async.py new file mode 100644 index 0000000000..16f2317bf1 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_get_model_deployment_monitoring_job_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_GetModelDeploymentMonitoringJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + response = await client.get_model_deployment_monitoring_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_JobService_GetModelDeploymentMonitoringJob_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_get_model_deployment_monitoring_job_sync.py b/samples/generated_samples/aiplatform_v1_generated_job_service_get_model_deployment_monitoring_job_sync.py new file mode 100644 index 0000000000..66888d2bff --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_get_model_deployment_monitoring_job_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_GetModelDeploymentMonitoringJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + response = client.get_model_deployment_monitoring_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_JobService_GetModelDeploymentMonitoringJob_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_list_batch_prediction_jobs_async.py b/samples/generated_samples/aiplatform_v1_generated_job_service_list_batch_prediction_jobs_async.py new file mode 100644 index 0000000000..710c18549d --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_list_batch_prediction_jobs_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListBatchPredictionJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_ListBatchPredictionJobs_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_batch_prediction_jobs(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListBatchPredictionJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_batch_prediction_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1_generated_JobService_ListBatchPredictionJobs_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_list_batch_prediction_jobs_sync.py b/samples/generated_samples/aiplatform_v1_generated_job_service_list_batch_prediction_jobs_sync.py new file mode 100644 index 0000000000..58afa26785 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_list_batch_prediction_jobs_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListBatchPredictionJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_ListBatchPredictionJobs_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_batch_prediction_jobs(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListBatchPredictionJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_batch_prediction_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1_generated_JobService_ListBatchPredictionJobs_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_list_custom_jobs_async.py b/samples/generated_samples/aiplatform_v1_generated_job_service_list_custom_jobs_async.py new file mode 100644 index 0000000000..4abc6f745f --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_list_custom_jobs_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListCustomJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_ListCustomJobs_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_custom_jobs(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListCustomJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_custom_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1_generated_JobService_ListCustomJobs_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_list_custom_jobs_sync.py b/samples/generated_samples/aiplatform_v1_generated_job_service_list_custom_jobs_sync.py new file mode 100644 index 0000000000..28fc039f6b --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_list_custom_jobs_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListCustomJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_ListCustomJobs_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_custom_jobs(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListCustomJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_custom_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1_generated_JobService_ListCustomJobs_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_list_data_labeling_jobs_async.py b/samples/generated_samples/aiplatform_v1_generated_job_service_list_data_labeling_jobs_async.py new file mode 100644 index 0000000000..f1551703b9 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_list_data_labeling_jobs_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDataLabelingJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_ListDataLabelingJobs_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_data_labeling_jobs(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListDataLabelingJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_data_labeling_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1_generated_JobService_ListDataLabelingJobs_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_list_data_labeling_jobs_sync.py b/samples/generated_samples/aiplatform_v1_generated_job_service_list_data_labeling_jobs_sync.py new file mode 100644 index 0000000000..147d71dfe8 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_list_data_labeling_jobs_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDataLabelingJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_ListDataLabelingJobs_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_data_labeling_jobs(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListDataLabelingJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_data_labeling_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1_generated_JobService_ListDataLabelingJobs_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_list_hyperparameter_tuning_jobs_async.py b/samples/generated_samples/aiplatform_v1_generated_job_service_list_hyperparameter_tuning_jobs_async.py new file mode 100644 index 0000000000..362fcb40a8 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_list_hyperparameter_tuning_jobs_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListHyperparameterTuningJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_ListHyperparameterTuningJobs_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_hyperparameter_tuning_jobs(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListHyperparameterTuningJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_hyperparameter_tuning_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1_generated_JobService_ListHyperparameterTuningJobs_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_list_hyperparameter_tuning_jobs_sync.py b/samples/generated_samples/aiplatform_v1_generated_job_service_list_hyperparameter_tuning_jobs_sync.py new file mode 100644 index 0000000000..98bf35c6a3 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_list_hyperparameter_tuning_jobs_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListHyperparameterTuningJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_ListHyperparameterTuningJobs_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_hyperparameter_tuning_jobs(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListHyperparameterTuningJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_hyperparameter_tuning_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1_generated_JobService_ListHyperparameterTuningJobs_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_list_model_deployment_monitoring_jobs_async.py b/samples/generated_samples/aiplatform_v1_generated_job_service_list_model_deployment_monitoring_jobs_async.py new file mode 100644 index 0000000000..c1526e51d5 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_list_model_deployment_monitoring_jobs_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListModelDeploymentMonitoringJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_ListModelDeploymentMonitoringJobs_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_model_deployment_monitoring_jobs(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListModelDeploymentMonitoringJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_model_deployment_monitoring_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1_generated_JobService_ListModelDeploymentMonitoringJobs_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_list_model_deployment_monitoring_jobs_sync.py b/samples/generated_samples/aiplatform_v1_generated_job_service_list_model_deployment_monitoring_jobs_sync.py new file mode 100644 index 0000000000..7bfa4bc111 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_list_model_deployment_monitoring_jobs_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListModelDeploymentMonitoringJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_ListModelDeploymentMonitoringJobs_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_model_deployment_monitoring_jobs(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListModelDeploymentMonitoringJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_model_deployment_monitoring_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1_generated_JobService_ListModelDeploymentMonitoringJobs_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_pause_model_deployment_monitoring_job_async.py b/samples/generated_samples/aiplatform_v1_generated_job_service_pause_model_deployment_monitoring_job_async.py new file mode 100644 index 0000000000..b16169b7af --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_pause_model_deployment_monitoring_job_async.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PauseModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_PauseModelDeploymentMonitoringJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_pause_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.PauseModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + await client.pause_model_deployment_monitoring_job(request=request) + + +# [END aiplatform_v1_generated_JobService_PauseModelDeploymentMonitoringJob_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_pause_model_deployment_monitoring_job_sync.py b/samples/generated_samples/aiplatform_v1_generated_job_service_pause_model_deployment_monitoring_job_sync.py new file mode 100644 index 0000000000..622d2b48f0 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_pause_model_deployment_monitoring_job_sync.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PauseModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_PauseModelDeploymentMonitoringJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_pause_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.PauseModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + client.pause_model_deployment_monitoring_job(request=request) + + +# [END aiplatform_v1_generated_JobService_PauseModelDeploymentMonitoringJob_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_resume_model_deployment_monitoring_job_async.py b/samples/generated_samples/aiplatform_v1_generated_job_service_resume_model_deployment_monitoring_job_async.py new file mode 100644 index 0000000000..c354e8081d --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_resume_model_deployment_monitoring_job_async.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ResumeModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_ResumeModelDeploymentMonitoringJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_resume_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ResumeModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + await client.resume_model_deployment_monitoring_job(request=request) + + +# [END aiplatform_v1_generated_JobService_ResumeModelDeploymentMonitoringJob_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_resume_model_deployment_monitoring_job_sync.py b/samples/generated_samples/aiplatform_v1_generated_job_service_resume_model_deployment_monitoring_job_sync.py new file mode 100644 index 0000000000..01f7513482 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_resume_model_deployment_monitoring_job_sync.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ResumeModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_ResumeModelDeploymentMonitoringJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_resume_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ResumeModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + client.resume_model_deployment_monitoring_job(request=request) + + +# [END aiplatform_v1_generated_JobService_ResumeModelDeploymentMonitoringJob_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_search_model_deployment_monitoring_stats_anomalies_async.py b/samples/generated_samples/aiplatform_v1_generated_job_service_search_model_deployment_monitoring_stats_anomalies_async.py new file mode 100644 index 0000000000..c5eb2af9a0 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_search_model_deployment_monitoring_stats_anomalies_async.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SearchModelDeploymentMonitoringStatsAnomalies +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_SearchModelDeploymentMonitoringStatsAnomalies_async] +from google.cloud import aiplatform_v1 + + +async def sample_search_model_deployment_monitoring_stats_anomalies(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.SearchModelDeploymentMonitoringStatsAnomaliesRequest( + model_deployment_monitoring_job="model_deployment_monitoring_job_value", + deployed_model_id="deployed_model_id_value", + ) + + # Make the request + page_result = client.search_model_deployment_monitoring_stats_anomalies(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1_generated_JobService_SearchModelDeploymentMonitoringStatsAnomalies_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_search_model_deployment_monitoring_stats_anomalies_sync.py b/samples/generated_samples/aiplatform_v1_generated_job_service_search_model_deployment_monitoring_stats_anomalies_sync.py new file mode 100644 index 0000000000..cc7f4cc271 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_search_model_deployment_monitoring_stats_anomalies_sync.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SearchModelDeploymentMonitoringStatsAnomalies +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_SearchModelDeploymentMonitoringStatsAnomalies_sync] +from google.cloud import aiplatform_v1 + + +def sample_search_model_deployment_monitoring_stats_anomalies(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.SearchModelDeploymentMonitoringStatsAnomaliesRequest( + model_deployment_monitoring_job="model_deployment_monitoring_job_value", + deployed_model_id="deployed_model_id_value", + ) + + # Make the request + page_result = client.search_model_deployment_monitoring_stats_anomalies(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1_generated_JobService_SearchModelDeploymentMonitoringStatsAnomalies_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_update_model_deployment_monitoring_job_async.py b/samples/generated_samples/aiplatform_v1_generated_job_service_update_model_deployment_monitoring_job_async.py new file mode 100644 index 0000000000..ee8df228db --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_update_model_deployment_monitoring_job_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_UpdateModelDeploymentMonitoringJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_update_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1.JobServiceAsyncClient() + + # Initialize request argument(s) + model_deployment_monitoring_job = aiplatform_v1.ModelDeploymentMonitoringJob() + model_deployment_monitoring_job.display_name = "display_name_value" + model_deployment_monitoring_job.endpoint = "endpoint_value" + + request = aiplatform_v1.UpdateModelDeploymentMonitoringJobRequest( + model_deployment_monitoring_job=model_deployment_monitoring_job, + ) + + # Make the request + operation = client.update_model_deployment_monitoring_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_JobService_UpdateModelDeploymentMonitoringJob_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_job_service_update_model_deployment_monitoring_job_sync.py b/samples/generated_samples/aiplatform_v1_generated_job_service_update_model_deployment_monitoring_job_sync.py new file mode 100644 index 0000000000..5f5e82da6d --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_job_service_update_model_deployment_monitoring_job_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_JobService_UpdateModelDeploymentMonitoringJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_update_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1.JobServiceClient() + + # Initialize request argument(s) + model_deployment_monitoring_job = aiplatform_v1.ModelDeploymentMonitoringJob() + model_deployment_monitoring_job.display_name = "display_name_value" + model_deployment_monitoring_job.endpoint = "endpoint_value" + + request = aiplatform_v1.UpdateModelDeploymentMonitoringJobRequest( + model_deployment_monitoring_job=model_deployment_monitoring_job, + ) + + # Make the request + operation = client.update_model_deployment_monitoring_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_JobService_UpdateModelDeploymentMonitoringJob_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_add_context_artifacts_and_executions_async.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_add_context_artifacts_and_executions_async.py new file mode 100644 index 0000000000..80c217b969 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_add_context_artifacts_and_executions_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddContextArtifactsAndExecutions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_AddContextArtifactsAndExecutions_async] +from google.cloud import aiplatform_v1 + + +async def sample_add_context_artifacts_and_executions(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.AddContextArtifactsAndExecutionsRequest( + context="context_value", + ) + + # Make the request + response = await client.add_context_artifacts_and_executions(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_AddContextArtifactsAndExecutions_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_add_context_artifacts_and_executions_sync.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_add_context_artifacts_and_executions_sync.py new file mode 100644 index 0000000000..74bcf8ea59 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_add_context_artifacts_and_executions_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddContextArtifactsAndExecutions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_AddContextArtifactsAndExecutions_sync] +from google.cloud import aiplatform_v1 + + +def sample_add_context_artifacts_and_executions(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.AddContextArtifactsAndExecutionsRequest( + context="context_value", + ) + + # Make the request + response = client.add_context_artifacts_and_executions(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_AddContextArtifactsAndExecutions_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_add_context_children_async.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_add_context_children_async.py new file mode 100644 index 0000000000..acab4726a8 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_add_context_children_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddContextChildren +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_AddContextChildren_async] +from google.cloud import aiplatform_v1 + + +async def sample_add_context_children(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.AddContextChildrenRequest( + context="context_value", + ) + + # Make the request + response = await client.add_context_children(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_AddContextChildren_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_add_context_children_sync.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_add_context_children_sync.py new file mode 100644 index 0000000000..6398876b76 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_add_context_children_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddContextChildren +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_AddContextChildren_sync] +from google.cloud import aiplatform_v1 + + +def sample_add_context_children(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.AddContextChildrenRequest( + context="context_value", + ) + + # Make the request + response = client.add_context_children(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_AddContextChildren_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_add_execution_events_async.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_add_execution_events_async.py new file mode 100644 index 0000000000..89c4593000 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_add_execution_events_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddExecutionEvents +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_AddExecutionEvents_async] +from google.cloud import aiplatform_v1 + + +async def sample_add_execution_events(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.AddExecutionEventsRequest( + execution="execution_value", + ) + + # Make the request + response = await client.add_execution_events(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_AddExecutionEvents_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_add_execution_events_sync.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_add_execution_events_sync.py new file mode 100644 index 0000000000..08ea408a6e --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_add_execution_events_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddExecutionEvents +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_AddExecutionEvents_sync] +from google.cloud import aiplatform_v1 + + +def sample_add_execution_events(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.AddExecutionEventsRequest( + execution="execution_value", + ) + + # Make the request + response = client.add_execution_events(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_AddExecutionEvents_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_create_artifact_async.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_create_artifact_async.py new file mode 100644 index 0000000000..ff3af7a59e --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_create_artifact_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateArtifact +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_CreateArtifact_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_artifact(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateArtifactRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_artifact(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_CreateArtifact_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_create_artifact_sync.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_create_artifact_sync.py new file mode 100644 index 0000000000..a6d7bc372d --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_create_artifact_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateArtifact +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_CreateArtifact_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_artifact(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateArtifactRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_artifact(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_CreateArtifact_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_create_context_async.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_create_context_async.py new file mode 100644 index 0000000000..ca9e9cc4da --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_create_context_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateContext +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_CreateContext_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_context(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateContextRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_context(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_CreateContext_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_create_context_sync.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_create_context_sync.py new file mode 100644 index 0000000000..66d45fed18 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_create_context_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateContext +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_CreateContext_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_context(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateContextRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_context(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_CreateContext_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_create_execution_async.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_create_execution_async.py new file mode 100644 index 0000000000..4d27a1999f --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_create_execution_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_CreateExecution_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_execution(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateExecutionRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_execution(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_CreateExecution_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_create_execution_sync.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_create_execution_sync.py new file mode 100644 index 0000000000..8551cc9a07 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_create_execution_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_CreateExecution_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_execution(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateExecutionRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_execution(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_CreateExecution_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_create_metadata_schema_async.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_create_metadata_schema_async.py new file mode 100644 index 0000000000..435b3f49b0 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_create_metadata_schema_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateMetadataSchema +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_CreateMetadataSchema_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_metadata_schema(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + metadata_schema = aiplatform_v1.MetadataSchema() + metadata_schema.schema = "schema_value" + + request = aiplatform_v1.CreateMetadataSchemaRequest( + parent="parent_value", + metadata_schema=metadata_schema, + ) + + # Make the request + response = await client.create_metadata_schema(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_CreateMetadataSchema_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_create_metadata_schema_sync.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_create_metadata_schema_sync.py new file mode 100644 index 0000000000..8d5049d57a --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_create_metadata_schema_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateMetadataSchema +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_CreateMetadataSchema_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_metadata_schema(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + metadata_schema = aiplatform_v1.MetadataSchema() + metadata_schema.schema = "schema_value" + + request = aiplatform_v1.CreateMetadataSchemaRequest( + parent="parent_value", + metadata_schema=metadata_schema, + ) + + # Make the request + response = client.create_metadata_schema(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_CreateMetadataSchema_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_create_metadata_store_async.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_create_metadata_store_async.py new file mode 100644 index 0000000000..43b162c7cc --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_create_metadata_store_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateMetadataStore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_CreateMetadataStore_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_metadata_store(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateMetadataStoreRequest( + parent="parent_value", + ) + + # Make the request + operation = client.create_metadata_store(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_CreateMetadataStore_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_create_metadata_store_sync.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_create_metadata_store_sync.py new file mode 100644 index 0000000000..6ed4d538b7 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_create_metadata_store_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateMetadataStore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_CreateMetadataStore_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_metadata_store(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateMetadataStoreRequest( + parent="parent_value", + ) + + # Make the request + operation = client.create_metadata_store(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_CreateMetadataStore_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_delete_artifact_async.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_delete_artifact_async.py new file mode 100644 index 0000000000..0782e6c6e9 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_delete_artifact_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteArtifact +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_DeleteArtifact_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_artifact(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteArtifactRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_artifact(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_DeleteArtifact_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_delete_artifact_sync.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_delete_artifact_sync.py new file mode 100644 index 0000000000..e319867bd3 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_delete_artifact_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteArtifact +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_DeleteArtifact_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_artifact(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteArtifactRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_artifact(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_DeleteArtifact_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_delete_context_async.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_delete_context_async.py new file mode 100644 index 0000000000..ca834d7e55 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_delete_context_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteContext +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_DeleteContext_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_context(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteContextRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_context(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_DeleteContext_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_delete_context_sync.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_delete_context_sync.py new file mode 100644 index 0000000000..88d5592809 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_delete_context_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteContext +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_DeleteContext_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_context(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteContextRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_context(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_DeleteContext_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_delete_execution_async.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_delete_execution_async.py new file mode 100644 index 0000000000..4292c4d342 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_delete_execution_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_DeleteExecution_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_execution(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteExecutionRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_execution(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_DeleteExecution_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_delete_execution_sync.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_delete_execution_sync.py new file mode 100644 index 0000000000..9f053cef44 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_delete_execution_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_DeleteExecution_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_execution(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteExecutionRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_execution(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_DeleteExecution_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_delete_metadata_store_async.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_delete_metadata_store_async.py new file mode 100644 index 0000000000..1d099a727f --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_delete_metadata_store_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteMetadataStore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_DeleteMetadataStore_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_metadata_store(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteMetadataStoreRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_metadata_store(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_DeleteMetadataStore_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_delete_metadata_store_sync.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_delete_metadata_store_sync.py new file mode 100644 index 0000000000..88a154c397 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_delete_metadata_store_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteMetadataStore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_DeleteMetadataStore_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_metadata_store(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteMetadataStoreRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_metadata_store(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_DeleteMetadataStore_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_get_artifact_async.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_get_artifact_async.py new file mode 100644 index 0000000000..5e7ebf1c1f --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_get_artifact_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetArtifact +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_GetArtifact_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_artifact(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetArtifactRequest( + name="name_value", + ) + + # Make the request + response = await client.get_artifact(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_GetArtifact_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_get_artifact_sync.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_get_artifact_sync.py new file mode 100644 index 0000000000..000f7bf853 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_get_artifact_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetArtifact +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_GetArtifact_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_artifact(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetArtifactRequest( + name="name_value", + ) + + # Make the request + response = client.get_artifact(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_GetArtifact_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_get_context_async.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_get_context_async.py new file mode 100644 index 0000000000..76aff63c76 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_get_context_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetContext +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_GetContext_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_context(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetContextRequest( + name="name_value", + ) + + # Make the request + response = await client.get_context(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_GetContext_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_get_context_sync.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_get_context_sync.py new file mode 100644 index 0000000000..5d3c36ef03 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_get_context_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetContext +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_GetContext_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_context(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetContextRequest( + name="name_value", + ) + + # Make the request + response = client.get_context(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_GetContext_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_get_execution_async.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_get_execution_async.py new file mode 100644 index 0000000000..0b3d2edd97 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_get_execution_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_GetExecution_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_execution(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetExecutionRequest( + name="name_value", + ) + + # Make the request + response = await client.get_execution(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_GetExecution_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_get_execution_sync.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_get_execution_sync.py new file mode 100644 index 0000000000..f7e6e8ac6c --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_get_execution_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_GetExecution_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_execution(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetExecutionRequest( + name="name_value", + ) + + # Make the request + response = client.get_execution(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_GetExecution_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_get_metadata_schema_async.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_get_metadata_schema_async.py new file mode 100644 index 0000000000..fb93d9e1e5 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_get_metadata_schema_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetMetadataSchema +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_GetMetadataSchema_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_metadata_schema(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetMetadataSchemaRequest( + name="name_value", + ) + + # Make the request + response = await client.get_metadata_schema(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_GetMetadataSchema_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_get_metadata_schema_sync.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_get_metadata_schema_sync.py new file mode 100644 index 0000000000..84a7704069 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_get_metadata_schema_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetMetadataSchema +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_GetMetadataSchema_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_metadata_schema(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetMetadataSchemaRequest( + name="name_value", + ) + + # Make the request + response = client.get_metadata_schema(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_GetMetadataSchema_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_get_metadata_store_async.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_get_metadata_store_async.py new file mode 100644 index 0000000000..5a34b49bfc --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_get_metadata_store_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetMetadataStore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_GetMetadataStore_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_metadata_store(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetMetadataStoreRequest( + name="name_value", + ) + + # Make the request + response = await client.get_metadata_store(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_GetMetadataStore_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_get_metadata_store_sync.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_get_metadata_store_sync.py new file mode 100644 index 0000000000..d0b94f904a --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_get_metadata_store_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetMetadataStore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_GetMetadataStore_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_metadata_store(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetMetadataStoreRequest( + name="name_value", + ) + + # Make the request + response = client.get_metadata_store(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_GetMetadataStore_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_list_artifacts_async.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_list_artifacts_async.py new file mode 100644 index 0000000000..7c706a7a07 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_list_artifacts_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListArtifacts +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_ListArtifacts_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_artifacts(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListArtifactsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_artifacts(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1_generated_MetadataService_ListArtifacts_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_list_artifacts_sync.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_list_artifacts_sync.py new file mode 100644 index 0000000000..a79537af49 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_list_artifacts_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListArtifacts +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_ListArtifacts_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_artifacts(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListArtifactsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_artifacts(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1_generated_MetadataService_ListArtifacts_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_list_contexts_async.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_list_contexts_async.py new file mode 100644 index 0000000000..63fcc14ef0 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_list_contexts_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListContexts +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_ListContexts_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_contexts(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListContextsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_contexts(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1_generated_MetadataService_ListContexts_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_list_contexts_sync.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_list_contexts_sync.py new file mode 100644 index 0000000000..1b4413600f --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_list_contexts_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListContexts +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_ListContexts_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_contexts(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListContextsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_contexts(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1_generated_MetadataService_ListContexts_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_list_executions_async.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_list_executions_async.py new file mode 100644 index 0000000000..0c51f41884 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_list_executions_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListExecutions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_ListExecutions_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_executions(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListExecutionsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_executions(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1_generated_MetadataService_ListExecutions_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_list_executions_sync.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_list_executions_sync.py new file mode 100644 index 0000000000..ba0f85ed82 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_list_executions_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListExecutions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_ListExecutions_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_executions(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListExecutionsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_executions(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1_generated_MetadataService_ListExecutions_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_list_metadata_schemas_async.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_list_metadata_schemas_async.py new file mode 100644 index 0000000000..2868b533b6 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_list_metadata_schemas_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListMetadataSchemas +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_ListMetadataSchemas_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_metadata_schemas(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListMetadataSchemasRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_metadata_schemas(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1_generated_MetadataService_ListMetadataSchemas_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_list_metadata_schemas_sync.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_list_metadata_schemas_sync.py new file mode 100644 index 0000000000..b69851488e --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_list_metadata_schemas_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListMetadataSchemas +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_ListMetadataSchemas_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_metadata_schemas(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListMetadataSchemasRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_metadata_schemas(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1_generated_MetadataService_ListMetadataSchemas_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_list_metadata_stores_async.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_list_metadata_stores_async.py new file mode 100644 index 0000000000..bc16d158ef --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_list_metadata_stores_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListMetadataStores +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_ListMetadataStores_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_metadata_stores(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListMetadataStoresRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_metadata_stores(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1_generated_MetadataService_ListMetadataStores_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_list_metadata_stores_sync.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_list_metadata_stores_sync.py new file mode 100644 index 0000000000..2997676bcf --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_list_metadata_stores_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListMetadataStores +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_ListMetadataStores_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_metadata_stores(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListMetadataStoresRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_metadata_stores(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1_generated_MetadataService_ListMetadataStores_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_purge_artifacts_async.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_purge_artifacts_async.py new file mode 100644 index 0000000000..d07abcb29e --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_purge_artifacts_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PurgeArtifacts +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_PurgeArtifacts_async] +from google.cloud import aiplatform_v1 + + +async def sample_purge_artifacts(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.PurgeArtifactsRequest( + parent="parent_value", + filter="filter_value", + ) + + # Make the request + operation = client.purge_artifacts(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_PurgeArtifacts_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_purge_artifacts_sync.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_purge_artifacts_sync.py new file mode 100644 index 0000000000..798eeed330 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_purge_artifacts_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PurgeArtifacts +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_PurgeArtifacts_sync] +from google.cloud import aiplatform_v1 + + +def sample_purge_artifacts(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.PurgeArtifactsRequest( + parent="parent_value", + filter="filter_value", + ) + + # Make the request + operation = client.purge_artifacts(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_PurgeArtifacts_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_purge_contexts_async.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_purge_contexts_async.py new file mode 100644 index 0000000000..27cd785e74 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_purge_contexts_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PurgeContexts +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_PurgeContexts_async] +from google.cloud import aiplatform_v1 + + +async def sample_purge_contexts(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.PurgeContextsRequest( + parent="parent_value", + filter="filter_value", + ) + + # Make the request + operation = client.purge_contexts(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_PurgeContexts_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_purge_contexts_sync.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_purge_contexts_sync.py new file mode 100644 index 0000000000..22c2790395 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_purge_contexts_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PurgeContexts +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_PurgeContexts_sync] +from google.cloud import aiplatform_v1 + + +def sample_purge_contexts(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.PurgeContextsRequest( + parent="parent_value", + filter="filter_value", + ) + + # Make the request + operation = client.purge_contexts(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_PurgeContexts_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_purge_executions_async.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_purge_executions_async.py new file mode 100644 index 0000000000..389555139d --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_purge_executions_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PurgeExecutions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_PurgeExecutions_async] +from google.cloud import aiplatform_v1 + + +async def sample_purge_executions(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.PurgeExecutionsRequest( + parent="parent_value", + filter="filter_value", + ) + + # Make the request + operation = client.purge_executions(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_PurgeExecutions_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_purge_executions_sync.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_purge_executions_sync.py new file mode 100644 index 0000000000..65faab708e --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_purge_executions_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PurgeExecutions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_PurgeExecutions_sync] +from google.cloud import aiplatform_v1 + + +def sample_purge_executions(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.PurgeExecutionsRequest( + parent="parent_value", + filter="filter_value", + ) + + # Make the request + operation = client.purge_executions(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_PurgeExecutions_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_query_artifact_lineage_subgraph_async.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_query_artifact_lineage_subgraph_async.py new file mode 100644 index 0000000000..f3899cedb7 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_query_artifact_lineage_subgraph_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for QueryArtifactLineageSubgraph +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_QueryArtifactLineageSubgraph_async] +from google.cloud import aiplatform_v1 + + +async def sample_query_artifact_lineage_subgraph(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.QueryArtifactLineageSubgraphRequest( + artifact="artifact_value", + ) + + # Make the request + response = await client.query_artifact_lineage_subgraph(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_QueryArtifactLineageSubgraph_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_query_artifact_lineage_subgraph_sync.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_query_artifact_lineage_subgraph_sync.py new file mode 100644 index 0000000000..8cc1e0b3cc --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_query_artifact_lineage_subgraph_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for QueryArtifactLineageSubgraph +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_QueryArtifactLineageSubgraph_sync] +from google.cloud import aiplatform_v1 + + +def sample_query_artifact_lineage_subgraph(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.QueryArtifactLineageSubgraphRequest( + artifact="artifact_value", + ) + + # Make the request + response = client.query_artifact_lineage_subgraph(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_QueryArtifactLineageSubgraph_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_query_context_lineage_subgraph_async.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_query_context_lineage_subgraph_async.py new file mode 100644 index 0000000000..3f7957e959 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_query_context_lineage_subgraph_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for QueryContextLineageSubgraph +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_QueryContextLineageSubgraph_async] +from google.cloud import aiplatform_v1 + + +async def sample_query_context_lineage_subgraph(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.QueryContextLineageSubgraphRequest( + context="context_value", + ) + + # Make the request + response = await client.query_context_lineage_subgraph(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_QueryContextLineageSubgraph_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_query_context_lineage_subgraph_sync.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_query_context_lineage_subgraph_sync.py new file mode 100644 index 0000000000..ea51b51346 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_query_context_lineage_subgraph_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for QueryContextLineageSubgraph +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_QueryContextLineageSubgraph_sync] +from google.cloud import aiplatform_v1 + + +def sample_query_context_lineage_subgraph(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.QueryContextLineageSubgraphRequest( + context="context_value", + ) + + # Make the request + response = client.query_context_lineage_subgraph(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_QueryContextLineageSubgraph_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_query_execution_inputs_and_outputs_async.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_query_execution_inputs_and_outputs_async.py new file mode 100644 index 0000000000..1674db77fd --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_query_execution_inputs_and_outputs_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for QueryExecutionInputsAndOutputs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_QueryExecutionInputsAndOutputs_async] +from google.cloud import aiplatform_v1 + + +async def sample_query_execution_inputs_and_outputs(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.QueryExecutionInputsAndOutputsRequest( + execution="execution_value", + ) + + # Make the request + response = await client.query_execution_inputs_and_outputs(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_QueryExecutionInputsAndOutputs_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_query_execution_inputs_and_outputs_sync.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_query_execution_inputs_and_outputs_sync.py new file mode 100644 index 0000000000..25b5bee868 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_query_execution_inputs_and_outputs_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for QueryExecutionInputsAndOutputs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_QueryExecutionInputsAndOutputs_sync] +from google.cloud import aiplatform_v1 + + +def sample_query_execution_inputs_and_outputs(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.QueryExecutionInputsAndOutputsRequest( + execution="execution_value", + ) + + # Make the request + response = client.query_execution_inputs_and_outputs(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_QueryExecutionInputsAndOutputs_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_update_artifact_async.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_update_artifact_async.py new file mode 100644 index 0000000000..9449ab0d2d --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_update_artifact_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateArtifact +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_UpdateArtifact_async] +from google.cloud import aiplatform_v1 + + +async def sample_update_artifact(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.UpdateArtifactRequest( + ) + + # Make the request + response = await client.update_artifact(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_UpdateArtifact_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_update_artifact_sync.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_update_artifact_sync.py new file mode 100644 index 0000000000..2dabbbb514 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_update_artifact_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateArtifact +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_UpdateArtifact_sync] +from google.cloud import aiplatform_v1 + + +def sample_update_artifact(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.UpdateArtifactRequest( + ) + + # Make the request + response = client.update_artifact(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_UpdateArtifact_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_update_context_async.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_update_context_async.py new file mode 100644 index 0000000000..a3937b1ed7 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_update_context_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateContext +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_UpdateContext_async] +from google.cloud import aiplatform_v1 + + +async def sample_update_context(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.UpdateContextRequest( + ) + + # Make the request + response = await client.update_context(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_UpdateContext_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_update_context_sync.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_update_context_sync.py new file mode 100644 index 0000000000..c7b1efb0db --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_update_context_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateContext +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_UpdateContext_sync] +from google.cloud import aiplatform_v1 + + +def sample_update_context(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.UpdateContextRequest( + ) + + # Make the request + response = client.update_context(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_UpdateContext_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_update_execution_async.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_update_execution_async.py new file mode 100644 index 0000000000..1caf21f5e8 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_update_execution_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_UpdateExecution_async] +from google.cloud import aiplatform_v1 + + +async def sample_update_execution(): + # Create a client + client = aiplatform_v1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.UpdateExecutionRequest( + ) + + # Make the request + response = await client.update_execution(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_UpdateExecution_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_metadata_service_update_execution_sync.py b/samples/generated_samples/aiplatform_v1_generated_metadata_service_update_execution_sync.py new file mode 100644 index 0000000000..c44ff97fd0 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_metadata_service_update_execution_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MetadataService_UpdateExecution_sync] +from google.cloud import aiplatform_v1 + + +def sample_update_execution(): + # Create a client + client = aiplatform_v1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.UpdateExecutionRequest( + ) + + # Make the request + response = client.update_execution(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MetadataService_UpdateExecution_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_migration_service_batch_migrate_resources_async.py b/samples/generated_samples/aiplatform_v1_generated_migration_service_batch_migrate_resources_async.py new file mode 100644 index 0000000000..296fc1c8d6 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_migration_service_batch_migrate_resources_async.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchMigrateResources +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MigrationService_BatchMigrateResources_async] +from google.cloud import aiplatform_v1 + + +async def sample_batch_migrate_resources(): + # Create a client + client = aiplatform_v1.MigrationServiceAsyncClient() + + # Initialize request argument(s) + migrate_resource_requests = aiplatform_v1.MigrateResourceRequest() + migrate_resource_requests.migrate_ml_engine_model_version_config.endpoint = "endpoint_value" + migrate_resource_requests.migrate_ml_engine_model_version_config.model_version = "model_version_value" + migrate_resource_requests.migrate_ml_engine_model_version_config.model_display_name = "model_display_name_value" + + request = aiplatform_v1.BatchMigrateResourcesRequest( + parent="parent_value", + migrate_resource_requests=migrate_resource_requests, + ) + + # Make the request + operation = client.batch_migrate_resources(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MigrationService_BatchMigrateResources_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_migration_service_batch_migrate_resources_sync.py b/samples/generated_samples/aiplatform_v1_generated_migration_service_batch_migrate_resources_sync.py new file mode 100644 index 0000000000..a8d6670023 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_migration_service_batch_migrate_resources_sync.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchMigrateResources +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MigrationService_BatchMigrateResources_sync] +from google.cloud import aiplatform_v1 + + +def sample_batch_migrate_resources(): + # Create a client + client = aiplatform_v1.MigrationServiceClient() + + # Initialize request argument(s) + migrate_resource_requests = aiplatform_v1.MigrateResourceRequest() + migrate_resource_requests.migrate_ml_engine_model_version_config.endpoint = "endpoint_value" + migrate_resource_requests.migrate_ml_engine_model_version_config.model_version = "model_version_value" + migrate_resource_requests.migrate_ml_engine_model_version_config.model_display_name = "model_display_name_value" + + request = aiplatform_v1.BatchMigrateResourcesRequest( + parent="parent_value", + migrate_resource_requests=migrate_resource_requests, + ) + + # Make the request + operation = client.batch_migrate_resources(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_MigrationService_BatchMigrateResources_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_migration_service_search_migratable_resources_async.py b/samples/generated_samples/aiplatform_v1_generated_migration_service_search_migratable_resources_async.py new file mode 100644 index 0000000000..cc0ec495b7 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_migration_service_search_migratable_resources_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SearchMigratableResources +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MigrationService_SearchMigratableResources_async] +from google.cloud import aiplatform_v1 + + +async def sample_search_migratable_resources(): + # Create a client + client = aiplatform_v1.MigrationServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.SearchMigratableResourcesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.search_migratable_resources(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1_generated_MigrationService_SearchMigratableResources_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_migration_service_search_migratable_resources_sync.py b/samples/generated_samples/aiplatform_v1_generated_migration_service_search_migratable_resources_sync.py new file mode 100644 index 0000000000..081e93fa14 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_migration_service_search_migratable_resources_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SearchMigratableResources +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_MigrationService_SearchMigratableResources_sync] +from google.cloud import aiplatform_v1 + + +def sample_search_migratable_resources(): + # Create a client + client = aiplatform_v1.MigrationServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.SearchMigratableResourcesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.search_migratable_resources(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1_generated_MigrationService_SearchMigratableResources_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_model_service_delete_model_async.py b/samples/generated_samples/aiplatform_v1_generated_model_service_delete_model_async.py new file mode 100644 index 0000000000..cefd282eea --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_model_service_delete_model_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_ModelService_DeleteModel_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_model(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteModelRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_model(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_ModelService_DeleteModel_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_model_service_delete_model_sync.py b/samples/generated_samples/aiplatform_v1_generated_model_service_delete_model_sync.py new file mode 100644 index 0000000000..88b4f48cc8 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_model_service_delete_model_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_ModelService_DeleteModel_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_model(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteModelRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_model(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_ModelService_DeleteModel_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_model_service_delete_model_version_async.py b/samples/generated_samples/aiplatform_v1_generated_model_service_delete_model_version_async.py new file mode 100644 index 0000000000..cb27c3d9d8 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_model_service_delete_model_version_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteModelVersion +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_ModelService_DeleteModelVersion_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_model_version(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteModelVersionRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_model_version(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_ModelService_DeleteModelVersion_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_model_service_delete_model_version_sync.py b/samples/generated_samples/aiplatform_v1_generated_model_service_delete_model_version_sync.py new file mode 100644 index 0000000000..070da48995 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_model_service_delete_model_version_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteModelVersion +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_ModelService_DeleteModelVersion_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_model_version(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteModelVersionRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_model_version(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_ModelService_DeleteModelVersion_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_model_service_export_model_async.py b/samples/generated_samples/aiplatform_v1_generated_model_service_export_model_async.py new file mode 100644 index 0000000000..6aefde7547 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_model_service_export_model_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_ModelService_ExportModel_async] +from google.cloud import aiplatform_v1 + + +async def sample_export_model(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ExportModelRequest( + name="name_value", + ) + + # Make the request + operation = client.export_model(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_ModelService_ExportModel_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_model_service_export_model_sync.py b/samples/generated_samples/aiplatform_v1_generated_model_service_export_model_sync.py new file mode 100644 index 0000000000..ef99724551 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_model_service_export_model_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_ModelService_ExportModel_sync] +from google.cloud import aiplatform_v1 + + +def sample_export_model(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ExportModelRequest( + name="name_value", + ) + + # Make the request + operation = client.export_model(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_ModelService_ExportModel_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_model_service_get_model_async.py b/samples/generated_samples/aiplatform_v1_generated_model_service_get_model_async.py new file mode 100644 index 0000000000..f40e0f6b33 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_model_service_get_model_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_ModelService_GetModel_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_model(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetModelRequest( + name="name_value", + ) + + # Make the request + response = await client.get_model(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_ModelService_GetModel_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_model_service_get_model_evaluation_async.py b/samples/generated_samples/aiplatform_v1_generated_model_service_get_model_evaluation_async.py new file mode 100644 index 0000000000..3aeb38f93b --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_model_service_get_model_evaluation_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetModelEvaluation +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_ModelService_GetModelEvaluation_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_model_evaluation(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetModelEvaluationRequest( + name="name_value", + ) + + # Make the request + response = await client.get_model_evaluation(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_ModelService_GetModelEvaluation_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_model_service_get_model_evaluation_slice_async.py b/samples/generated_samples/aiplatform_v1_generated_model_service_get_model_evaluation_slice_async.py new file mode 100644 index 0000000000..f9513d9962 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_model_service_get_model_evaluation_slice_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetModelEvaluationSlice +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_ModelService_GetModelEvaluationSlice_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_model_evaluation_slice(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetModelEvaluationSliceRequest( + name="name_value", + ) + + # Make the request + response = await client.get_model_evaluation_slice(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_ModelService_GetModelEvaluationSlice_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_model_service_get_model_evaluation_slice_sync.py b/samples/generated_samples/aiplatform_v1_generated_model_service_get_model_evaluation_slice_sync.py new file mode 100644 index 0000000000..722f24ae6f --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_model_service_get_model_evaluation_slice_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetModelEvaluationSlice +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_ModelService_GetModelEvaluationSlice_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_model_evaluation_slice(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetModelEvaluationSliceRequest( + name="name_value", + ) + + # Make the request + response = client.get_model_evaluation_slice(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_ModelService_GetModelEvaluationSlice_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_model_service_get_model_evaluation_sync.py b/samples/generated_samples/aiplatform_v1_generated_model_service_get_model_evaluation_sync.py new file mode 100644 index 0000000000..1c0ade5d12 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_model_service_get_model_evaluation_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetModelEvaluation +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_ModelService_GetModelEvaluation_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_model_evaluation(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetModelEvaluationRequest( + name="name_value", + ) + + # Make the request + response = client.get_model_evaluation(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_ModelService_GetModelEvaluation_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_model_service_get_model_sync.py b/samples/generated_samples/aiplatform_v1_generated_model_service_get_model_sync.py new file mode 100644 index 0000000000..ef2733a3ba --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_model_service_get_model_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_ModelService_GetModel_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_model(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetModelRequest( + name="name_value", + ) + + # Make the request + response = client.get_model(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_ModelService_GetModel_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_model_service_import_model_evaluation_async.py b/samples/generated_samples/aiplatform_v1_generated_model_service_import_model_evaluation_async.py new file mode 100644 index 0000000000..d705d6505f --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_model_service_import_model_evaluation_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ImportModelEvaluation +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_ModelService_ImportModelEvaluation_async] +from google.cloud import aiplatform_v1 + + +async def sample_import_model_evaluation(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ImportModelEvaluationRequest( + parent="parent_value", + ) + + # Make the request + response = await client.import_model_evaluation(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_ModelService_ImportModelEvaluation_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_model_service_import_model_evaluation_sync.py b/samples/generated_samples/aiplatform_v1_generated_model_service_import_model_evaluation_sync.py new file mode 100644 index 0000000000..f2910ac56e --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_model_service_import_model_evaluation_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ImportModelEvaluation +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_ModelService_ImportModelEvaluation_sync] +from google.cloud import aiplatform_v1 + + +def sample_import_model_evaluation(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ImportModelEvaluationRequest( + parent="parent_value", + ) + + # Make the request + response = client.import_model_evaluation(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_ModelService_ImportModelEvaluation_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_model_service_list_model_evaluation_slices_async.py b/samples/generated_samples/aiplatform_v1_generated_model_service_list_model_evaluation_slices_async.py new file mode 100644 index 0000000000..eb053302bd --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_model_service_list_model_evaluation_slices_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListModelEvaluationSlices +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_ModelService_ListModelEvaluationSlices_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_model_evaluation_slices(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListModelEvaluationSlicesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_model_evaluation_slices(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1_generated_ModelService_ListModelEvaluationSlices_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_model_service_list_model_evaluation_slices_sync.py b/samples/generated_samples/aiplatform_v1_generated_model_service_list_model_evaluation_slices_sync.py new file mode 100644 index 0000000000..6b1537fb90 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_model_service_list_model_evaluation_slices_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListModelEvaluationSlices +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_ModelService_ListModelEvaluationSlices_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_model_evaluation_slices(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListModelEvaluationSlicesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_model_evaluation_slices(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1_generated_ModelService_ListModelEvaluationSlices_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_model_service_list_model_evaluations_async.py b/samples/generated_samples/aiplatform_v1_generated_model_service_list_model_evaluations_async.py new file mode 100644 index 0000000000..855b1efb42 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_model_service_list_model_evaluations_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListModelEvaluations +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_ModelService_ListModelEvaluations_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_model_evaluations(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListModelEvaluationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_model_evaluations(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1_generated_ModelService_ListModelEvaluations_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_model_service_list_model_evaluations_sync.py b/samples/generated_samples/aiplatform_v1_generated_model_service_list_model_evaluations_sync.py new file mode 100644 index 0000000000..49d2f98139 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_model_service_list_model_evaluations_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListModelEvaluations +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_ModelService_ListModelEvaluations_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_model_evaluations(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListModelEvaluationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_model_evaluations(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1_generated_ModelService_ListModelEvaluations_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_model_service_list_model_versions_async.py b/samples/generated_samples/aiplatform_v1_generated_model_service_list_model_versions_async.py new file mode 100644 index 0000000000..f930d0c3a2 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_model_service_list_model_versions_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListModelVersions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_ModelService_ListModelVersions_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_model_versions(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListModelVersionsRequest( + name="name_value", + ) + + # Make the request + page_result = client.list_model_versions(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1_generated_ModelService_ListModelVersions_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_model_service_list_model_versions_sync.py b/samples/generated_samples/aiplatform_v1_generated_model_service_list_model_versions_sync.py new file mode 100644 index 0000000000..3403c2de8e --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_model_service_list_model_versions_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListModelVersions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_ModelService_ListModelVersions_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_model_versions(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListModelVersionsRequest( + name="name_value", + ) + + # Make the request + page_result = client.list_model_versions(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1_generated_ModelService_ListModelVersions_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_model_service_list_models_async.py b/samples/generated_samples/aiplatform_v1_generated_model_service_list_models_async.py new file mode 100644 index 0000000000..17cd1ed4d2 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_model_service_list_models_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListModels +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_ModelService_ListModels_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_models(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListModelsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_models(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1_generated_ModelService_ListModels_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_model_service_list_models_sync.py b/samples/generated_samples/aiplatform_v1_generated_model_service_list_models_sync.py new file mode 100644 index 0000000000..9a36fe9e08 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_model_service_list_models_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListModels +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_ModelService_ListModels_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_models(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListModelsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_models(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1_generated_ModelService_ListModels_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_model_service_merge_version_aliases_async.py b/samples/generated_samples/aiplatform_v1_generated_model_service_merge_version_aliases_async.py new file mode 100644 index 0000000000..f48cf4b425 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_model_service_merge_version_aliases_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for MergeVersionAliases +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_ModelService_MergeVersionAliases_async] +from google.cloud import aiplatform_v1 + + +async def sample_merge_version_aliases(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.MergeVersionAliasesRequest( + name="name_value", + version_aliases=['version_aliases_value_1', 'version_aliases_value_2'], + ) + + # Make the request + response = await client.merge_version_aliases(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_ModelService_MergeVersionAliases_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_model_service_merge_version_aliases_sync.py b/samples/generated_samples/aiplatform_v1_generated_model_service_merge_version_aliases_sync.py new file mode 100644 index 0000000000..b7ac00822d --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_model_service_merge_version_aliases_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for MergeVersionAliases +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_ModelService_MergeVersionAliases_sync] +from google.cloud import aiplatform_v1 + + +def sample_merge_version_aliases(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.MergeVersionAliasesRequest( + name="name_value", + version_aliases=['version_aliases_value_1', 'version_aliases_value_2'], + ) + + # Make the request + response = client.merge_version_aliases(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_ModelService_MergeVersionAliases_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_model_service_update_model_async.py b/samples/generated_samples/aiplatform_v1_generated_model_service_update_model_async.py new file mode 100644 index 0000000000..a9e19dedaf --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_model_service_update_model_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_ModelService_UpdateModel_async] +from google.cloud import aiplatform_v1 + + +async def sample_update_model(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + model = aiplatform_v1.Model() + model.display_name = "display_name_value" + + request = aiplatform_v1.UpdateModelRequest( + model=model, + ) + + # Make the request + response = await client.update_model(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_ModelService_UpdateModel_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_model_service_update_model_sync.py b/samples/generated_samples/aiplatform_v1_generated_model_service_update_model_sync.py new file mode 100644 index 0000000000..c2721d40c8 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_model_service_update_model_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_ModelService_UpdateModel_sync] +from google.cloud import aiplatform_v1 + + +def sample_update_model(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + model = aiplatform_v1.Model() + model.display_name = "display_name_value" + + request = aiplatform_v1.UpdateModelRequest( + model=model, + ) + + # Make the request + response = client.update_model(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_ModelService_UpdateModel_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_model_service_upload_model_async.py b/samples/generated_samples/aiplatform_v1_generated_model_service_upload_model_async.py new file mode 100644 index 0000000000..66dcd0d0dd --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_model_service_upload_model_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UploadModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_ModelService_UploadModel_async] +from google.cloud import aiplatform_v1 + + +async def sample_upload_model(): + # Create a client + client = aiplatform_v1.ModelServiceAsyncClient() + + # Initialize request argument(s) + model = aiplatform_v1.Model() + model.display_name = "display_name_value" + + request = aiplatform_v1.UploadModelRequest( + parent="parent_value", + model=model, + ) + + # Make the request + operation = client.upload_model(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_ModelService_UploadModel_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_model_service_upload_model_sync.py b/samples/generated_samples/aiplatform_v1_generated_model_service_upload_model_sync.py new file mode 100644 index 0000000000..47abf4e6aa --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_model_service_upload_model_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UploadModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_ModelService_UploadModel_sync] +from google.cloud import aiplatform_v1 + + +def sample_upload_model(): + # Create a client + client = aiplatform_v1.ModelServiceClient() + + # Initialize request argument(s) + model = aiplatform_v1.Model() + model.display_name = "display_name_value" + + request = aiplatform_v1.UploadModelRequest( + parent="parent_value", + model=model, + ) + + # Make the request + operation = client.upload_model(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_ModelService_UploadModel_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_pipeline_service_cancel_pipeline_job_async.py b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_cancel_pipeline_job_async.py new file mode 100644 index 0000000000..4c7f478f37 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_cancel_pipeline_job_async.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelPipelineJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_PipelineService_CancelPipelineJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_cancel_pipeline_job(): + # Create a client + client = aiplatform_v1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CancelPipelineJobRequest( + name="name_value", + ) + + # Make the request + await client.cancel_pipeline_job(request=request) + + +# [END aiplatform_v1_generated_PipelineService_CancelPipelineJob_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_pipeline_service_cancel_pipeline_job_sync.py b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_cancel_pipeline_job_sync.py new file mode 100644 index 0000000000..a65be7ac8e --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_cancel_pipeline_job_sync.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelPipelineJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_PipelineService_CancelPipelineJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_cancel_pipeline_job(): + # Create a client + client = aiplatform_v1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CancelPipelineJobRequest( + name="name_value", + ) + + # Make the request + client.cancel_pipeline_job(request=request) + + +# [END aiplatform_v1_generated_PipelineService_CancelPipelineJob_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_pipeline_service_cancel_training_pipeline_async.py b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_cancel_training_pipeline_async.py new file mode 100644 index 0000000000..69622f77c2 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_cancel_training_pipeline_async.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelTrainingPipeline +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_PipelineService_CancelTrainingPipeline_async] +from google.cloud import aiplatform_v1 + + +async def sample_cancel_training_pipeline(): + # Create a client + client = aiplatform_v1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CancelTrainingPipelineRequest( + name="name_value", + ) + + # Make the request + await client.cancel_training_pipeline(request=request) + + +# [END aiplatform_v1_generated_PipelineService_CancelTrainingPipeline_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_pipeline_service_cancel_training_pipeline_sync.py b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_cancel_training_pipeline_sync.py new file mode 100644 index 0000000000..51f261d32a --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_cancel_training_pipeline_sync.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelTrainingPipeline +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_PipelineService_CancelTrainingPipeline_sync] +from google.cloud import aiplatform_v1 + + +def sample_cancel_training_pipeline(): + # Create a client + client = aiplatform_v1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CancelTrainingPipelineRequest( + name="name_value", + ) + + # Make the request + client.cancel_training_pipeline(request=request) + + +# [END aiplatform_v1_generated_PipelineService_CancelTrainingPipeline_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_pipeline_service_create_pipeline_job_async.py b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_create_pipeline_job_async.py new file mode 100644 index 0000000000..64a5345922 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_create_pipeline_job_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreatePipelineJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_PipelineService_CreatePipelineJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_pipeline_job(): + # Create a client + client = aiplatform_v1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreatePipelineJobRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_pipeline_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_PipelineService_CreatePipelineJob_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_pipeline_service_create_pipeline_job_sync.py b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_create_pipeline_job_sync.py new file mode 100644 index 0000000000..5ade700a43 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_create_pipeline_job_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreatePipelineJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_PipelineService_CreatePipelineJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_pipeline_job(): + # Create a client + client = aiplatform_v1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreatePipelineJobRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_pipeline_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_PipelineService_CreatePipelineJob_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_pipeline_service_create_training_pipeline_async.py b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_create_training_pipeline_async.py new file mode 100644 index 0000000000..20d89bed38 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_create_training_pipeline_async.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTrainingPipeline +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_PipelineService_CreateTrainingPipeline_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_training_pipeline(): + # Create a client + client = aiplatform_v1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + training_pipeline = aiplatform_v1.TrainingPipeline() + training_pipeline.display_name = "display_name_value" + training_pipeline.training_task_definition = "training_task_definition_value" + training_pipeline.training_task_inputs.null_value = "NULL_VALUE" + + request = aiplatform_v1.CreateTrainingPipelineRequest( + parent="parent_value", + training_pipeline=training_pipeline, + ) + + # Make the request + response = await client.create_training_pipeline(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_PipelineService_CreateTrainingPipeline_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_pipeline_service_create_training_pipeline_sync.py b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_create_training_pipeline_sync.py new file mode 100644 index 0000000000..33bfc0e76a --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_create_training_pipeline_sync.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTrainingPipeline +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_PipelineService_CreateTrainingPipeline_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_training_pipeline(): + # Create a client + client = aiplatform_v1.PipelineServiceClient() + + # Initialize request argument(s) + training_pipeline = aiplatform_v1.TrainingPipeline() + training_pipeline.display_name = "display_name_value" + training_pipeline.training_task_definition = "training_task_definition_value" + training_pipeline.training_task_inputs.null_value = "NULL_VALUE" + + request = aiplatform_v1.CreateTrainingPipelineRequest( + parent="parent_value", + training_pipeline=training_pipeline, + ) + + # Make the request + response = client.create_training_pipeline(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_PipelineService_CreateTrainingPipeline_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_pipeline_service_delete_pipeline_job_async.py b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_delete_pipeline_job_async.py new file mode 100644 index 0000000000..194f78a217 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_delete_pipeline_job_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeletePipelineJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_PipelineService_DeletePipelineJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_pipeline_job(): + # Create a client + client = aiplatform_v1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeletePipelineJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_pipeline_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_PipelineService_DeletePipelineJob_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_pipeline_service_delete_pipeline_job_sync.py b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_delete_pipeline_job_sync.py new file mode 100644 index 0000000000..9f0dec1566 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_delete_pipeline_job_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeletePipelineJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_PipelineService_DeletePipelineJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_pipeline_job(): + # Create a client + client = aiplatform_v1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeletePipelineJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_pipeline_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_PipelineService_DeletePipelineJob_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_pipeline_service_delete_training_pipeline_async.py b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_delete_training_pipeline_async.py new file mode 100644 index 0000000000..ffe3d6f1f1 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_delete_training_pipeline_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTrainingPipeline +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_PipelineService_DeleteTrainingPipeline_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_training_pipeline(): + # Create a client + client = aiplatform_v1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteTrainingPipelineRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_training_pipeline(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_PipelineService_DeleteTrainingPipeline_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_pipeline_service_delete_training_pipeline_sync.py b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_delete_training_pipeline_sync.py new file mode 100644 index 0000000000..790fb6a3cd --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_delete_training_pipeline_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTrainingPipeline +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_PipelineService_DeleteTrainingPipeline_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_training_pipeline(): + # Create a client + client = aiplatform_v1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteTrainingPipelineRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_training_pipeline(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_PipelineService_DeleteTrainingPipeline_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_pipeline_service_get_pipeline_job_async.py b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_get_pipeline_job_async.py new file mode 100644 index 0000000000..452220e044 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_get_pipeline_job_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetPipelineJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_PipelineService_GetPipelineJob_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_pipeline_job(): + # Create a client + client = aiplatform_v1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetPipelineJobRequest( + name="name_value", + ) + + # Make the request + response = await client.get_pipeline_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_PipelineService_GetPipelineJob_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_pipeline_service_get_pipeline_job_sync.py b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_get_pipeline_job_sync.py new file mode 100644 index 0000000000..a03dcab198 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_get_pipeline_job_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetPipelineJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_PipelineService_GetPipelineJob_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_pipeline_job(): + # Create a client + client = aiplatform_v1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetPipelineJobRequest( + name="name_value", + ) + + # Make the request + response = client.get_pipeline_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_PipelineService_GetPipelineJob_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_pipeline_service_get_training_pipeline_async.py b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_get_training_pipeline_async.py new file mode 100644 index 0000000000..08205ada78 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_get_training_pipeline_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTrainingPipeline +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_PipelineService_GetTrainingPipeline_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_training_pipeline(): + # Create a client + client = aiplatform_v1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetTrainingPipelineRequest( + name="name_value", + ) + + # Make the request + response = await client.get_training_pipeline(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_PipelineService_GetTrainingPipeline_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_pipeline_service_get_training_pipeline_sync.py b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_get_training_pipeline_sync.py new file mode 100644 index 0000000000..41675e136a --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_get_training_pipeline_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTrainingPipeline +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_PipelineService_GetTrainingPipeline_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_training_pipeline(): + # Create a client + client = aiplatform_v1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetTrainingPipelineRequest( + name="name_value", + ) + + # Make the request + response = client.get_training_pipeline(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_PipelineService_GetTrainingPipeline_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_pipeline_service_list_pipeline_jobs_async.py b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_list_pipeline_jobs_async.py new file mode 100644 index 0000000000..35a5c83dc9 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_list_pipeline_jobs_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListPipelineJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_PipelineService_ListPipelineJobs_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_pipeline_jobs(): + # Create a client + client = aiplatform_v1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListPipelineJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_pipeline_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1_generated_PipelineService_ListPipelineJobs_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_pipeline_service_list_pipeline_jobs_sync.py b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_list_pipeline_jobs_sync.py new file mode 100644 index 0000000000..23091c2308 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_list_pipeline_jobs_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListPipelineJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_PipelineService_ListPipelineJobs_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_pipeline_jobs(): + # Create a client + client = aiplatform_v1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListPipelineJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_pipeline_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1_generated_PipelineService_ListPipelineJobs_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_pipeline_service_list_training_pipelines_async.py b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_list_training_pipelines_async.py new file mode 100644 index 0000000000..b17757b0a1 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_list_training_pipelines_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTrainingPipelines +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_PipelineService_ListTrainingPipelines_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_training_pipelines(): + # Create a client + client = aiplatform_v1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListTrainingPipelinesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_training_pipelines(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1_generated_PipelineService_ListTrainingPipelines_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_pipeline_service_list_training_pipelines_sync.py b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_list_training_pipelines_sync.py new file mode 100644 index 0000000000..1ff3c708f1 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_pipeline_service_list_training_pipelines_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTrainingPipelines +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_PipelineService_ListTrainingPipelines_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_training_pipelines(): + # Create a client + client = aiplatform_v1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListTrainingPipelinesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_training_pipelines(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1_generated_PipelineService_ListTrainingPipelines_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_prediction_service_explain_async.py b/samples/generated_samples/aiplatform_v1_generated_prediction_service_explain_async.py new file mode 100644 index 0000000000..5e5d44a881 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_prediction_service_explain_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for Explain +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_PredictionService_Explain_async] +from google.cloud import aiplatform_v1 + + +async def sample_explain(): + # Create a client + client = aiplatform_v1.PredictionServiceAsyncClient() + + # Initialize request argument(s) + instances = aiplatform_v1.Value() + instances.null_value = "NULL_VALUE" + + request = aiplatform_v1.ExplainRequest( + endpoint="endpoint_value", + instances=instances, + ) + + # Make the request + response = await client.explain(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_PredictionService_Explain_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_prediction_service_explain_sync.py b/samples/generated_samples/aiplatform_v1_generated_prediction_service_explain_sync.py new file mode 100644 index 0000000000..7c95bbaa5f --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_prediction_service_explain_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for Explain +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_PredictionService_Explain_sync] +from google.cloud import aiplatform_v1 + + +def sample_explain(): + # Create a client + client = aiplatform_v1.PredictionServiceClient() + + # Initialize request argument(s) + instances = aiplatform_v1.Value() + instances.null_value = "NULL_VALUE" + + request = aiplatform_v1.ExplainRequest( + endpoint="endpoint_value", + instances=instances, + ) + + # Make the request + response = client.explain(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_PredictionService_Explain_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_prediction_service_predict_async.py b/samples/generated_samples/aiplatform_v1_generated_prediction_service_predict_async.py new file mode 100644 index 0000000000..70c1e46874 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_prediction_service_predict_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for Predict +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_PredictionService_Predict_async] +from google.cloud import aiplatform_v1 + + +async def sample_predict(): + # Create a client + client = aiplatform_v1.PredictionServiceAsyncClient() + + # Initialize request argument(s) + instances = aiplatform_v1.Value() + instances.null_value = "NULL_VALUE" + + request = aiplatform_v1.PredictRequest( + endpoint="endpoint_value", + instances=instances, + ) + + # Make the request + response = await client.predict(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_PredictionService_Predict_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_prediction_service_predict_sync.py b/samples/generated_samples/aiplatform_v1_generated_prediction_service_predict_sync.py new file mode 100644 index 0000000000..d57a908d0a --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_prediction_service_predict_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for Predict +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_PredictionService_Predict_sync] +from google.cloud import aiplatform_v1 + + +def sample_predict(): + # Create a client + client = aiplatform_v1.PredictionServiceClient() + + # Initialize request argument(s) + instances = aiplatform_v1.Value() + instances.null_value = "NULL_VALUE" + + request = aiplatform_v1.PredictRequest( + endpoint="endpoint_value", + instances=instances, + ) + + # Make the request + response = client.predict(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_PredictionService_Predict_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_prediction_service_raw_predict_async.py b/samples/generated_samples/aiplatform_v1_generated_prediction_service_raw_predict_async.py new file mode 100644 index 0000000000..b8d3ae2619 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_prediction_service_raw_predict_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for RawPredict +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_PredictionService_RawPredict_async] +from google.cloud import aiplatform_v1 + + +async def sample_raw_predict(): + # Create a client + client = aiplatform_v1.PredictionServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.RawPredictRequest( + endpoint="endpoint_value", + ) + + # Make the request + response = await client.raw_predict(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_PredictionService_RawPredict_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_prediction_service_raw_predict_sync.py b/samples/generated_samples/aiplatform_v1_generated_prediction_service_raw_predict_sync.py new file mode 100644 index 0000000000..86f6e85494 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_prediction_service_raw_predict_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for RawPredict +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_PredictionService_RawPredict_sync] +from google.cloud import aiplatform_v1 + + +def sample_raw_predict(): + # Create a client + client = aiplatform_v1.PredictionServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.RawPredictRequest( + endpoint="endpoint_value", + ) + + # Make the request + response = client.raw_predict(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_PredictionService_RawPredict_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_specialist_pool_service_create_specialist_pool_async.py b/samples/generated_samples/aiplatform_v1_generated_specialist_pool_service_create_specialist_pool_async.py new file mode 100644 index 0000000000..79033d48e4 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_specialist_pool_service_create_specialist_pool_async.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateSpecialistPool +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_SpecialistPoolService_CreateSpecialistPool_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_specialist_pool(): + # Create a client + client = aiplatform_v1.SpecialistPoolServiceAsyncClient() + + # Initialize request argument(s) + specialist_pool = aiplatform_v1.SpecialistPool() + specialist_pool.name = "name_value" + specialist_pool.display_name = "display_name_value" + + request = aiplatform_v1.CreateSpecialistPoolRequest( + parent="parent_value", + specialist_pool=specialist_pool, + ) + + # Make the request + operation = client.create_specialist_pool(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_SpecialistPoolService_CreateSpecialistPool_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_specialist_pool_service_create_specialist_pool_sync.py b/samples/generated_samples/aiplatform_v1_generated_specialist_pool_service_create_specialist_pool_sync.py new file mode 100644 index 0000000000..03d448f25e --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_specialist_pool_service_create_specialist_pool_sync.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateSpecialistPool +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_SpecialistPoolService_CreateSpecialistPool_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_specialist_pool(): + # Create a client + client = aiplatform_v1.SpecialistPoolServiceClient() + + # Initialize request argument(s) + specialist_pool = aiplatform_v1.SpecialistPool() + specialist_pool.name = "name_value" + specialist_pool.display_name = "display_name_value" + + request = aiplatform_v1.CreateSpecialistPoolRequest( + parent="parent_value", + specialist_pool=specialist_pool, + ) + + # Make the request + operation = client.create_specialist_pool(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_SpecialistPoolService_CreateSpecialistPool_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_specialist_pool_service_delete_specialist_pool_async.py b/samples/generated_samples/aiplatform_v1_generated_specialist_pool_service_delete_specialist_pool_async.py new file mode 100644 index 0000000000..d3bcbc7eec --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_specialist_pool_service_delete_specialist_pool_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteSpecialistPool +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_SpecialistPoolService_DeleteSpecialistPool_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_specialist_pool(): + # Create a client + client = aiplatform_v1.SpecialistPoolServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteSpecialistPoolRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_specialist_pool(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_SpecialistPoolService_DeleteSpecialistPool_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_specialist_pool_service_delete_specialist_pool_sync.py b/samples/generated_samples/aiplatform_v1_generated_specialist_pool_service_delete_specialist_pool_sync.py new file mode 100644 index 0000000000..c575d152ac --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_specialist_pool_service_delete_specialist_pool_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteSpecialistPool +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_SpecialistPoolService_DeleteSpecialistPool_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_specialist_pool(): + # Create a client + client = aiplatform_v1.SpecialistPoolServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteSpecialistPoolRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_specialist_pool(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_SpecialistPoolService_DeleteSpecialistPool_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_specialist_pool_service_get_specialist_pool_async.py b/samples/generated_samples/aiplatform_v1_generated_specialist_pool_service_get_specialist_pool_async.py new file mode 100644 index 0000000000..d47c5c9d85 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_specialist_pool_service_get_specialist_pool_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetSpecialistPool +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_SpecialistPoolService_GetSpecialistPool_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_specialist_pool(): + # Create a client + client = aiplatform_v1.SpecialistPoolServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetSpecialistPoolRequest( + name="name_value", + ) + + # Make the request + response = await client.get_specialist_pool(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_SpecialistPoolService_GetSpecialistPool_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_specialist_pool_service_get_specialist_pool_sync.py b/samples/generated_samples/aiplatform_v1_generated_specialist_pool_service_get_specialist_pool_sync.py new file mode 100644 index 0000000000..a08a7b83bb --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_specialist_pool_service_get_specialist_pool_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetSpecialistPool +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_SpecialistPoolService_GetSpecialistPool_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_specialist_pool(): + # Create a client + client = aiplatform_v1.SpecialistPoolServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetSpecialistPoolRequest( + name="name_value", + ) + + # Make the request + response = client.get_specialist_pool(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_SpecialistPoolService_GetSpecialistPool_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_specialist_pool_service_list_specialist_pools_async.py b/samples/generated_samples/aiplatform_v1_generated_specialist_pool_service_list_specialist_pools_async.py new file mode 100644 index 0000000000..cbba73a939 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_specialist_pool_service_list_specialist_pools_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListSpecialistPools +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_SpecialistPoolService_ListSpecialistPools_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_specialist_pools(): + # Create a client + client = aiplatform_v1.SpecialistPoolServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListSpecialistPoolsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_specialist_pools(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1_generated_SpecialistPoolService_ListSpecialistPools_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_specialist_pool_service_list_specialist_pools_sync.py b/samples/generated_samples/aiplatform_v1_generated_specialist_pool_service_list_specialist_pools_sync.py new file mode 100644 index 0000000000..382fb61856 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_specialist_pool_service_list_specialist_pools_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListSpecialistPools +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_SpecialistPoolService_ListSpecialistPools_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_specialist_pools(): + # Create a client + client = aiplatform_v1.SpecialistPoolServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListSpecialistPoolsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_specialist_pools(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1_generated_SpecialistPoolService_ListSpecialistPools_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_specialist_pool_service_update_specialist_pool_async.py b/samples/generated_samples/aiplatform_v1_generated_specialist_pool_service_update_specialist_pool_async.py new file mode 100644 index 0000000000..e44a1e168e --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_specialist_pool_service_update_specialist_pool_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateSpecialistPool +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_SpecialistPoolService_UpdateSpecialistPool_async] +from google.cloud import aiplatform_v1 + + +async def sample_update_specialist_pool(): + # Create a client + client = aiplatform_v1.SpecialistPoolServiceAsyncClient() + + # Initialize request argument(s) + specialist_pool = aiplatform_v1.SpecialistPool() + specialist_pool.name = "name_value" + specialist_pool.display_name = "display_name_value" + + request = aiplatform_v1.UpdateSpecialistPoolRequest( + specialist_pool=specialist_pool, + ) + + # Make the request + operation = client.update_specialist_pool(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_SpecialistPoolService_UpdateSpecialistPool_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_specialist_pool_service_update_specialist_pool_sync.py b/samples/generated_samples/aiplatform_v1_generated_specialist_pool_service_update_specialist_pool_sync.py new file mode 100644 index 0000000000..d4fa9f0115 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_specialist_pool_service_update_specialist_pool_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateSpecialistPool +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_SpecialistPoolService_UpdateSpecialistPool_sync] +from google.cloud import aiplatform_v1 + + +def sample_update_specialist_pool(): + # Create a client + client = aiplatform_v1.SpecialistPoolServiceClient() + + # Initialize request argument(s) + specialist_pool = aiplatform_v1.SpecialistPool() + specialist_pool.name = "name_value" + specialist_pool.display_name = "display_name_value" + + request = aiplatform_v1.UpdateSpecialistPoolRequest( + specialist_pool=specialist_pool, + ) + + # Make the request + operation = client.update_specialist_pool(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_SpecialistPoolService_UpdateSpecialistPool_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_batch_create_tensorboard_runs_async.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_batch_create_tensorboard_runs_async.py new file mode 100644 index 0000000000..00eb92475a --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_batch_create_tensorboard_runs_async.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchCreateTensorboardRuns +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_BatchCreateTensorboardRuns_async] +from google.cloud import aiplatform_v1 + + +async def sample_batch_create_tensorboard_runs(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + requests = aiplatform_v1.CreateTensorboardRunRequest() + requests.parent = "parent_value" + requests.tensorboard_run.display_name = "display_name_value" + requests.tensorboard_run_id = "tensorboard_run_id_value" + + request = aiplatform_v1.BatchCreateTensorboardRunsRequest( + parent="parent_value", + requests=requests, + ) + + # Make the request + response = await client.batch_create_tensorboard_runs(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_BatchCreateTensorboardRuns_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_batch_create_tensorboard_runs_sync.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_batch_create_tensorboard_runs_sync.py new file mode 100644 index 0000000000..d74544e6f7 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_batch_create_tensorboard_runs_sync.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchCreateTensorboardRuns +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_BatchCreateTensorboardRuns_sync] +from google.cloud import aiplatform_v1 + + +def sample_batch_create_tensorboard_runs(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + requests = aiplatform_v1.CreateTensorboardRunRequest() + requests.parent = "parent_value" + requests.tensorboard_run.display_name = "display_name_value" + requests.tensorboard_run_id = "tensorboard_run_id_value" + + request = aiplatform_v1.BatchCreateTensorboardRunsRequest( + parent="parent_value", + requests=requests, + ) + + # Make the request + response = client.batch_create_tensorboard_runs(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_BatchCreateTensorboardRuns_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_batch_create_tensorboard_time_series_async.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_batch_create_tensorboard_time_series_async.py new file mode 100644 index 0000000000..4406ccc535 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_batch_create_tensorboard_time_series_async.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchCreateTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_BatchCreateTensorboardTimeSeries_async] +from google.cloud import aiplatform_v1 + + +async def sample_batch_create_tensorboard_time_series(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + requests = aiplatform_v1.CreateTensorboardTimeSeriesRequest() + requests.parent = "parent_value" + requests.tensorboard_time_series.display_name = "display_name_value" + requests.tensorboard_time_series.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1.BatchCreateTensorboardTimeSeriesRequest( + parent="parent_value", + requests=requests, + ) + + # Make the request + response = await client.batch_create_tensorboard_time_series(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_BatchCreateTensorboardTimeSeries_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_batch_create_tensorboard_time_series_sync.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_batch_create_tensorboard_time_series_sync.py new file mode 100644 index 0000000000..c491c0e0ce --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_batch_create_tensorboard_time_series_sync.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchCreateTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_BatchCreateTensorboardTimeSeries_sync] +from google.cloud import aiplatform_v1 + + +def sample_batch_create_tensorboard_time_series(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + requests = aiplatform_v1.CreateTensorboardTimeSeriesRequest() + requests.parent = "parent_value" + requests.tensorboard_time_series.display_name = "display_name_value" + requests.tensorboard_time_series.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1.BatchCreateTensorboardTimeSeriesRequest( + parent="parent_value", + requests=requests, + ) + + # Make the request + response = client.batch_create_tensorboard_time_series(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_BatchCreateTensorboardTimeSeries_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_batch_read_tensorboard_time_series_data_async.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_batch_read_tensorboard_time_series_data_async.py new file mode 100644 index 0000000000..6e82e6e7bf --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_batch_read_tensorboard_time_series_data_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchReadTensorboardTimeSeriesData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_BatchReadTensorboardTimeSeriesData_async] +from google.cloud import aiplatform_v1 + + +async def sample_batch_read_tensorboard_time_series_data(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.BatchReadTensorboardTimeSeriesDataRequest( + tensorboard="tensorboard_value", + time_series=['time_series_value_1', 'time_series_value_2'], + ) + + # Make the request + response = await client.batch_read_tensorboard_time_series_data(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_BatchReadTensorboardTimeSeriesData_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_batch_read_tensorboard_time_series_data_sync.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_batch_read_tensorboard_time_series_data_sync.py new file mode 100644 index 0000000000..5bd3676ae4 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_batch_read_tensorboard_time_series_data_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchReadTensorboardTimeSeriesData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_BatchReadTensorboardTimeSeriesData_sync] +from google.cloud import aiplatform_v1 + + +def sample_batch_read_tensorboard_time_series_data(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.BatchReadTensorboardTimeSeriesDataRequest( + tensorboard="tensorboard_value", + time_series=['time_series_value_1', 'time_series_value_2'], + ) + + # Make the request + response = client.batch_read_tensorboard_time_series_data(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_BatchReadTensorboardTimeSeriesData_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_create_tensorboard_async.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_create_tensorboard_async.py new file mode 100644 index 0000000000..021cd448f1 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_create_tensorboard_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTensorboard +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_CreateTensorboard_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_tensorboard(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + tensorboard = aiplatform_v1.Tensorboard() + tensorboard.display_name = "display_name_value" + + request = aiplatform_v1.CreateTensorboardRequest( + parent="parent_value", + tensorboard=tensorboard, + ) + + # Make the request + operation = client.create_tensorboard(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_CreateTensorboard_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_create_tensorboard_experiment_async.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_create_tensorboard_experiment_async.py new file mode 100644 index 0000000000..7d9591c078 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_create_tensorboard_experiment_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTensorboardExperiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_CreateTensorboardExperiment_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_tensorboard_experiment(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateTensorboardExperimentRequest( + parent="parent_value", + tensorboard_experiment_id="tensorboard_experiment_id_value", + ) + + # Make the request + response = await client.create_tensorboard_experiment(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_CreateTensorboardExperiment_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_create_tensorboard_experiment_sync.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_create_tensorboard_experiment_sync.py new file mode 100644 index 0000000000..063e851b6d --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_create_tensorboard_experiment_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTensorboardExperiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_CreateTensorboardExperiment_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_tensorboard_experiment(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateTensorboardExperimentRequest( + parent="parent_value", + tensorboard_experiment_id="tensorboard_experiment_id_value", + ) + + # Make the request + response = client.create_tensorboard_experiment(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_CreateTensorboardExperiment_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_create_tensorboard_run_async.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_create_tensorboard_run_async.py new file mode 100644 index 0000000000..03b4d5b0af --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_create_tensorboard_run_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTensorboardRun +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_CreateTensorboardRun_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_tensorboard_run(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + tensorboard_run = aiplatform_v1.TensorboardRun() + tensorboard_run.display_name = "display_name_value" + + request = aiplatform_v1.CreateTensorboardRunRequest( + parent="parent_value", + tensorboard_run=tensorboard_run, + tensorboard_run_id="tensorboard_run_id_value", + ) + + # Make the request + response = await client.create_tensorboard_run(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_CreateTensorboardRun_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_create_tensorboard_run_sync.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_create_tensorboard_run_sync.py new file mode 100644 index 0000000000..ecaf504337 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_create_tensorboard_run_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTensorboardRun +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_CreateTensorboardRun_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_tensorboard_run(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + tensorboard_run = aiplatform_v1.TensorboardRun() + tensorboard_run.display_name = "display_name_value" + + request = aiplatform_v1.CreateTensorboardRunRequest( + parent="parent_value", + tensorboard_run=tensorboard_run, + tensorboard_run_id="tensorboard_run_id_value", + ) + + # Make the request + response = client.create_tensorboard_run(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_CreateTensorboardRun_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_create_tensorboard_sync.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_create_tensorboard_sync.py new file mode 100644 index 0000000000..df66cc046e --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_create_tensorboard_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTensorboard +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_CreateTensorboard_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_tensorboard(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + tensorboard = aiplatform_v1.Tensorboard() + tensorboard.display_name = "display_name_value" + + request = aiplatform_v1.CreateTensorboardRequest( + parent="parent_value", + tensorboard=tensorboard, + ) + + # Make the request + operation = client.create_tensorboard(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_CreateTensorboard_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_create_tensorboard_time_series_async.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_create_tensorboard_time_series_async.py new file mode 100644 index 0000000000..aeb57161b4 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_create_tensorboard_time_series_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_CreateTensorboardTimeSeries_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_tensorboard_time_series(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + tensorboard_time_series = aiplatform_v1.TensorboardTimeSeries() + tensorboard_time_series.display_name = "display_name_value" + tensorboard_time_series.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1.CreateTensorboardTimeSeriesRequest( + parent="parent_value", + tensorboard_time_series=tensorboard_time_series, + ) + + # Make the request + response = await client.create_tensorboard_time_series(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_CreateTensorboardTimeSeries_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_create_tensorboard_time_series_sync.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_create_tensorboard_time_series_sync.py new file mode 100644 index 0000000000..ec5996e2bc --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_create_tensorboard_time_series_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_CreateTensorboardTimeSeries_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_tensorboard_time_series(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + tensorboard_time_series = aiplatform_v1.TensorboardTimeSeries() + tensorboard_time_series.display_name = "display_name_value" + tensorboard_time_series.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1.CreateTensorboardTimeSeriesRequest( + parent="parent_value", + tensorboard_time_series=tensorboard_time_series, + ) + + # Make the request + response = client.create_tensorboard_time_series(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_CreateTensorboardTimeSeries_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_delete_tensorboard_async.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_delete_tensorboard_async.py new file mode 100644 index 0000000000..d534d34371 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_delete_tensorboard_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTensorboard +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_DeleteTensorboard_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_tensorboard(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteTensorboardRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_DeleteTensorboard_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_delete_tensorboard_experiment_async.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_delete_tensorboard_experiment_async.py new file mode 100644 index 0000000000..fe3cb985f1 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_delete_tensorboard_experiment_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTensorboardExperiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_DeleteTensorboardExperiment_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_tensorboard_experiment(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteTensorboardExperimentRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard_experiment(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_DeleteTensorboardExperiment_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_delete_tensorboard_experiment_sync.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_delete_tensorboard_experiment_sync.py new file mode 100644 index 0000000000..f73f3cba4c --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_delete_tensorboard_experiment_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTensorboardExperiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_DeleteTensorboardExperiment_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_tensorboard_experiment(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteTensorboardExperimentRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard_experiment(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_DeleteTensorboardExperiment_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_delete_tensorboard_run_async.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_delete_tensorboard_run_async.py new file mode 100644 index 0000000000..feb3a67c18 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_delete_tensorboard_run_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTensorboardRun +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_DeleteTensorboardRun_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_tensorboard_run(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteTensorboardRunRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard_run(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_DeleteTensorboardRun_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_delete_tensorboard_run_sync.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_delete_tensorboard_run_sync.py new file mode 100644 index 0000000000..5a4404e657 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_delete_tensorboard_run_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTensorboardRun +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_DeleteTensorboardRun_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_tensorboard_run(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteTensorboardRunRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard_run(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_DeleteTensorboardRun_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_delete_tensorboard_sync.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_delete_tensorboard_sync.py new file mode 100644 index 0000000000..b1690032ce --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_delete_tensorboard_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTensorboard +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_DeleteTensorboard_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_tensorboard(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteTensorboardRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_DeleteTensorboard_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_delete_tensorboard_time_series_async.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_delete_tensorboard_time_series_async.py new file mode 100644 index 0000000000..720b9b7493 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_delete_tensorboard_time_series_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_DeleteTensorboardTimeSeries_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_tensorboard_time_series(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteTensorboardTimeSeriesRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard_time_series(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_DeleteTensorboardTimeSeries_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_delete_tensorboard_time_series_sync.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_delete_tensorboard_time_series_sync.py new file mode 100644 index 0000000000..454690c315 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_delete_tensorboard_time_series_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_DeleteTensorboardTimeSeries_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_tensorboard_time_series(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteTensorboardTimeSeriesRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard_time_series(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_DeleteTensorboardTimeSeries_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_export_tensorboard_time_series_data_async.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_export_tensorboard_time_series_data_async.py new file mode 100644 index 0000000000..f4b62c9eca --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_export_tensorboard_time_series_data_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportTensorboardTimeSeriesData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_ExportTensorboardTimeSeriesData_async] +from google.cloud import aiplatform_v1 + + +async def sample_export_tensorboard_time_series_data(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ExportTensorboardTimeSeriesDataRequest( + tensorboard_time_series="tensorboard_time_series_value", + ) + + # Make the request + page_result = client.export_tensorboard_time_series_data(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1_generated_TensorboardService_ExportTensorboardTimeSeriesData_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_export_tensorboard_time_series_data_sync.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_export_tensorboard_time_series_data_sync.py new file mode 100644 index 0000000000..dc56a42717 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_export_tensorboard_time_series_data_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportTensorboardTimeSeriesData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_ExportTensorboardTimeSeriesData_sync] +from google.cloud import aiplatform_v1 + + +def sample_export_tensorboard_time_series_data(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ExportTensorboardTimeSeriesDataRequest( + tensorboard_time_series="tensorboard_time_series_value", + ) + + # Make the request + page_result = client.export_tensorboard_time_series_data(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1_generated_TensorboardService_ExportTensorboardTimeSeriesData_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_get_tensorboard_async.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_get_tensorboard_async.py new file mode 100644 index 0000000000..6cbb0d2833 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_get_tensorboard_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTensorboard +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_GetTensorboard_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_tensorboard(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetTensorboardRequest( + name="name_value", + ) + + # Make the request + response = await client.get_tensorboard(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_GetTensorboard_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_get_tensorboard_experiment_async.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_get_tensorboard_experiment_async.py new file mode 100644 index 0000000000..62b03f1654 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_get_tensorboard_experiment_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTensorboardExperiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_GetTensorboardExperiment_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_tensorboard_experiment(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetTensorboardExperimentRequest( + name="name_value", + ) + + # Make the request + response = await client.get_tensorboard_experiment(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_GetTensorboardExperiment_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_get_tensorboard_experiment_sync.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_get_tensorboard_experiment_sync.py new file mode 100644 index 0000000000..422e366b4b --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_get_tensorboard_experiment_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTensorboardExperiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_GetTensorboardExperiment_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_tensorboard_experiment(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetTensorboardExperimentRequest( + name="name_value", + ) + + # Make the request + response = client.get_tensorboard_experiment(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_GetTensorboardExperiment_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_get_tensorboard_run_async.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_get_tensorboard_run_async.py new file mode 100644 index 0000000000..999deb6ce5 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_get_tensorboard_run_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTensorboardRun +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_GetTensorboardRun_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_tensorboard_run(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetTensorboardRunRequest( + name="name_value", + ) + + # Make the request + response = await client.get_tensorboard_run(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_GetTensorboardRun_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_get_tensorboard_run_sync.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_get_tensorboard_run_sync.py new file mode 100644 index 0000000000..dc8cb3d326 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_get_tensorboard_run_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTensorboardRun +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_GetTensorboardRun_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_tensorboard_run(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetTensorboardRunRequest( + name="name_value", + ) + + # Make the request + response = client.get_tensorboard_run(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_GetTensorboardRun_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_get_tensorboard_sync.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_get_tensorboard_sync.py new file mode 100644 index 0000000000..99d3cf05b5 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_get_tensorboard_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTensorboard +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_GetTensorboard_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_tensorboard(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetTensorboardRequest( + name="name_value", + ) + + # Make the request + response = client.get_tensorboard(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_GetTensorboard_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_get_tensorboard_time_series_async.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_get_tensorboard_time_series_async.py new file mode 100644 index 0000000000..0a59fa17ea --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_get_tensorboard_time_series_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_GetTensorboardTimeSeries_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_tensorboard_time_series(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetTensorboardTimeSeriesRequest( + name="name_value", + ) + + # Make the request + response = await client.get_tensorboard_time_series(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_GetTensorboardTimeSeries_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_get_tensorboard_time_series_sync.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_get_tensorboard_time_series_sync.py new file mode 100644 index 0000000000..a933c092bc --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_get_tensorboard_time_series_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_GetTensorboardTimeSeries_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_tensorboard_time_series(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetTensorboardTimeSeriesRequest( + name="name_value", + ) + + # Make the request + response = client.get_tensorboard_time_series(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_GetTensorboardTimeSeries_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_list_tensorboard_experiments_async.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_list_tensorboard_experiments_async.py new file mode 100644 index 0000000000..44ffbf98b1 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_list_tensorboard_experiments_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTensorboardExperiments +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_ListTensorboardExperiments_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_tensorboard_experiments(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListTensorboardExperimentsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboard_experiments(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1_generated_TensorboardService_ListTensorboardExperiments_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_list_tensorboard_experiments_sync.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_list_tensorboard_experiments_sync.py new file mode 100644 index 0000000000..a826f4fe83 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_list_tensorboard_experiments_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTensorboardExperiments +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_ListTensorboardExperiments_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_tensorboard_experiments(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListTensorboardExperimentsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboard_experiments(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1_generated_TensorboardService_ListTensorboardExperiments_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_list_tensorboard_runs_async.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_list_tensorboard_runs_async.py new file mode 100644 index 0000000000..a656b95b1b --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_list_tensorboard_runs_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTensorboardRuns +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_ListTensorboardRuns_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_tensorboard_runs(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListTensorboardRunsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboard_runs(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1_generated_TensorboardService_ListTensorboardRuns_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_list_tensorboard_runs_sync.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_list_tensorboard_runs_sync.py new file mode 100644 index 0000000000..1389821241 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_list_tensorboard_runs_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTensorboardRuns +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_ListTensorboardRuns_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_tensorboard_runs(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListTensorboardRunsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboard_runs(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1_generated_TensorboardService_ListTensorboardRuns_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_list_tensorboard_time_series_async.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_list_tensorboard_time_series_async.py new file mode 100644 index 0000000000..332cf9252b --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_list_tensorboard_time_series_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_ListTensorboardTimeSeries_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_tensorboard_time_series(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListTensorboardTimeSeriesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboard_time_series(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1_generated_TensorboardService_ListTensorboardTimeSeries_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_list_tensorboard_time_series_sync.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_list_tensorboard_time_series_sync.py new file mode 100644 index 0000000000..15b99118cf --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_list_tensorboard_time_series_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_ListTensorboardTimeSeries_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_tensorboard_time_series(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListTensorboardTimeSeriesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboard_time_series(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1_generated_TensorboardService_ListTensorboardTimeSeries_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_list_tensorboards_async.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_list_tensorboards_async.py new file mode 100644 index 0000000000..cf1586f9fe --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_list_tensorboards_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTensorboards +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_ListTensorboards_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_tensorboards(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListTensorboardsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboards(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1_generated_TensorboardService_ListTensorboards_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_list_tensorboards_sync.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_list_tensorboards_sync.py new file mode 100644 index 0000000000..f625ede9f8 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_list_tensorboards_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTensorboards +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_ListTensorboards_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_tensorboards(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListTensorboardsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboards(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1_generated_TensorboardService_ListTensorboards_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_read_tensorboard_blob_data_async.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_read_tensorboard_blob_data_async.py new file mode 100644 index 0000000000..61bbb8f6d9 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_read_tensorboard_blob_data_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ReadTensorboardBlobData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_ReadTensorboardBlobData_async] +from google.cloud import aiplatform_v1 + + +async def sample_read_tensorboard_blob_data(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ReadTensorboardBlobDataRequest( + time_series="time_series_value", + ) + + # Make the request + stream = await client.read_tensorboard_blob_data(request=request) + + # Handle the response + async for response in stream: + print(response) + +# [END aiplatform_v1_generated_TensorboardService_ReadTensorboardBlobData_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_read_tensorboard_blob_data_sync.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_read_tensorboard_blob_data_sync.py new file mode 100644 index 0000000000..04db8236e7 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_read_tensorboard_blob_data_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ReadTensorboardBlobData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_ReadTensorboardBlobData_sync] +from google.cloud import aiplatform_v1 + + +def sample_read_tensorboard_blob_data(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ReadTensorboardBlobDataRequest( + time_series="time_series_value", + ) + + # Make the request + stream = client.read_tensorboard_blob_data(request=request) + + # Handle the response + for response in stream: + print(response) + +# [END aiplatform_v1_generated_TensorboardService_ReadTensorboardBlobData_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_read_tensorboard_time_series_data_async.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_read_tensorboard_time_series_data_async.py new file mode 100644 index 0000000000..270421cdad --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_read_tensorboard_time_series_data_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ReadTensorboardTimeSeriesData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_ReadTensorboardTimeSeriesData_async] +from google.cloud import aiplatform_v1 + + +async def sample_read_tensorboard_time_series_data(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ReadTensorboardTimeSeriesDataRequest( + tensorboard_time_series="tensorboard_time_series_value", + ) + + # Make the request + response = await client.read_tensorboard_time_series_data(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_ReadTensorboardTimeSeriesData_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_read_tensorboard_time_series_data_sync.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_read_tensorboard_time_series_data_sync.py new file mode 100644 index 0000000000..723f625e8b --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_read_tensorboard_time_series_data_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ReadTensorboardTimeSeriesData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_ReadTensorboardTimeSeriesData_sync] +from google.cloud import aiplatform_v1 + + +def sample_read_tensorboard_time_series_data(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ReadTensorboardTimeSeriesDataRequest( + tensorboard_time_series="tensorboard_time_series_value", + ) + + # Make the request + response = client.read_tensorboard_time_series_data(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_ReadTensorboardTimeSeriesData_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_update_tensorboard_async.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_update_tensorboard_async.py new file mode 100644 index 0000000000..2efcdd6f09 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_update_tensorboard_async.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateTensorboard +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_UpdateTensorboard_async] +from google.cloud import aiplatform_v1 + + +async def sample_update_tensorboard(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + tensorboard = aiplatform_v1.Tensorboard() + tensorboard.display_name = "display_name_value" + + request = aiplatform_v1.UpdateTensorboardRequest( + tensorboard=tensorboard, + ) + + # Make the request + operation = client.update_tensorboard(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_UpdateTensorboard_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_update_tensorboard_experiment_async.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_update_tensorboard_experiment_async.py new file mode 100644 index 0000000000..ef1906dfcc --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_update_tensorboard_experiment_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateTensorboardExperiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_UpdateTensorboardExperiment_async] +from google.cloud import aiplatform_v1 + + +async def sample_update_tensorboard_experiment(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.UpdateTensorboardExperimentRequest( + ) + + # Make the request + response = await client.update_tensorboard_experiment(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_UpdateTensorboardExperiment_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_update_tensorboard_experiment_sync.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_update_tensorboard_experiment_sync.py new file mode 100644 index 0000000000..a7ce7ee31f --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_update_tensorboard_experiment_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateTensorboardExperiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_UpdateTensorboardExperiment_sync] +from google.cloud import aiplatform_v1 + + +def sample_update_tensorboard_experiment(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.UpdateTensorboardExperimentRequest( + ) + + # Make the request + response = client.update_tensorboard_experiment(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_UpdateTensorboardExperiment_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_update_tensorboard_run_async.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_update_tensorboard_run_async.py new file mode 100644 index 0000000000..355c3542b7 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_update_tensorboard_run_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateTensorboardRun +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_UpdateTensorboardRun_async] +from google.cloud import aiplatform_v1 + + +async def sample_update_tensorboard_run(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + tensorboard_run = aiplatform_v1.TensorboardRun() + tensorboard_run.display_name = "display_name_value" + + request = aiplatform_v1.UpdateTensorboardRunRequest( + tensorboard_run=tensorboard_run, + ) + + # Make the request + response = await client.update_tensorboard_run(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_UpdateTensorboardRun_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_update_tensorboard_run_sync.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_update_tensorboard_run_sync.py new file mode 100644 index 0000000000..d5227007cc --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_update_tensorboard_run_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateTensorboardRun +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_UpdateTensorboardRun_sync] +from google.cloud import aiplatform_v1 + + +def sample_update_tensorboard_run(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + tensorboard_run = aiplatform_v1.TensorboardRun() + tensorboard_run.display_name = "display_name_value" + + request = aiplatform_v1.UpdateTensorboardRunRequest( + tensorboard_run=tensorboard_run, + ) + + # Make the request + response = client.update_tensorboard_run(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_UpdateTensorboardRun_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_update_tensorboard_sync.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_update_tensorboard_sync.py new file mode 100644 index 0000000000..d79a4dbad3 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_update_tensorboard_sync.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateTensorboard +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_UpdateTensorboard_sync] +from google.cloud import aiplatform_v1 + + +def sample_update_tensorboard(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + tensorboard = aiplatform_v1.Tensorboard() + tensorboard.display_name = "display_name_value" + + request = aiplatform_v1.UpdateTensorboardRequest( + tensorboard=tensorboard, + ) + + # Make the request + operation = client.update_tensorboard(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_UpdateTensorboard_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_update_tensorboard_time_series_async.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_update_tensorboard_time_series_async.py new file mode 100644 index 0000000000..80de4e9ef4 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_update_tensorboard_time_series_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_UpdateTensorboardTimeSeries_async] +from google.cloud import aiplatform_v1 + + +async def sample_update_tensorboard_time_series(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + tensorboard_time_series = aiplatform_v1.TensorboardTimeSeries() + tensorboard_time_series.display_name = "display_name_value" + tensorboard_time_series.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1.UpdateTensorboardTimeSeriesRequest( + tensorboard_time_series=tensorboard_time_series, + ) + + # Make the request + response = await client.update_tensorboard_time_series(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_UpdateTensorboardTimeSeries_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_update_tensorboard_time_series_sync.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_update_tensorboard_time_series_sync.py new file mode 100644 index 0000000000..5a666f95ed --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_update_tensorboard_time_series_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_UpdateTensorboardTimeSeries_sync] +from google.cloud import aiplatform_v1 + + +def sample_update_tensorboard_time_series(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + tensorboard_time_series = aiplatform_v1.TensorboardTimeSeries() + tensorboard_time_series.display_name = "display_name_value" + tensorboard_time_series.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1.UpdateTensorboardTimeSeriesRequest( + tensorboard_time_series=tensorboard_time_series, + ) + + # Make the request + response = client.update_tensorboard_time_series(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_UpdateTensorboardTimeSeries_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_write_tensorboard_experiment_data_async.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_write_tensorboard_experiment_data_async.py new file mode 100644 index 0000000000..cf6790bc7e --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_write_tensorboard_experiment_data_async.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for WriteTensorboardExperimentData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_WriteTensorboardExperimentData_async] +from google.cloud import aiplatform_v1 + + +async def sample_write_tensorboard_experiment_data(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + write_run_data_requests = aiplatform_v1.WriteTensorboardRunDataRequest() + write_run_data_requests.tensorboard_run = "tensorboard_run_value" + write_run_data_requests.time_series_data.tensorboard_time_series_id = "tensorboard_time_series_id_value" + write_run_data_requests.time_series_data.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1.WriteTensorboardExperimentDataRequest( + tensorboard_experiment="tensorboard_experiment_value", + write_run_data_requests=write_run_data_requests, + ) + + # Make the request + response = await client.write_tensorboard_experiment_data(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_WriteTensorboardExperimentData_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_write_tensorboard_experiment_data_sync.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_write_tensorboard_experiment_data_sync.py new file mode 100644 index 0000000000..3e9153b5e5 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_write_tensorboard_experiment_data_sync.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for WriteTensorboardExperimentData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_WriteTensorboardExperimentData_sync] +from google.cloud import aiplatform_v1 + + +def sample_write_tensorboard_experiment_data(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + write_run_data_requests = aiplatform_v1.WriteTensorboardRunDataRequest() + write_run_data_requests.tensorboard_run = "tensorboard_run_value" + write_run_data_requests.time_series_data.tensorboard_time_series_id = "tensorboard_time_series_id_value" + write_run_data_requests.time_series_data.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1.WriteTensorboardExperimentDataRequest( + tensorboard_experiment="tensorboard_experiment_value", + write_run_data_requests=write_run_data_requests, + ) + + # Make the request + response = client.write_tensorboard_experiment_data(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_WriteTensorboardExperimentData_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_write_tensorboard_run_data_async.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_write_tensorboard_run_data_async.py new file mode 100644 index 0000000000..9164bacb8e --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_write_tensorboard_run_data_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for WriteTensorboardRunData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_WriteTensorboardRunData_async] +from google.cloud import aiplatform_v1 + + +async def sample_write_tensorboard_run_data(): + # Create a client + client = aiplatform_v1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + time_series_data = aiplatform_v1.TimeSeriesData() + time_series_data.tensorboard_time_series_id = "tensorboard_time_series_id_value" + time_series_data.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1.WriteTensorboardRunDataRequest( + tensorboard_run="tensorboard_run_value", + time_series_data=time_series_data, + ) + + # Make the request + response = await client.write_tensorboard_run_data(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_WriteTensorboardRunData_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_write_tensorboard_run_data_sync.py b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_write_tensorboard_run_data_sync.py new file mode 100644 index 0000000000..a75f7b99fc --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_tensorboard_service_write_tensorboard_run_data_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for WriteTensorboardRunData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_TensorboardService_WriteTensorboardRunData_sync] +from google.cloud import aiplatform_v1 + + +def sample_write_tensorboard_run_data(): + # Create a client + client = aiplatform_v1.TensorboardServiceClient() + + # Initialize request argument(s) + time_series_data = aiplatform_v1.TimeSeriesData() + time_series_data.tensorboard_time_series_id = "tensorboard_time_series_id_value" + time_series_data.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1.WriteTensorboardRunDataRequest( + tensorboard_run="tensorboard_run_value", + time_series_data=time_series_data, + ) + + # Make the request + response = client.write_tensorboard_run_data(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_TensorboardService_WriteTensorboardRunData_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_vizier_service_add_trial_measurement_async.py b/samples/generated_samples/aiplatform_v1_generated_vizier_service_add_trial_measurement_async.py new file mode 100644 index 0000000000..9a3f3c590c --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_vizier_service_add_trial_measurement_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddTrialMeasurement +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_VizierService_AddTrialMeasurement_async] +from google.cloud import aiplatform_v1 + + +async def sample_add_trial_measurement(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.AddTrialMeasurementRequest( + trial_name="trial_name_value", + ) + + # Make the request + response = await client.add_trial_measurement(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_VizierService_AddTrialMeasurement_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_vizier_service_add_trial_measurement_sync.py b/samples/generated_samples/aiplatform_v1_generated_vizier_service_add_trial_measurement_sync.py new file mode 100644 index 0000000000..0cdb6f1d48 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_vizier_service_add_trial_measurement_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddTrialMeasurement +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_VizierService_AddTrialMeasurement_sync] +from google.cloud import aiplatform_v1 + + +def sample_add_trial_measurement(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.AddTrialMeasurementRequest( + trial_name="trial_name_value", + ) + + # Make the request + response = client.add_trial_measurement(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_VizierService_AddTrialMeasurement_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_vizier_service_check_trial_early_stopping_state_async.py b/samples/generated_samples/aiplatform_v1_generated_vizier_service_check_trial_early_stopping_state_async.py new file mode 100644 index 0000000000..fd15098c55 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_vizier_service_check_trial_early_stopping_state_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CheckTrialEarlyStoppingState +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_VizierService_CheckTrialEarlyStoppingState_async] +from google.cloud import aiplatform_v1 + + +async def sample_check_trial_early_stopping_state(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CheckTrialEarlyStoppingStateRequest( + trial_name="trial_name_value", + ) + + # Make the request + operation = client.check_trial_early_stopping_state(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_VizierService_CheckTrialEarlyStoppingState_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_vizier_service_check_trial_early_stopping_state_sync.py b/samples/generated_samples/aiplatform_v1_generated_vizier_service_check_trial_early_stopping_state_sync.py new file mode 100644 index 0000000000..77f2459e5b --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_vizier_service_check_trial_early_stopping_state_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CheckTrialEarlyStoppingState +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_VizierService_CheckTrialEarlyStoppingState_sync] +from google.cloud import aiplatform_v1 + + +def sample_check_trial_early_stopping_state(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CheckTrialEarlyStoppingStateRequest( + trial_name="trial_name_value", + ) + + # Make the request + operation = client.check_trial_early_stopping_state(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_VizierService_CheckTrialEarlyStoppingState_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_vizier_service_complete_trial_async.py b/samples/generated_samples/aiplatform_v1_generated_vizier_service_complete_trial_async.py new file mode 100644 index 0000000000..cd58f93f6f --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_vizier_service_complete_trial_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CompleteTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_VizierService_CompleteTrial_async] +from google.cloud import aiplatform_v1 + + +async def sample_complete_trial(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CompleteTrialRequest( + name="name_value", + ) + + # Make the request + response = await client.complete_trial(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_VizierService_CompleteTrial_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_vizier_service_complete_trial_sync.py b/samples/generated_samples/aiplatform_v1_generated_vizier_service_complete_trial_sync.py new file mode 100644 index 0000000000..71118fc50b --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_vizier_service_complete_trial_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CompleteTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_VizierService_CompleteTrial_sync] +from google.cloud import aiplatform_v1 + + +def sample_complete_trial(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CompleteTrialRequest( + name="name_value", + ) + + # Make the request + response = client.complete_trial(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_VizierService_CompleteTrial_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_vizier_service_create_study_async.py b/samples/generated_samples/aiplatform_v1_generated_vizier_service_create_study_async.py new file mode 100644 index 0000000000..427fd4e819 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_vizier_service_create_study_async.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateStudy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_VizierService_CreateStudy_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_study(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + study = aiplatform_v1.Study() + study.display_name = "display_name_value" + study.study_spec.metrics.metric_id = "metric_id_value" + study.study_spec.metrics.goal = "MINIMIZE" + study.study_spec.parameters.double_value_spec.min_value = 0.96 + study.study_spec.parameters.double_value_spec.max_value = 0.962 + study.study_spec.parameters.parameter_id = "parameter_id_value" + + request = aiplatform_v1.CreateStudyRequest( + parent="parent_value", + study=study, + ) + + # Make the request + response = await client.create_study(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_VizierService_CreateStudy_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_vizier_service_create_study_sync.py b/samples/generated_samples/aiplatform_v1_generated_vizier_service_create_study_sync.py new file mode 100644 index 0000000000..4ff6c72222 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_vizier_service_create_study_sync.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateStudy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_VizierService_CreateStudy_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_study(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + study = aiplatform_v1.Study() + study.display_name = "display_name_value" + study.study_spec.metrics.metric_id = "metric_id_value" + study.study_spec.metrics.goal = "MINIMIZE" + study.study_spec.parameters.double_value_spec.min_value = 0.96 + study.study_spec.parameters.double_value_spec.max_value = 0.962 + study.study_spec.parameters.parameter_id = "parameter_id_value" + + request = aiplatform_v1.CreateStudyRequest( + parent="parent_value", + study=study, + ) + + # Make the request + response = client.create_study(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_VizierService_CreateStudy_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_vizier_service_create_trial_async.py b/samples/generated_samples/aiplatform_v1_generated_vizier_service_create_trial_async.py new file mode 100644 index 0000000000..ce3b895d53 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_vizier_service_create_trial_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_VizierService_CreateTrial_async] +from google.cloud import aiplatform_v1 + + +async def sample_create_trial(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateTrialRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_trial(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_VizierService_CreateTrial_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_vizier_service_create_trial_sync.py b/samples/generated_samples/aiplatform_v1_generated_vizier_service_create_trial_sync.py new file mode 100644 index 0000000000..5519fb4182 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_vizier_service_create_trial_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_VizierService_CreateTrial_sync] +from google.cloud import aiplatform_v1 + + +def sample_create_trial(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.CreateTrialRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_trial(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_VizierService_CreateTrial_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_vizier_service_delete_study_async.py b/samples/generated_samples/aiplatform_v1_generated_vizier_service_delete_study_async.py new file mode 100644 index 0000000000..cc4fd917bb --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_vizier_service_delete_study_async.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteStudy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_VizierService_DeleteStudy_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_study(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteStudyRequest( + name="name_value", + ) + + # Make the request + await client.delete_study(request=request) + + +# [END aiplatform_v1_generated_VizierService_DeleteStudy_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_vizier_service_delete_study_sync.py b/samples/generated_samples/aiplatform_v1_generated_vizier_service_delete_study_sync.py new file mode 100644 index 0000000000..0c4c0e96e1 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_vizier_service_delete_study_sync.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteStudy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_VizierService_DeleteStudy_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_study(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteStudyRequest( + name="name_value", + ) + + # Make the request + client.delete_study(request=request) + + +# [END aiplatform_v1_generated_VizierService_DeleteStudy_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_vizier_service_delete_trial_async.py b/samples/generated_samples/aiplatform_v1_generated_vizier_service_delete_trial_async.py new file mode 100644 index 0000000000..71004f7944 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_vizier_service_delete_trial_async.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_VizierService_DeleteTrial_async] +from google.cloud import aiplatform_v1 + + +async def sample_delete_trial(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteTrialRequest( + name="name_value", + ) + + # Make the request + await client.delete_trial(request=request) + + +# [END aiplatform_v1_generated_VizierService_DeleteTrial_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_vizier_service_delete_trial_sync.py b/samples/generated_samples/aiplatform_v1_generated_vizier_service_delete_trial_sync.py new file mode 100644 index 0000000000..a9645fa768 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_vizier_service_delete_trial_sync.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_VizierService_DeleteTrial_sync] +from google.cloud import aiplatform_v1 + + +def sample_delete_trial(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.DeleteTrialRequest( + name="name_value", + ) + + # Make the request + client.delete_trial(request=request) + + +# [END aiplatform_v1_generated_VizierService_DeleteTrial_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_vizier_service_get_study_async.py b/samples/generated_samples/aiplatform_v1_generated_vizier_service_get_study_async.py new file mode 100644 index 0000000000..896be0929d --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_vizier_service_get_study_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetStudy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_VizierService_GetStudy_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_study(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetStudyRequest( + name="name_value", + ) + + # Make the request + response = await client.get_study(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_VizierService_GetStudy_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_vizier_service_get_study_sync.py b/samples/generated_samples/aiplatform_v1_generated_vizier_service_get_study_sync.py new file mode 100644 index 0000000000..78403c40f4 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_vizier_service_get_study_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetStudy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_VizierService_GetStudy_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_study(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetStudyRequest( + name="name_value", + ) + + # Make the request + response = client.get_study(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_VizierService_GetStudy_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_vizier_service_get_trial_async.py b/samples/generated_samples/aiplatform_v1_generated_vizier_service_get_trial_async.py new file mode 100644 index 0000000000..8d8f18a296 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_vizier_service_get_trial_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_VizierService_GetTrial_async] +from google.cloud import aiplatform_v1 + + +async def sample_get_trial(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetTrialRequest( + name="name_value", + ) + + # Make the request + response = await client.get_trial(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_VizierService_GetTrial_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_vizier_service_get_trial_sync.py b/samples/generated_samples/aiplatform_v1_generated_vizier_service_get_trial_sync.py new file mode 100644 index 0000000000..bbe4b42559 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_vizier_service_get_trial_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_VizierService_GetTrial_sync] +from google.cloud import aiplatform_v1 + + +def sample_get_trial(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.GetTrialRequest( + name="name_value", + ) + + # Make the request + response = client.get_trial(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_VizierService_GetTrial_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_vizier_service_list_optimal_trials_async.py b/samples/generated_samples/aiplatform_v1_generated_vizier_service_list_optimal_trials_async.py new file mode 100644 index 0000000000..654800e7ba --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_vizier_service_list_optimal_trials_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListOptimalTrials +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_VizierService_ListOptimalTrials_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_optimal_trials(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListOptimalTrialsRequest( + parent="parent_value", + ) + + # Make the request + response = await client.list_optimal_trials(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_VizierService_ListOptimalTrials_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_vizier_service_list_optimal_trials_sync.py b/samples/generated_samples/aiplatform_v1_generated_vizier_service_list_optimal_trials_sync.py new file mode 100644 index 0000000000..afd546b2dc --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_vizier_service_list_optimal_trials_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListOptimalTrials +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_VizierService_ListOptimalTrials_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_optimal_trials(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListOptimalTrialsRequest( + parent="parent_value", + ) + + # Make the request + response = client.list_optimal_trials(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_VizierService_ListOptimalTrials_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_vizier_service_list_studies_async.py b/samples/generated_samples/aiplatform_v1_generated_vizier_service_list_studies_async.py new file mode 100644 index 0000000000..b0601edaa6 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_vizier_service_list_studies_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListStudies +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_VizierService_ListStudies_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_studies(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListStudiesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_studies(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1_generated_VizierService_ListStudies_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_vizier_service_list_studies_sync.py b/samples/generated_samples/aiplatform_v1_generated_vizier_service_list_studies_sync.py new file mode 100644 index 0000000000..58d586d9f8 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_vizier_service_list_studies_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListStudies +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_VizierService_ListStudies_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_studies(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListStudiesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_studies(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1_generated_VizierService_ListStudies_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_vizier_service_list_trials_async.py b/samples/generated_samples/aiplatform_v1_generated_vizier_service_list_trials_async.py new file mode 100644 index 0000000000..04acd2d138 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_vizier_service_list_trials_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTrials +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_VizierService_ListTrials_async] +from google.cloud import aiplatform_v1 + + +async def sample_list_trials(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListTrialsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_trials(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1_generated_VizierService_ListTrials_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_vizier_service_list_trials_sync.py b/samples/generated_samples/aiplatform_v1_generated_vizier_service_list_trials_sync.py new file mode 100644 index 0000000000..81b15f8c4a --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_vizier_service_list_trials_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTrials +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_VizierService_ListTrials_sync] +from google.cloud import aiplatform_v1 + + +def sample_list_trials(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.ListTrialsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_trials(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1_generated_VizierService_ListTrials_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_vizier_service_lookup_study_async.py b/samples/generated_samples/aiplatform_v1_generated_vizier_service_lookup_study_async.py new file mode 100644 index 0000000000..d02e6d3e9f --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_vizier_service_lookup_study_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for LookupStudy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_VizierService_LookupStudy_async] +from google.cloud import aiplatform_v1 + + +async def sample_lookup_study(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.LookupStudyRequest( + parent="parent_value", + display_name="display_name_value", + ) + + # Make the request + response = await client.lookup_study(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_VizierService_LookupStudy_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_vizier_service_lookup_study_sync.py b/samples/generated_samples/aiplatform_v1_generated_vizier_service_lookup_study_sync.py new file mode 100644 index 0000000000..fc63574a92 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_vizier_service_lookup_study_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for LookupStudy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_VizierService_LookupStudy_sync] +from google.cloud import aiplatform_v1 + + +def sample_lookup_study(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.LookupStudyRequest( + parent="parent_value", + display_name="display_name_value", + ) + + # Make the request + response = client.lookup_study(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_VizierService_LookupStudy_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_vizier_service_stop_trial_async.py b/samples/generated_samples/aiplatform_v1_generated_vizier_service_stop_trial_async.py new file mode 100644 index 0000000000..9565c230eb --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_vizier_service_stop_trial_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for StopTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_VizierService_StopTrial_async] +from google.cloud import aiplatform_v1 + + +async def sample_stop_trial(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.StopTrialRequest( + name="name_value", + ) + + # Make the request + response = await client.stop_trial(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_VizierService_StopTrial_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_vizier_service_stop_trial_sync.py b/samples/generated_samples/aiplatform_v1_generated_vizier_service_stop_trial_sync.py new file mode 100644 index 0000000000..9ee9f9cbf0 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_vizier_service_stop_trial_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for StopTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_VizierService_StopTrial_sync] +from google.cloud import aiplatform_v1 + + +def sample_stop_trial(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.StopTrialRequest( + name="name_value", + ) + + # Make the request + response = client.stop_trial(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_VizierService_StopTrial_sync] diff --git a/samples/generated_samples/aiplatform_v1_generated_vizier_service_suggest_trials_async.py b/samples/generated_samples/aiplatform_v1_generated_vizier_service_suggest_trials_async.py new file mode 100644 index 0000000000..576fcb4da0 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_vizier_service_suggest_trials_async.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SuggestTrials +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_VizierService_SuggestTrials_async] +from google.cloud import aiplatform_v1 + + +async def sample_suggest_trials(): + # Create a client + client = aiplatform_v1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1.SuggestTrialsRequest( + parent="parent_value", + suggestion_count=1744, + client_id="client_id_value", + ) + + # Make the request + operation = client.suggest_trials(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_VizierService_SuggestTrials_async] diff --git a/samples/generated_samples/aiplatform_v1_generated_vizier_service_suggest_trials_sync.py b/samples/generated_samples/aiplatform_v1_generated_vizier_service_suggest_trials_sync.py new file mode 100644 index 0000000000..27d99dc261 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1_generated_vizier_service_suggest_trials_sync.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SuggestTrials +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1_generated_VizierService_SuggestTrials_sync] +from google.cloud import aiplatform_v1 + + +def sample_suggest_trials(): + # Create a client + client = aiplatform_v1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1.SuggestTrialsRequest( + parent="parent_value", + suggestion_count=1744, + client_id="client_id_value", + ) + + # Make the request + operation = client.suggest_trials(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1_generated_VizierService_SuggestTrials_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_create_dataset_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_create_dataset_async.py new file mode 100644 index 0000000000..be32ee2193 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_create_dataset_async.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateDataset +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_DatasetService_CreateDataset_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_dataset(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + dataset = aiplatform_v1beta1.Dataset() + dataset.display_name = "display_name_value" + dataset.metadata_schema_uri = "metadata_schema_uri_value" + dataset.metadata.null_value = "NULL_VALUE" + + request = aiplatform_v1beta1.CreateDatasetRequest( + parent="parent_value", + dataset=dataset, + ) + + # Make the request + operation = client.create_dataset(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_DatasetService_CreateDataset_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_create_dataset_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_create_dataset_sync.py new file mode 100644 index 0000000000..5fd6715c4b --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_create_dataset_sync.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateDataset +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_DatasetService_CreateDataset_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_dataset(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceClient() + + # Initialize request argument(s) + dataset = aiplatform_v1beta1.Dataset() + dataset.display_name = "display_name_value" + dataset.metadata_schema_uri = "metadata_schema_uri_value" + dataset.metadata.null_value = "NULL_VALUE" + + request = aiplatform_v1beta1.CreateDatasetRequest( + parent="parent_value", + dataset=dataset, + ) + + # Make the request + operation = client.create_dataset(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_DatasetService_CreateDataset_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_delete_dataset_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_delete_dataset_async.py new file mode 100644 index 0000000000..630f191611 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_delete_dataset_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteDataset +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_DatasetService_DeleteDataset_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_dataset(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteDatasetRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_dataset(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_DatasetService_DeleteDataset_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_delete_dataset_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_delete_dataset_sync.py new file mode 100644 index 0000000000..38cca9813c --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_delete_dataset_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteDataset +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_DatasetService_DeleteDataset_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_dataset(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteDatasetRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_dataset(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_DatasetService_DeleteDataset_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_export_data_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_export_data_async.py new file mode 100644 index 0000000000..4079305540 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_export_data_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_DatasetService_ExportData_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_export_data(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + export_config = aiplatform_v1beta1.ExportDataConfig() + export_config.gcs_destination.output_uri_prefix = "output_uri_prefix_value" + + request = aiplatform_v1beta1.ExportDataRequest( + name="name_value", + export_config=export_config, + ) + + # Make the request + operation = client.export_data(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_DatasetService_ExportData_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_export_data_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_export_data_sync.py new file mode 100644 index 0000000000..18edfe461e --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_export_data_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_DatasetService_ExportData_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_export_data(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceClient() + + # Initialize request argument(s) + export_config = aiplatform_v1beta1.ExportDataConfig() + export_config.gcs_destination.output_uri_prefix = "output_uri_prefix_value" + + request = aiplatform_v1beta1.ExportDataRequest( + name="name_value", + export_config=export_config, + ) + + # Make the request + operation = client.export_data(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_DatasetService_ExportData_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_get_annotation_spec_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_get_annotation_spec_async.py new file mode 100644 index 0000000000..91d937dc52 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_get_annotation_spec_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetAnnotationSpec +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_DatasetService_GetAnnotationSpec_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_annotation_spec(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetAnnotationSpecRequest( + name="name_value", + ) + + # Make the request + response = await client.get_annotation_spec(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_DatasetService_GetAnnotationSpec_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_get_annotation_spec_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_get_annotation_spec_sync.py new file mode 100644 index 0000000000..747b3920fa --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_get_annotation_spec_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetAnnotationSpec +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_DatasetService_GetAnnotationSpec_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_annotation_spec(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetAnnotationSpecRequest( + name="name_value", + ) + + # Make the request + response = client.get_annotation_spec(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_DatasetService_GetAnnotationSpec_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_get_dataset_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_get_dataset_async.py new file mode 100644 index 0000000000..bfbe3efe3a --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_get_dataset_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetDataset +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_DatasetService_GetDataset_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_dataset(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetDatasetRequest( + name="name_value", + ) + + # Make the request + response = await client.get_dataset(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_DatasetService_GetDataset_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_get_dataset_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_get_dataset_sync.py new file mode 100644 index 0000000000..dfce9fe3ff --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_get_dataset_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetDataset +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_DatasetService_GetDataset_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_dataset(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetDatasetRequest( + name="name_value", + ) + + # Make the request + response = client.get_dataset(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_DatasetService_GetDataset_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_import_data_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_import_data_async.py new file mode 100644 index 0000000000..4bf1ee252e --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_import_data_async.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ImportData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_DatasetService_ImportData_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_import_data(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + import_configs = aiplatform_v1beta1.ImportDataConfig() + import_configs.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + import_configs.import_schema_uri = "import_schema_uri_value" + + request = aiplatform_v1beta1.ImportDataRequest( + name="name_value", + import_configs=import_configs, + ) + + # Make the request + operation = client.import_data(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_DatasetService_ImportData_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_import_data_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_import_data_sync.py new file mode 100644 index 0000000000..f639bf1027 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_import_data_sync.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ImportData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_DatasetService_ImportData_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_import_data(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceClient() + + # Initialize request argument(s) + import_configs = aiplatform_v1beta1.ImportDataConfig() + import_configs.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + import_configs.import_schema_uri = "import_schema_uri_value" + + request = aiplatform_v1beta1.ImportDataRequest( + name="name_value", + import_configs=import_configs, + ) + + # Make the request + operation = client.import_data(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_DatasetService_ImportData_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_list_annotations_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_list_annotations_async.py new file mode 100644 index 0000000000..efd32c9b48 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_list_annotations_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListAnnotations +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_DatasetService_ListAnnotations_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_annotations(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListAnnotationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_annotations(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_DatasetService_ListAnnotations_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_list_annotations_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_list_annotations_sync.py new file mode 100644 index 0000000000..a81eb58758 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_list_annotations_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListAnnotations +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_DatasetService_ListAnnotations_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_annotations(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListAnnotationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_annotations(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_DatasetService_ListAnnotations_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_list_data_items_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_list_data_items_async.py new file mode 100644 index 0000000000..69d9fb12d3 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_list_data_items_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDataItems +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_DatasetService_ListDataItems_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_data_items(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListDataItemsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_data_items(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_DatasetService_ListDataItems_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_list_data_items_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_list_data_items_sync.py new file mode 100644 index 0000000000..7a67c0207c --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_list_data_items_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDataItems +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_DatasetService_ListDataItems_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_data_items(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListDataItemsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_data_items(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_DatasetService_ListDataItems_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_list_datasets_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_list_datasets_async.py new file mode 100644 index 0000000000..8848e920d9 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_list_datasets_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDatasets +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_DatasetService_ListDatasets_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_datasets(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListDatasetsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_datasets(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_DatasetService_ListDatasets_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_list_datasets_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_list_datasets_sync.py new file mode 100644 index 0000000000..7dce202e99 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_list_datasets_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDatasets +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_DatasetService_ListDatasets_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_datasets(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListDatasetsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_datasets(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_DatasetService_ListDatasets_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_update_dataset_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_update_dataset_async.py new file mode 100644 index 0000000000..eafbcd3e12 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_update_dataset_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateDataset +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_DatasetService_UpdateDataset_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_update_dataset(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceAsyncClient() + + # Initialize request argument(s) + dataset = aiplatform_v1beta1.Dataset() + dataset.display_name = "display_name_value" + dataset.metadata_schema_uri = "metadata_schema_uri_value" + dataset.metadata.null_value = "NULL_VALUE" + + request = aiplatform_v1beta1.UpdateDatasetRequest( + dataset=dataset, + ) + + # Make the request + response = await client.update_dataset(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_DatasetService_UpdateDataset_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_update_dataset_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_update_dataset_sync.py new file mode 100644 index 0000000000..03b78f94e8 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_dataset_service_update_dataset_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateDataset +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_DatasetService_UpdateDataset_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_update_dataset(): + # Create a client + client = aiplatform_v1beta1.DatasetServiceClient() + + # Initialize request argument(s) + dataset = aiplatform_v1beta1.Dataset() + dataset.display_name = "display_name_value" + dataset.metadata_schema_uri = "metadata_schema_uri_value" + dataset.metadata.null_value = "NULL_VALUE" + + request = aiplatform_v1beta1.UpdateDatasetRequest( + dataset=dataset, + ) + + # Make the request + response = client.update_dataset(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_DatasetService_UpdateDataset_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_create_endpoint_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_create_endpoint_async.py new file mode 100644 index 0000000000..e39f00f51b --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_create_endpoint_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_EndpointService_CreateEndpoint_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_endpoint(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + endpoint = aiplatform_v1beta1.Endpoint() + endpoint.display_name = "display_name_value" + + request = aiplatform_v1beta1.CreateEndpointRequest( + parent="parent_value", + endpoint=endpoint, + ) + + # Make the request + operation = client.create_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_EndpointService_CreateEndpoint_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_create_endpoint_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_create_endpoint_sync.py new file mode 100644 index 0000000000..4f8a59f4cd --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_create_endpoint_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_EndpointService_CreateEndpoint_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_endpoint(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceClient() + + # Initialize request argument(s) + endpoint = aiplatform_v1beta1.Endpoint() + endpoint.display_name = "display_name_value" + + request = aiplatform_v1beta1.CreateEndpointRequest( + parent="parent_value", + endpoint=endpoint, + ) + + # Make the request + operation = client.create_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_EndpointService_CreateEndpoint_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_delete_endpoint_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_delete_endpoint_async.py new file mode 100644 index 0000000000..29f9baf561 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_delete_endpoint_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_EndpointService_DeleteEndpoint_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_endpoint(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteEndpointRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_EndpointService_DeleteEndpoint_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_delete_endpoint_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_delete_endpoint_sync.py new file mode 100644 index 0000000000..56d5e4eaa5 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_delete_endpoint_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_EndpointService_DeleteEndpoint_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_endpoint(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteEndpointRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_EndpointService_DeleteEndpoint_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_deploy_model_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_deploy_model_async.py new file mode 100644 index 0000000000..93cad9575d --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_deploy_model_async.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeployModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_EndpointService_DeployModel_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_deploy_model(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + deployed_model = aiplatform_v1beta1.DeployedModel() + deployed_model.dedicated_resources.min_replica_count = 1803 + deployed_model.model = "model_value" + + request = aiplatform_v1beta1.DeployModelRequest( + endpoint="endpoint_value", + deployed_model=deployed_model, + ) + + # Make the request + operation = client.deploy_model(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_EndpointService_DeployModel_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_deploy_model_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_deploy_model_sync.py new file mode 100644 index 0000000000..9dba9f27f3 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_deploy_model_sync.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeployModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_EndpointService_DeployModel_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_deploy_model(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceClient() + + # Initialize request argument(s) + deployed_model = aiplatform_v1beta1.DeployedModel() + deployed_model.dedicated_resources.min_replica_count = 1803 + deployed_model.model = "model_value" + + request = aiplatform_v1beta1.DeployModelRequest( + endpoint="endpoint_value", + deployed_model=deployed_model, + ) + + # Make the request + operation = client.deploy_model(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_EndpointService_DeployModel_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_get_endpoint_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_get_endpoint_async.py new file mode 100644 index 0000000000..602de3b4bb --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_get_endpoint_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_EndpointService_GetEndpoint_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_endpoint(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetEndpointRequest( + name="name_value", + ) + + # Make the request + response = await client.get_endpoint(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_EndpointService_GetEndpoint_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_get_endpoint_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_get_endpoint_sync.py new file mode 100644 index 0000000000..79df67a22e --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_get_endpoint_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_EndpointService_GetEndpoint_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_endpoint(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetEndpointRequest( + name="name_value", + ) + + # Make the request + response = client.get_endpoint(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_EndpointService_GetEndpoint_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_list_endpoints_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_list_endpoints_async.py new file mode 100644 index 0000000000..9bacfc4230 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_list_endpoints_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListEndpoints +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_EndpointService_ListEndpoints_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_endpoints(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListEndpointsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_endpoints(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_EndpointService_ListEndpoints_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_list_endpoints_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_list_endpoints_sync.py new file mode 100644 index 0000000000..1a39d2b7cb --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_list_endpoints_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListEndpoints +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_EndpointService_ListEndpoints_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_endpoints(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListEndpointsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_endpoints(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_EndpointService_ListEndpoints_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_undeploy_model_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_undeploy_model_async.py new file mode 100644 index 0000000000..0838ddbc7c --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_undeploy_model_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UndeployModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_EndpointService_UndeployModel_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_undeploy_model(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UndeployModelRequest( + endpoint="endpoint_value", + deployed_model_id="deployed_model_id_value", + ) + + # Make the request + operation = client.undeploy_model(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_EndpointService_UndeployModel_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_undeploy_model_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_undeploy_model_sync.py new file mode 100644 index 0000000000..03443b2c08 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_undeploy_model_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UndeployModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_EndpointService_UndeployModel_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_undeploy_model(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UndeployModelRequest( + endpoint="endpoint_value", + deployed_model_id="deployed_model_id_value", + ) + + # Make the request + operation = client.undeploy_model(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_EndpointService_UndeployModel_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_update_endpoint_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_update_endpoint_async.py new file mode 100644 index 0000000000..42e01ce142 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_update_endpoint_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_EndpointService_UpdateEndpoint_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_update_endpoint(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceAsyncClient() + + # Initialize request argument(s) + endpoint = aiplatform_v1beta1.Endpoint() + endpoint.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateEndpointRequest( + endpoint=endpoint, + ) + + # Make the request + response = await client.update_endpoint(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_EndpointService_UpdateEndpoint_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_update_endpoint_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_update_endpoint_sync.py new file mode 100644 index 0000000000..c456bc03f4 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_endpoint_service_update_endpoint_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_EndpointService_UpdateEndpoint_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_update_endpoint(): + # Create a client + client = aiplatform_v1beta1.EndpointServiceClient() + + # Initialize request argument(s) + endpoint = aiplatform_v1beta1.Endpoint() + endpoint.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateEndpointRequest( + endpoint=endpoint, + ) + + # Make the request + response = client.update_endpoint(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_EndpointService_UpdateEndpoint_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_online_serving_service_read_feature_values_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_online_serving_service_read_feature_values_async.py new file mode 100644 index 0000000000..f7c6963218 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_online_serving_service_read_feature_values_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ReadFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreOnlineServingService_ReadFeatureValues_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_read_feature_values(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreOnlineServingServiceAsyncClient() + + # Initialize request argument(s) + feature_selector = aiplatform_v1beta1.FeatureSelector() + feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1beta1.ReadFeatureValuesRequest( + entity_type="entity_type_value", + entity_id="entity_id_value", + feature_selector=feature_selector, + ) + + # Make the request + response = await client.read_feature_values(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreOnlineServingService_ReadFeatureValues_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_online_serving_service_read_feature_values_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_online_serving_service_read_feature_values_sync.py new file mode 100644 index 0000000000..1098ded9e4 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_online_serving_service_read_feature_values_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ReadFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreOnlineServingService_ReadFeatureValues_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_read_feature_values(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreOnlineServingServiceClient() + + # Initialize request argument(s) + feature_selector = aiplatform_v1beta1.FeatureSelector() + feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1beta1.ReadFeatureValuesRequest( + entity_type="entity_type_value", + entity_id="entity_id_value", + feature_selector=feature_selector, + ) + + # Make the request + response = client.read_feature_values(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreOnlineServingService_ReadFeatureValues_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_online_serving_service_streaming_read_feature_values_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_online_serving_service_streaming_read_feature_values_async.py new file mode 100644 index 0000000000..b85bacf44b --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_online_serving_service_streaming_read_feature_values_async.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for StreamingReadFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreOnlineServingService_StreamingReadFeatureValues_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_streaming_read_feature_values(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreOnlineServingServiceAsyncClient() + + # Initialize request argument(s) + feature_selector = aiplatform_v1beta1.FeatureSelector() + feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1beta1.StreamingReadFeatureValuesRequest( + entity_type="entity_type_value", + entity_ids=['entity_ids_value_1', 'entity_ids_value_2'], + feature_selector=feature_selector, + ) + + # Make the request + stream = await client.streaming_read_feature_values(request=request) + + # Handle the response + async for response in stream: + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreOnlineServingService_StreamingReadFeatureValues_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_online_serving_service_streaming_read_feature_values_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_online_serving_service_streaming_read_feature_values_sync.py new file mode 100644 index 0000000000..70e59a5409 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_online_serving_service_streaming_read_feature_values_sync.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for StreamingReadFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreOnlineServingService_StreamingReadFeatureValues_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_streaming_read_feature_values(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreOnlineServingServiceClient() + + # Initialize request argument(s) + feature_selector = aiplatform_v1beta1.FeatureSelector() + feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1beta1.StreamingReadFeatureValuesRequest( + entity_type="entity_type_value", + entity_ids=['entity_ids_value_1', 'entity_ids_value_2'], + feature_selector=feature_selector, + ) + + # Make the request + stream = client.streaming_read_feature_values(request=request) + + # Handle the response + for response in stream: + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreOnlineServingService_StreamingReadFeatureValues_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_batch_create_features_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_batch_create_features_async.py new file mode 100644 index 0000000000..03c577cde7 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_batch_create_features_async.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchCreateFeatures +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_BatchCreateFeatures_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_batch_create_features(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + requests = aiplatform_v1beta1.CreateFeatureRequest() + requests.parent = "parent_value" + requests.feature.value_type = "BYTES" + requests.feature_id = "feature_id_value" + + request = aiplatform_v1beta1.BatchCreateFeaturesRequest( + parent="parent_value", + requests=requests, + ) + + # Make the request + operation = client.batch_create_features(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_BatchCreateFeatures_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_batch_create_features_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_batch_create_features_sync.py new file mode 100644 index 0000000000..1ed56a5a37 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_batch_create_features_sync.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchCreateFeatures +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_BatchCreateFeatures_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_batch_create_features(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + requests = aiplatform_v1beta1.CreateFeatureRequest() + requests.parent = "parent_value" + requests.feature.value_type = "BYTES" + requests.feature_id = "feature_id_value" + + request = aiplatform_v1beta1.BatchCreateFeaturesRequest( + parent="parent_value", + requests=requests, + ) + + # Make the request + operation = client.batch_create_features(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_BatchCreateFeatures_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_batch_read_feature_values_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_batch_read_feature_values_async.py new file mode 100644 index 0000000000..be6bb266ef --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_batch_read_feature_values_async.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchReadFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_BatchReadFeatureValues_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_batch_read_feature_values(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + csv_read_instances = aiplatform_v1beta1.CsvSource() + csv_read_instances.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + + destination = aiplatform_v1beta1.FeatureValueDestination() + destination.bigquery_destination.output_uri = "output_uri_value" + + entity_type_specs = aiplatform_v1beta1.EntityTypeSpec() + entity_type_specs.entity_type_id = "entity_type_id_value" + entity_type_specs.feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1beta1.BatchReadFeatureValuesRequest( + csv_read_instances=csv_read_instances, + featurestore="featurestore_value", + destination=destination, + entity_type_specs=entity_type_specs, + ) + + # Make the request + operation = client.batch_read_feature_values(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_BatchReadFeatureValues_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_batch_read_feature_values_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_batch_read_feature_values_sync.py new file mode 100644 index 0000000000..fee4dfdfc1 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_batch_read_feature_values_sync.py @@ -0,0 +1,62 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchReadFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_BatchReadFeatureValues_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_batch_read_feature_values(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + csv_read_instances = aiplatform_v1beta1.CsvSource() + csv_read_instances.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + + destination = aiplatform_v1beta1.FeatureValueDestination() + destination.bigquery_destination.output_uri = "output_uri_value" + + entity_type_specs = aiplatform_v1beta1.EntityTypeSpec() + entity_type_specs.entity_type_id = "entity_type_id_value" + entity_type_specs.feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1beta1.BatchReadFeatureValuesRequest( + csv_read_instances=csv_read_instances, + featurestore="featurestore_value", + destination=destination, + entity_type_specs=entity_type_specs, + ) + + # Make the request + operation = client.batch_read_feature_values(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_BatchReadFeatureValues_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_create_entity_type_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_create_entity_type_async.py new file mode 100644 index 0000000000..bd07902f04 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_create_entity_type_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateEntityType +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_CreateEntityType_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_entity_type(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateEntityTypeRequest( + parent="parent_value", + entity_type_id="entity_type_id_value", + ) + + # Make the request + operation = client.create_entity_type(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_CreateEntityType_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_create_entity_type_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_create_entity_type_sync.py new file mode 100644 index 0000000000..0dc8e423b1 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_create_entity_type_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateEntityType +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_CreateEntityType_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_entity_type(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateEntityTypeRequest( + parent="parent_value", + entity_type_id="entity_type_id_value", + ) + + # Make the request + operation = client.create_entity_type(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_CreateEntityType_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_create_feature_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_create_feature_async.py new file mode 100644 index 0000000000..9e6f792ee9 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_create_feature_async.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateFeature +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_CreateFeature_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_feature(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + feature = aiplatform_v1beta1.Feature() + feature.value_type = "BYTES" + + request = aiplatform_v1beta1.CreateFeatureRequest( + parent="parent_value", + feature=feature, + feature_id="feature_id_value", + ) + + # Make the request + operation = client.create_feature(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_CreateFeature_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_create_feature_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_create_feature_sync.py new file mode 100644 index 0000000000..3c8a040e19 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_create_feature_sync.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateFeature +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_CreateFeature_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_feature(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + feature = aiplatform_v1beta1.Feature() + feature.value_type = "BYTES" + + request = aiplatform_v1beta1.CreateFeatureRequest( + parent="parent_value", + feature=feature, + feature_id="feature_id_value", + ) + + # Make the request + operation = client.create_feature(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_CreateFeature_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_create_featurestore_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_create_featurestore_async.py new file mode 100644 index 0000000000..55c0265e60 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_create_featurestore_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateFeaturestore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_CreateFeaturestore_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_featurestore(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateFeaturestoreRequest( + parent="parent_value", + featurestore_id="featurestore_id_value", + ) + + # Make the request + operation = client.create_featurestore(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_CreateFeaturestore_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_create_featurestore_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_create_featurestore_sync.py new file mode 100644 index 0000000000..bae54da7e0 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_create_featurestore_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateFeaturestore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_CreateFeaturestore_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_featurestore(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateFeaturestoreRequest( + parent="parent_value", + featurestore_id="featurestore_id_value", + ) + + # Make the request + operation = client.create_featurestore(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_CreateFeaturestore_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_delete_entity_type_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_delete_entity_type_async.py new file mode 100644 index 0000000000..54f4a4f228 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_delete_entity_type_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteEntityType +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_DeleteEntityType_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_entity_type(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteEntityTypeRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_entity_type(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_DeleteEntityType_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_delete_entity_type_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_delete_entity_type_sync.py new file mode 100644 index 0000000000..45e8bed43e --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_delete_entity_type_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteEntityType +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_DeleteEntityType_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_entity_type(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteEntityTypeRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_entity_type(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_DeleteEntityType_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_delete_feature_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_delete_feature_async.py new file mode 100644 index 0000000000..162d4f4953 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_delete_feature_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteFeature +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_DeleteFeature_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_feature(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteFeatureRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_feature(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_DeleteFeature_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_delete_feature_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_delete_feature_sync.py new file mode 100644 index 0000000000..a52680308d --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_delete_feature_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteFeature +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_DeleteFeature_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_feature(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteFeatureRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_feature(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_DeleteFeature_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_delete_featurestore_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_delete_featurestore_async.py new file mode 100644 index 0000000000..f6b00a321c --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_delete_featurestore_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteFeaturestore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_DeleteFeaturestore_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_featurestore(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteFeaturestoreRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_featurestore(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_DeleteFeaturestore_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_delete_featurestore_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_delete_featurestore_sync.py new file mode 100644 index 0000000000..4ef5be9942 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_delete_featurestore_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteFeaturestore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_DeleteFeaturestore_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_featurestore(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteFeaturestoreRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_featurestore(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_DeleteFeaturestore_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_export_feature_values_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_export_feature_values_async.py new file mode 100644 index 0000000000..08d208189a --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_export_feature_values_async.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_ExportFeatureValues_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_export_feature_values(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + destination = aiplatform_v1beta1.FeatureValueDestination() + destination.bigquery_destination.output_uri = "output_uri_value" + + feature_selector = aiplatform_v1beta1.FeatureSelector() + feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1beta1.ExportFeatureValuesRequest( + entity_type="entity_type_value", + destination=destination, + feature_selector=feature_selector, + ) + + # Make the request + operation = client.export_feature_values(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_ExportFeatureValues_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_export_feature_values_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_export_feature_values_sync.py new file mode 100644 index 0000000000..11ae90f23e --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_export_feature_values_sync.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_ExportFeatureValues_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_export_feature_values(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + destination = aiplatform_v1beta1.FeatureValueDestination() + destination.bigquery_destination.output_uri = "output_uri_value" + + feature_selector = aiplatform_v1beta1.FeatureSelector() + feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2'] + + request = aiplatform_v1beta1.ExportFeatureValuesRequest( + entity_type="entity_type_value", + destination=destination, + feature_selector=feature_selector, + ) + + # Make the request + operation = client.export_feature_values(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_ExportFeatureValues_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_get_entity_type_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_get_entity_type_async.py new file mode 100644 index 0000000000..55abe4ca8c --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_get_entity_type_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetEntityType +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_GetEntityType_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_entity_type(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetEntityTypeRequest( + name="name_value", + ) + + # Make the request + response = await client.get_entity_type(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_GetEntityType_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_get_entity_type_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_get_entity_type_sync.py new file mode 100644 index 0000000000..7b6337b8c7 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_get_entity_type_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetEntityType +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_GetEntityType_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_entity_type(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetEntityTypeRequest( + name="name_value", + ) + + # Make the request + response = client.get_entity_type(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_GetEntityType_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_get_feature_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_get_feature_async.py new file mode 100644 index 0000000000..51e1f2893a --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_get_feature_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetFeature +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_GetFeature_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_feature(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetFeatureRequest( + name="name_value", + ) + + # Make the request + response = await client.get_feature(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_GetFeature_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_get_feature_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_get_feature_sync.py new file mode 100644 index 0000000000..34066681d2 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_get_feature_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetFeature +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_GetFeature_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_feature(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetFeatureRequest( + name="name_value", + ) + + # Make the request + response = client.get_feature(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_GetFeature_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_get_featurestore_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_get_featurestore_async.py new file mode 100644 index 0000000000..e6b01ff9df --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_get_featurestore_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetFeaturestore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_GetFeaturestore_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_featurestore(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetFeaturestoreRequest( + name="name_value", + ) + + # Make the request + response = await client.get_featurestore(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_GetFeaturestore_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_get_featurestore_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_get_featurestore_sync.py new file mode 100644 index 0000000000..a370c27282 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_get_featurestore_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetFeaturestore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_GetFeaturestore_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_featurestore(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetFeaturestoreRequest( + name="name_value", + ) + + # Make the request + response = client.get_featurestore(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_GetFeaturestore_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_import_feature_values_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_import_feature_values_async.py new file mode 100644 index 0000000000..fbb5550b9e --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_import_feature_values_async.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ImportFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_ImportFeatureValues_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_import_feature_values(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + avro_source = aiplatform_v1beta1.AvroSource() + avro_source.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + + feature_specs = aiplatform_v1beta1.FeatureSpec() + feature_specs.id = "id_value" + + request = aiplatform_v1beta1.ImportFeatureValuesRequest( + avro_source=avro_source, + feature_time_field="feature_time_field_value", + entity_type="entity_type_value", + feature_specs=feature_specs, + ) + + # Make the request + operation = client.import_feature_values(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_ImportFeatureValues_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_import_feature_values_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_import_feature_values_sync.py new file mode 100644 index 0000000000..b368090c97 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_import_feature_values_sync.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ImportFeatureValues +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_ImportFeatureValues_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_import_feature_values(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + avro_source = aiplatform_v1beta1.AvroSource() + avro_source.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + + feature_specs = aiplatform_v1beta1.FeatureSpec() + feature_specs.id = "id_value" + + request = aiplatform_v1beta1.ImportFeatureValuesRequest( + avro_source=avro_source, + feature_time_field="feature_time_field_value", + entity_type="entity_type_value", + feature_specs=feature_specs, + ) + + # Make the request + operation = client.import_feature_values(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_ImportFeatureValues_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_list_entity_types_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_list_entity_types_async.py new file mode 100644 index 0000000000..b67b8554d6 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_list_entity_types_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListEntityTypes +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_ListEntityTypes_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_entity_types(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListEntityTypesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_entity_types(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_ListEntityTypes_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_list_entity_types_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_list_entity_types_sync.py new file mode 100644 index 0000000000..101da137a4 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_list_entity_types_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListEntityTypes +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_ListEntityTypes_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_entity_types(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListEntityTypesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_entity_types(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_ListEntityTypes_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_list_features_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_list_features_async.py new file mode 100644 index 0000000000..87bae8d617 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_list_features_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListFeatures +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_ListFeatures_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_features(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListFeaturesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_features(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_ListFeatures_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_list_features_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_list_features_sync.py new file mode 100644 index 0000000000..97f95073aa --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_list_features_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListFeatures +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_ListFeatures_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_features(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListFeaturesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_features(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_ListFeatures_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_list_featurestores_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_list_featurestores_async.py new file mode 100644 index 0000000000..fab4bc0252 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_list_featurestores_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListFeaturestores +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_ListFeaturestores_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_featurestores(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListFeaturestoresRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_featurestores(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_ListFeaturestores_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_list_featurestores_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_list_featurestores_sync.py new file mode 100644 index 0000000000..bae9106bd1 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_list_featurestores_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListFeaturestores +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_ListFeaturestores_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_featurestores(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListFeaturestoresRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_featurestores(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_ListFeaturestores_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_search_features_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_search_features_async.py new file mode 100644 index 0000000000..b5b05cd290 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_search_features_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SearchFeatures +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_SearchFeatures_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_search_features(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.SearchFeaturesRequest( + location="location_value", + ) + + # Make the request + page_result = client.search_features(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_SearchFeatures_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_search_features_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_search_features_sync.py new file mode 100644 index 0000000000..422eb6df31 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_search_features_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SearchFeatures +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_SearchFeatures_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_search_features(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.SearchFeaturesRequest( + location="location_value", + ) + + # Make the request + page_result = client.search_features(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_SearchFeatures_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_update_entity_type_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_update_entity_type_async.py new file mode 100644 index 0000000000..7edcae5f25 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_update_entity_type_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateEntityType +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_UpdateEntityType_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_update_entity_type(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateEntityTypeRequest( + ) + + # Make the request + response = await client.update_entity_type(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_UpdateEntityType_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_update_entity_type_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_update_entity_type_sync.py new file mode 100644 index 0000000000..cead93e903 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_update_entity_type_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateEntityType +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_UpdateEntityType_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_update_entity_type(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateEntityTypeRequest( + ) + + # Make the request + response = client.update_entity_type(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_UpdateEntityType_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_update_feature_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_update_feature_async.py new file mode 100644 index 0000000000..403b48dff6 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_update_feature_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateFeature +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_UpdateFeature_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_update_feature(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + feature = aiplatform_v1beta1.Feature() + feature.value_type = "BYTES" + + request = aiplatform_v1beta1.UpdateFeatureRequest( + feature=feature, + ) + + # Make the request + response = await client.update_feature(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_UpdateFeature_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_update_feature_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_update_feature_sync.py new file mode 100644 index 0000000000..4e0513690d --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_update_feature_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateFeature +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_UpdateFeature_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_update_feature(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + feature = aiplatform_v1beta1.Feature() + feature.value_type = "BYTES" + + request = aiplatform_v1beta1.UpdateFeatureRequest( + feature=feature, + ) + + # Make the request + response = client.update_feature(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_UpdateFeature_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_update_featurestore_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_update_featurestore_async.py new file mode 100644 index 0000000000..6137c45be4 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_update_featurestore_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateFeaturestore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_UpdateFeaturestore_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_update_featurestore(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateFeaturestoreRequest( + ) + + # Make the request + operation = client.update_featurestore(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_UpdateFeaturestore_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_update_featurestore_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_update_featurestore_sync.py new file mode 100644 index 0000000000..66fc77cda6 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_featurestore_service_update_featurestore_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateFeaturestore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_FeaturestoreService_UpdateFeaturestore_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_update_featurestore(): + # Create a client + client = aiplatform_v1beta1.FeaturestoreServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateFeaturestoreRequest( + ) + + # Make the request + operation = client.update_featurestore(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_FeaturestoreService_UpdateFeaturestore_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_create_index_endpoint_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_create_index_endpoint_async.py new file mode 100644 index 0000000000..3c6fff682e --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_create_index_endpoint_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateIndexEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_IndexEndpointService_CreateIndexEndpoint_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_index_endpoint(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + index_endpoint = aiplatform_v1beta1.IndexEndpoint() + index_endpoint.display_name = "display_name_value" + + request = aiplatform_v1beta1.CreateIndexEndpointRequest( + parent="parent_value", + index_endpoint=index_endpoint, + ) + + # Make the request + operation = client.create_index_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_IndexEndpointService_CreateIndexEndpoint_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_create_index_endpoint_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_create_index_endpoint_sync.py new file mode 100644 index 0000000000..bac6e73ba6 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_create_index_endpoint_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateIndexEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_IndexEndpointService_CreateIndexEndpoint_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_index_endpoint(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceClient() + + # Initialize request argument(s) + index_endpoint = aiplatform_v1beta1.IndexEndpoint() + index_endpoint.display_name = "display_name_value" + + request = aiplatform_v1beta1.CreateIndexEndpointRequest( + parent="parent_value", + index_endpoint=index_endpoint, + ) + + # Make the request + operation = client.create_index_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_IndexEndpointService_CreateIndexEndpoint_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_delete_index_endpoint_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_delete_index_endpoint_async.py new file mode 100644 index 0000000000..df6eae815e --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_delete_index_endpoint_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteIndexEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_IndexEndpointService_DeleteIndexEndpoint_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_index_endpoint(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteIndexEndpointRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_index_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_IndexEndpointService_DeleteIndexEndpoint_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_delete_index_endpoint_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_delete_index_endpoint_sync.py new file mode 100644 index 0000000000..0f0eb7e4cd --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_delete_index_endpoint_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteIndexEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_IndexEndpointService_DeleteIndexEndpoint_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_index_endpoint(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteIndexEndpointRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_index_endpoint(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_IndexEndpointService_DeleteIndexEndpoint_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_deploy_index_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_deploy_index_async.py new file mode 100644 index 0000000000..578032ecab --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_deploy_index_async.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeployIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_IndexEndpointService_DeployIndex_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_deploy_index(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + deployed_index = aiplatform_v1beta1.DeployedIndex() + deployed_index.id = "id_value" + deployed_index.index = "index_value" + + request = aiplatform_v1beta1.DeployIndexRequest( + index_endpoint="index_endpoint_value", + deployed_index=deployed_index, + ) + + # Make the request + operation = client.deploy_index(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_IndexEndpointService_DeployIndex_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_deploy_index_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_deploy_index_sync.py new file mode 100644 index 0000000000..c3100783d3 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_deploy_index_sync.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeployIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_IndexEndpointService_DeployIndex_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_deploy_index(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceClient() + + # Initialize request argument(s) + deployed_index = aiplatform_v1beta1.DeployedIndex() + deployed_index.id = "id_value" + deployed_index.index = "index_value" + + request = aiplatform_v1beta1.DeployIndexRequest( + index_endpoint="index_endpoint_value", + deployed_index=deployed_index, + ) + + # Make the request + operation = client.deploy_index(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_IndexEndpointService_DeployIndex_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_get_index_endpoint_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_get_index_endpoint_async.py new file mode 100644 index 0000000000..1083e72b06 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_get_index_endpoint_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetIndexEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_IndexEndpointService_GetIndexEndpoint_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_index_endpoint(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetIndexEndpointRequest( + name="name_value", + ) + + # Make the request + response = await client.get_index_endpoint(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_IndexEndpointService_GetIndexEndpoint_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_get_index_endpoint_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_get_index_endpoint_sync.py new file mode 100644 index 0000000000..bce70eed7a --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_get_index_endpoint_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetIndexEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_IndexEndpointService_GetIndexEndpoint_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_index_endpoint(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetIndexEndpointRequest( + name="name_value", + ) + + # Make the request + response = client.get_index_endpoint(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_IndexEndpointService_GetIndexEndpoint_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_list_index_endpoints_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_list_index_endpoints_async.py new file mode 100644 index 0000000000..dd0b43a9fb --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_list_index_endpoints_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListIndexEndpoints +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_IndexEndpointService_ListIndexEndpoints_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_index_endpoints(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListIndexEndpointsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_index_endpoints(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_IndexEndpointService_ListIndexEndpoints_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_list_index_endpoints_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_list_index_endpoints_sync.py new file mode 100644 index 0000000000..dc50814ddb --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_list_index_endpoints_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListIndexEndpoints +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_IndexEndpointService_ListIndexEndpoints_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_index_endpoints(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListIndexEndpointsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_index_endpoints(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_IndexEndpointService_ListIndexEndpoints_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_mutate_deployed_index_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_mutate_deployed_index_async.py new file mode 100644 index 0000000000..fa6f730deb --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_mutate_deployed_index_async.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for MutateDeployedIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_IndexEndpointService_MutateDeployedIndex_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_mutate_deployed_index(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + deployed_index = aiplatform_v1beta1.DeployedIndex() + deployed_index.id = "id_value" + deployed_index.index = "index_value" + + request = aiplatform_v1beta1.MutateDeployedIndexRequest( + index_endpoint="index_endpoint_value", + deployed_index=deployed_index, + ) + + # Make the request + operation = client.mutate_deployed_index(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_IndexEndpointService_MutateDeployedIndex_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_mutate_deployed_index_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_mutate_deployed_index_sync.py new file mode 100644 index 0000000000..af37ccb450 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_mutate_deployed_index_sync.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for MutateDeployedIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_IndexEndpointService_MutateDeployedIndex_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_mutate_deployed_index(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceClient() + + # Initialize request argument(s) + deployed_index = aiplatform_v1beta1.DeployedIndex() + deployed_index.id = "id_value" + deployed_index.index = "index_value" + + request = aiplatform_v1beta1.MutateDeployedIndexRequest( + index_endpoint="index_endpoint_value", + deployed_index=deployed_index, + ) + + # Make the request + operation = client.mutate_deployed_index(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_IndexEndpointService_MutateDeployedIndex_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_undeploy_index_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_undeploy_index_async.py new file mode 100644 index 0000000000..c62dd2408b --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_undeploy_index_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UndeployIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_IndexEndpointService_UndeployIndex_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_undeploy_index(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UndeployIndexRequest( + index_endpoint="index_endpoint_value", + deployed_index_id="deployed_index_id_value", + ) + + # Make the request + operation = client.undeploy_index(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_IndexEndpointService_UndeployIndex_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_undeploy_index_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_undeploy_index_sync.py new file mode 100644 index 0000000000..8605878dbe --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_undeploy_index_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UndeployIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_IndexEndpointService_UndeployIndex_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_undeploy_index(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UndeployIndexRequest( + index_endpoint="index_endpoint_value", + deployed_index_id="deployed_index_id_value", + ) + + # Make the request + operation = client.undeploy_index(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_IndexEndpointService_UndeployIndex_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_update_index_endpoint_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_update_index_endpoint_async.py new file mode 100644 index 0000000000..9c29e14327 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_update_index_endpoint_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateIndexEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_IndexEndpointService_UpdateIndexEndpoint_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_update_index_endpoint(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceAsyncClient() + + # Initialize request argument(s) + index_endpoint = aiplatform_v1beta1.IndexEndpoint() + index_endpoint.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateIndexEndpointRequest( + index_endpoint=index_endpoint, + ) + + # Make the request + response = await client.update_index_endpoint(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_IndexEndpointService_UpdateIndexEndpoint_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_update_index_endpoint_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_update_index_endpoint_sync.py new file mode 100644 index 0000000000..c3c213c461 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_index_endpoint_service_update_index_endpoint_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateIndexEndpoint +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_IndexEndpointService_UpdateIndexEndpoint_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_update_index_endpoint(): + # Create a client + client = aiplatform_v1beta1.IndexEndpointServiceClient() + + # Initialize request argument(s) + index_endpoint = aiplatform_v1beta1.IndexEndpoint() + index_endpoint.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateIndexEndpointRequest( + index_endpoint=index_endpoint, + ) + + # Make the request + response = client.update_index_endpoint(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_IndexEndpointService_UpdateIndexEndpoint_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_index_service_create_index_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_index_service_create_index_async.py new file mode 100644 index 0000000000..4424f64bc7 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_index_service_create_index_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_IndexService_CreateIndex_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_index(): + # Create a client + client = aiplatform_v1beta1.IndexServiceAsyncClient() + + # Initialize request argument(s) + index = aiplatform_v1beta1.Index() + index.display_name = "display_name_value" + + request = aiplatform_v1beta1.CreateIndexRequest( + parent="parent_value", + index=index, + ) + + # Make the request + operation = client.create_index(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_IndexService_CreateIndex_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_index_service_create_index_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_index_service_create_index_sync.py new file mode 100644 index 0000000000..b741299dab --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_index_service_create_index_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_IndexService_CreateIndex_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_index(): + # Create a client + client = aiplatform_v1beta1.IndexServiceClient() + + # Initialize request argument(s) + index = aiplatform_v1beta1.Index() + index.display_name = "display_name_value" + + request = aiplatform_v1beta1.CreateIndexRequest( + parent="parent_value", + index=index, + ) + + # Make the request + operation = client.create_index(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_IndexService_CreateIndex_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_index_service_delete_index_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_index_service_delete_index_async.py new file mode 100644 index 0000000000..02c604c849 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_index_service_delete_index_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_IndexService_DeleteIndex_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_index(): + # Create a client + client = aiplatform_v1beta1.IndexServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteIndexRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_index(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_IndexService_DeleteIndex_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_index_service_delete_index_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_index_service_delete_index_sync.py new file mode 100644 index 0000000000..b55e86a2d9 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_index_service_delete_index_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_IndexService_DeleteIndex_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_index(): + # Create a client + client = aiplatform_v1beta1.IndexServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteIndexRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_index(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_IndexService_DeleteIndex_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_index_service_get_index_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_index_service_get_index_async.py new file mode 100644 index 0000000000..5be45b1802 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_index_service_get_index_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_IndexService_GetIndex_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_index(): + # Create a client + client = aiplatform_v1beta1.IndexServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetIndexRequest( + name="name_value", + ) + + # Make the request + response = await client.get_index(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_IndexService_GetIndex_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_index_service_get_index_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_index_service_get_index_sync.py new file mode 100644 index 0000000000..5827bff3e4 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_index_service_get_index_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_IndexService_GetIndex_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_index(): + # Create a client + client = aiplatform_v1beta1.IndexServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetIndexRequest( + name="name_value", + ) + + # Make the request + response = client.get_index(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_IndexService_GetIndex_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_index_service_list_indexes_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_index_service_list_indexes_async.py new file mode 100644 index 0000000000..011938c402 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_index_service_list_indexes_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListIndexes +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_IndexService_ListIndexes_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_indexes(): + # Create a client + client = aiplatform_v1beta1.IndexServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListIndexesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_indexes(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_IndexService_ListIndexes_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_index_service_list_indexes_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_index_service_list_indexes_sync.py new file mode 100644 index 0000000000..8d64d779c9 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_index_service_list_indexes_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListIndexes +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_IndexService_ListIndexes_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_indexes(): + # Create a client + client = aiplatform_v1beta1.IndexServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListIndexesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_indexes(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_IndexService_ListIndexes_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_index_service_update_index_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_index_service_update_index_async.py new file mode 100644 index 0000000000..be4999a8c7 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_index_service_update_index_async.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_IndexService_UpdateIndex_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_update_index(): + # Create a client + client = aiplatform_v1beta1.IndexServiceAsyncClient() + + # Initialize request argument(s) + index = aiplatform_v1beta1.Index() + index.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateIndexRequest( + index=index, + ) + + # Make the request + operation = client.update_index(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_IndexService_UpdateIndex_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_index_service_update_index_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_index_service_update_index_sync.py new file mode 100644 index 0000000000..dcc2cb5263 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_index_service_update_index_sync.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateIndex +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_IndexService_UpdateIndex_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_update_index(): + # Create a client + client = aiplatform_v1beta1.IndexServiceClient() + + # Initialize request argument(s) + index = aiplatform_v1beta1.Index() + index.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateIndexRequest( + index=index, + ) + + # Make the request + operation = client.update_index(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_IndexService_UpdateIndex_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_cancel_batch_prediction_job_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_cancel_batch_prediction_job_async.py new file mode 100644 index 0000000000..ba03ab89e8 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_cancel_batch_prediction_job_async.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelBatchPredictionJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_CancelBatchPredictionJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_cancel_batch_prediction_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CancelBatchPredictionJobRequest( + name="name_value", + ) + + # Make the request + await client.cancel_batch_prediction_job(request=request) + + +# [END aiplatform_v1beta1_generated_JobService_CancelBatchPredictionJob_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_cancel_batch_prediction_job_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_cancel_batch_prediction_job_sync.py new file mode 100644 index 0000000000..3121919254 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_cancel_batch_prediction_job_sync.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelBatchPredictionJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_CancelBatchPredictionJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_cancel_batch_prediction_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CancelBatchPredictionJobRequest( + name="name_value", + ) + + # Make the request + client.cancel_batch_prediction_job(request=request) + + +# [END aiplatform_v1beta1_generated_JobService_CancelBatchPredictionJob_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_cancel_custom_job_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_cancel_custom_job_async.py new file mode 100644 index 0000000000..88ad6ef326 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_cancel_custom_job_async.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelCustomJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_CancelCustomJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_cancel_custom_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CancelCustomJobRequest( + name="name_value", + ) + + # Make the request + await client.cancel_custom_job(request=request) + + +# [END aiplatform_v1beta1_generated_JobService_CancelCustomJob_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_cancel_custom_job_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_cancel_custom_job_sync.py new file mode 100644 index 0000000000..512422f1ae --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_cancel_custom_job_sync.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelCustomJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_CancelCustomJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_cancel_custom_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CancelCustomJobRequest( + name="name_value", + ) + + # Make the request + client.cancel_custom_job(request=request) + + +# [END aiplatform_v1beta1_generated_JobService_CancelCustomJob_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_cancel_data_labeling_job_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_cancel_data_labeling_job_async.py new file mode 100644 index 0000000000..c9a1df76d9 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_cancel_data_labeling_job_async.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelDataLabelingJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_CancelDataLabelingJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_cancel_data_labeling_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CancelDataLabelingJobRequest( + name="name_value", + ) + + # Make the request + await client.cancel_data_labeling_job(request=request) + + +# [END aiplatform_v1beta1_generated_JobService_CancelDataLabelingJob_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_cancel_data_labeling_job_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_cancel_data_labeling_job_sync.py new file mode 100644 index 0000000000..a6e9a38057 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_cancel_data_labeling_job_sync.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelDataLabelingJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_CancelDataLabelingJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_cancel_data_labeling_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CancelDataLabelingJobRequest( + name="name_value", + ) + + # Make the request + client.cancel_data_labeling_job(request=request) + + +# [END aiplatform_v1beta1_generated_JobService_CancelDataLabelingJob_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_cancel_hyperparameter_tuning_job_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_cancel_hyperparameter_tuning_job_async.py new file mode 100644 index 0000000000..3b8639f0ea --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_cancel_hyperparameter_tuning_job_async.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelHyperparameterTuningJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_CancelHyperparameterTuningJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_cancel_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CancelHyperparameterTuningJobRequest( + name="name_value", + ) + + # Make the request + await client.cancel_hyperparameter_tuning_job(request=request) + + +# [END aiplatform_v1beta1_generated_JobService_CancelHyperparameterTuningJob_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_cancel_hyperparameter_tuning_job_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_cancel_hyperparameter_tuning_job_sync.py new file mode 100644 index 0000000000..12208f4859 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_cancel_hyperparameter_tuning_job_sync.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelHyperparameterTuningJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_CancelHyperparameterTuningJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_cancel_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CancelHyperparameterTuningJobRequest( + name="name_value", + ) + + # Make the request + client.cancel_hyperparameter_tuning_job(request=request) + + +# [END aiplatform_v1beta1_generated_JobService_CancelHyperparameterTuningJob_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_create_batch_prediction_job_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_create_batch_prediction_job_async.py new file mode 100644 index 0000000000..a9fc8f3759 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_create_batch_prediction_job_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateBatchPredictionJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_CreateBatchPredictionJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_batch_prediction_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + batch_prediction_job = aiplatform_v1beta1.BatchPredictionJob() + batch_prediction_job.display_name = "display_name_value" + batch_prediction_job.input_config.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + batch_prediction_job.input_config.instances_format = "instances_format_value" + batch_prediction_job.output_config.gcs_destination.output_uri_prefix = "output_uri_prefix_value" + batch_prediction_job.output_config.predictions_format = "predictions_format_value" + + request = aiplatform_v1beta1.CreateBatchPredictionJobRequest( + parent="parent_value", + batch_prediction_job=batch_prediction_job, + ) + + # Make the request + response = await client.create_batch_prediction_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_JobService_CreateBatchPredictionJob_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_create_batch_prediction_job_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_create_batch_prediction_job_sync.py new file mode 100644 index 0000000000..722d9299ef --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_create_batch_prediction_job_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateBatchPredictionJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_CreateBatchPredictionJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_batch_prediction_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + batch_prediction_job = aiplatform_v1beta1.BatchPredictionJob() + batch_prediction_job.display_name = "display_name_value" + batch_prediction_job.input_config.gcs_source.uris = ['uris_value_1', 'uris_value_2'] + batch_prediction_job.input_config.instances_format = "instances_format_value" + batch_prediction_job.output_config.gcs_destination.output_uri_prefix = "output_uri_prefix_value" + batch_prediction_job.output_config.predictions_format = "predictions_format_value" + + request = aiplatform_v1beta1.CreateBatchPredictionJobRequest( + parent="parent_value", + batch_prediction_job=batch_prediction_job, + ) + + # Make the request + response = client.create_batch_prediction_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_JobService_CreateBatchPredictionJob_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_create_custom_job_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_create_custom_job_async.py new file mode 100644 index 0000000000..6351151c93 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_create_custom_job_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateCustomJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_CreateCustomJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_custom_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + custom_job = aiplatform_v1beta1.CustomJob() + custom_job.display_name = "display_name_value" + custom_job.job_spec.worker_pool_specs.container_spec.image_uri = "image_uri_value" + + request = aiplatform_v1beta1.CreateCustomJobRequest( + parent="parent_value", + custom_job=custom_job, + ) + + # Make the request + response = await client.create_custom_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_JobService_CreateCustomJob_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_create_custom_job_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_create_custom_job_sync.py new file mode 100644 index 0000000000..8b33f1ba39 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_create_custom_job_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateCustomJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_CreateCustomJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_custom_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + custom_job = aiplatform_v1beta1.CustomJob() + custom_job.display_name = "display_name_value" + custom_job.job_spec.worker_pool_specs.container_spec.image_uri = "image_uri_value" + + request = aiplatform_v1beta1.CreateCustomJobRequest( + parent="parent_value", + custom_job=custom_job, + ) + + # Make the request + response = client.create_custom_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_JobService_CreateCustomJob_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_create_data_labeling_job_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_create_data_labeling_job_async.py new file mode 100644 index 0000000000..562c7544d7 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_create_data_labeling_job_async.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateDataLabelingJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_CreateDataLabelingJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_data_labeling_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + data_labeling_job = aiplatform_v1beta1.DataLabelingJob() + data_labeling_job.display_name = "display_name_value" + data_labeling_job.datasets = ['datasets_value_1', 'datasets_value_2'] + data_labeling_job.labeler_count = 1375 + data_labeling_job.instruction_uri = "instruction_uri_value" + data_labeling_job.inputs_schema_uri = "inputs_schema_uri_value" + data_labeling_job.inputs.null_value = "NULL_VALUE" + + request = aiplatform_v1beta1.CreateDataLabelingJobRequest( + parent="parent_value", + data_labeling_job=data_labeling_job, + ) + + # Make the request + response = await client.create_data_labeling_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_JobService_CreateDataLabelingJob_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_create_data_labeling_job_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_create_data_labeling_job_sync.py new file mode 100644 index 0000000000..5b2d75e1fb --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_create_data_labeling_job_sync.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateDataLabelingJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_CreateDataLabelingJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_data_labeling_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + data_labeling_job = aiplatform_v1beta1.DataLabelingJob() + data_labeling_job.display_name = "display_name_value" + data_labeling_job.datasets = ['datasets_value_1', 'datasets_value_2'] + data_labeling_job.labeler_count = 1375 + data_labeling_job.instruction_uri = "instruction_uri_value" + data_labeling_job.inputs_schema_uri = "inputs_schema_uri_value" + data_labeling_job.inputs.null_value = "NULL_VALUE" + + request = aiplatform_v1beta1.CreateDataLabelingJobRequest( + parent="parent_value", + data_labeling_job=data_labeling_job, + ) + + # Make the request + response = client.create_data_labeling_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_JobService_CreateDataLabelingJob_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_create_hyperparameter_tuning_job_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_create_hyperparameter_tuning_job_async.py new file mode 100644 index 0000000000..a9efcb8325 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_create_hyperparameter_tuning_job_async.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateHyperparameterTuningJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_CreateHyperparameterTuningJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + hyperparameter_tuning_job = aiplatform_v1beta1.HyperparameterTuningJob() + hyperparameter_tuning_job.display_name = "display_name_value" + hyperparameter_tuning_job.study_spec.metrics.metric_id = "metric_id_value" + hyperparameter_tuning_job.study_spec.metrics.goal = "MINIMIZE" + hyperparameter_tuning_job.study_spec.parameters.double_value_spec.min_value = 0.96 + hyperparameter_tuning_job.study_spec.parameters.double_value_spec.max_value = 0.962 + hyperparameter_tuning_job.study_spec.parameters.parameter_id = "parameter_id_value" + hyperparameter_tuning_job.max_trial_count = 1609 + hyperparameter_tuning_job.parallel_trial_count = 2128 + hyperparameter_tuning_job.trial_job_spec.worker_pool_specs.container_spec.image_uri = "image_uri_value" + + request = aiplatform_v1beta1.CreateHyperparameterTuningJobRequest( + parent="parent_value", + hyperparameter_tuning_job=hyperparameter_tuning_job, + ) + + # Make the request + response = await client.create_hyperparameter_tuning_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_JobService_CreateHyperparameterTuningJob_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_create_hyperparameter_tuning_job_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_create_hyperparameter_tuning_job_sync.py new file mode 100644 index 0000000000..897a527b33 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_create_hyperparameter_tuning_job_sync.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateHyperparameterTuningJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_CreateHyperparameterTuningJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + hyperparameter_tuning_job = aiplatform_v1beta1.HyperparameterTuningJob() + hyperparameter_tuning_job.display_name = "display_name_value" + hyperparameter_tuning_job.study_spec.metrics.metric_id = "metric_id_value" + hyperparameter_tuning_job.study_spec.metrics.goal = "MINIMIZE" + hyperparameter_tuning_job.study_spec.parameters.double_value_spec.min_value = 0.96 + hyperparameter_tuning_job.study_spec.parameters.double_value_spec.max_value = 0.962 + hyperparameter_tuning_job.study_spec.parameters.parameter_id = "parameter_id_value" + hyperparameter_tuning_job.max_trial_count = 1609 + hyperparameter_tuning_job.parallel_trial_count = 2128 + hyperparameter_tuning_job.trial_job_spec.worker_pool_specs.container_spec.image_uri = "image_uri_value" + + request = aiplatform_v1beta1.CreateHyperparameterTuningJobRequest( + parent="parent_value", + hyperparameter_tuning_job=hyperparameter_tuning_job, + ) + + # Make the request + response = client.create_hyperparameter_tuning_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_JobService_CreateHyperparameterTuningJob_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_create_model_deployment_monitoring_job_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_create_model_deployment_monitoring_job_async.py new file mode 100644 index 0000000000..b3254041ce --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_create_model_deployment_monitoring_job_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_CreateModelDeploymentMonitoringJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + model_deployment_monitoring_job = aiplatform_v1beta1.ModelDeploymentMonitoringJob() + model_deployment_monitoring_job.display_name = "display_name_value" + model_deployment_monitoring_job.endpoint = "endpoint_value" + + request = aiplatform_v1beta1.CreateModelDeploymentMonitoringJobRequest( + parent="parent_value", + model_deployment_monitoring_job=model_deployment_monitoring_job, + ) + + # Make the request + response = await client.create_model_deployment_monitoring_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_JobService_CreateModelDeploymentMonitoringJob_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_create_model_deployment_monitoring_job_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_create_model_deployment_monitoring_job_sync.py new file mode 100644 index 0000000000..dcfbd6d5f6 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_create_model_deployment_monitoring_job_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_CreateModelDeploymentMonitoringJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + model_deployment_monitoring_job = aiplatform_v1beta1.ModelDeploymentMonitoringJob() + model_deployment_monitoring_job.display_name = "display_name_value" + model_deployment_monitoring_job.endpoint = "endpoint_value" + + request = aiplatform_v1beta1.CreateModelDeploymentMonitoringJobRequest( + parent="parent_value", + model_deployment_monitoring_job=model_deployment_monitoring_job, + ) + + # Make the request + response = client.create_model_deployment_monitoring_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_JobService_CreateModelDeploymentMonitoringJob_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_delete_batch_prediction_job_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_delete_batch_prediction_job_async.py new file mode 100644 index 0000000000..5da9337e99 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_delete_batch_prediction_job_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteBatchPredictionJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_DeleteBatchPredictionJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_batch_prediction_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteBatchPredictionJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_batch_prediction_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_JobService_DeleteBatchPredictionJob_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_delete_batch_prediction_job_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_delete_batch_prediction_job_sync.py new file mode 100644 index 0000000000..d629433bff --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_delete_batch_prediction_job_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteBatchPredictionJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_DeleteBatchPredictionJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_batch_prediction_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteBatchPredictionJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_batch_prediction_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_JobService_DeleteBatchPredictionJob_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_delete_custom_job_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_delete_custom_job_async.py new file mode 100644 index 0000000000..24f6d4cfd1 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_delete_custom_job_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteCustomJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_DeleteCustomJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_custom_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteCustomJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_custom_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_JobService_DeleteCustomJob_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_delete_custom_job_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_delete_custom_job_sync.py new file mode 100644 index 0000000000..6e0f0bd7b4 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_delete_custom_job_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteCustomJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_DeleteCustomJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_custom_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteCustomJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_custom_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_JobService_DeleteCustomJob_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_delete_data_labeling_job_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_delete_data_labeling_job_async.py new file mode 100644 index 0000000000..ed1b757258 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_delete_data_labeling_job_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteDataLabelingJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_DeleteDataLabelingJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_data_labeling_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteDataLabelingJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_data_labeling_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_JobService_DeleteDataLabelingJob_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_delete_data_labeling_job_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_delete_data_labeling_job_sync.py new file mode 100644 index 0000000000..2eab38d6b9 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_delete_data_labeling_job_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteDataLabelingJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_DeleteDataLabelingJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_data_labeling_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteDataLabelingJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_data_labeling_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_JobService_DeleteDataLabelingJob_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_delete_hyperparameter_tuning_job_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_delete_hyperparameter_tuning_job_async.py new file mode 100644 index 0000000000..988f314639 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_delete_hyperparameter_tuning_job_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteHyperparameterTuningJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_DeleteHyperparameterTuningJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteHyperparameterTuningJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_hyperparameter_tuning_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_JobService_DeleteHyperparameterTuningJob_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_delete_hyperparameter_tuning_job_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_delete_hyperparameter_tuning_job_sync.py new file mode 100644 index 0000000000..fa37df05fa --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_delete_hyperparameter_tuning_job_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteHyperparameterTuningJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_DeleteHyperparameterTuningJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteHyperparameterTuningJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_hyperparameter_tuning_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_JobService_DeleteHyperparameterTuningJob_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_delete_model_deployment_monitoring_job_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_delete_model_deployment_monitoring_job_async.py new file mode 100644 index 0000000000..964cd314f6 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_delete_model_deployment_monitoring_job_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_DeleteModelDeploymentMonitoringJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_model_deployment_monitoring_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_JobService_DeleteModelDeploymentMonitoringJob_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_delete_model_deployment_monitoring_job_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_delete_model_deployment_monitoring_job_sync.py new file mode 100644 index 0000000000..cf618dd645 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_delete_model_deployment_monitoring_job_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_DeleteModelDeploymentMonitoringJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_model_deployment_monitoring_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_JobService_DeleteModelDeploymentMonitoringJob_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_get_batch_prediction_job_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_get_batch_prediction_job_async.py new file mode 100644 index 0000000000..0dd2177c0c --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_get_batch_prediction_job_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetBatchPredictionJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_GetBatchPredictionJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_batch_prediction_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetBatchPredictionJobRequest( + name="name_value", + ) + + # Make the request + response = await client.get_batch_prediction_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_JobService_GetBatchPredictionJob_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_get_batch_prediction_job_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_get_batch_prediction_job_sync.py new file mode 100644 index 0000000000..9b239136d3 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_get_batch_prediction_job_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetBatchPredictionJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_GetBatchPredictionJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_batch_prediction_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetBatchPredictionJobRequest( + name="name_value", + ) + + # Make the request + response = client.get_batch_prediction_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_JobService_GetBatchPredictionJob_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_get_custom_job_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_get_custom_job_async.py new file mode 100644 index 0000000000..50e3451cdd --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_get_custom_job_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetCustomJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_GetCustomJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_custom_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetCustomJobRequest( + name="name_value", + ) + + # Make the request + response = await client.get_custom_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_JobService_GetCustomJob_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_get_custom_job_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_get_custom_job_sync.py new file mode 100644 index 0000000000..24b599eb63 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_get_custom_job_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetCustomJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_GetCustomJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_custom_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetCustomJobRequest( + name="name_value", + ) + + # Make the request + response = client.get_custom_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_JobService_GetCustomJob_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_get_data_labeling_job_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_get_data_labeling_job_async.py new file mode 100644 index 0000000000..4b99f7417b --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_get_data_labeling_job_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetDataLabelingJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_GetDataLabelingJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_data_labeling_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetDataLabelingJobRequest( + name="name_value", + ) + + # Make the request + response = await client.get_data_labeling_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_JobService_GetDataLabelingJob_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_get_data_labeling_job_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_get_data_labeling_job_sync.py new file mode 100644 index 0000000000..b50e4560cf --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_get_data_labeling_job_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetDataLabelingJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_GetDataLabelingJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_data_labeling_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetDataLabelingJobRequest( + name="name_value", + ) + + # Make the request + response = client.get_data_labeling_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_JobService_GetDataLabelingJob_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_get_hyperparameter_tuning_job_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_get_hyperparameter_tuning_job_async.py new file mode 100644 index 0000000000..d9442b24e4 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_get_hyperparameter_tuning_job_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetHyperparameterTuningJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_GetHyperparameterTuningJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetHyperparameterTuningJobRequest( + name="name_value", + ) + + # Make the request + response = await client.get_hyperparameter_tuning_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_JobService_GetHyperparameterTuningJob_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_get_hyperparameter_tuning_job_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_get_hyperparameter_tuning_job_sync.py new file mode 100644 index 0000000000..81e81ed50e --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_get_hyperparameter_tuning_job_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetHyperparameterTuningJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_GetHyperparameterTuningJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_hyperparameter_tuning_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetHyperparameterTuningJobRequest( + name="name_value", + ) + + # Make the request + response = client.get_hyperparameter_tuning_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_JobService_GetHyperparameterTuningJob_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_get_model_deployment_monitoring_job_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_get_model_deployment_monitoring_job_async.py new file mode 100644 index 0000000000..04c4807aed --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_get_model_deployment_monitoring_job_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_GetModelDeploymentMonitoringJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + response = await client.get_model_deployment_monitoring_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_JobService_GetModelDeploymentMonitoringJob_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_get_model_deployment_monitoring_job_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_get_model_deployment_monitoring_job_sync.py new file mode 100644 index 0000000000..98c2a22367 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_get_model_deployment_monitoring_job_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_GetModelDeploymentMonitoringJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + response = client.get_model_deployment_monitoring_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_JobService_GetModelDeploymentMonitoringJob_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_list_batch_prediction_jobs_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_list_batch_prediction_jobs_async.py new file mode 100644 index 0000000000..4823327421 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_list_batch_prediction_jobs_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListBatchPredictionJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_ListBatchPredictionJobs_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_batch_prediction_jobs(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListBatchPredictionJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_batch_prediction_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_JobService_ListBatchPredictionJobs_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_list_batch_prediction_jobs_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_list_batch_prediction_jobs_sync.py new file mode 100644 index 0000000000..2ec0ea59b2 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_list_batch_prediction_jobs_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListBatchPredictionJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_ListBatchPredictionJobs_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_batch_prediction_jobs(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListBatchPredictionJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_batch_prediction_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_JobService_ListBatchPredictionJobs_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_list_custom_jobs_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_list_custom_jobs_async.py new file mode 100644 index 0000000000..6a337f9030 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_list_custom_jobs_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListCustomJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_ListCustomJobs_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_custom_jobs(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListCustomJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_custom_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_JobService_ListCustomJobs_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_list_custom_jobs_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_list_custom_jobs_sync.py new file mode 100644 index 0000000000..43b3ea4593 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_list_custom_jobs_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListCustomJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_ListCustomJobs_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_custom_jobs(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListCustomJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_custom_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_JobService_ListCustomJobs_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_list_data_labeling_jobs_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_list_data_labeling_jobs_async.py new file mode 100644 index 0000000000..65870edc86 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_list_data_labeling_jobs_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDataLabelingJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_ListDataLabelingJobs_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_data_labeling_jobs(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListDataLabelingJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_data_labeling_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_JobService_ListDataLabelingJobs_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_list_data_labeling_jobs_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_list_data_labeling_jobs_sync.py new file mode 100644 index 0000000000..757ba1fa2d --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_list_data_labeling_jobs_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListDataLabelingJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_ListDataLabelingJobs_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_data_labeling_jobs(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListDataLabelingJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_data_labeling_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_JobService_ListDataLabelingJobs_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_list_hyperparameter_tuning_jobs_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_list_hyperparameter_tuning_jobs_async.py new file mode 100644 index 0000000000..ba8f21ecfe --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_list_hyperparameter_tuning_jobs_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListHyperparameterTuningJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_ListHyperparameterTuningJobs_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_hyperparameter_tuning_jobs(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListHyperparameterTuningJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_hyperparameter_tuning_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_JobService_ListHyperparameterTuningJobs_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_list_hyperparameter_tuning_jobs_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_list_hyperparameter_tuning_jobs_sync.py new file mode 100644 index 0000000000..7d884a8d62 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_list_hyperparameter_tuning_jobs_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListHyperparameterTuningJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_ListHyperparameterTuningJobs_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_hyperparameter_tuning_jobs(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListHyperparameterTuningJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_hyperparameter_tuning_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_JobService_ListHyperparameterTuningJobs_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_list_model_deployment_monitoring_jobs_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_list_model_deployment_monitoring_jobs_async.py new file mode 100644 index 0000000000..878effea77 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_list_model_deployment_monitoring_jobs_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListModelDeploymentMonitoringJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_ListModelDeploymentMonitoringJobs_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_model_deployment_monitoring_jobs(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListModelDeploymentMonitoringJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_model_deployment_monitoring_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_JobService_ListModelDeploymentMonitoringJobs_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_list_model_deployment_monitoring_jobs_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_list_model_deployment_monitoring_jobs_sync.py new file mode 100644 index 0000000000..6a502bca9a --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_list_model_deployment_monitoring_jobs_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListModelDeploymentMonitoringJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_ListModelDeploymentMonitoringJobs_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_model_deployment_monitoring_jobs(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListModelDeploymentMonitoringJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_model_deployment_monitoring_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_JobService_ListModelDeploymentMonitoringJobs_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_pause_model_deployment_monitoring_job_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_pause_model_deployment_monitoring_job_async.py new file mode 100644 index 0000000000..27721a6378 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_pause_model_deployment_monitoring_job_async.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PauseModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_PauseModelDeploymentMonitoringJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_pause_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.PauseModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + await client.pause_model_deployment_monitoring_job(request=request) + + +# [END aiplatform_v1beta1_generated_JobService_PauseModelDeploymentMonitoringJob_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_pause_model_deployment_monitoring_job_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_pause_model_deployment_monitoring_job_sync.py new file mode 100644 index 0000000000..2053f9e73c --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_pause_model_deployment_monitoring_job_sync.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PauseModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_PauseModelDeploymentMonitoringJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_pause_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.PauseModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + client.pause_model_deployment_monitoring_job(request=request) + + +# [END aiplatform_v1beta1_generated_JobService_PauseModelDeploymentMonitoringJob_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_resume_model_deployment_monitoring_job_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_resume_model_deployment_monitoring_job_async.py new file mode 100644 index 0000000000..7980c3cd12 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_resume_model_deployment_monitoring_job_async.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ResumeModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_ResumeModelDeploymentMonitoringJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_resume_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ResumeModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + await client.resume_model_deployment_monitoring_job(request=request) + + +# [END aiplatform_v1beta1_generated_JobService_ResumeModelDeploymentMonitoringJob_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_resume_model_deployment_monitoring_job_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_resume_model_deployment_monitoring_job_sync.py new file mode 100644 index 0000000000..d79d66feda --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_resume_model_deployment_monitoring_job_sync.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ResumeModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_ResumeModelDeploymentMonitoringJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_resume_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ResumeModelDeploymentMonitoringJobRequest( + name="name_value", + ) + + # Make the request + client.resume_model_deployment_monitoring_job(request=request) + + +# [END aiplatform_v1beta1_generated_JobService_ResumeModelDeploymentMonitoringJob_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_search_model_deployment_monitoring_stats_anomalies_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_search_model_deployment_monitoring_stats_anomalies_async.py new file mode 100644 index 0000000000..156bd967ba --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_search_model_deployment_monitoring_stats_anomalies_async.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SearchModelDeploymentMonitoringStatsAnomalies +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_SearchModelDeploymentMonitoringStatsAnomalies_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_search_model_deployment_monitoring_stats_anomalies(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.SearchModelDeploymentMonitoringStatsAnomaliesRequest( + model_deployment_monitoring_job="model_deployment_monitoring_job_value", + deployed_model_id="deployed_model_id_value", + ) + + # Make the request + page_result = client.search_model_deployment_monitoring_stats_anomalies(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_JobService_SearchModelDeploymentMonitoringStatsAnomalies_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_search_model_deployment_monitoring_stats_anomalies_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_search_model_deployment_monitoring_stats_anomalies_sync.py new file mode 100644 index 0000000000..b7cf0a6b90 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_search_model_deployment_monitoring_stats_anomalies_sync.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SearchModelDeploymentMonitoringStatsAnomalies +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_SearchModelDeploymentMonitoringStatsAnomalies_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_search_model_deployment_monitoring_stats_anomalies(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.SearchModelDeploymentMonitoringStatsAnomaliesRequest( + model_deployment_monitoring_job="model_deployment_monitoring_job_value", + deployed_model_id="deployed_model_id_value", + ) + + # Make the request + page_result = client.search_model_deployment_monitoring_stats_anomalies(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_JobService_SearchModelDeploymentMonitoringStatsAnomalies_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_update_model_deployment_monitoring_job_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_update_model_deployment_monitoring_job_async.py new file mode 100644 index 0000000000..6b0a493fa3 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_update_model_deployment_monitoring_job_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_UpdateModelDeploymentMonitoringJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_update_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceAsyncClient() + + # Initialize request argument(s) + model_deployment_monitoring_job = aiplatform_v1beta1.ModelDeploymentMonitoringJob() + model_deployment_monitoring_job.display_name = "display_name_value" + model_deployment_monitoring_job.endpoint = "endpoint_value" + + request = aiplatform_v1beta1.UpdateModelDeploymentMonitoringJobRequest( + model_deployment_monitoring_job=model_deployment_monitoring_job, + ) + + # Make the request + operation = client.update_model_deployment_monitoring_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_JobService_UpdateModelDeploymentMonitoringJob_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_job_service_update_model_deployment_monitoring_job_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_update_model_deployment_monitoring_job_sync.py new file mode 100644 index 0000000000..5d989ac975 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_job_service_update_model_deployment_monitoring_job_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateModelDeploymentMonitoringJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_JobService_UpdateModelDeploymentMonitoringJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_update_model_deployment_monitoring_job(): + # Create a client + client = aiplatform_v1beta1.JobServiceClient() + + # Initialize request argument(s) + model_deployment_monitoring_job = aiplatform_v1beta1.ModelDeploymentMonitoringJob() + model_deployment_monitoring_job.display_name = "display_name_value" + model_deployment_monitoring_job.endpoint = "endpoint_value" + + request = aiplatform_v1beta1.UpdateModelDeploymentMonitoringJobRequest( + model_deployment_monitoring_job=model_deployment_monitoring_job, + ) + + # Make the request + operation = client.update_model_deployment_monitoring_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_JobService_UpdateModelDeploymentMonitoringJob_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_add_context_artifacts_and_executions_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_add_context_artifacts_and_executions_async.py new file mode 100644 index 0000000000..3d9f6ea005 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_add_context_artifacts_and_executions_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddContextArtifactsAndExecutions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_AddContextArtifactsAndExecutions_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_add_context_artifacts_and_executions(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.AddContextArtifactsAndExecutionsRequest( + context="context_value", + ) + + # Make the request + response = await client.add_context_artifacts_and_executions(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_AddContextArtifactsAndExecutions_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_add_context_artifacts_and_executions_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_add_context_artifacts_and_executions_sync.py new file mode 100644 index 0000000000..562437ffc4 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_add_context_artifacts_and_executions_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddContextArtifactsAndExecutions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_AddContextArtifactsAndExecutions_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_add_context_artifacts_and_executions(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.AddContextArtifactsAndExecutionsRequest( + context="context_value", + ) + + # Make the request + response = client.add_context_artifacts_and_executions(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_AddContextArtifactsAndExecutions_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_add_context_children_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_add_context_children_async.py new file mode 100644 index 0000000000..a143de0168 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_add_context_children_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddContextChildren +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_AddContextChildren_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_add_context_children(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.AddContextChildrenRequest( + context="context_value", + ) + + # Make the request + response = await client.add_context_children(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_AddContextChildren_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_add_context_children_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_add_context_children_sync.py new file mode 100644 index 0000000000..c2edee20bf --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_add_context_children_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddContextChildren +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_AddContextChildren_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_add_context_children(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.AddContextChildrenRequest( + context="context_value", + ) + + # Make the request + response = client.add_context_children(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_AddContextChildren_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_add_execution_events_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_add_execution_events_async.py new file mode 100644 index 0000000000..f248dc6369 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_add_execution_events_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddExecutionEvents +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_AddExecutionEvents_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_add_execution_events(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.AddExecutionEventsRequest( + execution="execution_value", + ) + + # Make the request + response = await client.add_execution_events(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_AddExecutionEvents_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_add_execution_events_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_add_execution_events_sync.py new file mode 100644 index 0000000000..51bbbb020f --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_add_execution_events_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddExecutionEvents +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_AddExecutionEvents_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_add_execution_events(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.AddExecutionEventsRequest( + execution="execution_value", + ) + + # Make the request + response = client.add_execution_events(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_AddExecutionEvents_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_create_artifact_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_create_artifact_async.py new file mode 100644 index 0000000000..64cbb8a8cd --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_create_artifact_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateArtifact +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_CreateArtifact_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_artifact(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateArtifactRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_artifact(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_CreateArtifact_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_create_artifact_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_create_artifact_sync.py new file mode 100644 index 0000000000..f7c6009dd4 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_create_artifact_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateArtifact +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_CreateArtifact_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_artifact(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateArtifactRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_artifact(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_CreateArtifact_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_create_context_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_create_context_async.py new file mode 100644 index 0000000000..b7ce1f9feb --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_create_context_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateContext +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_CreateContext_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_context(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateContextRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_context(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_CreateContext_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_create_context_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_create_context_sync.py new file mode 100644 index 0000000000..7aa6f4207c --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_create_context_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateContext +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_CreateContext_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_context(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateContextRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_context(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_CreateContext_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_create_execution_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_create_execution_async.py new file mode 100644 index 0000000000..bed6fd6988 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_create_execution_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_CreateExecution_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_execution(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateExecutionRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_execution(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_CreateExecution_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_create_execution_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_create_execution_sync.py new file mode 100644 index 0000000000..c44dd94057 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_create_execution_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_CreateExecution_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_execution(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateExecutionRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_execution(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_CreateExecution_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_create_metadata_schema_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_create_metadata_schema_async.py new file mode 100644 index 0000000000..a6ceab6351 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_create_metadata_schema_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateMetadataSchema +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_CreateMetadataSchema_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_metadata_schema(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + metadata_schema = aiplatform_v1beta1.MetadataSchema() + metadata_schema.schema = "schema_value" + + request = aiplatform_v1beta1.CreateMetadataSchemaRequest( + parent="parent_value", + metadata_schema=metadata_schema, + ) + + # Make the request + response = await client.create_metadata_schema(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_CreateMetadataSchema_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_create_metadata_schema_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_create_metadata_schema_sync.py new file mode 100644 index 0000000000..582ffa9513 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_create_metadata_schema_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateMetadataSchema +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_CreateMetadataSchema_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_metadata_schema(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + metadata_schema = aiplatform_v1beta1.MetadataSchema() + metadata_schema.schema = "schema_value" + + request = aiplatform_v1beta1.CreateMetadataSchemaRequest( + parent="parent_value", + metadata_schema=metadata_schema, + ) + + # Make the request + response = client.create_metadata_schema(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_CreateMetadataSchema_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_create_metadata_store_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_create_metadata_store_async.py new file mode 100644 index 0000000000..5aa7ec4ee4 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_create_metadata_store_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateMetadataStore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_CreateMetadataStore_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_metadata_store(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateMetadataStoreRequest( + parent="parent_value", + ) + + # Make the request + operation = client.create_metadata_store(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_CreateMetadataStore_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_create_metadata_store_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_create_metadata_store_sync.py new file mode 100644 index 0000000000..9469189ba3 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_create_metadata_store_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateMetadataStore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_CreateMetadataStore_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_metadata_store(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateMetadataStoreRequest( + parent="parent_value", + ) + + # Make the request + operation = client.create_metadata_store(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_CreateMetadataStore_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_delete_artifact_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_delete_artifact_async.py new file mode 100644 index 0000000000..127f903d9e --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_delete_artifact_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteArtifact +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_DeleteArtifact_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_artifact(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteArtifactRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_artifact(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_DeleteArtifact_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_delete_artifact_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_delete_artifact_sync.py new file mode 100644 index 0000000000..5e6ef6a279 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_delete_artifact_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteArtifact +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_DeleteArtifact_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_artifact(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteArtifactRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_artifact(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_DeleteArtifact_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_delete_context_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_delete_context_async.py new file mode 100644 index 0000000000..c05d6fe148 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_delete_context_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteContext +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_DeleteContext_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_context(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteContextRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_context(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_DeleteContext_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_delete_context_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_delete_context_sync.py new file mode 100644 index 0000000000..8d68e0e310 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_delete_context_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteContext +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_DeleteContext_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_context(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteContextRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_context(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_DeleteContext_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_delete_execution_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_delete_execution_async.py new file mode 100644 index 0000000000..468ec45eed --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_delete_execution_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_DeleteExecution_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_execution(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteExecutionRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_execution(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_DeleteExecution_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_delete_execution_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_delete_execution_sync.py new file mode 100644 index 0000000000..d0d0a201da --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_delete_execution_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_DeleteExecution_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_execution(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteExecutionRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_execution(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_DeleteExecution_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_delete_metadata_store_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_delete_metadata_store_async.py new file mode 100644 index 0000000000..08414e9312 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_delete_metadata_store_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteMetadataStore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_DeleteMetadataStore_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_metadata_store(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteMetadataStoreRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_metadata_store(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_DeleteMetadataStore_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_delete_metadata_store_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_delete_metadata_store_sync.py new file mode 100644 index 0000000000..3aa38e9029 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_delete_metadata_store_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteMetadataStore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_DeleteMetadataStore_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_metadata_store(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteMetadataStoreRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_metadata_store(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_DeleteMetadataStore_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_get_artifact_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_get_artifact_async.py new file mode 100644 index 0000000000..4923dd6f0d --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_get_artifact_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetArtifact +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_GetArtifact_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_artifact(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetArtifactRequest( + name="name_value", + ) + + # Make the request + response = await client.get_artifact(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_GetArtifact_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_get_artifact_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_get_artifact_sync.py new file mode 100644 index 0000000000..c021c7ef84 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_get_artifact_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetArtifact +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_GetArtifact_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_artifact(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetArtifactRequest( + name="name_value", + ) + + # Make the request + response = client.get_artifact(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_GetArtifact_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_get_context_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_get_context_async.py new file mode 100644 index 0000000000..8e09fd86b8 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_get_context_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetContext +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_GetContext_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_context(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetContextRequest( + name="name_value", + ) + + # Make the request + response = await client.get_context(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_GetContext_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_get_context_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_get_context_sync.py new file mode 100644 index 0000000000..59eee30ad5 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_get_context_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetContext +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_GetContext_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_context(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetContextRequest( + name="name_value", + ) + + # Make the request + response = client.get_context(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_GetContext_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_get_execution_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_get_execution_async.py new file mode 100644 index 0000000000..faf0607d94 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_get_execution_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_GetExecution_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_execution(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetExecutionRequest( + name="name_value", + ) + + # Make the request + response = await client.get_execution(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_GetExecution_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_get_execution_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_get_execution_sync.py new file mode 100644 index 0000000000..3b235ebbf4 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_get_execution_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_GetExecution_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_execution(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetExecutionRequest( + name="name_value", + ) + + # Make the request + response = client.get_execution(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_GetExecution_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_get_metadata_schema_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_get_metadata_schema_async.py new file mode 100644 index 0000000000..1f51b8c23c --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_get_metadata_schema_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetMetadataSchema +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_GetMetadataSchema_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_metadata_schema(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetMetadataSchemaRequest( + name="name_value", + ) + + # Make the request + response = await client.get_metadata_schema(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_GetMetadataSchema_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_get_metadata_schema_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_get_metadata_schema_sync.py new file mode 100644 index 0000000000..4a9996172b --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_get_metadata_schema_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetMetadataSchema +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_GetMetadataSchema_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_metadata_schema(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetMetadataSchemaRequest( + name="name_value", + ) + + # Make the request + response = client.get_metadata_schema(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_GetMetadataSchema_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_get_metadata_store_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_get_metadata_store_async.py new file mode 100644 index 0000000000..df7987842a --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_get_metadata_store_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetMetadataStore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_GetMetadataStore_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_metadata_store(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetMetadataStoreRequest( + name="name_value", + ) + + # Make the request + response = await client.get_metadata_store(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_GetMetadataStore_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_get_metadata_store_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_get_metadata_store_sync.py new file mode 100644 index 0000000000..9e3cbd2df1 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_get_metadata_store_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetMetadataStore +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_GetMetadataStore_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_metadata_store(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetMetadataStoreRequest( + name="name_value", + ) + + # Make the request + response = client.get_metadata_store(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_GetMetadataStore_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_list_artifacts_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_list_artifacts_async.py new file mode 100644 index 0000000000..3f4791abb6 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_list_artifacts_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListArtifacts +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_ListArtifacts_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_artifacts(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListArtifactsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_artifacts(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_ListArtifacts_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_list_artifacts_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_list_artifacts_sync.py new file mode 100644 index 0000000000..b2f11fe505 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_list_artifacts_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListArtifacts +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_ListArtifacts_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_artifacts(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListArtifactsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_artifacts(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_ListArtifacts_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_list_contexts_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_list_contexts_async.py new file mode 100644 index 0000000000..62fa6a7e9c --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_list_contexts_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListContexts +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_ListContexts_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_contexts(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListContextsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_contexts(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_ListContexts_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_list_contexts_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_list_contexts_sync.py new file mode 100644 index 0000000000..0169b67705 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_list_contexts_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListContexts +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_ListContexts_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_contexts(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListContextsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_contexts(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_ListContexts_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_list_executions_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_list_executions_async.py new file mode 100644 index 0000000000..10595404a0 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_list_executions_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListExecutions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_ListExecutions_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_executions(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListExecutionsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_executions(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_ListExecutions_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_list_executions_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_list_executions_sync.py new file mode 100644 index 0000000000..fc756c40cd --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_list_executions_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListExecutions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_ListExecutions_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_executions(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListExecutionsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_executions(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_ListExecutions_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_list_metadata_schemas_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_list_metadata_schemas_async.py new file mode 100644 index 0000000000..564ba0aae0 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_list_metadata_schemas_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListMetadataSchemas +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_ListMetadataSchemas_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_metadata_schemas(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListMetadataSchemasRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_metadata_schemas(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_ListMetadataSchemas_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_list_metadata_schemas_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_list_metadata_schemas_sync.py new file mode 100644 index 0000000000..d3f897bb7c --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_list_metadata_schemas_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListMetadataSchemas +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_ListMetadataSchemas_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_metadata_schemas(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListMetadataSchemasRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_metadata_schemas(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_ListMetadataSchemas_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_list_metadata_stores_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_list_metadata_stores_async.py new file mode 100644 index 0000000000..4e39c073f0 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_list_metadata_stores_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListMetadataStores +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_ListMetadataStores_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_metadata_stores(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListMetadataStoresRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_metadata_stores(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_ListMetadataStores_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_list_metadata_stores_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_list_metadata_stores_sync.py new file mode 100644 index 0000000000..a9f88c782c --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_list_metadata_stores_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListMetadataStores +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_ListMetadataStores_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_metadata_stores(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListMetadataStoresRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_metadata_stores(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_ListMetadataStores_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_purge_artifacts_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_purge_artifacts_async.py new file mode 100644 index 0000000000..ec465a555b --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_purge_artifacts_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PurgeArtifacts +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_PurgeArtifacts_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_purge_artifacts(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.PurgeArtifactsRequest( + parent="parent_value", + filter="filter_value", + ) + + # Make the request + operation = client.purge_artifacts(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_PurgeArtifacts_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_purge_artifacts_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_purge_artifacts_sync.py new file mode 100644 index 0000000000..ff0974d79f --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_purge_artifacts_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PurgeArtifacts +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_PurgeArtifacts_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_purge_artifacts(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.PurgeArtifactsRequest( + parent="parent_value", + filter="filter_value", + ) + + # Make the request + operation = client.purge_artifacts(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_PurgeArtifacts_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_purge_contexts_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_purge_contexts_async.py new file mode 100644 index 0000000000..74444d67b0 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_purge_contexts_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PurgeContexts +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_PurgeContexts_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_purge_contexts(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.PurgeContextsRequest( + parent="parent_value", + filter="filter_value", + ) + + # Make the request + operation = client.purge_contexts(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_PurgeContexts_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_purge_contexts_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_purge_contexts_sync.py new file mode 100644 index 0000000000..dcd54aaae6 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_purge_contexts_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PurgeContexts +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_PurgeContexts_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_purge_contexts(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.PurgeContextsRequest( + parent="parent_value", + filter="filter_value", + ) + + # Make the request + operation = client.purge_contexts(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_PurgeContexts_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_purge_executions_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_purge_executions_async.py new file mode 100644 index 0000000000..8b92f6cf34 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_purge_executions_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PurgeExecutions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_PurgeExecutions_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_purge_executions(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.PurgeExecutionsRequest( + parent="parent_value", + filter="filter_value", + ) + + # Make the request + operation = client.purge_executions(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_PurgeExecutions_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_purge_executions_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_purge_executions_sync.py new file mode 100644 index 0000000000..3f02f62c57 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_purge_executions_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for PurgeExecutions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_PurgeExecutions_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_purge_executions(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.PurgeExecutionsRequest( + parent="parent_value", + filter="filter_value", + ) + + # Make the request + operation = client.purge_executions(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_PurgeExecutions_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_query_artifact_lineage_subgraph_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_query_artifact_lineage_subgraph_async.py new file mode 100644 index 0000000000..7cd3db523a --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_query_artifact_lineage_subgraph_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for QueryArtifactLineageSubgraph +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_QueryArtifactLineageSubgraph_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_query_artifact_lineage_subgraph(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.QueryArtifactLineageSubgraphRequest( + artifact="artifact_value", + ) + + # Make the request + response = await client.query_artifact_lineage_subgraph(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_QueryArtifactLineageSubgraph_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_query_artifact_lineage_subgraph_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_query_artifact_lineage_subgraph_sync.py new file mode 100644 index 0000000000..28ba2c5ce4 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_query_artifact_lineage_subgraph_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for QueryArtifactLineageSubgraph +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_QueryArtifactLineageSubgraph_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_query_artifact_lineage_subgraph(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.QueryArtifactLineageSubgraphRequest( + artifact="artifact_value", + ) + + # Make the request + response = client.query_artifact_lineage_subgraph(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_QueryArtifactLineageSubgraph_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_query_context_lineage_subgraph_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_query_context_lineage_subgraph_async.py new file mode 100644 index 0000000000..d48f893219 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_query_context_lineage_subgraph_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for QueryContextLineageSubgraph +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_QueryContextLineageSubgraph_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_query_context_lineage_subgraph(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.QueryContextLineageSubgraphRequest( + context="context_value", + ) + + # Make the request + response = await client.query_context_lineage_subgraph(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_QueryContextLineageSubgraph_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_query_context_lineage_subgraph_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_query_context_lineage_subgraph_sync.py new file mode 100644 index 0000000000..9d766eacd4 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_query_context_lineage_subgraph_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for QueryContextLineageSubgraph +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_QueryContextLineageSubgraph_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_query_context_lineage_subgraph(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.QueryContextLineageSubgraphRequest( + context="context_value", + ) + + # Make the request + response = client.query_context_lineage_subgraph(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_QueryContextLineageSubgraph_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_query_execution_inputs_and_outputs_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_query_execution_inputs_and_outputs_async.py new file mode 100644 index 0000000000..f3d8fdeb60 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_query_execution_inputs_and_outputs_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for QueryExecutionInputsAndOutputs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_QueryExecutionInputsAndOutputs_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_query_execution_inputs_and_outputs(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.QueryExecutionInputsAndOutputsRequest( + execution="execution_value", + ) + + # Make the request + response = await client.query_execution_inputs_and_outputs(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_QueryExecutionInputsAndOutputs_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_query_execution_inputs_and_outputs_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_query_execution_inputs_and_outputs_sync.py new file mode 100644 index 0000000000..370bfd96c1 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_query_execution_inputs_and_outputs_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for QueryExecutionInputsAndOutputs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_QueryExecutionInputsAndOutputs_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_query_execution_inputs_and_outputs(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.QueryExecutionInputsAndOutputsRequest( + execution="execution_value", + ) + + # Make the request + response = client.query_execution_inputs_and_outputs(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_QueryExecutionInputsAndOutputs_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_update_artifact_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_update_artifact_async.py new file mode 100644 index 0000000000..74658ab8a7 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_update_artifact_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateArtifact +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_UpdateArtifact_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_update_artifact(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateArtifactRequest( + ) + + # Make the request + response = await client.update_artifact(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_UpdateArtifact_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_update_artifact_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_update_artifact_sync.py new file mode 100644 index 0000000000..bdfac1385c --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_update_artifact_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateArtifact +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_UpdateArtifact_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_update_artifact(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateArtifactRequest( + ) + + # Make the request + response = client.update_artifact(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_UpdateArtifact_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_update_context_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_update_context_async.py new file mode 100644 index 0000000000..f75a50c148 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_update_context_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateContext +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_UpdateContext_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_update_context(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateContextRequest( + ) + + # Make the request + response = await client.update_context(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_UpdateContext_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_update_context_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_update_context_sync.py new file mode 100644 index 0000000000..c4c9c04772 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_update_context_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateContext +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_UpdateContext_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_update_context(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateContextRequest( + ) + + # Make the request + response = client.update_context(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_UpdateContext_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_update_execution_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_update_execution_async.py new file mode 100644 index 0000000000..2b3ae95e3a --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_update_execution_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_UpdateExecution_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_update_execution(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateExecutionRequest( + ) + + # Make the request + response = await client.update_execution(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_UpdateExecution_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_update_execution_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_update_execution_sync.py new file mode 100644 index 0000000000..16d9a5edfa --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_metadata_service_update_execution_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateExecution +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MetadataService_UpdateExecution_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_update_execution(): + # Create a client + client = aiplatform_v1beta1.MetadataServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateExecutionRequest( + ) + + # Make the request + response = client.update_execution(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MetadataService_UpdateExecution_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_migration_service_batch_migrate_resources_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_migration_service_batch_migrate_resources_async.py new file mode 100644 index 0000000000..f6cad564df --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_migration_service_batch_migrate_resources_async.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchMigrateResources +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MigrationService_BatchMigrateResources_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_batch_migrate_resources(): + # Create a client + client = aiplatform_v1beta1.MigrationServiceAsyncClient() + + # Initialize request argument(s) + migrate_resource_requests = aiplatform_v1beta1.MigrateResourceRequest() + migrate_resource_requests.migrate_ml_engine_model_version_config.endpoint = "endpoint_value" + migrate_resource_requests.migrate_ml_engine_model_version_config.model_version = "model_version_value" + migrate_resource_requests.migrate_ml_engine_model_version_config.model_display_name = "model_display_name_value" + + request = aiplatform_v1beta1.BatchMigrateResourcesRequest( + parent="parent_value", + migrate_resource_requests=migrate_resource_requests, + ) + + # Make the request + operation = client.batch_migrate_resources(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MigrationService_BatchMigrateResources_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_migration_service_batch_migrate_resources_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_migration_service_batch_migrate_resources_sync.py new file mode 100644 index 0000000000..bc1e2fc412 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_migration_service_batch_migrate_resources_sync.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchMigrateResources +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MigrationService_BatchMigrateResources_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_batch_migrate_resources(): + # Create a client + client = aiplatform_v1beta1.MigrationServiceClient() + + # Initialize request argument(s) + migrate_resource_requests = aiplatform_v1beta1.MigrateResourceRequest() + migrate_resource_requests.migrate_ml_engine_model_version_config.endpoint = "endpoint_value" + migrate_resource_requests.migrate_ml_engine_model_version_config.model_version = "model_version_value" + migrate_resource_requests.migrate_ml_engine_model_version_config.model_display_name = "model_display_name_value" + + request = aiplatform_v1beta1.BatchMigrateResourcesRequest( + parent="parent_value", + migrate_resource_requests=migrate_resource_requests, + ) + + # Make the request + operation = client.batch_migrate_resources(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_MigrationService_BatchMigrateResources_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_migration_service_search_migratable_resources_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_migration_service_search_migratable_resources_async.py new file mode 100644 index 0000000000..d3ac5618e0 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_migration_service_search_migratable_resources_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SearchMigratableResources +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MigrationService_SearchMigratableResources_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_search_migratable_resources(): + # Create a client + client = aiplatform_v1beta1.MigrationServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.SearchMigratableResourcesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.search_migratable_resources(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_MigrationService_SearchMigratableResources_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_migration_service_search_migratable_resources_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_migration_service_search_migratable_resources_sync.py new file mode 100644 index 0000000000..af50eb80b4 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_migration_service_search_migratable_resources_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SearchMigratableResources +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_MigrationService_SearchMigratableResources_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_search_migratable_resources(): + # Create a client + client = aiplatform_v1beta1.MigrationServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.SearchMigratableResourcesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.search_migratable_resources(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_MigrationService_SearchMigratableResources_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_model_service_batch_import_model_evaluation_slices_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_batch_import_model_evaluation_slices_async.py new file mode 100644 index 0000000000..08c8a5e0bb --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_batch_import_model_evaluation_slices_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchImportModelEvaluationSlices +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_ModelService_BatchImportModelEvaluationSlices_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_batch_import_model_evaluation_slices(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.BatchImportModelEvaluationSlicesRequest( + parent="parent_value", + ) + + # Make the request + response = await client.batch_import_model_evaluation_slices(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_ModelService_BatchImportModelEvaluationSlices_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_model_service_batch_import_model_evaluation_slices_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_batch_import_model_evaluation_slices_sync.py new file mode 100644 index 0000000000..8857892744 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_batch_import_model_evaluation_slices_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchImportModelEvaluationSlices +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_ModelService_BatchImportModelEvaluationSlices_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_batch_import_model_evaluation_slices(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.BatchImportModelEvaluationSlicesRequest( + parent="parent_value", + ) + + # Make the request + response = client.batch_import_model_evaluation_slices(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_ModelService_BatchImportModelEvaluationSlices_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_model_service_delete_model_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_delete_model_async.py new file mode 100644 index 0000000000..0ad8dd565f --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_delete_model_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_ModelService_DeleteModel_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_model(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteModelRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_model(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_ModelService_DeleteModel_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_model_service_delete_model_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_delete_model_sync.py new file mode 100644 index 0000000000..657d1a6414 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_delete_model_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_ModelService_DeleteModel_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_model(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteModelRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_model(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_ModelService_DeleteModel_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_model_service_delete_model_version_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_delete_model_version_async.py new file mode 100644 index 0000000000..540cfe1fb1 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_delete_model_version_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteModelVersion +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_ModelService_DeleteModelVersion_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_model_version(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteModelVersionRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_model_version(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_ModelService_DeleteModelVersion_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_model_service_delete_model_version_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_delete_model_version_sync.py new file mode 100644 index 0000000000..d8ee80ef9d --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_delete_model_version_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteModelVersion +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_ModelService_DeleteModelVersion_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_model_version(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteModelVersionRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_model_version(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_ModelService_DeleteModelVersion_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_model_service_export_model_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_export_model_async.py new file mode 100644 index 0000000000..f3b7465316 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_export_model_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_ModelService_ExportModel_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_export_model(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ExportModelRequest( + name="name_value", + ) + + # Make the request + operation = client.export_model(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_ModelService_ExportModel_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_model_service_export_model_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_export_model_sync.py new file mode 100644 index 0000000000..f6dc889c0c --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_export_model_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_ModelService_ExportModel_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_export_model(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ExportModelRequest( + name="name_value", + ) + + # Make the request + operation = client.export_model(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_ModelService_ExportModel_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_model_service_get_model_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_get_model_async.py new file mode 100644 index 0000000000..f1b8db001b --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_get_model_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_ModelService_GetModel_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_model(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetModelRequest( + name="name_value", + ) + + # Make the request + response = await client.get_model(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_ModelService_GetModel_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_model_service_get_model_evaluation_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_get_model_evaluation_async.py new file mode 100644 index 0000000000..0bdef4d038 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_get_model_evaluation_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetModelEvaluation +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_ModelService_GetModelEvaluation_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_model_evaluation(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetModelEvaluationRequest( + name="name_value", + ) + + # Make the request + response = await client.get_model_evaluation(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_ModelService_GetModelEvaluation_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_model_service_get_model_evaluation_slice_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_get_model_evaluation_slice_async.py new file mode 100644 index 0000000000..007c432ac0 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_get_model_evaluation_slice_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetModelEvaluationSlice +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_ModelService_GetModelEvaluationSlice_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_model_evaluation_slice(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetModelEvaluationSliceRequest( + name="name_value", + ) + + # Make the request + response = await client.get_model_evaluation_slice(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_ModelService_GetModelEvaluationSlice_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_model_service_get_model_evaluation_slice_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_get_model_evaluation_slice_sync.py new file mode 100644 index 0000000000..5f0f61ad82 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_get_model_evaluation_slice_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetModelEvaluationSlice +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_ModelService_GetModelEvaluationSlice_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_model_evaluation_slice(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetModelEvaluationSliceRequest( + name="name_value", + ) + + # Make the request + response = client.get_model_evaluation_slice(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_ModelService_GetModelEvaluationSlice_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_model_service_get_model_evaluation_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_get_model_evaluation_sync.py new file mode 100644 index 0000000000..9accf1c4c0 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_get_model_evaluation_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetModelEvaluation +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_ModelService_GetModelEvaluation_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_model_evaluation(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetModelEvaluationRequest( + name="name_value", + ) + + # Make the request + response = client.get_model_evaluation(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_ModelService_GetModelEvaluation_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_model_service_get_model_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_get_model_sync.py new file mode 100644 index 0000000000..fe080717ba --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_get_model_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_ModelService_GetModel_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_model(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetModelRequest( + name="name_value", + ) + + # Make the request + response = client.get_model(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_ModelService_GetModel_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_model_service_import_model_evaluation_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_import_model_evaluation_async.py new file mode 100644 index 0000000000..67a59cf5e5 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_import_model_evaluation_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ImportModelEvaluation +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_ModelService_ImportModelEvaluation_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_import_model_evaluation(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ImportModelEvaluationRequest( + parent="parent_value", + ) + + # Make the request + response = await client.import_model_evaluation(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_ModelService_ImportModelEvaluation_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_model_service_import_model_evaluation_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_import_model_evaluation_sync.py new file mode 100644 index 0000000000..bb92dfdaea --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_import_model_evaluation_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ImportModelEvaluation +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_ModelService_ImportModelEvaluation_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_import_model_evaluation(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ImportModelEvaluationRequest( + parent="parent_value", + ) + + # Make the request + response = client.import_model_evaluation(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_ModelService_ImportModelEvaluation_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_model_service_list_model_evaluation_slices_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_list_model_evaluation_slices_async.py new file mode 100644 index 0000000000..b0f086c918 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_list_model_evaluation_slices_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListModelEvaluationSlices +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_ModelService_ListModelEvaluationSlices_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_model_evaluation_slices(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListModelEvaluationSlicesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_model_evaluation_slices(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_ModelService_ListModelEvaluationSlices_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_model_service_list_model_evaluation_slices_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_list_model_evaluation_slices_sync.py new file mode 100644 index 0000000000..3d858362a7 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_list_model_evaluation_slices_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListModelEvaluationSlices +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_ModelService_ListModelEvaluationSlices_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_model_evaluation_slices(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListModelEvaluationSlicesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_model_evaluation_slices(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_ModelService_ListModelEvaluationSlices_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_model_service_list_model_evaluations_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_list_model_evaluations_async.py new file mode 100644 index 0000000000..4c2d6ce419 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_list_model_evaluations_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListModelEvaluations +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_ModelService_ListModelEvaluations_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_model_evaluations(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListModelEvaluationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_model_evaluations(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_ModelService_ListModelEvaluations_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_model_service_list_model_evaluations_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_list_model_evaluations_sync.py new file mode 100644 index 0000000000..d5b3ac952c --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_list_model_evaluations_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListModelEvaluations +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_ModelService_ListModelEvaluations_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_model_evaluations(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListModelEvaluationsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_model_evaluations(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_ModelService_ListModelEvaluations_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_model_service_list_model_versions_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_list_model_versions_async.py new file mode 100644 index 0000000000..a5b5a951a3 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_list_model_versions_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListModelVersions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_ModelService_ListModelVersions_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_model_versions(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListModelVersionsRequest( + name="name_value", + ) + + # Make the request + page_result = client.list_model_versions(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_ModelService_ListModelVersions_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_model_service_list_model_versions_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_list_model_versions_sync.py new file mode 100644 index 0000000000..d717dd002d --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_list_model_versions_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListModelVersions +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_ModelService_ListModelVersions_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_model_versions(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListModelVersionsRequest( + name="name_value", + ) + + # Make the request + page_result = client.list_model_versions(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_ModelService_ListModelVersions_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_model_service_list_models_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_list_models_async.py new file mode 100644 index 0000000000..aa7d4f8ba2 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_list_models_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListModels +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_ModelService_ListModels_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_models(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListModelsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_models(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_ModelService_ListModels_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_model_service_list_models_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_list_models_sync.py new file mode 100644 index 0000000000..c5e2be1d4f --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_list_models_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListModels +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_ModelService_ListModels_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_models(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListModelsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_models(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_ModelService_ListModels_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_model_service_merge_version_aliases_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_merge_version_aliases_async.py new file mode 100644 index 0000000000..517425df71 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_merge_version_aliases_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for MergeVersionAliases +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_ModelService_MergeVersionAliases_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_merge_version_aliases(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.MergeVersionAliasesRequest( + name="name_value", + version_aliases=['version_aliases_value_1', 'version_aliases_value_2'], + ) + + # Make the request + response = await client.merge_version_aliases(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_ModelService_MergeVersionAliases_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_model_service_merge_version_aliases_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_merge_version_aliases_sync.py new file mode 100644 index 0000000000..fe8cb60202 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_merge_version_aliases_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for MergeVersionAliases +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_ModelService_MergeVersionAliases_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_merge_version_aliases(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.MergeVersionAliasesRequest( + name="name_value", + version_aliases=['version_aliases_value_1', 'version_aliases_value_2'], + ) + + # Make the request + response = client.merge_version_aliases(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_ModelService_MergeVersionAliases_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_model_service_update_explanation_dataset_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_update_explanation_dataset_async.py new file mode 100644 index 0000000000..cc070a4f30 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_update_explanation_dataset_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateExplanationDataset +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_ModelService_UpdateExplanationDataset_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_update_explanation_dataset(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateExplanationDatasetRequest( + model="model_value", + ) + + # Make the request + operation = client.update_explanation_dataset(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_ModelService_UpdateExplanationDataset_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_model_service_update_explanation_dataset_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_update_explanation_dataset_sync.py new file mode 100644 index 0000000000..3f17d7ca8d --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_update_explanation_dataset_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateExplanationDataset +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_ModelService_UpdateExplanationDataset_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_update_explanation_dataset(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateExplanationDatasetRequest( + model="model_value", + ) + + # Make the request + operation = client.update_explanation_dataset(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_ModelService_UpdateExplanationDataset_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_model_service_update_model_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_update_model_async.py new file mode 100644 index 0000000000..9a7bf7df62 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_update_model_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_ModelService_UpdateModel_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_update_model(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + model = aiplatform_v1beta1.Model() + model.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateModelRequest( + model=model, + ) + + # Make the request + response = await client.update_model(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_ModelService_UpdateModel_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_model_service_update_model_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_update_model_sync.py new file mode 100644 index 0000000000..e0ed3b7a65 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_update_model_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_ModelService_UpdateModel_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_update_model(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + model = aiplatform_v1beta1.Model() + model.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateModelRequest( + model=model, + ) + + # Make the request + response = client.update_model(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_ModelService_UpdateModel_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_model_service_upload_model_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_upload_model_async.py new file mode 100644 index 0000000000..b05244b467 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_upload_model_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UploadModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_ModelService_UploadModel_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_upload_model(): + # Create a client + client = aiplatform_v1beta1.ModelServiceAsyncClient() + + # Initialize request argument(s) + model = aiplatform_v1beta1.Model() + model.display_name = "display_name_value" + + request = aiplatform_v1beta1.UploadModelRequest( + parent="parent_value", + model=model, + ) + + # Make the request + operation = client.upload_model(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_ModelService_UploadModel_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_model_service_upload_model_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_upload_model_sync.py new file mode 100644 index 0000000000..df7f1b66da --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_model_service_upload_model_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UploadModel +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_ModelService_UploadModel_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_upload_model(): + # Create a client + client = aiplatform_v1beta1.ModelServiceClient() + + # Initialize request argument(s) + model = aiplatform_v1beta1.Model() + model.display_name = "display_name_value" + + request = aiplatform_v1beta1.UploadModelRequest( + parent="parent_value", + model=model, + ) + + # Make the request + operation = client.upload_model(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_ModelService_UploadModel_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_cancel_pipeline_job_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_cancel_pipeline_job_async.py new file mode 100644 index 0000000000..1ae9453393 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_cancel_pipeline_job_async.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelPipelineJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_PipelineService_CancelPipelineJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_cancel_pipeline_job(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CancelPipelineJobRequest( + name="name_value", + ) + + # Make the request + await client.cancel_pipeline_job(request=request) + + +# [END aiplatform_v1beta1_generated_PipelineService_CancelPipelineJob_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_cancel_pipeline_job_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_cancel_pipeline_job_sync.py new file mode 100644 index 0000000000..a48304dd4b --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_cancel_pipeline_job_sync.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelPipelineJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_PipelineService_CancelPipelineJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_cancel_pipeline_job(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CancelPipelineJobRequest( + name="name_value", + ) + + # Make the request + client.cancel_pipeline_job(request=request) + + +# [END aiplatform_v1beta1_generated_PipelineService_CancelPipelineJob_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_cancel_training_pipeline_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_cancel_training_pipeline_async.py new file mode 100644 index 0000000000..818bbf5fbf --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_cancel_training_pipeline_async.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelTrainingPipeline +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_PipelineService_CancelTrainingPipeline_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_cancel_training_pipeline(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CancelTrainingPipelineRequest( + name="name_value", + ) + + # Make the request + await client.cancel_training_pipeline(request=request) + + +# [END aiplatform_v1beta1_generated_PipelineService_CancelTrainingPipeline_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_cancel_training_pipeline_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_cancel_training_pipeline_sync.py new file mode 100644 index 0000000000..24a6fc3e58 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_cancel_training_pipeline_sync.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CancelTrainingPipeline +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_PipelineService_CancelTrainingPipeline_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_cancel_training_pipeline(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CancelTrainingPipelineRequest( + name="name_value", + ) + + # Make the request + client.cancel_training_pipeline(request=request) + + +# [END aiplatform_v1beta1_generated_PipelineService_CancelTrainingPipeline_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_create_pipeline_job_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_create_pipeline_job_async.py new file mode 100644 index 0000000000..c6eb72f73a --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_create_pipeline_job_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreatePipelineJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_PipelineService_CreatePipelineJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_pipeline_job(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreatePipelineJobRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_pipeline_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_PipelineService_CreatePipelineJob_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_create_pipeline_job_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_create_pipeline_job_sync.py new file mode 100644 index 0000000000..ee76472f93 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_create_pipeline_job_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreatePipelineJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_PipelineService_CreatePipelineJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_pipeline_job(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreatePipelineJobRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_pipeline_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_PipelineService_CreatePipelineJob_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_create_training_pipeline_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_create_training_pipeline_async.py new file mode 100644 index 0000000000..d7ce61f6ea --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_create_training_pipeline_async.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTrainingPipeline +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_PipelineService_CreateTrainingPipeline_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_training_pipeline(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + training_pipeline = aiplatform_v1beta1.TrainingPipeline() + training_pipeline.display_name = "display_name_value" + training_pipeline.training_task_definition = "training_task_definition_value" + training_pipeline.training_task_inputs.null_value = "NULL_VALUE" + + request = aiplatform_v1beta1.CreateTrainingPipelineRequest( + parent="parent_value", + training_pipeline=training_pipeline, + ) + + # Make the request + response = await client.create_training_pipeline(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_PipelineService_CreateTrainingPipeline_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_create_training_pipeline_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_create_training_pipeline_sync.py new file mode 100644 index 0000000000..fecf6cf314 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_create_training_pipeline_sync.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTrainingPipeline +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_PipelineService_CreateTrainingPipeline_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_training_pipeline(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceClient() + + # Initialize request argument(s) + training_pipeline = aiplatform_v1beta1.TrainingPipeline() + training_pipeline.display_name = "display_name_value" + training_pipeline.training_task_definition = "training_task_definition_value" + training_pipeline.training_task_inputs.null_value = "NULL_VALUE" + + request = aiplatform_v1beta1.CreateTrainingPipelineRequest( + parent="parent_value", + training_pipeline=training_pipeline, + ) + + # Make the request + response = client.create_training_pipeline(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_PipelineService_CreateTrainingPipeline_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_delete_pipeline_job_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_delete_pipeline_job_async.py new file mode 100644 index 0000000000..64aafe1369 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_delete_pipeline_job_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeletePipelineJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_PipelineService_DeletePipelineJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_pipeline_job(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeletePipelineJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_pipeline_job(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_PipelineService_DeletePipelineJob_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_delete_pipeline_job_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_delete_pipeline_job_sync.py new file mode 100644 index 0000000000..fc8b5ea2fa --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_delete_pipeline_job_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeletePipelineJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_PipelineService_DeletePipelineJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_pipeline_job(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeletePipelineJobRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_pipeline_job(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_PipelineService_DeletePipelineJob_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_delete_training_pipeline_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_delete_training_pipeline_async.py new file mode 100644 index 0000000000..097638e8e9 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_delete_training_pipeline_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTrainingPipeline +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_PipelineService_DeleteTrainingPipeline_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_training_pipeline(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteTrainingPipelineRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_training_pipeline(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_PipelineService_DeleteTrainingPipeline_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_delete_training_pipeline_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_delete_training_pipeline_sync.py new file mode 100644 index 0000000000..1a80bf60c1 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_delete_training_pipeline_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTrainingPipeline +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_PipelineService_DeleteTrainingPipeline_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_training_pipeline(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteTrainingPipelineRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_training_pipeline(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_PipelineService_DeleteTrainingPipeline_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_get_pipeline_job_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_get_pipeline_job_async.py new file mode 100644 index 0000000000..6eba96b5d1 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_get_pipeline_job_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetPipelineJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_PipelineService_GetPipelineJob_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_pipeline_job(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetPipelineJobRequest( + name="name_value", + ) + + # Make the request + response = await client.get_pipeline_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_PipelineService_GetPipelineJob_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_get_pipeline_job_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_get_pipeline_job_sync.py new file mode 100644 index 0000000000..37984b5bf8 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_get_pipeline_job_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetPipelineJob +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_PipelineService_GetPipelineJob_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_pipeline_job(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetPipelineJobRequest( + name="name_value", + ) + + # Make the request + response = client.get_pipeline_job(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_PipelineService_GetPipelineJob_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_get_training_pipeline_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_get_training_pipeline_async.py new file mode 100644 index 0000000000..5e6de6843e --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_get_training_pipeline_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTrainingPipeline +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_PipelineService_GetTrainingPipeline_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_training_pipeline(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetTrainingPipelineRequest( + name="name_value", + ) + + # Make the request + response = await client.get_training_pipeline(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_PipelineService_GetTrainingPipeline_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_get_training_pipeline_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_get_training_pipeline_sync.py new file mode 100644 index 0000000000..ba5edd03ad --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_get_training_pipeline_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTrainingPipeline +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_PipelineService_GetTrainingPipeline_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_training_pipeline(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetTrainingPipelineRequest( + name="name_value", + ) + + # Make the request + response = client.get_training_pipeline(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_PipelineService_GetTrainingPipeline_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_list_pipeline_jobs_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_list_pipeline_jobs_async.py new file mode 100644 index 0000000000..8318dc13d8 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_list_pipeline_jobs_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListPipelineJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_PipelineService_ListPipelineJobs_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_pipeline_jobs(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListPipelineJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_pipeline_jobs(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_PipelineService_ListPipelineJobs_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_list_pipeline_jobs_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_list_pipeline_jobs_sync.py new file mode 100644 index 0000000000..ec679372b3 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_list_pipeline_jobs_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListPipelineJobs +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_PipelineService_ListPipelineJobs_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_pipeline_jobs(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListPipelineJobsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_pipeline_jobs(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_PipelineService_ListPipelineJobs_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_list_training_pipelines_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_list_training_pipelines_async.py new file mode 100644 index 0000000000..b0a84fb3a3 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_list_training_pipelines_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTrainingPipelines +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_PipelineService_ListTrainingPipelines_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_training_pipelines(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListTrainingPipelinesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_training_pipelines(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_PipelineService_ListTrainingPipelines_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_list_training_pipelines_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_list_training_pipelines_sync.py new file mode 100644 index 0000000000..f69b7c0ca4 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_pipeline_service_list_training_pipelines_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTrainingPipelines +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_PipelineService_ListTrainingPipelines_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_training_pipelines(): + # Create a client + client = aiplatform_v1beta1.PipelineServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListTrainingPipelinesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_training_pipelines(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_PipelineService_ListTrainingPipelines_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_prediction_service_explain_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_prediction_service_explain_async.py new file mode 100644 index 0000000000..1abbae40a1 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_prediction_service_explain_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for Explain +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_PredictionService_Explain_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_explain(): + # Create a client + client = aiplatform_v1beta1.PredictionServiceAsyncClient() + + # Initialize request argument(s) + instances = aiplatform_v1beta1.Value() + instances.null_value = "NULL_VALUE" + + request = aiplatform_v1beta1.ExplainRequest( + endpoint="endpoint_value", + instances=instances, + ) + + # Make the request + response = await client.explain(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_PredictionService_Explain_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_prediction_service_explain_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_prediction_service_explain_sync.py new file mode 100644 index 0000000000..aa821d19d4 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_prediction_service_explain_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for Explain +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_PredictionService_Explain_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_explain(): + # Create a client + client = aiplatform_v1beta1.PredictionServiceClient() + + # Initialize request argument(s) + instances = aiplatform_v1beta1.Value() + instances.null_value = "NULL_VALUE" + + request = aiplatform_v1beta1.ExplainRequest( + endpoint="endpoint_value", + instances=instances, + ) + + # Make the request + response = client.explain(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_PredictionService_Explain_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_prediction_service_predict_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_prediction_service_predict_async.py new file mode 100644 index 0000000000..38da7d92c4 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_prediction_service_predict_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for Predict +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_PredictionService_Predict_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_predict(): + # Create a client + client = aiplatform_v1beta1.PredictionServiceAsyncClient() + + # Initialize request argument(s) + instances = aiplatform_v1beta1.Value() + instances.null_value = "NULL_VALUE" + + request = aiplatform_v1beta1.PredictRequest( + endpoint="endpoint_value", + instances=instances, + ) + + # Make the request + response = await client.predict(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_PredictionService_Predict_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_prediction_service_predict_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_prediction_service_predict_sync.py new file mode 100644 index 0000000000..8e0a96f195 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_prediction_service_predict_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for Predict +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_PredictionService_Predict_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_predict(): + # Create a client + client = aiplatform_v1beta1.PredictionServiceClient() + + # Initialize request argument(s) + instances = aiplatform_v1beta1.Value() + instances.null_value = "NULL_VALUE" + + request = aiplatform_v1beta1.PredictRequest( + endpoint="endpoint_value", + instances=instances, + ) + + # Make the request + response = client.predict(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_PredictionService_Predict_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_prediction_service_raw_predict_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_prediction_service_raw_predict_async.py new file mode 100644 index 0000000000..b347682562 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_prediction_service_raw_predict_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for RawPredict +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_PredictionService_RawPredict_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_raw_predict(): + # Create a client + client = aiplatform_v1beta1.PredictionServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.RawPredictRequest( + endpoint="endpoint_value", + ) + + # Make the request + response = await client.raw_predict(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_PredictionService_RawPredict_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_prediction_service_raw_predict_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_prediction_service_raw_predict_sync.py new file mode 100644 index 0000000000..20c7286fa0 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_prediction_service_raw_predict_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for RawPredict +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_PredictionService_RawPredict_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_raw_predict(): + # Create a client + client = aiplatform_v1beta1.PredictionServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.RawPredictRequest( + endpoint="endpoint_value", + ) + + # Make the request + response = client.raw_predict(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_PredictionService_RawPredict_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_specialist_pool_service_create_specialist_pool_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_specialist_pool_service_create_specialist_pool_async.py new file mode 100644 index 0000000000..4110e3a04f --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_specialist_pool_service_create_specialist_pool_async.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateSpecialistPool +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_SpecialistPoolService_CreateSpecialistPool_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_specialist_pool(): + # Create a client + client = aiplatform_v1beta1.SpecialistPoolServiceAsyncClient() + + # Initialize request argument(s) + specialist_pool = aiplatform_v1beta1.SpecialistPool() + specialist_pool.name = "name_value" + specialist_pool.display_name = "display_name_value" + + request = aiplatform_v1beta1.CreateSpecialistPoolRequest( + parent="parent_value", + specialist_pool=specialist_pool, + ) + + # Make the request + operation = client.create_specialist_pool(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_SpecialistPoolService_CreateSpecialistPool_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_specialist_pool_service_create_specialist_pool_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_specialist_pool_service_create_specialist_pool_sync.py new file mode 100644 index 0000000000..1569cc2f2a --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_specialist_pool_service_create_specialist_pool_sync.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateSpecialistPool +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_SpecialistPoolService_CreateSpecialistPool_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_specialist_pool(): + # Create a client + client = aiplatform_v1beta1.SpecialistPoolServiceClient() + + # Initialize request argument(s) + specialist_pool = aiplatform_v1beta1.SpecialistPool() + specialist_pool.name = "name_value" + specialist_pool.display_name = "display_name_value" + + request = aiplatform_v1beta1.CreateSpecialistPoolRequest( + parent="parent_value", + specialist_pool=specialist_pool, + ) + + # Make the request + operation = client.create_specialist_pool(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_SpecialistPoolService_CreateSpecialistPool_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_specialist_pool_service_delete_specialist_pool_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_specialist_pool_service_delete_specialist_pool_async.py new file mode 100644 index 0000000000..6743cf3a70 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_specialist_pool_service_delete_specialist_pool_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteSpecialistPool +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_SpecialistPoolService_DeleteSpecialistPool_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_specialist_pool(): + # Create a client + client = aiplatform_v1beta1.SpecialistPoolServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteSpecialistPoolRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_specialist_pool(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_SpecialistPoolService_DeleteSpecialistPool_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_specialist_pool_service_delete_specialist_pool_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_specialist_pool_service_delete_specialist_pool_sync.py new file mode 100644 index 0000000000..5e02eafb73 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_specialist_pool_service_delete_specialist_pool_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteSpecialistPool +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_SpecialistPoolService_DeleteSpecialistPool_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_specialist_pool(): + # Create a client + client = aiplatform_v1beta1.SpecialistPoolServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteSpecialistPoolRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_specialist_pool(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_SpecialistPoolService_DeleteSpecialistPool_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_specialist_pool_service_get_specialist_pool_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_specialist_pool_service_get_specialist_pool_async.py new file mode 100644 index 0000000000..a36e2e76aa --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_specialist_pool_service_get_specialist_pool_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetSpecialistPool +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_SpecialistPoolService_GetSpecialistPool_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_specialist_pool(): + # Create a client + client = aiplatform_v1beta1.SpecialistPoolServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetSpecialistPoolRequest( + name="name_value", + ) + + # Make the request + response = await client.get_specialist_pool(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_SpecialistPoolService_GetSpecialistPool_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_specialist_pool_service_get_specialist_pool_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_specialist_pool_service_get_specialist_pool_sync.py new file mode 100644 index 0000000000..360e6e7423 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_specialist_pool_service_get_specialist_pool_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetSpecialistPool +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_SpecialistPoolService_GetSpecialistPool_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_specialist_pool(): + # Create a client + client = aiplatform_v1beta1.SpecialistPoolServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetSpecialistPoolRequest( + name="name_value", + ) + + # Make the request + response = client.get_specialist_pool(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_SpecialistPoolService_GetSpecialistPool_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_specialist_pool_service_list_specialist_pools_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_specialist_pool_service_list_specialist_pools_async.py new file mode 100644 index 0000000000..d35fe10b3f --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_specialist_pool_service_list_specialist_pools_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListSpecialistPools +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_SpecialistPoolService_ListSpecialistPools_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_specialist_pools(): + # Create a client + client = aiplatform_v1beta1.SpecialistPoolServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListSpecialistPoolsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_specialist_pools(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_SpecialistPoolService_ListSpecialistPools_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_specialist_pool_service_list_specialist_pools_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_specialist_pool_service_list_specialist_pools_sync.py new file mode 100644 index 0000000000..31270e3d7f --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_specialist_pool_service_list_specialist_pools_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListSpecialistPools +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_SpecialistPoolService_ListSpecialistPools_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_specialist_pools(): + # Create a client + client = aiplatform_v1beta1.SpecialistPoolServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListSpecialistPoolsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_specialist_pools(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_SpecialistPoolService_ListSpecialistPools_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_specialist_pool_service_update_specialist_pool_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_specialist_pool_service_update_specialist_pool_async.py new file mode 100644 index 0000000000..fa0d8cd115 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_specialist_pool_service_update_specialist_pool_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateSpecialistPool +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_SpecialistPoolService_UpdateSpecialistPool_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_update_specialist_pool(): + # Create a client + client = aiplatform_v1beta1.SpecialistPoolServiceAsyncClient() + + # Initialize request argument(s) + specialist_pool = aiplatform_v1beta1.SpecialistPool() + specialist_pool.name = "name_value" + specialist_pool.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateSpecialistPoolRequest( + specialist_pool=specialist_pool, + ) + + # Make the request + operation = client.update_specialist_pool(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_SpecialistPoolService_UpdateSpecialistPool_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_specialist_pool_service_update_specialist_pool_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_specialist_pool_service_update_specialist_pool_sync.py new file mode 100644 index 0000000000..9e314cdd0a --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_specialist_pool_service_update_specialist_pool_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateSpecialistPool +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_SpecialistPoolService_UpdateSpecialistPool_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_update_specialist_pool(): + # Create a client + client = aiplatform_v1beta1.SpecialistPoolServiceClient() + + # Initialize request argument(s) + specialist_pool = aiplatform_v1beta1.SpecialistPool() + specialist_pool.name = "name_value" + specialist_pool.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateSpecialistPoolRequest( + specialist_pool=specialist_pool, + ) + + # Make the request + operation = client.update_specialist_pool(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_SpecialistPoolService_UpdateSpecialistPool_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_batch_create_tensorboard_runs_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_batch_create_tensorboard_runs_async.py new file mode 100644 index 0000000000..5937240bab --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_batch_create_tensorboard_runs_async.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchCreateTensorboardRuns +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_BatchCreateTensorboardRuns_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_batch_create_tensorboard_runs(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + requests = aiplatform_v1beta1.CreateTensorboardRunRequest() + requests.parent = "parent_value" + requests.tensorboard_run.display_name = "display_name_value" + requests.tensorboard_run_id = "tensorboard_run_id_value" + + request = aiplatform_v1beta1.BatchCreateTensorboardRunsRequest( + parent="parent_value", + requests=requests, + ) + + # Make the request + response = await client.batch_create_tensorboard_runs(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_BatchCreateTensorboardRuns_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_batch_create_tensorboard_runs_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_batch_create_tensorboard_runs_sync.py new file mode 100644 index 0000000000..a829aa595f --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_batch_create_tensorboard_runs_sync.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchCreateTensorboardRuns +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_BatchCreateTensorboardRuns_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_batch_create_tensorboard_runs(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + requests = aiplatform_v1beta1.CreateTensorboardRunRequest() + requests.parent = "parent_value" + requests.tensorboard_run.display_name = "display_name_value" + requests.tensorboard_run_id = "tensorboard_run_id_value" + + request = aiplatform_v1beta1.BatchCreateTensorboardRunsRequest( + parent="parent_value", + requests=requests, + ) + + # Make the request + response = client.batch_create_tensorboard_runs(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_BatchCreateTensorboardRuns_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_batch_create_tensorboard_time_series_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_batch_create_tensorboard_time_series_async.py new file mode 100644 index 0000000000..409e42451c --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_batch_create_tensorboard_time_series_async.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchCreateTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_BatchCreateTensorboardTimeSeries_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_batch_create_tensorboard_time_series(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + requests = aiplatform_v1beta1.CreateTensorboardTimeSeriesRequest() + requests.parent = "parent_value" + requests.tensorboard_time_series.display_name = "display_name_value" + requests.tensorboard_time_series.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1beta1.BatchCreateTensorboardTimeSeriesRequest( + parent="parent_value", + requests=requests, + ) + + # Make the request + response = await client.batch_create_tensorboard_time_series(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_BatchCreateTensorboardTimeSeries_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_batch_create_tensorboard_time_series_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_batch_create_tensorboard_time_series_sync.py new file mode 100644 index 0000000000..4d6dff304c --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_batch_create_tensorboard_time_series_sync.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchCreateTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_BatchCreateTensorboardTimeSeries_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_batch_create_tensorboard_time_series(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + requests = aiplatform_v1beta1.CreateTensorboardTimeSeriesRequest() + requests.parent = "parent_value" + requests.tensorboard_time_series.display_name = "display_name_value" + requests.tensorboard_time_series.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1beta1.BatchCreateTensorboardTimeSeriesRequest( + parent="parent_value", + requests=requests, + ) + + # Make the request + response = client.batch_create_tensorboard_time_series(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_BatchCreateTensorboardTimeSeries_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_batch_read_tensorboard_time_series_data_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_batch_read_tensorboard_time_series_data_async.py new file mode 100644 index 0000000000..07ee0f2040 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_batch_read_tensorboard_time_series_data_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchReadTensorboardTimeSeriesData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_BatchReadTensorboardTimeSeriesData_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_batch_read_tensorboard_time_series_data(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.BatchReadTensorboardTimeSeriesDataRequest( + tensorboard="tensorboard_value", + time_series=['time_series_value_1', 'time_series_value_2'], + ) + + # Make the request + response = await client.batch_read_tensorboard_time_series_data(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_BatchReadTensorboardTimeSeriesData_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_batch_read_tensorboard_time_series_data_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_batch_read_tensorboard_time_series_data_sync.py new file mode 100644 index 0000000000..c14bbb21d9 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_batch_read_tensorboard_time_series_data_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for BatchReadTensorboardTimeSeriesData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_BatchReadTensorboardTimeSeriesData_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_batch_read_tensorboard_time_series_data(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.BatchReadTensorboardTimeSeriesDataRequest( + tensorboard="tensorboard_value", + time_series=['time_series_value_1', 'time_series_value_2'], + ) + + # Make the request + response = client.batch_read_tensorboard_time_series_data(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_BatchReadTensorboardTimeSeriesData_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_async.py new file mode 100644 index 0000000000..27ffff4cf4 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_async.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTensorboard +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_CreateTensorboard_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_tensorboard(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + tensorboard = aiplatform_v1beta1.Tensorboard() + tensorboard.display_name = "display_name_value" + + request = aiplatform_v1beta1.CreateTensorboardRequest( + parent="parent_value", + tensorboard=tensorboard, + ) + + # Make the request + operation = client.create_tensorboard(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_CreateTensorboard_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_experiment_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_experiment_async.py new file mode 100644 index 0000000000..a3ee2e22d4 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_experiment_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTensorboardExperiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_CreateTensorboardExperiment_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_tensorboard_experiment(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateTensorboardExperimentRequest( + parent="parent_value", + tensorboard_experiment_id="tensorboard_experiment_id_value", + ) + + # Make the request + response = await client.create_tensorboard_experiment(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_CreateTensorboardExperiment_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_experiment_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_experiment_sync.py new file mode 100644 index 0000000000..86b25f8d5a --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_experiment_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTensorboardExperiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_CreateTensorboardExperiment_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_tensorboard_experiment(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateTensorboardExperimentRequest( + parent="parent_value", + tensorboard_experiment_id="tensorboard_experiment_id_value", + ) + + # Make the request + response = client.create_tensorboard_experiment(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_CreateTensorboardExperiment_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_run_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_run_async.py new file mode 100644 index 0000000000..4cf5a16922 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_run_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTensorboardRun +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_CreateTensorboardRun_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_tensorboard_run(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + tensorboard_run = aiplatform_v1beta1.TensorboardRun() + tensorboard_run.display_name = "display_name_value" + + request = aiplatform_v1beta1.CreateTensorboardRunRequest( + parent="parent_value", + tensorboard_run=tensorboard_run, + tensorboard_run_id="tensorboard_run_id_value", + ) + + # Make the request + response = await client.create_tensorboard_run(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_CreateTensorboardRun_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_run_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_run_sync.py new file mode 100644 index 0000000000..81e50e4b46 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_run_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTensorboardRun +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_CreateTensorboardRun_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_tensorboard_run(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + tensorboard_run = aiplatform_v1beta1.TensorboardRun() + tensorboard_run.display_name = "display_name_value" + + request = aiplatform_v1beta1.CreateTensorboardRunRequest( + parent="parent_value", + tensorboard_run=tensorboard_run, + tensorboard_run_id="tensorboard_run_id_value", + ) + + # Make the request + response = client.create_tensorboard_run(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_CreateTensorboardRun_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_sync.py new file mode 100644 index 0000000000..021008b4b1 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_sync.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTensorboard +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_CreateTensorboard_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_tensorboard(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + tensorboard = aiplatform_v1beta1.Tensorboard() + tensorboard.display_name = "display_name_value" + + request = aiplatform_v1beta1.CreateTensorboardRequest( + parent="parent_value", + tensorboard=tensorboard, + ) + + # Make the request + operation = client.create_tensorboard(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_CreateTensorboard_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_time_series_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_time_series_async.py new file mode 100644 index 0000000000..27ac95a98c --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_time_series_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_CreateTensorboardTimeSeries_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_tensorboard_time_series(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + tensorboard_time_series = aiplatform_v1beta1.TensorboardTimeSeries() + tensorboard_time_series.display_name = "display_name_value" + tensorboard_time_series.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1beta1.CreateTensorboardTimeSeriesRequest( + parent="parent_value", + tensorboard_time_series=tensorboard_time_series, + ) + + # Make the request + response = await client.create_tensorboard_time_series(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_CreateTensorboardTimeSeries_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_time_series_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_time_series_sync.py new file mode 100644 index 0000000000..89f205c530 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_time_series_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_CreateTensorboardTimeSeries_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_tensorboard_time_series(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + tensorboard_time_series = aiplatform_v1beta1.TensorboardTimeSeries() + tensorboard_time_series.display_name = "display_name_value" + tensorboard_time_series.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1beta1.CreateTensorboardTimeSeriesRequest( + parent="parent_value", + tensorboard_time_series=tensorboard_time_series, + ) + + # Make the request + response = client.create_tensorboard_time_series(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_CreateTensorboardTimeSeries_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_async.py new file mode 100644 index 0000000000..0fad128744 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTensorboard +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_DeleteTensorboard_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_tensorboard(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteTensorboardRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_DeleteTensorboard_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_experiment_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_experiment_async.py new file mode 100644 index 0000000000..6a00ba6551 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_experiment_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTensorboardExperiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_DeleteTensorboardExperiment_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_tensorboard_experiment(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteTensorboardExperimentRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard_experiment(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_DeleteTensorboardExperiment_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_experiment_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_experiment_sync.py new file mode 100644 index 0000000000..05bb0f8e3d --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_experiment_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTensorboardExperiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_DeleteTensorboardExperiment_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_tensorboard_experiment(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteTensorboardExperimentRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard_experiment(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_DeleteTensorboardExperiment_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_run_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_run_async.py new file mode 100644 index 0000000000..a9c126bdbf --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_run_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTensorboardRun +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_DeleteTensorboardRun_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_tensorboard_run(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteTensorboardRunRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard_run(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_DeleteTensorboardRun_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_run_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_run_sync.py new file mode 100644 index 0000000000..7de2b8038a --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_run_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTensorboardRun +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_DeleteTensorboardRun_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_tensorboard_run(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteTensorboardRunRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard_run(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_DeleteTensorboardRun_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_sync.py new file mode 100644 index 0000000000..e9181c8670 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTensorboard +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_DeleteTensorboard_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_tensorboard(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteTensorboardRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_DeleteTensorboard_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_time_series_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_time_series_async.py new file mode 100644 index 0000000000..1427937ce3 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_time_series_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_DeleteTensorboardTimeSeries_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_tensorboard_time_series(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteTensorboardTimeSeriesRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard_time_series(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_DeleteTensorboardTimeSeries_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_time_series_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_time_series_sync.py new file mode 100644 index 0000000000..97d5788320 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_time_series_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_DeleteTensorboardTimeSeries_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_tensorboard_time_series(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteTensorboardTimeSeriesRequest( + name="name_value", + ) + + # Make the request + operation = client.delete_tensorboard_time_series(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_DeleteTensorboardTimeSeries_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_export_tensorboard_time_series_data_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_export_tensorboard_time_series_data_async.py new file mode 100644 index 0000000000..9207970d60 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_export_tensorboard_time_series_data_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportTensorboardTimeSeriesData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_ExportTensorboardTimeSeriesData_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_export_tensorboard_time_series_data(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ExportTensorboardTimeSeriesDataRequest( + tensorboard_time_series="tensorboard_time_series_value", + ) + + # Make the request + page_result = client.export_tensorboard_time_series_data(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_ExportTensorboardTimeSeriesData_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_export_tensorboard_time_series_data_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_export_tensorboard_time_series_data_sync.py new file mode 100644 index 0000000000..bad73717bc --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_export_tensorboard_time_series_data_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ExportTensorboardTimeSeriesData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_ExportTensorboardTimeSeriesData_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_export_tensorboard_time_series_data(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ExportTensorboardTimeSeriesDataRequest( + tensorboard_time_series="tensorboard_time_series_value", + ) + + # Make the request + page_result = client.export_tensorboard_time_series_data(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_ExportTensorboardTimeSeriesData_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_async.py new file mode 100644 index 0000000000..76db628787 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTensorboard +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_GetTensorboard_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_tensorboard(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetTensorboardRequest( + name="name_value", + ) + + # Make the request + response = await client.get_tensorboard(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_GetTensorboard_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_experiment_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_experiment_async.py new file mode 100644 index 0000000000..59eaefa0a5 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_experiment_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTensorboardExperiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_GetTensorboardExperiment_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_tensorboard_experiment(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetTensorboardExperimentRequest( + name="name_value", + ) + + # Make the request + response = await client.get_tensorboard_experiment(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_GetTensorboardExperiment_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_experiment_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_experiment_sync.py new file mode 100644 index 0000000000..a4b0be05d6 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_experiment_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTensorboardExperiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_GetTensorboardExperiment_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_tensorboard_experiment(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetTensorboardExperimentRequest( + name="name_value", + ) + + # Make the request + response = client.get_tensorboard_experiment(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_GetTensorboardExperiment_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_run_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_run_async.py new file mode 100644 index 0000000000..3b6e6affb3 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_run_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTensorboardRun +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_GetTensorboardRun_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_tensorboard_run(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetTensorboardRunRequest( + name="name_value", + ) + + # Make the request + response = await client.get_tensorboard_run(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_GetTensorboardRun_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_run_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_run_sync.py new file mode 100644 index 0000000000..0a68e3959b --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_run_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTensorboardRun +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_GetTensorboardRun_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_tensorboard_run(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetTensorboardRunRequest( + name="name_value", + ) + + # Make the request + response = client.get_tensorboard_run(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_GetTensorboardRun_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_sync.py new file mode 100644 index 0000000000..26a5a65230 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTensorboard +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_GetTensorboard_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_tensorboard(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetTensorboardRequest( + name="name_value", + ) + + # Make the request + response = client.get_tensorboard(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_GetTensorboard_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_time_series_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_time_series_async.py new file mode 100644 index 0000000000..411c0af108 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_time_series_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_GetTensorboardTimeSeries_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_tensorboard_time_series(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetTensorboardTimeSeriesRequest( + name="name_value", + ) + + # Make the request + response = await client.get_tensorboard_time_series(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_GetTensorboardTimeSeries_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_time_series_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_time_series_sync.py new file mode 100644 index 0000000000..10c0d3f143 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_time_series_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_GetTensorboardTimeSeries_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_tensorboard_time_series(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetTensorboardTimeSeriesRequest( + name="name_value", + ) + + # Make the request + response = client.get_tensorboard_time_series(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_GetTensorboardTimeSeries_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_list_tensorboard_experiments_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_list_tensorboard_experiments_async.py new file mode 100644 index 0000000000..4373a11385 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_list_tensorboard_experiments_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTensorboardExperiments +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_ListTensorboardExperiments_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_tensorboard_experiments(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListTensorboardExperimentsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboard_experiments(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_ListTensorboardExperiments_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_list_tensorboard_experiments_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_list_tensorboard_experiments_sync.py new file mode 100644 index 0000000000..022518a974 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_list_tensorboard_experiments_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTensorboardExperiments +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_ListTensorboardExperiments_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_tensorboard_experiments(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListTensorboardExperimentsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboard_experiments(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_ListTensorboardExperiments_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_list_tensorboard_runs_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_list_tensorboard_runs_async.py new file mode 100644 index 0000000000..8c0b9f265e --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_list_tensorboard_runs_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTensorboardRuns +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_ListTensorboardRuns_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_tensorboard_runs(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListTensorboardRunsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboard_runs(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_ListTensorboardRuns_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_list_tensorboard_runs_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_list_tensorboard_runs_sync.py new file mode 100644 index 0000000000..1e3572ada3 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_list_tensorboard_runs_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTensorboardRuns +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_ListTensorboardRuns_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_tensorboard_runs(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListTensorboardRunsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboard_runs(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_ListTensorboardRuns_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_list_tensorboard_time_series_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_list_tensorboard_time_series_async.py new file mode 100644 index 0000000000..22dd43a6ce --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_list_tensorboard_time_series_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_ListTensorboardTimeSeries_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_tensorboard_time_series(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListTensorboardTimeSeriesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboard_time_series(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_ListTensorboardTimeSeries_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_list_tensorboard_time_series_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_list_tensorboard_time_series_sync.py new file mode 100644 index 0000000000..9e8deab9e0 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_list_tensorboard_time_series_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_ListTensorboardTimeSeries_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_tensorboard_time_series(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListTensorboardTimeSeriesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboard_time_series(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_ListTensorboardTimeSeries_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_list_tensorboards_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_list_tensorboards_async.py new file mode 100644 index 0000000000..3ddaf031a1 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_list_tensorboards_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTensorboards +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_ListTensorboards_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_tensorboards(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListTensorboardsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboards(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_ListTensorboards_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_list_tensorboards_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_list_tensorboards_sync.py new file mode 100644 index 0000000000..9e1ff86334 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_list_tensorboards_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTensorboards +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_ListTensorboards_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_tensorboards(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListTensorboardsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_tensorboards(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_ListTensorboards_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_read_tensorboard_blob_data_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_read_tensorboard_blob_data_async.py new file mode 100644 index 0000000000..4379e6a244 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_read_tensorboard_blob_data_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ReadTensorboardBlobData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_ReadTensorboardBlobData_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_read_tensorboard_blob_data(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ReadTensorboardBlobDataRequest( + time_series="time_series_value", + ) + + # Make the request + stream = await client.read_tensorboard_blob_data(request=request) + + # Handle the response + async for response in stream: + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_ReadTensorboardBlobData_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_read_tensorboard_blob_data_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_read_tensorboard_blob_data_sync.py new file mode 100644 index 0000000000..ba91617037 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_read_tensorboard_blob_data_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ReadTensorboardBlobData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_ReadTensorboardBlobData_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_read_tensorboard_blob_data(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ReadTensorboardBlobDataRequest( + time_series="time_series_value", + ) + + # Make the request + stream = client.read_tensorboard_blob_data(request=request) + + # Handle the response + for response in stream: + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_ReadTensorboardBlobData_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_read_tensorboard_time_series_data_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_read_tensorboard_time_series_data_async.py new file mode 100644 index 0000000000..98979860f6 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_read_tensorboard_time_series_data_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ReadTensorboardTimeSeriesData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_ReadTensorboardTimeSeriesData_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_read_tensorboard_time_series_data(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ReadTensorboardTimeSeriesDataRequest( + tensorboard_time_series="tensorboard_time_series_value", + ) + + # Make the request + response = await client.read_tensorboard_time_series_data(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_ReadTensorboardTimeSeriesData_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_read_tensorboard_time_series_data_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_read_tensorboard_time_series_data_sync.py new file mode 100644 index 0000000000..d0d932ad2f --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_read_tensorboard_time_series_data_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ReadTensorboardTimeSeriesData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_ReadTensorboardTimeSeriesData_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_read_tensorboard_time_series_data(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ReadTensorboardTimeSeriesDataRequest( + tensorboard_time_series="tensorboard_time_series_value", + ) + + # Make the request + response = client.read_tensorboard_time_series_data(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_ReadTensorboardTimeSeriesData_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_async.py new file mode 100644 index 0000000000..55d0b0fa73 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_async.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateTensorboard +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_UpdateTensorboard_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_update_tensorboard(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + tensorboard = aiplatform_v1beta1.Tensorboard() + tensorboard.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateTensorboardRequest( + tensorboard=tensorboard, + ) + + # Make the request + operation = client.update_tensorboard(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_UpdateTensorboard_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_experiment_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_experiment_async.py new file mode 100644 index 0000000000..3910a49162 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_experiment_async.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateTensorboardExperiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_UpdateTensorboardExperiment_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_update_tensorboard_experiment(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateTensorboardExperimentRequest( + ) + + # Make the request + response = await client.update_tensorboard_experiment(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_UpdateTensorboardExperiment_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_experiment_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_experiment_sync.py new file mode 100644 index 0000000000..06a9f08ce7 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_experiment_sync.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateTensorboardExperiment +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_UpdateTensorboardExperiment_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_update_tensorboard_experiment(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.UpdateTensorboardExperimentRequest( + ) + + # Make the request + response = client.update_tensorboard_experiment(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_UpdateTensorboardExperiment_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_run_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_run_async.py new file mode 100644 index 0000000000..505dea8e0d --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_run_async.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateTensorboardRun +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_UpdateTensorboardRun_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_update_tensorboard_run(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + tensorboard_run = aiplatform_v1beta1.TensorboardRun() + tensorboard_run.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateTensorboardRunRequest( + tensorboard_run=tensorboard_run, + ) + + # Make the request + response = await client.update_tensorboard_run(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_UpdateTensorboardRun_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_run_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_run_sync.py new file mode 100644 index 0000000000..2fc6027d82 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_run_sync.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateTensorboardRun +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_UpdateTensorboardRun_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_update_tensorboard_run(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + tensorboard_run = aiplatform_v1beta1.TensorboardRun() + tensorboard_run.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateTensorboardRunRequest( + tensorboard_run=tensorboard_run, + ) + + # Make the request + response = client.update_tensorboard_run(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_UpdateTensorboardRun_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_sync.py new file mode 100644 index 0000000000..bf762f7170 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_sync.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateTensorboard +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_UpdateTensorboard_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_update_tensorboard(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + tensorboard = aiplatform_v1beta1.Tensorboard() + tensorboard.display_name = "display_name_value" + + request = aiplatform_v1beta1.UpdateTensorboardRequest( + tensorboard=tensorboard, + ) + + # Make the request + operation = client.update_tensorboard(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_UpdateTensorboard_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_time_series_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_time_series_async.py new file mode 100644 index 0000000000..ece4853f6d --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_time_series_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_UpdateTensorboardTimeSeries_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_update_tensorboard_time_series(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + tensorboard_time_series = aiplatform_v1beta1.TensorboardTimeSeries() + tensorboard_time_series.display_name = "display_name_value" + tensorboard_time_series.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1beta1.UpdateTensorboardTimeSeriesRequest( + tensorboard_time_series=tensorboard_time_series, + ) + + # Make the request + response = await client.update_tensorboard_time_series(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_UpdateTensorboardTimeSeries_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_time_series_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_time_series_sync.py new file mode 100644 index 0000000000..68077f0c73 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_time_series_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for UpdateTensorboardTimeSeries +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_UpdateTensorboardTimeSeries_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_update_tensorboard_time_series(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + tensorboard_time_series = aiplatform_v1beta1.TensorboardTimeSeries() + tensorboard_time_series.display_name = "display_name_value" + tensorboard_time_series.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1beta1.UpdateTensorboardTimeSeriesRequest( + tensorboard_time_series=tensorboard_time_series, + ) + + # Make the request + response = client.update_tensorboard_time_series(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_UpdateTensorboardTimeSeries_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_write_tensorboard_experiment_data_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_write_tensorboard_experiment_data_async.py new file mode 100644 index 0000000000..51ca02807c --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_write_tensorboard_experiment_data_async.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for WriteTensorboardExperimentData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_WriteTensorboardExperimentData_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_write_tensorboard_experiment_data(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + write_run_data_requests = aiplatform_v1beta1.WriteTensorboardRunDataRequest() + write_run_data_requests.tensorboard_run = "tensorboard_run_value" + write_run_data_requests.time_series_data.tensorboard_time_series_id = "tensorboard_time_series_id_value" + write_run_data_requests.time_series_data.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1beta1.WriteTensorboardExperimentDataRequest( + tensorboard_experiment="tensorboard_experiment_value", + write_run_data_requests=write_run_data_requests, + ) + + # Make the request + response = await client.write_tensorboard_experiment_data(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_WriteTensorboardExperimentData_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_write_tensorboard_experiment_data_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_write_tensorboard_experiment_data_sync.py new file mode 100644 index 0000000000..527f950cdb --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_write_tensorboard_experiment_data_sync.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for WriteTensorboardExperimentData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_WriteTensorboardExperimentData_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_write_tensorboard_experiment_data(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + write_run_data_requests = aiplatform_v1beta1.WriteTensorboardRunDataRequest() + write_run_data_requests.tensorboard_run = "tensorboard_run_value" + write_run_data_requests.time_series_data.tensorboard_time_series_id = "tensorboard_time_series_id_value" + write_run_data_requests.time_series_data.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1beta1.WriteTensorboardExperimentDataRequest( + tensorboard_experiment="tensorboard_experiment_value", + write_run_data_requests=write_run_data_requests, + ) + + # Make the request + response = client.write_tensorboard_experiment_data(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_WriteTensorboardExperimentData_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_write_tensorboard_run_data_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_write_tensorboard_run_data_async.py new file mode 100644 index 0000000000..70e747c88c --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_write_tensorboard_run_data_async.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for WriteTensorboardRunData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_WriteTensorboardRunData_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_write_tensorboard_run_data(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceAsyncClient() + + # Initialize request argument(s) + time_series_data = aiplatform_v1beta1.TimeSeriesData() + time_series_data.tensorboard_time_series_id = "tensorboard_time_series_id_value" + time_series_data.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1beta1.WriteTensorboardRunDataRequest( + tensorboard_run="tensorboard_run_value", + time_series_data=time_series_data, + ) + + # Make the request + response = await client.write_tensorboard_run_data(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_WriteTensorboardRunData_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_write_tensorboard_run_data_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_write_tensorboard_run_data_sync.py new file mode 100644 index 0000000000..1abe72d656 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_tensorboard_service_write_tensorboard_run_data_sync.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for WriteTensorboardRunData +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_TensorboardService_WriteTensorboardRunData_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_write_tensorboard_run_data(): + # Create a client + client = aiplatform_v1beta1.TensorboardServiceClient() + + # Initialize request argument(s) + time_series_data = aiplatform_v1beta1.TimeSeriesData() + time_series_data.tensorboard_time_series_id = "tensorboard_time_series_id_value" + time_series_data.value_type = "BLOB_SEQUENCE" + + request = aiplatform_v1beta1.WriteTensorboardRunDataRequest( + tensorboard_run="tensorboard_run_value", + time_series_data=time_series_data, + ) + + # Make the request + response = client.write_tensorboard_run_data(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_TensorboardService_WriteTensorboardRunData_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_add_trial_measurement_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_add_trial_measurement_async.py new file mode 100644 index 0000000000..b59c855d2a --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_add_trial_measurement_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddTrialMeasurement +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_VizierService_AddTrialMeasurement_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_add_trial_measurement(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.AddTrialMeasurementRequest( + trial_name="trial_name_value", + ) + + # Make the request + response = await client.add_trial_measurement(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_VizierService_AddTrialMeasurement_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_add_trial_measurement_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_add_trial_measurement_sync.py new file mode 100644 index 0000000000..d713f727f4 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_add_trial_measurement_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for AddTrialMeasurement +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_VizierService_AddTrialMeasurement_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_add_trial_measurement(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.AddTrialMeasurementRequest( + trial_name="trial_name_value", + ) + + # Make the request + response = client.add_trial_measurement(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_VizierService_AddTrialMeasurement_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_check_trial_early_stopping_state_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_check_trial_early_stopping_state_async.py new file mode 100644 index 0000000000..7fa5901eb7 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_check_trial_early_stopping_state_async.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CheckTrialEarlyStoppingState +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_VizierService_CheckTrialEarlyStoppingState_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_check_trial_early_stopping_state(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CheckTrialEarlyStoppingStateRequest( + trial_name="trial_name_value", + ) + + # Make the request + operation = client.check_trial_early_stopping_state(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_VizierService_CheckTrialEarlyStoppingState_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_check_trial_early_stopping_state_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_check_trial_early_stopping_state_sync.py new file mode 100644 index 0000000000..8fc432fbd9 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_check_trial_early_stopping_state_sync.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CheckTrialEarlyStoppingState +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_VizierService_CheckTrialEarlyStoppingState_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_check_trial_early_stopping_state(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CheckTrialEarlyStoppingStateRequest( + trial_name="trial_name_value", + ) + + # Make the request + operation = client.check_trial_early_stopping_state(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_VizierService_CheckTrialEarlyStoppingState_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_complete_trial_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_complete_trial_async.py new file mode 100644 index 0000000000..30fc9af533 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_complete_trial_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CompleteTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_VizierService_CompleteTrial_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_complete_trial(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CompleteTrialRequest( + name="name_value", + ) + + # Make the request + response = await client.complete_trial(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_VizierService_CompleteTrial_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_complete_trial_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_complete_trial_sync.py new file mode 100644 index 0000000000..d227e01d15 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_complete_trial_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CompleteTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_VizierService_CompleteTrial_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_complete_trial(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CompleteTrialRequest( + name="name_value", + ) + + # Make the request + response = client.complete_trial(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_VizierService_CompleteTrial_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_create_study_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_create_study_async.py new file mode 100644 index 0000000000..1a923afb48 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_create_study_async.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateStudy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_VizierService_CreateStudy_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_study(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + study = aiplatform_v1beta1.Study() + study.display_name = "display_name_value" + study.study_spec.metrics.metric_id = "metric_id_value" + study.study_spec.metrics.goal = "MINIMIZE" + study.study_spec.parameters.double_value_spec.min_value = 0.96 + study.study_spec.parameters.double_value_spec.max_value = 0.962 + study.study_spec.parameters.parameter_id = "parameter_id_value" + + request = aiplatform_v1beta1.CreateStudyRequest( + parent="parent_value", + study=study, + ) + + # Make the request + response = await client.create_study(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_VizierService_CreateStudy_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_create_study_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_create_study_sync.py new file mode 100644 index 0000000000..396f45c5be --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_create_study_sync.py @@ -0,0 +1,54 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateStudy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_VizierService_CreateStudy_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_study(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + study = aiplatform_v1beta1.Study() + study.display_name = "display_name_value" + study.study_spec.metrics.metric_id = "metric_id_value" + study.study_spec.metrics.goal = "MINIMIZE" + study.study_spec.parameters.double_value_spec.min_value = 0.96 + study.study_spec.parameters.double_value_spec.max_value = 0.962 + study.study_spec.parameters.parameter_id = "parameter_id_value" + + request = aiplatform_v1beta1.CreateStudyRequest( + parent="parent_value", + study=study, + ) + + # Make the request + response = client.create_study(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_VizierService_CreateStudy_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_create_trial_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_create_trial_async.py new file mode 100644 index 0000000000..0fa2502f33 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_create_trial_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_VizierService_CreateTrial_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_create_trial(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateTrialRequest( + parent="parent_value", + ) + + # Make the request + response = await client.create_trial(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_VizierService_CreateTrial_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_create_trial_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_create_trial_sync.py new file mode 100644 index 0000000000..c776e0dcd2 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_create_trial_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for CreateTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_VizierService_CreateTrial_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_create_trial(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.CreateTrialRequest( + parent="parent_value", + ) + + # Make the request + response = client.create_trial(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_VizierService_CreateTrial_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_delete_study_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_delete_study_async.py new file mode 100644 index 0000000000..7178b7ffe0 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_delete_study_async.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteStudy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_VizierService_DeleteStudy_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_study(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteStudyRequest( + name="name_value", + ) + + # Make the request + await client.delete_study(request=request) + + +# [END aiplatform_v1beta1_generated_VizierService_DeleteStudy_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_delete_study_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_delete_study_sync.py new file mode 100644 index 0000000000..f259e8a0a5 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_delete_study_sync.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteStudy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_VizierService_DeleteStudy_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_study(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteStudyRequest( + name="name_value", + ) + + # Make the request + client.delete_study(request=request) + + +# [END aiplatform_v1beta1_generated_VizierService_DeleteStudy_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_delete_trial_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_delete_trial_async.py new file mode 100644 index 0000000000..0e2b0638f8 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_delete_trial_async.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_VizierService_DeleteTrial_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_delete_trial(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteTrialRequest( + name="name_value", + ) + + # Make the request + await client.delete_trial(request=request) + + +# [END aiplatform_v1beta1_generated_VizierService_DeleteTrial_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_delete_trial_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_delete_trial_sync.py new file mode 100644 index 0000000000..21fe7a82fc --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_delete_trial_sync.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for DeleteTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_VizierService_DeleteTrial_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_delete_trial(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.DeleteTrialRequest( + name="name_value", + ) + + # Make the request + client.delete_trial(request=request) + + +# [END aiplatform_v1beta1_generated_VizierService_DeleteTrial_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_get_study_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_get_study_async.py new file mode 100644 index 0000000000..ed514cada2 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_get_study_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetStudy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_VizierService_GetStudy_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_study(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetStudyRequest( + name="name_value", + ) + + # Make the request + response = await client.get_study(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_VizierService_GetStudy_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_get_study_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_get_study_sync.py new file mode 100644 index 0000000000..dea4a50945 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_get_study_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetStudy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_VizierService_GetStudy_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_study(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetStudyRequest( + name="name_value", + ) + + # Make the request + response = client.get_study(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_VizierService_GetStudy_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_get_trial_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_get_trial_async.py new file mode 100644 index 0000000000..a8cef49ac7 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_get_trial_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_VizierService_GetTrial_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_get_trial(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetTrialRequest( + name="name_value", + ) + + # Make the request + response = await client.get_trial(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_VizierService_GetTrial_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_get_trial_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_get_trial_sync.py new file mode 100644 index 0000000000..b1c32464f9 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_get_trial_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for GetTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_VizierService_GetTrial_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_get_trial(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.GetTrialRequest( + name="name_value", + ) + + # Make the request + response = client.get_trial(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_VizierService_GetTrial_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_list_optimal_trials_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_list_optimal_trials_async.py new file mode 100644 index 0000000000..5ea4f5d74d --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_list_optimal_trials_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListOptimalTrials +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_VizierService_ListOptimalTrials_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_optimal_trials(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListOptimalTrialsRequest( + parent="parent_value", + ) + + # Make the request + response = await client.list_optimal_trials(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_VizierService_ListOptimalTrials_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_list_optimal_trials_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_list_optimal_trials_sync.py new file mode 100644 index 0000000000..90f9f409bc --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_list_optimal_trials_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListOptimalTrials +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_VizierService_ListOptimalTrials_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_optimal_trials(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListOptimalTrialsRequest( + parent="parent_value", + ) + + # Make the request + response = client.list_optimal_trials(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_VizierService_ListOptimalTrials_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_list_studies_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_list_studies_async.py new file mode 100644 index 0000000000..6040471485 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_list_studies_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListStudies +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_VizierService_ListStudies_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_studies(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListStudiesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_studies(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_VizierService_ListStudies_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_list_studies_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_list_studies_sync.py new file mode 100644 index 0000000000..bcd72071d5 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_list_studies_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListStudies +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_VizierService_ListStudies_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_studies(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListStudiesRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_studies(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_VizierService_ListStudies_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_list_trials_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_list_trials_async.py new file mode 100644 index 0000000000..a86618e52c --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_list_trials_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTrials +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_VizierService_ListTrials_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_list_trials(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListTrialsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_trials(request=request) + + # Handle the response + async for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_VizierService_ListTrials_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_list_trials_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_list_trials_sync.py new file mode 100644 index 0000000000..7d68763af9 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_list_trials_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for ListTrials +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_VizierService_ListTrials_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_list_trials(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.ListTrialsRequest( + parent="parent_value", + ) + + # Make the request + page_result = client.list_trials(request=request) + + # Handle the response + for response in page_result: + print(response) + +# [END aiplatform_v1beta1_generated_VizierService_ListTrials_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_lookup_study_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_lookup_study_async.py new file mode 100644 index 0000000000..31d560c32e --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_lookup_study_async.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for LookupStudy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_VizierService_LookupStudy_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_lookup_study(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.LookupStudyRequest( + parent="parent_value", + display_name="display_name_value", + ) + + # Make the request + response = await client.lookup_study(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_VizierService_LookupStudy_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_lookup_study_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_lookup_study_sync.py new file mode 100644 index 0000000000..458b8dfe43 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_lookup_study_sync.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for LookupStudy +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_VizierService_LookupStudy_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_lookup_study(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.LookupStudyRequest( + parent="parent_value", + display_name="display_name_value", + ) + + # Make the request + response = client.lookup_study(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_VizierService_LookupStudy_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_stop_trial_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_stop_trial_async.py new file mode 100644 index 0000000000..ca540079db --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_stop_trial_async.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for StopTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_VizierService_StopTrial_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_stop_trial(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.StopTrialRequest( + name="name_value", + ) + + # Make the request + response = await client.stop_trial(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_VizierService_StopTrial_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_stop_trial_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_stop_trial_sync.py new file mode 100644 index 0000000000..8859749951 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_stop_trial_sync.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for StopTrial +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_VizierService_StopTrial_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_stop_trial(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.StopTrialRequest( + name="name_value", + ) + + # Make the request + response = client.stop_trial(request=request) + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_VizierService_StopTrial_sync] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_suggest_trials_async.py b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_suggest_trials_async.py new file mode 100644 index 0000000000..25c90f6119 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_suggest_trials_async.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SuggestTrials +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_VizierService_SuggestTrials_async] +from google.cloud import aiplatform_v1beta1 + + +async def sample_suggest_trials(): + # Create a client + client = aiplatform_v1beta1.VizierServiceAsyncClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.SuggestTrialsRequest( + parent="parent_value", + suggestion_count=1744, + client_id="client_id_value", + ) + + # Make the request + operation = client.suggest_trials(request=request) + + print("Waiting for operation to complete...") + + response = await operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_VizierService_SuggestTrials_async] diff --git a/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_suggest_trials_sync.py b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_suggest_trials_sync.py new file mode 100644 index 0000000000..8d8b220145 --- /dev/null +++ b/samples/generated_samples/aiplatform_v1beta1_generated_vizier_service_suggest_trials_sync.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +# Generated code. DO NOT EDIT! +# +# Snippet for SuggestTrials +# NOTE: This snippet has been automatically generated for illustrative purposes only. +# It may require modifications to work in your environment. + +# To install the latest published package dependency, execute the following: +# python3 -m pip install google-cloud-aiplatform + + +# [START aiplatform_v1beta1_generated_VizierService_SuggestTrials_sync] +from google.cloud import aiplatform_v1beta1 + + +def sample_suggest_trials(): + # Create a client + client = aiplatform_v1beta1.VizierServiceClient() + + # Initialize request argument(s) + request = aiplatform_v1beta1.SuggestTrialsRequest( + parent="parent_value", + suggestion_count=1744, + client_id="client_id_value", + ) + + # Make the request + operation = client.suggest_trials(request=request) + + print("Waiting for operation to complete...") + + response = operation.result() + + # Handle the response + print(response) + +# [END aiplatform_v1beta1_generated_VizierService_SuggestTrials_sync] diff --git a/samples/generated_samples/snippet_metadata_aiplatform_v1.json b/samples/generated_samples/snippet_metadata_aiplatform_v1.json new file mode 100644 index 0000000000..20a7d2ed99 --- /dev/null +++ b/samples/generated_samples/snippet_metadata_aiplatform_v1.json @@ -0,0 +1,30886 @@ +{ + "clientLibrary": { + "apis": [ + { + "id": "google.cloud.aiplatform.v1", + "version": "v1" + } + ], + "language": "PYTHON", + "name": "google-cloud-aiplatform" + }, + "snippets": [ + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.DatasetServiceAsyncClient", + "shortName": "DatasetServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.DatasetServiceAsyncClient.create_dataset", + "method": { + "fullName": "google.cloud.aiplatform.v1.DatasetService.CreateDataset", + "service": { + "fullName": "google.cloud.aiplatform.v1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "CreateDataset" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateDatasetRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "dataset", + "type": "google.cloud.aiplatform_v1.types.Dataset" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "create_dataset" + }, + "description": "Sample for CreateDataset", + "file": "aiplatform_v1_generated_dataset_service_create_dataset_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_DatasetService_CreateDataset_async", + "segments": [ + { + "end": 54, + "start": 27, + "type": "FULL" + }, + { + "end": 54, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 51, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 55, + "start": 52, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_dataset_service_create_dataset_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.DatasetServiceClient", + "shortName": "DatasetServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.DatasetServiceClient.create_dataset", + "method": { + "fullName": "google.cloud.aiplatform.v1.DatasetService.CreateDataset", + "service": { + "fullName": "google.cloud.aiplatform.v1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "CreateDataset" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateDatasetRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "dataset", + "type": "google.cloud.aiplatform_v1.types.Dataset" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "create_dataset" + }, + "description": "Sample for CreateDataset", + "file": "aiplatform_v1_generated_dataset_service_create_dataset_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_DatasetService_CreateDataset_sync", + "segments": [ + { + "end": 54, + "start": 27, + "type": "FULL" + }, + { + "end": 54, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 51, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 55, + "start": 52, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_dataset_service_create_dataset_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.DatasetServiceAsyncClient", + "shortName": "DatasetServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.DatasetServiceAsyncClient.delete_dataset", + "method": { + "fullName": "google.cloud.aiplatform.v1.DatasetService.DeleteDataset", + "service": { + "fullName": "google.cloud.aiplatform.v1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "DeleteDataset" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteDatasetRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_dataset" + }, + "description": "Sample for DeleteDataset", + "file": "aiplatform_v1_generated_dataset_service_delete_dataset_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_DatasetService_DeleteDataset_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_dataset_service_delete_dataset_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.DatasetServiceClient", + "shortName": "DatasetServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.DatasetServiceClient.delete_dataset", + "method": { + "fullName": "google.cloud.aiplatform.v1.DatasetService.DeleteDataset", + "service": { + "fullName": "google.cloud.aiplatform.v1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "DeleteDataset" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteDatasetRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_dataset" + }, + "description": "Sample for DeleteDataset", + "file": "aiplatform_v1_generated_dataset_service_delete_dataset_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_DatasetService_DeleteDataset_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_dataset_service_delete_dataset_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.DatasetServiceAsyncClient", + "shortName": "DatasetServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.DatasetServiceAsyncClient.export_data", + "method": { + "fullName": "google.cloud.aiplatform.v1.DatasetService.ExportData", + "service": { + "fullName": "google.cloud.aiplatform.v1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "ExportData" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ExportDataRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "export_config", + "type": "google.cloud.aiplatform_v1.types.ExportDataConfig" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "export_data" + }, + "description": "Sample for ExportData", + "file": "aiplatform_v1_generated_dataset_service_export_data_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_DatasetService_ExportData_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_dataset_service_export_data_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.DatasetServiceClient", + "shortName": "DatasetServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.DatasetServiceClient.export_data", + "method": { + "fullName": "google.cloud.aiplatform.v1.DatasetService.ExportData", + "service": { + "fullName": "google.cloud.aiplatform.v1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "ExportData" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ExportDataRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "export_config", + "type": "google.cloud.aiplatform_v1.types.ExportDataConfig" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "export_data" + }, + "description": "Sample for ExportData", + "file": "aiplatform_v1_generated_dataset_service_export_data_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_DatasetService_ExportData_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_dataset_service_export_data_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.DatasetServiceAsyncClient", + "shortName": "DatasetServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.DatasetServiceAsyncClient.get_annotation_spec", + "method": { + "fullName": "google.cloud.aiplatform.v1.DatasetService.GetAnnotationSpec", + "service": { + "fullName": "google.cloud.aiplatform.v1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "GetAnnotationSpec" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetAnnotationSpecRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.AnnotationSpec", + "shortName": "get_annotation_spec" + }, + "description": "Sample for GetAnnotationSpec", + "file": "aiplatform_v1_generated_dataset_service_get_annotation_spec_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_DatasetService_GetAnnotationSpec_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_dataset_service_get_annotation_spec_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.DatasetServiceClient", + "shortName": "DatasetServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.DatasetServiceClient.get_annotation_spec", + "method": { + "fullName": "google.cloud.aiplatform.v1.DatasetService.GetAnnotationSpec", + "service": { + "fullName": "google.cloud.aiplatform.v1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "GetAnnotationSpec" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetAnnotationSpecRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.AnnotationSpec", + "shortName": "get_annotation_spec" + }, + "description": "Sample for GetAnnotationSpec", + "file": "aiplatform_v1_generated_dataset_service_get_annotation_spec_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_DatasetService_GetAnnotationSpec_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_dataset_service_get_annotation_spec_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.DatasetServiceAsyncClient", + "shortName": "DatasetServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.DatasetServiceAsyncClient.get_dataset", + "method": { + "fullName": "google.cloud.aiplatform.v1.DatasetService.GetDataset", + "service": { + "fullName": "google.cloud.aiplatform.v1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "GetDataset" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetDatasetRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Dataset", + "shortName": "get_dataset" + }, + "description": "Sample for GetDataset", + "file": "aiplatform_v1_generated_dataset_service_get_dataset_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_DatasetService_GetDataset_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_dataset_service_get_dataset_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.DatasetServiceClient", + "shortName": "DatasetServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.DatasetServiceClient.get_dataset", + "method": { + "fullName": "google.cloud.aiplatform.v1.DatasetService.GetDataset", + "service": { + "fullName": "google.cloud.aiplatform.v1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "GetDataset" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetDatasetRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Dataset", + "shortName": "get_dataset" + }, + "description": "Sample for GetDataset", + "file": "aiplatform_v1_generated_dataset_service_get_dataset_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_DatasetService_GetDataset_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_dataset_service_get_dataset_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.DatasetServiceAsyncClient", + "shortName": "DatasetServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.DatasetServiceAsyncClient.import_data", + "method": { + "fullName": "google.cloud.aiplatform.v1.DatasetService.ImportData", + "service": { + "fullName": "google.cloud.aiplatform.v1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "ImportData" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ImportDataRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "import_configs", + "type": "Sequence[google.cloud.aiplatform_v1.types.ImportDataConfig]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "import_data" + }, + "description": "Sample for ImportData", + "file": "aiplatform_v1_generated_dataset_service_import_data_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_DatasetService_ImportData_async", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_dataset_service_import_data_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.DatasetServiceClient", + "shortName": "DatasetServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.DatasetServiceClient.import_data", + "method": { + "fullName": "google.cloud.aiplatform.v1.DatasetService.ImportData", + "service": { + "fullName": "google.cloud.aiplatform.v1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "ImportData" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ImportDataRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "import_configs", + "type": "Sequence[google.cloud.aiplatform_v1.types.ImportDataConfig]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "import_data" + }, + "description": "Sample for ImportData", + "file": "aiplatform_v1_generated_dataset_service_import_data_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_DatasetService_ImportData_sync", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_dataset_service_import_data_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.DatasetServiceAsyncClient", + "shortName": "DatasetServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.DatasetServiceAsyncClient.list_annotations", + "method": { + "fullName": "google.cloud.aiplatform.v1.DatasetService.ListAnnotations", + "service": { + "fullName": "google.cloud.aiplatform.v1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "ListAnnotations" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListAnnotationsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.dataset_service.pagers.ListAnnotationsAsyncPager", + "shortName": "list_annotations" + }, + "description": "Sample for ListAnnotations", + "file": "aiplatform_v1_generated_dataset_service_list_annotations_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_DatasetService_ListAnnotations_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_dataset_service_list_annotations_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.DatasetServiceClient", + "shortName": "DatasetServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.DatasetServiceClient.list_annotations", + "method": { + "fullName": "google.cloud.aiplatform.v1.DatasetService.ListAnnotations", + "service": { + "fullName": "google.cloud.aiplatform.v1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "ListAnnotations" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListAnnotationsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.dataset_service.pagers.ListAnnotationsPager", + "shortName": "list_annotations" + }, + "description": "Sample for ListAnnotations", + "file": "aiplatform_v1_generated_dataset_service_list_annotations_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_DatasetService_ListAnnotations_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_dataset_service_list_annotations_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.DatasetServiceAsyncClient", + "shortName": "DatasetServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.DatasetServiceAsyncClient.list_data_items", + "method": { + "fullName": "google.cloud.aiplatform.v1.DatasetService.ListDataItems", + "service": { + "fullName": "google.cloud.aiplatform.v1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "ListDataItems" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListDataItemsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.dataset_service.pagers.ListDataItemsAsyncPager", + "shortName": "list_data_items" + }, + "description": "Sample for ListDataItems", + "file": "aiplatform_v1_generated_dataset_service_list_data_items_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_DatasetService_ListDataItems_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_dataset_service_list_data_items_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.DatasetServiceClient", + "shortName": "DatasetServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.DatasetServiceClient.list_data_items", + "method": { + "fullName": "google.cloud.aiplatform.v1.DatasetService.ListDataItems", + "service": { + "fullName": "google.cloud.aiplatform.v1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "ListDataItems" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListDataItemsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.dataset_service.pagers.ListDataItemsPager", + "shortName": "list_data_items" + }, + "description": "Sample for ListDataItems", + "file": "aiplatform_v1_generated_dataset_service_list_data_items_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_DatasetService_ListDataItems_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_dataset_service_list_data_items_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.DatasetServiceAsyncClient", + "shortName": "DatasetServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.DatasetServiceAsyncClient.list_datasets", + "method": { + "fullName": "google.cloud.aiplatform.v1.DatasetService.ListDatasets", + "service": { + "fullName": "google.cloud.aiplatform.v1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "ListDatasets" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListDatasetsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.dataset_service.pagers.ListDatasetsAsyncPager", + "shortName": "list_datasets" + }, + "description": "Sample for ListDatasets", + "file": "aiplatform_v1_generated_dataset_service_list_datasets_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_DatasetService_ListDatasets_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_dataset_service_list_datasets_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.DatasetServiceClient", + "shortName": "DatasetServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.DatasetServiceClient.list_datasets", + "method": { + "fullName": "google.cloud.aiplatform.v1.DatasetService.ListDatasets", + "service": { + "fullName": "google.cloud.aiplatform.v1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "ListDatasets" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListDatasetsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.dataset_service.pagers.ListDatasetsPager", + "shortName": "list_datasets" + }, + "description": "Sample for ListDatasets", + "file": "aiplatform_v1_generated_dataset_service_list_datasets_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_DatasetService_ListDatasets_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_dataset_service_list_datasets_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.DatasetServiceAsyncClient", + "shortName": "DatasetServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.DatasetServiceAsyncClient.update_dataset", + "method": { + "fullName": "google.cloud.aiplatform.v1.DatasetService.UpdateDataset", + "service": { + "fullName": "google.cloud.aiplatform.v1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "UpdateDataset" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UpdateDatasetRequest" + }, + { + "name": "dataset", + "type": "google.cloud.aiplatform_v1.types.Dataset" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Dataset", + "shortName": "update_dataset" + }, + "description": "Sample for UpdateDataset", + "file": "aiplatform_v1_generated_dataset_service_update_dataset_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_DatasetService_UpdateDataset_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_dataset_service_update_dataset_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.DatasetServiceClient", + "shortName": "DatasetServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.DatasetServiceClient.update_dataset", + "method": { + "fullName": "google.cloud.aiplatform.v1.DatasetService.UpdateDataset", + "service": { + "fullName": "google.cloud.aiplatform.v1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "UpdateDataset" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UpdateDatasetRequest" + }, + { + "name": "dataset", + "type": "google.cloud.aiplatform_v1.types.Dataset" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Dataset", + "shortName": "update_dataset" + }, + "description": "Sample for UpdateDataset", + "file": "aiplatform_v1_generated_dataset_service_update_dataset_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_DatasetService_UpdateDataset_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_dataset_service_update_dataset_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.EndpointServiceAsyncClient", + "shortName": "EndpointServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.EndpointServiceAsyncClient.create_endpoint", + "method": { + "fullName": "google.cloud.aiplatform.v1.EndpointService.CreateEndpoint", + "service": { + "fullName": "google.cloud.aiplatform.v1.EndpointService", + "shortName": "EndpointService" + }, + "shortName": "CreateEndpoint" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateEndpointRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "endpoint", + "type": "google.cloud.aiplatform_v1.types.Endpoint" + }, + { + "name": "endpoint_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "create_endpoint" + }, + "description": "Sample for CreateEndpoint", + "file": "aiplatform_v1_generated_endpoint_service_create_endpoint_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_EndpointService_CreateEndpoint_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_endpoint_service_create_endpoint_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.EndpointServiceClient", + "shortName": "EndpointServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.EndpointServiceClient.create_endpoint", + "method": { + "fullName": "google.cloud.aiplatform.v1.EndpointService.CreateEndpoint", + "service": { + "fullName": "google.cloud.aiplatform.v1.EndpointService", + "shortName": "EndpointService" + }, + "shortName": "CreateEndpoint" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateEndpointRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "endpoint", + "type": "google.cloud.aiplatform_v1.types.Endpoint" + }, + { + "name": "endpoint_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "create_endpoint" + }, + "description": "Sample for CreateEndpoint", + "file": "aiplatform_v1_generated_endpoint_service_create_endpoint_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_EndpointService_CreateEndpoint_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_endpoint_service_create_endpoint_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.EndpointServiceAsyncClient", + "shortName": "EndpointServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.EndpointServiceAsyncClient.delete_endpoint", + "method": { + "fullName": "google.cloud.aiplatform.v1.EndpointService.DeleteEndpoint", + "service": { + "fullName": "google.cloud.aiplatform.v1.EndpointService", + "shortName": "EndpointService" + }, + "shortName": "DeleteEndpoint" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteEndpointRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_endpoint" + }, + "description": "Sample for DeleteEndpoint", + "file": "aiplatform_v1_generated_endpoint_service_delete_endpoint_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_EndpointService_DeleteEndpoint_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_endpoint_service_delete_endpoint_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.EndpointServiceClient", + "shortName": "EndpointServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.EndpointServiceClient.delete_endpoint", + "method": { + "fullName": "google.cloud.aiplatform.v1.EndpointService.DeleteEndpoint", + "service": { + "fullName": "google.cloud.aiplatform.v1.EndpointService", + "shortName": "EndpointService" + }, + "shortName": "DeleteEndpoint" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteEndpointRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_endpoint" + }, + "description": "Sample for DeleteEndpoint", + "file": "aiplatform_v1_generated_endpoint_service_delete_endpoint_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_EndpointService_DeleteEndpoint_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_endpoint_service_delete_endpoint_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.EndpointServiceAsyncClient", + "shortName": "EndpointServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.EndpointServiceAsyncClient.deploy_model", + "method": { + "fullName": "google.cloud.aiplatform.v1.EndpointService.DeployModel", + "service": { + "fullName": "google.cloud.aiplatform.v1.EndpointService", + "shortName": "EndpointService" + }, + "shortName": "DeployModel" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeployModelRequest" + }, + { + "name": "endpoint", + "type": "str" + }, + { + "name": "deployed_model", + "type": "google.cloud.aiplatform_v1.types.DeployedModel" + }, + { + "name": "traffic_split", + "type": "Mapping[str, int]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "deploy_model" + }, + "description": "Sample for DeployModel", + "file": "aiplatform_v1_generated_endpoint_service_deploy_model_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_EndpointService_DeployModel_async", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_endpoint_service_deploy_model_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.EndpointServiceClient", + "shortName": "EndpointServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.EndpointServiceClient.deploy_model", + "method": { + "fullName": "google.cloud.aiplatform.v1.EndpointService.DeployModel", + "service": { + "fullName": "google.cloud.aiplatform.v1.EndpointService", + "shortName": "EndpointService" + }, + "shortName": "DeployModel" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeployModelRequest" + }, + { + "name": "endpoint", + "type": "str" + }, + { + "name": "deployed_model", + "type": "google.cloud.aiplatform_v1.types.DeployedModel" + }, + { + "name": "traffic_split", + "type": "Mapping[str, int]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "deploy_model" + }, + "description": "Sample for DeployModel", + "file": "aiplatform_v1_generated_endpoint_service_deploy_model_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_EndpointService_DeployModel_sync", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_endpoint_service_deploy_model_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.EndpointServiceAsyncClient", + "shortName": "EndpointServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.EndpointServiceAsyncClient.get_endpoint", + "method": { + "fullName": "google.cloud.aiplatform.v1.EndpointService.GetEndpoint", + "service": { + "fullName": "google.cloud.aiplatform.v1.EndpointService", + "shortName": "EndpointService" + }, + "shortName": "GetEndpoint" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetEndpointRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Endpoint", + "shortName": "get_endpoint" + }, + "description": "Sample for GetEndpoint", + "file": "aiplatform_v1_generated_endpoint_service_get_endpoint_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_EndpointService_GetEndpoint_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_endpoint_service_get_endpoint_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.EndpointServiceClient", + "shortName": "EndpointServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.EndpointServiceClient.get_endpoint", + "method": { + "fullName": "google.cloud.aiplatform.v1.EndpointService.GetEndpoint", + "service": { + "fullName": "google.cloud.aiplatform.v1.EndpointService", + "shortName": "EndpointService" + }, + "shortName": "GetEndpoint" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetEndpointRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Endpoint", + "shortName": "get_endpoint" + }, + "description": "Sample for GetEndpoint", + "file": "aiplatform_v1_generated_endpoint_service_get_endpoint_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_EndpointService_GetEndpoint_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_endpoint_service_get_endpoint_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.EndpointServiceAsyncClient", + "shortName": "EndpointServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.EndpointServiceAsyncClient.list_endpoints", + "method": { + "fullName": "google.cloud.aiplatform.v1.EndpointService.ListEndpoints", + "service": { + "fullName": "google.cloud.aiplatform.v1.EndpointService", + "shortName": "EndpointService" + }, + "shortName": "ListEndpoints" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListEndpointsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.endpoint_service.pagers.ListEndpointsAsyncPager", + "shortName": "list_endpoints" + }, + "description": "Sample for ListEndpoints", + "file": "aiplatform_v1_generated_endpoint_service_list_endpoints_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_EndpointService_ListEndpoints_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_endpoint_service_list_endpoints_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.EndpointServiceClient", + "shortName": "EndpointServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.EndpointServiceClient.list_endpoints", + "method": { + "fullName": "google.cloud.aiplatform.v1.EndpointService.ListEndpoints", + "service": { + "fullName": "google.cloud.aiplatform.v1.EndpointService", + "shortName": "EndpointService" + }, + "shortName": "ListEndpoints" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListEndpointsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.endpoint_service.pagers.ListEndpointsPager", + "shortName": "list_endpoints" + }, + "description": "Sample for ListEndpoints", + "file": "aiplatform_v1_generated_endpoint_service_list_endpoints_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_EndpointService_ListEndpoints_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_endpoint_service_list_endpoints_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.EndpointServiceAsyncClient", + "shortName": "EndpointServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.EndpointServiceAsyncClient.undeploy_model", + "method": { + "fullName": "google.cloud.aiplatform.v1.EndpointService.UndeployModel", + "service": { + "fullName": "google.cloud.aiplatform.v1.EndpointService", + "shortName": "EndpointService" + }, + "shortName": "UndeployModel" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UndeployModelRequest" + }, + { + "name": "endpoint", + "type": "str" + }, + { + "name": "deployed_model_id", + "type": "str" + }, + { + "name": "traffic_split", + "type": "Mapping[str, int]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "undeploy_model" + }, + "description": "Sample for UndeployModel", + "file": "aiplatform_v1_generated_endpoint_service_undeploy_model_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_EndpointService_UndeployModel_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_endpoint_service_undeploy_model_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.EndpointServiceClient", + "shortName": "EndpointServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.EndpointServiceClient.undeploy_model", + "method": { + "fullName": "google.cloud.aiplatform.v1.EndpointService.UndeployModel", + "service": { + "fullName": "google.cloud.aiplatform.v1.EndpointService", + "shortName": "EndpointService" + }, + "shortName": "UndeployModel" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UndeployModelRequest" + }, + { + "name": "endpoint", + "type": "str" + }, + { + "name": "deployed_model_id", + "type": "str" + }, + { + "name": "traffic_split", + "type": "Mapping[str, int]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "undeploy_model" + }, + "description": "Sample for UndeployModel", + "file": "aiplatform_v1_generated_endpoint_service_undeploy_model_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_EndpointService_UndeployModel_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_endpoint_service_undeploy_model_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.EndpointServiceAsyncClient", + "shortName": "EndpointServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.EndpointServiceAsyncClient.update_endpoint", + "method": { + "fullName": "google.cloud.aiplatform.v1.EndpointService.UpdateEndpoint", + "service": { + "fullName": "google.cloud.aiplatform.v1.EndpointService", + "shortName": "EndpointService" + }, + "shortName": "UpdateEndpoint" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UpdateEndpointRequest" + }, + { + "name": "endpoint", + "type": "google.cloud.aiplatform_v1.types.Endpoint" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Endpoint", + "shortName": "update_endpoint" + }, + "description": "Sample for UpdateEndpoint", + "file": "aiplatform_v1_generated_endpoint_service_update_endpoint_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_EndpointService_UpdateEndpoint_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_endpoint_service_update_endpoint_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.EndpointServiceClient", + "shortName": "EndpointServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.EndpointServiceClient.update_endpoint", + "method": { + "fullName": "google.cloud.aiplatform.v1.EndpointService.UpdateEndpoint", + "service": { + "fullName": "google.cloud.aiplatform.v1.EndpointService", + "shortName": "EndpointService" + }, + "shortName": "UpdateEndpoint" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UpdateEndpointRequest" + }, + { + "name": "endpoint", + "type": "google.cloud.aiplatform_v1.types.Endpoint" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Endpoint", + "shortName": "update_endpoint" + }, + "description": "Sample for UpdateEndpoint", + "file": "aiplatform_v1_generated_endpoint_service_update_endpoint_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_EndpointService_UpdateEndpoint_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_endpoint_service_update_endpoint_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreOnlineServingServiceAsyncClient", + "shortName": "FeaturestoreOnlineServingServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreOnlineServingServiceAsyncClient.read_feature_values", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreOnlineServingService.ReadFeatureValues", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreOnlineServingService", + "shortName": "FeaturestoreOnlineServingService" + }, + "shortName": "ReadFeatureValues" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ReadFeatureValuesRequest" + }, + { + "name": "entity_type", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.ReadFeatureValuesResponse", + "shortName": "read_feature_values" + }, + "description": "Sample for ReadFeatureValues", + "file": "aiplatform_v1_generated_featurestore_online_serving_service_read_feature_values_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreOnlineServingService_ReadFeatureValues_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_online_serving_service_read_feature_values_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreOnlineServingServiceClient", + "shortName": "FeaturestoreOnlineServingServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreOnlineServingServiceClient.read_feature_values", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreOnlineServingService.ReadFeatureValues", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreOnlineServingService", + "shortName": "FeaturestoreOnlineServingService" + }, + "shortName": "ReadFeatureValues" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ReadFeatureValuesRequest" + }, + { + "name": "entity_type", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.ReadFeatureValuesResponse", + "shortName": "read_feature_values" + }, + "description": "Sample for ReadFeatureValues", + "file": "aiplatform_v1_generated_featurestore_online_serving_service_read_feature_values_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreOnlineServingService_ReadFeatureValues_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_online_serving_service_read_feature_values_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreOnlineServingServiceAsyncClient", + "shortName": "FeaturestoreOnlineServingServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreOnlineServingServiceAsyncClient.streaming_read_feature_values", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreOnlineServingService.StreamingReadFeatureValues", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreOnlineServingService", + "shortName": "FeaturestoreOnlineServingService" + }, + "shortName": "StreamingReadFeatureValues" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.StreamingReadFeatureValuesRequest" + }, + { + "name": "entity_type", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "Iterable[google.cloud.aiplatform_v1.types.ReadFeatureValuesResponse]", + "shortName": "streaming_read_feature_values" + }, + "description": "Sample for StreamingReadFeatureValues", + "file": "aiplatform_v1_generated_featurestore_online_serving_service_streaming_read_feature_values_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreOnlineServingService_StreamingReadFeatureValues_async", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_online_serving_service_streaming_read_feature_values_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreOnlineServingServiceClient", + "shortName": "FeaturestoreOnlineServingServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreOnlineServingServiceClient.streaming_read_feature_values", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreOnlineServingService.StreamingReadFeatureValues", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreOnlineServingService", + "shortName": "FeaturestoreOnlineServingService" + }, + "shortName": "StreamingReadFeatureValues" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.StreamingReadFeatureValuesRequest" + }, + { + "name": "entity_type", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "Iterable[google.cloud.aiplatform_v1.types.ReadFeatureValuesResponse]", + "shortName": "streaming_read_feature_values" + }, + "description": "Sample for StreamingReadFeatureValues", + "file": "aiplatform_v1_generated_featurestore_online_serving_service_streaming_read_feature_values_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreOnlineServingService_StreamingReadFeatureValues_sync", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_online_serving_service_streaming_read_feature_values_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient.batch_create_features", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.BatchCreateFeatures", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "BatchCreateFeatures" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.BatchCreateFeaturesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "requests", + "type": "Sequence[google.cloud.aiplatform_v1.types.CreateFeatureRequest]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "batch_create_features" + }, + "description": "Sample for BatchCreateFeatures", + "file": "aiplatform_v1_generated_featurestore_service_batch_create_features_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_BatchCreateFeatures_async", + "segments": [ + { + "end": 54, + "start": 27, + "type": "FULL" + }, + { + "end": 54, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 51, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 55, + "start": 52, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_batch_create_features_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient.batch_create_features", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.BatchCreateFeatures", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "BatchCreateFeatures" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.BatchCreateFeaturesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "requests", + "type": "Sequence[google.cloud.aiplatform_v1.types.CreateFeatureRequest]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "batch_create_features" + }, + "description": "Sample for BatchCreateFeatures", + "file": "aiplatform_v1_generated_featurestore_service_batch_create_features_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_BatchCreateFeatures_sync", + "segments": [ + { + "end": 54, + "start": 27, + "type": "FULL" + }, + { + "end": 54, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 51, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 55, + "start": 52, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_batch_create_features_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient.batch_read_feature_values", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.BatchReadFeatureValues", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "BatchReadFeatureValues" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.BatchReadFeatureValuesRequest" + }, + { + "name": "featurestore", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "batch_read_feature_values" + }, + "description": "Sample for BatchReadFeatureValues", + "file": "aiplatform_v1_generated_featurestore_service_batch_read_feature_values_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_BatchReadFeatureValues_async", + "segments": [ + { + "end": 61, + "start": 27, + "type": "FULL" + }, + { + "end": 61, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 51, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 58, + "start": 52, + "type": "REQUEST_EXECUTION" + }, + { + "end": 62, + "start": 59, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_batch_read_feature_values_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient.batch_read_feature_values", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.BatchReadFeatureValues", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "BatchReadFeatureValues" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.BatchReadFeatureValuesRequest" + }, + { + "name": "featurestore", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "batch_read_feature_values" + }, + "description": "Sample for BatchReadFeatureValues", + "file": "aiplatform_v1_generated_featurestore_service_batch_read_feature_values_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_BatchReadFeatureValues_sync", + "segments": [ + { + "end": 61, + "start": 27, + "type": "FULL" + }, + { + "end": 61, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 51, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 58, + "start": 52, + "type": "REQUEST_EXECUTION" + }, + { + "end": 62, + "start": 59, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_batch_read_feature_values_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient.create_entity_type", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.CreateEntityType", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "CreateEntityType" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateEntityTypeRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "entity_type", + "type": "google.cloud.aiplatform_v1.types.EntityType" + }, + { + "name": "entity_type_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "create_entity_type" + }, + "description": "Sample for CreateEntityType", + "file": "aiplatform_v1_generated_featurestore_service_create_entity_type_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_CreateEntityType_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_create_entity_type_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient.create_entity_type", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.CreateEntityType", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "CreateEntityType" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateEntityTypeRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "entity_type", + "type": "google.cloud.aiplatform_v1.types.EntityType" + }, + { + "name": "entity_type_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "create_entity_type" + }, + "description": "Sample for CreateEntityType", + "file": "aiplatform_v1_generated_featurestore_service_create_entity_type_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_CreateEntityType_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_create_entity_type_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient.create_feature", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.CreateFeature", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "CreateFeature" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateFeatureRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "feature", + "type": "google.cloud.aiplatform_v1.types.Feature" + }, + { + "name": "feature_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "create_feature" + }, + "description": "Sample for CreateFeature", + "file": "aiplatform_v1_generated_featurestore_service_create_feature_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_CreateFeature_async", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_create_feature_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient.create_feature", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.CreateFeature", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "CreateFeature" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateFeatureRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "feature", + "type": "google.cloud.aiplatform_v1.types.Feature" + }, + { + "name": "feature_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "create_feature" + }, + "description": "Sample for CreateFeature", + "file": "aiplatform_v1_generated_featurestore_service_create_feature_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_CreateFeature_sync", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_create_feature_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient.create_featurestore", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.CreateFeaturestore", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "CreateFeaturestore" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateFeaturestoreRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "featurestore", + "type": "google.cloud.aiplatform_v1.types.Featurestore" + }, + { + "name": "featurestore_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "create_featurestore" + }, + "description": "Sample for CreateFeaturestore", + "file": "aiplatform_v1_generated_featurestore_service_create_featurestore_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_CreateFeaturestore_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_create_featurestore_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient.create_featurestore", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.CreateFeaturestore", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "CreateFeaturestore" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateFeaturestoreRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "featurestore", + "type": "google.cloud.aiplatform_v1.types.Featurestore" + }, + { + "name": "featurestore_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "create_featurestore" + }, + "description": "Sample for CreateFeaturestore", + "file": "aiplatform_v1_generated_featurestore_service_create_featurestore_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_CreateFeaturestore_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_create_featurestore_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient.delete_entity_type", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.DeleteEntityType", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "DeleteEntityType" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteEntityTypeRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "force", + "type": "bool" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_entity_type" + }, + "description": "Sample for DeleteEntityType", + "file": "aiplatform_v1_generated_featurestore_service_delete_entity_type_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_DeleteEntityType_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_delete_entity_type_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient.delete_entity_type", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.DeleteEntityType", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "DeleteEntityType" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteEntityTypeRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "force", + "type": "bool" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_entity_type" + }, + "description": "Sample for DeleteEntityType", + "file": "aiplatform_v1_generated_featurestore_service_delete_entity_type_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_DeleteEntityType_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_delete_entity_type_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient.delete_feature", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.DeleteFeature", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "DeleteFeature" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteFeatureRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_feature" + }, + "description": "Sample for DeleteFeature", + "file": "aiplatform_v1_generated_featurestore_service_delete_feature_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_DeleteFeature_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_delete_feature_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient.delete_feature", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.DeleteFeature", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "DeleteFeature" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteFeatureRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_feature" + }, + "description": "Sample for DeleteFeature", + "file": "aiplatform_v1_generated_featurestore_service_delete_feature_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_DeleteFeature_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_delete_feature_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient.delete_featurestore", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.DeleteFeaturestore", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "DeleteFeaturestore" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteFeaturestoreRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "force", + "type": "bool" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_featurestore" + }, + "description": "Sample for DeleteFeaturestore", + "file": "aiplatform_v1_generated_featurestore_service_delete_featurestore_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_DeleteFeaturestore_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_delete_featurestore_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient.delete_featurestore", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.DeleteFeaturestore", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "DeleteFeaturestore" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteFeaturestoreRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "force", + "type": "bool" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_featurestore" + }, + "description": "Sample for DeleteFeaturestore", + "file": "aiplatform_v1_generated_featurestore_service_delete_featurestore_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_DeleteFeaturestore_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_delete_featurestore_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient.export_feature_values", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.ExportFeatureValues", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "ExportFeatureValues" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ExportFeatureValuesRequest" + }, + { + "name": "entity_type", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "export_feature_values" + }, + "description": "Sample for ExportFeatureValues", + "file": "aiplatform_v1_generated_featurestore_service_export_feature_values_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_ExportFeatureValues_async", + "segments": [ + { + "end": 56, + "start": 27, + "type": "FULL" + }, + { + "end": 56, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 53, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 57, + "start": 54, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_export_feature_values_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient.export_feature_values", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.ExportFeatureValues", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "ExportFeatureValues" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ExportFeatureValuesRequest" + }, + { + "name": "entity_type", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "export_feature_values" + }, + "description": "Sample for ExportFeatureValues", + "file": "aiplatform_v1_generated_featurestore_service_export_feature_values_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_ExportFeatureValues_sync", + "segments": [ + { + "end": 56, + "start": 27, + "type": "FULL" + }, + { + "end": 56, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 53, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 57, + "start": 54, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_export_feature_values_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient.get_entity_type", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.GetEntityType", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "GetEntityType" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetEntityTypeRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.EntityType", + "shortName": "get_entity_type" + }, + "description": "Sample for GetEntityType", + "file": "aiplatform_v1_generated_featurestore_service_get_entity_type_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_GetEntityType_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_get_entity_type_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient.get_entity_type", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.GetEntityType", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "GetEntityType" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetEntityTypeRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.EntityType", + "shortName": "get_entity_type" + }, + "description": "Sample for GetEntityType", + "file": "aiplatform_v1_generated_featurestore_service_get_entity_type_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_GetEntityType_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_get_entity_type_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient.get_feature", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.GetFeature", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "GetFeature" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetFeatureRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Feature", + "shortName": "get_feature" + }, + "description": "Sample for GetFeature", + "file": "aiplatform_v1_generated_featurestore_service_get_feature_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_GetFeature_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_get_feature_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient.get_feature", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.GetFeature", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "GetFeature" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetFeatureRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Feature", + "shortName": "get_feature" + }, + "description": "Sample for GetFeature", + "file": "aiplatform_v1_generated_featurestore_service_get_feature_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_GetFeature_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_get_feature_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient.get_featurestore", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.GetFeaturestore", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "GetFeaturestore" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetFeaturestoreRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Featurestore", + "shortName": "get_featurestore" + }, + "description": "Sample for GetFeaturestore", + "file": "aiplatform_v1_generated_featurestore_service_get_featurestore_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_GetFeaturestore_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_get_featurestore_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient.get_featurestore", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.GetFeaturestore", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "GetFeaturestore" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetFeaturestoreRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Featurestore", + "shortName": "get_featurestore" + }, + "description": "Sample for GetFeaturestore", + "file": "aiplatform_v1_generated_featurestore_service_get_featurestore_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_GetFeaturestore_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_get_featurestore_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient.import_feature_values", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.ImportFeatureValues", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "ImportFeatureValues" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ImportFeatureValuesRequest" + }, + { + "name": "entity_type", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "import_feature_values" + }, + "description": "Sample for ImportFeatureValues", + "file": "aiplatform_v1_generated_featurestore_service_import_feature_values_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_ImportFeatureValues_async", + "segments": [ + { + "end": 57, + "start": 27, + "type": "FULL" + }, + { + "end": 57, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 47, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 54, + "start": 48, + "type": "REQUEST_EXECUTION" + }, + { + "end": 58, + "start": 55, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_import_feature_values_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient.import_feature_values", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.ImportFeatureValues", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "ImportFeatureValues" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ImportFeatureValuesRequest" + }, + { + "name": "entity_type", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "import_feature_values" + }, + "description": "Sample for ImportFeatureValues", + "file": "aiplatform_v1_generated_featurestore_service_import_feature_values_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_ImportFeatureValues_sync", + "segments": [ + { + "end": 57, + "start": 27, + "type": "FULL" + }, + { + "end": 57, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 47, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 54, + "start": 48, + "type": "REQUEST_EXECUTION" + }, + { + "end": 58, + "start": 55, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_import_feature_values_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient.list_entity_types", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.ListEntityTypes", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "ListEntityTypes" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListEntityTypesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.featurestore_service.pagers.ListEntityTypesAsyncPager", + "shortName": "list_entity_types" + }, + "description": "Sample for ListEntityTypes", + "file": "aiplatform_v1_generated_featurestore_service_list_entity_types_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_ListEntityTypes_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_list_entity_types_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient.list_entity_types", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.ListEntityTypes", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "ListEntityTypes" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListEntityTypesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.featurestore_service.pagers.ListEntityTypesPager", + "shortName": "list_entity_types" + }, + "description": "Sample for ListEntityTypes", + "file": "aiplatform_v1_generated_featurestore_service_list_entity_types_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_ListEntityTypes_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_list_entity_types_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient.list_features", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.ListFeatures", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "ListFeatures" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListFeaturesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.featurestore_service.pagers.ListFeaturesAsyncPager", + "shortName": "list_features" + }, + "description": "Sample for ListFeatures", + "file": "aiplatform_v1_generated_featurestore_service_list_features_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_ListFeatures_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_list_features_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient.list_features", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.ListFeatures", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "ListFeatures" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListFeaturesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.featurestore_service.pagers.ListFeaturesPager", + "shortName": "list_features" + }, + "description": "Sample for ListFeatures", + "file": "aiplatform_v1_generated_featurestore_service_list_features_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_ListFeatures_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_list_features_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient.list_featurestores", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.ListFeaturestores", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "ListFeaturestores" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListFeaturestoresRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.featurestore_service.pagers.ListFeaturestoresAsyncPager", + "shortName": "list_featurestores" + }, + "description": "Sample for ListFeaturestores", + "file": "aiplatform_v1_generated_featurestore_service_list_featurestores_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_ListFeaturestores_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_list_featurestores_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient.list_featurestores", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.ListFeaturestores", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "ListFeaturestores" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListFeaturestoresRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.featurestore_service.pagers.ListFeaturestoresPager", + "shortName": "list_featurestores" + }, + "description": "Sample for ListFeaturestores", + "file": "aiplatform_v1_generated_featurestore_service_list_featurestores_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_ListFeaturestores_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_list_featurestores_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient.search_features", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.SearchFeatures", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "SearchFeatures" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.SearchFeaturesRequest" + }, + { + "name": "location", + "type": "str" + }, + { + "name": "query", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.featurestore_service.pagers.SearchFeaturesAsyncPager", + "shortName": "search_features" + }, + "description": "Sample for SearchFeatures", + "file": "aiplatform_v1_generated_featurestore_service_search_features_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_SearchFeatures_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_search_features_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient.search_features", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.SearchFeatures", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "SearchFeatures" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.SearchFeaturesRequest" + }, + { + "name": "location", + "type": "str" + }, + { + "name": "query", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.featurestore_service.pagers.SearchFeaturesPager", + "shortName": "search_features" + }, + "description": "Sample for SearchFeatures", + "file": "aiplatform_v1_generated_featurestore_service_search_features_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_SearchFeatures_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_search_features_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient.update_entity_type", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.UpdateEntityType", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "UpdateEntityType" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UpdateEntityTypeRequest" + }, + { + "name": "entity_type", + "type": "google.cloud.aiplatform_v1.types.EntityType" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.EntityType", + "shortName": "update_entity_type" + }, + "description": "Sample for UpdateEntityType", + "file": "aiplatform_v1_generated_featurestore_service_update_entity_type_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_UpdateEntityType_async", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_update_entity_type_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient.update_entity_type", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.UpdateEntityType", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "UpdateEntityType" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UpdateEntityTypeRequest" + }, + { + "name": "entity_type", + "type": "google.cloud.aiplatform_v1.types.EntityType" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.EntityType", + "shortName": "update_entity_type" + }, + "description": "Sample for UpdateEntityType", + "file": "aiplatform_v1_generated_featurestore_service_update_entity_type_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_UpdateEntityType_sync", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_update_entity_type_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient.update_feature", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.UpdateFeature", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "UpdateFeature" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UpdateFeatureRequest" + }, + { + "name": "feature", + "type": "google.cloud.aiplatform_v1.types.Feature" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Feature", + "shortName": "update_feature" + }, + "description": "Sample for UpdateFeature", + "file": "aiplatform_v1_generated_featurestore_service_update_feature_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_UpdateFeature_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_update_feature_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient.update_feature", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.UpdateFeature", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "UpdateFeature" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UpdateFeatureRequest" + }, + { + "name": "feature", + "type": "google.cloud.aiplatform_v1.types.Feature" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Feature", + "shortName": "update_feature" + }, + "description": "Sample for UpdateFeature", + "file": "aiplatform_v1_generated_featurestore_service_update_feature_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_UpdateFeature_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_update_feature_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceAsyncClient.update_featurestore", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.UpdateFeaturestore", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "UpdateFeaturestore" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UpdateFeaturestoreRequest" + }, + { + "name": "featurestore", + "type": "google.cloud.aiplatform_v1.types.Featurestore" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "update_featurestore" + }, + "description": "Sample for UpdateFeaturestore", + "file": "aiplatform_v1_generated_featurestore_service_update_featurestore_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_UpdateFeaturestore_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_update_featurestore_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.FeaturestoreServiceClient.update_featurestore", + "method": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService.UpdateFeaturestore", + "service": { + "fullName": "google.cloud.aiplatform.v1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "UpdateFeaturestore" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UpdateFeaturestoreRequest" + }, + { + "name": "featurestore", + "type": "google.cloud.aiplatform_v1.types.Featurestore" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "update_featurestore" + }, + "description": "Sample for UpdateFeaturestore", + "file": "aiplatform_v1_generated_featurestore_service_update_featurestore_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_FeaturestoreService_UpdateFeaturestore_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_featurestore_service_update_featurestore_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.IndexEndpointServiceAsyncClient", + "shortName": "IndexEndpointServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.IndexEndpointServiceAsyncClient.create_index_endpoint", + "method": { + "fullName": "google.cloud.aiplatform.v1.IndexEndpointService.CreateIndexEndpoint", + "service": { + "fullName": "google.cloud.aiplatform.v1.IndexEndpointService", + "shortName": "IndexEndpointService" + }, + "shortName": "CreateIndexEndpoint" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateIndexEndpointRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "index_endpoint", + "type": "google.cloud.aiplatform_v1.types.IndexEndpoint" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "create_index_endpoint" + }, + "description": "Sample for CreateIndexEndpoint", + "file": "aiplatform_v1_generated_index_endpoint_service_create_index_endpoint_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_IndexEndpointService_CreateIndexEndpoint_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_index_endpoint_service_create_index_endpoint_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.IndexEndpointServiceClient", + "shortName": "IndexEndpointServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.IndexEndpointServiceClient.create_index_endpoint", + "method": { + "fullName": "google.cloud.aiplatform.v1.IndexEndpointService.CreateIndexEndpoint", + "service": { + "fullName": "google.cloud.aiplatform.v1.IndexEndpointService", + "shortName": "IndexEndpointService" + }, + "shortName": "CreateIndexEndpoint" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateIndexEndpointRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "index_endpoint", + "type": "google.cloud.aiplatform_v1.types.IndexEndpoint" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "create_index_endpoint" + }, + "description": "Sample for CreateIndexEndpoint", + "file": "aiplatform_v1_generated_index_endpoint_service_create_index_endpoint_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_IndexEndpointService_CreateIndexEndpoint_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_index_endpoint_service_create_index_endpoint_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.IndexEndpointServiceAsyncClient", + "shortName": "IndexEndpointServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.IndexEndpointServiceAsyncClient.delete_index_endpoint", + "method": { + "fullName": "google.cloud.aiplatform.v1.IndexEndpointService.DeleteIndexEndpoint", + "service": { + "fullName": "google.cloud.aiplatform.v1.IndexEndpointService", + "shortName": "IndexEndpointService" + }, + "shortName": "DeleteIndexEndpoint" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteIndexEndpointRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_index_endpoint" + }, + "description": "Sample for DeleteIndexEndpoint", + "file": "aiplatform_v1_generated_index_endpoint_service_delete_index_endpoint_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_IndexEndpointService_DeleteIndexEndpoint_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_index_endpoint_service_delete_index_endpoint_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.IndexEndpointServiceClient", + "shortName": "IndexEndpointServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.IndexEndpointServiceClient.delete_index_endpoint", + "method": { + "fullName": "google.cloud.aiplatform.v1.IndexEndpointService.DeleteIndexEndpoint", + "service": { + "fullName": "google.cloud.aiplatform.v1.IndexEndpointService", + "shortName": "IndexEndpointService" + }, + "shortName": "DeleteIndexEndpoint" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteIndexEndpointRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_index_endpoint" + }, + "description": "Sample for DeleteIndexEndpoint", + "file": "aiplatform_v1_generated_index_endpoint_service_delete_index_endpoint_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_IndexEndpointService_DeleteIndexEndpoint_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_index_endpoint_service_delete_index_endpoint_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.IndexEndpointServiceAsyncClient", + "shortName": "IndexEndpointServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.IndexEndpointServiceAsyncClient.deploy_index", + "method": { + "fullName": "google.cloud.aiplatform.v1.IndexEndpointService.DeployIndex", + "service": { + "fullName": "google.cloud.aiplatform.v1.IndexEndpointService", + "shortName": "IndexEndpointService" + }, + "shortName": "DeployIndex" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeployIndexRequest" + }, + { + "name": "index_endpoint", + "type": "str" + }, + { + "name": "deployed_index", + "type": "google.cloud.aiplatform_v1.types.DeployedIndex" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "deploy_index" + }, + "description": "Sample for DeployIndex", + "file": "aiplatform_v1_generated_index_endpoint_service_deploy_index_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_IndexEndpointService_DeployIndex_async", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_index_endpoint_service_deploy_index_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.IndexEndpointServiceClient", + "shortName": "IndexEndpointServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.IndexEndpointServiceClient.deploy_index", + "method": { + "fullName": "google.cloud.aiplatform.v1.IndexEndpointService.DeployIndex", + "service": { + "fullName": "google.cloud.aiplatform.v1.IndexEndpointService", + "shortName": "IndexEndpointService" + }, + "shortName": "DeployIndex" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeployIndexRequest" + }, + { + "name": "index_endpoint", + "type": "str" + }, + { + "name": "deployed_index", + "type": "google.cloud.aiplatform_v1.types.DeployedIndex" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "deploy_index" + }, + "description": "Sample for DeployIndex", + "file": "aiplatform_v1_generated_index_endpoint_service_deploy_index_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_IndexEndpointService_DeployIndex_sync", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_index_endpoint_service_deploy_index_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.IndexEndpointServiceAsyncClient", + "shortName": "IndexEndpointServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.IndexEndpointServiceAsyncClient.get_index_endpoint", + "method": { + "fullName": "google.cloud.aiplatform.v1.IndexEndpointService.GetIndexEndpoint", + "service": { + "fullName": "google.cloud.aiplatform.v1.IndexEndpointService", + "shortName": "IndexEndpointService" + }, + "shortName": "GetIndexEndpoint" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetIndexEndpointRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.IndexEndpoint", + "shortName": "get_index_endpoint" + }, + "description": "Sample for GetIndexEndpoint", + "file": "aiplatform_v1_generated_index_endpoint_service_get_index_endpoint_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_IndexEndpointService_GetIndexEndpoint_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_index_endpoint_service_get_index_endpoint_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.IndexEndpointServiceClient", + "shortName": "IndexEndpointServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.IndexEndpointServiceClient.get_index_endpoint", + "method": { + "fullName": "google.cloud.aiplatform.v1.IndexEndpointService.GetIndexEndpoint", + "service": { + "fullName": "google.cloud.aiplatform.v1.IndexEndpointService", + "shortName": "IndexEndpointService" + }, + "shortName": "GetIndexEndpoint" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetIndexEndpointRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.IndexEndpoint", + "shortName": "get_index_endpoint" + }, + "description": "Sample for GetIndexEndpoint", + "file": "aiplatform_v1_generated_index_endpoint_service_get_index_endpoint_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_IndexEndpointService_GetIndexEndpoint_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_index_endpoint_service_get_index_endpoint_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.IndexEndpointServiceAsyncClient", + "shortName": "IndexEndpointServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.IndexEndpointServiceAsyncClient.list_index_endpoints", + "method": { + "fullName": "google.cloud.aiplatform.v1.IndexEndpointService.ListIndexEndpoints", + "service": { + "fullName": "google.cloud.aiplatform.v1.IndexEndpointService", + "shortName": "IndexEndpointService" + }, + "shortName": "ListIndexEndpoints" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListIndexEndpointsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.index_endpoint_service.pagers.ListIndexEndpointsAsyncPager", + "shortName": "list_index_endpoints" + }, + "description": "Sample for ListIndexEndpoints", + "file": "aiplatform_v1_generated_index_endpoint_service_list_index_endpoints_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_IndexEndpointService_ListIndexEndpoints_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_index_endpoint_service_list_index_endpoints_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.IndexEndpointServiceClient", + "shortName": "IndexEndpointServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.IndexEndpointServiceClient.list_index_endpoints", + "method": { + "fullName": "google.cloud.aiplatform.v1.IndexEndpointService.ListIndexEndpoints", + "service": { + "fullName": "google.cloud.aiplatform.v1.IndexEndpointService", + "shortName": "IndexEndpointService" + }, + "shortName": "ListIndexEndpoints" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListIndexEndpointsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.index_endpoint_service.pagers.ListIndexEndpointsPager", + "shortName": "list_index_endpoints" + }, + "description": "Sample for ListIndexEndpoints", + "file": "aiplatform_v1_generated_index_endpoint_service_list_index_endpoints_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_IndexEndpointService_ListIndexEndpoints_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_index_endpoint_service_list_index_endpoints_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.IndexEndpointServiceAsyncClient", + "shortName": "IndexEndpointServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.IndexEndpointServiceAsyncClient.mutate_deployed_index", + "method": { + "fullName": "google.cloud.aiplatform.v1.IndexEndpointService.MutateDeployedIndex", + "service": { + "fullName": "google.cloud.aiplatform.v1.IndexEndpointService", + "shortName": "IndexEndpointService" + }, + "shortName": "MutateDeployedIndex" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.MutateDeployedIndexRequest" + }, + { + "name": "index_endpoint", + "type": "str" + }, + { + "name": "deployed_index", + "type": "google.cloud.aiplatform_v1.types.DeployedIndex" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "mutate_deployed_index" + }, + "description": "Sample for MutateDeployedIndex", + "file": "aiplatform_v1_generated_index_endpoint_service_mutate_deployed_index_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_IndexEndpointService_MutateDeployedIndex_async", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_index_endpoint_service_mutate_deployed_index_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.IndexEndpointServiceClient", + "shortName": "IndexEndpointServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.IndexEndpointServiceClient.mutate_deployed_index", + "method": { + "fullName": "google.cloud.aiplatform.v1.IndexEndpointService.MutateDeployedIndex", + "service": { + "fullName": "google.cloud.aiplatform.v1.IndexEndpointService", + "shortName": "IndexEndpointService" + }, + "shortName": "MutateDeployedIndex" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.MutateDeployedIndexRequest" + }, + { + "name": "index_endpoint", + "type": "str" + }, + { + "name": "deployed_index", + "type": "google.cloud.aiplatform_v1.types.DeployedIndex" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "mutate_deployed_index" + }, + "description": "Sample for MutateDeployedIndex", + "file": "aiplatform_v1_generated_index_endpoint_service_mutate_deployed_index_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_IndexEndpointService_MutateDeployedIndex_sync", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_index_endpoint_service_mutate_deployed_index_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.IndexEndpointServiceAsyncClient", + "shortName": "IndexEndpointServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.IndexEndpointServiceAsyncClient.undeploy_index", + "method": { + "fullName": "google.cloud.aiplatform.v1.IndexEndpointService.UndeployIndex", + "service": { + "fullName": "google.cloud.aiplatform.v1.IndexEndpointService", + "shortName": "IndexEndpointService" + }, + "shortName": "UndeployIndex" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UndeployIndexRequest" + }, + { + "name": "index_endpoint", + "type": "str" + }, + { + "name": "deployed_index_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "undeploy_index" + }, + "description": "Sample for UndeployIndex", + "file": "aiplatform_v1_generated_index_endpoint_service_undeploy_index_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_IndexEndpointService_UndeployIndex_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_index_endpoint_service_undeploy_index_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.IndexEndpointServiceClient", + "shortName": "IndexEndpointServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.IndexEndpointServiceClient.undeploy_index", + "method": { + "fullName": "google.cloud.aiplatform.v1.IndexEndpointService.UndeployIndex", + "service": { + "fullName": "google.cloud.aiplatform.v1.IndexEndpointService", + "shortName": "IndexEndpointService" + }, + "shortName": "UndeployIndex" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UndeployIndexRequest" + }, + { + "name": "index_endpoint", + "type": "str" + }, + { + "name": "deployed_index_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "undeploy_index" + }, + "description": "Sample for UndeployIndex", + "file": "aiplatform_v1_generated_index_endpoint_service_undeploy_index_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_IndexEndpointService_UndeployIndex_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_index_endpoint_service_undeploy_index_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.IndexEndpointServiceAsyncClient", + "shortName": "IndexEndpointServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.IndexEndpointServiceAsyncClient.update_index_endpoint", + "method": { + "fullName": "google.cloud.aiplatform.v1.IndexEndpointService.UpdateIndexEndpoint", + "service": { + "fullName": "google.cloud.aiplatform.v1.IndexEndpointService", + "shortName": "IndexEndpointService" + }, + "shortName": "UpdateIndexEndpoint" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UpdateIndexEndpointRequest" + }, + { + "name": "index_endpoint", + "type": "google.cloud.aiplatform_v1.types.IndexEndpoint" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.IndexEndpoint", + "shortName": "update_index_endpoint" + }, + "description": "Sample for UpdateIndexEndpoint", + "file": "aiplatform_v1_generated_index_endpoint_service_update_index_endpoint_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_IndexEndpointService_UpdateIndexEndpoint_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_index_endpoint_service_update_index_endpoint_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.IndexEndpointServiceClient", + "shortName": "IndexEndpointServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.IndexEndpointServiceClient.update_index_endpoint", + "method": { + "fullName": "google.cloud.aiplatform.v1.IndexEndpointService.UpdateIndexEndpoint", + "service": { + "fullName": "google.cloud.aiplatform.v1.IndexEndpointService", + "shortName": "IndexEndpointService" + }, + "shortName": "UpdateIndexEndpoint" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UpdateIndexEndpointRequest" + }, + { + "name": "index_endpoint", + "type": "google.cloud.aiplatform_v1.types.IndexEndpoint" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.IndexEndpoint", + "shortName": "update_index_endpoint" + }, + "description": "Sample for UpdateIndexEndpoint", + "file": "aiplatform_v1_generated_index_endpoint_service_update_index_endpoint_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_IndexEndpointService_UpdateIndexEndpoint_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_index_endpoint_service_update_index_endpoint_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.IndexServiceAsyncClient", + "shortName": "IndexServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.IndexServiceAsyncClient.create_index", + "method": { + "fullName": "google.cloud.aiplatform.v1.IndexService.CreateIndex", + "service": { + "fullName": "google.cloud.aiplatform.v1.IndexService", + "shortName": "IndexService" + }, + "shortName": "CreateIndex" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateIndexRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "index", + "type": "google.cloud.aiplatform_v1.types.Index" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "create_index" + }, + "description": "Sample for CreateIndex", + "file": "aiplatform_v1_generated_index_service_create_index_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_IndexService_CreateIndex_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_index_service_create_index_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.IndexServiceClient", + "shortName": "IndexServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.IndexServiceClient.create_index", + "method": { + "fullName": "google.cloud.aiplatform.v1.IndexService.CreateIndex", + "service": { + "fullName": "google.cloud.aiplatform.v1.IndexService", + "shortName": "IndexService" + }, + "shortName": "CreateIndex" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateIndexRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "index", + "type": "google.cloud.aiplatform_v1.types.Index" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "create_index" + }, + "description": "Sample for CreateIndex", + "file": "aiplatform_v1_generated_index_service_create_index_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_IndexService_CreateIndex_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_index_service_create_index_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.IndexServiceAsyncClient", + "shortName": "IndexServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.IndexServiceAsyncClient.delete_index", + "method": { + "fullName": "google.cloud.aiplatform.v1.IndexService.DeleteIndex", + "service": { + "fullName": "google.cloud.aiplatform.v1.IndexService", + "shortName": "IndexService" + }, + "shortName": "DeleteIndex" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteIndexRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_index" + }, + "description": "Sample for DeleteIndex", + "file": "aiplatform_v1_generated_index_service_delete_index_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_IndexService_DeleteIndex_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_index_service_delete_index_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.IndexServiceClient", + "shortName": "IndexServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.IndexServiceClient.delete_index", + "method": { + "fullName": "google.cloud.aiplatform.v1.IndexService.DeleteIndex", + "service": { + "fullName": "google.cloud.aiplatform.v1.IndexService", + "shortName": "IndexService" + }, + "shortName": "DeleteIndex" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteIndexRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_index" + }, + "description": "Sample for DeleteIndex", + "file": "aiplatform_v1_generated_index_service_delete_index_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_IndexService_DeleteIndex_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_index_service_delete_index_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.IndexServiceAsyncClient", + "shortName": "IndexServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.IndexServiceAsyncClient.get_index", + "method": { + "fullName": "google.cloud.aiplatform.v1.IndexService.GetIndex", + "service": { + "fullName": "google.cloud.aiplatform.v1.IndexService", + "shortName": "IndexService" + }, + "shortName": "GetIndex" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetIndexRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Index", + "shortName": "get_index" + }, + "description": "Sample for GetIndex", + "file": "aiplatform_v1_generated_index_service_get_index_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_IndexService_GetIndex_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_index_service_get_index_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.IndexServiceClient", + "shortName": "IndexServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.IndexServiceClient.get_index", + "method": { + "fullName": "google.cloud.aiplatform.v1.IndexService.GetIndex", + "service": { + "fullName": "google.cloud.aiplatform.v1.IndexService", + "shortName": "IndexService" + }, + "shortName": "GetIndex" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetIndexRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Index", + "shortName": "get_index" + }, + "description": "Sample for GetIndex", + "file": "aiplatform_v1_generated_index_service_get_index_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_IndexService_GetIndex_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_index_service_get_index_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.IndexServiceAsyncClient", + "shortName": "IndexServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.IndexServiceAsyncClient.list_indexes", + "method": { + "fullName": "google.cloud.aiplatform.v1.IndexService.ListIndexes", + "service": { + "fullName": "google.cloud.aiplatform.v1.IndexService", + "shortName": "IndexService" + }, + "shortName": "ListIndexes" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListIndexesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.index_service.pagers.ListIndexesAsyncPager", + "shortName": "list_indexes" + }, + "description": "Sample for ListIndexes", + "file": "aiplatform_v1_generated_index_service_list_indexes_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_IndexService_ListIndexes_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_index_service_list_indexes_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.IndexServiceClient", + "shortName": "IndexServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.IndexServiceClient.list_indexes", + "method": { + "fullName": "google.cloud.aiplatform.v1.IndexService.ListIndexes", + "service": { + "fullName": "google.cloud.aiplatform.v1.IndexService", + "shortName": "IndexService" + }, + "shortName": "ListIndexes" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListIndexesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.index_service.pagers.ListIndexesPager", + "shortName": "list_indexes" + }, + "description": "Sample for ListIndexes", + "file": "aiplatform_v1_generated_index_service_list_indexes_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_IndexService_ListIndexes_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_index_service_list_indexes_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.IndexServiceAsyncClient", + "shortName": "IndexServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.IndexServiceAsyncClient.update_index", + "method": { + "fullName": "google.cloud.aiplatform.v1.IndexService.UpdateIndex", + "service": { + "fullName": "google.cloud.aiplatform.v1.IndexService", + "shortName": "IndexService" + }, + "shortName": "UpdateIndex" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UpdateIndexRequest" + }, + { + "name": "index", + "type": "google.cloud.aiplatform_v1.types.Index" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "update_index" + }, + "description": "Sample for UpdateIndex", + "file": "aiplatform_v1_generated_index_service_update_index_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_IndexService_UpdateIndex_async", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_index_service_update_index_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.IndexServiceClient", + "shortName": "IndexServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.IndexServiceClient.update_index", + "method": { + "fullName": "google.cloud.aiplatform.v1.IndexService.UpdateIndex", + "service": { + "fullName": "google.cloud.aiplatform.v1.IndexService", + "shortName": "IndexService" + }, + "shortName": "UpdateIndex" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UpdateIndexRequest" + }, + { + "name": "index", + "type": "google.cloud.aiplatform_v1.types.Index" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "update_index" + }, + "description": "Sample for UpdateIndex", + "file": "aiplatform_v1_generated_index_service_update_index_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_IndexService_UpdateIndex_sync", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_index_service_update_index_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient.cancel_batch_prediction_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.CancelBatchPredictionJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "CancelBatchPredictionJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CancelBatchPredictionJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "cancel_batch_prediction_job" + }, + "description": "Sample for CancelBatchPredictionJob", + "file": "aiplatform_v1_generated_job_service_cancel_batch_prediction_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_CancelBatchPredictionJob_async", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_cancel_batch_prediction_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceClient.cancel_batch_prediction_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.CancelBatchPredictionJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "CancelBatchPredictionJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CancelBatchPredictionJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "cancel_batch_prediction_job" + }, + "description": "Sample for CancelBatchPredictionJob", + "file": "aiplatform_v1_generated_job_service_cancel_batch_prediction_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_CancelBatchPredictionJob_sync", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_cancel_batch_prediction_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient.cancel_custom_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.CancelCustomJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "CancelCustomJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CancelCustomJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "cancel_custom_job" + }, + "description": "Sample for CancelCustomJob", + "file": "aiplatform_v1_generated_job_service_cancel_custom_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_CancelCustomJob_async", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_cancel_custom_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceClient.cancel_custom_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.CancelCustomJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "CancelCustomJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CancelCustomJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "cancel_custom_job" + }, + "description": "Sample for CancelCustomJob", + "file": "aiplatform_v1_generated_job_service_cancel_custom_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_CancelCustomJob_sync", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_cancel_custom_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient.cancel_data_labeling_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.CancelDataLabelingJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "CancelDataLabelingJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CancelDataLabelingJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "cancel_data_labeling_job" + }, + "description": "Sample for CancelDataLabelingJob", + "file": "aiplatform_v1_generated_job_service_cancel_data_labeling_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_CancelDataLabelingJob_async", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_cancel_data_labeling_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceClient.cancel_data_labeling_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.CancelDataLabelingJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "CancelDataLabelingJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CancelDataLabelingJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "cancel_data_labeling_job" + }, + "description": "Sample for CancelDataLabelingJob", + "file": "aiplatform_v1_generated_job_service_cancel_data_labeling_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_CancelDataLabelingJob_sync", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_cancel_data_labeling_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient.cancel_hyperparameter_tuning_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.CancelHyperparameterTuningJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "CancelHyperparameterTuningJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CancelHyperparameterTuningJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "cancel_hyperparameter_tuning_job" + }, + "description": "Sample for CancelHyperparameterTuningJob", + "file": "aiplatform_v1_generated_job_service_cancel_hyperparameter_tuning_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_CancelHyperparameterTuningJob_async", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_cancel_hyperparameter_tuning_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceClient.cancel_hyperparameter_tuning_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.CancelHyperparameterTuningJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "CancelHyperparameterTuningJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CancelHyperparameterTuningJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "cancel_hyperparameter_tuning_job" + }, + "description": "Sample for CancelHyperparameterTuningJob", + "file": "aiplatform_v1_generated_job_service_cancel_hyperparameter_tuning_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_CancelHyperparameterTuningJob_sync", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_cancel_hyperparameter_tuning_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient.create_batch_prediction_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.CreateBatchPredictionJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "CreateBatchPredictionJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateBatchPredictionJobRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "batch_prediction_job", + "type": "google.cloud.aiplatform_v1.types.BatchPredictionJob" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.BatchPredictionJob", + "shortName": "create_batch_prediction_job" + }, + "description": "Sample for CreateBatchPredictionJob", + "file": "aiplatform_v1_generated_job_service_create_batch_prediction_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_CreateBatchPredictionJob_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_create_batch_prediction_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceClient.create_batch_prediction_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.CreateBatchPredictionJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "CreateBatchPredictionJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateBatchPredictionJobRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "batch_prediction_job", + "type": "google.cloud.aiplatform_v1.types.BatchPredictionJob" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.BatchPredictionJob", + "shortName": "create_batch_prediction_job" + }, + "description": "Sample for CreateBatchPredictionJob", + "file": "aiplatform_v1_generated_job_service_create_batch_prediction_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_CreateBatchPredictionJob_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_create_batch_prediction_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient.create_custom_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.CreateCustomJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "CreateCustomJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateCustomJobRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "custom_job", + "type": "google.cloud.aiplatform_v1.types.CustomJob" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.CustomJob", + "shortName": "create_custom_job" + }, + "description": "Sample for CreateCustomJob", + "file": "aiplatform_v1_generated_job_service_create_custom_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_CreateCustomJob_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_create_custom_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceClient.create_custom_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.CreateCustomJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "CreateCustomJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateCustomJobRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "custom_job", + "type": "google.cloud.aiplatform_v1.types.CustomJob" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.CustomJob", + "shortName": "create_custom_job" + }, + "description": "Sample for CreateCustomJob", + "file": "aiplatform_v1_generated_job_service_create_custom_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_CreateCustomJob_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_create_custom_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient.create_data_labeling_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.CreateDataLabelingJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "CreateDataLabelingJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateDataLabelingJobRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "data_labeling_job", + "type": "google.cloud.aiplatform_v1.types.DataLabelingJob" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.DataLabelingJob", + "shortName": "create_data_labeling_job" + }, + "description": "Sample for CreateDataLabelingJob", + "file": "aiplatform_v1_generated_job_service_create_data_labeling_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_CreateDataLabelingJob_async", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 47, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 48, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_create_data_labeling_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceClient.create_data_labeling_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.CreateDataLabelingJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "CreateDataLabelingJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateDataLabelingJobRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "data_labeling_job", + "type": "google.cloud.aiplatform_v1.types.DataLabelingJob" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.DataLabelingJob", + "shortName": "create_data_labeling_job" + }, + "description": "Sample for CreateDataLabelingJob", + "file": "aiplatform_v1_generated_job_service_create_data_labeling_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_CreateDataLabelingJob_sync", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 47, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 48, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_create_data_labeling_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient.create_hyperparameter_tuning_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.CreateHyperparameterTuningJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "CreateHyperparameterTuningJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateHyperparameterTuningJobRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "hyperparameter_tuning_job", + "type": "google.cloud.aiplatform_v1.types.HyperparameterTuningJob" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.HyperparameterTuningJob", + "shortName": "create_hyperparameter_tuning_job" + }, + "description": "Sample for CreateHyperparameterTuningJob", + "file": "aiplatform_v1_generated_job_service_create_hyperparameter_tuning_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_CreateHyperparameterTuningJob_async", + "segments": [ + { + "end": 56, + "start": 27, + "type": "FULL" + }, + { + "end": 56, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 50, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 53, + "start": 51, + "type": "REQUEST_EXECUTION" + }, + { + "end": 57, + "start": 54, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_create_hyperparameter_tuning_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceClient.create_hyperparameter_tuning_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.CreateHyperparameterTuningJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "CreateHyperparameterTuningJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateHyperparameterTuningJobRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "hyperparameter_tuning_job", + "type": "google.cloud.aiplatform_v1.types.HyperparameterTuningJob" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.HyperparameterTuningJob", + "shortName": "create_hyperparameter_tuning_job" + }, + "description": "Sample for CreateHyperparameterTuningJob", + "file": "aiplatform_v1_generated_job_service_create_hyperparameter_tuning_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_CreateHyperparameterTuningJob_sync", + "segments": [ + { + "end": 56, + "start": 27, + "type": "FULL" + }, + { + "end": 56, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 50, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 53, + "start": 51, + "type": "REQUEST_EXECUTION" + }, + { + "end": 57, + "start": 54, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_create_hyperparameter_tuning_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient.create_model_deployment_monitoring_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.CreateModelDeploymentMonitoringJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "CreateModelDeploymentMonitoringJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateModelDeploymentMonitoringJobRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "model_deployment_monitoring_job", + "type": "google.cloud.aiplatform_v1.types.ModelDeploymentMonitoringJob" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.ModelDeploymentMonitoringJob", + "shortName": "create_model_deployment_monitoring_job" + }, + "description": "Sample for CreateModelDeploymentMonitoringJob", + "file": "aiplatform_v1_generated_job_service_create_model_deployment_monitoring_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_CreateModelDeploymentMonitoringJob_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_create_model_deployment_monitoring_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceClient.create_model_deployment_monitoring_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.CreateModelDeploymentMonitoringJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "CreateModelDeploymentMonitoringJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateModelDeploymentMonitoringJobRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "model_deployment_monitoring_job", + "type": "google.cloud.aiplatform_v1.types.ModelDeploymentMonitoringJob" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.ModelDeploymentMonitoringJob", + "shortName": "create_model_deployment_monitoring_job" + }, + "description": "Sample for CreateModelDeploymentMonitoringJob", + "file": "aiplatform_v1_generated_job_service_create_model_deployment_monitoring_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_CreateModelDeploymentMonitoringJob_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_create_model_deployment_monitoring_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient.delete_batch_prediction_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.DeleteBatchPredictionJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "DeleteBatchPredictionJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteBatchPredictionJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_batch_prediction_job" + }, + "description": "Sample for DeleteBatchPredictionJob", + "file": "aiplatform_v1_generated_job_service_delete_batch_prediction_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_DeleteBatchPredictionJob_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_delete_batch_prediction_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceClient.delete_batch_prediction_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.DeleteBatchPredictionJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "DeleteBatchPredictionJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteBatchPredictionJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_batch_prediction_job" + }, + "description": "Sample for DeleteBatchPredictionJob", + "file": "aiplatform_v1_generated_job_service_delete_batch_prediction_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_DeleteBatchPredictionJob_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_delete_batch_prediction_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient.delete_custom_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.DeleteCustomJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "DeleteCustomJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteCustomJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_custom_job" + }, + "description": "Sample for DeleteCustomJob", + "file": "aiplatform_v1_generated_job_service_delete_custom_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_DeleteCustomJob_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_delete_custom_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceClient.delete_custom_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.DeleteCustomJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "DeleteCustomJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteCustomJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_custom_job" + }, + "description": "Sample for DeleteCustomJob", + "file": "aiplatform_v1_generated_job_service_delete_custom_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_DeleteCustomJob_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_delete_custom_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient.delete_data_labeling_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.DeleteDataLabelingJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "DeleteDataLabelingJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteDataLabelingJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_data_labeling_job" + }, + "description": "Sample for DeleteDataLabelingJob", + "file": "aiplatform_v1_generated_job_service_delete_data_labeling_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_DeleteDataLabelingJob_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_delete_data_labeling_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceClient.delete_data_labeling_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.DeleteDataLabelingJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "DeleteDataLabelingJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteDataLabelingJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_data_labeling_job" + }, + "description": "Sample for DeleteDataLabelingJob", + "file": "aiplatform_v1_generated_job_service_delete_data_labeling_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_DeleteDataLabelingJob_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_delete_data_labeling_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient.delete_hyperparameter_tuning_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.DeleteHyperparameterTuningJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "DeleteHyperparameterTuningJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteHyperparameterTuningJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_hyperparameter_tuning_job" + }, + "description": "Sample for DeleteHyperparameterTuningJob", + "file": "aiplatform_v1_generated_job_service_delete_hyperparameter_tuning_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_DeleteHyperparameterTuningJob_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_delete_hyperparameter_tuning_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceClient.delete_hyperparameter_tuning_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.DeleteHyperparameterTuningJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "DeleteHyperparameterTuningJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteHyperparameterTuningJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_hyperparameter_tuning_job" + }, + "description": "Sample for DeleteHyperparameterTuningJob", + "file": "aiplatform_v1_generated_job_service_delete_hyperparameter_tuning_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_DeleteHyperparameterTuningJob_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_delete_hyperparameter_tuning_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient.delete_model_deployment_monitoring_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.DeleteModelDeploymentMonitoringJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "DeleteModelDeploymentMonitoringJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteModelDeploymentMonitoringJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_model_deployment_monitoring_job" + }, + "description": "Sample for DeleteModelDeploymentMonitoringJob", + "file": "aiplatform_v1_generated_job_service_delete_model_deployment_monitoring_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_DeleteModelDeploymentMonitoringJob_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_delete_model_deployment_monitoring_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceClient.delete_model_deployment_monitoring_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.DeleteModelDeploymentMonitoringJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "DeleteModelDeploymentMonitoringJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteModelDeploymentMonitoringJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_model_deployment_monitoring_job" + }, + "description": "Sample for DeleteModelDeploymentMonitoringJob", + "file": "aiplatform_v1_generated_job_service_delete_model_deployment_monitoring_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_DeleteModelDeploymentMonitoringJob_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_delete_model_deployment_monitoring_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient.get_batch_prediction_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.GetBatchPredictionJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "GetBatchPredictionJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetBatchPredictionJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.BatchPredictionJob", + "shortName": "get_batch_prediction_job" + }, + "description": "Sample for GetBatchPredictionJob", + "file": "aiplatform_v1_generated_job_service_get_batch_prediction_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_GetBatchPredictionJob_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_get_batch_prediction_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceClient.get_batch_prediction_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.GetBatchPredictionJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "GetBatchPredictionJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetBatchPredictionJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.BatchPredictionJob", + "shortName": "get_batch_prediction_job" + }, + "description": "Sample for GetBatchPredictionJob", + "file": "aiplatform_v1_generated_job_service_get_batch_prediction_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_GetBatchPredictionJob_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_get_batch_prediction_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient.get_custom_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.GetCustomJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "GetCustomJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetCustomJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.CustomJob", + "shortName": "get_custom_job" + }, + "description": "Sample for GetCustomJob", + "file": "aiplatform_v1_generated_job_service_get_custom_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_GetCustomJob_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_get_custom_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceClient.get_custom_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.GetCustomJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "GetCustomJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetCustomJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.CustomJob", + "shortName": "get_custom_job" + }, + "description": "Sample for GetCustomJob", + "file": "aiplatform_v1_generated_job_service_get_custom_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_GetCustomJob_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_get_custom_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient.get_data_labeling_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.GetDataLabelingJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "GetDataLabelingJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetDataLabelingJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.DataLabelingJob", + "shortName": "get_data_labeling_job" + }, + "description": "Sample for GetDataLabelingJob", + "file": "aiplatform_v1_generated_job_service_get_data_labeling_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_GetDataLabelingJob_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_get_data_labeling_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceClient.get_data_labeling_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.GetDataLabelingJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "GetDataLabelingJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetDataLabelingJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.DataLabelingJob", + "shortName": "get_data_labeling_job" + }, + "description": "Sample for GetDataLabelingJob", + "file": "aiplatform_v1_generated_job_service_get_data_labeling_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_GetDataLabelingJob_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_get_data_labeling_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient.get_hyperparameter_tuning_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.GetHyperparameterTuningJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "GetHyperparameterTuningJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetHyperparameterTuningJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.HyperparameterTuningJob", + "shortName": "get_hyperparameter_tuning_job" + }, + "description": "Sample for GetHyperparameterTuningJob", + "file": "aiplatform_v1_generated_job_service_get_hyperparameter_tuning_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_GetHyperparameterTuningJob_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_get_hyperparameter_tuning_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceClient.get_hyperparameter_tuning_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.GetHyperparameterTuningJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "GetHyperparameterTuningJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetHyperparameterTuningJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.HyperparameterTuningJob", + "shortName": "get_hyperparameter_tuning_job" + }, + "description": "Sample for GetHyperparameterTuningJob", + "file": "aiplatform_v1_generated_job_service_get_hyperparameter_tuning_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_GetHyperparameterTuningJob_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_get_hyperparameter_tuning_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient.get_model_deployment_monitoring_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.GetModelDeploymentMonitoringJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "GetModelDeploymentMonitoringJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetModelDeploymentMonitoringJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.ModelDeploymentMonitoringJob", + "shortName": "get_model_deployment_monitoring_job" + }, + "description": "Sample for GetModelDeploymentMonitoringJob", + "file": "aiplatform_v1_generated_job_service_get_model_deployment_monitoring_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_GetModelDeploymentMonitoringJob_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_get_model_deployment_monitoring_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceClient.get_model_deployment_monitoring_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.GetModelDeploymentMonitoringJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "GetModelDeploymentMonitoringJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetModelDeploymentMonitoringJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.ModelDeploymentMonitoringJob", + "shortName": "get_model_deployment_monitoring_job" + }, + "description": "Sample for GetModelDeploymentMonitoringJob", + "file": "aiplatform_v1_generated_job_service_get_model_deployment_monitoring_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_GetModelDeploymentMonitoringJob_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_get_model_deployment_monitoring_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient.list_batch_prediction_jobs", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.ListBatchPredictionJobs", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "ListBatchPredictionJobs" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListBatchPredictionJobsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.job_service.pagers.ListBatchPredictionJobsAsyncPager", + "shortName": "list_batch_prediction_jobs" + }, + "description": "Sample for ListBatchPredictionJobs", + "file": "aiplatform_v1_generated_job_service_list_batch_prediction_jobs_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_ListBatchPredictionJobs_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_list_batch_prediction_jobs_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceClient.list_batch_prediction_jobs", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.ListBatchPredictionJobs", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "ListBatchPredictionJobs" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListBatchPredictionJobsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.job_service.pagers.ListBatchPredictionJobsPager", + "shortName": "list_batch_prediction_jobs" + }, + "description": "Sample for ListBatchPredictionJobs", + "file": "aiplatform_v1_generated_job_service_list_batch_prediction_jobs_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_ListBatchPredictionJobs_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_list_batch_prediction_jobs_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient.list_custom_jobs", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.ListCustomJobs", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "ListCustomJobs" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListCustomJobsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.job_service.pagers.ListCustomJobsAsyncPager", + "shortName": "list_custom_jobs" + }, + "description": "Sample for ListCustomJobs", + "file": "aiplatform_v1_generated_job_service_list_custom_jobs_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_ListCustomJobs_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_list_custom_jobs_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceClient.list_custom_jobs", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.ListCustomJobs", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "ListCustomJobs" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListCustomJobsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.job_service.pagers.ListCustomJobsPager", + "shortName": "list_custom_jobs" + }, + "description": "Sample for ListCustomJobs", + "file": "aiplatform_v1_generated_job_service_list_custom_jobs_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_ListCustomJobs_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_list_custom_jobs_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient.list_data_labeling_jobs", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.ListDataLabelingJobs", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "ListDataLabelingJobs" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListDataLabelingJobsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.job_service.pagers.ListDataLabelingJobsAsyncPager", + "shortName": "list_data_labeling_jobs" + }, + "description": "Sample for ListDataLabelingJobs", + "file": "aiplatform_v1_generated_job_service_list_data_labeling_jobs_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_ListDataLabelingJobs_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_list_data_labeling_jobs_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceClient.list_data_labeling_jobs", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.ListDataLabelingJobs", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "ListDataLabelingJobs" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListDataLabelingJobsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.job_service.pagers.ListDataLabelingJobsPager", + "shortName": "list_data_labeling_jobs" + }, + "description": "Sample for ListDataLabelingJobs", + "file": "aiplatform_v1_generated_job_service_list_data_labeling_jobs_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_ListDataLabelingJobs_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_list_data_labeling_jobs_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient.list_hyperparameter_tuning_jobs", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.ListHyperparameterTuningJobs", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "ListHyperparameterTuningJobs" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListHyperparameterTuningJobsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.job_service.pagers.ListHyperparameterTuningJobsAsyncPager", + "shortName": "list_hyperparameter_tuning_jobs" + }, + "description": "Sample for ListHyperparameterTuningJobs", + "file": "aiplatform_v1_generated_job_service_list_hyperparameter_tuning_jobs_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_ListHyperparameterTuningJobs_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_list_hyperparameter_tuning_jobs_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceClient.list_hyperparameter_tuning_jobs", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.ListHyperparameterTuningJobs", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "ListHyperparameterTuningJobs" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListHyperparameterTuningJobsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.job_service.pagers.ListHyperparameterTuningJobsPager", + "shortName": "list_hyperparameter_tuning_jobs" + }, + "description": "Sample for ListHyperparameterTuningJobs", + "file": "aiplatform_v1_generated_job_service_list_hyperparameter_tuning_jobs_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_ListHyperparameterTuningJobs_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_list_hyperparameter_tuning_jobs_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient.list_model_deployment_monitoring_jobs", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.ListModelDeploymentMonitoringJobs", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "ListModelDeploymentMonitoringJobs" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListModelDeploymentMonitoringJobsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.job_service.pagers.ListModelDeploymentMonitoringJobsAsyncPager", + "shortName": "list_model_deployment_monitoring_jobs" + }, + "description": "Sample for ListModelDeploymentMonitoringJobs", + "file": "aiplatform_v1_generated_job_service_list_model_deployment_monitoring_jobs_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_ListModelDeploymentMonitoringJobs_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_list_model_deployment_monitoring_jobs_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceClient.list_model_deployment_monitoring_jobs", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.ListModelDeploymentMonitoringJobs", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "ListModelDeploymentMonitoringJobs" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListModelDeploymentMonitoringJobsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.job_service.pagers.ListModelDeploymentMonitoringJobsPager", + "shortName": "list_model_deployment_monitoring_jobs" + }, + "description": "Sample for ListModelDeploymentMonitoringJobs", + "file": "aiplatform_v1_generated_job_service_list_model_deployment_monitoring_jobs_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_ListModelDeploymentMonitoringJobs_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_list_model_deployment_monitoring_jobs_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient.pause_model_deployment_monitoring_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.PauseModelDeploymentMonitoringJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "PauseModelDeploymentMonitoringJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.PauseModelDeploymentMonitoringJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "pause_model_deployment_monitoring_job" + }, + "description": "Sample for PauseModelDeploymentMonitoringJob", + "file": "aiplatform_v1_generated_job_service_pause_model_deployment_monitoring_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_PauseModelDeploymentMonitoringJob_async", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_pause_model_deployment_monitoring_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceClient.pause_model_deployment_monitoring_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.PauseModelDeploymentMonitoringJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "PauseModelDeploymentMonitoringJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.PauseModelDeploymentMonitoringJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "pause_model_deployment_monitoring_job" + }, + "description": "Sample for PauseModelDeploymentMonitoringJob", + "file": "aiplatform_v1_generated_job_service_pause_model_deployment_monitoring_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_PauseModelDeploymentMonitoringJob_sync", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_pause_model_deployment_monitoring_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient.resume_model_deployment_monitoring_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.ResumeModelDeploymentMonitoringJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "ResumeModelDeploymentMonitoringJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ResumeModelDeploymentMonitoringJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "resume_model_deployment_monitoring_job" + }, + "description": "Sample for ResumeModelDeploymentMonitoringJob", + "file": "aiplatform_v1_generated_job_service_resume_model_deployment_monitoring_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_ResumeModelDeploymentMonitoringJob_async", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_resume_model_deployment_monitoring_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceClient.resume_model_deployment_monitoring_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.ResumeModelDeploymentMonitoringJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "ResumeModelDeploymentMonitoringJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ResumeModelDeploymentMonitoringJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "resume_model_deployment_monitoring_job" + }, + "description": "Sample for ResumeModelDeploymentMonitoringJob", + "file": "aiplatform_v1_generated_job_service_resume_model_deployment_monitoring_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_ResumeModelDeploymentMonitoringJob_sync", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_resume_model_deployment_monitoring_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient.search_model_deployment_monitoring_stats_anomalies", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.SearchModelDeploymentMonitoringStatsAnomalies", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "SearchModelDeploymentMonitoringStatsAnomalies" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.SearchModelDeploymentMonitoringStatsAnomaliesRequest" + }, + { + "name": "model_deployment_monitoring_job", + "type": "str" + }, + { + "name": "deployed_model_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.job_service.pagers.SearchModelDeploymentMonitoringStatsAnomaliesAsyncPager", + "shortName": "search_model_deployment_monitoring_stats_anomalies" + }, + "description": "Sample for SearchModelDeploymentMonitoringStatsAnomalies", + "file": "aiplatform_v1_generated_job_service_search_model_deployment_monitoring_stats_anomalies_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_SearchModelDeploymentMonitoringStatsAnomalies_async", + "segments": [ + { + "end": 46, + "start": 27, + "type": "FULL" + }, + { + "end": 46, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 47, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_search_model_deployment_monitoring_stats_anomalies_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceClient.search_model_deployment_monitoring_stats_anomalies", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.SearchModelDeploymentMonitoringStatsAnomalies", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "SearchModelDeploymentMonitoringStatsAnomalies" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.SearchModelDeploymentMonitoringStatsAnomaliesRequest" + }, + { + "name": "model_deployment_monitoring_job", + "type": "str" + }, + { + "name": "deployed_model_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.job_service.pagers.SearchModelDeploymentMonitoringStatsAnomaliesPager", + "shortName": "search_model_deployment_monitoring_stats_anomalies" + }, + "description": "Sample for SearchModelDeploymentMonitoringStatsAnomalies", + "file": "aiplatform_v1_generated_job_service_search_model_deployment_monitoring_stats_anomalies_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_SearchModelDeploymentMonitoringStatsAnomalies_sync", + "segments": [ + { + "end": 46, + "start": 27, + "type": "FULL" + }, + { + "end": 46, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 47, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_search_model_deployment_monitoring_stats_anomalies_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceAsyncClient.update_model_deployment_monitoring_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.UpdateModelDeploymentMonitoringJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "UpdateModelDeploymentMonitoringJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UpdateModelDeploymentMonitoringJobRequest" + }, + { + "name": "model_deployment_monitoring_job", + "type": "google.cloud.aiplatform_v1.types.ModelDeploymentMonitoringJob" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "update_model_deployment_monitoring_job" + }, + "description": "Sample for UpdateModelDeploymentMonitoringJob", + "file": "aiplatform_v1_generated_job_service_update_model_deployment_monitoring_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_UpdateModelDeploymentMonitoringJob_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_update_model_deployment_monitoring_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.JobServiceClient.update_model_deployment_monitoring_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.JobService.UpdateModelDeploymentMonitoringJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.JobService", + "shortName": "JobService" + }, + "shortName": "UpdateModelDeploymentMonitoringJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UpdateModelDeploymentMonitoringJobRequest" + }, + { + "name": "model_deployment_monitoring_job", + "type": "google.cloud.aiplatform_v1.types.ModelDeploymentMonitoringJob" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "update_model_deployment_monitoring_job" + }, + "description": "Sample for UpdateModelDeploymentMonitoringJob", + "file": "aiplatform_v1_generated_job_service_update_model_deployment_monitoring_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_JobService_UpdateModelDeploymentMonitoringJob_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_job_service_update_model_deployment_monitoring_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient.add_context_artifacts_and_executions", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.AddContextArtifactsAndExecutions", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "AddContextArtifactsAndExecutions" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.AddContextArtifactsAndExecutionsRequest" + }, + { + "name": "context", + "type": "str" + }, + { + "name": "artifacts", + "type": "Sequence[str]" + }, + { + "name": "executions", + "type": "Sequence[str]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.AddContextArtifactsAndExecutionsResponse", + "shortName": "add_context_artifacts_and_executions" + }, + "description": "Sample for AddContextArtifactsAndExecutions", + "file": "aiplatform_v1_generated_metadata_service_add_context_artifacts_and_executions_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_AddContextArtifactsAndExecutions_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_add_context_artifacts_and_executions_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient.add_context_artifacts_and_executions", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.AddContextArtifactsAndExecutions", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "AddContextArtifactsAndExecutions" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.AddContextArtifactsAndExecutionsRequest" + }, + { + "name": "context", + "type": "str" + }, + { + "name": "artifacts", + "type": "Sequence[str]" + }, + { + "name": "executions", + "type": "Sequence[str]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.AddContextArtifactsAndExecutionsResponse", + "shortName": "add_context_artifacts_and_executions" + }, + "description": "Sample for AddContextArtifactsAndExecutions", + "file": "aiplatform_v1_generated_metadata_service_add_context_artifacts_and_executions_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_AddContextArtifactsAndExecutions_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_add_context_artifacts_and_executions_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient.add_context_children", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.AddContextChildren", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "AddContextChildren" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.AddContextChildrenRequest" + }, + { + "name": "context", + "type": "str" + }, + { + "name": "child_contexts", + "type": "Sequence[str]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.AddContextChildrenResponse", + "shortName": "add_context_children" + }, + "description": "Sample for AddContextChildren", + "file": "aiplatform_v1_generated_metadata_service_add_context_children_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_AddContextChildren_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_add_context_children_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient.add_context_children", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.AddContextChildren", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "AddContextChildren" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.AddContextChildrenRequest" + }, + { + "name": "context", + "type": "str" + }, + { + "name": "child_contexts", + "type": "Sequence[str]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.AddContextChildrenResponse", + "shortName": "add_context_children" + }, + "description": "Sample for AddContextChildren", + "file": "aiplatform_v1_generated_metadata_service_add_context_children_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_AddContextChildren_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_add_context_children_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient.add_execution_events", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.AddExecutionEvents", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "AddExecutionEvents" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.AddExecutionEventsRequest" + }, + { + "name": "execution", + "type": "str" + }, + { + "name": "events", + "type": "Sequence[google.cloud.aiplatform_v1.types.Event]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.AddExecutionEventsResponse", + "shortName": "add_execution_events" + }, + "description": "Sample for AddExecutionEvents", + "file": "aiplatform_v1_generated_metadata_service_add_execution_events_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_AddExecutionEvents_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_add_execution_events_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient.add_execution_events", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.AddExecutionEvents", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "AddExecutionEvents" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.AddExecutionEventsRequest" + }, + { + "name": "execution", + "type": "str" + }, + { + "name": "events", + "type": "Sequence[google.cloud.aiplatform_v1.types.Event]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.AddExecutionEventsResponse", + "shortName": "add_execution_events" + }, + "description": "Sample for AddExecutionEvents", + "file": "aiplatform_v1_generated_metadata_service_add_execution_events_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_AddExecutionEvents_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_add_execution_events_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient.create_artifact", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.CreateArtifact", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "CreateArtifact" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateArtifactRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "artifact", + "type": "google.cloud.aiplatform_v1.types.Artifact" + }, + { + "name": "artifact_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Artifact", + "shortName": "create_artifact" + }, + "description": "Sample for CreateArtifact", + "file": "aiplatform_v1_generated_metadata_service_create_artifact_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_CreateArtifact_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_create_artifact_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient.create_artifact", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.CreateArtifact", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "CreateArtifact" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateArtifactRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "artifact", + "type": "google.cloud.aiplatform_v1.types.Artifact" + }, + { + "name": "artifact_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Artifact", + "shortName": "create_artifact" + }, + "description": "Sample for CreateArtifact", + "file": "aiplatform_v1_generated_metadata_service_create_artifact_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_CreateArtifact_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_create_artifact_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient.create_context", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.CreateContext", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "CreateContext" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateContextRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "context", + "type": "google.cloud.aiplatform_v1.types.Context" + }, + { + "name": "context_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Context", + "shortName": "create_context" + }, + "description": "Sample for CreateContext", + "file": "aiplatform_v1_generated_metadata_service_create_context_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_CreateContext_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_create_context_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient.create_context", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.CreateContext", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "CreateContext" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateContextRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "context", + "type": "google.cloud.aiplatform_v1.types.Context" + }, + { + "name": "context_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Context", + "shortName": "create_context" + }, + "description": "Sample for CreateContext", + "file": "aiplatform_v1_generated_metadata_service_create_context_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_CreateContext_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_create_context_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient.create_execution", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.CreateExecution", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "CreateExecution" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateExecutionRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "execution", + "type": "google.cloud.aiplatform_v1.types.Execution" + }, + { + "name": "execution_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Execution", + "shortName": "create_execution" + }, + "description": "Sample for CreateExecution", + "file": "aiplatform_v1_generated_metadata_service_create_execution_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_CreateExecution_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_create_execution_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient.create_execution", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.CreateExecution", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "CreateExecution" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateExecutionRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "execution", + "type": "google.cloud.aiplatform_v1.types.Execution" + }, + { + "name": "execution_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Execution", + "shortName": "create_execution" + }, + "description": "Sample for CreateExecution", + "file": "aiplatform_v1_generated_metadata_service_create_execution_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_CreateExecution_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_create_execution_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient.create_metadata_schema", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.CreateMetadataSchema", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "CreateMetadataSchema" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateMetadataSchemaRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "metadata_schema", + "type": "google.cloud.aiplatform_v1.types.MetadataSchema" + }, + { + "name": "metadata_schema_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.MetadataSchema", + "shortName": "create_metadata_schema" + }, + "description": "Sample for CreateMetadataSchema", + "file": "aiplatform_v1_generated_metadata_service_create_metadata_schema_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_CreateMetadataSchema_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_create_metadata_schema_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient.create_metadata_schema", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.CreateMetadataSchema", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "CreateMetadataSchema" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateMetadataSchemaRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "metadata_schema", + "type": "google.cloud.aiplatform_v1.types.MetadataSchema" + }, + { + "name": "metadata_schema_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.MetadataSchema", + "shortName": "create_metadata_schema" + }, + "description": "Sample for CreateMetadataSchema", + "file": "aiplatform_v1_generated_metadata_service_create_metadata_schema_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_CreateMetadataSchema_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_create_metadata_schema_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient.create_metadata_store", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.CreateMetadataStore", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "CreateMetadataStore" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateMetadataStoreRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "metadata_store", + "type": "google.cloud.aiplatform_v1.types.MetadataStore" + }, + { + "name": "metadata_store_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "create_metadata_store" + }, + "description": "Sample for CreateMetadataStore", + "file": "aiplatform_v1_generated_metadata_service_create_metadata_store_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_CreateMetadataStore_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_create_metadata_store_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient.create_metadata_store", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.CreateMetadataStore", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "CreateMetadataStore" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateMetadataStoreRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "metadata_store", + "type": "google.cloud.aiplatform_v1.types.MetadataStore" + }, + { + "name": "metadata_store_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "create_metadata_store" + }, + "description": "Sample for CreateMetadataStore", + "file": "aiplatform_v1_generated_metadata_service_create_metadata_store_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_CreateMetadataStore_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_create_metadata_store_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient.delete_artifact", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.DeleteArtifact", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "DeleteArtifact" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteArtifactRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_artifact" + }, + "description": "Sample for DeleteArtifact", + "file": "aiplatform_v1_generated_metadata_service_delete_artifact_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_DeleteArtifact_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_delete_artifact_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient.delete_artifact", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.DeleteArtifact", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "DeleteArtifact" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteArtifactRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_artifact" + }, + "description": "Sample for DeleteArtifact", + "file": "aiplatform_v1_generated_metadata_service_delete_artifact_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_DeleteArtifact_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_delete_artifact_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient.delete_context", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.DeleteContext", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "DeleteContext" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteContextRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_context" + }, + "description": "Sample for DeleteContext", + "file": "aiplatform_v1_generated_metadata_service_delete_context_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_DeleteContext_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_delete_context_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient.delete_context", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.DeleteContext", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "DeleteContext" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteContextRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_context" + }, + "description": "Sample for DeleteContext", + "file": "aiplatform_v1_generated_metadata_service_delete_context_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_DeleteContext_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_delete_context_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient.delete_execution", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.DeleteExecution", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "DeleteExecution" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteExecutionRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_execution" + }, + "description": "Sample for DeleteExecution", + "file": "aiplatform_v1_generated_metadata_service_delete_execution_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_DeleteExecution_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_delete_execution_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient.delete_execution", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.DeleteExecution", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "DeleteExecution" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteExecutionRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_execution" + }, + "description": "Sample for DeleteExecution", + "file": "aiplatform_v1_generated_metadata_service_delete_execution_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_DeleteExecution_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_delete_execution_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient.delete_metadata_store", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.DeleteMetadataStore", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "DeleteMetadataStore" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteMetadataStoreRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_metadata_store" + }, + "description": "Sample for DeleteMetadataStore", + "file": "aiplatform_v1_generated_metadata_service_delete_metadata_store_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_DeleteMetadataStore_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_delete_metadata_store_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient.delete_metadata_store", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.DeleteMetadataStore", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "DeleteMetadataStore" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteMetadataStoreRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_metadata_store" + }, + "description": "Sample for DeleteMetadataStore", + "file": "aiplatform_v1_generated_metadata_service_delete_metadata_store_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_DeleteMetadataStore_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_delete_metadata_store_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient.get_artifact", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.GetArtifact", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "GetArtifact" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetArtifactRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Artifact", + "shortName": "get_artifact" + }, + "description": "Sample for GetArtifact", + "file": "aiplatform_v1_generated_metadata_service_get_artifact_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_GetArtifact_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_get_artifact_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient.get_artifact", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.GetArtifact", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "GetArtifact" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetArtifactRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Artifact", + "shortName": "get_artifact" + }, + "description": "Sample for GetArtifact", + "file": "aiplatform_v1_generated_metadata_service_get_artifact_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_GetArtifact_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_get_artifact_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient.get_context", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.GetContext", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "GetContext" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetContextRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Context", + "shortName": "get_context" + }, + "description": "Sample for GetContext", + "file": "aiplatform_v1_generated_metadata_service_get_context_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_GetContext_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_get_context_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient.get_context", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.GetContext", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "GetContext" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetContextRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Context", + "shortName": "get_context" + }, + "description": "Sample for GetContext", + "file": "aiplatform_v1_generated_metadata_service_get_context_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_GetContext_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_get_context_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient.get_execution", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.GetExecution", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "GetExecution" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetExecutionRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Execution", + "shortName": "get_execution" + }, + "description": "Sample for GetExecution", + "file": "aiplatform_v1_generated_metadata_service_get_execution_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_GetExecution_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_get_execution_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient.get_execution", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.GetExecution", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "GetExecution" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetExecutionRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Execution", + "shortName": "get_execution" + }, + "description": "Sample for GetExecution", + "file": "aiplatform_v1_generated_metadata_service_get_execution_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_GetExecution_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_get_execution_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient.get_metadata_schema", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.GetMetadataSchema", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "GetMetadataSchema" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetMetadataSchemaRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.MetadataSchema", + "shortName": "get_metadata_schema" + }, + "description": "Sample for GetMetadataSchema", + "file": "aiplatform_v1_generated_metadata_service_get_metadata_schema_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_GetMetadataSchema_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_get_metadata_schema_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient.get_metadata_schema", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.GetMetadataSchema", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "GetMetadataSchema" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetMetadataSchemaRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.MetadataSchema", + "shortName": "get_metadata_schema" + }, + "description": "Sample for GetMetadataSchema", + "file": "aiplatform_v1_generated_metadata_service_get_metadata_schema_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_GetMetadataSchema_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_get_metadata_schema_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient.get_metadata_store", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.GetMetadataStore", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "GetMetadataStore" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetMetadataStoreRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.MetadataStore", + "shortName": "get_metadata_store" + }, + "description": "Sample for GetMetadataStore", + "file": "aiplatform_v1_generated_metadata_service_get_metadata_store_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_GetMetadataStore_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_get_metadata_store_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient.get_metadata_store", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.GetMetadataStore", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "GetMetadataStore" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetMetadataStoreRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.MetadataStore", + "shortName": "get_metadata_store" + }, + "description": "Sample for GetMetadataStore", + "file": "aiplatform_v1_generated_metadata_service_get_metadata_store_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_GetMetadataStore_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_get_metadata_store_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient.list_artifacts", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.ListArtifacts", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "ListArtifacts" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListArtifactsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.metadata_service.pagers.ListArtifactsAsyncPager", + "shortName": "list_artifacts" + }, + "description": "Sample for ListArtifacts", + "file": "aiplatform_v1_generated_metadata_service_list_artifacts_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_ListArtifacts_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_list_artifacts_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient.list_artifacts", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.ListArtifacts", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "ListArtifacts" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListArtifactsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.metadata_service.pagers.ListArtifactsPager", + "shortName": "list_artifacts" + }, + "description": "Sample for ListArtifacts", + "file": "aiplatform_v1_generated_metadata_service_list_artifacts_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_ListArtifacts_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_list_artifacts_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient.list_contexts", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.ListContexts", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "ListContexts" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListContextsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.metadata_service.pagers.ListContextsAsyncPager", + "shortName": "list_contexts" + }, + "description": "Sample for ListContexts", + "file": "aiplatform_v1_generated_metadata_service_list_contexts_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_ListContexts_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_list_contexts_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient.list_contexts", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.ListContexts", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "ListContexts" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListContextsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.metadata_service.pagers.ListContextsPager", + "shortName": "list_contexts" + }, + "description": "Sample for ListContexts", + "file": "aiplatform_v1_generated_metadata_service_list_contexts_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_ListContexts_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_list_contexts_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient.list_executions", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.ListExecutions", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "ListExecutions" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListExecutionsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.metadata_service.pagers.ListExecutionsAsyncPager", + "shortName": "list_executions" + }, + "description": "Sample for ListExecutions", + "file": "aiplatform_v1_generated_metadata_service_list_executions_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_ListExecutions_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_list_executions_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient.list_executions", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.ListExecutions", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "ListExecutions" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListExecutionsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.metadata_service.pagers.ListExecutionsPager", + "shortName": "list_executions" + }, + "description": "Sample for ListExecutions", + "file": "aiplatform_v1_generated_metadata_service_list_executions_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_ListExecutions_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_list_executions_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient.list_metadata_schemas", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.ListMetadataSchemas", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "ListMetadataSchemas" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListMetadataSchemasRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.metadata_service.pagers.ListMetadataSchemasAsyncPager", + "shortName": "list_metadata_schemas" + }, + "description": "Sample for ListMetadataSchemas", + "file": "aiplatform_v1_generated_metadata_service_list_metadata_schemas_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_ListMetadataSchemas_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_list_metadata_schemas_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient.list_metadata_schemas", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.ListMetadataSchemas", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "ListMetadataSchemas" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListMetadataSchemasRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.metadata_service.pagers.ListMetadataSchemasPager", + "shortName": "list_metadata_schemas" + }, + "description": "Sample for ListMetadataSchemas", + "file": "aiplatform_v1_generated_metadata_service_list_metadata_schemas_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_ListMetadataSchemas_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_list_metadata_schemas_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient.list_metadata_stores", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.ListMetadataStores", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "ListMetadataStores" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListMetadataStoresRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.metadata_service.pagers.ListMetadataStoresAsyncPager", + "shortName": "list_metadata_stores" + }, + "description": "Sample for ListMetadataStores", + "file": "aiplatform_v1_generated_metadata_service_list_metadata_stores_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_ListMetadataStores_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_list_metadata_stores_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient.list_metadata_stores", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.ListMetadataStores", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "ListMetadataStores" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListMetadataStoresRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.metadata_service.pagers.ListMetadataStoresPager", + "shortName": "list_metadata_stores" + }, + "description": "Sample for ListMetadataStores", + "file": "aiplatform_v1_generated_metadata_service_list_metadata_stores_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_ListMetadataStores_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_list_metadata_stores_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient.purge_artifacts", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.PurgeArtifacts", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "PurgeArtifacts" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.PurgeArtifactsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "purge_artifacts" + }, + "description": "Sample for PurgeArtifacts", + "file": "aiplatform_v1_generated_metadata_service_purge_artifacts_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_PurgeArtifacts_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_purge_artifacts_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient.purge_artifacts", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.PurgeArtifacts", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "PurgeArtifacts" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.PurgeArtifactsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "purge_artifacts" + }, + "description": "Sample for PurgeArtifacts", + "file": "aiplatform_v1_generated_metadata_service_purge_artifacts_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_PurgeArtifacts_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_purge_artifacts_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient.purge_contexts", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.PurgeContexts", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "PurgeContexts" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.PurgeContextsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "purge_contexts" + }, + "description": "Sample for PurgeContexts", + "file": "aiplatform_v1_generated_metadata_service_purge_contexts_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_PurgeContexts_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_purge_contexts_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient.purge_contexts", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.PurgeContexts", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "PurgeContexts" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.PurgeContextsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "purge_contexts" + }, + "description": "Sample for PurgeContexts", + "file": "aiplatform_v1_generated_metadata_service_purge_contexts_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_PurgeContexts_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_purge_contexts_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient.purge_executions", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.PurgeExecutions", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "PurgeExecutions" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.PurgeExecutionsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "purge_executions" + }, + "description": "Sample for PurgeExecutions", + "file": "aiplatform_v1_generated_metadata_service_purge_executions_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_PurgeExecutions_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_purge_executions_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient.purge_executions", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.PurgeExecutions", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "PurgeExecutions" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.PurgeExecutionsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "purge_executions" + }, + "description": "Sample for PurgeExecutions", + "file": "aiplatform_v1_generated_metadata_service_purge_executions_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_PurgeExecutions_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_purge_executions_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient.query_artifact_lineage_subgraph", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.QueryArtifactLineageSubgraph", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "QueryArtifactLineageSubgraph" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.QueryArtifactLineageSubgraphRequest" + }, + { + "name": "artifact", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.LineageSubgraph", + "shortName": "query_artifact_lineage_subgraph" + }, + "description": "Sample for QueryArtifactLineageSubgraph", + "file": "aiplatform_v1_generated_metadata_service_query_artifact_lineage_subgraph_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_QueryArtifactLineageSubgraph_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_query_artifact_lineage_subgraph_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient.query_artifact_lineage_subgraph", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.QueryArtifactLineageSubgraph", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "QueryArtifactLineageSubgraph" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.QueryArtifactLineageSubgraphRequest" + }, + { + "name": "artifact", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.LineageSubgraph", + "shortName": "query_artifact_lineage_subgraph" + }, + "description": "Sample for QueryArtifactLineageSubgraph", + "file": "aiplatform_v1_generated_metadata_service_query_artifact_lineage_subgraph_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_QueryArtifactLineageSubgraph_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_query_artifact_lineage_subgraph_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient.query_context_lineage_subgraph", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.QueryContextLineageSubgraph", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "QueryContextLineageSubgraph" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.QueryContextLineageSubgraphRequest" + }, + { + "name": "context", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.LineageSubgraph", + "shortName": "query_context_lineage_subgraph" + }, + "description": "Sample for QueryContextLineageSubgraph", + "file": "aiplatform_v1_generated_metadata_service_query_context_lineage_subgraph_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_QueryContextLineageSubgraph_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_query_context_lineage_subgraph_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient.query_context_lineage_subgraph", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.QueryContextLineageSubgraph", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "QueryContextLineageSubgraph" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.QueryContextLineageSubgraphRequest" + }, + { + "name": "context", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.LineageSubgraph", + "shortName": "query_context_lineage_subgraph" + }, + "description": "Sample for QueryContextLineageSubgraph", + "file": "aiplatform_v1_generated_metadata_service_query_context_lineage_subgraph_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_QueryContextLineageSubgraph_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_query_context_lineage_subgraph_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient.query_execution_inputs_and_outputs", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.QueryExecutionInputsAndOutputs", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "QueryExecutionInputsAndOutputs" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.QueryExecutionInputsAndOutputsRequest" + }, + { + "name": "execution", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.LineageSubgraph", + "shortName": "query_execution_inputs_and_outputs" + }, + "description": "Sample for QueryExecutionInputsAndOutputs", + "file": "aiplatform_v1_generated_metadata_service_query_execution_inputs_and_outputs_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_QueryExecutionInputsAndOutputs_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_query_execution_inputs_and_outputs_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient.query_execution_inputs_and_outputs", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.QueryExecutionInputsAndOutputs", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "QueryExecutionInputsAndOutputs" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.QueryExecutionInputsAndOutputsRequest" + }, + { + "name": "execution", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.LineageSubgraph", + "shortName": "query_execution_inputs_and_outputs" + }, + "description": "Sample for QueryExecutionInputsAndOutputs", + "file": "aiplatform_v1_generated_metadata_service_query_execution_inputs_and_outputs_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_QueryExecutionInputsAndOutputs_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_query_execution_inputs_and_outputs_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient.update_artifact", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.UpdateArtifact", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "UpdateArtifact" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UpdateArtifactRequest" + }, + { + "name": "artifact", + "type": "google.cloud.aiplatform_v1.types.Artifact" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Artifact", + "shortName": "update_artifact" + }, + "description": "Sample for UpdateArtifact", + "file": "aiplatform_v1_generated_metadata_service_update_artifact_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_UpdateArtifact_async", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_update_artifact_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient.update_artifact", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.UpdateArtifact", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "UpdateArtifact" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UpdateArtifactRequest" + }, + { + "name": "artifact", + "type": "google.cloud.aiplatform_v1.types.Artifact" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Artifact", + "shortName": "update_artifact" + }, + "description": "Sample for UpdateArtifact", + "file": "aiplatform_v1_generated_metadata_service_update_artifact_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_UpdateArtifact_sync", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_update_artifact_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient.update_context", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.UpdateContext", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "UpdateContext" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UpdateContextRequest" + }, + { + "name": "context", + "type": "google.cloud.aiplatform_v1.types.Context" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Context", + "shortName": "update_context" + }, + "description": "Sample for UpdateContext", + "file": "aiplatform_v1_generated_metadata_service_update_context_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_UpdateContext_async", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_update_context_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient.update_context", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.UpdateContext", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "UpdateContext" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UpdateContextRequest" + }, + { + "name": "context", + "type": "google.cloud.aiplatform_v1.types.Context" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Context", + "shortName": "update_context" + }, + "description": "Sample for UpdateContext", + "file": "aiplatform_v1_generated_metadata_service_update_context_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_UpdateContext_sync", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_update_context_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceAsyncClient.update_execution", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.UpdateExecution", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "UpdateExecution" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UpdateExecutionRequest" + }, + { + "name": "execution", + "type": "google.cloud.aiplatform_v1.types.Execution" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Execution", + "shortName": "update_execution" + }, + "description": "Sample for UpdateExecution", + "file": "aiplatform_v1_generated_metadata_service_update_execution_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_UpdateExecution_async", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_update_execution_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.MetadataServiceClient.update_execution", + "method": { + "fullName": "google.cloud.aiplatform.v1.MetadataService.UpdateExecution", + "service": { + "fullName": "google.cloud.aiplatform.v1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "UpdateExecution" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UpdateExecutionRequest" + }, + { + "name": "execution", + "type": "google.cloud.aiplatform_v1.types.Execution" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Execution", + "shortName": "update_execution" + }, + "description": "Sample for UpdateExecution", + "file": "aiplatform_v1_generated_metadata_service_update_execution_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MetadataService_UpdateExecution_sync", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_metadata_service_update_execution_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.MigrationServiceAsyncClient", + "shortName": "MigrationServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.MigrationServiceAsyncClient.batch_migrate_resources", + "method": { + "fullName": "google.cloud.aiplatform.v1.MigrationService.BatchMigrateResources", + "service": { + "fullName": "google.cloud.aiplatform.v1.MigrationService", + "shortName": "MigrationService" + }, + "shortName": "BatchMigrateResources" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.BatchMigrateResourcesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "migrate_resource_requests", + "type": "Sequence[google.cloud.aiplatform_v1.types.MigrateResourceRequest]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "batch_migrate_resources" + }, + "description": "Sample for BatchMigrateResources", + "file": "aiplatform_v1_generated_migration_service_batch_migrate_resources_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MigrationService_BatchMigrateResources_async", + "segments": [ + { + "end": 54, + "start": 27, + "type": "FULL" + }, + { + "end": 54, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 51, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 55, + "start": 52, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_migration_service_batch_migrate_resources_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.MigrationServiceClient", + "shortName": "MigrationServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.MigrationServiceClient.batch_migrate_resources", + "method": { + "fullName": "google.cloud.aiplatform.v1.MigrationService.BatchMigrateResources", + "service": { + "fullName": "google.cloud.aiplatform.v1.MigrationService", + "shortName": "MigrationService" + }, + "shortName": "BatchMigrateResources" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.BatchMigrateResourcesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "migrate_resource_requests", + "type": "Sequence[google.cloud.aiplatform_v1.types.MigrateResourceRequest]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "batch_migrate_resources" + }, + "description": "Sample for BatchMigrateResources", + "file": "aiplatform_v1_generated_migration_service_batch_migrate_resources_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MigrationService_BatchMigrateResources_sync", + "segments": [ + { + "end": 54, + "start": 27, + "type": "FULL" + }, + { + "end": 54, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 51, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 55, + "start": 52, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_migration_service_batch_migrate_resources_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.MigrationServiceAsyncClient", + "shortName": "MigrationServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.MigrationServiceAsyncClient.search_migratable_resources", + "method": { + "fullName": "google.cloud.aiplatform.v1.MigrationService.SearchMigratableResources", + "service": { + "fullName": "google.cloud.aiplatform.v1.MigrationService", + "shortName": "MigrationService" + }, + "shortName": "SearchMigratableResources" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.SearchMigratableResourcesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.migration_service.pagers.SearchMigratableResourcesAsyncPager", + "shortName": "search_migratable_resources" + }, + "description": "Sample for SearchMigratableResources", + "file": "aiplatform_v1_generated_migration_service_search_migratable_resources_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MigrationService_SearchMigratableResources_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_migration_service_search_migratable_resources_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.MigrationServiceClient", + "shortName": "MigrationServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.MigrationServiceClient.search_migratable_resources", + "method": { + "fullName": "google.cloud.aiplatform.v1.MigrationService.SearchMigratableResources", + "service": { + "fullName": "google.cloud.aiplatform.v1.MigrationService", + "shortName": "MigrationService" + }, + "shortName": "SearchMigratableResources" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.SearchMigratableResourcesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.migration_service.pagers.SearchMigratableResourcesPager", + "shortName": "search_migratable_resources" + }, + "description": "Sample for SearchMigratableResources", + "file": "aiplatform_v1_generated_migration_service_search_migratable_resources_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_MigrationService_SearchMigratableResources_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_migration_service_search_migratable_resources_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.ModelServiceAsyncClient", + "shortName": "ModelServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.ModelServiceAsyncClient.delete_model_version", + "method": { + "fullName": "google.cloud.aiplatform.v1.ModelService.DeleteModelVersion", + "service": { + "fullName": "google.cloud.aiplatform.v1.ModelService", + "shortName": "ModelService" + }, + "shortName": "DeleteModelVersion" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteModelVersionRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_model_version" + }, + "description": "Sample for DeleteModelVersion", + "file": "aiplatform_v1_generated_model_service_delete_model_version_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_ModelService_DeleteModelVersion_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_model_service_delete_model_version_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.ModelServiceClient", + "shortName": "ModelServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.ModelServiceClient.delete_model_version", + "method": { + "fullName": "google.cloud.aiplatform.v1.ModelService.DeleteModelVersion", + "service": { + "fullName": "google.cloud.aiplatform.v1.ModelService", + "shortName": "ModelService" + }, + "shortName": "DeleteModelVersion" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteModelVersionRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_model_version" + }, + "description": "Sample for DeleteModelVersion", + "file": "aiplatform_v1_generated_model_service_delete_model_version_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_ModelService_DeleteModelVersion_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_model_service_delete_model_version_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.ModelServiceAsyncClient", + "shortName": "ModelServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.ModelServiceAsyncClient.delete_model", + "method": { + "fullName": "google.cloud.aiplatform.v1.ModelService.DeleteModel", + "service": { + "fullName": "google.cloud.aiplatform.v1.ModelService", + "shortName": "ModelService" + }, + "shortName": "DeleteModel" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteModelRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_model" + }, + "description": "Sample for DeleteModel", + "file": "aiplatform_v1_generated_model_service_delete_model_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_ModelService_DeleteModel_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_model_service_delete_model_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.ModelServiceClient", + "shortName": "ModelServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.ModelServiceClient.delete_model", + "method": { + "fullName": "google.cloud.aiplatform.v1.ModelService.DeleteModel", + "service": { + "fullName": "google.cloud.aiplatform.v1.ModelService", + "shortName": "ModelService" + }, + "shortName": "DeleteModel" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteModelRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_model" + }, + "description": "Sample for DeleteModel", + "file": "aiplatform_v1_generated_model_service_delete_model_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_ModelService_DeleteModel_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_model_service_delete_model_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.ModelServiceAsyncClient", + "shortName": "ModelServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.ModelServiceAsyncClient.export_model", + "method": { + "fullName": "google.cloud.aiplatform.v1.ModelService.ExportModel", + "service": { + "fullName": "google.cloud.aiplatform.v1.ModelService", + "shortName": "ModelService" + }, + "shortName": "ExportModel" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ExportModelRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "output_config", + "type": "google.cloud.aiplatform_v1.types.ExportModelRequest.OutputConfig" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "export_model" + }, + "description": "Sample for ExportModel", + "file": "aiplatform_v1_generated_model_service_export_model_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_ModelService_ExportModel_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_model_service_export_model_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.ModelServiceClient", + "shortName": "ModelServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.ModelServiceClient.export_model", + "method": { + "fullName": "google.cloud.aiplatform.v1.ModelService.ExportModel", + "service": { + "fullName": "google.cloud.aiplatform.v1.ModelService", + "shortName": "ModelService" + }, + "shortName": "ExportModel" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ExportModelRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "output_config", + "type": "google.cloud.aiplatform_v1.types.ExportModelRequest.OutputConfig" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "export_model" + }, + "description": "Sample for ExportModel", + "file": "aiplatform_v1_generated_model_service_export_model_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_ModelService_ExportModel_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_model_service_export_model_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.ModelServiceAsyncClient", + "shortName": "ModelServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.ModelServiceAsyncClient.get_model_evaluation_slice", + "method": { + "fullName": "google.cloud.aiplatform.v1.ModelService.GetModelEvaluationSlice", + "service": { + "fullName": "google.cloud.aiplatform.v1.ModelService", + "shortName": "ModelService" + }, + "shortName": "GetModelEvaluationSlice" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetModelEvaluationSliceRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.ModelEvaluationSlice", + "shortName": "get_model_evaluation_slice" + }, + "description": "Sample for GetModelEvaluationSlice", + "file": "aiplatform_v1_generated_model_service_get_model_evaluation_slice_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_ModelService_GetModelEvaluationSlice_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_model_service_get_model_evaluation_slice_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.ModelServiceClient", + "shortName": "ModelServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.ModelServiceClient.get_model_evaluation_slice", + "method": { + "fullName": "google.cloud.aiplatform.v1.ModelService.GetModelEvaluationSlice", + "service": { + "fullName": "google.cloud.aiplatform.v1.ModelService", + "shortName": "ModelService" + }, + "shortName": "GetModelEvaluationSlice" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetModelEvaluationSliceRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.ModelEvaluationSlice", + "shortName": "get_model_evaluation_slice" + }, + "description": "Sample for GetModelEvaluationSlice", + "file": "aiplatform_v1_generated_model_service_get_model_evaluation_slice_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_ModelService_GetModelEvaluationSlice_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_model_service_get_model_evaluation_slice_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.ModelServiceAsyncClient", + "shortName": "ModelServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.ModelServiceAsyncClient.get_model_evaluation", + "method": { + "fullName": "google.cloud.aiplatform.v1.ModelService.GetModelEvaluation", + "service": { + "fullName": "google.cloud.aiplatform.v1.ModelService", + "shortName": "ModelService" + }, + "shortName": "GetModelEvaluation" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetModelEvaluationRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.ModelEvaluation", + "shortName": "get_model_evaluation" + }, + "description": "Sample for GetModelEvaluation", + "file": "aiplatform_v1_generated_model_service_get_model_evaluation_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_ModelService_GetModelEvaluation_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_model_service_get_model_evaluation_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.ModelServiceClient", + "shortName": "ModelServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.ModelServiceClient.get_model_evaluation", + "method": { + "fullName": "google.cloud.aiplatform.v1.ModelService.GetModelEvaluation", + "service": { + "fullName": "google.cloud.aiplatform.v1.ModelService", + "shortName": "ModelService" + }, + "shortName": "GetModelEvaluation" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetModelEvaluationRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.ModelEvaluation", + "shortName": "get_model_evaluation" + }, + "description": "Sample for GetModelEvaluation", + "file": "aiplatform_v1_generated_model_service_get_model_evaluation_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_ModelService_GetModelEvaluation_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_model_service_get_model_evaluation_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.ModelServiceAsyncClient", + "shortName": "ModelServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.ModelServiceAsyncClient.get_model", + "method": { + "fullName": "google.cloud.aiplatform.v1.ModelService.GetModel", + "service": { + "fullName": "google.cloud.aiplatform.v1.ModelService", + "shortName": "ModelService" + }, + "shortName": "GetModel" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetModelRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Model", + "shortName": "get_model" + }, + "description": "Sample for GetModel", + "file": "aiplatform_v1_generated_model_service_get_model_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_ModelService_GetModel_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_model_service_get_model_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.ModelServiceClient", + "shortName": "ModelServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.ModelServiceClient.get_model", + "method": { + "fullName": "google.cloud.aiplatform.v1.ModelService.GetModel", + "service": { + "fullName": "google.cloud.aiplatform.v1.ModelService", + "shortName": "ModelService" + }, + "shortName": "GetModel" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetModelRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Model", + "shortName": "get_model" + }, + "description": "Sample for GetModel", + "file": "aiplatform_v1_generated_model_service_get_model_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_ModelService_GetModel_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_model_service_get_model_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.ModelServiceAsyncClient", + "shortName": "ModelServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.ModelServiceAsyncClient.import_model_evaluation", + "method": { + "fullName": "google.cloud.aiplatform.v1.ModelService.ImportModelEvaluation", + "service": { + "fullName": "google.cloud.aiplatform.v1.ModelService", + "shortName": "ModelService" + }, + "shortName": "ImportModelEvaluation" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ImportModelEvaluationRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "model_evaluation", + "type": "google.cloud.aiplatform_v1.types.ModelEvaluation" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.ModelEvaluation", + "shortName": "import_model_evaluation" + }, + "description": "Sample for ImportModelEvaluation", + "file": "aiplatform_v1_generated_model_service_import_model_evaluation_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_ModelService_ImportModelEvaluation_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_model_service_import_model_evaluation_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.ModelServiceClient", + "shortName": "ModelServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.ModelServiceClient.import_model_evaluation", + "method": { + "fullName": "google.cloud.aiplatform.v1.ModelService.ImportModelEvaluation", + "service": { + "fullName": "google.cloud.aiplatform.v1.ModelService", + "shortName": "ModelService" + }, + "shortName": "ImportModelEvaluation" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ImportModelEvaluationRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "model_evaluation", + "type": "google.cloud.aiplatform_v1.types.ModelEvaluation" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.ModelEvaluation", + "shortName": "import_model_evaluation" + }, + "description": "Sample for ImportModelEvaluation", + "file": "aiplatform_v1_generated_model_service_import_model_evaluation_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_ModelService_ImportModelEvaluation_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_model_service_import_model_evaluation_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.ModelServiceAsyncClient", + "shortName": "ModelServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.ModelServiceAsyncClient.list_model_evaluation_slices", + "method": { + "fullName": "google.cloud.aiplatform.v1.ModelService.ListModelEvaluationSlices", + "service": { + "fullName": "google.cloud.aiplatform.v1.ModelService", + "shortName": "ModelService" + }, + "shortName": "ListModelEvaluationSlices" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListModelEvaluationSlicesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.model_service.pagers.ListModelEvaluationSlicesAsyncPager", + "shortName": "list_model_evaluation_slices" + }, + "description": "Sample for ListModelEvaluationSlices", + "file": "aiplatform_v1_generated_model_service_list_model_evaluation_slices_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_ModelService_ListModelEvaluationSlices_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_model_service_list_model_evaluation_slices_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.ModelServiceClient", + "shortName": "ModelServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.ModelServiceClient.list_model_evaluation_slices", + "method": { + "fullName": "google.cloud.aiplatform.v1.ModelService.ListModelEvaluationSlices", + "service": { + "fullName": "google.cloud.aiplatform.v1.ModelService", + "shortName": "ModelService" + }, + "shortName": "ListModelEvaluationSlices" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListModelEvaluationSlicesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.model_service.pagers.ListModelEvaluationSlicesPager", + "shortName": "list_model_evaluation_slices" + }, + "description": "Sample for ListModelEvaluationSlices", + "file": "aiplatform_v1_generated_model_service_list_model_evaluation_slices_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_ModelService_ListModelEvaluationSlices_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_model_service_list_model_evaluation_slices_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.ModelServiceAsyncClient", + "shortName": "ModelServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.ModelServiceAsyncClient.list_model_evaluations", + "method": { + "fullName": "google.cloud.aiplatform.v1.ModelService.ListModelEvaluations", + "service": { + "fullName": "google.cloud.aiplatform.v1.ModelService", + "shortName": "ModelService" + }, + "shortName": "ListModelEvaluations" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListModelEvaluationsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.model_service.pagers.ListModelEvaluationsAsyncPager", + "shortName": "list_model_evaluations" + }, + "description": "Sample for ListModelEvaluations", + "file": "aiplatform_v1_generated_model_service_list_model_evaluations_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_ModelService_ListModelEvaluations_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_model_service_list_model_evaluations_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.ModelServiceClient", + "shortName": "ModelServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.ModelServiceClient.list_model_evaluations", + "method": { + "fullName": "google.cloud.aiplatform.v1.ModelService.ListModelEvaluations", + "service": { + "fullName": "google.cloud.aiplatform.v1.ModelService", + "shortName": "ModelService" + }, + "shortName": "ListModelEvaluations" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListModelEvaluationsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.model_service.pagers.ListModelEvaluationsPager", + "shortName": "list_model_evaluations" + }, + "description": "Sample for ListModelEvaluations", + "file": "aiplatform_v1_generated_model_service_list_model_evaluations_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_ModelService_ListModelEvaluations_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_model_service_list_model_evaluations_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.ModelServiceAsyncClient", + "shortName": "ModelServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.ModelServiceAsyncClient.list_model_versions", + "method": { + "fullName": "google.cloud.aiplatform.v1.ModelService.ListModelVersions", + "service": { + "fullName": "google.cloud.aiplatform.v1.ModelService", + "shortName": "ModelService" + }, + "shortName": "ListModelVersions" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListModelVersionsRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.model_service.pagers.ListModelVersionsAsyncPager", + "shortName": "list_model_versions" + }, + "description": "Sample for ListModelVersions", + "file": "aiplatform_v1_generated_model_service_list_model_versions_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_ModelService_ListModelVersions_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_model_service_list_model_versions_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.ModelServiceClient", + "shortName": "ModelServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.ModelServiceClient.list_model_versions", + "method": { + "fullName": "google.cloud.aiplatform.v1.ModelService.ListModelVersions", + "service": { + "fullName": "google.cloud.aiplatform.v1.ModelService", + "shortName": "ModelService" + }, + "shortName": "ListModelVersions" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListModelVersionsRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.model_service.pagers.ListModelVersionsPager", + "shortName": "list_model_versions" + }, + "description": "Sample for ListModelVersions", + "file": "aiplatform_v1_generated_model_service_list_model_versions_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_ModelService_ListModelVersions_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_model_service_list_model_versions_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.ModelServiceAsyncClient", + "shortName": "ModelServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.ModelServiceAsyncClient.list_models", + "method": { + "fullName": "google.cloud.aiplatform.v1.ModelService.ListModels", + "service": { + "fullName": "google.cloud.aiplatform.v1.ModelService", + "shortName": "ModelService" + }, + "shortName": "ListModels" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListModelsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.model_service.pagers.ListModelsAsyncPager", + "shortName": "list_models" + }, + "description": "Sample for ListModels", + "file": "aiplatform_v1_generated_model_service_list_models_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_ModelService_ListModels_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_model_service_list_models_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.ModelServiceClient", + "shortName": "ModelServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.ModelServiceClient.list_models", + "method": { + "fullName": "google.cloud.aiplatform.v1.ModelService.ListModels", + "service": { + "fullName": "google.cloud.aiplatform.v1.ModelService", + "shortName": "ModelService" + }, + "shortName": "ListModels" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListModelsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.model_service.pagers.ListModelsPager", + "shortName": "list_models" + }, + "description": "Sample for ListModels", + "file": "aiplatform_v1_generated_model_service_list_models_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_ModelService_ListModels_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_model_service_list_models_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.ModelServiceAsyncClient", + "shortName": "ModelServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.ModelServiceAsyncClient.merge_version_aliases", + "method": { + "fullName": "google.cloud.aiplatform.v1.ModelService.MergeVersionAliases", + "service": { + "fullName": "google.cloud.aiplatform.v1.ModelService", + "shortName": "ModelService" + }, + "shortName": "MergeVersionAliases" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.MergeVersionAliasesRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "version_aliases", + "type": "Sequence[str]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Model", + "shortName": "merge_version_aliases" + }, + "description": "Sample for MergeVersionAliases", + "file": "aiplatform_v1_generated_model_service_merge_version_aliases_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_ModelService_MergeVersionAliases_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_model_service_merge_version_aliases_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.ModelServiceClient", + "shortName": "ModelServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.ModelServiceClient.merge_version_aliases", + "method": { + "fullName": "google.cloud.aiplatform.v1.ModelService.MergeVersionAliases", + "service": { + "fullName": "google.cloud.aiplatform.v1.ModelService", + "shortName": "ModelService" + }, + "shortName": "MergeVersionAliases" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.MergeVersionAliasesRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "version_aliases", + "type": "Sequence[str]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Model", + "shortName": "merge_version_aliases" + }, + "description": "Sample for MergeVersionAliases", + "file": "aiplatform_v1_generated_model_service_merge_version_aliases_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_ModelService_MergeVersionAliases_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_model_service_merge_version_aliases_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.ModelServiceAsyncClient", + "shortName": "ModelServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.ModelServiceAsyncClient.update_model", + "method": { + "fullName": "google.cloud.aiplatform.v1.ModelService.UpdateModel", + "service": { + "fullName": "google.cloud.aiplatform.v1.ModelService", + "shortName": "ModelService" + }, + "shortName": "UpdateModel" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UpdateModelRequest" + }, + { + "name": "model", + "type": "google.cloud.aiplatform_v1.types.Model" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Model", + "shortName": "update_model" + }, + "description": "Sample for UpdateModel", + "file": "aiplatform_v1_generated_model_service_update_model_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_ModelService_UpdateModel_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_model_service_update_model_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.ModelServiceClient", + "shortName": "ModelServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.ModelServiceClient.update_model", + "method": { + "fullName": "google.cloud.aiplatform.v1.ModelService.UpdateModel", + "service": { + "fullName": "google.cloud.aiplatform.v1.ModelService", + "shortName": "ModelService" + }, + "shortName": "UpdateModel" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UpdateModelRequest" + }, + { + "name": "model", + "type": "google.cloud.aiplatform_v1.types.Model" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Model", + "shortName": "update_model" + }, + "description": "Sample for UpdateModel", + "file": "aiplatform_v1_generated_model_service_update_model_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_ModelService_UpdateModel_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_model_service_update_model_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.ModelServiceAsyncClient", + "shortName": "ModelServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.ModelServiceAsyncClient.upload_model", + "method": { + "fullName": "google.cloud.aiplatform.v1.ModelService.UploadModel", + "service": { + "fullName": "google.cloud.aiplatform.v1.ModelService", + "shortName": "ModelService" + }, + "shortName": "UploadModel" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UploadModelRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "model", + "type": "google.cloud.aiplatform_v1.types.Model" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "upload_model" + }, + "description": "Sample for UploadModel", + "file": "aiplatform_v1_generated_model_service_upload_model_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_ModelService_UploadModel_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_model_service_upload_model_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.ModelServiceClient", + "shortName": "ModelServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.ModelServiceClient.upload_model", + "method": { + "fullName": "google.cloud.aiplatform.v1.ModelService.UploadModel", + "service": { + "fullName": "google.cloud.aiplatform.v1.ModelService", + "shortName": "ModelService" + }, + "shortName": "UploadModel" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UploadModelRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "model", + "type": "google.cloud.aiplatform_v1.types.Model" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "upload_model" + }, + "description": "Sample for UploadModel", + "file": "aiplatform_v1_generated_model_service_upload_model_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_ModelService_UploadModel_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_model_service_upload_model_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.PipelineServiceAsyncClient", + "shortName": "PipelineServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.PipelineServiceAsyncClient.cancel_pipeline_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.PipelineService.CancelPipelineJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "CancelPipelineJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CancelPipelineJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "cancel_pipeline_job" + }, + "description": "Sample for CancelPipelineJob", + "file": "aiplatform_v1_generated_pipeline_service_cancel_pipeline_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_PipelineService_CancelPipelineJob_async", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_pipeline_service_cancel_pipeline_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.PipelineServiceClient", + "shortName": "PipelineServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.PipelineServiceClient.cancel_pipeline_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.PipelineService.CancelPipelineJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "CancelPipelineJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CancelPipelineJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "cancel_pipeline_job" + }, + "description": "Sample for CancelPipelineJob", + "file": "aiplatform_v1_generated_pipeline_service_cancel_pipeline_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_PipelineService_CancelPipelineJob_sync", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_pipeline_service_cancel_pipeline_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.PipelineServiceAsyncClient", + "shortName": "PipelineServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.PipelineServiceAsyncClient.cancel_training_pipeline", + "method": { + "fullName": "google.cloud.aiplatform.v1.PipelineService.CancelTrainingPipeline", + "service": { + "fullName": "google.cloud.aiplatform.v1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "CancelTrainingPipeline" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CancelTrainingPipelineRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "cancel_training_pipeline" + }, + "description": "Sample for CancelTrainingPipeline", + "file": "aiplatform_v1_generated_pipeline_service_cancel_training_pipeline_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_PipelineService_CancelTrainingPipeline_async", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_pipeline_service_cancel_training_pipeline_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.PipelineServiceClient", + "shortName": "PipelineServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.PipelineServiceClient.cancel_training_pipeline", + "method": { + "fullName": "google.cloud.aiplatform.v1.PipelineService.CancelTrainingPipeline", + "service": { + "fullName": "google.cloud.aiplatform.v1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "CancelTrainingPipeline" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CancelTrainingPipelineRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "cancel_training_pipeline" + }, + "description": "Sample for CancelTrainingPipeline", + "file": "aiplatform_v1_generated_pipeline_service_cancel_training_pipeline_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_PipelineService_CancelTrainingPipeline_sync", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_pipeline_service_cancel_training_pipeline_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.PipelineServiceAsyncClient", + "shortName": "PipelineServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.PipelineServiceAsyncClient.create_pipeline_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.PipelineService.CreatePipelineJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "CreatePipelineJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreatePipelineJobRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "pipeline_job", + "type": "google.cloud.aiplatform_v1.types.PipelineJob" + }, + { + "name": "pipeline_job_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.PipelineJob", + "shortName": "create_pipeline_job" + }, + "description": "Sample for CreatePipelineJob", + "file": "aiplatform_v1_generated_pipeline_service_create_pipeline_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_PipelineService_CreatePipelineJob_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_pipeline_service_create_pipeline_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.PipelineServiceClient", + "shortName": "PipelineServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.PipelineServiceClient.create_pipeline_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.PipelineService.CreatePipelineJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "CreatePipelineJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreatePipelineJobRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "pipeline_job", + "type": "google.cloud.aiplatform_v1.types.PipelineJob" + }, + { + "name": "pipeline_job_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.PipelineJob", + "shortName": "create_pipeline_job" + }, + "description": "Sample for CreatePipelineJob", + "file": "aiplatform_v1_generated_pipeline_service_create_pipeline_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_PipelineService_CreatePipelineJob_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_pipeline_service_create_pipeline_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.PipelineServiceAsyncClient", + "shortName": "PipelineServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.PipelineServiceAsyncClient.create_training_pipeline", + "method": { + "fullName": "google.cloud.aiplatform.v1.PipelineService.CreateTrainingPipeline", + "service": { + "fullName": "google.cloud.aiplatform.v1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "CreateTrainingPipeline" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateTrainingPipelineRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "training_pipeline", + "type": "google.cloud.aiplatform_v1.types.TrainingPipeline" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.TrainingPipeline", + "shortName": "create_training_pipeline" + }, + "description": "Sample for CreateTrainingPipeline", + "file": "aiplatform_v1_generated_pipeline_service_create_training_pipeline_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_PipelineService_CreateTrainingPipeline_async", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 47, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "start": 48, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_pipeline_service_create_training_pipeline_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.PipelineServiceClient", + "shortName": "PipelineServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.PipelineServiceClient.create_training_pipeline", + "method": { + "fullName": "google.cloud.aiplatform.v1.PipelineService.CreateTrainingPipeline", + "service": { + "fullName": "google.cloud.aiplatform.v1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "CreateTrainingPipeline" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateTrainingPipelineRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "training_pipeline", + "type": "google.cloud.aiplatform_v1.types.TrainingPipeline" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.TrainingPipeline", + "shortName": "create_training_pipeline" + }, + "description": "Sample for CreateTrainingPipeline", + "file": "aiplatform_v1_generated_pipeline_service_create_training_pipeline_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_PipelineService_CreateTrainingPipeline_sync", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 47, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "start": 48, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_pipeline_service_create_training_pipeline_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.PipelineServiceAsyncClient", + "shortName": "PipelineServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.PipelineServiceAsyncClient.delete_pipeline_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.PipelineService.DeletePipelineJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "DeletePipelineJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeletePipelineJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_pipeline_job" + }, + "description": "Sample for DeletePipelineJob", + "file": "aiplatform_v1_generated_pipeline_service_delete_pipeline_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_PipelineService_DeletePipelineJob_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_pipeline_service_delete_pipeline_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.PipelineServiceClient", + "shortName": "PipelineServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.PipelineServiceClient.delete_pipeline_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.PipelineService.DeletePipelineJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "DeletePipelineJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeletePipelineJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_pipeline_job" + }, + "description": "Sample for DeletePipelineJob", + "file": "aiplatform_v1_generated_pipeline_service_delete_pipeline_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_PipelineService_DeletePipelineJob_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_pipeline_service_delete_pipeline_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.PipelineServiceAsyncClient", + "shortName": "PipelineServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.PipelineServiceAsyncClient.delete_training_pipeline", + "method": { + "fullName": "google.cloud.aiplatform.v1.PipelineService.DeleteTrainingPipeline", + "service": { + "fullName": "google.cloud.aiplatform.v1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "DeleteTrainingPipeline" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteTrainingPipelineRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_training_pipeline" + }, + "description": "Sample for DeleteTrainingPipeline", + "file": "aiplatform_v1_generated_pipeline_service_delete_training_pipeline_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_PipelineService_DeleteTrainingPipeline_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_pipeline_service_delete_training_pipeline_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.PipelineServiceClient", + "shortName": "PipelineServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.PipelineServiceClient.delete_training_pipeline", + "method": { + "fullName": "google.cloud.aiplatform.v1.PipelineService.DeleteTrainingPipeline", + "service": { + "fullName": "google.cloud.aiplatform.v1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "DeleteTrainingPipeline" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteTrainingPipelineRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_training_pipeline" + }, + "description": "Sample for DeleteTrainingPipeline", + "file": "aiplatform_v1_generated_pipeline_service_delete_training_pipeline_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_PipelineService_DeleteTrainingPipeline_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_pipeline_service_delete_training_pipeline_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.PipelineServiceAsyncClient", + "shortName": "PipelineServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.PipelineServiceAsyncClient.get_pipeline_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.PipelineService.GetPipelineJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "GetPipelineJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetPipelineJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.PipelineJob", + "shortName": "get_pipeline_job" + }, + "description": "Sample for GetPipelineJob", + "file": "aiplatform_v1_generated_pipeline_service_get_pipeline_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_PipelineService_GetPipelineJob_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_pipeline_service_get_pipeline_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.PipelineServiceClient", + "shortName": "PipelineServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.PipelineServiceClient.get_pipeline_job", + "method": { + "fullName": "google.cloud.aiplatform.v1.PipelineService.GetPipelineJob", + "service": { + "fullName": "google.cloud.aiplatform.v1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "GetPipelineJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetPipelineJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.PipelineJob", + "shortName": "get_pipeline_job" + }, + "description": "Sample for GetPipelineJob", + "file": "aiplatform_v1_generated_pipeline_service_get_pipeline_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_PipelineService_GetPipelineJob_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_pipeline_service_get_pipeline_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.PipelineServiceAsyncClient", + "shortName": "PipelineServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.PipelineServiceAsyncClient.get_training_pipeline", + "method": { + "fullName": "google.cloud.aiplatform.v1.PipelineService.GetTrainingPipeline", + "service": { + "fullName": "google.cloud.aiplatform.v1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "GetTrainingPipeline" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetTrainingPipelineRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.TrainingPipeline", + "shortName": "get_training_pipeline" + }, + "description": "Sample for GetTrainingPipeline", + "file": "aiplatform_v1_generated_pipeline_service_get_training_pipeline_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_PipelineService_GetTrainingPipeline_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_pipeline_service_get_training_pipeline_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.PipelineServiceClient", + "shortName": "PipelineServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.PipelineServiceClient.get_training_pipeline", + "method": { + "fullName": "google.cloud.aiplatform.v1.PipelineService.GetTrainingPipeline", + "service": { + "fullName": "google.cloud.aiplatform.v1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "GetTrainingPipeline" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetTrainingPipelineRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.TrainingPipeline", + "shortName": "get_training_pipeline" + }, + "description": "Sample for GetTrainingPipeline", + "file": "aiplatform_v1_generated_pipeline_service_get_training_pipeline_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_PipelineService_GetTrainingPipeline_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_pipeline_service_get_training_pipeline_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.PipelineServiceAsyncClient", + "shortName": "PipelineServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.PipelineServiceAsyncClient.list_pipeline_jobs", + "method": { + "fullName": "google.cloud.aiplatform.v1.PipelineService.ListPipelineJobs", + "service": { + "fullName": "google.cloud.aiplatform.v1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "ListPipelineJobs" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListPipelineJobsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.pipeline_service.pagers.ListPipelineJobsAsyncPager", + "shortName": "list_pipeline_jobs" + }, + "description": "Sample for ListPipelineJobs", + "file": "aiplatform_v1_generated_pipeline_service_list_pipeline_jobs_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_PipelineService_ListPipelineJobs_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_pipeline_service_list_pipeline_jobs_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.PipelineServiceClient", + "shortName": "PipelineServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.PipelineServiceClient.list_pipeline_jobs", + "method": { + "fullName": "google.cloud.aiplatform.v1.PipelineService.ListPipelineJobs", + "service": { + "fullName": "google.cloud.aiplatform.v1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "ListPipelineJobs" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListPipelineJobsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.pipeline_service.pagers.ListPipelineJobsPager", + "shortName": "list_pipeline_jobs" + }, + "description": "Sample for ListPipelineJobs", + "file": "aiplatform_v1_generated_pipeline_service_list_pipeline_jobs_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_PipelineService_ListPipelineJobs_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_pipeline_service_list_pipeline_jobs_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.PipelineServiceAsyncClient", + "shortName": "PipelineServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.PipelineServiceAsyncClient.list_training_pipelines", + "method": { + "fullName": "google.cloud.aiplatform.v1.PipelineService.ListTrainingPipelines", + "service": { + "fullName": "google.cloud.aiplatform.v1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "ListTrainingPipelines" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListTrainingPipelinesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.pipeline_service.pagers.ListTrainingPipelinesAsyncPager", + "shortName": "list_training_pipelines" + }, + "description": "Sample for ListTrainingPipelines", + "file": "aiplatform_v1_generated_pipeline_service_list_training_pipelines_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_PipelineService_ListTrainingPipelines_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_pipeline_service_list_training_pipelines_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.PipelineServiceClient", + "shortName": "PipelineServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.PipelineServiceClient.list_training_pipelines", + "method": { + "fullName": "google.cloud.aiplatform.v1.PipelineService.ListTrainingPipelines", + "service": { + "fullName": "google.cloud.aiplatform.v1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "ListTrainingPipelines" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListTrainingPipelinesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.pipeline_service.pagers.ListTrainingPipelinesPager", + "shortName": "list_training_pipelines" + }, + "description": "Sample for ListTrainingPipelines", + "file": "aiplatform_v1_generated_pipeline_service_list_training_pipelines_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_PipelineService_ListTrainingPipelines_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_pipeline_service_list_training_pipelines_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.PredictionServiceAsyncClient", + "shortName": "PredictionServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.PredictionServiceAsyncClient.explain", + "method": { + "fullName": "google.cloud.aiplatform.v1.PredictionService.Explain", + "service": { + "fullName": "google.cloud.aiplatform.v1.PredictionService", + "shortName": "PredictionService" + }, + "shortName": "Explain" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ExplainRequest" + }, + { + "name": "endpoint", + "type": "str" + }, + { + "name": "instances", + "type": "Sequence[google.protobuf.struct_pb2.Value]" + }, + { + "name": "parameters", + "type": "google.protobuf.struct_pb2.Value" + }, + { + "name": "deployed_model_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.ExplainResponse", + "shortName": "explain" + }, + "description": "Sample for Explain", + "file": "aiplatform_v1_generated_prediction_service_explain_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_PredictionService_Explain_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_prediction_service_explain_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.PredictionServiceClient", + "shortName": "PredictionServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.PredictionServiceClient.explain", + "method": { + "fullName": "google.cloud.aiplatform.v1.PredictionService.Explain", + "service": { + "fullName": "google.cloud.aiplatform.v1.PredictionService", + "shortName": "PredictionService" + }, + "shortName": "Explain" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ExplainRequest" + }, + { + "name": "endpoint", + "type": "str" + }, + { + "name": "instances", + "type": "Sequence[google.protobuf.struct_pb2.Value]" + }, + { + "name": "parameters", + "type": "google.protobuf.struct_pb2.Value" + }, + { + "name": "deployed_model_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.ExplainResponse", + "shortName": "explain" + }, + "description": "Sample for Explain", + "file": "aiplatform_v1_generated_prediction_service_explain_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_PredictionService_Explain_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_prediction_service_explain_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.PredictionServiceAsyncClient", + "shortName": "PredictionServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.PredictionServiceAsyncClient.predict", + "method": { + "fullName": "google.cloud.aiplatform.v1.PredictionService.Predict", + "service": { + "fullName": "google.cloud.aiplatform.v1.PredictionService", + "shortName": "PredictionService" + }, + "shortName": "Predict" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.PredictRequest" + }, + { + "name": "endpoint", + "type": "str" + }, + { + "name": "instances", + "type": "Sequence[google.protobuf.struct_pb2.Value]" + }, + { + "name": "parameters", + "type": "google.protobuf.struct_pb2.Value" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.PredictResponse", + "shortName": "predict" + }, + "description": "Sample for Predict", + "file": "aiplatform_v1_generated_prediction_service_predict_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_PredictionService_Predict_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_prediction_service_predict_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.PredictionServiceClient", + "shortName": "PredictionServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.PredictionServiceClient.predict", + "method": { + "fullName": "google.cloud.aiplatform.v1.PredictionService.Predict", + "service": { + "fullName": "google.cloud.aiplatform.v1.PredictionService", + "shortName": "PredictionService" + }, + "shortName": "Predict" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.PredictRequest" + }, + { + "name": "endpoint", + "type": "str" + }, + { + "name": "instances", + "type": "Sequence[google.protobuf.struct_pb2.Value]" + }, + { + "name": "parameters", + "type": "google.protobuf.struct_pb2.Value" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.PredictResponse", + "shortName": "predict" + }, + "description": "Sample for Predict", + "file": "aiplatform_v1_generated_prediction_service_predict_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_PredictionService_Predict_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_prediction_service_predict_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.PredictionServiceAsyncClient", + "shortName": "PredictionServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.PredictionServiceAsyncClient.raw_predict", + "method": { + "fullName": "google.cloud.aiplatform.v1.PredictionService.RawPredict", + "service": { + "fullName": "google.cloud.aiplatform.v1.PredictionService", + "shortName": "PredictionService" + }, + "shortName": "RawPredict" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.RawPredictRequest" + }, + { + "name": "endpoint", + "type": "str" + }, + { + "name": "http_body", + "type": "google.api.httpbody_pb2.HttpBody" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api.httpbody_pb2.HttpBody", + "shortName": "raw_predict" + }, + "description": "Sample for RawPredict", + "file": "aiplatform_v1_generated_prediction_service_raw_predict_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_PredictionService_RawPredict_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_prediction_service_raw_predict_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.PredictionServiceClient", + "shortName": "PredictionServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.PredictionServiceClient.raw_predict", + "method": { + "fullName": "google.cloud.aiplatform.v1.PredictionService.RawPredict", + "service": { + "fullName": "google.cloud.aiplatform.v1.PredictionService", + "shortName": "PredictionService" + }, + "shortName": "RawPredict" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.RawPredictRequest" + }, + { + "name": "endpoint", + "type": "str" + }, + { + "name": "http_body", + "type": "google.api.httpbody_pb2.HttpBody" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api.httpbody_pb2.HttpBody", + "shortName": "raw_predict" + }, + "description": "Sample for RawPredict", + "file": "aiplatform_v1_generated_prediction_service_raw_predict_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_PredictionService_RawPredict_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_prediction_service_raw_predict_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.SpecialistPoolServiceAsyncClient", + "shortName": "SpecialistPoolServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.SpecialistPoolServiceAsyncClient.create_specialist_pool", + "method": { + "fullName": "google.cloud.aiplatform.v1.SpecialistPoolService.CreateSpecialistPool", + "service": { + "fullName": "google.cloud.aiplatform.v1.SpecialistPoolService", + "shortName": "SpecialistPoolService" + }, + "shortName": "CreateSpecialistPool" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateSpecialistPoolRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "specialist_pool", + "type": "google.cloud.aiplatform_v1.types.SpecialistPool" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "create_specialist_pool" + }, + "description": "Sample for CreateSpecialistPool", + "file": "aiplatform_v1_generated_specialist_pool_service_create_specialist_pool_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_SpecialistPoolService_CreateSpecialistPool_async", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_specialist_pool_service_create_specialist_pool_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.SpecialistPoolServiceClient", + "shortName": "SpecialistPoolServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.SpecialistPoolServiceClient.create_specialist_pool", + "method": { + "fullName": "google.cloud.aiplatform.v1.SpecialistPoolService.CreateSpecialistPool", + "service": { + "fullName": "google.cloud.aiplatform.v1.SpecialistPoolService", + "shortName": "SpecialistPoolService" + }, + "shortName": "CreateSpecialistPool" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateSpecialistPoolRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "specialist_pool", + "type": "google.cloud.aiplatform_v1.types.SpecialistPool" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "create_specialist_pool" + }, + "description": "Sample for CreateSpecialistPool", + "file": "aiplatform_v1_generated_specialist_pool_service_create_specialist_pool_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_SpecialistPoolService_CreateSpecialistPool_sync", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_specialist_pool_service_create_specialist_pool_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.SpecialistPoolServiceAsyncClient", + "shortName": "SpecialistPoolServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.SpecialistPoolServiceAsyncClient.delete_specialist_pool", + "method": { + "fullName": "google.cloud.aiplatform.v1.SpecialistPoolService.DeleteSpecialistPool", + "service": { + "fullName": "google.cloud.aiplatform.v1.SpecialistPoolService", + "shortName": "SpecialistPoolService" + }, + "shortName": "DeleteSpecialistPool" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteSpecialistPoolRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_specialist_pool" + }, + "description": "Sample for DeleteSpecialistPool", + "file": "aiplatform_v1_generated_specialist_pool_service_delete_specialist_pool_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_SpecialistPoolService_DeleteSpecialistPool_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_specialist_pool_service_delete_specialist_pool_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.SpecialistPoolServiceClient", + "shortName": "SpecialistPoolServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.SpecialistPoolServiceClient.delete_specialist_pool", + "method": { + "fullName": "google.cloud.aiplatform.v1.SpecialistPoolService.DeleteSpecialistPool", + "service": { + "fullName": "google.cloud.aiplatform.v1.SpecialistPoolService", + "shortName": "SpecialistPoolService" + }, + "shortName": "DeleteSpecialistPool" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteSpecialistPoolRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_specialist_pool" + }, + "description": "Sample for DeleteSpecialistPool", + "file": "aiplatform_v1_generated_specialist_pool_service_delete_specialist_pool_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_SpecialistPoolService_DeleteSpecialistPool_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_specialist_pool_service_delete_specialist_pool_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.SpecialistPoolServiceAsyncClient", + "shortName": "SpecialistPoolServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.SpecialistPoolServiceAsyncClient.get_specialist_pool", + "method": { + "fullName": "google.cloud.aiplatform.v1.SpecialistPoolService.GetSpecialistPool", + "service": { + "fullName": "google.cloud.aiplatform.v1.SpecialistPoolService", + "shortName": "SpecialistPoolService" + }, + "shortName": "GetSpecialistPool" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetSpecialistPoolRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.SpecialistPool", + "shortName": "get_specialist_pool" + }, + "description": "Sample for GetSpecialistPool", + "file": "aiplatform_v1_generated_specialist_pool_service_get_specialist_pool_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_SpecialistPoolService_GetSpecialistPool_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_specialist_pool_service_get_specialist_pool_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.SpecialistPoolServiceClient", + "shortName": "SpecialistPoolServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.SpecialistPoolServiceClient.get_specialist_pool", + "method": { + "fullName": "google.cloud.aiplatform.v1.SpecialistPoolService.GetSpecialistPool", + "service": { + "fullName": "google.cloud.aiplatform.v1.SpecialistPoolService", + "shortName": "SpecialistPoolService" + }, + "shortName": "GetSpecialistPool" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetSpecialistPoolRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.SpecialistPool", + "shortName": "get_specialist_pool" + }, + "description": "Sample for GetSpecialistPool", + "file": "aiplatform_v1_generated_specialist_pool_service_get_specialist_pool_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_SpecialistPoolService_GetSpecialistPool_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_specialist_pool_service_get_specialist_pool_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.SpecialistPoolServiceAsyncClient", + "shortName": "SpecialistPoolServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.SpecialistPoolServiceAsyncClient.list_specialist_pools", + "method": { + "fullName": "google.cloud.aiplatform.v1.SpecialistPoolService.ListSpecialistPools", + "service": { + "fullName": "google.cloud.aiplatform.v1.SpecialistPoolService", + "shortName": "SpecialistPoolService" + }, + "shortName": "ListSpecialistPools" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListSpecialistPoolsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.specialist_pool_service.pagers.ListSpecialistPoolsAsyncPager", + "shortName": "list_specialist_pools" + }, + "description": "Sample for ListSpecialistPools", + "file": "aiplatform_v1_generated_specialist_pool_service_list_specialist_pools_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_SpecialistPoolService_ListSpecialistPools_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_specialist_pool_service_list_specialist_pools_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.SpecialistPoolServiceClient", + "shortName": "SpecialistPoolServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.SpecialistPoolServiceClient.list_specialist_pools", + "method": { + "fullName": "google.cloud.aiplatform.v1.SpecialistPoolService.ListSpecialistPools", + "service": { + "fullName": "google.cloud.aiplatform.v1.SpecialistPoolService", + "shortName": "SpecialistPoolService" + }, + "shortName": "ListSpecialistPools" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListSpecialistPoolsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.specialist_pool_service.pagers.ListSpecialistPoolsPager", + "shortName": "list_specialist_pools" + }, + "description": "Sample for ListSpecialistPools", + "file": "aiplatform_v1_generated_specialist_pool_service_list_specialist_pools_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_SpecialistPoolService_ListSpecialistPools_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_specialist_pool_service_list_specialist_pools_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.SpecialistPoolServiceAsyncClient", + "shortName": "SpecialistPoolServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.SpecialistPoolServiceAsyncClient.update_specialist_pool", + "method": { + "fullName": "google.cloud.aiplatform.v1.SpecialistPoolService.UpdateSpecialistPool", + "service": { + "fullName": "google.cloud.aiplatform.v1.SpecialistPoolService", + "shortName": "SpecialistPoolService" + }, + "shortName": "UpdateSpecialistPool" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UpdateSpecialistPoolRequest" + }, + { + "name": "specialist_pool", + "type": "google.cloud.aiplatform_v1.types.SpecialistPool" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "update_specialist_pool" + }, + "description": "Sample for UpdateSpecialistPool", + "file": "aiplatform_v1_generated_specialist_pool_service_update_specialist_pool_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_SpecialistPoolService_UpdateSpecialistPool_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_specialist_pool_service_update_specialist_pool_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.SpecialistPoolServiceClient", + "shortName": "SpecialistPoolServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.SpecialistPoolServiceClient.update_specialist_pool", + "method": { + "fullName": "google.cloud.aiplatform.v1.SpecialistPoolService.UpdateSpecialistPool", + "service": { + "fullName": "google.cloud.aiplatform.v1.SpecialistPoolService", + "shortName": "SpecialistPoolService" + }, + "shortName": "UpdateSpecialistPool" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UpdateSpecialistPoolRequest" + }, + { + "name": "specialist_pool", + "type": "google.cloud.aiplatform_v1.types.SpecialistPool" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "update_specialist_pool" + }, + "description": "Sample for UpdateSpecialistPool", + "file": "aiplatform_v1_generated_specialist_pool_service_update_specialist_pool_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_SpecialistPoolService_UpdateSpecialistPool_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_specialist_pool_service_update_specialist_pool_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient.batch_create_tensorboard_runs", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.BatchCreateTensorboardRuns", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "BatchCreateTensorboardRuns" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.BatchCreateTensorboardRunsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "requests", + "type": "Sequence[google.cloud.aiplatform_v1.types.CreateTensorboardRunRequest]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.BatchCreateTensorboardRunsResponse", + "shortName": "batch_create_tensorboard_runs" + }, + "description": "Sample for BatchCreateTensorboardRuns", + "file": "aiplatform_v1_generated_tensorboard_service_batch_create_tensorboard_runs_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_BatchCreateTensorboardRuns_async", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 47, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "start": 48, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_batch_create_tensorboard_runs_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient.batch_create_tensorboard_runs", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.BatchCreateTensorboardRuns", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "BatchCreateTensorboardRuns" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.BatchCreateTensorboardRunsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "requests", + "type": "Sequence[google.cloud.aiplatform_v1.types.CreateTensorboardRunRequest]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.BatchCreateTensorboardRunsResponse", + "shortName": "batch_create_tensorboard_runs" + }, + "description": "Sample for BatchCreateTensorboardRuns", + "file": "aiplatform_v1_generated_tensorboard_service_batch_create_tensorboard_runs_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_BatchCreateTensorboardRuns_sync", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 47, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "start": 48, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_batch_create_tensorboard_runs_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient.batch_create_tensorboard_time_series", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.BatchCreateTensorboardTimeSeries", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "BatchCreateTensorboardTimeSeries" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.BatchCreateTensorboardTimeSeriesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "requests", + "type": "Sequence[google.cloud.aiplatform_v1.types.CreateTensorboardTimeSeriesRequest]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.BatchCreateTensorboardTimeSeriesResponse", + "shortName": "batch_create_tensorboard_time_series" + }, + "description": "Sample for BatchCreateTensorboardTimeSeries", + "file": "aiplatform_v1_generated_tensorboard_service_batch_create_tensorboard_time_series_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_BatchCreateTensorboardTimeSeries_async", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 47, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "start": 48, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_batch_create_tensorboard_time_series_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient.batch_create_tensorboard_time_series", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.BatchCreateTensorboardTimeSeries", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "BatchCreateTensorboardTimeSeries" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.BatchCreateTensorboardTimeSeriesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "requests", + "type": "Sequence[google.cloud.aiplatform_v1.types.CreateTensorboardTimeSeriesRequest]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.BatchCreateTensorboardTimeSeriesResponse", + "shortName": "batch_create_tensorboard_time_series" + }, + "description": "Sample for BatchCreateTensorboardTimeSeries", + "file": "aiplatform_v1_generated_tensorboard_service_batch_create_tensorboard_time_series_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_BatchCreateTensorboardTimeSeries_sync", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 47, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "start": 48, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_batch_create_tensorboard_time_series_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient.batch_read_tensorboard_time_series_data", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.BatchReadTensorboardTimeSeriesData", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "BatchReadTensorboardTimeSeriesData" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.BatchReadTensorboardTimeSeriesDataRequest" + }, + { + "name": "tensorboard", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.BatchReadTensorboardTimeSeriesDataResponse", + "shortName": "batch_read_tensorboard_time_series_data" + }, + "description": "Sample for BatchReadTensorboardTimeSeriesData", + "file": "aiplatform_v1_generated_tensorboard_service_batch_read_tensorboard_time_series_data_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_BatchReadTensorboardTimeSeriesData_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_batch_read_tensorboard_time_series_data_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient.batch_read_tensorboard_time_series_data", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.BatchReadTensorboardTimeSeriesData", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "BatchReadTensorboardTimeSeriesData" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.BatchReadTensorboardTimeSeriesDataRequest" + }, + { + "name": "tensorboard", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.BatchReadTensorboardTimeSeriesDataResponse", + "shortName": "batch_read_tensorboard_time_series_data" + }, + "description": "Sample for BatchReadTensorboardTimeSeriesData", + "file": "aiplatform_v1_generated_tensorboard_service_batch_read_tensorboard_time_series_data_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_BatchReadTensorboardTimeSeriesData_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_batch_read_tensorboard_time_series_data_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient.create_tensorboard_experiment", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.CreateTensorboardExperiment", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "CreateTensorboardExperiment" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateTensorboardExperimentRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "tensorboard_experiment", + "type": "google.cloud.aiplatform_v1.types.TensorboardExperiment" + }, + { + "name": "tensorboard_experiment_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.TensorboardExperiment", + "shortName": "create_tensorboard_experiment" + }, + "description": "Sample for CreateTensorboardExperiment", + "file": "aiplatform_v1_generated_tensorboard_service_create_tensorboard_experiment_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_CreateTensorboardExperiment_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_create_tensorboard_experiment_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient.create_tensorboard_experiment", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.CreateTensorboardExperiment", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "CreateTensorboardExperiment" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateTensorboardExperimentRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "tensorboard_experiment", + "type": "google.cloud.aiplatform_v1.types.TensorboardExperiment" + }, + { + "name": "tensorboard_experiment_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.TensorboardExperiment", + "shortName": "create_tensorboard_experiment" + }, + "description": "Sample for CreateTensorboardExperiment", + "file": "aiplatform_v1_generated_tensorboard_service_create_tensorboard_experiment_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_CreateTensorboardExperiment_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_create_tensorboard_experiment_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient.create_tensorboard_run", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.CreateTensorboardRun", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "CreateTensorboardRun" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateTensorboardRunRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "tensorboard_run", + "type": "google.cloud.aiplatform_v1.types.TensorboardRun" + }, + { + "name": "tensorboard_run_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.TensorboardRun", + "shortName": "create_tensorboard_run" + }, + "description": "Sample for CreateTensorboardRun", + "file": "aiplatform_v1_generated_tensorboard_service_create_tensorboard_run_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_CreateTensorboardRun_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_create_tensorboard_run_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient.create_tensorboard_run", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.CreateTensorboardRun", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "CreateTensorboardRun" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateTensorboardRunRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "tensorboard_run", + "type": "google.cloud.aiplatform_v1.types.TensorboardRun" + }, + { + "name": "tensorboard_run_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.TensorboardRun", + "shortName": "create_tensorboard_run" + }, + "description": "Sample for CreateTensorboardRun", + "file": "aiplatform_v1_generated_tensorboard_service_create_tensorboard_run_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_CreateTensorboardRun_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_create_tensorboard_run_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient.create_tensorboard_time_series", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.CreateTensorboardTimeSeries", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "CreateTensorboardTimeSeries" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateTensorboardTimeSeriesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "tensorboard_time_series", + "type": "google.cloud.aiplatform_v1.types.TensorboardTimeSeries" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.TensorboardTimeSeries", + "shortName": "create_tensorboard_time_series" + }, + "description": "Sample for CreateTensorboardTimeSeries", + "file": "aiplatform_v1_generated_tensorboard_service_create_tensorboard_time_series_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_CreateTensorboardTimeSeries_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_create_tensorboard_time_series_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient.create_tensorboard_time_series", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.CreateTensorboardTimeSeries", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "CreateTensorboardTimeSeries" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateTensorboardTimeSeriesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "tensorboard_time_series", + "type": "google.cloud.aiplatform_v1.types.TensorboardTimeSeries" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.TensorboardTimeSeries", + "shortName": "create_tensorboard_time_series" + }, + "description": "Sample for CreateTensorboardTimeSeries", + "file": "aiplatform_v1_generated_tensorboard_service_create_tensorboard_time_series_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_CreateTensorboardTimeSeries_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_create_tensorboard_time_series_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient.create_tensorboard", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.CreateTensorboard", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "CreateTensorboard" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateTensorboardRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "tensorboard", + "type": "google.cloud.aiplatform_v1.types.Tensorboard" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "create_tensorboard" + }, + "description": "Sample for CreateTensorboard", + "file": "aiplatform_v1_generated_tensorboard_service_create_tensorboard_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_CreateTensorboard_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_create_tensorboard_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient.create_tensorboard", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.CreateTensorboard", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "CreateTensorboard" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateTensorboardRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "tensorboard", + "type": "google.cloud.aiplatform_v1.types.Tensorboard" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "create_tensorboard" + }, + "description": "Sample for CreateTensorboard", + "file": "aiplatform_v1_generated_tensorboard_service_create_tensorboard_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_CreateTensorboard_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_create_tensorboard_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient.delete_tensorboard_experiment", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.DeleteTensorboardExperiment", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "DeleteTensorboardExperiment" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteTensorboardExperimentRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_tensorboard_experiment" + }, + "description": "Sample for DeleteTensorboardExperiment", + "file": "aiplatform_v1_generated_tensorboard_service_delete_tensorboard_experiment_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_DeleteTensorboardExperiment_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_delete_tensorboard_experiment_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient.delete_tensorboard_experiment", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.DeleteTensorboardExperiment", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "DeleteTensorboardExperiment" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteTensorboardExperimentRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_tensorboard_experiment" + }, + "description": "Sample for DeleteTensorboardExperiment", + "file": "aiplatform_v1_generated_tensorboard_service_delete_tensorboard_experiment_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_DeleteTensorboardExperiment_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_delete_tensorboard_experiment_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient.delete_tensorboard_run", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.DeleteTensorboardRun", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "DeleteTensorboardRun" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteTensorboardRunRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_tensorboard_run" + }, + "description": "Sample for DeleteTensorboardRun", + "file": "aiplatform_v1_generated_tensorboard_service_delete_tensorboard_run_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_DeleteTensorboardRun_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_delete_tensorboard_run_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient.delete_tensorboard_run", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.DeleteTensorboardRun", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "DeleteTensorboardRun" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteTensorboardRunRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_tensorboard_run" + }, + "description": "Sample for DeleteTensorboardRun", + "file": "aiplatform_v1_generated_tensorboard_service_delete_tensorboard_run_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_DeleteTensorboardRun_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_delete_tensorboard_run_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient.delete_tensorboard_time_series", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.DeleteTensorboardTimeSeries", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "DeleteTensorboardTimeSeries" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteTensorboardTimeSeriesRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_tensorboard_time_series" + }, + "description": "Sample for DeleteTensorboardTimeSeries", + "file": "aiplatform_v1_generated_tensorboard_service_delete_tensorboard_time_series_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_DeleteTensorboardTimeSeries_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_delete_tensorboard_time_series_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient.delete_tensorboard_time_series", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.DeleteTensorboardTimeSeries", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "DeleteTensorboardTimeSeries" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteTensorboardTimeSeriesRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_tensorboard_time_series" + }, + "description": "Sample for DeleteTensorboardTimeSeries", + "file": "aiplatform_v1_generated_tensorboard_service_delete_tensorboard_time_series_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_DeleteTensorboardTimeSeries_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_delete_tensorboard_time_series_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient.delete_tensorboard", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.DeleteTensorboard", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "DeleteTensorboard" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteTensorboardRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_tensorboard" + }, + "description": "Sample for DeleteTensorboard", + "file": "aiplatform_v1_generated_tensorboard_service_delete_tensorboard_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_DeleteTensorboard_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_delete_tensorboard_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient.delete_tensorboard", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.DeleteTensorboard", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "DeleteTensorboard" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteTensorboardRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_tensorboard" + }, + "description": "Sample for DeleteTensorboard", + "file": "aiplatform_v1_generated_tensorboard_service_delete_tensorboard_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_DeleteTensorboard_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_delete_tensorboard_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient.export_tensorboard_time_series_data", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.ExportTensorboardTimeSeriesData", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "ExportTensorboardTimeSeriesData" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ExportTensorboardTimeSeriesDataRequest" + }, + { + "name": "tensorboard_time_series", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.tensorboard_service.pagers.ExportTensorboardTimeSeriesDataAsyncPager", + "shortName": "export_tensorboard_time_series_data" + }, + "description": "Sample for ExportTensorboardTimeSeriesData", + "file": "aiplatform_v1_generated_tensorboard_service_export_tensorboard_time_series_data_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_ExportTensorboardTimeSeriesData_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_export_tensorboard_time_series_data_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient.export_tensorboard_time_series_data", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.ExportTensorboardTimeSeriesData", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "ExportTensorboardTimeSeriesData" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ExportTensorboardTimeSeriesDataRequest" + }, + { + "name": "tensorboard_time_series", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.tensorboard_service.pagers.ExportTensorboardTimeSeriesDataPager", + "shortName": "export_tensorboard_time_series_data" + }, + "description": "Sample for ExportTensorboardTimeSeriesData", + "file": "aiplatform_v1_generated_tensorboard_service_export_tensorboard_time_series_data_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_ExportTensorboardTimeSeriesData_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_export_tensorboard_time_series_data_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient.get_tensorboard_experiment", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.GetTensorboardExperiment", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "GetTensorboardExperiment" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetTensorboardExperimentRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.TensorboardExperiment", + "shortName": "get_tensorboard_experiment" + }, + "description": "Sample for GetTensorboardExperiment", + "file": "aiplatform_v1_generated_tensorboard_service_get_tensorboard_experiment_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_GetTensorboardExperiment_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_get_tensorboard_experiment_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient.get_tensorboard_experiment", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.GetTensorboardExperiment", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "GetTensorboardExperiment" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetTensorboardExperimentRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.TensorboardExperiment", + "shortName": "get_tensorboard_experiment" + }, + "description": "Sample for GetTensorboardExperiment", + "file": "aiplatform_v1_generated_tensorboard_service_get_tensorboard_experiment_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_GetTensorboardExperiment_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_get_tensorboard_experiment_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient.get_tensorboard_run", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.GetTensorboardRun", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "GetTensorboardRun" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetTensorboardRunRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.TensorboardRun", + "shortName": "get_tensorboard_run" + }, + "description": "Sample for GetTensorboardRun", + "file": "aiplatform_v1_generated_tensorboard_service_get_tensorboard_run_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_GetTensorboardRun_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_get_tensorboard_run_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient.get_tensorboard_run", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.GetTensorboardRun", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "GetTensorboardRun" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetTensorboardRunRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.TensorboardRun", + "shortName": "get_tensorboard_run" + }, + "description": "Sample for GetTensorboardRun", + "file": "aiplatform_v1_generated_tensorboard_service_get_tensorboard_run_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_GetTensorboardRun_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_get_tensorboard_run_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient.get_tensorboard_time_series", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.GetTensorboardTimeSeries", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "GetTensorboardTimeSeries" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetTensorboardTimeSeriesRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.TensorboardTimeSeries", + "shortName": "get_tensorboard_time_series" + }, + "description": "Sample for GetTensorboardTimeSeries", + "file": "aiplatform_v1_generated_tensorboard_service_get_tensorboard_time_series_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_GetTensorboardTimeSeries_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_get_tensorboard_time_series_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient.get_tensorboard_time_series", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.GetTensorboardTimeSeries", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "GetTensorboardTimeSeries" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetTensorboardTimeSeriesRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.TensorboardTimeSeries", + "shortName": "get_tensorboard_time_series" + }, + "description": "Sample for GetTensorboardTimeSeries", + "file": "aiplatform_v1_generated_tensorboard_service_get_tensorboard_time_series_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_GetTensorboardTimeSeries_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_get_tensorboard_time_series_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient.get_tensorboard", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.GetTensorboard", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "GetTensorboard" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetTensorboardRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Tensorboard", + "shortName": "get_tensorboard" + }, + "description": "Sample for GetTensorboard", + "file": "aiplatform_v1_generated_tensorboard_service_get_tensorboard_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_GetTensorboard_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_get_tensorboard_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient.get_tensorboard", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.GetTensorboard", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "GetTensorboard" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetTensorboardRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Tensorboard", + "shortName": "get_tensorboard" + }, + "description": "Sample for GetTensorboard", + "file": "aiplatform_v1_generated_tensorboard_service_get_tensorboard_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_GetTensorboard_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_get_tensorboard_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient.list_tensorboard_experiments", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.ListTensorboardExperiments", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "ListTensorboardExperiments" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListTensorboardExperimentsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.tensorboard_service.pagers.ListTensorboardExperimentsAsyncPager", + "shortName": "list_tensorboard_experiments" + }, + "description": "Sample for ListTensorboardExperiments", + "file": "aiplatform_v1_generated_tensorboard_service_list_tensorboard_experiments_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_ListTensorboardExperiments_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_list_tensorboard_experiments_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient.list_tensorboard_experiments", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.ListTensorboardExperiments", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "ListTensorboardExperiments" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListTensorboardExperimentsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.tensorboard_service.pagers.ListTensorboardExperimentsPager", + "shortName": "list_tensorboard_experiments" + }, + "description": "Sample for ListTensorboardExperiments", + "file": "aiplatform_v1_generated_tensorboard_service_list_tensorboard_experiments_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_ListTensorboardExperiments_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_list_tensorboard_experiments_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient.list_tensorboard_runs", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.ListTensorboardRuns", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "ListTensorboardRuns" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListTensorboardRunsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.tensorboard_service.pagers.ListTensorboardRunsAsyncPager", + "shortName": "list_tensorboard_runs" + }, + "description": "Sample for ListTensorboardRuns", + "file": "aiplatform_v1_generated_tensorboard_service_list_tensorboard_runs_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_ListTensorboardRuns_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_list_tensorboard_runs_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient.list_tensorboard_runs", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.ListTensorboardRuns", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "ListTensorboardRuns" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListTensorboardRunsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.tensorboard_service.pagers.ListTensorboardRunsPager", + "shortName": "list_tensorboard_runs" + }, + "description": "Sample for ListTensorboardRuns", + "file": "aiplatform_v1_generated_tensorboard_service_list_tensorboard_runs_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_ListTensorboardRuns_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_list_tensorboard_runs_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient.list_tensorboard_time_series", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.ListTensorboardTimeSeries", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "ListTensorboardTimeSeries" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListTensorboardTimeSeriesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.tensorboard_service.pagers.ListTensorboardTimeSeriesAsyncPager", + "shortName": "list_tensorboard_time_series" + }, + "description": "Sample for ListTensorboardTimeSeries", + "file": "aiplatform_v1_generated_tensorboard_service_list_tensorboard_time_series_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_ListTensorboardTimeSeries_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_list_tensorboard_time_series_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient.list_tensorboard_time_series", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.ListTensorboardTimeSeries", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "ListTensorboardTimeSeries" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListTensorboardTimeSeriesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.tensorboard_service.pagers.ListTensorboardTimeSeriesPager", + "shortName": "list_tensorboard_time_series" + }, + "description": "Sample for ListTensorboardTimeSeries", + "file": "aiplatform_v1_generated_tensorboard_service_list_tensorboard_time_series_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_ListTensorboardTimeSeries_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_list_tensorboard_time_series_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient.list_tensorboards", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.ListTensorboards", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "ListTensorboards" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListTensorboardsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.tensorboard_service.pagers.ListTensorboardsAsyncPager", + "shortName": "list_tensorboards" + }, + "description": "Sample for ListTensorboards", + "file": "aiplatform_v1_generated_tensorboard_service_list_tensorboards_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_ListTensorboards_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_list_tensorboards_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient.list_tensorboards", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.ListTensorboards", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "ListTensorboards" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListTensorboardsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.tensorboard_service.pagers.ListTensorboardsPager", + "shortName": "list_tensorboards" + }, + "description": "Sample for ListTensorboards", + "file": "aiplatform_v1_generated_tensorboard_service_list_tensorboards_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_ListTensorboards_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_list_tensorboards_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient.read_tensorboard_blob_data", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.ReadTensorboardBlobData", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "ReadTensorboardBlobData" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ReadTensorboardBlobDataRequest" + }, + { + "name": "time_series", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "Iterable[google.cloud.aiplatform_v1.types.ReadTensorboardBlobDataResponse]", + "shortName": "read_tensorboard_blob_data" + }, + "description": "Sample for ReadTensorboardBlobData", + "file": "aiplatform_v1_generated_tensorboard_service_read_tensorboard_blob_data_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_ReadTensorboardBlobData_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_read_tensorboard_blob_data_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient.read_tensorboard_blob_data", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.ReadTensorboardBlobData", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "ReadTensorboardBlobData" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ReadTensorboardBlobDataRequest" + }, + { + "name": "time_series", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "Iterable[google.cloud.aiplatform_v1.types.ReadTensorboardBlobDataResponse]", + "shortName": "read_tensorboard_blob_data" + }, + "description": "Sample for ReadTensorboardBlobData", + "file": "aiplatform_v1_generated_tensorboard_service_read_tensorboard_blob_data_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_ReadTensorboardBlobData_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_read_tensorboard_blob_data_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient.read_tensorboard_time_series_data", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.ReadTensorboardTimeSeriesData", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "ReadTensorboardTimeSeriesData" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ReadTensorboardTimeSeriesDataRequest" + }, + { + "name": "tensorboard_time_series", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.ReadTensorboardTimeSeriesDataResponse", + "shortName": "read_tensorboard_time_series_data" + }, + "description": "Sample for ReadTensorboardTimeSeriesData", + "file": "aiplatform_v1_generated_tensorboard_service_read_tensorboard_time_series_data_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_ReadTensorboardTimeSeriesData_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_read_tensorboard_time_series_data_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient.read_tensorboard_time_series_data", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.ReadTensorboardTimeSeriesData", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "ReadTensorboardTimeSeriesData" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ReadTensorboardTimeSeriesDataRequest" + }, + { + "name": "tensorboard_time_series", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.ReadTensorboardTimeSeriesDataResponse", + "shortName": "read_tensorboard_time_series_data" + }, + "description": "Sample for ReadTensorboardTimeSeriesData", + "file": "aiplatform_v1_generated_tensorboard_service_read_tensorboard_time_series_data_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_ReadTensorboardTimeSeriesData_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_read_tensorboard_time_series_data_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient.update_tensorboard_experiment", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.UpdateTensorboardExperiment", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "UpdateTensorboardExperiment" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UpdateTensorboardExperimentRequest" + }, + { + "name": "tensorboard_experiment", + "type": "google.cloud.aiplatform_v1.types.TensorboardExperiment" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.TensorboardExperiment", + "shortName": "update_tensorboard_experiment" + }, + "description": "Sample for UpdateTensorboardExperiment", + "file": "aiplatform_v1_generated_tensorboard_service_update_tensorboard_experiment_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_UpdateTensorboardExperiment_async", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_update_tensorboard_experiment_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient.update_tensorboard_experiment", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.UpdateTensorboardExperiment", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "UpdateTensorboardExperiment" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UpdateTensorboardExperimentRequest" + }, + { + "name": "tensorboard_experiment", + "type": "google.cloud.aiplatform_v1.types.TensorboardExperiment" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.TensorboardExperiment", + "shortName": "update_tensorboard_experiment" + }, + "description": "Sample for UpdateTensorboardExperiment", + "file": "aiplatform_v1_generated_tensorboard_service_update_tensorboard_experiment_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_UpdateTensorboardExperiment_sync", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_update_tensorboard_experiment_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient.update_tensorboard_run", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.UpdateTensorboardRun", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "UpdateTensorboardRun" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UpdateTensorboardRunRequest" + }, + { + "name": "tensorboard_run", + "type": "google.cloud.aiplatform_v1.types.TensorboardRun" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.TensorboardRun", + "shortName": "update_tensorboard_run" + }, + "description": "Sample for UpdateTensorboardRun", + "file": "aiplatform_v1_generated_tensorboard_service_update_tensorboard_run_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_UpdateTensorboardRun_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_update_tensorboard_run_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient.update_tensorboard_run", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.UpdateTensorboardRun", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "UpdateTensorboardRun" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UpdateTensorboardRunRequest" + }, + { + "name": "tensorboard_run", + "type": "google.cloud.aiplatform_v1.types.TensorboardRun" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.TensorboardRun", + "shortName": "update_tensorboard_run" + }, + "description": "Sample for UpdateTensorboardRun", + "file": "aiplatform_v1_generated_tensorboard_service_update_tensorboard_run_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_UpdateTensorboardRun_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_update_tensorboard_run_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient.update_tensorboard_time_series", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.UpdateTensorboardTimeSeries", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "UpdateTensorboardTimeSeries" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UpdateTensorboardTimeSeriesRequest" + }, + { + "name": "tensorboard_time_series", + "type": "google.cloud.aiplatform_v1.types.TensorboardTimeSeries" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.TensorboardTimeSeries", + "shortName": "update_tensorboard_time_series" + }, + "description": "Sample for UpdateTensorboardTimeSeries", + "file": "aiplatform_v1_generated_tensorboard_service_update_tensorboard_time_series_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_UpdateTensorboardTimeSeries_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_update_tensorboard_time_series_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient.update_tensorboard_time_series", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.UpdateTensorboardTimeSeries", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "UpdateTensorboardTimeSeries" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UpdateTensorboardTimeSeriesRequest" + }, + { + "name": "tensorboard_time_series", + "type": "google.cloud.aiplatform_v1.types.TensorboardTimeSeries" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.TensorboardTimeSeries", + "shortName": "update_tensorboard_time_series" + }, + "description": "Sample for UpdateTensorboardTimeSeries", + "file": "aiplatform_v1_generated_tensorboard_service_update_tensorboard_time_series_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_UpdateTensorboardTimeSeries_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_update_tensorboard_time_series_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient.update_tensorboard", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.UpdateTensorboard", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "UpdateTensorboard" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UpdateTensorboardRequest" + }, + { + "name": "tensorboard", + "type": "google.cloud.aiplatform_v1.types.Tensorboard" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "update_tensorboard" + }, + "description": "Sample for UpdateTensorboard", + "file": "aiplatform_v1_generated_tensorboard_service_update_tensorboard_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_UpdateTensorboard_async", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_update_tensorboard_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient.update_tensorboard", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.UpdateTensorboard", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "UpdateTensorboard" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.UpdateTensorboardRequest" + }, + { + "name": "tensorboard", + "type": "google.cloud.aiplatform_v1.types.Tensorboard" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "update_tensorboard" + }, + "description": "Sample for UpdateTensorboard", + "file": "aiplatform_v1_generated_tensorboard_service_update_tensorboard_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_UpdateTensorboard_sync", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_update_tensorboard_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient.write_tensorboard_experiment_data", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.WriteTensorboardExperimentData", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "WriteTensorboardExperimentData" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.WriteTensorboardExperimentDataRequest" + }, + { + "name": "tensorboard_experiment", + "type": "str" + }, + { + "name": "write_run_data_requests", + "type": "Sequence[google.cloud.aiplatform_v1.types.WriteTensorboardRunDataRequest]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.WriteTensorboardExperimentDataResponse", + "shortName": "write_tensorboard_experiment_data" + }, + "description": "Sample for WriteTensorboardExperimentData", + "file": "aiplatform_v1_generated_tensorboard_service_write_tensorboard_experiment_data_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_WriteTensorboardExperimentData_async", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 47, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "start": 48, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_write_tensorboard_experiment_data_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient.write_tensorboard_experiment_data", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.WriteTensorboardExperimentData", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "WriteTensorboardExperimentData" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.WriteTensorboardExperimentDataRequest" + }, + { + "name": "tensorboard_experiment", + "type": "str" + }, + { + "name": "write_run_data_requests", + "type": "Sequence[google.cloud.aiplatform_v1.types.WriteTensorboardRunDataRequest]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.WriteTensorboardExperimentDataResponse", + "shortName": "write_tensorboard_experiment_data" + }, + "description": "Sample for WriteTensorboardExperimentData", + "file": "aiplatform_v1_generated_tensorboard_service_write_tensorboard_experiment_data_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_WriteTensorboardExperimentData_sync", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 47, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "start": 48, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_write_tensorboard_experiment_data_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceAsyncClient.write_tensorboard_run_data", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.WriteTensorboardRunData", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "WriteTensorboardRunData" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.WriteTensorboardRunDataRequest" + }, + { + "name": "tensorboard_run", + "type": "str" + }, + { + "name": "time_series_data", + "type": "Sequence[google.cloud.aiplatform_v1.types.TimeSeriesData]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.WriteTensorboardRunDataResponse", + "shortName": "write_tensorboard_run_data" + }, + "description": "Sample for WriteTensorboardRunData", + "file": "aiplatform_v1_generated_tensorboard_service_write_tensorboard_run_data_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_WriteTensorboardRunData_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_write_tensorboard_run_data_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.TensorboardServiceClient.write_tensorboard_run_data", + "method": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService.WriteTensorboardRunData", + "service": { + "fullName": "google.cloud.aiplatform.v1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "WriteTensorboardRunData" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.WriteTensorboardRunDataRequest" + }, + { + "name": "tensorboard_run", + "type": "str" + }, + { + "name": "time_series_data", + "type": "Sequence[google.cloud.aiplatform_v1.types.TimeSeriesData]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.WriteTensorboardRunDataResponse", + "shortName": "write_tensorboard_run_data" + }, + "description": "Sample for WriteTensorboardRunData", + "file": "aiplatform_v1_generated_tensorboard_service_write_tensorboard_run_data_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_TensorboardService_WriteTensorboardRunData_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_tensorboard_service_write_tensorboard_run_data_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.VizierServiceAsyncClient", + "shortName": "VizierServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.VizierServiceAsyncClient.add_trial_measurement", + "method": { + "fullName": "google.cloud.aiplatform.v1.VizierService.AddTrialMeasurement", + "service": { + "fullName": "google.cloud.aiplatform.v1.VizierService", + "shortName": "VizierService" + }, + "shortName": "AddTrialMeasurement" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.AddTrialMeasurementRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Trial", + "shortName": "add_trial_measurement" + }, + "description": "Sample for AddTrialMeasurement", + "file": "aiplatform_v1_generated_vizier_service_add_trial_measurement_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_VizierService_AddTrialMeasurement_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_vizier_service_add_trial_measurement_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.VizierServiceClient", + "shortName": "VizierServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.VizierServiceClient.add_trial_measurement", + "method": { + "fullName": "google.cloud.aiplatform.v1.VizierService.AddTrialMeasurement", + "service": { + "fullName": "google.cloud.aiplatform.v1.VizierService", + "shortName": "VizierService" + }, + "shortName": "AddTrialMeasurement" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.AddTrialMeasurementRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Trial", + "shortName": "add_trial_measurement" + }, + "description": "Sample for AddTrialMeasurement", + "file": "aiplatform_v1_generated_vizier_service_add_trial_measurement_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_VizierService_AddTrialMeasurement_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_vizier_service_add_trial_measurement_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.VizierServiceAsyncClient", + "shortName": "VizierServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.VizierServiceAsyncClient.check_trial_early_stopping_state", + "method": { + "fullName": "google.cloud.aiplatform.v1.VizierService.CheckTrialEarlyStoppingState", + "service": { + "fullName": "google.cloud.aiplatform.v1.VizierService", + "shortName": "VizierService" + }, + "shortName": "CheckTrialEarlyStoppingState" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CheckTrialEarlyStoppingStateRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "check_trial_early_stopping_state" + }, + "description": "Sample for CheckTrialEarlyStoppingState", + "file": "aiplatform_v1_generated_vizier_service_check_trial_early_stopping_state_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_VizierService_CheckTrialEarlyStoppingState_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_vizier_service_check_trial_early_stopping_state_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.VizierServiceClient", + "shortName": "VizierServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.VizierServiceClient.check_trial_early_stopping_state", + "method": { + "fullName": "google.cloud.aiplatform.v1.VizierService.CheckTrialEarlyStoppingState", + "service": { + "fullName": "google.cloud.aiplatform.v1.VizierService", + "shortName": "VizierService" + }, + "shortName": "CheckTrialEarlyStoppingState" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CheckTrialEarlyStoppingStateRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "check_trial_early_stopping_state" + }, + "description": "Sample for CheckTrialEarlyStoppingState", + "file": "aiplatform_v1_generated_vizier_service_check_trial_early_stopping_state_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_VizierService_CheckTrialEarlyStoppingState_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_vizier_service_check_trial_early_stopping_state_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.VizierServiceAsyncClient", + "shortName": "VizierServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.VizierServiceAsyncClient.complete_trial", + "method": { + "fullName": "google.cloud.aiplatform.v1.VizierService.CompleteTrial", + "service": { + "fullName": "google.cloud.aiplatform.v1.VizierService", + "shortName": "VizierService" + }, + "shortName": "CompleteTrial" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CompleteTrialRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Trial", + "shortName": "complete_trial" + }, + "description": "Sample for CompleteTrial", + "file": "aiplatform_v1_generated_vizier_service_complete_trial_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_VizierService_CompleteTrial_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_vizier_service_complete_trial_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.VizierServiceClient", + "shortName": "VizierServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.VizierServiceClient.complete_trial", + "method": { + "fullName": "google.cloud.aiplatform.v1.VizierService.CompleteTrial", + "service": { + "fullName": "google.cloud.aiplatform.v1.VizierService", + "shortName": "VizierService" + }, + "shortName": "CompleteTrial" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CompleteTrialRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Trial", + "shortName": "complete_trial" + }, + "description": "Sample for CompleteTrial", + "file": "aiplatform_v1_generated_vizier_service_complete_trial_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_VizierService_CompleteTrial_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_vizier_service_complete_trial_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.VizierServiceAsyncClient", + "shortName": "VizierServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.VizierServiceAsyncClient.create_study", + "method": { + "fullName": "google.cloud.aiplatform.v1.VizierService.CreateStudy", + "service": { + "fullName": "google.cloud.aiplatform.v1.VizierService", + "shortName": "VizierService" + }, + "shortName": "CreateStudy" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateStudyRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "study", + "type": "google.cloud.aiplatform_v1.types.Study" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Study", + "shortName": "create_study" + }, + "description": "Sample for CreateStudy", + "file": "aiplatform_v1_generated_vizier_service_create_study_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_VizierService_CreateStudy_async", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 47, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 48, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_vizier_service_create_study_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.VizierServiceClient", + "shortName": "VizierServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.VizierServiceClient.create_study", + "method": { + "fullName": "google.cloud.aiplatform.v1.VizierService.CreateStudy", + "service": { + "fullName": "google.cloud.aiplatform.v1.VizierService", + "shortName": "VizierService" + }, + "shortName": "CreateStudy" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateStudyRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "study", + "type": "google.cloud.aiplatform_v1.types.Study" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Study", + "shortName": "create_study" + }, + "description": "Sample for CreateStudy", + "file": "aiplatform_v1_generated_vizier_service_create_study_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_VizierService_CreateStudy_sync", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 47, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 48, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_vizier_service_create_study_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.VizierServiceAsyncClient", + "shortName": "VizierServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.VizierServiceAsyncClient.create_trial", + "method": { + "fullName": "google.cloud.aiplatform.v1.VizierService.CreateTrial", + "service": { + "fullName": "google.cloud.aiplatform.v1.VizierService", + "shortName": "VizierService" + }, + "shortName": "CreateTrial" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateTrialRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "trial", + "type": "google.cloud.aiplatform_v1.types.Trial" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Trial", + "shortName": "create_trial" + }, + "description": "Sample for CreateTrial", + "file": "aiplatform_v1_generated_vizier_service_create_trial_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_VizierService_CreateTrial_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_vizier_service_create_trial_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.VizierServiceClient", + "shortName": "VizierServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.VizierServiceClient.create_trial", + "method": { + "fullName": "google.cloud.aiplatform.v1.VizierService.CreateTrial", + "service": { + "fullName": "google.cloud.aiplatform.v1.VizierService", + "shortName": "VizierService" + }, + "shortName": "CreateTrial" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.CreateTrialRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "trial", + "type": "google.cloud.aiplatform_v1.types.Trial" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Trial", + "shortName": "create_trial" + }, + "description": "Sample for CreateTrial", + "file": "aiplatform_v1_generated_vizier_service_create_trial_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_VizierService_CreateTrial_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_vizier_service_create_trial_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.VizierServiceAsyncClient", + "shortName": "VizierServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.VizierServiceAsyncClient.delete_study", + "method": { + "fullName": "google.cloud.aiplatform.v1.VizierService.DeleteStudy", + "service": { + "fullName": "google.cloud.aiplatform.v1.VizierService", + "shortName": "VizierService" + }, + "shortName": "DeleteStudy" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteStudyRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "delete_study" + }, + "description": "Sample for DeleteStudy", + "file": "aiplatform_v1_generated_vizier_service_delete_study_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_VizierService_DeleteStudy_async", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_vizier_service_delete_study_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.VizierServiceClient", + "shortName": "VizierServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.VizierServiceClient.delete_study", + "method": { + "fullName": "google.cloud.aiplatform.v1.VizierService.DeleteStudy", + "service": { + "fullName": "google.cloud.aiplatform.v1.VizierService", + "shortName": "VizierService" + }, + "shortName": "DeleteStudy" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteStudyRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "delete_study" + }, + "description": "Sample for DeleteStudy", + "file": "aiplatform_v1_generated_vizier_service_delete_study_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_VizierService_DeleteStudy_sync", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_vizier_service_delete_study_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.VizierServiceAsyncClient", + "shortName": "VizierServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.VizierServiceAsyncClient.delete_trial", + "method": { + "fullName": "google.cloud.aiplatform.v1.VizierService.DeleteTrial", + "service": { + "fullName": "google.cloud.aiplatform.v1.VizierService", + "shortName": "VizierService" + }, + "shortName": "DeleteTrial" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteTrialRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "delete_trial" + }, + "description": "Sample for DeleteTrial", + "file": "aiplatform_v1_generated_vizier_service_delete_trial_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_VizierService_DeleteTrial_async", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_vizier_service_delete_trial_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.VizierServiceClient", + "shortName": "VizierServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.VizierServiceClient.delete_trial", + "method": { + "fullName": "google.cloud.aiplatform.v1.VizierService.DeleteTrial", + "service": { + "fullName": "google.cloud.aiplatform.v1.VizierService", + "shortName": "VizierService" + }, + "shortName": "DeleteTrial" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.DeleteTrialRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "delete_trial" + }, + "description": "Sample for DeleteTrial", + "file": "aiplatform_v1_generated_vizier_service_delete_trial_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_VizierService_DeleteTrial_sync", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_vizier_service_delete_trial_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.VizierServiceAsyncClient", + "shortName": "VizierServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.VizierServiceAsyncClient.get_study", + "method": { + "fullName": "google.cloud.aiplatform.v1.VizierService.GetStudy", + "service": { + "fullName": "google.cloud.aiplatform.v1.VizierService", + "shortName": "VizierService" + }, + "shortName": "GetStudy" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetStudyRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Study", + "shortName": "get_study" + }, + "description": "Sample for GetStudy", + "file": "aiplatform_v1_generated_vizier_service_get_study_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_VizierService_GetStudy_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_vizier_service_get_study_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.VizierServiceClient", + "shortName": "VizierServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.VizierServiceClient.get_study", + "method": { + "fullName": "google.cloud.aiplatform.v1.VizierService.GetStudy", + "service": { + "fullName": "google.cloud.aiplatform.v1.VizierService", + "shortName": "VizierService" + }, + "shortName": "GetStudy" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetStudyRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Study", + "shortName": "get_study" + }, + "description": "Sample for GetStudy", + "file": "aiplatform_v1_generated_vizier_service_get_study_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_VizierService_GetStudy_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_vizier_service_get_study_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.VizierServiceAsyncClient", + "shortName": "VizierServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.VizierServiceAsyncClient.get_trial", + "method": { + "fullName": "google.cloud.aiplatform.v1.VizierService.GetTrial", + "service": { + "fullName": "google.cloud.aiplatform.v1.VizierService", + "shortName": "VizierService" + }, + "shortName": "GetTrial" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetTrialRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Trial", + "shortName": "get_trial" + }, + "description": "Sample for GetTrial", + "file": "aiplatform_v1_generated_vizier_service_get_trial_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_VizierService_GetTrial_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_vizier_service_get_trial_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.VizierServiceClient", + "shortName": "VizierServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.VizierServiceClient.get_trial", + "method": { + "fullName": "google.cloud.aiplatform.v1.VizierService.GetTrial", + "service": { + "fullName": "google.cloud.aiplatform.v1.VizierService", + "shortName": "VizierService" + }, + "shortName": "GetTrial" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.GetTrialRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Trial", + "shortName": "get_trial" + }, + "description": "Sample for GetTrial", + "file": "aiplatform_v1_generated_vizier_service_get_trial_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_VizierService_GetTrial_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_vizier_service_get_trial_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.VizierServiceAsyncClient", + "shortName": "VizierServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.VizierServiceAsyncClient.list_optimal_trials", + "method": { + "fullName": "google.cloud.aiplatform.v1.VizierService.ListOptimalTrials", + "service": { + "fullName": "google.cloud.aiplatform.v1.VizierService", + "shortName": "VizierService" + }, + "shortName": "ListOptimalTrials" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListOptimalTrialsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.ListOptimalTrialsResponse", + "shortName": "list_optimal_trials" + }, + "description": "Sample for ListOptimalTrials", + "file": "aiplatform_v1_generated_vizier_service_list_optimal_trials_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_VizierService_ListOptimalTrials_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_vizier_service_list_optimal_trials_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.VizierServiceClient", + "shortName": "VizierServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.VizierServiceClient.list_optimal_trials", + "method": { + "fullName": "google.cloud.aiplatform.v1.VizierService.ListOptimalTrials", + "service": { + "fullName": "google.cloud.aiplatform.v1.VizierService", + "shortName": "VizierService" + }, + "shortName": "ListOptimalTrials" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListOptimalTrialsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.ListOptimalTrialsResponse", + "shortName": "list_optimal_trials" + }, + "description": "Sample for ListOptimalTrials", + "file": "aiplatform_v1_generated_vizier_service_list_optimal_trials_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_VizierService_ListOptimalTrials_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_vizier_service_list_optimal_trials_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.VizierServiceAsyncClient", + "shortName": "VizierServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.VizierServiceAsyncClient.list_studies", + "method": { + "fullName": "google.cloud.aiplatform.v1.VizierService.ListStudies", + "service": { + "fullName": "google.cloud.aiplatform.v1.VizierService", + "shortName": "VizierService" + }, + "shortName": "ListStudies" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListStudiesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.vizier_service.pagers.ListStudiesAsyncPager", + "shortName": "list_studies" + }, + "description": "Sample for ListStudies", + "file": "aiplatform_v1_generated_vizier_service_list_studies_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_VizierService_ListStudies_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_vizier_service_list_studies_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.VizierServiceClient", + "shortName": "VizierServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.VizierServiceClient.list_studies", + "method": { + "fullName": "google.cloud.aiplatform.v1.VizierService.ListStudies", + "service": { + "fullName": "google.cloud.aiplatform.v1.VizierService", + "shortName": "VizierService" + }, + "shortName": "ListStudies" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListStudiesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.vizier_service.pagers.ListStudiesPager", + "shortName": "list_studies" + }, + "description": "Sample for ListStudies", + "file": "aiplatform_v1_generated_vizier_service_list_studies_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_VizierService_ListStudies_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_vizier_service_list_studies_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.VizierServiceAsyncClient", + "shortName": "VizierServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.VizierServiceAsyncClient.list_trials", + "method": { + "fullName": "google.cloud.aiplatform.v1.VizierService.ListTrials", + "service": { + "fullName": "google.cloud.aiplatform.v1.VizierService", + "shortName": "VizierService" + }, + "shortName": "ListTrials" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListTrialsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.vizier_service.pagers.ListTrialsAsyncPager", + "shortName": "list_trials" + }, + "description": "Sample for ListTrials", + "file": "aiplatform_v1_generated_vizier_service_list_trials_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_VizierService_ListTrials_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_vizier_service_list_trials_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.VizierServiceClient", + "shortName": "VizierServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.VizierServiceClient.list_trials", + "method": { + "fullName": "google.cloud.aiplatform.v1.VizierService.ListTrials", + "service": { + "fullName": "google.cloud.aiplatform.v1.VizierService", + "shortName": "VizierService" + }, + "shortName": "ListTrials" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.ListTrialsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.services.vizier_service.pagers.ListTrialsPager", + "shortName": "list_trials" + }, + "description": "Sample for ListTrials", + "file": "aiplatform_v1_generated_vizier_service_list_trials_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_VizierService_ListTrials_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_vizier_service_list_trials_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.VizierServiceAsyncClient", + "shortName": "VizierServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.VizierServiceAsyncClient.lookup_study", + "method": { + "fullName": "google.cloud.aiplatform.v1.VizierService.LookupStudy", + "service": { + "fullName": "google.cloud.aiplatform.v1.VizierService", + "shortName": "VizierService" + }, + "shortName": "LookupStudy" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.LookupStudyRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Study", + "shortName": "lookup_study" + }, + "description": "Sample for LookupStudy", + "file": "aiplatform_v1_generated_vizier_service_lookup_study_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_VizierService_LookupStudy_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_vizier_service_lookup_study_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.VizierServiceClient", + "shortName": "VizierServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.VizierServiceClient.lookup_study", + "method": { + "fullName": "google.cloud.aiplatform.v1.VizierService.LookupStudy", + "service": { + "fullName": "google.cloud.aiplatform.v1.VizierService", + "shortName": "VizierService" + }, + "shortName": "LookupStudy" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.LookupStudyRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Study", + "shortName": "lookup_study" + }, + "description": "Sample for LookupStudy", + "file": "aiplatform_v1_generated_vizier_service_lookup_study_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_VizierService_LookupStudy_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_vizier_service_lookup_study_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.VizierServiceAsyncClient", + "shortName": "VizierServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.VizierServiceAsyncClient.stop_trial", + "method": { + "fullName": "google.cloud.aiplatform.v1.VizierService.StopTrial", + "service": { + "fullName": "google.cloud.aiplatform.v1.VizierService", + "shortName": "VizierService" + }, + "shortName": "StopTrial" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.StopTrialRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Trial", + "shortName": "stop_trial" + }, + "description": "Sample for StopTrial", + "file": "aiplatform_v1_generated_vizier_service_stop_trial_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_VizierService_StopTrial_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_vizier_service_stop_trial_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.VizierServiceClient", + "shortName": "VizierServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.VizierServiceClient.stop_trial", + "method": { + "fullName": "google.cloud.aiplatform.v1.VizierService.StopTrial", + "service": { + "fullName": "google.cloud.aiplatform.v1.VizierService", + "shortName": "VizierService" + }, + "shortName": "StopTrial" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.StopTrialRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1.types.Trial", + "shortName": "stop_trial" + }, + "description": "Sample for StopTrial", + "file": "aiplatform_v1_generated_vizier_service_stop_trial_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_VizierService_StopTrial_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_vizier_service_stop_trial_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1.VizierServiceAsyncClient", + "shortName": "VizierServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1.VizierServiceAsyncClient.suggest_trials", + "method": { + "fullName": "google.cloud.aiplatform.v1.VizierService.SuggestTrials", + "service": { + "fullName": "google.cloud.aiplatform.v1.VizierService", + "shortName": "VizierService" + }, + "shortName": "SuggestTrials" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.SuggestTrialsRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "suggest_trials" + }, + "description": "Sample for SuggestTrials", + "file": "aiplatform_v1_generated_vizier_service_suggest_trials_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_VizierService_SuggestTrials_async", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 40, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 47, + "start": 41, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "start": 48, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_vizier_service_suggest_trials_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1.VizierServiceClient", + "shortName": "VizierServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1.VizierServiceClient.suggest_trials", + "method": { + "fullName": "google.cloud.aiplatform.v1.VizierService.SuggestTrials", + "service": { + "fullName": "google.cloud.aiplatform.v1.VizierService", + "shortName": "VizierService" + }, + "shortName": "SuggestTrials" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1.types.SuggestTrialsRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "suggest_trials" + }, + "description": "Sample for SuggestTrials", + "file": "aiplatform_v1_generated_vizier_service_suggest_trials_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1_generated_VizierService_SuggestTrials_sync", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 40, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 47, + "start": 41, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "start": 48, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1_generated_vizier_service_suggest_trials_sync.py" + } + ] +} diff --git a/samples/generated_samples/snippet_metadata_aiplatform_v1beta1.json b/samples/generated_samples/snippet_metadata_aiplatform_v1beta1.json new file mode 100644 index 0000000000..9d8104bef2 --- /dev/null +++ b/samples/generated_samples/snippet_metadata_aiplatform_v1beta1.json @@ -0,0 +1,31216 @@ +{ + "clientLibrary": { + "apis": [ + { + "id": "google.cloud.aiplatform.v1beta1", + "version": "v1beta1" + } + ], + "language": "PYTHON", + "name": "google-cloud-aiplatform" + }, + "snippets": [ + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceAsyncClient", + "shortName": "DatasetServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceAsyncClient.create_dataset", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService.CreateDataset", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "CreateDataset" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateDatasetRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "dataset", + "type": "google.cloud.aiplatform_v1beta1.types.Dataset" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "create_dataset" + }, + "description": "Sample for CreateDataset", + "file": "aiplatform_v1beta1_generated_dataset_service_create_dataset_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_DatasetService_CreateDataset_async", + "segments": [ + { + "end": 54, + "start": 27, + "type": "FULL" + }, + { + "end": 54, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 51, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 55, + "start": 52, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_dataset_service_create_dataset_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceClient", + "shortName": "DatasetServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceClient.create_dataset", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService.CreateDataset", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "CreateDataset" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateDatasetRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "dataset", + "type": "google.cloud.aiplatform_v1beta1.types.Dataset" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "create_dataset" + }, + "description": "Sample for CreateDataset", + "file": "aiplatform_v1beta1_generated_dataset_service_create_dataset_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_DatasetService_CreateDataset_sync", + "segments": [ + { + "end": 54, + "start": 27, + "type": "FULL" + }, + { + "end": 54, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 51, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 55, + "start": 52, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_dataset_service_create_dataset_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceAsyncClient", + "shortName": "DatasetServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceAsyncClient.delete_dataset", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService.DeleteDataset", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "DeleteDataset" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteDatasetRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_dataset" + }, + "description": "Sample for DeleteDataset", + "file": "aiplatform_v1beta1_generated_dataset_service_delete_dataset_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_DatasetService_DeleteDataset_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_dataset_service_delete_dataset_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceClient", + "shortName": "DatasetServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceClient.delete_dataset", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService.DeleteDataset", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "DeleteDataset" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteDatasetRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_dataset" + }, + "description": "Sample for DeleteDataset", + "file": "aiplatform_v1beta1_generated_dataset_service_delete_dataset_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_DatasetService_DeleteDataset_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_dataset_service_delete_dataset_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceAsyncClient", + "shortName": "DatasetServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceAsyncClient.export_data", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService.ExportData", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "ExportData" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ExportDataRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "export_config", + "type": "google.cloud.aiplatform_v1beta1.types.ExportDataConfig" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "export_data" + }, + "description": "Sample for ExportData", + "file": "aiplatform_v1beta1_generated_dataset_service_export_data_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_DatasetService_ExportData_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_dataset_service_export_data_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceClient", + "shortName": "DatasetServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceClient.export_data", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService.ExportData", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "ExportData" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ExportDataRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "export_config", + "type": "google.cloud.aiplatform_v1beta1.types.ExportDataConfig" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "export_data" + }, + "description": "Sample for ExportData", + "file": "aiplatform_v1beta1_generated_dataset_service_export_data_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_DatasetService_ExportData_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_dataset_service_export_data_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceAsyncClient", + "shortName": "DatasetServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceAsyncClient.get_annotation_spec", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService.GetAnnotationSpec", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "GetAnnotationSpec" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetAnnotationSpecRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.AnnotationSpec", + "shortName": "get_annotation_spec" + }, + "description": "Sample for GetAnnotationSpec", + "file": "aiplatform_v1beta1_generated_dataset_service_get_annotation_spec_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_DatasetService_GetAnnotationSpec_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_dataset_service_get_annotation_spec_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceClient", + "shortName": "DatasetServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceClient.get_annotation_spec", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService.GetAnnotationSpec", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "GetAnnotationSpec" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetAnnotationSpecRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.AnnotationSpec", + "shortName": "get_annotation_spec" + }, + "description": "Sample for GetAnnotationSpec", + "file": "aiplatform_v1beta1_generated_dataset_service_get_annotation_spec_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_DatasetService_GetAnnotationSpec_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_dataset_service_get_annotation_spec_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceAsyncClient", + "shortName": "DatasetServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceAsyncClient.get_dataset", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService.GetDataset", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "GetDataset" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetDatasetRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Dataset", + "shortName": "get_dataset" + }, + "description": "Sample for GetDataset", + "file": "aiplatform_v1beta1_generated_dataset_service_get_dataset_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_DatasetService_GetDataset_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_dataset_service_get_dataset_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceClient", + "shortName": "DatasetServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceClient.get_dataset", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService.GetDataset", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "GetDataset" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetDatasetRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Dataset", + "shortName": "get_dataset" + }, + "description": "Sample for GetDataset", + "file": "aiplatform_v1beta1_generated_dataset_service_get_dataset_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_DatasetService_GetDataset_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_dataset_service_get_dataset_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceAsyncClient", + "shortName": "DatasetServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceAsyncClient.import_data", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService.ImportData", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "ImportData" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ImportDataRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "import_configs", + "type": "Sequence[google.cloud.aiplatform_v1beta1.types.ImportDataConfig]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "import_data" + }, + "description": "Sample for ImportData", + "file": "aiplatform_v1beta1_generated_dataset_service_import_data_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_DatasetService_ImportData_async", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_dataset_service_import_data_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceClient", + "shortName": "DatasetServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceClient.import_data", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService.ImportData", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "ImportData" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ImportDataRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "import_configs", + "type": "Sequence[google.cloud.aiplatform_v1beta1.types.ImportDataConfig]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "import_data" + }, + "description": "Sample for ImportData", + "file": "aiplatform_v1beta1_generated_dataset_service_import_data_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_DatasetService_ImportData_sync", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_dataset_service_import_data_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceAsyncClient", + "shortName": "DatasetServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceAsyncClient.list_annotations", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService.ListAnnotations", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "ListAnnotations" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListAnnotationsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.dataset_service.pagers.ListAnnotationsAsyncPager", + "shortName": "list_annotations" + }, + "description": "Sample for ListAnnotations", + "file": "aiplatform_v1beta1_generated_dataset_service_list_annotations_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_DatasetService_ListAnnotations_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_dataset_service_list_annotations_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceClient", + "shortName": "DatasetServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceClient.list_annotations", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService.ListAnnotations", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "ListAnnotations" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListAnnotationsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.dataset_service.pagers.ListAnnotationsPager", + "shortName": "list_annotations" + }, + "description": "Sample for ListAnnotations", + "file": "aiplatform_v1beta1_generated_dataset_service_list_annotations_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_DatasetService_ListAnnotations_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_dataset_service_list_annotations_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceAsyncClient", + "shortName": "DatasetServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceAsyncClient.list_data_items", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService.ListDataItems", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "ListDataItems" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListDataItemsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.dataset_service.pagers.ListDataItemsAsyncPager", + "shortName": "list_data_items" + }, + "description": "Sample for ListDataItems", + "file": "aiplatform_v1beta1_generated_dataset_service_list_data_items_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_DatasetService_ListDataItems_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_dataset_service_list_data_items_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceClient", + "shortName": "DatasetServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceClient.list_data_items", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService.ListDataItems", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "ListDataItems" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListDataItemsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.dataset_service.pagers.ListDataItemsPager", + "shortName": "list_data_items" + }, + "description": "Sample for ListDataItems", + "file": "aiplatform_v1beta1_generated_dataset_service_list_data_items_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_DatasetService_ListDataItems_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_dataset_service_list_data_items_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceAsyncClient", + "shortName": "DatasetServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceAsyncClient.list_datasets", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService.ListDatasets", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "ListDatasets" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListDatasetsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.dataset_service.pagers.ListDatasetsAsyncPager", + "shortName": "list_datasets" + }, + "description": "Sample for ListDatasets", + "file": "aiplatform_v1beta1_generated_dataset_service_list_datasets_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_DatasetService_ListDatasets_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_dataset_service_list_datasets_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceClient", + "shortName": "DatasetServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceClient.list_datasets", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService.ListDatasets", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "ListDatasets" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListDatasetsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.dataset_service.pagers.ListDatasetsPager", + "shortName": "list_datasets" + }, + "description": "Sample for ListDatasets", + "file": "aiplatform_v1beta1_generated_dataset_service_list_datasets_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_DatasetService_ListDatasets_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_dataset_service_list_datasets_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceAsyncClient", + "shortName": "DatasetServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceAsyncClient.update_dataset", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService.UpdateDataset", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "UpdateDataset" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdateDatasetRequest" + }, + { + "name": "dataset", + "type": "google.cloud.aiplatform_v1beta1.types.Dataset" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Dataset", + "shortName": "update_dataset" + }, + "description": "Sample for UpdateDataset", + "file": "aiplatform_v1beta1_generated_dataset_service_update_dataset_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_DatasetService_UpdateDataset_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_dataset_service_update_dataset_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceClient", + "shortName": "DatasetServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.DatasetServiceClient.update_dataset", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService.UpdateDataset", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.DatasetService", + "shortName": "DatasetService" + }, + "shortName": "UpdateDataset" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdateDatasetRequest" + }, + { + "name": "dataset", + "type": "google.cloud.aiplatform_v1beta1.types.Dataset" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Dataset", + "shortName": "update_dataset" + }, + "description": "Sample for UpdateDataset", + "file": "aiplatform_v1beta1_generated_dataset_service_update_dataset_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_DatasetService_UpdateDataset_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_dataset_service_update_dataset_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.EndpointServiceAsyncClient", + "shortName": "EndpointServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.EndpointServiceAsyncClient.create_endpoint", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.EndpointService.CreateEndpoint", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.EndpointService", + "shortName": "EndpointService" + }, + "shortName": "CreateEndpoint" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateEndpointRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "endpoint", + "type": "google.cloud.aiplatform_v1beta1.types.Endpoint" + }, + { + "name": "endpoint_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "create_endpoint" + }, + "description": "Sample for CreateEndpoint", + "file": "aiplatform_v1beta1_generated_endpoint_service_create_endpoint_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_EndpointService_CreateEndpoint_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_endpoint_service_create_endpoint_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.EndpointServiceClient", + "shortName": "EndpointServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.EndpointServiceClient.create_endpoint", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.EndpointService.CreateEndpoint", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.EndpointService", + "shortName": "EndpointService" + }, + "shortName": "CreateEndpoint" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateEndpointRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "endpoint", + "type": "google.cloud.aiplatform_v1beta1.types.Endpoint" + }, + { + "name": "endpoint_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "create_endpoint" + }, + "description": "Sample for CreateEndpoint", + "file": "aiplatform_v1beta1_generated_endpoint_service_create_endpoint_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_EndpointService_CreateEndpoint_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_endpoint_service_create_endpoint_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.EndpointServiceAsyncClient", + "shortName": "EndpointServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.EndpointServiceAsyncClient.delete_endpoint", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.EndpointService.DeleteEndpoint", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.EndpointService", + "shortName": "EndpointService" + }, + "shortName": "DeleteEndpoint" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteEndpointRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_endpoint" + }, + "description": "Sample for DeleteEndpoint", + "file": "aiplatform_v1beta1_generated_endpoint_service_delete_endpoint_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_EndpointService_DeleteEndpoint_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_endpoint_service_delete_endpoint_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.EndpointServiceClient", + "shortName": "EndpointServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.EndpointServiceClient.delete_endpoint", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.EndpointService.DeleteEndpoint", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.EndpointService", + "shortName": "EndpointService" + }, + "shortName": "DeleteEndpoint" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteEndpointRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_endpoint" + }, + "description": "Sample for DeleteEndpoint", + "file": "aiplatform_v1beta1_generated_endpoint_service_delete_endpoint_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_EndpointService_DeleteEndpoint_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_endpoint_service_delete_endpoint_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.EndpointServiceAsyncClient", + "shortName": "EndpointServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.EndpointServiceAsyncClient.deploy_model", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.EndpointService.DeployModel", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.EndpointService", + "shortName": "EndpointService" + }, + "shortName": "DeployModel" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeployModelRequest" + }, + { + "name": "endpoint", + "type": "str" + }, + { + "name": "deployed_model", + "type": "google.cloud.aiplatform_v1beta1.types.DeployedModel" + }, + { + "name": "traffic_split", + "type": "Mapping[str, int]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "deploy_model" + }, + "description": "Sample for DeployModel", + "file": "aiplatform_v1beta1_generated_endpoint_service_deploy_model_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_EndpointService_DeployModel_async", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_endpoint_service_deploy_model_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.EndpointServiceClient", + "shortName": "EndpointServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.EndpointServiceClient.deploy_model", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.EndpointService.DeployModel", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.EndpointService", + "shortName": "EndpointService" + }, + "shortName": "DeployModel" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeployModelRequest" + }, + { + "name": "endpoint", + "type": "str" + }, + { + "name": "deployed_model", + "type": "google.cloud.aiplatform_v1beta1.types.DeployedModel" + }, + { + "name": "traffic_split", + "type": "Mapping[str, int]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "deploy_model" + }, + "description": "Sample for DeployModel", + "file": "aiplatform_v1beta1_generated_endpoint_service_deploy_model_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_EndpointService_DeployModel_sync", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_endpoint_service_deploy_model_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.EndpointServiceAsyncClient", + "shortName": "EndpointServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.EndpointServiceAsyncClient.get_endpoint", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.EndpointService.GetEndpoint", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.EndpointService", + "shortName": "EndpointService" + }, + "shortName": "GetEndpoint" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetEndpointRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Endpoint", + "shortName": "get_endpoint" + }, + "description": "Sample for GetEndpoint", + "file": "aiplatform_v1beta1_generated_endpoint_service_get_endpoint_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_EndpointService_GetEndpoint_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_endpoint_service_get_endpoint_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.EndpointServiceClient", + "shortName": "EndpointServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.EndpointServiceClient.get_endpoint", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.EndpointService.GetEndpoint", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.EndpointService", + "shortName": "EndpointService" + }, + "shortName": "GetEndpoint" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetEndpointRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Endpoint", + "shortName": "get_endpoint" + }, + "description": "Sample for GetEndpoint", + "file": "aiplatform_v1beta1_generated_endpoint_service_get_endpoint_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_EndpointService_GetEndpoint_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_endpoint_service_get_endpoint_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.EndpointServiceAsyncClient", + "shortName": "EndpointServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.EndpointServiceAsyncClient.list_endpoints", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.EndpointService.ListEndpoints", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.EndpointService", + "shortName": "EndpointService" + }, + "shortName": "ListEndpoints" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListEndpointsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.endpoint_service.pagers.ListEndpointsAsyncPager", + "shortName": "list_endpoints" + }, + "description": "Sample for ListEndpoints", + "file": "aiplatform_v1beta1_generated_endpoint_service_list_endpoints_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_EndpointService_ListEndpoints_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_endpoint_service_list_endpoints_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.EndpointServiceClient", + "shortName": "EndpointServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.EndpointServiceClient.list_endpoints", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.EndpointService.ListEndpoints", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.EndpointService", + "shortName": "EndpointService" + }, + "shortName": "ListEndpoints" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListEndpointsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.endpoint_service.pagers.ListEndpointsPager", + "shortName": "list_endpoints" + }, + "description": "Sample for ListEndpoints", + "file": "aiplatform_v1beta1_generated_endpoint_service_list_endpoints_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_EndpointService_ListEndpoints_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_endpoint_service_list_endpoints_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.EndpointServiceAsyncClient", + "shortName": "EndpointServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.EndpointServiceAsyncClient.undeploy_model", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.EndpointService.UndeployModel", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.EndpointService", + "shortName": "EndpointService" + }, + "shortName": "UndeployModel" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UndeployModelRequest" + }, + { + "name": "endpoint", + "type": "str" + }, + { + "name": "deployed_model_id", + "type": "str" + }, + { + "name": "traffic_split", + "type": "Mapping[str, int]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "undeploy_model" + }, + "description": "Sample for UndeployModel", + "file": "aiplatform_v1beta1_generated_endpoint_service_undeploy_model_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_EndpointService_UndeployModel_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_endpoint_service_undeploy_model_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.EndpointServiceClient", + "shortName": "EndpointServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.EndpointServiceClient.undeploy_model", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.EndpointService.UndeployModel", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.EndpointService", + "shortName": "EndpointService" + }, + "shortName": "UndeployModel" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UndeployModelRequest" + }, + { + "name": "endpoint", + "type": "str" + }, + { + "name": "deployed_model_id", + "type": "str" + }, + { + "name": "traffic_split", + "type": "Mapping[str, int]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "undeploy_model" + }, + "description": "Sample for UndeployModel", + "file": "aiplatform_v1beta1_generated_endpoint_service_undeploy_model_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_EndpointService_UndeployModel_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_endpoint_service_undeploy_model_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.EndpointServiceAsyncClient", + "shortName": "EndpointServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.EndpointServiceAsyncClient.update_endpoint", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.EndpointService.UpdateEndpoint", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.EndpointService", + "shortName": "EndpointService" + }, + "shortName": "UpdateEndpoint" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdateEndpointRequest" + }, + { + "name": "endpoint", + "type": "google.cloud.aiplatform_v1beta1.types.Endpoint" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Endpoint", + "shortName": "update_endpoint" + }, + "description": "Sample for UpdateEndpoint", + "file": "aiplatform_v1beta1_generated_endpoint_service_update_endpoint_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_EndpointService_UpdateEndpoint_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_endpoint_service_update_endpoint_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.EndpointServiceClient", + "shortName": "EndpointServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.EndpointServiceClient.update_endpoint", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.EndpointService.UpdateEndpoint", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.EndpointService", + "shortName": "EndpointService" + }, + "shortName": "UpdateEndpoint" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdateEndpointRequest" + }, + { + "name": "endpoint", + "type": "google.cloud.aiplatform_v1beta1.types.Endpoint" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Endpoint", + "shortName": "update_endpoint" + }, + "description": "Sample for UpdateEndpoint", + "file": "aiplatform_v1beta1_generated_endpoint_service_update_endpoint_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_EndpointService_UpdateEndpoint_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_endpoint_service_update_endpoint_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreOnlineServingServiceAsyncClient", + "shortName": "FeaturestoreOnlineServingServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreOnlineServingServiceAsyncClient.read_feature_values", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreOnlineServingService.ReadFeatureValues", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreOnlineServingService", + "shortName": "FeaturestoreOnlineServingService" + }, + "shortName": "ReadFeatureValues" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ReadFeatureValuesRequest" + }, + { + "name": "entity_type", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.ReadFeatureValuesResponse", + "shortName": "read_feature_values" + }, + "description": "Sample for ReadFeatureValues", + "file": "aiplatform_v1beta1_generated_featurestore_online_serving_service_read_feature_values_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreOnlineServingService_ReadFeatureValues_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_online_serving_service_read_feature_values_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreOnlineServingServiceClient", + "shortName": "FeaturestoreOnlineServingServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreOnlineServingServiceClient.read_feature_values", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreOnlineServingService.ReadFeatureValues", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreOnlineServingService", + "shortName": "FeaturestoreOnlineServingService" + }, + "shortName": "ReadFeatureValues" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ReadFeatureValuesRequest" + }, + { + "name": "entity_type", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.ReadFeatureValuesResponse", + "shortName": "read_feature_values" + }, + "description": "Sample for ReadFeatureValues", + "file": "aiplatform_v1beta1_generated_featurestore_online_serving_service_read_feature_values_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreOnlineServingService_ReadFeatureValues_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_online_serving_service_read_feature_values_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreOnlineServingServiceAsyncClient", + "shortName": "FeaturestoreOnlineServingServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreOnlineServingServiceAsyncClient.streaming_read_feature_values", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreOnlineServingService.StreamingReadFeatureValues", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreOnlineServingService", + "shortName": "FeaturestoreOnlineServingService" + }, + "shortName": "StreamingReadFeatureValues" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.StreamingReadFeatureValuesRequest" + }, + { + "name": "entity_type", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "Iterable[google.cloud.aiplatform_v1beta1.types.ReadFeatureValuesResponse]", + "shortName": "streaming_read_feature_values" + }, + "description": "Sample for StreamingReadFeatureValues", + "file": "aiplatform_v1beta1_generated_featurestore_online_serving_service_streaming_read_feature_values_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreOnlineServingService_StreamingReadFeatureValues_async", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_online_serving_service_streaming_read_feature_values_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreOnlineServingServiceClient", + "shortName": "FeaturestoreOnlineServingServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreOnlineServingServiceClient.streaming_read_feature_values", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreOnlineServingService.StreamingReadFeatureValues", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreOnlineServingService", + "shortName": "FeaturestoreOnlineServingService" + }, + "shortName": "StreamingReadFeatureValues" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.StreamingReadFeatureValuesRequest" + }, + { + "name": "entity_type", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "Iterable[google.cloud.aiplatform_v1beta1.types.ReadFeatureValuesResponse]", + "shortName": "streaming_read_feature_values" + }, + "description": "Sample for StreamingReadFeatureValues", + "file": "aiplatform_v1beta1_generated_featurestore_online_serving_service_streaming_read_feature_values_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreOnlineServingService_StreamingReadFeatureValues_sync", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_online_serving_service_streaming_read_feature_values_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient.batch_create_features", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.BatchCreateFeatures", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "BatchCreateFeatures" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.BatchCreateFeaturesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "requests", + "type": "Sequence[google.cloud.aiplatform_v1beta1.types.CreateFeatureRequest]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "batch_create_features" + }, + "description": "Sample for BatchCreateFeatures", + "file": "aiplatform_v1beta1_generated_featurestore_service_batch_create_features_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_BatchCreateFeatures_async", + "segments": [ + { + "end": 54, + "start": 27, + "type": "FULL" + }, + { + "end": 54, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 51, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 55, + "start": 52, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_batch_create_features_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient.batch_create_features", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.BatchCreateFeatures", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "BatchCreateFeatures" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.BatchCreateFeaturesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "requests", + "type": "Sequence[google.cloud.aiplatform_v1beta1.types.CreateFeatureRequest]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "batch_create_features" + }, + "description": "Sample for BatchCreateFeatures", + "file": "aiplatform_v1beta1_generated_featurestore_service_batch_create_features_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_BatchCreateFeatures_sync", + "segments": [ + { + "end": 54, + "start": 27, + "type": "FULL" + }, + { + "end": 54, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 51, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 55, + "start": 52, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_batch_create_features_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient.batch_read_feature_values", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.BatchReadFeatureValues", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "BatchReadFeatureValues" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.BatchReadFeatureValuesRequest" + }, + { + "name": "featurestore", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "batch_read_feature_values" + }, + "description": "Sample for BatchReadFeatureValues", + "file": "aiplatform_v1beta1_generated_featurestore_service_batch_read_feature_values_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_BatchReadFeatureValues_async", + "segments": [ + { + "end": 61, + "start": 27, + "type": "FULL" + }, + { + "end": 61, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 51, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 58, + "start": 52, + "type": "REQUEST_EXECUTION" + }, + { + "end": 62, + "start": 59, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_batch_read_feature_values_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient.batch_read_feature_values", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.BatchReadFeatureValues", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "BatchReadFeatureValues" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.BatchReadFeatureValuesRequest" + }, + { + "name": "featurestore", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "batch_read_feature_values" + }, + "description": "Sample for BatchReadFeatureValues", + "file": "aiplatform_v1beta1_generated_featurestore_service_batch_read_feature_values_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_BatchReadFeatureValues_sync", + "segments": [ + { + "end": 61, + "start": 27, + "type": "FULL" + }, + { + "end": 61, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 51, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 58, + "start": 52, + "type": "REQUEST_EXECUTION" + }, + { + "end": 62, + "start": 59, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_batch_read_feature_values_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient.create_entity_type", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.CreateEntityType", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "CreateEntityType" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateEntityTypeRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "entity_type", + "type": "google.cloud.aiplatform_v1beta1.types.EntityType" + }, + { + "name": "entity_type_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "create_entity_type" + }, + "description": "Sample for CreateEntityType", + "file": "aiplatform_v1beta1_generated_featurestore_service_create_entity_type_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_CreateEntityType_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_create_entity_type_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient.create_entity_type", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.CreateEntityType", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "CreateEntityType" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateEntityTypeRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "entity_type", + "type": "google.cloud.aiplatform_v1beta1.types.EntityType" + }, + { + "name": "entity_type_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "create_entity_type" + }, + "description": "Sample for CreateEntityType", + "file": "aiplatform_v1beta1_generated_featurestore_service_create_entity_type_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_CreateEntityType_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_create_entity_type_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient.create_feature", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.CreateFeature", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "CreateFeature" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateFeatureRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "feature", + "type": "google.cloud.aiplatform_v1beta1.types.Feature" + }, + { + "name": "feature_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "create_feature" + }, + "description": "Sample for CreateFeature", + "file": "aiplatform_v1beta1_generated_featurestore_service_create_feature_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_CreateFeature_async", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_create_feature_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient.create_feature", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.CreateFeature", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "CreateFeature" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateFeatureRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "feature", + "type": "google.cloud.aiplatform_v1beta1.types.Feature" + }, + { + "name": "feature_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "create_feature" + }, + "description": "Sample for CreateFeature", + "file": "aiplatform_v1beta1_generated_featurestore_service_create_feature_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_CreateFeature_sync", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_create_feature_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient.create_featurestore", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.CreateFeaturestore", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "CreateFeaturestore" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateFeaturestoreRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "featurestore", + "type": "google.cloud.aiplatform_v1beta1.types.Featurestore" + }, + { + "name": "featurestore_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "create_featurestore" + }, + "description": "Sample for CreateFeaturestore", + "file": "aiplatform_v1beta1_generated_featurestore_service_create_featurestore_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_CreateFeaturestore_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_create_featurestore_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient.create_featurestore", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.CreateFeaturestore", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "CreateFeaturestore" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateFeaturestoreRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "featurestore", + "type": "google.cloud.aiplatform_v1beta1.types.Featurestore" + }, + { + "name": "featurestore_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "create_featurestore" + }, + "description": "Sample for CreateFeaturestore", + "file": "aiplatform_v1beta1_generated_featurestore_service_create_featurestore_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_CreateFeaturestore_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_create_featurestore_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient.delete_entity_type", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.DeleteEntityType", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "DeleteEntityType" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteEntityTypeRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "force", + "type": "bool" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_entity_type" + }, + "description": "Sample for DeleteEntityType", + "file": "aiplatform_v1beta1_generated_featurestore_service_delete_entity_type_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_DeleteEntityType_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_delete_entity_type_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient.delete_entity_type", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.DeleteEntityType", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "DeleteEntityType" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteEntityTypeRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "force", + "type": "bool" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_entity_type" + }, + "description": "Sample for DeleteEntityType", + "file": "aiplatform_v1beta1_generated_featurestore_service_delete_entity_type_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_DeleteEntityType_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_delete_entity_type_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient.delete_feature", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.DeleteFeature", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "DeleteFeature" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteFeatureRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_feature" + }, + "description": "Sample for DeleteFeature", + "file": "aiplatform_v1beta1_generated_featurestore_service_delete_feature_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_DeleteFeature_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_delete_feature_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient.delete_feature", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.DeleteFeature", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "DeleteFeature" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteFeatureRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_feature" + }, + "description": "Sample for DeleteFeature", + "file": "aiplatform_v1beta1_generated_featurestore_service_delete_feature_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_DeleteFeature_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_delete_feature_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient.delete_featurestore", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.DeleteFeaturestore", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "DeleteFeaturestore" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteFeaturestoreRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "force", + "type": "bool" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_featurestore" + }, + "description": "Sample for DeleteFeaturestore", + "file": "aiplatform_v1beta1_generated_featurestore_service_delete_featurestore_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_DeleteFeaturestore_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_delete_featurestore_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient.delete_featurestore", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.DeleteFeaturestore", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "DeleteFeaturestore" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteFeaturestoreRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "force", + "type": "bool" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_featurestore" + }, + "description": "Sample for DeleteFeaturestore", + "file": "aiplatform_v1beta1_generated_featurestore_service_delete_featurestore_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_DeleteFeaturestore_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_delete_featurestore_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient.export_feature_values", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.ExportFeatureValues", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "ExportFeatureValues" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ExportFeatureValuesRequest" + }, + { + "name": "entity_type", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "export_feature_values" + }, + "description": "Sample for ExportFeatureValues", + "file": "aiplatform_v1beta1_generated_featurestore_service_export_feature_values_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_ExportFeatureValues_async", + "segments": [ + { + "end": 56, + "start": 27, + "type": "FULL" + }, + { + "end": 56, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 53, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 57, + "start": 54, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_export_feature_values_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient.export_feature_values", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.ExportFeatureValues", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "ExportFeatureValues" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ExportFeatureValuesRequest" + }, + { + "name": "entity_type", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "export_feature_values" + }, + "description": "Sample for ExportFeatureValues", + "file": "aiplatform_v1beta1_generated_featurestore_service_export_feature_values_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_ExportFeatureValues_sync", + "segments": [ + { + "end": 56, + "start": 27, + "type": "FULL" + }, + { + "end": 56, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 53, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 57, + "start": 54, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_export_feature_values_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient.get_entity_type", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.GetEntityType", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "GetEntityType" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetEntityTypeRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.EntityType", + "shortName": "get_entity_type" + }, + "description": "Sample for GetEntityType", + "file": "aiplatform_v1beta1_generated_featurestore_service_get_entity_type_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_GetEntityType_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_get_entity_type_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient.get_entity_type", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.GetEntityType", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "GetEntityType" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetEntityTypeRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.EntityType", + "shortName": "get_entity_type" + }, + "description": "Sample for GetEntityType", + "file": "aiplatform_v1beta1_generated_featurestore_service_get_entity_type_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_GetEntityType_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_get_entity_type_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient.get_feature", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.GetFeature", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "GetFeature" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetFeatureRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Feature", + "shortName": "get_feature" + }, + "description": "Sample for GetFeature", + "file": "aiplatform_v1beta1_generated_featurestore_service_get_feature_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_GetFeature_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_get_feature_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient.get_feature", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.GetFeature", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "GetFeature" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetFeatureRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Feature", + "shortName": "get_feature" + }, + "description": "Sample for GetFeature", + "file": "aiplatform_v1beta1_generated_featurestore_service_get_feature_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_GetFeature_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_get_feature_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient.get_featurestore", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.GetFeaturestore", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "GetFeaturestore" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetFeaturestoreRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Featurestore", + "shortName": "get_featurestore" + }, + "description": "Sample for GetFeaturestore", + "file": "aiplatform_v1beta1_generated_featurestore_service_get_featurestore_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_GetFeaturestore_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_get_featurestore_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient.get_featurestore", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.GetFeaturestore", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "GetFeaturestore" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetFeaturestoreRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Featurestore", + "shortName": "get_featurestore" + }, + "description": "Sample for GetFeaturestore", + "file": "aiplatform_v1beta1_generated_featurestore_service_get_featurestore_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_GetFeaturestore_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_get_featurestore_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient.import_feature_values", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.ImportFeatureValues", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "ImportFeatureValues" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ImportFeatureValuesRequest" + }, + { + "name": "entity_type", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "import_feature_values" + }, + "description": "Sample for ImportFeatureValues", + "file": "aiplatform_v1beta1_generated_featurestore_service_import_feature_values_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_ImportFeatureValues_async", + "segments": [ + { + "end": 57, + "start": 27, + "type": "FULL" + }, + { + "end": 57, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 47, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 54, + "start": 48, + "type": "REQUEST_EXECUTION" + }, + { + "end": 58, + "start": 55, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_import_feature_values_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient.import_feature_values", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.ImportFeatureValues", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "ImportFeatureValues" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ImportFeatureValuesRequest" + }, + { + "name": "entity_type", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "import_feature_values" + }, + "description": "Sample for ImportFeatureValues", + "file": "aiplatform_v1beta1_generated_featurestore_service_import_feature_values_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_ImportFeatureValues_sync", + "segments": [ + { + "end": 57, + "start": 27, + "type": "FULL" + }, + { + "end": 57, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 47, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 54, + "start": 48, + "type": "REQUEST_EXECUTION" + }, + { + "end": 58, + "start": 55, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_import_feature_values_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient.list_entity_types", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.ListEntityTypes", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "ListEntityTypes" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListEntityTypesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.featurestore_service.pagers.ListEntityTypesAsyncPager", + "shortName": "list_entity_types" + }, + "description": "Sample for ListEntityTypes", + "file": "aiplatform_v1beta1_generated_featurestore_service_list_entity_types_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_ListEntityTypes_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_list_entity_types_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient.list_entity_types", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.ListEntityTypes", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "ListEntityTypes" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListEntityTypesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.featurestore_service.pagers.ListEntityTypesPager", + "shortName": "list_entity_types" + }, + "description": "Sample for ListEntityTypes", + "file": "aiplatform_v1beta1_generated_featurestore_service_list_entity_types_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_ListEntityTypes_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_list_entity_types_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient.list_features", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.ListFeatures", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "ListFeatures" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListFeaturesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.featurestore_service.pagers.ListFeaturesAsyncPager", + "shortName": "list_features" + }, + "description": "Sample for ListFeatures", + "file": "aiplatform_v1beta1_generated_featurestore_service_list_features_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_ListFeatures_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_list_features_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient.list_features", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.ListFeatures", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "ListFeatures" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListFeaturesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.featurestore_service.pagers.ListFeaturesPager", + "shortName": "list_features" + }, + "description": "Sample for ListFeatures", + "file": "aiplatform_v1beta1_generated_featurestore_service_list_features_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_ListFeatures_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_list_features_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient.list_featurestores", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.ListFeaturestores", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "ListFeaturestores" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListFeaturestoresRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.featurestore_service.pagers.ListFeaturestoresAsyncPager", + "shortName": "list_featurestores" + }, + "description": "Sample for ListFeaturestores", + "file": "aiplatform_v1beta1_generated_featurestore_service_list_featurestores_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_ListFeaturestores_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_list_featurestores_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient.list_featurestores", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.ListFeaturestores", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "ListFeaturestores" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListFeaturestoresRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.featurestore_service.pagers.ListFeaturestoresPager", + "shortName": "list_featurestores" + }, + "description": "Sample for ListFeaturestores", + "file": "aiplatform_v1beta1_generated_featurestore_service_list_featurestores_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_ListFeaturestores_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_list_featurestores_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient.search_features", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.SearchFeatures", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "SearchFeatures" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.SearchFeaturesRequest" + }, + { + "name": "location", + "type": "str" + }, + { + "name": "query", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.featurestore_service.pagers.SearchFeaturesAsyncPager", + "shortName": "search_features" + }, + "description": "Sample for SearchFeatures", + "file": "aiplatform_v1beta1_generated_featurestore_service_search_features_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_SearchFeatures_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_search_features_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient.search_features", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.SearchFeatures", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "SearchFeatures" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.SearchFeaturesRequest" + }, + { + "name": "location", + "type": "str" + }, + { + "name": "query", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.featurestore_service.pagers.SearchFeaturesPager", + "shortName": "search_features" + }, + "description": "Sample for SearchFeatures", + "file": "aiplatform_v1beta1_generated_featurestore_service_search_features_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_SearchFeatures_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_search_features_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient.update_entity_type", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.UpdateEntityType", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "UpdateEntityType" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdateEntityTypeRequest" + }, + { + "name": "entity_type", + "type": "google.cloud.aiplatform_v1beta1.types.EntityType" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.EntityType", + "shortName": "update_entity_type" + }, + "description": "Sample for UpdateEntityType", + "file": "aiplatform_v1beta1_generated_featurestore_service_update_entity_type_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_UpdateEntityType_async", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_update_entity_type_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient.update_entity_type", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.UpdateEntityType", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "UpdateEntityType" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdateEntityTypeRequest" + }, + { + "name": "entity_type", + "type": "google.cloud.aiplatform_v1beta1.types.EntityType" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.EntityType", + "shortName": "update_entity_type" + }, + "description": "Sample for UpdateEntityType", + "file": "aiplatform_v1beta1_generated_featurestore_service_update_entity_type_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_UpdateEntityType_sync", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_update_entity_type_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient.update_feature", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.UpdateFeature", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "UpdateFeature" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdateFeatureRequest" + }, + { + "name": "feature", + "type": "google.cloud.aiplatform_v1beta1.types.Feature" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Feature", + "shortName": "update_feature" + }, + "description": "Sample for UpdateFeature", + "file": "aiplatform_v1beta1_generated_featurestore_service_update_feature_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_UpdateFeature_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_update_feature_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient.update_feature", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.UpdateFeature", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "UpdateFeature" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdateFeatureRequest" + }, + { + "name": "feature", + "type": "google.cloud.aiplatform_v1beta1.types.Feature" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Feature", + "shortName": "update_feature" + }, + "description": "Sample for UpdateFeature", + "file": "aiplatform_v1beta1_generated_featurestore_service_update_feature_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_UpdateFeature_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_update_feature_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient", + "shortName": "FeaturestoreServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceAsyncClient.update_featurestore", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.UpdateFeaturestore", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "UpdateFeaturestore" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdateFeaturestoreRequest" + }, + { + "name": "featurestore", + "type": "google.cloud.aiplatform_v1beta1.types.Featurestore" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "update_featurestore" + }, + "description": "Sample for UpdateFeaturestore", + "file": "aiplatform_v1beta1_generated_featurestore_service_update_featurestore_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_UpdateFeaturestore_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_update_featurestore_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient", + "shortName": "FeaturestoreServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.FeaturestoreServiceClient.update_featurestore", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService.UpdateFeaturestore", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.FeaturestoreService", + "shortName": "FeaturestoreService" + }, + "shortName": "UpdateFeaturestore" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdateFeaturestoreRequest" + }, + { + "name": "featurestore", + "type": "google.cloud.aiplatform_v1beta1.types.Featurestore" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "update_featurestore" + }, + "description": "Sample for UpdateFeaturestore", + "file": "aiplatform_v1beta1_generated_featurestore_service_update_featurestore_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_FeaturestoreService_UpdateFeaturestore_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_featurestore_service_update_featurestore_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.IndexEndpointServiceAsyncClient", + "shortName": "IndexEndpointServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.IndexEndpointServiceAsyncClient.create_index_endpoint", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexEndpointService.CreateIndexEndpoint", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexEndpointService", + "shortName": "IndexEndpointService" + }, + "shortName": "CreateIndexEndpoint" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateIndexEndpointRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "index_endpoint", + "type": "google.cloud.aiplatform_v1beta1.types.IndexEndpoint" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "create_index_endpoint" + }, + "description": "Sample for CreateIndexEndpoint", + "file": "aiplatform_v1beta1_generated_index_endpoint_service_create_index_endpoint_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_IndexEndpointService_CreateIndexEndpoint_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_index_endpoint_service_create_index_endpoint_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.IndexEndpointServiceClient", + "shortName": "IndexEndpointServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.IndexEndpointServiceClient.create_index_endpoint", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexEndpointService.CreateIndexEndpoint", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexEndpointService", + "shortName": "IndexEndpointService" + }, + "shortName": "CreateIndexEndpoint" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateIndexEndpointRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "index_endpoint", + "type": "google.cloud.aiplatform_v1beta1.types.IndexEndpoint" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "create_index_endpoint" + }, + "description": "Sample for CreateIndexEndpoint", + "file": "aiplatform_v1beta1_generated_index_endpoint_service_create_index_endpoint_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_IndexEndpointService_CreateIndexEndpoint_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_index_endpoint_service_create_index_endpoint_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.IndexEndpointServiceAsyncClient", + "shortName": "IndexEndpointServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.IndexEndpointServiceAsyncClient.delete_index_endpoint", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexEndpointService.DeleteIndexEndpoint", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexEndpointService", + "shortName": "IndexEndpointService" + }, + "shortName": "DeleteIndexEndpoint" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteIndexEndpointRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_index_endpoint" + }, + "description": "Sample for DeleteIndexEndpoint", + "file": "aiplatform_v1beta1_generated_index_endpoint_service_delete_index_endpoint_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_IndexEndpointService_DeleteIndexEndpoint_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_index_endpoint_service_delete_index_endpoint_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.IndexEndpointServiceClient", + "shortName": "IndexEndpointServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.IndexEndpointServiceClient.delete_index_endpoint", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexEndpointService.DeleteIndexEndpoint", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexEndpointService", + "shortName": "IndexEndpointService" + }, + "shortName": "DeleteIndexEndpoint" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteIndexEndpointRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_index_endpoint" + }, + "description": "Sample for DeleteIndexEndpoint", + "file": "aiplatform_v1beta1_generated_index_endpoint_service_delete_index_endpoint_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_IndexEndpointService_DeleteIndexEndpoint_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_index_endpoint_service_delete_index_endpoint_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.IndexEndpointServiceAsyncClient", + "shortName": "IndexEndpointServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.IndexEndpointServiceAsyncClient.deploy_index", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexEndpointService.DeployIndex", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexEndpointService", + "shortName": "IndexEndpointService" + }, + "shortName": "DeployIndex" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeployIndexRequest" + }, + { + "name": "index_endpoint", + "type": "str" + }, + { + "name": "deployed_index", + "type": "google.cloud.aiplatform_v1beta1.types.DeployedIndex" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "deploy_index" + }, + "description": "Sample for DeployIndex", + "file": "aiplatform_v1beta1_generated_index_endpoint_service_deploy_index_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_IndexEndpointService_DeployIndex_async", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_index_endpoint_service_deploy_index_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.IndexEndpointServiceClient", + "shortName": "IndexEndpointServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.IndexEndpointServiceClient.deploy_index", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexEndpointService.DeployIndex", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexEndpointService", + "shortName": "IndexEndpointService" + }, + "shortName": "DeployIndex" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeployIndexRequest" + }, + { + "name": "index_endpoint", + "type": "str" + }, + { + "name": "deployed_index", + "type": "google.cloud.aiplatform_v1beta1.types.DeployedIndex" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "deploy_index" + }, + "description": "Sample for DeployIndex", + "file": "aiplatform_v1beta1_generated_index_endpoint_service_deploy_index_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_IndexEndpointService_DeployIndex_sync", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_index_endpoint_service_deploy_index_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.IndexEndpointServiceAsyncClient", + "shortName": "IndexEndpointServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.IndexEndpointServiceAsyncClient.get_index_endpoint", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexEndpointService.GetIndexEndpoint", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexEndpointService", + "shortName": "IndexEndpointService" + }, + "shortName": "GetIndexEndpoint" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetIndexEndpointRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.IndexEndpoint", + "shortName": "get_index_endpoint" + }, + "description": "Sample for GetIndexEndpoint", + "file": "aiplatform_v1beta1_generated_index_endpoint_service_get_index_endpoint_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_IndexEndpointService_GetIndexEndpoint_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_index_endpoint_service_get_index_endpoint_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.IndexEndpointServiceClient", + "shortName": "IndexEndpointServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.IndexEndpointServiceClient.get_index_endpoint", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexEndpointService.GetIndexEndpoint", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexEndpointService", + "shortName": "IndexEndpointService" + }, + "shortName": "GetIndexEndpoint" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetIndexEndpointRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.IndexEndpoint", + "shortName": "get_index_endpoint" + }, + "description": "Sample for GetIndexEndpoint", + "file": "aiplatform_v1beta1_generated_index_endpoint_service_get_index_endpoint_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_IndexEndpointService_GetIndexEndpoint_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_index_endpoint_service_get_index_endpoint_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.IndexEndpointServiceAsyncClient", + "shortName": "IndexEndpointServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.IndexEndpointServiceAsyncClient.list_index_endpoints", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexEndpointService.ListIndexEndpoints", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexEndpointService", + "shortName": "IndexEndpointService" + }, + "shortName": "ListIndexEndpoints" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListIndexEndpointsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.index_endpoint_service.pagers.ListIndexEndpointsAsyncPager", + "shortName": "list_index_endpoints" + }, + "description": "Sample for ListIndexEndpoints", + "file": "aiplatform_v1beta1_generated_index_endpoint_service_list_index_endpoints_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_IndexEndpointService_ListIndexEndpoints_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_index_endpoint_service_list_index_endpoints_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.IndexEndpointServiceClient", + "shortName": "IndexEndpointServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.IndexEndpointServiceClient.list_index_endpoints", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexEndpointService.ListIndexEndpoints", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexEndpointService", + "shortName": "IndexEndpointService" + }, + "shortName": "ListIndexEndpoints" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListIndexEndpointsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.index_endpoint_service.pagers.ListIndexEndpointsPager", + "shortName": "list_index_endpoints" + }, + "description": "Sample for ListIndexEndpoints", + "file": "aiplatform_v1beta1_generated_index_endpoint_service_list_index_endpoints_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_IndexEndpointService_ListIndexEndpoints_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_index_endpoint_service_list_index_endpoints_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.IndexEndpointServiceAsyncClient", + "shortName": "IndexEndpointServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.IndexEndpointServiceAsyncClient.mutate_deployed_index", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexEndpointService.MutateDeployedIndex", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexEndpointService", + "shortName": "IndexEndpointService" + }, + "shortName": "MutateDeployedIndex" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.MutateDeployedIndexRequest" + }, + { + "name": "index_endpoint", + "type": "str" + }, + { + "name": "deployed_index", + "type": "google.cloud.aiplatform_v1beta1.types.DeployedIndex" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "mutate_deployed_index" + }, + "description": "Sample for MutateDeployedIndex", + "file": "aiplatform_v1beta1_generated_index_endpoint_service_mutate_deployed_index_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_IndexEndpointService_MutateDeployedIndex_async", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_index_endpoint_service_mutate_deployed_index_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.IndexEndpointServiceClient", + "shortName": "IndexEndpointServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.IndexEndpointServiceClient.mutate_deployed_index", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexEndpointService.MutateDeployedIndex", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexEndpointService", + "shortName": "IndexEndpointService" + }, + "shortName": "MutateDeployedIndex" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.MutateDeployedIndexRequest" + }, + { + "name": "index_endpoint", + "type": "str" + }, + { + "name": "deployed_index", + "type": "google.cloud.aiplatform_v1beta1.types.DeployedIndex" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "mutate_deployed_index" + }, + "description": "Sample for MutateDeployedIndex", + "file": "aiplatform_v1beta1_generated_index_endpoint_service_mutate_deployed_index_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_IndexEndpointService_MutateDeployedIndex_sync", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_index_endpoint_service_mutate_deployed_index_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.IndexEndpointServiceAsyncClient", + "shortName": "IndexEndpointServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.IndexEndpointServiceAsyncClient.undeploy_index", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexEndpointService.UndeployIndex", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexEndpointService", + "shortName": "IndexEndpointService" + }, + "shortName": "UndeployIndex" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UndeployIndexRequest" + }, + { + "name": "index_endpoint", + "type": "str" + }, + { + "name": "deployed_index_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "undeploy_index" + }, + "description": "Sample for UndeployIndex", + "file": "aiplatform_v1beta1_generated_index_endpoint_service_undeploy_index_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_IndexEndpointService_UndeployIndex_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_index_endpoint_service_undeploy_index_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.IndexEndpointServiceClient", + "shortName": "IndexEndpointServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.IndexEndpointServiceClient.undeploy_index", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexEndpointService.UndeployIndex", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexEndpointService", + "shortName": "IndexEndpointService" + }, + "shortName": "UndeployIndex" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UndeployIndexRequest" + }, + { + "name": "index_endpoint", + "type": "str" + }, + { + "name": "deployed_index_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "undeploy_index" + }, + "description": "Sample for UndeployIndex", + "file": "aiplatform_v1beta1_generated_index_endpoint_service_undeploy_index_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_IndexEndpointService_UndeployIndex_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_index_endpoint_service_undeploy_index_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.IndexEndpointServiceAsyncClient", + "shortName": "IndexEndpointServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.IndexEndpointServiceAsyncClient.update_index_endpoint", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexEndpointService.UpdateIndexEndpoint", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexEndpointService", + "shortName": "IndexEndpointService" + }, + "shortName": "UpdateIndexEndpoint" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdateIndexEndpointRequest" + }, + { + "name": "index_endpoint", + "type": "google.cloud.aiplatform_v1beta1.types.IndexEndpoint" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.IndexEndpoint", + "shortName": "update_index_endpoint" + }, + "description": "Sample for UpdateIndexEndpoint", + "file": "aiplatform_v1beta1_generated_index_endpoint_service_update_index_endpoint_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_IndexEndpointService_UpdateIndexEndpoint_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_index_endpoint_service_update_index_endpoint_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.IndexEndpointServiceClient", + "shortName": "IndexEndpointServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.IndexEndpointServiceClient.update_index_endpoint", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexEndpointService.UpdateIndexEndpoint", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexEndpointService", + "shortName": "IndexEndpointService" + }, + "shortName": "UpdateIndexEndpoint" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdateIndexEndpointRequest" + }, + { + "name": "index_endpoint", + "type": "google.cloud.aiplatform_v1beta1.types.IndexEndpoint" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.IndexEndpoint", + "shortName": "update_index_endpoint" + }, + "description": "Sample for UpdateIndexEndpoint", + "file": "aiplatform_v1beta1_generated_index_endpoint_service_update_index_endpoint_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_IndexEndpointService_UpdateIndexEndpoint_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_index_endpoint_service_update_index_endpoint_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.IndexServiceAsyncClient", + "shortName": "IndexServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.IndexServiceAsyncClient.create_index", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexService.CreateIndex", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexService", + "shortName": "IndexService" + }, + "shortName": "CreateIndex" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateIndexRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "index", + "type": "google.cloud.aiplatform_v1beta1.types.Index" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "create_index" + }, + "description": "Sample for CreateIndex", + "file": "aiplatform_v1beta1_generated_index_service_create_index_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_IndexService_CreateIndex_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_index_service_create_index_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.IndexServiceClient", + "shortName": "IndexServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.IndexServiceClient.create_index", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexService.CreateIndex", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexService", + "shortName": "IndexService" + }, + "shortName": "CreateIndex" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateIndexRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "index", + "type": "google.cloud.aiplatform_v1beta1.types.Index" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "create_index" + }, + "description": "Sample for CreateIndex", + "file": "aiplatform_v1beta1_generated_index_service_create_index_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_IndexService_CreateIndex_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_index_service_create_index_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.IndexServiceAsyncClient", + "shortName": "IndexServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.IndexServiceAsyncClient.delete_index", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexService.DeleteIndex", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexService", + "shortName": "IndexService" + }, + "shortName": "DeleteIndex" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteIndexRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_index" + }, + "description": "Sample for DeleteIndex", + "file": "aiplatform_v1beta1_generated_index_service_delete_index_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_IndexService_DeleteIndex_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_index_service_delete_index_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.IndexServiceClient", + "shortName": "IndexServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.IndexServiceClient.delete_index", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexService.DeleteIndex", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexService", + "shortName": "IndexService" + }, + "shortName": "DeleteIndex" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteIndexRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_index" + }, + "description": "Sample for DeleteIndex", + "file": "aiplatform_v1beta1_generated_index_service_delete_index_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_IndexService_DeleteIndex_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_index_service_delete_index_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.IndexServiceAsyncClient", + "shortName": "IndexServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.IndexServiceAsyncClient.get_index", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexService.GetIndex", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexService", + "shortName": "IndexService" + }, + "shortName": "GetIndex" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetIndexRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Index", + "shortName": "get_index" + }, + "description": "Sample for GetIndex", + "file": "aiplatform_v1beta1_generated_index_service_get_index_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_IndexService_GetIndex_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_index_service_get_index_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.IndexServiceClient", + "shortName": "IndexServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.IndexServiceClient.get_index", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexService.GetIndex", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexService", + "shortName": "IndexService" + }, + "shortName": "GetIndex" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetIndexRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Index", + "shortName": "get_index" + }, + "description": "Sample for GetIndex", + "file": "aiplatform_v1beta1_generated_index_service_get_index_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_IndexService_GetIndex_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_index_service_get_index_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.IndexServiceAsyncClient", + "shortName": "IndexServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.IndexServiceAsyncClient.list_indexes", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexService.ListIndexes", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexService", + "shortName": "IndexService" + }, + "shortName": "ListIndexes" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListIndexesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.index_service.pagers.ListIndexesAsyncPager", + "shortName": "list_indexes" + }, + "description": "Sample for ListIndexes", + "file": "aiplatform_v1beta1_generated_index_service_list_indexes_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_IndexService_ListIndexes_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_index_service_list_indexes_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.IndexServiceClient", + "shortName": "IndexServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.IndexServiceClient.list_indexes", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexService.ListIndexes", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexService", + "shortName": "IndexService" + }, + "shortName": "ListIndexes" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListIndexesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.index_service.pagers.ListIndexesPager", + "shortName": "list_indexes" + }, + "description": "Sample for ListIndexes", + "file": "aiplatform_v1beta1_generated_index_service_list_indexes_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_IndexService_ListIndexes_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_index_service_list_indexes_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.IndexServiceAsyncClient", + "shortName": "IndexServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.IndexServiceAsyncClient.update_index", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexService.UpdateIndex", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexService", + "shortName": "IndexService" + }, + "shortName": "UpdateIndex" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdateIndexRequest" + }, + { + "name": "index", + "type": "google.cloud.aiplatform_v1beta1.types.Index" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "update_index" + }, + "description": "Sample for UpdateIndex", + "file": "aiplatform_v1beta1_generated_index_service_update_index_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_IndexService_UpdateIndex_async", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_index_service_update_index_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.IndexServiceClient", + "shortName": "IndexServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.IndexServiceClient.update_index", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexService.UpdateIndex", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.IndexService", + "shortName": "IndexService" + }, + "shortName": "UpdateIndex" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdateIndexRequest" + }, + { + "name": "index", + "type": "google.cloud.aiplatform_v1beta1.types.Index" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "update_index" + }, + "description": "Sample for UpdateIndex", + "file": "aiplatform_v1beta1_generated_index_service_update_index_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_IndexService_UpdateIndex_sync", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_index_service_update_index_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient.cancel_batch_prediction_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.CancelBatchPredictionJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "CancelBatchPredictionJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CancelBatchPredictionJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "cancel_batch_prediction_job" + }, + "description": "Sample for CancelBatchPredictionJob", + "file": "aiplatform_v1beta1_generated_job_service_cancel_batch_prediction_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_CancelBatchPredictionJob_async", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_cancel_batch_prediction_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient.cancel_batch_prediction_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.CancelBatchPredictionJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "CancelBatchPredictionJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CancelBatchPredictionJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "cancel_batch_prediction_job" + }, + "description": "Sample for CancelBatchPredictionJob", + "file": "aiplatform_v1beta1_generated_job_service_cancel_batch_prediction_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_CancelBatchPredictionJob_sync", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_cancel_batch_prediction_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient.cancel_custom_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.CancelCustomJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "CancelCustomJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CancelCustomJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "cancel_custom_job" + }, + "description": "Sample for CancelCustomJob", + "file": "aiplatform_v1beta1_generated_job_service_cancel_custom_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_CancelCustomJob_async", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_cancel_custom_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient.cancel_custom_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.CancelCustomJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "CancelCustomJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CancelCustomJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "cancel_custom_job" + }, + "description": "Sample for CancelCustomJob", + "file": "aiplatform_v1beta1_generated_job_service_cancel_custom_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_CancelCustomJob_sync", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_cancel_custom_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient.cancel_data_labeling_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.CancelDataLabelingJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "CancelDataLabelingJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CancelDataLabelingJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "cancel_data_labeling_job" + }, + "description": "Sample for CancelDataLabelingJob", + "file": "aiplatform_v1beta1_generated_job_service_cancel_data_labeling_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_CancelDataLabelingJob_async", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_cancel_data_labeling_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient.cancel_data_labeling_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.CancelDataLabelingJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "CancelDataLabelingJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CancelDataLabelingJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "cancel_data_labeling_job" + }, + "description": "Sample for CancelDataLabelingJob", + "file": "aiplatform_v1beta1_generated_job_service_cancel_data_labeling_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_CancelDataLabelingJob_sync", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_cancel_data_labeling_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient.cancel_hyperparameter_tuning_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.CancelHyperparameterTuningJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "CancelHyperparameterTuningJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CancelHyperparameterTuningJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "cancel_hyperparameter_tuning_job" + }, + "description": "Sample for CancelHyperparameterTuningJob", + "file": "aiplatform_v1beta1_generated_job_service_cancel_hyperparameter_tuning_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_CancelHyperparameterTuningJob_async", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_cancel_hyperparameter_tuning_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient.cancel_hyperparameter_tuning_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.CancelHyperparameterTuningJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "CancelHyperparameterTuningJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CancelHyperparameterTuningJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "cancel_hyperparameter_tuning_job" + }, + "description": "Sample for CancelHyperparameterTuningJob", + "file": "aiplatform_v1beta1_generated_job_service_cancel_hyperparameter_tuning_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_CancelHyperparameterTuningJob_sync", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_cancel_hyperparameter_tuning_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient.create_batch_prediction_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.CreateBatchPredictionJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "CreateBatchPredictionJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateBatchPredictionJobRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "batch_prediction_job", + "type": "google.cloud.aiplatform_v1beta1.types.BatchPredictionJob" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.BatchPredictionJob", + "shortName": "create_batch_prediction_job" + }, + "description": "Sample for CreateBatchPredictionJob", + "file": "aiplatform_v1beta1_generated_job_service_create_batch_prediction_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_CreateBatchPredictionJob_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_create_batch_prediction_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient.create_batch_prediction_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.CreateBatchPredictionJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "CreateBatchPredictionJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateBatchPredictionJobRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "batch_prediction_job", + "type": "google.cloud.aiplatform_v1beta1.types.BatchPredictionJob" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.BatchPredictionJob", + "shortName": "create_batch_prediction_job" + }, + "description": "Sample for CreateBatchPredictionJob", + "file": "aiplatform_v1beta1_generated_job_service_create_batch_prediction_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_CreateBatchPredictionJob_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 46, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 47, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_create_batch_prediction_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient.create_custom_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.CreateCustomJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "CreateCustomJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateCustomJobRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "custom_job", + "type": "google.cloud.aiplatform_v1beta1.types.CustomJob" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.CustomJob", + "shortName": "create_custom_job" + }, + "description": "Sample for CreateCustomJob", + "file": "aiplatform_v1beta1_generated_job_service_create_custom_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_CreateCustomJob_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_create_custom_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient.create_custom_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.CreateCustomJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "CreateCustomJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateCustomJobRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "custom_job", + "type": "google.cloud.aiplatform_v1beta1.types.CustomJob" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.CustomJob", + "shortName": "create_custom_job" + }, + "description": "Sample for CreateCustomJob", + "file": "aiplatform_v1beta1_generated_job_service_create_custom_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_CreateCustomJob_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_create_custom_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient.create_data_labeling_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.CreateDataLabelingJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "CreateDataLabelingJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateDataLabelingJobRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "data_labeling_job", + "type": "google.cloud.aiplatform_v1beta1.types.DataLabelingJob" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.DataLabelingJob", + "shortName": "create_data_labeling_job" + }, + "description": "Sample for CreateDataLabelingJob", + "file": "aiplatform_v1beta1_generated_job_service_create_data_labeling_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_CreateDataLabelingJob_async", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 47, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 48, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_create_data_labeling_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient.create_data_labeling_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.CreateDataLabelingJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "CreateDataLabelingJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateDataLabelingJobRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "data_labeling_job", + "type": "google.cloud.aiplatform_v1beta1.types.DataLabelingJob" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.DataLabelingJob", + "shortName": "create_data_labeling_job" + }, + "description": "Sample for CreateDataLabelingJob", + "file": "aiplatform_v1beta1_generated_job_service_create_data_labeling_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_CreateDataLabelingJob_sync", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 47, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 48, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_create_data_labeling_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient.create_hyperparameter_tuning_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.CreateHyperparameterTuningJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "CreateHyperparameterTuningJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateHyperparameterTuningJobRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "hyperparameter_tuning_job", + "type": "google.cloud.aiplatform_v1beta1.types.HyperparameterTuningJob" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.HyperparameterTuningJob", + "shortName": "create_hyperparameter_tuning_job" + }, + "description": "Sample for CreateHyperparameterTuningJob", + "file": "aiplatform_v1beta1_generated_job_service_create_hyperparameter_tuning_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_CreateHyperparameterTuningJob_async", + "segments": [ + { + "end": 56, + "start": 27, + "type": "FULL" + }, + { + "end": 56, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 50, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 53, + "start": 51, + "type": "REQUEST_EXECUTION" + }, + { + "end": 57, + "start": 54, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_create_hyperparameter_tuning_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient.create_hyperparameter_tuning_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.CreateHyperparameterTuningJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "CreateHyperparameterTuningJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateHyperparameterTuningJobRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "hyperparameter_tuning_job", + "type": "google.cloud.aiplatform_v1beta1.types.HyperparameterTuningJob" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.HyperparameterTuningJob", + "shortName": "create_hyperparameter_tuning_job" + }, + "description": "Sample for CreateHyperparameterTuningJob", + "file": "aiplatform_v1beta1_generated_job_service_create_hyperparameter_tuning_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_CreateHyperparameterTuningJob_sync", + "segments": [ + { + "end": 56, + "start": 27, + "type": "FULL" + }, + { + "end": 56, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 50, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 53, + "start": 51, + "type": "REQUEST_EXECUTION" + }, + { + "end": 57, + "start": 54, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_create_hyperparameter_tuning_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient.create_model_deployment_monitoring_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.CreateModelDeploymentMonitoringJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "CreateModelDeploymentMonitoringJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateModelDeploymentMonitoringJobRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "model_deployment_monitoring_job", + "type": "google.cloud.aiplatform_v1beta1.types.ModelDeploymentMonitoringJob" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.ModelDeploymentMonitoringJob", + "shortName": "create_model_deployment_monitoring_job" + }, + "description": "Sample for CreateModelDeploymentMonitoringJob", + "file": "aiplatform_v1beta1_generated_job_service_create_model_deployment_monitoring_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_CreateModelDeploymentMonitoringJob_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_create_model_deployment_monitoring_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient.create_model_deployment_monitoring_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.CreateModelDeploymentMonitoringJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "CreateModelDeploymentMonitoringJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateModelDeploymentMonitoringJobRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "model_deployment_monitoring_job", + "type": "google.cloud.aiplatform_v1beta1.types.ModelDeploymentMonitoringJob" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.ModelDeploymentMonitoringJob", + "shortName": "create_model_deployment_monitoring_job" + }, + "description": "Sample for CreateModelDeploymentMonitoringJob", + "file": "aiplatform_v1beta1_generated_job_service_create_model_deployment_monitoring_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_CreateModelDeploymentMonitoringJob_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_create_model_deployment_monitoring_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient.delete_batch_prediction_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.DeleteBatchPredictionJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "DeleteBatchPredictionJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteBatchPredictionJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_batch_prediction_job" + }, + "description": "Sample for DeleteBatchPredictionJob", + "file": "aiplatform_v1beta1_generated_job_service_delete_batch_prediction_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_DeleteBatchPredictionJob_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_delete_batch_prediction_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient.delete_batch_prediction_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.DeleteBatchPredictionJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "DeleteBatchPredictionJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteBatchPredictionJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_batch_prediction_job" + }, + "description": "Sample for DeleteBatchPredictionJob", + "file": "aiplatform_v1beta1_generated_job_service_delete_batch_prediction_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_DeleteBatchPredictionJob_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_delete_batch_prediction_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient.delete_custom_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.DeleteCustomJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "DeleteCustomJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteCustomJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_custom_job" + }, + "description": "Sample for DeleteCustomJob", + "file": "aiplatform_v1beta1_generated_job_service_delete_custom_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_DeleteCustomJob_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_delete_custom_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient.delete_custom_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.DeleteCustomJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "DeleteCustomJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteCustomJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_custom_job" + }, + "description": "Sample for DeleteCustomJob", + "file": "aiplatform_v1beta1_generated_job_service_delete_custom_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_DeleteCustomJob_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_delete_custom_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient.delete_data_labeling_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.DeleteDataLabelingJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "DeleteDataLabelingJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteDataLabelingJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_data_labeling_job" + }, + "description": "Sample for DeleteDataLabelingJob", + "file": "aiplatform_v1beta1_generated_job_service_delete_data_labeling_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_DeleteDataLabelingJob_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_delete_data_labeling_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient.delete_data_labeling_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.DeleteDataLabelingJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "DeleteDataLabelingJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteDataLabelingJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_data_labeling_job" + }, + "description": "Sample for DeleteDataLabelingJob", + "file": "aiplatform_v1beta1_generated_job_service_delete_data_labeling_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_DeleteDataLabelingJob_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_delete_data_labeling_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient.delete_hyperparameter_tuning_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.DeleteHyperparameterTuningJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "DeleteHyperparameterTuningJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteHyperparameterTuningJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_hyperparameter_tuning_job" + }, + "description": "Sample for DeleteHyperparameterTuningJob", + "file": "aiplatform_v1beta1_generated_job_service_delete_hyperparameter_tuning_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_DeleteHyperparameterTuningJob_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_delete_hyperparameter_tuning_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient.delete_hyperparameter_tuning_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.DeleteHyperparameterTuningJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "DeleteHyperparameterTuningJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteHyperparameterTuningJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_hyperparameter_tuning_job" + }, + "description": "Sample for DeleteHyperparameterTuningJob", + "file": "aiplatform_v1beta1_generated_job_service_delete_hyperparameter_tuning_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_DeleteHyperparameterTuningJob_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_delete_hyperparameter_tuning_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient.delete_model_deployment_monitoring_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.DeleteModelDeploymentMonitoringJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "DeleteModelDeploymentMonitoringJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteModelDeploymentMonitoringJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_model_deployment_monitoring_job" + }, + "description": "Sample for DeleteModelDeploymentMonitoringJob", + "file": "aiplatform_v1beta1_generated_job_service_delete_model_deployment_monitoring_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_DeleteModelDeploymentMonitoringJob_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_delete_model_deployment_monitoring_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient.delete_model_deployment_monitoring_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.DeleteModelDeploymentMonitoringJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "DeleteModelDeploymentMonitoringJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteModelDeploymentMonitoringJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_model_deployment_monitoring_job" + }, + "description": "Sample for DeleteModelDeploymentMonitoringJob", + "file": "aiplatform_v1beta1_generated_job_service_delete_model_deployment_monitoring_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_DeleteModelDeploymentMonitoringJob_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_delete_model_deployment_monitoring_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient.get_batch_prediction_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.GetBatchPredictionJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "GetBatchPredictionJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetBatchPredictionJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.BatchPredictionJob", + "shortName": "get_batch_prediction_job" + }, + "description": "Sample for GetBatchPredictionJob", + "file": "aiplatform_v1beta1_generated_job_service_get_batch_prediction_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_GetBatchPredictionJob_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_get_batch_prediction_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient.get_batch_prediction_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.GetBatchPredictionJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "GetBatchPredictionJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetBatchPredictionJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.BatchPredictionJob", + "shortName": "get_batch_prediction_job" + }, + "description": "Sample for GetBatchPredictionJob", + "file": "aiplatform_v1beta1_generated_job_service_get_batch_prediction_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_GetBatchPredictionJob_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_get_batch_prediction_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient.get_custom_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.GetCustomJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "GetCustomJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetCustomJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.CustomJob", + "shortName": "get_custom_job" + }, + "description": "Sample for GetCustomJob", + "file": "aiplatform_v1beta1_generated_job_service_get_custom_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_GetCustomJob_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_get_custom_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient.get_custom_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.GetCustomJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "GetCustomJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetCustomJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.CustomJob", + "shortName": "get_custom_job" + }, + "description": "Sample for GetCustomJob", + "file": "aiplatform_v1beta1_generated_job_service_get_custom_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_GetCustomJob_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_get_custom_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient.get_data_labeling_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.GetDataLabelingJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "GetDataLabelingJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetDataLabelingJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.DataLabelingJob", + "shortName": "get_data_labeling_job" + }, + "description": "Sample for GetDataLabelingJob", + "file": "aiplatform_v1beta1_generated_job_service_get_data_labeling_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_GetDataLabelingJob_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_get_data_labeling_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient.get_data_labeling_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.GetDataLabelingJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "GetDataLabelingJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetDataLabelingJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.DataLabelingJob", + "shortName": "get_data_labeling_job" + }, + "description": "Sample for GetDataLabelingJob", + "file": "aiplatform_v1beta1_generated_job_service_get_data_labeling_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_GetDataLabelingJob_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_get_data_labeling_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient.get_hyperparameter_tuning_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.GetHyperparameterTuningJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "GetHyperparameterTuningJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetHyperparameterTuningJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.HyperparameterTuningJob", + "shortName": "get_hyperparameter_tuning_job" + }, + "description": "Sample for GetHyperparameterTuningJob", + "file": "aiplatform_v1beta1_generated_job_service_get_hyperparameter_tuning_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_GetHyperparameterTuningJob_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_get_hyperparameter_tuning_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient.get_hyperparameter_tuning_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.GetHyperparameterTuningJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "GetHyperparameterTuningJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetHyperparameterTuningJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.HyperparameterTuningJob", + "shortName": "get_hyperparameter_tuning_job" + }, + "description": "Sample for GetHyperparameterTuningJob", + "file": "aiplatform_v1beta1_generated_job_service_get_hyperparameter_tuning_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_GetHyperparameterTuningJob_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_get_hyperparameter_tuning_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient.get_model_deployment_monitoring_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.GetModelDeploymentMonitoringJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "GetModelDeploymentMonitoringJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetModelDeploymentMonitoringJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.ModelDeploymentMonitoringJob", + "shortName": "get_model_deployment_monitoring_job" + }, + "description": "Sample for GetModelDeploymentMonitoringJob", + "file": "aiplatform_v1beta1_generated_job_service_get_model_deployment_monitoring_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_GetModelDeploymentMonitoringJob_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_get_model_deployment_monitoring_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient.get_model_deployment_monitoring_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.GetModelDeploymentMonitoringJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "GetModelDeploymentMonitoringJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetModelDeploymentMonitoringJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.ModelDeploymentMonitoringJob", + "shortName": "get_model_deployment_monitoring_job" + }, + "description": "Sample for GetModelDeploymentMonitoringJob", + "file": "aiplatform_v1beta1_generated_job_service_get_model_deployment_monitoring_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_GetModelDeploymentMonitoringJob_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_get_model_deployment_monitoring_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient.list_batch_prediction_jobs", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.ListBatchPredictionJobs", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "ListBatchPredictionJobs" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListBatchPredictionJobsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.job_service.pagers.ListBatchPredictionJobsAsyncPager", + "shortName": "list_batch_prediction_jobs" + }, + "description": "Sample for ListBatchPredictionJobs", + "file": "aiplatform_v1beta1_generated_job_service_list_batch_prediction_jobs_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_ListBatchPredictionJobs_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_list_batch_prediction_jobs_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient.list_batch_prediction_jobs", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.ListBatchPredictionJobs", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "ListBatchPredictionJobs" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListBatchPredictionJobsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.job_service.pagers.ListBatchPredictionJobsPager", + "shortName": "list_batch_prediction_jobs" + }, + "description": "Sample for ListBatchPredictionJobs", + "file": "aiplatform_v1beta1_generated_job_service_list_batch_prediction_jobs_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_ListBatchPredictionJobs_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_list_batch_prediction_jobs_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient.list_custom_jobs", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.ListCustomJobs", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "ListCustomJobs" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListCustomJobsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.job_service.pagers.ListCustomJobsAsyncPager", + "shortName": "list_custom_jobs" + }, + "description": "Sample for ListCustomJobs", + "file": "aiplatform_v1beta1_generated_job_service_list_custom_jobs_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_ListCustomJobs_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_list_custom_jobs_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient.list_custom_jobs", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.ListCustomJobs", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "ListCustomJobs" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListCustomJobsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.job_service.pagers.ListCustomJobsPager", + "shortName": "list_custom_jobs" + }, + "description": "Sample for ListCustomJobs", + "file": "aiplatform_v1beta1_generated_job_service_list_custom_jobs_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_ListCustomJobs_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_list_custom_jobs_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient.list_data_labeling_jobs", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.ListDataLabelingJobs", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "ListDataLabelingJobs" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListDataLabelingJobsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.job_service.pagers.ListDataLabelingJobsAsyncPager", + "shortName": "list_data_labeling_jobs" + }, + "description": "Sample for ListDataLabelingJobs", + "file": "aiplatform_v1beta1_generated_job_service_list_data_labeling_jobs_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_ListDataLabelingJobs_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_list_data_labeling_jobs_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient.list_data_labeling_jobs", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.ListDataLabelingJobs", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "ListDataLabelingJobs" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListDataLabelingJobsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.job_service.pagers.ListDataLabelingJobsPager", + "shortName": "list_data_labeling_jobs" + }, + "description": "Sample for ListDataLabelingJobs", + "file": "aiplatform_v1beta1_generated_job_service_list_data_labeling_jobs_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_ListDataLabelingJobs_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_list_data_labeling_jobs_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient.list_hyperparameter_tuning_jobs", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.ListHyperparameterTuningJobs", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "ListHyperparameterTuningJobs" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListHyperparameterTuningJobsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.job_service.pagers.ListHyperparameterTuningJobsAsyncPager", + "shortName": "list_hyperparameter_tuning_jobs" + }, + "description": "Sample for ListHyperparameterTuningJobs", + "file": "aiplatform_v1beta1_generated_job_service_list_hyperparameter_tuning_jobs_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_ListHyperparameterTuningJobs_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_list_hyperparameter_tuning_jobs_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient.list_hyperparameter_tuning_jobs", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.ListHyperparameterTuningJobs", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "ListHyperparameterTuningJobs" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListHyperparameterTuningJobsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.job_service.pagers.ListHyperparameterTuningJobsPager", + "shortName": "list_hyperparameter_tuning_jobs" + }, + "description": "Sample for ListHyperparameterTuningJobs", + "file": "aiplatform_v1beta1_generated_job_service_list_hyperparameter_tuning_jobs_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_ListHyperparameterTuningJobs_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_list_hyperparameter_tuning_jobs_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient.list_model_deployment_monitoring_jobs", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.ListModelDeploymentMonitoringJobs", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "ListModelDeploymentMonitoringJobs" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListModelDeploymentMonitoringJobsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.job_service.pagers.ListModelDeploymentMonitoringJobsAsyncPager", + "shortName": "list_model_deployment_monitoring_jobs" + }, + "description": "Sample for ListModelDeploymentMonitoringJobs", + "file": "aiplatform_v1beta1_generated_job_service_list_model_deployment_monitoring_jobs_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_ListModelDeploymentMonitoringJobs_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_list_model_deployment_monitoring_jobs_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient.list_model_deployment_monitoring_jobs", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.ListModelDeploymentMonitoringJobs", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "ListModelDeploymentMonitoringJobs" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListModelDeploymentMonitoringJobsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.job_service.pagers.ListModelDeploymentMonitoringJobsPager", + "shortName": "list_model_deployment_monitoring_jobs" + }, + "description": "Sample for ListModelDeploymentMonitoringJobs", + "file": "aiplatform_v1beta1_generated_job_service_list_model_deployment_monitoring_jobs_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_ListModelDeploymentMonitoringJobs_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_list_model_deployment_monitoring_jobs_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient.pause_model_deployment_monitoring_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.PauseModelDeploymentMonitoringJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "PauseModelDeploymentMonitoringJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.PauseModelDeploymentMonitoringJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "pause_model_deployment_monitoring_job" + }, + "description": "Sample for PauseModelDeploymentMonitoringJob", + "file": "aiplatform_v1beta1_generated_job_service_pause_model_deployment_monitoring_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_PauseModelDeploymentMonitoringJob_async", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_pause_model_deployment_monitoring_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient.pause_model_deployment_monitoring_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.PauseModelDeploymentMonitoringJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "PauseModelDeploymentMonitoringJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.PauseModelDeploymentMonitoringJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "pause_model_deployment_monitoring_job" + }, + "description": "Sample for PauseModelDeploymentMonitoringJob", + "file": "aiplatform_v1beta1_generated_job_service_pause_model_deployment_monitoring_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_PauseModelDeploymentMonitoringJob_sync", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_pause_model_deployment_monitoring_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient.resume_model_deployment_monitoring_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.ResumeModelDeploymentMonitoringJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "ResumeModelDeploymentMonitoringJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ResumeModelDeploymentMonitoringJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "resume_model_deployment_monitoring_job" + }, + "description": "Sample for ResumeModelDeploymentMonitoringJob", + "file": "aiplatform_v1beta1_generated_job_service_resume_model_deployment_monitoring_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_ResumeModelDeploymentMonitoringJob_async", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_resume_model_deployment_monitoring_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient.resume_model_deployment_monitoring_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.ResumeModelDeploymentMonitoringJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "ResumeModelDeploymentMonitoringJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ResumeModelDeploymentMonitoringJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "resume_model_deployment_monitoring_job" + }, + "description": "Sample for ResumeModelDeploymentMonitoringJob", + "file": "aiplatform_v1beta1_generated_job_service_resume_model_deployment_monitoring_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_ResumeModelDeploymentMonitoringJob_sync", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_resume_model_deployment_monitoring_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient.search_model_deployment_monitoring_stats_anomalies", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.SearchModelDeploymentMonitoringStatsAnomalies", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "SearchModelDeploymentMonitoringStatsAnomalies" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.SearchModelDeploymentMonitoringStatsAnomaliesRequest" + }, + { + "name": "model_deployment_monitoring_job", + "type": "str" + }, + { + "name": "deployed_model_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.job_service.pagers.SearchModelDeploymentMonitoringStatsAnomaliesAsyncPager", + "shortName": "search_model_deployment_monitoring_stats_anomalies" + }, + "description": "Sample for SearchModelDeploymentMonitoringStatsAnomalies", + "file": "aiplatform_v1beta1_generated_job_service_search_model_deployment_monitoring_stats_anomalies_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_SearchModelDeploymentMonitoringStatsAnomalies_async", + "segments": [ + { + "end": 46, + "start": 27, + "type": "FULL" + }, + { + "end": 46, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 47, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_search_model_deployment_monitoring_stats_anomalies_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient.search_model_deployment_monitoring_stats_anomalies", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.SearchModelDeploymentMonitoringStatsAnomalies", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "SearchModelDeploymentMonitoringStatsAnomalies" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.SearchModelDeploymentMonitoringStatsAnomaliesRequest" + }, + { + "name": "model_deployment_monitoring_job", + "type": "str" + }, + { + "name": "deployed_model_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.job_service.pagers.SearchModelDeploymentMonitoringStatsAnomaliesPager", + "shortName": "search_model_deployment_monitoring_stats_anomalies" + }, + "description": "Sample for SearchModelDeploymentMonitoringStatsAnomalies", + "file": "aiplatform_v1beta1_generated_job_service_search_model_deployment_monitoring_stats_anomalies_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_SearchModelDeploymentMonitoringStatsAnomalies_sync", + "segments": [ + { + "end": 46, + "start": 27, + "type": "FULL" + }, + { + "end": 46, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 47, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_search_model_deployment_monitoring_stats_anomalies_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient", + "shortName": "JobServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceAsyncClient.update_model_deployment_monitoring_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.UpdateModelDeploymentMonitoringJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "UpdateModelDeploymentMonitoringJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdateModelDeploymentMonitoringJobRequest" + }, + { + "name": "model_deployment_monitoring_job", + "type": "google.cloud.aiplatform_v1beta1.types.ModelDeploymentMonitoringJob" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "update_model_deployment_monitoring_job" + }, + "description": "Sample for UpdateModelDeploymentMonitoringJob", + "file": "aiplatform_v1beta1_generated_job_service_update_model_deployment_monitoring_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_UpdateModelDeploymentMonitoringJob_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_update_model_deployment_monitoring_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient", + "shortName": "JobServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.JobServiceClient.update_model_deployment_monitoring_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService.UpdateModelDeploymentMonitoringJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.JobService", + "shortName": "JobService" + }, + "shortName": "UpdateModelDeploymentMonitoringJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdateModelDeploymentMonitoringJobRequest" + }, + { + "name": "model_deployment_monitoring_job", + "type": "google.cloud.aiplatform_v1beta1.types.ModelDeploymentMonitoringJob" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "update_model_deployment_monitoring_job" + }, + "description": "Sample for UpdateModelDeploymentMonitoringJob", + "file": "aiplatform_v1beta1_generated_job_service_update_model_deployment_monitoring_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_JobService_UpdateModelDeploymentMonitoringJob_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_job_service_update_model_deployment_monitoring_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient.add_context_artifacts_and_executions", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.AddContextArtifactsAndExecutions", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "AddContextArtifactsAndExecutions" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.AddContextArtifactsAndExecutionsRequest" + }, + { + "name": "context", + "type": "str" + }, + { + "name": "artifacts", + "type": "Sequence[str]" + }, + { + "name": "executions", + "type": "Sequence[str]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.AddContextArtifactsAndExecutionsResponse", + "shortName": "add_context_artifacts_and_executions" + }, + "description": "Sample for AddContextArtifactsAndExecutions", + "file": "aiplatform_v1beta1_generated_metadata_service_add_context_artifacts_and_executions_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_AddContextArtifactsAndExecutions_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_add_context_artifacts_and_executions_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient.add_context_artifacts_and_executions", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.AddContextArtifactsAndExecutions", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "AddContextArtifactsAndExecutions" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.AddContextArtifactsAndExecutionsRequest" + }, + { + "name": "context", + "type": "str" + }, + { + "name": "artifacts", + "type": "Sequence[str]" + }, + { + "name": "executions", + "type": "Sequence[str]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.AddContextArtifactsAndExecutionsResponse", + "shortName": "add_context_artifacts_and_executions" + }, + "description": "Sample for AddContextArtifactsAndExecutions", + "file": "aiplatform_v1beta1_generated_metadata_service_add_context_artifacts_and_executions_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_AddContextArtifactsAndExecutions_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_add_context_artifacts_and_executions_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient.add_context_children", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.AddContextChildren", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "AddContextChildren" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.AddContextChildrenRequest" + }, + { + "name": "context", + "type": "str" + }, + { + "name": "child_contexts", + "type": "Sequence[str]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.AddContextChildrenResponse", + "shortName": "add_context_children" + }, + "description": "Sample for AddContextChildren", + "file": "aiplatform_v1beta1_generated_metadata_service_add_context_children_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_AddContextChildren_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_add_context_children_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient.add_context_children", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.AddContextChildren", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "AddContextChildren" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.AddContextChildrenRequest" + }, + { + "name": "context", + "type": "str" + }, + { + "name": "child_contexts", + "type": "Sequence[str]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.AddContextChildrenResponse", + "shortName": "add_context_children" + }, + "description": "Sample for AddContextChildren", + "file": "aiplatform_v1beta1_generated_metadata_service_add_context_children_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_AddContextChildren_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_add_context_children_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient.add_execution_events", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.AddExecutionEvents", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "AddExecutionEvents" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.AddExecutionEventsRequest" + }, + { + "name": "execution", + "type": "str" + }, + { + "name": "events", + "type": "Sequence[google.cloud.aiplatform_v1beta1.types.Event]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.AddExecutionEventsResponse", + "shortName": "add_execution_events" + }, + "description": "Sample for AddExecutionEvents", + "file": "aiplatform_v1beta1_generated_metadata_service_add_execution_events_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_AddExecutionEvents_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_add_execution_events_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient.add_execution_events", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.AddExecutionEvents", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "AddExecutionEvents" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.AddExecutionEventsRequest" + }, + { + "name": "execution", + "type": "str" + }, + { + "name": "events", + "type": "Sequence[google.cloud.aiplatform_v1beta1.types.Event]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.AddExecutionEventsResponse", + "shortName": "add_execution_events" + }, + "description": "Sample for AddExecutionEvents", + "file": "aiplatform_v1beta1_generated_metadata_service_add_execution_events_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_AddExecutionEvents_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_add_execution_events_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient.create_artifact", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.CreateArtifact", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "CreateArtifact" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateArtifactRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "artifact", + "type": "google.cloud.aiplatform_v1beta1.types.Artifact" + }, + { + "name": "artifact_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Artifact", + "shortName": "create_artifact" + }, + "description": "Sample for CreateArtifact", + "file": "aiplatform_v1beta1_generated_metadata_service_create_artifact_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_CreateArtifact_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_create_artifact_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient.create_artifact", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.CreateArtifact", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "CreateArtifact" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateArtifactRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "artifact", + "type": "google.cloud.aiplatform_v1beta1.types.Artifact" + }, + { + "name": "artifact_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Artifact", + "shortName": "create_artifact" + }, + "description": "Sample for CreateArtifact", + "file": "aiplatform_v1beta1_generated_metadata_service_create_artifact_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_CreateArtifact_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_create_artifact_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient.create_context", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.CreateContext", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "CreateContext" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateContextRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "context", + "type": "google.cloud.aiplatform_v1beta1.types.Context" + }, + { + "name": "context_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Context", + "shortName": "create_context" + }, + "description": "Sample for CreateContext", + "file": "aiplatform_v1beta1_generated_metadata_service_create_context_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_CreateContext_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_create_context_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient.create_context", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.CreateContext", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "CreateContext" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateContextRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "context", + "type": "google.cloud.aiplatform_v1beta1.types.Context" + }, + { + "name": "context_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Context", + "shortName": "create_context" + }, + "description": "Sample for CreateContext", + "file": "aiplatform_v1beta1_generated_metadata_service_create_context_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_CreateContext_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_create_context_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient.create_execution", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.CreateExecution", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "CreateExecution" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateExecutionRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "execution", + "type": "google.cloud.aiplatform_v1beta1.types.Execution" + }, + { + "name": "execution_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Execution", + "shortName": "create_execution" + }, + "description": "Sample for CreateExecution", + "file": "aiplatform_v1beta1_generated_metadata_service_create_execution_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_CreateExecution_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_create_execution_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient.create_execution", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.CreateExecution", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "CreateExecution" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateExecutionRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "execution", + "type": "google.cloud.aiplatform_v1beta1.types.Execution" + }, + { + "name": "execution_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Execution", + "shortName": "create_execution" + }, + "description": "Sample for CreateExecution", + "file": "aiplatform_v1beta1_generated_metadata_service_create_execution_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_CreateExecution_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_create_execution_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient.create_metadata_schema", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.CreateMetadataSchema", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "CreateMetadataSchema" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateMetadataSchemaRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "metadata_schema", + "type": "google.cloud.aiplatform_v1beta1.types.MetadataSchema" + }, + { + "name": "metadata_schema_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.MetadataSchema", + "shortName": "create_metadata_schema" + }, + "description": "Sample for CreateMetadataSchema", + "file": "aiplatform_v1beta1_generated_metadata_service_create_metadata_schema_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_CreateMetadataSchema_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_create_metadata_schema_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient.create_metadata_schema", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.CreateMetadataSchema", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "CreateMetadataSchema" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateMetadataSchemaRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "metadata_schema", + "type": "google.cloud.aiplatform_v1beta1.types.MetadataSchema" + }, + { + "name": "metadata_schema_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.MetadataSchema", + "shortName": "create_metadata_schema" + }, + "description": "Sample for CreateMetadataSchema", + "file": "aiplatform_v1beta1_generated_metadata_service_create_metadata_schema_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_CreateMetadataSchema_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_create_metadata_schema_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient.create_metadata_store", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.CreateMetadataStore", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "CreateMetadataStore" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateMetadataStoreRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "metadata_store", + "type": "google.cloud.aiplatform_v1beta1.types.MetadataStore" + }, + { + "name": "metadata_store_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "create_metadata_store" + }, + "description": "Sample for CreateMetadataStore", + "file": "aiplatform_v1beta1_generated_metadata_service_create_metadata_store_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_CreateMetadataStore_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_create_metadata_store_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient.create_metadata_store", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.CreateMetadataStore", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "CreateMetadataStore" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateMetadataStoreRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "metadata_store", + "type": "google.cloud.aiplatform_v1beta1.types.MetadataStore" + }, + { + "name": "metadata_store_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "create_metadata_store" + }, + "description": "Sample for CreateMetadataStore", + "file": "aiplatform_v1beta1_generated_metadata_service_create_metadata_store_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_CreateMetadataStore_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_create_metadata_store_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient.delete_artifact", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.DeleteArtifact", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "DeleteArtifact" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteArtifactRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_artifact" + }, + "description": "Sample for DeleteArtifact", + "file": "aiplatform_v1beta1_generated_metadata_service_delete_artifact_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_DeleteArtifact_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_delete_artifact_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient.delete_artifact", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.DeleteArtifact", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "DeleteArtifact" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteArtifactRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_artifact" + }, + "description": "Sample for DeleteArtifact", + "file": "aiplatform_v1beta1_generated_metadata_service_delete_artifact_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_DeleteArtifact_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_delete_artifact_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient.delete_context", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.DeleteContext", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "DeleteContext" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteContextRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_context" + }, + "description": "Sample for DeleteContext", + "file": "aiplatform_v1beta1_generated_metadata_service_delete_context_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_DeleteContext_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_delete_context_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient.delete_context", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.DeleteContext", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "DeleteContext" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteContextRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_context" + }, + "description": "Sample for DeleteContext", + "file": "aiplatform_v1beta1_generated_metadata_service_delete_context_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_DeleteContext_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_delete_context_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient.delete_execution", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.DeleteExecution", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "DeleteExecution" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteExecutionRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_execution" + }, + "description": "Sample for DeleteExecution", + "file": "aiplatform_v1beta1_generated_metadata_service_delete_execution_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_DeleteExecution_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_delete_execution_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient.delete_execution", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.DeleteExecution", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "DeleteExecution" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteExecutionRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_execution" + }, + "description": "Sample for DeleteExecution", + "file": "aiplatform_v1beta1_generated_metadata_service_delete_execution_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_DeleteExecution_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_delete_execution_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient.delete_metadata_store", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.DeleteMetadataStore", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "DeleteMetadataStore" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteMetadataStoreRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_metadata_store" + }, + "description": "Sample for DeleteMetadataStore", + "file": "aiplatform_v1beta1_generated_metadata_service_delete_metadata_store_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_DeleteMetadataStore_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_delete_metadata_store_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient.delete_metadata_store", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.DeleteMetadataStore", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "DeleteMetadataStore" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteMetadataStoreRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_metadata_store" + }, + "description": "Sample for DeleteMetadataStore", + "file": "aiplatform_v1beta1_generated_metadata_service_delete_metadata_store_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_DeleteMetadataStore_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_delete_metadata_store_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient.get_artifact", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.GetArtifact", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "GetArtifact" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetArtifactRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Artifact", + "shortName": "get_artifact" + }, + "description": "Sample for GetArtifact", + "file": "aiplatform_v1beta1_generated_metadata_service_get_artifact_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_GetArtifact_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_get_artifact_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient.get_artifact", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.GetArtifact", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "GetArtifact" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetArtifactRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Artifact", + "shortName": "get_artifact" + }, + "description": "Sample for GetArtifact", + "file": "aiplatform_v1beta1_generated_metadata_service_get_artifact_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_GetArtifact_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_get_artifact_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient.get_context", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.GetContext", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "GetContext" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetContextRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Context", + "shortName": "get_context" + }, + "description": "Sample for GetContext", + "file": "aiplatform_v1beta1_generated_metadata_service_get_context_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_GetContext_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_get_context_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient.get_context", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.GetContext", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "GetContext" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetContextRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Context", + "shortName": "get_context" + }, + "description": "Sample for GetContext", + "file": "aiplatform_v1beta1_generated_metadata_service_get_context_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_GetContext_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_get_context_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient.get_execution", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.GetExecution", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "GetExecution" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetExecutionRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Execution", + "shortName": "get_execution" + }, + "description": "Sample for GetExecution", + "file": "aiplatform_v1beta1_generated_metadata_service_get_execution_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_GetExecution_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_get_execution_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient.get_execution", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.GetExecution", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "GetExecution" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetExecutionRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Execution", + "shortName": "get_execution" + }, + "description": "Sample for GetExecution", + "file": "aiplatform_v1beta1_generated_metadata_service_get_execution_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_GetExecution_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_get_execution_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient.get_metadata_schema", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.GetMetadataSchema", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "GetMetadataSchema" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetMetadataSchemaRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.MetadataSchema", + "shortName": "get_metadata_schema" + }, + "description": "Sample for GetMetadataSchema", + "file": "aiplatform_v1beta1_generated_metadata_service_get_metadata_schema_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_GetMetadataSchema_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_get_metadata_schema_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient.get_metadata_schema", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.GetMetadataSchema", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "GetMetadataSchema" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetMetadataSchemaRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.MetadataSchema", + "shortName": "get_metadata_schema" + }, + "description": "Sample for GetMetadataSchema", + "file": "aiplatform_v1beta1_generated_metadata_service_get_metadata_schema_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_GetMetadataSchema_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_get_metadata_schema_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient.get_metadata_store", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.GetMetadataStore", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "GetMetadataStore" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetMetadataStoreRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.MetadataStore", + "shortName": "get_metadata_store" + }, + "description": "Sample for GetMetadataStore", + "file": "aiplatform_v1beta1_generated_metadata_service_get_metadata_store_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_GetMetadataStore_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_get_metadata_store_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient.get_metadata_store", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.GetMetadataStore", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "GetMetadataStore" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetMetadataStoreRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.MetadataStore", + "shortName": "get_metadata_store" + }, + "description": "Sample for GetMetadataStore", + "file": "aiplatform_v1beta1_generated_metadata_service_get_metadata_store_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_GetMetadataStore_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_get_metadata_store_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient.list_artifacts", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.ListArtifacts", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "ListArtifacts" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListArtifactsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.metadata_service.pagers.ListArtifactsAsyncPager", + "shortName": "list_artifacts" + }, + "description": "Sample for ListArtifacts", + "file": "aiplatform_v1beta1_generated_metadata_service_list_artifacts_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_ListArtifacts_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_list_artifacts_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient.list_artifacts", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.ListArtifacts", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "ListArtifacts" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListArtifactsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.metadata_service.pagers.ListArtifactsPager", + "shortName": "list_artifacts" + }, + "description": "Sample for ListArtifacts", + "file": "aiplatform_v1beta1_generated_metadata_service_list_artifacts_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_ListArtifacts_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_list_artifacts_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient.list_contexts", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.ListContexts", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "ListContexts" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListContextsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.metadata_service.pagers.ListContextsAsyncPager", + "shortName": "list_contexts" + }, + "description": "Sample for ListContexts", + "file": "aiplatform_v1beta1_generated_metadata_service_list_contexts_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_ListContexts_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_list_contexts_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient.list_contexts", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.ListContexts", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "ListContexts" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListContextsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.metadata_service.pagers.ListContextsPager", + "shortName": "list_contexts" + }, + "description": "Sample for ListContexts", + "file": "aiplatform_v1beta1_generated_metadata_service_list_contexts_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_ListContexts_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_list_contexts_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient.list_executions", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.ListExecutions", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "ListExecutions" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListExecutionsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.metadata_service.pagers.ListExecutionsAsyncPager", + "shortName": "list_executions" + }, + "description": "Sample for ListExecutions", + "file": "aiplatform_v1beta1_generated_metadata_service_list_executions_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_ListExecutions_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_list_executions_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient.list_executions", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.ListExecutions", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "ListExecutions" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListExecutionsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.metadata_service.pagers.ListExecutionsPager", + "shortName": "list_executions" + }, + "description": "Sample for ListExecutions", + "file": "aiplatform_v1beta1_generated_metadata_service_list_executions_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_ListExecutions_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_list_executions_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient.list_metadata_schemas", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.ListMetadataSchemas", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "ListMetadataSchemas" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListMetadataSchemasRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.metadata_service.pagers.ListMetadataSchemasAsyncPager", + "shortName": "list_metadata_schemas" + }, + "description": "Sample for ListMetadataSchemas", + "file": "aiplatform_v1beta1_generated_metadata_service_list_metadata_schemas_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_ListMetadataSchemas_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_list_metadata_schemas_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient.list_metadata_schemas", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.ListMetadataSchemas", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "ListMetadataSchemas" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListMetadataSchemasRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.metadata_service.pagers.ListMetadataSchemasPager", + "shortName": "list_metadata_schemas" + }, + "description": "Sample for ListMetadataSchemas", + "file": "aiplatform_v1beta1_generated_metadata_service_list_metadata_schemas_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_ListMetadataSchemas_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_list_metadata_schemas_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient.list_metadata_stores", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.ListMetadataStores", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "ListMetadataStores" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListMetadataStoresRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.metadata_service.pagers.ListMetadataStoresAsyncPager", + "shortName": "list_metadata_stores" + }, + "description": "Sample for ListMetadataStores", + "file": "aiplatform_v1beta1_generated_metadata_service_list_metadata_stores_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_ListMetadataStores_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_list_metadata_stores_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient.list_metadata_stores", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.ListMetadataStores", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "ListMetadataStores" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListMetadataStoresRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.metadata_service.pagers.ListMetadataStoresPager", + "shortName": "list_metadata_stores" + }, + "description": "Sample for ListMetadataStores", + "file": "aiplatform_v1beta1_generated_metadata_service_list_metadata_stores_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_ListMetadataStores_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_list_metadata_stores_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient.purge_artifacts", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.PurgeArtifacts", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "PurgeArtifacts" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.PurgeArtifactsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "purge_artifacts" + }, + "description": "Sample for PurgeArtifacts", + "file": "aiplatform_v1beta1_generated_metadata_service_purge_artifacts_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_PurgeArtifacts_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_purge_artifacts_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient.purge_artifacts", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.PurgeArtifacts", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "PurgeArtifacts" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.PurgeArtifactsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "purge_artifacts" + }, + "description": "Sample for PurgeArtifacts", + "file": "aiplatform_v1beta1_generated_metadata_service_purge_artifacts_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_PurgeArtifacts_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_purge_artifacts_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient.purge_contexts", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.PurgeContexts", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "PurgeContexts" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.PurgeContextsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "purge_contexts" + }, + "description": "Sample for PurgeContexts", + "file": "aiplatform_v1beta1_generated_metadata_service_purge_contexts_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_PurgeContexts_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_purge_contexts_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient.purge_contexts", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.PurgeContexts", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "PurgeContexts" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.PurgeContextsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "purge_contexts" + }, + "description": "Sample for PurgeContexts", + "file": "aiplatform_v1beta1_generated_metadata_service_purge_contexts_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_PurgeContexts_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_purge_contexts_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient.purge_executions", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.PurgeExecutions", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "PurgeExecutions" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.PurgeExecutionsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "purge_executions" + }, + "description": "Sample for PurgeExecutions", + "file": "aiplatform_v1beta1_generated_metadata_service_purge_executions_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_PurgeExecutions_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_purge_executions_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient.purge_executions", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.PurgeExecutions", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "PurgeExecutions" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.PurgeExecutionsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "purge_executions" + }, + "description": "Sample for PurgeExecutions", + "file": "aiplatform_v1beta1_generated_metadata_service_purge_executions_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_PurgeExecutions_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_purge_executions_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient.query_artifact_lineage_subgraph", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.QueryArtifactLineageSubgraph", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "QueryArtifactLineageSubgraph" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.QueryArtifactLineageSubgraphRequest" + }, + { + "name": "artifact", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.LineageSubgraph", + "shortName": "query_artifact_lineage_subgraph" + }, + "description": "Sample for QueryArtifactLineageSubgraph", + "file": "aiplatform_v1beta1_generated_metadata_service_query_artifact_lineage_subgraph_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_QueryArtifactLineageSubgraph_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_query_artifact_lineage_subgraph_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient.query_artifact_lineage_subgraph", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.QueryArtifactLineageSubgraph", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "QueryArtifactLineageSubgraph" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.QueryArtifactLineageSubgraphRequest" + }, + { + "name": "artifact", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.LineageSubgraph", + "shortName": "query_artifact_lineage_subgraph" + }, + "description": "Sample for QueryArtifactLineageSubgraph", + "file": "aiplatform_v1beta1_generated_metadata_service_query_artifact_lineage_subgraph_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_QueryArtifactLineageSubgraph_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_query_artifact_lineage_subgraph_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient.query_context_lineage_subgraph", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.QueryContextLineageSubgraph", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "QueryContextLineageSubgraph" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.QueryContextLineageSubgraphRequest" + }, + { + "name": "context", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.LineageSubgraph", + "shortName": "query_context_lineage_subgraph" + }, + "description": "Sample for QueryContextLineageSubgraph", + "file": "aiplatform_v1beta1_generated_metadata_service_query_context_lineage_subgraph_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_QueryContextLineageSubgraph_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_query_context_lineage_subgraph_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient.query_context_lineage_subgraph", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.QueryContextLineageSubgraph", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "QueryContextLineageSubgraph" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.QueryContextLineageSubgraphRequest" + }, + { + "name": "context", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.LineageSubgraph", + "shortName": "query_context_lineage_subgraph" + }, + "description": "Sample for QueryContextLineageSubgraph", + "file": "aiplatform_v1beta1_generated_metadata_service_query_context_lineage_subgraph_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_QueryContextLineageSubgraph_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_query_context_lineage_subgraph_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient.query_execution_inputs_and_outputs", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.QueryExecutionInputsAndOutputs", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "QueryExecutionInputsAndOutputs" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.QueryExecutionInputsAndOutputsRequest" + }, + { + "name": "execution", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.LineageSubgraph", + "shortName": "query_execution_inputs_and_outputs" + }, + "description": "Sample for QueryExecutionInputsAndOutputs", + "file": "aiplatform_v1beta1_generated_metadata_service_query_execution_inputs_and_outputs_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_QueryExecutionInputsAndOutputs_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_query_execution_inputs_and_outputs_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient.query_execution_inputs_and_outputs", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.QueryExecutionInputsAndOutputs", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "QueryExecutionInputsAndOutputs" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.QueryExecutionInputsAndOutputsRequest" + }, + { + "name": "execution", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.LineageSubgraph", + "shortName": "query_execution_inputs_and_outputs" + }, + "description": "Sample for QueryExecutionInputsAndOutputs", + "file": "aiplatform_v1beta1_generated_metadata_service_query_execution_inputs_and_outputs_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_QueryExecutionInputsAndOutputs_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_query_execution_inputs_and_outputs_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient.update_artifact", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.UpdateArtifact", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "UpdateArtifact" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdateArtifactRequest" + }, + { + "name": "artifact", + "type": "google.cloud.aiplatform_v1beta1.types.Artifact" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Artifact", + "shortName": "update_artifact" + }, + "description": "Sample for UpdateArtifact", + "file": "aiplatform_v1beta1_generated_metadata_service_update_artifact_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_UpdateArtifact_async", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_update_artifact_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient.update_artifact", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.UpdateArtifact", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "UpdateArtifact" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdateArtifactRequest" + }, + { + "name": "artifact", + "type": "google.cloud.aiplatform_v1beta1.types.Artifact" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Artifact", + "shortName": "update_artifact" + }, + "description": "Sample for UpdateArtifact", + "file": "aiplatform_v1beta1_generated_metadata_service_update_artifact_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_UpdateArtifact_sync", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_update_artifact_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient.update_context", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.UpdateContext", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "UpdateContext" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdateContextRequest" + }, + { + "name": "context", + "type": "google.cloud.aiplatform_v1beta1.types.Context" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Context", + "shortName": "update_context" + }, + "description": "Sample for UpdateContext", + "file": "aiplatform_v1beta1_generated_metadata_service_update_context_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_UpdateContext_async", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_update_context_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient.update_context", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.UpdateContext", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "UpdateContext" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdateContextRequest" + }, + { + "name": "context", + "type": "google.cloud.aiplatform_v1beta1.types.Context" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Context", + "shortName": "update_context" + }, + "description": "Sample for UpdateContext", + "file": "aiplatform_v1beta1_generated_metadata_service_update_context_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_UpdateContext_sync", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_update_context_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient", + "shortName": "MetadataServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceAsyncClient.update_execution", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.UpdateExecution", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "UpdateExecution" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdateExecutionRequest" + }, + { + "name": "execution", + "type": "google.cloud.aiplatform_v1beta1.types.Execution" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Execution", + "shortName": "update_execution" + }, + "description": "Sample for UpdateExecution", + "file": "aiplatform_v1beta1_generated_metadata_service_update_execution_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_UpdateExecution_async", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_update_execution_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient", + "shortName": "MetadataServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MetadataServiceClient.update_execution", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService.UpdateExecution", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MetadataService", + "shortName": "MetadataService" + }, + "shortName": "UpdateExecution" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdateExecutionRequest" + }, + { + "name": "execution", + "type": "google.cloud.aiplatform_v1beta1.types.Execution" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Execution", + "shortName": "update_execution" + }, + "description": "Sample for UpdateExecution", + "file": "aiplatform_v1beta1_generated_metadata_service_update_execution_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MetadataService_UpdateExecution_sync", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_metadata_service_update_execution_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MigrationServiceAsyncClient", + "shortName": "MigrationServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MigrationServiceAsyncClient.batch_migrate_resources", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MigrationService.BatchMigrateResources", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MigrationService", + "shortName": "MigrationService" + }, + "shortName": "BatchMigrateResources" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.BatchMigrateResourcesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "migrate_resource_requests", + "type": "Sequence[google.cloud.aiplatform_v1beta1.types.MigrateResourceRequest]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "batch_migrate_resources" + }, + "description": "Sample for BatchMigrateResources", + "file": "aiplatform_v1beta1_generated_migration_service_batch_migrate_resources_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MigrationService_BatchMigrateResources_async", + "segments": [ + { + "end": 54, + "start": 27, + "type": "FULL" + }, + { + "end": 54, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 51, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 55, + "start": 52, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_migration_service_batch_migrate_resources_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MigrationServiceClient", + "shortName": "MigrationServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MigrationServiceClient.batch_migrate_resources", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MigrationService.BatchMigrateResources", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MigrationService", + "shortName": "MigrationService" + }, + "shortName": "BatchMigrateResources" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.BatchMigrateResourcesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "migrate_resource_requests", + "type": "Sequence[google.cloud.aiplatform_v1beta1.types.MigrateResourceRequest]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "batch_migrate_resources" + }, + "description": "Sample for BatchMigrateResources", + "file": "aiplatform_v1beta1_generated_migration_service_batch_migrate_resources_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MigrationService_BatchMigrateResources_sync", + "segments": [ + { + "end": 54, + "start": 27, + "type": "FULL" + }, + { + "end": 54, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 51, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 55, + "start": 52, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_migration_service_batch_migrate_resources_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MigrationServiceAsyncClient", + "shortName": "MigrationServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MigrationServiceAsyncClient.search_migratable_resources", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MigrationService.SearchMigratableResources", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MigrationService", + "shortName": "MigrationService" + }, + "shortName": "SearchMigratableResources" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.SearchMigratableResourcesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.migration_service.pagers.SearchMigratableResourcesAsyncPager", + "shortName": "search_migratable_resources" + }, + "description": "Sample for SearchMigratableResources", + "file": "aiplatform_v1beta1_generated_migration_service_search_migratable_resources_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MigrationService_SearchMigratableResources_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_migration_service_search_migratable_resources_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.MigrationServiceClient", + "shortName": "MigrationServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.MigrationServiceClient.search_migratable_resources", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.MigrationService.SearchMigratableResources", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.MigrationService", + "shortName": "MigrationService" + }, + "shortName": "SearchMigratableResources" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.SearchMigratableResourcesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.migration_service.pagers.SearchMigratableResourcesPager", + "shortName": "search_migratable_resources" + }, + "description": "Sample for SearchMigratableResources", + "file": "aiplatform_v1beta1_generated_migration_service_search_migratable_resources_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_MigrationService_SearchMigratableResources_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_migration_service_search_migratable_resources_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceAsyncClient", + "shortName": "ModelServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceAsyncClient.batch_import_model_evaluation_slices", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService.BatchImportModelEvaluationSlices", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService", + "shortName": "ModelService" + }, + "shortName": "BatchImportModelEvaluationSlices" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.BatchImportModelEvaluationSlicesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "model_evaluation_slices", + "type": "Sequence[google.cloud.aiplatform_v1beta1.types.ModelEvaluationSlice]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.BatchImportModelEvaluationSlicesResponse", + "shortName": "batch_import_model_evaluation_slices" + }, + "description": "Sample for BatchImportModelEvaluationSlices", + "file": "aiplatform_v1beta1_generated_model_service_batch_import_model_evaluation_slices_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_ModelService_BatchImportModelEvaluationSlices_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_model_service_batch_import_model_evaluation_slices_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceClient", + "shortName": "ModelServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceClient.batch_import_model_evaluation_slices", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService.BatchImportModelEvaluationSlices", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService", + "shortName": "ModelService" + }, + "shortName": "BatchImportModelEvaluationSlices" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.BatchImportModelEvaluationSlicesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "model_evaluation_slices", + "type": "Sequence[google.cloud.aiplatform_v1beta1.types.ModelEvaluationSlice]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.BatchImportModelEvaluationSlicesResponse", + "shortName": "batch_import_model_evaluation_slices" + }, + "description": "Sample for BatchImportModelEvaluationSlices", + "file": "aiplatform_v1beta1_generated_model_service_batch_import_model_evaluation_slices_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_ModelService_BatchImportModelEvaluationSlices_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_model_service_batch_import_model_evaluation_slices_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceAsyncClient", + "shortName": "ModelServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceAsyncClient.delete_model_version", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService.DeleteModelVersion", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService", + "shortName": "ModelService" + }, + "shortName": "DeleteModelVersion" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteModelVersionRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_model_version" + }, + "description": "Sample for DeleteModelVersion", + "file": "aiplatform_v1beta1_generated_model_service_delete_model_version_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_ModelService_DeleteModelVersion_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_model_service_delete_model_version_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceClient", + "shortName": "ModelServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceClient.delete_model_version", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService.DeleteModelVersion", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService", + "shortName": "ModelService" + }, + "shortName": "DeleteModelVersion" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteModelVersionRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_model_version" + }, + "description": "Sample for DeleteModelVersion", + "file": "aiplatform_v1beta1_generated_model_service_delete_model_version_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_ModelService_DeleteModelVersion_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_model_service_delete_model_version_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceAsyncClient", + "shortName": "ModelServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceAsyncClient.delete_model", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService.DeleteModel", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService", + "shortName": "ModelService" + }, + "shortName": "DeleteModel" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteModelRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_model" + }, + "description": "Sample for DeleteModel", + "file": "aiplatform_v1beta1_generated_model_service_delete_model_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_ModelService_DeleteModel_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_model_service_delete_model_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceClient", + "shortName": "ModelServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceClient.delete_model", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService.DeleteModel", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService", + "shortName": "ModelService" + }, + "shortName": "DeleteModel" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteModelRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_model" + }, + "description": "Sample for DeleteModel", + "file": "aiplatform_v1beta1_generated_model_service_delete_model_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_ModelService_DeleteModel_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_model_service_delete_model_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceAsyncClient", + "shortName": "ModelServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceAsyncClient.export_model", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService.ExportModel", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService", + "shortName": "ModelService" + }, + "shortName": "ExportModel" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ExportModelRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "output_config", + "type": "google.cloud.aiplatform_v1beta1.types.ExportModelRequest.OutputConfig" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "export_model" + }, + "description": "Sample for ExportModel", + "file": "aiplatform_v1beta1_generated_model_service_export_model_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_ModelService_ExportModel_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_model_service_export_model_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceClient", + "shortName": "ModelServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceClient.export_model", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService.ExportModel", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService", + "shortName": "ModelService" + }, + "shortName": "ExportModel" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ExportModelRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "output_config", + "type": "google.cloud.aiplatform_v1beta1.types.ExportModelRequest.OutputConfig" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "export_model" + }, + "description": "Sample for ExportModel", + "file": "aiplatform_v1beta1_generated_model_service_export_model_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_ModelService_ExportModel_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_model_service_export_model_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceAsyncClient", + "shortName": "ModelServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceAsyncClient.get_model_evaluation_slice", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService.GetModelEvaluationSlice", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService", + "shortName": "ModelService" + }, + "shortName": "GetModelEvaluationSlice" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetModelEvaluationSliceRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.ModelEvaluationSlice", + "shortName": "get_model_evaluation_slice" + }, + "description": "Sample for GetModelEvaluationSlice", + "file": "aiplatform_v1beta1_generated_model_service_get_model_evaluation_slice_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_ModelService_GetModelEvaluationSlice_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_model_service_get_model_evaluation_slice_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceClient", + "shortName": "ModelServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceClient.get_model_evaluation_slice", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService.GetModelEvaluationSlice", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService", + "shortName": "ModelService" + }, + "shortName": "GetModelEvaluationSlice" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetModelEvaluationSliceRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.ModelEvaluationSlice", + "shortName": "get_model_evaluation_slice" + }, + "description": "Sample for GetModelEvaluationSlice", + "file": "aiplatform_v1beta1_generated_model_service_get_model_evaluation_slice_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_ModelService_GetModelEvaluationSlice_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_model_service_get_model_evaluation_slice_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceAsyncClient", + "shortName": "ModelServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceAsyncClient.get_model_evaluation", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService.GetModelEvaluation", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService", + "shortName": "ModelService" + }, + "shortName": "GetModelEvaluation" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetModelEvaluationRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.ModelEvaluation", + "shortName": "get_model_evaluation" + }, + "description": "Sample for GetModelEvaluation", + "file": "aiplatform_v1beta1_generated_model_service_get_model_evaluation_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_ModelService_GetModelEvaluation_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_model_service_get_model_evaluation_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceClient", + "shortName": "ModelServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceClient.get_model_evaluation", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService.GetModelEvaluation", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService", + "shortName": "ModelService" + }, + "shortName": "GetModelEvaluation" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetModelEvaluationRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.ModelEvaluation", + "shortName": "get_model_evaluation" + }, + "description": "Sample for GetModelEvaluation", + "file": "aiplatform_v1beta1_generated_model_service_get_model_evaluation_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_ModelService_GetModelEvaluation_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_model_service_get_model_evaluation_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceAsyncClient", + "shortName": "ModelServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceAsyncClient.get_model", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService.GetModel", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService", + "shortName": "ModelService" + }, + "shortName": "GetModel" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetModelRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Model", + "shortName": "get_model" + }, + "description": "Sample for GetModel", + "file": "aiplatform_v1beta1_generated_model_service_get_model_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_ModelService_GetModel_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_model_service_get_model_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceClient", + "shortName": "ModelServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceClient.get_model", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService.GetModel", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService", + "shortName": "ModelService" + }, + "shortName": "GetModel" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetModelRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Model", + "shortName": "get_model" + }, + "description": "Sample for GetModel", + "file": "aiplatform_v1beta1_generated_model_service_get_model_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_ModelService_GetModel_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_model_service_get_model_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceAsyncClient", + "shortName": "ModelServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceAsyncClient.import_model_evaluation", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService.ImportModelEvaluation", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService", + "shortName": "ModelService" + }, + "shortName": "ImportModelEvaluation" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ImportModelEvaluationRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "model_evaluation", + "type": "google.cloud.aiplatform_v1beta1.types.ModelEvaluation" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.ModelEvaluation", + "shortName": "import_model_evaluation" + }, + "description": "Sample for ImportModelEvaluation", + "file": "aiplatform_v1beta1_generated_model_service_import_model_evaluation_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_ModelService_ImportModelEvaluation_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_model_service_import_model_evaluation_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceClient", + "shortName": "ModelServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceClient.import_model_evaluation", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService.ImportModelEvaluation", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService", + "shortName": "ModelService" + }, + "shortName": "ImportModelEvaluation" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ImportModelEvaluationRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "model_evaluation", + "type": "google.cloud.aiplatform_v1beta1.types.ModelEvaluation" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.ModelEvaluation", + "shortName": "import_model_evaluation" + }, + "description": "Sample for ImportModelEvaluation", + "file": "aiplatform_v1beta1_generated_model_service_import_model_evaluation_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_ModelService_ImportModelEvaluation_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_model_service_import_model_evaluation_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceAsyncClient", + "shortName": "ModelServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceAsyncClient.list_model_evaluation_slices", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService.ListModelEvaluationSlices", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService", + "shortName": "ModelService" + }, + "shortName": "ListModelEvaluationSlices" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListModelEvaluationSlicesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.model_service.pagers.ListModelEvaluationSlicesAsyncPager", + "shortName": "list_model_evaluation_slices" + }, + "description": "Sample for ListModelEvaluationSlices", + "file": "aiplatform_v1beta1_generated_model_service_list_model_evaluation_slices_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_ModelService_ListModelEvaluationSlices_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_model_service_list_model_evaluation_slices_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceClient", + "shortName": "ModelServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceClient.list_model_evaluation_slices", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService.ListModelEvaluationSlices", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService", + "shortName": "ModelService" + }, + "shortName": "ListModelEvaluationSlices" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListModelEvaluationSlicesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.model_service.pagers.ListModelEvaluationSlicesPager", + "shortName": "list_model_evaluation_slices" + }, + "description": "Sample for ListModelEvaluationSlices", + "file": "aiplatform_v1beta1_generated_model_service_list_model_evaluation_slices_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_ModelService_ListModelEvaluationSlices_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_model_service_list_model_evaluation_slices_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceAsyncClient", + "shortName": "ModelServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceAsyncClient.list_model_evaluations", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService.ListModelEvaluations", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService", + "shortName": "ModelService" + }, + "shortName": "ListModelEvaluations" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListModelEvaluationsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.model_service.pagers.ListModelEvaluationsAsyncPager", + "shortName": "list_model_evaluations" + }, + "description": "Sample for ListModelEvaluations", + "file": "aiplatform_v1beta1_generated_model_service_list_model_evaluations_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_ModelService_ListModelEvaluations_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_model_service_list_model_evaluations_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceClient", + "shortName": "ModelServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceClient.list_model_evaluations", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService.ListModelEvaluations", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService", + "shortName": "ModelService" + }, + "shortName": "ListModelEvaluations" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListModelEvaluationsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.model_service.pagers.ListModelEvaluationsPager", + "shortName": "list_model_evaluations" + }, + "description": "Sample for ListModelEvaluations", + "file": "aiplatform_v1beta1_generated_model_service_list_model_evaluations_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_ModelService_ListModelEvaluations_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_model_service_list_model_evaluations_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceAsyncClient", + "shortName": "ModelServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceAsyncClient.list_model_versions", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService.ListModelVersions", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService", + "shortName": "ModelService" + }, + "shortName": "ListModelVersions" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListModelVersionsRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.model_service.pagers.ListModelVersionsAsyncPager", + "shortName": "list_model_versions" + }, + "description": "Sample for ListModelVersions", + "file": "aiplatform_v1beta1_generated_model_service_list_model_versions_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_ModelService_ListModelVersions_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_model_service_list_model_versions_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceClient", + "shortName": "ModelServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceClient.list_model_versions", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService.ListModelVersions", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService", + "shortName": "ModelService" + }, + "shortName": "ListModelVersions" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListModelVersionsRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.model_service.pagers.ListModelVersionsPager", + "shortName": "list_model_versions" + }, + "description": "Sample for ListModelVersions", + "file": "aiplatform_v1beta1_generated_model_service_list_model_versions_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_ModelService_ListModelVersions_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_model_service_list_model_versions_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceAsyncClient", + "shortName": "ModelServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceAsyncClient.list_models", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService.ListModels", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService", + "shortName": "ModelService" + }, + "shortName": "ListModels" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListModelsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.model_service.pagers.ListModelsAsyncPager", + "shortName": "list_models" + }, + "description": "Sample for ListModels", + "file": "aiplatform_v1beta1_generated_model_service_list_models_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_ModelService_ListModels_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_model_service_list_models_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceClient", + "shortName": "ModelServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceClient.list_models", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService.ListModels", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService", + "shortName": "ModelService" + }, + "shortName": "ListModels" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListModelsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.model_service.pagers.ListModelsPager", + "shortName": "list_models" + }, + "description": "Sample for ListModels", + "file": "aiplatform_v1beta1_generated_model_service_list_models_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_ModelService_ListModels_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_model_service_list_models_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceAsyncClient", + "shortName": "ModelServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceAsyncClient.merge_version_aliases", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService.MergeVersionAliases", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService", + "shortName": "ModelService" + }, + "shortName": "MergeVersionAliases" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.MergeVersionAliasesRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "version_aliases", + "type": "Sequence[str]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Model", + "shortName": "merge_version_aliases" + }, + "description": "Sample for MergeVersionAliases", + "file": "aiplatform_v1beta1_generated_model_service_merge_version_aliases_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_ModelService_MergeVersionAliases_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_model_service_merge_version_aliases_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceClient", + "shortName": "ModelServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceClient.merge_version_aliases", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService.MergeVersionAliases", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService", + "shortName": "ModelService" + }, + "shortName": "MergeVersionAliases" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.MergeVersionAliasesRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "version_aliases", + "type": "Sequence[str]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Model", + "shortName": "merge_version_aliases" + }, + "description": "Sample for MergeVersionAliases", + "file": "aiplatform_v1beta1_generated_model_service_merge_version_aliases_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_ModelService_MergeVersionAliases_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_model_service_merge_version_aliases_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceAsyncClient", + "shortName": "ModelServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceAsyncClient.update_explanation_dataset", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService.UpdateExplanationDataset", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService", + "shortName": "ModelService" + }, + "shortName": "UpdateExplanationDataset" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdateExplanationDatasetRequest" + }, + { + "name": "model", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "update_explanation_dataset" + }, + "description": "Sample for UpdateExplanationDataset", + "file": "aiplatform_v1beta1_generated_model_service_update_explanation_dataset_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_ModelService_UpdateExplanationDataset_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_model_service_update_explanation_dataset_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceClient", + "shortName": "ModelServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceClient.update_explanation_dataset", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService.UpdateExplanationDataset", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService", + "shortName": "ModelService" + }, + "shortName": "UpdateExplanationDataset" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdateExplanationDatasetRequest" + }, + { + "name": "model", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "update_explanation_dataset" + }, + "description": "Sample for UpdateExplanationDataset", + "file": "aiplatform_v1beta1_generated_model_service_update_explanation_dataset_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_ModelService_UpdateExplanationDataset_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_model_service_update_explanation_dataset_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceAsyncClient", + "shortName": "ModelServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceAsyncClient.update_model", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService.UpdateModel", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService", + "shortName": "ModelService" + }, + "shortName": "UpdateModel" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdateModelRequest" + }, + { + "name": "model", + "type": "google.cloud.aiplatform_v1beta1.types.Model" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Model", + "shortName": "update_model" + }, + "description": "Sample for UpdateModel", + "file": "aiplatform_v1beta1_generated_model_service_update_model_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_ModelService_UpdateModel_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_model_service_update_model_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceClient", + "shortName": "ModelServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceClient.update_model", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService.UpdateModel", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService", + "shortName": "ModelService" + }, + "shortName": "UpdateModel" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdateModelRequest" + }, + { + "name": "model", + "type": "google.cloud.aiplatform_v1beta1.types.Model" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Model", + "shortName": "update_model" + }, + "description": "Sample for UpdateModel", + "file": "aiplatform_v1beta1_generated_model_service_update_model_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_ModelService_UpdateModel_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_model_service_update_model_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceAsyncClient", + "shortName": "ModelServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceAsyncClient.upload_model", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService.UploadModel", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService", + "shortName": "ModelService" + }, + "shortName": "UploadModel" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UploadModelRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "model", + "type": "google.cloud.aiplatform_v1beta1.types.Model" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "upload_model" + }, + "description": "Sample for UploadModel", + "file": "aiplatform_v1beta1_generated_model_service_upload_model_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_ModelService_UploadModel_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_model_service_upload_model_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceClient", + "shortName": "ModelServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.ModelServiceClient.upload_model", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService.UploadModel", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.ModelService", + "shortName": "ModelService" + }, + "shortName": "UploadModel" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UploadModelRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "model", + "type": "google.cloud.aiplatform_v1beta1.types.Model" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "upload_model" + }, + "description": "Sample for UploadModel", + "file": "aiplatform_v1beta1_generated_model_service_upload_model_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_ModelService_UploadModel_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_model_service_upload_model_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceAsyncClient", + "shortName": "PipelineServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceAsyncClient.cancel_pipeline_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService.CancelPipelineJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "CancelPipelineJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CancelPipelineJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "cancel_pipeline_job" + }, + "description": "Sample for CancelPipelineJob", + "file": "aiplatform_v1beta1_generated_pipeline_service_cancel_pipeline_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_PipelineService_CancelPipelineJob_async", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_pipeline_service_cancel_pipeline_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceClient", + "shortName": "PipelineServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceClient.cancel_pipeline_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService.CancelPipelineJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "CancelPipelineJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CancelPipelineJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "cancel_pipeline_job" + }, + "description": "Sample for CancelPipelineJob", + "file": "aiplatform_v1beta1_generated_pipeline_service_cancel_pipeline_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_PipelineService_CancelPipelineJob_sync", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_pipeline_service_cancel_pipeline_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceAsyncClient", + "shortName": "PipelineServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceAsyncClient.cancel_training_pipeline", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService.CancelTrainingPipeline", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "CancelTrainingPipeline" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CancelTrainingPipelineRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "cancel_training_pipeline" + }, + "description": "Sample for CancelTrainingPipeline", + "file": "aiplatform_v1beta1_generated_pipeline_service_cancel_training_pipeline_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_PipelineService_CancelTrainingPipeline_async", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_pipeline_service_cancel_training_pipeline_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceClient", + "shortName": "PipelineServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceClient.cancel_training_pipeline", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService.CancelTrainingPipeline", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "CancelTrainingPipeline" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CancelTrainingPipelineRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "cancel_training_pipeline" + }, + "description": "Sample for CancelTrainingPipeline", + "file": "aiplatform_v1beta1_generated_pipeline_service_cancel_training_pipeline_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_PipelineService_CancelTrainingPipeline_sync", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_pipeline_service_cancel_training_pipeline_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceAsyncClient", + "shortName": "PipelineServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceAsyncClient.create_pipeline_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService.CreatePipelineJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "CreatePipelineJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreatePipelineJobRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "pipeline_job", + "type": "google.cloud.aiplatform_v1beta1.types.PipelineJob" + }, + { + "name": "pipeline_job_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.PipelineJob", + "shortName": "create_pipeline_job" + }, + "description": "Sample for CreatePipelineJob", + "file": "aiplatform_v1beta1_generated_pipeline_service_create_pipeline_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_PipelineService_CreatePipelineJob_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_pipeline_service_create_pipeline_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceClient", + "shortName": "PipelineServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceClient.create_pipeline_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService.CreatePipelineJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "CreatePipelineJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreatePipelineJobRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "pipeline_job", + "type": "google.cloud.aiplatform_v1beta1.types.PipelineJob" + }, + { + "name": "pipeline_job_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.PipelineJob", + "shortName": "create_pipeline_job" + }, + "description": "Sample for CreatePipelineJob", + "file": "aiplatform_v1beta1_generated_pipeline_service_create_pipeline_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_PipelineService_CreatePipelineJob_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_pipeline_service_create_pipeline_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceAsyncClient", + "shortName": "PipelineServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceAsyncClient.create_training_pipeline", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService.CreateTrainingPipeline", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "CreateTrainingPipeline" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateTrainingPipelineRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "training_pipeline", + "type": "google.cloud.aiplatform_v1beta1.types.TrainingPipeline" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.TrainingPipeline", + "shortName": "create_training_pipeline" + }, + "description": "Sample for CreateTrainingPipeline", + "file": "aiplatform_v1beta1_generated_pipeline_service_create_training_pipeline_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_PipelineService_CreateTrainingPipeline_async", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 47, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "start": 48, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_pipeline_service_create_training_pipeline_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceClient", + "shortName": "PipelineServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceClient.create_training_pipeline", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService.CreateTrainingPipeline", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "CreateTrainingPipeline" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateTrainingPipelineRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "training_pipeline", + "type": "google.cloud.aiplatform_v1beta1.types.TrainingPipeline" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.TrainingPipeline", + "shortName": "create_training_pipeline" + }, + "description": "Sample for CreateTrainingPipeline", + "file": "aiplatform_v1beta1_generated_pipeline_service_create_training_pipeline_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_PipelineService_CreateTrainingPipeline_sync", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 47, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "start": 48, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_pipeline_service_create_training_pipeline_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceAsyncClient", + "shortName": "PipelineServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceAsyncClient.delete_pipeline_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService.DeletePipelineJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "DeletePipelineJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeletePipelineJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_pipeline_job" + }, + "description": "Sample for DeletePipelineJob", + "file": "aiplatform_v1beta1_generated_pipeline_service_delete_pipeline_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_PipelineService_DeletePipelineJob_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_pipeline_service_delete_pipeline_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceClient", + "shortName": "PipelineServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceClient.delete_pipeline_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService.DeletePipelineJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "DeletePipelineJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeletePipelineJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_pipeline_job" + }, + "description": "Sample for DeletePipelineJob", + "file": "aiplatform_v1beta1_generated_pipeline_service_delete_pipeline_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_PipelineService_DeletePipelineJob_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_pipeline_service_delete_pipeline_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceAsyncClient", + "shortName": "PipelineServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceAsyncClient.delete_training_pipeline", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService.DeleteTrainingPipeline", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "DeleteTrainingPipeline" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteTrainingPipelineRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_training_pipeline" + }, + "description": "Sample for DeleteTrainingPipeline", + "file": "aiplatform_v1beta1_generated_pipeline_service_delete_training_pipeline_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_PipelineService_DeleteTrainingPipeline_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_pipeline_service_delete_training_pipeline_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceClient", + "shortName": "PipelineServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceClient.delete_training_pipeline", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService.DeleteTrainingPipeline", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "DeleteTrainingPipeline" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteTrainingPipelineRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_training_pipeline" + }, + "description": "Sample for DeleteTrainingPipeline", + "file": "aiplatform_v1beta1_generated_pipeline_service_delete_training_pipeline_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_PipelineService_DeleteTrainingPipeline_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_pipeline_service_delete_training_pipeline_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceAsyncClient", + "shortName": "PipelineServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceAsyncClient.get_pipeline_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService.GetPipelineJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "GetPipelineJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetPipelineJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.PipelineJob", + "shortName": "get_pipeline_job" + }, + "description": "Sample for GetPipelineJob", + "file": "aiplatform_v1beta1_generated_pipeline_service_get_pipeline_job_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_PipelineService_GetPipelineJob_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_pipeline_service_get_pipeline_job_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceClient", + "shortName": "PipelineServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceClient.get_pipeline_job", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService.GetPipelineJob", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "GetPipelineJob" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetPipelineJobRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.PipelineJob", + "shortName": "get_pipeline_job" + }, + "description": "Sample for GetPipelineJob", + "file": "aiplatform_v1beta1_generated_pipeline_service_get_pipeline_job_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_PipelineService_GetPipelineJob_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_pipeline_service_get_pipeline_job_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceAsyncClient", + "shortName": "PipelineServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceAsyncClient.get_training_pipeline", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService.GetTrainingPipeline", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "GetTrainingPipeline" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetTrainingPipelineRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.TrainingPipeline", + "shortName": "get_training_pipeline" + }, + "description": "Sample for GetTrainingPipeline", + "file": "aiplatform_v1beta1_generated_pipeline_service_get_training_pipeline_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_PipelineService_GetTrainingPipeline_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_pipeline_service_get_training_pipeline_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceClient", + "shortName": "PipelineServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceClient.get_training_pipeline", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService.GetTrainingPipeline", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "GetTrainingPipeline" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetTrainingPipelineRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.TrainingPipeline", + "shortName": "get_training_pipeline" + }, + "description": "Sample for GetTrainingPipeline", + "file": "aiplatform_v1beta1_generated_pipeline_service_get_training_pipeline_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_PipelineService_GetTrainingPipeline_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_pipeline_service_get_training_pipeline_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceAsyncClient", + "shortName": "PipelineServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceAsyncClient.list_pipeline_jobs", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService.ListPipelineJobs", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "ListPipelineJobs" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListPipelineJobsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.pipeline_service.pagers.ListPipelineJobsAsyncPager", + "shortName": "list_pipeline_jobs" + }, + "description": "Sample for ListPipelineJobs", + "file": "aiplatform_v1beta1_generated_pipeline_service_list_pipeline_jobs_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_PipelineService_ListPipelineJobs_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_pipeline_service_list_pipeline_jobs_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceClient", + "shortName": "PipelineServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceClient.list_pipeline_jobs", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService.ListPipelineJobs", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "ListPipelineJobs" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListPipelineJobsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.pipeline_service.pagers.ListPipelineJobsPager", + "shortName": "list_pipeline_jobs" + }, + "description": "Sample for ListPipelineJobs", + "file": "aiplatform_v1beta1_generated_pipeline_service_list_pipeline_jobs_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_PipelineService_ListPipelineJobs_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_pipeline_service_list_pipeline_jobs_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceAsyncClient", + "shortName": "PipelineServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceAsyncClient.list_training_pipelines", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService.ListTrainingPipelines", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "ListTrainingPipelines" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListTrainingPipelinesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.pipeline_service.pagers.ListTrainingPipelinesAsyncPager", + "shortName": "list_training_pipelines" + }, + "description": "Sample for ListTrainingPipelines", + "file": "aiplatform_v1beta1_generated_pipeline_service_list_training_pipelines_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_PipelineService_ListTrainingPipelines_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_pipeline_service_list_training_pipelines_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceClient", + "shortName": "PipelineServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.PipelineServiceClient.list_training_pipelines", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService.ListTrainingPipelines", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.PipelineService", + "shortName": "PipelineService" + }, + "shortName": "ListTrainingPipelines" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListTrainingPipelinesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.pipeline_service.pagers.ListTrainingPipelinesPager", + "shortName": "list_training_pipelines" + }, + "description": "Sample for ListTrainingPipelines", + "file": "aiplatform_v1beta1_generated_pipeline_service_list_training_pipelines_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_PipelineService_ListTrainingPipelines_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_pipeline_service_list_training_pipelines_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.PredictionServiceAsyncClient", + "shortName": "PredictionServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.PredictionServiceAsyncClient.explain", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.PredictionService.Explain", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.PredictionService", + "shortName": "PredictionService" + }, + "shortName": "Explain" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ExplainRequest" + }, + { + "name": "endpoint", + "type": "str" + }, + { + "name": "instances", + "type": "Sequence[google.protobuf.struct_pb2.Value]" + }, + { + "name": "parameters", + "type": "google.protobuf.struct_pb2.Value" + }, + { + "name": "deployed_model_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.ExplainResponse", + "shortName": "explain" + }, + "description": "Sample for Explain", + "file": "aiplatform_v1beta1_generated_prediction_service_explain_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_PredictionService_Explain_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_prediction_service_explain_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.PredictionServiceClient", + "shortName": "PredictionServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.PredictionServiceClient.explain", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.PredictionService.Explain", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.PredictionService", + "shortName": "PredictionService" + }, + "shortName": "Explain" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ExplainRequest" + }, + { + "name": "endpoint", + "type": "str" + }, + { + "name": "instances", + "type": "Sequence[google.protobuf.struct_pb2.Value]" + }, + { + "name": "parameters", + "type": "google.protobuf.struct_pb2.Value" + }, + { + "name": "deployed_model_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.ExplainResponse", + "shortName": "explain" + }, + "description": "Sample for Explain", + "file": "aiplatform_v1beta1_generated_prediction_service_explain_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_PredictionService_Explain_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_prediction_service_explain_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.PredictionServiceAsyncClient", + "shortName": "PredictionServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.PredictionServiceAsyncClient.predict", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.PredictionService.Predict", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.PredictionService", + "shortName": "PredictionService" + }, + "shortName": "Predict" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.PredictRequest" + }, + { + "name": "endpoint", + "type": "str" + }, + { + "name": "instances", + "type": "Sequence[google.protobuf.struct_pb2.Value]" + }, + { + "name": "parameters", + "type": "google.protobuf.struct_pb2.Value" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.PredictResponse", + "shortName": "predict" + }, + "description": "Sample for Predict", + "file": "aiplatform_v1beta1_generated_prediction_service_predict_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_PredictionService_Predict_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_prediction_service_predict_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.PredictionServiceClient", + "shortName": "PredictionServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.PredictionServiceClient.predict", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.PredictionService.Predict", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.PredictionService", + "shortName": "PredictionService" + }, + "shortName": "Predict" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.PredictRequest" + }, + { + "name": "endpoint", + "type": "str" + }, + { + "name": "instances", + "type": "Sequence[google.protobuf.struct_pb2.Value]" + }, + { + "name": "parameters", + "type": "google.protobuf.struct_pb2.Value" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.PredictResponse", + "shortName": "predict" + }, + "description": "Sample for Predict", + "file": "aiplatform_v1beta1_generated_prediction_service_predict_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_PredictionService_Predict_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_prediction_service_predict_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.PredictionServiceAsyncClient", + "shortName": "PredictionServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.PredictionServiceAsyncClient.raw_predict", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.PredictionService.RawPredict", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.PredictionService", + "shortName": "PredictionService" + }, + "shortName": "RawPredict" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.RawPredictRequest" + }, + { + "name": "endpoint", + "type": "str" + }, + { + "name": "http_body", + "type": "google.api.httpbody_pb2.HttpBody" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api.httpbody_pb2.HttpBody", + "shortName": "raw_predict" + }, + "description": "Sample for RawPredict", + "file": "aiplatform_v1beta1_generated_prediction_service_raw_predict_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_PredictionService_RawPredict_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_prediction_service_raw_predict_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.PredictionServiceClient", + "shortName": "PredictionServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.PredictionServiceClient.raw_predict", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.PredictionService.RawPredict", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.PredictionService", + "shortName": "PredictionService" + }, + "shortName": "RawPredict" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.RawPredictRequest" + }, + { + "name": "endpoint", + "type": "str" + }, + { + "name": "http_body", + "type": "google.api.httpbody_pb2.HttpBody" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api.httpbody_pb2.HttpBody", + "shortName": "raw_predict" + }, + "description": "Sample for RawPredict", + "file": "aiplatform_v1beta1_generated_prediction_service_raw_predict_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_PredictionService_RawPredict_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_prediction_service_raw_predict_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.SpecialistPoolServiceAsyncClient", + "shortName": "SpecialistPoolServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.SpecialistPoolServiceAsyncClient.create_specialist_pool", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.SpecialistPoolService.CreateSpecialistPool", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.SpecialistPoolService", + "shortName": "SpecialistPoolService" + }, + "shortName": "CreateSpecialistPool" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateSpecialistPoolRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "specialist_pool", + "type": "google.cloud.aiplatform_v1beta1.types.SpecialistPool" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "create_specialist_pool" + }, + "description": "Sample for CreateSpecialistPool", + "file": "aiplatform_v1beta1_generated_specialist_pool_service_create_specialist_pool_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_SpecialistPoolService_CreateSpecialistPool_async", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_specialist_pool_service_create_specialist_pool_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.SpecialistPoolServiceClient", + "shortName": "SpecialistPoolServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.SpecialistPoolServiceClient.create_specialist_pool", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.SpecialistPoolService.CreateSpecialistPool", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.SpecialistPoolService", + "shortName": "SpecialistPoolService" + }, + "shortName": "CreateSpecialistPool" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateSpecialistPoolRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "specialist_pool", + "type": "google.cloud.aiplatform_v1beta1.types.SpecialistPool" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "create_specialist_pool" + }, + "description": "Sample for CreateSpecialistPool", + "file": "aiplatform_v1beta1_generated_specialist_pool_service_create_specialist_pool_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_SpecialistPoolService_CreateSpecialistPool_sync", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_specialist_pool_service_create_specialist_pool_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.SpecialistPoolServiceAsyncClient", + "shortName": "SpecialistPoolServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.SpecialistPoolServiceAsyncClient.delete_specialist_pool", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.SpecialistPoolService.DeleteSpecialistPool", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.SpecialistPoolService", + "shortName": "SpecialistPoolService" + }, + "shortName": "DeleteSpecialistPool" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteSpecialistPoolRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_specialist_pool" + }, + "description": "Sample for DeleteSpecialistPool", + "file": "aiplatform_v1beta1_generated_specialist_pool_service_delete_specialist_pool_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_SpecialistPoolService_DeleteSpecialistPool_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_specialist_pool_service_delete_specialist_pool_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.SpecialistPoolServiceClient", + "shortName": "SpecialistPoolServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.SpecialistPoolServiceClient.delete_specialist_pool", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.SpecialistPoolService.DeleteSpecialistPool", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.SpecialistPoolService", + "shortName": "SpecialistPoolService" + }, + "shortName": "DeleteSpecialistPool" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteSpecialistPoolRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_specialist_pool" + }, + "description": "Sample for DeleteSpecialistPool", + "file": "aiplatform_v1beta1_generated_specialist_pool_service_delete_specialist_pool_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_SpecialistPoolService_DeleteSpecialistPool_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_specialist_pool_service_delete_specialist_pool_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.SpecialistPoolServiceAsyncClient", + "shortName": "SpecialistPoolServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.SpecialistPoolServiceAsyncClient.get_specialist_pool", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.SpecialistPoolService.GetSpecialistPool", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.SpecialistPoolService", + "shortName": "SpecialistPoolService" + }, + "shortName": "GetSpecialistPool" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetSpecialistPoolRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.SpecialistPool", + "shortName": "get_specialist_pool" + }, + "description": "Sample for GetSpecialistPool", + "file": "aiplatform_v1beta1_generated_specialist_pool_service_get_specialist_pool_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_SpecialistPoolService_GetSpecialistPool_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_specialist_pool_service_get_specialist_pool_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.SpecialistPoolServiceClient", + "shortName": "SpecialistPoolServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.SpecialistPoolServiceClient.get_specialist_pool", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.SpecialistPoolService.GetSpecialistPool", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.SpecialistPoolService", + "shortName": "SpecialistPoolService" + }, + "shortName": "GetSpecialistPool" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetSpecialistPoolRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.SpecialistPool", + "shortName": "get_specialist_pool" + }, + "description": "Sample for GetSpecialistPool", + "file": "aiplatform_v1beta1_generated_specialist_pool_service_get_specialist_pool_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_SpecialistPoolService_GetSpecialistPool_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_specialist_pool_service_get_specialist_pool_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.SpecialistPoolServiceAsyncClient", + "shortName": "SpecialistPoolServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.SpecialistPoolServiceAsyncClient.list_specialist_pools", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.SpecialistPoolService.ListSpecialistPools", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.SpecialistPoolService", + "shortName": "SpecialistPoolService" + }, + "shortName": "ListSpecialistPools" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListSpecialistPoolsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.specialist_pool_service.pagers.ListSpecialistPoolsAsyncPager", + "shortName": "list_specialist_pools" + }, + "description": "Sample for ListSpecialistPools", + "file": "aiplatform_v1beta1_generated_specialist_pool_service_list_specialist_pools_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_SpecialistPoolService_ListSpecialistPools_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_specialist_pool_service_list_specialist_pools_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.SpecialistPoolServiceClient", + "shortName": "SpecialistPoolServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.SpecialistPoolServiceClient.list_specialist_pools", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.SpecialistPoolService.ListSpecialistPools", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.SpecialistPoolService", + "shortName": "SpecialistPoolService" + }, + "shortName": "ListSpecialistPools" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListSpecialistPoolsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.specialist_pool_service.pagers.ListSpecialistPoolsPager", + "shortName": "list_specialist_pools" + }, + "description": "Sample for ListSpecialistPools", + "file": "aiplatform_v1beta1_generated_specialist_pool_service_list_specialist_pools_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_SpecialistPoolService_ListSpecialistPools_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_specialist_pool_service_list_specialist_pools_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.SpecialistPoolServiceAsyncClient", + "shortName": "SpecialistPoolServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.SpecialistPoolServiceAsyncClient.update_specialist_pool", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.SpecialistPoolService.UpdateSpecialistPool", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.SpecialistPoolService", + "shortName": "SpecialistPoolService" + }, + "shortName": "UpdateSpecialistPool" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdateSpecialistPoolRequest" + }, + { + "name": "specialist_pool", + "type": "google.cloud.aiplatform_v1beta1.types.SpecialistPool" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "update_specialist_pool" + }, + "description": "Sample for UpdateSpecialistPool", + "file": "aiplatform_v1beta1_generated_specialist_pool_service_update_specialist_pool_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_SpecialistPoolService_UpdateSpecialistPool_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_specialist_pool_service_update_specialist_pool_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.SpecialistPoolServiceClient", + "shortName": "SpecialistPoolServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.SpecialistPoolServiceClient.update_specialist_pool", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.SpecialistPoolService.UpdateSpecialistPool", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.SpecialistPoolService", + "shortName": "SpecialistPoolService" + }, + "shortName": "UpdateSpecialistPool" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdateSpecialistPoolRequest" + }, + { + "name": "specialist_pool", + "type": "google.cloud.aiplatform_v1beta1.types.SpecialistPool" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "update_specialist_pool" + }, + "description": "Sample for UpdateSpecialistPool", + "file": "aiplatform_v1beta1_generated_specialist_pool_service_update_specialist_pool_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_SpecialistPoolService_UpdateSpecialistPool_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_specialist_pool_service_update_specialist_pool_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient.batch_create_tensorboard_runs", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.BatchCreateTensorboardRuns", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "BatchCreateTensorboardRuns" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.BatchCreateTensorboardRunsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "requests", + "type": "Sequence[google.cloud.aiplatform_v1beta1.types.CreateTensorboardRunRequest]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.BatchCreateTensorboardRunsResponse", + "shortName": "batch_create_tensorboard_runs" + }, + "description": "Sample for BatchCreateTensorboardRuns", + "file": "aiplatform_v1beta1_generated_tensorboard_service_batch_create_tensorboard_runs_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_BatchCreateTensorboardRuns_async", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 47, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "start": 48, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_batch_create_tensorboard_runs_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient.batch_create_tensorboard_runs", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.BatchCreateTensorboardRuns", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "BatchCreateTensorboardRuns" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.BatchCreateTensorboardRunsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "requests", + "type": "Sequence[google.cloud.aiplatform_v1beta1.types.CreateTensorboardRunRequest]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.BatchCreateTensorboardRunsResponse", + "shortName": "batch_create_tensorboard_runs" + }, + "description": "Sample for BatchCreateTensorboardRuns", + "file": "aiplatform_v1beta1_generated_tensorboard_service_batch_create_tensorboard_runs_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_BatchCreateTensorboardRuns_sync", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 47, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "start": 48, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_batch_create_tensorboard_runs_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient.batch_create_tensorboard_time_series", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.BatchCreateTensorboardTimeSeries", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "BatchCreateTensorboardTimeSeries" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.BatchCreateTensorboardTimeSeriesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "requests", + "type": "Sequence[google.cloud.aiplatform_v1beta1.types.CreateTensorboardTimeSeriesRequest]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.BatchCreateTensorboardTimeSeriesResponse", + "shortName": "batch_create_tensorboard_time_series" + }, + "description": "Sample for BatchCreateTensorboardTimeSeries", + "file": "aiplatform_v1beta1_generated_tensorboard_service_batch_create_tensorboard_time_series_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_BatchCreateTensorboardTimeSeries_async", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 47, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "start": 48, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_batch_create_tensorboard_time_series_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient.batch_create_tensorboard_time_series", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.BatchCreateTensorboardTimeSeries", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "BatchCreateTensorboardTimeSeries" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.BatchCreateTensorboardTimeSeriesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "requests", + "type": "Sequence[google.cloud.aiplatform_v1beta1.types.CreateTensorboardTimeSeriesRequest]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.BatchCreateTensorboardTimeSeriesResponse", + "shortName": "batch_create_tensorboard_time_series" + }, + "description": "Sample for BatchCreateTensorboardTimeSeries", + "file": "aiplatform_v1beta1_generated_tensorboard_service_batch_create_tensorboard_time_series_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_BatchCreateTensorboardTimeSeries_sync", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 47, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "start": 48, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_batch_create_tensorboard_time_series_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient.batch_read_tensorboard_time_series_data", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.BatchReadTensorboardTimeSeriesData", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "BatchReadTensorboardTimeSeriesData" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.BatchReadTensorboardTimeSeriesDataRequest" + }, + { + "name": "tensorboard", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.BatchReadTensorboardTimeSeriesDataResponse", + "shortName": "batch_read_tensorboard_time_series_data" + }, + "description": "Sample for BatchReadTensorboardTimeSeriesData", + "file": "aiplatform_v1beta1_generated_tensorboard_service_batch_read_tensorboard_time_series_data_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_BatchReadTensorboardTimeSeriesData_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_batch_read_tensorboard_time_series_data_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient.batch_read_tensorboard_time_series_data", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.BatchReadTensorboardTimeSeriesData", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "BatchReadTensorboardTimeSeriesData" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.BatchReadTensorboardTimeSeriesDataRequest" + }, + { + "name": "tensorboard", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.BatchReadTensorboardTimeSeriesDataResponse", + "shortName": "batch_read_tensorboard_time_series_data" + }, + "description": "Sample for BatchReadTensorboardTimeSeriesData", + "file": "aiplatform_v1beta1_generated_tensorboard_service_batch_read_tensorboard_time_series_data_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_BatchReadTensorboardTimeSeriesData_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_batch_read_tensorboard_time_series_data_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient.create_tensorboard_experiment", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.CreateTensorboardExperiment", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "CreateTensorboardExperiment" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateTensorboardExperimentRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "tensorboard_experiment", + "type": "google.cloud.aiplatform_v1beta1.types.TensorboardExperiment" + }, + { + "name": "tensorboard_experiment_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.TensorboardExperiment", + "shortName": "create_tensorboard_experiment" + }, + "description": "Sample for CreateTensorboardExperiment", + "file": "aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_experiment_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_CreateTensorboardExperiment_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_experiment_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient.create_tensorboard_experiment", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.CreateTensorboardExperiment", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "CreateTensorboardExperiment" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateTensorboardExperimentRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "tensorboard_experiment", + "type": "google.cloud.aiplatform_v1beta1.types.TensorboardExperiment" + }, + { + "name": "tensorboard_experiment_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.TensorboardExperiment", + "shortName": "create_tensorboard_experiment" + }, + "description": "Sample for CreateTensorboardExperiment", + "file": "aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_experiment_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_CreateTensorboardExperiment_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_experiment_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient.create_tensorboard_run", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.CreateTensorboardRun", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "CreateTensorboardRun" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateTensorboardRunRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "tensorboard_run", + "type": "google.cloud.aiplatform_v1beta1.types.TensorboardRun" + }, + { + "name": "tensorboard_run_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.TensorboardRun", + "shortName": "create_tensorboard_run" + }, + "description": "Sample for CreateTensorboardRun", + "file": "aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_run_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_CreateTensorboardRun_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_run_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient.create_tensorboard_run", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.CreateTensorboardRun", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "CreateTensorboardRun" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateTensorboardRunRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "tensorboard_run", + "type": "google.cloud.aiplatform_v1beta1.types.TensorboardRun" + }, + { + "name": "tensorboard_run_id", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.TensorboardRun", + "shortName": "create_tensorboard_run" + }, + "description": "Sample for CreateTensorboardRun", + "file": "aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_run_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_CreateTensorboardRun_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_run_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient.create_tensorboard_time_series", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.CreateTensorboardTimeSeries", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "CreateTensorboardTimeSeries" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateTensorboardTimeSeriesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "tensorboard_time_series", + "type": "google.cloud.aiplatform_v1beta1.types.TensorboardTimeSeries" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.TensorboardTimeSeries", + "shortName": "create_tensorboard_time_series" + }, + "description": "Sample for CreateTensorboardTimeSeries", + "file": "aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_time_series_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_CreateTensorboardTimeSeries_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_time_series_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient.create_tensorboard_time_series", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.CreateTensorboardTimeSeries", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "CreateTensorboardTimeSeries" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateTensorboardTimeSeriesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "tensorboard_time_series", + "type": "google.cloud.aiplatform_v1beta1.types.TensorboardTimeSeries" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.TensorboardTimeSeries", + "shortName": "create_tensorboard_time_series" + }, + "description": "Sample for CreateTensorboardTimeSeries", + "file": "aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_time_series_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_CreateTensorboardTimeSeries_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_time_series_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient.create_tensorboard", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.CreateTensorboard", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "CreateTensorboard" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateTensorboardRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "tensorboard", + "type": "google.cloud.aiplatform_v1beta1.types.Tensorboard" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "create_tensorboard" + }, + "description": "Sample for CreateTensorboard", + "file": "aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_CreateTensorboard_async", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient.create_tensorboard", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.CreateTensorboard", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "CreateTensorboard" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateTensorboardRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "tensorboard", + "type": "google.cloud.aiplatform_v1beta1.types.Tensorboard" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "create_tensorboard" + }, + "description": "Sample for CreateTensorboard", + "file": "aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_CreateTensorboard_sync", + "segments": [ + { + "end": 52, + "start": 27, + "type": "FULL" + }, + { + "end": 52, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 49, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 53, + "start": 50, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_create_tensorboard_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient.delete_tensorboard_experiment", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.DeleteTensorboardExperiment", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "DeleteTensorboardExperiment" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteTensorboardExperimentRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_tensorboard_experiment" + }, + "description": "Sample for DeleteTensorboardExperiment", + "file": "aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_experiment_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_DeleteTensorboardExperiment_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_experiment_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient.delete_tensorboard_experiment", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.DeleteTensorboardExperiment", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "DeleteTensorboardExperiment" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteTensorboardExperimentRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_tensorboard_experiment" + }, + "description": "Sample for DeleteTensorboardExperiment", + "file": "aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_experiment_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_DeleteTensorboardExperiment_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_experiment_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient.delete_tensorboard_run", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.DeleteTensorboardRun", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "DeleteTensorboardRun" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteTensorboardRunRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_tensorboard_run" + }, + "description": "Sample for DeleteTensorboardRun", + "file": "aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_run_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_DeleteTensorboardRun_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_run_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient.delete_tensorboard_run", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.DeleteTensorboardRun", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "DeleteTensorboardRun" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteTensorboardRunRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_tensorboard_run" + }, + "description": "Sample for DeleteTensorboardRun", + "file": "aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_run_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_DeleteTensorboardRun_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_run_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient.delete_tensorboard_time_series", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.DeleteTensorboardTimeSeries", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "DeleteTensorboardTimeSeries" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteTensorboardTimeSeriesRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_tensorboard_time_series" + }, + "description": "Sample for DeleteTensorboardTimeSeries", + "file": "aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_time_series_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_DeleteTensorboardTimeSeries_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_time_series_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient.delete_tensorboard_time_series", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.DeleteTensorboardTimeSeries", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "DeleteTensorboardTimeSeries" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteTensorboardTimeSeriesRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_tensorboard_time_series" + }, + "description": "Sample for DeleteTensorboardTimeSeries", + "file": "aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_time_series_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_DeleteTensorboardTimeSeries_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_time_series_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient.delete_tensorboard", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.DeleteTensorboard", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "DeleteTensorboard" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteTensorboardRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "delete_tensorboard" + }, + "description": "Sample for DeleteTensorboard", + "file": "aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_DeleteTensorboard_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient.delete_tensorboard", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.DeleteTensorboard", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "DeleteTensorboard" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteTensorboardRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "delete_tensorboard" + }, + "description": "Sample for DeleteTensorboard", + "file": "aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_DeleteTensorboard_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_delete_tensorboard_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient.export_tensorboard_time_series_data", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.ExportTensorboardTimeSeriesData", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "ExportTensorboardTimeSeriesData" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ExportTensorboardTimeSeriesDataRequest" + }, + { + "name": "tensorboard_time_series", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.tensorboard_service.pagers.ExportTensorboardTimeSeriesDataAsyncPager", + "shortName": "export_tensorboard_time_series_data" + }, + "description": "Sample for ExportTensorboardTimeSeriesData", + "file": "aiplatform_v1beta1_generated_tensorboard_service_export_tensorboard_time_series_data_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_ExportTensorboardTimeSeriesData_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_export_tensorboard_time_series_data_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient.export_tensorboard_time_series_data", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.ExportTensorboardTimeSeriesData", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "ExportTensorboardTimeSeriesData" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ExportTensorboardTimeSeriesDataRequest" + }, + { + "name": "tensorboard_time_series", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.tensorboard_service.pagers.ExportTensorboardTimeSeriesDataPager", + "shortName": "export_tensorboard_time_series_data" + }, + "description": "Sample for ExportTensorboardTimeSeriesData", + "file": "aiplatform_v1beta1_generated_tensorboard_service_export_tensorboard_time_series_data_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_ExportTensorboardTimeSeriesData_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_export_tensorboard_time_series_data_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient.get_tensorboard_experiment", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.GetTensorboardExperiment", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "GetTensorboardExperiment" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetTensorboardExperimentRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.TensorboardExperiment", + "shortName": "get_tensorboard_experiment" + }, + "description": "Sample for GetTensorboardExperiment", + "file": "aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_experiment_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_GetTensorboardExperiment_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_experiment_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient.get_tensorboard_experiment", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.GetTensorboardExperiment", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "GetTensorboardExperiment" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetTensorboardExperimentRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.TensorboardExperiment", + "shortName": "get_tensorboard_experiment" + }, + "description": "Sample for GetTensorboardExperiment", + "file": "aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_experiment_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_GetTensorboardExperiment_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_experiment_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient.get_tensorboard_run", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.GetTensorboardRun", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "GetTensorboardRun" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetTensorboardRunRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.TensorboardRun", + "shortName": "get_tensorboard_run" + }, + "description": "Sample for GetTensorboardRun", + "file": "aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_run_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_GetTensorboardRun_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_run_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient.get_tensorboard_run", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.GetTensorboardRun", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "GetTensorboardRun" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetTensorboardRunRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.TensorboardRun", + "shortName": "get_tensorboard_run" + }, + "description": "Sample for GetTensorboardRun", + "file": "aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_run_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_GetTensorboardRun_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_run_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient.get_tensorboard_time_series", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.GetTensorboardTimeSeries", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "GetTensorboardTimeSeries" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetTensorboardTimeSeriesRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.TensorboardTimeSeries", + "shortName": "get_tensorboard_time_series" + }, + "description": "Sample for GetTensorboardTimeSeries", + "file": "aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_time_series_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_GetTensorboardTimeSeries_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_time_series_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient.get_tensorboard_time_series", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.GetTensorboardTimeSeries", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "GetTensorboardTimeSeries" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetTensorboardTimeSeriesRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.TensorboardTimeSeries", + "shortName": "get_tensorboard_time_series" + }, + "description": "Sample for GetTensorboardTimeSeries", + "file": "aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_time_series_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_GetTensorboardTimeSeries_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_time_series_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient.get_tensorboard", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.GetTensorboard", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "GetTensorboard" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetTensorboardRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Tensorboard", + "shortName": "get_tensorboard" + }, + "description": "Sample for GetTensorboard", + "file": "aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_GetTensorboard_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient.get_tensorboard", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.GetTensorboard", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "GetTensorboard" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetTensorboardRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Tensorboard", + "shortName": "get_tensorboard" + }, + "description": "Sample for GetTensorboard", + "file": "aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_GetTensorboard_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_get_tensorboard_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient.list_tensorboard_experiments", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.ListTensorboardExperiments", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "ListTensorboardExperiments" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListTensorboardExperimentsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.tensorboard_service.pagers.ListTensorboardExperimentsAsyncPager", + "shortName": "list_tensorboard_experiments" + }, + "description": "Sample for ListTensorboardExperiments", + "file": "aiplatform_v1beta1_generated_tensorboard_service_list_tensorboard_experiments_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_ListTensorboardExperiments_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_list_tensorboard_experiments_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient.list_tensorboard_experiments", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.ListTensorboardExperiments", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "ListTensorboardExperiments" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListTensorboardExperimentsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.tensorboard_service.pagers.ListTensorboardExperimentsPager", + "shortName": "list_tensorboard_experiments" + }, + "description": "Sample for ListTensorboardExperiments", + "file": "aiplatform_v1beta1_generated_tensorboard_service_list_tensorboard_experiments_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_ListTensorboardExperiments_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_list_tensorboard_experiments_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient.list_tensorboard_runs", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.ListTensorboardRuns", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "ListTensorboardRuns" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListTensorboardRunsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.tensorboard_service.pagers.ListTensorboardRunsAsyncPager", + "shortName": "list_tensorboard_runs" + }, + "description": "Sample for ListTensorboardRuns", + "file": "aiplatform_v1beta1_generated_tensorboard_service_list_tensorboard_runs_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_ListTensorboardRuns_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_list_tensorboard_runs_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient.list_tensorboard_runs", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.ListTensorboardRuns", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "ListTensorboardRuns" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListTensorboardRunsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.tensorboard_service.pagers.ListTensorboardRunsPager", + "shortName": "list_tensorboard_runs" + }, + "description": "Sample for ListTensorboardRuns", + "file": "aiplatform_v1beta1_generated_tensorboard_service_list_tensorboard_runs_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_ListTensorboardRuns_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_list_tensorboard_runs_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient.list_tensorboard_time_series", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.ListTensorboardTimeSeries", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "ListTensorboardTimeSeries" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListTensorboardTimeSeriesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.tensorboard_service.pagers.ListTensorboardTimeSeriesAsyncPager", + "shortName": "list_tensorboard_time_series" + }, + "description": "Sample for ListTensorboardTimeSeries", + "file": "aiplatform_v1beta1_generated_tensorboard_service_list_tensorboard_time_series_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_ListTensorboardTimeSeries_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_list_tensorboard_time_series_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient.list_tensorboard_time_series", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.ListTensorboardTimeSeries", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "ListTensorboardTimeSeries" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListTensorboardTimeSeriesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.tensorboard_service.pagers.ListTensorboardTimeSeriesPager", + "shortName": "list_tensorboard_time_series" + }, + "description": "Sample for ListTensorboardTimeSeries", + "file": "aiplatform_v1beta1_generated_tensorboard_service_list_tensorboard_time_series_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_ListTensorboardTimeSeries_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_list_tensorboard_time_series_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient.list_tensorboards", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.ListTensorboards", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "ListTensorboards" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListTensorboardsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.tensorboard_service.pagers.ListTensorboardsAsyncPager", + "shortName": "list_tensorboards" + }, + "description": "Sample for ListTensorboards", + "file": "aiplatform_v1beta1_generated_tensorboard_service_list_tensorboards_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_ListTensorboards_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_list_tensorboards_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient.list_tensorboards", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.ListTensorboards", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "ListTensorboards" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListTensorboardsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.tensorboard_service.pagers.ListTensorboardsPager", + "shortName": "list_tensorboards" + }, + "description": "Sample for ListTensorboards", + "file": "aiplatform_v1beta1_generated_tensorboard_service_list_tensorboards_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_ListTensorboards_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_list_tensorboards_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient.read_tensorboard_blob_data", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.ReadTensorboardBlobData", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "ReadTensorboardBlobData" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ReadTensorboardBlobDataRequest" + }, + { + "name": "time_series", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "Iterable[google.cloud.aiplatform_v1beta1.types.ReadTensorboardBlobDataResponse]", + "shortName": "read_tensorboard_blob_data" + }, + "description": "Sample for ReadTensorboardBlobData", + "file": "aiplatform_v1beta1_generated_tensorboard_service_read_tensorboard_blob_data_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_ReadTensorboardBlobData_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_read_tensorboard_blob_data_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient.read_tensorboard_blob_data", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.ReadTensorboardBlobData", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "ReadTensorboardBlobData" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ReadTensorboardBlobDataRequest" + }, + { + "name": "time_series", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "Iterable[google.cloud.aiplatform_v1beta1.types.ReadTensorboardBlobDataResponse]", + "shortName": "read_tensorboard_blob_data" + }, + "description": "Sample for ReadTensorboardBlobData", + "file": "aiplatform_v1beta1_generated_tensorboard_service_read_tensorboard_blob_data_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_ReadTensorboardBlobData_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_read_tensorboard_blob_data_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient.read_tensorboard_time_series_data", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.ReadTensorboardTimeSeriesData", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "ReadTensorboardTimeSeriesData" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ReadTensorboardTimeSeriesDataRequest" + }, + { + "name": "tensorboard_time_series", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.ReadTensorboardTimeSeriesDataResponse", + "shortName": "read_tensorboard_time_series_data" + }, + "description": "Sample for ReadTensorboardTimeSeriesData", + "file": "aiplatform_v1beta1_generated_tensorboard_service_read_tensorboard_time_series_data_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_ReadTensorboardTimeSeriesData_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_read_tensorboard_time_series_data_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient.read_tensorboard_time_series_data", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.ReadTensorboardTimeSeriesData", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "ReadTensorboardTimeSeriesData" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ReadTensorboardTimeSeriesDataRequest" + }, + { + "name": "tensorboard_time_series", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.ReadTensorboardTimeSeriesDataResponse", + "shortName": "read_tensorboard_time_series_data" + }, + "description": "Sample for ReadTensorboardTimeSeriesData", + "file": "aiplatform_v1beta1_generated_tensorboard_service_read_tensorboard_time_series_data_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_ReadTensorboardTimeSeriesData_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_read_tensorboard_time_series_data_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient.update_tensorboard_experiment", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.UpdateTensorboardExperiment", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "UpdateTensorboardExperiment" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdateTensorboardExperimentRequest" + }, + { + "name": "tensorboard_experiment", + "type": "google.cloud.aiplatform_v1beta1.types.TensorboardExperiment" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.TensorboardExperiment", + "shortName": "update_tensorboard_experiment" + }, + "description": "Sample for UpdateTensorboardExperiment", + "file": "aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_experiment_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_UpdateTensorboardExperiment_async", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_experiment_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient.update_tensorboard_experiment", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.UpdateTensorboardExperiment", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "UpdateTensorboardExperiment" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdateTensorboardExperimentRequest" + }, + { + "name": "tensorboard_experiment", + "type": "google.cloud.aiplatform_v1beta1.types.TensorboardExperiment" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.TensorboardExperiment", + "shortName": "update_tensorboard_experiment" + }, + "description": "Sample for UpdateTensorboardExperiment", + "file": "aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_experiment_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_UpdateTensorboardExperiment_sync", + "segments": [ + { + "end": 43, + "start": 27, + "type": "FULL" + }, + { + "end": 43, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 37, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 40, + "start": 38, + "type": "REQUEST_EXECUTION" + }, + { + "end": 44, + "start": 41, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_experiment_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient.update_tensorboard_run", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.UpdateTensorboardRun", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "UpdateTensorboardRun" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdateTensorboardRunRequest" + }, + { + "name": "tensorboard_run", + "type": "google.cloud.aiplatform_v1beta1.types.TensorboardRun" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.TensorboardRun", + "shortName": "update_tensorboard_run" + }, + "description": "Sample for UpdateTensorboardRun", + "file": "aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_run_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_UpdateTensorboardRun_async", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_run_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient.update_tensorboard_run", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.UpdateTensorboardRun", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "UpdateTensorboardRun" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdateTensorboardRunRequest" + }, + { + "name": "tensorboard_run", + "type": "google.cloud.aiplatform_v1beta1.types.TensorboardRun" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.TensorboardRun", + "shortName": "update_tensorboard_run" + }, + "description": "Sample for UpdateTensorboardRun", + "file": "aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_run_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_UpdateTensorboardRun_sync", + "segments": [ + { + "end": 47, + "start": 27, + "type": "FULL" + }, + { + "end": 47, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 44, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 48, + "start": 45, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_run_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient.update_tensorboard_time_series", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.UpdateTensorboardTimeSeries", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "UpdateTensorboardTimeSeries" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdateTensorboardTimeSeriesRequest" + }, + { + "name": "tensorboard_time_series", + "type": "google.cloud.aiplatform_v1beta1.types.TensorboardTimeSeries" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.TensorboardTimeSeries", + "shortName": "update_tensorboard_time_series" + }, + "description": "Sample for UpdateTensorboardTimeSeries", + "file": "aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_time_series_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_UpdateTensorboardTimeSeries_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_time_series_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient.update_tensorboard_time_series", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.UpdateTensorboardTimeSeries", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "UpdateTensorboardTimeSeries" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdateTensorboardTimeSeriesRequest" + }, + { + "name": "tensorboard_time_series", + "type": "google.cloud.aiplatform_v1beta1.types.TensorboardTimeSeries" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.TensorboardTimeSeries", + "shortName": "update_tensorboard_time_series" + }, + "description": "Sample for UpdateTensorboardTimeSeries", + "file": "aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_time_series_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_UpdateTensorboardTimeSeries_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 42, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 43, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_time_series_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient.update_tensorboard", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.UpdateTensorboard", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "UpdateTensorboard" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdateTensorboardRequest" + }, + { + "name": "tensorboard", + "type": "google.cloud.aiplatform_v1beta1.types.Tensorboard" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "update_tensorboard" + }, + "description": "Sample for UpdateTensorboard", + "file": "aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_UpdateTensorboard_async", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient.update_tensorboard", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.UpdateTensorboard", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "UpdateTensorboard" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.UpdateTensorboardRequest" + }, + { + "name": "tensorboard", + "type": "google.cloud.aiplatform_v1beta1.types.Tensorboard" + }, + { + "name": "update_mask", + "type": "google.protobuf.field_mask_pb2.FieldMask" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "update_tensorboard" + }, + "description": "Sample for UpdateTensorboard", + "file": "aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_UpdateTensorboard_sync", + "segments": [ + { + "end": 51, + "start": 27, + "type": "FULL" + }, + { + "end": 51, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 41, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 48, + "start": 42, + "type": "REQUEST_EXECUTION" + }, + { + "end": 52, + "start": 49, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_update_tensorboard_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient.write_tensorboard_experiment_data", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.WriteTensorboardExperimentData", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "WriteTensorboardExperimentData" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.WriteTensorboardExperimentDataRequest" + }, + { + "name": "tensorboard_experiment", + "type": "str" + }, + { + "name": "write_run_data_requests", + "type": "Sequence[google.cloud.aiplatform_v1beta1.types.WriteTensorboardRunDataRequest]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.WriteTensorboardExperimentDataResponse", + "shortName": "write_tensorboard_experiment_data" + }, + "description": "Sample for WriteTensorboardExperimentData", + "file": "aiplatform_v1beta1_generated_tensorboard_service_write_tensorboard_experiment_data_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_WriteTensorboardExperimentData_async", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 47, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "start": 48, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_write_tensorboard_experiment_data_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient.write_tensorboard_experiment_data", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.WriteTensorboardExperimentData", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "WriteTensorboardExperimentData" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.WriteTensorboardExperimentDataRequest" + }, + { + "name": "tensorboard_experiment", + "type": "str" + }, + { + "name": "write_run_data_requests", + "type": "Sequence[google.cloud.aiplatform_v1beta1.types.WriteTensorboardRunDataRequest]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.WriteTensorboardExperimentDataResponse", + "shortName": "write_tensorboard_experiment_data" + }, + "description": "Sample for WriteTensorboardExperimentData", + "file": "aiplatform_v1beta1_generated_tensorboard_service_write_tensorboard_experiment_data_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_WriteTensorboardExperimentData_sync", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 44, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 47, + "start": 45, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "start": 48, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_write_tensorboard_experiment_data_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient", + "shortName": "TensorboardServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceAsyncClient.write_tensorboard_run_data", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.WriteTensorboardRunData", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "WriteTensorboardRunData" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.WriteTensorboardRunDataRequest" + }, + { + "name": "tensorboard_run", + "type": "str" + }, + { + "name": "time_series_data", + "type": "Sequence[google.cloud.aiplatform_v1beta1.types.TimeSeriesData]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.WriteTensorboardRunDataResponse", + "shortName": "write_tensorboard_run_data" + }, + "description": "Sample for WriteTensorboardRunData", + "file": "aiplatform_v1beta1_generated_tensorboard_service_write_tensorboard_run_data_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_WriteTensorboardRunData_async", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_write_tensorboard_run_data_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient", + "shortName": "TensorboardServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.TensorboardServiceClient.write_tensorboard_run_data", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService.WriteTensorboardRunData", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.TensorboardService", + "shortName": "TensorboardService" + }, + "shortName": "WriteTensorboardRunData" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.WriteTensorboardRunDataRequest" + }, + { + "name": "tensorboard_run", + "type": "str" + }, + { + "name": "time_series_data", + "type": "Sequence[google.cloud.aiplatform_v1beta1.types.TimeSeriesData]" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.WriteTensorboardRunDataResponse", + "shortName": "write_tensorboard_run_data" + }, + "description": "Sample for WriteTensorboardRunData", + "file": "aiplatform_v1beta1_generated_tensorboard_service_write_tensorboard_run_data_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_TensorboardService_WriteTensorboardRunData_sync", + "segments": [ + { + "end": 49, + "start": 27, + "type": "FULL" + }, + { + "end": 49, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 43, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 46, + "start": 44, + "type": "REQUEST_EXECUTION" + }, + { + "end": 50, + "start": 47, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_tensorboard_service_write_tensorboard_run_data_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceAsyncClient", + "shortName": "VizierServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceAsyncClient.add_trial_measurement", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService.AddTrialMeasurement", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService", + "shortName": "VizierService" + }, + "shortName": "AddTrialMeasurement" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.AddTrialMeasurementRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Trial", + "shortName": "add_trial_measurement" + }, + "description": "Sample for AddTrialMeasurement", + "file": "aiplatform_v1beta1_generated_vizier_service_add_trial_measurement_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_VizierService_AddTrialMeasurement_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_vizier_service_add_trial_measurement_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceClient", + "shortName": "VizierServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceClient.add_trial_measurement", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService.AddTrialMeasurement", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService", + "shortName": "VizierService" + }, + "shortName": "AddTrialMeasurement" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.AddTrialMeasurementRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Trial", + "shortName": "add_trial_measurement" + }, + "description": "Sample for AddTrialMeasurement", + "file": "aiplatform_v1beta1_generated_vizier_service_add_trial_measurement_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_VizierService_AddTrialMeasurement_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_vizier_service_add_trial_measurement_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceAsyncClient", + "shortName": "VizierServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceAsyncClient.check_trial_early_stopping_state", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService.CheckTrialEarlyStoppingState", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService", + "shortName": "VizierService" + }, + "shortName": "CheckTrialEarlyStoppingState" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CheckTrialEarlyStoppingStateRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "check_trial_early_stopping_state" + }, + "description": "Sample for CheckTrialEarlyStoppingState", + "file": "aiplatform_v1beta1_generated_vizier_service_check_trial_early_stopping_state_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_VizierService_CheckTrialEarlyStoppingState_async", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_vizier_service_check_trial_early_stopping_state_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceClient", + "shortName": "VizierServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceClient.check_trial_early_stopping_state", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService.CheckTrialEarlyStoppingState", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService", + "shortName": "VizierService" + }, + "shortName": "CheckTrialEarlyStoppingState" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CheckTrialEarlyStoppingStateRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "check_trial_early_stopping_state" + }, + "description": "Sample for CheckTrialEarlyStoppingState", + "file": "aiplatform_v1beta1_generated_vizier_service_check_trial_early_stopping_state_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_VizierService_CheckTrialEarlyStoppingState_sync", + "segments": [ + { + "end": 48, + "start": 27, + "type": "FULL" + }, + { + "end": 48, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 45, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 49, + "start": 46, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_vizier_service_check_trial_early_stopping_state_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceAsyncClient", + "shortName": "VizierServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceAsyncClient.complete_trial", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService.CompleteTrial", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService", + "shortName": "VizierService" + }, + "shortName": "CompleteTrial" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CompleteTrialRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Trial", + "shortName": "complete_trial" + }, + "description": "Sample for CompleteTrial", + "file": "aiplatform_v1beta1_generated_vizier_service_complete_trial_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_VizierService_CompleteTrial_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_vizier_service_complete_trial_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceClient", + "shortName": "VizierServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceClient.complete_trial", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService.CompleteTrial", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService", + "shortName": "VizierService" + }, + "shortName": "CompleteTrial" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CompleteTrialRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Trial", + "shortName": "complete_trial" + }, + "description": "Sample for CompleteTrial", + "file": "aiplatform_v1beta1_generated_vizier_service_complete_trial_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_VizierService_CompleteTrial_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_vizier_service_complete_trial_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceAsyncClient", + "shortName": "VizierServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceAsyncClient.create_study", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService.CreateStudy", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService", + "shortName": "VizierService" + }, + "shortName": "CreateStudy" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateStudyRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "study", + "type": "google.cloud.aiplatform_v1beta1.types.Study" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Study", + "shortName": "create_study" + }, + "description": "Sample for CreateStudy", + "file": "aiplatform_v1beta1_generated_vizier_service_create_study_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_VizierService_CreateStudy_async", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 47, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 48, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_vizier_service_create_study_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceClient", + "shortName": "VizierServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceClient.create_study", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService.CreateStudy", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService", + "shortName": "VizierService" + }, + "shortName": "CreateStudy" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateStudyRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "study", + "type": "google.cloud.aiplatform_v1beta1.types.Study" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Study", + "shortName": "create_study" + }, + "description": "Sample for CreateStudy", + "file": "aiplatform_v1beta1_generated_vizier_service_create_study_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_VizierService_CreateStudy_sync", + "segments": [ + { + "end": 53, + "start": 27, + "type": "FULL" + }, + { + "end": 53, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 47, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 50, + "start": 48, + "type": "REQUEST_EXECUTION" + }, + { + "end": 54, + "start": 51, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_vizier_service_create_study_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceAsyncClient", + "shortName": "VizierServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceAsyncClient.create_trial", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService.CreateTrial", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService", + "shortName": "VizierService" + }, + "shortName": "CreateTrial" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateTrialRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "trial", + "type": "google.cloud.aiplatform_v1beta1.types.Trial" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Trial", + "shortName": "create_trial" + }, + "description": "Sample for CreateTrial", + "file": "aiplatform_v1beta1_generated_vizier_service_create_trial_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_VizierService_CreateTrial_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_vizier_service_create_trial_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceClient", + "shortName": "VizierServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceClient.create_trial", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService.CreateTrial", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService", + "shortName": "VizierService" + }, + "shortName": "CreateTrial" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.CreateTrialRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "trial", + "type": "google.cloud.aiplatform_v1beta1.types.Trial" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Trial", + "shortName": "create_trial" + }, + "description": "Sample for CreateTrial", + "file": "aiplatform_v1beta1_generated_vizier_service_create_trial_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_VizierService_CreateTrial_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_vizier_service_create_trial_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceAsyncClient", + "shortName": "VizierServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceAsyncClient.delete_study", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService.DeleteStudy", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService", + "shortName": "VizierService" + }, + "shortName": "DeleteStudy" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteStudyRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "delete_study" + }, + "description": "Sample for DeleteStudy", + "file": "aiplatform_v1beta1_generated_vizier_service_delete_study_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_VizierService_DeleteStudy_async", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_vizier_service_delete_study_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceClient", + "shortName": "VizierServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceClient.delete_study", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService.DeleteStudy", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService", + "shortName": "VizierService" + }, + "shortName": "DeleteStudy" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteStudyRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "delete_study" + }, + "description": "Sample for DeleteStudy", + "file": "aiplatform_v1beta1_generated_vizier_service_delete_study_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_VizierService_DeleteStudy_sync", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_vizier_service_delete_study_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceAsyncClient", + "shortName": "VizierServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceAsyncClient.delete_trial", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService.DeleteTrial", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService", + "shortName": "VizierService" + }, + "shortName": "DeleteTrial" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteTrialRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "delete_trial" + }, + "description": "Sample for DeleteTrial", + "file": "aiplatform_v1beta1_generated_vizier_service_delete_trial_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_VizierService_DeleteTrial_async", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_vizier_service_delete_trial_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceClient", + "shortName": "VizierServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceClient.delete_trial", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService.DeleteTrial", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService", + "shortName": "VizierService" + }, + "shortName": "DeleteTrial" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.DeleteTrialRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "shortName": "delete_trial" + }, + "description": "Sample for DeleteTrial", + "file": "aiplatform_v1beta1_generated_vizier_service_delete_trial_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_VizierService_DeleteTrial_sync", + "segments": [ + { + "end": 42, + "start": 27, + "type": "FULL" + }, + { + "end": 42, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_vizier_service_delete_trial_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceAsyncClient", + "shortName": "VizierServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceAsyncClient.get_study", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService.GetStudy", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService", + "shortName": "VizierService" + }, + "shortName": "GetStudy" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetStudyRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Study", + "shortName": "get_study" + }, + "description": "Sample for GetStudy", + "file": "aiplatform_v1beta1_generated_vizier_service_get_study_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_VizierService_GetStudy_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_vizier_service_get_study_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceClient", + "shortName": "VizierServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceClient.get_study", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService.GetStudy", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService", + "shortName": "VizierService" + }, + "shortName": "GetStudy" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetStudyRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Study", + "shortName": "get_study" + }, + "description": "Sample for GetStudy", + "file": "aiplatform_v1beta1_generated_vizier_service_get_study_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_VizierService_GetStudy_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_vizier_service_get_study_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceAsyncClient", + "shortName": "VizierServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceAsyncClient.get_trial", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService.GetTrial", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService", + "shortName": "VizierService" + }, + "shortName": "GetTrial" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetTrialRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Trial", + "shortName": "get_trial" + }, + "description": "Sample for GetTrial", + "file": "aiplatform_v1beta1_generated_vizier_service_get_trial_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_VizierService_GetTrial_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_vizier_service_get_trial_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceClient", + "shortName": "VizierServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceClient.get_trial", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService.GetTrial", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService", + "shortName": "VizierService" + }, + "shortName": "GetTrial" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.GetTrialRequest" + }, + { + "name": "name", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Trial", + "shortName": "get_trial" + }, + "description": "Sample for GetTrial", + "file": "aiplatform_v1beta1_generated_vizier_service_get_trial_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_VizierService_GetTrial_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_vizier_service_get_trial_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceAsyncClient", + "shortName": "VizierServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceAsyncClient.list_optimal_trials", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService.ListOptimalTrials", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService", + "shortName": "VizierService" + }, + "shortName": "ListOptimalTrials" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListOptimalTrialsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.ListOptimalTrialsResponse", + "shortName": "list_optimal_trials" + }, + "description": "Sample for ListOptimalTrials", + "file": "aiplatform_v1beta1_generated_vizier_service_list_optimal_trials_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_VizierService_ListOptimalTrials_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_vizier_service_list_optimal_trials_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceClient", + "shortName": "VizierServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceClient.list_optimal_trials", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService.ListOptimalTrials", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService", + "shortName": "VizierService" + }, + "shortName": "ListOptimalTrials" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListOptimalTrialsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.ListOptimalTrialsResponse", + "shortName": "list_optimal_trials" + }, + "description": "Sample for ListOptimalTrials", + "file": "aiplatform_v1beta1_generated_vizier_service_list_optimal_trials_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_VizierService_ListOptimalTrials_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_vizier_service_list_optimal_trials_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceAsyncClient", + "shortName": "VizierServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceAsyncClient.list_studies", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService.ListStudies", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService", + "shortName": "VizierService" + }, + "shortName": "ListStudies" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListStudiesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.vizier_service.pagers.ListStudiesAsyncPager", + "shortName": "list_studies" + }, + "description": "Sample for ListStudies", + "file": "aiplatform_v1beta1_generated_vizier_service_list_studies_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_VizierService_ListStudies_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_vizier_service_list_studies_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceClient", + "shortName": "VizierServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceClient.list_studies", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService.ListStudies", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService", + "shortName": "VizierService" + }, + "shortName": "ListStudies" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListStudiesRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.vizier_service.pagers.ListStudiesPager", + "shortName": "list_studies" + }, + "description": "Sample for ListStudies", + "file": "aiplatform_v1beta1_generated_vizier_service_list_studies_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_VizierService_ListStudies_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_vizier_service_list_studies_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceAsyncClient", + "shortName": "VizierServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceAsyncClient.list_trials", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService.ListTrials", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService", + "shortName": "VizierService" + }, + "shortName": "ListTrials" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListTrialsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.vizier_service.pagers.ListTrialsAsyncPager", + "shortName": "list_trials" + }, + "description": "Sample for ListTrials", + "file": "aiplatform_v1beta1_generated_vizier_service_list_trials_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_VizierService_ListTrials_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_vizier_service_list_trials_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceClient", + "shortName": "VizierServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceClient.list_trials", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService.ListTrials", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService", + "shortName": "VizierService" + }, + "shortName": "ListTrials" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.ListTrialsRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.services.vizier_service.pagers.ListTrialsPager", + "shortName": "list_trials" + }, + "description": "Sample for ListTrials", + "file": "aiplatform_v1beta1_generated_vizier_service_list_trials_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_VizierService_ListTrials_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_vizier_service_list_trials_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceAsyncClient", + "shortName": "VizierServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceAsyncClient.lookup_study", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService.LookupStudy", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService", + "shortName": "VizierService" + }, + "shortName": "LookupStudy" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.LookupStudyRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Study", + "shortName": "lookup_study" + }, + "description": "Sample for LookupStudy", + "file": "aiplatform_v1beta1_generated_vizier_service_lookup_study_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_VizierService_LookupStudy_async", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_vizier_service_lookup_study_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceClient", + "shortName": "VizierServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceClient.lookup_study", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService.LookupStudy", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService", + "shortName": "VizierService" + }, + "shortName": "LookupStudy" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.LookupStudyRequest" + }, + { + "name": "parent", + "type": "str" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Study", + "shortName": "lookup_study" + }, + "description": "Sample for LookupStudy", + "file": "aiplatform_v1beta1_generated_vizier_service_lookup_study_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_VizierService_LookupStudy_sync", + "segments": [ + { + "end": 45, + "start": 27, + "type": "FULL" + }, + { + "end": 45, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 39, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 42, + "start": 40, + "type": "REQUEST_EXECUTION" + }, + { + "end": 46, + "start": 43, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_vizier_service_lookup_study_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceAsyncClient", + "shortName": "VizierServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceAsyncClient.stop_trial", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService.StopTrial", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService", + "shortName": "VizierService" + }, + "shortName": "StopTrial" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.StopTrialRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Trial", + "shortName": "stop_trial" + }, + "description": "Sample for StopTrial", + "file": "aiplatform_v1beta1_generated_vizier_service_stop_trial_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_VizierService_StopTrial_async", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_vizier_service_stop_trial_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceClient", + "shortName": "VizierServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceClient.stop_trial", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService.StopTrial", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService", + "shortName": "VizierService" + }, + "shortName": "StopTrial" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.StopTrialRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.cloud.aiplatform_v1beta1.types.Trial", + "shortName": "stop_trial" + }, + "description": "Sample for StopTrial", + "file": "aiplatform_v1beta1_generated_vizier_service_stop_trial_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_VizierService_StopTrial_sync", + "segments": [ + { + "end": 44, + "start": 27, + "type": "FULL" + }, + { + "end": 44, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 38, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 41, + "start": 39, + "type": "REQUEST_EXECUTION" + }, + { + "end": 45, + "start": 42, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_vizier_service_stop_trial_sync.py" + }, + { + "canonical": true, + "clientMethod": { + "async": true, + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceAsyncClient", + "shortName": "VizierServiceAsyncClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceAsyncClient.suggest_trials", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService.SuggestTrials", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService", + "shortName": "VizierService" + }, + "shortName": "SuggestTrials" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.SuggestTrialsRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation_async.AsyncOperation", + "shortName": "suggest_trials" + }, + "description": "Sample for SuggestTrials", + "file": "aiplatform_v1beta1_generated_vizier_service_suggest_trials_async.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_VizierService_SuggestTrials_async", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 40, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 47, + "start": 41, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "start": 48, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_vizier_service_suggest_trials_async.py" + }, + { + "canonical": true, + "clientMethod": { + "client": { + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceClient", + "shortName": "VizierServiceClient" + }, + "fullName": "google.cloud.aiplatform_v1beta1.VizierServiceClient.suggest_trials", + "method": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService.SuggestTrials", + "service": { + "fullName": "google.cloud.aiplatform.v1beta1.VizierService", + "shortName": "VizierService" + }, + "shortName": "SuggestTrials" + }, + "parameters": [ + { + "name": "request", + "type": "google.cloud.aiplatform_v1beta1.types.SuggestTrialsRequest" + }, + { + "name": "retry", + "type": "google.api_core.retry.Retry" + }, + { + "name": "timeout", + "type": "float" + }, + { + "name": "metadata", + "type": "Sequence[Tuple[str, str]" + } + ], + "resultType": "google.api_core.operation.Operation", + "shortName": "suggest_trials" + }, + "description": "Sample for SuggestTrials", + "file": "aiplatform_v1beta1_generated_vizier_service_suggest_trials_sync.py", + "language": "PYTHON", + "origin": "API_DEFINITION", + "regionTag": "aiplatform_v1beta1_generated_VizierService_SuggestTrials_sync", + "segments": [ + { + "end": 50, + "start": 27, + "type": "FULL" + }, + { + "end": 50, + "start": 27, + "type": "SHORT" + }, + { + "end": 33, + "start": 31, + "type": "CLIENT_INITIALIZATION" + }, + { + "end": 40, + "start": 34, + "type": "REQUEST_INITIALIZATION" + }, + { + "end": 47, + "start": 41, + "type": "REQUEST_EXECUTION" + }, + { + "end": 51, + "start": 48, + "type": "RESPONSE_HANDLING" + } + ], + "title": "aiplatform_v1beta1_generated_vizier_service_suggest_trials_sync.py" + } + ] +} diff --git a/samples/model-builder/automl_image_classification_training_job_sample.py b/samples/model-builder/automl_image_classification_training_job_sample.py index 502caf008d..352d057bcd 100644 --- a/samples/model-builder/automl_image_classification_training_job_sample.py +++ b/samples/model-builder/automl_image_classification_training_job_sample.py @@ -18,7 +18,10 @@ # [START aiplatform_sdk_automl_image_classification_training_job_sample] def automl_image_classification_training_job_sample( - project: str, location: str, dataset_id: str, display_name: str, + project: str, + location: str, + dataset_id: str, + display_name: str, ): aiplatform.init(project=project, location=location) diff --git a/samples/model-builder/batch_create_features_sample.py b/samples/model-builder/batch_create_features_sample.py new file mode 100644 index 0000000000..2dd1c11dab --- /dev/null +++ b/samples/model-builder/batch_create_features_sample.py @@ -0,0 +1,46 @@ +# Copyright 2022 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 aiplatform_sdk_batch_create_features_sample] +from google.cloud import aiplatform + + +def batch_create_features_sample( + project: str, + location: str, + entity_type_id: str, + featurestore_id: str, + sync: bool = True, +): + + aiplatform.init(project=project, location=location) + + my_entity_type = aiplatform.featurestore.EntityType( + entity_type_name=entity_type_id, featurestore_id=featurestore_id + ) + + FEATURE_CONFIGS = { + "age": {"value_type": "INT64", "description": "User age"}, + "gender": {"value_type": "STRING", "description": "User gender"}, + "liked_genres": { + "value_type": "STRING_ARRAY", + "description": "An array of genres this user liked", + }, + } + + my_entity_type.batch_create_features(feature_configs=FEATURE_CONFIGS, sync=sync) + + +# [END aiplatform_sdk_batch_create_features_sample] diff --git a/samples/model-builder/batch_create_features_sample_test.py b/samples/model-builder/batch_create_features_sample_test.py new file mode 100644 index 0000000000..d0fcd1c36d --- /dev/null +++ b/samples/model-builder/batch_create_features_sample_test.py @@ -0,0 +1,42 @@ +# Copyright 2022 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 batch_create_features_sample +import test_constants as constants + + +def test_batch_create_features_sample( + mock_sdk_init, mock_get_entity_type, mock_batch_create_features +): + + batch_create_features_sample.batch_create_features_sample( + project=constants.PROJECT, + location=constants.LOCATION, + entity_type_id=constants.ENTITY_TYPE_ID, + featurestore_id=constants.FEATURESTORE_ID, + sync=constants.SYNC, + ) + + mock_sdk_init.assert_called_once_with( + project=constants.PROJECT, location=constants.LOCATION + ) + + mock_get_entity_type.assert_called_once_with( + entity_type_name=constants.ENTITY_TYPE_ID, + featurestore_id=constants.FEATURESTORE_ID, + ) + + mock_batch_create_features.assert_called_once_with( + feature_configs=constants.FEATURE_CONFIGS, sync=constants.SYNC + ) diff --git a/samples/model-builder/batch_serve_features_to_bq_sample.py b/samples/model-builder/batch_serve_features_to_bq_sample.py new file mode 100644 index 0000000000..7228a27749 --- /dev/null +++ b/samples/model-builder/batch_serve_features_to_bq_sample.py @@ -0,0 +1,46 @@ +# Copyright 2022 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 aiplatform_sdk_batch_serve_features_to_bq_sample] +from google.cloud import aiplatform + + +def batch_serve_features_to_bq_sample( + project: str, + location: str, + featurestore_name: str, + bq_destination_output_uri: str, + read_instances_uri: str, + sync: bool = True, +): + + aiplatform.init(project=project, location=location) + + fs = aiplatform.featurestore.Featurestore(featurestore_name=featurestore_name) + + SERVING_FEATURE_IDS = { + "users": ["age", "gender", "liked_genres"], + "movies": ["title", "average_rating", "genres"], + } + + fs.batch_serve_to_bq( + bq_destination_output_uri=bq_destination_output_uri, + serving_feature_ids=SERVING_FEATURE_IDS, + read_instances_uri=read_instances_uri, + sync=sync, + ) + + +# [END aiplatform_sdk_batch_serve_features_to_bq_sample] diff --git a/samples/model-builder/batch_serve_features_to_bq_sample_test.py b/samples/model-builder/batch_serve_features_to_bq_sample_test.py new file mode 100644 index 0000000000..988ab95806 --- /dev/null +++ b/samples/model-builder/batch_serve_features_to_bq_sample_test.py @@ -0,0 +1,45 @@ +# Copyright 2022 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 batch_serve_features_to_bq_sample +import test_constants as constants + + +def test_batch_serve_features_to_bq_sample( + mock_sdk_init, mock_get_featurestore, mock_batch_serve_to_bq +): + + batch_serve_features_to_bq_sample.batch_serve_features_to_bq_sample( + project=constants.PROJECT, + location=constants.LOCATION, + featurestore_name=constants.FEATURESTORE_NAME, + bq_destination_output_uri=constants.BQ_DESTINATION_OUTPUT_URI, + read_instances_uri=constants.INPUT_CSV_FILE, + sync=constants.SYNC, + ) + + mock_sdk_init.assert_called_once_with( + project=constants.PROJECT, location=constants.LOCATION + ) + + mock_get_featurestore.assert_called_once_with( + featurestore_name=constants.FEATURESTORE_NAME + ) + + mock_batch_serve_to_bq.assert_called_once_with( + bq_destination_output_uri=constants.BQ_DESTINATION_OUTPUT_URI, + serving_feature_ids=constants.SERVING_FEATURE_IDS, + read_instances_uri=constants.INPUT_CSV_FILE, + sync=constants.SYNC, + ) diff --git a/samples/model-builder/conftest.py b/samples/model-builder/conftest.py index c6bbd30fc0..d48547c9e3 100644 --- a/samples/model-builder/conftest.py +++ b/samples/model-builder/conftest.py @@ -45,6 +45,12 @@ def mock_tabular_dataset(): yield mock +@pytest.fixture +def mock_time_series_dataset(): + mock = MagicMock(aiplatform.datasets.TimeSeriesDataset) + yield mock + + @pytest.fixture def mock_text_dataset(): mock = MagicMock(aiplatform.datasets.TextDataset) @@ -74,6 +80,13 @@ def mock_get_tabular_dataset(mock_tabular_dataset): yield mock_get_tabular_dataset +@pytest.fixture +def mock_get_time_series_dataset(mock_time_series_dataset): + with patch.object(aiplatform, "TimeSeriesDataset") as mock_get_time_series_dataset: + mock_get_time_series_dataset.return_value = mock_time_series_dataset + yield mock_get_time_series_dataset + + @pytest.fixture def mock_get_text_dataset(mock_text_dataset): with patch.object(aiplatform, "TextDataset") as mock_get_text_dataset: @@ -107,6 +120,15 @@ def mock_create_tabular_dataset(mock_tabular_dataset): yield mock_create_tabular_dataset +@pytest.fixture +def mock_create_time_series_dataset(mock_time_series_dataset): + with patch.object( + aiplatform.TimeSeriesDataset, "create" + ) as mock_create_time_series_dataset: + mock_create_time_series_dataset.return_value = mock_time_series_dataset + yield mock_create_time_series_dataset + + @pytest.fixture def mock_create_text_dataset(mock_text_dataset): with patch.object(aiplatform.TextDataset, "create") as mock_create_text_dataset: @@ -183,6 +205,12 @@ def mock_tabular_training_job(): yield mock +@pytest.fixture +def mock_forecasting_training_job(): + mock = MagicMock(aiplatform.training_jobs.AutoMLForecastingTrainingJob) + yield mock + + @pytest.fixture def mock_text_training_job(): mock = MagicMock(aiplatform.training_jobs.AutoMLTextTrainingJob) @@ -208,6 +236,19 @@ def mock_run_automl_tabular_training_job(mock_tabular_training_job): yield mock +@pytest.fixture +def mock_get_automl_forecasting_training_job(mock_forecasting_training_job): + with patch.object(aiplatform, "AutoMLForecastingTrainingJob") as mock: + mock.return_value = mock_forecasting_training_job + yield mock + + +@pytest.fixture +def mock_run_automl_forecasting_training_job(mock_forecasting_training_job): + with patch.object(mock_forecasting_training_job, "run") as mock: + yield mock + + @pytest.fixture def mock_get_automl_image_training_job(mock_image_training_job): with patch.object(aiplatform, "AutoMLImageTrainingJob") as mock: @@ -364,3 +405,302 @@ def mock_endpoint_explain(mock_endpoint): with patch.object(mock_endpoint, "explain") as mock_endpoint_explain: mock_get_endpoint.return_value = mock_endpoint yield mock_endpoint_explain + + +""" +---------------------------------------------------------------------------- +Feature Store Fixtures +---------------------------------------------------------------------------- +""" + + +@pytest.fixture +def mock_featurestore(): + mock = MagicMock(aiplatform.featurestore.Featurestore) + yield mock + + +@pytest.fixture +def mock_entity_type(): + mock = MagicMock(aiplatform.featurestore.EntityType) + yield mock + + +@pytest.fixture +def mock_feature(): + mock = MagicMock(aiplatform.featurestore.Feature) + yield mock + + +@pytest.fixture +def mock_get_featurestore(mock_featurestore): + with patch.object(aiplatform.featurestore, "Featurestore") as mock_get_featurestore: + mock_get_featurestore.return_value = mock_featurestore + yield mock_get_featurestore + + +@pytest.fixture +def mock_get_entity_type(mock_entity_type): + with patch.object(aiplatform.featurestore, "EntityType") as mock_get_entity_type: + mock_get_entity_type.return_value = mock_entity_type + yield mock_get_entity_type + + +@pytest.fixture +def mock_create_featurestore(mock_featurestore): + with patch.object( + aiplatform.featurestore.Featurestore, "create" + ) as mock_create_featurestore: + mock_create_featurestore.return_value = mock_featurestore + yield mock_create_featurestore + + +@pytest.fixture +def mock_create_entity_type(mock_entity_type): + with patch.object( + aiplatform.featurestore.EntityType, "create" + ) as mock_create_entity_type: + mock_create_entity_type.return_value = mock_entity_type + yield mock_create_entity_type + + +@pytest.fixture +def mock_create_feature(mock_feature): + with patch.object(aiplatform.featurestore.Feature, "create") as mock_create_feature: + mock_create_feature.return_value = mock_feature + yield mock_create_feature + + +@pytest.fixture +def mock_delete_featurestore(mock_featurestore): + with patch.object(mock_featurestore, "delete") as mock_delete_featurestore: + yield mock_delete_featurestore + + +@pytest.fixture +def mock_batch_serve_to_bq(mock_featurestore): + with patch.object(mock_featurestore, "batch_serve_to_bq") as mock_batch_serve_to_bq: + yield mock_batch_serve_to_bq + + +@pytest.fixture +def mock_batch_create_features(mock_entity_type): + with patch.object( + mock_entity_type, "batch_create_features" + ) as mock_batch_create_features: + yield mock_batch_create_features + + +@pytest.fixture +def mock_read_feature_values(mock_entity_type): + with patch.object(mock_entity_type, "read") as mock_read_feature_values: + yield mock_read_feature_values + + +@pytest.fixture +def mock_import_feature_values(mock_entity_type): + with patch.object( + mock_entity_type, "ingest_from_gcs" + ) as mock_import_feature_values: + yield mock_import_feature_values + + +""" +---------------------------------------------------------------------------- +Experiment Tracking Fixtures +---------------------------------------------------------------------------- +""" + + +@pytest.fixture +def mock_execution(): + mock = MagicMock(aiplatform.Execution) + mock.assign_input_artifacts.return_value = None + mock.assign_output_artifacts.return_value = None + mock.__enter__.return_value = mock + yield mock + + +@pytest.fixture +def mock_artifact(): + mock = MagicMock(aiplatform.Artifact) + yield mock + + +@pytest.fixture +def mock_experiment(): + mock = MagicMock(aiplatform.Experiment) + yield mock + + +@pytest.fixture +def mock_experiment_run(): + mock = MagicMock(aiplatform.ExperimentRun) + yield mock + + +@pytest.fixture +def mock_pipeline_job(): + mock = MagicMock(aiplatform.PipelineJob) + yield mock + + +@pytest.fixture +def mock_df(): + mock = MagicMock() + yield mock + + +@pytest.fixture +def mock_metrics(): + mock = MagicMock() + yield mock + + +@pytest.fixture +def mock_params(): + mock = MagicMock() + yield mock + + +@pytest.fixture +def mock_time_series_metrics(): + mock = MagicMock() + yield mock + + +@pytest.fixture +def mock_get_execution(mock_execution): + with patch.object(aiplatform, "Execution") as mock_get_execution: + mock_get_execution.return_value = mock_execution + yield mock_get_execution + + +@pytest.fixture +def mock_get_artifact(mock_artifact): + with patch.object(aiplatform, "Artifact") as mock_get_artifact: + mock_get_artifact.return_value = mock_artifact + yield mock_get_artifact + + +@pytest.fixture +def mock_pipeline_job_create(mock_pipeline_job): + with patch.object(aiplatform, "PipelineJob") as mock_pipeline_job_create: + mock_pipeline_job_create.return_value = mock_pipeline_job + yield mock_pipeline_job_create + + +@pytest.fixture +def mock_pipeline_job_submit(mock_pipeline_job): + with patch.object(mock_pipeline_job, "submit") as mock_pipeline_job_submit: + mock_pipeline_job_submit.return_value = None + yield mock_pipeline_job_submit + + +@pytest.fixture +def mock_create_artifact(mock_artifact): + with patch.object(aiplatform.Artifact, "create") as mock_create_artifact: + mock_create_artifact.return_value = mock_artifact + yield mock_create_artifact + + +@pytest.fixture +def mock_start_run(mock_experiment_run): + with patch.object(aiplatform, "start_run") as mock_start_run: + mock_start_run.return_value = mock_experiment_run + yield mock_start_run + + +@pytest.fixture +def mock_start_execution(mock_execution): + with patch.object(aiplatform, "start_execution") as mock_start_execution: + mock_start_execution.return_value = mock_execution + yield mock_start_execution + + +@pytest.fixture +def mock_end_run(): + with patch.object(aiplatform, "end_run") as mock_end_run: + mock_end_run.return_value = None + yield mock_end_run + + +@pytest.fixture +def mock_log_metrics(): + with patch.object(aiplatform, "log_metrics") as mock_log_metrics: + mock_log_metrics.return_value = None + yield mock_log_metrics + + +@pytest.fixture +def mock_log_time_series_metrics(): + with patch.object( + aiplatform, "log_time_series_metrics" + ) as mock_log_time_series_metrics: + mock_log_time_series_metrics.return_value = None + yield mock_log_time_series_metrics + + +@pytest.fixture +def mock_log_params(): + with patch.object(aiplatform, "log_params") as mock_log_params: + mock_log_params.return_value = None + yield mock_log_params + + +@pytest.fixture +def mock_log_pipeline_job(): + with patch.object(aiplatform, "log") as mock_log_pipeline_job: + mock_log_pipeline_job.return_value = None + yield mock_log_pipeline_job + + +@pytest.fixture +def mock_get_run(mock_experiment_run): + with patch.object(aiplatform, "ExperimentRun") as mock_get_run: + mock_get_run.return_value = mock_experiment_run + yield mock_get_run + + +@pytest.fixture +def mock_get_experiment(mock_experiment): + with patch.object(aiplatform, "Experiment") as mock_get_experiment: + mock_get_experiment.return_value = mock_experiment + yield mock_get_experiment + + +@pytest.fixture +def mock_get_with_uri(mock_artifact): + with patch.object(aiplatform.Artifact, "get_with_uri") as mock_get_with_uri: + mock_get_with_uri.return_value = mock_artifact + yield mock_get_with_uri + + +@pytest.fixture +def mock_get_experiment_df(mock_df): + with patch.object(aiplatform, "get_experiment_df") as mock_get_experiment_df: + mock_get_experiment_df.return_value = mock_df + yield mock_get_experiment_df + + +@pytest.fixture +def mock_get_metrics(mock_metrics, mock_experiment_run): + with patch.object(mock_experiment_run, "get_metrics") as mock_get_metrics: + mock_get_metrics.return_value = mock_metrics + yield mock_get_metrics + + +@pytest.fixture +def mock_get_params(mock_params, mock_experiment_run): + with patch.object(mock_experiment_run, "get_params") as mock_get_params: + mock_get_params.return_value = mock_params + yield mock_get_params + + +@pytest.fixture +def mock_get_time_series_metrics(mock_time_series_metrics, mock_experiment_run): + with patch.object( + mock_experiment_run, "get_time_series_data_frame" + ) as mock_get_time_series_metrics: + mock_get_time_series_metrics.return_value = mock_time_series_metrics + yield mock_get_time_series_metrics diff --git a/samples/model-builder/create_and_import_dataset_image_sample.py b/samples/model-builder/create_and_import_dataset_image_sample.py index bab7c8a59c..f414f9e4ad 100644 --- a/samples/model-builder/create_and_import_dataset_image_sample.py +++ b/samples/model-builder/create_and_import_dataset_image_sample.py @@ -12,12 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. + +# [START aiplatform_sdk_create_and_import_dataset_image_sample] from typing import List, Union from google.cloud import aiplatform -# [START aiplatform_sdk_create_and_import_dataset_image_sample] def create_and_import_dataset_image_sample( project: str, location: str, @@ -25,6 +26,11 @@ def create_and_import_dataset_image_sample( src_uris: Union[str, List[str]], sync: bool = True, ): + """ + src_uris -- a string or list of strings, e.g. + ["gs://bucket1/source1.jsonl", "gs://bucket7/source4.jsonl"] + """ + aiplatform.init(project=project, location=location) ds = aiplatform.ImageDataset.create( diff --git a/samples/model-builder/create_and_import_dataset_tabular_bigquery_sample.py b/samples/model-builder/create_and_import_dataset_tabular_bigquery_sample.py index b7f4ea8013..5942ef1f3f 100644 --- a/samples/model-builder/create_and_import_dataset_tabular_bigquery_sample.py +++ b/samples/model-builder/create_and_import_dataset_tabular_bigquery_sample.py @@ -18,13 +18,17 @@ # [START aiplatform_sdk_create_and_import_dataset_tabular_bigquery_sample] def create_and_import_dataset_tabular_bigquery_sample( - display_name: str, project: str, location: str, bigquery_source: str, + display_name: str, + project: str, + location: str, + bigquery_source: str, ): aiplatform.init(project=project, location=location) dataset = aiplatform.TabularDataset.create( - display_name=display_name, bigquery_source=bigquery_source, + display_name=display_name, + bigquery_source=bigquery_source, ) dataset.wait() diff --git a/samples/model-builder/create_and_import_dataset_tabular_bigquery_sample_test.py b/samples/model-builder/create_and_import_dataset_tabular_bigquery_sample_test.py index 6eefcf7702..448fcf9c44 100644 --- a/samples/model-builder/create_and_import_dataset_tabular_bigquery_sample_test.py +++ b/samples/model-builder/create_and_import_dataset_tabular_bigquery_sample_test.py @@ -32,5 +32,6 @@ def test_create_and_import_dataset_tabular_bigquery_sample( project=constants.PROJECT, location=constants.LOCATION ) mock_create_tabular_dataset.assert_called_once_with( - display_name=constants.DISPLAY_NAME, bigquery_source=constants.BIGQUERY_SOURCE, + display_name=constants.DISPLAY_NAME, + bigquery_source=constants.BIGQUERY_SOURCE, ) diff --git a/samples/model-builder/create_and_import_dataset_tabular_gcs_sample.py b/samples/model-builder/create_and_import_dataset_tabular_gcs_sample.py index cac7a64d89..ba7f6f3b49 100644 --- a/samples/model-builder/create_and_import_dataset_tabular_gcs_sample.py +++ b/samples/model-builder/create_and_import_dataset_tabular_gcs_sample.py @@ -19,13 +19,17 @@ # [START aiplatform_sdk_create_and_import_dataset_tabular_gcs_sample] def create_and_import_dataset_tabular_gcs_sample( - display_name: str, project: str, location: str, gcs_source: Union[str, List[str]], + display_name: str, + project: str, + location: str, + gcs_source: Union[str, List[str]], ): aiplatform.init(project=project, location=location) dataset = aiplatform.TabularDataset.create( - display_name=display_name, gcs_source=gcs_source, + display_name=display_name, + gcs_source=gcs_source, ) dataset.wait() diff --git a/samples/model-builder/create_and_import_dataset_tabular_gcs_sample_test.py b/samples/model-builder/create_and_import_dataset_tabular_gcs_sample_test.py index ca8679be01..3f486a452b 100644 --- a/samples/model-builder/create_and_import_dataset_tabular_gcs_sample_test.py +++ b/samples/model-builder/create_and_import_dataset_tabular_gcs_sample_test.py @@ -32,5 +32,6 @@ def test_create_and_import_dataset_tabular_gcs_sample( project=constants.PROJECT, location=constants.LOCATION ) mock_create_tabular_dataset.assert_called_once_with( - display_name=constants.DISPLAY_NAME, gcs_source=constants.GCS_SOURCES, + display_name=constants.DISPLAY_NAME, + gcs_source=constants.GCS_SOURCES, ) diff --git a/samples/model-builder/create_and_import_dataset_time_series_bigquery_sample.py b/samples/model-builder/create_and_import_dataset_time_series_bigquery_sample.py new file mode 100644 index 0000000000..76c17a9cd3 --- /dev/null +++ b/samples/model-builder/create_and_import_dataset_time_series_bigquery_sample.py @@ -0,0 +1,40 @@ +# Copyright 2022 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 import aiplatform + + +# [START aiplatform_sdk_create_and_import_dataset_time_series_bigquery_sample] +def create_and_import_dataset_time_series_bigquery_sample( + display_name: str, + project: str, + location: str, + bigquery_source: str, +): + + aiplatform.init(project=project, location=location) + + dataset = aiplatform.TimeSeriesDataset.create( + display_name=display_name, + bigquery_source=bigquery_source, + ) + + dataset.wait() + + print(f'\tDataset: "{dataset.display_name}"') + print(f'\tname: "{dataset.resource_name}"') + + +# [END aiplatform_sdk_create_and_import_dataset_time_series_bigquery_sample] diff --git a/samples/model-builder/create_and_import_dataset_time_series_bigquery_sample_test.py b/samples/model-builder/create_and_import_dataset_time_series_bigquery_sample_test.py new file mode 100644 index 0000000000..21436da8ee --- /dev/null +++ b/samples/model-builder/create_and_import_dataset_time_series_bigquery_sample_test.py @@ -0,0 +1,37 @@ +# Copyright 2022 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 create_and_import_dataset_time_series_bigquery_sample +import test_constants as constants + + +def test_create_and_import_dataset_time_series_bigquery_sample( + mock_sdk_init, mock_create_time_series_dataset +): + + create_and_import_dataset_time_series_bigquery_sample.create_and_import_dataset_time_series_bigquery_sample( + project=constants.PROJECT, + location=constants.LOCATION, + bigquery_source=constants.BIGQUERY_SOURCE, + display_name=constants.DISPLAY_NAME, + ) + + mock_sdk_init.assert_called_once_with( + project=constants.PROJECT, location=constants.LOCATION + ) + mock_create_time_series_dataset.assert_called_once_with( + display_name=constants.DISPLAY_NAME, + bigquery_source=constants.BIGQUERY_SOURCE, + ) diff --git a/samples/model-builder/create_and_import_dataset_time_series_gcs_sample.py b/samples/model-builder/create_and_import_dataset_time_series_gcs_sample.py new file mode 100644 index 0000000000..a2fde124d8 --- /dev/null +++ b/samples/model-builder/create_and_import_dataset_time_series_gcs_sample.py @@ -0,0 +1,41 @@ +# Copyright 2022 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 typing import List, Union + +from google.cloud import aiplatform + + +# [START aiplatform_sdk_create_and_import_dataset_time_series_gcs_sample] +def create_and_import_dataset_time_series_gcs_sample( + display_name: str, + project: str, + location: str, + gcs_source: Union[str, List[str]], +): + + aiplatform.init(project=project, location=location) + + dataset = aiplatform.TimeSeriesDataset.create( + display_name=display_name, + gcs_source=gcs_source, + ) + + dataset.wait() + + print(f'\tDataset: "{dataset.display_name}"') + print(f'\tname: "{dataset.resource_name}"') + + +# [END aiplatform_sdk_create_and_import_dataset_time_series_gcs_sample] diff --git a/samples/model-builder/create_and_import_dataset_time_series_gcs_sample_test.py b/samples/model-builder/create_and_import_dataset_time_series_gcs_sample_test.py new file mode 100644 index 0000000000..90c1f9711b --- /dev/null +++ b/samples/model-builder/create_and_import_dataset_time_series_gcs_sample_test.py @@ -0,0 +1,37 @@ +# Copyright 2022 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 create_and_import_dataset_time_series_gcs_sample +import test_constants as constants + + +def test_create_and_import_dataset_time_series_gcs_sample( + mock_sdk_init, mock_create_time_series_dataset +): + + create_and_import_dataset_time_series_gcs_sample.create_and_import_dataset_time_series_gcs_sample( + project=constants.PROJECT, + location=constants.LOCATION, + gcs_source=constants.GCS_SOURCES, + display_name=constants.DISPLAY_NAME, + ) + + mock_sdk_init.assert_called_once_with( + project=constants.PROJECT, location=constants.LOCATION + ) + mock_create_time_series_dataset.assert_called_once_with( + display_name=constants.DISPLAY_NAME, + gcs_source=constants.GCS_SOURCES, + ) diff --git a/samples/model-builder/create_batch_prediction_job_bigquery_sample.py b/samples/model-builder/create_batch_prediction_job_bigquery_sample.py new file mode 100644 index 0000000000..94f66fd04c --- /dev/null +++ b/samples/model-builder/create_batch_prediction_job_bigquery_sample.py @@ -0,0 +1,47 @@ +# 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 import aiplatform + + +# [START aiplatform_sdk_create_batch_prediction_job_bigquery_sample] +def create_batch_prediction_job_bigquery_sample( + project: str, + location: str, + model_resource_name: str, + job_display_name: str, + bigquery_source: str, + bigquery_destination_prefix: str, + sync: bool = True, +): + aiplatform.init(project=project, location=location) + + my_model = aiplatform.Model(model_resource_name) + + batch_prediction_job = my_model.batch_predict( + job_display_name=job_display_name, + bigquery_source=bigquery_source, + bigquery_destination_prefix=bigquery_destination_prefix, + sync=sync, + ) + + batch_prediction_job.wait() + + print(batch_prediction_job.display_name) + print(batch_prediction_job.resource_name) + print(batch_prediction_job.state) + return batch_prediction_job + + +# [END aiplatform_sdk_create_batch_prediction_job_bigquery_sample] diff --git a/samples/model-builder/create_batch_prediction_job_bigquery_sample_test.py b/samples/model-builder/create_batch_prediction_job_bigquery_sample_test.py new file mode 100644 index 0000000000..6b5c509d95 --- /dev/null +++ b/samples/model-builder/create_batch_prediction_job_bigquery_sample_test.py @@ -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 create_batch_prediction_job_bigquery_sample +import test_constants as constants + + +def test_create_batch_prediction_job_bigquery_sample( + mock_sdk_init, mock_model, mock_init_model, mock_batch_predict_model +): + + create_batch_prediction_job_bigquery_sample.create_batch_prediction_job_bigquery_sample( + project=constants.PROJECT, + location=constants.LOCATION, + model_resource_name=constants.MODEL_NAME, + job_display_name=constants.DISPLAY_NAME, + bigquery_source=constants.BIGQUERY_SOURCE, + bigquery_destination_prefix=constants.BIGQUERY_DESTINATION_PREFIX, + ) + + mock_sdk_init.assert_called_once_with( + project=constants.PROJECT, location=constants.LOCATION + ) + mock_init_model.assert_called_once_with(constants.MODEL_NAME) + mock_batch_predict_model.assert_called_once_with( + job_display_name=constants.DISPLAY_NAME, + bigquery_source=constants.BIGQUERY_SOURCE, + bigquery_destination_prefix=constants.BIGQUERY_DESTINATION_PREFIX, + sync=True, + ) diff --git a/samples/model-builder/create_batch_prediction_job_dedicated_resources_bigquery_sample.py b/samples/model-builder/create_batch_prediction_job_dedicated_resources_bigquery_sample.py new file mode 100644 index 0000000000..6c2cdd8953 --- /dev/null +++ b/samples/model-builder/create_batch_prediction_job_dedicated_resources_bigquery_sample.py @@ -0,0 +1,59 @@ +# 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 typing import Union + +from google.cloud import aiplatform, aiplatform_v1 + + +# [START aiplatform_sdk_create_batch_prediction_job_dedicated_resources_bigquery_sample] +def create_batch_prediction_job_dedicated_resources_bigquery_sample( + project: str, + location: str, + model_resource_name: str, + job_display_name: str, + bigquery_source: str, + bigquery_destination_prefix: str, + machine_type: str = "n1-standard-2", + accelerator_count: int = 1, + accelerator_type: Union[str, aiplatform_v1.AcceleratorType] = "NVIDIA_TESLA_K80", + starting_replica_count: int = 1, + max_replica_count: int = 1, + sync: bool = True, +): + aiplatform.init(project=project, location=location) + + my_model = aiplatform.Model(model_resource_name) + + batch_prediction_job = my_model.batch_predict( + job_display_name=job_display_name, + bigquery_source=bigquery_source, + bigquery_destination_prefix=bigquery_destination_prefix, + machine_type=machine_type, + accelerator_count=accelerator_count, + accelerator_type=accelerator_type, + starting_replica_count=starting_replica_count, + max_replica_count=max_replica_count, + sync=sync, + ) + + batch_prediction_job.wait() + + print(batch_prediction_job.display_name) + print(batch_prediction_job.resource_name) + print(batch_prediction_job.state) + return batch_prediction_job + + +# [END aiplatform_sdk_create_batch_prediction_job_dedicated_resources_bigquery_sample] diff --git a/samples/model-builder/create_batch_prediction_job_dedicated_resources_sample_bigquery_test.py b/samples/model-builder/create_batch_prediction_job_dedicated_resources_sample_bigquery_test.py new file mode 100644 index 0000000000..d40b91d31e --- /dev/null +++ b/samples/model-builder/create_batch_prediction_job_dedicated_resources_sample_bigquery_test.py @@ -0,0 +1,55 @@ +# 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 pytest + +import create_batch_prediction_job_dedicated_resources_bigquery_sample +import test_constants as constants + + +@pytest.mark.usefixtures("mock_model") +def test_create_batch_prediction_job_bigquery_sample( + mock_sdk_init, mock_init_model, mock_batch_predict_model +): + + create_batch_prediction_job_dedicated_resources_bigquery_sample.create_batch_prediction_job_dedicated_resources_bigquery_sample( + project=constants.PROJECT, + location=constants.LOCATION, + model_resource_name=constants.MODEL_NAME, + job_display_name=constants.DISPLAY_NAME, + bigquery_source=constants.BIGQUERY_SOURCE, + bigquery_destination_prefix=constants.BIGQUERY_DESTINATION_PREFIX, + machine_type=constants.ACCELERATOR_TYPE, + accelerator_count=constants.ACCELERATOR_COUNT, + accelerator_type=constants.ACCELERATOR_TYPE, + starting_replica_count=constants.MIN_REPLICA_COUNT, + max_replica_count=constants.MAX_REPLICA_COUNT, + ) + + mock_sdk_init.assert_called_once_with( + project=constants.PROJECT, location=constants.LOCATION + ) + mock_init_model.assert_called_once_with(constants.MODEL_NAME) + mock_batch_predict_model.assert_called_once_with( + job_display_name=constants.DISPLAY_NAME, + bigquery_source=constants.BIGQUERY_SOURCE, + bigquery_destination_prefix=constants.BIGQUERY_DESTINATION_PREFIX, + machine_type=constants.ACCELERATOR_TYPE, + accelerator_count=constants.ACCELERATOR_COUNT, + accelerator_type=constants.ACCELERATOR_TYPE, + starting_replica_count=constants.MIN_REPLICA_COUNT, + max_replica_count=constants.MAX_REPLICA_COUNT, + sync=True, + ) diff --git a/samples/model-builder/create_endpoint_sample.py b/samples/model-builder/create_endpoint_sample.py index fa3762bd57..38536ca598 100644 --- a/samples/model-builder/create_endpoint_sample.py +++ b/samples/model-builder/create_endpoint_sample.py @@ -17,17 +17,20 @@ # [START aiplatform_sdk_create_endpoint_sample] def create_endpoint_sample( - project: str, display_name: str, location: str, sync: bool = True, + project: str, + display_name: str, + location: str, ): aiplatform.init(project=project, location=location) endpoint = aiplatform.Endpoint.create( - display_name=display_name, project=project, location=location, + display_name=display_name, + project=project, + location=location, ) print(endpoint.display_name) print(endpoint.resource_name) - print(endpoint.uri) return endpoint diff --git a/samples/model-builder/create_entity_type_sample.py b/samples/model-builder/create_entity_type_sample.py new file mode 100644 index 0000000000..bdd3678dcd --- /dev/null +++ b/samples/model-builder/create_entity_type_sample.py @@ -0,0 +1,38 @@ +# Copyright 2022 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 aiplatform_sdk_create_entity_type_sample] +from google.cloud import aiplatform + + +def create_entity_type_sample( + project: str, + location: str, + entity_type_id: str, + featurestore_name: str, +): + + aiplatform.init(project=project, location=location) + + my_entity_type = aiplatform.EntityType.create( + entity_type_id=entity_type_id, featurestore_name=featurestore_name + ) + + my_entity_type.wait() + + return my_entity_type + + +# [END aiplatform_sdk_create_entity_type_sample] diff --git a/samples/model-builder/create_entity_type_sample_test.py b/samples/model-builder/create_entity_type_sample_test.py new file mode 100644 index 0000000000..fe7dfd3f77 --- /dev/null +++ b/samples/model-builder/create_entity_type_sample_test.py @@ -0,0 +1,35 @@ +# Copyright 2022 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 create_entity_type_sample +import test_constants as constants + + +def test_create_entity_type_sample(mock_sdk_init, mock_create_entity_type): + + create_entity_type_sample.create_entity_type_sample( + project=constants.PROJECT, + location=constants.LOCATION, + entity_type_id=constants.ENTITY_TYPE_ID, + featurestore_name=constants.FEATURESTORE_NAME, + ) + + mock_sdk_init.assert_called_once_with( + project=constants.PROJECT, location=constants.LOCATION + ) + + mock_create_entity_type.assert_called_once_with( + entity_type_id=constants.ENTITY_TYPE_ID, + featurestore_name=constants.FEATURESTORE_NAME, + ) diff --git a/samples/model-builder/create_feature_sample.py b/samples/model-builder/create_feature_sample.py new file mode 100644 index 0000000000..b9b2328ae8 --- /dev/null +++ b/samples/model-builder/create_feature_sample.py @@ -0,0 +1,43 @@ +# Copyright 2022 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 aiplatform_sdk_create_feature_sample] +from google.cloud import aiplatform + + +def create_feature_sample( + project: str, + location: str, + feature_id: str, + value_type: str, + entity_type_id: str, + featurestore_id: str, +): + + aiplatform.init(project=project, location=location) + + my_feature = aiplatform.Feature.create( + feature_id=feature_id, + value_type=value_type, + entity_type_name=entity_type_id, + featurestore_id=featurestore_id, + ) + + my_feature.wait() + + return my_feature + + +# [END aiplatform_sdk_create_feature_sample] diff --git a/samples/model-builder/create_feature_sample_test.py b/samples/model-builder/create_feature_sample_test.py new file mode 100644 index 0000000000..673f475691 --- /dev/null +++ b/samples/model-builder/create_feature_sample_test.py @@ -0,0 +1,39 @@ +# Copyright 2022 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 create_feature_sample +import test_constants as constants + + +def test_create_feature_sample(mock_sdk_init, mock_create_feature): + + create_feature_sample.create_feature_sample( + project=constants.PROJECT, + location=constants.LOCATION, + feature_id=constants.FEATURE_ID, + value_type=constants.FEATURE_VALUE_TYPE, + entity_type_id=constants.ENTITY_TYPE_ID, + featurestore_id=constants.FEATURESTORE_ID, + ) + + mock_sdk_init.assert_called_once_with( + project=constants.PROJECT, location=constants.LOCATION + ) + + mock_create_feature.assert_called_once_with( + feature_id=constants.FEATURE_ID, + value_type=constants.FEATURE_VALUE_TYPE, + entity_type_name=constants.ENTITY_TYPE_ID, + featurestore_id=constants.FEATURESTORE_ID, + ) diff --git a/samples/model-builder/create_featurestore_sample.py b/samples/model-builder/create_featurestore_sample.py new file mode 100644 index 0000000000..48a143aa11 --- /dev/null +++ b/samples/model-builder/create_featurestore_sample.py @@ -0,0 +1,41 @@ +# Copyright 2022 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 aiplatform_sdk_create_featurestore_sample] +from google.cloud import aiplatform + + +def create_featurestore_sample( + project: str, + location: str, + featurestore_id: str, + online_store_fixed_node_count: int = 1, + sync: bool = True, +): + + aiplatform.init(project=project, location=location) + + fs = aiplatform.Featurestore.create( + featurestore_id=featurestore_id, + online_store_fixed_node_count=online_store_fixed_node_count, + sync=sync, + ) + + fs.wait() + + return fs + + +# [END aiplatform_sdk_create_featurestore_sample] diff --git a/samples/model-builder/create_featurestore_sample_test.py b/samples/model-builder/create_featurestore_sample_test.py new file mode 100644 index 0000000000..2531f58c6d --- /dev/null +++ b/samples/model-builder/create_featurestore_sample_test.py @@ -0,0 +1,37 @@ +# Copyright 2022 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 create_featurestore_sample +import test_constants as constants + + +def test_create_featurestore_sample(mock_sdk_init, mock_create_featurestore): + + create_featurestore_sample.create_featurestore_sample( + project=constants.PROJECT, + location=constants.LOCATION, + featurestore_id=constants.FEATURESTORE_ID, + online_store_fixed_node_count=constants.ONLINE_STORE_FIXED_NODE_COUNT, + sync=constants.SYNC, + ) + + mock_sdk_init.assert_called_once_with( + project=constants.PROJECT, location=constants.LOCATION + ) + + mock_create_featurestore.assert_called_once_with( + featurestore_id=constants.FEATURESTORE_ID, + online_store_fixed_node_count=constants.ONLINE_STORE_FIXED_NODE_COUNT, + sync=constants.SYNC, + ) diff --git a/samples/model-builder/create_training_pipeline_forecasting_sample.py b/samples/model-builder/create_training_pipeline_forecasting_sample.py new file mode 100644 index 0000000000..0b710e894b --- /dev/null +++ b/samples/model-builder/create_training_pipeline_forecasting_sample.py @@ -0,0 +1,98 @@ +# Copyright 2022 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 typing import List, Optional + +from google.cloud import aiplatform + + +# [START aiplatform_sdk_create_training_pipeline_forecasting_sample] +def create_training_pipeline_forecasting_sample( + project: str, + display_name: str, + dataset_id: str, + location: str = "us-central1", + model_display_name: str = None, + target_column: str = "target_column", + time_column: str = "date", + time_series_identifier_column: str = "time_series_id", + unavailable_at_forecast_columns: List[str] = [], + available_at_forecast_columns: List[str] = [], + forecast_horizon: int = 1, + data_granularity_unit: str = "week", + data_granularity_count: int = 1, + training_fraction_split: float = 0.8, + validation_fraction_split: float = 0.1, + test_fraction_split: float = 0.1, + budget_milli_node_hours: int = 8000, + timestamp_split_column_name: str = "timestamp_split", + weight_column: str = "weight", + time_series_attribute_columns: List[str] = [], + context_window: int = 0, + export_evaluated_data_items: bool = False, + export_evaluated_data_items_bigquery_destination_uri: Optional[str] = None, + export_evaluated_data_items_override_destination: bool = False, + quantiles: Optional[List[float]] = None, + validation_options: Optional[str] = None, + predefined_split_column_name: Optional[str] = None, + sync: bool = True, +): + aiplatform.init(project=project, location=location) + + # Create training job + forecasting_job = aiplatform.AutoMLForecastingTrainingJob( + display_name=display_name, optimization_objective="minimize-rmse" + ) + + # Retrieve existing dataset + dataset = aiplatform.TimeSeriesDataset(dataset_id) + + # Run training job + model = forecasting_job.run( + dataset=dataset, + target_column=target_column, + time_column=time_column, + time_series_identifier_column=time_series_identifier_column, + unavailable_at_forecast_columns=unavailable_at_forecast_columns, + available_at_forecast_columns=available_at_forecast_columns, + forecast_horizon=forecast_horizon, + data_granularity_unit=data_granularity_unit, + data_granularity_count=data_granularity_count, + training_fraction_split=training_fraction_split, + validation_fraction_split=validation_fraction_split, + test_fraction_split=test_fraction_split, + predefined_split_column_name=predefined_split_column_name, + timestamp_split_column_name=timestamp_split_column_name, + weight_column=weight_column, + time_series_attribute_columns=time_series_attribute_columns, + context_window=context_window, + export_evaluated_data_items=export_evaluated_data_items, + export_evaluated_data_items_bigquery_destination_uri=export_evaluated_data_items_bigquery_destination_uri, + export_evaluated_data_items_override_destination=export_evaluated_data_items_override_destination, + quantiles=quantiles, + validation_options=validation_options, + budget_milli_node_hours=budget_milli_node_hours, + model_display_name=model_display_name, + sync=sync, + ) + + model.wait() + + print(model.display_name) + print(model.resource_name) + print(model.uri) + return model + + +# [END aiplatform_sdk_create_training_pipeline_forecasting_sample] diff --git a/samples/model-builder/create_training_pipeline_forecasting_sample_test.py b/samples/model-builder/create_training_pipeline_forecasting_sample_test.py new file mode 100644 index 0000000000..2aa6eaa76d --- /dev/null +++ b/samples/model-builder/create_training_pipeline_forecasting_sample_test.py @@ -0,0 +1,85 @@ +# Copyright 2022 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 create_training_pipeline_forecasting_sample +import test_constants as constants + + +def test_create_training_pipeline_forecasting_sample( + mock_sdk_init, + mock_time_series_dataset, + mock_get_automl_forecasting_training_job, + mock_run_automl_forecasting_training_job, + mock_get_time_series_dataset, +): + + create_training_pipeline_forecasting_sample.create_training_pipeline_forecasting_sample( + project=constants.PROJECT, + display_name=constants.DISPLAY_NAME, + dataset_id=constants.RESOURCE_ID, + model_display_name=constants.DISPLAY_NAME_2, + target_column=constants.TABULAR_TARGET_COLUMN, + training_fraction_split=constants.TRAINING_FRACTION_SPLIT, + validation_fraction_split=constants.VALIDATION_FRACTION_SPLIT, + test_fraction_split=constants.TEST_FRACTION_SPLIT, + budget_milli_node_hours=constants.BUDGET_MILLI_NODE_HOURS_8000, + timestamp_split_column_name=constants.TIMESTAMP_SPLIT_COLUMN_NAME, + weight_column=constants.WEIGHT_COLUMN, + time_series_attribute_columns=constants.TIME_SERIES_ATTRIBUTE_COLUMNS, + context_window=constants.CONTEXT_WINDOW, + export_evaluated_data_items=constants.EXPORT_EVALUATED_DATA_ITEMS, + export_evaluated_data_items_bigquery_destination_uri=constants.EXPORT_EVALUATED_DATA_ITEMS_BIGQUERY_DESTINATION_URI, + export_evaluated_data_items_override_destination=constants.EXPORT_EVALUATED_DATA_ITEMS_OVERRIDE_DESTINATION, + quantiles=constants.QUANTILES, + validation_options=constants.VALIDATION_OPTIONS, + predefined_split_column_name=constants.PREDEFINED_SPLIT_COLUMN_NAME, + ) + + mock_get_time_series_dataset.assert_called_once_with(constants.RESOURCE_ID) + + mock_sdk_init.assert_called_once_with( + project=constants.PROJECT, location=constants.LOCATION + ) + mock_get_automl_forecasting_training_job.assert_called_once_with( + display_name=constants.DISPLAY_NAME, + optimization_objective="minimize-rmse", + ) + mock_run_automl_forecasting_training_job.assert_called_once_with( + dataset=mock_time_series_dataset, + target_column=constants.TABULAR_TARGET_COLUMN, + time_column=constants.FORECASTNG_TIME_COLUMN, + time_series_identifier_column=constants.FORECASTNG_TIME_SERIES_IDENTIFIER_COLUMN, + unavailable_at_forecast_columns=constants.FORECASTNG_UNAVAILABLE_AT_FORECAST_COLUMNS, + available_at_forecast_columns=constants.FORECASTNG_AVAILABLE_AT_FORECAST_COLUMNS, + forecast_horizon=constants.FORECASTNG_FORECAST_HORIZON, + data_granularity_unit=constants.DATA_GRANULARITY_UNIT, + data_granularity_count=constants.DATA_GRANULARITY_COUNT, + training_fraction_split=constants.TRAINING_FRACTION_SPLIT, + validation_fraction_split=constants.VALIDATION_FRACTION_SPLIT, + test_fraction_split=constants.TEST_FRACTION_SPLIT, + budget_milli_node_hours=constants.BUDGET_MILLI_NODE_HOURS_8000, + model_display_name=constants.DISPLAY_NAME_2, + timestamp_split_column_name=constants.TIMESTAMP_SPLIT_COLUMN_NAME, + weight_column=constants.WEIGHT_COLUMN, + time_series_attribute_columns=constants.TIME_SERIES_ATTRIBUTE_COLUMNS, + context_window=constants.CONTEXT_WINDOW, + export_evaluated_data_items=constants.EXPORT_EVALUATED_DATA_ITEMS, + export_evaluated_data_items_bigquery_destination_uri=constants.EXPORT_EVALUATED_DATA_ITEMS_BIGQUERY_DESTINATION_URI, + export_evaluated_data_items_override_destination=constants.EXPORT_EVALUATED_DATA_ITEMS_OVERRIDE_DESTINATION, + quantiles=constants.QUANTILES, + validation_options=constants.VALIDATION_OPTIONS, + predefined_split_column_name=constants.PREDEFINED_SPLIT_COLUMN_NAME, + sync=True, + ) diff --git a/samples/model-builder/create_training_pipeline_image_classification_sample.py b/samples/model-builder/create_training_pipeline_image_classification_sample.py index 3786894a05..ccf95ec746 100644 --- a/samples/model-builder/create_training_pipeline_image_classification_sample.py +++ b/samples/model-builder/create_training_pipeline_image_classification_sample.py @@ -22,8 +22,10 @@ def create_training_pipeline_image_classification_sample( project: str, location: str, display_name: str, - dataset_id: int, + dataset_id: str, model_display_name: Optional[str] = None, + model_type: str = "CLOUD", + multi_label: bool = False, training_fraction_split: float = 0.8, validation_fraction_split: float = 0.1, test_fraction_split: float = 0.1, @@ -33,7 +35,12 @@ def create_training_pipeline_image_classification_sample( ): aiplatform.init(project=project, location=location) - job = aiplatform.AutoMLImageTrainingJob(display_name=display_name) + job = aiplatform.AutoMLImageTrainingJob( + display_name=display_name, + model_type=model_type, + prediction_type="classification", + multi_label=multi_label, + ) my_image_ds = aiplatform.ImageDataset(dataset_id) diff --git a/samples/model-builder/create_training_pipeline_image_classification_sample_test.py b/samples/model-builder/create_training_pipeline_image_classification_sample_test.py index 1c7080e7a1..83d49b4d91 100644 --- a/samples/model-builder/create_training_pipeline_image_classification_sample_test.py +++ b/samples/model-builder/create_training_pipeline_image_classification_sample_test.py @@ -44,7 +44,10 @@ def test_create_training_pipeline_image_classification_sample( project=constants.PROJECT, location=constants.LOCATION ) mock_get_automl_image_training_job.assert_called_once_with( - display_name=constants.DISPLAY_NAME + display_name=constants.DISPLAY_NAME, + model_type=constants.MODEL_TYPE, + multi_label=False, + prediction_type="classification", ) mock_run_automl_image_training_job.assert_called_once_with( dataset=mock_image_dataset, diff --git a/samples/model-builder/create_training_pipeline_tabular_classification_sample.py b/samples/model-builder/create_training_pipeline_tabular_classification_sample.py index 6bd9405383..6e9e520317 100644 --- a/samples/model-builder/create_training_pipeline_tabular_classification_sample.py +++ b/samples/model-builder/create_training_pipeline_tabular_classification_sample.py @@ -19,9 +19,10 @@ def create_training_pipeline_tabular_classification_sample( project: str, display_name: str, - dataset_id: int, + dataset_id: str, location: str = "us-central1", model_display_name: str = None, + target_column: str = "target_column", training_fraction_split: float = 0.8, validation_fraction_split: float = 0.1, test_fraction_split: float = 0.1, @@ -32,13 +33,14 @@ def create_training_pipeline_tabular_classification_sample( aiplatform.init(project=project, location=location) tabular_classification_job = aiplatform.AutoMLTabularTrainingJob( - display_name=display_name, + display_name=display_name, optimization_prediction_type="classification" ) - my_tabular_dataset = aiplatform.TabularDataset(dataset_id) + my_tabular_dataset = aiplatform.TabularDataset(dataset_name=dataset_id) model = tabular_classification_job.run( dataset=my_tabular_dataset, + target_column=target_column, training_fraction_split=training_fraction_split, validation_fraction_split=validation_fraction_split, test_fraction_split=test_fraction_split, diff --git a/samples/model-builder/create_training_pipeline_tabular_classification_sample_test.py b/samples/model-builder/create_training_pipeline_tabular_classification_sample_test.py index c015e99785..cb0de0320d 100644 --- a/samples/model-builder/create_training_pipeline_tabular_classification_sample_test.py +++ b/samples/model-builder/create_training_pipeline_tabular_classification_sample_test.py @@ -30,6 +30,7 @@ def test_create_training_pipeline_tabular_classification_sample( display_name=constants.DISPLAY_NAME, dataset_id=constants.RESOURCE_ID, model_display_name=constants.DISPLAY_NAME_2, + target_column=constants.TABULAR_TARGET_COLUMN, training_fraction_split=constants.TRAINING_FRACTION_SPLIT, validation_fraction_split=constants.VALIDATION_FRACTION_SPLIT, test_fraction_split=constants.TEST_FRACTION_SPLIT, @@ -37,17 +38,19 @@ def test_create_training_pipeline_tabular_classification_sample( disable_early_stopping=False, ) - mock_get_tabular_dataset.assert_called_once_with(constants.RESOURCE_ID) + mock_get_tabular_dataset.assert_called_once_with(dataset_name=constants.RESOURCE_ID) mock_sdk_init.assert_called_once_with( project=constants.PROJECT, location=constants.LOCATION ) mock_get_automl_tabular_training_job.assert_called_once_with( display_name=constants.DISPLAY_NAME, + optimization_prediction_type="classification", ) mock_run_automl_tabular_training_job.assert_called_once_with( dataset=mock_tabular_dataset, model_display_name=constants.DISPLAY_NAME_2, + target_column=constants.TABULAR_TARGET_COLUMN, training_fraction_split=constants.TRAINING_FRACTION_SPLIT, validation_fraction_split=constants.VALIDATION_FRACTION_SPLIT, test_fraction_split=constants.TEST_FRACTION_SPLIT, diff --git a/samples/model-builder/create_training_pipeline_tabular_regression_sample.py b/samples/model-builder/create_training_pipeline_tabular_regression_sample.py index 2404bb37e2..9a3524f234 100644 --- a/samples/model-builder/create_training_pipeline_tabular_regression_sample.py +++ b/samples/model-builder/create_training_pipeline_tabular_regression_sample.py @@ -19,9 +19,10 @@ def create_training_pipeline_tabular_regression_sample( project: str, display_name: str, - dataset_id: int, + dataset_id: str, location: str = "us-central1", model_display_name: str = None, + target_column: str = "target_column", training_fraction_split: float = 0.8, validation_fraction_split: float = 0.1, test_fraction_split: float = 0.1, @@ -32,13 +33,14 @@ def create_training_pipeline_tabular_regression_sample( aiplatform.init(project=project, location=location) tabular_regression_job = aiplatform.AutoMLTabularTrainingJob( - display_name=display_name, + display_name=display_name, optimization_prediction_type="regression" ) - my_tabular_dataset = aiplatform.TabularDataset(dataset_id) + my_tabular_dataset = aiplatform.TabularDataset(dataset_name=dataset_id) model = tabular_regression_job.run( dataset=my_tabular_dataset, + target_column=target_column, training_fraction_split=training_fraction_split, validation_fraction_split=validation_fraction_split, test_fraction_split=test_fraction_split, diff --git a/samples/model-builder/create_training_pipeline_tabular_regression_sample_test.py b/samples/model-builder/create_training_pipeline_tabular_regression_sample_test.py index 1e897b5851..c39ebcfa4f 100644 --- a/samples/model-builder/create_training_pipeline_tabular_regression_sample_test.py +++ b/samples/model-builder/create_training_pipeline_tabular_regression_sample_test.py @@ -30,6 +30,7 @@ def test_create_training_pipeline_tabular_regression_sample( display_name=constants.DISPLAY_NAME, dataset_id=constants.RESOURCE_ID, model_display_name=constants.DISPLAY_NAME_2, + target_column=constants.TABULAR_TARGET_COLUMN, training_fraction_split=constants.TRAINING_FRACTION_SPLIT, validation_fraction_split=constants.VALIDATION_FRACTION_SPLIT, test_fraction_split=constants.TEST_FRACTION_SPLIT, @@ -37,17 +38,18 @@ def test_create_training_pipeline_tabular_regression_sample( disable_early_stopping=False, ) - mock_get_tabular_dataset.assert_called_once_with(constants.RESOURCE_ID) + mock_get_tabular_dataset.assert_called_once_with(dataset_name=constants.RESOURCE_ID) mock_sdk_init.assert_called_once_with( project=constants.PROJECT, location=constants.LOCATION ) mock_get_automl_tabular_training_job.assert_called_once_with( - display_name=constants.DISPLAY_NAME, + display_name=constants.DISPLAY_NAME, optimization_prediction_type="regression" ) mock_run_automl_tabular_training_job.assert_called_once_with( dataset=mock_tabular_dataset, model_display_name=constants.DISPLAY_NAME_2, + target_column=constants.TABULAR_TARGET_COLUMN, training_fraction_split=constants.TRAINING_FRACTION_SPLIT, validation_fraction_split=constants.VALIDATION_FRACTION_SPLIT, test_fraction_split=constants.TEST_FRACTION_SPLIT, diff --git a/samples/model-builder/create_training_pipeline_text_classification_sample.py b/samples/model-builder/create_training_pipeline_text_classification_sample.py index 9306a82084..b27a2f18d4 100644 --- a/samples/model-builder/create_training_pipeline_text_classification_sample.py +++ b/samples/model-builder/create_training_pipeline_text_classification_sample.py @@ -22,7 +22,7 @@ def create_training_pipeline_text_classification_sample( project: str, location: str, display_name: str, - dataset_id: int, + dataset_id: str, model_display_name: Optional[str] = None, multi_label: bool = False, training_fraction_split: float = 0.8, diff --git a/samples/model-builder/create_training_pipeline_text_entity_extraction_sample.py b/samples/model-builder/create_training_pipeline_text_entity_extraction_sample.py index 2d53cb2d63..8e5c25d1b2 100644 --- a/samples/model-builder/create_training_pipeline_text_entity_extraction_sample.py +++ b/samples/model-builder/create_training_pipeline_text_entity_extraction_sample.py @@ -22,7 +22,7 @@ def create_training_pipeline_text_entity_extraction_sample( project: str, location: str, display_name: str, - dataset_id: int, + dataset_id: str, model_display_name: Optional[str] = None, training_fraction_split: float = 0.8, validation_fraction_split: float = 0.1, diff --git a/samples/model-builder/create_training_pipeline_text_sentiment_analysis_sample.py b/samples/model-builder/create_training_pipeline_text_sentiment_analysis_sample.py index 685bed6feb..57a829f237 100644 --- a/samples/model-builder/create_training_pipeline_text_sentiment_analysis_sample.py +++ b/samples/model-builder/create_training_pipeline_text_sentiment_analysis_sample.py @@ -22,7 +22,7 @@ def create_training_pipeline_text_sentiment_analysis_sample( project: str, location: str, display_name: str, - dataset_id: int, + dataset_id: str, model_display_name: Optional[str] = None, sentiment_max: int = 10, training_fraction_split: float = 0.8, diff --git a/samples/model-builder/delete_featurestore_sample.py b/samples/model-builder/delete_featurestore_sample.py new file mode 100644 index 0000000000..a03a6d1d5a --- /dev/null +++ b/samples/model-builder/delete_featurestore_sample.py @@ -0,0 +1,34 @@ +# Copyright 2022 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 aiplatform_sdk_delete_featurestore_sample] +from google.cloud import aiplatform + + +def delete_featurestore_sample( + project: str, + location: str, + featurestore_name: str, + sync: bool = True, + force: bool = True, +): + + aiplatform.init(project=project, location=location) + + fs = aiplatform.featurestore.Featurestore(featurestore_name=featurestore_name) + fs.delete(sync=sync, force=force) + + +# [END aiplatform_sdk_delete_featurestore_sample] diff --git a/samples/model-builder/delete_featurestore_sample_test.py b/samples/model-builder/delete_featurestore_sample_test.py new file mode 100644 index 0000000000..21b7cba84c --- /dev/null +++ b/samples/model-builder/delete_featurestore_sample_test.py @@ -0,0 +1,41 @@ +# Copyright 2022 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 delete_featurestore_sample +import test_constants as constants + + +def test_delete_featurestore_sample( + mock_sdk_init, mock_get_featurestore, mock_delete_featurestore +): + + delete_featurestore_sample.delete_featurestore_sample( + project=constants.PROJECT, + location=constants.LOCATION, + featurestore_name=constants.FEATURESTORE_NAME, + sync=constants.SYNC, + force=constants.FORCE, + ) + + mock_sdk_init.assert_called_once_with( + project=constants.PROJECT, location=constants.LOCATION + ) + + mock_get_featurestore.assert_called_once_with( + featurestore_name=constants.FEATURESTORE_NAME + ) + + mock_delete_featurestore.assert_called_once_with( + sync=constants.SYNC, force=constants.FORCE + ) diff --git a/samples/model-builder/deploy_model_with_automatic_resources_sample.py b/samples/model-builder/deploy_model_with_automatic_resources_sample.py index 27976ae652..22e0e779c5 100644 --- a/samples/model-builder/deploy_model_with_automatic_resources_sample.py +++ b/samples/model-builder/deploy_model_with_automatic_resources_sample.py @@ -31,6 +31,11 @@ def deploy_model_with_automatic_resources_sample( metadata: Optional[Sequence[Tuple[str, str]]] = (), sync: bool = True, ): + """ + model_name: A fully-qualified model resource name or model ID. + Example: "projects/123/locations/us-central1/models/456" or + "456" when project and location are initialized or passed. + """ aiplatform.init(project=project, location=location) diff --git a/samples/model-builder/deploy_model_with_automatic_resources_test.py b/samples/model-builder/deploy_model_with_automatic_resources_test.py index fff08b6e7e..b4485961ff 100644 --- a/samples/model-builder/deploy_model_with_automatic_resources_test.py +++ b/samples/model-builder/deploy_model_with_automatic_resources_test.py @@ -18,7 +18,10 @@ def test_deploy_model_with_automatic_resources_sample( - mock_sdk_init, mock_model, mock_init_model, mock_deploy_model, + mock_sdk_init, + mock_model, + mock_init_model, + mock_deploy_model, ): deploy_model_with_automatic_resources_sample.deploy_model_with_automatic_resources_sample( diff --git a/samples/model-builder/deploy_model_with_dedicated_resources_sample.py b/samples/model-builder/deploy_model_with_dedicated_resources_sample.py index 093dfae805..cdb021a77b 100644 --- a/samples/model-builder/deploy_model_with_dedicated_resources_sample.py +++ b/samples/model-builder/deploy_model_with_dedicated_resources_sample.py @@ -37,6 +37,11 @@ def deploy_model_with_dedicated_resources_sample( metadata: Optional[Sequence[Tuple[str, str]]] = (), sync: bool = True, ): + """ + model_name: A fully-qualified model resource name or model ID. + Example: "projects/123/locations/us-central1/models/456" or + "456" when project and location are initialized or passed. + """ aiplatform.init(project=project, location=location) diff --git a/samples/model-builder/experiment_tracking/assign_artifact_as_execution_input_sample.py b/samples/model-builder/experiment_tracking/assign_artifact_as_execution_input_sample.py new file mode 100644 index 0000000000..c91b31b9c0 --- /dev/null +++ b/samples/model-builder/experiment_tracking/assign_artifact_as_execution_input_sample.py @@ -0,0 +1,24 @@ +# Copyright 2022 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 import aiplatform + + +# [START aiplatform_sdk_assign_artifact_as_execution_input_sample] +def assign_artifact_as_execution_input_sample( + execution: aiplatform.Execution, + artifact: aiplatform.Artifact, +): + execution.assign_input_artifacts([artifact]) +# [END aiplatform_sdk_assign_artifact_as_execution_input_sample] diff --git a/samples/model-builder/experiment_tracking/assign_artifact_as_execution_input_sample_test.py b/samples/model-builder/experiment_tracking/assign_artifact_as_execution_input_sample_test.py new file mode 100644 index 0000000000..316caf5393 --- /dev/null +++ b/samples/model-builder/experiment_tracking/assign_artifact_as_execution_input_sample_test.py @@ -0,0 +1,29 @@ +# Copyright 2022 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 assign_artifact_as_execution_input_sample +from google.cloud import aiplatform + + +def test_assign_artifact_as_execution_input_sample( + mock_get_execution, + mock_get_artifact, +): + exc = aiplatform.Execution() + art = aiplatform.Artifact() + assign_artifact_as_execution_input_sample.assign_artifact_as_execution_input_sample( + execution=exc, artifact=art + ) + + exc.assign_input_artifacts.assert_called_with([art]) diff --git a/samples/model-builder/experiment_tracking/assign_artifact_as_execution_output_sample.py b/samples/model-builder/experiment_tracking/assign_artifact_as_execution_output_sample.py new file mode 100644 index 0000000000..dabf50985e --- /dev/null +++ b/samples/model-builder/experiment_tracking/assign_artifact_as_execution_output_sample.py @@ -0,0 +1,26 @@ +# Copyright 2022 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 import aiplatform + + +# [START aiplatform_sdk_assign_artifact_as_execution_output_sample] +def assign_artifact_as_execution_output_sample( + execution: aiplatform.Execution, + artifact: aiplatform.Artifact, +): + execution.assign_output_artifacts([artifact]) + + +# [END aiplatform_sdk_assign_artifact_as_execution_output_sample] diff --git a/samples/model-builder/experiment_tracking/assign_artifact_as_execution_output_sample_test.py b/samples/model-builder/experiment_tracking/assign_artifact_as_execution_output_sample_test.py new file mode 100644 index 0000000000..049acdf1e3 --- /dev/null +++ b/samples/model-builder/experiment_tracking/assign_artifact_as_execution_output_sample_test.py @@ -0,0 +1,29 @@ +# Copyright 2022 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 assign_artifact_as_execution_output_sample +from google.cloud import aiplatform + + +def test_assign_artifact_as_execution_output_sample( + mock_get_execution, + mock_get_artifact, +): + exc = aiplatform.Execution() + art = aiplatform.Artifact() + assign_artifact_as_execution_output_sample.assign_artifact_as_execution_output_sample( + execution=exc, artifact=art + ) + + exc.assign_output_artifacts.assert_called_with([art]) diff --git a/samples/model-builder/experiment_tracking/create_artifact_sample.py b/samples/model-builder/experiment_tracking/create_artifact_sample.py new file mode 100644 index 0000000000..90a7432bea --- /dev/null +++ b/samples/model-builder/experiment_tracking/create_artifact_sample.py @@ -0,0 +1,47 @@ +# Copyright 2022 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 typing import Dict, Optional + +from google.cloud import aiplatform + + +# [START aiplatform_sdk_create_artifact_sample] +def create_artifact_sample( + schema_title: str, + project: str, + location: str, + uri: Optional[str] = None, + resource_id: Optional[str] = None, + display_name: Optional[str] = None, + schema_version: Optional[str] = None, + description: Optional[str] = None, + metadata: Optional[Dict] = None, +): + artifact = aiplatform.Artifact.create( + schema_title=schema_title, + uri=uri, + resource_id=resource_id, + display_name=display_name, + schema_version=schema_version, + description=description, + metadata=metadata, + project=project, + location=location, + ) + + return artifact + + +# [END aiplatform_sdk_create_artifact_sample] diff --git a/samples/model-builder/experiment_tracking/create_artifact_sample_test.py b/samples/model-builder/experiment_tracking/create_artifact_sample_test.py new file mode 100644 index 0000000000..dea7747e0e --- /dev/null +++ b/samples/model-builder/experiment_tracking/create_artifact_sample_test.py @@ -0,0 +1,45 @@ +# Copyright 2022 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 create_artifact_sample + +import test_constants as constants + + +def test_create_artifact_sample(mock_artifact, mock_create_artifact): + artifact = create_artifact_sample.create_artifact_sample( + schema_title=constants.SCHEMA_TITLE, + uri=constants.MODEL_ARTIFACT_URI, + resource_id=constants.RESOURCE_ID, + display_name=constants.DISPLAY_NAME, + schema_version=constants.SCHEMA_VERSION, + description=constants.DESCRIPTION, + metadata=constants.METADATA, + project=constants.PROJECT, + location=constants.LOCATION, + ) + + mock_create_artifact.assert_called_with( + schema_title=constants.SCHEMA_TITLE, + uri=constants.MODEL_ARTIFACT_URI, + resource_id=constants.RESOURCE_ID, + display_name=constants.DISPLAY_NAME, + schema_version=constants.SCHEMA_VERSION, + description=constants.DESCRIPTION, + metadata=constants.METADATA, + project=constants.PROJECT, + location=constants.LOCATION, + ) + + assert artifact is mock_artifact diff --git a/samples/model-builder/experiment_tracking/create_experiment_run_sample.py b/samples/model-builder/experiment_tracking/create_experiment_run_sample.py new file mode 100644 index 0000000000..0767139eba --- /dev/null +++ b/samples/model-builder/experiment_tracking/create_experiment_run_sample.py @@ -0,0 +1,33 @@ +# Copyright 2022 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 typing import Optional, Union + +from google.cloud import aiplatform + + +# [START aiplatform_sdk_create_experiment_run_sample] +def create_experiment_run_sample( + experiment_name: str, + run_name: str, + experiment_run_tensorboard: Optional[Union[str, aiplatform.Tensorboard]], + project: str, + location: str, +): + aiplatform.init(experiment_name=experiment_name, project=project, location=location) + + aiplatform.start_run(run=run_name, tensorboard=experiment_run_tensorboard) + + +# [END aiplatform_sdk_create_experiment_run_sample] diff --git a/samples/model-builder/experiment_tracking/create_experiment_run_sample_test.py b/samples/model-builder/experiment_tracking/create_experiment_run_sample_test.py new file mode 100644 index 0000000000..c0affc0da1 --- /dev/null +++ b/samples/model-builder/experiment_tracking/create_experiment_run_sample_test.py @@ -0,0 +1,39 @@ +# Copyright 2022 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 create_experiment_run_sample + +import test_constants as constants + + +def test_create_experiment_run_sample(mock_sdk_init, mock_start_run): + + create_experiment_run_sample.create_experiment_run_sample( + experiment_name=constants.EXPERIMENT_NAME, + run_name=constants.EXPERIMENT_RUN_NAME, + experiment_run_tensorboard=constants.TENSORBOARD_NAME, + project=constants.PROJECT, + location=constants.LOCATION, + ) + + mock_sdk_init.assert_called_with( + experiment_name=constants.EXPERIMENT_NAME, + project=constants.PROJECT, + location=constants.LOCATION, + ) + + mock_start_run.assert_called_with( + run=constants.EXPERIMENT_RUN_NAME, + tensorboard=constants.TENSORBOARD_NAME, + ) diff --git a/samples/model-builder/experiment_tracking/create_experiment_sample.py b/samples/model-builder/experiment_tracking/create_experiment_sample.py new file mode 100644 index 0000000000..f73954cc95 --- /dev/null +++ b/samples/model-builder/experiment_tracking/create_experiment_sample.py @@ -0,0 +1,37 @@ +# Copyright 2022 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 typing import Optional, Union + +from google.cloud import aiplatform + + +# [START aiplatform_sdk_create_experiment_sample] +def create_experiment_sample( + experiment_name: str, + experiment_description: str, + experiment_tensorboard: Optional[Union[str, aiplatform.Tensorboard]], + project: str, + location: str, +): + aiplatform.init( + experiment_name=experiment_name, + experiment_description=experiment_description, + experiment_tensorboard=experiment_tensorboard, + project=project, + location=location, + ) + + +# [END aiplatform_sdk_create_experiment_sample] diff --git a/samples/model-builder/experiment_tracking/create_experiment_sample_test.py b/samples/model-builder/experiment_tracking/create_experiment_sample_test.py new file mode 100644 index 0000000000..c4c3ae3843 --- /dev/null +++ b/samples/model-builder/experiment_tracking/create_experiment_sample_test.py @@ -0,0 +1,37 @@ +# Copyright 2022 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 create_experiment_sample + +import test_constants as constants + + +def test_create_experiment_sample(mock_sdk_init): + + create_experiment_sample.create_experiment_sample( + experiment_name=constants.EXPERIMENT_NAME, + experiment_description=constants.DESCRIPTION, + experiment_tensorboard=constants.TENSORBOARD_NAME, + project=constants.PROJECT, + location=constants.LOCATION, + ) + + mock_sdk_init.assert_called_with( + experiment_name=constants.EXPERIMENT_NAME, + experiment_description=constants.DESCRIPTION, + experiment_tensorboard=constants.TENSORBOARD_NAME, + project=constants.PROJECT, + location=constants.LOCATION, + ) diff --git a/samples/model-builder/experiment_tracking/delete_experiment_run_sample.py b/samples/model-builder/experiment_tracking/delete_experiment_run_sample.py new file mode 100644 index 0000000000..7f8704bb00 --- /dev/null +++ b/samples/model-builder/experiment_tracking/delete_experiment_run_sample.py @@ -0,0 +1,35 @@ +# Copyright 2022 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 typing import Union + +from google.cloud import aiplatform + + +# [START aiplatform_sdk_delete_experiment_run_sample] +def delete_experiment_run_sample( + run_name: str, + experiment: Union[str, aiplatform.Experiment], + project: str, + location: str, + delete_backing_tensorboard_run: bool = False, +): + experiment_run = aiplatform.ExperimentRun( + run_name=run_name, experiment=experiment, project=project, location=location + ) + + experiment_run.delete(delete_backing_tensorboard_run=delete_backing_tensorboard_run) + + +# [END aiplatform_sdk_delete_experiment_run_sample] diff --git a/samples/model-builder/experiment_tracking/delete_experiment_run_sample_test.py b/samples/model-builder/experiment_tracking/delete_experiment_run_sample_test.py new file mode 100644 index 0000000000..2da57e3f47 --- /dev/null +++ b/samples/model-builder/experiment_tracking/delete_experiment_run_sample_test.py @@ -0,0 +1,39 @@ +# Copyright 2022 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 delete_experiment_run_sample + +import test_constants + + +def test_delete_experiment_run_sample( + mock_experiment_run, + mock_get_run, +): + delete_experiment_run_sample.delete_experiment_run_sample( + run_name=test_constants.EXPERIMENT_RUN_NAME, + experiment=test_constants.EXPERIMENT_NAME, + project=test_constants.PROJECT, + location=test_constants.LOCATION, + delete_backing_tensorboard_run=True, + ) + + mock_get_run.assert_called_with( + run_name=test_constants.EXPERIMENT_RUN_NAME, + experiment=test_constants.EXPERIMENT_NAME, + project=test_constants.PROJECT, + location=test_constants.LOCATION, + ) + + mock_experiment_run.delete.assert_called_with(delete_backing_tensorboard_run=True) diff --git a/samples/model-builder/experiment_tracking/delete_experiment_sample.py b/samples/model-builder/experiment_tracking/delete_experiment_sample.py new file mode 100644 index 0000000000..0b95e438b9 --- /dev/null +++ b/samples/model-builder/experiment_tracking/delete_experiment_sample.py @@ -0,0 +1,33 @@ +# Copyright 2022 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 import aiplatform + + +# [START aiplatform_sdk_delete_experiment_sample] +def delete_experiment_sample( + experiment_name: str, + project: str, + location: str, + delete_backing_tensorboard_runs: bool = False, +): + experiment = aiplatform.Experiment( + experiment_name=experiment_name, project=project, location=location + ) + + experiment.delete(delete_backing_tensorboard_runs=delete_backing_tensorboard_runs) + + +# [END aiplatform_sdk_delete_experiment_sample] diff --git a/samples/model-builder/experiment_tracking/delete_experiment_sample_test.py b/samples/model-builder/experiment_tracking/delete_experiment_sample_test.py new file mode 100644 index 0000000000..a397b185aa --- /dev/null +++ b/samples/model-builder/experiment_tracking/delete_experiment_sample_test.py @@ -0,0 +1,35 @@ +# Copyright 2022 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 delete_experiment_sample + +import test_constants + + +def test_delete_experiment_sample(mock_experiment, mock_get_experiment): + delete_experiment_sample.delete_experiment_sample( + experiment_name=test_constants.EXPERIMENT_NAME, + project=test_constants.PROJECT, + location=test_constants.LOCATION, + delete_backing_tensorboard_runs=True, + ) + + mock_get_experiment.assert_called_with( + experiment_name=test_constants.EXPERIMENT_NAME, + project=test_constants.PROJECT, + location=test_constants.LOCATION, + ) + + mock_experiment.delete.assert_called_with(delete_backing_tensorboard_runs=True) diff --git a/samples/model-builder/experiment_tracking/end_experiment_run_sample.py b/samples/model-builder/experiment_tracking/end_experiment_run_sample.py new file mode 100644 index 0000000000..5161c15937 --- /dev/null +++ b/samples/model-builder/experiment_tracking/end_experiment_run_sample.py @@ -0,0 +1,33 @@ +# Copyright 2022 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 import aiplatform + + +# [START aiplatform_sdk_end_experiment_run_sample] +def end_experiment_run_sample( + experiment_name: str, + run_name: str, + project: str, + location: str, +): + aiplatform.init(experiment_name=experiment_name, project=project, location=location) + + aiplatform.start_run(run=run_name, resume=True) + + aiplatform.end_run() + + +# [END aiplatform_sdk_end_experiment_run_sample] diff --git a/samples/model-builder/experiment_tracking/end_experiment_run_sample_test.py b/samples/model-builder/experiment_tracking/end_experiment_run_sample_test.py new file mode 100644 index 0000000000..551f57d3cd --- /dev/null +++ b/samples/model-builder/experiment_tracking/end_experiment_run_sample_test.py @@ -0,0 +1,37 @@ +# Copyright 2022 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 end_experiment_run_sample + +import test_constants as constants + + +def test_end_experiment_run_sample(mock_sdk_init, mock_start_run, mock_end_run): + + end_experiment_run_sample.end_experiment_run_sample( + experiment_name=constants.EXPERIMENT_NAME, + run_name=constants.EXPERIMENT_RUN_NAME, + project=constants.PROJECT, + location=constants.LOCATION, + ) + + mock_sdk_init.assert_called_with( + experiment_name=constants.EXPERIMENT_NAME, + project=constants.PROJECT, + location=constants.LOCATION, + ) + + mock_start_run.assert_called_with(run=constants.EXPERIMENT_RUN_NAME, resume=True) + + mock_end_run.assert_called_with() diff --git a/samples/model-builder/experiment_tracking/get_artifact_sample.py b/samples/model-builder/experiment_tracking/get_artifact_sample.py new file mode 100644 index 0000000000..e0b9fc5500 --- /dev/null +++ b/samples/model-builder/experiment_tracking/get_artifact_sample.py @@ -0,0 +1,31 @@ +# Copyright 2022 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 import aiplatform + + +# [START aiplatform_sdk_get_artifact_sample] +def get_artifact_sample( + uri: str, + project: str, + location: str, +): + artifact = aiplatform.Artifact.get_with_uri( + uri=uri, project=project, location=location + ) + + return artifact + + +# [END aiplatform_sdk_get_artifact_sample] diff --git a/samples/model-builder/experiment_tracking/get_artifact_sample_test.py b/samples/model-builder/experiment_tracking/get_artifact_sample_test.py new file mode 100644 index 0000000000..7387927ef3 --- /dev/null +++ b/samples/model-builder/experiment_tracking/get_artifact_sample_test.py @@ -0,0 +1,33 @@ +# Copyright 2022 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 get_artifact_sample + +import test_constants + + +def test_get_artifact_sample(mock_artifact, mock_get_with_uri): + artifact = get_artifact_sample.get_artifact_sample( + uri=test_constants.MODEL_ARTIFACT_URI, + project=test_constants.PROJECT, + location=test_constants.LOCATION, + ) + + mock_get_with_uri.assert_called_with( + uri=test_constants.MODEL_ARTIFACT_URI, + project=test_constants.PROJECT, + location=test_constants.LOCATION, + ) + + assert artifact is mock_artifact diff --git a/samples/model-builder/experiment_tracking/get_experiment_data_frame_sample.py b/samples/model-builder/experiment_tracking/get_experiment_data_frame_sample.py new file mode 100644 index 0000000000..0a65a82f7b --- /dev/null +++ b/samples/model-builder/experiment_tracking/get_experiment_data_frame_sample.py @@ -0,0 +1,32 @@ +# Copyright 2022 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 import aiplatform + + +# [START aiplatform_sdk_get_experiments_data_frame_sample] +def get_experiments_data_frame_sample( + experiment_name: str, + project: str, + location: str, +): + aiplatform.init(experiment_name=experiment_name, project=project, location=location) + + experiments_df = aiplatform.get_experiment_df() + + return experiments_df + + +# [END aiplatform_sdk_get_experiments_data_frame_sample] diff --git a/samples/model-builder/experiment_tracking/get_experiment_data_frame_sample_test.py b/samples/model-builder/experiment_tracking/get_experiment_data_frame_sample_test.py new file mode 100644 index 0000000000..8740f5c2c7 --- /dev/null +++ b/samples/model-builder/experiment_tracking/get_experiment_data_frame_sample_test.py @@ -0,0 +1,32 @@ +# Copyright 2022 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 get_experiment_data_frame_sample + +import pytest + +import test_constants as constants + + +@pytest.mark.usefixtures("mock_sdk_init") +def test_get_experiments_data_frame_sample(mock_get_experiment_df, mock_df): + df = get_experiment_data_frame_sample.get_experiments_data_frame_sample( + experiment_name=constants.EXPERIMENT_NAME, + project=constants.PROJECT, + location=constants.LOCATION, + ) + + mock_get_experiment_df.assert_called_with() + + assert df is mock_df diff --git a/samples/model-builder/experiment_tracking/get_experiment_run_metrics_sample.py b/samples/model-builder/experiment_tracking/get_experiment_run_metrics_sample.py new file mode 100644 index 0000000000..ce4b36b60d --- /dev/null +++ b/samples/model-builder/experiment_tracking/get_experiment_run_metrics_sample.py @@ -0,0 +1,34 @@ +# Copyright 2022 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 typing import Dict, Union + +from google.cloud import aiplatform + + +# [START aiplatform_sdk_get_experiment_run_metrics_sample] +def get_experiment_run_metrics_sample( + run_name: str, + experiment: Union[str, aiplatform.Experiment], + project: str, + location: str, +) -> Dict[str, Union[float, int]]: + experiment_run = aiplatform.ExperimentRun( + run_name=run_name, experiment=experiment, project=project, location=location + ) + + return experiment_run.get_metrics() + + +# [END aiplatform_sdk_get_experiment_run_metrics_sample] diff --git a/samples/model-builder/experiment_tracking/get_experiment_run_metrics_sample_test.py b/samples/model-builder/experiment_tracking/get_experiment_run_metrics_sample_test.py new file mode 100644 index 0000000000..4ff9502392 --- /dev/null +++ b/samples/model-builder/experiment_tracking/get_experiment_run_metrics_sample_test.py @@ -0,0 +1,34 @@ +# Copyright 2022 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 get_experiment_run_metrics_sample + +import pytest + +import test_constants as constants + + +@pytest.mark.usefixtures("mock_get_run") +def test_get_experiment_run_metrics_sample(mock_get_metrics, mock_metrics): + + metrics = get_experiment_run_metrics_sample.get_experiment_run_metrics_sample( + run_name=constants.EXPERIMENT_RUN_NAME, + experiment=constants.EXPERIMENT_NAME, + project=constants.PROJECT, + location=constants.LOCATION, + ) + + mock_get_metrics.assert_called_with() + + assert metrics is mock_metrics diff --git a/samples/model-builder/experiment_tracking/get_experiment_run_params_sample.py b/samples/model-builder/experiment_tracking/get_experiment_run_params_sample.py new file mode 100644 index 0000000000..1bad58ebad --- /dev/null +++ b/samples/model-builder/experiment_tracking/get_experiment_run_params_sample.py @@ -0,0 +1,34 @@ +# Copyright 2022 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 typing import Dict, Union + +from google.cloud import aiplatform + + +# [START aiplatform_sdk_get_experiment_run_params_sample] +def get_experiment_run_params_sample( + run_name: str, + experiment: Union[str, aiplatform.Experiment], + project: str, + location: str, +) -> Dict[str, Union[float, int, str]]: + experiment_run = aiplatform.ExperimentRun( + run_name=run_name, experiment=experiment, project=project, location=location + ) + + return experiment_run.get_params() + + +# [END aiplatform_sdk_get_experiment_run_params_sample] diff --git a/samples/model-builder/experiment_tracking/get_experiment_run_params_sample_test.py b/samples/model-builder/experiment_tracking/get_experiment_run_params_sample_test.py new file mode 100644 index 0000000000..96610526a9 --- /dev/null +++ b/samples/model-builder/experiment_tracking/get_experiment_run_params_sample_test.py @@ -0,0 +1,34 @@ +# Copyright 2022 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 get_experiment_run_params_sample + +import pytest + +import test_constants as constants + + +@pytest.mark.usefixtures("mock_get_run") +def test_get_experiment_run_params_sample(mock_get_params, mock_params): + + params = get_experiment_run_params_sample.get_experiment_run_params_sample( + run_name=constants.EXPERIMENT_RUN_NAME, + experiment=constants.EXPERIMENT_NAME, + project=constants.PROJECT, + location=constants.LOCATION, + ) + + mock_get_params.assert_called_with() + + assert params is mock_params diff --git a/samples/model-builder/experiment_tracking/get_experiment_run_time_series_metric_data_frame_sample.py b/samples/model-builder/experiment_tracking/get_experiment_run_time_series_metric_data_frame_sample.py new file mode 100644 index 0000000000..febb92fcb6 --- /dev/null +++ b/samples/model-builder/experiment_tracking/get_experiment_run_time_series_metric_data_frame_sample.py @@ -0,0 +1,34 @@ +# Copyright 2022 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 typing import Union + +from google.cloud import aiplatform + + +# [START aiplatform_sdk_get_experiment_run_time_series_metric_data_frame_sample] +def get_experiment_run_time_series_metric_data_frame_sample( + run_name: str, + experiment: Union[str, aiplatform.Experiment], + project: str, + location: str, +) -> "pd.DataFrame": # noqa: F821 + experiment_run = aiplatform.ExperimentRun( + run_name=run_name, experiment=experiment, project=project, location=location + ) + + return experiment_run.get_time_series_data_frame() + + +# [END aiplatform_sdk_get_experiment_run_time_series_metric_data_frame_sample] diff --git a/samples/model-builder/experiment_tracking/get_experiment_run_time_series_metric_data_frame_sample_test.py b/samples/model-builder/experiment_tracking/get_experiment_run_time_series_metric_data_frame_sample_test.py new file mode 100644 index 0000000000..2bd40cd814 --- /dev/null +++ b/samples/model-builder/experiment_tracking/get_experiment_run_time_series_metric_data_frame_sample_test.py @@ -0,0 +1,36 @@ +# Copyright 2022 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 get_experiment_run_time_series_metric_data_frame_sample + +import pytest + +import test_constants as constants + + +@pytest.mark.usefixtures("mock_get_run") +def test_get_experiment_run_time_series_metric_data_frame_sample( + mock_get_time_series_metrics, mock_time_series_metrics +): + + metrics = get_experiment_run_time_series_metric_data_frame_sample.get_experiment_run_time_series_metric_data_frame_sample( + run_name=constants.EXPERIMENT_RUN_NAME, + experiment=constants.EXPERIMENT_NAME, + project=constants.PROJECT, + location=constants.LOCATION, + ) + + mock_get_time_series_metrics.assert_called_with() + + assert metrics is mock_time_series_metrics diff --git a/samples/model-builder/experiment_tracking/log_metrics_sample.py b/samples/model-builder/experiment_tracking/log_metrics_sample.py new file mode 100644 index 0000000000..be139dbae1 --- /dev/null +++ b/samples/model-builder/experiment_tracking/log_metrics_sample.py @@ -0,0 +1,35 @@ +# Copyright 2022 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 typing import Dict + +from google.cloud import aiplatform + + +# [START aiplatform_sdk_log_metrics_sample] +def log_metrics_sample( + experiment_name: str, + run_name: str, + metrics: Dict[str, float], + project: str, + location: str, +): + aiplatform.init(experiment_name=experiment_name, project=project, location=location) + + aiplatform.start_run(run_name=run_name, resume=True) + + aiplatform.log_metrics(metrics) + + +# [END aiplatform_sdk_log_metrics_sample] diff --git a/samples/model-builder/experiment_tracking/log_metrics_sample_test.py b/samples/model-builder/experiment_tracking/log_metrics_sample_test.py new file mode 100644 index 0000000000..8cc003fa3f --- /dev/null +++ b/samples/model-builder/experiment_tracking/log_metrics_sample_test.py @@ -0,0 +1,33 @@ +# Copyright 2022 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 log_metrics_sample + +import pytest + +import test_constants as constants + + +@pytest.mark.usefixtures("mock_sdk_init", "mock_start_run") +def test_log_metrics_sample(mock_log_metrics): + + log_metrics_sample.log_metrics_sample( + experiment_name=constants.EXPERIMENT_NAME, + run_name=constants.EXPERIMENT_RUN_NAME, + metrics=constants.METRICS, + project=constants.PROJECT, + location=constants.LOCATION, + ) + + mock_log_metrics.assert_called_with(constants.METRICS) diff --git a/samples/model-builder/experiment_tracking/log_params_sample.py b/samples/model-builder/experiment_tracking/log_params_sample.py new file mode 100644 index 0000000000..9f07b3bdf3 --- /dev/null +++ b/samples/model-builder/experiment_tracking/log_params_sample.py @@ -0,0 +1,35 @@ +# Copyright 2022 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 typing import Dict, Union + +from google.cloud import aiplatform + + +# [START aiplatform_sdk_log_params_sample] +def log_params_sample( + experiment_name: str, + run_name: str, + params: Dict[str, Union[float, int, str]], + project: str, + location: str, +): + aiplatform.init(experiment_name=experiment_name, project=project, location=location) + + aiplatform.start_run(run_name=run_name, resume=True) + + aiplatform.log_params(params) + + +# [END aiplatform_sdk_log_params_sample] diff --git a/samples/model-builder/experiment_tracking/log_params_sample_test.py b/samples/model-builder/experiment_tracking/log_params_sample_test.py new file mode 100644 index 0000000000..f09673eda1 --- /dev/null +++ b/samples/model-builder/experiment_tracking/log_params_sample_test.py @@ -0,0 +1,33 @@ +# Copyright 2022 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 log_params_sample + +import pytest + +import test_constants as constants + + +@pytest.mark.usefixtures("mock_sdk_init", "mock_start_run") +def test_log_params_sample(mock_log_params): + + log_params_sample.log_params_sample( + experiment_name=constants.EXPERIMENT_NAME, + run_name=constants.EXPERIMENT_RUN_NAME, + params=constants.PARAMS, + project=constants.PROJECT, + location=constants.LOCATION, + ) + + mock_log_params.assert_called_with(constants.PARAMS) diff --git a/samples/model-builder/experiment_tracking/log_pipeline_job_sample.py b/samples/model-builder/experiment_tracking/log_pipeline_job_sample.py new file mode 100644 index 0000000000..467e969edd --- /dev/null +++ b/samples/model-builder/experiment_tracking/log_pipeline_job_sample.py @@ -0,0 +1,34 @@ +# Copyright 2022 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 import aiplatform + + +# [START aiplatform_sdk_log_pipeline_job_sample] +def log_pipeline_job_sample( + experiment_name: str, + run_name: str, + pipeline_job: aiplatform.PipelineJob, + project: str, + location: str, +): + aiplatform.init(experiment_name=experiment_name, project=project, location=location) + + aiplatform.start_run(run_name=run_name, resume=True) + + aiplatform.log(pipeline_job=pipeline_job) + + +# [END aiplatform_sdk_log_pipeline_job_sample] diff --git a/samples/model-builder/experiment_tracking/log_pipeline_job_sample_test.py b/samples/model-builder/experiment_tracking/log_pipeline_job_sample_test.py new file mode 100644 index 0000000000..68f3293f1c --- /dev/null +++ b/samples/model-builder/experiment_tracking/log_pipeline_job_sample_test.py @@ -0,0 +1,33 @@ +# Copyright 2022 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 log_pipeline_job_sample + +import pytest + +import test_constants as constants + + +@pytest.mark.usefixtures("mock_sdk_init", "mock_start_run") +def test_log_pipeline_job_sample(mock_log_pipeline_job, mock_pipeline_job): + + log_pipeline_job_sample.log_pipeline_job_sample( + experiment_name=constants.EXPERIMENT_NAME, + run_name=constants.EXPERIMENT_RUN_NAME, + pipeline_job=mock_pipeline_job, + project=constants.PROJECT, + location=constants.LOCATION, + ) + + mock_log_pipeline_job.assert_called_with(pipeline_job=mock_pipeline_job) diff --git a/samples/model-builder/experiment_tracking/log_pipeline_job_to_experiment_sample.py b/samples/model-builder/experiment_tracking/log_pipeline_job_to_experiment_sample.py new file mode 100644 index 0000000000..495f9c2581 --- /dev/null +++ b/samples/model-builder/experiment_tracking/log_pipeline_job_to_experiment_sample.py @@ -0,0 +1,42 @@ +# Copyright 2022 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 typing import Any, Dict, Optional + +from google.cloud import aiplatform + + +# [START aiplatform_sdk_log_pipeline_job_to_experiment_sample] +def log_pipeline_job_to_experiment_sample( + experiment_name: str, + pipeline_job_display_name: str, + template_path: str, + pipeline_root: str, + parameter_values: Optional[Dict[str, Any]], + project: str, + location: str, +): + aiplatform.init(project=project, location=location) + + pipeline_job = aiplatform.PipelineJob( + display_name=pipeline_job_display_name, + template_path=template_path, + pipeline_root=pipeline_root, + parameter_values=parameter_values, + ) + + pipeline_job.submit(experiment=experiment_name) + + +# [END aiplatform_sdk_log_pipeline_job_to_experiment_sample] diff --git a/samples/model-builder/experiment_tracking/log_pipeline_job_to_experiment_sample_test.py b/samples/model-builder/experiment_tracking/log_pipeline_job_to_experiment_sample_test.py new file mode 100644 index 0000000000..3cb5e8cfff --- /dev/null +++ b/samples/model-builder/experiment_tracking/log_pipeline_job_to_experiment_sample_test.py @@ -0,0 +1,45 @@ +# Copyright 2022 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 log_pipeline_job_to_experiment_sample + +import test_constants as constants + + +def test_log_pipeline_job_sample( + mock_sdk_init, mock_pipeline_job_create, mock_pipeline_job_submit +): + + log_pipeline_job_to_experiment_sample.log_pipeline_job_to_experiment_sample( + experiment_name=constants.EXPERIMENT_NAME, + pipeline_job_display_name=constants.DISPLAY_NAME, + template_path=constants.TEMPLATE_PATH, + pipeline_root=constants.STAGING_BUCKET, + parameter_values=constants.PARAMS, + project=constants.PROJECT, + location=constants.LOCATION, + ) + + mock_sdk_init.assert_called_with( + project=constants.PROJECT, location=constants.LOCATION + ) + + mock_pipeline_job_create.assert_called_with( + display_name=constants.DISPLAY_NAME, + template_path=constants.TEMPLATE_PATH, + pipeline_root=constants.STAGING_BUCKET, + parameter_values=constants.PARAMS, + ) + + mock_pipeline_job_submit.assert_called_with(experiment=constants.EXPERIMENT_NAME) diff --git a/samples/model-builder/experiment_tracking/log_time_series_metrics_sample.py b/samples/model-builder/experiment_tracking/log_time_series_metrics_sample.py new file mode 100644 index 0000000000..2ab8d46d2f --- /dev/null +++ b/samples/model-builder/experiment_tracking/log_time_series_metrics_sample.py @@ -0,0 +1,38 @@ +# Copyright 2022 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 typing import Dict, Optional + +from google.cloud import aiplatform +from google.protobuf import timestamp_pb2 + + +# [START aiplatform_sdk_log_time_series_metrics_sample] +def log_time_series_metrics_sample( + experiment_name: str, + run_name: str, + metrics: Dict[str, float], + step: Optional[int], + wall_time: Optional[timestamp_pb2.Timestamp], + project: str, + location: str, +): + aiplatform.init(experiment_name=experiment_name, project=project, location=location) + + aiplatform.start_run(run_name=run_name, resume=True) + + aiplatform.log_time_series_metrics(metrics=metrics, step=step, wall_time=wall_time) + + +# [END aiplatform_sdk_log_time_series_metrics_sample] diff --git a/samples/model-builder/experiment_tracking/log_time_series_metrics_sample_test.py b/samples/model-builder/experiment_tracking/log_time_series_metrics_sample_test.py new file mode 100644 index 0000000000..e85c204fb1 --- /dev/null +++ b/samples/model-builder/experiment_tracking/log_time_series_metrics_sample_test.py @@ -0,0 +1,39 @@ +# Copyright 2022 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 log_time_series_metrics_sample + +import pytest + +import test_constants as constants + + +@pytest.mark.usefixtures("mock_sdk_init", "mock_start_run") +def test_log_time_series_metrics_sample(mock_log_time_series_metrics): + + log_time_series_metrics_sample.log_time_series_metrics_sample( + experiment_name=constants.EXPERIMENT_NAME, + run_name=constants.EXPERIMENT_RUN_NAME, + metrics=constants.METRICS, + step=constants.STEP, + wall_time=constants.TIMESTAMP, + project=constants.PROJECT, + location=constants.LOCATION, + ) + + mock_log_time_series_metrics.assert_called_with( + metrics=constants.METRICS, + step=constants.STEP, + wall_time=constants.TIMESTAMP, + ) diff --git a/samples/model-builder/experiment_tracking/resume_experiment_run_sample.py b/samples/model-builder/experiment_tracking/resume_experiment_run_sample.py new file mode 100644 index 0000000000..6ba254f07f --- /dev/null +++ b/samples/model-builder/experiment_tracking/resume_experiment_run_sample.py @@ -0,0 +1,31 @@ +# Copyright 2022 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 import aiplatform + + +# [START aiplatform_sdk_resume_experiment_run_sample] +def resume_experiment_run_sample( + experiment_name: str, + run_name: str, + project: str, + location: str, +): + aiplatform.init(experiment_name=experiment_name, project=project, location=location) + + aiplatform.start_run(run=run_name, resume=True) + + +# [END aiplatform_sdk_resume_experiment_run_sample] diff --git a/samples/model-builder/experiment_tracking/resume_experiment_run_sample_test.py b/samples/model-builder/experiment_tracking/resume_experiment_run_sample_test.py new file mode 100644 index 0000000000..964178f857 --- /dev/null +++ b/samples/model-builder/experiment_tracking/resume_experiment_run_sample_test.py @@ -0,0 +1,35 @@ +# Copyright 2022 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 resume_experiment_run_sample + +import test_constants as constants + + +def test_resume_experiment_run_sample(mock_sdk_init, mock_start_run): + + resume_experiment_run_sample.resume_experiment_run_sample( + experiment_name=constants.EXPERIMENT_NAME, + run_name=constants.EXPERIMENT_RUN_NAME, + project=constants.PROJECT, + location=constants.LOCATION, + ) + + mock_sdk_init.assert_called_with( + experiment_name=constants.EXPERIMENT_NAME, + project=constants.PROJECT, + location=constants.LOCATION, + ) + + mock_start_run.assert_called_with(run=constants.EXPERIMENT_RUN_NAME, resume=True) diff --git a/samples/model-builder/experiment_tracking/start_execution_sample.py b/samples/model-builder/experiment_tracking/start_execution_sample.py new file mode 100644 index 0000000000..8d8632bfce --- /dev/null +++ b/samples/model-builder/experiment_tracking/start_execution_sample.py @@ -0,0 +1,48 @@ +# Copyright 2022 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 typing import Any, Dict, List, Optional + +from google.cloud import aiplatform + + +# [START aiplatform_sdk_start_execution_sample] +def start_execution_sample( + schema_title: str, + display_name: str, + input_artifacts: List[aiplatform.Artifact], + output_artifacts: List[aiplatform.Artifact], + project: str, + location: str, + resource_id: Optional[str] = None, + metadata: Optional[Dict[str, Any]] = None, + schema_version: Optional[str] = None, + resume: bool = False, +): + aiplatform.init(project=project, location=location) + + with aiplatform.start_execution( + schema_title=schema_title, + display_name=display_name, + resource_id=resource_id, + metadata=metadata, + schema_version=schema_version, + resume=resume, + ) as execution: + execution.assign_input_artifacts(input_artifacts) + execution.assign_output_artifacts(output_artifacts) + return execution + + +# [END aiplatform_sdk_start_execution_sample] diff --git a/samples/model-builder/experiment_tracking/start_execution_sample_test.py b/samples/model-builder/experiment_tracking/start_execution_sample_test.py new file mode 100644 index 0000000000..c1be84fe0f --- /dev/null +++ b/samples/model-builder/experiment_tracking/start_execution_sample_test.py @@ -0,0 +1,63 @@ +# Copyright 2022 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 import aiplatform + +import start_execution_sample + +import test_constants as constants + + +def test_start_execution_sample( + mock_sdk_init, + mock_get_execution, + mock_get_artifact, + mock_start_execution, + mock_execution, +): + + input_art = aiplatform.Artifact() + output_art = aiplatform.Artifact() + + exc = start_execution_sample.start_execution_sample( + schema_title=constants.SCHEMA_TITLE, + display_name=constants.DISPLAY_NAME, + input_artifacts=[input_art], + output_artifacts=[output_art], + project=constants.PROJECT, + location=constants.LOCATION, + resource_id=constants.RESOURCE_ID, + metadata=constants.METADATA, + schema_version=constants.SCHEMA_VERSION, + resume=True, + ) + + mock_sdk_init.assert_called_with( + project=constants.PROJECT, + location=constants.LOCATION, + ) + + mock_start_execution.assert_called_with( + schema_title=constants.SCHEMA_TITLE, + display_name=constants.DISPLAY_NAME, + resource_id=constants.RESOURCE_ID, + metadata=constants.METADATA, + schema_version=constants.SCHEMA_VERSION, + resume=True, + ) + + mock_execution.assign_input_artifacts.assert_called_with([input_art]) + mock_execution.assign_output_artifacts.assert_called_with([output_art]) + + assert exc is mock_execution diff --git a/samples/model-builder/explain_sample.py b/samples/model-builder/explain_sample.py new file mode 100644 index 0000000000..2f61e0cd9c --- /dev/null +++ b/samples/model-builder/explain_sample.py @@ -0,0 +1,48 @@ +# Copyright 2022 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 typing import Dict + +from google.cloud import aiplatform + + +# [START aiplatform_sdk_explain_sample] +def explain_sample(project: str, location: str, endpoint_id: str, instance_dict: Dict): + + aiplatform.init(project=project, location=location) + + endpoint = aiplatform.Endpoint(endpoint_id) + + response = endpoint.explain(instances=[instance_dict], parameters={}) + + for explanation in response.explanations: + print(" explanation") + # Feature attributions. + attributions = explanation.attributions + for attribution in attributions: + print(" attribution") + print(" baseline_output_value:", attribution.baseline_output_value) + print(" instance_output_value:", attribution.instance_output_value) + print(" output_display_name:", attribution.output_display_name) + print(" approximation_error:", attribution.approximation_error) + print(" output_name:", attribution.output_name) + output_index = attribution.output_index + for output_index in output_index: + print(" output_index:", output_index) + + for prediction in response.predictions: + print(prediction) + + +# [END aiplatform_sdk_explain_sample] diff --git a/samples/model-builder/explain_sample_test.py b/samples/model-builder/explain_sample_test.py new file mode 100644 index 0000000000..83434edae8 --- /dev/null +++ b/samples/model-builder/explain_sample_test.py @@ -0,0 +1,41 @@ +# Copyright 2022 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 explain_sample +import test_constants as constants + + +def test_explain_sample( + mock_sdk_init, mock_endpoint, mock_get_endpoint, mock_endpoint_explain +): + + explain_sample.explain_sample( + project=constants.PROJECT, + location=constants.LOCATION, + endpoint_id=constants.ENDPOINT_NAME, + instance_dict=constants.PREDICTION_TABULAR_INSTANCE, + ) + + mock_sdk_init.assert_called_once_with( + project=constants.PROJECT, location=constants.LOCATION + ) + + mock_get_endpoint.assert_called_once_with( + constants.ENDPOINT_NAME, + ) + + mock_endpoint_explain.assert_called_once_with( + instances=[constants.PREDICTION_TABULAR_INSTANCE], parameters={} + ) diff --git a/samples/model-builder/explain_tabular_sample_test.py b/samples/model-builder/explain_tabular_sample_test.py index d088da9658..11af809632 100644 --- a/samples/model-builder/explain_tabular_sample_test.py +++ b/samples/model-builder/explain_tabular_sample_test.py @@ -32,7 +32,9 @@ def test_explain_tabular_sample( project=constants.PROJECT, location=constants.LOCATION ) - mock_get_endpoint.assert_called_once_with(constants.ENDPOINT_NAME,) + mock_get_endpoint.assert_called_once_with( + constants.ENDPOINT_NAME, + ) mock_endpoint_explain.assert_called_once_with( instances=[constants.PREDICTION_TABULAR_INSTANCE], parameters={} diff --git a/samples/model-builder/import_data_text_entity_extraction_sample_test.py b/samples/model-builder/import_data_text_entity_extraction_sample_test.py index 44ce9cc328..a3b93e9200 100644 --- a/samples/model-builder/import_data_text_entity_extraction_sample_test.py +++ b/samples/model-builder/import_data_text_entity_extraction_sample_test.py @@ -34,7 +34,9 @@ def test_import_data_text_entity_extraction_sample( project=constants.PROJECT, location=constants.LOCATION ) - mock_get_text_dataset.assert_called_once_with(constants.DATASET_NAME,) + mock_get_text_dataset.assert_called_once_with( + constants.DATASET_NAME, + ) mock_import_text_dataset.assert_called_once_with( gcs_source=constants.GCS_SOURCES, diff --git a/samples/model-builder/import_data_text_sentiment_analysis_sample_test.py b/samples/model-builder/import_data_text_sentiment_analysis_sample_test.py index 8bfd6ac0c3..2134d66b35 100644 --- a/samples/model-builder/import_data_text_sentiment_analysis_sample_test.py +++ b/samples/model-builder/import_data_text_sentiment_analysis_sample_test.py @@ -34,7 +34,9 @@ def test_import_data_text_sentiment_analysis_sample( project=constants.PROJECT, location=constants.LOCATION ) - mock_get_text_dataset.assert_called_once_with(constants.DATASET_NAME,) + mock_get_text_dataset.assert_called_once_with( + constants.DATASET_NAME, + ) mock_import_text_dataset.assert_called_once_with( gcs_source=constants.GCS_SOURCES, diff --git a/samples/model-builder/import_feature_values_sample.py b/samples/model-builder/import_feature_values_sample.py new file mode 100644 index 0000000000..cdb300f7c8 --- /dev/null +++ b/samples/model-builder/import_feature_values_sample.py @@ -0,0 +1,48 @@ +# Copyright 2022 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 aiplatform_sdk_import_feature_values_sample] +import datetime +from typing import List, Union + +from google.cloud import aiplatform + + +def import_feature_values_sample( + project: str, + location: str, + entity_type_id: str, + featurestore_id: str, + feature_ids: List[str], + feature_time: Union[str, datetime.datetime], + gcs_source_uris: Union[str, List[str]], + gcs_source_type: str, +): + + aiplatform.init(project=project, location=location) + + my_entity_type = aiplatform.featurestore.EntityType( + entity_type_name=entity_type_id, featurestore_id=featurestore_id + ) + + my_entity_type.ingest_from_gcs( + feature_ids=feature_ids, + feature_time=feature_time, + gcs_source_uris=gcs_source_uris, + gcs_source_type=gcs_source_type, + ) + + +# [END aiplatform_sdk_import_feature_values_sample] diff --git a/samples/model-builder/import_feature_values_sample_test.py b/samples/model-builder/import_feature_values_sample_test.py new file mode 100644 index 0000000000..a218eceddb --- /dev/null +++ b/samples/model-builder/import_feature_values_sample_test.py @@ -0,0 +1,48 @@ +# Copyright 2022 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 import_feature_values_sample +import test_constants as constants + + +def test_import_feature_values_sample( + mock_sdk_init, mock_get_entity_type, mock_import_feature_values +): + + import_feature_values_sample.import_feature_values_sample( + project=constants.PROJECT, + location=constants.LOCATION, + entity_type_id=constants.ENTITY_TYPE_ID, + featurestore_id=constants.FEATURESTORE_ID, + feature_ids=constants.FEATURE_IDS, + feature_time=constants.USERS_FEATURE_TIME, + gcs_source_uris=constants.USERS_GCS_SOURCE_URI, + gcs_source_type=constants.GCS_SOURCE_TYPE, + ) + + mock_sdk_init.assert_called_once_with( + project=constants.PROJECT, location=constants.LOCATION + ) + + mock_get_entity_type.assert_called_once_with( + entity_type_name=constants.ENTITY_TYPE_ID, + featurestore_id=constants.FEATURESTORE_ID, + ) + + mock_import_feature_values.assert_called_once_with( + feature_ids=constants.FEATURE_IDS, + feature_time=constants.USERS_FEATURE_TIME, + gcs_source_uris=constants.USERS_GCS_SOURCE_URI, + gcs_source_type=constants.GCS_SOURCE_TYPE, + ) diff --git a/samples/model-builder/noxfile.py b/samples/model-builder/noxfile.py index 83bf446de2..38bb0a572b 100644 --- a/samples/model-builder/noxfile.py +++ b/samples/model-builder/noxfile.py @@ -14,20 +14,25 @@ from __future__ import print_function +import glob import os from pathlib import Path import sys +from typing import Callable, Dict, List, Optional import nox + # WARNING - WARNING - WARNING - WARNING - WARNING # WARNING - WARNING - WARNING - WARNING - WARNING # DO NOT EDIT THIS FILE EVER! # WARNING - WARNING - WARNING - WARNING - WARNING # WARNING - WARNING - WARNING - WARNING - WARNING -# Copy `noxfile_config.py` to your directory and modify it instead. +BLACK_VERSION = "black==22.3.0" +ISORT_VERSION = "isort==5.10.1" +# Copy `noxfile_config.py` to your directory and modify it instead. # `TEST_CONFIG` dict is a configuration hook that allows users to # modify the test configurations. The values here should be in sync @@ -36,13 +41,20 @@ TEST_CONFIG = { # You can opt out from the test for specific Python versions. - "ignored_versions": ["2.7"], + "ignored_versions": [], + # Old samples are opted out of enforcing Python type hints + # All new samples should feature them + "enforce_type_hints": False, # 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', + # If you need to use a specific version of pip, + # change pip_version_override to the string representation + # of the version number, for example, "20.2.4" + "pip_version_override": None, # A dictionary you want to inject into your test. Don't put any # secrets here. These values will override predefined values. "envs": {}, @@ -61,7 +73,7 @@ TEST_CONFIG.update(TEST_CONFIG_OVERRIDE) -def get_pytest_env_vars(): +def get_pytest_env_vars() -> Dict[str, str]: """Returns a dict for pytest invocation.""" ret = {} @@ -76,21 +88,28 @@ def get_pytest_env_vars(): # DO NOT EDIT - automatically generated. -# All versions used to tested samples. -ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8"] +# All versions used to test samples. +ALL_VERSIONS = ["3.6", "3.7", "3.8", "3.9", "3.10"] # Any default versions that should be ignored. IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"] TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS]) -INSTALL_LIBRARY_FROM_SOURCE = bool(os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False)) +INSTALL_LIBRARY_FROM_SOURCE = os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False) in ( + "True", + "true", +) + +# Error if a python version is missing +nox.options.error_on_missing_interpreters = True + # # Style Checks # -def _determine_local_import_names(start_dir): +def _determine_local_import_names(start_dir: str) -> List[str]: """Determines all import names that should be considered "local". This is used when running the linter to insure that import order is @@ -128,8 +147,11 @@ def _determine_local_import_names(start_dir): @nox.session -def lint(session): - session.install("flake8", "flake8-import-order") +def lint(session: nox.sessions.Session) -> None: + if not TEST_CONFIG["enforce_type_hints"]: + session.install("flake8", "flake8-import-order") + else: + session.install("flake8", "flake8-import-order", "flake8-annotations") local_names = _determine_local_import_names(".") args = FLAKE8_COMMON_ARGS + [ @@ -140,6 +162,39 @@ def lint(session): session.run("flake8", *args) +# +# Black +# + + +@nox.session +def blacken(session: nox.sessions.Session) -> None: + """Run black. Format code to uniform standard.""" + session.install(BLACK_VERSION) + python_files = [path for path in os.listdir(".") if path.endswith(".py")] + + session.run("black", *python_files) + + +# +# format = isort + black +# + +@nox.session +def format(session: nox.sessions.Session) -> None: + """ + Run isort to sort imports. Then run black + to format code to uniform standard. + """ + session.install(BLACK_VERSION, ISORT_VERSION) + python_files = [path for path in os.listdir(".") if path.endswith(".py")] + + # Use the --fss option to sort imports using strict alphabetical order. + # See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections + session.run("isort", "--fss", *python_files) + session.run("black", *python_files) + + # # Sample Tests # @@ -148,13 +203,39 @@ def lint(session): PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"] -def _session_tests(session, post_install=None): +def _session_tests( + session: nox.sessions.Session, post_install: Callable = None +) -> None: + # check for presence of tests + test_list = glob.glob("*_test.py") + glob.glob("test_*.py") + test_list.extend(glob.glob("tests")) + + if len(test_list) == 0: + print("No tests found, skipping directory.") + return + + if TEST_CONFIG["pip_version_override"]: + pip_version = TEST_CONFIG["pip_version_override"] + session.install(f"pip=={pip_version}") """Runs py.test for a particular project.""" + concurrent_args = [] if os.path.exists("requirements.txt"): - session.install("-r", "requirements.txt") + if os.path.exists("constraints.txt"): + session.install("-r", "requirements.txt", "-c", "constraints.txt") + else: + session.install("-r", "requirements.txt") + with open("requirements.txt") as rfile: + packages = rfile.read() if os.path.exists("requirements-test.txt"): - session.install("-r", "requirements-test.txt") + if os.path.exists("constraints-test.txt"): + session.install( + "-r", "requirements-test.txt", "-c", "constraints-test.txt" + ) + else: + session.install("-r", "requirements-test.txt") + with open("requirements-test.txt") as rtfile: + packages += rtfile.read() if INSTALL_LIBRARY_FROM_SOURCE: session.install("-e", _get_repo_root()) @@ -162,19 +243,24 @@ def _session_tests(session, post_install=None): if post_install: post_install(session) + if "pytest-parallel" in packages: + concurrent_args.extend(['--workers', 'auto', '--tests-per-worker', 'auto']) + elif "pytest-xdist" in packages: + concurrent_args.extend(['-n', 'auto']) + session.run( "pytest", - *(PYTEST_COMMON_ARGS + session.posargs), + *(PYTEST_COMMON_ARGS + session.posargs + concurrent_args), # Pytest will return 5 when no tests are collected. This can happen # on travis where slow and flaky tests are excluded. # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html success_codes=[0, 5], - env=get_pytest_env_vars() + env=get_pytest_env_vars(), ) @nox.session(python=ALL_VERSIONS) -def py(session): +def py(session: nox.sessions.Session) -> None: """Runs py.test for a sample using the specified version of Python.""" if session.python in TESTED_VERSIONS: _session_tests(session) @@ -189,7 +275,7 @@ def py(session): # -def _get_repo_root(): +def _get_repo_root() -> Optional[str]: """ Returns the root folder of the project. """ # Get root of this repository. Assume we don't have directories nested deeper than 10 items. p = Path(os.getcwd()) @@ -198,6 +284,11 @@ def _get_repo_root(): break if Path(p / ".git").exists(): return str(p) + # .git is not available in repos cloned via Cloud Build + # setup.py is always in the library's root, so use that instead + # https://github.com/googleapis/synthtool/issues/792 + if Path(p / "setup.py").exists(): + return str(p) p = p.parent raise Exception("Unable to detect repository root.") @@ -207,7 +298,7 @@ def _get_repo_root(): @nox.session @nox.parametrize("path", GENERATED_READMES) -def readmegen(session, path): +def readmegen(session: nox.sessions.Session, path: str) -> None: """(Re-)generates the readme for a sample.""" session.install("jinja2", "pyyaml") dir_ = os.path.dirname(path) diff --git a/samples/model-builder/noxfile_config.py b/samples/model-builder/noxfile_config.py new file mode 100644 index 0000000000..fa5af7e8f9 --- /dev/null +++ b/samples/model-builder/noxfile_config.py @@ -0,0 +1,44 @@ +# 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 imported 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"], + # Old samples are opted out of enforcing Python type hints + # All new samples should feature them + "enforce_type_hints": False, + # 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", + # If you need to use a specific version of pip, + # change pip_version_override to the string representation + # of the version number, for example, "20.2.4" + "pip_version_override": None, + # A dictionary you want to inject into your test. Don't put any + # secrets here. These values will override predefined values. + "envs": { + "PYTEST_ADDOPTS": "-n=auto" # Run tests parallel using all available CPUs + }, +} diff --git a/samples/model-builder/predict_tabular_classification_sample.py b/samples/model-builder/predict_tabular_classification_sample.py index e5b1a0283d..0490a1beb1 100644 --- a/samples/model-builder/predict_tabular_classification_sample.py +++ b/samples/model-builder/predict_tabular_classification_sample.py @@ -20,11 +20,22 @@ # [START aiplatform_sdk_predict_tabular_classification_sample] def predict_tabular_classification_sample( - project: str, location: str, endpoint: str, instances: List[Dict], + project: str, + location: str, + endpoint_name: str, + instances: List[Dict], ): + """ + Args + project: Your project ID or project number. + location: Region where Endpoint is located. For example, 'us-central1'. + endpoint_name: A fully qualified endpoint name or endpoint ID. Example: "projects/123/locations/us-central1/endpoints/456" or + "456" when project and location are initialized or passed. + instances: A list of one or more instances (examples) to return a prediction for. + """ aiplatform.init(project=project, location=location) - endpoint = aiplatform.Endpoint(endpoint) + endpoint = aiplatform.Endpoint(endpoint_name) response = endpoint.predict(instances=instances) diff --git a/samples/model-builder/predict_tabular_classification_sample_test.py b/samples/model-builder/predict_tabular_classification_sample_test.py index 49a701115b..c44388131e 100644 --- a/samples/model-builder/predict_tabular_classification_sample_test.py +++ b/samples/model-builder/predict_tabular_classification_sample_test.py @@ -22,7 +22,7 @@ def test_predict_tabular_classification_sample(mock_sdk_init, mock_get_endpoint) predict_tabular_classification_sample.predict_tabular_classification_sample( project=constants.PROJECT, location=constants.LOCATION, - endpoint=constants.ENDPOINT_NAME, + endpoint_name=constants.ENDPOINT_NAME, instances=constants.PREDICTION_TABULAR_CLASSIFICATION_INSTANCE, ) @@ -30,4 +30,6 @@ def test_predict_tabular_classification_sample(mock_sdk_init, mock_get_endpoint) project=constants.PROJECT, location=constants.LOCATION ) - mock_get_endpoint.assert_called_once_with(constants.ENDPOINT_NAME,) + mock_get_endpoint.assert_called_once_with( + constants.ENDPOINT_NAME, + ) diff --git a/samples/model-builder/predict_tabular_regression_sample.py b/samples/model-builder/predict_tabular_regression_sample.py index fee4d34e38..b7bf575d44 100644 --- a/samples/model-builder/predict_tabular_regression_sample.py +++ b/samples/model-builder/predict_tabular_regression_sample.py @@ -19,11 +19,14 @@ # [START aiplatform_sdk_predict_tabular_regression_sample] def predict_tabular_regression_sample( - project: str, location: str, endpoint: str, instances: List[Dict], + project: str, + location: str, + endpoint_name: str, + instances: List[Dict], ): aiplatform.init(project=project, location=location) - endpoint = aiplatform.Endpoint(endpoint) + endpoint = aiplatform.Endpoint(endpoint_name) response = endpoint.predict(instances=instances) diff --git a/samples/model-builder/predict_tabular_regression_sample_test.py b/samples/model-builder/predict_tabular_regression_sample_test.py index 7491d7c1d5..572539e987 100644 --- a/samples/model-builder/predict_tabular_regression_sample_test.py +++ b/samples/model-builder/predict_tabular_regression_sample_test.py @@ -22,7 +22,7 @@ def test_predict_tabular_regression_sample(mock_sdk_init, mock_get_endpoint): predict_tabular_regression_sample.predict_tabular_regression_sample( project=constants.PROJECT, location=constants.LOCATION, - endpoint=constants.ENDPOINT_NAME, + endpoint_name=constants.ENDPOINT_NAME, instances=constants.PREDICTION_TABULAR_REGRESSOIN_INSTANCE, ) @@ -30,4 +30,6 @@ def test_predict_tabular_regression_sample(mock_sdk_init, mock_get_endpoint): project=constants.PROJECT, location=constants.LOCATION ) - mock_get_endpoint.assert_called_once_with(constants.ENDPOINT_NAME,) + mock_get_endpoint.assert_called_once_with( + constants.ENDPOINT_NAME, + ) diff --git a/samples/model-builder/predict_text_classification_single_label_sample_test.py b/samples/model-builder/predict_text_classification_single_label_sample_test.py index 789f2962c3..c446235a79 100644 --- a/samples/model-builder/predict_text_classification_single_label_sample_test.py +++ b/samples/model-builder/predict_text_classification_single_label_sample_test.py @@ -32,4 +32,6 @@ def test_predict_text_classification_single_label_sample( project=constants.PROJECT, location=constants.LOCATION ) - mock_get_endpoint.assert_called_once_with(constants.ENDPOINT_NAME,) + mock_get_endpoint.assert_called_once_with( + constants.ENDPOINT_NAME, + ) diff --git a/samples/model-builder/predict_text_entity_extraction_sample_test.py b/samples/model-builder/predict_text_entity_extraction_sample_test.py index 3b123ff148..3ca2b49b43 100644 --- a/samples/model-builder/predict_text_entity_extraction_sample_test.py +++ b/samples/model-builder/predict_text_entity_extraction_sample_test.py @@ -30,4 +30,6 @@ def test_predict_text_entity_extraction_sample(mock_sdk_init, mock_get_endpoint) project=constants.PROJECT, location=constants.LOCATION ) - mock_get_endpoint.assert_called_once_with(constants.ENDPOINT_NAME,) + mock_get_endpoint.assert_called_once_with( + constants.ENDPOINT_NAME, + ) diff --git a/samples/model-builder/predict_text_sentiment_analysis_sample_test.py b/samples/model-builder/predict_text_sentiment_analysis_sample_test.py index e3a3fad58c..c2ed180c9f 100644 --- a/samples/model-builder/predict_text_sentiment_analysis_sample_test.py +++ b/samples/model-builder/predict_text_sentiment_analysis_sample_test.py @@ -30,4 +30,6 @@ def test_predict_text_sentiment_analysis_sample(mock_sdk_init, mock_get_endpoint project=constants.PROJECT, location=constants.LOCATION ) - mock_get_endpoint.assert_called_once_with(constants.ENDPOINT_NAME,) + mock_get_endpoint.assert_called_once_with( + constants.ENDPOINT_NAME, + ) diff --git a/samples/model-builder/read_feature_values_sample.py b/samples/model-builder/read_feature_values_sample.py new file mode 100644 index 0000000000..d98a4ae2e8 --- /dev/null +++ b/samples/model-builder/read_feature_values_sample.py @@ -0,0 +1,42 @@ +# Copyright 2022 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 aiplatform_sdk_read_features_sample] +from typing import List, Union + +from google.cloud import aiplatform + + +def read_feature_values_sample( + project: str, + location: str, + entity_type_id: str, + featurestore_id: str, + entity_ids: Union[str, List[str]], + feature_ids: Union[str, List[str]] = "*", +): + + aiplatform.init(project=project, location=location) + + my_entity_type = aiplatform.featurestore.EntityType( + entity_type_name=entity_type_id, featurestore_id=featurestore_id + ) + + my_dataframe = my_entity_type.read(entity_ids=entity_ids, feature_ids=feature_ids) + + return my_dataframe + + +# [END aiplatform_sdk_read_features_sample] diff --git a/samples/model-builder/read_feature_values_sample_test.py b/samples/model-builder/read_feature_values_sample_test.py new file mode 100644 index 0000000000..1d69b0220c --- /dev/null +++ b/samples/model-builder/read_feature_values_sample_test.py @@ -0,0 +1,43 @@ +# Copyright 2022 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 read_feature_values_sample +import test_constants as constants + + +def test_read_feature_values_sample( + mock_sdk_init, mock_get_entity_type, mock_read_feature_values +): + + read_feature_values_sample.read_feature_values_sample( + project=constants.PROJECT, + location=constants.LOCATION, + entity_type_id=constants.ENTITY_TYPE_ID, + featurestore_id=constants.FEATURESTORE_ID, + entity_ids=constants.ENTITY_IDS, + feature_ids=constants.FEATURE_IDS, + ) + + mock_sdk_init.assert_called_once_with( + project=constants.PROJECT, location=constants.LOCATION + ) + + mock_get_entity_type.assert_called_once_with( + entity_type_name=constants.ENTITY_TYPE_ID, + featurestore_id=constants.FEATURESTORE_ID, + ) + + mock_read_feature_values.assert_called_once_with( + entity_ids=constants.ENTITY_IDS, feature_ids=constants.FEATURE_IDS + ) diff --git a/samples/model-builder/requirements-test.txt b/samples/model-builder/requirements-test.txt new file mode 100644 index 0000000000..4957e408f6 --- /dev/null +++ b/samples/model-builder/requirements-test.txt @@ -0,0 +1,2 @@ +pytest==6.2.5 +pytest-xdist \ No newline at end of file diff --git a/samples/model-builder/requirements-tests.txt b/samples/model-builder/requirements-tests.txt deleted file mode 100644 index f53c4c11a6..0000000000 --- a/samples/model-builder/requirements-tests.txt +++ /dev/null @@ -1 +0,0 @@ -pytest >= 6.2 diff --git a/samples/model-builder/requirements.txt b/samples/model-builder/requirements.txt index efe811b2c3..983ca6b4c6 100644 --- a/samples/model-builder/requirements.txt +++ b/samples/model-builder/requirements.txt @@ -1,2 +1 @@ -pytest >= 6.2 -git+https://github.com/googleapis/python-aiplatform.git@mb-release#egg=google-cloud-aiplatform \ No newline at end of file +google-cloud-aiplatform \ No newline at end of file diff --git a/samples/model-builder/test_constants.py b/samples/model-builder/test_constants.py index aa92434b95..6f13f137bd 100644 --- a/samples/model-builder/test_constants.py +++ b/samples/model-builder/test_constants.py @@ -17,6 +17,7 @@ from google.auth import credentials from google.cloud import aiplatform +from google.protobuf import timestamp_pb2 PROJECT = "abc" LOCATION = "us-central1" @@ -41,6 +42,7 @@ TRAINING_JOB_NAME = f"{PARENT}/trainingJobs/{RESOURCE_ID}" BIGQUERY_SOURCE = f"bq://{PROJECT}.{DATASET_NAME}.table1" +BIGQUERY_DESTINATION_PREFIX = "bq://bigquery-public-data.ml_datasets.iris" GCS_SOURCES = ["gs://bucket1/source1.jsonl", "gs://bucket7/source4.jsonl"] BIGQUERY_SOURCE = "bq://bigquery-public-data.ml_datasets.iris" @@ -196,3 +198,79 @@ "gs://bucket3/custom-training-python-package/my_app/trainer-0.1.tar.gz" ) PYTHON_MODULE_NAME = "trainer.task" +MODEL_TYPE = "CLOUD" + +# Feature store constants +FEATURESTORE_ID = "movie_prediction" +FEATURESTORE_NAME = ( + f"projects/{PROJECT}/locations/{LOCATION}/featurestores/{FEATURESTORE_ID}" +) +ENTITY_TYPE_ID = "users" +ENTITY_IDS = ["alice", "bob"] +ENTITY_TYPE_NAME = f"projects/{PROJECT}/locations/{LOCATION}/featurestores/{FEATURESTORE_ID}/entityTypes/{ENTITY_TYPE_ID}" +FEATURE_ID = "liked_genres" +FEATURE_IDS = ["age", "gender", "liked_genres"] +FEATURE_NAME = f"projects/{PROJECT}/locations/{LOCATION}/featurestores/{FEATURESTORE_ID}/entityTypes/{ENTITY_TYPE_ID}/features/{FEATURE_ID}" +FEATURE_VALUE_TYPE = "INT64" +FEATURE_CONFIGS = { + "age": {"value_type": "INT64", "description": "User age"}, + "gender": {"value_type": "STRING", "description": "User gender"}, + "liked_genres": { + "value_type": "STRING_ARRAY", + "description": "An array of genres this user liked", + }, +} +SERVING_FEATURE_IDS = { + "users": ["age", "gender", "liked_genres"], + "movies": ["title", "average_rating", "genres"], +} +ONLINE_STORE_FIXED_NODE_COUNT = 1 +SYNC = True +FORCE = True +BQ_DESTINATION_OUTPUT_URI = f"bq://{PROJECT}.example_dataset.example_table" +INPUT_CSV_FILE = "gs://cloud-samples-data-us-central1/vertex-ai/feature-store/datasets/movie_prediction.csv" +USERS_FEATURE_TIME = "update_time" +USERS_ENTITY_ID_FIELD = "user_id" +USERS_GCS_SOURCE_URI = ( + "gs://cloud-samples-data-us-central1/vertex-ai/feature-store/datasets/users.avro" +) +GCS_SOURCE_TYPE = "avro" +WORKER_COUNT = 1 + +TABULAR_TARGET_COLUMN = "target_column" +FORECASTNG_TIME_COLUMN = "date" +FORECASTNG_TIME_SERIES_IDENTIFIER_COLUMN = "time_series_id" +FORECASTNG_UNAVAILABLE_AT_FORECAST_COLUMNS = [] +FORECASTNG_AVAILABLE_AT_FORECAST_COLUMNS = [] +FORECASTNG_FORECAST_HORIZON = 1 +DATA_GRANULARITY_UNIT = "week" +DATA_GRANULARITY_COUNT = 1 + +TIMESTAMP_SPLIT_COLUMN_NAME = "timestamp_split_column_name" +WEIGHT_COLUMN = "weight" +TIME_SERIES_ATTRIBUTE_COLUMNS = [] +CONTEXT_WINDOW = 0 +EXPORT_EVALUATED_DATA_ITEMS = True +EXPORT_EVALUATED_DATA_ITEMS_BIGQUERY_DESTINATION_URI = "bq://test:test:test" +EXPORT_EVALUATED_DATA_ITEMS_OVERRIDE_DESTINATION = True +QUANTILES = [0, 0.5, 1] +VALIDATION_OPTIONS = "fail-pipeline" +PREDEFINED_SPLIT_COLUMN_NAME = "predefined" + +TENSORBOARD_NAME = ( + f"projects/{PROJECT}/locations/{LOCATION}/tensorboards/my-tensorboard" +) + +SCHEMA_TITLE = "system.Schema" +SCHEMA_VERSION = "0.0.1" +METADATA = {} + +EXPERIMENT_RUN_NAME = "my-run" + +METRICS = {"accuracy": 0.1} +PARAMS = {"learning_rate": 0.1} + +TEMPLATE_PATH = "pipeline.json" + +STEP = 1 +TIMESTAMP = timestamp_pb2.Timestamp() diff --git a/samples/snippets/conftest.py b/samples/snippets/conftest.py index 2d2dd2fa78..db8bfaf73b 100644 --- a/samples/snippets/conftest.py +++ b/samples/snippets/conftest.py @@ -15,7 +15,10 @@ import os from uuid import uuid4 -from google.cloud import aiplatform +from google.api_core import exceptions + +from google.cloud import aiplatform, aiplatform_v1beta1 +from google.cloud import bigquery from google.cloud import storage import pytest @@ -83,6 +86,22 @@ def dataset_client(): yield dataset_client +@pytest.fixture +def featurestore_client(): + featurestore_client = aiplatform_v1beta1.FeaturestoreServiceClient( + client_options={"api_endpoint": "us-central1-aiplatform.googleapis.com"} + ) + yield featurestore_client + + +@pytest.fixture +def bigquery_client(): + bigquery_client = bigquery.Client( + project=os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") + ) + yield bigquery_client + + # Shared setup/teardown. @pytest.fixture() def teardown_batch_prediction_job(shared_state, job_client): @@ -158,20 +177,27 @@ def teardown_hyperparameter_tuning_job(shared_state, job_client): def teardown_training_pipeline(shared_state, pipeline_client): yield - pipeline_client.cancel_training_pipeline( - name=shared_state["training_pipeline_name"] - ) + try: + pipeline_client.cancel_training_pipeline( + name=shared_state["training_pipeline_name"] + ) - # Waiting for training pipeline to be in CANCELLED state - helpers.wait_for_job_state( - get_job_method=pipeline_client.get_training_pipeline, - name=shared_state["training_pipeline_name"], - ) + # Waiting for training pipeline to be in CANCELLED state + timeout = shared_state["cancel_batch_prediction_job_timeout"] + helpers.wait_for_job_state( + get_job_method=pipeline_client.get_training_pipeline, + name=shared_state["training_pipeline_name"], + timeout=timeout, + ) - # Delete the training pipeline - pipeline_client.delete_training_pipeline( - name=shared_state["training_pipeline_name"] - ) + except exceptions.FailedPrecondition: + pass # If pipeline failed, ignore and skip directly to deletion + + finally: + # Delete the training pipeline + pipeline_client.delete_training_pipeline( + name=shared_state["training_pipeline_name"] + ) @pytest.fixture() @@ -201,6 +227,57 @@ def teardown_dataset(shared_state, dataset_client): dataset_client.delete_dataset(name=shared_state["dataset_name"]) +@pytest.fixture() +def teardown_featurestore(shared_state, featurestore_client): + yield + + # Force delete the created featurestore + force_delete_featurestore_request = { + "name": shared_state["featurestore_name"], + "force": True, + } + featurestore_client.delete_featurestore(request=force_delete_featurestore_request) + + +@pytest.fixture() +def teardown_entity_type(shared_state, featurestore_client): + yield + + # Force delete the created entity type + force_delete_entity_type_request = { + "name": shared_state["entity_type_name"], + "force": True, + } + featurestore_client.delete_entity_type(request=force_delete_entity_type_request) + + +@pytest.fixture() +def teardown_feature(shared_state, featurestore_client): + yield + + # Delete the created feature + featurestore_client.delete_feature(name=shared_state["feature_name"]) + + +@pytest.fixture() +def teardown_features(shared_state, featurestore_client): + yield + + # Delete the created features + for feature_name in shared_state["feature_names"]: + featurestore_client.delete_feature(name=feature_name) + + +@pytest.fixture() +def teardown_batch_read_feature_values(shared_state, bigquery_client): + yield + + # Delete the created dataset + bigquery_client.delete_dataset( + shared_state["destination_data_set"], delete_contents=True, not_found_ok=True + ) + + @pytest.fixture() def create_endpoint(shared_state, endpoint_client): def create(project, location, test_name="temp_deploy_model_test"): diff --git a/samples/snippets/create_dataset_image_sample.py b/samples/snippets/dataset_service/create_dataset_image_sample.py similarity index 100% rename from samples/snippets/create_dataset_image_sample.py rename to samples/snippets/dataset_service/create_dataset_image_sample.py diff --git a/samples/snippets/create_dataset_image_sample_test.py b/samples/snippets/dataset_service/create_dataset_image_sample_test.py similarity index 93% rename from samples/snippets/create_dataset_image_sample_test.py rename to samples/snippets/dataset_service/create_dataset_image_sample_test.py index 96d9dde089..75305313a3 100644 --- a/samples/snippets/create_dataset_image_sample_test.py +++ b/samples/snippets/dataset_service/create_dataset_image_sample_test.py @@ -15,9 +15,9 @@ import os from uuid import uuid4 +import create_dataset_image_sample import pytest -import create_dataset_image_sample import helpers PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") @@ -28,6 +28,7 @@ def teardown(teardown_dataset): yield +@pytest.mark.skip(reason="https://github.com/googleapis/java-aiplatform/issues/420") def test_ucaip_generated_create_dataset_image(capsys, shared_state): create_dataset_image_sample.create_dataset_image_sample( display_name=f"temp_create_dataset_image_test_{uuid4()}", project=PROJECT_ID diff --git a/samples/snippets/create_dataset_sample.py b/samples/snippets/dataset_service/create_dataset_sample.py similarity index 100% rename from samples/snippets/create_dataset_sample.py rename to samples/snippets/dataset_service/create_dataset_sample.py diff --git a/samples/snippets/create_dataset_sample_test.py b/samples/snippets/dataset_service/create_dataset_sample_test.py similarity index 100% rename from samples/snippets/create_dataset_sample_test.py rename to samples/snippets/dataset_service/create_dataset_sample_test.py index 5394395dec..c56a8e8a29 100644 --- a/samples/snippets/create_dataset_sample_test.py +++ b/samples/snippets/dataset_service/create_dataset_sample_test.py @@ -15,9 +15,9 @@ import os from uuid import uuid4 +import create_dataset_sample import pytest -import create_dataset_sample import helpers PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") diff --git a/samples/snippets/create_dataset_tabular_bigquery_sample.py b/samples/snippets/dataset_service/create_dataset_tabular_bigquery_sample.py similarity index 100% rename from samples/snippets/create_dataset_tabular_bigquery_sample.py rename to samples/snippets/dataset_service/create_dataset_tabular_bigquery_sample.py diff --git a/samples/snippets/create_dataset_tabular_bigquery_sample_test.py b/samples/snippets/dataset_service/create_dataset_tabular_bigquery_sample_test.py similarity index 100% rename from samples/snippets/create_dataset_tabular_bigquery_sample_test.py rename to samples/snippets/dataset_service/create_dataset_tabular_bigquery_sample_test.py index d8f8dc1993..0752db30e6 100644 --- a/samples/snippets/create_dataset_tabular_bigquery_sample_test.py +++ b/samples/snippets/dataset_service/create_dataset_tabular_bigquery_sample_test.py @@ -15,9 +15,9 @@ import os from uuid import uuid4 +import create_dataset_tabular_bigquery_sample import pytest -import create_dataset_tabular_bigquery_sample import helpers PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") diff --git a/samples/snippets/create_dataset_tabular_gcs_sample.py b/samples/snippets/dataset_service/create_dataset_tabular_gcs_sample.py similarity index 100% rename from samples/snippets/create_dataset_tabular_gcs_sample.py rename to samples/snippets/dataset_service/create_dataset_tabular_gcs_sample.py diff --git a/samples/snippets/create_dataset_tabular_gcs_sample_test.py b/samples/snippets/dataset_service/create_dataset_tabular_gcs_sample_test.py similarity index 93% rename from samples/snippets/create_dataset_tabular_gcs_sample_test.py rename to samples/snippets/dataset_service/create_dataset_tabular_gcs_sample_test.py index aaf5c9bad3..03f07c46aa 100644 --- a/samples/snippets/create_dataset_tabular_gcs_sample_test.py +++ b/samples/snippets/dataset_service/create_dataset_tabular_gcs_sample_test.py @@ -15,9 +15,9 @@ import os from uuid import uuid4 +import create_dataset_tabular_gcs_sample import pytest -import create_dataset_tabular_gcs_sample import helpers PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") @@ -29,6 +29,7 @@ def teardown(teardown_dataset): yield +@pytest.mark.skip(reason="https://github.com/googleapis/java-aiplatform/issues/420") def test_ucaip_generated_create_dataset_tabular_gcs(capsys, shared_state): create_dataset_tabular_gcs_sample.create_dataset_tabular_gcs_sample( display_name=f"temp_create_dataset_test_{uuid4()}", diff --git a/samples/snippets/create_dataset_text_sample.py b/samples/snippets/dataset_service/create_dataset_text_sample.py similarity index 100% rename from samples/snippets/create_dataset_text_sample.py rename to samples/snippets/dataset_service/create_dataset_text_sample.py diff --git a/samples/snippets/create_dataset_video_sample.py b/samples/snippets/dataset_service/create_dataset_video_sample.py similarity index 100% rename from samples/snippets/create_dataset_video_sample.py rename to samples/snippets/dataset_service/create_dataset_video_sample.py diff --git a/samples/snippets/create_dataset_video_sample_test.py b/samples/snippets/dataset_service/create_dataset_video_sample_test.py similarity index 93% rename from samples/snippets/create_dataset_video_sample_test.py rename to samples/snippets/dataset_service/create_dataset_video_sample_test.py index d2c499ae4c..902676b8bb 100644 --- a/samples/snippets/create_dataset_video_sample_test.py +++ b/samples/snippets/dataset_service/create_dataset_video_sample_test.py @@ -15,9 +15,9 @@ import os from uuid import uuid4 +import create_dataset_video_sample import pytest -import create_dataset_video_sample import helpers PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") @@ -31,6 +31,7 @@ def teardown(teardown_dataset): yield +@pytest.mark.skip(reason="https://github.com/googleapis/java-aiplatform/issues/420") def test_ucaip_generated_create_dataset_video_sample_vision(capsys, shared_state): create_dataset_video_sample.create_dataset_video_sample( display_name=f"temp_create_dataset_test_{uuid4()}", project=PROJECT_ID diff --git a/samples/snippets/delete_dataset_sample.py b/samples/snippets/dataset_service/delete_dataset_sample.py similarity index 100% rename from samples/snippets/delete_dataset_sample.py rename to samples/snippets/dataset_service/delete_dataset_sample.py diff --git a/samples/snippets/import_data_image_classification_single_label_sample.py b/samples/snippets/dataset_service/import_data_image_classification_single_label_sample.py similarity index 100% rename from samples/snippets/import_data_image_classification_single_label_sample.py rename to samples/snippets/dataset_service/import_data_image_classification_single_label_sample.py diff --git a/samples/snippets/import_data_image_object_detection_sample.py b/samples/snippets/dataset_service/import_data_image_object_detection_sample.py similarity index 100% rename from samples/snippets/import_data_image_object_detection_sample.py rename to samples/snippets/dataset_service/import_data_image_object_detection_sample.py diff --git a/samples/snippets/import_data_sample.py b/samples/snippets/dataset_service/import_data_sample.py similarity index 100% rename from samples/snippets/import_data_sample.py rename to samples/snippets/dataset_service/import_data_sample.py diff --git a/samples/snippets/import_data_text_classification_single_label_sample.py b/samples/snippets/dataset_service/import_data_text_classification_single_label_sample.py similarity index 100% rename from samples/snippets/import_data_text_classification_single_label_sample.py rename to samples/snippets/dataset_service/import_data_text_classification_single_label_sample.py diff --git a/samples/snippets/import_data_text_entity_extraction_sample.py b/samples/snippets/dataset_service/import_data_text_entity_extraction_sample.py similarity index 100% rename from samples/snippets/import_data_text_entity_extraction_sample.py rename to samples/snippets/dataset_service/import_data_text_entity_extraction_sample.py diff --git a/samples/snippets/import_data_text_entity_extraction_sample_test.py b/samples/snippets/dataset_service/import_data_text_entity_extraction_sample_test.py similarity index 59% rename from samples/snippets/import_data_text_entity_extraction_sample_test.py rename to samples/snippets/dataset_service/import_data_text_entity_extraction_sample_test.py index 378dac434a..728fcd86fc 100644 --- a/samples/snippets/import_data_text_entity_extraction_sample_test.py +++ b/samples/snippets/dataset_service/import_data_text_entity_extraction_sample_test.py @@ -1,9 +1,22 @@ -import os +# 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. -import pytest -import import_data_text_entity_extraction_sample +import os +import import_data_text_entity_extraction_sample +import pytest PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") LOCATION = "us-central1" @@ -24,6 +37,7 @@ def teardown(teardown_dataset): yield +@pytest.mark.skip(reason="https://github.com/googleapis/java-aiplatform/issues/420") def test_ucaip_generated_import_data_text_entity_extraction_sample( capsys, shared_state ): diff --git a/samples/snippets/import_data_text_sentiment_analysis_sample.py b/samples/snippets/dataset_service/import_data_text_sentiment_analysis_sample.py similarity index 100% rename from samples/snippets/import_data_text_sentiment_analysis_sample.py rename to samples/snippets/dataset_service/import_data_text_sentiment_analysis_sample.py diff --git a/samples/snippets/import_data_text_sentiment_analysis_sample_test.py b/samples/snippets/dataset_service/import_data_text_sentiment_analysis_sample_test.py similarity index 63% rename from samples/snippets/import_data_text_sentiment_analysis_sample_test.py rename to samples/snippets/dataset_service/import_data_text_sentiment_analysis_sample_test.py index 2bca6f4779..48265e6093 100644 --- a/samples/snippets/import_data_text_sentiment_analysis_sample_test.py +++ b/samples/snippets/dataset_service/import_data_text_sentiment_analysis_sample_test.py @@ -1,9 +1,22 @@ -import os +# 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. -import pytest -import import_data_text_sentiment_analysis_sample +import os +import import_data_text_sentiment_analysis_sample +import pytest PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") LOCATION = "us-central1" diff --git a/samples/snippets/import_data_video_action_recognition_sample.py b/samples/snippets/dataset_service/import_data_video_action_recognition_sample.py similarity index 100% rename from samples/snippets/import_data_video_action_recognition_sample.py rename to samples/snippets/dataset_service/import_data_video_action_recognition_sample.py diff --git a/samples/snippets/import_data_video_action_recognition_sample_test.py b/samples/snippets/dataset_service/import_data_video_action_recognition_sample_test.py similarity index 94% rename from samples/snippets/import_data_video_action_recognition_sample_test.py rename to samples/snippets/dataset_service/import_data_video_action_recognition_sample_test.py index 8f4199c6a0..7680e4d004 100644 --- a/samples/snippets/import_data_video_action_recognition_sample_test.py +++ b/samples/snippets/dataset_service/import_data_video_action_recognition_sample_test.py @@ -15,9 +15,8 @@ import os -import pytest - import import_data_video_action_recognition_sample +import pytest PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") LOCATION = "us-central1" @@ -38,6 +37,7 @@ def teardown(teardown_dataset): yield +@pytest.mark.skip(reason="https://github.com/googleapis/java-aiplatform/issues/420") def test_import_data_video_action_recognition_sample( capsys, shared_state, dataset_client ): diff --git a/samples/snippets/import_data_video_classification_sample.py b/samples/snippets/dataset_service/import_data_video_classification_sample.py similarity index 100% rename from samples/snippets/import_data_video_classification_sample.py rename to samples/snippets/dataset_service/import_data_video_classification_sample.py diff --git a/samples/snippets/import_data_video_classification_sample_test.py b/samples/snippets/dataset_service/import_data_video_classification_sample_test.py similarity index 94% rename from samples/snippets/import_data_video_classification_sample_test.py rename to samples/snippets/dataset_service/import_data_video_classification_sample_test.py index 089b9a8b5b..2b588e3f6b 100644 --- a/samples/snippets/import_data_video_classification_sample_test.py +++ b/samples/snippets/dataset_service/import_data_video_classification_sample_test.py @@ -15,9 +15,8 @@ import os -import pytest - import import_data_video_classification_sample +import pytest PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") LOCATION = "us-central1" @@ -38,6 +37,7 @@ def teardown(teardown_dataset): yield +@pytest.mark.skip(reason="https://github.com/googleapis/java-aiplatform/issues/420") def test_ucaip_generated_import_data_video_classification_sample_single_label_image( capsys, shared_state ): diff --git a/samples/snippets/import_data_video_object_tracking_sample.py b/samples/snippets/dataset_service/import_data_video_object_tracking_sample.py similarity index 100% rename from samples/snippets/import_data_video_object_tracking_sample.py rename to samples/snippets/dataset_service/import_data_video_object_tracking_sample.py diff --git a/samples/snippets/import_data_video_object_tracking_sample_test.py b/samples/snippets/dataset_service/import_data_video_object_tracking_sample_test.py similarity index 99% rename from samples/snippets/import_data_video_object_tracking_sample_test.py rename to samples/snippets/dataset_service/import_data_video_object_tracking_sample_test.py index 6ba16a9c43..9813b2753c 100644 --- a/samples/snippets/import_data_video_object_tracking_sample_test.py +++ b/samples/snippets/dataset_service/import_data_video_object_tracking_sample_test.py @@ -15,9 +15,8 @@ import os -import pytest - import import_data_video_object_tracking_sample +import pytest PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") LOCATION = "us-central1" diff --git a/samples/snippets/create_endpoint_sample.py b/samples/snippets/endpoint_service/create_endpoint_sample.py similarity index 100% rename from samples/snippets/create_endpoint_sample.py rename to samples/snippets/endpoint_service/create_endpoint_sample.py diff --git a/samples/snippets/create_endpoint_sample_test.py b/samples/snippets/endpoint_service/create_endpoint_sample_test.py similarity index 100% rename from samples/snippets/create_endpoint_sample_test.py rename to samples/snippets/endpoint_service/create_endpoint_sample_test.py index 5d6c66e510..fa2b3f7053 100644 --- a/samples/snippets/create_endpoint_sample_test.py +++ b/samples/snippets/endpoint_service/create_endpoint_sample_test.py @@ -15,9 +15,9 @@ import os from uuid import uuid4 +import create_endpoint_sample import pytest -import create_endpoint_sample import helpers DISPLAY_NAME = f"temp_create_endpoint_test_{uuid4()}" diff --git a/samples/snippets/delete_endpoint_sample.py b/samples/snippets/endpoint_service/delete_endpoint_sample.py similarity index 100% rename from samples/snippets/delete_endpoint_sample.py rename to samples/snippets/endpoint_service/delete_endpoint_sample.py diff --git a/samples/snippets/deploy_model_custom_trained_model_sample.py b/samples/snippets/endpoint_service/deploy_model_custom_trained_model_sample.py similarity index 100% rename from samples/snippets/deploy_model_custom_trained_model_sample.py rename to samples/snippets/endpoint_service/deploy_model_custom_trained_model_sample.py diff --git a/samples/snippets/deploy_model_custom_trained_model_sample_test.py b/samples/snippets/endpoint_service/deploy_model_custom_trained_model_sample_test.py similarity index 95% rename from samples/snippets/deploy_model_custom_trained_model_sample_test.py rename to samples/snippets/endpoint_service/deploy_model_custom_trained_model_sample_test.py index 3f4ba603d7..6151889ede 100644 --- a/samples/snippets/deploy_model_custom_trained_model_sample_test.py +++ b/samples/snippets/endpoint_service/deploy_model_custom_trained_model_sample_test.py @@ -15,9 +15,9 @@ import os from uuid import uuid4 +import deploy_model_custom_trained_model_sample import pytest -import deploy_model_custom_trained_model_sample import helpers PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") @@ -38,6 +38,7 @@ def teardown(teardown_endpoint): yield +@pytest.mark.skip(reason="https://github.com/googleapis/java-aiplatform/issues/420") def test_ucaip_generated_deploy_model_custom_trained_model_sample(capsys, shared_state): assert shared_state["endpoint_name"] is not None diff --git a/samples/snippets/deploy_model_sample.py b/samples/snippets/endpoint_service/deploy_model_sample.py similarity index 100% rename from samples/snippets/deploy_model_sample.py rename to samples/snippets/endpoint_service/deploy_model_sample.py diff --git a/samples/snippets/deploy_model_sample_test.py b/samples/snippets/endpoint_service/deploy_model_sample_test.py similarity index 100% rename from samples/snippets/deploy_model_sample_test.py rename to samples/snippets/endpoint_service/deploy_model_sample_test.py index e739d75f2f..b12b234b8b 100644 --- a/samples/snippets/deploy_model_sample_test.py +++ b/samples/snippets/endpoint_service/deploy_model_sample_test.py @@ -15,9 +15,9 @@ import os from uuid import uuid4 +import deploy_model_sample import pytest -import deploy_model_sample import helpers PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") diff --git a/samples/snippets/feature_store_service/batch_create_features_sample.py b/samples/snippets/feature_store_service/batch_create_features_sample.py new file mode 100644 index 0000000000..07070d65f7 --- /dev/null +++ b/samples/snippets/feature_store_service/batch_create_features_sample.py @@ -0,0 +1,74 @@ +# 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. + +# Create features in bulk for an existing type. +# See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running +# the code snippet + +# [START aiplatform_batch_create_features_sample] +from google.cloud import aiplatform + + +def batch_create_features_sample( + project: str, + featurestore_id: str, + entity_type_id: str, + location: str = "us-central1", + api_endpoint: str = "us-central1-aiplatform.googleapis.com", + timeout: int = 300, +): + # The AI Platform services require regional API endpoints, which need to be + # in the same region or multi-region overlap with the Feature Store location. + client_options = {"api_endpoint": api_endpoint} + # Initialize client that will be used to create and send requests. + # This client only needs to be created once, and can be reused for multiple requests. + client = aiplatform.gapic.FeaturestoreServiceClient(client_options=client_options) + parent = f"projects/{project}/locations/{location}/featurestores/{featurestore_id}/entityTypes/{entity_type_id}" + age_feature = aiplatform.gapic.Feature( + value_type=aiplatform.gapic.Feature.ValueType.INT64, description="User age", + ) + age_feature_request = aiplatform.gapic.CreateFeatureRequest( + feature=age_feature, feature_id="age" + ) + + gender_feature = aiplatform.gapic.Feature( + value_type=aiplatform.gapic.Feature.ValueType.STRING, description="User gender" + ) + gender_feature_request = aiplatform.gapic.CreateFeatureRequest( + feature=gender_feature, feature_id="gender" + ) + + liked_genres_feature = aiplatform.gapic.Feature( + value_type=aiplatform.gapic.Feature.ValueType.STRING_ARRAY, + description="An array of genres that this user liked", + ) + liked_genres_feature_request = aiplatform.gapic.CreateFeatureRequest( + feature=liked_genres_feature, feature_id="liked_genres" + ) + + requests = [ + age_feature_request, + gender_feature_request, + liked_genres_feature_request, + ] + batch_create_features_request = aiplatform.gapic.BatchCreateFeaturesRequest( + parent=parent, requests=requests + ) + lro_response = client.batch_create_features(request=batch_create_features_request) + print("Long running operation:", lro_response.operation.name) + batch_create_features_response = lro_response.result(timeout=timeout) + print("batch_create_features_response:", batch_create_features_response) + + +# [END aiplatform_batch_create_features_sample] diff --git a/samples/snippets/feature_store_service/batch_create_features_sample_test.py b/samples/snippets/feature_store_service/batch_create_features_sample_test.py new file mode 100644 index 0000000000..8864bd5741 --- /dev/null +++ b/samples/snippets/feature_store_service/batch_create_features_sample_test.py @@ -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 +# +# 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. + +import os +from uuid import uuid4 + +import batch_create_features_sample +import create_entity_type_sample + +import pytest + +import helpers + +PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") + + +@pytest.fixture(scope="function", autouse=True) +def teardown(teardown_entity_type): + yield + + +def setup_temp_entity_type(featurestore_id, entity_type_id, capsys): + create_entity_type_sample.create_entity_type_sample( + project=PROJECT_ID, + featurestore_id=featurestore_id, + entity_type_id=entity_type_id, + ) + out, _ = capsys.readouterr() + assert "create_entity_type_response" in out + return helpers.get_featurestore_resource_name(out) + + +def test_ucaip_generated_batch_create_features_sample_vision(capsys, shared_state): + featurestore_id = "perm_sample_featurestore" + entity_type_id = f"users_{uuid4()}".replace("-", "_")[:60] + entity_type_name = setup_temp_entity_type(featurestore_id, entity_type_id, capsys) + location = "us-central1" + batch_create_features_sample.batch_create_features_sample( + project=PROJECT_ID, + featurestore_id=featurestore_id, + entity_type_id=entity_type_id, + location=location, + ) + out, _ = capsys.readouterr() + assert "batch_create_features_response" in out + + shared_state["entity_type_name"] = entity_type_name diff --git a/samples/snippets/feature_store_service/batch_read_feature_values_sample.py b/samples/snippets/feature_store_service/batch_read_feature_values_sample.py new file mode 100644 index 0000000000..7563eebb46 --- /dev/null +++ b/samples/snippets/feature_store_service/batch_read_feature_values_sample.py @@ -0,0 +1,86 @@ +# 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. + +# Batch read feature values from a featurestore, as determined by your read +# instances list file, to export data. +# See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running +# the code snippet + +# [START aiplatform_batch_read_feature_values_sample] +from google.cloud import aiplatform + + +def batch_read_feature_values_sample( + project: str, + featurestore_id: str, + input_csv_file: str, + destination_table_uri: str, + location: str = "us-central1", + api_endpoint: str = "us-central1-aiplatform.googleapis.com", + timeout: int = 300, +): + # The AI Platform services require regional API endpoints, which need to be + # in the same region or multi-region overlap with the Feature Store location. + client_options = {"api_endpoint": api_endpoint} + # Initialize client that will be used to create and send requests. + # This client only needs to be created once, and can be reused for multiple requests. + client = aiplatform.gapic.FeaturestoreServiceClient(client_options=client_options) + featurestore = ( + f"projects/{project}/locations/{location}/featurestores/{featurestore_id}" + ) + csv_read_instances = aiplatform.gapic.CsvSource( + gcs_source=aiplatform.gapic.GcsSource(uris=[input_csv_file]) + ) + destination = aiplatform.gapic.FeatureValueDestination( + bigquery_destination=aiplatform.gapic.BigQueryDestination( + # Output to BigQuery table created earlier + output_uri=destination_table_uri + ) + ) + + users_feature_selector = aiplatform.gapic.FeatureSelector( + id_matcher=aiplatform.gapic.IdMatcher(ids=["age", "gender", "liked_genres"]) + ) + users_entity_type_spec = aiplatform.gapic.BatchReadFeatureValuesRequest.EntityTypeSpec( + # Read the 'age', 'gender' and 'liked_genres' features from the 'perm_users' entity + entity_type_id="perm_users", + feature_selector=users_feature_selector, + ) + + movies_feature_selector = aiplatform.gapic.FeatureSelector( + id_matcher=aiplatform.gapic.IdMatcher(ids=["*"]) + ) + movies_entity_type_spec = aiplatform.gapic.BatchReadFeatureValuesRequest.EntityTypeSpec( + # Read the all features from the 'perm_movies' entity + entity_type_id="perm_movies", + feature_selector=movies_feature_selector, + ) + + entity_type_specs = [users_entity_type_spec, movies_entity_type_spec] + # Batch serving request from CSV + batch_read_feature_values_request = aiplatform.gapic.BatchReadFeatureValuesRequest( + featurestore=featurestore, + csv_read_instances=csv_read_instances, + destination=destination, + entity_type_specs=entity_type_specs, + ) + lro_response = client.batch_read_feature_values( + request=batch_read_feature_values_request + ) + print("Long running operation:", lro_response.operation.name) + batch_read_feature_values_response = lro_response.result(timeout=timeout) + print("batch_read_feature_values_response:", batch_read_feature_values_response) + + +# [END aiplatform_batch_read_feature_values_sample] diff --git a/samples/snippets/feature_store_service/batch_read_feature_values_sample_test.py b/samples/snippets/feature_store_service/batch_read_feature_values_sample_test.py new file mode 100644 index 0000000000..4432310476 --- /dev/null +++ b/samples/snippets/feature_store_service/batch_read_feature_values_sample_test.py @@ -0,0 +1,70 @@ +# 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 +# +# 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 datetime import datetime +import os + +import batch_read_feature_values_sample +from google.cloud import bigquery + +import pytest + +PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") +LOCATION = "us-central1" +INPUT_CSV_FILE = "gs://cloud-samples-data-us-central1/vertex-ai/feature-store/datasets/movie_prediction_perm.csv" + + +@pytest.fixture(scope="function", autouse=True) +def teardown(teardown_batch_read_feature_values): + yield + + +def setup_test(): + # Output dataset + destination_data_set = "movie_predictions_" + datetime.now().strftime( + "%Y%m%d%H%M%S" + ) + # Output table. Make sure that the table does NOT already exist, the + # BatchReadFeatureValues API cannot overwrite an existing table. + destination_table_name = "training_data" + DESTINATION_PATTERN = "bq://{project}.{dataset}.{table}" + destination_table_uri = DESTINATION_PATTERN.format( + project=PROJECT_ID, dataset=destination_data_set, table=destination_table_name + ) + # Create dataset + bq_client = bigquery.Client(project=PROJECT_ID) + dataset_id = "{}.{}".format(bq_client.project, destination_data_set) + dataset = bigquery.Dataset(dataset_id) + dataset.location = LOCATION + dataset = bq_client.create_dataset(dataset) + print("Created dataset {}.{}".format(bq_client.project, dataset.dataset_id)) + return destination_data_set, destination_table_uri + + +def test_ucaip_generated_batch_read_feature_values_sample_vision(capsys, shared_state): + destination_data_set, destination_table_uri = setup_test() + featurestore_id = "perm_sample_featurestore" + + batch_read_feature_values_sample.batch_read_feature_values_sample( + project=PROJECT_ID, + featurestore_id=featurestore_id, + input_csv_file=INPUT_CSV_FILE, + destination_table_uri=destination_table_uri, + ) + out, _ = capsys.readouterr() + assert "batch_read_feature_values_response" in out + with capsys.disabled(): + print(out) + + shared_state["destination_data_set"] = destination_data_set diff --git a/samples/snippets/feature_store_service/create_entity_type_sample.py b/samples/snippets/feature_store_service/create_entity_type_sample.py new file mode 100644 index 0000000000..d650b396cc --- /dev/null +++ b/samples/snippets/feature_store_service/create_entity_type_sample.py @@ -0,0 +1,50 @@ +# 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. + +# Create an entity type so that you can create its related features. +# See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running +# the code snippet + +# [START aiplatform_create_entity_type_sample] +from google.cloud import aiplatform + + +def create_entity_type_sample( + project: str, + featurestore_id: str, + entity_type_id: str, + description: str = "sample entity type", + location: str = "us-central1", + api_endpoint: str = "us-central1-aiplatform.googleapis.com", + timeout: int = 300, +): + # The AI Platform services require regional API endpoints, which need to be + # in the same region or multi-region overlap with the Feature Store location. + client_options = {"api_endpoint": api_endpoint} + # Initialize client that will be used to create and send requests. + # This client only needs to be created once, and can be reused for multiple requests. + client = aiplatform.gapic.FeaturestoreServiceClient(client_options=client_options) + parent = f"projects/{project}/locations/{location}/featurestores/{featurestore_id}" + create_entity_type_request = aiplatform.gapic.CreateEntityTypeRequest( + parent=parent, + entity_type_id=entity_type_id, + entity_type=aiplatform.gapic.EntityType(description=description), + ) + lro_response = client.create_entity_type(request=create_entity_type_request) + print("Long running operation:", lro_response.operation.name) + create_entity_type_response = lro_response.result(timeout=timeout) + print("create_entity_type_response:", create_entity_type_response) + + +# [END aiplatform_create_entity_type_sample] diff --git a/samples/snippets/feature_store_service/create_entity_type_sample_test.py b/samples/snippets/feature_store_service/create_entity_type_sample_test.py new file mode 100644 index 0000000000..a2311cfe28 --- /dev/null +++ b/samples/snippets/feature_store_service/create_entity_type_sample_test.py @@ -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 +# +# 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. + +import os +from uuid import uuid4 + +import create_entity_type_sample +import pytest + +import helpers + +PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") + + +@pytest.fixture(scope="function", autouse=True) +def teardown(teardown_entity_type): + yield + + +def test_ucaip_generated_create_entity_type_sample_vision(capsys, shared_state): + featurestore_id = "perm_sample_featurestore" + entity_type_id = f"temp_create_entity_type_test_{uuid4()}".replace("-", "_")[:60] + create_entity_type_sample.create_entity_type_sample( + project=PROJECT_ID, + featurestore_id=featurestore_id, + entity_type_id=entity_type_id, + ) + out, _ = capsys.readouterr() + assert "create_entity_type_response" in out + + shared_state["entity_type_name"] = helpers.get_featurestore_resource_name(out) diff --git a/samples/snippets/feature_store_service/create_feature_sample.py b/samples/snippets/feature_store_service/create_feature_sample.py new file mode 100644 index 0000000000..9475c01de2 --- /dev/null +++ b/samples/snippets/feature_store_service/create_feature_sample.py @@ -0,0 +1,54 @@ +# 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. + +# Create a single feature for an existing entity type. +# See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running +# the code snippet + +# [START aiplatform_create_feature_sample] +from google.cloud import aiplatform + + +def create_feature_sample( + project: str, + featurestore_id: str, + entity_type_id: str, + feature_id: str, + value_type: aiplatform.gapic.Feature.ValueType, + description: str = "sample feature", + location: str = "us-central1", + api_endpoint: str = "us-central1-aiplatform.googleapis.com", + timeout: int = 300, +): + # The AI Platform services require regional API endpoints, which need to be + # in the same region or multi-region overlap with the Feature Store location. + client_options = {"api_endpoint": api_endpoint} + # Initialize client that will be used to create and send requests. + # This client only needs to be created once, and can be reused for multiple requests. + client = aiplatform.gapic.FeaturestoreServiceClient(client_options=client_options) + parent = f"projects/{project}/locations/{location}/featurestores/{featurestore_id}/entityTypes/{entity_type_id}" + create_feature_request = aiplatform.gapic.CreateFeatureRequest( + parent=parent, + feature=aiplatform.gapic.Feature( + value_type=value_type, description=description + ), + feature_id=feature_id, + ) + lro_response = client.create_feature(request=create_feature_request) + print("Long running operation:", lro_response.operation.name) + create_feature_response = lro_response.result(timeout=timeout) + print("create_feature_response:", create_feature_response) + + +# [END aiplatform_create_feature_sample] diff --git a/samples/snippets/feature_store_service/create_feature_sample_test.py b/samples/snippets/feature_store_service/create_feature_sample_test.py new file mode 100644 index 0000000000..d1af2f34a4 --- /dev/null +++ b/samples/snippets/feature_store_service/create_feature_sample_test.py @@ -0,0 +1,46 @@ +# 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 +# +# 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. + +import os +from uuid import uuid4 + +import create_feature_sample +from google.cloud import aiplatform_v1beta1 as aiplatform +import pytest + +import helpers + +PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") + + +@pytest.fixture(scope="function", autouse=True) +def teardown(teardown_feature): + yield + + +def test_ucaip_generated_create_feature_sample_vision(capsys, shared_state): + featurestore_id = "perm_sample_featurestore" + entity_type_id = "perm_sample_entity_type" + feature_id = f"temp_create_feature_test_{uuid4()}".replace("-", "_")[:60] + create_feature_sample.create_feature_sample( + project=PROJECT_ID, + featurestore_id=featurestore_id, + entity_type_id=entity_type_id, + feature_id=feature_id, + value_type=aiplatform.Feature.ValueType.INT64, + ) + out, _ = capsys.readouterr() + assert "create_feature_response" in out + + shared_state["feature_name"] = helpers.get_featurestore_resource_name(out) diff --git a/samples/snippets/feature_store_service/create_featurestore_sample.py b/samples/snippets/feature_store_service/create_featurestore_sample.py new file mode 100644 index 0000000000..efd57cc8cb --- /dev/null +++ b/samples/snippets/feature_store_service/create_featurestore_sample.py @@ -0,0 +1,53 @@ +# 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. + +# Create a featurestore resource to contain entity types and features. +# See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running +# the code snippet + +# [START aiplatform_create_featurestore_sample] +from google.cloud import aiplatform + + +def create_featurestore_sample( + project: str, + featurestore_id: str, + fixed_node_count: int = 1, + location: str = "us-central1", + api_endpoint: str = "us-central1-aiplatform.googleapis.com", + timeout: int = 300, +): + # The AI Platform services require regional API endpoints, which need to be + # in the same region or multi-region overlap with the Feature Store location. + client_options = {"api_endpoint": api_endpoint} + # Initialize client that will be used to create and send requests. + # This client only needs to be created once, and can be reused for multiple requests. + client = aiplatform.gapic.FeaturestoreServiceClient(client_options=client_options) + parent = f"projects/{project}/locations/{location}" + create_featurestore_request = aiplatform.gapic.CreateFeaturestoreRequest( + parent=parent, + featurestore_id=featurestore_id, + featurestore=aiplatform.gapic.Featurestore( + online_serving_config=aiplatform.gapic.Featurestore.OnlineServingConfig( + fixed_node_count=fixed_node_count, + ), + ), + ) + lro_response = client.create_featurestore(request=create_featurestore_request) + print("Long running operation:", lro_response.operation.name) + create_featurestore_response = lro_response.result(timeout=timeout) + print("create_featurestore_response:", create_featurestore_response) + + +# [END aiplatform_create_featurestore_sample] diff --git a/samples/snippets/feature_store_service/create_featurestore_sample_test.py b/samples/snippets/feature_store_service/create_featurestore_sample_test.py new file mode 100644 index 0000000000..0de26762e1 --- /dev/null +++ b/samples/snippets/feature_store_service/create_featurestore_sample_test.py @@ -0,0 +1,39 @@ +# 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 +# +# 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. + +import os +from uuid import uuid4 + +import create_featurestore_sample +import pytest + +import helpers + +PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") + + +@pytest.fixture(scope="function", autouse=True) +def teardown(teardown_featurestore): + yield + + +def test_ucaip_generated_create_featurestore_sample_vision(capsys, shared_state): + featurestore_id = f"temp_create_featurestore_test_{uuid4()}".replace("-", "_")[:60] + create_featurestore_sample.create_featurestore_sample( + project=PROJECT_ID, featurestore_id=featurestore_id, fixed_node_count=1 + ) + out, _ = capsys.readouterr() + assert "create_featurestore_response" in out + + shared_state["featurestore_name"] = helpers.get_featurestore_resource_name(out) diff --git a/samples/snippets/feature_store_service/delete_featurestore_sample.py b/samples/snippets/feature_store_service/delete_featurestore_sample.py new file mode 100644 index 0000000000..b893ff44f3 --- /dev/null +++ b/samples/snippets/feature_store_service/delete_featurestore_sample.py @@ -0,0 +1,45 @@ +# 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. + +# Delete a featurestore. +# See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running +# the code snippet + +# [START aiplatform_delete_featurestore_sample] +from google.cloud import aiplatform + + +def delete_featurestore_sample( + project: str, + featurestore_id: str, + location: str = "us-central1", + api_endpoint: str = "us-central1-aiplatform.googleapis.com", + timeout: int = 300, +): + # The AI Platform services require regional API endpoints, which need to be + # in the same region or multi-region overlap with the Feature Store location. + client_options = {"api_endpoint": api_endpoint} + # Initialize client that will be used to create and send requests. + # This client only needs to be created once, and can be reused for multiple requests. + client = aiplatform.gapic.FeaturestoreServiceClient(client_options=client_options) + name = client.featurestore_path( + project=project, location=location, featurestore=featurestore_id + ) + response = client.delete_featurestore(name=name) + print("Long running operation:", response.operation.name) + delete_featurestore_response = response.result(timeout=timeout) + print("delete_featurestore_response:", delete_featurestore_response) + + +# [END aiplatform_delete_featurestore_sample] diff --git a/samples/snippets/feature_store_service/delete_featurestore_sample_test.py b/samples/snippets/feature_store_service/delete_featurestore_sample_test.py new file mode 100644 index 0000000000..ef09095d9a --- /dev/null +++ b/samples/snippets/feature_store_service/delete_featurestore_sample_test.py @@ -0,0 +1,45 @@ +# 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 +# +# 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. + +import os +from uuid import uuid4 + +import create_featurestore_sample +import delete_featurestore_sample +import pytest + +PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") + + +@pytest.fixture(scope="function", autouse=True) +def teardown(): + yield + + +def setup_test(capsys, featurestore_id): + create_featurestore_sample.create_featurestore_sample( + project=PROJECT_ID, featurestore_id=featurestore_id, fixed_node_count=1 + ) + out, _ = capsys.readouterr() + assert "create_featurestore_response" in out + + +def test_ucaip_generated_delete_featurestore_sample_vision(capsys, shared_state): + featurestore_id = f"temp_create_featurestore_test_{uuid4()}".replace("-", "_")[:60] + setup_test(capsys, featurestore_id) + delete_featurestore_sample.delete_featurestore_sample( + project=PROJECT_ID, featurestore_id=featurestore_id + ) + out, _ = capsys.readouterr() + assert "delete_featurestore_response" in out diff --git a/samples/snippets/feature_store_service/import_feature_values_sample.py b/samples/snippets/feature_store_service/import_feature_values_sample.py new file mode 100644 index 0000000000..f06c76de04 --- /dev/null +++ b/samples/snippets/feature_store_service/import_feature_values_sample.py @@ -0,0 +1,64 @@ +# 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. + +# Bulk import values into a featurestore for existing features. +# See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running +# the code snippet + +# [START aiplatform_import_feature_values_sample] +from google.cloud import aiplatform + + +def import_feature_values_sample( + project: str, + featurestore_id: str, + entity_type_id: str, + avro_gcs_uri: str, + entity_id_field: str, + feature_time_field: str, + worker_count: int = 2, + location: str = "us-central1", + api_endpoint: str = "us-central1-aiplatform.googleapis.com", + timeout: int = 300, +): + # The AI Platform services require regional API endpoints, which need to be + # in the same region or multi-region overlap with the Feature Store location. + client_options = {"api_endpoint": api_endpoint} + # Initialize client that will be used to create and send requests. + # This client only needs to be created once, and can be reused for multiple requests. + client = aiplatform.gapic.FeaturestoreServiceClient(client_options=client_options) + entity_type = f"projects/{project}/locations/{location}/featurestores/{featurestore_id}/entityTypes/{entity_type_id}" + avro_source = aiplatform.gapic.AvroSource( + gcs_source=aiplatform.gapic.GcsSource(uris=[avro_gcs_uri]) + ) + feature_specs = [ + aiplatform.gapic.ImportFeatureValuesRequest.FeatureSpec(id="age"), + aiplatform.gapic.ImportFeatureValuesRequest.FeatureSpec(id="gender"), + aiplatform.gapic.ImportFeatureValuesRequest.FeatureSpec(id="liked_genres"), + ] + import_feature_values_request = aiplatform.gapic.ImportFeatureValuesRequest( + entity_type=entity_type, + avro_source=avro_source, + feature_specs=feature_specs, + entity_id_field=entity_id_field, + feature_time_field=feature_time_field, + worker_count=worker_count, + ) + lro_response = client.import_feature_values(request=import_feature_values_request) + print("Long running operation:", lro_response.operation.name) + import_feature_values_response = lro_response.result(timeout=timeout) + print("import_feature_values_response:", import_feature_values_response) + + +# [END aiplatform_import_feature_values_sample] diff --git a/samples/snippets/feature_store_service/import_feature_values_sample_test.py b/samples/snippets/feature_store_service/import_feature_values_sample_test.py new file mode 100644 index 0000000000..c7f927cc97 --- /dev/null +++ b/samples/snippets/feature_store_service/import_feature_values_sample_test.py @@ -0,0 +1,77 @@ +# 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 +# +# 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. + +import os +from uuid import uuid4 + +import batch_create_features_sample +import create_entity_type_sample +import import_feature_values_sample +import pytest + +import helpers + +PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") +AVRO_GCS_URI = ( + "gs://cloud-samples-data-us-central1/vertex-ai/feature-store/datasets/users.avro" +) + + +@pytest.fixture(scope="function", autouse=True) +def teardown(teardown_entity_type): + yield + + +def setup_features(featurestore_id, entity_type_id, capsys): + batch_create_features_sample.batch_create_features_sample( + project=PROJECT_ID, + featurestore_id=featurestore_id, + entity_type_id=entity_type_id, + ) + out, _ = capsys.readouterr() + assert "batch_create_features_response" in out + + +def setup_temp_entity_type(featurestore_id, entity_type_id, capsys): + create_entity_type_sample.create_entity_type_sample( + project=PROJECT_ID, + featurestore_id=featurestore_id, + entity_type_id=entity_type_id, + ) + out, _ = capsys.readouterr() + assert "create_entity_type_response" in out + return helpers.get_featurestore_resource_name(out) + + +def test_ucaip_generated_import_feature_values_sample_vision(capsys, shared_state): + featurestore_id = "perm_sample_featurestore" + entity_type_id = f"users_{uuid4()}".replace("-", "_")[:60] + entity_type_name = setup_temp_entity_type(featurestore_id, entity_type_id, capsys) + setup_features(featurestore_id, entity_type_id, capsys) + + import_feature_values_sample.import_feature_values_sample( + project=PROJECT_ID, + featurestore_id=featurestore_id, + entity_type_id=entity_type_id, + avro_gcs_uri=AVRO_GCS_URI, + entity_id_field="user_id", + feature_time_field="update_time", + worker_count=2, + timeout=60 * 30, + ) + + out, _ = capsys.readouterr() + assert "imported_feature_value_count: 12" in out + + shared_state["entity_type_name"] = entity_type_name diff --git a/samples/snippets/feature_store_service/read_feature_values_sample.py b/samples/snippets/feature_store_service/read_feature_values_sample.py new file mode 100644 index 0000000000..6a67bb2f6d --- /dev/null +++ b/samples/snippets/feature_store_service/read_feature_values_sample.py @@ -0,0 +1,52 @@ +# 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. + +# Serve feature values from a single entity for a particular entity type. +# See https://cloud.google.com/vertex-ai/docs/featurestore/setup before running +# the code snippet + +# [START aiplatform_read_feature_values_sample] +from google.cloud import aiplatform + + +def read_feature_values_sample( + project: str, + featurestore_id: str, + entity_type_id: str, + entity_id: str, + location: str = "us-central1", + api_endpoint: str = "us-central1-aiplatform.googleapis.com", +): + # The AI Platform services require regional API endpoints, which need to be + # in the same region or multi-region overlap with the Feature Store location. + client_options = {"api_endpoint": api_endpoint} + # Initialize client that will be used to create and send requests. + # This client only needs to be created once, and can be reused for multiple requests. + client = aiplatform.gapic.FeaturestoreOnlineServingServiceClient( + client_options=client_options + ) + entity_type = f"projects/{project}/locations/{location}/featurestores/{featurestore_id}/entityTypes/{entity_type_id}" + feature_selector = aiplatform.gapic.FeatureSelector( + id_matcher=aiplatform.gapic.IdMatcher(ids=["age", "gender", "liked_genres"]) + ) + read_feature_values_request = aiplatform.gapic.ReadFeatureValuesRequest( + entity_type=entity_type, entity_id=entity_id, feature_selector=feature_selector + ) + read_feature_values_response = client.read_feature_values( + request=read_feature_values_request + ) + print("read_feature_values_response:", read_feature_values_response) + + +# [END aiplatform_read_feature_values_sample] diff --git a/samples/snippets/feature_store_service/read_feature_values_sample_test.py b/samples/snippets/feature_store_service/read_feature_values_sample_test.py new file mode 100644 index 0000000000..5a15ff9b32 --- /dev/null +++ b/samples/snippets/feature_store_service/read_feature_values_sample_test.py @@ -0,0 +1,38 @@ +# 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 +# +# 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. + +import os + +import pytest +import read_feature_values_sample + +PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") + + +@pytest.fixture(scope="function", autouse=True) +def teardown(): + yield + + +def test_ucaip_generated_read_feature_values_sample_vision(capsys, shared_state): + featurestore_id = "perm_sample_featurestore" + entity_type_id = "perm_users" + read_feature_values_sample.read_feature_values_sample( + project=PROJECT_ID, + featurestore_id=featurestore_id, + entity_type_id=entity_type_id, + entity_id="alice", + ) + out, _ = capsys.readouterr() + assert "int64_value: 55" in out diff --git a/samples/snippets/helpers.py b/samples/snippets/helpers.py index d86da0238c..4a9b50719f 100644 --- a/samples/snippets/helpers.py +++ b/samples/snippets/helpers.py @@ -1,5 +1,24 @@ +# -*- coding: utf-8 -*- + +# Copyright 2022 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. +# + +import collections import re import time +from timeit import default_timer as timer from typing import Callable @@ -18,6 +37,13 @@ def get_state(out): return state +def get_featurestore_resource_name(out, key="name"): + pattern = re.compile(fr'{key}:\s*"([\_\-a-zA-Z0-9/]+)"') + name = re.search(pattern, out).group(1) + + return name + + def wait_for_job_state( get_job_method: Callable[[str], "proto.Message"], # noqa: F821 name: str, @@ -56,3 +82,21 @@ def wait_for_job_state( "\nTry increasing the timeout in sample test" f"\nLast recorded state: {response.state}" ) + + +def flaky_test_diagnostic(file_name, test_name, N=20): + + import pytest + + timing_dict = collections.defaultdict(list) + for ri in range(N): + start = timer() + result = pytest.main(['-s', f'{file_name}::{test_name}']) + end = timer() + delta = end-start + if result == pytest.ExitCode.OK: + timing_dict['SUCCESS'].append(delta) + else: + timing_dict['FAILURE'].append(delta) + + return timing_dict diff --git a/samples/snippets/cancel_batch_prediction_job_sample.py b/samples/snippets/job_service/cancel_batch_prediction_job_sample.py similarity index 100% rename from samples/snippets/cancel_batch_prediction_job_sample.py rename to samples/snippets/job_service/cancel_batch_prediction_job_sample.py diff --git a/samples/snippets/cancel_custom_job_sample.py b/samples/snippets/job_service/cancel_custom_job_sample.py similarity index 100% rename from samples/snippets/cancel_custom_job_sample.py rename to samples/snippets/job_service/cancel_custom_job_sample.py diff --git a/samples/snippets/cancel_data_labeling_job_sample.py b/samples/snippets/job_service/cancel_data_labeling_job_sample.py similarity index 100% rename from samples/snippets/cancel_data_labeling_job_sample.py rename to samples/snippets/job_service/cancel_data_labeling_job_sample.py diff --git a/samples/snippets/cancel_hyperparameter_tuning_job_sample.py b/samples/snippets/job_service/cancel_hyperparameter_tuning_job_sample.py similarity index 100% rename from samples/snippets/cancel_hyperparameter_tuning_job_sample.py rename to samples/snippets/job_service/cancel_hyperparameter_tuning_job_sample.py diff --git a/samples/snippets/create_batch_prediction_job_bigquery_sample.py b/samples/snippets/job_service/create_batch_prediction_job_bigquery_sample.py similarity index 100% rename from samples/snippets/create_batch_prediction_job_bigquery_sample.py rename to samples/snippets/job_service/create_batch_prediction_job_bigquery_sample.py diff --git a/samples/snippets/create_batch_prediction_job_bigquery_sample_test.py b/samples/snippets/job_service/create_batch_prediction_job_bigquery_sample_test.py similarity index 100% rename from samples/snippets/create_batch_prediction_job_bigquery_sample_test.py rename to samples/snippets/job_service/create_batch_prediction_job_bigquery_sample_test.py index d82217aea7..66ab41baef 100644 --- a/samples/snippets/create_batch_prediction_job_bigquery_sample_test.py +++ b/samples/snippets/job_service/create_batch_prediction_job_bigquery_sample_test.py @@ -15,9 +15,9 @@ import os from uuid import uuid4 +import create_batch_prediction_job_bigquery_sample import pytest -import create_batch_prediction_job_bigquery_sample import helpers PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") diff --git a/samples/snippets/create_batch_prediction_job_sample.py b/samples/snippets/job_service/create_batch_prediction_job_sample.py similarity index 100% rename from samples/snippets/create_batch_prediction_job_sample.py rename to samples/snippets/job_service/create_batch_prediction_job_sample.py diff --git a/samples/snippets/create_batch_prediction_job_sample_test.py b/samples/snippets/job_service/create_batch_prediction_job_sample_test.py similarity index 100% rename from samples/snippets/create_batch_prediction_job_sample_test.py rename to samples/snippets/job_service/create_batch_prediction_job_sample_test.py index 6690a11d0b..32148ae691 100644 --- a/samples/snippets/create_batch_prediction_job_sample_test.py +++ b/samples/snippets/job_service/create_batch_prediction_job_sample_test.py @@ -15,9 +15,9 @@ import os from uuid import uuid4 +import create_batch_prediction_job_sample import pytest -import create_batch_prediction_job_sample import helpers PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") diff --git a/samples/snippets/create_batch_prediction_job_tabular_forecasting_sample.py b/samples/snippets/job_service/create_batch_prediction_job_tabular_forecasting_sample.py similarity index 100% rename from samples/snippets/create_batch_prediction_job_tabular_forecasting_sample.py rename to samples/snippets/job_service/create_batch_prediction_job_tabular_forecasting_sample.py diff --git a/samples/snippets/create_batch_prediction_job_tabular_forecasting_sample_test.py b/samples/snippets/job_service/create_batch_prediction_job_tabular_forecasting_sample_test.py similarity index 95% rename from samples/snippets/create_batch_prediction_job_tabular_forecasting_sample_test.py rename to samples/snippets/job_service/create_batch_prediction_job_tabular_forecasting_sample_test.py index f992cc575e..04eb3ede36 100644 --- a/samples/snippets/create_batch_prediction_job_tabular_forecasting_sample_test.py +++ b/samples/snippets/job_service/create_batch_prediction_job_tabular_forecasting_sample_test.py @@ -15,9 +15,9 @@ import os from uuid import uuid4 +import create_batch_prediction_job_tabular_forecasting_sample import pytest -import create_batch_prediction_job_tabular_forecasting_sample import helpers PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") @@ -34,6 +34,7 @@ def teardown(teardown_batch_prediction_job): yield +@pytest.mark.skip(reason="https://github.com/googleapis/java-aiplatform/issues/420") # Creating AutoML Tabular Forecasting Classification batch prediction job def test_create_batch_prediction_job_tabular_forecasting_sample(capsys, shared_state): diff --git a/samples/snippets/create_batch_prediction_job_text_classification_sample.py b/samples/snippets/job_service/create_batch_prediction_job_text_classification_sample.py similarity index 100% rename from samples/snippets/create_batch_prediction_job_text_classification_sample.py rename to samples/snippets/job_service/create_batch_prediction_job_text_classification_sample.py diff --git a/samples/snippets/create_batch_prediction_job_text_classification_sample_test.py b/samples/snippets/job_service/create_batch_prediction_job_text_classification_sample_test.py similarity index 95% rename from samples/snippets/create_batch_prediction_job_text_classification_sample_test.py rename to samples/snippets/job_service/create_batch_prediction_job_text_classification_sample_test.py index 2561facac8..c35f8b572c 100644 --- a/samples/snippets/create_batch_prediction_job_text_classification_sample_test.py +++ b/samples/snippets/job_service/create_batch_prediction_job_text_classification_sample_test.py @@ -15,9 +15,9 @@ import os from uuid import uuid4 +import create_batch_prediction_job_text_classification_sample import pytest -import create_batch_prediction_job_text_classification_sample import helpers PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") @@ -35,6 +35,7 @@ def teardown(teardown_batch_prediction_job): yield +@pytest.mark.skip(reason="https://github.com/googleapis/java-aiplatform/issues/420") # Creating AutoML Text Classification batch prediction job def test_ucaip_generated_create_batch_prediction_tcn_sample(capsys, shared_state): diff --git a/samples/snippets/create_batch_prediction_job_text_entity_extraction_sample.py b/samples/snippets/job_service/create_batch_prediction_job_text_entity_extraction_sample.py similarity index 100% rename from samples/snippets/create_batch_prediction_job_text_entity_extraction_sample.py rename to samples/snippets/job_service/create_batch_prediction_job_text_entity_extraction_sample.py diff --git a/samples/snippets/create_batch_prediction_job_text_entity_extraction_sample_test.py b/samples/snippets/job_service/create_batch_prediction_job_text_entity_extraction_sample_test.py similarity index 95% rename from samples/snippets/create_batch_prediction_job_text_entity_extraction_sample_test.py rename to samples/snippets/job_service/create_batch_prediction_job_text_entity_extraction_sample_test.py index d7e6469715..643f16ec90 100644 --- a/samples/snippets/create_batch_prediction_job_text_entity_extraction_sample_test.py +++ b/samples/snippets/job_service/create_batch_prediction_job_text_entity_extraction_sample_test.py @@ -15,9 +15,9 @@ import os from uuid import uuid4 +import create_batch_prediction_job_text_entity_extraction_sample import pytest -import create_batch_prediction_job_text_entity_extraction_sample import helpers PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") @@ -35,6 +35,7 @@ def teardown(teardown_batch_prediction_job): yield +@pytest.mark.skip(reason="https://github.com/googleapis/java-aiplatform/issues/420") # Creating AutoML Text Entity Extraction batch prediction job def test_ucaip_generated_create_batch_prediction_ten_sample(capsys, shared_state): diff --git a/samples/snippets/create_batch_prediction_job_text_sentiment_analysis_sample.py b/samples/snippets/job_service/create_batch_prediction_job_text_sentiment_analysis_sample.py similarity index 100% rename from samples/snippets/create_batch_prediction_job_text_sentiment_analysis_sample.py rename to samples/snippets/job_service/create_batch_prediction_job_text_sentiment_analysis_sample.py diff --git a/samples/snippets/create_batch_prediction_job_text_sentiment_analysis_sample_test.py b/samples/snippets/job_service/create_batch_prediction_job_text_sentiment_analysis_sample_test.py similarity index 95% rename from samples/snippets/create_batch_prediction_job_text_sentiment_analysis_sample_test.py rename to samples/snippets/job_service/create_batch_prediction_job_text_sentiment_analysis_sample_test.py index 9695873668..d56a58070f 100644 --- a/samples/snippets/create_batch_prediction_job_text_sentiment_analysis_sample_test.py +++ b/samples/snippets/job_service/create_batch_prediction_job_text_sentiment_analysis_sample_test.py @@ -15,9 +15,9 @@ import os from uuid import uuid4 +import create_batch_prediction_job_text_sentiment_analysis_sample import pytest -import create_batch_prediction_job_text_sentiment_analysis_sample import helpers PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") @@ -35,6 +35,7 @@ def teardown(teardown_batch_prediction_job): yield +@pytest.mark.skip(reason="https://github.com/googleapis/java-aiplatform/issues/420") # Creating AutoML Text Sentiment Analysis batch prediction job def test_ucaip_generated_create_batch_prediction_tsn_sample(capsys, shared_state): diff --git a/samples/snippets/create_batch_prediction_job_video_action_recognition_sample.py b/samples/snippets/job_service/create_batch_prediction_job_video_action_recognition_sample.py similarity index 100% rename from samples/snippets/create_batch_prediction_job_video_action_recognition_sample.py rename to samples/snippets/job_service/create_batch_prediction_job_video_action_recognition_sample.py diff --git a/samples/snippets/create_batch_prediction_job_video_action_recognition_sample_test.py b/samples/snippets/job_service/create_batch_prediction_job_video_action_recognition_sample_test.py similarity index 95% rename from samples/snippets/create_batch_prediction_job_video_action_recognition_sample_test.py rename to samples/snippets/job_service/create_batch_prediction_job_video_action_recognition_sample_test.py index d2295cd0c8..94a75c2906 100644 --- a/samples/snippets/create_batch_prediction_job_video_action_recognition_sample_test.py +++ b/samples/snippets/job_service/create_batch_prediction_job_video_action_recognition_sample_test.py @@ -15,9 +15,9 @@ import os import uuid +import create_batch_prediction_job_video_action_recognition_sample import pytest -import create_batch_prediction_job_video_action_recognition_sample import helpers PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") @@ -35,6 +35,7 @@ def teardown(teardown_batch_prediction_job): yield +@pytest.mark.skip(reason="https://github.com/googleapis/java-aiplatform/issues/420") # Creating AutoML Video Object Tracking batch prediction job def test_create_batch_prediction_job_video_action_recognition_sample( capsys, shared_state, job_client diff --git a/samples/snippets/create_batch_prediction_job_video_classification_sample.py b/samples/snippets/job_service/create_batch_prediction_job_video_classification_sample.py similarity index 100% rename from samples/snippets/create_batch_prediction_job_video_classification_sample.py rename to samples/snippets/job_service/create_batch_prediction_job_video_classification_sample.py diff --git a/samples/snippets/create_batch_prediction_job_video_classification_sample_test.py b/samples/snippets/job_service/create_batch_prediction_job_video_classification_sample_test.py similarity index 95% rename from samples/snippets/create_batch_prediction_job_video_classification_sample_test.py rename to samples/snippets/job_service/create_batch_prediction_job_video_classification_sample_test.py index c3bd6e24a1..a47af0da52 100644 --- a/samples/snippets/create_batch_prediction_job_video_classification_sample_test.py +++ b/samples/snippets/job_service/create_batch_prediction_job_video_classification_sample_test.py @@ -15,9 +15,9 @@ import os from uuid import uuid4 +import create_batch_prediction_job_video_classification_sample import pytest -import create_batch_prediction_job_video_classification_sample import helpers PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") @@ -35,6 +35,7 @@ def teardown(teardown_batch_prediction_job): yield +@pytest.mark.skip(reason="https://github.com/googleapis/java-aiplatform/issues/420") # Creating AutoML Video Classification batch prediction job def test_ucaip_generated_create_batch_prediction_vcn_sample(capsys, shared_state): diff --git a/samples/snippets/create_batch_prediction_job_video_object_tracking_sample.py b/samples/snippets/job_service/create_batch_prediction_job_video_object_tracking_sample.py similarity index 100% rename from samples/snippets/create_batch_prediction_job_video_object_tracking_sample.py rename to samples/snippets/job_service/create_batch_prediction_job_video_object_tracking_sample.py diff --git a/samples/snippets/create_batch_prediction_job_video_object_tracking_sample_test.py b/samples/snippets/job_service/create_batch_prediction_job_video_object_tracking_sample_test.py similarity index 95% rename from samples/snippets/create_batch_prediction_job_video_object_tracking_sample_test.py rename to samples/snippets/job_service/create_batch_prediction_job_video_object_tracking_sample_test.py index 12426af11b..42cdb31023 100644 --- a/samples/snippets/create_batch_prediction_job_video_object_tracking_sample_test.py +++ b/samples/snippets/job_service/create_batch_prediction_job_video_object_tracking_sample_test.py @@ -15,9 +15,9 @@ import os from uuid import uuid4 +import create_batch_prediction_job_video_object_tracking_sample import pytest -import create_batch_prediction_job_video_object_tracking_sample import helpers PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") @@ -35,6 +35,7 @@ def teardown(teardown_batch_prediction_job): yield +@pytest.mark.skip(reason="https://github.com/googleapis/java-aiplatform/issues/420") # Creating AutoML Video Object Tracking batch prediction job def test_ucaip_generated_create_batch_prediction_vcn_sample(capsys, shared_state): diff --git a/samples/snippets/create_custom_job_sample.py b/samples/snippets/job_service/create_custom_job_sample.py similarity index 100% rename from samples/snippets/create_custom_job_sample.py rename to samples/snippets/job_service/create_custom_job_sample.py diff --git a/samples/snippets/create_custom_job_sample_test.py b/samples/snippets/job_service/create_custom_job_sample_test.py similarity index 100% rename from samples/snippets/create_custom_job_sample_test.py rename to samples/snippets/job_service/create_custom_job_sample_test.py index 0a29132cdc..c067983913 100644 --- a/samples/snippets/create_custom_job_sample_test.py +++ b/samples/snippets/job_service/create_custom_job_sample_test.py @@ -16,9 +16,9 @@ import os import uuid +import create_custom_job_sample import pytest -import create_custom_job_sample import helpers PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") diff --git a/samples/snippets/create_data_labeling_job_active_learning_sample.py b/samples/snippets/job_service/create_data_labeling_job_active_learning_sample.py similarity index 100% rename from samples/snippets/create_data_labeling_job_active_learning_sample.py rename to samples/snippets/job_service/create_data_labeling_job_active_learning_sample.py diff --git a/samples/snippets/create_data_labeling_job_active_learning_sample_test.py b/samples/snippets/job_service/create_data_labeling_job_active_learning_sample_test.py similarity index 100% rename from samples/snippets/create_data_labeling_job_active_learning_sample_test.py rename to samples/snippets/job_service/create_data_labeling_job_active_learning_sample_test.py index 4ec5394535..ee264dbca2 100644 --- a/samples/snippets/create_data_labeling_job_active_learning_sample_test.py +++ b/samples/snippets/job_service/create_data_labeling_job_active_learning_sample_test.py @@ -15,9 +15,9 @@ import os import uuid +import create_data_labeling_job_active_learning_sample import pytest -import create_data_labeling_job_active_learning_sample import helpers API_ENDPOINT = os.getenv("DATA_LABELING_API_ENDPOINT") diff --git a/samples/snippets/create_data_labeling_job_image_segmentation_sample.py b/samples/snippets/job_service/create_data_labeling_job_image_segmentation_sample.py similarity index 100% rename from samples/snippets/create_data_labeling_job_image_segmentation_sample.py rename to samples/snippets/job_service/create_data_labeling_job_image_segmentation_sample.py diff --git a/samples/snippets/create_data_labeling_job_image_segmentation_sample_test.py b/samples/snippets/job_service/create_data_labeling_job_image_segmentation_sample_test.py similarity index 100% rename from samples/snippets/create_data_labeling_job_image_segmentation_sample_test.py rename to samples/snippets/job_service/create_data_labeling_job_image_segmentation_sample_test.py index e5f365d234..f0500d0bc9 100644 --- a/samples/snippets/create_data_labeling_job_image_segmentation_sample_test.py +++ b/samples/snippets/job_service/create_data_labeling_job_image_segmentation_sample_test.py @@ -15,9 +15,9 @@ import os import uuid +import create_data_labeling_job_image_segmentation_sample import pytest -import create_data_labeling_job_image_segmentation_sample import helpers API_ENDPOINT = os.getenv("DATA_LABELING_API_ENDPOINT") diff --git a/samples/snippets/create_data_labeling_job_images_sample.py b/samples/snippets/job_service/create_data_labeling_job_images_sample.py similarity index 100% rename from samples/snippets/create_data_labeling_job_images_sample.py rename to samples/snippets/job_service/create_data_labeling_job_images_sample.py diff --git a/samples/snippets/create_data_labeling_job_images_sample_test.py b/samples/snippets/job_service/create_data_labeling_job_images_sample_test.py similarity index 100% rename from samples/snippets/create_data_labeling_job_images_sample_test.py rename to samples/snippets/job_service/create_data_labeling_job_images_sample_test.py index 026a0fbd58..b56a377ea7 100644 --- a/samples/snippets/create_data_labeling_job_images_sample_test.py +++ b/samples/snippets/job_service/create_data_labeling_job_images_sample_test.py @@ -15,9 +15,9 @@ import os from uuid import uuid4 +import create_data_labeling_job_images_sample import pytest -import create_data_labeling_job_images_sample import helpers PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") diff --git a/samples/snippets/create_data_labeling_job_sample.py b/samples/snippets/job_service/create_data_labeling_job_sample.py similarity index 100% rename from samples/snippets/create_data_labeling_job_sample.py rename to samples/snippets/job_service/create_data_labeling_job_sample.py diff --git a/samples/snippets/create_data_labeling_job_sample_test.py b/samples/snippets/job_service/create_data_labeling_job_sample_test.py similarity index 100% rename from samples/snippets/create_data_labeling_job_sample_test.py rename to samples/snippets/job_service/create_data_labeling_job_sample_test.py index 847e452c0a..8b77950b84 100644 --- a/samples/snippets/create_data_labeling_job_sample_test.py +++ b/samples/snippets/job_service/create_data_labeling_job_sample_test.py @@ -15,9 +15,9 @@ import os from uuid import uuid4 +import create_data_labeling_job_sample import pytest -import create_data_labeling_job_sample import helpers PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") diff --git a/samples/snippets/create_data_labeling_job_specialist_pool_sample.py b/samples/snippets/job_service/create_data_labeling_job_specialist_pool_sample.py similarity index 100% rename from samples/snippets/create_data_labeling_job_specialist_pool_sample.py rename to samples/snippets/job_service/create_data_labeling_job_specialist_pool_sample.py diff --git a/samples/snippets/create_data_labeling_job_specialist_pool_sample_test.py b/samples/snippets/job_service/create_data_labeling_job_specialist_pool_sample_test.py similarity index 100% rename from samples/snippets/create_data_labeling_job_specialist_pool_sample_test.py rename to samples/snippets/job_service/create_data_labeling_job_specialist_pool_sample_test.py index 0f0f882c8c..7ae76a0550 100644 --- a/samples/snippets/create_data_labeling_job_specialist_pool_sample_test.py +++ b/samples/snippets/job_service/create_data_labeling_job_specialist_pool_sample_test.py @@ -15,9 +15,9 @@ import os import uuid +import create_data_labeling_job_specialist_pool_sample import pytest -import create_data_labeling_job_specialist_pool_sample import helpers API_ENDPOINT = os.getenv("DATA_LABELING_API_ENDPOINT") diff --git a/samples/snippets/create_data_labeling_job_video_sample.py b/samples/snippets/job_service/create_data_labeling_job_video_sample.py similarity index 100% rename from samples/snippets/create_data_labeling_job_video_sample.py rename to samples/snippets/job_service/create_data_labeling_job_video_sample.py diff --git a/samples/snippets/create_data_labeling_job_video_sample_test.py b/samples/snippets/job_service/create_data_labeling_job_video_sample_test.py similarity index 100% rename from samples/snippets/create_data_labeling_job_video_sample_test.py rename to samples/snippets/job_service/create_data_labeling_job_video_sample_test.py index 5d952ec552..6b38d8d65c 100644 --- a/samples/snippets/create_data_labeling_job_video_sample_test.py +++ b/samples/snippets/job_service/create_data_labeling_job_video_sample_test.py @@ -15,9 +15,9 @@ import os from uuid import uuid4 +import create_data_labeling_job_video_sample import pytest -import create_data_labeling_job_video_sample import helpers PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") diff --git a/samples/snippets/create_hyperparameter_tuning_job_python_package_sample.py b/samples/snippets/job_service/create_hyperparameter_tuning_job_python_package_sample.py similarity index 100% rename from samples/snippets/create_hyperparameter_tuning_job_python_package_sample.py rename to samples/snippets/job_service/create_hyperparameter_tuning_job_python_package_sample.py diff --git a/samples/snippets/create_hyperparameter_tuning_job_python_package_sample_test.py b/samples/snippets/job_service/create_hyperparameter_tuning_job_python_package_sample_test.py similarity index 95% rename from samples/snippets/create_hyperparameter_tuning_job_python_package_sample_test.py rename to samples/snippets/job_service/create_hyperparameter_tuning_job_python_package_sample_test.py index 7bb5ec5ac3..9e8538810a 100644 --- a/samples/snippets/create_hyperparameter_tuning_job_python_package_sample_test.py +++ b/samples/snippets/job_service/create_hyperparameter_tuning_job_python_package_sample_test.py @@ -15,9 +15,9 @@ import os import uuid +import create_hyperparameter_tuning_job_python_package_sample import pytest -import create_hyperparameter_tuning_job_python_package_sample import helpers PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") @@ -35,6 +35,7 @@ def teardown(teardown_hyperparameter_tuning_job): yield +@pytest.mark.skip(reason="https://github.com/googleapis/java-aiplatform/issues/420") def test_create_hyperparameter_tuning_job_python_package_sample(capsys, shared_state): create_hyperparameter_tuning_job_python_package_sample.create_hyperparameter_tuning_job_python_package_sample( diff --git a/samples/snippets/create_hyperparameter_tuning_job_sample.py b/samples/snippets/job_service/create_hyperparameter_tuning_job_sample.py similarity index 100% rename from samples/snippets/create_hyperparameter_tuning_job_sample.py rename to samples/snippets/job_service/create_hyperparameter_tuning_job_sample.py diff --git a/samples/snippets/create_hyperparameter_tuning_job_sample_test.py b/samples/snippets/job_service/create_hyperparameter_tuning_job_sample_test.py similarity index 100% rename from samples/snippets/create_hyperparameter_tuning_job_sample_test.py rename to samples/snippets/job_service/create_hyperparameter_tuning_job_sample_test.py index 9a16bdcb9c..63b1ac9be1 100644 --- a/samples/snippets/create_hyperparameter_tuning_job_sample_test.py +++ b/samples/snippets/job_service/create_hyperparameter_tuning_job_sample_test.py @@ -15,9 +15,9 @@ import os import uuid +import create_hyperparameter_tuning_job_sample import pytest -import create_hyperparameter_tuning_job_sample import helpers PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") diff --git a/samples/snippets/delete_batch_prediction_job_sample.py b/samples/snippets/job_service/delete_batch_prediction_job_sample.py similarity index 100% rename from samples/snippets/delete_batch_prediction_job_sample.py rename to samples/snippets/job_service/delete_batch_prediction_job_sample.py diff --git a/samples/snippets/delete_custom_job_sample.py b/samples/snippets/job_service/delete_custom_job_sample.py similarity index 100% rename from samples/snippets/delete_custom_job_sample.py rename to samples/snippets/job_service/delete_custom_job_sample.py diff --git a/samples/snippets/delete_data_labeling_job_sample.py b/samples/snippets/job_service/delete_data_labeling_job_sample.py similarity index 100% rename from samples/snippets/delete_data_labeling_job_sample.py rename to samples/snippets/job_service/delete_data_labeling_job_sample.py diff --git a/samples/snippets/delete_hyperparameter_tuning_job_sample.py b/samples/snippets/job_service/delete_hyperparameter_tuning_job_sample.py similarity index 100% rename from samples/snippets/delete_hyperparameter_tuning_job_sample.py rename to samples/snippets/job_service/delete_hyperparameter_tuning_job_sample.py diff --git a/samples/snippets/get_batch_prediction_job_sample.py b/samples/snippets/job_service/get_batch_prediction_job_sample.py similarity index 100% rename from samples/snippets/get_batch_prediction_job_sample.py rename to samples/snippets/job_service/get_batch_prediction_job_sample.py diff --git a/samples/snippets/get_custom_job_sample.py b/samples/snippets/job_service/get_custom_job_sample.py similarity index 100% rename from samples/snippets/get_custom_job_sample.py rename to samples/snippets/job_service/get_custom_job_sample.py diff --git a/samples/snippets/get_custom_job_sample_test.py b/samples/snippets/job_service/get_custom_job_sample_test.py similarity index 100% rename from samples/snippets/get_custom_job_sample_test.py rename to samples/snippets/job_service/get_custom_job_sample_test.py diff --git a/samples/snippets/get_hyperparameter_tuning_job_sample.py b/samples/snippets/job_service/get_hyperparameter_tuning_job_sample.py similarity index 100% rename from samples/snippets/get_hyperparameter_tuning_job_sample.py rename to samples/snippets/job_service/get_hyperparameter_tuning_job_sample.py diff --git a/samples/snippets/get_hyperparameter_tuning_job_sample_test.py b/samples/snippets/job_service/get_hyperparameter_tuning_job_sample_test.py similarity index 99% rename from samples/snippets/get_hyperparameter_tuning_job_sample_test.py rename to samples/snippets/job_service/get_hyperparameter_tuning_job_sample_test.py index 06ac1627e7..05845e0941 100644 --- a/samples/snippets/get_hyperparameter_tuning_job_sample_test.py +++ b/samples/snippets/job_service/get_hyperparameter_tuning_job_sample_test.py @@ -14,7 +14,6 @@ import os - import get_hyperparameter_tuning_job_sample PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") diff --git a/samples/snippets/delete_model_sample.py b/samples/snippets/model_service/delete_model_sample.py similarity index 100% rename from samples/snippets/delete_model_sample.py rename to samples/snippets/model_service/delete_model_sample.py diff --git a/samples/snippets/export_model_sample.py b/samples/snippets/model_service/export_model_sample.py similarity index 100% rename from samples/snippets/export_model_sample.py rename to samples/snippets/model_service/export_model_sample.py diff --git a/samples/snippets/export_model_sample_test.py b/samples/snippets/model_service/export_model_sample_test.py similarity index 100% rename from samples/snippets/export_model_sample_test.py rename to samples/snippets/model_service/export_model_sample_test.py index 67a625b657..6a8c0708f4 100644 --- a/samples/snippets/export_model_sample_test.py +++ b/samples/snippets/model_service/export_model_sample_test.py @@ -14,9 +14,9 @@ import os +import export_model_sample import pytest -import export_model_sample PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") MODEL_ID = ( diff --git a/samples/snippets/export_model_tabular_classification_sample.py b/samples/snippets/model_service/export_model_tabular_classification_sample.py similarity index 100% rename from samples/snippets/export_model_tabular_classification_sample.py rename to samples/snippets/model_service/export_model_tabular_classification_sample.py diff --git a/samples/snippets/export_model_tabular_classification_sample_test.py b/samples/snippets/model_service/export_model_tabular_classification_sample_test.py similarity index 94% rename from samples/snippets/export_model_tabular_classification_sample_test.py rename to samples/snippets/model_service/export_model_tabular_classification_sample_test.py index f74de8648c..52312c31eb 100644 --- a/samples/snippets/export_model_tabular_classification_sample_test.py +++ b/samples/snippets/model_service/export_model_tabular_classification_sample_test.py @@ -15,9 +15,9 @@ import os from uuid import uuid4 +import export_model_tabular_classification_sample import pytest -import export_model_tabular_classification_sample PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") MODEL_ID = "6036688272397172736" # iris 1000 @@ -35,6 +35,7 @@ def teardown(storage_client): blob.delete() +@pytest.mark.skip(reason="https://github.com/googleapis/java-aiplatform/issues/420") def test_ucaip_generated_export_model_tabular_classification_sample(capsys): export_model_tabular_classification_sample.export_model_tabular_classification_sample( project=PROJECT_ID, diff --git a/samples/snippets/export_model_video_action_recognition_sample.py b/samples/snippets/model_service/export_model_video_action_recognition_sample.py similarity index 100% rename from samples/snippets/export_model_video_action_recognition_sample.py rename to samples/snippets/model_service/export_model_video_action_recognition_sample.py diff --git a/samples/snippets/export_model_video_action_recognition_sample_test.py b/samples/snippets/model_service/export_model_video_action_recognition_sample_test.py similarity index 94% rename from samples/snippets/export_model_video_action_recognition_sample_test.py rename to samples/snippets/model_service/export_model_video_action_recognition_sample_test.py index c690c466e5..3efa50b363 100644 --- a/samples/snippets/export_model_video_action_recognition_sample_test.py +++ b/samples/snippets/model_service/export_model_video_action_recognition_sample_test.py @@ -14,9 +14,9 @@ import os +import export_model_video_action_recognition_sample import pytest -import export_model_video_action_recognition_sample PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") MODEL_ID = ( @@ -38,6 +38,7 @@ def teardown(storage_client): blob.delete() +@pytest.mark.skip(reason="https://github.com/googleapis/java-aiplatform/issues/420") def test_export_model_video_action_recognition_sample(capsys): export_model_video_action_recognition_sample.export_model_video_action_recognition_sample( project=PROJECT_ID, diff --git a/samples/snippets/get_model_evaluation_image_classification_sample.py b/samples/snippets/model_service/get_model_evaluation_image_classification_sample.py similarity index 74% rename from samples/snippets/get_model_evaluation_image_classification_sample.py rename to samples/snippets/model_service/get_model_evaluation_image_classification_sample.py index 9fe35aa60e..23e83e9239 100644 --- a/samples/snippets/get_model_evaluation_image_classification_sample.py +++ b/samples/snippets/model_service/get_model_evaluation_image_classification_sample.py @@ -23,6 +23,19 @@ def get_model_evaluation_image_classification_sample( location: str = "us-central1", api_endpoint: str = "us-central1-aiplatform.googleapis.com", ): + """ + To obtain evaluation_id run the following commands where LOCATION + is the region where the model is stored, PROJECT is the project ID, + and MODEL_ID is the ID of your model. + + model_client = aiplatform.gapic.ModelServiceClient( + client_options={ + 'api_endpoint':'LOCATION-aiplatform.googleapis.com' + } + ) + evaluations = model_client.list_model_evaluations(parent='projects/PROJECT/locations/LOCATION/models/MODEL_ID') + print("evaluations:", evaluations) + """ # The AI Platform services require regional API endpoints. client_options = {"api_endpoint": api_endpoint} # Initialize client that will be used to create and send requests. diff --git a/samples/snippets/get_model_evaluation_image_object_detection_sample.py b/samples/snippets/model_service/get_model_evaluation_image_object_detection_sample.py similarity index 74% rename from samples/snippets/get_model_evaluation_image_object_detection_sample.py rename to samples/snippets/model_service/get_model_evaluation_image_object_detection_sample.py index d6a4c5cc9a..d9d35b18b8 100644 --- a/samples/snippets/get_model_evaluation_image_object_detection_sample.py +++ b/samples/snippets/model_service/get_model_evaluation_image_object_detection_sample.py @@ -23,6 +23,19 @@ def get_model_evaluation_image_object_detection_sample( location: str = "us-central1", api_endpoint: str = "us-central1-aiplatform.googleapis.com", ): + """ + To obtain evaluation_id run the following commands where LOCATION + is the region where the model is stored, PROJECT is the project ID, + and MODEL_ID is the ID of your model. + + model_client = aiplatform.gapic.ModelServiceClient( + client_options={ + 'api_endpoint':'LOCATION-aiplatform.googleapis.com' + } + ) + evaluations = model_client.list_model_evaluations(parent='projects/PROJECT/locations/LOCATION/models/MODEL_ID') + print("evaluations:", evaluations) + """ # The AI Platform services require regional API endpoints. client_options = {"api_endpoint": api_endpoint} # Initialize client that will be used to create and send requests. diff --git a/samples/snippets/get_model_evaluation_sample.py b/samples/snippets/model_service/get_model_evaluation_sample.py similarity index 100% rename from samples/snippets/get_model_evaluation_sample.py rename to samples/snippets/model_service/get_model_evaluation_sample.py diff --git a/samples/snippets/get_model_evaluation_sample_test.py b/samples/snippets/model_service/get_model_evaluation_sample_test.py similarity index 100% rename from samples/snippets/get_model_evaluation_sample_test.py rename to samples/snippets/model_service/get_model_evaluation_sample_test.py diff --git a/samples/snippets/get_model_evaluation_slice_sample.py b/samples/snippets/model_service/get_model_evaluation_slice_sample.py similarity index 75% rename from samples/snippets/get_model_evaluation_slice_sample.py rename to samples/snippets/model_service/get_model_evaluation_slice_sample.py index e79e787c7d..f8a465ec95 100644 --- a/samples/snippets/get_model_evaluation_slice_sample.py +++ b/samples/snippets/model_service/get_model_evaluation_slice_sample.py @@ -24,6 +24,19 @@ def get_model_evaluation_slice_sample( location: str = "us-central1", api_endpoint: str = "us-central1-aiplatform.googleapis.com", ): + """ + To obtain evaluation_id run the following commands where LOCATION + is the region where the model is stored, PROJECT is the project ID, + and MODEL_ID is the ID of your model. + + model_client = aiplatform.gapic.ModelServiceClient( + client_options={ + 'api_endpoint':'LOCATION-aiplatform.googleapis.com' + } + ) + evaluations = model_client.list_model_evaluations(parent='projects/PROJECT/locations/LOCATION/models/MODEL_ID') + print("evaluations:", evaluations) + """ # The AI Platform services require regional API endpoints. client_options = {"api_endpoint": api_endpoint} # Initialize client that will be used to create and send requests. diff --git a/samples/snippets/get_model_evaluation_slice_sample_test.py b/samples/snippets/model_service/get_model_evaluation_slice_sample_test.py similarity index 100% rename from samples/snippets/get_model_evaluation_slice_sample_test.py rename to samples/snippets/model_service/get_model_evaluation_slice_sample_test.py diff --git a/samples/snippets/get_model_evaluation_tabular_classification_sample.py b/samples/snippets/model_service/get_model_evaluation_tabular_classification_sample.py similarity index 74% rename from samples/snippets/get_model_evaluation_tabular_classification_sample.py rename to samples/snippets/model_service/get_model_evaluation_tabular_classification_sample.py index 2dd870f89f..e7c3901fb7 100644 --- a/samples/snippets/get_model_evaluation_tabular_classification_sample.py +++ b/samples/snippets/model_service/get_model_evaluation_tabular_classification_sample.py @@ -23,6 +23,19 @@ def get_model_evaluation_tabular_classification_sample( location: str = "us-central1", api_endpoint: str = "us-central1-aiplatform.googleapis.com", ): + """ + To obtain evaluation_id run the following commands where LOCATION + is the region where the model is stored, PROJECT is the project ID, + and MODEL_ID is the ID of your model. + + model_client = aiplatform.gapic.ModelServiceClient( + client_options={ + 'api_endpoint':'LOCATION-aiplatform.googleapis.com' + } + ) + evaluations = model_client.list_model_evaluations(parent='projects/PROJECT/locations/LOCATION/models/MODEL_ID') + print("evaluations:", evaluations) + """ # The AI Platform services require regional API endpoints. client_options = {"api_endpoint": api_endpoint} # Initialize client that will be used to create and send requests. diff --git a/samples/snippets/get_model_evaluation_tabular_classification_sample_test.py b/samples/snippets/model_service/get_model_evaluation_tabular_classification_sample_test.py similarity index 100% rename from samples/snippets/get_model_evaluation_tabular_classification_sample_test.py rename to samples/snippets/model_service/get_model_evaluation_tabular_classification_sample_test.py diff --git a/samples/snippets/get_model_evaluation_tabular_regression_sample.py b/samples/snippets/model_service/get_model_evaluation_tabular_regression_sample.py similarity index 74% rename from samples/snippets/get_model_evaluation_tabular_regression_sample.py rename to samples/snippets/model_service/get_model_evaluation_tabular_regression_sample.py index b08bcd5a45..6923d16068 100644 --- a/samples/snippets/get_model_evaluation_tabular_regression_sample.py +++ b/samples/snippets/model_service/get_model_evaluation_tabular_regression_sample.py @@ -23,6 +23,19 @@ def get_model_evaluation_tabular_regression_sample( location: str = "us-central1", api_endpoint: str = "us-central1-aiplatform.googleapis.com", ): + """ + To obtain evaluation_id run the following commands where LOCATION + is the region where the model is stored, PROJECT is the project ID, + and MODEL_ID is the ID of your model. + + model_client = aiplatform.gapic.ModelServiceClient( + client_options={ + 'api_endpoint':'LOCATION-aiplatform.googleapis.com' + } + ) + evaluations = model_client.list_model_evaluations(parent='projects/PROJECT/locations/LOCATION/models/MODEL_ID') + print("evaluations:", evaluations) + """ # The AI Platform services require regional API endpoints. client_options = {"api_endpoint": api_endpoint} # Initialize client that will be used to create and send requests. diff --git a/samples/snippets/get_model_evaluation_tabular_regression_sample_test.py b/samples/snippets/model_service/get_model_evaluation_tabular_regression_sample_test.py similarity index 100% rename from samples/snippets/get_model_evaluation_tabular_regression_sample_test.py rename to samples/snippets/model_service/get_model_evaluation_tabular_regression_sample_test.py diff --git a/samples/snippets/get_model_evaluation_text_classification_sample.py b/samples/snippets/model_service/get_model_evaluation_text_classification_sample.py similarity index 74% rename from samples/snippets/get_model_evaluation_text_classification_sample.py rename to samples/snippets/model_service/get_model_evaluation_text_classification_sample.py index cdaea5c988..300760a88d 100644 --- a/samples/snippets/get_model_evaluation_text_classification_sample.py +++ b/samples/snippets/model_service/get_model_evaluation_text_classification_sample.py @@ -23,6 +23,19 @@ def get_model_evaluation_text_classification_sample( location: str = "us-central1", api_endpoint: str = "us-central1-aiplatform.googleapis.com", ): + """ + To obtain evaluation_id run the following commands where LOCATION + is the region where the model is stored, PROJECT is the project ID, + and MODEL_ID is the ID of your model. + + model_client = aiplatform.gapic.ModelServiceClient( + client_options={ + 'api_endpoint':'LOCATION-aiplatform.googleapis.com' + } + ) + evaluations = model_client.list_model_evaluations(parent='projects/PROJECT/locations/LOCATION/models/MODEL_ID') + print("evaluations:", evaluations) + """ # The AI Platform services require regional API endpoints. client_options = {"api_endpoint": api_endpoint} # Initialize client that will be used to create and send requests. diff --git a/samples/snippets/get_model_evaluation_text_entity_extraction_sample.py b/samples/snippets/model_service/get_model_evaluation_text_entity_extraction_sample.py similarity index 74% rename from samples/snippets/get_model_evaluation_text_entity_extraction_sample.py rename to samples/snippets/model_service/get_model_evaluation_text_entity_extraction_sample.py index 1fff1fa767..9c43ba9279 100644 --- a/samples/snippets/get_model_evaluation_text_entity_extraction_sample.py +++ b/samples/snippets/model_service/get_model_evaluation_text_entity_extraction_sample.py @@ -23,6 +23,19 @@ def get_model_evaluation_text_entity_extraction_sample( location: str = "us-central1", api_endpoint: str = "us-central1-aiplatform.googleapis.com", ): + """ + To obtain evaluation_id run the following commands where LOCATION + is the region where the model is stored, PROJECT is the project ID, + and MODEL_ID is the ID of your model. + + model_client = aiplatform.gapic.ModelServiceClient( + client_options={ + 'api_endpoint':'LOCATION-aiplatform.googleapis.com' + } + ) + evaluations = model_client.list_model_evaluations(parent='projects/PROJECT/locations/LOCATION/models/MODEL_ID') + print("evaluations:", evaluations) + """ # The AI Platform services require regional API endpoints. client_options = {"api_endpoint": api_endpoint} # Initialize client that will be used to create and send requests. diff --git a/samples/snippets/get_model_evaluation_text_sentiment_analysis_sample.py b/samples/snippets/model_service/get_model_evaluation_text_sentiment_analysis_sample.py similarity index 74% rename from samples/snippets/get_model_evaluation_text_sentiment_analysis_sample.py rename to samples/snippets/model_service/get_model_evaluation_text_sentiment_analysis_sample.py index bb8521c1b1..65cbac6767 100644 --- a/samples/snippets/get_model_evaluation_text_sentiment_analysis_sample.py +++ b/samples/snippets/model_service/get_model_evaluation_text_sentiment_analysis_sample.py @@ -23,6 +23,19 @@ def get_model_evaluation_text_sentiment_analysis_sample( location: str = "us-central1", api_endpoint: str = "us-central1-aiplatform.googleapis.com", ): + """ + To obtain evaluation_id run the following commands where LOCATION + is the region where the model is stored, PROJECT is the project ID, + and MODEL_ID is the ID of your model. + + model_client = aiplatform.gapic.ModelServiceClient( + client_options={ + 'api_endpoint':'LOCATION-aiplatform.googleapis.com' + } + ) + evaluations = model_client.list_model_evaluations(parent='projects/PROJECT/locations/LOCATION/models/MODEL_ID') + print("evaluations:", evaluations) + """ # The AI Platform services require regional API endpoints. client_options = {"api_endpoint": api_endpoint} # Initialize client that will be used to create and send requests. diff --git a/samples/snippets/get_model_evaluation_video_action_recognition_sample.py b/samples/snippets/model_service/get_model_evaluation_video_action_recognition_sample.py similarity index 74% rename from samples/snippets/get_model_evaluation_video_action_recognition_sample.py rename to samples/snippets/model_service/get_model_evaluation_video_action_recognition_sample.py index 3233b45677..90e84b9ee9 100644 --- a/samples/snippets/get_model_evaluation_video_action_recognition_sample.py +++ b/samples/snippets/model_service/get_model_evaluation_video_action_recognition_sample.py @@ -23,6 +23,19 @@ def get_model_evaluation_video_action_recognition_sample( location: str = "us-central1", api_endpoint: str = "us-central1-aiplatform.googleapis.com", ): + """ + To obtain evaluation_id run the following commands where LOCATION + is the region where the model is stored, PROJECT is the project ID, + and MODEL_ID is the ID of your model. + + model_client = aiplatform.gapic.ModelServiceClient( + client_options={ + 'api_endpoint':'LOCATION-aiplatform.googleapis.com' + } + ) + evaluations = model_client.list_model_evaluations(parent='projects/PROJECT/locations/LOCATION/models/MODEL_ID') + print("evaluations:", evaluations) + """ # The AI Platform services require regional API endpoints. client_options = {"api_endpoint": api_endpoint} # Initialize client that will be used to create and send requests. diff --git a/samples/snippets/get_model_evaluation_video_action_recognition_sample_test.py b/samples/snippets/model_service/get_model_evaluation_video_action_recognition_sample_test.py similarity index 100% rename from samples/snippets/get_model_evaluation_video_action_recognition_sample_test.py rename to samples/snippets/model_service/get_model_evaluation_video_action_recognition_sample_test.py diff --git a/samples/snippets/get_model_evaluation_video_classification_sample.py b/samples/snippets/model_service/get_model_evaluation_video_classification_sample.py similarity index 74% rename from samples/snippets/get_model_evaluation_video_classification_sample.py rename to samples/snippets/model_service/get_model_evaluation_video_classification_sample.py index 3f0eb65566..158e3ba1ff 100644 --- a/samples/snippets/get_model_evaluation_video_classification_sample.py +++ b/samples/snippets/model_service/get_model_evaluation_video_classification_sample.py @@ -23,6 +23,19 @@ def get_model_evaluation_video_classification_sample( location: str = "us-central1", api_endpoint: str = "us-central1-aiplatform.googleapis.com", ): + """ + To obtain evaluation_id run the following commands where LOCATION + is the region where the model is stored, PROJECT is the project ID, + and MODEL_ID is the ID of your model. + + model_client = aiplatform.gapic.ModelServiceClient( + client_options={ + 'api_endpoint':'LOCATION-aiplatform.googleapis.com' + } + ) + evaluations = model_client.list_model_evaluations(parent='projects/PROJECT/locations/LOCATION/models/MODEL_ID') + print("evaluations:", evaluations) + """ # The AI Platform services require regional API endpoints. client_options = {"api_endpoint": api_endpoint} # Initialize client that will be used to create and send requests. diff --git a/samples/snippets/get_model_evaluation_video_classification_sample_test.py b/samples/snippets/model_service/get_model_evaluation_video_classification_sample_test.py similarity index 100% rename from samples/snippets/get_model_evaluation_video_classification_sample_test.py rename to samples/snippets/model_service/get_model_evaluation_video_classification_sample_test.py diff --git a/samples/snippets/get_model_evaluation_video_object_tracking_sample.py b/samples/snippets/model_service/get_model_evaluation_video_object_tracking_sample.py similarity index 74% rename from samples/snippets/get_model_evaluation_video_object_tracking_sample.py rename to samples/snippets/model_service/get_model_evaluation_video_object_tracking_sample.py index 493b3730dd..2726681178 100644 --- a/samples/snippets/get_model_evaluation_video_object_tracking_sample.py +++ b/samples/snippets/model_service/get_model_evaluation_video_object_tracking_sample.py @@ -23,6 +23,19 @@ def get_model_evaluation_video_object_tracking_sample( location: str = "us-central1", api_endpoint: str = "us-central1-aiplatform.googleapis.com", ): + """ + To obtain evaluation_id run the following commands where LOCATION + is the region where the model is stored, PROJECT is the project ID, + and MODEL_ID is the ID of your model. + + model_client = aiplatform.gapic.ModelServiceClient( + client_options={ + 'api_endpoint':'LOCATION-aiplatform.googleapis.com' + } + ) + evaluations = model_client.list_model_evaluations(parent='projects/PROJECT/locations/LOCATION/models/MODEL_ID') + print("evaluations:", evaluations) + """ # The AI Platform services require regional API endpoints. client_options = {"api_endpoint": api_endpoint} # Initialize client that will be used to create and send requests. diff --git a/samples/snippets/get_model_evaluation_video_object_tracking_sample_test.py b/samples/snippets/model_service/get_model_evaluation_video_object_tracking_sample_test.py similarity index 100% rename from samples/snippets/get_model_evaluation_video_object_tracking_sample_test.py rename to samples/snippets/model_service/get_model_evaluation_video_object_tracking_sample_test.py diff --git a/samples/snippets/get_model_sample.py b/samples/snippets/model_service/get_model_sample.py similarity index 100% rename from samples/snippets/get_model_sample.py rename to samples/snippets/model_service/get_model_sample.py diff --git a/samples/snippets/get_model_sample_test.py b/samples/snippets/model_service/get_model_sample_test.py similarity index 100% rename from samples/snippets/get_model_sample_test.py rename to samples/snippets/model_service/get_model_sample_test.py diff --git a/samples/snippets/list_model_evaluation_slices_sample.py b/samples/snippets/model_service/list_model_evaluation_slices_sample.py similarity index 75% rename from samples/snippets/list_model_evaluation_slices_sample.py rename to samples/snippets/model_service/list_model_evaluation_slices_sample.py index 8285999aca..1d895a41ce 100644 --- a/samples/snippets/list_model_evaluation_slices_sample.py +++ b/samples/snippets/model_service/list_model_evaluation_slices_sample.py @@ -23,6 +23,19 @@ def list_model_evaluation_slices_sample( location: str = "us-central1", api_endpoint: str = "us-central1-aiplatform.googleapis.com", ): + """ + To obtain evaluation_id run the following commands where LOCATION + is the region where the model is stored, PROJECT is the project ID, + and MODEL_ID is the ID of your model. + + model_client = aiplatform.gapic.ModelServiceClient( + client_options={ + 'api_endpoint':'LOCATION-aiplatform.googleapis.com' + } + ) + evaluations = model_client.list_model_evaluations(parent='projects/PROJECT/locations/LOCATION/models/MODEL_ID') + print("evaluations:", evaluations) + """ # The AI Platform services require regional API endpoints. client_options = {"api_endpoint": api_endpoint} # Initialize client that will be used to create and send requests. diff --git a/samples/snippets/list_model_evaluation_slices_sample_test.py b/samples/snippets/model_service/list_model_evaluation_slices_sample_test.py similarity index 100% rename from samples/snippets/list_model_evaluation_slices_sample_test.py rename to samples/snippets/model_service/list_model_evaluation_slices_sample_test.py diff --git a/samples/snippets/upload_model_explain_image_managed_container_sample.py b/samples/snippets/model_service/upload_model_explain_image_managed_container_sample.py similarity index 100% rename from samples/snippets/upload_model_explain_image_managed_container_sample.py rename to samples/snippets/model_service/upload_model_explain_image_managed_container_sample.py diff --git a/samples/snippets/upload_model_explain_image_managed_container_sample_test.py b/samples/snippets/model_service/upload_model_explain_image_managed_container_sample_test.py similarity index 95% rename from samples/snippets/upload_model_explain_image_managed_container_sample_test.py rename to samples/snippets/model_service/upload_model_explain_image_managed_container_sample_test.py index e93b9348ec..bb572446e0 100644 --- a/samples/snippets/upload_model_explain_image_managed_container_sample_test.py +++ b/samples/snippets/model_service/upload_model_explain_image_managed_container_sample_test.py @@ -17,10 +17,10 @@ from uuid import uuid4 import pytest +import upload_model_explain_image_managed_container_sample import helpers -import upload_model_explain_image_managed_container_sample PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") IMAGE_URI = "gcr.io/cloud-aiplatform/prediction/tf2-cpu.2-1:latest" @@ -36,6 +36,7 @@ def teardown(teardown_model): yield +@pytest.mark.skip(reason="https://github.com/googleapis/java-aiplatform/issues/420") def test_ucaip_generated_upload_model_explain_image_managed_container_sample(capsys, shared_state): upload_model_explain_image_managed_container_sample.upload_model_explain_image_managed_container_sample( diff --git a/samples/snippets/upload_model_explain_tabular_managed_container_sample.py b/samples/snippets/model_service/upload_model_explain_tabular_managed_container_sample.py similarity index 100% rename from samples/snippets/upload_model_explain_tabular_managed_container_sample.py rename to samples/snippets/model_service/upload_model_explain_tabular_managed_container_sample.py diff --git a/samples/snippets/upload_model_explain_tabular_managed_container_sample_test.py b/samples/snippets/model_service/upload_model_explain_tabular_managed_container_sample_test.py similarity index 95% rename from samples/snippets/upload_model_explain_tabular_managed_container_sample_test.py rename to samples/snippets/model_service/upload_model_explain_tabular_managed_container_sample_test.py index 581a11e5b4..a3ccd71623 100644 --- a/samples/snippets/upload_model_explain_tabular_managed_container_sample_test.py +++ b/samples/snippets/model_service/upload_model_explain_tabular_managed_container_sample_test.py @@ -17,10 +17,10 @@ from uuid import uuid4 import pytest +import upload_model_explain_tabular_managed_container_sample import helpers -import upload_model_explain_tabular_managed_container_sample PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") IMAGE_URI = "gcr.io/cloud-aiplatform/prediction/tf2-cpu.2-1:latest" @@ -36,6 +36,7 @@ def teardown(teardown_model): yield +@pytest.mark.skip(reason="https://github.com/googleapis/java-aiplatform/issues/420") def test_ucaip_generated_upload_model_explain_tabular_managed_constainer_sample(capsys, shared_state): upload_model_explain_tabular_managed_container_sample.upload_model_explain_tabular_managed_container_sample( diff --git a/samples/snippets/upload_model_sample.py b/samples/snippets/model_service/upload_model_sample.py similarity index 100% rename from samples/snippets/upload_model_sample.py rename to samples/snippets/model_service/upload_model_sample.py diff --git a/samples/snippets/upload_model_sample_test.py b/samples/snippets/model_service/upload_model_sample_test.py similarity index 99% rename from samples/snippets/upload_model_sample_test.py rename to samples/snippets/model_service/upload_model_sample_test.py index 8a38605455..2f9670c26e 100644 --- a/samples/snippets/upload_model_sample_test.py +++ b/samples/snippets/model_service/upload_model_sample_test.py @@ -17,9 +17,11 @@ import pytest -import helpers import upload_model_sample +import helpers + + PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") IMAGE_URI = "gcr.io/cloud-ml-service-public/cloud-ml-online-prediction-model-server-cpu:v1_15py3cmle_op_images_20200229_0210_RC00" ARTIFACT_URI = "gs://ucaip-samples-us-central1/model/explain/" diff --git a/samples/snippets/noxfile.py b/samples/snippets/noxfile.py index 5660f08be4..38bb0a572b 100644 --- a/samples/snippets/noxfile.py +++ b/samples/snippets/noxfile.py @@ -14,9 +14,11 @@ from __future__ import print_function +import glob import os from pathlib import Path import sys +from typing import Callable, Dict, List, Optional import nox @@ -27,8 +29,10 @@ # WARNING - WARNING - WARNING - WARNING - WARNING # WARNING - WARNING - WARNING - WARNING - WARNING -# Copy `noxfile_config.py` to your directory and modify it instead. +BLACK_VERSION = "black==22.3.0" +ISORT_VERSION = "isort==5.10.1" +# Copy `noxfile_config.py` to your directory and modify it instead. # `TEST_CONFIG` dict is a configuration hook that allows users to # modify the test configurations. The values here should be in sync @@ -37,13 +41,20 @@ TEST_CONFIG = { # You can opt out from the test for specific Python versions. - "ignored_versions": ["2.7"], + "ignored_versions": [], + # Old samples are opted out of enforcing Python type hints + # All new samples should feature them + "enforce_type_hints": False, # 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', + # If you need to use a specific version of pip, + # change pip_version_override to the string representation + # of the version number, for example, "20.2.4" + "pip_version_override": None, # A dictionary you want to inject into your test. Don't put any # secrets here. These values will override predefined values. "envs": {}, @@ -62,7 +73,7 @@ TEST_CONFIG.update(TEST_CONFIG_OVERRIDE) -def get_pytest_env_vars(): +def get_pytest_env_vars() -> Dict[str, str]: """Returns a dict for pytest invocation.""" ret = {} @@ -77,21 +88,28 @@ def get_pytest_env_vars(): # DO NOT EDIT - automatically generated. -# All versions used to tested samples. -ALL_VERSIONS = ["2.7", "3.6", "3.7", "3.8"] +# All versions used to test samples. +ALL_VERSIONS = ["3.6", "3.7", "3.8", "3.9", "3.10"] # Any default versions that should be ignored. IGNORED_VERSIONS = TEST_CONFIG["ignored_versions"] TESTED_VERSIONS = sorted([v for v in ALL_VERSIONS if v not in IGNORED_VERSIONS]) -INSTALL_LIBRARY_FROM_SOURCE = bool(os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False)) +INSTALL_LIBRARY_FROM_SOURCE = os.environ.get("INSTALL_LIBRARY_FROM_SOURCE", False) in ( + "True", + "true", +) + +# Error if a python version is missing +nox.options.error_on_missing_interpreters = True + # # Style Checks # -def _determine_local_import_names(start_dir): +def _determine_local_import_names(start_dir: str) -> List[str]: """Determines all import names that should be considered "local". This is used when running the linter to insure that import order is @@ -129,8 +147,11 @@ def _determine_local_import_names(start_dir): @nox.session -def lint(session): - session.install("flake8", "flake8-import-order") +def lint(session: nox.sessions.Session) -> None: + if not TEST_CONFIG["enforce_type_hints"]: + session.install("flake8", "flake8-import-order") + else: + session.install("flake8", "flake8-import-order", "flake8-annotations") local_names = _determine_local_import_names(".") args = FLAKE8_COMMON_ARGS + [ @@ -141,6 +162,39 @@ def lint(session): session.run("flake8", *args) +# +# Black +# + + +@nox.session +def blacken(session: nox.sessions.Session) -> None: + """Run black. Format code to uniform standard.""" + session.install(BLACK_VERSION) + python_files = [path for path in os.listdir(".") if path.endswith(".py")] + + session.run("black", *python_files) + + +# +# format = isort + black +# + +@nox.session +def format(session: nox.sessions.Session) -> None: + """ + Run isort to sort imports. Then run black + to format code to uniform standard. + """ + session.install(BLACK_VERSION, ISORT_VERSION) + python_files = [path for path in os.listdir(".") if path.endswith(".py")] + + # Use the --fss option to sort imports using strict alphabetical order. + # See https://pycqa.github.io/isort/docs/configuration/options.html#force-sort-within-sections + session.run("isort", "--fss", *python_files) + session.run("black", *python_files) + + # # Sample Tests # @@ -149,13 +203,39 @@ def lint(session): PYTEST_COMMON_ARGS = ["--junitxml=sponge_log.xml"] -def _session_tests(session, post_install=None): +def _session_tests( + session: nox.sessions.Session, post_install: Callable = None +) -> None: + # check for presence of tests + test_list = glob.glob("*_test.py") + glob.glob("test_*.py") + test_list.extend(glob.glob("tests")) + + if len(test_list) == 0: + print("No tests found, skipping directory.") + return + + if TEST_CONFIG["pip_version_override"]: + pip_version = TEST_CONFIG["pip_version_override"] + session.install(f"pip=={pip_version}") """Runs py.test for a particular project.""" + concurrent_args = [] if os.path.exists("requirements.txt"): - session.install("-r", "requirements.txt") + if os.path.exists("constraints.txt"): + session.install("-r", "requirements.txt", "-c", "constraints.txt") + else: + session.install("-r", "requirements.txt") + with open("requirements.txt") as rfile: + packages = rfile.read() if os.path.exists("requirements-test.txt"): - session.install("-r", "requirements-test.txt") + if os.path.exists("constraints-test.txt"): + session.install( + "-r", "requirements-test.txt", "-c", "constraints-test.txt" + ) + else: + session.install("-r", "requirements-test.txt") + with open("requirements-test.txt") as rtfile: + packages += rtfile.read() if INSTALL_LIBRARY_FROM_SOURCE: session.install("-e", _get_repo_root()) @@ -163,19 +243,24 @@ def _session_tests(session, post_install=None): if post_install: post_install(session) + if "pytest-parallel" in packages: + concurrent_args.extend(['--workers', 'auto', '--tests-per-worker', 'auto']) + elif "pytest-xdist" in packages: + concurrent_args.extend(['-n', 'auto']) + session.run( "pytest", - *(PYTEST_COMMON_ARGS + session.posargs), + *(PYTEST_COMMON_ARGS + session.posargs + concurrent_args), # Pytest will return 5 when no tests are collected. This can happen # on travis where slow and flaky tests are excluded. # See http://doc.pytest.org/en/latest/_modules/_pytest/main.html success_codes=[0, 5], - env=get_pytest_env_vars() + env=get_pytest_env_vars(), ) @nox.session(python=ALL_VERSIONS) -def py(session): +def py(session: nox.sessions.Session) -> None: """Runs py.test for a sample using the specified version of Python.""" if session.python in TESTED_VERSIONS: _session_tests(session) @@ -190,7 +275,7 @@ def py(session): # -def _get_repo_root(): +def _get_repo_root() -> Optional[str]: """ Returns the root folder of the project. """ # Get root of this repository. Assume we don't have directories nested deeper than 10 items. p = Path(os.getcwd()) @@ -199,6 +284,11 @@ def _get_repo_root(): break if Path(p / ".git").exists(): return str(p) + # .git is not available in repos cloned via Cloud Build + # setup.py is always in the library's root, so use that instead + # https://github.com/googleapis/synthtool/issues/792 + if Path(p / "setup.py").exists(): + return str(p) p = p.parent raise Exception("Unable to detect repository root.") @@ -208,7 +298,7 @@ def _get_repo_root(): @nox.session @nox.parametrize("path", GENERATED_READMES) -def readmegen(session, path): +def readmegen(session: nox.sessions.Session, path: str) -> None: """(Re-)generates the readme for a sample.""" session.install("jinja2", "pyyaml") dir_ = os.path.dirname(path) diff --git a/samples/snippets/noxfile_config.py b/samples/snippets/noxfile_config.py index 82a6331eee..d1502d6bf6 100644 --- a/samples/snippets/noxfile_config.py +++ b/samples/snippets/noxfile_config.py @@ -19,7 +19,7 @@ TEST_CONFIG_OVERRIDE = { # You can opt out from the test for specific Python versions. - "ignored_versions": ["2.7"], + "ignored_versions": ["2.7", "3.6", "3.8", "3.9"], # 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 @@ -29,6 +29,7 @@ # A dictionary you want to inject into your test. Don't put any # secrets here. These values will override predefined values. "envs": { - "DATA_LABELING_API_ENDPOINT": "us-central1-autopush-aiplatform.sandbox.googleapis.com" + "DATA_LABELING_API_ENDPOINT": "us-central1-autopush-aiplatform.sandbox.googleapis.com", + "PYTEST_ADDOPTS": "-n=auto" # Run tests parallel using all available CPUs }, } diff --git a/samples/snippets/cancel_training_pipeline_sample.py b/samples/snippets/pipeline_service/cancel_training_pipeline_sample.py similarity index 100% rename from samples/snippets/cancel_training_pipeline_sample.py rename to samples/snippets/pipeline_service/cancel_training_pipeline_sample.py diff --git a/samples/snippets/cancel_training_pipeline_sample_test.py b/samples/snippets/pipeline_service/cancel_training_pipeline_sample_test.py similarity index 100% rename from samples/snippets/cancel_training_pipeline_sample_test.py rename to samples/snippets/pipeline_service/cancel_training_pipeline_sample_test.py index 992cf8269d..f517d4c7b2 100644 --- a/samples/snippets/cancel_training_pipeline_sample_test.py +++ b/samples/snippets/pipeline_service/cancel_training_pipeline_sample_test.py @@ -15,11 +15,11 @@ import os from uuid import uuid4 +import cancel_training_pipeline_sample from google.protobuf import json_format from google.protobuf.struct_pb2 import Value import pytest -import cancel_training_pipeline_sample import helpers PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") diff --git a/samples/snippets/create_training_pipeline_custom_job_sample.py b/samples/snippets/pipeline_service/create_training_pipeline_custom_job_sample.py similarity index 100% rename from samples/snippets/create_training_pipeline_custom_job_sample.py rename to samples/snippets/pipeline_service/create_training_pipeline_custom_job_sample.py diff --git a/samples/snippets/create_training_pipeline_custom_job_sample_test.py b/samples/snippets/pipeline_service/create_training_pipeline_custom_job_sample_test.py similarity index 95% rename from samples/snippets/create_training_pipeline_custom_job_sample_test.py rename to samples/snippets/pipeline_service/create_training_pipeline_custom_job_sample_test.py index 5a0677f0a1..283bbc2ed6 100644 --- a/samples/snippets/create_training_pipeline_custom_job_sample_test.py +++ b/samples/snippets/pipeline_service/create_training_pipeline_custom_job_sample_test.py @@ -15,9 +15,9 @@ import os from uuid import uuid4 +import create_training_pipeline_custom_job_sample import pytest -import create_training_pipeline_custom_job_sample import helpers PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") @@ -29,6 +29,7 @@ def teardown(teardown_training_pipeline): yield +@pytest.mark.skip(reason="https://github.com/googleapis/java-aiplatform/issues/420") def test_ucaip_generated_create_training_pipeline_custom_job_sample( capsys, shared_state ): diff --git a/samples/snippets/create_training_pipeline_custom_training_managed_dataset_sample.py b/samples/snippets/pipeline_service/create_training_pipeline_custom_training_managed_dataset_sample.py similarity index 100% rename from samples/snippets/create_training_pipeline_custom_training_managed_dataset_sample.py rename to samples/snippets/pipeline_service/create_training_pipeline_custom_training_managed_dataset_sample.py diff --git a/samples/snippets/create_training_pipeline_custom_training_managed_dataset_sample_test.py b/samples/snippets/pipeline_service/create_training_pipeline_custom_training_managed_dataset_sample_test.py similarity index 96% rename from samples/snippets/create_training_pipeline_custom_training_managed_dataset_sample_test.py rename to samples/snippets/pipeline_service/create_training_pipeline_custom_training_managed_dataset_sample_test.py index 2323163c9e..d18a925747 100644 --- a/samples/snippets/create_training_pipeline_custom_training_managed_dataset_sample_test.py +++ b/samples/snippets/pipeline_service/create_training_pipeline_custom_training_managed_dataset_sample_test.py @@ -15,9 +15,9 @@ import os import uuid +import create_training_pipeline_custom_training_managed_dataset_sample import pytest -import create_training_pipeline_custom_training_managed_dataset_sample import helpers PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") @@ -42,6 +42,7 @@ def teardown(teardown_training_pipeline): yield +@pytest.mark.skip(reason="https://github.com/googleapis/java-aiplatform/issues/420") def test_create_training_pipeline_custom_training_managed_dataset_sample( capsys, shared_state, pipeline_client ): diff --git a/samples/snippets/create_training_pipeline_image_classification_sample.py b/samples/snippets/pipeline_service/create_training_pipeline_image_classification_sample.py similarity index 100% rename from samples/snippets/create_training_pipeline_image_classification_sample.py rename to samples/snippets/pipeline_service/create_training_pipeline_image_classification_sample.py diff --git a/samples/snippets/create_training_pipeline_image_classification_sample_test.py b/samples/snippets/pipeline_service/create_training_pipeline_image_classification_sample_test.py similarity index 94% rename from samples/snippets/create_training_pipeline_image_classification_sample_test.py rename to samples/snippets/pipeline_service/create_training_pipeline_image_classification_sample_test.py index e6f9eca397..44073eb247 100644 --- a/samples/snippets/create_training_pipeline_image_classification_sample_test.py +++ b/samples/snippets/pipeline_service/create_training_pipeline_image_classification_sample_test.py @@ -15,9 +15,9 @@ import os from uuid import uuid4 +import create_training_pipeline_image_classification_sample import pytest -import create_training_pipeline_image_classification_sample import helpers PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") @@ -30,6 +30,7 @@ def teardown(teardown_training_pipeline): yield +@pytest.mark.skip(reason="https://github.com/googleapis/java-aiplatform/issues/420") def test_ucaip_generated_create_training_pipeline_video_classification_sample( capsys, shared_state ): diff --git a/samples/snippets/create_training_pipeline_image_object_detection_sample.py b/samples/snippets/pipeline_service/create_training_pipeline_image_object_detection_sample.py similarity index 100% rename from samples/snippets/create_training_pipeline_image_object_detection_sample.py rename to samples/snippets/pipeline_service/create_training_pipeline_image_object_detection_sample.py diff --git a/samples/snippets/create_training_pipeline_image_object_detection_sample_test.py b/samples/snippets/pipeline_service/create_training_pipeline_image_object_detection_sample_test.py similarity index 94% rename from samples/snippets/create_training_pipeline_image_object_detection_sample_test.py rename to samples/snippets/pipeline_service/create_training_pipeline_image_object_detection_sample_test.py index 46f4e786ef..1b092b2af0 100644 --- a/samples/snippets/create_training_pipeline_image_object_detection_sample_test.py +++ b/samples/snippets/pipeline_service/create_training_pipeline_image_object_detection_sample_test.py @@ -15,9 +15,9 @@ import os from uuid import uuid4 +import create_training_pipeline_image_object_detection_sample import pytest -import create_training_pipeline_image_object_detection_sample import helpers PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") @@ -30,6 +30,7 @@ def teardown(teardown_training_pipeline): yield +@pytest.mark.skip(reason="https://github.com/googleapis/java-aiplatform/issues/420") def test_ucaip_generated_create_training_pipeline_image_object_dectection( capsys, shared_state ): diff --git a/samples/snippets/create_training_pipeline_sample.py b/samples/snippets/pipeline_service/create_training_pipeline_sample.py similarity index 100% rename from samples/snippets/create_training_pipeline_sample.py rename to samples/snippets/pipeline_service/create_training_pipeline_sample.py diff --git a/samples/snippets/create_training_pipeline_sample_test.py b/samples/snippets/pipeline_service/create_training_pipeline_sample_test.py similarity index 96% rename from samples/snippets/create_training_pipeline_sample_test.py rename to samples/snippets/pipeline_service/create_training_pipeline_sample_test.py index 38771638f9..c585379737 100644 --- a/samples/snippets/create_training_pipeline_sample_test.py +++ b/samples/snippets/pipeline_service/create_training_pipeline_sample_test.py @@ -15,9 +15,9 @@ import os from uuid import uuid4 +import create_training_pipeline_sample import pytest -import create_training_pipeline_sample import helpers PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") @@ -34,6 +34,8 @@ def teardown(teardown_training_pipeline): # Training AutoML Vision Model def test_ucaip_generated_create_training_pipeline_sample(capsys, shared_state): + shared_state["cancel_batch_prediction_job_timeout"] = 300 + create_training_pipeline_sample.create_training_pipeline_sample( project=PROJECT_ID, display_name=DISPLAY_NAME, diff --git a/samples/snippets/create_training_pipeline_tabular_classification_sample.py b/samples/snippets/pipeline_service/create_training_pipeline_tabular_classification_sample.py similarity index 100% rename from samples/snippets/create_training_pipeline_tabular_classification_sample.py rename to samples/snippets/pipeline_service/create_training_pipeline_tabular_classification_sample.py diff --git a/samples/snippets/create_training_pipeline_tabular_classification_sample_test.py b/samples/snippets/pipeline_service/create_training_pipeline_tabular_classification_sample_test.py similarity index 91% rename from samples/snippets/create_training_pipeline_tabular_classification_sample_test.py rename to samples/snippets/pipeline_service/create_training_pipeline_tabular_classification_sample_test.py index 00c64ab1f6..4096cb723b 100644 --- a/samples/snippets/create_training_pipeline_tabular_classification_sample_test.py +++ b/samples/snippets/pipeline_service/create_training_pipeline_tabular_classification_sample_test.py @@ -15,9 +15,9 @@ import os from uuid import uuid4 +import create_training_pipeline_tabular_classification_sample import pytest -import create_training_pipeline_tabular_classification_sample import helpers PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") @@ -32,8 +32,11 @@ def teardown(teardown_training_pipeline): yield +@pytest.mark.skip(reason="https://github.com/googleapis/java-aiplatform/issues/420") def test_ucaip_generated_create_training_pipeline_sample(capsys, shared_state): + shared_state["cancel_batch_prediction_job_timeout"] = 300 + create_training_pipeline_tabular_classification_sample.create_training_pipeline_tabular_classification_sample( project=PROJECT_ID, display_name=DISPLAY_NAME, diff --git a/samples/snippets/create_training_pipeline_tabular_forecasting_sample.py b/samples/snippets/pipeline_service/create_training_pipeline_tabular_forecasting_sample.py similarity index 87% rename from samples/snippets/create_training_pipeline_tabular_forecasting_sample.py rename to samples/snippets/pipeline_service/create_training_pipeline_tabular_forecasting_sample.py index 7d69cc1265..aceb81196f 100644 --- a/samples/snippets/create_training_pipeline_tabular_forecasting_sample.py +++ b/samples/snippets/pipeline_service/create_training_pipeline_tabular_forecasting_sample.py @@ -26,10 +26,10 @@ def create_training_pipeline_tabular_forecasting_sample( target_column: str, time_series_identifier_column: str, time_column: str, - static_columns: str, - time_variant_past_only_columns: str, - time_variant_past_and_future_columns: str, - forecast_window_end: int, + time_series_attribute_columns: str, + unavailable_at_forecast: str, + available_at_forecast: str, + forecast_horizon: int, location: str = "us-central1", api_endpoint: str = "us-central1-aiplatform.googleapis.com", ): @@ -47,7 +47,7 @@ def create_training_pipeline_tabular_forecasting_sample( {"auto": {"column_name": "deaths"}}, ] - period = {"unit": "day", "quantity": 1} + data_granularity = {"unit": "day", "quantity": 1} # the inputs should be formatted according to the training_task_definition yaml file training_task_inputs_dict = { @@ -56,13 +56,13 @@ def create_training_pipeline_tabular_forecasting_sample( "timeSeriesIdentifierColumn": time_series_identifier_column, "timeColumn": time_column, "transformations": transformations, - "period": period, + "dataGranularity": data_granularity, "optimizationObjective": "minimize-rmse", "trainBudgetMilliNodeHours": 8000, - "staticColumns": static_columns, - "timeVariantPastOnlyColumns": time_variant_past_only_columns, - "timeVariantPastAndFutureColumns": time_variant_past_and_future_columns, - "forecastWindowEnd": forecast_window_end, + "timeSeriesAttributeColumns": time_series_attribute_columns, + "unavailableAtForecast": unavailable_at_forecast, + "availableAtForecast": available_at_forecast, + "forecastHorizon": forecast_horizon, } training_task_inputs = json_format.ParseDict(training_task_inputs_dict, Value()) diff --git a/samples/snippets/create_training_pipeline_tabular_forecasting_sample_test.py b/samples/snippets/pipeline_service/create_training_pipeline_tabular_forecasting_sample_test.py similarity index 89% rename from samples/snippets/create_training_pipeline_tabular_forecasting_sample_test.py rename to samples/snippets/pipeline_service/create_training_pipeline_tabular_forecasting_sample_test.py index d5c58a7992..fde61c4e43 100644 --- a/samples/snippets/create_training_pipeline_tabular_forecasting_sample_test.py +++ b/samples/snippets/pipeline_service/create_training_pipeline_tabular_forecasting_sample_test.py @@ -15,12 +15,12 @@ import os from uuid import uuid4 -from google.cloud import aiplatform -import pytest - import cancel_training_pipeline_sample import create_training_pipeline_tabular_forecasting_sample import delete_training_pipeline_sample +from google.cloud import aiplatform +import pytest + import helpers PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") @@ -64,8 +64,11 @@ def teardown(shared_state): ) +@pytest.mark.skip(reason="https://github.com/googleapis/java-aiplatform/issues/420") def test_ucaip_generated_create_training_pipeline_sample(capsys, shared_state): + shared_state["cancel_batch_prediction_job_timeout"] = 300 + create_training_pipeline_tabular_forecasting_sample.create_training_pipeline_tabular_forecasting_sample( project=PROJECT_ID, display_name=DISPLAY_NAME, @@ -74,10 +77,10 @@ def test_ucaip_generated_create_training_pipeline_sample(capsys, shared_state): target_column=TARGET_COLUMN, time_series_identifier_column="county", time_column="date", - static_columns=["state_name"], - time_variant_past_only_columns=["deaths"], - time_variant_past_and_future_columns=["date"], - forecast_window_end=10, + time_series_attribute_columns=["state_name"], + unavailable_at_forecast=["deaths"], + available_at_forecast=["date"], + forecast_horizon=10, ) out, _ = capsys.readouterr() diff --git a/samples/snippets/create_training_pipeline_tabular_regression_sample.py b/samples/snippets/pipeline_service/create_training_pipeline_tabular_regression_sample.py similarity index 100% rename from samples/snippets/create_training_pipeline_tabular_regression_sample.py rename to samples/snippets/pipeline_service/create_training_pipeline_tabular_regression_sample.py diff --git a/samples/snippets/create_training_pipeline_tabular_regression_sample_test.py b/samples/snippets/pipeline_service/create_training_pipeline_tabular_regression_sample_test.py similarity index 91% rename from samples/snippets/create_training_pipeline_tabular_regression_sample_test.py rename to samples/snippets/pipeline_service/create_training_pipeline_tabular_regression_sample_test.py index 0209d6087e..ac8583f87b 100644 --- a/samples/snippets/create_training_pipeline_tabular_regression_sample_test.py +++ b/samples/snippets/pipeline_service/create_training_pipeline_tabular_regression_sample_test.py @@ -15,9 +15,9 @@ import os from uuid import uuid4 +import create_training_pipeline_tabular_regression_sample import pytest -import create_training_pipeline_tabular_regression_sample import helpers PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") @@ -34,6 +34,9 @@ def teardown(teardown_training_pipeline): def test_ucaip_generated_create_training_pipeline_sample(capsys, shared_state): + # The return of the cancellation can be flaky; max of 20 runs was 215 sec. + shared_state["cancel_batch_prediction_job_timeout"] = 300 + create_training_pipeline_tabular_regression_sample.create_training_pipeline_tabular_regression_sample( project=PROJECT_ID, display_name=DISPLAY_NAME, diff --git a/samples/snippets/create_training_pipeline_text_classification_sample.py b/samples/snippets/pipeline_service/create_training_pipeline_text_classification_sample.py similarity index 100% rename from samples/snippets/create_training_pipeline_text_classification_sample.py rename to samples/snippets/pipeline_service/create_training_pipeline_text_classification_sample.py diff --git a/samples/snippets/create_training_pipeline_text_entity_extraction_sample.py b/samples/snippets/pipeline_service/create_training_pipeline_text_entity_extraction_sample.py similarity index 100% rename from samples/snippets/create_training_pipeline_text_entity_extraction_sample.py rename to samples/snippets/pipeline_service/create_training_pipeline_text_entity_extraction_sample.py diff --git a/samples/snippets/create_training_pipeline_text_entity_extraction_sample_test.py b/samples/snippets/pipeline_service/create_training_pipeline_text_entity_extraction_sample_test.py similarity index 96% rename from samples/snippets/create_training_pipeline_text_entity_extraction_sample_test.py rename to samples/snippets/pipeline_service/create_training_pipeline_text_entity_extraction_sample_test.py index e7dabbae76..b1edf640af 100644 --- a/samples/snippets/create_training_pipeline_text_entity_extraction_sample_test.py +++ b/samples/snippets/pipeline_service/create_training_pipeline_text_entity_extraction_sample_test.py @@ -15,9 +15,9 @@ import os from uuid import uuid4 +import create_training_pipeline_text_entity_extraction_sample import pytest -import create_training_pipeline_text_entity_extraction_sample import helpers PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") @@ -35,6 +35,8 @@ def test_ucaip_generated_create_training_pipeline_text_entity_extraction_sample( capsys, shared_state ): + shared_state["cancel_batch_prediction_job_timeout"] = 300 + create_training_pipeline_text_entity_extraction_sample.create_training_pipeline_text_entity_extraction_sample( project=PROJECT_ID, display_name=DISPLAY_NAME, diff --git a/samples/snippets/create_training_pipeline_text_sentiment_analysis_sample.py b/samples/snippets/pipeline_service/create_training_pipeline_text_sentiment_analysis_sample.py similarity index 100% rename from samples/snippets/create_training_pipeline_text_sentiment_analysis_sample.py rename to samples/snippets/pipeline_service/create_training_pipeline_text_sentiment_analysis_sample.py diff --git a/samples/snippets/create_training_pipeline_text_sentiment_analysis_sample_test.py b/samples/snippets/pipeline_service/create_training_pipeline_text_sentiment_analysis_sample_test.py similarity index 91% rename from samples/snippets/create_training_pipeline_text_sentiment_analysis_sample_test.py rename to samples/snippets/pipeline_service/create_training_pipeline_text_sentiment_analysis_sample_test.py index 0e2af0f967..701665029c 100644 --- a/samples/snippets/create_training_pipeline_text_sentiment_analysis_sample_test.py +++ b/samples/snippets/pipeline_service/create_training_pipeline_text_sentiment_analysis_sample_test.py @@ -15,9 +15,9 @@ import os from uuid import uuid4 +import create_training_pipeline_text_sentiment_analysis_sample import pytest -import create_training_pipeline_text_sentiment_analysis_sample import helpers PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") @@ -30,11 +30,14 @@ def teardown(teardown_training_pipeline): yield +@pytest.mark.skip(reason="https://github.com/googleapis/java-aiplatform/issues/420") # Training Text Sentiment Analysis Model def test_ucaip_generated_create_training_pipeline_text_sentiment_analysis_sample( capsys, shared_state ): + shared_state["cancel_batch_prediction_job_timeout"] = 300 + create_training_pipeline_text_sentiment_analysis_sample.create_training_pipeline_text_sentiment_analysis_sample( project=PROJECT_ID, display_name=DISPLAY_NAME, diff --git a/samples/snippets/create_training_pipeline_video_action_recognition_sample.py b/samples/snippets/pipeline_service/create_training_pipeline_video_action_recognition_sample.py similarity index 100% rename from samples/snippets/create_training_pipeline_video_action_recognition_sample.py rename to samples/snippets/pipeline_service/create_training_pipeline_video_action_recognition_sample.py diff --git a/samples/snippets/create_training_pipeline_video_action_recognition_sample_test.py b/samples/snippets/pipeline_service/create_training_pipeline_video_action_recognition_sample_test.py similarity index 92% rename from samples/snippets/create_training_pipeline_video_action_recognition_sample_test.py rename to samples/snippets/pipeline_service/create_training_pipeline_video_action_recognition_sample_test.py index c4fca042dd..6f3ba5b45c 100644 --- a/samples/snippets/create_training_pipeline_video_action_recognition_sample_test.py +++ b/samples/snippets/pipeline_service/create_training_pipeline_video_action_recognition_sample_test.py @@ -15,9 +15,9 @@ import os import uuid +import create_training_pipeline_video_action_recognition_sample import pytest -import create_training_pipeline_video_action_recognition_sample import helpers LOCATION = "us-central1" @@ -37,8 +37,12 @@ def teardown(teardown_training_pipeline): yield +@pytest.mark.skip(reason="https://github.com/googleapis/java-aiplatform/issues/420") # Training AutoML Vision Model def test_create_training_pipeline_video_action_recognition_sample(capsys, shared_state): + + shared_state["cancel_batch_prediction_job_timeout"] = 300 + create_training_pipeline_video_action_recognition_sample.create_training_pipeline_video_action_recognition_sample( project=PROJECT_ID, display_name=DISPLAY_NAME, diff --git a/samples/snippets/create_training_pipeline_video_classification_sample.py b/samples/snippets/pipeline_service/create_training_pipeline_video_classification_sample.py similarity index 100% rename from samples/snippets/create_training_pipeline_video_classification_sample.py rename to samples/snippets/pipeline_service/create_training_pipeline_video_classification_sample.py diff --git a/samples/snippets/create_training_pipeline_video_classification_sample_test.py b/samples/snippets/pipeline_service/create_training_pipeline_video_classification_sample_test.py similarity index 91% rename from samples/snippets/create_training_pipeline_video_classification_sample_test.py rename to samples/snippets/pipeline_service/create_training_pipeline_video_classification_sample_test.py index f3479e1d59..331ad05684 100644 --- a/samples/snippets/create_training_pipeline_video_classification_sample_test.py +++ b/samples/snippets/pipeline_service/create_training_pipeline_video_classification_sample_test.py @@ -15,9 +15,9 @@ import os from uuid import uuid4 +import create_training_pipeline_video_classification_sample import pytest -import create_training_pipeline_video_classification_sample import helpers PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") @@ -30,11 +30,14 @@ def teardown(teardown_training_pipeline): yield +@pytest.mark.skip(reason="https://github.com/googleapis/java-aiplatform/issues/420") # Training AutoML Vision Model def test_ucaip_generated_create_training_pipeline_video_classification_sample( capsys, shared_state ): + shared_state["cancel_batch_prediction_job_timeout"] = 300 + create_training_pipeline_video_classification_sample.create_training_pipeline_video_classification_sample( project=PROJECT_ID, display_name=DISPLAY_NAME, diff --git a/samples/snippets/create_training_pipeline_video_object_tracking_sample.py b/samples/snippets/pipeline_service/create_training_pipeline_video_object_tracking_sample.py similarity index 100% rename from samples/snippets/create_training_pipeline_video_object_tracking_sample.py rename to samples/snippets/pipeline_service/create_training_pipeline_video_object_tracking_sample.py diff --git a/samples/snippets/create_training_pipeline_video_object_tracking_sample_test.py b/samples/snippets/pipeline_service/create_training_pipeline_video_object_tracking_sample_test.py similarity index 96% rename from samples/snippets/create_training_pipeline_video_object_tracking_sample_test.py rename to samples/snippets/pipeline_service/create_training_pipeline_video_object_tracking_sample_test.py index 634c74bac9..0c659350e0 100644 --- a/samples/snippets/create_training_pipeline_video_object_tracking_sample_test.py +++ b/samples/snippets/pipeline_service/create_training_pipeline_video_object_tracking_sample_test.py @@ -15,9 +15,9 @@ import os from uuid import uuid4 +import create_training_pipeline_video_object_tracking_sample import pytest -import create_training_pipeline_video_object_tracking_sample import helpers PROJECT_ID = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") @@ -35,6 +35,8 @@ def test_ucaip_generated_create_training_pipeline_video_object_tracking_sample( capsys, shared_state ): + shared_state["cancel_batch_prediction_job_timeout"] = 300 + create_training_pipeline_video_object_tracking_sample.create_training_pipeline_video_object_tracking_sample( project=PROJECT_ID, display_name=DISPLAY_NAME, diff --git a/samples/snippets/delete_training_pipeline_sample.py b/samples/snippets/pipeline_service/delete_training_pipeline_sample.py similarity index 100% rename from samples/snippets/delete_training_pipeline_sample.py rename to samples/snippets/pipeline_service/delete_training_pipeline_sample.py diff --git a/samples/snippets/get_training_pipeline_sample.py b/samples/snippets/pipeline_service/get_training_pipeline_sample.py similarity index 100% rename from samples/snippets/get_training_pipeline_sample.py rename to samples/snippets/pipeline_service/get_training_pipeline_sample.py diff --git a/samples/snippets/get_training_pipeline_sample_test.py b/samples/snippets/pipeline_service/get_training_pipeline_sample_test.py similarity index 100% rename from samples/snippets/get_training_pipeline_sample_test.py rename to samples/snippets/pipeline_service/get_training_pipeline_sample_test.py diff --git a/samples/snippets/explain_tabular_sample.py b/samples/snippets/prediction_service/explain_tabular_sample.py similarity index 100% rename from samples/snippets/explain_tabular_sample.py rename to samples/snippets/prediction_service/explain_tabular_sample.py diff --git a/samples/snippets/explain_tabular_sample_test.py b/samples/snippets/prediction_service/explain_tabular_sample_test.py similarity index 100% rename from samples/snippets/explain_tabular_sample_test.py rename to samples/snippets/prediction_service/explain_tabular_sample_test.py diff --git a/samples/snippets/predict_custom_trained_model_sample.py b/samples/snippets/prediction_service/predict_custom_trained_model_sample.py similarity index 85% rename from samples/snippets/predict_custom_trained_model_sample.py rename to samples/snippets/prediction_service/predict_custom_trained_model_sample.py index d48085945b..5d04fc2400 100644 --- a/samples/snippets/predict_custom_trained_model_sample.py +++ b/samples/snippets/prediction_service/predict_custom_trained_model_sample.py @@ -13,7 +13,7 @@ # limitations under the License. # [START aiplatform_predict_custom_trained_model_sample] -from typing import Dict +from typing import Dict, List, Union from google.cloud import aiplatform from google.protobuf import json_format @@ -23,18 +23,24 @@ def predict_custom_trained_model_sample( project: str, endpoint_id: str, - instance_dict: Dict, + instances: Union[Dict, List[Dict]], location: str = "us-central1", api_endpoint: str = "us-central1-aiplatform.googleapis.com", ): + """ + `instances` can be either single instance of type dict or a list + of instances. + """ # The AI Platform services require regional API endpoints. client_options = {"api_endpoint": api_endpoint} # Initialize client that will be used to create and send requests. # This client only needs to be created once, and can be reused for multiple requests. client = aiplatform.gapic.PredictionServiceClient(client_options=client_options) # The format of each instance should conform to the deployed model's prediction input schema. - instance = json_format.ParseDict(instance_dict, Value()) - instances = [instance] + instances = instances if type(instances) == list else [instances] + instances = [ + json_format.ParseDict(instance_dict, Value()) for instance_dict in instances + ] parameters_dict = {} parameters = json_format.ParseDict(parameters_dict, Value()) endpoint = client.endpoint_path( diff --git a/samples/snippets/predict_custom_trained_model_sample_test.py b/samples/snippets/prediction_service/predict_custom_trained_model_sample_test.py similarity index 74% rename from samples/snippets/predict_custom_trained_model_sample_test.py rename to samples/snippets/prediction_service/predict_custom_trained_model_sample_test.py index b3cc1ddaf6..9ba69047c5 100644 --- a/samples/snippets/predict_custom_trained_model_sample_test.py +++ b/samples/snippets/prediction_service/predict_custom_trained_model_sample_test.py @@ -32,9 +32,20 @@ def test_ucaip_generated_predict_custom_trained_model_sample(capsys): instance_dict = {"image_bytes": {"b64": encoded_content}, "key": "0"} + # Single instance as a dict predict_custom_trained_model_sample.predict_custom_trained_model_sample( - instance_dict=instance_dict, project=PROJECT_ID, endpoint_id=ENDPOINT_ID + instances=instance_dict, project=PROJECT_ID, endpoint_id=ENDPOINT_ID + ) + + # Multiple instances in a list + predict_custom_trained_model_sample.predict_custom_trained_model_sample( + instances=[instance_dict, instance_dict], + project=PROJECT_ID, + endpoint_id=ENDPOINT_ID, ) out, _ = capsys.readouterr() assert "1.0" in out + + # Two sets of scores for multi-instance, one score for single instance + assert out.count("scores") == 3 diff --git a/samples/snippets/predict_image_classification_sample.py b/samples/snippets/prediction_service/predict_image_classification_sample.py similarity index 97% rename from samples/snippets/predict_image_classification_sample.py rename to samples/snippets/prediction_service/predict_image_classification_sample.py index 0e0253d341..48a88bd256 100644 --- a/samples/snippets/predict_image_classification_sample.py +++ b/samples/snippets/prediction_service/predict_image_classification_sample.py @@ -52,7 +52,7 @@ def predict_image_classification_sample( ) print("response") print(" deployed_model_id:", response.deployed_model_id) - # See gs://google-cloud-aiplatform/schema/predict/prediction/classification.yaml for the format of the predictions. + # See gs://google-cloud-aiplatform/schema/predict/prediction/image_classification_1.0.0.yaml for the format of the predictions. predictions = response.predictions for prediction in predictions: print(" prediction:", dict(prediction)) diff --git a/samples/snippets/predict_image_classification_sample_test.py b/samples/snippets/prediction_service/predict_image_classification_sample_test.py similarity index 100% rename from samples/snippets/predict_image_classification_sample_test.py rename to samples/snippets/prediction_service/predict_image_classification_sample_test.py diff --git a/samples/snippets/predict_image_object_detection_sample.py b/samples/snippets/prediction_service/predict_image_object_detection_sample.py similarity index 97% rename from samples/snippets/predict_image_object_detection_sample.py rename to samples/snippets/prediction_service/predict_image_object_detection_sample.py index b3bccc2921..1975b06a33 100644 --- a/samples/snippets/predict_image_object_detection_sample.py +++ b/samples/snippets/prediction_service/predict_image_object_detection_sample.py @@ -52,7 +52,7 @@ def predict_image_object_detection_sample( ) print("response") print(" deployed_model_id:", response.deployed_model_id) - # See gs://google-cloud-aiplatform/schema/predict/prediction/image_object_detection.yaml for the format of the predictions. + # See gs://google-cloud-aiplatform/schema/predict/prediction/image_object_detection_1.0.0.yaml for the format of the predictions. predictions = response.predictions for prediction in predictions: print(" prediction:", dict(prediction)) diff --git a/samples/snippets/predict_image_object_detection_sample_test.py b/samples/snippets/prediction_service/predict_image_object_detection_sample_test.py similarity index 100% rename from samples/snippets/predict_image_object_detection_sample_test.py rename to samples/snippets/prediction_service/predict_image_object_detection_sample_test.py diff --git a/samples/snippets/predict_sample.py b/samples/snippets/prediction_service/predict_sample.py similarity index 100% rename from samples/snippets/predict_sample.py rename to samples/snippets/prediction_service/predict_sample.py diff --git a/samples/snippets/predict_tabular_classification_sample.py b/samples/snippets/prediction_service/predict_tabular_classification_sample.py similarity index 96% rename from samples/snippets/predict_tabular_classification_sample.py rename to samples/snippets/prediction_service/predict_tabular_classification_sample.py index a9df7678a7..7de71ab38d 100644 --- a/samples/snippets/predict_tabular_classification_sample.py +++ b/samples/snippets/prediction_service/predict_tabular_classification_sample.py @@ -46,7 +46,7 @@ def predict_tabular_classification_sample( ) print("response") print(" deployed_model_id:", response.deployed_model_id) - # See gs://google-cloud-aiplatform/schema/predict/prediction/tables_classification.yaml for the format of the predictions. + # See gs://google-cloud-aiplatform/schema/predict/prediction/tabular_classification_1.0.0.yaml for the format of the predictions. predictions = response.predictions for prediction in predictions: print(" prediction:", dict(prediction)) diff --git a/samples/snippets/predict_tabular_classification_sample_test.py b/samples/snippets/prediction_service/predict_tabular_classification_sample_test.py similarity index 100% rename from samples/snippets/predict_tabular_classification_sample_test.py rename to samples/snippets/prediction_service/predict_tabular_classification_sample_test.py diff --git a/samples/snippets/predict_tabular_regression_sample.py b/samples/snippets/prediction_service/predict_tabular_regression_sample.py similarity index 97% rename from samples/snippets/predict_tabular_regression_sample.py rename to samples/snippets/prediction_service/predict_tabular_regression_sample.py index 7f76dc6f17..2cd970c4f7 100644 --- a/samples/snippets/predict_tabular_regression_sample.py +++ b/samples/snippets/prediction_service/predict_tabular_regression_sample.py @@ -46,7 +46,7 @@ def predict_tabular_regression_sample( ) print("response") print(" deployed_model_id:", response.deployed_model_id) - # See gs://google-cloud-aiplatform/schema/predict/prediction/tables_regression.yaml for the format of the predictions. + # See gs://google-cloud-aiplatform/schema/predict/prediction/tabular_regression_1.0.0.yaml for the format of the predictions. predictions = response.predictions for prediction in predictions: print(" prediction:", dict(prediction)) diff --git a/samples/snippets/predict_tabular_regression_sample_test.py b/samples/snippets/prediction_service/predict_tabular_regression_sample_test.py similarity index 100% rename from samples/snippets/predict_tabular_regression_sample_test.py rename to samples/snippets/prediction_service/predict_tabular_regression_sample_test.py diff --git a/samples/snippets/predict_text_classification_single_label_sample.py b/samples/snippets/prediction_service/predict_text_classification_single_label_sample.py similarity index 94% rename from samples/snippets/predict_text_classification_single_label_sample.py rename to samples/snippets/prediction_service/predict_text_classification_single_label_sample.py index c0579224ef..38e72f11e6 100644 --- a/samples/snippets/predict_text_classification_single_label_sample.py +++ b/samples/snippets/prediction_service/predict_text_classification_single_label_sample.py @@ -45,7 +45,7 @@ def predict_text_classification_single_label_sample( ) print("response") print(" deployed_model_id:", response.deployed_model_id) - # See gs://google-cloud-aiplatform/schema/predict/prediction/text_classification.yaml for the format of the predictions. + predictions = response.predictions for prediction in predictions: print(" prediction:", dict(prediction)) diff --git a/samples/snippets/predict_text_classification_single_label_sample_test.py b/samples/snippets/prediction_service/predict_text_classification_single_label_sample_test.py similarity index 100% rename from samples/snippets/predict_text_classification_single_label_sample_test.py rename to samples/snippets/prediction_service/predict_text_classification_single_label_sample_test.py diff --git a/samples/snippets/predict_text_entity_extraction_sample.py b/samples/snippets/prediction_service/predict_text_entity_extraction_sample.py similarity index 97% rename from samples/snippets/predict_text_entity_extraction_sample.py rename to samples/snippets/prediction_service/predict_text_entity_extraction_sample.py index be70a3c075..97b354b874 100644 --- a/samples/snippets/predict_text_entity_extraction_sample.py +++ b/samples/snippets/prediction_service/predict_text_entity_extraction_sample.py @@ -46,7 +46,7 @@ def predict_text_entity_extraction_sample( ) print("response") print(" deployed_model_id:", response.deployed_model_id) - # See gs://google-cloud-aiplatform/schema/predict/prediction/text_extraction.yaml for the format of the predictions. + # See gs://google-cloud-aiplatform/schema/predict/prediction/text_extraction_1.0.0.yaml for the format of the predictions. predictions = response.predictions for prediction in predictions: print(" prediction:", dict(prediction)) diff --git a/samples/snippets/predict_text_entity_extraction_sample_test.py b/samples/snippets/prediction_service/predict_text_entity_extraction_sample_test.py similarity index 100% rename from samples/snippets/predict_text_entity_extraction_sample_test.py rename to samples/snippets/prediction_service/predict_text_entity_extraction_sample_test.py diff --git a/samples/snippets/predict_text_sentiment_analysis_sample.py b/samples/snippets/prediction_service/predict_text_sentiment_analysis_sample.py similarity index 97% rename from samples/snippets/predict_text_sentiment_analysis_sample.py rename to samples/snippets/prediction_service/predict_text_sentiment_analysis_sample.py index 934bc5da9e..f8e66afaa2 100644 --- a/samples/snippets/predict_text_sentiment_analysis_sample.py +++ b/samples/snippets/prediction_service/predict_text_sentiment_analysis_sample.py @@ -45,7 +45,7 @@ def predict_text_sentiment_analysis_sample( ) print("response") print(" deployed_model_id:", response.deployed_model_id) - # See gs://google-cloud-aiplatform/schema/predict/prediction/text_sentiment.yaml for the format of the predictions. + # See gs://google-cloud-aiplatform/schema/predict/prediction/text_sentiment_1.0.0.yaml for the format of the predictions. predictions = response.predictions for prediction in predictions: print(" prediction:", dict(prediction)) diff --git a/samples/snippets/predict_text_sentiment_analysis_sample_test.py b/samples/snippets/prediction_service/predict_text_sentiment_analysis_sample_test.py similarity index 100% rename from samples/snippets/predict_text_sentiment_analysis_sample_test.py rename to samples/snippets/prediction_service/predict_text_sentiment_analysis_sample_test.py diff --git a/samples/snippets/resources/caprese_salad.jpg b/samples/snippets/prediction_service/resources/caprese_salad.jpg similarity index 100% rename from samples/snippets/resources/caprese_salad.jpg rename to samples/snippets/prediction_service/resources/caprese_salad.jpg diff --git a/samples/snippets/resources/daisy.jpg b/samples/snippets/prediction_service/resources/daisy.jpg similarity index 100% rename from samples/snippets/resources/daisy.jpg rename to samples/snippets/prediction_service/resources/daisy.jpg diff --git a/samples/snippets/requirements-test.txt b/samples/snippets/requirements-test.txt new file mode 100644 index 0000000000..bf21b8ef74 --- /dev/null +++ b/samples/snippets/requirements-test.txt @@ -0,0 +1,2 @@ +pytest==6.2.5 +pytest-xdist diff --git a/samples/snippets/requirements-tests.txt b/samples/snippets/requirements-tests.txt deleted file mode 100644 index 7e460c8c86..0000000000 --- a/samples/snippets/requirements-tests.txt +++ /dev/null @@ -1 +0,0 @@ -pytest==6.0.1 diff --git a/samples/snippets/requirements.txt b/samples/snippets/requirements.txt index 0c84038bd2..d09caa45e0 100644 --- a/samples/snippets/requirements.txt +++ b/samples/snippets/requirements.txt @@ -1,3 +1 @@ -pytest==6.2.4 -google-cloud-storage>=1.26.0, <2.0.0dev -google-cloud-aiplatform==1.0.0 +google-cloud-aiplatform diff --git a/scripts/readme-gen/readme_gen.py b/scripts/readme-gen/readme_gen.py index d309d6e975..91b59676bf 100644 --- a/scripts/readme-gen/readme_gen.py +++ b/scripts/readme-gen/readme_gen.py @@ -28,7 +28,10 @@ jinja_env = jinja2.Environment( trim_blocks=True, loader=jinja2.FileSystemLoader( - os.path.abspath(os.path.join(os.path.dirname(__file__), 'templates')))) + os.path.abspath(os.path.join(os.path.dirname(__file__), "templates")) + ), + autoescape=True, +) README_TMPL = jinja_env.get_template('README.tmpl.rst') diff --git a/scripts/readme-gen/templates/install_deps.tmpl.rst b/scripts/readme-gen/templates/install_deps.tmpl.rst index a0406dba8c..275d649890 100644 --- a/scripts/readme-gen/templates/install_deps.tmpl.rst +++ b/scripts/readme-gen/templates/install_deps.tmpl.rst @@ -12,7 +12,7 @@ Install Dependencies .. _Python Development Environment Setup Guide: https://cloud.google.com/python/setup -#. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+. +#. Create a virtualenv. Samples are compatible with Python 3.6+. .. code-block:: bash diff --git a/scripts/run_flaky_test_diagnostic.py b/scripts/run_flaky_test_diagnostic.py new file mode 100644 index 0000000000..46b64d52b1 --- /dev/null +++ b/scripts/run_flaky_test_diagnostic.py @@ -0,0 +1,37 @@ +# Copyright 2022 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. +# + +import os +import pathlib +import sys + +# Run test in snippets directory: +dir_of_curr_file = os.path.dirname(__file__) +helper_filepath = pathlib.Path(dir_of_curr_file).parent / 'samples' / 'snippets' +sys.path.append(helper_filepath.resolve().as_posix()) +os.chdir(helper_filepath.resolve()) +from helpers import flaky_test_diagnostic + +# Settings: +file_name = 'pipeline_service/create_training_pipeline_tabular_regression_sample_test.py' +test_name = 'test_ucaip_generated_create_training_pipeline_sample' +timing_dict = flaky_test_diagnostic(file_name, test_name, N=1) + +for key, delta_list in timing_dict.items(): + mean_time = sum(delta_list)/len(delta_list) + max_time = max(delta_list) + min_time = min(delta_list) + report_string = f'Result: {key}, mean={mean_time:3.2f}, min={min_time:3.2f}, max={max_time:3.2f}, count={len(delta_list)}' + print(report_string) diff --git a/setup.py b/setup.py index d1cced2675..a22cd5a226 100644 --- a/setup.py +++ b/setup.py @@ -21,22 +21,59 @@ import setuptools # type: ignore name = "google-cloud-aiplatform" -version = "1.0.1" -description = "Cloud AI Platform API client library" +description = "Vertex AI API client library" package_root = os.path.abspath(os.path.dirname(__file__)) readme_filename = os.path.join(package_root, "README.rst") with io.open(readme_filename, encoding="utf-8") as readme_file: readme = readme_file.read() -tensorboard_extra_require = [ - "tensorflow-cpu>=2.3.0, <=2.5.0", - "grpcio~=1.34.0", - "six~=1.15.0", -] +version = {} +with open(os.path.join(package_root, "google/cloud/aiplatform/version.py")) as fp: + exec(fp.read(), version) +version = version["__version__"] + +tensorboard_extra_require = ["tensorflow >=2.3.0, <3.0.0dev"] metadata_extra_require = ["pandas >= 1.0.0"] -full_extra_require = tensorboard_extra_require + metadata_extra_require -testing_extra_require = full_extra_require + ["grpcio-testing ~= 1.34.0"] +xai_extra_require = ["tensorflow >=2.3.0, <3.0.0dev"] +lit_extra_require = [ + "tensorflow >= 2.3.0, <3.0.0dev", + "pandas >= 1.0.0", + "lit-nlp >= 0.4.0", + "explainable-ai-sdk >= 1.0.0", +] +profiler_extra_require = [ + "tensorboard-plugin-profile >= 2.4.0, <3.0.0dev", + "werkzeug >= 2.0.0, <2.1.0dev", + "tensorflow >=2.4.0, <3.0.0dev", +] +featurestore_extra_require = [ + "google-cloud-bigquery-storage", + "pandas >= 1.0.0", + "pyarrow >= 6.0.1", +] +pipelines_extra_requires = [ + "pyyaml>=5.3,<6", +] +datasets_extra_require = [ + "pyarrow >= 3.0.0, < 8.0dev", +] +full_extra_require = list( + set( + tensorboard_extra_require + + metadata_extra_require + + xai_extra_require + + lit_extra_require + + featurestore_extra_require + + pipelines_extra_requires + + datasets_extra_require + ) +) +testing_extra_require = ( + full_extra_require + + profiler_extra_require + + ["grpcio-testing", "pytest-xdist", "ipython", "kfp"] +) setuptools.setup( @@ -44,7 +81,11 @@ version=version, description=description, long_description=readme, - packages=setuptools.PEP420PackageFinder.find(), + packages=[ + package + for package in setuptools.PEP420PackageFinder.find() + if package.startswith("google") + ], entry_points={ "console_scripts": [ "tb-gcp-uploader=google.cloud.aiplatform.tensorboard.uploader_main:run_main" @@ -58,27 +99,37 @@ platforms="Posix; MacOS X; Windows", include_package_data=True, install_requires=( - "google-api-core[grpc] >= 1.22.2, < 2.0.0dev", - "proto-plus >= 1.10.1", - "packaging >= 14.3", - "google-cloud-storage >= 1.32.0, < 2.0.0dev", + # NOTE: Maintainers, please do not require google-api-core>=2.x.x + # Until this issue is closed + # https://github.com/googleapis/google-cloud-python/issues/10566 + "google-api-core[grpc] >= 1.31.5, <3.0.0dev,!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0", + "proto-plus >= 1.15.0, <2.0.0dev", + "protobuf >= 3.19.0, <4.0.0dev", + "packaging >= 14.3, <22.0.0dev", + "google-cloud-storage >= 1.32.0, < 3.0.0dev", "google-cloud-bigquery >= 1.15.0, < 3.0.0dev", + "google-cloud-resource-manager >= 1.3.3, < 3.0.0dev", ), extras_require={ "full": full_extra_require, "metadata": metadata_extra_require, "tensorboard": tensorboard_extra_require, "testing": testing_extra_require, + "xai": xai_extra_require, + "lit": lit_extra_require, + "cloud_profiler": profiler_extra_require, + "pipelines": pipelines_extra_requires, }, - python_requires=">=3.6", - scripts=[], + python_requires=">=3.7", classifiers=[ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "Operating System :: OS Independent", - "Programming Language :: Python :: 3.6", + "Programming Language :: Python", + "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", "Topic :: Internet", "Topic :: Software Development :: Libraries :: Python Modules", ], diff --git a/synth.metadata b/synth.metadata deleted file mode 100644 index 5167eaca25..0000000000 --- a/synth.metadata +++ /dev/null @@ -1,53 +0,0 @@ -{ - "sources": [ - { - "git": { - "name": ".", - "remote": "https://github.com/googleapis/python-aiplatform.git", - "sha": "fd36abe48afa3bd4d95f152b97a65613cc2ff23c" - } - }, - { - "git": { - "name": "googleapis", - "remote": "https://github.com/googleapis/googleapis.git", - "sha": "7f6e0d54743dcb86c618b2f78aac2d51e02834b5", - "internalRef": "355883280" - } - }, - { - "git": { - "name": "synthtool", - "remote": "https://github.com/googleapis/synthtool.git", - "sha": "692715c0f23a7bb3bfbbaa300f7620ddfa8c47e5" - } - }, - { - "git": { - "name": "synthtool", - "remote": "https://github.com/googleapis/synthtool.git", - "sha": "692715c0f23a7bb3bfbbaa300f7620ddfa8c47e5" - } - } - ], - "destinations": [ - { - "client": { - "source": "googleapis", - "apiName": "aiplatform", - "apiVersion": "v1beta1", - "language": "python", - "generator": "bazel" - } - }, - { - "client": { - "source": "googleapis", - "apiName": "aiplatform", - "apiVersion": "v1", - "language": "python", - "generator": "bazel" - } - } - ] -} \ No newline at end of file diff --git a/synth.py b/synth.py deleted file mode 100644 index c60f1b9319..0000000000 --- a/synth.py +++ /dev/null @@ -1,137 +0,0 @@ -# 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. - -"""This script is used to synthesize generated parts of this library.""" - -import os - -import synthtool as s -import synthtool.gcp as gcp -from synthtool.languages import python - -gapic = gcp.GAPICBazel() - -common = gcp.CommonTemplates() - -# ---------------------------------------------------------------------------- -# Generate AI Platform GAPIC layer -# ---------------------------------------------------------------------------- - - -versions = ["v1beta1", "v1"] - -for version in versions: - library = gapic.py_library( - service="aiplatform", - version=version, - bazel_target=f"//google/cloud/aiplatform/{version}:aiplatform-{version}-py", - ) - - s.move( - library, - excludes=[ - ".pre-commit-config.yaml", - "setup.py", - "README.rst", - "docs/index.rst", - f"docs/definition_{version}/services.rst", - f"docs/instance_{version}/services.rst", - f"docs/params_{version}/services.rst", - f"docs/prediction_{version}/services.rst", - f"scripts/fixup_aiplatform_{version}_keywords.py", - f"scripts/fixup_definition_{version}_keywords.py", - f"scripts/fixup_instance_{version}_keywords.py", - f"scripts/fixup_params_{version}_keywords.py", - f"scripts/fixup_prediction_{version}_keywords.py", - "google/cloud/aiplatform/__init__.py", - f"google/cloud/aiplatform/{version}/schema/**/services/", - f"tests/unit/gapic/definition_{version}/", - f"tests/unit/gapic/instance_{version}/", - f"tests/unit/gapic/params_{version}/", - f"tests/unit/gapic/prediction_{version}/", - ], - ) - - # --------------------------------------------------------------------- - # Patch each version of the library - # --------------------------------------------------------------------- - - # https://github.com/googleapis/gapic-generator-python/issues/413 - s.replace( - f"google/cloud/aiplatform_{version}/services/prediction_service/client.py", - "request.instances = instances", - "request.instances.extend(instances)", - ) - - # https://github.com/googleapis/gapic-generator-python/issues/672 - s.replace( - "google/cloud/aiplatform_{version}/services/endpoint_service/client.py", - "request.traffic_split.extend\(traffic_split\)", - "request.traffic_split = traffic_split", - ) - -# ---------------------------------------------------------------------------- -# Patch the library -# ---------------------------------------------------------------------------- - -# Fix assert with endpoint missing port -# https://github.com/googleapis/gapic-generator-python/issues/872 -s.replace( - "tests/unit/gapic/**/*.py", - '''create_channel\.assert_called_with\( -(\s+)"aiplatform\.googleapis\.com",''', - '''create_channel.assert_called_with( -\g<1>"aiplatform.googleapis.com:443",''' -) - -# Patch broken assert -# https://github.com/googleapis/gapic-generator-python/issues/414 -s.replace( - "tests/unit/gapic/**/test_prediction_service.py", - """assert args\[0\]\.parameters == struct_pb2\.Value\(null_value=struct_pb2\.NullValue\.NULL_VALUE\)""", - """# https://github.com/googleapis/gapic-generator-python/issues/414 - # assert args[0].parameters == struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE)""" -) - -# Generator adds a bad import statement to enhanced type; -# need to fix in post-processing steps. -#s.replace( -# "google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/text_sentiment.py", -# "text_sentiment_pb2 as gcaspi_text_sentiment # type: ignore", -# "TextSentimentPredictionInstance") - -#s.replace( -# "google/cloud/aiplatform/v1beta1/schema/predict/prediction_v1beta1/types/text_sentiment.py", -# "message=gcaspi_text_sentiment.TextSentimentPredictionInstance,", -# "message=TextSentimentPredictionInstance,") - - - -# ---------------------------------------------------------------------------- -# Add templated files -# ---------------------------------------------------------------------------- - -templated_files = common.py_library(cov_level=99, microgenerator=True) -s.move( - templated_files, - excludes=[ - ".coveragerc", - ".kokoro/samples/**" - ] -) # the microgenerator has a good coveragerc file - -# Don't treat docs warnings as errors -s.replace("noxfile.py", """["']-W["'], # warnings as errors""", "") - -s.shell.run(["nox", "-s", "blacken"], hide_output=False) diff --git a/testing/constraints-3.6.txt b/testing/constraints-3.6.txt index 6753ac710d..acf8ecba0c 100644 --- a/testing/constraints-3.6.txt +++ b/testing/constraints-3.6.txt @@ -5,10 +5,12 @@ # # e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev", # Then this file should have foo==1.14.0 -google-api-core==1.22.2 +google-api-core==1.31.5 libcst==0.2.5 -proto-plus==1.10.1 +proto-plus==1.15.0 +protobuf==3.19.0 mock==4.0.2 google-cloud-storage==1.32.0 google-auth==1.25.0 # TODO: Remove when google-api-core >= 1.26.0 is required packaging==14.3 +grpcio-testing==1.34.0 \ No newline at end of file diff --git a/testing/constraints-3.7.txt b/testing/constraints-3.7.txt index e69de29bb2..8636cd790f 100644 --- a/testing/constraints-3.7.txt +++ b/testing/constraints-3.7.txt @@ -0,0 +1,16 @@ +# This constraints file is used to check that lower bounds +# are correct in setup.py +# List *all* library dependencies and extras in this file. +# Pin the version to the lower bound. +# +# e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev", +# Then this file should have foo==1.14.0 +google-api-core==1.31.5 +libcst==0.2.5 +proto-plus==1.15.0 +protobuf==3.19.0 +mock==4.0.2 +google-cloud-storage==1.32.0 +google-auth==1.25.0 # TODO: Remove when google-api-core >= 1.26.0 is required +packaging==14.3 +grpcio-testing==1.34.0 diff --git a/tests/__init__.py b/tests/__init__.py index 4de65971c2..e8e1c3845d 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/system/__init__.py b/tests/system/__init__.py new file mode 100644 index 0000000000..e8e1c3845d --- /dev/null +++ b/tests/system/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# diff --git a/tests/system/aiplatform/__init__.py b/tests/system/aiplatform/__init__.py new file mode 100644 index 0000000000..e8e1c3845d --- /dev/null +++ b/tests/system/aiplatform/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# diff --git a/tests/system/aiplatform/e2e_base.py b/tests/system/aiplatform/e2e_base.py new file mode 100644 index 0000000000..26d67e9b66 --- /dev/null +++ b/tests/system/aiplatform/e2e_base.py @@ -0,0 +1,202 @@ +# -*- coding: utf-8 -*- + +# 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 +# +# 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. +# + +import abc +import importlib +import logging +import os +import pytest +import uuid + +from typing import Any, Dict, Generator + +from google.api_core import exceptions +from google.cloud import aiplatform +from google.cloud import bigquery +from google.cloud import resourcemanager +from google.cloud import storage +from google.cloud.aiplatform import initializer + +_PROJECT = os.getenv("BUILD_SPECIFIC_GCLOUD_PROJECT") +_VPC_NETWORK_URI = os.getenv("_VPC_NETWORK_URI") +_LOCATION = "us-central1" + + +class TestEndToEnd(metaclass=abc.ABCMeta): + @property + @classmethod + @abc.abstractmethod + def _temp_prefix(cls) -> str: + """Prefix to staging bucket and display names created by this end-to-end test. + Keep the string as short as possible and use kebab case, starting with a lowercase letter. + + Example: `"temp-vertex-hpt-test"` + """ + pass + + @classmethod + def _make_display_name(cls, key: str) -> str: + """Helper method to make unique display_names. + + Args: + key (str): Required. Identifier for the display name. + Returns: + Unique display name. + """ + return f"{cls._temp_prefix}-{key}-{uuid.uuid4()}" + + def setup_method(self): + importlib.reload(initializer) + importlib.reload(aiplatform) + + @pytest.fixture(scope="class") + def shared_state(self) -> Generator[Dict[str, Any], None, None]: + shared_state = {} + yield shared_state + + @pytest.fixture(scope="class") + def prepare_staging_bucket( + self, shared_state: Dict[str, Any] + ) -> Generator[storage.bucket.Bucket, None, None]: + """Create a staging bucket and store bucket resource object in shared state.""" + + staging_bucket_name = f"{self._temp_prefix.lower()}-{uuid.uuid4()}"[:63] + shared_state["staging_bucket_name"] = staging_bucket_name + + storage_client = storage.Client(project=_PROJECT) + shared_state["storage_client"] = storage_client + + bucket = storage_client.create_bucket( + staging_bucket_name, project=_PROJECT, location=_LOCATION + ) + + # TODO(#1415) Once PR Is merged, use the added utilities to + # provide create/view access to Pipeline's default service account (compute) + project_number = ( + resourcemanager.ProjectsClient() + .get_project(name=f"projects/{_PROJECT}") + .name.split("/", 1)[1] + ) + + service_account = f"{project_number}-compute@developer.gserviceaccount.com" + bucket_iam_policy = bucket.get_iam_policy() + bucket_iam_policy.setdefault("roles/storage.objectCreator", set()).add( + f"serviceAccount:{service_account}" + ) + bucket_iam_policy.setdefault("roles/storage.objectViewer", set()).add( + f"serviceAccount:{service_account}" + ) + bucket.set_iam_policy(bucket_iam_policy) + + shared_state["bucket"] = bucket + yield + + @pytest.fixture(scope="class") + def delete_staging_bucket(self, shared_state: Dict[str, Any]): + """Delete the staging bucket and all it's contents""" + + yield + + # Get the staging bucket used for testing and wipe it + bucket = shared_state["bucket"] + bucket.delete(force=True) + + @pytest.fixture(scope="class") + def prepare_bigquery_dataset( + self, shared_state: Dict[str, Any] + ) -> Generator[bigquery.dataset.Dataset, None, None]: + """Create a bigquery dataset and store bigquery resource object in shared state.""" + + bigquery_client = bigquery.Client(project=_PROJECT) + shared_state["bigquery_client"] = bigquery_client + + dataset_name = f"{self._temp_prefix.lower()}_{uuid.uuid4()}".replace("-", "_") + dataset_id = f"{_PROJECT}.{dataset_name}" + shared_state["bigquery_dataset_id"] = dataset_id + + dataset = bigquery.Dataset(dataset_id) + dataset.location = _LOCATION + shared_state["bigquery_dataset"] = bigquery_client.create_dataset(dataset) + + yield + + @pytest.fixture(scope="class") + def delete_bigquery_dataset(self, shared_state: Dict[str, Any]): + """Delete the bigquery dataset""" + + yield + + # Get the bigquery dataset id used for testing and wipe it + bigquery_dataset = shared_state["bigquery_dataset"] + bigquery_client = shared_state["bigquery_client"] + bigquery_client.delete_dataset( + bigquery_dataset.dataset_id, delete_contents=True, not_found_ok=True + ) # Make an API request. + + @pytest.fixture(scope="class") + def bigquery_dataset(self) -> Generator[bigquery.dataset.Dataset, None, None]: + """Create a bigquery dataset and store bigquery resource object in shared state.""" + + bigquery_client = bigquery.Client(project=_PROJECT) + + dataset_name = f"{self._temp_prefix.lower()}_{uuid.uuid4()}".replace("-", "_") + dataset_id = f"{_PROJECT}.{dataset_name}" + + dataset = bigquery.Dataset(dataset_id) + dataset.location = _LOCATION + dataset = bigquery_client.create_dataset(dataset) + + yield dataset + + bigquery_client.delete_dataset( + dataset.dataset_id, delete_contents=True, not_found_ok=True + ) # Make an API request. + + @pytest.fixture(scope="class") + def tear_down_resources(self, shared_state: Dict[str, Any]): + """Delete every Vertex AI resource created during test""" + + yield + + # TODO(b/218310362): Add resource deletion system tests + + # Bring all Endpoints to the front of the list + # Ensures Models are undeployed first before we attempt deletion + shared_state["resources"].sort( + key=lambda r: 1 + if isinstance(r, aiplatform.Endpoint) + or isinstance(r, aiplatform.MatchingEngineIndexEndpoint) + else 2 + ) + + for resource in shared_state["resources"]: + try: + if isinstance( + resource, + ( + aiplatform.Endpoint, + aiplatform.Featurestore, + aiplatform.MatchingEngineIndexEndpoint, + ), + ): + # For endpoint, undeploy model then delete endpoint + # For featurestore, force delete its entity_types and features with the featurestore + resource.delete(force=True) + else: + resource.delete() + except exceptions.GoogleAPIError as e: + logging.error(f"Could not delete resource: {resource} due to: {e}") diff --git a/tests/system/aiplatform/test_dataset.py b/tests/system/aiplatform/test_dataset.py index e852933dc3..40f2e87c46 100644 --- a/tests/system/aiplatform/test_dataset.py +++ b/tests/system/aiplatform/test_dataset.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,27 +20,29 @@ import pytest import importlib -from google import auth as google_auth -from google.protobuf import json_format +import pandas as pd + from google.api_core import exceptions from google.api_core import client_options +from google.cloud import bigquery + from google.cloud import aiplatform from google.cloud import storage from google.cloud.aiplatform import utils from google.cloud.aiplatform import initializer -from google.cloud.aiplatform_v1beta1.types import dataset as gca_dataset from google.cloud.aiplatform_v1beta1.services import dataset_service from test_utils.vpcsc_config import vpcsc_config -# TODO(vinnys): Replace with env var `BUILD_SPECIFIC_GCP_PROJECT` once supported -_, _TEST_PROJECT = google_auth.default() +from tests.system.aiplatform import e2e_base + +_TEST_PROJECT = e2e_base._PROJECT +_TEST_LOCATION = e2e_base._LOCATION TEST_BUCKET = os.environ.get( "GCLOUD_TEST_SAMPLES_BUCKET", "cloud-samples-data-us-central1" ) -_TEST_LOCATION = "us-central1" _TEST_PARENT = f"projects/{_TEST_PROJECT}/locations/{_TEST_LOCATION}" _TEST_API_ENDPOINT = f"{_TEST_LOCATION}-aiplatform.googleapis.com" _TEST_IMAGE_DATASET_ID = "1084241610289446912" # permanent_50_flowers_dataset @@ -48,7 +50,12 @@ "6203215905493614592" # permanent_text_entity_extraction_dataset ) _TEST_DATASET_DISPLAY_NAME = "permanent_50_flowers_dataset" +_TEST_DATASET_LABELS = {"test": "labels"} +_TEST_DATASET_DESCRIPTION = "test description" _TEST_TABULAR_CLASSIFICATION_GCS_SOURCE = "gs://ucaip-sample-resources/iris_1000.csv" +_TEST_FORECASTING_BQ_SOURCE = ( + "bq://ucaip-sample-tests:ucaip_test_us_central1.2020_sales_train" +) _TEST_TEXT_ENTITY_EXTRACTION_GCS_SOURCE = f"gs://{TEST_BUCKET}/ai-platform-unified/sdk/datasets/text_entity_extraction_dataset.jsonl" _TEST_IMAGE_OBJECT_DETECTION_GCS_SOURCE = ( "gs://ucaip-test-us-central1/dataset/salads_oid_ml_use_public_unassigned.jsonl" @@ -56,39 +63,89 @@ _TEST_TEXT_ENTITY_IMPORT_SCHEMA = "gs://google-cloud-aiplatform/schema/dataset/ioformat/text_extraction_io_format_1.0.0.yaml" _TEST_IMAGE_OBJ_DET_IMPORT_SCHEMA = "gs://google-cloud-aiplatform/schema/dataset/ioformat/image_bounding_box_io_format_1.0.0.yaml" +# create_from_dataframe +_TEST_BOOL_COL = "bool_col" +_TEST_BOOL_ARR_COL = "bool_array_col" +_TEST_DOUBLE_COL = "double_col" +_TEST_DOUBLE_ARR_COL = "double_array_col" +_TEST_INT_COL = "int64_col" +_TEST_INT_ARR_COL = "int64_array_col" +_TEST_STR_COL = "string_col" +_TEST_STR_ARR_COL = "string_array_col" +_TEST_BYTES_COL = "bytes_col" +_TEST_DF_COLUMN_NAMES = [ + _TEST_BOOL_COL, + _TEST_BOOL_ARR_COL, + _TEST_DOUBLE_COL, + _TEST_DOUBLE_ARR_COL, + _TEST_INT_COL, + _TEST_INT_ARR_COL, + _TEST_STR_COL, + _TEST_STR_ARR_COL, + _TEST_BYTES_COL, +] +_TEST_DATAFRAME = pd.DataFrame( + data=[ + [ + False, + [True, False], + 1.2, + [1.2, 3.4], + 1, + [1, 2], + "test", + ["test1", "test2"], + b"1", + ], + [ + True, + [True, True], + 2.2, + [2.2, 4.4], + 2, + [2, 3], + "test1", + ["test2", "test3"], + b"0", + ], + ], + columns=_TEST_DF_COLUMN_NAMES, +) +_TEST_DATAFRAME_BQ_SCHEMA = [ + bigquery.SchemaField(name="bool_col", field_type="BOOL"), + bigquery.SchemaField(name="bool_array_col", field_type="BOOL", mode="REPEATED"), + bigquery.SchemaField(name="double_col", field_type="FLOAT"), + bigquery.SchemaField(name="double_array_col", field_type="FLOAT", mode="REPEATED"), + bigquery.SchemaField(name="int64_col", field_type="INTEGER"), + bigquery.SchemaField(name="int64_array_col", field_type="INTEGER", mode="REPEATED"), + bigquery.SchemaField(name="string_col", field_type="STRING"), + bigquery.SchemaField(name="string_array_col", field_type="STRING", mode="REPEATED"), + bigquery.SchemaField(name="bytes_col", field_type="STRING"), +] + + +class TestDataset(e2e_base.TestEndToEnd): + + _temp_prefix = "temp-vertex-sdk-dataset-test" -class TestDataset: def setup_method(self): importlib.reload(initializer) importlib.reload(aiplatform) - @pytest.fixture() - def shared_state(self): - shared_state = {} - yield shared_state + aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) @pytest.fixture() - def create_staging_bucket(self, shared_state): - new_staging_bucket = f"temp-sdk-integration-{uuid.uuid4()}" - - storage_client = storage.Client() - storage_client.create_bucket(new_staging_bucket) - shared_state["storage_client"] = storage_client - shared_state["staging_bucket"] = new_staging_bucket - yield + def storage_client(self): + yield storage.Client(project=_TEST_PROJECT) @pytest.fixture() - def delete_staging_bucket(self, shared_state): - yield - storage_client = shared_state["storage_client"] + def staging_bucket(self, storage_client): + new_staging_bucket = f"temp-sdk-integration-{uuid.uuid4()}" + bucket = storage_client.create_bucket(new_staging_bucket) - # Delete temp staging bucket - bucket_to_delete = storage_client.get_bucket(shared_state["staging_bucket"]) - bucket_to_delete.delete(force=True) + yield bucket - # Close Storage Client - storage_client._http._auth_request.session.close() - storage_client._http.close() + bucket.delete(force=True) @pytest.fixture() def dataset_gapic_client(self): @@ -98,71 +155,12 @@ def dataset_gapic_client(self): yield gapic_client - @pytest.fixture() - def create_text_dataset(self, dataset_gapic_client, shared_state): - - gapic_dataset = gca_dataset.Dataset( - display_name=f"temp_sdk_integration_test_create_text_dataset_{uuid.uuid4()}", - metadata_schema_uri=aiplatform.schema.dataset.metadata.text, - ) - - create_lro = dataset_gapic_client.create_dataset( - parent=_TEST_PARENT, dataset=gapic_dataset - ) - new_dataset = create_lro.result() - shared_state["dataset_name"] = new_dataset.name - yield - - @pytest.fixture() - def create_tabular_dataset(self, dataset_gapic_client, shared_state): - - gapic_dataset = gca_dataset.Dataset( - display_name=f"temp_sdk_integration_test_create_tabular_dataset_{uuid.uuid4()}", - metadata_schema_uri=aiplatform.schema.dataset.metadata.tabular, - ) - - create_lro = dataset_gapic_client.create_dataset( - parent=_TEST_PARENT, dataset=gapic_dataset - ) - new_dataset = create_lro.result() - shared_state["dataset_name"] = new_dataset.name - yield - - @pytest.fixture() - def create_image_dataset(self, dataset_gapic_client, shared_state): - - gapic_dataset = gca_dataset.Dataset( - display_name=f"temp_sdk_integration_test_create_image_dataset_{uuid.uuid4()}", - metadata_schema_uri=aiplatform.schema.dataset.metadata.image, - ) - - create_lro = dataset_gapic_client.create_dataset( - parent=_TEST_PARENT, dataset=gapic_dataset - ) - new_dataset = create_lro.result() - shared_state["dataset_name"] = new_dataset.name - yield - - @pytest.fixture() - def delete_new_dataset(self, dataset_gapic_client, shared_state): - yield - assert shared_state["dataset_name"] - - deletion_lro = dataset_gapic_client.delete_dataset( - name=shared_state["dataset_name"] - ) - deletion_lro.result() - - shared_state["dataset_name"] = None - # TODO(vinnys): Remove pytest skip once persistent resources are accessible @pytest.mark.skip(reason="System tests cannot access persistent test resources") def test_get_existing_dataset(self): """Retrieve a known existing dataset, ensure SDK successfully gets the dataset resource.""" - aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) - flowers_dataset = aiplatform.ImageDataset(dataset_name=_TEST_IMAGE_DATASET_ID) assert flowers_dataset.name == _TEST_IMAGE_DATASET_ID assert flowers_dataset.display_name == _TEST_DATASET_DISPLAY_NAME @@ -171,117 +169,209 @@ def test_get_nonexistent_dataset(self): """Ensure attempting to retrieve a dataset that doesn't exist raises a Google API core 404 exception.""" - aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) - # AI Platform service returns 404 with pytest.raises(exceptions.NotFound): aiplatform.ImageDataset(dataset_name="0") - @pytest.mark.usefixtures("create_text_dataset", "delete_new_dataset") - def test_get_new_dataset_and_import(self, dataset_gapic_client, shared_state): + def test_get_new_dataset_and_import(self, dataset_gapic_client): """Retrieve new, empty dataset and import a text dataset using import(). Then verify data items were successfully imported.""" - assert shared_state["dataset_name"] - aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) + try: + text_dataset = aiplatform.TextDataset.create( + display_name=self._make_display_name(key="get_new_dataset_and_import"), + ) - my_dataset = aiplatform.TextDataset(dataset_name=shared_state["dataset_name"]) + my_dataset = aiplatform.TextDataset(dataset_name=text_dataset.name) - data_items_pre_import = dataset_gapic_client.list_data_items( - parent=my_dataset.resource_name - ) + data_items_pre_import = dataset_gapic_client.list_data_items( + parent=my_dataset.resource_name + ) - assert len(list(data_items_pre_import)) == 0 + assert len(list(data_items_pre_import)) == 0 - # Blocking call to import - my_dataset.import_data( - gcs_source=_TEST_TEXT_ENTITY_EXTRACTION_GCS_SOURCE, - import_schema_uri=_TEST_TEXT_ENTITY_IMPORT_SCHEMA, - ) + # Blocking call to import + my_dataset.import_data( + gcs_source=_TEST_TEXT_ENTITY_EXTRACTION_GCS_SOURCE, + import_schema_uri=_TEST_TEXT_ENTITY_IMPORT_SCHEMA, + import_request_timeout=500, + ) - data_items_post_import = dataset_gapic_client.list_data_items( - parent=my_dataset.resource_name - ) + data_items_post_import = dataset_gapic_client.list_data_items( + parent=my_dataset.resource_name + ) - assert len(list(data_items_post_import)) == 469 + assert len(list(data_items_post_import)) == 469 + finally: + text_dataset.delete() @vpcsc_config.skip_if_inside_vpcsc - @pytest.mark.usefixtures("delete_new_dataset") - def test_create_and_import_image_dataset(self, dataset_gapic_client, shared_state): + def test_create_and_import_image_dataset(self, dataset_gapic_client): """Use the Dataset.create() method to create a new image obj detection dataset and import images. Then confirm images were successfully imported.""" - aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) - - img_dataset = aiplatform.ImageDataset.create( - display_name=f"temp_sdk_integration_create_and_import_dataset_{uuid.uuid4()}", - gcs_source=_TEST_IMAGE_OBJECT_DETECTION_GCS_SOURCE, - import_schema_uri=_TEST_IMAGE_OBJ_DET_IMPORT_SCHEMA, - ) + try: + img_dataset = aiplatform.ImageDataset.create( + display_name=self._make_display_name( + key="create_and_import_image_dataset" + ), + gcs_source=_TEST_IMAGE_OBJECT_DETECTION_GCS_SOURCE, + import_schema_uri=_TEST_IMAGE_OBJ_DET_IMPORT_SCHEMA, + create_request_timeout=None, + ) - shared_state["dataset_name"] = img_dataset.resource_name + data_items_iterator = dataset_gapic_client.list_data_items( + parent=img_dataset.resource_name + ) - data_items_iterator = dataset_gapic_client.list_data_items( - parent=img_dataset.resource_name - ) + assert len(list(data_items_iterator)) == 14 - assert len(list(data_items_iterator)) == 14 + finally: + if img_dataset is not None: + img_dataset.delete() - @pytest.mark.usefixtures("delete_new_dataset") - def test_create_tabular_dataset(self, dataset_gapic_client, shared_state): + def test_create_tabular_dataset(self): """Use the Dataset.create() method to create a new tabular dataset. Then confirm the dataset was successfully created and references GCS source.""" - aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) + try: + tabular_dataset = aiplatform.TabularDataset.create( + display_name=self._make_display_name(key="create_tabular_dataset"), + gcs_source=[_TEST_TABULAR_CLASSIFICATION_GCS_SOURCE], + create_request_timeout=None, + ) + + gapic_metadata = tabular_dataset.to_dict()["metadata"] + gcs_source_uris = gapic_metadata["inputConfig"]["gcsSource"]["uri"] + + assert len(gcs_source_uris) == 1 + assert _TEST_TABULAR_CLASSIFICATION_GCS_SOURCE == gcs_source_uris[0] + assert ( + tabular_dataset.metadata_schema_uri + == aiplatform.schema.dataset.metadata.tabular + ) + + finally: + if tabular_dataset is not None: + tabular_dataset.delete() + + def test_create_tabular_dataset_from_dataframe(self, bigquery_dataset): + bq_staging_table = f"bq://{_TEST_PROJECT}.{bigquery_dataset.dataset_id}.test_table{uuid.uuid4()}" + + try: + tabular_dataset = aiplatform.TabularDataset.create_from_dataframe( + df_source=_TEST_DATAFRAME, + staging_path=bq_staging_table, + display_name=self._make_display_name( + key="create_and_import_dataset_from_dataframe" + ), + ) + + """Use the Dataset.create_from_dataframe() method to create a new tabular dataset. + Then confirm the dataset was successfully created and references the BQ source.""" + gapic_metadata = tabular_dataset.to_dict()["metadata"] + bq_source = gapic_metadata["inputConfig"]["bigquerySource"]["uri"] + + assert bq_staging_table == bq_source + assert ( + tabular_dataset.metadata_schema_uri + == aiplatform.schema.dataset.metadata.tabular + ) + finally: + if tabular_dataset is not None: + tabular_dataset.delete() + + def test_create_tabular_dataset_from_dataframe_with_provided_schema( + self, bigquery_dataset + ): + """Use the Dataset.create_from_dataframe() method to create a new tabular dataset, + passing in the optional `bq_schema` argument. Then confirm the dataset was successfully + created and references the BQ source.""" + + try: + bq_staging_table = f"bq://{_TEST_PROJECT}.{bigquery_dataset.dataset_id}.test_table{uuid.uuid4()}" + + tabular_dataset = aiplatform.TabularDataset.create_from_dataframe( + df_source=_TEST_DATAFRAME, + staging_path=bq_staging_table, + display_name=self._make_display_name( + key="create_and_import_dataset_from_dataframe" + ), + bq_schema=_TEST_DATAFRAME_BQ_SCHEMA, + ) + + gapic_metadata = tabular_dataset.to_dict()["metadata"] + bq_source = gapic_metadata["inputConfig"]["bigquerySource"]["uri"] + + assert bq_staging_table == bq_source + assert ( + tabular_dataset.metadata_schema_uri + == aiplatform.schema.dataset.metadata.tabular + ) + finally: + tabular_dataset.delete() + + def test_create_time_series_dataset(self): + """Use the Dataset.create() method to create a new time series dataset. + Then confirm the dataset was successfully created and references GCS source.""" - tabular_dataset = aiplatform.TabularDataset.create( - display_name=f"temp_sdk_integration_create_and_import_dataset_{uuid.uuid4()}", - gcs_source=[_TEST_TABULAR_CLASSIFICATION_GCS_SOURCE], - ) + try: + time_series_dataset = aiplatform.TimeSeriesDataset.create( + display_name=self._make_display_name(key="create_time_series_dataset"), + bq_source=[_TEST_FORECASTING_BQ_SOURCE], + create_request_timeout=None, + ) - gapic_dataset = tabular_dataset._gca_resource - shared_state["dataset_name"] = tabular_dataset.resource_name + gapic_metadata = time_series_dataset.to_dict()["metadata"] + bq_source_uri = gapic_metadata["inputConfig"]["bigquerySource"]["uri"] - gapic_metadata = json_format.MessageToDict(gapic_dataset._pb.metadata) - gcs_source_uris = gapic_metadata["inputConfig"]["gcsSource"]["uri"] + assert _TEST_FORECASTING_BQ_SOURCE == bq_source_uri + assert ( + time_series_dataset.metadata_schema_uri + == aiplatform.schema.dataset.metadata.time_series + ) - assert len(gcs_source_uris) == 1 - assert _TEST_TABULAR_CLASSIFICATION_GCS_SOURCE == gcs_source_uris[0] - assert ( - gapic_dataset.metadata_schema_uri - == aiplatform.schema.dataset.metadata.tabular - ) + finally: + if time_series_dataset is not None: + time_series_dataset.delete() - # TODO(vinnys): Remove pytest skip once persistent resources are accessible - @pytest.mark.skip(reason="System tests cannot access persistent test resources") - @pytest.mark.usefixtures("create_staging_bucket", "delete_staging_bucket") - def test_export_data(self, shared_state): + def test_export_data(self, storage_client, staging_bucket): """Get an existing dataset, export data to a newly created folder in Google Cloud Storage, then verify data was successfully exported.""" - assert shared_state["staging_bucket"] - assert shared_state["storage_client"] - - aiplatform.init( - project=_TEST_PROJECT, - location=_TEST_LOCATION, - staging_bucket=f"gs://{shared_state['staging_bucket']}", - ) - - text_dataset = aiplatform.TextDataset(dataset_name=_TEST_TEXT_DATASET_ID) + dataset = aiplatform.TextDataset(dataset_name=_TEST_TEXT_DATASET_ID) - exported_files = text_dataset.export_data( - output_dir=f"gs://{shared_state['staging_bucket']}" - ) + exported_files = dataset.export_data(output_dir=f"gs://{staging_bucket.name}") assert len(exported_files) # Ensure at least one GCS path was returned exported_file = exported_files[0] bucket, prefix = utils.extract_bucket_and_prefix_from_gcs_path(exported_file) - storage_client = shared_state["storage_client"] - bucket = storage_client.get_bucket(bucket) blob = bucket.get_blob(prefix) assert blob # Verify the returned GCS export path exists + + def test_update_dataset(self): + """Create a new dataset and use update() method to change its display_name, labels, and description. + Then confirm these fields of the dataset was successfully modifed.""" + + try: + dataset = aiplatform.ImageDataset.create() + labels = dataset.labels + + dataset = dataset.update( + display_name=_TEST_DATASET_DISPLAY_NAME, + labels=_TEST_DATASET_LABELS, + description=_TEST_DATASET_DESCRIPTION, + update_request_timeout=None, + ) + labels.update(_TEST_DATASET_LABELS) + + assert dataset.display_name == _TEST_DATASET_DISPLAY_NAME + assert dataset.labels == labels + assert dataset.gca_resource.description == _TEST_DATASET_DESCRIPTION + + finally: + dataset.delete() diff --git a/tests/system/aiplatform/test_e2e_forecasting.py b/tests/system/aiplatform/test_e2e_forecasting.py new file mode 100644 index 0000000000..024946b91b --- /dev/null +++ b/tests/system/aiplatform/test_e2e_forecasting.py @@ -0,0 +1,124 @@ +# -*- coding: utf-8 -*- + +# Copyright 2022 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 google.cloud import aiplatform +from google.cloud.aiplatform import training_jobs +from google.cloud.aiplatform.compat.types import job_state +from google.cloud.aiplatform.compat.types import pipeline_state +import pytest +from tests.system.aiplatform import e2e_base + +_TRAINING_DATASET_BQ_PATH = ( + "bq://ucaip-sample-tests:ucaip_test_us_central1.2020_sales_train" +) +_PREDICTION_DATASET_BQ_PATH = ( + "bq://ucaip-sample-tests:ucaip_test_us_central1.2021_sales_predict" +) + + +@pytest.mark.usefixtures("prepare_staging_bucket", "delete_staging_bucket") +class TestEndToEndForecasting(e2e_base.TestEndToEnd): + """End to end system test of the Vertex SDK with forecasting data.""" + + _temp_prefix = "temp-vertex-sdk-e2e-forecasting" + + @pytest.mark.parametrize( + "training_job", + [ + training_jobs.AutoMLForecastingTrainingJob, + pytest.param( + training_jobs.SequenceToSequencePlusForecastingTrainingJob, + marks=pytest.mark.skip(reason="Seq2Seq not yet released."), + ), + ], + ) + def test_end_to_end_forecasting(self, shared_state, training_job): + """Builds a dataset, trains models, and gets batch predictions.""" + resources = [] + + aiplatform.init( + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + staging_bucket=shared_state["staging_bucket_name"], + ) + try: + ds = aiplatform.TimeSeriesDataset.create( + display_name=self._make_display_name("dataset"), + bq_source=[_TRAINING_DATASET_BQ_PATH], + sync=False, + create_request_timeout=180.0, + ) + resources.append(ds) + + time_column = "date" + time_series_identifier_column = "store_name" + target_column = "sale_dollars" + column_specs = { + time_column: "timestamp", + target_column: "numeric", + "city": "categorical", + "zip_code": "categorical", + "county": "categorical", + } + + job = training_job( + display_name=self._make_display_name("train-housing-forecasting"), + optimization_objective="minimize-rmse", + column_specs=column_specs, + ) + resources.append(job) + + model = job.run( + dataset=ds, + target_column=target_column, + time_column=time_column, + time_series_identifier_column=time_series_identifier_column, + available_at_forecast_columns=[time_column], + unavailable_at_forecast_columns=[target_column], + time_series_attribute_columns=["city", "zip_code", "county"], + forecast_horizon=30, + context_window=30, + data_granularity_unit="day", + data_granularity_count=1, + budget_milli_node_hours=1000, + holiday_regions=["GLOBAL"], + hierarchy_group_total_weight=1, + window_stride_length=1, + model_display_name=self._make_display_name("forecasting-liquor-model"), + sync=False, + ) + resources.append(model) + + batch_prediction_job = model.batch_predict( + job_display_name=self._make_display_name("forecasting-liquor-model"), + instances_format="bigquery", + predictions_format="csv", + machine_type="n1-standard-4", + bigquery_source=_PREDICTION_DATASET_BQ_PATH, + gcs_destination_prefix=( + f'gs://{shared_state["staging_bucket_name"]}/bp_results/' + ), + sync=False, + ) + resources.append(batch_prediction_job) + + batch_prediction_job.wait() + assert job.state == pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + assert batch_prediction_job.state == job_state.JobState.JOB_STATE_SUCCEEDED + finally: + for resource in resources: + resource.delete() diff --git a/tests/system/aiplatform/test_e2e_metadata_schema.py b/tests/system/aiplatform/test_e2e_metadata_schema.py new file mode 100644 index 0000000000..238e32606b --- /dev/null +++ b/tests/system/aiplatform/test_e2e_metadata_schema.py @@ -0,0 +1,114 @@ +# -*- coding: utf-8 -*- + +# Copyright 2022 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. +# +import json + +import pytest + +from google.cloud import aiplatform +from google.cloud.aiplatform.metadata.schema.google import ( + artifact_schema as google_artifact_schema, +) +from google.cloud.aiplatform.metadata.schema.system import ( + artifact_schema as system_artifact_schema, +) +from google.cloud.aiplatform.metadata.schema.system import ( + execution_schema as system_execution_schema, +) +from tests.system.aiplatform import e2e_base + + +@pytest.mark.usefixtures("tear_down_resources") +class TestMetadataSchema(e2e_base.TestEndToEnd): + + _temp_prefix = "tmpvrtxmlmdsdk-e2e" + + def setup_class(cls): + # Truncating the name because of resource id constraints from the service + cls.artifact_display_name = cls._make_display_name("base-artifact")[:30] + cls.artifact_id = cls._make_display_name("base-artifact-id")[:30] + cls.artifact_uri = cls._make_display_name("base-uri") + cls.artifact_metadata = {"test_property": "test_value"} + cls.artifact_description = cls._make_display_name("base-description") + cls.execution_display_name = cls._make_display_name("base-execution")[:30] + cls.execution_description = cls._make_display_name("base-description") + + def test_system_dataset_artifact_create(self): + + aiplatform.init( + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + ) + + artifact = system_artifact_schema.Dataset( + display_name=self.artifact_display_name, + uri=self.artifact_uri, + metadata=self.artifact_metadata, + description=self.artifact_description, + ).create() + + assert artifact.display_name == self.artifact_display_name + assert json.dumps(artifact.metadata, sort_keys=True) == json.dumps( + self.artifact_metadata, sort_keys=True + ) + assert artifact.schema_title == "system.Dataset" + assert artifact.description == self.artifact_description + assert "/metadataStores/default/artifacts/" in artifact.resource_name + + def test_google_dataset_artifact_create(self): + + aiplatform.init( + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + ) + vertex_dataset_name = f"projects/{e2e_base._PROJECT}/locations/{e2e_base._LOCATION}/datasets/dataset" + artifact = google_artifact_schema.VertexDataset( + vertex_dataset_name=vertex_dataset_name, + display_name=self.artifact_display_name, + metadata=self.artifact_metadata, + description=self.artifact_description, + ).create() + expected_metadata = self.artifact_metadata.copy() + expected_metadata["resourceName"] = vertex_dataset_name + + assert artifact.display_name == self.artifact_display_name + assert json.dumps(artifact.metadata, sort_keys=True) == json.dumps( + expected_metadata, sort_keys=True + ) + assert artifact.schema_title == "google.VertexDataset" + assert artifact.description == self.artifact_description + assert "/metadataStores/default/artifacts/" in artifact.resource_name + assert ( + artifact.uri + == f"https://{e2e_base._LOCATION}-aiplatform.googleapis.com/v1/{vertex_dataset_name}" + ) + + def test_execution_create_using_system_schema_class(self): + + aiplatform.init( + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + ) + + execution = system_execution_schema.CustomJobExecution( + display_name=self.execution_display_name, + description=self.execution_description, + ).create() + + assert execution.display_name == self.execution_display_name + assert execution.schema_title == "system.CustomJobExecution" + assert execution.description == self.execution_description + assert "/metadataStores/default/executions/" in execution.resource_name diff --git a/tests/system/aiplatform/test_e2e_tabular.py b/tests/system/aiplatform/test_e2e_tabular.py new file mode 100644 index 0000000000..6746e816a9 --- /dev/null +++ b/tests/system/aiplatform/test_e2e_tabular.py @@ -0,0 +1,216 @@ +# -*- coding: utf-8 -*- + +# 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 +# +# 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. +# + +import os +from urllib import request + +import pytest + +from google.cloud import aiplatform +from google.cloud.aiplatform.compat.types import ( + job_state as gca_job_state, + pipeline_state as gca_pipeline_state, +) +from tests.system.aiplatform import e2e_base + + +_BLOB_PATH = "california-housing-data.csv" +_DATASET_SRC = "https://dl.google.com/mlcc/mledu-datasets/california_housing_train.csv" +_DIR_NAME = os.path.dirname(os.path.abspath(__file__)) +_LOCAL_TRAINING_SCRIPT_PATH = os.path.join( + _DIR_NAME, "test_resources/california_housing_training_script.py" +) +_INSTANCE = { + "longitude": -124.35, + "latitude": 40.54, + "housing_median_age": 52.0, + "total_rooms": 1820.0, + "total_bedrooms": 300.0, + "population": 806, + "households": 270.0, + "median_income": 3.014700, +} + + +@pytest.mark.usefixtures( + "prepare_staging_bucket", "delete_staging_bucket", "tear_down_resources" +) +class TestEndToEndTabular(e2e_base.TestEndToEnd): + """End to end system test of the Vertex SDK with tabular data adapted from + reference notebook http://shortn/_eyoNx3SN0X""" + + _temp_prefix = "temp-vertex-sdk-e2e-tabular" + + def test_end_to_end_tabular(self, shared_state): + """Build dataset, train a custom and AutoML model, deploy, and get predictions""" + + assert shared_state["bucket"] + bucket = shared_state["bucket"] + + blob = bucket.blob(_BLOB_PATH) + + # Download the CSV file into memory and save it directory to staging bucket + with request.urlopen(_DATASET_SRC) as response: + data = response.read() + blob.upload_from_string(data) + + # Collection of resources generated by this test, to be deleted during teardown + shared_state["resources"] = [] + + aiplatform.init( + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + staging_bucket=shared_state["staging_bucket_name"], + ) + + # Create and import to single managed dataset for both training jobs + + dataset_gcs_source = f'gs://{shared_state["staging_bucket_name"]}/{_BLOB_PATH}' + + ds = aiplatform.TabularDataset.create( + display_name=self._make_display_name("dataset"), + gcs_source=[dataset_gcs_source], + sync=False, + create_request_timeout=180.0, + ) + + shared_state["resources"].extend([ds]) + + # Define both training jobs + + custom_job = aiplatform.CustomTrainingJob( + display_name=self._make_display_name("train-housing-custom"), + script_path=_LOCAL_TRAINING_SCRIPT_PATH, + container_uri="gcr.io/cloud-aiplatform/training/tf-cpu.2-2:latest", + requirements=["gcsfs==0.7.1"], + model_serving_container_image_uri="gcr.io/cloud-aiplatform/prediction/tf2-cpu.2-2:latest", + ) + + automl_job = aiplatform.AutoMLTabularTrainingJob( + display_name=self._make_display_name("train-housing-automl"), + optimization_prediction_type="regression", + optimization_objective="minimize-rmse", + ) + + # Kick off both training jobs, AutoML job will take approx one hour to run + + custom_model = custom_job.run( + ds, + replica_count=1, + model_display_name=self._make_display_name("custom-housing-model"), + timeout=1234, + restart_job_on_worker_restart=True, + enable_web_access=True, + sync=False, + create_request_timeout=None, + ) + + automl_model = automl_job.run( + dataset=ds, + target_column="median_house_value", + model_display_name=self._make_display_name("automl-housing-model"), + sync=False, + ) + + shared_state["resources"].extend( + [automl_job, automl_model, custom_job, custom_model] + ) + + # Deploy both models after training completes + custom_endpoint = custom_model.deploy(machine_type="n1-standard-4", sync=False) + automl_endpoint = automl_model.deploy(machine_type="n1-standard-4", sync=False) + shared_state["resources"].extend([automl_endpoint, custom_endpoint]) + + custom_batch_prediction_job = custom_model.batch_predict( + job_display_name=self._make_display_name("automl-housing-model"), + instances_format="csv", + machine_type="n1-standard-4", + gcs_source=dataset_gcs_source, + gcs_destination_prefix=f'gs://{shared_state["staging_bucket_name"]}/bp_results/', + sync=False, + ) + + shared_state["resources"].append(custom_batch_prediction_job) + + in_progress_done_check = custom_job.done() + custom_job.wait_for_resource_creation() + + automl_job.wait_for_resource_creation() + custom_batch_prediction_job.wait_for_resource_creation() + + # Send online prediction with same instance to both deployed models + # This sample is taken from an observation where median_house_value = 94600 + custom_endpoint.wait() + + # Check scheduling is correctly set + assert ( + custom_job._gca_resource.training_task_inputs["scheduling"]["timeout"] + == "1234s" + ) + assert ( + custom_job._gca_resource.training_task_inputs["scheduling"][ + "restartJobOnWorkerRestart" + ] + is True + ) + + custom_prediction = custom_endpoint.predict([_INSTANCE], timeout=180.0) + + custom_batch_prediction_job.wait() + + automl_endpoint.wait() + automl_prediction = automl_endpoint.predict( + [{k: str(v) for k, v in _INSTANCE.items()}], # Cast int values to strings + timeout=180.0, + ) + + # Test lazy loading of Endpoint, check getter was never called after predict() + custom_endpoint = aiplatform.Endpoint(custom_endpoint.resource_name) + custom_endpoint.predict([_INSTANCE]) + + completion_done_check = custom_job.done() + assert custom_endpoint._skipped_getter_call() + + assert ( + custom_job.state + == gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) + assert ( + automl_job.state + == gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) + assert ( + custom_batch_prediction_job.state + == gca_job_state.JobState.JOB_STATE_SUCCEEDED + ) + + # Ensure a single prediction was returned + assert len(custom_prediction.predictions) == 1 + assert len(automl_prediction.predictions) == 1 + + # Ensure the models are remotely accurate + try: + automl_result = automl_prediction.predictions[0]["value"] + custom_result = custom_prediction.predictions[0][0] + assert 200000 > automl_result > 50000 + assert 200000 > custom_result > 50000 + except KeyError as e: + raise RuntimeError("Unexpected prediction response structure:", e) + + # Check done() method works correctly + assert in_progress_done_check is False + assert completion_done_check is True diff --git a/tests/system/aiplatform/test_experiments.py b/tests/system/aiplatform/test_experiments.py new file mode 100644 index 0000000000..c65cb0c723 --- /dev/null +++ b/tests/system/aiplatform/test_experiments.py @@ -0,0 +1,383 @@ +# -*- coding: utf-8 -*- + +# 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 +# +# 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. +# +import tempfile + +import pytest + +from google.api_core import exceptions +from google.cloud import storage + +from google.cloud import aiplatform +from google.cloud.aiplatform.utils import rest_utils +from tests.system.aiplatform import e2e_base +from tests.system.aiplatform import test_model_upload + + +_RUN = "run-1" +_PARAMS = {"sdk-param-test-1": 0.1, "sdk-param-test-2": 0.2} +_METRICS = {"sdk-metric-test-1": 0.8, "sdk-metric-test-2": 100.0} + +_RUN_2 = "run-2" +_PARAMS_2 = {"sdk-param-test-1": 0.2, "sdk-param-test-2": 0.4} +_METRICS_2 = {"sdk-metric-test-1": 1.6, "sdk-metric-test-2": 200.0} + +_TIME_SERIES_METRIC_KEY = "accuracy" + + +@pytest.mark.usefixtures( + "prepare_staging_bucket", "delete_staging_bucket", "tear_down_resources" +) +class TestExperiments(e2e_base.TestEndToEnd): + + _temp_prefix = "tmpvrtxsdk-e2e" + + def setup_class(cls): + cls._experiment_name = cls._make_display_name("")[:64] + cls._dataset_artifact_name = cls._make_display_name("")[:64] + cls._dataset_artifact_uri = cls._make_display_name("ds-uri") + cls._pipeline_job_id = cls._make_display_name("job-id") + + def test_create_experiment(self, shared_state): + + # Truncating the name because of resource id constraints from the service + tensorboard = aiplatform.Tensorboard.create( + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + display_name=self._experiment_name, + ) + + shared_state["resources"] = [tensorboard] + + aiplatform.init( + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + experiment=self._experiment_name, + experiment_tensorboard=tensorboard, + ) + + shared_state["resources"].append( + aiplatform.metadata.metadata._experiment_tracker.experiment + ) + + def test_get_experiment(self): + experiment = aiplatform.Experiment( + experiment_name=self._experiment_name, + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + ) + assert experiment.name == self._experiment_name + + def test_start_run(self): + aiplatform.init( + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + experiment=self._experiment_name, + ) + run = aiplatform.start_run(_RUN) + assert run.name == _RUN + + def test_get_run(self): + run = aiplatform.ExperimentRun( + run_name=_RUN, + experiment=self._experiment_name, + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + ) + assert run.name == _RUN + assert run.state == aiplatform.gapic.Execution.State.RUNNING + + def test_log_params(self): + aiplatform.init( + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + experiment=self._experiment_name, + ) + aiplatform.start_run(_RUN, resume=True) + aiplatform.log_params(_PARAMS) + run = aiplatform.ExperimentRun(run_name=_RUN, experiment=self._experiment_name) + assert run.get_params() == _PARAMS + + def test_log_metrics(self): + aiplatform.init( + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + experiment=self._experiment_name, + ) + aiplatform.start_run(_RUN, resume=True) + aiplatform.log_metrics(_METRICS) + run = aiplatform.ExperimentRun(run_name=_RUN, experiment=self._experiment_name) + assert run.get_metrics() == _METRICS + + def test_log_time_series_metrics(self): + aiplatform.init( + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + experiment=self._experiment_name, + ) + + aiplatform.start_run(_RUN, resume=True) + + for i in range(5): + aiplatform.log_time_series_metrics({_TIME_SERIES_METRIC_KEY: i}) + + run = aiplatform.ExperimentRun(run_name=_RUN, experiment=self._experiment_name) + + time_series_result = run.get_time_series_data_frame()[ + [_TIME_SERIES_METRIC_KEY, "step"] + ].to_dict("list") + + assert time_series_result == { + "step": list(range(1, 6)), + _TIME_SERIES_METRIC_KEY: [float(value) for value in range(5)], + } + + def test_create_artifact(self, shared_state): + ds = aiplatform.Artifact.create( + schema_title="system.Dataset", + resource_id=self._dataset_artifact_name, + uri=self._dataset_artifact_uri, + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + ) + + shared_state["resources"].append(ds) + assert ds.uri == self._dataset_artifact_uri + + def test_get_artifact_by_uri(self): + ds = aiplatform.Artifact.get_with_uri( + uri=self._dataset_artifact_uri, + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + ) + + assert ds.uri == self._dataset_artifact_uri + assert ds.name == self._dataset_artifact_name + + def test_log_execution_and_artifact(self, shared_state): + aiplatform.init( + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + experiment=self._experiment_name, + ) + aiplatform.start_run(_RUN, resume=True) + + with aiplatform.start_execution( + schema_title="system.ContainerExecution", + resource_id=self._make_display_name("execution"), + ) as execution: + + shared_state["resources"].append(execution) + + ds = aiplatform.Artifact( + artifact_name=self._dataset_artifact_name, + ) + execution.assign_input_artifacts([ds]) + + model = aiplatform.Artifact.create(schema_title="system.Model") + shared_state["resources"].append(model) + + storage_client = storage.Client(project=e2e_base._PROJECT) + model_blob = storage.Blob.from_string( + uri=test_model_upload._XGBOOST_MODEL_URI, client=storage_client + ) + model_path = tempfile.mktemp() + ".my_model.xgb" + model_blob.download_to_filename(filename=model_path) + + vertex_model = aiplatform.Model.upload_xgboost_model_file( + display_name=self._make_display_name("model"), + model_file_path=model_path, + ) + shared_state["resources"].append(vertex_model) + + execution.assign_output_artifacts([model, vertex_model]) + + input_artifacts = execution.get_input_artifacts() + assert input_artifacts[0].name == ds.name + + output_artifacts = execution.get_output_artifacts() + # system.Model, google.VertexModel + output_artifacts.sort(key=lambda artifact: artifact.schema_title, reverse=True) + + shared_state["resources"].append(output_artifacts[-1]) + + assert output_artifacts[0].name == model.name + assert output_artifacts[1].uri == rest_utils.make_gcp_resource_rest_url( + resource=vertex_model + ) + + run = aiplatform.ExperimentRun(run_name=_RUN, experiment=self._experiment_name) + executions = run.get_executions() + assert executions[0].name == execution.name + + artifacts = run.get_artifacts() + + # system.Model, system.Dataset, google.VertexTensorboardRun, google.VertexModel + artifacts.sort(key=lambda artifact: artifact.schema_title, reverse=True) + assert artifacts.pop().uri == rest_utils.make_gcp_resource_rest_url( + resource=vertex_model + ) + + # tensorboard run artifact is also included + assert sorted([artifact.name for artifact in artifacts]) == sorted( + [ds.name, model.name, run._tensorboard_run_id(run.resource_id)] + ) + + def test_end_run(self): + aiplatform.init( + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + experiment=self._experiment_name, + ) + aiplatform.start_run(_RUN, resume=True) + aiplatform.end_run() + run = aiplatform.ExperimentRun(run_name=_RUN, experiment=self._experiment_name) + assert run.state == aiplatform.gapic.Execution.State.COMPLETE + + def test_run_context_manager(self): + aiplatform.init( + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + experiment=self._experiment_name, + ) + with aiplatform.start_run(_RUN_2) as run: + run.log_params(_PARAMS_2) + run.log_metrics(_METRICS_2) + assert run.state == aiplatform.gapic.Execution.State.RUNNING + + assert run.state == aiplatform.gapic.Execution.State.COMPLETE + + def test_add_pipeline_job_to_experiment(self, shared_state): + import kfp.v2.dsl as dsl + import kfp.v2.compiler as compiler + from kfp.v2.dsl import component, Metrics, Output + + @component + def trainer( + learning_rate: float, dropout_rate: float, metrics: Output[Metrics] + ): + metrics.log_metric("accuracy", 0.8) + metrics.log_metric("mse", 1.2) + + @dsl.pipeline(name=self._make_display_name("pipeline")) + def pipeline(learning_rate: float, dropout_rate: float): + trainer(learning_rate=learning_rate, dropout_rate=dropout_rate) + + compiler.Compiler().compile( + pipeline_func=pipeline, package_path="pipeline.json" + ) + + job = aiplatform.PipelineJob( + display_name=self._make_display_name("experiment pipeline job"), + template_path="pipeline.json", + job_id=self._pipeline_job_id, + pipeline_root=f'gs://{shared_state["staging_bucket_name"]}', + parameter_values={"learning_rate": 0.1, "dropout_rate": 0.2}, + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + ) + + job.submit( + experiment=self._experiment_name, + ) + + shared_state["resources"].append(job) + + job.wait() + + def test_get_experiments_df(self): + aiplatform.init( + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + experiment=self._experiment_name, + ) + + df = aiplatform.get_experiment_df() + + pipelines_param_and_metrics = { + "param.dropout_rate": 0.2, + "param.learning_rate": 0.1, + "metric.accuracy": 0.8, + "metric.mse": 1.2, + } + + true_df_dict_1 = {f"metric.{key}": value for key, value in _METRICS.items()} + for key, value in _PARAMS.items(): + true_df_dict_1[f"param.{key}"] = value + + true_df_dict_1["experiment_name"] = self._experiment_name + true_df_dict_1["run_name"] = _RUN + true_df_dict_1["state"] = aiplatform.gapic.Execution.State.COMPLETE.name + true_df_dict_1["run_type"] = aiplatform.metadata.constants.SYSTEM_EXPERIMENT_RUN + true_df_dict_1[f"time_series_metric.{_TIME_SERIES_METRIC_KEY}"] = 4.0 + + true_df_dict_2 = {f"metric.{key}": value for key, value in _METRICS_2.items()} + for key, value in _PARAMS_2.items(): + true_df_dict_2[f"param.{key}"] = value + + true_df_dict_2["experiment_name"] = self._experiment_name + true_df_dict_2["run_name"] = _RUN_2 + true_df_dict_2["state"] = aiplatform.gapic.Execution.State.COMPLETE.name + true_df_dict_2["run_type"] = aiplatform.metadata.constants.SYSTEM_EXPERIMENT_RUN + true_df_dict_2[f"time_series_metric.{_TIME_SERIES_METRIC_KEY}"] = 0.0 + + true_df_dict_3 = { + "experiment_name": self._experiment_name, + "run_name": self._pipeline_job_id, + "run_type": aiplatform.metadata.constants.SYSTEM_PIPELINE_RUN, + "state": aiplatform.gapic.Execution.State.COMPLETE.name, + "time_series_metric.accuracy": 0.0, + } + + true_df_dict_3.update(pipelines_param_and_metrics) + + for key in pipelines_param_and_metrics.keys(): + true_df_dict_1[key] = 0.0 + true_df_dict_2[key] = 0.0 + + for key in _PARAMS.keys(): + true_df_dict_3[f"param.{key}"] = 0.0 + + for key in _METRICS.keys(): + true_df_dict_3[f"metric.{key}"] = 0.0 + + assert sorted( + [true_df_dict_1, true_df_dict_2, true_df_dict_3], + key=lambda d: d["run_name"], + ) == sorted(df.fillna(0.0).to_dict("records"), key=lambda d: d["run_name"]) + + def test_delete_run(self): + run = aiplatform.ExperimentRun( + run_name=_RUN, + experiment=self._experiment_name, + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + ) + run.delete(delete_backing_tensorboard_run=True) + + with pytest.raises(exceptions.NotFound): + aiplatform.ExperimentRun(run_name=_RUN, experiment=self._experiment_name) + + def test_delete_experiment(self): + experiment = aiplatform.Experiment( + experiment_name=self._experiment_name, + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + ) + experiment.delete(delete_backing_tensorboard_runs=True) + + with pytest.raises(exceptions.NotFound): + aiplatform.Experiment(experiment_name=self._experiment_name) diff --git a/tests/system/aiplatform/test_featurestore.py b/tests/system/aiplatform/test_featurestore.py new file mode 100644 index 0000000000..9573ea6556 --- /dev/null +++ b/tests/system/aiplatform/test_featurestore.py @@ -0,0 +1,645 @@ +# -*- coding: utf-8 -*- + +# 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 +# +# 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. +# + +import datetime +import logging +import pytest + +from google.cloud import aiplatform +from tests.system.aiplatform import e2e_base + +import pandas as pd + +_TEST_USERS_ENTITY_TYPE_GCS_SRC = ( + "gs://cloud-samples-data-us-central1/vertex-ai/feature-store/datasets/users.avro" +) +_TEST_MOVIES_ENTITY_TYPE_GCS_SRC = ( + "gs://cloud-samples-data-us-central1/vertex-ai/feature-store/datasets/movies.avro" +) + +_TEST_READ_INSTANCE_SRC = "gs://cloud-samples-data-us-central1/vertex-ai/feature-store/datasets/movie_prediction.csv" + +_TEST_FEATURESTORE_ID = "movie_prediction" +_TEST_USER_ENTITY_TYPE_ID = "users" +_TEST_MOVIE_ENTITY_TYPE_ID = "movies" + +_TEST_USER_AGE_FEATURE_ID = "age" +_TEST_USER_GENDER_FEATURE_ID = "gender" +_TEST_USER_LIKED_GENRES_FEATURE_ID = "liked_genres" + +_TEST_MOVIE_TITLE_FEATURE_ID = "title" +_TEST_MOVIE_GENRES_FEATURE_ID = "genres" +_TEST_MOVIE_AVERAGE_RATING_FEATURE_ID = "average_rating" + + +@pytest.mark.usefixtures( + "prepare_staging_bucket", + "delete_staging_bucket", + "prepare_bigquery_dataset", + "delete_bigquery_dataset", + "tear_down_resources", +) +class TestFeaturestore(e2e_base.TestEndToEnd): + + _temp_prefix = "temp_vertex_sdk_e2e_featurestore_test" + + def test_create_get_list_featurestore(self, shared_state): + aiplatform.init( + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + ) + + featurestore_id = self._make_display_name(key=_TEST_FEATURESTORE_ID).replace( + "-", "_" + )[:60] + featurestore = aiplatform.Featurestore.create( + featurestore_id=featurestore_id, online_store_fixed_node_count=1 + ) + + shared_state["resources"] = [featurestore] + shared_state["featurestore"] = featurestore + shared_state["featurestore_name"] = featurestore.resource_name + + get_featurestore = aiplatform.Featurestore( + featurestore_name=featurestore.resource_name + ) + assert featurestore.resource_name == get_featurestore.resource_name + + list_featurestores = aiplatform.Featurestore.list() + assert get_featurestore.resource_name in [ + featurestore.resource_name for featurestore in list_featurestores + ] + + def test_create_get_list_entity_types(self, shared_state): + + assert shared_state["featurestore"] + assert shared_state["featurestore_name"] + + featurestore = shared_state["featurestore"] + featurestore_name = shared_state["featurestore_name"] + + aiplatform.init( + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + ) + + # Users + user_entity_type = featurestore.create_entity_type( + entity_type_id=_TEST_USER_ENTITY_TYPE_ID + ) + shared_state["user_entity_type"] = user_entity_type + shared_state["user_entity_type_name"] = user_entity_type.resource_name + + get_user_entity_type = featurestore.get_entity_type( + entity_type_id=_TEST_USER_ENTITY_TYPE_ID + ) + assert user_entity_type.resource_name == get_user_entity_type.resource_name + + # Movies + movie_entity_type = aiplatform.EntityType.create( + entity_type_id=_TEST_MOVIE_ENTITY_TYPE_ID, + featurestore_name=featurestore_name, + ) + shared_state["movie_entity_type"] = movie_entity_type + shared_state["movie_entity_type_name"] = movie_entity_type.resource_name + + get_movie_entity_type = aiplatform.EntityType( + entity_type_name=movie_entity_type.resource_name + ) + assert movie_entity_type.resource_name == get_movie_entity_type.resource_name + + list_entity_types = aiplatform.EntityType.list( + featurestore_name=featurestore_name + ) + assert get_movie_entity_type.resource_name in [ + entity_type.resource_name for entity_type in list_entity_types + ] + + def test_create_get_list_features(self, shared_state): + + assert shared_state["user_entity_type"] + assert shared_state["user_entity_type_name"] + user_entity_type = shared_state["user_entity_type"] + user_entity_type_name = shared_state["user_entity_type_name"] + + aiplatform.init( + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + ) + + # User Features + user_age_feature = user_entity_type.create_feature( + feature_id=_TEST_USER_AGE_FEATURE_ID, value_type="INT64" + ) + shared_state["user_age_feature_resource_name"] = user_age_feature.resource_name + get_user_age_feature = user_entity_type.get_feature( + feature_id=_TEST_USER_AGE_FEATURE_ID + ) + assert user_age_feature.resource_name == get_user_age_feature.resource_name + + user_gender_feature = aiplatform.Feature.create( + feature_id=_TEST_USER_GENDER_FEATURE_ID, + value_type="STRING", + entity_type_name=user_entity_type_name, + ) + shared_state[ + "user_gender_feature_resource_name" + ] = user_gender_feature.resource_name + + get_user_gender_feature = aiplatform.Feature( + feature_name=user_gender_feature.resource_name + ) + assert ( + user_gender_feature.resource_name == get_user_gender_feature.resource_name + ) + + user_liked_genres_feature = user_entity_type.create_feature( + feature_id=_TEST_USER_LIKED_GENRES_FEATURE_ID, + value_type="STRING_ARRAY", + ) + shared_state[ + "user_liked_genres_feature_resource_name" + ] = user_liked_genres_feature.resource_name + + get_user_liked_genres_feature = aiplatform.Feature( + feature_name=user_liked_genres_feature.resource_name + ) + assert ( + user_liked_genres_feature.resource_name + == get_user_liked_genres_feature.resource_name + ) + + list_user_features = user_entity_type.list_features() + list_user_feature_resource_names = [ + feature.resource_name for feature in list_user_features + ] + + assert get_user_age_feature.resource_name in list_user_feature_resource_names + assert get_user_gender_feature.resource_name in list_user_feature_resource_names + assert ( + get_user_liked_genres_feature.resource_name + in list_user_feature_resource_names + ) + + def test_ingest_feature_values(self, shared_state, caplog): + + assert shared_state["user_entity_type"] + user_entity_type = shared_state["user_entity_type"] + + caplog.set_level(logging.INFO) + + aiplatform.init( + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + ) + + user_entity_type.ingest_from_gcs( + feature_ids=[ + _TEST_USER_AGE_FEATURE_ID, + _TEST_USER_GENDER_FEATURE_ID, + _TEST_USER_LIKED_GENRES_FEATURE_ID, + ], + feature_time="update_time", + gcs_source_uris=_TEST_USERS_ENTITY_TYPE_GCS_SRC, + gcs_source_type="avro", + entity_id_field="user_id", + worker_count=1, + ) + + assert "EntityType feature values imported." in caplog.text + + caplog.clear() + + def test_batch_create_features(self, shared_state): + assert shared_state["movie_entity_type"] + movie_entity_type = shared_state["movie_entity_type"] + + aiplatform.init( + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + ) + + movie_feature_configs = { + _TEST_MOVIE_TITLE_FEATURE_ID: {"value_type": "STRING"}, + _TEST_MOVIE_GENRES_FEATURE_ID: {"value_type": "STRING_ARRAY"}, + _TEST_MOVIE_AVERAGE_RATING_FEATURE_ID: {"value_type": "DOUBLE"}, + } + + movie_entity_type.batch_create_features(feature_configs=movie_feature_configs) + + get_movie_title_feature = movie_entity_type.get_feature( + feature_id=_TEST_MOVIE_TITLE_FEATURE_ID + ) + get_movie_genres_feature = movie_entity_type.get_feature( + feature_id=_TEST_MOVIE_GENRES_FEATURE_ID + ) + get_movie_avg_rating_feature = movie_entity_type.get_feature( + feature_id=_TEST_MOVIE_AVERAGE_RATING_FEATURE_ID + ) + + list_movie_features = movie_entity_type.list_features() + movie_feature_resource_names = [ + feature.resource_name for feature in list_movie_features + ] + + assert get_movie_title_feature.resource_name in movie_feature_resource_names + assert get_movie_genres_feature.resource_name in movie_feature_resource_names + assert ( + get_movie_avg_rating_feature.resource_name in movie_feature_resource_names + ) + + def test_ingest_feature_values_from_df_using_feature_time_column_and_online_read_multiple_entities( + self, shared_state, caplog + ): + + assert shared_state["movie_entity_type"] + movie_entity_type = shared_state["movie_entity_type"] + + caplog.set_level(logging.INFO) + + aiplatform.init( + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + ) + + read_feature_ids = ["average_rating", "title", "genres"] + + movie_entity_views_df_before_ingest = movie_entity_type.read( + entity_ids=["movie_01", "movie_02"], + feature_ids=read_feature_ids, + ) + expected_data_before_ingest = [ + { + "entity_id": "movie_01", + "average_rating": None, + "title": None, + "genres": None, + }, + { + "entity_id": "movie_02", + "average_rating": None, + "title": None, + "genres": None, + }, + ] + expected_movie_entity_views_df_before_ingest = pd.DataFrame( + data=expected_data_before_ingest, columns=read_feature_ids + ) + + movie_entity_views_df_before_ingest.equals( + expected_movie_entity_views_df_before_ingest + ) + + movies_df = pd.DataFrame( + data=[ + { + "movie_id": "movie_01", + "average_rating": 4.9, + "title": "The Shawshank Redemption", + "genres": ["Drama"], + "update_time": "2021-08-20 20:44:11.094375+00:00", + }, + { + "movie_id": "movie_02", + "average_rating": 4.2, + "title": "The Shining", + "genres": ["Horror"], + "update_time": "2021-08-20 20:44:11.094375+00:00", + }, + ], + columns=["movie_id", "average_rating", "title", "genres", "update_time"], + ) + movies_df = movies_df.astype({"update_time": "datetime64"}) + feature_time_column = "update_time" + + movie_entity_type.ingest_from_df( + feature_ids=[ + _TEST_MOVIE_TITLE_FEATURE_ID, + _TEST_MOVIE_GENRES_FEATURE_ID, + _TEST_MOVIE_AVERAGE_RATING_FEATURE_ID, + ], + feature_time=feature_time_column, + df_source=movies_df, + entity_id_field="movie_id", + ) + + movie_entity_views_df_after_ingest = movie_entity_type.read( + entity_ids=["movie_01", "movie_02"], + feature_ids=read_feature_ids, + ) + expected_data_after_ingest = [ + { + "movie_id": "movie_01", + "average_rating": 4.9, + "title": "The Shawshank Redemption", + "genres": ["Drama"], + }, + { + "movie_id": "movie_02", + "average_rating": 4.2, + "title": "The Shining", + "genres": ["Horror"], + }, + ] + expected_movie_entity_views_df_after_ingest = pd.DataFrame( + data=expected_data_after_ingest, columns=read_feature_ids + ) + + movie_entity_views_df_after_ingest.equals( + expected_movie_entity_views_df_after_ingest + ) + + assert "EntityType feature values imported." in caplog.text + caplog.clear() + + def test_ingest_feature_values_from_df_using_feature_time_datetime_and_online_read_single_entity( + self, shared_state, caplog + ): + assert shared_state["movie_entity_type"] + movie_entity_type = shared_state["movie_entity_type"] + + caplog.set_level(logging.INFO) + + aiplatform.init( + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + ) + + movies_df = pd.DataFrame( + data=[ + { + "movie_id": "movie_03", + "average_rating": 4.5, + "title": "Cinema Paradiso", + "genres": ["Romance"], + }, + { + "movie_id": "movie_04", + "average_rating": 4.6, + "title": "The Dark Knight", + "genres": ["Action"], + }, + ], + columns=["movie_id", "average_rating", "title", "genres"], + ) + + feature_time_datetime_str = datetime.datetime.now().isoformat( + sep=" ", timespec="milliseconds" + ) + feature_time_datetime = datetime.datetime.strptime( + feature_time_datetime_str, "%Y-%m-%d %H:%M:%S.%f" + ) + + movie_entity_type.ingest_from_df( + feature_ids=[ + _TEST_MOVIE_TITLE_FEATURE_ID, + _TEST_MOVIE_GENRES_FEATURE_ID, + _TEST_MOVIE_AVERAGE_RATING_FEATURE_ID, + ], + feature_time=feature_time_datetime, + df_source=movies_df, + entity_id_field="movie_id", + ) + + movie_entity_views_df_avg_rating = movie_entity_type.read( + entity_ids="movie_04", + feature_ids="average_rating", + ) + expected_data_avg_rating = [ + {"movie_id": "movie_04", "average_rating": 4.6}, + ] + expected_movie_entity_views_df_avg_rating = pd.DataFrame( + data=expected_data_avg_rating, columns=["average_rating"] + ) + + movie_entity_views_df_avg_rating.equals( + expected_movie_entity_views_df_avg_rating + ) + + assert "EntityType feature values imported." in caplog.text + + caplog.clear() + + def test_search_features(self, shared_state): + + aiplatform.init( + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + ) + + list_searched_features = aiplatform.Feature.search() + assert len(list_searched_features) >= 1 + + def test_batch_serve_to_df(self, shared_state, caplog): + + assert shared_state["featurestore"] + assert shared_state["user_age_feature_resource_name"] + assert shared_state["user_gender_feature_resource_name"] + assert shared_state["user_liked_genres_feature_resource_name"] + + featurestore = shared_state["featurestore"] + + user_age_feature_resource_name = shared_state["user_age_feature_resource_name"] + user_gender_feature_resource_name = shared_state[ + "user_gender_feature_resource_name" + ] + user_liked_genres_feature_resource_name = shared_state[ + "user_liked_genres_feature_resource_name" + ] + + aiplatform.init( + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + ) + + caplog.set_level(logging.INFO) + + read_instances_df = pd.DataFrame( + data=[ + ["alice", "movie_01", "2021-09-15T08:28:14Z"], + ["bob", "movie_02", "2021-09-15T08:28:14Z"], + ["dav", "movie_03", "2021-09-15T08:28:14Z"], + ["eve", "movie_04", "2021-09-15T08:28:14Z"], + ["alice", "movie_03", "2021-09-14T09:35:15Z"], + ["bob", "movie_04", "2020-02-14T09:35:15Z"], + ], + columns=["users", "movies", "timestamp"], + ) + read_instances_df = read_instances_df.astype({"timestamp": "datetime64"}) + + df = featurestore.batch_serve_to_df( + serving_feature_ids={ + _TEST_USER_ENTITY_TYPE_ID: [ + _TEST_USER_AGE_FEATURE_ID, + _TEST_USER_GENDER_FEATURE_ID, + _TEST_USER_LIKED_GENRES_FEATURE_ID, + ], + _TEST_MOVIE_ENTITY_TYPE_ID: [ + _TEST_MOVIE_TITLE_FEATURE_ID, + _TEST_MOVIE_GENRES_FEATURE_ID, + _TEST_MOVIE_AVERAGE_RATING_FEATURE_ID, + ], + }, + read_instances_df=read_instances_df, + feature_destination_fields={ + user_age_feature_resource_name: "user_age_dest", + user_gender_feature_resource_name: "user_gender_dest", + user_liked_genres_feature_resource_name: "user_liked_genres_dest", + }, + ) + + expected_df_columns = [ + "timestamp", + "entity_type_users", + "user_age_dest", + "user_gender_dest", + "user_liked_genres_dest", + "entity_type_movies", + "title", + "genres", + "average_rating", + ] + + assert type(df) == pd.DataFrame + assert list(df.columns) == expected_df_columns + assert df.size == 54 + assert "Featurestore feature values served." in caplog.text + + caplog.clear() + + def test_batch_serve_to_gcs(self, shared_state, caplog): + + assert shared_state["featurestore"] + assert shared_state["bucket"] + assert shared_state["user_age_feature_resource_name"] + assert shared_state["user_gender_feature_resource_name"] + assert shared_state["user_liked_genres_feature_resource_name"] + + featurestore = shared_state["featurestore"] + bucket_name = shared_state["staging_bucket_name"] + user_age_feature_resource_name = shared_state["user_age_feature_resource_name"] + user_gender_feature_resource_name = shared_state[ + "user_gender_feature_resource_name" + ] + user_liked_genres_feature_resource_name = shared_state[ + "user_liked_genres_feature_resource_name" + ] + + aiplatform.init( + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + ) + + caplog.set_level(logging.INFO) + + featurestore.batch_serve_to_gcs( + serving_feature_ids={ + _TEST_USER_ENTITY_TYPE_ID: [ + _TEST_USER_AGE_FEATURE_ID, + _TEST_USER_GENDER_FEATURE_ID, + _TEST_USER_LIKED_GENRES_FEATURE_ID, + ], + _TEST_MOVIE_ENTITY_TYPE_ID: [ + _TEST_MOVIE_TITLE_FEATURE_ID, + _TEST_MOVIE_GENRES_FEATURE_ID, + _TEST_MOVIE_AVERAGE_RATING_FEATURE_ID, + ], + }, + read_instances_uri=_TEST_READ_INSTANCE_SRC, + feature_destination_fields={ + user_age_feature_resource_name: "user_age_dest", + user_gender_feature_resource_name: "user_gender_dest", + user_liked_genres_feature_resource_name: "user_liked_genres_dest", + }, + gcs_destination_output_uri_prefix=f"gs://{bucket_name}/featurestore_test/tfrecord", + gcs_destination_type="tfrecord", + ) + assert "Featurestore feature values served." in caplog.text + + caplog.clear() + + def test_batch_serve_to_bq(self, shared_state, caplog): + + assert shared_state["featurestore"] + assert shared_state["bigquery_dataset"] + assert shared_state["user_age_feature_resource_name"] + assert shared_state["user_gender_feature_resource_name"] + assert shared_state["user_liked_genres_feature_resource_name"] + + featurestore = shared_state["featurestore"] + bigquery_dataset_id = shared_state["bigquery_dataset_id"] + user_age_feature_resource_name = shared_state["user_age_feature_resource_name"] + user_gender_feature_resource_name = shared_state[ + "user_gender_feature_resource_name" + ] + user_liked_genres_feature_resource_name = shared_state[ + "user_liked_genres_feature_resource_name" + ] + + aiplatform.init( + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + ) + + caplog.set_level(logging.INFO) + + featurestore.batch_serve_to_bq( + serving_feature_ids={ + _TEST_USER_ENTITY_TYPE_ID: [ + _TEST_USER_AGE_FEATURE_ID, + _TEST_USER_GENDER_FEATURE_ID, + _TEST_USER_LIKED_GENRES_FEATURE_ID, + ], + _TEST_MOVIE_ENTITY_TYPE_ID: [ + _TEST_MOVIE_TITLE_FEATURE_ID, + _TEST_MOVIE_GENRES_FEATURE_ID, + _TEST_MOVIE_AVERAGE_RATING_FEATURE_ID, + ], + }, + read_instances_uri=_TEST_READ_INSTANCE_SRC, + feature_destination_fields={ + user_age_feature_resource_name: "user_age_dest", + user_gender_feature_resource_name: "user_gender_dest", + user_liked_genres_feature_resource_name: "user_liked_genres_dest", + }, + bq_destination_output_uri=f"bq://{bigquery_dataset_id}.test_table", + ) + + assert "Featurestore feature values served." in caplog.text + caplog.clear() + + def test_online_reads(self, shared_state): + assert shared_state["user_entity_type"] + assert shared_state["movie_entity_type"] + + user_entity_type = shared_state["user_entity_type"] + movie_entity_type = shared_state["movie_entity_type"] + + user_entity_views = user_entity_type.read(entity_ids="alice") + assert type(user_entity_views) == pd.DataFrame + + movie_entity_views = movie_entity_type.read( + entity_ids=["movie_01", "movie_04"], + feature_ids=[_TEST_MOVIE_TITLE_FEATURE_ID, _TEST_MOVIE_GENRES_FEATURE_ID], + ) + assert type(movie_entity_views) == pd.DataFrame + + movie_entity_views = movie_entity_type.read( + entity_ids="movie_01", + feature_ids=[_TEST_MOVIE_TITLE_FEATURE_ID, _TEST_MOVIE_GENRES_FEATURE_ID], + ) + assert type(movie_entity_views) == pd.DataFrame diff --git a/tests/system/aiplatform/test_matching_engine_index.py b/tests/system/aiplatform/test_matching_engine_index.py new file mode 100644 index 0000000000..db4f4ac6bf --- /dev/null +++ b/tests/system/aiplatform/test_matching_engine_index.py @@ -0,0 +1,303 @@ +# -*- coding: utf-8 -*- + +# Copyright 2022 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. +# + +import uuid + +from google.cloud import aiplatform + +from tests.system.aiplatform import e2e_base + +# project +_TEST_INDEX_DISPLAY_NAME = "index_display_name" +_TEST_INDEX_DESCRIPTION = "index_description" +_TEST_INDEX_DISTANCE_MEASURE_TYPE = "SQUARED_L2_DISTANCE" + +_TEST_INDEX_CONFIG_DIMENSIONS = 100 +_TEST_INDEX_APPROXIMATE_NEIGHBORS_COUNT = 150 +_TEST_LEAF_NODE_EMBEDDING_COUNT = 123 +_TEST_LEAF_NODES_TO_SEARCH_PERCENT = 50 + + +_TEST_CONTENTS_DELTA_URI = ( + "gs://cloud-samples-data-us-central1/vertex-ai/matching_engine/glove100/initial" +) +_TEST_CONTENTS_DELTA_URI_UPDATE = ( + "gs://cloud-samples-data-us-central1/vertex-ai/matching_engine/glove100/incremental" +) +_TEST_IS_COMPLETE_OVERWRITE = True +_TEST_INDEX_DISTANCE_MEASURE_TYPE = "SQUARED_L2_DISTANCE" + + +_TEST_LABELS = {"my_key": "my_value"} +_TEST_DISPLAY_NAME_UPDATE = "my new display name" +_TEST_DESCRIPTION_UPDATE = "my description update" +_TEST_LABELS_UPDATE = {"my_key_update": "my_value_update"} + +# ENDPOINT +_TEST_INDEX_ENDPOINT_DISPLAY_NAME = "endpoint_name" +_TEST_INDEX_ENDPOINT_DESCRIPTION = "my endpoint" + +# DEPLOYED INDEX +_TEST_DEPLOYED_INDEX_ID = f"deployed_index_id_{uuid.uuid4()}" +_TEST_DEPLOYED_INDEX_DISPLAY_NAME = f"deployed_index_display_name_{uuid.uuid4()}" +_TEST_MIN_REPLICA_COUNT_UPDATED = 4 +_TEST_MAX_REPLICA_COUNT_UPDATED = 4 + +# QUERY +_TEST_MATCH_QUERY = query = [ + -0.11333, + 0.48402, + 0.090771, + -0.22439, + 0.034206, + -0.55831, + 0.041849, + -0.53573, + 0.18809, + -0.58722, + 0.015313, + -0.014555, + 0.80842, + -0.038519, + 0.75348, + 0.70502, + -0.17863, + 0.3222, + 0.67575, + 0.67198, + 0.26044, + 0.4187, + -0.34122, + 0.2286, + -0.53529, + 1.2582, + -0.091543, + 0.19716, + -0.037454, + -0.3336, + 0.31399, + 0.36488, + 0.71263, + 0.1307, + -0.24654, + -0.52445, + -0.036091, + 0.55068, + 0.10017, + 0.48095, + 0.71104, + -0.053462, + 0.22325, + 0.30917, + -0.39926, + 0.036634, + -0.35431, + -0.42795, + 0.46444, + 0.25586, + 0.68257, + -0.20821, + 0.38433, + 0.055773, + -0.2539, + -0.20804, + 0.52522, + -0.11399, + -0.3253, + -0.44104, + 0.17528, + 0.62255, + 0.50237, + -0.7607, + -0.071786, + 0.0080131, + -0.13286, + 0.50097, + 0.18824, + -0.54722, + -0.42664, + 0.4292, + 0.14877, + -0.0072514, + -0.16484, + -0.059798, + 0.9895, + -0.61738, + 0.054169, + 0.48424, + -0.35084, + -0.27053, + 0.37829, + 0.11503, + -0.39613, + 0.24266, + 0.39147, + -0.075256, + 0.65093, + -0.20822, + -0.17456, + 0.53571, + -0.16537, + 0.13582, + -0.56016, + 0.016964, + 0.1277, + 0.94071, + -0.22608, + -0.021106, +] + + +class TestMatchingEngine(e2e_base.TestEndToEnd): + + _temp_prefix = "temp_vertex_sdk_e2e_matching_engine_test" + + def test_create_get_list_matching_engine_index(self, shared_state): + aiplatform.init( + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + ) + + # Create an index + index = aiplatform.MatchingEngineIndex.create_tree_ah_index( + display_name=_TEST_INDEX_DISPLAY_NAME, + contents_delta_uri=_TEST_CONTENTS_DELTA_URI, + dimensions=_TEST_INDEX_CONFIG_DIMENSIONS, + approximate_neighbors_count=_TEST_INDEX_APPROXIMATE_NEIGHBORS_COUNT, + distance_measure_type=_TEST_INDEX_DISTANCE_MEASURE_TYPE, + leaf_node_embedding_count=_TEST_LEAF_NODE_EMBEDDING_COUNT, + leaf_nodes_to_search_percent=_TEST_LEAF_NODES_TO_SEARCH_PERCENT, + description=_TEST_INDEX_DESCRIPTION, + labels=_TEST_LABELS, + ) + + shared_state["resources"] = [index] + shared_state["index"] = index + shared_state["index_name"] = index.resource_name + + # Verify that the retrieved index is the same + get_index = aiplatform.MatchingEngineIndex(index_name=index.resource_name) + assert index.resource_name == get_index.resource_name + + # Create index and check that it is listed + list_indexes = aiplatform.MatchingEngineIndex.list() + assert get_index.resource_name in [ + index.resource_name for index in list_indexes + ] + + # Update the index metadata + updated_index = get_index.update_metadata( + display_name=_TEST_DISPLAY_NAME_UPDATE, + description=_TEST_DESCRIPTION_UPDATE, + labels=_TEST_LABELS_UPDATE, + ) + + assert updated_index.name == get_index.name + # TODO: Reinstate assertions once b/220005272 is fixed. + # assert updated_index.display_name == _TEST_DISPLAY_NAME_UPDATE + # assert updated_index.description == _TEST_DESCRIPTION_UPDATE + # assert updated_index.labels == _TEST_LABELS_UPDATE + + # Update the index embeddings + updated_index = get_index.update_embeddings( + contents_delta_uri=_TEST_CONTENTS_DELTA_URI_UPDATE, + is_complete_overwrite=_TEST_IS_COMPLETE_OVERWRITE, + ) + + assert updated_index.name == get_index.name + + # Create endpoint and check that it is listed + my_index_endpoint = aiplatform.MatchingEngineIndexEndpoint.create( + display_name=_TEST_INDEX_ENDPOINT_DISPLAY_NAME, + description=_TEST_INDEX_ENDPOINT_DESCRIPTION, + network=e2e_base._VPC_NETWORK_URI, + labels=_TEST_LABELS, + ) + assert my_index_endpoint.resource_name in [ + index_endpoint.resource_name + for index_endpoint in aiplatform.MatchingEngineIndexEndpoint.list() + ] + + assert my_index_endpoint.labels == _TEST_LABELS + assert my_index_endpoint.display_name == _TEST_INDEX_ENDPOINT_DISPLAY_NAME + assert my_index_endpoint.description == _TEST_INDEX_ENDPOINT_DESCRIPTION + + shared_state["resources"].append(my_index_endpoint) + + # Deploy endpoint + my_index_endpoint = my_index_endpoint.deploy_index( + index=index, + deployed_index_id=_TEST_DEPLOYED_INDEX_ID, + display_name=_TEST_DEPLOYED_INDEX_DISPLAY_NAME, + ) + + # Update endpoint + updated_index_endpoint = my_index_endpoint.update( + display_name=_TEST_DISPLAY_NAME_UPDATE, + description=_TEST_DESCRIPTION_UPDATE, + labels=_TEST_LABELS_UPDATE, + ) + + assert updated_index_endpoint.labels == _TEST_LABELS_UPDATE + assert updated_index_endpoint.display_name == _TEST_DISPLAY_NAME_UPDATE + assert updated_index_endpoint.description == _TEST_DESCRIPTION_UPDATE + + # Mutate deployed index + my_index_endpoint.mutate_deployed_index( + deployed_index_id=_TEST_DEPLOYED_INDEX_ID, + min_replica_count=_TEST_MIN_REPLICA_COUNT_UPDATED, + max_replica_count=_TEST_MAX_REPLICA_COUNT_UPDATED, + ) + + deployed_index = my_index_endpoint.deployed_indexes[0] + + assert deployed_index.id == _TEST_DEPLOYED_INDEX_ID + assert deployed_index.index == index.resource_name + assert ( + deployed_index.automatic_resources.min_replica_count + == _TEST_MIN_REPLICA_COUNT_UPDATED + ) + assert ( + deployed_index.automatic_resources.max_replica_count + == _TEST_MAX_REPLICA_COUNT_UPDATED + ) + + # TODO: Test `my_index_endpoint.match` request. This requires running this test in a VPC. + # results = my_index_endpoint.match( + # deployed_index_id=_TEST_DEPLOYED_INDEX_ID, queries=[_TEST_MATCH_QUERY] + # ) + + # assert results[0][0].id == 870 + + # Undeploy index + my_index_endpoint = my_index_endpoint.undeploy_index( + deployed_index_id=deployed_index.id + ) + + # Delete index and check that it is no longer listed + index.delete() + list_indexes = aiplatform.MatchingEngineIndex.list() + assert get_index.resource_name not in [ + index.resource_name for index in list_indexes + ] + + # Delete index endpoint and check that it is no longer listed + my_index_endpoint.delete() + assert my_index_endpoint.resource_name not in [ + index_endpoint.resource_name + for index_endpoint in aiplatform.MatchingEngineIndexEndpoint.list() + ] diff --git a/tests/system/aiplatform/test_model_upload.py b/tests/system/aiplatform/test_model_upload.py new file mode 100644 index 0000000000..48e6169af4 --- /dev/null +++ b/tests/system/aiplatform/test_model_upload.py @@ -0,0 +1,87 @@ +# -*- 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. +# + +import tempfile + +import pytest + +from google.cloud import aiplatform +from google.cloud import storage + +from tests.system.aiplatform import e2e_base + + +_XGBOOST_MODEL_URI = "gs://cloud-samples-data-us-central1/vertex-ai/google-cloud-aiplatform-ci-artifacts/models/iris_xgboost/model.bst" + + +@pytest.mark.usefixtures("delete_staging_bucket", "tear_down_resources") +class TestModel(e2e_base.TestEndToEnd): + + _temp_prefix = "temp_vertex_sdk_e2e_model_upload_test" + + def test_upload_and_deploy_xgboost_model(self, shared_state): + """Upload XGBoost model from local file and deploy it for prediction. Additionally, update model name, description and labels""" + + aiplatform.init( + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + ) + + storage_client = storage.Client(project=e2e_base._PROJECT) + model_blob = storage.Blob.from_string( + uri=_XGBOOST_MODEL_URI, client=storage_client + ) + model_path = tempfile.mktemp() + ".my_model.xgb" + model_blob.download_to_filename(filename=model_path) + + model = aiplatform.Model.upload_xgboost_model_file( + model_file_path=model_path, + ) + shared_state["resources"] = [model] + + staging_bucket = storage.Blob.from_string( + uri=model.uri, client=storage_client + ).bucket + # Checking that the bucket is auto-generated + assert "-vertex-staging-" in staging_bucket.name + + shared_state["bucket"] = staging_bucket + + # Currently we need to explicitly specify machine type. + # See https://github.com/googleapis/python-aiplatform/issues/773 + endpoint = model.deploy(machine_type="n1-standard-2") + shared_state["resources"].append(endpoint) + predict_response = endpoint.predict(instances=[[0, 0, 0]]) + assert len(predict_response.predictions) == 1 + + model = model.update( + display_name="new_name", + description="new_description", + labels={"my_label": "updated"}, + ) + assert model.display_name == "new_name" + assert model.description == "new_description" + assert model.labels == {"my_label": "updated"} + + assert len(endpoint.list_models()) == 1 + endpoint.deploy(model, traffic_percentage=100) + assert len(endpoint.list_models()) == 2 + traffic_split = { + deployed_model.id: 50 for deployed_model in endpoint.list_models() + } + endpoint.update(traffic_split=traffic_split) + assert endpoint.traffic_split == traffic_split diff --git a/tests/system/aiplatform/test_project_id_inference.py b/tests/system/aiplatform/test_project_id_inference.py new file mode 100644 index 0000000000..4150ed35e2 --- /dev/null +++ b/tests/system/aiplatform/test_project_id_inference.py @@ -0,0 +1,77 @@ +# -*- coding: utf-8 -*- + +# 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 +# +# 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. +# + +import pytest + +from google.cloud import aiplatform +from google.cloud.aiplatform.compat.types import job_state as gca_job_state +from tests.system.aiplatform import e2e_base + +_SCRIPT = """ +from google.cloud import aiplatform +# Not initializing the Vertex SDK explicitly +# Checking the project ID +print(aiplatform.initializer.global_config.project) +assert not aiplatform.initializer.global_config.project.endswith("-tp") +""" + + +@pytest.mark.usefixtures("prepare_staging_bucket", "delete_staging_bucket") +class TestProjectIDInference(e2e_base.TestEndToEnd): + + _temp_prefix = "temp-vertex-sdk-project-id-inference" + + def test_project_id_inference(self, shared_state): + # Collection of resources generated by this test, to be deleted during teardown + shared_state["resources"] = [] + + aiplatform.init( + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + staging_bucket=shared_state["staging_bucket_name"], + ) + + worker_pool_specs = [ + { + "machine_spec": {"machine_type": "n1-standard-4"}, + "replica_count": 1, + "container_spec": { + "image_uri": "python:3.9", + "command": [ + "sh", + "-exc", + """python3 -m pip install git+https://github.com/googleapis/python-aiplatform@main + "$0" "$@" + """, + "python3", + "-c", + _SCRIPT, + ], + "args": [], + }, + } + ] + + custom_job = aiplatform.CustomJob( + display_name=self._make_display_name("custom"), + worker_pool_specs=worker_pool_specs, + ) + custom_job.run() + + shared_state["resources"].append(custom_job) + + assert custom_job.state == gca_job_state.JobState.JOB_STATE_SUCCEEDED diff --git a/tests/system/aiplatform/test_resources/california_housing_training_script.py b/tests/system/aiplatform/test_resources/california_housing_training_script.py new file mode 100644 index 0000000000..ae5b26e531 --- /dev/null +++ b/tests/system/aiplatform/test_resources/california_housing_training_script.py @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- + +# 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 +# +# 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. +# + +import pandas as pd +import os +import tensorflow as tf +from tensorflow.keras import layers + + +# uncomment and bump up replica_count for distributed training +# strategy = tf.distribute.experimental.MultiWorkerMirroredStrategy() +# tf.distribute.experimental_set_strategy(strategy) + +target = "median_house_value" + + +def aip_data_to_dataframe(wild_card_path): + return pd.concat( + [ + pd.read_csv(fp.numpy().decode()) + for fp in tf.data.Dataset.list_files([wild_card_path]) + ] + ) + + +def get_features_and_labels(df): + features = df.drop(target, axis=1) + return {key: features[key].values for key in features.columns}, df[target].values + + +def data_prep(wild_card_path): + return get_features_and_labels(aip_data_to_dataframe(wild_card_path)) + + +train_features, train_labels = data_prep(os.environ["AIP_TRAINING_DATA_URI"]) + +feature_columns = [ + tf.feature_column.numeric_column(name) for name in train_features.keys() +] + +model = tf.keras.Sequential( + [layers.DenseFeatures(feature_columns), layers.Dense(64), layers.Dense(1)] +) +model.compile(loss="mse", optimizer="adam") + +model.fit( + train_features, + train_labels, + epochs=10, + validation_data=data_prep(os.environ["AIP_VALIDATION_DATA_URI"]), +) +print(model.evaluate(*data_prep(os.environ["AIP_TEST_DATA_URI"]))) + +# save as Vertex AI Managed model +tf.saved_model.save(model, os.environ["AIP_MODEL_DIR"]) diff --git a/tests/system/aiplatform/test_tensorboard.py b/tests/system/aiplatform/test_tensorboard.py new file mode 100644 index 0000000000..e1262640dc --- /dev/null +++ b/tests/system/aiplatform/test_tensorboard.py @@ -0,0 +1,141 @@ +# -*- coding: utf-8 -*- + +# 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 +# +# 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. +# + +import pytest + +from google.cloud import aiplatform +from tests.system.aiplatform import e2e_base + + +@pytest.mark.usefixtures("tear_down_resources") +class TestTensorboard(e2e_base.TestEndToEnd): + + _temp_prefix = "temp-vertex-sdk-e2e-test" + + def test_create_and_get_tensorboard(self, shared_state): + + aiplatform.init( + project=e2e_base._PROJECT, + location=e2e_base._LOCATION, + ) + + display_name = self._make_display_name("tensorboard") + + tb = aiplatform.Tensorboard.create( + display_name=display_name, + create_request_timeout=None, + ) + + shared_state["resources"] = [tb] + shared_state["tensorboard"] = tb + + get_tb = aiplatform.Tensorboard(tb.resource_name) + + assert tb.resource_name == get_tb.resource_name + + list_tb = aiplatform.Tensorboard.list() + + assert len(list_tb) > 0 + + def test_create_and_get_tensorboard_experiment(self, shared_state): + assert shared_state["tensorboard"] + tb = shared_state["tensorboard"] + + tb_experiment = aiplatform.TensorboardExperiment.create( + tensorboard_experiment_id="vertex-sdk-e2e-test-experiment", + tensorboard_name=tb.resource_name, + display_name=self._make_display_name("tensorboard_experiment"), + description="Vertex SDK Integration test.", + labels={"test": "labels"}, + create_request_timeout=None, + ) + + shared_state["resources"].append(tb_experiment) + shared_state["tensorboard_experiment"] = tb_experiment + + get_tb_experiment = aiplatform.TensorboardExperiment( + tb_experiment.resource_name + ) + + assert tb_experiment.resource_name == get_tb_experiment.resource_name + + list_tb_experiment = aiplatform.TensorboardExperiment.list( + tensorboard_name=tb.resource_name + ) + + assert len(list_tb_experiment) > 0 + + def test_create_and_get_tensorboard_run(self, shared_state): + assert shared_state["tensorboard_experiment"] + tb_experiment = shared_state["tensorboard_experiment"] + + tb_run = aiplatform.TensorboardRun.create( + tensorboard_run_id="test-run", + tensorboard_experiment_name=tb_experiment.resource_name, + description="Vertex SDK Integration test run", + labels={"test": "labels"}, + create_request_timeout=None, + ) + + shared_state["resources"].append(tb_run) + shared_state["tensorboard_run"] = tb_run + + get_tb_run = aiplatform.TensorboardRun(tb_run.resource_name) + + assert tb_run.resource_name == get_tb_run.resource_name + + list_tb_run = aiplatform.TensorboardRun.list( + tensorboard_experiment_name=tb_experiment.resource_name + ) + + assert len(list_tb_run) > 0 + + def test_create_and_get_tensorboard_time_series(self, shared_state): + assert shared_state["tensorboard_run"] + tb_run = shared_state["tensorboard_run"] + + tb_time_series = aiplatform.TensorboardTimeSeries.create( + display_name="test-time-series", + tensorboard_run_name=tb_run.resource_name, + description="Vertex SDK Integration test run", + ) + + shared_state["resources"].append(tb_time_series) + shared_state["tensorboard_time_series"] = tb_time_series + + get_tb_time_series = aiplatform.TensorboardTimeSeries( + tb_time_series.resource_name + ) + + assert tb_time_series.resource_name == get_tb_time_series.resource_name + + list_tb_time_series = aiplatform.TensorboardTimeSeries.list( + tensorboard_run_name=tb_run.resource_name + ) + + assert len(list_tb_time_series) > 0 + + def test_write_tensorboard_scalar_data(self, shared_state): + assert shared_state["tensorboard_time_series"] + assert shared_state["tensorboard_run"] + tb_run = shared_state["tensorboard_run"] + tb_time_series = shared_state["tensorboard_time_series"] + + tb_run.write_tensorboard_scalar_data( + time_series_data={tb_time_series.display_name: 1.0}, + step=1, + ) diff --git a/tests/unit/__init__.py b/tests/unit/__init__.py index 4de65971c2..e8e1c3845d 100644 --- a/tests/unit/__init__.py +++ b/tests/unit/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/unit/aiplatform/conftest.py b/tests/unit/aiplatform/conftest.py new file mode 100644 index 0000000000..1a2e9c54f1 --- /dev/null +++ b/tests/unit/aiplatform/conftest.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- + +# Copyright 2022 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. +# + +import pytest + +from google import auth +from google.auth import credentials as auth_credentials +from unittest.mock import patch + + +@pytest.fixture(scope="module") +def google_auth_mock(): + with patch.object(auth, "default") as google_auth_mock: + google_auth_mock.return_value = ( + auth_credentials.AnonymousCredentials(), + "test-project", + ) + yield google_auth_mock diff --git a/tests/unit/aiplatform/test_automl_forecasting_training_jobs.py b/tests/unit/aiplatform/test_automl_forecasting_training_jobs.py index 5d89360566..236275237a 100644 --- a/tests/unit/aiplatform/test_automl_forecasting_training_jobs.py +++ b/tests/unit/aiplatform/test_automl_forecasting_training_jobs.py @@ -1,24 +1,42 @@ +# -*- coding: utf-8 -*- + +# Copyright 2022 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. +# + import importlib import pytest from unittest import mock from google.cloud import aiplatform +from google.cloud.aiplatform import base from google.cloud.aiplatform import datasets from google.cloud.aiplatform import initializer from google.cloud.aiplatform import schema -from google.cloud.aiplatform.training_jobs import AutoMLForecastingTrainingJob +from google.cloud.aiplatform import training_jobs -from google.cloud.aiplatform_v1.services.model_service import ( - client as model_service_client, -) -from google.cloud.aiplatform_v1.services.pipeline_service import ( - client as pipeline_service_client, +from google.cloud.aiplatform.compat.services import ( + model_service_client, + pipeline_service_client, ) -from google.cloud.aiplatform_v1.types import ( + +from google.cloud.aiplatform.compat.types import ( dataset as gca_dataset, model as gca_model, pipeline_state as gca_pipeline_state, training_pipeline as gca_training_pipeline, + encryption_spec as gca_encryption_spec, ) from google.protobuf import json_format from google.protobuf import struct_pb2 @@ -62,62 +80,105 @@ _TEST_TRAINING_BUDGET_MILLI_NODE_HOURS = 1000 _TEST_TRAINING_WEIGHT_COLUMN = "weight" _TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME = "minimize-rmse" -_TEST_TRAINING_TASK_INPUTS = json_format.ParseDict( +_TEST_ADDITIONAL_EXPERIMENTS = ["exp1", "exp2"] +_TEST_HIERARCHY_GROUP_COLUMNS = [] +_TEST_HIERARCHY_GROUP_TOTAL_WEIGHT = 1 +_TEST_HIERARCHY_TEMPORAL_TOTAL_WEIGHT = None +_TEST_HIERARCHY_GROUP_TEMPORAL_TOTAL_WEIGHT = None +_TEST_WINDOW_COLUMN = None +_TEST_WINDOW_STRIDE_LENGTH = 1 +_TEST_WINDOW_MAX_COUNT = None +_TEST_TRAINING_HOLIDAY_REGIONS = ["GLOBAL"] +_TEST_TRAINING_TASK_INPUTS_DICT = { + # required inputs + "targetColumn": _TEST_TRAINING_TARGET_COLUMN, + "timeColumn": _TEST_TRAINING_TIME_COLUMN, + "timeSeriesIdentifierColumn": _TEST_TRAINING_TIME_SERIES_IDENTIFIER_COLUMN, + "timeSeriesAttributeColumns": _TEST_TRAINING_TIME_SERIES_ATTRIBUTE_COLUMNS, + "unavailableAtForecastColumns": _TEST_TRAINING_UNAVAILABLE_AT_FORECAST_COLUMNS, + "availableAtForecastColumns": _TEST_TRAINING_AVAILABLE_AT_FORECAST_COLUMNS, + "forecastHorizon": _TEST_TRAINING_FORECAST_HORIZON, + "dataGranularity": { + "unit": _TEST_TRAINING_DATA_GRANULARITY_UNIT, + "quantity": _TEST_TRAINING_DATA_GRANULARITY_COUNT, + }, + "transformations": _TEST_TRAINING_COLUMN_TRANSFORMATIONS, + "trainBudgetMilliNodeHours": _TEST_TRAINING_BUDGET_MILLI_NODE_HOURS, + # optional inputs + "weightColumn": _TEST_TRAINING_WEIGHT_COLUMN, + "contextWindow": _TEST_TRAINING_CONTEXT_WINDOW, + "exportEvaluatedDataItemsConfig": { + "destinationBigqueryUri": _TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS_BIGQUERY_DESTINATION_URI, + "overrideExistingTable": _TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS_OVERRIDE_DESTINATION, + }, + "quantiles": _TEST_TRAINING_QUANTILES, + "validationOptions": _TEST_TRAINING_VALIDATION_OPTIONS, + "optimizationObjective": _TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME, + "hierarchyConfig": { + "groupColumns": _TEST_HIERARCHY_GROUP_COLUMNS, + "groupTotalWeight": _TEST_HIERARCHY_GROUP_TOTAL_WEIGHT, + "temporalTotalWeight": _TEST_HIERARCHY_TEMPORAL_TOTAL_WEIGHT, + "groupTemporalTotalWeight": _TEST_HIERARCHY_GROUP_TEMPORAL_TOTAL_WEIGHT, + }, + "windowConfig": { + "strideLength": _TEST_WINDOW_STRIDE_LENGTH, + }, + "holidayRegions": _TEST_TRAINING_HOLIDAY_REGIONS, +} + +_TEST_TRAINING_TASK_INPUTS_WITH_ADDITIONAL_EXPERIMENTS = json_format.ParseDict( { - # required inputs - "targetColumn": _TEST_TRAINING_TARGET_COLUMN, - "timeColumn": _TEST_TRAINING_TIME_COLUMN, - "timeSeriesIdentifierColumn": _TEST_TRAINING_TIME_SERIES_IDENTIFIER_COLUMN, - "timeSeriesAttributeColumns": _TEST_TRAINING_TIME_SERIES_ATTRIBUTE_COLUMNS, - "unavailableAtForecastColumns": _TEST_TRAINING_UNAVAILABLE_AT_FORECAST_COLUMNS, - "availableAtForecastColumns": _TEST_TRAINING_AVAILABLE_AT_FORECAST_COLUMNS, - "forecastHorizon": _TEST_TRAINING_FORECAST_HORIZON, - "dataGranularity": { - "unit": _TEST_TRAINING_DATA_GRANULARITY_UNIT, - "quantity": _TEST_TRAINING_DATA_GRANULARITY_COUNT, - }, - "transformations": _TEST_TRAINING_COLUMN_TRANSFORMATIONS, - "trainBudgetMilliNodeHours": _TEST_TRAINING_BUDGET_MILLI_NODE_HOURS, - # optional inputs - "weightColumn": _TEST_TRAINING_WEIGHT_COLUMN, - "contextWindow": _TEST_TRAINING_CONTEXT_WINDOW, - "exportEvaluatedDataItemsConfig": { - "destinationBigqueryUri": _TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS_BIGQUERY_DESTINATION_URI, - "overrideExistingTable": _TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS_OVERRIDE_DESTINATION, - }, - "quantiles": _TEST_TRAINING_QUANTILES, - "validationOptions": _TEST_TRAINING_VALIDATION_OPTIONS, - "optimizationObjective": _TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME, + **_TEST_TRAINING_TASK_INPUTS_DICT, + "additionalExperiments": _TEST_ADDITIONAL_EXPERIMENTS, }, struct_pb2.Value(), ) +_TEST_TRAINING_TASK_INPUTS = json_format.ParseDict( + _TEST_TRAINING_TASK_INPUTS_DICT, + struct_pb2.Value(), +) + _TEST_DATASET_NAME = "test-dataset-name" _TEST_MODEL_DISPLAY_NAME = "model-display-name" -_TEST_TRAINING_FRACTION_SPLIT = 0.8 -_TEST_VALIDATION_FRACTION_SPLIT = 0.1 -_TEST_TEST_FRACTION_SPLIT = 0.1 -_TEST_PREDEFINED_SPLIT_COLUMN_NAME = "split" -_TEST_OUTPUT_PYTHON_PACKAGE_PATH = "gs://test/ouput/python/trainer.tar.gz" +_TEST_LABELS = {"key": "value"} +_TEST_MODEL_LABELS = {"model_key": "model_value"} + +_TEST_PREDEFINED_SPLIT_COLUMN_NAME = "split" _TEST_MODEL_NAME = "projects/my-project/locations/us-central1/models/12345" _TEST_PIPELINE_RESOURCE_NAME = ( - "projects/my-project/locations/us-central1/trainingPipeline/12345" + "projects/my-project/locations/us-central1/trainingPipelines/12345" +) + +# CMEK encryption +_TEST_DEFAULT_ENCRYPTION_KEY_NAME = "key_default" +_TEST_DEFAULT_ENCRYPTION_SPEC = gca_encryption_spec.EncryptionSpec( + kms_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME ) +_TEST_FRACTION_SPLIT_TRAINING = 0.6 +_TEST_FRACTION_SPLIT_VALIDATION = 0.2 +_TEST_FRACTION_SPLIT_TEST = 0.2 + +_TEST_SPLIT_PREDEFINED_COLUMN_NAME = "split" +_TEST_SPLIT_TIMESTAMP_COLUMN_NAME = "timestamp" + @pytest.fixture def mock_pipeline_service_create(): with mock.patch.object( pipeline_service_client.PipelineServiceClient, "create_training_pipeline" ) as mock_create_training_pipeline: - mock_create_training_pipeline.return_value = gca_training_pipeline.TrainingPipeline( - name=_TEST_PIPELINE_RESOURCE_NAME, - state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, - model_to_upload=gca_model.Model(name=_TEST_MODEL_NAME), + mock_create_training_pipeline.return_value = ( + gca_training_pipeline.TrainingPipeline( + name=_TEST_PIPELINE_RESOURCE_NAME, + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, + model_to_upload=gca_model.Model(name=_TEST_MODEL_NAME), + ) ) yield mock_create_training_pipeline @@ -131,6 +192,9 @@ def mock_pipeline_service_get(): name=_TEST_PIPELINE_RESOURCE_NAME, state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, model_to_upload=gca_model.Model(name=_TEST_MODEL_NAME), + training_task_metadata={ + "evaluatedDataItemsBigqueryUri": _TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS_BIGQUERY_DESTINATION_URI + }, ) yield mock_get_training_pipeline @@ -140,17 +204,21 @@ def mock_pipeline_service_create_and_get_with_fail(): with mock.patch.object( pipeline_service_client.PipelineServiceClient, "create_training_pipeline" ) as mock_create_training_pipeline: - mock_create_training_pipeline.return_value = gca_training_pipeline.TrainingPipeline( - name=_TEST_PIPELINE_RESOURCE_NAME, - state=gca_pipeline_state.PipelineState.PIPELINE_STATE_RUNNING, + mock_create_training_pipeline.return_value = ( + gca_training_pipeline.TrainingPipeline( + name=_TEST_PIPELINE_RESOURCE_NAME, + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_RUNNING, + ) ) with mock.patch.object( pipeline_service_client.PipelineServiceClient, "get_training_pipeline" ) as mock_get_training_pipeline: - mock_get_training_pipeline.return_value = gca_training_pipeline.TrainingPipeline( - name=_TEST_PIPELINE_RESOURCE_NAME, - state=gca_pipeline_state.PipelineState.PIPELINE_STATE_FAILED, + mock_get_training_pipeline.return_value = ( + gca_training_pipeline.TrainingPipeline( + name=_TEST_PIPELINE_RESOURCE_NAME, + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_FAILED, + ) ) yield mock_create_training_pipeline, mock_get_training_pipeline @@ -197,7 +265,8 @@ def mock_dataset_nontimeseries(): return ds -class TestAutoMLForecastingTrainingJob: +@pytest.mark.usefixtures("google_auth_mock") +class TestForecastingTrainingJob: def setup_method(self): importlib.reload(initializer) importlib.reload(aiplatform) @@ -205,7 +274,16 @@ def setup_method(self): def teardown_method(self): initializer.global_pool.shutdown(wait=True) + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) + @pytest.mark.parametrize( + "training_job", + [ + training_jobs.AutoMLForecastingTrainingJob, + training_jobs.SequenceToSequencePlusForecastingTrainingJob, + ], + ) def test_run_call_pipeline_service_create( self, mock_pipeline_service_create, @@ -213,13 +291,15 @@ def test_run_call_pipeline_service_create( mock_dataset_time_series, mock_model_service_get, sync, + training_job, ): aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME) - job = AutoMLForecastingTrainingJob( + job = training_job( display_name=_TEST_DISPLAY_NAME, optimization_objective=_TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME, column_transformations=_TEST_TRAINING_COLUMN_TRANSFORMATIONS, + labels=_TEST_LABELS, ) model_from_job = job.run( @@ -233,6 +313,7 @@ def test_run_call_pipeline_service_create( data_granularity_unit=_TEST_TRAINING_DATA_GRANULARITY_UNIT, data_granularity_count=_TEST_TRAINING_DATA_GRANULARITY_COUNT, model_display_name=_TEST_MODEL_DISPLAY_NAME, + model_labels=_TEST_MODEL_LABELS, predefined_split_column_name=_TEST_PREDEFINED_SPLIT_COLUMN_NAME, weight_column=_TEST_TRAINING_WEIGHT_COLUMN, time_series_attribute_columns=_TEST_TRAINING_TIME_SERIES_ATTRIBUTE_COLUMNS, @@ -243,22 +324,27 @@ def test_run_call_pipeline_service_create( export_evaluated_data_items_override_destination=_TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS_OVERRIDE_DESTINATION, quantiles=_TEST_TRAINING_QUANTILES, validation_options=_TEST_TRAINING_VALIDATION_OPTIONS, + additional_experiments=_TEST_ADDITIONAL_EXPERIMENTS, + hierarchy_group_columns=_TEST_HIERARCHY_GROUP_COLUMNS, + hierarchy_group_total_weight=_TEST_HIERARCHY_GROUP_TOTAL_WEIGHT, + hierarchy_temporal_total_weight=_TEST_HIERARCHY_TEMPORAL_TOTAL_WEIGHT, + hierarchy_group_temporal_total_weight=_TEST_HIERARCHY_GROUP_TEMPORAL_TOTAL_WEIGHT, + window_column=_TEST_WINDOW_COLUMN, + window_stride_length=_TEST_WINDOW_STRIDE_LENGTH, + window_max_count=_TEST_WINDOW_MAX_COUNT, sync=sync, + create_request_timeout=None, + holiday_regions=_TEST_TRAINING_HOLIDAY_REGIONS, ) if not sync: model_from_job.wait() - true_fraction_split = gca_training_pipeline.FractionSplit( - training_fraction=_TEST_TRAINING_FRACTION_SPLIT, - validation_fraction=_TEST_VALIDATION_FRACTION_SPLIT, - test_fraction=_TEST_TEST_FRACTION_SPLIT, + true_managed_model = gca_model.Model( + display_name=_TEST_MODEL_DISPLAY_NAME, labels=_TEST_MODEL_LABELS ) - true_managed_model = gca_model.Model(display_name=_TEST_MODEL_DISPLAY_NAME) - true_input_data_config = gca_training_pipeline.InputDataConfig( - fraction_split=true_fraction_split, predefined_split=gca_training_pipeline.PredefinedSplit( key=_TEST_PREDEFINED_SPLIT_COLUMN_NAME ), @@ -267,8 +353,9 @@ def test_run_call_pipeline_service_create( true_training_pipeline = gca_training_pipeline.TrainingPipeline( display_name=_TEST_DISPLAY_NAME, - training_task_definition=schema.training_job.definition.automl_forecasting, - training_task_inputs=_TEST_TRAINING_TASK_INPUTS, + labels=_TEST_LABELS, + training_task_definition=training_job._training_task_definition, + training_task_inputs=_TEST_TRAINING_TASK_INPUTS_WITH_ADDITIONAL_EXPERIMENTS, model_to_upload=true_managed_model, input_data_config=true_input_data_config, ) @@ -276,11 +363,14 @@ def test_run_call_pipeline_service_create( mock_pipeline_service_create.assert_called_once_with( parent=initializer.global_config.common_location_path(), training_pipeline=true_training_pipeline, + timeout=None, ) assert job._gca_resource is mock_pipeline_service_get.return_value - mock_model_service_get.assert_called_once_with(name=_TEST_MODEL_NAME) + mock_model_service_get.assert_called_once_with( + name=_TEST_MODEL_NAME, retry=base._DEFAULT_RETRY + ) assert model_from_job._gca_resource is mock_model_service_get.return_value @@ -290,21 +380,124 @@ def test_run_call_pipeline_service_create( assert job.state == gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + @pytest.mark.parametrize( + "training_job", + [ + training_jobs.AutoMLForecastingTrainingJob, + training_jobs.SequenceToSequencePlusForecastingTrainingJob, + ], + ) + def test_run_call_pipeline_service_create_with_timeout( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + mock_dataset_time_series, + mock_model_service_get, + sync, + training_job, + ): + aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME) + + job = training_job( + display_name=_TEST_DISPLAY_NAME, + optimization_objective=_TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME, + column_transformations=_TEST_TRAINING_COLUMN_TRANSFORMATIONS, + labels=_TEST_LABELS, + ) + + model_from_job = job.run( + dataset=mock_dataset_time_series, + target_column=_TEST_TRAINING_TARGET_COLUMN, + time_column=_TEST_TRAINING_TIME_COLUMN, + time_series_identifier_column=_TEST_TRAINING_TIME_SERIES_IDENTIFIER_COLUMN, + unavailable_at_forecast_columns=_TEST_TRAINING_UNAVAILABLE_AT_FORECAST_COLUMNS, + available_at_forecast_columns=_TEST_TRAINING_AVAILABLE_AT_FORECAST_COLUMNS, + forecast_horizon=_TEST_TRAINING_FORECAST_HORIZON, + data_granularity_unit=_TEST_TRAINING_DATA_GRANULARITY_UNIT, + data_granularity_count=_TEST_TRAINING_DATA_GRANULARITY_COUNT, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + model_labels=_TEST_MODEL_LABELS, + predefined_split_column_name=_TEST_PREDEFINED_SPLIT_COLUMN_NAME, + weight_column=_TEST_TRAINING_WEIGHT_COLUMN, + time_series_attribute_columns=_TEST_TRAINING_TIME_SERIES_ATTRIBUTE_COLUMNS, + context_window=_TEST_TRAINING_CONTEXT_WINDOW, + budget_milli_node_hours=_TEST_TRAINING_BUDGET_MILLI_NODE_HOURS, + export_evaluated_data_items=_TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS, + export_evaluated_data_items_bigquery_destination_uri=_TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS_BIGQUERY_DESTINATION_URI, + export_evaluated_data_items_override_destination=_TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS_OVERRIDE_DESTINATION, + quantiles=_TEST_TRAINING_QUANTILES, + validation_options=_TEST_TRAINING_VALIDATION_OPTIONS, + additional_experiments=_TEST_ADDITIONAL_EXPERIMENTS, + hierarchy_group_columns=_TEST_HIERARCHY_GROUP_COLUMNS, + hierarchy_group_total_weight=_TEST_HIERARCHY_GROUP_TOTAL_WEIGHT, + hierarchy_temporal_total_weight=_TEST_HIERARCHY_TEMPORAL_TOTAL_WEIGHT, + hierarchy_group_temporal_total_weight=_TEST_HIERARCHY_GROUP_TEMPORAL_TOTAL_WEIGHT, + window_column=_TEST_WINDOW_COLUMN, + window_stride_length=_TEST_WINDOW_STRIDE_LENGTH, + window_max_count=_TEST_WINDOW_MAX_COUNT, + sync=sync, + create_request_timeout=180.0, + holiday_regions=_TEST_TRAINING_HOLIDAY_REGIONS, + ) + + if not sync: + model_from_job.wait() + + true_managed_model = gca_model.Model( + display_name=_TEST_MODEL_DISPLAY_NAME, labels=_TEST_MODEL_LABELS + ) + + true_input_data_config = gca_training_pipeline.InputDataConfig( + predefined_split=gca_training_pipeline.PredefinedSplit( + key=_TEST_PREDEFINED_SPLIT_COLUMN_NAME + ), + dataset_id=mock_dataset_time_series.name, + ) + + true_training_pipeline = gca_training_pipeline.TrainingPipeline( + display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, + training_task_definition=training_job._training_task_definition, + training_task_inputs=_TEST_TRAINING_TASK_INPUTS_WITH_ADDITIONAL_EXPERIMENTS, + model_to_upload=true_managed_model, + input_data_config=true_input_data_config, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + training_pipeline=true_training_pipeline, + timeout=180.0, + ) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.usefixtures("mock_pipeline_service_get") @pytest.mark.parametrize("sync", [True, False]) - def test_run_call_pipeline_if_no_model_display_name( + @pytest.mark.parametrize( + "training_job", + [ + training_jobs.AutoMLForecastingTrainingJob, + training_jobs.SequenceToSequencePlusForecastingTrainingJob, + ], + ) + def test_run_call_pipeline_if_no_model_display_name_nor_model_labels( self, mock_pipeline_service_create, mock_dataset_time_series, mock_model_service_get, sync, + training_job, ): aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME) - job = AutoMLForecastingTrainingJob( + job = training_job( display_name=_TEST_DISPLAY_NAME, optimization_objective=_TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME, column_transformations=_TEST_TRAINING_COLUMN_TRANSFORMATIONS, + labels=_TEST_LABELS, ) model_from_job = job.run( @@ -326,30 +519,120 @@ def test_run_call_pipeline_if_no_model_display_name( export_evaluated_data_items_override_destination=_TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS_OVERRIDE_DESTINATION, quantiles=_TEST_TRAINING_QUANTILES, validation_options=_TEST_TRAINING_VALIDATION_OPTIONS, + hierarchy_group_columns=_TEST_HIERARCHY_GROUP_COLUMNS, + hierarchy_group_total_weight=_TEST_HIERARCHY_GROUP_TOTAL_WEIGHT, + hierarchy_temporal_total_weight=_TEST_HIERARCHY_TEMPORAL_TOTAL_WEIGHT, + hierarchy_group_temporal_total_weight=_TEST_HIERARCHY_GROUP_TEMPORAL_TOTAL_WEIGHT, + window_column=_TEST_WINDOW_COLUMN, + window_stride_length=_TEST_WINDOW_STRIDE_LENGTH, + window_max_count=_TEST_WINDOW_MAX_COUNT, sync=sync, + create_request_timeout=None, + holiday_regions=_TEST_TRAINING_HOLIDAY_REGIONS, ) if not sync: model_from_job.wait() - true_fraction_split = gca_training_pipeline.FractionSplit( - training_fraction=_TEST_TRAINING_FRACTION_SPLIT, - validation_fraction=_TEST_VALIDATION_FRACTION_SPLIT, - test_fraction=_TEST_TEST_FRACTION_SPLIT, + # Test that if defaults to the job display name + true_managed_model = gca_model.Model( + display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, + ) + + true_input_data_config = gca_training_pipeline.InputDataConfig( + dataset_id=mock_dataset_time_series.name, ) + true_training_pipeline = gca_training_pipeline.TrainingPipeline( + display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, + training_task_definition=training_job._training_task_definition, + training_task_inputs=_TEST_TRAINING_TASK_INPUTS, + model_to_upload=true_managed_model, + input_data_config=true_input_data_config, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + training_pipeline=true_training_pipeline, + timeout=None, + ) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.usefixtures("mock_pipeline_service_get") + @pytest.mark.parametrize("sync", [True, False]) + @pytest.mark.parametrize( + "training_job", + [ + training_jobs.AutoMLForecastingTrainingJob, + training_jobs.SequenceToSequencePlusForecastingTrainingJob, + ], + ) + def test_run_call_pipeline_if_set_additional_experiments( + self, + mock_pipeline_service_create, + mock_dataset_time_series, + mock_model_service_get, + sync, + training_job, + ): + aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME) + + job = training_job( + display_name=_TEST_DISPLAY_NAME, + optimization_objective=_TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME, + column_transformations=_TEST_TRAINING_COLUMN_TRANSFORMATIONS, + ) + + job._add_additional_experiments(_TEST_ADDITIONAL_EXPERIMENTS) + + model_from_job = job.run( + dataset=mock_dataset_time_series, + target_column=_TEST_TRAINING_TARGET_COLUMN, + time_column=_TEST_TRAINING_TIME_COLUMN, + time_series_identifier_column=_TEST_TRAINING_TIME_SERIES_IDENTIFIER_COLUMN, + unavailable_at_forecast_columns=_TEST_TRAINING_UNAVAILABLE_AT_FORECAST_COLUMNS, + available_at_forecast_columns=_TEST_TRAINING_AVAILABLE_AT_FORECAST_COLUMNS, + forecast_horizon=_TEST_TRAINING_FORECAST_HORIZON, + data_granularity_unit=_TEST_TRAINING_DATA_GRANULARITY_UNIT, + data_granularity_count=_TEST_TRAINING_DATA_GRANULARITY_COUNT, + weight_column=_TEST_TRAINING_WEIGHT_COLUMN, + time_series_attribute_columns=_TEST_TRAINING_TIME_SERIES_ATTRIBUTE_COLUMNS, + context_window=_TEST_TRAINING_CONTEXT_WINDOW, + budget_milli_node_hours=_TEST_TRAINING_BUDGET_MILLI_NODE_HOURS, + export_evaluated_data_items=_TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS, + export_evaluated_data_items_bigquery_destination_uri=_TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS_BIGQUERY_DESTINATION_URI, + export_evaluated_data_items_override_destination=_TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS_OVERRIDE_DESTINATION, + quantiles=_TEST_TRAINING_QUANTILES, + validation_options=_TEST_TRAINING_VALIDATION_OPTIONS, + hierarchy_group_columns=_TEST_HIERARCHY_GROUP_COLUMNS, + hierarchy_group_total_weight=_TEST_HIERARCHY_GROUP_TOTAL_WEIGHT, + hierarchy_temporal_total_weight=_TEST_HIERARCHY_TEMPORAL_TOTAL_WEIGHT, + hierarchy_group_temporal_total_weight=_TEST_HIERARCHY_GROUP_TEMPORAL_TOTAL_WEIGHT, + window_column=_TEST_WINDOW_COLUMN, + window_stride_length=_TEST_WINDOW_STRIDE_LENGTH, + window_max_count=_TEST_WINDOW_MAX_COUNT, + sync=sync, + create_request_timeout=None, + holiday_regions=_TEST_TRAINING_HOLIDAY_REGIONS, + ) + + if not sync: + model_from_job.wait() + # Test that if defaults to the job display name true_managed_model = gca_model.Model(display_name=_TEST_DISPLAY_NAME) true_input_data_config = gca_training_pipeline.InputDataConfig( - fraction_split=true_fraction_split, dataset_id=mock_dataset_time_series.name, ) true_training_pipeline = gca_training_pipeline.TrainingPipeline( display_name=_TEST_DISPLAY_NAME, - training_task_definition=schema.training_job.definition.automl_forecasting, - training_task_inputs=_TEST_TRAINING_TASK_INPUTS, + training_task_definition=training_job._training_task_definition, + training_task_inputs=_TEST_TRAINING_TASK_INPUTS_WITH_ADDITIONAL_EXPERIMENTS, model_to_upload=true_managed_model, input_data_config=true_input_data_config, ) @@ -357,20 +640,33 @@ def test_run_call_pipeline_if_no_model_display_name( mock_pipeline_service_create.assert_called_once_with( parent=initializer.global_config.common_location_path(), training_pipeline=true_training_pipeline, + timeout=None, ) + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.usefixtures( "mock_pipeline_service_create", "mock_pipeline_service_get", "mock_model_service_get", ) @pytest.mark.parametrize("sync", [True, False]) + @pytest.mark.parametrize( + "training_job", + [ + training_jobs.AutoMLForecastingTrainingJob, + training_jobs.SequenceToSequencePlusForecastingTrainingJob, + ], + ) def test_run_called_twice_raises( - self, mock_dataset_time_series, sync, + self, + mock_dataset_time_series, + sync, + training_job, ): aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME) - job = AutoMLForecastingTrainingJob( + job = training_job( display_name=_TEST_DISPLAY_NAME, optimization_objective=_TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME, column_transformations=_TEST_TRAINING_COLUMN_TRANSFORMATIONS, @@ -396,7 +692,15 @@ def test_run_called_twice_raises( export_evaluated_data_items_override_destination=_TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS_OVERRIDE_DESTINATION, quantiles=_TEST_TRAINING_QUANTILES, validation_options=_TEST_TRAINING_VALIDATION_OPTIONS, + hierarchy_group_columns=_TEST_HIERARCHY_GROUP_COLUMNS, + hierarchy_group_total_weight=_TEST_HIERARCHY_GROUP_TOTAL_WEIGHT, + hierarchy_temporal_total_weight=_TEST_HIERARCHY_TEMPORAL_TOTAL_WEIGHT, + hierarchy_group_temporal_total_weight=_TEST_HIERARCHY_GROUP_TEMPORAL_TOTAL_WEIGHT, + window_column=_TEST_WINDOW_COLUMN, + window_stride_length=_TEST_WINDOW_STRIDE_LENGTH, + window_max_count=_TEST_WINDOW_MAX_COUNT, sync=sync, + holiday_regions=_TEST_TRAINING_HOLIDAY_REGIONS, ) with pytest.raises(RuntimeError): @@ -420,20 +724,38 @@ def test_run_called_twice_raises( export_evaluated_data_items_override_destination=_TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS_OVERRIDE_DESTINATION, quantiles=_TEST_TRAINING_QUANTILES, validation_options=_TEST_TRAINING_VALIDATION_OPTIONS, + hierarchy_group_columns=_TEST_HIERARCHY_GROUP_COLUMNS, + hierarchy_group_total_weight=_TEST_HIERARCHY_GROUP_TOTAL_WEIGHT, + hierarchy_temporal_total_weight=_TEST_HIERARCHY_TEMPORAL_TOTAL_WEIGHT, + hierarchy_group_temporal_total_weight=_TEST_HIERARCHY_GROUP_TEMPORAL_TOTAL_WEIGHT, + window_column=_TEST_WINDOW_COLUMN, + window_stride_length=_TEST_WINDOW_STRIDE_LENGTH, + window_max_count=_TEST_WINDOW_MAX_COUNT, sync=sync, + holiday_regions=_TEST_TRAINING_HOLIDAY_REGIONS, ) + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) + @pytest.mark.parametrize( + "training_job", + [ + training_jobs.AutoMLForecastingTrainingJob, + training_jobs.SequenceToSequencePlusForecastingTrainingJob, + ], + ) def test_run_raises_if_pipeline_fails( self, mock_pipeline_service_create_and_get_with_fail, mock_dataset_time_series, sync, + training_job, ): aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME) - job = AutoMLForecastingTrainingJob( + job = training_job( display_name=_TEST_DISPLAY_NAME, optimization_objective=_TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME, column_transformations=_TEST_TRAINING_COLUMN_TRANSFORMATIONS, @@ -460,7 +782,15 @@ def test_run_raises_if_pipeline_fails( export_evaluated_data_items_override_destination=_TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS_OVERRIDE_DESTINATION, quantiles=_TEST_TRAINING_QUANTILES, validation_options=_TEST_TRAINING_VALIDATION_OPTIONS, + hierarchy_group_columns=_TEST_HIERARCHY_GROUP_COLUMNS, + hierarchy_group_total_weight=_TEST_HIERARCHY_GROUP_TOTAL_WEIGHT, + hierarchy_temporal_total_weight=_TEST_HIERARCHY_TEMPORAL_TOTAL_WEIGHT, + hierarchy_group_temporal_total_weight=_TEST_HIERARCHY_GROUP_TEMPORAL_TOTAL_WEIGHT, + window_column=_TEST_WINDOW_COLUMN, + window_stride_length=_TEST_WINDOW_STRIDE_LENGTH, + window_max_count=_TEST_WINDOW_MAX_COUNT, sync=sync, + holiday_regions=_TEST_TRAINING_HOLIDAY_REGIONS, ) if not sync: @@ -469,10 +799,21 @@ def test_run_raises_if_pipeline_fails( with pytest.raises(RuntimeError): job.get_model() - def test_raises_before_run_is_called(self, mock_pipeline_service_create): + @pytest.mark.parametrize( + "training_job", + [ + training_jobs.AutoMLForecastingTrainingJob, + training_jobs.SequenceToSequencePlusForecastingTrainingJob, + ], + ) + def test_raises_before_run_is_called( + self, + mock_pipeline_service_create, + training_job, + ): aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME) - job = AutoMLForecastingTrainingJob( + job = training_job( display_name=_TEST_DISPLAY_NAME, optimization_objective=_TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME, column_transformations=_TEST_TRAINING_COLUMN_TRANSFORMATIONS, @@ -486,3 +827,407 @@ def test_raises_before_run_is_called(self, mock_pipeline_service_create): with pytest.raises(RuntimeError): job.state + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + @pytest.mark.parametrize( + "training_job", + [ + training_jobs.AutoMLForecastingTrainingJob, + training_jobs.SequenceToSequencePlusForecastingTrainingJob, + ], + ) + def test_splits_fraction( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + mock_dataset_time_series, + mock_model_service_get, + sync, + training_job, + ): + """ + Initiate aiplatform with encryption key name. + Create and run an Forecasting training job, verify calls and return value + """ + + aiplatform.init( + project=_TEST_PROJECT, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) + + job = training_job( + display_name=_TEST_DISPLAY_NAME, + optimization_objective=_TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME, + column_transformations=_TEST_TRAINING_COLUMN_TRANSFORMATIONS, + ) + + model_from_job = job.run( + dataset=mock_dataset_time_series, + training_fraction_split=_TEST_FRACTION_SPLIT_TRAINING, + validation_fraction_split=_TEST_FRACTION_SPLIT_VALIDATION, + test_fraction_split=_TEST_FRACTION_SPLIT_TEST, + target_column=_TEST_TRAINING_TARGET_COLUMN, + time_column=_TEST_TRAINING_TIME_COLUMN, + time_series_identifier_column=_TEST_TRAINING_TIME_SERIES_IDENTIFIER_COLUMN, + unavailable_at_forecast_columns=_TEST_TRAINING_UNAVAILABLE_AT_FORECAST_COLUMNS, + available_at_forecast_columns=_TEST_TRAINING_AVAILABLE_AT_FORECAST_COLUMNS, + forecast_horizon=_TEST_TRAINING_FORECAST_HORIZON, + data_granularity_unit=_TEST_TRAINING_DATA_GRANULARITY_UNIT, + data_granularity_count=_TEST_TRAINING_DATA_GRANULARITY_COUNT, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + weight_column=_TEST_TRAINING_WEIGHT_COLUMN, + time_series_attribute_columns=_TEST_TRAINING_TIME_SERIES_ATTRIBUTE_COLUMNS, + context_window=_TEST_TRAINING_CONTEXT_WINDOW, + budget_milli_node_hours=_TEST_TRAINING_BUDGET_MILLI_NODE_HOURS, + export_evaluated_data_items=_TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS, + export_evaluated_data_items_bigquery_destination_uri=_TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS_BIGQUERY_DESTINATION_URI, + export_evaluated_data_items_override_destination=_TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS_OVERRIDE_DESTINATION, + quantiles=_TEST_TRAINING_QUANTILES, + validation_options=_TEST_TRAINING_VALIDATION_OPTIONS, + hierarchy_group_columns=_TEST_HIERARCHY_GROUP_COLUMNS, + hierarchy_group_total_weight=_TEST_HIERARCHY_GROUP_TOTAL_WEIGHT, + hierarchy_temporal_total_weight=_TEST_HIERARCHY_TEMPORAL_TOTAL_WEIGHT, + hierarchy_group_temporal_total_weight=_TEST_HIERARCHY_GROUP_TEMPORAL_TOTAL_WEIGHT, + window_column=_TEST_WINDOW_COLUMN, + window_stride_length=_TEST_WINDOW_STRIDE_LENGTH, + window_max_count=_TEST_WINDOW_MAX_COUNT, + sync=sync, + create_request_timeout=None, + holiday_regions=_TEST_TRAINING_HOLIDAY_REGIONS, + ) + + if not sync: + model_from_job.wait() + + true_fraction_split = gca_training_pipeline.FractionSplit( + training_fraction=_TEST_FRACTION_SPLIT_TRAINING, + validation_fraction=_TEST_FRACTION_SPLIT_VALIDATION, + test_fraction=_TEST_FRACTION_SPLIT_TEST, + ) + + true_managed_model = gca_model.Model( + display_name=_TEST_MODEL_DISPLAY_NAME, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + true_input_data_config = gca_training_pipeline.InputDataConfig( + fraction_split=true_fraction_split, + dataset_id=mock_dataset_time_series.name, + ) + + true_training_pipeline = gca_training_pipeline.TrainingPipeline( + display_name=_TEST_DISPLAY_NAME, + training_task_definition=training_job._training_task_definition, + training_task_inputs=_TEST_TRAINING_TASK_INPUTS, + model_to_upload=true_managed_model, + input_data_config=true_input_data_config, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + training_pipeline=true_training_pipeline, + timeout=None, + ) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + @pytest.mark.parametrize( + "training_job", + [ + training_jobs.AutoMLForecastingTrainingJob, + training_jobs.SequenceToSequencePlusForecastingTrainingJob, + ], + ) + def test_splits_timestamp( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + mock_dataset_time_series, + mock_model_service_get, + sync, + training_job, + ): + """Initiate aiplatform with encryption key name. + + Create and run an Forecasting training job, verify calls and + return value + """ + + aiplatform.init( + project=_TEST_PROJECT, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) + + job = training_job( + display_name=_TEST_DISPLAY_NAME, + optimization_objective=_TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME, + column_transformations=_TEST_TRAINING_COLUMN_TRANSFORMATIONS, + ) + + model_from_job = job.run( + dataset=mock_dataset_time_series, + training_fraction_split=_TEST_FRACTION_SPLIT_TRAINING, + validation_fraction_split=_TEST_FRACTION_SPLIT_VALIDATION, + test_fraction_split=_TEST_FRACTION_SPLIT_TEST, + timestamp_split_column_name=_TEST_SPLIT_TIMESTAMP_COLUMN_NAME, + target_column=_TEST_TRAINING_TARGET_COLUMN, + time_column=_TEST_TRAINING_TIME_COLUMN, + time_series_identifier_column=_TEST_TRAINING_TIME_SERIES_IDENTIFIER_COLUMN, + unavailable_at_forecast_columns=_TEST_TRAINING_UNAVAILABLE_AT_FORECAST_COLUMNS, + available_at_forecast_columns=_TEST_TRAINING_AVAILABLE_AT_FORECAST_COLUMNS, + forecast_horizon=_TEST_TRAINING_FORECAST_HORIZON, + data_granularity_unit=_TEST_TRAINING_DATA_GRANULARITY_UNIT, + data_granularity_count=_TEST_TRAINING_DATA_GRANULARITY_COUNT, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + weight_column=_TEST_TRAINING_WEIGHT_COLUMN, + time_series_attribute_columns=_TEST_TRAINING_TIME_SERIES_ATTRIBUTE_COLUMNS, + context_window=_TEST_TRAINING_CONTEXT_WINDOW, + budget_milli_node_hours=_TEST_TRAINING_BUDGET_MILLI_NODE_HOURS, + export_evaluated_data_items=_TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS, + export_evaluated_data_items_bigquery_destination_uri=_TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS_BIGQUERY_DESTINATION_URI, + export_evaluated_data_items_override_destination=_TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS_OVERRIDE_DESTINATION, + quantiles=_TEST_TRAINING_QUANTILES, + validation_options=_TEST_TRAINING_VALIDATION_OPTIONS, + hierarchy_group_columns=_TEST_HIERARCHY_GROUP_COLUMNS, + hierarchy_group_total_weight=_TEST_HIERARCHY_GROUP_TOTAL_WEIGHT, + hierarchy_temporal_total_weight=_TEST_HIERARCHY_TEMPORAL_TOTAL_WEIGHT, + hierarchy_group_temporal_total_weight=_TEST_HIERARCHY_GROUP_TEMPORAL_TOTAL_WEIGHT, + window_column=_TEST_WINDOW_COLUMN, + window_stride_length=_TEST_WINDOW_STRIDE_LENGTH, + window_max_count=_TEST_WINDOW_MAX_COUNT, + sync=sync, + create_request_timeout=None, + holiday_regions=_TEST_TRAINING_HOLIDAY_REGIONS, + ) + + if not sync: + model_from_job.wait() + + true_split = gca_training_pipeline.TimestampSplit( + training_fraction=_TEST_FRACTION_SPLIT_TRAINING, + validation_fraction=_TEST_FRACTION_SPLIT_VALIDATION, + test_fraction=_TEST_FRACTION_SPLIT_TEST, + key=_TEST_SPLIT_TIMESTAMP_COLUMN_NAME, + ) + + true_managed_model = gca_model.Model( + display_name=_TEST_MODEL_DISPLAY_NAME, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + true_input_data_config = gca_training_pipeline.InputDataConfig( + timestamp_split=true_split, dataset_id=mock_dataset_time_series.name + ) + + true_training_pipeline = gca_training_pipeline.TrainingPipeline( + display_name=_TEST_DISPLAY_NAME, + training_task_definition=training_job._training_task_definition, + training_task_inputs=_TEST_TRAINING_TASK_INPUTS, + model_to_upload=true_managed_model, + input_data_config=true_input_data_config, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + training_pipeline=true_training_pipeline, + timeout=None, + ) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + @pytest.mark.parametrize( + "training_job", + [ + training_jobs.AutoMLForecastingTrainingJob, + training_jobs.SequenceToSequencePlusForecastingTrainingJob, + ], + ) + def test_splits_predefined( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + mock_dataset_time_series, + mock_model_service_get, + sync, + training_job, + ): + """ + Initiate aiplatform with encryption key name. + Create and run an Forecasting training job, verify calls and return value + """ + + aiplatform.init( + project=_TEST_PROJECT, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) + + job = training_job( + display_name=_TEST_DISPLAY_NAME, + optimization_objective=_TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME, + column_transformations=_TEST_TRAINING_COLUMN_TRANSFORMATIONS, + ) + + model_from_job = job.run( + dataset=mock_dataset_time_series, + predefined_split_column_name=_TEST_PREDEFINED_SPLIT_COLUMN_NAME, + target_column=_TEST_TRAINING_TARGET_COLUMN, + time_column=_TEST_TRAINING_TIME_COLUMN, + time_series_identifier_column=_TEST_TRAINING_TIME_SERIES_IDENTIFIER_COLUMN, + unavailable_at_forecast_columns=_TEST_TRAINING_UNAVAILABLE_AT_FORECAST_COLUMNS, + available_at_forecast_columns=_TEST_TRAINING_AVAILABLE_AT_FORECAST_COLUMNS, + forecast_horizon=_TEST_TRAINING_FORECAST_HORIZON, + data_granularity_unit=_TEST_TRAINING_DATA_GRANULARITY_UNIT, + data_granularity_count=_TEST_TRAINING_DATA_GRANULARITY_COUNT, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + weight_column=_TEST_TRAINING_WEIGHT_COLUMN, + time_series_attribute_columns=_TEST_TRAINING_TIME_SERIES_ATTRIBUTE_COLUMNS, + context_window=_TEST_TRAINING_CONTEXT_WINDOW, + budget_milli_node_hours=_TEST_TRAINING_BUDGET_MILLI_NODE_HOURS, + export_evaluated_data_items=_TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS, + export_evaluated_data_items_bigquery_destination_uri=_TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS_BIGQUERY_DESTINATION_URI, + export_evaluated_data_items_override_destination=_TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS_OVERRIDE_DESTINATION, + quantiles=_TEST_TRAINING_QUANTILES, + validation_options=_TEST_TRAINING_VALIDATION_OPTIONS, + hierarchy_group_columns=_TEST_HIERARCHY_GROUP_COLUMNS, + hierarchy_group_total_weight=_TEST_HIERARCHY_GROUP_TOTAL_WEIGHT, + hierarchy_temporal_total_weight=_TEST_HIERARCHY_TEMPORAL_TOTAL_WEIGHT, + hierarchy_group_temporal_total_weight=_TEST_HIERARCHY_GROUP_TEMPORAL_TOTAL_WEIGHT, + window_column=_TEST_WINDOW_COLUMN, + window_stride_length=_TEST_WINDOW_STRIDE_LENGTH, + window_max_count=_TEST_WINDOW_MAX_COUNT, + sync=sync, + create_request_timeout=None, + holiday_regions=_TEST_TRAINING_HOLIDAY_REGIONS, + ) + + if not sync: + model_from_job.wait() + + true_split = gca_training_pipeline.PredefinedSplit( + key=_TEST_SPLIT_PREDEFINED_COLUMN_NAME + ) + + true_managed_model = gca_model.Model( + display_name=_TEST_MODEL_DISPLAY_NAME, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + true_input_data_config = gca_training_pipeline.InputDataConfig( + predefined_split=true_split, + dataset_id=mock_dataset_time_series.name, + ) + + true_training_pipeline = gca_training_pipeline.TrainingPipeline( + display_name=_TEST_DISPLAY_NAME, + training_task_definition=training_job._training_task_definition, + training_task_inputs=_TEST_TRAINING_TASK_INPUTS, + model_to_upload=true_managed_model, + input_data_config=true_input_data_config, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + training_pipeline=true_training_pipeline, + timeout=None, + ) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + @pytest.mark.parametrize( + "training_job", + [ + training_jobs.AutoMLForecastingTrainingJob, + training_jobs.SequenceToSequencePlusForecastingTrainingJob, + ], + ) + def test_splits_default( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + mock_dataset_time_series, + mock_model_service_get, + sync, + training_job, + ): + """ + Initiate aiplatform with encryption key name. + Create and run an Forecasting training job, verify calls and return value + """ + + aiplatform.init( + project=_TEST_PROJECT, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) + + job = training_job( + display_name=_TEST_DISPLAY_NAME, + optimization_objective=_TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME, + column_transformations=_TEST_TRAINING_COLUMN_TRANSFORMATIONS, + ) + + model_from_job = job.run( + dataset=mock_dataset_time_series, + target_column=_TEST_TRAINING_TARGET_COLUMN, + time_column=_TEST_TRAINING_TIME_COLUMN, + time_series_identifier_column=_TEST_TRAINING_TIME_SERIES_IDENTIFIER_COLUMN, + unavailable_at_forecast_columns=_TEST_TRAINING_UNAVAILABLE_AT_FORECAST_COLUMNS, + available_at_forecast_columns=_TEST_TRAINING_AVAILABLE_AT_FORECAST_COLUMNS, + forecast_horizon=_TEST_TRAINING_FORECAST_HORIZON, + data_granularity_unit=_TEST_TRAINING_DATA_GRANULARITY_UNIT, + data_granularity_count=_TEST_TRAINING_DATA_GRANULARITY_COUNT, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + weight_column=_TEST_TRAINING_WEIGHT_COLUMN, + time_series_attribute_columns=_TEST_TRAINING_TIME_SERIES_ATTRIBUTE_COLUMNS, + context_window=_TEST_TRAINING_CONTEXT_WINDOW, + budget_milli_node_hours=_TEST_TRAINING_BUDGET_MILLI_NODE_HOURS, + export_evaluated_data_items=_TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS, + export_evaluated_data_items_bigquery_destination_uri=_TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS_BIGQUERY_DESTINATION_URI, + export_evaluated_data_items_override_destination=_TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS_OVERRIDE_DESTINATION, + quantiles=_TEST_TRAINING_QUANTILES, + validation_options=_TEST_TRAINING_VALIDATION_OPTIONS, + hierarchy_group_columns=_TEST_HIERARCHY_GROUP_COLUMNS, + hierarchy_group_total_weight=_TEST_HIERARCHY_GROUP_TOTAL_WEIGHT, + hierarchy_temporal_total_weight=_TEST_HIERARCHY_TEMPORAL_TOTAL_WEIGHT, + hierarchy_group_temporal_total_weight=_TEST_HIERARCHY_GROUP_TEMPORAL_TOTAL_WEIGHT, + window_column=_TEST_WINDOW_COLUMN, + window_stride_length=_TEST_WINDOW_STRIDE_LENGTH, + window_max_count=_TEST_WINDOW_MAX_COUNT, + sync=sync, + create_request_timeout=None, + holiday_regions=_TEST_TRAINING_HOLIDAY_REGIONS, + ) + + if not sync: + model_from_job.wait() + + true_managed_model = gca_model.Model( + display_name=_TEST_MODEL_DISPLAY_NAME, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + true_input_data_config = gca_training_pipeline.InputDataConfig( + dataset_id=mock_dataset_time_series.name, + ) + + true_training_pipeline = gca_training_pipeline.TrainingPipeline( + display_name=_TEST_DISPLAY_NAME, + training_task_definition=training_job._training_task_definition, + training_task_inputs=_TEST_TRAINING_TASK_INPUTS, + model_to_upload=true_managed_model, + input_data_config=true_input_data_config, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + training_pipeline=true_training_pipeline, + timeout=None, + ) diff --git a/tests/unit/aiplatform/test_automl_image_training_jobs.py b/tests/unit/aiplatform/test_automl_image_training_jobs.py index ec0de7140b..563f16613a 100644 --- a/tests/unit/aiplatform/test_automl_image_training_jobs.py +++ b/tests/unit/aiplatform/test_automl_image_training_jobs.py @@ -1,3 +1,20 @@ +# -*- coding: utf-8 -*- + +# Copyright 2022 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. +# + import pytest import importlib from unittest import mock @@ -6,20 +23,18 @@ from google.protobuf import struct_pb2 from google.cloud import aiplatform - +from google.cloud.aiplatform import base from google.cloud.aiplatform import datasets from google.cloud.aiplatform import initializer from google.cloud.aiplatform import models from google.cloud.aiplatform import schema from google.cloud.aiplatform import training_jobs -from google.cloud.aiplatform_v1.services.model_service import ( - client as model_service_client, -) -from google.cloud.aiplatform_v1.services.pipeline_service import ( - client as pipeline_service_client, +from google.cloud.aiplatform.compat.services import ( + model_service_client, + pipeline_service_client, ) -from google.cloud.aiplatform_v1.types import ( +from google.cloud.aiplatform.compat.types import ( dataset as gca_dataset, encryption_spec as gca_encryption_spec, model as gca_model, @@ -34,7 +49,7 @@ _TEST_DISPLAY_NAME = "test-display-name" _TEST_METADATA_SCHEMA_URI_IMAGE = schema.dataset.metadata.image -_TEST_TRAINING_BUDGET_MILLI_NODE_HOURS = 1000 +_TEST_TRAINING_BUDGET_MILLI_NODE_HOURS = 7500 _TEST_TRAINING_DISABLE_EARLY_STOPPING = True _TEST_MODEL_TYPE_ICN = "CLOUD" # Image Classification default _TEST_MODEL_TYPE_IOD = "CLOUD_HIGH_ACCURACY_1" # Image Object Detection default @@ -46,6 +61,9 @@ _TEST_MODEL_DISPLAY_NAME = "model-display-name" _TEST_MODEL_ID = "98777645321" +_TEST_LABELS = {"key": "value"} +_TEST_MODEL_LABELS = {"model_key": "model_value"} + _TEST_TRAINING_TASK_INPUTS = json_format.ParseDict( { "modelType": "CLOUD", @@ -71,12 +89,16 @@ _TEST_FRACTION_SPLIT_VALIDATION = 0.2 _TEST_FRACTION_SPLIT_TEST = 0.2 +_TEST_FILTER_SPLIT_TRAINING = "train" +_TEST_FILTER_SPLIT_VALIDATION = "validate" +_TEST_FILTER_SPLIT_TEST = "test" + _TEST_MODEL_NAME = ( f"projects/{_TEST_PROJECT}/locations/{_TEST_LOCATION}/models/{_TEST_MODEL_ID}" ) _TEST_PIPELINE_RESOURCE_NAME = ( - f"projects/{_TEST_PROJECT}/locations/{_TEST_LOCATION}/trainingPipeline/12345" + f"projects/{_TEST_PROJECT}/locations/{_TEST_LOCATION}/trainingPipelines/12345" ) # CMEK encryption @@ -101,10 +123,12 @@ def mock_pipeline_service_create(): with mock.patch.object( pipeline_service_client.PipelineServiceClient, "create_training_pipeline" ) as mock_create_training_pipeline: - mock_create_training_pipeline.return_value = gca_training_pipeline.TrainingPipeline( - name=_TEST_PIPELINE_RESOURCE_NAME, - state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, - model_to_upload=gca_model.Model(name=_TEST_MODEL_NAME), + mock_create_training_pipeline.return_value = ( + gca_training_pipeline.TrainingPipeline( + name=_TEST_PIPELINE_RESOURCE_NAME, + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, + model_to_upload=gca_model.Model(name=_TEST_MODEL_NAME), + ) ) yield mock_create_training_pipeline @@ -114,10 +138,12 @@ def mock_pipeline_service_get(): with mock.patch.object( pipeline_service_client.PipelineServiceClient, "get_training_pipeline" ) as mock_get_training_pipeline: - mock_get_training_pipeline.return_value = gca_training_pipeline.TrainingPipeline( - name=_TEST_PIPELINE_RESOURCE_NAME, - state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, - model_to_upload=gca_model.Model(name=_TEST_MODEL_NAME), + mock_get_training_pipeline.return_value = ( + gca_training_pipeline.TrainingPipeline( + name=_TEST_PIPELINE_RESOURCE_NAME, + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, + model_to_upload=gca_model.Model(name=_TEST_MODEL_NAME), + ) ) yield mock_get_training_pipeline @@ -127,17 +153,21 @@ def mock_pipeline_service_create_and_get_with_fail(): with mock.patch.object( pipeline_service_client.PipelineServiceClient, "create_training_pipeline" ) as mock_create_training_pipeline: - mock_create_training_pipeline.return_value = gca_training_pipeline.TrainingPipeline( - name=_TEST_PIPELINE_RESOURCE_NAME, - state=gca_pipeline_state.PipelineState.PIPELINE_STATE_RUNNING, + mock_create_training_pipeline.return_value = ( + gca_training_pipeline.TrainingPipeline( + name=_TEST_PIPELINE_RESOURCE_NAME, + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_RUNNING, + ) ) with mock.patch.object( pipeline_service_client.PipelineServiceClient, "get_training_pipeline" ) as mock_get_training_pipeline: - mock_get_training_pipeline.return_value = gca_training_pipeline.TrainingPipeline( - name=_TEST_PIPELINE_RESOURCE_NAME, - state=gca_pipeline_state.PipelineState.PIPELINE_STATE_FAILED, + mock_get_training_pipeline.return_value = ( + gca_training_pipeline.TrainingPipeline( + name=_TEST_PIPELINE_RESOURCE_NAME, + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_FAILED, + ) ) yield mock_create_training_pipeline, mock_get_training_pipeline @@ -156,6 +186,7 @@ def mock_model_service_get(): def mock_dataset_image(): ds = mock.MagicMock(datasets.ImageDataset) ds.name = _TEST_DATASET_NAME + ds.metadata_schema_uri = _TEST_METADATA_SCHEMA_URI_IMAGE ds._latest_future = None ds._exception = None ds._gca_resource = gca_dataset.Dataset( @@ -169,7 +200,7 @@ def mock_dataset_image(): @pytest.fixture -def mock_model_image(): +def mock_model(): model = mock.MagicMock(models.Model) model.name = _TEST_MODEL_ID model._latest_future = None @@ -182,6 +213,7 @@ def mock_model_image(): yield model +@pytest.mark.usefixtures("google_auth_mock") class TestAutoMLImageTrainingJob: def setup_method(self): importlib.reload(initializer) @@ -190,8 +222,8 @@ def setup_method(self): def teardown_method(self): initializer.global_pool.shutdown(wait=True) - def test_init_all_parameters(self, mock_model_image): - """Ensure all private members are set correctly at initalization""" + def test_init_all_parameters(self, mock_model): + """Ensure all private members are set correctly at initialization""" aiplatform.init(project=_TEST_PROJECT) @@ -199,7 +231,7 @@ def test_init_all_parameters(self, mock_model_image): display_name=_TEST_DISPLAY_NAME, prediction_type=_TEST_PREDICTION_TYPE_ICN, model_type=_TEST_MODEL_TYPE_MOBILE, - base_model=mock_model_image, + base_model=mock_model, multi_label=True, ) @@ -207,16 +239,17 @@ def test_init_all_parameters(self, mock_model_image): assert job._model_type == _TEST_MODEL_TYPE_MOBILE assert job._prediction_type == _TEST_PREDICTION_TYPE_ICN assert job._multi_label is True - assert job._base_model == mock_model_image + assert job._base_model == mock_model - def test_init_wrong_parameters(self, mock_model_image): + def test_init_wrong_parameters(self, mock_model): """Ensure correct exceptions are raised when initializing with invalid args""" aiplatform.init(project=_TEST_PROJECT) with pytest.raises(ValueError, match=r"not a supported prediction type"): training_jobs.AutoMLImageTrainingJob( - display_name=_TEST_DISPLAY_NAME, prediction_type="abcdefg", + display_name=_TEST_DISPLAY_NAME, + prediction_type="abcdefg", ) with pytest.raises(ValueError, match=r"not a supported model_type for"): @@ -230,9 +263,11 @@ def test_init_wrong_parameters(self, mock_model_image): training_jobs.AutoMLImageTrainingJob( display_name=_TEST_DISPLAY_NAME, prediction_type=_TEST_PREDICTION_TYPE_IOD, - base_model=mock_model_image, + base_model=mock_model, ) + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) def test_run_call_pipeline_service_create( self, @@ -240,7 +275,7 @@ def test_run_call_pipeline_service_create( mock_pipeline_service_get, mock_dataset_image, mock_model_service_get, - mock_model_image, + mock_model, sync, ): """Create and run an AutoML ICN training job, verify calls and return value""" @@ -251,41 +286,48 @@ def test_run_call_pipeline_service_create( ) job = training_jobs.AutoMLImageTrainingJob( - display_name=_TEST_DISPLAY_NAME, base_model=mock_model_image + display_name=_TEST_DISPLAY_NAME, + base_model=mock_model, + labels=_TEST_LABELS, ) model_from_job = job.run( dataset=mock_dataset_image, model_display_name=_TEST_MODEL_DISPLAY_NAME, - training_fraction_split=_TEST_FRACTION_SPLIT_TRAINING, - validation_fraction_split=_TEST_FRACTION_SPLIT_VALIDATION, - test_fraction_split=_TEST_FRACTION_SPLIT_TEST, + model_labels=_TEST_MODEL_LABELS, + training_filter_split=_TEST_FILTER_SPLIT_TRAINING, + validation_filter_split=_TEST_FILTER_SPLIT_VALIDATION, + test_filter_split=_TEST_FILTER_SPLIT_TEST, budget_milli_node_hours=_TEST_TRAINING_BUDGET_MILLI_NODE_HOURS, disable_early_stopping=_TEST_TRAINING_DISABLE_EARLY_STOPPING, sync=sync, + create_request_timeout=None, ) if not sync: model_from_job.wait() - true_fraction_split = gca_training_pipeline.FractionSplit( - training_fraction=_TEST_FRACTION_SPLIT_TRAINING, - validation_fraction=_TEST_FRACTION_SPLIT_VALIDATION, - test_fraction=_TEST_FRACTION_SPLIT_TEST, + true_filter_split = gca_training_pipeline.FilterSplit( + training_filter=_TEST_FILTER_SPLIT_TRAINING, + validation_filter=_TEST_FILTER_SPLIT_VALIDATION, + test_filter=_TEST_FILTER_SPLIT_TEST, ) true_managed_model = gca_model.Model( display_name=_TEST_MODEL_DISPLAY_NAME, - description=mock_model_image._gca_resource.description, + labels=mock_model._gca_resource.labels, + description=mock_model._gca_resource.description, encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, ) true_input_data_config = gca_training_pipeline.InputDataConfig( - fraction_split=true_fraction_split, dataset_id=mock_dataset_image.name, + filter_split=true_filter_split, + dataset_id=mock_dataset_image.name, ) true_training_pipeline = gca_training_pipeline.TrainingPipeline( display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, training_task_definition=schema.training_job.definition.automl_image_classification, training_task_inputs=_TEST_TRAINING_TASK_INPUTS_WITH_BASE_MODEL, model_to_upload=true_managed_model, @@ -296,18 +338,98 @@ def test_run_call_pipeline_service_create( mock_pipeline_service_create.assert_called_once_with( parent=initializer.global_config.common_location_path(), training_pipeline=true_training_pipeline, + timeout=None, ) - mock_model_service_get.assert_called_once_with(name=_TEST_MODEL_NAME) + mock_model_service_get.assert_called_once_with( + name=_TEST_MODEL_NAME, retry=base._DEFAULT_RETRY + ) assert job._gca_resource is mock_pipeline_service_get.return_value assert model_from_job._gca_resource is mock_model_service_get.return_value assert job.get_model()._gca_resource is mock_model_service_get.return_value assert not job.has_failed assert job.state == gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + def test_run_call_pipeline_service_create_with_timeout( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + mock_dataset_image, + mock_model_service_get, + mock_model, + sync, + ): + """Create and run an AutoML ICN training job, verify calls and return value""" + + aiplatform.init( + project=_TEST_PROJECT, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) + + job = training_jobs.AutoMLImageTrainingJob( + display_name=_TEST_DISPLAY_NAME, + base_model=mock_model, + labels=_TEST_LABELS, + ) + + model_from_job = job.run( + dataset=mock_dataset_image, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + model_labels=_TEST_MODEL_LABELS, + training_filter_split=_TEST_FILTER_SPLIT_TRAINING, + validation_filter_split=_TEST_FILTER_SPLIT_VALIDATION, + test_filter_split=_TEST_FILTER_SPLIT_TEST, + budget_milli_node_hours=_TEST_TRAINING_BUDGET_MILLI_NODE_HOURS, + disable_early_stopping=_TEST_TRAINING_DISABLE_EARLY_STOPPING, + sync=sync, + create_request_timeout=180.0, + ) + + if not sync: + model_from_job.wait() + + true_filter_split = gca_training_pipeline.FilterSplit( + training_filter=_TEST_FILTER_SPLIT_TRAINING, + validation_filter=_TEST_FILTER_SPLIT_VALIDATION, + test_filter=_TEST_FILTER_SPLIT_TEST, + ) + + true_managed_model = gca_model.Model( + display_name=_TEST_MODEL_DISPLAY_NAME, + labels=mock_model._gca_resource.labels, + description=mock_model._gca_resource.description, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + true_input_data_config = gca_training_pipeline.InputDataConfig( + filter_split=true_filter_split, + dataset_id=mock_dataset_image.name, + ) + + true_training_pipeline = gca_training_pipeline.TrainingPipeline( + display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, + training_task_definition=schema.training_job.definition.automl_image_classification, + training_task_inputs=_TEST_TRAINING_TASK_INPUTS_WITH_BASE_MODEL, + model_to_upload=true_managed_model, + input_data_config=true_input_data_config, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + training_pipeline=true_training_pipeline, + timeout=180.0, + ) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.usefixtures("mock_pipeline_service_get") @pytest.mark.parametrize("sync", [True, False]) - def test_run_call_pipeline_if_no_model_display_name( + def test_run_call_pipeline_if_no_model_display_name_nor_model_labels( self, mock_pipeline_service_create, mock_dataset_image, @@ -318,39 +440,35 @@ def test_run_call_pipeline_if_no_model_display_name( job = training_jobs.AutoMLImageTrainingJob( display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, training_encryption_spec_key_name=_TEST_PIPELINE_ENCRYPTION_KEY_NAME, model_encryption_spec_key_name=_TEST_MODEL_ENCRYPTION_KEY_NAME, ) model_from_job = job.run( dataset=mock_dataset_image, - training_fraction_split=_TEST_FRACTION_SPLIT_TRAINING, - validation_fraction_split=_TEST_FRACTION_SPLIT_VALIDATION, - test_fraction_split=_TEST_FRACTION_SPLIT_TEST, budget_milli_node_hours=_TEST_TRAINING_BUDGET_MILLI_NODE_HOURS, disable_early_stopping=_TEST_TRAINING_DISABLE_EARLY_STOPPING, + create_request_timeout=None, ) if not sync: model_from_job.wait() - true_fraction_split = gca_training_pipeline.FractionSplit( - training_fraction=_TEST_FRACTION_SPLIT_TRAINING, - validation_fraction=_TEST_FRACTION_SPLIT_VALIDATION, - test_fraction=_TEST_FRACTION_SPLIT_TEST, - ) - # Test that if defaults to the job display name true_managed_model = gca_model.Model( - display_name=_TEST_DISPLAY_NAME, encryption_spec=_TEST_MODEL_ENCRYPTION_SPEC + display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, + encryption_spec=_TEST_MODEL_ENCRYPTION_SPEC, ) true_input_data_config = gca_training_pipeline.InputDataConfig( - fraction_split=true_fraction_split, dataset_id=mock_dataset_image.name, + dataset_id=mock_dataset_image.name ) true_training_pipeline = gca_training_pipeline.TrainingPipeline( display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, training_task_definition=schema.training_job.definition.automl_image_classification, training_task_inputs=_TEST_TRAINING_TASK_INPUTS, model_to_upload=true_managed_model, @@ -361,8 +479,11 @@ def test_run_call_pipeline_if_no_model_display_name( mock_pipeline_service_create.assert_called_once_with( parent=initializer.global_config.common_location_path(), training_pipeline=true_training_pipeline, + timeout=None, ) + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.usefixtures( "mock_pipeline_service_create", "mock_pipeline_service_get", @@ -372,7 +493,9 @@ def test_run_call_pipeline_if_no_model_display_name( def test_run_called_twice_raises(self, mock_dataset_image, sync): aiplatform.init(project=_TEST_PROJECT) - job = training_jobs.AutoMLImageTrainingJob(display_name=_TEST_DISPLAY_NAME,) + job = training_jobs.AutoMLImageTrainingJob( + display_name=_TEST_DISPLAY_NAME, + ) job.run( dataset=mock_dataset_image, @@ -386,14 +509,47 @@ def test_run_called_twice_raises(self, mock_dataset_image, sync): with pytest.raises(RuntimeError): job.run( + dataset=mock_dataset_image, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + sync=sync, + ) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.usefixtures( + "mock_pipeline_service_create", + "mock_pipeline_service_get", + "mock_model_service_get", + ) + @pytest.mark.parametrize("sync", [True, False]) + def test_run_with_two_split_raises( + self, + mock_dataset_image, + sync, + ): + aiplatform.init(project=_TEST_PROJECT) + + job = training_jobs.AutoMLImageTrainingJob( + display_name=_TEST_DISPLAY_NAME, + ) + + with pytest.raises(ValueError): + model_from_job = job.run( dataset=mock_dataset_image, model_display_name=_TEST_MODEL_DISPLAY_NAME, training_fraction_split=_TEST_FRACTION_SPLIT_TRAINING, validation_fraction_split=_TEST_FRACTION_SPLIT_VALIDATION, test_fraction_split=_TEST_FRACTION_SPLIT_TEST, + training_filter_split=_TEST_FILTER_SPLIT_TRAINING, + validation_filter_split=_TEST_FILTER_SPLIT_VALIDATION, + test_filter_split=_TEST_FILTER_SPLIT_TEST, sync=sync, ) + if not sync: + model_from_job.wait() + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) def test_run_raises_if_pipeline_fails( self, mock_pipeline_service_create_and_get_with_fail, mock_dataset_image, sync @@ -401,7 +557,9 @@ def test_run_raises_if_pipeline_fails( aiplatform.init(project=_TEST_PROJECT) - job = training_jobs.AutoMLImageTrainingJob(display_name=_TEST_DISPLAY_NAME,) + job = training_jobs.AutoMLImageTrainingJob( + display_name=_TEST_DISPLAY_NAME, + ) with pytest.raises(RuntimeError): job.run( @@ -419,10 +577,14 @@ def test_run_raises_if_pipeline_fails( with pytest.raises(RuntimeError): job.get_model() + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) def test_raises_before_run_is_called(self, mock_pipeline_service_create): aiplatform.init(project=_TEST_PROJECT) - job = training_jobs.AutoMLImageTrainingJob(display_name=_TEST_DISPLAY_NAME,) + job = training_jobs.AutoMLImageTrainingJob( + display_name=_TEST_DISPLAY_NAME, + ) with pytest.raises(RuntimeError): job.get_model() @@ -432,3 +594,243 @@ def test_raises_before_run_is_called(self, mock_pipeline_service_create): with pytest.raises(RuntimeError): job.state + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + def test_splits_fraction( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + mock_dataset_image, + mock_model_service_get, + mock_model, + sync, + ): + """ + Initiate aiplatform with encryption key name. + Create and run an AutoML Video Classification training job, verify calls and return value + """ + + aiplatform.init( + project=_TEST_PROJECT, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) + job = training_jobs.AutoMLImageTrainingJob( + display_name=_TEST_DISPLAY_NAME, base_model=mock_model + ) + + model_from_job = job.run( + dataset=mock_dataset_image, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + training_fraction_split=_TEST_FRACTION_SPLIT_TRAINING, + validation_fraction_split=_TEST_FRACTION_SPLIT_VALIDATION, + test_fraction_split=_TEST_FRACTION_SPLIT_TEST, + budget_milli_node_hours=_TEST_TRAINING_BUDGET_MILLI_NODE_HOURS, + disable_early_stopping=_TEST_TRAINING_DISABLE_EARLY_STOPPING, + sync=sync, + create_request_timeout=None, + ) + + if not sync: + model_from_job.wait() + + true_fraction_split = gca_training_pipeline.FractionSplit( + training_fraction=_TEST_FRACTION_SPLIT_TRAINING, + validation_fraction=_TEST_FRACTION_SPLIT_VALIDATION, + test_fraction=_TEST_FRACTION_SPLIT_TEST, + ) + + true_managed_model = gca_model.Model( + display_name=_TEST_MODEL_DISPLAY_NAME, + description=mock_model._gca_resource.description, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + true_input_data_config = gca_training_pipeline.InputDataConfig( + fraction_split=true_fraction_split, + dataset_id=mock_dataset_image.name, + ) + + true_training_pipeline = gca_training_pipeline.TrainingPipeline( + display_name=_TEST_DISPLAY_NAME, + training_task_definition=schema.training_job.definition.automl_image_classification, + training_task_inputs=_TEST_TRAINING_TASK_INPUTS_WITH_BASE_MODEL, + model_to_upload=true_managed_model, + input_data_config=true_input_data_config, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + training_pipeline=true_training_pipeline, + timeout=None, + ) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + def test_splits_filter( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + mock_dataset_image, + mock_model_service_get, + mock_model, + sync, + ): + """ + Initiate aiplatform with encryption key name. + Create and run an AutoML Video Classification training job, verify calls and return value + """ + + aiplatform.init( + project=_TEST_PROJECT, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) + + job = training_jobs.AutoMLImageTrainingJob( + display_name=_TEST_DISPLAY_NAME, base_model=mock_model + ) + + model_from_job = job.run( + dataset=mock_dataset_image, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + training_filter_split=_TEST_FILTER_SPLIT_TRAINING, + validation_filter_split=_TEST_FILTER_SPLIT_VALIDATION, + test_filter_split=_TEST_FILTER_SPLIT_TEST, + budget_milli_node_hours=_TEST_TRAINING_BUDGET_MILLI_NODE_HOURS, + disable_early_stopping=_TEST_TRAINING_DISABLE_EARLY_STOPPING, + sync=sync, + create_request_timeout=None, + ) + + if not sync: + model_from_job.wait() + + true_filter_split = gca_training_pipeline.FilterSplit( + training_filter=_TEST_FILTER_SPLIT_TRAINING, + validation_filter=_TEST_FILTER_SPLIT_VALIDATION, + test_filter=_TEST_FILTER_SPLIT_TEST, + ) + + true_managed_model = gca_model.Model( + display_name=_TEST_MODEL_DISPLAY_NAME, + description=mock_model._gca_resource.description, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + true_input_data_config = gca_training_pipeline.InputDataConfig( + filter_split=true_filter_split, + dataset_id=mock_dataset_image.name, + ) + + true_training_pipeline = gca_training_pipeline.TrainingPipeline( + display_name=_TEST_DISPLAY_NAME, + training_task_definition=schema.training_job.definition.automl_image_classification, + training_task_inputs=_TEST_TRAINING_TASK_INPUTS_WITH_BASE_MODEL, + model_to_upload=true_managed_model, + input_data_config=true_input_data_config, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + training_pipeline=true_training_pipeline, + timeout=None, + ) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + def test_splits_default( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + mock_dataset_image, + mock_model_service_get, + mock_model, + sync, + ): + """ + Initiate aiplatform with encryption key name. + Create and run an AutoML Video Classification training job, verify calls and return value + """ + + aiplatform.init( + project=_TEST_PROJECT, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) + + job = training_jobs.AutoMLImageTrainingJob( + display_name=_TEST_DISPLAY_NAME, base_model=mock_model + ) + + model_from_job = job.run( + dataset=mock_dataset_image, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + budget_milli_node_hours=_TEST_TRAINING_BUDGET_MILLI_NODE_HOURS, + disable_early_stopping=_TEST_TRAINING_DISABLE_EARLY_STOPPING, + sync=sync, + create_request_timeout=None, + ) + + if not sync: + model_from_job.wait() + + true_managed_model = gca_model.Model( + display_name=_TEST_MODEL_DISPLAY_NAME, + description=mock_model._gca_resource.description, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + true_input_data_config = gca_training_pipeline.InputDataConfig( + dataset_id=mock_dataset_image.name, + ) + + true_training_pipeline = gca_training_pipeline.TrainingPipeline( + display_name=_TEST_DISPLAY_NAME, + training_task_definition=schema.training_job.definition.automl_image_classification, + training_task_inputs=_TEST_TRAINING_TASK_INPUTS_WITH_BASE_MODEL, + model_to_upload=true_managed_model, + input_data_config=true_input_data_config, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + training_pipeline=true_training_pipeline, + timeout=None, + ) + + def test_splits_filter_incomplete( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + mock_dataset_image, + mock_model_service_get, + mock_model, + ): + """ + Initiate aiplatform with encryption key name. + Create and run an AutoML Video Classification training job, verify calls and return value + """ + + aiplatform.init( + project=_TEST_PROJECT, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) + + job = training_jobs.AutoMLImageTrainingJob( + display_name=_TEST_DISPLAY_NAME, base_model=mock_model + ) + + with pytest.raises(ValueError): + job.run( + dataset=mock_dataset_image, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + training_filter_split=_TEST_FILTER_SPLIT_TRAINING, + validation_fraction_split=None, + test_filter_split=_TEST_FILTER_SPLIT_TEST, + disable_early_stopping=_TEST_TRAINING_DISABLE_EARLY_STOPPING, + ) diff --git a/tests/unit/aiplatform/test_automl_tabular_training_jobs.py b/tests/unit/aiplatform/test_automl_tabular_training_jobs.py index aea5b66d5f..7a3d3340fc 100644 --- a/tests/unit/aiplatform/test_automl_tabular_training_jobs.py +++ b/tests/unit/aiplatform/test_automl_tabular_training_jobs.py @@ -1,21 +1,37 @@ +# -*- coding: utf-8 -*- + +# Copyright 2022 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. +# + import importlib import pytest from unittest import mock from google.cloud import aiplatform - +from google.cloud.aiplatform import base from google.cloud.aiplatform import datasets from google.cloud.aiplatform import initializer from google.cloud.aiplatform import schema from google.cloud.aiplatform import training_jobs -from google.cloud.aiplatform_v1.services.model_service import ( - client as model_service_client, +from google.cloud.aiplatform.compat.services import ( + model_service_client, + pipeline_service_client, ) -from google.cloud.aiplatform_v1.services.pipeline_service import ( - client as pipeline_service_client, -) -from google.cloud.aiplatform_v1.types import ( + +from google.cloud.aiplatform.compat.types import ( dataset as gca_dataset, encryption_spec as gca_encryption_spec, model as gca_model, @@ -42,6 +58,14 @@ "sepal_length", "petal_length", "petal_width", + "target", +] + +_TEST_TRAINING_COLUMN_NAMES_ALTERNATIVE = [ + "apple", + "banana", + "coconut", + "target", ] _TEST_TRAINING_COLUMN_TRANSFORMATIONS = [ @@ -50,25 +74,78 @@ {"auto": {"column_name": "petal_length"}}, {"auto": {"column_name": "petal_width"}}, ] +_TEST_TRAINING_COLUMN_SPECS = { + "apple": "auto", + "banana": "auto", + "coconut": "auto", +} +_TEST_TRAINING_COLUMN_TRANSFORMATIONS_ALTERNATIVE = [ + {"auto": {"column_name": "apple"}}, + {"auto": {"column_name": "banana"}}, + {"auto": {"column_name": "coconut"}}, +] +_TEST_TRAINING_COLUMN_TRANSFORMATIONS_ALTERNATIVE_NOT_AUTO = [ + {"numeric": {"column_name": "apple"}}, + {"categorical": {"column_name": "banana"}}, + {"text": {"column_name": "coconut"}}, +] _TEST_TRAINING_TARGET_COLUMN = "target" _TEST_TRAINING_BUDGET_MILLI_NODE_HOURS = 1000 _TEST_TRAINING_WEIGHT_COLUMN = "weight" _TEST_TRAINING_DISABLE_EARLY_STOPPING = True _TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME = "minimize-log-loss" _TEST_TRAINING_OPTIMIZATION_PREDICTION_TYPE = "classification" +_TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS = True +_TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS_BIGQUERY_DESTINATION_URI = ( + "bq://path.to.table" +) +_TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS_OVERRIDE_DESTINATION = False +_TEST_ADDITIONAL_EXPERIMENTS = ["exp1", "exp2"] +_TEST_TRAINING_TASK_INPUTS_DICT = { + # required inputs + "targetColumn": _TEST_TRAINING_TARGET_COLUMN, + "transformations": _TEST_TRAINING_COLUMN_TRANSFORMATIONS, + "trainBudgetMilliNodeHours": _TEST_TRAINING_BUDGET_MILLI_NODE_HOURS, + # optional inputs + "weightColumnName": _TEST_TRAINING_WEIGHT_COLUMN, + "disableEarlyStopping": _TEST_TRAINING_DISABLE_EARLY_STOPPING, + "predictionType": _TEST_TRAINING_OPTIMIZATION_PREDICTION_TYPE, + "optimizationObjective": _TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME, + "optimizationObjectiveRecallValue": None, + "optimizationObjectivePrecisionValue": None, +} _TEST_TRAINING_TASK_INPUTS = json_format.ParseDict( + _TEST_TRAINING_TASK_INPUTS_DICT, + struct_pb2.Value(), +) +_TEST_TRAINING_TASK_INPUTS_WITH_ADDITIONAL_EXPERIMENTS = json_format.ParseDict( + { + **_TEST_TRAINING_TASK_INPUTS_DICT, + "additionalExperiments": _TEST_ADDITIONAL_EXPERIMENTS, + }, + struct_pb2.Value(), +) +_TEST_TRAINING_TASK_INPUTS_ALTERNATIVE = json_format.ParseDict( + { + **_TEST_TRAINING_TASK_INPUTS_DICT, + "transformations": _TEST_TRAINING_COLUMN_TRANSFORMATIONS_ALTERNATIVE, + }, + struct_pb2.Value(), +) +_TEST_TRAINING_TASK_INPUTS_ALTERNATIVE_NOT_AUTO = json_format.ParseDict( + { + **_TEST_TRAINING_TASK_INPUTS_DICT, + "transformations": _TEST_TRAINING_COLUMN_TRANSFORMATIONS_ALTERNATIVE_NOT_AUTO, + }, + struct_pb2.Value(), +) +_TEST_TRAINING_TASK_INPUTS_WITH_EXPORT_EVAL_DATA_ITEMS = json_format.ParseDict( { - # required inputs - "targetColumn": _TEST_TRAINING_TARGET_COLUMN, - "transformations": _TEST_TRAINING_COLUMN_TRANSFORMATIONS, - "trainBudgetMilliNodeHours": _TEST_TRAINING_BUDGET_MILLI_NODE_HOURS, - # optional inputs - "weightColumnName": _TEST_TRAINING_WEIGHT_COLUMN, - "disableEarlyStopping": _TEST_TRAINING_DISABLE_EARLY_STOPPING, - "predictionType": _TEST_TRAINING_OPTIMIZATION_PREDICTION_TYPE, - "optimizationObjective": _TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME, - "optimizationObjectiveRecallValue": None, - "optimizationObjectivePrecisionValue": None, + **_TEST_TRAINING_TASK_INPUTS_DICT, + "exportEvaluatedDataItemsConfig": { + "destinationBigqueryUri": _TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS_BIGQUERY_DESTINATION_URI, + "overrideExistingTable": _TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS_OVERRIDE_DESTINATION, + }, }, struct_pb2.Value(), ) @@ -76,17 +153,23 @@ _TEST_DATASET_NAME = "test-dataset-name" _TEST_MODEL_DISPLAY_NAME = "model-display-name" -_TEST_TRAINING_FRACTION_SPLIT = 0.6 -_TEST_VALIDATION_FRACTION_SPLIT = 0.2 -_TEST_TEST_FRACTION_SPLIT = 0.2 -_TEST_PREDEFINED_SPLIT_COLUMN_NAME = "split" + +_TEST_LABELS = {"key": "value"} +_TEST_MODEL_LABELS = {"model_key": "model_value"} + +_TEST_FRACTION_SPLIT_TRAINING = 0.6 +_TEST_FRACTION_SPLIT_VALIDATION = 0.2 +_TEST_FRACTION_SPLIT_TEST = 0.2 + +_TEST_SPLIT_PREDEFINED_COLUMN_NAME = "split" +_TEST_SPLIT_TIMESTAMP_COLUMN_NAME = "timestamp" _TEST_OUTPUT_PYTHON_PACKAGE_PATH = "gs://test/ouput/python/trainer.tar.gz" _TEST_MODEL_NAME = "projects/my-project/locations/us-central1/models/12345" _TEST_PIPELINE_RESOURCE_NAME = ( - "projects/my-project/locations/us-central1/trainingPipeline/12345" + "projects/my-project/locations/us-central1/trainingPipelines/12345" ) # CMEK encryption @@ -111,23 +194,36 @@ def mock_pipeline_service_create(): with mock.patch.object( pipeline_service_client.PipelineServiceClient, "create_training_pipeline" ) as mock_create_training_pipeline: - mock_create_training_pipeline.return_value = gca_training_pipeline.TrainingPipeline( - name=_TEST_PIPELINE_RESOURCE_NAME, - state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, - model_to_upload=gca_model.Model(name=_TEST_MODEL_NAME), + mock_create_training_pipeline.return_value = ( + gca_training_pipeline.TrainingPipeline( + name=_TEST_PIPELINE_RESOURCE_NAME, + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, + model_to_upload=gca_model.Model(name=_TEST_MODEL_NAME), + ) ) yield mock_create_training_pipeline +@pytest.fixture +def mock_pipeline_service_create_fail(): + with mock.patch.object( + pipeline_service_client.PipelineServiceClient, "create_training_pipeline" + ) as mock_create_training_pipeline: + mock_create_training_pipeline.side_effect = RuntimeError("Mock fail") + yield mock_create_training_pipeline + + @pytest.fixture def mock_pipeline_service_get(): with mock.patch.object( pipeline_service_client.PipelineServiceClient, "get_training_pipeline" ) as mock_get_training_pipeline: - mock_get_training_pipeline.return_value = gca_training_pipeline.TrainingPipeline( - name=_TEST_PIPELINE_RESOURCE_NAME, - state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, - model_to_upload=gca_model.Model(name=_TEST_MODEL_NAME), + mock_get_training_pipeline.return_value = ( + gca_training_pipeline.TrainingPipeline( + name=_TEST_PIPELINE_RESOURCE_NAME, + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, + model_to_upload=gca_model.Model(name=_TEST_MODEL_NAME), + ) ) yield mock_get_training_pipeline @@ -137,17 +233,21 @@ def mock_pipeline_service_create_and_get_with_fail(): with mock.patch.object( pipeline_service_client.PipelineServiceClient, "create_training_pipeline" ) as mock_create_training_pipeline: - mock_create_training_pipeline.return_value = gca_training_pipeline.TrainingPipeline( - name=_TEST_PIPELINE_RESOURCE_NAME, - state=gca_pipeline_state.PipelineState.PIPELINE_STATE_RUNNING, + mock_create_training_pipeline.return_value = ( + gca_training_pipeline.TrainingPipeline( + name=_TEST_PIPELINE_RESOURCE_NAME, + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_RUNNING, + ) ) with mock.patch.object( pipeline_service_client.PipelineServiceClient, "get_training_pipeline" ) as mock_get_training_pipeline: - mock_get_training_pipeline.return_value = gca_training_pipeline.TrainingPipeline( - name=_TEST_PIPELINE_RESOURCE_NAME, - state=gca_pipeline_state.PipelineState.PIPELINE_STATE_FAILED, + mock_get_training_pipeline.return_value = ( + gca_training_pipeline.TrainingPipeline( + name=_TEST_PIPELINE_RESOURCE_NAME, + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_FAILED, + ) ) yield mock_create_training_pipeline, mock_get_training_pipeline @@ -180,6 +280,24 @@ def mock_dataset_tabular(): yield ds +@pytest.fixture +def mock_dataset_tabular_alternative(): + ds = mock.MagicMock(datasets.TabularDataset) + ds.name = _TEST_DATASET_NAME + ds._latest_future = None + ds._exception = None + ds._gca_resource = gca_dataset.Dataset( + display_name=_TEST_DATASET_DISPLAY_NAME, + metadata_schema_uri=_TEST_METADATA_SCHEMA_URI_TABULAR, + labels={}, + name=_TEST_DATASET_NAME, + metadata={}, + ) + ds.column_names = _TEST_TRAINING_COLUMN_NAMES_ALTERNATIVE + + yield ds + + @pytest.fixture def mock_dataset_nontabular(): ds = mock.MagicMock(datasets.ImageDataset) @@ -196,6 +314,7 @@ def mock_dataset_nontabular(): return ds +@pytest.mark.usefixtures("google_auth_mock") class TestAutoMLTabularTrainingJob: def setup_method(self): importlib.reload(initializer) @@ -204,6 +323,8 @@ def setup_method(self): def teardown_method(self): initializer.global_pool.shutdown(wait=True) + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) def test_run_call_pipeline_service_create( self, @@ -221,6 +342,7 @@ def test_run_call_pipeline_service_create( job = training_jobs.AutoMLTabularTrainingJob( display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, optimization_objective=_TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME, optimization_prediction_type=_TEST_TRAINING_OPTIMIZATION_PREDICTION_TYPE, column_transformations=_TEST_TRAINING_COLUMN_TRANSFORMATIONS, @@ -232,42 +354,37 @@ def test_run_call_pipeline_service_create( dataset=mock_dataset_tabular, target_column=_TEST_TRAINING_TARGET_COLUMN, model_display_name=_TEST_MODEL_DISPLAY_NAME, - training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT, - validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, - test_fraction_split=_TEST_TEST_FRACTION_SPLIT, - predefined_split_column_name=_TEST_PREDEFINED_SPLIT_COLUMN_NAME, + model_labels=_TEST_MODEL_LABELS, weight_column=_TEST_TRAINING_WEIGHT_COLUMN, budget_milli_node_hours=_TEST_TRAINING_BUDGET_MILLI_NODE_HOURS, disable_early_stopping=_TEST_TRAINING_DISABLE_EARLY_STOPPING, + additional_experiments=_TEST_ADDITIONAL_EXPERIMENTS, sync=sync, + create_request_timeout=None, ) + job.wait_for_resource_creation() + + assert job.resource_name == _TEST_PIPELINE_RESOURCE_NAME + if not sync: model_from_job.wait() - true_fraction_split = gca_training_pipeline.FractionSplit( - training_fraction=_TEST_TRAINING_FRACTION_SPLIT, - validation_fraction=_TEST_VALIDATION_FRACTION_SPLIT, - test_fraction=_TEST_TEST_FRACTION_SPLIT, - ) - true_managed_model = gca_model.Model( display_name=_TEST_MODEL_DISPLAY_NAME, + labels=_TEST_MODEL_LABELS, encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, ) true_input_data_config = gca_training_pipeline.InputDataConfig( - fraction_split=true_fraction_split, - predefined_split=gca_training_pipeline.PredefinedSplit( - key=_TEST_PREDEFINED_SPLIT_COLUMN_NAME - ), dataset_id=mock_dataset_tabular.name, ) true_training_pipeline = gca_training_pipeline.TrainingPipeline( display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, training_task_definition=schema.training_job.definition.automl_tabular, - training_task_inputs=_TEST_TRAINING_TASK_INPUTS, + training_task_inputs=_TEST_TRAINING_TASK_INPUTS_WITH_ADDITIONAL_EXPERIMENTS, model_to_upload=true_managed_model, input_data_config=true_input_data_config, encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, @@ -276,11 +393,14 @@ def test_run_call_pipeline_service_create( mock_pipeline_service_create.assert_called_once_with( parent=initializer.global_config.common_location_path(), training_pipeline=true_training_pipeline, + timeout=None, ) assert job._gca_resource is mock_pipeline_service_get.return_value - mock_model_service_get.assert_called_once_with(name=_TEST_MODEL_NAME) + mock_model_service_get.assert_called_once_with( + name=_TEST_MODEL_NAME, retry=base._DEFAULT_RETRY + ) assert model_from_job._gca_resource is mock_model_service_get.return_value @@ -290,74 +410,81 @@ def test_run_call_pipeline_service_create( assert job.state == gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED - @pytest.mark.usefixtures("mock_pipeline_service_get") + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) - def test_run_call_pipeline_if_no_model_display_name( + def test_run_call_pipeline_service_create_with_timeout( self, mock_pipeline_service_create, + mock_pipeline_service_get, mock_dataset_tabular, mock_model_service_get, sync, ): - aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME) + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_BUCKET_NAME, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) job = training_jobs.AutoMLTabularTrainingJob( display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, optimization_objective=_TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME, optimization_prediction_type=_TEST_TRAINING_OPTIMIZATION_PREDICTION_TYPE, column_transformations=_TEST_TRAINING_COLUMN_TRANSFORMATIONS, optimization_objective_recall_value=None, optimization_objective_precision_value=None, - training_encryption_spec_key_name=_TEST_PIPELINE_ENCRYPTION_KEY_NAME, - model_encryption_spec_key_name=_TEST_MODEL_ENCRYPTION_KEY_NAME, ) model_from_job = job.run( dataset=mock_dataset_tabular, target_column=_TEST_TRAINING_TARGET_COLUMN, - training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT, - validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, - test_fraction_split=_TEST_TEST_FRACTION_SPLIT, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + model_labels=_TEST_MODEL_LABELS, weight_column=_TEST_TRAINING_WEIGHT_COLUMN, budget_milli_node_hours=_TEST_TRAINING_BUDGET_MILLI_NODE_HOURS, disable_early_stopping=_TEST_TRAINING_DISABLE_EARLY_STOPPING, + additional_experiments=_TEST_ADDITIONAL_EXPERIMENTS, + sync=sync, + create_request_timeout=180.0, ) + job.wait_for_resource_creation() + if not sync: model_from_job.wait() - true_fraction_split = gca_training_pipeline.FractionSplit( - training_fraction=_TEST_TRAINING_FRACTION_SPLIT, - validation_fraction=_TEST_VALIDATION_FRACTION_SPLIT, - test_fraction=_TEST_TEST_FRACTION_SPLIT, - ) - - # Test that if defaults to the job display name true_managed_model = gca_model.Model( - display_name=_TEST_DISPLAY_NAME, encryption_spec=_TEST_MODEL_ENCRYPTION_SPEC + display_name=_TEST_MODEL_DISPLAY_NAME, + labels=_TEST_MODEL_LABELS, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, ) true_input_data_config = gca_training_pipeline.InputDataConfig( - fraction_split=true_fraction_split, dataset_id=mock_dataset_tabular.name, + dataset_id=mock_dataset_tabular.name, ) true_training_pipeline = gca_training_pipeline.TrainingPipeline( display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, training_task_definition=schema.training_job.definition.automl_tabular, - training_task_inputs=_TEST_TRAINING_TASK_INPUTS, + training_task_inputs=_TEST_TRAINING_TASK_INPUTS_WITH_ADDITIONAL_EXPERIMENTS, model_to_upload=true_managed_model, input_data_config=true_input_data_config, - encryption_spec=_TEST_PIPELINE_ENCRYPTION_SPEC, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, ) mock_pipeline_service_create.assert_called_once_with( parent=initializer.global_config.common_location_path(), training_pipeline=true_training_pipeline, + timeout=180.0, ) + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) - # This test checks that default transformations are used if no columns transformations are provided - def test_run_call_pipeline_service_create_if_no_column_transformations( + def test_run_call_pipeline_service_create_with_export_eval_data_items( self, mock_pipeline_service_create, mock_pipeline_service_get, @@ -375,7 +502,7 @@ def test_run_call_pipeline_service_create_if_no_column_transformations( display_name=_TEST_DISPLAY_NAME, optimization_objective=_TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME, optimization_prediction_type=_TEST_TRAINING_OPTIMIZATION_PREDICTION_TYPE, - column_transformations=None, + column_transformations=_TEST_TRAINING_COLUMN_TRANSFORMATIONS, optimization_objective_recall_value=None, optimization_objective_precision_value=None, ) @@ -384,42 +511,36 @@ def test_run_call_pipeline_service_create_if_no_column_transformations( dataset=mock_dataset_tabular, target_column=_TEST_TRAINING_TARGET_COLUMN, model_display_name=_TEST_MODEL_DISPLAY_NAME, - training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT, - validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, - test_fraction_split=_TEST_TEST_FRACTION_SPLIT, - predefined_split_column_name=_TEST_PREDEFINED_SPLIT_COLUMN_NAME, weight_column=_TEST_TRAINING_WEIGHT_COLUMN, budget_milli_node_hours=_TEST_TRAINING_BUDGET_MILLI_NODE_HOURS, disable_early_stopping=_TEST_TRAINING_DISABLE_EARLY_STOPPING, + export_evaluated_data_items=_TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS, + export_evaluated_data_items_bigquery_destination_uri=_TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS_BIGQUERY_DESTINATION_URI, + export_evaluated_data_items_override_destination=_TEST_TRAINING_EXPORT_EVALUATED_DATA_ITEMS_OVERRIDE_DESTINATION, sync=sync, + create_request_timeout=None, ) + job.wait_for_resource_creation() + + assert job.resource_name == _TEST_PIPELINE_RESOURCE_NAME + if not sync: model_from_job.wait() - true_fraction_split = gca_training_pipeline.FractionSplit( - training_fraction=_TEST_TRAINING_FRACTION_SPLIT, - validation_fraction=_TEST_VALIDATION_FRACTION_SPLIT, - test_fraction=_TEST_TEST_FRACTION_SPLIT, - ) - true_managed_model = gca_model.Model( display_name=_TEST_MODEL_DISPLAY_NAME, encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, ) true_input_data_config = gca_training_pipeline.InputDataConfig( - fraction_split=true_fraction_split, - predefined_split=gca_training_pipeline.PredefinedSplit( - key=_TEST_PREDEFINED_SPLIT_COLUMN_NAME - ), dataset_id=mock_dataset_tabular.name, ) true_training_pipeline = gca_training_pipeline.TrainingPipeline( display_name=_TEST_DISPLAY_NAME, training_task_definition=schema.training_job.definition.automl_tabular, - training_task_inputs=_TEST_TRAINING_TASK_INPUTS, + training_task_inputs=_TEST_TRAINING_TASK_INPUTS_WITH_EXPORT_EVAL_DATA_ITEMS, model_to_upload=true_managed_model, input_data_config=true_input_data_config, encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, @@ -428,97 +549,948 @@ def test_run_call_pipeline_service_create_if_no_column_transformations( mock_pipeline_service_create.assert_called_once_with( parent=initializer.global_config.common_location_path(), training_pipeline=true_training_pipeline, + timeout=None, ) - @pytest.mark.usefixtures( - "mock_pipeline_service_create", - "mock_pipeline_service_get", - "mock_model_service_get", - ) + assert job._gca_resource is mock_pipeline_service_get.return_value + + mock_model_service_get.assert_called_once_with( + name=_TEST_MODEL_NAME, retry=base._DEFAULT_RETRY + ) + + assert model_from_job._gca_resource is mock_model_service_get.return_value + + assert job.get_model()._gca_resource is mock_model_service_get.return_value + + assert not job.has_failed + + assert job.state == gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.usefixtures("mock_pipeline_service_get") @pytest.mark.parametrize("sync", [True, False]) - def test_run_called_twice_raises(self, mock_dataset_tabular, sync): + def test_run_call_pipeline_if_no_model_display_name_nor_model_labels( + self, + mock_pipeline_service_create, + mock_dataset_tabular, + mock_model_service_get, + sync, + ): aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME) job = training_jobs.AutoMLTabularTrainingJob( display_name=_TEST_DISPLAY_NAME, - optimization_prediction_type=_TEST_TRAINING_OPTIMIZATION_PREDICTION_TYPE, + labels=_TEST_LABELS, optimization_objective=_TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME, + optimization_prediction_type=_TEST_TRAINING_OPTIMIZATION_PREDICTION_TYPE, column_transformations=_TEST_TRAINING_COLUMN_TRANSFORMATIONS, optimization_objective_recall_value=None, optimization_objective_precision_value=None, + training_encryption_spec_key_name=_TEST_PIPELINE_ENCRYPTION_KEY_NAME, + model_encryption_spec_key_name=_TEST_MODEL_ENCRYPTION_KEY_NAME, ) - job.run( + model_from_job = job.run( dataset=mock_dataset_tabular, target_column=_TEST_TRAINING_TARGET_COLUMN, - model_display_name=_TEST_MODEL_DISPLAY_NAME, - training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT, - validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, - test_fraction_split=_TEST_TEST_FRACTION_SPLIT, - sync=sync, + weight_column=_TEST_TRAINING_WEIGHT_COLUMN, + budget_milli_node_hours=_TEST_TRAINING_BUDGET_MILLI_NODE_HOURS, + disable_early_stopping=_TEST_TRAINING_DISABLE_EARLY_STOPPING, + create_request_timeout=None, ) - with pytest.raises(RuntimeError): - job.run( - dataset=mock_dataset_tabular, - target_column=_TEST_TRAINING_TARGET_COLUMN, - model_display_name=_TEST_MODEL_DISPLAY_NAME, - training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT, - validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, - test_fraction_split=_TEST_TEST_FRACTION_SPLIT, - sync=sync, - ) + job.wait_for_resource_creation() + + assert job.resource_name == _TEST_PIPELINE_RESOURCE_NAME + + if not sync: + model_from_job.wait() + + # Test that if defaults to the job display name + true_managed_model = gca_model.Model( + display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, + encryption_spec=_TEST_MODEL_ENCRYPTION_SPEC, + ) + + true_input_data_config = gca_training_pipeline.InputDataConfig( + dataset_id=mock_dataset_tabular.name, + ) + + true_training_pipeline = gca_training_pipeline.TrainingPipeline( + display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, + training_task_definition=schema.training_job.definition.automl_tabular, + training_task_inputs=_TEST_TRAINING_TASK_INPUTS, + model_to_upload=true_managed_model, + input_data_config=true_input_data_config, + encryption_spec=_TEST_PIPELINE_ENCRYPTION_SPEC, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + training_pipeline=true_training_pipeline, + timeout=None, + ) + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) - def test_run_raises_if_pipeline_fails( - self, mock_pipeline_service_create_and_get_with_fail, mock_dataset_tabular, sync + # This test checks that default transformations are used if no columns transformations are provided + def test_run_call_pipeline_service_create_if_no_column_transformations( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + mock_dataset_tabular, + mock_model_service_get, + sync, ): - - aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME) + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_BUCKET_NAME, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) job = training_jobs.AutoMLTabularTrainingJob( display_name=_TEST_DISPLAY_NAME, - optimization_prediction_type=_TEST_TRAINING_OPTIMIZATION_PREDICTION_TYPE, optimization_objective=_TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME, - column_transformations=_TEST_TRAINING_COLUMN_TRANSFORMATIONS, + optimization_prediction_type=_TEST_TRAINING_OPTIMIZATION_PREDICTION_TYPE, + column_transformations=None, optimization_objective_recall_value=None, optimization_objective_precision_value=None, ) - with pytest.raises(RuntimeError): - job.run( - model_display_name=_TEST_MODEL_DISPLAY_NAME, - dataset=mock_dataset_tabular, - target_column=_TEST_TRAINING_TARGET_COLUMN, - training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT, - validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, - test_fraction_split=_TEST_TEST_FRACTION_SPLIT, - sync=sync, - ) + model_from_job = job.run( + dataset=mock_dataset_tabular, + target_column=_TEST_TRAINING_TARGET_COLUMN, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + weight_column=_TEST_TRAINING_WEIGHT_COLUMN, + budget_milli_node_hours=_TEST_TRAINING_BUDGET_MILLI_NODE_HOURS, + disable_early_stopping=_TEST_TRAINING_DISABLE_EARLY_STOPPING, + sync=sync, + create_request_timeout=None, + ) - if not sync: - job.wait() + job.wait_for_resource_creation() - with pytest.raises(RuntimeError): - job.get_model() + assert job.resource_name == _TEST_PIPELINE_RESOURCE_NAME - def test_raises_before_run_is_called(self, mock_pipeline_service_create): - aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME) + if not sync: + model_from_job.wait() + + true_managed_model = gca_model.Model( + display_name=_TEST_MODEL_DISPLAY_NAME, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + true_input_data_config = gca_training_pipeline.InputDataConfig( + dataset_id=mock_dataset_tabular.name, + ) + + true_training_pipeline = gca_training_pipeline.TrainingPipeline( + display_name=_TEST_DISPLAY_NAME, + training_task_definition=schema.training_job.definition.automl_tabular, + training_task_inputs=_TEST_TRAINING_TASK_INPUTS, + model_to_upload=true_managed_model, + input_data_config=true_input_data_config, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + training_pipeline=true_training_pipeline, + timeout=None, + ) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + # This test checks that default transformations are used if no columns transformations are provided + def test_run_call_pipeline_service_create_if_set_additional_experiments( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + mock_dataset_tabular, + mock_model_service_get, + sync, + ): + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_BUCKET_NAME, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) job = training_jobs.AutoMLTabularTrainingJob( display_name=_TEST_DISPLAY_NAME, - optimization_prediction_type=_TEST_TRAINING_OPTIMIZATION_PREDICTION_TYPE, optimization_objective=_TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME, - column_transformations=_TEST_TRAINING_COLUMN_TRANSFORMATIONS, + optimization_prediction_type=_TEST_TRAINING_OPTIMIZATION_PREDICTION_TYPE, + column_transformations=None, optimization_objective_recall_value=None, optimization_objective_precision_value=None, ) - with pytest.raises(RuntimeError): + job._add_additional_experiments(_TEST_ADDITIONAL_EXPERIMENTS) + + model_from_job = job.run( + dataset=mock_dataset_tabular, + target_column=_TEST_TRAINING_TARGET_COLUMN, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + weight_column=_TEST_TRAINING_WEIGHT_COLUMN, + budget_milli_node_hours=_TEST_TRAINING_BUDGET_MILLI_NODE_HOURS, + disable_early_stopping=_TEST_TRAINING_DISABLE_EARLY_STOPPING, + sync=sync, + create_request_timeout=None, + ) + + job.wait_for_resource_creation() + + assert job.resource_name == _TEST_PIPELINE_RESOURCE_NAME + + if not sync: + model_from_job.wait() + + true_managed_model = gca_model.Model( + display_name=_TEST_MODEL_DISPLAY_NAME, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + true_input_data_config = gca_training_pipeline.InputDataConfig( + dataset_id=mock_dataset_tabular.name, + ) + + true_training_pipeline = gca_training_pipeline.TrainingPipeline( + display_name=_TEST_DISPLAY_NAME, + training_task_definition=schema.training_job.definition.automl_tabular, + training_task_inputs=_TEST_TRAINING_TASK_INPUTS_WITH_ADDITIONAL_EXPERIMENTS, + model_to_upload=true_managed_model, + input_data_config=true_input_data_config, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + training_pipeline=true_training_pipeline, + timeout=None, + ) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + def test_run_call_pipeline_service_create_with_column_specs( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + mock_dataset_tabular_alternative, + mock_model_service_get, + sync, + ): + aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME) + + column_specs = training_jobs.AutoMLTabularTrainingJob.get_auto_column_specs( + dataset=mock_dataset_tabular_alternative, + target_column=_TEST_TRAINING_TARGET_COLUMN, + ) + + assert column_specs == _TEST_TRAINING_COLUMN_SPECS + + job = training_jobs.AutoMLTabularTrainingJob( + display_name=_TEST_DISPLAY_NAME, + optimization_objective=_TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME, + optimization_prediction_type=_TEST_TRAINING_OPTIMIZATION_PREDICTION_TYPE, + column_specs=column_specs, + optimization_objective_recall_value=None, + optimization_objective_precision_value=None, + ) + + model_from_job = job.run( + dataset=mock_dataset_tabular_alternative, + target_column=_TEST_TRAINING_TARGET_COLUMN, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + weight_column=_TEST_TRAINING_WEIGHT_COLUMN, + budget_milli_node_hours=_TEST_TRAINING_BUDGET_MILLI_NODE_HOURS, + disable_early_stopping=_TEST_TRAINING_DISABLE_EARLY_STOPPING, + sync=sync, + create_request_timeout=None, + ) + + if not sync: + model_from_job.wait() + + true_managed_model = gca_model.Model(display_name=_TEST_MODEL_DISPLAY_NAME) + + true_input_data_config = gca_training_pipeline.InputDataConfig( + dataset_id=mock_dataset_tabular_alternative.name, + ) + + true_training_pipeline = gca_training_pipeline.TrainingPipeline( + display_name=_TEST_DISPLAY_NAME, + training_task_definition=schema.training_job.definition.automl_tabular, + training_task_inputs=_TEST_TRAINING_TASK_INPUTS_ALTERNATIVE, + model_to_upload=true_managed_model, + input_data_config=true_input_data_config, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + training_pipeline=true_training_pipeline, + timeout=None, + ) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + def test_call_pipeline_service_create_with_column_specs_and_transformations_raises( + self, + mock_dataset_tabular_alternative, + sync, + ): + aiplatform.init() + + column_specs = training_jobs.AutoMLTabularTrainingJob.get_auto_column_specs( + dataset=mock_dataset_tabular_alternative, + target_column=_TEST_TRAINING_TARGET_COLUMN, + ) + + assert column_specs == _TEST_TRAINING_COLUMN_SPECS + + with pytest.raises(ValueError): + training_jobs.AutoMLTabularTrainingJob( + display_name=_TEST_DISPLAY_NAME, + optimization_prediction_type=_TEST_TRAINING_OPTIMIZATION_PREDICTION_TYPE, + column_transformations=_TEST_TRAINING_COLUMN_TRANSFORMATIONS, + column_specs=column_specs, + ) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + def test_get_column_specs_no_target_raises( + self, + mock_dataset_tabular_alternative, + sync, + ): + aiplatform.init() + + with pytest.raises(TypeError): + training_jobs.AutoMLTabularTrainingJob.get_auto_column_specs( + dataset=mock_dataset_tabular_alternative + ) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + def test_run_call_pipeline_service_create_with_column_specs_not_auto( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + mock_dataset_tabular_alternative, + mock_model_service_get, + sync, + ): + aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME) + + column_specs = training_jobs.AutoMLTabularTrainingJob.get_auto_column_specs( + dataset=mock_dataset_tabular_alternative, + target_column=_TEST_TRAINING_TARGET_COLUMN, + ) + column_specs[ + _TEST_TRAINING_COLUMN_NAMES_ALTERNATIVE[0] + ] = training_jobs.AutoMLTabularTrainingJob.column_data_types.NUMERIC + column_specs[ + _TEST_TRAINING_COLUMN_NAMES_ALTERNATIVE[1] + ] = training_jobs.AutoMLTabularTrainingJob.column_data_types.CATEGORICAL + column_specs[ + _TEST_TRAINING_COLUMN_NAMES_ALTERNATIVE[2] + ] = training_jobs.AutoMLTabularTrainingJob.column_data_types.TEXT + + job = training_jobs.AutoMLTabularTrainingJob( + display_name=_TEST_DISPLAY_NAME, + optimization_objective=_TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME, + optimization_prediction_type=_TEST_TRAINING_OPTIMIZATION_PREDICTION_TYPE, + column_specs=column_specs, + optimization_objective_recall_value=None, + optimization_objective_precision_value=None, + ) + + model_from_job = job.run( + dataset=mock_dataset_tabular_alternative, + target_column=_TEST_TRAINING_TARGET_COLUMN, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + weight_column=_TEST_TRAINING_WEIGHT_COLUMN, + budget_milli_node_hours=_TEST_TRAINING_BUDGET_MILLI_NODE_HOURS, + disable_early_stopping=_TEST_TRAINING_DISABLE_EARLY_STOPPING, + sync=sync, + create_request_timeout=None, + ) + + if not sync: + model_from_job.wait() + + true_managed_model = gca_model.Model(display_name=_TEST_MODEL_DISPLAY_NAME) + + true_input_data_config = gca_training_pipeline.InputDataConfig( + dataset_id=mock_dataset_tabular_alternative.name, + ) + + true_training_pipeline = gca_training_pipeline.TrainingPipeline( + display_name=_TEST_DISPLAY_NAME, + training_task_definition=schema.training_job.definition.automl_tabular, + training_task_inputs=_TEST_TRAINING_TASK_INPUTS_ALTERNATIVE_NOT_AUTO, + model_to_upload=true_managed_model, + input_data_config=true_input_data_config, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + training_pipeline=true_training_pipeline, + timeout=None, + ) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.usefixtures( + "mock_pipeline_service_create", + "mock_pipeline_service_get", + "mock_model_service_get", + ) + @pytest.mark.parametrize("sync", [True, False]) + # Also acts as a custom column_transformations test as it should not error during first call + def test_run_called_twice_raises(self, mock_dataset_tabular, sync): + aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME) + + job = training_jobs.AutoMLTabularTrainingJob( + display_name=_TEST_DISPLAY_NAME, + optimization_prediction_type=_TEST_TRAINING_OPTIMIZATION_PREDICTION_TYPE, + optimization_objective=_TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME, + column_transformations=_TEST_TRAINING_COLUMN_TRANSFORMATIONS, + optimization_objective_recall_value=None, + optimization_objective_precision_value=None, + ) + + job.run( + dataset=mock_dataset_tabular, + target_column=_TEST_TRAINING_TARGET_COLUMN, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + sync=sync, + ) + + job.wait_for_resource_creation() + + assert job.resource_name == _TEST_PIPELINE_RESOURCE_NAME + + with pytest.raises(RuntimeError): + job.run( + dataset=mock_dataset_tabular, + target_column=_TEST_TRAINING_TARGET_COLUMN, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + sync=sync, + ) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + def test_run_raises_if_pipeline_fails( + self, mock_pipeline_service_create_and_get_with_fail, mock_dataset_tabular, sync + ): + + aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME) + + job = training_jobs.AutoMLTabularTrainingJob( + display_name=_TEST_DISPLAY_NAME, + optimization_prediction_type=_TEST_TRAINING_OPTIMIZATION_PREDICTION_TYPE, + optimization_objective=_TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME, + column_transformations=_TEST_TRAINING_COLUMN_TRANSFORMATIONS, + optimization_objective_recall_value=None, + optimization_objective_precision_value=None, + ) + + with pytest.raises(RuntimeError): + job.run( + model_display_name=_TEST_MODEL_DISPLAY_NAME, + dataset=mock_dataset_tabular, + target_column=_TEST_TRAINING_TARGET_COLUMN, + sync=sync, + ) + + if not sync: + job.wait() + + with pytest.raises(RuntimeError): job.get_model() + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + def test_wait_for_resource_creation_does_not_fail_if_creation_does_not_fail( + self, mock_pipeline_service_create_and_get_with_fail, mock_dataset_tabular + ): + + aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME) + + job = training_jobs.AutoMLTabularTrainingJob( + display_name=_TEST_DISPLAY_NAME, + optimization_prediction_type=_TEST_TRAINING_OPTIMIZATION_PREDICTION_TYPE, + optimization_objective=_TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME, + column_transformations=_TEST_TRAINING_COLUMN_TRANSFORMATIONS, + optimization_objective_recall_value=None, + optimization_objective_precision_value=None, + ) + + job.run( + model_display_name=_TEST_MODEL_DISPLAY_NAME, + dataset=mock_dataset_tabular, + target_column=_TEST_TRAINING_TARGET_COLUMN, + sync=False, + ) + + job.wait_for_resource_creation() + + assert job.resource_name == _TEST_PIPELINE_RESOURCE_NAME + with pytest.raises(RuntimeError): - job.has_failed + job.wait() with pytest.raises(RuntimeError): - job.state + job.get_model() + + @pytest.mark.usefixtures("mock_pipeline_service_create_fail") + @pytest.mark.parametrize("sync", [True, False]) + def test_create_fails(self, mock_dataset_tabular, sync): + + aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME) + + job = training_jobs.AutoMLTabularTrainingJob( + display_name=_TEST_DISPLAY_NAME, + optimization_prediction_type=_TEST_TRAINING_OPTIMIZATION_PREDICTION_TYPE, + optimization_objective=_TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME, + column_transformations=_TEST_TRAINING_COLUMN_TRANSFORMATIONS, + optimization_objective_recall_value=None, + optimization_objective_precision_value=None, + ) + + if sync: + with pytest.raises(RuntimeError) as e: + job.run( + model_display_name=_TEST_MODEL_DISPLAY_NAME, + dataset=mock_dataset_tabular, + target_column=_TEST_TRAINING_TARGET_COLUMN, + sync=sync, + ) + assert e.match("Mock fail") + + with pytest.raises(RuntimeError) as e: + job.wait_for_resource_creation() + assert e.match( + regexp=r"AutoMLTabularTrainingJob resource is not scheduled to be created." + ) + + with pytest.raises(RuntimeError) as e: + assert job.resource_name == _TEST_PIPELINE_RESOURCE_NAME + assert e.match( + regexp=r"AutoMLTabularTrainingJob resource has not been created." + ) + + job.wait() + + with pytest.raises(RuntimeError) as e: + job.get_model() + e.match( + regexp="TrainingPipeline has not been launched. You must run this TrainingPipeline using TrainingPipeline.run." + ) + + else: + job.run( + model_display_name=_TEST_MODEL_DISPLAY_NAME, + dataset=mock_dataset_tabular, + target_column=_TEST_TRAINING_TARGET_COLUMN, + sync=sync, + ) + + with pytest.raises(RuntimeError) as e: + job.wait_for_resource_creation() + assert e.match(regexp=r"Mock fail") + + with pytest.raises(RuntimeError) as e: + assert job.resource_name == _TEST_PIPELINE_RESOURCE_NAME + assert e.match( + regexp=r"AutoMLTabularTrainingJob resource has not been created. Resource failed with: Mock fail" + ) + + with pytest.raises(RuntimeError): + job.wait() + + with pytest.raises(RuntimeError): + job.get_model() + + def test_raises_before_run_is_called(self, mock_pipeline_service_create): + aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME) + + job = training_jobs.AutoMLTabularTrainingJob( + display_name=_TEST_DISPLAY_NAME, + optimization_prediction_type=_TEST_TRAINING_OPTIMIZATION_PREDICTION_TYPE, + optimization_objective=_TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME, + column_transformations=_TEST_TRAINING_COLUMN_TRANSFORMATIONS, + optimization_objective_recall_value=None, + optimization_objective_precision_value=None, + ) + + with pytest.raises(RuntimeError): + job.get_model() + + with pytest.raises(RuntimeError): + job.has_failed + + with pytest.raises(RuntimeError): + job.state + + with pytest.raises(RuntimeError) as e: + job.wait_for_resource_creation() + assert e.match( + regexp=r"AutoMLTabularTrainingJob resource is not scheduled to be created." + ) + + def test_properties_throw_if_not_available(self): + + job = training_jobs.AutoMLTabularTrainingJob( + display_name=_TEST_DISPLAY_NAME, + optimization_prediction_type=_TEST_TRAINING_OPTIMIZATION_PREDICTION_TYPE, + optimization_objective=_TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME, + ) + + with pytest.raises(RuntimeError) as e: + job.name + assert e.match( + regexp=r"AutoMLTabularTrainingJob resource has not been created" + ) + + with pytest.raises(RuntimeError) as e: + job.resource_name + assert e.match( + regexp=r"AutoMLTabularTrainingJob resource has not been created" + ) + + with pytest.raises(RuntimeError) as e: + job.display_name + assert e.match( + regexp=r"AutoMLTabularTrainingJob resource has not been created" + ) + + with pytest.raises(RuntimeError) as e: + job.create_time + assert e.match( + regexp=r"AutoMLTabularTrainingJob resource has not been created" + ) + + with pytest.raises(RuntimeError) as e: + job.encryption_spec + assert e.match( + regexp=r"AutoMLTabularTrainingJob resource has not been created" + ) + + with pytest.raises(RuntimeError) as e: + job.labels + assert e.match( + regexp=r"AutoMLTabularTrainingJob resource has not been created" + ) + + with pytest.raises(RuntimeError) as e: + job.gca_resource + assert e.match( + regexp=r"AutoMLTabularTrainingJob resource has not been created" + ) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + def test_splits_fraction( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + mock_dataset_tabular, + mock_model_service_get, + sync, + ): + """ + Initiate aiplatform with encryption key name. + Create and run an AutoML Video Classification training job, verify calls and return value + """ + + aiplatform.init( + project=_TEST_PROJECT, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) + + job = training_jobs.AutoMLTabularTrainingJob( + display_name=_TEST_DISPLAY_NAME, + optimization_prediction_type=_TEST_TRAINING_OPTIMIZATION_PREDICTION_TYPE, + optimization_objective=_TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME, + column_transformations=_TEST_TRAINING_COLUMN_TRANSFORMATIONS, + optimization_objective_recall_value=None, + optimization_objective_precision_value=None, + ) + + model_from_job = job.run( + dataset=mock_dataset_tabular, + target_column=_TEST_TRAINING_TARGET_COLUMN, + weight_column=_TEST_TRAINING_WEIGHT_COLUMN, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + training_fraction_split=_TEST_FRACTION_SPLIT_TRAINING, + validation_fraction_split=_TEST_FRACTION_SPLIT_VALIDATION, + test_fraction_split=_TEST_FRACTION_SPLIT_TEST, + disable_early_stopping=_TEST_TRAINING_DISABLE_EARLY_STOPPING, + sync=sync, + create_request_timeout=None, + ) + + if not sync: + model_from_job.wait() + + true_fraction_split = gca_training_pipeline.FractionSplit( + training_fraction=_TEST_FRACTION_SPLIT_TRAINING, + validation_fraction=_TEST_FRACTION_SPLIT_VALIDATION, + test_fraction=_TEST_FRACTION_SPLIT_TEST, + ) + + true_managed_model = gca_model.Model( + display_name=_TEST_MODEL_DISPLAY_NAME, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + true_input_data_config = gca_training_pipeline.InputDataConfig( + fraction_split=true_fraction_split, + dataset_id=mock_dataset_tabular.name, + ) + + true_training_pipeline = gca_training_pipeline.TrainingPipeline( + display_name=_TEST_DISPLAY_NAME, + training_task_definition=schema.training_job.definition.automl_tabular, + training_task_inputs=_TEST_TRAINING_TASK_INPUTS, + model_to_upload=true_managed_model, + input_data_config=true_input_data_config, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + training_pipeline=true_training_pipeline, + timeout=None, + ) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + def test_splits_timestamp( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + mock_dataset_tabular, + mock_model_service_get, + sync, + ): + """ + Initiate aiplatform with encryption key name. + Create and run an AutoML Video Classification training job, verify calls and return value + """ + + aiplatform.init( + project=_TEST_PROJECT, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) + + job = training_jobs.AutoMLTabularTrainingJob( + display_name=_TEST_DISPLAY_NAME, + optimization_prediction_type=_TEST_TRAINING_OPTIMIZATION_PREDICTION_TYPE, + optimization_objective=_TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME, + column_transformations=_TEST_TRAINING_COLUMN_TRANSFORMATIONS, + optimization_objective_recall_value=None, + optimization_objective_precision_value=None, + ) + + model_from_job = job.run( + dataset=mock_dataset_tabular, + target_column=_TEST_TRAINING_TARGET_COLUMN, + weight_column=_TEST_TRAINING_WEIGHT_COLUMN, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + training_fraction_split=_TEST_FRACTION_SPLIT_TRAINING, + validation_fraction_split=_TEST_FRACTION_SPLIT_VALIDATION, + test_fraction_split=_TEST_FRACTION_SPLIT_TEST, + timestamp_split_column_name=_TEST_SPLIT_TIMESTAMP_COLUMN_NAME, + disable_early_stopping=_TEST_TRAINING_DISABLE_EARLY_STOPPING, + sync=sync, + create_request_timeout=None, + ) + + if not sync: + model_from_job.wait() + + true_split = gca_training_pipeline.TimestampSplit( + training_fraction=_TEST_FRACTION_SPLIT_TRAINING, + validation_fraction=_TEST_FRACTION_SPLIT_VALIDATION, + test_fraction=_TEST_FRACTION_SPLIT_TEST, + key=_TEST_SPLIT_TIMESTAMP_COLUMN_NAME, + ) + + true_managed_model = gca_model.Model( + display_name=_TEST_MODEL_DISPLAY_NAME, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + true_input_data_config = gca_training_pipeline.InputDataConfig( + timestamp_split=true_split, + dataset_id=mock_dataset_tabular.name, + ) + + true_training_pipeline = gca_training_pipeline.TrainingPipeline( + display_name=_TEST_DISPLAY_NAME, + training_task_definition=schema.training_job.definition.automl_tabular, + training_task_inputs=_TEST_TRAINING_TASK_INPUTS, + model_to_upload=true_managed_model, + input_data_config=true_input_data_config, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + training_pipeline=true_training_pipeline, + timeout=None, + ) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + def test_splits_predefined( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + mock_dataset_tabular, + mock_model_service_get, + sync, + ): + """ + Initiate aiplatform with encryption key name. + Create and run an AutoML Video Classification training job, verify calls and return value + """ + + aiplatform.init( + project=_TEST_PROJECT, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) + + job = training_jobs.AutoMLTabularTrainingJob( + display_name=_TEST_DISPLAY_NAME, + optimization_prediction_type=_TEST_TRAINING_OPTIMIZATION_PREDICTION_TYPE, + optimization_objective=_TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME, + column_transformations=_TEST_TRAINING_COLUMN_TRANSFORMATIONS, + optimization_objective_recall_value=None, + optimization_objective_precision_value=None, + ) + + model_from_job = job.run( + dataset=mock_dataset_tabular, + target_column=_TEST_TRAINING_TARGET_COLUMN, + weight_column=_TEST_TRAINING_WEIGHT_COLUMN, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + predefined_split_column_name=_TEST_SPLIT_PREDEFINED_COLUMN_NAME, + disable_early_stopping=_TEST_TRAINING_DISABLE_EARLY_STOPPING, + sync=sync, + create_request_timeout=None, + ) + + if not sync: + model_from_job.wait() + + true_split = gca_training_pipeline.PredefinedSplit( + key=_TEST_SPLIT_PREDEFINED_COLUMN_NAME + ) + + true_managed_model = gca_model.Model( + display_name=_TEST_MODEL_DISPLAY_NAME, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + true_input_data_config = gca_training_pipeline.InputDataConfig( + predefined_split=true_split, + dataset_id=mock_dataset_tabular.name, + ) + + true_training_pipeline = gca_training_pipeline.TrainingPipeline( + display_name=_TEST_DISPLAY_NAME, + training_task_definition=schema.training_job.definition.automl_tabular, + training_task_inputs=_TEST_TRAINING_TASK_INPUTS, + model_to_upload=true_managed_model, + input_data_config=true_input_data_config, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + training_pipeline=true_training_pipeline, + timeout=None, + ) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + def test_splits_default( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + mock_dataset_tabular, + mock_model_service_get, + sync, + ): + """ + Initiate aiplatform with encryption key name. + Create and run an AutoML Video Classification training job, verify calls and return value + """ + + aiplatform.init( + project=_TEST_PROJECT, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) + + job = training_jobs.AutoMLTabularTrainingJob( + display_name=_TEST_DISPLAY_NAME, + optimization_prediction_type=_TEST_TRAINING_OPTIMIZATION_PREDICTION_TYPE, + optimization_objective=_TEST_TRAINING_OPTIMIZATION_OBJECTIVE_NAME, + column_transformations=_TEST_TRAINING_COLUMN_TRANSFORMATIONS, + optimization_objective_recall_value=None, + optimization_objective_precision_value=None, + ) + + model_from_job = job.run( + dataset=mock_dataset_tabular, + target_column=_TEST_TRAINING_TARGET_COLUMN, + weight_column=_TEST_TRAINING_WEIGHT_COLUMN, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + disable_early_stopping=_TEST_TRAINING_DISABLE_EARLY_STOPPING, + sync=sync, + create_request_timeout=None, + ) + + if not sync: + model_from_job.wait() + + true_managed_model = gca_model.Model( + display_name=_TEST_MODEL_DISPLAY_NAME, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + true_input_data_config = gca_training_pipeline.InputDataConfig( + dataset_id=mock_dataset_tabular.name, + ) + + true_training_pipeline = gca_training_pipeline.TrainingPipeline( + display_name=_TEST_DISPLAY_NAME, + training_task_definition=schema.training_job.definition.automl_tabular, + training_task_inputs=_TEST_TRAINING_TASK_INPUTS, + model_to_upload=true_managed_model, + input_data_config=true_input_data_config, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + training_pipeline=true_training_pipeline, + timeout=None, + ) diff --git a/tests/unit/aiplatform/test_automl_text_training_jobs.py b/tests/unit/aiplatform/test_automl_text_training_jobs.py index 101ff79ef5..d424cdd654 100644 --- a/tests/unit/aiplatform/test_automl_text_training_jobs.py +++ b/tests/unit/aiplatform/test_automl_text_training_jobs.py @@ -1,22 +1,37 @@ +# -*- coding: utf-8 -*- + +# Copyright 2022 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. +# + import pytest import importlib from unittest import mock from google.cloud import aiplatform - +from google.cloud.aiplatform import base from google.cloud.aiplatform import datasets from google.cloud.aiplatform import initializer from google.cloud.aiplatform import models from google.cloud.aiplatform import schema from google.cloud.aiplatform import training_jobs -from google.cloud.aiplatform_v1.services.model_service import ( - client as model_service_client, -) -from google.cloud.aiplatform_v1.services.pipeline_service import ( - client as pipeline_service_client, +from google.cloud.aiplatform.compat.services import ( + model_service_client, + pipeline_service_client, ) -from google.cloud.aiplatform_v1.types import ( +from google.cloud.aiplatform.compat.types import ( dataset as gca_dataset, encryption_spec as gca_encryption_spec, model as gca_model, @@ -42,10 +57,16 @@ _TEST_DATASET_NAME = "test-dataset-name" _TEST_MODEL_DISPLAY_NAME = "model-display-name" + +_TEST_LABELS = {"key": "value"} +_TEST_MODEL_LABELS = {"model_key": "model_value"} + _TEST_MODEL_ID = "98777645321" -_TEST_TRAINING_TASK_INPUTS_CLASSIFICATION = training_job_inputs.AutoMlTextClassificationInputs( - multi_label=_TEST_CLASSIFICATION_MULTILABEL +_TEST_TRAINING_TASK_INPUTS_CLASSIFICATION = ( + training_job_inputs.AutoMlTextClassificationInputs( + multi_label=_TEST_CLASSIFICATION_MULTILABEL + ) ) _TEST_TRAINING_TASK_INPUTS_EXTRACTION = training_job_inputs.AutoMlTextExtractionInputs() _TEST_TRAINING_TASK_INPUTS_SENTIMENT = training_job_inputs.AutoMlTextSentimentInputs( @@ -55,13 +76,17 @@ _TEST_FRACTION_SPLIT_TRAINING = 0.6 _TEST_FRACTION_SPLIT_VALIDATION = 0.2 _TEST_FRACTION_SPLIT_TEST = 0.2 +_TEST_FILTER_SPLIT_TRAINING = "train" +_TEST_FILTER_SPLIT_VALIDATION = "validate" +_TEST_FILTER_SPLIT_TEST = "test" +_TEST_PREDEFINED_SPLIT_COLUMN_NAME = "predefined_column" _TEST_MODEL_NAME = ( f"projects/{_TEST_PROJECT}/locations/{_TEST_LOCATION}/models/{_TEST_MODEL_ID}" ) _TEST_PIPELINE_RESOURCE_NAME = ( - f"projects/{_TEST_PROJECT}/locations/{_TEST_LOCATION}/trainingPipeline/12345" + f"projects/{_TEST_PROJECT}/locations/{_TEST_LOCATION}/trainingPipelines/12345" ) # CMEK encryption @@ -86,10 +111,12 @@ def mock_pipeline_service_create(): with mock.patch.object( pipeline_service_client.PipelineServiceClient, "create_training_pipeline" ) as mock_create_training_pipeline: - mock_create_training_pipeline.return_value = gca_training_pipeline.TrainingPipeline( - name=_TEST_PIPELINE_RESOURCE_NAME, - state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, - model_to_upload=gca_model.Model(name=_TEST_MODEL_NAME), + mock_create_training_pipeline.return_value = ( + gca_training_pipeline.TrainingPipeline( + name=_TEST_PIPELINE_RESOURCE_NAME, + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, + model_to_upload=gca_model.Model(name=_TEST_MODEL_NAME), + ) ) yield mock_create_training_pipeline @@ -99,10 +126,12 @@ def mock_pipeline_service_get(): with mock.patch.object( pipeline_service_client.PipelineServiceClient, "get_training_pipeline" ) as mock_get_training_pipeline: - mock_get_training_pipeline.return_value = gca_training_pipeline.TrainingPipeline( - name=_TEST_PIPELINE_RESOURCE_NAME, - state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, - model_to_upload=gca_model.Model(name=_TEST_MODEL_NAME), + mock_get_training_pipeline.return_value = ( + gca_training_pipeline.TrainingPipeline( + name=_TEST_PIPELINE_RESOURCE_NAME, + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, + model_to_upload=gca_model.Model(name=_TEST_MODEL_NAME), + ) ) yield mock_get_training_pipeline @@ -112,17 +141,21 @@ def mock_pipeline_service_create_and_get_with_fail(): with mock.patch.object( pipeline_service_client.PipelineServiceClient, "create_training_pipeline" ) as mock_create_training_pipeline: - mock_create_training_pipeline.return_value = gca_training_pipeline.TrainingPipeline( - name=_TEST_PIPELINE_RESOURCE_NAME, - state=gca_pipeline_state.PipelineState.PIPELINE_STATE_RUNNING, + mock_create_training_pipeline.return_value = ( + gca_training_pipeline.TrainingPipeline( + name=_TEST_PIPELINE_RESOURCE_NAME, + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_RUNNING, + ) ) with mock.patch.object( pipeline_service_client.PipelineServiceClient, "get_training_pipeline" ) as mock_get_training_pipeline: - mock_get_training_pipeline.return_value = gca_training_pipeline.TrainingPipeline( - name=_TEST_PIPELINE_RESOURCE_NAME, - state=gca_pipeline_state.PipelineState.PIPELINE_STATE_FAILED, + mock_get_training_pipeline.return_value = ( + gca_training_pipeline.TrainingPipeline( + name=_TEST_PIPELINE_RESOURCE_NAME, + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_FAILED, + ) ) yield mock_create_training_pipeline, mock_get_training_pipeline @@ -141,6 +174,7 @@ def mock_model_service_get(): def mock_dataset_text(): ds = mock.MagicMock(datasets.TextDataset) ds.name = _TEST_DATASET_NAME + ds.metadata_schema_uri = _TEST_METADATA_SCHEMA_URI_TEXT ds._latest_future = None ds._exception = None ds._gca_resource = gca_dataset.Dataset( @@ -159,11 +193,13 @@ def mock_model(): model.name = _TEST_MODEL_ID model._latest_future = None model._gca_resource = gca_model.Model( - display_name=_TEST_MODEL_DISPLAY_NAME, name=_TEST_MODEL_NAME, + display_name=_TEST_MODEL_DISPLAY_NAME, + name=_TEST_MODEL_NAME, ) yield model +@pytest.mark.usefixtures("google_auth_mock") class TestAutoMLTextTrainingJob: def setup_method(self): importlib.reload(initializer) @@ -173,7 +209,7 @@ def teardown_method(self): initializer.global_pool.shutdown(wait=True) def test_init_all_parameters_classification(self): - """Ensure all private members are set correctly at initalization""" + """Ensure all private members are set correctly at initialization""" aiplatform.init(project=_TEST_PROJECT) @@ -196,7 +232,7 @@ def test_init_all_parameters_classification(self): ) def test_init_all_parameters_extraction(self): - """Ensure all private members are set correctly at initalization""" + """Ensure all private members are set correctly at initialization""" aiplatform.init(project=_TEST_PROJECT) @@ -216,7 +252,7 @@ def test_init_all_parameters_extraction(self): ) def test_init_all_parameters_sentiment(self): - """Ensure all private members are set correctly at initalization""" + """Ensure all private members are set correctly at initialization""" aiplatform.init(project=_TEST_PROJECT) @@ -238,6 +274,8 @@ def test_init_all_parameters_sentiment(self): ) ) + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.usefixtures("mock_pipeline_service_get") @pytest.mark.parametrize("sync", [True, False]) def test_init_aiplatform_with_encryption_key_name_and_create_training_job( @@ -266,28 +304,20 @@ def test_init_aiplatform_with_encryption_key_name_and_create_training_job( model_from_job = job.run( dataset=mock_dataset_text, model_display_name=_TEST_MODEL_DISPLAY_NAME, - training_fraction_split=_TEST_FRACTION_SPLIT_TRAINING, - validation_fraction_split=_TEST_FRACTION_SPLIT_VALIDATION, - test_fraction_split=_TEST_FRACTION_SPLIT_TEST, sync=sync, + create_request_timeout=None, ) if not sync: model_from_job.wait() - true_fraction_split = gca_training_pipeline.FractionSplit( - training_fraction=_TEST_FRACTION_SPLIT_TRAINING, - validation_fraction=_TEST_FRACTION_SPLIT_VALIDATION, - test_fraction=_TEST_FRACTION_SPLIT_TEST, - ) - true_managed_model = gca_model.Model( display_name=_TEST_MODEL_DISPLAY_NAME, encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, ) true_input_data_config = gca_training_pipeline.InputDataConfig( - fraction_split=true_fraction_split, dataset_id=mock_dataset_text.name, + dataset_id=mock_dataset_text.name, ) true_training_pipeline = gca_training_pipeline.TrainingPipeline( @@ -302,8 +332,11 @@ def test_init_aiplatform_with_encryption_key_name_and_create_training_job( mock_pipeline_service_create.assert_called_once_with( parent=initializer.global_config.common_location_path(), training_pipeline=true_training_pipeline, + timeout=None, ) + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) def test_run_call_pipeline_service_create_classification( self, @@ -319,6 +352,7 @@ def test_run_call_pipeline_service_create_classification( job = training_jobs.AutoMLTextTrainingJob( display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, prediction_type=_TEST_PREDICTION_TYPE_CLASSIFICATION, multi_label=_TEST_CLASSIFICATION_MULTILABEL, training_encryption_spec_key_name=_TEST_PIPELINE_ENCRYPTION_KEY_NAME, @@ -328,32 +362,37 @@ def test_run_call_pipeline_service_create_classification( model_from_job = job.run( dataset=mock_dataset_text, model_display_name=_TEST_MODEL_DISPLAY_NAME, - training_fraction_split=_TEST_FRACTION_SPLIT_TRAINING, - validation_fraction_split=_TEST_FRACTION_SPLIT_VALIDATION, - test_fraction_split=_TEST_FRACTION_SPLIT_TEST, + model_labels=_TEST_MODEL_LABELS, + training_filter_split=_TEST_FILTER_SPLIT_TRAINING, + validation_filter_split=_TEST_FILTER_SPLIT_VALIDATION, + test_filter_split=_TEST_FILTER_SPLIT_TEST, sync=sync, + create_request_timeout=None, ) if not sync: model_from_job.wait() - true_fraction_split = gca_training_pipeline.FractionSplit( - training_fraction=_TEST_FRACTION_SPLIT_TRAINING, - validation_fraction=_TEST_FRACTION_SPLIT_VALIDATION, - test_fraction=_TEST_FRACTION_SPLIT_TEST, + true_filter_split = gca_training_pipeline.FilterSplit( + training_filter=_TEST_FILTER_SPLIT_TRAINING, + validation_filter=_TEST_FILTER_SPLIT_VALIDATION, + test_filter=_TEST_FILTER_SPLIT_TEST, ) true_managed_model = gca_model.Model( display_name=_TEST_MODEL_DISPLAY_NAME, + labels=_TEST_MODEL_LABELS, encryption_spec=_TEST_MODEL_ENCRYPTION_SPEC, ) true_input_data_config = gca_training_pipeline.InputDataConfig( - fraction_split=true_fraction_split, dataset_id=mock_dataset_text.name, + filter_split=true_filter_split, + dataset_id=mock_dataset_text.name, ) true_training_pipeline = gca_training_pipeline.TrainingPipeline( display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, training_task_definition=schema.training_job.definition.automl_text_classification, training_task_inputs=_TEST_TRAINING_TASK_INPUTS_CLASSIFICATION, model_to_upload=true_managed_model, @@ -364,15 +403,91 @@ def test_run_call_pipeline_service_create_classification( mock_pipeline_service_create.assert_called_once_with( parent=initializer.global_config.common_location_path(), training_pipeline=true_training_pipeline, + timeout=None, ) - mock_model_service_get.assert_called_once_with(name=_TEST_MODEL_NAME) + mock_model_service_get.assert_called_once_with( + name=_TEST_MODEL_NAME, retry=base._DEFAULT_RETRY + ) assert job._gca_resource is mock_pipeline_service_get.return_value assert model_from_job._gca_resource is mock_model_service_get.return_value assert job.get_model()._gca_resource is mock_model_service_get.return_value assert not job.has_failed assert job.state == gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + def test_run_call_pipeline_service_create_classification_with_timeout( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + mock_dataset_text, + mock_model_service_get, + sync, + ): + """Create and run an AutoML Text Classification training job, verify calls and return value""" + + aiplatform.init(project=_TEST_PROJECT) + + job = training_jobs.AutoMLTextTrainingJob( + display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, + prediction_type=_TEST_PREDICTION_TYPE_CLASSIFICATION, + multi_label=_TEST_CLASSIFICATION_MULTILABEL, + training_encryption_spec_key_name=_TEST_PIPELINE_ENCRYPTION_KEY_NAME, + model_encryption_spec_key_name=_TEST_MODEL_ENCRYPTION_KEY_NAME, + ) + + model_from_job = job.run( + dataset=mock_dataset_text, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + model_labels=_TEST_MODEL_LABELS, + training_filter_split=_TEST_FILTER_SPLIT_TRAINING, + validation_filter_split=_TEST_FILTER_SPLIT_VALIDATION, + test_filter_split=_TEST_FILTER_SPLIT_TEST, + sync=sync, + create_request_timeout=180.0, + ) + + if not sync: + model_from_job.wait() + + true_filter_split = gca_training_pipeline.FilterSplit( + training_filter=_TEST_FILTER_SPLIT_TRAINING, + validation_filter=_TEST_FILTER_SPLIT_VALIDATION, + test_filter=_TEST_FILTER_SPLIT_TEST, + ) + + true_managed_model = gca_model.Model( + display_name=_TEST_MODEL_DISPLAY_NAME, + labels=_TEST_MODEL_LABELS, + encryption_spec=_TEST_MODEL_ENCRYPTION_SPEC, + ) + + true_input_data_config = gca_training_pipeline.InputDataConfig( + filter_split=true_filter_split, + dataset_id=mock_dataset_text.name, + ) + + true_training_pipeline = gca_training_pipeline.TrainingPipeline( + display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, + training_task_definition=schema.training_job.definition.automl_text_classification, + training_task_inputs=_TEST_TRAINING_TASK_INPUTS_CLASSIFICATION, + model_to_upload=true_managed_model, + input_data_config=true_input_data_config, + encryption_spec=_TEST_PIPELINE_ENCRYPTION_SPEC, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + training_pipeline=true_training_pipeline, + timeout=180.0, + ) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) def test_run_call_pipeline_service_create_extraction( self, @@ -388,16 +503,19 @@ def test_run_call_pipeline_service_create_extraction( job = training_jobs.AutoMLTextTrainingJob( display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, prediction_type=_TEST_PREDICTION_TYPE_EXTRACTION, ) model_from_job = job.run( dataset=mock_dataset_text, model_display_name=_TEST_MODEL_DISPLAY_NAME, + model_labels=_TEST_MODEL_LABELS, training_fraction_split=_TEST_FRACTION_SPLIT_TRAINING, validation_fraction_split=_TEST_FRACTION_SPLIT_VALIDATION, test_fraction_split=_TEST_FRACTION_SPLIT_TEST, sync=sync, + create_request_timeout=None, ) if not sync: @@ -409,14 +527,19 @@ def test_run_call_pipeline_service_create_extraction( test_fraction=_TEST_FRACTION_SPLIT_TEST, ) - true_managed_model = gca_model.Model(display_name=_TEST_MODEL_DISPLAY_NAME) + true_managed_model = gca_model.Model( + display_name=_TEST_MODEL_DISPLAY_NAME, + labels=_TEST_MODEL_LABELS, + ) true_input_data_config = gca_training_pipeline.InputDataConfig( - fraction_split=true_fraction_split, dataset_id=mock_dataset_text.name, + fraction_split=true_fraction_split, + dataset_id=mock_dataset_text.name, ) true_training_pipeline = gca_training_pipeline.TrainingPipeline( display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, training_task_definition=schema.training_job.definition.automl_text_extraction, training_task_inputs=_TEST_TRAINING_TASK_INPUTS_EXTRACTION, model_to_upload=true_managed_model, @@ -426,15 +549,20 @@ def test_run_call_pipeline_service_create_extraction( mock_pipeline_service_create.assert_called_once_with( parent=initializer.global_config.common_location_path(), training_pipeline=true_training_pipeline, + timeout=None, ) - mock_model_service_get.assert_called_once_with(name=_TEST_MODEL_NAME) + mock_model_service_get.assert_called_once_with( + name=_TEST_MODEL_NAME, retry=base._DEFAULT_RETRY + ) assert job._gca_resource is mock_pipeline_service_get.return_value assert model_from_job._gca_resource is mock_model_service_get.return_value assert job.get_model()._gca_resource is mock_model_service_get.return_value assert not job.has_failed assert job.state == gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) def test_run_call_pipeline_service_create_sentiment( self, @@ -450,6 +578,7 @@ def test_run_call_pipeline_service_create_sentiment( job = training_jobs.AutoMLTextTrainingJob( display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, prediction_type=_TEST_PREDICTION_TYPE_SENTIMENT, sentiment_max=10, ) @@ -457,29 +586,35 @@ def test_run_call_pipeline_service_create_sentiment( model_from_job = job.run( dataset=mock_dataset_text, model_display_name=_TEST_MODEL_DISPLAY_NAME, - training_fraction_split=_TEST_FRACTION_SPLIT_TRAINING, - validation_fraction_split=_TEST_FRACTION_SPLIT_VALIDATION, - test_fraction_split=_TEST_FRACTION_SPLIT_TEST, + model_labels=_TEST_MODEL_LABELS, + training_filter_split=_TEST_FILTER_SPLIT_TRAINING, + validation_filter_split=_TEST_FILTER_SPLIT_VALIDATION, + test_filter_split=_TEST_FILTER_SPLIT_TEST, sync=sync, + create_request_timeout=None, ) if not sync: model_from_job.wait() - true_fraction_split = gca_training_pipeline.FractionSplit( - training_fraction=_TEST_FRACTION_SPLIT_TRAINING, - validation_fraction=_TEST_FRACTION_SPLIT_VALIDATION, - test_fraction=_TEST_FRACTION_SPLIT_TEST, + true_filter_split = gca_training_pipeline.FilterSplit( + training_filter=_TEST_FILTER_SPLIT_TRAINING, + validation_filter=_TEST_FILTER_SPLIT_VALIDATION, + test_filter=_TEST_FILTER_SPLIT_TEST, ) - true_managed_model = gca_model.Model(display_name=_TEST_MODEL_DISPLAY_NAME) + true_managed_model = gca_model.Model( + display_name=_TEST_MODEL_DISPLAY_NAME, labels=_TEST_MODEL_LABELS + ) true_input_data_config = gca_training_pipeline.InputDataConfig( - fraction_split=true_fraction_split, dataset_id=mock_dataset_text.name, + filter_split=true_filter_split, + dataset_id=mock_dataset_text.name, ) true_training_pipeline = gca_training_pipeline.TrainingPipeline( display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, training_task_definition=schema.training_job.definition.automl_text_sentiment, training_task_inputs=_TEST_TRAINING_TASK_INPUTS_SENTIMENT, model_to_upload=true_managed_model, @@ -489,18 +624,23 @@ def test_run_call_pipeline_service_create_sentiment( mock_pipeline_service_create.assert_called_once_with( parent=initializer.global_config.common_location_path(), training_pipeline=true_training_pipeline, + timeout=None, ) - mock_model_service_get.assert_called_once_with(name=_TEST_MODEL_NAME) + mock_model_service_get.assert_called_once_with( + name=_TEST_MODEL_NAME, retry=base._DEFAULT_RETRY + ) assert job._gca_resource is mock_pipeline_service_get.return_value assert model_from_job._gca_resource is mock_model_service_get.return_value assert job.get_model()._gca_resource is mock_model_service_get.return_value assert not job.has_failed assert job.state == gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.usefixtures("mock_pipeline_service_get") @pytest.mark.parametrize("sync", [True, False]) - def test_run_call_pipeline_if_no_model_display_name( + def test_run_call_pipeline_if_no_model_display_name_nor_model_labels( self, mock_pipeline_service_create, mock_dataset_text, @@ -514,35 +654,32 @@ def test_run_call_pipeline_if_no_model_display_name( display_name=_TEST_DISPLAY_NAME, prediction_type="classification", multi_label=True, + labels=_TEST_LABELS, ) model_from_job = job.run( dataset=mock_dataset_text, - training_fraction_split=_TEST_FRACTION_SPLIT_TRAINING, - validation_fraction_split=_TEST_FRACTION_SPLIT_VALIDATION, - test_fraction_split=_TEST_FRACTION_SPLIT_TEST, model_display_name=None, # Omit model_display_name sync=sync, + create_request_timeout=None, ) if not sync: model_from_job.wait() - true_fraction_split = gca_training_pipeline.FractionSplit( - training_fraction=_TEST_FRACTION_SPLIT_TRAINING, - validation_fraction=_TEST_FRACTION_SPLIT_VALIDATION, - test_fraction=_TEST_FRACTION_SPLIT_TEST, - ) - # Test that if defaults to the job display name - true_managed_model = gca_model.Model(display_name=_TEST_DISPLAY_NAME) + true_managed_model = gca_model.Model( + display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, + ) true_input_data_config = gca_training_pipeline.InputDataConfig( - fraction_split=true_fraction_split, dataset_id=mock_dataset_text.name, + dataset_id=mock_dataset_text.name, ) true_training_pipeline = gca_training_pipeline.TrainingPipeline( display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, training_task_definition=schema.training_job.definition.automl_text_classification, training_task_inputs=_TEST_TRAINING_TASK_INPUTS_CLASSIFICATION, model_to_upload=true_managed_model, @@ -552,8 +689,11 @@ def test_run_call_pipeline_if_no_model_display_name( mock_pipeline_service_create.assert_called_once_with( parent=initializer.global_config.common_location_path(), training_pipeline=true_training_pipeline, + timeout=None, ) + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.usefixtures( "mock_pipeline_service_create", "mock_pipeline_service_get", @@ -580,14 +720,49 @@ def test_run_called_twice_raises(self, mock_dataset_text, sync): with pytest.raises(RuntimeError): job.run( + dataset=mock_dataset_text, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + sync=sync, + ) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.usefixtures( + "mock_pipeline_service_create", + "mock_pipeline_service_get", + "mock_model_service_get", + ) + @pytest.mark.parametrize("sync", [True, False]) + def test_run_with_two_split_raises( + self, + mock_dataset_text, + sync, + ): + aiplatform.init(project=_TEST_PROJECT) + + job = training_jobs.AutoMLTextTrainingJob( + display_name=_TEST_DISPLAY_NAME, + prediction_type="classification", + multi_label=True, + ) + + with pytest.raises(ValueError): + model_from_job = job.run( dataset=mock_dataset_text, model_display_name=_TEST_MODEL_DISPLAY_NAME, training_fraction_split=_TEST_FRACTION_SPLIT_TRAINING, validation_fraction_split=_TEST_FRACTION_SPLIT_VALIDATION, test_fraction_split=_TEST_FRACTION_SPLIT_TEST, + training_filter_split=_TEST_FILTER_SPLIT_TRAINING, + validation_filter_split=_TEST_FILTER_SPLIT_VALIDATION, + test_filter_split=_TEST_FILTER_SPLIT_TEST, sync=sync, ) + if not sync: + model_from_job.wait() + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) def test_run_raises_if_pipeline_fails( self, mock_pipeline_service_create_and_get_with_fail, mock_dataset_text, sync @@ -616,3 +791,212 @@ def test_run_raises_if_pipeline_fails( with pytest.raises(RuntimeError): job.get_model() + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + def test_splits_fraction( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + mock_dataset_text, + mock_model_service_get, + mock_model, + sync, + ): + """ + Initiate aiplatform with encryption key name. + Create and run an AutoML Video Classification training job, verify calls and return value + """ + + aiplatform.init( + project=_TEST_PROJECT, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) + + job = training_jobs.AutoMLTextTrainingJob( + display_name=_TEST_DISPLAY_NAME, + prediction_type=_TEST_PREDICTION_TYPE_CLASSIFICATION, + multi_label=_TEST_CLASSIFICATION_MULTILABEL, + ) + + model_from_job = job.run( + dataset=mock_dataset_text, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + training_fraction_split=_TEST_FRACTION_SPLIT_TRAINING, + validation_fraction_split=_TEST_FRACTION_SPLIT_VALIDATION, + test_fraction_split=_TEST_FRACTION_SPLIT_TEST, + sync=sync, + create_request_timeout=None, + ) + + if not sync: + model_from_job.wait() + + true_fraction_split = gca_training_pipeline.FractionSplit( + training_fraction=_TEST_FRACTION_SPLIT_TRAINING, + validation_fraction=_TEST_FRACTION_SPLIT_VALIDATION, + test_fraction=_TEST_FRACTION_SPLIT_TEST, + ) + + true_managed_model = gca_model.Model( + display_name=_TEST_MODEL_DISPLAY_NAME, + description=mock_model._gca_resource.description, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + true_input_data_config = gca_training_pipeline.InputDataConfig( + fraction_split=true_fraction_split, + dataset_id=mock_dataset_text.name, + ) + + true_training_pipeline = gca_training_pipeline.TrainingPipeline( + display_name=_TEST_DISPLAY_NAME, + training_task_definition=schema.training_job.definition.automl_text_classification, + training_task_inputs=_TEST_TRAINING_TASK_INPUTS_CLASSIFICATION, + model_to_upload=true_managed_model, + input_data_config=true_input_data_config, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + training_pipeline=true_training_pipeline, + timeout=None, + ) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + def test_splits_filter( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + mock_dataset_text, + mock_model_service_get, + mock_model, + sync, + ): + """ + Initiate aiplatform with encryption key name. + Create and run an AutoML Video Classification training job, verify calls and return value + """ + + aiplatform.init( + project=_TEST_PROJECT, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) + + job = training_jobs.AutoMLTextTrainingJob( + display_name=_TEST_DISPLAY_NAME, + prediction_type=_TEST_PREDICTION_TYPE_CLASSIFICATION, + multi_label=_TEST_CLASSIFICATION_MULTILABEL, + ) + + model_from_job = job.run( + dataset=mock_dataset_text, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + training_filter_split=_TEST_FILTER_SPLIT_TRAINING, + validation_filter_split=_TEST_FILTER_SPLIT_VALIDATION, + test_filter_split=_TEST_FILTER_SPLIT_TEST, + sync=sync, + create_request_timeout=None, + ) + + if not sync: + model_from_job.wait() + + true_filter_split = gca_training_pipeline.FilterSplit( + training_filter=_TEST_FILTER_SPLIT_TRAINING, + validation_filter=_TEST_FILTER_SPLIT_VALIDATION, + test_filter=_TEST_FILTER_SPLIT_TEST, + ) + + true_managed_model = gca_model.Model( + display_name=_TEST_MODEL_DISPLAY_NAME, + description=mock_model._gca_resource.description, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + true_input_data_config = gca_training_pipeline.InputDataConfig( + filter_split=true_filter_split, + dataset_id=mock_dataset_text.name, + ) + + true_training_pipeline = gca_training_pipeline.TrainingPipeline( + display_name=_TEST_DISPLAY_NAME, + training_task_definition=schema.training_job.definition.automl_text_classification, + training_task_inputs=_TEST_TRAINING_TASK_INPUTS_CLASSIFICATION, + model_to_upload=true_managed_model, + input_data_config=true_input_data_config, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + training_pipeline=true_training_pipeline, + timeout=None, + ) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + def test_splits_default( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + mock_dataset_text, + mock_model_service_get, + mock_model, + sync, + ): + """ + Initiate aiplatform with encryption key name. + Create and run an AutoML Video Classification training job, verify calls and return value + """ + + aiplatform.init( + project=_TEST_PROJECT, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) + + job = training_jobs.AutoMLTextTrainingJob( + display_name=_TEST_DISPLAY_NAME, + prediction_type=_TEST_PREDICTION_TYPE_CLASSIFICATION, + multi_label=_TEST_CLASSIFICATION_MULTILABEL, + ) + + model_from_job = job.run( + dataset=mock_dataset_text, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + sync=sync, + create_request_timeout=None, + ) + + if not sync: + model_from_job.wait() + + true_managed_model = gca_model.Model( + display_name=_TEST_MODEL_DISPLAY_NAME, + description=mock_model._gca_resource.description, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + true_input_data_config = gca_training_pipeline.InputDataConfig( + dataset_id=mock_dataset_text.name, + ) + + true_training_pipeline = gca_training_pipeline.TrainingPipeline( + display_name=_TEST_DISPLAY_NAME, + training_task_definition=schema.training_job.definition.automl_text_classification, + training_task_inputs=_TEST_TRAINING_TASK_INPUTS_CLASSIFICATION, + model_to_upload=true_managed_model, + input_data_config=true_input_data_config, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + training_pipeline=true_training_pipeline, + timeout=None, + ) diff --git a/tests/unit/aiplatform/test_automl_video_training_jobs.py b/tests/unit/aiplatform/test_automl_video_training_jobs.py index 66f1692fcf..94ed81e5b1 100644 --- a/tests/unit/aiplatform/test_automl_video_training_jobs.py +++ b/tests/unit/aiplatform/test_automl_video_training_jobs.py @@ -1,3 +1,20 @@ +# -*- coding: utf-8 -*- + +# Copyright 2022 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. +# + import pytest import importlib from unittest import mock @@ -6,20 +23,18 @@ from google.protobuf import struct_pb2 from google.cloud import aiplatform - +from google.cloud.aiplatform import base from google.cloud.aiplatform import datasets from google.cloud.aiplatform import initializer from google.cloud.aiplatform import models from google.cloud.aiplatform import schema from google.cloud.aiplatform import training_jobs -from google.cloud.aiplatform_v1.services.model_service import ( - client as model_service_client, -) -from google.cloud.aiplatform_v1.services.pipeline_service import ( - client as pipeline_service_client, +from google.cloud.aiplatform.compat.services import ( + model_service_client, + pipeline_service_client, ) -from google.cloud.aiplatform_v1.types import ( +from google.cloud.aiplatform.compat.types import ( dataset as gca_dataset, encryption_spec as gca_encryption_spec, model as gca_model, @@ -43,21 +58,32 @@ _TEST_DATASET_NAME = "test-dataset-name" _TEST_MODEL_DISPLAY_NAME = "model-display-name" + +_TEST_LABELS = {"key": "value"} +_TEST_MODEL_LABELS = {"model_key": "model_value"} + _TEST_MODEL_ID = "98777645321" # TODO _TEST_TRAINING_TASK_INPUTS = json_format.ParseDict( - {"modelType": "CLOUD"}, struct_pb2.Value(), + {"modelType": "CLOUD"}, + struct_pb2.Value(), ) _TEST_FRACTION_SPLIT_TRAINING = 0.8 +_TEST_FRACTION_SPLIT_VALIDATION = 0.0 _TEST_FRACTION_SPLIT_TEST = 0.2 +_TEST_ALTERNATE_FRACTION_SPLIT_TRAINING = 0.7 +_TEST_ALTERNATE_FRACTION_SPLIT_TEST = 0.3 +_TEST_FILTER_SPLIT_TRAINING = "train" +_TEST_FILTER_SPLIT_VALIDATION = "-" +_TEST_FILTER_SPLIT_TEST = "test" _TEST_MODEL_NAME = ( f"projects/{_TEST_PROJECT}/locations/{_TEST_LOCATION}/models/{_TEST_MODEL_ID}" ) _TEST_PIPELINE_RESOURCE_NAME = ( - f"projects/{_TEST_PROJECT}/locations/{_TEST_LOCATION}/trainingPipeline/12345" + f"projects/{_TEST_PROJECT}/locations/{_TEST_LOCATION}/trainingPipelines/12345" ) # CMEK encryption @@ -82,10 +108,12 @@ def mock_pipeline_service_create(): with mock.patch.object( pipeline_service_client.PipelineServiceClient, "create_training_pipeline" ) as mock_create_training_pipeline: - mock_create_training_pipeline.return_value = gca_training_pipeline.TrainingPipeline( - name=_TEST_PIPELINE_RESOURCE_NAME, - state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, - model_to_upload=gca_model.Model(name=_TEST_MODEL_NAME), + mock_create_training_pipeline.return_value = ( + gca_training_pipeline.TrainingPipeline( + name=_TEST_PIPELINE_RESOURCE_NAME, + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, + model_to_upload=gca_model.Model(name=_TEST_MODEL_NAME), + ) ) yield mock_create_training_pipeline @@ -95,10 +123,12 @@ def mock_pipeline_service_get(): with mock.patch.object( pipeline_service_client.PipelineServiceClient, "get_training_pipeline" ) as mock_get_training_pipeline: - mock_get_training_pipeline.return_value = gca_training_pipeline.TrainingPipeline( - name=_TEST_PIPELINE_RESOURCE_NAME, - state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, - model_to_upload=gca_model.Model(name=_TEST_MODEL_NAME), + mock_get_training_pipeline.return_value = ( + gca_training_pipeline.TrainingPipeline( + name=_TEST_PIPELINE_RESOURCE_NAME, + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, + model_to_upload=gca_model.Model(name=_TEST_MODEL_NAME), + ) ) yield mock_get_training_pipeline @@ -108,17 +138,21 @@ def mock_pipeline_service_create_and_get_with_fail(): with mock.patch.object( pipeline_service_client.PipelineServiceClient, "create_training_pipeline" ) as mock_create_training_pipeline: - mock_create_training_pipeline.return_value = gca_training_pipeline.TrainingPipeline( - name=_TEST_PIPELINE_RESOURCE_NAME, - state=gca_pipeline_state.PipelineState.PIPELINE_STATE_RUNNING, + mock_create_training_pipeline.return_value = ( + gca_training_pipeline.TrainingPipeline( + name=_TEST_PIPELINE_RESOURCE_NAME, + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_RUNNING, + ) ) with mock.patch.object( pipeline_service_client.PipelineServiceClient, "get_training_pipeline" ) as mock_get_training_pipeline: - mock_get_training_pipeline.return_value = gca_training_pipeline.TrainingPipeline( - name=_TEST_PIPELINE_RESOURCE_NAME, - state=gca_pipeline_state.PipelineState.PIPELINE_STATE_FAILED, + mock_get_training_pipeline.return_value = ( + gca_training_pipeline.TrainingPipeline( + name=_TEST_PIPELINE_RESOURCE_NAME, + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_FAILED, + ) ) yield mock_create_training_pipeline, mock_get_training_pipeline @@ -137,6 +171,7 @@ def mock_model_service_get(): def mock_dataset_video(): ds = mock.MagicMock(datasets.VideoDataset) ds.name = _TEST_DATASET_NAME + ds.metadata_schema_uri = _TEST_METADATA_SCHEMA_URI_VIDEO ds._latest_future = None ds._exception = None ds._gca_resource = gca_dataset.Dataset( @@ -156,11 +191,13 @@ def mock_model(): model._latest_future = None model._exception = None model._gca_resource = gca_model.Model( - display_name=_TEST_MODEL_DISPLAY_NAME, name=_TEST_MODEL_NAME, + display_name=_TEST_MODEL_DISPLAY_NAME, + name=_TEST_MODEL_NAME, ) yield model +@pytest.mark.usefixtures("google_auth_mock") class TestAutoMLVideoTrainingJob: def setup_method(self): importlib.reload(initializer) @@ -170,7 +207,7 @@ def teardown_method(self): initializer.global_pool.shutdown(wait=True) def test_init_all_parameters(self): - """Ensure all private members are set correctly at initalization""" + """Ensure all private members are set correctly at initialization""" aiplatform.init(project=_TEST_PROJECT) @@ -191,7 +228,8 @@ def test_init_wrong_parameters(self): with pytest.raises(ValueError, match=r"not a supported prediction type"): training_jobs.AutoMLVideoTrainingJob( - display_name=_TEST_DISPLAY_NAME, prediction_type="abcdefg", + display_name=_TEST_DISPLAY_NAME, + prediction_type="abcdefg", ) with pytest.raises(ValueError, match=r"not a supported model_type for"): @@ -201,6 +239,8 @@ def test_init_wrong_parameters(self): model_type="abcdefg", ) + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) def test_init_aiplatform_with_encryption_key_name_and_create_training_job( self, @@ -227,12 +267,85 @@ def test_init_aiplatform_with_encryption_key_name_and_create_training_job( model_type=_TEST_MODEL_TYPE_CLOUD, ) + model_from_job = job.run( + dataset=mock_dataset_video, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + sync=sync, + create_request_timeout=None, + ) + + if not sync: + model_from_job.wait() + + true_managed_model = gca_model.Model( + display_name=_TEST_MODEL_DISPLAY_NAME, + description=mock_model._gca_resource.description, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + true_input_data_config = gca_training_pipeline.InputDataConfig( + dataset_id=mock_dataset_video.name, + ) + + true_training_pipeline = gca_training_pipeline.TrainingPipeline( + display_name=_TEST_DISPLAY_NAME, + training_task_definition=schema.training_job.definition.automl_video_classification, + training_task_inputs=_TEST_TRAINING_TASK_INPUTS, + model_to_upload=true_managed_model, + input_data_config=true_input_data_config, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + training_pipeline=true_training_pipeline, + timeout=None, + ) + + mock_model_service_get.assert_called_once_with( + name=_TEST_MODEL_NAME, retry=base._DEFAULT_RETRY + ) + assert job._gca_resource is mock_pipeline_service_get.return_value + assert model_from_job._gca_resource is mock_model_service_get.return_value + assert job.get_model()._gca_resource is mock_model_service_get.return_value + assert not job.has_failed + assert job.state == gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + def test_splits_fraction( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + mock_dataset_video, + mock_model_service_get, + mock_model, + sync, + ): + """ + Initiate aiplatform with encryption key name. + Create and run an AutoML Video Classification training job, verify calls and return value + """ + + aiplatform.init( + project=_TEST_PROJECT, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) + + job = training_jobs.AutoMLVideoTrainingJob( + display_name=_TEST_DISPLAY_NAME, + prediction_type=_TEST_PREDICTION_TYPE_VCN, + model_type=_TEST_MODEL_TYPE_CLOUD, + ) + model_from_job = job.run( dataset=mock_dataset_video, model_display_name=_TEST_MODEL_DISPLAY_NAME, training_fraction_split=_TEST_FRACTION_SPLIT_TRAINING, test_fraction_split=_TEST_FRACTION_SPLIT_TEST, sync=sync, + create_request_timeout=None, ) if not sync: @@ -240,6 +353,7 @@ def test_init_aiplatform_with_encryption_key_name_and_create_training_job( true_fraction_split = gca_training_pipeline.FractionSplit( training_fraction=_TEST_FRACTION_SPLIT_TRAINING, + validation_fraction=_TEST_FRACTION_SPLIT_VALIDATION, test_fraction=_TEST_FRACTION_SPLIT_TEST, ) @@ -250,7 +364,8 @@ def test_init_aiplatform_with_encryption_key_name_and_create_training_job( ) true_input_data_config = gca_training_pipeline.InputDataConfig( - fraction_split=true_fraction_split, dataset_id=mock_dataset_video.name, + fraction_split=true_fraction_split, + dataset_id=mock_dataset_video.name, ) true_training_pipeline = gca_training_pipeline.TrainingPipeline( @@ -265,15 +380,146 @@ def test_init_aiplatform_with_encryption_key_name_and_create_training_job( mock_pipeline_service_create.assert_called_once_with( parent=initializer.global_config.common_location_path(), training_pipeline=true_training_pipeline, + timeout=None, ) - mock_model_service_get.assert_called_once_with(name=_TEST_MODEL_NAME) - assert job._gca_resource is mock_pipeline_service_get.return_value - assert model_from_job._gca_resource is mock_model_service_get.return_value - assert job.get_model()._gca_resource is mock_model_service_get.return_value - assert not job.has_failed - assert job.state == gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + def test_splits_filter( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + mock_dataset_video, + mock_model_service_get, + mock_model, + sync, + ): + """ + Initiate aiplatform with encryption key name. + Create and run an AutoML Video Classification training job, verify calls and return value + """ + aiplatform.init( + project=_TEST_PROJECT, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) + + job = training_jobs.AutoMLVideoTrainingJob( + display_name=_TEST_DISPLAY_NAME, + prediction_type=_TEST_PREDICTION_TYPE_VCN, + model_type=_TEST_MODEL_TYPE_CLOUD, + ) + + model_from_job = job.run( + dataset=mock_dataset_video, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + training_filter_split=_TEST_FILTER_SPLIT_TRAINING, + test_filter_split=_TEST_FILTER_SPLIT_TEST, + sync=sync, + create_request_timeout=None, + ) + + if not sync: + model_from_job.wait() + + true_filter_split = gca_training_pipeline.FilterSplit( + training_filter=_TEST_FILTER_SPLIT_TRAINING, + validation_filter=_TEST_FILTER_SPLIT_VALIDATION, + test_filter=_TEST_FILTER_SPLIT_TEST, + ) + + true_managed_model = gca_model.Model( + display_name=_TEST_MODEL_DISPLAY_NAME, + description=mock_model._gca_resource.description, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + true_input_data_config = gca_training_pipeline.InputDataConfig( + filter_split=true_filter_split, + dataset_id=mock_dataset_video.name, + ) + + true_training_pipeline = gca_training_pipeline.TrainingPipeline( + display_name=_TEST_DISPLAY_NAME, + training_task_definition=schema.training_job.definition.automl_video_classification, + training_task_inputs=_TEST_TRAINING_TASK_INPUTS, + model_to_upload=true_managed_model, + input_data_config=true_input_data_config, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + training_pipeline=true_training_pipeline, + timeout=None, + ) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + def test_splits_default( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + mock_dataset_video, + mock_model_service_get, + mock_model, + sync, + ): + """ + Initiate aiplatform with encryption key name. + Create and run an AutoML Video Classification training job, verify calls and return value + """ + + aiplatform.init( + project=_TEST_PROJECT, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) + + job = training_jobs.AutoMLVideoTrainingJob( + display_name=_TEST_DISPLAY_NAME, + prediction_type=_TEST_PREDICTION_TYPE_VCN, + model_type=_TEST_MODEL_TYPE_CLOUD, + ) + + model_from_job = job.run( + dataset=mock_dataset_video, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + sync=sync, + create_request_timeout=None, + ) + + if not sync: + model_from_job.wait() + + true_managed_model = gca_model.Model( + display_name=_TEST_MODEL_DISPLAY_NAME, + description=mock_model._gca_resource.description, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + true_input_data_config = gca_training_pipeline.InputDataConfig( + dataset_id=mock_dataset_video.name, + ) + + true_training_pipeline = gca_training_pipeline.TrainingPipeline( + display_name=_TEST_DISPLAY_NAME, + training_task_definition=schema.training_job.definition.automl_video_classification, + training_task_inputs=_TEST_TRAINING_TASK_INPUTS, + model_to_upload=true_managed_model, + input_data_config=true_input_data_config, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + training_pipeline=true_training_pipeline, + timeout=None, + ) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) def test_run_call_pipeline_service_create( self, @@ -290,6 +536,7 @@ def test_run_call_pipeline_service_create( job = training_jobs.AutoMLVideoTrainingJob( display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, prediction_type=_TEST_PREDICTION_TYPE_VCN, model_type=_TEST_MODEL_TYPE_CLOUD, training_encryption_spec_key_name=_TEST_PIPELINE_ENCRYPTION_KEY_NAME, @@ -299,31 +546,37 @@ def test_run_call_pipeline_service_create( model_from_job = job.run( dataset=mock_dataset_video, model_display_name=_TEST_MODEL_DISPLAY_NAME, - training_fraction_split=_TEST_FRACTION_SPLIT_TRAINING, - test_fraction_split=_TEST_FRACTION_SPLIT_TEST, + model_labels=_TEST_MODEL_LABELS, + training_filter_split=_TEST_FILTER_SPLIT_TRAINING, + test_filter_split=_TEST_FILTER_SPLIT_TEST, sync=sync, + create_request_timeout=None, ) if not sync: model_from_job.wait() - true_fraction_split = gca_training_pipeline.FractionSplit( - training_fraction=_TEST_FRACTION_SPLIT_TRAINING, - test_fraction=_TEST_FRACTION_SPLIT_TEST, + true_filter_split = gca_training_pipeline.FilterSplit( + training_filter=_TEST_FILTER_SPLIT_TRAINING, + validation_filter=_TEST_FILTER_SPLIT_VALIDATION, + test_filter=_TEST_FILTER_SPLIT_TEST, ) true_managed_model = gca_model.Model( display_name=_TEST_MODEL_DISPLAY_NAME, + labels=_TEST_MODEL_LABELS, description=mock_model._gca_resource.description, encryption_spec=_TEST_MODEL_ENCRYPTION_SPEC, ) true_input_data_config = gca_training_pipeline.InputDataConfig( - fraction_split=true_fraction_split, dataset_id=mock_dataset_video.name, + filter_split=true_filter_split, + dataset_id=mock_dataset_video.name, ) true_training_pipeline = gca_training_pipeline.TrainingPipeline( display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, training_task_definition=schema.training_job.definition.automl_video_classification, training_task_inputs=_TEST_TRAINING_TASK_INPUTS, model_to_upload=true_managed_model, @@ -334,18 +587,95 @@ def test_run_call_pipeline_service_create( mock_pipeline_service_create.assert_called_once_with( parent=initializer.global_config.common_location_path(), training_pipeline=true_training_pipeline, + timeout=None, ) - mock_model_service_get.assert_called_once_with(name=_TEST_MODEL_NAME) + mock_model_service_get.assert_called_once_with( + name=_TEST_MODEL_NAME, retry=base._DEFAULT_RETRY + ) assert job._gca_resource is mock_pipeline_service_get.return_value assert model_from_job._gca_resource is mock_model_service_get.return_value assert job.get_model()._gca_resource is mock_model_service_get.return_value assert not job.has_failed assert job.state == gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + def test_run_call_pipeline_service_create_with_timeout( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + mock_dataset_video, + mock_model_service_get, + mock_model, + sync, + ): + """Create and run an AutoML ICN training job, verify calls and return value""" + + aiplatform.init(project=_TEST_PROJECT) + + job = training_jobs.AutoMLVideoTrainingJob( + display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, + prediction_type=_TEST_PREDICTION_TYPE_VCN, + model_type=_TEST_MODEL_TYPE_CLOUD, + training_encryption_spec_key_name=_TEST_PIPELINE_ENCRYPTION_KEY_NAME, + model_encryption_spec_key_name=_TEST_MODEL_ENCRYPTION_KEY_NAME, + ) + + model_from_job = job.run( + dataset=mock_dataset_video, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + model_labels=_TEST_MODEL_LABELS, + training_filter_split=_TEST_FILTER_SPLIT_TRAINING, + test_filter_split=_TEST_FILTER_SPLIT_TEST, + sync=sync, + create_request_timeout=180.0, + ) + + if not sync: + model_from_job.wait() + + true_filter_split = gca_training_pipeline.FilterSplit( + training_filter=_TEST_FILTER_SPLIT_TRAINING, + validation_filter=_TEST_FILTER_SPLIT_VALIDATION, + test_filter=_TEST_FILTER_SPLIT_TEST, + ) + + true_managed_model = gca_model.Model( + display_name=_TEST_MODEL_DISPLAY_NAME, + labels=_TEST_MODEL_LABELS, + description=mock_model._gca_resource.description, + encryption_spec=_TEST_MODEL_ENCRYPTION_SPEC, + ) + + true_input_data_config = gca_training_pipeline.InputDataConfig( + filter_split=true_filter_split, + dataset_id=mock_dataset_video.name, + ) + + true_training_pipeline = gca_training_pipeline.TrainingPipeline( + display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, + training_task_definition=schema.training_job.definition.automl_video_classification, + training_task_inputs=_TEST_TRAINING_TASK_INPUTS, + model_to_upload=true_managed_model, + input_data_config=true_input_data_config, + encryption_spec=_TEST_PIPELINE_ENCRYPTION_SPEC, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + training_pipeline=true_training_pipeline, + timeout=180.0, + ) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.usefixtures("mock_pipeline_service_get") @pytest.mark.parametrize("sync", [True, False]) - def test_run_call_pipeline_if_no_model_display_name( + def test_run_call_pipeline_if_no_model_display_name_nor_model_labels( self, mock_pipeline_service_create, mock_dataset_video, @@ -356,33 +686,41 @@ def test_run_call_pipeline_if_no_model_display_name( job = training_jobs.AutoMLVideoTrainingJob( display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, prediction_type=_TEST_PREDICTION_TYPE_VCN, model_type=_TEST_MODEL_TYPE_CLOUD, ) model_from_job = job.run( dataset=mock_dataset_video, - training_fraction_split=_TEST_FRACTION_SPLIT_TRAINING, - test_fraction_split=_TEST_FRACTION_SPLIT_TEST, + training_fraction_split=_TEST_ALTERNATE_FRACTION_SPLIT_TRAINING, + test_fraction_split=_TEST_ALTERNATE_FRACTION_SPLIT_TEST, + create_request_timeout=None, ) if not sync: model_from_job.wait() true_fraction_split = gca_training_pipeline.FractionSplit( - training_fraction=_TEST_FRACTION_SPLIT_TRAINING, - test_fraction=_TEST_FRACTION_SPLIT_TEST, + training_fraction=_TEST_ALTERNATE_FRACTION_SPLIT_TRAINING, + validation_fraction=_TEST_FRACTION_SPLIT_VALIDATION, + test_fraction=_TEST_ALTERNATE_FRACTION_SPLIT_TEST, ) # Test that if defaults to the job display name - true_managed_model = gca_model.Model(display_name=_TEST_DISPLAY_NAME) + true_managed_model = gca_model.Model( + display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, + ) true_input_data_config = gca_training_pipeline.InputDataConfig( - fraction_split=true_fraction_split, dataset_id=mock_dataset_video.name, + fraction_split=true_fraction_split, + dataset_id=mock_dataset_video.name, ) true_training_pipeline = gca_training_pipeline.TrainingPipeline( display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, training_task_definition=schema.training_job.definition.automl_video_classification, training_task_inputs=_TEST_TRAINING_TASK_INPUTS, model_to_upload=true_managed_model, @@ -392,8 +730,11 @@ def test_run_call_pipeline_if_no_model_display_name( mock_pipeline_service_create.assert_called_once_with( parent=initializer.global_config.common_location_path(), training_pipeline=true_training_pipeline, + timeout=None, ) + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.usefixtures( "mock_pipeline_service_create", "mock_pipeline_service_get", @@ -401,29 +742,63 @@ def test_run_call_pipeline_if_no_model_display_name( ) @pytest.mark.parametrize("sync", [True, False]) def test_run_called_twice_raises( - self, mock_dataset_video, sync, + self, + mock_dataset_video, + sync, ): aiplatform.init(project=_TEST_PROJECT) - job = training_jobs.AutoMLVideoTrainingJob(display_name=_TEST_DISPLAY_NAME,) + job = training_jobs.AutoMLVideoTrainingJob( + display_name=_TEST_DISPLAY_NAME, + ) job.run( dataset=mock_dataset_video, model_display_name=_TEST_MODEL_DISPLAY_NAME, - training_fraction_split=_TEST_FRACTION_SPLIT_TRAINING, - test_fraction_split=_TEST_FRACTION_SPLIT_TEST, sync=sync, ) with pytest.raises(RuntimeError): job.run( + dataset=mock_dataset_video, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + sync=sync, + ) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.usefixtures( + "mock_pipeline_service_create", + "mock_pipeline_service_get", + "mock_model_service_get", + ) + @pytest.mark.parametrize("sync", [True, False]) + def test_run_with_two_split_raises( + self, + mock_dataset_video, + sync, + ): + aiplatform.init(project=_TEST_PROJECT) + + job = training_jobs.AutoMLVideoTrainingJob( + display_name=_TEST_DISPLAY_NAME, + ) + + with pytest.raises(ValueError): + model_from_job = job.run( dataset=mock_dataset_video, model_display_name=_TEST_MODEL_DISPLAY_NAME, training_fraction_split=_TEST_FRACTION_SPLIT_TRAINING, test_fraction_split=_TEST_FRACTION_SPLIT_TEST, + training_filter_split=_TEST_FILTER_SPLIT_TEST, + test_filter_split=_TEST_FILTER_SPLIT_TEST, sync=sync, ) + if not sync: + model_from_job.wait() + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) def test_run_raises_if_pipeline_fails( self, mock_pipeline_service_create_and_get_with_fail, mock_dataset_video, sync @@ -431,7 +806,9 @@ def test_run_raises_if_pipeline_fails( aiplatform.init(project=_TEST_PROJECT) - job = training_jobs.AutoMLVideoTrainingJob(display_name=_TEST_DISPLAY_NAME,) + job = training_jobs.AutoMLVideoTrainingJob( + display_name=_TEST_DISPLAY_NAME, + ) with pytest.raises(RuntimeError): job.run( @@ -451,7 +828,9 @@ def test_run_raises_if_pipeline_fails( def test_raises_before_run_is_called(self, mock_pipeline_service_create): aiplatform.init(project=_TEST_PROJECT) - job = training_jobs.AutoMLVideoTrainingJob(display_name=_TEST_DISPLAY_NAME,) + job = training_jobs.AutoMLVideoTrainingJob( + display_name=_TEST_DISPLAY_NAME, + ) with pytest.raises(RuntimeError): job.get_model() diff --git a/tests/unit/aiplatform/test_cloud_profiler.py b/tests/unit/aiplatform/test_cloud_profiler.py new file mode 100644 index 0000000000..388405d034 --- /dev/null +++ b/tests/unit/aiplatform/test_cloud_profiler.py @@ -0,0 +1,448 @@ +# -*- coding: utf-8 -*- + +# 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 +# +# 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. +# + +import importlib.util +import json +import sys +import threading +from typing import List, Optional + +import pytest +import unittest + +from unittest import mock +from werkzeug import wrappers +from werkzeug.test import EnvironBuilder + +from google.api_core import exceptions +from google.cloud import aiplatform +from google.cloud.aiplatform import training_utils +from google.cloud.aiplatform.tensorboard.plugins.tf_profiler import profile_uploader +from google.cloud.aiplatform.training_utils.cloud_profiler.plugins import base_plugin +from google.cloud.aiplatform.training_utils.cloud_profiler.plugins.tensorflow import ( + tf_profiler, +) +from google.cloud.aiplatform.training_utils.cloud_profiler.plugins.tensorflow.tf_profiler import ( + TFProfiler, +) +from google.cloud.aiplatform.training_utils.cloud_profiler.plugins.tensorflow import ( + tensorboard_api, +) +from google.cloud.aiplatform.training_utils.cloud_profiler import webserver +from google.cloud.aiplatform.training_utils.cloud_profiler import initializer + + +# Mock cluster specs from the training environment. +_CLUSTER_SPEC_VM = { + "cluster": {"chief": ["localhost:1234"]}, + "environment": "cloud", + "task": {"type": "chief", "index": 0}, +} + + +def _create_mock_plugin( + plugin_name: str = "test_plugin", routes: Optional[List] = ["/route1"] +): + mock_plugin = mock.Mock(spec=base_plugin.BasePlugin) + mock_plugin.can_initialize.return_value = True + mock_plugin.post_setup_check.return_value = True + mock_plugin.PLUGIN_NAME = plugin_name + + # Some mock routes to test number of times each has been called. + mock_routes = {} + for route in routes: + mock_routes[route] = mock.Mock() + + mock_plugin.get_routes.return_value = mock_routes + + # A call should just return the mock object itself. + mock_plugin.return_value = mock_plugin + + return mock_plugin + + +def _find_child_modules(root_module): + return [module for module in sys.modules.keys() if module.startswith(root_module)] + + +@pytest.fixture +def tf_profile_plugin_mock(): + """Mock the tensorboard profile plugin""" + import tensorboard_plugin_profile.profile_plugin + + with mock.patch.object( + tensorboard_plugin_profile.profile_plugin.ProfilePlugin, "capture_route" + ) as profile_mock: + profile_mock.return_value = ( + wrappers.BaseResponse( + json.dumps({"error": "some error"}), + content_type="application/json", + status=200, + ), + ) + yield profile_mock + + +@pytest.fixture +def tensorboard_api_mock(): + with mock.patch.object( + tensorboard_api, + "create_profile_request_sender", + ) as sender_mock: + sender_mock.return_value = mock.Mock() + yield sender_mock + + +@pytest.fixture +def mock_api_environment_variables(): + with mock.patch.object(training_utils, "environment_variables") as mock_env: + mock_env.tensorboard_api_uri = "testuri" + mock_env.tensorboard_resource_name = ( + "projects/testproj/locations/us-central1/tensorboards/123" + ) + mock_env.cloud_ml_job_id = "test_job_id" + mock_env.tensorboard_log_dir = "gs://my_log_dir" + + yield mock_env + + +def setupProfilerEnvVars(): + tf_profiler.environment_variables.tf_profiler_port = "6009" + tf_profiler.environment_variables.tensorboard_log_dir = "tmp/" + tf_profiler.environment_variables.tensorboard_api_uri = "test_api_uri" + tf_profiler.environment_variables.tensorboard_resource_name = ( + "projects/123/region/us-central1/tensorboards/mytb" + ) + tf_profiler.environment_variables.cluster_spec = _CLUSTER_SPEC_VM + tf_profiler.environment_variables.cloud_ml_job_id = "myjob" + + +class TestProfilerPlugin(unittest.TestCase): + def setUp(self): + setupProfilerEnvVars() + + # Environment variable tests + def testCanInitializeProfilerPortUnset(self): + tf_profiler.environment_variables.tf_profiler_port = None + assert not TFProfiler.can_initialize() + + def testCanInitializeTBLogDirUnset(self): + tf_profiler.environment_variables.tensorboard_log_dir = None + assert not TFProfiler.can_initialize() + + def testCanInitializeTBAPIuriUnset(self): + tf_profiler.environment_variables.tensorboard_api_uri = None + assert not TFProfiler.can_initialize() + + def testCanInitializeTBResourceNameUnset(self): + tf_profiler.environment_variables.tensorboard_resource_name = None + assert not TFProfiler.can_initialize() + + def testCanInitializeJobIdUnset(self): + tf_profiler.environment_variables.cloud_ml_job_id = None + assert not TFProfiler.can_initialize() + + def testCanInitializeNoClusterSpec(self): + tf_profiler.environment_variables.cluster_spec = None + assert not TFProfiler.can_initialize() + + # Check tensorflow dependencies + def testCanInitializeTFInstalled(self): + orig_find_spec = importlib.util.find_spec + + def tf_import_mock(name, *args, **kwargs): + if name == "tensorflow": + return None + return orig_find_spec(name, *args, **kwargs) + + with mock.patch("importlib.util.find_spec", side_effect=tf_import_mock): + assert not TFProfiler.can_initialize() + + def testCanInitializeTFVersion(self): + import tensorflow + + with mock.patch.object(tensorflow, "__version__", return_value="1.2.3.4"): + assert not TFProfiler.can_initialize() + + def testCanInitializeOldTFVersion(self): + import tensorflow + + with mock.patch.object(tensorflow, "__version__", return_value="2.3.0"): + assert not TFProfiler.can_initialize() + + def testCanInitializeNoProfilePlugin(self): + orig_find_spec = importlib.util.find_spec + + def plugin_import_mock(name, *args, **kwargs): + if name == "tensorboard_plugin_profile": + return None + return orig_find_spec(name, *args, **kwargs) + + with mock.patch("importlib.util.find_spec", side_effect=plugin_import_mock): + assert not TFProfiler.can_initialize() + + def testCanInitialize(self): + assert TFProfiler.can_initialize() + + def testSetup(self): + import tensorflow + + with mock.patch.object( + tensorflow.profiler.experimental.server, "start", return_value=None + ) as server_mock: + TFProfiler.setup() + + assert server_mock.call_count == 1 + + def testPostSetupChecksFail(self): + tf_profiler.environment_variables.cluster_spec = {} + assert not TFProfiler.post_setup_check() + + def testPostSetupChecks(self): + assert TFProfiler.post_setup_check() + + # Tests for plugin + @pytest.mark.usefixtures("tf_profile_plugin_mock") + @pytest.mark.usefixtures("tensorboard_api_mock") + def testCaptureProfile(self): + profiler = TFProfiler() + environ = dict(QUERY_STRING="?service_addr=myhost1,myhost2&someotherdata=5") + start_response = None + + resp = profiler.capture_profile_wrapper(environ, start_response) + assert resp[0].status_code == 200 + + @pytest.mark.usefixtures("tf_profile_plugin_mock") + @pytest.mark.usefixtures("tensorboard_api_mock") + def testCaptureProfileNoClusterSpec(self): + profiler = TFProfiler() + + environ = dict(QUERY_STRING="?service_addr=myhost1,myhost2&someotherdata=5") + start_response = None + + tf_profiler.environment_variables.cluster_spec = None + resp = profiler.capture_profile_wrapper(environ, start_response) + + assert resp.status_code == 500 + + @pytest.mark.usefixtures("tf_profile_plugin_mock") + @pytest.mark.usefixtures("tensorboard_api_mock") + def testCaptureProfileNoCluster(self): + profiler = TFProfiler() + + environ = dict(QUERY_STRING="?service_addr=myhost1,myhost2&someotherdata=5") + start_response = None + tf_profiler.environment_variables.cluster_spec = {"cluster": {}} + + resp = profiler.capture_profile_wrapper(environ, start_response) + + assert resp.status_code == 500 + + @pytest.mark.usefixtures("tf_profile_plugin_mock") + @pytest.mark.usefixtures("tensorboard_api_mock") + def testGetRoutes(self): + profiler = TFProfiler() + + routes = profiler.get_routes() + assert isinstance(routes, dict) + + +# Tensorboard API tests +class TestTensorboardAPIBuilder(unittest.TestCase): + @pytest.mark.usefixtures("mock_api_environment_variables") + def test_get_api_client(self): + with mock.patch.object(aiplatform, "initializer") as mock_initializer: + tensorboard_api._get_api_client() + mock_initializer.global_config.create_client.assert_called_once() + + def test_get_project_id_fail(self): + with mock.patch.object(training_utils, "environment_variables") as mock_env: + mock_env.tensorboard_resource_name = "bad_resource" + self.assertRaises(ValueError, tensorboard_api._get_project_id) + + @pytest.mark.usefixtures("mock_api_environment_variables") + def test_get_project_id(self): + project_id = tensorboard_api._get_project_id() + assert project_id == "testproj" + + @pytest.mark.usefixtures("mock_api_environment_variables") + def test_get_or_create_experiment(self): + api = mock.Mock() + api.create_tensorboard_experiment.side_effect = exceptions.AlreadyExists("test") + tensorboard_api._get_or_create_experiment(api, "test") + api.get_tensorboard_experiment.assert_called_once() + + @pytest.mark.usefixtures("mock_api_environment_variables") + def test_create_profile_request_sender(self): + tensorboard_api.storage = mock.Mock() + tensorboard_api.uploader_utils = mock.Mock() + + with mock.patch.object(profile_uploader, "ProfileRequestSender") as mock_sender: + with mock.patch.object(aiplatform, "initializer"): + tensorboard_api.create_profile_request_sender() + mock_sender.assert_called_once() + + +# Webserver tests +class TestWebServer(unittest.TestCase): + def test_create_webserver_bad_route(self): + plugin = _create_mock_plugin() + plugin.get_routes.return_value = {"my_route": "some_handler"} + + self.assertRaises(ValueError, webserver.WebServer, [plugin]) + + def test_dispatch_bad_request(self): + plugin = _create_mock_plugin() + plugin.get_routes.return_value = {"/test_route": "test_handler"} + + ws = webserver.WebServer([plugin]) + + builder = EnvironBuilder(method="GET", path="/") + + env = builder.get_environ() + + # Mock a start response callable + response = [] + buff = [] + + def start_response(status, headers): + response[:] = [status, headers] + return buff.append + + ws(env, start_response) + + assert response[0] == "404 NOT FOUND" + + def test_correct_response(self): + res_dict = {"response": "OK"} + + def my_callable(var1, var2): + return wrappers.BaseResponse( + json.dumps(res_dict), content_type="application/json", status=200 + ) + + plugin = _create_mock_plugin() + plugin.get_routes.return_value = {"/my_route": my_callable} + ws = webserver.WebServer([plugin]) + + builder = EnvironBuilder(method="GET", path="/test_plugin/my_route") + + env = builder.get_environ() + + # Mock a start response callable + response = [] + buff = [] + + def start_response(status, headers): + response[:] = [status, headers] + return buff.append + + res = ws(env, start_response) + + final_response = json.loads(res.response[0].decode("utf-8")) + + assert final_response == res_dict + + +# Initializer tests +class TestInitializer(unittest.TestCase): + def testImportError(self): + # Unloads any of the cloud profiler sub-modules + for mod in _find_child_modules( + "google.cloud.aiplatform.training_utils.cloud_profiler" + ): + del sys.modules[mod] + + # Modules to be mocked out + for mock_module in [ + "tensorflow", + "tensorboard_plugin_profile.profile_plugin", + "werkzeug", + ]: + with self.subTest(): + with mock.patch.dict("sys.modules", {mock_module: None}): + with self.assertRaises(ImportError) as cm: + importlib.import_module( + "google.cloud.aiplatform.training_utils.cloud_profiler" + ) + assert "Could not load the cloud profiler" in cm.exception.msg + + def test_build_plugin_fail_initialize(self): + plugin = _create_mock_plugin() + plugin.can_initialize.return_value = False + + assert not initializer._build_plugin(plugin) + + def test_build_plugin_fail_setup_check(self): + plugin = _create_mock_plugin() + plugin.can_initialize.return_value = True + plugin.post_setup_check.return_value = False + + assert not initializer._build_plugin(plugin) + + def test_build_plugin_success(self): + plugin = _create_mock_plugin() + plugin.can_initialize.return_value = True + plugin.post_setup_check.return_value = True + + initializer._build_plugin(plugin) + + assert plugin.called + + # Testing the initialize function + def test_initialize_bad_plugin(self): + with mock.patch.object(initializer, "_AVAILABLE_PLUGINS", {}): + self.assertRaises(ValueError, initializer.initialize, "bad_plugin") + + def test_initialize_build_plugin_fail(self): + plugin = _create_mock_plugin() + with mock.patch.object(initializer, "_AVAILABLE_PLUGINS", {"test": plugin}): + with mock.patch.object(initializer, "_build_plugin") as build_mock: + with mock.patch.object( + initializer, "_run_app_thread" + ) as app_thread_mock: + build_mock.return_value = None + initializer.initialize("test") + + assert not app_thread_mock.call_count + + def test_initialize_no_http_handler(self): + plugin = _create_mock_plugin() + initializer.environment_variables.http_handler_port = None + + with mock.patch.object(initializer, "_AVAILABLE_PLUGINS", {"test": plugin}): + with pytest.raises(initializer.MissingEnvironmentVariableException): + initializer.initialize("test") + + def test_initialize_build_plugin_success(self): + plugin = _create_mock_plugin() + initializer.environment_variables.http_handler_port = "1234" + + with mock.patch.object(initializer, "_AVAILABLE_PLUGINS", {"test": plugin}): + with mock.patch.object(initializer, "_run_app_thread") as app_thread_mock: + initializer.initialize("test") + + assert app_thread_mock.call_count == 1 + + def test_run_app_thread(self): + with mock.patch.object(threading, "Thread") as mock_thread: + daemon_mock = mock.Mock() + mock_thread.return_value = daemon_mock + + initializer._run_app_thread(None, 1234) + + assert daemon_mock.start.call_count == 1 diff --git a/tests/unit/aiplatform/test_custom_job.py b/tests/unit/aiplatform/test_custom_job.py index 7797e0edef..c09df26ad2 100644 --- a/tests/unit/aiplatform/test_custom_job.py +++ b/tests/unit/aiplatform/test_custom_job.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2021 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,6 +15,7 @@ # import pytest +import logging import copy from importlib import reload @@ -28,19 +29,14 @@ from test_training_jobs import mock_python_package_to_gcs # noqa: F401 from google.cloud import aiplatform +from google.cloud.aiplatform import base from google.cloud.aiplatform.compat.types import custom_job as gca_custom_job_compat -from google.cloud.aiplatform.compat.types import ( - custom_job_v1beta1 as gca_custom_job_v1beta1, -) from google.cloud.aiplatform.compat.types import io as gca_io_compat from google.cloud.aiplatform.compat.types import job_state as gca_job_state_compat from google.cloud.aiplatform.compat.types import ( encryption_spec as gca_encryption_spec_compat, ) -from google.cloud.aiplatform_v1.services.job_service import client as job_service_client -from google.cloud.aiplatform_v1beta1.services.job_service import ( - client as job_service_client_v1beta1, -) +from google.cloud.aiplatform.compat.services import job_service_client _TEST_PROJECT = "test-project" _TEST_LOCATION = "us-central1" @@ -51,9 +47,12 @@ _TEST_CUSTOM_JOB_NAME = f"{_TEST_PARENT}/customJobs/{_TEST_ID}" _TEST_TENSORBOARD_NAME = f"{_TEST_PARENT}/tensorboards/{_TEST_ID}" - +_TEST_ENABLE_WEB_ACCESS = True +_TEST_WEB_ACCESS_URIS = {"workerpool0-0": "uri"} _TEST_TRAINING_CONTAINER_IMAGE = "gcr.io/test-training/container:image" +_TEST_RUN_ARGS = ["-v", "0.1", "--test=arg"] + _TEST_WORKER_POOL_SPEC = [ { "machine_spec": { @@ -62,15 +61,17 @@ "accelerator_count": 1, }, "replica_count": 1, + "disk_spec": {"boot_disk_type": "pd-ssd", "boot_disk_size_gb": 100}, "container_spec": { "image_uri": _TEST_TRAINING_CONTAINER_IMAGE, "command": [], - "args": [], + "args": _TEST_RUN_ARGS, }, } ] _TEST_STAGING_BUCKET = "gs://test-staging-bucket" +_TEST_BASE_OUTPUT_DIR = f"{_TEST_STAGING_BUCKET}/{_TEST_DISPLAY_NAME}" # CMEK encryption _TEST_DEFAULT_ENCRYPTION_KEY_NAME = "key_default" @@ -86,12 +87,14 @@ _TEST_TIMEOUT = 8000 _TEST_RESTART_JOB_ON_WORKER_RESTART = True +_TEST_LABELS = {"my_key": "my_value"} + _TEST_BASE_CUSTOM_JOB_PROTO = gca_custom_job_compat.CustomJob( display_name=_TEST_DISPLAY_NAME, job_spec=gca_custom_job_compat.CustomJobSpec( worker_pool_specs=_TEST_WORKER_POOL_SPEC, base_output_directory=gca_io_compat.GcsDestination( - output_uri_prefix=_TEST_STAGING_BUCKET + output_uri_prefix=_TEST_BASE_OUTPUT_DIR ), scheduling=gca_custom_job_compat.Scheduling( timeout=duration_pb2.Duration(seconds=_TEST_TIMEOUT), @@ -100,24 +103,24 @@ service_account=_TEST_SERVICE_ACCOUNT, network=_TEST_NETWORK, ), + labels=_TEST_LABELS, encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, ) -def _get_custom_job_proto(state=None, name=None, error=None, version="v1"): +def _get_custom_job_proto(state=None, name=None, error=None): custom_job_proto = copy.deepcopy(_TEST_BASE_CUSTOM_JOB_PROTO) custom_job_proto.name = name custom_job_proto.state = state custom_job_proto.error = error + return custom_job_proto - if version == "v1beta1": - v1beta1_custom_job_proto = gca_custom_job_v1beta1.CustomJob() - v1beta1_custom_job_proto._pb.MergeFromString( - custom_job_proto._pb.SerializeToString() - ) - custom_job_proto = v1beta1_custom_job_proto - custom_job_proto.job_spec.tensorboard = _TEST_TENSORBOARD_NAME +def _get_custom_job_proto_with_enable_web_access(state=None, name=None, error=None): + custom_job_proto = _get_custom_job_proto(state=state, name=name, error=error) + custom_job_proto.job_spec.enable_web_access = _TEST_ENABLE_WEB_ACCESS + if state == gca_job_state_compat.JobState.JOB_STATE_RUNNING: + custom_job_proto.web_access_uris = _TEST_WEB_ACCESS_URIS return custom_job_proto @@ -162,10 +165,57 @@ def get_custom_job_mock_with_fail(): state=gca_job_state_compat.JobState.JOB_STATE_FAILED, error=status_pb2.Status(message="Test Error"), ), + _get_custom_job_proto( + name=_TEST_CUSTOM_JOB_NAME, + state=gca_job_state_compat.JobState.JOB_STATE_FAILED, + error=status_pb2.Status(message="Test Error"), + ), + ] + yield get_custom_job_mock + + +@pytest.fixture +def get_custom_job_mock_with_enable_web_access(): + with patch.object( + job_service_client.JobServiceClient, "get_custom_job" + ) as get_custom_job_mock: + get_custom_job_mock.side_effect = [ + _get_custom_job_proto_with_enable_web_access( + name=_TEST_CUSTOM_JOB_NAME, + state=gca_job_state_compat.JobState.JOB_STATE_PENDING, + ), + _get_custom_job_proto_with_enable_web_access( + name=_TEST_CUSTOM_JOB_NAME, + state=gca_job_state_compat.JobState.JOB_STATE_RUNNING, + ), + _get_custom_job_proto_with_enable_web_access( + name=_TEST_CUSTOM_JOB_NAME, + state=gca_job_state_compat.JobState.JOB_STATE_RUNNING, + ), + _get_custom_job_proto_with_enable_web_access( + name=_TEST_CUSTOM_JOB_NAME, + state=gca_job_state_compat.JobState.JOB_STATE_RUNNING, + ), + _get_custom_job_proto_with_enable_web_access( + name=_TEST_CUSTOM_JOB_NAME, + state=gca_job_state_compat.JobState.JOB_STATE_SUCCEEDED, + ), ] yield get_custom_job_mock +@pytest.fixture +def get_custom_job_mock_with_enable_web_access_succeeded(): + with mock.patch.object( + job_service_client.JobServiceClient, "get_custom_job" + ) as get_custom_job_mock: + get_custom_job_mock.return_value = _get_custom_job_proto_with_enable_web_access( + name=_TEST_CUSTOM_JOB_NAME, + state=gca_job_state_compat.JobState.JOB_STATE_SUCCEEDED, + ) + yield get_custom_job_mock + + @pytest.fixture def create_custom_job_mock(): with mock.patch.object( @@ -179,18 +229,43 @@ def create_custom_job_mock(): @pytest.fixture -def create_custom_job_v1beta1_mock(): +def create_custom_job_mock_with_enable_web_access(): with mock.patch.object( - job_service_client_v1beta1.JobServiceClient, "create_custom_job" + job_service_client.JobServiceClient, "create_custom_job" ) as create_custom_job_mock: - create_custom_job_mock.return_value = _get_custom_job_proto( + create_custom_job_mock.return_value = ( + _get_custom_job_proto_with_enable_web_access( + name=_TEST_CUSTOM_JOB_NAME, + state=gca_job_state_compat.JobState.JOB_STATE_PENDING, + ) + ) + yield create_custom_job_mock + + +@pytest.fixture +def create_custom_job_mock_with_tensorboard(): + with mock.patch.object( + job_service_client.JobServiceClient, "create_custom_job" + ) as create_custom_job_mock: + custom_job_proto = _get_custom_job_proto( name=_TEST_CUSTOM_JOB_NAME, state=gca_job_state_compat.JobState.JOB_STATE_PENDING, - version="v1beta1", ) + custom_job_proto.job_spec.tensorboard = _TEST_TENSORBOARD_NAME + create_custom_job_mock.return_value = custom_job_proto + yield create_custom_job_mock + + +@pytest.fixture +def create_custom_job_mock_fail(): + with mock.patch.object( + job_service_client.JobServiceClient, "create_custom_job" + ) as create_custom_job_mock: + create_custom_job_mock.side_effect = RuntimeError("Mock fail") yield create_custom_job_mock +@pytest.mark.usefixtures("google_auth_mock") class TestCustomJob: def setup_method(self): reload(aiplatform.initializer) @@ -210,7 +285,10 @@ def test_create_custom_job(self, create_custom_job_mock, get_custom_job_mock, sy ) job = aiplatform.CustomJob( - display_name=_TEST_DISPLAY_NAME, worker_pool_specs=_TEST_WORKER_POOL_SPEC + display_name=_TEST_DISPLAY_NAME, + worker_pool_specs=_TEST_WORKER_POOL_SPEC, + base_output_dir=_TEST_BASE_OUTPUT_DIR, + labels=_TEST_LABELS, ) job.run( @@ -219,20 +297,111 @@ def test_create_custom_job(self, create_custom_job_mock, get_custom_job_mock, sy timeout=_TEST_TIMEOUT, restart_job_on_worker_restart=_TEST_RESTART_JOB_ON_WORKER_RESTART, sync=sync, + create_request_timeout=None, ) + job.wait_for_resource_creation() + + assert job.resource_name == _TEST_CUSTOM_JOB_NAME + job.wait() expected_custom_job = _get_custom_job_proto() create_custom_job_mock.assert_called_once_with( - parent=_TEST_PARENT, custom_job=expected_custom_job + parent=_TEST_PARENT, + custom_job=expected_custom_job, + timeout=None, ) assert job.job_spec == expected_custom_job.job_spec assert ( job._gca_resource.state == gca_job_state_compat.JobState.JOB_STATE_SUCCEEDED ) + assert job.network == _TEST_NETWORK + + @pytest.mark.parametrize("sync", [True, False]) + def test_create_custom_job_with_timeout( + self, create_custom_job_mock, get_custom_job_mock, sync + ): + + aiplatform.init( + project=_TEST_PROJECT, + location=_TEST_LOCATION, + staging_bucket=_TEST_STAGING_BUCKET, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) + + job = aiplatform.CustomJob( + display_name=_TEST_DISPLAY_NAME, + worker_pool_specs=_TEST_WORKER_POOL_SPEC, + base_output_dir=_TEST_BASE_OUTPUT_DIR, + labels=_TEST_LABELS, + ) + + job.run( + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, + timeout=_TEST_TIMEOUT, + restart_job_on_worker_restart=_TEST_RESTART_JOB_ON_WORKER_RESTART, + sync=sync, + create_request_timeout=180.0, + ) + + job.wait_for_resource_creation() + + assert job.resource_name == _TEST_CUSTOM_JOB_NAME + + job.wait() + + expected_custom_job = _get_custom_job_proto() + + create_custom_job_mock.assert_called_once_with( + parent=_TEST_PARENT, + custom_job=expected_custom_job, + timeout=180.0, + ) + + @pytest.mark.parametrize("sync", [True, False]) + def test_create_custom_job_with_timeout_not_explicitly_set( + self, create_custom_job_mock, get_custom_job_mock, sync + ): + + aiplatform.init( + project=_TEST_PROJECT, + location=_TEST_LOCATION, + staging_bucket=_TEST_STAGING_BUCKET, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) + + job = aiplatform.CustomJob( + display_name=_TEST_DISPLAY_NAME, + worker_pool_specs=_TEST_WORKER_POOL_SPEC, + base_output_dir=_TEST_BASE_OUTPUT_DIR, + labels=_TEST_LABELS, + ) + + job.run( + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, + timeout=_TEST_TIMEOUT, + restart_job_on_worker_restart=_TEST_RESTART_JOB_ON_WORKER_RESTART, + sync=sync, + ) + + job.wait_for_resource_creation() + + assert job.resource_name == _TEST_CUSTOM_JOB_NAME + + job.wait() + + expected_custom_job = _get_custom_job_proto() + + create_custom_job_mock.assert_called_once_with( + parent=_TEST_PARENT, + custom_job=expected_custom_job, + timeout=None, + ) @pytest.mark.parametrize("sync", [True, False]) def test_run_custom_job_with_fail_raises( @@ -246,9 +415,16 @@ def test_run_custom_job_with_fail_raises( ) job = aiplatform.CustomJob( - display_name=_TEST_DISPLAY_NAME, worker_pool_specs=_TEST_WORKER_POOL_SPEC + display_name=_TEST_DISPLAY_NAME, + worker_pool_specs=_TEST_WORKER_POOL_SPEC, + base_output_dir=_TEST_BASE_OUTPUT_DIR, + labels=_TEST_LABELS, ) + with pytest.raises(RuntimeError) as e: + job.wait_for_resource_creation() + assert e.match(r"CustomJob resource is not scheduled to be created.") + with pytest.raises(RuntimeError): job.run( service_account=_TEST_SERVICE_ACCOUNT, @@ -256,18 +432,64 @@ def test_run_custom_job_with_fail_raises( timeout=_TEST_TIMEOUT, restart_job_on_worker_restart=_TEST_RESTART_JOB_ON_WORKER_RESTART, sync=sync, + create_request_timeout=None, ) job.wait() + # shouldn't fail + job.wait_for_resource_creation() + assert job.resource_name == _TEST_CUSTOM_JOB_NAME + expected_custom_job = _get_custom_job_proto() create_custom_job_mock.assert_called_once_with( - parent=_TEST_PARENT, custom_job=expected_custom_job + parent=_TEST_PARENT, + custom_job=expected_custom_job, + timeout=None, ) assert job.job_spec == expected_custom_job.job_spec - assert job._gca_resource.state == gca_job_state_compat.JobState.JOB_STATE_FAILED + assert job.state == gca_job_state_compat.JobState.JOB_STATE_FAILED + + @pytest.mark.usefixtures("create_custom_job_mock_fail") + def test_run_custom_job_with_fail_at_creation(self): + aiplatform.init( + project=_TEST_PROJECT, + location=_TEST_LOCATION, + staging_bucket=_TEST_STAGING_BUCKET, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) + + job = aiplatform.CustomJob( + display_name=_TEST_DISPLAY_NAME, + worker_pool_specs=_TEST_WORKER_POOL_SPEC, + base_output_dir=_TEST_BASE_OUTPUT_DIR, + ) + + job.run( + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, + timeout=_TEST_TIMEOUT, + restart_job_on_worker_restart=_TEST_RESTART_JOB_ON_WORKER_RESTART, + sync=False, + ) + + with pytest.raises(RuntimeError) as e: + job.wait_for_resource_creation() + assert e.match("Mock fail") + + with pytest.raises(RuntimeError) as e: + job.resource_name + assert e.match( + "CustomJob resource has not been created. Resource failed with: Mock fail" + ) + + with pytest.raises(RuntimeError) as e: + job.network + assert e.match( + "CustomJob resource has not been created. Resource failed with: Mock fail" + ) def test_custom_job_get_state_raises_without_run(self): aiplatform.init( @@ -278,7 +500,9 @@ def test_custom_job_get_state_raises_without_run(self): ) job = aiplatform.CustomJob( - display_name=_TEST_DISPLAY_NAME, worker_pool_specs=_TEST_WORKER_POOL_SPEC + display_name=_TEST_DISPLAY_NAME, + worker_pool_specs=_TEST_WORKER_POOL_SPEC, + base_output_dir=_TEST_BASE_OUTPUT_DIR, ) with pytest.raises(RuntimeError): @@ -298,7 +522,9 @@ def test_get_custom_job(self, get_custom_job_mock): job = aiplatform.CustomJob.get(_TEST_CUSTOM_JOB_NAME) - get_custom_job_mock.assert_called_once_with(name=_TEST_CUSTOM_JOB_NAME) + get_custom_job_mock.assert_called_once_with( + name=_TEST_CUSTOM_JOB_NAME, retry=base._DEFAULT_RETRY + ) assert ( job._gca_resource.state == gca_job_state_compat.JobState.JOB_STATE_PENDING ) @@ -321,6 +547,8 @@ def test_create_from_local_script( display_name=_TEST_DISPLAY_NAME, script_path=test_training_jobs._TEST_LOCAL_SCRIPT_FILE_NAME, container_uri=_TEST_TRAINING_CONTAINER_IMAGE, + base_output_dir=_TEST_BASE_OUTPUT_DIR, + labels=_TEST_LABELS, ) job.run(sync=sync) @@ -351,9 +579,85 @@ def test_create_from_local_script_raises_with_no_staging_bucket( container_uri=_TEST_TRAINING_CONTAINER_IMAGE, ) + @pytest.mark.parametrize("sync", [True, False]) + def test_create_custom_job_with_enable_web_access( + self, + create_custom_job_mock_with_enable_web_access, + get_custom_job_mock_with_enable_web_access, + sync, + caplog, + ): + caplog.set_level(logging.INFO) + + aiplatform.init( + project=_TEST_PROJECT, + location=_TEST_LOCATION, + staging_bucket=_TEST_STAGING_BUCKET, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) + + job = aiplatform.CustomJob( + display_name=_TEST_DISPLAY_NAME, + worker_pool_specs=_TEST_WORKER_POOL_SPEC, + base_output_dir=_TEST_BASE_OUTPUT_DIR, + labels=_TEST_LABELS, + ) + + job.run( + enable_web_access=_TEST_ENABLE_WEB_ACCESS, + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, + timeout=_TEST_TIMEOUT, + restart_job_on_worker_restart=_TEST_RESTART_JOB_ON_WORKER_RESTART, + sync=sync, + create_request_timeout=None, + ) + + job.wait_for_resource_creation() + + job.wait() + + assert "workerpool0-0" in caplog.text + + assert job.resource_name == _TEST_CUSTOM_JOB_NAME + + expected_custom_job = _get_custom_job_proto_with_enable_web_access() + + create_custom_job_mock_with_enable_web_access.assert_called_once_with( + parent=_TEST_PARENT, + custom_job=expected_custom_job, + timeout=None, + ) + + assert job.job_spec == expected_custom_job.job_spec + assert ( + job._gca_resource.state == gca_job_state_compat.JobState.JOB_STATE_SUCCEEDED + ) + caplog.clear() + + def test_get_web_access_uris(self, get_custom_job_mock_with_enable_web_access): + job = aiplatform.CustomJob.get(_TEST_CUSTOM_JOB_NAME) + while True: + if job.web_access_uris: + assert job.web_access_uris == _TEST_WEB_ACCESS_URIS + break + + def test_log_access_web_uris_after_get( + self, get_custom_job_mock_with_enable_web_access + ): + job = aiplatform.CustomJob.get(_TEST_CUSTOM_JOB_NAME) + job._block_until_complete() + assert job._logged_web_access_uris == set(_TEST_WEB_ACCESS_URIS.values()) + + def test_get_web_access_uris_job_succeeded( + self, get_custom_job_mock_with_enable_web_access_succeeded + ): + job = aiplatform.CustomJob.get(_TEST_CUSTOM_JOB_NAME) + assert not job.web_access_uris + @pytest.mark.parametrize("sync", [True, False]) def test_create_custom_job_with_tensorboard( - self, create_custom_job_v1beta1_mock, get_custom_job_mock, sync + self, create_custom_job_mock_with_tensorboard, get_custom_job_mock, sync ): aiplatform.init( @@ -364,7 +668,10 @@ def test_create_custom_job_with_tensorboard( ) job = aiplatform.CustomJob( - display_name=_TEST_DISPLAY_NAME, worker_pool_specs=_TEST_WORKER_POOL_SPEC + display_name=_TEST_DISPLAY_NAME, + worker_pool_specs=_TEST_WORKER_POOL_SPEC, + base_output_dir=_TEST_BASE_OUTPUT_DIR, + labels=_TEST_LABELS, ) job.run( @@ -374,14 +681,18 @@ def test_create_custom_job_with_tensorboard( timeout=_TEST_TIMEOUT, restart_job_on_worker_restart=_TEST_RESTART_JOB_ON_WORKER_RESTART, sync=sync, + create_request_timeout=None, ) job.wait() - expected_custom_job = _get_custom_job_proto(version="v1beta1") + expected_custom_job = _get_custom_job_proto() + expected_custom_job.job_spec.tensorboard = _TEST_TENSORBOARD_NAME - create_custom_job_v1beta1_mock.assert_called_once_with( - parent=_TEST_PARENT, custom_job=expected_custom_job + create_custom_job_mock_with_tensorboard.assert_called_once_with( + parent=_TEST_PARENT, + custom_job=expected_custom_job, + timeout=None, ) expected_custom_job = _get_custom_job_proto() @@ -390,3 +701,99 @@ def test_create_custom_job_with_tensorboard( assert ( job._gca_resource.state == gca_job_state_compat.JobState.JOB_STATE_SUCCEEDED ) + + def test_create_custom_job_without_base_output_dir( + self, + ): + + aiplatform.init( + project=_TEST_PROJECT, + location=_TEST_LOCATION, + staging_bucket=_TEST_STAGING_BUCKET, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) + + job = aiplatform.CustomJob( + display_name=_TEST_DISPLAY_NAME, + worker_pool_specs=_TEST_WORKER_POOL_SPEC, + ) + + assert job.job_spec.base_output_directory.output_uri_prefix.startswith( + f"{_TEST_STAGING_BUCKET}/aiplatform-custom-job" + ) + + @pytest.mark.usefixtures("mock_python_package_to_gcs") + @pytest.mark.parametrize("sync", [True, False]) + def test_create_from_local_script_with_all_args( + self, get_custom_job_mock, create_custom_job_mock, sync + ): + aiplatform.init( + project=_TEST_PROJECT, + location=_TEST_LOCATION, + staging_bucket=_TEST_STAGING_BUCKET, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) + + # configuration on this is tested in test_training_jobs.py + job = aiplatform.CustomJob.from_local_script( + display_name=_TEST_DISPLAY_NAME, + script_path=test_training_jobs._TEST_LOCAL_SCRIPT_FILE_NAME, + container_uri=_TEST_TRAINING_CONTAINER_IMAGE, + args=_TEST_RUN_ARGS, + requirements=test_training_jobs._TEST_REQUIREMENTS, + environment_variables=test_training_jobs._TEST_ENVIRONMENT_VARIABLES, + replica_count=test_training_jobs._TEST_REPLICA_COUNT, + machine_type=test_training_jobs._TEST_MACHINE_TYPE, + accelerator_type=test_training_jobs._TEST_ACCELERATOR_TYPE, + accelerator_count=test_training_jobs._TEST_ACCELERATOR_COUNT, + boot_disk_type=test_training_jobs._TEST_BOOT_DISK_TYPE, + boot_disk_size_gb=test_training_jobs._TEST_BOOT_DISK_SIZE_GB, + reduction_server_replica_count=test_training_jobs._TEST_REDUCTION_SERVER_REPLICA_COUNT, + reduction_server_machine_type=test_training_jobs._TEST_REDUCTION_SERVER_MACHINE_TYPE, + reduction_server_container_uri=test_training_jobs._TEST_REDUCTION_SERVER_CONTAINER_URI, + base_output_dir=_TEST_BASE_OUTPUT_DIR, + labels=_TEST_LABELS, + ) + + job.run(sync=sync) + + job.wait() + + assert ( + job._gca_resource.state == gca_job_state_compat.JobState.JOB_STATE_SUCCEEDED + ) + + @pytest.mark.usefixtures("get_custom_job_mock", "create_custom_job_mock") + def test_check_custom_job_availability(self): + aiplatform.init( + project=_TEST_PROJECT, + location=_TEST_LOCATION, + staging_bucket=_TEST_STAGING_BUCKET, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) + + job = aiplatform.CustomJob( + display_name=_TEST_DISPLAY_NAME, + worker_pool_specs=_TEST_WORKER_POOL_SPEC, + base_output_dir=_TEST_BASE_OUTPUT_DIR, + labels=_TEST_LABELS, + ) + + assert not job._resource_is_available + assert job.__repr__().startswith( + " dict: + """ + Takes list of values for all method parameters and return dict of kwargs, + dropping keywords that were set as None. + """ + func = helpers.get_prebuilt_prediction_container_uri + arg_names = func.__code__.co_varnames[: func.__code__.co_argcount] + return {k: v for k, v in dict(zip(arg_names, args)).items() if v is not None} + + @pytest.mark.parametrize( + "args, expected_uri", + [ + ( + ("tensorflow", "2.6", None, None), + "us-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-6:latest", + ), + ( + ("tensorflow", "1.15", "europe-west4", None), + "europe-docker.pkg.dev/vertex-ai/prediction/tf-cpu.1-15:latest", + ), + ( + ("tensorflow", "2.2", None, "gpu"), + "us-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-2:latest", + ), + ( + ("sklearn", "0.24", "asia", "cpu"), + "asia-docker.pkg.dev/vertex-ai/prediction/sklearn-cpu.0-24:latest", + ), + ( + ("sklearn", "0.20", None, None), + "us-docker.pkg.dev/vertex-ai/prediction/sklearn-cpu.0-20:latest", + ), + ( + ("xgboost", "1.3", None, None), + "us-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.1-3:latest", + ), + ( + ("xgboost", "0.90", "europe", None), + "europe-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.0-90:latest", + ), + ], + ) + def test_correct_prediction_uri_args(self, args, expected_uri): + uri = helpers.get_prebuilt_prediction_container_uri( + **self._build_predict_uri_kwargs(args) + ) + + assert uri == expected_uri + + def test_correct_prediction_uri_args_with_init_location(self): + """ + Ensure that aiplatform.init location is used when region + is not provided + """ + uri = aiplatform.helpers.get_prebuilt_prediction_container_uri( + "tensorflow", "2.6" + ) + # SDK default location is us-central1 + assert uri.startswith("us-docker.pkg.dev") + + aiplatform.init(location="asia-northeast3") + uri = aiplatform.helpers.get_prebuilt_prediction_container_uri( + "tensorflow", "2.6" + ) + assert uri.startswith("asia-docker.pkg.dev") + + aiplatform.init(location="europe-west2") + uri = aiplatform.helpers.get_prebuilt_prediction_container_uri( + "xgboost", "0.90" + ) + assert uri.startswith("europe-docker.pkg.dev") + + @pytest.mark.parametrize( + "args, expected_error_msg", + [ + ( + ("pytorch", "1.10", None, None), + "No containers found for framework `pytorch`. Supported frameworks are", + ), + ( + ("tensorflow", "9.15", None, None), + ( + "No serving container for `tensorflow` version `9.15` with accelerator " + "`cpu` found. Supported versions include" + ), + ), + ( + # Make sure region error supercedes version error + ("tensorflow", "9.15", "pluto", None), + "Unsupported container region `pluto`, supported regions are ", + ), + ( + ("tensorflow", "2.2", "narnia", None), + "Unsupported container region `narnia`, supported regions are ", + ), + ( + ("sklearn", "0.24", "asia", "gpu"), + "sklearn containers do not support `gpu` accelerator. Supported accelerators are cpu.", + ), + ( + # Make sure framework error supercedes accelerator error + ("onnx", "1.9", None, "gpu"), + "No containers found for framework `onnx`. Supported frameworks are", + ), + ], + ) + def test_invalid_prediction_uri_args(self, args, expected_error_msg): + + with pytest.raises(ValueError) as err: + helpers.get_prebuilt_prediction_container_uri( + **self._build_predict_uri_kwargs(args) + ) + + assert err.match(expected_error_msg) diff --git a/tests/unit/aiplatform/test_hyperparameter_tuning_job.py b/tests/unit/aiplatform/test_hyperparameter_tuning_job.py index f4102fc3bb..30a2ea40be 100644 --- a/tests/unit/aiplatform/test_hyperparameter_tuning_job.py +++ b/tests/unit/aiplatform/test_hyperparameter_tuning_job.py @@ -21,23 +21,19 @@ from unittest import mock from unittest.mock import patch +import logging from google.rpc import status_pb2 from google.cloud import aiplatform +from google.cloud.aiplatform import base from google.cloud.aiplatform import hyperparameter_tuning as hpt -from google.cloud.aiplatform.compat.types import job_state as gca_job_state_compat from google.cloud.aiplatform.compat.types import ( encryption_spec as gca_encryption_spec_compat, -) -from google.cloud.aiplatform.compat.types import ( hyperparameter_tuning_job as gca_hyperparameter_tuning_job_compat, - hyperparameter_tuning_job_v1beta1 as gca_hyperparameter_tuning_job_v1beta1, -) -from google.cloud.aiplatform.compat.types import study as gca_study_compat -from google.cloud.aiplatform_v1.services.job_service import client as job_service_client -from google.cloud.aiplatform_v1beta1.services.job_service import ( - client as job_service_client_v1beta1, + job_state as gca_job_state_compat, + study as gca_study_compat, ) +from google.cloud.aiplatform.compat.services import job_service_client import test_custom_job @@ -49,6 +45,7 @@ _TEST_PARENT = f"projects/{_TEST_PROJECT}/locations/{_TEST_LOCATION}" _TEST_STAGING_BUCKET = test_custom_job._TEST_STAGING_BUCKET +_TEST_BASE_OUTPUT_DIR = test_custom_job._TEST_BASE_OUTPUT_DIR _TEST_HYPERPARAMETERTUNING_JOB_NAME = ( f"{_TEST_PARENT}/hyperparameterTuningJobs/{_TEST_ID}" @@ -77,6 +74,7 @@ _TEST_SEARCH_ALGORITHM = "random" _TEST_MEASUREMENT_SELECTION = "best" +_TEST_LABELS = {"my_hp_key": "my_hp_value"} _TEST_BASE_HYPERPARAMETER_TUNING_JOB_PROTO = gca_hyperparameter_tuning_job_compat.HyperparameterTuningJob( display_name=_TEST_DISPLAY_NAME, @@ -122,13 +120,14 @@ max_trial_count=_TEST_MAX_TRIAL_COUNT, max_failed_trial_count=_TEST_MAX_FAILED_TRIAL_COUNT, trial_job_spec=test_custom_job._TEST_BASE_CUSTOM_JOB_PROTO.job_spec, + labels=_TEST_LABELS, encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, ) +_TEST_BASE_TRIAL_PROTO = gca_study_compat.Trial() -def _get_hyperparameter_tuning_job_proto( - state=None, name=None, error=None, version="v1" -): + +def _get_hyperparameter_tuning_job_proto(state=None, name=None, error=None): hyperparameter_tuning_job_proto = copy.deepcopy( _TEST_BASE_HYPERPARAMETER_TUNING_JOB_PROTO ) @@ -136,18 +135,31 @@ def _get_hyperparameter_tuning_job_proto( hyperparameter_tuning_job_proto.state = state hyperparameter_tuning_job_proto.error = error - if version == "v1beta1": - v1beta1_hyperparameter_tuning_job_proto = ( - gca_hyperparameter_tuning_job_v1beta1.HyperparameterTuningJob() - ) - v1beta1_hyperparameter_tuning_job_proto._pb.MergeFromString( - hyperparameter_tuning_job_proto._pb.SerializeToString() - ) - hyperparameter_tuning_job_proto = v1beta1_hyperparameter_tuning_job_proto - hyperparameter_tuning_job_proto.trial_job_spec.tensorboard = ( - test_custom_job._TEST_TENSORBOARD_NAME - ) + return hyperparameter_tuning_job_proto + + +def _get_trial_proto(id=None, state=None): + trial_proto = copy.deepcopy(_TEST_BASE_TRIAL_PROTO) + trial_proto.id = id + trial_proto.state = state + if state == gca_study_compat.Trial.State.ACTIVE: + trial_proto.web_access_uris = test_custom_job._TEST_WEB_ACCESS_URIS + return trial_proto + +def _get_hyperparameter_tuning_job_proto_with_enable_web_access( + state=None, name=None, error=None, trials=[] +): + hyperparameter_tuning_job_proto = _get_hyperparameter_tuning_job_proto( + state=state, + name=name, + error=error, + ) + hyperparameter_tuning_job_proto.trial_job_spec.enable_web_access = ( + test_custom_job._TEST_ENABLE_WEB_ACCESS + ) + if state == gca_job_state_compat.JobState.JOB_STATE_RUNNING: + hyperparameter_tuning_job_proto.trials = trials return hyperparameter_tuning_job_proto @@ -169,6 +181,90 @@ def get_hyperparameter_tuning_job_mock(): name=_TEST_HYPERPARAMETERTUNING_JOB_NAME, state=gca_job_state_compat.JobState.JOB_STATE_SUCCEEDED, ), + _get_hyperparameter_tuning_job_proto( + name=_TEST_HYPERPARAMETERTUNING_JOB_NAME, + state=gca_job_state_compat.JobState.JOB_STATE_SUCCEEDED, + ), + ] + yield get_hyperparameter_tuning_job_mock + + +@pytest.fixture +def get_hyperparameter_tuning_job_mock_with_enable_web_access(): + with patch.object( + job_service_client.JobServiceClient, "get_hyperparameter_tuning_job" + ) as get_hyperparameter_tuning_job_mock: + get_hyperparameter_tuning_job_mock.side_effect = [ + _get_hyperparameter_tuning_job_proto_with_enable_web_access( + name=_TEST_HYPERPARAMETERTUNING_JOB_NAME, + state=gca_job_state_compat.JobState.JOB_STATE_PENDING, + ), + _get_hyperparameter_tuning_job_proto_with_enable_web_access( + name=_TEST_HYPERPARAMETERTUNING_JOB_NAME, + state=gca_job_state_compat.JobState.JOB_STATE_RUNNING, + trials=[ + _get_trial_proto( + id="1", state=gca_study_compat.Trial.State.REQUESTED + ), + ], + ), + _get_hyperparameter_tuning_job_proto_with_enable_web_access( + name=_TEST_HYPERPARAMETERTUNING_JOB_NAME, + state=gca_job_state_compat.JobState.JOB_STATE_RUNNING, + trials=[ + _get_trial_proto(id="1", state=gca_study_compat.Trial.State.ACTIVE), + ], + ), + _get_hyperparameter_tuning_job_proto_with_enable_web_access( + name=_TEST_HYPERPARAMETERTUNING_JOB_NAME, + state=gca_job_state_compat.JobState.JOB_STATE_RUNNING, + trials=[ + _get_trial_proto(id="1", state=gca_study_compat.Trial.State.ACTIVE), + ], + ), + _get_hyperparameter_tuning_job_proto_with_enable_web_access( + name=_TEST_HYPERPARAMETERTUNING_JOB_NAME, + state=gca_job_state_compat.JobState.JOB_STATE_RUNNING, + trials=[ + _get_trial_proto(id="1", state=gca_study_compat.Trial.State.ACTIVE), + ], + ), + _get_hyperparameter_tuning_job_proto_with_enable_web_access( + name=_TEST_HYPERPARAMETERTUNING_JOB_NAME, + state=gca_job_state_compat.JobState.JOB_STATE_RUNNING, + trials=[ + _get_trial_proto( + id="1", state=gca_study_compat.Trial.State.SUCCEEDED + ), + ], + ), + _get_hyperparameter_tuning_job_proto_with_enable_web_access( + name=_TEST_HYPERPARAMETERTUNING_JOB_NAME, + state=gca_job_state_compat.JobState.JOB_STATE_SUCCEEDED, + trials=[ + _get_trial_proto( + id="1", state=gca_study_compat.Trial.State.SUCCEEDED + ), + ], + ), + _get_hyperparameter_tuning_job_proto_with_enable_web_access( + name=_TEST_HYPERPARAMETERTUNING_JOB_NAME, + state=gca_job_state_compat.JobState.JOB_STATE_SUCCEEDED, + trials=[ + _get_trial_proto( + id="1", state=gca_study_compat.Trial.State.SUCCEEDED + ), + ], + ), + _get_hyperparameter_tuning_job_proto_with_enable_web_access( + name=_TEST_HYPERPARAMETERTUNING_JOB_NAME, + state=gca_job_state_compat.JobState.JOB_STATE_SUCCEEDED, + trials=[ + _get_trial_proto( + id="1", state=gca_study_compat.Trial.State.SUCCEEDED + ), + ], + ), ] yield get_hyperparameter_tuning_job_mock @@ -201,26 +297,57 @@ def create_hyperparameter_tuning_job_mock(): with mock.patch.object( job_service_client.JobServiceClient, "create_hyperparameter_tuning_job" ) as create_hyperparameter_tuning_job_mock: - create_hyperparameter_tuning_job_mock.return_value = _get_hyperparameter_tuning_job_proto( - name=_TEST_HYPERPARAMETERTUNING_JOB_NAME, - state=gca_job_state_compat.JobState.JOB_STATE_PENDING, + create_hyperparameter_tuning_job_mock.return_value = ( + _get_hyperparameter_tuning_job_proto( + name=_TEST_HYPERPARAMETERTUNING_JOB_NAME, + state=gca_job_state_compat.JobState.JOB_STATE_PENDING, + ) ) yield create_hyperparameter_tuning_job_mock @pytest.fixture -def create_hyperparameter_tuning_job_v1beta1_mock(): +def create_hyperparameter_tuning_job_mock_with_enable_web_access(): with mock.patch.object( - job_service_client_v1beta1.JobServiceClient, "create_hyperparameter_tuning_job" + job_service_client.JobServiceClient, "create_hyperparameter_tuning_job" ) as create_hyperparameter_tuning_job_mock: - create_hyperparameter_tuning_job_mock.return_value = _get_hyperparameter_tuning_job_proto( + create_hyperparameter_tuning_job_mock.return_value = ( + _get_hyperparameter_tuning_job_proto_with_enable_web_access( + name=_TEST_HYPERPARAMETERTUNING_JOB_NAME, + state=gca_job_state_compat.JobState.JOB_STATE_PENDING, + ) + ) + yield create_hyperparameter_tuning_job_mock + + +@pytest.fixture +def create_hyperparameter_tuning_job_mock_fail(): + with mock.patch.object( + job_service_client.JobServiceClient, "create_hyperparameter_tuning_job" + ) as create_hyperparameter_tuning_job_mock: + create_hyperparameter_tuning_job_mock.side_effect = RuntimeError("Mock fail") + yield create_hyperparameter_tuning_job_mock + + +@pytest.fixture +def create_hyperparameter_tuning_job_mock_with_tensorboard(): + with mock.patch.object( + job_service_client.JobServiceClient, "create_hyperparameter_tuning_job" + ) as create_hyperparameter_tuning_job_mock: + hyperparameter_tuning_job_proto = _get_hyperparameter_tuning_job_proto( name=_TEST_HYPERPARAMETERTUNING_JOB_NAME, state=gca_job_state_compat.JobState.JOB_STATE_PENDING, - version="v1beta1", + ) + hyperparameter_tuning_job_proto.trial_job_spec.tensorboard = ( + test_custom_job._TEST_TENSORBOARD_NAME + ) + create_hyperparameter_tuning_job_mock.return_value = ( + hyperparameter_tuning_job_proto ) yield create_hyperparameter_tuning_job_mock +@pytest.mark.usefixtures("google_auth_mock") class TestHyperparameterTuningJob: def setup_method(self): reload(aiplatform.initializer) @@ -247,6 +374,7 @@ def test_create_hyperparameter_tuning_job( custom_job = aiplatform.CustomJob( display_name=test_custom_job._TEST_DISPLAY_NAME, worker_pool_specs=test_custom_job._TEST_WORKER_POOL_SPEC, + base_output_dir=test_custom_job._TEST_BASE_OUTPUT_DIR, ) job = aiplatform.HyperparameterTuningJob( @@ -268,6 +396,7 @@ def test_create_hyperparameter_tuning_job( max_failed_trial_count=_TEST_MAX_FAILED_TRIAL_COUNT, search_algorithm=_TEST_SEARCH_ALGORITHM, measurement_selection=_TEST_MEASUREMENT_SELECTION, + labels=_TEST_LABELS, ) job.run( @@ -276,6 +405,7 @@ def test_create_hyperparameter_tuning_job( timeout=_TEST_TIMEOUT, restart_job_on_worker_restart=_TEST_RESTART_JOB_ON_WORKER_RESTART, sync=sync, + create_request_timeout=None, ) job.wait() @@ -285,10 +415,73 @@ def test_create_hyperparameter_tuning_job( create_hyperparameter_tuning_job_mock.assert_called_once_with( parent=_TEST_PARENT, hyperparameter_tuning_job=expected_hyperparameter_tuning_job, + timeout=None, ) - assert ( - job._gca_resource.state == gca_job_state_compat.JobState.JOB_STATE_SUCCEEDED + assert job.state == gca_job_state_compat.JobState.JOB_STATE_SUCCEEDED + assert job.network == _TEST_NETWORK + assert job.trials == [] + + @pytest.mark.parametrize("sync", [True, False]) + def test_create_hyperparameter_tuning_job_with_timeout( + self, + create_hyperparameter_tuning_job_mock, + get_hyperparameter_tuning_job_mock, + sync, + ): + + aiplatform.init( + project=_TEST_PROJECT, + location=_TEST_LOCATION, + staging_bucket=_TEST_STAGING_BUCKET, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) + + custom_job = aiplatform.CustomJob( + display_name=test_custom_job._TEST_DISPLAY_NAME, + worker_pool_specs=test_custom_job._TEST_WORKER_POOL_SPEC, + base_output_dir=test_custom_job._TEST_BASE_OUTPUT_DIR, + ) + + job = aiplatform.HyperparameterTuningJob( + display_name=_TEST_DISPLAY_NAME, + custom_job=custom_job, + metric_spec={_TEST_METRIC_SPEC_KEY: _TEST_METRIC_SPEC_VALUE}, + parameter_spec={ + "lr": hpt.DoubleParameterSpec(min=0.001, max=0.1, scale="log"), + "units": hpt.IntegerParameterSpec(min=4, max=1028, scale="linear"), + "activation": hpt.CategoricalParameterSpec( + values=["relu", "sigmoid", "elu", "selu", "tanh"] + ), + "batch_size": hpt.DiscreteParameterSpec( + values=[16, 32], scale="linear" + ), + }, + parallel_trial_count=_TEST_PARALLEL_TRIAL_COUNT, + max_trial_count=_TEST_MAX_TRIAL_COUNT, + max_failed_trial_count=_TEST_MAX_FAILED_TRIAL_COUNT, + search_algorithm=_TEST_SEARCH_ALGORITHM, + measurement_selection=_TEST_MEASUREMENT_SELECTION, + labels=_TEST_LABELS, + ) + + job.run( + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, + timeout=_TEST_TIMEOUT, + restart_job_on_worker_restart=_TEST_RESTART_JOB_ON_WORKER_RESTART, + sync=sync, + create_request_timeout=180.0, + ) + + job.wait() + + expected_hyperparameter_tuning_job = _get_hyperparameter_tuning_job_proto() + + create_hyperparameter_tuning_job_mock.assert_called_once_with( + parent=_TEST_PARENT, + hyperparameter_tuning_job=expected_hyperparameter_tuning_job, + timeout=180.0, ) @pytest.mark.parametrize("sync", [True, False]) @@ -308,6 +501,7 @@ def test_run_hyperparameter_tuning_job_with_fail_raises( custom_job = aiplatform.CustomJob( display_name=test_custom_job._TEST_DISPLAY_NAME, worker_pool_specs=test_custom_job._TEST_WORKER_POOL_SPEC, + base_output_dir=test_custom_job._TEST_BASE_OUTPUT_DIR, ) job = aiplatform.HyperparameterTuningJob( @@ -329,6 +523,7 @@ def test_run_hyperparameter_tuning_job_with_fail_raises( max_failed_trial_count=_TEST_MAX_FAILED_TRIAL_COUNT, search_algorithm=_TEST_SEARCH_ALGORITHM, measurement_selection=_TEST_MEASUREMENT_SELECTION, + labels=_TEST_LABELS, ) with pytest.raises(RuntimeError): @@ -338,6 +533,7 @@ def test_run_hyperparameter_tuning_job_with_fail_raises( timeout=_TEST_TIMEOUT, restart_job_on_worker_restart=_TEST_RESTART_JOB_ON_WORKER_RESTART, sync=sync, + create_request_timeout=None, ) job.wait() @@ -347,10 +543,77 @@ def test_run_hyperparameter_tuning_job_with_fail_raises( create_hyperparameter_tuning_job_mock.assert_called_once_with( parent=_TEST_PARENT, hyperparameter_tuning_job=expected_hyperparameter_tuning_job, + timeout=None, ) assert job._gca_resource.state == gca_job_state_compat.JobState.JOB_STATE_FAILED + @pytest.mark.usefixtures("create_hyperparameter_tuning_job_mock_fail") + def test_run_hyperparameter_tuning_job_with_fail_at_creation(self): + aiplatform.init( + project=_TEST_PROJECT, + location=_TEST_LOCATION, + staging_bucket=_TEST_STAGING_BUCKET, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) + + custom_job = aiplatform.CustomJob( + display_name=test_custom_job._TEST_DISPLAY_NAME, + worker_pool_specs=test_custom_job._TEST_WORKER_POOL_SPEC, + base_output_dir=test_custom_job._TEST_BASE_OUTPUT_DIR, + ) + + job = aiplatform.HyperparameterTuningJob( + display_name=_TEST_DISPLAY_NAME, + custom_job=custom_job, + metric_spec={_TEST_METRIC_SPEC_KEY: _TEST_METRIC_SPEC_VALUE}, + parameter_spec={ + "lr": hpt.DoubleParameterSpec(min=0.001, max=0.1, scale="log"), + "units": hpt.IntegerParameterSpec(min=4, max=1028, scale="linear"), + "activation": hpt.CategoricalParameterSpec( + values=["relu", "sigmoid", "elu", "selu", "tanh"] + ), + "batch_size": hpt.DiscreteParameterSpec( + values=[16, 32], scale="linear" + ), + }, + parallel_trial_count=_TEST_PARALLEL_TRIAL_COUNT, + max_trial_count=_TEST_MAX_TRIAL_COUNT, + max_failed_trial_count=_TEST_MAX_FAILED_TRIAL_COUNT, + search_algorithm=_TEST_SEARCH_ALGORITHM, + measurement_selection=_TEST_MEASUREMENT_SELECTION, + ) + + job.run( + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, + timeout=_TEST_TIMEOUT, + restart_job_on_worker_restart=_TEST_RESTART_JOB_ON_WORKER_RESTART, + sync=False, + ) + + with pytest.raises(RuntimeError) as e: + job.wait_for_resource_creation() + assert e.match("Mock fail") + + with pytest.raises(RuntimeError) as e: + job.resource_name + assert e.match( + "HyperparameterTuningJob resource has not been created. Resource failed with: Mock fail" + ) + + with pytest.raises(RuntimeError) as e: + job.network + assert e.match( + "HyperparameterTuningJob resource has not been created. Resource failed with: Mock fail" + ) + + with pytest.raises(RuntimeError) as e: + job.trials + assert e.match( + "HyperparameterTuningJob resource has not been created. Resource failed with: Mock fail" + ) + def test_hyperparameter_tuning_job_get_state_raises_without_run(self): aiplatform.init( project=_TEST_PROJECT, @@ -362,6 +625,7 @@ def test_hyperparameter_tuning_job_get_state_raises_without_run(self): custom_job = aiplatform.CustomJob( display_name=test_custom_job._TEST_DISPLAY_NAME, worker_pool_specs=test_custom_job._TEST_WORKER_POOL_SPEC, + base_output_dir=test_custom_job._TEST_BASE_OUTPUT_DIR, ) job = aiplatform.HyperparameterTuningJob( @@ -395,7 +659,7 @@ def test_get_hyperparameter_tuning_job(self, get_hyperparameter_tuning_job_mock) ) get_hyperparameter_tuning_job_mock.assert_called_once_with( - name=_TEST_HYPERPARAMETERTUNING_JOB_NAME + name=_TEST_HYPERPARAMETERTUNING_JOB_NAME, retry=base._DEFAULT_RETRY ) assert ( job._gca_resource.state == gca_job_state_compat.JobState.JOB_STATE_PENDING @@ -404,7 +668,7 @@ def test_get_hyperparameter_tuning_job(self, get_hyperparameter_tuning_job_mock) @pytest.mark.parametrize("sync", [True, False]) def test_create_hyperparameter_tuning_job_with_tensorboard( self, - create_hyperparameter_tuning_job_v1beta1_mock, + create_hyperparameter_tuning_job_mock_with_tensorboard, get_hyperparameter_tuning_job_mock, sync, ): @@ -419,6 +683,7 @@ def test_create_hyperparameter_tuning_job_with_tensorboard( custom_job = aiplatform.CustomJob( display_name=test_custom_job._TEST_DISPLAY_NAME, worker_pool_specs=test_custom_job._TEST_WORKER_POOL_SPEC, + base_output_dir=test_custom_job._TEST_BASE_OUTPUT_DIR, ) job = aiplatform.HyperparameterTuningJob( @@ -440,6 +705,7 @@ def test_create_hyperparameter_tuning_job_with_tensorboard( max_failed_trial_count=_TEST_MAX_FAILED_TRIAL_COUNT, search_algorithm=_TEST_SEARCH_ALGORITHM, measurement_selection=_TEST_MEASUREMENT_SELECTION, + labels=_TEST_LABELS, ) job.run( @@ -449,19 +715,110 @@ def test_create_hyperparameter_tuning_job_with_tensorboard( restart_job_on_worker_restart=_TEST_RESTART_JOB_ON_WORKER_RESTART, tensorboard=test_custom_job._TEST_TENSORBOARD_NAME, sync=sync, + create_request_timeout=None, ) job.wait() - expected_hyperparameter_tuning_job = _get_hyperparameter_tuning_job_proto( - version="v1beta1" + expected_hyperparameter_tuning_job = _get_hyperparameter_tuning_job_proto() + expected_hyperparameter_tuning_job.trial_job_spec.tensorboard = ( + test_custom_job._TEST_TENSORBOARD_NAME ) - create_hyperparameter_tuning_job_v1beta1_mock.assert_called_once_with( + create_hyperparameter_tuning_job_mock_with_tensorboard.assert_called_once_with( parent=_TEST_PARENT, hyperparameter_tuning_job=expected_hyperparameter_tuning_job, + timeout=None, ) assert ( job._gca_resource.state == gca_job_state_compat.JobState.JOB_STATE_SUCCEEDED ) + + @pytest.mark.parametrize("sync", [True, False]) + def test_create_hyperparameter_tuning_job_with_enable_web_access( + self, + create_hyperparameter_tuning_job_mock_with_enable_web_access, + get_hyperparameter_tuning_job_mock_with_enable_web_access, + sync, + caplog, + ): + caplog.set_level(logging.INFO) + + aiplatform.init( + project=_TEST_PROJECT, + location=_TEST_LOCATION, + staging_bucket=_TEST_STAGING_BUCKET, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) + + custom_job = aiplatform.CustomJob( + display_name=test_custom_job._TEST_DISPLAY_NAME, + worker_pool_specs=test_custom_job._TEST_WORKER_POOL_SPEC, + base_output_dir=test_custom_job._TEST_BASE_OUTPUT_DIR, + ) + + job = aiplatform.HyperparameterTuningJob( + display_name=_TEST_DISPLAY_NAME, + custom_job=custom_job, + metric_spec={_TEST_METRIC_SPEC_KEY: _TEST_METRIC_SPEC_VALUE}, + parameter_spec={ + "lr": hpt.DoubleParameterSpec(min=0.001, max=0.1, scale="log"), + "units": hpt.IntegerParameterSpec(min=4, max=1028, scale="linear"), + "activation": hpt.CategoricalParameterSpec( + values=["relu", "sigmoid", "elu", "selu", "tanh"] + ), + "batch_size": hpt.DiscreteParameterSpec( + values=[16, 32], scale="linear" + ), + }, + parallel_trial_count=_TEST_PARALLEL_TRIAL_COUNT, + max_trial_count=_TEST_MAX_TRIAL_COUNT, + max_failed_trial_count=_TEST_MAX_FAILED_TRIAL_COUNT, + search_algorithm=_TEST_SEARCH_ALGORITHM, + measurement_selection=_TEST_MEASUREMENT_SELECTION, + labels=_TEST_LABELS, + ) + + job.run( + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, + timeout=_TEST_TIMEOUT, + restart_job_on_worker_restart=_TEST_RESTART_JOB_ON_WORKER_RESTART, + enable_web_access=test_custom_job._TEST_ENABLE_WEB_ACCESS, + sync=sync, + create_request_timeout=None, + ) + + job.wait() + + assert "workerpool0-0" in caplog.text + + expected_hyperparameter_tuning_job = ( + _get_hyperparameter_tuning_job_proto_with_enable_web_access() + ) + + create_hyperparameter_tuning_job_mock_with_enable_web_access.assert_called_once_with( + parent=_TEST_PARENT, + hyperparameter_tuning_job=expected_hyperparameter_tuning_job, + timeout=None, + ) + + assert job.state == gca_job_state_compat.JobState.JOB_STATE_SUCCEEDED + assert job.network == _TEST_NETWORK + assert job.trials == [] + + caplog.clear() + + def test_log_enable_web_access_after_get_hyperparameter_tuning_job( + self, + get_hyperparameter_tuning_job_mock_with_enable_web_access, + ): + + hp_job = aiplatform.HyperparameterTuningJob.get( + _TEST_HYPERPARAMETERTUNING_JOB_NAME + ) + hp_job._block_until_complete() + assert hp_job._logged_web_access_uris == set( + test_custom_job._TEST_WEB_ACCESS_URIS.values() + ) diff --git a/tests/unit/aiplatform/test_initializer.py b/tests/unit/aiplatform/test_initializer.py index 7e65c99b4c..edc78c6967 100644 --- a/tests/unit/aiplatform/test_initializer.py +++ b/tests/unit/aiplatform/test_initializer.py @@ -25,12 +25,13 @@ from google.auth import credentials from google.cloud.aiplatform import initializer -from google.cloud.aiplatform.metadata.metadata import metadata_service -from google.cloud.aiplatform import constants +from google.cloud.aiplatform.metadata.metadata import _experiment_tracker +from google.cloud.aiplatform.constants import base as constants from google.cloud.aiplatform import utils +from google.cloud.aiplatform.utils import resource_manager_utils -from google.cloud.aiplatform_v1.services.model_service import ( - client as model_service_client, +from google.cloud.aiplatform.compat.services import ( + model_service_client, ) _TEST_PROJECT = "test-project" @@ -43,6 +44,7 @@ _TEST_STAGING_BUCKET = "test-bucket" +@pytest.mark.usefixtures("google_auth_mock") class TestInit: def setup_method(self): importlib.reload(initializer) @@ -61,6 +63,22 @@ def mock_auth_default(): monkeypatch.setattr(google.auth, "default", mock_auth_default) assert initializer.global_config.project == _TEST_PROJECT + def test_infer_project_id(self): + cloud_project_number = "123" + + def mock_get_project_id(project_number: str, **_): + assert project_number == cloud_project_number + return _TEST_PROJECT + + with mock.patch.object( + target=resource_manager_utils, + attribute="get_project_id", + new=mock_get_project_id, + ), mock.patch.dict( + os.environ, {"CLOUD_ML_PROJECT_ID": cloud_project_number}, clear=True + ): + assert initializer.global_config.project == _TEST_PROJECT + def test_init_location_sets_location(self): initializer.global_config.init(location=_TEST_LOCATION) assert initializer.global_config.location == _TEST_LOCATION @@ -72,14 +90,14 @@ def test_init_location_with_invalid_location_raises(self): with pytest.raises(ValueError): initializer.global_config.init(location=_TEST_INVALID_LOCATION) - @patch.object(metadata_service, "set_experiment") + @patch.object(_experiment_tracker, "set_experiment") def test_init_experiment_sets_experiment(self, set_experiment_mock): initializer.global_config.init(experiment=_TEST_EXPERIMENT) set_experiment_mock.assert_called_once_with( - experiment=_TEST_EXPERIMENT, description=None + experiment=_TEST_EXPERIMENT, description=None, backing_tensorboard=None ) - @patch.object(metadata_service, "set_experiment") + @patch.object(_experiment_tracker, "set_experiment") def test_init_experiment_sets_experiment_with_description( self, set_experiment_mock ): @@ -87,7 +105,9 @@ def test_init_experiment_sets_experiment_with_description( experiment=_TEST_EXPERIMENT, experiment_description=_TEST_DESCRIPTION ) set_experiment_mock.assert_called_once_with( - experiment=_TEST_EXPERIMENT, description=_TEST_DESCRIPTION + experiment=_TEST_EXPERIMENT, + description=_TEST_DESCRIPTION, + backing_tensorboard=None, ) def test_init_experiment_description_fail_without_experiment(self): @@ -160,7 +180,11 @@ def test_create_client_user_agent(self): "init_location, location_override, expected_endpoint", [ ("us-central1", None, "us-central1-aiplatform.googleapis.com"), - ("us-central1", "europe-west4", "europe-west4-aiplatform.googleapis.com",), + ( + "us-central1", + "europe-west4", + "europe-west4-aiplatform.googleapis.com", + ), ("asia-east1", None, "asia-east1-aiplatform.googleapis.com"), ( "asia-southeast1", @@ -170,7 +194,10 @@ def test_create_client_user_agent(self): ], ) def test_get_client_options( - self, init_location: str, location_override: str, expected_endpoint: str, + self, + init_location: str, + location_override: str, + expected_endpoint: str, ): initializer.global_config.init(location=init_location) @@ -181,6 +208,15 @@ def test_get_client_options( == expected_endpoint ) + def test_get_client_options_with_api_override(self): + initializer.global_config.init(location="asia-east1") + + client_options = initializer.global_config.get_client_options( + api_base_path_override="override.googleapis.com" + ) + + assert client_options.api_endpoint == "asia-east1-override.googleapis.com" + class TestThreadPool: def teardown_method(self): diff --git a/tests/unit/aiplatform/test_jobs.py b/tests/unit/aiplatform/test_jobs.py index acc7317ebb..e69378f55b 100644 --- a/tests/unit/aiplatform/test_jobs.py +++ b/tests/unit/aiplatform/test_jobs.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -27,40 +27,38 @@ from google.auth import credentials as auth_credentials from google.cloud import aiplatform - -from google.cloud.aiplatform import jobs +from google.cloud.aiplatform import base from google.cloud.aiplatform import initializer +from google.cloud.aiplatform import jobs -from google.cloud.aiplatform_v1beta1.services.job_service import ( - client as job_service_client_v1beta1, +from google.cloud.aiplatform.compat.types import ( + batch_prediction_job as gca_batch_prediction_job_compat, + explanation as gca_explanation_compat, + io as gca_io_compat, + job_state as gca_job_state_compat, + machine_resources as gca_machine_resources_compat, + manual_batch_tuning_parameters as gca_manual_batch_tuning_parameters_compat, ) -from google.cloud.aiplatform_v1beta1.types import ( - batch_prediction_job as gca_batch_prediction_job_v1beta1, - explanation as gca_explanation_v1beta1, - io as gca_io_v1beta1, - machine_resources as gca_machine_resources_v1beta1, +from google.cloud.aiplatform.compat.services import ( + job_service_client, ) -from google.cloud.aiplatform_v1.services.job_service import client as job_service_client - -from google.cloud.aiplatform_v1.types import ( - batch_prediction_job as gca_batch_prediction_job, - io as gca_io, - job_state as gca_job_state, -) +_TEST_API_CLIENT = job_service_client.JobServiceClient _TEST_PROJECT = "test-project" _TEST_LOCATION = "us-central1" _TEST_ID = "1028944691210842416" _TEST_ALT_ID = "8834795523125638878" _TEST_DISPLAY_NAME = "my_job_1234" +_TEST_BQ_PROJECT_ID = "projectId" _TEST_BQ_DATASET_ID = "bqDatasetId" +_TEST_BQ_TABLE_NAME = "someBqTable" _TEST_BQ_JOB_ID = "123459876" _TEST_BQ_MAX_RESULTS = 100 _TEST_GCS_BUCKET_NAME = "my-bucket" -_TEST_BQ_PATH = f"bq://projectId.{_TEST_BQ_DATASET_ID}" +_TEST_BQ_PATH = f"bq://{_TEST_BQ_PROJECT_ID}.{_TEST_BQ_DATASET_ID}" _TEST_GCS_BUCKET_PATH = f"gs://{_TEST_GCS_BUCKET_NAME}" _TEST_GCS_JSONL_SOURCE_URI = f"{_TEST_GCS_BUCKET_PATH}/bp_input_config.jsonl" _TEST_PARENT = f"projects/{_TEST_PROJECT}/locations/{_TEST_LOCATION}" @@ -82,36 +80,51 @@ f"bq://{_TEST_BATCH_PREDICTION_BQ_PREFIX}" ) -_TEST_JOB_STATE_SUCCESS = gca_job_state.JobState(4) -_TEST_JOB_STATE_RUNNING = gca_job_state.JobState(3) -_TEST_JOB_STATE_PENDING = gca_job_state.JobState(2) +_TEST_JOB_STATE_SUCCESS = gca_job_state_compat.JobState(4) +_TEST_JOB_STATE_RUNNING = gca_job_state_compat.JobState(3) +_TEST_JOB_STATE_PENDING = gca_job_state_compat.JobState(2) -_TEST_GCS_INPUT_CONFIG = gca_batch_prediction_job.BatchPredictionJob.InputConfig( +_TEST_GCS_INPUT_CONFIG = gca_batch_prediction_job_compat.BatchPredictionJob.InputConfig( instances_format="jsonl", - gcs_source=gca_io.GcsSource(uris=[_TEST_GCS_JSONL_SOURCE_URI]), + gcs_source=gca_io_compat.GcsSource(uris=[_TEST_GCS_JSONL_SOURCE_URI]), ) -_TEST_GCS_OUTPUT_CONFIG = gca_batch_prediction_job.BatchPredictionJob.OutputConfig( - predictions_format="jsonl", - gcs_destination=gca_io.GcsDestination(output_uri_prefix=_TEST_GCS_BUCKET_PATH), +_TEST_GCS_OUTPUT_CONFIG = ( + gca_batch_prediction_job_compat.BatchPredictionJob.OutputConfig( + predictions_format="jsonl", + gcs_destination=gca_io_compat.GcsDestination( + output_uri_prefix=_TEST_GCS_BUCKET_PATH + ), + ) ) -_TEST_BQ_INPUT_CONFIG = gca_batch_prediction_job.BatchPredictionJob.InputConfig( +_TEST_BQ_INPUT_CONFIG = gca_batch_prediction_job_compat.BatchPredictionJob.InputConfig( instances_format="bigquery", - bigquery_source=gca_io.BigQuerySource(input_uri=_TEST_BQ_PATH), + bigquery_source=gca_io_compat.BigQuerySource(input_uri=_TEST_BQ_PATH), ) -_TEST_BQ_OUTPUT_CONFIG = gca_batch_prediction_job.BatchPredictionJob.OutputConfig( - predictions_format="bigquery", - bigquery_destination=gca_io.BigQueryDestination(output_uri=_TEST_BQ_PATH), +_TEST_BQ_OUTPUT_CONFIG = ( + gca_batch_prediction_job_compat.BatchPredictionJob.OutputConfig( + predictions_format="bigquery", + bigquery_destination=gca_io_compat.BigQueryDestination( + output_uri=_TEST_BQ_PATH + ), + ) ) -_TEST_GCS_OUTPUT_INFO = gca_batch_prediction_job.BatchPredictionJob.OutputInfo( +_TEST_GCS_OUTPUT_INFO = gca_batch_prediction_job_compat.BatchPredictionJob.OutputInfo( gcs_output_directory=_TEST_GCS_BUCKET_NAME ) -_TEST_BQ_OUTPUT_INFO = gca_batch_prediction_job.BatchPredictionJob.OutputInfo( - bigquery_output_dataset=_TEST_BQ_PATH +_TEST_BQ_OUTPUT_INFO = gca_batch_prediction_job_compat.BatchPredictionJob.OutputInfo( + bigquery_output_dataset=_TEST_BQ_PATH, bigquery_output_table=_TEST_BQ_TABLE_NAME +) +_TEST_BQ_OUTPUT_INFO_INCOMPLETE = ( + gca_batch_prediction_job_compat.BatchPredictionJob.OutputInfo( + bigquery_output_dataset=_TEST_BQ_PATH + ) ) -_TEST_EMPTY_OUTPUT_INFO = gca_batch_prediction_job.BatchPredictionJob.OutputInfo() +_TEST_EMPTY_OUTPUT_INFO = ( + gca_batch_prediction_job_compat.BatchPredictionJob.OutputInfo() +) _TEST_GCS_BLOBS = [ storage.Blob(name="some/path/prediction.jsonl", bucket=_TEST_GCS_BUCKET_NAME) @@ -122,6 +135,7 @@ _TEST_ACCELERATOR_COUNT = 2 _TEST_STARTING_REPLICA_COUNT = 2 _TEST_MAX_REPLICA_COUNT = 12 +_TEST_BATCH_SIZE = 16 _TEST_LABEL = {"team": "experimentation", "trial_id": "x435"} @@ -140,11 +154,11 @@ {"sampled_shapley_attribution": {"path_count": 10}} ) -_TEST_JOB_GET_METHOD_NAME = "get_fake_job" -_TEST_JOB_LIST_METHOD_NAME = "list_fake_job" -_TEST_JOB_CANCEL_METHOD_NAME = "cancel_fake_job" -_TEST_JOB_DELETE_METHOD_NAME = "delete_fake_job" -_TEST_JOB_RESOURCE_NAME = f"{_TEST_PARENT}/fakeJobs/{_TEST_ID}" +_TEST_JOB_GET_METHOD_NAME = "get_custom_job" +_TEST_JOB_LIST_METHOD_NAME = "list_custom_job" +_TEST_JOB_CANCEL_METHOD_NAME = "cancel_custom_job" +_TEST_JOB_DELETE_METHOD_NAME = "delete_custom_job" +_TEST_JOB_RESOURCE_NAME = f"{_TEST_PARENT}/customJobs/{_TEST_ID}" # TODO(b/171333554): Move reusable test fixtures to conftest.py file @@ -152,7 +166,7 @@ @pytest.fixture def fake_job_getter_mock(): with patch.object( - job_service_client.JobServiceClient, _TEST_JOB_GET_METHOD_NAME, create=True + _TEST_API_CLIENT, _TEST_JOB_GET_METHOD_NAME, create=True ) as fake_job_getter_mock: fake_job_getter_mock.return_value = {} yield fake_job_getter_mock @@ -161,19 +175,22 @@ def fake_job_getter_mock(): @pytest.fixture def fake_job_cancel_mock(): with patch.object( - job_service_client.JobServiceClient, _TEST_JOB_CANCEL_METHOD_NAME, create=True + _TEST_API_CLIENT, _TEST_JOB_CANCEL_METHOD_NAME, create=True ) as fake_job_cancel_mock: yield fake_job_cancel_mock +@pytest.mark.usefixtures("google_auth_mock") class TestJob: class FakeJob(jobs._Job): - _job_type = "fake-job" - _resource_noun = "fakeJobs" + _job_type = "custom-job" + _resource_noun = "customJobs" _getter_method = _TEST_JOB_GET_METHOD_NAME _list_method = _TEST_JOB_LIST_METHOD_NAME _cancel_method = _TEST_JOB_CANCEL_METHOD_NAME _delete_method = _TEST_JOB_DELETE_METHOD_NAME + _parse_resource_name_method = "parse_custom_job_path" + _format_resource_name_method = "custom_job_path" resource_name = _TEST_JOB_RESOURCE_NAME def setup_method(self): @@ -205,20 +222,25 @@ def test_cancel_mock_job(self, fake_job_cancel_mock): @pytest.fixture def get_batch_prediction_job_mock(): with patch.object( - job_service_client.JobServiceClient, "get_batch_prediction_job" + _TEST_API_CLIENT, "get_batch_prediction_job" ) as get_batch_prediction_job_mock: get_batch_prediction_job_mock.side_effect = [ - gca_batch_prediction_job.BatchPredictionJob( + gca_batch_prediction_job_compat.BatchPredictionJob( + name=_TEST_BATCH_PREDICTION_JOB_NAME, + display_name=_TEST_DISPLAY_NAME, + state=_TEST_JOB_STATE_PENDING, + ), + gca_batch_prediction_job_compat.BatchPredictionJob( name=_TEST_BATCH_PREDICTION_JOB_NAME, display_name=_TEST_DISPLAY_NAME, state=_TEST_JOB_STATE_RUNNING, ), - gca_batch_prediction_job.BatchPredictionJob( + gca_batch_prediction_job_compat.BatchPredictionJob( name=_TEST_BATCH_PREDICTION_JOB_NAME, display_name=_TEST_DISPLAY_NAME, state=_TEST_JOB_STATE_SUCCESS, ), - gca_batch_prediction_job.BatchPredictionJob( + gca_batch_prediction_job_compat.BatchPredictionJob( name=_TEST_BATCH_PREDICTION_JOB_NAME, display_name=_TEST_DISPLAY_NAME, state=_TEST_JOB_STATE_SUCCESS, @@ -230,25 +252,38 @@ def get_batch_prediction_job_mock(): @pytest.fixture def create_batch_prediction_job_mock(): with mock.patch.object( - job_service_client.JobServiceClient, "create_batch_prediction_job" + _TEST_API_CLIENT, "create_batch_prediction_job" ) as create_batch_prediction_job_mock: - create_batch_prediction_job_mock.return_value = gca_batch_prediction_job.BatchPredictionJob( - name=_TEST_BATCH_PREDICTION_JOB_NAME, - display_name=_TEST_DISPLAY_NAME, - state=_TEST_JOB_STATE_SUCCESS, + create_batch_prediction_job_mock.return_value = ( + gca_batch_prediction_job_compat.BatchPredictionJob( + name=_TEST_BATCH_PREDICTION_JOB_NAME, + display_name=_TEST_DISPLAY_NAME, + state=_TEST_JOB_STATE_SUCCESS, + ) ) yield create_batch_prediction_job_mock +@pytest.fixture +def create_batch_prediction_job_mock_fail(): + with mock.patch.object( + _TEST_API_CLIENT, "create_batch_prediction_job" + ) as create_batch_prediction_job_mock: + create_batch_prediction_job_mock.side_effect = RuntimeError("Mock fail") + yield create_batch_prediction_job_mock + + @pytest.fixture def create_batch_prediction_job_with_explanations_mock(): with mock.patch.object( - job_service_client_v1beta1.JobServiceClient, "create_batch_prediction_job" + _TEST_API_CLIENT, "create_batch_prediction_job" ) as create_batch_prediction_job_mock: - create_batch_prediction_job_mock.return_value = gca_batch_prediction_job_v1beta1.BatchPredictionJob( - name=_TEST_BATCH_PREDICTION_JOB_NAME, - display_name=_TEST_DISPLAY_NAME, - state=_TEST_JOB_STATE_SUCCESS, + create_batch_prediction_job_mock.return_value = ( + gca_batch_prediction_job_compat.BatchPredictionJob( + name=_TEST_BATCH_PREDICTION_JOB_NAME, + display_name=_TEST_DISPLAY_NAME, + state=_TEST_JOB_STATE_SUCCESS, + ) ) yield create_batch_prediction_job_mock @@ -256,16 +291,18 @@ def create_batch_prediction_job_with_explanations_mock(): @pytest.fixture def get_batch_prediction_job_gcs_output_mock(): with patch.object( - job_service_client.JobServiceClient, "get_batch_prediction_job" + _TEST_API_CLIENT, "get_batch_prediction_job" ) as get_batch_prediction_job_mock: - get_batch_prediction_job_mock.return_value = gca_batch_prediction_job.BatchPredictionJob( - name=_TEST_BATCH_PREDICTION_JOB_NAME, - display_name=_TEST_DISPLAY_NAME, - model=_TEST_MODEL_NAME, - input_config=_TEST_GCS_INPUT_CONFIG, - output_config=_TEST_GCS_OUTPUT_CONFIG, - output_info=_TEST_GCS_OUTPUT_INFO, - state=_TEST_JOB_STATE_SUCCESS, + get_batch_prediction_job_mock.return_value = ( + gca_batch_prediction_job_compat.BatchPredictionJob( + name=_TEST_BATCH_PREDICTION_JOB_NAME, + display_name=_TEST_DISPLAY_NAME, + model=_TEST_MODEL_NAME, + input_config=_TEST_GCS_INPUT_CONFIG, + output_config=_TEST_GCS_OUTPUT_CONFIG, + output_info=_TEST_GCS_OUTPUT_INFO, + state=_TEST_JOB_STATE_SUCCESS, + ) ) yield get_batch_prediction_job_mock @@ -273,16 +310,37 @@ def get_batch_prediction_job_gcs_output_mock(): @pytest.fixture def get_batch_prediction_job_bq_output_mock(): with patch.object( - job_service_client.JobServiceClient, "get_batch_prediction_job" + _TEST_API_CLIENT, "get_batch_prediction_job" ) as get_batch_prediction_job_mock: - get_batch_prediction_job_mock.return_value = gca_batch_prediction_job.BatchPredictionJob( - name=_TEST_BATCH_PREDICTION_JOB_NAME, - display_name=_TEST_DISPLAY_NAME, - model=_TEST_MODEL_NAME, - input_config=_TEST_GCS_INPUT_CONFIG, - output_config=_TEST_BQ_OUTPUT_CONFIG, - output_info=_TEST_BQ_OUTPUT_INFO, - state=_TEST_JOB_STATE_SUCCESS, + get_batch_prediction_job_mock.return_value = ( + gca_batch_prediction_job_compat.BatchPredictionJob( + name=_TEST_BATCH_PREDICTION_JOB_NAME, + display_name=_TEST_DISPLAY_NAME, + model=_TEST_MODEL_NAME, + input_config=_TEST_GCS_INPUT_CONFIG, + output_config=_TEST_BQ_OUTPUT_CONFIG, + output_info=_TEST_BQ_OUTPUT_INFO, + state=_TEST_JOB_STATE_SUCCESS, + ) + ) + yield get_batch_prediction_job_mock + + +@pytest.fixture +def get_batch_prediction_job_incomplete_bq_output_mock(): + with patch.object( + _TEST_API_CLIENT, "get_batch_prediction_job" + ) as get_batch_prediction_job_mock: + get_batch_prediction_job_mock.return_value = ( + gca_batch_prediction_job_compat.BatchPredictionJob( + name=_TEST_BATCH_PREDICTION_JOB_NAME, + display_name=_TEST_DISPLAY_NAME, + model=_TEST_MODEL_NAME, + input_config=_TEST_GCS_INPUT_CONFIG, + output_config=_TEST_BQ_OUTPUT_CONFIG, + output_info=_TEST_BQ_OUTPUT_INFO_INCOMPLETE, + state=_TEST_JOB_STATE_SUCCESS, + ) ) yield get_batch_prediction_job_mock @@ -290,16 +348,18 @@ def get_batch_prediction_job_bq_output_mock(): @pytest.fixture def get_batch_prediction_job_empty_output_mock(): with patch.object( - job_service_client.JobServiceClient, "get_batch_prediction_job" + _TEST_API_CLIENT, "get_batch_prediction_job" ) as get_batch_prediction_job_mock: - get_batch_prediction_job_mock.return_value = gca_batch_prediction_job.BatchPredictionJob( - name=_TEST_BATCH_PREDICTION_JOB_NAME, - display_name=_TEST_DISPLAY_NAME, - model=_TEST_MODEL_NAME, - input_config=_TEST_GCS_INPUT_CONFIG, - output_config=_TEST_BQ_OUTPUT_CONFIG, - output_info=_TEST_EMPTY_OUTPUT_INFO, - state=_TEST_JOB_STATE_SUCCESS, + get_batch_prediction_job_mock.return_value = ( + gca_batch_prediction_job_compat.BatchPredictionJob( + name=_TEST_BATCH_PREDICTION_JOB_NAME, + display_name=_TEST_DISPLAY_NAME, + model=_TEST_MODEL_NAME, + input_config=_TEST_GCS_INPUT_CONFIG, + output_config=_TEST_BQ_OUTPUT_CONFIG, + output_info=_TEST_EMPTY_OUTPUT_INFO, + state=_TEST_JOB_STATE_SUCCESS, + ) ) yield get_batch_prediction_job_mock @@ -307,16 +367,18 @@ def get_batch_prediction_job_empty_output_mock(): @pytest.fixture def get_batch_prediction_job_running_bq_output_mock(): with patch.object( - job_service_client.JobServiceClient, "get_batch_prediction_job" + _TEST_API_CLIENT, "get_batch_prediction_job" ) as get_batch_prediction_job_mock: - get_batch_prediction_job_mock.return_value = gca_batch_prediction_job.BatchPredictionJob( - name=_TEST_BATCH_PREDICTION_JOB_NAME, - display_name=_TEST_DISPLAY_NAME, - model=_TEST_MODEL_NAME, - input_config=_TEST_GCS_INPUT_CONFIG, - output_config=_TEST_BQ_OUTPUT_CONFIG, - output_info=_TEST_BQ_OUTPUT_INFO, - state=_TEST_JOB_STATE_RUNNING, + get_batch_prediction_job_mock.return_value = ( + gca_batch_prediction_job_compat.BatchPredictionJob( + name=_TEST_BATCH_PREDICTION_JOB_NAME, + display_name=_TEST_DISPLAY_NAME, + model=_TEST_MODEL_NAME, + input_config=_TEST_GCS_INPUT_CONFIG, + output_config=_TEST_BQ_OUTPUT_CONFIG, + output_info=_TEST_BQ_OUTPUT_INFO, + state=_TEST_JOB_STATE_RUNNING, + ) ) yield get_batch_prediction_job_mock @@ -335,6 +397,7 @@ def bq_list_rows_mock(): yield list_rows_mock +@pytest.mark.usefixtures("google_auth_mock") class TestBatchPredictionJob: def setup_method(self): reload(initializer) @@ -348,7 +411,7 @@ def test_init_batch_prediction_job(self, get_batch_prediction_job_mock): batch_prediction_job_name=_TEST_BATCH_PREDICTION_JOB_NAME ) get_batch_prediction_job_mock.assert_called_once_with( - name=_TEST_BATCH_PREDICTION_JOB_NAME + name=_TEST_BATCH_PREDICTION_JOB_NAME, retry=base._DEFAULT_RETRY ) def test_batch_prediction_job_status(self, get_batch_prediction_job_mock): @@ -360,12 +423,20 @@ def test_batch_prediction_job_status(self, get_batch_prediction_job_mock): bp_job_state = bp.state assert get_batch_prediction_job_mock.call_count == 2 - assert bp_job_state == _TEST_JOB_STATE_SUCCESS + assert bp_job_state == _TEST_JOB_STATE_RUNNING get_batch_prediction_job_mock.assert_called_with( - name=_TEST_BATCH_PREDICTION_JOB_NAME + name=_TEST_BATCH_PREDICTION_JOB_NAME, retry=base._DEFAULT_RETRY + ) + + def test_batch_prediction_job_done_get(self, get_batch_prediction_job_mock): + bp = jobs.BatchPredictionJob( + batch_prediction_job_name=_TEST_BATCH_PREDICTION_JOB_NAME ) + assert bp.done() is False + assert get_batch_prediction_job_mock.call_count == 2 + @pytest.mark.usefixtures("get_batch_prediction_job_gcs_output_mock") def test_batch_prediction_iter_dirs_gcs(self, storage_list_blobs_mock): bp = jobs.BatchPredictionJob( @@ -388,7 +459,22 @@ def test_batch_prediction_iter_dirs_bq(self, bq_list_rows_mock): bp.iter_outputs() bq_list_rows_mock.assert_called_once_with( - table=f"{_TEST_BQ_DATASET_ID}.predictions", max_results=_TEST_BQ_MAX_RESULTS + table=f"{_TEST_BQ_PROJECT_ID}.{_TEST_BQ_DATASET_ID}.{_TEST_BQ_TABLE_NAME}", + max_results=_TEST_BQ_MAX_RESULTS, + ) + + @pytest.mark.usefixtures("get_batch_prediction_job_incomplete_bq_output_mock") + def test_batch_prediction_iter_dirs_bq_raises_on_empty(self, bq_list_rows_mock): + bp = jobs.BatchPredictionJob( + batch_prediction_job_name=_TEST_BATCH_PREDICTION_JOB_NAME + ) + with pytest.raises(RuntimeError) as e: + bp.iter_outputs() + assert e.match( + regexp=( + "A BigQuery table with predictions was not found," + " this might be due to errors. Visit http" + ) ) @pytest.mark.usefixtures("get_batch_prediction_job_running_bq_output_mock") @@ -414,6 +500,8 @@ def test_batch_prediction_iter_dirs_invalid_output_info(self): ) bp.iter_outputs() + @mock.patch.object(jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) @pytest.mark.usefixtures("get_batch_prediction_job_mock") def test_batch_predict_gcs_source_and_dest( @@ -428,21 +516,25 @@ def test_batch_predict_gcs_source_and_dest( gcs_source=_TEST_BATCH_PREDICTION_GCS_SOURCE, gcs_destination_prefix=_TEST_BATCH_PREDICTION_GCS_DEST_PREFIX, sync=sync, + create_request_timeout=None, ) - if not sync: - batch_prediction_job.wait() + batch_prediction_job.wait_for_resource_creation() + + batch_prediction_job.wait() # Construct expected request - expected_gapic_batch_prediction_job = gca_batch_prediction_job.BatchPredictionJob( + expected_gapic_batch_prediction_job = gca_batch_prediction_job_compat.BatchPredictionJob( display_name=_TEST_BATCH_PREDICTION_JOB_DISPLAY_NAME, model=_TEST_MODEL_NAME, - input_config=gca_batch_prediction_job.BatchPredictionJob.InputConfig( + input_config=gca_batch_prediction_job_compat.BatchPredictionJob.InputConfig( instances_format="jsonl", - gcs_source=gca_io.GcsSource(uris=[_TEST_BATCH_PREDICTION_GCS_SOURCE]), + gcs_source=gca_io_compat.GcsSource( + uris=[_TEST_BATCH_PREDICTION_GCS_SOURCE] + ), ), - output_config=gca_batch_prediction_job.BatchPredictionJob.OutputConfig( - gcs_destination=gca_io.GcsDestination( + output_config=gca_batch_prediction_job_compat.BatchPredictionJob.OutputConfig( + gcs_destination=gca_io_compat.GcsDestination( output_uri_prefix=_TEST_BATCH_PREDICTION_GCS_DEST_PREFIX ), predictions_format="jsonl", @@ -452,8 +544,127 @@ def test_batch_predict_gcs_source_and_dest( create_batch_prediction_job_mock.assert_called_once_with( parent=_TEST_PARENT, batch_prediction_job=expected_gapic_batch_prediction_job, + timeout=None, ) + @mock.patch.object(jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + @pytest.mark.usefixtures("get_batch_prediction_job_mock") + def test_batch_predict_gcs_source_and_dest_with_timeout( + self, create_batch_prediction_job_mock, sync + ): + aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) + + # Make SDK batch_predict method call + batch_prediction_job = jobs.BatchPredictionJob.create( + model_name=_TEST_MODEL_NAME, + job_display_name=_TEST_BATCH_PREDICTION_JOB_DISPLAY_NAME, + gcs_source=_TEST_BATCH_PREDICTION_GCS_SOURCE, + gcs_destination_prefix=_TEST_BATCH_PREDICTION_GCS_DEST_PREFIX, + sync=sync, + create_request_timeout=180.0, + ) + + batch_prediction_job.wait_for_resource_creation() + + batch_prediction_job.wait() + + # Construct expected request + expected_gapic_batch_prediction_job = gca_batch_prediction_job_compat.BatchPredictionJob( + display_name=_TEST_BATCH_PREDICTION_JOB_DISPLAY_NAME, + model=_TEST_MODEL_NAME, + input_config=gca_batch_prediction_job_compat.BatchPredictionJob.InputConfig( + instances_format="jsonl", + gcs_source=gca_io_compat.GcsSource( + uris=[_TEST_BATCH_PREDICTION_GCS_SOURCE] + ), + ), + output_config=gca_batch_prediction_job_compat.BatchPredictionJob.OutputConfig( + gcs_destination=gca_io_compat.GcsDestination( + output_uri_prefix=_TEST_BATCH_PREDICTION_GCS_DEST_PREFIX + ), + predictions_format="jsonl", + ), + ) + + create_batch_prediction_job_mock.assert_called_once_with( + parent=_TEST_PARENT, + batch_prediction_job=expected_gapic_batch_prediction_job, + timeout=180.0, + ) + + @mock.patch.object(jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + @pytest.mark.usefixtures("get_batch_prediction_job_mock") + def test_batch_predict_gcs_source_and_dest_with_timeout_not_explicitly_set( + self, create_batch_prediction_job_mock, sync + ): + aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) + + # Make SDK batch_predict method call + batch_prediction_job = jobs.BatchPredictionJob.create( + model_name=_TEST_MODEL_NAME, + job_display_name=_TEST_BATCH_PREDICTION_JOB_DISPLAY_NAME, + gcs_source=_TEST_BATCH_PREDICTION_GCS_SOURCE, + gcs_destination_prefix=_TEST_BATCH_PREDICTION_GCS_DEST_PREFIX, + sync=sync, + ) + + batch_prediction_job.wait_for_resource_creation() + + batch_prediction_job.wait() + + # Construct expected request + expected_gapic_batch_prediction_job = gca_batch_prediction_job_compat.BatchPredictionJob( + display_name=_TEST_BATCH_PREDICTION_JOB_DISPLAY_NAME, + model=_TEST_MODEL_NAME, + input_config=gca_batch_prediction_job_compat.BatchPredictionJob.InputConfig( + instances_format="jsonl", + gcs_source=gca_io_compat.GcsSource( + uris=[_TEST_BATCH_PREDICTION_GCS_SOURCE] + ), + ), + output_config=gca_batch_prediction_job_compat.BatchPredictionJob.OutputConfig( + gcs_destination=gca_io_compat.GcsDestination( + output_uri_prefix=_TEST_BATCH_PREDICTION_GCS_DEST_PREFIX + ), + predictions_format="jsonl", + ), + ) + + create_batch_prediction_job_mock.assert_called_once_with( + parent=_TEST_PARENT, + batch_prediction_job=expected_gapic_batch_prediction_job, + timeout=None, + ) + + @mock.patch.object(jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.usefixtures("get_batch_prediction_job_mock") + def test_batch_predict_job_done_create(self, create_batch_prediction_job_mock): + aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) + + # Make SDK batch_predict method call + batch_prediction_job = jobs.BatchPredictionJob.create( + model_name=_TEST_MODEL_NAME, + job_display_name=_TEST_BATCH_PREDICTION_JOB_DISPLAY_NAME, + gcs_source=_TEST_BATCH_PREDICTION_GCS_SOURCE, + gcs_destination_prefix=_TEST_BATCH_PREDICTION_GCS_DEST_PREFIX, + sync=False, + ) + + batch_prediction_job.wait_for_resource_creation() + + assert batch_prediction_job.done() is False + + batch_prediction_job.wait() + + assert batch_prediction_job.done() is True + + @mock.patch.object(jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) @pytest.mark.usefixtures("get_batch_prediction_job_mock") def test_batch_predict_gcs_source_bq_dest( @@ -467,21 +678,30 @@ def test_batch_predict_gcs_source_bq_dest( gcs_source=_TEST_BATCH_PREDICTION_GCS_SOURCE, bigquery_destination_prefix=_TEST_BATCH_PREDICTION_BQ_PREFIX, sync=sync, + create_request_timeout=None, ) - if not sync: - batch_prediction_job.wait() + batch_prediction_job.wait_for_resource_creation() + + batch_prediction_job.wait() + + assert ( + batch_prediction_job.output_info + == gca_batch_prediction_job_compat.BatchPredictionJob.OutputInfo() + ) # Construct expected request - expected_gapic_batch_prediction_job = gca_batch_prediction_job.BatchPredictionJob( + expected_gapic_batch_prediction_job = gca_batch_prediction_job_compat.BatchPredictionJob( display_name=_TEST_BATCH_PREDICTION_JOB_DISPLAY_NAME, model=_TEST_MODEL_NAME, - input_config=gca_batch_prediction_job.BatchPredictionJob.InputConfig( + input_config=gca_batch_prediction_job_compat.BatchPredictionJob.InputConfig( instances_format="jsonl", - gcs_source=gca_io.GcsSource(uris=[_TEST_BATCH_PREDICTION_GCS_SOURCE]), + gcs_source=gca_io_compat.GcsSource( + uris=[_TEST_BATCH_PREDICTION_GCS_SOURCE] + ), ), - output_config=gca_batch_prediction_job.BatchPredictionJob.OutputConfig( - bigquery_destination=gca_io.BigQueryDestination( + output_config=gca_batch_prediction_job_compat.BatchPredictionJob.OutputConfig( + bigquery_destination=gca_io_compat.BigQueryDestination( output_uri=_TEST_BATCH_PREDICTION_BQ_DEST_PREFIX_WITH_PROTOCOL ), predictions_format="bigquery", @@ -491,8 +711,11 @@ def test_batch_predict_gcs_source_bq_dest( create_batch_prediction_job_mock.assert_called_once_with( parent=_TEST_PARENT, batch_prediction_job=expected_gapic_batch_prediction_job, + timeout=None, ) + @mock.patch.object(jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) @pytest.mark.usefixtures("get_batch_prediction_job_mock") def test_batch_predict_with_all_args( @@ -519,29 +742,32 @@ def test_batch_predict_with_all_args( labels=_TEST_LABEL, credentials=creds, sync=sync, + create_request_timeout=None, + batch_size=_TEST_BATCH_SIZE, ) - if not sync: - batch_prediction_job.wait() + batch_prediction_job.wait_for_resource_creation() + + batch_prediction_job.wait() # Construct expected request - expected_gapic_batch_prediction_job = gca_batch_prediction_job_v1beta1.BatchPredictionJob( + expected_gapic_batch_prediction_job = gca_batch_prediction_job_compat.BatchPredictionJob( display_name=_TEST_BATCH_PREDICTION_JOB_DISPLAY_NAME, model=_TEST_MODEL_NAME, - input_config=gca_batch_prediction_job_v1beta1.BatchPredictionJob.InputConfig( + input_config=gca_batch_prediction_job_compat.BatchPredictionJob.InputConfig( instances_format="jsonl", - gcs_source=gca_io_v1beta1.GcsSource( + gcs_source=gca_io_compat.GcsSource( uris=[_TEST_BATCH_PREDICTION_GCS_SOURCE] ), ), - output_config=gca_batch_prediction_job_v1beta1.BatchPredictionJob.OutputConfig( - gcs_destination=gca_io_v1beta1.GcsDestination( + output_config=gca_batch_prediction_job_compat.BatchPredictionJob.OutputConfig( + gcs_destination=gca_io_compat.GcsDestination( output_uri_prefix=_TEST_BATCH_PREDICTION_GCS_DEST_PREFIX ), predictions_format="csv", ), - dedicated_resources=gca_machine_resources_v1beta1.BatchDedicatedResources( - machine_spec=gca_machine_resources_v1beta1.MachineSpec( + dedicated_resources=gca_machine_resources_compat.BatchDedicatedResources( + machine_spec=gca_machine_resources_compat.MachineSpec( machine_type=_TEST_MACHINE_TYPE, accelerator_type=_TEST_ACCELERATOR_TYPE, accelerator_count=_TEST_ACCELERATOR_COUNT, @@ -549,8 +775,11 @@ def test_batch_predict_with_all_args( starting_replica_count=_TEST_STARTING_REPLICA_COUNT, max_replica_count=_TEST_MAX_REPLICA_COUNT, ), + manual_batch_tuning_parameters=gca_manual_batch_tuning_parameters_compat.ManualBatchTuningParameters( + batch_size=_TEST_BATCH_SIZE + ), generate_explanation=True, - explanation_spec=gca_explanation_v1beta1.ExplanationSpec( + explanation_spec=gca_explanation_compat.ExplanationSpec( metadata=_TEST_EXPLANATION_METADATA, parameters=_TEST_EXPLANATION_PARAMETERS, ), @@ -560,6 +789,47 @@ def test_batch_predict_with_all_args( create_batch_prediction_job_with_explanations_mock.assert_called_once_with( parent=f"projects/{_TEST_PROJECT}/locations/{_TEST_LOCATION}", batch_prediction_job=expected_gapic_batch_prediction_job, + timeout=None, + ) + + @pytest.mark.usefixtures("create_batch_prediction_job_mock_fail") + def test_batch_predict_create_fails(self): + aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) + + batch_prediction_job = jobs.BatchPredictionJob.create( + model_name=_TEST_MODEL_NAME, + job_display_name=_TEST_BATCH_PREDICTION_JOB_DISPLAY_NAME, + gcs_source=_TEST_BATCH_PREDICTION_GCS_SOURCE, + bigquery_destination_prefix=_TEST_BATCH_PREDICTION_BQ_PREFIX, + sync=False, + ) + + with pytest.raises(RuntimeError) as e: + batch_prediction_job.wait() + assert e.match(regexp=r"Mock fail") + + with pytest.raises(RuntimeError) as e: + batch_prediction_job.output_info + assert e.match( + regexp=r"BatchPredictionJob resource has not been created. Resource failed with: Mock fail" + ) + + with pytest.raises(RuntimeError) as e: + batch_prediction_job.partial_failures + assert e.match( + regexp=r"BatchPredictionJob resource has not been created. Resource failed with: Mock fail" + ) + + with pytest.raises(RuntimeError) as e: + batch_prediction_job.completion_stats + assert e.match( + regexp=r"BatchPredictionJob resource has not been created. Resource failed with: Mock fail" + ) + + with pytest.raises(RuntimeError) as e: + batch_prediction_job.iter_outputs() + assert e.match( + regexp=r"BatchPredictionJob resource has not been created. Resource failed with: Mock fail" ) @pytest.mark.usefixtures("get_batch_prediction_job_mock") diff --git a/tests/unit/aiplatform/test_logging.py b/tests/unit/aiplatform/test_logging.py new file mode 100644 index 0000000000..e18cbe623f --- /dev/null +++ b/tests/unit/aiplatform/test_logging.py @@ -0,0 +1,51 @@ +# -*- 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 google.cloud.aiplatform import base +import logging + + +class TestLogging: + def test_no_root_logging_handler_override(self, caplog): + # Users should be able to control the root logger in their apps + # The aiplatform module import should not override their root logger config + caplog.set_level(logging.DEBUG) + + logging.debug("Debug level") + logging.info("Info level") + logging.critical("Critical level") + + assert "Debug level\n" in caplog.text + assert "Info level\n" in caplog.text + assert "Critical level\n" in caplog.text + + def test_log_level_coexistance(self, caplog): + # The aiplatform module and the root logger can have different log levels. + aip_logger = base.Logger(__name__) + + caplog.set_level(logging.DEBUG) + + logging.debug("This should exist") + logging.info("This should too") + + aip_logger.info("This should also exist") + aip_logger.debug("This should NOT exist") + + assert "This should exist\n" in caplog.text + assert "This should too\n" in caplog.text + assert "This should also exist\n" in caplog.text + assert "This should NOT exist\n" not in caplog.text diff --git a/tests/unit/aiplatform/test_matching_engine_index.py b/tests/unit/aiplatform/test_matching_engine_index.py new file mode 100644 index 0000000000..78e3a608a9 --- /dev/null +++ b/tests/unit/aiplatform/test_matching_engine_index.py @@ -0,0 +1,357 @@ +# -*- coding: utf-8 -*- + +# Copyright 2022 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. +# + +import pytest +import uuid + +from unittest import mock +from importlib import reload +from unittest.mock import patch + +from google.api_core import operation +from google.protobuf import field_mask_pb2 + +from google.cloud import aiplatform +from google.cloud.aiplatform import base +from google.cloud.aiplatform import initializer +from google.cloud.aiplatform.compat.services import ( + index_service_client, +) + +from google.cloud.aiplatform.compat.types import index as gca_index + +# project +_TEST_PROJECT = "test-project" +_TEST_LOCATION = "us-central1" +_TEST_PARENT = f"projects/{_TEST_PROJECT}/locations/{_TEST_LOCATION}" + + +# index +_TEST_INDEX_ID = "index_id" +_TEST_INDEX_NAME = f"{_TEST_PARENT}/indexes/{_TEST_INDEX_ID}" +_TEST_INDEX_DISPLAY_NAME = "index_display_name" +_TEST_CONTENTS_DELTA_URI = "gs://contents" +_TEST_INDEX_DISTANCE_MEASURE_TYPE = "SQUARED_L2_DISTANCE" + +_TEST_CONTENTS_DELTA_URI_UPDATE = "gs://contents_update" +_TEST_IS_COMPLETE_OVERWRITE_UPDATE = True + +_TEST_INDEX_CONFIG_DIMENSIONS = 100 +_TEST_INDEX_APPROXIMATE_NEIGHBORS_COUNT = 150 +_TEST_LEAF_NODE_EMBEDDING_COUNT = 123 +_TEST_LEAF_NODES_TO_SEARCH_PERCENT = 50 + +_TEST_INDEX_DESCRIPTION = "index_description" + + +_TEST_LABELS = {"my_key": "my_value"} +_TEST_DISPLAY_NAME_UPDATE = "my new display name" +_TEST_DESCRIPTION_UPDATE = "my description update" +_TEST_LABELS_UPDATE = {"my_key_update": "my_value_update"} + +# request_metadata +_TEST_REQUEST_METADATA = () + +# Lists +_TEST_INDEX_LIST = [ + gca_index.Index( + name=_TEST_INDEX_NAME, + display_name=_TEST_INDEX_DISPLAY_NAME, + description=_TEST_INDEX_DESCRIPTION, + ), + gca_index.Index( + name=_TEST_INDEX_NAME, + display_name=_TEST_INDEX_DISPLAY_NAME, + description=_TEST_INDEX_DESCRIPTION, + ), + gca_index.Index( + name=_TEST_INDEX_NAME, + display_name=_TEST_INDEX_DISPLAY_NAME, + description=_TEST_INDEX_DESCRIPTION, + ), +] + + +def uuid_mock(): + return uuid.UUID(int=1) + + +# All Index Mocks +@pytest.fixture +def get_index_mock(): + with patch.object( + index_service_client.IndexServiceClient, "get_index" + ) as get_index_mock: + get_index_mock.return_value = gca_index.Index( + name=_TEST_INDEX_NAME, + display_name=_TEST_INDEX_DISPLAY_NAME, + description=_TEST_INDEX_DESCRIPTION, + ) + yield get_index_mock + + +@pytest.fixture +def update_index_metadata_mock(): + with patch.object( + index_service_client.IndexServiceClient, "update_index" + ) as update_index_mock: + index_lro_mock = mock.Mock(operation.Operation) + index_lro_mock.result.return_value = gca_index.Index( + name=_TEST_INDEX_NAME, + display_name=_TEST_DISPLAY_NAME_UPDATE, + description=_TEST_DESCRIPTION_UPDATE, + labels=_TEST_LABELS_UPDATE, + ) + update_index_mock.return_value = index_lro_mock + yield update_index_mock + + +@pytest.fixture +def update_index_embeddings_mock(): + with patch.object( + index_service_client.IndexServiceClient, "update_index" + ) as update_index_mock: + index_lro_mock = mock.Mock(operation.Operation) + index_lro_mock.result.return_value = gca_index.Index( + name=_TEST_INDEX_NAME, + ) + update_index_mock.return_value = index_lro_mock + yield update_index_mock + + +@pytest.fixture +def list_indexes_mock(): + with patch.object( + index_service_client.IndexServiceClient, "list_indexes" + ) as list_indexes_mock: + list_indexes_mock.return_value = _TEST_INDEX_LIST + yield list_indexes_mock + + +@pytest.fixture +def delete_index_mock(): + with mock.patch.object( + index_service_client.IndexServiceClient, "delete_index" + ) as delete_index_mock: + delete_index_lro_mock = mock.Mock(operation.Operation) + delete_index_mock.return_value = delete_index_lro_mock + yield delete_index_mock + + +@pytest.fixture +def create_index_mock(): + with patch.object( + index_service_client.IndexServiceClient, "create_index" + ) as create_index_mock: + create_index_lro_mock = mock.Mock(operation.Operation) + create_index_lro_mock.result.return_value = gca_index.Index( + name=_TEST_INDEX_NAME, + display_name=_TEST_INDEX_DISPLAY_NAME, + description=_TEST_INDEX_DESCRIPTION, + ) + create_index_mock.return_value = create_index_lro_mock + yield create_index_mock + + +@pytest.mark.usefixtures("google_auth_mock") +class TestMatchingEngineIndex: + def setup_method(self): + reload(initializer) + reload(aiplatform) + + def teardown_method(self): + initializer.global_pool.shutdown(wait=True) + + @pytest.mark.parametrize("index_name", [_TEST_INDEX_ID, _TEST_INDEX_NAME]) + def test_init_index(self, index_name, get_index_mock): + aiplatform.init(project=_TEST_PROJECT) + + my_index = aiplatform.MatchingEngineIndex(index_name=index_name) + + get_index_mock.assert_called_once_with( + name=my_index.resource_name, retry=base._DEFAULT_RETRY + ) + + @pytest.mark.usefixtures("get_index_mock") + def test_update_index_metadata(self, update_index_metadata_mock): + aiplatform.init(project=_TEST_PROJECT) + + my_index = aiplatform.MatchingEngineIndex(index_name=_TEST_INDEX_ID) + updated_index = my_index.update_metadata( + display_name=_TEST_DISPLAY_NAME_UPDATE, + description=_TEST_DESCRIPTION_UPDATE, + labels=_TEST_LABELS_UPDATE, + ) + + expected = gca_index.Index( + name=_TEST_INDEX_NAME, + display_name=_TEST_DISPLAY_NAME_UPDATE, + description=_TEST_DESCRIPTION_UPDATE, + labels=_TEST_LABELS_UPDATE, + ) + + update_index_metadata_mock.assert_called_once_with( + index=expected, + update_mask=field_mask_pb2.FieldMask( + paths=["labels", "display_name", "description"] + ), + metadata=_TEST_REQUEST_METADATA, + ) + + assert updated_index.gca_resource == expected + + @pytest.mark.usefixtures("get_index_mock") + def test_update_index_embeddings(self, update_index_embeddings_mock): + aiplatform.init(project=_TEST_PROJECT) + + my_index = aiplatform.MatchingEngineIndex(index_name=_TEST_INDEX_ID) + updated_index = my_index.update_embeddings( + contents_delta_uri=_TEST_CONTENTS_DELTA_URI_UPDATE, + is_complete_overwrite=_TEST_IS_COMPLETE_OVERWRITE_UPDATE, + ) + + expected = gca_index.Index( + name=_TEST_INDEX_NAME, + metadata={ + "contentsDeltaUri": _TEST_CONTENTS_DELTA_URI_UPDATE, + "isCompleteOverwrite": _TEST_IS_COMPLETE_OVERWRITE_UPDATE, + }, + ) + + update_index_embeddings_mock.assert_called_once_with( + index=expected, + update_mask=field_mask_pb2.FieldMask(paths=["metadata"]), + metadata=_TEST_REQUEST_METADATA, + ) + + # The service only returns the name of the Index + assert updated_index.gca_resource == gca_index.Index(name=_TEST_INDEX_NAME) + + def test_list_indexes(self, list_indexes_mock): + aiplatform.init(project=_TEST_PROJECT) + + my_indexes_list = aiplatform.MatchingEngineIndex.list() + + list_indexes_mock.assert_called_once_with( + request={"parent": _TEST_PARENT, "filter": None} + ) + assert len(my_indexes_list) == len(_TEST_INDEX_LIST) + for my_index in my_indexes_list: + assert type(my_index) == aiplatform.MatchingEngineIndex + + @pytest.mark.parametrize("sync", [True, False]) + @pytest.mark.usefixtures("get_index_mock") + def test_delete_index(self, delete_index_mock, sync): + aiplatform.init(project=_TEST_PROJECT) + + my_index = aiplatform.MatchingEngineIndex(index_name=_TEST_INDEX_ID) + my_index.delete(sync=sync) + + if not sync: + my_index.wait() + + delete_index_mock.assert_called_once_with(name=my_index.resource_name) + + @pytest.mark.usefixtures("get_index_mock") + @pytest.mark.parametrize("sync", [True, False]) + def test_create_tree_ah_index(self, create_index_mock, sync): + aiplatform.init(project=_TEST_PROJECT) + + my_index = aiplatform.MatchingEngineIndex.create_tree_ah_index( + display_name=_TEST_INDEX_DISPLAY_NAME, + contents_delta_uri=_TEST_CONTENTS_DELTA_URI, + dimensions=_TEST_INDEX_CONFIG_DIMENSIONS, + approximate_neighbors_count=_TEST_INDEX_APPROXIMATE_NEIGHBORS_COUNT, + distance_measure_type=_TEST_INDEX_DISTANCE_MEASURE_TYPE, + leaf_node_embedding_count=_TEST_LEAF_NODE_EMBEDDING_COUNT, + leaf_nodes_to_search_percent=_TEST_LEAF_NODES_TO_SEARCH_PERCENT, + description=_TEST_INDEX_DESCRIPTION, + labels=_TEST_LABELS, + sync=sync, + ) + + if not sync: + my_index.wait() + + config = { + "treeAhConfig": { + "leafNodeEmbeddingCount": _TEST_LEAF_NODE_EMBEDDING_COUNT, + "leafNodesToSearchPercent": _TEST_LEAF_NODES_TO_SEARCH_PERCENT, + } + } + + expected = gca_index.Index( + display_name=_TEST_INDEX_DISPLAY_NAME, + metadata={ + "config": { + "algorithmConfig": config, + "dimensions": _TEST_INDEX_CONFIG_DIMENSIONS, + "approximateNeighborsCount": _TEST_INDEX_APPROXIMATE_NEIGHBORS_COUNT, + "distanceMeasureType": _TEST_INDEX_DISTANCE_MEASURE_TYPE, + }, + "contentsDeltaUri": _TEST_CONTENTS_DELTA_URI, + }, + description=_TEST_INDEX_DESCRIPTION, + labels=_TEST_LABELS, + ) + + create_index_mock.assert_called_once_with( + parent=_TEST_PARENT, + index=expected, + metadata=_TEST_REQUEST_METADATA, + ) + + @pytest.mark.usefixtures("get_index_mock") + @pytest.mark.parametrize("sync", [True, False]) + def test_create_brute_force_index(self, create_index_mock, sync): + aiplatform.init(project=_TEST_PROJECT) + + my_index = aiplatform.MatchingEngineIndex.create_brute_force_index( + display_name=_TEST_INDEX_DISPLAY_NAME, + contents_delta_uri=_TEST_CONTENTS_DELTA_URI, + dimensions=_TEST_INDEX_CONFIG_DIMENSIONS, + distance_measure_type=_TEST_INDEX_DISTANCE_MEASURE_TYPE, + description=_TEST_INDEX_DESCRIPTION, + labels=_TEST_LABELS, + sync=sync, + ) + + if not sync: + my_index.wait() + + config = {"bruteForceConfig": {}} + + expected = gca_index.Index( + display_name=_TEST_INDEX_DISPLAY_NAME, + metadata={ + "config": { + "algorithmConfig": config, + "dimensions": _TEST_INDEX_CONFIG_DIMENSIONS, + "approximateNeighborsCount": None, + "distanceMeasureType": _TEST_INDEX_DISTANCE_MEASURE_TYPE, + }, + "contentsDeltaUri": _TEST_CONTENTS_DELTA_URI, + }, + description=_TEST_INDEX_DESCRIPTION, + labels=_TEST_LABELS, + ) + + create_index_mock.assert_called_once_with( + parent=_TEST_PARENT, + index=expected, + metadata=_TEST_REQUEST_METADATA, + ) diff --git a/tests/unit/aiplatform/test_matching_engine_index_endpoint.py b/tests/unit/aiplatform/test_matching_engine_index_endpoint.py new file mode 100644 index 0000000000..58ff16ed56 --- /dev/null +++ b/tests/unit/aiplatform/test_matching_engine_index_endpoint.py @@ -0,0 +1,619 @@ +# -*- coding: utf-8 -*- + +# Copyright 2022 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. +# + +import uuid +from importlib import reload +from unittest import mock +from unittest.mock import patch + +from google.api_core import operation +from google.cloud import aiplatform +from google.cloud.aiplatform import base +from google.cloud.aiplatform import initializer +from google.cloud.aiplatform.compat.types import ( + matching_engine_deployed_index_ref as gca_matching_engine_deployed_index_ref, + index_endpoint as gca_index_endpoint, + index as gca_index, +) + +from google.cloud.aiplatform.compat.services import ( + index_endpoint_service_client, + index_service_client, +) + +from google.protobuf import field_mask_pb2 + +import pytest + +# project +_TEST_PROJECT = "test-project" +_TEST_LOCATION = "us-central1" +_TEST_PARENT = f"projects/{_TEST_PROJECT}/locations/{_TEST_LOCATION}" + +# index +_TEST_INDEX_ID = "index_id" +_TEST_INDEX_NAME = f"{_TEST_PARENT}/indexes/{_TEST_INDEX_ID}" +_TEST_INDEX_DISPLAY_NAME = "index_display_name" + +# index_endpoint +_TEST_INDEX_ENDPOINT_ID = "index_endpoint_id" +_TEST_INDEX_ENDPOINT_NAME = f"{_TEST_PARENT}/indexEndpoints/{_TEST_INDEX_ENDPOINT_ID}" +_TEST_INDEX_ENDPOINT_DISPLAY_NAME = "index_endpoint_display_name" +_TEST_INDEX_ENDPOINT_DESCRIPTION = "index_endpoint_description" +_TEST_INDEX_DESCRIPTION = "index_description" +_TEST_INDEX_ENDPOINT_VPC_NETWORK = "projects/{}/global/networks/{}".format( + "12345", "network" +) + +_TEST_LABELS = {"my_key": "my_value"} +_TEST_DISPLAY_NAME_UPDATE = "my new display name" +_TEST_DESCRIPTION_UPDATE = "my description update" +_TEST_LABELS_UPDATE = {"my_key_update": "my_value_update"} + +# deployment +_TEST_DEPLOYED_INDEX_ID = "deployed_index_id" +_TEST_DEPLOYED_INDEX_DISPLAY_NAME = "deployed_index_display_name" +_TEST_MIN_REPLICA_COUNT = 2 +_TEST_MAX_REPLICA_COUNT = 2 +_TEST_ENABLE_ACCESS_LOGGING = False +_TEST_RESERVED_IP_RANGES = ["vertex-ai-ip-range-1", "vertex-ai-ip-range-2"] +_TEST_DEPLOYMENT_GROUP = "prod" +_TEST_AUTH_CONFIG_AUDIENCES = ["a", "b"] +_TEST_AUTH_CONFIG_ALLOWED_ISSUERS = [ + "service-account-name-1@project-id.iam.gserviceaccount.com", + "service-account-name-2@project-id.iam.gserviceaccount.com", +] + +# deployment_updated +_TEST_MIN_REPLICA_COUNT_UPDATED = 4 +_TEST_MAX_REPLICA_COUNT_UPDATED = 4 + +# request_metadata +_TEST_REQUEST_METADATA = () + +# Lists +_TEST_INDEX_ENDPOINT_LIST = [ + gca_index_endpoint.IndexEndpoint( + name=_TEST_INDEX_ENDPOINT_NAME, + display_name=_TEST_INDEX_ENDPOINT_DISPLAY_NAME, + description=_TEST_INDEX_ENDPOINT_DESCRIPTION, + ), + gca_index_endpoint.IndexEndpoint( + name=_TEST_INDEX_ENDPOINT_NAME, + display_name=_TEST_INDEX_ENDPOINT_DISPLAY_NAME, + description=_TEST_INDEX_ENDPOINT_DESCRIPTION, + ), + gca_index_endpoint.IndexEndpoint( + name=_TEST_INDEX_ENDPOINT_NAME, + display_name=_TEST_INDEX_ENDPOINT_DISPLAY_NAME, + description=_TEST_INDEX_ENDPOINT_DESCRIPTION, + ), +] + +# Match +_TEST_QUERIES = [ + [ + -0.11333, + 0.48402, + 0.090771, + -0.22439, + 0.034206, + -0.55831, + 0.041849, + -0.53573, + 0.18809, + -0.58722, + 0.015313, + -0.014555, + 0.80842, + -0.038519, + 0.75348, + 0.70502, + -0.17863, + 0.3222, + 0.67575, + 0.67198, + 0.26044, + 0.4187, + -0.34122, + 0.2286, + -0.53529, + 1.2582, + -0.091543, + 0.19716, + -0.037454, + -0.3336, + 0.31399, + 0.36488, + 0.71263, + 0.1307, + -0.24654, + -0.52445, + -0.036091, + 0.55068, + 0.10017, + 0.48095, + 0.71104, + -0.053462, + 0.22325, + 0.30917, + -0.39926, + 0.036634, + -0.35431, + -0.42795, + 0.46444, + 0.25586, + 0.68257, + -0.20821, + 0.38433, + 0.055773, + -0.2539, + -0.20804, + 0.52522, + -0.11399, + -0.3253, + -0.44104, + 0.17528, + 0.62255, + 0.50237, + -0.7607, + -0.071786, + 0.0080131, + -0.13286, + 0.50097, + 0.18824, + -0.54722, + -0.42664, + 0.4292, + 0.14877, + -0.0072514, + -0.16484, + -0.059798, + 0.9895, + -0.61738, + 0.054169, + 0.48424, + -0.35084, + -0.27053, + 0.37829, + 0.11503, + -0.39613, + 0.24266, + 0.39147, + -0.075256, + 0.65093, + -0.20822, + -0.17456, + 0.53571, + -0.16537, + 0.13582, + -0.56016, + 0.016964, + 0.1277, + 0.94071, + -0.22608, + -0.021106, + ] +] +_TEST_NUM_NEIGHBOURS = 1 + + +def uuid_mock(): + return uuid.UUID(int=1) + + +# All index mocks +@pytest.fixture +def get_index_mock(): + with patch.object( + index_service_client.IndexServiceClient, "get_index" + ) as get_index_mock: + index = gca_index.Index( + name=_TEST_INDEX_NAME, + display_name=_TEST_INDEX_DISPLAY_NAME, + description=_TEST_INDEX_DESCRIPTION, + ) + + index.deployed_indexes = [ + gca_matching_engine_deployed_index_ref.DeployedIndexRef( + index_endpoint=index.name, + deployed_index_id=_TEST_DEPLOYED_INDEX_ID, + ) + ] + + get_index_mock.return_value = index + yield get_index_mock + + +# All index_endpoint mocks +@pytest.fixture +def get_index_endpoint_mock(): + with patch.object( + index_endpoint_service_client.IndexEndpointServiceClient, "get_index_endpoint" + ) as get_index_endpoint_mock: + index_endpoint = gca_index_endpoint.IndexEndpoint( + name=_TEST_INDEX_ENDPOINT_NAME, + display_name=_TEST_INDEX_ENDPOINT_DISPLAY_NAME, + description=_TEST_INDEX_ENDPOINT_DESCRIPTION, + ) + index_endpoint.deployed_indexes = [ + gca_index_endpoint.DeployedIndex( + id=_TEST_DEPLOYED_INDEX_ID, + index=_TEST_INDEX_NAME, + display_name=_TEST_DEPLOYED_INDEX_DISPLAY_NAME, + enable_access_logging=_TEST_ENABLE_ACCESS_LOGGING, + reserved_ip_ranges=_TEST_RESERVED_IP_RANGES, + deployment_group=_TEST_DEPLOYMENT_GROUP, + automatic_resources={ + "min_replica_count": _TEST_MIN_REPLICA_COUNT, + "max_replica_count": _TEST_MAX_REPLICA_COUNT, + }, + deployed_index_auth_config=gca_index_endpoint.DeployedIndexAuthConfig( + auth_provider=gca_index_endpoint.DeployedIndexAuthConfig.AuthProvider( + audiences=_TEST_AUTH_CONFIG_AUDIENCES, + allowed_issuers=_TEST_AUTH_CONFIG_ALLOWED_ISSUERS, + ) + ), + ), + gca_index_endpoint.DeployedIndex( + id=f"{_TEST_DEPLOYED_INDEX_ID}_2", + index=f"{_TEST_INDEX_NAME}_2", + display_name=_TEST_DEPLOYED_INDEX_DISPLAY_NAME, + enable_access_logging=_TEST_ENABLE_ACCESS_LOGGING, + reserved_ip_ranges=_TEST_RESERVED_IP_RANGES, + deployment_group=_TEST_DEPLOYMENT_GROUP, + automatic_resources={ + "min_replica_count": _TEST_MIN_REPLICA_COUNT, + "max_replica_count": _TEST_MAX_REPLICA_COUNT, + }, + deployed_index_auth_config=gca_index_endpoint.DeployedIndexAuthConfig( + auth_provider=gca_index_endpoint.DeployedIndexAuthConfig.AuthProvider( + audiences=_TEST_AUTH_CONFIG_AUDIENCES, + allowed_issuers=_TEST_AUTH_CONFIG_ALLOWED_ISSUERS, + ) + ), + ), + ] + + get_index_endpoint_mock.return_value = index_endpoint + yield get_index_endpoint_mock + + +@pytest.fixture +def deploy_index_mock(): + with patch.object( + index_endpoint_service_client.IndexEndpointServiceClient, + "deploy_index", + ) as deploy_index_mock: + deploy_index_lro_mock = mock.Mock(operation.Operation) + deploy_index_mock.return_value = deploy_index_lro_mock + yield deploy_index_mock + + +@pytest.fixture +def undeploy_index_mock(): + with patch.object( + index_endpoint_service_client.IndexEndpointServiceClient, + "undeploy_index", + ) as undeploy_index_mock: + undeploy_index_lro_mock = mock.Mock(operation.Operation) + undeploy_index_mock.return_value = undeploy_index_lro_mock + yield undeploy_index_mock + + +@pytest.fixture +def update_index_endpoint_mock(): + with patch.object( + index_endpoint_service_client.IndexEndpointServiceClient, + "update_index_endpoint", + ) as index_endpoint_mock: + index_endpoint_mock.return_value = gca_index_endpoint.IndexEndpoint( + name=_TEST_INDEX_ENDPOINT_NAME, + display_name=_TEST_DISPLAY_NAME_UPDATE, + description=_TEST_DESCRIPTION_UPDATE, + labels=_TEST_LABELS_UPDATE, + ) + + yield index_endpoint_mock + + +@pytest.fixture +def mutate_deployed_index_mock(): + with patch.object( + index_endpoint_service_client.IndexEndpointServiceClient, + "mutate_deployed_index", + ) as mutate_deployed_index_mock: + mutate_deployed_index_lro_mock = mock.Mock(operation.Operation) + update_index_endpoint_mock.return_value = mutate_deployed_index_lro_mock + yield mutate_deployed_index_mock + + +@pytest.fixture +def list_index_endpoints_mock(): + with patch.object( + index_endpoint_service_client.IndexEndpointServiceClient, "list_index_endpoints" + ) as list_index_endpoints_mock: + list_index_endpoints_mock.return_value = _TEST_INDEX_ENDPOINT_LIST + yield list_index_endpoints_mock + + +@pytest.fixture +def delete_index_endpoint_mock(): + with patch.object( + index_endpoint_service_client.IndexEndpointServiceClient, + "delete_index_endpoint", + ) as delete_index_endpoint_mock: + delete_index_endpoint_lro_mock = mock.Mock(operation.Operation) + delete_index_endpoint_mock.return_value = delete_index_endpoint_lro_mock + yield delete_index_endpoint_mock + + +@pytest.fixture +def create_index_endpoint_mock(): + with patch.object( + index_endpoint_service_client.IndexEndpointServiceClient, + "create_index_endpoint", + ) as create_index_endpoint_mock: + create_index_endpoint_lro_mock = mock.Mock(operation.Operation) + create_index_endpoint_lro_mock.result.return_value = ( + gca_index_endpoint.IndexEndpoint( + name=_TEST_INDEX_ENDPOINT_NAME, + display_name=_TEST_INDEX_ENDPOINT_DISPLAY_NAME, + description=_TEST_INDEX_ENDPOINT_DESCRIPTION, + ) + ) + create_index_endpoint_mock.return_value = create_index_endpoint_lro_mock + yield create_index_endpoint_mock + + +@pytest.mark.usefixtures("google_auth_mock") +class TestMatchingEngineIndexEndpoint: + def setup_method(self): + reload(initializer) + reload(aiplatform) + + def teardown_method(self): + initializer.global_pool.shutdown(wait=True) + + @pytest.mark.parametrize( + "index_endpoint_name", [_TEST_INDEX_ENDPOINT_ID, _TEST_INDEX_ENDPOINT_NAME] + ) + def test_init_index_endpoint(self, index_endpoint_name, get_index_endpoint_mock): + aiplatform.init(project=_TEST_PROJECT) + + my_index_endpoint = aiplatform.MatchingEngineIndexEndpoint( + index_endpoint_name=index_endpoint_name + ) + + get_index_endpoint_mock.assert_called_once_with( + name=my_index_endpoint.resource_name, retry=base._DEFAULT_RETRY + ) + + @pytest.mark.usefixtures("get_index_endpoint_mock") + def test_update_index_endpoint(self, update_index_endpoint_mock): + aiplatform.init(project=_TEST_PROJECT) + + my_index_endpoint = aiplatform.MatchingEngineIndexEndpoint( + index_endpoint_name=_TEST_INDEX_ENDPOINT_ID + ) + updated_endpoint = my_index_endpoint.update( + display_name=_TEST_DISPLAY_NAME_UPDATE, + description=_TEST_DESCRIPTION_UPDATE, + labels=_TEST_LABELS_UPDATE, + request_metadata=_TEST_REQUEST_METADATA, + ) + + expected = gca_index_endpoint.IndexEndpoint( + name=_TEST_INDEX_ENDPOINT_NAME, + display_name=_TEST_DISPLAY_NAME_UPDATE, + description=_TEST_DESCRIPTION_UPDATE, + labels=_TEST_LABELS_UPDATE, + ) + + update_index_endpoint_mock.assert_called_once_with( + index_endpoint=expected, + update_mask=field_mask_pb2.FieldMask( + paths=["labels", "display_name", "description"] + ), + metadata=_TEST_REQUEST_METADATA, + ) + + assert updated_endpoint.gca_resource == expected + + def test_list_index_endpoints(self, list_index_endpoints_mock): + aiplatform.init(project=_TEST_PROJECT) + + my_index_endpoints_list = aiplatform.MatchingEngineIndexEndpoint.list() + + list_index_endpoints_mock.assert_called_once_with( + request={"parent": _TEST_PARENT, "filter": None} + ) + assert len(my_index_endpoints_list) == len(_TEST_INDEX_ENDPOINT_LIST) + for my_index_endpoint in my_index_endpoints_list: + assert type(my_index_endpoint) == aiplatform.MatchingEngineIndexEndpoint + + @pytest.mark.parametrize("sync", [True, False]) + @pytest.mark.usefixtures("get_index_endpoint_mock") + def test_delete_index_endpoint(self, delete_index_endpoint_mock, sync): + aiplatform.init(project=_TEST_PROJECT) + + my_index_endpoint = aiplatform.MatchingEngineIndexEndpoint( + index_endpoint_name=_TEST_INDEX_ENDPOINT_ID + ) + my_index_endpoint.delete(sync=sync) + + if not sync: + my_index_endpoint.wait() + + delete_index_endpoint_mock.assert_called_once_with( + name=my_index_endpoint.resource_name + ) + + @pytest.mark.usefixtures("get_index_endpoint_mock") + @pytest.mark.parametrize("sync", [True, False]) + def test_create_index_endpoint(self, create_index_endpoint_mock, sync): + aiplatform.init(project=_TEST_PROJECT) + + my_index_endpoint = aiplatform.MatchingEngineIndexEndpoint.create( + display_name=_TEST_INDEX_ENDPOINT_DISPLAY_NAME, + network=_TEST_INDEX_ENDPOINT_VPC_NETWORK, + description=_TEST_INDEX_ENDPOINT_DESCRIPTION, + labels=_TEST_LABELS, + ) + + if not sync: + my_index_endpoint.wait() + + expected = gca_index_endpoint.IndexEndpoint( + display_name=_TEST_INDEX_ENDPOINT_DISPLAY_NAME, + network=_TEST_INDEX_ENDPOINT_VPC_NETWORK, + description=_TEST_INDEX_ENDPOINT_DESCRIPTION, + labels=_TEST_LABELS, + ) + create_index_endpoint_mock.assert_called_once_with( + parent=_TEST_PARENT, + index_endpoint=expected, + metadata=_TEST_REQUEST_METADATA, + ) + + @pytest.mark.usefixtures("get_index_endpoint_mock", "get_index_mock") + def test_deploy_index(self, deploy_index_mock, undeploy_index_mock): + aiplatform.init(project=_TEST_PROJECT) + + my_index_endpoint = aiplatform.MatchingEngineIndexEndpoint( + index_endpoint_name=_TEST_INDEX_ENDPOINT_ID + ) + + # Get index + my_index = aiplatform.MatchingEngineIndex(index_name=_TEST_INDEX_NAME) + + my_index_endpoint = my_index_endpoint.deploy_index( + index=my_index, + deployed_index_id=_TEST_DEPLOYED_INDEX_ID, + display_name=_TEST_DEPLOYED_INDEX_DISPLAY_NAME, + min_replica_count=_TEST_MIN_REPLICA_COUNT, + max_replica_count=_TEST_MAX_REPLICA_COUNT, + enable_access_logging=_TEST_ENABLE_ACCESS_LOGGING, + reserved_ip_ranges=_TEST_RESERVED_IP_RANGES, + deployment_group=_TEST_DEPLOYMENT_GROUP, + auth_config_audiences=_TEST_AUTH_CONFIG_AUDIENCES, + auth_config_allowed_issuers=_TEST_AUTH_CONFIG_ALLOWED_ISSUERS, + request_metadata=_TEST_REQUEST_METADATA, + ) + + deploy_index_mock.assert_called_once_with( + index_endpoint=my_index_endpoint.resource_name, + deployed_index=gca_index_endpoint.DeployedIndex( + id=_TEST_DEPLOYED_INDEX_ID, + index=my_index.resource_name, + display_name=_TEST_DEPLOYED_INDEX_DISPLAY_NAME, + enable_access_logging=_TEST_ENABLE_ACCESS_LOGGING, + reserved_ip_ranges=_TEST_RESERVED_IP_RANGES, + deployment_group=_TEST_DEPLOYMENT_GROUP, + automatic_resources={ + "min_replica_count": _TEST_MIN_REPLICA_COUNT, + "max_replica_count": _TEST_MAX_REPLICA_COUNT, + }, + deployed_index_auth_config=gca_index_endpoint.DeployedIndexAuthConfig( + auth_provider=gca_index_endpoint.DeployedIndexAuthConfig.AuthProvider( + audiences=_TEST_AUTH_CONFIG_AUDIENCES, + allowed_issuers=_TEST_AUTH_CONFIG_ALLOWED_ISSUERS, + ) + ), + ), + metadata=_TEST_REQUEST_METADATA, + ) + + my_index_endpoint = my_index_endpoint.undeploy_index( + deployed_index_id=_TEST_DEPLOYED_INDEX_ID + ) + + undeploy_index_mock.assert_called_once_with( + index_endpoint=my_index_endpoint.resource_name, + deployed_index_id=_TEST_DEPLOYED_INDEX_ID, + metadata=_TEST_REQUEST_METADATA, + ) + + @pytest.mark.usefixtures("get_index_endpoint_mock", "get_index_mock") + def test_mutate_deployed_index(self, mutate_deployed_index_mock): + aiplatform.init(project=_TEST_PROJECT) + + my_index_endpoint = aiplatform.MatchingEngineIndexEndpoint( + index_endpoint_name=_TEST_INDEX_ENDPOINT_ID + ) + + my_index_endpoint.mutate_deployed_index( + deployed_index_id=_TEST_DEPLOYED_INDEX_ID, + min_replica_count=_TEST_MIN_REPLICA_COUNT_UPDATED, + max_replica_count=_TEST_MAX_REPLICA_COUNT_UPDATED, + request_metadata=_TEST_REQUEST_METADATA, + ) + + mutate_deployed_index_mock.assert_called_once_with( + index_endpoint=_TEST_INDEX_ENDPOINT_NAME, + deployed_index=gca_index_endpoint.DeployedIndex( + id=_TEST_DEPLOYED_INDEX_ID, + automatic_resources={ + "min_replica_count": _TEST_MIN_REPLICA_COUNT_UPDATED, + "max_replica_count": _TEST_MAX_REPLICA_COUNT_UPDATED, + }, + ), + metadata=_TEST_REQUEST_METADATA, + ) + + @pytest.mark.usefixtures("get_index_endpoint_mock") + @pytest.mark.parametrize("sync", [True, False]) + def test_delete_index_endpoint_without_force( + self, undeploy_index_mock, delete_index_endpoint_mock, sync + ): + + my_index_endpoint = aiplatform.MatchingEngineIndexEndpoint( + index_endpoint_name=_TEST_INDEX_ENDPOINT_NAME + ) + + my_index_endpoint.delete(sync=sync) + + if not sync: + my_index_endpoint.wait() + + # undeploy_index_mock should not be called unless force is set to True + undeploy_index_mock.assert_not_called() + + delete_index_endpoint_mock.assert_called_once_with( + name=_TEST_INDEX_ENDPOINT_NAME + ) + + @pytest.mark.usefixtures("get_index_endpoint_mock") + @pytest.mark.parametrize("sync", [True, False]) + def test_delete_index_endpoint_with_force( + self, undeploy_index_mock, delete_index_endpoint_mock, sync + ): + + my_index_endpoint = aiplatform.MatchingEngineIndexEndpoint( + index_endpoint_name=_TEST_INDEX_ENDPOINT_NAME + ) + my_index_endpoint.delete(force=True, sync=sync) + + if not sync: + my_index_endpoint.wait() + + # undeploy_index_mock should be called if force is set to True + assert undeploy_index_mock.call_count == 2 + + delete_index_endpoint_mock.assert_called_once_with( + name=_TEST_INDEX_ENDPOINT_NAME + ) diff --git a/tests/unit/aiplatform/test_metadata.py b/tests/unit/aiplatform/test_metadata.py index 9a930dd3f5..85d6b80d8d 100644 --- a/tests/unit/aiplatform/test_metadata.py +++ b/tests/unit/aiplatform/test_metadata.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2021 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,33 +14,54 @@ # See the License for the specific language governing permissions and # limitations under the License. # - +import copy from importlib import reload +from unittest import mock from unittest.mock import patch, call import pytest from google.api_core import exceptions +from google.api_core import operation +from google.auth import credentials +import google.cloud.aiplatform.metadata.constants from google.cloud import aiplatform +from google.cloud.aiplatform import base from google.cloud.aiplatform import initializer -from google.cloud.aiplatform.metadata import constants -from google.cloud.aiplatform.metadata import metadata -from google.cloud.aiplatform_v1beta1 import ( - AddContextArtifactsAndExecutionsResponse, - Event, - LineageSubgraph, - ListExecutionsRequest, +from google.cloud.aiplatform.compat.types import event as gca_event +from google.cloud.aiplatform.compat.types import execution as gca_execution +from google.cloud.aiplatform.compat.types import ( + tensorboard_data as gca_tensorboard_data, ) -from google.cloud.aiplatform_v1beta1 import Artifact as GapicArtifact -from google.cloud.aiplatform_v1beta1 import Context as GapicContext -from google.cloud.aiplatform_v1beta1 import Execution as GapicExecution -from google.cloud.aiplatform_v1beta1 import ( - MetadataServiceClient, - AddExecutionEventsResponse, +from google.cloud.aiplatform.compat.types import ( + tensorboard_experiment as gca_tensorboard_experiment, ) -from google.cloud.aiplatform_v1beta1 import MetadataStore as GapicMetadataStore - -# project +from google.cloud.aiplatform.compat.types import tensorboard_run as gca_tensorboard_run +from google.cloud.aiplatform.compat.types import ( + tensorboard_time_series as gca_tensorboard_time_series, +) +from google.cloud.aiplatform.metadata import constants +from google.cloud.aiplatform.metadata import experiment_run_resource +from google.cloud.aiplatform.metadata import metadata +from google.cloud.aiplatform.metadata import metadata_store +from google.cloud.aiplatform.metadata import utils as metadata_utils +from google.cloud.aiplatform import utils + +from google.cloud.aiplatform_v1 import AddContextArtifactsAndExecutionsResponse +from google.cloud.aiplatform_v1 import AddExecutionEventsResponse +from google.cloud.aiplatform_v1 import Artifact as GapicArtifact +from google.cloud.aiplatform_v1 import Context as GapicContext +from google.cloud.aiplatform_v1 import Execution as GapicExecution +from google.cloud.aiplatform_v1 import LineageSubgraph +from google.cloud.aiplatform_v1 import MetadataServiceClient +from google.cloud.aiplatform_v1 import MetadataStore as GapicMetadataStore +from google.cloud.aiplatform_v1 import TensorboardServiceClient + +from test_pipeline_jobs import mock_pipeline_service_get # noqa: F401 +from test_pipeline_jobs import _TEST_PIPELINE_JOB_NAME # noqa: F401 + +import test_pipeline_jobs +import test_tensorboard _TEST_PROJECT = "test-project" _TEST_OTHER_PROJECT = "test-project-1" @@ -106,6 +127,34 @@ def get_metadata_store_mock(): yield get_metadata_store_mock +@pytest.fixture +def get_metadata_store_mock_raise_not_found_exception(): + with patch.object( + MetadataServiceClient, "get_metadata_store" + ) as get_metadata_store_mock: + get_metadata_store_mock.side_effect = [ + exceptions.NotFound("Test store not found."), + GapicMetadataStore( + name=_TEST_METADATASTORE, + ), + ] + + yield get_metadata_store_mock + + +@pytest.fixture +def create_metadata_store_mock(): + with patch.object( + MetadataServiceClient, "create_metadata_store" + ) as create_metadata_store_mock: + create_metadata_store_lro_mock = mock.Mock(operation.Operation) + create_metadata_store_lro_mock.result.return_value = GapicMetadataStore( + name=_TEST_METADATASTORE, + ) + create_metadata_store_mock.return_value = create_metadata_store_lro_mock + yield create_metadata_store_mock + + @pytest.fixture def get_context_mock(): with patch.object(MetadataServiceClient, "get_context") as get_context_mock: @@ -159,17 +208,23 @@ def get_context_not_found_mock(): yield get_context_not_found_mock +_TEST_EXPERIMENT_CONTEXT = GapicContext( + name=_TEST_CONTEXT_NAME, + display_name=_TEST_EXPERIMENT, + description=_TEST_EXPERIMENT_DESCRIPTION, + schema_title=constants.SYSTEM_EXPERIMENT, + schema_version=constants.SCHEMA_VERSIONS[constants.SYSTEM_EXPERIMENT], + metadata={ + **constants.EXPERIMENT_METADATA, + constants._BACKING_TENSORBOARD_RESOURCE_KEY: test_tensorboard._TEST_NAME, + }, +) + + @pytest.fixture def update_context_mock(): with patch.object(MetadataServiceClient, "update_context") as update_context_mock: - update_context_mock.return_value = GapicContext( - name=_TEST_CONTEXT_NAME, - display_name=_TEST_EXPERIMENT, - description=_TEST_OTHER_EXPERIMENT_DESCRIPTION, - schema_title=constants.SYSTEM_EXPERIMENT, - schema_version=constants.SCHEMA_VERSIONS[constants.SYSTEM_EXPERIMENT], - metadata=constants.EXPERIMENT_METADATA, - ) + update_context_mock.return_value = _TEST_EXPERIMENT_CONTEXT yield update_context_mock @@ -256,6 +311,42 @@ def list_executions_mock(): yield list_executions_mock +@pytest.fixture +def get_tensorboard_run_not_found_mock(): + with patch.object( + TensorboardServiceClient, "get_tensorboard_run" + ) as get_tensorboard_run_mock: + get_tensorboard_run_mock.side_effect = [ + exceptions.NotFound(""), + test_tensorboard._TEST_TENSORBOARD_RUN, + ] + yield get_tensorboard_run_mock + + +@pytest.fixture +def get_tensorboard_experiment_not_found_mock(): + with patch.object( + TensorboardServiceClient, "get_tensorboard_experiment" + ) as get_tensorboard_experiment_mock: + get_tensorboard_experiment_mock.side_effect = [ + exceptions.NotFound(""), + test_tensorboard._TEST_TENSORBOARD_EXPERIMENT, + ] + yield get_tensorboard_experiment_mock + + +@pytest.fixture +def get_tensorboard_time_series_not_found_mock(): + with patch.object( + TensorboardServiceClient, "get_tensorboard_time_series" + ) as get_tensorboard_time_series_mock: + get_tensorboard_time_series_mock.side_effect = [ + exceptions.NotFound(""), + # test_tensorboard._TEST_TENSORBOARD_TIME_SERIES # change to time series + ] + yield get_tensorboard_time_series_mock + + @pytest.fixture def query_execution_inputs_and_outputs_mock(): with patch.object( @@ -272,7 +363,14 @@ def query_execution_inputs_and_outputs_mock(): constants.SYSTEM_METRICS ], metadata=_TEST_METRICS, - ), + ) + ], + events=[ + gca_event.Event( + artifact=_TEST_ARTIFACT_NAME, + execution=_TEST_EXECUTION_NAME, + type_=gca_event.Event.Type.OUTPUT, + ) ], ), LineageSubgraph( @@ -287,6 +385,13 @@ def query_execution_inputs_and_outputs_mock(): metadata=_TEST_OTHER_METRICS, ), ], + events=[ + gca_event.Event( + artifact=_TEST_OTHER_ARTIFACT_NAME, + execution=_TEST_OTHER_EXECUTION_NAME, + type_=gca_event.Event.Type.OUTPUT, + ) + ], ), ] yield query_execution_inputs_and_outputs_mock @@ -304,6 +409,13 @@ def get_artifact_mock(): yield get_artifact_mock +@pytest.fixture +def get_artifact_not_found_mock(): + with patch.object(MetadataServiceClient, "get_artifact") as get_artifact_mock: + get_artifact_mock.side_effect = exceptions.NotFound("") + yield get_artifact_mock + + @pytest.fixture def get_artifact_wrong_schema_mock(): with patch.object( @@ -337,7 +449,7 @@ def _assert_frame_equal_with_sorted_columns(dataframe_1, dataframe_2): except ImportError: raise ImportError( "Pandas is not installed and is required to test the get_experiment_df/pipeline_df method. " - 'Please install the SDK using "pip install python-aiplatform[full]"' + 'Please install the SDK using "pip install google-cloud-aiplatform[full]"' ) pd.testing.assert_frame_equal( @@ -345,6 +457,7 @@ def _assert_frame_equal_with_sorted_columns(dataframe_1, dataframe_2): ) +@pytest.mark.usefixtures("google_auth_mock") class TestMetadata: def setup_method(self): reload(initializer) @@ -354,18 +467,459 @@ def setup_method(self): def teardown_method(self): initializer.global_pool.shutdown(wait=True) + @pytest.mark.usefixtures("get_pipeline_context_mock") + def test_get_pipeline_df( + self, list_executions_mock, query_execution_inputs_and_outputs_mock + ): + try: + import pandas as pd + except ImportError: + raise ImportError( + "Pandas is not installed and is required to test the get_pipeline_df method. " + 'Please install the SDK using "pip install google-cloud-aiplatform[full]"' + ) + aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) + + pipeline_df = aiplatform.get_pipeline_df(_TEST_PIPELINE) + + expected_filter = metadata_utils._make_filter_string( + schema_title=constants.SYSTEM_RUN, in_context=[_TEST_CONTEXT_NAME] + ) + + list_executions_mock.assert_called_once_with( + request={"parent": _TEST_PARENT, "filter": expected_filter} + ) + query_execution_inputs_and_outputs_mock.assert_has_calls( + [ + call(execution=_TEST_EXECUTION_NAME), + call(execution=_TEST_OTHER_EXECUTION_NAME), + ] + ) + pipeline_df_truth = pd.DataFrame( + [ + { + "pipeline_name": _TEST_PIPELINE, + "run_name": _TEST_RUN, + "param.%s" % _TEST_PARAM_KEY_1: 0.01, + "param.%s" % _TEST_PARAM_KEY_2: 0.2, + "metric.%s" % _TEST_METRIC_KEY_1: 222, + "metric.%s" % _TEST_METRIC_KEY_2: 1, + }, + { + "pipeline_name": _TEST_PIPELINE, + "run_name": _TEST_OTHER_RUN, + "param.%s" % _TEST_PARAM_KEY_1: 0.02, + "param.%s" % _TEST_PARAM_KEY_2: 0.3, + "metric.%s" % _TEST_METRIC_KEY_2: 0.9, + }, + ] + ) + + _assert_frame_equal_with_sorted_columns(pipeline_df, pipeline_df_truth) + + @pytest.mark.usefixtures("get_context_not_found_mock") + def test_get_pipeline_df_not_exist(self): + aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) + with pytest.raises(exceptions.NotFound): + aiplatform.get_pipeline_df(_TEST_PIPELINE) + + @pytest.mark.usefixtures("get_context_mock") + def test_get_pipeline_df_wrong_schema(self): + aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) + with pytest.raises(ValueError): + aiplatform.get_pipeline_df(_TEST_PIPELINE) + + +_TEST_EXPERIMENT_RUN_CONTEXT_NAME = f"{_TEST_PARENT}/contexts/{_TEST_EXECUTION_ID}" +_TEST_OTHER_EXPERIMENT_RUN_CONTEXT_NAME = ( + f"{_TEST_PARENT}/contexts/{_TEST_OTHER_EXECUTION_ID}" +) + +_EXPERIMENT_MOCK = GapicContext( + name=_TEST_CONTEXT_NAME, + display_name=_TEST_EXPERIMENT, + description=_TEST_EXPERIMENT_DESCRIPTION, + schema_title=constants.SYSTEM_EXPERIMENT, + schema_version=constants.SCHEMA_VERSIONS[constants.SYSTEM_EXPERIMENT], + metadata={**constants.EXPERIMENT_METADATA}, +) + +_EXPERIMENT_RUN_MOCK = GapicContext( + name=_TEST_EXPERIMENT_RUN_CONTEXT_NAME, + display_name=_TEST_RUN, + schema_title=constants.SYSTEM_EXPERIMENT_RUN, + schema_version=constants.SCHEMA_VERSIONS[constants.SYSTEM_EXPERIMENT_RUN], + metadata={ + constants._PARAM_KEY: {}, + constants._METRIC_KEY: {}, + constants._STATE_KEY: gca_execution.Execution.State.RUNNING.name, + }, +) + +_EXPERIMENT_RUN_MOCK_WITH_PARENT_EXPERIMENT = copy.deepcopy(_EXPERIMENT_RUN_MOCK) +_EXPERIMENT_RUN_MOCK_WITH_PARENT_EXPERIMENT.parent_contexts = [_TEST_CONTEXT_NAME] + + +@pytest.fixture +def get_experiment_mock(): + with patch.object(MetadataServiceClient, "get_context") as get_context_mock: + get_context_mock.return_value = _EXPERIMENT_MOCK + yield get_context_mock + + +@pytest.fixture +def get_experiment_run_run_mock(): + with patch.object(MetadataServiceClient, "get_context") as get_context_mock: + get_context_mock.side_effect = [ + _EXPERIMENT_MOCK, + _EXPERIMENT_RUN_MOCK, + _EXPERIMENT_RUN_MOCK_WITH_PARENT_EXPERIMENT, + ] + + yield get_context_mock + + +@pytest.fixture +def get_experiment_run_mock(): + with patch.object(MetadataServiceClient, "get_context") as get_context_mock: + get_context_mock.side_effect = [ + _EXPERIMENT_MOCK, + _EXPERIMENT_RUN_MOCK_WITH_PARENT_EXPERIMENT, + ] + + yield get_context_mock + + +@pytest.fixture +def create_experiment_run_context_mock(): + with patch.object(MetadataServiceClient, "create_context") as create_context_mock: + create_context_mock.side_effect = [_EXPERIMENT_RUN_MOCK] + yield create_context_mock + + +@pytest.fixture +def update_experiment_run_context_to_running(): + with patch.object(MetadataServiceClient, "update_context") as update_context_mock: + update_context_mock.side_effect = [_EXPERIMENT_RUN_MOCK] + yield update_context_mock + + +@pytest.fixture +def update_context_mock_v2(): + with patch.object(MetadataServiceClient, "update_context") as update_context_mock: + update_context_mock.side_effect = [ + # experiment run + GapicContext( + name=_TEST_EXPERIMENT_RUN_CONTEXT_NAME, + display_name=_TEST_RUN, + schema_title=constants.SYSTEM_EXPERIMENT_RUN, + schema_version=constants.SCHEMA_VERSIONS[ + constants.SYSTEM_EXPERIMENT_RUN + ], + metadata={**constants.EXPERIMENT_METADATA}, + ), + # experiment run + GapicContext( + name=_TEST_EXPERIMENT_RUN_CONTEXT_NAME, + display_name=_TEST_RUN, + schema_title=constants.SYSTEM_EXPERIMENT_RUN, + schema_version=constants.SCHEMA_VERSIONS[ + constants.SYSTEM_EXPERIMENT_RUN + ], + metadata=constants.EXPERIMENT_METADATA, + parent_contexts=[_TEST_CONTEXT_NAME], + ), + ] + + yield update_context_mock + + +@pytest.fixture +def list_contexts_mock(): + with patch.object(MetadataServiceClient, "list_contexts") as list_contexts_mock: + list_contexts_mock.return_value = [ + GapicContext( + name=_TEST_EXPERIMENT_RUN_CONTEXT_NAME, + display_name=_TEST_RUN, + schema_title=constants.SYSTEM_EXPERIMENT_RUN, + schema_version=constants.SCHEMA_VERSIONS[ + constants.SYSTEM_EXPERIMENT_RUN + ], + metadata=constants.EXPERIMENT_METADATA, + parent_contexts=[_TEST_CONTEXT_NAME], + ), + GapicContext( + name=_TEST_OTHER_EXPERIMENT_RUN_CONTEXT_NAME, + display_name=_TEST_OTHER_RUN, + schema_title=constants.SYSTEM_EXPERIMENT_RUN, + schema_version=constants.SCHEMA_VERSIONS[ + constants.SYSTEM_EXPERIMENT_RUN + ], + metadata=constants.EXPERIMENT_METADATA, + parent_contexts=[_TEST_CONTEXT_NAME], + ), + ] + yield list_contexts_mock + + +@pytest.fixture +def add_context_children_mock(): + with patch.object( + MetadataServiceClient, "add_context_children" + ) as add_context_children_mock: + yield add_context_children_mock + + +_EXPERIMENT_RUN_MOCK_POPULATED_1 = copy.deepcopy( + _EXPERIMENT_RUN_MOCK_WITH_PARENT_EXPERIMENT +) +_EXPERIMENT_RUN_MOCK_POPULATED_1.metadata[constants._PARAM_KEY].update(_TEST_PARAMS) +_EXPERIMENT_RUN_MOCK_POPULATED_1.metadata[constants._METRIC_KEY].update(_TEST_METRICS) +_EXPERIMENT_RUN_MOCK_POPULATED_2 = copy.deepcopy( + _EXPERIMENT_RUN_MOCK_WITH_PARENT_EXPERIMENT +) +_EXPERIMENT_RUN_MOCK_POPULATED_2.display_name = _TEST_OTHER_RUN +_EXPERIMENT_RUN_MOCK_POPULATED_2.metadata[constants._PARAM_KEY].update( + _TEST_OTHER_PARAMS +) +_EXPERIMENT_RUN_MOCK_POPULATED_2.metadata[constants._METRIC_KEY].update( + _TEST_OTHER_METRICS +) + +_TEST_PIPELINE_RUN_ID = "test-pipeline-run" +_TEST_PIPELINE_RUN_CONTEXT_NAME = f"{_TEST_PARENT}/contexts/{_TEST_PIPELINE_RUN_ID}" + +_TEST_PIPELINE_CONTEXT = GapicContext( + name=_TEST_PIPELINE_RUN_CONTEXT_NAME, + display_name=_TEST_PIPELINE_RUN_ID, + schema_title=constants.SYSTEM_PIPELINE_RUN, + parent_contexts=[_TEST_CONTEXT_NAME], +) + + +@pytest.fixture() +def list_context_mock_for_experiment_dataframe_mock(): + with patch.object(MetadataServiceClient, "list_contexts") as list_context_mock: + list_context_mock.side_effect = [ + # experiment runs + [ + _EXPERIMENT_RUN_MOCK_POPULATED_1, + _EXPERIMENT_RUN_MOCK_POPULATED_2, + _TEST_PIPELINE_CONTEXT, + ], + # pipeline runs + [], + ] + yield list_context_mock + + +_TEST_LEGACY_METRIC_ARTIFACT = GapicArtifact( + name=_TEST_ARTIFACT_NAME, + schema_title=constants.SYSTEM_METRICS, + metadata=_TEST_METRICS, +) + +_TEST_PIPELINE_METRIC_ARTIFACT = GapicArtifact( + name=_TEST_ARTIFACT_NAME, + schema_title=constants.SYSTEM_METRICS, + metadata={key: value + 1 for key, value in _TEST_METRICS.items()}, +) + + +@pytest.fixture() +def list_artifact_mock_for_experiment_dataframe(): + with patch.object(MetadataServiceClient, "list_artifacts") as list_artifacts_mock: + list_artifacts_mock.side_effect = [ + # pipeline run metric artifact + [_TEST_PIPELINE_METRIC_ARTIFACT], + ] + yield list_artifacts_mock + + +_TEST_PIPELINE_SYSTEM_RUN_EXECUTION = GapicExecution( + name=_TEST_EXECUTION_NAME, + schema_title=constants.SYSTEM_RUN, + state=gca_execution.Execution.State.RUNNING, + metadata={f"input:{key}": value + 1 for key, value in _TEST_PARAMS.items()}, +) + +_TEST_LEGACY_SYSTEM_RUN_EXECUTION = GapicExecution( + name=_TEST_EXECUTION_NAME, + display_name=_TEST_RUN, + schema_title=constants.SYSTEM_RUN, + schema_version=constants.SCHEMA_VERSIONS[constants.SYSTEM_RUN], + metadata=_TEST_PARAMS, +) + + +# backward compatibility +@pytest.fixture() +def list_executions_mock_for_experiment_dataframe(): + with patch.object(MetadataServiceClient, "list_executions") as list_executions_mock: + list_executions_mock.side_effect = [ + # legacy system.run execution + [_TEST_LEGACY_SYSTEM_RUN_EXECUTION], + # pipeline system.run execution + [_TEST_PIPELINE_SYSTEM_RUN_EXECUTION], + ] + yield list_executions_mock + + +@pytest.fixture +def get_tensorboard_run_artifact_not_found_mock(): + with patch.object(MetadataServiceClient, "get_artifact") as get_artifact_mock: + get_artifact_mock.side_effect = exceptions.NotFound("") + yield get_artifact_mock + + +_TEST_LEGACY_METRIC_ARTIFACT + +_TEST_TENSORBOARD_RUN_ARTIFACT = GapicArtifact( + name=experiment_run_resource.ExperimentRun._tensorboard_run_id( + _TEST_EXPERIMENT_RUN_CONTEXT_NAME + ), + uri="https://us-central1-aiplatform.googleapis.com/v1/projects/test-project/locations/us-central1/tensorboards/1028944691210842416/experiments/test-experiment/runs/test-run", + schema_title=google.cloud.aiplatform.metadata.constants._TENSORBOARD_RUN_REFERENCE_ARTIFACT.schema_title, + schema_version=google.cloud.aiplatform.metadata.constants._TENSORBOARD_RUN_REFERENCE_ARTIFACT.schema_version, + state=GapicArtifact.State.LIVE, + metadata={ + google.cloud.aiplatform.metadata.constants._VERTEX_EXPERIMENT_TRACKING_LABEL: True, + constants.GCP_ARTIFACT_RESOURCE_NAME_KEY: test_tensorboard._TEST_TENSORBOARD_RUN_NAME, + }, +) + +get_tensorboard_mock = test_tensorboard.get_tensorboard_mock +create_tensorboard_experiment_mock = test_tensorboard.create_tensorboard_experiment_mock +create_tensorboard_run_mock = test_tensorboard.create_tensorboard_run_mock +write_tensorboard_run_data_mock = test_tensorboard.write_tensorboard_run_data_mock +create_tensorboard_time_series_mock = ( + test_tensorboard.create_tensorboard_time_series_mock +) + +get_tensorboard_run_mock = test_tensorboard.get_tensorboard_run_mock +list_tensorboard_time_series_mock = test_tensorboard.list_tensorboard_time_series_mock +batch_read_tensorboard_time_series_mock = ( + test_tensorboard.batch_read_tensorboard_time_series_mock +) +get_pipeline_job_mock = test_pipeline_jobs.mock_pipeline_service_get + + +@pytest.fixture +def list_tensorboard_time_series_mock_empty(): + with patch.object( + TensorboardServiceClient, + "list_tensorboard_time_series", + ) as list_tensorboard_time_series_mock: + list_tensorboard_time_series_mock.side_effect = [ + [], # initially empty + [], + [test_tensorboard._TEST_TENSORBOARD_TIME_SERIES], + ] + yield list_tensorboard_time_series_mock + + +@pytest.fixture +def create_tensorboard_run_artifact_mock(): + with patch.object(MetadataServiceClient, "create_artifact") as create_artifact_mock: + create_artifact_mock.side_effect = [_TEST_TENSORBOARD_RUN_ARTIFACT] + yield create_artifact_mock + + +@pytest.fixture +def get_tensorboard_run_artifact_mock(): + with patch.object(MetadataServiceClient, "get_artifact") as get_artifact_mock: + get_artifact_mock.side_effect = [ + _TEST_TENSORBOARD_RUN_ARTIFACT, + exceptions.NotFound(""), + _TEST_LEGACY_METRIC_ARTIFACT, + ] + yield get_artifact_mock + + +@pytest.mark.usefixtures("google_auth_mock") +class TestExperiments: + def setup_method(self): + reload(initializer) + reload(metadata) + reload(aiplatform) + + def teardown_method(self): + initializer.global_pool.shutdown(wait=True) + def test_init_experiment_with_existing_metadataStore_and_context( - self, get_metadata_store_mock, get_context_mock + self, get_metadata_store_mock, get_experiment_run_run_mock ): aiplatform.init( - project=_TEST_PROJECT, location=_TEST_LOCATION, experiment=_TEST_EXPERIMENT + project=_TEST_PROJECT, + location=_TEST_LOCATION, + experiment=_TEST_EXPERIMENT, + ) + + get_metadata_store_mock.assert_called_once_with( + name=_TEST_METADATASTORE, retry=base._DEFAULT_RETRY + ) + get_experiment_run_run_mock.assert_called_once_with( + name=_TEST_CONTEXT_NAME, retry=base._DEFAULT_RETRY ) - get_metadata_store_mock.assert_called_once_with(name=_TEST_METADATASTORE) - get_context_mock.assert_called_once_with(name=_TEST_CONTEXT_NAME) + def test_init_experiment_with_credentials( + self, + get_metadata_store_mock, + get_experiment_run_run_mock, + ): + creds = credentials.AnonymousCredentials() + + aiplatform.init( + project=_TEST_PROJECT, + location=_TEST_LOCATION, + experiment=_TEST_EXPERIMENT, + credentials=creds, + ) + + assert ( + metadata._experiment_tracker._experiment._metadata_context.api_client._transport._credentials + == creds + ) + + get_metadata_store_mock.assert_called_once_with( + name=_TEST_METADATASTORE, retry=base._DEFAULT_RETRY + ) + get_experiment_run_run_mock.assert_called_once_with( + name=_TEST_CONTEXT_NAME, retry=base._DEFAULT_RETRY + ) + + def test_init_and_get_metadata_store_with_credentials( + self, get_metadata_store_mock + ): + creds = credentials.AnonymousCredentials() + + aiplatform.init( + project=_TEST_PROJECT, location=_TEST_LOCATION, credentials=creds + ) + + store = metadata_store._MetadataStore.get_or_create() + + assert store.api_client._transport._credentials == creds + + @pytest.mark.usefixtures( + "get_metadata_store_mock_raise_not_found_exception", + "create_metadata_store_mock", + ) + def test_init_and_get_then_create_metadata_store_with_credentials( + self, + ): + creds = credentials.AnonymousCredentials() + + aiplatform.init( + project=_TEST_PROJECT, location=_TEST_LOCATION, credentials=creds + ) + + store = metadata_store._MetadataStore.get_or_create() + + assert store.api_client._transport._credentials == creds def test_init_experiment_with_existing_description( - self, get_metadata_store_mock, get_context_mock + self, get_metadata_store_mock, get_experiment_run_run_mock ): aiplatform.init( project=_TEST_PROJECT, @@ -374,12 +928,18 @@ def test_init_experiment_with_existing_description( experiment_description=_TEST_EXPERIMENT_DESCRIPTION, ) - get_metadata_store_mock.assert_called_once_with(name=_TEST_METADATASTORE) - get_context_mock.assert_called_once_with(name=_TEST_CONTEXT_NAME) + get_metadata_store_mock.assert_called_once_with( + name=_TEST_METADATASTORE, retry=base._DEFAULT_RETRY + ) + get_experiment_run_run_mock.assert_called_once_with( + name=_TEST_CONTEXT_NAME, retry=base._DEFAULT_RETRY + ) - @pytest.mark.usefixtures("get_metadata_store_mock") - @pytest.mark.usefixtures("get_context_mock") - def test_init_experiment_without_existing_description(self, update_context_mock): + @pytest.mark.usefixtures("get_metadata_store_mock", "get_experiment_run_run_mock") + def test_init_experiment_without_existing_description( + self, + update_context_mock, + ): aiplatform.init( project=_TEST_PROJECT, location=_TEST_LOCATION, @@ -398,8 +958,31 @@ def test_init_experiment_without_existing_description(self, update_context_mock) update_context_mock.assert_called_once_with(context=experiment_context) - @pytest.mark.usefixtures("get_metadata_store_mock") - @pytest.mark.usefixtures("get_context_wrong_schema_mock") + @pytest.mark.usefixtures( + "get_metadata_store_mock", + "get_experiment_run_mock", + "update_experiment_run_context_to_running", + "get_tensorboard_run_artifact_not_found_mock", + ) + def test_init_experiment_reset(self): + aiplatform.init( + project=_TEST_PROJECT, + location=_TEST_LOCATION, + experiment=_TEST_EXPERIMENT, + ) + aiplatform.start_run(_TEST_RUN, resume=True) + + aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) + + assert metadata._experiment_tracker.experiment_name == _TEST_EXPERIMENT + assert metadata._experiment_tracker.experiment_run.name == _TEST_RUN + + aiplatform.init(project=_TEST_OTHER_PROJECT, location=_TEST_LOCATION) + + assert metadata._experiment_tracker.experiment_name is None + assert metadata._experiment_tracker.experiment_run is None + + @pytest.mark.usefixtures("get_metadata_store_mock", "get_context_wrong_schema_mock") def test_init_experiment_wrong_schema(self): with pytest.raises(ValueError): aiplatform.init( @@ -409,180 +992,377 @@ def test_init_experiment_wrong_schema(self): ) @pytest.mark.usefixtures("get_metadata_store_mock") - @pytest.mark.usefixtures("get_context_mock") - @pytest.mark.usefixtures("get_execution_mock") - @pytest.mark.usefixtures("add_context_artifacts_and_executions_mock") - @pytest.mark.usefixtures("get_artifact_mock") - @pytest.mark.usefixtures("add_execution_events_mock") - def test_init_experiment_reset(self): + @pytest.mark.usefixtures() + def test_start_run( + self, + get_experiment_mock, + create_experiment_run_context_mock, + add_context_children_mock, + ): + aiplatform.init( - project=_TEST_PROJECT, location=_TEST_LOCATION, experiment=_TEST_EXPERIMENT + project=_TEST_PROJECT, + location=_TEST_LOCATION, + experiment=_TEST_EXPERIMENT, ) aiplatform.start_run(_TEST_RUN) - aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) + get_experiment_mock.assert_called_with( + name=_TEST_CONTEXT_NAME, retry=base._DEFAULT_RETRY + ) - assert metadata.metadata_service.experiment_name == _TEST_EXPERIMENT - assert metadata.metadata_service.run_name == _TEST_RUN + _TRUE_CONTEXT = copy.deepcopy(_EXPERIMENT_RUN_MOCK) + _TRUE_CONTEXT.name = None - aiplatform.init(project=_TEST_OTHER_PROJECT, location=_TEST_LOCATION) + create_experiment_run_context_mock.assert_called_with( + parent=_TEST_METADATASTORE, + context=_TRUE_CONTEXT, + context_id=_EXPERIMENT_RUN_MOCK.name.split("/")[-1], + ) - assert metadata.metadata_service.experiment_name is None - assert metadata.metadata_service.run_name is None + add_context_children_mock.assert_called_with( + context=_EXPERIMENT_MOCK.name, child_contexts=[_EXPERIMENT_RUN_MOCK.name] + ) - @pytest.mark.usefixtures("get_metadata_store_mock") - @pytest.mark.usefixtures("get_context_mock") - def test_start_run_with_existing_execution_and_artifact( + @pytest.mark.usefixtures( + "get_metadata_store_mock", + "get_experiment_mock", + "create_experiment_run_context_mock", + "add_context_children_mock", + ) + def test_log_params( + self, + update_context_mock, + ): + aiplatform.init( + project=_TEST_PROJECT, + location=_TEST_LOCATION, + experiment=_TEST_EXPERIMENT, + ) + aiplatform.start_run(_TEST_RUN) + aiplatform.log_params(_TEST_PARAMS) + + _TRUE_CONTEXT = copy.deepcopy(_EXPERIMENT_RUN_MOCK) + _TRUE_CONTEXT.metadata[constants._PARAM_KEY].update(_TEST_PARAMS) + + update_context_mock.assert_called_once_with(context=_TRUE_CONTEXT) + + @pytest.mark.usefixtures( + "get_metadata_store_mock", + "get_experiment_mock", + "create_experiment_run_context_mock", + "add_context_children_mock", + ) + def test_log_metrics(self, update_context_mock): + aiplatform.init( + project=_TEST_PROJECT, + location=_TEST_LOCATION, + experiment=_TEST_EXPERIMENT, + ) + aiplatform.start_run(_TEST_RUN) + aiplatform.log_metrics(_TEST_METRICS) + + _TRUE_CONTEXT = copy.deepcopy(_EXPERIMENT_RUN_MOCK) + _TRUE_CONTEXT.metadata[constants._METRIC_KEY].update(_TEST_METRICS) + + update_context_mock.assert_called_once_with(context=_TRUE_CONTEXT) + + @pytest.mark.usefixtures( + "get_metadata_store_mock", + "get_experiment_mock", + "create_experiment_run_context_mock", + "add_context_children_mock", + "get_tensorboard_mock", + "get_tensorboard_run_not_found_mock", + "get_tensorboard_experiment_not_found_mock", + "get_artifact_not_found_mock", + "get_tensorboard_time_series_not_found_mock", + "list_tensorboard_time_series_mock_empty", + ) + def test_log_time_series_metrics( self, - get_execution_mock, + update_context_mock, + create_tensorboard_experiment_mock, + create_tensorboard_run_mock, + create_tensorboard_run_artifact_mock, add_context_artifacts_and_executions_mock, - get_artifact_mock, - add_execution_events_mock, + create_tensorboard_time_series_mock, + batch_read_tensorboard_time_series_mock, + write_tensorboard_run_data_mock, ): + tb = aiplatform.Tensorboard(test_tensorboard._TEST_NAME) + aiplatform.init( - project=_TEST_PROJECT, location=_TEST_LOCATION, experiment=_TEST_EXPERIMENT + project=_TEST_PROJECT, + location=_TEST_LOCATION, + experiment=_TEST_EXPERIMENT, + experiment_tensorboard=tb, ) + + update_context_mock.assert_called_once_with(context=_TEST_EXPERIMENT_CONTEXT) + aiplatform.start_run(_TEST_RUN) + timestamp = utils.get_timestamp_proto() + aiplatform.log_time_series_metrics(_TEST_OTHER_METRICS, wall_time=timestamp) + + create_tensorboard_experiment_mock.assert_called_once_with( + parent=test_tensorboard._TEST_NAME, + tensorboard_experiment_id=_TEST_CONTEXT_ID, + tensorboard_experiment=gca_tensorboard_experiment.TensorboardExperiment( + display_name=experiment_run_resource.ExperimentRun._format_tensorboard_experiment_display_name( + _TEST_CONTEXT_ID + ), + ), + metadata=(), + timeout=None, + ) + + create_tensorboard_run_mock.assert_called_once_with( + parent=test_tensorboard._TEST_TENSORBOARD_EXPERIMENT_NAME, + tensorboard_run_id=_TEST_RUN, + tensorboard_run=gca_tensorboard_run.TensorboardRun( + display_name=_TEST_RUN, + ), + metadata=(), + timeout=None, + ) + + true_tb_run_artifact = copy.deepcopy(_TEST_TENSORBOARD_RUN_ARTIFACT) + true_tb_run_artifact.name = None + + create_tensorboard_run_artifact_mock.assert_called_once_with( + parent=_TEST_PARENT, + artifact=true_tb_run_artifact, + artifact_id=experiment_run_resource.ExperimentRun._tensorboard_run_id( + _TEST_EXECUTION_ID + ), + ) - get_execution_mock.assert_called_once_with(name=_TEST_EXECUTION_NAME) add_context_artifacts_and_executions_mock.assert_called_once_with( - context=_TEST_CONTEXT_NAME, - artifacts=None, - executions=[_TEST_EXECUTION_NAME], + context=_TEST_EXPERIMENT_RUN_CONTEXT_NAME, + artifacts=[_TEST_TENSORBOARD_RUN_ARTIFACT.name], + executions=None, ) - get_artifact_mock.assert_called_once_with(name=_TEST_ARTIFACT_NAME) - add_execution_events_mock.assert_called_once_with( - execution=_TEST_EXECUTION_NAME, - events=[Event(artifact=_TEST_ARTIFACT_NAME, type_=Event.Type.OUTPUT)], + + create_tensorboard_time_series_mock.assert_called_with( + parent=test_tensorboard._TEST_TENSORBOARD_RUN_NAME, + tensorboard_time_series=gca_tensorboard_time_series.TensorboardTimeSeries( + display_name=list(_TEST_OTHER_METRICS.keys())[0], + value_type="SCALAR", + plugin_name="scalars", + ), ) - @pytest.mark.usefixtures("get_metadata_store_mock") - @pytest.mark.usefixtures("get_context_mock") - @pytest.mark.usefixtures("get_execution_wrong_schema_mock") - def test_start_run_with_wrong_run_execution_schema(self,): + ts_data = [ + gca_tensorboard_data.TimeSeriesData( + tensorboard_time_series_id=test_tensorboard._TEST_TENSORBOARD_TIME_SERIES_ID, + value_type=gca_tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR, + values=[ + gca_tensorboard_data.TimeSeriesDataPoint( + scalar=gca_tensorboard_data.Scalar(value=value), + wall_time=timestamp, + step=2, + ) + ], + ) + for value in _TEST_OTHER_METRICS.values() + ] + + write_tensorboard_run_data_mock.assert_called_once_with( + tensorboard_run=test_tensorboard._TEST_TENSORBOARD_RUN_NAME, + time_series_data=ts_data, + ) + + @pytest.mark.usefixtures( + "get_metadata_store_mock", + "get_experiment_mock", + "create_experiment_run_context_mock", + "add_context_children_mock", + ) + def test_log_metrics_nest_value_raises_error(self): aiplatform.init( project=_TEST_PROJECT, location=_TEST_LOCATION, experiment=_TEST_EXPERIMENT ) - with pytest.raises(ValueError): - aiplatform.start_run(_TEST_RUN) + aiplatform.start_run(_TEST_RUN) + with pytest.raises(TypeError): + aiplatform.log_metrics({"test": {"nested": "string"}}) - @pytest.mark.usefixtures("get_metadata_store_mock") - @pytest.mark.usefixtures("get_context_mock") - @pytest.mark.usefixtures("get_execution_mock") - @pytest.mark.usefixtures("add_context_artifacts_and_executions_mock") - @pytest.mark.usefixtures("get_artifact_wrong_schema_mock") - def test_start_run_with_wrong_metrics_artifact_schema(self,): + @pytest.mark.usefixtures( + "get_metadata_store_mock", + "get_experiment_mock", + "create_experiment_run_context_mock", + "add_context_children_mock", + ) + def test_log_params_nest_value_raises_error(self): aiplatform.init( project=_TEST_PROJECT, location=_TEST_LOCATION, experiment=_TEST_EXPERIMENT ) - with pytest.raises(ValueError): - aiplatform.start_run(_TEST_RUN) + aiplatform.start_run(_TEST_RUN) + with pytest.raises(TypeError): + aiplatform.log_params({"test": {"nested": "string"}}) - @pytest.mark.usefixtures("get_metadata_store_mock") - @pytest.mark.usefixtures("get_context_mock") - @pytest.mark.usefixtures("get_execution_mock") - @pytest.mark.usefixtures("add_context_artifacts_and_executions_mock") - @pytest.mark.usefixtures("get_artifact_mock") - @pytest.mark.usefixtures("add_execution_events_mock") - def test_log_params( - self, update_execution_mock, + @pytest.mark.usefixtures( + "get_metadata_store_mock", + "get_experiment_mock", + "create_experiment_run_context_mock", + "add_context_children_mock", + ) + def test_end_run( + self, + update_context_mock, ): aiplatform.init( - project=_TEST_PROJECT, location=_TEST_LOCATION, experiment=_TEST_EXPERIMENT + project=_TEST_PROJECT, + location=_TEST_LOCATION, + experiment=_TEST_EXPERIMENT, ) aiplatform.start_run(_TEST_RUN) - aiplatform.log_params(_TEST_PARAMS) + aiplatform.end_run() - updated_execution = GapicExecution( - name=_TEST_EXECUTION_NAME, - display_name=_TEST_RUN, - schema_title=constants.SYSTEM_RUN, - schema_version=constants.SCHEMA_VERSIONS[constants.SYSTEM_RUN], - metadata=_TEST_PARAMS, - ) + _TRUE_CONTEXT = copy.deepcopy(_EXPERIMENT_RUN_MOCK) + _TRUE_CONTEXT.metadata[ + constants._STATE_KEY + ] = gca_execution.Execution.State.COMPLETE.name - update_execution_mock.assert_called_once_with(execution=updated_execution) + update_context_mock.assert_called_once_with(context=_TRUE_CONTEXT) - @pytest.mark.usefixtures("get_metadata_store_mock") - @pytest.mark.usefixtures("get_context_mock") - @pytest.mark.usefixtures("get_execution_mock") - @pytest.mark.usefixtures("add_context_artifacts_and_executions_mock") - @pytest.mark.usefixtures("get_artifact_mock") - @pytest.mark.usefixtures("add_execution_events_mock") - def test_log_metrics( - self, update_artifact_mock, + @pytest.mark.usefixtures( + "get_metadata_store_mock", + "get_experiment_mock", + "create_experiment_run_context_mock", + "get_pipeline_job_mock", + ) + def test_log_pipeline_job( + self, + add_context_children_mock, ): aiplatform.init( - project=_TEST_PROJECT, location=_TEST_LOCATION, experiment=_TEST_EXPERIMENT + project=_TEST_PROJECT, + location=_TEST_LOCATION, + experiment=_TEST_EXPERIMENT, ) aiplatform.start_run(_TEST_RUN) - aiplatform.log_metrics(_TEST_METRICS) - updated_artifact = GapicArtifact( - name=_TEST_ARTIFACT_NAME, - display_name=_TEST_ARTIFACT_ID, - schema_title=constants.SYSTEM_METRICS, - schema_version=constants.SCHEMA_VERSIONS[constants.SYSTEM_METRICS], - metadata=_TEST_METRICS, + pipeline_job = aiplatform.PipelineJob.get( + test_pipeline_jobs._TEST_PIPELINE_JOB_ID ) + pipeline_job.wait() - update_artifact_mock.assert_called_once_with(artifact=updated_artifact) + aiplatform.log(pipeline_job=pipeline_job) - @pytest.mark.usefixtures("get_metadata_store_mock") - @pytest.mark.usefixtures("get_context_mock") - @pytest.mark.usefixtures("get_execution_mock") - @pytest.mark.usefixtures("add_context_artifacts_and_executions_mock") - @pytest.mark.usefixtures("get_artifact_mock") - @pytest.mark.usefixtures("add_execution_events_mock") - def test_log_metrics_string_value_raise_error(self): - aiplatform.init( - project=_TEST_PROJECT, location=_TEST_LOCATION, experiment=_TEST_EXPERIMENT + add_context_children_mock.assert_called_with( + context=_EXPERIMENT_RUN_MOCK.name, + child_contexts=[ + pipeline_job.gca_resource.job_detail.pipeline_run_context.name + ], ) - aiplatform.start_run(_TEST_RUN) - with pytest.raises(TypeError): - aiplatform.log_metrics({"test": "string"}) - @pytest.mark.usefixtures("get_context_mock") + @pytest.mark.usefixtures( + "get_experiment_mock", + "list_tensorboard_time_series_mock", + "batch_read_tensorboard_time_series_mock", + ) def test_get_experiment_df( - self, list_executions_mock, query_execution_inputs_and_outputs_mock + self, + list_context_mock_for_experiment_dataframe_mock, + list_artifact_mock_for_experiment_dataframe, + list_executions_mock_for_experiment_dataframe, + get_tensorboard_run_artifact_mock, + get_tensorboard_run_mock, ): - try: - import pandas as pd - except ImportError: - raise ImportError( - "Pandas is not installed and is required to test the get_experiment_df method. " - 'Please install the SDK using "pip install python-aiplatform[full]"' - ) + import pandas as pd + aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) experiment_df = aiplatform.get_experiment_df(_TEST_EXPERIMENT) - expected_filter = f'schema_title="{constants.SYSTEM_RUN}" AND in_context("{_TEST_CONTEXT_NAME}")' - list_executions_mock.assert_called_once_with( - request=ListExecutionsRequest(parent=_TEST_PARENT, filter=expected_filter,) + expected_filter = metadata_utils._make_filter_string( + parent_contexts=[_TEST_CONTEXT_NAME], + schema_title=[ + constants.SYSTEM_EXPERIMENT_RUN, + constants.SYSTEM_PIPELINE_RUN, + ], ) - query_execution_inputs_and_outputs_mock.assert_has_calls( - [ - call(execution=_TEST_EXECUTION_NAME), - call(execution=_TEST_OTHER_EXECUTION_NAME), - ] + + list_context_mock_for_experiment_dataframe_mock.assert_called_once_with( + request=dict(parent=_TEST_PARENT, filter=expected_filter) + ) + + expected_legacy_filter = metadata_utils._make_filter_string( + in_context=[_TEST_CONTEXT_NAME], schema_title=[constants.SYSTEM_RUN] ) + expected_pipeline_filter = metadata_utils._make_filter_string( + in_context=[_TEST_PIPELINE_CONTEXT.name], schema_title=constants.SYSTEM_RUN + ) + + list_executions_mock_for_experiment_dataframe.assert_has_calls( + calls=[ + call(request=dict(parent=_TEST_PARENT, filter=expected_legacy_filter)), + call( + request=dict(parent=_TEST_PARENT, filter=expected_pipeline_filter) + ), + ], + any_order=False, + ) + + expected_filter = metadata_utils._make_filter_string( + in_context=[_TEST_PIPELINE_CONTEXT.name], + schema_title=constants.SYSTEM_METRICS, + ) + + list_artifact_mock_for_experiment_dataframe.assert_has_calls( + calls=[call(request=dict(parent=_TEST_PARENT, filter=expected_filter))], + any_order=False, + ) + experiment_df_truth = pd.DataFrame( [ { "experiment_name": _TEST_EXPERIMENT, + "run_type": constants.SYSTEM_EXPERIMENT_RUN, + "state": gca_execution.Execution.State.RUNNING.name, "run_name": _TEST_RUN, - "param.%s" % _TEST_PARAM_KEY_1: 0.01, - "param.%s" % _TEST_PARAM_KEY_2: 0.2, - "metric.%s" % _TEST_METRIC_KEY_1: 222, - "metric.%s" % _TEST_METRIC_KEY_2: 1, + "param.%s" % _TEST_PARAM_KEY_1: _TEST_PARAMS[_TEST_PARAM_KEY_1], + "param.%s" % _TEST_PARAM_KEY_2: _TEST_PARAMS[_TEST_PARAM_KEY_2], + "metric.%s" % _TEST_METRIC_KEY_1: _TEST_METRICS[_TEST_METRIC_KEY_1], + "metric.%s" % _TEST_METRIC_KEY_2: _TEST_METRICS[_TEST_METRIC_KEY_2], + "time_series_metric.accuracy": test_tensorboard._TEST_TENSORBOARD_TIME_SERIES_DATA.values[ + 0 + ].scalar.value, }, { "experiment_name": _TEST_EXPERIMENT, + "run_type": constants.SYSTEM_EXPERIMENT_RUN, + "state": gca_execution.Execution.State.RUNNING.name, "run_name": _TEST_OTHER_RUN, - "param.%s" % _TEST_PARAM_KEY_1: 0.02, - "param.%s" % _TEST_PARAM_KEY_2: 0.3, - "metric.%s" % _TEST_METRIC_KEY_2: 0.9, + "param.%s" + % _TEST_PARAM_KEY_1: _TEST_OTHER_PARAMS[_TEST_PARAM_KEY_1], + "param.%s" + % _TEST_PARAM_KEY_2: _TEST_OTHER_PARAMS[_TEST_PARAM_KEY_2], + "metric.%s" + % _TEST_METRIC_KEY_2: _TEST_OTHER_METRICS[_TEST_METRIC_KEY_2], + }, + { + "experiment_name": _TEST_EXPERIMENT, + "run_type": constants.SYSTEM_PIPELINE_RUN, + "state": gca_execution.Execution.State.RUNNING.name, + "run_name": _TEST_PIPELINE_RUN_ID, + "param.%s" % _TEST_PARAM_KEY_1: _TEST_PARAMS[_TEST_PARAM_KEY_1] + 1, + "param.%s" % _TEST_PARAM_KEY_2: _TEST_PARAMS[_TEST_PARAM_KEY_2] + 1, + "metric.%s" % _TEST_METRIC_KEY_1: _TEST_METRICS[_TEST_METRIC_KEY_1] + + 1, + "metric.%s" % _TEST_METRIC_KEY_2: _TEST_METRICS[_TEST_METRIC_KEY_2] + + 1, + }, + { + "experiment_name": _TEST_EXPERIMENT, + "run_type": constants.SYSTEM_RUN, + "state": gca_execution.Execution.State.STATE_UNSPECIFIED.name, + "run_name": _TEST_RUN, + "param.%s" % _TEST_PARAM_KEY_1: _TEST_PARAMS[_TEST_PARAM_KEY_1], + "param.%s" % _TEST_PARAM_KEY_2: _TEST_PARAMS[_TEST_PARAM_KEY_2], + "metric.%s" % _TEST_METRIC_KEY_1: _TEST_METRICS[_TEST_METRIC_KEY_1], + "metric.%s" % _TEST_METRIC_KEY_2: _TEST_METRICS[_TEST_METRIC_KEY_2], }, ] ) @@ -600,62 +1380,3 @@ def test_get_experiment_df_wrong_schema(self): aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) with pytest.raises(ValueError): aiplatform.get_experiment_df(_TEST_EXPERIMENT) - - @pytest.mark.usefixtures("get_pipeline_context_mock") - def test_get_pipeline_df( - self, list_executions_mock, query_execution_inputs_and_outputs_mock - ): - try: - import pandas as pd - except ImportError: - raise ImportError( - "Pandas is not installed and is required to test the get_pipeline_df method. " - 'Please install the SDK using "pip install python-aiplatform[full]"' - ) - aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) - - pipeline_df = aiplatform.get_pipeline_df(_TEST_PIPELINE) - - expected_filter = f'schema_title="{constants.SYSTEM_RUN}" AND in_context("{_TEST_CONTEXT_NAME}")' - list_executions_mock.assert_called_once_with( - request=ListExecutionsRequest(parent=_TEST_PARENT, filter=expected_filter,) - ) - query_execution_inputs_and_outputs_mock.assert_has_calls( - [ - call(execution=_TEST_EXECUTION_NAME), - call(execution=_TEST_OTHER_EXECUTION_NAME), - ] - ) - pipeline_df_truth = pd.DataFrame( - [ - { - "pipeline_name": _TEST_PIPELINE, - "run_name": _TEST_RUN, - "param.%s" % _TEST_PARAM_KEY_1: 0.01, - "param.%s" % _TEST_PARAM_KEY_2: 0.2, - "metric.%s" % _TEST_METRIC_KEY_1: 222, - "metric.%s" % _TEST_METRIC_KEY_2: 1, - }, - { - "pipeline_name": _TEST_PIPELINE, - "run_name": _TEST_OTHER_RUN, - "param.%s" % _TEST_PARAM_KEY_1: 0.02, - "param.%s" % _TEST_PARAM_KEY_2: 0.3, - "metric.%s" % _TEST_METRIC_KEY_2: 0.9, - }, - ] - ) - - _assert_frame_equal_with_sorted_columns(pipeline_df, pipeline_df_truth) - - @pytest.mark.usefixtures("get_context_not_found_mock") - def test_get_pipeline_df_not_exist(self): - aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) - with pytest.raises(exceptions.NotFound): - aiplatform.get_pipeline_df(_TEST_PIPELINE) - - @pytest.mark.usefixtures("get_context_mock") - def test_get_pipeline_df_wrong_schema(self): - aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) - with pytest.raises(ValueError): - aiplatform.get_pipeline_df(_TEST_PIPELINE) diff --git a/tests/unit/aiplatform/test_metadata_resources.py b/tests/unit/aiplatform/test_metadata_resources.py index 19258aef3c..f78f3a1a92 100644 --- a/tests/unit/aiplatform/test_metadata_resources.py +++ b/tests/unit/aiplatform/test_metadata_resources.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2021 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -22,22 +22,21 @@ from google.api_core import exceptions from google.cloud import aiplatform +from google.cloud.aiplatform import base from google.cloud.aiplatform import initializer +from google.cloud.aiplatform.compat.types import event as gca_event from google.cloud.aiplatform.metadata import artifact from google.cloud.aiplatform.metadata import context from google.cloud.aiplatform.metadata import execution -from google.cloud.aiplatform_v1beta1 import AddContextArtifactsAndExecutionsResponse -from google.cloud.aiplatform_v1beta1 import Artifact as GapicArtifact -from google.cloud.aiplatform_v1beta1 import Context as GapicContext -from google.cloud.aiplatform_v1beta1 import Execution as GapicExecution -from google.cloud.aiplatform_v1beta1 import LineageSubgraph -from google.cloud.aiplatform_v1beta1 import ( +from google.cloud.aiplatform_v1 import AddContextArtifactsAndExecutionsResponse +from google.cloud.aiplatform_v1 import Artifact as GapicArtifact +from google.cloud.aiplatform_v1 import Context as GapicContext +from google.cloud.aiplatform_v1 import Execution as GapicExecution +from google.cloud.aiplatform_v1 import LineageSubgraph +from google.cloud.aiplatform_v1 import ( MetadataServiceClient, AddExecutionEventsResponse, Event, - ListExecutionsRequest, - ListArtifactsRequest, - ListContextsRequest, ) # project @@ -197,6 +196,7 @@ def create_execution_mock(): schema_version=_TEST_SCHEMA_VERSION, description=_TEST_DESCRIPTION, metadata=_TEST_METADATA, + state=GapicExecution.State.RUNNING, ) yield create_execution_mock @@ -240,14 +240,13 @@ def query_execution_inputs_and_outputs_mock(): description=_TEST_DESCRIPTION, metadata=_TEST_METADATA, ), - GapicArtifact( - name=_TEST_ARTIFACT_NAME, - display_name=_TEST_DISPLAY_NAME, - schema_title=_TEST_SCHEMA_TITLE, - schema_version=_TEST_SCHEMA_VERSION, - description=_TEST_DESCRIPTION, - metadata=_TEST_METADATA, - ), + ], + events=[ + gca_event.Event( + artifact=_TEST_ARTIFACT_NAME, + execution=_TEST_EXECUTION_NAME, + type_=gca_event.Event.Type.OUTPUT, + ) ], ) yield query_execution_inputs_and_outputs_mock @@ -265,6 +264,7 @@ def update_execution_mock(): schema_version=_TEST_SCHEMA_VERSION, description=_TEST_DESCRIPTION, metadata=_TEST_UPDATED_METADATA, + state=GapicExecution.State.RUNNING, ) yield update_execution_mock @@ -313,6 +313,7 @@ def create_artifact_mock(): schema_version=_TEST_SCHEMA_VERSION, description=_TEST_DESCRIPTION, metadata=_TEST_METADATA, + state=GapicArtifact.State.LIVE, ) yield create_artifact_mock @@ -351,10 +352,12 @@ def update_artifact_mock(): schema_version=_TEST_SCHEMA_VERSION, description=_TEST_DESCRIPTION, metadata=_TEST_UPDATED_METADATA, + state=GapicArtifact.State.LIVE, ) yield update_artifact_mock +@pytest.mark.usefixtures("google_auth_mock") class TestContext: def setup_method(self): reload(initializer) @@ -366,14 +369,18 @@ def teardown_method(self): def test_init_context(self, get_context_mock): aiplatform.init(project=_TEST_PROJECT) context._Context(resource_name=_TEST_CONTEXT_NAME) - get_context_mock.assert_called_once_with(name=_TEST_CONTEXT_NAME) + get_context_mock.assert_called_once_with( + name=_TEST_CONTEXT_NAME, retry=base._DEFAULT_RETRY + ) def test_init_context_with_id(self, get_context_mock): aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) context._Context( resource_name=_TEST_CONTEXT_ID, metadata_store_id=_TEST_METADATA_STORE ) - get_context_mock.assert_called_once_with(name=_TEST_CONTEXT_NAME) + get_context_mock.assert_called_once_with( + name=_TEST_CONTEXT_NAME, retry=base._DEFAULT_RETRY + ) def test_get_or_create_context( self, get_context_for_get_or_create_mock, create_context_mock @@ -398,10 +405,12 @@ def test_get_or_create_context( metadata=_TEST_METADATA, ) get_context_for_get_or_create_mock.assert_called_once_with( - name=_TEST_CONTEXT_NAME + name=_TEST_CONTEXT_NAME, retry=base._DEFAULT_RETRY ) create_context_mock.assert_called_once_with( - parent=_TEST_PARENT, context_id=_TEST_CONTEXT_ID, context=expected_context, + parent=_TEST_PARENT, + context_id=_TEST_CONTEXT_ID, + context=expected_context, ) expected_context.name = _TEST_CONTEXT_NAME @@ -454,7 +463,10 @@ def test_list_contexts(self, list_contexts_mock): ) list_contexts_mock.assert_called_once_with( - request=ListContextsRequest(parent=_TEST_PARENT, filter=filter,) + request={ + "parent": _TEST_PARENT, + "filter": filter, + } ) assert len(context_list) == 2 assert context_list[0]._gca_resource == expected_context @@ -541,22 +553,26 @@ def teardown_method(self): def test_init_execution(self, get_execution_mock): aiplatform.init(project=_TEST_PROJECT) - execution._Execution(resource_name=_TEST_EXECUTION_NAME) - get_execution_mock.assert_called_once_with(name=_TEST_EXECUTION_NAME) + execution.Execution(execution_name=_TEST_EXECUTION_NAME) + get_execution_mock.assert_called_once_with( + name=_TEST_EXECUTION_NAME, retry=base._DEFAULT_RETRY + ) def test_init_execution_with_id(self, get_execution_mock): aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) - execution._Execution( - resource_name=_TEST_EXECUTION_ID, metadata_store_id=_TEST_METADATA_STORE + execution.Execution( + execution_name=_TEST_EXECUTION_ID, metadata_store_id=_TEST_METADATA_STORE + ) + get_execution_mock.assert_called_once_with( + name=_TEST_EXECUTION_NAME, retry=base._DEFAULT_RETRY ) - get_execution_mock.assert_called_once_with(name=_TEST_EXECUTION_NAME) def test_get_or_create_execution( self, get_execution_for_get_or_create_mock, create_execution_mock ): aiplatform.init(project=_TEST_PROJECT) - my_execution = execution._Execution.get_or_create( + my_execution = execution.Execution.get_or_create( resource_id=_TEST_EXECUTION_ID, schema_title=_TEST_SCHEMA_TITLE, display_name=_TEST_DISPLAY_NAME, @@ -572,9 +588,10 @@ def test_get_or_create_execution( display_name=_TEST_DISPLAY_NAME, description=_TEST_DESCRIPTION, metadata=_TEST_METADATA, + state=GapicExecution.State.RUNNING, ) get_execution_for_get_or_create_mock.assert_called_once_with( - name=_TEST_EXECUTION_NAME + name=_TEST_EXECUTION_NAME, retry=base._DEFAULT_RETRY ) create_execution_mock.assert_called_once_with( parent=_TEST_PARENT, @@ -590,7 +607,7 @@ def test_get_or_create_execution( def test_update_execution(self, update_execution_mock): aiplatform.init(project=_TEST_PROJECT) - my_execution = execution._Execution._create( + my_execution = execution.Execution._create( resource_id=_TEST_EXECUTION_ID, schema_title=_TEST_SCHEMA_TITLE, display_name=_TEST_DISPLAY_NAME, @@ -599,7 +616,7 @@ def test_update_execution(self, update_execution_mock): metadata=_TEST_METADATA, metadata_store_id=_TEST_METADATA_STORE, ) - my_execution.update(_TEST_UPDATED_METADATA) + my_execution.update(metadata=_TEST_UPDATED_METADATA) updated_execution = GapicExecution( name=_TEST_EXECUTION_NAME, @@ -608,6 +625,7 @@ def test_update_execution(self, update_execution_mock): display_name=_TEST_DISPLAY_NAME, description=_TEST_DESCRIPTION, metadata=_TEST_UPDATED_METADATA, + state=GapicExecution.State.RUNNING, ) update_execution_mock.assert_called_once_with(execution=updated_execution) @@ -618,7 +636,7 @@ def test_list_executions(self, list_executions_mock): aiplatform.init(project=_TEST_PROJECT) filter = "test-filter" - execution_list = execution._Execution.list( + execution_list = execution.Execution.list( filter=filter, metadata_store_id=_TEST_METADATA_STORE ) @@ -632,17 +650,20 @@ def test_list_executions(self, list_executions_mock): ) list_executions_mock.assert_called_once_with( - request=ListExecutionsRequest(parent=_TEST_PARENT, filter=filter,) + request=dict( + parent=_TEST_PARENT, + filter=filter, + ) ) assert len(execution_list) == 2 assert execution_list[0]._gca_resource == expected_execution assert execution_list[1]._gca_resource == expected_execution - @pytest.mark.usefixtures("get_execution_mock") + @pytest.mark.usefixtures("get_execution_mock", "get_artifact_mock") def test_add_artifact(self, add_execution_events_mock): aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) - my_execution = execution._Execution.get_or_create( + my_execution = execution.Execution.get_or_create( resource_id=_TEST_EXECUTION_ID, schema_title=_TEST_SCHEMA_TITLE, display_name=_TEST_DISPLAY_NAME, @@ -651,9 +672,9 @@ def test_add_artifact(self, add_execution_events_mock): metadata=_TEST_METADATA, metadata_store_id=_TEST_METADATA_STORE, ) - my_execution.add_artifact( - artifact_resource_name=_TEST_ARTIFACT_NAME, input=False, - ) + + my_artifact = aiplatform.Artifact(_TEST_ARTIFACT_ID) + my_execution.assign_output_artifacts(artifacts=[my_artifact]) add_execution_events_mock.assert_called_once_with( execution=_TEST_EXECUTION_NAME, events=[Event(artifact=_TEST_ARTIFACT_NAME, type_=Event.Type.OUTPUT)], @@ -664,7 +685,7 @@ def test_query_input_and_output_artifacts( self, query_execution_inputs_and_outputs_mock ): aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) - my_execution = execution._Execution.get_or_create( + my_execution = execution.Execution.get_or_create( resource_id=_TEST_EXECUTION_ID, schema_title=_TEST_SCHEMA_TITLE, display_name=_TEST_DISPLAY_NAME, @@ -674,7 +695,7 @@ def test_query_input_and_output_artifacts( metadata_store_id=_TEST_METADATA_STORE, ) - artifact_list = my_execution.query_input_and_output_artifacts() + artifact_list = my_execution.get_output_artifacts() expected_artifact = GapicArtifact( name=_TEST_ARTIFACT_NAME, @@ -688,9 +709,8 @@ def test_query_input_and_output_artifacts( query_execution_inputs_and_outputs_mock.assert_called_once_with( execution=_TEST_EXECUTION_NAME, ) - assert len(artifact_list) == 2 + assert len(artifact_list) == 1 assert artifact_list[0]._gca_resource == expected_artifact - assert artifact_list[1]._gca_resource == expected_artifact class TestArtifact: @@ -703,22 +723,26 @@ def teardown_method(self): def test_init_artifact(self, get_artifact_mock): aiplatform.init(project=_TEST_PROJECT) - artifact._Artifact(resource_name=_TEST_ARTIFACT_NAME) - get_artifact_mock.assert_called_once_with(name=_TEST_ARTIFACT_NAME) + artifact.Artifact(artifact_name=_TEST_ARTIFACT_NAME) + get_artifact_mock.assert_called_once_with( + name=_TEST_ARTIFACT_NAME, retry=base._DEFAULT_RETRY + ) def test_init_artifact_with_id(self, get_artifact_mock): aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) - artifact._Artifact( - resource_name=_TEST_ARTIFACT_ID, metadata_store_id=_TEST_METADATA_STORE + artifact.Artifact( + artifact_name=_TEST_ARTIFACT_ID, metadata_store_id=_TEST_METADATA_STORE + ) + get_artifact_mock.assert_called_once_with( + name=_TEST_ARTIFACT_NAME, retry=base._DEFAULT_RETRY ) - get_artifact_mock.assert_called_once_with(name=_TEST_ARTIFACT_NAME) def test_get_or_create_artifact( self, get_artifact_for_get_or_create_mock, create_artifact_mock ): aiplatform.init(project=_TEST_PROJECT) - my_artifact = artifact._Artifact.get_or_create( + my_artifact = artifact.Artifact.get_or_create( resource_id=_TEST_ARTIFACT_ID, schema_title=_TEST_SCHEMA_TITLE, display_name=_TEST_DISPLAY_NAME, @@ -734,9 +758,10 @@ def test_get_or_create_artifact( display_name=_TEST_DISPLAY_NAME, description=_TEST_DESCRIPTION, metadata=_TEST_METADATA, + state=GapicArtifact.State.LIVE, ) get_artifact_for_get_or_create_mock.assert_called_once_with( - name=_TEST_ARTIFACT_NAME + name=_TEST_ARTIFACT_NAME, retry=base._DEFAULT_RETRY ) create_artifact_mock.assert_called_once_with( parent=_TEST_PARENT, @@ -752,7 +777,7 @@ def test_get_or_create_artifact( def test_update_artifact(self, update_artifact_mock): aiplatform.init(project=_TEST_PROJECT) - my_artifact = artifact._Artifact._create( + my_artifact = artifact.Artifact._create( resource_id=_TEST_ARTIFACT_ID, schema_title=_TEST_SCHEMA_TITLE, display_name=_TEST_DISPLAY_NAME, @@ -761,7 +786,7 @@ def test_update_artifact(self, update_artifact_mock): metadata=_TEST_METADATA, metadata_store_id=_TEST_METADATA_STORE, ) - my_artifact.update(_TEST_UPDATED_METADATA) + my_artifact.update(metadata=_TEST_UPDATED_METADATA) updated_artifact = GapicArtifact( name=_TEST_ARTIFACT_NAME, @@ -770,6 +795,7 @@ def test_update_artifact(self, update_artifact_mock): display_name=_TEST_DISPLAY_NAME, description=_TEST_DESCRIPTION, metadata=_TEST_UPDATED_METADATA, + state=GapicArtifact.State.LIVE, ) update_artifact_mock.assert_called_once_with(artifact=updated_artifact) @@ -780,7 +806,7 @@ def test_list_artifacts(self, list_artifacts_mock): aiplatform.init(project=_TEST_PROJECT) filter = "test-filter" - artifact_list = artifact._Artifact.list( + artifact_list = artifact.Artifact.list( filter=filter, metadata_store_id=_TEST_METADATA_STORE ) @@ -794,7 +820,10 @@ def test_list_artifacts(self, list_artifacts_mock): ) list_artifacts_mock.assert_called_once_with( - request=ListArtifactsRequest(parent=_TEST_PARENT, filter=filter,) + request=dict( + parent=_TEST_PARENT, + filter=filter, + ) ) assert len(artifact_list) == 2 assert artifact_list[0]._gca_resource == expected_artifact diff --git a/tests/unit/aiplatform/test_metadata_schema.py b/tests/unit/aiplatform/test_metadata_schema.py new file mode 100644 index 0000000000..cbf7d38609 --- /dev/null +++ b/tests/unit/aiplatform/test_metadata_schema.py @@ -0,0 +1,563 @@ +# -*- coding: utf-8 -*- + +# Copyright 2022 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. +# + +import json +import pytest + +from importlib import reload +from unittest import mock +from unittest.mock import patch + +from google.cloud import aiplatform +from google.cloud.aiplatform import initializer +from google.cloud.aiplatform.compat.types import artifact as gca_artifact +from google.cloud.aiplatform.compat.types import execution as gca_execution +from google.cloud.aiplatform.metadata import metadata +from google.cloud.aiplatform.metadata.schema import base_artifact +from google.cloud.aiplatform.metadata.schema import base_execution +from google.cloud.aiplatform.metadata.schema.google import ( + artifact_schema as google_artifact_schema, +) +from google.cloud.aiplatform.metadata.schema.system import ( + artifact_schema as system_artifact_schema, +) +from google.cloud.aiplatform.metadata.schema.system import ( + execution_schema as system_execution_schema, +) +from google.cloud.aiplatform.metadata.schema import utils +from google.cloud.aiplatform_v1 import MetadataServiceClient +from google.cloud.aiplatform_v1 import Artifact as GapicArtifact +from google.cloud.aiplatform_v1 import Execution as GapicExecution + + +# project +_TEST_PROJECT = "test-project" +_TEST_LOCATION = "us-central1" +_TEST_METADATA_STORE = "test-metadata-store" +_TEST_PARENT = f"projects/{_TEST_PROJECT}/locations/{_TEST_LOCATION}" + +# resource attributes +_TEST_ARTIFACT_STATE = gca_artifact.Artifact.State.STATE_UNSPECIFIED +_TEST_EXECUTION_STATE = gca_execution.Execution.State.STATE_UNSPECIFIED +_TEST_URI = "test-uri" +_TEST_DISPLAY_NAME = "test-display-name" +_TEST_SCHEMA_TITLE = "test.Example" +_TEST_SCHEMA_VERSION = "0.0.1" +_TEST_DESCRIPTION = "test description" +_TEST_METADATA = {"test-param1": 1, "test-param2": "test-value", "test-param3": True} +_TEST_UPDATED_METADATA = { + "test-param1": 2, + "test-param2": "test-value-1", + "test-param3": False, +} + +# artifact +_TEST_ARTIFACT_ID = "test-artifact-id" +_TEST_ARTIFACT_NAME = f"{_TEST_PARENT}/artifacts/{_TEST_ARTIFACT_ID}" + +# execution +_TEST_EXECUTION_ID = "test-execution-id" +_TEST_EXECUTION_NAME = f"{_TEST_PARENT}/executions/{_TEST_EXECUTION_ID}" + + +@pytest.fixture +def create_artifact_mock(): + with patch.object(MetadataServiceClient, "create_artifact") as create_artifact_mock: + create_artifact_mock.return_value = GapicArtifact( + name=_TEST_ARTIFACT_NAME, + display_name=_TEST_DISPLAY_NAME, + schema_title=_TEST_SCHEMA_TITLE, + schema_version=_TEST_SCHEMA_VERSION, + description=_TEST_DESCRIPTION, + metadata=_TEST_METADATA, + state=GapicArtifact.State.STATE_UNSPECIFIED, + ) + yield create_artifact_mock + + +@pytest.fixture +def create_execution_mock(): + with patch.object( + MetadataServiceClient, "create_execution" + ) as create_execution_mock: + create_execution_mock.return_value = GapicExecution( + name=_TEST_EXECUTION_NAME, + display_name=_TEST_DISPLAY_NAME, + schema_title=_TEST_SCHEMA_TITLE, + schema_version=_TEST_SCHEMA_VERSION, + description=_TEST_DESCRIPTION, + metadata=_TEST_METADATA, + state=GapicExecution.State.RUNNING, + ) + yield create_execution_mock + + +class TestMetadataBaseArtifactSchema: + def setup_method(self): + reload(initializer) + reload(metadata) + reload(aiplatform) + + def teardown_method(self): + initializer.global_pool.shutdown(wait=True) + + def test_base_class_instatiated_uses_schema_title(self): + class TestArtifact(base_artifact.BaseArtifactSchema): + schema_title = _TEST_SCHEMA_TITLE + + artifact = TestArtifact() + assert artifact.schema_title == _TEST_SCHEMA_TITLE + + def test_base_class_parameters_overrides_default_values(self): + class TestArtifact(base_artifact.BaseArtifactSchema): + schema_title = _TEST_SCHEMA_TITLE + + artifact = TestArtifact( + state=_TEST_ARTIFACT_STATE, + schema_version=_TEST_SCHEMA_VERSION, + artifact_id=_TEST_ARTIFACT_ID, + uri=_TEST_URI, + display_name=_TEST_DISPLAY_NAME, + description=_TEST_DESCRIPTION, + metadata=_TEST_UPDATED_METADATA, + ) + assert artifact.state == _TEST_ARTIFACT_STATE + assert artifact.state == _TEST_ARTIFACT_STATE + assert artifact.schema_version == _TEST_SCHEMA_VERSION + assert artifact.artifact_id == _TEST_ARTIFACT_ID + assert artifact.schema_title == _TEST_SCHEMA_TITLE + assert artifact.uri == _TEST_URI + assert artifact.display_name == _TEST_DISPLAY_NAME + assert artifact.description == _TEST_DESCRIPTION + assert artifact.metadata == _TEST_UPDATED_METADATA + + def test_base_class_without_schema_title_raises_error(self): + with pytest.raises(TypeError): + base_artifact.BaseArtifactSchema() + + @pytest.mark.usefixtures("create_artifact_mock") + def test_create_is_called_with_default_parameters(self, create_artifact_mock): + aiplatform.init(project=_TEST_PROJECT) + + class TestArtifact(base_artifact.BaseArtifactSchema): + schema_title = _TEST_SCHEMA_TITLE + + artifact = TestArtifact( + uri=_TEST_URI, + display_name=_TEST_DISPLAY_NAME, + description=_TEST_DESCRIPTION, + metadata=_TEST_UPDATED_METADATA, + state=_TEST_ARTIFACT_STATE, + ) + artifact.create(metadata_store_id=_TEST_METADATA_STORE) + create_artifact_mock.assert_called_once_with( + parent=f"{_TEST_PARENT}/metadataStores/{_TEST_METADATA_STORE}", + artifact=mock.ANY, + artifact_id=None, + ) + _, _, kwargs = create_artifact_mock.mock_calls[0] + assert kwargs["artifact"].schema_title == _TEST_SCHEMA_TITLE + assert kwargs["artifact"].uri == _TEST_URI + assert kwargs["artifact"].display_name == _TEST_DISPLAY_NAME + assert kwargs["artifact"].description == _TEST_DESCRIPTION + assert kwargs["artifact"].metadata == _TEST_UPDATED_METADATA + assert kwargs["artifact"].state == _TEST_ARTIFACT_STATE + + +class TestMetadataBaseExecutionSchema: + def setup_method(self): + reload(initializer) + reload(metadata) + reload(aiplatform) + + def teardown_method(self): + initializer.global_pool.shutdown(wait=True) + + def test_base_class_overrides_default_schema_title(self): + class TestExecution(base_execution.BaseExecutionSchema): + schema_title = _TEST_SCHEMA_TITLE + + execution = TestExecution() + assert execution.schema_title == _TEST_SCHEMA_TITLE + + def test_base_class_parameters_overrides_default_values(self): + class TestExecution(base_execution.BaseExecutionSchema): + schema_title = _TEST_SCHEMA_TITLE + + execution = TestExecution( + state=_TEST_EXECUTION_STATE, + schema_version=_TEST_SCHEMA_VERSION, + execution_id=_TEST_EXECUTION_ID, + display_name=_TEST_DISPLAY_NAME, + description=_TEST_DESCRIPTION, + metadata=_TEST_UPDATED_METADATA, + ) + assert execution.state == _TEST_EXECUTION_STATE + assert execution.schema_version == _TEST_SCHEMA_VERSION + assert execution.execution_id == _TEST_EXECUTION_ID + assert execution.schema_title == _TEST_SCHEMA_TITLE + assert execution.display_name == _TEST_DISPLAY_NAME + assert execution.description == _TEST_DESCRIPTION + assert execution.metadata == _TEST_UPDATED_METADATA + + def test_base_class_without_schema_title_raises_error(self): + with pytest.raises(TypeError): + base_execution.BaseExecutionSchema() + + @pytest.mark.usefixtures("create_execution_mock") + def test_create_method_calls_gapic_library_with_correct_parameters( + self, create_execution_mock + ): + aiplatform.init(project=_TEST_PROJECT) + + class TestExecution(base_execution.BaseExecutionSchema): + schema_title = _TEST_SCHEMA_TITLE + + execution = TestExecution( + state=_TEST_EXECUTION_STATE, + display_name=_TEST_DISPLAY_NAME, + description=_TEST_DESCRIPTION, + metadata=_TEST_UPDATED_METADATA, + ) + execution.create(metadata_store_id=_TEST_METADATA_STORE) + create_execution_mock.assert_called_once_with( + parent=f"{_TEST_PARENT}/metadataStores/{_TEST_METADATA_STORE}", + execution=mock.ANY, + execution_id=None, + ) + _, _, kwargs = create_execution_mock.mock_calls[0] + assert kwargs["execution"].schema_title == _TEST_SCHEMA_TITLE + assert kwargs["execution"].state == _TEST_EXECUTION_STATE + assert kwargs["execution"].display_name == _TEST_DISPLAY_NAME + assert kwargs["execution"].description == _TEST_DESCRIPTION + assert kwargs["execution"].metadata == _TEST_UPDATED_METADATA + + +class TestMetadataGoogleArtifactSchema: + def setup_method(self): + reload(initializer) + reload(metadata) + reload(aiplatform) + + def teardown_method(self): + initializer.global_pool.shutdown(wait=True) + + def test_vertex_dataset_schema_title_is_set_correctly(self): + artifact = google_artifact_schema.VertexDataset( + vertex_dataset_name=_TEST_ARTIFACT_NAME, + ) + assert artifact.schema_title == "google.VertexDataset" + + def test_vertex_dataset_constructor_parameters_are_set_correctly(self): + artifact = google_artifact_schema.VertexDataset( + vertex_dataset_name=f"{_TEST_PARENT}/datasets/dataset-id", + display_name=_TEST_DISPLAY_NAME, + schema_version=_TEST_SCHEMA_VERSION, + description=_TEST_DESCRIPTION, + metadata={}, + ) + assert ( + artifact.uri + == "https://us-central1-aiplatform.googleapis.com/v1/projects/test-project/locations/us-central1/datasets/dataset-id" + ) + assert artifact.display_name == _TEST_DISPLAY_NAME + assert artifact.description == _TEST_DESCRIPTION + assert artifact.metadata == { + "resourceName": "projects/test-project/locations/us-central1/datasets/dataset-id" + } + assert artifact.schema_version == _TEST_SCHEMA_VERSION + + def test_vertex_model_schema_title_is_set_correctly(self): + artifact = google_artifact_schema.VertexModel( + vertex_model_name=_TEST_ARTIFACT_NAME, + ) + assert artifact.schema_title == "google.VertexModel" + + def test_vertex_model_constructor_parameters_are_set_correctly(self): + artifact = google_artifact_schema.VertexModel( + vertex_model_name=f"{_TEST_PARENT}/models/model-id", + display_name=_TEST_DISPLAY_NAME, + schema_version=_TEST_SCHEMA_VERSION, + description=_TEST_DESCRIPTION, + metadata={}, + ) + assert ( + artifact.uri + == "https://us-central1-aiplatform.googleapis.com/v1/projects/test-project/locations/us-central1/models/model-id" + ) + assert artifact.display_name == _TEST_DISPLAY_NAME + assert artifact.description == _TEST_DESCRIPTION + assert artifact.metadata == { + "resourceName": "projects/test-project/locations/us-central1/models/model-id" + } + assert artifact.schema_version == _TEST_SCHEMA_VERSION + + def test_vertex_endpoint_schema_title_is_set_correctly(self): + artifact = google_artifact_schema.VertexEndpoint( + vertex_endpoint_name=_TEST_ARTIFACT_NAME, + ) + assert artifact.schema_title == "google.VertexEndpoint" + + def test_vertex_endpoint_constructor_parameters_are_set_correctly(self): + artifact = google_artifact_schema.VertexEndpoint( + vertex_endpoint_name=f"{_TEST_PARENT}/endpoints/endpoint-id", + display_name=_TEST_DISPLAY_NAME, + schema_version=_TEST_SCHEMA_VERSION, + description=_TEST_DESCRIPTION, + metadata={}, + ) + assert ( + artifact.uri + == "https://us-central1-aiplatform.googleapis.com/v1/projects/test-project/locations/us-central1/endpoints/endpoint-id" + ) + assert artifact.display_name == _TEST_DISPLAY_NAME + assert artifact.description == _TEST_DESCRIPTION + assert artifact.metadata == { + "resourceName": "projects/test-project/locations/us-central1/endpoints/endpoint-id" + } + assert artifact.schema_version == _TEST_SCHEMA_VERSION + + def test_unmanaged_container_model_title_is_set_correctly(self): + predict_schema_ta = utils.PredictSchemata( + instance_schema_uri="instance_uri", + prediction_schema_uri="prediction_uri", + parameters_schema_uri="parameters_uri", + ) + + container_spec = utils.ContainerSpec( + image_uri="gcr.io/test_container_image_uri" + ) + artifact = google_artifact_schema.UnmanagedContainerModel( + predict_schema_ta=predict_schema_ta, + container_spec=container_spec, + ) + assert artifact.schema_title == "google.UnmanagedContainerModel" + + def test_unmanaged_container_model_constructor_parameters_are_set_correctly(self): + predict_schema_ta = utils.PredictSchemata( + instance_schema_uri="instance_uri", + prediction_schema_uri="prediction_uri", + parameters_schema_uri="parameters_uri", + ) + + container_spec = utils.ContainerSpec( + image_uri="gcr.io/test_container_image_uri" + ) + + artifact = google_artifact_schema.UnmanagedContainerModel( + predict_schema_ta=predict_schema_ta, + container_spec=container_spec, + artifact_id=_TEST_ARTIFACT_ID, + uri=_TEST_URI, + display_name=_TEST_DISPLAY_NAME, + schema_version=_TEST_SCHEMA_VERSION, + description=_TEST_DESCRIPTION, + metadata=_TEST_UPDATED_METADATA, + ) + expected_metadata = { + "test-param1": 2, + "test-param2": "test-value-1", + "test-param3": False, + "predictSchemata": { + "instanceSchemaUri": "instance_uri", + "parametersSchemaUri": "parameters_uri", + "predictionSchemaUri": "prediction_uri", + }, + "containerSpec": {"imageUri": "gcr.io/test_container_image_uri"}, + } + + assert artifact.artifact_id == _TEST_ARTIFACT_ID + assert artifact.uri == _TEST_URI + assert artifact.display_name == _TEST_DISPLAY_NAME + assert artifact.description == _TEST_DESCRIPTION + assert json.dumps(artifact.metadata) == json.dumps(expected_metadata) + assert artifact.schema_version == _TEST_SCHEMA_VERSION + + +class TestMetadataSystemArtifactSchema: + def setup_method(self): + reload(initializer) + reload(metadata) + reload(aiplatform) + + def teardown_method(self): + initializer.global_pool.shutdown(wait=True) + + def test_system_dataset_schema_title_is_set_correctly(self): + artifact = system_artifact_schema.Dataset() + assert artifact.schema_title == "system.Dataset" + + def test_system_dataset_constructor_parameters_are_set_correctly(self): + artifact = system_artifact_schema.Dataset( + uri=_TEST_URI, + artifact_id=_TEST_ARTIFACT_ID, + display_name=_TEST_DISPLAY_NAME, + schema_version=_TEST_SCHEMA_VERSION, + description=_TEST_DESCRIPTION, + metadata=_TEST_UPDATED_METADATA, + ) + assert artifact.uri == _TEST_URI + assert artifact.artifact_id == _TEST_ARTIFACT_ID + assert artifact.display_name == _TEST_DISPLAY_NAME + assert artifact.description == _TEST_DESCRIPTION + assert artifact.metadata == _TEST_UPDATED_METADATA + assert artifact.schema_version == _TEST_SCHEMA_VERSION + + def test_system_artifact_schema_title_is_set_correctly(self): + artifact = system_artifact_schema.Artifact() + assert artifact.schema_title == "system.Artifact" + + def test_system_artifact_constructor_parameters_are_set_correctly(self): + artifact = system_artifact_schema.Artifact( + uri=_TEST_URI, + artifact_id=_TEST_ARTIFACT_ID, + display_name=_TEST_DISPLAY_NAME, + schema_version=_TEST_SCHEMA_VERSION, + description=_TEST_DESCRIPTION, + metadata=_TEST_UPDATED_METADATA, + ) + assert artifact.uri == _TEST_URI + assert artifact.artifact_id == _TEST_ARTIFACT_ID + assert artifact.display_name == _TEST_DISPLAY_NAME + assert artifact.description == _TEST_DESCRIPTION + assert artifact.metadata == _TEST_UPDATED_METADATA + assert artifact.schema_version == _TEST_SCHEMA_VERSION + + def test_system_model_schema_title_is_set_correctly(self): + artifact = system_artifact_schema.Model() + assert artifact.schema_title == "system.Model" + + def test_system_model_constructor_parameters_are_set_correctly(self): + artifact = system_artifact_schema.Model( + uri=_TEST_URI, + artifact_id=_TEST_ARTIFACT_ID, + display_name=_TEST_DISPLAY_NAME, + schema_version=_TEST_SCHEMA_VERSION, + description=_TEST_DESCRIPTION, + metadata=_TEST_UPDATED_METADATA, + ) + assert artifact.uri == _TEST_URI + assert artifact.artifact_id == _TEST_ARTIFACT_ID + assert artifact.display_name == _TEST_DISPLAY_NAME + assert artifact.description == _TEST_DESCRIPTION + assert artifact.metadata == _TEST_UPDATED_METADATA + assert artifact.schema_version == _TEST_SCHEMA_VERSION + + def test_system_metrics_schema_title_is_set_correctly(self): + artifact = system_artifact_schema.Metrics() + assert artifact.schema_title == "system.Metrics" + + def test_system_metrics_values_default_to_none(self): + artifact = system_artifact_schema.Metrics() + assert artifact.metadata == {} + + def test_system_metrics_constructor_parameters_are_set_correctly(self): + artifact = system_artifact_schema.Metrics( + accuracy=0.1, + precision=0.2, + recall=0.3, + f1score=0.4, + mean_absolute_error=0.5, + mean_squared_error=0.6, + artifact_id=_TEST_ARTIFACT_ID, + uri=_TEST_URI, + display_name=_TEST_DISPLAY_NAME, + schema_version=_TEST_SCHEMA_VERSION, + description=_TEST_DESCRIPTION, + metadata=_TEST_UPDATED_METADATA, + ) + assert artifact.uri == _TEST_URI + assert artifact.artifact_id == _TEST_ARTIFACT_ID + assert artifact.display_name == _TEST_DISPLAY_NAME + assert artifact.description == _TEST_DESCRIPTION + assert artifact.schema_version == _TEST_SCHEMA_VERSION + assert artifact.metadata["accuracy"] == 0.1 + assert artifact.metadata["precision"] == 0.2 + assert artifact.metadata["recall"] == 0.3 + assert artifact.metadata["f1score"] == 0.4 + assert artifact.metadata["mean_absolute_error"] == 0.5 + assert artifact.metadata["mean_squared_error"] == 0.6 + + +class TestMetadataSystemSchemaExecution: + def setup_method(self): + reload(initializer) + reload(metadata) + reload(aiplatform) + + def teardown_method(self): + initializer.global_pool.shutdown(wait=True) + + # Test system.Execution Schemas + def test_system_container_execution_schema_title_is_set_correctly(self): + execution = system_execution_schema.ContainerExecution() + assert execution.schema_title == "system.ContainerExecution" + + def test_system_custom_job_execution_schema_title_is_set_correctly(self): + execution = system_execution_schema.CustomJobExecution() + assert execution.schema_title == "system.CustomJobExecution" + + def test_system_run_execution_schema_title_is_set_correctly(self): + execution = system_execution_schema.Run() + assert execution.schema_title == "system.Run" + + +class TestMetadataUtils: + def setup_method(self): + reload(initializer) + reload(metadata) + reload(aiplatform) + + def teardown_method(self): + initializer.global_pool.shutdown(wait=True) + + def test_predict_schemata_to_dict_method_returns_correct_schema(self): + predict_schema_ta = utils.PredictSchemata( + instance_schema_uri="instance_uri", + prediction_schema_uri="prediction_uri", + parameters_schema_uri="parameters_uri", + ) + expected_results = { + "instanceSchemaUri": "instance_uri", + "parametersSchemaUri": "parameters_uri", + "predictionSchemaUri": "prediction_uri", + } + + assert json.dumps(predict_schema_ta.to_dict()) == json.dumps(expected_results) + + def test_container_spec_to_dict_method_returns_correct_schema(self): + container_spec = utils.ContainerSpec( + image_uri="gcr.io/some_container_image_uri", + command=["test_command"], + args=["test_args"], + env=[{"env_var_name": "env_var_value"}], + ports=[1], + predict_route="test_prediction_rout", + health_route="test_health_rout", + ) + + expected_results = { + "imageUri": "gcr.io/some_container_image_uri", + "command": ["test_command"], + "args": ["test_args"], + "env": [{"env_var_name": "env_var_value"}], + "ports": [1], + "predictRoute": "test_prediction_rout", + "healthRoute": "test_health_rout", + } + + assert json.dumps(container_spec.to_dict()) == json.dumps(expected_results) diff --git a/tests/unit/aiplatform/test_metadata_store.py b/tests/unit/aiplatform/test_metadata_store.py index 516e61d849..b6dfe8e032 100644 --- a/tests/unit/aiplatform/test_metadata_store.py +++ b/tests/unit/aiplatform/test_metadata_store.py @@ -15,23 +15,21 @@ # limitations under the License. # -import os from importlib import reload from unittest import mock from unittest.mock import patch import pytest from google.api_core import operation -from google.auth import credentials as auth_credentials -from google.auth.exceptions import GoogleAuthError from google.cloud import aiplatform +from google.cloud.aiplatform import base from google.cloud.aiplatform import initializer from google.cloud.aiplatform.metadata import metadata_store -from google.cloud.aiplatform_v1beta1 import MetadataServiceClient -from google.cloud.aiplatform_v1beta1 import MetadataStore as GapicMetadataStore -from google.cloud.aiplatform_v1beta1.types import encryption_spec as gca_encryption_spec -from google.cloud.aiplatform_v1beta1.types import metadata_service +from google.cloud.aiplatform_v1 import MetadataServiceClient +from google.cloud.aiplatform_v1 import MetadataStore as GapicMetadataStore +from google.cloud.aiplatform.compat.types import encryption_spec as gca_encryption_spec +from google.cloud.aiplatform.compat.types import metadata_service # project _TEST_PROJECT = "test-project" @@ -66,7 +64,8 @@ def get_metadata_store_mock(): MetadataServiceClient, "get_metadata_store" ) as get_metadata_store_mock: get_metadata_store_mock.return_value = GapicMetadataStore( - name=_TEST_NAME, encryption_spec=_TEST_ENCRYPTION_SPEC, + name=_TEST_NAME, + encryption_spec=_TEST_ENCRYPTION_SPEC, ) yield get_metadata_store_mock @@ -77,7 +76,8 @@ def get_default_metadata_store_mock(): MetadataServiceClient, "get_metadata_store" ) as get_metadata_store_mock: get_metadata_store_mock.return_value = GapicMetadataStore( - name=_TEST_DEFAULT_NAME, encryption_spec=_TEST_ENCRYPTION_SPEC, + name=_TEST_DEFAULT_NAME, + encryption_spec=_TEST_ENCRYPTION_SPEC, ) yield get_metadata_store_mock @@ -100,7 +100,8 @@ def create_metadata_store_mock(): ) as create_metadata_store_mock: create_metadata_store_lro_mock = mock.Mock(operation.Operation) create_metadata_store_lro_mock.result.return_value = GapicMetadataStore( - name=_TEST_NAME, encryption_spec=_TEST_ENCRYPTION_SPEC, + name=_TEST_NAME, + encryption_spec=_TEST_ENCRYPTION_SPEC, ) create_metadata_store_mock.return_value = create_metadata_store_lro_mock yield create_metadata_store_mock @@ -113,7 +114,8 @@ def create_default_metadata_store_mock(): ) as create_metadata_store_mock: create_metadata_store_lro_mock = mock.Mock(operation.Operation) create_metadata_store_lro_mock.result.return_value = GapicMetadataStore( - name=_TEST_DEFAULT_NAME, encryption_spec=_TEST_ENCRYPTION_SPEC, + name=_TEST_DEFAULT_NAME, + encryption_spec=_TEST_ENCRYPTION_SPEC, ) create_metadata_store_mock.return_value = create_metadata_store_lro_mock yield create_metadata_store_mock @@ -140,38 +142,36 @@ def setup_method(self): def teardown_method(self): initializer.global_pool.shutdown(wait=True) + @pytest.mark.usefixtures("google_auth_mock") def test_init_metadata_store(self, get_metadata_store_mock): aiplatform.init(project=_TEST_PROJECT) metadata_store._MetadataStore(metadata_store_name=_TEST_NAME) - get_metadata_store_mock.assert_called_once_with(name=_TEST_NAME) + get_metadata_store_mock.assert_called_once_with( + name=_TEST_NAME, retry=base._DEFAULT_RETRY + ) def test_init_metadata_store_with_id(self, get_metadata_store_mock): aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) metadata_store._MetadataStore(metadata_store_name=_TEST_ID) - get_metadata_store_mock.assert_called_once_with(name=_TEST_NAME) + get_metadata_store_mock.assert_called_once_with( + name=_TEST_NAME, retry=base._DEFAULT_RETRY + ) def test_init_metadata_store_with_default_id(self, get_metadata_store_mock): aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) metadata_store._MetadataStore() - get_metadata_store_mock.assert_called_once_with(name=_TEST_DEFAULT_NAME) - - @pytest.mark.usefixtures("get_metadata_store_without_name_mock") - @patch.dict( - os.environ, {"GOOGLE_CLOUD_PROJECT": "", "GOOGLE_APPLICATION_CREDENTIALS": ""} - ) - def test_init_metadata_store_with_id_without_project_or_location(self): - with pytest.raises(GoogleAuthError): - metadata_store._MetadataStore( - metadata_store_name=_TEST_ID, - credentials=auth_credentials.AnonymousCredentials(), - ) + get_metadata_store_mock.assert_called_once_with( + name=_TEST_DEFAULT_NAME, retry=base._DEFAULT_RETRY + ) def test_init_metadata_store_with_location_override(self, get_metadata_store_mock): aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) metadata_store._MetadataStore( metadata_store_name=_TEST_ID, location=_TEST_ALT_LOCATION ) - get_metadata_store_mock.assert_called_once_with(name=_TEST_ALT_LOC_NAME) + get_metadata_store_mock.assert_called_once_with( + name=_TEST_ALT_LOC_NAME, retry=base._DEFAULT_RETRY + ) @pytest.mark.usefixtures("get_metadata_store_mock") def test_init_metadata_store_with_invalid_name(self): @@ -184,7 +184,8 @@ def test_init_aiplatform_with_encryption_key_name_and_create_default_metadata_st self, create_default_metadata_store_mock ): aiplatform.init( - project=_TEST_PROJECT, encryption_spec_key_name=_TEST_ENCRYPTION_KEY_NAME, + project=_TEST_PROJECT, + encryption_spec_key_name=_TEST_ENCRYPTION_KEY_NAME, ) my_metadata_store = metadata_store._MetadataStore._create( diff --git a/tests/unit/aiplatform/test_model_evaluation.py b/tests/unit/aiplatform/test_model_evaluation.py new file mode 100644 index 0000000000..d45e9a1506 --- /dev/null +++ b/tests/unit/aiplatform/test_model_evaluation.py @@ -0,0 +1,189 @@ +# -*- coding: utf-8 -*- + +# Copyright 2022 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. +# + +import pytest + +from unittest import mock + +from google.cloud import aiplatform +from google.cloud.aiplatform import base +from google.cloud.aiplatform import models + +from google.cloud.aiplatform.compat.services import ( + model_service_client, +) + + +from google.cloud.aiplatform.compat.types import model as gca_model + +from google.cloud.aiplatform.compat.types import ( + model_evaluation as gca_model_evaluation, +) + +_TEST_PROJECT = "test-project" +_TEST_LOCATION = "us-central1" +_TEST_MODEL_NAME = "test-model" +_TEST_MODEL_ID = "1028944691210842416" +_TEST_EVAL_ID = "1028944691210842622" + +_TEST_MODEL_RESOURCE_NAME = model_service_client.ModelServiceClient.model_path( + _TEST_PROJECT, _TEST_LOCATION, _TEST_MODEL_ID +) + +_TEST_MODEL_EVAL_RESOURCE_NAME = ( + model_service_client.ModelServiceClient.model_evaluation_path( + _TEST_PROJECT, + _TEST_LOCATION, + _TEST_MODEL_ID, + _TEST_EVAL_ID, + ) +) + +_TEST_MODEL_EVAL_METRICS = { + "auPrc": 0.80592036, + "auRoc": 0.8100363, + "logLoss": 0.53061414, + "confidenceMetrics": [ + { + "confidenceThreshold": -0.01, + "recall": 1.0, + "precision": 0.5, + "falsePositiveRate": 1.0, + "f1Score": 0.6666667, + "recallAt1": 1.0, + "precisionAt1": 0.5, + "falsePositiveRateAt1": 1.0, + "f1ScoreAt1": 0.6666667, + "truePositiveCount": "415", + "falsePositiveCount": "415", + }, + { + "recall": 1.0, + "precision": 0.5, + "falsePositiveRate": 1.0, + "f1Score": 0.6666667, + "recallAt1": 0.74216866, + "precisionAt1": 0.74216866, + "falsePositiveRateAt1": 0.25783134, + "f1ScoreAt1": 0.74216866, + "truePositiveCount": "415", + "falsePositiveCount": "415", + }, + ], +} + + +@pytest.fixture +def get_model_mock(): + with mock.patch.object( + model_service_client.ModelServiceClient, "get_model" + ) as get_model_mock: + get_model_mock.return_value = gca_model.Model( + display_name=_TEST_MODEL_NAME, + name=_TEST_MODEL_RESOURCE_NAME, + ) + + yield get_model_mock + + +@pytest.fixture +def mock_model(): + model = mock.MagicMock(models.Model) + model.name = _TEST_MODEL_ID + model._latest_future = None + model._exception = None + model._gca_resource = gca_model.Model( + display_name="test-eval-model", + description="This is the mock Model's description", + name=_TEST_MODEL_NAME, + ) + yield model + + +# ModelEvaluation mocks +@pytest.fixture +def mock_model_eval_get(): + with mock.patch.object( + model_service_client.ModelServiceClient, "get_model_evaluation" + ) as mock_get_model_eval: + mock_get_model_eval.return_value = gca_model_evaluation.ModelEvaluation( + name=_TEST_MODEL_EVAL_RESOURCE_NAME, + metrics=_TEST_MODEL_EVAL_METRICS, + ) + yield mock_get_model_eval + + +@pytest.mark.usefixtures("google_auth_mock") +class TestModelEvaluation: + def test_init_model_evaluation_with_only_resource_name(self, mock_model_eval_get): + aiplatform.init(project=_TEST_PROJECT) + + aiplatform.ModelEvaluation(evaluation_name=_TEST_MODEL_EVAL_RESOURCE_NAME) + + mock_model_eval_get.assert_called_once_with( + name=_TEST_MODEL_EVAL_RESOURCE_NAME, retry=base._DEFAULT_RETRY + ) + + def test_init_model_evaluation_with_eval_id_and_model_id(self, mock_model_eval_get): + aiplatform.init(project=_TEST_PROJECT) + + aiplatform.ModelEvaluation( + evaluation_name=_TEST_EVAL_ID, model_id=_TEST_MODEL_ID + ) + + mock_model_eval_get.assert_called_once_with( + name=_TEST_MODEL_EVAL_RESOURCE_NAME, retry=base._DEFAULT_RETRY + ) + + def test_init_model_evaluatin_with_id_project_and_location( + self, mock_model_eval_get + ): + aiplatform.init(project=_TEST_PROJECT) + + aiplatform.ModelEvaluation( + evaluation_name=_TEST_MODEL_EVAL_RESOURCE_NAME, + project=_TEST_PROJECT, + location=_TEST_LOCATION, + ) + mock_model_eval_get.assert_called_once_with( + name=_TEST_MODEL_EVAL_RESOURCE_NAME, retry=base._DEFAULT_RETRY + ) + + def test_init_model_evaluation_with_invalid_evaluation_resource_raises( + self, mock_model_eval_get + ): + aiplatform.init(project=_TEST_PROJECT) + + with pytest.raises(ValueError): + aiplatform.ModelEvaluation(evaluation_name=_TEST_MODEL_RESOURCE_NAME) + + def test_get_model_evaluation_metrics(self, mock_model_eval_get): + aiplatform.init(project=_TEST_PROJECT) + + eval_metrics = aiplatform.ModelEvaluation( + evaluation_name=_TEST_MODEL_EVAL_RESOURCE_NAME + ).metrics + assert eval_metrics == _TEST_MODEL_EVAL_METRICS + + def test_no_delete_model_evaluation_method(self, mock_model_eval_get): + + my_eval = aiplatform.ModelEvaluation( + evaluation_name=_TEST_MODEL_EVAL_RESOURCE_NAME + ) + + with pytest.raises(NotImplementedError): + my_eval.delete() diff --git a/tests/unit/aiplatform/test_models.py b/tests/unit/aiplatform/test_models.py index ad84fde65b..23f933128a 100644 --- a/tests/unit/aiplatform/test_models.py +++ b/tests/unit/aiplatform/test_models.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,59 +17,44 @@ import importlib from concurrent import futures +import pathlib import pytest from unittest import mock +from unittest.mock import patch from google.api_core import operation as ga_operation +from google.api_core import exceptions as api_exceptions from google.auth import credentials as auth_credentials from google.cloud import aiplatform - +from google.cloud.aiplatform import base from google.cloud.aiplatform import initializer from google.cloud.aiplatform import models from google.cloud.aiplatform import utils -from google.cloud.aiplatform_v1beta1.services.endpoint_service import ( - client as endpoint_service_client_v1beta1, -) -from google.cloud.aiplatform_v1beta1.services.job_service import ( - client as job_service_client_v1beta1, -) -from google.cloud.aiplatform_v1beta1.services.model_service import ( - client as model_service_client_v1beta1, -) -from google.cloud.aiplatform_v1beta1.types import ( - batch_prediction_job as gca_batch_prediction_job_v1beta1, - env_var as gca_env_var_v1beta1, - explanation as gca_explanation_v1beta1, - io as gca_io_v1beta1, - model as gca_model_v1beta1, - endpoint as gca_endpoint_v1beta1, - machine_resources as gca_machine_resources_v1beta1, - model_service as gca_model_service_v1beta1, - endpoint_service as gca_endpoint_service_v1beta1, - encryption_spec as gca_encryption_spec_v1beta1, -) - -from google.cloud.aiplatform_v1.services.endpoint_service import ( - client as endpoint_service_client, +from google.cloud.aiplatform.compat.services import ( + endpoint_service_client, + model_service_client, + job_service_client, ) -from google.cloud.aiplatform_v1.services.job_service import client as job_service_client -from google.cloud.aiplatform_v1.services.model_service import ( - client as model_service_client, -) -from google.cloud.aiplatform_v1.types import ( +from google.cloud.aiplatform.compat.services import pipeline_service_client +from google.cloud.aiplatform.compat.types import ( batch_prediction_job as gca_batch_prediction_job, io as gca_io, job_state as gca_job_state, model as gca_model, endpoint as gca_endpoint, + env_var as gca_env_var, + explanation as gca_explanation, machine_resources as gca_machine_resources, + manual_batch_tuning_parameters as gca_manual_batch_tuning_parameters_compat, model_service as gca_model_service, + model_evaluation as gca_model_evaluation, endpoint_service as gca_endpoint_service, encryption_spec as gca_encryption_spec, ) +from google.protobuf import field_mask_pb2 from test_endpoints import create_endpoint_mock # noqa: F401 @@ -100,6 +85,12 @@ _TEST_STARTING_REPLICA_COUNT = 2 _TEST_MAX_REPLICA_COUNT = 12 +_TEST_BATCH_SIZE = 16 + +_TEST_PIPELINE_RESOURCE_NAME = ( + "projects/my-project/locations/us-central1/trainingPipeline/12345" +) + _TEST_BATCH_PREDICTION_GCS_SOURCE = "gs://example-bucket/folder/instance.jsonl" _TEST_BATCH_PREDICTION_GCS_SOURCE_LIST = [ "gs://example-bucket/folder/instance1.jsonl", @@ -111,8 +102,10 @@ f"bq://{_TEST_BATCH_PREDICTION_BQ_PREFIX}" ) _TEST_BATCH_PREDICTION_DISPLAY_NAME = "test-batch-prediction-job" -_TEST_BATCH_PREDICTION_JOB_NAME = job_service_client.JobServiceClient.batch_prediction_job_path( - project=_TEST_PROJECT, location=_TEST_LOCATION, batch_prediction_job=_TEST_ID +_TEST_BATCH_PREDICTION_JOB_NAME = ( + job_service_client.JobServiceClient.batch_prediction_job_path( + project=_TEST_PROJECT, location=_TEST_LOCATION, batch_prediction_job=_TEST_ID + ) ) _TEST_INSTANCE_SCHEMA_URI = "gs://test/schema/instance.yaml" @@ -142,18 +135,19 @@ _TEST_ENCRYPTION_SPEC = gca_encryption_spec.EncryptionSpec( kms_key_name=_TEST_ENCRYPTION_KEY_NAME ) -_TEST_ENCRYPTION_SPEC_V1BETA1 = gca_encryption_spec_v1beta1.EncryptionSpec( - kms_key_name=_TEST_ENCRYPTION_KEY_NAME -) _TEST_MODEL_RESOURCE_NAME = model_service_client.ModelServiceClient.model_path( _TEST_PROJECT, _TEST_LOCATION, _TEST_ID ) -_TEST_MODEL_RESOURCE_NAME_CUSTOM_PROJECT = model_service_client.ModelServiceClient.model_path( - _TEST_PROJECT_2, _TEST_LOCATION, _TEST_ID +_TEST_MODEL_RESOURCE_NAME_CUSTOM_PROJECT = ( + model_service_client.ModelServiceClient.model_path( + _TEST_PROJECT_2, _TEST_LOCATION, _TEST_ID + ) ) -_TEST_MODEL_RESOURCE_NAME_CUSTOM_LOCATION = model_service_client.ModelServiceClient.model_path( - _TEST_PROJECT, _TEST_LOCATION_2, _TEST_ID +_TEST_MODEL_RESOURCE_NAME_CUSTOM_LOCATION = ( + model_service_client.ModelServiceClient.model_path( + _TEST_PROJECT, _TEST_LOCATION_2, _TEST_ID + ) ) _TEST_OUTPUT_DIR = "gs://my-output-bucket" @@ -191,17 +185,88 @@ _TEST_SUPPORTED_EXPORT_FORMATS_UNSUPPORTED = [] _TEST_CONTAINER_REGISTRY_DESTINATION +# Model Evaluation +_TEST_MODEL_EVAL_RESOURCE_NAME = f"{_TEST_MODEL_RESOURCE_NAME}/evaluations/{_TEST_ID}" +_TEST_MODEL_EVAL_METRICS = { + "auPrc": 0.80592036, + "auRoc": 0.8100363, + "logLoss": 0.53061414, + "confidenceMetrics": [ + { + "confidenceThreshold": -0.01, + "recall": 1.0, + "precision": 0.5, + "falsePositiveRate": 1.0, + "f1Score": 0.6666667, + "recallAt1": 1.0, + "precisionAt1": 0.5, + "falsePositiveRateAt1": 1.0, + "f1ScoreAt1": 0.6666667, + "truePositiveCount": "415", + "falsePositiveCount": "415", + }, + { + "recall": 1.0, + "precision": 0.5, + "falsePositiveRate": 1.0, + "f1Score": 0.6666667, + "recallAt1": 0.74216866, + "precisionAt1": 0.74216866, + "falsePositiveRateAt1": 0.25783134, + "f1ScoreAt1": 0.74216866, + "truePositiveCount": "415", + "falsePositiveCount": "415", + }, + ], +} + +_TEST_MODEL_EVAL_LIST = [ + gca_model_evaluation.ModelEvaluation( + name=_TEST_MODEL_EVAL_RESOURCE_NAME, + ), + gca_model_evaluation.ModelEvaluation( + name=_TEST_MODEL_EVAL_RESOURCE_NAME, + ), + gca_model_evaluation.ModelEvaluation( + name=_TEST_MODEL_EVAL_RESOURCE_NAME, + ), +] + + +@pytest.fixture +def mock_model(): + model = mock.MagicMock(models.Model) + model.name = _TEST_ID + model._latest_future = None + model._exception = None + model._gca_resource = gca_model.Model( + display_name=_TEST_MODEL_NAME, + description=_TEST_DESCRIPTION, + labels=_TEST_LABEL, + ) + yield model + + +@pytest.fixture +def update_model_mock(mock_model): + with patch.object(model_service_client.ModelServiceClient, "update_model") as mock: + mock.return_value = mock_model + yield mock + @pytest.fixture def get_endpoint_mock(): with mock.patch.object( endpoint_service_client.EndpointServiceClient, "get_endpoint" ) as get_endpoint_mock: - test_endpoint_resource_name = endpoint_service_client.EndpointServiceClient.endpoint_path( - _TEST_PROJECT, _TEST_LOCATION, _TEST_ID + test_endpoint_resource_name = ( + endpoint_service_client.EndpointServiceClient.endpoint_path( + _TEST_PROJECT, _TEST_LOCATION, _TEST_ID + ) ) get_endpoint_mock.return_value = gca_endpoint.Endpoint( - display_name=_TEST_MODEL_NAME, name=test_endpoint_resource_name, + display_name=_TEST_MODEL_NAME, + name=test_endpoint_resource_name, ) yield get_endpoint_mock @@ -212,42 +277,48 @@ def get_model_mock(): model_service_client.ModelServiceClient, "get_model" ) as get_model_mock: get_model_mock.return_value = gca_model.Model( - display_name=_TEST_MODEL_NAME, name=_TEST_MODEL_RESOURCE_NAME, + display_name=_TEST_MODEL_NAME, + name=_TEST_MODEL_RESOURCE_NAME, ) + yield get_model_mock @pytest.fixture -def get_model_with_explanations_mock(): +def get_model_with_custom_location_mock(): with mock.patch.object( - model_service_client_v1beta1.ModelServiceClient, "get_model" + model_service_client.ModelServiceClient, "get_model" ) as get_model_mock: - get_model_mock.return_value = gca_model_v1beta1.Model( - display_name=_TEST_MODEL_NAME, name=_TEST_MODEL_RESOURCE_NAME, + get_model_mock.return_value = gca_model.Model( + display_name=_TEST_MODEL_NAME, + name=_TEST_MODEL_RESOURCE_NAME_CUSTOM_LOCATION, ) yield get_model_mock @pytest.fixture -def get_model_with_custom_location_mock(): +def get_model_with_custom_project_mock(): with mock.patch.object( model_service_client.ModelServiceClient, "get_model" ) as get_model_mock: get_model_mock.return_value = gca_model.Model( display_name=_TEST_MODEL_NAME, - name=_TEST_MODEL_RESOURCE_NAME_CUSTOM_LOCATION, + name=_TEST_MODEL_RESOURCE_NAME_CUSTOM_PROJECT, + artifact_uri=_TEST_ARTIFACT_URI, + description=_TEST_DESCRIPTION, ) yield get_model_mock @pytest.fixture -def get_model_with_custom_project_mock(): +def get_model_with_training_job(): with mock.patch.object( model_service_client.ModelServiceClient, "get_model" ) as get_model_mock: get_model_mock.return_value = gca_model.Model( display_name=_TEST_MODEL_NAME, name=_TEST_MODEL_RESOURCE_NAME_CUSTOM_PROJECT, + training_pipeline=_TEST_PIPELINE_RESOURCE_NAME, ) yield get_model_mock @@ -317,19 +388,6 @@ def upload_model_mock(): yield upload_model_mock -@pytest.fixture -def upload_model_with_explanations_mock(): - with mock.patch.object( - model_service_client_v1beta1.ModelServiceClient, "upload_model" - ) as upload_model_mock: - mock_lro = mock.Mock(ga_operation.Operation) - mock_lro.result.return_value = gca_model_service_v1beta1.UploadModelResponse( - model=_TEST_MODEL_RESOURCE_NAME - ) - upload_model_mock.return_value = mock_lro - yield upload_model_mock - - @pytest.fixture def upload_model_with_custom_project_mock(): with mock.patch.object( @@ -391,27 +449,14 @@ def deploy_model_mock(): endpoint_service_client.EndpointServiceClient, "deploy_model" ) as deploy_model_mock: deployed_model = gca_endpoint.DeployedModel( - model=_TEST_MODEL_RESOURCE_NAME, display_name=_TEST_MODEL_NAME, - ) - deploy_model_lro_mock = mock.Mock(ga_operation.Operation) - deploy_model_lro_mock.result.return_value = gca_endpoint_service.DeployModelResponse( - deployed_model=deployed_model, - ) - deploy_model_mock.return_value = deploy_model_lro_mock - yield deploy_model_mock - - -@pytest.fixture -def deploy_model_with_explanations_mock(): - with mock.patch.object( - endpoint_service_client_v1beta1.EndpointServiceClient, "deploy_model" - ) as deploy_model_mock: - deployed_model = gca_endpoint_v1beta1.DeployedModel( - model=_TEST_MODEL_RESOURCE_NAME, display_name=_TEST_MODEL_NAME, + model=_TEST_MODEL_RESOURCE_NAME, + display_name=_TEST_MODEL_NAME, ) deploy_model_lro_mock = mock.Mock(ga_operation.Operation) - deploy_model_lro_mock.result.return_value = gca_endpoint_service_v1beta1.DeployModelResponse( - deployed_model=deployed_model, + deploy_model_lro_mock.result.return_value = ( + gca_endpoint_service.DeployModelResponse( + deployed_model=deployed_model, + ) ) deploy_model_mock.return_value = deploy_model_lro_mock yield deploy_model_mock @@ -445,16 +490,13 @@ def create_batch_prediction_job_mock(): @pytest.fixture -def create_batch_prediction_job_with_explanations_mock(): - with mock.patch.object( - job_service_client_v1beta1.JobServiceClient, "create_batch_prediction_job" - ) as create_batch_prediction_job_mock: - batch_prediction_job_mock = mock.Mock( - spec=gca_batch_prediction_job_v1beta1.BatchPredictionJob - ) - batch_prediction_job_mock.name = _TEST_BATCH_PREDICTION_JOB_NAME - create_batch_prediction_job_mock.return_value = batch_prediction_job_mock - yield create_batch_prediction_job_mock +def get_training_job_non_existent_mock(): + with patch.object( + pipeline_service_client.PipelineServiceClient, "get_training_pipeline" + ) as get_training_job_non_existent_mock: + get_training_job_non_existent_mock.side_effect = api_exceptions.NotFound("404") + + yield get_training_job_non_existent_mock @pytest.fixture @@ -467,6 +509,39 @@ def create_client_mock(): yield create_client_mock +@pytest.fixture +def mock_storage_blob_upload_from_filename(): + with patch( + "google.cloud.storage.Blob.upload_from_filename" + ) as mock_blob_upload_from_filename, patch( + "google.cloud.storage.Bucket.exists", return_value=True + ): + yield mock_blob_upload_from_filename + + +# ModelEvaluation mocks +@pytest.fixture +def mock_model_eval_get(): + with mock.patch.object( + model_service_client.ModelServiceClient, "get_model_evaluation" + ) as mock_get_model_eval: + mock_get_model_eval.return_value = gca_model_evaluation.ModelEvaluation( + name=_TEST_MODEL_EVAL_RESOURCE_NAME, + metrics=_TEST_MODEL_EVAL_METRICS, + ) + yield mock_get_model_eval + + +@pytest.fixture +def list_model_evaluations_mock(): + with mock.patch.object( + model_service_client.ModelServiceClient, "list_model_evaluations" + ) as list_model_evaluations_mock: + list_model_evaluations_mock.return_value = _TEST_MODEL_EVAL_LIST + yield list_model_evaluations_mock + + +@pytest.mark.usefixtures("google_auth_mock") class TestModel: def setup_method(self): importlib.reload(initializer) @@ -487,7 +562,6 @@ def test_constructor_creates_client(self, create_client_mock): client_class=utils.ModelClientWithOverride, credentials=initializer.global_config.credentials, location_override=_TEST_LOCATION, - prediction_client=False, ) def test_constructor_create_client_with_custom_location(self, create_client_mock): @@ -501,7 +575,6 @@ def test_constructor_create_client_with_custom_location(self, create_client_mock client_class=utils.ModelClientWithOverride, credentials=initializer.global_config.credentials, location_override=_TEST_LOCATION_2, - prediction_client=False, ) def test_constructor_creates_client_with_custom_credentials( @@ -513,26 +586,31 @@ def test_constructor_creates_client_with_custom_credentials( client_class=utils.ModelClientWithOverride, credentials=creds, location_override=_TEST_LOCATION, - prediction_client=False, ) def test_constructor_gets_model(self, get_model_mock): models.Model(_TEST_ID) - get_model_mock.assert_called_once_with(name=_TEST_MODEL_RESOURCE_NAME) + get_model_mock.assert_called_once_with( + name=_TEST_MODEL_RESOURCE_NAME, retry=base._DEFAULT_RETRY + ) def test_constructor_gets_model_with_custom_project(self, get_model_mock): models.Model(_TEST_ID, project=_TEST_PROJECT_2) test_model_resource_name = model_service_client.ModelServiceClient.model_path( _TEST_PROJECT_2, _TEST_LOCATION, _TEST_ID ) - get_model_mock.assert_called_once_with(name=test_model_resource_name) + get_model_mock.assert_called_once_with( + name=test_model_resource_name, retry=base._DEFAULT_RETRY + ) def test_constructor_gets_model_with_custom_location(self, get_model_mock): models.Model(_TEST_ID, location=_TEST_LOCATION_2) test_model_resource_name = model_service_client.ModelServiceClient.model_path( _TEST_PROJECT, _TEST_LOCATION_2, _TEST_ID ) - get_model_mock.assert_called_once_with(name=test_model_resource_name) + get_model_mock.assert_called_once_with( + name=test_model_resource_name, retry=base._DEFAULT_RETRY + ) @pytest.mark.parametrize("sync", [True, False]) def test_upload_uploads_and_gets_model( @@ -545,6 +623,7 @@ def test_upload_uploads_and_gets_model( serving_container_predict_route=_TEST_SERVING_CONTAINER_PREDICTION_ROUTE, serving_container_health_route=_TEST_SERVING_CONTAINER_HEALTH_ROUTE, sync=sync, + upload_request_timeout=None, ) if not sync: @@ -557,15 +636,114 @@ def test_upload_uploads_and_gets_model( ) managed_model = gca_model.Model( - display_name=_TEST_MODEL_NAME, container_spec=container_spec, + display_name=_TEST_MODEL_NAME, + container_spec=container_spec, ) upload_model_mock.assert_called_once_with( parent=initializer.global_config.common_location_path(), model=managed_model, + timeout=None, ) - get_model_mock.assert_called_once_with(name=_TEST_MODEL_RESOURCE_NAME) + get_model_mock.assert_called_once_with( + name=_TEST_MODEL_RESOURCE_NAME, retry=base._DEFAULT_RETRY + ) + + @pytest.mark.parametrize("sync", [True, False]) + def test_upload_with_timeout(self, upload_model_mock, get_model_mock, sync): + my_model = models.Model.upload( + display_name=_TEST_MODEL_NAME, + serving_container_image_uri=_TEST_SERVING_CONTAINER_IMAGE, + sync=sync, + upload_request_timeout=180.0, + ) + + if not sync: + my_model.wait() + + container_spec = gca_model.ModelContainerSpec( + image_uri=_TEST_SERVING_CONTAINER_IMAGE, + ) + + managed_model = gca_model.Model( + display_name=_TEST_MODEL_NAME, + container_spec=container_spec, + ) + + upload_model_mock.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + model=managed_model, + timeout=180.0, + ) + + @pytest.mark.parametrize("sync", [True, False]) + def test_upload_with_timeout_not_explicitly_set( + self, upload_model_mock, get_model_mock, sync + ): + my_model = models.Model.upload( + display_name=_TEST_MODEL_NAME, + serving_container_image_uri=_TEST_SERVING_CONTAINER_IMAGE, + sync=sync, + ) + + if not sync: + my_model.wait() + + container_spec = gca_model.ModelContainerSpec( + image_uri=_TEST_SERVING_CONTAINER_IMAGE, + ) + + managed_model = gca_model.Model( + display_name=_TEST_MODEL_NAME, + container_spec=container_spec, + ) + + upload_model_mock.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + model=managed_model, + timeout=None, + ) + + @pytest.mark.parametrize("sync", [True, False]) + def test_upload_uploads_and_gets_model_with_labels( + self, upload_model_mock, get_model_mock, sync + ): + + my_model = models.Model.upload( + display_name=_TEST_MODEL_NAME, + serving_container_image_uri=_TEST_SERVING_CONTAINER_IMAGE, + serving_container_predict_route=_TEST_SERVING_CONTAINER_PREDICTION_ROUTE, + serving_container_health_route=_TEST_SERVING_CONTAINER_HEALTH_ROUTE, + labels=_TEST_LABEL, + upload_request_timeout=None, + sync=sync, + ) + + if not sync: + my_model.wait() + + container_spec = gca_model.ModelContainerSpec( + image_uri=_TEST_SERVING_CONTAINER_IMAGE, + predict_route=_TEST_SERVING_CONTAINER_PREDICTION_ROUTE, + health_route=_TEST_SERVING_CONTAINER_HEALTH_ROUTE, + ) + + managed_model = gca_model.Model( + display_name=_TEST_MODEL_NAME, + container_spec=container_spec, + labels=_TEST_LABEL, + ) + + upload_model_mock.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + model=managed_model, + timeout=None, + ) + + get_model_mock.assert_called_once_with( + name=_TEST_MODEL_RESOURCE_NAME, retry=base._DEFAULT_RETRY + ) def test_upload_raises_with_impartial_explanation_spec(self): @@ -582,7 +760,7 @@ def test_upload_raises_with_impartial_explanation_spec(self): @pytest.mark.parametrize("sync", [True, False]) def test_upload_uploads_and_gets_model_with_all_args( - self, upload_model_with_explanations_mock, get_model_mock, sync + self, upload_model_mock, get_model_mock, sync ): my_model = models.Model.upload( @@ -601,23 +779,25 @@ def test_upload_uploads_and_gets_model_with_all_args( serving_container_ports=_TEST_SERVING_CONTAINER_PORTS, explanation_metadata=_TEST_EXPLANATION_METADATA, explanation_parameters=_TEST_EXPLANATION_PARAMETERS, + labels=_TEST_LABEL, sync=sync, + upload_request_timeout=None, ) if not sync: my_model.wait() env = [ - gca_env_var_v1beta1.EnvVar(name=str(key), value=str(value)) + gca_env_var.EnvVar(name=str(key), value=str(value)) for key, value in _TEST_SERVING_CONTAINER_ENVIRONMENT_VARIABLES.items() ] ports = [ - gca_model_v1beta1.Port(container_port=port) + gca_model.Port(container_port=port) for port in _TEST_SERVING_CONTAINER_PORTS ] - container_spec = gca_model_v1beta1.ModelContainerSpec( + container_spec = gca_model.ModelContainerSpec( image_uri=_TEST_SERVING_CONTAINER_IMAGE, predict_route=_TEST_SERVING_CONTAINER_PREDICTION_ROUTE, health_route=_TEST_SERVING_CONTAINER_HEALTH_ROUTE, @@ -627,27 +807,31 @@ def test_upload_uploads_and_gets_model_with_all_args( ports=ports, ) - managed_model = gca_model_v1beta1.Model( + managed_model = gca_model.Model( display_name=_TEST_MODEL_NAME, description=_TEST_DESCRIPTION, artifact_uri=_TEST_ARTIFACT_URI, container_spec=container_spec, - predict_schemata=gca_model_v1beta1.PredictSchemata( + predict_schemata=gca_model.PredictSchemata( instance_schema_uri=_TEST_INSTANCE_SCHEMA_URI, parameters_schema_uri=_TEST_PARAMETERS_SCHEMA_URI, prediction_schema_uri=_TEST_PREDICTION_SCHEMA_URI, ), - explanation_spec=gca_model_v1beta1.explanation.ExplanationSpec( + explanation_spec=gca_model.explanation.ExplanationSpec( metadata=_TEST_EXPLANATION_METADATA, parameters=_TEST_EXPLANATION_PARAMETERS, ), + labels=_TEST_LABEL, ) - upload_model_with_explanations_mock.assert_called_once_with( + upload_model_mock.assert_called_once_with( parent=initializer.global_config.common_location_path(), model=managed_model, + timeout=None, + ) + get_model_mock.assert_called_once_with( + name=_TEST_MODEL_RESOURCE_NAME, retry=base._DEFAULT_RETRY ) - get_model_mock.assert_called_once_with(name=_TEST_MODEL_RESOURCE_NAME) @pytest.mark.usefixtures("get_model_with_custom_project_mock") @pytest.mark.parametrize("sync", [True, False]) @@ -670,6 +854,7 @@ def test_upload_uploads_and_gets_model_with_custom_project( serving_container_health_route=_TEST_SERVING_CONTAINER_HEALTH_ROUTE, project=_TEST_PROJECT_2, sync=sync, + upload_request_timeout=None, ) if not sync: @@ -690,12 +875,56 @@ def test_upload_uploads_and_gets_model_with_custom_project( upload_model_with_custom_project_mock.assert_called_once_with( parent=f"projects/{_TEST_PROJECT_2}/locations/{_TEST_LOCATION}", model=managed_model, + timeout=None, ) get_model_with_custom_project_mock.assert_called_once_with( - name=test_model_resource_name + name=test_model_resource_name, retry=base._DEFAULT_RETRY ) + assert my_model.uri == _TEST_ARTIFACT_URI + assert my_model.supported_export_formats == {} + assert my_model.supported_deployment_resources_types == [] + assert my_model.supported_input_storage_formats == [] + assert my_model.supported_output_storage_formats == [] + assert my_model.description == _TEST_DESCRIPTION + + @pytest.mark.usefixtures("get_model_with_custom_project_mock") + def test_accessing_properties_with_no_resource_raises( + self, + ): + + test_model_resource_name = model_service_client.ModelServiceClient.model_path( + _TEST_PROJECT_2, _TEST_LOCATION, _TEST_ID + ) + + my_model = models.Model(test_model_resource_name) + my_model._gca_resource = None + + with pytest.raises(RuntimeError) as e: + my_model.uri + e.match(regexp=r"Model resource has not been created.") + + with pytest.raises(RuntimeError) as e: + my_model.supported_export_formats + e.match(regexp=r"Model resource has not been created.") + + with pytest.raises(RuntimeError) as e: + my_model.supported_deployment_resources_types + e.match(regexp=r"Model resource has not been created.") + + with pytest.raises(RuntimeError) as e: + my_model.supported_input_storage_formats + e.match(regexp=r"Model resource has not been created.") + + with pytest.raises(RuntimeError) as e: + my_model.supported_output_storage_formats + e.match(regexp=r"Model resource has not been created.") + + with pytest.raises(RuntimeError) as e: + my_model.description + e.match(regexp=r"Model resource has not been created.") + @pytest.mark.usefixtures("get_model_with_custom_location_mock") @pytest.mark.parametrize("sync", [True, False]) def test_upload_uploads_and_gets_model_with_custom_location( @@ -716,6 +945,7 @@ def test_upload_uploads_and_gets_model_with_custom_location( serving_container_health_route=_TEST_SERVING_CONTAINER_HEALTH_ROUTE, location=_TEST_LOCATION_2, sync=sync, + upload_request_timeout=None, ) if not sync: @@ -736,10 +966,11 @@ def test_upload_uploads_and_gets_model_with_custom_location( upload_model_with_custom_location_mock.assert_called_once_with( parent=f"projects/{_TEST_PROJECT}/locations/{_TEST_LOCATION_2}", model=managed_model, + timeout=None, ) get_model_with_custom_location_mock.assert_called_once_with( - name=test_model_resource_name + name=test_model_resource_name, retry=base._DEFAULT_RETRY ) @pytest.mark.usefixtures("get_endpoint_mock", "get_model_mock") @@ -747,15 +978,61 @@ def test_upload_uploads_and_gets_model_with_custom_location( def test_deploy(self, deploy_model_mock, sync): test_model = models.Model(_TEST_ID) + test_model._gca_resource.supported_deployment_resources_types.append( + aiplatform.gapic.Model.DeploymentResourcesType.AUTOMATIC_RESOURCES + ) + + test_endpoint = models.Endpoint(_TEST_ID) + + assert ( + test_model.deploy( + test_endpoint, + sync=sync, + ) + == test_endpoint + ) + + if not sync: + test_endpoint.wait() + + automatic_resources = gca_machine_resources.AutomaticResources( + min_replica_count=1, + max_replica_count=1, + ) + deployed_model = gca_endpoint.DeployedModel( + automatic_resources=automatic_resources, + model=test_model.resource_name, + display_name=None, + ) + deploy_model_mock.assert_called_once_with( + endpoint=test_endpoint.resource_name, + deployed_model=deployed_model, + traffic_split={"0": 100}, + metadata=(), + timeout=None, + ) + + @pytest.mark.usefixtures( + "get_endpoint_mock", "get_model_mock", "create_endpoint_mock" + ) + @pytest.mark.parametrize("sync", [True, False]) + def test_deploy_with_timeout(self, deploy_model_mock, sync): + + test_model = models.Model(_TEST_ID) + test_model._gca_resource.supported_deployment_resources_types.append( + aiplatform.gapic.Model.DeploymentResourcesType.AUTOMATIC_RESOURCES + ) + test_endpoint = models.Endpoint(_TEST_ID) - assert test_model.deploy(test_endpoint, sync=sync,) == test_endpoint + test_model.deploy(test_endpoint, sync=sync, deploy_request_timeout=180.0) if not sync: test_endpoint.wait() automatic_resources = gca_machine_resources.AutomaticResources( - min_replica_count=1, max_replica_count=1, + min_replica_count=1, + max_replica_count=1, ) deployed_model = gca_endpoint.DeployedModel( automatic_resources=automatic_resources, @@ -767,6 +1044,45 @@ def test_deploy(self, deploy_model_mock, sync): deployed_model=deployed_model, traffic_split={"0": 100}, metadata=(), + timeout=180.0, + ) + + @pytest.mark.usefixtures( + "get_endpoint_mock", "get_model_mock", "create_endpoint_mock" + ) + @pytest.mark.parametrize("sync", [True, False]) + def test_deploy_with_timeout_not_explicitly_set(self, deploy_model_mock, sync): + + test_model = models.Model(_TEST_ID) + test_model._gca_resource.supported_deployment_resources_types.append( + aiplatform.gapic.Model.DeploymentResourcesType.AUTOMATIC_RESOURCES + ) + + test_endpoint = models.Endpoint(_TEST_ID) + + test_model.deploy( + test_endpoint, + sync=sync, + ) + + if not sync: + test_endpoint.wait() + + automatic_resources = gca_machine_resources.AutomaticResources( + min_replica_count=1, + max_replica_count=1, + ) + deployed_model = gca_endpoint.DeployedModel( + automatic_resources=automatic_resources, + model=test_model.resource_name, + display_name=None, + ) + deploy_model_mock.assert_called_once_with( + endpoint=test_endpoint.resource_name, + deployed_model=deployed_model, + traffic_split={"0": 100}, + metadata=(), + timeout=None, ) @pytest.mark.usefixtures( @@ -776,13 +1092,17 @@ def test_deploy(self, deploy_model_mock, sync): def test_deploy_no_endpoint(self, deploy_model_mock, sync): test_model = models.Model(_TEST_ID) + test_model._gca_resource.supported_deployment_resources_types.append( + aiplatform.gapic.Model.DeploymentResourcesType.AUTOMATIC_RESOURCES + ) test_endpoint = test_model.deploy(sync=sync) if not sync: test_endpoint.wait() automatic_resources = gca_machine_resources.AutomaticResources( - min_replica_count=1, max_replica_count=1, + min_replica_count=1, + max_replica_count=1, ) deployed_model = gca_endpoint.DeployedModel( automatic_resources=automatic_resources, @@ -794,6 +1114,7 @@ def test_deploy_no_endpoint(self, deploy_model_mock, sync): deployed_model=deployed_model, traffic_split={"0": 100}, metadata=(), + timeout=None, ) @pytest.mark.usefixtures( @@ -803,12 +1124,16 @@ def test_deploy_no_endpoint(self, deploy_model_mock, sync): def test_deploy_no_endpoint_dedicated_resources(self, deploy_model_mock, sync): test_model = models.Model(_TEST_ID) + test_model._gca_resource.supported_deployment_resources_types.append( + aiplatform.gapic.Model.DeploymentResourcesType.DEDICATED_RESOURCES + ) test_endpoint = test_model.deploy( machine_type=_TEST_MACHINE_TYPE, accelerator_type=_TEST_ACCELERATOR_TYPE, accelerator_count=_TEST_ACCELERATOR_COUNT, service_account=_TEST_SERVICE_ACCOUNT, sync=sync, + deploy_request_timeout=None, ) if not sync: @@ -833,16 +1158,18 @@ def test_deploy_no_endpoint_dedicated_resources(self, deploy_model_mock, sync): deployed_model=expected_deployed_model, traffic_split={"0": 100}, metadata=(), + timeout=None, ) @pytest.mark.usefixtures( "get_endpoint_mock", "get_model_mock", "create_endpoint_mock" ) @pytest.mark.parametrize("sync", [True, False]) - def test_deploy_no_endpoint_with_explanations( - self, deploy_model_with_explanations_mock, sync - ): + def test_deploy_no_endpoint_with_explanations(self, deploy_model_mock, sync): test_model = models.Model(_TEST_ID) + test_model._gca_resource.supported_deployment_resources_types.append( + aiplatform.gapic.Model.DeploymentResourcesType.DEDICATED_RESOURCES + ) test_endpoint = test_model.deploy( machine_type=_TEST_MACHINE_TYPE, accelerator_type=_TEST_ACCELERATOR_TYPE, @@ -850,33 +1177,35 @@ def test_deploy_no_endpoint_with_explanations( explanation_metadata=_TEST_EXPLANATION_METADATA, explanation_parameters=_TEST_EXPLANATION_PARAMETERS, sync=sync, + deploy_request_timeout=None, ) if not sync: test_endpoint.wait() - expected_machine_spec = gca_machine_resources_v1beta1.MachineSpec( + expected_machine_spec = gca_machine_resources.MachineSpec( machine_type=_TEST_MACHINE_TYPE, accelerator_type=_TEST_ACCELERATOR_TYPE, accelerator_count=_TEST_ACCELERATOR_COUNT, ) - expected_dedicated_resources = gca_machine_resources_v1beta1.DedicatedResources( + expected_dedicated_resources = gca_machine_resources.DedicatedResources( machine_spec=expected_machine_spec, min_replica_count=1, max_replica_count=1 ) - expected_deployed_model = gca_endpoint_v1beta1.DeployedModel( + expected_deployed_model = gca_endpoint.DeployedModel( dedicated_resources=expected_dedicated_resources, model=test_model.resource_name, display_name=None, - explanation_spec=gca_endpoint_v1beta1.explanation.ExplanationSpec( + explanation_spec=gca_endpoint.explanation.ExplanationSpec( metadata=_TEST_EXPLANATION_METADATA, parameters=_TEST_EXPLANATION_PARAMETERS, ), ) - deploy_model_with_explanations_mock.assert_called_once_with( + deploy_model_mock.assert_called_once_with( endpoint=test_endpoint.resource_name, deployed_model=expected_deployed_model, traffic_split={"0": 100}, metadata=(), + timeout=None, ) @pytest.mark.usefixtures( @@ -885,6 +1214,9 @@ def test_deploy_no_endpoint_with_explanations( def test_deploy_raises_with_impartial_explanation_spec(self): test_model = models.Model(_TEST_ID) + test_model._gca_resource.supported_deployment_resources_types.append( + aiplatform.gapic.Model.DeploymentResourcesType.DEDICATED_RESOURCES + ) with pytest.raises(ValueError) as e: test_model.deploy( @@ -915,33 +1247,39 @@ def test_init_aiplatform_with_encryption_key_name_and_batch_predict_gcs_source_a gcs_source=_TEST_BATCH_PREDICTION_GCS_SOURCE, gcs_destination_prefix=_TEST_BATCH_PREDICTION_GCS_DEST_PREFIX, sync=sync, + create_request_timeout=None, ) if not sync: batch_prediction_job.wait() # Construct expected request - expected_gapic_batch_prediction_job = gca_batch_prediction_job.BatchPredictionJob( - display_name=_TEST_BATCH_PREDICTION_DISPLAY_NAME, - model=model_service_client.ModelServiceClient.model_path( - _TEST_PROJECT, _TEST_LOCATION, _TEST_ID - ), - input_config=gca_batch_prediction_job.BatchPredictionJob.InputConfig( - instances_format="jsonl", - gcs_source=gca_io.GcsSource(uris=[_TEST_BATCH_PREDICTION_GCS_SOURCE]), - ), - output_config=gca_batch_prediction_job.BatchPredictionJob.OutputConfig( - gcs_destination=gca_io.GcsDestination( - output_uri_prefix=_TEST_BATCH_PREDICTION_GCS_DEST_PREFIX + expected_gapic_batch_prediction_job = ( + gca_batch_prediction_job.BatchPredictionJob( + display_name=_TEST_BATCH_PREDICTION_DISPLAY_NAME, + model=model_service_client.ModelServiceClient.model_path( + _TEST_PROJECT, _TEST_LOCATION, _TEST_ID ), - predictions_format="jsonl", - ), - encryption_spec=_TEST_ENCRYPTION_SPEC, + input_config=gca_batch_prediction_job.BatchPredictionJob.InputConfig( + instances_format="jsonl", + gcs_source=gca_io.GcsSource( + uris=[_TEST_BATCH_PREDICTION_GCS_SOURCE] + ), + ), + output_config=gca_batch_prediction_job.BatchPredictionJob.OutputConfig( + gcs_destination=gca_io.GcsDestination( + output_uri_prefix=_TEST_BATCH_PREDICTION_GCS_DEST_PREFIX + ), + predictions_format="jsonl", + ), + encryption_spec=_TEST_ENCRYPTION_SPEC, + ) ) create_batch_prediction_job_mock.assert_called_once_with( parent=_TEST_PARENT, batch_prediction_job=expected_gapic_batch_prediction_job, + timeout=None, ) @pytest.mark.parametrize("sync", [True, False]) @@ -958,32 +1296,38 @@ def test_batch_predict_gcs_source_and_dest( gcs_source=_TEST_BATCH_PREDICTION_GCS_SOURCE, gcs_destination_prefix=_TEST_BATCH_PREDICTION_GCS_DEST_PREFIX, sync=sync, + create_request_timeout=None, ) if not sync: batch_prediction_job.wait() # Construct expected request - expected_gapic_batch_prediction_job = gca_batch_prediction_job.BatchPredictionJob( - display_name=_TEST_BATCH_PREDICTION_DISPLAY_NAME, - model=model_service_client.ModelServiceClient.model_path( - _TEST_PROJECT, _TEST_LOCATION, _TEST_ID - ), - input_config=gca_batch_prediction_job.BatchPredictionJob.InputConfig( - instances_format="jsonl", - gcs_source=gca_io.GcsSource(uris=[_TEST_BATCH_PREDICTION_GCS_SOURCE]), - ), - output_config=gca_batch_prediction_job.BatchPredictionJob.OutputConfig( - gcs_destination=gca_io.GcsDestination( - output_uri_prefix=_TEST_BATCH_PREDICTION_GCS_DEST_PREFIX + expected_gapic_batch_prediction_job = ( + gca_batch_prediction_job.BatchPredictionJob( + display_name=_TEST_BATCH_PREDICTION_DISPLAY_NAME, + model=model_service_client.ModelServiceClient.model_path( + _TEST_PROJECT, _TEST_LOCATION, _TEST_ID ), - predictions_format="jsonl", - ), + input_config=gca_batch_prediction_job.BatchPredictionJob.InputConfig( + instances_format="jsonl", + gcs_source=gca_io.GcsSource( + uris=[_TEST_BATCH_PREDICTION_GCS_SOURCE] + ), + ), + output_config=gca_batch_prediction_job.BatchPredictionJob.OutputConfig( + gcs_destination=gca_io.GcsDestination( + output_uri_prefix=_TEST_BATCH_PREDICTION_GCS_DEST_PREFIX + ), + predictions_format="jsonl", + ), + ) ) create_batch_prediction_job_mock.assert_called_once_with( parent=_TEST_PARENT, batch_prediction_job=expected_gapic_batch_prediction_job, + timeout=None, ) @pytest.mark.parametrize("sync", [True, False]) @@ -1000,39 +1344,43 @@ def test_batch_predict_gcs_source_bq_dest( gcs_source=_TEST_BATCH_PREDICTION_GCS_SOURCE, bigquery_destination_prefix=_TEST_BATCH_PREDICTION_BQ_PREFIX, sync=sync, + create_request_timeout=None, ) if not sync: batch_prediction_job.wait() # Construct expected request - expected_gapic_batch_prediction_job = gca_batch_prediction_job.BatchPredictionJob( - display_name=_TEST_BATCH_PREDICTION_DISPLAY_NAME, - model=model_service_client.ModelServiceClient.model_path( - _TEST_PROJECT, _TEST_LOCATION, _TEST_ID - ), - input_config=gca_batch_prediction_job.BatchPredictionJob.InputConfig( - instances_format="jsonl", - gcs_source=gca_io.GcsSource(uris=[_TEST_BATCH_PREDICTION_GCS_SOURCE]), - ), - output_config=gca_batch_prediction_job.BatchPredictionJob.OutputConfig( - bigquery_destination=gca_io.BigQueryDestination( - output_uri=_TEST_BATCH_PREDICTION_BQ_DEST_PREFIX_WITH_PROTOCOL + expected_gapic_batch_prediction_job = ( + gca_batch_prediction_job.BatchPredictionJob( + display_name=_TEST_BATCH_PREDICTION_DISPLAY_NAME, + model=model_service_client.ModelServiceClient.model_path( + _TEST_PROJECT, _TEST_LOCATION, _TEST_ID ), - predictions_format="bigquery", - ), + input_config=gca_batch_prediction_job.BatchPredictionJob.InputConfig( + instances_format="jsonl", + gcs_source=gca_io.GcsSource( + uris=[_TEST_BATCH_PREDICTION_GCS_SOURCE] + ), + ), + output_config=gca_batch_prediction_job.BatchPredictionJob.OutputConfig( + bigquery_destination=gca_io.BigQueryDestination( + output_uri=_TEST_BATCH_PREDICTION_BQ_DEST_PREFIX_WITH_PROTOCOL + ), + predictions_format="bigquery", + ), + ) ) create_batch_prediction_job_mock.assert_called_once_with( parent=_TEST_PARENT, batch_prediction_job=expected_gapic_batch_prediction_job, + timeout=None, ) @pytest.mark.parametrize("sync", [True, False]) @pytest.mark.usefixtures("get_model_mock", "get_batch_prediction_job_mock") - def test_batch_predict_with_all_args( - self, create_batch_prediction_job_with_explanations_mock, sync - ): + def test_batch_predict_with_all_args(self, create_batch_prediction_job_mock, sync): test_model = models.Model(_TEST_ID) creds = auth_credentials.AnonymousCredentials() @@ -1055,31 +1403,31 @@ def test_batch_predict_with_all_args( credentials=creds, encryption_spec_key_name=_TEST_ENCRYPTION_KEY_NAME, sync=sync, + create_request_timeout=None, + batch_size=_TEST_BATCH_SIZE, ) if not sync: batch_prediction_job.wait() # Construct expected request - expected_gapic_batch_prediction_job = gca_batch_prediction_job_v1beta1.BatchPredictionJob( + expected_gapic_batch_prediction_job = gca_batch_prediction_job.BatchPredictionJob( display_name=_TEST_BATCH_PREDICTION_DISPLAY_NAME, - model=model_service_client_v1beta1.ModelServiceClient.model_path( + model=model_service_client.ModelServiceClient.model_path( _TEST_PROJECT, _TEST_LOCATION, _TEST_ID ), - input_config=gca_batch_prediction_job_v1beta1.BatchPredictionJob.InputConfig( + input_config=gca_batch_prediction_job.BatchPredictionJob.InputConfig( instances_format="jsonl", - gcs_source=gca_io_v1beta1.GcsSource( - uris=[_TEST_BATCH_PREDICTION_GCS_SOURCE] - ), + gcs_source=gca_io.GcsSource(uris=[_TEST_BATCH_PREDICTION_GCS_SOURCE]), ), - output_config=gca_batch_prediction_job_v1beta1.BatchPredictionJob.OutputConfig( - gcs_destination=gca_io_v1beta1.GcsDestination( + output_config=gca_batch_prediction_job.BatchPredictionJob.OutputConfig( + gcs_destination=gca_io.GcsDestination( output_uri_prefix=_TEST_BATCH_PREDICTION_GCS_DEST_PREFIX ), predictions_format="csv", ), - dedicated_resources=gca_machine_resources_v1beta1.BatchDedicatedResources( - machine_spec=gca_machine_resources_v1beta1.MachineSpec( + dedicated_resources=gca_machine_resources.BatchDedicatedResources( + machine_spec=gca_machine_resources.MachineSpec( machine_type=_TEST_MACHINE_TYPE, accelerator_type=_TEST_ACCELERATOR_TYPE, accelerator_count=_TEST_ACCELERATOR_COUNT, @@ -1087,18 +1435,22 @@ def test_batch_predict_with_all_args( starting_replica_count=_TEST_STARTING_REPLICA_COUNT, max_replica_count=_TEST_MAX_REPLICA_COUNT, ), + manual_batch_tuning_parameters=gca_manual_batch_tuning_parameters_compat.ManualBatchTuningParameters( + batch_size=_TEST_BATCH_SIZE + ), generate_explanation=True, - explanation_spec=gca_explanation_v1beta1.ExplanationSpec( + explanation_spec=gca_explanation.ExplanationSpec( metadata=_TEST_EXPLANATION_METADATA, parameters=_TEST_EXPLANATION_PARAMETERS, ), labels=_TEST_LABEL, - encryption_spec=_TEST_ENCRYPTION_SPEC_V1BETA1, + encryption_spec=_TEST_ENCRYPTION_SPEC, ) - create_batch_prediction_job_with_explanations_mock.assert_called_once_with( + create_batch_prediction_job_mock.assert_called_once_with( parent=f"projects/{_TEST_PROJECT}/locations/{_TEST_LOCATION}", batch_prediction_job=expected_gapic_batch_prediction_job, + timeout=None, ) @pytest.mark.usefixtures("get_model_mock", "get_batch_prediction_job_mock") @@ -1339,7 +1691,8 @@ def test_export_model_as_image_with_invalid_args(self, export_model_mock, sync): test_model = models.Model(_TEST_ID) test_model.export_model( - export_format_id=_TEST_EXPORT_FORMAT_ID_IMAGE, sync=sync, + export_format_id=_TEST_EXPORT_FORMAT_ID_IMAGE, + sync=sync, ) if not sync: @@ -1384,3 +1737,305 @@ def test_export_model_as_artifact_with_invalid_args(self, export_model_mock, syn assert e.match( regexp=r"This model can not be exported as a container image." ) + + @pytest.mark.usefixtures( + "get_training_job_non_existent_mock", "get_model_with_training_job" + ) + def test_get_and_return_subclass_not_found(self): + test_model = models.Model(_TEST_ID) + + # Attempt to access Model's training job that no longer exists + with pytest.raises(api_exceptions.NotFound) as e: + test_model.training_job + + assert e.match( + regexp=( + r"The training job used to create this model could not be found: " + rf"{_TEST_PIPELINE_RESOURCE_NAME}" + ) + ) + + @pytest.mark.parametrize("sync", [True, False]) + @pytest.mark.parametrize( + "model_file_name", + ["my_model.xgb", "my_model.pkl", "my_model.joblib", "my_model.bst"], + ) + def test_upload_xgboost_model_file_uploads_and_gets_model( + self, + tmp_path: pathlib.Path, + model_file_name: str, + mock_storage_blob_upload_from_filename, + upload_model_mock, + get_model_mock, + sync: bool, + ): + model_file_path = tmp_path / model_file_name + model_file_path.touch() + + my_model = models.Model.upload_xgboost_model_file( + model_file_path=str(model_file_path), + xgboost_version="1.4", + display_name=_TEST_MODEL_NAME, + project=_TEST_PROJECT, + location=_TEST_LOCATION, + sync=sync, + upload_request_timeout=None, + ) + + if not sync: + my_model.wait() + + upload_model_mock.assert_called_once() + upload_model_call_kwargs = upload_model_mock.call_args[1] + upload_model_model = upload_model_call_kwargs["model"] + + # Verifying the container image selection + assert ( + upload_model_model.container_spec.image_uri + == "us-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.1-4:latest" + ) + + # Verifying the staging bucket name generation + assert upload_model_model.artifact_uri.startswith( + f"gs://{_TEST_PROJECT}-vertex-staging-{_TEST_LOCATION}" + ) + assert "/vertex_ai_auto_staging/" in upload_model_model.artifact_uri + + # Verifying that the model was renamed to a file name that is acceptable for Model.upload + staged_model_file_path = mock_storage_blob_upload_from_filename.call_args[1][ + "filename" + ] + staged_model_file_name = staged_model_file_path.split("/")[-1] + assert staged_model_file_name in ["model.bst", "model.pkl", "model.joblib"] + + @pytest.mark.parametrize("sync", [True, False]) + @pytest.mark.parametrize( + "model_file_name", + [ + "model.bst", + "model.pkl", + "model.joblib", + "saved_model.pb", + "saved_model.pbtxt", + ], + ) + def test_upload_stages_data_uploads_and_gets_model( + self, + tmp_path: pathlib.Path, + model_file_name: str, + mock_storage_blob_upload_from_filename, + upload_model_mock, + get_model_mock, + sync: bool, + ): + model_file_path = tmp_path / model_file_name + model_file_path.touch() + + my_model = models.Model.upload( + artifact_uri=str(tmp_path), + serving_container_image_uri="us-docker.pkg.dev/vertex-ai/prediction/xgboost-cpu.1-4:latest", + display_name=_TEST_MODEL_NAME, + project=_TEST_PROJECT, + location=_TEST_LOCATION, + sync=sync, + ) + + if not sync: + my_model.wait() + + upload_model_mock.assert_called_once() + upload_model_call_kwargs = upload_model_mock.call_args[1] + upload_model_model = upload_model_call_kwargs["model"] + + # Verifying the staging bucket name generation + assert upload_model_model.artifact_uri.startswith( + f"gs://{_TEST_PROJECT}-vertex-staging-{_TEST_LOCATION}" + ) + assert "/vertex_ai_auto_staging/" in upload_model_model.artifact_uri + + # Verifying that the model was renamed to a file name that is acceptable for Model.upload + staged_model_file_path = mock_storage_blob_upload_from_filename.call_args[1][ + "filename" + ] + staged_model_file_name = staged_model_file_path.split("/")[-1] + assert staged_model_file_name in [ + "model.bst", + "model.pkl", + "model.joblib", + "saved_model.pb", + "saved_model.pbtxt", + ] + + @pytest.mark.parametrize("sync", [True, False]) + @pytest.mark.parametrize( + "model_file_name", + ["my_model.pkl", "my_model.joblib"], + ) + def test_upload_scikit_learn_model_file_uploads_and_gets_model( + self, + tmp_path: pathlib.Path, + model_file_name: str, + mock_storage_blob_upload_from_filename, + upload_model_mock, + get_model_mock, + sync: bool, + ): + model_file_path = tmp_path / model_file_name + model_file_path.touch() + + my_model = models.Model.upload_scikit_learn_model_file( + model_file_path=str(model_file_path), + sklearn_version="0.24", + display_name=_TEST_MODEL_NAME, + project=_TEST_PROJECT, + location=_TEST_LOCATION, + sync=sync, + upload_request_timeout=None, + ) + + if not sync: + my_model.wait() + + upload_model_mock.assert_called_once() + upload_model_call_kwargs = upload_model_mock.call_args[1] + upload_model_model = upload_model_call_kwargs["model"] + + # Verifying the container image selection + assert ( + upload_model_model.container_spec.image_uri + == "us-docker.pkg.dev/vertex-ai/prediction/sklearn-cpu.0-24:latest" + ) + + # Verifying the staging bucket name generation + assert upload_model_model.artifact_uri.startswith( + f"gs://{_TEST_PROJECT}-vertex-staging-{_TEST_LOCATION}" + ) + assert "/vertex_ai_auto_staging/" in upload_model_model.artifact_uri + + # Verifying that the model was renamed to a file name that is acceptable for Model.upload + staged_model_file_path = mock_storage_blob_upload_from_filename.call_args[1][ + "filename" + ] + staged_model_file_name = staged_model_file_path.split("/")[-1] + assert staged_model_file_name in ["model.pkl", "model.joblib"] + + @pytest.mark.parametrize("sync", [True, False]) + def test_upload_tensorflow_saved_model_uploads_and_gets_model( + self, + tmp_path: pathlib.Path, + mock_storage_blob_upload_from_filename, + upload_model_mock, + get_model_mock, + sync: bool, + ): + saved_model_dir = tmp_path / "saved_model" + saved_model_dir.mkdir() + (saved_model_dir / "saved_model.pb").touch() + + my_model = models.Model.upload_tensorflow_saved_model( + saved_model_dir=str(saved_model_dir), + tensorflow_version="2.6", + use_gpu=True, + display_name=_TEST_MODEL_NAME, + project=_TEST_PROJECT, + location=_TEST_LOCATION, + sync=sync, + upload_request_timeout=None, + ) + + if not sync: + my_model.wait() + + upload_model_mock.assert_called_once() + upload_model_call_kwargs = upload_model_mock.call_args[1] + upload_model_model = upload_model_call_kwargs["model"] + + # Verifying the container image selection + assert ( + upload_model_model.container_spec.image_uri + == "us-docker.pkg.dev/vertex-ai/prediction/tf2-gpu.2-6:latest" + ) + + # Verifying the staging bucket name generation + assert upload_model_model.artifact_uri.startswith( + f"gs://{_TEST_PROJECT}-vertex-staging-{_TEST_LOCATION}" + ) + assert "/vertex_ai_auto_staging/" in upload_model_model.artifact_uri + + # Verifying that the model files were uploaded + staged_model_file_path = mock_storage_blob_upload_from_filename.call_args[1][ + "filename" + ] + staged_model_file_name = staged_model_file_path.split("/")[-1] + assert staged_model_file_name in ["saved_model.pb", "saved_model.pbtxt"] + + @pytest.mark.usefixtures("get_model_mock") + def test_update(self, update_model_mock, get_model_mock): + + test_model = models.Model(_TEST_ID) + + test_model.update( + display_name=_TEST_MODEL_NAME, + description=_TEST_DESCRIPTION, + labels=_TEST_LABEL, + ) + + current_model_proto = gca_model.Model( + display_name=_TEST_MODEL_NAME, + description=_TEST_DESCRIPTION, + labels=_TEST_LABEL, + name=_TEST_MODEL_RESOURCE_NAME, + ) + + update_mask = field_mask_pb2.FieldMask( + paths=["display_name", "description", "labels"] + ) + + update_model_mock.assert_called_once_with( + model=current_model_proto, update_mask=update_mask + ) + + def test_get_model_evaluation_with_id( + self, + mock_model_eval_get, + get_model_mock, + list_model_evaluations_mock, + ): + test_model = models.Model(model_name=_TEST_MODEL_RESOURCE_NAME) + + test_model.get_model_evaluation(evaluation_id=_TEST_ID) + + mock_model_eval_get.assert_called_once_with( + name=_TEST_MODEL_EVAL_RESOURCE_NAME, retry=base._DEFAULT_RETRY + ) + + def test_get_model_evaluation_without_id( + self, + mock_model_eval_get, + get_model_mock, + list_model_evaluations_mock, + ): + test_model = models.Model(model_name=_TEST_MODEL_RESOURCE_NAME) + + test_model.get_model_evaluation() + + list_model_evaluations_mock.assert_called_once_with( + request={"parent": _TEST_MODEL_RESOURCE_NAME, "filter": None} + ) + + def test_list_model_evaluations( + self, + get_model_mock, + mock_model_eval_get, + list_model_evaluations_mock, + ): + + test_model = models.Model(model_name=_TEST_MODEL_RESOURCE_NAME) + + eval_list = test_model.list_model_evaluations() + + list_model_evaluations_mock.assert_called_once_with( + request={"parent": _TEST_MODEL_RESOURCE_NAME, "filter": None} + ) + + assert len(eval_list) == len(_TEST_MODEL_EVAL_LIST) diff --git a/tests/unit/aiplatform/test_pipeline_jobs.py b/tests/unit/aiplatform/test_pipeline_jobs.py new file mode 100644 index 0000000000..5f6b24fd09 --- /dev/null +++ b/tests/unit/aiplatform/test_pipeline_jobs.py @@ -0,0 +1,1386 @@ +# -*- coding: utf-8 -*- + +# Copyright 2022 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. +# + +import yaml +import pytest +import json + +from unittest import mock +from importlib import reload +from unittest.mock import patch +from urllib import request +from datetime import datetime + +from google.auth import credentials as auth_credentials +from google.cloud import aiplatform +from google.cloud.aiplatform import base +from google.cloud.aiplatform import initializer +from google.cloud.aiplatform import pipeline_jobs +from google.cloud.aiplatform.compat.types import pipeline_failure_policy +from google.cloud import storage +from google.protobuf import json_format + +from google.cloud.aiplatform.compat.services import ( + pipeline_service_client, +) +from google.cloud.aiplatform.compat.types import ( + pipeline_job as gca_pipeline_job, + pipeline_state as gca_pipeline_state, + context as gca_context, +) + +_TEST_PROJECT = "test-project" +_TEST_LOCATION = "us-central1" +_TEST_PIPELINE_JOB_DISPLAY_NAME = "sample-pipeline-job-display-name" +_TEST_PIPELINE_JOB_ID = "sample-test-pipeline-202111111" +_TEST_GCS_BUCKET_NAME = "my-bucket" +_TEST_CREDENTIALS = auth_credentials.AnonymousCredentials() +_TEST_SERVICE_ACCOUNT = "abcde@my-project.iam.gserviceaccount.com" + +_TEST_TEMPLATE_PATH = f"gs://{_TEST_GCS_BUCKET_NAME}/job_spec.json" +_TEST_AR_TEMPLATE_PATH = "https://us-central1-kfp.pkg.dev/proj/repo/pack/latest" +_TEST_PARENT = f"projects/{_TEST_PROJECT}/locations/{_TEST_LOCATION}" +_TEST_NETWORK = f"projects/{_TEST_PROJECT}/global/networks/{_TEST_PIPELINE_JOB_ID}" + +_TEST_PIPELINE_JOB_NAME = f"projects/{_TEST_PROJECT}/locations/{_TEST_LOCATION}/pipelineJobs/{_TEST_PIPELINE_JOB_ID}" + +_TEST_PIPELINE_PARAMETER_VALUES_LEGACY = {"string_param": "hello"} +_TEST_PIPELINE_PARAMETER_VALUES = { + "string_param": "hello world", + "bool_param": True, + "double_param": 12.34, + "int_param": 5678, + "list_int_param": [123, 456, 789], + "list_string_param": ["lorem", "ipsum"], + "struct_param": {"key1": 12345, "key2": 67890}, +} + +_TEST_PIPELINE_SPEC_LEGACY_JSON = json.dumps( + { + "pipelineInfo": {"name": "my-pipeline"}, + "root": { + "dag": {"tasks": {}}, + "inputDefinitions": {"parameters": {"string_param": {"type": "STRING"}}}, + }, + "schemaVersion": "2.0.0", + "components": {}, + } +) +_TEST_PIPELINE_SPEC_LEGACY_YAML = """\ +pipelineInfo: + name: my-pipeline +root: + dag: + tasks: {} + inputDefinitions: + parameters: + string_param: + type: STRING +schemaVersion: 2.0.0 +components: {} +""" +_TEST_PIPELINE_SPEC_JSON = json.dumps( + { + "pipelineInfo": {"name": "my-pipeline"}, + "root": { + "dag": {"tasks": {}}, + "inputDefinitions": { + "parameters": { + "string_param": {"parameterType": "STRING"}, + "bool_param": {"parameterType": "BOOLEAN"}, + "double_param": {"parameterType": "NUMBER_DOUBLE"}, + "int_param": {"parameterType": "NUMBER_INTEGER"}, + "list_int_param": {"parameterType": "LIST"}, + "list_string_param": {"parameterType": "LIST"}, + "struct_param": {"parameterType": "STRUCT"}, + } + }, + }, + "schemaVersion": "2.1.0", + "components": {}, + } +) +_TEST_PIPELINE_SPEC_YAML = """\ +pipelineInfo: + name: my-pipeline +root: + dag: + tasks: {} + inputDefinitions: + parameters: + string_param: + parameterType: STRING + bool_param: + parameterType: BOOLEAN + double_param: + parameterType: NUMBER_DOUBLE + int_param: + parameterType: NUMBER_INTEGER + list_int_param: + parameterType: LIST + list_string_param: + parameterType: LIST + struct_param: + parameterType: STRUCT +schemaVersion: 2.1.0 +components: {} +""" +_TEST_TFX_PIPELINE_SPEC_JSON = json.dumps( + { + "pipelineInfo": {"name": "my-pipeline"}, + "root": { + "dag": {"tasks": {}}, + "inputDefinitions": {"parameters": {"string_param": {"type": "STRING"}}}, + }, + "schemaVersion": "2.0.0", + "sdkVersion": "tfx-1.4.0", + "components": {}, + } +) +_TEST_TFX_PIPELINE_SPEC_YAML = """\ +pipelineInfo: + name: my-pipeline +root: + dag: + tasks: {} + inputDefinitions: + parameters: + string_param: + type: STRING +schemaVersion: 2.0.0 +sdkVersion: tfx-1.4.0 +components: {} +""" + +_TEST_PIPELINE_JOB_LEGACY = json.dumps( + {"runtimeConfig": {}, "pipelineSpec": json.loads(_TEST_PIPELINE_SPEC_LEGACY_JSON)} +) +_TEST_PIPELINE_JOB = json.dumps( + { + "runtimeConfig": {"parameterValues": _TEST_PIPELINE_PARAMETER_VALUES}, + "pipelineSpec": json.loads(_TEST_PIPELINE_SPEC_JSON), + } +) +_TEST_PIPELINE_JOB_TFX = json.dumps( + {"runtimeConfig": {}, "pipelineSpec": json.loads(_TEST_TFX_PIPELINE_SPEC_JSON)} +) + +_TEST_PIPELINE_GET_METHOD_NAME = "get_fake_pipeline_job" +_TEST_PIPELINE_LIST_METHOD_NAME = "list_fake_pipeline_jobs" +_TEST_PIPELINE_CANCEL_METHOD_NAME = "cancel_fake_pipeline_job" +_TEST_PIPELINE_DELETE_METHOD_NAME = "delete_fake_pipeline_job" +_TEST_PIPELINE_RESOURCE_NAME = ( + f"{_TEST_PARENT}/fakePipelineJobs/{_TEST_PIPELINE_JOB_ID}" +) +_TEST_PIPELINE_CREATE_TIME = datetime.now() + + +@pytest.fixture +def mock_pipeline_service_create(): + with mock.patch.object( + pipeline_service_client.PipelineServiceClient, "create_pipeline_job" + ) as mock_create_pipeline_job: + mock_create_pipeline_job.return_value = gca_pipeline_job.PipelineJob( + name=_TEST_PIPELINE_JOB_NAME, + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, + create_time=_TEST_PIPELINE_CREATE_TIME, + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, + ) + yield mock_create_pipeline_job + + +def make_pipeline_job(state): + return gca_pipeline_job.PipelineJob( + name=_TEST_PIPELINE_JOB_NAME, + state=state, + create_time=_TEST_PIPELINE_CREATE_TIME, + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, + job_detail=gca_pipeline_job.PipelineJobDetail( + pipeline_run_context=gca_context.Context( + name=_TEST_PIPELINE_JOB_NAME, + ) + ), + ) + + +@pytest.fixture +def mock_pipeline_service_get(): + with mock.patch.object( + pipeline_service_client.PipelineServiceClient, "get_pipeline_job" + ) as mock_get_pipeline_job: + mock_get_pipeline_job.side_effect = [ + make_pipeline_job(gca_pipeline_state.PipelineState.PIPELINE_STATE_RUNNING), + make_pipeline_job( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ), + make_pipeline_job( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ), + make_pipeline_job( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ), + make_pipeline_job( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ), + make_pipeline_job( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ), + make_pipeline_job( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ), + make_pipeline_job( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ), + make_pipeline_job( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ), + ] + + yield mock_get_pipeline_job + + +@pytest.fixture +def mock_pipeline_service_get_with_fail(): + with mock.patch.object( + pipeline_service_client.PipelineServiceClient, "get_pipeline_job" + ) as mock_get_pipeline_job: + mock_get_pipeline_job.side_effect = [ + make_pipeline_job(gca_pipeline_state.PipelineState.PIPELINE_STATE_RUNNING), + make_pipeline_job(gca_pipeline_state.PipelineState.PIPELINE_STATE_RUNNING), + make_pipeline_job(gca_pipeline_state.PipelineState.PIPELINE_STATE_FAILED), + ] + + yield mock_get_pipeline_job + + +@pytest.fixture +def mock_pipeline_service_cancel(): + with mock.patch.object( + pipeline_service_client.PipelineServiceClient, "cancel_pipeline_job" + ) as mock_cancel_pipeline_job: + yield mock_cancel_pipeline_job + + +@pytest.fixture +def mock_pipeline_service_list(): + with mock.patch.object( + pipeline_service_client.PipelineServiceClient, "list_pipeline_jobs" + ) as mock_list_pipeline_jobs: + yield mock_list_pipeline_jobs + + +@pytest.fixture +def mock_load_yaml_and_json(job_spec): + with patch.object(storage.Blob, "download_as_bytes") as mock_load_yaml_and_json: + mock_load_yaml_and_json.return_value = job_spec.encode() + yield mock_load_yaml_and_json + + +@pytest.fixture +def mock_request_urlopen(job_spec): + with patch.object(request, "urlopen") as mock_urlopen: + mock_read_response = mock.MagicMock() + mock_decode_response = mock.MagicMock() + mock_decode_response.return_value = job_spec.encode() + mock_read_response.return_value.decode = mock_decode_response + mock_urlopen.return_value.read = mock_read_response + yield mock_urlopen + + +@pytest.mark.usefixtures("google_auth_mock") +class TestPipelineJob: + def setup_method(self): + reload(initializer) + reload(aiplatform) + aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) + + def teardown_method(self): + initializer.global_pool.shutdown(wait=True) + + @pytest.mark.parametrize( + "job_spec", + [_TEST_PIPELINE_SPEC_JSON, _TEST_PIPELINE_SPEC_YAML, _TEST_PIPELINE_JOB], + ) + @pytest.mark.parametrize("sync", [True, False]) + def test_run_call_pipeline_service_create( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + job_spec, + mock_load_yaml_and_json, + sync, + ): + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_GCS_BUCKET_NAME, + location=_TEST_LOCATION, + credentials=_TEST_CREDENTIALS, + ) + + job = pipeline_jobs.PipelineJob( + display_name=_TEST_PIPELINE_JOB_DISPLAY_NAME, + template_path=_TEST_TEMPLATE_PATH, + job_id=_TEST_PIPELINE_JOB_ID, + parameter_values=_TEST_PIPELINE_PARAMETER_VALUES, + enable_caching=True, + ) + + job.run( + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, + sync=sync, + create_request_timeout=None, + ) + + if not sync: + job.wait() + + expected_runtime_config_dict = { + "gcsOutputDirectory": _TEST_GCS_BUCKET_NAME, + "parameterValues": _TEST_PIPELINE_PARAMETER_VALUES, + } + runtime_config = gca_pipeline_job.PipelineJob.RuntimeConfig()._pb + json_format.ParseDict(expected_runtime_config_dict, runtime_config) + + job_spec = yaml.safe_load(job_spec) + pipeline_spec = job_spec.get("pipelineSpec") or job_spec + + # Construct expected request + expected_gapic_pipeline_job = gca_pipeline_job.PipelineJob( + display_name=_TEST_PIPELINE_JOB_DISPLAY_NAME, + pipeline_spec={ + "components": {}, + "pipelineInfo": pipeline_spec["pipelineInfo"], + "root": pipeline_spec["root"], + "schemaVersion": "2.1.0", + }, + runtime_config=runtime_config, + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=_TEST_PARENT, + pipeline_job=expected_gapic_pipeline_job, + pipeline_job_id=_TEST_PIPELINE_JOB_ID, + timeout=None, + ) + + mock_pipeline_service_get.assert_called_with( + name=_TEST_PIPELINE_JOB_NAME, retry=base._DEFAULT_RETRY + ) + + assert job._gca_resource == make_pipeline_job( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) + + @pytest.mark.parametrize( + "job_spec", + [_TEST_PIPELINE_SPEC_JSON, _TEST_PIPELINE_SPEC_YAML, _TEST_PIPELINE_JOB], + ) + @pytest.mark.parametrize("sync", [True, False]) + def test_run_call_pipeline_service_create_artifact_registry( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + mock_request_urlopen, + job_spec, + mock_load_yaml_and_json, + sync, + ): + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_GCS_BUCKET_NAME, + location=_TEST_LOCATION, + credentials=_TEST_CREDENTIALS, + ) + + job = pipeline_jobs.PipelineJob( + display_name=_TEST_PIPELINE_JOB_DISPLAY_NAME, + template_path=_TEST_AR_TEMPLATE_PATH, + job_id=_TEST_PIPELINE_JOB_ID, + parameter_values=_TEST_PIPELINE_PARAMETER_VALUES, + enable_caching=True, + ) + + job.run( + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, + sync=sync, + create_request_timeout=None, + ) + + if not sync: + job.wait() + + expected_runtime_config_dict = { + "gcsOutputDirectory": _TEST_GCS_BUCKET_NAME, + "parameterValues": _TEST_PIPELINE_PARAMETER_VALUES, + } + runtime_config = gca_pipeline_job.PipelineJob.RuntimeConfig()._pb + json_format.ParseDict(expected_runtime_config_dict, runtime_config) + + job_spec = yaml.safe_load(job_spec) + pipeline_spec = job_spec.get("pipelineSpec") or job_spec + + # Construct expected request + expected_gapic_pipeline_job = gca_pipeline_job.PipelineJob( + display_name=_TEST_PIPELINE_JOB_DISPLAY_NAME, + pipeline_spec={ + "components": {}, + "pipelineInfo": pipeline_spec["pipelineInfo"], + "root": pipeline_spec["root"], + "schemaVersion": "2.1.0", + }, + runtime_config=runtime_config, + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, + template_uri=_TEST_AR_TEMPLATE_PATH, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=_TEST_PARENT, + pipeline_job=expected_gapic_pipeline_job, + pipeline_job_id=_TEST_PIPELINE_JOB_ID, + timeout=None, + ) + + mock_pipeline_service_get.assert_called_with( + name=_TEST_PIPELINE_JOB_NAME, retry=base._DEFAULT_RETRY + ) + + assert job._gca_resource == make_pipeline_job( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) + + @pytest.mark.parametrize( + "job_spec", + [ + _TEST_PIPELINE_SPEC_JSON, + _TEST_PIPELINE_SPEC_YAML, + _TEST_PIPELINE_JOB, + ], + ) + @pytest.mark.parametrize("sync", [True, False]) + def test_run_call_pipeline_service_create_with_timeout( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + job_spec, + mock_load_yaml_and_json, + sync, + ): + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_GCS_BUCKET_NAME, + location=_TEST_LOCATION, + credentials=_TEST_CREDENTIALS, + ) + + job = pipeline_jobs.PipelineJob( + display_name=_TEST_PIPELINE_JOB_DISPLAY_NAME, + template_path=_TEST_TEMPLATE_PATH, + job_id=_TEST_PIPELINE_JOB_ID, + parameter_values=_TEST_PIPELINE_PARAMETER_VALUES, + enable_caching=True, + ) + + job.run( + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, + sync=sync, + create_request_timeout=180.0, + ) + + if not sync: + job.wait() + + expected_runtime_config_dict = { + "gcsOutputDirectory": _TEST_GCS_BUCKET_NAME, + "parameterValues": _TEST_PIPELINE_PARAMETER_VALUES, + } + runtime_config = gca_pipeline_job.PipelineJob.RuntimeConfig()._pb + json_format.ParseDict(expected_runtime_config_dict, runtime_config) + + job_spec = yaml.safe_load(job_spec) + pipeline_spec = job_spec.get("pipelineSpec") or job_spec + + # Construct expected request + expected_gapic_pipeline_job = gca_pipeline_job.PipelineJob( + display_name=_TEST_PIPELINE_JOB_DISPLAY_NAME, + pipeline_spec={ + "components": {}, + "pipelineInfo": pipeline_spec["pipelineInfo"], + "root": pipeline_spec["root"], + "schemaVersion": "2.1.0", + }, + runtime_config=runtime_config, + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=_TEST_PARENT, + pipeline_job=expected_gapic_pipeline_job, + pipeline_job_id=_TEST_PIPELINE_JOB_ID, + timeout=180.0, + ) + + # mock_pipeline_service_get.assert_called_with( + # name=_TEST_PIPELINE_JOB_NAME, retry=base._DEFAULT_RETRY + # ) + + # assert job._gca_resource == make_pipeline_job( + # gca_pipeline_state_v1.PipelineState.PIPELINE_STATE_SUCCEEDED + # ) + + @pytest.mark.parametrize( + "job_spec", + [ + _TEST_PIPELINE_SPEC_JSON, + _TEST_PIPELINE_SPEC_YAML, + _TEST_PIPELINE_JOB, + ], + ) + @pytest.mark.parametrize("sync", [True, False]) + def test_run_call_pipeline_service_create_with_timeout_not_explicitly_set( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + job_spec, + mock_load_yaml_and_json, + sync, + ): + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_GCS_BUCKET_NAME, + location=_TEST_LOCATION, + credentials=_TEST_CREDENTIALS, + ) + + job = pipeline_jobs.PipelineJob( + display_name=_TEST_PIPELINE_JOB_DISPLAY_NAME, + template_path=_TEST_TEMPLATE_PATH, + job_id=_TEST_PIPELINE_JOB_ID, + parameter_values=_TEST_PIPELINE_PARAMETER_VALUES, + enable_caching=True, + ) + + job.run( + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, + sync=sync, + ) + + if not sync: + job.wait() + + expected_runtime_config_dict = { + "gcsOutputDirectory": _TEST_GCS_BUCKET_NAME, + "parameterValues": _TEST_PIPELINE_PARAMETER_VALUES, + } + runtime_config = gca_pipeline_job.PipelineJob.RuntimeConfig()._pb + json_format.ParseDict(expected_runtime_config_dict, runtime_config) + + job_spec = yaml.safe_load(job_spec) + pipeline_spec = job_spec.get("pipelineSpec") or job_spec + + # Construct expected request + expected_gapic_pipeline_job = gca_pipeline_job.PipelineJob( + display_name=_TEST_PIPELINE_JOB_DISPLAY_NAME, + pipeline_spec={ + "components": {}, + "pipelineInfo": pipeline_spec["pipelineInfo"], + "root": pipeline_spec["root"], + "schemaVersion": "2.1.0", + }, + runtime_config=runtime_config, + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=_TEST_PARENT, + pipeline_job=expected_gapic_pipeline_job, + pipeline_job_id=_TEST_PIPELINE_JOB_ID, + timeout=None, + ) + + @pytest.mark.parametrize( + "job_spec", + [_TEST_PIPELINE_SPEC_JSON, _TEST_PIPELINE_SPEC_YAML, _TEST_PIPELINE_JOB], + ) + @pytest.mark.parametrize( + "failure_policy", + [ + ( + "slow", + pipeline_failure_policy.PipelineFailurePolicy.PIPELINE_FAILURE_POLICY_FAIL_SLOW, + ), + ( + "fast", + pipeline_failure_policy.PipelineFailurePolicy.PIPELINE_FAILURE_POLICY_FAIL_FAST, + ), + ], + ) + @pytest.mark.parametrize("sync", [True, False]) + def test_run_call_pipeline_service_create_with_failure_policy( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + job_spec, + mock_load_yaml_and_json, + failure_policy, + sync, + ): + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_GCS_BUCKET_NAME, + location=_TEST_LOCATION, + credentials=_TEST_CREDENTIALS, + ) + + job = pipeline_jobs.PipelineJob( + display_name=_TEST_PIPELINE_JOB_DISPLAY_NAME, + template_path=_TEST_TEMPLATE_PATH, + job_id=_TEST_PIPELINE_JOB_ID, + parameter_values=_TEST_PIPELINE_PARAMETER_VALUES, + enable_caching=True, + failure_policy=failure_policy[0], + ) + + job.run( + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, + sync=sync, + create_request_timeout=None, + ) + + if not sync: + job.wait() + + expected_runtime_config_dict = { + "gcsOutputDirectory": _TEST_GCS_BUCKET_NAME, + "parameterValues": _TEST_PIPELINE_PARAMETER_VALUES, + "failurePolicy": failure_policy[1], + } + runtime_config = gca_pipeline_job.PipelineJob.RuntimeConfig()._pb + json_format.ParseDict(expected_runtime_config_dict, runtime_config) + + job_spec = yaml.safe_load(job_spec) + pipeline_spec = job_spec.get("pipelineSpec") or job_spec + + # Construct expected request + expected_gapic_pipeline_job = gca_pipeline_job.PipelineJob( + display_name=_TEST_PIPELINE_JOB_DISPLAY_NAME, + pipeline_spec={ + "components": {}, + "pipelineInfo": pipeline_spec["pipelineInfo"], + "root": pipeline_spec["root"], + "schemaVersion": "2.1.0", + }, + runtime_config=runtime_config, + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=_TEST_PARENT, + pipeline_job=expected_gapic_pipeline_job, + pipeline_job_id=_TEST_PIPELINE_JOB_ID, + timeout=None, + ) + + mock_pipeline_service_get.assert_called_with( + name=_TEST_PIPELINE_JOB_NAME, retry=base._DEFAULT_RETRY + ) + + assert job._gca_resource == make_pipeline_job( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) + + @pytest.mark.parametrize( + "job_spec", + [ + _TEST_PIPELINE_SPEC_LEGACY_JSON, + _TEST_PIPELINE_SPEC_LEGACY_YAML, + _TEST_PIPELINE_JOB_LEGACY, + ], + ) + @pytest.mark.parametrize("sync", [True, False]) + def test_run_call_pipeline_service_create_legacy( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + job_spec, + mock_load_yaml_and_json, + sync, + ): + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_GCS_BUCKET_NAME, + location=_TEST_LOCATION, + credentials=_TEST_CREDENTIALS, + ) + + job = pipeline_jobs.PipelineJob( + display_name=_TEST_PIPELINE_JOB_DISPLAY_NAME, + template_path=_TEST_TEMPLATE_PATH, + job_id=_TEST_PIPELINE_JOB_ID, + parameter_values=_TEST_PIPELINE_PARAMETER_VALUES_LEGACY, + enable_caching=True, + ) + + job.run( + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, + sync=sync, + create_request_timeout=None, + ) + + if not sync: + job.wait() + + expected_runtime_config_dict = { + "gcsOutputDirectory": _TEST_GCS_BUCKET_NAME, + "parameters": {"string_param": {"stringValue": "hello"}}, + } + runtime_config = gca_pipeline_job.PipelineJob.RuntimeConfig()._pb + json_format.ParseDict(expected_runtime_config_dict, runtime_config) + + job_spec = yaml.safe_load(job_spec) + pipeline_spec = job_spec.get("pipelineSpec") or job_spec + + # Construct expected request + expected_gapic_pipeline_job = gca_pipeline_job.PipelineJob( + display_name=_TEST_PIPELINE_JOB_DISPLAY_NAME, + pipeline_spec={ + "components": {}, + "pipelineInfo": pipeline_spec["pipelineInfo"], + "root": pipeline_spec["root"], + "schemaVersion": "2.0.0", + }, + runtime_config=runtime_config, + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=_TEST_PARENT, + pipeline_job=expected_gapic_pipeline_job, + pipeline_job_id=_TEST_PIPELINE_JOB_ID, + timeout=None, + ) + + mock_pipeline_service_get.assert_called_with( + name=_TEST_PIPELINE_JOB_NAME, retry=base._DEFAULT_RETRY + ) + + assert job._gca_resource == make_pipeline_job( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) + + @pytest.mark.parametrize( + "job_spec", + [ + _TEST_TFX_PIPELINE_SPEC_JSON, + _TEST_TFX_PIPELINE_SPEC_YAML, + _TEST_PIPELINE_JOB_TFX, + ], + ) + @pytest.mark.parametrize("sync", [True, False]) + def test_run_call_pipeline_service_create_tfx( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + job_spec, + mock_load_yaml_and_json, + sync, + ): + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_GCS_BUCKET_NAME, + location=_TEST_LOCATION, + credentials=_TEST_CREDENTIALS, + ) + + job = pipeline_jobs.PipelineJob( + display_name=_TEST_PIPELINE_JOB_DISPLAY_NAME, + template_path=_TEST_TEMPLATE_PATH, + job_id=_TEST_PIPELINE_JOB_ID, + parameter_values=_TEST_PIPELINE_PARAMETER_VALUES_LEGACY, + enable_caching=True, + ) + + job.run( + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, + sync=sync, + create_request_timeout=None, + ) + + if not sync: + job.wait() + + expected_runtime_config_dict = { + "gcsOutputDirectory": _TEST_GCS_BUCKET_NAME, + "parameters": {"string_param": {"stringValue": "hello"}}, + } + runtime_config = gca_pipeline_job.PipelineJob.RuntimeConfig()._pb + json_format.ParseDict(expected_runtime_config_dict, runtime_config) + + job_spec = yaml.safe_load(job_spec) + pipeline_spec = job_spec.get("pipelineSpec") or job_spec + + # Construct expected request + expected_gapic_pipeline_job = gca_pipeline_job.PipelineJob( + display_name=_TEST_PIPELINE_JOB_DISPLAY_NAME, + pipeline_spec={ + "components": {}, + "pipelineInfo": pipeline_spec["pipelineInfo"], + "root": pipeline_spec["root"], + "schemaVersion": "2.0.0", + "sdkVersion": "tfx-1.4.0", + }, + runtime_config=runtime_config, + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=_TEST_PARENT, + pipeline_job=expected_gapic_pipeline_job, + pipeline_job_id=_TEST_PIPELINE_JOB_ID, + timeout=None, + ) + + mock_pipeline_service_get.assert_called_with( + name=_TEST_PIPELINE_JOB_NAME, retry=base._DEFAULT_RETRY + ) + + assert job._gca_resource == make_pipeline_job( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) + + @pytest.mark.parametrize( + "job_spec", + [_TEST_PIPELINE_SPEC_JSON, _TEST_PIPELINE_SPEC_YAML, _TEST_PIPELINE_JOB], + ) + def test_submit_call_pipeline_service_pipeline_job_create( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + job_spec, + mock_load_yaml_and_json, + ): + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_GCS_BUCKET_NAME, + location=_TEST_LOCATION, + credentials=_TEST_CREDENTIALS, + ) + + job = pipeline_jobs.PipelineJob( + display_name=_TEST_PIPELINE_JOB_DISPLAY_NAME, + template_path=_TEST_TEMPLATE_PATH, + job_id=_TEST_PIPELINE_JOB_ID, + parameter_values=_TEST_PIPELINE_PARAMETER_VALUES, + enable_caching=True, + ) + + job.submit( + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, + create_request_timeout=None, + ) + + expected_runtime_config_dict = { + "gcsOutputDirectory": _TEST_GCS_BUCKET_NAME, + "parameterValues": _TEST_PIPELINE_PARAMETER_VALUES, + } + runtime_config = gca_pipeline_job.PipelineJob.RuntimeConfig()._pb + json_format.ParseDict(expected_runtime_config_dict, runtime_config) + + job_spec = yaml.safe_load(job_spec) + pipeline_spec = job_spec.get("pipelineSpec") or job_spec + + # Construct expected request + expected_gapic_pipeline_job = gca_pipeline_job.PipelineJob( + display_name=_TEST_PIPELINE_JOB_DISPLAY_NAME, + pipeline_spec={ + "components": {}, + "pipelineInfo": pipeline_spec["pipelineInfo"], + "root": pipeline_spec["root"], + "schemaVersion": "2.1.0", + }, + runtime_config=runtime_config, + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=_TEST_PARENT, + pipeline_job=expected_gapic_pipeline_job, + pipeline_job_id=_TEST_PIPELINE_JOB_ID, + timeout=None, + ) + + assert not mock_pipeline_service_get.called + + job.wait() + + mock_pipeline_service_get.assert_called_with( + name=_TEST_PIPELINE_JOB_NAME, retry=base._DEFAULT_RETRY + ) + + assert job._gca_resource == make_pipeline_job( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) + + @pytest.mark.parametrize( + "job_spec", + [_TEST_PIPELINE_SPEC_JSON, _TEST_PIPELINE_SPEC_YAML, _TEST_PIPELINE_JOB], + ) + def test_done_method_pipeline_service( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + job_spec, + mock_load_yaml_and_json, + ): + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_GCS_BUCKET_NAME, + location=_TEST_LOCATION, + credentials=_TEST_CREDENTIALS, + ) + + job = pipeline_jobs.PipelineJob( + display_name=_TEST_PIPELINE_JOB_DISPLAY_NAME, + template_path=_TEST_TEMPLATE_PATH, + job_id=_TEST_PIPELINE_JOB_ID, + parameter_values=_TEST_PIPELINE_PARAMETER_VALUES, + enable_caching=True, + ) + + job.submit(service_account=_TEST_SERVICE_ACCOUNT, network=_TEST_NETWORK) + + assert job.done() is False + + job.wait() + + assert job.done() is True + + @pytest.mark.parametrize( + "job_spec", + [ + _TEST_PIPELINE_SPEC_LEGACY_JSON, + _TEST_PIPELINE_SPEC_LEGACY_YAML, + _TEST_PIPELINE_JOB_LEGACY, + ], + ) + def test_submit_call_pipeline_service_pipeline_job_create_legacy( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + job_spec, + mock_load_yaml_and_json, + ): + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_GCS_BUCKET_NAME, + location=_TEST_LOCATION, + credentials=_TEST_CREDENTIALS, + ) + + job = pipeline_jobs.PipelineJob( + display_name=_TEST_PIPELINE_JOB_DISPLAY_NAME, + template_path=_TEST_TEMPLATE_PATH, + job_id=_TEST_PIPELINE_JOB_ID, + parameter_values=_TEST_PIPELINE_PARAMETER_VALUES_LEGACY, + enable_caching=True, + ) + + job.submit( + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, + create_request_timeout=None, + ) + + expected_runtime_config_dict = { + "parameters": {"string_param": {"stringValue": "hello"}}, + "gcsOutputDirectory": _TEST_GCS_BUCKET_NAME, + } + runtime_config = gca_pipeline_job.PipelineJob.RuntimeConfig()._pb + json_format.ParseDict(expected_runtime_config_dict, runtime_config) + + job_spec = yaml.safe_load(job_spec) + pipeline_spec = job_spec.get("pipelineSpec") or job_spec + + # Construct expected request + expected_gapic_pipeline_job = gca_pipeline_job.PipelineJob( + display_name=_TEST_PIPELINE_JOB_DISPLAY_NAME, + pipeline_spec={ + "components": {}, + "pipelineInfo": pipeline_spec["pipelineInfo"], + "root": pipeline_spec["root"], + "schemaVersion": "2.0.0", + }, + runtime_config=runtime_config, + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=_TEST_PARENT, + pipeline_job=expected_gapic_pipeline_job, + pipeline_job_id=_TEST_PIPELINE_JOB_ID, + timeout=None, + ) + + assert not mock_pipeline_service_get.called + + job.wait() + + mock_pipeline_service_get.assert_called_with( + name=_TEST_PIPELINE_JOB_NAME, retry=base._DEFAULT_RETRY + ) + + assert job._gca_resource == make_pipeline_job( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) + + @pytest.mark.usefixtures("mock_pipeline_service_get") + def test_get_pipeline_job(self, mock_pipeline_service_get): + aiplatform.init(project=_TEST_PROJECT) + job = pipeline_jobs.PipelineJob.get(resource_name=_TEST_PIPELINE_JOB_ID) + + mock_pipeline_service_get.assert_called_once_with( + name=_TEST_PIPELINE_JOB_NAME, retry=base._DEFAULT_RETRY + ) + assert isinstance(job, pipeline_jobs.PipelineJob) + + @pytest.mark.usefixtures( + "mock_pipeline_service_create", + "mock_pipeline_service_get", + ) + @pytest.mark.parametrize( + "job_spec", + [ + _TEST_PIPELINE_SPEC_JSON, + _TEST_PIPELINE_SPEC_YAML, + _TEST_PIPELINE_JOB, + _TEST_PIPELINE_SPEC_LEGACY_JSON, + _TEST_PIPELINE_SPEC_LEGACY_YAML, + _TEST_PIPELINE_JOB_LEGACY, + ], + ) + def test_cancel_pipeline_job( + self, mock_pipeline_service_cancel, mock_load_yaml_and_json + ): + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_GCS_BUCKET_NAME, + credentials=_TEST_CREDENTIALS, + ) + + job = pipeline_jobs.PipelineJob( + display_name=_TEST_PIPELINE_JOB_DISPLAY_NAME, + template_path=_TEST_TEMPLATE_PATH, + job_id=_TEST_PIPELINE_JOB_ID, + ) + + job.run() + job.cancel() + + mock_pipeline_service_cancel.assert_called_once_with( + name=_TEST_PIPELINE_JOB_NAME + ) + + @pytest.mark.usefixtures( + "mock_pipeline_service_create", + "mock_pipeline_service_get", + ) + @pytest.mark.parametrize( + "job_spec", + [ + _TEST_PIPELINE_SPEC_JSON, + _TEST_PIPELINE_SPEC_YAML, + _TEST_PIPELINE_JOB, + _TEST_PIPELINE_SPEC_LEGACY_JSON, + _TEST_PIPELINE_SPEC_LEGACY_YAML, + _TEST_PIPELINE_JOB_LEGACY, + ], + ) + def test_list_pipeline_job( + self, mock_pipeline_service_list, mock_load_yaml_and_json + ): + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_GCS_BUCKET_NAME, + credentials=_TEST_CREDENTIALS, + ) + + job = pipeline_jobs.PipelineJob( + display_name=_TEST_PIPELINE_JOB_DISPLAY_NAME, + template_path=_TEST_TEMPLATE_PATH, + job_id=_TEST_PIPELINE_JOB_ID, + ) + + job.run() + job.list() + + mock_pipeline_service_list.assert_called_once_with( + request={"parent": _TEST_PARENT, "filter": None} + ) + + @pytest.mark.usefixtures( + "mock_pipeline_service_create", + "mock_pipeline_service_get", + ) + @pytest.mark.parametrize( + "job_spec", + [ + _TEST_PIPELINE_SPEC_JSON, + _TEST_PIPELINE_SPEC_YAML, + _TEST_PIPELINE_JOB, + _TEST_PIPELINE_SPEC_LEGACY_JSON, + _TEST_PIPELINE_SPEC_LEGACY_YAML, + _TEST_PIPELINE_JOB_LEGACY, + ], + ) + def test_cancel_pipeline_job_without_running( + self, + mock_pipeline_service_cancel, + mock_load_yaml_and_json, + ): + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_GCS_BUCKET_NAME, + credentials=_TEST_CREDENTIALS, + ) + + job = pipeline_jobs.PipelineJob( + display_name=_TEST_PIPELINE_JOB_DISPLAY_NAME, + template_path=_TEST_TEMPLATE_PATH, + job_id=_TEST_PIPELINE_JOB_ID, + ) + + with pytest.raises(RuntimeError) as e: + job.cancel() + + assert e.match(regexp=r"PipelineJob resource has not been created") + + @pytest.mark.usefixtures( + "mock_pipeline_service_create", + "mock_pipeline_service_get_with_fail", + ) + @pytest.mark.parametrize( + "job_spec", + [_TEST_PIPELINE_SPEC_JSON, _TEST_PIPELINE_SPEC_YAML, _TEST_PIPELINE_JOB], + ) + @pytest.mark.parametrize("sync", [True, False]) + def test_pipeline_failure_raises(self, mock_load_yaml_and_json, sync): + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_GCS_BUCKET_NAME, + location=_TEST_LOCATION, + credentials=_TEST_CREDENTIALS, + ) + + job = pipeline_jobs.PipelineJob( + display_name=_TEST_PIPELINE_JOB_DISPLAY_NAME, + template_path=_TEST_TEMPLATE_PATH, + job_id=_TEST_PIPELINE_JOB_ID, + parameter_values=_TEST_PIPELINE_PARAMETER_VALUES, + enable_caching=True, + ) + + with pytest.raises(RuntimeError): + job.run( + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, + sync=sync, + ) + + if not sync: + job.wait() + + @pytest.mark.parametrize( + "job_spec", + [_TEST_PIPELINE_SPEC_JSON, _TEST_PIPELINE_SPEC_YAML, _TEST_PIPELINE_JOB], + ) + def test_clone_pipeline_job( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + job_spec, + mock_load_yaml_and_json, + ): + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_GCS_BUCKET_NAME, + location=_TEST_LOCATION, + credentials=_TEST_CREDENTIALS, + ) + + job = pipeline_jobs.PipelineJob( + display_name=_TEST_PIPELINE_JOB_DISPLAY_NAME, + template_path=_TEST_TEMPLATE_PATH, + job_id=_TEST_PIPELINE_JOB_ID, + parameter_values=_TEST_PIPELINE_PARAMETER_VALUES, + enable_caching=True, + ) + + cloned = job.clone(job_id=f"cloned-{_TEST_PIPELINE_JOB_ID}") + + cloned.submit( + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, + create_request_timeout=None, + ) + + expected_runtime_config_dict = { + "gcsOutputDirectory": _TEST_GCS_BUCKET_NAME, + "parameterValues": _TEST_PIPELINE_PARAMETER_VALUES, + } + runtime_config = gca_pipeline_job.PipelineJob.RuntimeConfig()._pb + json_format.ParseDict(expected_runtime_config_dict, runtime_config) + + job_spec = yaml.safe_load(job_spec) + pipeline_spec = job_spec.get("pipelineSpec") or job_spec + + # Construct expected request + expected_gapic_pipeline_job = gca_pipeline_job.PipelineJob( + display_name=_TEST_PIPELINE_JOB_DISPLAY_NAME, + pipeline_spec={ + "components": {}, + "pipelineInfo": pipeline_spec["pipelineInfo"], + "root": pipeline_spec["root"], + "schemaVersion": "2.1.0", + }, + runtime_config=runtime_config, + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=_TEST_PARENT, + pipeline_job=expected_gapic_pipeline_job, + pipeline_job_id=f"cloned-{_TEST_PIPELINE_JOB_ID}", + timeout=None, + ) + + assert not mock_pipeline_service_get.called + + cloned.wait() + + mock_pipeline_service_get.assert_called_with( + name=_TEST_PIPELINE_JOB_NAME, retry=base._DEFAULT_RETRY + ) + + assert cloned._gca_resource == make_pipeline_job( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) + + @pytest.mark.parametrize( + "job_spec", + [_TEST_PIPELINE_SPEC_JSON, _TEST_PIPELINE_SPEC_YAML, _TEST_PIPELINE_JOB], + ) + def test_clone_pipeline_job_with_all_args( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + job_spec, + mock_load_yaml_and_json, + ): + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_GCS_BUCKET_NAME, + location=_TEST_LOCATION, + credentials=_TEST_CREDENTIALS, + ) + + job = pipeline_jobs.PipelineJob( + display_name=_TEST_PIPELINE_JOB_DISPLAY_NAME, + template_path=_TEST_TEMPLATE_PATH, + job_id=_TEST_PIPELINE_JOB_ID, + parameter_values=_TEST_PIPELINE_PARAMETER_VALUES, + enable_caching=True, + ) + + cloned = job.clone( + display_name=f"cloned-{_TEST_PIPELINE_JOB_DISPLAY_NAME}", + job_id=f"cloned-{_TEST_PIPELINE_JOB_ID}", + pipeline_root=f"cloned-{_TEST_GCS_BUCKET_NAME}", + parameter_values=_TEST_PIPELINE_PARAMETER_VALUES, + enable_caching=True, + credentials=_TEST_CREDENTIALS, + project=_TEST_PROJECT, + location=_TEST_LOCATION, + ) + + cloned.submit( + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, + create_request_timeout=None, + ) + + expected_runtime_config_dict = { + "gcsOutputDirectory": f"cloned-{_TEST_GCS_BUCKET_NAME}", + "parameterValues": _TEST_PIPELINE_PARAMETER_VALUES, + } + runtime_config = gca_pipeline_job.PipelineJob.RuntimeConfig()._pb + json_format.ParseDict(expected_runtime_config_dict, runtime_config) + + job_spec = yaml.safe_load(job_spec) + pipeline_spec = job_spec.get("pipelineSpec") or job_spec + + # Construct expected request + expected_gapic_pipeline_job = gca_pipeline_job.PipelineJob( + display_name=f"cloned-{_TEST_PIPELINE_JOB_DISPLAY_NAME}", + pipeline_spec={ + "components": {}, + "pipelineInfo": pipeline_spec["pipelineInfo"], + "root": pipeline_spec["root"], + "schemaVersion": "2.1.0", + }, + runtime_config=runtime_config, + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=_TEST_PARENT, + pipeline_job=expected_gapic_pipeline_job, + pipeline_job_id=f"cloned-{_TEST_PIPELINE_JOB_ID}", + timeout=None, + ) + + assert not mock_pipeline_service_get.called + + cloned.wait() + + mock_pipeline_service_get.assert_called_with( + name=_TEST_PIPELINE_JOB_NAME, retry=base._DEFAULT_RETRY + ) + + assert cloned._gca_resource == make_pipeline_job( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) diff --git a/tests/unit/aiplatform/test_tensorboard.py b/tests/unit/aiplatform/test_tensorboard.py new file mode 100644 index 0000000000..b73b805202 --- /dev/null +++ b/tests/unit/aiplatform/test_tensorboard.py @@ -0,0 +1,1068 @@ +# -*- coding: utf-8 -*- + +# Copyright 2022 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. +# + +import pytest + +from unittest import mock +from unittest.mock import patch +from importlib import reload + +from google.api_core import operation + +from google.cloud import aiplatform +from google.cloud.aiplatform import base +from google.cloud.aiplatform import initializer +from google.cloud.aiplatform import tensorboard +from google.cloud.aiplatform import utils + +from google.cloud.aiplatform.compat.services import ( + tensorboard_service_client, +) + +from google.cloud.aiplatform.compat.types import ( + encryption_spec as gca_encryption_spec, + tensorboard as gca_tensorboard, + tensorboard_data as gca_tensorboard_data, + tensorboard_experiment as gca_tensorboard_experiment, + tensorboard_run as gca_tensorboard_run, + tensorboard_service as gca_tensorboard_service, + tensorboard_time_series as gca_tensorboard_time_series, +) + +from google.protobuf import field_mask_pb2 + +# project +_TEST_PROJECT = "test-project" +_TEST_LOCATION = "us-central1" +_TEST_PARENT = f"projects/{_TEST_PROJECT}/locations/{_TEST_LOCATION}" +_TEST_ALT_PROJECT = "test-project_alt" + +_TEST_ALT_LOCATION = "europe-west4" +_TEST_INVALID_LOCATION = "us-central2" + +# tensorboard +_TEST_ID = "1028944691210842416" +_TEST_DISPLAY_NAME = "my_tensorboard_1234" +_TEST_DISPLAY_NAME_UPDATE = "my_tensorboard_1234_update" + +_TEST_NAME = ( + f"projects/{_TEST_PROJECT}/locations/{_TEST_LOCATION}/tensorboards/{_TEST_ID}" +) +_TEST_ALT_NAME = ( + f"projects/{_TEST_PROJECT}/locations/{_TEST_ALT_LOCATION}/tensorboards/{_TEST_ID}" +) +_TEST_INVALID_NAME = f"prj/{_TEST_PROJECT}/locations/{_TEST_LOCATION}/{_TEST_ID}" + +_TEST_TENSORBOARD_EXPERIMENT_ID = "test-experiment" +_TEST_TENSORBOARD_EXPERIMENT_NAME = ( + f"{_TEST_NAME}/experiments/{_TEST_TENSORBOARD_EXPERIMENT_ID}" +) + +_TEST_TENSORBOARD_RUN_ID = "test-run" +_TEST_TENSORBOARD_RUN_NAME = ( + f"{_TEST_TENSORBOARD_EXPERIMENT_NAME}/runs/{_TEST_TENSORBOARD_RUN_ID}" +) + +_TEST_TENSORBOARD_TIME_SERIES_ID = "test-time-series" +_TEST_TENSORBOARD_TIME_SERIES_NAME = ( + f"{_TEST_TENSORBOARD_RUN_NAME}/timeSeries/{_TEST_TENSORBOARD_TIME_SERIES_ID}" +) + +# request_metadata +_TEST_REQUEST_METADATA = () + +# CMEK encryption +_TEST_ENCRYPTION_KEY_NAME = "key_1234" +_TEST_ENCRYPTION_SPEC = gca_encryption_spec.EncryptionSpec( + kms_key_name=_TEST_ENCRYPTION_KEY_NAME +) + +_TEST_TIME_SERIES_DISPLAY_NAME = "accuracy" + + +@pytest.fixture +def get_tensorboard_mock(): + with patch.object( + tensorboard_service_client.TensorboardServiceClient, "get_tensorboard" + ) as get_tensorboard_mock: + get_tensorboard_mock.return_value = gca_tensorboard.Tensorboard( + name=_TEST_NAME, + display_name=_TEST_DISPLAY_NAME, + encryption_spec=_TEST_ENCRYPTION_SPEC, + ) + yield get_tensorboard_mock + + +@pytest.fixture +def create_tensorboard_mock(): + with patch.object( + tensorboard_service_client.TensorboardServiceClient, "create_tensorboard" + ) as create_tensorboard_mock: + create_tensorboard_lro_mock = mock.Mock(operation.Operation) + create_tensorboard_lro_mock.result.return_value = gca_tensorboard.Tensorboard( + name=_TEST_NAME, + display_name=_TEST_DISPLAY_NAME, + encryption_spec=_TEST_ENCRYPTION_SPEC, + ) + create_tensorboard_mock.return_value = create_tensorboard_lro_mock + yield create_tensorboard_mock + + +@pytest.fixture +def update_tensorboard_mock(): + with patch.object( + tensorboard_service_client.TensorboardServiceClient, "update_tensorboard" + ) as update_tensorboard_mock: + update_tensorboard_lro_mock = mock.Mock(operation.Operation) + update_tensorboard_lro_mock.result.return_value = gca_tensorboard.Tensorboard( + name=_TEST_NAME, + display_name=_TEST_DISPLAY_NAME_UPDATE, + encryption_spec=_TEST_ENCRYPTION_SPEC, + ) + update_tensorboard_mock.return_value = update_tensorboard_lro_mock + yield update_tensorboard_mock + + +@pytest.fixture +def delete_tensorboard_mock(): + with mock.patch.object( + tensorboard_service_client.TensorboardServiceClient, "delete_tensorboard" + ) as delete_tensorboard_mock: + delete_tensorboard_lro_mock = mock.Mock(operation.Operation) + delete_tensorboard_lro_mock.result.return_value = ( + gca_tensorboard_service.DeleteTensorboardRequest( + name=_TEST_NAME, + ) + ) + delete_tensorboard_mock.return_value = delete_tensorboard_lro_mock + yield delete_tensorboard_mock + + +_TEST_TENSORBOARD_EXPERIMENT = gca_tensorboard_experiment.TensorboardExperiment( + name=_TEST_TENSORBOARD_EXPERIMENT_NAME, + display_name=_TEST_DISPLAY_NAME, +) + + +@pytest.fixture +def get_tensorboard_experiment_mock(): + with patch.object( + tensorboard_service_client.TensorboardServiceClient, + "get_tensorboard_experiment", + ) as get_tensorboard_experiment__mock: + get_tensorboard_experiment__mock.return_value = _TEST_TENSORBOARD_EXPERIMENT + yield get_tensorboard_experiment__mock + + +@pytest.fixture +def create_tensorboard_experiment_mock(): + with patch.object( + tensorboard_service_client.TensorboardServiceClient, + "create_tensorboard_experiment", + ) as create_tensorboard_experiment_mock: + create_tensorboard_experiment_mock.return_value = _TEST_TENSORBOARD_EXPERIMENT + yield create_tensorboard_experiment_mock + + +@pytest.fixture +def delete_tensorboard_experiment_mock(): + with mock.patch.object( + tensorboard_service_client.TensorboardServiceClient, + "delete_tensorboard_experiment", + ) as delete_tensorboard_experiment_mock: + delete_tensorboard_lro_experiment_mock = mock.Mock(operation.Operation) + delete_tensorboard_lro_experiment_mock.result.return_value = ( + gca_tensorboard_service.DeleteTensorboardExperimentRequest( + name=_TEST_TENSORBOARD_EXPERIMENT_NAME, + ) + ) + delete_tensorboard_experiment_mock.return_value = ( + delete_tensorboard_lro_experiment_mock + ) + yield delete_tensorboard_experiment_mock + + +@pytest.fixture +def list_tensorboard_experiment_mock(): + with patch.object( + tensorboard_service_client.TensorboardServiceClient, + "list_tensorboard_experiments", + ) as list_tensorboard_experiment_mock: + list_tensorboard_experiment_mock.return_value = [_TEST_TENSORBOARD_EXPERIMENT] + yield list_tensorboard_experiment_mock + + +_TEST_TENSORBOARD_RUN = gca_tensorboard_run.TensorboardRun( + name=_TEST_TENSORBOARD_RUN_NAME, + display_name=_TEST_DISPLAY_NAME, +) + + +@pytest.fixture +def get_tensorboard_run_mock(): + with patch.object( + tensorboard_service_client.TensorboardServiceClient, + "get_tensorboard_run", + ) as get_tensorboard_run_mock: + get_tensorboard_run_mock.return_value = _TEST_TENSORBOARD_RUN + yield get_tensorboard_run_mock + + +@pytest.fixture +def create_tensorboard_run_mock(): + with patch.object( + tensorboard_service_client.TensorboardServiceClient, + "create_tensorboard_run", + ) as create_tensorboard_run_mock: + create_tensorboard_run_mock.return_value = _TEST_TENSORBOARD_RUN + yield create_tensorboard_run_mock + + +@pytest.fixture +def delete_tensorboard_run_mock(): + with mock.patch.object( + tensorboard_service_client.TensorboardServiceClient, + "delete_tensorboard_run", + ) as delete_tensorboard_run_mock: + delete_tensorboard_lro_run_mock = mock.Mock(operation.Operation) + delete_tensorboard_lro_run_mock.result.return_value = ( + gca_tensorboard_service.DeleteTensorboardRunRequest( + name=_TEST_TENSORBOARD_RUN_NAME, + ) + ) + delete_tensorboard_run_mock.return_value = delete_tensorboard_lro_run_mock + yield delete_tensorboard_run_mock + + +@pytest.fixture +def list_tensorboard_run_mock(): + with patch.object( + tensorboard_service_client.TensorboardServiceClient, + "list_tensorboard_runs", + ) as list_tensorboard_run_mock: + list_tensorboard_run_mock.return_value = [ + gca_tensorboard_run.TensorboardRun( + name=_TEST_TENSORBOARD_RUN_NAME, + display_name=_TEST_DISPLAY_NAME, + ) + ] + yield list_tensorboard_run_mock + + +@pytest.fixture +def write_tensorboard_run_data_mock(): + with patch.object( + tensorboard_service_client.TensorboardServiceClient, + "write_tensorboard_run_data", + ) as write_tensorboard_run_data_mock: + yield write_tensorboard_run_data_mock + + +_TEST_TENSORBOARD_TIME_SERIES = gca_tensorboard_time_series.TensorboardTimeSeries( + name=_TEST_TENSORBOARD_TIME_SERIES_NAME, + display_name=_TEST_TIME_SERIES_DISPLAY_NAME, + value_type=gca_tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR, +) + + +@pytest.fixture +def get_tensorboard_time_series_mock(): + with patch.object( + tensorboard_service_client.TensorboardServiceClient, + "get_tensorboard_time_series", + ) as get_tensorboard_time_series_mock: + get_tensorboard_time_series_mock.return_value = _TEST_TENSORBOARD_TIME_SERIES + yield get_tensorboard_time_series_mock + + +@pytest.fixture +def create_tensorboard_time_series_mock(): + with patch.object( + tensorboard_service_client.TensorboardServiceClient, + "create_tensorboard_time_series", + ) as create_tensorboard_time_series_mock: + create_tensorboard_time_series_mock.return_value = _TEST_TENSORBOARD_TIME_SERIES + yield create_tensorboard_time_series_mock + + +@pytest.fixture +def delete_tensorboard_time_series_mock(): + with mock.patch.object( + tensorboard_service_client.TensorboardServiceClient, + "delete_tensorboard_time_series", + ) as delete_tensorboard_time_series_mock: + delete_tensorboard_lro_time_series_mock = mock.Mock(operation.Operation) + delete_tensorboard_lro_time_series_mock.result.return_value = ( + gca_tensorboard_service.DeleteTensorboardTimeSeriesRequest( + name=_TEST_TENSORBOARD_TIME_SERIES_NAME, + ) + ) + delete_tensorboard_time_series_mock.return_value = ( + delete_tensorboard_lro_time_series_mock + ) + yield delete_tensorboard_time_series_mock + + +@pytest.fixture +def list_tensorboard_time_series_mock(): + with patch.object( + tensorboard_service_client.TensorboardServiceClient, + "list_tensorboard_time_series", + ) as list_tensorboard_time_series_mock: + list_tensorboard_time_series_mock.return_value = [_TEST_TENSORBOARD_TIME_SERIES] + yield list_tensorboard_time_series_mock + + +_TEST_TENSORBOARD_TIME_SERIES_DATA = gca_tensorboard_data.TimeSeriesData( + tensorboard_time_series_id=_TEST_TENSORBOARD_TIME_SERIES_ID, + value_type=gca_tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR, + values=[ + gca_tensorboard_data.TimeSeriesDataPoint( + scalar=gca_tensorboard_data.Scalar(value=1.0), + step=1, + wall_time=utils.get_timestamp_proto(), + ) + ], +) + + +@pytest.fixture +def batch_read_tensorboard_time_series_mock(): + with patch.object( + tensorboard_service_client.TensorboardServiceClient, + "batch_read_tensorboard_time_series_data", + ) as batch_read_tensorboard_time_series_data_mock: + batch_read_tensorboard_time_series_data_mock.return_value = ( + gca_tensorboard_service.BatchReadTensorboardTimeSeriesDataResponse( + time_series_data=[_TEST_TENSORBOARD_TIME_SERIES_DATA] + ) + ) + yield batch_read_tensorboard_time_series_data_mock + + +@pytest.mark.usefixtures("google_auth_mock") +class TestTensorboard: + def setup_method(self): + reload(initializer) + reload(aiplatform) + + def teardown_method(self): + initializer.global_pool.shutdown(wait=True) + + def test_init_tensorboard(self, get_tensorboard_mock): + aiplatform.init(project=_TEST_PROJECT) + tensorboard.Tensorboard(tensorboard_name=_TEST_NAME) + get_tensorboard_mock.assert_called_once_with( + name=_TEST_NAME, retry=base._DEFAULT_RETRY + ) + + def test_init_tensorboard_with_id_only_with_project_and_location( + self, get_tensorboard_mock + ): + aiplatform.init(project=_TEST_PROJECT) + tensorboard.Tensorboard( + tensorboard_name=_TEST_ID, project=_TEST_PROJECT, location=_TEST_LOCATION + ) + get_tensorboard_mock.assert_called_once_with( + name=_TEST_NAME, retry=base._DEFAULT_RETRY + ) + + def test_init_tensorboard_with_project_and_location(self, get_tensorboard_mock): + aiplatform.init(project=_TEST_PROJECT) + tensorboard.Tensorboard( + tensorboard_name=_TEST_NAME, project=_TEST_PROJECT, location=_TEST_LOCATION + ) + get_tensorboard_mock.assert_called_once_with( + name=_TEST_NAME, retry=base._DEFAULT_RETRY + ) + + def test_init_tensorboard_with_alt_project_and_location(self, get_tensorboard_mock): + aiplatform.init(project=_TEST_PROJECT) + tensorboard.Tensorboard( + tensorboard_name=_TEST_NAME, + project=_TEST_ALT_PROJECT, + location=_TEST_LOCATION, + ) + get_tensorboard_mock.assert_called_once_with( + name=_TEST_NAME, retry=base._DEFAULT_RETRY + ) + + def test_init_tensorboard_with_alt_location(self, get_tensorboard_mock): + aiplatform.init(project=_TEST_PROJECT, location=_TEST_ALT_LOCATION) + tensorboard.Tensorboard( + tensorboard_name=_TEST_NAME, + ) + get_tensorboard_mock.assert_called_once_with( + name=_TEST_NAME, retry=base._DEFAULT_RETRY + ) + + def test_init_tensorboard_with_project_and_alt_location(self): + aiplatform.init(project=_TEST_PROJECT) + with pytest.raises(RuntimeError): + tensorboard.Tensorboard( + tensorboard_name=_TEST_NAME, + project=_TEST_PROJECT, + location=_TEST_ALT_LOCATION, + ) + + def test_init_tensorboard_with_location_override(self, get_tensorboard_mock): + aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) + tensorboard.Tensorboard(tensorboard_name=_TEST_ID, location=_TEST_ALT_LOCATION) + get_tensorboard_mock.assert_called_once_with( + name=_TEST_ALT_NAME, retry=base._DEFAULT_RETRY + ) + + @pytest.mark.usefixtures("get_tensorboard_mock") + def test_init_tensorboard_with_invalid_name(self): + with pytest.raises(ValueError): + aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) + tensorboard.Tensorboard(tensorboard_name=_TEST_INVALID_NAME) + + @pytest.mark.usefixtures("get_tensorboard_mock") + def test_create_tensorboard_with_default_encryption_key( + self, create_tensorboard_mock + ): + aiplatform.init( + project=_TEST_PROJECT, + encryption_spec_key_name=_TEST_ENCRYPTION_KEY_NAME, + ) + + tensorboard.Tensorboard.create( + display_name=_TEST_DISPLAY_NAME, + create_request_timeout=None, + ) + + expected_tensorboard = gca_tensorboard.Tensorboard( + display_name=_TEST_DISPLAY_NAME, + encryption_spec=_TEST_ENCRYPTION_SPEC, + ) + + create_tensorboard_mock.assert_called_once_with( + parent=_TEST_PARENT, + tensorboard=expected_tensorboard, + metadata=_TEST_REQUEST_METADATA, + timeout=None, + ) + + @pytest.mark.usefixtures("get_tensorboard_mock") + def test_create_tensorboard(self, create_tensorboard_mock): + + aiplatform.init( + project=_TEST_PROJECT, + ) + + tensorboard.Tensorboard.create( + display_name=_TEST_DISPLAY_NAME, + encryption_spec_key_name=_TEST_ENCRYPTION_KEY_NAME, + create_request_timeout=None, + ) + + expected_tensorboard = gca_tensorboard.Tensorboard( + display_name=_TEST_DISPLAY_NAME, + encryption_spec=_TEST_ENCRYPTION_SPEC, + ) + + create_tensorboard_mock.assert_called_once_with( + parent=_TEST_PARENT, + tensorboard=expected_tensorboard, + metadata=_TEST_REQUEST_METADATA, + timeout=None, + ) + + @pytest.mark.usefixtures("get_tensorboard_mock") + def test_create_tensorboard_with_timeout(self, create_tensorboard_mock): + + aiplatform.init( + project=_TEST_PROJECT, + ) + + tensorboard.Tensorboard.create( + display_name=_TEST_DISPLAY_NAME, + encryption_spec_key_name=_TEST_ENCRYPTION_KEY_NAME, + create_request_timeout=180.0, + ) + + expected_tensorboard = gca_tensorboard.Tensorboard( + display_name=_TEST_DISPLAY_NAME, + encryption_spec=_TEST_ENCRYPTION_SPEC, + ) + + create_tensorboard_mock.assert_called_once_with( + parent=_TEST_PARENT, + tensorboard=expected_tensorboard, + metadata=_TEST_REQUEST_METADATA, + timeout=180.0, + ) + + @pytest.mark.usefixtures("get_tensorboard_mock") + def test_create_tensorboard_with_timeout_not_explicitly_set( + self, create_tensorboard_mock + ): + + aiplatform.init( + project=_TEST_PROJECT, + ) + + tensorboard.Tensorboard.create( + display_name=_TEST_DISPLAY_NAME, + encryption_spec_key_name=_TEST_ENCRYPTION_KEY_NAME, + ) + + expected_tensorboard = gca_tensorboard.Tensorboard( + display_name=_TEST_DISPLAY_NAME, + encryption_spec=_TEST_ENCRYPTION_SPEC, + ) + + create_tensorboard_mock.assert_called_once_with( + parent=_TEST_PARENT, + tensorboard=expected_tensorboard, + metadata=_TEST_REQUEST_METADATA, + timeout=None, + ) + + @pytest.mark.usefixtures("get_tensorboard_mock") + def test_delete_tensorboard(self, delete_tensorboard_mock): + aiplatform.init(project=_TEST_PROJECT) + + my_tensorboard = tensorboard.Tensorboard(tensorboard_name=_TEST_NAME) + + my_tensorboard.delete() + + delete_tensorboard_mock.assert_called_once_with( + name=my_tensorboard.resource_name + ) + + @pytest.mark.usefixtures("get_tensorboard_mock") + def test_update_tensorboard_display_name(self, update_tensorboard_mock): + aiplatform.init(project=_TEST_PROJECT) + + my_tensorboard = tensorboard.Tensorboard(tensorboard_name=_TEST_NAME) + my_tensorboard.update(display_name=_TEST_DISPLAY_NAME_UPDATE) + + expected_tensorboard = gca_tensorboard.Tensorboard( + name=_TEST_NAME, + display_name=_TEST_DISPLAY_NAME_UPDATE, + ) + update_tensorboard_mock.assert_called_once_with( + update_mask=field_mask_pb2.FieldMask(paths=["display_name"]), + tensorboard=expected_tensorboard, + metadata=_TEST_REQUEST_METADATA, + ) + + @pytest.mark.usefixtures("get_tensorboard_mock") + def test_update_tensorboard_encryption_spec(self, update_tensorboard_mock): + aiplatform.init(project=_TEST_PROJECT) + + my_tensorboard = tensorboard.Tensorboard(tensorboard_name=_TEST_NAME) + my_tensorboard.update(encryption_spec_key_name=_TEST_ENCRYPTION_KEY_NAME) + + expected_tensorboard = gca_tensorboard.Tensorboard( + name=_TEST_NAME, + encryption_spec=_TEST_ENCRYPTION_SPEC, + ) + update_tensorboard_mock.assert_called_once_with( + update_mask=field_mask_pb2.FieldMask(paths=["encryption_spec"]), + tensorboard=expected_tensorboard, + metadata=_TEST_REQUEST_METADATA, + ) + + +@pytest.mark.usefixtures("google_auth_mock") +class TestTensorboardExperiment: + def setup_method(self): + reload(initializer) + reload(aiplatform) + + def teardown_method(self): + initializer.global_pool.shutdown(wait=True) + + def test_init_tensorboard_experiment(self, get_tensorboard_experiment_mock): + aiplatform.init(project=_TEST_PROJECT) + tensorboard.TensorboardExperiment( + tensorboard_experiment_name=_TEST_TENSORBOARD_EXPERIMENT_NAME + ) + get_tensorboard_experiment_mock.assert_called_once_with( + name=_TEST_TENSORBOARD_EXPERIMENT_NAME, retry=base._DEFAULT_RETRY + ) + + def test_init_tensorboard_experiment_with_tensorboard( + self, get_tensorboard_experiment_mock + ): + aiplatform.init(project=_TEST_PROJECT) + tensorboard.TensorboardExperiment( + tensorboard_experiment_name=_TEST_TENSORBOARD_EXPERIMENT_ID, + tensorboard_id=_TEST_ID, + ) + get_tensorboard_experiment_mock.assert_called_once_with( + name=_TEST_TENSORBOARD_EXPERIMENT_NAME, retry=base._DEFAULT_RETRY + ) + + def test_init_tensorboard_experiment_with_id_only_with_project_and_location( + self, get_tensorboard_experiment_mock + ): + aiplatform.init(project=_TEST_PROJECT) + tensorboard.TensorboardExperiment( + tensorboard_experiment_name=_TEST_TENSORBOARD_EXPERIMENT_ID, + tensorboard_id=_TEST_ID, + project=_TEST_PROJECT, + location=_TEST_LOCATION, + ) + get_tensorboard_experiment_mock.assert_called_once_with( + name=_TEST_TENSORBOARD_EXPERIMENT_NAME, retry=base._DEFAULT_RETRY + ) + + def test_create_tensorboard_experiment( + self, create_tensorboard_experiment_mock, get_tensorboard_experiment_mock + ): + + aiplatform.init( + project=_TEST_PROJECT, + ) + + tensorboard.TensorboardExperiment.create( + tensorboard_experiment_id=_TEST_TENSORBOARD_EXPERIMENT_ID, + tensorboard_name=_TEST_NAME, + display_name=_TEST_DISPLAY_NAME, + create_request_timeout=None, + ) + + expected_tensorboard_experiment = ( + gca_tensorboard_experiment.TensorboardExperiment( + display_name=_TEST_DISPLAY_NAME, + ) + ) + + create_tensorboard_experiment_mock.assert_called_once_with( + parent=_TEST_NAME, + tensorboard_experiment=expected_tensorboard_experiment, + tensorboard_experiment_id=_TEST_TENSORBOARD_EXPERIMENT_ID, + metadata=_TEST_REQUEST_METADATA, + timeout=None, + ) + + get_tensorboard_experiment_mock.assert_called_once_with( + name=_TEST_TENSORBOARD_EXPERIMENT_NAME, retry=base._DEFAULT_RETRY + ) + + def test_create_tensorboard_experiment_with_timeout( + self, create_tensorboard_experiment_mock, get_tensorboard_experiment_mock + ): + + aiplatform.init( + project=_TEST_PROJECT, + ) + + tensorboard.TensorboardExperiment.create( + tensorboard_experiment_id=_TEST_TENSORBOARD_EXPERIMENT_ID, + tensorboard_name=_TEST_NAME, + display_name=_TEST_DISPLAY_NAME, + create_request_timeout=180.0, + ) + + expected_tensorboard_experiment = ( + gca_tensorboard_experiment.TensorboardExperiment( + display_name=_TEST_DISPLAY_NAME, + ) + ) + + create_tensorboard_experiment_mock.assert_called_once_with( + parent=_TEST_NAME, + tensorboard_experiment=expected_tensorboard_experiment, + tensorboard_experiment_id=_TEST_TENSORBOARD_EXPERIMENT_ID, + metadata=_TEST_REQUEST_METADATA, + timeout=180.0, + ) + + def test_create_tensorboard_experiment_with_timeout_not_explicitly_set( + self, create_tensorboard_experiment_mock, get_tensorboard_experiment_mock + ): + + aiplatform.init( + project=_TEST_PROJECT, + ) + + tensorboard.TensorboardExperiment.create( + tensorboard_experiment_id=_TEST_TENSORBOARD_EXPERIMENT_ID, + tensorboard_name=_TEST_NAME, + display_name=_TEST_DISPLAY_NAME, + ) + + expected_tensorboard_experiment = ( + gca_tensorboard_experiment.TensorboardExperiment( + display_name=_TEST_DISPLAY_NAME, + ) + ) + + create_tensorboard_experiment_mock.assert_called_once_with( + parent=_TEST_NAME, + tensorboard_experiment=expected_tensorboard_experiment, + tensorboard_experiment_id=_TEST_TENSORBOARD_EXPERIMENT_ID, + metadata=_TEST_REQUEST_METADATA, + timeout=None, + ) + + @pytest.mark.usefixtures("get_tensorboard_experiment_mock") + def test_delete_tensorboard_experiement(self, delete_tensorboard_experiment_mock): + aiplatform.init(project=_TEST_PROJECT) + + my_tensorboard_experiment = tensorboard.TensorboardExperiment( + tensorboard_experiment_name=_TEST_TENSORBOARD_EXPERIMENT_NAME + ) + + my_tensorboard_experiment.delete() + + delete_tensorboard_experiment_mock.assert_called_once_with( + name=my_tensorboard_experiment.resource_name + ) + + def test_list_tensorboard_experiments(self, list_tensorboard_experiment_mock): + aiplatform.init(project=_TEST_PROJECT) + + tensorboard.TensorboardExperiment.list(tensorboard_name=_TEST_NAME) + + list_tensorboard_experiment_mock.assert_called_once_with( + request={"parent": _TEST_NAME, "filter": None} + ) + + +@pytest.mark.usefixtures("google_auth_mock") +class TestTensorboardRun: + def setup_method(self): + reload(initializer) + reload(aiplatform) + + def teardown_method(self): + initializer.global_pool.shutdown(wait=True) + + @pytest.mark.usefixtures("list_tensorboard_time_series_mock") + def test_init_tensorboard_run(self, get_tensorboard_run_mock): + aiplatform.init(project=_TEST_PROJECT) + tensorboard.TensorboardRun(tensorboard_run_name=_TEST_TENSORBOARD_RUN_NAME) + get_tensorboard_run_mock.assert_called_once_with( + name=_TEST_TENSORBOARD_RUN_NAME, retry=base._DEFAULT_RETRY + ) + + @pytest.mark.usefixtures("list_tensorboard_time_series_mock") + def test_init_tensorboard_run_with_tensorboard_and_experiment( + self, get_tensorboard_run_mock + ): + aiplatform.init(project=_TEST_PROJECT) + tensorboard.TensorboardRun( + tensorboard_run_name=_TEST_TENSORBOARD_RUN_ID, + tensorboard_experiment_id=_TEST_TENSORBOARD_EXPERIMENT_ID, + tensorboard_id=_TEST_ID, + ) + get_tensorboard_run_mock.assert_called_once_with( + name=_TEST_TENSORBOARD_RUN_NAME, retry=base._DEFAULT_RETRY + ) + + def test_init_tensorboard_run_with_id_only_with_project_and_location( + self, get_tensorboard_run_mock, list_tensorboard_time_series_mock + ): + aiplatform.init(project=_TEST_PROJECT) + tensorboard.TensorboardRun( + tensorboard_run_name=_TEST_TENSORBOARD_RUN_ID, + tensorboard_experiment_id=_TEST_TENSORBOARD_EXPERIMENT_ID, + tensorboard_id=_TEST_ID, + project=_TEST_PROJECT, + location=_TEST_LOCATION, + ) + get_tensorboard_run_mock.assert_called_once_with( + name=_TEST_TENSORBOARD_RUN_NAME, retry=base._DEFAULT_RETRY + ) + list_tensorboard_time_series_mock.assert_called_once_with( + request={"parent": _TEST_TENSORBOARD_RUN_NAME, "filter": None} + ) + + @pytest.mark.usefixtures("list_tensorboard_time_series_mock") + def test_create_tensorboard_run( + self, + create_tensorboard_run_mock, + get_tensorboard_run_mock, + ): + + aiplatform.init( + project=_TEST_PROJECT, + ) + + tensorboard.TensorboardRun.create( + tensorboard_run_id=_TEST_TENSORBOARD_RUN_ID, + tensorboard_experiment_name=_TEST_TENSORBOARD_EXPERIMENT_NAME, + create_request_timeout=None, + ) + + expected_tensorboard_run = gca_tensorboard_run.TensorboardRun( + display_name=_TEST_TENSORBOARD_RUN_ID, + ) + + create_tensorboard_run_mock.assert_called_once_with( + parent=_TEST_TENSORBOARD_EXPERIMENT_NAME, + tensorboard_run=expected_tensorboard_run, + tensorboard_run_id=_TEST_TENSORBOARD_RUN_ID, + metadata=_TEST_REQUEST_METADATA, + timeout=None, + ) + + get_tensorboard_run_mock.assert_called_once_with( + name=_TEST_TENSORBOARD_RUN_NAME, retry=base._DEFAULT_RETRY + ) + + @pytest.mark.usefixtures("list_tensorboard_time_series_mock") + def test_create_tensorboard_run_with_timeout( + self, create_tensorboard_run_mock, get_tensorboard_run_mock + ): + + aiplatform.init( + project=_TEST_PROJECT, + ) + + tensorboard.TensorboardRun.create( + tensorboard_run_id=_TEST_TENSORBOARD_RUN_ID, + tensorboard_experiment_name=_TEST_TENSORBOARD_EXPERIMENT_NAME, + create_request_timeout=180.0, + ) + + expected_tensorboard_run = gca_tensorboard_run.TensorboardRun( + display_name=_TEST_TENSORBOARD_RUN_ID, + ) + + create_tensorboard_run_mock.assert_called_once_with( + parent=_TEST_TENSORBOARD_EXPERIMENT_NAME, + tensorboard_run=expected_tensorboard_run, + tensorboard_run_id=_TEST_TENSORBOARD_RUN_ID, + metadata=_TEST_REQUEST_METADATA, + timeout=180.0, + ) + + @pytest.mark.usefixtures("list_tensorboard_time_series_mock") + def test_create_tensorboard_run_with_timeout_not_explicitly_set( + self, create_tensorboard_run_mock, get_tensorboard_run_mock + ): + + aiplatform.init( + project=_TEST_PROJECT, + ) + + tensorboard.TensorboardRun.create( + tensorboard_run_id=_TEST_TENSORBOARD_RUN_ID, + tensorboard_experiment_name=_TEST_TENSORBOARD_EXPERIMENT_NAME, + ) + + expected_tensorboard_run = gca_tensorboard_run.TensorboardRun( + display_name=_TEST_TENSORBOARD_RUN_ID, + ) + + create_tensorboard_run_mock.assert_called_once_with( + parent=_TEST_TENSORBOARD_EXPERIMENT_NAME, + tensorboard_run=expected_tensorboard_run, + tensorboard_run_id=_TEST_TENSORBOARD_RUN_ID, + metadata=_TEST_REQUEST_METADATA, + timeout=None, + ) + + @pytest.mark.usefixtures( + "get_tensorboard_run_mock", "list_tensorboard_time_series_mock" + ) + def test_delete_tensorboard_run(self, delete_tensorboard_run_mock): + aiplatform.init(project=_TEST_PROJECT) + + my_tensorboard_run = tensorboard.TensorboardRun( + tensorboard_run_name=_TEST_TENSORBOARD_RUN_NAME + ) + + my_tensorboard_run.delete() + + delete_tensorboard_run_mock.assert_called_once_with( + name=my_tensorboard_run.resource_name + ) + + def test_list_tensorboard_runs( + self, list_tensorboard_run_mock, list_tensorboard_time_series_mock + ): + aiplatform.init(project=_TEST_PROJECT) + + tensorboard.TensorboardRun.list( + tensorboard_experiment_name=_TEST_TENSORBOARD_EXPERIMENT_NAME + ) + + list_tensorboard_run_mock.assert_called_once_with( + request={"parent": _TEST_TENSORBOARD_EXPERIMENT_NAME, "filter": None} + ) + + list_tensorboard_time_series_mock.assert_called_once_with( + request={"parent": _TEST_TENSORBOARD_RUN_NAME, "filter": None} + ) + + @pytest.mark.usefixtures( + "get_tensorboard_run_mock", "list_tensorboard_time_series_mock" + ) + def test_write_tensorboard_run_data(self, write_tensorboard_run_data_mock): + aiplatform.init(project=_TEST_PROJECT) + + tb_run = tensorboard.TensorboardRun( + tensorboard_run_name=_TEST_TENSORBOARD_RUN_NAME + ) + + timestamp = utils.get_timestamp_proto() + tb_run.write_tensorboard_scalar_data( + time_series_data={"accuracy": 0.9}, step=1, wall_time=timestamp + ) + + expected_time_series_data = [ + gca_tensorboard_data.TimeSeriesData( + tensorboard_time_series_id=_TEST_TENSORBOARD_TIME_SERIES_ID, + value_type=gca_tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR, + values=[ + gca_tensorboard_data.TimeSeriesDataPoint( + scalar=gca_tensorboard_data.Scalar(value=0.9), + wall_time=timestamp, + step=1, + ) + ], + ), + ] + + write_tensorboard_run_data_mock.assert_called_once_with( + tensorboard_run=_TEST_TENSORBOARD_RUN_NAME, + time_series_data=expected_time_series_data, + ) + + @pytest.mark.usefixtures( + "get_tensorboard_run_mock", "list_tensorboard_time_series_mock" + ) + def test_read_tensorboard_time_series( + self, batch_read_tensorboard_time_series_mock + ): + aiplatform.init(project=_TEST_PROJECT) + + tb_run = tensorboard.TensorboardRun( + tensorboard_run_name=_TEST_TENSORBOARD_RUN_NAME + ) + + ts_data = tb_run.read_time_series_data() + + true_ts_data = { + _TEST_TIME_SERIES_DISPLAY_NAME: _TEST_TENSORBOARD_TIME_SERIES_DATA + } + + batch_read_tensorboard_time_series_mock.assert_called_once_with( + request=gca_tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest( + tensorboard=_TEST_NAME, + time_series=[_TEST_TENSORBOARD_TIME_SERIES_NAME], + ) + ) + + assert ts_data == true_ts_data + + +@pytest.mark.usefixtures("google_auth_mock") +class TestTensorboardTimeSeries: + def setup_method(self): + reload(initializer) + reload(aiplatform) + + def teardown_method(self): + initializer.global_pool.shutdown(wait=True) + + def test_init_tensorboard_time_series(self, get_tensorboard_time_series_mock): + aiplatform.init(project=_TEST_PROJECT) + tensorboard.TensorboardTimeSeries( + tensorboard_time_series_name=_TEST_TENSORBOARD_TIME_SERIES_NAME + ) + get_tensorboard_time_series_mock.assert_called_once_with( + name=_TEST_TENSORBOARD_TIME_SERIES_NAME, retry=base._DEFAULT_RETRY + ) + + def test_init_tensorboard_time_series_with_tensorboard_and_experiment_and_run( + self, get_tensorboard_time_series_mock + ): + aiplatform.init(project=_TEST_PROJECT) + tensorboard.TensorboardTimeSeries( + tensorboard_time_series_name=_TEST_TENSORBOARD_TIME_SERIES_ID, + tensorboard_run_id=_TEST_TENSORBOARD_RUN_ID, + tensorboard_experiment_id=_TEST_TENSORBOARD_EXPERIMENT_ID, + tensorboard_id=_TEST_ID, + ) + get_tensorboard_time_series_mock.assert_called_once_with( + name=_TEST_TENSORBOARD_TIME_SERIES_NAME, retry=base._DEFAULT_RETRY + ) + + def test_init_tensorboard_time_series_with_id_only_with_project_and_location( + self, get_tensorboard_time_series_mock + ): + aiplatform.init(project=_TEST_PROJECT) + tensorboard.TensorboardTimeSeries( + tensorboard_time_series_name=_TEST_TENSORBOARD_TIME_SERIES_ID, + tensorboard_run_id=_TEST_TENSORBOARD_RUN_ID, + tensorboard_experiment_id=_TEST_TENSORBOARD_EXPERIMENT_ID, + tensorboard_id=_TEST_ID, + project=_TEST_PROJECT, + location=_TEST_LOCATION, + ) + get_tensorboard_time_series_mock.assert_called_once_with( + name=_TEST_TENSORBOARD_TIME_SERIES_NAME, retry=base._DEFAULT_RETRY + ) + + def test_create_tensorboard_time_series( + self, + create_tensorboard_time_series_mock, + ): + + aiplatform.init( + project=_TEST_PROJECT, + ) + + tensorboard.TensorboardTimeSeries.create( + display_name=_TEST_TIME_SERIES_DISPLAY_NAME, + tensorboard_run_name=_TEST_TENSORBOARD_RUN_NAME, + ) + + expected_tensorboard_time_series = gca_tensorboard_time_series.TensorboardTimeSeries( + display_name=_TEST_TIME_SERIES_DISPLAY_NAME, + value_type=gca_tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR, + plugin_name="scalars", + ) + + create_tensorboard_time_series_mock.assert_called_once_with( + parent=_TEST_TENSORBOARD_RUN_NAME, + tensorboard_time_series=expected_tensorboard_time_series, + ) + + @pytest.mark.usefixtures("get_tensorboard_time_series_mock") + def test_delete_tensorboard_time_series(self, delete_tensorboard_time_series_mock): + aiplatform.init(project=_TEST_PROJECT) + + my_tensorboard_time_series = tensorboard.TensorboardTimeSeries( + tensorboard_time_series_name=_TEST_TENSORBOARD_TIME_SERIES_NAME + ) + + my_tensorboard_time_series.delete() + + delete_tensorboard_time_series_mock.assert_called_once_with( + name=my_tensorboard_time_series.resource_name + ) + + def test_list_tensorboard_time_series(self, list_tensorboard_time_series_mock): + aiplatform.init(project=_TEST_PROJECT) + + tensorboard.TensorboardTimeSeries.list( + tensorboard_run_name=_TEST_TENSORBOARD_RUN_NAME + ) + + list_tensorboard_time_series_mock.assert_called_once_with( + request={"parent": _TEST_TENSORBOARD_RUN_NAME, "filter": None} + ) diff --git a/tests/unit/aiplatform/test_training_jobs.py b/tests/unit/aiplatform/test_training_jobs.py index 75478263e8..17d338887f 100644 --- a/tests/unit/aiplatform/test_training_jobs.py +++ b/tests/unit/aiplatform/test_training_jobs.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,8 +16,11 @@ # from distutils import core +import copy +import os import functools import importlib +import logging import pathlib import pytest import subprocess @@ -25,33 +28,37 @@ import sys import tarfile import tempfile +import uuid from unittest import mock from unittest.mock import patch +import test_training_jobs + from google.auth import credentials as auth_credentials -from google.cloud.aiplatform import utils -from google.cloud.aiplatform.utils import source_utils -from google.cloud.aiplatform.utils import worker_spec_utils from google.cloud import aiplatform - +from google.cloud.aiplatform import base from google.cloud.aiplatform import datasets from google.cloud.aiplatform import initializer from google.cloud.aiplatform import schema from google.cloud.aiplatform import training_jobs +from google.cloud.aiplatform import utils +from google.cloud.aiplatform.utils import source_utils +from google.cloud.aiplatform.utils import worker_spec_utils -from google.cloud.aiplatform_v1.services.model_service import ( - client as model_service_client, -) -from google.cloud.aiplatform_v1.services.pipeline_service import ( - client as pipeline_service_client, +from google.cloud.aiplatform.compat.services import ( + model_service_client, + pipeline_service_client, + job_service_client, ) -from google.cloud.aiplatform_v1.types import ( +from google.cloud.aiplatform.compat.types import ( + custom_job as gca_custom_job, dataset as gca_dataset, encryption_spec as gca_encryption_spec, env_var as gca_env_var, io as gca_io, + job_state as gca_job_state, model as gca_model, pipeline_state as gca_pipeline_state, training_pipeline as gca_training_pipeline, @@ -60,14 +67,15 @@ from google.cloud import storage from google.protobuf import json_format from google.protobuf import struct_pb2 - +from google.protobuf import duration_pb2 # type: ignore _TEST_BUCKET_NAME = "test-bucket" _TEST_GCS_PATH_WITHOUT_BUCKET = "path/to/folder" _TEST_GCS_PATH = f"{_TEST_BUCKET_NAME}/{_TEST_GCS_PATH_WITHOUT_BUCKET}" _TEST_GCS_PATH_WITH_TRAILING_SLASH = f"{_TEST_GCS_PATH}/" _TEST_LOCAL_SCRIPT_FILE_NAME = "____test____script.py" -_TEST_LOCAL_SCRIPT_FILE_PATH = f"path/to/{_TEST_LOCAL_SCRIPT_FILE_NAME}" +_TEST_TEMPDIR = tempfile.mkdtemp() +_TEST_LOCAL_SCRIPT_FILE_PATH = os.path.join(_TEST_TEMPDIR, _TEST_LOCAL_SCRIPT_FILE_NAME) _TEST_PYTHON_SOURCE = """ print('hello world') """ @@ -82,6 +90,7 @@ _TEST_SERVING_CONTAINER_IMAGE = "gcr.io/test-serving/container:image" _TEST_SERVING_CONTAINER_PREDICTION_ROUTE = "predict" _TEST_SERVING_CONTAINER_HEALTH_ROUTE = "metadata" +_TEST_MODULE_NAME = f"{source_utils._TrainingScriptPythonPackager._ROOT_MODULE}.task" _TEST_METADATA_SCHEMA_URI_NONTABULAR = schema.dataset.metadata.image _TEST_ANNOTATION_SCHEMA_URI = schema.dataset.annotation.image.classification @@ -92,17 +101,30 @@ _TEST_RUN_ARGS = ["-v", 0.1, "--test=arg"] _TEST_REPLICA_COUNT = 1 _TEST_MACHINE_TYPE = "n1-standard-4" +_TEST_REDUCTION_SERVER_REPLICA_COUNT = 1 +_TEST_REDUCTION_SERVER_MACHINE_TYPE = "n1-highcpu-16" +_TEST_REDUCTION_SERVER_CONTAINER_URI = ( + "us-docker.pkg.dev/vertex-ai-restricted/training/reductionserver:latest" +) _TEST_ACCELERATOR_TYPE = "NVIDIA_TESLA_K80" _TEST_INVALID_ACCELERATOR_TYPE = "NVIDIA_DOES_NOT_EXIST" _TEST_ACCELERATOR_COUNT = 1 +_TEST_BOOT_DISK_TYPE_DEFAULT = "pd-ssd" +_TEST_BOOT_DISK_SIZE_GB_DEFAULT = 100 +_TEST_BOOT_DISK_TYPE = "pd-standard" +_TEST_BOOT_DISK_SIZE_GB = 300 _TEST_MODEL_DISPLAY_NAME = "model-display-name" -_TEST_DEFAULT_TRAINING_FRACTION_SPLIT = 0.8 -_TEST_DEFAULT_VALIDATION_FRACTION_SPLIT = 0.1 -_TEST_DEFAULT_TEST_FRACTION_SPLIT = 0.1 +_TEST_LABELS = {"key": "value"} +_TEST_MODEL_LABELS = {"model_key": "model_value"} + _TEST_TRAINING_FRACTION_SPLIT = 0.6 _TEST_VALIDATION_FRACTION_SPLIT = 0.2 _TEST_TEST_FRACTION_SPLIT = 0.2 +_TEST_TRAINING_FILTER_SPLIT = "train" +_TEST_VALIDATION_FILTER_SPLIT = "validate" +_TEST_TEST_FILTER_SPLIT = "test" _TEST_PREDEFINED_SPLIT_COLUMN_NAME = "split" +_TEST_TIMESTAMP_SPLIT_COLUMN_NAME = "timestamp" _TEST_PROJECT = "test-project" _TEST_LOCATION = "us-central1" @@ -110,6 +132,12 @@ _TEST_NAME = ( f"projects/{_TEST_PROJECT}/locations/{_TEST_LOCATION}/trainingPipelines/{_TEST_ID}" ) +_TEST_TENSORBOARD_RESOURCE_NAME = ( + f"projects/{_TEST_PROJECT}/locations/{_TEST_LOCATION}/tensorboards/{_TEST_ID}" +) +_TEST_CUSTOM_JOB_RESOURCE_NAME = ( + f"projects/{_TEST_PROJECT}/locations/{_TEST_LOCATION}/customJobs/{_TEST_ID}" +) _TEST_ALT_PROJECT = "test-project-alt" _TEST_ALT_LOCATION = "europe-west4" _TEST_NETWORK = f"projects/{_TEST_PROJECT}/global/networks/{_TEST_ID}" @@ -135,7 +163,7 @@ _TEST_MODEL_NAME = "projects/my-project/locations/us-central1/models/12345" _TEST_PIPELINE_RESOURCE_NAME = ( - "projects/my-project/locations/us-central1/trainingPipeline/12345" + "projects/my-project/locations/us-central1/trainingPipelines/12345" ) _TEST_CREDENTIALS = mock.Mock(spec=auth_credentials.AnonymousCredentials()) @@ -155,6 +183,42 @@ kms_key_name=_TEST_MODEL_ENCRYPTION_KEY_NAME ) +_TEST_TIMEOUT = 1000 +_TEST_RESTART_JOB_ON_WORKER_RESTART = True + +_TEST_ENABLE_WEB_ACCESS = True +_TEST_WEB_ACCESS_URIS = {"workerpool0-0": "uri"} + +_TEST_BASE_CUSTOM_JOB_PROTO = gca_custom_job.CustomJob( + job_spec=gca_custom_job.CustomJobSpec(), +) + + +def _get_custom_job_proto_with_enable_web_access(state=None, name=None, version="v1"): + custom_job_proto = copy.deepcopy(_TEST_BASE_CUSTOM_JOB_PROTO) + custom_job_proto.name = name + custom_job_proto.state = state + + custom_job_proto.job_spec.enable_web_access = _TEST_ENABLE_WEB_ACCESS + if state == gca_job_state.JobState.JOB_STATE_RUNNING: + custom_job_proto.web_access_uris = _TEST_WEB_ACCESS_URIS + return custom_job_proto + + +def _get_custom_job_proto_with_scheduling(state=None, name=None, version="v1"): + custom_job_proto = copy.deepcopy(_TEST_BASE_CUSTOM_JOB_PROTO) + custom_job_proto.name = name + custom_job_proto.state = state + + custom_job_proto.job_spec.scheduling.timeout = duration_pb2.Duration( + seconds=_TEST_TIMEOUT + ) + custom_job_proto.job_spec.scheduling.restart_job_on_worker_restart = ( + _TEST_RESTART_JOB_ON_WORKER_RESTART + ) + + return custom_job_proto + def local_copy_method(path): shutil.copy(path, ".") @@ -166,11 +230,13 @@ def get_training_job_custom_mock(): with patch.object( pipeline_service_client.PipelineServiceClient, "get_training_pipeline" ) as get_training_job_custom_mock: - get_training_job_custom_mock.return_value = gca_training_pipeline.TrainingPipeline( - name=_TEST_PIPELINE_RESOURCE_NAME, - state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, - model_to_upload=gca_model.Model(name=_TEST_MODEL_NAME), - training_task_definition=schema.training_job.definition.custom_task, + get_training_job_custom_mock.return_value = ( + gca_training_pipeline.TrainingPipeline( + name=_TEST_PIPELINE_RESOURCE_NAME, + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, + model_to_upload=gca_model.Model(name=_TEST_MODEL_NAME), + training_task_definition=schema.training_job.definition.custom_task, + ) ) yield get_training_job_custom_mock @@ -181,11 +247,13 @@ def get_training_job_custom_mock_no_model_to_upload(): with patch.object( pipeline_service_client.PipelineServiceClient, "get_training_pipeline" ) as get_training_job_custom_mock: - get_training_job_custom_mock.return_value = gca_training_pipeline.TrainingPipeline( - name=_TEST_PIPELINE_RESOURCE_NAME, - state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, - model_to_upload=None, - training_task_definition=schema.training_job.definition.custom_task, + get_training_job_custom_mock.return_value = ( + gca_training_pipeline.TrainingPipeline( + name=_TEST_PIPELINE_RESOURCE_NAME, + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, + model_to_upload=None, + training_task_definition=schema.training_job.definition.custom_task, + ) ) yield get_training_job_custom_mock @@ -196,11 +264,13 @@ def get_training_job_tabular_mock(): with patch.object( pipeline_service_client.PipelineServiceClient, "get_training_pipeline" ) as get_training_job_tabular_mock: - get_training_job_tabular_mock.return_value = gca_training_pipeline.TrainingPipeline( - name=_TEST_PIPELINE_RESOURCE_NAME, - state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, - model_to_upload=gca_model.Model(name=_TEST_MODEL_NAME), - training_task_definition=schema.training_job.definition.automl_tabular, + get_training_job_tabular_mock.return_value = ( + gca_training_pipeline.TrainingPipeline( + name=_TEST_PIPELINE_RESOURCE_NAME, + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, + model_to_upload=gca_model.Model(name=_TEST_MODEL_NAME), + training_task_definition=schema.training_job.definition.automl_tabular, + ) ) yield get_training_job_tabular_mock @@ -226,6 +296,44 @@ def blob_side_effect(name, mock_blob, bucket): yield mock_client_bucket, MockBlob +@pytest.fixture +def mock_get_backing_custom_job_with_enable_web_access(): + with patch.object( + job_service_client.JobServiceClient, "get_custom_job" + ) as get_custom_job_mock: + get_custom_job_mock.side_effect = [ + _get_custom_job_proto_with_enable_web_access( + name=_TEST_CUSTOM_JOB_RESOURCE_NAME, + state=gca_job_state.JobState.JOB_STATE_PENDING, + ), + _get_custom_job_proto_with_enable_web_access( + name=_TEST_CUSTOM_JOB_RESOURCE_NAME, + state=gca_job_state.JobState.JOB_STATE_RUNNING, + ), + _get_custom_job_proto_with_enable_web_access( + name=_TEST_CUSTOM_JOB_RESOURCE_NAME, + state=gca_job_state.JobState.JOB_STATE_RUNNING, + ), + _get_custom_job_proto_with_enable_web_access( + name=_TEST_CUSTOM_JOB_RESOURCE_NAME, + state=gca_job_state.JobState.JOB_STATE_RUNNING, + ), + _get_custom_job_proto_with_enable_web_access( + name=_TEST_CUSTOM_JOB_RESOURCE_NAME, + state=gca_job_state.JobState.JOB_STATE_SUCCEEDED, + ), + _get_custom_job_proto_with_enable_web_access( + name=_TEST_CUSTOM_JOB_RESOURCE_NAME, + state=gca_job_state.JobState.JOB_STATE_SUCCEEDED, + ), + ] + yield get_custom_job_mock + + +@pytest.mark.skipif( + sys.executable is None, reason="requires python path to invoke subprocess" +) +@pytest.mark.usefixtures("google_auth_mock") class TestTrainingScriptPythonPackagerHelpers: def setup_method(self): importlib.reload(initializer) @@ -341,15 +449,19 @@ def test_get_python_executable_returns_python_executable(self): assert "python" in source_utils._get_python_executable().lower() +@pytest.mark.skipif( + sys.executable is None, reason="requires python path to invoke subprocess" +) +@pytest.mark.usefixtures("google_auth_mock") class TestTrainingScriptPythonPackager: def setup_method(self): importlib.reload(initializer) importlib.reload(aiplatform) - with open(_TEST_LOCAL_SCRIPT_FILE_NAME, "w") as fp: + with open(_TEST_LOCAL_SCRIPT_FILE_PATH, "w") as fp: fp.write(_TEST_PYTHON_SOURCE) def teardown_method(self): - pathlib.Path(_TEST_LOCAL_SCRIPT_FILE_NAME).unlink() + pathlib.Path(_TEST_LOCAL_SCRIPT_FILE_PATH).unlink() python_package_file = f"{source_utils._TrainingScriptPythonPackager._ROOT_MODULE}-{source_utils._TrainingScriptPythonPackager._SETUP_PY_VERSION}.tar.gz" if pathlib.Path(python_package_file).is_file(): pathlib.Path(python_package_file).unlink() @@ -363,14 +475,14 @@ def teardown_method(self): ) def test_packager_creates_and_copies_python_package(self): - tsp = source_utils._TrainingScriptPythonPackager(_TEST_LOCAL_SCRIPT_FILE_NAME) + tsp = source_utils._TrainingScriptPythonPackager(_TEST_LOCAL_SCRIPT_FILE_PATH) tsp.package_and_copy(copy_method=local_copy_method) assert pathlib.Path( f"{tsp._ROOT_MODULE}-{tsp._SETUP_PY_VERSION}.tar.gz" ).is_file() def test_created_package_module_is_installable_and_can_be_run(self): - tsp = source_utils._TrainingScriptPythonPackager(_TEST_LOCAL_SCRIPT_FILE_NAME) + tsp = source_utils._TrainingScriptPythonPackager(_TEST_LOCAL_SCRIPT_FILE_PATH) source_dist_path = tsp.package_and_copy(copy_method=local_copy_method) subprocess.check_output(["pip3", "install", source_dist_path]) module_output = subprocess.check_output( @@ -380,7 +492,7 @@ def test_created_package_module_is_installable_and_can_be_run(self): def test_requirements_are_in_package(self): tsp = source_utils._TrainingScriptPythonPackager( - _TEST_LOCAL_SCRIPT_FILE_NAME, requirements=_TEST_REQUIREMENTS + _TEST_LOCAL_SCRIPT_FILE_PATH, requirements=_TEST_REQUIREMENTS ) source_dist_path = tsp.package_and_copy(copy_method=local_copy_method) with tarfile.open(source_dist_path) as tf: @@ -399,7 +511,7 @@ def test_packaging_fails_whith_RuntimeError(self): mock_subprocess.returncode = 1 mock_popen.return_value = mock_subprocess tsp = source_utils._TrainingScriptPythonPackager( - _TEST_LOCAL_SCRIPT_FILE_NAME + _TEST_LOCAL_SCRIPT_FILE_PATH ) with pytest.raises(RuntimeError): tsp.package_and_copy(copy_method=local_copy_method) @@ -407,7 +519,7 @@ def test_packaging_fails_whith_RuntimeError(self): def test_package_and_copy_to_gcs_copies_to_gcs(self, mock_client_bucket): mock_client_bucket, mock_blob = mock_client_bucket - tsp = source_utils._TrainingScriptPythonPackager(_TEST_LOCAL_SCRIPT_FILE_NAME) + tsp = source_utils._TrainingScriptPythonPackager(_TEST_LOCAL_SCRIPT_FILE_PATH) gcs_path = tsp.package_and_copy_to_gcs( gcs_staging_dir=_TEST_BUCKET_NAME, project=_TEST_PROJECT @@ -429,24 +541,161 @@ def mock_pipeline_service_create(): with mock.patch.object( pipeline_service_client.PipelineServiceClient, "create_training_pipeline" ) as mock_create_training_pipeline: - mock_create_training_pipeline.return_value = gca_training_pipeline.TrainingPipeline( - name=_TEST_PIPELINE_RESOURCE_NAME, - state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, - model_to_upload=gca_model.Model(name=_TEST_MODEL_NAME), + mock_create_training_pipeline.return_value = ( + gca_training_pipeline.TrainingPipeline( + name=_TEST_PIPELINE_RESOURCE_NAME, + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, + model_to_upload=gca_model.Model(name=_TEST_MODEL_NAME), + ) ) yield mock_create_training_pipeline +def make_training_pipeline(state, add_training_task_metadata=True): + return gca_training_pipeline.TrainingPipeline( + name=_TEST_PIPELINE_RESOURCE_NAME, + state=state, + model_to_upload=gca_model.Model(name=_TEST_MODEL_NAME), + training_task_inputs={"tensorboard": _TEST_TENSORBOARD_RESOURCE_NAME}, + training_task_metadata={"backingCustomJob": _TEST_CUSTOM_JOB_RESOURCE_NAME} + if add_training_task_metadata + else None, + ) + + +def make_training_pipeline_with_no_model_upload(state): + return gca_training_pipeline.TrainingPipeline( + name=_TEST_PIPELINE_RESOURCE_NAME, + state=state, + ) + + +def make_training_pipeline_with_enable_web_access(state): + training_pipeline = gca_training_pipeline.TrainingPipeline( + name=_TEST_PIPELINE_RESOURCE_NAME, + state=state, + training_task_inputs={"enable_web_access": _TEST_ENABLE_WEB_ACCESS}, + ) + if state == gca_pipeline_state.PipelineState.PIPELINE_STATE_RUNNING: + training_pipeline.training_task_metadata = { + "backingCustomJob": _TEST_CUSTOM_JOB_RESOURCE_NAME + } + return training_pipeline + + +def make_training_pipeline_with_scheduling(state): + training_pipeline = gca_training_pipeline.TrainingPipeline( + name=_TEST_PIPELINE_RESOURCE_NAME, + state=state, + training_task_inputs={ + "timeout": f"{_TEST_TIMEOUT}s", + "restart_job_on_worker_restart": _TEST_RESTART_JOB_ON_WORKER_RESTART, + }, + ) + if state == gca_pipeline_state.PipelineState.PIPELINE_STATE_RUNNING: + training_pipeline.training_task_metadata = { + "backingCustomJob": _TEST_CUSTOM_JOB_RESOURCE_NAME + } + return training_pipeline + + @pytest.fixture def mock_pipeline_service_get(): with mock.patch.object( pipeline_service_client.PipelineServiceClient, "get_training_pipeline" ) as mock_get_training_pipeline: - mock_get_training_pipeline.return_value = gca_training_pipeline.TrainingPipeline( - name=_TEST_PIPELINE_RESOURCE_NAME, - state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, - model_to_upload=gca_model.Model(name=_TEST_MODEL_NAME), - ) + mock_get_training_pipeline.side_effect = [ + make_training_pipeline( + gca_pipeline_state.PipelineState.PIPELINE_STATE_RUNNING, + add_training_task_metadata=False, + ), + make_training_pipeline( + gca_pipeline_state.PipelineState.PIPELINE_STATE_RUNNING, + ), + make_training_pipeline( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ), + make_training_pipeline( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ), + make_training_pipeline( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ), + make_training_pipeline( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ), + make_training_pipeline( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ), + make_training_pipeline( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ), + make_training_pipeline( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ), + make_training_pipeline( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ), + ] + + yield mock_get_training_pipeline + + +@pytest.fixture +def mock_pipeline_service_get_with_enable_web_access(): + with mock.patch.object( + pipeline_service_client.PipelineServiceClient, "get_training_pipeline" + ) as mock_get_training_pipeline: + mock_get_training_pipeline.side_effect = [ + make_training_pipeline_with_enable_web_access( + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_PENDING, + ), + make_training_pipeline_with_enable_web_access( + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_RUNNING, + ), + make_training_pipeline_with_enable_web_access( + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_RUNNING, + ), + make_training_pipeline_with_enable_web_access( + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_RUNNING, + ), + make_training_pipeline_with_enable_web_access( + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, + ), + make_training_pipeline_with_enable_web_access( + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, + ), + ] + + yield mock_get_training_pipeline + + +@pytest.fixture +def mock_pipeline_service_get_with_scheduling(): + with mock.patch.object( + pipeline_service_client.PipelineServiceClient, "get_training_pipeline" + ) as mock_get_training_pipeline: + mock_get_training_pipeline.side_effect = [ + make_training_pipeline_with_scheduling( + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_PENDING, + ), + make_training_pipeline_with_scheduling( + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_RUNNING, + ), + make_training_pipeline_with_scheduling( + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_RUNNING, + ), + make_training_pipeline_with_scheduling( + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_RUNNING, + ), + make_training_pipeline_with_scheduling( + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, + ), + make_training_pipeline_with_scheduling( + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, + ), + ] + yield mock_get_training_pipeline @@ -463,9 +712,37 @@ def mock_pipeline_service_create_with_no_model_to_upload(): with mock.patch.object( pipeline_service_client.PipelineServiceClient, "create_training_pipeline" ) as mock_create_training_pipeline: - mock_create_training_pipeline.return_value = gca_training_pipeline.TrainingPipeline( - name=_TEST_PIPELINE_RESOURCE_NAME, - state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, + mock_create_training_pipeline.return_value = ( + gca_training_pipeline.TrainingPipeline( + name=_TEST_PIPELINE_RESOURCE_NAME, + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, + ) + ) + yield mock_create_training_pipeline + + +@pytest.fixture +def mock_pipeline_service_create_with_enable_web_access(): + with mock.patch.object( + pipeline_service_client.PipelineServiceClient, "create_training_pipeline" + ) as mock_create_training_pipeline: + mock_create_training_pipeline.return_value = ( + make_training_pipeline_with_enable_web_access( + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_PENDING, + ) + ) + yield mock_create_training_pipeline + + +@pytest.fixture +def mock_pipeline_service_create_with_scheduling(): + with mock.patch.object( + pipeline_service_client.PipelineServiceClient, "create_training_pipeline" + ) as mock_create_training_pipeline: + mock_create_training_pipeline.return_value = ( + make_training_pipeline_with_scheduling( + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_PENDING, + ) ) yield mock_create_training_pipeline @@ -475,9 +752,11 @@ def mock_pipeline_service_get_with_no_model_to_upload(): with mock.patch.object( pipeline_service_client.PipelineServiceClient, "get_training_pipeline" ) as mock_get_training_pipeline: - mock_get_training_pipeline.return_value = gca_training_pipeline.TrainingPipeline( - name=_TEST_PIPELINE_RESOURCE_NAME, - state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, + mock_get_training_pipeline.return_value = ( + gca_training_pipeline.TrainingPipeline( + name=_TEST_PIPELINE_RESOURCE_NAME, + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED, + ) ) yield mock_get_training_pipeline @@ -487,17 +766,21 @@ def mock_pipeline_service_create_and_get_with_fail(): with mock.patch.object( pipeline_service_client.PipelineServiceClient, "create_training_pipeline" ) as mock_create_training_pipeline: - mock_create_training_pipeline.return_value = gca_training_pipeline.TrainingPipeline( - name=_TEST_PIPELINE_RESOURCE_NAME, - state=gca_pipeline_state.PipelineState.PIPELINE_STATE_RUNNING, + mock_create_training_pipeline.return_value = ( + gca_training_pipeline.TrainingPipeline( + name=_TEST_PIPELINE_RESOURCE_NAME, + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_RUNNING, + ) ) with mock.patch.object( pipeline_service_client.PipelineServiceClient, "get_training_pipeline" ) as mock_get_training_pipeline: - mock_get_training_pipeline.return_value = gca_training_pipeline.TrainingPipeline( - name=_TEST_PIPELINE_RESOURCE_NAME, - state=gca_pipeline_state.PipelineState.PIPELINE_STATE_FAILED, + mock_get_training_pipeline.return_value = ( + gca_training_pipeline.TrainingPipeline( + name=_TEST_PIPELINE_RESOURCE_NAME, + state=gca_pipeline_state.PipelineState.PIPELINE_STATE_FAILED, + ) ) yield mock_create_training_pipeline, mock_get_training_pipeline @@ -509,6 +792,9 @@ def mock_model_service_get(): model_service_client.ModelServiceClient, "get_model" ) as mock_get_model: mock_get_model.return_value = gca_model.Model(name=_TEST_MODEL_NAME) + mock_get_model.return_value.supported_deployment_resources_types.append( + aiplatform.gapic.Model.DeploymentResourcesType.DEDICATED_RESOURCES + ) yield mock_get_model @@ -525,6 +811,7 @@ def mock_python_package_to_gcs(): def mock_tabular_dataset(): ds = mock.MagicMock(datasets.TabularDataset) ds.name = _TEST_DATASET_NAME + ds.metadata_schema_uri = _TEST_METADATA_SCHEMA_URI_TABULAR ds._latest_future = None ds._exception = None ds._gca_resource = gca_dataset.Dataset( @@ -541,6 +828,7 @@ def mock_tabular_dataset(): def mock_nontabular_dataset(): ds = mock.MagicMock(datasets.ImageDataset) ds.name = _TEST_DATASET_NAME + ds.metadata_schema_uri = _TEST_METADATA_SCHEMA_URI_NONTABULAR ds._latest_future = None ds._exception = None ds._gca_resource = gca_dataset.Dataset( @@ -553,17 +841,23 @@ def mock_nontabular_dataset(): return ds +@pytest.mark.usefixtures("google_auth_mock") class TestCustomTrainingJob: def setup_method(self): importlib.reload(initializer) importlib.reload(aiplatform) - with open(_TEST_LOCAL_SCRIPT_FILE_NAME, "w") as fp: + self._local_script_file_name = os.path.join( + _TEST_TEMPDIR, f"{uuid.uuid4()}-{_TEST_LOCAL_SCRIPT_FILE_NAME}" + ) + with open(self._local_script_file_name, "w") as fp: fp.write(_TEST_PYTHON_SOURCE) def teardown_method(self): - pathlib.Path(_TEST_LOCAL_SCRIPT_FILE_NAME).unlink() + pathlib.Path(self._local_script_file_name).unlink() initializer.global_pool.shutdown(wait=True) + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) def test_run_call_pipeline_service_create_with_tabular_dataset( self, @@ -583,6 +877,7 @@ def test_run_call_pipeline_service_create_with_tabular_dataset( job = training_jobs.CustomTrainingJob( display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, script_path=_TEST_LOCAL_SCRIPT_FILE_NAME, container_uri=_TEST_TRAINING_CONTAINER_IMAGE, model_serving_container_image_uri=_TEST_SERVING_CONTAINER_IMAGE, @@ -605,16 +900,18 @@ def test_run_call_pipeline_service_create_with_tabular_dataset( network=_TEST_NETWORK, args=_TEST_RUN_ARGS, environment_variables=_TEST_ENVIRONMENT_VARIABLES, - replica_count=1, machine_type=_TEST_MACHINE_TYPE, accelerator_type=_TEST_ACCELERATOR_TYPE, accelerator_count=_TEST_ACCELERATOR_COUNT, model_display_name=_TEST_MODEL_DISPLAY_NAME, + model_labels=_TEST_MODEL_LABELS, training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT, validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, test_fraction_split=_TEST_TEST_FRACTION_SPLIT, - predefined_split_column_name=_TEST_PREDEFINED_SPLIT_COLUMN_NAME, + timestamp_split_column_name=_TEST_TIMESTAMP_SPLIT_COLUMN_NAME, + tensorboard=_TEST_TENSORBOARD_RESOURCE_NAME, sync=sync, + create_request_timeout=None, ) if not sync: @@ -639,19 +936,24 @@ def test_run_call_pipeline_service_create_with_tabular_dataset( "accelerator_type": _TEST_ACCELERATOR_TYPE, "accelerator_count": _TEST_ACCELERATOR_COUNT, }, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, "python_package_spec": { "executor_image_uri": _TEST_TRAINING_CONTAINER_IMAGE, - "python_module": source_utils._TrainingScriptPythonPackager.module_name, + "python_module": _TEST_MODULE_NAME, "package_uris": [_TEST_OUTPUT_PYTHON_PACKAGE_PATH], "args": true_args, "env": true_env, }, } - true_fraction_split = gca_training_pipeline.FractionSplit( + true_timestamp_split = gca_training_pipeline.TimestampSplit( training_fraction=_TEST_TRAINING_FRACTION_SPLIT, validation_fraction=_TEST_VALIDATION_FRACTION_SPLIT, test_fraction=_TEST_TEST_FRACTION_SPLIT, + key=_TEST_TIMESTAMP_SPLIT_COLUMN_NAME, ) env = [ @@ -676,6 +978,7 @@ def test_run_call_pipeline_service_create_with_tabular_dataset( true_managed_model = gca_model.Model( display_name=_TEST_MODEL_DISPLAY_NAME, + labels=_TEST_MODEL_LABELS, description=_TEST_MODEL_DESCRIPTION, container_spec=true_container_spec, predict_schemata=gca_model.PredictSchemata( @@ -687,10 +990,7 @@ def test_run_call_pipeline_service_create_with_tabular_dataset( ) true_input_data_config = gca_training_pipeline.InputDataConfig( - fraction_split=true_fraction_split, - predefined_split=gca_training_pipeline.PredefinedSplit( - key=_TEST_PREDEFINED_SPLIT_COLUMN_NAME - ), + timestamp_split=true_timestamp_split, dataset_id=mock_tabular_dataset.name, gcs_destination=gca_io.GcsDestination( output_uri_prefix=_TEST_BASE_OUTPUT_DIR @@ -708,22 +1008,29 @@ def test_run_call_pipeline_service_create_with_tabular_dataset( }, "service_account": _TEST_SERVICE_ACCOUNT, "network": _TEST_NETWORK, + "tensorboard": _TEST_TENSORBOARD_RESOURCE_NAME, }, struct_pb2.Value(), ), model_to_upload=true_managed_model, input_data_config=true_input_data_config, + labels=_TEST_LABELS, encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, ) mock_pipeline_service_create.assert_called_once_with( parent=initializer.global_config.common_location_path(), training_pipeline=true_training_pipeline, + timeout=None, ) - assert job._gca_resource is mock_pipeline_service_get.return_value + assert job._gca_resource == make_training_pipeline( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) - mock_model_service_get.assert_called_once_with(name=_TEST_MODEL_NAME) + mock_model_service_get.assert_called_once_with( + name=_TEST_MODEL_NAME, retry=base._DEFAULT_RETRY + ) assert model_from_job._gca_resource is mock_model_service_get.return_value @@ -733,8 +1040,74 @@ def test_run_call_pipeline_service_create_with_tabular_dataset( assert job.state == gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + assert job._has_logged_custom_job + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + def test_custom_training_tabular_done( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + mock_python_package_to_gcs, + mock_tabular_dataset, + mock_model_service_get, + ): + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_BUCKET_NAME, + credentials=_TEST_CREDENTIALS, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) + + job = training_jobs.CustomTrainingJob( + display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, + script_path=_TEST_LOCAL_SCRIPT_FILE_NAME, + container_uri=_TEST_TRAINING_CONTAINER_IMAGE, + model_serving_container_image_uri=_TEST_SERVING_CONTAINER_IMAGE, + model_serving_container_predict_route=_TEST_SERVING_CONTAINER_PREDICTION_ROUTE, + model_serving_container_health_route=_TEST_SERVING_CONTAINER_HEALTH_ROUTE, + model_instance_schema_uri=_TEST_MODEL_INSTANCE_SCHEMA_URI, + model_parameters_schema_uri=_TEST_MODEL_PARAMETERS_SCHEMA_URI, + model_prediction_schema_uri=_TEST_MODEL_PREDICTION_SCHEMA_URI, + model_serving_container_command=_TEST_MODEL_SERVING_CONTAINER_COMMAND, + model_serving_container_args=_TEST_MODEL_SERVING_CONTAINER_ARGS, + model_serving_container_environment_variables=_TEST_MODEL_SERVING_CONTAINER_ENVIRONMENT_VARIABLES, + model_serving_container_ports=_TEST_MODEL_SERVING_CONTAINER_PORTS, + model_description=_TEST_MODEL_DESCRIPTION, + ) + + job.run( + dataset=mock_tabular_dataset, + base_output_dir=_TEST_BASE_OUTPUT_DIR, + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, + args=_TEST_RUN_ARGS, + environment_variables=_TEST_ENVIRONMENT_VARIABLES, + machine_type=_TEST_MACHINE_TYPE, + accelerator_type=_TEST_ACCELERATOR_TYPE, + accelerator_count=_TEST_ACCELERATOR_COUNT, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + model_labels=_TEST_MODEL_LABELS, + training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT, + validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, + test_fraction_split=_TEST_TEST_FRACTION_SPLIT, + timestamp_split_column_name=_TEST_TIMESTAMP_SPLIT_COLUMN_NAME, + tensorboard=_TEST_TENSORBOARD_RESOURCE_NAME, + sync=False, + create_request_timeout=None, + ) + + assert job.done() is False + + job.wait() + + assert job.done() is True + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) - def test_run_call_pipeline_service_create_with_bigquery_destination( + def test_run_call_pipeline_service_create_with_tabular_dataset_and_timeout( self, mock_pipeline_service_create, mock_pipeline_service_get, @@ -744,11 +1117,15 @@ def test_run_call_pipeline_service_create_with_bigquery_destination( sync, ): aiplatform.init( - project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME, + project=_TEST_PROJECT, + staging_bucket=_TEST_BUCKET_NAME, + credentials=_TEST_CREDENTIALS, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, ) job = training_jobs.CustomTrainingJob( display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, script_path=_TEST_LOCAL_SCRIPT_FILE_NAME, container_uri=_TEST_TRAINING_CONTAINER_IMAGE, model_serving_container_image_uri=_TEST_SERVING_CONTAINER_IMAGE, @@ -762,26 +1139,27 @@ def test_run_call_pipeline_service_create_with_bigquery_destination( model_serving_container_environment_variables=_TEST_MODEL_SERVING_CONTAINER_ENVIRONMENT_VARIABLES, model_serving_container_ports=_TEST_MODEL_SERVING_CONTAINER_PORTS, model_description=_TEST_MODEL_DESCRIPTION, - training_encryption_spec_key_name=_TEST_PIPELINE_ENCRYPTION_KEY_NAME, - model_encryption_spec_key_name=_TEST_MODEL_ENCRYPTION_KEY_NAME, ) model_from_job = job.run( dataset=mock_tabular_dataset, base_output_dir=_TEST_BASE_OUTPUT_DIR, - bigquery_destination=_TEST_BIGQUERY_DESTINATION, + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, args=_TEST_RUN_ARGS, environment_variables=_TEST_ENVIRONMENT_VARIABLES, - replica_count=1, machine_type=_TEST_MACHINE_TYPE, accelerator_type=_TEST_ACCELERATOR_TYPE, accelerator_count=_TEST_ACCELERATOR_COUNT, model_display_name=_TEST_MODEL_DISPLAY_NAME, + model_labels=_TEST_MODEL_LABELS, training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT, validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, test_fraction_split=_TEST_TEST_FRACTION_SPLIT, - predefined_split_column_name=_TEST_PREDEFINED_SPLIT_COLUMN_NAME, + timestamp_split_column_name=_TEST_TIMESTAMP_SPLIT_COLUMN_NAME, + tensorboard=_TEST_TENSORBOARD_RESOURCE_NAME, sync=sync, + create_request_timeout=180.0, ) if not sync: @@ -800,19 +1178,24 @@ def test_run_call_pipeline_service_create_with_bigquery_destination( "accelerator_type": _TEST_ACCELERATOR_TYPE, "accelerator_count": _TEST_ACCELERATOR_COUNT, }, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, "python_package_spec": { "executor_image_uri": _TEST_TRAINING_CONTAINER_IMAGE, - "python_module": source_utils._TrainingScriptPythonPackager.module_name, + "python_module": _TEST_MODULE_NAME, "package_uris": [_TEST_OUTPUT_PYTHON_PACKAGE_PATH], "args": true_args, "env": true_env, }, } - true_fraction_split = gca_training_pipeline.FractionSplit( + true_timestamp_split = gca_training_pipeline.TimestampSplit( training_fraction=_TEST_TRAINING_FRACTION_SPLIT, validation_fraction=_TEST_VALIDATION_FRACTION_SPLIT, test_fraction=_TEST_TEST_FRACTION_SPLIT, + key=_TEST_TIMESTAMP_SPLIT_COLUMN_NAME, ) env = [ @@ -837,6 +1220,7 @@ def test_run_call_pipeline_service_create_with_bigquery_destination( true_managed_model = gca_model.Model( display_name=_TEST_MODEL_DISPLAY_NAME, + labels=_TEST_MODEL_LABELS, description=_TEST_MODEL_DESCRIPTION, container_spec=true_container_spec, predict_schemata=gca_model.PredictSchemata( @@ -844,17 +1228,14 @@ def test_run_call_pipeline_service_create_with_bigquery_destination( parameters_schema_uri=_TEST_MODEL_PARAMETERS_SCHEMA_URI, prediction_schema_uri=_TEST_MODEL_PREDICTION_SCHEMA_URI, ), - encryption_spec=_TEST_MODEL_ENCRYPTION_SPEC, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, ) true_input_data_config = gca_training_pipeline.InputDataConfig( - fraction_split=true_fraction_split, - predefined_split=gca_training_pipeline.PredefinedSplit( - key=_TEST_PREDEFINED_SPLIT_COLUMN_NAME - ), + timestamp_split=true_timestamp_split, dataset_id=mock_tabular_dataset.name, - bigquery_destination=gca_io.BigQueryDestination( - output_uri=_TEST_BIGQUERY_DESTINATION + gcs_destination=gca_io.GcsDestination( + output_uri_prefix=_TEST_BASE_OUTPUT_DIR ), ) @@ -867,168 +1248,200 @@ def test_run_call_pipeline_service_create_with_bigquery_destination( "base_output_directory": { "output_uri_prefix": _TEST_BASE_OUTPUT_DIR }, + "service_account": _TEST_SERVICE_ACCOUNT, + "network": _TEST_NETWORK, + "tensorboard": _TEST_TENSORBOARD_RESOURCE_NAME, }, struct_pb2.Value(), ), model_to_upload=true_managed_model, input_data_config=true_input_data_config, - encryption_spec=_TEST_PIPELINE_ENCRYPTION_SPEC, + labels=_TEST_LABELS, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, ) mock_pipeline_service_create.assert_called_once_with( parent=initializer.global_config.common_location_path(), training_pipeline=true_training_pipeline, + timeout=180.0, ) - assert job._gca_resource is mock_pipeline_service_get.return_value - - mock_model_service_get.assert_called_once_with(name=_TEST_MODEL_NAME) - - assert model_from_job._gca_resource is mock_model_service_get.return_value - - assert job.get_model()._gca_resource is mock_model_service_get.return_value - - assert not job.has_failed - - assert job.state == gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED - - @pytest.mark.usefixtures( - "mock_pipeline_service_create", - "mock_pipeline_service_get", - "mock_python_package_to_gcs", - "mock_model_service_get", - ) + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) - def test_run_called_twice_raises( - self, mock_tabular_dataset, sync, + def test_run_call_pipeline_service_create_with_tabular_dataset_and_timeout_not_explicitly_set( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + mock_python_package_to_gcs, + mock_tabular_dataset, + mock_model_service_get, + sync, ): - aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME) + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_BUCKET_NAME, + credentials=_TEST_CREDENTIALS, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) job = training_jobs.CustomTrainingJob( display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, script_path=_TEST_LOCAL_SCRIPT_FILE_NAME, container_uri=_TEST_TRAINING_CONTAINER_IMAGE, model_serving_container_image_uri=_TEST_SERVING_CONTAINER_IMAGE, model_serving_container_predict_route=_TEST_SERVING_CONTAINER_PREDICTION_ROUTE, model_serving_container_health_route=_TEST_SERVING_CONTAINER_HEALTH_ROUTE, - ) + model_instance_schema_uri=_TEST_MODEL_INSTANCE_SCHEMA_URI, + model_parameters_schema_uri=_TEST_MODEL_PARAMETERS_SCHEMA_URI, + model_prediction_schema_uri=_TEST_MODEL_PREDICTION_SCHEMA_URI, + model_serving_container_command=_TEST_MODEL_SERVING_CONTAINER_COMMAND, + model_serving_container_args=_TEST_MODEL_SERVING_CONTAINER_ARGS, + model_serving_container_environment_variables=_TEST_MODEL_SERVING_CONTAINER_ENVIRONMENT_VARIABLES, + model_serving_container_ports=_TEST_MODEL_SERVING_CONTAINER_PORTS, + model_description=_TEST_MODEL_DESCRIPTION, + ) - job.run( + model_from_job = job.run( dataset=mock_tabular_dataset, base_output_dir=_TEST_BASE_OUTPUT_DIR, + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, args=_TEST_RUN_ARGS, - replica_count=1, + environment_variables=_TEST_ENVIRONMENT_VARIABLES, machine_type=_TEST_MACHINE_TYPE, accelerator_type=_TEST_ACCELERATOR_TYPE, accelerator_count=_TEST_ACCELERATOR_COUNT, model_display_name=_TEST_MODEL_DISPLAY_NAME, + model_labels=_TEST_MODEL_LABELS, training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT, validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, test_fraction_split=_TEST_TEST_FRACTION_SPLIT, + timestamp_split_column_name=_TEST_TIMESTAMP_SPLIT_COLUMN_NAME, + tensorboard=_TEST_TENSORBOARD_RESOURCE_NAME, sync=sync, ) - with pytest.raises(RuntimeError): - job.run( - dataset=mock_tabular_dataset, - base_output_dir=_TEST_BASE_OUTPUT_DIR, - args=_TEST_RUN_ARGS, - replica_count=1, - machine_type=_TEST_MACHINE_TYPE, - accelerator_type=_TEST_ACCELERATOR_TYPE, - accelerator_count=_TEST_ACCELERATOR_COUNT, - model_display_name=_TEST_MODEL_DISPLAY_NAME, - training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT, - validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, - test_fraction_split=_TEST_TEST_FRACTION_SPLIT, - sync=sync, - ) - if not sync: - job.wait() + model_from_job.wait() - @pytest.mark.parametrize("sync", [True, False]) - def test_run_with_invalid_accelerator_type_raises( - self, - mock_pipeline_service_create, - mock_python_package_to_gcs, - mock_tabular_dataset, - mock_model_service_get, - sync, - ): - aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME) + true_args = _TEST_RUN_ARGS + true_env = [ + {"name": key, "value": value} + for key, value in _TEST_ENVIRONMENT_VARIABLES.items() + ] - job = training_jobs.CustomTrainingJob( - display_name=_TEST_DISPLAY_NAME, - script_path=_TEST_LOCAL_SCRIPT_FILE_NAME, - container_uri=_TEST_TRAINING_CONTAINER_IMAGE, - model_serving_container_image_uri=_TEST_SERVING_CONTAINER_IMAGE, - model_serving_container_predict_route=_TEST_SERVING_CONTAINER_PREDICTION_ROUTE, - model_serving_container_health_route=_TEST_SERVING_CONTAINER_HEALTH_ROUTE, + true_worker_pool_spec = { + "replica_count": _TEST_REPLICA_COUNT, + "machine_spec": { + "machine_type": _TEST_MACHINE_TYPE, + "accelerator_type": _TEST_ACCELERATOR_TYPE, + "accelerator_count": _TEST_ACCELERATOR_COUNT, + }, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, + "python_package_spec": { + "executor_image_uri": _TEST_TRAINING_CONTAINER_IMAGE, + "python_module": _TEST_MODULE_NAME, + "package_uris": [_TEST_OUTPUT_PYTHON_PACKAGE_PATH], + "args": true_args, + "env": true_env, + }, + } + + true_timestamp_split = gca_training_pipeline.TimestampSplit( + training_fraction=_TEST_TRAINING_FRACTION_SPLIT, + validation_fraction=_TEST_VALIDATION_FRACTION_SPLIT, + test_fraction=_TEST_TEST_FRACTION_SPLIT, + key=_TEST_TIMESTAMP_SPLIT_COLUMN_NAME, ) - with pytest.raises(ValueError): - job.run( - dataset=mock_tabular_dataset, - base_output_dir=_TEST_BASE_OUTPUT_DIR, - args=_TEST_RUN_ARGS, - replica_count=1, - machine_type=_TEST_MACHINE_TYPE, - accelerator_type=_TEST_INVALID_ACCELERATOR_TYPE, - accelerator_count=_TEST_ACCELERATOR_COUNT, - model_display_name=_TEST_MODEL_DISPLAY_NAME, - training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT, - validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, - test_fraction_split=_TEST_TEST_FRACTION_SPLIT, - sync=sync, - ) + env = [ + gca_env_var.EnvVar(name=str(key), value=str(value)) + for key, value in _TEST_MODEL_SERVING_CONTAINER_ENVIRONMENT_VARIABLES.items() + ] - @pytest.mark.parametrize("sync", [True, False]) - def test_run_with_incomplete_model_info_raises_with_model_to_upload( - self, - mock_pipeline_service_create, - mock_python_package_to_gcs, - mock_tabular_dataset, - mock_model_service_get, - sync, - ): - aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME) + ports = [ + gca_model.Port(container_port=port) + for port in _TEST_MODEL_SERVING_CONTAINER_PORTS + ] - job = training_jobs.CustomTrainingJob( + true_container_spec = gca_model.ModelContainerSpec( + image_uri=_TEST_SERVING_CONTAINER_IMAGE, + predict_route=_TEST_SERVING_CONTAINER_PREDICTION_ROUTE, + health_route=_TEST_SERVING_CONTAINER_HEALTH_ROUTE, + command=_TEST_MODEL_SERVING_CONTAINER_COMMAND, + args=_TEST_MODEL_SERVING_CONTAINER_ARGS, + env=env, + ports=ports, + ) + + true_managed_model = gca_model.Model( + display_name=_TEST_MODEL_DISPLAY_NAME, + labels=_TEST_MODEL_LABELS, + description=_TEST_MODEL_DESCRIPTION, + container_spec=true_container_spec, + predict_schemata=gca_model.PredictSchemata( + instance_schema_uri=_TEST_MODEL_INSTANCE_SCHEMA_URI, + parameters_schema_uri=_TEST_MODEL_PARAMETERS_SCHEMA_URI, + prediction_schema_uri=_TEST_MODEL_PREDICTION_SCHEMA_URI, + ), + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + true_input_data_config = gca_training_pipeline.InputDataConfig( + timestamp_split=true_timestamp_split, + dataset_id=mock_tabular_dataset.name, + gcs_destination=gca_io.GcsDestination( + output_uri_prefix=_TEST_BASE_OUTPUT_DIR + ), + ) + + true_training_pipeline = gca_training_pipeline.TrainingPipeline( display_name=_TEST_DISPLAY_NAME, - script_path=_TEST_LOCAL_SCRIPT_FILE_NAME, - container_uri=_TEST_TRAINING_CONTAINER_IMAGE, + training_task_definition=schema.training_job.definition.custom_task, + training_task_inputs=json_format.ParseDict( + { + "worker_pool_specs": [true_worker_pool_spec], + "base_output_directory": { + "output_uri_prefix": _TEST_BASE_OUTPUT_DIR + }, + "service_account": _TEST_SERVICE_ACCOUNT, + "network": _TEST_NETWORK, + "tensorboard": _TEST_TENSORBOARD_RESOURCE_NAME, + }, + struct_pb2.Value(), + ), + model_to_upload=true_managed_model, + input_data_config=true_input_data_config, + labels=_TEST_LABELS, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, ) - with pytest.raises(RuntimeError): - job.run( - dataset=mock_tabular_dataset, - base_output_dir=_TEST_BASE_OUTPUT_DIR, - args=_TEST_RUN_ARGS, - replica_count=1, - machine_type=_TEST_MACHINE_TYPE, - accelerator_type=_TEST_ACCELERATOR_TYPE, - accelerator_count=_TEST_ACCELERATOR_COUNT, - model_display_name=_TEST_MODEL_DISPLAY_NAME, - training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT, - validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, - test_fraction_split=_TEST_TEST_FRACTION_SPLIT, - sync=sync, - ) + mock_pipeline_service_create.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + training_pipeline=true_training_pipeline, + timeout=None, + ) + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) - def test_run_call_pipeline_service_create_with_no_dataset( + def test_run_call_pipeline_service_create_with_bigquery_destination( self, mock_pipeline_service_create, mock_pipeline_service_get, mock_python_package_to_gcs, + mock_tabular_dataset, mock_model_service_get, sync, ): aiplatform.init( project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME, - credentials=_TEST_CREDENTIALS, ) job = training_jobs.CustomTrainingJob( @@ -1038,32 +1451,36 @@ def test_run_call_pipeline_service_create_with_no_dataset( model_serving_container_image_uri=_TEST_SERVING_CONTAINER_IMAGE, model_serving_container_predict_route=_TEST_SERVING_CONTAINER_PREDICTION_ROUTE, model_serving_container_health_route=_TEST_SERVING_CONTAINER_HEALTH_ROUTE, + model_instance_schema_uri=_TEST_MODEL_INSTANCE_SCHEMA_URI, + model_parameters_schema_uri=_TEST_MODEL_PARAMETERS_SCHEMA_URI, + model_prediction_schema_uri=_TEST_MODEL_PREDICTION_SCHEMA_URI, + model_serving_container_command=_TEST_MODEL_SERVING_CONTAINER_COMMAND, + model_serving_container_args=_TEST_MODEL_SERVING_CONTAINER_ARGS, + model_serving_container_environment_variables=_TEST_MODEL_SERVING_CONTAINER_ENVIRONMENT_VARIABLES, + model_serving_container_ports=_TEST_MODEL_SERVING_CONTAINER_PORTS, + model_description=_TEST_MODEL_DESCRIPTION, + training_encryption_spec_key_name=_TEST_PIPELINE_ENCRYPTION_KEY_NAME, + model_encryption_spec_key_name=_TEST_MODEL_ENCRYPTION_KEY_NAME, ) model_from_job = job.run( + dataset=mock_tabular_dataset, base_output_dir=_TEST_BASE_OUTPUT_DIR, + bigquery_destination=_TEST_BIGQUERY_DESTINATION, args=_TEST_RUN_ARGS, environment_variables=_TEST_ENVIRONMENT_VARIABLES, - replica_count=1, machine_type=_TEST_MACHINE_TYPE, accelerator_type=_TEST_ACCELERATOR_TYPE, accelerator_count=_TEST_ACCELERATOR_COUNT, model_display_name=_TEST_MODEL_DISPLAY_NAME, - training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT, - validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, - test_fraction_split=_TEST_TEST_FRACTION_SPLIT, + predefined_split_column_name=_TEST_PREDEFINED_SPLIT_COLUMN_NAME, sync=sync, + create_request_timeout=None, ) if not sync: model_from_job.wait() - mock_python_package_to_gcs.assert_called_once_with( - gcs_staging_dir=_TEST_BUCKET_NAME, - project=_TEST_PROJECT, - credentials=initializer.global_config.credentials, - ) - true_args = _TEST_RUN_ARGS true_env = [ {"name": key, "value": value} @@ -1077,23 +1494,59 @@ def test_run_call_pipeline_service_create_with_no_dataset( "accelerator_type": _TEST_ACCELERATOR_TYPE, "accelerator_count": _TEST_ACCELERATOR_COUNT, }, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, "python_package_spec": { "executor_image_uri": _TEST_TRAINING_CONTAINER_IMAGE, - "python_module": source_utils._TrainingScriptPythonPackager.module_name, + "python_module": test_training_jobs._TEST_MODULE_NAME, "package_uris": [_TEST_OUTPUT_PYTHON_PACKAGE_PATH], "args": true_args, "env": true_env, }, } + env = [ + gca_env_var.EnvVar(name=str(key), value=str(value)) + for key, value in _TEST_MODEL_SERVING_CONTAINER_ENVIRONMENT_VARIABLES.items() + ] + + ports = [ + gca_model.Port(container_port=port) + for port in _TEST_MODEL_SERVING_CONTAINER_PORTS + ] + true_container_spec = gca_model.ModelContainerSpec( image_uri=_TEST_SERVING_CONTAINER_IMAGE, predict_route=_TEST_SERVING_CONTAINER_PREDICTION_ROUTE, health_route=_TEST_SERVING_CONTAINER_HEALTH_ROUTE, + command=_TEST_MODEL_SERVING_CONTAINER_COMMAND, + args=_TEST_MODEL_SERVING_CONTAINER_ARGS, + env=env, + ports=ports, ) true_managed_model = gca_model.Model( - display_name=_TEST_MODEL_DISPLAY_NAME, container_spec=true_container_spec + display_name=_TEST_MODEL_DISPLAY_NAME, + description=_TEST_MODEL_DESCRIPTION, + container_spec=true_container_spec, + predict_schemata=gca_model.PredictSchemata( + instance_schema_uri=_TEST_MODEL_INSTANCE_SCHEMA_URI, + parameters_schema_uri=_TEST_MODEL_PARAMETERS_SCHEMA_URI, + prediction_schema_uri=_TEST_MODEL_PREDICTION_SCHEMA_URI, + ), + encryption_spec=_TEST_MODEL_ENCRYPTION_SPEC, + ) + + true_input_data_config = gca_training_pipeline.InputDataConfig( + predefined_split=gca_training_pipeline.PredefinedSplit( + key=_TEST_PREDEFINED_SPLIT_COLUMN_NAME + ), + dataset_id=mock_tabular_dataset.name, + bigquery_destination=gca_io.BigQueryDestination( + output_uri=_TEST_BIGQUERY_DESTINATION + ), ) true_training_pipeline = gca_training_pipeline.TrainingPipeline( @@ -1109,27 +1562,45 @@ def test_run_call_pipeline_service_create_with_no_dataset( struct_pb2.Value(), ), model_to_upload=true_managed_model, + input_data_config=true_input_data_config, + encryption_spec=_TEST_PIPELINE_ENCRYPTION_SPEC, ) mock_pipeline_service_create.assert_called_once_with( parent=initializer.global_config.common_location_path(), training_pipeline=true_training_pipeline, + timeout=None, ) - assert job._gca_resource is mock_pipeline_service_get.return_value + assert job._gca_resource == make_training_pipeline( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) - mock_model_service_get.assert_called_once_with(name=_TEST_MODEL_NAME) + mock_model_service_get.assert_called_once_with( + name=_TEST_MODEL_NAME, retry=base._DEFAULT_RETRY + ) assert model_from_job._gca_resource is mock_model_service_get.return_value + assert job.get_model()._gca_resource is mock_model_service_get.return_value + + assert not job.has_failed + + assert job.state == gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.usefixtures( - "mock_pipeline_service_create_with_no_model_to_upload", - "mock_pipeline_service_get_with_no_model_to_upload", + "mock_pipeline_service_create", + "mock_pipeline_service_get", "mock_python_package_to_gcs", + "mock_model_service_get", ) @pytest.mark.parametrize("sync", [True, False]) - def test_run_returns_none_if_no_model_to_upload( - self, mock_tabular_dataset, sync, + def test_run_called_twice_raises( + self, + mock_tabular_dataset, + sync, ): aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME) @@ -1137,9 +1608,12 @@ def test_run_returns_none_if_no_model_to_upload( display_name=_TEST_DISPLAY_NAME, script_path=_TEST_LOCAL_SCRIPT_FILE_NAME, container_uri=_TEST_TRAINING_CONTAINER_IMAGE, + model_serving_container_image_uri=_TEST_SERVING_CONTAINER_IMAGE, + model_serving_container_predict_route=_TEST_SERVING_CONTAINER_PREDICTION_ROUTE, + model_serving_container_health_route=_TEST_SERVING_CONTAINER_HEALTH_ROUTE, ) - model = job.run( + job.run( dataset=mock_tabular_dataset, base_output_dir=_TEST_BASE_OUTPUT_DIR, args=_TEST_RUN_ARGS, @@ -1147,22 +1621,42 @@ def test_run_returns_none_if_no_model_to_upload( machine_type=_TEST_MACHINE_TYPE, accelerator_type=_TEST_ACCELERATOR_TYPE, accelerator_count=_TEST_ACCELERATOR_COUNT, + model_display_name=_TEST_MODEL_DISPLAY_NAME, training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT, validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, test_fraction_split=_TEST_TEST_FRACTION_SPLIT, sync=sync, + create_request_timeout=None, ) - assert model is None + with pytest.raises(RuntimeError): + job.run( + dataset=mock_tabular_dataset, + base_output_dir=_TEST_BASE_OUTPUT_DIR, + args=_TEST_RUN_ARGS, + replica_count=1, + machine_type=_TEST_MACHINE_TYPE, + accelerator_type=_TEST_ACCELERATOR_TYPE, + accelerator_count=_TEST_ACCELERATOR_COUNT, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT, + validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, + test_fraction_split=_TEST_TEST_FRACTION_SPLIT, + sync=sync, + create_request_timeout=None, + ) + + if not sync: + job.wait() - @pytest.mark.usefixtures( - "mock_pipeline_service_create_with_no_model_to_upload", - "mock_pipeline_service_get_with_no_model_to_upload", - "mock_python_package_to_gcs", - ) @pytest.mark.parametrize("sync", [True, False]) - def test_get_model_raises_if_no_model_to_upload( - self, mock_tabular_dataset, sync, + def test_run_with_invalid_accelerator_type_raises( + self, + mock_pipeline_service_create, + mock_python_package_to_gcs, + mock_tabular_dataset, + mock_model_service_get, + sync, ): aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME) @@ -1170,37 +1664,34 @@ def test_get_model_raises_if_no_model_to_upload( display_name=_TEST_DISPLAY_NAME, script_path=_TEST_LOCAL_SCRIPT_FILE_NAME, container_uri=_TEST_TRAINING_CONTAINER_IMAGE, + model_serving_container_image_uri=_TEST_SERVING_CONTAINER_IMAGE, + model_serving_container_predict_route=_TEST_SERVING_CONTAINER_PREDICTION_ROUTE, + model_serving_container_health_route=_TEST_SERVING_CONTAINER_HEALTH_ROUTE, ) - job.run( - dataset=mock_tabular_dataset, - base_output_dir=_TEST_BASE_OUTPUT_DIR, - args=_TEST_RUN_ARGS, - replica_count=1, - machine_type=_TEST_MACHINE_TYPE, - accelerator_type=_TEST_ACCELERATOR_TYPE, - accelerator_count=_TEST_ACCELERATOR_COUNT, - training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT, - validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, - test_fraction_split=_TEST_TEST_FRACTION_SPLIT, - sync=sync, - ) - - if not sync: - job.wait() - - with pytest.raises(RuntimeError): - job.get_model() + with pytest.raises(ValueError): + job.run( + dataset=mock_tabular_dataset, + base_output_dir=_TEST_BASE_OUTPUT_DIR, + args=_TEST_RUN_ARGS, + replica_count=1, + machine_type=_TEST_MACHINE_TYPE, + accelerator_type=_TEST_INVALID_ACCELERATOR_TYPE, + accelerator_count=_TEST_ACCELERATOR_COUNT, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + sync=sync, + create_request_timeout=None, + ) @pytest.mark.parametrize("sync", [True, False]) - def test_run_raises_if_pipeline_fails( + def test_run_with_two_splits_raises( self, - mock_pipeline_service_create_and_get_with_fail, + mock_pipeline_service_create, mock_python_package_to_gcs, mock_tabular_dataset, + mock_model_service_get, sync, ): - aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME) job = training_jobs.CustomTrainingJob( @@ -1209,29 +1700,29 @@ def test_run_raises_if_pipeline_fails( container_uri=_TEST_TRAINING_CONTAINER_IMAGE, ) - with pytest.raises(RuntimeError): + with pytest.raises(ValueError): job.run( dataset=mock_tabular_dataset, - base_output_dir=_TEST_BASE_OUTPUT_DIR, - args=_TEST_RUN_ARGS, replica_count=1, machine_type=_TEST_MACHINE_TYPE, - accelerator_type=_TEST_ACCELERATOR_TYPE, + accelerator_type=_TEST_INVALID_ACCELERATOR_TYPE, accelerator_count=_TEST_ACCELERATOR_COUNT, + predefined_split_column_name=_TEST_PREDEFINED_SPLIT_COLUMN_NAME, training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT, validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, test_fraction_split=_TEST_TEST_FRACTION_SPLIT, sync=sync, + create_request_timeout=None, ) - if not sync: - job.wait() - - with pytest.raises(RuntimeError): - job.get_model() - - def test_raises_before_run_is_called( - self, mock_pipeline_service_create, mock_python_package_to_gcs + @pytest.mark.parametrize("sync", [True, False]) + def test_run_with_incomplete_model_info_raises_with_model_to_upload( + self, + mock_pipeline_service_create, + mock_python_package_to_gcs, + mock_tabular_dataset, + mock_model_service_get, + sync, ): aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME) @@ -1239,38 +1730,31 @@ def test_raises_before_run_is_called( display_name=_TEST_DISPLAY_NAME, script_path=_TEST_LOCAL_SCRIPT_FILE_NAME, container_uri=_TEST_TRAINING_CONTAINER_IMAGE, - model_serving_container_image_uri=_TEST_SERVING_CONTAINER_IMAGE, - model_serving_container_predict_route=_TEST_SERVING_CONTAINER_PREDICTION_ROUTE, - model_serving_container_health_route=_TEST_SERVING_CONTAINER_HEALTH_ROUTE, ) with pytest.raises(RuntimeError): - job.get_model() - - with pytest.raises(RuntimeError): - job.has_failed - - with pytest.raises(RuntimeError): - job.state - - def test_run_raises_if_no_staging_bucket(self): - - aiplatform.init(project=_TEST_PROJECT) - - with pytest.raises(RuntimeError): - training_jobs.CustomTrainingJob( - display_name=_TEST_DISPLAY_NAME, - script_path=_TEST_LOCAL_SCRIPT_FILE_NAME, - container_uri=_TEST_TRAINING_CONTAINER_IMAGE, + job.run( + dataset=mock_tabular_dataset, + base_output_dir=_TEST_BASE_OUTPUT_DIR, + args=_TEST_RUN_ARGS, + replica_count=1, + machine_type=_TEST_MACHINE_TYPE, + accelerator_type=_TEST_ACCELERATOR_TYPE, + accelerator_count=_TEST_ACCELERATOR_COUNT, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT, + validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, + test_fraction_split=_TEST_TEST_FRACTION_SPLIT, + sync=sync, + create_request_timeout=None, ) @pytest.mark.parametrize("sync", [True, False]) - def test_run_call_pipeline_service_create_distributed_training( + def test_run_call_pipeline_service_create_with_no_dataset( self, mock_pipeline_service_create, mock_pipeline_service_get, mock_python_package_to_gcs, - mock_tabular_dataset, mock_model_service_get, sync, ): @@ -1287,17 +1771,12 @@ def test_run_call_pipeline_service_create_distributed_training( model_serving_container_image_uri=_TEST_SERVING_CONTAINER_IMAGE, model_serving_container_predict_route=_TEST_SERVING_CONTAINER_PREDICTION_ROUTE, model_serving_container_health_route=_TEST_SERVING_CONTAINER_HEALTH_ROUTE, - model_instance_schema_uri=_TEST_MODEL_INSTANCE_SCHEMA_URI, - model_parameters_schema_uri=_TEST_MODEL_PARAMETERS_SCHEMA_URI, - model_prediction_schema_uri=_TEST_MODEL_PREDICTION_SCHEMA_URI, ) model_from_job = job.run( - dataset=mock_tabular_dataset, base_output_dir=_TEST_BASE_OUTPUT_DIR, args=_TEST_RUN_ARGS, environment_variables=_TEST_ENVIRONMENT_VARIABLES, - replica_count=10, machine_type=_TEST_MACHINE_TYPE, accelerator_type=_TEST_ACCELERATOR_TYPE, accelerator_count=_TEST_ACCELERATOR_COUNT, @@ -1305,7 +1784,11 @@ def test_run_call_pipeline_service_create_distributed_training( training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT, validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, test_fraction_split=_TEST_TEST_FRACTION_SPLIT, + training_filter_split=_TEST_TRAINING_FILTER_SPLIT, + validation_filter_split=_TEST_VALIDATION_FILTER_SPLIT, + test_filter_split=_TEST_TEST_FILTER_SPLIT, sync=sync, + create_request_timeout=None, ) if not sync: @@ -1323,44 +1806,25 @@ def test_run_call_pipeline_service_create_distributed_training( for key, value in _TEST_ENVIRONMENT_VARIABLES.items() ] - true_worker_pool_spec = [ - { - "replica_count": 1, - "machine_spec": { - "machine_type": _TEST_MACHINE_TYPE, - "accelerator_type": _TEST_ACCELERATOR_TYPE, - "accelerator_count": _TEST_ACCELERATOR_COUNT, - }, - "python_package_spec": { - "executor_image_uri": _TEST_TRAINING_CONTAINER_IMAGE, - "python_module": source_utils._TrainingScriptPythonPackager.module_name, - "package_uris": [_TEST_OUTPUT_PYTHON_PACKAGE_PATH], - "args": true_args, - "env": true_env, - }, + true_worker_pool_spec = { + "replica_count": _TEST_REPLICA_COUNT, + "machine_spec": { + "machine_type": _TEST_MACHINE_TYPE, + "accelerator_type": _TEST_ACCELERATOR_TYPE, + "accelerator_count": _TEST_ACCELERATOR_COUNT, }, - { - "replica_count": 9, - "machine_spec": { - "machine_type": _TEST_MACHINE_TYPE, - "accelerator_type": _TEST_ACCELERATOR_TYPE, - "accelerator_count": _TEST_ACCELERATOR_COUNT, - }, - "python_package_spec": { - "executor_image_uri": _TEST_TRAINING_CONTAINER_IMAGE, - "python_module": source_utils._TrainingScriptPythonPackager.module_name, - "package_uris": [_TEST_OUTPUT_PYTHON_PACKAGE_PATH], - "args": true_args, - "env": true_env, - }, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, }, - ] - - true_fraction_split = gca_training_pipeline.FractionSplit( - training_fraction=_TEST_TRAINING_FRACTION_SPLIT, - validation_fraction=_TEST_VALIDATION_FRACTION_SPLIT, - test_fraction=_TEST_TEST_FRACTION_SPLIT, - ) + "python_package_spec": { + "executor_image_uri": _TEST_TRAINING_CONTAINER_IMAGE, + "python_module": test_training_jobs._TEST_MODULE_NAME, + "package_uris": [_TEST_OUTPUT_PYTHON_PACKAGE_PATH], + "args": true_args, + "env": true_env, + }, + } true_container_spec = gca_model.ModelContainerSpec( image_uri=_TEST_SERVING_CONTAINER_IMAGE, @@ -1369,21 +1833,7 @@ def test_run_call_pipeline_service_create_distributed_training( ) true_managed_model = gca_model.Model( - display_name=_TEST_MODEL_DISPLAY_NAME, - container_spec=true_container_spec, - predict_schemata=gca_model.PredictSchemata( - instance_schema_uri=_TEST_MODEL_INSTANCE_SCHEMA_URI, - parameters_schema_uri=_TEST_MODEL_PARAMETERS_SCHEMA_URI, - prediction_schema_uri=_TEST_MODEL_PREDICTION_SCHEMA_URI, - ), - ) - - true_input_data_config = gca_training_pipeline.InputDataConfig( - fraction_split=true_fraction_split, - dataset_id=mock_tabular_dataset.name, - gcs_destination=gca_io.GcsDestination( - output_uri_prefix=_TEST_BASE_OUTPUT_DIR - ), + display_name=_TEST_MODEL_DISPLAY_NAME, container_spec=true_container_spec ) true_training_pipeline = gca_training_pipeline.TrainingPipeline( @@ -1391,7 +1841,7 @@ def test_run_call_pipeline_service_create_distributed_training( training_task_definition=schema.training_job.definition.custom_task, training_task_inputs=json_format.ParseDict( { - "worker_pool_specs": true_worker_pool_spec, + "worker_pool_specs": [true_worker_pool_spec], "base_output_directory": { "output_uri_prefix": _TEST_BASE_OUTPUT_DIR }, @@ -1399,124 +1849,1031 @@ def test_run_call_pipeline_service_create_distributed_training( struct_pb2.Value(), ), model_to_upload=true_managed_model, - input_data_config=true_input_data_config, ) mock_pipeline_service_create.assert_called_once_with( parent=initializer.global_config.common_location_path(), training_pipeline=true_training_pipeline, + timeout=None, ) - assert job._gca_resource is mock_pipeline_service_get.return_value + assert job._gca_resource == make_training_pipeline( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) - mock_model_service_get.assert_called_once_with(name=_TEST_MODEL_NAME) + mock_model_service_get.assert_called_once_with( + name=_TEST_MODEL_NAME, retry=base._DEFAULT_RETRY + ) assert model_from_job._gca_resource is mock_model_service_get.return_value - assert job.get_model()._gca_resource is mock_model_service_get.return_value - - assert not job.has_failed + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.usefixtures( + "mock_pipeline_service_create_with_enable_web_access", + "mock_pipeline_service_get_with_enable_web_access", + "mock_get_backing_custom_job_with_enable_web_access", + "mock_python_package_to_gcs", + ) + @pytest.mark.parametrize("sync", [True, False]) + def test_run_call_pipeline_service_create_with_enable_web_access( + self, sync, caplog + ): - assert job.state == gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + caplog.set_level(logging.INFO) - @pytest.mark.usefixtures("get_training_job_custom_mock") - def test_get_training_job(self, get_training_job_custom_mock): - aiplatform.init(project=_TEST_PROJECT) - job = training_jobs.CustomTrainingJob.get(resource_name=_TEST_NAME) + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_BUCKET_NAME, + credentials=_TEST_CREDENTIALS, + ) - get_training_job_custom_mock.assert_called_once_with(name=_TEST_NAME) - assert isinstance(job, training_jobs.CustomTrainingJob) + job = training_jobs.CustomTrainingJob( + display_name=_TEST_DISPLAY_NAME, + script_path=_TEST_LOCAL_SCRIPT_FILE_NAME, + container_uri=_TEST_TRAINING_CONTAINER_IMAGE, + ) - @pytest.mark.usefixtures("get_training_job_custom_mock") - def test_get_training_job_wrong_job_type(self, get_training_job_custom_mock): - aiplatform.init(project=_TEST_PROJECT) + job.run( + base_output_dir=_TEST_BASE_OUTPUT_DIR, + args=_TEST_RUN_ARGS, + machine_type=_TEST_MACHINE_TYPE, + accelerator_type=_TEST_ACCELERATOR_TYPE, + accelerator_count=_TEST_ACCELERATOR_COUNT, + enable_web_access=_TEST_ENABLE_WEB_ACCESS, + sync=sync, + create_request_timeout=None, + ) - # The returned job is for a custom training task, - # but the calling type if of AutoMLImageTrainingJob. - # Hence, it should throw an error. - with pytest.raises(ValueError): - training_jobs.AutoMLImageTrainingJob.get(resource_name=_TEST_NAME) + if not sync: + job.wait() - @pytest.mark.usefixtures("get_training_job_custom_mock_no_model_to_upload") - def test_get_training_job_no_model_to_upload( - self, get_training_job_custom_mock_no_model_to_upload - ): - aiplatform.init(project=_TEST_PROJECT) + print(caplog.text) + assert "workerpool0-0" in caplog.text + assert job._gca_resource == make_training_pipeline_with_enable_web_access( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) - job = training_jobs.CustomTrainingJob.get(resource_name=_TEST_NAME) + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.usefixtures( + "mock_pipeline_service_create_with_scheduling", + "mock_pipeline_service_get_with_scheduling", + "mock_python_package_to_gcs", + ) + @pytest.mark.parametrize("sync", [True, False]) + def test_run_call_pipeline_service_create_with_scheduling(self, sync, caplog): + + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_BUCKET_NAME, + credentials=_TEST_CREDENTIALS, + ) + + job = training_jobs.CustomTrainingJob( + display_name=_TEST_DISPLAY_NAME, + script_path=_TEST_LOCAL_SCRIPT_FILE_NAME, + container_uri=_TEST_TRAINING_CONTAINER_IMAGE, + ) + + job.run( + base_output_dir=_TEST_BASE_OUTPUT_DIR, + args=_TEST_RUN_ARGS, + machine_type=_TEST_MACHINE_TYPE, + accelerator_type=_TEST_ACCELERATOR_TYPE, + accelerator_count=_TEST_ACCELERATOR_COUNT, + timeout=_TEST_TIMEOUT, + restart_job_on_worker_restart=_TEST_RESTART_JOB_ON_WORKER_RESTART, + sync=sync, + create_request_timeout=None, + ) + + if not sync: + job.wait() + + assert job._gca_resource == make_training_pipeline_with_scheduling( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) + + assert ( + job._gca_resource.state + == gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) + assert job._gca_resource.training_task_inputs["timeout"] == f"{_TEST_TIMEOUT}s" + assert ( + job._gca_resource.training_task_inputs["restart_job_on_worker_restart"] + == _TEST_RESTART_JOB_ON_WORKER_RESTART + ) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.usefixtures( + "mock_pipeline_service_create_with_no_model_to_upload", + "mock_pipeline_service_get_with_no_model_to_upload", + "mock_python_package_to_gcs", + ) + @pytest.mark.parametrize("sync", [True, False]) + def test_run_returns_none_if_no_model_to_upload( + self, + mock_tabular_dataset, + sync, + ): + aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME) + + job = training_jobs.CustomTrainingJob( + display_name=_TEST_DISPLAY_NAME, + script_path=_TEST_LOCAL_SCRIPT_FILE_NAME, + container_uri=_TEST_TRAINING_CONTAINER_IMAGE, + ) + + model = job.run( + dataset=mock_tabular_dataset, + base_output_dir=_TEST_BASE_OUTPUT_DIR, + args=_TEST_RUN_ARGS, + replica_count=1, + machine_type=_TEST_MACHINE_TYPE, + accelerator_type=_TEST_ACCELERATOR_TYPE, + accelerator_count=_TEST_ACCELERATOR_COUNT, + training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT, + validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, + test_fraction_split=_TEST_TEST_FRACTION_SPLIT, + sync=sync, + create_request_timeout=None, + ) + + assert model is None + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.usefixtures( + "mock_pipeline_service_create_with_no_model_to_upload", + "mock_pipeline_service_get_with_no_model_to_upload", + "mock_python_package_to_gcs", + ) + @pytest.mark.parametrize("sync", [True, False]) + def test_get_model_raises_if_no_model_to_upload( + self, + mock_tabular_dataset, + sync, + ): + aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME) + + job = training_jobs.CustomTrainingJob( + display_name=_TEST_DISPLAY_NAME, + script_path=_TEST_LOCAL_SCRIPT_FILE_NAME, + container_uri=_TEST_TRAINING_CONTAINER_IMAGE, + ) + + job.run( + dataset=mock_tabular_dataset, + base_output_dir=_TEST_BASE_OUTPUT_DIR, + args=_TEST_RUN_ARGS, + replica_count=1, + machine_type=_TEST_MACHINE_TYPE, + accelerator_type=_TEST_ACCELERATOR_TYPE, + accelerator_count=_TEST_ACCELERATOR_COUNT, + training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT, + validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, + test_fraction_split=_TEST_TEST_FRACTION_SPLIT, + sync=sync, + create_request_timeout=None, + ) + + if not sync: + job.wait() with pytest.raises(RuntimeError): - job.get_model(sync=False) + job.get_model() - @pytest.mark.usefixtures("get_training_job_tabular_mock") - def test_get_training_job_tabular(self, get_training_job_tabular_mock): - aiplatform.init(project=_TEST_PROJECT) + @pytest.mark.parametrize("sync", [True, False]) + def test_run_raises_if_pipeline_fails( + self, + mock_pipeline_service_create_and_get_with_fail, + mock_python_package_to_gcs, + mock_tabular_dataset, + sync, + ): - with pytest.raises(ValueError): - training_jobs.CustomTrainingJob.get(resource_name=_TEST_NAME) + aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME) - @pytest.mark.usefixtures("get_training_job_custom_mock") - def test_get_training_job_with_id_only(self, get_training_job_custom_mock): - aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) - training_jobs.CustomTrainingJob.get(resource_name=_TEST_ID) - get_training_job_custom_mock.assert_called_once_with(name=_TEST_NAME) + job = training_jobs.CustomTrainingJob( + display_name=_TEST_DISPLAY_NAME, + script_path=_TEST_LOCAL_SCRIPT_FILE_NAME, + container_uri=_TEST_TRAINING_CONTAINER_IMAGE, + ) - def test_get_training_job_with_id_only_with_project_and_location( - self, get_training_job_custom_mock + with pytest.raises(RuntimeError): + job.run( + dataset=mock_tabular_dataset, + base_output_dir=_TEST_BASE_OUTPUT_DIR, + args=_TEST_RUN_ARGS, + replica_count=1, + machine_type=_TEST_MACHINE_TYPE, + accelerator_type=_TEST_ACCELERATOR_TYPE, + accelerator_count=_TEST_ACCELERATOR_COUNT, + training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT, + validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, + test_fraction_split=_TEST_TEST_FRACTION_SPLIT, + sync=sync, + create_request_timeout=None, + ) + + if not sync: + job.wait() + + with pytest.raises(RuntimeError): + job.get_model() + + def test_raises_before_run_is_called( + self, mock_pipeline_service_create, mock_python_package_to_gcs ): - aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) - training_jobs.CustomTrainingJob.get( - resource_name=_TEST_ID, project=_TEST_PROJECT, location=_TEST_LOCATION + aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME) + + job = training_jobs.CustomTrainingJob( + display_name=_TEST_DISPLAY_NAME, + script_path=_TEST_LOCAL_SCRIPT_FILE_NAME, + container_uri=_TEST_TRAINING_CONTAINER_IMAGE, + model_serving_container_image_uri=_TEST_SERVING_CONTAINER_IMAGE, + model_serving_container_predict_route=_TEST_SERVING_CONTAINER_PREDICTION_ROUTE, + model_serving_container_health_route=_TEST_SERVING_CONTAINER_HEALTH_ROUTE, ) - get_training_job_custom_mock.assert_called_once_with(name=_TEST_NAME) - def test_get_training_job_with_project_and_location( - self, get_training_job_custom_mock + with pytest.raises(RuntimeError): + job.get_model() + + with pytest.raises(RuntimeError): + job.has_failed + + with pytest.raises(RuntimeError): + job.state + + def test_run_raises_if_no_staging_bucket(self): + + aiplatform.init(project=_TEST_PROJECT) + + with pytest.raises(RuntimeError): + training_jobs.CustomTrainingJob( + display_name=_TEST_DISPLAY_NAME, + script_path=_TEST_LOCAL_SCRIPT_FILE_NAME, + container_uri=_TEST_TRAINING_CONTAINER_IMAGE, + ) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + def test_run_call_pipeline_service_create_distributed_training( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + mock_python_package_to_gcs, + mock_tabular_dataset, + mock_model_service_get, + sync, ): - aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) - training_jobs.CustomTrainingJob.get( - resource_name=_TEST_NAME, project=_TEST_PROJECT, location=_TEST_LOCATION + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_BUCKET_NAME, + credentials=_TEST_CREDENTIALS, + ) + + job = training_jobs.CustomTrainingJob( + display_name=_TEST_DISPLAY_NAME, + script_path=_TEST_LOCAL_SCRIPT_FILE_NAME, + container_uri=_TEST_TRAINING_CONTAINER_IMAGE, + model_serving_container_image_uri=_TEST_SERVING_CONTAINER_IMAGE, + model_serving_container_predict_route=_TEST_SERVING_CONTAINER_PREDICTION_ROUTE, + model_serving_container_health_route=_TEST_SERVING_CONTAINER_HEALTH_ROUTE, + model_instance_schema_uri=_TEST_MODEL_INSTANCE_SCHEMA_URI, + model_parameters_schema_uri=_TEST_MODEL_PARAMETERS_SCHEMA_URI, + model_prediction_schema_uri=_TEST_MODEL_PREDICTION_SCHEMA_URI, + ) + + model_from_job = job.run( + dataset=mock_tabular_dataset, + base_output_dir=_TEST_BASE_OUTPUT_DIR, + args=_TEST_RUN_ARGS, + environment_variables=_TEST_ENVIRONMENT_VARIABLES, + replica_count=10, + machine_type=_TEST_MACHINE_TYPE, + accelerator_type=_TEST_ACCELERATOR_TYPE, + accelerator_count=_TEST_ACCELERATOR_COUNT, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + sync=sync, + create_request_timeout=None, + ) + + if not sync: + model_from_job.wait() + + mock_python_package_to_gcs.assert_called_once_with( + gcs_staging_dir=_TEST_BUCKET_NAME, + project=_TEST_PROJECT, + credentials=initializer.global_config.credentials, + ) + + true_args = _TEST_RUN_ARGS + true_env = [ + {"name": key, "value": value} + for key, value in _TEST_ENVIRONMENT_VARIABLES.items() + ] + + true_worker_pool_spec = [ + { + "replica_count": 1, + "machine_spec": { + "machine_type": _TEST_MACHINE_TYPE, + "accelerator_type": _TEST_ACCELERATOR_TYPE, + "accelerator_count": _TEST_ACCELERATOR_COUNT, + }, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, + "python_package_spec": { + "executor_image_uri": _TEST_TRAINING_CONTAINER_IMAGE, + "python_module": test_training_jobs._TEST_MODULE_NAME, + "package_uris": [_TEST_OUTPUT_PYTHON_PACKAGE_PATH], + "args": true_args, + "env": true_env, + }, + }, + { + "replica_count": 9, + "machine_spec": { + "machine_type": _TEST_MACHINE_TYPE, + "accelerator_type": _TEST_ACCELERATOR_TYPE, + "accelerator_count": _TEST_ACCELERATOR_COUNT, + }, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, + "python_package_spec": { + "executor_image_uri": _TEST_TRAINING_CONTAINER_IMAGE, + "python_module": _TEST_MODULE_NAME, + "package_uris": [_TEST_OUTPUT_PYTHON_PACKAGE_PATH], + "args": true_args, + "env": true_env, + }, + }, + ] + + true_container_spec = gca_model.ModelContainerSpec( + image_uri=_TEST_SERVING_CONTAINER_IMAGE, + predict_route=_TEST_SERVING_CONTAINER_PREDICTION_ROUTE, + health_route=_TEST_SERVING_CONTAINER_HEALTH_ROUTE, + ) + + true_managed_model = gca_model.Model( + display_name=_TEST_MODEL_DISPLAY_NAME, + container_spec=true_container_spec, + predict_schemata=gca_model.PredictSchemata( + instance_schema_uri=_TEST_MODEL_INSTANCE_SCHEMA_URI, + parameters_schema_uri=_TEST_MODEL_PARAMETERS_SCHEMA_URI, + prediction_schema_uri=_TEST_MODEL_PREDICTION_SCHEMA_URI, + ), + ) + + true_input_data_config = gca_training_pipeline.InputDataConfig( + dataset_id=mock_tabular_dataset.name, + gcs_destination=gca_io.GcsDestination( + output_uri_prefix=_TEST_BASE_OUTPUT_DIR + ), + ) + + true_training_pipeline = gca_training_pipeline.TrainingPipeline( + display_name=_TEST_DISPLAY_NAME, + training_task_definition=schema.training_job.definition.custom_task, + training_task_inputs=json_format.ParseDict( + { + "worker_pool_specs": true_worker_pool_spec, + "base_output_directory": { + "output_uri_prefix": _TEST_BASE_OUTPUT_DIR + }, + }, + struct_pb2.Value(), + ), + model_to_upload=true_managed_model, + input_data_config=true_input_data_config, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + training_pipeline=true_training_pipeline, + timeout=None, + ) + + assert job._gca_resource == make_training_pipeline( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) + + mock_model_service_get.assert_called_once_with( + name=_TEST_MODEL_NAME, retry=base._DEFAULT_RETRY + ) + + assert model_from_job._gca_resource is mock_model_service_get.return_value + + assert job.get_model()._gca_resource is mock_model_service_get.return_value + + assert not job.has_failed + + assert job.state == gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + def test_run_call_pipeline_service_create_distributed_training_with_reduction_server( + self, + mock_pipeline_service_create_with_no_model_to_upload, + mock_pipeline_service_get_with_no_model_to_upload, + mock_python_package_to_gcs, + sync, + ): + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_BUCKET_NAME, + credentials=_TEST_CREDENTIALS, + ) + + job = training_jobs.CustomTrainingJob( + display_name=_TEST_DISPLAY_NAME, + script_path=_TEST_LOCAL_SCRIPT_FILE_NAME, + container_uri=_TEST_TRAINING_CONTAINER_IMAGE, + ) + + job.run( + base_output_dir=_TEST_BASE_OUTPUT_DIR, + args=_TEST_RUN_ARGS, + environment_variables=_TEST_ENVIRONMENT_VARIABLES, + replica_count=10, + machine_type=_TEST_MACHINE_TYPE, + accelerator_type=_TEST_ACCELERATOR_TYPE, + accelerator_count=_TEST_ACCELERATOR_COUNT, + reduction_server_replica_count=_TEST_REDUCTION_SERVER_REPLICA_COUNT, + reduction_server_machine_type=_TEST_REDUCTION_SERVER_MACHINE_TYPE, + reduction_server_container_uri=_TEST_REDUCTION_SERVER_CONTAINER_URI, + sync=sync, + create_request_timeout=None, + ) + + if not sync: + job.wait() + + mock_python_package_to_gcs.assert_called_once_with( + gcs_staging_dir=_TEST_BUCKET_NAME, + project=_TEST_PROJECT, + credentials=initializer.global_config.credentials, + ) + + true_args = _TEST_RUN_ARGS + true_env = [ + {"name": key, "value": value} + for key, value in _TEST_ENVIRONMENT_VARIABLES.items() + ] + + true_worker_pool_spec = [ + { + "replica_count": 1, + "machine_spec": { + "machine_type": _TEST_MACHINE_TYPE, + "accelerator_type": _TEST_ACCELERATOR_TYPE, + "accelerator_count": _TEST_ACCELERATOR_COUNT, + }, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, + "python_package_spec": { + "executor_image_uri": _TEST_TRAINING_CONTAINER_IMAGE, + "python_module": _TEST_MODULE_NAME, + "package_uris": [_TEST_OUTPUT_PYTHON_PACKAGE_PATH], + "args": true_args, + "env": true_env, + }, + }, + { + "replica_count": 9, + "machine_spec": { + "machine_type": _TEST_MACHINE_TYPE, + "accelerator_type": _TEST_ACCELERATOR_TYPE, + "accelerator_count": _TEST_ACCELERATOR_COUNT, + }, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, + "python_package_spec": { + "executor_image_uri": _TEST_TRAINING_CONTAINER_IMAGE, + "python_module": test_training_jobs._TEST_MODULE_NAME, + "package_uris": [_TEST_OUTPUT_PYTHON_PACKAGE_PATH], + "args": true_args, + "env": true_env, + }, + }, + { + "replica_count": _TEST_REDUCTION_SERVER_REPLICA_COUNT, + "machine_spec": {"machine_type": _TEST_REDUCTION_SERVER_MACHINE_TYPE}, + "container_spec": {"image_uri": _TEST_REDUCTION_SERVER_CONTAINER_URI}, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, + }, + ] + + true_training_pipeline = gca_training_pipeline.TrainingPipeline( + display_name=_TEST_DISPLAY_NAME, + training_task_definition=schema.training_job.definition.custom_task, + training_task_inputs=json_format.ParseDict( + { + "worker_pool_specs": true_worker_pool_spec, + "base_output_directory": { + "output_uri_prefix": _TEST_BASE_OUTPUT_DIR + }, + }, + struct_pb2.Value(), + ), + ) + + mock_pipeline_service_create_with_no_model_to_upload.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + training_pipeline=true_training_pipeline, + timeout=None, + ) + + assert job._gca_resource == make_training_pipeline_with_no_model_upload( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) + + assert not job.has_failed + + assert job.state == gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + + @pytest.mark.usefixtures("get_training_job_custom_mock") + def test_get_training_job(self, get_training_job_custom_mock): + aiplatform.init(project=_TEST_PROJECT) + job = training_jobs.CustomTrainingJob.get(resource_name=_TEST_NAME) + + get_training_job_custom_mock.assert_called_once_with( + name=_TEST_NAME, retry=base._DEFAULT_RETRY + ) + assert isinstance(job, training_jobs.CustomTrainingJob) + + @pytest.mark.usefixtures("get_training_job_custom_mock") + def test_get_training_job_wrong_job_type(self, get_training_job_custom_mock): + aiplatform.init(project=_TEST_PROJECT) + + # The returned job is for a custom training task, + # but the calling type if of AutoMLImageTrainingJob. + # Hence, it should throw an error. + with pytest.raises(ValueError): + training_jobs.AutoMLImageTrainingJob.get(resource_name=_TEST_NAME) + + @pytest.mark.usefixtures("get_training_job_custom_mock_no_model_to_upload") + def test_get_training_job_no_model_to_upload( + self, get_training_job_custom_mock_no_model_to_upload + ): + aiplatform.init(project=_TEST_PROJECT) + + job = training_jobs.CustomTrainingJob.get(resource_name=_TEST_NAME) + + with pytest.raises(RuntimeError): + job.get_model(sync=False) + + @pytest.mark.usefixtures("get_training_job_tabular_mock") + def test_get_training_job_tabular(self, get_training_job_tabular_mock): + aiplatform.init(project=_TEST_PROJECT) + + with pytest.raises(ValueError): + training_jobs.CustomTrainingJob.get(resource_name=_TEST_NAME) + + @pytest.mark.usefixtures("get_training_job_custom_mock") + def test_get_training_job_with_id_only(self, get_training_job_custom_mock): + aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) + training_jobs.CustomTrainingJob.get(resource_name=_TEST_ID) + get_training_job_custom_mock.assert_called_once_with( + name=_TEST_NAME, retry=base._DEFAULT_RETRY + ) + + def test_get_training_job_with_id_only_with_project_and_location( + self, get_training_job_custom_mock + ): + aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) + training_jobs.CustomTrainingJob.get( + resource_name=_TEST_ID, project=_TEST_PROJECT, location=_TEST_LOCATION + ) + get_training_job_custom_mock.assert_called_once_with( + name=_TEST_NAME, retry=base._DEFAULT_RETRY + ) + + def test_get_training_job_with_project_and_location( + self, get_training_job_custom_mock + ): + aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) + training_jobs.CustomTrainingJob.get( + resource_name=_TEST_NAME, project=_TEST_PROJECT, location=_TEST_LOCATION + ) + get_training_job_custom_mock.assert_called_once_with( + name=_TEST_NAME, retry=base._DEFAULT_RETRY + ) + + def test_get_training_job_with_alt_project_and_location( + self, get_training_job_custom_mock + ): + aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) + training_jobs.CustomTrainingJob.get( + resource_name=_TEST_NAME, project=_TEST_ALT_PROJECT, location=_TEST_LOCATION + ) + get_training_job_custom_mock.assert_called_once_with( + name=_TEST_NAME, retry=base._DEFAULT_RETRY + ) + + def test_get_training_job_with_project_and_alt_location(self): + aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) + with pytest.raises(RuntimeError): + training_jobs.CustomTrainingJob.get( + resource_name=_TEST_NAME, + project=_TEST_PROJECT, + location=_TEST_ALT_LOCATION, + ) + + def test_unique_supported_training_schemas(self): + """Ensure that the `_supported_training_schemas` across AutoML training + classes and CustomTrainingJob contain unique values.""" + + schemas = [ + schema + for c in aiplatform.training_jobs._TrainingJob.__subclasses__() + for schema in c._supported_training_schemas + if c.__name__.startswith("AutoML") + ] + + schemas.extend( + aiplatform.training_jobs.CustomTrainingJob._supported_training_schemas + ) + + # Ensure all schemas across classes are unique + assert len(set(schemas)) == len(schemas) + + @pytest.mark.usefixtures("get_training_job_tabular_mock") + def test_get_and_return_subclass_automl(self): + subcls = aiplatform.training_jobs._TrainingJob._get_and_return_subclass( + resource_name=_TEST_PIPELINE_RESOURCE_NAME + ) + + assert isinstance(subcls, aiplatform.training_jobs.AutoMLTabularTrainingJob) + + @pytest.mark.usefixtures("get_training_job_custom_mock") + def test_get_and_return_subclass_custom(self): + subcls = aiplatform.training_jobs._TrainingJob._get_and_return_subclass( + resource_name=_TEST_PIPELINE_RESOURCE_NAME + ) + + assert isinstance(subcls, aiplatform.training_jobs.CustomTrainingJob) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + def test_run_call_pipeline_service_create_with_nontabular_dataset_without_model_display_name_nor_model_labels( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + mock_python_package_to_gcs, + mock_nontabular_dataset, + mock_model_service_get, + sync, + ): + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_BUCKET_NAME, + credentials=_TEST_CREDENTIALS, + ) + + job = training_jobs.CustomTrainingJob( + display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, + script_path=_TEST_LOCAL_SCRIPT_FILE_NAME, + container_uri=_TEST_TRAINING_CONTAINER_IMAGE, + model_serving_container_image_uri=_TEST_SERVING_CONTAINER_IMAGE, + model_serving_container_predict_route=_TEST_SERVING_CONTAINER_PREDICTION_ROUTE, + model_serving_container_health_route=_TEST_SERVING_CONTAINER_HEALTH_ROUTE, + model_instance_schema_uri=_TEST_MODEL_INSTANCE_SCHEMA_URI, + model_parameters_schema_uri=_TEST_MODEL_PARAMETERS_SCHEMA_URI, + model_prediction_schema_uri=_TEST_MODEL_PREDICTION_SCHEMA_URI, + model_serving_container_command=_TEST_MODEL_SERVING_CONTAINER_COMMAND, + model_serving_container_args=_TEST_MODEL_SERVING_CONTAINER_ARGS, + model_serving_container_environment_variables=_TEST_MODEL_SERVING_CONTAINER_ENVIRONMENT_VARIABLES, + model_serving_container_ports=_TEST_MODEL_SERVING_CONTAINER_PORTS, + model_description=_TEST_MODEL_DESCRIPTION, + ) + + model_from_job = job.run( + dataset=mock_nontabular_dataset, + annotation_schema_uri=_TEST_ANNOTATION_SCHEMA_URI, + base_output_dir=_TEST_BASE_OUTPUT_DIR, + args=_TEST_RUN_ARGS, + machine_type=_TEST_MACHINE_TYPE, + accelerator_type=_TEST_ACCELERATOR_TYPE, + accelerator_count=_TEST_ACCELERATOR_COUNT, + training_filter_split=_TEST_TRAINING_FILTER_SPLIT, + validation_filter_split=_TEST_VALIDATION_FILTER_SPLIT, + test_filter_split=_TEST_TEST_FILTER_SPLIT, + sync=sync, + create_request_timeout=None, + ) + + if not sync: + model_from_job.wait() + + mock_python_package_to_gcs.assert_called_once_with( + gcs_staging_dir=_TEST_BUCKET_NAME, + project=_TEST_PROJECT, + credentials=initializer.global_config.credentials, + ) + + true_args = _TEST_RUN_ARGS + + true_worker_pool_spec = { + "replica_count": _TEST_REPLICA_COUNT, + "machine_spec": { + "machine_type": _TEST_MACHINE_TYPE, + "accelerator_type": _TEST_ACCELERATOR_TYPE, + "accelerator_count": _TEST_ACCELERATOR_COUNT, + }, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, + "python_package_spec": { + "executor_image_uri": _TEST_TRAINING_CONTAINER_IMAGE, + "python_module": test_training_jobs._TEST_MODULE_NAME, + "package_uris": [_TEST_OUTPUT_PYTHON_PACKAGE_PATH], + "args": true_args, + }, + } + + true_filter_split = gca_training_pipeline.FilterSplit( + training_filter=_TEST_TRAINING_FILTER_SPLIT, + validation_filter=_TEST_VALIDATION_FILTER_SPLIT, + test_filter=_TEST_TEST_FILTER_SPLIT, + ) + + env = [ + gca_env_var.EnvVar(name=str(key), value=str(value)) + for key, value in _TEST_MODEL_SERVING_CONTAINER_ENVIRONMENT_VARIABLES.items() + ] + + ports = [ + gca_model.Port(container_port=port) + for port in _TEST_MODEL_SERVING_CONTAINER_PORTS + ] + + true_container_spec = gca_model.ModelContainerSpec( + image_uri=_TEST_SERVING_CONTAINER_IMAGE, + predict_route=_TEST_SERVING_CONTAINER_PREDICTION_ROUTE, + health_route=_TEST_SERVING_CONTAINER_HEALTH_ROUTE, + command=_TEST_MODEL_SERVING_CONTAINER_COMMAND, + args=_TEST_MODEL_SERVING_CONTAINER_ARGS, + env=env, + ports=ports, + ) + + true_managed_model = gca_model.Model( + display_name=_TEST_DISPLAY_NAME + "-model", + labels=_TEST_LABELS, + description=_TEST_MODEL_DESCRIPTION, + container_spec=true_container_spec, + predict_schemata=gca_model.PredictSchemata( + instance_schema_uri=_TEST_MODEL_INSTANCE_SCHEMA_URI, + parameters_schema_uri=_TEST_MODEL_PARAMETERS_SCHEMA_URI, + prediction_schema_uri=_TEST_MODEL_PREDICTION_SCHEMA_URI, + ), + ) + + true_input_data_config = gca_training_pipeline.InputDataConfig( + filter_split=true_filter_split, + dataset_id=mock_nontabular_dataset.name, + annotation_schema_uri=_TEST_ANNOTATION_SCHEMA_URI, + gcs_destination=gca_io.GcsDestination( + output_uri_prefix=_TEST_BASE_OUTPUT_DIR + ), + ) + + true_training_pipeline = gca_training_pipeline.TrainingPipeline( + display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, + training_task_definition=schema.training_job.definition.custom_task, + training_task_inputs=json_format.ParseDict( + { + "worker_pool_specs": [true_worker_pool_spec], + "base_output_directory": { + "output_uri_prefix": _TEST_BASE_OUTPUT_DIR + }, + }, + struct_pb2.Value(), + ), + model_to_upload=true_managed_model, + input_data_config=true_input_data_config, + ) + + mock_pipeline_service_create.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + training_pipeline=true_training_pipeline, + timeout=None, + ) + + assert job._gca_resource == make_training_pipeline( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) + + mock_model_service_get.assert_called_once_with( + name=_TEST_MODEL_NAME, retry=base._DEFAULT_RETRY + ) + + assert model_from_job._gca_resource is mock_model_service_get.return_value + + assert job.get_model()._gca_resource is mock_model_service_get.return_value + + assert not job.has_failed + + assert job.state == gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + + def test_run_call_pipeline_service_create_with_nontabular_dataset_raises_if_annotation_schema_uri( + self, + mock_nontabular_dataset, + ): + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_BUCKET_NAME, + ) + + job = training_jobs.CustomTrainingJob( + display_name=_TEST_DISPLAY_NAME, + script_path=_TEST_LOCAL_SCRIPT_FILE_NAME, + container_uri=_TEST_TRAINING_CONTAINER_IMAGE, + model_serving_container_image_uri=_TEST_SERVING_CONTAINER_IMAGE, + model_serving_container_predict_route=_TEST_SERVING_CONTAINER_PREDICTION_ROUTE, + model_serving_container_health_route=_TEST_SERVING_CONTAINER_HEALTH_ROUTE, + model_instance_schema_uri=_TEST_MODEL_INSTANCE_SCHEMA_URI, + model_parameters_schema_uri=_TEST_MODEL_PARAMETERS_SCHEMA_URI, + model_prediction_schema_uri=_TEST_MODEL_PREDICTION_SCHEMA_URI, + model_serving_container_command=_TEST_MODEL_SERVING_CONTAINER_COMMAND, + model_serving_container_args=_TEST_MODEL_SERVING_CONTAINER_ARGS, + model_serving_container_environment_variables=_TEST_MODEL_SERVING_CONTAINER_ENVIRONMENT_VARIABLES, + model_serving_container_ports=_TEST_MODEL_SERVING_CONTAINER_PORTS, + model_description=_TEST_MODEL_DESCRIPTION, + ) + + with pytest.raises(Exception): + job.run( + dataset=mock_nontabular_dataset, + base_output_dir=_TEST_BASE_OUTPUT_DIR, + args=_TEST_RUN_ARGS, + replica_count=1, + machine_type=_TEST_MACHINE_TYPE, + accelerator_type=_TEST_ACCELERATOR_TYPE, + accelerator_count=_TEST_ACCELERATOR_COUNT, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + create_request_timeout=None, + ) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.usefixtures( + "mock_pipeline_service_create", + "mock_pipeline_service_get", + "mock_python_package_to_gcs", + "mock_model_service_get", + ) + def test_cancel_training_job(self, mock_pipeline_service_cancel): + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_BUCKET_NAME, + ) + + job = training_jobs.CustomTrainingJob( + display_name=_TEST_DISPLAY_NAME, + script_path=_TEST_LOCAL_SCRIPT_FILE_NAME, + container_uri=_TEST_TRAINING_CONTAINER_IMAGE, + ) + + job.run() + job.cancel() + + mock_pipeline_service_cancel.assert_called_once_with( + name=_TEST_PIPELINE_RESOURCE_NAME + ) + + @pytest.mark.usefixtures( + "mock_pipeline_service_create", + "mock_python_package_to_gcs", + "mock_model_service_get", + ) + def test_cancel_training_job_without_running(self, mock_pipeline_service_cancel): + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_BUCKET_NAME, + ) + + job = training_jobs.CustomTrainingJob( + display_name=_TEST_DISPLAY_NAME, + script_path=_TEST_LOCAL_SCRIPT_FILE_NAME, + container_uri=_TEST_TRAINING_CONTAINER_IMAGE, + ) + + with pytest.raises(RuntimeError) as e: + job.cancel() + + assert e.match(regexp=r"TrainingJob has not been launched") + + +@pytest.mark.usefixtures("google_auth_mock") +class TestCustomContainerTrainingJob: + def setup_method(self): + importlib.reload(initializer) + importlib.reload(aiplatform) + + def teardown_method(self): + initializer.global_pool.shutdown(wait=True) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + def test_custom_container_training_tabular_done( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + mock_tabular_dataset, + mock_model_service_get, + ): + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_BUCKET_NAME, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) + + job = training_jobs.CustomContainerTrainingJob( + display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, + container_uri=_TEST_TRAINING_CONTAINER_IMAGE, + command=_TEST_TRAINING_CONTAINER_CMD, + model_serving_container_image_uri=_TEST_SERVING_CONTAINER_IMAGE, + model_serving_container_predict_route=_TEST_SERVING_CONTAINER_PREDICTION_ROUTE, + model_serving_container_health_route=_TEST_SERVING_CONTAINER_HEALTH_ROUTE, + model_instance_schema_uri=_TEST_MODEL_INSTANCE_SCHEMA_URI, + model_parameters_schema_uri=_TEST_MODEL_PARAMETERS_SCHEMA_URI, + model_prediction_schema_uri=_TEST_MODEL_PREDICTION_SCHEMA_URI, + model_serving_container_command=_TEST_MODEL_SERVING_CONTAINER_COMMAND, + model_serving_container_args=_TEST_MODEL_SERVING_CONTAINER_ARGS, + model_serving_container_environment_variables=_TEST_MODEL_SERVING_CONTAINER_ENVIRONMENT_VARIABLES, + model_serving_container_ports=_TEST_MODEL_SERVING_CONTAINER_PORTS, + model_description=_TEST_MODEL_DESCRIPTION, ) - get_training_job_custom_mock.assert_called_once_with(name=_TEST_NAME) - def test_get_training_job_with_alt_project_and_location( - self, get_training_job_custom_mock - ): - aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) - training_jobs.CustomTrainingJob.get( - resource_name=_TEST_NAME, project=_TEST_ALT_PROJECT, location=_TEST_LOCATION + job.run( + dataset=mock_tabular_dataset, + base_output_dir=_TEST_BASE_OUTPUT_DIR, + args=_TEST_RUN_ARGS, + environment_variables=_TEST_ENVIRONMENT_VARIABLES, + machine_type=_TEST_MACHINE_TYPE, + accelerator_type=_TEST_ACCELERATOR_TYPE, + accelerator_count=_TEST_ACCELERATOR_COUNT, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + model_labels=_TEST_MODEL_LABELS, + predefined_split_column_name=_TEST_PREDEFINED_SPLIT_COLUMN_NAME, + service_account=_TEST_SERVICE_ACCOUNT, + tensorboard=_TEST_TENSORBOARD_RESOURCE_NAME, + sync=False, + create_request_timeout=None, ) - get_training_job_custom_mock.assert_called_once_with(name=_TEST_NAME) - def test_get_training_job_with_project_and_alt_location(self): - aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) - with pytest.raises(RuntimeError): - training_jobs.CustomTrainingJob.get( - resource_name=_TEST_NAME, - project=_TEST_PROJECT, - location=_TEST_ALT_LOCATION, - ) + assert job.done() is False + + job.wait() + + assert job.done() is True + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) - def test_run_call_pipeline_service_create_with_nontabular_dataset( + def test_run_call_pipeline_service_create_with_tabular_dataset( self, mock_pipeline_service_create, mock_pipeline_service_get, - mock_python_package_to_gcs, - mock_nontabular_dataset, + mock_tabular_dataset, mock_model_service_get, sync, ): aiplatform.init( project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME, - credentials=_TEST_CREDENTIALS, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, ) - job = training_jobs.CustomTrainingJob( + job = training_jobs.CustomContainerTrainingJob( display_name=_TEST_DISPLAY_NAME, - script_path=_TEST_LOCAL_SCRIPT_FILE_NAME, + labels=_TEST_LABELS, container_uri=_TEST_TRAINING_CONTAINER_IMAGE, + command=_TEST_TRAINING_CONTAINER_CMD, model_serving_container_image_uri=_TEST_SERVING_CONTAINER_IMAGE, model_serving_container_predict_route=_TEST_SERVING_CONTAINER_PREDICTION_ROUTE, model_serving_container_health_route=_TEST_SERVING_CONTAINER_HEALTH_ROUTE, @@ -1531,28 +2888,30 @@ def test_run_call_pipeline_service_create_with_nontabular_dataset( ) model_from_job = job.run( - dataset=mock_nontabular_dataset, - annotation_schema_uri=_TEST_ANNOTATION_SCHEMA_URI, + dataset=mock_tabular_dataset, base_output_dir=_TEST_BASE_OUTPUT_DIR, args=_TEST_RUN_ARGS, - replica_count=1, + environment_variables=_TEST_ENVIRONMENT_VARIABLES, machine_type=_TEST_MACHINE_TYPE, accelerator_type=_TEST_ACCELERATOR_TYPE, accelerator_count=_TEST_ACCELERATOR_COUNT, model_display_name=_TEST_MODEL_DISPLAY_NAME, + model_labels=_TEST_MODEL_LABELS, + predefined_split_column_name=_TEST_PREDEFINED_SPLIT_COLUMN_NAME, + service_account=_TEST_SERVICE_ACCOUNT, + tensorboard=_TEST_TENSORBOARD_RESOURCE_NAME, sync=sync, + create_request_timeout=None, ) if not sync: model_from_job.wait() - mock_python_package_to_gcs.assert_called_once_with( - gcs_staging_dir=_TEST_BUCKET_NAME, - project=_TEST_PROJECT, - credentials=initializer.global_config.credentials, - ) - true_args = _TEST_RUN_ARGS + true_env = [ + {"name": key, "value": value} + for key, value in _TEST_ENVIRONMENT_VARIABLES.items() + ] true_worker_pool_spec = { "replica_count": _TEST_REPLICA_COUNT, @@ -1561,20 +2920,18 @@ def test_run_call_pipeline_service_create_with_nontabular_dataset( "accelerator_type": _TEST_ACCELERATOR_TYPE, "accelerator_count": _TEST_ACCELERATOR_COUNT, }, - "python_package_spec": { - "executor_image_uri": _TEST_TRAINING_CONTAINER_IMAGE, - "python_module": source_utils._TrainingScriptPythonPackager.module_name, - "package_uris": [_TEST_OUTPUT_PYTHON_PACKAGE_PATH], + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, + "containerSpec": { + "imageUri": _TEST_TRAINING_CONTAINER_IMAGE, + "command": _TEST_TRAINING_CONTAINER_CMD, "args": true_args, + "env": true_env, }, } - true_fraction_split = gca_training_pipeline.FractionSplit( - training_fraction=_TEST_DEFAULT_TRAINING_FRACTION_SPLIT, - validation_fraction=_TEST_DEFAULT_VALIDATION_FRACTION_SPLIT, - test_fraction=_TEST_DEFAULT_TEST_FRACTION_SPLIT, - ) - env = [ gca_env_var.EnvVar(name=str(key), value=str(value)) for key, value in _TEST_MODEL_SERVING_CONTAINER_ENVIRONMENT_VARIABLES.items() @@ -1597,6 +2954,7 @@ def test_run_call_pipeline_service_create_with_nontabular_dataset( true_managed_model = gca_model.Model( display_name=_TEST_MODEL_DISPLAY_NAME, + labels=_TEST_MODEL_LABELS, description=_TEST_MODEL_DESCRIPTION, container_spec=true_container_spec, predict_schemata=gca_model.PredictSchemata( @@ -1604,12 +2962,14 @@ def test_run_call_pipeline_service_create_with_nontabular_dataset( parameters_schema_uri=_TEST_MODEL_PARAMETERS_SCHEMA_URI, prediction_schema_uri=_TEST_MODEL_PREDICTION_SCHEMA_URI, ), + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, ) true_input_data_config = gca_training_pipeline.InputDataConfig( - fraction_split=true_fraction_split, - dataset_id=mock_nontabular_dataset.name, - annotation_schema_uri=_TEST_ANNOTATION_SCHEMA_URI, + predefined_split=gca_training_pipeline.PredefinedSplit( + key=_TEST_PREDEFINED_SPLIT_COLUMN_NAME + ), + dataset_id=mock_tabular_dataset.name, gcs_destination=gca_io.GcsDestination( output_uri_prefix=_TEST_BASE_OUTPUT_DIR ), @@ -1617,6 +2977,7 @@ def test_run_call_pipeline_service_create_with_nontabular_dataset( true_training_pipeline = gca_training_pipeline.TrainingPipeline( display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, training_task_definition=schema.training_job.definition.custom_task, training_task_inputs=json_format.ParseDict( { @@ -1624,21 +2985,29 @@ def test_run_call_pipeline_service_create_with_nontabular_dataset( "base_output_directory": { "output_uri_prefix": _TEST_BASE_OUTPUT_DIR }, + "service_account": _TEST_SERVICE_ACCOUNT, + "tensorboard": _TEST_TENSORBOARD_RESOURCE_NAME, }, struct_pb2.Value(), ), model_to_upload=true_managed_model, input_data_config=true_input_data_config, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, ) mock_pipeline_service_create.assert_called_once_with( parent=initializer.global_config.common_location_path(), training_pipeline=true_training_pipeline, + timeout=None, ) - assert job._gca_resource is mock_pipeline_service_get.return_value + assert job._gca_resource == make_training_pipeline( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) - mock_model_service_get.assert_called_once_with(name=_TEST_MODEL_NAME) + mock_model_service_get.assert_called_once_with( + name=_TEST_MODEL_NAME, retry=base._DEFAULT_RETRY + ) assert model_from_job._gca_resource is mock_model_service_get.return_value @@ -1648,17 +3017,30 @@ def test_run_call_pipeline_service_create_with_nontabular_dataset( assert job.state == gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED - def test_run_call_pipeline_service_create_with_nontabular_dataset_raises_if_annotation_schema_uri( - self, mock_nontabular_dataset, + assert job._has_logged_custom_job + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + def test_run_call_pipeline_service_create_with_tabular_dataset_and_timeout( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + mock_tabular_dataset, + mock_model_service_get, + sync, ): aiplatform.init( - project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME, + project=_TEST_PROJECT, + staging_bucket=_TEST_BUCKET_NAME, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, ) - job = training_jobs.CustomTrainingJob( + job = training_jobs.CustomContainerTrainingJob( display_name=_TEST_DISPLAY_NAME, - script_path=_TEST_LOCAL_SCRIPT_FILE_NAME, + labels=_TEST_LABELS, container_uri=_TEST_TRAINING_CONTAINER_IMAGE, + command=_TEST_TRAINING_CONTAINER_CMD, model_serving_container_image_uri=_TEST_SERVING_CONTAINER_IMAGE, model_serving_container_predict_route=_TEST_SERVING_CONTAINER_PREDICTION_ROUTE, model_serving_container_health_route=_TEST_SERVING_CONTAINER_HEALTH_ROUTE, @@ -1672,74 +3054,142 @@ def test_run_call_pipeline_service_create_with_nontabular_dataset_raises_if_anno model_description=_TEST_MODEL_DESCRIPTION, ) - with pytest.raises(Exception): - job.run( - dataset=mock_nontabular_dataset, - base_output_dir=_TEST_BASE_OUTPUT_DIR, - args=_TEST_RUN_ARGS, - replica_count=1, - machine_type=_TEST_MACHINE_TYPE, - accelerator_type=_TEST_ACCELERATOR_TYPE, - accelerator_count=_TEST_ACCELERATOR_COUNT, - model_display_name=_TEST_MODEL_DISPLAY_NAME, - ) - - @pytest.mark.usefixtures( - "mock_pipeline_service_create", - "mock_pipeline_service_get", - "mock_python_package_to_gcs", - "mock_model_service_get", - ) - def test_cancel_training_job(self, mock_pipeline_service_cancel): - aiplatform.init( - project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME, + model_from_job = job.run( + dataset=mock_tabular_dataset, + base_output_dir=_TEST_BASE_OUTPUT_DIR, + args=_TEST_RUN_ARGS, + environment_variables=_TEST_ENVIRONMENT_VARIABLES, + machine_type=_TEST_MACHINE_TYPE, + accelerator_type=_TEST_ACCELERATOR_TYPE, + accelerator_count=_TEST_ACCELERATOR_COUNT, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + model_labels=_TEST_MODEL_LABELS, + predefined_split_column_name=_TEST_PREDEFINED_SPLIT_COLUMN_NAME, + service_account=_TEST_SERVICE_ACCOUNT, + tensorboard=_TEST_TENSORBOARD_RESOURCE_NAME, + sync=sync, + create_request_timeout=180.0, ) - job = training_jobs.CustomTrainingJob( - display_name=_TEST_DISPLAY_NAME, - script_path=_TEST_LOCAL_SCRIPT_FILE_NAME, - container_uri=_TEST_TRAINING_CONTAINER_IMAGE, - ) + if not sync: + model_from_job.wait() - job.run() - job.cancel() + true_args = _TEST_RUN_ARGS + true_env = [ + {"name": key, "value": value} + for key, value in _TEST_ENVIRONMENT_VARIABLES.items() + ] - mock_pipeline_service_cancel.assert_called_once_with( - name=_TEST_PIPELINE_RESOURCE_NAME + true_worker_pool_spec = { + "replica_count": _TEST_REPLICA_COUNT, + "machine_spec": { + "machine_type": _TEST_MACHINE_TYPE, + "accelerator_type": _TEST_ACCELERATOR_TYPE, + "accelerator_count": _TEST_ACCELERATOR_COUNT, + }, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, + "containerSpec": { + "imageUri": _TEST_TRAINING_CONTAINER_IMAGE, + "command": _TEST_TRAINING_CONTAINER_CMD, + "args": true_args, + "env": true_env, + }, + } + + env = [ + gca_env_var.EnvVar(name=str(key), value=str(value)) + for key, value in _TEST_MODEL_SERVING_CONTAINER_ENVIRONMENT_VARIABLES.items() + ] + + ports = [ + gca_model.Port(container_port=port) + for port in _TEST_MODEL_SERVING_CONTAINER_PORTS + ] + + true_container_spec = gca_model.ModelContainerSpec( + image_uri=_TEST_SERVING_CONTAINER_IMAGE, + predict_route=_TEST_SERVING_CONTAINER_PREDICTION_ROUTE, + health_route=_TEST_SERVING_CONTAINER_HEALTH_ROUTE, + command=_TEST_MODEL_SERVING_CONTAINER_COMMAND, + args=_TEST_MODEL_SERVING_CONTAINER_ARGS, + env=env, + ports=ports, ) - @pytest.mark.usefixtures( - "mock_pipeline_service_create", - "mock_python_package_to_gcs", - "mock_model_service_get", - ) - def test_cancel_training_job_without_running(self, mock_pipeline_service_cancel): - aiplatform.init( - project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME, + true_managed_model = gca_model.Model( + display_name=_TEST_MODEL_DISPLAY_NAME, + labels=_TEST_MODEL_LABELS, + description=_TEST_MODEL_DESCRIPTION, + container_spec=true_container_spec, + predict_schemata=gca_model.PredictSchemata( + instance_schema_uri=_TEST_MODEL_INSTANCE_SCHEMA_URI, + parameters_schema_uri=_TEST_MODEL_PARAMETERS_SCHEMA_URI, + prediction_schema_uri=_TEST_MODEL_PREDICTION_SCHEMA_URI, + ), + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, ) - job = training_jobs.CustomTrainingJob( + true_input_data_config = gca_training_pipeline.InputDataConfig( + predefined_split=gca_training_pipeline.PredefinedSplit( + key=_TEST_PREDEFINED_SPLIT_COLUMN_NAME + ), + dataset_id=mock_tabular_dataset.name, + gcs_destination=gca_io.GcsDestination( + output_uri_prefix=_TEST_BASE_OUTPUT_DIR + ), + ) + + true_training_pipeline = gca_training_pipeline.TrainingPipeline( display_name=_TEST_DISPLAY_NAME, - script_path=_TEST_LOCAL_SCRIPT_FILE_NAME, - container_uri=_TEST_TRAINING_CONTAINER_IMAGE, + labels=_TEST_LABELS, + training_task_definition=schema.training_job.definition.custom_task, + training_task_inputs=json_format.ParseDict( + { + "worker_pool_specs": [true_worker_pool_spec], + "base_output_directory": { + "output_uri_prefix": _TEST_BASE_OUTPUT_DIR + }, + "service_account": _TEST_SERVICE_ACCOUNT, + "tensorboard": _TEST_TENSORBOARD_RESOURCE_NAME, + }, + struct_pb2.Value(), + ), + model_to_upload=true_managed_model, + input_data_config=true_input_data_config, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, ) - with pytest.raises(RuntimeError) as e: - job.cancel() + mock_pipeline_service_create.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + training_pipeline=true_training_pipeline, + timeout=180.0, + ) - assert e.match(regexp=r"TrainingJob has not been launched") + # assert job._gca_resource == make_training_pipeline( + # gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + # ) + # mock_model_service_get.assert_called_once_with( + # name=_TEST_MODEL_NAME, retry=base._DEFAULT_RETRY + # ) -class TestCustomContainerTrainingJob: - def setup_method(self): - importlib.reload(initializer) - importlib.reload(aiplatform) + # assert model_from_job._gca_resource is mock_model_service_get.return_value - def teardown_method(self): - initializer.global_pool.shutdown(wait=True) + # assert job.get_model()._gca_resource is mock_model_service_get.return_value + + # assert not job.has_failed + # assert job.state == gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + + # assert job._has_logged_custom_job + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) - def test_run_call_pipeline_service_create_with_tabular_dataset( + def test_run_call_pipeline_service_create_with_tabular_dataset_and_timeout_not_explicitly_set( self, mock_pipeline_service_create, mock_pipeline_service_get, @@ -1755,6 +3205,7 @@ def test_run_call_pipeline_service_create_with_tabular_dataset( job = training_jobs.CustomContainerTrainingJob( display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, container_uri=_TEST_TRAINING_CONTAINER_IMAGE, command=_TEST_TRAINING_CONTAINER_CMD, model_serving_container_image_uri=_TEST_SERVING_CONTAINER_IMAGE, @@ -1775,15 +3226,14 @@ def test_run_call_pipeline_service_create_with_tabular_dataset( base_output_dir=_TEST_BASE_OUTPUT_DIR, args=_TEST_RUN_ARGS, environment_variables=_TEST_ENVIRONMENT_VARIABLES, - replica_count=1, machine_type=_TEST_MACHINE_TYPE, accelerator_type=_TEST_ACCELERATOR_TYPE, accelerator_count=_TEST_ACCELERATOR_COUNT, model_display_name=_TEST_MODEL_DISPLAY_NAME, - training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT, - validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, - test_fraction_split=_TEST_TEST_FRACTION_SPLIT, + model_labels=_TEST_MODEL_LABELS, predefined_split_column_name=_TEST_PREDEFINED_SPLIT_COLUMN_NAME, + service_account=_TEST_SERVICE_ACCOUNT, + tensorboard=_TEST_TENSORBOARD_RESOURCE_NAME, sync=sync, ) @@ -1803,19 +3253,17 @@ def test_run_call_pipeline_service_create_with_tabular_dataset( "accelerator_type": _TEST_ACCELERATOR_TYPE, "accelerator_count": _TEST_ACCELERATOR_COUNT, }, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, "containerSpec": { "imageUri": _TEST_TRAINING_CONTAINER_IMAGE, - "command": _TEST_TRAINING_CONTAINER_CMD, - "args": true_args, - "env": true_env, - }, - } - - true_fraction_split = gca_training_pipeline.FractionSplit( - training_fraction=_TEST_TRAINING_FRACTION_SPLIT, - validation_fraction=_TEST_VALIDATION_FRACTION_SPLIT, - test_fraction=_TEST_TEST_FRACTION_SPLIT, - ) + "command": _TEST_TRAINING_CONTAINER_CMD, + "args": true_args, + "env": true_env, + }, + } env = [ gca_env_var.EnvVar(name=str(key), value=str(value)) @@ -1839,6 +3287,7 @@ def test_run_call_pipeline_service_create_with_tabular_dataset( true_managed_model = gca_model.Model( display_name=_TEST_MODEL_DISPLAY_NAME, + labels=_TEST_MODEL_LABELS, description=_TEST_MODEL_DESCRIPTION, container_spec=true_container_spec, predict_schemata=gca_model.PredictSchemata( @@ -1850,7 +3299,6 @@ def test_run_call_pipeline_service_create_with_tabular_dataset( ) true_input_data_config = gca_training_pipeline.InputDataConfig( - fraction_split=true_fraction_split, predefined_split=gca_training_pipeline.PredefinedSplit( key=_TEST_PREDEFINED_SPLIT_COLUMN_NAME ), @@ -1862,6 +3310,7 @@ def test_run_call_pipeline_service_create_with_tabular_dataset( true_training_pipeline = gca_training_pipeline.TrainingPipeline( display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, training_task_definition=schema.training_job.definition.custom_task, training_task_inputs=json_format.ParseDict( { @@ -1869,6 +3318,8 @@ def test_run_call_pipeline_service_create_with_tabular_dataset( "base_output_directory": { "output_uri_prefix": _TEST_BASE_OUTPUT_DIR }, + "service_account": _TEST_SERVICE_ACCOUNT, + "tensorboard": _TEST_TENSORBOARD_RESOURCE_NAME, }, struct_pb2.Value(), ), @@ -1880,20 +3331,11 @@ def test_run_call_pipeline_service_create_with_tabular_dataset( mock_pipeline_service_create.assert_called_once_with( parent=initializer.global_config.common_location_path(), training_pipeline=true_training_pipeline, + timeout=None, ) - assert job._gca_resource is mock_pipeline_service_get.return_value - - mock_model_service_get.assert_called_once_with(name=_TEST_MODEL_NAME) - - assert model_from_job._gca_resource is mock_model_service_get.return_value - - assert job.get_model()._gca_resource is mock_model_service_get.return_value - - assert not job.has_failed - - assert job.state == gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED - + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) def test_run_call_pipeline_service_create_with_bigquery_destination( self, @@ -1929,7 +3371,6 @@ def test_run_call_pipeline_service_create_with_bigquery_destination( base_output_dir=_TEST_BASE_OUTPUT_DIR, bigquery_destination=_TEST_BIGQUERY_DESTINATION, args=_TEST_RUN_ARGS, - replica_count=1, machine_type=_TEST_MACHINE_TYPE, accelerator_type=_TEST_ACCELERATOR_TYPE, accelerator_count=_TEST_ACCELERATOR_COUNT, @@ -1937,8 +3378,9 @@ def test_run_call_pipeline_service_create_with_bigquery_destination( training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT, validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, test_fraction_split=_TEST_TEST_FRACTION_SPLIT, - predefined_split_column_name=_TEST_PREDEFINED_SPLIT_COLUMN_NAME, + timestamp_split_column_name=_TEST_TIMESTAMP_SPLIT_COLUMN_NAME, sync=sync, + create_request_timeout=None, ) if not sync: @@ -1953,6 +3395,10 @@ def test_run_call_pipeline_service_create_with_bigquery_destination( "accelerator_type": _TEST_ACCELERATOR_TYPE, "accelerator_count": _TEST_ACCELERATOR_COUNT, }, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, "containerSpec": { "imageUri": _TEST_TRAINING_CONTAINER_IMAGE, "command": _TEST_TRAINING_CONTAINER_CMD, @@ -1960,10 +3406,11 @@ def test_run_call_pipeline_service_create_with_bigquery_destination( }, } - true_fraction_split = gca_training_pipeline.FractionSplit( + true_timestamp_split = gca_training_pipeline.TimestampSplit( training_fraction=_TEST_TRAINING_FRACTION_SPLIT, validation_fraction=_TEST_VALIDATION_FRACTION_SPLIT, test_fraction=_TEST_TEST_FRACTION_SPLIT, + key=_TEST_TIMESTAMP_SPLIT_COLUMN_NAME, ) env = [ @@ -1999,10 +3446,7 @@ def test_run_call_pipeline_service_create_with_bigquery_destination( ) true_input_data_config = gca_training_pipeline.InputDataConfig( - fraction_split=true_fraction_split, - predefined_split=gca_training_pipeline.PredefinedSplit( - key=_TEST_PREDEFINED_SPLIT_COLUMN_NAME - ), + timestamp_split=true_timestamp_split, dataset_id=mock_tabular_dataset.name, bigquery_destination=gca_io.BigQueryDestination( output_uri=_TEST_BIGQUERY_DESTINATION @@ -2029,11 +3473,16 @@ def test_run_call_pipeline_service_create_with_bigquery_destination( mock_pipeline_service_create.assert_called_once_with( parent=initializer.global_config.common_location_path(), training_pipeline=true_training_pipeline, + timeout=None, ) - assert job._gca_resource is mock_pipeline_service_get.return_value + assert job._gca_resource == make_training_pipeline( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) - mock_model_service_get.assert_called_once_with(name=_TEST_MODEL_NAME) + mock_model_service_get.assert_called_once_with( + name=_TEST_MODEL_NAME, retry=base._DEFAULT_RETRY + ) assert model_from_job._gca_resource is mock_model_service_get.return_value @@ -2043,6 +3492,8 @@ def test_run_call_pipeline_service_create_with_bigquery_destination( assert job.state == gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.usefixtures( "mock_pipeline_service_create", "mock_pipeline_service_get", @@ -2051,7 +3502,9 @@ def test_run_call_pipeline_service_create_with_bigquery_destination( ) @pytest.mark.parametrize("sync", [True, False]) def test_run_called_twice_raises( - self, mock_tabular_dataset, sync, + self, + mock_tabular_dataset, + sync, ): aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME) @@ -2077,6 +3530,7 @@ def test_run_called_twice_raises( validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, test_fraction_split=_TEST_TEST_FRACTION_SPLIT, sync=sync, + create_request_timeout=None, ) with pytest.raises(RuntimeError): @@ -2093,6 +3547,7 @@ def test_run_called_twice_raises( validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, test_fraction_split=_TEST_TEST_FRACTION_SPLIT, sync=sync, + create_request_timeout=None, ) if not sync: @@ -2128,10 +3583,39 @@ def test_run_with_invalid_accelerator_type_raises( accelerator_type=_TEST_INVALID_ACCELERATOR_TYPE, accelerator_count=_TEST_ACCELERATOR_COUNT, model_display_name=_TEST_MODEL_DISPLAY_NAME, + sync=sync, + create_request_timeout=None, + ) + + @pytest.mark.parametrize("sync", [True, False]) + def test_run_with_two_split_raises( + self, + mock_pipeline_service_create, + mock_python_package_to_gcs, + mock_tabular_dataset, + mock_model_service_get, + sync, + ): + aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME) + + job = training_jobs.CustomContainerTrainingJob( + display_name=_TEST_DISPLAY_NAME, + container_uri=_TEST_TRAINING_CONTAINER_IMAGE, + ) + + with pytest.raises(ValueError): + job.run( + dataset=mock_tabular_dataset, + replica_count=1, + machine_type=_TEST_MACHINE_TYPE, + accelerator_type=_TEST_INVALID_ACCELERATOR_TYPE, + accelerator_count=_TEST_ACCELERATOR_COUNT, + predefined_split_column_name=_TEST_PREDEFINED_SPLIT_COLUMN_NAME, training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT, validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, test_fraction_split=_TEST_TEST_FRACTION_SPLIT, sync=sync, + create_request_timeout=None, ) @pytest.mark.parametrize("sync", [True, False]) @@ -2165,8 +3649,11 @@ def test_run_with_incomplete_model_info_raises_with_model_to_upload( validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, test_fraction_split=_TEST_TEST_FRACTION_SPLIT, sync=sync, + create_request_timeout=None, ) + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) def test_run_call_pipeline_service_create_with_no_dataset( self, @@ -2189,7 +3676,6 @@ def test_run_call_pipeline_service_create_with_no_dataset( model_from_job = job.run( base_output_dir=_TEST_BASE_OUTPUT_DIR, args=_TEST_RUN_ARGS, - replica_count=1, machine_type=_TEST_MACHINE_TYPE, accelerator_type=_TEST_ACCELERATOR_TYPE, accelerator_count=_TEST_ACCELERATOR_COUNT, @@ -2198,6 +3684,7 @@ def test_run_call_pipeline_service_create_with_no_dataset( validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, test_fraction_split=_TEST_TEST_FRACTION_SPLIT, sync=sync, + create_request_timeout=None, ) if not sync: @@ -2212,6 +3699,10 @@ def test_run_call_pipeline_service_create_with_no_dataset( "accelerator_type": _TEST_ACCELERATOR_TYPE, "accelerator_count": _TEST_ACCELERATOR_COUNT, }, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, "containerSpec": { "imageUri": _TEST_TRAINING_CONTAINER_IMAGE, "command": _TEST_TRAINING_CONTAINER_CMD, @@ -2247,14 +3738,117 @@ def test_run_call_pipeline_service_create_with_no_dataset( mock_pipeline_service_create.assert_called_once_with( parent=initializer.global_config.common_location_path(), training_pipeline=true_training_pipeline, + timeout=None, ) - assert job._gca_resource is mock_pipeline_service_get.return_value + assert job._gca_resource == make_training_pipeline( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) - mock_model_service_get.assert_called_once_with(name=_TEST_MODEL_NAME) + mock_model_service_get.assert_called_once_with( + name=_TEST_MODEL_NAME, retry=base._DEFAULT_RETRY + ) assert model_from_job._gca_resource is mock_model_service_get.return_value + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.usefixtures( + "mock_pipeline_service_create_with_enable_web_access", + "mock_pipeline_service_get_with_enable_web_access", + "mock_get_backing_custom_job_with_enable_web_access", + ) + @pytest.mark.parametrize("sync", [True, False]) + def test_run_call_pipeline_service_create_with_enable_web_access( + self, sync, caplog + ): + + caplog.set_level(logging.INFO) + + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_BUCKET_NAME, + credentials=_TEST_CREDENTIALS, + ) + + job = training_jobs.CustomContainerTrainingJob( + display_name=_TEST_DISPLAY_NAME, + container_uri=_TEST_TRAINING_CONTAINER_IMAGE, + command=_TEST_TRAINING_CONTAINER_CMD, + ) + + job.run( + base_output_dir=_TEST_BASE_OUTPUT_DIR, + args=_TEST_RUN_ARGS, + machine_type=_TEST_MACHINE_TYPE, + accelerator_type=_TEST_ACCELERATOR_TYPE, + accelerator_count=_TEST_ACCELERATOR_COUNT, + enable_web_access=_TEST_ENABLE_WEB_ACCESS, + sync=sync, + create_request_timeout=None, + ) + + if not sync: + job.wait() + + print(caplog.text) + assert "workerpool0-0" in caplog.text + assert job._gca_resource == make_training_pipeline_with_enable_web_access( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.usefixtures( + "mock_pipeline_service_create_with_scheduling", + "mock_pipeline_service_get_with_scheduling", + ) + @pytest.mark.parametrize("sync", [True, False]) + def test_run_call_pipeline_service_create_with_scheduling(self, sync, caplog): + + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_BUCKET_NAME, + credentials=_TEST_CREDENTIALS, + ) + + job = training_jobs.CustomContainerTrainingJob( + display_name=_TEST_DISPLAY_NAME, + container_uri=_TEST_TRAINING_CONTAINER_IMAGE, + command=_TEST_TRAINING_CONTAINER_CMD, + ) + + job.run( + base_output_dir=_TEST_BASE_OUTPUT_DIR, + args=_TEST_RUN_ARGS, + machine_type=_TEST_MACHINE_TYPE, + accelerator_type=_TEST_ACCELERATOR_TYPE, + accelerator_count=_TEST_ACCELERATOR_COUNT, + timeout=_TEST_TIMEOUT, + restart_job_on_worker_restart=_TEST_RESTART_JOB_ON_WORKER_RESTART, + sync=sync, + create_request_timeout=None, + ) + + if not sync: + job.wait() + + assert job._gca_resource == make_training_pipeline_with_scheduling( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) + + assert ( + job._gca_resource.state + == gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) + assert job._gca_resource.training_task_inputs["timeout"] == f"{_TEST_TIMEOUT}s" + assert ( + job._gca_resource.training_task_inputs["restart_job_on_worker_restart"] + == _TEST_RESTART_JOB_ON_WORKER_RESTART + ) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) def test_run_returns_none_if_no_model_to_upload( self, @@ -2279,21 +3873,23 @@ def test_run_returns_none_if_no_model_to_upload( machine_type=_TEST_MACHINE_TYPE, accelerator_type=_TEST_ACCELERATOR_TYPE, accelerator_count=_TEST_ACCELERATOR_COUNT, - training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT, - validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, - test_fraction_split=_TEST_TEST_FRACTION_SPLIT, sync=sync, + create_request_timeout=None, ) assert model is None + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.usefixtures( "mock_pipeline_service_create_with_no_model_to_upload", "mock_pipeline_service_get_with_no_model_to_upload", ) @pytest.mark.parametrize("sync", [True, False]) def test_get_model_raises_if_no_model_to_upload( - self, mock_tabular_dataset, sync, + self, + mock_tabular_dataset, + sync, ): aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME) @@ -2315,6 +3911,7 @@ def test_get_model_raises_if_no_model_to_upload( validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, test_fraction_split=_TEST_TEST_FRACTION_SPLIT, sync=sync, + create_request_timeout=None, ) if not sync: @@ -2323,6 +3920,8 @@ def test_get_model_raises_if_no_model_to_upload( with pytest.raises(RuntimeError): job.get_model() + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) def test_run_raises_if_pipeline_fails( self, @@ -2352,6 +3951,7 @@ def test_run_raises_if_pipeline_fails( validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, test_fraction_split=_TEST_TEST_FRACTION_SPLIT, sync=sync, + create_request_timeout=None, ) if not sync: @@ -2392,6 +3992,8 @@ def test_run_raises_if_no_staging_bucket(self): command=_TEST_TRAINING_CONTAINER_CMD, ) + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) def test_run_call_pipeline_service_create_distributed_training( self, @@ -2428,6 +4030,7 @@ def test_run_call_pipeline_service_create_distributed_training( validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, test_fraction_split=_TEST_TEST_FRACTION_SPLIT, sync=sync, + create_request_timeout=None, ) if not sync: @@ -2443,6 +4046,10 @@ def test_run_call_pipeline_service_create_distributed_training( "accelerator_type": _TEST_ACCELERATOR_TYPE, "accelerator_count": _TEST_ACCELERATOR_COUNT, }, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, "containerSpec": { "imageUri": _TEST_TRAINING_CONTAINER_IMAGE, "command": _TEST_TRAINING_CONTAINER_CMD, @@ -2456,6 +4063,10 @@ def test_run_call_pipeline_service_create_distributed_training( "accelerator_type": _TEST_ACCELERATOR_TYPE, "accelerator_count": _TEST_ACCELERATOR_COUNT, }, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, "containerSpec": { "imageUri": _TEST_TRAINING_CONTAINER_IMAGE, "command": _TEST_TRAINING_CONTAINER_CMD, @@ -2513,11 +4124,16 @@ def test_run_call_pipeline_service_create_distributed_training( mock_pipeline_service_create.assert_called_once_with( parent=initializer.global_config.common_location_path(), training_pipeline=true_training_pipeline, + timeout=None, ) - assert job._gca_resource is mock_pipeline_service_get.return_value + assert job._gca_resource == make_training_pipeline( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) - mock_model_service_get.assert_called_once_with(name=_TEST_MODEL_NAME) + mock_model_service_get.assert_called_once_with( + name=_TEST_MODEL_NAME, retry=base._DEFAULT_RETRY + ) assert model_from_job._gca_resource is mock_model_service_get.return_value @@ -2527,6 +4143,122 @@ def test_run_call_pipeline_service_create_distributed_training( assert job.state == gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + def test_run_call_pipeline_service_create_distributed_training_with_reduction_server( + self, + mock_pipeline_service_create_with_no_model_to_upload, + mock_pipeline_service_get_with_no_model_to_upload, + sync, + ): + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_BUCKET_NAME, + credentials=_TEST_CREDENTIALS, + ) + + job = training_jobs.CustomContainerTrainingJob( + display_name=_TEST_DISPLAY_NAME, + container_uri=_TEST_TRAINING_CONTAINER_IMAGE, + command=_TEST_TRAINING_CONTAINER_CMD, + ) + + job.run( + base_output_dir=_TEST_BASE_OUTPUT_DIR, + args=_TEST_RUN_ARGS, + replica_count=10, + machine_type=_TEST_MACHINE_TYPE, + accelerator_type=_TEST_ACCELERATOR_TYPE, + accelerator_count=_TEST_ACCELERATOR_COUNT, + reduction_server_replica_count=_TEST_REDUCTION_SERVER_REPLICA_COUNT, + reduction_server_machine_type=_TEST_REDUCTION_SERVER_MACHINE_TYPE, + reduction_server_container_uri=_TEST_REDUCTION_SERVER_CONTAINER_URI, + sync=sync, + create_request_timeout=None, + ) + + if not sync: + job.wait() + + true_args = _TEST_RUN_ARGS + + true_worker_pool_spec = [ + { + "replica_count": 1, + "machine_spec": { + "machine_type": _TEST_MACHINE_TYPE, + "accelerator_type": _TEST_ACCELERATOR_TYPE, + "accelerator_count": _TEST_ACCELERATOR_COUNT, + }, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, + "containerSpec": { + "imageUri": _TEST_TRAINING_CONTAINER_IMAGE, + "command": _TEST_TRAINING_CONTAINER_CMD, + "args": true_args, + }, + }, + { + "replica_count": 9, + "machine_spec": { + "machine_type": _TEST_MACHINE_TYPE, + "accelerator_type": _TEST_ACCELERATOR_TYPE, + "accelerator_count": _TEST_ACCELERATOR_COUNT, + }, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, + "containerSpec": { + "imageUri": _TEST_TRAINING_CONTAINER_IMAGE, + "command": _TEST_TRAINING_CONTAINER_CMD, + "args": true_args, + }, + }, + { + "replica_count": _TEST_REDUCTION_SERVER_REPLICA_COUNT, + "machine_spec": {"machine_type": _TEST_REDUCTION_SERVER_MACHINE_TYPE}, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, + "container_spec": {"image_uri": _TEST_REDUCTION_SERVER_CONTAINER_URI}, + }, + ] + + true_training_pipeline = gca_training_pipeline.TrainingPipeline( + display_name=_TEST_DISPLAY_NAME, + training_task_definition=schema.training_job.definition.custom_task, + training_task_inputs=json_format.ParseDict( + { + "worker_pool_specs": true_worker_pool_spec, + "base_output_directory": { + "output_uri_prefix": _TEST_BASE_OUTPUT_DIR + }, + }, + struct_pb2.Value(), + ), + ) + + mock_pipeline_service_create_with_no_model_to_upload.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + training_pipeline=true_training_pipeline, + timeout=None, + ) + + assert job._gca_resource == make_training_pipeline_with_no_model_upload( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) + + assert not job.has_failed + + assert job.state == gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) def test_run_call_pipeline_service_create_with_nontabular_dataset( self, @@ -2538,11 +4270,13 @@ def test_run_call_pipeline_service_create_with_nontabular_dataset( sync, ): aiplatform.init( - project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME, + project=_TEST_PROJECT, + staging_bucket=_TEST_BUCKET_NAME, ) job = training_jobs.CustomContainerTrainingJob( display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, container_uri=_TEST_TRAINING_CONTAINER_IMAGE, command=_TEST_TRAINING_CONTAINER_CMD, model_serving_container_image_uri=_TEST_SERVING_CONTAINER_IMAGE, @@ -2565,12 +4299,16 @@ def test_run_call_pipeline_service_create_with_nontabular_dataset( service_account=_TEST_SERVICE_ACCOUNT, network=_TEST_NETWORK, args=_TEST_RUN_ARGS, - replica_count=1, machine_type=_TEST_MACHINE_TYPE, accelerator_type=_TEST_ACCELERATOR_TYPE, accelerator_count=_TEST_ACCELERATOR_COUNT, model_display_name=_TEST_MODEL_DISPLAY_NAME, + model_labels=_TEST_MODEL_LABELS, + training_filter_split=_TEST_TRAINING_FILTER_SPLIT, + validation_filter_split=_TEST_VALIDATION_FILTER_SPLIT, + test_filter_split=_TEST_TEST_FILTER_SPLIT, sync=sync, + create_request_timeout=None, ) if not sync: @@ -2585,6 +4323,10 @@ def test_run_call_pipeline_service_create_with_nontabular_dataset( "accelerator_type": _TEST_ACCELERATOR_TYPE, "accelerator_count": _TEST_ACCELERATOR_COUNT, }, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, "containerSpec": { "imageUri": _TEST_TRAINING_CONTAINER_IMAGE, "command": _TEST_TRAINING_CONTAINER_CMD, @@ -2592,10 +4334,10 @@ def test_run_call_pipeline_service_create_with_nontabular_dataset( }, } - true_fraction_split = gca_training_pipeline.FractionSplit( - training_fraction=_TEST_DEFAULT_TRAINING_FRACTION_SPLIT, - validation_fraction=_TEST_DEFAULT_VALIDATION_FRACTION_SPLIT, - test_fraction=_TEST_DEFAULT_TEST_FRACTION_SPLIT, + true_filter_split = gca_training_pipeline.FilterSplit( + training_filter=_TEST_TRAINING_FILTER_SPLIT, + validation_filter=_TEST_VALIDATION_FILTER_SPLIT, + test_filter=_TEST_TEST_FILTER_SPLIT, ) env = [ @@ -2620,6 +4362,7 @@ def test_run_call_pipeline_service_create_with_nontabular_dataset( true_managed_model = gca_model.Model( display_name=_TEST_MODEL_DISPLAY_NAME, + labels=_TEST_MODEL_LABELS, description=_TEST_MODEL_DESCRIPTION, container_spec=true_container_spec, predict_schemata=gca_model.PredictSchemata( @@ -2630,7 +4373,7 @@ def test_run_call_pipeline_service_create_with_nontabular_dataset( ) true_input_data_config = gca_training_pipeline.InputDataConfig( - fraction_split=true_fraction_split, + filter_split=true_filter_split, dataset_id=mock_nontabular_dataset.name, annotation_schema_uri=_TEST_ANNOTATION_SCHEMA_URI, gcs_destination=gca_io.GcsDestination( @@ -2654,16 +4397,22 @@ def test_run_call_pipeline_service_create_with_nontabular_dataset( ), model_to_upload=true_managed_model, input_data_config=true_input_data_config, + labels=_TEST_LABELS, ) mock_pipeline_service_create.assert_called_once_with( parent=initializer.global_config.common_location_path(), training_pipeline=true_training_pipeline, + timeout=None, ) - assert job._gca_resource is mock_pipeline_service_get.return_value + assert job._gca_resource == make_training_pipeline( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) - mock_model_service_get.assert_called_once_with(name=_TEST_MODEL_NAME) + mock_model_service_get.assert_called_once_with( + name=_TEST_MODEL_NAME, retry=base._DEFAULT_RETRY + ) assert model_from_job._gca_resource is mock_model_service_get.return_value @@ -2674,10 +4423,12 @@ def test_run_call_pipeline_service_create_with_nontabular_dataset( assert job.state == gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED def test_run_call_pipeline_service_create_with_nontabular_dataset_raises_if_annotation_schema_uri( - self, mock_nontabular_dataset, + self, + mock_nontabular_dataset, ): aiplatform.init( - project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME, + project=_TEST_PROJECT, + staging_bucket=_TEST_BUCKET_NAME, ) job = training_jobs.CustomContainerTrainingJob( @@ -2707,16 +4458,42 @@ def test_run_call_pipeline_service_create_with_nontabular_dataset_raises_if_anno accelerator_type=_TEST_ACCELERATOR_TYPE, accelerator_count=_TEST_ACCELERATOR_COUNT, model_display_name=_TEST_MODEL_DISPLAY_NAME, + create_request_timeout=None, ) -class Test_MachineSpec: +class Test_WorkerPoolSpec: def test_machine_spec_return_spec_dict(self): - test_spec = worker_spec_utils._MachineSpec( + test_spec = worker_spec_utils._WorkerPoolSpec( + replica_count=_TEST_REPLICA_COUNT, + machine_type=_TEST_MACHINE_TYPE, + accelerator_count=_TEST_ACCELERATOR_COUNT, + accelerator_type=_TEST_ACCELERATOR_TYPE, + ) + + true_spec_dict = { + "machine_spec": { + "machine_type": _TEST_MACHINE_TYPE, + "accelerator_type": _TEST_ACCELERATOR_TYPE, + "accelerator_count": _TEST_ACCELERATOR_COUNT, + }, + "replica_count": _TEST_REPLICA_COUNT, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, + } + + assert test_spec.spec_dict == true_spec_dict + + def test_machine_spec_return_spec_dict_with_boot_disk(self): + test_spec = worker_spec_utils._WorkerPoolSpec( replica_count=_TEST_REPLICA_COUNT, machine_type=_TEST_MACHINE_TYPE, accelerator_count=_TEST_ACCELERATOR_COUNT, accelerator_type=_TEST_ACCELERATOR_TYPE, + boot_disk_type=_TEST_BOOT_DISK_TYPE, + boot_disk_size_gb=_TEST_BOOT_DISK_SIZE_GB, ) true_spec_dict = { @@ -2726,12 +4503,16 @@ def test_machine_spec_return_spec_dict(self): "accelerator_count": _TEST_ACCELERATOR_COUNT, }, "replica_count": _TEST_REPLICA_COUNT, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB, + }, } assert test_spec.spec_dict == true_spec_dict def test_machine_spec_return_spec_dict_with_no_accelerator(self): - test_spec = worker_spec_utils._MachineSpec( + test_spec = worker_spec_utils._WorkerPoolSpec( replica_count=_TEST_REPLICA_COUNT, machine_type=_TEST_MACHINE_TYPE, accelerator_count=0, @@ -2741,12 +4522,16 @@ def test_machine_spec_return_spec_dict_with_no_accelerator(self): true_spec_dict = { "machine_spec": {"machine_type": _TEST_MACHINE_TYPE}, "replica_count": _TEST_REPLICA_COUNT, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, } assert test_spec.spec_dict == true_spec_dict def test_machine_spec_spec_dict_raises_invalid_accelerator(self): - test_spec = worker_spec_utils._MachineSpec( + test_spec = worker_spec_utils._WorkerPoolSpec( replica_count=_TEST_REPLICA_COUNT, machine_type=_TEST_MACHINE_TYPE, accelerator_count=_TEST_ACCELERATOR_COUNT, @@ -2757,7 +4542,7 @@ def test_machine_spec_spec_dict_raises_invalid_accelerator(self): test_spec.spec_dict def test_machine_spec_spec_dict_is_empty(self): - test_spec = worker_spec_utils._MachineSpec( + test_spec = worker_spec_utils._WorkerPoolSpec( replica_count=0, machine_type=_TEST_MACHINE_TYPE, accelerator_count=_TEST_ACCELERATOR_COUNT, @@ -2767,7 +4552,7 @@ def test_machine_spec_spec_dict_is_empty(self): assert test_spec.is_empty def test_machine_spec_spec_dict_is_not_empty(self): - test_spec = worker_spec_utils._MachineSpec( + test_spec = worker_spec_utils._WorkerPoolSpec( replica_count=_TEST_REPLICA_COUNT, machine_type=_TEST_MACHINE_TYPE, accelerator_count=_TEST_ACCELERATOR_COUNT, @@ -2781,25 +4566,25 @@ class Test_DistributedTrainingSpec: def test_machine_spec_returns_pool_spec(self): spec = worker_spec_utils._DistributedTrainingSpec( - chief_spec=worker_spec_utils._MachineSpec( + chief_spec=worker_spec_utils._WorkerPoolSpec( replica_count=1, machine_type=_TEST_MACHINE_TYPE, accelerator_count=_TEST_ACCELERATOR_COUNT, accelerator_type=_TEST_ACCELERATOR_TYPE, ), - worker_spec=worker_spec_utils._MachineSpec( + worker_spec=worker_spec_utils._WorkerPoolSpec( replica_count=10, machine_type=_TEST_MACHINE_TYPE, accelerator_count=_TEST_ACCELERATOR_COUNT, accelerator_type=_TEST_ACCELERATOR_TYPE, ), - parameter_server_spec=worker_spec_utils._MachineSpec( + server_spec=worker_spec_utils._WorkerPoolSpec( replica_count=3, machine_type=_TEST_MACHINE_TYPE, accelerator_count=_TEST_ACCELERATOR_COUNT, accelerator_type=_TEST_ACCELERATOR_TYPE, ), - evaluator_spec=worker_spec_utils._MachineSpec( + evaluator_spec=worker_spec_utils._WorkerPoolSpec( replica_count=1, machine_type=_TEST_MACHINE_TYPE, accelerator_count=_TEST_ACCELERATOR_COUNT, @@ -2815,6 +4600,10 @@ def test_machine_spec_returns_pool_spec(self): "accelerator_count": _TEST_ACCELERATOR_COUNT, }, "replica_count": 1, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, }, { "machine_spec": { @@ -2823,6 +4612,10 @@ def test_machine_spec_returns_pool_spec(self): "accelerator_count": _TEST_ACCELERATOR_COUNT, }, "replica_count": 10, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, }, { "machine_spec": { @@ -2831,137 +4624,502 @@ def test_machine_spec_returns_pool_spec(self): "accelerator_count": _TEST_ACCELERATOR_COUNT, }, "replica_count": 3, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, + }, + { + "machine_spec": { + "machine_type": _TEST_MACHINE_TYPE, + "accelerator_type": _TEST_ACCELERATOR_TYPE, + "accelerator_count": _TEST_ACCELERATOR_COUNT, + }, + "replica_count": 1, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, + }, + ] + + assert spec.pool_specs == true_pool_spec + + def test_chief_worker_pool_returns_spec(self): + + chief_worker_spec = ( + worker_spec_utils._DistributedTrainingSpec.chief_worker_pool( + replica_count=10, + machine_type=_TEST_MACHINE_TYPE, + accelerator_count=_TEST_ACCELERATOR_COUNT, + accelerator_type=_TEST_ACCELERATOR_TYPE, + ) + ) + + true_pool_spec = [ + { + "machine_spec": { + "machine_type": _TEST_MACHINE_TYPE, + "accelerator_type": _TEST_ACCELERATOR_TYPE, + "accelerator_count": _TEST_ACCELERATOR_COUNT, + }, + "replica_count": 1, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, + }, + { + "machine_spec": { + "machine_type": _TEST_MACHINE_TYPE, + "accelerator_type": _TEST_ACCELERATOR_TYPE, + "accelerator_count": _TEST_ACCELERATOR_COUNT, + }, + "replica_count": 9, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, + }, + ] + + assert chief_worker_spec.pool_specs == true_pool_spec + + def test_chief_worker_pool_returns_just_chief(self): + + chief_worker_spec = ( + worker_spec_utils._DistributedTrainingSpec.chief_worker_pool( + replica_count=1, + machine_type=_TEST_MACHINE_TYPE, + accelerator_count=_TEST_ACCELERATOR_COUNT, + accelerator_type=_TEST_ACCELERATOR_TYPE, + ) + ) + + true_pool_spec = [ + { + "machine_spec": { + "machine_type": _TEST_MACHINE_TYPE, + "accelerator_type": _TEST_ACCELERATOR_TYPE, + "accelerator_count": _TEST_ACCELERATOR_COUNT, + }, + "replica_count": 1, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, + } + ] + + assert chief_worker_spec.pool_specs == true_pool_spec + + def test_machine_spec_raise_with_more_than_one_chief_replica(self): + + spec = worker_spec_utils._DistributedTrainingSpec( + chief_spec=worker_spec_utils._WorkerPoolSpec( + replica_count=2, + machine_type=_TEST_MACHINE_TYPE, + accelerator_count=_TEST_ACCELERATOR_COUNT, + accelerator_type=_TEST_ACCELERATOR_TYPE, + ), + ) + + with pytest.raises(ValueError): + spec.pool_specs + + def test_machine_spec_handles_missing_pools(self): + + spec = worker_spec_utils._DistributedTrainingSpec( + chief_spec=worker_spec_utils._WorkerPoolSpec( + replica_count=1, + machine_type=_TEST_MACHINE_TYPE, + accelerator_count=_TEST_ACCELERATOR_COUNT, + accelerator_type=_TEST_ACCELERATOR_TYPE, + ), + worker_spec=worker_spec_utils._WorkerPoolSpec(replica_count=0), + server_spec=worker_spec_utils._WorkerPoolSpec( + replica_count=3, + machine_type=_TEST_MACHINE_TYPE, + accelerator_count=_TEST_ACCELERATOR_COUNT, + accelerator_type=_TEST_ACCELERATOR_TYPE, + ), + evaluator_spec=worker_spec_utils._WorkerPoolSpec(replica_count=0), + ) + + true_pool_spec = [ + { + "machine_spec": { + "machine_type": _TEST_MACHINE_TYPE, + "accelerator_type": _TEST_ACCELERATOR_TYPE, + "accelerator_count": _TEST_ACCELERATOR_COUNT, + }, + "replica_count": 1, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, }, + {}, { "machine_spec": { "machine_type": _TEST_MACHINE_TYPE, "accelerator_type": _TEST_ACCELERATOR_TYPE, "accelerator_count": _TEST_ACCELERATOR_COUNT, }, - "replica_count": 1, - }, - ] + "replica_count": 3, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, + }, + ] + + assert spec.pool_specs == true_pool_spec + + +@pytest.mark.usefixtures("google_auth_mock") +class TestCustomPythonPackageTrainingJob: + def setup_method(self): + importlib.reload(initializer) + importlib.reload(aiplatform) + + def teardown_method(self): + initializer.global_pool.shutdown(wait=True) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + def test_run_call_pipeline_service_create_with_tabular_dataset( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + mock_tabular_dataset, + mock_model_service_get, + sync, + ): + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_BUCKET_NAME, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) + + job = training_jobs.CustomPythonPackageTrainingJob( + display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, + python_package_gcs_uri=_TEST_OUTPUT_PYTHON_PACKAGE_PATH, + python_module_name=_TEST_PYTHON_MODULE_NAME, + container_uri=_TEST_TRAINING_CONTAINER_IMAGE, + model_serving_container_image_uri=_TEST_SERVING_CONTAINER_IMAGE, + model_serving_container_predict_route=_TEST_SERVING_CONTAINER_PREDICTION_ROUTE, + model_serving_container_health_route=_TEST_SERVING_CONTAINER_HEALTH_ROUTE, + model_serving_container_command=_TEST_MODEL_SERVING_CONTAINER_COMMAND, + model_serving_container_args=_TEST_MODEL_SERVING_CONTAINER_ARGS, + model_serving_container_environment_variables=_TEST_MODEL_SERVING_CONTAINER_ENVIRONMENT_VARIABLES, + model_serving_container_ports=_TEST_MODEL_SERVING_CONTAINER_PORTS, + model_description=_TEST_MODEL_DESCRIPTION, + model_instance_schema_uri=_TEST_MODEL_INSTANCE_SCHEMA_URI, + model_parameters_schema_uri=_TEST_MODEL_PARAMETERS_SCHEMA_URI, + model_prediction_schema_uri=_TEST_MODEL_PREDICTION_SCHEMA_URI, + ) + + model_from_job = job.run( + dataset=mock_tabular_dataset, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + model_labels=_TEST_MODEL_LABELS, + base_output_dir=_TEST_BASE_OUTPUT_DIR, + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, + args=_TEST_RUN_ARGS, + environment_variables=_TEST_ENVIRONMENT_VARIABLES, + machine_type=_TEST_MACHINE_TYPE, + accelerator_type=_TEST_ACCELERATOR_TYPE, + accelerator_count=_TEST_ACCELERATOR_COUNT, + training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT, + validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, + test_fraction_split=_TEST_TEST_FRACTION_SPLIT, + sync=sync, + create_request_timeout=None, + ) + + if not sync: + model_from_job.wait() + + true_args = _TEST_RUN_ARGS + true_env = [ + {"name": key, "value": value} + for key, value in _TEST_ENVIRONMENT_VARIABLES.items() + ] + + true_worker_pool_spec = { + "replica_count": _TEST_REPLICA_COUNT, + "machine_spec": { + "machine_type": _TEST_MACHINE_TYPE, + "accelerator_type": _TEST_ACCELERATOR_TYPE, + "accelerator_count": _TEST_ACCELERATOR_COUNT, + }, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, + "python_package_spec": { + "executor_image_uri": _TEST_TRAINING_CONTAINER_IMAGE, + "python_module": _TEST_PYTHON_MODULE_NAME, + "package_uris": [_TEST_OUTPUT_PYTHON_PACKAGE_PATH], + "args": true_args, + "env": true_env, + }, + } + + true_fraction_split = gca_training_pipeline.FractionSplit( + training_fraction=_TEST_TRAINING_FRACTION_SPLIT, + validation_fraction=_TEST_VALIDATION_FRACTION_SPLIT, + test_fraction=_TEST_TEST_FRACTION_SPLIT, + ) + + env = [ + gca_env_var.EnvVar(name=str(key), value=str(value)) + for key, value in _TEST_MODEL_SERVING_CONTAINER_ENVIRONMENT_VARIABLES.items() + ] + + ports = [ + gca_model.Port(container_port=port) + for port in _TEST_MODEL_SERVING_CONTAINER_PORTS + ] + + true_container_spec = gca_model.ModelContainerSpec( + image_uri=_TEST_SERVING_CONTAINER_IMAGE, + predict_route=_TEST_SERVING_CONTAINER_PREDICTION_ROUTE, + health_route=_TEST_SERVING_CONTAINER_HEALTH_ROUTE, + command=_TEST_MODEL_SERVING_CONTAINER_COMMAND, + args=_TEST_MODEL_SERVING_CONTAINER_ARGS, + env=env, + ports=ports, + ) + + true_managed_model = gca_model.Model( + display_name=_TEST_MODEL_DISPLAY_NAME, + labels=_TEST_MODEL_LABELS, + description=_TEST_MODEL_DESCRIPTION, + container_spec=true_container_spec, + predict_schemata=gca_model.PredictSchemata( + instance_schema_uri=_TEST_MODEL_INSTANCE_SCHEMA_URI, + parameters_schema_uri=_TEST_MODEL_PARAMETERS_SCHEMA_URI, + prediction_schema_uri=_TEST_MODEL_PREDICTION_SCHEMA_URI, + ), + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + true_input_data_config = gca_training_pipeline.InputDataConfig( + fraction_split=true_fraction_split, + dataset_id=mock_tabular_dataset.name, + gcs_destination=gca_io.GcsDestination( + output_uri_prefix=_TEST_BASE_OUTPUT_DIR + ), + ) + + true_training_pipeline = gca_training_pipeline.TrainingPipeline( + display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, + training_task_definition=schema.training_job.definition.custom_task, + training_task_inputs=json_format.ParseDict( + { + "worker_pool_specs": [true_worker_pool_spec], + "base_output_directory": { + "output_uri_prefix": _TEST_BASE_OUTPUT_DIR + }, + "service_account": _TEST_SERVICE_ACCOUNT, + "network": _TEST_NETWORK, + }, + struct_pb2.Value(), + ), + model_to_upload=true_managed_model, + input_data_config=true_input_data_config, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) - assert spec.pool_specs == true_pool_spec + mock_pipeline_service_create.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + training_pipeline=true_training_pipeline, + timeout=None, + ) - def test_chief_worker_pool_returns_spec(self): + assert job._gca_resource == make_training_pipeline( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) - chief_worker_spec = worker_spec_utils._DistributedTrainingSpec.chief_worker_pool( - replica_count=10, - machine_type=_TEST_MACHINE_TYPE, - accelerator_count=_TEST_ACCELERATOR_COUNT, - accelerator_type=_TEST_ACCELERATOR_TYPE, + mock_model_service_get.assert_called_once_with( + name=_TEST_MODEL_NAME, retry=base._DEFAULT_RETRY ) - true_pool_spec = [ - { - "machine_spec": { - "machine_type": _TEST_MACHINE_TYPE, - "accelerator_type": _TEST_ACCELERATOR_TYPE, - "accelerator_count": _TEST_ACCELERATOR_COUNT, - }, - "replica_count": 1, - }, - { - "machine_spec": { - "machine_type": _TEST_MACHINE_TYPE, - "accelerator_type": _TEST_ACCELERATOR_TYPE, - "accelerator_count": _TEST_ACCELERATOR_COUNT, - }, - "replica_count": 9, - }, - ] + assert model_from_job._gca_resource is mock_model_service_get.return_value - assert chief_worker_spec.pool_specs == true_pool_spec + assert job.get_model()._gca_resource is mock_model_service_get.return_value - def test_chief_worker_pool_returns_just_chief(self): + assert not job.has_failed - chief_worker_spec = worker_spec_utils._DistributedTrainingSpec.chief_worker_pool( - replica_count=1, + assert job.state == gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + def test_run_call_pipeline_service_create_with_tabular_dataset_with_timeout( + self, + mock_pipeline_service_create, + mock_pipeline_service_get, + mock_tabular_dataset, + mock_model_service_get, + sync, + ): + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_BUCKET_NAME, + encryption_spec_key_name=_TEST_DEFAULT_ENCRYPTION_KEY_NAME, + ) + + job = training_jobs.CustomPythonPackageTrainingJob( + display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, + python_package_gcs_uri=_TEST_OUTPUT_PYTHON_PACKAGE_PATH, + python_module_name=_TEST_PYTHON_MODULE_NAME, + container_uri=_TEST_TRAINING_CONTAINER_IMAGE, + model_serving_container_image_uri=_TEST_SERVING_CONTAINER_IMAGE, + model_serving_container_predict_route=_TEST_SERVING_CONTAINER_PREDICTION_ROUTE, + model_serving_container_health_route=_TEST_SERVING_CONTAINER_HEALTH_ROUTE, + model_serving_container_command=_TEST_MODEL_SERVING_CONTAINER_COMMAND, + model_serving_container_args=_TEST_MODEL_SERVING_CONTAINER_ARGS, + model_serving_container_environment_variables=_TEST_MODEL_SERVING_CONTAINER_ENVIRONMENT_VARIABLES, + model_serving_container_ports=_TEST_MODEL_SERVING_CONTAINER_PORTS, + model_description=_TEST_MODEL_DESCRIPTION, + model_instance_schema_uri=_TEST_MODEL_INSTANCE_SCHEMA_URI, + model_parameters_schema_uri=_TEST_MODEL_PARAMETERS_SCHEMA_URI, + model_prediction_schema_uri=_TEST_MODEL_PREDICTION_SCHEMA_URI, + ) + + model_from_job = job.run( + dataset=mock_tabular_dataset, + model_display_name=_TEST_MODEL_DISPLAY_NAME, + model_labels=_TEST_MODEL_LABELS, + base_output_dir=_TEST_BASE_OUTPUT_DIR, + service_account=_TEST_SERVICE_ACCOUNT, + network=_TEST_NETWORK, + args=_TEST_RUN_ARGS, + environment_variables=_TEST_ENVIRONMENT_VARIABLES, machine_type=_TEST_MACHINE_TYPE, - accelerator_count=_TEST_ACCELERATOR_COUNT, accelerator_type=_TEST_ACCELERATOR_TYPE, + accelerator_count=_TEST_ACCELERATOR_COUNT, + training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT, + validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, + test_fraction_split=_TEST_TEST_FRACTION_SPLIT, + sync=sync, + create_request_timeout=180.0, ) - true_pool_spec = [ - { - "machine_spec": { - "machine_type": _TEST_MACHINE_TYPE, - "accelerator_type": _TEST_ACCELERATOR_TYPE, - "accelerator_count": _TEST_ACCELERATOR_COUNT, - }, - "replica_count": 1, - } - ] + if not sync: + model_from_job.wait() - assert chief_worker_spec.pool_specs == true_pool_spec + true_args = _TEST_RUN_ARGS + true_env = [ + {"name": key, "value": value} + for key, value in _TEST_ENVIRONMENT_VARIABLES.items() + ] - def test_machine_spec_raise_with_more_than_one_chief_replica(self): + true_worker_pool_spec = { + "replica_count": _TEST_REPLICA_COUNT, + "machine_spec": { + "machine_type": _TEST_MACHINE_TYPE, + "accelerator_type": _TEST_ACCELERATOR_TYPE, + "accelerator_count": _TEST_ACCELERATOR_COUNT, + }, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, + "python_package_spec": { + "executor_image_uri": _TEST_TRAINING_CONTAINER_IMAGE, + "python_module": _TEST_PYTHON_MODULE_NAME, + "package_uris": [_TEST_OUTPUT_PYTHON_PACKAGE_PATH], + "args": true_args, + "env": true_env, + }, + } - spec = worker_spec_utils._DistributedTrainingSpec( - chief_spec=worker_spec_utils._MachineSpec( - replica_count=2, - machine_type=_TEST_MACHINE_TYPE, - accelerator_count=_TEST_ACCELERATOR_COUNT, - accelerator_type=_TEST_ACCELERATOR_TYPE, - ), + true_fraction_split = gca_training_pipeline.FractionSplit( + training_fraction=_TEST_TRAINING_FRACTION_SPLIT, + validation_fraction=_TEST_VALIDATION_FRACTION_SPLIT, + test_fraction=_TEST_TEST_FRACTION_SPLIT, ) - with pytest.raises(ValueError): - spec.pool_specs + env = [ + gca_env_var.EnvVar(name=str(key), value=str(value)) + for key, value in _TEST_MODEL_SERVING_CONTAINER_ENVIRONMENT_VARIABLES.items() + ] - def test_machine_spec_handles_missing_pools(self): + ports = [ + gca_model.Port(container_port=port) + for port in _TEST_MODEL_SERVING_CONTAINER_PORTS + ] - spec = worker_spec_utils._DistributedTrainingSpec( - chief_spec=worker_spec_utils._MachineSpec( - replica_count=1, - machine_type=_TEST_MACHINE_TYPE, - accelerator_count=_TEST_ACCELERATOR_COUNT, - accelerator_type=_TEST_ACCELERATOR_TYPE, + true_container_spec = gca_model.ModelContainerSpec( + image_uri=_TEST_SERVING_CONTAINER_IMAGE, + predict_route=_TEST_SERVING_CONTAINER_PREDICTION_ROUTE, + health_route=_TEST_SERVING_CONTAINER_HEALTH_ROUTE, + command=_TEST_MODEL_SERVING_CONTAINER_COMMAND, + args=_TEST_MODEL_SERVING_CONTAINER_ARGS, + env=env, + ports=ports, + ) + + true_managed_model = gca_model.Model( + display_name=_TEST_MODEL_DISPLAY_NAME, + labels=_TEST_MODEL_LABELS, + description=_TEST_MODEL_DESCRIPTION, + container_spec=true_container_spec, + predict_schemata=gca_model.PredictSchemata( + instance_schema_uri=_TEST_MODEL_INSTANCE_SCHEMA_URI, + parameters_schema_uri=_TEST_MODEL_PARAMETERS_SCHEMA_URI, + prediction_schema_uri=_TEST_MODEL_PREDICTION_SCHEMA_URI, ), - worker_spec=worker_spec_utils._MachineSpec(replica_count=0), - parameter_server_spec=worker_spec_utils._MachineSpec( - replica_count=3, - machine_type=_TEST_MACHINE_TYPE, - accelerator_count=_TEST_ACCELERATOR_COUNT, - accelerator_type=_TEST_ACCELERATOR_TYPE, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) + + true_input_data_config = gca_training_pipeline.InputDataConfig( + fraction_split=true_fraction_split, + dataset_id=mock_tabular_dataset.name, + gcs_destination=gca_io.GcsDestination( + output_uri_prefix=_TEST_BASE_OUTPUT_DIR ), - evaluator_spec=worker_spec_utils._MachineSpec(replica_count=0), ) - true_pool_spec = [ - { - "machine_spec": { - "machine_type": _TEST_MACHINE_TYPE, - "accelerator_type": _TEST_ACCELERATOR_TYPE, - "accelerator_count": _TEST_ACCELERATOR_COUNT, - }, - "replica_count": 1, - }, - {"machine_spec": {"machine_type": "n1-standard-4"}, "replica_count": 0}, - { - "machine_spec": { - "machine_type": _TEST_MACHINE_TYPE, - "accelerator_type": _TEST_ACCELERATOR_TYPE, - "accelerator_count": _TEST_ACCELERATOR_COUNT, + true_training_pipeline = gca_training_pipeline.TrainingPipeline( + display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, + training_task_definition=schema.training_job.definition.custom_task, + training_task_inputs=json_format.ParseDict( + { + "worker_pool_specs": [true_worker_pool_spec], + "base_output_directory": { + "output_uri_prefix": _TEST_BASE_OUTPUT_DIR + }, + "service_account": _TEST_SERVICE_ACCOUNT, + "network": _TEST_NETWORK, }, - "replica_count": 3, - }, - ] - - assert spec.pool_specs == true_pool_spec - - -class TestCustomPythonPackageTrainingJob: - def setup_method(self): - importlib.reload(initializer) - importlib.reload(aiplatform) + struct_pb2.Value(), + ), + model_to_upload=true_managed_model, + input_data_config=true_input_data_config, + encryption_spec=_TEST_DEFAULT_ENCRYPTION_SPEC, + ) - def teardown_method(self): - initializer.global_pool.shutdown(wait=True) + mock_pipeline_service_create.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + training_pipeline=true_training_pipeline, + timeout=180.0, + ) + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) - def test_run_call_pipeline_service_create_with_tabular_dataset( + def test_run_call_pipeline_service_create_with_tabular_dataset_with_timeout_not_explicitly_set( self, mock_pipeline_service_create, mock_pipeline_service_get, @@ -2977,6 +5135,7 @@ def test_run_call_pipeline_service_create_with_tabular_dataset( job = training_jobs.CustomPythonPackageTrainingJob( display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, python_package_gcs_uri=_TEST_OUTPUT_PYTHON_PACKAGE_PATH, python_module_name=_TEST_PYTHON_MODULE_NAME, container_uri=_TEST_TRAINING_CONTAINER_IMAGE, @@ -2996,19 +5155,18 @@ def test_run_call_pipeline_service_create_with_tabular_dataset( model_from_job = job.run( dataset=mock_tabular_dataset, model_display_name=_TEST_MODEL_DISPLAY_NAME, + model_labels=_TEST_MODEL_LABELS, base_output_dir=_TEST_BASE_OUTPUT_DIR, service_account=_TEST_SERVICE_ACCOUNT, network=_TEST_NETWORK, args=_TEST_RUN_ARGS, environment_variables=_TEST_ENVIRONMENT_VARIABLES, - replica_count=1, machine_type=_TEST_MACHINE_TYPE, accelerator_type=_TEST_ACCELERATOR_TYPE, accelerator_count=_TEST_ACCELERATOR_COUNT, training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT, validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, test_fraction_split=_TEST_TEST_FRACTION_SPLIT, - predefined_split_column_name=_TEST_PREDEFINED_SPLIT_COLUMN_NAME, sync=sync, ) @@ -3028,6 +5186,10 @@ def test_run_call_pipeline_service_create_with_tabular_dataset( "accelerator_type": _TEST_ACCELERATOR_TYPE, "accelerator_count": _TEST_ACCELERATOR_COUNT, }, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, "python_package_spec": { "executor_image_uri": _TEST_TRAINING_CONTAINER_IMAGE, "python_module": _TEST_PYTHON_MODULE_NAME, @@ -3065,6 +5227,7 @@ def test_run_call_pipeline_service_create_with_tabular_dataset( true_managed_model = gca_model.Model( display_name=_TEST_MODEL_DISPLAY_NAME, + labels=_TEST_MODEL_LABELS, description=_TEST_MODEL_DESCRIPTION, container_spec=true_container_spec, predict_schemata=gca_model.PredictSchemata( @@ -3077,9 +5240,6 @@ def test_run_call_pipeline_service_create_with_tabular_dataset( true_input_data_config = gca_training_pipeline.InputDataConfig( fraction_split=true_fraction_split, - predefined_split=gca_training_pipeline.PredefinedSplit( - key=_TEST_PREDEFINED_SPLIT_COLUMN_NAME - ), dataset_id=mock_tabular_dataset.name, gcs_destination=gca_io.GcsDestination( output_uri_prefix=_TEST_BASE_OUTPUT_DIR @@ -3088,6 +5248,7 @@ def test_run_call_pipeline_service_create_with_tabular_dataset( true_training_pipeline = gca_training_pipeline.TrainingPipeline( display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, training_task_definition=schema.training_job.definition.custom_task, training_task_inputs=json_format.ParseDict( { @@ -3108,22 +5269,13 @@ def test_run_call_pipeline_service_create_with_tabular_dataset( mock_pipeline_service_create.assert_called_once_with( parent=initializer.global_config.common_location_path(), training_pipeline=true_training_pipeline, + timeout=None, ) - assert job._gca_resource is mock_pipeline_service_get.return_value - - mock_model_service_get.assert_called_once_with(name=_TEST_MODEL_NAME) - - assert model_from_job._gca_resource is mock_model_service_get.return_value - - assert job.get_model()._gca_resource is mock_model_service_get.return_value - - assert not job.has_failed - - assert job.state == gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED - + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) - def test_run_call_pipeline_service_create_with_tabular_dataset_without_model_display_name( + def test_run_call_pipeline_service_create_with_tabular_dataset_without_model_display_name_nor_model_labels( self, mock_pipeline_service_create, mock_pipeline_service_get, @@ -3139,6 +5291,7 @@ def test_run_call_pipeline_service_create_with_tabular_dataset_without_model_dis job = training_jobs.CustomPythonPackageTrainingJob( display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, python_package_gcs_uri=_TEST_OUTPUT_PYTHON_PACKAGE_PATH, python_module_name=_TEST_PYTHON_MODULE_NAME, container_uri=_TEST_TRAINING_CONTAINER_IMAGE, @@ -3160,15 +5313,12 @@ def test_run_call_pipeline_service_create_with_tabular_dataset_without_model_dis # model_display_name=_TEST_MODEL_DISPLAY_NAME, base_output_dir=_TEST_BASE_OUTPUT_DIR, args=_TEST_RUN_ARGS, - replica_count=1, machine_type=_TEST_MACHINE_TYPE, accelerator_type=_TEST_ACCELERATOR_TYPE, accelerator_count=_TEST_ACCELERATOR_COUNT, - training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT, - validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, - test_fraction_split=_TEST_TEST_FRACTION_SPLIT, predefined_split_column_name=_TEST_PREDEFINED_SPLIT_COLUMN_NAME, sync=sync, + create_request_timeout=None, ) if not sync: @@ -3183,6 +5333,10 @@ def test_run_call_pipeline_service_create_with_tabular_dataset_without_model_dis "accelerator_type": _TEST_ACCELERATOR_TYPE, "accelerator_count": _TEST_ACCELERATOR_COUNT, }, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, "python_package_spec": { "executor_image_uri": _TEST_TRAINING_CONTAINER_IMAGE, "python_module": _TEST_PYTHON_MODULE_NAME, @@ -3191,12 +5345,6 @@ def test_run_call_pipeline_service_create_with_tabular_dataset_without_model_dis }, } - true_fraction_split = gca_training_pipeline.FractionSplit( - training_fraction=_TEST_TRAINING_FRACTION_SPLIT, - validation_fraction=_TEST_VALIDATION_FRACTION_SPLIT, - test_fraction=_TEST_TEST_FRACTION_SPLIT, - ) - env = [ gca_env_var.EnvVar(name=str(key), value=str(value)) for key, value in _TEST_MODEL_SERVING_CONTAINER_ENVIRONMENT_VARIABLES.items() @@ -3219,6 +5367,7 @@ def test_run_call_pipeline_service_create_with_tabular_dataset_without_model_dis true_managed_model = gca_model.Model( display_name=_TEST_DISPLAY_NAME + "-model", + labels=_TEST_LABELS, description=_TEST_MODEL_DESCRIPTION, container_spec=true_container_spec, predict_schemata=gca_model.PredictSchemata( @@ -3230,7 +5379,6 @@ def test_run_call_pipeline_service_create_with_tabular_dataset_without_model_dis ) true_input_data_config = gca_training_pipeline.InputDataConfig( - fraction_split=true_fraction_split, predefined_split=gca_training_pipeline.PredefinedSplit( key=_TEST_PREDEFINED_SPLIT_COLUMN_NAME ), @@ -3242,6 +5390,7 @@ def test_run_call_pipeline_service_create_with_tabular_dataset_without_model_dis true_training_pipeline = gca_training_pipeline.TrainingPipeline( display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, training_task_definition=schema.training_job.definition.custom_task, training_task_inputs=json_format.ParseDict( { @@ -3260,11 +5409,16 @@ def test_run_call_pipeline_service_create_with_tabular_dataset_without_model_dis mock_pipeline_service_create.assert_called_once_with( parent=initializer.global_config.common_location_path(), training_pipeline=true_training_pipeline, + timeout=None, ) - assert job._gca_resource is mock_pipeline_service_get.return_value + assert job._gca_resource == make_training_pipeline( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) - mock_model_service_get.assert_called_once_with(name=_TEST_MODEL_NAME) + mock_model_service_get.assert_called_once_with( + name=_TEST_MODEL_NAME, retry=base._DEFAULT_RETRY + ) assert model_from_job._gca_resource is mock_model_service_get.return_value @@ -3274,6 +5428,8 @@ def test_run_call_pipeline_service_create_with_tabular_dataset_without_model_dis assert job.state == gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) def test_run_call_pipeline_service_create_with_bigquery_destination( self, @@ -3311,15 +5467,15 @@ def test_run_call_pipeline_service_create_with_bigquery_destination( base_output_dir=_TEST_BASE_OUTPUT_DIR, bigquery_destination=_TEST_BIGQUERY_DESTINATION, args=_TEST_RUN_ARGS, - replica_count=1, machine_type=_TEST_MACHINE_TYPE, accelerator_type=_TEST_ACCELERATOR_TYPE, accelerator_count=_TEST_ACCELERATOR_COUNT, training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT, validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, test_fraction_split=_TEST_TEST_FRACTION_SPLIT, - predefined_split_column_name=_TEST_PREDEFINED_SPLIT_COLUMN_NAME, + timestamp_split_column_name=_TEST_TIMESTAMP_SPLIT_COLUMN_NAME, sync=sync, + create_request_timeout=None, ) if not sync: @@ -3334,6 +5490,10 @@ def test_run_call_pipeline_service_create_with_bigquery_destination( "accelerator_type": _TEST_ACCELERATOR_TYPE, "accelerator_count": _TEST_ACCELERATOR_COUNT, }, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, "python_package_spec": { "executor_image_uri": _TEST_TRAINING_CONTAINER_IMAGE, "python_module": _TEST_PYTHON_MODULE_NAME, @@ -3342,10 +5502,11 @@ def test_run_call_pipeline_service_create_with_bigquery_destination( }, } - true_fraction_split = gca_training_pipeline.FractionSplit( + true_timestamp_split = gca_training_pipeline.TimestampSplit( training_fraction=_TEST_TRAINING_FRACTION_SPLIT, validation_fraction=_TEST_VALIDATION_FRACTION_SPLIT, test_fraction=_TEST_TEST_FRACTION_SPLIT, + key=_TEST_TIMESTAMP_SPLIT_COLUMN_NAME, ) env = [ @@ -3381,10 +5542,7 @@ def test_run_call_pipeline_service_create_with_bigquery_destination( ) true_input_data_config = gca_training_pipeline.InputDataConfig( - fraction_split=true_fraction_split, - predefined_split=gca_training_pipeline.PredefinedSplit( - key=_TEST_PREDEFINED_SPLIT_COLUMN_NAME - ), + timestamp_split=true_timestamp_split, dataset_id=mock_tabular_dataset.name, bigquery_destination=gca_io.BigQueryDestination( output_uri=_TEST_BIGQUERY_DESTINATION @@ -3411,11 +5569,16 @@ def test_run_call_pipeline_service_create_with_bigquery_destination( mock_pipeline_service_create.assert_called_once_with( parent=initializer.global_config.common_location_path(), training_pipeline=true_training_pipeline, + timeout=None, ) - assert job._gca_resource is mock_pipeline_service_get.return_value + assert job._gca_resource == make_training_pipeline( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) - mock_model_service_get.assert_called_once_with(name=_TEST_MODEL_NAME) + mock_model_service_get.assert_called_once_with( + name=_TEST_MODEL_NAME, retry=base._DEFAULT_RETRY + ) assert model_from_job._gca_resource is mock_model_service_get.return_value @@ -3425,6 +5588,8 @@ def test_run_call_pipeline_service_create_with_bigquery_destination( assert job.state == gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.usefixtures( "mock_pipeline_service_create", "mock_pipeline_service_get", @@ -3433,7 +5598,9 @@ def test_run_call_pipeline_service_create_with_bigquery_destination( ) @pytest.mark.parametrize("sync", [True, False]) def test_run_called_twice_raises( - self, mock_tabular_dataset, sync, + self, + mock_tabular_dataset, + sync, ): aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME) @@ -3456,10 +5623,8 @@ def test_run_called_twice_raises( accelerator_type=_TEST_ACCELERATOR_TYPE, accelerator_count=_TEST_ACCELERATOR_COUNT, model_display_name=_TEST_MODEL_DISPLAY_NAME, - training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT, - validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, - test_fraction_split=_TEST_TEST_FRACTION_SPLIT, sync=sync, + create_request_timeout=None, ) with pytest.raises(RuntimeError): @@ -3472,10 +5637,8 @@ def test_run_called_twice_raises( accelerator_type=_TEST_ACCELERATOR_TYPE, accelerator_count=_TEST_ACCELERATOR_COUNT, model_display_name=_TEST_MODEL_DISPLAY_NAME, - training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT, - validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, - test_fraction_split=_TEST_TEST_FRACTION_SPLIT, sync=sync, + create_request_timeout=None, ) if not sync: @@ -3516,8 +5679,44 @@ def test_run_with_invalid_accelerator_type_raises( validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, test_fraction_split=_TEST_TEST_FRACTION_SPLIT, sync=sync, + create_request_timeout=None, + ) + + @pytest.mark.parametrize("sync", [True, False]) + def test_run_with_two_split_raises( + self, + mock_pipeline_service_create, + mock_python_package_to_gcs, + mock_tabular_dataset, + mock_model_service_get, + sync, + ): + aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME) + + job = training_jobs.CustomPythonPackageTrainingJob( + display_name=_TEST_DISPLAY_NAME, + python_package_gcs_uri=_TEST_OUTPUT_PYTHON_PACKAGE_PATH, + python_module_name=_TEST_PYTHON_MODULE_NAME, + container_uri=_TEST_TRAINING_CONTAINER_IMAGE, + ) + + with pytest.raises(ValueError): + job.run( + dataset=mock_tabular_dataset, + replica_count=1, + machine_type=_TEST_MACHINE_TYPE, + accelerator_type=_TEST_INVALID_ACCELERATOR_TYPE, + accelerator_count=_TEST_ACCELERATOR_COUNT, + predefined_split_column_name=_TEST_PREDEFINED_SPLIT_COLUMN_NAME, + training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT, + validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, + test_fraction_split=_TEST_TEST_FRACTION_SPLIT, + sync=sync, + create_request_timeout=None, ) + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) def test_run_with_incomplete_model_info_raises_with_model_to_upload( self, @@ -3550,8 +5749,11 @@ def test_run_with_incomplete_model_info_raises_with_model_to_upload( validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, test_fraction_split=_TEST_TEST_FRACTION_SPLIT, sync=sync, + create_request_timeout=None, ) + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) def test_run_call_pipeline_service_create_with_no_dataset( self, @@ -3576,7 +5778,6 @@ def test_run_call_pipeline_service_create_with_no_dataset( model_display_name=_TEST_MODEL_DISPLAY_NAME, base_output_dir=_TEST_BASE_OUTPUT_DIR, args=_TEST_RUN_ARGS, - replica_count=1, machine_type=_TEST_MACHINE_TYPE, accelerator_type=_TEST_ACCELERATOR_TYPE, accelerator_count=_TEST_ACCELERATOR_COUNT, @@ -3584,6 +5785,7 @@ def test_run_call_pipeline_service_create_with_no_dataset( validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, test_fraction_split=_TEST_TEST_FRACTION_SPLIT, sync=sync, + create_request_timeout=None, ) if not sync: @@ -3598,6 +5800,10 @@ def test_run_call_pipeline_service_create_with_no_dataset( "accelerator_type": _TEST_ACCELERATOR_TYPE, "accelerator_count": _TEST_ACCELERATOR_COUNT, }, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, "python_package_spec": { "executor_image_uri": _TEST_TRAINING_CONTAINER_IMAGE, "python_module": _TEST_PYTHON_MODULE_NAME, @@ -3634,21 +5840,128 @@ def test_run_call_pipeline_service_create_with_no_dataset( mock_pipeline_service_create.assert_called_once_with( parent=initializer.global_config.common_location_path(), training_pipeline=true_training_pipeline, + timeout=None, ) - assert job._gca_resource is mock_pipeline_service_get.return_value + assert job._gca_resource == make_training_pipeline( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) - mock_model_service_get.assert_called_once_with(name=_TEST_MODEL_NAME) + mock_model_service_get.assert_called_once_with( + name=_TEST_MODEL_NAME, retry=base._DEFAULT_RETRY + ) assert model_from_job._gca_resource is mock_model_service_get.return_value + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.usefixtures( + "mock_pipeline_service_create_with_enable_web_access", + "mock_pipeline_service_get_with_enable_web_access", + "mock_get_backing_custom_job_with_enable_web_access", + ) + @pytest.mark.parametrize("sync", [True, False]) + def test_run_call_pipeline_service_create_with_enable_web_access( + self, sync, caplog + ): + + caplog.set_level(logging.INFO) + + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_BUCKET_NAME, + credentials=_TEST_CREDENTIALS, + ) + + job = training_jobs.CustomPythonPackageTrainingJob( + display_name=_TEST_DISPLAY_NAME, + python_package_gcs_uri=_TEST_OUTPUT_PYTHON_PACKAGE_PATH, + python_module_name=_TEST_PYTHON_MODULE_NAME, + container_uri=_TEST_TRAINING_CONTAINER_IMAGE, + ) + + job.run( + base_output_dir=_TEST_BASE_OUTPUT_DIR, + args=_TEST_RUN_ARGS, + machine_type=_TEST_MACHINE_TYPE, + accelerator_type=_TEST_ACCELERATOR_TYPE, + accelerator_count=_TEST_ACCELERATOR_COUNT, + enable_web_access=_TEST_ENABLE_WEB_ACCESS, + sync=sync, + create_request_timeout=None, + ) + + if not sync: + job.wait() + + print(caplog.text) + assert "workerpool0-0" in caplog.text + assert job._gca_resource == make_training_pipeline_with_enable_web_access( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.usefixtures( + "mock_pipeline_service_create_with_scheduling", + "mock_pipeline_service_get_with_scheduling", + ) + @pytest.mark.parametrize("sync", [True, False]) + def test_run_call_pipeline_service_create_with_scheduling(self, sync, caplog): + + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_BUCKET_NAME, + credentials=_TEST_CREDENTIALS, + ) + + job = training_jobs.CustomPythonPackageTrainingJob( + display_name=_TEST_DISPLAY_NAME, + python_package_gcs_uri=_TEST_OUTPUT_PYTHON_PACKAGE_PATH, + python_module_name=_TEST_PYTHON_MODULE_NAME, + container_uri=_TEST_TRAINING_CONTAINER_IMAGE, + ) + + job.run( + base_output_dir=_TEST_BASE_OUTPUT_DIR, + args=_TEST_RUN_ARGS, + machine_type=_TEST_MACHINE_TYPE, + accelerator_type=_TEST_ACCELERATOR_TYPE, + accelerator_count=_TEST_ACCELERATOR_COUNT, + timeout=_TEST_TIMEOUT, + restart_job_on_worker_restart=_TEST_RESTART_JOB_ON_WORKER_RESTART, + sync=sync, + create_request_timeout=None, + ) + + if not sync: + job.wait() + + assert job._gca_resource == make_training_pipeline_with_scheduling( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) + + assert ( + job._gca_resource.state + == gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) + assert job._gca_resource.training_task_inputs["timeout"] == f"{_TEST_TIMEOUT}s" + assert ( + job._gca_resource.training_task_inputs["restart_job_on_worker_restart"] + == _TEST_RESTART_JOB_ON_WORKER_RESTART + ) + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.usefixtures( "mock_pipeline_service_create_with_no_model_to_upload", "mock_pipeline_service_get_with_no_model_to_upload", ) @pytest.mark.parametrize("sync", [True, False]) def test_run_returns_none_if_no_model_to_upload( - self, mock_tabular_dataset, sync, + self, + mock_tabular_dataset, + sync, ): aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME) @@ -3671,17 +5984,22 @@ def test_run_returns_none_if_no_model_to_upload( validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, test_fraction_split=_TEST_TEST_FRACTION_SPLIT, sync=sync, + create_request_timeout=None, ) assert model is None + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.usefixtures( "mock_pipeline_service_create_with_no_model_to_upload", "mock_pipeline_service_get_with_no_model_to_upload", ) @pytest.mark.parametrize("sync", [True, False]) def test_get_model_raises_if_no_model_to_upload( - self, mock_tabular_dataset, sync, + self, + mock_tabular_dataset, + sync, ): aiplatform.init(project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME) @@ -3704,6 +6022,7 @@ def test_get_model_raises_if_no_model_to_upload( validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, test_fraction_split=_TEST_TEST_FRACTION_SPLIT, sync=sync, + create_request_timeout=None, ) if not sync: @@ -3712,6 +6031,8 @@ def test_get_model_raises_if_no_model_to_upload( with pytest.raises(RuntimeError): job.get_model() + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) def test_run_raises_if_pipeline_fails( self, @@ -3738,9 +6059,6 @@ def test_run_raises_if_pipeline_fails( machine_type=_TEST_MACHINE_TYPE, accelerator_type=_TEST_ACCELERATOR_TYPE, accelerator_count=_TEST_ACCELERATOR_COUNT, - training_fraction_split=_TEST_TRAINING_FRACTION_SPLIT, - validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, - test_fraction_split=_TEST_TEST_FRACTION_SPLIT, sync=sync, ) @@ -3784,6 +6102,8 @@ def test_run_raises_if_no_staging_bucket(self): container_uri=_TEST_TRAINING_CONTAINER_IMAGE, ) + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) def test_run_call_pipeline_service_create_distributed_training( self, @@ -3821,6 +6141,7 @@ def test_run_call_pipeline_service_create_distributed_training( validation_fraction_split=_TEST_VALIDATION_FRACTION_SPLIT, test_fraction_split=_TEST_TEST_FRACTION_SPLIT, sync=sync, + create_request_timeout=None, ) if not sync: @@ -3836,6 +6157,10 @@ def test_run_call_pipeline_service_create_distributed_training( "accelerator_type": _TEST_ACCELERATOR_TYPE, "accelerator_count": _TEST_ACCELERATOR_COUNT, }, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, "python_package_spec": { "executor_image_uri": _TEST_TRAINING_CONTAINER_IMAGE, "python_module": _TEST_PYTHON_MODULE_NAME, @@ -3850,6 +6175,10 @@ def test_run_call_pipeline_service_create_distributed_training( "accelerator_type": _TEST_ACCELERATOR_TYPE, "accelerator_count": _TEST_ACCELERATOR_COUNT, }, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, "python_package_spec": { "executor_image_uri": _TEST_TRAINING_CONTAINER_IMAGE, "python_module": _TEST_PYTHON_MODULE_NAME, @@ -3908,11 +6237,16 @@ def test_run_call_pipeline_service_create_distributed_training( mock_pipeline_service_create.assert_called_once_with( parent=initializer.global_config.common_location_path(), training_pipeline=true_training_pipeline, + timeout=None, ) - assert job._gca_resource is mock_pipeline_service_get.return_value + assert job._gca_resource == make_training_pipeline( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) - mock_model_service_get.assert_called_once_with(name=_TEST_MODEL_NAME) + mock_model_service_get.assert_called_once_with( + name=_TEST_MODEL_NAME, retry=base._DEFAULT_RETRY + ) assert model_from_job._gca_resource is mock_model_service_get.return_value @@ -3922,8 +6256,127 @@ def test_run_call_pipeline_service_create_distributed_training( assert job.state == gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) @pytest.mark.parametrize("sync", [True, False]) - def test_run_call_pipeline_service_create_with_nontabular_dataset( + def test_run_call_pipeline_service_create_distributed_training_with_reduction_server( + self, + mock_pipeline_service_create_with_no_model_to_upload, + mock_pipeline_service_get_with_no_model_to_upload, + sync, + ): + aiplatform.init( + project=_TEST_PROJECT, + staging_bucket=_TEST_BUCKET_NAME, + credentials=_TEST_CREDENTIALS, + ) + + job = training_jobs.CustomPythonPackageTrainingJob( + display_name=_TEST_DISPLAY_NAME, + python_package_gcs_uri=_TEST_OUTPUT_PYTHON_PACKAGE_PATH, + python_module_name=_TEST_PYTHON_MODULE_NAME, + container_uri=_TEST_TRAINING_CONTAINER_IMAGE, + ) + + job.run( + base_output_dir=_TEST_BASE_OUTPUT_DIR, + args=_TEST_RUN_ARGS, + replica_count=10, + machine_type=_TEST_MACHINE_TYPE, + accelerator_type=_TEST_ACCELERATOR_TYPE, + accelerator_count=_TEST_ACCELERATOR_COUNT, + reduction_server_replica_count=_TEST_REDUCTION_SERVER_REPLICA_COUNT, + reduction_server_machine_type=_TEST_REDUCTION_SERVER_MACHINE_TYPE, + reduction_server_container_uri=_TEST_REDUCTION_SERVER_CONTAINER_URI, + sync=sync, + create_request_timeout=None, + ) + + if not sync: + job.wait() + + true_args = _TEST_RUN_ARGS + + true_worker_pool_spec = [ + { + "replica_count": 1, + "machine_spec": { + "machine_type": _TEST_MACHINE_TYPE, + "accelerator_type": _TEST_ACCELERATOR_TYPE, + "accelerator_count": _TEST_ACCELERATOR_COUNT, + }, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, + "python_package_spec": { + "executor_image_uri": _TEST_TRAINING_CONTAINER_IMAGE, + "python_module": _TEST_PYTHON_MODULE_NAME, + "package_uris": [_TEST_OUTPUT_PYTHON_PACKAGE_PATH], + "args": true_args, + }, + }, + { + "replica_count": 9, + "machine_spec": { + "machine_type": _TEST_MACHINE_TYPE, + "accelerator_type": _TEST_ACCELERATOR_TYPE, + "accelerator_count": _TEST_ACCELERATOR_COUNT, + }, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, + "python_package_spec": { + "executor_image_uri": _TEST_TRAINING_CONTAINER_IMAGE, + "python_module": _TEST_PYTHON_MODULE_NAME, + "package_uris": [_TEST_OUTPUT_PYTHON_PACKAGE_PATH], + "args": true_args, + }, + }, + { + "replica_count": _TEST_REDUCTION_SERVER_REPLICA_COUNT, + "machine_spec": {"machine_type": _TEST_REDUCTION_SERVER_MACHINE_TYPE}, + "container_spec": {"image_uri": _TEST_REDUCTION_SERVER_CONTAINER_URI}, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, + }, + ] + + true_training_pipeline = gca_training_pipeline.TrainingPipeline( + display_name=_TEST_DISPLAY_NAME, + training_task_definition=schema.training_job.definition.custom_task, + training_task_inputs=json_format.ParseDict( + { + "worker_pool_specs": true_worker_pool_spec, + "base_output_directory": { + "output_uri_prefix": _TEST_BASE_OUTPUT_DIR + }, + }, + struct_pb2.Value(), + ), + ) + + mock_pipeline_service_create_with_no_model_to_upload.assert_called_once_with( + parent=initializer.global_config.common_location_path(), + training_pipeline=true_training_pipeline, + timeout=None, + ) + + assert job._gca_resource == make_training_pipeline_with_no_model_upload( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) + + assert not job.has_failed + + assert job.state == gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + + @mock.patch.object(training_jobs, "_JOB_WAIT_TIME", 1) + @mock.patch.object(training_jobs, "_LOG_WAIT_TIME", 1) + @pytest.mark.parametrize("sync", [True, False]) + def test_run_call_pipeline_service_create_with_nontabular_dataset_without_model_display_name_nor_model_labels( self, mock_pipeline_service_create, mock_pipeline_service_get, @@ -3933,11 +6386,13 @@ def test_run_call_pipeline_service_create_with_nontabular_dataset( sync, ): aiplatform.init( - project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME, + project=_TEST_PROJECT, + staging_bucket=_TEST_BUCKET_NAME, ) job = training_jobs.CustomPythonPackageTrainingJob( display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, python_package_gcs_uri=_TEST_OUTPUT_PYTHON_PACKAGE_PATH, python_module_name=_TEST_PYTHON_MODULE_NAME, container_uri=_TEST_TRAINING_CONTAINER_IMAGE, @@ -3959,12 +6414,16 @@ def test_run_call_pipeline_service_create_with_nontabular_dataset( annotation_schema_uri=_TEST_ANNOTATION_SCHEMA_URI, base_output_dir=_TEST_BASE_OUTPUT_DIR, args=_TEST_RUN_ARGS, - replica_count=1, machine_type=_TEST_MACHINE_TYPE, accelerator_type=_TEST_ACCELERATOR_TYPE, accelerator_count=_TEST_ACCELERATOR_COUNT, - model_display_name=_TEST_MODEL_DISPLAY_NAME, + service_account=_TEST_SERVICE_ACCOUNT, + tensorboard=_TEST_TENSORBOARD_RESOURCE_NAME, + training_filter_split=_TEST_TRAINING_FILTER_SPLIT, + validation_filter_split=_TEST_VALIDATION_FILTER_SPLIT, + test_filter_split=_TEST_TEST_FILTER_SPLIT, sync=sync, + create_request_timeout=None, ) if not sync: @@ -3979,6 +6438,10 @@ def test_run_call_pipeline_service_create_with_nontabular_dataset( "accelerator_type": _TEST_ACCELERATOR_TYPE, "accelerator_count": _TEST_ACCELERATOR_COUNT, }, + "disk_spec": { + "boot_disk_type": _TEST_BOOT_DISK_TYPE_DEFAULT, + "boot_disk_size_gb": _TEST_BOOT_DISK_SIZE_GB_DEFAULT, + }, "python_package_spec": { "executor_image_uri": _TEST_TRAINING_CONTAINER_IMAGE, "python_module": _TEST_PYTHON_MODULE_NAME, @@ -3987,10 +6450,10 @@ def test_run_call_pipeline_service_create_with_nontabular_dataset( }, } - true_fraction_split = gca_training_pipeline.FractionSplit( - training_fraction=_TEST_DEFAULT_TRAINING_FRACTION_SPLIT, - validation_fraction=_TEST_DEFAULT_VALIDATION_FRACTION_SPLIT, - test_fraction=_TEST_DEFAULT_TEST_FRACTION_SPLIT, + true_filter_split = gca_training_pipeline.FilterSplit( + training_filter=_TEST_TRAINING_FILTER_SPLIT, + validation_filter=_TEST_VALIDATION_FILTER_SPLIT, + test_filter=_TEST_TEST_FILTER_SPLIT, ) env = [ @@ -4014,7 +6477,8 @@ def test_run_call_pipeline_service_create_with_nontabular_dataset( ) true_managed_model = gca_model.Model( - display_name=_TEST_MODEL_DISPLAY_NAME, + display_name=_TEST_DISPLAY_NAME + "-model", + labels=_TEST_LABELS, description=_TEST_MODEL_DESCRIPTION, container_spec=true_container_spec, predict_schemata=gca_model.PredictSchemata( @@ -4025,7 +6489,7 @@ def test_run_call_pipeline_service_create_with_nontabular_dataset( ) true_input_data_config = gca_training_pipeline.InputDataConfig( - fraction_split=true_fraction_split, + filter_split=true_filter_split, dataset_id=mock_nontabular_dataset.name, annotation_schema_uri=_TEST_ANNOTATION_SCHEMA_URI, gcs_destination=gca_io.GcsDestination( @@ -4035,6 +6499,7 @@ def test_run_call_pipeline_service_create_with_nontabular_dataset( true_training_pipeline = gca_training_pipeline.TrainingPipeline( display_name=_TEST_DISPLAY_NAME, + labels=_TEST_LABELS, training_task_definition=schema.training_job.definition.custom_task, training_task_inputs=json_format.ParseDict( { @@ -4042,6 +6507,8 @@ def test_run_call_pipeline_service_create_with_nontabular_dataset( "base_output_directory": { "output_uri_prefix": _TEST_BASE_OUTPUT_DIR }, + "service_account": _TEST_SERVICE_ACCOUNT, + "tensorboard": _TEST_TENSORBOARD_RESOURCE_NAME, }, struct_pb2.Value(), ), @@ -4052,11 +6519,16 @@ def test_run_call_pipeline_service_create_with_nontabular_dataset( mock_pipeline_service_create.assert_called_once_with( parent=initializer.global_config.common_location_path(), training_pipeline=true_training_pipeline, + timeout=None, ) - assert job._gca_resource is mock_pipeline_service_get.return_value + assert job._gca_resource == make_training_pipeline( + gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + ) - mock_model_service_get.assert_called_once_with(name=_TEST_MODEL_NAME) + mock_model_service_get.assert_called_once_with( + name=_TEST_MODEL_NAME, retry=base._DEFAULT_RETRY + ) assert model_from_job._gca_resource is mock_model_service_get.return_value @@ -4066,11 +6538,15 @@ def test_run_call_pipeline_service_create_with_nontabular_dataset( assert job.state == gca_pipeline_state.PipelineState.PIPELINE_STATE_SUCCEEDED + assert job._has_logged_custom_job + def test_run_call_pipeline_service_create_with_nontabular_dataset_raises_if_annotation_schema_uri( - self, mock_nontabular_dataset, + self, + mock_nontabular_dataset, ): aiplatform.init( - project=_TEST_PROJECT, staging_bucket=_TEST_BUCKET_NAME, + project=_TEST_PROJECT, + staging_bucket=_TEST_BUCKET_NAME, ) job = training_jobs.CustomPythonPackageTrainingJob( diff --git a/tests/unit/aiplatform/test_training_utils.py b/tests/unit/aiplatform/test_training_utils.py new file mode 100644 index 0000000000..24a60d95ff --- /dev/null +++ b/tests/unit/aiplatform/test_training_utils.py @@ -0,0 +1,282 @@ +# -*- coding: utf-8 -*- + +# 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 importlib import reload +import filecmp +import json +import os +import pytest +import tempfile + +from google.cloud.aiplatform.training_utils import environment_variables +from google.cloud.aiplatform.utils import source_utils +from unittest import mock + +_TEST_TRAINING_DATA_URI = "gs://training-data-uri" +_TEST_VALIDATION_DATA_URI = "gs://test-validation-data-uri" +_TEST_TEST_DATA_URI = "gs://test-data-uri" +_TEST_MODEL_DIR = "gs://test-model-dir" +_TEST_CHECKPOINT_DIR = "gs://test-checkpoint-dir" +_TEST_TENSORBOARD_LOG_DIR = "gs://test-tensorboard-log-dir" +_TEST_CLUSTER_SPEC = """{ + "cluster": { + "worker_pools":[ + { + "index":0, + "replicas":[ + "training-workerpool0-ab-0:2222" + ] + }, + { + "index":1, + "replicas":[ + "training-workerpool1-ab-0:2222", + "training-workerpool1-ab-1:2222" + ] + } + ] + }, + "environment": "cloud", + "task": { + "worker_pool_index":0, + "replica_index":0, + "trial":"TRIAL_ID" + } +}""" +_TEST_AIP_TF_PROFILER_PORT = "1234" +_TEST_TENSORBOARD_API_URI = "http://testuri.com" +_TEST_TENSORBOARD_RESOURCE_NAME = ( + "projects/myproj/locations/us-central1/tensorboards/1234" +) +_TEST_CLOUD_ML_JOB_ID = "myjob" +_TEST_AIP_HTTP_HANDLER_PORT = "5678" + + +class TestTrainingUtils: + @pytest.fixture + def mock_environment(self): + env_vars = { + "AIP_TRAINING_DATA_URI": _TEST_TRAINING_DATA_URI, + "AIP_VALIDATION_DATA_URI": _TEST_VALIDATION_DATA_URI, + "AIP_TEST_DATA_URI": _TEST_TEST_DATA_URI, + "AIP_MODEL_DIR": _TEST_MODEL_DIR, + "AIP_CHECKPOINT_DIR": _TEST_CHECKPOINT_DIR, + "AIP_TENSORBOARD_LOG_DIR": _TEST_TENSORBOARD_LOG_DIR, + "AIP_TF_PROFILER_PORT": _TEST_AIP_TF_PROFILER_PORT, + "AIP_HTTP_HANDLER_PORT": _TEST_AIP_HTTP_HANDLER_PORT, + "AIP_TENSORBOARD_API_URI": _TEST_TENSORBOARD_API_URI, + "AIP_TENSORBOARD_RESOURCE_NAME": _TEST_TENSORBOARD_RESOURCE_NAME, + "CLOUD_ML_JOB_ID": _TEST_CLOUD_ML_JOB_ID, + "CLUSTER_SPEC": _TEST_CLUSTER_SPEC, + "TF_CONFIG": _TEST_CLUSTER_SPEC, + } + with mock.patch.dict(os.environ, env_vars, clear=True): + yield + + @pytest.mark.usefixtures("mock_environment") + def test_training_data_uri(self): + reload(environment_variables) + assert environment_variables.training_data_uri == _TEST_TRAINING_DATA_URI + + def test_training_data_uri_none(self): + reload(environment_variables) + assert environment_variables.training_data_uri is None + + @pytest.mark.usefixtures("mock_environment") + def test_validation_data_uri(self): + reload(environment_variables) + assert environment_variables.validation_data_uri == _TEST_VALIDATION_DATA_URI + + def test_validation_data_uri_none(self): + reload(environment_variables) + assert environment_variables.validation_data_uri is None + + @pytest.mark.usefixtures("mock_environment") + def test_test_data_uri(self): + reload(environment_variables) + assert environment_variables.test_data_uri == _TEST_TEST_DATA_URI + + def test_test_data_uri_none(self): + reload(environment_variables) + assert environment_variables.test_data_uri is None + + @pytest.mark.usefixtures("mock_environment") + def test_model_dir(self): + reload(environment_variables) + assert environment_variables.model_dir == _TEST_MODEL_DIR + + def test_model_dir_none(self): + reload(environment_variables) + assert environment_variables.model_dir is None + + @pytest.mark.usefixtures("mock_environment") + def test_checkpoint_dir(self): + reload(environment_variables) + assert environment_variables.checkpoint_dir == _TEST_CHECKPOINT_DIR + + def test_checkpoint_dir_none(self): + reload(environment_variables) + assert environment_variables.checkpoint_dir is None + + @pytest.mark.usefixtures("mock_environment") + def test_tensorboard_log_dir(self): + reload(environment_variables) + assert environment_variables.tensorboard_log_dir == _TEST_TENSORBOARD_LOG_DIR + + def test_tensorboard_log_dir_none(self): + reload(environment_variables) + assert environment_variables.tensorboard_log_dir is None + + @pytest.mark.usefixtures("mock_environment") + def test_cluster_spec(self): + reload(environment_variables) + assert environment_variables.cluster_spec == json.loads(_TEST_CLUSTER_SPEC) + + def test_cluster_spec_none(self): + reload(environment_variables) + assert environment_variables.cluster_spec is None + + @pytest.mark.usefixtures("mock_environment") + def test_tf_config(self): + reload(environment_variables) + assert environment_variables.tf_config == json.loads(_TEST_CLUSTER_SPEC) + + def test_tf_config_none(self): + reload(environment_variables) + assert environment_variables.tf_config is None + + @pytest.mark.usefixtures("mock_environment") + def test_tf_profiler_port(self): + reload(environment_variables) + assert environment_variables.tf_profiler_port == _TEST_AIP_TF_PROFILER_PORT + + def test_tf_profiler_port_none(self): + reload(environment_variables) + assert environment_variables.tf_profiler_port is None + + @pytest.mark.usefixtures("mock_environment") + def test_tensorboard_api_uri(self): + reload(environment_variables) + assert environment_variables.tensorboard_api_uri == _TEST_TENSORBOARD_API_URI + + def test_tensorboard_api_uri_none(self): + reload(environment_variables) + assert environment_variables.tensorboard_api_uri is None + + @pytest.mark.usefixtures("mock_environment") + def test_tensorboard_resource_name(self): + reload(environment_variables) + assert ( + environment_variables.tensorboard_resource_name + == _TEST_TENSORBOARD_RESOURCE_NAME + ) + + def test_tensorboard_resource_name_none(self): + reload(environment_variables) + assert environment_variables.tensorboard_resource_name is None + + @pytest.mark.usefixtures("mock_environment") + def test_cloud_ml_job_id(self): + reload(environment_variables) + assert environment_variables.cloud_ml_job_id == _TEST_CLOUD_ML_JOB_ID + + def test_cloud_ml_job_id_none(self): + reload(environment_variables) + assert environment_variables.cloud_ml_job_id is None + + @pytest.mark.usefixtures("mock_environment") + def test_http_handler_port(self): + reload(environment_variables) + assert environment_variables.http_handler_port == _TEST_AIP_HTTP_HANDLER_PORT + + def test_http_handler_port_none(self): + reload(environment_variables) + assert environment_variables.http_handler_port is None + + @pytest.fixture() + def mock_temp_file_name(self): + # Create random files + # tmpdirname = tempfile.TemporaryDirectory() + file = tempfile.NamedTemporaryFile() + + with open(file.name, "w") as handle: + handle.write("test") + + yield file.name + + file.close() + + def test_package_file(self, mock_temp_file_name): + # Test that the packager properly copies the source file to the destination file + + packager = source_utils._TrainingScriptPythonPackager( + script_path=mock_temp_file_name + ) + + with tempfile.TemporaryDirectory() as destination_directory_name: + _ = packager.make_package(package_directory=destination_directory_name) + + # Check that contents of source_distribution_path is the same as destination_directory_name + destination_inner_path = f"{destination_directory_name}/{packager._TRAINER_FOLDER}/{packager._ROOT_MODULE}/{packager.task_module_name}.py" + + assert filecmp.cmp( + mock_temp_file_name, destination_inner_path, shallow=False + ) + + @pytest.fixture() + def mock_temp_folder_name(self): + # Create random folder + folder = tempfile.TemporaryDirectory() + + file = tempfile.NamedTemporaryFile(dir=folder.name) + + # Create random file in the folder + with open(file.name, "w") as handle: + handle.write("test") + + yield folder.name + + file.close() + + folder.cleanup() + + def test_package_folder(self, mock_temp_folder_name): + # Test that the packager properly copies the source folder to the destination folder + + packager = source_utils._TrainingScriptPythonPackager( + script_path=mock_temp_folder_name + ) + + with tempfile.TemporaryDirectory() as destination_directory_name: + # Add an existing file into the destination directory to check if it gets deleted + existing_file = tempfile.NamedTemporaryFile(dir=destination_directory_name) + + with open(existing_file.name, "w") as handle: + handle.write("existing") + + _ = packager.make_package(package_directory=destination_directory_name) + + # Check that contents of source_distribution_path is the same as destination_directory_name + destination_inner_path = f"{destination_directory_name}/{packager._TRAINER_FOLDER}/{packager._ROOT_MODULE}" + + dcmp = filecmp.dircmp(mock_temp_folder_name, destination_inner_path) + + assert len(dcmp.diff_files) == 0 + assert len(dcmp.left_only) == 0 + assert len(dcmp.right_only) == 0 + + existing_file.close() diff --git a/tests/unit/aiplatform/test_uploader.py b/tests/unit/aiplatform/test_uploader.py index c63f729fd3..3d064075b9 100644 --- a/tests/unit/aiplatform/test_uploader.py +++ b/tests/unit/aiplatform/test_uploader.py @@ -16,9 +16,12 @@ # """Tests for uploader.py.""" +import datetime +import functools import logging import os import re +import tempfile from unittest import mock import grpc @@ -39,23 +42,25 @@ import tensorflow as tf from google.api_core import datetime_helpers -import google.cloud.aiplatform.tensorboard.uploader as uploader_lib +from google.cloud.aiplatform.tensorboard import uploader_utils +from google.cloud.aiplatform.tensorboard.plugins.tf_profiler import profile_uploader +from google.cloud.aiplatform.tensorboard import uploader as uploader_lib from google.cloud import storage -from google.cloud.aiplatform.compat.services import tensorboard_service_client_v1beta1 -from google.cloud.aiplatform_v1beta1.services.tensorboard_service.transports import ( - grpc as transports_grpc, -) -from google.cloud.aiplatform.compat.types import ( - tensorboard_data_v1beta1 as tensorboard_data, +from google.cloud.aiplatform.compat.services import ( + tensorboard_service_client, ) -from google.cloud.aiplatform.compat.types import ( - tensorboard_experiment_v1beta1 as tensorboard_experiment_type, +from google.cloud.aiplatform_v1.services.tensorboard_service.transports import ( + grpc as transports_grpc, ) + +from google.cloud.aiplatform.compat.types import tensorboard_data +from google.cloud.aiplatform.compat.types import tensorboard_service from google.cloud.aiplatform.compat.types import ( - tensorboard_run_v1beta1 as tensorboard_run_type, + tensorboard_experiment as tensorboard_experiment_type, ) +from google.cloud.aiplatform.compat.types import tensorboard_run as tensorboard_run_type from google.cloud.aiplatform.compat.types import ( - tensorboard_time_series_v1beta1 as tensorboard_time_series_type, + tensorboard_time_series as tensorboard_time_series_type, ) from google.protobuf import timestamp_pb2 from google.protobuf import message @@ -66,7 +71,10 @@ image_pb = summary_v1._image_summary.pb _SCALARS_HISTOGRAMS_AND_GRAPHS = frozenset( - (scalars_metadata.PLUGIN_NAME, graphs_metadata.PLUGIN_NAME,) + ( + scalars_metadata.PLUGIN_NAME, + graphs_metadata.PLUGIN_NAME, + ) ) # Sentinel for `_create_*` helpers, for arguments for which we want to @@ -111,11 +119,17 @@ def _create_mock_client(): # Create a stub instance (using a test channel) in order to derive a mock # from it with autospec enabled. Mocking TensorBoardWriterServiceStub itself # doesn't work with autospec because grpc constructs stubs via metaclassing. + def create_experiment_response( tensorboard_experiment_id=None, tensorboard_experiment=None, # pylint: disable=unused-argument parent=None, ): # pylint: disable=unused-argument + tensorboard_experiment_id = ( + "{}/experiments/{}".format(parent, tensorboard_experiment_id) + if parent + else tensorboard_experiment_id + ) return tensorboard_experiment_type.TensorboardExperiment( name=tensorboard_experiment_id ) @@ -125,13 +139,23 @@ def create_run_response( tensorboard_run_id=None, parent=None, ): # pylint: disable=unused-argument + tensorboard_run_id = ( + "{}/runs/{}".format(parent, tensorboard_run_id) + if parent + else tensorboard_run_id + ) return tensorboard_run_type.TensorboardRun(name=tensorboard_run_id) def create_tensorboard_time_series( tensorboard_time_series=None, parent=None ): # pylint: disable=unused-argument + name = ( + "{}/timeSeries/{}".format(parent, tensorboard_time_series.display_name) + if parent + else tensorboard_time_series.display_name + ) return tensorboard_time_series_type.TensorboardTimeSeries( - name=tensorboard_time_series.display_name, + name=name, display_name=tensorboard_time_series.display_name, ) @@ -139,7 +163,7 @@ def create_tensorboard_time_series( service_descriptors=[], time=grpc_testing.strict_real_time() ) mock_client = mock.Mock( - spec=tensorboard_service_client_v1beta1.TensorboardServiceClient( + spec=tensorboard_service_client.TensorboardServiceClient( transport=transports_grpc.TensorboardServiceGrpcTransport( channel=test_channel ) @@ -153,6 +177,13 @@ def create_tensorboard_time_series( return mock_client +def _create_mock_blob_storage(): + mock_blob_storage = mock.Mock() + mock_blob_storage.mock_add_spec(storage.Bucket) + + return mock_blob_storage + + def _create_uploader( writer_client=_USE_DEFAULT, logdir=None, @@ -170,6 +201,7 @@ def _create_uploader( description=None, verbosity=0, # Use 0 to minimize littering the test output. one_shot=None, + allowed_plugins=_SCALARS_HISTOGRAMS_AND_GRAPHS, ): if writer_client is _USE_DEFAULT: writer_client = _create_mock_client() @@ -201,7 +233,7 @@ def _create_uploader( tensorboard_resource_name=tensorboard_resource_name, writer_client=writer_client, logdir=logdir, - allowed_plugins=_SCALARS_HISTOGRAMS_AND_GRAPHS, + allowed_plugins=allowed_plugins, upload_limits=upload_limits, blob_storage_bucket=blob_storage_bucket, blob_storage_folder=blob_storage_folder, @@ -213,8 +245,11 @@ def _create_uploader( ) -def _create_request_sender( - experiment_resource_name, api=None, allowed_plugins=_USE_DEFAULT +def _create_dispatcher( + experiment_resource_name, + api=None, + allowed_plugins=_USE_DEFAULT, + logdir=None, ): if api is _USE_DEFAULT: api = _create_mock_client() @@ -225,13 +260,18 @@ def _create_request_sender( max_scalar_request_size=128000, max_tensor_request_size=128000, max_tensor_point_size=52000, + max_blob_request_size=128000, ) rpc_rate_limiter = util.RateLimiter(0) tensor_rpc_rate_limiter = util.RateLimiter(0) blob_rpc_rate_limiter = util.RateLimiter(0) - return uploader_lib._BatchedRequestSender( + one_platform_resource_manager = uploader_utils.OnePlatformResourceManager( + experiment_resource_name, api + ) + + request_sender = uploader_lib._BatchedRequestSender( experiment_resource_name=experiment_resource_name, api=api, allowed_plugins=allowed_plugins, @@ -241,19 +281,42 @@ def _create_request_sender( blob_rpc_rate_limiter=blob_rpc_rate_limiter, blob_storage_bucket=None, blob_storage_folder=None, + one_platform_resource_manager=one_platform_resource_manager, tracker=upload_tracker.UploadTracker(verbosity=0), ) + additional_senders = {} + if "profile" in allowed_plugins: + additional_senders["profile"] = profile_uploader.ProfileRequestSender( + experiment_resource_name=experiment_resource_name, + api=api, + upload_limits=upload_limits, + blob_rpc_rate_limiter=util.RateLimiter(0), + blob_storage_bucket=_create_mock_blob_storage(), + source_bucket=_create_mock_blob_storage(), + blob_storage_folder=None, + tracker=upload_tracker.UploadTracker(verbosity=0), + logdir=logdir, + ) + + return uploader_lib._Dispatcher( + request_sender=request_sender, + additional_senders=additional_senders, + ) + def _create_scalar_request_sender( - run_resource_id, api=_USE_DEFAULT, max_request_size=_USE_DEFAULT + experiment_resource_id, api=_USE_DEFAULT, max_request_size=_USE_DEFAULT ): if api is _USE_DEFAULT: api = _create_mock_client() if max_request_size is _USE_DEFAULT: max_request_size = 128000 return uploader_lib._ScalarBatchedRequestSender( - run_resource_id=run_resource_id, + experiment_resource_id=experiment_resource_id, + one_platform_resource_manager=uploader_utils.OnePlatformResourceManager( + experiment_resource_id, api + ), api=api, rpc_rate_limiter=util.RateLimiter(0), max_request_size=max_request_size, @@ -261,6 +324,38 @@ def _create_scalar_request_sender( ) +def _create_file_request_sender( + run_resource_id, + api=_USE_DEFAULT, + max_blob_request_size=_USE_DEFAULT, + max_blob_size=_USE_DEFAULT, + blob_storage_folder=None, + blob_storage_bucket=_USE_DEFAULT, + source_bucket=_USE_DEFAULT, +): + if api is _USE_DEFAULT: + api = _create_mock_client() + if max_blob_request_size is _USE_DEFAULT: + max_blob_request_size = 128000 + if blob_storage_bucket is _USE_DEFAULT: + blob_storage_bucket = _create_mock_blob_storage() + if source_bucket is _USE_DEFAULT: + source_bucket = _create_mock_blob_storage() + if max_blob_size is _USE_DEFAULT: + max_blob_size = 128000 + return profile_uploader._FileRequestSender( + run_resource_id=run_resource_id, + api=api, + rpc_rate_limiter=util.RateLimiter(0), + max_blob_request_size=max_blob_request_size, + max_blob_size=max_blob_size, + blob_storage_bucket=blob_storage_bucket, + blob_storage_folder=blob_storage_folder, + tracker=upload_tracker.UploadTracker(verbosity=0), + source_bucket=source_bucket, + ) + + def _scalar_event(tag, value): return event_pb2.Event(summary=scalar_v2_pb(tag, value)) @@ -286,7 +381,7 @@ class FileWriter(tf.compat.v1.summary.FileWriter): which is largely discouraged in TensorBoard. We do not want a TB.Writer but require one for testing in integrational style (writing out event files and use the real event readers). - """ + """ def __init__(self, *args, **kwargs): # Briefly enter graph mode context so this testing FileWriter can be @@ -376,7 +471,7 @@ def test_create_experiment(self): logdir = _TEST_LOG_DIR_NAME uploader = _create_uploader(_create_mock_client(), logdir) uploader.create_experiment() - self.assertEqual(uploader._experiment.name, _TEST_EXPERIMENT_NAME) + self.assertEqual(uploader._experiment.name, _TEST_ONE_PLATFORM_EXPERIMENT_NAME) def test_create_experiment_with_name(self): logdir = _TEST_LOG_DIR_NAME @@ -463,7 +558,7 @@ def test_start_uploading_scalars(self): writer_client=mock_client, logdir=_TEST_LOG_DIR_NAME, # Send each Event below in a separate WriteScalarRequest - max_scalar_request_size=100, + max_scalar_request_size=200, rpc_rate_limiter=mock_rate_limiter, verbosity=1, # In order to test the upload tracker. ) @@ -497,21 +592,55 @@ def test_start_uploading_scalars(self): uploader, "_logdir_loader", mock_logdir_loader ), self.assertRaises(AbortUploadError): uploader.start_uploading() - self.assertEqual(10, mock_client.write_tensorboard_run_data.call_count) - self.assertEqual(10, mock_rate_limiter.tick.call_count) + self.assertEqual(5, mock_client.write_tensorboard_experiment_data.call_count) + self.assertEqual(5, mock_rate_limiter.tick.call_count) self.assertEqual(0, mock_tensor_rate_limiter.tick.call_count) self.assertEqual(0, mock_blob_rate_limiter.tick.call_count) # Check upload tracker calls. self.assertEqual(mock_tracker.send_tracker.call_count, 2) - self.assertEqual(mock_tracker.scalars_tracker.call_count, 10) + self.assertEqual(mock_tracker.scalars_tracker.call_count, 5) self.assertLen(mock_tracker.scalars_tracker.call_args[0], 1) self.assertEqual(mock_tracker.tensors_tracker.call_count, 0) self.assertEqual(mock_tracker.blob_tracker.call_count, 0) def test_start_uploading_scalars_one_shot(self): """Check that one-shot uploading stops without AbortUploadError.""" + + def batch_create_runs(parent, requests): + # pylint: disable=unused-argument + tb_runs = [] + for request in requests: + tb_run = tensorboard_run_type.TensorboardRun(request.tensorboard_run) + tb_run.name = "{}/runs/{}".format( + request.parent, request.tensorboard_run_id + ) + tb_runs.append(tb_run) + return tensorboard_service.BatchCreateTensorboardRunsResponse( + tensorboard_runs=tb_runs + ) + + def batch_create_time_series(parent, requests): + # pylint: disable=unused-argument + tb_time_series = [] + for request in requests: + ts = tensorboard_time_series_type.TensorboardTimeSeries( + request.tensorboard_time_series + ) + ts.name = "{}/timeSeries/{}".format( + request.parent, request.tensorboard_time_series.display_name + ) + tb_time_series.append(ts) + return tensorboard_service.BatchCreateTensorboardTimeSeriesResponse( + tensorboard_time_series=tb_time_series + ) + mock_client = _create_mock_client() + mock_client.batch_create_tensorboard_runs.side_effect = batch_create_runs + mock_client.batch_create_tensorboard_time_series.side_effect = ( + batch_create_time_series + ) + mock_rate_limiter = mock.create_autospec(util.RateLimiter) mock_tracker = mock.MagicMock() with mock.patch.object( @@ -521,7 +650,7 @@ def test_start_uploading_scalars_one_shot(self): writer_client=mock_client, logdir=_TEST_LOG_DIR_NAME, # Send each Event below in a separate WriteScalarRequest - max_scalar_request_size=100, + max_scalar_request_size=200, rpc_rate_limiter=mock_rate_limiter, verbosity=1, # In order to test the upload tracker. one_shot=True, @@ -532,24 +661,39 @@ def test_start_uploading_scalars_one_shot(self): mock_logdir_loader.get_run_events.side_effect = [ { "run 1": _apply_compat( - [_scalar_event("1.1", 5.0), _scalar_event("1.2", 5.0)] + [_scalar_event("tag_1.1", 5.0), _scalar_event("tag_1.2", 5.0)] ), "run 2": _apply_compat( - [_scalar_event("2.1", 5.0), _scalar_event("2.2", 5.0)] + [_scalar_event("tag_2.1", 5.0), _scalar_event("tag_2.2", 5.0)] + ), + }, + # Note the lack of AbortUploadError here. + ] + mock_logdir_loader_pre_create = mock.create_autospec(logdir_loader.LogdirLoader) + mock_logdir_loader_pre_create.get_run_events.side_effect = [ + { + "run 1": _apply_compat( + [_scalar_event("tag_1.1", 5.0), _scalar_event("tag_1.2", 5.0)] + ), + "run 2": _apply_compat( + [_scalar_event("tag_2.1", 5.0), _scalar_event("tag_2.2", 5.0)] ), }, # Note the lack of AbortUploadError here. ] with mock.patch.object(uploader, "_logdir_loader", mock_logdir_loader): - uploader.start_uploading() + with mock.patch.object( + uploader, "_logdir_loader_pre_create", mock_logdir_loader_pre_create + ): + uploader.start_uploading() - self.assertEqual(4, mock_client.write_tensorboard_run_data.call_count) - self.assertEqual(4, mock_rate_limiter.tick.call_count) + self.assertEqual(2, mock_client.write_tensorboard_experiment_data.call_count) + self.assertEqual(2, mock_rate_limiter.tick.call_count) # Check upload tracker calls. self.assertEqual(mock_tracker.send_tracker.call_count, 1) - self.assertEqual(mock_tracker.scalars_tracker.call_count, 4) + self.assertEqual(mock_tracker.scalars_tracker.call_count, 2) self.assertLen(mock_tracker.scalars_tracker.call_args[0], 1) self.assertEqual(mock_tracker.tensors_tracker.call_count, 0) self.assertEqual(mock_tracker.blob_tracker.call_count, 0) @@ -560,7 +704,7 @@ def test_upload_empty_logdir(self): uploader = _create_uploader(mock_client, logdir) uploader.create_experiment() uploader._upload_once() - mock_client.write_tensorboard_run_data.assert_not_called() + mock_client.write_tensorboard_experiment_data.assert_not_called() def test_upload_polls_slowly_once_done(self): class SuccessError(Exception): @@ -577,7 +721,8 @@ def mock_upload_once(): raise SuccessError() uploader = _create_uploader( - logdir=self.get_temp_dir(), logdir_poll_rate_limiter=mock_rate_limiter, + logdir=self.get_temp_dir(), + logdir_poll_rate_limiter=mock_rate_limiter, ) uploader._upload_once = mock_upload_once @@ -593,9 +738,9 @@ def test_upload_swallows_rpc_failure(self): uploader = _create_uploader(mock_client, logdir) uploader.create_experiment() error = _grpc_error(grpc.StatusCode.INTERNAL, "Failure") - mock_client.write_tensorboard_run_data.side_effect = error + mock_client.write_tensorboard_experiment_data.side_effect = error uploader._upload_once() - mock_client.write_tensorboard_run_data.assert_called_once() + mock_client.write_tensorboard_experiment_data.assert_called_once() def test_upload_full_logdir(self): logdir = self.get_temp_dir() @@ -636,11 +781,11 @@ def test_upload_full_logdir(self): self.assertEqual("scalars", request.plugin_name) self.assertEqual(b"12345", request.plugin_data) - self.assertEqual(2, mock_client.write_tensorboard_run_data.call_count) - call_args_list = mock_client.write_tensorboard_run_data.call_args_list + self.assertEqual(1, mock_client.write_tensorboard_experiment_data.call_count) + call_args_list = mock_client.write_tensorboard_experiment_data.call_args_list request1, request2 = ( - call_args_list[0][1]["time_series_data"], - call_args_list[1][1]["time_series_data"], + call_args_list[0][1]["write_run_data_requests"][0].time_series_data, + call_args_list[0][1]["write_run_data_requests"][1].time_series_data, ) _clear_wall_times(request1) _clear_wall_times(request2) @@ -672,7 +817,7 @@ def test_upload_full_logdir(self): self.assertProtoEquals(expected_request1[1], request1[1]) self.assertProtoEquals(expected_request2[0], request2[0]) - mock_client.write_tensorboard_run_data.reset_mock() + mock_client.write_tensorboard_experiment_data.reset_mock() # Second round writer.add_test_summary("foo", simple_value=10.0, step=5) @@ -682,11 +827,11 @@ def test_upload_full_logdir(self): writer_b.add_test_summary("xyz", simple_value=12.0, step=1) writer_b.flush() uploader._upload_once() - self.assertEqual(2, mock_client.write_tensorboard_run_data.call_count) - call_args_list = mock_client.write_tensorboard_run_data.call_args_list + self.assertEqual(1, mock_client.write_tensorboard_experiment_data.call_count) + call_args_list = mock_client.write_tensorboard_experiment_data.call_args_list request3, request4 = ( - call_args_list[0][1]["time_series_data"], - call_args_list[1][1]["time_series_data"], + call_args_list[0][1]["write_run_data_requests"][0].time_series_data, + call_args_list[0][1]["write_run_data_requests"][1].time_series_data, ) _clear_wall_times(request3) _clear_wall_times(request4) @@ -712,11 +857,11 @@ def test_upload_full_logdir(self): self.assertProtoEquals(expected_request3[0], request3[0]) self.assertProtoEquals(expected_request3[1], request3[1]) self.assertProtoEquals(expected_request4[0], request4[0]) - mock_client.write_tensorboard_run_data.reset_mock() + mock_client.write_tensorboard_experiment_data.reset_mock() # Empty third round uploader._upload_once() - mock_client.write_tensorboard_run_data.assert_not_called() + mock_client.write_tensorboard_experiment_data.assert_not_called() def test_verbosity_zero_creates_upload_tracker_with_verbosity_zero(self): mock_client = _create_mock_client() @@ -771,8 +916,7 @@ def create_time_series(tensorboard_time_series, parent=None): uploader = _create_uploader( writer_client=mock_client, logdir=_TEST_LOG_DIR_NAME, - # Verify behavior with lots of small chunks - max_blob_request_size=100, + max_blob_request_size=1000, rpc_rate_limiter=mock_rate_limiter, blob_storage_bucket=mock_bucket, verbosity=1, # In order to test tracker. @@ -822,14 +966,14 @@ def create_time_series(tensorboard_time_series, parent=None): actual_graph_def = graph_pb2.GraphDef.FromString(request) self.assertProtoEquals(expected_graph_def, actual_graph_def) - for call in mock_client.write_tensorboard_run_data.call_args_list: + for call in mock_client.write_tensorboard_experiment_data.call_args_list: kargs = call[1] - time_series_data = kargs["time_series_data"] + time_series_data = kargs["write_run_data_requests"][0].time_series_data self.assertEqual(len(time_series_data), 1) self.assertEqual( time_series_data[0].tensorboard_time_series_id, _TEST_TIME_SERIES_NAME ) - self.assertEqual(len(time_series_data[0].values), 1) + self.assertEqual(len(time_series_data[0].values), 2) blobs = time_series_data[0].values[0].blobs.values self.assertEqual(len(blobs), 1) self.assertIn(blobs[0].id, blob_ids) @@ -838,9 +982,7 @@ def create_time_series(tensorboard_time_series, parent=None): self.assertEqual(mock_tracker.send_tracker.call_count, 2) self.assertEqual(mock_tracker.scalars_tracker.call_count, 0) self.assertEqual(mock_tracker.tensors_tracker.call_count, 0) - self.assertEqual(mock_tracker.blob_tracker.call_count, 10) - self.assertLen(mock_tracker.blob_tracker.call_args[0], 1) - self.assertGreater(mock_tracker.blob_tracker.call_args[0][0], 0) + self.assertEqual(mock_tracker.blob_tracker.call_count, 12) def test_filter_graphs(self): # Three graphs: one short, one long, one corrupt. @@ -910,22 +1052,35 @@ def create_time_series(tensorboard_time_series, parent=None): with self.subTest("corrupt graphs should be skipped"): self.assertLen(actual_blobs, 2) + def test_add_profile_plugin(self): + uploader = _create_uploader( + _create_mock_client(), + _TEST_LOG_DIR_NAME, + one_shot=True, + allowed_plugins=frozenset(("profile",)), + ) + uploader.create_experiment() + self.assertIn("profile", uploader._dispatcher._additional_senders) + class BatchedRequestSenderTest(tf.test.TestCase): def _populate_run_from_events( self, n_scalar_events, events, allowed_plugins=_USE_DEFAULT ): mock_client = _create_mock_client() - builder = _create_request_sender( + builder = _create_dispatcher( experiment_resource_name="123", api=mock_client, allowed_plugins=allowed_plugins, ) - builder.send_requests({"": _apply_compat(events)}) - scalar_requests = mock_client.write_tensorboard_run_data.call_args_list + builder.dispatch_requests({"": _apply_compat(events)}) + scalar_requests = mock_client.write_tensorboard_experiment_data.call_args_list if scalar_requests: self.assertLen(scalar_requests, 1) - self.assertLen(scalar_requests[0][1]["time_series_data"], n_scalar_events) + self.assertLen( + scalar_requests[0][1]["write_run_data_requests"][0].time_series_data, + n_scalar_events, + ) return scalar_requests def test_empty_events(self): @@ -965,7 +1120,9 @@ def test_skips_events_from_disallowed_plugins(self): step=1, wall_time=123.456, summary=scalar_v2_pb("foo", 5.0) ) call_args_lists = self._populate_run_from_events( - 0, [event], allowed_plugins=frozenset("not-scalars"), + 0, + [event], + allowed_plugins=frozenset("not-scalars"), ) self.assertEqual(call_args_lists, []) @@ -1012,33 +1169,244 @@ def test_expands_multiple_values_in_event(self): ) self.assertProtoEquals( - time_series_data, call_args_list[0][1]["time_series_data"][0] + time_series_data, + call_args_list[0][1]["write_run_data_requests"][0].time_series_data[0], + ) + + +class ProfileRequestSenderTest(tf.test.TestCase): + def _create_builder(self, mock_client, logdir): + return _create_dispatcher( + experiment_resource_name=_TEST_ONE_PLATFORM_EXPERIMENT_NAME, + api=mock_client, + logdir=logdir, + allowed_plugins=frozenset({"profile"}), ) + def _populate_run_from_events( + self, + events, + logdir, + mock_client=None, + builder=None, + ): + if not mock_client: + mock_client = _create_mock_client() + + if not builder: + builder = self._create_builder(mock_client, logdir) + + builder.dispatch_requests({"": _apply_compat(events)}) + profile_requests = mock_client.write_tensorboard_run_data.call_args_list + + return profile_requests + + def test_profile_event_missing_prof_run_dirs(self): + events = [ + event_pb2.Event(file_version="brain.Event:2"), + ] + with tempfile.TemporaryDirectory() as logdir: + call_args_list = self._populate_run_from_events(events, logdir) + + self.assertProtoEquals(call_args_list, []) + + def test_profile_event_bad_prof_path(self): + events = [ + event_pb2.Event(file_version="brain.Event:2"), + ] + prof_run_name = "bad_run_name" + + with tempfile.TemporaryDirectory() as logdir: + prof_path = os.path.join( + logdir, profile_uploader.ProfileRequestSender.PROFILE_PATH + ) + os.makedirs(prof_path) + + run_path = os.path.join(prof_path, prof_run_name) + os.makedirs(run_path) + + call_args_list = self._populate_run_from_events(events, logdir) + + self.assertProtoEquals(call_args_list, []) + + def test_profile_event_single_prof_run(self): + events = [ + event_pb2.Event(file_version="brain.Event:2"), + ] + prof_run_name = "2021_01_01_01_10_10" + + with tempfile.TemporaryDirectory() as logdir: + prof_path = os.path.join( + logdir, profile_uploader.ProfileRequestSender.PROFILE_PATH + ) + os.makedirs(prof_path) + + run_path = os.path.join(prof_path, prof_run_name) + os.makedirs(run_path) + + with tempfile.NamedTemporaryFile(suffix=".xplane.pb", dir=run_path): + call_args_list = self._populate_run_from_events(events, logdir) + + profile_tag_counts = _extract_tag_counts_time_series(call_args_list) + self.assertEqual(profile_tag_counts, {prof_run_name: 1}) + + def test_profile_event_single_prof_run_new_files(self): + # Check that files are not uploaded twice for the same profiling run + events = [ + event_pb2.Event(file_version="brain.Event:2"), + ] + prof_run_name = "2021_01_01_01_10_10" + mock_client = _create_mock_client() + + with tempfile.TemporaryDirectory() as logdir: + builder = self._create_builder(mock_client=mock_client, logdir=logdir) + prof_path = os.path.join( + logdir, profile_uploader.ProfileRequestSender.PROFILE_PATH + ) + os.makedirs(prof_path) + + run_path = os.path.join(prof_path, prof_run_name) + os.makedirs(run_path) + + with tempfile.NamedTemporaryFile( + prefix="a", suffix=".xplane.pb", dir=run_path + ): + call_args_list = self._populate_run_from_events( + events, logdir, builder=builder, mock_client=mock_client + ) + with tempfile.NamedTemporaryFile( + prefix="b", suffix=".xplane.pb", dir=run_path + ): + call_args_list = self._populate_run_from_events( + events, logdir, builder=builder, mock_client=mock_client + ) + + profile_tag_counts = _extract_tag_counts_time_series(call_args_list) + self.assertEqual(profile_tag_counts, {prof_run_name: 1}) + + def test_profile_event_multi_prof_run(self): + events = [ + event_pb2.Event(file_version="brain.Event:2"), + ] + prof_run_names = [ + "2021_01_01_01_10_10", + "2021_02_02_02_20_20", + ] + + with tempfile.TemporaryDirectory() as logdir: + prof_path = os.path.join( + logdir, profile_uploader.ProfileRequestSender.PROFILE_PATH + ) + os.makedirs(prof_path) + + run_paths = [ + os.path.join(prof_path, prof_run_names[0]), + os.path.join(prof_path, prof_run_names[1]), + ] + [os.makedirs(run_path) for run_path in run_paths] + + named_temp = functools.partial( + tempfile.NamedTemporaryFile, suffix=".xplane.pb" + ) + + with named_temp(dir=run_paths[0]), named_temp(dir=run_paths[1]): + call_args_list = self._populate_run_from_events(events, logdir) + + self.assertLen(call_args_list, 2) + profile_tag_counts = _extract_tag_counts_time_series(call_args_list) + self.assertEqual(profile_tag_counts, dict.fromkeys(prof_run_names, 1)) + + def test_profile_event_add_consecutive_prof_runs(self): + # Multiple profiling events happen one after another, should only update + # new profiling runs + events = [ + event_pb2.Event(file_version="brain.Event:2"), + ] + + prof_run_name = "2021_01_01_01_10_10" + + mock_client = _create_mock_client() + + with tempfile.TemporaryDirectory() as logdir: + builder = self._create_builder(mock_client=mock_client, logdir=logdir) + + prof_path = os.path.join( + logdir, profile_uploader.ProfileRequestSender.PROFILE_PATH + ) + os.makedirs(prof_path) + + run_path = os.path.join(prof_path, prof_run_name) + os.makedirs(run_path) + + named_temp = functools.partial( + tempfile.NamedTemporaryFile, suffix=".xplane.pb" + ) + + with named_temp(dir=run_path): + call_args_list = self._populate_run_from_events( + events, + logdir, + mock_client=mock_client, + builder=builder, + ) + + self.assertLen(call_args_list, 1) + self.assertEqual( + call_args_list[0][1]["time_series_data"][0].tensorboard_time_series_id, + prof_run_name, + ) + + prof_run_name_2 = "2021_02_02_02_20_20" + + run_path = os.path.join(prof_path, prof_run_name_2) + os.makedirs(run_path) + mock_client.write_tensorboard_run_data.reset_mock() + + with named_temp(dir=run_path): + call_args_list = self._populate_run_from_events( + events, + logdir, + mock_client=mock_client, + builder=builder, + ) + + self.assertLen(call_args_list, 1) + self.assertEqual( + call_args_list[0][1]["time_series_data"][0].tensorboard_time_series_id, + prof_run_name_2, + ) + class ScalarBatchedRequestSenderTest(tf.test.TestCase): def _add_events(self, sender, events): for event in events: for value in event.summary.value: - sender.add_event(event, value, value.metadata) + sender.add_event(_TEST_RUN_NAME, event, value, value.metadata) def _add_events_and_flush(self, events, expected_n_time_series): mock_client = _create_mock_client() sender = _create_scalar_request_sender( - run_resource_id=_TEST_RUN_NAME, api=mock_client, + experiment_resource_id=_TEST_EXPERIMENT_NAME, + api=mock_client, ) self._add_events(sender, events) sender.flush() - requests = mock_client.write_tensorboard_run_data.call_args_list + requests = mock_client.write_tensorboard_experiment_data.call_args_list self.assertLen(requests, 1) - self.assertLen(requests[0][1]["time_series_data"], expected_n_time_series) - return requests[0] + call_args = requests[0] + self.assertLen( + call_args[1]["write_run_data_requests"][0].time_series_data, + expected_n_time_series, + ) + return call_args def test_aggregation_by_tag(self): def make_event(step, wall_time, tag, value): return event_pb2.Event( - step=step, wall_time=wall_time, summary=scalar_v2_pb(tag, value), + step=step, + wall_time=wall_time, + summary=scalar_v2_pb(tag, value), ) events = [ @@ -1050,7 +1418,7 @@ def make_event(step, wall_time, tag, value): make_event(1, 6.0, "three", 66.0), ] call_args = self._add_events_and_flush(events, 3) - ts_data = call_args[1]["time_series_data"] + ts_data = call_args[1]["write_run_data_requests"][0].time_series_data tag_data = { ts.tensorboard_time_series_id: [ ( @@ -1076,9 +1444,9 @@ def test_v1_summary(self): event.summary.value.add(tag="foo", simple_value=5.0) call_args = self._add_events_and_flush(_apply_compat([event]), 1) - expected_call_args = mock.call( - tensorboard_run=_TEST_RUN_NAME, - time_series_data=[ + self.assertEqual(_TEST_EXPERIMENT_NAME, call_args[1]["tensorboard_experiment"]) + self.assertEqual( + [ tensorboard_data.TimeSeriesData( tensorboard_time_series_id="foo", value_type=tensorboard_time_series_type.TensorboardTimeSeries.ValueType.SCALAR, @@ -1091,8 +1459,8 @@ def test_v1_summary(self): ], ) ], + call_args[1]["write_run_data_requests"][0].time_series_data, ) - self.assertEqual(expected_call_args, call_args) def test_v1_summary_tb_summary(self): tf_summary = summary_v1.scalar_pb("foo", 5.0) @@ -1100,9 +1468,9 @@ def test_v1_summary_tb_summary(self): event = event_pb2.Event(step=1, wall_time=123.456, summary=tb_summary) call_args = self._add_events_and_flush(_apply_compat([event]), 1) - expected_call_args = mock.call( - tensorboard_run=_TEST_RUN_NAME, - time_series_data=[ + self.assertEqual(_TEST_EXPERIMENT_NAME, call_args[1]["tensorboard_experiment"]) + self.assertEqual( + [ tensorboard_data.TimeSeriesData( tensorboard_time_series_id="scalar_summary", value_type=tensorboard_time_series_type.TensorboardTimeSeries.ValueType.SCALAR, @@ -1115,8 +1483,8 @@ def test_v1_summary_tb_summary(self): ], ) ], + call_args[1]["write_run_data_requests"][0].time_series_data, ) - self.assertEqual(expected_call_args, call_args) def test_v2_summary(self): event = event_pb2.Event( @@ -1124,9 +1492,9 @@ def test_v2_summary(self): ) call_args = self._add_events_and_flush(_apply_compat([event]), 1) - expected_call_args = mock.call( - tensorboard_run=_TEST_RUN_NAME, - time_series_data=[ + self.assertEqual(_TEST_EXPERIMENT_NAME, call_args[1]["tensorboard_experiment"]) + self.assertEqual( + [ tensorboard_data.TimeSeriesData( tensorboard_time_series_id="foo", value_type=tensorboard_time_series_type.TensorboardTimeSeries.ValueType.SCALAR, @@ -1139,10 +1507,9 @@ def test_v2_summary(self): ], ) ], + call_args[1]["write_run_data_requests"][0].time_series_data, ) - self.assertEqual(expected_call_args, call_args) - def test_propagates_experiment_deletion(self): event = event_pb2.Event(step=1) event.summary.value.add(tag="foo", simple_value=1.0) @@ -1152,16 +1519,18 @@ def test_propagates_experiment_deletion(self): self._add_events(sender, _apply_compat([event])) error = _grpc_error(grpc.StatusCode.NOT_FOUND, "nope") - mock_client.write_tensorboard_run_data.side_effect = error + mock_client.write_tensorboard_experiment_data.side_effect = error with self.assertRaises(uploader_lib.ExperimentNotFoundError): sender.flush() def test_no_budget_for_base_request(self): mock_client = _create_mock_client() - long_run_id = "A" * 12 + long_experiment_id = "A" * 12 with self.assertRaises(uploader_lib._OutOfSpaceError) as cm: _create_scalar_request_sender( - run_resource_id=long_run_id, api=mock_client, max_request_size=12, + experiment_resource_id=long_experiment_id, + api=mock_client, + max_request_size=12, ) self.assertEqual(str(cm.exception), "Byte budget too small for base request") @@ -1202,46 +1571,48 @@ def test_break_at_run_boundary(self): self._add_events(sender_2, _apply_compat([event_2])) sender_1.flush() sender_2.flush() - call_args_list = mock_client.write_tensorboard_run_data.call_args_list + call_args_list = mock_client.write_tensorboard_experiment_data.call_args_list for call_args in call_args_list: - _clear_wall_times(call_args[1]["time_series_data"]) + _clear_wall_times( + call_args[1]["write_run_data_requests"][0].time_series_data + ) # Expect two calls despite a single explicit call to flush(). expected = [ - mock.call( - tensorboard_run=long_run_1, - time_series_data=[ - tensorboard_data.TimeSeriesData( - tensorboard_time_series_id="foo", - value_type=tensorboard_time_series_type.TensorboardTimeSeries.ValueType.SCALAR, - values=[ - tensorboard_data.TimeSeriesDataPoint( - step=1, scalar=tensorboard_data.Scalar(value=1.0) - ) - ], - ) - ], - ), - mock.call( - tensorboard_run=long_run_2, - time_series_data=[ - tensorboard_data.TimeSeriesData( - tensorboard_time_series_id="bar", - value_type=tensorboard_time_series_type.TensorboardTimeSeries.ValueType.SCALAR, - values=[ - tensorboard_data.TimeSeriesDataPoint( - step=2, scalar=tensorboard_data.Scalar(value=-2.0) - ) - ], - ) - ], - ), + [ + tensorboard_data.TimeSeriesData( + tensorboard_time_series_id="foo", + value_type=tensorboard_time_series_type.TensorboardTimeSeries.ValueType.SCALAR, + values=[ + tensorboard_data.TimeSeriesDataPoint( + step=1, scalar=tensorboard_data.Scalar(value=1.0) + ) + ], + ) + ], + [ + tensorboard_data.TimeSeriesData( + tensorboard_time_series_id="bar", + value_type=tensorboard_time_series_type.TensorboardTimeSeries.ValueType.SCALAR, + values=[ + tensorboard_data.TimeSeriesDataPoint( + step=2, scalar=tensorboard_data.Scalar(value=-2.0) + ) + ], + ) + ], ] - self.assertEqual(expected[0], call_args_list[0]) - self.assertEqual(expected[1], call_args_list[1]) + self.assertEqual( + expected[0], + call_args_list[0][1]["write_run_data_requests"][0].time_series_data, + ) + self.assertEqual( + expected[1], + call_args_list[1][1]["write_run_data_requests"][0].time_series_data, + ) def test_break_at_tag_boundary(self): mock_client = _create_mock_client() @@ -1262,9 +1633,9 @@ def test_break_at_tag_boundary(self): ) self._add_events(sender, _apply_compat([event])) sender.flush() - call_args_list = mock_client.write_tensorboard_run_data.call_args_list + call_args_list = mock_client.write_tensorboard_experiment_data.call_args_list - request1 = call_args_list[0][1]["time_series_data"] + request1 = call_args_list[0][1]["write_run_data_requests"][0].time_series_data _clear_wall_times(request1) # Convenience helpers for constructing expected requests. @@ -1305,10 +1676,12 @@ def test_break_at_scalar_point_boundary(self): ) self._add_events(sender, _apply_compat(events)) sender.flush() - call_args_list = mock_client.write_tensorboard_run_data.call_args_list + call_args_list = mock_client.write_tensorboard_experiment_data.call_args_list for call_args in call_args_list: - _clear_wall_times(call_args[1]["time_series_data"]) + _clear_wall_times( + call_args[1]["write_run_data_requests"][0].time_series_data + ) self.assertGreater(len(call_args_list), 1) self.assertLess(len(call_args_list), point_count) @@ -1320,9 +1693,12 @@ def test_break_at_scalar_point_boundary(self): total_points_in_result = 0 for call_args in call_args_list: - self.assertLen(call_args[1]["time_series_data"], 1) - self.assertEqual(call_args[1]["tensorboard_run"], "train") - time_series_data = call_args[1]["time_series_data"][0] + self.assertLen( + call_args[1]["write_run_data_requests"][0].time_series_data, 1 + ) + time_series_data = call_args[1]["write_run_data_requests"][ + 0 + ].time_series_data[0] self.assertEqual(time_series_data.tensorboard_time_series_id, "loss") for point in time_series_data.values: self.assertEqual(point.step, total_points_in_result) @@ -1347,17 +1723,19 @@ def mock_add_point(byte_budget_manager_self, point): raise uploader_lib._OutOfSpaceError() with mock.patch.object( - uploader_lib._ByteBudgetManager, "add_point", mock_add_point, + uploader_lib._ByteBudgetManager, + "add_point", + mock_add_point, ): sender = _create_scalar_request_sender("123", mock_client) self._add_events(sender, _apply_compat([event_1])) self._add_events(sender, _apply_compat([event_2])) sender.flush() - call_args_list = mock_client.write_tensorboard_run_data.call_args_list + call_args_list = mock_client.write_tensorboard_experiment_data.call_args_list request1, request2 = ( - call_args_list[0][1]["time_series_data"], - call_args_list[1][1]["time_series_data"], + call_args_list[0][1]["write_run_data_requests"][0].time_series_data, + call_args_list[1][1]["write_run_data_requests"][0].time_series_data, ) _clear_wall_times(request1) _clear_wall_times(request2) @@ -1399,16 +1777,182 @@ def test_wall_time_precision(self): datetime_helpers.DatetimeWithNanoseconds.from_timestamp_pb( _timestamp_pb(1567808404765432119) ), - call_args[1]["time_series_data"][0].values[0].wall_time, + call_args[1]["write_run_data_requests"][0] + .time_series_data[0] + .values[0] + .wall_time, ) self.assertEqual( datetime_helpers.DatetimeWithNanoseconds.from_timestamp_pb( _timestamp_pb(1000000002) ), - call_args[1]["time_series_data"][0].values[1].wall_time, + call_args[1]["write_run_data_requests"][0] + .time_series_data[0] + .values[1] + .wall_time, ) +class FileRequestSenderTest(tf.test.TestCase): + def test_empty_files_no_messages(self): + mock_client = _create_mock_client() + sender = _create_file_request_sender( + api=mock_client, + run_resource_id=_TEST_ONE_PLATFORM_RUN_NAME, + ) + + sender.add_files( + files=[], tag="my_tag", plugin="test_plugin", event_timestamp="" + ) + + self.assertEmpty(mock_client.write_tensorboard_run_data.call_args_list) + + def test_fake_files_no_sent_messages(self): + mock_client = _create_mock_client() + sender = _create_file_request_sender( + api=mock_client, + run_resource_id=_TEST_ONE_PLATFORM_RUN_NAME, + ) + + with mock.patch("os.path.isfile", return_value=False): + sender.add_files( + files=["fakefile1", "fakefile2"], + tag="my_tag", + plugin="test_plugin", + event_timestamp="", + ) + + self.assertEmpty(mock_client.write_tensorboard_run_data.call_args_list) + + def test_files_too_large(self): + mock_client = _create_mock_client() + sender = _create_file_request_sender( + api=mock_client, + run_resource_id=_TEST_ONE_PLATFORM_RUN_NAME, + max_blob_size=10, + ) + + with tempfile.NamedTemporaryFile() as f1: + f1.write(b"A" * 12) + f1.flush() + sender.add_files( + files=[f1.name], + tag="my_tag", + plugin="test_plugin", + event_timestamp=timestamp_pb2.Timestamp().FromDatetime( + datetime.datetime.strptime("2020-01-01", "%Y-%m-%d") + ), + ) + + self.assertEmpty(mock_client.write_tensorboard_run_data.call_args_list) + + def test_single_file_upload(self): + mock_client = _create_mock_client() + sender = _create_file_request_sender( + api=mock_client, + run_resource_id=_TEST_ONE_PLATFORM_RUN_NAME, + ) + + with tempfile.NamedTemporaryFile() as f1: + fn = os.path.basename(f1.name) + sender.add_files( + files=[f1.name], + tag="my_tag", + plugin="test_plugin", + event_timestamp=timestamp_pb2.Timestamp().FromDatetime( + datetime.datetime.strptime("2020-01-01", "%Y-%m-%d") + ), + ) + + call_args_list = mock_client.write_tensorboard_run_data.call_args_list[0][1] + self.assertEqual( + fn, call_args_list["time_series_data"][0].values[0].blobs.values[0].id + ) + + def test_multi_file_upload(self): + mock_client = _create_mock_client() + sender = _create_file_request_sender( + api=mock_client, + run_resource_id=_TEST_ONE_PLATFORM_RUN_NAME, + ) + + files = None + with tempfile.NamedTemporaryFile() as f1, tempfile.NamedTemporaryFile() as f2: + files = [os.path.basename(f1.name), os.path.basename(f2.name)] + sender.add_files( + files=[f1.name, f2.name], + tag="my_tag", + plugin="test_plugin", + event_timestamp=timestamp_pb2.Timestamp().FromDatetime( + datetime.datetime.strptime("2020-01-01", "%Y-%m-%d") + ), + ) + + call_args_list = mock_client.write_tensorboard_run_data.call_args_list[0][1] + + self.assertEqual( + files, + [ + x.id + for x in call_args_list["time_series_data"][0].values[0].blobs.values + ], + ) + + def test_add_files_no_experiment(self): + mock_client = _create_mock_client() + mock_client.write_tensorboard_run_data.side_effect = grpc.RpcError + + sender = _create_file_request_sender( + api=mock_client, + run_resource_id=_TEST_ONE_PLATFORM_RUN_NAME, + ) + + with tempfile.NamedTemporaryFile() as f1: + sender.add_files( + files=[f1.name], + tag="my_tag", + plugin="test_plugin", + event_timestamp=timestamp_pb2.Timestamp().FromDatetime( + datetime.datetime.strptime("2020-01-01", "%Y-%m-%d") + ), + ) + + mock_client.write_tensorboard_run_data.assert_called_once() + + def test_add_files_from_local(self): + mock_client = _create_mock_client() + bucket = _create_mock_blob_storage() + + sender = _create_file_request_sender( + api=mock_client, + run_resource_id=_TEST_ONE_PLATFORM_RUN_NAME, + blob_storage_bucket=bucket, + source_bucket=None, + ) + + with tempfile.NamedTemporaryFile() as f1: + sender.add_files( + files=[f1.name], + tag="my_tag", + plugin="test_plugin", + event_timestamp=timestamp_pb2.Timestamp().FromDatetime( + datetime.datetime.strptime("2020-01-01", "%Y-%m-%d") + ), + ) + + bucket.blob.assert_called_once() + + def test_copy_blobs(self): + mock_client = _create_mock_client() + sender = _create_file_request_sender( + api=mock_client, + run_resource_id=_TEST_ONE_PLATFORM_RUN_NAME, + ) + + sender._copy_between_buckets("gs://path/to/my/file", None) + self.assertLen(sender._source_bucket.copy_blob.call_args_list, 1) + + class VarintCostTest(tf.test.TestCase): def test_varint_cost(self): self.assertEqual(uploader_lib._varint_cost(0), 1) @@ -1422,9 +1966,9 @@ def test_varint_cost(self): def _clear_wall_times(repeated_time_series_data): """Clears the wall_time fields in a TimeSeriesData to be deterministic. - Args: - repeated_time_series_data: Iterable of tensorboard_data.TimeSeriesData. - """ + Args: + repeated_time_series_data: Iterable of tensorboard_data.TimeSeriesData. + """ for time_series_data in repeated_time_series_data: for value in time_series_data.values: @@ -1443,6 +1987,14 @@ def _apply_compat(events): def _extract_tag_counts(call_args_list): + return { + ts_data.tensorboard_time_series_id: len(ts_data.values) + for call_args in call_args_list + for ts_data in call_args[1]["write_run_data_requests"][0].time_series_data + } + + +def _extract_tag_counts_time_series(call_args_list): return { ts_data.tensorboard_time_series_id: len(ts_data.values) for call_args in call_args_list diff --git a/tests/unit/aiplatform/test_uploader_main.py b/tests/unit/aiplatform/test_uploader_main.py new file mode 100644 index 0000000000..417c865c27 --- /dev/null +++ b/tests/unit/aiplatform/test_uploader_main.py @@ -0,0 +1,127 @@ +# -*- coding: utf-8 -*- +# 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 +# +# 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. +# + +import pytest + +from importlib import reload +from unittest.mock import patch + +from google.api_core import exceptions +from google.cloud import aiplatform +from google.cloud.aiplatform import initializer +from google.cloud.aiplatform.tensorboard import uploader_main +from google.cloud.aiplatform.compat.types import job_state as gca_job_state_compat +from google.cloud.aiplatform.compat.types import custom_job as gca_custom_job_compat +from google.cloud.aiplatform.compat.services import ( + job_service_client, +) + +_TEST_PROJECT = "test-project" +_TEST_LOCATION = "us-central1" +_TEST_PARENT = f"projects/{_TEST_PROJECT}/locations/{_TEST_LOCATION}" +_TEST_CUSTOM_JOB_ID = "445768" +_TEST_CUSTOM_JOB_NAME = f"{_TEST_PARENT}/customJobs/{_TEST_CUSTOM_JOB_ID}" +_TEST_CUSTOM_JOBS_DISPLAY_NAME = "a custom job display name" +_TEST_PASSED_IN_EXPERIMENT_DISPLAY_NAME = "someDisplayName" + + +def _get_custom_job_proto(state=None, name=None): + custom_job_proto = gca_custom_job_compat.CustomJob() + custom_job_proto.name = name + custom_job_proto.state = state + custom_job_proto.display_name = _TEST_CUSTOM_JOBS_DISPLAY_NAME + return custom_job_proto + + +@pytest.fixture +def get_custom_job_mock_not_found(): + with patch.object( + job_service_client.JobServiceClient, "get_custom_job" + ) as get_custom_job_mock: + get_custom_job_mock.side_effect = exceptions.NotFound("not found") + yield get_custom_job_mock + + +@pytest.fixture +def get_custom_job_mock(): + with patch.object( + job_service_client.JobServiceClient, "get_custom_job" + ) as get_custom_job_mock: + get_custom_job_mock.side_effect = [ + _get_custom_job_proto( + name=_TEST_CUSTOM_JOB_NAME, + state=gca_job_state_compat.JobState.JOB_STATE_SUCCEEDED, + ), + ] + yield get_custom_job_mock + + +@pytest.mark.usefixtures("google_auth_mock") +class TestUploaderMain: + def setup_method(self): + reload(initializer) + reload(aiplatform) + aiplatform.init(project=_TEST_PROJECT, location=_TEST_LOCATION) + + def teardown_method(self): + initializer.global_pool.shutdown(wait=True) + + def test_get_default_custom_job_display_name(self, get_custom_job_mock): + aiplatform.init(project=_TEST_PROJECT) + assert ( + uploader_main.get_experiment_display_name_with_override( + _TEST_CUSTOM_JOB_ID, None, _TEST_PROJECT, _TEST_LOCATION + ) + == _TEST_CUSTOM_JOBS_DISPLAY_NAME + ) + + def test_non_decimal_experiment_name(self, get_custom_job_mock): + aiplatform.init(project=_TEST_PROJECT) + assert ( + uploader_main.get_experiment_display_name_with_override( + "someExperimentName", + _TEST_PASSED_IN_EXPERIMENT_DISPLAY_NAME, + _TEST_PROJECT, + _TEST_LOCATION, + ) + == _TEST_PASSED_IN_EXPERIMENT_DISPLAY_NAME + ) + get_custom_job_mock.assert_not_called() + + def test_display_name_already_specified(self, get_custom_job_mock): + aiplatform.init(project=_TEST_PROJECT) + assert ( + uploader_main.get_experiment_display_name_with_override( + _TEST_CUSTOM_JOB_ID, + _TEST_PASSED_IN_EXPERIMENT_DISPLAY_NAME, + _TEST_PROJECT, + _TEST_LOCATION, + ) + == _TEST_PASSED_IN_EXPERIMENT_DISPLAY_NAME + ) + get_custom_job_mock.assert_not_called() + + def test_custom_job_not_found(self, get_custom_job_mock_not_found): + aiplatform.init(project=_TEST_PROJECT) + assert ( + uploader_main.get_experiment_display_name_with_override( + _TEST_CUSTOM_JOB_ID, + _TEST_PASSED_IN_EXPERIMENT_DISPLAY_NAME, + _TEST_PROJECT, + _TEST_LOCATION, + ) + == _TEST_PASSED_IN_EXPERIMENT_DISPLAY_NAME + ) diff --git a/tests/unit/aiplatform/test_utils.py b/tests/unit/aiplatform/test_utils.py index c5ce327db8..6651990c5a 100644 --- a/tests/unit/aiplatform/test_utils.py +++ b/tests/unit/aiplatform/test_utils.py @@ -16,122 +16,34 @@ # -import pytest -from uuid import uuid4 -from random import choice -from random import randint -from string import ascii_letters +import datetime +import json +import os +from typing import Callable, Dict, Optional +from unittest import mock +from urllib import request -from google.api_core import client_options -from google.api_core import gapic_v1 +import pytest +import yaml +from google.api_core import client_options, gapic_v1 from google.cloud import aiplatform -from google.cloud.aiplatform import compat -from google.cloud.aiplatform import utils - -from google.cloud.aiplatform_v1beta1.services.model_service import ( - client as model_service_client_v1beta1, -) +from google.cloud.aiplatform import compat, utils +from google.cloud.aiplatform.compat.types import pipeline_failure_policy +from google.cloud.aiplatform.utils import pipeline_utils, tensorboard_utils, yaml_utils from google.cloud.aiplatform_v1.services.model_service import ( client as model_service_client_v1, ) - -model_service_client_default = model_service_client_v1 - - -@pytest.mark.parametrize( - "resource_name, expected", - [ - ("projects/123456/locations/us-central1/datasets/987654", True), - ("projects/857392/locations/us-central1/trainingPipelines/347292", True), - ("projects/acme-co-proj-1/locations/us-central1/datasets/123456", True), - ("projects/acme-co-proj-1/locations/us-central1/datasets/abcdef", True), - ("projects/acme-co-proj-1/locations/us-central1/datasets/abc-def", True), - ("project/123456/locations/us-central1/datasets/987654", False), - ("project//locations//datasets/987654", False), - ("locations/europe-west4/datasets/987654", False), - ("987654", False), - ], +from google.cloud.aiplatform_v1beta1.services.model_service import ( + client as model_service_client_v1beta1, ) -def test_extract_fields_from_resource_name(resource_name: str, expected: bool): - # Given a resource name and expected validity, test extract_fields_from_resource_name() - assert expected == bool(utils.extract_fields_from_resource_name(resource_name)) - - -@pytest.fixture -def generated_resource_fields(): - generated_fields = utils.Fields( - project=str(uuid4()), - location=str(uuid4()), - resource="".join(choice(ascii_letters) for i in range(10)), # 10 random letters - id=str(randint(0, 100000)), - ) - - yield generated_fields - - -@pytest.fixture -def generated_resource_name(generated_resource_fields: utils.Fields): - name = ( - f"projects/{generated_resource_fields.project}/" - f"locations/{generated_resource_fields.location}" - f"/{generated_resource_fields.resource}/{generated_resource_fields.id}" - ) - - yield name - - -def test_extract_fields_from_resource_name_with_extracted_fields( - generated_resource_name: str, generated_resource_fields: utils.Fields -): - """Verify fields extracted from resource name match the original fields""" - - assert ( - utils.extract_fields_from_resource_name(resource_name=generated_resource_name) - == generated_resource_fields - ) - +from google.protobuf import timestamp_pb2 -@pytest.mark.parametrize( - "resource_name, resource_noun, expected", - [ - # Expects pattern "projects/.../locations/.../datasets/..." - ("projects/123456/locations/us-central1/datasets/987654", "datasets", True), - # Expects pattern "projects/.../locations/.../batchPredictionJobs/..." - ( - "projects/857392/locations/us-central1/trainingPipelines/347292", - "batchPredictionJobs", - False, - ), - # Expects pattern "projects/.../locations/.../metadataStores/.../contexts/..." - ( - "projects/857392/locations/us-central1/metadataStores/default/contexts/123", - "metadataStores/default/contexts", - True, - ), - # Expects pattern "projects/.../locations/.../tensorboards/.../experiments/.../runs/.../timeSeries/..." - ( - "projects/857392/locations/us-central1/tensorboards/123/experiments/456/runs/789/timeSeries/1", - "tensorboards/123/experiments/456/runs/789/timeSeries", - True, - ), - ], -) -def test_extract_fields_from_resource_name_with_resource_noun( - resource_name: str, resource_noun: str, expected: bool -): - assert ( - bool( - utils.extract_fields_from_resource_name( - resource_name=resource_name, resource_noun=resource_noun - ) - ) - == expected - ) +model_service_client_default = model_service_client_v1 def test_invalid_region_raises_with_invalid_region(): with pytest.raises(ValueError): - aiplatform.utils.validate_region(region="us-west4") + aiplatform.utils.validate_region(region="us-west3") def test_invalid_region_does_not_raise_with_valid_region(): @@ -139,42 +51,69 @@ def test_invalid_region_does_not_raise_with_valid_region(): @pytest.mark.parametrize( - "resource_noun, project, location, full_name", + "resource_noun, project, parse_resource_name_method, format_resource_name_method, parent_resource_name_fields, location, full_name", [ ( "datasets", "123456", + aiplatform.TabularDataset._parse_resource_name, + aiplatform.TabularDataset._format_resource_name, + None, "us-central1", "projects/123456/locations/us-central1/datasets/987654", ), ( "trainingPipelines", "857392", + aiplatform.CustomTrainingJob._parse_resource_name, + aiplatform.CustomTrainingJob._format_resource_name, + None, "us-west20", "projects/857392/locations/us-central1/trainingPipelines/347292", ), ( - "metadataStores/default/contexts", + "contexts", "123456", + aiplatform.metadata.context._Context._parse_resource_name, + aiplatform.metadata.context._Context._format_resource_name, + { + aiplatform.metadata.metadata_store._MetadataStore._resource_noun: "default" + }, "europe-west4", "projects/857392/locations/us-central1/metadataStores/default/contexts/123", ), ( - "tensorboards/123/experiments/456/runs/789/timeSeries", + "timeSeries", "857392", + aiplatform.gapic.TensorboardServiceClient.parse_tensorboard_time_series_path, + aiplatform.gapic.TensorboardServiceClient.tensorboard_time_series_path, + { + aiplatform.Tensorboard._resource_noun: "123", + "experiments": "456", + "runs": "789", + }, "us-central1", "projects/857392/locations/us-central1/tensorboards/123/experiments/456/runs/789/timeSeries/1", ), ], ) def test_full_resource_name_with_full_name( - resource_noun: str, project: str, location: str, full_name: str, + resource_noun: str, + project: str, + parse_resource_name_method: Callable[[str], Dict[str, str]], + format_resource_name_method: Callable[..., str], + parent_resource_name_fields: Optional[Dict[str, str]], + location: str, + full_name: str, ): # should ignore issues with other arguments as resource_name is full_name assert ( aiplatform.utils.full_resource_name( resource_name=full_name, resource_noun=resource_noun, + parse_resource_name_method=parse_resource_name_method, + format_resource_name_method=format_resource_name_method, + parent_resource_name_fields=parent_resource_name_fields, project=project, location=location, ) @@ -183,11 +122,14 @@ def test_full_resource_name_with_full_name( @pytest.mark.parametrize( - "partial_name, resource_noun, project, location, full_name", + "partial_name, resource_noun, parse_resource_name_method, format_resource_name_method, parent_resource_name_fields, project, location, full_name", [ ( "987654", "datasets", + aiplatform.TabularDataset._parse_resource_name, + aiplatform.TabularDataset._format_resource_name, + None, "123456", "us-central1", "projects/123456/locations/us-central1/datasets/987654", @@ -195,20 +137,35 @@ def test_full_resource_name_with_full_name( ( "347292", "trainingPipelines", + aiplatform.CustomTrainingJob._parse_resource_name, + aiplatform.CustomTrainingJob._format_resource_name, + None, "857392", "us-central1", "projects/857392/locations/us-central1/trainingPipelines/347292", ), ( "123", - "metadataStores/default/contexts", + "contexts", + aiplatform.metadata.context._Context._parse_resource_name, + aiplatform.metadata.context._Context._format_resource_name, + { + aiplatform.metadata.metadata_store._MetadataStore._resource_noun: "default" + }, "857392", "us-central1", "projects/857392/locations/us-central1/metadataStores/default/contexts/123", ), ( "1", - "tensorboards/123/experiments/456/runs/789/timeSeries", + "timeSeries", + aiplatform.gapic.TensorboardServiceClient.parse_tensorboard_time_series_path, + aiplatform.gapic.TensorboardServiceClient.tensorboard_time_series_path, + { + aiplatform.Tensorboard._resource_noun: "123", + "experiments": "456", + "runs": "789", + }, "857392", "us-central1", "projects/857392/locations/us-central1/tensorboards/123/experiments/456/runs/789/timeSeries/1", @@ -216,12 +173,22 @@ def test_full_resource_name_with_full_name( ], ) def test_full_resource_name_with_partial_name( - partial_name: str, resource_noun: str, project: str, location: str, full_name: str, + partial_name: str, + resource_noun: str, + parse_resource_name_method: Callable[[str], Dict[str, str]], + format_resource_name_method: Callable[..., str], + parent_resource_name_fields: Optional[Dict[str, str]], + project: str, + location: str, + full_name: str, ): assert ( aiplatform.utils.full_resource_name( resource_name=partial_name, resource_noun=resource_noun, + parse_resource_name_method=parse_resource_name_method, + format_resource_name_method=format_resource_name_method, + parent_resource_name_fields=parent_resource_name_fields, project=project, location=location, ) @@ -234,12 +201,17 @@ def test_full_resource_name_with_partial_name( [("347292", "trainingPipelines", "857392", "us-west2020")], ) def test_full_resource_name_raises_value_error( - partial_name: str, resource_noun: str, project: str, location: str, + partial_name: str, + resource_noun: str, + project: str, + location: str, ): with pytest.raises(ValueError): aiplatform.utils.full_resource_name( resource_name=partial_name, resource_noun=resource_noun, + parse_resource_name_method=aiplatform.CustomTrainingJob._parse_resource_name, + format_resource_name_method=aiplatform.CustomTrainingJob._format_resource_name, project=project, location=location, ) @@ -256,6 +228,20 @@ def test_validate_display_name(): aiplatform.utils.validate_display_name("my_model_abc") +def test_validate_labels_raises_value_not_str(): + with pytest.raises(ValueError): + aiplatform.utils.validate_labels({"my_key1": 1, "my_key2": 2}) + + +def test_validate_labels_raises_key_not_str(): + with pytest.raises(ValueError): + aiplatform.utils.validate_labels({1: "my_value1", 2: "my_value2"}) + + +def test_validate_labels(): + aiplatform.utils.validate_labels({"my_key1": "my_value1", "my_key2": "my_value2"}) + + @pytest.mark.parametrize( "accelerator_type, expected", [ @@ -293,6 +279,7 @@ def test_extract_bucket_and_prefix_from_gcs_path(gcs_path: str, expected: tuple) assert expected == utils.extract_bucket_and_prefix_from_gcs_path(gcs_path) +@pytest.mark.usefixtures("google_auth_mock") def test_wrapped_client(): test_client_info = gapic_v1.client_info.ClientInfo() test_client_options = client_options.ClientOptions() @@ -315,7 +302,8 @@ def test_client_w_override_default_version(): test_client_options = client_options.ClientOptions() client_w_override = utils.ModelClientWithOverride( - client_options=test_client_options, client_info=test_client_info, + client_options=test_client_options, + client_info=test_client_info, ) assert isinstance( client_w_override._clients[ @@ -331,7 +319,8 @@ def test_client_w_override_select_version(): test_client_options = client_options.ClientOptions() client_w_override = utils.ModelClientWithOverride( - client_options=test_client_options, client_info=test_client_info, + client_options=test_client_options, + client_info=test_client_info, ) assert isinstance( @@ -342,3 +331,298 @@ def test_client_w_override_select_version(): client_w_override.select_version(compat.V1).get_model.__self__, model_service_client_v1.ModelServiceClient, ) + + +@pytest.mark.parametrize( + "year,month,day,hour,minute,second,microsecond,expected_seconds,expected_nanos", + [ + ( + 2021, + 12, + 23, + 23, + 59, + 59, + 999999, + 1640303999, + 999000000, + ), + ( + 2013, + 1, + 1, + 1, + 1, + 1, + 199999, + 1357002061, + 199000000, + ), + ], +) +def test_get_timestamp_proto( + year, + month, + day, + hour, + minute, + second, + microsecond, + expected_seconds, + expected_nanos, +): + time = datetime.datetime( + year=year, + month=month, + day=day, + hour=hour, + minute=minute, + second=second, + microsecond=microsecond, + ) + true_timestamp_proto = timestamp_pb2.Timestamp( + seconds=expected_seconds, nanos=expected_nanos + ) + assert true_timestamp_proto == utils.get_timestamp_proto(time) + + +class TestPipelineUtils: + SAMPLE_JOB_SPEC = { + "pipelineSpec": { + "root": { + "inputDefinitions": { + "parameters": { + "string_param": {"type": "STRING"}, + "int_param": {"type": "INT"}, + "float_param": {"type": "DOUBLE"}, + "new_param": {"type": "STRING"}, + "bool_param": {"type": "STRING"}, + "dict_param": {"type": "STRING"}, + "list_param": {"type": "STRING"}, + } + } + }, + "schemaVersion": "2.0.0", + }, + "runtimeConfig": { + "gcsOutputDirectory": "path/to/my/root", + "parameters": { + "string_param": {"stringValue": "test-string"}, + "int_param": {"intValue": 42}, + "float_param": {"doubleValue": 3.14}, + }, + }, + } + + def test_pipeline_utils_runtime_config_builder_from_values(self): + my_builder = pipeline_utils.PipelineRuntimeConfigBuilder( + pipeline_root="path/to/my/root", + schema_version="2.0.0", + parameter_types={ + "string_param": "STRING", + "int_param": "INT", + "float_param": "DOUBLE", + }, + parameter_values={ + "string_param": "test-string", + "int_param": 42, + "float_param": 3.14, + }, + ) + actual_runtime_config = my_builder.build() + assert True + + expected_runtime_config = self.SAMPLE_JOB_SPEC["runtimeConfig"] + assert expected_runtime_config == actual_runtime_config + + def test_pipeline_utils_runtime_config_builder_from_json(self): + my_builder = pipeline_utils.PipelineRuntimeConfigBuilder.from_job_spec_json( + self.SAMPLE_JOB_SPEC + ) + actual_runtime_config = my_builder.build() + + expected_runtime_config = self.SAMPLE_JOB_SPEC["runtimeConfig"] + assert expected_runtime_config == actual_runtime_config + + def test_pipeline_utils_runtime_config_builder_with_no_op_updates(self): + my_builder = pipeline_utils.PipelineRuntimeConfigBuilder.from_job_spec_json( + self.SAMPLE_JOB_SPEC + ) + my_builder.update_pipeline_root(None) + my_builder.update_runtime_parameters(None) + actual_runtime_config = my_builder.build() + + expected_runtime_config = self.SAMPLE_JOB_SPEC["runtimeConfig"] + assert expected_runtime_config == actual_runtime_config + + @pytest.mark.parametrize( + "failure_policy", + [ + ( + "slow", + pipeline_failure_policy.PipelineFailurePolicy.PIPELINE_FAILURE_POLICY_FAIL_SLOW, + ), + ( + "fast", + pipeline_failure_policy.PipelineFailurePolicy.PIPELINE_FAILURE_POLICY_FAIL_FAST, + ), + ], + ) + def test_pipeline_utils_runtime_config_builder_with_merge_updates( + self, failure_policy + ): + my_builder = pipeline_utils.PipelineRuntimeConfigBuilder.from_job_spec_json( + self.SAMPLE_JOB_SPEC + ) + my_builder.update_pipeline_root("path/to/my/new/root") + my_builder.update_runtime_parameters( + { + "int_param": 888, + "new_param": "new-string", + "dict_param": {"a": 1}, + "list_param": [1, 2, 3], + "bool_param": True, + } + ) + my_builder.update_failure_policy(failure_policy[0]) + actual_runtime_config = my_builder.build() + + expected_runtime_config = { + "gcsOutputDirectory": "path/to/my/new/root", + "parameters": { + "string_param": {"stringValue": "test-string"}, + "int_param": {"intValue": 888}, + "float_param": {"doubleValue": 3.14}, + "new_param": {"stringValue": "new-string"}, + "dict_param": {"stringValue": '{"a": 1}'}, + "list_param": {"stringValue": "[1, 2, 3]"}, + "bool_param": {"stringValue": "true"}, + }, + "failurePolicy": failure_policy[1], + } + assert expected_runtime_config == actual_runtime_config + + def test_pipeline_utils_runtime_config_builder_invalid_failure_policy(self): + my_builder = pipeline_utils.PipelineRuntimeConfigBuilder.from_job_spec_json( + self.SAMPLE_JOB_SPEC + ) + with pytest.raises(ValueError) as e: + my_builder.update_failure_policy("slo") + + assert e.match( + regexp=r'failure_policy should be either "slow" or "fast", but got: "slo".' + ) + + def test_pipeline_utils_runtime_config_builder_parameter_not_found(self): + my_builder = pipeline_utils.PipelineRuntimeConfigBuilder.from_job_spec_json( + self.SAMPLE_JOB_SPEC + ) + my_builder.update_pipeline_root("path/to/my/new/root") + my_builder.update_runtime_parameters({"no_such_param": "new-string"}) + with pytest.raises(ValueError) as e: + my_builder.build() + + assert e.match(regexp=r"The pipeline parameter no_such_param is not found") + + +class TestTensorboardUtils: + def test_tensorboard_get_experiment_url(self): + actual = tensorboard_utils.get_experiment_url( + "projects/123/locations/asia-east1/tensorboards/456/experiments/exp1" + ) + assert actual == ( + "https://asia-east1.tensorboard." + + "googleusercontent.com/experiment/projects+123+locations+asia-east1+tensorboards+456+experiments+exp1" + ) + + def test_get_experiments_url_bad_experiment_name(self): + with pytest.raises(ValueError, match="Invalid experiment name: foo-bar."): + tensorboard_utils.get_experiment_url("foo-bar") + + def test_tensorboard_get_experiments_compare_url(self): + actual = tensorboard_utils.get_experiments_compare_url( + ( + "projects/123/locations/asia-east1/tensorboards/456/experiments/exp1", + "projects/123/locations/asia-east1/tensorboards/456/experiments/exp2", + ) + ) + assert actual == ( + "https://asia-east1.tensorboard." + + "googleusercontent.com/compare/1-exp1:123+asia-east1+456+exp1," + + "2-exp2:123+asia-east1+456+exp2" + ) + + def test_tensorboard_get_experiments_compare_url_fail_just_one_exp(self): + with pytest.raises( + ValueError, match="At least two experiment_names are required." + ): + tensorboard_utils.get_experiments_compare_url( + ("projects/123/locations/asia-east1/tensorboards/456/experiments/exp1",) + ) + + def test_tensorboard_get_experiments_compare_url_fail_diff_region(self): + with pytest.raises( + ValueError, + match="Got experiments from different locations: asia-east.", + ): + tensorboard_utils.get_experiments_compare_url( + ( + "projects/123/locations/asia-east1/tensorboards/456/experiments/exp1", + "projects/123/locations/asia-east2/tensorboards/456/experiments/exp2", + ) + ) + + def test_get_experiments_compare_url_bad_experiment_name(self): + with pytest.raises(ValueError, match="Invalid experiment name: foo-bar."): + tensorboard_utils.get_experiments_compare_url(("foo-bar", "foo-bar1")) + + +@pytest.fixture(scope="function") +def yaml_file(tmp_path): + data = {"key": "val", "list": ["1", 2, 3.0]} + yaml_file_path = os.path.join(tmp_path, "test.yaml") + with open(yaml_file_path, "w") as f: + yaml.dump(data, f) + yield yaml_file_path + + +@pytest.fixture(scope="function") +def json_file(tmp_path): + data = {"key": "val", "list": ["1", 2, 3.0]} + json_file_path = os.path.join(tmp_path, "test.json") + with open(json_file_path, "w") as f: + json.dump(data, f) + yield json_file_path + + +@pytest.fixture(scope="function") +def mock_request_urlopen(): + data = {"key": "val", "list": ["1", 2, 3.0]} + with mock.patch.object(request, "urlopen") as mock_urlopen: + mock_read_response = mock.MagicMock() + mock_decode_response = mock.MagicMock() + mock_decode_response.return_value = json.dumps(data) + mock_read_response.return_value.decode = mock_decode_response + mock_urlopen.return_value.read = mock_read_response + yield "https://us-central1-kfp.pkg.dev/proj/repo/pack/latest" + + +class TestYamlUtils: + def test_load_yaml_from_local_file__with_yaml(self, yaml_file): + actual = yaml_utils.load_yaml(yaml_file) + expected = {"key": "val", "list": ["1", 2, 3.0]} + assert actual == expected + + def test_load_yaml_from_local_file__with_json(self, json_file): + actual = yaml_utils.load_yaml(json_file) + expected = {"key": "val", "list": ["1", 2, 3.0]} + assert actual == expected + + def test_load_yaml_from_ar_uri(self, mock_request_urlopen): + actual = yaml_utils.load_yaml(mock_request_urlopen) + expected = {"key": "val", "list": ["1", 2, 3.0]} + assert actual == expected + + def test_load_yaml_from_invalid_uri(self): + with pytest.raises(FileNotFoundError): + yaml_utils.load_yaml("https://us-docker.pkg.dev/v2/proj/repo/img/tags/list") diff --git a/tests/unit/enhanced_library/test_value_converter.py b/tests/unit/enhanced_library/test_value_converter.py index b39512611b..4bb24372e2 100644 --- a/tests/unit/enhanced_library/test_value_converter.py +++ b/tests/unit/enhanced_library/test_value_converter.py @@ -13,7 +13,7 @@ # limitations under the License. from __future__ import absolute_import -from google.cloud.aiplatform.helpers import value_converter +from google.cloud.aiplatform.utils.enhanced_library import value_converter from google.protobuf import json_format from google.protobuf.struct_pb2 import Value import proto @@ -63,9 +63,7 @@ def test_convert_value_to_message(): actual_from_value_output = value_converter.from_value(SomeMessage, input_value) expected_type = SomeMessage(input_dict) - # TODO: compare instance of SomeMessage against - # actual_from_value_output. - # See https://github.com/googleapis/python-aiplatform/issues/136 + assert actual_from_value_output.__class__.__name__ == SomeMessage.__name__ # Check property-level ("duck-typing") equivalency assert actual_from_value_output.test_str == expected_type.test_str @@ -79,9 +77,7 @@ def test_convert_map_to_message(): map_composite = message_with_map.test_map actual_output = value_converter.from_map(SomeOutType, map_composite) - # TODO: compare instance of SomeMessage against - # actual_from_value_output. - # See https://github.com/googleapis/python-aiplatform/issues/136 + assert actual_output.__class__.__name__ == SomeOutType.__name__ # Check property-to-key/value equivalency assert actual_output.test_int == map_composite["test_int"] diff --git a/tests/unit/gapic/__init__.py b/tests/unit/gapic/__init__.py index 4de65971c2..e8e1c3845d 100644 --- a/tests/unit/gapic/__init__.py +++ b/tests/unit/gapic/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/unit/gapic/aiplatform_v1/__init__.py b/tests/unit/gapic/aiplatform_v1/__init__.py index 4de65971c2..e8e1c3845d 100644 --- a/tests/unit/gapic/aiplatform_v1/__init__.py +++ b/tests/unit/gapic/aiplatform_v1/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/unit/gapic/aiplatform_v1/test_dataset_service.py b/tests/unit/gapic/aiplatform_v1/test_dataset_service.py index 6ebf22cd26..b6979a4ac4 100644 --- a/tests/unit/gapic/aiplatform_v1/test_dataset_service.py +++ b/tests/unit/gapic/aiplatform_v1/test_dataset_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,8 +14,13 @@ # limitations under the License. # import os -import mock -import packaging.version + +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock +except ImportError: + import mock import grpc from grpc.experimental import aio @@ -30,8 +35,10 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.aiplatform_v1.services.dataset_service import ( @@ -40,12 +47,6 @@ from google.cloud.aiplatform_v1.services.dataset_service import DatasetServiceClient from google.cloud.aiplatform_v1.services.dataset_service import pagers from google.cloud.aiplatform_v1.services.dataset_service import transports -from google.cloud.aiplatform_v1.services.dataset_service.transports.base import ( - _API_CORE_VERSION, -) -from google.cloud.aiplatform_v1.services.dataset_service.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.aiplatform_v1.types import annotation from google.cloud.aiplatform_v1.types import annotation_spec from google.cloud.aiplatform_v1.types import data_item @@ -55,6 +56,10 @@ from google.cloud.aiplatform_v1.types import encryption_spec from google.cloud.aiplatform_v1.types import io from google.cloud.aiplatform_v1.types import operation as gca_operation +from google.cloud.location import locations_pb2 +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 from google.oauth2 import service_account from google.protobuf import field_mask_pb2 # type: ignore @@ -63,29 +68,6 @@ import google.auth -# TODO(busunkim): Once google-api-core >= 1.26.0 is required: -# - Delete all the api-core and auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - -requires_api_core_lt_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), - reason="This test requires google-api-core < 1.26.0", -) - -requires_api_core_gte_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), - reason="This test requires google-api-core >= 1.26.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -131,40 +113,77 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( - "client_class", [DatasetServiceClient, DatasetServiceAsyncClient,] + "client_class,transport_name", + [ + (DatasetServiceClient, "grpc"), + (DatasetServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_dataset_service_client_from_service_account_info(client_class): +def test_dataset_service_client_from_service_account_info(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.DatasetServiceGrpcTransport, "grpc"), + (transports.DatasetServiceGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_dataset_service_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() @pytest.mark.parametrize( - "client_class", [DatasetServiceClient, DatasetServiceAsyncClient,] + "client_class,transport_name", + [ + (DatasetServiceClient, "grpc"), + (DatasetServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_dataset_service_client_from_service_account_file(client_class): +def test_dataset_service_client_from_service_account_file(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") def test_dataset_service_client_get_transport_class(): @@ -217,7 +236,7 @@ def test_dataset_service_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -226,6 +245,7 @@ def test_dataset_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -233,7 +253,7 @@ def test_dataset_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -242,6 +262,7 @@ def test_dataset_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -249,7 +270,7 @@ def test_dataset_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -258,26 +279,27 @@ def test_dataset_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -286,6 +308,7 @@ def test_dataset_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -335,7 +358,7 @@ def test_dataset_service_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -352,6 +375,7 @@ def test_dataset_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case ADC client cert is provided. Whether client cert is used depends on @@ -376,7 +400,7 @@ def test_dataset_service_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -385,6 +409,7 @@ def test_dataset_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case client_cert_source and ADC client cert are not provided. @@ -397,7 +422,7 @@ def test_dataset_service_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -406,9 +431,91 @@ def test_dataset_service_client_mtls_env_auto( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) +@pytest.mark.parametrize( + "client_class", [DatasetServiceClient, DatasetServiceAsyncClient] +) +@mock.patch.object( + DatasetServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(DatasetServiceClient), +) +@mock.patch.object( + DatasetServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(DatasetServiceAsyncClient), +) +def test_dataset_service_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + @pytest.mark.parametrize( "client_class,transport_class,transport_name", [ @@ -424,10 +531,12 @@ def test_dataset_service_client_client_options_scopes( client_class, transport_class, transport_name ): # Check the case scopes are provided. - options = client_options.ClientOptions(scopes=["1", "2"],) + options = client_options.ClientOptions( + scopes=["1", "2"], + ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -436,28 +545,36 @@ def test_dataset_service_client_client_options_scopes( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (DatasetServiceClient, transports.DatasetServiceGrpcTransport, "grpc"), + ( + DatasetServiceClient, + transports.DatasetServiceGrpcTransport, + "grpc", + grpc_helpers, + ), ( DatasetServiceAsyncClient, transports.DatasetServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_dataset_service_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -466,6 +583,7 @@ def test_dataset_service_client_client_options_credentials_file( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -485,14 +603,87 @@ def test_dataset_service_client_client_options_from_dict(): client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) -def test_create_dataset( - transport: str = "grpc", request_type=dataset_service.CreateDatasetRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + DatasetServiceClient, + transports.DatasetServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + DatasetServiceAsyncClient, + transports.DatasetServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_dataset_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers ): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + dataset_service.CreateDatasetRequest, + dict, + ], +) +def test_create_dataset(request_type, transport: str = "grpc"): client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -514,15 +705,12 @@ def test_create_dataset( assert isinstance(response, future.Future) -def test_create_dataset_from_dict(): - test_create_dataset(request_type=dict) - - def test_create_dataset_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -538,7 +726,8 @@ async def test_create_dataset_async( transport: str = "grpc_asyncio", request_type=dataset_service.CreateDatasetRequest ): client = DatasetServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -568,13 +757,15 @@ async def test_create_dataset_async_from_dict(): def test_create_dataset_field_headers(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = dataset_service.CreateDatasetRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_dataset), "__call__") as call: @@ -588,7 +779,10 @@ def test_create_dataset_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -601,7 +795,7 @@ async def test_create_dataset_field_headers_async(): # a field header. Set these to a non-empty value. request = dataset_service.CreateDatasetRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_dataset), "__call__") as call: @@ -617,11 +811,16 @@ async def test_create_dataset_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_create_dataset_flattened(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_dataset), "__call__") as call: @@ -630,19 +829,26 @@ def test_create_dataset_flattened(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.create_dataset( - parent="parent_value", dataset=gca_dataset.Dataset(name="name_value"), + parent="parent_value", + dataset=gca_dataset.Dataset(name="name_value"), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].dataset == gca_dataset.Dataset(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].dataset + mock_val = gca_dataset.Dataset(name="name_value") + assert arg == mock_val def test_create_dataset_flattened_error(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -671,15 +877,20 @@ async def test_create_dataset_flattened_async(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. response = await client.create_dataset( - parent="parent_value", dataset=gca_dataset.Dataset(name="name_value"), + parent="parent_value", + dataset=gca_dataset.Dataset(name="name_value"), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].dataset == gca_dataset.Dataset(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].dataset + mock_val = gca_dataset.Dataset(name="name_value") + assert arg == mock_val @pytest.mark.asyncio @@ -698,11 +909,17 @@ async def test_create_dataset_flattened_error_async(): ) -def test_get_dataset( - transport: str = "grpc", request_type=dataset_service.GetDatasetRequest -): +@pytest.mark.parametrize( + "request_type", + [ + dataset_service.GetDatasetRequest, + dict, + ], +) +def test_get_dataset(request_type, transport: str = "grpc"): client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -715,6 +932,7 @@ def test_get_dataset( call.return_value = dataset.Dataset( name="name_value", display_name="display_name_value", + description="description_value", metadata_schema_uri="metadata_schema_uri_value", etag="etag_value", ) @@ -729,19 +947,17 @@ def test_get_dataset( assert isinstance(response, dataset.Dataset) assert response.name == "name_value" assert response.display_name == "display_name_value" + assert response.description == "description_value" assert response.metadata_schema_uri == "metadata_schema_uri_value" assert response.etag == "etag_value" -def test_get_dataset_from_dict(): - test_get_dataset(request_type=dict) - - def test_get_dataset_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -757,7 +973,8 @@ async def test_get_dataset_async( transport: str = "grpc_asyncio", request_type=dataset_service.GetDatasetRequest ): client = DatasetServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -771,6 +988,7 @@ async def test_get_dataset_async( dataset.Dataset( name="name_value", display_name="display_name_value", + description="description_value", metadata_schema_uri="metadata_schema_uri_value", etag="etag_value", ) @@ -786,6 +1004,7 @@ async def test_get_dataset_async( assert isinstance(response, dataset.Dataset) assert response.name == "name_value" assert response.display_name == "display_name_value" + assert response.description == "description_value" assert response.metadata_schema_uri == "metadata_schema_uri_value" assert response.etag == "etag_value" @@ -796,13 +1015,15 @@ async def test_get_dataset_async_from_dict(): def test_get_dataset_field_headers(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = dataset_service.GetDatasetRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_dataset), "__call__") as call: @@ -816,7 +1037,10 @@ def test_get_dataset_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -829,7 +1053,7 @@ async def test_get_dataset_field_headers_async(): # a field header. Set these to a non-empty value. request = dataset_service.GetDatasetRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_dataset), "__call__") as call: @@ -843,11 +1067,16 @@ async def test_get_dataset_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_get_dataset_flattened(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_dataset), "__call__") as call: @@ -855,23 +1084,30 @@ def test_get_dataset_flattened(): call.return_value = dataset.Dataset() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_dataset(name="name_value",) + client.get_dataset( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_dataset_flattened_error(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.get_dataset( - dataset_service.GetDatasetRequest(), name="name_value", + dataset_service.GetDatasetRequest(), + name="name_value", ) @@ -889,13 +1125,17 @@ async def test_get_dataset_flattened_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(dataset.Dataset()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_dataset(name="name_value",) + response = await client.get_dataset( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -908,15 +1148,22 @@ async def test_get_dataset_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.get_dataset( - dataset_service.GetDatasetRequest(), name="name_value", + dataset_service.GetDatasetRequest(), + name="name_value", ) -def test_update_dataset( - transport: str = "grpc", request_type=dataset_service.UpdateDatasetRequest -): +@pytest.mark.parametrize( + "request_type", + [ + dataset_service.UpdateDatasetRequest, + dict, + ], +) +def test_update_dataset(request_type, transport: str = "grpc"): client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -929,6 +1176,7 @@ def test_update_dataset( call.return_value = gca_dataset.Dataset( name="name_value", display_name="display_name_value", + description="description_value", metadata_schema_uri="metadata_schema_uri_value", etag="etag_value", ) @@ -943,19 +1191,17 @@ def test_update_dataset( assert isinstance(response, gca_dataset.Dataset) assert response.name == "name_value" assert response.display_name == "display_name_value" + assert response.description == "description_value" assert response.metadata_schema_uri == "metadata_schema_uri_value" assert response.etag == "etag_value" -def test_update_dataset_from_dict(): - test_update_dataset(request_type=dict) - - def test_update_dataset_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -971,7 +1217,8 @@ async def test_update_dataset_async( transport: str = "grpc_asyncio", request_type=dataset_service.UpdateDatasetRequest ): client = DatasetServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -985,6 +1232,7 @@ async def test_update_dataset_async( gca_dataset.Dataset( name="name_value", display_name="display_name_value", + description="description_value", metadata_schema_uri="metadata_schema_uri_value", etag="etag_value", ) @@ -1000,6 +1248,7 @@ async def test_update_dataset_async( assert isinstance(response, gca_dataset.Dataset) assert response.name == "name_value" assert response.display_name == "display_name_value" + assert response.description == "description_value" assert response.metadata_schema_uri == "metadata_schema_uri_value" assert response.etag == "etag_value" @@ -1010,13 +1259,15 @@ async def test_update_dataset_async_from_dict(): def test_update_dataset_field_headers(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = dataset_service.UpdateDatasetRequest() - request.dataset.name = "dataset.name/value" + request.dataset.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_dataset), "__call__") as call: @@ -1030,9 +1281,10 @@ def test_update_dataset_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "dataset.name=dataset.name/value",) in kw[ - "metadata" - ] + assert ( + "x-goog-request-params", + "dataset.name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1045,7 +1297,7 @@ async def test_update_dataset_field_headers_async(): # a field header. Set these to a non-empty value. request = dataset_service.UpdateDatasetRequest() - request.dataset.name = "dataset.name/value" + request.dataset.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_dataset), "__call__") as call: @@ -1059,13 +1311,16 @@ async def test_update_dataset_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "dataset.name=dataset.name/value",) in kw[ - "metadata" - ] + assert ( + "x-goog-request-params", + "dataset.name=name_value", + ) in kw["metadata"] def test_update_dataset_flattened(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_dataset), "__call__") as call: @@ -1082,12 +1337,18 @@ def test_update_dataset_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].dataset == gca_dataset.Dataset(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].dataset + mock_val = gca_dataset.Dataset(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val def test_update_dataset_flattened_error(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1122,8 +1383,12 @@ async def test_update_dataset_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].dataset == gca_dataset.Dataset(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].dataset + mock_val = gca_dataset.Dataset(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val @pytest.mark.asyncio @@ -1142,11 +1407,17 @@ async def test_update_dataset_flattened_error_async(): ) -def test_list_datasets( - transport: str = "grpc", request_type=dataset_service.ListDatasetsRequest -): +@pytest.mark.parametrize( + "request_type", + [ + dataset_service.ListDatasetsRequest, + dict, + ], +) +def test_list_datasets(request_type, transport: str = "grpc"): client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1171,15 +1442,12 @@ def test_list_datasets( assert response.next_page_token == "next_page_token_value" -def test_list_datasets_from_dict(): - test_list_datasets(request_type=dict) - - def test_list_datasets_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1195,7 +1463,8 @@ async def test_list_datasets_async( transport: str = "grpc_asyncio", request_type=dataset_service.ListDatasetsRequest ): client = DatasetServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1228,13 +1497,15 @@ async def test_list_datasets_async_from_dict(): def test_list_datasets_field_headers(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = dataset_service.ListDatasetsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_datasets), "__call__") as call: @@ -1248,7 +1519,10 @@ def test_list_datasets_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1261,7 +1535,7 @@ async def test_list_datasets_field_headers_async(): # a field header. Set these to a non-empty value. request = dataset_service.ListDatasetsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_datasets), "__call__") as call: @@ -1277,11 +1551,16 @@ async def test_list_datasets_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_datasets_flattened(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_datasets), "__call__") as call: @@ -1289,23 +1568,30 @@ def test_list_datasets_flattened(): call.return_value = dataset_service.ListDatasetsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_datasets(parent="parent_value",) + client.list_datasets( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_datasets_flattened_error(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.list_datasets( - dataset_service.ListDatasetsRequest(), parent="parent_value", + dataset_service.ListDatasetsRequest(), + parent="parent_value", ) @@ -1325,13 +1611,17 @@ async def test_list_datasets_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_datasets(parent="parent_value",) + response = await client.list_datasets( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1344,27 +1634,44 @@ async def test_list_datasets_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.list_datasets( - dataset_service.ListDatasetsRequest(), parent="parent_value", + dataset_service.ListDatasetsRequest(), + parent="parent_value", ) -def test_list_datasets_pager(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_datasets_pager(transport_name: str = "grpc"): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_datasets), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( dataset_service.ListDatasetsResponse( - datasets=[dataset.Dataset(), dataset.Dataset(), dataset.Dataset(),], + datasets=[ + dataset.Dataset(), + dataset.Dataset(), + dataset.Dataset(), + ], next_page_token="abc", ), - dataset_service.ListDatasetsResponse(datasets=[], next_page_token="def",), dataset_service.ListDatasetsResponse( - datasets=[dataset.Dataset(),], next_page_token="ghi", + datasets=[], + next_page_token="def", + ), + dataset_service.ListDatasetsResponse( + datasets=[ + dataset.Dataset(), + ], + next_page_token="ghi", ), dataset_service.ListDatasetsResponse( - datasets=[dataset.Dataset(), dataset.Dataset(),], + datasets=[ + dataset.Dataset(), + dataset.Dataset(), + ], ), RuntimeError, ) @@ -1377,28 +1684,44 @@ def test_list_datasets_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all(isinstance(i, dataset.Dataset) for i in results) -def test_list_datasets_pages(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_datasets_pages(transport_name: str = "grpc"): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_datasets), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( dataset_service.ListDatasetsResponse( - datasets=[dataset.Dataset(), dataset.Dataset(), dataset.Dataset(),], + datasets=[ + dataset.Dataset(), + dataset.Dataset(), + dataset.Dataset(), + ], next_page_token="abc", ), - dataset_service.ListDatasetsResponse(datasets=[], next_page_token="def",), dataset_service.ListDatasetsResponse( - datasets=[dataset.Dataset(),], next_page_token="ghi", + datasets=[], + next_page_token="def", ), dataset_service.ListDatasetsResponse( - datasets=[dataset.Dataset(), dataset.Dataset(),], + datasets=[ + dataset.Dataset(), + ], + next_page_token="ghi", + ), + dataset_service.ListDatasetsResponse( + datasets=[ + dataset.Dataset(), + dataset.Dataset(), + ], ), RuntimeError, ) @@ -1409,7 +1732,9 @@ def test_list_datasets_pages(): @pytest.mark.asyncio async def test_list_datasets_async_pager(): - client = DatasetServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1418,22 +1743,37 @@ async def test_list_datasets_async_pager(): # Set the response to a series of pages. call.side_effect = ( dataset_service.ListDatasetsResponse( - datasets=[dataset.Dataset(), dataset.Dataset(), dataset.Dataset(),], + datasets=[ + dataset.Dataset(), + dataset.Dataset(), + dataset.Dataset(), + ], next_page_token="abc", ), - dataset_service.ListDatasetsResponse(datasets=[], next_page_token="def",), dataset_service.ListDatasetsResponse( - datasets=[dataset.Dataset(),], next_page_token="ghi", + datasets=[], + next_page_token="def", + ), + dataset_service.ListDatasetsResponse( + datasets=[ + dataset.Dataset(), + ], + next_page_token="ghi", ), dataset_service.ListDatasetsResponse( - datasets=[dataset.Dataset(), dataset.Dataset(),], + datasets=[ + dataset.Dataset(), + dataset.Dataset(), + ], ), RuntimeError, ) - async_pager = await client.list_datasets(request={},) + async_pager = await client.list_datasets( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -1442,7 +1782,9 @@ async def test_list_datasets_async_pager(): @pytest.mark.asyncio async def test_list_datasets_async_pages(): - client = DatasetServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1451,30 +1793,51 @@ async def test_list_datasets_async_pages(): # Set the response to a series of pages. call.side_effect = ( dataset_service.ListDatasetsResponse( - datasets=[dataset.Dataset(), dataset.Dataset(), dataset.Dataset(),], + datasets=[ + dataset.Dataset(), + dataset.Dataset(), + dataset.Dataset(), + ], next_page_token="abc", ), - dataset_service.ListDatasetsResponse(datasets=[], next_page_token="def",), dataset_service.ListDatasetsResponse( - datasets=[dataset.Dataset(),], next_page_token="ghi", + datasets=[], + next_page_token="def", + ), + dataset_service.ListDatasetsResponse( + datasets=[ + dataset.Dataset(), + ], + next_page_token="ghi", ), dataset_service.ListDatasetsResponse( - datasets=[dataset.Dataset(), dataset.Dataset(),], + datasets=[ + dataset.Dataset(), + dataset.Dataset(), + ], ), RuntimeError, ) pages = [] - async for page_ in (await client.list_datasets(request={})).pages: + async for page_ in ( + await client.list_datasets(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_delete_dataset( - transport: str = "grpc", request_type=dataset_service.DeleteDatasetRequest -): +@pytest.mark.parametrize( + "request_type", + [ + dataset_service.DeleteDatasetRequest, + dict, + ], +) +def test_delete_dataset(request_type, transport: str = "grpc"): client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1496,15 +1859,12 @@ def test_delete_dataset( assert isinstance(response, future.Future) -def test_delete_dataset_from_dict(): - test_delete_dataset(request_type=dict) - - def test_delete_dataset_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1520,7 +1880,8 @@ async def test_delete_dataset_async( transport: str = "grpc_asyncio", request_type=dataset_service.DeleteDatasetRequest ): client = DatasetServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1550,13 +1911,15 @@ async def test_delete_dataset_async_from_dict(): def test_delete_dataset_field_headers(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = dataset_service.DeleteDatasetRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_dataset), "__call__") as call: @@ -1570,7 +1933,10 @@ def test_delete_dataset_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1583,7 +1949,7 @@ async def test_delete_dataset_field_headers_async(): # a field header. Set these to a non-empty value. request = dataset_service.DeleteDatasetRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_dataset), "__call__") as call: @@ -1599,11 +1965,16 @@ async def test_delete_dataset_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_delete_dataset_flattened(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_dataset), "__call__") as call: @@ -1611,23 +1982,30 @@ def test_delete_dataset_flattened(): call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_dataset(name="name_value",) + client.delete_dataset( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_delete_dataset_flattened_error(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.delete_dataset( - dataset_service.DeleteDatasetRequest(), name="name_value", + dataset_service.DeleteDatasetRequest(), + name="name_value", ) @@ -1647,13 +2025,17 @@ async def test_delete_dataset_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_dataset(name="name_value",) + response = await client.delete_dataset( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1666,15 +2048,22 @@ async def test_delete_dataset_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.delete_dataset( - dataset_service.DeleteDatasetRequest(), name="name_value", + dataset_service.DeleteDatasetRequest(), + name="name_value", ) -def test_import_data( - transport: str = "grpc", request_type=dataset_service.ImportDataRequest -): +@pytest.mark.parametrize( + "request_type", + [ + dataset_service.ImportDataRequest, + dict, + ], +) +def test_import_data(request_type, transport: str = "grpc"): client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1696,15 +2085,12 @@ def test_import_data( assert isinstance(response, future.Future) -def test_import_data_from_dict(): - test_import_data(request_type=dict) - - def test_import_data_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1720,7 +2106,8 @@ async def test_import_data_async( transport: str = "grpc_asyncio", request_type=dataset_service.ImportDataRequest ): client = DatasetServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1750,13 +2137,15 @@ async def test_import_data_async_from_dict(): def test_import_data_field_headers(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = dataset_service.ImportDataRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.import_data), "__call__") as call: @@ -1770,7 +2159,10 @@ def test_import_data_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1783,7 +2175,7 @@ async def test_import_data_field_headers_async(): # a field header. Set these to a non-empty value. request = dataset_service.ImportDataRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.import_data), "__call__") as call: @@ -1799,11 +2191,16 @@ async def test_import_data_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_import_data_flattened(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.import_data), "__call__") as call: @@ -1822,14 +2219,20 @@ def test_import_data_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].import_configs == [ + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].import_configs + mock_val = [ dataset.ImportDataConfig(gcs_source=io.GcsSource(uris=["uris_value"])) ] + assert arg == mock_val def test_import_data_flattened_error(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1870,10 +2273,14 @@ async def test_import_data_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].import_configs == [ + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].import_configs + mock_val = [ dataset.ImportDataConfig(gcs_source=io.GcsSource(uris=["uris_value"])) ] + assert arg == mock_val @pytest.mark.asyncio @@ -1894,11 +2301,17 @@ async def test_import_data_flattened_error_async(): ) -def test_export_data( - transport: str = "grpc", request_type=dataset_service.ExportDataRequest -): +@pytest.mark.parametrize( + "request_type", + [ + dataset_service.ExportDataRequest, + dict, + ], +) +def test_export_data(request_type, transport: str = "grpc"): client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1920,15 +2333,12 @@ def test_export_data( assert isinstance(response, future.Future) -def test_export_data_from_dict(): - test_export_data(request_type=dict) - - def test_export_data_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1944,7 +2354,8 @@ async def test_export_data_async( transport: str = "grpc_asyncio", request_type=dataset_service.ExportDataRequest ): client = DatasetServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1974,13 +2385,15 @@ async def test_export_data_async_from_dict(): def test_export_data_field_headers(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = dataset_service.ExportDataRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.export_data), "__call__") as call: @@ -1994,7 +2407,10 @@ def test_export_data_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2007,7 +2423,7 @@ async def test_export_data_field_headers_async(): # a field header. Set these to a non-empty value. request = dataset_service.ExportDataRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.export_data), "__call__") as call: @@ -2023,11 +2439,16 @@ async def test_export_data_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_export_data_flattened(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.export_data), "__call__") as call: @@ -2048,16 +2469,22 @@ def test_export_data_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].export_config == dataset.ExportDataConfig( + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].export_config + mock_val = dataset.ExportDataConfig( gcs_destination=io.GcsDestination( output_uri_prefix="output_uri_prefix_value" ) ) + assert arg == mock_val def test_export_data_flattened_error(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2102,12 +2529,16 @@ async def test_export_data_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].export_config == dataset.ExportDataConfig( + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].export_config + mock_val = dataset.ExportDataConfig( gcs_destination=io.GcsDestination( output_uri_prefix="output_uri_prefix_value" ) ) + assert arg == mock_val @pytest.mark.asyncio @@ -2130,11 +2561,17 @@ async def test_export_data_flattened_error_async(): ) -def test_list_data_items( - transport: str = "grpc", request_type=dataset_service.ListDataItemsRequest -): +@pytest.mark.parametrize( + "request_type", + [ + dataset_service.ListDataItemsRequest, + dict, + ], +) +def test_list_data_items(request_type, transport: str = "grpc"): client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2159,15 +2596,12 @@ def test_list_data_items( assert response.next_page_token == "next_page_token_value" -def test_list_data_items_from_dict(): - test_list_data_items(request_type=dict) - - def test_list_data_items_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2183,7 +2617,8 @@ async def test_list_data_items_async( transport: str = "grpc_asyncio", request_type=dataset_service.ListDataItemsRequest ): client = DatasetServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2216,13 +2651,15 @@ async def test_list_data_items_async_from_dict(): def test_list_data_items_field_headers(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = dataset_service.ListDataItemsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_data_items), "__call__") as call: @@ -2236,7 +2673,10 @@ def test_list_data_items_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2249,7 +2689,7 @@ async def test_list_data_items_field_headers_async(): # a field header. Set these to a non-empty value. request = dataset_service.ListDataItemsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_data_items), "__call__") as call: @@ -2265,11 +2705,16 @@ async def test_list_data_items_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_data_items_flattened(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_data_items), "__call__") as call: @@ -2277,23 +2722,30 @@ def test_list_data_items_flattened(): call.return_value = dataset_service.ListDataItemsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_data_items(parent="parent_value",) + client.list_data_items( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_data_items_flattened_error(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.list_data_items( - dataset_service.ListDataItemsRequest(), parent="parent_value", + dataset_service.ListDataItemsRequest(), + parent="parent_value", ) @@ -2313,13 +2765,17 @@ async def test_list_data_items_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_data_items(parent="parent_value",) + response = await client.list_data_items( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -2332,12 +2788,16 @@ async def test_list_data_items_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.list_data_items( - dataset_service.ListDataItemsRequest(), parent="parent_value", + dataset_service.ListDataItemsRequest(), + parent="parent_value", ) -def test_list_data_items_pager(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_data_items_pager(transport_name: str = "grpc"): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_data_items), "__call__") as call: @@ -2352,13 +2812,20 @@ def test_list_data_items_pager(): next_page_token="abc", ), dataset_service.ListDataItemsResponse( - data_items=[], next_page_token="def", + data_items=[], + next_page_token="def", ), dataset_service.ListDataItemsResponse( - data_items=[data_item.DataItem(),], next_page_token="ghi", + data_items=[ + data_item.DataItem(), + ], + next_page_token="ghi", ), dataset_service.ListDataItemsResponse( - data_items=[data_item.DataItem(), data_item.DataItem(),], + data_items=[ + data_item.DataItem(), + data_item.DataItem(), + ], ), RuntimeError, ) @@ -2371,13 +2838,16 @@ def test_list_data_items_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all(isinstance(i, data_item.DataItem) for i in results) -def test_list_data_items_pages(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_data_items_pages(transport_name: str = "grpc"): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_data_items), "__call__") as call: @@ -2392,13 +2862,20 @@ def test_list_data_items_pages(): next_page_token="abc", ), dataset_service.ListDataItemsResponse( - data_items=[], next_page_token="def", + data_items=[], + next_page_token="def", ), dataset_service.ListDataItemsResponse( - data_items=[data_item.DataItem(),], next_page_token="ghi", + data_items=[ + data_item.DataItem(), + ], + next_page_token="ghi", ), dataset_service.ListDataItemsResponse( - data_items=[data_item.DataItem(), data_item.DataItem(),], + data_items=[ + data_item.DataItem(), + data_item.DataItem(), + ], ), RuntimeError, ) @@ -2409,7 +2886,9 @@ def test_list_data_items_pages(): @pytest.mark.asyncio async def test_list_data_items_async_pager(): - client = DatasetServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2426,20 +2905,29 @@ async def test_list_data_items_async_pager(): next_page_token="abc", ), dataset_service.ListDataItemsResponse( - data_items=[], next_page_token="def", + data_items=[], + next_page_token="def", ), dataset_service.ListDataItemsResponse( - data_items=[data_item.DataItem(),], next_page_token="ghi", + data_items=[ + data_item.DataItem(), + ], + next_page_token="ghi", ), dataset_service.ListDataItemsResponse( - data_items=[data_item.DataItem(), data_item.DataItem(),], + data_items=[ + data_item.DataItem(), + data_item.DataItem(), + ], ), RuntimeError, ) - async_pager = await client.list_data_items(request={},) + async_pager = await client.list_data_items( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -2448,7 +2936,9 @@ async def test_list_data_items_async_pager(): @pytest.mark.asyncio async def test_list_data_items_async_pages(): - client = DatasetServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2465,28 +2955,43 @@ async def test_list_data_items_async_pages(): next_page_token="abc", ), dataset_service.ListDataItemsResponse( - data_items=[], next_page_token="def", + data_items=[], + next_page_token="def", ), dataset_service.ListDataItemsResponse( - data_items=[data_item.DataItem(),], next_page_token="ghi", + data_items=[ + data_item.DataItem(), + ], + next_page_token="ghi", ), dataset_service.ListDataItemsResponse( - data_items=[data_item.DataItem(), data_item.DataItem(),], + data_items=[ + data_item.DataItem(), + data_item.DataItem(), + ], ), RuntimeError, ) pages = [] - async for page_ in (await client.list_data_items(request={})).pages: + async for page_ in ( + await client.list_data_items(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_get_annotation_spec( - transport: str = "grpc", request_type=dataset_service.GetAnnotationSpecRequest -): +@pytest.mark.parametrize( + "request_type", + [ + dataset_service.GetAnnotationSpecRequest, + dict, + ], +) +def test_get_annotation_spec(request_type, transport: str = "grpc"): client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2499,7 +3004,9 @@ def test_get_annotation_spec( ) as call: # Designate an appropriate return value for the call. call.return_value = annotation_spec.AnnotationSpec( - name="name_value", display_name="display_name_value", etag="etag_value", + name="name_value", + display_name="display_name_value", + etag="etag_value", ) response = client.get_annotation_spec(request) @@ -2515,15 +3022,12 @@ def test_get_annotation_spec( assert response.etag == "etag_value" -def test_get_annotation_spec_from_dict(): - test_get_annotation_spec(request_type=dict) - - def test_get_annotation_spec_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2542,7 +3046,8 @@ async def test_get_annotation_spec_async( request_type=dataset_service.GetAnnotationSpecRequest, ): client = DatasetServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2556,7 +3061,9 @@ async def test_get_annotation_spec_async( # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( annotation_spec.AnnotationSpec( - name="name_value", display_name="display_name_value", etag="etag_value", + name="name_value", + display_name="display_name_value", + etag="etag_value", ) ) response = await client.get_annotation_spec(request) @@ -2579,13 +3086,15 @@ async def test_get_annotation_spec_async_from_dict(): def test_get_annotation_spec_field_headers(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = dataset_service.GetAnnotationSpecRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2601,7 +3110,10 @@ def test_get_annotation_spec_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2614,7 +3126,7 @@ async def test_get_annotation_spec_field_headers_async(): # a field header. Set these to a non-empty value. request = dataset_service.GetAnnotationSpecRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2632,11 +3144,16 @@ async def test_get_annotation_spec_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_get_annotation_spec_flattened(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2646,23 +3163,30 @@ def test_get_annotation_spec_flattened(): call.return_value = annotation_spec.AnnotationSpec() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_annotation_spec(name="name_value",) + client.get_annotation_spec( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_annotation_spec_flattened_error(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.get_annotation_spec( - dataset_service.GetAnnotationSpecRequest(), name="name_value", + dataset_service.GetAnnotationSpecRequest(), + name="name_value", ) @@ -2684,13 +3208,17 @@ async def test_get_annotation_spec_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_annotation_spec(name="name_value",) + response = await client.get_annotation_spec( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -2703,15 +3231,22 @@ async def test_get_annotation_spec_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.get_annotation_spec( - dataset_service.GetAnnotationSpecRequest(), name="name_value", + dataset_service.GetAnnotationSpecRequest(), + name="name_value", ) -def test_list_annotations( - transport: str = "grpc", request_type=dataset_service.ListAnnotationsRequest -): +@pytest.mark.parametrize( + "request_type", + [ + dataset_service.ListAnnotationsRequest, + dict, + ], +) +def test_list_annotations(request_type, transport: str = "grpc"): client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2736,15 +3271,12 @@ def test_list_annotations( assert response.next_page_token == "next_page_token_value" -def test_list_annotations_from_dict(): - test_list_annotations(request_type=dict) - - def test_list_annotations_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2760,7 +3292,8 @@ async def test_list_annotations_async( transport: str = "grpc_asyncio", request_type=dataset_service.ListAnnotationsRequest ): client = DatasetServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2793,13 +3326,15 @@ async def test_list_annotations_async_from_dict(): def test_list_annotations_field_headers(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = dataset_service.ListAnnotationsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_annotations), "__call__") as call: @@ -2813,7 +3348,10 @@ def test_list_annotations_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2826,7 +3364,7 @@ async def test_list_annotations_field_headers_async(): # a field header. Set these to a non-empty value. request = dataset_service.ListAnnotationsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_annotations), "__call__") as call: @@ -2842,11 +3380,16 @@ async def test_list_annotations_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_annotations_flattened(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_annotations), "__call__") as call: @@ -2854,23 +3397,30 @@ def test_list_annotations_flattened(): call.return_value = dataset_service.ListAnnotationsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_annotations(parent="parent_value",) + client.list_annotations( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_annotations_flattened_error(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.list_annotations( - dataset_service.ListAnnotationsRequest(), parent="parent_value", + dataset_service.ListAnnotationsRequest(), + parent="parent_value", ) @@ -2890,13 +3440,17 @@ async def test_list_annotations_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_annotations(parent="parent_value",) + response = await client.list_annotations( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -2909,12 +3463,16 @@ async def test_list_annotations_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.list_annotations( - dataset_service.ListAnnotationsRequest(), parent="parent_value", + dataset_service.ListAnnotationsRequest(), + parent="parent_value", ) -def test_list_annotations_pager(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_annotations_pager(transport_name: str = "grpc"): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_annotations), "__call__") as call: @@ -2929,13 +3487,20 @@ def test_list_annotations_pager(): next_page_token="abc", ), dataset_service.ListAnnotationsResponse( - annotations=[], next_page_token="def", + annotations=[], + next_page_token="def", ), dataset_service.ListAnnotationsResponse( - annotations=[annotation.Annotation(),], next_page_token="ghi", + annotations=[ + annotation.Annotation(), + ], + next_page_token="ghi", ), dataset_service.ListAnnotationsResponse( - annotations=[annotation.Annotation(), annotation.Annotation(),], + annotations=[ + annotation.Annotation(), + annotation.Annotation(), + ], ), RuntimeError, ) @@ -2948,13 +3513,16 @@ def test_list_annotations_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all(isinstance(i, annotation.Annotation) for i in results) -def test_list_annotations_pages(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_annotations_pages(transport_name: str = "grpc"): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_annotations), "__call__") as call: @@ -2969,13 +3537,20 @@ def test_list_annotations_pages(): next_page_token="abc", ), dataset_service.ListAnnotationsResponse( - annotations=[], next_page_token="def", + annotations=[], + next_page_token="def", ), dataset_service.ListAnnotationsResponse( - annotations=[annotation.Annotation(),], next_page_token="ghi", + annotations=[ + annotation.Annotation(), + ], + next_page_token="ghi", ), dataset_service.ListAnnotationsResponse( - annotations=[annotation.Annotation(), annotation.Annotation(),], + annotations=[ + annotation.Annotation(), + annotation.Annotation(), + ], ), RuntimeError, ) @@ -2986,7 +3561,9 @@ def test_list_annotations_pages(): @pytest.mark.asyncio async def test_list_annotations_async_pager(): - client = DatasetServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3003,20 +3580,29 @@ async def test_list_annotations_async_pager(): next_page_token="abc", ), dataset_service.ListAnnotationsResponse( - annotations=[], next_page_token="def", + annotations=[], + next_page_token="def", ), dataset_service.ListAnnotationsResponse( - annotations=[annotation.Annotation(),], next_page_token="ghi", + annotations=[ + annotation.Annotation(), + ], + next_page_token="ghi", ), dataset_service.ListAnnotationsResponse( - annotations=[annotation.Annotation(), annotation.Annotation(),], + annotations=[ + annotation.Annotation(), + annotation.Annotation(), + ], ), RuntimeError, ) - async_pager = await client.list_annotations(request={},) + async_pager = await client.list_annotations( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -3025,7 +3611,9 @@ async def test_list_annotations_async_pager(): @pytest.mark.asyncio async def test_list_annotations_async_pages(): - client = DatasetServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3042,18 +3630,27 @@ async def test_list_annotations_async_pages(): next_page_token="abc", ), dataset_service.ListAnnotationsResponse( - annotations=[], next_page_token="def", + annotations=[], + next_page_token="def", ), dataset_service.ListAnnotationsResponse( - annotations=[annotation.Annotation(),], next_page_token="ghi", + annotations=[ + annotation.Annotation(), + ], + next_page_token="ghi", ), dataset_service.ListAnnotationsResponse( - annotations=[annotation.Annotation(), annotation.Annotation(),], + annotations=[ + annotation.Annotation(), + annotation.Annotation(), + ], ), RuntimeError, ) pages = [] - async for page_ in (await client.list_annotations(request={})).pages: + async for page_ in ( + await client.list_annotations(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token @@ -3066,7 +3663,8 @@ def test_credentials_transport_error(): ) with pytest.raises(ValueError): client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # It is an error to provide a credentials file and a transport instance. @@ -3079,13 +3677,34 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.DatasetServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = DatasetServiceClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = DatasetServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.DatasetServiceGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = DatasetServiceClient( - client_options={"scopes": ["1", "2"]}, transport=transport, + client_options={"scopes": ["1", "2"]}, + transport=transport, ) @@ -3128,10 +3747,28 @@ def test_transport_adc(transport_class): adc.assert_called_once() +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = DatasetServiceClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + def test_transport_grpc_default(): # A client should use the gRPC transport by default. - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) - assert isinstance(client.transport, transports.DatasetServiceGrpcTransport,) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.DatasetServiceGrpcTransport, + ) def test_dataset_service_base_transport_error(): @@ -3166,18 +3803,38 @@ def test_dataset_service_base_transport(): "list_data_items", "get_annotation_spec", "list_annotations", + "set_iam_policy", + "get_iam_policy", + "test_iam_permissions", + "get_location", + "list_locations", + "get_operation", + "wait_operation", + "cancel_operation", + "delete_operation", + "list_operations", ) for method in methods: with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + # Additionally, the LRO client (a property) should # also raise NotImplementedError with pytest.raises(NotImplementedError): transport.operations_client + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + -@requires_google_auth_gte_1_25_0 def test_dataset_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -3188,7 +3845,8 @@ def test_dataset_service_base_transport_with_credentials_file(): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DatasetServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", + credentials_file="credentials.json", + quota_project_id="octopus", ) load_creds.assert_called_once_with( "credentials.json", @@ -3198,26 +3856,6 @@ def test_dataset_service_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_dataset_service_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.aiplatform_v1.services.dataset_service.transports.DatasetServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.DatasetServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - def test_dataset_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( @@ -3229,7 +3867,6 @@ def test_dataset_service_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_dataset_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -3242,18 +3879,6 @@ def test_dataset_service_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_dataset_service_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - DatasetServiceClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -3261,7 +3886,6 @@ def test_dataset_service_auth_adc_old_google_auth(): transports.DatasetServiceGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_dataset_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -3275,26 +3899,6 @@ def test_dataset_service_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.DatasetServiceGrpcTransport, - transports.DatasetServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_dataset_service_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ @@ -3302,7 +3906,6 @@ def test_dataset_service_transport_auth_adc_old_google_auth(transport_class): (transports.DatasetServiceGrpcAsyncIOTransport, grpc_helpers_async), ], ) -@requires_api_core_gte_1_26_0 def test_dataset_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -3331,79 +3934,6 @@ def test_dataset_service_transport_create_channel(transport_class, grpc_helpers) ) -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.DatasetServiceGrpcTransport, grpc_helpers), - (transports.DatasetServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_dataset_service_transport_create_channel_old_api_core( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class(quota_project_id="octopus") - - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.DatasetServiceGrpcTransport, grpc_helpers), - (transports.DatasetServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_dataset_service_transport_create_channel_user_scopes( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=["1", "2"], - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -3426,7 +3956,7 @@ def test_dataset_service_grpc_transport_client_cert_source_for_mtls(transport_cl "squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_channel_creds, quota_project_id=None, options=[ @@ -3449,24 +3979,40 @@ def test_dataset_service_grpc_transport_client_cert_source_for_mtls(transport_cl ) -def test_dataset_service_host_no_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_dataset_service_host_no_port(transport_name): client = DatasetServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="aiplatform.googleapis.com" ), + transport=transport_name, ) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") -def test_dataset_service_host_with_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_dataset_service_host_with_port(transport_name): client = DatasetServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="aiplatform.googleapis.com:8000" ), + transport=transport_name, ) - assert client.transport._host == "aiplatform.googleapis.com:8000" + assert client.transport._host == ("aiplatform.googleapis.com:8000") def test_dataset_service_grpc_transport_channel(): @@ -3474,7 +4020,8 @@ def test_dataset_service_grpc_transport_channel(): # Check that channel is used if provided. transport = transports.DatasetServiceGrpcTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -3486,7 +4033,8 @@ def test_dataset_service_grpc_asyncio_transport_channel(): # Check that channel is used if provided. transport = transports.DatasetServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -3535,7 +4083,7 @@ def test_dataset_service_transport_channel_mtls_with_client_cert_source( "mtls.squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -3582,7 +4130,7 @@ def test_dataset_service_transport_channel_mtls_with_adc(transport_class): "mtls.squid.clam.whelk:443", credentials=mock_cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -3595,12 +4143,16 @@ def test_dataset_service_transport_channel_mtls_with_adc(transport_class): def test_dataset_service_grpc_lro_client(): client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -3608,12 +4160,16 @@ def test_dataset_service_grpc_lro_client(): def test_dataset_service_grpc_lro_async_client(): client = DatasetServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -3690,7 +4246,10 @@ def test_data_item_path(): dataset = "winkle" data_item = "nautilus" expected = "projects/{project}/locations/{location}/datasets/{dataset}/dataItems/{data_item}".format( - project=project, location=location, dataset=dataset, data_item=data_item, + project=project, + location=location, + dataset=dataset, + data_item=data_item, ) actual = DatasetServiceClient.data_item_path(project, location, dataset, data_item) assert expected == actual @@ -3715,7 +4274,9 @@ def test_dataset_path(): location = "octopus" dataset = "oyster" expected = "projects/{project}/locations/{location}/datasets/{dataset}".format( - project=project, location=location, dataset=dataset, + project=project, + location=location, + dataset=dataset, ) actual = DatasetServiceClient.dataset_path(project, location, dataset) assert expected == actual @@ -3756,7 +4317,9 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "scallop" - expected = "folders/{folder}".format(folder=folder,) + expected = "folders/{folder}".format( + folder=folder, + ) actual = DatasetServiceClient.common_folder_path(folder) assert expected == actual @@ -3774,7 +4337,9 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "squid" - expected = "organizations/{organization}".format(organization=organization,) + expected = "organizations/{organization}".format( + organization=organization, + ) actual = DatasetServiceClient.common_organization_path(organization) assert expected == actual @@ -3792,7 +4357,9 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "whelk" - expected = "projects/{project}".format(project=project,) + expected = "projects/{project}".format( + project=project, + ) actual = DatasetServiceClient.common_project_path(project) assert expected == actual @@ -3812,7 +4379,8 @@ def test_common_location_path(): project = "oyster" location = "nudibranch" expected = "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) actual = DatasetServiceClient.common_location_path(project, location) assert expected == actual @@ -3830,14 +4398,15 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( transports.DatasetServiceTransport, "_prep_wrapped_messages" ) as prep: client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -3846,6 +4415,1593 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = DatasetServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_delete_operation(transport: str = "grpc"): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_operation(transport: str = "grpc"): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_operation_field_headers(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = None + + client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_operation_field_headers_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_delete_operation_from_dict(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_delete_operation_from_dict_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_cancel_operation(transport: str = "grpc"): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation(transport: str = "grpc"): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_wait_operation(transport: str = "grpc"): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_wait_operation(transport: str = "grpc"): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_wait_operation_field_headers(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_wait_operation_field_headers_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_wait_operation_from_dict(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_wait_operation_from_dict_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_operation(transport: str = "grpc"): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_get_operation(transport: str = "grpc"): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_get_operation_field_headers(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_get_operation_from_dict(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_operations(transport: str = "grpc"): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + response = client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +@pytest.mark.asyncio +async def test_list_operations(transport: str = "grpc"): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +def test_list_operations_field_headers(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_operations_field_headers_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_operations_from_dict(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + response = client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_operations_from_dict_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_locations(transport: str = "grpc"): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + response = client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +@pytest.mark.asyncio +async def test_list_locations(transport: str = "grpc"): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +def test_list_locations_field_headers(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_locations_field_headers_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_locations_from_dict(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + response = client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_locations_from_dict_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_location(transport: str = "grpc"): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + response = client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +@pytest.mark.asyncio +async def test_get_location_async(transport: str = "grpc_asyncio"): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +def test_get_location_field_headers(): + client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials()) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = locations_pb2.Location() + + client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_location_field_headers_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials() + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +def test_get_location_from_dict(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + response = client.get_location( + request={ + "name": "locations/abc", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_location_from_dict_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_set_iam_policy(transport: str = "grpc"): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + response = client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + response = await client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_set_iam_policy_field_headers(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_set_iam_policy_field_headers_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_set_iam_policy_from_dict(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_set_iam_policy_from_dict_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +def test_get_iam_policy(transport: str = "grpc"): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + + response = client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + + response = await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_get_iam_policy_field_headers(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_iam_policy_field_headers_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_get_iam_policy_from_dict(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_iam_policy_from_dict_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +def test_test_iam_permissions(transport: str = "grpc"): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + + response = client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + ) + + response = await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +def test_test_iam_permissions_field_headers(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_field_headers_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_test_iam_permissions_from_dict(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + response = client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_from_dict_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + response = await client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (DatasetServiceClient, transports.DatasetServiceGrpcTransport), + (DatasetServiceAsyncClient, transports.DatasetServiceGrpcAsyncIOTransport), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) diff --git a/tests/unit/gapic/aiplatform_v1/test_endpoint_service.py b/tests/unit/gapic/aiplatform_v1/test_endpoint_service.py index 707ddf6fc0..a4fd3aca00 100644 --- a/tests/unit/gapic/aiplatform_v1/test_endpoint_service.py +++ b/tests/unit/gapic/aiplatform_v1/test_endpoint_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,8 +14,13 @@ # limitations under the License. # import os -import mock -import packaging.version + +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock +except ImportError: + import mock import grpc from grpc.experimental import aio @@ -30,8 +35,10 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.aiplatform_v1.services.endpoint_service import ( @@ -40,49 +47,28 @@ from google.cloud.aiplatform_v1.services.endpoint_service import EndpointServiceClient from google.cloud.aiplatform_v1.services.endpoint_service import pagers from google.cloud.aiplatform_v1.services.endpoint_service import transports -from google.cloud.aiplatform_v1.services.endpoint_service.transports.base import ( - _API_CORE_VERSION, -) -from google.cloud.aiplatform_v1.services.endpoint_service.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.aiplatform_v1.types import accelerator_type from google.cloud.aiplatform_v1.types import encryption_spec from google.cloud.aiplatform_v1.types import endpoint from google.cloud.aiplatform_v1.types import endpoint as gca_endpoint from google.cloud.aiplatform_v1.types import endpoint_service +from google.cloud.aiplatform_v1.types import explanation +from google.cloud.aiplatform_v1.types import explanation_metadata +from google.cloud.aiplatform_v1.types import io from google.cloud.aiplatform_v1.types import machine_resources from google.cloud.aiplatform_v1.types import operation as gca_operation +from google.cloud.location import locations_pb2 +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 from google.oauth2 import service_account from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import struct_pb2 # type: ignore from google.protobuf import timestamp_pb2 # type: ignore import google.auth -# TODO(busunkim): Once google-api-core >= 1.26.0 is required: -# - Delete all the api-core and auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - -requires_api_core_lt_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), - reason="This test requires google-api-core < 1.26.0", -) - -requires_api_core_gte_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), - reason="This test requires google-api-core >= 1.26.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -128,40 +114,81 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( - "client_class", [EndpointServiceClient, EndpointServiceAsyncClient,] + "client_class,transport_name", + [ + (EndpointServiceClient, "grpc"), + (EndpointServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_endpoint_service_client_from_service_account_info(client_class): +def test_endpoint_service_client_from_service_account_info( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.EndpointServiceGrpcTransport, "grpc"), + (transports.EndpointServiceGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_endpoint_service_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() @pytest.mark.parametrize( - "client_class", [EndpointServiceClient, EndpointServiceAsyncClient,] + "client_class,transport_name", + [ + (EndpointServiceClient, "grpc"), + (EndpointServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_endpoint_service_client_from_service_account_file(client_class): +def test_endpoint_service_client_from_service_account_file( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") def test_endpoint_service_client_get_transport_class(): @@ -214,7 +241,7 @@ def test_endpoint_service_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -223,6 +250,7 @@ def test_endpoint_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -230,7 +258,7 @@ def test_endpoint_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -239,6 +267,7 @@ def test_endpoint_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -246,7 +275,7 @@ def test_endpoint_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -255,26 +284,27 @@ def test_endpoint_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -283,6 +313,7 @@ def test_endpoint_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -342,7 +373,7 @@ def test_endpoint_service_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -359,6 +390,7 @@ def test_endpoint_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case ADC client cert is provided. Whether client cert is used depends on @@ -383,7 +415,7 @@ def test_endpoint_service_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -392,6 +424,7 @@ def test_endpoint_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case client_cert_source and ADC client cert are not provided. @@ -404,7 +437,7 @@ def test_endpoint_service_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -413,9 +446,91 @@ def test_endpoint_service_client_mtls_env_auto( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) +@pytest.mark.parametrize( + "client_class", [EndpointServiceClient, EndpointServiceAsyncClient] +) +@mock.patch.object( + EndpointServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(EndpointServiceClient), +) +@mock.patch.object( + EndpointServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(EndpointServiceAsyncClient), +) +def test_endpoint_service_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + @pytest.mark.parametrize( "client_class,transport_class,transport_name", [ @@ -431,10 +546,12 @@ def test_endpoint_service_client_client_options_scopes( client_class, transport_class, transport_name ): # Check the case scopes are provided. - options = client_options.ClientOptions(scopes=["1", "2"],) + options = client_options.ClientOptions( + scopes=["1", "2"], + ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -443,28 +560,36 @@ def test_endpoint_service_client_client_options_scopes( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (EndpointServiceClient, transports.EndpointServiceGrpcTransport, "grpc"), + ( + EndpointServiceClient, + transports.EndpointServiceGrpcTransport, + "grpc", + grpc_helpers, + ), ( EndpointServiceAsyncClient, transports.EndpointServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_endpoint_service_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -473,6 +598,7 @@ def test_endpoint_service_client_client_options_credentials_file( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -492,14 +618,87 @@ def test_endpoint_service_client_client_options_from_dict(): client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) -def test_create_endpoint( - transport: str = "grpc", request_type=endpoint_service.CreateEndpointRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + EndpointServiceClient, + transports.EndpointServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + EndpointServiceAsyncClient, + transports.EndpointServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_endpoint_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers ): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + endpoint_service.CreateEndpointRequest, + dict, + ], +) +def test_create_endpoint(request_type, transport: str = "grpc"): client = EndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -521,15 +720,12 @@ def test_create_endpoint( assert isinstance(response, future.Future) -def test_create_endpoint_from_dict(): - test_create_endpoint(request_type=dict) - - def test_create_endpoint_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -545,7 +741,8 @@ async def test_create_endpoint_async( transport: str = "grpc_asyncio", request_type=endpoint_service.CreateEndpointRequest ): client = EndpointServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -575,13 +772,15 @@ async def test_create_endpoint_async_from_dict(): def test_create_endpoint_field_headers(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = endpoint_service.CreateEndpointRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_endpoint), "__call__") as call: @@ -595,7 +794,10 @@ def test_create_endpoint_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -608,7 +810,7 @@ async def test_create_endpoint_field_headers_async(): # a field header. Set these to a non-empty value. request = endpoint_service.CreateEndpointRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_endpoint), "__call__") as call: @@ -624,11 +826,16 @@ async def test_create_endpoint_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_create_endpoint_flattened(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_endpoint), "__call__") as call: @@ -637,19 +844,30 @@ def test_create_endpoint_flattened(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.create_endpoint( - parent="parent_value", endpoint=gca_endpoint.Endpoint(name="name_value"), + parent="parent_value", + endpoint=gca_endpoint.Endpoint(name="name_value"), + endpoint_id="endpoint_id_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].endpoint == gca_endpoint.Endpoint(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].endpoint + mock_val = gca_endpoint.Endpoint(name="name_value") + assert arg == mock_val + arg = args[0].endpoint_id + mock_val = "endpoint_id_value" + assert arg == mock_val def test_create_endpoint_flattened_error(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -658,6 +876,7 @@ def test_create_endpoint_flattened_error(): endpoint_service.CreateEndpointRequest(), parent="parent_value", endpoint=gca_endpoint.Endpoint(name="name_value"), + endpoint_id="endpoint_id_value", ) @@ -678,15 +897,24 @@ async def test_create_endpoint_flattened_async(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. response = await client.create_endpoint( - parent="parent_value", endpoint=gca_endpoint.Endpoint(name="name_value"), + parent="parent_value", + endpoint=gca_endpoint.Endpoint(name="name_value"), + endpoint_id="endpoint_id_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].endpoint == gca_endpoint.Endpoint(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].endpoint + mock_val = gca_endpoint.Endpoint(name="name_value") + assert arg == mock_val + arg = args[0].endpoint_id + mock_val = "endpoint_id_value" + assert arg == mock_val @pytest.mark.asyncio @@ -702,14 +930,21 @@ async def test_create_endpoint_flattened_error_async(): endpoint_service.CreateEndpointRequest(), parent="parent_value", endpoint=gca_endpoint.Endpoint(name="name_value"), + endpoint_id="endpoint_id_value", ) -def test_get_endpoint( - transport: str = "grpc", request_type=endpoint_service.GetEndpointRequest -): +@pytest.mark.parametrize( + "request_type", + [ + endpoint_service.GetEndpointRequest, + dict, + ], +) +def test_get_endpoint(request_type, transport: str = "grpc"): client = EndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -724,6 +959,9 @@ def test_get_endpoint( display_name="display_name_value", description="description_value", etag="etag_value", + network="network_value", + enable_private_service_connect=True, + model_deployment_monitoring_job="model_deployment_monitoring_job_value", ) response = client.get_endpoint(request) @@ -738,17 +976,20 @@ def test_get_endpoint( assert response.display_name == "display_name_value" assert response.description == "description_value" assert response.etag == "etag_value" - - -def test_get_endpoint_from_dict(): - test_get_endpoint(request_type=dict) + assert response.network == "network_value" + assert response.enable_private_service_connect is True + assert ( + response.model_deployment_monitoring_job + == "model_deployment_monitoring_job_value" + ) def test_get_endpoint_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -764,7 +1005,8 @@ async def test_get_endpoint_async( transport: str = "grpc_asyncio", request_type=endpoint_service.GetEndpointRequest ): client = EndpointServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -780,6 +1022,9 @@ async def test_get_endpoint_async( display_name="display_name_value", description="description_value", etag="etag_value", + network="network_value", + enable_private_service_connect=True, + model_deployment_monitoring_job="model_deployment_monitoring_job_value", ) ) response = await client.get_endpoint(request) @@ -795,6 +1040,12 @@ async def test_get_endpoint_async( assert response.display_name == "display_name_value" assert response.description == "description_value" assert response.etag == "etag_value" + assert response.network == "network_value" + assert response.enable_private_service_connect is True + assert ( + response.model_deployment_monitoring_job + == "model_deployment_monitoring_job_value" + ) @pytest.mark.asyncio @@ -803,13 +1054,15 @@ async def test_get_endpoint_async_from_dict(): def test_get_endpoint_field_headers(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = endpoint_service.GetEndpointRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_endpoint), "__call__") as call: @@ -823,7 +1076,10 @@ def test_get_endpoint_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -836,7 +1092,7 @@ async def test_get_endpoint_field_headers_async(): # a field header. Set these to a non-empty value. request = endpoint_service.GetEndpointRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_endpoint), "__call__") as call: @@ -850,11 +1106,16 @@ async def test_get_endpoint_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_get_endpoint_flattened(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_endpoint), "__call__") as call: @@ -862,23 +1123,30 @@ def test_get_endpoint_flattened(): call.return_value = endpoint.Endpoint() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_endpoint(name="name_value",) + client.get_endpoint( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_endpoint_flattened_error(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.get_endpoint( - endpoint_service.GetEndpointRequest(), name="name_value", + endpoint_service.GetEndpointRequest(), + name="name_value", ) @@ -896,13 +1164,17 @@ async def test_get_endpoint_flattened_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(endpoint.Endpoint()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_endpoint(name="name_value",) + response = await client.get_endpoint( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -915,15 +1187,22 @@ async def test_get_endpoint_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.get_endpoint( - endpoint_service.GetEndpointRequest(), name="name_value", + endpoint_service.GetEndpointRequest(), + name="name_value", ) -def test_list_endpoints( - transport: str = "grpc", request_type=endpoint_service.ListEndpointsRequest -): +@pytest.mark.parametrize( + "request_type", + [ + endpoint_service.ListEndpointsRequest, + dict, + ], +) +def test_list_endpoints(request_type, transport: str = "grpc"): client = EndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -948,15 +1227,12 @@ def test_list_endpoints( assert response.next_page_token == "next_page_token_value" -def test_list_endpoints_from_dict(): - test_list_endpoints(request_type=dict) - - def test_list_endpoints_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -972,7 +1248,8 @@ async def test_list_endpoints_async( transport: str = "grpc_asyncio", request_type=endpoint_service.ListEndpointsRequest ): client = EndpointServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1005,13 +1282,15 @@ async def test_list_endpoints_async_from_dict(): def test_list_endpoints_field_headers(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = endpoint_service.ListEndpointsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_endpoints), "__call__") as call: @@ -1025,7 +1304,10 @@ def test_list_endpoints_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1038,7 +1320,7 @@ async def test_list_endpoints_field_headers_async(): # a field header. Set these to a non-empty value. request = endpoint_service.ListEndpointsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_endpoints), "__call__") as call: @@ -1054,11 +1336,16 @@ async def test_list_endpoints_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_endpoints_flattened(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_endpoints), "__call__") as call: @@ -1066,23 +1353,30 @@ def test_list_endpoints_flattened(): call.return_value = endpoint_service.ListEndpointsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_endpoints(parent="parent_value",) + client.list_endpoints( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_endpoints_flattened_error(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.list_endpoints( - endpoint_service.ListEndpointsRequest(), parent="parent_value", + endpoint_service.ListEndpointsRequest(), + parent="parent_value", ) @@ -1102,13 +1396,17 @@ async def test_list_endpoints_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_endpoints(parent="parent_value",) + response = await client.list_endpoints( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1121,12 +1419,16 @@ async def test_list_endpoints_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.list_endpoints( - endpoint_service.ListEndpointsRequest(), parent="parent_value", + endpoint_service.ListEndpointsRequest(), + parent="parent_value", ) -def test_list_endpoints_pager(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_endpoints_pager(transport_name: str = "grpc"): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_endpoints), "__call__") as call: @@ -1141,13 +1443,20 @@ def test_list_endpoints_pager(): next_page_token="abc", ), endpoint_service.ListEndpointsResponse( - endpoints=[], next_page_token="def", + endpoints=[], + next_page_token="def", ), endpoint_service.ListEndpointsResponse( - endpoints=[endpoint.Endpoint(),], next_page_token="ghi", + endpoints=[ + endpoint.Endpoint(), + ], + next_page_token="ghi", ), endpoint_service.ListEndpointsResponse( - endpoints=[endpoint.Endpoint(), endpoint.Endpoint(),], + endpoints=[ + endpoint.Endpoint(), + endpoint.Endpoint(), + ], ), RuntimeError, ) @@ -1160,13 +1469,16 @@ def test_list_endpoints_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all(isinstance(i, endpoint.Endpoint) for i in results) -def test_list_endpoints_pages(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_endpoints_pages(transport_name: str = "grpc"): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_endpoints), "__call__") as call: @@ -1181,13 +1493,20 @@ def test_list_endpoints_pages(): next_page_token="abc", ), endpoint_service.ListEndpointsResponse( - endpoints=[], next_page_token="def", + endpoints=[], + next_page_token="def", ), endpoint_service.ListEndpointsResponse( - endpoints=[endpoint.Endpoint(),], next_page_token="ghi", + endpoints=[ + endpoint.Endpoint(), + ], + next_page_token="ghi", ), endpoint_service.ListEndpointsResponse( - endpoints=[endpoint.Endpoint(), endpoint.Endpoint(),], + endpoints=[ + endpoint.Endpoint(), + endpoint.Endpoint(), + ], ), RuntimeError, ) @@ -1217,20 +1536,29 @@ async def test_list_endpoints_async_pager(): next_page_token="abc", ), endpoint_service.ListEndpointsResponse( - endpoints=[], next_page_token="def", + endpoints=[], + next_page_token="def", ), endpoint_service.ListEndpointsResponse( - endpoints=[endpoint.Endpoint(),], next_page_token="ghi", + endpoints=[ + endpoint.Endpoint(), + ], + next_page_token="ghi", ), endpoint_service.ListEndpointsResponse( - endpoints=[endpoint.Endpoint(), endpoint.Endpoint(),], + endpoints=[ + endpoint.Endpoint(), + endpoint.Endpoint(), + ], ), RuntimeError, ) - async_pager = await client.list_endpoints(request={},) + async_pager = await client.list_endpoints( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -1258,28 +1586,43 @@ async def test_list_endpoints_async_pages(): next_page_token="abc", ), endpoint_service.ListEndpointsResponse( - endpoints=[], next_page_token="def", + endpoints=[], + next_page_token="def", ), endpoint_service.ListEndpointsResponse( - endpoints=[endpoint.Endpoint(),], next_page_token="ghi", + endpoints=[ + endpoint.Endpoint(), + ], + next_page_token="ghi", ), endpoint_service.ListEndpointsResponse( - endpoints=[endpoint.Endpoint(), endpoint.Endpoint(),], + endpoints=[ + endpoint.Endpoint(), + endpoint.Endpoint(), + ], ), RuntimeError, ) pages = [] - async for page_ in (await client.list_endpoints(request={})).pages: + async for page_ in ( + await client.list_endpoints(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_update_endpoint( - transport: str = "grpc", request_type=endpoint_service.UpdateEndpointRequest -): +@pytest.mark.parametrize( + "request_type", + [ + endpoint_service.UpdateEndpointRequest, + dict, + ], +) +def test_update_endpoint(request_type, transport: str = "grpc"): client = EndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1294,6 +1637,9 @@ def test_update_endpoint( display_name="display_name_value", description="description_value", etag="etag_value", + network="network_value", + enable_private_service_connect=True, + model_deployment_monitoring_job="model_deployment_monitoring_job_value", ) response = client.update_endpoint(request) @@ -1308,17 +1654,20 @@ def test_update_endpoint( assert response.display_name == "display_name_value" assert response.description == "description_value" assert response.etag == "etag_value" - - -def test_update_endpoint_from_dict(): - test_update_endpoint(request_type=dict) + assert response.network == "network_value" + assert response.enable_private_service_connect is True + assert ( + response.model_deployment_monitoring_job + == "model_deployment_monitoring_job_value" + ) def test_update_endpoint_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1334,7 +1683,8 @@ async def test_update_endpoint_async( transport: str = "grpc_asyncio", request_type=endpoint_service.UpdateEndpointRequest ): client = EndpointServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1350,6 +1700,9 @@ async def test_update_endpoint_async( display_name="display_name_value", description="description_value", etag="etag_value", + network="network_value", + enable_private_service_connect=True, + model_deployment_monitoring_job="model_deployment_monitoring_job_value", ) ) response = await client.update_endpoint(request) @@ -1365,6 +1718,12 @@ async def test_update_endpoint_async( assert response.display_name == "display_name_value" assert response.description == "description_value" assert response.etag == "etag_value" + assert response.network == "network_value" + assert response.enable_private_service_connect is True + assert ( + response.model_deployment_monitoring_job + == "model_deployment_monitoring_job_value" + ) @pytest.mark.asyncio @@ -1373,13 +1732,15 @@ async def test_update_endpoint_async_from_dict(): def test_update_endpoint_field_headers(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = endpoint_service.UpdateEndpointRequest() - request.endpoint.name = "endpoint.name/value" + request.endpoint.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_endpoint), "__call__") as call: @@ -1393,9 +1754,10 @@ def test_update_endpoint_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "endpoint.name=endpoint.name/value",) in kw[ - "metadata" - ] + assert ( + "x-goog-request-params", + "endpoint.name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1408,7 +1770,7 @@ async def test_update_endpoint_field_headers_async(): # a field header. Set these to a non-empty value. request = endpoint_service.UpdateEndpointRequest() - request.endpoint.name = "endpoint.name/value" + request.endpoint.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_endpoint), "__call__") as call: @@ -1424,13 +1786,16 @@ async def test_update_endpoint_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "endpoint.name=endpoint.name/value",) in kw[ - "metadata" - ] + assert ( + "x-goog-request-params", + "endpoint.name=name_value", + ) in kw["metadata"] def test_update_endpoint_flattened(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_endpoint), "__call__") as call: @@ -1447,12 +1812,18 @@ def test_update_endpoint_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].endpoint == gca_endpoint.Endpoint(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].endpoint + mock_val = gca_endpoint.Endpoint(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val def test_update_endpoint_flattened_error(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1489,8 +1860,12 @@ async def test_update_endpoint_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].endpoint == gca_endpoint.Endpoint(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].endpoint + mock_val = gca_endpoint.Endpoint(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val @pytest.mark.asyncio @@ -1509,11 +1884,17 @@ async def test_update_endpoint_flattened_error_async(): ) -def test_delete_endpoint( - transport: str = "grpc", request_type=endpoint_service.DeleteEndpointRequest -): +@pytest.mark.parametrize( + "request_type", + [ + endpoint_service.DeleteEndpointRequest, + dict, + ], +) +def test_delete_endpoint(request_type, transport: str = "grpc"): client = EndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1535,15 +1916,12 @@ def test_delete_endpoint( assert isinstance(response, future.Future) -def test_delete_endpoint_from_dict(): - test_delete_endpoint(request_type=dict) - - def test_delete_endpoint_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1559,7 +1937,8 @@ async def test_delete_endpoint_async( transport: str = "grpc_asyncio", request_type=endpoint_service.DeleteEndpointRequest ): client = EndpointServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1589,13 +1968,15 @@ async def test_delete_endpoint_async_from_dict(): def test_delete_endpoint_field_headers(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = endpoint_service.DeleteEndpointRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_endpoint), "__call__") as call: @@ -1609,7 +1990,10 @@ def test_delete_endpoint_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1622,7 +2006,7 @@ async def test_delete_endpoint_field_headers_async(): # a field header. Set these to a non-empty value. request = endpoint_service.DeleteEndpointRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_endpoint), "__call__") as call: @@ -1638,11 +2022,16 @@ async def test_delete_endpoint_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_delete_endpoint_flattened(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_endpoint), "__call__") as call: @@ -1650,23 +2039,30 @@ def test_delete_endpoint_flattened(): call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_endpoint(name="name_value",) + client.delete_endpoint( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_delete_endpoint_flattened_error(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.delete_endpoint( - endpoint_service.DeleteEndpointRequest(), name="name_value", + endpoint_service.DeleteEndpointRequest(), + name="name_value", ) @@ -1686,13 +2082,17 @@ async def test_delete_endpoint_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_endpoint(name="name_value",) + response = await client.delete_endpoint( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1705,15 +2105,22 @@ async def test_delete_endpoint_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.delete_endpoint( - endpoint_service.DeleteEndpointRequest(), name="name_value", + endpoint_service.DeleteEndpointRequest(), + name="name_value", ) -def test_deploy_model( - transport: str = "grpc", request_type=endpoint_service.DeployModelRequest -): +@pytest.mark.parametrize( + "request_type", + [ + endpoint_service.DeployModelRequest, + dict, + ], +) +def test_deploy_model(request_type, transport: str = "grpc"): client = EndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1735,15 +2142,12 @@ def test_deploy_model( assert isinstance(response, future.Future) -def test_deploy_model_from_dict(): - test_deploy_model(request_type=dict) - - def test_deploy_model_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1759,7 +2163,8 @@ async def test_deploy_model_async( transport: str = "grpc_asyncio", request_type=endpoint_service.DeployModelRequest ): client = EndpointServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1789,13 +2194,15 @@ async def test_deploy_model_async_from_dict(): def test_deploy_model_field_headers(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = endpoint_service.DeployModelRequest() - request.endpoint = "endpoint/value" + request.endpoint = "endpoint_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.deploy_model), "__call__") as call: @@ -1809,7 +2216,10 @@ def test_deploy_model_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "endpoint=endpoint/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "endpoint=endpoint_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1822,7 +2232,7 @@ async def test_deploy_model_field_headers_async(): # a field header. Set these to a non-empty value. request = endpoint_service.DeployModelRequest() - request.endpoint = "endpoint/value" + request.endpoint = "endpoint_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.deploy_model), "__call__") as call: @@ -1838,11 +2248,16 @@ async def test_deploy_model_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "endpoint=endpoint/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "endpoint=endpoint_value", + ) in kw["metadata"] def test_deploy_model_flattened(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.deploy_model), "__call__") as call: @@ -1866,19 +2281,27 @@ def test_deploy_model_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].endpoint == "endpoint_value" - assert args[0].deployed_model == gca_endpoint.DeployedModel( + arg = args[0].endpoint + mock_val = "endpoint_value" + assert arg == mock_val + arg = args[0].deployed_model + mock_val = gca_endpoint.DeployedModel( dedicated_resources=machine_resources.DedicatedResources( machine_spec=machine_resources.MachineSpec( machine_type="machine_type_value" ) ) ) - assert args[0].traffic_split == {"key_value": 541} + assert arg == mock_val + arg = args[0].traffic_split + mock_val = {"key_value": 541} + assert arg == mock_val def test_deploy_model_flattened_error(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1929,15 +2352,21 @@ async def test_deploy_model_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].endpoint == "endpoint_value" - assert args[0].deployed_model == gca_endpoint.DeployedModel( + arg = args[0].endpoint + mock_val = "endpoint_value" + assert arg == mock_val + arg = args[0].deployed_model + mock_val = gca_endpoint.DeployedModel( dedicated_resources=machine_resources.DedicatedResources( machine_spec=machine_resources.MachineSpec( machine_type="machine_type_value" ) ) ) - assert args[0].traffic_split == {"key_value": 541} + assert arg == mock_val + arg = args[0].traffic_split + mock_val = {"key_value": 541} + assert arg == mock_val @pytest.mark.asyncio @@ -1963,11 +2392,17 @@ async def test_deploy_model_flattened_error_async(): ) -def test_undeploy_model( - transport: str = "grpc", request_type=endpoint_service.UndeployModelRequest -): +@pytest.mark.parametrize( + "request_type", + [ + endpoint_service.UndeployModelRequest, + dict, + ], +) +def test_undeploy_model(request_type, transport: str = "grpc"): client = EndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1989,15 +2424,12 @@ def test_undeploy_model( assert isinstance(response, future.Future) -def test_undeploy_model_from_dict(): - test_undeploy_model(request_type=dict) - - def test_undeploy_model_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2013,7 +2445,8 @@ async def test_undeploy_model_async( transport: str = "grpc_asyncio", request_type=endpoint_service.UndeployModelRequest ): client = EndpointServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2043,13 +2476,15 @@ async def test_undeploy_model_async_from_dict(): def test_undeploy_model_field_headers(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = endpoint_service.UndeployModelRequest() - request.endpoint = "endpoint/value" + request.endpoint = "endpoint_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.undeploy_model), "__call__") as call: @@ -2063,7 +2498,10 @@ def test_undeploy_model_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "endpoint=endpoint/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "endpoint=endpoint_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2076,7 +2514,7 @@ async def test_undeploy_model_field_headers_async(): # a field header. Set these to a non-empty value. request = endpoint_service.UndeployModelRequest() - request.endpoint = "endpoint/value" + request.endpoint = "endpoint_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.undeploy_model), "__call__") as call: @@ -2092,11 +2530,16 @@ async def test_undeploy_model_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "endpoint=endpoint/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "endpoint=endpoint_value", + ) in kw["metadata"] def test_undeploy_model_flattened(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.undeploy_model), "__call__") as call: @@ -2114,13 +2557,21 @@ def test_undeploy_model_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].endpoint == "endpoint_value" - assert args[0].deployed_model_id == "deployed_model_id_value" - assert args[0].traffic_split == {"key_value": 541} + arg = args[0].endpoint + mock_val = "endpoint_value" + assert arg == mock_val + arg = args[0].deployed_model_id + mock_val = "deployed_model_id_value" + assert arg == mock_val + arg = args[0].traffic_split + mock_val = {"key_value": 541} + assert arg == mock_val def test_undeploy_model_flattened_error(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2159,9 +2610,15 @@ async def test_undeploy_model_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].endpoint == "endpoint_value" - assert args[0].deployed_model_id == "deployed_model_id_value" - assert args[0].traffic_split == {"key_value": 541} + arg = args[0].endpoint + mock_val = "endpoint_value" + assert arg == mock_val + arg = args[0].deployed_model_id + mock_val = "deployed_model_id_value" + assert arg == mock_val + arg = args[0].traffic_split + mock_val = {"key_value": 541} + assert arg == mock_val @pytest.mark.asyncio @@ -2188,7 +2645,8 @@ def test_credentials_transport_error(): ) with pytest.raises(ValueError): client = EndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # It is an error to provide a credentials file and a transport instance. @@ -2201,13 +2659,34 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.EndpointServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = EndpointServiceClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = EndpointServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.EndpointServiceGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = EndpointServiceClient( - client_options={"scopes": ["1", "2"]}, transport=transport, + client_options={"scopes": ["1", "2"]}, + transport=transport, ) @@ -2250,10 +2729,28 @@ def test_transport_adc(transport_class): adc.assert_called_once() +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = EndpointServiceClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + def test_transport_grpc_default(): # A client should use the gRPC transport by default. - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) - assert isinstance(client.transport, transports.EndpointServiceGrpcTransport,) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.EndpointServiceGrpcTransport, + ) def test_endpoint_service_base_transport_error(): @@ -2285,18 +2782,38 @@ def test_endpoint_service_base_transport(): "delete_endpoint", "deploy_model", "undeploy_model", + "set_iam_policy", + "get_iam_policy", + "test_iam_permissions", + "get_location", + "list_locations", + "get_operation", + "wait_operation", + "cancel_operation", + "delete_operation", + "list_operations", ) for method in methods: with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + # Additionally, the LRO client (a property) should # also raise NotImplementedError with pytest.raises(NotImplementedError): transport.operations_client + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + -@requires_google_auth_gte_1_25_0 def test_endpoint_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -2307,7 +2824,8 @@ def test_endpoint_service_base_transport_with_credentials_file(): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EndpointServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", + credentials_file="credentials.json", + quota_project_id="octopus", ) load_creds.assert_called_once_with( "credentials.json", @@ -2317,26 +2835,6 @@ def test_endpoint_service_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_endpoint_service_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.aiplatform_v1.services.endpoint_service.transports.EndpointServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.EndpointServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - def test_endpoint_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( @@ -2348,7 +2846,6 @@ def test_endpoint_service_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_endpoint_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -2361,18 +2858,6 @@ def test_endpoint_service_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_endpoint_service_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - EndpointServiceClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -2380,7 +2865,6 @@ def test_endpoint_service_auth_adc_old_google_auth(): transports.EndpointServiceGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_endpoint_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -2394,26 +2878,6 @@ def test_endpoint_service_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.EndpointServiceGrpcTransport, - transports.EndpointServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_endpoint_service_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ @@ -2421,7 +2885,6 @@ def test_endpoint_service_transport_auth_adc_old_google_auth(transport_class): (transports.EndpointServiceGrpcAsyncIOTransport, grpc_helpers_async), ], ) -@requires_api_core_gte_1_26_0 def test_endpoint_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -2450,79 +2913,6 @@ def test_endpoint_service_transport_create_channel(transport_class, grpc_helpers ) -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.EndpointServiceGrpcTransport, grpc_helpers), - (transports.EndpointServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_endpoint_service_transport_create_channel_old_api_core( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class(quota_project_id="octopus") - - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.EndpointServiceGrpcTransport, grpc_helpers), - (transports.EndpointServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_endpoint_service_transport_create_channel_user_scopes( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=["1", "2"], - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -2545,7 +2935,7 @@ def test_endpoint_service_grpc_transport_client_cert_source_for_mtls(transport_c "squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_channel_creds, quota_project_id=None, options=[ @@ -2568,24 +2958,40 @@ def test_endpoint_service_grpc_transport_client_cert_source_for_mtls(transport_c ) -def test_endpoint_service_host_no_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_endpoint_service_host_no_port(transport_name): client = EndpointServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="aiplatform.googleapis.com" ), + transport=transport_name, ) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") -def test_endpoint_service_host_with_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_endpoint_service_host_with_port(transport_name): client = EndpointServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="aiplatform.googleapis.com:8000" ), + transport=transport_name, ) - assert client.transport._host == "aiplatform.googleapis.com:8000" + assert client.transport._host == ("aiplatform.googleapis.com:8000") def test_endpoint_service_grpc_transport_channel(): @@ -2593,7 +2999,8 @@ def test_endpoint_service_grpc_transport_channel(): # Check that channel is used if provided. transport = transports.EndpointServiceGrpcTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -2605,7 +3012,8 @@ def test_endpoint_service_grpc_asyncio_transport_channel(): # Check that channel is used if provided. transport = transports.EndpointServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -2654,7 +3062,7 @@ def test_endpoint_service_transport_channel_mtls_with_client_cert_source( "mtls.squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -2701,7 +3109,7 @@ def test_endpoint_service_transport_channel_mtls_with_adc(transport_class): "mtls.squid.clam.whelk:443", credentials=mock_cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -2714,12 +3122,16 @@ def test_endpoint_service_transport_channel_mtls_with_adc(transport_class): def test_endpoint_service_grpc_lro_client(): client = EndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -2727,12 +3139,16 @@ def test_endpoint_service_grpc_lro_client(): def test_endpoint_service_grpc_lro_async_client(): client = EndpointServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -2743,7 +3159,9 @@ def test_endpoint_path(): location = "clam" endpoint = "whelk" expected = "projects/{project}/locations/{location}/endpoints/{endpoint}".format( - project=project, location=location, endpoint=endpoint, + project=project, + location=location, + endpoint=endpoint, ) actual = EndpointServiceClient.endpoint_path(project, location, endpoint) assert expected == actual @@ -2767,7 +3185,9 @@ def test_model_path(): location = "mussel" model = "winkle" expected = "projects/{project}/locations/{location}/models/{model}".format( - project=project, location=location, model=model, + project=project, + location=location, + model=model, ) actual = EndpointServiceClient.model_path(project, location, model) assert expected == actual @@ -2786,54 +3206,109 @@ def test_parse_model_path(): assert expected == actual -def test_common_billing_account_path(): - billing_account = "squid" - expected = "billingAccounts/{billing_account}".format( - billing_account=billing_account, +def test_model_deployment_monitoring_job_path(): + project = "squid" + location = "clam" + model_deployment_monitoring_job = "whelk" + expected = "projects/{project}/locations/{location}/modelDeploymentMonitoringJobs/{model_deployment_monitoring_job}".format( + project=project, + location=location, + model_deployment_monitoring_job=model_deployment_monitoring_job, + ) + actual = EndpointServiceClient.model_deployment_monitoring_job_path( + project, location, model_deployment_monitoring_job ) - actual = EndpointServiceClient.common_billing_account_path(billing_account) assert expected == actual -def test_parse_common_billing_account_path(): +def test_parse_model_deployment_monitoring_job_path(): expected = { - "billing_account": "clam", + "project": "octopus", + "location": "oyster", + "model_deployment_monitoring_job": "nudibranch", } - path = EndpointServiceClient.common_billing_account_path(**expected) + path = EndpointServiceClient.model_deployment_monitoring_job_path(**expected) # Check that the path construction is reversible. - actual = EndpointServiceClient.parse_common_billing_account_path(path) + actual = EndpointServiceClient.parse_model_deployment_monitoring_job_path(path) assert expected == actual -def test_common_folder_path(): - folder = "whelk" - expected = "folders/{folder}".format(folder=folder,) - actual = EndpointServiceClient.common_folder_path(folder) +def test_network_path(): + project = "cuttlefish" + network = "mussel" + expected = "projects/{project}/global/networks/{network}".format( + project=project, + network=network, + ) + actual = EndpointServiceClient.network_path(project, network) assert expected == actual -def test_parse_common_folder_path(): +def test_parse_network_path(): expected = { - "folder": "octopus", + "project": "winkle", + "network": "nautilus", } - path = EndpointServiceClient.common_folder_path(**expected) + path = EndpointServiceClient.network_path(**expected) # Check that the path construction is reversible. - actual = EndpointServiceClient.parse_common_folder_path(path) + actual = EndpointServiceClient.parse_network_path(path) assert expected == actual -def test_common_organization_path(): - organization = "oyster" - expected = "organizations/{organization}".format(organization=organization,) - actual = EndpointServiceClient.common_organization_path(organization) +def test_common_billing_account_path(): + billing_account = "scallop" + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + actual = EndpointServiceClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "abalone", + } + path = EndpointServiceClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = EndpointServiceClient.parse_common_billing_account_path(path) + assert expected == actual + + +def test_common_folder_path(): + folder = "squid" + expected = "folders/{folder}".format( + folder=folder, + ) + actual = EndpointServiceClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "clam", + } + path = EndpointServiceClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = EndpointServiceClient.parse_common_folder_path(path) + assert expected == actual + + +def test_common_organization_path(): + organization = "whelk" + expected = "organizations/{organization}".format( + organization=organization, + ) + actual = EndpointServiceClient.common_organization_path(organization) assert expected == actual def test_parse_common_organization_path(): expected = { - "organization": "nudibranch", + "organization": "octopus", } path = EndpointServiceClient.common_organization_path(**expected) @@ -2843,15 +3318,17 @@ def test_parse_common_organization_path(): def test_common_project_path(): - project = "cuttlefish" - expected = "projects/{project}".format(project=project,) + project = "oyster" + expected = "projects/{project}".format( + project=project, + ) actual = EndpointServiceClient.common_project_path(project) assert expected == actual def test_parse_common_project_path(): expected = { - "project": "mussel", + "project": "nudibranch", } path = EndpointServiceClient.common_project_path(**expected) @@ -2861,10 +3338,11 @@ def test_parse_common_project_path(): def test_common_location_path(): - project = "winkle" - location = "nautilus" + project = "cuttlefish" + location = "mussel" expected = "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) actual = EndpointServiceClient.common_location_path(project, location) assert expected == actual @@ -2872,8 +3350,8 @@ def test_common_location_path(): def test_parse_common_location_path(): expected = { - "project": "scallop", - "location": "abalone", + "project": "winkle", + "location": "nautilus", } path = EndpointServiceClient.common_location_path(**expected) @@ -2882,14 +3360,15 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( transports.EndpointServiceTransport, "_prep_wrapped_messages" ) as prep: client = EndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2898,6 +3377,1593 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = EndpointServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_delete_operation(transport: str = "grpc"): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_operation(transport: str = "grpc"): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_operation_field_headers(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = None + + client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_operation_field_headers_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_delete_operation_from_dict(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_delete_operation_from_dict_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_cancel_operation(transport: str = "grpc"): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation(transport: str = "grpc"): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_wait_operation(transport: str = "grpc"): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_wait_operation(transport: str = "grpc"): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_wait_operation_field_headers(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_wait_operation_field_headers_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_wait_operation_from_dict(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_wait_operation_from_dict_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_operation(transport: str = "grpc"): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_get_operation(transport: str = "grpc"): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_get_operation_field_headers(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_get_operation_from_dict(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_operations(transport: str = "grpc"): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + response = client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +@pytest.mark.asyncio +async def test_list_operations(transport: str = "grpc"): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +def test_list_operations_field_headers(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_operations_field_headers_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_operations_from_dict(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + response = client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_operations_from_dict_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_locations(transport: str = "grpc"): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + response = client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +@pytest.mark.asyncio +async def test_list_locations(transport: str = "grpc"): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +def test_list_locations_field_headers(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_locations_field_headers_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_locations_from_dict(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + response = client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_locations_from_dict_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_location(transport: str = "grpc"): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + response = client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +@pytest.mark.asyncio +async def test_get_location_async(transport: str = "grpc_asyncio"): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +def test_get_location_field_headers(): + client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials()) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = locations_pb2.Location() + + client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_location_field_headers_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials() + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +def test_get_location_from_dict(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + response = client.get_location( + request={ + "name": "locations/abc", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_location_from_dict_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_set_iam_policy(transport: str = "grpc"): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + response = client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + response = await client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_set_iam_policy_field_headers(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_set_iam_policy_field_headers_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_set_iam_policy_from_dict(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_set_iam_policy_from_dict_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +def test_get_iam_policy(transport: str = "grpc"): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + + response = client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + + response = await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_get_iam_policy_field_headers(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_iam_policy_field_headers_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_get_iam_policy_from_dict(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_iam_policy_from_dict_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +def test_test_iam_permissions(transport: str = "grpc"): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + + response = client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + ) + + response = await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +def test_test_iam_permissions_field_headers(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_field_headers_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_test_iam_permissions_from_dict(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + response = client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_from_dict_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + response = await client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (EndpointServiceClient, transports.EndpointServiceGrpcTransport), + (EndpointServiceAsyncClient, transports.EndpointServiceGrpcAsyncIOTransport), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) diff --git a/tests/unit/gapic/aiplatform_v1/test_featurestore_online_serving_service.py b/tests/unit/gapic/aiplatform_v1/test_featurestore_online_serving_service.py new file mode 100644 index 0000000000..ec92ba080b --- /dev/null +++ b/tests/unit/gapic/aiplatform_v1/test_featurestore_online_serving_service.py @@ -0,0 +1,3450 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import os + +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock +except ImportError: + import mock + +import grpc +from grpc.experimental import aio +import math +import pytest +from proto.marshal.rules.dates import DurationRule, TimestampRule + + +from google.api_core import client_options +from google.api_core import exceptions as core_exceptions +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers +from google.api_core import grpc_helpers_async +from google.api_core import path_template +from google.auth import credentials as ga_credentials +from google.auth.exceptions import MutualTLSChannelError +from google.cloud.aiplatform_v1.services.featurestore_online_serving_service import ( + FeaturestoreOnlineServingServiceAsyncClient, +) +from google.cloud.aiplatform_v1.services.featurestore_online_serving_service import ( + FeaturestoreOnlineServingServiceClient, +) +from google.cloud.aiplatform_v1.services.featurestore_online_serving_service import ( + transports, +) +from google.cloud.aiplatform_v1.types import feature_selector +from google.cloud.aiplatform_v1.types import featurestore_online_service +from google.cloud.location import locations_pb2 +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.oauth2 import service_account +import google.auth + + +def client_cert_source_callback(): + return b"cert bytes", b"key bytes" + + +# If default endpoint is localhost, then default mtls endpoint will be the same. +# This method modifies the default endpoint so the client can produce a different +# mtls endpoint for endpoint testing purposes. +def modify_default_endpoint(client): + return ( + "foo.googleapis.com" + if ("localhost" in client.DEFAULT_ENDPOINT) + else client.DEFAULT_ENDPOINT + ) + + +def test__get_default_mtls_endpoint(): + api_endpoint = "example.googleapis.com" + api_mtls_endpoint = "example.mtls.googleapis.com" + sandbox_endpoint = "example.sandbox.googleapis.com" + sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" + non_googleapi = "api.example.com" + + assert ( + FeaturestoreOnlineServingServiceClient._get_default_mtls_endpoint(None) is None + ) + assert ( + FeaturestoreOnlineServingServiceClient._get_default_mtls_endpoint(api_endpoint) + == api_mtls_endpoint + ) + assert ( + FeaturestoreOnlineServingServiceClient._get_default_mtls_endpoint( + api_mtls_endpoint + ) + == api_mtls_endpoint + ) + assert ( + FeaturestoreOnlineServingServiceClient._get_default_mtls_endpoint( + sandbox_endpoint + ) + == sandbox_mtls_endpoint + ) + assert ( + FeaturestoreOnlineServingServiceClient._get_default_mtls_endpoint( + sandbox_mtls_endpoint + ) + == sandbox_mtls_endpoint + ) + assert ( + FeaturestoreOnlineServingServiceClient._get_default_mtls_endpoint(non_googleapi) + == non_googleapi + ) + + +@pytest.mark.parametrize( + "client_class,transport_name", + [ + (FeaturestoreOnlineServingServiceClient, "grpc"), + (FeaturestoreOnlineServingServiceAsyncClient, "grpc_asyncio"), + ], +) +def test_featurestore_online_serving_service_client_from_service_account_info( + client_class, transport_name +): + creds = ga_credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_info" + ) as factory: + factory.return_value = creds + info = {"valid": True} + client = client_class.from_service_account_info(info, transport=transport_name) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.FeaturestoreOnlineServingServiceGrpcTransport, "grpc"), + ( + transports.FeaturestoreOnlineServingServiceGrpcAsyncIOTransport, + "grpc_asyncio", + ), + ], +) +def test_featurestore_online_serving_service_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + +@pytest.mark.parametrize( + "client_class,transport_name", + [ + (FeaturestoreOnlineServingServiceClient, "grpc"), + (FeaturestoreOnlineServingServiceAsyncClient, "grpc_asyncio"), + ], +) +def test_featurestore_online_serving_service_client_from_service_account_file( + client_class, transport_name +): + creds = ga_credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_file" + ) as factory: + factory.return_value = creds + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +def test_featurestore_online_serving_service_client_get_transport_class(): + transport = FeaturestoreOnlineServingServiceClient.get_transport_class() + available_transports = [ + transports.FeaturestoreOnlineServingServiceGrpcTransport, + ] + assert transport in available_transports + + transport = FeaturestoreOnlineServingServiceClient.get_transport_class("grpc") + assert transport == transports.FeaturestoreOnlineServingServiceGrpcTransport + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + ( + FeaturestoreOnlineServingServiceClient, + transports.FeaturestoreOnlineServingServiceGrpcTransport, + "grpc", + ), + ( + FeaturestoreOnlineServingServiceAsyncClient, + transports.FeaturestoreOnlineServingServiceGrpcAsyncIOTransport, + "grpc_asyncio", + ), + ], +) +@mock.patch.object( + FeaturestoreOnlineServingServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(FeaturestoreOnlineServingServiceClient), +) +@mock.patch.object( + FeaturestoreOnlineServingServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(FeaturestoreOnlineServingServiceAsyncClient), +) +def test_featurestore_online_serving_service_client_client_options( + client_class, transport_class, transport_name +): + # Check that if channel is provided we won't create a new one. + with mock.patch.object( + FeaturestoreOnlineServingServiceClient, "get_transport_class" + ) as gtc: + transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + client = client_class(transport=transport) + gtc.assert_not_called() + + # Check that if channel is provided via str we will create a new one. + with mock.patch.object( + FeaturestoreOnlineServingServiceClient, "get_transport_class" + ) as gtc: + client = client_class(transport=transport_name) + gtc.assert_called() + + # Check the case api_endpoint is provided. + options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(transport=transport_name, client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is + # "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is + # "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_MTLS_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has + # unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError): + client = client_class(transport=transport_name) + + # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError): + client = client_class(transport=transport_name) + + # Check the case quota_project_id is provided + options = client_options.ClientOptions(quota_project_id="octopus") + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id="octopus", + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,use_client_cert_env", + [ + ( + FeaturestoreOnlineServingServiceClient, + transports.FeaturestoreOnlineServingServiceGrpcTransport, + "grpc", + "true", + ), + ( + FeaturestoreOnlineServingServiceAsyncClient, + transports.FeaturestoreOnlineServingServiceGrpcAsyncIOTransport, + "grpc_asyncio", + "true", + ), + ( + FeaturestoreOnlineServingServiceClient, + transports.FeaturestoreOnlineServingServiceGrpcTransport, + "grpc", + "false", + ), + ( + FeaturestoreOnlineServingServiceAsyncClient, + transports.FeaturestoreOnlineServingServiceGrpcAsyncIOTransport, + "grpc_asyncio", + "false", + ), + ], +) +@mock.patch.object( + FeaturestoreOnlineServingServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(FeaturestoreOnlineServingServiceClient), +) +@mock.patch.object( + FeaturestoreOnlineServingServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(FeaturestoreOnlineServingServiceAsyncClient), +) +@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) +def test_featurestore_online_serving_service_client_mtls_env_auto( + client_class, transport_class, transport_name, use_client_cert_env +): + # This tests the endpoint autoswitch behavior. Endpoint is autoswitched to the default + # mtls endpoint, if GOOGLE_API_USE_CLIENT_CERTIFICATE is "true" and client cert exists. + + # Check the case client_cert_source is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + options = client_options.ClientOptions( + client_cert_source=client_cert_source_callback + ) + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client.DEFAULT_ENDPOINT + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT + + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # Check the case ADC client cert is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=client_cert_source_callback, + ): + if use_client_cert_env == "false": + expected_host = client.DEFAULT_ENDPOINT + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback + + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + +@pytest.mark.parametrize( + "client_class", + [ + FeaturestoreOnlineServingServiceClient, + FeaturestoreOnlineServingServiceAsyncClient, + ], +) +@mock.patch.object( + FeaturestoreOnlineServingServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(FeaturestoreOnlineServingServiceClient), +) +@mock.patch.object( + FeaturestoreOnlineServingServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(FeaturestoreOnlineServingServiceAsyncClient), +) +def test_featurestore_online_serving_service_client_get_mtls_endpoint_and_cert_source( + client_class, +): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + ( + FeaturestoreOnlineServingServiceClient, + transports.FeaturestoreOnlineServingServiceGrpcTransport, + "grpc", + ), + ( + FeaturestoreOnlineServingServiceAsyncClient, + transports.FeaturestoreOnlineServingServiceGrpcAsyncIOTransport, + "grpc_asyncio", + ), + ], +) +def test_featurestore_online_serving_service_client_client_options_scopes( + client_class, transport_class, transport_name +): + # Check the case scopes are provided. + options = client_options.ClientOptions( + scopes=["1", "2"], + ) + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=["1", "2"], + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + FeaturestoreOnlineServingServiceClient, + transports.FeaturestoreOnlineServingServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + FeaturestoreOnlineServingServiceAsyncClient, + transports.FeaturestoreOnlineServingServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_featurestore_online_serving_service_client_client_options_credentials_file( + client_class, transport_class, transport_name, grpc_helpers +): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + +def test_featurestore_online_serving_service_client_client_options_from_dict(): + with mock.patch( + "google.cloud.aiplatform_v1.services.featurestore_online_serving_service.transports.FeaturestoreOnlineServingServiceGrpcTransport.__init__" + ) as grpc_transport: + grpc_transport.return_value = None + client = FeaturestoreOnlineServingServiceClient( + client_options={"api_endpoint": "squid.clam.whelk"} + ) + grpc_transport.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + FeaturestoreOnlineServingServiceClient, + transports.FeaturestoreOnlineServingServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + FeaturestoreOnlineServingServiceAsyncClient, + transports.FeaturestoreOnlineServingServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_featurestore_online_serving_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers +): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + featurestore_online_service.ReadFeatureValuesRequest, + dict, + ], +) +def test_read_feature_values(request_type, transport: str = "grpc"): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.read_feature_values), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = featurestore_online_service.ReadFeatureValuesResponse() + response = client.read_feature_values(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_online_service.ReadFeatureValuesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, featurestore_online_service.ReadFeatureValuesResponse) + + +def test_read_feature_values_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.read_feature_values), "__call__" + ) as call: + client.read_feature_values() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_online_service.ReadFeatureValuesRequest() + + +@pytest.mark.asyncio +async def test_read_feature_values_async( + transport: str = "grpc_asyncio", + request_type=featurestore_online_service.ReadFeatureValuesRequest, +): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.read_feature_values), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + featurestore_online_service.ReadFeatureValuesResponse() + ) + response = await client.read_feature_values(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_online_service.ReadFeatureValuesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, featurestore_online_service.ReadFeatureValuesResponse) + + +@pytest.mark.asyncio +async def test_read_feature_values_async_from_dict(): + await test_read_feature_values_async(request_type=dict) + + +def test_read_feature_values_field_headers(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_online_service.ReadFeatureValuesRequest() + + request.entity_type = "entity_type_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.read_feature_values), "__call__" + ) as call: + call.return_value = featurestore_online_service.ReadFeatureValuesResponse() + client.read_feature_values(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "entity_type=entity_type_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_read_feature_values_field_headers_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_online_service.ReadFeatureValuesRequest() + + request.entity_type = "entity_type_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.read_feature_values), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + featurestore_online_service.ReadFeatureValuesResponse() + ) + await client.read_feature_values(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "entity_type=entity_type_value", + ) in kw["metadata"] + + +def test_read_feature_values_flattened(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.read_feature_values), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = featurestore_online_service.ReadFeatureValuesResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.read_feature_values( + entity_type="entity_type_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].entity_type + mock_val = "entity_type_value" + assert arg == mock_val + + +def test_read_feature_values_flattened_error(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.read_feature_values( + featurestore_online_service.ReadFeatureValuesRequest(), + entity_type="entity_type_value", + ) + + +@pytest.mark.asyncio +async def test_read_feature_values_flattened_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.read_feature_values), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = featurestore_online_service.ReadFeatureValuesResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + featurestore_online_service.ReadFeatureValuesResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.read_feature_values( + entity_type="entity_type_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].entity_type + mock_val = "entity_type_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_read_feature_values_flattened_error_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.read_feature_values( + featurestore_online_service.ReadFeatureValuesRequest(), + entity_type="entity_type_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + featurestore_online_service.StreamingReadFeatureValuesRequest, + dict, + ], +) +def test_streaming_read_feature_values(request_type, transport: str = "grpc"): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.streaming_read_feature_values), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iter( + [featurestore_online_service.ReadFeatureValuesResponse()] + ) + response = client.streaming_read_feature_values(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert ( + args[0] == featurestore_online_service.StreamingReadFeatureValuesRequest() + ) + + # Establish that the response is the type that we expect. + for message in response: + assert isinstance( + message, featurestore_online_service.ReadFeatureValuesResponse + ) + + +def test_streaming_read_feature_values_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.streaming_read_feature_values), "__call__" + ) as call: + client.streaming_read_feature_values() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert ( + args[0] == featurestore_online_service.StreamingReadFeatureValuesRequest() + ) + + +@pytest.mark.asyncio +async def test_streaming_read_feature_values_async( + transport: str = "grpc_asyncio", + request_type=featurestore_online_service.StreamingReadFeatureValuesRequest, +): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.streaming_read_feature_values), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = mock.Mock(aio.UnaryStreamCall, autospec=True) + call.return_value.read = mock.AsyncMock( + side_effect=[featurestore_online_service.ReadFeatureValuesResponse()] + ) + response = await client.streaming_read_feature_values(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert ( + args[0] == featurestore_online_service.StreamingReadFeatureValuesRequest() + ) + + # Establish that the response is the type that we expect. + message = await response.read() + assert isinstance(message, featurestore_online_service.ReadFeatureValuesResponse) + + +@pytest.mark.asyncio +async def test_streaming_read_feature_values_async_from_dict(): + await test_streaming_read_feature_values_async(request_type=dict) + + +def test_streaming_read_feature_values_field_headers(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_online_service.StreamingReadFeatureValuesRequest() + + request.entity_type = "entity_type_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.streaming_read_feature_values), "__call__" + ) as call: + call.return_value = iter( + [featurestore_online_service.ReadFeatureValuesResponse()] + ) + client.streaming_read_feature_values(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "entity_type=entity_type_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_streaming_read_feature_values_field_headers_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_online_service.StreamingReadFeatureValuesRequest() + + request.entity_type = "entity_type_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.streaming_read_feature_values), "__call__" + ) as call: + call.return_value = mock.Mock(aio.UnaryStreamCall, autospec=True) + call.return_value.read = mock.AsyncMock( + side_effect=[featurestore_online_service.ReadFeatureValuesResponse()] + ) + await client.streaming_read_feature_values(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "entity_type=entity_type_value", + ) in kw["metadata"] + + +def test_streaming_read_feature_values_flattened(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.streaming_read_feature_values), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iter( + [featurestore_online_service.ReadFeatureValuesResponse()] + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.streaming_read_feature_values( + entity_type="entity_type_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].entity_type + mock_val = "entity_type_value" + assert arg == mock_val + + +def test_streaming_read_feature_values_flattened_error(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.streaming_read_feature_values( + featurestore_online_service.StreamingReadFeatureValuesRequest(), + entity_type="entity_type_value", + ) + + +@pytest.mark.asyncio +async def test_streaming_read_feature_values_flattened_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.streaming_read_feature_values), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iter( + [featurestore_online_service.ReadFeatureValuesResponse()] + ) + + call.return_value = mock.Mock(aio.UnaryStreamCall, autospec=True) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.streaming_read_feature_values( + entity_type="entity_type_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].entity_type + mock_val = "entity_type_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_streaming_read_feature_values_flattened_error_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.streaming_read_feature_values( + featurestore_online_service.StreamingReadFeatureValuesRequest(), + entity_type="entity_type_value", + ) + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.FeaturestoreOnlineServingServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.FeaturestoreOnlineServingServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = FeaturestoreOnlineServingServiceClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide an api_key and a transport instance. + transport = transports.FeaturestoreOnlineServingServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = FeaturestoreOnlineServingServiceClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = FeaturestoreOnlineServingServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.FeaturestoreOnlineServingServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = FeaturestoreOnlineServingServiceClient( + client_options={"scopes": ["1", "2"]}, + transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.FeaturestoreOnlineServingServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + client = FeaturestoreOnlineServingServiceClient(transport=transport) + assert client.transport is transport + + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.FeaturestoreOnlineServingServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.FeaturestoreOnlineServingServiceGrpcAsyncIOTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.FeaturestoreOnlineServingServiceGrpcTransport, + transports.FeaturestoreOnlineServingServiceGrpcAsyncIOTransport, + ], +) +def test_transport_adc(transport_class): + # Test default credentials are used if not provided. + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class() + adc.assert_called_once() + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = FeaturestoreOnlineServingServiceClient.get_transport_class( + transport_name + )( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + +def test_transport_grpc_default(): + # A client should use the gRPC transport by default. + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.FeaturestoreOnlineServingServiceGrpcTransport, + ) + + +def test_featurestore_online_serving_service_base_transport_error(): + # Passing both a credentials object and credentials_file should raise an error + with pytest.raises(core_exceptions.DuplicateCredentialArgs): + transport = transports.FeaturestoreOnlineServingServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + credentials_file="credentials.json", + ) + + +def test_featurestore_online_serving_service_base_transport(): + # Instantiate the base transport. + with mock.patch( + "google.cloud.aiplatform_v1.services.featurestore_online_serving_service.transports.FeaturestoreOnlineServingServiceTransport.__init__" + ) as Transport: + Transport.return_value = None + transport = transports.FeaturestoreOnlineServingServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Every method on the transport should just blindly + # raise NotImplementedError. + methods = ( + "read_feature_values", + "streaming_read_feature_values", + "set_iam_policy", + "get_iam_policy", + "test_iam_permissions", + "get_location", + "list_locations", + "get_operation", + "wait_operation", + "cancel_operation", + "delete_operation", + "list_operations", + ) + for method in methods: + with pytest.raises(NotImplementedError): + getattr(transport, method)(request=object()) + + with pytest.raises(NotImplementedError): + transport.close() + + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + + +def test_featurestore_online_serving_service_base_transport_with_credentials_file(): + # Instantiate the base transport with a credentials file + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch( + "google.cloud.aiplatform_v1.services.featurestore_online_serving_service.transports.FeaturestoreOnlineServingServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.FeaturestoreOnlineServingServiceTransport( + credentials_file="credentials.json", + quota_project_id="octopus", + ) + load_creds.assert_called_once_with( + "credentials.json", + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +def test_featurestore_online_serving_service_base_transport_with_adc(): + # Test the default credentials are used if credentials and credentials_file are None. + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( + "google.cloud.aiplatform_v1.services.featurestore_online_serving_service.transports.FeaturestoreOnlineServingServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.FeaturestoreOnlineServingServiceTransport() + adc.assert_called_once() + + +def test_featurestore_online_serving_service_auth_adc(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + FeaturestoreOnlineServingServiceClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id=None, + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.FeaturestoreOnlineServingServiceGrpcTransport, + transports.FeaturestoreOnlineServingServiceGrpcAsyncIOTransport, + ], +) +def test_featurestore_online_serving_service_transport_auth_adc(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.FeaturestoreOnlineServingServiceGrpcTransport, grpc_helpers), + ( + transports.FeaturestoreOnlineServingServiceGrpcAsyncIOTransport, + grpc_helpers_async, + ), + ], +) +def test_featurestore_online_serving_service_transport_create_channel( + transport_class, grpc_helpers +): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=["1", "2"], + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.FeaturestoreOnlineServingServiceGrpcTransport, + transports.FeaturestoreOnlineServingServiceGrpcAsyncIOTransport, + ], +) +def test_featurestore_online_serving_service_grpc_transport_client_cert_source_for_mtls( + transport_class, +): + cred = ga_credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds, + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback, + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, private_key=expected_key + ) + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_featurestore_online_serving_service_host_no_port(transport_name): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions( + api_endpoint="aiplatform.googleapis.com" + ), + transport=transport_name, + ) + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_featurestore_online_serving_service_host_with_port(transport_name): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions( + api_endpoint="aiplatform.googleapis.com:8000" + ), + transport=transport_name, + ) + assert client.transport._host == ("aiplatform.googleapis.com:8000") + + +def test_featurestore_online_serving_service_grpc_transport_channel(): + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.FeaturestoreOnlineServingServiceGrpcTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +def test_featurestore_online_serving_service_grpc_asyncio_transport_channel(): + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.FeaturestoreOnlineServingServiceGrpcAsyncIOTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize( + "transport_class", + [ + transports.FeaturestoreOnlineServingServiceGrpcTransport, + transports.FeaturestoreOnlineServingServiceGrpcAsyncIOTransport, + ], +) +def test_featurestore_online_serving_service_transport_channel_mtls_with_client_cert_source( + transport_class, +): + with mock.patch( + "grpc.ssl_channel_credentials", autospec=True + ) as grpc_ssl_channel_cred: + with mock.patch.object( + transport_class, "create_channel" + ) as grpc_create_channel: + mock_ssl_cred = mock.Mock() + grpc_ssl_channel_cred.return_value = mock_ssl_cred + + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + + cred = ga_credentials.AnonymousCredentials() + with pytest.warns(DeprecationWarning): + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (cred, None) + transport = transport_class( + host="squid.clam.whelk", + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=client_cert_source_callback, + ) + adc.assert_called_once() + + grpc_ssl_channel_cred.assert_called_once_with( + certificate_chain=b"cert bytes", private_key=b"key bytes" + ) + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize( + "transport_class", + [ + transports.FeaturestoreOnlineServingServiceGrpcTransport, + transports.FeaturestoreOnlineServingServiceGrpcAsyncIOTransport, + ], +) +def test_featurestore_online_serving_service_transport_channel_mtls_with_adc( + transport_class, +): + mock_ssl_cred = mock.Mock() + with mock.patch.multiple( + "google.auth.transport.grpc.SslCredentials", + __init__=mock.Mock(return_value=None), + ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), + ): + with mock.patch.object( + transport_class, "create_channel" + ) as grpc_create_channel: + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + mock_cred = mock.Mock() + + with pytest.warns(DeprecationWarning): + transport = transport_class( + host="squid.clam.whelk", + credentials=mock_cred, + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=None, + ) + + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=mock_cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + + +def test_entity_type_path(): + project = "squid" + location = "clam" + featurestore = "whelk" + entity_type = "octopus" + expected = "projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}".format( + project=project, + location=location, + featurestore=featurestore, + entity_type=entity_type, + ) + actual = FeaturestoreOnlineServingServiceClient.entity_type_path( + project, location, featurestore, entity_type + ) + assert expected == actual + + +def test_parse_entity_type_path(): + expected = { + "project": "oyster", + "location": "nudibranch", + "featurestore": "cuttlefish", + "entity_type": "mussel", + } + path = FeaturestoreOnlineServingServiceClient.entity_type_path(**expected) + + # Check that the path construction is reversible. + actual = FeaturestoreOnlineServingServiceClient.parse_entity_type_path(path) + assert expected == actual + + +def test_common_billing_account_path(): + billing_account = "winkle" + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + actual = FeaturestoreOnlineServingServiceClient.common_billing_account_path( + billing_account + ) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "nautilus", + } + path = FeaturestoreOnlineServingServiceClient.common_billing_account_path( + **expected + ) + + # Check that the path construction is reversible. + actual = FeaturestoreOnlineServingServiceClient.parse_common_billing_account_path( + path + ) + assert expected == actual + + +def test_common_folder_path(): + folder = "scallop" + expected = "folders/{folder}".format( + folder=folder, + ) + actual = FeaturestoreOnlineServingServiceClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "abalone", + } + path = FeaturestoreOnlineServingServiceClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = FeaturestoreOnlineServingServiceClient.parse_common_folder_path(path) + assert expected == actual + + +def test_common_organization_path(): + organization = "squid" + expected = "organizations/{organization}".format( + organization=organization, + ) + actual = FeaturestoreOnlineServingServiceClient.common_organization_path( + organization + ) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "clam", + } + path = FeaturestoreOnlineServingServiceClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = FeaturestoreOnlineServingServiceClient.parse_common_organization_path(path) + assert expected == actual + + +def test_common_project_path(): + project = "whelk" + expected = "projects/{project}".format( + project=project, + ) + actual = FeaturestoreOnlineServingServiceClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "octopus", + } + path = FeaturestoreOnlineServingServiceClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = FeaturestoreOnlineServingServiceClient.parse_common_project_path(path) + assert expected == actual + + +def test_common_location_path(): + project = "oyster" + location = "nudibranch" + expected = "projects/{project}/locations/{location}".format( + project=project, + location=location, + ) + actual = FeaturestoreOnlineServingServiceClient.common_location_path( + project, location + ) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "cuttlefish", + "location": "mussel", + } + path = FeaturestoreOnlineServingServiceClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = FeaturestoreOnlineServingServiceClient.parse_common_location_path(path) + assert expected == actual + + +def test_client_with_default_client_info(): + client_info = gapic_v1.client_info.ClientInfo() + + with mock.patch.object( + transports.FeaturestoreOnlineServingServiceTransport, "_prep_wrapped_messages" + ) as prep: + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + with mock.patch.object( + transports.FeaturestoreOnlineServingServiceTransport, "_prep_wrapped_messages" + ) as prep: + transport_class = FeaturestoreOnlineServingServiceClient.get_transport_class() + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_delete_operation(transport: str = "grpc"): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_operation(transport: str = "grpc"): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_operation_field_headers(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = None + + client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_operation_field_headers_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_delete_operation_from_dict(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_delete_operation_from_dict_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_cancel_operation(transport: str = "grpc"): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation(transport: str = "grpc"): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_wait_operation(transport: str = "grpc"): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_wait_operation(transport: str = "grpc"): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_wait_operation_field_headers(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_wait_operation_field_headers_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_wait_operation_from_dict(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_wait_operation_from_dict_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_operation(transport: str = "grpc"): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_get_operation(transport: str = "grpc"): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_get_operation_field_headers(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_get_operation_from_dict(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_operations(transport: str = "grpc"): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + response = client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +@pytest.mark.asyncio +async def test_list_operations(transport: str = "grpc"): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +def test_list_operations_field_headers(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_operations_field_headers_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_operations_from_dict(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + response = client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_operations_from_dict_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_locations(transport: str = "grpc"): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + response = client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +@pytest.mark.asyncio +async def test_list_locations(transport: str = "grpc"): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +def test_list_locations_field_headers(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_locations_field_headers_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_locations_from_dict(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + response = client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_locations_from_dict_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_location(transport: str = "grpc"): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + response = client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +@pytest.mark.asyncio +async def test_get_location_async(transport: str = "grpc_asyncio"): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +def test_get_location_field_headers(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials() + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = locations_pb2.Location() + + client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_location_field_headers_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials() + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +def test_get_location_from_dict(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + response = client.get_location( + request={ + "name": "locations/abc", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_location_from_dict_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_set_iam_policy(transport: str = "grpc"): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + response = client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + response = await client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_set_iam_policy_field_headers(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_set_iam_policy_field_headers_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_set_iam_policy_from_dict(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_set_iam_policy_from_dict_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +def test_get_iam_policy(transport: str = "grpc"): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + + response = client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + + response = await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_get_iam_policy_field_headers(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_iam_policy_field_headers_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_get_iam_policy_from_dict(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_iam_policy_from_dict_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +def test_test_iam_permissions(transport: str = "grpc"): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + + response = client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + ) + + response = await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +def test_test_iam_permissions_field_headers(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_field_headers_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_test_iam_permissions_from_dict(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + response = client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_from_dict_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + response = await client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + ( + FeaturestoreOnlineServingServiceClient, + transports.FeaturestoreOnlineServingServiceGrpcTransport, + ), + ( + FeaturestoreOnlineServingServiceAsyncClient, + transports.FeaturestoreOnlineServingServiceGrpcAsyncIOTransport, + ), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) diff --git a/tests/unit/gapic/aiplatform_v1/test_featurestore_service.py b/tests/unit/gapic/aiplatform_v1/test_featurestore_service.py new file mode 100644 index 0000000000..3a6fbc4802 --- /dev/null +++ b/tests/unit/gapic/aiplatform_v1/test_featurestore_service.py @@ -0,0 +1,8751 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import os + +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock +except ImportError: + import mock + +import grpc +from grpc.experimental import aio +import math +import pytest +from proto.marshal.rules.dates import DurationRule, TimestampRule + + +from google.api_core import client_options +from google.api_core import exceptions as core_exceptions +from google.api_core import future +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers +from google.api_core import grpc_helpers_async +from google.api_core import operation +from google.api_core import operation_async # type: ignore +from google.api_core import operations_v1 +from google.api_core import path_template +from google.auth import credentials as ga_credentials +from google.auth.exceptions import MutualTLSChannelError +from google.cloud.aiplatform_v1.services.featurestore_service import ( + FeaturestoreServiceAsyncClient, +) +from google.cloud.aiplatform_v1.services.featurestore_service import ( + FeaturestoreServiceClient, +) +from google.cloud.aiplatform_v1.services.featurestore_service import pagers +from google.cloud.aiplatform_v1.services.featurestore_service import transports +from google.cloud.aiplatform_v1.types import encryption_spec +from google.cloud.aiplatform_v1.types import entity_type +from google.cloud.aiplatform_v1.types import entity_type as gca_entity_type +from google.cloud.aiplatform_v1.types import feature +from google.cloud.aiplatform_v1.types import feature as gca_feature +from google.cloud.aiplatform_v1.types import feature_monitoring_stats +from google.cloud.aiplatform_v1.types import feature_selector +from google.cloud.aiplatform_v1.types import featurestore +from google.cloud.aiplatform_v1.types import featurestore as gca_featurestore +from google.cloud.aiplatform_v1.types import featurestore_monitoring +from google.cloud.aiplatform_v1.types import featurestore_service +from google.cloud.aiplatform_v1.types import io +from google.cloud.aiplatform_v1.types import operation as gca_operation +from google.cloud.location import locations_pb2 +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.oauth2 import service_account +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +import google.auth + + +def client_cert_source_callback(): + return b"cert bytes", b"key bytes" + + +# If default endpoint is localhost, then default mtls endpoint will be the same. +# This method modifies the default endpoint so the client can produce a different +# mtls endpoint for endpoint testing purposes. +def modify_default_endpoint(client): + return ( + "foo.googleapis.com" + if ("localhost" in client.DEFAULT_ENDPOINT) + else client.DEFAULT_ENDPOINT + ) + + +def test__get_default_mtls_endpoint(): + api_endpoint = "example.googleapis.com" + api_mtls_endpoint = "example.mtls.googleapis.com" + sandbox_endpoint = "example.sandbox.googleapis.com" + sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" + non_googleapi = "api.example.com" + + assert FeaturestoreServiceClient._get_default_mtls_endpoint(None) is None + assert ( + FeaturestoreServiceClient._get_default_mtls_endpoint(api_endpoint) + == api_mtls_endpoint + ) + assert ( + FeaturestoreServiceClient._get_default_mtls_endpoint(api_mtls_endpoint) + == api_mtls_endpoint + ) + assert ( + FeaturestoreServiceClient._get_default_mtls_endpoint(sandbox_endpoint) + == sandbox_mtls_endpoint + ) + assert ( + FeaturestoreServiceClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) + == sandbox_mtls_endpoint + ) + assert ( + FeaturestoreServiceClient._get_default_mtls_endpoint(non_googleapi) + == non_googleapi + ) + + +@pytest.mark.parametrize( + "client_class,transport_name", + [ + (FeaturestoreServiceClient, "grpc"), + (FeaturestoreServiceAsyncClient, "grpc_asyncio"), + ], +) +def test_featurestore_service_client_from_service_account_info( + client_class, transport_name +): + creds = ga_credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_info" + ) as factory: + factory.return_value = creds + info = {"valid": True} + client = client_class.from_service_account_info(info, transport=transport_name) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.FeaturestoreServiceGrpcTransport, "grpc"), + (transports.FeaturestoreServiceGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_featurestore_service_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + +@pytest.mark.parametrize( + "client_class,transport_name", + [ + (FeaturestoreServiceClient, "grpc"), + (FeaturestoreServiceAsyncClient, "grpc_asyncio"), + ], +) +def test_featurestore_service_client_from_service_account_file( + client_class, transport_name +): + creds = ga_credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_file" + ) as factory: + factory.return_value = creds + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +def test_featurestore_service_client_get_transport_class(): + transport = FeaturestoreServiceClient.get_transport_class() + available_transports = [ + transports.FeaturestoreServiceGrpcTransport, + ] + assert transport in available_transports + + transport = FeaturestoreServiceClient.get_transport_class("grpc") + assert transport == transports.FeaturestoreServiceGrpcTransport + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + ( + FeaturestoreServiceClient, + transports.FeaturestoreServiceGrpcTransport, + "grpc", + ), + ( + FeaturestoreServiceAsyncClient, + transports.FeaturestoreServiceGrpcAsyncIOTransport, + "grpc_asyncio", + ), + ], +) +@mock.patch.object( + FeaturestoreServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(FeaturestoreServiceClient), +) +@mock.patch.object( + FeaturestoreServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(FeaturestoreServiceAsyncClient), +) +def test_featurestore_service_client_client_options( + client_class, transport_class, transport_name +): + # Check that if channel is provided we won't create a new one. + with mock.patch.object(FeaturestoreServiceClient, "get_transport_class") as gtc: + transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + client = client_class(transport=transport) + gtc.assert_not_called() + + # Check that if channel is provided via str we will create a new one. + with mock.patch.object(FeaturestoreServiceClient, "get_transport_class") as gtc: + client = client_class(transport=transport_name) + gtc.assert_called() + + # Check the case api_endpoint is provided. + options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(transport=transport_name, client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is + # "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is + # "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_MTLS_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has + # unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError): + client = client_class(transport=transport_name) + + # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError): + client = client_class(transport=transport_name) + + # Check the case quota_project_id is provided + options = client_options.ClientOptions(quota_project_id="octopus") + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id="octopus", + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,use_client_cert_env", + [ + ( + FeaturestoreServiceClient, + transports.FeaturestoreServiceGrpcTransport, + "grpc", + "true", + ), + ( + FeaturestoreServiceAsyncClient, + transports.FeaturestoreServiceGrpcAsyncIOTransport, + "grpc_asyncio", + "true", + ), + ( + FeaturestoreServiceClient, + transports.FeaturestoreServiceGrpcTransport, + "grpc", + "false", + ), + ( + FeaturestoreServiceAsyncClient, + transports.FeaturestoreServiceGrpcAsyncIOTransport, + "grpc_asyncio", + "false", + ), + ], +) +@mock.patch.object( + FeaturestoreServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(FeaturestoreServiceClient), +) +@mock.patch.object( + FeaturestoreServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(FeaturestoreServiceAsyncClient), +) +@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) +def test_featurestore_service_client_mtls_env_auto( + client_class, transport_class, transport_name, use_client_cert_env +): + # This tests the endpoint autoswitch behavior. Endpoint is autoswitched to the default + # mtls endpoint, if GOOGLE_API_USE_CLIENT_CERTIFICATE is "true" and client cert exists. + + # Check the case client_cert_source is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + options = client_options.ClientOptions( + client_cert_source=client_cert_source_callback + ) + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client.DEFAULT_ENDPOINT + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT + + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # Check the case ADC client cert is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=client_cert_source_callback, + ): + if use_client_cert_env == "false": + expected_host = client.DEFAULT_ENDPOINT + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback + + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + +@pytest.mark.parametrize( + "client_class", [FeaturestoreServiceClient, FeaturestoreServiceAsyncClient] +) +@mock.patch.object( + FeaturestoreServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(FeaturestoreServiceClient), +) +@mock.patch.object( + FeaturestoreServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(FeaturestoreServiceAsyncClient), +) +def test_featurestore_service_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + ( + FeaturestoreServiceClient, + transports.FeaturestoreServiceGrpcTransport, + "grpc", + ), + ( + FeaturestoreServiceAsyncClient, + transports.FeaturestoreServiceGrpcAsyncIOTransport, + "grpc_asyncio", + ), + ], +) +def test_featurestore_service_client_client_options_scopes( + client_class, transport_class, transport_name +): + # Check the case scopes are provided. + options = client_options.ClientOptions( + scopes=["1", "2"], + ) + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=["1", "2"], + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + FeaturestoreServiceClient, + transports.FeaturestoreServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + FeaturestoreServiceAsyncClient, + transports.FeaturestoreServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_featurestore_service_client_client_options_credentials_file( + client_class, transport_class, transport_name, grpc_helpers +): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + +def test_featurestore_service_client_client_options_from_dict(): + with mock.patch( + "google.cloud.aiplatform_v1.services.featurestore_service.transports.FeaturestoreServiceGrpcTransport.__init__" + ) as grpc_transport: + grpc_transport.return_value = None + client = FeaturestoreServiceClient( + client_options={"api_endpoint": "squid.clam.whelk"} + ) + grpc_transport.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + FeaturestoreServiceClient, + transports.FeaturestoreServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + FeaturestoreServiceAsyncClient, + transports.FeaturestoreServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_featurestore_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers +): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.CreateFeaturestoreRequest, + dict, + ], +) +def test_create_featurestore(request_type, transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_featurestore), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.create_featurestore(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.CreateFeaturestoreRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_create_featurestore_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_featurestore), "__call__" + ) as call: + client.create_featurestore() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.CreateFeaturestoreRequest() + + +@pytest.mark.asyncio +async def test_create_featurestore_async( + transport: str = "grpc_asyncio", + request_type=featurestore_service.CreateFeaturestoreRequest, +): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_featurestore), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.create_featurestore(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.CreateFeaturestoreRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_create_featurestore_async_from_dict(): + await test_create_featurestore_async(request_type=dict) + + +def test_create_featurestore_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.CreateFeaturestoreRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_featurestore), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.create_featurestore(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_create_featurestore_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.CreateFeaturestoreRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_featurestore), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.create_featurestore(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_create_featurestore_flattened(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_featurestore), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_featurestore( + parent="parent_value", + featurestore=gca_featurestore.Featurestore(name="name_value"), + featurestore_id="featurestore_id_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].featurestore + mock_val = gca_featurestore.Featurestore(name="name_value") + assert arg == mock_val + arg = args[0].featurestore_id + mock_val = "featurestore_id_value" + assert arg == mock_val + + +def test_create_featurestore_flattened_error(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_featurestore( + featurestore_service.CreateFeaturestoreRequest(), + parent="parent_value", + featurestore=gca_featurestore.Featurestore(name="name_value"), + featurestore_id="featurestore_id_value", + ) + + +@pytest.mark.asyncio +async def test_create_featurestore_flattened_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_featurestore), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_featurestore( + parent="parent_value", + featurestore=gca_featurestore.Featurestore(name="name_value"), + featurestore_id="featurestore_id_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].featurestore + mock_val = gca_featurestore.Featurestore(name="name_value") + assert arg == mock_val + arg = args[0].featurestore_id + mock_val = "featurestore_id_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_create_featurestore_flattened_error_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.create_featurestore( + featurestore_service.CreateFeaturestoreRequest(), + parent="parent_value", + featurestore=gca_featurestore.Featurestore(name="name_value"), + featurestore_id="featurestore_id_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.GetFeaturestoreRequest, + dict, + ], +) +def test_get_featurestore(request_type, transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_featurestore), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = featurestore.Featurestore( + name="name_value", + etag="etag_value", + state=featurestore.Featurestore.State.STABLE, + ) + response = client.get_featurestore(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.GetFeaturestoreRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, featurestore.Featurestore) + assert response.name == "name_value" + assert response.etag == "etag_value" + assert response.state == featurestore.Featurestore.State.STABLE + + +def test_get_featurestore_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_featurestore), "__call__") as call: + client.get_featurestore() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.GetFeaturestoreRequest() + + +@pytest.mark.asyncio +async def test_get_featurestore_async( + transport: str = "grpc_asyncio", + request_type=featurestore_service.GetFeaturestoreRequest, +): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_featurestore), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + featurestore.Featurestore( + name="name_value", + etag="etag_value", + state=featurestore.Featurestore.State.STABLE, + ) + ) + response = await client.get_featurestore(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.GetFeaturestoreRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, featurestore.Featurestore) + assert response.name == "name_value" + assert response.etag == "etag_value" + assert response.state == featurestore.Featurestore.State.STABLE + + +@pytest.mark.asyncio +async def test_get_featurestore_async_from_dict(): + await test_get_featurestore_async(request_type=dict) + + +def test_get_featurestore_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.GetFeaturestoreRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_featurestore), "__call__") as call: + call.return_value = featurestore.Featurestore() + client.get_featurestore(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_featurestore_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.GetFeaturestoreRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_featurestore), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + featurestore.Featurestore() + ) + await client.get_featurestore(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_get_featurestore_flattened(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_featurestore), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = featurestore.Featurestore() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_featurestore( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_get_featurestore_flattened_error(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_featurestore( + featurestore_service.GetFeaturestoreRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_featurestore_flattened_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_featurestore), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = featurestore.Featurestore() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + featurestore.Featurestore() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_featurestore( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_get_featurestore_flattened_error_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_featurestore( + featurestore_service.GetFeaturestoreRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.ListFeaturestoresRequest, + dict, + ], +) +def test_list_featurestores(request_type, transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_featurestores), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = featurestore_service.ListFeaturestoresResponse( + next_page_token="next_page_token_value", + ) + response = client.list_featurestores(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.ListFeaturestoresRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListFeaturestoresPager) + assert response.next_page_token == "next_page_token_value" + + +def test_list_featurestores_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_featurestores), "__call__" + ) as call: + client.list_featurestores() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.ListFeaturestoresRequest() + + +@pytest.mark.asyncio +async def test_list_featurestores_async( + transport: str = "grpc_asyncio", + request_type=featurestore_service.ListFeaturestoresRequest, +): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_featurestores), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + featurestore_service.ListFeaturestoresResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.list_featurestores(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.ListFeaturestoresRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListFeaturestoresAsyncPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_list_featurestores_async_from_dict(): + await test_list_featurestores_async(request_type=dict) + + +def test_list_featurestores_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.ListFeaturestoresRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_featurestores), "__call__" + ) as call: + call.return_value = featurestore_service.ListFeaturestoresResponse() + client.list_featurestores(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_featurestores_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.ListFeaturestoresRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_featurestores), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + featurestore_service.ListFeaturestoresResponse() + ) + await client.list_featurestores(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_list_featurestores_flattened(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_featurestores), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = featurestore_service.ListFeaturestoresResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_featurestores( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +def test_list_featurestores_flattened_error(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_featurestores( + featurestore_service.ListFeaturestoresRequest(), + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_featurestores_flattened_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_featurestores), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = featurestore_service.ListFeaturestoresResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + featurestore_service.ListFeaturestoresResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_featurestores( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_list_featurestores_flattened_error_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_featurestores( + featurestore_service.ListFeaturestoresRequest(), + parent="parent_value", + ) + + +def test_list_featurestores_pager(transport_name: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_featurestores), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + featurestore_service.ListFeaturestoresResponse( + featurestores=[ + featurestore.Featurestore(), + featurestore.Featurestore(), + featurestore.Featurestore(), + ], + next_page_token="abc", + ), + featurestore_service.ListFeaturestoresResponse( + featurestores=[], + next_page_token="def", + ), + featurestore_service.ListFeaturestoresResponse( + featurestores=[ + featurestore.Featurestore(), + ], + next_page_token="ghi", + ), + featurestore_service.ListFeaturestoresResponse( + featurestores=[ + featurestore.Featurestore(), + featurestore.Featurestore(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_featurestores(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, featurestore.Featurestore) for i in results) + + +def test_list_featurestores_pages(transport_name: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_featurestores), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + featurestore_service.ListFeaturestoresResponse( + featurestores=[ + featurestore.Featurestore(), + featurestore.Featurestore(), + featurestore.Featurestore(), + ], + next_page_token="abc", + ), + featurestore_service.ListFeaturestoresResponse( + featurestores=[], + next_page_token="def", + ), + featurestore_service.ListFeaturestoresResponse( + featurestores=[ + featurestore.Featurestore(), + ], + next_page_token="ghi", + ), + featurestore_service.ListFeaturestoresResponse( + featurestores=[ + featurestore.Featurestore(), + featurestore.Featurestore(), + ], + ), + RuntimeError, + ) + pages = list(client.list_featurestores(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.asyncio +async def test_list_featurestores_async_pager(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_featurestores), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + featurestore_service.ListFeaturestoresResponse( + featurestores=[ + featurestore.Featurestore(), + featurestore.Featurestore(), + featurestore.Featurestore(), + ], + next_page_token="abc", + ), + featurestore_service.ListFeaturestoresResponse( + featurestores=[], + next_page_token="def", + ), + featurestore_service.ListFeaturestoresResponse( + featurestores=[ + featurestore.Featurestore(), + ], + next_page_token="ghi", + ), + featurestore_service.ListFeaturestoresResponse( + featurestores=[ + featurestore.Featurestore(), + featurestore.Featurestore(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_featurestores( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, featurestore.Featurestore) for i in responses) + + +@pytest.mark.asyncio +async def test_list_featurestores_async_pages(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_featurestores), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + featurestore_service.ListFeaturestoresResponse( + featurestores=[ + featurestore.Featurestore(), + featurestore.Featurestore(), + featurestore.Featurestore(), + ], + next_page_token="abc", + ), + featurestore_service.ListFeaturestoresResponse( + featurestores=[], + next_page_token="def", + ), + featurestore_service.ListFeaturestoresResponse( + featurestores=[ + featurestore.Featurestore(), + ], + next_page_token="ghi", + ), + featurestore_service.ListFeaturestoresResponse( + featurestores=[ + featurestore.Featurestore(), + featurestore.Featurestore(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.list_featurestores(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.UpdateFeaturestoreRequest, + dict, + ], +) +def test_update_featurestore(request_type, transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_featurestore), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.update_featurestore(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.UpdateFeaturestoreRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_update_featurestore_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_featurestore), "__call__" + ) as call: + client.update_featurestore() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.UpdateFeaturestoreRequest() + + +@pytest.mark.asyncio +async def test_update_featurestore_async( + transport: str = "grpc_asyncio", + request_type=featurestore_service.UpdateFeaturestoreRequest, +): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_featurestore), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.update_featurestore(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.UpdateFeaturestoreRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_update_featurestore_async_from_dict(): + await test_update_featurestore_async(request_type=dict) + + +def test_update_featurestore_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.UpdateFeaturestoreRequest() + + request.featurestore.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_featurestore), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.update_featurestore(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "featurestore.name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_update_featurestore_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.UpdateFeaturestoreRequest() + + request.featurestore.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_featurestore), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.update_featurestore(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "featurestore.name=name_value", + ) in kw["metadata"] + + +def test_update_featurestore_flattened(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_featurestore), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.update_featurestore( + featurestore=gca_featurestore.Featurestore(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].featurestore + mock_val = gca_featurestore.Featurestore(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + + +def test_update_featurestore_flattened_error(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_featurestore( + featurestore_service.UpdateFeaturestoreRequest(), + featurestore=gca_featurestore.Featurestore(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.asyncio +async def test_update_featurestore_flattened_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_featurestore), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.update_featurestore( + featurestore=gca_featurestore.Featurestore(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].featurestore + mock_val = gca_featurestore.Featurestore(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_update_featurestore_flattened_error_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.update_featurestore( + featurestore_service.UpdateFeaturestoreRequest(), + featurestore=gca_featurestore.Featurestore(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.DeleteFeaturestoreRequest, + dict, + ], +) +def test_delete_featurestore(request_type, transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_featurestore), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.delete_featurestore(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.DeleteFeaturestoreRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_delete_featurestore_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_featurestore), "__call__" + ) as call: + client.delete_featurestore() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.DeleteFeaturestoreRequest() + + +@pytest.mark.asyncio +async def test_delete_featurestore_async( + transport: str = "grpc_asyncio", + request_type=featurestore_service.DeleteFeaturestoreRequest, +): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_featurestore), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.delete_featurestore(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.DeleteFeaturestoreRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_delete_featurestore_async_from_dict(): + await test_delete_featurestore_async(request_type=dict) + + +def test_delete_featurestore_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.DeleteFeaturestoreRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_featurestore), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_featurestore(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_featurestore_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.DeleteFeaturestoreRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_featurestore), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.delete_featurestore(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_delete_featurestore_flattened(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_featurestore), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_featurestore( + name="name_value", + force=True, + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].force + mock_val = True + assert arg == mock_val + + +def test_delete_featurestore_flattened_error(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_featurestore( + featurestore_service.DeleteFeaturestoreRequest(), + name="name_value", + force=True, + ) + + +@pytest.mark.asyncio +async def test_delete_featurestore_flattened_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_featurestore), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_featurestore( + name="name_value", + force=True, + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].force + mock_val = True + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_delete_featurestore_flattened_error_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.delete_featurestore( + featurestore_service.DeleteFeaturestoreRequest(), + name="name_value", + force=True, + ) + + +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.CreateEntityTypeRequest, + dict, + ], +) +def test_create_entity_type(request_type, transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_entity_type), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.create_entity_type(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.CreateEntityTypeRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_create_entity_type_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_entity_type), "__call__" + ) as call: + client.create_entity_type() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.CreateEntityTypeRequest() + + +@pytest.mark.asyncio +async def test_create_entity_type_async( + transport: str = "grpc_asyncio", + request_type=featurestore_service.CreateEntityTypeRequest, +): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_entity_type), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.create_entity_type(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.CreateEntityTypeRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_create_entity_type_async_from_dict(): + await test_create_entity_type_async(request_type=dict) + + +def test_create_entity_type_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.CreateEntityTypeRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_entity_type), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.create_entity_type(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_create_entity_type_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.CreateEntityTypeRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_entity_type), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.create_entity_type(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_create_entity_type_flattened(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_entity_type), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_entity_type( + parent="parent_value", + entity_type=gca_entity_type.EntityType(name="name_value"), + entity_type_id="entity_type_id_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].entity_type + mock_val = gca_entity_type.EntityType(name="name_value") + assert arg == mock_val + arg = args[0].entity_type_id + mock_val = "entity_type_id_value" + assert arg == mock_val + + +def test_create_entity_type_flattened_error(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_entity_type( + featurestore_service.CreateEntityTypeRequest(), + parent="parent_value", + entity_type=gca_entity_type.EntityType(name="name_value"), + entity_type_id="entity_type_id_value", + ) + + +@pytest.mark.asyncio +async def test_create_entity_type_flattened_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_entity_type), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_entity_type( + parent="parent_value", + entity_type=gca_entity_type.EntityType(name="name_value"), + entity_type_id="entity_type_id_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].entity_type + mock_val = gca_entity_type.EntityType(name="name_value") + assert arg == mock_val + arg = args[0].entity_type_id + mock_val = "entity_type_id_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_create_entity_type_flattened_error_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.create_entity_type( + featurestore_service.CreateEntityTypeRequest(), + parent="parent_value", + entity_type=gca_entity_type.EntityType(name="name_value"), + entity_type_id="entity_type_id_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.GetEntityTypeRequest, + dict, + ], +) +def test_get_entity_type(request_type, transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_entity_type), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = entity_type.EntityType( + name="name_value", + description="description_value", + etag="etag_value", + ) + response = client.get_entity_type(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.GetEntityTypeRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, entity_type.EntityType) + assert response.name == "name_value" + assert response.description == "description_value" + assert response.etag == "etag_value" + + +def test_get_entity_type_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_entity_type), "__call__") as call: + client.get_entity_type() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.GetEntityTypeRequest() + + +@pytest.mark.asyncio +async def test_get_entity_type_async( + transport: str = "grpc_asyncio", + request_type=featurestore_service.GetEntityTypeRequest, +): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_entity_type), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + entity_type.EntityType( + name="name_value", + description="description_value", + etag="etag_value", + ) + ) + response = await client.get_entity_type(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.GetEntityTypeRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, entity_type.EntityType) + assert response.name == "name_value" + assert response.description == "description_value" + assert response.etag == "etag_value" + + +@pytest.mark.asyncio +async def test_get_entity_type_async_from_dict(): + await test_get_entity_type_async(request_type=dict) + + +def test_get_entity_type_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.GetEntityTypeRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_entity_type), "__call__") as call: + call.return_value = entity_type.EntityType() + client.get_entity_type(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_entity_type_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.GetEntityTypeRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_entity_type), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + entity_type.EntityType() + ) + await client.get_entity_type(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_get_entity_type_flattened(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_entity_type), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = entity_type.EntityType() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_entity_type( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_get_entity_type_flattened_error(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_entity_type( + featurestore_service.GetEntityTypeRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_entity_type_flattened_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_entity_type), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = entity_type.EntityType() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + entity_type.EntityType() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_entity_type( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_get_entity_type_flattened_error_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_entity_type( + featurestore_service.GetEntityTypeRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.ListEntityTypesRequest, + dict, + ], +) +def test_list_entity_types(request_type, transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_entity_types), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = featurestore_service.ListEntityTypesResponse( + next_page_token="next_page_token_value", + ) + response = client.list_entity_types(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.ListEntityTypesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListEntityTypesPager) + assert response.next_page_token == "next_page_token_value" + + +def test_list_entity_types_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_entity_types), "__call__" + ) as call: + client.list_entity_types() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.ListEntityTypesRequest() + + +@pytest.mark.asyncio +async def test_list_entity_types_async( + transport: str = "grpc_asyncio", + request_type=featurestore_service.ListEntityTypesRequest, +): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_entity_types), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + featurestore_service.ListEntityTypesResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.list_entity_types(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.ListEntityTypesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListEntityTypesAsyncPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_list_entity_types_async_from_dict(): + await test_list_entity_types_async(request_type=dict) + + +def test_list_entity_types_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.ListEntityTypesRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_entity_types), "__call__" + ) as call: + call.return_value = featurestore_service.ListEntityTypesResponse() + client.list_entity_types(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_entity_types_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.ListEntityTypesRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_entity_types), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + featurestore_service.ListEntityTypesResponse() + ) + await client.list_entity_types(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_list_entity_types_flattened(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_entity_types), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = featurestore_service.ListEntityTypesResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_entity_types( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +def test_list_entity_types_flattened_error(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_entity_types( + featurestore_service.ListEntityTypesRequest(), + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_entity_types_flattened_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_entity_types), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = featurestore_service.ListEntityTypesResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + featurestore_service.ListEntityTypesResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_entity_types( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_list_entity_types_flattened_error_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_entity_types( + featurestore_service.ListEntityTypesRequest(), + parent="parent_value", + ) + + +def test_list_entity_types_pager(transport_name: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_entity_types), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + featurestore_service.ListEntityTypesResponse( + entity_types=[ + entity_type.EntityType(), + entity_type.EntityType(), + entity_type.EntityType(), + ], + next_page_token="abc", + ), + featurestore_service.ListEntityTypesResponse( + entity_types=[], + next_page_token="def", + ), + featurestore_service.ListEntityTypesResponse( + entity_types=[ + entity_type.EntityType(), + ], + next_page_token="ghi", + ), + featurestore_service.ListEntityTypesResponse( + entity_types=[ + entity_type.EntityType(), + entity_type.EntityType(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_entity_types(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, entity_type.EntityType) for i in results) + + +def test_list_entity_types_pages(transport_name: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_entity_types), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + featurestore_service.ListEntityTypesResponse( + entity_types=[ + entity_type.EntityType(), + entity_type.EntityType(), + entity_type.EntityType(), + ], + next_page_token="abc", + ), + featurestore_service.ListEntityTypesResponse( + entity_types=[], + next_page_token="def", + ), + featurestore_service.ListEntityTypesResponse( + entity_types=[ + entity_type.EntityType(), + ], + next_page_token="ghi", + ), + featurestore_service.ListEntityTypesResponse( + entity_types=[ + entity_type.EntityType(), + entity_type.EntityType(), + ], + ), + RuntimeError, + ) + pages = list(client.list_entity_types(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.asyncio +async def test_list_entity_types_async_pager(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_entity_types), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + featurestore_service.ListEntityTypesResponse( + entity_types=[ + entity_type.EntityType(), + entity_type.EntityType(), + entity_type.EntityType(), + ], + next_page_token="abc", + ), + featurestore_service.ListEntityTypesResponse( + entity_types=[], + next_page_token="def", + ), + featurestore_service.ListEntityTypesResponse( + entity_types=[ + entity_type.EntityType(), + ], + next_page_token="ghi", + ), + featurestore_service.ListEntityTypesResponse( + entity_types=[ + entity_type.EntityType(), + entity_type.EntityType(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_entity_types( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, entity_type.EntityType) for i in responses) + + +@pytest.mark.asyncio +async def test_list_entity_types_async_pages(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_entity_types), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + featurestore_service.ListEntityTypesResponse( + entity_types=[ + entity_type.EntityType(), + entity_type.EntityType(), + entity_type.EntityType(), + ], + next_page_token="abc", + ), + featurestore_service.ListEntityTypesResponse( + entity_types=[], + next_page_token="def", + ), + featurestore_service.ListEntityTypesResponse( + entity_types=[ + entity_type.EntityType(), + ], + next_page_token="ghi", + ), + featurestore_service.ListEntityTypesResponse( + entity_types=[ + entity_type.EntityType(), + entity_type.EntityType(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.list_entity_types(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.UpdateEntityTypeRequest, + dict, + ], +) +def test_update_entity_type(request_type, transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_entity_type), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gca_entity_type.EntityType( + name="name_value", + description="description_value", + etag="etag_value", + ) + response = client.update_entity_type(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.UpdateEntityTypeRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_entity_type.EntityType) + assert response.name == "name_value" + assert response.description == "description_value" + assert response.etag == "etag_value" + + +def test_update_entity_type_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_entity_type), "__call__" + ) as call: + client.update_entity_type() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.UpdateEntityTypeRequest() + + +@pytest.mark.asyncio +async def test_update_entity_type_async( + transport: str = "grpc_asyncio", + request_type=featurestore_service.UpdateEntityTypeRequest, +): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_entity_type), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_entity_type.EntityType( + name="name_value", + description="description_value", + etag="etag_value", + ) + ) + response = await client.update_entity_type(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.UpdateEntityTypeRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_entity_type.EntityType) + assert response.name == "name_value" + assert response.description == "description_value" + assert response.etag == "etag_value" + + +@pytest.mark.asyncio +async def test_update_entity_type_async_from_dict(): + await test_update_entity_type_async(request_type=dict) + + +def test_update_entity_type_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.UpdateEntityTypeRequest() + + request.entity_type.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_entity_type), "__call__" + ) as call: + call.return_value = gca_entity_type.EntityType() + client.update_entity_type(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "entity_type.name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_update_entity_type_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.UpdateEntityTypeRequest() + + request.entity_type.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_entity_type), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_entity_type.EntityType() + ) + await client.update_entity_type(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "entity_type.name=name_value", + ) in kw["metadata"] + + +def test_update_entity_type_flattened(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_entity_type), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gca_entity_type.EntityType() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.update_entity_type( + entity_type=gca_entity_type.EntityType(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].entity_type + mock_val = gca_entity_type.EntityType(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + + +def test_update_entity_type_flattened_error(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_entity_type( + featurestore_service.UpdateEntityTypeRequest(), + entity_type=gca_entity_type.EntityType(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.asyncio +async def test_update_entity_type_flattened_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_entity_type), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gca_entity_type.EntityType() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_entity_type.EntityType() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.update_entity_type( + entity_type=gca_entity_type.EntityType(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].entity_type + mock_val = gca_entity_type.EntityType(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_update_entity_type_flattened_error_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.update_entity_type( + featurestore_service.UpdateEntityTypeRequest(), + entity_type=gca_entity_type.EntityType(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.DeleteEntityTypeRequest, + dict, + ], +) +def test_delete_entity_type(request_type, transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_entity_type), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.delete_entity_type(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.DeleteEntityTypeRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_delete_entity_type_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_entity_type), "__call__" + ) as call: + client.delete_entity_type() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.DeleteEntityTypeRequest() + + +@pytest.mark.asyncio +async def test_delete_entity_type_async( + transport: str = "grpc_asyncio", + request_type=featurestore_service.DeleteEntityTypeRequest, +): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_entity_type), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.delete_entity_type(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.DeleteEntityTypeRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_delete_entity_type_async_from_dict(): + await test_delete_entity_type_async(request_type=dict) + + +def test_delete_entity_type_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.DeleteEntityTypeRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_entity_type), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_entity_type(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_entity_type_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.DeleteEntityTypeRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_entity_type), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.delete_entity_type(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_delete_entity_type_flattened(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_entity_type), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_entity_type( + name="name_value", + force=True, + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].force + mock_val = True + assert arg == mock_val + + +def test_delete_entity_type_flattened_error(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_entity_type( + featurestore_service.DeleteEntityTypeRequest(), + name="name_value", + force=True, + ) + + +@pytest.mark.asyncio +async def test_delete_entity_type_flattened_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_entity_type), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_entity_type( + name="name_value", + force=True, + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].force + mock_val = True + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_delete_entity_type_flattened_error_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.delete_entity_type( + featurestore_service.DeleteEntityTypeRequest(), + name="name_value", + force=True, + ) + + +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.CreateFeatureRequest, + dict, + ], +) +def test_create_feature(request_type, transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_feature), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.create_feature(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.CreateFeatureRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_create_feature_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_feature), "__call__") as call: + client.create_feature() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.CreateFeatureRequest() + + +@pytest.mark.asyncio +async def test_create_feature_async( + transport: str = "grpc_asyncio", + request_type=featurestore_service.CreateFeatureRequest, +): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_feature), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.create_feature(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.CreateFeatureRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_create_feature_async_from_dict(): + await test_create_feature_async(request_type=dict) + + +def test_create_feature_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.CreateFeatureRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_feature), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.create_feature(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_create_feature_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.CreateFeatureRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_feature), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.create_feature(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_create_feature_flattened(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_feature), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_feature( + parent="parent_value", + feature=gca_feature.Feature(name="name_value"), + feature_id="feature_id_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].feature + mock_val = gca_feature.Feature(name="name_value") + assert arg == mock_val + arg = args[0].feature_id + mock_val = "feature_id_value" + assert arg == mock_val + + +def test_create_feature_flattened_error(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_feature( + featurestore_service.CreateFeatureRequest(), + parent="parent_value", + feature=gca_feature.Feature(name="name_value"), + feature_id="feature_id_value", + ) + + +@pytest.mark.asyncio +async def test_create_feature_flattened_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_feature), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_feature( + parent="parent_value", + feature=gca_feature.Feature(name="name_value"), + feature_id="feature_id_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].feature + mock_val = gca_feature.Feature(name="name_value") + assert arg == mock_val + arg = args[0].feature_id + mock_val = "feature_id_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_create_feature_flattened_error_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.create_feature( + featurestore_service.CreateFeatureRequest(), + parent="parent_value", + feature=gca_feature.Feature(name="name_value"), + feature_id="feature_id_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.BatchCreateFeaturesRequest, + dict, + ], +) +def test_batch_create_features(request_type, transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_create_features), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.batch_create_features(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.BatchCreateFeaturesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_batch_create_features_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_create_features), "__call__" + ) as call: + client.batch_create_features() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.BatchCreateFeaturesRequest() + + +@pytest.mark.asyncio +async def test_batch_create_features_async( + transport: str = "grpc_asyncio", + request_type=featurestore_service.BatchCreateFeaturesRequest, +): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_create_features), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.batch_create_features(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.BatchCreateFeaturesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_batch_create_features_async_from_dict(): + await test_batch_create_features_async(request_type=dict) + + +def test_batch_create_features_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.BatchCreateFeaturesRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_create_features), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.batch_create_features(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_batch_create_features_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.BatchCreateFeaturesRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_create_features), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.batch_create_features(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_batch_create_features_flattened(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_create_features), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.batch_create_features( + parent="parent_value", + requests=[featurestore_service.CreateFeatureRequest(parent="parent_value")], + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].requests + mock_val = [featurestore_service.CreateFeatureRequest(parent="parent_value")] + assert arg == mock_val + + +def test_batch_create_features_flattened_error(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.batch_create_features( + featurestore_service.BatchCreateFeaturesRequest(), + parent="parent_value", + requests=[featurestore_service.CreateFeatureRequest(parent="parent_value")], + ) + + +@pytest.mark.asyncio +async def test_batch_create_features_flattened_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_create_features), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.batch_create_features( + parent="parent_value", + requests=[featurestore_service.CreateFeatureRequest(parent="parent_value")], + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].requests + mock_val = [featurestore_service.CreateFeatureRequest(parent="parent_value")] + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_batch_create_features_flattened_error_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.batch_create_features( + featurestore_service.BatchCreateFeaturesRequest(), + parent="parent_value", + requests=[featurestore_service.CreateFeatureRequest(parent="parent_value")], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.GetFeatureRequest, + dict, + ], +) +def test_get_feature(request_type, transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_feature), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = feature.Feature( + name="name_value", + description="description_value", + value_type=feature.Feature.ValueType.BOOL, + etag="etag_value", + disable_monitoring=True, + ) + response = client.get_feature(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.GetFeatureRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, feature.Feature) + assert response.name == "name_value" + assert response.description == "description_value" + assert response.value_type == feature.Feature.ValueType.BOOL + assert response.etag == "etag_value" + assert response.disable_monitoring is True + + +def test_get_feature_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_feature), "__call__") as call: + client.get_feature() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.GetFeatureRequest() + + +@pytest.mark.asyncio +async def test_get_feature_async( + transport: str = "grpc_asyncio", request_type=featurestore_service.GetFeatureRequest +): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_feature), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + feature.Feature( + name="name_value", + description="description_value", + value_type=feature.Feature.ValueType.BOOL, + etag="etag_value", + disable_monitoring=True, + ) + ) + response = await client.get_feature(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.GetFeatureRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, feature.Feature) + assert response.name == "name_value" + assert response.description == "description_value" + assert response.value_type == feature.Feature.ValueType.BOOL + assert response.etag == "etag_value" + assert response.disable_monitoring is True + + +@pytest.mark.asyncio +async def test_get_feature_async_from_dict(): + await test_get_feature_async(request_type=dict) + + +def test_get_feature_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.GetFeatureRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_feature), "__call__") as call: + call.return_value = feature.Feature() + client.get_feature(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_feature_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.GetFeatureRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_feature), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(feature.Feature()) + await client.get_feature(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_get_feature_flattened(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_feature), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = feature.Feature() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_feature( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_get_feature_flattened_error(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_feature( + featurestore_service.GetFeatureRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_feature_flattened_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_feature), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = feature.Feature() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(feature.Feature()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_feature( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_get_feature_flattened_error_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_feature( + featurestore_service.GetFeatureRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.ListFeaturesRequest, + dict, + ], +) +def test_list_features(request_type, transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_features), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = featurestore_service.ListFeaturesResponse( + next_page_token="next_page_token_value", + ) + response = client.list_features(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.ListFeaturesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListFeaturesPager) + assert response.next_page_token == "next_page_token_value" + + +def test_list_features_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_features), "__call__") as call: + client.list_features() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.ListFeaturesRequest() + + +@pytest.mark.asyncio +async def test_list_features_async( + transport: str = "grpc_asyncio", + request_type=featurestore_service.ListFeaturesRequest, +): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_features), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + featurestore_service.ListFeaturesResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.list_features(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.ListFeaturesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListFeaturesAsyncPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_list_features_async_from_dict(): + await test_list_features_async(request_type=dict) + + +def test_list_features_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.ListFeaturesRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_features), "__call__") as call: + call.return_value = featurestore_service.ListFeaturesResponse() + client.list_features(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_features_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.ListFeaturesRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_features), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + featurestore_service.ListFeaturesResponse() + ) + await client.list_features(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_list_features_flattened(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_features), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = featurestore_service.ListFeaturesResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_features( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +def test_list_features_flattened_error(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_features( + featurestore_service.ListFeaturesRequest(), + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_features_flattened_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_features), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = featurestore_service.ListFeaturesResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + featurestore_service.ListFeaturesResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_features( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_list_features_flattened_error_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_features( + featurestore_service.ListFeaturesRequest(), + parent="parent_value", + ) + + +def test_list_features_pager(transport_name: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_features), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + featurestore_service.ListFeaturesResponse( + features=[ + feature.Feature(), + feature.Feature(), + feature.Feature(), + ], + next_page_token="abc", + ), + featurestore_service.ListFeaturesResponse( + features=[], + next_page_token="def", + ), + featurestore_service.ListFeaturesResponse( + features=[ + feature.Feature(), + ], + next_page_token="ghi", + ), + featurestore_service.ListFeaturesResponse( + features=[ + feature.Feature(), + feature.Feature(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_features(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, feature.Feature) for i in results) + + +def test_list_features_pages(transport_name: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_features), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + featurestore_service.ListFeaturesResponse( + features=[ + feature.Feature(), + feature.Feature(), + feature.Feature(), + ], + next_page_token="abc", + ), + featurestore_service.ListFeaturesResponse( + features=[], + next_page_token="def", + ), + featurestore_service.ListFeaturesResponse( + features=[ + feature.Feature(), + ], + next_page_token="ghi", + ), + featurestore_service.ListFeaturesResponse( + features=[ + feature.Feature(), + feature.Feature(), + ], + ), + RuntimeError, + ) + pages = list(client.list_features(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.asyncio +async def test_list_features_async_pager(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_features), "__call__", new_callable=mock.AsyncMock + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + featurestore_service.ListFeaturesResponse( + features=[ + feature.Feature(), + feature.Feature(), + feature.Feature(), + ], + next_page_token="abc", + ), + featurestore_service.ListFeaturesResponse( + features=[], + next_page_token="def", + ), + featurestore_service.ListFeaturesResponse( + features=[ + feature.Feature(), + ], + next_page_token="ghi", + ), + featurestore_service.ListFeaturesResponse( + features=[ + feature.Feature(), + feature.Feature(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_features( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, feature.Feature) for i in responses) + + +@pytest.mark.asyncio +async def test_list_features_async_pages(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_features), "__call__", new_callable=mock.AsyncMock + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + featurestore_service.ListFeaturesResponse( + features=[ + feature.Feature(), + feature.Feature(), + feature.Feature(), + ], + next_page_token="abc", + ), + featurestore_service.ListFeaturesResponse( + features=[], + next_page_token="def", + ), + featurestore_service.ListFeaturesResponse( + features=[ + feature.Feature(), + ], + next_page_token="ghi", + ), + featurestore_service.ListFeaturesResponse( + features=[ + feature.Feature(), + feature.Feature(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.list_features(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.UpdateFeatureRequest, + dict, + ], +) +def test_update_feature(request_type, transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_feature), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = gca_feature.Feature( + name="name_value", + description="description_value", + value_type=gca_feature.Feature.ValueType.BOOL, + etag="etag_value", + disable_monitoring=True, + ) + response = client.update_feature(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.UpdateFeatureRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_feature.Feature) + assert response.name == "name_value" + assert response.description == "description_value" + assert response.value_type == gca_feature.Feature.ValueType.BOOL + assert response.etag == "etag_value" + assert response.disable_monitoring is True + + +def test_update_feature_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_feature), "__call__") as call: + client.update_feature() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.UpdateFeatureRequest() + + +@pytest.mark.asyncio +async def test_update_feature_async( + transport: str = "grpc_asyncio", + request_type=featurestore_service.UpdateFeatureRequest, +): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_feature), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_feature.Feature( + name="name_value", + description="description_value", + value_type=gca_feature.Feature.ValueType.BOOL, + etag="etag_value", + disable_monitoring=True, + ) + ) + response = await client.update_feature(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.UpdateFeatureRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_feature.Feature) + assert response.name == "name_value" + assert response.description == "description_value" + assert response.value_type == gca_feature.Feature.ValueType.BOOL + assert response.etag == "etag_value" + assert response.disable_monitoring is True + + +@pytest.mark.asyncio +async def test_update_feature_async_from_dict(): + await test_update_feature_async(request_type=dict) + + +def test_update_feature_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.UpdateFeatureRequest() + + request.feature.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_feature), "__call__") as call: + call.return_value = gca_feature.Feature() + client.update_feature(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "feature.name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_update_feature_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.UpdateFeatureRequest() + + request.feature.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_feature), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gca_feature.Feature()) + await client.update_feature(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "feature.name=name_value", + ) in kw["metadata"] + + +def test_update_feature_flattened(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_feature), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = gca_feature.Feature() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.update_feature( + feature=gca_feature.Feature(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].feature + mock_val = gca_feature.Feature(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + + +def test_update_feature_flattened_error(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_feature( + featurestore_service.UpdateFeatureRequest(), + feature=gca_feature.Feature(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.asyncio +async def test_update_feature_flattened_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_feature), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = gca_feature.Feature() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gca_feature.Feature()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.update_feature( + feature=gca_feature.Feature(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].feature + mock_val = gca_feature.Feature(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_update_feature_flattened_error_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.update_feature( + featurestore_service.UpdateFeatureRequest(), + feature=gca_feature.Feature(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.DeleteFeatureRequest, + dict, + ], +) +def test_delete_feature(request_type, transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_feature), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.delete_feature(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.DeleteFeatureRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_delete_feature_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_feature), "__call__") as call: + client.delete_feature() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.DeleteFeatureRequest() + + +@pytest.mark.asyncio +async def test_delete_feature_async( + transport: str = "grpc_asyncio", + request_type=featurestore_service.DeleteFeatureRequest, +): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_feature), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.delete_feature(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.DeleteFeatureRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_delete_feature_async_from_dict(): + await test_delete_feature_async(request_type=dict) + + +def test_delete_feature_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.DeleteFeatureRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_feature), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_feature(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_feature_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.DeleteFeatureRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_feature), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.delete_feature(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_delete_feature_flattened(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_feature), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_feature( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_delete_feature_flattened_error(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_feature( + featurestore_service.DeleteFeatureRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_delete_feature_flattened_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_feature), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_feature( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_delete_feature_flattened_error_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.delete_feature( + featurestore_service.DeleteFeatureRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.ImportFeatureValuesRequest, + dict, + ], +) +def test_import_feature_values(request_type, transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.import_feature_values), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.import_feature_values(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.ImportFeatureValuesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_import_feature_values_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.import_feature_values), "__call__" + ) as call: + client.import_feature_values() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.ImportFeatureValuesRequest() + + +@pytest.mark.asyncio +async def test_import_feature_values_async( + transport: str = "grpc_asyncio", + request_type=featurestore_service.ImportFeatureValuesRequest, +): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.import_feature_values), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.import_feature_values(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.ImportFeatureValuesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_import_feature_values_async_from_dict(): + await test_import_feature_values_async(request_type=dict) + + +def test_import_feature_values_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.ImportFeatureValuesRequest() + + request.entity_type = "entity_type_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.import_feature_values), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.import_feature_values(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "entity_type=entity_type_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_import_feature_values_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.ImportFeatureValuesRequest() + + request.entity_type = "entity_type_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.import_feature_values), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.import_feature_values(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "entity_type=entity_type_value", + ) in kw["metadata"] + + +def test_import_feature_values_flattened(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.import_feature_values), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.import_feature_values( + entity_type="entity_type_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].entity_type + mock_val = "entity_type_value" + assert arg == mock_val + + +def test_import_feature_values_flattened_error(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.import_feature_values( + featurestore_service.ImportFeatureValuesRequest(), + entity_type="entity_type_value", + ) + + +@pytest.mark.asyncio +async def test_import_feature_values_flattened_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.import_feature_values), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.import_feature_values( + entity_type="entity_type_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].entity_type + mock_val = "entity_type_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_import_feature_values_flattened_error_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.import_feature_values( + featurestore_service.ImportFeatureValuesRequest(), + entity_type="entity_type_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.BatchReadFeatureValuesRequest, + dict, + ], +) +def test_batch_read_feature_values(request_type, transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_read_feature_values), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.batch_read_feature_values(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.BatchReadFeatureValuesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_batch_read_feature_values_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_read_feature_values), "__call__" + ) as call: + client.batch_read_feature_values() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.BatchReadFeatureValuesRequest() + + +@pytest.mark.asyncio +async def test_batch_read_feature_values_async( + transport: str = "grpc_asyncio", + request_type=featurestore_service.BatchReadFeatureValuesRequest, +): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_read_feature_values), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.batch_read_feature_values(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.BatchReadFeatureValuesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_batch_read_feature_values_async_from_dict(): + await test_batch_read_feature_values_async(request_type=dict) + + +def test_batch_read_feature_values_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.BatchReadFeatureValuesRequest() + + request.featurestore = "featurestore_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_read_feature_values), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.batch_read_feature_values(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "featurestore=featurestore_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_batch_read_feature_values_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.BatchReadFeatureValuesRequest() + + request.featurestore = "featurestore_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_read_feature_values), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.batch_read_feature_values(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "featurestore=featurestore_value", + ) in kw["metadata"] + + +def test_batch_read_feature_values_flattened(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_read_feature_values), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.batch_read_feature_values( + featurestore="featurestore_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].featurestore + mock_val = "featurestore_value" + assert arg == mock_val + + +def test_batch_read_feature_values_flattened_error(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.batch_read_feature_values( + featurestore_service.BatchReadFeatureValuesRequest(), + featurestore="featurestore_value", + ) + + +@pytest.mark.asyncio +async def test_batch_read_feature_values_flattened_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_read_feature_values), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.batch_read_feature_values( + featurestore="featurestore_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].featurestore + mock_val = "featurestore_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_batch_read_feature_values_flattened_error_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.batch_read_feature_values( + featurestore_service.BatchReadFeatureValuesRequest(), + featurestore="featurestore_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.ExportFeatureValuesRequest, + dict, + ], +) +def test_export_feature_values(request_type, transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.export_feature_values), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.export_feature_values(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.ExportFeatureValuesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_export_feature_values_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.export_feature_values), "__call__" + ) as call: + client.export_feature_values() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.ExportFeatureValuesRequest() + + +@pytest.mark.asyncio +async def test_export_feature_values_async( + transport: str = "grpc_asyncio", + request_type=featurestore_service.ExportFeatureValuesRequest, +): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.export_feature_values), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.export_feature_values(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.ExportFeatureValuesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_export_feature_values_async_from_dict(): + await test_export_feature_values_async(request_type=dict) + + +def test_export_feature_values_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.ExportFeatureValuesRequest() + + request.entity_type = "entity_type_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.export_feature_values), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.export_feature_values(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "entity_type=entity_type_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_export_feature_values_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.ExportFeatureValuesRequest() + + request.entity_type = "entity_type_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.export_feature_values), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.export_feature_values(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "entity_type=entity_type_value", + ) in kw["metadata"] + + +def test_export_feature_values_flattened(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.export_feature_values), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.export_feature_values( + entity_type="entity_type_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].entity_type + mock_val = "entity_type_value" + assert arg == mock_val + + +def test_export_feature_values_flattened_error(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.export_feature_values( + featurestore_service.ExportFeatureValuesRequest(), + entity_type="entity_type_value", + ) + + +@pytest.mark.asyncio +async def test_export_feature_values_flattened_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.export_feature_values), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.export_feature_values( + entity_type="entity_type_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].entity_type + mock_val = "entity_type_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_export_feature_values_flattened_error_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.export_feature_values( + featurestore_service.ExportFeatureValuesRequest(), + entity_type="entity_type_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.SearchFeaturesRequest, + dict, + ], +) +def test_search_features(request_type, transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.search_features), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = featurestore_service.SearchFeaturesResponse( + next_page_token="next_page_token_value", + ) + response = client.search_features(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.SearchFeaturesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.SearchFeaturesPager) + assert response.next_page_token == "next_page_token_value" + + +def test_search_features_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.search_features), "__call__") as call: + client.search_features() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.SearchFeaturesRequest() + + +@pytest.mark.asyncio +async def test_search_features_async( + transport: str = "grpc_asyncio", + request_type=featurestore_service.SearchFeaturesRequest, +): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.search_features), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + featurestore_service.SearchFeaturesResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.search_features(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == featurestore_service.SearchFeaturesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.SearchFeaturesAsyncPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_search_features_async_from_dict(): + await test_search_features_async(request_type=dict) + + +def test_search_features_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.SearchFeaturesRequest() + + request.location = "location_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.search_features), "__call__") as call: + call.return_value = featurestore_service.SearchFeaturesResponse() + client.search_features(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "location=location_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_search_features_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = featurestore_service.SearchFeaturesRequest() + + request.location = "location_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.search_features), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + featurestore_service.SearchFeaturesResponse() + ) + await client.search_features(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "location=location_value", + ) in kw["metadata"] + + +def test_search_features_flattened(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.search_features), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = featurestore_service.SearchFeaturesResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.search_features( + location="location_value", + query="query_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].location + mock_val = "location_value" + assert arg == mock_val + arg = args[0].query + mock_val = "query_value" + assert arg == mock_val + + +def test_search_features_flattened_error(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.search_features( + featurestore_service.SearchFeaturesRequest(), + location="location_value", + query="query_value", + ) + + +@pytest.mark.asyncio +async def test_search_features_flattened_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.search_features), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = featurestore_service.SearchFeaturesResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + featurestore_service.SearchFeaturesResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.search_features( + location="location_value", + query="query_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].location + mock_val = "location_value" + assert arg == mock_val + arg = args[0].query + mock_val = "query_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_search_features_flattened_error_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.search_features( + featurestore_service.SearchFeaturesRequest(), + location="location_value", + query="query_value", + ) + + +def test_search_features_pager(transport_name: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.search_features), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + featurestore_service.SearchFeaturesResponse( + features=[ + feature.Feature(), + feature.Feature(), + feature.Feature(), + ], + next_page_token="abc", + ), + featurestore_service.SearchFeaturesResponse( + features=[], + next_page_token="def", + ), + featurestore_service.SearchFeaturesResponse( + features=[ + feature.Feature(), + ], + next_page_token="ghi", + ), + featurestore_service.SearchFeaturesResponse( + features=[ + feature.Feature(), + feature.Feature(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("location", ""),)), + ) + pager = client.search_features(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, feature.Feature) for i in results) + + +def test_search_features_pages(transport_name: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.search_features), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + featurestore_service.SearchFeaturesResponse( + features=[ + feature.Feature(), + feature.Feature(), + feature.Feature(), + ], + next_page_token="abc", + ), + featurestore_service.SearchFeaturesResponse( + features=[], + next_page_token="def", + ), + featurestore_service.SearchFeaturesResponse( + features=[ + feature.Feature(), + ], + next_page_token="ghi", + ), + featurestore_service.SearchFeaturesResponse( + features=[ + feature.Feature(), + feature.Feature(), + ], + ), + RuntimeError, + ) + pages = list(client.search_features(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.asyncio +async def test_search_features_async_pager(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.search_features), "__call__", new_callable=mock.AsyncMock + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + featurestore_service.SearchFeaturesResponse( + features=[ + feature.Feature(), + feature.Feature(), + feature.Feature(), + ], + next_page_token="abc", + ), + featurestore_service.SearchFeaturesResponse( + features=[], + next_page_token="def", + ), + featurestore_service.SearchFeaturesResponse( + features=[ + feature.Feature(), + ], + next_page_token="ghi", + ), + featurestore_service.SearchFeaturesResponse( + features=[ + feature.Feature(), + feature.Feature(), + ], + ), + RuntimeError, + ) + async_pager = await client.search_features( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, feature.Feature) for i in responses) + + +@pytest.mark.asyncio +async def test_search_features_async_pages(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.search_features), "__call__", new_callable=mock.AsyncMock + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + featurestore_service.SearchFeaturesResponse( + features=[ + feature.Feature(), + feature.Feature(), + feature.Feature(), + ], + next_page_token="abc", + ), + featurestore_service.SearchFeaturesResponse( + features=[], + next_page_token="def", + ), + featurestore_service.SearchFeaturesResponse( + features=[ + feature.Feature(), + ], + next_page_token="ghi", + ), + featurestore_service.SearchFeaturesResponse( + features=[ + feature.Feature(), + feature.Feature(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.search_features(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.FeaturestoreServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.FeaturestoreServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = FeaturestoreServiceClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide an api_key and a transport instance. + transport = transports.FeaturestoreServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = FeaturestoreServiceClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = FeaturestoreServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.FeaturestoreServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = FeaturestoreServiceClient( + client_options={"scopes": ["1", "2"]}, + transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.FeaturestoreServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + client = FeaturestoreServiceClient(transport=transport) + assert client.transport is transport + + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.FeaturestoreServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.FeaturestoreServiceGrpcAsyncIOTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.FeaturestoreServiceGrpcTransport, + transports.FeaturestoreServiceGrpcAsyncIOTransport, + ], +) +def test_transport_adc(transport_class): + # Test default credentials are used if not provided. + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class() + adc.assert_called_once() + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = FeaturestoreServiceClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + +def test_transport_grpc_default(): + # A client should use the gRPC transport by default. + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.FeaturestoreServiceGrpcTransport, + ) + + +def test_featurestore_service_base_transport_error(): + # Passing both a credentials object and credentials_file should raise an error + with pytest.raises(core_exceptions.DuplicateCredentialArgs): + transport = transports.FeaturestoreServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + credentials_file="credentials.json", + ) + + +def test_featurestore_service_base_transport(): + # Instantiate the base transport. + with mock.patch( + "google.cloud.aiplatform_v1.services.featurestore_service.transports.FeaturestoreServiceTransport.__init__" + ) as Transport: + Transport.return_value = None + transport = transports.FeaturestoreServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Every method on the transport should just blindly + # raise NotImplementedError. + methods = ( + "create_featurestore", + "get_featurestore", + "list_featurestores", + "update_featurestore", + "delete_featurestore", + "create_entity_type", + "get_entity_type", + "list_entity_types", + "update_entity_type", + "delete_entity_type", + "create_feature", + "batch_create_features", + "get_feature", + "list_features", + "update_feature", + "delete_feature", + "import_feature_values", + "batch_read_feature_values", + "export_feature_values", + "search_features", + "set_iam_policy", + "get_iam_policy", + "test_iam_permissions", + "get_location", + "list_locations", + "get_operation", + "wait_operation", + "cancel_operation", + "delete_operation", + "list_operations", + ) + for method in methods: + with pytest.raises(NotImplementedError): + getattr(transport, method)(request=object()) + + with pytest.raises(NotImplementedError): + transport.close() + + # Additionally, the LRO client (a property) should + # also raise NotImplementedError + with pytest.raises(NotImplementedError): + transport.operations_client + + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + + +def test_featurestore_service_base_transport_with_credentials_file(): + # Instantiate the base transport with a credentials file + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch( + "google.cloud.aiplatform_v1.services.featurestore_service.transports.FeaturestoreServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.FeaturestoreServiceTransport( + credentials_file="credentials.json", + quota_project_id="octopus", + ) + load_creds.assert_called_once_with( + "credentials.json", + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +def test_featurestore_service_base_transport_with_adc(): + # Test the default credentials are used if credentials and credentials_file are None. + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( + "google.cloud.aiplatform_v1.services.featurestore_service.transports.FeaturestoreServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.FeaturestoreServiceTransport() + adc.assert_called_once() + + +def test_featurestore_service_auth_adc(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + FeaturestoreServiceClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id=None, + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.FeaturestoreServiceGrpcTransport, + transports.FeaturestoreServiceGrpcAsyncIOTransport, + ], +) +def test_featurestore_service_transport_auth_adc(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.FeaturestoreServiceGrpcTransport, grpc_helpers), + (transports.FeaturestoreServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +def test_featurestore_service_transport_create_channel(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=["1", "2"], + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.FeaturestoreServiceGrpcTransport, + transports.FeaturestoreServiceGrpcAsyncIOTransport, + ], +) +def test_featurestore_service_grpc_transport_client_cert_source_for_mtls( + transport_class, +): + cred = ga_credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds, + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback, + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, private_key=expected_key + ) + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_featurestore_service_host_no_port(transport_name): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions( + api_endpoint="aiplatform.googleapis.com" + ), + transport=transport_name, + ) + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_featurestore_service_host_with_port(transport_name): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions( + api_endpoint="aiplatform.googleapis.com:8000" + ), + transport=transport_name, + ) + assert client.transport._host == ("aiplatform.googleapis.com:8000") + + +def test_featurestore_service_grpc_transport_channel(): + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.FeaturestoreServiceGrpcTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +def test_featurestore_service_grpc_asyncio_transport_channel(): + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.FeaturestoreServiceGrpcAsyncIOTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize( + "transport_class", + [ + transports.FeaturestoreServiceGrpcTransport, + transports.FeaturestoreServiceGrpcAsyncIOTransport, + ], +) +def test_featurestore_service_transport_channel_mtls_with_client_cert_source( + transport_class, +): + with mock.patch( + "grpc.ssl_channel_credentials", autospec=True + ) as grpc_ssl_channel_cred: + with mock.patch.object( + transport_class, "create_channel" + ) as grpc_create_channel: + mock_ssl_cred = mock.Mock() + grpc_ssl_channel_cred.return_value = mock_ssl_cred + + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + + cred = ga_credentials.AnonymousCredentials() + with pytest.warns(DeprecationWarning): + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (cred, None) + transport = transport_class( + host="squid.clam.whelk", + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=client_cert_source_callback, + ) + adc.assert_called_once() + + grpc_ssl_channel_cred.assert_called_once_with( + certificate_chain=b"cert bytes", private_key=b"key bytes" + ) + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize( + "transport_class", + [ + transports.FeaturestoreServiceGrpcTransport, + transports.FeaturestoreServiceGrpcAsyncIOTransport, + ], +) +def test_featurestore_service_transport_channel_mtls_with_adc(transport_class): + mock_ssl_cred = mock.Mock() + with mock.patch.multiple( + "google.auth.transport.grpc.SslCredentials", + __init__=mock.Mock(return_value=None), + ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), + ): + with mock.patch.object( + transport_class, "create_channel" + ) as grpc_create_channel: + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + mock_cred = mock.Mock() + + with pytest.warns(DeprecationWarning): + transport = transport_class( + host="squid.clam.whelk", + credentials=mock_cred, + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=None, + ) + + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=mock_cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + + +def test_featurestore_service_grpc_lro_client(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_featurestore_service_grpc_lro_async_client(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_entity_type_path(): + project = "squid" + location = "clam" + featurestore = "whelk" + entity_type = "octopus" + expected = "projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}".format( + project=project, + location=location, + featurestore=featurestore, + entity_type=entity_type, + ) + actual = FeaturestoreServiceClient.entity_type_path( + project, location, featurestore, entity_type + ) + assert expected == actual + + +def test_parse_entity_type_path(): + expected = { + "project": "oyster", + "location": "nudibranch", + "featurestore": "cuttlefish", + "entity_type": "mussel", + } + path = FeaturestoreServiceClient.entity_type_path(**expected) + + # Check that the path construction is reversible. + actual = FeaturestoreServiceClient.parse_entity_type_path(path) + assert expected == actual + + +def test_feature_path(): + project = "winkle" + location = "nautilus" + featurestore = "scallop" + entity_type = "abalone" + feature = "squid" + expected = "projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entity_type}/features/{feature}".format( + project=project, + location=location, + featurestore=featurestore, + entity_type=entity_type, + feature=feature, + ) + actual = FeaturestoreServiceClient.feature_path( + project, location, featurestore, entity_type, feature + ) + assert expected == actual + + +def test_parse_feature_path(): + expected = { + "project": "clam", + "location": "whelk", + "featurestore": "octopus", + "entity_type": "oyster", + "feature": "nudibranch", + } + path = FeaturestoreServiceClient.feature_path(**expected) + + # Check that the path construction is reversible. + actual = FeaturestoreServiceClient.parse_feature_path(path) + assert expected == actual + + +def test_featurestore_path(): + project = "cuttlefish" + location = "mussel" + featurestore = "winkle" + expected = ( + "projects/{project}/locations/{location}/featurestores/{featurestore}".format( + project=project, + location=location, + featurestore=featurestore, + ) + ) + actual = FeaturestoreServiceClient.featurestore_path( + project, location, featurestore + ) + assert expected == actual + + +def test_parse_featurestore_path(): + expected = { + "project": "nautilus", + "location": "scallop", + "featurestore": "abalone", + } + path = FeaturestoreServiceClient.featurestore_path(**expected) + + # Check that the path construction is reversible. + actual = FeaturestoreServiceClient.parse_featurestore_path(path) + assert expected == actual + + +def test_common_billing_account_path(): + billing_account = "squid" + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + actual = FeaturestoreServiceClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "clam", + } + path = FeaturestoreServiceClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = FeaturestoreServiceClient.parse_common_billing_account_path(path) + assert expected == actual + + +def test_common_folder_path(): + folder = "whelk" + expected = "folders/{folder}".format( + folder=folder, + ) + actual = FeaturestoreServiceClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "octopus", + } + path = FeaturestoreServiceClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = FeaturestoreServiceClient.parse_common_folder_path(path) + assert expected == actual + + +def test_common_organization_path(): + organization = "oyster" + expected = "organizations/{organization}".format( + organization=organization, + ) + actual = FeaturestoreServiceClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "nudibranch", + } + path = FeaturestoreServiceClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = FeaturestoreServiceClient.parse_common_organization_path(path) + assert expected == actual + + +def test_common_project_path(): + project = "cuttlefish" + expected = "projects/{project}".format( + project=project, + ) + actual = FeaturestoreServiceClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "mussel", + } + path = FeaturestoreServiceClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = FeaturestoreServiceClient.parse_common_project_path(path) + assert expected == actual + + +def test_common_location_path(): + project = "winkle" + location = "nautilus" + expected = "projects/{project}/locations/{location}".format( + project=project, + location=location, + ) + actual = FeaturestoreServiceClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "scallop", + "location": "abalone", + } + path = FeaturestoreServiceClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = FeaturestoreServiceClient.parse_common_location_path(path) + assert expected == actual + + +def test_client_with_default_client_info(): + client_info = gapic_v1.client_info.ClientInfo() + + with mock.patch.object( + transports.FeaturestoreServiceTransport, "_prep_wrapped_messages" + ) as prep: + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + with mock.patch.object( + transports.FeaturestoreServiceTransport, "_prep_wrapped_messages" + ) as prep: + transport_class = FeaturestoreServiceClient.get_transport_class() + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_delete_operation(transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_operation(transport: str = "grpc"): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_operation_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = None + + client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_operation_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_delete_operation_from_dict(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_delete_operation_from_dict_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_cancel_operation(transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation(transport: str = "grpc"): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_wait_operation(transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_wait_operation(transport: str = "grpc"): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_wait_operation_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_wait_operation_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_wait_operation_from_dict(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_wait_operation_from_dict_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_operation(transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_get_operation(transport: str = "grpc"): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_get_operation_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_get_operation_from_dict(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_operations(transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + response = client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +@pytest.mark.asyncio +async def test_list_operations(transport: str = "grpc"): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +def test_list_operations_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_operations_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_operations_from_dict(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + response = client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_operations_from_dict_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_locations(transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + response = client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +@pytest.mark.asyncio +async def test_list_locations(transport: str = "grpc"): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +def test_list_locations_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_locations_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_locations_from_dict(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + response = client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_locations_from_dict_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_location(transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + response = client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +@pytest.mark.asyncio +async def test_get_location_async(transport: str = "grpc_asyncio"): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +def test_get_location_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials() + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = locations_pb2.Location() + + client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_location_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials() + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +def test_get_location_from_dict(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + response = client.get_location( + request={ + "name": "locations/abc", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_location_from_dict_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_set_iam_policy(transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + response = client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + response = await client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_set_iam_policy_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_set_iam_policy_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_set_iam_policy_from_dict(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_set_iam_policy_from_dict_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +def test_get_iam_policy(transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + + response = client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + + response = await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_get_iam_policy_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_iam_policy_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_get_iam_policy_from_dict(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_iam_policy_from_dict_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +def test_test_iam_permissions(transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + + response = client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + ) + + response = await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +def test_test_iam_permissions_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_test_iam_permissions_from_dict(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + response = client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_from_dict_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + response = await client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (FeaturestoreServiceClient, transports.FeaturestoreServiceGrpcTransport), + ( + FeaturestoreServiceAsyncClient, + transports.FeaturestoreServiceGrpcAsyncIOTransport, + ), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) diff --git a/tests/unit/gapic/aiplatform_v1/test_index_endpoint_service.py b/tests/unit/gapic/aiplatform_v1/test_index_endpoint_service.py new file mode 100644 index 0000000000..3b57660444 --- /dev/null +++ b/tests/unit/gapic/aiplatform_v1/test_index_endpoint_service.py @@ -0,0 +1,5188 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import os + +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock +except ImportError: + import mock + +import grpc +from grpc.experimental import aio +import math +import pytest +from proto.marshal.rules.dates import DurationRule, TimestampRule + + +from google.api_core import client_options +from google.api_core import exceptions as core_exceptions +from google.api_core import future +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers +from google.api_core import grpc_helpers_async +from google.api_core import operation +from google.api_core import operation_async # type: ignore +from google.api_core import operations_v1 +from google.api_core import path_template +from google.auth import credentials as ga_credentials +from google.auth.exceptions import MutualTLSChannelError +from google.cloud.aiplatform_v1.services.index_endpoint_service import ( + IndexEndpointServiceAsyncClient, +) +from google.cloud.aiplatform_v1.services.index_endpoint_service import ( + IndexEndpointServiceClient, +) +from google.cloud.aiplatform_v1.services.index_endpoint_service import pagers +from google.cloud.aiplatform_v1.services.index_endpoint_service import transports +from google.cloud.aiplatform_v1.types import accelerator_type +from google.cloud.aiplatform_v1.types import index_endpoint +from google.cloud.aiplatform_v1.types import index_endpoint as gca_index_endpoint +from google.cloud.aiplatform_v1.types import index_endpoint_service +from google.cloud.aiplatform_v1.types import machine_resources +from google.cloud.aiplatform_v1.types import operation as gca_operation +from google.cloud.location import locations_pb2 +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.oauth2 import service_account +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +import google.auth + + +def client_cert_source_callback(): + return b"cert bytes", b"key bytes" + + +# If default endpoint is localhost, then default mtls endpoint will be the same. +# This method modifies the default endpoint so the client can produce a different +# mtls endpoint for endpoint testing purposes. +def modify_default_endpoint(client): + return ( + "foo.googleapis.com" + if ("localhost" in client.DEFAULT_ENDPOINT) + else client.DEFAULT_ENDPOINT + ) + + +def test__get_default_mtls_endpoint(): + api_endpoint = "example.googleapis.com" + api_mtls_endpoint = "example.mtls.googleapis.com" + sandbox_endpoint = "example.sandbox.googleapis.com" + sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" + non_googleapi = "api.example.com" + + assert IndexEndpointServiceClient._get_default_mtls_endpoint(None) is None + assert ( + IndexEndpointServiceClient._get_default_mtls_endpoint(api_endpoint) + == api_mtls_endpoint + ) + assert ( + IndexEndpointServiceClient._get_default_mtls_endpoint(api_mtls_endpoint) + == api_mtls_endpoint + ) + assert ( + IndexEndpointServiceClient._get_default_mtls_endpoint(sandbox_endpoint) + == sandbox_mtls_endpoint + ) + assert ( + IndexEndpointServiceClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) + == sandbox_mtls_endpoint + ) + assert ( + IndexEndpointServiceClient._get_default_mtls_endpoint(non_googleapi) + == non_googleapi + ) + + +@pytest.mark.parametrize( + "client_class,transport_name", + [ + (IndexEndpointServiceClient, "grpc"), + (IndexEndpointServiceAsyncClient, "grpc_asyncio"), + ], +) +def test_index_endpoint_service_client_from_service_account_info( + client_class, transport_name +): + creds = ga_credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_info" + ) as factory: + factory.return_value = creds + info = {"valid": True} + client = client_class.from_service_account_info(info, transport=transport_name) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.IndexEndpointServiceGrpcTransport, "grpc"), + (transports.IndexEndpointServiceGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_index_endpoint_service_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + +@pytest.mark.parametrize( + "client_class,transport_name", + [ + (IndexEndpointServiceClient, "grpc"), + (IndexEndpointServiceAsyncClient, "grpc_asyncio"), + ], +) +def test_index_endpoint_service_client_from_service_account_file( + client_class, transport_name +): + creds = ga_credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_file" + ) as factory: + factory.return_value = creds + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +def test_index_endpoint_service_client_get_transport_class(): + transport = IndexEndpointServiceClient.get_transport_class() + available_transports = [ + transports.IndexEndpointServiceGrpcTransport, + ] + assert transport in available_transports + + transport = IndexEndpointServiceClient.get_transport_class("grpc") + assert transport == transports.IndexEndpointServiceGrpcTransport + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + ( + IndexEndpointServiceClient, + transports.IndexEndpointServiceGrpcTransport, + "grpc", + ), + ( + IndexEndpointServiceAsyncClient, + transports.IndexEndpointServiceGrpcAsyncIOTransport, + "grpc_asyncio", + ), + ], +) +@mock.patch.object( + IndexEndpointServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(IndexEndpointServiceClient), +) +@mock.patch.object( + IndexEndpointServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(IndexEndpointServiceAsyncClient), +) +def test_index_endpoint_service_client_client_options( + client_class, transport_class, transport_name +): + # Check that if channel is provided we won't create a new one. + with mock.patch.object(IndexEndpointServiceClient, "get_transport_class") as gtc: + transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + client = client_class(transport=transport) + gtc.assert_not_called() + + # Check that if channel is provided via str we will create a new one. + with mock.patch.object(IndexEndpointServiceClient, "get_transport_class") as gtc: + client = client_class(transport=transport_name) + gtc.assert_called() + + # Check the case api_endpoint is provided. + options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(transport=transport_name, client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is + # "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is + # "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_MTLS_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has + # unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError): + client = client_class(transport=transport_name) + + # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError): + client = client_class(transport=transport_name) + + # Check the case quota_project_id is provided + options = client_options.ClientOptions(quota_project_id="octopus") + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id="octopus", + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,use_client_cert_env", + [ + ( + IndexEndpointServiceClient, + transports.IndexEndpointServiceGrpcTransport, + "grpc", + "true", + ), + ( + IndexEndpointServiceAsyncClient, + transports.IndexEndpointServiceGrpcAsyncIOTransport, + "grpc_asyncio", + "true", + ), + ( + IndexEndpointServiceClient, + transports.IndexEndpointServiceGrpcTransport, + "grpc", + "false", + ), + ( + IndexEndpointServiceAsyncClient, + transports.IndexEndpointServiceGrpcAsyncIOTransport, + "grpc_asyncio", + "false", + ), + ], +) +@mock.patch.object( + IndexEndpointServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(IndexEndpointServiceClient), +) +@mock.patch.object( + IndexEndpointServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(IndexEndpointServiceAsyncClient), +) +@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) +def test_index_endpoint_service_client_mtls_env_auto( + client_class, transport_class, transport_name, use_client_cert_env +): + # This tests the endpoint autoswitch behavior. Endpoint is autoswitched to the default + # mtls endpoint, if GOOGLE_API_USE_CLIENT_CERTIFICATE is "true" and client cert exists. + + # Check the case client_cert_source is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + options = client_options.ClientOptions( + client_cert_source=client_cert_source_callback + ) + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client.DEFAULT_ENDPOINT + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT + + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # Check the case ADC client cert is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=client_cert_source_callback, + ): + if use_client_cert_env == "false": + expected_host = client.DEFAULT_ENDPOINT + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback + + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + +@pytest.mark.parametrize( + "client_class", [IndexEndpointServiceClient, IndexEndpointServiceAsyncClient] +) +@mock.patch.object( + IndexEndpointServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(IndexEndpointServiceClient), +) +@mock.patch.object( + IndexEndpointServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(IndexEndpointServiceAsyncClient), +) +def test_index_endpoint_service_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + ( + IndexEndpointServiceClient, + transports.IndexEndpointServiceGrpcTransport, + "grpc", + ), + ( + IndexEndpointServiceAsyncClient, + transports.IndexEndpointServiceGrpcAsyncIOTransport, + "grpc_asyncio", + ), + ], +) +def test_index_endpoint_service_client_client_options_scopes( + client_class, transport_class, transport_name +): + # Check the case scopes are provided. + options = client_options.ClientOptions( + scopes=["1", "2"], + ) + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=["1", "2"], + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + IndexEndpointServiceClient, + transports.IndexEndpointServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + IndexEndpointServiceAsyncClient, + transports.IndexEndpointServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_index_endpoint_service_client_client_options_credentials_file( + client_class, transport_class, transport_name, grpc_helpers +): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + +def test_index_endpoint_service_client_client_options_from_dict(): + with mock.patch( + "google.cloud.aiplatform_v1.services.index_endpoint_service.transports.IndexEndpointServiceGrpcTransport.__init__" + ) as grpc_transport: + grpc_transport.return_value = None + client = IndexEndpointServiceClient( + client_options={"api_endpoint": "squid.clam.whelk"} + ) + grpc_transport.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + IndexEndpointServiceClient, + transports.IndexEndpointServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + IndexEndpointServiceAsyncClient, + transports.IndexEndpointServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_index_endpoint_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers +): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + index_endpoint_service.CreateIndexEndpointRequest, + dict, + ], +) +def test_create_index_endpoint(request_type, transport: str = "grpc"): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_index_endpoint), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.create_index_endpoint(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == index_endpoint_service.CreateIndexEndpointRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_create_index_endpoint_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_index_endpoint), "__call__" + ) as call: + client.create_index_endpoint() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == index_endpoint_service.CreateIndexEndpointRequest() + + +@pytest.mark.asyncio +async def test_create_index_endpoint_async( + transport: str = "grpc_asyncio", + request_type=index_endpoint_service.CreateIndexEndpointRequest, +): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_index_endpoint), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.create_index_endpoint(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == index_endpoint_service.CreateIndexEndpointRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_create_index_endpoint_async_from_dict(): + await test_create_index_endpoint_async(request_type=dict) + + +def test_create_index_endpoint_field_headers(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = index_endpoint_service.CreateIndexEndpointRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_index_endpoint), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.create_index_endpoint(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_create_index_endpoint_field_headers_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = index_endpoint_service.CreateIndexEndpointRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_index_endpoint), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.create_index_endpoint(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_create_index_endpoint_flattened(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_index_endpoint), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_index_endpoint( + parent="parent_value", + index_endpoint=gca_index_endpoint.IndexEndpoint(name="name_value"), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].index_endpoint + mock_val = gca_index_endpoint.IndexEndpoint(name="name_value") + assert arg == mock_val + + +def test_create_index_endpoint_flattened_error(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_index_endpoint( + index_endpoint_service.CreateIndexEndpointRequest(), + parent="parent_value", + index_endpoint=gca_index_endpoint.IndexEndpoint(name="name_value"), + ) + + +@pytest.mark.asyncio +async def test_create_index_endpoint_flattened_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_index_endpoint), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_index_endpoint( + parent="parent_value", + index_endpoint=gca_index_endpoint.IndexEndpoint(name="name_value"), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].index_endpoint + mock_val = gca_index_endpoint.IndexEndpoint(name="name_value") + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_create_index_endpoint_flattened_error_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.create_index_endpoint( + index_endpoint_service.CreateIndexEndpointRequest(), + parent="parent_value", + index_endpoint=gca_index_endpoint.IndexEndpoint(name="name_value"), + ) + + +@pytest.mark.parametrize( + "request_type", + [ + index_endpoint_service.GetIndexEndpointRequest, + dict, + ], +) +def test_get_index_endpoint(request_type, transport: str = "grpc"): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_index_endpoint), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = index_endpoint.IndexEndpoint( + name="name_value", + display_name="display_name_value", + description="description_value", + etag="etag_value", + network="network_value", + enable_private_service_connect=True, + ) + response = client.get_index_endpoint(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == index_endpoint_service.GetIndexEndpointRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, index_endpoint.IndexEndpoint) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.etag == "etag_value" + assert response.network == "network_value" + assert response.enable_private_service_connect is True + + +def test_get_index_endpoint_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_index_endpoint), "__call__" + ) as call: + client.get_index_endpoint() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == index_endpoint_service.GetIndexEndpointRequest() + + +@pytest.mark.asyncio +async def test_get_index_endpoint_async( + transport: str = "grpc_asyncio", + request_type=index_endpoint_service.GetIndexEndpointRequest, +): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_index_endpoint), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + index_endpoint.IndexEndpoint( + name="name_value", + display_name="display_name_value", + description="description_value", + etag="etag_value", + network="network_value", + enable_private_service_connect=True, + ) + ) + response = await client.get_index_endpoint(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == index_endpoint_service.GetIndexEndpointRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, index_endpoint.IndexEndpoint) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.etag == "etag_value" + assert response.network == "network_value" + assert response.enable_private_service_connect is True + + +@pytest.mark.asyncio +async def test_get_index_endpoint_async_from_dict(): + await test_get_index_endpoint_async(request_type=dict) + + +def test_get_index_endpoint_field_headers(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = index_endpoint_service.GetIndexEndpointRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_index_endpoint), "__call__" + ) as call: + call.return_value = index_endpoint.IndexEndpoint() + client.get_index_endpoint(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_index_endpoint_field_headers_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = index_endpoint_service.GetIndexEndpointRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_index_endpoint), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + index_endpoint.IndexEndpoint() + ) + await client.get_index_endpoint(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_get_index_endpoint_flattened(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_index_endpoint), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = index_endpoint.IndexEndpoint() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_index_endpoint( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_get_index_endpoint_flattened_error(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_index_endpoint( + index_endpoint_service.GetIndexEndpointRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_index_endpoint_flattened_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_index_endpoint), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = index_endpoint.IndexEndpoint() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + index_endpoint.IndexEndpoint() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_index_endpoint( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_get_index_endpoint_flattened_error_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_index_endpoint( + index_endpoint_service.GetIndexEndpointRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + index_endpoint_service.ListIndexEndpointsRequest, + dict, + ], +) +def test_list_index_endpoints(request_type, transport: str = "grpc"): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_index_endpoints), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = index_endpoint_service.ListIndexEndpointsResponse( + next_page_token="next_page_token_value", + ) + response = client.list_index_endpoints(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == index_endpoint_service.ListIndexEndpointsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListIndexEndpointsPager) + assert response.next_page_token == "next_page_token_value" + + +def test_list_index_endpoints_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_index_endpoints), "__call__" + ) as call: + client.list_index_endpoints() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == index_endpoint_service.ListIndexEndpointsRequest() + + +@pytest.mark.asyncio +async def test_list_index_endpoints_async( + transport: str = "grpc_asyncio", + request_type=index_endpoint_service.ListIndexEndpointsRequest, +): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_index_endpoints), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + index_endpoint_service.ListIndexEndpointsResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.list_index_endpoints(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == index_endpoint_service.ListIndexEndpointsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListIndexEndpointsAsyncPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_list_index_endpoints_async_from_dict(): + await test_list_index_endpoints_async(request_type=dict) + + +def test_list_index_endpoints_field_headers(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = index_endpoint_service.ListIndexEndpointsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_index_endpoints), "__call__" + ) as call: + call.return_value = index_endpoint_service.ListIndexEndpointsResponse() + client.list_index_endpoints(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_index_endpoints_field_headers_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = index_endpoint_service.ListIndexEndpointsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_index_endpoints), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + index_endpoint_service.ListIndexEndpointsResponse() + ) + await client.list_index_endpoints(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_list_index_endpoints_flattened(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_index_endpoints), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = index_endpoint_service.ListIndexEndpointsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_index_endpoints( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +def test_list_index_endpoints_flattened_error(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_index_endpoints( + index_endpoint_service.ListIndexEndpointsRequest(), + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_index_endpoints_flattened_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_index_endpoints), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = index_endpoint_service.ListIndexEndpointsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + index_endpoint_service.ListIndexEndpointsResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_index_endpoints( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_list_index_endpoints_flattened_error_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_index_endpoints( + index_endpoint_service.ListIndexEndpointsRequest(), + parent="parent_value", + ) + + +def test_list_index_endpoints_pager(transport_name: str = "grpc"): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_index_endpoints), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + index_endpoint_service.ListIndexEndpointsResponse( + index_endpoints=[ + index_endpoint.IndexEndpoint(), + index_endpoint.IndexEndpoint(), + index_endpoint.IndexEndpoint(), + ], + next_page_token="abc", + ), + index_endpoint_service.ListIndexEndpointsResponse( + index_endpoints=[], + next_page_token="def", + ), + index_endpoint_service.ListIndexEndpointsResponse( + index_endpoints=[ + index_endpoint.IndexEndpoint(), + ], + next_page_token="ghi", + ), + index_endpoint_service.ListIndexEndpointsResponse( + index_endpoints=[ + index_endpoint.IndexEndpoint(), + index_endpoint.IndexEndpoint(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_index_endpoints(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, index_endpoint.IndexEndpoint) for i in results) + + +def test_list_index_endpoints_pages(transport_name: str = "grpc"): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_index_endpoints), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + index_endpoint_service.ListIndexEndpointsResponse( + index_endpoints=[ + index_endpoint.IndexEndpoint(), + index_endpoint.IndexEndpoint(), + index_endpoint.IndexEndpoint(), + ], + next_page_token="abc", + ), + index_endpoint_service.ListIndexEndpointsResponse( + index_endpoints=[], + next_page_token="def", + ), + index_endpoint_service.ListIndexEndpointsResponse( + index_endpoints=[ + index_endpoint.IndexEndpoint(), + ], + next_page_token="ghi", + ), + index_endpoint_service.ListIndexEndpointsResponse( + index_endpoints=[ + index_endpoint.IndexEndpoint(), + index_endpoint.IndexEndpoint(), + ], + ), + RuntimeError, + ) + pages = list(client.list_index_endpoints(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.asyncio +async def test_list_index_endpoints_async_pager(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_index_endpoints), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + index_endpoint_service.ListIndexEndpointsResponse( + index_endpoints=[ + index_endpoint.IndexEndpoint(), + index_endpoint.IndexEndpoint(), + index_endpoint.IndexEndpoint(), + ], + next_page_token="abc", + ), + index_endpoint_service.ListIndexEndpointsResponse( + index_endpoints=[], + next_page_token="def", + ), + index_endpoint_service.ListIndexEndpointsResponse( + index_endpoints=[ + index_endpoint.IndexEndpoint(), + ], + next_page_token="ghi", + ), + index_endpoint_service.ListIndexEndpointsResponse( + index_endpoints=[ + index_endpoint.IndexEndpoint(), + index_endpoint.IndexEndpoint(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_index_endpoints( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, index_endpoint.IndexEndpoint) for i in responses) + + +@pytest.mark.asyncio +async def test_list_index_endpoints_async_pages(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_index_endpoints), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + index_endpoint_service.ListIndexEndpointsResponse( + index_endpoints=[ + index_endpoint.IndexEndpoint(), + index_endpoint.IndexEndpoint(), + index_endpoint.IndexEndpoint(), + ], + next_page_token="abc", + ), + index_endpoint_service.ListIndexEndpointsResponse( + index_endpoints=[], + next_page_token="def", + ), + index_endpoint_service.ListIndexEndpointsResponse( + index_endpoints=[ + index_endpoint.IndexEndpoint(), + ], + next_page_token="ghi", + ), + index_endpoint_service.ListIndexEndpointsResponse( + index_endpoints=[ + index_endpoint.IndexEndpoint(), + index_endpoint.IndexEndpoint(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.list_index_endpoints(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize( + "request_type", + [ + index_endpoint_service.UpdateIndexEndpointRequest, + dict, + ], +) +def test_update_index_endpoint(request_type, transport: str = "grpc"): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_index_endpoint), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gca_index_endpoint.IndexEndpoint( + name="name_value", + display_name="display_name_value", + description="description_value", + etag="etag_value", + network="network_value", + enable_private_service_connect=True, + ) + response = client.update_index_endpoint(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == index_endpoint_service.UpdateIndexEndpointRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_index_endpoint.IndexEndpoint) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.etag == "etag_value" + assert response.network == "network_value" + assert response.enable_private_service_connect is True + + +def test_update_index_endpoint_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_index_endpoint), "__call__" + ) as call: + client.update_index_endpoint() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == index_endpoint_service.UpdateIndexEndpointRequest() + + +@pytest.mark.asyncio +async def test_update_index_endpoint_async( + transport: str = "grpc_asyncio", + request_type=index_endpoint_service.UpdateIndexEndpointRequest, +): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_index_endpoint), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_index_endpoint.IndexEndpoint( + name="name_value", + display_name="display_name_value", + description="description_value", + etag="etag_value", + network="network_value", + enable_private_service_connect=True, + ) + ) + response = await client.update_index_endpoint(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == index_endpoint_service.UpdateIndexEndpointRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_index_endpoint.IndexEndpoint) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.etag == "etag_value" + assert response.network == "network_value" + assert response.enable_private_service_connect is True + + +@pytest.mark.asyncio +async def test_update_index_endpoint_async_from_dict(): + await test_update_index_endpoint_async(request_type=dict) + + +def test_update_index_endpoint_field_headers(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = index_endpoint_service.UpdateIndexEndpointRequest() + + request.index_endpoint.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_index_endpoint), "__call__" + ) as call: + call.return_value = gca_index_endpoint.IndexEndpoint() + client.update_index_endpoint(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "index_endpoint.name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_update_index_endpoint_field_headers_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = index_endpoint_service.UpdateIndexEndpointRequest() + + request.index_endpoint.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_index_endpoint), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_index_endpoint.IndexEndpoint() + ) + await client.update_index_endpoint(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "index_endpoint.name=name_value", + ) in kw["metadata"] + + +def test_update_index_endpoint_flattened(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_index_endpoint), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gca_index_endpoint.IndexEndpoint() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.update_index_endpoint( + index_endpoint=gca_index_endpoint.IndexEndpoint(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].index_endpoint + mock_val = gca_index_endpoint.IndexEndpoint(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + + +def test_update_index_endpoint_flattened_error(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_index_endpoint( + index_endpoint_service.UpdateIndexEndpointRequest(), + index_endpoint=gca_index_endpoint.IndexEndpoint(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.asyncio +async def test_update_index_endpoint_flattened_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_index_endpoint), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gca_index_endpoint.IndexEndpoint() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_index_endpoint.IndexEndpoint() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.update_index_endpoint( + index_endpoint=gca_index_endpoint.IndexEndpoint(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].index_endpoint + mock_val = gca_index_endpoint.IndexEndpoint(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_update_index_endpoint_flattened_error_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.update_index_endpoint( + index_endpoint_service.UpdateIndexEndpointRequest(), + index_endpoint=gca_index_endpoint.IndexEndpoint(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.parametrize( + "request_type", + [ + index_endpoint_service.DeleteIndexEndpointRequest, + dict, + ], +) +def test_delete_index_endpoint(request_type, transport: str = "grpc"): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_index_endpoint), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.delete_index_endpoint(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == index_endpoint_service.DeleteIndexEndpointRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_delete_index_endpoint_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_index_endpoint), "__call__" + ) as call: + client.delete_index_endpoint() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == index_endpoint_service.DeleteIndexEndpointRequest() + + +@pytest.mark.asyncio +async def test_delete_index_endpoint_async( + transport: str = "grpc_asyncio", + request_type=index_endpoint_service.DeleteIndexEndpointRequest, +): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_index_endpoint), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.delete_index_endpoint(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == index_endpoint_service.DeleteIndexEndpointRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_delete_index_endpoint_async_from_dict(): + await test_delete_index_endpoint_async(request_type=dict) + + +def test_delete_index_endpoint_field_headers(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = index_endpoint_service.DeleteIndexEndpointRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_index_endpoint), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_index_endpoint(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_index_endpoint_field_headers_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = index_endpoint_service.DeleteIndexEndpointRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_index_endpoint), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.delete_index_endpoint(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_delete_index_endpoint_flattened(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_index_endpoint), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_index_endpoint( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_delete_index_endpoint_flattened_error(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_index_endpoint( + index_endpoint_service.DeleteIndexEndpointRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_delete_index_endpoint_flattened_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_index_endpoint), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_index_endpoint( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_delete_index_endpoint_flattened_error_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.delete_index_endpoint( + index_endpoint_service.DeleteIndexEndpointRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + index_endpoint_service.DeployIndexRequest, + dict, + ], +) +def test_deploy_index(request_type, transport: str = "grpc"): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.deploy_index), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.deploy_index(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == index_endpoint_service.DeployIndexRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_deploy_index_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.deploy_index), "__call__") as call: + client.deploy_index() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == index_endpoint_service.DeployIndexRequest() + + +@pytest.mark.asyncio +async def test_deploy_index_async( + transport: str = "grpc_asyncio", + request_type=index_endpoint_service.DeployIndexRequest, +): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.deploy_index), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.deploy_index(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == index_endpoint_service.DeployIndexRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_deploy_index_async_from_dict(): + await test_deploy_index_async(request_type=dict) + + +def test_deploy_index_field_headers(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = index_endpoint_service.DeployIndexRequest() + + request.index_endpoint = "index_endpoint_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.deploy_index), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.deploy_index(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "index_endpoint=index_endpoint_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_deploy_index_field_headers_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = index_endpoint_service.DeployIndexRequest() + + request.index_endpoint = "index_endpoint_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.deploy_index), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.deploy_index(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "index_endpoint=index_endpoint_value", + ) in kw["metadata"] + + +def test_deploy_index_flattened(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.deploy_index), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.deploy_index( + index_endpoint="index_endpoint_value", + deployed_index=gca_index_endpoint.DeployedIndex(id="id_value"), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].index_endpoint + mock_val = "index_endpoint_value" + assert arg == mock_val + arg = args[0].deployed_index + mock_val = gca_index_endpoint.DeployedIndex(id="id_value") + assert arg == mock_val + + +def test_deploy_index_flattened_error(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.deploy_index( + index_endpoint_service.DeployIndexRequest(), + index_endpoint="index_endpoint_value", + deployed_index=gca_index_endpoint.DeployedIndex(id="id_value"), + ) + + +@pytest.mark.asyncio +async def test_deploy_index_flattened_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.deploy_index), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.deploy_index( + index_endpoint="index_endpoint_value", + deployed_index=gca_index_endpoint.DeployedIndex(id="id_value"), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].index_endpoint + mock_val = "index_endpoint_value" + assert arg == mock_val + arg = args[0].deployed_index + mock_val = gca_index_endpoint.DeployedIndex(id="id_value") + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_deploy_index_flattened_error_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.deploy_index( + index_endpoint_service.DeployIndexRequest(), + index_endpoint="index_endpoint_value", + deployed_index=gca_index_endpoint.DeployedIndex(id="id_value"), + ) + + +@pytest.mark.parametrize( + "request_type", + [ + index_endpoint_service.UndeployIndexRequest, + dict, + ], +) +def test_undeploy_index(request_type, transport: str = "grpc"): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.undeploy_index), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.undeploy_index(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == index_endpoint_service.UndeployIndexRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_undeploy_index_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.undeploy_index), "__call__") as call: + client.undeploy_index() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == index_endpoint_service.UndeployIndexRequest() + + +@pytest.mark.asyncio +async def test_undeploy_index_async( + transport: str = "grpc_asyncio", + request_type=index_endpoint_service.UndeployIndexRequest, +): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.undeploy_index), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.undeploy_index(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == index_endpoint_service.UndeployIndexRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_undeploy_index_async_from_dict(): + await test_undeploy_index_async(request_type=dict) + + +def test_undeploy_index_field_headers(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = index_endpoint_service.UndeployIndexRequest() + + request.index_endpoint = "index_endpoint_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.undeploy_index), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.undeploy_index(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "index_endpoint=index_endpoint_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_undeploy_index_field_headers_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = index_endpoint_service.UndeployIndexRequest() + + request.index_endpoint = "index_endpoint_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.undeploy_index), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.undeploy_index(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "index_endpoint=index_endpoint_value", + ) in kw["metadata"] + + +def test_undeploy_index_flattened(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.undeploy_index), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.undeploy_index( + index_endpoint="index_endpoint_value", + deployed_index_id="deployed_index_id_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].index_endpoint + mock_val = "index_endpoint_value" + assert arg == mock_val + arg = args[0].deployed_index_id + mock_val = "deployed_index_id_value" + assert arg == mock_val + + +def test_undeploy_index_flattened_error(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.undeploy_index( + index_endpoint_service.UndeployIndexRequest(), + index_endpoint="index_endpoint_value", + deployed_index_id="deployed_index_id_value", + ) + + +@pytest.mark.asyncio +async def test_undeploy_index_flattened_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.undeploy_index), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.undeploy_index( + index_endpoint="index_endpoint_value", + deployed_index_id="deployed_index_id_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].index_endpoint + mock_val = "index_endpoint_value" + assert arg == mock_val + arg = args[0].deployed_index_id + mock_val = "deployed_index_id_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_undeploy_index_flattened_error_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.undeploy_index( + index_endpoint_service.UndeployIndexRequest(), + index_endpoint="index_endpoint_value", + deployed_index_id="deployed_index_id_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + index_endpoint_service.MutateDeployedIndexRequest, + dict, + ], +) +def test_mutate_deployed_index(request_type, transport: str = "grpc"): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.mutate_deployed_index), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.mutate_deployed_index(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == index_endpoint_service.MutateDeployedIndexRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_mutate_deployed_index_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.mutate_deployed_index), "__call__" + ) as call: + client.mutate_deployed_index() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == index_endpoint_service.MutateDeployedIndexRequest() + + +@pytest.mark.asyncio +async def test_mutate_deployed_index_async( + transport: str = "grpc_asyncio", + request_type=index_endpoint_service.MutateDeployedIndexRequest, +): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.mutate_deployed_index), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.mutate_deployed_index(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == index_endpoint_service.MutateDeployedIndexRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_mutate_deployed_index_async_from_dict(): + await test_mutate_deployed_index_async(request_type=dict) + + +def test_mutate_deployed_index_field_headers(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = index_endpoint_service.MutateDeployedIndexRequest() + + request.index_endpoint = "index_endpoint_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.mutate_deployed_index), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.mutate_deployed_index(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "index_endpoint=index_endpoint_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_mutate_deployed_index_field_headers_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = index_endpoint_service.MutateDeployedIndexRequest() + + request.index_endpoint = "index_endpoint_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.mutate_deployed_index), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.mutate_deployed_index(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "index_endpoint=index_endpoint_value", + ) in kw["metadata"] + + +def test_mutate_deployed_index_flattened(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.mutate_deployed_index), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.mutate_deployed_index( + index_endpoint="index_endpoint_value", + deployed_index=gca_index_endpoint.DeployedIndex(id="id_value"), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].index_endpoint + mock_val = "index_endpoint_value" + assert arg == mock_val + arg = args[0].deployed_index + mock_val = gca_index_endpoint.DeployedIndex(id="id_value") + assert arg == mock_val + + +def test_mutate_deployed_index_flattened_error(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.mutate_deployed_index( + index_endpoint_service.MutateDeployedIndexRequest(), + index_endpoint="index_endpoint_value", + deployed_index=gca_index_endpoint.DeployedIndex(id="id_value"), + ) + + +@pytest.mark.asyncio +async def test_mutate_deployed_index_flattened_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.mutate_deployed_index), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.mutate_deployed_index( + index_endpoint="index_endpoint_value", + deployed_index=gca_index_endpoint.DeployedIndex(id="id_value"), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].index_endpoint + mock_val = "index_endpoint_value" + assert arg == mock_val + arg = args[0].deployed_index + mock_val = gca_index_endpoint.DeployedIndex(id="id_value") + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_mutate_deployed_index_flattened_error_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.mutate_deployed_index( + index_endpoint_service.MutateDeployedIndexRequest(), + index_endpoint="index_endpoint_value", + deployed_index=gca_index_endpoint.DeployedIndex(id="id_value"), + ) + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.IndexEndpointServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.IndexEndpointServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = IndexEndpointServiceClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide an api_key and a transport instance. + transport = transports.IndexEndpointServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = IndexEndpointServiceClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = IndexEndpointServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.IndexEndpointServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = IndexEndpointServiceClient( + client_options={"scopes": ["1", "2"]}, + transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.IndexEndpointServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + client = IndexEndpointServiceClient(transport=transport) + assert client.transport is transport + + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.IndexEndpointServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.IndexEndpointServiceGrpcAsyncIOTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.IndexEndpointServiceGrpcTransport, + transports.IndexEndpointServiceGrpcAsyncIOTransport, + ], +) +def test_transport_adc(transport_class): + # Test default credentials are used if not provided. + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class() + adc.assert_called_once() + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = IndexEndpointServiceClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + +def test_transport_grpc_default(): + # A client should use the gRPC transport by default. + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.IndexEndpointServiceGrpcTransport, + ) + + +def test_index_endpoint_service_base_transport_error(): + # Passing both a credentials object and credentials_file should raise an error + with pytest.raises(core_exceptions.DuplicateCredentialArgs): + transport = transports.IndexEndpointServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + credentials_file="credentials.json", + ) + + +def test_index_endpoint_service_base_transport(): + # Instantiate the base transport. + with mock.patch( + "google.cloud.aiplatform_v1.services.index_endpoint_service.transports.IndexEndpointServiceTransport.__init__" + ) as Transport: + Transport.return_value = None + transport = transports.IndexEndpointServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Every method on the transport should just blindly + # raise NotImplementedError. + methods = ( + "create_index_endpoint", + "get_index_endpoint", + "list_index_endpoints", + "update_index_endpoint", + "delete_index_endpoint", + "deploy_index", + "undeploy_index", + "mutate_deployed_index", + "set_iam_policy", + "get_iam_policy", + "test_iam_permissions", + "get_location", + "list_locations", + "get_operation", + "wait_operation", + "cancel_operation", + "delete_operation", + "list_operations", + ) + for method in methods: + with pytest.raises(NotImplementedError): + getattr(transport, method)(request=object()) + + with pytest.raises(NotImplementedError): + transport.close() + + # Additionally, the LRO client (a property) should + # also raise NotImplementedError + with pytest.raises(NotImplementedError): + transport.operations_client + + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + + +def test_index_endpoint_service_base_transport_with_credentials_file(): + # Instantiate the base transport with a credentials file + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch( + "google.cloud.aiplatform_v1.services.index_endpoint_service.transports.IndexEndpointServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.IndexEndpointServiceTransport( + credentials_file="credentials.json", + quota_project_id="octopus", + ) + load_creds.assert_called_once_with( + "credentials.json", + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +def test_index_endpoint_service_base_transport_with_adc(): + # Test the default credentials are used if credentials and credentials_file are None. + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( + "google.cloud.aiplatform_v1.services.index_endpoint_service.transports.IndexEndpointServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.IndexEndpointServiceTransport() + adc.assert_called_once() + + +def test_index_endpoint_service_auth_adc(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + IndexEndpointServiceClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id=None, + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.IndexEndpointServiceGrpcTransport, + transports.IndexEndpointServiceGrpcAsyncIOTransport, + ], +) +def test_index_endpoint_service_transport_auth_adc(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.IndexEndpointServiceGrpcTransport, grpc_helpers), + (transports.IndexEndpointServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +def test_index_endpoint_service_transport_create_channel(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=["1", "2"], + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.IndexEndpointServiceGrpcTransport, + transports.IndexEndpointServiceGrpcAsyncIOTransport, + ], +) +def test_index_endpoint_service_grpc_transport_client_cert_source_for_mtls( + transport_class, +): + cred = ga_credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds, + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback, + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, private_key=expected_key + ) + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_index_endpoint_service_host_no_port(transport_name): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions( + api_endpoint="aiplatform.googleapis.com" + ), + transport=transport_name, + ) + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_index_endpoint_service_host_with_port(transport_name): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions( + api_endpoint="aiplatform.googleapis.com:8000" + ), + transport=transport_name, + ) + assert client.transport._host == ("aiplatform.googleapis.com:8000") + + +def test_index_endpoint_service_grpc_transport_channel(): + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.IndexEndpointServiceGrpcTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +def test_index_endpoint_service_grpc_asyncio_transport_channel(): + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.IndexEndpointServiceGrpcAsyncIOTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize( + "transport_class", + [ + transports.IndexEndpointServiceGrpcTransport, + transports.IndexEndpointServiceGrpcAsyncIOTransport, + ], +) +def test_index_endpoint_service_transport_channel_mtls_with_client_cert_source( + transport_class, +): + with mock.patch( + "grpc.ssl_channel_credentials", autospec=True + ) as grpc_ssl_channel_cred: + with mock.patch.object( + transport_class, "create_channel" + ) as grpc_create_channel: + mock_ssl_cred = mock.Mock() + grpc_ssl_channel_cred.return_value = mock_ssl_cred + + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + + cred = ga_credentials.AnonymousCredentials() + with pytest.warns(DeprecationWarning): + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (cred, None) + transport = transport_class( + host="squid.clam.whelk", + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=client_cert_source_callback, + ) + adc.assert_called_once() + + grpc_ssl_channel_cred.assert_called_once_with( + certificate_chain=b"cert bytes", private_key=b"key bytes" + ) + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize( + "transport_class", + [ + transports.IndexEndpointServiceGrpcTransport, + transports.IndexEndpointServiceGrpcAsyncIOTransport, + ], +) +def test_index_endpoint_service_transport_channel_mtls_with_adc(transport_class): + mock_ssl_cred = mock.Mock() + with mock.patch.multiple( + "google.auth.transport.grpc.SslCredentials", + __init__=mock.Mock(return_value=None), + ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), + ): + with mock.patch.object( + transport_class, "create_channel" + ) as grpc_create_channel: + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + mock_cred = mock.Mock() + + with pytest.warns(DeprecationWarning): + transport = transport_class( + host="squid.clam.whelk", + credentials=mock_cred, + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=None, + ) + + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=mock_cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + + +def test_index_endpoint_service_grpc_lro_client(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_index_endpoint_service_grpc_lro_async_client(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_index_path(): + project = "squid" + location = "clam" + index = "whelk" + expected = "projects/{project}/locations/{location}/indexes/{index}".format( + project=project, + location=location, + index=index, + ) + actual = IndexEndpointServiceClient.index_path(project, location, index) + assert expected == actual + + +def test_parse_index_path(): + expected = { + "project": "octopus", + "location": "oyster", + "index": "nudibranch", + } + path = IndexEndpointServiceClient.index_path(**expected) + + # Check that the path construction is reversible. + actual = IndexEndpointServiceClient.parse_index_path(path) + assert expected == actual + + +def test_index_endpoint_path(): + project = "cuttlefish" + location = "mussel" + index_endpoint = "winkle" + expected = "projects/{project}/locations/{location}/indexEndpoints/{index_endpoint}".format( + project=project, + location=location, + index_endpoint=index_endpoint, + ) + actual = IndexEndpointServiceClient.index_endpoint_path( + project, location, index_endpoint + ) + assert expected == actual + + +def test_parse_index_endpoint_path(): + expected = { + "project": "nautilus", + "location": "scallop", + "index_endpoint": "abalone", + } + path = IndexEndpointServiceClient.index_endpoint_path(**expected) + + # Check that the path construction is reversible. + actual = IndexEndpointServiceClient.parse_index_endpoint_path(path) + assert expected == actual + + +def test_common_billing_account_path(): + billing_account = "squid" + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + actual = IndexEndpointServiceClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "clam", + } + path = IndexEndpointServiceClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = IndexEndpointServiceClient.parse_common_billing_account_path(path) + assert expected == actual + + +def test_common_folder_path(): + folder = "whelk" + expected = "folders/{folder}".format( + folder=folder, + ) + actual = IndexEndpointServiceClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "octopus", + } + path = IndexEndpointServiceClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = IndexEndpointServiceClient.parse_common_folder_path(path) + assert expected == actual + + +def test_common_organization_path(): + organization = "oyster" + expected = "organizations/{organization}".format( + organization=organization, + ) + actual = IndexEndpointServiceClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "nudibranch", + } + path = IndexEndpointServiceClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = IndexEndpointServiceClient.parse_common_organization_path(path) + assert expected == actual + + +def test_common_project_path(): + project = "cuttlefish" + expected = "projects/{project}".format( + project=project, + ) + actual = IndexEndpointServiceClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "mussel", + } + path = IndexEndpointServiceClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = IndexEndpointServiceClient.parse_common_project_path(path) + assert expected == actual + + +def test_common_location_path(): + project = "winkle" + location = "nautilus" + expected = "projects/{project}/locations/{location}".format( + project=project, + location=location, + ) + actual = IndexEndpointServiceClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "scallop", + "location": "abalone", + } + path = IndexEndpointServiceClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = IndexEndpointServiceClient.parse_common_location_path(path) + assert expected == actual + + +def test_client_with_default_client_info(): + client_info = gapic_v1.client_info.ClientInfo() + + with mock.patch.object( + transports.IndexEndpointServiceTransport, "_prep_wrapped_messages" + ) as prep: + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + with mock.patch.object( + transports.IndexEndpointServiceTransport, "_prep_wrapped_messages" + ) as prep: + transport_class = IndexEndpointServiceClient.get_transport_class() + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_delete_operation(transport: str = "grpc"): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_operation(transport: str = "grpc"): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_operation_field_headers(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = None + + client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_operation_field_headers_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_delete_operation_from_dict(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_delete_operation_from_dict_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_cancel_operation(transport: str = "grpc"): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation(transport: str = "grpc"): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_wait_operation(transport: str = "grpc"): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_wait_operation(transport: str = "grpc"): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_wait_operation_field_headers(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_wait_operation_field_headers_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_wait_operation_from_dict(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_wait_operation_from_dict_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_operation(transport: str = "grpc"): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_get_operation(transport: str = "grpc"): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_get_operation_field_headers(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_get_operation_from_dict(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_operations(transport: str = "grpc"): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + response = client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +@pytest.mark.asyncio +async def test_list_operations(transport: str = "grpc"): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +def test_list_operations_field_headers(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_operations_field_headers_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_operations_from_dict(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + response = client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_operations_from_dict_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_locations(transport: str = "grpc"): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + response = client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +@pytest.mark.asyncio +async def test_list_locations(transport: str = "grpc"): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +def test_list_locations_field_headers(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_locations_field_headers_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_locations_from_dict(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + response = client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_locations_from_dict_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_location(transport: str = "grpc"): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + response = client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +@pytest.mark.asyncio +async def test_get_location_async(transport: str = "grpc_asyncio"): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +def test_get_location_field_headers(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials() + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = locations_pb2.Location() + + client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_location_field_headers_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials() + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +def test_get_location_from_dict(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + response = client.get_location( + request={ + "name": "locations/abc", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_location_from_dict_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_set_iam_policy(transport: str = "grpc"): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + response = client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + response = await client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_set_iam_policy_field_headers(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_set_iam_policy_field_headers_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_set_iam_policy_from_dict(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_set_iam_policy_from_dict_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +def test_get_iam_policy(transport: str = "grpc"): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + + response = client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + + response = await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_get_iam_policy_field_headers(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_iam_policy_field_headers_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_get_iam_policy_from_dict(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_iam_policy_from_dict_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +def test_test_iam_permissions(transport: str = "grpc"): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + + response = client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + ) + + response = await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +def test_test_iam_permissions_field_headers(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_field_headers_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_test_iam_permissions_from_dict(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + response = client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_from_dict_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + response = await client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (IndexEndpointServiceClient, transports.IndexEndpointServiceGrpcTransport), + ( + IndexEndpointServiceAsyncClient, + transports.IndexEndpointServiceGrpcAsyncIOTransport, + ), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) diff --git a/tests/unit/gapic/aiplatform_v1/test_index_service.py b/tests/unit/gapic/aiplatform_v1/test_index_service.py new file mode 100644 index 0000000000..21a3ae8f91 --- /dev/null +++ b/tests/unit/gapic/aiplatform_v1/test_index_service.py @@ -0,0 +1,4281 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import os + +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock +except ImportError: + import mock + +import grpc +from grpc.experimental import aio +import math +import pytest +from proto.marshal.rules.dates import DurationRule, TimestampRule + + +from google.api_core import client_options +from google.api_core import exceptions as core_exceptions +from google.api_core import future +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers +from google.api_core import grpc_helpers_async +from google.api_core import operation +from google.api_core import operation_async # type: ignore +from google.api_core import operations_v1 +from google.api_core import path_template +from google.auth import credentials as ga_credentials +from google.auth.exceptions import MutualTLSChannelError +from google.cloud.aiplatform_v1.services.index_service import IndexServiceAsyncClient +from google.cloud.aiplatform_v1.services.index_service import IndexServiceClient +from google.cloud.aiplatform_v1.services.index_service import pagers +from google.cloud.aiplatform_v1.services.index_service import transports +from google.cloud.aiplatform_v1.types import deployed_index_ref +from google.cloud.aiplatform_v1.types import index +from google.cloud.aiplatform_v1.types import index as gca_index +from google.cloud.aiplatform_v1.types import index_service +from google.cloud.aiplatform_v1.types import operation as gca_operation +from google.cloud.location import locations_pb2 +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.oauth2 import service_account +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import struct_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +import google.auth + + +def client_cert_source_callback(): + return b"cert bytes", b"key bytes" + + +# If default endpoint is localhost, then default mtls endpoint will be the same. +# This method modifies the default endpoint so the client can produce a different +# mtls endpoint for endpoint testing purposes. +def modify_default_endpoint(client): + return ( + "foo.googleapis.com" + if ("localhost" in client.DEFAULT_ENDPOINT) + else client.DEFAULT_ENDPOINT + ) + + +def test__get_default_mtls_endpoint(): + api_endpoint = "example.googleapis.com" + api_mtls_endpoint = "example.mtls.googleapis.com" + sandbox_endpoint = "example.sandbox.googleapis.com" + sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" + non_googleapi = "api.example.com" + + assert IndexServiceClient._get_default_mtls_endpoint(None) is None + assert ( + IndexServiceClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint + ) + assert ( + IndexServiceClient._get_default_mtls_endpoint(api_mtls_endpoint) + == api_mtls_endpoint + ) + assert ( + IndexServiceClient._get_default_mtls_endpoint(sandbox_endpoint) + == sandbox_mtls_endpoint + ) + assert ( + IndexServiceClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) + == sandbox_mtls_endpoint + ) + assert IndexServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + + +@pytest.mark.parametrize( + "client_class,transport_name", + [ + (IndexServiceClient, "grpc"), + (IndexServiceAsyncClient, "grpc_asyncio"), + ], +) +def test_index_service_client_from_service_account_info(client_class, transport_name): + creds = ga_credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_info" + ) as factory: + factory.return_value = creds + info = {"valid": True} + client = client_class.from_service_account_info(info, transport=transport_name) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.IndexServiceGrpcTransport, "grpc"), + (transports.IndexServiceGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_index_service_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + +@pytest.mark.parametrize( + "client_class,transport_name", + [ + (IndexServiceClient, "grpc"), + (IndexServiceAsyncClient, "grpc_asyncio"), + ], +) +def test_index_service_client_from_service_account_file(client_class, transport_name): + creds = ga_credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_file" + ) as factory: + factory.return_value = creds + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +def test_index_service_client_get_transport_class(): + transport = IndexServiceClient.get_transport_class() + available_transports = [ + transports.IndexServiceGrpcTransport, + ] + assert transport in available_transports + + transport = IndexServiceClient.get_transport_class("grpc") + assert transport == transports.IndexServiceGrpcTransport + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (IndexServiceClient, transports.IndexServiceGrpcTransport, "grpc"), + ( + IndexServiceAsyncClient, + transports.IndexServiceGrpcAsyncIOTransport, + "grpc_asyncio", + ), + ], +) +@mock.patch.object( + IndexServiceClient, "DEFAULT_ENDPOINT", modify_default_endpoint(IndexServiceClient) +) +@mock.patch.object( + IndexServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(IndexServiceAsyncClient), +) +def test_index_service_client_client_options( + client_class, transport_class, transport_name +): + # Check that if channel is provided we won't create a new one. + with mock.patch.object(IndexServiceClient, "get_transport_class") as gtc: + transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + client = client_class(transport=transport) + gtc.assert_not_called() + + # Check that if channel is provided via str we will create a new one. + with mock.patch.object(IndexServiceClient, "get_transport_class") as gtc: + client = client_class(transport=transport_name) + gtc.assert_called() + + # Check the case api_endpoint is provided. + options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(transport=transport_name, client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is + # "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is + # "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_MTLS_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has + # unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError): + client = client_class(transport=transport_name) + + # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError): + client = client_class(transport=transport_name) + + # Check the case quota_project_id is provided + options = client_options.ClientOptions(quota_project_id="octopus") + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id="octopus", + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,use_client_cert_env", + [ + (IndexServiceClient, transports.IndexServiceGrpcTransport, "grpc", "true"), + ( + IndexServiceAsyncClient, + transports.IndexServiceGrpcAsyncIOTransport, + "grpc_asyncio", + "true", + ), + (IndexServiceClient, transports.IndexServiceGrpcTransport, "grpc", "false"), + ( + IndexServiceAsyncClient, + transports.IndexServiceGrpcAsyncIOTransport, + "grpc_asyncio", + "false", + ), + ], +) +@mock.patch.object( + IndexServiceClient, "DEFAULT_ENDPOINT", modify_default_endpoint(IndexServiceClient) +) +@mock.patch.object( + IndexServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(IndexServiceAsyncClient), +) +@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) +def test_index_service_client_mtls_env_auto( + client_class, transport_class, transport_name, use_client_cert_env +): + # This tests the endpoint autoswitch behavior. Endpoint is autoswitched to the default + # mtls endpoint, if GOOGLE_API_USE_CLIENT_CERTIFICATE is "true" and client cert exists. + + # Check the case client_cert_source is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + options = client_options.ClientOptions( + client_cert_source=client_cert_source_callback + ) + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client.DEFAULT_ENDPOINT + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT + + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # Check the case ADC client cert is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=client_cert_source_callback, + ): + if use_client_cert_env == "false": + expected_host = client.DEFAULT_ENDPOINT + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback + + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + +@pytest.mark.parametrize("client_class", [IndexServiceClient, IndexServiceAsyncClient]) +@mock.patch.object( + IndexServiceClient, "DEFAULT_ENDPOINT", modify_default_endpoint(IndexServiceClient) +) +@mock.patch.object( + IndexServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(IndexServiceAsyncClient), +) +def test_index_service_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (IndexServiceClient, transports.IndexServiceGrpcTransport, "grpc"), + ( + IndexServiceAsyncClient, + transports.IndexServiceGrpcAsyncIOTransport, + "grpc_asyncio", + ), + ], +) +def test_index_service_client_client_options_scopes( + client_class, transport_class, transport_name +): + # Check the case scopes are provided. + options = client_options.ClientOptions( + scopes=["1", "2"], + ) + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=["1", "2"], + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + IndexServiceClient, + transports.IndexServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + IndexServiceAsyncClient, + transports.IndexServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_index_service_client_client_options_credentials_file( + client_class, transport_class, transport_name, grpc_helpers +): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + +def test_index_service_client_client_options_from_dict(): + with mock.patch( + "google.cloud.aiplatform_v1.services.index_service.transports.IndexServiceGrpcTransport.__init__" + ) as grpc_transport: + grpc_transport.return_value = None + client = IndexServiceClient(client_options={"api_endpoint": "squid.clam.whelk"}) + grpc_transport.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + IndexServiceClient, + transports.IndexServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + IndexServiceAsyncClient, + transports.IndexServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_index_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers +): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + index_service.CreateIndexRequest, + dict, + ], +) +def test_create_index(request_type, transport: str = "grpc"): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_index), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.create_index(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == index_service.CreateIndexRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_create_index_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_index), "__call__") as call: + client.create_index() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == index_service.CreateIndexRequest() + + +@pytest.mark.asyncio +async def test_create_index_async( + transport: str = "grpc_asyncio", request_type=index_service.CreateIndexRequest +): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_index), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.create_index(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == index_service.CreateIndexRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_create_index_async_from_dict(): + await test_create_index_async(request_type=dict) + + +def test_create_index_field_headers(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = index_service.CreateIndexRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_index), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.create_index(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_create_index_field_headers_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = index_service.CreateIndexRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_index), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.create_index(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_create_index_flattened(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_index), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_index( + parent="parent_value", + index=gca_index.Index(name="name_value"), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].index + mock_val = gca_index.Index(name="name_value") + assert arg == mock_val + + +def test_create_index_flattened_error(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_index( + index_service.CreateIndexRequest(), + parent="parent_value", + index=gca_index.Index(name="name_value"), + ) + + +@pytest.mark.asyncio +async def test_create_index_flattened_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_index), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_index( + parent="parent_value", + index=gca_index.Index(name="name_value"), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].index + mock_val = gca_index.Index(name="name_value") + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_create_index_flattened_error_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.create_index( + index_service.CreateIndexRequest(), + parent="parent_value", + index=gca_index.Index(name="name_value"), + ) + + +@pytest.mark.parametrize( + "request_type", + [ + index_service.GetIndexRequest, + dict, + ], +) +def test_get_index(request_type, transport: str = "grpc"): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_index), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = index.Index( + name="name_value", + display_name="display_name_value", + description="description_value", + metadata_schema_uri="metadata_schema_uri_value", + etag="etag_value", + ) + response = client.get_index(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == index_service.GetIndexRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, index.Index) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.metadata_schema_uri == "metadata_schema_uri_value" + assert response.etag == "etag_value" + + +def test_get_index_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_index), "__call__") as call: + client.get_index() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == index_service.GetIndexRequest() + + +@pytest.mark.asyncio +async def test_get_index_async( + transport: str = "grpc_asyncio", request_type=index_service.GetIndexRequest +): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_index), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + index.Index( + name="name_value", + display_name="display_name_value", + description="description_value", + metadata_schema_uri="metadata_schema_uri_value", + etag="etag_value", + ) + ) + response = await client.get_index(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == index_service.GetIndexRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, index.Index) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.metadata_schema_uri == "metadata_schema_uri_value" + assert response.etag == "etag_value" + + +@pytest.mark.asyncio +async def test_get_index_async_from_dict(): + await test_get_index_async(request_type=dict) + + +def test_get_index_field_headers(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = index_service.GetIndexRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_index), "__call__") as call: + call.return_value = index.Index() + client.get_index(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_index_field_headers_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = index_service.GetIndexRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_index), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(index.Index()) + await client.get_index(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_get_index_flattened(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_index), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = index.Index() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_index( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_get_index_flattened_error(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_index( + index_service.GetIndexRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_index_flattened_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_index), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = index.Index() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(index.Index()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_index( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_get_index_flattened_error_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_index( + index_service.GetIndexRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + index_service.ListIndexesRequest, + dict, + ], +) +def test_list_indexes(request_type, transport: str = "grpc"): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_indexes), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = index_service.ListIndexesResponse( + next_page_token="next_page_token_value", + ) + response = client.list_indexes(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == index_service.ListIndexesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListIndexesPager) + assert response.next_page_token == "next_page_token_value" + + +def test_list_indexes_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_indexes), "__call__") as call: + client.list_indexes() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == index_service.ListIndexesRequest() + + +@pytest.mark.asyncio +async def test_list_indexes_async( + transport: str = "grpc_asyncio", request_type=index_service.ListIndexesRequest +): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_indexes), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + index_service.ListIndexesResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.list_indexes(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == index_service.ListIndexesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListIndexesAsyncPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_list_indexes_async_from_dict(): + await test_list_indexes_async(request_type=dict) + + +def test_list_indexes_field_headers(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = index_service.ListIndexesRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_indexes), "__call__") as call: + call.return_value = index_service.ListIndexesResponse() + client.list_indexes(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_indexes_field_headers_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = index_service.ListIndexesRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_indexes), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + index_service.ListIndexesResponse() + ) + await client.list_indexes(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_list_indexes_flattened(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_indexes), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = index_service.ListIndexesResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_indexes( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +def test_list_indexes_flattened_error(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_indexes( + index_service.ListIndexesRequest(), + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_indexes_flattened_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_indexes), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = index_service.ListIndexesResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + index_service.ListIndexesResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_indexes( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_list_indexes_flattened_error_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_indexes( + index_service.ListIndexesRequest(), + parent="parent_value", + ) + + +def test_list_indexes_pager(transport_name: str = "grpc"): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_indexes), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + index_service.ListIndexesResponse( + indexes=[ + index.Index(), + index.Index(), + index.Index(), + ], + next_page_token="abc", + ), + index_service.ListIndexesResponse( + indexes=[], + next_page_token="def", + ), + index_service.ListIndexesResponse( + indexes=[ + index.Index(), + ], + next_page_token="ghi", + ), + index_service.ListIndexesResponse( + indexes=[ + index.Index(), + index.Index(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_indexes(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, index.Index) for i in results) + + +def test_list_indexes_pages(transport_name: str = "grpc"): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_indexes), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + index_service.ListIndexesResponse( + indexes=[ + index.Index(), + index.Index(), + index.Index(), + ], + next_page_token="abc", + ), + index_service.ListIndexesResponse( + indexes=[], + next_page_token="def", + ), + index_service.ListIndexesResponse( + indexes=[ + index.Index(), + ], + next_page_token="ghi", + ), + index_service.ListIndexesResponse( + indexes=[ + index.Index(), + index.Index(), + ], + ), + RuntimeError, + ) + pages = list(client.list_indexes(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.asyncio +async def test_list_indexes_async_pager(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_indexes), "__call__", new_callable=mock.AsyncMock + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + index_service.ListIndexesResponse( + indexes=[ + index.Index(), + index.Index(), + index.Index(), + ], + next_page_token="abc", + ), + index_service.ListIndexesResponse( + indexes=[], + next_page_token="def", + ), + index_service.ListIndexesResponse( + indexes=[ + index.Index(), + ], + next_page_token="ghi", + ), + index_service.ListIndexesResponse( + indexes=[ + index.Index(), + index.Index(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_indexes( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, index.Index) for i in responses) + + +@pytest.mark.asyncio +async def test_list_indexes_async_pages(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_indexes), "__call__", new_callable=mock.AsyncMock + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + index_service.ListIndexesResponse( + indexes=[ + index.Index(), + index.Index(), + index.Index(), + ], + next_page_token="abc", + ), + index_service.ListIndexesResponse( + indexes=[], + next_page_token="def", + ), + index_service.ListIndexesResponse( + indexes=[ + index.Index(), + ], + next_page_token="ghi", + ), + index_service.ListIndexesResponse( + indexes=[ + index.Index(), + index.Index(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.list_indexes(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize( + "request_type", + [ + index_service.UpdateIndexRequest, + dict, + ], +) +def test_update_index(request_type, transport: str = "grpc"): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_index), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.update_index(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == index_service.UpdateIndexRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_update_index_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_index), "__call__") as call: + client.update_index() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == index_service.UpdateIndexRequest() + + +@pytest.mark.asyncio +async def test_update_index_async( + transport: str = "grpc_asyncio", request_type=index_service.UpdateIndexRequest +): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_index), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.update_index(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == index_service.UpdateIndexRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_update_index_async_from_dict(): + await test_update_index_async(request_type=dict) + + +def test_update_index_field_headers(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = index_service.UpdateIndexRequest() + + request.index.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_index), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.update_index(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "index.name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_update_index_field_headers_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = index_service.UpdateIndexRequest() + + request.index.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_index), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.update_index(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "index.name=name_value", + ) in kw["metadata"] + + +def test_update_index_flattened(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_index), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.update_index( + index=gca_index.Index(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].index + mock_val = gca_index.Index(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + + +def test_update_index_flattened_error(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_index( + index_service.UpdateIndexRequest(), + index=gca_index.Index(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.asyncio +async def test_update_index_flattened_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_index), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.update_index( + index=gca_index.Index(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].index + mock_val = gca_index.Index(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_update_index_flattened_error_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.update_index( + index_service.UpdateIndexRequest(), + index=gca_index.Index(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.parametrize( + "request_type", + [ + index_service.DeleteIndexRequest, + dict, + ], +) +def test_delete_index(request_type, transport: str = "grpc"): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_index), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.delete_index(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == index_service.DeleteIndexRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_delete_index_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_index), "__call__") as call: + client.delete_index() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == index_service.DeleteIndexRequest() + + +@pytest.mark.asyncio +async def test_delete_index_async( + transport: str = "grpc_asyncio", request_type=index_service.DeleteIndexRequest +): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_index), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.delete_index(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == index_service.DeleteIndexRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_delete_index_async_from_dict(): + await test_delete_index_async(request_type=dict) + + +def test_delete_index_field_headers(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = index_service.DeleteIndexRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_index), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_index(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_index_field_headers_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = index_service.DeleteIndexRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_index), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.delete_index(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_delete_index_flattened(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_index), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_index( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_delete_index_flattened_error(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_index( + index_service.DeleteIndexRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_delete_index_flattened_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_index), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_index( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_delete_index_flattened_error_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.delete_index( + index_service.DeleteIndexRequest(), + name="name_value", + ) + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.IndexServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.IndexServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = IndexServiceClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide an api_key and a transport instance. + transport = transports.IndexServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = IndexServiceClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = IndexServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.IndexServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = IndexServiceClient( + client_options={"scopes": ["1", "2"]}, + transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.IndexServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + client = IndexServiceClient(transport=transport) + assert client.transport is transport + + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.IndexServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.IndexServiceGrpcAsyncIOTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.IndexServiceGrpcTransport, + transports.IndexServiceGrpcAsyncIOTransport, + ], +) +def test_transport_adc(transport_class): + # Test default credentials are used if not provided. + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class() + adc.assert_called_once() + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = IndexServiceClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + +def test_transport_grpc_default(): + # A client should use the gRPC transport by default. + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.IndexServiceGrpcTransport, + ) + + +def test_index_service_base_transport_error(): + # Passing both a credentials object and credentials_file should raise an error + with pytest.raises(core_exceptions.DuplicateCredentialArgs): + transport = transports.IndexServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + credentials_file="credentials.json", + ) + + +def test_index_service_base_transport(): + # Instantiate the base transport. + with mock.patch( + "google.cloud.aiplatform_v1.services.index_service.transports.IndexServiceTransport.__init__" + ) as Transport: + Transport.return_value = None + transport = transports.IndexServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Every method on the transport should just blindly + # raise NotImplementedError. + methods = ( + "create_index", + "get_index", + "list_indexes", + "update_index", + "delete_index", + "set_iam_policy", + "get_iam_policy", + "test_iam_permissions", + "get_location", + "list_locations", + "get_operation", + "wait_operation", + "cancel_operation", + "delete_operation", + "list_operations", + ) + for method in methods: + with pytest.raises(NotImplementedError): + getattr(transport, method)(request=object()) + + with pytest.raises(NotImplementedError): + transport.close() + + # Additionally, the LRO client (a property) should + # also raise NotImplementedError + with pytest.raises(NotImplementedError): + transport.operations_client + + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + + +def test_index_service_base_transport_with_credentials_file(): + # Instantiate the base transport with a credentials file + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch( + "google.cloud.aiplatform_v1.services.index_service.transports.IndexServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.IndexServiceTransport( + credentials_file="credentials.json", + quota_project_id="octopus", + ) + load_creds.assert_called_once_with( + "credentials.json", + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +def test_index_service_base_transport_with_adc(): + # Test the default credentials are used if credentials and credentials_file are None. + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( + "google.cloud.aiplatform_v1.services.index_service.transports.IndexServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.IndexServiceTransport() + adc.assert_called_once() + + +def test_index_service_auth_adc(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + IndexServiceClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id=None, + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.IndexServiceGrpcTransport, + transports.IndexServiceGrpcAsyncIOTransport, + ], +) +def test_index_service_transport_auth_adc(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.IndexServiceGrpcTransport, grpc_helpers), + (transports.IndexServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +def test_index_service_transport_create_channel(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=["1", "2"], + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class", + [transports.IndexServiceGrpcTransport, transports.IndexServiceGrpcAsyncIOTransport], +) +def test_index_service_grpc_transport_client_cert_source_for_mtls(transport_class): + cred = ga_credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds, + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback, + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, private_key=expected_key + ) + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_index_service_host_no_port(transport_name): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions( + api_endpoint="aiplatform.googleapis.com" + ), + transport=transport_name, + ) + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_index_service_host_with_port(transport_name): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions( + api_endpoint="aiplatform.googleapis.com:8000" + ), + transport=transport_name, + ) + assert client.transport._host == ("aiplatform.googleapis.com:8000") + + +def test_index_service_grpc_transport_channel(): + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.IndexServiceGrpcTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +def test_index_service_grpc_asyncio_transport_channel(): + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.IndexServiceGrpcAsyncIOTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize( + "transport_class", + [transports.IndexServiceGrpcTransport, transports.IndexServiceGrpcAsyncIOTransport], +) +def test_index_service_transport_channel_mtls_with_client_cert_source(transport_class): + with mock.patch( + "grpc.ssl_channel_credentials", autospec=True + ) as grpc_ssl_channel_cred: + with mock.patch.object( + transport_class, "create_channel" + ) as grpc_create_channel: + mock_ssl_cred = mock.Mock() + grpc_ssl_channel_cred.return_value = mock_ssl_cred + + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + + cred = ga_credentials.AnonymousCredentials() + with pytest.warns(DeprecationWarning): + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (cred, None) + transport = transport_class( + host="squid.clam.whelk", + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=client_cert_source_callback, + ) + adc.assert_called_once() + + grpc_ssl_channel_cred.assert_called_once_with( + certificate_chain=b"cert bytes", private_key=b"key bytes" + ) + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize( + "transport_class", + [transports.IndexServiceGrpcTransport, transports.IndexServiceGrpcAsyncIOTransport], +) +def test_index_service_transport_channel_mtls_with_adc(transport_class): + mock_ssl_cred = mock.Mock() + with mock.patch.multiple( + "google.auth.transport.grpc.SslCredentials", + __init__=mock.Mock(return_value=None), + ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), + ): + with mock.patch.object( + transport_class, "create_channel" + ) as grpc_create_channel: + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + mock_cred = mock.Mock() + + with pytest.warns(DeprecationWarning): + transport = transport_class( + host="squid.clam.whelk", + credentials=mock_cred, + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=None, + ) + + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=mock_cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + + +def test_index_service_grpc_lro_client(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_index_service_grpc_lro_async_client(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_index_path(): + project = "squid" + location = "clam" + index = "whelk" + expected = "projects/{project}/locations/{location}/indexes/{index}".format( + project=project, + location=location, + index=index, + ) + actual = IndexServiceClient.index_path(project, location, index) + assert expected == actual + + +def test_parse_index_path(): + expected = { + "project": "octopus", + "location": "oyster", + "index": "nudibranch", + } + path = IndexServiceClient.index_path(**expected) + + # Check that the path construction is reversible. + actual = IndexServiceClient.parse_index_path(path) + assert expected == actual + + +def test_index_endpoint_path(): + project = "cuttlefish" + location = "mussel" + index_endpoint = "winkle" + expected = "projects/{project}/locations/{location}/indexEndpoints/{index_endpoint}".format( + project=project, + location=location, + index_endpoint=index_endpoint, + ) + actual = IndexServiceClient.index_endpoint_path(project, location, index_endpoint) + assert expected == actual + + +def test_parse_index_endpoint_path(): + expected = { + "project": "nautilus", + "location": "scallop", + "index_endpoint": "abalone", + } + path = IndexServiceClient.index_endpoint_path(**expected) + + # Check that the path construction is reversible. + actual = IndexServiceClient.parse_index_endpoint_path(path) + assert expected == actual + + +def test_common_billing_account_path(): + billing_account = "squid" + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + actual = IndexServiceClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "clam", + } + path = IndexServiceClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = IndexServiceClient.parse_common_billing_account_path(path) + assert expected == actual + + +def test_common_folder_path(): + folder = "whelk" + expected = "folders/{folder}".format( + folder=folder, + ) + actual = IndexServiceClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "octopus", + } + path = IndexServiceClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = IndexServiceClient.parse_common_folder_path(path) + assert expected == actual + + +def test_common_organization_path(): + organization = "oyster" + expected = "organizations/{organization}".format( + organization=organization, + ) + actual = IndexServiceClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "nudibranch", + } + path = IndexServiceClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = IndexServiceClient.parse_common_organization_path(path) + assert expected == actual + + +def test_common_project_path(): + project = "cuttlefish" + expected = "projects/{project}".format( + project=project, + ) + actual = IndexServiceClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "mussel", + } + path = IndexServiceClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = IndexServiceClient.parse_common_project_path(path) + assert expected == actual + + +def test_common_location_path(): + project = "winkle" + location = "nautilus" + expected = "projects/{project}/locations/{location}".format( + project=project, + location=location, + ) + actual = IndexServiceClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "scallop", + "location": "abalone", + } + path = IndexServiceClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = IndexServiceClient.parse_common_location_path(path) + assert expected == actual + + +def test_client_with_default_client_info(): + client_info = gapic_v1.client_info.ClientInfo() + + with mock.patch.object( + transports.IndexServiceTransport, "_prep_wrapped_messages" + ) as prep: + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + with mock.patch.object( + transports.IndexServiceTransport, "_prep_wrapped_messages" + ) as prep: + transport_class = IndexServiceClient.get_transport_class() + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_delete_operation(transport: str = "grpc"): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_operation(transport: str = "grpc"): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_operation_field_headers(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = None + + client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_operation_field_headers_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_delete_operation_from_dict(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_delete_operation_from_dict_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_cancel_operation(transport: str = "grpc"): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation(transport: str = "grpc"): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_wait_operation(transport: str = "grpc"): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_wait_operation(transport: str = "grpc"): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_wait_operation_field_headers(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_wait_operation_field_headers_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_wait_operation_from_dict(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_wait_operation_from_dict_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_operation(transport: str = "grpc"): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_get_operation(transport: str = "grpc"): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_get_operation_field_headers(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_get_operation_from_dict(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_operations(transport: str = "grpc"): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + response = client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +@pytest.mark.asyncio +async def test_list_operations(transport: str = "grpc"): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +def test_list_operations_field_headers(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_operations_field_headers_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_operations_from_dict(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + response = client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_operations_from_dict_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_locations(transport: str = "grpc"): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + response = client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +@pytest.mark.asyncio +async def test_list_locations(transport: str = "grpc"): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +def test_list_locations_field_headers(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_locations_field_headers_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_locations_from_dict(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + response = client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_locations_from_dict_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_location(transport: str = "grpc"): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + response = client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +@pytest.mark.asyncio +async def test_get_location_async(transport: str = "grpc_asyncio"): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +def test_get_location_field_headers(): + client = IndexServiceClient(credentials=ga_credentials.AnonymousCredentials()) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = locations_pb2.Location() + + client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_location_field_headers_async(): + client = IndexServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials()) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +def test_get_location_from_dict(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + response = client.get_location( + request={ + "name": "locations/abc", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_location_from_dict_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_set_iam_policy(transport: str = "grpc"): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + response = client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + response = await client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_set_iam_policy_field_headers(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_set_iam_policy_field_headers_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_set_iam_policy_from_dict(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_set_iam_policy_from_dict_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +def test_get_iam_policy(transport: str = "grpc"): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + + response = client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + + response = await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_get_iam_policy_field_headers(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_iam_policy_field_headers_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_get_iam_policy_from_dict(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_iam_policy_from_dict_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +def test_test_iam_permissions(transport: str = "grpc"): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + + response = client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + ) + + response = await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +def test_test_iam_permissions_field_headers(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_field_headers_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_test_iam_permissions_from_dict(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + response = client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_from_dict_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + response = await client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (IndexServiceClient, transports.IndexServiceGrpcTransport), + (IndexServiceAsyncClient, transports.IndexServiceGrpcAsyncIOTransport), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) diff --git a/tests/unit/gapic/aiplatform_v1/test_job_service.py b/tests/unit/gapic/aiplatform_v1/test_job_service.py index 3c490870e9..9c7dbfb2d3 100644 --- a/tests/unit/gapic/aiplatform_v1/test_job_service.py +++ b/tests/unit/gapic/aiplatform_v1/test_job_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,8 +14,13 @@ # limitations under the License. # import os -import mock -import packaging.version + +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock +except ImportError: + import mock import grpc from grpc.experimental import aio @@ -30,20 +35,16 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.aiplatform_v1.services.job_service import JobServiceAsyncClient from google.cloud.aiplatform_v1.services.job_service import JobServiceClient from google.cloud.aiplatform_v1.services.job_service import pagers from google.cloud.aiplatform_v1.services.job_service import transports -from google.cloud.aiplatform_v1.services.job_service.transports.base import ( - _API_CORE_VERSION, -) -from google.cloud.aiplatform_v1.services.job_service.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.aiplatform_v1.types import accelerator_type from google.cloud.aiplatform_v1.types import batch_prediction_job from google.cloud.aiplatform_v1.types import ( @@ -56,6 +57,8 @@ from google.cloud.aiplatform_v1.types import data_labeling_job as gca_data_labeling_job from google.cloud.aiplatform_v1.types import encryption_spec from google.cloud.aiplatform_v1.types import env_var +from google.cloud.aiplatform_v1.types import explanation +from google.cloud.aiplatform_v1.types import explanation_metadata from google.cloud.aiplatform_v1.types import hyperparameter_tuning_job from google.cloud.aiplatform_v1.types import ( hyperparameter_tuning_job as gca_hyperparameter_tuning_job, @@ -65,8 +68,19 @@ from google.cloud.aiplatform_v1.types import job_state from google.cloud.aiplatform_v1.types import machine_resources from google.cloud.aiplatform_v1.types import manual_batch_tuning_parameters +from google.cloud.aiplatform_v1.types import model +from google.cloud.aiplatform_v1.types import model_deployment_monitoring_job +from google.cloud.aiplatform_v1.types import ( + model_deployment_monitoring_job as gca_model_deployment_monitoring_job, +) +from google.cloud.aiplatform_v1.types import model_monitoring from google.cloud.aiplatform_v1.types import operation as gca_operation from google.cloud.aiplatform_v1.types import study +from google.cloud.aiplatform_v1.types import unmanaged_container_model +from google.cloud.location import locations_pb2 +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 from google.oauth2 import service_account from google.protobuf import any_pb2 # type: ignore @@ -79,29 +93,6 @@ import google.auth -# TODO(busunkim): Once google-api-core >= 1.26.0 is required: -# - Delete all the api-core and auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - -requires_api_core_lt_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), - reason="This test requires google-api-core < 1.26.0", -) - -requires_api_core_gte_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), - reason="This test requires google-api-core >= 1.26.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -143,37 +134,78 @@ def test__get_default_mtls_endpoint(): assert JobServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi -@pytest.mark.parametrize("client_class", [JobServiceClient, JobServiceAsyncClient,]) -def test_job_service_client_from_service_account_info(client_class): +@pytest.mark.parametrize( + "client_class,transport_name", + [ + (JobServiceClient, "grpc"), + (JobServiceAsyncClient, "grpc_asyncio"), + ], +) +def test_job_service_client_from_service_account_info(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.JobServiceGrpcTransport, "grpc"), + (transports.JobServiceGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_job_service_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() -@pytest.mark.parametrize("client_class", [JobServiceClient, JobServiceAsyncClient,]) -def test_job_service_client_from_service_account_file(client_class): +@pytest.mark.parametrize( + "client_class,transport_name", + [ + (JobServiceClient, "grpc"), + (JobServiceAsyncClient, "grpc_asyncio"), + ], +) +def test_job_service_client_from_service_account_file(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") def test_job_service_client_get_transport_class(): @@ -224,7 +256,7 @@ def test_job_service_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -233,6 +265,7 @@ def test_job_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -240,7 +273,7 @@ def test_job_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -249,6 +282,7 @@ def test_job_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -256,7 +290,7 @@ def test_job_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -265,26 +299,27 @@ def test_job_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -293,6 +328,7 @@ def test_job_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -340,7 +376,7 @@ def test_job_service_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -357,6 +393,7 @@ def test_job_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case ADC client cert is provided. Whether client cert is used depends on @@ -381,7 +418,7 @@ def test_job_service_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -390,6 +427,7 @@ def test_job_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case client_cert_source and ADC client cert are not provided. @@ -402,7 +440,7 @@ def test_job_service_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -411,9 +449,87 @@ def test_job_service_client_mtls_env_auto( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) +@pytest.mark.parametrize("client_class", [JobServiceClient, JobServiceAsyncClient]) +@mock.patch.object( + JobServiceClient, "DEFAULT_ENDPOINT", modify_default_endpoint(JobServiceClient) +) +@mock.patch.object( + JobServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(JobServiceAsyncClient), +) +def test_job_service_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + @pytest.mark.parametrize( "client_class,transport_class,transport_name", [ @@ -429,10 +545,12 @@ def test_job_service_client_client_options_scopes( client_class, transport_class, transport_name ): # Check the case scopes are provided. - options = client_options.ClientOptions(scopes=["1", "2"],) + options = client_options.ClientOptions( + scopes=["1", "2"], + ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -441,28 +559,31 @@ def test_job_service_client_client_options_scopes( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (JobServiceClient, transports.JobServiceGrpcTransport, "grpc"), + (JobServiceClient, transports.JobServiceGrpcTransport, "grpc", grpc_helpers), ( JobServiceAsyncClient, transports.JobServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_job_service_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -471,6 +592,7 @@ def test_job_service_client_client_options_credentials_file( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -488,14 +610,82 @@ def test_job_service_client_client_options_from_dict(): client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) -def test_create_custom_job( - transport: str = "grpc", request_type=job_service.CreateCustomJobRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + (JobServiceClient, transports.JobServiceGrpcTransport, "grpc", grpc_helpers), + ( + JobServiceAsyncClient, + transports.JobServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_job_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers ): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + job_service.CreateCustomJobRequest, + dict, + ], +) +def test_create_custom_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -526,15 +716,12 @@ def test_create_custom_job( assert response.state == job_state.JobState.JOB_STATE_QUEUED -def test_create_custom_job_from_dict(): - test_create_custom_job(request_type=dict) - - def test_create_custom_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -552,7 +739,8 @@ async def test_create_custom_job_async( transport: str = "grpc_asyncio", request_type=job_service.CreateCustomJobRequest ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -591,13 +779,15 @@ async def test_create_custom_job_async_from_dict(): def test_create_custom_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.CreateCustomJobRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -613,18 +803,23 @@ def test_create_custom_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_create_custom_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.CreateCustomJobRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -642,11 +837,16 @@ async def test_create_custom_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_create_custom_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -665,12 +865,18 @@ def test_create_custom_job_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].custom_job == gca_custom_job.CustomJob(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].custom_job + mock_val = gca_custom_job.CustomJob(name="name_value") + assert arg == mock_val def test_create_custom_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -684,7 +890,9 @@ def test_create_custom_job_flattened_error(): @pytest.mark.asyncio async def test_create_custom_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -707,13 +915,19 @@ async def test_create_custom_job_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].custom_job == gca_custom_job.CustomJob(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].custom_job + mock_val = gca_custom_job.CustomJob(name="name_value") + assert arg == mock_val @pytest.mark.asyncio async def test_create_custom_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -725,11 +939,17 @@ async def test_create_custom_job_flattened_error_async(): ) -def test_get_custom_job( - transport: str = "grpc", request_type=job_service.GetCustomJobRequest -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.GetCustomJobRequest, + dict, + ], +) +def test_get_custom_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -758,15 +978,12 @@ def test_get_custom_job( assert response.state == job_state.JobState.JOB_STATE_QUEUED -def test_get_custom_job_from_dict(): - test_get_custom_job(request_type=dict) - - def test_get_custom_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -782,7 +999,8 @@ async def test_get_custom_job_async( transport: str = "grpc_asyncio", request_type=job_service.GetCustomJobRequest ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -819,13 +1037,15 @@ async def test_get_custom_job_async_from_dict(): def test_get_custom_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.GetCustomJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_custom_job), "__call__") as call: @@ -839,18 +1059,23 @@ def test_get_custom_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_get_custom_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.GetCustomJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_custom_job), "__call__") as call: @@ -866,11 +1091,16 @@ async def test_get_custom_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_get_custom_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_custom_job), "__call__") as call: @@ -878,29 +1108,38 @@ def test_get_custom_job_flattened(): call.return_value = custom_job.CustomJob() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_custom_job(name="name_value",) + client.get_custom_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_custom_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.get_custom_job( - job_service.GetCustomJobRequest(), name="name_value", + job_service.GetCustomJobRequest(), + name="name_value", ) @pytest.mark.asyncio async def test_get_custom_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_custom_job), "__call__") as call: @@ -912,32 +1151,45 @@ async def test_get_custom_job_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_custom_job(name="name_value",) + response = await client.get_custom_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio async def test_get_custom_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.get_custom_job( - job_service.GetCustomJobRequest(), name="name_value", + job_service.GetCustomJobRequest(), + name="name_value", ) -def test_list_custom_jobs( - transport: str = "grpc", request_type=job_service.ListCustomJobsRequest -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.ListCustomJobsRequest, + dict, + ], +) +def test_list_custom_jobs(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -962,15 +1214,12 @@ def test_list_custom_jobs( assert response.next_page_token == "next_page_token_value" -def test_list_custom_jobs_from_dict(): - test_list_custom_jobs(request_type=dict) - - def test_list_custom_jobs_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -986,7 +1235,8 @@ async def test_list_custom_jobs_async( transport: str = "grpc_asyncio", request_type=job_service.ListCustomJobsRequest ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -997,7 +1247,9 @@ async def test_list_custom_jobs_async( with mock.patch.object(type(client.transport.list_custom_jobs), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - job_service.ListCustomJobsResponse(next_page_token="next_page_token_value",) + job_service.ListCustomJobsResponse( + next_page_token="next_page_token_value", + ) ) response = await client.list_custom_jobs(request) @@ -1017,13 +1269,15 @@ async def test_list_custom_jobs_async_from_dict(): def test_list_custom_jobs_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.ListCustomJobsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_custom_jobs), "__call__") as call: @@ -1037,18 +1291,23 @@ def test_list_custom_jobs_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_list_custom_jobs_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.ListCustomJobsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_custom_jobs), "__call__") as call: @@ -1064,11 +1323,16 @@ async def test_list_custom_jobs_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_custom_jobs_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_custom_jobs), "__call__") as call: @@ -1076,29 +1340,38 @@ def test_list_custom_jobs_flattened(): call.return_value = job_service.ListCustomJobsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_custom_jobs(parent="parent_value",) + client.list_custom_jobs( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_custom_jobs_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.list_custom_jobs( - job_service.ListCustomJobsRequest(), parent="parent_value", + job_service.ListCustomJobsRequest(), + parent="parent_value", ) @pytest.mark.asyncio async def test_list_custom_jobs_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_custom_jobs), "__call__") as call: @@ -1110,29 +1383,39 @@ async def test_list_custom_jobs_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_custom_jobs(parent="parent_value",) + response = await client.list_custom_jobs( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio async def test_list_custom_jobs_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.list_custom_jobs( - job_service.ListCustomJobsRequest(), parent="parent_value", + job_service.ListCustomJobsRequest(), + parent="parent_value", ) -def test_list_custom_jobs_pager(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_custom_jobs_pager(transport_name: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_custom_jobs), "__call__") as call: @@ -1146,12 +1429,21 @@ def test_list_custom_jobs_pager(): ], next_page_token="abc", ), - job_service.ListCustomJobsResponse(custom_jobs=[], next_page_token="def",), job_service.ListCustomJobsResponse( - custom_jobs=[custom_job.CustomJob(),], next_page_token="ghi", + custom_jobs=[], + next_page_token="def", + ), + job_service.ListCustomJobsResponse( + custom_jobs=[ + custom_job.CustomJob(), + ], + next_page_token="ghi", ), job_service.ListCustomJobsResponse( - custom_jobs=[custom_job.CustomJob(), custom_job.CustomJob(),], + custom_jobs=[ + custom_job.CustomJob(), + custom_job.CustomJob(), + ], ), RuntimeError, ) @@ -1164,13 +1456,16 @@ def test_list_custom_jobs_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all(isinstance(i, custom_job.CustomJob) for i in results) -def test_list_custom_jobs_pages(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_custom_jobs_pages(transport_name: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_custom_jobs), "__call__") as call: @@ -1184,12 +1479,21 @@ def test_list_custom_jobs_pages(): ], next_page_token="abc", ), - job_service.ListCustomJobsResponse(custom_jobs=[], next_page_token="def",), job_service.ListCustomJobsResponse( - custom_jobs=[custom_job.CustomJob(),], next_page_token="ghi", + custom_jobs=[], + next_page_token="def", + ), + job_service.ListCustomJobsResponse( + custom_jobs=[ + custom_job.CustomJob(), + ], + next_page_token="ghi", ), job_service.ListCustomJobsResponse( - custom_jobs=[custom_job.CustomJob(), custom_job.CustomJob(),], + custom_jobs=[ + custom_job.CustomJob(), + custom_job.CustomJob(), + ], ), RuntimeError, ) @@ -1200,7 +1504,9 @@ def test_list_custom_jobs_pages(): @pytest.mark.asyncio async def test_list_custom_jobs_async_pager(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1216,19 +1522,30 @@ async def test_list_custom_jobs_async_pager(): ], next_page_token="abc", ), - job_service.ListCustomJobsResponse(custom_jobs=[], next_page_token="def",), job_service.ListCustomJobsResponse( - custom_jobs=[custom_job.CustomJob(),], next_page_token="ghi", + custom_jobs=[], + next_page_token="def", + ), + job_service.ListCustomJobsResponse( + custom_jobs=[ + custom_job.CustomJob(), + ], + next_page_token="ghi", ), job_service.ListCustomJobsResponse( - custom_jobs=[custom_job.CustomJob(), custom_job.CustomJob(),], + custom_jobs=[ + custom_job.CustomJob(), + custom_job.CustomJob(), + ], ), RuntimeError, ) - async_pager = await client.list_custom_jobs(request={},) + async_pager = await client.list_custom_jobs( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -1237,7 +1554,9 @@ async def test_list_custom_jobs_async_pager(): @pytest.mark.asyncio async def test_list_custom_jobs_async_pages(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1253,27 +1572,44 @@ async def test_list_custom_jobs_async_pages(): ], next_page_token="abc", ), - job_service.ListCustomJobsResponse(custom_jobs=[], next_page_token="def",), job_service.ListCustomJobsResponse( - custom_jobs=[custom_job.CustomJob(),], next_page_token="ghi", + custom_jobs=[], + next_page_token="def", ), job_service.ListCustomJobsResponse( - custom_jobs=[custom_job.CustomJob(), custom_job.CustomJob(),], - ), - RuntimeError, + custom_jobs=[ + custom_job.CustomJob(), + ], + next_page_token="ghi", + ), + job_service.ListCustomJobsResponse( + custom_jobs=[ + custom_job.CustomJob(), + custom_job.CustomJob(), + ], + ), + RuntimeError, ) pages = [] - async for page_ in (await client.list_custom_jobs(request={})).pages: + async for page_ in ( + await client.list_custom_jobs(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_delete_custom_job( - transport: str = "grpc", request_type=job_service.DeleteCustomJobRequest -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.DeleteCustomJobRequest, + dict, + ], +) +def test_delete_custom_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1297,15 +1633,12 @@ def test_delete_custom_job( assert isinstance(response, future.Future) -def test_delete_custom_job_from_dict(): - test_delete_custom_job(request_type=dict) - - def test_delete_custom_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1323,7 +1656,8 @@ async def test_delete_custom_job_async( transport: str = "grpc_asyncio", request_type=job_service.DeleteCustomJobRequest ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1355,13 +1689,15 @@ async def test_delete_custom_job_async_from_dict(): def test_delete_custom_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.DeleteCustomJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1377,18 +1713,23 @@ def test_delete_custom_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_delete_custom_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.DeleteCustomJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1406,11 +1747,16 @@ async def test_delete_custom_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_delete_custom_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1420,29 +1766,38 @@ def test_delete_custom_job_flattened(): call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_custom_job(name="name_value",) + client.delete_custom_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_delete_custom_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.delete_custom_job( - job_service.DeleteCustomJobRequest(), name="name_value", + job_service.DeleteCustomJobRequest(), + name="name_value", ) @pytest.mark.asyncio async def test_delete_custom_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1456,32 +1811,45 @@ async def test_delete_custom_job_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_custom_job(name="name_value",) + response = await client.delete_custom_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio async def test_delete_custom_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.delete_custom_job( - job_service.DeleteCustomJobRequest(), name="name_value", + job_service.DeleteCustomJobRequest(), + name="name_value", ) -def test_cancel_custom_job( - transport: str = "grpc", request_type=job_service.CancelCustomJobRequest -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.CancelCustomJobRequest, + dict, + ], +) +def test_cancel_custom_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1505,15 +1873,12 @@ def test_cancel_custom_job( assert response is None -def test_cancel_custom_job_from_dict(): - test_cancel_custom_job(request_type=dict) - - def test_cancel_custom_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1531,7 +1896,8 @@ async def test_cancel_custom_job_async( transport: str = "grpc_asyncio", request_type=job_service.CancelCustomJobRequest ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1561,13 +1927,15 @@ async def test_cancel_custom_job_async_from_dict(): def test_cancel_custom_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.CancelCustomJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1583,18 +1951,23 @@ def test_cancel_custom_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_cancel_custom_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.CancelCustomJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1610,11 +1983,16 @@ async def test_cancel_custom_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_cancel_custom_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1624,29 +2002,38 @@ def test_cancel_custom_job_flattened(): call.return_value = None # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.cancel_custom_job(name="name_value",) + client.cancel_custom_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_cancel_custom_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.cancel_custom_job( - job_service.CancelCustomJobRequest(), name="name_value", + job_service.CancelCustomJobRequest(), + name="name_value", ) @pytest.mark.asyncio async def test_cancel_custom_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1658,32 +2045,45 @@ async def test_cancel_custom_job_flattened_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.cancel_custom_job(name="name_value",) + response = await client.cancel_custom_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio async def test_cancel_custom_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.cancel_custom_job( - job_service.CancelCustomJobRequest(), name="name_value", + job_service.CancelCustomJobRequest(), + name="name_value", ) -def test_create_data_labeling_job( - transport: str = "grpc", request_type=job_service.CreateDataLabelingJobRequest -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.CreateDataLabelingJobRequest, + dict, + ], +) +def test_create_data_labeling_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1726,15 +2126,12 @@ def test_create_data_labeling_job( assert response.specialist_pools == ["specialist_pools_value"] -def test_create_data_labeling_job_from_dict(): - test_create_data_labeling_job(request_type=dict) - - def test_create_data_labeling_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1753,7 +2150,8 @@ async def test_create_data_labeling_job_async( request_type=job_service.CreateDataLabelingJobRequest, ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1804,13 +2202,15 @@ async def test_create_data_labeling_job_async_from_dict(): def test_create_data_labeling_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.CreateDataLabelingJobRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1826,18 +2226,23 @@ def test_create_data_labeling_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_create_data_labeling_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.CreateDataLabelingJobRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1855,11 +2260,16 @@ async def test_create_data_labeling_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_create_data_labeling_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1878,14 +2288,18 @@ def test_create_data_labeling_job_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].data_labeling_job == gca_data_labeling_job.DataLabelingJob( - name="name_value" - ) + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].data_labeling_job + mock_val = gca_data_labeling_job.DataLabelingJob(name="name_value") + assert arg == mock_val def test_create_data_labeling_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1899,7 +2313,9 @@ def test_create_data_labeling_job_flattened_error(): @pytest.mark.asyncio async def test_create_data_labeling_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1922,15 +2338,19 @@ async def test_create_data_labeling_job_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].data_labeling_job == gca_data_labeling_job.DataLabelingJob( - name="name_value" - ) + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].data_labeling_job + mock_val = gca_data_labeling_job.DataLabelingJob(name="name_value") + assert arg == mock_val @pytest.mark.asyncio async def test_create_data_labeling_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1942,11 +2362,17 @@ async def test_create_data_labeling_job_flattened_error_async(): ) -def test_get_data_labeling_job( - transport: str = "grpc", request_type=job_service.GetDataLabelingJobRequest -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.GetDataLabelingJobRequest, + dict, + ], +) +def test_get_data_labeling_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1989,15 +2415,12 @@ def test_get_data_labeling_job( assert response.specialist_pools == ["specialist_pools_value"] -def test_get_data_labeling_job_from_dict(): - test_get_data_labeling_job(request_type=dict) - - def test_get_data_labeling_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2015,7 +2438,8 @@ async def test_get_data_labeling_job_async( transport: str = "grpc_asyncio", request_type=job_service.GetDataLabelingJobRequest ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2066,13 +2490,15 @@ async def test_get_data_labeling_job_async_from_dict(): def test_get_data_labeling_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.GetDataLabelingJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2088,18 +2514,23 @@ def test_get_data_labeling_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_get_data_labeling_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.GetDataLabelingJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2117,11 +2548,16 @@ async def test_get_data_labeling_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_get_data_labeling_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2131,29 +2567,38 @@ def test_get_data_labeling_job_flattened(): call.return_value = data_labeling_job.DataLabelingJob() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_data_labeling_job(name="name_value",) + client.get_data_labeling_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_data_labeling_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.get_data_labeling_job( - job_service.GetDataLabelingJobRequest(), name="name_value", + job_service.GetDataLabelingJobRequest(), + name="name_value", ) @pytest.mark.asyncio async def test_get_data_labeling_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2167,32 +2612,45 @@ async def test_get_data_labeling_job_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_data_labeling_job(name="name_value",) + response = await client.get_data_labeling_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio async def test_get_data_labeling_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.get_data_labeling_job( - job_service.GetDataLabelingJobRequest(), name="name_value", + job_service.GetDataLabelingJobRequest(), + name="name_value", ) -def test_list_data_labeling_jobs( - transport: str = "grpc", request_type=job_service.ListDataLabelingJobsRequest -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.ListDataLabelingJobsRequest, + dict, + ], +) +def test_list_data_labeling_jobs(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2219,15 +2677,12 @@ def test_list_data_labeling_jobs( assert response.next_page_token == "next_page_token_value" -def test_list_data_labeling_jobs_from_dict(): - test_list_data_labeling_jobs(request_type=dict) - - def test_list_data_labeling_jobs_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2246,7 +2701,8 @@ async def test_list_data_labeling_jobs_async( request_type=job_service.ListDataLabelingJobsRequest, ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2281,13 +2737,15 @@ async def test_list_data_labeling_jobs_async_from_dict(): def test_list_data_labeling_jobs_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.ListDataLabelingJobsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2303,18 +2761,23 @@ def test_list_data_labeling_jobs_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_list_data_labeling_jobs_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.ListDataLabelingJobsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2332,11 +2795,16 @@ async def test_list_data_labeling_jobs_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_data_labeling_jobs_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2346,29 +2814,38 @@ def test_list_data_labeling_jobs_flattened(): call.return_value = job_service.ListDataLabelingJobsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_data_labeling_jobs(parent="parent_value",) + client.list_data_labeling_jobs( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_data_labeling_jobs_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.list_data_labeling_jobs( - job_service.ListDataLabelingJobsRequest(), parent="parent_value", + job_service.ListDataLabelingJobsRequest(), + parent="parent_value", ) @pytest.mark.asyncio async def test_list_data_labeling_jobs_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2382,29 +2859,39 @@ async def test_list_data_labeling_jobs_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_data_labeling_jobs(parent="parent_value",) + response = await client.list_data_labeling_jobs( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio async def test_list_data_labeling_jobs_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.list_data_labeling_jobs( - job_service.ListDataLabelingJobsRequest(), parent="parent_value", + job_service.ListDataLabelingJobsRequest(), + parent="parent_value", ) -def test_list_data_labeling_jobs_pager(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_data_labeling_jobs_pager(transport_name: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2421,10 +2908,13 @@ def test_list_data_labeling_jobs_pager(): next_page_token="abc", ), job_service.ListDataLabelingJobsResponse( - data_labeling_jobs=[], next_page_token="def", + data_labeling_jobs=[], + next_page_token="def", ), job_service.ListDataLabelingJobsResponse( - data_labeling_jobs=[data_labeling_job.DataLabelingJob(),], + data_labeling_jobs=[ + data_labeling_job.DataLabelingJob(), + ], next_page_token="ghi", ), job_service.ListDataLabelingJobsResponse( @@ -2444,13 +2934,16 @@ def test_list_data_labeling_jobs_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all(isinstance(i, data_labeling_job.DataLabelingJob) for i in results) -def test_list_data_labeling_jobs_pages(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_data_labeling_jobs_pages(transport_name: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2467,10 +2960,13 @@ def test_list_data_labeling_jobs_pages(): next_page_token="abc", ), job_service.ListDataLabelingJobsResponse( - data_labeling_jobs=[], next_page_token="def", + data_labeling_jobs=[], + next_page_token="def", ), job_service.ListDataLabelingJobsResponse( - data_labeling_jobs=[data_labeling_job.DataLabelingJob(),], + data_labeling_jobs=[ + data_labeling_job.DataLabelingJob(), + ], next_page_token="ghi", ), job_service.ListDataLabelingJobsResponse( @@ -2488,7 +2984,9 @@ def test_list_data_labeling_jobs_pages(): @pytest.mark.asyncio async def test_list_data_labeling_jobs_async_pager(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2507,10 +3005,13 @@ async def test_list_data_labeling_jobs_async_pager(): next_page_token="abc", ), job_service.ListDataLabelingJobsResponse( - data_labeling_jobs=[], next_page_token="def", + data_labeling_jobs=[], + next_page_token="def", ), job_service.ListDataLabelingJobsResponse( - data_labeling_jobs=[data_labeling_job.DataLabelingJob(),], + data_labeling_jobs=[ + data_labeling_job.DataLabelingJob(), + ], next_page_token="ghi", ), job_service.ListDataLabelingJobsResponse( @@ -2521,10 +3022,12 @@ async def test_list_data_labeling_jobs_async_pager(): ), RuntimeError, ) - async_pager = await client.list_data_labeling_jobs(request={},) + async_pager = await client.list_data_labeling_jobs( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -2533,7 +3036,9 @@ async def test_list_data_labeling_jobs_async_pager(): @pytest.mark.asyncio async def test_list_data_labeling_jobs_async_pages(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2552,10 +3057,13 @@ async def test_list_data_labeling_jobs_async_pages(): next_page_token="abc", ), job_service.ListDataLabelingJobsResponse( - data_labeling_jobs=[], next_page_token="def", + data_labeling_jobs=[], + next_page_token="def", ), job_service.ListDataLabelingJobsResponse( - data_labeling_jobs=[data_labeling_job.DataLabelingJob(),], + data_labeling_jobs=[ + data_labeling_job.DataLabelingJob(), + ], next_page_token="ghi", ), job_service.ListDataLabelingJobsResponse( @@ -2567,17 +3075,25 @@ async def test_list_data_labeling_jobs_async_pages(): RuntimeError, ) pages = [] - async for page_ in (await client.list_data_labeling_jobs(request={})).pages: + async for page_ in ( + await client.list_data_labeling_jobs(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_delete_data_labeling_job( - transport: str = "grpc", request_type=job_service.DeleteDataLabelingJobRequest -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.DeleteDataLabelingJobRequest, + dict, + ], +) +def test_delete_data_labeling_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2601,15 +3117,12 @@ def test_delete_data_labeling_job( assert isinstance(response, future.Future) -def test_delete_data_labeling_job_from_dict(): - test_delete_data_labeling_job(request_type=dict) - - def test_delete_data_labeling_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2628,7 +3141,8 @@ async def test_delete_data_labeling_job_async( request_type=job_service.DeleteDataLabelingJobRequest, ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2660,13 +3174,15 @@ async def test_delete_data_labeling_job_async_from_dict(): def test_delete_data_labeling_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.DeleteDataLabelingJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2682,18 +3198,23 @@ def test_delete_data_labeling_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_delete_data_labeling_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.DeleteDataLabelingJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2711,11 +3232,16 @@ async def test_delete_data_labeling_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_delete_data_labeling_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2725,29 +3251,38 @@ def test_delete_data_labeling_job_flattened(): call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_data_labeling_job(name="name_value",) + client.delete_data_labeling_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_delete_data_labeling_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.delete_data_labeling_job( - job_service.DeleteDataLabelingJobRequest(), name="name_value", + job_service.DeleteDataLabelingJobRequest(), + name="name_value", ) @pytest.mark.asyncio async def test_delete_data_labeling_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2761,32 +3296,45 @@ async def test_delete_data_labeling_job_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_data_labeling_job(name="name_value",) + response = await client.delete_data_labeling_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio async def test_delete_data_labeling_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.delete_data_labeling_job( - job_service.DeleteDataLabelingJobRequest(), name="name_value", + job_service.DeleteDataLabelingJobRequest(), + name="name_value", ) -def test_cancel_data_labeling_job( - transport: str = "grpc", request_type=job_service.CancelDataLabelingJobRequest -): - client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, +@pytest.mark.parametrize( + "request_type", + [ + job_service.CancelDataLabelingJobRequest, + dict, + ], +) +def test_cancel_data_labeling_job(request_type, transport: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2810,15 +3358,12 @@ def test_cancel_data_labeling_job( assert response is None -def test_cancel_data_labeling_job_from_dict(): - test_cancel_data_labeling_job(request_type=dict) - - def test_cancel_data_labeling_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2837,7 +3382,8 @@ async def test_cancel_data_labeling_job_async( request_type=job_service.CancelDataLabelingJobRequest, ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2867,13 +3413,15 @@ async def test_cancel_data_labeling_job_async_from_dict(): def test_cancel_data_labeling_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.CancelDataLabelingJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2889,18 +3437,23 @@ def test_cancel_data_labeling_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_cancel_data_labeling_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.CancelDataLabelingJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2916,11 +3469,16 @@ async def test_cancel_data_labeling_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_cancel_data_labeling_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2930,29 +3488,38 @@ def test_cancel_data_labeling_job_flattened(): call.return_value = None # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.cancel_data_labeling_job(name="name_value",) + client.cancel_data_labeling_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_cancel_data_labeling_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.cancel_data_labeling_job( - job_service.CancelDataLabelingJobRequest(), name="name_value", + job_service.CancelDataLabelingJobRequest(), + name="name_value", ) @pytest.mark.asyncio async def test_cancel_data_labeling_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2964,33 +3531,45 @@ async def test_cancel_data_labeling_job_flattened_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.cancel_data_labeling_job(name="name_value",) + response = await client.cancel_data_labeling_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio async def test_cancel_data_labeling_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.cancel_data_labeling_job( - job_service.CancelDataLabelingJobRequest(), name="name_value", + job_service.CancelDataLabelingJobRequest(), + name="name_value", ) -def test_create_hyperparameter_tuning_job( - transport: str = "grpc", - request_type=job_service.CreateHyperparameterTuningJobRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.CreateHyperparameterTuningJobRequest, + dict, + ], +) +def test_create_hyperparameter_tuning_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3027,15 +3606,12 @@ def test_create_hyperparameter_tuning_job( assert response.state == job_state.JobState.JOB_STATE_QUEUED -def test_create_hyperparameter_tuning_job_from_dict(): - test_create_hyperparameter_tuning_job(request_type=dict) - - def test_create_hyperparameter_tuning_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3054,7 +3630,8 @@ async def test_create_hyperparameter_tuning_job_async( request_type=job_service.CreateHyperparameterTuningJobRequest, ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3099,13 +3676,15 @@ async def test_create_hyperparameter_tuning_job_async_from_dict(): def test_create_hyperparameter_tuning_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.CreateHyperparameterTuningJobRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3121,18 +3700,23 @@ def test_create_hyperparameter_tuning_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_create_hyperparameter_tuning_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.CreateHyperparameterTuningJobRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3150,11 +3734,16 @@ async def test_create_hyperparameter_tuning_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_create_hyperparameter_tuning_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3175,16 +3764,20 @@ def test_create_hyperparameter_tuning_job_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[ - 0 - ].hyperparameter_tuning_job == gca_hyperparameter_tuning_job.HyperparameterTuningJob( + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].hyperparameter_tuning_job + mock_val = gca_hyperparameter_tuning_job.HyperparameterTuningJob( name="name_value" ) + assert arg == mock_val def test_create_hyperparameter_tuning_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -3200,7 +3793,9 @@ def test_create_hyperparameter_tuning_job_flattened_error(): @pytest.mark.asyncio async def test_create_hyperparameter_tuning_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3225,17 +3820,21 @@ async def test_create_hyperparameter_tuning_job_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[ - 0 - ].hyperparameter_tuning_job == gca_hyperparameter_tuning_job.HyperparameterTuningJob( + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].hyperparameter_tuning_job + mock_val = gca_hyperparameter_tuning_job.HyperparameterTuningJob( name="name_value" ) + assert arg == mock_val @pytest.mark.asyncio async def test_create_hyperparameter_tuning_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -3249,11 +3848,17 @@ async def test_create_hyperparameter_tuning_job_flattened_error_async(): ) -def test_get_hyperparameter_tuning_job( - transport: str = "grpc", request_type=job_service.GetHyperparameterTuningJobRequest -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.GetHyperparameterTuningJobRequest, + dict, + ], +) +def test_get_hyperparameter_tuning_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3290,15 +3895,12 @@ def test_get_hyperparameter_tuning_job( assert response.state == job_state.JobState.JOB_STATE_QUEUED -def test_get_hyperparameter_tuning_job_from_dict(): - test_get_hyperparameter_tuning_job(request_type=dict) - - def test_get_hyperparameter_tuning_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3317,7 +3919,8 @@ async def test_get_hyperparameter_tuning_job_async( request_type=job_service.GetHyperparameterTuningJobRequest, ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3362,13 +3965,15 @@ async def test_get_hyperparameter_tuning_job_async_from_dict(): def test_get_hyperparameter_tuning_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.GetHyperparameterTuningJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3384,18 +3989,23 @@ def test_get_hyperparameter_tuning_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_get_hyperparameter_tuning_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.GetHyperparameterTuningJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3413,11 +4023,16 @@ async def test_get_hyperparameter_tuning_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_get_hyperparameter_tuning_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3427,29 +4042,38 @@ def test_get_hyperparameter_tuning_job_flattened(): call.return_value = hyperparameter_tuning_job.HyperparameterTuningJob() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_hyperparameter_tuning_job(name="name_value",) + client.get_hyperparameter_tuning_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_hyperparameter_tuning_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.get_hyperparameter_tuning_job( - job_service.GetHyperparameterTuningJobRequest(), name="name_value", + job_service.GetHyperparameterTuningJobRequest(), + name="name_value", ) @pytest.mark.asyncio async def test_get_hyperparameter_tuning_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3463,33 +4087,45 @@ async def test_get_hyperparameter_tuning_job_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_hyperparameter_tuning_job(name="name_value",) + response = await client.get_hyperparameter_tuning_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio async def test_get_hyperparameter_tuning_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.get_hyperparameter_tuning_job( - job_service.GetHyperparameterTuningJobRequest(), name="name_value", + job_service.GetHyperparameterTuningJobRequest(), + name="name_value", ) -def test_list_hyperparameter_tuning_jobs( - transport: str = "grpc", - request_type=job_service.ListHyperparameterTuningJobsRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.ListHyperparameterTuningJobsRequest, + dict, + ], +) +def test_list_hyperparameter_tuning_jobs(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3516,15 +4152,12 @@ def test_list_hyperparameter_tuning_jobs( assert response.next_page_token == "next_page_token_value" -def test_list_hyperparameter_tuning_jobs_from_dict(): - test_list_hyperparameter_tuning_jobs(request_type=dict) - - def test_list_hyperparameter_tuning_jobs_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3543,7 +4176,8 @@ async def test_list_hyperparameter_tuning_jobs_async( request_type=job_service.ListHyperparameterTuningJobsRequest, ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3578,13 +4212,15 @@ async def test_list_hyperparameter_tuning_jobs_async_from_dict(): def test_list_hyperparameter_tuning_jobs_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.ListHyperparameterTuningJobsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3600,18 +4236,23 @@ def test_list_hyperparameter_tuning_jobs_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_list_hyperparameter_tuning_jobs_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.ListHyperparameterTuningJobsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3629,11 +4270,16 @@ async def test_list_hyperparameter_tuning_jobs_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_hyperparameter_tuning_jobs_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3643,29 +4289,38 @@ def test_list_hyperparameter_tuning_jobs_flattened(): call.return_value = job_service.ListHyperparameterTuningJobsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_hyperparameter_tuning_jobs(parent="parent_value",) + client.list_hyperparameter_tuning_jobs( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_hyperparameter_tuning_jobs_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.list_hyperparameter_tuning_jobs( - job_service.ListHyperparameterTuningJobsRequest(), parent="parent_value", + job_service.ListHyperparameterTuningJobsRequest(), + parent="parent_value", ) @pytest.mark.asyncio async def test_list_hyperparameter_tuning_jobs_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3679,29 +4334,39 @@ async def test_list_hyperparameter_tuning_jobs_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_hyperparameter_tuning_jobs(parent="parent_value",) + response = await client.list_hyperparameter_tuning_jobs( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio async def test_list_hyperparameter_tuning_jobs_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.list_hyperparameter_tuning_jobs( - job_service.ListHyperparameterTuningJobsRequest(), parent="parent_value", + job_service.ListHyperparameterTuningJobsRequest(), + parent="parent_value", ) -def test_list_hyperparameter_tuning_jobs_pager(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_hyperparameter_tuning_jobs_pager(transport_name: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3718,7 +4383,8 @@ def test_list_hyperparameter_tuning_jobs_pager(): next_page_token="abc", ), job_service.ListHyperparameterTuningJobsResponse( - hyperparameter_tuning_jobs=[], next_page_token="def", + hyperparameter_tuning_jobs=[], + next_page_token="def", ), job_service.ListHyperparameterTuningJobsResponse( hyperparameter_tuning_jobs=[ @@ -3743,7 +4409,7 @@ def test_list_hyperparameter_tuning_jobs_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all( isinstance(i, hyperparameter_tuning_job.HyperparameterTuningJob) @@ -3751,8 +4417,11 @@ def test_list_hyperparameter_tuning_jobs_pager(): ) -def test_list_hyperparameter_tuning_jobs_pages(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_hyperparameter_tuning_jobs_pages(transport_name: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3769,7 +4438,8 @@ def test_list_hyperparameter_tuning_jobs_pages(): next_page_token="abc", ), job_service.ListHyperparameterTuningJobsResponse( - hyperparameter_tuning_jobs=[], next_page_token="def", + hyperparameter_tuning_jobs=[], + next_page_token="def", ), job_service.ListHyperparameterTuningJobsResponse( hyperparameter_tuning_jobs=[ @@ -3792,7 +4462,9 @@ def test_list_hyperparameter_tuning_jobs_pages(): @pytest.mark.asyncio async def test_list_hyperparameter_tuning_jobs_async_pager(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3811,7 +4483,8 @@ async def test_list_hyperparameter_tuning_jobs_async_pager(): next_page_token="abc", ), job_service.ListHyperparameterTuningJobsResponse( - hyperparameter_tuning_jobs=[], next_page_token="def", + hyperparameter_tuning_jobs=[], + next_page_token="def", ), job_service.ListHyperparameterTuningJobsResponse( hyperparameter_tuning_jobs=[ @@ -3827,10 +4500,12 @@ async def test_list_hyperparameter_tuning_jobs_async_pager(): ), RuntimeError, ) - async_pager = await client.list_hyperparameter_tuning_jobs(request={},) + async_pager = await client.list_hyperparameter_tuning_jobs( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -3842,7 +4517,9 @@ async def test_list_hyperparameter_tuning_jobs_async_pager(): @pytest.mark.asyncio async def test_list_hyperparameter_tuning_jobs_async_pages(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3861,7 +4538,8 @@ async def test_list_hyperparameter_tuning_jobs_async_pages(): next_page_token="abc", ), job_service.ListHyperparameterTuningJobsResponse( - hyperparameter_tuning_jobs=[], next_page_token="def", + hyperparameter_tuning_jobs=[], + next_page_token="def", ), job_service.ListHyperparameterTuningJobsResponse( hyperparameter_tuning_jobs=[ @@ -3880,18 +4558,23 @@ async def test_list_hyperparameter_tuning_jobs_async_pages(): pages = [] async for page_ in ( await client.list_hyperparameter_tuning_jobs(request={}) - ).pages: + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_delete_hyperparameter_tuning_job( - transport: str = "grpc", - request_type=job_service.DeleteHyperparameterTuningJobRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.DeleteHyperparameterTuningJobRequest, + dict, + ], +) +def test_delete_hyperparameter_tuning_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3915,15 +4598,12 @@ def test_delete_hyperparameter_tuning_job( assert isinstance(response, future.Future) -def test_delete_hyperparameter_tuning_job_from_dict(): - test_delete_hyperparameter_tuning_job(request_type=dict) - - def test_delete_hyperparameter_tuning_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3942,7 +4622,8 @@ async def test_delete_hyperparameter_tuning_job_async( request_type=job_service.DeleteHyperparameterTuningJobRequest, ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3974,13 +4655,15 @@ async def test_delete_hyperparameter_tuning_job_async_from_dict(): def test_delete_hyperparameter_tuning_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.DeleteHyperparameterTuningJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3996,18 +4679,23 @@ def test_delete_hyperparameter_tuning_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_delete_hyperparameter_tuning_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.DeleteHyperparameterTuningJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4025,11 +4713,16 @@ async def test_delete_hyperparameter_tuning_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_delete_hyperparameter_tuning_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4039,29 +4732,38 @@ def test_delete_hyperparameter_tuning_job_flattened(): call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_hyperparameter_tuning_job(name="name_value",) + client.delete_hyperparameter_tuning_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_delete_hyperparameter_tuning_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.delete_hyperparameter_tuning_job( - job_service.DeleteHyperparameterTuningJobRequest(), name="name_value", + job_service.DeleteHyperparameterTuningJobRequest(), + name="name_value", ) @pytest.mark.asyncio async def test_delete_hyperparameter_tuning_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4075,33 +4777,45 @@ async def test_delete_hyperparameter_tuning_job_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_hyperparameter_tuning_job(name="name_value",) + response = await client.delete_hyperparameter_tuning_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio async def test_delete_hyperparameter_tuning_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.delete_hyperparameter_tuning_job( - job_service.DeleteHyperparameterTuningJobRequest(), name="name_value", + job_service.DeleteHyperparameterTuningJobRequest(), + name="name_value", ) -def test_cancel_hyperparameter_tuning_job( - transport: str = "grpc", - request_type=job_service.CancelHyperparameterTuningJobRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.CancelHyperparameterTuningJobRequest, + dict, + ], +) +def test_cancel_hyperparameter_tuning_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4125,15 +4839,12 @@ def test_cancel_hyperparameter_tuning_job( assert response is None -def test_cancel_hyperparameter_tuning_job_from_dict(): - test_cancel_hyperparameter_tuning_job(request_type=dict) - - def test_cancel_hyperparameter_tuning_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4152,7 +4863,8 @@ async def test_cancel_hyperparameter_tuning_job_async( request_type=job_service.CancelHyperparameterTuningJobRequest, ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4182,13 +4894,15 @@ async def test_cancel_hyperparameter_tuning_job_async_from_dict(): def test_cancel_hyperparameter_tuning_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.CancelHyperparameterTuningJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4204,18 +4918,23 @@ def test_cancel_hyperparameter_tuning_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_cancel_hyperparameter_tuning_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.CancelHyperparameterTuningJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4231,11 +4950,16 @@ async def test_cancel_hyperparameter_tuning_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_cancel_hyperparameter_tuning_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4245,29 +4969,38 @@ def test_cancel_hyperparameter_tuning_job_flattened(): call.return_value = None # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.cancel_hyperparameter_tuning_job(name="name_value",) + client.cancel_hyperparameter_tuning_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_cancel_hyperparameter_tuning_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.cancel_hyperparameter_tuning_job( - job_service.CancelHyperparameterTuningJobRequest(), name="name_value", + job_service.CancelHyperparameterTuningJobRequest(), + name="name_value", ) @pytest.mark.asyncio async def test_cancel_hyperparameter_tuning_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4279,32 +5012,45 @@ async def test_cancel_hyperparameter_tuning_job_flattened_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.cancel_hyperparameter_tuning_job(name="name_value",) + response = await client.cancel_hyperparameter_tuning_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio async def test_cancel_hyperparameter_tuning_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.cancel_hyperparameter_tuning_job( - job_service.CancelHyperparameterTuningJobRequest(), name="name_value", + job_service.CancelHyperparameterTuningJobRequest(), + name="name_value", ) -def test_create_batch_prediction_job( - transport: str = "grpc", request_type=job_service.CreateBatchPredictionJobRequest -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.CreateBatchPredictionJobRequest, + dict, + ], +) +def test_create_batch_prediction_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4320,6 +5066,8 @@ def test_create_batch_prediction_job( name="name_value", display_name="display_name_value", model="model_value", + model_version_id="model_version_id_value", + generate_explanation=True, state=job_state.JobState.JOB_STATE_QUEUED, ) response = client.create_batch_prediction_job(request) @@ -4334,18 +5082,17 @@ def test_create_batch_prediction_job( assert response.name == "name_value" assert response.display_name == "display_name_value" assert response.model == "model_value" + assert response.model_version_id == "model_version_id_value" + assert response.generate_explanation is True assert response.state == job_state.JobState.JOB_STATE_QUEUED -def test_create_batch_prediction_job_from_dict(): - test_create_batch_prediction_job(request_type=dict) - - def test_create_batch_prediction_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4364,7 +5111,8 @@ async def test_create_batch_prediction_job_async( request_type=job_service.CreateBatchPredictionJobRequest, ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4381,6 +5129,8 @@ async def test_create_batch_prediction_job_async( name="name_value", display_name="display_name_value", model="model_value", + model_version_id="model_version_id_value", + generate_explanation=True, state=job_state.JobState.JOB_STATE_QUEUED, ) ) @@ -4396,6 +5146,8 @@ async def test_create_batch_prediction_job_async( assert response.name == "name_value" assert response.display_name == "display_name_value" assert response.model == "model_value" + assert response.model_version_id == "model_version_id_value" + assert response.generate_explanation is True assert response.state == job_state.JobState.JOB_STATE_QUEUED @@ -4405,13 +5157,15 @@ async def test_create_batch_prediction_job_async_from_dict(): def test_create_batch_prediction_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.CreateBatchPredictionJobRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4427,18 +5181,23 @@ def test_create_batch_prediction_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_create_batch_prediction_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.CreateBatchPredictionJobRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4456,11 +5215,16 @@ async def test_create_batch_prediction_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_create_batch_prediction_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4481,16 +5245,18 @@ def test_create_batch_prediction_job_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[ - 0 - ].batch_prediction_job == gca_batch_prediction_job.BatchPredictionJob( - name="name_value" - ) + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].batch_prediction_job + mock_val = gca_batch_prediction_job.BatchPredictionJob(name="name_value") + assert arg == mock_val def test_create_batch_prediction_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -4506,9 +5272,11 @@ def test_create_batch_prediction_job_flattened_error(): @pytest.mark.asyncio async def test_create_batch_prediction_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) - - # Mock the actual call within the gRPC stub, and fake the request. + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( type(client.transport.create_batch_prediction_job), "__call__" ) as call: @@ -4531,17 +5299,19 @@ async def test_create_batch_prediction_job_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[ - 0 - ].batch_prediction_job == gca_batch_prediction_job.BatchPredictionJob( - name="name_value" - ) + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].batch_prediction_job + mock_val = gca_batch_prediction_job.BatchPredictionJob(name="name_value") + assert arg == mock_val @pytest.mark.asyncio async def test_create_batch_prediction_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -4555,11 +5325,17 @@ async def test_create_batch_prediction_job_flattened_error_async(): ) -def test_get_batch_prediction_job( - transport: str = "grpc", request_type=job_service.GetBatchPredictionJobRequest -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.GetBatchPredictionJobRequest, + dict, + ], +) +def test_get_batch_prediction_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4575,6 +5351,8 @@ def test_get_batch_prediction_job( name="name_value", display_name="display_name_value", model="model_value", + model_version_id="model_version_id_value", + generate_explanation=True, state=job_state.JobState.JOB_STATE_QUEUED, ) response = client.get_batch_prediction_job(request) @@ -4589,18 +5367,17 @@ def test_get_batch_prediction_job( assert response.name == "name_value" assert response.display_name == "display_name_value" assert response.model == "model_value" + assert response.model_version_id == "model_version_id_value" + assert response.generate_explanation is True assert response.state == job_state.JobState.JOB_STATE_QUEUED -def test_get_batch_prediction_job_from_dict(): - test_get_batch_prediction_job(request_type=dict) - - def test_get_batch_prediction_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4619,7 +5396,8 @@ async def test_get_batch_prediction_job_async( request_type=job_service.GetBatchPredictionJobRequest, ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4636,6 +5414,8 @@ async def test_get_batch_prediction_job_async( name="name_value", display_name="display_name_value", model="model_value", + model_version_id="model_version_id_value", + generate_explanation=True, state=job_state.JobState.JOB_STATE_QUEUED, ) ) @@ -4651,6 +5431,8 @@ async def test_get_batch_prediction_job_async( assert response.name == "name_value" assert response.display_name == "display_name_value" assert response.model == "model_value" + assert response.model_version_id == "model_version_id_value" + assert response.generate_explanation is True assert response.state == job_state.JobState.JOB_STATE_QUEUED @@ -4660,13 +5442,15 @@ async def test_get_batch_prediction_job_async_from_dict(): def test_get_batch_prediction_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.GetBatchPredictionJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4682,18 +5466,23 @@ def test_get_batch_prediction_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_get_batch_prediction_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.GetBatchPredictionJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4711,11 +5500,16 @@ async def test_get_batch_prediction_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_get_batch_prediction_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4725,29 +5519,38 @@ def test_get_batch_prediction_job_flattened(): call.return_value = batch_prediction_job.BatchPredictionJob() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_batch_prediction_job(name="name_value",) + client.get_batch_prediction_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_batch_prediction_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.get_batch_prediction_job( - job_service.GetBatchPredictionJobRequest(), name="name_value", + job_service.GetBatchPredictionJobRequest(), + name="name_value", ) @pytest.mark.asyncio async def test_get_batch_prediction_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4761,32 +5564,45 @@ async def test_get_batch_prediction_job_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_batch_prediction_job(name="name_value",) + response = await client.get_batch_prediction_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio async def test_get_batch_prediction_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.get_batch_prediction_job( - job_service.GetBatchPredictionJobRequest(), name="name_value", + job_service.GetBatchPredictionJobRequest(), + name="name_value", ) -def test_list_batch_prediction_jobs( - transport: str = "grpc", request_type=job_service.ListBatchPredictionJobsRequest -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.ListBatchPredictionJobsRequest, + dict, + ], +) +def test_list_batch_prediction_jobs(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4813,15 +5629,12 @@ def test_list_batch_prediction_jobs( assert response.next_page_token == "next_page_token_value" -def test_list_batch_prediction_jobs_from_dict(): - test_list_batch_prediction_jobs(request_type=dict) - - def test_list_batch_prediction_jobs_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4840,7 +5653,8 @@ async def test_list_batch_prediction_jobs_async( request_type=job_service.ListBatchPredictionJobsRequest, ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4875,13 +5689,15 @@ async def test_list_batch_prediction_jobs_async_from_dict(): def test_list_batch_prediction_jobs_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.ListBatchPredictionJobsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4897,18 +5713,23 @@ def test_list_batch_prediction_jobs_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_list_batch_prediction_jobs_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.ListBatchPredictionJobsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4926,11 +5747,16 @@ async def test_list_batch_prediction_jobs_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_batch_prediction_jobs_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4940,29 +5766,38 @@ def test_list_batch_prediction_jobs_flattened(): call.return_value = job_service.ListBatchPredictionJobsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_batch_prediction_jobs(parent="parent_value",) + client.list_batch_prediction_jobs( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_batch_prediction_jobs_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.list_batch_prediction_jobs( - job_service.ListBatchPredictionJobsRequest(), parent="parent_value", + job_service.ListBatchPredictionJobsRequest(), + parent="parent_value", ) @pytest.mark.asyncio async def test_list_batch_prediction_jobs_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4976,29 +5811,39 @@ async def test_list_batch_prediction_jobs_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_batch_prediction_jobs(parent="parent_value",) + response = await client.list_batch_prediction_jobs( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio async def test_list_batch_prediction_jobs_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.list_batch_prediction_jobs( - job_service.ListBatchPredictionJobsRequest(), parent="parent_value", + job_service.ListBatchPredictionJobsRequest(), + parent="parent_value", ) -def test_list_batch_prediction_jobs_pager(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_batch_prediction_jobs_pager(transport_name: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5015,10 +5860,13 @@ def test_list_batch_prediction_jobs_pager(): next_page_token="abc", ), job_service.ListBatchPredictionJobsResponse( - batch_prediction_jobs=[], next_page_token="def", + batch_prediction_jobs=[], + next_page_token="def", ), job_service.ListBatchPredictionJobsResponse( - batch_prediction_jobs=[batch_prediction_job.BatchPredictionJob(),], + batch_prediction_jobs=[ + batch_prediction_job.BatchPredictionJob(), + ], next_page_token="ghi", ), job_service.ListBatchPredictionJobsResponse( @@ -5038,15 +5886,18 @@ def test_list_batch_prediction_jobs_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all( isinstance(i, batch_prediction_job.BatchPredictionJob) for i in results ) -def test_list_batch_prediction_jobs_pages(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_batch_prediction_jobs_pages(transport_name: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5063,10 +5914,13 @@ def test_list_batch_prediction_jobs_pages(): next_page_token="abc", ), job_service.ListBatchPredictionJobsResponse( - batch_prediction_jobs=[], next_page_token="def", + batch_prediction_jobs=[], + next_page_token="def", ), job_service.ListBatchPredictionJobsResponse( - batch_prediction_jobs=[batch_prediction_job.BatchPredictionJob(),], + batch_prediction_jobs=[ + batch_prediction_job.BatchPredictionJob(), + ], next_page_token="ghi", ), job_service.ListBatchPredictionJobsResponse( @@ -5084,7 +5938,9 @@ def test_list_batch_prediction_jobs_pages(): @pytest.mark.asyncio async def test_list_batch_prediction_jobs_async_pager(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5103,10 +5959,13 @@ async def test_list_batch_prediction_jobs_async_pager(): next_page_token="abc", ), job_service.ListBatchPredictionJobsResponse( - batch_prediction_jobs=[], next_page_token="def", + batch_prediction_jobs=[], + next_page_token="def", ), job_service.ListBatchPredictionJobsResponse( - batch_prediction_jobs=[batch_prediction_job.BatchPredictionJob(),], + batch_prediction_jobs=[ + batch_prediction_job.BatchPredictionJob(), + ], next_page_token="ghi", ), job_service.ListBatchPredictionJobsResponse( @@ -5117,10 +5976,12 @@ async def test_list_batch_prediction_jobs_async_pager(): ), RuntimeError, ) - async_pager = await client.list_batch_prediction_jobs(request={},) + async_pager = await client.list_batch_prediction_jobs( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -5131,7 +5992,9 @@ async def test_list_batch_prediction_jobs_async_pager(): @pytest.mark.asyncio async def test_list_batch_prediction_jobs_async_pages(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5150,10 +6013,13 @@ async def test_list_batch_prediction_jobs_async_pages(): next_page_token="abc", ), job_service.ListBatchPredictionJobsResponse( - batch_prediction_jobs=[], next_page_token="def", + batch_prediction_jobs=[], + next_page_token="def", ), job_service.ListBatchPredictionJobsResponse( - batch_prediction_jobs=[batch_prediction_job.BatchPredictionJob(),], + batch_prediction_jobs=[ + batch_prediction_job.BatchPredictionJob(), + ], next_page_token="ghi", ), job_service.ListBatchPredictionJobsResponse( @@ -5165,17 +6031,25 @@ async def test_list_batch_prediction_jobs_async_pages(): RuntimeError, ) pages = [] - async for page_ in (await client.list_batch_prediction_jobs(request={})).pages: + async for page_ in ( + await client.list_batch_prediction_jobs(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_delete_batch_prediction_job( - transport: str = "grpc", request_type=job_service.DeleteBatchPredictionJobRequest -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.DeleteBatchPredictionJobRequest, + dict, + ], +) +def test_delete_batch_prediction_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5199,15 +6073,12 @@ def test_delete_batch_prediction_job( assert isinstance(response, future.Future) -def test_delete_batch_prediction_job_from_dict(): - test_delete_batch_prediction_job(request_type=dict) - - def test_delete_batch_prediction_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5226,7 +6097,8 @@ async def test_delete_batch_prediction_job_async( request_type=job_service.DeleteBatchPredictionJobRequest, ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5258,13 +6130,15 @@ async def test_delete_batch_prediction_job_async_from_dict(): def test_delete_batch_prediction_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.DeleteBatchPredictionJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5280,18 +6154,23 @@ def test_delete_batch_prediction_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_delete_batch_prediction_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.DeleteBatchPredictionJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5309,11 +6188,16 @@ async def test_delete_batch_prediction_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_delete_batch_prediction_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5323,29 +6207,38 @@ def test_delete_batch_prediction_job_flattened(): call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_batch_prediction_job(name="name_value",) + client.delete_batch_prediction_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_delete_batch_prediction_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.delete_batch_prediction_job( - job_service.DeleteBatchPredictionJobRequest(), name="name_value", + job_service.DeleteBatchPredictionJobRequest(), + name="name_value", ) @pytest.mark.asyncio async def test_delete_batch_prediction_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5359,32 +6252,45 @@ async def test_delete_batch_prediction_job_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_batch_prediction_job(name="name_value",) + response = await client.delete_batch_prediction_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio async def test_delete_batch_prediction_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.delete_batch_prediction_job( - job_service.DeleteBatchPredictionJobRequest(), name="name_value", + job_service.DeleteBatchPredictionJobRequest(), + name="name_value", ) -def test_cancel_batch_prediction_job( - transport: str = "grpc", request_type=job_service.CancelBatchPredictionJobRequest -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.CancelBatchPredictionJobRequest, + dict, + ], +) +def test_cancel_batch_prediction_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5408,15 +6314,12 @@ def test_cancel_batch_prediction_job( assert response is None -def test_cancel_batch_prediction_job_from_dict(): - test_cancel_batch_prediction_job(request_type=dict) - - def test_cancel_batch_prediction_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5435,7 +6338,8 @@ async def test_cancel_batch_prediction_job_async( request_type=job_service.CancelBatchPredictionJobRequest, ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5465,13 +6369,15 @@ async def test_cancel_batch_prediction_job_async_from_dict(): def test_cancel_batch_prediction_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.CancelBatchPredictionJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5487,18 +6393,23 @@ def test_cancel_batch_prediction_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_cancel_batch_prediction_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.CancelBatchPredictionJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5514,11 +6425,16 @@ async def test_cancel_batch_prediction_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_cancel_batch_prediction_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5528,29 +6444,38 @@ def test_cancel_batch_prediction_job_flattened(): call.return_value = None # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.cancel_batch_prediction_job(name="name_value",) + client.cancel_batch_prediction_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_cancel_batch_prediction_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.cancel_batch_prediction_job( - job_service.CancelBatchPredictionJobRequest(), name="name_value", + job_service.CancelBatchPredictionJobRequest(), + name="name_value", ) @pytest.mark.asyncio async def test_cancel_batch_prediction_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5562,867 +6487,5097 @@ async def test_cancel_batch_prediction_job_flattened_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.cancel_batch_prediction_job(name="name_value",) + response = await client.cancel_batch_prediction_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio async def test_cancel_batch_prediction_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.cancel_batch_prediction_job( - job_service.CancelBatchPredictionJobRequest(), name="name_value", + job_service.CancelBatchPredictionJobRequest(), + name="name_value", ) -def test_credentials_transport_error(): - # It is an error to provide credentials and a transport instance. - transport = transports.JobServiceGrpcTransport( +@pytest.mark.parametrize( + "request_type", + [ + job_service.CreateModelDeploymentMonitoringJobRequest, + dict, + ], +) +def test_create_model_deployment_monitoring_job(request_type, transport: str = "grpc"): + client = JobServiceClient( credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - with pytest.raises(ValueError): - client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, - ) - # It is an error to provide a credentials file and a transport instance. - transport = transports.JobServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = JobServiceClient( - client_options={"credentials_file": "credentials.json"}, - transport=transport, - ) + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() - # It is an error to provide scopes and a transport instance. - transport = transports.JobServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = JobServiceClient( - client_options={"scopes": ["1", "2"]}, transport=transport, + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_model_deployment_monitoring_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob( + name="name_value", + display_name="display_name_value", + endpoint="endpoint_value", + state=job_state.JobState.JOB_STATE_QUEUED, + schedule_state=gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob.MonitoringScheduleState.PENDING, + predict_instance_schema_uri="predict_instance_schema_uri_value", + analysis_instance_schema_uri="analysis_instance_schema_uri_value", + enable_monitoring_pipeline_logs=True, ) + response = client.create_model_deployment_monitoring_job(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == job_service.CreateModelDeploymentMonitoringJobRequest() -def test_transport_instance(): - # A client may be instantiated with a custom transport instance. - transport = transports.JobServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + # Establish that the response is the type that we expect. + assert isinstance( + response, gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob ) - client = JobServiceClient(transport=transport) - assert client.transport is transport + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.endpoint == "endpoint_value" + assert response.state == job_state.JobState.JOB_STATE_QUEUED + assert ( + response.schedule_state + == gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob.MonitoringScheduleState.PENDING + ) + assert response.predict_instance_schema_uri == "predict_instance_schema_uri_value" + assert response.analysis_instance_schema_uri == "analysis_instance_schema_uri_value" + assert response.enable_monitoring_pipeline_logs is True -def test_transport_get_channel(): - # A client may be instantiated with a custom transport instance. - transport = transports.JobServiceGrpcTransport( +def test_create_model_deployment_monitoring_job_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = JobServiceClient( credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) - channel = transport.grpc_channel - assert channel - transport = transports.JobServiceGrpcAsyncIOTransport( + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_model_deployment_monitoring_job), "__call__" + ) as call: + client.create_model_deployment_monitoring_job() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == job_service.CreateModelDeploymentMonitoringJobRequest() + + +@pytest.mark.asyncio +async def test_create_model_deployment_monitoring_job_async( + transport: str = "grpc_asyncio", + request_type=job_service.CreateModelDeploymentMonitoringJobRequest, +): + client = JobServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - channel = transport.grpc_channel - assert channel + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() -@pytest.mark.parametrize( - "transport_class", - [transports.JobServiceGrpcTransport, transports.JobServiceGrpcAsyncIOTransport,], -) -def test_transport_adc(transport_class): - # Test default credentials are used if not provided. - with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class() - adc.assert_called_once() + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_model_deployment_monitoring_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob( + name="name_value", + display_name="display_name_value", + endpoint="endpoint_value", + state=job_state.JobState.JOB_STATE_QUEUED, + schedule_state=gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob.MonitoringScheduleState.PENDING, + predict_instance_schema_uri="predict_instance_schema_uri_value", + analysis_instance_schema_uri="analysis_instance_schema_uri_value", + enable_monitoring_pipeline_logs=True, + ) + ) + response = await client.create_model_deployment_monitoring_job(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == job_service.CreateModelDeploymentMonitoringJobRequest() -def test_transport_grpc_default(): - # A client should use the gRPC transport by default. - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) - assert isinstance(client.transport, transports.JobServiceGrpcTransport,) + # Establish that the response is the type that we expect. + assert isinstance( + response, gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob + ) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.endpoint == "endpoint_value" + assert response.state == job_state.JobState.JOB_STATE_QUEUED + assert ( + response.schedule_state + == gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob.MonitoringScheduleState.PENDING + ) + assert response.predict_instance_schema_uri == "predict_instance_schema_uri_value" + assert response.analysis_instance_schema_uri == "analysis_instance_schema_uri_value" + assert response.enable_monitoring_pipeline_logs is True -def test_job_service_base_transport_error(): - # Passing both a credentials object and credentials_file should raise an error - with pytest.raises(core_exceptions.DuplicateCredentialArgs): - transport = transports.JobServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), - credentials_file="credentials.json", - ) +@pytest.mark.asyncio +async def test_create_model_deployment_monitoring_job_async_from_dict(): + await test_create_model_deployment_monitoring_job_async(request_type=dict) -def test_job_service_base_transport(): - # Instantiate the base transport. - with mock.patch( - "google.cloud.aiplatform_v1.services.job_service.transports.JobServiceTransport.__init__" - ) as Transport: - Transport.return_value = None - transport = transports.JobServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), +def test_create_model_deployment_monitoring_job_field_headers(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = job_service.CreateModelDeploymentMonitoringJobRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_model_deployment_monitoring_job), "__call__" + ) as call: + call.return_value = ( + gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob() ) + client.create_model_deployment_monitoring_job(request) - # Every method on the transport should just blindly - # raise NotImplementedError. - methods = ( - "create_custom_job", - "get_custom_job", - "list_custom_jobs", - "delete_custom_job", - "cancel_custom_job", - "create_data_labeling_job", - "get_data_labeling_job", - "list_data_labeling_jobs", - "delete_data_labeling_job", - "cancel_data_labeling_job", - "create_hyperparameter_tuning_job", - "get_hyperparameter_tuning_job", - "list_hyperparameter_tuning_jobs", - "delete_hyperparameter_tuning_job", - "cancel_hyperparameter_tuning_job", - "create_batch_prediction_job", - "get_batch_prediction_job", - "list_batch_prediction_jobs", - "delete_batch_prediction_job", - "cancel_batch_prediction_job", + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_create_model_deployment_monitoring_job_field_headers_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), ) - for method in methods: - with pytest.raises(NotImplementedError): - getattr(transport, method)(request=object()) - # Additionally, the LRO client (a property) should - # also raise NotImplementedError - with pytest.raises(NotImplementedError): - transport.operations_client + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = job_service.CreateModelDeploymentMonitoringJobRequest() + request.parent = "parent_value" -@requires_google_auth_gte_1_25_0 -def test_job_service_base_transport_with_credentials_file(): - # Instantiate the base transport with a credentials file + # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.aiplatform_v1.services.job_service.transports.JobServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.JobServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=None, - default_scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", + type(client.transport.create_model_deployment_monitoring_job), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob() ) + await client.create_model_deployment_monitoring_job(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request -@requires_google_auth_lt_1_25_0 -def test_job_service_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_create_model_deployment_monitoring_job_flattened(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.aiplatform_v1.services.job_service.transports.JobServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.JobServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", + type(client.transport.create_model_deployment_monitoring_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = ( + gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob() ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_model_deployment_monitoring_job( + parent="parent_value", + model_deployment_monitoring_job=gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob( + name="name_value" + ), ) + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].model_deployment_monitoring_job + mock_val = gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob( + name="name_value" + ) + assert arg == mock_val -def test_job_service_base_transport_with_adc(): - # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.aiplatform_v1.services.job_service.transports.JobServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.JobServiceTransport() - adc.assert_called_once() +def test_create_model_deployment_monitoring_job_flattened_error(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) -@requires_google_auth_gte_1_25_0 -def test_job_service_auth_adc(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - JobServiceClient() - adc.assert_called_once_with( - scopes=None, - default_scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_model_deployment_monitoring_job( + job_service.CreateModelDeploymentMonitoringJobRequest(), + parent="parent_value", + model_deployment_monitoring_job=gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob( + name="name_value" + ), ) -@requires_google_auth_lt_1_25_0 -def test_job_service_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - JobServiceClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, +@pytest.mark.asyncio +async def test_create_model_deployment_monitoring_job_flattened_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_model_deployment_monitoring_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = ( + gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob() ) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_model_deployment_monitoring_job( + parent="parent_value", + model_deployment_monitoring_job=gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob( + name="name_value" + ), + ) -@pytest.mark.parametrize( - "transport_class", - [transports.JobServiceGrpcTransport, transports.JobServiceGrpcAsyncIOTransport,], -) -@requires_google_auth_gte_1_25_0 -def test_job_service_transport_auth_adc(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - adc.assert_called_once_with( - scopes=["1", "2"], - default_scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].model_deployment_monitoring_job + mock_val = gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob( + name="name_value" ) + assert arg == mock_val -@pytest.mark.parametrize( - "transport_class", - [transports.JobServiceGrpcTransport, transports.JobServiceGrpcAsyncIOTransport,], -) -@requires_google_auth_lt_1_25_0 -def test_job_service_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", +@pytest.mark.asyncio +async def test_create_model_deployment_monitoring_job_flattened_error_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.create_model_deployment_monitoring_job( + job_service.CreateModelDeploymentMonitoringJobRequest(), + parent="parent_value", + model_deployment_monitoring_job=gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob( + name="name_value" + ), ) @pytest.mark.parametrize( - "transport_class,grpc_helpers", + "request_type", [ - (transports.JobServiceGrpcTransport, grpc_helpers), - (transports.JobServiceGrpcAsyncIOTransport, grpc_helpers_async), + job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest, + dict, ], ) -@requires_api_core_gte_1_26_0 -def test_job_service_transport_create_channel(transport_class, grpc_helpers): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class(quota_project_id="octopus", scopes=["1", "2"]) +def test_search_model_deployment_monitoring_stats_anomalies( + request_type, transport: str = "grpc" +): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - default_scopes=("https://www.googleapis.com/auth/cloud-platform",), - scopes=["1", "2"], - default_host="aiplatform.googleapis.com", - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.search_model_deployment_monitoring_stats_anomalies), + "__call__", + ) as call: + # Designate an appropriate return value for the call. + call.return_value = ( + job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse( + next_page_token="next_page_token_value", + ) ) + response = client.search_model_deployment_monitoring_stats_anomalies(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert ( + args[0] + == job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest() + ) -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.JobServiceGrpcTransport, grpc_helpers), - (transports.JobServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_job_service_transport_create_channel_old_api_core( - transport_class, grpc_helpers + # Establish that the response is the type that we expect. + assert isinstance( + response, pagers.SearchModelDeploymentMonitoringStatsAnomaliesPager + ) + assert response.next_page_token == "next_page_token_value" + + +def test_search_model_deployment_monitoring_stats_anomalies_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.search_model_deployment_monitoring_stats_anomalies), + "__call__", + ) as call: + client.search_model_deployment_monitoring_stats_anomalies() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert ( + args[0] + == job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest() + ) + + +@pytest.mark.asyncio +async def test_search_model_deployment_monitoring_stats_anomalies_async( + transport: str = "grpc_asyncio", + request_type=job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest, ): - # If credentials and host are not provided, the transport class should use - # ADC credentials. + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class(quota_project_id="octopus") + type(client.transport.search_model_deployment_monitoring_stats_anomalies), + "__call__", + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.search_model_deployment_monitoring_stats_anomalies( + request + ) - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert ( + args[0] + == job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest() ) + # Establish that the response is the type that we expect. + assert isinstance( + response, pagers.SearchModelDeploymentMonitoringStatsAnomaliesAsyncPager + ) + assert response.next_page_token == "next_page_token_value" -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.JobServiceGrpcTransport, grpc_helpers), - (transports.JobServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_job_service_transport_create_channel_user_scopes( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. + +@pytest.mark.asyncio +async def test_search_model_deployment_monitoring_stats_anomalies_async_from_dict(): + await test_search_model_deployment_monitoring_stats_anomalies_async( + request_type=dict + ) + + +def test_search_model_deployment_monitoring_stats_anomalies_field_headers(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest() + + request.model_deployment_monitoring_job = "model_deployment_monitoring_job_value" + + # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) + type(client.transport.search_model_deployment_monitoring_stats_anomalies), + "__call__", + ) as call: + call.return_value = ( + job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse() + ) + client.search_model_deployment_monitoring_stats_anomalies(request) - transport_class(quota_project_id="octopus", scopes=["1", "2"]) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=["1", "2"], - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "model_deployment_monitoring_job=model_deployment_monitoring_job_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_search_model_deployment_monitoring_stats_anomalies_field_headers_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest() + + request.model_deployment_monitoring_job = "model_deployment_monitoring_job_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.search_model_deployment_monitoring_stats_anomalies), + "__call__", + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse() ) + await client.search_model_deployment_monitoring_stats_anomalies(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request -@pytest.mark.parametrize( - "transport_class", - [transports.JobServiceGrpcTransport, transports.JobServiceGrpcAsyncIOTransport], -) -def test_job_service_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "model_deployment_monitoring_job=model_deployment_monitoring_job_value", + ) in kw["metadata"] - # Check ssl_channel_credentials is used if provided. - with mock.patch.object(transport_class, "create_channel") as mock_create_channel: - mock_ssl_channel_creds = mock.Mock() - transport_class( - host="squid.clam.whelk", - credentials=cred, - ssl_channel_credentials=mock_ssl_channel_creds, + +def test_search_model_deployment_monitoring_stats_anomalies_flattened(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.search_model_deployment_monitoring_stats_anomalies), + "__call__", + ) as call: + # Designate an appropriate return value for the call. + call.return_value = ( + job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse() ) - mock_create_channel.assert_called_once_with( - "squid.clam.whelk:443", - credentials=cred, - credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=mock_ssl_channel_creds, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.search_model_deployment_monitoring_stats_anomalies( + model_deployment_monitoring_job="model_deployment_monitoring_job_value", + deployed_model_id="deployed_model_id_value", ) - # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls - # is used. - with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): - with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: - transport_class( - credentials=cred, - client_cert_source_for_mtls=client_cert_source_callback, - ) - expected_cert, expected_key = client_cert_source_callback() - mock_ssl_cred.assert_called_once_with( - certificate_chain=expected_cert, private_key=expected_key - ) + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].model_deployment_monitoring_job + mock_val = "model_deployment_monitoring_job_value" + assert arg == mock_val + arg = args[0].deployed_model_id + mock_val = "deployed_model_id_value" + assert arg == mock_val + + +def test_search_model_deployment_monitoring_stats_anomalies_flattened_error(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.search_model_deployment_monitoring_stats_anomalies( + job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest(), + model_deployment_monitoring_job="model_deployment_monitoring_job_value", + deployed_model_id="deployed_model_id_value", + ) + + +@pytest.mark.asyncio +async def test_search_model_deployment_monitoring_stats_anomalies_flattened_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.search_model_deployment_monitoring_stats_anomalies), + "__call__", + ) as call: + # Designate an appropriate return value for the call. + call.return_value = ( + job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse() + ) + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.search_model_deployment_monitoring_stats_anomalies( + model_deployment_monitoring_job="model_deployment_monitoring_job_value", + deployed_model_id="deployed_model_id_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].model_deployment_monitoring_job + mock_val = "model_deployment_monitoring_job_value" + assert arg == mock_val + arg = args[0].deployed_model_id + mock_val = "deployed_model_id_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_search_model_deployment_monitoring_stats_anomalies_flattened_error_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.search_model_deployment_monitoring_stats_anomalies( + job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest(), + model_deployment_monitoring_job="model_deployment_monitoring_job_value", + deployed_model_id="deployed_model_id_value", + ) + + +def test_search_model_deployment_monitoring_stats_anomalies_pager( + transport_name: str = "grpc", +): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.search_model_deployment_monitoring_stats_anomalies), + "__call__", + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse( + monitoring_stats=[ + gca_model_deployment_monitoring_job.ModelMonitoringStatsAnomalies(), + gca_model_deployment_monitoring_job.ModelMonitoringStatsAnomalies(), + gca_model_deployment_monitoring_job.ModelMonitoringStatsAnomalies(), + ], + next_page_token="abc", + ), + job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse( + monitoring_stats=[], + next_page_token="def", + ), + job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse( + monitoring_stats=[ + gca_model_deployment_monitoring_job.ModelMonitoringStatsAnomalies(), + ], + next_page_token="ghi", + ), + job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse( + monitoring_stats=[ + gca_model_deployment_monitoring_job.ModelMonitoringStatsAnomalies(), + gca_model_deployment_monitoring_job.ModelMonitoringStatsAnomalies(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("model_deployment_monitoring_job", ""),) + ), + ) + pager = client.search_model_deployment_monitoring_stats_anomalies(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all( + isinstance( + i, gca_model_deployment_monitoring_job.ModelMonitoringStatsAnomalies + ) + for i in results + ) + + +def test_search_model_deployment_monitoring_stats_anomalies_pages( + transport_name: str = "grpc", +): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.search_model_deployment_monitoring_stats_anomalies), + "__call__", + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse( + monitoring_stats=[ + gca_model_deployment_monitoring_job.ModelMonitoringStatsAnomalies(), + gca_model_deployment_monitoring_job.ModelMonitoringStatsAnomalies(), + gca_model_deployment_monitoring_job.ModelMonitoringStatsAnomalies(), + ], + next_page_token="abc", + ), + job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse( + monitoring_stats=[], + next_page_token="def", + ), + job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse( + monitoring_stats=[ + gca_model_deployment_monitoring_job.ModelMonitoringStatsAnomalies(), + ], + next_page_token="ghi", + ), + job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse( + monitoring_stats=[ + gca_model_deployment_monitoring_job.ModelMonitoringStatsAnomalies(), + gca_model_deployment_monitoring_job.ModelMonitoringStatsAnomalies(), + ], + ), + RuntimeError, + ) + pages = list( + client.search_model_deployment_monitoring_stats_anomalies(request={}).pages + ) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.asyncio +async def test_search_model_deployment_monitoring_stats_anomalies_async_pager(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.search_model_deployment_monitoring_stats_anomalies), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse( + monitoring_stats=[ + gca_model_deployment_monitoring_job.ModelMonitoringStatsAnomalies(), + gca_model_deployment_monitoring_job.ModelMonitoringStatsAnomalies(), + gca_model_deployment_monitoring_job.ModelMonitoringStatsAnomalies(), + ], + next_page_token="abc", + ), + job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse( + monitoring_stats=[], + next_page_token="def", + ), + job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse( + monitoring_stats=[ + gca_model_deployment_monitoring_job.ModelMonitoringStatsAnomalies(), + ], + next_page_token="ghi", + ), + job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse( + monitoring_stats=[ + gca_model_deployment_monitoring_job.ModelMonitoringStatsAnomalies(), + gca_model_deployment_monitoring_job.ModelMonitoringStatsAnomalies(), + ], + ), + RuntimeError, + ) + async_pager = await client.search_model_deployment_monitoring_stats_anomalies( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all( + isinstance( + i, gca_model_deployment_monitoring_job.ModelMonitoringStatsAnomalies + ) + for i in responses + ) + + +@pytest.mark.asyncio +async def test_search_model_deployment_monitoring_stats_anomalies_async_pages(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.search_model_deployment_monitoring_stats_anomalies), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse( + monitoring_stats=[ + gca_model_deployment_monitoring_job.ModelMonitoringStatsAnomalies(), + gca_model_deployment_monitoring_job.ModelMonitoringStatsAnomalies(), + gca_model_deployment_monitoring_job.ModelMonitoringStatsAnomalies(), + ], + next_page_token="abc", + ), + job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse( + monitoring_stats=[], + next_page_token="def", + ), + job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse( + monitoring_stats=[ + gca_model_deployment_monitoring_job.ModelMonitoringStatsAnomalies(), + ], + next_page_token="ghi", + ), + job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse( + monitoring_stats=[ + gca_model_deployment_monitoring_job.ModelMonitoringStatsAnomalies(), + gca_model_deployment_monitoring_job.ModelMonitoringStatsAnomalies(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.search_model_deployment_monitoring_stats_anomalies(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize( + "request_type", + [ + job_service.GetModelDeploymentMonitoringJobRequest, + dict, + ], +) +def test_get_model_deployment_monitoring_job(request_type, transport: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_model_deployment_monitoring_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = model_deployment_monitoring_job.ModelDeploymentMonitoringJob( + name="name_value", + display_name="display_name_value", + endpoint="endpoint_value", + state=job_state.JobState.JOB_STATE_QUEUED, + schedule_state=model_deployment_monitoring_job.ModelDeploymentMonitoringJob.MonitoringScheduleState.PENDING, + predict_instance_schema_uri="predict_instance_schema_uri_value", + analysis_instance_schema_uri="analysis_instance_schema_uri_value", + enable_monitoring_pipeline_logs=True, + ) + response = client.get_model_deployment_monitoring_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == job_service.GetModelDeploymentMonitoringJobRequest() + + # Establish that the response is the type that we expect. + assert isinstance( + response, model_deployment_monitoring_job.ModelDeploymentMonitoringJob + ) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.endpoint == "endpoint_value" + assert response.state == job_state.JobState.JOB_STATE_QUEUED + assert ( + response.schedule_state + == model_deployment_monitoring_job.ModelDeploymentMonitoringJob.MonitoringScheduleState.PENDING + ) + assert response.predict_instance_schema_uri == "predict_instance_schema_uri_value" + assert response.analysis_instance_schema_uri == "analysis_instance_schema_uri_value" + assert response.enable_monitoring_pipeline_logs is True + + +def test_get_model_deployment_monitoring_job_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_model_deployment_monitoring_job), "__call__" + ) as call: + client.get_model_deployment_monitoring_job() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == job_service.GetModelDeploymentMonitoringJobRequest() + + +@pytest.mark.asyncio +async def test_get_model_deployment_monitoring_job_async( + transport: str = "grpc_asyncio", + request_type=job_service.GetModelDeploymentMonitoringJobRequest, +): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_model_deployment_monitoring_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + model_deployment_monitoring_job.ModelDeploymentMonitoringJob( + name="name_value", + display_name="display_name_value", + endpoint="endpoint_value", + state=job_state.JobState.JOB_STATE_QUEUED, + schedule_state=model_deployment_monitoring_job.ModelDeploymentMonitoringJob.MonitoringScheduleState.PENDING, + predict_instance_schema_uri="predict_instance_schema_uri_value", + analysis_instance_schema_uri="analysis_instance_schema_uri_value", + enable_monitoring_pipeline_logs=True, + ) + ) + response = await client.get_model_deployment_monitoring_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == job_service.GetModelDeploymentMonitoringJobRequest() + + # Establish that the response is the type that we expect. + assert isinstance( + response, model_deployment_monitoring_job.ModelDeploymentMonitoringJob + ) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.endpoint == "endpoint_value" + assert response.state == job_state.JobState.JOB_STATE_QUEUED + assert ( + response.schedule_state + == model_deployment_monitoring_job.ModelDeploymentMonitoringJob.MonitoringScheduleState.PENDING + ) + assert response.predict_instance_schema_uri == "predict_instance_schema_uri_value" + assert response.analysis_instance_schema_uri == "analysis_instance_schema_uri_value" + assert response.enable_monitoring_pipeline_logs is True + + +@pytest.mark.asyncio +async def test_get_model_deployment_monitoring_job_async_from_dict(): + await test_get_model_deployment_monitoring_job_async(request_type=dict) + + +def test_get_model_deployment_monitoring_job_field_headers(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = job_service.GetModelDeploymentMonitoringJobRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_model_deployment_monitoring_job), "__call__" + ) as call: + call.return_value = ( + model_deployment_monitoring_job.ModelDeploymentMonitoringJob() + ) + client.get_model_deployment_monitoring_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_model_deployment_monitoring_job_field_headers_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = job_service.GetModelDeploymentMonitoringJobRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_model_deployment_monitoring_job), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + model_deployment_monitoring_job.ModelDeploymentMonitoringJob() + ) + await client.get_model_deployment_monitoring_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_get_model_deployment_monitoring_job_flattened(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_model_deployment_monitoring_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = ( + model_deployment_monitoring_job.ModelDeploymentMonitoringJob() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_model_deployment_monitoring_job( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_get_model_deployment_monitoring_job_flattened_error(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_model_deployment_monitoring_job( + job_service.GetModelDeploymentMonitoringJobRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_model_deployment_monitoring_job_flattened_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_model_deployment_monitoring_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = ( + model_deployment_monitoring_job.ModelDeploymentMonitoringJob() + ) + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + model_deployment_monitoring_job.ModelDeploymentMonitoringJob() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_model_deployment_monitoring_job( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_get_model_deployment_monitoring_job_flattened_error_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_model_deployment_monitoring_job( + job_service.GetModelDeploymentMonitoringJobRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + job_service.ListModelDeploymentMonitoringJobsRequest, + dict, + ], +) +def test_list_model_deployment_monitoring_jobs(request_type, transport: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_deployment_monitoring_jobs), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = job_service.ListModelDeploymentMonitoringJobsResponse( + next_page_token="next_page_token_value", + ) + response = client.list_model_deployment_monitoring_jobs(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == job_service.ListModelDeploymentMonitoringJobsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListModelDeploymentMonitoringJobsPager) + assert response.next_page_token == "next_page_token_value" + + +def test_list_model_deployment_monitoring_jobs_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_deployment_monitoring_jobs), "__call__" + ) as call: + client.list_model_deployment_monitoring_jobs() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == job_service.ListModelDeploymentMonitoringJobsRequest() + + +@pytest.mark.asyncio +async def test_list_model_deployment_monitoring_jobs_async( + transport: str = "grpc_asyncio", + request_type=job_service.ListModelDeploymentMonitoringJobsRequest, +): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_deployment_monitoring_jobs), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + job_service.ListModelDeploymentMonitoringJobsResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.list_model_deployment_monitoring_jobs(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == job_service.ListModelDeploymentMonitoringJobsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListModelDeploymentMonitoringJobsAsyncPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_list_model_deployment_monitoring_jobs_async_from_dict(): + await test_list_model_deployment_monitoring_jobs_async(request_type=dict) + + +def test_list_model_deployment_monitoring_jobs_field_headers(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = job_service.ListModelDeploymentMonitoringJobsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_deployment_monitoring_jobs), "__call__" + ) as call: + call.return_value = job_service.ListModelDeploymentMonitoringJobsResponse() + client.list_model_deployment_monitoring_jobs(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_model_deployment_monitoring_jobs_field_headers_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = job_service.ListModelDeploymentMonitoringJobsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_deployment_monitoring_jobs), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + job_service.ListModelDeploymentMonitoringJobsResponse() + ) + await client.list_model_deployment_monitoring_jobs(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_list_model_deployment_monitoring_jobs_flattened(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_deployment_monitoring_jobs), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = job_service.ListModelDeploymentMonitoringJobsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_model_deployment_monitoring_jobs( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +def test_list_model_deployment_monitoring_jobs_flattened_error(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_model_deployment_monitoring_jobs( + job_service.ListModelDeploymentMonitoringJobsRequest(), + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_model_deployment_monitoring_jobs_flattened_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_deployment_monitoring_jobs), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = job_service.ListModelDeploymentMonitoringJobsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + job_service.ListModelDeploymentMonitoringJobsResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_model_deployment_monitoring_jobs( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_list_model_deployment_monitoring_jobs_flattened_error_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_model_deployment_monitoring_jobs( + job_service.ListModelDeploymentMonitoringJobsRequest(), + parent="parent_value", + ) + + +def test_list_model_deployment_monitoring_jobs_pager(transport_name: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_deployment_monitoring_jobs), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + job_service.ListModelDeploymentMonitoringJobsResponse( + model_deployment_monitoring_jobs=[ + model_deployment_monitoring_job.ModelDeploymentMonitoringJob(), + model_deployment_monitoring_job.ModelDeploymentMonitoringJob(), + model_deployment_monitoring_job.ModelDeploymentMonitoringJob(), + ], + next_page_token="abc", + ), + job_service.ListModelDeploymentMonitoringJobsResponse( + model_deployment_monitoring_jobs=[], + next_page_token="def", + ), + job_service.ListModelDeploymentMonitoringJobsResponse( + model_deployment_monitoring_jobs=[ + model_deployment_monitoring_job.ModelDeploymentMonitoringJob(), + ], + next_page_token="ghi", + ), + job_service.ListModelDeploymentMonitoringJobsResponse( + model_deployment_monitoring_jobs=[ + model_deployment_monitoring_job.ModelDeploymentMonitoringJob(), + model_deployment_monitoring_job.ModelDeploymentMonitoringJob(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_model_deployment_monitoring_jobs(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all( + isinstance(i, model_deployment_monitoring_job.ModelDeploymentMonitoringJob) + for i in results + ) + + +def test_list_model_deployment_monitoring_jobs_pages(transport_name: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_deployment_monitoring_jobs), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + job_service.ListModelDeploymentMonitoringJobsResponse( + model_deployment_monitoring_jobs=[ + model_deployment_monitoring_job.ModelDeploymentMonitoringJob(), + model_deployment_monitoring_job.ModelDeploymentMonitoringJob(), + model_deployment_monitoring_job.ModelDeploymentMonitoringJob(), + ], + next_page_token="abc", + ), + job_service.ListModelDeploymentMonitoringJobsResponse( + model_deployment_monitoring_jobs=[], + next_page_token="def", + ), + job_service.ListModelDeploymentMonitoringJobsResponse( + model_deployment_monitoring_jobs=[ + model_deployment_monitoring_job.ModelDeploymentMonitoringJob(), + ], + next_page_token="ghi", + ), + job_service.ListModelDeploymentMonitoringJobsResponse( + model_deployment_monitoring_jobs=[ + model_deployment_monitoring_job.ModelDeploymentMonitoringJob(), + model_deployment_monitoring_job.ModelDeploymentMonitoringJob(), + ], + ), + RuntimeError, + ) + pages = list(client.list_model_deployment_monitoring_jobs(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.asyncio +async def test_list_model_deployment_monitoring_jobs_async_pager(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_deployment_monitoring_jobs), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + job_service.ListModelDeploymentMonitoringJobsResponse( + model_deployment_monitoring_jobs=[ + model_deployment_monitoring_job.ModelDeploymentMonitoringJob(), + model_deployment_monitoring_job.ModelDeploymentMonitoringJob(), + model_deployment_monitoring_job.ModelDeploymentMonitoringJob(), + ], + next_page_token="abc", + ), + job_service.ListModelDeploymentMonitoringJobsResponse( + model_deployment_monitoring_jobs=[], + next_page_token="def", + ), + job_service.ListModelDeploymentMonitoringJobsResponse( + model_deployment_monitoring_jobs=[ + model_deployment_monitoring_job.ModelDeploymentMonitoringJob(), + ], + next_page_token="ghi", + ), + job_service.ListModelDeploymentMonitoringJobsResponse( + model_deployment_monitoring_jobs=[ + model_deployment_monitoring_job.ModelDeploymentMonitoringJob(), + model_deployment_monitoring_job.ModelDeploymentMonitoringJob(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_model_deployment_monitoring_jobs( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all( + isinstance(i, model_deployment_monitoring_job.ModelDeploymentMonitoringJob) + for i in responses + ) + + +@pytest.mark.asyncio +async def test_list_model_deployment_monitoring_jobs_async_pages(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_deployment_monitoring_jobs), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + job_service.ListModelDeploymentMonitoringJobsResponse( + model_deployment_monitoring_jobs=[ + model_deployment_monitoring_job.ModelDeploymentMonitoringJob(), + model_deployment_monitoring_job.ModelDeploymentMonitoringJob(), + model_deployment_monitoring_job.ModelDeploymentMonitoringJob(), + ], + next_page_token="abc", + ), + job_service.ListModelDeploymentMonitoringJobsResponse( + model_deployment_monitoring_jobs=[], + next_page_token="def", + ), + job_service.ListModelDeploymentMonitoringJobsResponse( + model_deployment_monitoring_jobs=[ + model_deployment_monitoring_job.ModelDeploymentMonitoringJob(), + ], + next_page_token="ghi", + ), + job_service.ListModelDeploymentMonitoringJobsResponse( + model_deployment_monitoring_jobs=[ + model_deployment_monitoring_job.ModelDeploymentMonitoringJob(), + model_deployment_monitoring_job.ModelDeploymentMonitoringJob(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.list_model_deployment_monitoring_jobs(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize( + "request_type", + [ + job_service.UpdateModelDeploymentMonitoringJobRequest, + dict, + ], +) +def test_update_model_deployment_monitoring_job(request_type, transport: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_model_deployment_monitoring_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.update_model_deployment_monitoring_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == job_service.UpdateModelDeploymentMonitoringJobRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_update_model_deployment_monitoring_job_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_model_deployment_monitoring_job), "__call__" + ) as call: + client.update_model_deployment_monitoring_job() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == job_service.UpdateModelDeploymentMonitoringJobRequest() + + +@pytest.mark.asyncio +async def test_update_model_deployment_monitoring_job_async( + transport: str = "grpc_asyncio", + request_type=job_service.UpdateModelDeploymentMonitoringJobRequest, +): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_model_deployment_monitoring_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.update_model_deployment_monitoring_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == job_service.UpdateModelDeploymentMonitoringJobRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_update_model_deployment_monitoring_job_async_from_dict(): + await test_update_model_deployment_monitoring_job_async(request_type=dict) + + +def test_update_model_deployment_monitoring_job_field_headers(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = job_service.UpdateModelDeploymentMonitoringJobRequest() + + request.model_deployment_monitoring_job.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_model_deployment_monitoring_job), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.update_model_deployment_monitoring_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "model_deployment_monitoring_job.name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_update_model_deployment_monitoring_job_field_headers_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = job_service.UpdateModelDeploymentMonitoringJobRequest() + + request.model_deployment_monitoring_job.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_model_deployment_monitoring_job), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.update_model_deployment_monitoring_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "model_deployment_monitoring_job.name=name_value", + ) in kw["metadata"] + + +def test_update_model_deployment_monitoring_job_flattened(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_model_deployment_monitoring_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.update_model_deployment_monitoring_job( + model_deployment_monitoring_job=gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob( + name="name_value" + ), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].model_deployment_monitoring_job + mock_val = gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob( + name="name_value" + ) + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + + +def test_update_model_deployment_monitoring_job_flattened_error(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_model_deployment_monitoring_job( + job_service.UpdateModelDeploymentMonitoringJobRequest(), + model_deployment_monitoring_job=gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob( + name="name_value" + ), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.asyncio +async def test_update_model_deployment_monitoring_job_flattened_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_model_deployment_monitoring_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.update_model_deployment_monitoring_job( + model_deployment_monitoring_job=gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob( + name="name_value" + ), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].model_deployment_monitoring_job + mock_val = gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob( + name="name_value" + ) + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_update_model_deployment_monitoring_job_flattened_error_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.update_model_deployment_monitoring_job( + job_service.UpdateModelDeploymentMonitoringJobRequest(), + model_deployment_monitoring_job=gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob( + name="name_value" + ), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.parametrize( + "request_type", + [ + job_service.DeleteModelDeploymentMonitoringJobRequest, + dict, + ], +) +def test_delete_model_deployment_monitoring_job(request_type, transport: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_model_deployment_monitoring_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.delete_model_deployment_monitoring_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == job_service.DeleteModelDeploymentMonitoringJobRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_delete_model_deployment_monitoring_job_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_model_deployment_monitoring_job), "__call__" + ) as call: + client.delete_model_deployment_monitoring_job() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == job_service.DeleteModelDeploymentMonitoringJobRequest() + + +@pytest.mark.asyncio +async def test_delete_model_deployment_monitoring_job_async( + transport: str = "grpc_asyncio", + request_type=job_service.DeleteModelDeploymentMonitoringJobRequest, +): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_model_deployment_monitoring_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.delete_model_deployment_monitoring_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == job_service.DeleteModelDeploymentMonitoringJobRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_delete_model_deployment_monitoring_job_async_from_dict(): + await test_delete_model_deployment_monitoring_job_async(request_type=dict) + + +def test_delete_model_deployment_monitoring_job_field_headers(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = job_service.DeleteModelDeploymentMonitoringJobRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_model_deployment_monitoring_job), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_model_deployment_monitoring_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_model_deployment_monitoring_job_field_headers_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = job_service.DeleteModelDeploymentMonitoringJobRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_model_deployment_monitoring_job), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.delete_model_deployment_monitoring_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_delete_model_deployment_monitoring_job_flattened(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_model_deployment_monitoring_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_model_deployment_monitoring_job( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_delete_model_deployment_monitoring_job_flattened_error(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_model_deployment_monitoring_job( + job_service.DeleteModelDeploymentMonitoringJobRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_delete_model_deployment_monitoring_job_flattened_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_model_deployment_monitoring_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_model_deployment_monitoring_job( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_delete_model_deployment_monitoring_job_flattened_error_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.delete_model_deployment_monitoring_job( + job_service.DeleteModelDeploymentMonitoringJobRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + job_service.PauseModelDeploymentMonitoringJobRequest, + dict, + ], +) +def test_pause_model_deployment_monitoring_job(request_type, transport: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.pause_model_deployment_monitoring_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.pause_model_deployment_monitoring_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == job_service.PauseModelDeploymentMonitoringJobRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +def test_pause_model_deployment_monitoring_job_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.pause_model_deployment_monitoring_job), "__call__" + ) as call: + client.pause_model_deployment_monitoring_job() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == job_service.PauseModelDeploymentMonitoringJobRequest() + + +@pytest.mark.asyncio +async def test_pause_model_deployment_monitoring_job_async( + transport: str = "grpc_asyncio", + request_type=job_service.PauseModelDeploymentMonitoringJobRequest, +): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.pause_model_deployment_monitoring_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.pause_model_deployment_monitoring_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == job_service.PauseModelDeploymentMonitoringJobRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_pause_model_deployment_monitoring_job_async_from_dict(): + await test_pause_model_deployment_monitoring_job_async(request_type=dict) + + +def test_pause_model_deployment_monitoring_job_field_headers(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = job_service.PauseModelDeploymentMonitoringJobRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.pause_model_deployment_monitoring_job), "__call__" + ) as call: + call.return_value = None + client.pause_model_deployment_monitoring_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_pause_model_deployment_monitoring_job_field_headers_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = job_service.PauseModelDeploymentMonitoringJobRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.pause_model_deployment_monitoring_job), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.pause_model_deployment_monitoring_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_pause_model_deployment_monitoring_job_flattened(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.pause_model_deployment_monitoring_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = None + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.pause_model_deployment_monitoring_job( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_pause_model_deployment_monitoring_job_flattened_error(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.pause_model_deployment_monitoring_job( + job_service.PauseModelDeploymentMonitoringJobRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_pause_model_deployment_monitoring_job_flattened_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.pause_model_deployment_monitoring_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = None + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.pause_model_deployment_monitoring_job( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_pause_model_deployment_monitoring_job_flattened_error_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.pause_model_deployment_monitoring_job( + job_service.PauseModelDeploymentMonitoringJobRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + job_service.ResumeModelDeploymentMonitoringJobRequest, + dict, + ], +) +def test_resume_model_deployment_monitoring_job(request_type, transport: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.resume_model_deployment_monitoring_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.resume_model_deployment_monitoring_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == job_service.ResumeModelDeploymentMonitoringJobRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +def test_resume_model_deployment_monitoring_job_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.resume_model_deployment_monitoring_job), "__call__" + ) as call: + client.resume_model_deployment_monitoring_job() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == job_service.ResumeModelDeploymentMonitoringJobRequest() + + +@pytest.mark.asyncio +async def test_resume_model_deployment_monitoring_job_async( + transport: str = "grpc_asyncio", + request_type=job_service.ResumeModelDeploymentMonitoringJobRequest, +): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.resume_model_deployment_monitoring_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.resume_model_deployment_monitoring_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == job_service.ResumeModelDeploymentMonitoringJobRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_resume_model_deployment_monitoring_job_async_from_dict(): + await test_resume_model_deployment_monitoring_job_async(request_type=dict) + + +def test_resume_model_deployment_monitoring_job_field_headers(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = job_service.ResumeModelDeploymentMonitoringJobRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.resume_model_deployment_monitoring_job), "__call__" + ) as call: + call.return_value = None + client.resume_model_deployment_monitoring_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_resume_model_deployment_monitoring_job_field_headers_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = job_service.ResumeModelDeploymentMonitoringJobRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.resume_model_deployment_monitoring_job), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.resume_model_deployment_monitoring_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_resume_model_deployment_monitoring_job_flattened(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.resume_model_deployment_monitoring_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = None + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.resume_model_deployment_monitoring_job( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_resume_model_deployment_monitoring_job_flattened_error(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.resume_model_deployment_monitoring_job( + job_service.ResumeModelDeploymentMonitoringJobRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_resume_model_deployment_monitoring_job_flattened_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.resume_model_deployment_monitoring_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = None + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.resume_model_deployment_monitoring_job( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_resume_model_deployment_monitoring_job_flattened_error_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.resume_model_deployment_monitoring_job( + job_service.ResumeModelDeploymentMonitoringJobRequest(), + name="name_value", + ) + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.JobServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.JobServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = JobServiceClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide an api_key and a transport instance. + transport = transports.JobServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = JobServiceClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = JobServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.JobServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = JobServiceClient( + client_options={"scopes": ["1", "2"]}, + transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.JobServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + client = JobServiceClient(transport=transport) + assert client.transport is transport + + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.JobServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.JobServiceGrpcAsyncIOTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.JobServiceGrpcTransport, + transports.JobServiceGrpcAsyncIOTransport, + ], +) +def test_transport_adc(transport_class): + # Test default credentials are used if not provided. + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class() + adc.assert_called_once() + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = JobServiceClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + +def test_transport_grpc_default(): + # A client should use the gRPC transport by default. + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.JobServiceGrpcTransport, + ) + + +def test_job_service_base_transport_error(): + # Passing both a credentials object and credentials_file should raise an error + with pytest.raises(core_exceptions.DuplicateCredentialArgs): + transport = transports.JobServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + credentials_file="credentials.json", + ) + + +def test_job_service_base_transport(): + # Instantiate the base transport. + with mock.patch( + "google.cloud.aiplatform_v1.services.job_service.transports.JobServiceTransport.__init__" + ) as Transport: + Transport.return_value = None + transport = transports.JobServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Every method on the transport should just blindly + # raise NotImplementedError. + methods = ( + "create_custom_job", + "get_custom_job", + "list_custom_jobs", + "delete_custom_job", + "cancel_custom_job", + "create_data_labeling_job", + "get_data_labeling_job", + "list_data_labeling_jobs", + "delete_data_labeling_job", + "cancel_data_labeling_job", + "create_hyperparameter_tuning_job", + "get_hyperparameter_tuning_job", + "list_hyperparameter_tuning_jobs", + "delete_hyperparameter_tuning_job", + "cancel_hyperparameter_tuning_job", + "create_batch_prediction_job", + "get_batch_prediction_job", + "list_batch_prediction_jobs", + "delete_batch_prediction_job", + "cancel_batch_prediction_job", + "create_model_deployment_monitoring_job", + "search_model_deployment_monitoring_stats_anomalies", + "get_model_deployment_monitoring_job", + "list_model_deployment_monitoring_jobs", + "update_model_deployment_monitoring_job", + "delete_model_deployment_monitoring_job", + "pause_model_deployment_monitoring_job", + "resume_model_deployment_monitoring_job", + "set_iam_policy", + "get_iam_policy", + "test_iam_permissions", + "get_location", + "list_locations", + "get_operation", + "wait_operation", + "cancel_operation", + "delete_operation", + "list_operations", + ) + for method in methods: + with pytest.raises(NotImplementedError): + getattr(transport, method)(request=object()) + + with pytest.raises(NotImplementedError): + transport.close() + + # Additionally, the LRO client (a property) should + # also raise NotImplementedError + with pytest.raises(NotImplementedError): + transport.operations_client + + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + + +def test_job_service_base_transport_with_credentials_file(): + # Instantiate the base transport with a credentials file + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch( + "google.cloud.aiplatform_v1.services.job_service.transports.JobServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.JobServiceTransport( + credentials_file="credentials.json", + quota_project_id="octopus", + ) + load_creds.assert_called_once_with( + "credentials.json", + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +def test_job_service_base_transport_with_adc(): + # Test the default credentials are used if credentials and credentials_file are None. + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( + "google.cloud.aiplatform_v1.services.job_service.transports.JobServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.JobServiceTransport() + adc.assert_called_once() + + +def test_job_service_auth_adc(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + JobServiceClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id=None, + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.JobServiceGrpcTransport, + transports.JobServiceGrpcAsyncIOTransport, + ], +) +def test_job_service_transport_auth_adc(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.JobServiceGrpcTransport, grpc_helpers), + (transports.JobServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +def test_job_service_transport_create_channel(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=["1", "2"], + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class", + [transports.JobServiceGrpcTransport, transports.JobServiceGrpcAsyncIOTransport], +) +def test_job_service_grpc_transport_client_cert_source_for_mtls(transport_class): + cred = ga_credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds, + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback, + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, private_key=expected_key + ) + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_job_service_host_no_port(transport_name): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions( + api_endpoint="aiplatform.googleapis.com" + ), + transport=transport_name, + ) + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_job_service_host_with_port(transport_name): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions( + api_endpoint="aiplatform.googleapis.com:8000" + ), + transport=transport_name, + ) + assert client.transport._host == ("aiplatform.googleapis.com:8000") + + +def test_job_service_grpc_transport_channel(): + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.JobServiceGrpcTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +def test_job_service_grpc_asyncio_transport_channel(): + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.JobServiceGrpcAsyncIOTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize( + "transport_class", + [transports.JobServiceGrpcTransport, transports.JobServiceGrpcAsyncIOTransport], +) +def test_job_service_transport_channel_mtls_with_client_cert_source(transport_class): + with mock.patch( + "grpc.ssl_channel_credentials", autospec=True + ) as grpc_ssl_channel_cred: + with mock.patch.object( + transport_class, "create_channel" + ) as grpc_create_channel: + mock_ssl_cred = mock.Mock() + grpc_ssl_channel_cred.return_value = mock_ssl_cred + + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + + cred = ga_credentials.AnonymousCredentials() + with pytest.warns(DeprecationWarning): + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (cred, None) + transport = transport_class( + host="squid.clam.whelk", + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=client_cert_source_callback, + ) + adc.assert_called_once() + + grpc_ssl_channel_cred.assert_called_once_with( + certificate_chain=b"cert bytes", private_key=b"key bytes" + ) + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize( + "transport_class", + [transports.JobServiceGrpcTransport, transports.JobServiceGrpcAsyncIOTransport], +) +def test_job_service_transport_channel_mtls_with_adc(transport_class): + mock_ssl_cred = mock.Mock() + with mock.patch.multiple( + "google.auth.transport.grpc.SslCredentials", + __init__=mock.Mock(return_value=None), + ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), + ): + with mock.patch.object( + transport_class, "create_channel" + ) as grpc_create_channel: + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + mock_cred = mock.Mock() + + with pytest.warns(DeprecationWarning): + transport = transport_class( + host="squid.clam.whelk", + credentials=mock_cred, + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=None, + ) + + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=mock_cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + + +def test_job_service_grpc_lro_client(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_job_service_grpc_lro_async_client(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_batch_prediction_job_path(): + project = "squid" + location = "clam" + batch_prediction_job = "whelk" + expected = "projects/{project}/locations/{location}/batchPredictionJobs/{batch_prediction_job}".format( + project=project, + location=location, + batch_prediction_job=batch_prediction_job, + ) + actual = JobServiceClient.batch_prediction_job_path( + project, location, batch_prediction_job + ) + assert expected == actual + + +def test_parse_batch_prediction_job_path(): + expected = { + "project": "octopus", + "location": "oyster", + "batch_prediction_job": "nudibranch", + } + path = JobServiceClient.batch_prediction_job_path(**expected) + + # Check that the path construction is reversible. + actual = JobServiceClient.parse_batch_prediction_job_path(path) + assert expected == actual + + +def test_custom_job_path(): + project = "cuttlefish" + location = "mussel" + custom_job = "winkle" + expected = "projects/{project}/locations/{location}/customJobs/{custom_job}".format( + project=project, + location=location, + custom_job=custom_job, + ) + actual = JobServiceClient.custom_job_path(project, location, custom_job) + assert expected == actual + + +def test_parse_custom_job_path(): + expected = { + "project": "nautilus", + "location": "scallop", + "custom_job": "abalone", + } + path = JobServiceClient.custom_job_path(**expected) + + # Check that the path construction is reversible. + actual = JobServiceClient.parse_custom_job_path(path) + assert expected == actual + + +def test_data_labeling_job_path(): + project = "squid" + location = "clam" + data_labeling_job = "whelk" + expected = "projects/{project}/locations/{location}/dataLabelingJobs/{data_labeling_job}".format( + project=project, + location=location, + data_labeling_job=data_labeling_job, + ) + actual = JobServiceClient.data_labeling_job_path( + project, location, data_labeling_job + ) + assert expected == actual + + +def test_parse_data_labeling_job_path(): + expected = { + "project": "octopus", + "location": "oyster", + "data_labeling_job": "nudibranch", + } + path = JobServiceClient.data_labeling_job_path(**expected) + + # Check that the path construction is reversible. + actual = JobServiceClient.parse_data_labeling_job_path(path) + assert expected == actual + + +def test_dataset_path(): + project = "cuttlefish" + location = "mussel" + dataset = "winkle" + expected = "projects/{project}/locations/{location}/datasets/{dataset}".format( + project=project, + location=location, + dataset=dataset, + ) + actual = JobServiceClient.dataset_path(project, location, dataset) + assert expected == actual + + +def test_parse_dataset_path(): + expected = { + "project": "nautilus", + "location": "scallop", + "dataset": "abalone", + } + path = JobServiceClient.dataset_path(**expected) + + # Check that the path construction is reversible. + actual = JobServiceClient.parse_dataset_path(path) + assert expected == actual + + +def test_endpoint_path(): + project = "squid" + location = "clam" + endpoint = "whelk" + expected = "projects/{project}/locations/{location}/endpoints/{endpoint}".format( + project=project, + location=location, + endpoint=endpoint, + ) + actual = JobServiceClient.endpoint_path(project, location, endpoint) + assert expected == actual + + +def test_parse_endpoint_path(): + expected = { + "project": "octopus", + "location": "oyster", + "endpoint": "nudibranch", + } + path = JobServiceClient.endpoint_path(**expected) + + # Check that the path construction is reversible. + actual = JobServiceClient.parse_endpoint_path(path) + assert expected == actual + + +def test_hyperparameter_tuning_job_path(): + project = "cuttlefish" + location = "mussel" + hyperparameter_tuning_job = "winkle" + expected = "projects/{project}/locations/{location}/hyperparameterTuningJobs/{hyperparameter_tuning_job}".format( + project=project, + location=location, + hyperparameter_tuning_job=hyperparameter_tuning_job, + ) + actual = JobServiceClient.hyperparameter_tuning_job_path( + project, location, hyperparameter_tuning_job + ) + assert expected == actual + + +def test_parse_hyperparameter_tuning_job_path(): + expected = { + "project": "nautilus", + "location": "scallop", + "hyperparameter_tuning_job": "abalone", + } + path = JobServiceClient.hyperparameter_tuning_job_path(**expected) + + # Check that the path construction is reversible. + actual = JobServiceClient.parse_hyperparameter_tuning_job_path(path) + assert expected == actual + + +def test_model_path(): + project = "squid" + location = "clam" + model = "whelk" + expected = "projects/{project}/locations/{location}/models/{model}".format( + project=project, + location=location, + model=model, + ) + actual = JobServiceClient.model_path(project, location, model) + assert expected == actual + + +def test_parse_model_path(): + expected = { + "project": "octopus", + "location": "oyster", + "model": "nudibranch", + } + path = JobServiceClient.model_path(**expected) + + # Check that the path construction is reversible. + actual = JobServiceClient.parse_model_path(path) + assert expected == actual + + +def test_model_deployment_monitoring_job_path(): + project = "cuttlefish" + location = "mussel" + model_deployment_monitoring_job = "winkle" + expected = "projects/{project}/locations/{location}/modelDeploymentMonitoringJobs/{model_deployment_monitoring_job}".format( + project=project, + location=location, + model_deployment_monitoring_job=model_deployment_monitoring_job, + ) + actual = JobServiceClient.model_deployment_monitoring_job_path( + project, location, model_deployment_monitoring_job + ) + assert expected == actual + + +def test_parse_model_deployment_monitoring_job_path(): + expected = { + "project": "nautilus", + "location": "scallop", + "model_deployment_monitoring_job": "abalone", + } + path = JobServiceClient.model_deployment_monitoring_job_path(**expected) + + # Check that the path construction is reversible. + actual = JobServiceClient.parse_model_deployment_monitoring_job_path(path) + assert expected == actual + + +def test_network_path(): + project = "squid" + network = "clam" + expected = "projects/{project}/global/networks/{network}".format( + project=project, + network=network, + ) + actual = JobServiceClient.network_path(project, network) + assert expected == actual + + +def test_parse_network_path(): + expected = { + "project": "whelk", + "network": "octopus", + } + path = JobServiceClient.network_path(**expected) + + # Check that the path construction is reversible. + actual = JobServiceClient.parse_network_path(path) + assert expected == actual + + +def test_tensorboard_path(): + project = "oyster" + location = "nudibranch" + tensorboard = "cuttlefish" + expected = ( + "projects/{project}/locations/{location}/tensorboards/{tensorboard}".format( + project=project, + location=location, + tensorboard=tensorboard, + ) + ) + actual = JobServiceClient.tensorboard_path(project, location, tensorboard) + assert expected == actual + + +def test_parse_tensorboard_path(): + expected = { + "project": "mussel", + "location": "winkle", + "tensorboard": "nautilus", + } + path = JobServiceClient.tensorboard_path(**expected) + + # Check that the path construction is reversible. + actual = JobServiceClient.parse_tensorboard_path(path) + assert expected == actual + + +def test_trial_path(): + project = "scallop" + location = "abalone" + study = "squid" + trial = "clam" + expected = ( + "projects/{project}/locations/{location}/studies/{study}/trials/{trial}".format( + project=project, + location=location, + study=study, + trial=trial, + ) + ) + actual = JobServiceClient.trial_path(project, location, study, trial) + assert expected == actual + + +def test_parse_trial_path(): + expected = { + "project": "whelk", + "location": "octopus", + "study": "oyster", + "trial": "nudibranch", + } + path = JobServiceClient.trial_path(**expected) + + # Check that the path construction is reversible. + actual = JobServiceClient.parse_trial_path(path) + assert expected == actual + + +def test_common_billing_account_path(): + billing_account = "cuttlefish" + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + actual = JobServiceClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "mussel", + } + path = JobServiceClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = JobServiceClient.parse_common_billing_account_path(path) + assert expected == actual + + +def test_common_folder_path(): + folder = "winkle" + expected = "folders/{folder}".format( + folder=folder, + ) + actual = JobServiceClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "nautilus", + } + path = JobServiceClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = JobServiceClient.parse_common_folder_path(path) + assert expected == actual + + +def test_common_organization_path(): + organization = "scallop" + expected = "organizations/{organization}".format( + organization=organization, + ) + actual = JobServiceClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "abalone", + } + path = JobServiceClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = JobServiceClient.parse_common_organization_path(path) + assert expected == actual + + +def test_common_project_path(): + project = "squid" + expected = "projects/{project}".format( + project=project, + ) + actual = JobServiceClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "clam", + } + path = JobServiceClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = JobServiceClient.parse_common_project_path(path) + assert expected == actual + + +def test_common_location_path(): + project = "whelk" + location = "octopus" + expected = "projects/{project}/locations/{location}".format( + project=project, + location=location, + ) + actual = JobServiceClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "oyster", + "location": "nudibranch", + } + path = JobServiceClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = JobServiceClient.parse_common_location_path(path) + assert expected == actual + + +def test_client_with_default_client_info(): + client_info = gapic_v1.client_info.ClientInfo() + + with mock.patch.object( + transports.JobServiceTransport, "_prep_wrapped_messages" + ) as prep: + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + with mock.patch.object( + transports.JobServiceTransport, "_prep_wrapped_messages" + ) as prep: + transport_class = JobServiceClient.get_transport_class() + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_delete_operation(transport: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_operation(transport: str = "grpc"): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_operation_field_headers(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = None + + client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_operation_field_headers_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_delete_operation_from_dict(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_delete_operation_from_dict_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_cancel_operation(transport: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation(transport: str = "grpc"): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_wait_operation(transport: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_wait_operation(transport: str = "grpc"): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_wait_operation_field_headers(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_wait_operation_field_headers_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_wait_operation_from_dict(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_wait_operation_from_dict_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_operation(transport: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_get_operation(transport: str = "grpc"): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_get_operation_field_headers(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_get_operation_from_dict(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_operations(transport: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + response = client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +@pytest.mark.asyncio +async def test_list_operations(transport: str = "grpc"): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +def test_list_operations_field_headers(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_operations_field_headers_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_operations_from_dict(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + response = client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_operations_from_dict_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_locations(transport: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + response = client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +@pytest.mark.asyncio +async def test_list_locations(transport: str = "grpc"): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +def test_list_locations_field_headers(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_locations_field_headers_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_locations_from_dict(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + response = client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_locations_from_dict_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_location(transport: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + response = client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +@pytest.mark.asyncio +async def test_get_location_async(transport: str = "grpc_asyncio"): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +def test_get_location_field_headers(): + client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials()) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = locations_pb2.Location() + + client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_location_field_headers_async(): + client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials()) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +def test_get_location_from_dict(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + response = client.get_location( + request={ + "name": "locations/abc", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_location_from_dict_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_set_iam_policy(transport: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + response = client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + response = await client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_set_iam_policy_field_headers(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_set_iam_policy_field_headers_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) -def test_job_service_host_no_port(): - client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions( - api_endpoint="aiplatform.googleapis.com" - ), - ) - assert client.transport._host == "aiplatform.googleapis.com:443" + await client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] -def test_job_service_host_with_port(): +def test_set_iam_policy_from_dict(): client = JobServiceClient( credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions( - api_endpoint="aiplatform.googleapis.com:8000" - ), ) - assert client.transport._host == "aiplatform.googleapis.com:8000" + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + response = client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() -def test_job_service_grpc_transport_channel(): - channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) - # Check that channel is used if provided. - transport = transports.JobServiceGrpcTransport( - host="squid.clam.whelk", channel=channel, +@pytest.mark.asyncio +async def test_set_iam_policy_from_dict_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), ) - assert transport.grpc_channel == channel - assert transport._host == "squid.clam.whelk:443" - assert transport._ssl_channel_credentials == None + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + response = await client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() -def test_job_service_grpc_asyncio_transport_channel(): - channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) - # Check that channel is used if provided. - transport = transports.JobServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", channel=channel, +def test_get_iam_policy(transport: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - assert transport.grpc_channel == channel - assert transport._host == "squid.clam.whelk:443" - assert transport._ssl_channel_credentials == None + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() -# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are -# removed from grpc/grpc_asyncio transport constructor. -@pytest.mark.parametrize( - "transport_class", - [transports.JobServiceGrpcTransport, transports.JobServiceGrpcAsyncIOTransport], -) -def test_job_service_transport_channel_mtls_with_client_cert_source(transport_class): - with mock.patch( - "grpc.ssl_channel_credentials", autospec=True - ) as grpc_ssl_channel_cred: - with mock.patch.object( - transport_class, "create_channel" - ) as grpc_create_channel: - mock_ssl_cred = mock.Mock() - grpc_ssl_channel_cred.return_value = mock_ssl_cred - - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) - cred = ga_credentials.AnonymousCredentials() - with pytest.warns(DeprecationWarning): - with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (cred, None) - transport = transport_class( - host="squid.clam.whelk", - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=client_cert_source_callback, - ) - adc.assert_called_once() + response = client.get_iam_policy(request) - grpc_ssl_channel_cred.assert_called_once_with( - certificate_chain=b"cert bytes", private_key=b"key bytes" - ) - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=cred, - credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - assert transport.grpc_channel == mock_grpc_channel - assert transport._ssl_channel_credentials == mock_ssl_cred + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request -# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are -# removed from grpc/grpc_asyncio transport constructor. -@pytest.mark.parametrize( - "transport_class", - [transports.JobServiceGrpcTransport, transports.JobServiceGrpcAsyncIOTransport], -) -def test_job_service_transport_channel_mtls_with_adc(transport_class): - mock_ssl_cred = mock.Mock() - with mock.patch.multiple( - "google.auth.transport.grpc.SslCredentials", - __init__=mock.Mock(return_value=None), - ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), - ): - with mock.patch.object( - transport_class, "create_channel" - ) as grpc_create_channel: - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel - mock_cred = mock.Mock() + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) - with pytest.warns(DeprecationWarning): - transport = transport_class( - host="squid.clam.whelk", - credentials=mock_cred, - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=None, - ) + assert response.version == 774 - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=mock_cred, - credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - assert transport.grpc_channel == mock_grpc_channel + assert response.etag == b"etag_blob" -def test_job_service_grpc_lro_client(): - client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", +@pytest.mark.asyncio +async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - transport = client.transport - # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsClient,) - - # Ensure that subsequent calls to the property send the exact same object. - assert transport.operations_client is transport.operations_client + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) -def test_job_service_grpc_lro_async_client(): - client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", - ) - transport = client.transport + response = await client.get_iam_policy(request) - # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient,) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] - # Ensure that subsequent calls to the property send the exact same object. - assert transport.operations_client is transport.operations_client + assert args[0] == request + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) -def test_batch_prediction_job_path(): - project = "squid" - location = "clam" - batch_prediction_job = "whelk" - expected = "projects/{project}/locations/{location}/batchPredictionJobs/{batch_prediction_job}".format( - project=project, location=location, batch_prediction_job=batch_prediction_job, - ) - actual = JobServiceClient.batch_prediction_job_path( - project, location, batch_prediction_job - ) - assert expected == actual + assert response.version == 774 + assert response.etag == b"etag_blob" -def test_parse_batch_prediction_job_path(): - expected = { - "project": "octopus", - "location": "oyster", - "batch_prediction_job": "nudibranch", - } - path = JobServiceClient.batch_prediction_job_path(**expected) - # Check that the path construction is reversible. - actual = JobServiceClient.parse_batch_prediction_job_path(path) - assert expected == actual +def test_get_iam_policy_field_headers(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" -def test_custom_job_path(): - project = "cuttlefish" - location = "mussel" - custom_job = "winkle" - expected = "projects/{project}/locations/{location}/customJobs/{custom_job}".format( - project=project, location=location, custom_job=custom_job, - ) - actual = JobServiceClient.custom_job_path(project, location, custom_job) - assert expected == actual + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + client.get_iam_policy(request) -def test_parse_custom_job_path(): - expected = { - "project": "nautilus", - "location": "scallop", - "custom_job": "abalone", - } - path = JobServiceClient.custom_job_path(**expected) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request - # Check that the path construction is reversible. - actual = JobServiceClient.parse_custom_job_path(path) - assert expected == actual + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] -def test_data_labeling_job_path(): - project = "squid" - location = "clam" - data_labeling_job = "whelk" - expected = "projects/{project}/locations/{location}/dataLabelingJobs/{data_labeling_job}".format( - project=project, location=location, data_labeling_job=data_labeling_job, - ) - actual = JobServiceClient.data_labeling_job_path( - project, location, data_labeling_job +@pytest.mark.asyncio +async def test_get_iam_policy_field_headers_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), ) - assert expected == actual + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" -def test_parse_data_labeling_job_path(): - expected = { - "project": "octopus", - "location": "oyster", - "data_labeling_job": "nudibranch", - } - path = JobServiceClient.data_labeling_job_path(**expected) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) - # Check that the path construction is reversible. - actual = JobServiceClient.parse_data_labeling_job_path(path) - assert expected == actual + await client.get_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request -def test_dataset_path(): - project = "cuttlefish" - location = "mussel" - dataset = "winkle" - expected = "projects/{project}/locations/{location}/datasets/{dataset}".format( - project=project, location=location, dataset=dataset, - ) - actual = JobServiceClient.dataset_path(project, location, dataset) - assert expected == actual + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] -def test_parse_dataset_path(): - expected = { - "project": "nautilus", - "location": "scallop", - "dataset": "abalone", - } - path = JobServiceClient.dataset_path(**expected) +def test_get_iam_policy_from_dict(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() - # Check that the path construction is reversible. - actual = JobServiceClient.parse_dataset_path(path) - assert expected == actual + response = client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() -def test_hyperparameter_tuning_job_path(): - project = "squid" - location = "clam" - hyperparameter_tuning_job = "whelk" - expected = "projects/{project}/locations/{location}/hyperparameterTuningJobs/{hyperparameter_tuning_job}".format( - project=project, - location=location, - hyperparameter_tuning_job=hyperparameter_tuning_job, - ) - actual = JobServiceClient.hyperparameter_tuning_job_path( - project, location, hyperparameter_tuning_job +@pytest.mark.asyncio +async def test_get_iam_policy_from_dict_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), ) - assert expected == actual + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + response = await client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() -def test_parse_hyperparameter_tuning_job_path(): - expected = { - "project": "octopus", - "location": "oyster", - "hyperparameter_tuning_job": "nudibranch", - } - path = JobServiceClient.hyperparameter_tuning_job_path(**expected) - # Check that the path construction is reversible. - actual = JobServiceClient.parse_hyperparameter_tuning_job_path(path) - assert expected == actual +def test_test_iam_permissions(transport: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() -def test_model_path(): - project = "cuttlefish" - location = "mussel" - model = "winkle" - expected = "projects/{project}/locations/{location}/models/{model}".format( - project=project, location=location, model=model, - ) - actual = JobServiceClient.model_path(project, location, model) - assert expected == actual + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + response = client.test_iam_permissions(request) -def test_parse_model_path(): - expected = { - "project": "nautilus", - "location": "scallop", - "model": "abalone", - } - path = JobServiceClient.model_path(**expected) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] - # Check that the path construction is reversible. - actual = JobServiceClient.parse_model_path(path) - assert expected == actual + assert args[0] == request + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) -def test_trial_path(): - project = "squid" - location = "clam" - study = "whelk" - trial = "octopus" - expected = "projects/{project}/locations/{location}/studies/{study}/trials/{trial}".format( - project=project, location=location, study=study, trial=trial, - ) - actual = JobServiceClient.trial_path(project, location, study, trial) - assert expected == actual + assert response.permissions == ["permissions_value"] -def test_parse_trial_path(): - expected = { - "project": "oyster", - "location": "nudibranch", - "study": "cuttlefish", - "trial": "mussel", - } - path = JobServiceClient.trial_path(**expected) +@pytest.mark.asyncio +async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) - # Check that the path construction is reversible. - actual = JobServiceClient.parse_trial_path(path) - assert expected == actual + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + ) -def test_common_billing_account_path(): - billing_account = "winkle" - expected = "billingAccounts/{billing_account}".format( - billing_account=billing_account, - ) - actual = JobServiceClient.common_billing_account_path(billing_account) - assert expected == actual + response = await client.test_iam_permissions(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] -def test_parse_common_billing_account_path(): - expected = { - "billing_account": "nautilus", - } - path = JobServiceClient.common_billing_account_path(**expected) + assert args[0] == request - # Check that the path construction is reversible. - actual = JobServiceClient.parse_common_billing_account_path(path) - assert expected == actual + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + assert response.permissions == ["permissions_value"] -def test_common_folder_path(): - folder = "scallop" - expected = "folders/{folder}".format(folder=folder,) - actual = JobServiceClient.common_folder_path(folder) - assert expected == actual +def test_test_iam_permissions_field_headers(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) -def test_parse_common_folder_path(): - expected = { - "folder": "abalone", - } - path = JobServiceClient.common_folder_path(**expected) + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" - # Check that the path construction is reversible. - actual = JobServiceClient.parse_common_folder_path(path) - assert expected == actual + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + client.test_iam_permissions(request) -def test_common_organization_path(): - organization = "squid" - expected = "organizations/{organization}".format(organization=organization,) - actual = JobServiceClient.common_organization_path(organization) - assert expected == actual + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] -def test_parse_common_organization_path(): - expected = { - "organization": "clam", - } - path = JobServiceClient.common_organization_path(**expected) - # Check that the path construction is reversible. - actual = JobServiceClient.parse_common_organization_path(path) - assert expected == actual +@pytest.mark.asyncio +async def test_test_iam_permissions_field_headers_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" -def test_common_project_path(): - project = "whelk" - expected = "projects/{project}".format(project=project,) - actual = JobServiceClient.common_project_path(project) - assert expected == actual + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + await client.test_iam_permissions(request) -def test_parse_common_project_path(): - expected = { - "project": "octopus", - } - path = JobServiceClient.common_project_path(**expected) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request - # Check that the path construction is reversible. - actual = JobServiceClient.parse_common_project_path(path) - assert expected == actual + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] -def test_common_location_path(): - project = "oyster" - location = "nudibranch" - expected = "projects/{project}/locations/{location}".format( - project=project, location=location, +def test_test_iam_permissions_from_dict(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), ) - actual = JobServiceClient.common_location_path(project, location) - assert expected == actual + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + response = client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() -def test_parse_common_location_path(): - expected = { - "project": "cuttlefish", - "location": "mussel", - } - path = JobServiceClient.common_location_path(**expected) - # Check that the path construction is reversible. - actual = JobServiceClient.parse_common_location_path(path) - assert expected == actual +@pytest.mark.asyncio +async def test_test_iam_permissions_from_dict_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + response = await client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() -def test_client_withDEFAULT_CLIENT_INFO(): - client_info = gapic_v1.client_info.ClientInfo() - with mock.patch.object( - transports.JobServiceTransport, "_prep_wrapped_messages" - ) as prep: +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), transport=transport ) - prep.assert_called_once_with(client_info) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() - with mock.patch.object( - transports.JobServiceTransport, "_prep_wrapped_messages" - ) as prep: - transport_class = JobServiceClient.get_transport_class() - transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport ) - prep.assert_called_once_with(client_info) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (JobServiceClient, transports.JobServiceGrpcTransport), + (JobServiceAsyncClient, transports.JobServiceGrpcAsyncIOTransport), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) diff --git a/tests/unit/gapic/aiplatform_v1/test_metadata_service.py b/tests/unit/gapic/aiplatform_v1/test_metadata_service.py new file mode 100644 index 0000000000..af6e51289f --- /dev/null +++ b/tests/unit/gapic/aiplatform_v1/test_metadata_service.py @@ -0,0 +1,11790 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import os + +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock +except ImportError: + import mock + +import grpc +from grpc.experimental import aio +import math +import pytest +from proto.marshal.rules.dates import DurationRule, TimestampRule + + +from google.api_core import client_options +from google.api_core import exceptions as core_exceptions +from google.api_core import future +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers +from google.api_core import grpc_helpers_async +from google.api_core import operation +from google.api_core import operation_async # type: ignore +from google.api_core import operations_v1 +from google.api_core import path_template +from google.auth import credentials as ga_credentials +from google.auth.exceptions import MutualTLSChannelError +from google.cloud.aiplatform_v1.services.metadata_service import ( + MetadataServiceAsyncClient, +) +from google.cloud.aiplatform_v1.services.metadata_service import MetadataServiceClient +from google.cloud.aiplatform_v1.services.metadata_service import pagers +from google.cloud.aiplatform_v1.services.metadata_service import transports +from google.cloud.aiplatform_v1.types import artifact +from google.cloud.aiplatform_v1.types import artifact as gca_artifact +from google.cloud.aiplatform_v1.types import context +from google.cloud.aiplatform_v1.types import context as gca_context +from google.cloud.aiplatform_v1.types import encryption_spec +from google.cloud.aiplatform_v1.types import event +from google.cloud.aiplatform_v1.types import execution +from google.cloud.aiplatform_v1.types import execution as gca_execution +from google.cloud.aiplatform_v1.types import lineage_subgraph +from google.cloud.aiplatform_v1.types import metadata_schema +from google.cloud.aiplatform_v1.types import metadata_schema as gca_metadata_schema +from google.cloud.aiplatform_v1.types import metadata_service +from google.cloud.aiplatform_v1.types import metadata_store +from google.cloud.aiplatform_v1.types import metadata_store as gca_metadata_store +from google.cloud.aiplatform_v1.types import operation as gca_operation +from google.cloud.location import locations_pb2 +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.oauth2 import service_account +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import struct_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +import google.auth + + +def client_cert_source_callback(): + return b"cert bytes", b"key bytes" + + +# If default endpoint is localhost, then default mtls endpoint will be the same. +# This method modifies the default endpoint so the client can produce a different +# mtls endpoint for endpoint testing purposes. +def modify_default_endpoint(client): + return ( + "foo.googleapis.com" + if ("localhost" in client.DEFAULT_ENDPOINT) + else client.DEFAULT_ENDPOINT + ) + + +def test__get_default_mtls_endpoint(): + api_endpoint = "example.googleapis.com" + api_mtls_endpoint = "example.mtls.googleapis.com" + sandbox_endpoint = "example.sandbox.googleapis.com" + sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" + non_googleapi = "api.example.com" + + assert MetadataServiceClient._get_default_mtls_endpoint(None) is None + assert ( + MetadataServiceClient._get_default_mtls_endpoint(api_endpoint) + == api_mtls_endpoint + ) + assert ( + MetadataServiceClient._get_default_mtls_endpoint(api_mtls_endpoint) + == api_mtls_endpoint + ) + assert ( + MetadataServiceClient._get_default_mtls_endpoint(sandbox_endpoint) + == sandbox_mtls_endpoint + ) + assert ( + MetadataServiceClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) + == sandbox_mtls_endpoint + ) + assert ( + MetadataServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + ) + + +@pytest.mark.parametrize( + "client_class,transport_name", + [ + (MetadataServiceClient, "grpc"), + (MetadataServiceAsyncClient, "grpc_asyncio"), + ], +) +def test_metadata_service_client_from_service_account_info( + client_class, transport_name +): + creds = ga_credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_info" + ) as factory: + factory.return_value = creds + info = {"valid": True} + client = client_class.from_service_account_info(info, transport=transport_name) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.MetadataServiceGrpcTransport, "grpc"), + (transports.MetadataServiceGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_metadata_service_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + +@pytest.mark.parametrize( + "client_class,transport_name", + [ + (MetadataServiceClient, "grpc"), + (MetadataServiceAsyncClient, "grpc_asyncio"), + ], +) +def test_metadata_service_client_from_service_account_file( + client_class, transport_name +): + creds = ga_credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_file" + ) as factory: + factory.return_value = creds + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +def test_metadata_service_client_get_transport_class(): + transport = MetadataServiceClient.get_transport_class() + available_transports = [ + transports.MetadataServiceGrpcTransport, + ] + assert transport in available_transports + + transport = MetadataServiceClient.get_transport_class("grpc") + assert transport == transports.MetadataServiceGrpcTransport + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (MetadataServiceClient, transports.MetadataServiceGrpcTransport, "grpc"), + ( + MetadataServiceAsyncClient, + transports.MetadataServiceGrpcAsyncIOTransport, + "grpc_asyncio", + ), + ], +) +@mock.patch.object( + MetadataServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(MetadataServiceClient), +) +@mock.patch.object( + MetadataServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(MetadataServiceAsyncClient), +) +def test_metadata_service_client_client_options( + client_class, transport_class, transport_name +): + # Check that if channel is provided we won't create a new one. + with mock.patch.object(MetadataServiceClient, "get_transport_class") as gtc: + transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + client = client_class(transport=transport) + gtc.assert_not_called() + + # Check that if channel is provided via str we will create a new one. + with mock.patch.object(MetadataServiceClient, "get_transport_class") as gtc: + client = client_class(transport=transport_name) + gtc.assert_called() + + # Check the case api_endpoint is provided. + options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(transport=transport_name, client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is + # "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is + # "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_MTLS_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has + # unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError): + client = client_class(transport=transport_name) + + # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError): + client = client_class(transport=transport_name) + + # Check the case quota_project_id is provided + options = client_options.ClientOptions(quota_project_id="octopus") + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id="octopus", + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,use_client_cert_env", + [ + ( + MetadataServiceClient, + transports.MetadataServiceGrpcTransport, + "grpc", + "true", + ), + ( + MetadataServiceAsyncClient, + transports.MetadataServiceGrpcAsyncIOTransport, + "grpc_asyncio", + "true", + ), + ( + MetadataServiceClient, + transports.MetadataServiceGrpcTransport, + "grpc", + "false", + ), + ( + MetadataServiceAsyncClient, + transports.MetadataServiceGrpcAsyncIOTransport, + "grpc_asyncio", + "false", + ), + ], +) +@mock.patch.object( + MetadataServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(MetadataServiceClient), +) +@mock.patch.object( + MetadataServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(MetadataServiceAsyncClient), +) +@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) +def test_metadata_service_client_mtls_env_auto( + client_class, transport_class, transport_name, use_client_cert_env +): + # This tests the endpoint autoswitch behavior. Endpoint is autoswitched to the default + # mtls endpoint, if GOOGLE_API_USE_CLIENT_CERTIFICATE is "true" and client cert exists. + + # Check the case client_cert_source is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + options = client_options.ClientOptions( + client_cert_source=client_cert_source_callback + ) + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client.DEFAULT_ENDPOINT + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT + + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # Check the case ADC client cert is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=client_cert_source_callback, + ): + if use_client_cert_env == "false": + expected_host = client.DEFAULT_ENDPOINT + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback + + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + +@pytest.mark.parametrize( + "client_class", [MetadataServiceClient, MetadataServiceAsyncClient] +) +@mock.patch.object( + MetadataServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(MetadataServiceClient), +) +@mock.patch.object( + MetadataServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(MetadataServiceAsyncClient), +) +def test_metadata_service_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (MetadataServiceClient, transports.MetadataServiceGrpcTransport, "grpc"), + ( + MetadataServiceAsyncClient, + transports.MetadataServiceGrpcAsyncIOTransport, + "grpc_asyncio", + ), + ], +) +def test_metadata_service_client_client_options_scopes( + client_class, transport_class, transport_name +): + # Check the case scopes are provided. + options = client_options.ClientOptions( + scopes=["1", "2"], + ) + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=["1", "2"], + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + MetadataServiceClient, + transports.MetadataServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + MetadataServiceAsyncClient, + transports.MetadataServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_metadata_service_client_client_options_credentials_file( + client_class, transport_class, transport_name, grpc_helpers +): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + +def test_metadata_service_client_client_options_from_dict(): + with mock.patch( + "google.cloud.aiplatform_v1.services.metadata_service.transports.MetadataServiceGrpcTransport.__init__" + ) as grpc_transport: + grpc_transport.return_value = None + client = MetadataServiceClient( + client_options={"api_endpoint": "squid.clam.whelk"} + ) + grpc_transport.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + MetadataServiceClient, + transports.MetadataServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + MetadataServiceAsyncClient, + transports.MetadataServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_metadata_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers +): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.CreateMetadataStoreRequest, + dict, + ], +) +def test_create_metadata_store(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_metadata_store), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.create_metadata_store(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.CreateMetadataStoreRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_create_metadata_store_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_metadata_store), "__call__" + ) as call: + client.create_metadata_store() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.CreateMetadataStoreRequest() + + +@pytest.mark.asyncio +async def test_create_metadata_store_async( + transport: str = "grpc_asyncio", + request_type=metadata_service.CreateMetadataStoreRequest, +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_metadata_store), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.create_metadata_store(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.CreateMetadataStoreRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_create_metadata_store_async_from_dict(): + await test_create_metadata_store_async(request_type=dict) + + +def test_create_metadata_store_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.CreateMetadataStoreRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_metadata_store), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.create_metadata_store(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_create_metadata_store_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.CreateMetadataStoreRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_metadata_store), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.create_metadata_store(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_create_metadata_store_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_metadata_store), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_metadata_store( + parent="parent_value", + metadata_store=gca_metadata_store.MetadataStore(name="name_value"), + metadata_store_id="metadata_store_id_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].metadata_store + mock_val = gca_metadata_store.MetadataStore(name="name_value") + assert arg == mock_val + arg = args[0].metadata_store_id + mock_val = "metadata_store_id_value" + assert arg == mock_val + + +def test_create_metadata_store_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_metadata_store( + metadata_service.CreateMetadataStoreRequest(), + parent="parent_value", + metadata_store=gca_metadata_store.MetadataStore(name="name_value"), + metadata_store_id="metadata_store_id_value", + ) + + +@pytest.mark.asyncio +async def test_create_metadata_store_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_metadata_store), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_metadata_store( + parent="parent_value", + metadata_store=gca_metadata_store.MetadataStore(name="name_value"), + metadata_store_id="metadata_store_id_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].metadata_store + mock_val = gca_metadata_store.MetadataStore(name="name_value") + assert arg == mock_val + arg = args[0].metadata_store_id + mock_val = "metadata_store_id_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_create_metadata_store_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.create_metadata_store( + metadata_service.CreateMetadataStoreRequest(), + parent="parent_value", + metadata_store=gca_metadata_store.MetadataStore(name="name_value"), + metadata_store_id="metadata_store_id_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.GetMetadataStoreRequest, + dict, + ], +) +def test_get_metadata_store(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_metadata_store), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_store.MetadataStore( + name="name_value", + description="description_value", + ) + response = client.get_metadata_store(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.GetMetadataStoreRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, metadata_store.MetadataStore) + assert response.name == "name_value" + assert response.description == "description_value" + + +def test_get_metadata_store_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_metadata_store), "__call__" + ) as call: + client.get_metadata_store() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.GetMetadataStoreRequest() + + +@pytest.mark.asyncio +async def test_get_metadata_store_async( + transport: str = "grpc_asyncio", + request_type=metadata_service.GetMetadataStoreRequest, +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_metadata_store), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_store.MetadataStore( + name="name_value", + description="description_value", + ) + ) + response = await client.get_metadata_store(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.GetMetadataStoreRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, metadata_store.MetadataStore) + assert response.name == "name_value" + assert response.description == "description_value" + + +@pytest.mark.asyncio +async def test_get_metadata_store_async_from_dict(): + await test_get_metadata_store_async(request_type=dict) + + +def test_get_metadata_store_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.GetMetadataStoreRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_metadata_store), "__call__" + ) as call: + call.return_value = metadata_store.MetadataStore() + client.get_metadata_store(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_metadata_store_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.GetMetadataStoreRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_metadata_store), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_store.MetadataStore() + ) + await client.get_metadata_store(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_get_metadata_store_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_metadata_store), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_store.MetadataStore() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_metadata_store( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_get_metadata_store_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_metadata_store( + metadata_service.GetMetadataStoreRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_metadata_store_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_metadata_store), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_store.MetadataStore() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_store.MetadataStore() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_metadata_store( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_get_metadata_store_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_metadata_store( + metadata_service.GetMetadataStoreRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.ListMetadataStoresRequest, + dict, + ], +) +def test_list_metadata_stores(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_metadata_stores), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_service.ListMetadataStoresResponse( + next_page_token="next_page_token_value", + ) + response = client.list_metadata_stores(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.ListMetadataStoresRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListMetadataStoresPager) + assert response.next_page_token == "next_page_token_value" + + +def test_list_metadata_stores_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_metadata_stores), "__call__" + ) as call: + client.list_metadata_stores() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.ListMetadataStoresRequest() + + +@pytest.mark.asyncio +async def test_list_metadata_stores_async( + transport: str = "grpc_asyncio", + request_type=metadata_service.ListMetadataStoresRequest, +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_metadata_stores), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_service.ListMetadataStoresResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.list_metadata_stores(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.ListMetadataStoresRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListMetadataStoresAsyncPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_list_metadata_stores_async_from_dict(): + await test_list_metadata_stores_async(request_type=dict) + + +def test_list_metadata_stores_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.ListMetadataStoresRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_metadata_stores), "__call__" + ) as call: + call.return_value = metadata_service.ListMetadataStoresResponse() + client.list_metadata_stores(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_metadata_stores_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.ListMetadataStoresRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_metadata_stores), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_service.ListMetadataStoresResponse() + ) + await client.list_metadata_stores(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_list_metadata_stores_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_metadata_stores), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_service.ListMetadataStoresResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_metadata_stores( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +def test_list_metadata_stores_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_metadata_stores( + metadata_service.ListMetadataStoresRequest(), + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_metadata_stores_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_metadata_stores), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_service.ListMetadataStoresResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_service.ListMetadataStoresResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_metadata_stores( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_list_metadata_stores_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_metadata_stores( + metadata_service.ListMetadataStoresRequest(), + parent="parent_value", + ) + + +def test_list_metadata_stores_pager(transport_name: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_metadata_stores), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + metadata_service.ListMetadataStoresResponse( + metadata_stores=[ + metadata_store.MetadataStore(), + metadata_store.MetadataStore(), + metadata_store.MetadataStore(), + ], + next_page_token="abc", + ), + metadata_service.ListMetadataStoresResponse( + metadata_stores=[], + next_page_token="def", + ), + metadata_service.ListMetadataStoresResponse( + metadata_stores=[ + metadata_store.MetadataStore(), + ], + next_page_token="ghi", + ), + metadata_service.ListMetadataStoresResponse( + metadata_stores=[ + metadata_store.MetadataStore(), + metadata_store.MetadataStore(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_metadata_stores(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, metadata_store.MetadataStore) for i in results) + + +def test_list_metadata_stores_pages(transport_name: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_metadata_stores), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + metadata_service.ListMetadataStoresResponse( + metadata_stores=[ + metadata_store.MetadataStore(), + metadata_store.MetadataStore(), + metadata_store.MetadataStore(), + ], + next_page_token="abc", + ), + metadata_service.ListMetadataStoresResponse( + metadata_stores=[], + next_page_token="def", + ), + metadata_service.ListMetadataStoresResponse( + metadata_stores=[ + metadata_store.MetadataStore(), + ], + next_page_token="ghi", + ), + metadata_service.ListMetadataStoresResponse( + metadata_stores=[ + metadata_store.MetadataStore(), + metadata_store.MetadataStore(), + ], + ), + RuntimeError, + ) + pages = list(client.list_metadata_stores(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.asyncio +async def test_list_metadata_stores_async_pager(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_metadata_stores), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + metadata_service.ListMetadataStoresResponse( + metadata_stores=[ + metadata_store.MetadataStore(), + metadata_store.MetadataStore(), + metadata_store.MetadataStore(), + ], + next_page_token="abc", + ), + metadata_service.ListMetadataStoresResponse( + metadata_stores=[], + next_page_token="def", + ), + metadata_service.ListMetadataStoresResponse( + metadata_stores=[ + metadata_store.MetadataStore(), + ], + next_page_token="ghi", + ), + metadata_service.ListMetadataStoresResponse( + metadata_stores=[ + metadata_store.MetadataStore(), + metadata_store.MetadataStore(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_metadata_stores( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, metadata_store.MetadataStore) for i in responses) + + +@pytest.mark.asyncio +async def test_list_metadata_stores_async_pages(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_metadata_stores), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + metadata_service.ListMetadataStoresResponse( + metadata_stores=[ + metadata_store.MetadataStore(), + metadata_store.MetadataStore(), + metadata_store.MetadataStore(), + ], + next_page_token="abc", + ), + metadata_service.ListMetadataStoresResponse( + metadata_stores=[], + next_page_token="def", + ), + metadata_service.ListMetadataStoresResponse( + metadata_stores=[ + metadata_store.MetadataStore(), + ], + next_page_token="ghi", + ), + metadata_service.ListMetadataStoresResponse( + metadata_stores=[ + metadata_store.MetadataStore(), + metadata_store.MetadataStore(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.list_metadata_stores(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.DeleteMetadataStoreRequest, + dict, + ], +) +def test_delete_metadata_store(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_metadata_store), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.delete_metadata_store(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.DeleteMetadataStoreRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_delete_metadata_store_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_metadata_store), "__call__" + ) as call: + client.delete_metadata_store() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.DeleteMetadataStoreRequest() + + +@pytest.mark.asyncio +async def test_delete_metadata_store_async( + transport: str = "grpc_asyncio", + request_type=metadata_service.DeleteMetadataStoreRequest, +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_metadata_store), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.delete_metadata_store(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.DeleteMetadataStoreRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_delete_metadata_store_async_from_dict(): + await test_delete_metadata_store_async(request_type=dict) + + +def test_delete_metadata_store_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.DeleteMetadataStoreRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_metadata_store), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_metadata_store(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_metadata_store_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.DeleteMetadataStoreRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_metadata_store), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.delete_metadata_store(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_delete_metadata_store_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_metadata_store), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_metadata_store( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_delete_metadata_store_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_metadata_store( + metadata_service.DeleteMetadataStoreRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_delete_metadata_store_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_metadata_store), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_metadata_store( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_delete_metadata_store_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.delete_metadata_store( + metadata_service.DeleteMetadataStoreRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.CreateArtifactRequest, + dict, + ], +) +def test_create_artifact(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_artifact), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = gca_artifact.Artifact( + name="name_value", + display_name="display_name_value", + uri="uri_value", + etag="etag_value", + state=gca_artifact.Artifact.State.PENDING, + schema_title="schema_title_value", + schema_version="schema_version_value", + description="description_value", + ) + response = client.create_artifact(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.CreateArtifactRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_artifact.Artifact) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.uri == "uri_value" + assert response.etag == "etag_value" + assert response.state == gca_artifact.Artifact.State.PENDING + assert response.schema_title == "schema_title_value" + assert response.schema_version == "schema_version_value" + assert response.description == "description_value" + + +def test_create_artifact_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_artifact), "__call__") as call: + client.create_artifact() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.CreateArtifactRequest() + + +@pytest.mark.asyncio +async def test_create_artifact_async( + transport: str = "grpc_asyncio", request_type=metadata_service.CreateArtifactRequest +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_artifact), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_artifact.Artifact( + name="name_value", + display_name="display_name_value", + uri="uri_value", + etag="etag_value", + state=gca_artifact.Artifact.State.PENDING, + schema_title="schema_title_value", + schema_version="schema_version_value", + description="description_value", + ) + ) + response = await client.create_artifact(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.CreateArtifactRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_artifact.Artifact) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.uri == "uri_value" + assert response.etag == "etag_value" + assert response.state == gca_artifact.Artifact.State.PENDING + assert response.schema_title == "schema_title_value" + assert response.schema_version == "schema_version_value" + assert response.description == "description_value" + + +@pytest.mark.asyncio +async def test_create_artifact_async_from_dict(): + await test_create_artifact_async(request_type=dict) + + +def test_create_artifact_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.CreateArtifactRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_artifact), "__call__") as call: + call.return_value = gca_artifact.Artifact() + client.create_artifact(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_create_artifact_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.CreateArtifactRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_artifact), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_artifact.Artifact() + ) + await client.create_artifact(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_create_artifact_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_artifact), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = gca_artifact.Artifact() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_artifact( + parent="parent_value", + artifact=gca_artifact.Artifact(name="name_value"), + artifact_id="artifact_id_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].artifact + mock_val = gca_artifact.Artifact(name="name_value") + assert arg == mock_val + arg = args[0].artifact_id + mock_val = "artifact_id_value" + assert arg == mock_val + + +def test_create_artifact_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_artifact( + metadata_service.CreateArtifactRequest(), + parent="parent_value", + artifact=gca_artifact.Artifact(name="name_value"), + artifact_id="artifact_id_value", + ) + + +@pytest.mark.asyncio +async def test_create_artifact_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_artifact), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = gca_artifact.Artifact() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_artifact.Artifact() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_artifact( + parent="parent_value", + artifact=gca_artifact.Artifact(name="name_value"), + artifact_id="artifact_id_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].artifact + mock_val = gca_artifact.Artifact(name="name_value") + assert arg == mock_val + arg = args[0].artifact_id + mock_val = "artifact_id_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_create_artifact_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.create_artifact( + metadata_service.CreateArtifactRequest(), + parent="parent_value", + artifact=gca_artifact.Artifact(name="name_value"), + artifact_id="artifact_id_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.GetArtifactRequest, + dict, + ], +) +def test_get_artifact(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_artifact), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = artifact.Artifact( + name="name_value", + display_name="display_name_value", + uri="uri_value", + etag="etag_value", + state=artifact.Artifact.State.PENDING, + schema_title="schema_title_value", + schema_version="schema_version_value", + description="description_value", + ) + response = client.get_artifact(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.GetArtifactRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, artifact.Artifact) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.uri == "uri_value" + assert response.etag == "etag_value" + assert response.state == artifact.Artifact.State.PENDING + assert response.schema_title == "schema_title_value" + assert response.schema_version == "schema_version_value" + assert response.description == "description_value" + + +def test_get_artifact_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_artifact), "__call__") as call: + client.get_artifact() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.GetArtifactRequest() + + +@pytest.mark.asyncio +async def test_get_artifact_async( + transport: str = "grpc_asyncio", request_type=metadata_service.GetArtifactRequest +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_artifact), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + artifact.Artifact( + name="name_value", + display_name="display_name_value", + uri="uri_value", + etag="etag_value", + state=artifact.Artifact.State.PENDING, + schema_title="schema_title_value", + schema_version="schema_version_value", + description="description_value", + ) + ) + response = await client.get_artifact(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.GetArtifactRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, artifact.Artifact) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.uri == "uri_value" + assert response.etag == "etag_value" + assert response.state == artifact.Artifact.State.PENDING + assert response.schema_title == "schema_title_value" + assert response.schema_version == "schema_version_value" + assert response.description == "description_value" + + +@pytest.mark.asyncio +async def test_get_artifact_async_from_dict(): + await test_get_artifact_async(request_type=dict) + + +def test_get_artifact_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.GetArtifactRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_artifact), "__call__") as call: + call.return_value = artifact.Artifact() + client.get_artifact(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_artifact_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.GetArtifactRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_artifact), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(artifact.Artifact()) + await client.get_artifact(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_get_artifact_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_artifact), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = artifact.Artifact() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_artifact( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_get_artifact_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_artifact( + metadata_service.GetArtifactRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_artifact_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_artifact), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = artifact.Artifact() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(artifact.Artifact()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_artifact( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_get_artifact_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_artifact( + metadata_service.GetArtifactRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.ListArtifactsRequest, + dict, + ], +) +def test_list_artifacts(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_artifacts), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_service.ListArtifactsResponse( + next_page_token="next_page_token_value", + ) + response = client.list_artifacts(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.ListArtifactsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListArtifactsPager) + assert response.next_page_token == "next_page_token_value" + + +def test_list_artifacts_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_artifacts), "__call__") as call: + client.list_artifacts() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.ListArtifactsRequest() + + +@pytest.mark.asyncio +async def test_list_artifacts_async( + transport: str = "grpc_asyncio", request_type=metadata_service.ListArtifactsRequest +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_artifacts), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_service.ListArtifactsResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.list_artifacts(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.ListArtifactsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListArtifactsAsyncPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_list_artifacts_async_from_dict(): + await test_list_artifacts_async(request_type=dict) + + +def test_list_artifacts_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.ListArtifactsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_artifacts), "__call__") as call: + call.return_value = metadata_service.ListArtifactsResponse() + client.list_artifacts(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_artifacts_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.ListArtifactsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_artifacts), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_service.ListArtifactsResponse() + ) + await client.list_artifacts(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_list_artifacts_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_artifacts), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_service.ListArtifactsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_artifacts( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +def test_list_artifacts_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_artifacts( + metadata_service.ListArtifactsRequest(), + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_artifacts_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_artifacts), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_service.ListArtifactsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_service.ListArtifactsResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_artifacts( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_list_artifacts_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_artifacts( + metadata_service.ListArtifactsRequest(), + parent="parent_value", + ) + + +def test_list_artifacts_pager(transport_name: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_artifacts), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + metadata_service.ListArtifactsResponse( + artifacts=[ + artifact.Artifact(), + artifact.Artifact(), + artifact.Artifact(), + ], + next_page_token="abc", + ), + metadata_service.ListArtifactsResponse( + artifacts=[], + next_page_token="def", + ), + metadata_service.ListArtifactsResponse( + artifacts=[ + artifact.Artifact(), + ], + next_page_token="ghi", + ), + metadata_service.ListArtifactsResponse( + artifacts=[ + artifact.Artifact(), + artifact.Artifact(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_artifacts(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, artifact.Artifact) for i in results) + + +def test_list_artifacts_pages(transport_name: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_artifacts), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + metadata_service.ListArtifactsResponse( + artifacts=[ + artifact.Artifact(), + artifact.Artifact(), + artifact.Artifact(), + ], + next_page_token="abc", + ), + metadata_service.ListArtifactsResponse( + artifacts=[], + next_page_token="def", + ), + metadata_service.ListArtifactsResponse( + artifacts=[ + artifact.Artifact(), + ], + next_page_token="ghi", + ), + metadata_service.ListArtifactsResponse( + artifacts=[ + artifact.Artifact(), + artifact.Artifact(), + ], + ), + RuntimeError, + ) + pages = list(client.list_artifacts(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.asyncio +async def test_list_artifacts_async_pager(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_artifacts), "__call__", new_callable=mock.AsyncMock + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + metadata_service.ListArtifactsResponse( + artifacts=[ + artifact.Artifact(), + artifact.Artifact(), + artifact.Artifact(), + ], + next_page_token="abc", + ), + metadata_service.ListArtifactsResponse( + artifacts=[], + next_page_token="def", + ), + metadata_service.ListArtifactsResponse( + artifacts=[ + artifact.Artifact(), + ], + next_page_token="ghi", + ), + metadata_service.ListArtifactsResponse( + artifacts=[ + artifact.Artifact(), + artifact.Artifact(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_artifacts( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, artifact.Artifact) for i in responses) + + +@pytest.mark.asyncio +async def test_list_artifacts_async_pages(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_artifacts), "__call__", new_callable=mock.AsyncMock + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + metadata_service.ListArtifactsResponse( + artifacts=[ + artifact.Artifact(), + artifact.Artifact(), + artifact.Artifact(), + ], + next_page_token="abc", + ), + metadata_service.ListArtifactsResponse( + artifacts=[], + next_page_token="def", + ), + metadata_service.ListArtifactsResponse( + artifacts=[ + artifact.Artifact(), + ], + next_page_token="ghi", + ), + metadata_service.ListArtifactsResponse( + artifacts=[ + artifact.Artifact(), + artifact.Artifact(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.list_artifacts(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.UpdateArtifactRequest, + dict, + ], +) +def test_update_artifact(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_artifact), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = gca_artifact.Artifact( + name="name_value", + display_name="display_name_value", + uri="uri_value", + etag="etag_value", + state=gca_artifact.Artifact.State.PENDING, + schema_title="schema_title_value", + schema_version="schema_version_value", + description="description_value", + ) + response = client.update_artifact(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.UpdateArtifactRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_artifact.Artifact) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.uri == "uri_value" + assert response.etag == "etag_value" + assert response.state == gca_artifact.Artifact.State.PENDING + assert response.schema_title == "schema_title_value" + assert response.schema_version == "schema_version_value" + assert response.description == "description_value" + + +def test_update_artifact_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_artifact), "__call__") as call: + client.update_artifact() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.UpdateArtifactRequest() + + +@pytest.mark.asyncio +async def test_update_artifact_async( + transport: str = "grpc_asyncio", request_type=metadata_service.UpdateArtifactRequest +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_artifact), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_artifact.Artifact( + name="name_value", + display_name="display_name_value", + uri="uri_value", + etag="etag_value", + state=gca_artifact.Artifact.State.PENDING, + schema_title="schema_title_value", + schema_version="schema_version_value", + description="description_value", + ) + ) + response = await client.update_artifact(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.UpdateArtifactRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_artifact.Artifact) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.uri == "uri_value" + assert response.etag == "etag_value" + assert response.state == gca_artifact.Artifact.State.PENDING + assert response.schema_title == "schema_title_value" + assert response.schema_version == "schema_version_value" + assert response.description == "description_value" + + +@pytest.mark.asyncio +async def test_update_artifact_async_from_dict(): + await test_update_artifact_async(request_type=dict) + + +def test_update_artifact_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.UpdateArtifactRequest() + + request.artifact.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_artifact), "__call__") as call: + call.return_value = gca_artifact.Artifact() + client.update_artifact(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "artifact.name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_update_artifact_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.UpdateArtifactRequest() + + request.artifact.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_artifact), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_artifact.Artifact() + ) + await client.update_artifact(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "artifact.name=name_value", + ) in kw["metadata"] + + +def test_update_artifact_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_artifact), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = gca_artifact.Artifact() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.update_artifact( + artifact=gca_artifact.Artifact(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].artifact + mock_val = gca_artifact.Artifact(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + + +def test_update_artifact_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_artifact( + metadata_service.UpdateArtifactRequest(), + artifact=gca_artifact.Artifact(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.asyncio +async def test_update_artifact_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_artifact), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = gca_artifact.Artifact() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_artifact.Artifact() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.update_artifact( + artifact=gca_artifact.Artifact(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].artifact + mock_val = gca_artifact.Artifact(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_update_artifact_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.update_artifact( + metadata_service.UpdateArtifactRequest(), + artifact=gca_artifact.Artifact(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.DeleteArtifactRequest, + dict, + ], +) +def test_delete_artifact(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_artifact), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.delete_artifact(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.DeleteArtifactRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_delete_artifact_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_artifact), "__call__") as call: + client.delete_artifact() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.DeleteArtifactRequest() + + +@pytest.mark.asyncio +async def test_delete_artifact_async( + transport: str = "grpc_asyncio", request_type=metadata_service.DeleteArtifactRequest +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_artifact), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.delete_artifact(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.DeleteArtifactRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_delete_artifact_async_from_dict(): + await test_delete_artifact_async(request_type=dict) + + +def test_delete_artifact_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.DeleteArtifactRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_artifact), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_artifact(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_artifact_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.DeleteArtifactRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_artifact), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.delete_artifact(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_delete_artifact_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_artifact), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_artifact( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_delete_artifact_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_artifact( + metadata_service.DeleteArtifactRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_delete_artifact_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_artifact), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_artifact( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_delete_artifact_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.delete_artifact( + metadata_service.DeleteArtifactRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.PurgeArtifactsRequest, + dict, + ], +) +def test_purge_artifacts(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.purge_artifacts), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.purge_artifacts(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.PurgeArtifactsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_purge_artifacts_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.purge_artifacts), "__call__") as call: + client.purge_artifacts() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.PurgeArtifactsRequest() + + +@pytest.mark.asyncio +async def test_purge_artifacts_async( + transport: str = "grpc_asyncio", request_type=metadata_service.PurgeArtifactsRequest +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.purge_artifacts), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.purge_artifacts(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.PurgeArtifactsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_purge_artifacts_async_from_dict(): + await test_purge_artifacts_async(request_type=dict) + + +def test_purge_artifacts_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.PurgeArtifactsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.purge_artifacts), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.purge_artifacts(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_purge_artifacts_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.PurgeArtifactsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.purge_artifacts), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.purge_artifacts(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_purge_artifacts_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.purge_artifacts), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.purge_artifacts( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +def test_purge_artifacts_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.purge_artifacts( + metadata_service.PurgeArtifactsRequest(), + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_purge_artifacts_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.purge_artifacts), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.purge_artifacts( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_purge_artifacts_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.purge_artifacts( + metadata_service.PurgeArtifactsRequest(), + parent="parent_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.CreateContextRequest, + dict, + ], +) +def test_create_context(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_context), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = gca_context.Context( + name="name_value", + display_name="display_name_value", + etag="etag_value", + parent_contexts=["parent_contexts_value"], + schema_title="schema_title_value", + schema_version="schema_version_value", + description="description_value", + ) + response = client.create_context(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.CreateContextRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_context.Context) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.etag == "etag_value" + assert response.parent_contexts == ["parent_contexts_value"] + assert response.schema_title == "schema_title_value" + assert response.schema_version == "schema_version_value" + assert response.description == "description_value" + + +def test_create_context_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_context), "__call__") as call: + client.create_context() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.CreateContextRequest() + + +@pytest.mark.asyncio +async def test_create_context_async( + transport: str = "grpc_asyncio", request_type=metadata_service.CreateContextRequest +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_context), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_context.Context( + name="name_value", + display_name="display_name_value", + etag="etag_value", + parent_contexts=["parent_contexts_value"], + schema_title="schema_title_value", + schema_version="schema_version_value", + description="description_value", + ) + ) + response = await client.create_context(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.CreateContextRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_context.Context) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.etag == "etag_value" + assert response.parent_contexts == ["parent_contexts_value"] + assert response.schema_title == "schema_title_value" + assert response.schema_version == "schema_version_value" + assert response.description == "description_value" + + +@pytest.mark.asyncio +async def test_create_context_async_from_dict(): + await test_create_context_async(request_type=dict) + + +def test_create_context_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.CreateContextRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_context), "__call__") as call: + call.return_value = gca_context.Context() + client.create_context(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_create_context_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.CreateContextRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_context), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gca_context.Context()) + await client.create_context(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_create_context_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_context), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = gca_context.Context() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_context( + parent="parent_value", + context=gca_context.Context(name="name_value"), + context_id="context_id_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].context + mock_val = gca_context.Context(name="name_value") + assert arg == mock_val + arg = args[0].context_id + mock_val = "context_id_value" + assert arg == mock_val + + +def test_create_context_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_context( + metadata_service.CreateContextRequest(), + parent="parent_value", + context=gca_context.Context(name="name_value"), + context_id="context_id_value", + ) + + +@pytest.mark.asyncio +async def test_create_context_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_context), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = gca_context.Context() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gca_context.Context()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_context( + parent="parent_value", + context=gca_context.Context(name="name_value"), + context_id="context_id_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].context + mock_val = gca_context.Context(name="name_value") + assert arg == mock_val + arg = args[0].context_id + mock_val = "context_id_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_create_context_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.create_context( + metadata_service.CreateContextRequest(), + parent="parent_value", + context=gca_context.Context(name="name_value"), + context_id="context_id_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.GetContextRequest, + dict, + ], +) +def test_get_context(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_context), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = context.Context( + name="name_value", + display_name="display_name_value", + etag="etag_value", + parent_contexts=["parent_contexts_value"], + schema_title="schema_title_value", + schema_version="schema_version_value", + description="description_value", + ) + response = client.get_context(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.GetContextRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, context.Context) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.etag == "etag_value" + assert response.parent_contexts == ["parent_contexts_value"] + assert response.schema_title == "schema_title_value" + assert response.schema_version == "schema_version_value" + assert response.description == "description_value" + + +def test_get_context_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_context), "__call__") as call: + client.get_context() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.GetContextRequest() + + +@pytest.mark.asyncio +async def test_get_context_async( + transport: str = "grpc_asyncio", request_type=metadata_service.GetContextRequest +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_context), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + context.Context( + name="name_value", + display_name="display_name_value", + etag="etag_value", + parent_contexts=["parent_contexts_value"], + schema_title="schema_title_value", + schema_version="schema_version_value", + description="description_value", + ) + ) + response = await client.get_context(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.GetContextRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, context.Context) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.etag == "etag_value" + assert response.parent_contexts == ["parent_contexts_value"] + assert response.schema_title == "schema_title_value" + assert response.schema_version == "schema_version_value" + assert response.description == "description_value" + + +@pytest.mark.asyncio +async def test_get_context_async_from_dict(): + await test_get_context_async(request_type=dict) + + +def test_get_context_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.GetContextRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_context), "__call__") as call: + call.return_value = context.Context() + client.get_context(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_context_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.GetContextRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_context), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(context.Context()) + await client.get_context(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_get_context_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_context), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = context.Context() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_context( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_get_context_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_context( + metadata_service.GetContextRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_context_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_context), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = context.Context() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(context.Context()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_context( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_get_context_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_context( + metadata_service.GetContextRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.ListContextsRequest, + dict, + ], +) +def test_list_contexts(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_contexts), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_service.ListContextsResponse( + next_page_token="next_page_token_value", + ) + response = client.list_contexts(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.ListContextsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListContextsPager) + assert response.next_page_token == "next_page_token_value" + + +def test_list_contexts_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_contexts), "__call__") as call: + client.list_contexts() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.ListContextsRequest() + + +@pytest.mark.asyncio +async def test_list_contexts_async( + transport: str = "grpc_asyncio", request_type=metadata_service.ListContextsRequest +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_contexts), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_service.ListContextsResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.list_contexts(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.ListContextsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListContextsAsyncPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_list_contexts_async_from_dict(): + await test_list_contexts_async(request_type=dict) + + +def test_list_contexts_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.ListContextsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_contexts), "__call__") as call: + call.return_value = metadata_service.ListContextsResponse() + client.list_contexts(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_contexts_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.ListContextsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_contexts), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_service.ListContextsResponse() + ) + await client.list_contexts(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_list_contexts_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_contexts), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_service.ListContextsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_contexts( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +def test_list_contexts_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_contexts( + metadata_service.ListContextsRequest(), + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_contexts_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_contexts), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_service.ListContextsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_service.ListContextsResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_contexts( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_list_contexts_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_contexts( + metadata_service.ListContextsRequest(), + parent="parent_value", + ) + + +def test_list_contexts_pager(transport_name: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_contexts), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + metadata_service.ListContextsResponse( + contexts=[ + context.Context(), + context.Context(), + context.Context(), + ], + next_page_token="abc", + ), + metadata_service.ListContextsResponse( + contexts=[], + next_page_token="def", + ), + metadata_service.ListContextsResponse( + contexts=[ + context.Context(), + ], + next_page_token="ghi", + ), + metadata_service.ListContextsResponse( + contexts=[ + context.Context(), + context.Context(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_contexts(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, context.Context) for i in results) + + +def test_list_contexts_pages(transport_name: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_contexts), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + metadata_service.ListContextsResponse( + contexts=[ + context.Context(), + context.Context(), + context.Context(), + ], + next_page_token="abc", + ), + metadata_service.ListContextsResponse( + contexts=[], + next_page_token="def", + ), + metadata_service.ListContextsResponse( + contexts=[ + context.Context(), + ], + next_page_token="ghi", + ), + metadata_service.ListContextsResponse( + contexts=[ + context.Context(), + context.Context(), + ], + ), + RuntimeError, + ) + pages = list(client.list_contexts(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.asyncio +async def test_list_contexts_async_pager(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_contexts), "__call__", new_callable=mock.AsyncMock + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + metadata_service.ListContextsResponse( + contexts=[ + context.Context(), + context.Context(), + context.Context(), + ], + next_page_token="abc", + ), + metadata_service.ListContextsResponse( + contexts=[], + next_page_token="def", + ), + metadata_service.ListContextsResponse( + contexts=[ + context.Context(), + ], + next_page_token="ghi", + ), + metadata_service.ListContextsResponse( + contexts=[ + context.Context(), + context.Context(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_contexts( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, context.Context) for i in responses) + + +@pytest.mark.asyncio +async def test_list_contexts_async_pages(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_contexts), "__call__", new_callable=mock.AsyncMock + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + metadata_service.ListContextsResponse( + contexts=[ + context.Context(), + context.Context(), + context.Context(), + ], + next_page_token="abc", + ), + metadata_service.ListContextsResponse( + contexts=[], + next_page_token="def", + ), + metadata_service.ListContextsResponse( + contexts=[ + context.Context(), + ], + next_page_token="ghi", + ), + metadata_service.ListContextsResponse( + contexts=[ + context.Context(), + context.Context(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.list_contexts(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.UpdateContextRequest, + dict, + ], +) +def test_update_context(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_context), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = gca_context.Context( + name="name_value", + display_name="display_name_value", + etag="etag_value", + parent_contexts=["parent_contexts_value"], + schema_title="schema_title_value", + schema_version="schema_version_value", + description="description_value", + ) + response = client.update_context(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.UpdateContextRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_context.Context) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.etag == "etag_value" + assert response.parent_contexts == ["parent_contexts_value"] + assert response.schema_title == "schema_title_value" + assert response.schema_version == "schema_version_value" + assert response.description == "description_value" + + +def test_update_context_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_context), "__call__") as call: + client.update_context() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.UpdateContextRequest() + + +@pytest.mark.asyncio +async def test_update_context_async( + transport: str = "grpc_asyncio", request_type=metadata_service.UpdateContextRequest +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_context), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_context.Context( + name="name_value", + display_name="display_name_value", + etag="etag_value", + parent_contexts=["parent_contexts_value"], + schema_title="schema_title_value", + schema_version="schema_version_value", + description="description_value", + ) + ) + response = await client.update_context(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.UpdateContextRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_context.Context) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.etag == "etag_value" + assert response.parent_contexts == ["parent_contexts_value"] + assert response.schema_title == "schema_title_value" + assert response.schema_version == "schema_version_value" + assert response.description == "description_value" + + +@pytest.mark.asyncio +async def test_update_context_async_from_dict(): + await test_update_context_async(request_type=dict) + + +def test_update_context_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.UpdateContextRequest() + + request.context.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_context), "__call__") as call: + call.return_value = gca_context.Context() + client.update_context(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "context.name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_update_context_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.UpdateContextRequest() + + request.context.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_context), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gca_context.Context()) + await client.update_context(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "context.name=name_value", + ) in kw["metadata"] + + +def test_update_context_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_context), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = gca_context.Context() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.update_context( + context=gca_context.Context(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].context + mock_val = gca_context.Context(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + + +def test_update_context_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_context( + metadata_service.UpdateContextRequest(), + context=gca_context.Context(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.asyncio +async def test_update_context_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_context), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = gca_context.Context() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gca_context.Context()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.update_context( + context=gca_context.Context(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].context + mock_val = gca_context.Context(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_update_context_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.update_context( + metadata_service.UpdateContextRequest(), + context=gca_context.Context(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.DeleteContextRequest, + dict, + ], +) +def test_delete_context(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_context), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.delete_context(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.DeleteContextRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_delete_context_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_context), "__call__") as call: + client.delete_context() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.DeleteContextRequest() + + +@pytest.mark.asyncio +async def test_delete_context_async( + transport: str = "grpc_asyncio", request_type=metadata_service.DeleteContextRequest +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_context), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.delete_context(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.DeleteContextRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_delete_context_async_from_dict(): + await test_delete_context_async(request_type=dict) + + +def test_delete_context_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.DeleteContextRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_context), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_context(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_context_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.DeleteContextRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_context), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.delete_context(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_delete_context_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_context), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_context( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_delete_context_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_context( + metadata_service.DeleteContextRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_delete_context_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_context), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_context( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_delete_context_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.delete_context( + metadata_service.DeleteContextRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.PurgeContextsRequest, + dict, + ], +) +def test_purge_contexts(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.purge_contexts), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.purge_contexts(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.PurgeContextsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_purge_contexts_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.purge_contexts), "__call__") as call: + client.purge_contexts() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.PurgeContextsRequest() + + +@pytest.mark.asyncio +async def test_purge_contexts_async( + transport: str = "grpc_asyncio", request_type=metadata_service.PurgeContextsRequest +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.purge_contexts), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.purge_contexts(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.PurgeContextsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_purge_contexts_async_from_dict(): + await test_purge_contexts_async(request_type=dict) + + +def test_purge_contexts_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.PurgeContextsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.purge_contexts), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.purge_contexts(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_purge_contexts_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.PurgeContextsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.purge_contexts), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.purge_contexts(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_purge_contexts_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.purge_contexts), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.purge_contexts( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +def test_purge_contexts_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.purge_contexts( + metadata_service.PurgeContextsRequest(), + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_purge_contexts_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.purge_contexts), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.purge_contexts( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_purge_contexts_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.purge_contexts( + metadata_service.PurgeContextsRequest(), + parent="parent_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.AddContextArtifactsAndExecutionsRequest, + dict, + ], +) +def test_add_context_artifacts_and_executions(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_context_artifacts_and_executions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_service.AddContextArtifactsAndExecutionsResponse() + response = client.add_context_artifacts_and_executions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.AddContextArtifactsAndExecutionsRequest() + + # Establish that the response is the type that we expect. + assert isinstance( + response, metadata_service.AddContextArtifactsAndExecutionsResponse + ) + + +def test_add_context_artifacts_and_executions_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_context_artifacts_and_executions), "__call__" + ) as call: + client.add_context_artifacts_and_executions() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.AddContextArtifactsAndExecutionsRequest() + + +@pytest.mark.asyncio +async def test_add_context_artifacts_and_executions_async( + transport: str = "grpc_asyncio", + request_type=metadata_service.AddContextArtifactsAndExecutionsRequest, +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_context_artifacts_and_executions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_service.AddContextArtifactsAndExecutionsResponse() + ) + response = await client.add_context_artifacts_and_executions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.AddContextArtifactsAndExecutionsRequest() + + # Establish that the response is the type that we expect. + assert isinstance( + response, metadata_service.AddContextArtifactsAndExecutionsResponse + ) + + +@pytest.mark.asyncio +async def test_add_context_artifacts_and_executions_async_from_dict(): + await test_add_context_artifacts_and_executions_async(request_type=dict) + + +def test_add_context_artifacts_and_executions_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.AddContextArtifactsAndExecutionsRequest() + + request.context = "context_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_context_artifacts_and_executions), "__call__" + ) as call: + call.return_value = metadata_service.AddContextArtifactsAndExecutionsResponse() + client.add_context_artifacts_and_executions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "context=context_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_add_context_artifacts_and_executions_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.AddContextArtifactsAndExecutionsRequest() + + request.context = "context_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_context_artifacts_and_executions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_service.AddContextArtifactsAndExecutionsResponse() + ) + await client.add_context_artifacts_and_executions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "context=context_value", + ) in kw["metadata"] + + +def test_add_context_artifacts_and_executions_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_context_artifacts_and_executions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_service.AddContextArtifactsAndExecutionsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.add_context_artifacts_and_executions( + context="context_value", + artifacts=["artifacts_value"], + executions=["executions_value"], + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].context + mock_val = "context_value" + assert arg == mock_val + arg = args[0].artifacts + mock_val = ["artifacts_value"] + assert arg == mock_val + arg = args[0].executions + mock_val = ["executions_value"] + assert arg == mock_val + + +def test_add_context_artifacts_and_executions_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.add_context_artifacts_and_executions( + metadata_service.AddContextArtifactsAndExecutionsRequest(), + context="context_value", + artifacts=["artifacts_value"], + executions=["executions_value"], + ) + + +@pytest.mark.asyncio +async def test_add_context_artifacts_and_executions_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_context_artifacts_and_executions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_service.AddContextArtifactsAndExecutionsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_service.AddContextArtifactsAndExecutionsResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.add_context_artifacts_and_executions( + context="context_value", + artifacts=["artifacts_value"], + executions=["executions_value"], + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].context + mock_val = "context_value" + assert arg == mock_val + arg = args[0].artifacts + mock_val = ["artifacts_value"] + assert arg == mock_val + arg = args[0].executions + mock_val = ["executions_value"] + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_add_context_artifacts_and_executions_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.add_context_artifacts_and_executions( + metadata_service.AddContextArtifactsAndExecutionsRequest(), + context="context_value", + artifacts=["artifacts_value"], + executions=["executions_value"], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.AddContextChildrenRequest, + dict, + ], +) +def test_add_context_children(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_context_children), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_service.AddContextChildrenResponse() + response = client.add_context_children(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.AddContextChildrenRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, metadata_service.AddContextChildrenResponse) + + +def test_add_context_children_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_context_children), "__call__" + ) as call: + client.add_context_children() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.AddContextChildrenRequest() + + +@pytest.mark.asyncio +async def test_add_context_children_async( + transport: str = "grpc_asyncio", + request_type=metadata_service.AddContextChildrenRequest, +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_context_children), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_service.AddContextChildrenResponse() + ) + response = await client.add_context_children(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.AddContextChildrenRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, metadata_service.AddContextChildrenResponse) + + +@pytest.mark.asyncio +async def test_add_context_children_async_from_dict(): + await test_add_context_children_async(request_type=dict) + + +def test_add_context_children_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.AddContextChildrenRequest() + + request.context = "context_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_context_children), "__call__" + ) as call: + call.return_value = metadata_service.AddContextChildrenResponse() + client.add_context_children(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "context=context_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_add_context_children_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.AddContextChildrenRequest() + + request.context = "context_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_context_children), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_service.AddContextChildrenResponse() + ) + await client.add_context_children(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "context=context_value", + ) in kw["metadata"] + + +def test_add_context_children_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_context_children), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_service.AddContextChildrenResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.add_context_children( + context="context_value", + child_contexts=["child_contexts_value"], + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].context + mock_val = "context_value" + assert arg == mock_val + arg = args[0].child_contexts + mock_val = ["child_contexts_value"] + assert arg == mock_val + + +def test_add_context_children_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.add_context_children( + metadata_service.AddContextChildrenRequest(), + context="context_value", + child_contexts=["child_contexts_value"], + ) + + +@pytest.mark.asyncio +async def test_add_context_children_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_context_children), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_service.AddContextChildrenResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_service.AddContextChildrenResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.add_context_children( + context="context_value", + child_contexts=["child_contexts_value"], + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].context + mock_val = "context_value" + assert arg == mock_val + arg = args[0].child_contexts + mock_val = ["child_contexts_value"] + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_add_context_children_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.add_context_children( + metadata_service.AddContextChildrenRequest(), + context="context_value", + child_contexts=["child_contexts_value"], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.QueryContextLineageSubgraphRequest, + dict, + ], +) +def test_query_context_lineage_subgraph(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_context_lineage_subgraph), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = lineage_subgraph.LineageSubgraph() + response = client.query_context_lineage_subgraph(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.QueryContextLineageSubgraphRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, lineage_subgraph.LineageSubgraph) + + +def test_query_context_lineage_subgraph_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_context_lineage_subgraph), "__call__" + ) as call: + client.query_context_lineage_subgraph() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.QueryContextLineageSubgraphRequest() + + +@pytest.mark.asyncio +async def test_query_context_lineage_subgraph_async( + transport: str = "grpc_asyncio", + request_type=metadata_service.QueryContextLineageSubgraphRequest, +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_context_lineage_subgraph), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + lineage_subgraph.LineageSubgraph() + ) + response = await client.query_context_lineage_subgraph(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.QueryContextLineageSubgraphRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, lineage_subgraph.LineageSubgraph) + + +@pytest.mark.asyncio +async def test_query_context_lineage_subgraph_async_from_dict(): + await test_query_context_lineage_subgraph_async(request_type=dict) + + +def test_query_context_lineage_subgraph_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.QueryContextLineageSubgraphRequest() + + request.context = "context_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_context_lineage_subgraph), "__call__" + ) as call: + call.return_value = lineage_subgraph.LineageSubgraph() + client.query_context_lineage_subgraph(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "context=context_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_query_context_lineage_subgraph_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.QueryContextLineageSubgraphRequest() + + request.context = "context_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_context_lineage_subgraph), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + lineage_subgraph.LineageSubgraph() + ) + await client.query_context_lineage_subgraph(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "context=context_value", + ) in kw["metadata"] + + +def test_query_context_lineage_subgraph_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_context_lineage_subgraph), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = lineage_subgraph.LineageSubgraph() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.query_context_lineage_subgraph( + context="context_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].context + mock_val = "context_value" + assert arg == mock_val + + +def test_query_context_lineage_subgraph_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.query_context_lineage_subgraph( + metadata_service.QueryContextLineageSubgraphRequest(), + context="context_value", + ) + + +@pytest.mark.asyncio +async def test_query_context_lineage_subgraph_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_context_lineage_subgraph), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = lineage_subgraph.LineageSubgraph() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + lineage_subgraph.LineageSubgraph() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.query_context_lineage_subgraph( + context="context_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].context + mock_val = "context_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_query_context_lineage_subgraph_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.query_context_lineage_subgraph( + metadata_service.QueryContextLineageSubgraphRequest(), + context="context_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.CreateExecutionRequest, + dict, + ], +) +def test_create_execution(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_execution), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = gca_execution.Execution( + name="name_value", + display_name="display_name_value", + state=gca_execution.Execution.State.NEW, + etag="etag_value", + schema_title="schema_title_value", + schema_version="schema_version_value", + description="description_value", + ) + response = client.create_execution(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.CreateExecutionRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_execution.Execution) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.state == gca_execution.Execution.State.NEW + assert response.etag == "etag_value" + assert response.schema_title == "schema_title_value" + assert response.schema_version == "schema_version_value" + assert response.description == "description_value" + + +def test_create_execution_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_execution), "__call__") as call: + client.create_execution() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.CreateExecutionRequest() + + +@pytest.mark.asyncio +async def test_create_execution_async( + transport: str = "grpc_asyncio", + request_type=metadata_service.CreateExecutionRequest, +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_execution), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_execution.Execution( + name="name_value", + display_name="display_name_value", + state=gca_execution.Execution.State.NEW, + etag="etag_value", + schema_title="schema_title_value", + schema_version="schema_version_value", + description="description_value", + ) + ) + response = await client.create_execution(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.CreateExecutionRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_execution.Execution) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.state == gca_execution.Execution.State.NEW + assert response.etag == "etag_value" + assert response.schema_title == "schema_title_value" + assert response.schema_version == "schema_version_value" + assert response.description == "description_value" + + +@pytest.mark.asyncio +async def test_create_execution_async_from_dict(): + await test_create_execution_async(request_type=dict) + + +def test_create_execution_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.CreateExecutionRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_execution), "__call__") as call: + call.return_value = gca_execution.Execution() + client.create_execution(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_create_execution_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.CreateExecutionRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_execution), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_execution.Execution() + ) + await client.create_execution(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_create_execution_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_execution), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = gca_execution.Execution() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_execution( + parent="parent_value", + execution=gca_execution.Execution(name="name_value"), + execution_id="execution_id_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].execution + mock_val = gca_execution.Execution(name="name_value") + assert arg == mock_val + arg = args[0].execution_id + mock_val = "execution_id_value" + assert arg == mock_val + + +def test_create_execution_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_execution( + metadata_service.CreateExecutionRequest(), + parent="parent_value", + execution=gca_execution.Execution(name="name_value"), + execution_id="execution_id_value", + ) + + +@pytest.mark.asyncio +async def test_create_execution_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_execution), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = gca_execution.Execution() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_execution.Execution() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_execution( + parent="parent_value", + execution=gca_execution.Execution(name="name_value"), + execution_id="execution_id_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].execution + mock_val = gca_execution.Execution(name="name_value") + assert arg == mock_val + arg = args[0].execution_id + mock_val = "execution_id_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_create_execution_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.create_execution( + metadata_service.CreateExecutionRequest(), + parent="parent_value", + execution=gca_execution.Execution(name="name_value"), + execution_id="execution_id_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.GetExecutionRequest, + dict, + ], +) +def test_get_execution(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_execution), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = execution.Execution( + name="name_value", + display_name="display_name_value", + state=execution.Execution.State.NEW, + etag="etag_value", + schema_title="schema_title_value", + schema_version="schema_version_value", + description="description_value", + ) + response = client.get_execution(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.GetExecutionRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, execution.Execution) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.state == execution.Execution.State.NEW + assert response.etag == "etag_value" + assert response.schema_title == "schema_title_value" + assert response.schema_version == "schema_version_value" + assert response.description == "description_value" + + +def test_get_execution_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_execution), "__call__") as call: + client.get_execution() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.GetExecutionRequest() + + +@pytest.mark.asyncio +async def test_get_execution_async( + transport: str = "grpc_asyncio", request_type=metadata_service.GetExecutionRequest +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_execution), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + execution.Execution( + name="name_value", + display_name="display_name_value", + state=execution.Execution.State.NEW, + etag="etag_value", + schema_title="schema_title_value", + schema_version="schema_version_value", + description="description_value", + ) + ) + response = await client.get_execution(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.GetExecutionRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, execution.Execution) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.state == execution.Execution.State.NEW + assert response.etag == "etag_value" + assert response.schema_title == "schema_title_value" + assert response.schema_version == "schema_version_value" + assert response.description == "description_value" + + +@pytest.mark.asyncio +async def test_get_execution_async_from_dict(): + await test_get_execution_async(request_type=dict) + + +def test_get_execution_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.GetExecutionRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_execution), "__call__") as call: + call.return_value = execution.Execution() + client.get_execution(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_execution_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.GetExecutionRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_execution), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(execution.Execution()) + await client.get_execution(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_get_execution_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_execution), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = execution.Execution() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_execution( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_get_execution_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_execution( + metadata_service.GetExecutionRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_execution_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_execution), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = execution.Execution() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(execution.Execution()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_execution( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_get_execution_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_execution( + metadata_service.GetExecutionRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.ListExecutionsRequest, + dict, + ], +) +def test_list_executions(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_executions), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_service.ListExecutionsResponse( + next_page_token="next_page_token_value", + ) + response = client.list_executions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.ListExecutionsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListExecutionsPager) + assert response.next_page_token == "next_page_token_value" + + +def test_list_executions_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_executions), "__call__") as call: + client.list_executions() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.ListExecutionsRequest() + + +@pytest.mark.asyncio +async def test_list_executions_async( + transport: str = "grpc_asyncio", request_type=metadata_service.ListExecutionsRequest +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_executions), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_service.ListExecutionsResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.list_executions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.ListExecutionsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListExecutionsAsyncPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_list_executions_async_from_dict(): + await test_list_executions_async(request_type=dict) + + +def test_list_executions_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.ListExecutionsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_executions), "__call__") as call: + call.return_value = metadata_service.ListExecutionsResponse() + client.list_executions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_executions_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.ListExecutionsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_executions), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_service.ListExecutionsResponse() + ) + await client.list_executions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_list_executions_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_executions), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_service.ListExecutionsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_executions( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +def test_list_executions_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_executions( + metadata_service.ListExecutionsRequest(), + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_executions_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_executions), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_service.ListExecutionsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_service.ListExecutionsResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_executions( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_list_executions_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_executions( + metadata_service.ListExecutionsRequest(), + parent="parent_value", + ) + + +def test_list_executions_pager(transport_name: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_executions), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + metadata_service.ListExecutionsResponse( + executions=[ + execution.Execution(), + execution.Execution(), + execution.Execution(), + ], + next_page_token="abc", + ), + metadata_service.ListExecutionsResponse( + executions=[], + next_page_token="def", + ), + metadata_service.ListExecutionsResponse( + executions=[ + execution.Execution(), + ], + next_page_token="ghi", + ), + metadata_service.ListExecutionsResponse( + executions=[ + execution.Execution(), + execution.Execution(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_executions(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, execution.Execution) for i in results) + + +def test_list_executions_pages(transport_name: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_executions), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + metadata_service.ListExecutionsResponse( + executions=[ + execution.Execution(), + execution.Execution(), + execution.Execution(), + ], + next_page_token="abc", + ), + metadata_service.ListExecutionsResponse( + executions=[], + next_page_token="def", + ), + metadata_service.ListExecutionsResponse( + executions=[ + execution.Execution(), + ], + next_page_token="ghi", + ), + metadata_service.ListExecutionsResponse( + executions=[ + execution.Execution(), + execution.Execution(), + ], + ), + RuntimeError, + ) + pages = list(client.list_executions(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.asyncio +async def test_list_executions_async_pager(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_executions), "__call__", new_callable=mock.AsyncMock + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + metadata_service.ListExecutionsResponse( + executions=[ + execution.Execution(), + execution.Execution(), + execution.Execution(), + ], + next_page_token="abc", + ), + metadata_service.ListExecutionsResponse( + executions=[], + next_page_token="def", + ), + metadata_service.ListExecutionsResponse( + executions=[ + execution.Execution(), + ], + next_page_token="ghi", + ), + metadata_service.ListExecutionsResponse( + executions=[ + execution.Execution(), + execution.Execution(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_executions( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, execution.Execution) for i in responses) + + +@pytest.mark.asyncio +async def test_list_executions_async_pages(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_executions), "__call__", new_callable=mock.AsyncMock + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + metadata_service.ListExecutionsResponse( + executions=[ + execution.Execution(), + execution.Execution(), + execution.Execution(), + ], + next_page_token="abc", + ), + metadata_service.ListExecutionsResponse( + executions=[], + next_page_token="def", + ), + metadata_service.ListExecutionsResponse( + executions=[ + execution.Execution(), + ], + next_page_token="ghi", + ), + metadata_service.ListExecutionsResponse( + executions=[ + execution.Execution(), + execution.Execution(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.list_executions(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.UpdateExecutionRequest, + dict, + ], +) +def test_update_execution(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_execution), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = gca_execution.Execution( + name="name_value", + display_name="display_name_value", + state=gca_execution.Execution.State.NEW, + etag="etag_value", + schema_title="schema_title_value", + schema_version="schema_version_value", + description="description_value", + ) + response = client.update_execution(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.UpdateExecutionRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_execution.Execution) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.state == gca_execution.Execution.State.NEW + assert response.etag == "etag_value" + assert response.schema_title == "schema_title_value" + assert response.schema_version == "schema_version_value" + assert response.description == "description_value" + + +def test_update_execution_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_execution), "__call__") as call: + client.update_execution() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.UpdateExecutionRequest() + + +@pytest.mark.asyncio +async def test_update_execution_async( + transport: str = "grpc_asyncio", + request_type=metadata_service.UpdateExecutionRequest, +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_execution), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_execution.Execution( + name="name_value", + display_name="display_name_value", + state=gca_execution.Execution.State.NEW, + etag="etag_value", + schema_title="schema_title_value", + schema_version="schema_version_value", + description="description_value", + ) + ) + response = await client.update_execution(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.UpdateExecutionRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_execution.Execution) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.state == gca_execution.Execution.State.NEW + assert response.etag == "etag_value" + assert response.schema_title == "schema_title_value" + assert response.schema_version == "schema_version_value" + assert response.description == "description_value" + + +@pytest.mark.asyncio +async def test_update_execution_async_from_dict(): + await test_update_execution_async(request_type=dict) + + +def test_update_execution_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.UpdateExecutionRequest() + + request.execution.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_execution), "__call__") as call: + call.return_value = gca_execution.Execution() + client.update_execution(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "execution.name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_update_execution_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.UpdateExecutionRequest() + + request.execution.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_execution), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_execution.Execution() + ) + await client.update_execution(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "execution.name=name_value", + ) in kw["metadata"] + + +def test_update_execution_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_execution), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = gca_execution.Execution() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.update_execution( + execution=gca_execution.Execution(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].execution + mock_val = gca_execution.Execution(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + + +def test_update_execution_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_execution( + metadata_service.UpdateExecutionRequest(), + execution=gca_execution.Execution(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.asyncio +async def test_update_execution_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_execution), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = gca_execution.Execution() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_execution.Execution() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.update_execution( + execution=gca_execution.Execution(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].execution + mock_val = gca_execution.Execution(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_update_execution_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.update_execution( + metadata_service.UpdateExecutionRequest(), + execution=gca_execution.Execution(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.DeleteExecutionRequest, + dict, + ], +) +def test_delete_execution(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_execution), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.delete_execution(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.DeleteExecutionRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_delete_execution_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_execution), "__call__") as call: + client.delete_execution() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.DeleteExecutionRequest() + + +@pytest.mark.asyncio +async def test_delete_execution_async( + transport: str = "grpc_asyncio", + request_type=metadata_service.DeleteExecutionRequest, +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_execution), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.delete_execution(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.DeleteExecutionRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_delete_execution_async_from_dict(): + await test_delete_execution_async(request_type=dict) + + +def test_delete_execution_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.DeleteExecutionRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_execution), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_execution(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_execution_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.DeleteExecutionRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_execution), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.delete_execution(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_delete_execution_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_execution), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_execution( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_delete_execution_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_execution( + metadata_service.DeleteExecutionRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_delete_execution_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_execution), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_execution( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_delete_execution_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.delete_execution( + metadata_service.DeleteExecutionRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.PurgeExecutionsRequest, + dict, + ], +) +def test_purge_executions(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.purge_executions), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.purge_executions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.PurgeExecutionsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_purge_executions_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.purge_executions), "__call__") as call: + client.purge_executions() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.PurgeExecutionsRequest() + + +@pytest.mark.asyncio +async def test_purge_executions_async( + transport: str = "grpc_asyncio", + request_type=metadata_service.PurgeExecutionsRequest, +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.purge_executions), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.purge_executions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.PurgeExecutionsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_purge_executions_async_from_dict(): + await test_purge_executions_async(request_type=dict) + + +def test_purge_executions_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.PurgeExecutionsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.purge_executions), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.purge_executions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_purge_executions_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.PurgeExecutionsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.purge_executions), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.purge_executions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_purge_executions_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.purge_executions), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.purge_executions( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +def test_purge_executions_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.purge_executions( + metadata_service.PurgeExecutionsRequest(), + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_purge_executions_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.purge_executions), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.purge_executions( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_purge_executions_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.purge_executions( + metadata_service.PurgeExecutionsRequest(), + parent="parent_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.AddExecutionEventsRequest, + dict, + ], +) +def test_add_execution_events(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_execution_events), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_service.AddExecutionEventsResponse() + response = client.add_execution_events(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.AddExecutionEventsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, metadata_service.AddExecutionEventsResponse) + + +def test_add_execution_events_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_execution_events), "__call__" + ) as call: + client.add_execution_events() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.AddExecutionEventsRequest() + + +@pytest.mark.asyncio +async def test_add_execution_events_async( + transport: str = "grpc_asyncio", + request_type=metadata_service.AddExecutionEventsRequest, +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_execution_events), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_service.AddExecutionEventsResponse() + ) + response = await client.add_execution_events(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.AddExecutionEventsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, metadata_service.AddExecutionEventsResponse) + + +@pytest.mark.asyncio +async def test_add_execution_events_async_from_dict(): + await test_add_execution_events_async(request_type=dict) + + +def test_add_execution_events_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.AddExecutionEventsRequest() + + request.execution = "execution_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_execution_events), "__call__" + ) as call: + call.return_value = metadata_service.AddExecutionEventsResponse() + client.add_execution_events(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "execution=execution_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_add_execution_events_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.AddExecutionEventsRequest() + + request.execution = "execution_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_execution_events), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_service.AddExecutionEventsResponse() + ) + await client.add_execution_events(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "execution=execution_value", + ) in kw["metadata"] + + +def test_add_execution_events_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_execution_events), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_service.AddExecutionEventsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.add_execution_events( + execution="execution_value", + events=[event.Event(artifact="artifact_value")], + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].execution + mock_val = "execution_value" + assert arg == mock_val + arg = args[0].events + mock_val = [event.Event(artifact="artifact_value")] + assert arg == mock_val + + +def test_add_execution_events_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.add_execution_events( + metadata_service.AddExecutionEventsRequest(), + execution="execution_value", + events=[event.Event(artifact="artifact_value")], + ) + + +@pytest.mark.asyncio +async def test_add_execution_events_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_execution_events), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_service.AddExecutionEventsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_service.AddExecutionEventsResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.add_execution_events( + execution="execution_value", + events=[event.Event(artifact="artifact_value")], + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].execution + mock_val = "execution_value" + assert arg == mock_val + arg = args[0].events + mock_val = [event.Event(artifact="artifact_value")] + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_add_execution_events_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.add_execution_events( + metadata_service.AddExecutionEventsRequest(), + execution="execution_value", + events=[event.Event(artifact="artifact_value")], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.QueryExecutionInputsAndOutputsRequest, + dict, + ], +) +def test_query_execution_inputs_and_outputs(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_execution_inputs_and_outputs), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = lineage_subgraph.LineageSubgraph() + response = client.query_execution_inputs_and_outputs(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.QueryExecutionInputsAndOutputsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, lineage_subgraph.LineageSubgraph) + + +def test_query_execution_inputs_and_outputs_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_execution_inputs_and_outputs), "__call__" + ) as call: + client.query_execution_inputs_and_outputs() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.QueryExecutionInputsAndOutputsRequest() + + +@pytest.mark.asyncio +async def test_query_execution_inputs_and_outputs_async( + transport: str = "grpc_asyncio", + request_type=metadata_service.QueryExecutionInputsAndOutputsRequest, +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_execution_inputs_and_outputs), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + lineage_subgraph.LineageSubgraph() + ) + response = await client.query_execution_inputs_and_outputs(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.QueryExecutionInputsAndOutputsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, lineage_subgraph.LineageSubgraph) + + +@pytest.mark.asyncio +async def test_query_execution_inputs_and_outputs_async_from_dict(): + await test_query_execution_inputs_and_outputs_async(request_type=dict) + + +def test_query_execution_inputs_and_outputs_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.QueryExecutionInputsAndOutputsRequest() + + request.execution = "execution_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_execution_inputs_and_outputs), "__call__" + ) as call: + call.return_value = lineage_subgraph.LineageSubgraph() + client.query_execution_inputs_and_outputs(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "execution=execution_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_query_execution_inputs_and_outputs_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.QueryExecutionInputsAndOutputsRequest() + + request.execution = "execution_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_execution_inputs_and_outputs), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + lineage_subgraph.LineageSubgraph() + ) + await client.query_execution_inputs_and_outputs(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "execution=execution_value", + ) in kw["metadata"] + + +def test_query_execution_inputs_and_outputs_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_execution_inputs_and_outputs), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = lineage_subgraph.LineageSubgraph() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.query_execution_inputs_and_outputs( + execution="execution_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].execution + mock_val = "execution_value" + assert arg == mock_val + + +def test_query_execution_inputs_and_outputs_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.query_execution_inputs_and_outputs( + metadata_service.QueryExecutionInputsAndOutputsRequest(), + execution="execution_value", + ) + + +@pytest.mark.asyncio +async def test_query_execution_inputs_and_outputs_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_execution_inputs_and_outputs), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = lineage_subgraph.LineageSubgraph() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + lineage_subgraph.LineageSubgraph() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.query_execution_inputs_and_outputs( + execution="execution_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].execution + mock_val = "execution_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_query_execution_inputs_and_outputs_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.query_execution_inputs_and_outputs( + metadata_service.QueryExecutionInputsAndOutputsRequest(), + execution="execution_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.CreateMetadataSchemaRequest, + dict, + ], +) +def test_create_metadata_schema(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_metadata_schema), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gca_metadata_schema.MetadataSchema( + name="name_value", + schema_version="schema_version_value", + schema="schema_value", + schema_type=gca_metadata_schema.MetadataSchema.MetadataSchemaType.ARTIFACT_TYPE, + description="description_value", + ) + response = client.create_metadata_schema(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.CreateMetadataSchemaRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_metadata_schema.MetadataSchema) + assert response.name == "name_value" + assert response.schema_version == "schema_version_value" + assert response.schema == "schema_value" + assert ( + response.schema_type + == gca_metadata_schema.MetadataSchema.MetadataSchemaType.ARTIFACT_TYPE + ) + assert response.description == "description_value" + + +def test_create_metadata_schema_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_metadata_schema), "__call__" + ) as call: + client.create_metadata_schema() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.CreateMetadataSchemaRequest() + + +@pytest.mark.asyncio +async def test_create_metadata_schema_async( + transport: str = "grpc_asyncio", + request_type=metadata_service.CreateMetadataSchemaRequest, +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_metadata_schema), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_metadata_schema.MetadataSchema( + name="name_value", + schema_version="schema_version_value", + schema="schema_value", + schema_type=gca_metadata_schema.MetadataSchema.MetadataSchemaType.ARTIFACT_TYPE, + description="description_value", + ) + ) + response = await client.create_metadata_schema(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.CreateMetadataSchemaRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_metadata_schema.MetadataSchema) + assert response.name == "name_value" + assert response.schema_version == "schema_version_value" + assert response.schema == "schema_value" + assert ( + response.schema_type + == gca_metadata_schema.MetadataSchema.MetadataSchemaType.ARTIFACT_TYPE + ) + assert response.description == "description_value" + + +@pytest.mark.asyncio +async def test_create_metadata_schema_async_from_dict(): + await test_create_metadata_schema_async(request_type=dict) + + +def test_create_metadata_schema_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.CreateMetadataSchemaRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_metadata_schema), "__call__" + ) as call: + call.return_value = gca_metadata_schema.MetadataSchema() + client.create_metadata_schema(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_create_metadata_schema_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.CreateMetadataSchemaRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_metadata_schema), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_metadata_schema.MetadataSchema() + ) + await client.create_metadata_schema(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_create_metadata_schema_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_metadata_schema), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gca_metadata_schema.MetadataSchema() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_metadata_schema( + parent="parent_value", + metadata_schema=gca_metadata_schema.MetadataSchema(name="name_value"), + metadata_schema_id="metadata_schema_id_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].metadata_schema + mock_val = gca_metadata_schema.MetadataSchema(name="name_value") + assert arg == mock_val + arg = args[0].metadata_schema_id + mock_val = "metadata_schema_id_value" + assert arg == mock_val + + +def test_create_metadata_schema_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_metadata_schema( + metadata_service.CreateMetadataSchemaRequest(), + parent="parent_value", + metadata_schema=gca_metadata_schema.MetadataSchema(name="name_value"), + metadata_schema_id="metadata_schema_id_value", + ) + + +@pytest.mark.asyncio +async def test_create_metadata_schema_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_metadata_schema), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gca_metadata_schema.MetadataSchema() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_metadata_schema.MetadataSchema() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_metadata_schema( + parent="parent_value", + metadata_schema=gca_metadata_schema.MetadataSchema(name="name_value"), + metadata_schema_id="metadata_schema_id_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].metadata_schema + mock_val = gca_metadata_schema.MetadataSchema(name="name_value") + assert arg == mock_val + arg = args[0].metadata_schema_id + mock_val = "metadata_schema_id_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_create_metadata_schema_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.create_metadata_schema( + metadata_service.CreateMetadataSchemaRequest(), + parent="parent_value", + metadata_schema=gca_metadata_schema.MetadataSchema(name="name_value"), + metadata_schema_id="metadata_schema_id_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.GetMetadataSchemaRequest, + dict, + ], +) +def test_get_metadata_schema(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_metadata_schema), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_schema.MetadataSchema( + name="name_value", + schema_version="schema_version_value", + schema="schema_value", + schema_type=metadata_schema.MetadataSchema.MetadataSchemaType.ARTIFACT_TYPE, + description="description_value", + ) + response = client.get_metadata_schema(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.GetMetadataSchemaRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, metadata_schema.MetadataSchema) + assert response.name == "name_value" + assert response.schema_version == "schema_version_value" + assert response.schema == "schema_value" + assert ( + response.schema_type + == metadata_schema.MetadataSchema.MetadataSchemaType.ARTIFACT_TYPE + ) + assert response.description == "description_value" + + +def test_get_metadata_schema_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_metadata_schema), "__call__" + ) as call: + client.get_metadata_schema() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.GetMetadataSchemaRequest() + + +@pytest.mark.asyncio +async def test_get_metadata_schema_async( + transport: str = "grpc_asyncio", + request_type=metadata_service.GetMetadataSchemaRequest, +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_metadata_schema), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_schema.MetadataSchema( + name="name_value", + schema_version="schema_version_value", + schema="schema_value", + schema_type=metadata_schema.MetadataSchema.MetadataSchemaType.ARTIFACT_TYPE, + description="description_value", + ) + ) + response = await client.get_metadata_schema(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.GetMetadataSchemaRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, metadata_schema.MetadataSchema) + assert response.name == "name_value" + assert response.schema_version == "schema_version_value" + assert response.schema == "schema_value" + assert ( + response.schema_type + == metadata_schema.MetadataSchema.MetadataSchemaType.ARTIFACT_TYPE + ) + assert response.description == "description_value" + + +@pytest.mark.asyncio +async def test_get_metadata_schema_async_from_dict(): + await test_get_metadata_schema_async(request_type=dict) + + +def test_get_metadata_schema_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.GetMetadataSchemaRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_metadata_schema), "__call__" + ) as call: + call.return_value = metadata_schema.MetadataSchema() + client.get_metadata_schema(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_metadata_schema_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.GetMetadataSchemaRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_metadata_schema), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_schema.MetadataSchema() + ) + await client.get_metadata_schema(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_get_metadata_schema_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_metadata_schema), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_schema.MetadataSchema() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_metadata_schema( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_get_metadata_schema_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_metadata_schema( + metadata_service.GetMetadataSchemaRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_metadata_schema_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_metadata_schema), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_schema.MetadataSchema() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_schema.MetadataSchema() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_metadata_schema( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_get_metadata_schema_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_metadata_schema( + metadata_service.GetMetadataSchemaRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.ListMetadataSchemasRequest, + dict, + ], +) +def test_list_metadata_schemas(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_metadata_schemas), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_service.ListMetadataSchemasResponse( + next_page_token="next_page_token_value", + ) + response = client.list_metadata_schemas(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.ListMetadataSchemasRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListMetadataSchemasPager) + assert response.next_page_token == "next_page_token_value" + + +def test_list_metadata_schemas_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_metadata_schemas), "__call__" + ) as call: + client.list_metadata_schemas() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.ListMetadataSchemasRequest() + + +@pytest.mark.asyncio +async def test_list_metadata_schemas_async( + transport: str = "grpc_asyncio", + request_type=metadata_service.ListMetadataSchemasRequest, +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_metadata_schemas), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_service.ListMetadataSchemasResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.list_metadata_schemas(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.ListMetadataSchemasRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListMetadataSchemasAsyncPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_list_metadata_schemas_async_from_dict(): + await test_list_metadata_schemas_async(request_type=dict) + + +def test_list_metadata_schemas_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.ListMetadataSchemasRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_metadata_schemas), "__call__" + ) as call: + call.return_value = metadata_service.ListMetadataSchemasResponse() + client.list_metadata_schemas(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_metadata_schemas_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.ListMetadataSchemasRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_metadata_schemas), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_service.ListMetadataSchemasResponse() + ) + await client.list_metadata_schemas(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_list_metadata_schemas_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_metadata_schemas), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_service.ListMetadataSchemasResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_metadata_schemas( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +def test_list_metadata_schemas_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_metadata_schemas( + metadata_service.ListMetadataSchemasRequest(), + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_metadata_schemas_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_metadata_schemas), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_service.ListMetadataSchemasResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_service.ListMetadataSchemasResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_metadata_schemas( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_list_metadata_schemas_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_metadata_schemas( + metadata_service.ListMetadataSchemasRequest(), + parent="parent_value", + ) + + +def test_list_metadata_schemas_pager(transport_name: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_metadata_schemas), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + metadata_service.ListMetadataSchemasResponse( + metadata_schemas=[ + metadata_schema.MetadataSchema(), + metadata_schema.MetadataSchema(), + metadata_schema.MetadataSchema(), + ], + next_page_token="abc", + ), + metadata_service.ListMetadataSchemasResponse( + metadata_schemas=[], + next_page_token="def", + ), + metadata_service.ListMetadataSchemasResponse( + metadata_schemas=[ + metadata_schema.MetadataSchema(), + ], + next_page_token="ghi", + ), + metadata_service.ListMetadataSchemasResponse( + metadata_schemas=[ + metadata_schema.MetadataSchema(), + metadata_schema.MetadataSchema(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_metadata_schemas(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, metadata_schema.MetadataSchema) for i in results) + + +def test_list_metadata_schemas_pages(transport_name: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_metadata_schemas), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + metadata_service.ListMetadataSchemasResponse( + metadata_schemas=[ + metadata_schema.MetadataSchema(), + metadata_schema.MetadataSchema(), + metadata_schema.MetadataSchema(), + ], + next_page_token="abc", + ), + metadata_service.ListMetadataSchemasResponse( + metadata_schemas=[], + next_page_token="def", + ), + metadata_service.ListMetadataSchemasResponse( + metadata_schemas=[ + metadata_schema.MetadataSchema(), + ], + next_page_token="ghi", + ), + metadata_service.ListMetadataSchemasResponse( + metadata_schemas=[ + metadata_schema.MetadataSchema(), + metadata_schema.MetadataSchema(), + ], + ), + RuntimeError, + ) + pages = list(client.list_metadata_schemas(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.asyncio +async def test_list_metadata_schemas_async_pager(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_metadata_schemas), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + metadata_service.ListMetadataSchemasResponse( + metadata_schemas=[ + metadata_schema.MetadataSchema(), + metadata_schema.MetadataSchema(), + metadata_schema.MetadataSchema(), + ], + next_page_token="abc", + ), + metadata_service.ListMetadataSchemasResponse( + metadata_schemas=[], + next_page_token="def", + ), + metadata_service.ListMetadataSchemasResponse( + metadata_schemas=[ + metadata_schema.MetadataSchema(), + ], + next_page_token="ghi", + ), + metadata_service.ListMetadataSchemasResponse( + metadata_schemas=[ + metadata_schema.MetadataSchema(), + metadata_schema.MetadataSchema(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_metadata_schemas( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, metadata_schema.MetadataSchema) for i in responses) + + +@pytest.mark.asyncio +async def test_list_metadata_schemas_async_pages(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_metadata_schemas), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + metadata_service.ListMetadataSchemasResponse( + metadata_schemas=[ + metadata_schema.MetadataSchema(), + metadata_schema.MetadataSchema(), + metadata_schema.MetadataSchema(), + ], + next_page_token="abc", + ), + metadata_service.ListMetadataSchemasResponse( + metadata_schemas=[], + next_page_token="def", + ), + metadata_service.ListMetadataSchemasResponse( + metadata_schemas=[ + metadata_schema.MetadataSchema(), + ], + next_page_token="ghi", + ), + metadata_service.ListMetadataSchemasResponse( + metadata_schemas=[ + metadata_schema.MetadataSchema(), + metadata_schema.MetadataSchema(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.list_metadata_schemas(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.QueryArtifactLineageSubgraphRequest, + dict, + ], +) +def test_query_artifact_lineage_subgraph(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_artifact_lineage_subgraph), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = lineage_subgraph.LineageSubgraph() + response = client.query_artifact_lineage_subgraph(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.QueryArtifactLineageSubgraphRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, lineage_subgraph.LineageSubgraph) + + +def test_query_artifact_lineage_subgraph_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_artifact_lineage_subgraph), "__call__" + ) as call: + client.query_artifact_lineage_subgraph() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.QueryArtifactLineageSubgraphRequest() + + +@pytest.mark.asyncio +async def test_query_artifact_lineage_subgraph_async( + transport: str = "grpc_asyncio", + request_type=metadata_service.QueryArtifactLineageSubgraphRequest, +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_artifact_lineage_subgraph), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + lineage_subgraph.LineageSubgraph() + ) + response = await client.query_artifact_lineage_subgraph(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.QueryArtifactLineageSubgraphRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, lineage_subgraph.LineageSubgraph) + + +@pytest.mark.asyncio +async def test_query_artifact_lineage_subgraph_async_from_dict(): + await test_query_artifact_lineage_subgraph_async(request_type=dict) + + +def test_query_artifact_lineage_subgraph_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.QueryArtifactLineageSubgraphRequest() + + request.artifact = "artifact_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_artifact_lineage_subgraph), "__call__" + ) as call: + call.return_value = lineage_subgraph.LineageSubgraph() + client.query_artifact_lineage_subgraph(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "artifact=artifact_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_query_artifact_lineage_subgraph_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.QueryArtifactLineageSubgraphRequest() + + request.artifact = "artifact_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_artifact_lineage_subgraph), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + lineage_subgraph.LineageSubgraph() + ) + await client.query_artifact_lineage_subgraph(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "artifact=artifact_value", + ) in kw["metadata"] + + +def test_query_artifact_lineage_subgraph_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_artifact_lineage_subgraph), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = lineage_subgraph.LineageSubgraph() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.query_artifact_lineage_subgraph( + artifact="artifact_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].artifact + mock_val = "artifact_value" + assert arg == mock_val + + +def test_query_artifact_lineage_subgraph_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.query_artifact_lineage_subgraph( + metadata_service.QueryArtifactLineageSubgraphRequest(), + artifact="artifact_value", + ) + + +@pytest.mark.asyncio +async def test_query_artifact_lineage_subgraph_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_artifact_lineage_subgraph), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = lineage_subgraph.LineageSubgraph() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + lineage_subgraph.LineageSubgraph() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.query_artifact_lineage_subgraph( + artifact="artifact_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].artifact + mock_val = "artifact_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_query_artifact_lineage_subgraph_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.query_artifact_lineage_subgraph( + metadata_service.QueryArtifactLineageSubgraphRequest(), + artifact="artifact_value", + ) + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.MetadataServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.MetadataServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = MetadataServiceClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide an api_key and a transport instance. + transport = transports.MetadataServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = MetadataServiceClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = MetadataServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.MetadataServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = MetadataServiceClient( + client_options={"scopes": ["1", "2"]}, + transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.MetadataServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + client = MetadataServiceClient(transport=transport) + assert client.transport is transport + + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.MetadataServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.MetadataServiceGrpcAsyncIOTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.MetadataServiceGrpcTransport, + transports.MetadataServiceGrpcAsyncIOTransport, + ], +) +def test_transport_adc(transport_class): + # Test default credentials are used if not provided. + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class() + adc.assert_called_once() + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = MetadataServiceClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + +def test_transport_grpc_default(): + # A client should use the gRPC transport by default. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.MetadataServiceGrpcTransport, + ) + + +def test_metadata_service_base_transport_error(): + # Passing both a credentials object and credentials_file should raise an error + with pytest.raises(core_exceptions.DuplicateCredentialArgs): + transport = transports.MetadataServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + credentials_file="credentials.json", + ) + + +def test_metadata_service_base_transport(): + # Instantiate the base transport. + with mock.patch( + "google.cloud.aiplatform_v1.services.metadata_service.transports.MetadataServiceTransport.__init__" + ) as Transport: + Transport.return_value = None + transport = transports.MetadataServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Every method on the transport should just blindly + # raise NotImplementedError. + methods = ( + "create_metadata_store", + "get_metadata_store", + "list_metadata_stores", + "delete_metadata_store", + "create_artifact", + "get_artifact", + "list_artifacts", + "update_artifact", + "delete_artifact", + "purge_artifacts", + "create_context", + "get_context", + "list_contexts", + "update_context", + "delete_context", + "purge_contexts", + "add_context_artifacts_and_executions", + "add_context_children", + "query_context_lineage_subgraph", + "create_execution", + "get_execution", + "list_executions", + "update_execution", + "delete_execution", + "purge_executions", + "add_execution_events", + "query_execution_inputs_and_outputs", + "create_metadata_schema", + "get_metadata_schema", + "list_metadata_schemas", + "query_artifact_lineage_subgraph", + "set_iam_policy", + "get_iam_policy", + "test_iam_permissions", + "get_location", + "list_locations", + "get_operation", + "wait_operation", + "cancel_operation", + "delete_operation", + "list_operations", + ) + for method in methods: + with pytest.raises(NotImplementedError): + getattr(transport, method)(request=object()) + + with pytest.raises(NotImplementedError): + transport.close() + + # Additionally, the LRO client (a property) should + # also raise NotImplementedError + with pytest.raises(NotImplementedError): + transport.operations_client + + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + + +def test_metadata_service_base_transport_with_credentials_file(): + # Instantiate the base transport with a credentials file + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch( + "google.cloud.aiplatform_v1.services.metadata_service.transports.MetadataServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.MetadataServiceTransport( + credentials_file="credentials.json", + quota_project_id="octopus", + ) + load_creds.assert_called_once_with( + "credentials.json", + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +def test_metadata_service_base_transport_with_adc(): + # Test the default credentials are used if credentials and credentials_file are None. + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( + "google.cloud.aiplatform_v1.services.metadata_service.transports.MetadataServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.MetadataServiceTransport() + adc.assert_called_once() + + +def test_metadata_service_auth_adc(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + MetadataServiceClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id=None, + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.MetadataServiceGrpcTransport, + transports.MetadataServiceGrpcAsyncIOTransport, + ], +) +def test_metadata_service_transport_auth_adc(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.MetadataServiceGrpcTransport, grpc_helpers), + (transports.MetadataServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +def test_metadata_service_transport_create_channel(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=["1", "2"], + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.MetadataServiceGrpcTransport, + transports.MetadataServiceGrpcAsyncIOTransport, + ], +) +def test_metadata_service_grpc_transport_client_cert_source_for_mtls(transport_class): + cred = ga_credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds, + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback, + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, private_key=expected_key + ) + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_metadata_service_host_no_port(transport_name): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions( + api_endpoint="aiplatform.googleapis.com" + ), + transport=transport_name, + ) + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_metadata_service_host_with_port(transport_name): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions( + api_endpoint="aiplatform.googleapis.com:8000" + ), + transport=transport_name, + ) + assert client.transport._host == ("aiplatform.googleapis.com:8000") + + +def test_metadata_service_grpc_transport_channel(): + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.MetadataServiceGrpcTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +def test_metadata_service_grpc_asyncio_transport_channel(): + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.MetadataServiceGrpcAsyncIOTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize( + "transport_class", + [ + transports.MetadataServiceGrpcTransport, + transports.MetadataServiceGrpcAsyncIOTransport, + ], +) +def test_metadata_service_transport_channel_mtls_with_client_cert_source( + transport_class, +): + with mock.patch( + "grpc.ssl_channel_credentials", autospec=True + ) as grpc_ssl_channel_cred: + with mock.patch.object( + transport_class, "create_channel" + ) as grpc_create_channel: + mock_ssl_cred = mock.Mock() + grpc_ssl_channel_cred.return_value = mock_ssl_cred + + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + + cred = ga_credentials.AnonymousCredentials() + with pytest.warns(DeprecationWarning): + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (cred, None) + transport = transport_class( + host="squid.clam.whelk", + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=client_cert_source_callback, + ) + adc.assert_called_once() + + grpc_ssl_channel_cred.assert_called_once_with( + certificate_chain=b"cert bytes", private_key=b"key bytes" + ) + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize( + "transport_class", + [ + transports.MetadataServiceGrpcTransport, + transports.MetadataServiceGrpcAsyncIOTransport, + ], +) +def test_metadata_service_transport_channel_mtls_with_adc(transport_class): + mock_ssl_cred = mock.Mock() + with mock.patch.multiple( + "google.auth.transport.grpc.SslCredentials", + __init__=mock.Mock(return_value=None), + ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), + ): + with mock.patch.object( + transport_class, "create_channel" + ) as grpc_create_channel: + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + mock_cred = mock.Mock() + + with pytest.warns(DeprecationWarning): + transport = transport_class( + host="squid.clam.whelk", + credentials=mock_cred, + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=None, + ) + + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=mock_cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + + +def test_metadata_service_grpc_lro_client(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_metadata_service_grpc_lro_async_client(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_artifact_path(): + project = "squid" + location = "clam" + metadata_store = "whelk" + artifact = "octopus" + expected = "projects/{project}/locations/{location}/metadataStores/{metadata_store}/artifacts/{artifact}".format( + project=project, + location=location, + metadata_store=metadata_store, + artifact=artifact, + ) + actual = MetadataServiceClient.artifact_path( + project, location, metadata_store, artifact + ) + assert expected == actual + + +def test_parse_artifact_path(): + expected = { + "project": "oyster", + "location": "nudibranch", + "metadata_store": "cuttlefish", + "artifact": "mussel", + } + path = MetadataServiceClient.artifact_path(**expected) + + # Check that the path construction is reversible. + actual = MetadataServiceClient.parse_artifact_path(path) + assert expected == actual + + +def test_context_path(): + project = "winkle" + location = "nautilus" + metadata_store = "scallop" + context = "abalone" + expected = "projects/{project}/locations/{location}/metadataStores/{metadata_store}/contexts/{context}".format( + project=project, + location=location, + metadata_store=metadata_store, + context=context, + ) + actual = MetadataServiceClient.context_path( + project, location, metadata_store, context + ) + assert expected == actual + + +def test_parse_context_path(): + expected = { + "project": "squid", + "location": "clam", + "metadata_store": "whelk", + "context": "octopus", + } + path = MetadataServiceClient.context_path(**expected) + + # Check that the path construction is reversible. + actual = MetadataServiceClient.parse_context_path(path) + assert expected == actual + + +def test_execution_path(): + project = "oyster" + location = "nudibranch" + metadata_store = "cuttlefish" + execution = "mussel" + expected = "projects/{project}/locations/{location}/metadataStores/{metadata_store}/executions/{execution}".format( + project=project, + location=location, + metadata_store=metadata_store, + execution=execution, + ) + actual = MetadataServiceClient.execution_path( + project, location, metadata_store, execution + ) + assert expected == actual + + +def test_parse_execution_path(): + expected = { + "project": "winkle", + "location": "nautilus", + "metadata_store": "scallop", + "execution": "abalone", + } + path = MetadataServiceClient.execution_path(**expected) + + # Check that the path construction is reversible. + actual = MetadataServiceClient.parse_execution_path(path) + assert expected == actual + + +def test_metadata_schema_path(): + project = "squid" + location = "clam" + metadata_store = "whelk" + metadata_schema = "octopus" + expected = "projects/{project}/locations/{location}/metadataStores/{metadata_store}/metadataSchemas/{metadata_schema}".format( + project=project, + location=location, + metadata_store=metadata_store, + metadata_schema=metadata_schema, + ) + actual = MetadataServiceClient.metadata_schema_path( + project, location, metadata_store, metadata_schema + ) + assert expected == actual + + +def test_parse_metadata_schema_path(): + expected = { + "project": "oyster", + "location": "nudibranch", + "metadata_store": "cuttlefish", + "metadata_schema": "mussel", + } + path = MetadataServiceClient.metadata_schema_path(**expected) + + # Check that the path construction is reversible. + actual = MetadataServiceClient.parse_metadata_schema_path(path) + assert expected == actual + + +def test_metadata_store_path(): + project = "winkle" + location = "nautilus" + metadata_store = "scallop" + expected = "projects/{project}/locations/{location}/metadataStores/{metadata_store}".format( + project=project, + location=location, + metadata_store=metadata_store, + ) + actual = MetadataServiceClient.metadata_store_path( + project, location, metadata_store + ) + assert expected == actual + + +def test_parse_metadata_store_path(): + expected = { + "project": "abalone", + "location": "squid", + "metadata_store": "clam", + } + path = MetadataServiceClient.metadata_store_path(**expected) + + # Check that the path construction is reversible. + actual = MetadataServiceClient.parse_metadata_store_path(path) + assert expected == actual + + +def test_common_billing_account_path(): + billing_account = "whelk" + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + actual = MetadataServiceClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "octopus", + } + path = MetadataServiceClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = MetadataServiceClient.parse_common_billing_account_path(path) + assert expected == actual + + +def test_common_folder_path(): + folder = "oyster" + expected = "folders/{folder}".format( + folder=folder, + ) + actual = MetadataServiceClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "nudibranch", + } + path = MetadataServiceClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = MetadataServiceClient.parse_common_folder_path(path) + assert expected == actual + + +def test_common_organization_path(): + organization = "cuttlefish" + expected = "organizations/{organization}".format( + organization=organization, + ) + actual = MetadataServiceClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "mussel", + } + path = MetadataServiceClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = MetadataServiceClient.parse_common_organization_path(path) + assert expected == actual + + +def test_common_project_path(): + project = "winkle" + expected = "projects/{project}".format( + project=project, + ) + actual = MetadataServiceClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "nautilus", + } + path = MetadataServiceClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = MetadataServiceClient.parse_common_project_path(path) + assert expected == actual + + +def test_common_location_path(): + project = "scallop" + location = "abalone" + expected = "projects/{project}/locations/{location}".format( + project=project, + location=location, + ) + actual = MetadataServiceClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "squid", + "location": "clam", + } + path = MetadataServiceClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = MetadataServiceClient.parse_common_location_path(path) + assert expected == actual + + +def test_client_with_default_client_info(): + client_info = gapic_v1.client_info.ClientInfo() + + with mock.patch.object( + transports.MetadataServiceTransport, "_prep_wrapped_messages" + ) as prep: + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + with mock.patch.object( + transports.MetadataServiceTransport, "_prep_wrapped_messages" + ) as prep: + transport_class = MetadataServiceClient.get_transport_class() + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_delete_operation(transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_operation(transport: str = "grpc"): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_operation_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = None + + client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_operation_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_delete_operation_from_dict(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_delete_operation_from_dict_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_cancel_operation(transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation(transport: str = "grpc"): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_wait_operation(transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_wait_operation(transport: str = "grpc"): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_wait_operation_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_wait_operation_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_wait_operation_from_dict(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_wait_operation_from_dict_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_operation(transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_get_operation(transport: str = "grpc"): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_get_operation_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_get_operation_from_dict(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_operations(transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + response = client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +@pytest.mark.asyncio +async def test_list_operations(transport: str = "grpc"): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +def test_list_operations_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_operations_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_operations_from_dict(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + response = client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_operations_from_dict_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_locations(transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + response = client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +@pytest.mark.asyncio +async def test_list_locations(transport: str = "grpc"): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +def test_list_locations_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_locations_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_locations_from_dict(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + response = client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_locations_from_dict_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_location(transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + response = client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +@pytest.mark.asyncio +async def test_get_location_async(transport: str = "grpc_asyncio"): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +def test_get_location_field_headers(): + client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials()) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = locations_pb2.Location() + + client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_location_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials() + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +def test_get_location_from_dict(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + response = client.get_location( + request={ + "name": "locations/abc", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_location_from_dict_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_set_iam_policy(transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + response = client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + response = await client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_set_iam_policy_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_set_iam_policy_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_set_iam_policy_from_dict(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_set_iam_policy_from_dict_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +def test_get_iam_policy(transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + + response = client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + + response = await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_get_iam_policy_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_iam_policy_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_get_iam_policy_from_dict(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_iam_policy_from_dict_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +def test_test_iam_permissions(transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + + response = client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + ) + + response = await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +def test_test_iam_permissions_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_test_iam_permissions_from_dict(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + response = client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_from_dict_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + response = await client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (MetadataServiceClient, transports.MetadataServiceGrpcTransport), + (MetadataServiceAsyncClient, transports.MetadataServiceGrpcAsyncIOTransport), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) diff --git a/tests/unit/gapic/aiplatform_v1/test_migration_service.py b/tests/unit/gapic/aiplatform_v1/test_migration_service.py index d4d1abdd46..6e3cfe496d 100644 --- a/tests/unit/gapic/aiplatform_v1/test_migration_service.py +++ b/tests/unit/gapic/aiplatform_v1/test_migration_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,8 +14,13 @@ # limitations under the License. # import os -import mock -import packaging.version + +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock +except ImportError: + import mock import grpc from grpc.experimental import aio @@ -30,8 +35,10 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.aiplatform_v1.services.migration_service import ( @@ -40,42 +47,17 @@ from google.cloud.aiplatform_v1.services.migration_service import MigrationServiceClient from google.cloud.aiplatform_v1.services.migration_service import pagers from google.cloud.aiplatform_v1.services.migration_service import transports -from google.cloud.aiplatform_v1.services.migration_service.transports.base import ( - _API_CORE_VERSION, -) -from google.cloud.aiplatform_v1.services.migration_service.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.aiplatform_v1.types import migratable_resource from google.cloud.aiplatform_v1.types import migration_service +from google.cloud.location import locations_pb2 +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 from google.oauth2 import service_account import google.auth -# TODO(busunkim): Once google-api-core >= 1.26.0 is required: -# - Delete all the api-core and auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - -requires_api_core_lt_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), - reason="This test requires google-api-core < 1.26.0", -) - -requires_api_core_gte_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), - reason="This test requires google-api-core >= 1.26.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -122,40 +104,81 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( - "client_class", [MigrationServiceClient, MigrationServiceAsyncClient,] + "client_class,transport_name", + [ + (MigrationServiceClient, "grpc"), + (MigrationServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_migration_service_client_from_service_account_info(client_class): +def test_migration_service_client_from_service_account_info( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.MigrationServiceGrpcTransport, "grpc"), + (transports.MigrationServiceGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_migration_service_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() @pytest.mark.parametrize( - "client_class", [MigrationServiceClient, MigrationServiceAsyncClient,] + "client_class,transport_name", + [ + (MigrationServiceClient, "grpc"), + (MigrationServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_migration_service_client_from_service_account_file(client_class): +def test_migration_service_client_from_service_account_file( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") def test_migration_service_client_get_transport_class(): @@ -208,7 +231,7 @@ def test_migration_service_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -217,6 +240,7 @@ def test_migration_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -224,7 +248,7 @@ def test_migration_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -233,6 +257,7 @@ def test_migration_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -240,7 +265,7 @@ def test_migration_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -249,26 +274,27 @@ def test_migration_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -277,6 +303,7 @@ def test_migration_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -336,7 +363,7 @@ def test_migration_service_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -353,6 +380,7 @@ def test_migration_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case ADC client cert is provided. Whether client cert is used depends on @@ -377,7 +405,7 @@ def test_migration_service_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -386,6 +414,7 @@ def test_migration_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case client_cert_source and ADC client cert are not provided. @@ -398,7 +427,7 @@ def test_migration_service_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -407,9 +436,91 @@ def test_migration_service_client_mtls_env_auto( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) +@pytest.mark.parametrize( + "client_class", [MigrationServiceClient, MigrationServiceAsyncClient] +) +@mock.patch.object( + MigrationServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(MigrationServiceClient), +) +@mock.patch.object( + MigrationServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(MigrationServiceAsyncClient), +) +def test_migration_service_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + @pytest.mark.parametrize( "client_class,transport_class,transport_name", [ @@ -425,10 +536,12 @@ def test_migration_service_client_client_options_scopes( client_class, transport_class, transport_name ): # Check the case scopes are provided. - options = client_options.ClientOptions(scopes=["1", "2"],) + options = client_options.ClientOptions( + scopes=["1", "2"], + ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -437,28 +550,36 @@ def test_migration_service_client_client_options_scopes( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (MigrationServiceClient, transports.MigrationServiceGrpcTransport, "grpc"), + ( + MigrationServiceClient, + transports.MigrationServiceGrpcTransport, + "grpc", + grpc_helpers, + ), ( MigrationServiceAsyncClient, transports.MigrationServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_migration_service_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -467,6 +588,7 @@ def test_migration_service_client_client_options_credentials_file( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -486,15 +608,87 @@ def test_migration_service_client_client_options_from_dict(): client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) -def test_search_migratable_resources( - transport: str = "grpc", - request_type=migration_service.SearchMigratableResourcesRequest, +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + MigrationServiceClient, + transports.MigrationServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + MigrationServiceAsyncClient, + transports.MigrationServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_migration_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers ): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + migration_service.SearchMigratableResourcesRequest, + dict, + ], +) +def test_search_migratable_resources(request_type, transport: str = "grpc"): client = MigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -521,15 +715,12 @@ def test_search_migratable_resources( assert response.next_page_token == "next_page_token_value" -def test_search_migratable_resources_from_dict(): - test_search_migratable_resources(request_type=dict) - - def test_search_migratable_resources_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = MigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -548,7 +739,8 @@ async def test_search_migratable_resources_async( request_type=migration_service.SearchMigratableResourcesRequest, ): client = MigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -583,13 +775,15 @@ async def test_search_migratable_resources_async_from_dict(): def test_search_migratable_resources_field_headers(): - client = MigrationServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = migration_service.SearchMigratableResourcesRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -605,7 +799,10 @@ def test_search_migratable_resources_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -618,7 +815,7 @@ async def test_search_migratable_resources_field_headers_async(): # a field header. Set these to a non-empty value. request = migration_service.SearchMigratableResourcesRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -636,11 +833,16 @@ async def test_search_migratable_resources_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_search_migratable_resources_flattened(): - client = MigrationServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -650,23 +852,30 @@ def test_search_migratable_resources_flattened(): call.return_value = migration_service.SearchMigratableResourcesResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.search_migratable_resources(parent="parent_value",) + client.search_migratable_resources( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_search_migratable_resources_flattened_error(): - client = MigrationServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.search_migratable_resources( - migration_service.SearchMigratableResourcesRequest(), parent="parent_value", + migration_service.SearchMigratableResourcesRequest(), + parent="parent_value", ) @@ -688,13 +897,17 @@ async def test_search_migratable_resources_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.search_migratable_resources(parent="parent_value",) + response = await client.search_migratable_resources( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -707,12 +920,16 @@ async def test_search_migratable_resources_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.search_migratable_resources( - migration_service.SearchMigratableResourcesRequest(), parent="parent_value", + migration_service.SearchMigratableResourcesRequest(), + parent="parent_value", ) -def test_search_migratable_resources_pager(): - client = MigrationServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_search_migratable_resources_pager(transport_name: str = "grpc"): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -729,10 +946,13 @@ def test_search_migratable_resources_pager(): next_page_token="abc", ), migration_service.SearchMigratableResourcesResponse( - migratable_resources=[], next_page_token="def", + migratable_resources=[], + next_page_token="def", ), migration_service.SearchMigratableResourcesResponse( - migratable_resources=[migratable_resource.MigratableResource(),], + migratable_resources=[ + migratable_resource.MigratableResource(), + ], next_page_token="ghi", ), migration_service.SearchMigratableResourcesResponse( @@ -752,15 +972,18 @@ def test_search_migratable_resources_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all( isinstance(i, migratable_resource.MigratableResource) for i in results ) -def test_search_migratable_resources_pages(): - client = MigrationServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_search_migratable_resources_pages(transport_name: str = "grpc"): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -777,10 +1000,13 @@ def test_search_migratable_resources_pages(): next_page_token="abc", ), migration_service.SearchMigratableResourcesResponse( - migratable_resources=[], next_page_token="def", + migratable_resources=[], + next_page_token="def", ), migration_service.SearchMigratableResourcesResponse( - migratable_resources=[migratable_resource.MigratableResource(),], + migratable_resources=[ + migratable_resource.MigratableResource(), + ], next_page_token="ghi", ), migration_service.SearchMigratableResourcesResponse( @@ -819,10 +1045,13 @@ async def test_search_migratable_resources_async_pager(): next_page_token="abc", ), migration_service.SearchMigratableResourcesResponse( - migratable_resources=[], next_page_token="def", + migratable_resources=[], + next_page_token="def", ), migration_service.SearchMigratableResourcesResponse( - migratable_resources=[migratable_resource.MigratableResource(),], + migratable_resources=[ + migratable_resource.MigratableResource(), + ], next_page_token="ghi", ), migration_service.SearchMigratableResourcesResponse( @@ -833,10 +1062,12 @@ async def test_search_migratable_resources_async_pager(): ), RuntimeError, ) - async_pager = await client.search_migratable_resources(request={},) + async_pager = await client.search_migratable_resources( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -868,10 +1099,13 @@ async def test_search_migratable_resources_async_pages(): next_page_token="abc", ), migration_service.SearchMigratableResourcesResponse( - migratable_resources=[], next_page_token="def", + migratable_resources=[], + next_page_token="def", ), migration_service.SearchMigratableResourcesResponse( - migratable_resources=[migratable_resource.MigratableResource(),], + migratable_resources=[ + migratable_resource.MigratableResource(), + ], next_page_token="ghi", ), migration_service.SearchMigratableResourcesResponse( @@ -883,17 +1117,25 @@ async def test_search_migratable_resources_async_pages(): RuntimeError, ) pages = [] - async for page_ in (await client.search_migratable_resources(request={})).pages: + async for page_ in ( + await client.search_migratable_resources(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_batch_migrate_resources( - transport: str = "grpc", request_type=migration_service.BatchMigrateResourcesRequest -): +@pytest.mark.parametrize( + "request_type", + [ + migration_service.BatchMigrateResourcesRequest, + dict, + ], +) +def test_batch_migrate_resources(request_type, transport: str = "grpc"): client = MigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -917,15 +1159,12 @@ def test_batch_migrate_resources( assert isinstance(response, future.Future) -def test_batch_migrate_resources_from_dict(): - test_batch_migrate_resources(request_type=dict) - - def test_batch_migrate_resources_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = MigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -944,7 +1183,8 @@ async def test_batch_migrate_resources_async( request_type=migration_service.BatchMigrateResourcesRequest, ): client = MigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -976,13 +1216,15 @@ async def test_batch_migrate_resources_async_from_dict(): def test_batch_migrate_resources_field_headers(): - client = MigrationServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = migration_service.BatchMigrateResourcesRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -998,7 +1240,10 @@ def test_batch_migrate_resources_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1011,7 +1256,7 @@ async def test_batch_migrate_resources_field_headers_async(): # a field header. Set these to a non-empty value. request = migration_service.BatchMigrateResourcesRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1029,11 +1274,16 @@ async def test_batch_migrate_resources_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_batch_migrate_resources_flattened(): - client = MigrationServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1058,18 +1308,24 @@ def test_batch_migrate_resources_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].migrate_resource_requests == [ + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].migrate_resource_requests + mock_val = [ migration_service.MigrateResourceRequest( migrate_ml_engine_model_version_config=migration_service.MigrateResourceRequest.MigrateMlEngineModelVersionConfig( endpoint="endpoint_value" ) ) ] + assert arg == mock_val def test_batch_migrate_resources_flattened_error(): - client = MigrationServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1120,14 +1376,18 @@ async def test_batch_migrate_resources_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].migrate_resource_requests == [ + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].migrate_resource_requests + mock_val = [ migration_service.MigrateResourceRequest( migrate_ml_engine_model_version_config=migration_service.MigrateResourceRequest.MigrateMlEngineModelVersionConfig( endpoint="endpoint_value" ) ) ] + assert arg == mock_val @pytest.mark.asyncio @@ -1159,7 +1419,8 @@ def test_credentials_transport_error(): ) with pytest.raises(ValueError): client = MigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # It is an error to provide a credentials file and a transport instance. @@ -1172,13 +1433,34 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.MigrationServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = MigrationServiceClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = MigrationServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.MigrationServiceGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = MigrationServiceClient( - client_options={"scopes": ["1", "2"]}, transport=transport, + client_options={"scopes": ["1", "2"]}, + transport=transport, ) @@ -1221,10 +1503,28 @@ def test_transport_adc(transport_class): adc.assert_called_once() +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = MigrationServiceClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + def test_transport_grpc_default(): # A client should use the gRPC transport by default. - client = MigrationServiceClient(credentials=ga_credentials.AnonymousCredentials(),) - assert isinstance(client.transport, transports.MigrationServiceGrpcTransport,) + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.MigrationServiceGrpcTransport, + ) def test_migration_service_base_transport_error(): @@ -1251,18 +1551,38 @@ def test_migration_service_base_transport(): methods = ( "search_migratable_resources", "batch_migrate_resources", + "set_iam_policy", + "get_iam_policy", + "test_iam_permissions", + "get_location", + "list_locations", + "get_operation", + "wait_operation", + "cancel_operation", + "delete_operation", + "list_operations", ) for method in methods: with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + # Additionally, the LRO client (a property) should # also raise NotImplementedError with pytest.raises(NotImplementedError): transport.operations_client + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + -@requires_google_auth_gte_1_25_0 def test_migration_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -1273,7 +1593,8 @@ def test_migration_service_base_transport_with_credentials_file(): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MigrationServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", + credentials_file="credentials.json", + quota_project_id="octopus", ) load_creds.assert_called_once_with( "credentials.json", @@ -1283,26 +1604,6 @@ def test_migration_service_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_migration_service_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.aiplatform_v1.services.migration_service.transports.MigrationServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.MigrationServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - def test_migration_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( @@ -1314,7 +1615,6 @@ def test_migration_service_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_migration_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -1327,18 +1627,6 @@ def test_migration_service_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_migration_service_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - MigrationServiceClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -1346,7 +1634,6 @@ def test_migration_service_auth_adc_old_google_auth(): transports.MigrationServiceGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_migration_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -1361,34 +1648,13 @@ def test_migration_service_transport_auth_adc(transport_class): @pytest.mark.parametrize( - "transport_class", + "transport_class,grpc_helpers", [ - transports.MigrationServiceGrpcTransport, - transports.MigrationServiceGrpcAsyncIOTransport, + (transports.MigrationServiceGrpcTransport, grpc_helpers), + (transports.MigrationServiceGrpcAsyncIOTransport, grpc_helpers_async), ], ) -@requires_google_auth_lt_1_25_0 -def test_migration_service_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.MigrationServiceGrpcTransport, grpc_helpers), - (transports.MigrationServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_gte_1_26_0 -def test_migration_service_transport_create_channel(transport_class, grpc_helpers): +def test_migration_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object( @@ -1416,79 +1682,6 @@ def test_migration_service_transport_create_channel(transport_class, grpc_helper ) -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.MigrationServiceGrpcTransport, grpc_helpers), - (transports.MigrationServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_migration_service_transport_create_channel_old_api_core( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class(quota_project_id="octopus") - - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.MigrationServiceGrpcTransport, grpc_helpers), - (transports.MigrationServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_migration_service_transport_create_channel_user_scopes( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=["1", "2"], - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -1511,7 +1704,7 @@ def test_migration_service_grpc_transport_client_cert_source_for_mtls(transport_ "squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_channel_creds, quota_project_id=None, options=[ @@ -1534,24 +1727,40 @@ def test_migration_service_grpc_transport_client_cert_source_for_mtls(transport_ ) -def test_migration_service_host_no_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_migration_service_host_no_port(transport_name): client = MigrationServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="aiplatform.googleapis.com" ), + transport=transport_name, ) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") -def test_migration_service_host_with_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_migration_service_host_with_port(transport_name): client = MigrationServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="aiplatform.googleapis.com:8000" ), + transport=transport_name, ) - assert client.transport._host == "aiplatform.googleapis.com:8000" + assert client.transport._host == ("aiplatform.googleapis.com:8000") def test_migration_service_grpc_transport_channel(): @@ -1559,7 +1768,8 @@ def test_migration_service_grpc_transport_channel(): # Check that channel is used if provided. transport = transports.MigrationServiceGrpcTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -1571,7 +1781,8 @@ def test_migration_service_grpc_asyncio_transport_channel(): # Check that channel is used if provided. transport = transports.MigrationServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -1620,7 +1831,7 @@ def test_migration_service_transport_channel_mtls_with_client_cert_source( "mtls.squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -1667,7 +1878,7 @@ def test_migration_service_transport_channel_mtls_with_adc(transport_class): "mtls.squid.clam.whelk:443", credentials=mock_cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -1680,12 +1891,16 @@ def test_migration_service_transport_channel_mtls_with_adc(transport_class): def test_migration_service_grpc_lro_client(): client = MigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -1693,12 +1908,16 @@ def test_migration_service_grpc_lro_client(): def test_migration_service_grpc_lro_async_client(): client = MigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -1709,7 +1928,9 @@ def test_annotated_dataset_path(): dataset = "clam" annotated_dataset = "whelk" expected = "projects/{project}/datasets/{dataset}/annotatedDatasets/{annotated_dataset}".format( - project=project, dataset=dataset, annotated_dataset=annotated_dataset, + project=project, + dataset=dataset, + annotated_dataset=annotated_dataset, ) actual = MigrationServiceClient.annotated_dataset_path( project, dataset, annotated_dataset @@ -1734,7 +1955,8 @@ def test_dataset_path(): project = "cuttlefish" dataset = "mussel" expected = "projects/{project}/datasets/{dataset}".format( - project=project, dataset=dataset, + project=project, + dataset=dataset, ) actual = MigrationServiceClient.dataset_path(project, dataset) assert expected == actual @@ -1757,7 +1979,9 @@ def test_dataset_path(): location = "abalone" dataset = "squid" expected = "projects/{project}/locations/{location}/datasets/{dataset}".format( - project=project, location=location, dataset=dataset, + project=project, + location=location, + dataset=dataset, ) actual = MigrationServiceClient.dataset_path(project, location, dataset) assert expected == actual @@ -1781,7 +2005,9 @@ def test_dataset_path(): location = "nudibranch" dataset = "cuttlefish" expected = "projects/{project}/locations/{location}/datasets/{dataset}".format( - project=project, location=location, dataset=dataset, + project=project, + location=location, + dataset=dataset, ) actual = MigrationServiceClient.dataset_path(project, location, dataset) assert expected == actual @@ -1805,7 +2031,9 @@ def test_model_path(): location = "abalone" model = "squid" expected = "projects/{project}/locations/{location}/models/{model}".format( - project=project, location=location, model=model, + project=project, + location=location, + model=model, ) actual = MigrationServiceClient.model_path(project, location, model) assert expected == actual @@ -1829,7 +2057,9 @@ def test_model_path(): location = "nudibranch" model = "cuttlefish" expected = "projects/{project}/locations/{location}/models/{model}".format( - project=project, location=location, model=model, + project=project, + location=location, + model=model, ) actual = MigrationServiceClient.model_path(project, location, model) assert expected == actual @@ -1853,7 +2083,9 @@ def test_version_path(): model = "abalone" version = "squid" expected = "projects/{project}/models/{model}/versions/{version}".format( - project=project, model=model, version=version, + project=project, + model=model, + version=version, ) actual = MigrationServiceClient.version_path(project, model, version) assert expected == actual @@ -1894,7 +2126,9 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "cuttlefish" - expected = "folders/{folder}".format(folder=folder,) + expected = "folders/{folder}".format( + folder=folder, + ) actual = MigrationServiceClient.common_folder_path(folder) assert expected == actual @@ -1912,7 +2146,9 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "winkle" - expected = "organizations/{organization}".format(organization=organization,) + expected = "organizations/{organization}".format( + organization=organization, + ) actual = MigrationServiceClient.common_organization_path(organization) assert expected == actual @@ -1930,7 +2166,9 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "scallop" - expected = "projects/{project}".format(project=project,) + expected = "projects/{project}".format( + project=project, + ) actual = MigrationServiceClient.common_project_path(project) assert expected == actual @@ -1950,7 +2188,8 @@ def test_common_location_path(): project = "squid" location = "clam" expected = "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) actual = MigrationServiceClient.common_location_path(project, location) assert expected == actual @@ -1968,14 +2207,15 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( transports.MigrationServiceTransport, "_prep_wrapped_messages" ) as prep: client = MigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -1984,6 +2224,1593 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = MigrationServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_delete_operation(transport: str = "grpc"): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_operation(transport: str = "grpc"): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_operation_field_headers(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = None + + client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_operation_field_headers_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_delete_operation_from_dict(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_delete_operation_from_dict_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_cancel_operation(transport: str = "grpc"): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation(transport: str = "grpc"): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_wait_operation(transport: str = "grpc"): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_wait_operation(transport: str = "grpc"): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_wait_operation_field_headers(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_wait_operation_field_headers_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_wait_operation_from_dict(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_wait_operation_from_dict_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_operation(transport: str = "grpc"): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_get_operation(transport: str = "grpc"): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_get_operation_field_headers(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_get_operation_from_dict(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_operations(transport: str = "grpc"): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + response = client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +@pytest.mark.asyncio +async def test_list_operations(transport: str = "grpc"): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +def test_list_operations_field_headers(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_operations_field_headers_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_operations_from_dict(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + response = client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_operations_from_dict_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_locations(transport: str = "grpc"): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + response = client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +@pytest.mark.asyncio +async def test_list_locations(transport: str = "grpc"): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +def test_list_locations_field_headers(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_locations_field_headers_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_locations_from_dict(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + response = client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_locations_from_dict_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_location(transport: str = "grpc"): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + response = client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +@pytest.mark.asyncio +async def test_get_location_async(transport: str = "grpc_asyncio"): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +def test_get_location_field_headers(): + client = MigrationServiceClient(credentials=ga_credentials.AnonymousCredentials()) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = locations_pb2.Location() + + client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_location_field_headers_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials() + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +def test_get_location_from_dict(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + response = client.get_location( + request={ + "name": "locations/abc", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_location_from_dict_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_set_iam_policy(transport: str = "grpc"): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + response = client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + response = await client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_set_iam_policy_field_headers(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_set_iam_policy_field_headers_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_set_iam_policy_from_dict(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_set_iam_policy_from_dict_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +def test_get_iam_policy(transport: str = "grpc"): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + + response = client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + + response = await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_get_iam_policy_field_headers(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_iam_policy_field_headers_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_get_iam_policy_from_dict(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_iam_policy_from_dict_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +def test_test_iam_permissions(transport: str = "grpc"): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + + response = client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + ) + + response = await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +def test_test_iam_permissions_field_headers(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_field_headers_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_test_iam_permissions_from_dict(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + response = client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_from_dict_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + response = await client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (MigrationServiceClient, transports.MigrationServiceGrpcTransport), + (MigrationServiceAsyncClient, transports.MigrationServiceGrpcAsyncIOTransport), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) diff --git a/tests/unit/gapic/aiplatform_v1/test_model_service.py b/tests/unit/gapic/aiplatform_v1/test_model_service.py index bfc0d94a16..a7ade0df96 100644 --- a/tests/unit/gapic/aiplatform_v1/test_model_service.py +++ b/tests/unit/gapic/aiplatform_v1/test_model_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,8 +14,13 @@ # limitations under the License. # import os -import mock -import packaging.version + +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock +except ImportError: + import mock import grpc from grpc.experimental import aio @@ -30,30 +35,33 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.aiplatform_v1.services.model_service import ModelServiceAsyncClient from google.cloud.aiplatform_v1.services.model_service import ModelServiceClient from google.cloud.aiplatform_v1.services.model_service import pagers from google.cloud.aiplatform_v1.services.model_service import transports -from google.cloud.aiplatform_v1.services.model_service.transports.base import ( - _API_CORE_VERSION, -) -from google.cloud.aiplatform_v1.services.model_service.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.aiplatform_v1.types import deployed_model_ref from google.cloud.aiplatform_v1.types import encryption_spec from google.cloud.aiplatform_v1.types import env_var +from google.cloud.aiplatform_v1.types import explanation +from google.cloud.aiplatform_v1.types import explanation_metadata from google.cloud.aiplatform_v1.types import io from google.cloud.aiplatform_v1.types import model from google.cloud.aiplatform_v1.types import model as gca_model from google.cloud.aiplatform_v1.types import model_evaluation +from google.cloud.aiplatform_v1.types import model_evaluation as gca_model_evaluation from google.cloud.aiplatform_v1.types import model_evaluation_slice from google.cloud.aiplatform_v1.types import model_service from google.cloud.aiplatform_v1.types import operation as gca_operation +from google.cloud.location import locations_pb2 +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 from google.oauth2 import service_account from google.protobuf import field_mask_pb2 # type: ignore @@ -62,29 +70,6 @@ import google.auth -# TODO(busunkim): Once google-api-core >= 1.26.0 is required: -# - Delete all the api-core and auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - -requires_api_core_lt_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), - reason="This test requires google-api-core < 1.26.0", -) - -requires_api_core_gte_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), - reason="This test requires google-api-core >= 1.26.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -126,37 +111,78 @@ def test__get_default_mtls_endpoint(): assert ModelServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi -@pytest.mark.parametrize("client_class", [ModelServiceClient, ModelServiceAsyncClient,]) -def test_model_service_client_from_service_account_info(client_class): +@pytest.mark.parametrize( + "client_class,transport_name", + [ + (ModelServiceClient, "grpc"), + (ModelServiceAsyncClient, "grpc_asyncio"), + ], +) +def test_model_service_client_from_service_account_info(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") + +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.ModelServiceGrpcTransport, "grpc"), + (transports.ModelServiceGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_model_service_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() -@pytest.mark.parametrize("client_class", [ModelServiceClient, ModelServiceAsyncClient,]) -def test_model_service_client_from_service_account_file(client_class): + +@pytest.mark.parametrize( + "client_class,transport_name", + [ + (ModelServiceClient, "grpc"), + (ModelServiceAsyncClient, "grpc_asyncio"), + ], +) +def test_model_service_client_from_service_account_file(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") def test_model_service_client_get_transport_class(): @@ -207,7 +233,7 @@ def test_model_service_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -216,6 +242,7 @@ def test_model_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -223,7 +250,7 @@ def test_model_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -232,6 +259,7 @@ def test_model_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -239,7 +267,7 @@ def test_model_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -248,26 +276,27 @@ def test_model_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -276,6 +305,7 @@ def test_model_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -323,7 +353,7 @@ def test_model_service_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -340,6 +370,7 @@ def test_model_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case ADC client cert is provided. Whether client cert is used depends on @@ -364,7 +395,7 @@ def test_model_service_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -373,6 +404,7 @@ def test_model_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case client_cert_source and ADC client cert are not provided. @@ -385,7 +417,7 @@ def test_model_service_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -394,9 +426,87 @@ def test_model_service_client_mtls_env_auto( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) +@pytest.mark.parametrize("client_class", [ModelServiceClient, ModelServiceAsyncClient]) +@mock.patch.object( + ModelServiceClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ModelServiceClient) +) +@mock.patch.object( + ModelServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(ModelServiceAsyncClient), +) +def test_model_service_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + @pytest.mark.parametrize( "client_class,transport_class,transport_name", [ @@ -412,10 +522,12 @@ def test_model_service_client_client_options_scopes( client_class, transport_class, transport_name ): # Check the case scopes are provided. - options = client_options.ClientOptions(scopes=["1", "2"],) + options = client_options.ClientOptions( + scopes=["1", "2"], + ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -424,28 +536,36 @@ def test_model_service_client_client_options_scopes( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (ModelServiceClient, transports.ModelServiceGrpcTransport, "grpc"), + ( + ModelServiceClient, + transports.ModelServiceGrpcTransport, + "grpc", + grpc_helpers, + ), ( ModelServiceAsyncClient, transports.ModelServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_model_service_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -454,6 +574,7 @@ def test_model_service_client_client_options_credentials_file( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -471,14 +592,87 @@ def test_model_service_client_client_options_from_dict(): client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) -def test_upload_model( - transport: str = "grpc", request_type=model_service.UploadModelRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + ModelServiceClient, + transports.ModelServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + ModelServiceAsyncClient, + transports.ModelServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_model_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers ): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + model_service.UploadModelRequest, + dict, + ], +) +def test_upload_model(request_type, transport: str = "grpc"): client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -500,15 +694,12 @@ def test_upload_model( assert isinstance(response, future.Future) -def test_upload_model_from_dict(): - test_upload_model(request_type=dict) - - def test_upload_model_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -524,7 +715,8 @@ async def test_upload_model_async( transport: str = "grpc_asyncio", request_type=model_service.UploadModelRequest ): client = ModelServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -554,13 +746,15 @@ async def test_upload_model_async_from_dict(): def test_upload_model_field_headers(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = model_service.UploadModelRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.upload_model), "__call__") as call: @@ -574,18 +768,23 @@ def test_upload_model_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_upload_model_field_headers_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = model_service.UploadModelRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.upload_model), "__call__") as call: @@ -601,11 +800,16 @@ async def test_upload_model_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_upload_model_flattened(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.upload_model), "__call__") as call: @@ -614,19 +818,26 @@ def test_upload_model_flattened(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.upload_model( - parent="parent_value", model=gca_model.Model(name="name_value"), + parent="parent_value", + model=gca_model.Model(name="name_value"), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].model == gca_model.Model(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].model + mock_val = gca_model.Model(name="name_value") + assert arg == mock_val def test_upload_model_flattened_error(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -640,7 +851,9 @@ def test_upload_model_flattened_error(): @pytest.mark.asyncio async def test_upload_model_flattened_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.upload_model), "__call__") as call: @@ -653,20 +866,27 @@ async def test_upload_model_flattened_async(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. response = await client.upload_model( - parent="parent_value", model=gca_model.Model(name="name_value"), + parent="parent_value", + model=gca_model.Model(name="name_value"), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].model == gca_model.Model(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].model + mock_val = gca_model.Model(name="name_value") + assert arg == mock_val @pytest.mark.asyncio async def test_upload_model_flattened_error_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -678,9 +898,17 @@ async def test_upload_model_flattened_error_async(): ) -def test_get_model(transport: str = "grpc", request_type=model_service.GetModelRequest): +@pytest.mark.parametrize( + "request_type", + [ + model_service.GetModelRequest, + dict, + ], +) +def test_get_model(request_type, transport: str = "grpc"): client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -692,8 +920,11 @@ def test_get_model(transport: str = "grpc", request_type=model_service.GetModelR # Designate an appropriate return value for the call. call.return_value = model.Model( name="name_value", + version_id="version_id_value", + version_aliases=["version_aliases_value"], display_name="display_name_value", description="description_value", + version_description="version_description_value", metadata_schema_uri="metadata_schema_uri_value", training_pipeline="training_pipeline_value", artifact_uri="artifact_uri_value", @@ -714,8 +945,11 @@ def test_get_model(transport: str = "grpc", request_type=model_service.GetModelR # Establish that the response is the type that we expect. assert isinstance(response, model.Model) assert response.name == "name_value" + assert response.version_id == "version_id_value" + assert response.version_aliases == ["version_aliases_value"] assert response.display_name == "display_name_value" assert response.description == "description_value" + assert response.version_description == "version_description_value" assert response.metadata_schema_uri == "metadata_schema_uri_value" assert response.training_pipeline == "training_pipeline_value" assert response.artifact_uri == "artifact_uri_value" @@ -731,15 +965,12 @@ def test_get_model(transport: str = "grpc", request_type=model_service.GetModelR assert response.etag == "etag_value" -def test_get_model_from_dict(): - test_get_model(request_type=dict) - - def test_get_model_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -755,7 +986,8 @@ async def test_get_model_async( transport: str = "grpc_asyncio", request_type=model_service.GetModelRequest ): client = ModelServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -768,8 +1000,11 @@ async def test_get_model_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( model.Model( name="name_value", + version_id="version_id_value", + version_aliases=["version_aliases_value"], display_name="display_name_value", description="description_value", + version_description="version_description_value", metadata_schema_uri="metadata_schema_uri_value", training_pipeline="training_pipeline_value", artifact_uri="artifact_uri_value", @@ -795,8 +1030,11 @@ async def test_get_model_async( # Establish that the response is the type that we expect. assert isinstance(response, model.Model) assert response.name == "name_value" + assert response.version_id == "version_id_value" + assert response.version_aliases == ["version_aliases_value"] assert response.display_name == "display_name_value" assert response.description == "description_value" + assert response.version_description == "version_description_value" assert response.metadata_schema_uri == "metadata_schema_uri_value" assert response.training_pipeline == "training_pipeline_value" assert response.artifact_uri == "artifact_uri_value" @@ -818,13 +1056,15 @@ async def test_get_model_async_from_dict(): def test_get_model_field_headers(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = model_service.GetModelRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_model), "__call__") as call: @@ -838,18 +1078,23 @@ def test_get_model_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_get_model_field_headers_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = model_service.GetModelRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_model), "__call__") as call: @@ -863,11 +1108,16 @@ async def test_get_model_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_get_model_flattened(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_model), "__call__") as call: @@ -875,29 +1125,38 @@ def test_get_model_flattened(): call.return_value = model.Model() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_model(name="name_value",) + client.get_model( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_model_flattened_error(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.get_model( - model_service.GetModelRequest(), name="name_value", + model_service.GetModelRequest(), + name="name_value", ) @pytest.mark.asyncio async def test_get_model_flattened_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_model), "__call__") as call: @@ -907,32 +1166,45 @@ async def test_get_model_flattened_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(model.Model()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_model(name="name_value",) + response = await client.get_model( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio async def test_get_model_flattened_error_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.get_model( - model_service.GetModelRequest(), name="name_value", + model_service.GetModelRequest(), + name="name_value", ) -def test_list_models( - transport: str = "grpc", request_type=model_service.ListModelsRequest -): +@pytest.mark.parametrize( + "request_type", + [ + model_service.ListModelsRequest, + dict, + ], +) +def test_list_models(request_type, transport: str = "grpc"): client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -957,15 +1229,12 @@ def test_list_models( assert response.next_page_token == "next_page_token_value" -def test_list_models_from_dict(): - test_list_models(request_type=dict) - - def test_list_models_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -981,7 +1250,8 @@ async def test_list_models_async( transport: str = "grpc_asyncio", request_type=model_service.ListModelsRequest ): client = ModelServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -992,7 +1262,9 @@ async def test_list_models_async( with mock.patch.object(type(client.transport.list_models), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - model_service.ListModelsResponse(next_page_token="next_page_token_value",) + model_service.ListModelsResponse( + next_page_token="next_page_token_value", + ) ) response = await client.list_models(request) @@ -1012,13 +1284,15 @@ async def test_list_models_async_from_dict(): def test_list_models_field_headers(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = model_service.ListModelsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_models), "__call__") as call: @@ -1032,18 +1306,23 @@ def test_list_models_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_list_models_field_headers_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = model_service.ListModelsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_models), "__call__") as call: @@ -1059,11 +1338,16 @@ async def test_list_models_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_models_flattened(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_models), "__call__") as call: @@ -1071,29 +1355,38 @@ def test_list_models_flattened(): call.return_value = model_service.ListModelsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_models(parent="parent_value",) + client.list_models( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_models_flattened_error(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.list_models( - model_service.ListModelsRequest(), parent="parent_value", + model_service.ListModelsRequest(), + parent="parent_value", ) @pytest.mark.asyncio async def test_list_models_flattened_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_models), "__call__") as call: @@ -1105,43 +1398,68 @@ async def test_list_models_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_models(parent="parent_value",) + response = await client.list_models( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio async def test_list_models_flattened_error_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.list_models( - model_service.ListModelsRequest(), parent="parent_value", + model_service.ListModelsRequest(), + parent="parent_value", ) -def test_list_models_pager(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_models_pager(transport_name: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_models), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( model_service.ListModelsResponse( - models=[model.Model(), model.Model(), model.Model(),], + models=[ + model.Model(), + model.Model(), + model.Model(), + ], next_page_token="abc", ), - model_service.ListModelsResponse(models=[], next_page_token="def",), model_service.ListModelsResponse( - models=[model.Model(),], next_page_token="ghi", + models=[], + next_page_token="def", + ), + model_service.ListModelsResponse( + models=[ + model.Model(), + ], + next_page_token="ghi", + ), + model_service.ListModelsResponse( + models=[ + model.Model(), + model.Model(), + ], ), - model_service.ListModelsResponse(models=[model.Model(), model.Model(),],), RuntimeError, ) @@ -1153,27 +1471,45 @@ def test_list_models_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all(isinstance(i, model.Model) for i in results) -def test_list_models_pages(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_models_pages(transport_name: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_models), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( model_service.ListModelsResponse( - models=[model.Model(), model.Model(), model.Model(),], + models=[ + model.Model(), + model.Model(), + model.Model(), + ], next_page_token="abc", ), - model_service.ListModelsResponse(models=[], next_page_token="def",), model_service.ListModelsResponse( - models=[model.Model(),], next_page_token="ghi", + models=[], + next_page_token="def", + ), + model_service.ListModelsResponse( + models=[ + model.Model(), + ], + next_page_token="ghi", + ), + model_service.ListModelsResponse( + models=[ + model.Model(), + model.Model(), + ], ), - model_service.ListModelsResponse(models=[model.Model(), model.Model(),],), RuntimeError, ) pages = list(client.list_models(request={}).pages) @@ -1183,7 +1519,9 @@ def test_list_models_pages(): @pytest.mark.asyncio async def test_list_models_async_pager(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1192,20 +1530,37 @@ async def test_list_models_async_pager(): # Set the response to a series of pages. call.side_effect = ( model_service.ListModelsResponse( - models=[model.Model(), model.Model(), model.Model(),], + models=[ + model.Model(), + model.Model(), + model.Model(), + ], next_page_token="abc", ), - model_service.ListModelsResponse(models=[], next_page_token="def",), model_service.ListModelsResponse( - models=[model.Model(),], next_page_token="ghi", + models=[], + next_page_token="def", + ), + model_service.ListModelsResponse( + models=[ + model.Model(), + ], + next_page_token="ghi", + ), + model_service.ListModelsResponse( + models=[ + model.Model(), + model.Model(), + ], ), - model_service.ListModelsResponse(models=[model.Model(), model.Model(),],), RuntimeError, ) - async_pager = await client.list_models(request={},) + async_pager = await client.list_models( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -1214,7 +1569,9 @@ async def test_list_models_async_pager(): @pytest.mark.asyncio async def test_list_models_async_pages(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1223,28 +1580,51 @@ async def test_list_models_async_pages(): # Set the response to a series of pages. call.side_effect = ( model_service.ListModelsResponse( - models=[model.Model(), model.Model(), model.Model(),], + models=[ + model.Model(), + model.Model(), + model.Model(), + ], next_page_token="abc", ), - model_service.ListModelsResponse(models=[], next_page_token="def",), model_service.ListModelsResponse( - models=[model.Model(),], next_page_token="ghi", + models=[], + next_page_token="def", ), - model_service.ListModelsResponse(models=[model.Model(), model.Model(),],), - RuntimeError, - ) + model_service.ListModelsResponse( + models=[ + model.Model(), + ], + next_page_token="ghi", + ), + model_service.ListModelsResponse( + models=[ + model.Model(), + model.Model(), + ], + ), + RuntimeError, + ) pages = [] - async for page_ in (await client.list_models(request={})).pages: + async for page_ in ( + await client.list_models(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_update_model( - transport: str = "grpc", request_type=model_service.UpdateModelRequest -): +@pytest.mark.parametrize( + "request_type", + [ + model_service.ListModelVersionsRequest, + dict, + ], +) +def test_list_model_versions(request_type, transport: str = "grpc"): client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1252,74 +1632,50 @@ def test_update_model( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_model), "__call__") as call: + with mock.patch.object( + type(client.transport.list_model_versions), "__call__" + ) as call: # Designate an appropriate return value for the call. - call.return_value = gca_model.Model( - name="name_value", - display_name="display_name_value", - description="description_value", - metadata_schema_uri="metadata_schema_uri_value", - training_pipeline="training_pipeline_value", - artifact_uri="artifact_uri_value", - supported_deployment_resources_types=[ - gca_model.Model.DeploymentResourcesType.DEDICATED_RESOURCES - ], - supported_input_storage_formats=["supported_input_storage_formats_value"], - supported_output_storage_formats=["supported_output_storage_formats_value"], - etag="etag_value", + call.return_value = model_service.ListModelVersionsResponse( + next_page_token="next_page_token_value", ) - response = client.update_model(request) + response = client.list_model_versions(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == model_service.UpdateModelRequest() + assert args[0] == model_service.ListModelVersionsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gca_model.Model) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.description == "description_value" - assert response.metadata_schema_uri == "metadata_schema_uri_value" - assert response.training_pipeline == "training_pipeline_value" - assert response.artifact_uri == "artifact_uri_value" - assert response.supported_deployment_resources_types == [ - gca_model.Model.DeploymentResourcesType.DEDICATED_RESOURCES - ] - assert response.supported_input_storage_formats == [ - "supported_input_storage_formats_value" - ] - assert response.supported_output_storage_formats == [ - "supported_output_storage_formats_value" - ] - assert response.etag == "etag_value" - - -def test_update_model_from_dict(): - test_update_model(request_type=dict) + assert isinstance(response, pagers.ListModelVersionsPager) + assert response.next_page_token == "next_page_token_value" -def test_update_model_empty_call(): +def test_list_model_versions_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_model), "__call__") as call: - client.update_model() + with mock.patch.object( + type(client.transport.list_model_versions), "__call__" + ) as call: + client.list_model_versions() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == model_service.UpdateModelRequest() + assert args[0] == model_service.ListModelVersionsRequest() @pytest.mark.asyncio -async def test_update_model_async( - transport: str = "grpc_asyncio", request_type=model_service.UpdateModelRequest +async def test_list_model_versions_async( + transport: str = "grpc_asyncio", request_type=model_service.ListModelVersionsRequest ): client = ModelServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1327,73 +1683,49 @@ async def test_update_model_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_model), "__call__") as call: + with mock.patch.object( + type(client.transport.list_model_versions), "__call__" + ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gca_model.Model( - name="name_value", - display_name="display_name_value", - description="description_value", - metadata_schema_uri="metadata_schema_uri_value", - training_pipeline="training_pipeline_value", - artifact_uri="artifact_uri_value", - supported_deployment_resources_types=[ - gca_model.Model.DeploymentResourcesType.DEDICATED_RESOURCES - ], - supported_input_storage_formats=[ - "supported_input_storage_formats_value" - ], - supported_output_storage_formats=[ - "supported_output_storage_formats_value" - ], - etag="etag_value", + model_service.ListModelVersionsResponse( + next_page_token="next_page_token_value", ) ) - response = await client.update_model(request) + response = await client.list_model_versions(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == model_service.UpdateModelRequest() + assert args[0] == model_service.ListModelVersionsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gca_model.Model) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.description == "description_value" - assert response.metadata_schema_uri == "metadata_schema_uri_value" - assert response.training_pipeline == "training_pipeline_value" - assert response.artifact_uri == "artifact_uri_value" - assert response.supported_deployment_resources_types == [ - gca_model.Model.DeploymentResourcesType.DEDICATED_RESOURCES - ] - assert response.supported_input_storage_formats == [ - "supported_input_storage_formats_value" - ] - assert response.supported_output_storage_formats == [ - "supported_output_storage_formats_value" - ] - assert response.etag == "etag_value" + assert isinstance(response, pagers.ListModelVersionsAsyncPager) + assert response.next_page_token == "next_page_token_value" @pytest.mark.asyncio -async def test_update_model_async_from_dict(): - await test_update_model_async(request_type=dict) +async def test_list_model_versions_async_from_dict(): + await test_list_model_versions_async(request_type=dict) -def test_update_model_field_headers(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_list_model_versions_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = model_service.UpdateModelRequest() + request = model_service.ListModelVersionsRequest() - request.model.name = "model.name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_model), "__call__") as call: - call.return_value = gca_model.Model() - client.update_model(request) + with mock.patch.object( + type(client.transport.list_model_versions), "__call__" + ) as call: + call.return_value = model_service.ListModelVersionsResponse() + client.list_model_versions(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -1402,23 +1734,32 @@ def test_update_model_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "model.name=model.name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_update_model_field_headers_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_list_model_versions_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = model_service.UpdateModelRequest() + request = model_service.ListModelVersionsRequest() - request.model.name = "model.name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_model), "__call__") as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gca_model.Model()) - await client.update_model(request) + with mock.patch.object( + type(client.transport.list_model_versions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + model_service.ListModelVersionsResponse() + ) + await client.list_model_versions(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -1427,175 +1768,466 @@ async def test_update_model_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "model.name=model.name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] -def test_update_model_flattened(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_list_model_versions_flattened(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_model), "__call__") as call: + with mock.patch.object( + type(client.transport.list_model_versions), "__call__" + ) as call: # Designate an appropriate return value for the call. - call.return_value = gca_model.Model() + call.return_value = model_service.ListModelVersionsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.update_model( - model=gca_model.Model(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + client.list_model_versions( + name="name_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].model == gca_model.Model(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val -def test_update_model_flattened_error(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_list_model_versions_flattened_error(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.update_model( - model_service.UpdateModelRequest(), - model=gca_model.Model(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + client.list_model_versions( + model_service.ListModelVersionsRequest(), + name="name_value", ) @pytest.mark.asyncio -async def test_update_model_flattened_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_list_model_versions_flattened_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_model), "__call__") as call: + with mock.patch.object( + type(client.transport.list_model_versions), "__call__" + ) as call: # Designate an appropriate return value for the call. - call.return_value = gca_model.Model() + call.return_value = model_service.ListModelVersionsResponse() - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gca_model.Model()) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + model_service.ListModelVersionsResponse() + ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.update_model( - model=gca_model.Model(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + response = await client.list_model_versions( + name="name_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].model == gca_model.Model(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio -async def test_update_model_flattened_error_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_list_model_versions_flattened_error_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.update_model( - model_service.UpdateModelRequest(), - model=gca_model.Model(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + await client.list_model_versions( + model_service.ListModelVersionsRequest(), + name="name_value", ) -def test_delete_model( - transport: str = "grpc", request_type=model_service.DeleteModelRequest -): +def test_list_model_versions_pager(transport_name: str = "grpc"): client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_model), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.delete_model(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == model_service.DeleteModelRequest() + with mock.patch.object( + type(client.transport.list_model_versions), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + model_service.ListModelVersionsResponse( + models=[ + model.Model(), + model.Model(), + model.Model(), + ], + next_page_token="abc", + ), + model_service.ListModelVersionsResponse( + models=[], + next_page_token="def", + ), + model_service.ListModelVersionsResponse( + models=[ + model.Model(), + ], + next_page_token="ghi", + ), + model_service.ListModelVersionsResponse( + models=[ + model.Model(), + model.Model(), + ], + ), + RuntimeError, + ) - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", ""),)), + ) + pager = client.list_model_versions(request={}) + assert pager._metadata == metadata -def test_delete_model_from_dict(): - test_delete_model(request_type=dict) + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, model.Model) for i in results) -def test_delete_model_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. +def test_list_model_versions_pages(transport_name: str = "grpc"): client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_model), "__call__") as call: - client.delete_model() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == model_service.DeleteModelRequest() + with mock.patch.object( + type(client.transport.list_model_versions), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + model_service.ListModelVersionsResponse( + models=[ + model.Model(), + model.Model(), + model.Model(), + ], + next_page_token="abc", + ), + model_service.ListModelVersionsResponse( + models=[], + next_page_token="def", + ), + model_service.ListModelVersionsResponse( + models=[ + model.Model(), + ], + next_page_token="ghi", + ), + model_service.ListModelVersionsResponse( + models=[ + model.Model(), + model.Model(), + ], + ), + RuntimeError, + ) + pages = list(client.list_model_versions(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token @pytest.mark.asyncio -async def test_delete_model_async( - transport: str = "grpc_asyncio", request_type=model_service.DeleteModelRequest -): +async def test_list_model_versions_async_pager(): client = ModelServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials, ) - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_model), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") - ) - response = await client.delete_model(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == model_service.DeleteModelRequest() + with mock.patch.object( + type(client.transport.list_model_versions), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + model_service.ListModelVersionsResponse( + models=[ + model.Model(), + model.Model(), + model.Model(), + ], + next_page_token="abc", + ), + model_service.ListModelVersionsResponse( + models=[], + next_page_token="def", + ), + model_service.ListModelVersionsResponse( + models=[ + model.Model(), + ], + next_page_token="ghi", + ), + model_service.ListModelVersionsResponse( + models=[ + model.Model(), + model.Model(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_model_versions( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, model.Model) for i in responses) + + +@pytest.mark.asyncio +async def test_list_model_versions_async_pages(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_versions), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + model_service.ListModelVersionsResponse( + models=[ + model.Model(), + model.Model(), + model.Model(), + ], + next_page_token="abc", + ), + model_service.ListModelVersionsResponse( + models=[], + next_page_token="def", + ), + model_service.ListModelVersionsResponse( + models=[ + model.Model(), + ], + next_page_token="ghi", + ), + model_service.ListModelVersionsResponse( + models=[ + model.Model(), + model.Model(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.list_model_versions(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize( + "request_type", + [ + model_service.UpdateModelRequest, + dict, + ], +) +def test_update_model(request_type, transport: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_model), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = gca_model.Model( + name="name_value", + version_id="version_id_value", + version_aliases=["version_aliases_value"], + display_name="display_name_value", + description="description_value", + version_description="version_description_value", + metadata_schema_uri="metadata_schema_uri_value", + training_pipeline="training_pipeline_value", + artifact_uri="artifact_uri_value", + supported_deployment_resources_types=[ + gca_model.Model.DeploymentResourcesType.DEDICATED_RESOURCES + ], + supported_input_storage_formats=["supported_input_storage_formats_value"], + supported_output_storage_formats=["supported_output_storage_formats_value"], + etag="etag_value", + ) + response = client.update_model(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.UpdateModelRequest() # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) + assert isinstance(response, gca_model.Model) + assert response.name == "name_value" + assert response.version_id == "version_id_value" + assert response.version_aliases == ["version_aliases_value"] + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.version_description == "version_description_value" + assert response.metadata_schema_uri == "metadata_schema_uri_value" + assert response.training_pipeline == "training_pipeline_value" + assert response.artifact_uri == "artifact_uri_value" + assert response.supported_deployment_resources_types == [ + gca_model.Model.DeploymentResourcesType.DEDICATED_RESOURCES + ] + assert response.supported_input_storage_formats == [ + "supported_input_storage_formats_value" + ] + assert response.supported_output_storage_formats == [ + "supported_output_storage_formats_value" + ] + assert response.etag == "etag_value" + + +def test_update_model_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_model), "__call__") as call: + client.update_model() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.UpdateModelRequest() @pytest.mark.asyncio -async def test_delete_model_async_from_dict(): - await test_delete_model_async(request_type=dict) +async def test_update_model_async( + transport: str = "grpc_asyncio", request_type=model_service.UpdateModelRequest +): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() -def test_delete_model_field_headers(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_model), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_model.Model( + name="name_value", + version_id="version_id_value", + version_aliases=["version_aliases_value"], + display_name="display_name_value", + description="description_value", + version_description="version_description_value", + metadata_schema_uri="metadata_schema_uri_value", + training_pipeline="training_pipeline_value", + artifact_uri="artifact_uri_value", + supported_deployment_resources_types=[ + gca_model.Model.DeploymentResourcesType.DEDICATED_RESOURCES + ], + supported_input_storage_formats=[ + "supported_input_storage_formats_value" + ], + supported_output_storage_formats=[ + "supported_output_storage_formats_value" + ], + etag="etag_value", + ) + ) + response = await client.update_model(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.UpdateModelRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_model.Model) + assert response.name == "name_value" + assert response.version_id == "version_id_value" + assert response.version_aliases == ["version_aliases_value"] + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.version_description == "version_description_value" + assert response.metadata_schema_uri == "metadata_schema_uri_value" + assert response.training_pipeline == "training_pipeline_value" + assert response.artifact_uri == "artifact_uri_value" + assert response.supported_deployment_resources_types == [ + gca_model.Model.DeploymentResourcesType.DEDICATED_RESOURCES + ] + assert response.supported_input_storage_formats == [ + "supported_input_storage_formats_value" + ] + assert response.supported_output_storage_formats == [ + "supported_output_storage_formats_value" + ] + assert response.etag == "etag_value" + + +@pytest.mark.asyncio +async def test_update_model_async_from_dict(): + await test_update_model_async(request_type=dict) + + +def test_update_model_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = model_service.DeleteModelRequest() + request = model_service.UpdateModelRequest() - request.name = "name/value" + request.model.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_model), "__call__") as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_model(request) + with mock.patch.object(type(client.transport.update_model), "__call__") as call: + call.return_value = gca_model.Model() + client.update_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -1604,25 +2236,28 @@ def test_delete_model_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "model.name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_delete_model_field_headers_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_update_model_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = model_service.DeleteModelRequest() + request = model_service.UpdateModelRequest() - request.name = "name/value" + request.model.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_model), "__call__") as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/op") - ) - await client.delete_model(request) + with mock.patch.object(type(client.transport.update_model), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gca_model.Model()) + await client.update_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -1631,78 +2266,113 @@ async def test_delete_model_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "model.name=name_value", + ) in kw["metadata"] -def test_delete_model_flattened(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_update_model_flattened(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_model), "__call__") as call: + with mock.patch.object(type(client.transport.update_model), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name="operations/op") + call.return_value = gca_model.Model() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_model(name="name_value",) + client.update_model( + model=gca_model.Model(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].model + mock_val = gca_model.Model(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val -def test_delete_model_flattened_error(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_update_model_flattened_error(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.delete_model( - model_service.DeleteModelRequest(), name="name_value", + client.update_model( + model_service.UpdateModelRequest(), + model=gca_model.Model(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @pytest.mark.asyncio -async def test_delete_model_flattened_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_update_model_flattened_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_model), "__call__") as call: + with mock.patch.object(type(client.transport.update_model), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name="operations/op") + call.return_value = gca_model.Model() - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") - ) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gca_model.Model()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_model(name="name_value",) + response = await client.update_model( + model=gca_model.Model(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].model + mock_val = gca_model.Model(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val @pytest.mark.asyncio -async def test_delete_model_flattened_error_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_update_model_flattened_error_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.delete_model( - model_service.DeleteModelRequest(), name="name_value", + await client.update_model( + model_service.UpdateModelRequest(), + model=gca_model.Model(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) -def test_export_model( - transport: str = "grpc", request_type=model_service.ExportModelRequest -): +@pytest.mark.parametrize( + "request_type", + [ + model_service.DeleteModelRequest, + dict, + ], +) +def test_delete_model(request_type, transport: str = "grpc"): client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1710,45 +2380,43 @@ def test_export_model( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.export_model), "__call__") as call: + with mock.patch.object(type(client.transport.delete_model), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.export_model(request) + response = client.delete_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == model_service.ExportModelRequest() + assert args[0] == model_service.DeleteModelRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) -def test_export_model_from_dict(): - test_export_model(request_type=dict) - - -def test_export_model_empty_call(): +def test_delete_model_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.export_model), "__call__") as call: - client.export_model() + with mock.patch.object(type(client.transport.delete_model), "__call__") as call: + client.delete_model() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == model_service.ExportModelRequest() + assert args[0] == model_service.DeleteModelRequest() @pytest.mark.asyncio -async def test_export_model_async( - transport: str = "grpc_asyncio", request_type=model_service.ExportModelRequest +async def test_delete_model_async( + transport: str = "grpc_asyncio", request_type=model_service.DeleteModelRequest ): client = ModelServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1756,40 +2424,42 @@ async def test_export_model_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.export_model), "__call__") as call: + with mock.patch.object(type(client.transport.delete_model), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.export_model(request) + response = await client.delete_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == model_service.ExportModelRequest() + assert args[0] == model_service.DeleteModelRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) @pytest.mark.asyncio -async def test_export_model_async_from_dict(): - await test_export_model_async(request_type=dict) +async def test_delete_model_async_from_dict(): + await test_delete_model_async(request_type=dict) -def test_export_model_field_headers(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_delete_model_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = model_service.ExportModelRequest() + request = model_service.DeleteModelRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.export_model), "__call__") as call: + with mock.patch.object(type(client.transport.delete_model), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.export_model(request) + client.delete_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -1798,25 +2468,30 @@ def test_export_model_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_export_model_field_headers_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_delete_model_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = model_service.ExportModelRequest() + request = model_service.DeleteModelRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.export_model), "__call__") as call: + with mock.patch.object(type(client.transport.delete_model), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.export_model(request) + await client.delete_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -1825,56 +2500,58 @@ async def test_export_model_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] -def test_export_model_flattened(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_delete_model_flattened(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.export_model), "__call__") as call: + with mock.patch.object(type(client.transport.delete_model), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.export_model( + client.delete_model( name="name_value", - output_config=model_service.ExportModelRequest.OutputConfig( - export_format_id="export_format_id_value" - ), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].output_config == model_service.ExportModelRequest.OutputConfig( - export_format_id="export_format_id_value" - ) + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val -def test_export_model_flattened_error(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_delete_model_flattened_error(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.export_model( - model_service.ExportModelRequest(), + client.delete_model( + model_service.DeleteModelRequest(), name="name_value", - output_config=model_service.ExportModelRequest.OutputConfig( - export_format_id="export_format_id_value" - ), ) @pytest.mark.asyncio -async def test_export_model_flattened_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_delete_model_flattened_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.export_model), "__call__") as call: + with mock.patch.object(type(client.transport.delete_model), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -1883,44 +2560,45 @@ async def test_export_model_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.export_model( + response = await client.delete_model( name="name_value", - output_config=model_service.ExportModelRequest.OutputConfig( - export_format_id="export_format_id_value" - ), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].output_config == model_service.ExportModelRequest.OutputConfig( - export_format_id="export_format_id_value" - ) + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio -async def test_export_model_flattened_error_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_delete_model_flattened_error_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.export_model( - model_service.ExportModelRequest(), + await client.delete_model( + model_service.DeleteModelRequest(), name="name_value", - output_config=model_service.ExportModelRequest.OutputConfig( - export_format_id="export_format_id_value" - ), ) -def test_get_model_evaluation( - transport: str = "grpc", request_type=model_service.GetModelEvaluationRequest -): +@pytest.mark.parametrize( + "request_type", + [ + model_service.DeleteModelVersionRequest, + dict, + ], +) +def test_delete_model_version(request_type, transport: str = "grpc"): client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1929,56 +2607,47 @@ def test_get_model_evaluation( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_model_evaluation), "__call__" + type(client.transport.delete_model_version), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = model_evaluation.ModelEvaluation( - name="name_value", - metrics_schema_uri="metrics_schema_uri_value", - slice_dimensions=["slice_dimensions_value"], - ) - response = client.get_model_evaluation(request) + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.delete_model_version(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == model_service.GetModelEvaluationRequest() + assert args[0] == model_service.DeleteModelVersionRequest() # Establish that the response is the type that we expect. - assert isinstance(response, model_evaluation.ModelEvaluation) - assert response.name == "name_value" - assert response.metrics_schema_uri == "metrics_schema_uri_value" - assert response.slice_dimensions == ["slice_dimensions_value"] - - -def test_get_model_evaluation_from_dict(): - test_get_model_evaluation(request_type=dict) + assert isinstance(response, future.Future) -def test_get_model_evaluation_empty_call(): +def test_delete_model_version_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_model_evaluation), "__call__" + type(client.transport.delete_model_version), "__call__" ) as call: - client.get_model_evaluation() + client.delete_model_version() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == model_service.GetModelEvaluationRequest() + assert args[0] == model_service.DeleteModelVersionRequest() @pytest.mark.asyncio -async def test_get_model_evaluation_async( +async def test_delete_model_version_async( transport: str = "grpc_asyncio", - request_type=model_service.GetModelEvaluationRequest, + request_type=model_service.DeleteModelVersionRequest, ): client = ModelServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1987,50 +2656,45 @@ async def test_get_model_evaluation_async( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_model_evaluation), "__call__" + type(client.transport.delete_model_version), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - model_evaluation.ModelEvaluation( - name="name_value", - metrics_schema_uri="metrics_schema_uri_value", - slice_dimensions=["slice_dimensions_value"], - ) + operations_pb2.Operation(name="operations/spam") ) - response = await client.get_model_evaluation(request) + response = await client.delete_model_version(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == model_service.GetModelEvaluationRequest() + assert args[0] == model_service.DeleteModelVersionRequest() # Establish that the response is the type that we expect. - assert isinstance(response, model_evaluation.ModelEvaluation) - assert response.name == "name_value" - assert response.metrics_schema_uri == "metrics_schema_uri_value" - assert response.slice_dimensions == ["slice_dimensions_value"] + assert isinstance(response, future.Future) @pytest.mark.asyncio -async def test_get_model_evaluation_async_from_dict(): - await test_get_model_evaluation_async(request_type=dict) +async def test_delete_model_version_async_from_dict(): + await test_delete_model_version_async(request_type=dict) -def test_get_model_evaluation_field_headers(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_delete_model_version_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = model_service.GetModelEvaluationRequest() + request = model_service.DeleteModelVersionRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_model_evaluation), "__call__" + type(client.transport.delete_model_version), "__call__" ) as call: - call.return_value = model_evaluation.ModelEvaluation() - client.get_model_evaluation(request) + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_model_version(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -2039,27 +2703,32 @@ def test_get_model_evaluation_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_get_model_evaluation_field_headers_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_delete_model_version_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = model_service.GetModelEvaluationRequest() + request = model_service.DeleteModelVersionRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_model_evaluation), "__call__" + type(client.transport.delete_model_version), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - model_evaluation.ModelEvaluation() + operations_pb2.Operation(name="operations/op") ) - await client.get_model_evaluation(request) + await client.delete_model_version(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -2068,82 +2737,109 @@ async def test_get_model_evaluation_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] -def test_get_model_evaluation_flattened(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_delete_model_version_flattened(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_model_evaluation), "__call__" + type(client.transport.delete_model_version), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = model_evaluation.ModelEvaluation() + call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_model_evaluation(name="name_value",) + client.delete_model_version( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val -def test_get_model_evaluation_flattened_error(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_delete_model_version_flattened_error(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_model_evaluation( - model_service.GetModelEvaluationRequest(), name="name_value", + client.delete_model_version( + model_service.DeleteModelVersionRequest(), + name="name_value", ) @pytest.mark.asyncio -async def test_get_model_evaluation_flattened_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_delete_model_version_flattened_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_model_evaluation), "__call__" + type(client.transport.delete_model_version), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = model_evaluation.ModelEvaluation() + call.return_value = operations_pb2.Operation(name="operations/op") call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - model_evaluation.ModelEvaluation() + operations_pb2.Operation(name="operations/spam") ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_model_evaluation(name="name_value",) + response = await client.delete_model_version( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio -async def test_get_model_evaluation_flattened_error_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_delete_model_version_flattened_error_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.get_model_evaluation( - model_service.GetModelEvaluationRequest(), name="name_value", + await client.delete_model_version( + model_service.DeleteModelVersionRequest(), + name="name_value", ) -def test_list_model_evaluations( - transport: str = "grpc", request_type=model_service.ListModelEvaluationsRequest -): +@pytest.mark.parametrize( + "request_type", + [ + model_service.MergeVersionAliasesRequest, + dict, + ], +) +def test_merge_version_aliases(request_type, transport: str = "grpc"): client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2152,52 +2848,82 @@ def test_list_model_evaluations( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_model_evaluations), "__call__" + type(client.transport.merge_version_aliases), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = model_service.ListModelEvaluationsResponse( - next_page_token="next_page_token_value", + call.return_value = model.Model( + name="name_value", + version_id="version_id_value", + version_aliases=["version_aliases_value"], + display_name="display_name_value", + description="description_value", + version_description="version_description_value", + metadata_schema_uri="metadata_schema_uri_value", + training_pipeline="training_pipeline_value", + artifact_uri="artifact_uri_value", + supported_deployment_resources_types=[ + model.Model.DeploymentResourcesType.DEDICATED_RESOURCES + ], + supported_input_storage_formats=["supported_input_storage_formats_value"], + supported_output_storage_formats=["supported_output_storage_formats_value"], + etag="etag_value", ) - response = client.list_model_evaluations(request) + response = client.merge_version_aliases(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == model_service.ListModelEvaluationsRequest() + assert args[0] == model_service.MergeVersionAliasesRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListModelEvaluationsPager) - assert response.next_page_token == "next_page_token_value" - - -def test_list_model_evaluations_from_dict(): - test_list_model_evaluations(request_type=dict) - - -def test_list_model_evaluations_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. + assert isinstance(response, model.Model) + assert response.name == "name_value" + assert response.version_id == "version_id_value" + assert response.version_aliases == ["version_aliases_value"] + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.version_description == "version_description_value" + assert response.metadata_schema_uri == "metadata_schema_uri_value" + assert response.training_pipeline == "training_pipeline_value" + assert response.artifact_uri == "artifact_uri_value" + assert response.supported_deployment_resources_types == [ + model.Model.DeploymentResourcesType.DEDICATED_RESOURCES + ] + assert response.supported_input_storage_formats == [ + "supported_input_storage_formats_value" + ] + assert response.supported_output_storage_formats == [ + "supported_output_storage_formats_value" + ] + assert response.etag == "etag_value" + + +def test_merge_version_aliases_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_model_evaluations), "__call__" + type(client.transport.merge_version_aliases), "__call__" ) as call: - client.list_model_evaluations() + client.merge_version_aliases() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == model_service.ListModelEvaluationsRequest() + assert args[0] == model_service.MergeVersionAliasesRequest() @pytest.mark.asyncio -async def test_list_model_evaluations_async( +async def test_merge_version_aliases_async( transport: str = "grpc_asyncio", - request_type=model_service.ListModelEvaluationsRequest, + request_type=model_service.MergeVersionAliasesRequest, ): client = ModelServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2206,46 +2932,84 @@ async def test_list_model_evaluations_async( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_model_evaluations), "__call__" + type(client.transport.merge_version_aliases), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - model_service.ListModelEvaluationsResponse( - next_page_token="next_page_token_value", + model.Model( + name="name_value", + version_id="version_id_value", + version_aliases=["version_aliases_value"], + display_name="display_name_value", + description="description_value", + version_description="version_description_value", + metadata_schema_uri="metadata_schema_uri_value", + training_pipeline="training_pipeline_value", + artifact_uri="artifact_uri_value", + supported_deployment_resources_types=[ + model.Model.DeploymentResourcesType.DEDICATED_RESOURCES + ], + supported_input_storage_formats=[ + "supported_input_storage_formats_value" + ], + supported_output_storage_formats=[ + "supported_output_storage_formats_value" + ], + etag="etag_value", ) ) - response = await client.list_model_evaluations(request) + response = await client.merge_version_aliases(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == model_service.ListModelEvaluationsRequest() + assert args[0] == model_service.MergeVersionAliasesRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListModelEvaluationsAsyncPager) - assert response.next_page_token == "next_page_token_value" + assert isinstance(response, model.Model) + assert response.name == "name_value" + assert response.version_id == "version_id_value" + assert response.version_aliases == ["version_aliases_value"] + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.version_description == "version_description_value" + assert response.metadata_schema_uri == "metadata_schema_uri_value" + assert response.training_pipeline == "training_pipeline_value" + assert response.artifact_uri == "artifact_uri_value" + assert response.supported_deployment_resources_types == [ + model.Model.DeploymentResourcesType.DEDICATED_RESOURCES + ] + assert response.supported_input_storage_formats == [ + "supported_input_storage_formats_value" + ] + assert response.supported_output_storage_formats == [ + "supported_output_storage_formats_value" + ] + assert response.etag == "etag_value" @pytest.mark.asyncio -async def test_list_model_evaluations_async_from_dict(): - await test_list_model_evaluations_async(request_type=dict) +async def test_merge_version_aliases_async_from_dict(): + await test_merge_version_aliases_async(request_type=dict) -def test_list_model_evaluations_field_headers(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_merge_version_aliases_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = model_service.ListModelEvaluationsRequest() + request = model_service.MergeVersionAliasesRequest() - request.parent = "parent/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_model_evaluations), "__call__" + type(client.transport.merge_version_aliases), "__call__" ) as call: - call.return_value = model_service.ListModelEvaluationsResponse() - client.list_model_evaluations(request) + call.return_value = model.Model() + client.merge_version_aliases(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -2254,27 +3018,30 @@ def test_list_model_evaluations_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_list_model_evaluations_field_headers_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_merge_version_aliases_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = model_service.ListModelEvaluationsRequest() + request = model_service.MergeVersionAliasesRequest() - request.parent = "parent/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_model_evaluations), "__call__" + type(client.transport.merge_version_aliases), "__call__" ) as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - model_service.ListModelEvaluationsResponse() - ) - await client.list_model_evaluations(request) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(model.Model()) + await client.merge_version_aliases(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -2283,252 +3050,365 @@ async def test_list_model_evaluations_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] -def test_list_model_evaluations_flattened(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_merge_version_aliases_flattened(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_model_evaluations), "__call__" + type(client.transport.merge_version_aliases), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = model_service.ListModelEvaluationsResponse() + call.return_value = model.Model() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_model_evaluations(parent="parent_value",) + client.merge_version_aliases( + name="name_value", + version_aliases=["version_aliases_value"], + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].version_aliases + mock_val = ["version_aliases_value"] + assert arg == mock_val -def test_list_model_evaluations_flattened_error(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_merge_version_aliases_flattened_error(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_model_evaluations( - model_service.ListModelEvaluationsRequest(), parent="parent_value", + client.merge_version_aliases( + model_service.MergeVersionAliasesRequest(), + name="name_value", + version_aliases=["version_aliases_value"], ) @pytest.mark.asyncio -async def test_list_model_evaluations_flattened_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_merge_version_aliases_flattened_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_model_evaluations), "__call__" + type(client.transport.merge_version_aliases), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = model_service.ListModelEvaluationsResponse() + call.return_value = model.Model() - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - model_service.ListModelEvaluationsResponse() - ) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(model.Model()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_model_evaluations(parent="parent_value",) + response = await client.merge_version_aliases( + name="name_value", + version_aliases=["version_aliases_value"], + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].version_aliases + mock_val = ["version_aliases_value"] + assert arg == mock_val @pytest.mark.asyncio -async def test_list_model_evaluations_flattened_error_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_merge_version_aliases_flattened_error_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.list_model_evaluations( - model_service.ListModelEvaluationsRequest(), parent="parent_value", + await client.merge_version_aliases( + model_service.MergeVersionAliasesRequest(), + name="name_value", + version_aliases=["version_aliases_value"], ) -def test_list_model_evaluations_pager(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials,) +@pytest.mark.parametrize( + "request_type", + [ + model_service.ExportModelRequest, + dict, + ], +) +def test_export_model(request_type, transport: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_model_evaluations), "__call__" - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - model_service.ListModelEvaluationsResponse( - model_evaluations=[ - model_evaluation.ModelEvaluation(), - model_evaluation.ModelEvaluation(), - model_evaluation.ModelEvaluation(), - ], - next_page_token="abc", - ), - model_service.ListModelEvaluationsResponse( - model_evaluations=[], next_page_token="def", - ), - model_service.ListModelEvaluationsResponse( - model_evaluations=[model_evaluation.ModelEvaluation(),], - next_page_token="ghi", - ), - model_service.ListModelEvaluationsResponse( - model_evaluations=[ - model_evaluation.ModelEvaluation(), - model_evaluation.ModelEvaluation(), - ], - ), - RuntimeError, - ) + with mock.patch.object(type(client.transport.export_model), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.export_model(request) - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), - ) - pager = client.list_model_evaluations(request={}) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.ExportModelRequest() - assert pager._metadata == metadata + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) - results = [i for i in pager] - assert len(results) == 6 - assert all(isinstance(i, model_evaluation.ModelEvaluation) for i in results) +def test_export_model_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.export_model), "__call__") as call: + client.export_model() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.ExportModelRequest() + + +@pytest.mark.asyncio +async def test_export_model_async( + transport: str = "grpc_asyncio", request_type=model_service.ExportModelRequest +): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) -def test_list_model_evaluations_pages(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials,) + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_model_evaluations), "__call__" - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - model_service.ListModelEvaluationsResponse( - model_evaluations=[ - model_evaluation.ModelEvaluation(), - model_evaluation.ModelEvaluation(), - model_evaluation.ModelEvaluation(), - ], - next_page_token="abc", - ), - model_service.ListModelEvaluationsResponse( - model_evaluations=[], next_page_token="def", - ), - model_service.ListModelEvaluationsResponse( - model_evaluations=[model_evaluation.ModelEvaluation(),], - next_page_token="ghi", - ), - model_service.ListModelEvaluationsResponse( - model_evaluations=[ - model_evaluation.ModelEvaluation(), - model_evaluation.ModelEvaluation(), - ], - ), - RuntimeError, + with mock.patch.object(type(client.transport.export_model), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") ) - pages = list(client.list_model_evaluations(request={}).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token + response = await client.export_model(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.ExportModelRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) @pytest.mark.asyncio -async def test_list_model_evaluations_async_pager(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) +async def test_export_model_async_from_dict(): + await test_export_model_async(request_type=dict) - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_model_evaluations), - "__call__", - new_callable=mock.AsyncMock, - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - model_service.ListModelEvaluationsResponse( - model_evaluations=[ - model_evaluation.ModelEvaluation(), - model_evaluation.ModelEvaluation(), - model_evaluation.ModelEvaluation(), - ], - next_page_token="abc", - ), - model_service.ListModelEvaluationsResponse( - model_evaluations=[], next_page_token="def", - ), - model_service.ListModelEvaluationsResponse( - model_evaluations=[model_evaluation.ModelEvaluation(),], - next_page_token="ghi", - ), - model_service.ListModelEvaluationsResponse( - model_evaluations=[ - model_evaluation.ModelEvaluation(), - model_evaluation.ModelEvaluation(), - ], - ), - RuntimeError, - ) - async_pager = await client.list_model_evaluations(request={},) - assert async_pager.next_page_token == "abc" - responses = [] - async for response in async_pager: - responses.append(response) - assert len(responses) == 6 - assert all(isinstance(i, model_evaluation.ModelEvaluation) for i in responses) +def test_export_model_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = model_service.ExportModelRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.export_model), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.export_model(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_list_model_evaluations_async_pages(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) +async def test_export_model_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = model_service.ExportModelRequest() + + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_model_evaluations), - "__call__", - new_callable=mock.AsyncMock, - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - model_service.ListModelEvaluationsResponse( - model_evaluations=[ - model_evaluation.ModelEvaluation(), - model_evaluation.ModelEvaluation(), - model_evaluation.ModelEvaluation(), - ], - next_page_token="abc", + with mock.patch.object(type(client.transport.export_model), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.export_model(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_export_model_flattened(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.export_model), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.export_model( + name="name_value", + output_config=model_service.ExportModelRequest.OutputConfig( + export_format_id="export_format_id_value" ), - model_service.ListModelEvaluationsResponse( - model_evaluations=[], next_page_token="def", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].output_config + mock_val = model_service.ExportModelRequest.OutputConfig( + export_format_id="export_format_id_value" + ) + assert arg == mock_val + + +def test_export_model_flattened_error(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.export_model( + model_service.ExportModelRequest(), + name="name_value", + output_config=model_service.ExportModelRequest.OutputConfig( + export_format_id="export_format_id_value" ), - model_service.ListModelEvaluationsResponse( - model_evaluations=[model_evaluation.ModelEvaluation(),], - next_page_token="ghi", + ) + + +@pytest.mark.asyncio +async def test_export_model_flattened_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.export_model), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.export_model( + name="name_value", + output_config=model_service.ExportModelRequest.OutputConfig( + export_format_id="export_format_id_value" ), - model_service.ListModelEvaluationsResponse( - model_evaluations=[ - model_evaluation.ModelEvaluation(), - model_evaluation.ModelEvaluation(), - ], + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].output_config + mock_val = model_service.ExportModelRequest.OutputConfig( + export_format_id="export_format_id_value" + ) + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_export_model_flattened_error_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.export_model( + model_service.ExportModelRequest(), + name="name_value", + output_config=model_service.ExportModelRequest.OutputConfig( + export_format_id="export_format_id_value" ), - RuntimeError, ) - pages = [] - async for page_ in (await client.list_model_evaluations(request={})).pages: - pages.append(page_) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token -def test_get_model_evaluation_slice( - transport: str = "grpc", request_type=model_service.GetModelEvaluationSliceRequest -): +@pytest.mark.parametrize( + "request_type", + [ + model_service.ImportModelEvaluationRequest, + dict, + ], +) +def test_import_model_evaluation(request_type, transport: str = "grpc"): client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2537,53 +3417,60 @@ def test_get_model_evaluation_slice( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_model_evaluation_slice), "__call__" + type(client.transport.import_model_evaluation), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = model_evaluation_slice.ModelEvaluationSlice( - name="name_value", metrics_schema_uri="metrics_schema_uri_value", + call.return_value = gca_model_evaluation.ModelEvaluation( + name="name_value", + display_name="display_name_value", + metrics_schema_uri="metrics_schema_uri_value", + slice_dimensions=["slice_dimensions_value"], + data_item_schema_uri="data_item_schema_uri_value", + annotation_schema_uri="annotation_schema_uri_value", ) - response = client.get_model_evaluation_slice(request) + response = client.import_model_evaluation(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == model_service.GetModelEvaluationSliceRequest() + assert args[0] == model_service.ImportModelEvaluationRequest() # Establish that the response is the type that we expect. - assert isinstance(response, model_evaluation_slice.ModelEvaluationSlice) + assert isinstance(response, gca_model_evaluation.ModelEvaluation) assert response.name == "name_value" + assert response.display_name == "display_name_value" assert response.metrics_schema_uri == "metrics_schema_uri_value" + assert response.slice_dimensions == ["slice_dimensions_value"] + assert response.data_item_schema_uri == "data_item_schema_uri_value" + assert response.annotation_schema_uri == "annotation_schema_uri_value" -def test_get_model_evaluation_slice_from_dict(): - test_get_model_evaluation_slice(request_type=dict) - - -def test_get_model_evaluation_slice_empty_call(): +def test_import_model_evaluation_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_model_evaluation_slice), "__call__" + type(client.transport.import_model_evaluation), "__call__" ) as call: - client.get_model_evaluation_slice() + client.import_model_evaluation() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == model_service.GetModelEvaluationSliceRequest() + assert args[0] == model_service.ImportModelEvaluationRequest() @pytest.mark.asyncio -async def test_get_model_evaluation_slice_async( +async def test_import_model_evaluation_async( transport: str = "grpc_asyncio", - request_type=model_service.GetModelEvaluationSliceRequest, + request_type=model_service.ImportModelEvaluationRequest, ): client = ModelServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2592,47 +3479,58 @@ async def test_get_model_evaluation_slice_async( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_model_evaluation_slice), "__call__" + type(client.transport.import_model_evaluation), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - model_evaluation_slice.ModelEvaluationSlice( - name="name_value", metrics_schema_uri="metrics_schema_uri_value", + gca_model_evaluation.ModelEvaluation( + name="name_value", + display_name="display_name_value", + metrics_schema_uri="metrics_schema_uri_value", + slice_dimensions=["slice_dimensions_value"], + data_item_schema_uri="data_item_schema_uri_value", + annotation_schema_uri="annotation_schema_uri_value", ) ) - response = await client.get_model_evaluation_slice(request) + response = await client.import_model_evaluation(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == model_service.GetModelEvaluationSliceRequest() + assert args[0] == model_service.ImportModelEvaluationRequest() # Establish that the response is the type that we expect. - assert isinstance(response, model_evaluation_slice.ModelEvaluationSlice) + assert isinstance(response, gca_model_evaluation.ModelEvaluation) assert response.name == "name_value" + assert response.display_name == "display_name_value" assert response.metrics_schema_uri == "metrics_schema_uri_value" + assert response.slice_dimensions == ["slice_dimensions_value"] + assert response.data_item_schema_uri == "data_item_schema_uri_value" + assert response.annotation_schema_uri == "annotation_schema_uri_value" @pytest.mark.asyncio -async def test_get_model_evaluation_slice_async_from_dict(): - await test_get_model_evaluation_slice_async(request_type=dict) +async def test_import_model_evaluation_async_from_dict(): + await test_import_model_evaluation_async(request_type=dict) -def test_get_model_evaluation_slice_field_headers(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_import_model_evaluation_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = model_service.GetModelEvaluationSliceRequest() + request = model_service.ImportModelEvaluationRequest() - request.name = "name/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_model_evaluation_slice), "__call__" + type(client.transport.import_model_evaluation), "__call__" ) as call: - call.return_value = model_evaluation_slice.ModelEvaluationSlice() - client.get_model_evaluation_slice(request) + call.return_value = gca_model_evaluation.ModelEvaluation() + client.import_model_evaluation(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -2641,27 +3539,32 @@ def test_get_model_evaluation_slice_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_get_model_evaluation_slice_field_headers_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_import_model_evaluation_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = model_service.GetModelEvaluationSliceRequest() + request = model_service.ImportModelEvaluationRequest() - request.name = "name/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_model_evaluation_slice), "__call__" + type(client.transport.import_model_evaluation), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - model_evaluation_slice.ModelEvaluationSlice() + gca_model_evaluation.ModelEvaluation() ) - await client.get_model_evaluation_slice(request) + await client.import_model_evaluation(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -2670,82 +3573,119 @@ async def test_get_model_evaluation_slice_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] -def test_get_model_evaluation_slice_flattened(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_import_model_evaluation_flattened(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_model_evaluation_slice), "__call__" + type(client.transport.import_model_evaluation), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = model_evaluation_slice.ModelEvaluationSlice() + call.return_value = gca_model_evaluation.ModelEvaluation() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_model_evaluation_slice(name="name_value",) + client.import_model_evaluation( + parent="parent_value", + model_evaluation=gca_model_evaluation.ModelEvaluation(name="name_value"), + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].model_evaluation + mock_val = gca_model_evaluation.ModelEvaluation(name="name_value") + assert arg == mock_val -def test_get_model_evaluation_slice_flattened_error(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_import_model_evaluation_flattened_error(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_model_evaluation_slice( - model_service.GetModelEvaluationSliceRequest(), name="name_value", + client.import_model_evaluation( + model_service.ImportModelEvaluationRequest(), + parent="parent_value", + model_evaluation=gca_model_evaluation.ModelEvaluation(name="name_value"), ) @pytest.mark.asyncio -async def test_get_model_evaluation_slice_flattened_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_import_model_evaluation_flattened_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_model_evaluation_slice), "__call__" + type(client.transport.import_model_evaluation), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = model_evaluation_slice.ModelEvaluationSlice() + call.return_value = gca_model_evaluation.ModelEvaluation() call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - model_evaluation_slice.ModelEvaluationSlice() + gca_model_evaluation.ModelEvaluation() ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_model_evaluation_slice(name="name_value",) + response = await client.import_model_evaluation( + parent="parent_value", + model_evaluation=gca_model_evaluation.ModelEvaluation(name="name_value"), + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].model_evaluation + mock_val = gca_model_evaluation.ModelEvaluation(name="name_value") + assert arg == mock_val @pytest.mark.asyncio -async def test_get_model_evaluation_slice_flattened_error_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_import_model_evaluation_flattened_error_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.get_model_evaluation_slice( - model_service.GetModelEvaluationSliceRequest(), name="name_value", + await client.import_model_evaluation( + model_service.ImportModelEvaluationRequest(), + parent="parent_value", + model_evaluation=gca_model_evaluation.ModelEvaluation(name="name_value"), ) -def test_list_model_evaluation_slices( - transport: str = "grpc", request_type=model_service.ListModelEvaluationSlicesRequest -): +@pytest.mark.parametrize( + "request_type", + [ + model_service.GetModelEvaluationRequest, + dict, + ], +) +def test_get_model_evaluation(request_type, transport: str = "grpc"): client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2754,52 +3694,60 @@ def test_list_model_evaluation_slices( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_model_evaluation_slices), "__call__" + type(client.transport.get_model_evaluation), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = model_service.ListModelEvaluationSlicesResponse( - next_page_token="next_page_token_value", + call.return_value = model_evaluation.ModelEvaluation( + name="name_value", + display_name="display_name_value", + metrics_schema_uri="metrics_schema_uri_value", + slice_dimensions=["slice_dimensions_value"], + data_item_schema_uri="data_item_schema_uri_value", + annotation_schema_uri="annotation_schema_uri_value", ) - response = client.list_model_evaluation_slices(request) + response = client.get_model_evaluation(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == model_service.ListModelEvaluationSlicesRequest() + assert args[0] == model_service.GetModelEvaluationRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListModelEvaluationSlicesPager) - assert response.next_page_token == "next_page_token_value" - - -def test_list_model_evaluation_slices_from_dict(): - test_list_model_evaluation_slices(request_type=dict) + assert isinstance(response, model_evaluation.ModelEvaluation) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.metrics_schema_uri == "metrics_schema_uri_value" + assert response.slice_dimensions == ["slice_dimensions_value"] + assert response.data_item_schema_uri == "data_item_schema_uri_value" + assert response.annotation_schema_uri == "annotation_schema_uri_value" -def test_list_model_evaluation_slices_empty_call(): +def test_get_model_evaluation_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_model_evaluation_slices), "__call__" + type(client.transport.get_model_evaluation), "__call__" ) as call: - client.list_model_evaluation_slices() + client.get_model_evaluation() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == model_service.ListModelEvaluationSlicesRequest() + assert args[0] == model_service.GetModelEvaluationRequest() @pytest.mark.asyncio -async def test_list_model_evaluation_slices_async( +async def test_get_model_evaluation_async( transport: str = "grpc_asyncio", - request_type=model_service.ListModelEvaluationSlicesRequest, + request_type=model_service.GetModelEvaluationRequest, ): client = ModelServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2808,46 +3756,58 @@ async def test_list_model_evaluation_slices_async( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_model_evaluation_slices), "__call__" + type(client.transport.get_model_evaluation), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - model_service.ListModelEvaluationSlicesResponse( - next_page_token="next_page_token_value", + model_evaluation.ModelEvaluation( + name="name_value", + display_name="display_name_value", + metrics_schema_uri="metrics_schema_uri_value", + slice_dimensions=["slice_dimensions_value"], + data_item_schema_uri="data_item_schema_uri_value", + annotation_schema_uri="annotation_schema_uri_value", ) ) - response = await client.list_model_evaluation_slices(request) + response = await client.get_model_evaluation(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == model_service.ListModelEvaluationSlicesRequest() + assert args[0] == model_service.GetModelEvaluationRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListModelEvaluationSlicesAsyncPager) - assert response.next_page_token == "next_page_token_value" + assert isinstance(response, model_evaluation.ModelEvaluation) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.metrics_schema_uri == "metrics_schema_uri_value" + assert response.slice_dimensions == ["slice_dimensions_value"] + assert response.data_item_schema_uri == "data_item_schema_uri_value" + assert response.annotation_schema_uri == "annotation_schema_uri_value" @pytest.mark.asyncio -async def test_list_model_evaluation_slices_async_from_dict(): - await test_list_model_evaluation_slices_async(request_type=dict) +async def test_get_model_evaluation_async_from_dict(): + await test_get_model_evaluation_async(request_type=dict) -def test_list_model_evaluation_slices_field_headers(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_get_model_evaluation_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = model_service.ListModelEvaluationSlicesRequest() + request = model_service.GetModelEvaluationRequest() - request.parent = "parent/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_model_evaluation_slices), "__call__" + type(client.transport.get_model_evaluation), "__call__" ) as call: - call.return_value = model_service.ListModelEvaluationSlicesResponse() - client.list_model_evaluation_slices(request) + call.return_value = model_evaluation.ModelEvaluation() + client.get_model_evaluation(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -2856,27 +3816,32 @@ def test_list_model_evaluation_slices_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_list_model_evaluation_slices_field_headers_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_get_model_evaluation_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = model_service.ListModelEvaluationSlicesRequest() + request = model_service.GetModelEvaluationRequest() - request.parent = "parent/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_model_evaluation_slices), "__call__" + type(client.transport.get_model_evaluation), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - model_service.ListModelEvaluationSlicesResponse() + model_evaluation.ModelEvaluation() ) - await client.list_model_evaluation_slices(request) + await client.get_model_evaluation(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -2885,599 +3850,1514 @@ async def test_list_model_evaluation_slices_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] -def test_list_model_evaluation_slices_flattened(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_get_model_evaluation_flattened(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_model_evaluation_slices), "__call__" + type(client.transport.get_model_evaluation), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = model_service.ListModelEvaluationSlicesResponse() + call.return_value = model_evaluation.ModelEvaluation() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_model_evaluation_slices(parent="parent_value",) + client.get_model_evaluation( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val -def test_list_model_evaluation_slices_flattened_error(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_get_model_evaluation_flattened_error(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_model_evaluation_slices( - model_service.ListModelEvaluationSlicesRequest(), parent="parent_value", + client.get_model_evaluation( + model_service.GetModelEvaluationRequest(), + name="name_value", ) @pytest.mark.asyncio -async def test_list_model_evaluation_slices_flattened_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_get_model_evaluation_flattened_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_model_evaluation_slices), "__call__" + type(client.transport.get_model_evaluation), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = model_service.ListModelEvaluationSlicesResponse() + call.return_value = model_evaluation.ModelEvaluation() call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - model_service.ListModelEvaluationSlicesResponse() + model_evaluation.ModelEvaluation() ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_model_evaluation_slices(parent="parent_value",) + response = await client.get_model_evaluation( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio -async def test_list_model_evaluation_slices_flattened_error_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_get_model_evaluation_flattened_error_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.list_model_evaluation_slices( - model_service.ListModelEvaluationSlicesRequest(), parent="parent_value", + await client.get_model_evaluation( + model_service.GetModelEvaluationRequest(), + name="name_value", ) -def test_list_model_evaluation_slices_pager(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials,) +@pytest.mark.parametrize( + "request_type", + [ + model_service.ListModelEvaluationsRequest, + dict, + ], +) +def test_list_model_evaluations(request_type, transport: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_model_evaluation_slices), "__call__" + type(client.transport.list_model_evaluations), "__call__" ) as call: - # Set the response to a series of pages. - call.side_effect = ( - model_service.ListModelEvaluationSlicesResponse( - model_evaluation_slices=[ - model_evaluation_slice.ModelEvaluationSlice(), - model_evaluation_slice.ModelEvaluationSlice(), - model_evaluation_slice.ModelEvaluationSlice(), - ], - next_page_token="abc", - ), - model_service.ListModelEvaluationSlicesResponse( - model_evaluation_slices=[], next_page_token="def", - ), - model_service.ListModelEvaluationSlicesResponse( - model_evaluation_slices=[ - model_evaluation_slice.ModelEvaluationSlice(), - ], - next_page_token="ghi", - ), - model_service.ListModelEvaluationSlicesResponse( - model_evaluation_slices=[ - model_evaluation_slice.ModelEvaluationSlice(), - model_evaluation_slice.ModelEvaluationSlice(), - ], - ), - RuntimeError, + # Designate an appropriate return value for the call. + call.return_value = model_service.ListModelEvaluationsResponse( + next_page_token="next_page_token_value", ) + response = client.list_model_evaluations(request) - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), - ) - pager = client.list_model_evaluation_slices(request={}) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.ListModelEvaluationsRequest() - assert pager._metadata == metadata + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListModelEvaluationsPager) + assert response.next_page_token == "next_page_token_value" + + +def test_list_model_evaluations_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluations), "__call__" + ) as call: + client.list_model_evaluations() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.ListModelEvaluationsRequest() - results = [i for i in pager] - assert len(results) == 6 - assert all( - isinstance(i, model_evaluation_slice.ModelEvaluationSlice) for i in results - ) +@pytest.mark.asyncio +async def test_list_model_evaluations_async( + transport: str = "grpc_asyncio", + request_type=model_service.ListModelEvaluationsRequest, +): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) -def test_list_model_evaluation_slices_pages(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials,) + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_model_evaluation_slices), "__call__" + type(client.transport.list_model_evaluations), "__call__" ) as call: - # Set the response to a series of pages. - call.side_effect = ( - model_service.ListModelEvaluationSlicesResponse( - model_evaluation_slices=[ - model_evaluation_slice.ModelEvaluationSlice(), - model_evaluation_slice.ModelEvaluationSlice(), - model_evaluation_slice.ModelEvaluationSlice(), - ], - next_page_token="abc", - ), - model_service.ListModelEvaluationSlicesResponse( - model_evaluation_slices=[], next_page_token="def", - ), - model_service.ListModelEvaluationSlicesResponse( - model_evaluation_slices=[ - model_evaluation_slice.ModelEvaluationSlice(), - ], - next_page_token="ghi", - ), - model_service.ListModelEvaluationSlicesResponse( - model_evaluation_slices=[ - model_evaluation_slice.ModelEvaluationSlice(), - model_evaluation_slice.ModelEvaluationSlice(), - ], - ), - RuntimeError, + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + model_service.ListModelEvaluationsResponse( + next_page_token="next_page_token_value", + ) ) - pages = list(client.list_model_evaluation_slices(request={}).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token + response = await client.list_model_evaluations(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.ListModelEvaluationsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListModelEvaluationsAsyncPager) + assert response.next_page_token == "next_page_token_value" @pytest.mark.asyncio -async def test_list_model_evaluation_slices_async_pager(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) +async def test_list_model_evaluations_async_from_dict(): + await test_list_model_evaluations_async(request_type=dict) + + +def test_list_model_evaluations_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = model_service.ListModelEvaluationsRequest() + + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_model_evaluation_slices), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_model_evaluations), "__call__" + ) as call: + call.return_value = model_service.ListModelEvaluationsResponse() + client.list_model_evaluations(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_model_evaluations_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = model_service.ListModelEvaluationsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluations), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + model_service.ListModelEvaluationsResponse() + ) + await client.list_model_evaluations(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_list_model_evaluations_flattened(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluations), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = model_service.ListModelEvaluationsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_model_evaluations( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +def test_list_model_evaluations_flattened_error(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_model_evaluations( + model_service.ListModelEvaluationsRequest(), + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_model_evaluations_flattened_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluations), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = model_service.ListModelEvaluationsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + model_service.ListModelEvaluationsResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_model_evaluations( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_list_model_evaluations_flattened_error_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_model_evaluations( + model_service.ListModelEvaluationsRequest(), + parent="parent_value", + ) + + +def test_list_model_evaluations_pager(transport_name: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluations), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( - model_service.ListModelEvaluationSlicesResponse( - model_evaluation_slices=[ - model_evaluation_slice.ModelEvaluationSlice(), - model_evaluation_slice.ModelEvaluationSlice(), - model_evaluation_slice.ModelEvaluationSlice(), + model_service.ListModelEvaluationsResponse( + model_evaluations=[ + model_evaluation.ModelEvaluation(), + model_evaluation.ModelEvaluation(), + model_evaluation.ModelEvaluation(), ], next_page_token="abc", ), - model_service.ListModelEvaluationSlicesResponse( - model_evaluation_slices=[], next_page_token="def", + model_service.ListModelEvaluationsResponse( + model_evaluations=[], + next_page_token="def", ), - model_service.ListModelEvaluationSlicesResponse( - model_evaluation_slices=[ - model_evaluation_slice.ModelEvaluationSlice(), + model_service.ListModelEvaluationsResponse( + model_evaluations=[ + model_evaluation.ModelEvaluation(), ], next_page_token="ghi", ), - model_service.ListModelEvaluationSlicesResponse( - model_evaluation_slices=[ - model_evaluation_slice.ModelEvaluationSlice(), - model_evaluation_slice.ModelEvaluationSlice(), + model_service.ListModelEvaluationsResponse( + model_evaluations=[ + model_evaluation.ModelEvaluation(), + model_evaluation.ModelEvaluation(), ], ), RuntimeError, ) - async_pager = await client.list_model_evaluation_slices(request={},) - assert async_pager.next_page_token == "abc" - responses = [] - async for response in async_pager: - responses.append(response) - assert len(responses) == 6 - assert all( - isinstance(i, model_evaluation_slice.ModelEvaluationSlice) - for i in responses + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), ) + pager = client.list_model_evaluations(request={}) + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, model_evaluation.ModelEvaluation) for i in results) -@pytest.mark.asyncio -async def test_list_model_evaluation_slices_async_pages(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + +def test_list_model_evaluations_pages(transport_name: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_model_evaluation_slices), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_model_evaluations), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( - model_service.ListModelEvaluationSlicesResponse( - model_evaluation_slices=[ - model_evaluation_slice.ModelEvaluationSlice(), - model_evaluation_slice.ModelEvaluationSlice(), - model_evaluation_slice.ModelEvaluationSlice(), + model_service.ListModelEvaluationsResponse( + model_evaluations=[ + model_evaluation.ModelEvaluation(), + model_evaluation.ModelEvaluation(), + model_evaluation.ModelEvaluation(), ], next_page_token="abc", ), - model_service.ListModelEvaluationSlicesResponse( - model_evaluation_slices=[], next_page_token="def", + model_service.ListModelEvaluationsResponse( + model_evaluations=[], + next_page_token="def", ), - model_service.ListModelEvaluationSlicesResponse( - model_evaluation_slices=[ - model_evaluation_slice.ModelEvaluationSlice(), + model_service.ListModelEvaluationsResponse( + model_evaluations=[ + model_evaluation.ModelEvaluation(), ], next_page_token="ghi", ), - model_service.ListModelEvaluationSlicesResponse( - model_evaluation_slices=[ - model_evaluation_slice.ModelEvaluationSlice(), - model_evaluation_slice.ModelEvaluationSlice(), + model_service.ListModelEvaluationsResponse( + model_evaluations=[ + model_evaluation.ModelEvaluation(), + model_evaluation.ModelEvaluation(), ], ), RuntimeError, ) - pages = [] - async for page_ in ( - await client.list_model_evaluation_slices(request={}) - ).pages: - pages.append(page_) + pages = list(client.list_model_evaluations(request={}).pages) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_credentials_transport_error(): - # It is an error to provide credentials and a transport instance. - transport = transports.ModelServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), +@pytest.mark.asyncio +async def test_list_model_evaluations_async_pager(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, ) - with pytest.raises(ValueError): - client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluations), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + model_service.ListModelEvaluationsResponse( + model_evaluations=[ + model_evaluation.ModelEvaluation(), + model_evaluation.ModelEvaluation(), + model_evaluation.ModelEvaluation(), + ], + next_page_token="abc", + ), + model_service.ListModelEvaluationsResponse( + model_evaluations=[], + next_page_token="def", + ), + model_service.ListModelEvaluationsResponse( + model_evaluations=[ + model_evaluation.ModelEvaluation(), + ], + next_page_token="ghi", + ), + model_service.ListModelEvaluationsResponse( + model_evaluations=[ + model_evaluation.ModelEvaluation(), + model_evaluation.ModelEvaluation(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_model_evaluations( + request={}, ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) - # It is an error to provide a credentials file and a transport instance. - transport = transports.ModelServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), + assert len(responses) == 6 + assert all(isinstance(i, model_evaluation.ModelEvaluation) for i in responses) + + +@pytest.mark.asyncio +async def test_list_model_evaluations_async_pages(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, ) - with pytest.raises(ValueError): - client = ModelServiceClient( - client_options={"credentials_file": "credentials.json"}, - transport=transport, + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluations), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + model_service.ListModelEvaluationsResponse( + model_evaluations=[ + model_evaluation.ModelEvaluation(), + model_evaluation.ModelEvaluation(), + model_evaluation.ModelEvaluation(), + ], + next_page_token="abc", + ), + model_service.ListModelEvaluationsResponse( + model_evaluations=[], + next_page_token="def", + ), + model_service.ListModelEvaluationsResponse( + model_evaluations=[ + model_evaluation.ModelEvaluation(), + ], + next_page_token="ghi", + ), + model_service.ListModelEvaluationsResponse( + model_evaluations=[ + model_evaluation.ModelEvaluation(), + model_evaluation.ModelEvaluation(), + ], + ), + RuntimeError, ) + pages = [] + async for page_ in ( + await client.list_model_evaluations(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token - # It is an error to provide scopes and a transport instance. - transport = transports.ModelServiceGrpcTransport( + +@pytest.mark.parametrize( + "request_type", + [ + model_service.GetModelEvaluationSliceRequest, + dict, + ], +) +def test_get_model_evaluation_slice(request_type, transport: str = "grpc"): + client = ModelServiceClient( credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - with pytest.raises(ValueError): - client = ModelServiceClient( - client_options={"scopes": ["1", "2"]}, transport=transport, + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_model_evaluation_slice), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = model_evaluation_slice.ModelEvaluationSlice( + name="name_value", + metrics_schema_uri="metrics_schema_uri_value", ) + response = client.get_model_evaluation_slice(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.GetModelEvaluationSliceRequest() -def test_transport_instance(): - # A client may be instantiated with a custom transport instance. - transport = transports.ModelServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - client = ModelServiceClient(transport=transport) - assert client.transport is transport + # Establish that the response is the type that we expect. + assert isinstance(response, model_evaluation_slice.ModelEvaluationSlice) + assert response.name == "name_value" + assert response.metrics_schema_uri == "metrics_schema_uri_value" -def test_transport_get_channel(): - # A client may be instantiated with a custom transport instance. - transport = transports.ModelServiceGrpcTransport( +def test_get_model_evaluation_slice_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = ModelServiceClient( credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) - channel = transport.grpc_channel - assert channel - transport = transports.ModelServiceGrpcAsyncIOTransport( + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_model_evaluation_slice), "__call__" + ) as call: + client.get_model_evaluation_slice() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.GetModelEvaluationSliceRequest() + + +@pytest.mark.asyncio +async def test_get_model_evaluation_slice_async( + transport: str = "grpc_asyncio", + request_type=model_service.GetModelEvaluationSliceRequest, +): + client = ModelServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - channel = transport.grpc_channel - assert channel - -@pytest.mark.parametrize( - "transport_class", - [ - transports.ModelServiceGrpcTransport, - transports.ModelServiceGrpcAsyncIOTransport, - ], -) -def test_transport_adc(transport_class): - # Test default credentials are used if not provided. - with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class() - adc.assert_called_once() + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_model_evaluation_slice), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + model_evaluation_slice.ModelEvaluationSlice( + name="name_value", + metrics_schema_uri="metrics_schema_uri_value", + ) + ) + response = await client.get_model_evaluation_slice(request) -def test_transport_grpc_default(): - # A client should use the gRPC transport by default. - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) - assert isinstance(client.transport, transports.ModelServiceGrpcTransport,) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.GetModelEvaluationSliceRequest() + # Establish that the response is the type that we expect. + assert isinstance(response, model_evaluation_slice.ModelEvaluationSlice) + assert response.name == "name_value" + assert response.metrics_schema_uri == "metrics_schema_uri_value" -def test_model_service_base_transport_error(): - # Passing both a credentials object and credentials_file should raise an error - with pytest.raises(core_exceptions.DuplicateCredentialArgs): - transport = transports.ModelServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), - credentials_file="credentials.json", - ) +@pytest.mark.asyncio +async def test_get_model_evaluation_slice_async_from_dict(): + await test_get_model_evaluation_slice_async(request_type=dict) -def test_model_service_base_transport(): - # Instantiate the base transport. - with mock.patch( - "google.cloud.aiplatform_v1.services.model_service.transports.ModelServiceTransport.__init__" - ) as Transport: - Transport.return_value = None - transport = transports.ModelServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - # Every method on the transport should just blindly - # raise NotImplementedError. - methods = ( - "upload_model", - "get_model", - "list_models", - "update_model", - "delete_model", - "export_model", - "get_model_evaluation", - "list_model_evaluations", - "get_model_evaluation_slice", - "list_model_evaluation_slices", +def test_get_model_evaluation_slice_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), ) - for method in methods: - with pytest.raises(NotImplementedError): - getattr(transport, method)(request=object()) - # Additionally, the LRO client (a property) should - # also raise NotImplementedError - with pytest.raises(NotImplementedError): - transport.operations_client + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = model_service.GetModelEvaluationSliceRequest() + request.name = "name_value" -@requires_google_auth_gte_1_25_0 -def test_model_service_base_transport_with_credentials_file(): - # Instantiate the base transport with a credentials file + # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.aiplatform_v1.services.model_service.transports.ModelServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ModelServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=None, - default_scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) + type(client.transport.get_model_evaluation_slice), "__call__" + ) as call: + call.return_value = model_evaluation_slice.ModelEvaluationSlice() + client.get_model_evaluation_slice(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request -@requires_google_auth_lt_1_25_0 -def test_model_service_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.aiplatform_v1.services.model_service.transports.ModelServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ModelServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] -def test_model_service_base_transport_with_adc(): - # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.aiplatform_v1.services.model_service.transports.ModelServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ModelServiceTransport() - adc.assert_called_once() +@pytest.mark.asyncio +async def test_get_model_evaluation_slice_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = model_service.GetModelEvaluationSliceRequest() -@requires_google_auth_gte_1_25_0 -def test_model_service_auth_adc(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - ModelServiceClient() - adc.assert_called_once_with( - scopes=None, - default_scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_model_evaluation_slice), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + model_evaluation_slice.ModelEvaluationSlice() ) + await client.get_model_evaluation_slice(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request -@requires_google_auth_lt_1_25_0 -def test_model_service_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - ModelServiceClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] -@pytest.mark.parametrize( - "transport_class", - [ - transports.ModelServiceGrpcTransport, - transports.ModelServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_gte_1_25_0 -def test_model_service_transport_auth_adc(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - adc.assert_called_once_with( - scopes=["1", "2"], - default_scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", +def test_get_model_evaluation_slice_flattened(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_model_evaluation_slice), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = model_evaluation_slice.ModelEvaluationSlice() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_model_evaluation_slice( + name="name_value", ) + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val -@pytest.mark.parametrize( - "transport_class", - [ - transports.ModelServiceGrpcTransport, - transports.ModelServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_model_service_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", + +def test_get_model_evaluation_slice_flattened_error(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_model_evaluation_slice( + model_service.GetModelEvaluationSliceRequest(), + name="name_value", ) -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.ModelServiceGrpcTransport, grpc_helpers), - (transports.ModelServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_gte_1_26_0 -def test_model_service_transport_create_channel(transport_class, grpc_helpers): - # If credentials and host are not provided, the transport class should use - # ADC credentials. +@pytest.mark.asyncio +async def test_get_model_evaluation_slice_flattened_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class(quota_project_id="octopus", scopes=["1", "2"]) + type(client.transport.get_model_evaluation_slice), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = model_evaluation_slice.ModelEvaluationSlice() - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - default_scopes=("https://www.googleapis.com/auth/cloud-platform",), - scopes=["1", "2"], - default_host="aiplatform.googleapis.com", - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + model_evaluation_slice.ModelEvaluationSlice() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_model_evaluation_slice( + name="name_value", ) + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.ModelServiceGrpcTransport, grpc_helpers), - (transports.ModelServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_model_service_transport_create_channel_old_api_core( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class(quota_project_id="octopus") +@pytest.mark.asyncio +async def test_get_model_evaluation_slice_flattened_error_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_model_evaluation_slice( + model_service.GetModelEvaluationSliceRequest(), + name="name_value", ) @pytest.mark.parametrize( - "transport_class,grpc_helpers", + "request_type", [ - (transports.ModelServiceGrpcTransport, grpc_helpers), - (transports.ModelServiceGrpcAsyncIOTransport, grpc_helpers_async), + model_service.ListModelEvaluationSlicesRequest, + dict, ], ) -@requires_api_core_lt_1_26_0 -def test_model_service_transport_create_channel_user_scopes( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) +def test_list_model_evaluation_slices(request_type, transport: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) - transport_class(quota_project_id="octopus", scopes=["1", "2"]) + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluation_slices), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = model_service.ListModelEvaluationSlicesResponse( + next_page_token="next_page_token_value", + ) + response = client.list_model_evaluation_slices(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.ListModelEvaluationSlicesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListModelEvaluationSlicesPager) + assert response.next_page_token == "next_page_token_value" + + +def test_list_model_evaluation_slices_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluation_slices), "__call__" + ) as call: + client.list_model_evaluation_slices() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.ListModelEvaluationSlicesRequest() + + +@pytest.mark.asyncio +async def test_list_model_evaluation_slices_async( + transport: str = "grpc_asyncio", + request_type=model_service.ListModelEvaluationSlicesRequest, +): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluation_slices), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + model_service.ListModelEvaluationSlicesResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.list_model_evaluation_slices(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.ListModelEvaluationSlicesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListModelEvaluationSlicesAsyncPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_list_model_evaluation_slices_async_from_dict(): + await test_list_model_evaluation_slices_async(request_type=dict) + + +def test_list_model_evaluation_slices_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = model_service.ListModelEvaluationSlicesRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluation_slices), "__call__" + ) as call: + call.return_value = model_service.ListModelEvaluationSlicesResponse() + client.list_model_evaluation_slices(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_model_evaluation_slices_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = model_service.ListModelEvaluationSlicesRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluation_slices), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + model_service.ListModelEvaluationSlicesResponse() + ) + await client.list_model_evaluation_slices(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_list_model_evaluation_slices_flattened(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluation_slices), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = model_service.ListModelEvaluationSlicesResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_model_evaluation_slices( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +def test_list_model_evaluation_slices_flattened_error(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_model_evaluation_slices( + model_service.ListModelEvaluationSlicesRequest(), + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_model_evaluation_slices_flattened_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluation_slices), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = model_service.ListModelEvaluationSlicesResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + model_service.ListModelEvaluationSlicesResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_model_evaluation_slices( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_list_model_evaluation_slices_flattened_error_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_model_evaluation_slices( + model_service.ListModelEvaluationSlicesRequest(), + parent="parent_value", + ) + + +def test_list_model_evaluation_slices_pager(transport_name: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluation_slices), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + model_service.ListModelEvaluationSlicesResponse( + model_evaluation_slices=[ + model_evaluation_slice.ModelEvaluationSlice(), + model_evaluation_slice.ModelEvaluationSlice(), + model_evaluation_slice.ModelEvaluationSlice(), + ], + next_page_token="abc", + ), + model_service.ListModelEvaluationSlicesResponse( + model_evaluation_slices=[], + next_page_token="def", + ), + model_service.ListModelEvaluationSlicesResponse( + model_evaluation_slices=[ + model_evaluation_slice.ModelEvaluationSlice(), + ], + next_page_token="ghi", + ), + model_service.ListModelEvaluationSlicesResponse( + model_evaluation_slices=[ + model_evaluation_slice.ModelEvaluationSlice(), + model_evaluation_slice.ModelEvaluationSlice(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_model_evaluation_slices(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all( + isinstance(i, model_evaluation_slice.ModelEvaluationSlice) for i in results + ) + + +def test_list_model_evaluation_slices_pages(transport_name: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluation_slices), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + model_service.ListModelEvaluationSlicesResponse( + model_evaluation_slices=[ + model_evaluation_slice.ModelEvaluationSlice(), + model_evaluation_slice.ModelEvaluationSlice(), + model_evaluation_slice.ModelEvaluationSlice(), + ], + next_page_token="abc", + ), + model_service.ListModelEvaluationSlicesResponse( + model_evaluation_slices=[], + next_page_token="def", + ), + model_service.ListModelEvaluationSlicesResponse( + model_evaluation_slices=[ + model_evaluation_slice.ModelEvaluationSlice(), + ], + next_page_token="ghi", + ), + model_service.ListModelEvaluationSlicesResponse( + model_evaluation_slices=[ + model_evaluation_slice.ModelEvaluationSlice(), + model_evaluation_slice.ModelEvaluationSlice(), + ], + ), + RuntimeError, + ) + pages = list(client.list_model_evaluation_slices(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.asyncio +async def test_list_model_evaluation_slices_async_pager(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluation_slices), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + model_service.ListModelEvaluationSlicesResponse( + model_evaluation_slices=[ + model_evaluation_slice.ModelEvaluationSlice(), + model_evaluation_slice.ModelEvaluationSlice(), + model_evaluation_slice.ModelEvaluationSlice(), + ], + next_page_token="abc", + ), + model_service.ListModelEvaluationSlicesResponse( + model_evaluation_slices=[], + next_page_token="def", + ), + model_service.ListModelEvaluationSlicesResponse( + model_evaluation_slices=[ + model_evaluation_slice.ModelEvaluationSlice(), + ], + next_page_token="ghi", + ), + model_service.ListModelEvaluationSlicesResponse( + model_evaluation_slices=[ + model_evaluation_slice.ModelEvaluationSlice(), + model_evaluation_slice.ModelEvaluationSlice(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_model_evaluation_slices( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all( + isinstance(i, model_evaluation_slice.ModelEvaluationSlice) + for i in responses + ) + + +@pytest.mark.asyncio +async def test_list_model_evaluation_slices_async_pages(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluation_slices), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + model_service.ListModelEvaluationSlicesResponse( + model_evaluation_slices=[ + model_evaluation_slice.ModelEvaluationSlice(), + model_evaluation_slice.ModelEvaluationSlice(), + model_evaluation_slice.ModelEvaluationSlice(), + ], + next_page_token="abc", + ), + model_service.ListModelEvaluationSlicesResponse( + model_evaluation_slices=[], + next_page_token="def", + ), + model_service.ListModelEvaluationSlicesResponse( + model_evaluation_slices=[ + model_evaluation_slice.ModelEvaluationSlice(), + ], + next_page_token="ghi", + ), + model_service.ListModelEvaluationSlicesResponse( + model_evaluation_slices=[ + model_evaluation_slice.ModelEvaluationSlice(), + model_evaluation_slice.ModelEvaluationSlice(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.list_model_evaluation_slices(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.ModelServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.ModelServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ModelServiceClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide an api_key and a transport instance. + transport = transports.ModelServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = ModelServiceClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = ModelServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.ModelServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ModelServiceClient( + client_options={"scopes": ["1", "2"]}, + transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.ModelServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + client = ModelServiceClient(transport=transport) + assert client.transport is transport + + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.ModelServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.ModelServiceGrpcAsyncIOTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.ModelServiceGrpcTransport, + transports.ModelServiceGrpcAsyncIOTransport, + ], +) +def test_transport_adc(transport_class): + # Test default credentials are used if not provided. + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class() + adc.assert_called_once() + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = ModelServiceClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + +def test_transport_grpc_default(): + # A client should use the gRPC transport by default. + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.ModelServiceGrpcTransport, + ) + + +def test_model_service_base_transport_error(): + # Passing both a credentials object and credentials_file should raise an error + with pytest.raises(core_exceptions.DuplicateCredentialArgs): + transport = transports.ModelServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + credentials_file="credentials.json", + ) + + +def test_model_service_base_transport(): + # Instantiate the base transport. + with mock.patch( + "google.cloud.aiplatform_v1.services.model_service.transports.ModelServiceTransport.__init__" + ) as Transport: + Transport.return_value = None + transport = transports.ModelServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Every method on the transport should just blindly + # raise NotImplementedError. + methods = ( + "upload_model", + "get_model", + "list_models", + "list_model_versions", + "update_model", + "delete_model", + "delete_model_version", + "merge_version_aliases", + "export_model", + "import_model_evaluation", + "get_model_evaluation", + "list_model_evaluations", + "get_model_evaluation_slice", + "list_model_evaluation_slices", + "set_iam_policy", + "get_iam_policy", + "test_iam_permissions", + "get_location", + "list_locations", + "get_operation", + "wait_operation", + "cancel_operation", + "delete_operation", + "list_operations", + ) + for method in methods: + with pytest.raises(NotImplementedError): + getattr(transport, method)(request=object()) + + with pytest.raises(NotImplementedError): + transport.close() + + # Additionally, the LRO client (a property) should + # also raise NotImplementedError + with pytest.raises(NotImplementedError): + transport.operations_client + + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + + +def test_model_service_base_transport_with_credentials_file(): + # Instantiate the base transport with a credentials file + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch( + "google.cloud.aiplatform_v1.services.model_service.transports.ModelServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ModelServiceTransport( + credentials_file="credentials.json", + quota_project_id="octopus", + ) + load_creds.assert_called_once_with( + "credentials.json", + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +def test_model_service_base_transport_with_adc(): + # Test the default credentials are used if credentials and credentials_file are None. + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( + "google.cloud.aiplatform_v1.services.model_service.transports.ModelServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ModelServiceTransport() + adc.assert_called_once() + + +def test_model_service_auth_adc(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + ModelServiceClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id=None, + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.ModelServiceGrpcTransport, + transports.ModelServiceGrpcAsyncIOTransport, + ], +) +def test_model_service_transport_auth_adc(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.ModelServiceGrpcTransport, grpc_helpers), + (transports.ModelServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +def test_model_service_transport_create_channel(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=creds, + credentials_file=None, quota_project_id="octopus", + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), scopes=["1", "2"], + default_host="aiplatform.googleapis.com", ssl_credentials=None, options=[ ("grpc.max_send_message_length", -1), @@ -3486,458 +5366,2086 @@ def test_model_service_transport_create_channel_user_scopes( ) -@pytest.mark.parametrize( - "transport_class", - [transports.ModelServiceGrpcTransport, transports.ModelServiceGrpcAsyncIOTransport], -) -def test_model_service_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() +@pytest.mark.parametrize( + "transport_class", + [transports.ModelServiceGrpcTransport, transports.ModelServiceGrpcAsyncIOTransport], +) +def test_model_service_grpc_transport_client_cert_source_for_mtls(transport_class): + cred = ga_credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds, + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback, + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, private_key=expected_key + ) + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_model_service_host_no_port(transport_name): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions( + api_endpoint="aiplatform.googleapis.com" + ), + transport=transport_name, + ) + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_model_service_host_with_port(transport_name): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions( + api_endpoint="aiplatform.googleapis.com:8000" + ), + transport=transport_name, + ) + assert client.transport._host == ("aiplatform.googleapis.com:8000") + + +def test_model_service_grpc_transport_channel(): + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.ModelServiceGrpcTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +def test_model_service_grpc_asyncio_transport_channel(): + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.ModelServiceGrpcAsyncIOTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize( + "transport_class", + [transports.ModelServiceGrpcTransport, transports.ModelServiceGrpcAsyncIOTransport], +) +def test_model_service_transport_channel_mtls_with_client_cert_source(transport_class): + with mock.patch( + "grpc.ssl_channel_credentials", autospec=True + ) as grpc_ssl_channel_cred: + with mock.patch.object( + transport_class, "create_channel" + ) as grpc_create_channel: + mock_ssl_cred = mock.Mock() + grpc_ssl_channel_cred.return_value = mock_ssl_cred + + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + + cred = ga_credentials.AnonymousCredentials() + with pytest.warns(DeprecationWarning): + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (cred, None) + transport = transport_class( + host="squid.clam.whelk", + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=client_cert_source_callback, + ) + adc.assert_called_once() + + grpc_ssl_channel_cred.assert_called_once_with( + certificate_chain=b"cert bytes", private_key=b"key bytes" + ) + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize( + "transport_class", + [transports.ModelServiceGrpcTransport, transports.ModelServiceGrpcAsyncIOTransport], +) +def test_model_service_transport_channel_mtls_with_adc(transport_class): + mock_ssl_cred = mock.Mock() + with mock.patch.multiple( + "google.auth.transport.grpc.SslCredentials", + __init__=mock.Mock(return_value=None), + ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), + ): + with mock.patch.object( + transport_class, "create_channel" + ) as grpc_create_channel: + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + mock_cred = mock.Mock() + + with pytest.warns(DeprecationWarning): + transport = transport_class( + host="squid.clam.whelk", + credentials=mock_cred, + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=None, + ) + + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=mock_cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + + +def test_model_service_grpc_lro_client(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_model_service_grpc_lro_async_client(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_endpoint_path(): + project = "squid" + location = "clam" + endpoint = "whelk" + expected = "projects/{project}/locations/{location}/endpoints/{endpoint}".format( + project=project, + location=location, + endpoint=endpoint, + ) + actual = ModelServiceClient.endpoint_path(project, location, endpoint) + assert expected == actual + + +def test_parse_endpoint_path(): + expected = { + "project": "octopus", + "location": "oyster", + "endpoint": "nudibranch", + } + path = ModelServiceClient.endpoint_path(**expected) + + # Check that the path construction is reversible. + actual = ModelServiceClient.parse_endpoint_path(path) + assert expected == actual + + +def test_model_path(): + project = "cuttlefish" + location = "mussel" + model = "winkle" + expected = "projects/{project}/locations/{location}/models/{model}".format( + project=project, + location=location, + model=model, + ) + actual = ModelServiceClient.model_path(project, location, model) + assert expected == actual + + +def test_parse_model_path(): + expected = { + "project": "nautilus", + "location": "scallop", + "model": "abalone", + } + path = ModelServiceClient.model_path(**expected) + + # Check that the path construction is reversible. + actual = ModelServiceClient.parse_model_path(path) + assert expected == actual + + +def test_model_evaluation_path(): + project = "squid" + location = "clam" + model = "whelk" + evaluation = "octopus" + expected = "projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}".format( + project=project, + location=location, + model=model, + evaluation=evaluation, + ) + actual = ModelServiceClient.model_evaluation_path( + project, location, model, evaluation + ) + assert expected == actual + + +def test_parse_model_evaluation_path(): + expected = { + "project": "oyster", + "location": "nudibranch", + "model": "cuttlefish", + "evaluation": "mussel", + } + path = ModelServiceClient.model_evaluation_path(**expected) + + # Check that the path construction is reversible. + actual = ModelServiceClient.parse_model_evaluation_path(path) + assert expected == actual + + +def test_model_evaluation_slice_path(): + project = "winkle" + location = "nautilus" + model = "scallop" + evaluation = "abalone" + slice = "squid" + expected = "projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}/slices/{slice}".format( + project=project, + location=location, + model=model, + evaluation=evaluation, + slice=slice, + ) + actual = ModelServiceClient.model_evaluation_slice_path( + project, location, model, evaluation, slice + ) + assert expected == actual + + +def test_parse_model_evaluation_slice_path(): + expected = { + "project": "clam", + "location": "whelk", + "model": "octopus", + "evaluation": "oyster", + "slice": "nudibranch", + } + path = ModelServiceClient.model_evaluation_slice_path(**expected) + + # Check that the path construction is reversible. + actual = ModelServiceClient.parse_model_evaluation_slice_path(path) + assert expected == actual + + +def test_training_pipeline_path(): + project = "cuttlefish" + location = "mussel" + training_pipeline = "winkle" + expected = "projects/{project}/locations/{location}/trainingPipelines/{training_pipeline}".format( + project=project, + location=location, + training_pipeline=training_pipeline, + ) + actual = ModelServiceClient.training_pipeline_path( + project, location, training_pipeline + ) + assert expected == actual + + +def test_parse_training_pipeline_path(): + expected = { + "project": "nautilus", + "location": "scallop", + "training_pipeline": "abalone", + } + path = ModelServiceClient.training_pipeline_path(**expected) + + # Check that the path construction is reversible. + actual = ModelServiceClient.parse_training_pipeline_path(path) + assert expected == actual + + +def test_common_billing_account_path(): + billing_account = "squid" + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + actual = ModelServiceClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "clam", + } + path = ModelServiceClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = ModelServiceClient.parse_common_billing_account_path(path) + assert expected == actual + + +def test_common_folder_path(): + folder = "whelk" + expected = "folders/{folder}".format( + folder=folder, + ) + actual = ModelServiceClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "octopus", + } + path = ModelServiceClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = ModelServiceClient.parse_common_folder_path(path) + assert expected == actual + + +def test_common_organization_path(): + organization = "oyster" + expected = "organizations/{organization}".format( + organization=organization, + ) + actual = ModelServiceClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "nudibranch", + } + path = ModelServiceClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = ModelServiceClient.parse_common_organization_path(path) + assert expected == actual + + +def test_common_project_path(): + project = "cuttlefish" + expected = "projects/{project}".format( + project=project, + ) + actual = ModelServiceClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "mussel", + } + path = ModelServiceClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = ModelServiceClient.parse_common_project_path(path) + assert expected == actual + + +def test_common_location_path(): + project = "winkle" + location = "nautilus" + expected = "projects/{project}/locations/{location}".format( + project=project, + location=location, + ) + actual = ModelServiceClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "scallop", + "location": "abalone", + } + path = ModelServiceClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = ModelServiceClient.parse_common_location_path(path) + assert expected == actual + + +def test_client_with_default_client_info(): + client_info = gapic_v1.client_info.ClientInfo() + + with mock.patch.object( + transports.ModelServiceTransport, "_prep_wrapped_messages" + ) as prep: + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + with mock.patch.object( + transports.ModelServiceTransport, "_prep_wrapped_messages" + ) as prep: + transport_class = ModelServiceClient.get_transport_class() + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_delete_operation(transport: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_operation(transport: str = "grpc"): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_operation_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = None + + client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_operation_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_delete_operation_from_dict(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_delete_operation_from_dict_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_cancel_operation(transport: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation(transport: str = "grpc"): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_wait_operation(transport: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_wait_operation(transport: str = "grpc"): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_wait_operation_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_wait_operation_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_wait_operation_from_dict(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_wait_operation_from_dict_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_operation(transport: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_get_operation(transport: str = "grpc"): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_get_operation_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_get_operation_from_dict(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_operations(transport: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + response = client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +@pytest.mark.asyncio +async def test_list_operations(transport: str = "grpc"): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +def test_list_operations_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_operations_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_operations_from_dict(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + response = client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_operations_from_dict_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_locations(transport: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + response = client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +@pytest.mark.asyncio +async def test_list_locations(transport: str = "grpc"): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + - # Check ssl_channel_credentials is used if provided. - with mock.patch.object(transport_class, "create_channel") as mock_create_channel: - mock_ssl_channel_creds = mock.Mock() - transport_class( - host="squid.clam.whelk", - credentials=cred, - ssl_channel_credentials=mock_ssl_channel_creds, +def test_list_locations_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_locations_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() ) - mock_create_channel.assert_called_once_with( - "squid.clam.whelk:443", - credentials=cred, - credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=mock_ssl_channel_creds, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], + await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_locations_from_dict(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + response = client.list_locations( + request={ + "name": "locations", + } ) + call.assert_called() - # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls - # is used. - with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): - with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: - transport_class( - credentials=cred, - client_cert_source_for_mtls=client_cert_source_callback, - ) - expected_cert, expected_key = client_cert_source_callback() - mock_ssl_cred.assert_called_once_with( - certificate_chain=expected_cert, private_key=expected_key + +@pytest.mark.asyncio +async def test_list_locations_from_dict_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_location(transport: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + response = client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +@pytest.mark.asyncio +async def test_get_location_async(transport: str = "grpc_asyncio"): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +def test_get_location_field_headers(): + client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials()) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = locations_pb2.Location() + + client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_location_field_headers_async(): + client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials()) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +def test_get_location_from_dict(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + response = client.get_location( + request={ + "name": "locations/abc", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_location_from_dict_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_set_iam_policy(transport: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + response = client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", ) + ) + response = await client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_set_iam_policy_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] -def test_model_service_host_no_port(): - client = ModelServiceClient( +@pytest.mark.asyncio +async def test_set_iam_policy_field_headers_async(): + client = ModelServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions( - api_endpoint="aiplatform.googleapis.com" - ), ) - assert client.transport._host == "aiplatform.googleapis.com:443" + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy(request) -def test_model_service_host_with_port(): + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_set_iam_policy_from_dict(): client = ModelServiceClient( credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions( - api_endpoint="aiplatform.googleapis.com:8000" - ), ) - assert client.transport._host == "aiplatform.googleapis.com:8000" + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + response = client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() -def test_model_service_grpc_transport_channel(): - channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) - # Check that channel is used if provided. - transport = transports.ModelServiceGrpcTransport( - host="squid.clam.whelk", channel=channel, +@pytest.mark.asyncio +async def test_set_iam_policy_from_dict_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), ) - assert transport.grpc_channel == channel - assert transport._host == "squid.clam.whelk:443" - assert transport._ssl_channel_credentials == None + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + response = await client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() -def test_model_service_grpc_asyncio_transport_channel(): - channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) - # Check that channel is used if provided. - transport = transports.ModelServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", channel=channel, +def test_get_iam_policy(transport: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - assert transport.grpc_channel == channel - assert transport._host == "squid.clam.whelk:443" - assert transport._ssl_channel_credentials == None + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() -# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are -# removed from grpc/grpc_asyncio transport constructor. -@pytest.mark.parametrize( - "transport_class", - [transports.ModelServiceGrpcTransport, transports.ModelServiceGrpcAsyncIOTransport], -) -def test_model_service_transport_channel_mtls_with_client_cert_source(transport_class): - with mock.patch( - "grpc.ssl_channel_credentials", autospec=True - ) as grpc_ssl_channel_cred: - with mock.patch.object( - transport_class, "create_channel" - ) as grpc_create_channel: - mock_ssl_cred = mock.Mock() - grpc_ssl_channel_cred.return_value = mock_ssl_cred + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel + response = client.get_iam_policy(request) - cred = ga_credentials.AnonymousCredentials() - with pytest.warns(DeprecationWarning): - with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (cred, None) - transport = transport_class( - host="squid.clam.whelk", - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=client_cert_source_callback, - ) - adc.assert_called_once() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] - grpc_ssl_channel_cred.assert_called_once_with( - certificate_chain=b"cert bytes", private_key=b"key bytes" - ) - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=cred, - credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - assert transport.grpc_channel == mock_grpc_channel - assert transport._ssl_channel_credentials == mock_ssl_cred + assert args[0] == request + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) -# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are -# removed from grpc/grpc_asyncio transport constructor. -@pytest.mark.parametrize( - "transport_class", - [transports.ModelServiceGrpcTransport, transports.ModelServiceGrpcAsyncIOTransport], -) -def test_model_service_transport_channel_mtls_with_adc(transport_class): - mock_ssl_cred = mock.Mock() - with mock.patch.multiple( - "google.auth.transport.grpc.SslCredentials", - __init__=mock.Mock(return_value=None), - ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), - ): - with mock.patch.object( - transport_class, "create_channel" - ) as grpc_create_channel: - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel - mock_cred = mock.Mock() + assert response.version == 774 - with pytest.warns(DeprecationWarning): - transport = transport_class( - host="squid.clam.whelk", - credentials=mock_cred, - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=None, - ) + assert response.etag == b"etag_blob" - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=mock_cred, - credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], + +@pytest.mark.asyncio +async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", ) - assert transport.grpc_channel == mock_grpc_channel + ) + response = await client.get_iam_policy(request) -def test_model_service_grpc_lro_client(): - client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", - ) - transport = client.transport + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] - # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsClient,) + assert args[0] == request - # Ensure that subsequent calls to the property send the exact same object. - assert transport.operations_client is transport.operations_client + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + assert response.version == 774 -def test_model_service_grpc_lro_async_client(): - client = ModelServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + assert response.etag == b"etag_blob" + + +def test_get_iam_policy_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), ) - transport = client.transport - # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient,) + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" - # Ensure that subsequent calls to the property send the exact same object. - assert transport.operations_client is transport.operations_client + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + client.get_iam_policy(request) -def test_endpoint_path(): - project = "squid" - location = "clam" - endpoint = "whelk" - expected = "projects/{project}/locations/{location}/endpoints/{endpoint}".format( - project=project, location=location, endpoint=endpoint, + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_iam_policy_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), ) - actual = ModelServiceClient.endpoint_path(project, location, endpoint) - assert expected == actual + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" -def test_parse_endpoint_path(): - expected = { - "project": "octopus", - "location": "oyster", - "endpoint": "nudibranch", - } - path = ModelServiceClient.endpoint_path(**expected) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) - # Check that the path construction is reversible. - actual = ModelServiceClient.parse_endpoint_path(path) - assert expected == actual + await client.get_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request -def test_model_path(): - project = "cuttlefish" - location = "mussel" - model = "winkle" - expected = "projects/{project}/locations/{location}/models/{model}".format( - project=project, location=location, model=model, + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_get_iam_policy_from_dict(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), ) - actual = ModelServiceClient.model_path(project, location, model) - assert expected == actual + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + response = client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() -def test_parse_model_path(): - expected = { - "project": "nautilus", - "location": "scallop", - "model": "abalone", - } - path = ModelServiceClient.model_path(**expected) - # Check that the path construction is reversible. - actual = ModelServiceClient.parse_model_path(path) - assert expected == actual +@pytest.mark.asyncio +async def test_get_iam_policy_from_dict_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() -def test_model_evaluation_path(): - project = "squid" - location = "clam" - model = "whelk" - evaluation = "octopus" - expected = "projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}".format( - project=project, location=location, model=model, evaluation=evaluation, - ) - actual = ModelServiceClient.model_evaluation_path( - project, location, model, evaluation +def test_test_iam_permissions(transport: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - assert expected == actual + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() -def test_parse_model_evaluation_path(): - expected = { - "project": "oyster", - "location": "nudibranch", - "model": "cuttlefish", - "evaluation": "mussel", - } - path = ModelServiceClient.model_evaluation_path(**expected) - - # Check that the path construction is reversible. - actual = ModelServiceClient.parse_model_evaluation_path(path) - assert expected == actual + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + response = client.test_iam_permissions(request) -def test_model_evaluation_slice_path(): - project = "winkle" - location = "nautilus" - model = "scallop" - evaluation = "abalone" - slice = "squid" - expected = "projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}/slices/{slice}".format( - project=project, - location=location, - model=model, - evaluation=evaluation, - slice=slice, - ) - actual = ModelServiceClient.model_evaluation_slice_path( - project, location, model, evaluation, slice - ) - assert expected == actual + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request -def test_parse_model_evaluation_slice_path(): - expected = { - "project": "clam", - "location": "whelk", - "model": "octopus", - "evaluation": "oyster", - "slice": "nudibranch", - } - path = ModelServiceClient.model_evaluation_slice_path(**expected) + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) - # Check that the path construction is reversible. - actual = ModelServiceClient.parse_model_evaluation_slice_path(path) - assert expected == actual + assert response.permissions == ["permissions_value"] -def test_training_pipeline_path(): - project = "cuttlefish" - location = "mussel" - training_pipeline = "winkle" - expected = "projects/{project}/locations/{location}/trainingPipelines/{training_pipeline}".format( - project=project, location=location, training_pipeline=training_pipeline, - ) - actual = ModelServiceClient.training_pipeline_path( - project, location, training_pipeline +@pytest.mark.asyncio +async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - assert expected == actual + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() -def test_parse_training_pipeline_path(): - expected = { - "project": "nautilus", - "location": "scallop", - "training_pipeline": "abalone", - } - path = ModelServiceClient.training_pipeline_path(**expected) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + ) - # Check that the path construction is reversible. - actual = ModelServiceClient.parse_training_pipeline_path(path) - assert expected == actual + response = await client.test_iam_permissions(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] -def test_common_billing_account_path(): - billing_account = "squid" - expected = "billingAccounts/{billing_account}".format( - billing_account=billing_account, - ) - actual = ModelServiceClient.common_billing_account_path(billing_account) - assert expected == actual + assert args[0] == request + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) -def test_parse_common_billing_account_path(): - expected = { - "billing_account": "clam", - } - path = ModelServiceClient.common_billing_account_path(**expected) + assert response.permissions == ["permissions_value"] - # Check that the path construction is reversible. - actual = ModelServiceClient.parse_common_billing_account_path(path) - assert expected == actual +def test_test_iam_permissions_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" -def test_common_folder_path(): - folder = "whelk" - expected = "folders/{folder}".format(folder=folder,) - actual = ModelServiceClient.common_folder_path(folder) - assert expected == actual + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + client.test_iam_permissions(request) -def test_parse_common_folder_path(): - expected = { - "folder": "octopus", - } - path = ModelServiceClient.common_folder_path(**expected) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request - # Check that the path construction is reversible. - actual = ModelServiceClient.parse_common_folder_path(path) - assert expected == actual + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] -def test_common_organization_path(): - organization = "oyster" - expected = "organizations/{organization}".format(organization=organization,) - actual = ModelServiceClient.common_organization_path(organization) - assert expected == actual +@pytest.mark.asyncio +async def test_test_iam_permissions_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" -def test_parse_common_organization_path(): - expected = { - "organization": "nudibranch", - } - path = ModelServiceClient.common_organization_path(**expected) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) - # Check that the path construction is reversible. - actual = ModelServiceClient.parse_common_organization_path(path) - assert expected == actual + await client.test_iam_permissions(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request -def test_common_project_path(): - project = "cuttlefish" - expected = "projects/{project}".format(project=project,) - actual = ModelServiceClient.common_project_path(project) - assert expected == actual + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] -def test_parse_common_project_path(): - expected = { - "project": "mussel", - } - path = ModelServiceClient.common_project_path(**expected) +def test_test_iam_permissions_from_dict(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() - # Check that the path construction is reversible. - actual = ModelServiceClient.parse_common_project_path(path) - assert expected == actual + response = client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() -def test_common_location_path(): - project = "winkle" - location = "nautilus" - expected = "projects/{project}/locations/{location}".format( - project=project, location=location, +@pytest.mark.asyncio +async def test_test_iam_permissions_from_dict_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), ) - actual = ModelServiceClient.common_location_path(project, location) - assert expected == actual + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + response = await client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() -def test_parse_common_location_path(): - expected = { - "project": "scallop", - "location": "abalone", - } - path = ModelServiceClient.common_location_path(**expected) - # Check that the path construction is reversible. - actual = ModelServiceClient.parse_common_location_path(path) - assert expected == actual +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + for transport, close_name in transports.items(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() -def test_client_withDEFAULT_CLIENT_INFO(): - client_info = gapic_v1.client_info.ClientInfo() - with mock.patch.object( - transports.ModelServiceTransport, "_prep_wrapped_messages" - ) as prep: +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), transport=transport ) - prep.assert_called_once_with(client_info) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (ModelServiceClient, transports.ModelServiceGrpcTransport), + (ModelServiceAsyncClient, transports.ModelServiceGrpcAsyncIOTransport), + ], +) +def test_api_key_credentials(client_class, transport_class): with mock.patch.object( - transports.ModelServiceTransport, "_prep_wrapped_messages" - ) as prep: - transport_class = ModelServiceClient.get_transport_class() - transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, - ) - prep.assert_called_once_with(client_info) + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) diff --git a/tests/unit/gapic/aiplatform_v1/test_pipeline_service.py b/tests/unit/gapic/aiplatform_v1/test_pipeline_service.py index e1cac311f2..85fd99a677 100644 --- a/tests/unit/gapic/aiplatform_v1/test_pipeline_service.py +++ b/tests/unit/gapic/aiplatform_v1/test_pipeline_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,8 +14,13 @@ # limitations under the License. # import os -import mock -import packaging.version + +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock +except ImportError: + import mock import grpc from grpc.experimental import aio @@ -30,8 +35,10 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.aiplatform_v1.services.pipeline_service import ( @@ -40,22 +47,29 @@ from google.cloud.aiplatform_v1.services.pipeline_service import PipelineServiceClient from google.cloud.aiplatform_v1.services.pipeline_service import pagers from google.cloud.aiplatform_v1.services.pipeline_service import transports -from google.cloud.aiplatform_v1.services.pipeline_service.transports.base import ( - _API_CORE_VERSION, -) -from google.cloud.aiplatform_v1.services.pipeline_service.transports.base import ( - _GOOGLE_AUTH_VERSION, -) +from google.cloud.aiplatform_v1.types import artifact +from google.cloud.aiplatform_v1.types import context from google.cloud.aiplatform_v1.types import deployed_model_ref from google.cloud.aiplatform_v1.types import encryption_spec from google.cloud.aiplatform_v1.types import env_var +from google.cloud.aiplatform_v1.types import execution +from google.cloud.aiplatform_v1.types import explanation +from google.cloud.aiplatform_v1.types import explanation_metadata from google.cloud.aiplatform_v1.types import io from google.cloud.aiplatform_v1.types import model from google.cloud.aiplatform_v1.types import operation as gca_operation +from google.cloud.aiplatform_v1.types import pipeline_failure_policy +from google.cloud.aiplatform_v1.types import pipeline_job +from google.cloud.aiplatform_v1.types import pipeline_job as gca_pipeline_job from google.cloud.aiplatform_v1.types import pipeline_service from google.cloud.aiplatform_v1.types import pipeline_state from google.cloud.aiplatform_v1.types import training_pipeline from google.cloud.aiplatform_v1.types import training_pipeline as gca_training_pipeline +from google.cloud.aiplatform_v1.types import value +from google.cloud.location import locations_pb2 +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 from google.oauth2 import service_account from google.protobuf import any_pb2 # type: ignore @@ -66,29 +80,6 @@ import google.auth -# TODO(busunkim): Once google-api-core >= 1.26.0 is required: -# - Delete all the api-core and auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - -requires_api_core_lt_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), - reason="This test requires google-api-core < 1.26.0", -) - -requires_api_core_gte_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), - reason="This test requires google-api-core >= 1.26.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -134,40 +125,81 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( - "client_class", [PipelineServiceClient, PipelineServiceAsyncClient,] + "client_class,transport_name", + [ + (PipelineServiceClient, "grpc"), + (PipelineServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_pipeline_service_client_from_service_account_info(client_class): +def test_pipeline_service_client_from_service_account_info( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.PipelineServiceGrpcTransport, "grpc"), + (transports.PipelineServiceGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_pipeline_service_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() @pytest.mark.parametrize( - "client_class", [PipelineServiceClient, PipelineServiceAsyncClient,] + "client_class,transport_name", + [ + (PipelineServiceClient, "grpc"), + (PipelineServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_pipeline_service_client_from_service_account_file(client_class): +def test_pipeline_service_client_from_service_account_file( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") def test_pipeline_service_client_get_transport_class(): @@ -220,7 +252,7 @@ def test_pipeline_service_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -229,6 +261,7 @@ def test_pipeline_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -236,7 +269,7 @@ def test_pipeline_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -245,6 +278,7 @@ def test_pipeline_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -252,7 +286,7 @@ def test_pipeline_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -261,26 +295,27 @@ def test_pipeline_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -289,6 +324,7 @@ def test_pipeline_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -348,7 +384,7 @@ def test_pipeline_service_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -365,6 +401,7 @@ def test_pipeline_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case ADC client cert is provided. Whether client cert is used depends on @@ -389,7 +426,7 @@ def test_pipeline_service_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -398,6 +435,7 @@ def test_pipeline_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case client_cert_source and ADC client cert are not provided. @@ -410,7 +448,7 @@ def test_pipeline_service_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -419,9 +457,91 @@ def test_pipeline_service_client_mtls_env_auto( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) +@pytest.mark.parametrize( + "client_class", [PipelineServiceClient, PipelineServiceAsyncClient] +) +@mock.patch.object( + PipelineServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(PipelineServiceClient), +) +@mock.patch.object( + PipelineServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(PipelineServiceAsyncClient), +) +def test_pipeline_service_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + @pytest.mark.parametrize( "client_class,transport_class,transport_name", [ @@ -437,10 +557,12 @@ def test_pipeline_service_client_client_options_scopes( client_class, transport_class, transport_name ): # Check the case scopes are provided. - options = client_options.ClientOptions(scopes=["1", "2"],) + options = client_options.ClientOptions( + scopes=["1", "2"], + ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -449,28 +571,36 @@ def test_pipeline_service_client_client_options_scopes( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (PipelineServiceClient, transports.PipelineServiceGrpcTransport, "grpc"), + ( + PipelineServiceClient, + transports.PipelineServiceGrpcTransport, + "grpc", + grpc_helpers, + ), ( PipelineServiceAsyncClient, transports.PipelineServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_pipeline_service_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -479,6 +609,7 @@ def test_pipeline_service_client_client_options_credentials_file( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -498,14 +629,87 @@ def test_pipeline_service_client_client_options_from_dict(): client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) -def test_create_training_pipeline( - transport: str = "grpc", request_type=pipeline_service.CreateTrainingPipelineRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + PipelineServiceClient, + transports.PipelineServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + PipelineServiceAsyncClient, + transports.PipelineServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_pipeline_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers ): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + pipeline_service.CreateTrainingPipelineRequest, + dict, + ], +) +def test_create_training_pipeline(request_type, transport: str = "grpc"): client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -521,6 +725,8 @@ def test_create_training_pipeline( name="name_value", display_name="display_name_value", training_task_definition="training_task_definition_value", + model_id="model_id_value", + parent_model="parent_model_value", state=pipeline_state.PipelineState.PIPELINE_STATE_QUEUED, ) response = client.create_training_pipeline(request) @@ -535,18 +741,17 @@ def test_create_training_pipeline( assert response.name == "name_value" assert response.display_name == "display_name_value" assert response.training_task_definition == "training_task_definition_value" + assert response.model_id == "model_id_value" + assert response.parent_model == "parent_model_value" assert response.state == pipeline_state.PipelineState.PIPELINE_STATE_QUEUED -def test_create_training_pipeline_from_dict(): - test_create_training_pipeline(request_type=dict) - - def test_create_training_pipeline_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -565,7 +770,8 @@ async def test_create_training_pipeline_async( request_type=pipeline_service.CreateTrainingPipelineRequest, ): client = PipelineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -582,6 +788,8 @@ async def test_create_training_pipeline_async( name="name_value", display_name="display_name_value", training_task_definition="training_task_definition_value", + model_id="model_id_value", + parent_model="parent_model_value", state=pipeline_state.PipelineState.PIPELINE_STATE_QUEUED, ) ) @@ -597,6 +805,8 @@ async def test_create_training_pipeline_async( assert response.name == "name_value" assert response.display_name == "display_name_value" assert response.training_task_definition == "training_task_definition_value" + assert response.model_id == "model_id_value" + assert response.parent_model == "parent_model_value" assert response.state == pipeline_state.PipelineState.PIPELINE_STATE_QUEUED @@ -606,13 +816,15 @@ async def test_create_training_pipeline_async_from_dict(): def test_create_training_pipeline_field_headers(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = pipeline_service.CreateTrainingPipelineRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -628,7 +840,10 @@ def test_create_training_pipeline_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -641,7 +856,7 @@ async def test_create_training_pipeline_field_headers_async(): # a field header. Set these to a non-empty value. request = pipeline_service.CreateTrainingPipelineRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -659,11 +874,16 @@ async def test_create_training_pipeline_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_create_training_pipeline_flattened(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -682,14 +902,18 @@ def test_create_training_pipeline_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].training_pipeline == gca_training_pipeline.TrainingPipeline( - name="name_value" - ) + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].training_pipeline + mock_val = gca_training_pipeline.TrainingPipeline(name="name_value") + assert arg == mock_val def test_create_training_pipeline_flattened_error(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -728,10 +952,12 @@ async def test_create_training_pipeline_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].training_pipeline == gca_training_pipeline.TrainingPipeline( - name="name_value" - ) + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].training_pipeline + mock_val = gca_training_pipeline.TrainingPipeline(name="name_value") + assert arg == mock_val @pytest.mark.asyncio @@ -750,11 +976,17 @@ async def test_create_training_pipeline_flattened_error_async(): ) -def test_get_training_pipeline( - transport: str = "grpc", request_type=pipeline_service.GetTrainingPipelineRequest -): +@pytest.mark.parametrize( + "request_type", + [ + pipeline_service.GetTrainingPipelineRequest, + dict, + ], +) +def test_get_training_pipeline(request_type, transport: str = "grpc"): client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -770,6 +1002,8 @@ def test_get_training_pipeline( name="name_value", display_name="display_name_value", training_task_definition="training_task_definition_value", + model_id="model_id_value", + parent_model="parent_model_value", state=pipeline_state.PipelineState.PIPELINE_STATE_QUEUED, ) response = client.get_training_pipeline(request) @@ -784,18 +1018,17 @@ def test_get_training_pipeline( assert response.name == "name_value" assert response.display_name == "display_name_value" assert response.training_task_definition == "training_task_definition_value" + assert response.model_id == "model_id_value" + assert response.parent_model == "parent_model_value" assert response.state == pipeline_state.PipelineState.PIPELINE_STATE_QUEUED -def test_get_training_pipeline_from_dict(): - test_get_training_pipeline(request_type=dict) - - def test_get_training_pipeline_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -814,7 +1047,8 @@ async def test_get_training_pipeline_async( request_type=pipeline_service.GetTrainingPipelineRequest, ): client = PipelineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -831,6 +1065,8 @@ async def test_get_training_pipeline_async( name="name_value", display_name="display_name_value", training_task_definition="training_task_definition_value", + model_id="model_id_value", + parent_model="parent_model_value", state=pipeline_state.PipelineState.PIPELINE_STATE_QUEUED, ) ) @@ -846,6 +1082,8 @@ async def test_get_training_pipeline_async( assert response.name == "name_value" assert response.display_name == "display_name_value" assert response.training_task_definition == "training_task_definition_value" + assert response.model_id == "model_id_value" + assert response.parent_model == "parent_model_value" assert response.state == pipeline_state.PipelineState.PIPELINE_STATE_QUEUED @@ -855,13 +1093,15 @@ async def test_get_training_pipeline_async_from_dict(): def test_get_training_pipeline_field_headers(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = pipeline_service.GetTrainingPipelineRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -877,7 +1117,10 @@ def test_get_training_pipeline_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -890,7 +1133,7 @@ async def test_get_training_pipeline_field_headers_async(): # a field header. Set these to a non-empty value. request = pipeline_service.GetTrainingPipelineRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -908,11 +1151,16 @@ async def test_get_training_pipeline_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_get_training_pipeline_flattened(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -922,23 +1170,30 @@ def test_get_training_pipeline_flattened(): call.return_value = training_pipeline.TrainingPipeline() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_training_pipeline(name="name_value",) + client.get_training_pipeline( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_training_pipeline_flattened_error(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.get_training_pipeline( - pipeline_service.GetTrainingPipelineRequest(), name="name_value", + pipeline_service.GetTrainingPipelineRequest(), + name="name_value", ) @@ -960,13 +1215,17 @@ async def test_get_training_pipeline_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_training_pipeline(name="name_value",) + response = await client.get_training_pipeline( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -979,15 +1238,22 @@ async def test_get_training_pipeline_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.get_training_pipeline( - pipeline_service.GetTrainingPipelineRequest(), name="name_value", + pipeline_service.GetTrainingPipelineRequest(), + name="name_value", ) -def test_list_training_pipelines( - transport: str = "grpc", request_type=pipeline_service.ListTrainingPipelinesRequest -): +@pytest.mark.parametrize( + "request_type", + [ + pipeline_service.ListTrainingPipelinesRequest, + dict, + ], +) +def test_list_training_pipelines(request_type, transport: str = "grpc"): client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1014,15 +1280,12 @@ def test_list_training_pipelines( assert response.next_page_token == "next_page_token_value" -def test_list_training_pipelines_from_dict(): - test_list_training_pipelines(request_type=dict) - - def test_list_training_pipelines_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1041,7 +1304,8 @@ async def test_list_training_pipelines_async( request_type=pipeline_service.ListTrainingPipelinesRequest, ): client = PipelineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1076,13 +1340,15 @@ async def test_list_training_pipelines_async_from_dict(): def test_list_training_pipelines_field_headers(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = pipeline_service.ListTrainingPipelinesRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1098,7 +1364,10 @@ def test_list_training_pipelines_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1111,7 +1380,7 @@ async def test_list_training_pipelines_field_headers_async(): # a field header. Set these to a non-empty value. request = pipeline_service.ListTrainingPipelinesRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1129,11 +1398,16 @@ async def test_list_training_pipelines_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_training_pipelines_flattened(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1143,23 +1417,30 @@ def test_list_training_pipelines_flattened(): call.return_value = pipeline_service.ListTrainingPipelinesResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_training_pipelines(parent="parent_value",) + client.list_training_pipelines( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_training_pipelines_flattened_error(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.list_training_pipelines( - pipeline_service.ListTrainingPipelinesRequest(), parent="parent_value", + pipeline_service.ListTrainingPipelinesRequest(), + parent="parent_value", ) @@ -1181,13 +1462,17 @@ async def test_list_training_pipelines_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_training_pipelines(parent="parent_value",) + response = await client.list_training_pipelines( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1200,12 +1485,16 @@ async def test_list_training_pipelines_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.list_training_pipelines( - pipeline_service.ListTrainingPipelinesRequest(), parent="parent_value", + pipeline_service.ListTrainingPipelinesRequest(), + parent="parent_value", ) -def test_list_training_pipelines_pager(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_training_pipelines_pager(transport_name: str = "grpc"): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1222,10 +1511,13 @@ def test_list_training_pipelines_pager(): next_page_token="abc", ), pipeline_service.ListTrainingPipelinesResponse( - training_pipelines=[], next_page_token="def", + training_pipelines=[], + next_page_token="def", ), pipeline_service.ListTrainingPipelinesResponse( - training_pipelines=[training_pipeline.TrainingPipeline(),], + training_pipelines=[ + training_pipeline.TrainingPipeline(), + ], next_page_token="ghi", ), pipeline_service.ListTrainingPipelinesResponse( @@ -1245,13 +1537,16 @@ def test_list_training_pipelines_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all(isinstance(i, training_pipeline.TrainingPipeline) for i in results) -def test_list_training_pipelines_pages(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_training_pipelines_pages(transport_name: str = "grpc"): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1268,10 +1563,13 @@ def test_list_training_pipelines_pages(): next_page_token="abc", ), pipeline_service.ListTrainingPipelinesResponse( - training_pipelines=[], next_page_token="def", + training_pipelines=[], + next_page_token="def", ), pipeline_service.ListTrainingPipelinesResponse( - training_pipelines=[training_pipeline.TrainingPipeline(),], + training_pipelines=[ + training_pipeline.TrainingPipeline(), + ], next_page_token="ghi", ), pipeline_service.ListTrainingPipelinesResponse( @@ -1310,10 +1608,13 @@ async def test_list_training_pipelines_async_pager(): next_page_token="abc", ), pipeline_service.ListTrainingPipelinesResponse( - training_pipelines=[], next_page_token="def", + training_pipelines=[], + next_page_token="def", ), pipeline_service.ListTrainingPipelinesResponse( - training_pipelines=[training_pipeline.TrainingPipeline(),], + training_pipelines=[ + training_pipeline.TrainingPipeline(), + ], next_page_token="ghi", ), pipeline_service.ListTrainingPipelinesResponse( @@ -1324,10 +1625,12 @@ async def test_list_training_pipelines_async_pager(): ), RuntimeError, ) - async_pager = await client.list_training_pipelines(request={},) + async_pager = await client.list_training_pipelines( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -1357,10 +1660,13 @@ async def test_list_training_pipelines_async_pages(): next_page_token="abc", ), pipeline_service.ListTrainingPipelinesResponse( - training_pipelines=[], next_page_token="def", + training_pipelines=[], + next_page_token="def", ), pipeline_service.ListTrainingPipelinesResponse( - training_pipelines=[training_pipeline.TrainingPipeline(),], + training_pipelines=[ + training_pipeline.TrainingPipeline(), + ], next_page_token="ghi", ), pipeline_service.ListTrainingPipelinesResponse( @@ -1372,17 +1678,25 @@ async def test_list_training_pipelines_async_pages(): RuntimeError, ) pages = [] - async for page_ in (await client.list_training_pipelines(request={})).pages: + async for page_ in ( + await client.list_training_pipelines(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_delete_training_pipeline( - transport: str = "grpc", request_type=pipeline_service.DeleteTrainingPipelineRequest -): +@pytest.mark.parametrize( + "request_type", + [ + pipeline_service.DeleteTrainingPipelineRequest, + dict, + ], +) +def test_delete_training_pipeline(request_type, transport: str = "grpc"): client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1406,15 +1720,12 @@ def test_delete_training_pipeline( assert isinstance(response, future.Future) -def test_delete_training_pipeline_from_dict(): - test_delete_training_pipeline(request_type=dict) - - def test_delete_training_pipeline_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1433,7 +1744,8 @@ async def test_delete_training_pipeline_async( request_type=pipeline_service.DeleteTrainingPipelineRequest, ): client = PipelineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1465,13 +1777,15 @@ async def test_delete_training_pipeline_async_from_dict(): def test_delete_training_pipeline_field_headers(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = pipeline_service.DeleteTrainingPipelineRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1487,7 +1801,10 @@ def test_delete_training_pipeline_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1500,7 +1817,7 @@ async def test_delete_training_pipeline_field_headers_async(): # a field header. Set these to a non-empty value. request = pipeline_service.DeleteTrainingPipelineRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1518,11 +1835,16 @@ async def test_delete_training_pipeline_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_delete_training_pipeline_flattened(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1532,23 +1854,30 @@ def test_delete_training_pipeline_flattened(): call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_training_pipeline(name="name_value",) + client.delete_training_pipeline( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_delete_training_pipeline_flattened_error(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.delete_training_pipeline( - pipeline_service.DeleteTrainingPipelineRequest(), name="name_value", + pipeline_service.DeleteTrainingPipelineRequest(), + name="name_value", ) @@ -1570,13 +1899,17 @@ async def test_delete_training_pipeline_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_training_pipeline(name="name_value",) + response = await client.delete_training_pipeline( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1589,15 +1922,22 @@ async def test_delete_training_pipeline_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.delete_training_pipeline( - pipeline_service.DeleteTrainingPipelineRequest(), name="name_value", + pipeline_service.DeleteTrainingPipelineRequest(), + name="name_value", ) -def test_cancel_training_pipeline( - transport: str = "grpc", request_type=pipeline_service.CancelTrainingPipelineRequest -): +@pytest.mark.parametrize( + "request_type", + [ + pipeline_service.CancelTrainingPipelineRequest, + dict, + ], +) +def test_cancel_training_pipeline(request_type, transport: str = "grpc"): client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1621,15 +1961,12 @@ def test_cancel_training_pipeline( assert response is None -def test_cancel_training_pipeline_from_dict(): - test_cancel_training_pipeline(request_type=dict) - - def test_cancel_training_pipeline_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1648,7 +1985,8 @@ async def test_cancel_training_pipeline_async( request_type=pipeline_service.CancelTrainingPipelineRequest, ): client = PipelineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1678,13 +2016,15 @@ async def test_cancel_training_pipeline_async_from_dict(): def test_cancel_training_pipeline_field_headers(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) - - # Any value that is part of the HTTP/1.1 URI should be sent as + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = pipeline_service.CancelTrainingPipelineRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1700,7 +2040,10 @@ def test_cancel_training_pipeline_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1713,7 +2056,7 @@ async def test_cancel_training_pipeline_field_headers_async(): # a field header. Set these to a non-empty value. request = pipeline_service.CancelTrainingPipelineRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1729,11 +2072,16 @@ async def test_cancel_training_pipeline_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_cancel_training_pipeline_flattened(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1743,23 +2091,30 @@ def test_cancel_training_pipeline_flattened(): call.return_value = None # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.cancel_training_pipeline(name="name_value",) + client.cancel_training_pipeline( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_cancel_training_pipeline_flattened_error(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.cancel_training_pipeline( - pipeline_service.CancelTrainingPipelineRequest(), name="name_value", + pipeline_service.CancelTrainingPipelineRequest(), + name="name_value", ) @@ -1779,13 +2134,17 @@ async def test_cancel_training_pipeline_flattened_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.cancel_training_pipeline(name="name_value",) + response = await client.cancel_training_pipeline( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1798,751 +2157,3945 @@ async def test_cancel_training_pipeline_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.cancel_training_pipeline( - pipeline_service.CancelTrainingPipelineRequest(), name="name_value", + pipeline_service.CancelTrainingPipelineRequest(), + name="name_value", ) -def test_credentials_transport_error(): - # It is an error to provide credentials and a transport instance. - transport = transports.PipelineServiceGrpcTransport( +@pytest.mark.parametrize( + "request_type", + [ + pipeline_service.CreatePipelineJobRequest, + dict, + ], +) +def test_create_pipeline_job(request_type, transport: str = "grpc"): + client = PipelineServiceClient( credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - with pytest.raises(ValueError): - client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_pipeline_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gca_pipeline_job.PipelineJob( + name="name_value", + display_name="display_name_value", + state=pipeline_state.PipelineState.PIPELINE_STATE_QUEUED, + service_account="service_account_value", + network="network_value", + template_uri="template_uri_value", ) + response = client.create_pipeline_job(request) - # It is an error to provide a credentials file and a transport instance. - transport = transports.PipelineServiceGrpcTransport( + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == pipeline_service.CreatePipelineJobRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_pipeline_job.PipelineJob) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.state == pipeline_state.PipelineState.PIPELINE_STATE_QUEUED + assert response.service_account == "service_account_value" + assert response.network == "network_value" + assert response.template_uri == "template_uri_value" + + +def test_create_pipeline_job_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = PipelineServiceClient( credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) - with pytest.raises(ValueError): - client = PipelineServiceClient( - client_options={"credentials_file": "credentials.json"}, - transport=transport, - ) - # It is an error to provide scopes and a transport instance. - transport = transports.PipelineServiceGrpcTransport( + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_pipeline_job), "__call__" + ) as call: + client.create_pipeline_job() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == pipeline_service.CreatePipelineJobRequest() + + +@pytest.mark.asyncio +async def test_create_pipeline_job_async( + transport: str = "grpc_asyncio", + request_type=pipeline_service.CreatePipelineJobRequest, +): + client = PipelineServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - with pytest.raises(ValueError): - client = PipelineServiceClient( - client_options={"scopes": ["1", "2"]}, transport=transport, + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_pipeline_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_pipeline_job.PipelineJob( + name="name_value", + display_name="display_name_value", + state=pipeline_state.PipelineState.PIPELINE_STATE_QUEUED, + service_account="service_account_value", + network="network_value", + template_uri="template_uri_value", + ) ) + response = await client.create_pipeline_job(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == pipeline_service.CreatePipelineJobRequest() -def test_transport_instance(): - # A client may be instantiated with a custom transport instance. - transport = transports.PipelineServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - client = PipelineServiceClient(transport=transport) - assert client.transport is transport + # Establish that the response is the type that we expect. + assert isinstance(response, gca_pipeline_job.PipelineJob) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.state == pipeline_state.PipelineState.PIPELINE_STATE_QUEUED + assert response.service_account == "service_account_value" + assert response.network == "network_value" + assert response.template_uri == "template_uri_value" -def test_transport_get_channel(): - # A client may be instantiated with a custom transport instance. - transport = transports.PipelineServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel +@pytest.mark.asyncio +async def test_create_pipeline_job_async_from_dict(): + await test_create_pipeline_job_async(request_type=dict) - transport = transports.PipelineServiceGrpcAsyncIOTransport( + +def test_create_pipeline_job_field_headers(): + client = PipelineServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) - channel = transport.grpc_channel - assert channel + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = pipeline_service.CreatePipelineJobRequest() -@pytest.mark.parametrize( - "transport_class", - [ - transports.PipelineServiceGrpcTransport, - transports.PipelineServiceGrpcAsyncIOTransport, - ], -) -def test_transport_adc(transport_class): - # Test default credentials are used if not provided. - with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class() - adc.assert_called_once() + request.parent = "parent_value" + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_pipeline_job), "__call__" + ) as call: + call.return_value = gca_pipeline_job.PipelineJob() + client.create_pipeline_job(request) -def test_transport_grpc_default(): - # A client should use the gRPC transport by default. - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) - assert isinstance(client.transport, transports.PipelineServiceGrpcTransport,) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] -def test_pipeline_service_base_transport_error(): - # Passing both a credentials object and credentials_file should raise an error - with pytest.raises(core_exceptions.DuplicateCredentialArgs): - transport = transports.PipelineServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), - credentials_file="credentials.json", - ) +@pytest.mark.asyncio +async def test_create_pipeline_job_field_headers_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) -def test_pipeline_service_base_transport(): - # Instantiate the base transport. - with mock.patch( - "google.cloud.aiplatform_v1.services.pipeline_service.transports.PipelineServiceTransport.__init__" - ) as Transport: - Transport.return_value = None - transport = transports.PipelineServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = pipeline_service.CreatePipelineJobRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_pipeline_job), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_pipeline_job.PipelineJob() ) + await client.create_pipeline_job(request) - # Every method on the transport should just blindly - # raise NotImplementedError. - methods = ( - "create_training_pipeline", - "get_training_pipeline", - "list_training_pipelines", - "delete_training_pipeline", - "cancel_training_pipeline", - ) - for method in methods: - with pytest.raises(NotImplementedError): - getattr(transport, method)(request=object()) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request - # Additionally, the LRO client (a property) should - # also raise NotImplementedError - with pytest.raises(NotImplementedError): - transport.operations_client + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] -@requires_google_auth_gte_1_25_0 -def test_pipeline_service_base_transport_with_credentials_file(): - # Instantiate the base transport with a credentials file +def test_create_pipeline_job_flattened(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.aiplatform_v1.services.pipeline_service.transports.PipelineServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.PipelineServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", + type(client.transport.create_pipeline_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gca_pipeline_job.PipelineJob() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_pipeline_job( + parent="parent_value", + pipeline_job=gca_pipeline_job.PipelineJob(name="name_value"), + pipeline_job_id="pipeline_job_id_value", ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=None, - default_scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].pipeline_job + mock_val = gca_pipeline_job.PipelineJob(name="name_value") + assert arg == mock_val + arg = args[0].pipeline_job_id + mock_val = "pipeline_job_id_value" + assert arg == mock_val + + +def test_create_pipeline_job_flattened_error(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_pipeline_job( + pipeline_service.CreatePipelineJobRequest(), + parent="parent_value", + pipeline_job=gca_pipeline_job.PipelineJob(name="name_value"), + pipeline_job_id="pipeline_job_id_value", ) -@requires_google_auth_lt_1_25_0 -def test_pipeline_service_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file +@pytest.mark.asyncio +async def test_create_pipeline_job_flattened_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.aiplatform_v1.services.pipeline_service.transports.PipelineServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.PipelineServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", + type(client.transport.create_pipeline_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gca_pipeline_job.PipelineJob() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_pipeline_job.PipelineJob() ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_pipeline_job( + parent="parent_value", + pipeline_job=gca_pipeline_job.PipelineJob(name="name_value"), + pipeline_job_id="pipeline_job_id_value", ) + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].pipeline_job + mock_val = gca_pipeline_job.PipelineJob(name="name_value") + assert arg == mock_val + arg = args[0].pipeline_job_id + mock_val = "pipeline_job_id_value" + assert arg == mock_val -def test_pipeline_service_base_transport_with_adc(): - # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.aiplatform_v1.services.pipeline_service.transports.PipelineServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.PipelineServiceTransport() - adc.assert_called_once() - - -@requires_google_auth_gte_1_25_0 -def test_pipeline_service_auth_adc(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - PipelineServiceClient() - adc.assert_called_once_with( - scopes=None, - default_scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) +@pytest.mark.asyncio +async def test_create_pipeline_job_flattened_error_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) -@requires_google_auth_lt_1_25_0 -def test_pipeline_service_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - PipelineServiceClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.create_pipeline_job( + pipeline_service.CreatePipelineJobRequest(), + parent="parent_value", + pipeline_job=gca_pipeline_job.PipelineJob(name="name_value"), + pipeline_job_id="pipeline_job_id_value", ) @pytest.mark.parametrize( - "transport_class", + "request_type", [ - transports.PipelineServiceGrpcTransport, - transports.PipelineServiceGrpcAsyncIOTransport, + pipeline_service.GetPipelineJobRequest, + dict, ], ) -@requires_google_auth_gte_1_25_0 -def test_pipeline_service_transport_auth_adc(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - adc.assert_called_once_with( - scopes=["1", "2"], - default_scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) +def test_get_pipeline_job(request_type, transport: str = "grpc"): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() -@pytest.mark.parametrize( - "transport_class", - [ - transports.PipelineServiceGrpcTransport, - transports.PipelineServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_pipeline_service_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_pipeline_job), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = pipeline_job.PipelineJob( + name="name_value", + display_name="display_name_value", + state=pipeline_state.PipelineState.PIPELINE_STATE_QUEUED, + service_account="service_account_value", + network="network_value", + template_uri="template_uri_value", ) + response = client.get_pipeline_job(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == pipeline_service.GetPipelineJobRequest() -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.PipelineServiceGrpcTransport, grpc_helpers), - (transports.PipelineServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_gte_1_26_0 -def test_pipeline_service_transport_create_channel(transport_class, grpc_helpers): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - default_scopes=("https://www.googleapis.com/auth/cloud-platform",), - scopes=["1", "2"], - default_host="aiplatform.googleapis.com", - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) + # Establish that the response is the type that we expect. + assert isinstance(response, pipeline_job.PipelineJob) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.state == pipeline_state.PipelineState.PIPELINE_STATE_QUEUED + assert response.service_account == "service_account_value" + assert response.network == "network_value" + assert response.template_uri == "template_uri_value" -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.PipelineServiceGrpcTransport, grpc_helpers), - (transports.PipelineServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_pipeline_service_transport_create_channel_old_api_core( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class(quota_project_id="octopus") +def test_get_pipeline_job_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_pipeline_job), "__call__") as call: + client.get_pipeline_job() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == pipeline_service.GetPipelineJobRequest() -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.PipelineServiceGrpcTransport, grpc_helpers), - (transports.PipelineServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_pipeline_service_transport_create_channel_user_scopes( - transport_class, grpc_helpers +@pytest.mark.asyncio +async def test_get_pipeline_job_async( + transport: str = "grpc_asyncio", request_type=pipeline_service.GetPipelineJobRequest ): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) - transport_class(quota_project_id="octopus", scopes=["1", "2"]) + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=["1", "2"], - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_pipeline_job), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + pipeline_job.PipelineJob( + name="name_value", + display_name="display_name_value", + state=pipeline_state.PipelineState.PIPELINE_STATE_QUEUED, + service_account="service_account_value", + network="network_value", + template_uri="template_uri_value", + ) ) + response = await client.get_pipeline_job(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == pipeline_service.GetPipelineJobRequest() -@pytest.mark.parametrize( - "transport_class", - [ - transports.PipelineServiceGrpcTransport, - transports.PipelineServiceGrpcAsyncIOTransport, - ], -) -def test_pipeline_service_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + # Establish that the response is the type that we expect. + assert isinstance(response, pipeline_job.PipelineJob) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.state == pipeline_state.PipelineState.PIPELINE_STATE_QUEUED + assert response.service_account == "service_account_value" + assert response.network == "network_value" + assert response.template_uri == "template_uri_value" - # Check ssl_channel_credentials is used if provided. - with mock.patch.object(transport_class, "create_channel") as mock_create_channel: - mock_ssl_channel_creds = mock.Mock() - transport_class( - host="squid.clam.whelk", - credentials=cred, - ssl_channel_credentials=mock_ssl_channel_creds, - ) - mock_create_channel.assert_called_once_with( - "squid.clam.whelk:443", - credentials=cred, - credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=mock_ssl_channel_creds, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls - # is used. - with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): - with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: - transport_class( - credentials=cred, - client_cert_source_for_mtls=client_cert_source_callback, - ) - expected_cert, expected_key = client_cert_source_callback() - mock_ssl_cred.assert_called_once_with( - certificate_chain=expected_cert, private_key=expected_key - ) +@pytest.mark.asyncio +async def test_get_pipeline_job_async_from_dict(): + await test_get_pipeline_job_async(request_type=dict) -def test_pipeline_service_host_no_port(): +def test_get_pipeline_job_field_headers(): client = PipelineServiceClient( credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions( - api_endpoint="aiplatform.googleapis.com" - ), ) - assert client.transport._host == "aiplatform.googleapis.com:443" + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = pipeline_service.GetPipelineJobRequest() -def test_pipeline_service_host_with_port(): - client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions( - api_endpoint="aiplatform.googleapis.com:8000" - ), - ) - assert client.transport._host == "aiplatform.googleapis.com:8000" + request.name = "name_value" + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_pipeline_job), "__call__") as call: + call.return_value = pipeline_job.PipelineJob() + client.get_pipeline_job(request) -def test_pipeline_service_grpc_transport_channel(): - channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request - # Check that channel is used if provided. - transport = transports.PipelineServiceGrpcTransport( - host="squid.clam.whelk", channel=channel, + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_pipeline_job_field_headers_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), ) - assert transport.grpc_channel == channel - assert transport._host == "squid.clam.whelk:443" - assert transport._ssl_channel_credentials == None + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = pipeline_service.GetPipelineJobRequest() -def test_pipeline_service_grpc_asyncio_transport_channel(): - channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) + request.name = "name_value" - # Check that channel is used if provided. - transport = transports.PipelineServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", channel=channel, + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_pipeline_job), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + pipeline_job.PipelineJob() + ) + await client.get_pipeline_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_get_pipeline_job_flattened(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), ) - assert transport.grpc_channel == channel - assert transport._host == "squid.clam.whelk:443" - assert transport._ssl_channel_credentials == None + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_pipeline_job), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = pipeline_job.PipelineJob() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_pipeline_job( + name="name_value", + ) -# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are -# removed from grpc/grpc_asyncio transport constructor. -@pytest.mark.parametrize( - "transport_class", - [ - transports.PipelineServiceGrpcTransport, - transports.PipelineServiceGrpcAsyncIOTransport, - ], -) -def test_pipeline_service_transport_channel_mtls_with_client_cert_source( - transport_class, -): - with mock.patch( - "grpc.ssl_channel_credentials", autospec=True - ) as grpc_ssl_channel_cred: - with mock.patch.object( - transport_class, "create_channel" - ) as grpc_create_channel: - mock_ssl_cred = mock.Mock() - grpc_ssl_channel_cred.return_value = mock_ssl_cred + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() - with pytest.warns(DeprecationWarning): - with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (cred, None) - transport = transport_class( - host="squid.clam.whelk", - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=client_cert_source_callback, - ) - adc.assert_called_once() +def test_get_pipeline_job_flattened_error(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) - grpc_ssl_channel_cred.assert_called_once_with( - certificate_chain=b"cert bytes", private_key=b"key bytes" - ) - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=cred, - credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - assert transport.grpc_channel == mock_grpc_channel - assert transport._ssl_channel_credentials == mock_ssl_cred + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_pipeline_job( + pipeline_service.GetPipelineJobRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_pipeline_job_flattened_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_pipeline_job), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = pipeline_job.PipelineJob() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + pipeline_job.PipelineJob() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_pipeline_job( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_get_pipeline_job_flattened_error_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_pipeline_job( + pipeline_service.GetPipelineJobRequest(), + name="name_value", + ) -# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are -# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( - "transport_class", + "request_type", [ - transports.PipelineServiceGrpcTransport, - transports.PipelineServiceGrpcAsyncIOTransport, + pipeline_service.ListPipelineJobsRequest, + dict, ], ) -def test_pipeline_service_transport_channel_mtls_with_adc(transport_class): - mock_ssl_cred = mock.Mock() - with mock.patch.multiple( - "google.auth.transport.grpc.SslCredentials", - __init__=mock.Mock(return_value=None), - ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), - ): - with mock.patch.object( - transport_class, "create_channel" - ) as grpc_create_channel: - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel - mock_cred = mock.Mock() +def test_list_pipeline_jobs(request_type, transport: str = "grpc"): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) - with pytest.warns(DeprecationWarning): - transport = transport_class( - host="squid.clam.whelk", - credentials=mock_cred, - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=None, - ) + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=mock_cred, - credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_pipeline_jobs), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = pipeline_service.ListPipelineJobsResponse( + next_page_token="next_page_token_value", + ) + response = client.list_pipeline_jobs(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == pipeline_service.ListPipelineJobsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListPipelineJobsPager) + assert response.next_page_token == "next_page_token_value" + + +def test_list_pipeline_jobs_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_pipeline_jobs), "__call__" + ) as call: + client.list_pipeline_jobs() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == pipeline_service.ListPipelineJobsRequest() + + +@pytest.mark.asyncio +async def test_list_pipeline_jobs_async( + transport: str = "grpc_asyncio", + request_type=pipeline_service.ListPipelineJobsRequest, +): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_pipeline_jobs), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + pipeline_service.ListPipelineJobsResponse( + next_page_token="next_page_token_value", ) - assert transport.grpc_channel == mock_grpc_channel + ) + response = await client.list_pipeline_jobs(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == pipeline_service.ListPipelineJobsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListPipelineJobsAsyncPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_list_pipeline_jobs_async_from_dict(): + await test_list_pipeline_jobs_async(request_type=dict) + + +def test_list_pipeline_jobs_field_headers(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = pipeline_service.ListPipelineJobsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_pipeline_jobs), "__call__" + ) as call: + call.return_value = pipeline_service.ListPipelineJobsResponse() + client.list_pipeline_jobs(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_pipeline_jobs_field_headers_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = pipeline_service.ListPipelineJobsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_pipeline_jobs), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + pipeline_service.ListPipelineJobsResponse() + ) + await client.list_pipeline_jobs(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_list_pipeline_jobs_flattened(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_pipeline_jobs), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = pipeline_service.ListPipelineJobsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_pipeline_jobs( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +def test_list_pipeline_jobs_flattened_error(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_pipeline_jobs( + pipeline_service.ListPipelineJobsRequest(), + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_pipeline_jobs_flattened_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_pipeline_jobs), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = pipeline_service.ListPipelineJobsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + pipeline_service.ListPipelineJobsResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_pipeline_jobs( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_list_pipeline_jobs_flattened_error_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_pipeline_jobs( + pipeline_service.ListPipelineJobsRequest(), + parent="parent_value", + ) + + +def test_list_pipeline_jobs_pager(transport_name: str = "grpc"): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_pipeline_jobs), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + pipeline_service.ListPipelineJobsResponse( + pipeline_jobs=[ + pipeline_job.PipelineJob(), + pipeline_job.PipelineJob(), + pipeline_job.PipelineJob(), + ], + next_page_token="abc", + ), + pipeline_service.ListPipelineJobsResponse( + pipeline_jobs=[], + next_page_token="def", + ), + pipeline_service.ListPipelineJobsResponse( + pipeline_jobs=[ + pipeline_job.PipelineJob(), + ], + next_page_token="ghi", + ), + pipeline_service.ListPipelineJobsResponse( + pipeline_jobs=[ + pipeline_job.PipelineJob(), + pipeline_job.PipelineJob(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_pipeline_jobs(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, pipeline_job.PipelineJob) for i in results) + + +def test_list_pipeline_jobs_pages(transport_name: str = "grpc"): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_pipeline_jobs), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + pipeline_service.ListPipelineJobsResponse( + pipeline_jobs=[ + pipeline_job.PipelineJob(), + pipeline_job.PipelineJob(), + pipeline_job.PipelineJob(), + ], + next_page_token="abc", + ), + pipeline_service.ListPipelineJobsResponse( + pipeline_jobs=[], + next_page_token="def", + ), + pipeline_service.ListPipelineJobsResponse( + pipeline_jobs=[ + pipeline_job.PipelineJob(), + ], + next_page_token="ghi", + ), + pipeline_service.ListPipelineJobsResponse( + pipeline_jobs=[ + pipeline_job.PipelineJob(), + pipeline_job.PipelineJob(), + ], + ), + RuntimeError, + ) + pages = list(client.list_pipeline_jobs(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.asyncio +async def test_list_pipeline_jobs_async_pager(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_pipeline_jobs), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + pipeline_service.ListPipelineJobsResponse( + pipeline_jobs=[ + pipeline_job.PipelineJob(), + pipeline_job.PipelineJob(), + pipeline_job.PipelineJob(), + ], + next_page_token="abc", + ), + pipeline_service.ListPipelineJobsResponse( + pipeline_jobs=[], + next_page_token="def", + ), + pipeline_service.ListPipelineJobsResponse( + pipeline_jobs=[ + pipeline_job.PipelineJob(), + ], + next_page_token="ghi", + ), + pipeline_service.ListPipelineJobsResponse( + pipeline_jobs=[ + pipeline_job.PipelineJob(), + pipeline_job.PipelineJob(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_pipeline_jobs( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, pipeline_job.PipelineJob) for i in responses) + + +@pytest.mark.asyncio +async def test_list_pipeline_jobs_async_pages(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_pipeline_jobs), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + pipeline_service.ListPipelineJobsResponse( + pipeline_jobs=[ + pipeline_job.PipelineJob(), + pipeline_job.PipelineJob(), + pipeline_job.PipelineJob(), + ], + next_page_token="abc", + ), + pipeline_service.ListPipelineJobsResponse( + pipeline_jobs=[], + next_page_token="def", + ), + pipeline_service.ListPipelineJobsResponse( + pipeline_jobs=[ + pipeline_job.PipelineJob(), + ], + next_page_token="ghi", + ), + pipeline_service.ListPipelineJobsResponse( + pipeline_jobs=[ + pipeline_job.PipelineJob(), + pipeline_job.PipelineJob(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.list_pipeline_jobs(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize( + "request_type", + [ + pipeline_service.DeletePipelineJobRequest, + dict, + ], +) +def test_delete_pipeline_job(request_type, transport: str = "grpc"): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_pipeline_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.delete_pipeline_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == pipeline_service.DeletePipelineJobRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_delete_pipeline_job_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_pipeline_job), "__call__" + ) as call: + client.delete_pipeline_job() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == pipeline_service.DeletePipelineJobRequest() + + +@pytest.mark.asyncio +async def test_delete_pipeline_job_async( + transport: str = "grpc_asyncio", + request_type=pipeline_service.DeletePipelineJobRequest, +): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_pipeline_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.delete_pipeline_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == pipeline_service.DeletePipelineJobRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_delete_pipeline_job_async_from_dict(): + await test_delete_pipeline_job_async(request_type=dict) + + +def test_delete_pipeline_job_field_headers(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = pipeline_service.DeletePipelineJobRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_pipeline_job), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_pipeline_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_pipeline_job_field_headers_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = pipeline_service.DeletePipelineJobRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_pipeline_job), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.delete_pipeline_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_delete_pipeline_job_flattened(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_pipeline_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_pipeline_job( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_delete_pipeline_job_flattened_error(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_pipeline_job( + pipeline_service.DeletePipelineJobRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_delete_pipeline_job_flattened_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_pipeline_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_pipeline_job( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_delete_pipeline_job_flattened_error_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.delete_pipeline_job( + pipeline_service.DeletePipelineJobRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + pipeline_service.CancelPipelineJobRequest, + dict, + ], +) +def test_cancel_pipeline_job(request_type, transport: str = "grpc"): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.cancel_pipeline_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_pipeline_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == pipeline_service.CancelPipelineJobRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_pipeline_job_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.cancel_pipeline_job), "__call__" + ) as call: + client.cancel_pipeline_job() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == pipeline_service.CancelPipelineJobRequest() + + +@pytest.mark.asyncio +async def test_cancel_pipeline_job_async( + transport: str = "grpc_asyncio", + request_type=pipeline_service.CancelPipelineJobRequest, +): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.cancel_pipeline_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_pipeline_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == pipeline_service.CancelPipelineJobRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_pipeline_job_async_from_dict(): + await test_cancel_pipeline_job_async(request_type=dict) + + +def test_cancel_pipeline_job_field_headers(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = pipeline_service.CancelPipelineJobRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.cancel_pipeline_job), "__call__" + ) as call: + call.return_value = None + client.cancel_pipeline_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_pipeline_job_field_headers_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = pipeline_service.CancelPipelineJobRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.cancel_pipeline_job), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_pipeline_job(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_cancel_pipeline_job_flattened(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.cancel_pipeline_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = None + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.cancel_pipeline_job( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_cancel_pipeline_job_flattened_error(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.cancel_pipeline_job( + pipeline_service.CancelPipelineJobRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_cancel_pipeline_job_flattened_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.cancel_pipeline_job), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = None + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.cancel_pipeline_job( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_cancel_pipeline_job_flattened_error_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.cancel_pipeline_job( + pipeline_service.CancelPipelineJobRequest(), + name="name_value", + ) + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.PipelineServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.PipelineServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = PipelineServiceClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide an api_key and a transport instance. + transport = transports.PipelineServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = PipelineServiceClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = PipelineServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.PipelineServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = PipelineServiceClient( + client_options={"scopes": ["1", "2"]}, + transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.PipelineServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + client = PipelineServiceClient(transport=transport) + assert client.transport is transport + + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.PipelineServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.PipelineServiceGrpcAsyncIOTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.PipelineServiceGrpcTransport, + transports.PipelineServiceGrpcAsyncIOTransport, + ], +) +def test_transport_adc(transport_class): + # Test default credentials are used if not provided. + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class() + adc.assert_called_once() + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = PipelineServiceClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + +def test_transport_grpc_default(): + # A client should use the gRPC transport by default. + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.PipelineServiceGrpcTransport, + ) + + +def test_pipeline_service_base_transport_error(): + # Passing both a credentials object and credentials_file should raise an error + with pytest.raises(core_exceptions.DuplicateCredentialArgs): + transport = transports.PipelineServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + credentials_file="credentials.json", + ) + + +def test_pipeline_service_base_transport(): + # Instantiate the base transport. + with mock.patch( + "google.cloud.aiplatform_v1.services.pipeline_service.transports.PipelineServiceTransport.__init__" + ) as Transport: + Transport.return_value = None + transport = transports.PipelineServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Every method on the transport should just blindly + # raise NotImplementedError. + methods = ( + "create_training_pipeline", + "get_training_pipeline", + "list_training_pipelines", + "delete_training_pipeline", + "cancel_training_pipeline", + "create_pipeline_job", + "get_pipeline_job", + "list_pipeline_jobs", + "delete_pipeline_job", + "cancel_pipeline_job", + "set_iam_policy", + "get_iam_policy", + "test_iam_permissions", + "get_location", + "list_locations", + "get_operation", + "wait_operation", + "cancel_operation", + "delete_operation", + "list_operations", + ) + for method in methods: + with pytest.raises(NotImplementedError): + getattr(transport, method)(request=object()) + + with pytest.raises(NotImplementedError): + transport.close() + + # Additionally, the LRO client (a property) should + # also raise NotImplementedError + with pytest.raises(NotImplementedError): + transport.operations_client + + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + + +def test_pipeline_service_base_transport_with_credentials_file(): + # Instantiate the base transport with a credentials file + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch( + "google.cloud.aiplatform_v1.services.pipeline_service.transports.PipelineServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.PipelineServiceTransport( + credentials_file="credentials.json", + quota_project_id="octopus", + ) + load_creds.assert_called_once_with( + "credentials.json", + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +def test_pipeline_service_base_transport_with_adc(): + # Test the default credentials are used if credentials and credentials_file are None. + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( + "google.cloud.aiplatform_v1.services.pipeline_service.transports.PipelineServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.PipelineServiceTransport() + adc.assert_called_once() + + +def test_pipeline_service_auth_adc(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + PipelineServiceClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id=None, + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.PipelineServiceGrpcTransport, + transports.PipelineServiceGrpcAsyncIOTransport, + ], +) +def test_pipeline_service_transport_auth_adc(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.PipelineServiceGrpcTransport, grpc_helpers), + (transports.PipelineServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +def test_pipeline_service_transport_create_channel(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=["1", "2"], + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.PipelineServiceGrpcTransport, + transports.PipelineServiceGrpcAsyncIOTransport, + ], +) +def test_pipeline_service_grpc_transport_client_cert_source_for_mtls(transport_class): + cred = ga_credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds, + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback, + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, private_key=expected_key + ) + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_pipeline_service_host_no_port(transport_name): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions( + api_endpoint="aiplatform.googleapis.com" + ), + transport=transport_name, + ) + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_pipeline_service_host_with_port(transport_name): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions( + api_endpoint="aiplatform.googleapis.com:8000" + ), + transport=transport_name, + ) + assert client.transport._host == ("aiplatform.googleapis.com:8000") + + +def test_pipeline_service_grpc_transport_channel(): + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.PipelineServiceGrpcTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +def test_pipeline_service_grpc_asyncio_transport_channel(): + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.PipelineServiceGrpcAsyncIOTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize( + "transport_class", + [ + transports.PipelineServiceGrpcTransport, + transports.PipelineServiceGrpcAsyncIOTransport, + ], +) +def test_pipeline_service_transport_channel_mtls_with_client_cert_source( + transport_class, +): + with mock.patch( + "grpc.ssl_channel_credentials", autospec=True + ) as grpc_ssl_channel_cred: + with mock.patch.object( + transport_class, "create_channel" + ) as grpc_create_channel: + mock_ssl_cred = mock.Mock() + grpc_ssl_channel_cred.return_value = mock_ssl_cred + + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + + cred = ga_credentials.AnonymousCredentials() + with pytest.warns(DeprecationWarning): + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (cred, None) + transport = transport_class( + host="squid.clam.whelk", + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=client_cert_source_callback, + ) + adc.assert_called_once() + + grpc_ssl_channel_cred.assert_called_once_with( + certificate_chain=b"cert bytes", private_key=b"key bytes" + ) + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize( + "transport_class", + [ + transports.PipelineServiceGrpcTransport, + transports.PipelineServiceGrpcAsyncIOTransport, + ], +) +def test_pipeline_service_transport_channel_mtls_with_adc(transport_class): + mock_ssl_cred = mock.Mock() + with mock.patch.multiple( + "google.auth.transport.grpc.SslCredentials", + __init__=mock.Mock(return_value=None), + ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), + ): + with mock.patch.object( + transport_class, "create_channel" + ) as grpc_create_channel: + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + mock_cred = mock.Mock() + + with pytest.warns(DeprecationWarning): + transport = transport_class( + host="squid.clam.whelk", + credentials=mock_cred, + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=None, + ) + + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=mock_cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + + +def test_pipeline_service_grpc_lro_client(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_pipeline_service_grpc_lro_async_client(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_artifact_path(): + project = "squid" + location = "clam" + metadata_store = "whelk" + artifact = "octopus" + expected = "projects/{project}/locations/{location}/metadataStores/{metadata_store}/artifacts/{artifact}".format( + project=project, + location=location, + metadata_store=metadata_store, + artifact=artifact, + ) + actual = PipelineServiceClient.artifact_path( + project, location, metadata_store, artifact + ) + assert expected == actual + + +def test_parse_artifact_path(): + expected = { + "project": "oyster", + "location": "nudibranch", + "metadata_store": "cuttlefish", + "artifact": "mussel", + } + path = PipelineServiceClient.artifact_path(**expected) + + # Check that the path construction is reversible. + actual = PipelineServiceClient.parse_artifact_path(path) + assert expected == actual + + +def test_context_path(): + project = "winkle" + location = "nautilus" + metadata_store = "scallop" + context = "abalone" + expected = "projects/{project}/locations/{location}/metadataStores/{metadata_store}/contexts/{context}".format( + project=project, + location=location, + metadata_store=metadata_store, + context=context, + ) + actual = PipelineServiceClient.context_path( + project, location, metadata_store, context + ) + assert expected == actual + + +def test_parse_context_path(): + expected = { + "project": "squid", + "location": "clam", + "metadata_store": "whelk", + "context": "octopus", + } + path = PipelineServiceClient.context_path(**expected) + + # Check that the path construction is reversible. + actual = PipelineServiceClient.parse_context_path(path) + assert expected == actual + + +def test_custom_job_path(): + project = "oyster" + location = "nudibranch" + custom_job = "cuttlefish" + expected = "projects/{project}/locations/{location}/customJobs/{custom_job}".format( + project=project, + location=location, + custom_job=custom_job, + ) + actual = PipelineServiceClient.custom_job_path(project, location, custom_job) + assert expected == actual + + +def test_parse_custom_job_path(): + expected = { + "project": "mussel", + "location": "winkle", + "custom_job": "nautilus", + } + path = PipelineServiceClient.custom_job_path(**expected) + + # Check that the path construction is reversible. + actual = PipelineServiceClient.parse_custom_job_path(path) + assert expected == actual + + +def test_endpoint_path(): + project = "scallop" + location = "abalone" + endpoint = "squid" + expected = "projects/{project}/locations/{location}/endpoints/{endpoint}".format( + project=project, + location=location, + endpoint=endpoint, + ) + actual = PipelineServiceClient.endpoint_path(project, location, endpoint) + assert expected == actual + + +def test_parse_endpoint_path(): + expected = { + "project": "clam", + "location": "whelk", + "endpoint": "octopus", + } + path = PipelineServiceClient.endpoint_path(**expected) + + # Check that the path construction is reversible. + actual = PipelineServiceClient.parse_endpoint_path(path) + assert expected == actual + + +def test_execution_path(): + project = "oyster" + location = "nudibranch" + metadata_store = "cuttlefish" + execution = "mussel" + expected = "projects/{project}/locations/{location}/metadataStores/{metadata_store}/executions/{execution}".format( + project=project, + location=location, + metadata_store=metadata_store, + execution=execution, + ) + actual = PipelineServiceClient.execution_path( + project, location, metadata_store, execution + ) + assert expected == actual + + +def test_parse_execution_path(): + expected = { + "project": "winkle", + "location": "nautilus", + "metadata_store": "scallop", + "execution": "abalone", + } + path = PipelineServiceClient.execution_path(**expected) + + # Check that the path construction is reversible. + actual = PipelineServiceClient.parse_execution_path(path) + assert expected == actual + + +def test_model_path(): + project = "squid" + location = "clam" + model = "whelk" + expected = "projects/{project}/locations/{location}/models/{model}".format( + project=project, + location=location, + model=model, + ) + actual = PipelineServiceClient.model_path(project, location, model) + assert expected == actual + + +def test_parse_model_path(): + expected = { + "project": "octopus", + "location": "oyster", + "model": "nudibranch", + } + path = PipelineServiceClient.model_path(**expected) + + # Check that the path construction is reversible. + actual = PipelineServiceClient.parse_model_path(path) + assert expected == actual + + +def test_network_path(): + project = "cuttlefish" + network = "mussel" + expected = "projects/{project}/global/networks/{network}".format( + project=project, + network=network, + ) + actual = PipelineServiceClient.network_path(project, network) + assert expected == actual + + +def test_parse_network_path(): + expected = { + "project": "winkle", + "network": "nautilus", + } + path = PipelineServiceClient.network_path(**expected) + + # Check that the path construction is reversible. + actual = PipelineServiceClient.parse_network_path(path) + assert expected == actual + + +def test_pipeline_job_path(): + project = "scallop" + location = "abalone" + pipeline_job = "squid" + expected = ( + "projects/{project}/locations/{location}/pipelineJobs/{pipeline_job}".format( + project=project, + location=location, + pipeline_job=pipeline_job, + ) + ) + actual = PipelineServiceClient.pipeline_job_path(project, location, pipeline_job) + assert expected == actual + + +def test_parse_pipeline_job_path(): + expected = { + "project": "clam", + "location": "whelk", + "pipeline_job": "octopus", + } + path = PipelineServiceClient.pipeline_job_path(**expected) + + # Check that the path construction is reversible. + actual = PipelineServiceClient.parse_pipeline_job_path(path) + assert expected == actual + + +def test_training_pipeline_path(): + project = "oyster" + location = "nudibranch" + training_pipeline = "cuttlefish" + expected = "projects/{project}/locations/{location}/trainingPipelines/{training_pipeline}".format( + project=project, + location=location, + training_pipeline=training_pipeline, + ) + actual = PipelineServiceClient.training_pipeline_path( + project, location, training_pipeline + ) + assert expected == actual + + +def test_parse_training_pipeline_path(): + expected = { + "project": "mussel", + "location": "winkle", + "training_pipeline": "nautilus", + } + path = PipelineServiceClient.training_pipeline_path(**expected) + + # Check that the path construction is reversible. + actual = PipelineServiceClient.parse_training_pipeline_path(path) + assert expected == actual + + +def test_common_billing_account_path(): + billing_account = "scallop" + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + actual = PipelineServiceClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "abalone", + } + path = PipelineServiceClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = PipelineServiceClient.parse_common_billing_account_path(path) + assert expected == actual + + +def test_common_folder_path(): + folder = "squid" + expected = "folders/{folder}".format( + folder=folder, + ) + actual = PipelineServiceClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "clam", + } + path = PipelineServiceClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = PipelineServiceClient.parse_common_folder_path(path) + assert expected == actual + + +def test_common_organization_path(): + organization = "whelk" + expected = "organizations/{organization}".format( + organization=organization, + ) + actual = PipelineServiceClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "octopus", + } + path = PipelineServiceClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = PipelineServiceClient.parse_common_organization_path(path) + assert expected == actual + + +def test_common_project_path(): + project = "oyster" + expected = "projects/{project}".format( + project=project, + ) + actual = PipelineServiceClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "nudibranch", + } + path = PipelineServiceClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = PipelineServiceClient.parse_common_project_path(path) + assert expected == actual + + +def test_common_location_path(): + project = "cuttlefish" + location = "mussel" + expected = "projects/{project}/locations/{location}".format( + project=project, + location=location, + ) + actual = PipelineServiceClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "winkle", + "location": "nautilus", + } + path = PipelineServiceClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = PipelineServiceClient.parse_common_location_path(path) + assert expected == actual + + +def test_client_with_default_client_info(): + client_info = gapic_v1.client_info.ClientInfo() + + with mock.patch.object( + transports.PipelineServiceTransport, "_prep_wrapped_messages" + ) as prep: + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + with mock.patch.object( + transports.PipelineServiceTransport, "_prep_wrapped_messages" + ) as prep: + transport_class = PipelineServiceClient.get_transport_class() + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_delete_operation(transport: str = "grpc"): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_operation(transport: str = "grpc"): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_operation_field_headers(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = None + + client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_operation_field_headers_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_delete_operation_from_dict(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_delete_operation_from_dict_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_cancel_operation(transport: str = "grpc"): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation(transport: str = "grpc"): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_wait_operation(transport: str = "grpc"): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_wait_operation(transport: str = "grpc"): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_wait_operation_field_headers(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_wait_operation_field_headers_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_wait_operation_from_dict(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_wait_operation_from_dict_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_operation(transport: str = "grpc"): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_get_operation(transport: str = "grpc"): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_get_operation_field_headers(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_get_operation_from_dict(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_operations(transport: str = "grpc"): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + response = client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +@pytest.mark.asyncio +async def test_list_operations(transport: str = "grpc"): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +def test_list_operations_field_headers(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_operations_field_headers_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_operations_from_dict(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + response = client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_operations_from_dict_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_locations(transport: str = "grpc"): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + response = client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +@pytest.mark.asyncio +async def test_list_locations(transport: str = "grpc"): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +def test_list_locations_field_headers(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_locations_field_headers_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_locations_from_dict(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + response = client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_locations_from_dict_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_location(transport: str = "grpc"): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + response = client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +@pytest.mark.asyncio +async def test_get_location_async(transport: str = "grpc_asyncio"): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +def test_get_location_field_headers(): + client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials()) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = locations_pb2.Location() + + client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_location_field_headers_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials() + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +def test_get_location_from_dict(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + response = client.get_location( + request={ + "name": "locations/abc", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_location_from_dict_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_set_iam_policy(transport: str = "grpc"): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + response = client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + response = await client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_set_iam_policy_field_headers(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_set_iam_policy_field_headers_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_set_iam_policy_from_dict(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_set_iam_policy_from_dict_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +def test_get_iam_policy(transport: str = "grpc"): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + + response = client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + + response = await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_get_iam_policy_field_headers(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_iam_policy_field_headers_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + await client.get_iam_policy(request) -def test_pipeline_service_grpc_lro_client(): + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_get_iam_policy_from_dict(): client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), ) - transport = client.transport - - # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsClient,) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() - # Ensure that subsequent calls to the property send the exact same object. - assert transport.operations_client is transport.operations_client + response = client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() -def test_pipeline_service_grpc_lro_async_client(): +@pytest.mark.asyncio +async def test_get_iam_policy_from_dict_async(): client = PipelineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), ) - transport = client.transport - - # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient,) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) - # Ensure that subsequent calls to the property send the exact same object. - assert transport.operations_client is transport.operations_client + response = await client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() -def test_endpoint_path(): - project = "squid" - location = "clam" - endpoint = "whelk" - expected = "projects/{project}/locations/{location}/endpoints/{endpoint}".format( - project=project, location=location, endpoint=endpoint, +def test_test_iam_permissions(transport: str = "grpc"): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - actual = PipelineServiceClient.endpoint_path(project, location, endpoint) - assert expected == actual - -def test_parse_endpoint_path(): - expected = { - "project": "octopus", - "location": "oyster", - "endpoint": "nudibranch", - } - path = PipelineServiceClient.endpoint_path(**expected) + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() - # Check that the path construction is reversible. - actual = PipelineServiceClient.parse_endpoint_path(path) - assert expected == actual + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + response = client.test_iam_permissions(request) -def test_model_path(): - project = "cuttlefish" - location = "mussel" - model = "winkle" - expected = "projects/{project}/locations/{location}/models/{model}".format( - project=project, location=location, model=model, - ) - actual = PipelineServiceClient.model_path(project, location, model) - assert expected == actual + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request -def test_parse_model_path(): - expected = { - "project": "nautilus", - "location": "scallop", - "model": "abalone", - } - path = PipelineServiceClient.model_path(**expected) + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) - # Check that the path construction is reversible. - actual = PipelineServiceClient.parse_model_path(path) - assert expected == actual + assert response.permissions == ["permissions_value"] -def test_training_pipeline_path(): - project = "squid" - location = "clam" - training_pipeline = "whelk" - expected = "projects/{project}/locations/{location}/trainingPipelines/{training_pipeline}".format( - project=project, location=location, training_pipeline=training_pipeline, - ) - actual = PipelineServiceClient.training_pipeline_path( - project, location, training_pipeline +@pytest.mark.asyncio +async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - assert expected == actual + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() -def test_parse_training_pipeline_path(): - expected = { - "project": "octopus", - "location": "oyster", - "training_pipeline": "nudibranch", - } - path = PipelineServiceClient.training_pipeline_path(**expected) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + ) - # Check that the path construction is reversible. - actual = PipelineServiceClient.parse_training_pipeline_path(path) - assert expected == actual + response = await client.test_iam_permissions(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] -def test_common_billing_account_path(): - billing_account = "cuttlefish" - expected = "billingAccounts/{billing_account}".format( - billing_account=billing_account, - ) - actual = PipelineServiceClient.common_billing_account_path(billing_account) - assert expected == actual + assert args[0] == request + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) -def test_parse_common_billing_account_path(): - expected = { - "billing_account": "mussel", - } - path = PipelineServiceClient.common_billing_account_path(**expected) + assert response.permissions == ["permissions_value"] - # Check that the path construction is reversible. - actual = PipelineServiceClient.parse_common_billing_account_path(path) - assert expected == actual +def test_test_iam_permissions_field_headers(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) -def test_common_folder_path(): - folder = "winkle" - expected = "folders/{folder}".format(folder=folder,) - actual = PipelineServiceClient.common_folder_path(folder) - assert expected == actual + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() -def test_parse_common_folder_path(): - expected = { - "folder": "nautilus", - } - path = PipelineServiceClient.common_folder_path(**expected) + client.test_iam_permissions(request) - # Check that the path construction is reversible. - actual = PipelineServiceClient.parse_common_folder_path(path) - assert expected == actual + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] -def test_common_organization_path(): - organization = "scallop" - expected = "organizations/{organization}".format(organization=organization,) - actual = PipelineServiceClient.common_organization_path(organization) - assert expected == actual +@pytest.mark.asyncio +async def test_test_iam_permissions_field_headers_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) -def test_parse_common_organization_path(): - expected = { - "organization": "abalone", - } - path = PipelineServiceClient.common_organization_path(**expected) + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" - # Check that the path construction is reversible. - actual = PipelineServiceClient.parse_common_organization_path(path) - assert expected == actual + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + await client.test_iam_permissions(request) -def test_common_project_path(): - project = "squid" - expected = "projects/{project}".format(project=project,) - actual = PipelineServiceClient.common_project_path(project) - assert expected == actual + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] -def test_parse_common_project_path(): - expected = { - "project": "clam", - } - path = PipelineServiceClient.common_project_path(**expected) - # Check that the path construction is reversible. - actual = PipelineServiceClient.parse_common_project_path(path) - assert expected == actual +def test_test_iam_permissions_from_dict(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + response = client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() -def test_common_location_path(): - project = "whelk" - location = "octopus" - expected = "projects/{project}/locations/{location}".format( - project=project, location=location, + +@pytest.mark.asyncio +async def test_test_iam_permissions_from_dict_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), ) - actual = PipelineServiceClient.common_location_path(project, location) - assert expected == actual + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + response = await client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() -def test_parse_common_location_path(): - expected = { - "project": "oyster", - "location": "nudibranch", - } - path = PipelineServiceClient.common_location_path(**expected) - # Check that the path construction is reversible. - actual = PipelineServiceClient.parse_common_location_path(path) - assert expected == actual +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + for transport, close_name in transports.items(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() -def test_client_withDEFAULT_CLIENT_INFO(): - client_info = gapic_v1.client_info.ClientInfo() - with mock.patch.object( - transports.PipelineServiceTransport, "_prep_wrapped_messages" - ) as prep: +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), transport=transport ) - prep.assert_called_once_with(client_info) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (PipelineServiceClient, transports.PipelineServiceGrpcTransport), + (PipelineServiceAsyncClient, transports.PipelineServiceGrpcAsyncIOTransport), + ], +) +def test_api_key_credentials(client_class, transport_class): with mock.patch.object( - transports.PipelineServiceTransport, "_prep_wrapped_messages" - ) as prep: - transport_class = PipelineServiceClient.get_transport_class() - transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, - ) - prep.assert_called_once_with(client_info) + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) diff --git a/tests/unit/gapic/aiplatform_v1/test_prediction_service.py b/tests/unit/gapic/aiplatform_v1/test_prediction_service.py index a65e69f1b6..f76cd473a0 100644 --- a/tests/unit/gapic/aiplatform_v1/test_prediction_service.py +++ b/tests/unit/gapic/aiplatform_v1/test_prediction_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,8 +14,13 @@ # limitations under the License. # import os -import mock -import packaging.version + +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock +except ImportError: + import mock import grpc from grpc.experimental import aio @@ -24,11 +29,13 @@ from proto.marshal.rules.dates import DurationRule, TimestampRule +from google.api import httpbody_pb2 # type: ignore from google.api_core import client_options from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.aiplatform_v1.services.prediction_service import ( @@ -38,41 +45,19 @@ PredictionServiceClient, ) from google.cloud.aiplatform_v1.services.prediction_service import transports -from google.cloud.aiplatform_v1.services.prediction_service.transports.base import ( - _API_CORE_VERSION, -) -from google.cloud.aiplatform_v1.services.prediction_service.transports.base import ( - _GOOGLE_AUTH_VERSION, -) +from google.cloud.aiplatform_v1.types import explanation from google.cloud.aiplatform_v1.types import prediction_service +from google.cloud.location import locations_pb2 +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.oauth2 import service_account +from google.protobuf import any_pb2 # type: ignore from google.protobuf import struct_pb2 # type: ignore import google.auth -# TODO(busunkim): Once google-api-core >= 1.26.0 is required: -# - Delete all the api-core and auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - -requires_api_core_lt_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), - reason="This test requires google-api-core < 1.26.0", -) - -requires_api_core_gte_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), - reason="This test requires google-api-core >= 1.26.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -119,40 +104,81 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( - "client_class", [PredictionServiceClient, PredictionServiceAsyncClient,] + "client_class,transport_name", + [ + (PredictionServiceClient, "grpc"), + (PredictionServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_prediction_service_client_from_service_account_info(client_class): +def test_prediction_service_client_from_service_account_info( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.PredictionServiceGrpcTransport, "grpc"), + (transports.PredictionServiceGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_prediction_service_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() @pytest.mark.parametrize( - "client_class", [PredictionServiceClient, PredictionServiceAsyncClient,] + "client_class,transport_name", + [ + (PredictionServiceClient, "grpc"), + (PredictionServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_prediction_service_client_from_service_account_file(client_class): +def test_prediction_service_client_from_service_account_file( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") def test_prediction_service_client_get_transport_class(): @@ -205,7 +231,7 @@ def test_prediction_service_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -214,6 +240,7 @@ def test_prediction_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -221,7 +248,7 @@ def test_prediction_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -230,6 +257,7 @@ def test_prediction_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -237,7 +265,7 @@ def test_prediction_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -246,26 +274,27 @@ def test_prediction_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -274,6 +303,7 @@ def test_prediction_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -333,7 +363,7 @@ def test_prediction_service_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -350,6 +380,7 @@ def test_prediction_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case ADC client cert is provided. Whether client cert is used depends on @@ -374,7 +405,7 @@ def test_prediction_service_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -383,6 +414,7 @@ def test_prediction_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case client_cert_source and ADC client cert are not provided. @@ -395,7 +427,7 @@ def test_prediction_service_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -404,9 +436,91 @@ def test_prediction_service_client_mtls_env_auto( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) +@pytest.mark.parametrize( + "client_class", [PredictionServiceClient, PredictionServiceAsyncClient] +) +@mock.patch.object( + PredictionServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(PredictionServiceClient), +) +@mock.patch.object( + PredictionServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(PredictionServiceAsyncClient), +) +def test_prediction_service_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + @pytest.mark.parametrize( "client_class,transport_class,transport_name", [ @@ -422,10 +536,12 @@ def test_prediction_service_client_client_options_scopes( client_class, transport_class, transport_name ): # Check the case scopes are provided. - options = client_options.ClientOptions(scopes=["1", "2"],) + options = client_options.ClientOptions( + scopes=["1", "2"], + ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -434,28 +550,36 @@ def test_prediction_service_client_client_options_scopes( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (PredictionServiceClient, transports.PredictionServiceGrpcTransport, "grpc"), + ( + PredictionServiceClient, + transports.PredictionServiceGrpcTransport, + "grpc", + grpc_helpers, + ), ( PredictionServiceAsyncClient, transports.PredictionServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_prediction_service_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -464,6 +588,7 @@ def test_prediction_service_client_client_options_credentials_file( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -483,14 +608,87 @@ def test_prediction_service_client_client_options_from_dict(): client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) -def test_predict( - transport: str = "grpc", request_type=prediction_service.PredictRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + PredictionServiceClient, + transports.PredictionServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + PredictionServiceAsyncClient, + transports.PredictionServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_prediction_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers ): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + prediction_service.PredictRequest, + dict, + ], +) +def test_predict(request_type, transport: str = "grpc"): client = PredictionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -502,6 +700,9 @@ def test_predict( # Designate an appropriate return value for the call. call.return_value = prediction_service.PredictResponse( deployed_model_id="deployed_model_id_value", + model="model_value", + model_version_id="model_version_id_value", + model_display_name="model_display_name_value", ) response = client.predict(request) @@ -513,17 +714,17 @@ def test_predict( # Establish that the response is the type that we expect. assert isinstance(response, prediction_service.PredictResponse) assert response.deployed_model_id == "deployed_model_id_value" - - -def test_predict_from_dict(): - test_predict(request_type=dict) + assert response.model == "model_value" + assert response.model_version_id == "model_version_id_value" + assert response.model_display_name == "model_display_name_value" def test_predict_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = PredictionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -539,7 +740,8 @@ async def test_predict_async( transport: str = "grpc_asyncio", request_type=prediction_service.PredictRequest ): client = PredictionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -552,6 +754,9 @@ async def test_predict_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( prediction_service.PredictResponse( deployed_model_id="deployed_model_id_value", + model="model_value", + model_version_id="model_version_id_value", + model_display_name="model_display_name_value", ) ) response = await client.predict(request) @@ -564,6 +769,9 @@ async def test_predict_async( # Establish that the response is the type that we expect. assert isinstance(response, prediction_service.PredictResponse) assert response.deployed_model_id == "deployed_model_id_value" + assert response.model == "model_value" + assert response.model_version_id == "model_version_id_value" + assert response.model_display_name == "model_display_name_value" @pytest.mark.asyncio @@ -572,13 +780,15 @@ async def test_predict_async_from_dict(): def test_predict_field_headers(): - client = PredictionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = prediction_service.PredictRequest() - request.endpoint = "endpoint/value" + request.endpoint = "endpoint_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.predict), "__call__") as call: @@ -592,7 +802,10 @@ def test_predict_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "endpoint=endpoint/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "endpoint=endpoint_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -605,7 +818,7 @@ async def test_predict_field_headers_async(): # a field header. Set these to a non-empty value. request = prediction_service.PredictRequest() - request.endpoint = "endpoint/value" + request.endpoint = "endpoint_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.predict), "__call__") as call: @@ -621,38 +834,16 @@ async def test_predict_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "endpoint=endpoint/value",) in kw["metadata"] - - -def test_predict_flattened(): - client = PredictionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.predict), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = prediction_service.PredictResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.predict( - endpoint="endpoint_value", - instances=[struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE)], - parameters=struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE), - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0].endpoint == "endpoint_value" - assert args[0].instances == [ - struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE) - ] - # https://github.com/googleapis/gapic-generator-python/issues/414 - # assert args[0].parameters == struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE) + assert ( + "x-goog-request-params", + "endpoint=endpoint_value", + ) in kw["metadata"] def test_predict_flattened_error(): - client = PredictionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -665,40 +856,6 @@ def test_predict_flattened_error(): ) -@pytest.mark.asyncio -async def test_predict_flattened_async(): - client = PredictionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.predict), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = prediction_service.PredictResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - prediction_service.PredictResponse() - ) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.predict( - endpoint="endpoint_value", - instances=[struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE)], - parameters=struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE), - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0].endpoint == "endpoint_value" - assert args[0].instances == [ - struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE) - ] - # https://github.com/googleapis/gapic-generator-python/issues/414 - # assert args[0].parameters == struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE) - - @pytest.mark.asyncio async def test_predict_flattened_error_async(): client = PredictionServiceAsyncClient( @@ -716,426 +873,513 @@ async def test_predict_flattened_error_async(): ) -def test_credentials_transport_error(): - # It is an error to provide credentials and a transport instance. - transport = transports.PredictionServiceGrpcTransport( +@pytest.mark.parametrize( + "request_type", + [ + prediction_service.RawPredictRequest, + dict, + ], +) +def test_raw_predict(request_type, transport: str = "grpc"): + client = PredictionServiceClient( credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - with pytest.raises(ValueError): - client = PredictionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.raw_predict), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = httpbody_pb2.HttpBody( + content_type="content_type_value", + data=b"data_blob", ) + response = client.raw_predict(request) - # It is an error to provide a credentials file and a transport instance. - transport = transports.PredictionServiceGrpcTransport( + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == prediction_service.RawPredictRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, httpbody_pb2.HttpBody) + assert response.content_type == "content_type_value" + assert response.data == b"data_blob" + + +def test_raw_predict_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = PredictionServiceClient( credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) - with pytest.raises(ValueError): - client = PredictionServiceClient( - client_options={"credentials_file": "credentials.json"}, - transport=transport, - ) - # It is an error to provide scopes and a transport instance. - transport = transports.PredictionServiceGrpcTransport( + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.raw_predict), "__call__") as call: + client.raw_predict() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == prediction_service.RawPredictRequest() + + +@pytest.mark.asyncio +async def test_raw_predict_async( + transport: str = "grpc_asyncio", request_type=prediction_service.RawPredictRequest +): + client = PredictionServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - with pytest.raises(ValueError): - client = PredictionServiceClient( - client_options={"scopes": ["1", "2"]}, transport=transport, + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.raw_predict), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + httpbody_pb2.HttpBody( + content_type="content_type_value", + data=b"data_blob", + ) ) + response = await client.raw_predict(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == prediction_service.RawPredictRequest() -def test_transport_instance(): - # A client may be instantiated with a custom transport instance. - transport = transports.PredictionServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - client = PredictionServiceClient(transport=transport) - assert client.transport is transport + # Establish that the response is the type that we expect. + assert isinstance(response, httpbody_pb2.HttpBody) + assert response.content_type == "content_type_value" + assert response.data == b"data_blob" -def test_transport_get_channel(): - # A client may be instantiated with a custom transport instance. - transport = transports.PredictionServiceGrpcTransport( +@pytest.mark.asyncio +async def test_raw_predict_async_from_dict(): + await test_raw_predict_async(request_type=dict) + + +def test_raw_predict_field_headers(): + client = PredictionServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) - channel = transport.grpc_channel - assert channel - transport = transports.PredictionServiceGrpcAsyncIOTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = prediction_service.RawPredictRequest() + request.endpoint = "endpoint_value" -@pytest.mark.parametrize( - "transport_class", - [ - transports.PredictionServiceGrpcTransport, - transports.PredictionServiceGrpcAsyncIOTransport, - ], -) -def test_transport_adc(transport_class): - # Test default credentials are used if not provided. - with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class() - adc.assert_called_once() + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.raw_predict), "__call__") as call: + call.return_value = httpbody_pb2.HttpBody() + client.raw_predict(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request -def test_transport_grpc_default(): - # A client should use the gRPC transport by default. - client = PredictionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) - assert isinstance(client.transport, transports.PredictionServiceGrpcTransport,) + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "endpoint=endpoint_value", + ) in kw["metadata"] -def test_prediction_service_base_transport_error(): - # Passing both a credentials object and credentials_file should raise an error - with pytest.raises(core_exceptions.DuplicateCredentialArgs): - transport = transports.PredictionServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), - credentials_file="credentials.json", - ) +@pytest.mark.asyncio +async def test_raw_predict_field_headers_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = prediction_service.RawPredictRequest() -def test_prediction_service_base_transport(): - # Instantiate the base transport. - with mock.patch( - "google.cloud.aiplatform_v1.services.prediction_service.transports.PredictionServiceTransport.__init__" - ) as Transport: - Transport.return_value = None - transport = transports.PredictionServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + request.endpoint = "endpoint_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.raw_predict), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + httpbody_pb2.HttpBody() ) + await client.raw_predict(request) - # Every method on the transport should just blindly - # raise NotImplementedError. - methods = ("predict",) - for method in methods: - with pytest.raises(NotImplementedError): - getattr(transport, method)(request=object()) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "endpoint=endpoint_value", + ) in kw["metadata"] -@requires_google_auth_gte_1_25_0 -def test_prediction_service_base_transport_with_credentials_file(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.aiplatform_v1.services.prediction_service.transports.PredictionServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.PredictionServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=None, - default_scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) +def test_raw_predict_flattened(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) -@requires_google_auth_lt_1_25_0 -def test_prediction_service_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.aiplatform_v1.services.prediction_service.transports.PredictionServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.PredictionServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.raw_predict), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = httpbody_pb2.HttpBody() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.raw_predict( + endpoint="endpoint_value", + http_body=httpbody_pb2.HttpBody(content_type="content_type_value"), ) + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].endpoint + mock_val = "endpoint_value" + assert arg == mock_val + arg = args[0].http_body + mock_val = httpbody_pb2.HttpBody(content_type="content_type_value") + assert arg == mock_val -def test_prediction_service_base_transport_with_adc(): - # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.aiplatform_v1.services.prediction_service.transports.PredictionServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.PredictionServiceTransport() - adc.assert_called_once() +def test_raw_predict_flattened_error(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) -@requires_google_auth_gte_1_25_0 -def test_prediction_service_auth_adc(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - PredictionServiceClient() - adc.assert_called_once_with( - scopes=None, - default_scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.raw_predict( + prediction_service.RawPredictRequest(), + endpoint="endpoint_value", + http_body=httpbody_pb2.HttpBody(content_type="content_type_value"), ) -@requires_google_auth_lt_1_25_0 -def test_prediction_service_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - PredictionServiceClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) +@pytest.mark.asyncio +async def test_raw_predict_flattened_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.raw_predict), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = httpbody_pb2.HttpBody() -@pytest.mark.parametrize( - "transport_class", - [ - transports.PredictionServiceGrpcTransport, - transports.PredictionServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_gte_1_25_0 -def test_prediction_service_transport_auth_adc(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - adc.assert_called_once_with( - scopes=["1", "2"], - default_scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + httpbody_pb2.HttpBody() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.raw_predict( + endpoint="endpoint_value", + http_body=httpbody_pb2.HttpBody(content_type="content_type_value"), ) + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].endpoint + mock_val = "endpoint_value" + assert arg == mock_val + arg = args[0].http_body + mock_val = httpbody_pb2.HttpBody(content_type="content_type_value") + assert arg == mock_val -@pytest.mark.parametrize( - "transport_class", - [ - transports.PredictionServiceGrpcTransport, - transports.PredictionServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_prediction_service_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", + +@pytest.mark.asyncio +async def test_raw_predict_flattened_error_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.raw_predict( + prediction_service.RawPredictRequest(), + endpoint="endpoint_value", + http_body=httpbody_pb2.HttpBody(content_type="content_type_value"), ) @pytest.mark.parametrize( - "transport_class,grpc_helpers", + "request_type", [ - (transports.PredictionServiceGrpcTransport, grpc_helpers), - (transports.PredictionServiceGrpcAsyncIOTransport, grpc_helpers_async), + prediction_service.ExplainRequest, + dict, ], ) -@requires_api_core_gte_1_26_0 -def test_prediction_service_transport_create_channel(transport_class, grpc_helpers): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class(quota_project_id="octopus", scopes=["1", "2"]) +def test_explain(request_type, transport: str = "grpc"): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - default_scopes=("https://www.googleapis.com/auth/cloud-platform",), - scopes=["1", "2"], - default_host="aiplatform.googleapis.com", - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.explain), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = prediction_service.ExplainResponse( + deployed_model_id="deployed_model_id_value", ) + response = client.explain(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == prediction_service.ExplainRequest() -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.PredictionServiceGrpcTransport, grpc_helpers), - (transports.PredictionServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_prediction_service_transport_create_channel_old_api_core( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class(quota_project_id="octopus") + # Establish that the response is the type that we expect. + assert isinstance(response, prediction_service.ExplainResponse) + assert response.deployed_model_id == "deployed_model_id_value" - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) +def test_explain_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.PredictionServiceGrpcTransport, grpc_helpers), - (transports.PredictionServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_prediction_service_transport_create_channel_user_scopes( - transport_class, grpc_helpers + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.explain), "__call__") as call: + client.explain() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == prediction_service.ExplainRequest() + + +@pytest.mark.asyncio +async def test_explain_async( + transport: str = "grpc_asyncio", request_type=prediction_service.ExplainRequest ): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) - transport_class(quota_project_id="octopus", scopes=["1", "2"]) + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=["1", "2"], - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.explain), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + prediction_service.ExplainResponse( + deployed_model_id="deployed_model_id_value", + ) ) + response = await client.explain(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == prediction_service.ExplainRequest() -@pytest.mark.parametrize( - "transport_class", - [ - transports.PredictionServiceGrpcTransport, - transports.PredictionServiceGrpcAsyncIOTransport, - ], -) -def test_prediction_service_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() + # Establish that the response is the type that we expect. + assert isinstance(response, prediction_service.ExplainResponse) + assert response.deployed_model_id == "deployed_model_id_value" - # Check ssl_channel_credentials is used if provided. - with mock.patch.object(transport_class, "create_channel") as mock_create_channel: - mock_ssl_channel_creds = mock.Mock() - transport_class( - host="squid.clam.whelk", - credentials=cred, - ssl_channel_credentials=mock_ssl_channel_creds, - ) - mock_create_channel.assert_called_once_with( - "squid.clam.whelk:443", - credentials=cred, - credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=mock_ssl_channel_creds, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls - # is used. - with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): - with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: - transport_class( - credentials=cred, - client_cert_source_for_mtls=client_cert_source_callback, - ) - expected_cert, expected_key = client_cert_source_callback() - mock_ssl_cred.assert_called_once_with( - certificate_chain=expected_cert, private_key=expected_key - ) +@pytest.mark.asyncio +async def test_explain_async_from_dict(): + await test_explain_async(request_type=dict) -def test_prediction_service_host_no_port(): +def test_explain_field_headers(): client = PredictionServiceClient( credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions( - api_endpoint="aiplatform.googleapis.com" - ), ) - assert client.transport._host == "aiplatform.googleapis.com:443" + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = prediction_service.ExplainRequest() + + request.endpoint = "endpoint_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.explain), "__call__") as call: + call.return_value = prediction_service.ExplainResponse() + client.explain(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "endpoint=endpoint_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_explain_field_headers_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = prediction_service.ExplainRequest() + + request.endpoint = "endpoint_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.explain), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + prediction_service.ExplainResponse() + ) + await client.explain(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "endpoint=endpoint_value", + ) in kw["metadata"] -def test_prediction_service_host_with_port(): +def test_explain_flattened_error(): client = PredictionServiceClient( credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions( - api_endpoint="aiplatform.googleapis.com:8000" - ), ) - assert client.transport._host == "aiplatform.googleapis.com:8000" + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.explain( + prediction_service.ExplainRequest(), + endpoint="endpoint_value", + instances=[struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE)], + parameters=struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE), + deployed_model_id="deployed_model_id_value", + ) -def test_prediction_service_grpc_transport_channel(): - channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) - # Check that channel is used if provided. +@pytest.mark.asyncio +async def test_explain_flattened_error_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.explain( + prediction_service.ExplainRequest(), + endpoint="endpoint_value", + instances=[struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE)], + parameters=struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE), + deployed_model_id="deployed_model_id_value", + ) + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. transport = transports.PredictionServiceGrpcTransport( - host="squid.clam.whelk", channel=channel, + credentials=ga_credentials.AnonymousCredentials(), ) - assert transport.grpc_channel == channel - assert transport._host == "squid.clam.whelk:443" - assert transport._ssl_channel_credentials == None + with pytest.raises(ValueError): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.PredictionServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = PredictionServiceClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + # It is an error to provide an api_key and a transport instance. + transport = transports.PredictionServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = PredictionServiceClient( + client_options=options, + transport=transport, + ) -def test_prediction_service_grpc_asyncio_transport_channel(): - channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = PredictionServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.PredictionServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = PredictionServiceClient( + client_options={"scopes": ["1", "2"]}, + transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.PredictionServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + client = PredictionServiceClient(transport=transport) + assert client.transport is transport + + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.PredictionServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel - # Check that channel is used if provided. transport = transports.PredictionServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", channel=channel, + credentials=ga_credentials.AnonymousCredentials(), ) - assert transport.grpc_channel == channel - assert transport._host == "squid.clam.whelk:443" - assert transport._ssl_channel_credentials == None + channel = transport.grpc_channel + assert channel -# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are -# removed from grpc/grpc_asyncio transport constructor. @pytest.mark.parametrize( "transport_class", [ @@ -1143,233 +1387,2158 @@ def test_prediction_service_grpc_asyncio_transport_channel(): transports.PredictionServiceGrpcAsyncIOTransport, ], ) -def test_prediction_service_transport_channel_mtls_with_client_cert_source( - transport_class, -): - with mock.patch( - "grpc.ssl_channel_credentials", autospec=True - ) as grpc_ssl_channel_cred: - with mock.patch.object( - transport_class, "create_channel" - ) as grpc_create_channel: - mock_ssl_cred = mock.Mock() - grpc_ssl_channel_cred.return_value = mock_ssl_cred +def test_transport_adc(transport_class): + # Test default credentials are used if not provided. + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class() + adc.assert_called_once() + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = PredictionServiceClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + +def test_transport_grpc_default(): + # A client should use the gRPC transport by default. + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.PredictionServiceGrpcTransport, + ) + + +def test_prediction_service_base_transport_error(): + # Passing both a credentials object and credentials_file should raise an error + with pytest.raises(core_exceptions.DuplicateCredentialArgs): + transport = transports.PredictionServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + credentials_file="credentials.json", + ) + + +def test_prediction_service_base_transport(): + # Instantiate the base transport. + with mock.patch( + "google.cloud.aiplatform_v1.services.prediction_service.transports.PredictionServiceTransport.__init__" + ) as Transport: + Transport.return_value = None + transport = transports.PredictionServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Every method on the transport should just blindly + # raise NotImplementedError. + methods = ( + "predict", + "raw_predict", + "explain", + "set_iam_policy", + "get_iam_policy", + "test_iam_permissions", + "get_location", + "list_locations", + "get_operation", + "wait_operation", + "cancel_operation", + "delete_operation", + "list_operations", + ) + for method in methods: + with pytest.raises(NotImplementedError): + getattr(transport, method)(request=object()) + + with pytest.raises(NotImplementedError): + transport.close() + + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + + +def test_prediction_service_base_transport_with_credentials_file(): + # Instantiate the base transport with a credentials file + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch( + "google.cloud.aiplatform_v1.services.prediction_service.transports.PredictionServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.PredictionServiceTransport( + credentials_file="credentials.json", + quota_project_id="octopus", + ) + load_creds.assert_called_once_with( + "credentials.json", + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +def test_prediction_service_base_transport_with_adc(): + # Test the default credentials are used if credentials and credentials_file are None. + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( + "google.cloud.aiplatform_v1.services.prediction_service.transports.PredictionServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.PredictionServiceTransport() + adc.assert_called_once() + + +def test_prediction_service_auth_adc(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + PredictionServiceClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id=None, + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.PredictionServiceGrpcTransport, + transports.PredictionServiceGrpcAsyncIOTransport, + ], +) +def test_prediction_service_transport_auth_adc(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.PredictionServiceGrpcTransport, grpc_helpers), + (transports.PredictionServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +def test_prediction_service_transport_create_channel(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=["1", "2"], + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.PredictionServiceGrpcTransport, + transports.PredictionServiceGrpcAsyncIOTransport, + ], +) +def test_prediction_service_grpc_transport_client_cert_source_for_mtls(transport_class): + cred = ga_credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds, + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback, + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, private_key=expected_key + ) + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_prediction_service_host_no_port(transport_name): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions( + api_endpoint="aiplatform.googleapis.com" + ), + transport=transport_name, + ) + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_prediction_service_host_with_port(transport_name): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions( + api_endpoint="aiplatform.googleapis.com:8000" + ), + transport=transport_name, + ) + assert client.transport._host == ("aiplatform.googleapis.com:8000") + + +def test_prediction_service_grpc_transport_channel(): + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.PredictionServiceGrpcTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +def test_prediction_service_grpc_asyncio_transport_channel(): + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.PredictionServiceGrpcAsyncIOTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize( + "transport_class", + [ + transports.PredictionServiceGrpcTransport, + transports.PredictionServiceGrpcAsyncIOTransport, + ], +) +def test_prediction_service_transport_channel_mtls_with_client_cert_source( + transport_class, +): + with mock.patch( + "grpc.ssl_channel_credentials", autospec=True + ) as grpc_ssl_channel_cred: + with mock.patch.object( + transport_class, "create_channel" + ) as grpc_create_channel: + mock_ssl_cred = mock.Mock() + grpc_ssl_channel_cred.return_value = mock_ssl_cred + + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + + cred = ga_credentials.AnonymousCredentials() + with pytest.warns(DeprecationWarning): + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (cred, None) + transport = transport_class( + host="squid.clam.whelk", + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=client_cert_source_callback, + ) + adc.assert_called_once() + + grpc_ssl_channel_cred.assert_called_once_with( + certificate_chain=b"cert bytes", private_key=b"key bytes" + ) + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize( + "transport_class", + [ + transports.PredictionServiceGrpcTransport, + transports.PredictionServiceGrpcAsyncIOTransport, + ], +) +def test_prediction_service_transport_channel_mtls_with_adc(transport_class): + mock_ssl_cred = mock.Mock() + with mock.patch.multiple( + "google.auth.transport.grpc.SslCredentials", + __init__=mock.Mock(return_value=None), + ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), + ): + with mock.patch.object( + transport_class, "create_channel" + ) as grpc_create_channel: + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + mock_cred = mock.Mock() + + with pytest.warns(DeprecationWarning): + transport = transport_class( + host="squid.clam.whelk", + credentials=mock_cred, + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=None, + ) + + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=mock_cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + + +def test_endpoint_path(): + project = "squid" + location = "clam" + endpoint = "whelk" + expected = "projects/{project}/locations/{location}/endpoints/{endpoint}".format( + project=project, + location=location, + endpoint=endpoint, + ) + actual = PredictionServiceClient.endpoint_path(project, location, endpoint) + assert expected == actual + + +def test_parse_endpoint_path(): + expected = { + "project": "octopus", + "location": "oyster", + "endpoint": "nudibranch", + } + path = PredictionServiceClient.endpoint_path(**expected) + + # Check that the path construction is reversible. + actual = PredictionServiceClient.parse_endpoint_path(path) + assert expected == actual + + +def test_model_path(): + project = "cuttlefish" + location = "mussel" + model = "winkle" + expected = "projects/{project}/locations/{location}/models/{model}".format( + project=project, + location=location, + model=model, + ) + actual = PredictionServiceClient.model_path(project, location, model) + assert expected == actual + + +def test_parse_model_path(): + expected = { + "project": "nautilus", + "location": "scallop", + "model": "abalone", + } + path = PredictionServiceClient.model_path(**expected) + + # Check that the path construction is reversible. + actual = PredictionServiceClient.parse_model_path(path) + assert expected == actual + + +def test_common_billing_account_path(): + billing_account = "squid" + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + actual = PredictionServiceClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "clam", + } + path = PredictionServiceClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = PredictionServiceClient.parse_common_billing_account_path(path) + assert expected == actual + + +def test_common_folder_path(): + folder = "whelk" + expected = "folders/{folder}".format( + folder=folder, + ) + actual = PredictionServiceClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "octopus", + } + path = PredictionServiceClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = PredictionServiceClient.parse_common_folder_path(path) + assert expected == actual + + +def test_common_organization_path(): + organization = "oyster" + expected = "organizations/{organization}".format( + organization=organization, + ) + actual = PredictionServiceClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "nudibranch", + } + path = PredictionServiceClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = PredictionServiceClient.parse_common_organization_path(path) + assert expected == actual + + +def test_common_project_path(): + project = "cuttlefish" + expected = "projects/{project}".format( + project=project, + ) + actual = PredictionServiceClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "mussel", + } + path = PredictionServiceClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = PredictionServiceClient.parse_common_project_path(path) + assert expected == actual + + +def test_common_location_path(): + project = "winkle" + location = "nautilus" + expected = "projects/{project}/locations/{location}".format( + project=project, + location=location, + ) + actual = PredictionServiceClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "scallop", + "location": "abalone", + } + path = PredictionServiceClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = PredictionServiceClient.parse_common_location_path(path) + assert expected == actual + + +def test_client_with_default_client_info(): + client_info = gapic_v1.client_info.ClientInfo() + + with mock.patch.object( + transports.PredictionServiceTransport, "_prep_wrapped_messages" + ) as prep: + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + with mock.patch.object( + transports.PredictionServiceTransport, "_prep_wrapped_messages" + ) as prep: + transport_class = PredictionServiceClient.get_transport_class() + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_delete_operation(transport: str = "grpc"): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_operation(transport: str = "grpc"): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_operation_field_headers(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = None + + client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_operation_field_headers_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_delete_operation_from_dict(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_delete_operation_from_dict_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_cancel_operation(transport: str = "grpc"): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation(transport: str = "grpc"): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_wait_operation(transport: str = "grpc"): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_wait_operation(transport: str = "grpc"): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_wait_operation_field_headers(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_wait_operation_field_headers_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_wait_operation_from_dict(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_wait_operation_from_dict_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_operation(transport: str = "grpc"): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_get_operation(transport: str = "grpc"): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_get_operation_field_headers(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_get_operation_from_dict(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_operations(transport: str = "grpc"): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + response = client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +@pytest.mark.asyncio +async def test_list_operations(transport: str = "grpc"): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +def test_list_operations_field_headers(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_operations_field_headers_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_operations_from_dict(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + response = client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_operations_from_dict_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_locations(transport: str = "grpc"): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + response = client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +@pytest.mark.asyncio +async def test_list_locations(transport: str = "grpc"): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +def test_list_locations_field_headers(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_locations_field_headers_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_locations_from_dict(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + response = client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_locations_from_dict_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_location(transport: str = "grpc"): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + response = client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +@pytest.mark.asyncio +async def test_get_location_async(transport: str = "grpc_asyncio"): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +def test_get_location_field_headers(): + client = PredictionServiceClient(credentials=ga_credentials.AnonymousCredentials()) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = locations_pb2.Location() + + client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_location_field_headers_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials() + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +def test_get_location_from_dict(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + response = client.get_location( + request={ + "name": "locations/abc", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_location_from_dict_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_set_iam_policy(transport: str = "grpc"): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + response = client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + response = await client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_set_iam_policy_field_headers(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_set_iam_policy_field_headers_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_set_iam_policy_from_dict(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_set_iam_policy_from_dict_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +def test_get_iam_policy(transport: str = "grpc"): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + + response = client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + + response = await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_get_iam_policy_field_headers(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_iam_policy_field_headers_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_get_iam_policy_from_dict(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_iam_policy_from_dict_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +def test_test_iam_permissions(transport: str = "grpc"): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() - cred = ga_credentials.AnonymousCredentials() - with pytest.warns(DeprecationWarning): - with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (cred, None) - transport = transport_class( - host="squid.clam.whelk", - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=client_cert_source_callback, - ) - adc.assert_called_once() + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) - grpc_ssl_channel_cred.assert_called_once_with( - certificate_chain=b"cert bytes", private_key=b"key bytes" - ) - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=cred, - credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - assert transport.grpc_channel == mock_grpc_channel - assert transport._ssl_channel_credentials == mock_ssl_cred + response = client.test_iam_permissions(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] -# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are -# removed from grpc/grpc_asyncio transport constructor. -@pytest.mark.parametrize( - "transport_class", - [ - transports.PredictionServiceGrpcTransport, - transports.PredictionServiceGrpcAsyncIOTransport, - ], -) -def test_prediction_service_transport_channel_mtls_with_adc(transport_class): - mock_ssl_cred = mock.Mock() - with mock.patch.multiple( - "google.auth.transport.grpc.SslCredentials", - __init__=mock.Mock(return_value=None), - ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), - ): - with mock.patch.object( - transport_class, "create_channel" - ) as grpc_create_channel: - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel - mock_cred = mock.Mock() + assert args[0] == request - with pytest.warns(DeprecationWarning): - transport = transport_class( - host="squid.clam.whelk", - credentials=mock_cred, - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=None, - ) + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=mock_cred, - credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - assert transport.grpc_channel == mock_grpc_channel + assert response.permissions == ["permissions_value"] -def test_endpoint_path(): - project = "squid" - location = "clam" - endpoint = "whelk" - expected = "projects/{project}/locations/{location}/endpoints/{endpoint}".format( - project=project, location=location, endpoint=endpoint, +@pytest.mark.asyncio +async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - actual = PredictionServiceClient.endpoint_path(project, location, endpoint) - assert expected == actual + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() -def test_parse_endpoint_path(): - expected = { - "project": "octopus", - "location": "oyster", - "endpoint": "nudibranch", - } - path = PredictionServiceClient.endpoint_path(**expected) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + ) - # Check that the path construction is reversible. - actual = PredictionServiceClient.parse_endpoint_path(path) - assert expected == actual + response = await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request -def test_common_billing_account_path(): - billing_account = "cuttlefish" - expected = "billingAccounts/{billing_account}".format( - billing_account=billing_account, - ) - actual = PredictionServiceClient.common_billing_account_path(billing_account) - assert expected == actual + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + assert response.permissions == ["permissions_value"] -def test_parse_common_billing_account_path(): - expected = { - "billing_account": "mussel", - } - path = PredictionServiceClient.common_billing_account_path(**expected) - # Check that the path construction is reversible. - actual = PredictionServiceClient.parse_common_billing_account_path(path) - assert expected == actual +def test_test_iam_permissions_field_headers(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" -def test_common_folder_path(): - folder = "winkle" - expected = "folders/{folder}".format(folder=folder,) - actual = PredictionServiceClient.common_folder_path(folder) - assert expected == actual + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + client.test_iam_permissions(request) -def test_parse_common_folder_path(): - expected = { - "folder": "nautilus", - } - path = PredictionServiceClient.common_folder_path(**expected) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request - # Check that the path construction is reversible. - actual = PredictionServiceClient.parse_common_folder_path(path) - assert expected == actual + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] -def test_common_organization_path(): - organization = "scallop" - expected = "organizations/{organization}".format(organization=organization,) - actual = PredictionServiceClient.common_organization_path(organization) - assert expected == actual +@pytest.mark.asyncio +async def test_test_iam_permissions_field_headers_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" -def test_parse_common_organization_path(): - expected = { - "organization": "abalone", - } - path = PredictionServiceClient.common_organization_path(**expected) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) - # Check that the path construction is reversible. - actual = PredictionServiceClient.parse_common_organization_path(path) - assert expected == actual + await client.test_iam_permissions(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request -def test_common_project_path(): - project = "squid" - expected = "projects/{project}".format(project=project,) - actual = PredictionServiceClient.common_project_path(project) - assert expected == actual + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] -def test_parse_common_project_path(): - expected = { - "project": "clam", - } - path = PredictionServiceClient.common_project_path(**expected) +def test_test_iam_permissions_from_dict(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() - # Check that the path construction is reversible. - actual = PredictionServiceClient.parse_common_project_path(path) - assert expected == actual + response = client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() -def test_common_location_path(): - project = "whelk" - location = "octopus" - expected = "projects/{project}/locations/{location}".format( - project=project, location=location, +@pytest.mark.asyncio +async def test_test_iam_permissions_from_dict_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), ) - actual = PredictionServiceClient.common_location_path(project, location) - assert expected == actual + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + response = await client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() -def test_parse_common_location_path(): - expected = { - "project": "oyster", - "location": "nudibranch", - } - path = PredictionServiceClient.common_location_path(**expected) - # Check that the path construction is reversible. - actual = PredictionServiceClient.parse_common_location_path(path) - assert expected == actual +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + for transport, close_name in transports.items(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() -def test_client_withDEFAULT_CLIENT_INFO(): - client_info = gapic_v1.client_info.ClientInfo() - with mock.patch.object( - transports.PredictionServiceTransport, "_prep_wrapped_messages" - ) as prep: +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: client = PredictionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), transport=transport ) - prep.assert_called_once_with(client_info) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (PredictionServiceClient, transports.PredictionServiceGrpcTransport), + ( + PredictionServiceAsyncClient, + transports.PredictionServiceGrpcAsyncIOTransport, + ), + ], +) +def test_api_key_credentials(client_class, transport_class): with mock.patch.object( - transports.PredictionServiceTransport, "_prep_wrapped_messages" - ) as prep: - transport_class = PredictionServiceClient.get_transport_class() - transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, - ) - prep.assert_called_once_with(client_info) + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) diff --git a/tests/unit/gapic/aiplatform_v1/test_specialist_pool_service.py b/tests/unit/gapic/aiplatform_v1/test_specialist_pool_service.py index 2f54d4b68c..00d931af2d 100644 --- a/tests/unit/gapic/aiplatform_v1/test_specialist_pool_service.py +++ b/tests/unit/gapic/aiplatform_v1/test_specialist_pool_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,8 +14,13 @@ # limitations under the License. # import os -import mock -import packaging.version + +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock +except ImportError: + import mock import grpc from grpc.experimental import aio @@ -30,8 +35,10 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.aiplatform_v1.services.specialist_pool_service import ( @@ -42,45 +49,20 @@ ) from google.cloud.aiplatform_v1.services.specialist_pool_service import pagers from google.cloud.aiplatform_v1.services.specialist_pool_service import transports -from google.cloud.aiplatform_v1.services.specialist_pool_service.transports.base import ( - _API_CORE_VERSION, -) -from google.cloud.aiplatform_v1.services.specialist_pool_service.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.aiplatform_v1.types import operation as gca_operation from google.cloud.aiplatform_v1.types import specialist_pool from google.cloud.aiplatform_v1.types import specialist_pool as gca_specialist_pool from google.cloud.aiplatform_v1.types import specialist_pool_service +from google.cloud.location import locations_pb2 +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 from google.oauth2 import service_account from google.protobuf import field_mask_pb2 # type: ignore import google.auth -# TODO(busunkim): Once google-api-core >= 1.26.0 is required: -# - Delete all the api-core and auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - -requires_api_core_lt_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), - reason="This test requires google-api-core < 1.26.0", -) - -requires_api_core_gte_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), - reason="This test requires google-api-core >= 1.26.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -127,40 +109,81 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( - "client_class", [SpecialistPoolServiceClient, SpecialistPoolServiceAsyncClient,] + "client_class,transport_name", + [ + (SpecialistPoolServiceClient, "grpc"), + (SpecialistPoolServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_specialist_pool_service_client_from_service_account_info(client_class): +def test_specialist_pool_service_client_from_service_account_info( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.SpecialistPoolServiceGrpcTransport, "grpc"), + (transports.SpecialistPoolServiceGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_specialist_pool_service_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() @pytest.mark.parametrize( - "client_class", [SpecialistPoolServiceClient, SpecialistPoolServiceAsyncClient,] + "client_class,transport_name", + [ + (SpecialistPoolServiceClient, "grpc"), + (SpecialistPoolServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_specialist_pool_service_client_from_service_account_file(client_class): +def test_specialist_pool_service_client_from_service_account_file( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") def test_specialist_pool_service_client_get_transport_class(): @@ -217,7 +240,7 @@ def test_specialist_pool_service_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -226,6 +249,7 @@ def test_specialist_pool_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -233,7 +257,7 @@ def test_specialist_pool_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -242,6 +266,7 @@ def test_specialist_pool_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -249,7 +274,7 @@ def test_specialist_pool_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -258,26 +283,27 @@ def test_specialist_pool_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -286,6 +312,7 @@ def test_specialist_pool_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -345,7 +372,7 @@ def test_specialist_pool_service_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -362,6 +389,7 @@ def test_specialist_pool_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case ADC client cert is provided. Whether client cert is used depends on @@ -386,7 +414,7 @@ def test_specialist_pool_service_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -395,6 +423,7 @@ def test_specialist_pool_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case client_cert_source and ADC client cert are not provided. @@ -407,7 +436,7 @@ def test_specialist_pool_service_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -416,9 +445,91 @@ def test_specialist_pool_service_client_mtls_env_auto( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) +@pytest.mark.parametrize( + "client_class", [SpecialistPoolServiceClient, SpecialistPoolServiceAsyncClient] +) +@mock.patch.object( + SpecialistPoolServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(SpecialistPoolServiceClient), +) +@mock.patch.object( + SpecialistPoolServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(SpecialistPoolServiceAsyncClient), +) +def test_specialist_pool_service_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + @pytest.mark.parametrize( "client_class,transport_class,transport_name", [ @@ -438,10 +549,12 @@ def test_specialist_pool_service_client_client_options_scopes( client_class, transport_class, transport_name ): # Check the case scopes are provided. - options = client_options.ClientOptions(scopes=["1", "2"],) + options = client_options.ClientOptions( + scopes=["1", "2"], + ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -450,32 +563,36 @@ def test_specialist_pool_service_client_client_options_scopes( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ ( SpecialistPoolServiceClient, transports.SpecialistPoolServiceGrpcTransport, "grpc", + grpc_helpers, ), ( SpecialistPoolServiceAsyncClient, transports.SpecialistPoolServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_specialist_pool_service_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -484,6 +601,7 @@ def test_specialist_pool_service_client_client_options_credentials_file( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -503,15 +621,87 @@ def test_specialist_pool_service_client_client_options_from_dict(): client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) -def test_create_specialist_pool( - transport: str = "grpc", - request_type=specialist_pool_service.CreateSpecialistPoolRequest, +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + SpecialistPoolServiceClient, + transports.SpecialistPoolServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + SpecialistPoolServiceAsyncClient, + transports.SpecialistPoolServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_specialist_pool_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers ): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + specialist_pool_service.CreateSpecialistPoolRequest, + dict, + ], +) +def test_create_specialist_pool(request_type, transport: str = "grpc"): client = SpecialistPoolServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -535,15 +725,12 @@ def test_create_specialist_pool( assert isinstance(response, future.Future) -def test_create_specialist_pool_from_dict(): - test_create_specialist_pool(request_type=dict) - - def test_create_specialist_pool_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SpecialistPoolServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -562,7 +749,8 @@ async def test_create_specialist_pool_async( request_type=specialist_pool_service.CreateSpecialistPoolRequest, ): client = SpecialistPoolServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -602,7 +790,7 @@ def test_create_specialist_pool_field_headers(): # a field header. Set these to a non-empty value. request = specialist_pool_service.CreateSpecialistPoolRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -618,7 +806,10 @@ def test_create_specialist_pool_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -631,7 +822,7 @@ async def test_create_specialist_pool_field_headers_async(): # a field header. Set these to a non-empty value. request = specialist_pool_service.CreateSpecialistPoolRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -649,7 +840,10 @@ async def test_create_specialist_pool_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_create_specialist_pool_flattened(): @@ -674,10 +868,12 @@ def test_create_specialist_pool_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].specialist_pool == gca_specialist_pool.SpecialistPool( - name="name_value" - ) + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].specialist_pool + mock_val = gca_specialist_pool.SpecialistPool(name="name_value") + assert arg == mock_val def test_create_specialist_pool_flattened_error(): @@ -722,10 +918,12 @@ async def test_create_specialist_pool_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].specialist_pool == gca_specialist_pool.SpecialistPool( - name="name_value" - ) + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].specialist_pool + mock_val = gca_specialist_pool.SpecialistPool(name="name_value") + assert arg == mock_val @pytest.mark.asyncio @@ -744,12 +942,17 @@ async def test_create_specialist_pool_flattened_error_async(): ) -def test_get_specialist_pool( - transport: str = "grpc", - request_type=specialist_pool_service.GetSpecialistPoolRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + specialist_pool_service.GetSpecialistPoolRequest, + dict, + ], +) +def test_get_specialist_pool(request_type, transport: str = "grpc"): client = SpecialistPoolServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -767,6 +970,7 @@ def test_get_specialist_pool( specialist_managers_count=2662, specialist_manager_emails=["specialist_manager_emails_value"], pending_data_labeling_jobs=["pending_data_labeling_jobs_value"], + specialist_worker_emails=["specialist_worker_emails_value"], ) response = client.get_specialist_pool(request) @@ -782,17 +986,15 @@ def test_get_specialist_pool( assert response.specialist_managers_count == 2662 assert response.specialist_manager_emails == ["specialist_manager_emails_value"] assert response.pending_data_labeling_jobs == ["pending_data_labeling_jobs_value"] - - -def test_get_specialist_pool_from_dict(): - test_get_specialist_pool(request_type=dict) + assert response.specialist_worker_emails == ["specialist_worker_emails_value"] def test_get_specialist_pool_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SpecialistPoolServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -811,7 +1013,8 @@ async def test_get_specialist_pool_async( request_type=specialist_pool_service.GetSpecialistPoolRequest, ): client = SpecialistPoolServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -830,6 +1033,7 @@ async def test_get_specialist_pool_async( specialist_managers_count=2662, specialist_manager_emails=["specialist_manager_emails_value"], pending_data_labeling_jobs=["pending_data_labeling_jobs_value"], + specialist_worker_emails=["specialist_worker_emails_value"], ) ) response = await client.get_specialist_pool(request) @@ -846,6 +1050,7 @@ async def test_get_specialist_pool_async( assert response.specialist_managers_count == 2662 assert response.specialist_manager_emails == ["specialist_manager_emails_value"] assert response.pending_data_labeling_jobs == ["pending_data_labeling_jobs_value"] + assert response.specialist_worker_emails == ["specialist_worker_emails_value"] @pytest.mark.asyncio @@ -862,7 +1067,7 @@ def test_get_specialist_pool_field_headers(): # a field header. Set these to a non-empty value. request = specialist_pool_service.GetSpecialistPoolRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -878,7 +1083,10 @@ def test_get_specialist_pool_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -891,7 +1099,7 @@ async def test_get_specialist_pool_field_headers_async(): # a field header. Set these to a non-empty value. request = specialist_pool_service.GetSpecialistPoolRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -909,7 +1117,10 @@ async def test_get_specialist_pool_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_get_specialist_pool_flattened(): @@ -925,13 +1136,17 @@ def test_get_specialist_pool_flattened(): call.return_value = specialist_pool.SpecialistPool() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_specialist_pool(name="name_value",) + client.get_specialist_pool( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_specialist_pool_flattened_error(): @@ -943,7 +1158,8 @@ def test_get_specialist_pool_flattened_error(): # fields is an error. with pytest.raises(ValueError): client.get_specialist_pool( - specialist_pool_service.GetSpecialistPoolRequest(), name="name_value", + specialist_pool_service.GetSpecialistPoolRequest(), + name="name_value", ) @@ -965,13 +1181,17 @@ async def test_get_specialist_pool_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_specialist_pool(name="name_value",) + response = await client.get_specialist_pool( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -984,16 +1204,22 @@ async def test_get_specialist_pool_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.get_specialist_pool( - specialist_pool_service.GetSpecialistPoolRequest(), name="name_value", + specialist_pool_service.GetSpecialistPoolRequest(), + name="name_value", ) -def test_list_specialist_pools( - transport: str = "grpc", - request_type=specialist_pool_service.ListSpecialistPoolsRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + specialist_pool_service.ListSpecialistPoolsRequest, + dict, + ], +) +def test_list_specialist_pools(request_type, transport: str = "grpc"): client = SpecialistPoolServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1020,15 +1246,12 @@ def test_list_specialist_pools( assert response.next_page_token == "next_page_token_value" -def test_list_specialist_pools_from_dict(): - test_list_specialist_pools(request_type=dict) - - def test_list_specialist_pools_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SpecialistPoolServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1047,7 +1270,8 @@ async def test_list_specialist_pools_async( request_type=specialist_pool_service.ListSpecialistPoolsRequest, ): client = SpecialistPoolServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1090,7 +1314,7 @@ def test_list_specialist_pools_field_headers(): # a field header. Set these to a non-empty value. request = specialist_pool_service.ListSpecialistPoolsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1106,7 +1330,10 @@ def test_list_specialist_pools_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1119,7 +1346,7 @@ async def test_list_specialist_pools_field_headers_async(): # a field header. Set these to a non-empty value. request = specialist_pool_service.ListSpecialistPoolsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1137,7 +1364,10 @@ async def test_list_specialist_pools_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_specialist_pools_flattened(): @@ -1153,13 +1383,17 @@ def test_list_specialist_pools_flattened(): call.return_value = specialist_pool_service.ListSpecialistPoolsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_specialist_pools(parent="parent_value",) + client.list_specialist_pools( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_specialist_pools_flattened_error(): @@ -1171,7 +1405,8 @@ def test_list_specialist_pools_flattened_error(): # fields is an error. with pytest.raises(ValueError): client.list_specialist_pools( - specialist_pool_service.ListSpecialistPoolsRequest(), parent="parent_value", + specialist_pool_service.ListSpecialistPoolsRequest(), + parent="parent_value", ) @@ -1193,13 +1428,17 @@ async def test_list_specialist_pools_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_specialist_pools(parent="parent_value",) + response = await client.list_specialist_pools( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1212,13 +1451,15 @@ async def test_list_specialist_pools_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.list_specialist_pools( - specialist_pool_service.ListSpecialistPoolsRequest(), parent="parent_value", + specialist_pool_service.ListSpecialistPoolsRequest(), + parent="parent_value", ) -def test_list_specialist_pools_pager(): +def test_list_specialist_pools_pager(transport_name: str = "grpc"): client = SpecialistPoolServiceClient( credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1236,10 +1477,13 @@ def test_list_specialist_pools_pager(): next_page_token="abc", ), specialist_pool_service.ListSpecialistPoolsResponse( - specialist_pools=[], next_page_token="def", + specialist_pools=[], + next_page_token="def", ), specialist_pool_service.ListSpecialistPoolsResponse( - specialist_pools=[specialist_pool.SpecialistPool(),], + specialist_pools=[ + specialist_pool.SpecialistPool(), + ], next_page_token="ghi", ), specialist_pool_service.ListSpecialistPoolsResponse( @@ -1259,14 +1503,15 @@ def test_list_specialist_pools_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all(isinstance(i, specialist_pool.SpecialistPool) for i in results) -def test_list_specialist_pools_pages(): +def test_list_specialist_pools_pages(transport_name: str = "grpc"): client = SpecialistPoolServiceClient( credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1284,10 +1529,13 @@ def test_list_specialist_pools_pages(): next_page_token="abc", ), specialist_pool_service.ListSpecialistPoolsResponse( - specialist_pools=[], next_page_token="def", + specialist_pools=[], + next_page_token="def", ), specialist_pool_service.ListSpecialistPoolsResponse( - specialist_pools=[specialist_pool.SpecialistPool(),], + specialist_pools=[ + specialist_pool.SpecialistPool(), + ], next_page_token="ghi", ), specialist_pool_service.ListSpecialistPoolsResponse( @@ -1326,10 +1574,13 @@ async def test_list_specialist_pools_async_pager(): next_page_token="abc", ), specialist_pool_service.ListSpecialistPoolsResponse( - specialist_pools=[], next_page_token="def", + specialist_pools=[], + next_page_token="def", ), specialist_pool_service.ListSpecialistPoolsResponse( - specialist_pools=[specialist_pool.SpecialistPool(),], + specialist_pools=[ + specialist_pool.SpecialistPool(), + ], next_page_token="ghi", ), specialist_pool_service.ListSpecialistPoolsResponse( @@ -1340,10 +1591,12 @@ async def test_list_specialist_pools_async_pager(): ), RuntimeError, ) - async_pager = await client.list_specialist_pools(request={},) + async_pager = await client.list_specialist_pools( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -1373,10 +1626,13 @@ async def test_list_specialist_pools_async_pages(): next_page_token="abc", ), specialist_pool_service.ListSpecialistPoolsResponse( - specialist_pools=[], next_page_token="def", + specialist_pools=[], + next_page_token="def", ), specialist_pool_service.ListSpecialistPoolsResponse( - specialist_pools=[specialist_pool.SpecialistPool(),], + specialist_pools=[ + specialist_pool.SpecialistPool(), + ], next_page_token="ghi", ), specialist_pool_service.ListSpecialistPoolsResponse( @@ -1388,18 +1644,25 @@ async def test_list_specialist_pools_async_pages(): RuntimeError, ) pages = [] - async for page_ in (await client.list_specialist_pools(request={})).pages: + async for page_ in ( + await client.list_specialist_pools(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_delete_specialist_pool( - transport: str = "grpc", - request_type=specialist_pool_service.DeleteSpecialistPoolRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + specialist_pool_service.DeleteSpecialistPoolRequest, + dict, + ], +) +def test_delete_specialist_pool(request_type, transport: str = "grpc"): client = SpecialistPoolServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1423,15 +1686,12 @@ def test_delete_specialist_pool( assert isinstance(response, future.Future) -def test_delete_specialist_pool_from_dict(): - test_delete_specialist_pool(request_type=dict) - - def test_delete_specialist_pool_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SpecialistPoolServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1450,7 +1710,8 @@ async def test_delete_specialist_pool_async( request_type=specialist_pool_service.DeleteSpecialistPoolRequest, ): client = SpecialistPoolServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1490,7 +1751,7 @@ def test_delete_specialist_pool_field_headers(): # a field header. Set these to a non-empty value. request = specialist_pool_service.DeleteSpecialistPoolRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1506,7 +1767,10 @@ def test_delete_specialist_pool_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1519,7 +1783,7 @@ async def test_delete_specialist_pool_field_headers_async(): # a field header. Set these to a non-empty value. request = specialist_pool_service.DeleteSpecialistPoolRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1537,7 +1801,10 @@ async def test_delete_specialist_pool_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_delete_specialist_pool_flattened(): @@ -1553,13 +1820,17 @@ def test_delete_specialist_pool_flattened(): call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_specialist_pool(name="name_value",) + client.delete_specialist_pool( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_delete_specialist_pool_flattened_error(): @@ -1571,7 +1842,8 @@ def test_delete_specialist_pool_flattened_error(): # fields is an error. with pytest.raises(ValueError): client.delete_specialist_pool( - specialist_pool_service.DeleteSpecialistPoolRequest(), name="name_value", + specialist_pool_service.DeleteSpecialistPoolRequest(), + name="name_value", ) @@ -1593,13 +1865,17 @@ async def test_delete_specialist_pool_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_specialist_pool(name="name_value",) + response = await client.delete_specialist_pool( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1612,16 +1888,22 @@ async def test_delete_specialist_pool_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.delete_specialist_pool( - specialist_pool_service.DeleteSpecialistPoolRequest(), name="name_value", + specialist_pool_service.DeleteSpecialistPoolRequest(), + name="name_value", ) -def test_update_specialist_pool( - transport: str = "grpc", - request_type=specialist_pool_service.UpdateSpecialistPoolRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + specialist_pool_service.UpdateSpecialistPoolRequest, + dict, + ], +) +def test_update_specialist_pool(request_type, transport: str = "grpc"): client = SpecialistPoolServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1645,15 +1927,12 @@ def test_update_specialist_pool( assert isinstance(response, future.Future) -def test_update_specialist_pool_from_dict(): - test_update_specialist_pool(request_type=dict) - - def test_update_specialist_pool_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SpecialistPoolServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1672,7 +1951,8 @@ async def test_update_specialist_pool_async( request_type=specialist_pool_service.UpdateSpecialistPoolRequest, ): client = SpecialistPoolServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1712,7 +1992,7 @@ def test_update_specialist_pool_field_headers(): # a field header. Set these to a non-empty value. request = specialist_pool_service.UpdateSpecialistPoolRequest() - request.specialist_pool.name = "specialist_pool.name/value" + request.specialist_pool.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1730,7 +2010,7 @@ def test_update_specialist_pool_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "specialist_pool.name=specialist_pool.name/value", + "specialist_pool.name=name_value", ) in kw["metadata"] @@ -1744,7 +2024,7 @@ async def test_update_specialist_pool_field_headers_async(): # a field header. Set these to a non-empty value. request = specialist_pool_service.UpdateSpecialistPoolRequest() - request.specialist_pool.name = "specialist_pool.name/value" + request.specialist_pool.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1764,7 +2044,7 @@ async def test_update_specialist_pool_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "specialist_pool.name=specialist_pool.name/value", + "specialist_pool.name=name_value", ) in kw["metadata"] @@ -1790,10 +2070,12 @@ def test_update_specialist_pool_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].specialist_pool == gca_specialist_pool.SpecialistPool( - name="name_value" - ) - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].specialist_pool + mock_val = gca_specialist_pool.SpecialistPool(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val def test_update_specialist_pool_flattened_error(): @@ -1838,10 +2120,12 @@ async def test_update_specialist_pool_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].specialist_pool == gca_specialist_pool.SpecialistPool( - name="name_value" - ) - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].specialist_pool + mock_val = gca_specialist_pool.SpecialistPool(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val @pytest.mark.asyncio @@ -1867,7 +2151,8 @@ def test_credentials_transport_error(): ) with pytest.raises(ValueError): client = SpecialistPoolServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # It is an error to provide a credentials file and a transport instance. @@ -1880,13 +2165,34 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.SpecialistPoolServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = SpecialistPoolServiceClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = SpecialistPoolServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.SpecialistPoolServiceGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = SpecialistPoolServiceClient( - client_options={"scopes": ["1", "2"]}, transport=transport, + client_options={"scopes": ["1", "2"]}, + transport=transport, ) @@ -1929,12 +2235,28 @@ def test_transport_adc(transport_class): adc.assert_called_once() +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = SpecialistPoolServiceClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = SpecialistPoolServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) - assert isinstance(client.transport, transports.SpecialistPoolServiceGrpcTransport,) + assert isinstance( + client.transport, + transports.SpecialistPoolServiceGrpcTransport, + ) def test_specialist_pool_service_base_transport_error(): @@ -1964,18 +2286,38 @@ def test_specialist_pool_service_base_transport(): "list_specialist_pools", "delete_specialist_pool", "update_specialist_pool", + "set_iam_policy", + "get_iam_policy", + "test_iam_permissions", + "get_location", + "list_locations", + "get_operation", + "wait_operation", + "cancel_operation", + "delete_operation", + "list_operations", ) for method in methods: with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + # Additionally, the LRO client (a property) should # also raise NotImplementedError with pytest.raises(NotImplementedError): transport.operations_client + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + -@requires_google_auth_gte_1_25_0 def test_specialist_pool_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -1986,7 +2328,8 @@ def test_specialist_pool_service_base_transport_with_credentials_file(): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SpecialistPoolServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", + credentials_file="credentials.json", + quota_project_id="octopus", ) load_creds.assert_called_once_with( "credentials.json", @@ -1996,26 +2339,6 @@ def test_specialist_pool_service_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_specialist_pool_service_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.aiplatform_v1.services.specialist_pool_service.transports.SpecialistPoolServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.SpecialistPoolServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - def test_specialist_pool_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( @@ -2027,7 +2350,6 @@ def test_specialist_pool_service_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_specialist_pool_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -2040,18 +2362,6 @@ def test_specialist_pool_service_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_specialist_pool_service_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - SpecialistPoolServiceClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -2059,7 +2369,6 @@ def test_specialist_pool_service_auth_adc_old_google_auth(): transports.SpecialistPoolServiceGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_specialist_pool_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -2073,26 +2382,6 @@ def test_specialist_pool_service_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.SpecialistPoolServiceGrpcTransport, - transports.SpecialistPoolServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_specialist_pool_service_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ @@ -2100,7 +2389,6 @@ def test_specialist_pool_service_transport_auth_adc_old_google_auth(transport_cl (transports.SpecialistPoolServiceGrpcAsyncIOTransport, grpc_helpers_async), ], ) -@requires_api_core_gte_1_26_0 def test_specialist_pool_service_transport_create_channel( transport_class, grpc_helpers ): @@ -2131,79 +2419,6 @@ def test_specialist_pool_service_transport_create_channel( ) -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.SpecialistPoolServiceGrpcTransport, grpc_helpers), - (transports.SpecialistPoolServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_specialist_pool_service_transport_create_channel_old_api_core( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class(quota_project_id="octopus") - - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.SpecialistPoolServiceGrpcTransport, grpc_helpers), - (transports.SpecialistPoolServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_specialist_pool_service_transport_create_channel_user_scopes( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=["1", "2"], - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -2228,7 +2443,7 @@ def test_specialist_pool_service_grpc_transport_client_cert_source_for_mtls( "squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_channel_creds, quota_project_id=None, options=[ @@ -2251,24 +2466,40 @@ def test_specialist_pool_service_grpc_transport_client_cert_source_for_mtls( ) -def test_specialist_pool_service_host_no_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_specialist_pool_service_host_no_port(transport_name): client = SpecialistPoolServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="aiplatform.googleapis.com" ), + transport=transport_name, ) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") -def test_specialist_pool_service_host_with_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_specialist_pool_service_host_with_port(transport_name): client = SpecialistPoolServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="aiplatform.googleapis.com:8000" ), + transport=transport_name, ) - assert client.transport._host == "aiplatform.googleapis.com:8000" + assert client.transport._host == ("aiplatform.googleapis.com:8000") def test_specialist_pool_service_grpc_transport_channel(): @@ -2276,7 +2507,8 @@ def test_specialist_pool_service_grpc_transport_channel(): # Check that channel is used if provided. transport = transports.SpecialistPoolServiceGrpcTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -2288,7 +2520,8 @@ def test_specialist_pool_service_grpc_asyncio_transport_channel(): # Check that channel is used if provided. transport = transports.SpecialistPoolServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -2337,7 +2570,7 @@ def test_specialist_pool_service_transport_channel_mtls_with_client_cert_source( "mtls.squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -2384,7 +2617,7 @@ def test_specialist_pool_service_transport_channel_mtls_with_adc(transport_class "mtls.squid.clam.whelk:443", credentials=mock_cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -2397,12 +2630,16 @@ def test_specialist_pool_service_transport_channel_mtls_with_adc(transport_class def test_specialist_pool_service_grpc_lro_client(): client = SpecialistPoolServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -2410,12 +2647,16 @@ def test_specialist_pool_service_grpc_lro_client(): def test_specialist_pool_service_grpc_lro_async_client(): client = SpecialistPoolServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -2426,7 +2667,9 @@ def test_specialist_pool_path(): location = "clam" specialist_pool = "whelk" expected = "projects/{project}/locations/{location}/specialistPools/{specialist_pool}".format( - project=project, location=location, specialist_pool=specialist_pool, + project=project, + location=location, + specialist_pool=specialist_pool, ) actual = SpecialistPoolServiceClient.specialist_pool_path( project, location, specialist_pool @@ -2469,7 +2712,9 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "winkle" - expected = "folders/{folder}".format(folder=folder,) + expected = "folders/{folder}".format( + folder=folder, + ) actual = SpecialistPoolServiceClient.common_folder_path(folder) assert expected == actual @@ -2487,7 +2732,9 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "scallop" - expected = "organizations/{organization}".format(organization=organization,) + expected = "organizations/{organization}".format( + organization=organization, + ) actual = SpecialistPoolServiceClient.common_organization_path(organization) assert expected == actual @@ -2505,7 +2752,9 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "squid" - expected = "projects/{project}".format(project=project,) + expected = "projects/{project}".format( + project=project, + ) actual = SpecialistPoolServiceClient.common_project_path(project) assert expected == actual @@ -2525,7 +2774,8 @@ def test_common_location_path(): project = "whelk" location = "octopus" expected = "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) actual = SpecialistPoolServiceClient.common_location_path(project, location) assert expected == actual @@ -2543,14 +2793,15 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( transports.SpecialistPoolServiceTransport, "_prep_wrapped_messages" ) as prep: client = SpecialistPoolServiceClient( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2559,6 +2810,1598 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = SpecialistPoolServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_delete_operation(transport: str = "grpc"): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_operation(transport: str = "grpc"): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_operation_field_headers(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = None + + client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_operation_field_headers_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_delete_operation_from_dict(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_delete_operation_from_dict_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_cancel_operation(transport: str = "grpc"): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation(transport: str = "grpc"): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_wait_operation(transport: str = "grpc"): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_wait_operation(transport: str = "grpc"): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_wait_operation_field_headers(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_wait_operation_field_headers_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_wait_operation_from_dict(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_wait_operation_from_dict_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_operation(transport: str = "grpc"): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_get_operation(transport: str = "grpc"): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_get_operation_field_headers(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_get_operation_from_dict(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_operations(transport: str = "grpc"): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + response = client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +@pytest.mark.asyncio +async def test_list_operations(transport: str = "grpc"): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +def test_list_operations_field_headers(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_operations_field_headers_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_operations_from_dict(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + response = client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_operations_from_dict_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_locations(transport: str = "grpc"): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + response = client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +@pytest.mark.asyncio +async def test_list_locations(transport: str = "grpc"): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +def test_list_locations_field_headers(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_locations_field_headers_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_locations_from_dict(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + response = client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_locations_from_dict_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_location(transport: str = "grpc"): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + response = client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +@pytest.mark.asyncio +async def test_get_location_async(transport: str = "grpc_asyncio"): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +def test_get_location_field_headers(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials() + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = locations_pb2.Location() + + client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_location_field_headers_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials() + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +def test_get_location_from_dict(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + response = client.get_location( + request={ + "name": "locations/abc", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_location_from_dict_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_set_iam_policy(transport: str = "grpc"): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + response = client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + response = await client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_set_iam_policy_field_headers(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_set_iam_policy_field_headers_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_set_iam_policy_from_dict(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_set_iam_policy_from_dict_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +def test_get_iam_policy(transport: str = "grpc"): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + + response = client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + + response = await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_get_iam_policy_field_headers(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_iam_policy_field_headers_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_get_iam_policy_from_dict(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_iam_policy_from_dict_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +def test_test_iam_permissions(transport: str = "grpc"): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + + response = client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + ) + + response = await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +def test_test_iam_permissions_field_headers(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_field_headers_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_test_iam_permissions_from_dict(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + response = client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_from_dict_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + response = await client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (SpecialistPoolServiceClient, transports.SpecialistPoolServiceGrpcTransport), + ( + SpecialistPoolServiceAsyncClient, + transports.SpecialistPoolServiceGrpcAsyncIOTransport, + ), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) diff --git a/tests/unit/gapic/aiplatform_v1/test_tensorboard_service.py b/tests/unit/gapic/aiplatform_v1/test_tensorboard_service.py new file mode 100644 index 0000000000..4fad14dc0e --- /dev/null +++ b/tests/unit/gapic/aiplatform_v1/test_tensorboard_service.py @@ -0,0 +1,11418 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import os + +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock +except ImportError: + import mock + +import grpc +from grpc.experimental import aio +import math +import pytest +from proto.marshal.rules.dates import DurationRule, TimestampRule + + +from google.api_core import client_options +from google.api_core import exceptions as core_exceptions +from google.api_core import future +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers +from google.api_core import grpc_helpers_async +from google.api_core import operation +from google.api_core import operation_async # type: ignore +from google.api_core import operations_v1 +from google.api_core import path_template +from google.auth import credentials as ga_credentials +from google.auth.exceptions import MutualTLSChannelError +from google.cloud.aiplatform_v1.services.tensorboard_service import ( + TensorboardServiceAsyncClient, +) +from google.cloud.aiplatform_v1.services.tensorboard_service import ( + TensorboardServiceClient, +) +from google.cloud.aiplatform_v1.services.tensorboard_service import pagers +from google.cloud.aiplatform_v1.services.tensorboard_service import transports +from google.cloud.aiplatform_v1.types import encryption_spec +from google.cloud.aiplatform_v1.types import operation as gca_operation +from google.cloud.aiplatform_v1.types import tensorboard +from google.cloud.aiplatform_v1.types import tensorboard as gca_tensorboard +from google.cloud.aiplatform_v1.types import tensorboard_data +from google.cloud.aiplatform_v1.types import tensorboard_experiment +from google.cloud.aiplatform_v1.types import ( + tensorboard_experiment as gca_tensorboard_experiment, +) +from google.cloud.aiplatform_v1.types import tensorboard_run +from google.cloud.aiplatform_v1.types import tensorboard_run as gca_tensorboard_run +from google.cloud.aiplatform_v1.types import tensorboard_service +from google.cloud.aiplatform_v1.types import tensorboard_time_series +from google.cloud.aiplatform_v1.types import ( + tensorboard_time_series as gca_tensorboard_time_series, +) +from google.cloud.location import locations_pb2 +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.oauth2 import service_account +from google.protobuf import field_mask_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +import google.auth + + +def client_cert_source_callback(): + return b"cert bytes", b"key bytes" + + +# If default endpoint is localhost, then default mtls endpoint will be the same. +# This method modifies the default endpoint so the client can produce a different +# mtls endpoint for endpoint testing purposes. +def modify_default_endpoint(client): + return ( + "foo.googleapis.com" + if ("localhost" in client.DEFAULT_ENDPOINT) + else client.DEFAULT_ENDPOINT + ) + + +def test__get_default_mtls_endpoint(): + api_endpoint = "example.googleapis.com" + api_mtls_endpoint = "example.mtls.googleapis.com" + sandbox_endpoint = "example.sandbox.googleapis.com" + sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" + non_googleapi = "api.example.com" + + assert TensorboardServiceClient._get_default_mtls_endpoint(None) is None + assert ( + TensorboardServiceClient._get_default_mtls_endpoint(api_endpoint) + == api_mtls_endpoint + ) + assert ( + TensorboardServiceClient._get_default_mtls_endpoint(api_mtls_endpoint) + == api_mtls_endpoint + ) + assert ( + TensorboardServiceClient._get_default_mtls_endpoint(sandbox_endpoint) + == sandbox_mtls_endpoint + ) + assert ( + TensorboardServiceClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) + == sandbox_mtls_endpoint + ) + assert ( + TensorboardServiceClient._get_default_mtls_endpoint(non_googleapi) + == non_googleapi + ) + + +@pytest.mark.parametrize( + "client_class,transport_name", + [ + (TensorboardServiceClient, "grpc"), + (TensorboardServiceAsyncClient, "grpc_asyncio"), + ], +) +def test_tensorboard_service_client_from_service_account_info( + client_class, transport_name +): + creds = ga_credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_info" + ) as factory: + factory.return_value = creds + info = {"valid": True} + client = client_class.from_service_account_info(info, transport=transport_name) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.TensorboardServiceGrpcTransport, "grpc"), + (transports.TensorboardServiceGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_tensorboard_service_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + +@pytest.mark.parametrize( + "client_class,transport_name", + [ + (TensorboardServiceClient, "grpc"), + (TensorboardServiceAsyncClient, "grpc_asyncio"), + ], +) +def test_tensorboard_service_client_from_service_account_file( + client_class, transport_name +): + creds = ga_credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_file" + ) as factory: + factory.return_value = creds + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +def test_tensorboard_service_client_get_transport_class(): + transport = TensorboardServiceClient.get_transport_class() + available_transports = [ + transports.TensorboardServiceGrpcTransport, + ] + assert transport in available_transports + + transport = TensorboardServiceClient.get_transport_class("grpc") + assert transport == transports.TensorboardServiceGrpcTransport + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (TensorboardServiceClient, transports.TensorboardServiceGrpcTransport, "grpc"), + ( + TensorboardServiceAsyncClient, + transports.TensorboardServiceGrpcAsyncIOTransport, + "grpc_asyncio", + ), + ], +) +@mock.patch.object( + TensorboardServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(TensorboardServiceClient), +) +@mock.patch.object( + TensorboardServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(TensorboardServiceAsyncClient), +) +def test_tensorboard_service_client_client_options( + client_class, transport_class, transport_name +): + # Check that if channel is provided we won't create a new one. + with mock.patch.object(TensorboardServiceClient, "get_transport_class") as gtc: + transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + client = client_class(transport=transport) + gtc.assert_not_called() + + # Check that if channel is provided via str we will create a new one. + with mock.patch.object(TensorboardServiceClient, "get_transport_class") as gtc: + client = client_class(transport=transport_name) + gtc.assert_called() + + # Check the case api_endpoint is provided. + options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(transport=transport_name, client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is + # "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is + # "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_MTLS_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has + # unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError): + client = client_class(transport=transport_name) + + # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError): + client = client_class(transport=transport_name) + + # Check the case quota_project_id is provided + options = client_options.ClientOptions(quota_project_id="octopus") + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id="octopus", + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,use_client_cert_env", + [ + ( + TensorboardServiceClient, + transports.TensorboardServiceGrpcTransport, + "grpc", + "true", + ), + ( + TensorboardServiceAsyncClient, + transports.TensorboardServiceGrpcAsyncIOTransport, + "grpc_asyncio", + "true", + ), + ( + TensorboardServiceClient, + transports.TensorboardServiceGrpcTransport, + "grpc", + "false", + ), + ( + TensorboardServiceAsyncClient, + transports.TensorboardServiceGrpcAsyncIOTransport, + "grpc_asyncio", + "false", + ), + ], +) +@mock.patch.object( + TensorboardServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(TensorboardServiceClient), +) +@mock.patch.object( + TensorboardServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(TensorboardServiceAsyncClient), +) +@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) +def test_tensorboard_service_client_mtls_env_auto( + client_class, transport_class, transport_name, use_client_cert_env +): + # This tests the endpoint autoswitch behavior. Endpoint is autoswitched to the default + # mtls endpoint, if GOOGLE_API_USE_CLIENT_CERTIFICATE is "true" and client cert exists. + + # Check the case client_cert_source is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + options = client_options.ClientOptions( + client_cert_source=client_cert_source_callback + ) + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client.DEFAULT_ENDPOINT + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT + + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # Check the case ADC client cert is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=client_cert_source_callback, + ): + if use_client_cert_env == "false": + expected_host = client.DEFAULT_ENDPOINT + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback + + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + +@pytest.mark.parametrize( + "client_class", [TensorboardServiceClient, TensorboardServiceAsyncClient] +) +@mock.patch.object( + TensorboardServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(TensorboardServiceClient), +) +@mock.patch.object( + TensorboardServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(TensorboardServiceAsyncClient), +) +def test_tensorboard_service_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (TensorboardServiceClient, transports.TensorboardServiceGrpcTransport, "grpc"), + ( + TensorboardServiceAsyncClient, + transports.TensorboardServiceGrpcAsyncIOTransport, + "grpc_asyncio", + ), + ], +) +def test_tensorboard_service_client_client_options_scopes( + client_class, transport_class, transport_name +): + # Check the case scopes are provided. + options = client_options.ClientOptions( + scopes=["1", "2"], + ) + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=["1", "2"], + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + TensorboardServiceClient, + transports.TensorboardServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + TensorboardServiceAsyncClient, + transports.TensorboardServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_tensorboard_service_client_client_options_credentials_file( + client_class, transport_class, transport_name, grpc_helpers +): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + +def test_tensorboard_service_client_client_options_from_dict(): + with mock.patch( + "google.cloud.aiplatform_v1.services.tensorboard_service.transports.TensorboardServiceGrpcTransport.__init__" + ) as grpc_transport: + grpc_transport.return_value = None + client = TensorboardServiceClient( + client_options={"api_endpoint": "squid.clam.whelk"} + ) + grpc_transport.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + TensorboardServiceClient, + transports.TensorboardServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + TensorboardServiceAsyncClient, + transports.TensorboardServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_tensorboard_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers +): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/cloud-platform.read-only", + ), + scopes=None, + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.CreateTensorboardRequest, + dict, + ], +) +def test_create_tensorboard(request_type, transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_tensorboard), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.create_tensorboard(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.CreateTensorboardRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_create_tensorboard_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_tensorboard), "__call__" + ) as call: + client.create_tensorboard() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.CreateTensorboardRequest() + + +@pytest.mark.asyncio +async def test_create_tensorboard_async( + transport: str = "grpc_asyncio", + request_type=tensorboard_service.CreateTensorboardRequest, +): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_tensorboard), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.create_tensorboard(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.CreateTensorboardRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_create_tensorboard_async_from_dict(): + await test_create_tensorboard_async(request_type=dict) + + +def test_create_tensorboard_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.CreateTensorboardRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_tensorboard), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.create_tensorboard(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_create_tensorboard_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.CreateTensorboardRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_tensorboard), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.create_tensorboard(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_create_tensorboard_flattened(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_tensorboard), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_tensorboard( + parent="parent_value", + tensorboard=gca_tensorboard.Tensorboard(name="name_value"), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].tensorboard + mock_val = gca_tensorboard.Tensorboard(name="name_value") + assert arg == mock_val + + +def test_create_tensorboard_flattened_error(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_tensorboard( + tensorboard_service.CreateTensorboardRequest(), + parent="parent_value", + tensorboard=gca_tensorboard.Tensorboard(name="name_value"), + ) + + +@pytest.mark.asyncio +async def test_create_tensorboard_flattened_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_tensorboard), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_tensorboard( + parent="parent_value", + tensorboard=gca_tensorboard.Tensorboard(name="name_value"), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].tensorboard + mock_val = gca_tensorboard.Tensorboard(name="name_value") + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_create_tensorboard_flattened_error_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.create_tensorboard( + tensorboard_service.CreateTensorboardRequest(), + parent="parent_value", + tensorboard=gca_tensorboard.Tensorboard(name="name_value"), + ) + + +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.GetTensorboardRequest, + dict, + ], +) +def test_get_tensorboard(request_type, transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_tensorboard), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard.Tensorboard( + name="name_value", + display_name="display_name_value", + description="description_value", + blob_storage_path_prefix="blob_storage_path_prefix_value", + run_count=989, + etag="etag_value", + ) + response = client.get_tensorboard(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.GetTensorboardRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, tensorboard.Tensorboard) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.blob_storage_path_prefix == "blob_storage_path_prefix_value" + assert response.run_count == 989 + assert response.etag == "etag_value" + + +def test_get_tensorboard_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_tensorboard), "__call__") as call: + client.get_tensorboard() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.GetTensorboardRequest() + + +@pytest.mark.asyncio +async def test_get_tensorboard_async( + transport: str = "grpc_asyncio", + request_type=tensorboard_service.GetTensorboardRequest, +): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_tensorboard), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard.Tensorboard( + name="name_value", + display_name="display_name_value", + description="description_value", + blob_storage_path_prefix="blob_storage_path_prefix_value", + run_count=989, + etag="etag_value", + ) + ) + response = await client.get_tensorboard(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.GetTensorboardRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, tensorboard.Tensorboard) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.blob_storage_path_prefix == "blob_storage_path_prefix_value" + assert response.run_count == 989 + assert response.etag == "etag_value" + + +@pytest.mark.asyncio +async def test_get_tensorboard_async_from_dict(): + await test_get_tensorboard_async(request_type=dict) + + +def test_get_tensorboard_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.GetTensorboardRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_tensorboard), "__call__") as call: + call.return_value = tensorboard.Tensorboard() + client.get_tensorboard(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_tensorboard_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.GetTensorboardRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_tensorboard), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard.Tensorboard() + ) + await client.get_tensorboard(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_get_tensorboard_flattened(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_tensorboard), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard.Tensorboard() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_tensorboard( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_get_tensorboard_flattened_error(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_tensorboard( + tensorboard_service.GetTensorboardRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_tensorboard_flattened_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_tensorboard), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard.Tensorboard() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard.Tensorboard() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_tensorboard( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_get_tensorboard_flattened_error_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_tensorboard( + tensorboard_service.GetTensorboardRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.UpdateTensorboardRequest, + dict, + ], +) +def test_update_tensorboard(request_type, transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_tensorboard), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.update_tensorboard(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.UpdateTensorboardRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_update_tensorboard_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_tensorboard), "__call__" + ) as call: + client.update_tensorboard() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.UpdateTensorboardRequest() + + +@pytest.mark.asyncio +async def test_update_tensorboard_async( + transport: str = "grpc_asyncio", + request_type=tensorboard_service.UpdateTensorboardRequest, +): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_tensorboard), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.update_tensorboard(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.UpdateTensorboardRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_update_tensorboard_async_from_dict(): + await test_update_tensorboard_async(request_type=dict) + + +def test_update_tensorboard_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.UpdateTensorboardRequest() + + request.tensorboard.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_tensorboard), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.update_tensorboard(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "tensorboard.name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_update_tensorboard_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.UpdateTensorboardRequest() + + request.tensorboard.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_tensorboard), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.update_tensorboard(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "tensorboard.name=name_value", + ) in kw["metadata"] + + +def test_update_tensorboard_flattened(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_tensorboard), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.update_tensorboard( + tensorboard=gca_tensorboard.Tensorboard(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].tensorboard + mock_val = gca_tensorboard.Tensorboard(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + + +def test_update_tensorboard_flattened_error(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_tensorboard( + tensorboard_service.UpdateTensorboardRequest(), + tensorboard=gca_tensorboard.Tensorboard(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.asyncio +async def test_update_tensorboard_flattened_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_tensorboard), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.update_tensorboard( + tensorboard=gca_tensorboard.Tensorboard(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].tensorboard + mock_val = gca_tensorboard.Tensorboard(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_update_tensorboard_flattened_error_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.update_tensorboard( + tensorboard_service.UpdateTensorboardRequest(), + tensorboard=gca_tensorboard.Tensorboard(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.ListTensorboardsRequest, + dict, + ], +) +def test_list_tensorboards(request_type, transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboards), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_service.ListTensorboardsResponse( + next_page_token="next_page_token_value", + ) + response = client.list_tensorboards(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.ListTensorboardsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListTensorboardsPager) + assert response.next_page_token == "next_page_token_value" + + +def test_list_tensorboards_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboards), "__call__" + ) as call: + client.list_tensorboards() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.ListTensorboardsRequest() + + +@pytest.mark.asyncio +async def test_list_tensorboards_async( + transport: str = "grpc_asyncio", + request_type=tensorboard_service.ListTensorboardsRequest, +): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboards), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.ListTensorboardsResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.list_tensorboards(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.ListTensorboardsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListTensorboardsAsyncPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_list_tensorboards_async_from_dict(): + await test_list_tensorboards_async(request_type=dict) + + +def test_list_tensorboards_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.ListTensorboardsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboards), "__call__" + ) as call: + call.return_value = tensorboard_service.ListTensorboardsResponse() + client.list_tensorboards(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_tensorboards_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.ListTensorboardsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboards), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.ListTensorboardsResponse() + ) + await client.list_tensorboards(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_list_tensorboards_flattened(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboards), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_service.ListTensorboardsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_tensorboards( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +def test_list_tensorboards_flattened_error(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_tensorboards( + tensorboard_service.ListTensorboardsRequest(), + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_tensorboards_flattened_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboards), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_service.ListTensorboardsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.ListTensorboardsResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_tensorboards( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_list_tensorboards_flattened_error_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_tensorboards( + tensorboard_service.ListTensorboardsRequest(), + parent="parent_value", + ) + + +def test_list_tensorboards_pager(transport_name: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboards), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + tensorboard_service.ListTensorboardsResponse( + tensorboards=[ + tensorboard.Tensorboard(), + tensorboard.Tensorboard(), + tensorboard.Tensorboard(), + ], + next_page_token="abc", + ), + tensorboard_service.ListTensorboardsResponse( + tensorboards=[], + next_page_token="def", + ), + tensorboard_service.ListTensorboardsResponse( + tensorboards=[ + tensorboard.Tensorboard(), + ], + next_page_token="ghi", + ), + tensorboard_service.ListTensorboardsResponse( + tensorboards=[ + tensorboard.Tensorboard(), + tensorboard.Tensorboard(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_tensorboards(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, tensorboard.Tensorboard) for i in results) + + +def test_list_tensorboards_pages(transport_name: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboards), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + tensorboard_service.ListTensorboardsResponse( + tensorboards=[ + tensorboard.Tensorboard(), + tensorboard.Tensorboard(), + tensorboard.Tensorboard(), + ], + next_page_token="abc", + ), + tensorboard_service.ListTensorboardsResponse( + tensorboards=[], + next_page_token="def", + ), + tensorboard_service.ListTensorboardsResponse( + tensorboards=[ + tensorboard.Tensorboard(), + ], + next_page_token="ghi", + ), + tensorboard_service.ListTensorboardsResponse( + tensorboards=[ + tensorboard.Tensorboard(), + tensorboard.Tensorboard(), + ], + ), + RuntimeError, + ) + pages = list(client.list_tensorboards(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.asyncio +async def test_list_tensorboards_async_pager(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboards), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + tensorboard_service.ListTensorboardsResponse( + tensorboards=[ + tensorboard.Tensorboard(), + tensorboard.Tensorboard(), + tensorboard.Tensorboard(), + ], + next_page_token="abc", + ), + tensorboard_service.ListTensorboardsResponse( + tensorboards=[], + next_page_token="def", + ), + tensorboard_service.ListTensorboardsResponse( + tensorboards=[ + tensorboard.Tensorboard(), + ], + next_page_token="ghi", + ), + tensorboard_service.ListTensorboardsResponse( + tensorboards=[ + tensorboard.Tensorboard(), + tensorboard.Tensorboard(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_tensorboards( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, tensorboard.Tensorboard) for i in responses) + + +@pytest.mark.asyncio +async def test_list_tensorboards_async_pages(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboards), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + tensorboard_service.ListTensorboardsResponse( + tensorboards=[ + tensorboard.Tensorboard(), + tensorboard.Tensorboard(), + tensorboard.Tensorboard(), + ], + next_page_token="abc", + ), + tensorboard_service.ListTensorboardsResponse( + tensorboards=[], + next_page_token="def", + ), + tensorboard_service.ListTensorboardsResponse( + tensorboards=[ + tensorboard.Tensorboard(), + ], + next_page_token="ghi", + ), + tensorboard_service.ListTensorboardsResponse( + tensorboards=[ + tensorboard.Tensorboard(), + tensorboard.Tensorboard(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.list_tensorboards(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.DeleteTensorboardRequest, + dict, + ], +) +def test_delete_tensorboard(request_type, transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_tensorboard), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.delete_tensorboard(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.DeleteTensorboardRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_delete_tensorboard_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_tensorboard), "__call__" + ) as call: + client.delete_tensorboard() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.DeleteTensorboardRequest() + + +@pytest.mark.asyncio +async def test_delete_tensorboard_async( + transport: str = "grpc_asyncio", + request_type=tensorboard_service.DeleteTensorboardRequest, +): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_tensorboard), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.delete_tensorboard(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.DeleteTensorboardRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_delete_tensorboard_async_from_dict(): + await test_delete_tensorboard_async(request_type=dict) + + +def test_delete_tensorboard_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.DeleteTensorboardRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_tensorboard), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_tensorboard(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_tensorboard_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.DeleteTensorboardRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_tensorboard), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.delete_tensorboard(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_delete_tensorboard_flattened(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_tensorboard), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_tensorboard( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_delete_tensorboard_flattened_error(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_tensorboard( + tensorboard_service.DeleteTensorboardRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_delete_tensorboard_flattened_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_tensorboard), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_tensorboard( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_delete_tensorboard_flattened_error_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.delete_tensorboard( + tensorboard_service.DeleteTensorboardRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.CreateTensorboardExperimentRequest, + dict, + ], +) +def test_create_tensorboard_experiment(request_type, transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_tensorboard_experiment), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gca_tensorboard_experiment.TensorboardExperiment( + name="name_value", + display_name="display_name_value", + description="description_value", + etag="etag_value", + source="source_value", + ) + response = client.create_tensorboard_experiment(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.CreateTensorboardExperimentRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_tensorboard_experiment.TensorboardExperiment) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.etag == "etag_value" + assert response.source == "source_value" + + +def test_create_tensorboard_experiment_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_tensorboard_experiment), "__call__" + ) as call: + client.create_tensorboard_experiment() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.CreateTensorboardExperimentRequest() + + +@pytest.mark.asyncio +async def test_create_tensorboard_experiment_async( + transport: str = "grpc_asyncio", + request_type=tensorboard_service.CreateTensorboardExperimentRequest, +): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_tensorboard_experiment), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_tensorboard_experiment.TensorboardExperiment( + name="name_value", + display_name="display_name_value", + description="description_value", + etag="etag_value", + source="source_value", + ) + ) + response = await client.create_tensorboard_experiment(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.CreateTensorboardExperimentRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_tensorboard_experiment.TensorboardExperiment) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.etag == "etag_value" + assert response.source == "source_value" + + +@pytest.mark.asyncio +async def test_create_tensorboard_experiment_async_from_dict(): + await test_create_tensorboard_experiment_async(request_type=dict) + + +def test_create_tensorboard_experiment_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.CreateTensorboardExperimentRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_tensorboard_experiment), "__call__" + ) as call: + call.return_value = gca_tensorboard_experiment.TensorboardExperiment() + client.create_tensorboard_experiment(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_create_tensorboard_experiment_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.CreateTensorboardExperimentRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_tensorboard_experiment), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_tensorboard_experiment.TensorboardExperiment() + ) + await client.create_tensorboard_experiment(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_create_tensorboard_experiment_flattened(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_tensorboard_experiment), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gca_tensorboard_experiment.TensorboardExperiment() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_tensorboard_experiment( + parent="parent_value", + tensorboard_experiment=gca_tensorboard_experiment.TensorboardExperiment( + name="name_value" + ), + tensorboard_experiment_id="tensorboard_experiment_id_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].tensorboard_experiment + mock_val = gca_tensorboard_experiment.TensorboardExperiment(name="name_value") + assert arg == mock_val + arg = args[0].tensorboard_experiment_id + mock_val = "tensorboard_experiment_id_value" + assert arg == mock_val + + +def test_create_tensorboard_experiment_flattened_error(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_tensorboard_experiment( + tensorboard_service.CreateTensorboardExperimentRequest(), + parent="parent_value", + tensorboard_experiment=gca_tensorboard_experiment.TensorboardExperiment( + name="name_value" + ), + tensorboard_experiment_id="tensorboard_experiment_id_value", + ) + + +@pytest.mark.asyncio +async def test_create_tensorboard_experiment_flattened_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_tensorboard_experiment), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gca_tensorboard_experiment.TensorboardExperiment() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_tensorboard_experiment.TensorboardExperiment() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_tensorboard_experiment( + parent="parent_value", + tensorboard_experiment=gca_tensorboard_experiment.TensorboardExperiment( + name="name_value" + ), + tensorboard_experiment_id="tensorboard_experiment_id_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].tensorboard_experiment + mock_val = gca_tensorboard_experiment.TensorboardExperiment(name="name_value") + assert arg == mock_val + arg = args[0].tensorboard_experiment_id + mock_val = "tensorboard_experiment_id_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_create_tensorboard_experiment_flattened_error_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.create_tensorboard_experiment( + tensorboard_service.CreateTensorboardExperimentRequest(), + parent="parent_value", + tensorboard_experiment=gca_tensorboard_experiment.TensorboardExperiment( + name="name_value" + ), + tensorboard_experiment_id="tensorboard_experiment_id_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.GetTensorboardExperimentRequest, + dict, + ], +) +def test_get_tensorboard_experiment(request_type, transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_tensorboard_experiment), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_experiment.TensorboardExperiment( + name="name_value", + display_name="display_name_value", + description="description_value", + etag="etag_value", + source="source_value", + ) + response = client.get_tensorboard_experiment(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.GetTensorboardExperimentRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, tensorboard_experiment.TensorboardExperiment) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.etag == "etag_value" + assert response.source == "source_value" + + +def test_get_tensorboard_experiment_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_tensorboard_experiment), "__call__" + ) as call: + client.get_tensorboard_experiment() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.GetTensorboardExperimentRequest() + + +@pytest.mark.asyncio +async def test_get_tensorboard_experiment_async( + transport: str = "grpc_asyncio", + request_type=tensorboard_service.GetTensorboardExperimentRequest, +): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_tensorboard_experiment), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_experiment.TensorboardExperiment( + name="name_value", + display_name="display_name_value", + description="description_value", + etag="etag_value", + source="source_value", + ) + ) + response = await client.get_tensorboard_experiment(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.GetTensorboardExperimentRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, tensorboard_experiment.TensorboardExperiment) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.etag == "etag_value" + assert response.source == "source_value" + + +@pytest.mark.asyncio +async def test_get_tensorboard_experiment_async_from_dict(): + await test_get_tensorboard_experiment_async(request_type=dict) + + +def test_get_tensorboard_experiment_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.GetTensorboardExperimentRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_tensorboard_experiment), "__call__" + ) as call: + call.return_value = tensorboard_experiment.TensorboardExperiment() + client.get_tensorboard_experiment(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_tensorboard_experiment_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.GetTensorboardExperimentRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_tensorboard_experiment), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_experiment.TensorboardExperiment() + ) + await client.get_tensorboard_experiment(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_get_tensorboard_experiment_flattened(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_tensorboard_experiment), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_experiment.TensorboardExperiment() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_tensorboard_experiment( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_get_tensorboard_experiment_flattened_error(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_tensorboard_experiment( + tensorboard_service.GetTensorboardExperimentRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_tensorboard_experiment_flattened_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_tensorboard_experiment), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_experiment.TensorboardExperiment() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_experiment.TensorboardExperiment() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_tensorboard_experiment( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_get_tensorboard_experiment_flattened_error_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_tensorboard_experiment( + tensorboard_service.GetTensorboardExperimentRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.UpdateTensorboardExperimentRequest, + dict, + ], +) +def test_update_tensorboard_experiment(request_type, transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_tensorboard_experiment), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gca_tensorboard_experiment.TensorboardExperiment( + name="name_value", + display_name="display_name_value", + description="description_value", + etag="etag_value", + source="source_value", + ) + response = client.update_tensorboard_experiment(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.UpdateTensorboardExperimentRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_tensorboard_experiment.TensorboardExperiment) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.etag == "etag_value" + assert response.source == "source_value" + + +def test_update_tensorboard_experiment_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_tensorboard_experiment), "__call__" + ) as call: + client.update_tensorboard_experiment() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.UpdateTensorboardExperimentRequest() + + +@pytest.mark.asyncio +async def test_update_tensorboard_experiment_async( + transport: str = "grpc_asyncio", + request_type=tensorboard_service.UpdateTensorboardExperimentRequest, +): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_tensorboard_experiment), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_tensorboard_experiment.TensorboardExperiment( + name="name_value", + display_name="display_name_value", + description="description_value", + etag="etag_value", + source="source_value", + ) + ) + response = await client.update_tensorboard_experiment(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.UpdateTensorboardExperimentRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_tensorboard_experiment.TensorboardExperiment) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.etag == "etag_value" + assert response.source == "source_value" + + +@pytest.mark.asyncio +async def test_update_tensorboard_experiment_async_from_dict(): + await test_update_tensorboard_experiment_async(request_type=dict) + + +def test_update_tensorboard_experiment_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.UpdateTensorboardExperimentRequest() + + request.tensorboard_experiment.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_tensorboard_experiment), "__call__" + ) as call: + call.return_value = gca_tensorboard_experiment.TensorboardExperiment() + client.update_tensorboard_experiment(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "tensorboard_experiment.name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_update_tensorboard_experiment_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.UpdateTensorboardExperimentRequest() + + request.tensorboard_experiment.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_tensorboard_experiment), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_tensorboard_experiment.TensorboardExperiment() + ) + await client.update_tensorboard_experiment(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "tensorboard_experiment.name=name_value", + ) in kw["metadata"] + + +def test_update_tensorboard_experiment_flattened(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_tensorboard_experiment), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gca_tensorboard_experiment.TensorboardExperiment() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.update_tensorboard_experiment( + tensorboard_experiment=gca_tensorboard_experiment.TensorboardExperiment( + name="name_value" + ), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].tensorboard_experiment + mock_val = gca_tensorboard_experiment.TensorboardExperiment(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + + +def test_update_tensorboard_experiment_flattened_error(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_tensorboard_experiment( + tensorboard_service.UpdateTensorboardExperimentRequest(), + tensorboard_experiment=gca_tensorboard_experiment.TensorboardExperiment( + name="name_value" + ), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.asyncio +async def test_update_tensorboard_experiment_flattened_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_tensorboard_experiment), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gca_tensorboard_experiment.TensorboardExperiment() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_tensorboard_experiment.TensorboardExperiment() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.update_tensorboard_experiment( + tensorboard_experiment=gca_tensorboard_experiment.TensorboardExperiment( + name="name_value" + ), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].tensorboard_experiment + mock_val = gca_tensorboard_experiment.TensorboardExperiment(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_update_tensorboard_experiment_flattened_error_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.update_tensorboard_experiment( + tensorboard_service.UpdateTensorboardExperimentRequest(), + tensorboard_experiment=gca_tensorboard_experiment.TensorboardExperiment( + name="name_value" + ), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.ListTensorboardExperimentsRequest, + dict, + ], +) +def test_list_tensorboard_experiments(request_type, transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_experiments), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_service.ListTensorboardExperimentsResponse( + next_page_token="next_page_token_value", + ) + response = client.list_tensorboard_experiments(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.ListTensorboardExperimentsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListTensorboardExperimentsPager) + assert response.next_page_token == "next_page_token_value" + + +def test_list_tensorboard_experiments_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_experiments), "__call__" + ) as call: + client.list_tensorboard_experiments() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.ListTensorboardExperimentsRequest() + + +@pytest.mark.asyncio +async def test_list_tensorboard_experiments_async( + transport: str = "grpc_asyncio", + request_type=tensorboard_service.ListTensorboardExperimentsRequest, +): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_experiments), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.ListTensorboardExperimentsResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.list_tensorboard_experiments(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.ListTensorboardExperimentsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListTensorboardExperimentsAsyncPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_list_tensorboard_experiments_async_from_dict(): + await test_list_tensorboard_experiments_async(request_type=dict) + + +def test_list_tensorboard_experiments_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.ListTensorboardExperimentsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_experiments), "__call__" + ) as call: + call.return_value = tensorboard_service.ListTensorboardExperimentsResponse() + client.list_tensorboard_experiments(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_tensorboard_experiments_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.ListTensorboardExperimentsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_experiments), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.ListTensorboardExperimentsResponse() + ) + await client.list_tensorboard_experiments(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_list_tensorboard_experiments_flattened(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_experiments), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_service.ListTensorboardExperimentsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_tensorboard_experiments( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +def test_list_tensorboard_experiments_flattened_error(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_tensorboard_experiments( + tensorboard_service.ListTensorboardExperimentsRequest(), + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_tensorboard_experiments_flattened_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_experiments), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_service.ListTensorboardExperimentsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.ListTensorboardExperimentsResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_tensorboard_experiments( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_list_tensorboard_experiments_flattened_error_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_tensorboard_experiments( + tensorboard_service.ListTensorboardExperimentsRequest(), + parent="parent_value", + ) + + +def test_list_tensorboard_experiments_pager(transport_name: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_experiments), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + tensorboard_service.ListTensorboardExperimentsResponse( + tensorboard_experiments=[ + tensorboard_experiment.TensorboardExperiment(), + tensorboard_experiment.TensorboardExperiment(), + tensorboard_experiment.TensorboardExperiment(), + ], + next_page_token="abc", + ), + tensorboard_service.ListTensorboardExperimentsResponse( + tensorboard_experiments=[], + next_page_token="def", + ), + tensorboard_service.ListTensorboardExperimentsResponse( + tensorboard_experiments=[ + tensorboard_experiment.TensorboardExperiment(), + ], + next_page_token="ghi", + ), + tensorboard_service.ListTensorboardExperimentsResponse( + tensorboard_experiments=[ + tensorboard_experiment.TensorboardExperiment(), + tensorboard_experiment.TensorboardExperiment(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_tensorboard_experiments(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all( + isinstance(i, tensorboard_experiment.TensorboardExperiment) for i in results + ) + + +def test_list_tensorboard_experiments_pages(transport_name: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_experiments), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + tensorboard_service.ListTensorboardExperimentsResponse( + tensorboard_experiments=[ + tensorboard_experiment.TensorboardExperiment(), + tensorboard_experiment.TensorboardExperiment(), + tensorboard_experiment.TensorboardExperiment(), + ], + next_page_token="abc", + ), + tensorboard_service.ListTensorboardExperimentsResponse( + tensorboard_experiments=[], + next_page_token="def", + ), + tensorboard_service.ListTensorboardExperimentsResponse( + tensorboard_experiments=[ + tensorboard_experiment.TensorboardExperiment(), + ], + next_page_token="ghi", + ), + tensorboard_service.ListTensorboardExperimentsResponse( + tensorboard_experiments=[ + tensorboard_experiment.TensorboardExperiment(), + tensorboard_experiment.TensorboardExperiment(), + ], + ), + RuntimeError, + ) + pages = list(client.list_tensorboard_experiments(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.asyncio +async def test_list_tensorboard_experiments_async_pager(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_experiments), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + tensorboard_service.ListTensorboardExperimentsResponse( + tensorboard_experiments=[ + tensorboard_experiment.TensorboardExperiment(), + tensorboard_experiment.TensorboardExperiment(), + tensorboard_experiment.TensorboardExperiment(), + ], + next_page_token="abc", + ), + tensorboard_service.ListTensorboardExperimentsResponse( + tensorboard_experiments=[], + next_page_token="def", + ), + tensorboard_service.ListTensorboardExperimentsResponse( + tensorboard_experiments=[ + tensorboard_experiment.TensorboardExperiment(), + ], + next_page_token="ghi", + ), + tensorboard_service.ListTensorboardExperimentsResponse( + tensorboard_experiments=[ + tensorboard_experiment.TensorboardExperiment(), + tensorboard_experiment.TensorboardExperiment(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_tensorboard_experiments( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all( + isinstance(i, tensorboard_experiment.TensorboardExperiment) + for i in responses + ) + + +@pytest.mark.asyncio +async def test_list_tensorboard_experiments_async_pages(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_experiments), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + tensorboard_service.ListTensorboardExperimentsResponse( + tensorboard_experiments=[ + tensorboard_experiment.TensorboardExperiment(), + tensorboard_experiment.TensorboardExperiment(), + tensorboard_experiment.TensorboardExperiment(), + ], + next_page_token="abc", + ), + tensorboard_service.ListTensorboardExperimentsResponse( + tensorboard_experiments=[], + next_page_token="def", + ), + tensorboard_service.ListTensorboardExperimentsResponse( + tensorboard_experiments=[ + tensorboard_experiment.TensorboardExperiment(), + ], + next_page_token="ghi", + ), + tensorboard_service.ListTensorboardExperimentsResponse( + tensorboard_experiments=[ + tensorboard_experiment.TensorboardExperiment(), + tensorboard_experiment.TensorboardExperiment(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.list_tensorboard_experiments(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.DeleteTensorboardExperimentRequest, + dict, + ], +) +def test_delete_tensorboard_experiment(request_type, transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_tensorboard_experiment), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.delete_tensorboard_experiment(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.DeleteTensorboardExperimentRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_delete_tensorboard_experiment_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_tensorboard_experiment), "__call__" + ) as call: + client.delete_tensorboard_experiment() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.DeleteTensorboardExperimentRequest() + + +@pytest.mark.asyncio +async def test_delete_tensorboard_experiment_async( + transport: str = "grpc_asyncio", + request_type=tensorboard_service.DeleteTensorboardExperimentRequest, +): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_tensorboard_experiment), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.delete_tensorboard_experiment(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.DeleteTensorboardExperimentRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_delete_tensorboard_experiment_async_from_dict(): + await test_delete_tensorboard_experiment_async(request_type=dict) + + +def test_delete_tensorboard_experiment_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.DeleteTensorboardExperimentRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_tensorboard_experiment), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_tensorboard_experiment(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_tensorboard_experiment_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.DeleteTensorboardExperimentRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_tensorboard_experiment), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.delete_tensorboard_experiment(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_delete_tensorboard_experiment_flattened(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_tensorboard_experiment), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_tensorboard_experiment( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_delete_tensorboard_experiment_flattened_error(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_tensorboard_experiment( + tensorboard_service.DeleteTensorboardExperimentRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_delete_tensorboard_experiment_flattened_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_tensorboard_experiment), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_tensorboard_experiment( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_delete_tensorboard_experiment_flattened_error_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.delete_tensorboard_experiment( + tensorboard_service.DeleteTensorboardExperimentRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.CreateTensorboardRunRequest, + dict, + ], +) +def test_create_tensorboard_run(request_type, transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_tensorboard_run), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gca_tensorboard_run.TensorboardRun( + name="name_value", + display_name="display_name_value", + description="description_value", + etag="etag_value", + ) + response = client.create_tensorboard_run(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.CreateTensorboardRunRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_tensorboard_run.TensorboardRun) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.etag == "etag_value" + + +def test_create_tensorboard_run_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_tensorboard_run), "__call__" + ) as call: + client.create_tensorboard_run() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.CreateTensorboardRunRequest() + + +@pytest.mark.asyncio +async def test_create_tensorboard_run_async( + transport: str = "grpc_asyncio", + request_type=tensorboard_service.CreateTensorboardRunRequest, +): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_tensorboard_run), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_tensorboard_run.TensorboardRun( + name="name_value", + display_name="display_name_value", + description="description_value", + etag="etag_value", + ) + ) + response = await client.create_tensorboard_run(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.CreateTensorboardRunRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_tensorboard_run.TensorboardRun) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.etag == "etag_value" + + +@pytest.mark.asyncio +async def test_create_tensorboard_run_async_from_dict(): + await test_create_tensorboard_run_async(request_type=dict) + + +def test_create_tensorboard_run_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.CreateTensorboardRunRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_tensorboard_run), "__call__" + ) as call: + call.return_value = gca_tensorboard_run.TensorboardRun() + client.create_tensorboard_run(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_create_tensorboard_run_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.CreateTensorboardRunRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_tensorboard_run), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_tensorboard_run.TensorboardRun() + ) + await client.create_tensorboard_run(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_create_tensorboard_run_flattened(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_tensorboard_run), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gca_tensorboard_run.TensorboardRun() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_tensorboard_run( + parent="parent_value", + tensorboard_run=gca_tensorboard_run.TensorboardRun(name="name_value"), + tensorboard_run_id="tensorboard_run_id_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].tensorboard_run + mock_val = gca_tensorboard_run.TensorboardRun(name="name_value") + assert arg == mock_val + arg = args[0].tensorboard_run_id + mock_val = "tensorboard_run_id_value" + assert arg == mock_val + + +def test_create_tensorboard_run_flattened_error(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_tensorboard_run( + tensorboard_service.CreateTensorboardRunRequest(), + parent="parent_value", + tensorboard_run=gca_tensorboard_run.TensorboardRun(name="name_value"), + tensorboard_run_id="tensorboard_run_id_value", + ) + + +@pytest.mark.asyncio +async def test_create_tensorboard_run_flattened_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_tensorboard_run), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gca_tensorboard_run.TensorboardRun() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_tensorboard_run.TensorboardRun() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_tensorboard_run( + parent="parent_value", + tensorboard_run=gca_tensorboard_run.TensorboardRun(name="name_value"), + tensorboard_run_id="tensorboard_run_id_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].tensorboard_run + mock_val = gca_tensorboard_run.TensorboardRun(name="name_value") + assert arg == mock_val + arg = args[0].tensorboard_run_id + mock_val = "tensorboard_run_id_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_create_tensorboard_run_flattened_error_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.create_tensorboard_run( + tensorboard_service.CreateTensorboardRunRequest(), + parent="parent_value", + tensorboard_run=gca_tensorboard_run.TensorboardRun(name="name_value"), + tensorboard_run_id="tensorboard_run_id_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.BatchCreateTensorboardRunsRequest, + dict, + ], +) +def test_batch_create_tensorboard_runs(request_type, transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_create_tensorboard_runs), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_service.BatchCreateTensorboardRunsResponse() + response = client.batch_create_tensorboard_runs(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.BatchCreateTensorboardRunsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, tensorboard_service.BatchCreateTensorboardRunsResponse) + + +def test_batch_create_tensorboard_runs_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_create_tensorboard_runs), "__call__" + ) as call: + client.batch_create_tensorboard_runs() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.BatchCreateTensorboardRunsRequest() + + +@pytest.mark.asyncio +async def test_batch_create_tensorboard_runs_async( + transport: str = "grpc_asyncio", + request_type=tensorboard_service.BatchCreateTensorboardRunsRequest, +): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_create_tensorboard_runs), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.BatchCreateTensorboardRunsResponse() + ) + response = await client.batch_create_tensorboard_runs(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.BatchCreateTensorboardRunsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, tensorboard_service.BatchCreateTensorboardRunsResponse) + + +@pytest.mark.asyncio +async def test_batch_create_tensorboard_runs_async_from_dict(): + await test_batch_create_tensorboard_runs_async(request_type=dict) + + +def test_batch_create_tensorboard_runs_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.BatchCreateTensorboardRunsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_create_tensorboard_runs), "__call__" + ) as call: + call.return_value = tensorboard_service.BatchCreateTensorboardRunsResponse() + client.batch_create_tensorboard_runs(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_batch_create_tensorboard_runs_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.BatchCreateTensorboardRunsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_create_tensorboard_runs), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.BatchCreateTensorboardRunsResponse() + ) + await client.batch_create_tensorboard_runs(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_batch_create_tensorboard_runs_flattened(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_create_tensorboard_runs), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_service.BatchCreateTensorboardRunsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.batch_create_tensorboard_runs( + parent="parent_value", + requests=[ + tensorboard_service.CreateTensorboardRunRequest(parent="parent_value") + ], + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].requests + mock_val = [ + tensorboard_service.CreateTensorboardRunRequest(parent="parent_value") + ] + assert arg == mock_val + + +def test_batch_create_tensorboard_runs_flattened_error(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.batch_create_tensorboard_runs( + tensorboard_service.BatchCreateTensorboardRunsRequest(), + parent="parent_value", + requests=[ + tensorboard_service.CreateTensorboardRunRequest(parent="parent_value") + ], + ) + + +@pytest.mark.asyncio +async def test_batch_create_tensorboard_runs_flattened_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_create_tensorboard_runs), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_service.BatchCreateTensorboardRunsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.BatchCreateTensorboardRunsResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.batch_create_tensorboard_runs( + parent="parent_value", + requests=[ + tensorboard_service.CreateTensorboardRunRequest(parent="parent_value") + ], + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].requests + mock_val = [ + tensorboard_service.CreateTensorboardRunRequest(parent="parent_value") + ] + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_batch_create_tensorboard_runs_flattened_error_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.batch_create_tensorboard_runs( + tensorboard_service.BatchCreateTensorboardRunsRequest(), + parent="parent_value", + requests=[ + tensorboard_service.CreateTensorboardRunRequest(parent="parent_value") + ], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.GetTensorboardRunRequest, + dict, + ], +) +def test_get_tensorboard_run(request_type, transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_tensorboard_run), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_run.TensorboardRun( + name="name_value", + display_name="display_name_value", + description="description_value", + etag="etag_value", + ) + response = client.get_tensorboard_run(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.GetTensorboardRunRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, tensorboard_run.TensorboardRun) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.etag == "etag_value" + + +def test_get_tensorboard_run_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_tensorboard_run), "__call__" + ) as call: + client.get_tensorboard_run() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.GetTensorboardRunRequest() + + +@pytest.mark.asyncio +async def test_get_tensorboard_run_async( + transport: str = "grpc_asyncio", + request_type=tensorboard_service.GetTensorboardRunRequest, +): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_tensorboard_run), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_run.TensorboardRun( + name="name_value", + display_name="display_name_value", + description="description_value", + etag="etag_value", + ) + ) + response = await client.get_tensorboard_run(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.GetTensorboardRunRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, tensorboard_run.TensorboardRun) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.etag == "etag_value" + + +@pytest.mark.asyncio +async def test_get_tensorboard_run_async_from_dict(): + await test_get_tensorboard_run_async(request_type=dict) + + +def test_get_tensorboard_run_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.GetTensorboardRunRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_tensorboard_run), "__call__" + ) as call: + call.return_value = tensorboard_run.TensorboardRun() + client.get_tensorboard_run(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_tensorboard_run_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.GetTensorboardRunRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_tensorboard_run), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_run.TensorboardRun() + ) + await client.get_tensorboard_run(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_get_tensorboard_run_flattened(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_tensorboard_run), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_run.TensorboardRun() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_tensorboard_run( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_get_tensorboard_run_flattened_error(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_tensorboard_run( + tensorboard_service.GetTensorboardRunRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_tensorboard_run_flattened_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_tensorboard_run), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_run.TensorboardRun() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_run.TensorboardRun() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_tensorboard_run( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_get_tensorboard_run_flattened_error_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_tensorboard_run( + tensorboard_service.GetTensorboardRunRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.UpdateTensorboardRunRequest, + dict, + ], +) +def test_update_tensorboard_run(request_type, transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_tensorboard_run), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gca_tensorboard_run.TensorboardRun( + name="name_value", + display_name="display_name_value", + description="description_value", + etag="etag_value", + ) + response = client.update_tensorboard_run(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.UpdateTensorboardRunRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_tensorboard_run.TensorboardRun) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.etag == "etag_value" + + +def test_update_tensorboard_run_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_tensorboard_run), "__call__" + ) as call: + client.update_tensorboard_run() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.UpdateTensorboardRunRequest() + + +@pytest.mark.asyncio +async def test_update_tensorboard_run_async( + transport: str = "grpc_asyncio", + request_type=tensorboard_service.UpdateTensorboardRunRequest, +): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_tensorboard_run), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_tensorboard_run.TensorboardRun( + name="name_value", + display_name="display_name_value", + description="description_value", + etag="etag_value", + ) + ) + response = await client.update_tensorboard_run(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.UpdateTensorboardRunRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_tensorboard_run.TensorboardRun) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.etag == "etag_value" + + +@pytest.mark.asyncio +async def test_update_tensorboard_run_async_from_dict(): + await test_update_tensorboard_run_async(request_type=dict) + + +def test_update_tensorboard_run_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.UpdateTensorboardRunRequest() + + request.tensorboard_run.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_tensorboard_run), "__call__" + ) as call: + call.return_value = gca_tensorboard_run.TensorboardRun() + client.update_tensorboard_run(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "tensorboard_run.name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_update_tensorboard_run_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.UpdateTensorboardRunRequest() + + request.tensorboard_run.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_tensorboard_run), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_tensorboard_run.TensorboardRun() + ) + await client.update_tensorboard_run(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "tensorboard_run.name=name_value", + ) in kw["metadata"] + + +def test_update_tensorboard_run_flattened(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_tensorboard_run), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gca_tensorboard_run.TensorboardRun() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.update_tensorboard_run( + tensorboard_run=gca_tensorboard_run.TensorboardRun(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].tensorboard_run + mock_val = gca_tensorboard_run.TensorboardRun(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + + +def test_update_tensorboard_run_flattened_error(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_tensorboard_run( + tensorboard_service.UpdateTensorboardRunRequest(), + tensorboard_run=gca_tensorboard_run.TensorboardRun(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.asyncio +async def test_update_tensorboard_run_flattened_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_tensorboard_run), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gca_tensorboard_run.TensorboardRun() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_tensorboard_run.TensorboardRun() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.update_tensorboard_run( + tensorboard_run=gca_tensorboard_run.TensorboardRun(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].tensorboard_run + mock_val = gca_tensorboard_run.TensorboardRun(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_update_tensorboard_run_flattened_error_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.update_tensorboard_run( + tensorboard_service.UpdateTensorboardRunRequest(), + tensorboard_run=gca_tensorboard_run.TensorboardRun(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.ListTensorboardRunsRequest, + dict, + ], +) +def test_list_tensorboard_runs(request_type, transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_runs), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_service.ListTensorboardRunsResponse( + next_page_token="next_page_token_value", + ) + response = client.list_tensorboard_runs(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.ListTensorboardRunsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListTensorboardRunsPager) + assert response.next_page_token == "next_page_token_value" + + +def test_list_tensorboard_runs_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_runs), "__call__" + ) as call: + client.list_tensorboard_runs() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.ListTensorboardRunsRequest() + + +@pytest.mark.asyncio +async def test_list_tensorboard_runs_async( + transport: str = "grpc_asyncio", + request_type=tensorboard_service.ListTensorboardRunsRequest, +): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_runs), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.ListTensorboardRunsResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.list_tensorboard_runs(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.ListTensorboardRunsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListTensorboardRunsAsyncPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_list_tensorboard_runs_async_from_dict(): + await test_list_tensorboard_runs_async(request_type=dict) + + +def test_list_tensorboard_runs_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.ListTensorboardRunsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_runs), "__call__" + ) as call: + call.return_value = tensorboard_service.ListTensorboardRunsResponse() + client.list_tensorboard_runs(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_tensorboard_runs_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.ListTensorboardRunsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_runs), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.ListTensorboardRunsResponse() + ) + await client.list_tensorboard_runs(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_list_tensorboard_runs_flattened(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_runs), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_service.ListTensorboardRunsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_tensorboard_runs( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +def test_list_tensorboard_runs_flattened_error(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_tensorboard_runs( + tensorboard_service.ListTensorboardRunsRequest(), + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_tensorboard_runs_flattened_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_runs), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_service.ListTensorboardRunsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.ListTensorboardRunsResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_tensorboard_runs( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_list_tensorboard_runs_flattened_error_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_tensorboard_runs( + tensorboard_service.ListTensorboardRunsRequest(), + parent="parent_value", + ) + + +def test_list_tensorboard_runs_pager(transport_name: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_runs), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + tensorboard_service.ListTensorboardRunsResponse( + tensorboard_runs=[ + tensorboard_run.TensorboardRun(), + tensorboard_run.TensorboardRun(), + tensorboard_run.TensorboardRun(), + ], + next_page_token="abc", + ), + tensorboard_service.ListTensorboardRunsResponse( + tensorboard_runs=[], + next_page_token="def", + ), + tensorboard_service.ListTensorboardRunsResponse( + tensorboard_runs=[ + tensorboard_run.TensorboardRun(), + ], + next_page_token="ghi", + ), + tensorboard_service.ListTensorboardRunsResponse( + tensorboard_runs=[ + tensorboard_run.TensorboardRun(), + tensorboard_run.TensorboardRun(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_tensorboard_runs(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, tensorboard_run.TensorboardRun) for i in results) + + +def test_list_tensorboard_runs_pages(transport_name: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_runs), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + tensorboard_service.ListTensorboardRunsResponse( + tensorboard_runs=[ + tensorboard_run.TensorboardRun(), + tensorboard_run.TensorboardRun(), + tensorboard_run.TensorboardRun(), + ], + next_page_token="abc", + ), + tensorboard_service.ListTensorboardRunsResponse( + tensorboard_runs=[], + next_page_token="def", + ), + tensorboard_service.ListTensorboardRunsResponse( + tensorboard_runs=[ + tensorboard_run.TensorboardRun(), + ], + next_page_token="ghi", + ), + tensorboard_service.ListTensorboardRunsResponse( + tensorboard_runs=[ + tensorboard_run.TensorboardRun(), + tensorboard_run.TensorboardRun(), + ], + ), + RuntimeError, + ) + pages = list(client.list_tensorboard_runs(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.asyncio +async def test_list_tensorboard_runs_async_pager(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_runs), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + tensorboard_service.ListTensorboardRunsResponse( + tensorboard_runs=[ + tensorboard_run.TensorboardRun(), + tensorboard_run.TensorboardRun(), + tensorboard_run.TensorboardRun(), + ], + next_page_token="abc", + ), + tensorboard_service.ListTensorboardRunsResponse( + tensorboard_runs=[], + next_page_token="def", + ), + tensorboard_service.ListTensorboardRunsResponse( + tensorboard_runs=[ + tensorboard_run.TensorboardRun(), + ], + next_page_token="ghi", + ), + tensorboard_service.ListTensorboardRunsResponse( + tensorboard_runs=[ + tensorboard_run.TensorboardRun(), + tensorboard_run.TensorboardRun(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_tensorboard_runs( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, tensorboard_run.TensorboardRun) for i in responses) + + +@pytest.mark.asyncio +async def test_list_tensorboard_runs_async_pages(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_runs), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + tensorboard_service.ListTensorboardRunsResponse( + tensorboard_runs=[ + tensorboard_run.TensorboardRun(), + tensorboard_run.TensorboardRun(), + tensorboard_run.TensorboardRun(), + ], + next_page_token="abc", + ), + tensorboard_service.ListTensorboardRunsResponse( + tensorboard_runs=[], + next_page_token="def", + ), + tensorboard_service.ListTensorboardRunsResponse( + tensorboard_runs=[ + tensorboard_run.TensorboardRun(), + ], + next_page_token="ghi", + ), + tensorboard_service.ListTensorboardRunsResponse( + tensorboard_runs=[ + tensorboard_run.TensorboardRun(), + tensorboard_run.TensorboardRun(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.list_tensorboard_runs(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.DeleteTensorboardRunRequest, + dict, + ], +) +def test_delete_tensorboard_run(request_type, transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_tensorboard_run), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.delete_tensorboard_run(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.DeleteTensorboardRunRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_delete_tensorboard_run_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_tensorboard_run), "__call__" + ) as call: + client.delete_tensorboard_run() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.DeleteTensorboardRunRequest() + + +@pytest.mark.asyncio +async def test_delete_tensorboard_run_async( + transport: str = "grpc_asyncio", + request_type=tensorboard_service.DeleteTensorboardRunRequest, +): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_tensorboard_run), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.delete_tensorboard_run(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.DeleteTensorboardRunRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_delete_tensorboard_run_async_from_dict(): + await test_delete_tensorboard_run_async(request_type=dict) + + +def test_delete_tensorboard_run_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.DeleteTensorboardRunRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_tensorboard_run), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_tensorboard_run(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_tensorboard_run_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.DeleteTensorboardRunRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_tensorboard_run), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.delete_tensorboard_run(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_delete_tensorboard_run_flattened(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_tensorboard_run), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_tensorboard_run( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_delete_tensorboard_run_flattened_error(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_tensorboard_run( + tensorboard_service.DeleteTensorboardRunRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_delete_tensorboard_run_flattened_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_tensorboard_run), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_tensorboard_run( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_delete_tensorboard_run_flattened_error_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.delete_tensorboard_run( + tensorboard_service.DeleteTensorboardRunRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.BatchCreateTensorboardTimeSeriesRequest, + dict, + ], +) +def test_batch_create_tensorboard_time_series(request_type, transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_create_tensorboard_time_series), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = ( + tensorboard_service.BatchCreateTensorboardTimeSeriesResponse() + ) + response = client.batch_create_tensorboard_time_series(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.BatchCreateTensorboardTimeSeriesRequest() + + # Establish that the response is the type that we expect. + assert isinstance( + response, tensorboard_service.BatchCreateTensorboardTimeSeriesResponse + ) + + +def test_batch_create_tensorboard_time_series_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_create_tensorboard_time_series), "__call__" + ) as call: + client.batch_create_tensorboard_time_series() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.BatchCreateTensorboardTimeSeriesRequest() + + +@pytest.mark.asyncio +async def test_batch_create_tensorboard_time_series_async( + transport: str = "grpc_asyncio", + request_type=tensorboard_service.BatchCreateTensorboardTimeSeriesRequest, +): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_create_tensorboard_time_series), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.BatchCreateTensorboardTimeSeriesResponse() + ) + response = await client.batch_create_tensorboard_time_series(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.BatchCreateTensorboardTimeSeriesRequest() + + # Establish that the response is the type that we expect. + assert isinstance( + response, tensorboard_service.BatchCreateTensorboardTimeSeriesResponse + ) + + +@pytest.mark.asyncio +async def test_batch_create_tensorboard_time_series_async_from_dict(): + await test_batch_create_tensorboard_time_series_async(request_type=dict) + + +def test_batch_create_tensorboard_time_series_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.BatchCreateTensorboardTimeSeriesRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_create_tensorboard_time_series), "__call__" + ) as call: + call.return_value = ( + tensorboard_service.BatchCreateTensorboardTimeSeriesResponse() + ) + client.batch_create_tensorboard_time_series(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_batch_create_tensorboard_time_series_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.BatchCreateTensorboardTimeSeriesRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_create_tensorboard_time_series), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.BatchCreateTensorboardTimeSeriesResponse() + ) + await client.batch_create_tensorboard_time_series(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_batch_create_tensorboard_time_series_flattened(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_create_tensorboard_time_series), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = ( + tensorboard_service.BatchCreateTensorboardTimeSeriesResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.batch_create_tensorboard_time_series( + parent="parent_value", + requests=[ + tensorboard_service.CreateTensorboardTimeSeriesRequest( + parent="parent_value" + ) + ], + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].requests + mock_val = [ + tensorboard_service.CreateTensorboardTimeSeriesRequest( + parent="parent_value" + ) + ] + assert arg == mock_val + + +def test_batch_create_tensorboard_time_series_flattened_error(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.batch_create_tensorboard_time_series( + tensorboard_service.BatchCreateTensorboardTimeSeriesRequest(), + parent="parent_value", + requests=[ + tensorboard_service.CreateTensorboardTimeSeriesRequest( + parent="parent_value" + ) + ], + ) + + +@pytest.mark.asyncio +async def test_batch_create_tensorboard_time_series_flattened_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_create_tensorboard_time_series), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = ( + tensorboard_service.BatchCreateTensorboardTimeSeriesResponse() + ) + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.BatchCreateTensorboardTimeSeriesResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.batch_create_tensorboard_time_series( + parent="parent_value", + requests=[ + tensorboard_service.CreateTensorboardTimeSeriesRequest( + parent="parent_value" + ) + ], + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].requests + mock_val = [ + tensorboard_service.CreateTensorboardTimeSeriesRequest( + parent="parent_value" + ) + ] + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_batch_create_tensorboard_time_series_flattened_error_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.batch_create_tensorboard_time_series( + tensorboard_service.BatchCreateTensorboardTimeSeriesRequest(), + parent="parent_value", + requests=[ + tensorboard_service.CreateTensorboardTimeSeriesRequest( + parent="parent_value" + ) + ], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.CreateTensorboardTimeSeriesRequest, + dict, + ], +) +def test_create_tensorboard_time_series(request_type, transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_tensorboard_time_series), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gca_tensorboard_time_series.TensorboardTimeSeries( + name="name_value", + display_name="display_name_value", + description="description_value", + value_type=gca_tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR, + etag="etag_value", + plugin_name="plugin_name_value", + plugin_data=b"plugin_data_blob", + ) + response = client.create_tensorboard_time_series(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.CreateTensorboardTimeSeriesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_tensorboard_time_series.TensorboardTimeSeries) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert ( + response.value_type + == gca_tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR + ) + assert response.etag == "etag_value" + assert response.plugin_name == "plugin_name_value" + assert response.plugin_data == b"plugin_data_blob" + + +def test_create_tensorboard_time_series_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_tensorboard_time_series), "__call__" + ) as call: + client.create_tensorboard_time_series() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.CreateTensorboardTimeSeriesRequest() + + +@pytest.mark.asyncio +async def test_create_tensorboard_time_series_async( + transport: str = "grpc_asyncio", + request_type=tensorboard_service.CreateTensorboardTimeSeriesRequest, +): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_tensorboard_time_series), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_tensorboard_time_series.TensorboardTimeSeries( + name="name_value", + display_name="display_name_value", + description="description_value", + value_type=gca_tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR, + etag="etag_value", + plugin_name="plugin_name_value", + plugin_data=b"plugin_data_blob", + ) + ) + response = await client.create_tensorboard_time_series(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.CreateTensorboardTimeSeriesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_tensorboard_time_series.TensorboardTimeSeries) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert ( + response.value_type + == gca_tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR + ) + assert response.etag == "etag_value" + assert response.plugin_name == "plugin_name_value" + assert response.plugin_data == b"plugin_data_blob" + + +@pytest.mark.asyncio +async def test_create_tensorboard_time_series_async_from_dict(): + await test_create_tensorboard_time_series_async(request_type=dict) + + +def test_create_tensorboard_time_series_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.CreateTensorboardTimeSeriesRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_tensorboard_time_series), "__call__" + ) as call: + call.return_value = gca_tensorboard_time_series.TensorboardTimeSeries() + client.create_tensorboard_time_series(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_create_tensorboard_time_series_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.CreateTensorboardTimeSeriesRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_tensorboard_time_series), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_tensorboard_time_series.TensorboardTimeSeries() + ) + await client.create_tensorboard_time_series(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_create_tensorboard_time_series_flattened(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_tensorboard_time_series), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gca_tensorboard_time_series.TensorboardTimeSeries() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_tensorboard_time_series( + parent="parent_value", + tensorboard_time_series=gca_tensorboard_time_series.TensorboardTimeSeries( + name="name_value" + ), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].tensorboard_time_series + mock_val = gca_tensorboard_time_series.TensorboardTimeSeries(name="name_value") + assert arg == mock_val + + +def test_create_tensorboard_time_series_flattened_error(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_tensorboard_time_series( + tensorboard_service.CreateTensorboardTimeSeriesRequest(), + parent="parent_value", + tensorboard_time_series=gca_tensorboard_time_series.TensorboardTimeSeries( + name="name_value" + ), + ) + + +@pytest.mark.asyncio +async def test_create_tensorboard_time_series_flattened_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_tensorboard_time_series), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gca_tensorboard_time_series.TensorboardTimeSeries() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_tensorboard_time_series.TensorboardTimeSeries() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_tensorboard_time_series( + parent="parent_value", + tensorboard_time_series=gca_tensorboard_time_series.TensorboardTimeSeries( + name="name_value" + ), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].tensorboard_time_series + mock_val = gca_tensorboard_time_series.TensorboardTimeSeries(name="name_value") + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_create_tensorboard_time_series_flattened_error_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.create_tensorboard_time_series( + tensorboard_service.CreateTensorboardTimeSeriesRequest(), + parent="parent_value", + tensorboard_time_series=gca_tensorboard_time_series.TensorboardTimeSeries( + name="name_value" + ), + ) + + +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.GetTensorboardTimeSeriesRequest, + dict, + ], +) +def test_get_tensorboard_time_series(request_type, transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_tensorboard_time_series), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_time_series.TensorboardTimeSeries( + name="name_value", + display_name="display_name_value", + description="description_value", + value_type=tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR, + etag="etag_value", + plugin_name="plugin_name_value", + plugin_data=b"plugin_data_blob", + ) + response = client.get_tensorboard_time_series(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.GetTensorboardTimeSeriesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, tensorboard_time_series.TensorboardTimeSeries) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert ( + response.value_type + == tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR + ) + assert response.etag == "etag_value" + assert response.plugin_name == "plugin_name_value" + assert response.plugin_data == b"plugin_data_blob" + + +def test_get_tensorboard_time_series_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_tensorboard_time_series), "__call__" + ) as call: + client.get_tensorboard_time_series() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.GetTensorboardTimeSeriesRequest() + + +@pytest.mark.asyncio +async def test_get_tensorboard_time_series_async( + transport: str = "grpc_asyncio", + request_type=tensorboard_service.GetTensorboardTimeSeriesRequest, +): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_tensorboard_time_series), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_time_series.TensorboardTimeSeries( + name="name_value", + display_name="display_name_value", + description="description_value", + value_type=tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR, + etag="etag_value", + plugin_name="plugin_name_value", + plugin_data=b"plugin_data_blob", + ) + ) + response = await client.get_tensorboard_time_series(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.GetTensorboardTimeSeriesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, tensorboard_time_series.TensorboardTimeSeries) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert ( + response.value_type + == tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR + ) + assert response.etag == "etag_value" + assert response.plugin_name == "plugin_name_value" + assert response.plugin_data == b"plugin_data_blob" + + +@pytest.mark.asyncio +async def test_get_tensorboard_time_series_async_from_dict(): + await test_get_tensorboard_time_series_async(request_type=dict) + + +def test_get_tensorboard_time_series_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.GetTensorboardTimeSeriesRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_tensorboard_time_series), "__call__" + ) as call: + call.return_value = tensorboard_time_series.TensorboardTimeSeries() + client.get_tensorboard_time_series(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_tensorboard_time_series_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.GetTensorboardTimeSeriesRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_tensorboard_time_series), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_time_series.TensorboardTimeSeries() + ) + await client.get_tensorboard_time_series(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_get_tensorboard_time_series_flattened(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_tensorboard_time_series), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_time_series.TensorboardTimeSeries() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_tensorboard_time_series( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_get_tensorboard_time_series_flattened_error(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_tensorboard_time_series( + tensorboard_service.GetTensorboardTimeSeriesRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_tensorboard_time_series_flattened_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_tensorboard_time_series), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_time_series.TensorboardTimeSeries() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_time_series.TensorboardTimeSeries() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_tensorboard_time_series( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_get_tensorboard_time_series_flattened_error_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_tensorboard_time_series( + tensorboard_service.GetTensorboardTimeSeriesRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.UpdateTensorboardTimeSeriesRequest, + dict, + ], +) +def test_update_tensorboard_time_series(request_type, transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_tensorboard_time_series), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gca_tensorboard_time_series.TensorboardTimeSeries( + name="name_value", + display_name="display_name_value", + description="description_value", + value_type=gca_tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR, + etag="etag_value", + plugin_name="plugin_name_value", + plugin_data=b"plugin_data_blob", + ) + response = client.update_tensorboard_time_series(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.UpdateTensorboardTimeSeriesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_tensorboard_time_series.TensorboardTimeSeries) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert ( + response.value_type + == gca_tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR + ) + assert response.etag == "etag_value" + assert response.plugin_name == "plugin_name_value" + assert response.plugin_data == b"plugin_data_blob" + + +def test_update_tensorboard_time_series_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_tensorboard_time_series), "__call__" + ) as call: + client.update_tensorboard_time_series() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.UpdateTensorboardTimeSeriesRequest() + + +@pytest.mark.asyncio +async def test_update_tensorboard_time_series_async( + transport: str = "grpc_asyncio", + request_type=tensorboard_service.UpdateTensorboardTimeSeriesRequest, +): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_tensorboard_time_series), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_tensorboard_time_series.TensorboardTimeSeries( + name="name_value", + display_name="display_name_value", + description="description_value", + value_type=gca_tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR, + etag="etag_value", + plugin_name="plugin_name_value", + plugin_data=b"plugin_data_blob", + ) + ) + response = await client.update_tensorboard_time_series(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.UpdateTensorboardTimeSeriesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_tensorboard_time_series.TensorboardTimeSeries) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert ( + response.value_type + == gca_tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR + ) + assert response.etag == "etag_value" + assert response.plugin_name == "plugin_name_value" + assert response.plugin_data == b"plugin_data_blob" + + +@pytest.mark.asyncio +async def test_update_tensorboard_time_series_async_from_dict(): + await test_update_tensorboard_time_series_async(request_type=dict) + + +def test_update_tensorboard_time_series_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.UpdateTensorboardTimeSeriesRequest() + + request.tensorboard_time_series.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_tensorboard_time_series), "__call__" + ) as call: + call.return_value = gca_tensorboard_time_series.TensorboardTimeSeries() + client.update_tensorboard_time_series(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "tensorboard_time_series.name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_update_tensorboard_time_series_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.UpdateTensorboardTimeSeriesRequest() + + request.tensorboard_time_series.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_tensorboard_time_series), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_tensorboard_time_series.TensorboardTimeSeries() + ) + await client.update_tensorboard_time_series(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "tensorboard_time_series.name=name_value", + ) in kw["metadata"] + + +def test_update_tensorboard_time_series_flattened(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_tensorboard_time_series), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gca_tensorboard_time_series.TensorboardTimeSeries() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.update_tensorboard_time_series( + tensorboard_time_series=gca_tensorboard_time_series.TensorboardTimeSeries( + name="name_value" + ), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].tensorboard_time_series + mock_val = gca_tensorboard_time_series.TensorboardTimeSeries(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + + +def test_update_tensorboard_time_series_flattened_error(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.update_tensorboard_time_series( + tensorboard_service.UpdateTensorboardTimeSeriesRequest(), + tensorboard_time_series=gca_tensorboard_time_series.TensorboardTimeSeries( + name="name_value" + ), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.asyncio +async def test_update_tensorboard_time_series_flattened_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.update_tensorboard_time_series), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gca_tensorboard_time_series.TensorboardTimeSeries() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_tensorboard_time_series.TensorboardTimeSeries() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.update_tensorboard_time_series( + tensorboard_time_series=gca_tensorboard_time_series.TensorboardTimeSeries( + name="name_value" + ), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].tensorboard_time_series + mock_val = gca_tensorboard_time_series.TensorboardTimeSeries(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_update_tensorboard_time_series_flattened_error_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.update_tensorboard_time_series( + tensorboard_service.UpdateTensorboardTimeSeriesRequest(), + tensorboard_time_series=gca_tensorboard_time_series.TensorboardTimeSeries( + name="name_value" + ), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + + +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.ListTensorboardTimeSeriesRequest, + dict, + ], +) +def test_list_tensorboard_time_series(request_type, transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_time_series), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_service.ListTensorboardTimeSeriesResponse( + next_page_token="next_page_token_value", + ) + response = client.list_tensorboard_time_series(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.ListTensorboardTimeSeriesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListTensorboardTimeSeriesPager) + assert response.next_page_token == "next_page_token_value" + + +def test_list_tensorboard_time_series_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_time_series), "__call__" + ) as call: + client.list_tensorboard_time_series() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.ListTensorboardTimeSeriesRequest() + + +@pytest.mark.asyncio +async def test_list_tensorboard_time_series_async( + transport: str = "grpc_asyncio", + request_type=tensorboard_service.ListTensorboardTimeSeriesRequest, +): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_time_series), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.ListTensorboardTimeSeriesResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.list_tensorboard_time_series(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.ListTensorboardTimeSeriesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListTensorboardTimeSeriesAsyncPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_list_tensorboard_time_series_async_from_dict(): + await test_list_tensorboard_time_series_async(request_type=dict) + + +def test_list_tensorboard_time_series_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.ListTensorboardTimeSeriesRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_time_series), "__call__" + ) as call: + call.return_value = tensorboard_service.ListTensorboardTimeSeriesResponse() + client.list_tensorboard_time_series(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_tensorboard_time_series_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.ListTensorboardTimeSeriesRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_time_series), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.ListTensorboardTimeSeriesResponse() + ) + await client.list_tensorboard_time_series(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_list_tensorboard_time_series_flattened(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_time_series), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_service.ListTensorboardTimeSeriesResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_tensorboard_time_series( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +def test_list_tensorboard_time_series_flattened_error(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_tensorboard_time_series( + tensorboard_service.ListTensorboardTimeSeriesRequest(), + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_tensorboard_time_series_flattened_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_time_series), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_service.ListTensorboardTimeSeriesResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.ListTensorboardTimeSeriesResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_tensorboard_time_series( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_list_tensorboard_time_series_flattened_error_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_tensorboard_time_series( + tensorboard_service.ListTensorboardTimeSeriesRequest(), + parent="parent_value", + ) + + +def test_list_tensorboard_time_series_pager(transport_name: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_time_series), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + tensorboard_service.ListTensorboardTimeSeriesResponse( + tensorboard_time_series=[ + tensorboard_time_series.TensorboardTimeSeries(), + tensorboard_time_series.TensorboardTimeSeries(), + tensorboard_time_series.TensorboardTimeSeries(), + ], + next_page_token="abc", + ), + tensorboard_service.ListTensorboardTimeSeriesResponse( + tensorboard_time_series=[], + next_page_token="def", + ), + tensorboard_service.ListTensorboardTimeSeriesResponse( + tensorboard_time_series=[ + tensorboard_time_series.TensorboardTimeSeries(), + ], + next_page_token="ghi", + ), + tensorboard_service.ListTensorboardTimeSeriesResponse( + tensorboard_time_series=[ + tensorboard_time_series.TensorboardTimeSeries(), + tensorboard_time_series.TensorboardTimeSeries(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_tensorboard_time_series(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all( + isinstance(i, tensorboard_time_series.TensorboardTimeSeries) + for i in results + ) + + +def test_list_tensorboard_time_series_pages(transport_name: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_time_series), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + tensorboard_service.ListTensorboardTimeSeriesResponse( + tensorboard_time_series=[ + tensorboard_time_series.TensorboardTimeSeries(), + tensorboard_time_series.TensorboardTimeSeries(), + tensorboard_time_series.TensorboardTimeSeries(), + ], + next_page_token="abc", + ), + tensorboard_service.ListTensorboardTimeSeriesResponse( + tensorboard_time_series=[], + next_page_token="def", + ), + tensorboard_service.ListTensorboardTimeSeriesResponse( + tensorboard_time_series=[ + tensorboard_time_series.TensorboardTimeSeries(), + ], + next_page_token="ghi", + ), + tensorboard_service.ListTensorboardTimeSeriesResponse( + tensorboard_time_series=[ + tensorboard_time_series.TensorboardTimeSeries(), + tensorboard_time_series.TensorboardTimeSeries(), + ], + ), + RuntimeError, + ) + pages = list(client.list_tensorboard_time_series(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.asyncio +async def test_list_tensorboard_time_series_async_pager(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_time_series), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + tensorboard_service.ListTensorboardTimeSeriesResponse( + tensorboard_time_series=[ + tensorboard_time_series.TensorboardTimeSeries(), + tensorboard_time_series.TensorboardTimeSeries(), + tensorboard_time_series.TensorboardTimeSeries(), + ], + next_page_token="abc", + ), + tensorboard_service.ListTensorboardTimeSeriesResponse( + tensorboard_time_series=[], + next_page_token="def", + ), + tensorboard_service.ListTensorboardTimeSeriesResponse( + tensorboard_time_series=[ + tensorboard_time_series.TensorboardTimeSeries(), + ], + next_page_token="ghi", + ), + tensorboard_service.ListTensorboardTimeSeriesResponse( + tensorboard_time_series=[ + tensorboard_time_series.TensorboardTimeSeries(), + tensorboard_time_series.TensorboardTimeSeries(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_tensorboard_time_series( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all( + isinstance(i, tensorboard_time_series.TensorboardTimeSeries) + for i in responses + ) + + +@pytest.mark.asyncio +async def test_list_tensorboard_time_series_async_pages(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_time_series), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + tensorboard_service.ListTensorboardTimeSeriesResponse( + tensorboard_time_series=[ + tensorboard_time_series.TensorboardTimeSeries(), + tensorboard_time_series.TensorboardTimeSeries(), + tensorboard_time_series.TensorboardTimeSeries(), + ], + next_page_token="abc", + ), + tensorboard_service.ListTensorboardTimeSeriesResponse( + tensorboard_time_series=[], + next_page_token="def", + ), + tensorboard_service.ListTensorboardTimeSeriesResponse( + tensorboard_time_series=[ + tensorboard_time_series.TensorboardTimeSeries(), + ], + next_page_token="ghi", + ), + tensorboard_service.ListTensorboardTimeSeriesResponse( + tensorboard_time_series=[ + tensorboard_time_series.TensorboardTimeSeries(), + tensorboard_time_series.TensorboardTimeSeries(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.list_tensorboard_time_series(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.DeleteTensorboardTimeSeriesRequest, + dict, + ], +) +def test_delete_tensorboard_time_series(request_type, transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_tensorboard_time_series), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.delete_tensorboard_time_series(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.DeleteTensorboardTimeSeriesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_delete_tensorboard_time_series_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_tensorboard_time_series), "__call__" + ) as call: + client.delete_tensorboard_time_series() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.DeleteTensorboardTimeSeriesRequest() + + +@pytest.mark.asyncio +async def test_delete_tensorboard_time_series_async( + transport: str = "grpc_asyncio", + request_type=tensorboard_service.DeleteTensorboardTimeSeriesRequest, +): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_tensorboard_time_series), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.delete_tensorboard_time_series(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.DeleteTensorboardTimeSeriesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_delete_tensorboard_time_series_async_from_dict(): + await test_delete_tensorboard_time_series_async(request_type=dict) + + +def test_delete_tensorboard_time_series_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.DeleteTensorboardTimeSeriesRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_tensorboard_time_series), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_tensorboard_time_series(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_tensorboard_time_series_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.DeleteTensorboardTimeSeriesRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_tensorboard_time_series), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.delete_tensorboard_time_series(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_delete_tensorboard_time_series_flattened(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_tensorboard_time_series), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_tensorboard_time_series( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_delete_tensorboard_time_series_flattened_error(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_tensorboard_time_series( + tensorboard_service.DeleteTensorboardTimeSeriesRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_delete_tensorboard_time_series_flattened_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_tensorboard_time_series), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_tensorboard_time_series( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_delete_tensorboard_time_series_flattened_error_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.delete_tensorboard_time_series( + tensorboard_service.DeleteTensorboardTimeSeriesRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest, + dict, + ], +) +def test_batch_read_tensorboard_time_series_data(request_type, transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_read_tensorboard_time_series_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = ( + tensorboard_service.BatchReadTensorboardTimeSeriesDataResponse() + ) + response = client.batch_read_tensorboard_time_series_data(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert ( + args[0] == tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest() + ) + + # Establish that the response is the type that we expect. + assert isinstance( + response, tensorboard_service.BatchReadTensorboardTimeSeriesDataResponse + ) + + +def test_batch_read_tensorboard_time_series_data_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_read_tensorboard_time_series_data), "__call__" + ) as call: + client.batch_read_tensorboard_time_series_data() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert ( + args[0] == tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest() + ) + + +@pytest.mark.asyncio +async def test_batch_read_tensorboard_time_series_data_async( + transport: str = "grpc_asyncio", + request_type=tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest, +): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_read_tensorboard_time_series_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.BatchReadTensorboardTimeSeriesDataResponse() + ) + response = await client.batch_read_tensorboard_time_series_data(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert ( + args[0] == tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest() + ) + + # Establish that the response is the type that we expect. + assert isinstance( + response, tensorboard_service.BatchReadTensorboardTimeSeriesDataResponse + ) + + +@pytest.mark.asyncio +async def test_batch_read_tensorboard_time_series_data_async_from_dict(): + await test_batch_read_tensorboard_time_series_data_async(request_type=dict) + + +def test_batch_read_tensorboard_time_series_data_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest() + + request.tensorboard = "tensorboard_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_read_tensorboard_time_series_data), "__call__" + ) as call: + call.return_value = ( + tensorboard_service.BatchReadTensorboardTimeSeriesDataResponse() + ) + client.batch_read_tensorboard_time_series_data(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "tensorboard=tensorboard_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_batch_read_tensorboard_time_series_data_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest() + + request.tensorboard = "tensorboard_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_read_tensorboard_time_series_data), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.BatchReadTensorboardTimeSeriesDataResponse() + ) + await client.batch_read_tensorboard_time_series_data(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "tensorboard=tensorboard_value", + ) in kw["metadata"] + + +def test_batch_read_tensorboard_time_series_data_flattened(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_read_tensorboard_time_series_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = ( + tensorboard_service.BatchReadTensorboardTimeSeriesDataResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.batch_read_tensorboard_time_series_data( + tensorboard="tensorboard_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].tensorboard + mock_val = "tensorboard_value" + assert arg == mock_val + + +def test_batch_read_tensorboard_time_series_data_flattened_error(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.batch_read_tensorboard_time_series_data( + tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest(), + tensorboard="tensorboard_value", + ) + + +@pytest.mark.asyncio +async def test_batch_read_tensorboard_time_series_data_flattened_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_read_tensorboard_time_series_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = ( + tensorboard_service.BatchReadTensorboardTimeSeriesDataResponse() + ) + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.BatchReadTensorboardTimeSeriesDataResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.batch_read_tensorboard_time_series_data( + tensorboard="tensorboard_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].tensorboard + mock_val = "tensorboard_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_batch_read_tensorboard_time_series_data_flattened_error_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.batch_read_tensorboard_time_series_data( + tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest(), + tensorboard="tensorboard_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.ReadTensorboardTimeSeriesDataRequest, + dict, + ], +) +def test_read_tensorboard_time_series_data(request_type, transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.read_tensorboard_time_series_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_service.ReadTensorboardTimeSeriesDataResponse() + response = client.read_tensorboard_time_series_data(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.ReadTensorboardTimeSeriesDataRequest() + + # Establish that the response is the type that we expect. + assert isinstance( + response, tensorboard_service.ReadTensorboardTimeSeriesDataResponse + ) + + +def test_read_tensorboard_time_series_data_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.read_tensorboard_time_series_data), "__call__" + ) as call: + client.read_tensorboard_time_series_data() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.ReadTensorboardTimeSeriesDataRequest() + + +@pytest.mark.asyncio +async def test_read_tensorboard_time_series_data_async( + transport: str = "grpc_asyncio", + request_type=tensorboard_service.ReadTensorboardTimeSeriesDataRequest, +): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.read_tensorboard_time_series_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.ReadTensorboardTimeSeriesDataResponse() + ) + response = await client.read_tensorboard_time_series_data(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.ReadTensorboardTimeSeriesDataRequest() + + # Establish that the response is the type that we expect. + assert isinstance( + response, tensorboard_service.ReadTensorboardTimeSeriesDataResponse + ) + + +@pytest.mark.asyncio +async def test_read_tensorboard_time_series_data_async_from_dict(): + await test_read_tensorboard_time_series_data_async(request_type=dict) + + +def test_read_tensorboard_time_series_data_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.ReadTensorboardTimeSeriesDataRequest() + + request.tensorboard_time_series = "tensorboard_time_series_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.read_tensorboard_time_series_data), "__call__" + ) as call: + call.return_value = tensorboard_service.ReadTensorboardTimeSeriesDataResponse() + client.read_tensorboard_time_series_data(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "tensorboard_time_series=tensorboard_time_series_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_read_tensorboard_time_series_data_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.ReadTensorboardTimeSeriesDataRequest() + + request.tensorboard_time_series = "tensorboard_time_series_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.read_tensorboard_time_series_data), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.ReadTensorboardTimeSeriesDataResponse() + ) + await client.read_tensorboard_time_series_data(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "tensorboard_time_series=tensorboard_time_series_value", + ) in kw["metadata"] + + +def test_read_tensorboard_time_series_data_flattened(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.read_tensorboard_time_series_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_service.ReadTensorboardTimeSeriesDataResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.read_tensorboard_time_series_data( + tensorboard_time_series="tensorboard_time_series_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].tensorboard_time_series + mock_val = "tensorboard_time_series_value" + assert arg == mock_val + + +def test_read_tensorboard_time_series_data_flattened_error(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.read_tensorboard_time_series_data( + tensorboard_service.ReadTensorboardTimeSeriesDataRequest(), + tensorboard_time_series="tensorboard_time_series_value", + ) + + +@pytest.mark.asyncio +async def test_read_tensorboard_time_series_data_flattened_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.read_tensorboard_time_series_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_service.ReadTensorboardTimeSeriesDataResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.ReadTensorboardTimeSeriesDataResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.read_tensorboard_time_series_data( + tensorboard_time_series="tensorboard_time_series_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].tensorboard_time_series + mock_val = "tensorboard_time_series_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_read_tensorboard_time_series_data_flattened_error_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.read_tensorboard_time_series_data( + tensorboard_service.ReadTensorboardTimeSeriesDataRequest(), + tensorboard_time_series="tensorboard_time_series_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.ReadTensorboardBlobDataRequest, + dict, + ], +) +def test_read_tensorboard_blob_data(request_type, transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.read_tensorboard_blob_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iter( + [tensorboard_service.ReadTensorboardBlobDataResponse()] + ) + response = client.read_tensorboard_blob_data(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.ReadTensorboardBlobDataRequest() + + # Establish that the response is the type that we expect. + for message in response: + assert isinstance(message, tensorboard_service.ReadTensorboardBlobDataResponse) + + +def test_read_tensorboard_blob_data_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.read_tensorboard_blob_data), "__call__" + ) as call: + client.read_tensorboard_blob_data() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.ReadTensorboardBlobDataRequest() + + +@pytest.mark.asyncio +async def test_read_tensorboard_blob_data_async( + transport: str = "grpc_asyncio", + request_type=tensorboard_service.ReadTensorboardBlobDataRequest, +): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.read_tensorboard_blob_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = mock.Mock(aio.UnaryStreamCall, autospec=True) + call.return_value.read = mock.AsyncMock( + side_effect=[tensorboard_service.ReadTensorboardBlobDataResponse()] + ) + response = await client.read_tensorboard_blob_data(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.ReadTensorboardBlobDataRequest() + + # Establish that the response is the type that we expect. + message = await response.read() + assert isinstance(message, tensorboard_service.ReadTensorboardBlobDataResponse) + + +@pytest.mark.asyncio +async def test_read_tensorboard_blob_data_async_from_dict(): + await test_read_tensorboard_blob_data_async(request_type=dict) + + +def test_read_tensorboard_blob_data_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.ReadTensorboardBlobDataRequest() + + request.time_series = "time_series_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.read_tensorboard_blob_data), "__call__" + ) as call: + call.return_value = iter( + [tensorboard_service.ReadTensorboardBlobDataResponse()] + ) + client.read_tensorboard_blob_data(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "time_series=time_series_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_read_tensorboard_blob_data_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.ReadTensorboardBlobDataRequest() + + request.time_series = "time_series_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.read_tensorboard_blob_data), "__call__" + ) as call: + call.return_value = mock.Mock(aio.UnaryStreamCall, autospec=True) + call.return_value.read = mock.AsyncMock( + side_effect=[tensorboard_service.ReadTensorboardBlobDataResponse()] + ) + await client.read_tensorboard_blob_data(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "time_series=time_series_value", + ) in kw["metadata"] + + +def test_read_tensorboard_blob_data_flattened(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.read_tensorboard_blob_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iter( + [tensorboard_service.ReadTensorboardBlobDataResponse()] + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.read_tensorboard_blob_data( + time_series="time_series_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].time_series + mock_val = "time_series_value" + assert arg == mock_val + + +def test_read_tensorboard_blob_data_flattened_error(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.read_tensorboard_blob_data( + tensorboard_service.ReadTensorboardBlobDataRequest(), + time_series="time_series_value", + ) + + +@pytest.mark.asyncio +async def test_read_tensorboard_blob_data_flattened_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.read_tensorboard_blob_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iter( + [tensorboard_service.ReadTensorboardBlobDataResponse()] + ) + + call.return_value = mock.Mock(aio.UnaryStreamCall, autospec=True) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.read_tensorboard_blob_data( + time_series="time_series_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].time_series + mock_val = "time_series_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_read_tensorboard_blob_data_flattened_error_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.read_tensorboard_blob_data( + tensorboard_service.ReadTensorboardBlobDataRequest(), + time_series="time_series_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.WriteTensorboardExperimentDataRequest, + dict, + ], +) +def test_write_tensorboard_experiment_data(request_type, transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.write_tensorboard_experiment_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_service.WriteTensorboardExperimentDataResponse() + response = client.write_tensorboard_experiment_data(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.WriteTensorboardExperimentDataRequest() + + # Establish that the response is the type that we expect. + assert isinstance( + response, tensorboard_service.WriteTensorboardExperimentDataResponse + ) + + +def test_write_tensorboard_experiment_data_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.write_tensorboard_experiment_data), "__call__" + ) as call: + client.write_tensorboard_experiment_data() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.WriteTensorboardExperimentDataRequest() + + +@pytest.mark.asyncio +async def test_write_tensorboard_experiment_data_async( + transport: str = "grpc_asyncio", + request_type=tensorboard_service.WriteTensorboardExperimentDataRequest, +): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.write_tensorboard_experiment_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.WriteTensorboardExperimentDataResponse() + ) + response = await client.write_tensorboard_experiment_data(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.WriteTensorboardExperimentDataRequest() + + # Establish that the response is the type that we expect. + assert isinstance( + response, tensorboard_service.WriteTensorboardExperimentDataResponse + ) + + +@pytest.mark.asyncio +async def test_write_tensorboard_experiment_data_async_from_dict(): + await test_write_tensorboard_experiment_data_async(request_type=dict) + + +def test_write_tensorboard_experiment_data_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.WriteTensorboardExperimentDataRequest() + + request.tensorboard_experiment = "tensorboard_experiment_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.write_tensorboard_experiment_data), "__call__" + ) as call: + call.return_value = tensorboard_service.WriteTensorboardExperimentDataResponse() + client.write_tensorboard_experiment_data(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "tensorboard_experiment=tensorboard_experiment_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_write_tensorboard_experiment_data_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.WriteTensorboardExperimentDataRequest() + + request.tensorboard_experiment = "tensorboard_experiment_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.write_tensorboard_experiment_data), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.WriteTensorboardExperimentDataResponse() + ) + await client.write_tensorboard_experiment_data(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "tensorboard_experiment=tensorboard_experiment_value", + ) in kw["metadata"] + + +def test_write_tensorboard_experiment_data_flattened(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.write_tensorboard_experiment_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_service.WriteTensorboardExperimentDataResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.write_tensorboard_experiment_data( + tensorboard_experiment="tensorboard_experiment_value", + write_run_data_requests=[ + tensorboard_service.WriteTensorboardRunDataRequest( + tensorboard_run="tensorboard_run_value" + ) + ], + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].tensorboard_experiment + mock_val = "tensorboard_experiment_value" + assert arg == mock_val + arg = args[0].write_run_data_requests + mock_val = [ + tensorboard_service.WriteTensorboardRunDataRequest( + tensorboard_run="tensorboard_run_value" + ) + ] + assert arg == mock_val + + +def test_write_tensorboard_experiment_data_flattened_error(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.write_tensorboard_experiment_data( + tensorboard_service.WriteTensorboardExperimentDataRequest(), + tensorboard_experiment="tensorboard_experiment_value", + write_run_data_requests=[ + tensorboard_service.WriteTensorboardRunDataRequest( + tensorboard_run="tensorboard_run_value" + ) + ], + ) + + +@pytest.mark.asyncio +async def test_write_tensorboard_experiment_data_flattened_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.write_tensorboard_experiment_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_service.WriteTensorboardExperimentDataResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.WriteTensorboardExperimentDataResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.write_tensorboard_experiment_data( + tensorboard_experiment="tensorboard_experiment_value", + write_run_data_requests=[ + tensorboard_service.WriteTensorboardRunDataRequest( + tensorboard_run="tensorboard_run_value" + ) + ], + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].tensorboard_experiment + mock_val = "tensorboard_experiment_value" + assert arg == mock_val + arg = args[0].write_run_data_requests + mock_val = [ + tensorboard_service.WriteTensorboardRunDataRequest( + tensorboard_run="tensorboard_run_value" + ) + ] + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_write_tensorboard_experiment_data_flattened_error_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.write_tensorboard_experiment_data( + tensorboard_service.WriteTensorboardExperimentDataRequest(), + tensorboard_experiment="tensorboard_experiment_value", + write_run_data_requests=[ + tensorboard_service.WriteTensorboardRunDataRequest( + tensorboard_run="tensorboard_run_value" + ) + ], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.WriteTensorboardRunDataRequest, + dict, + ], +) +def test_write_tensorboard_run_data(request_type, transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.write_tensorboard_run_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_service.WriteTensorboardRunDataResponse() + response = client.write_tensorboard_run_data(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.WriteTensorboardRunDataRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, tensorboard_service.WriteTensorboardRunDataResponse) + + +def test_write_tensorboard_run_data_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.write_tensorboard_run_data), "__call__" + ) as call: + client.write_tensorboard_run_data() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.WriteTensorboardRunDataRequest() + + +@pytest.mark.asyncio +async def test_write_tensorboard_run_data_async( + transport: str = "grpc_asyncio", + request_type=tensorboard_service.WriteTensorboardRunDataRequest, +): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.write_tensorboard_run_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.WriteTensorboardRunDataResponse() + ) + response = await client.write_tensorboard_run_data(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.WriteTensorboardRunDataRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, tensorboard_service.WriteTensorboardRunDataResponse) + + +@pytest.mark.asyncio +async def test_write_tensorboard_run_data_async_from_dict(): + await test_write_tensorboard_run_data_async(request_type=dict) + + +def test_write_tensorboard_run_data_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.WriteTensorboardRunDataRequest() + + request.tensorboard_run = "tensorboard_run_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.write_tensorboard_run_data), "__call__" + ) as call: + call.return_value = tensorboard_service.WriteTensorboardRunDataResponse() + client.write_tensorboard_run_data(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "tensorboard_run=tensorboard_run_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_write_tensorboard_run_data_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.WriteTensorboardRunDataRequest() + + request.tensorboard_run = "tensorboard_run_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.write_tensorboard_run_data), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.WriteTensorboardRunDataResponse() + ) + await client.write_tensorboard_run_data(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "tensorboard_run=tensorboard_run_value", + ) in kw["metadata"] + + +def test_write_tensorboard_run_data_flattened(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.write_tensorboard_run_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_service.WriteTensorboardRunDataResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.write_tensorboard_run_data( + tensorboard_run="tensorboard_run_value", + time_series_data=[ + tensorboard_data.TimeSeriesData( + tensorboard_time_series_id="tensorboard_time_series_id_value" + ) + ], + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].tensorboard_run + mock_val = "tensorboard_run_value" + assert arg == mock_val + arg = args[0].time_series_data + mock_val = [ + tensorboard_data.TimeSeriesData( + tensorboard_time_series_id="tensorboard_time_series_id_value" + ) + ] + assert arg == mock_val + + +def test_write_tensorboard_run_data_flattened_error(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.write_tensorboard_run_data( + tensorboard_service.WriteTensorboardRunDataRequest(), + tensorboard_run="tensorboard_run_value", + time_series_data=[ + tensorboard_data.TimeSeriesData( + tensorboard_time_series_id="tensorboard_time_series_id_value" + ) + ], + ) + + +@pytest.mark.asyncio +async def test_write_tensorboard_run_data_flattened_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.write_tensorboard_run_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_service.WriteTensorboardRunDataResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.WriteTensorboardRunDataResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.write_tensorboard_run_data( + tensorboard_run="tensorboard_run_value", + time_series_data=[ + tensorboard_data.TimeSeriesData( + tensorboard_time_series_id="tensorboard_time_series_id_value" + ) + ], + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].tensorboard_run + mock_val = "tensorboard_run_value" + assert arg == mock_val + arg = args[0].time_series_data + mock_val = [ + tensorboard_data.TimeSeriesData( + tensorboard_time_series_id="tensorboard_time_series_id_value" + ) + ] + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_write_tensorboard_run_data_flattened_error_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.write_tensorboard_run_data( + tensorboard_service.WriteTensorboardRunDataRequest(), + tensorboard_run="tensorboard_run_value", + time_series_data=[ + tensorboard_data.TimeSeriesData( + tensorboard_time_series_id="tensorboard_time_series_id_value" + ) + ], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.ExportTensorboardTimeSeriesDataRequest, + dict, + ], +) +def test_export_tensorboard_time_series_data(request_type, transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.export_tensorboard_time_series_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_service.ExportTensorboardTimeSeriesDataResponse( + next_page_token="next_page_token_value", + ) + response = client.export_tensorboard_time_series_data(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.ExportTensorboardTimeSeriesDataRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ExportTensorboardTimeSeriesDataPager) + assert response.next_page_token == "next_page_token_value" + + +def test_export_tensorboard_time_series_data_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.export_tensorboard_time_series_data), "__call__" + ) as call: + client.export_tensorboard_time_series_data() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.ExportTensorboardTimeSeriesDataRequest() + + +@pytest.mark.asyncio +async def test_export_tensorboard_time_series_data_async( + transport: str = "grpc_asyncio", + request_type=tensorboard_service.ExportTensorboardTimeSeriesDataRequest, +): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.export_tensorboard_time_series_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.ExportTensorboardTimeSeriesDataResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.export_tensorboard_time_series_data(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.ExportTensorboardTimeSeriesDataRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ExportTensorboardTimeSeriesDataAsyncPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_export_tensorboard_time_series_data_async_from_dict(): + await test_export_tensorboard_time_series_data_async(request_type=dict) + + +def test_export_tensorboard_time_series_data_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.ExportTensorboardTimeSeriesDataRequest() + + request.tensorboard_time_series = "tensorboard_time_series_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.export_tensorboard_time_series_data), "__call__" + ) as call: + call.return_value = ( + tensorboard_service.ExportTensorboardTimeSeriesDataResponse() + ) + client.export_tensorboard_time_series_data(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "tensorboard_time_series=tensorboard_time_series_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_export_tensorboard_time_series_data_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.ExportTensorboardTimeSeriesDataRequest() + + request.tensorboard_time_series = "tensorboard_time_series_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.export_tensorboard_time_series_data), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.ExportTensorboardTimeSeriesDataResponse() + ) + await client.export_tensorboard_time_series_data(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "tensorboard_time_series=tensorboard_time_series_value", + ) in kw["metadata"] + + +def test_export_tensorboard_time_series_data_flattened(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.export_tensorboard_time_series_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = ( + tensorboard_service.ExportTensorboardTimeSeriesDataResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.export_tensorboard_time_series_data( + tensorboard_time_series="tensorboard_time_series_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].tensorboard_time_series + mock_val = "tensorboard_time_series_value" + assert arg == mock_val + + +def test_export_tensorboard_time_series_data_flattened_error(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.export_tensorboard_time_series_data( + tensorboard_service.ExportTensorboardTimeSeriesDataRequest(), + tensorboard_time_series="tensorboard_time_series_value", + ) + + +@pytest.mark.asyncio +async def test_export_tensorboard_time_series_data_flattened_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.export_tensorboard_time_series_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = ( + tensorboard_service.ExportTensorboardTimeSeriesDataResponse() + ) + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.ExportTensorboardTimeSeriesDataResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.export_tensorboard_time_series_data( + tensorboard_time_series="tensorboard_time_series_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].tensorboard_time_series + mock_val = "tensorboard_time_series_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_export_tensorboard_time_series_data_flattened_error_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.export_tensorboard_time_series_data( + tensorboard_service.ExportTensorboardTimeSeriesDataRequest(), + tensorboard_time_series="tensorboard_time_series_value", + ) + + +def test_export_tensorboard_time_series_data_pager(transport_name: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.export_tensorboard_time_series_data), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + tensorboard_service.ExportTensorboardTimeSeriesDataResponse( + time_series_data_points=[ + tensorboard_data.TimeSeriesDataPoint(), + tensorboard_data.TimeSeriesDataPoint(), + tensorboard_data.TimeSeriesDataPoint(), + ], + next_page_token="abc", + ), + tensorboard_service.ExportTensorboardTimeSeriesDataResponse( + time_series_data_points=[], + next_page_token="def", + ), + tensorboard_service.ExportTensorboardTimeSeriesDataResponse( + time_series_data_points=[ + tensorboard_data.TimeSeriesDataPoint(), + ], + next_page_token="ghi", + ), + tensorboard_service.ExportTensorboardTimeSeriesDataResponse( + time_series_data_points=[ + tensorboard_data.TimeSeriesDataPoint(), + tensorboard_data.TimeSeriesDataPoint(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("tensorboard_time_series", ""),) + ), + ) + pager = client.export_tensorboard_time_series_data(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, tensorboard_data.TimeSeriesDataPoint) for i in results) + + +def test_export_tensorboard_time_series_data_pages(transport_name: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.export_tensorboard_time_series_data), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + tensorboard_service.ExportTensorboardTimeSeriesDataResponse( + time_series_data_points=[ + tensorboard_data.TimeSeriesDataPoint(), + tensorboard_data.TimeSeriesDataPoint(), + tensorboard_data.TimeSeriesDataPoint(), + ], + next_page_token="abc", + ), + tensorboard_service.ExportTensorboardTimeSeriesDataResponse( + time_series_data_points=[], + next_page_token="def", + ), + tensorboard_service.ExportTensorboardTimeSeriesDataResponse( + time_series_data_points=[ + tensorboard_data.TimeSeriesDataPoint(), + ], + next_page_token="ghi", + ), + tensorboard_service.ExportTensorboardTimeSeriesDataResponse( + time_series_data_points=[ + tensorboard_data.TimeSeriesDataPoint(), + tensorboard_data.TimeSeriesDataPoint(), + ], + ), + RuntimeError, + ) + pages = list(client.export_tensorboard_time_series_data(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.asyncio +async def test_export_tensorboard_time_series_data_async_pager(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.export_tensorboard_time_series_data), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + tensorboard_service.ExportTensorboardTimeSeriesDataResponse( + time_series_data_points=[ + tensorboard_data.TimeSeriesDataPoint(), + tensorboard_data.TimeSeriesDataPoint(), + tensorboard_data.TimeSeriesDataPoint(), + ], + next_page_token="abc", + ), + tensorboard_service.ExportTensorboardTimeSeriesDataResponse( + time_series_data_points=[], + next_page_token="def", + ), + tensorboard_service.ExportTensorboardTimeSeriesDataResponse( + time_series_data_points=[ + tensorboard_data.TimeSeriesDataPoint(), + ], + next_page_token="ghi", + ), + tensorboard_service.ExportTensorboardTimeSeriesDataResponse( + time_series_data_points=[ + tensorboard_data.TimeSeriesDataPoint(), + tensorboard_data.TimeSeriesDataPoint(), + ], + ), + RuntimeError, + ) + async_pager = await client.export_tensorboard_time_series_data( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all( + isinstance(i, tensorboard_data.TimeSeriesDataPoint) for i in responses + ) + + +@pytest.mark.asyncio +async def test_export_tensorboard_time_series_data_async_pages(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.export_tensorboard_time_series_data), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + tensorboard_service.ExportTensorboardTimeSeriesDataResponse( + time_series_data_points=[ + tensorboard_data.TimeSeriesDataPoint(), + tensorboard_data.TimeSeriesDataPoint(), + tensorboard_data.TimeSeriesDataPoint(), + ], + next_page_token="abc", + ), + tensorboard_service.ExportTensorboardTimeSeriesDataResponse( + time_series_data_points=[], + next_page_token="def", + ), + tensorboard_service.ExportTensorboardTimeSeriesDataResponse( + time_series_data_points=[ + tensorboard_data.TimeSeriesDataPoint(), + ], + next_page_token="ghi", + ), + tensorboard_service.ExportTensorboardTimeSeriesDataResponse( + time_series_data_points=[ + tensorboard_data.TimeSeriesDataPoint(), + tensorboard_data.TimeSeriesDataPoint(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.export_tensorboard_time_series_data(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.TensorboardServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.TensorboardServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = TensorboardServiceClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide an api_key and a transport instance. + transport = transports.TensorboardServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = TensorboardServiceClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = TensorboardServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.TensorboardServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = TensorboardServiceClient( + client_options={"scopes": ["1", "2"]}, + transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.TensorboardServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + client = TensorboardServiceClient(transport=transport) + assert client.transport is transport + + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.TensorboardServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.TensorboardServiceGrpcAsyncIOTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.TensorboardServiceGrpcTransport, + transports.TensorboardServiceGrpcAsyncIOTransport, + ], +) +def test_transport_adc(transport_class): + # Test default credentials are used if not provided. + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class() + adc.assert_called_once() + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = TensorboardServiceClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + +def test_transport_grpc_default(): + # A client should use the gRPC transport by default. + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.TensorboardServiceGrpcTransport, + ) + + +def test_tensorboard_service_base_transport_error(): + # Passing both a credentials object and credentials_file should raise an error + with pytest.raises(core_exceptions.DuplicateCredentialArgs): + transport = transports.TensorboardServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + credentials_file="credentials.json", + ) + + +def test_tensorboard_service_base_transport(): + # Instantiate the base transport. + with mock.patch( + "google.cloud.aiplatform_v1.services.tensorboard_service.transports.TensorboardServiceTransport.__init__" + ) as Transport: + Transport.return_value = None + transport = transports.TensorboardServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Every method on the transport should just blindly + # raise NotImplementedError. + methods = ( + "create_tensorboard", + "get_tensorboard", + "update_tensorboard", + "list_tensorboards", + "delete_tensorboard", + "create_tensorboard_experiment", + "get_tensorboard_experiment", + "update_tensorboard_experiment", + "list_tensorboard_experiments", + "delete_tensorboard_experiment", + "create_tensorboard_run", + "batch_create_tensorboard_runs", + "get_tensorboard_run", + "update_tensorboard_run", + "list_tensorboard_runs", + "delete_tensorboard_run", + "batch_create_tensorboard_time_series", + "create_tensorboard_time_series", + "get_tensorboard_time_series", + "update_tensorboard_time_series", + "list_tensorboard_time_series", + "delete_tensorboard_time_series", + "batch_read_tensorboard_time_series_data", + "read_tensorboard_time_series_data", + "read_tensorboard_blob_data", + "write_tensorboard_experiment_data", + "write_tensorboard_run_data", + "export_tensorboard_time_series_data", + "set_iam_policy", + "get_iam_policy", + "test_iam_permissions", + "get_location", + "list_locations", + "get_operation", + "wait_operation", + "cancel_operation", + "delete_operation", + "list_operations", + ) + for method in methods: + with pytest.raises(NotImplementedError): + getattr(transport, method)(request=object()) + + with pytest.raises(NotImplementedError): + transport.close() + + # Additionally, the LRO client (a property) should + # also raise NotImplementedError + with pytest.raises(NotImplementedError): + transport.operations_client + + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + + +def test_tensorboard_service_base_transport_with_credentials_file(): + # Instantiate the base transport with a credentials file + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch( + "google.cloud.aiplatform_v1.services.tensorboard_service.transports.TensorboardServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.TensorboardServiceTransport( + credentials_file="credentials.json", + quota_project_id="octopus", + ) + load_creds.assert_called_once_with( + "credentials.json", + scopes=None, + default_scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/cloud-platform.read-only", + ), + quota_project_id="octopus", + ) + + +def test_tensorboard_service_base_transport_with_adc(): + # Test the default credentials are used if credentials and credentials_file are None. + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( + "google.cloud.aiplatform_v1.services.tensorboard_service.transports.TensorboardServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.TensorboardServiceTransport() + adc.assert_called_once() + + +def test_tensorboard_service_auth_adc(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + TensorboardServiceClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/cloud-platform.read-only", + ), + quota_project_id=None, + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.TensorboardServiceGrpcTransport, + transports.TensorboardServiceGrpcAsyncIOTransport, + ], +) +def test_tensorboard_service_transport_auth_adc(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/cloud-platform.read-only", + ), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.TensorboardServiceGrpcTransport, grpc_helpers), + (transports.TensorboardServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +def test_tensorboard_service_transport_create_channel(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/cloud-platform.read-only", + ), + scopes=["1", "2"], + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.TensorboardServiceGrpcTransport, + transports.TensorboardServiceGrpcAsyncIOTransport, + ], +) +def test_tensorboard_service_grpc_transport_client_cert_source_for_mtls( + transport_class, +): + cred = ga_credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds, + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback, + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, private_key=expected_key + ) + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_tensorboard_service_host_no_port(transport_name): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions( + api_endpoint="aiplatform.googleapis.com" + ), + transport=transport_name, + ) + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_tensorboard_service_host_with_port(transport_name): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions( + api_endpoint="aiplatform.googleapis.com:8000" + ), + transport=transport_name, + ) + assert client.transport._host == ("aiplatform.googleapis.com:8000") + + +def test_tensorboard_service_grpc_transport_channel(): + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.TensorboardServiceGrpcTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +def test_tensorboard_service_grpc_asyncio_transport_channel(): + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.TensorboardServiceGrpcAsyncIOTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize( + "transport_class", + [ + transports.TensorboardServiceGrpcTransport, + transports.TensorboardServiceGrpcAsyncIOTransport, + ], +) +def test_tensorboard_service_transport_channel_mtls_with_client_cert_source( + transport_class, +): + with mock.patch( + "grpc.ssl_channel_credentials", autospec=True + ) as grpc_ssl_channel_cred: + with mock.patch.object( + transport_class, "create_channel" + ) as grpc_create_channel: + mock_ssl_cred = mock.Mock() + grpc_ssl_channel_cred.return_value = mock_ssl_cred + + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + + cred = ga_credentials.AnonymousCredentials() + with pytest.warns(DeprecationWarning): + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (cred, None) + transport = transport_class( + host="squid.clam.whelk", + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=client_cert_source_callback, + ) + adc.assert_called_once() + + grpc_ssl_channel_cred.assert_called_once_with( + certificate_chain=b"cert bytes", private_key=b"key bytes" + ) + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize( + "transport_class", + [ + transports.TensorboardServiceGrpcTransport, + transports.TensorboardServiceGrpcAsyncIOTransport, + ], +) +def test_tensorboard_service_transport_channel_mtls_with_adc(transport_class): + mock_ssl_cred = mock.Mock() + with mock.patch.multiple( + "google.auth.transport.grpc.SslCredentials", + __init__=mock.Mock(return_value=None), + ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), + ): + with mock.patch.object( + transport_class, "create_channel" + ) as grpc_create_channel: + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + mock_cred = mock.Mock() + + with pytest.warns(DeprecationWarning): + transport = transport_class( + host="squid.clam.whelk", + credentials=mock_cred, + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=None, + ) + + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=mock_cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + + +def test_tensorboard_service_grpc_lro_client(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_tensorboard_service_grpc_lro_async_client(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_tensorboard_path(): + project = "squid" + location = "clam" + tensorboard = "whelk" + expected = ( + "projects/{project}/locations/{location}/tensorboards/{tensorboard}".format( + project=project, + location=location, + tensorboard=tensorboard, + ) + ) + actual = TensorboardServiceClient.tensorboard_path(project, location, tensorboard) + assert expected == actual + + +def test_parse_tensorboard_path(): + expected = { + "project": "octopus", + "location": "oyster", + "tensorboard": "nudibranch", + } + path = TensorboardServiceClient.tensorboard_path(**expected) + + # Check that the path construction is reversible. + actual = TensorboardServiceClient.parse_tensorboard_path(path) + assert expected == actual + + +def test_tensorboard_experiment_path(): + project = "cuttlefish" + location = "mussel" + tensorboard = "winkle" + experiment = "nautilus" + expected = "projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}".format( + project=project, + location=location, + tensorboard=tensorboard, + experiment=experiment, + ) + actual = TensorboardServiceClient.tensorboard_experiment_path( + project, location, tensorboard, experiment + ) + assert expected == actual + + +def test_parse_tensorboard_experiment_path(): + expected = { + "project": "scallop", + "location": "abalone", + "tensorboard": "squid", + "experiment": "clam", + } + path = TensorboardServiceClient.tensorboard_experiment_path(**expected) + + # Check that the path construction is reversible. + actual = TensorboardServiceClient.parse_tensorboard_experiment_path(path) + assert expected == actual + + +def test_tensorboard_run_path(): + project = "whelk" + location = "octopus" + tensorboard = "oyster" + experiment = "nudibranch" + run = "cuttlefish" + expected = "projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}".format( + project=project, + location=location, + tensorboard=tensorboard, + experiment=experiment, + run=run, + ) + actual = TensorboardServiceClient.tensorboard_run_path( + project, location, tensorboard, experiment, run + ) + assert expected == actual + + +def test_parse_tensorboard_run_path(): + expected = { + "project": "mussel", + "location": "winkle", + "tensorboard": "nautilus", + "experiment": "scallop", + "run": "abalone", + } + path = TensorboardServiceClient.tensorboard_run_path(**expected) + + # Check that the path construction is reversible. + actual = TensorboardServiceClient.parse_tensorboard_run_path(path) + assert expected == actual + + +def test_tensorboard_time_series_path(): + project = "squid" + location = "clam" + tensorboard = "whelk" + experiment = "octopus" + run = "oyster" + time_series = "nudibranch" + expected = "projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}/timeSeries/{time_series}".format( + project=project, + location=location, + tensorboard=tensorboard, + experiment=experiment, + run=run, + time_series=time_series, + ) + actual = TensorboardServiceClient.tensorboard_time_series_path( + project, location, tensorboard, experiment, run, time_series + ) + assert expected == actual + + +def test_parse_tensorboard_time_series_path(): + expected = { + "project": "cuttlefish", + "location": "mussel", + "tensorboard": "winkle", + "experiment": "nautilus", + "run": "scallop", + "time_series": "abalone", + } + path = TensorboardServiceClient.tensorboard_time_series_path(**expected) + + # Check that the path construction is reversible. + actual = TensorboardServiceClient.parse_tensorboard_time_series_path(path) + assert expected == actual + + +def test_common_billing_account_path(): + billing_account = "squid" + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + actual = TensorboardServiceClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "clam", + } + path = TensorboardServiceClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = TensorboardServiceClient.parse_common_billing_account_path(path) + assert expected == actual + + +def test_common_folder_path(): + folder = "whelk" + expected = "folders/{folder}".format( + folder=folder, + ) + actual = TensorboardServiceClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "octopus", + } + path = TensorboardServiceClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = TensorboardServiceClient.parse_common_folder_path(path) + assert expected == actual + + +def test_common_organization_path(): + organization = "oyster" + expected = "organizations/{organization}".format( + organization=organization, + ) + actual = TensorboardServiceClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "nudibranch", + } + path = TensorboardServiceClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = TensorboardServiceClient.parse_common_organization_path(path) + assert expected == actual + + +def test_common_project_path(): + project = "cuttlefish" + expected = "projects/{project}".format( + project=project, + ) + actual = TensorboardServiceClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "mussel", + } + path = TensorboardServiceClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = TensorboardServiceClient.parse_common_project_path(path) + assert expected == actual + + +def test_common_location_path(): + project = "winkle" + location = "nautilus" + expected = "projects/{project}/locations/{location}".format( + project=project, + location=location, + ) + actual = TensorboardServiceClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "scallop", + "location": "abalone", + } + path = TensorboardServiceClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = TensorboardServiceClient.parse_common_location_path(path) + assert expected == actual + + +def test_client_with_default_client_info(): + client_info = gapic_v1.client_info.ClientInfo() + + with mock.patch.object( + transports.TensorboardServiceTransport, "_prep_wrapped_messages" + ) as prep: + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + with mock.patch.object( + transports.TensorboardServiceTransport, "_prep_wrapped_messages" + ) as prep: + transport_class = TensorboardServiceClient.get_transport_class() + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_delete_operation(transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_operation(transport: str = "grpc"): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_operation_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = None + + client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_operation_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_delete_operation_from_dict(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_delete_operation_from_dict_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_cancel_operation(transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation(transport: str = "grpc"): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_wait_operation(transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_wait_operation(transport: str = "grpc"): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_wait_operation_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_wait_operation_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_wait_operation_from_dict(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_wait_operation_from_dict_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_operation(transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_get_operation(transport: str = "grpc"): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_get_operation_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_get_operation_from_dict(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_operations(transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + response = client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +@pytest.mark.asyncio +async def test_list_operations(transport: str = "grpc"): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +def test_list_operations_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_operations_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_operations_from_dict(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + response = client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_operations_from_dict_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_locations(transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + response = client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +@pytest.mark.asyncio +async def test_list_locations(transport: str = "grpc"): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +def test_list_locations_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_locations_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_locations_from_dict(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + response = client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_locations_from_dict_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_location(transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + response = client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +@pytest.mark.asyncio +async def test_get_location_async(transport: str = "grpc_asyncio"): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +def test_get_location_field_headers(): + client = TensorboardServiceClient(credentials=ga_credentials.AnonymousCredentials()) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = locations_pb2.Location() + + client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_location_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials() + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +def test_get_location_from_dict(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + response = client.get_location( + request={ + "name": "locations/abc", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_location_from_dict_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_set_iam_policy(transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + response = client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + response = await client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_set_iam_policy_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_set_iam_policy_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_set_iam_policy_from_dict(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_set_iam_policy_from_dict_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +def test_get_iam_policy(transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + + response = client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + + response = await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_get_iam_policy_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_iam_policy_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_get_iam_policy_from_dict(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_iam_policy_from_dict_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +def test_test_iam_permissions(transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + + response = client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + ) + + response = await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +def test_test_iam_permissions_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_test_iam_permissions_from_dict(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + response = client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_from_dict_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + response = await client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (TensorboardServiceClient, transports.TensorboardServiceGrpcTransport), + ( + TensorboardServiceAsyncClient, + transports.TensorboardServiceGrpcAsyncIOTransport, + ), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) diff --git a/tests/unit/gapic/aiplatform_v1/test_vizier_service.py b/tests/unit/gapic/aiplatform_v1/test_vizier_service.py new file mode 100644 index 0000000000..25b1b51f5e --- /dev/null +++ b/tests/unit/gapic/aiplatform_v1/test_vizier_service.py @@ -0,0 +1,6551 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# +import os + +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock +except ImportError: + import mock + +import grpc +from grpc.experimental import aio +import math +import pytest +from proto.marshal.rules.dates import DurationRule, TimestampRule + + +from google.api_core import client_options +from google.api_core import exceptions as core_exceptions +from google.api_core import future +from google.api_core import gapic_v1 +from google.api_core import grpc_helpers +from google.api_core import grpc_helpers_async +from google.api_core import operation +from google.api_core import operation_async # type: ignore +from google.api_core import operations_v1 +from google.api_core import path_template +from google.auth import credentials as ga_credentials +from google.auth.exceptions import MutualTLSChannelError +from google.cloud.aiplatform_v1.services.vizier_service import VizierServiceAsyncClient +from google.cloud.aiplatform_v1.services.vizier_service import VizierServiceClient +from google.cloud.aiplatform_v1.services.vizier_service import pagers +from google.cloud.aiplatform_v1.services.vizier_service import transports +from google.cloud.aiplatform_v1.types import study +from google.cloud.aiplatform_v1.types import study as gca_study +from google.cloud.aiplatform_v1.types import vizier_service +from google.cloud.location import locations_pb2 +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 +from google.oauth2 import service_account +from google.protobuf import duration_pb2 # type: ignore +from google.protobuf import struct_pb2 # type: ignore +from google.protobuf import timestamp_pb2 # type: ignore +import google.auth + + +def client_cert_source_callback(): + return b"cert bytes", b"key bytes" + + +# If default endpoint is localhost, then default mtls endpoint will be the same. +# This method modifies the default endpoint so the client can produce a different +# mtls endpoint for endpoint testing purposes. +def modify_default_endpoint(client): + return ( + "foo.googleapis.com" + if ("localhost" in client.DEFAULT_ENDPOINT) + else client.DEFAULT_ENDPOINT + ) + + +def test__get_default_mtls_endpoint(): + api_endpoint = "example.googleapis.com" + api_mtls_endpoint = "example.mtls.googleapis.com" + sandbox_endpoint = "example.sandbox.googleapis.com" + sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" + non_googleapi = "api.example.com" + + assert VizierServiceClient._get_default_mtls_endpoint(None) is None + assert ( + VizierServiceClient._get_default_mtls_endpoint(api_endpoint) + == api_mtls_endpoint + ) + assert ( + VizierServiceClient._get_default_mtls_endpoint(api_mtls_endpoint) + == api_mtls_endpoint + ) + assert ( + VizierServiceClient._get_default_mtls_endpoint(sandbox_endpoint) + == sandbox_mtls_endpoint + ) + assert ( + VizierServiceClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) + == sandbox_mtls_endpoint + ) + assert ( + VizierServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + ) + + +@pytest.mark.parametrize( + "client_class,transport_name", + [ + (VizierServiceClient, "grpc"), + (VizierServiceAsyncClient, "grpc_asyncio"), + ], +) +def test_vizier_service_client_from_service_account_info(client_class, transport_name): + creds = ga_credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_info" + ) as factory: + factory.return_value = creds + info = {"valid": True} + client = client_class.from_service_account_info(info, transport=transport_name) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.VizierServiceGrpcTransport, "grpc"), + (transports.VizierServiceGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_vizier_service_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + +@pytest.mark.parametrize( + "client_class,transport_name", + [ + (VizierServiceClient, "grpc"), + (VizierServiceAsyncClient, "grpc_asyncio"), + ], +) +def test_vizier_service_client_from_service_account_file(client_class, transport_name): + creds = ga_credentials.AnonymousCredentials() + with mock.patch.object( + service_account.Credentials, "from_service_account_file" + ) as factory: + factory.return_value = creds + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) + assert client.transport._credentials == creds + assert isinstance(client, client_class) + + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +def test_vizier_service_client_get_transport_class(): + transport = VizierServiceClient.get_transport_class() + available_transports = [ + transports.VizierServiceGrpcTransport, + ] + assert transport in available_transports + + transport = VizierServiceClient.get_transport_class("grpc") + assert transport == transports.VizierServiceGrpcTransport + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (VizierServiceClient, transports.VizierServiceGrpcTransport, "grpc"), + ( + VizierServiceAsyncClient, + transports.VizierServiceGrpcAsyncIOTransport, + "grpc_asyncio", + ), + ], +) +@mock.patch.object( + VizierServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(VizierServiceClient), +) +@mock.patch.object( + VizierServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(VizierServiceAsyncClient), +) +def test_vizier_service_client_client_options( + client_class, transport_class, transport_name +): + # Check that if channel is provided we won't create a new one. + with mock.patch.object(VizierServiceClient, "get_transport_class") as gtc: + transport = transport_class(credentials=ga_credentials.AnonymousCredentials()) + client = client_class(transport=transport) + gtc.assert_not_called() + + # Check that if channel is provided via str we will create a new one. + with mock.patch.object(VizierServiceClient, "get_transport_class") as gtc: + client = client_class(transport=transport_name) + gtc.assert_called() + + # Check the case api_endpoint is provided. + options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(transport=transport_name, client_options=options) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is + # "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is + # "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_MTLS_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has + # unsupported value. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): + with pytest.raises(MutualTLSChannelError): + client = client_class(transport=transport_name) + + # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} + ): + with pytest.raises(ValueError): + client = client_class(transport=transport_name) + + # Check the case quota_project_id is provided + options = client_options.ClientOptions(quota_project_id="octopus") + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id="octopus", + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,use_client_cert_env", + [ + (VizierServiceClient, transports.VizierServiceGrpcTransport, "grpc", "true"), + ( + VizierServiceAsyncClient, + transports.VizierServiceGrpcAsyncIOTransport, + "grpc_asyncio", + "true", + ), + (VizierServiceClient, transports.VizierServiceGrpcTransport, "grpc", "false"), + ( + VizierServiceAsyncClient, + transports.VizierServiceGrpcAsyncIOTransport, + "grpc_asyncio", + "false", + ), + ], +) +@mock.patch.object( + VizierServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(VizierServiceClient), +) +@mock.patch.object( + VizierServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(VizierServiceAsyncClient), +) +@mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "auto"}) +def test_vizier_service_client_mtls_env_auto( + client_class, transport_class, transport_name, use_client_cert_env +): + # This tests the endpoint autoswitch behavior. Endpoint is autoswitched to the default + # mtls endpoint, if GOOGLE_API_USE_CLIENT_CERTIFICATE is "true" and client cert exists. + + # Check the case client_cert_source is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + options = client_options.ClientOptions( + client_cert_source=client_cert_source_callback + ) + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + + if use_client_cert_env == "false": + expected_client_cert_source = None + expected_host = client.DEFAULT_ENDPOINT + else: + expected_client_cert_source = client_cert_source_callback + expected_host = client.DEFAULT_MTLS_ENDPOINT + + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # Check the case ADC client cert is provided. Whether client cert is used depends on + # GOOGLE_API_USE_CLIENT_CERTIFICATE value. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=client_cert_source_callback, + ): + if use_client_cert_env == "false": + expected_host = client.DEFAULT_ENDPOINT + expected_client_cert_source = None + else: + expected_host = client.DEFAULT_MTLS_ENDPOINT + expected_client_cert_source = client_cert_source_callback + + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=expected_host, + scopes=None, + client_cert_source_for_mtls=expected_client_cert_source, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # Check the case client_cert_source and ADC client cert are not provided. + with mock.patch.dict( + os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": use_client_cert_env} + ): + with mock.patch.object(transport_class, "__init__") as patched: + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + patched.return_value = None + client = client_class(transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + +@pytest.mark.parametrize( + "client_class", [VizierServiceClient, VizierServiceAsyncClient] +) +@mock.patch.object( + VizierServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(VizierServiceClient), +) +@mock.patch.object( + VizierServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(VizierServiceAsyncClient), +) +def test_vizier_service_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name", + [ + (VizierServiceClient, transports.VizierServiceGrpcTransport, "grpc"), + ( + VizierServiceAsyncClient, + transports.VizierServiceGrpcAsyncIOTransport, + "grpc_asyncio", + ), + ], +) +def test_vizier_service_client_client_options_scopes( + client_class, transport_class, transport_name +): + # Check the case scopes are provided. + options = client_options.ClientOptions( + scopes=["1", "2"], + ) + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=["1", "2"], + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + VizierServiceClient, + transports.VizierServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + VizierServiceAsyncClient, + transports.VizierServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_vizier_service_client_client_options_credentials_file( + client_class, transport_class, transport_name, grpc_helpers +): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + +def test_vizier_service_client_client_options_from_dict(): + with mock.patch( + "google.cloud.aiplatform_v1.services.vizier_service.transports.VizierServiceGrpcTransport.__init__" + ) as grpc_transport: + grpc_transport.return_value = None + client = VizierServiceClient( + client_options={"api_endpoint": "squid.clam.whelk"} + ) + grpc_transport.assert_called_once_with( + credentials=None, + credentials_file=None, + host="squid.clam.whelk", + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + VizierServiceClient, + transports.VizierServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + VizierServiceAsyncClient, + transports.VizierServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_vizier_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers +): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + vizier_service.CreateStudyRequest, + dict, + ], +) +def test_create_study(request_type, transport: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_study), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = gca_study.Study( + name="name_value", + display_name="display_name_value", + state=gca_study.Study.State.ACTIVE, + inactive_reason="inactive_reason_value", + ) + response = client.create_study(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.CreateStudyRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_study.Study) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.state == gca_study.Study.State.ACTIVE + assert response.inactive_reason == "inactive_reason_value" + + +def test_create_study_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_study), "__call__") as call: + client.create_study() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.CreateStudyRequest() + + +@pytest.mark.asyncio +async def test_create_study_async( + transport: str = "grpc_asyncio", request_type=vizier_service.CreateStudyRequest +): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_study), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_study.Study( + name="name_value", + display_name="display_name_value", + state=gca_study.Study.State.ACTIVE, + inactive_reason="inactive_reason_value", + ) + ) + response = await client.create_study(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.CreateStudyRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_study.Study) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.state == gca_study.Study.State.ACTIVE + assert response.inactive_reason == "inactive_reason_value" + + +@pytest.mark.asyncio +async def test_create_study_async_from_dict(): + await test_create_study_async(request_type=dict) + + +def test_create_study_field_headers(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = vizier_service.CreateStudyRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_study), "__call__") as call: + call.return_value = gca_study.Study() + client.create_study(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_create_study_field_headers_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = vizier_service.CreateStudyRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_study), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gca_study.Study()) + await client.create_study(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_create_study_flattened(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_study), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = gca_study.Study() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_study( + parent="parent_value", + study=gca_study.Study(name="name_value"), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].study + mock_val = gca_study.Study(name="name_value") + assert arg == mock_val + + +def test_create_study_flattened_error(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_study( + vizier_service.CreateStudyRequest(), + parent="parent_value", + study=gca_study.Study(name="name_value"), + ) + + +@pytest.mark.asyncio +async def test_create_study_flattened_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_study), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = gca_study.Study() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gca_study.Study()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_study( + parent="parent_value", + study=gca_study.Study(name="name_value"), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].study + mock_val = gca_study.Study(name="name_value") + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_create_study_flattened_error_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.create_study( + vizier_service.CreateStudyRequest(), + parent="parent_value", + study=gca_study.Study(name="name_value"), + ) + + +@pytest.mark.parametrize( + "request_type", + [ + vizier_service.GetStudyRequest, + dict, + ], +) +def test_get_study(request_type, transport: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_study), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = study.Study( + name="name_value", + display_name="display_name_value", + state=study.Study.State.ACTIVE, + inactive_reason="inactive_reason_value", + ) + response = client.get_study(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.GetStudyRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, study.Study) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.state == study.Study.State.ACTIVE + assert response.inactive_reason == "inactive_reason_value" + + +def test_get_study_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_study), "__call__") as call: + client.get_study() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.GetStudyRequest() + + +@pytest.mark.asyncio +async def test_get_study_async( + transport: str = "grpc_asyncio", request_type=vizier_service.GetStudyRequest +): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_study), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + study.Study( + name="name_value", + display_name="display_name_value", + state=study.Study.State.ACTIVE, + inactive_reason="inactive_reason_value", + ) + ) + response = await client.get_study(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.GetStudyRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, study.Study) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.state == study.Study.State.ACTIVE + assert response.inactive_reason == "inactive_reason_value" + + +@pytest.mark.asyncio +async def test_get_study_async_from_dict(): + await test_get_study_async(request_type=dict) + + +def test_get_study_field_headers(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = vizier_service.GetStudyRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_study), "__call__") as call: + call.return_value = study.Study() + client.get_study(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_study_field_headers_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = vizier_service.GetStudyRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_study), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(study.Study()) + await client.get_study(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_get_study_flattened(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_study), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = study.Study() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_study( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_get_study_flattened_error(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_study( + vizier_service.GetStudyRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_study_flattened_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_study), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = study.Study() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(study.Study()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_study( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_get_study_flattened_error_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_study( + vizier_service.GetStudyRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + vizier_service.ListStudiesRequest, + dict, + ], +) +def test_list_studies(request_type, transport: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_studies), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = vizier_service.ListStudiesResponse( + next_page_token="next_page_token_value", + ) + response = client.list_studies(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.ListStudiesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListStudiesPager) + assert response.next_page_token == "next_page_token_value" + + +def test_list_studies_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_studies), "__call__") as call: + client.list_studies() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.ListStudiesRequest() + + +@pytest.mark.asyncio +async def test_list_studies_async( + transport: str = "grpc_asyncio", request_type=vizier_service.ListStudiesRequest +): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_studies), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + vizier_service.ListStudiesResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.list_studies(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.ListStudiesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListStudiesAsyncPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_list_studies_async_from_dict(): + await test_list_studies_async(request_type=dict) + + +def test_list_studies_field_headers(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = vizier_service.ListStudiesRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_studies), "__call__") as call: + call.return_value = vizier_service.ListStudiesResponse() + client.list_studies(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_studies_field_headers_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = vizier_service.ListStudiesRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_studies), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + vizier_service.ListStudiesResponse() + ) + await client.list_studies(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_list_studies_flattened(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_studies), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = vizier_service.ListStudiesResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_studies( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +def test_list_studies_flattened_error(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_studies( + vizier_service.ListStudiesRequest(), + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_studies_flattened_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_studies), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = vizier_service.ListStudiesResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + vizier_service.ListStudiesResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_studies( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_list_studies_flattened_error_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_studies( + vizier_service.ListStudiesRequest(), + parent="parent_value", + ) + + +def test_list_studies_pager(transport_name: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_studies), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + vizier_service.ListStudiesResponse( + studies=[ + study.Study(), + study.Study(), + study.Study(), + ], + next_page_token="abc", + ), + vizier_service.ListStudiesResponse( + studies=[], + next_page_token="def", + ), + vizier_service.ListStudiesResponse( + studies=[ + study.Study(), + ], + next_page_token="ghi", + ), + vizier_service.ListStudiesResponse( + studies=[ + study.Study(), + study.Study(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_studies(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, study.Study) for i in results) + + +def test_list_studies_pages(transport_name: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_studies), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + vizier_service.ListStudiesResponse( + studies=[ + study.Study(), + study.Study(), + study.Study(), + ], + next_page_token="abc", + ), + vizier_service.ListStudiesResponse( + studies=[], + next_page_token="def", + ), + vizier_service.ListStudiesResponse( + studies=[ + study.Study(), + ], + next_page_token="ghi", + ), + vizier_service.ListStudiesResponse( + studies=[ + study.Study(), + study.Study(), + ], + ), + RuntimeError, + ) + pages = list(client.list_studies(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.asyncio +async def test_list_studies_async_pager(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_studies), "__call__", new_callable=mock.AsyncMock + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + vizier_service.ListStudiesResponse( + studies=[ + study.Study(), + study.Study(), + study.Study(), + ], + next_page_token="abc", + ), + vizier_service.ListStudiesResponse( + studies=[], + next_page_token="def", + ), + vizier_service.ListStudiesResponse( + studies=[ + study.Study(), + ], + next_page_token="ghi", + ), + vizier_service.ListStudiesResponse( + studies=[ + study.Study(), + study.Study(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_studies( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, study.Study) for i in responses) + + +@pytest.mark.asyncio +async def test_list_studies_async_pages(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_studies), "__call__", new_callable=mock.AsyncMock + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + vizier_service.ListStudiesResponse( + studies=[ + study.Study(), + study.Study(), + study.Study(), + ], + next_page_token="abc", + ), + vizier_service.ListStudiesResponse( + studies=[], + next_page_token="def", + ), + vizier_service.ListStudiesResponse( + studies=[ + study.Study(), + ], + next_page_token="ghi", + ), + vizier_service.ListStudiesResponse( + studies=[ + study.Study(), + study.Study(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.list_studies(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize( + "request_type", + [ + vizier_service.DeleteStudyRequest, + dict, + ], +) +def test_delete_study(request_type, transport: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_study), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_study(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.DeleteStudyRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_study_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_study), "__call__") as call: + client.delete_study() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.DeleteStudyRequest() + + +@pytest.mark.asyncio +async def test_delete_study_async( + transport: str = "grpc_asyncio", request_type=vizier_service.DeleteStudyRequest +): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_study), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_study(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.DeleteStudyRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_study_async_from_dict(): + await test_delete_study_async(request_type=dict) + + +def test_delete_study_field_headers(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = vizier_service.DeleteStudyRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_study), "__call__") as call: + call.return_value = None + client.delete_study(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_study_field_headers_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = vizier_service.DeleteStudyRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_study), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_study(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_delete_study_flattened(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_study), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_study( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_delete_study_flattened_error(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_study( + vizier_service.DeleteStudyRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_delete_study_flattened_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_study), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_study( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_delete_study_flattened_error_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.delete_study( + vizier_service.DeleteStudyRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + vizier_service.LookupStudyRequest, + dict, + ], +) +def test_lookup_study(request_type, transport: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.lookup_study), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = study.Study( + name="name_value", + display_name="display_name_value", + state=study.Study.State.ACTIVE, + inactive_reason="inactive_reason_value", + ) + response = client.lookup_study(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.LookupStudyRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, study.Study) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.state == study.Study.State.ACTIVE + assert response.inactive_reason == "inactive_reason_value" + + +def test_lookup_study_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.lookup_study), "__call__") as call: + client.lookup_study() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.LookupStudyRequest() + + +@pytest.mark.asyncio +async def test_lookup_study_async( + transport: str = "grpc_asyncio", request_type=vizier_service.LookupStudyRequest +): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.lookup_study), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + study.Study( + name="name_value", + display_name="display_name_value", + state=study.Study.State.ACTIVE, + inactive_reason="inactive_reason_value", + ) + ) + response = await client.lookup_study(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.LookupStudyRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, study.Study) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.state == study.Study.State.ACTIVE + assert response.inactive_reason == "inactive_reason_value" + + +@pytest.mark.asyncio +async def test_lookup_study_async_from_dict(): + await test_lookup_study_async(request_type=dict) + + +def test_lookup_study_field_headers(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = vizier_service.LookupStudyRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.lookup_study), "__call__") as call: + call.return_value = study.Study() + client.lookup_study(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_lookup_study_field_headers_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = vizier_service.LookupStudyRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.lookup_study), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(study.Study()) + await client.lookup_study(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_lookup_study_flattened(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.lookup_study), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = study.Study() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.lookup_study( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +def test_lookup_study_flattened_error(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.lookup_study( + vizier_service.LookupStudyRequest(), + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_lookup_study_flattened_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.lookup_study), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = study.Study() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(study.Study()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.lookup_study( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_lookup_study_flattened_error_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.lookup_study( + vizier_service.LookupStudyRequest(), + parent="parent_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + vizier_service.SuggestTrialsRequest, + dict, + ], +) +def test_suggest_trials(request_type, transport: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.suggest_trials), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.suggest_trials(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.SuggestTrialsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_suggest_trials_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.suggest_trials), "__call__") as call: + client.suggest_trials() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.SuggestTrialsRequest() + + +@pytest.mark.asyncio +async def test_suggest_trials_async( + transport: str = "grpc_asyncio", request_type=vizier_service.SuggestTrialsRequest +): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.suggest_trials), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.suggest_trials(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.SuggestTrialsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_suggest_trials_async_from_dict(): + await test_suggest_trials_async(request_type=dict) + + +def test_suggest_trials_field_headers(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = vizier_service.SuggestTrialsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.suggest_trials), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.suggest_trials(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_suggest_trials_field_headers_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = vizier_service.SuggestTrialsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.suggest_trials), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.suggest_trials(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.parametrize( + "request_type", + [ + vizier_service.CreateTrialRequest, + dict, + ], +) +def test_create_trial(request_type, transport: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_trial), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = study.Trial( + name="name_value", + id="id_value", + state=study.Trial.State.REQUESTED, + client_id="client_id_value", + infeasible_reason="infeasible_reason_value", + custom_job="custom_job_value", + ) + response = client.create_trial(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.CreateTrialRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, study.Trial) + assert response.name == "name_value" + assert response.id == "id_value" + assert response.state == study.Trial.State.REQUESTED + assert response.client_id == "client_id_value" + assert response.infeasible_reason == "infeasible_reason_value" + assert response.custom_job == "custom_job_value" + + +def test_create_trial_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_trial), "__call__") as call: + client.create_trial() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.CreateTrialRequest() + + +@pytest.mark.asyncio +async def test_create_trial_async( + transport: str = "grpc_asyncio", request_type=vizier_service.CreateTrialRequest +): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_trial), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + study.Trial( + name="name_value", + id="id_value", + state=study.Trial.State.REQUESTED, + client_id="client_id_value", + infeasible_reason="infeasible_reason_value", + custom_job="custom_job_value", + ) + ) + response = await client.create_trial(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.CreateTrialRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, study.Trial) + assert response.name == "name_value" + assert response.id == "id_value" + assert response.state == study.Trial.State.REQUESTED + assert response.client_id == "client_id_value" + assert response.infeasible_reason == "infeasible_reason_value" + assert response.custom_job == "custom_job_value" + + +@pytest.mark.asyncio +async def test_create_trial_async_from_dict(): + await test_create_trial_async(request_type=dict) + + +def test_create_trial_field_headers(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = vizier_service.CreateTrialRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_trial), "__call__") as call: + call.return_value = study.Trial() + client.create_trial(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_create_trial_field_headers_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = vizier_service.CreateTrialRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_trial), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(study.Trial()) + await client.create_trial(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_create_trial_flattened(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_trial), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = study.Trial() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_trial( + parent="parent_value", + trial=study.Trial(name="name_value"), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].trial + mock_val = study.Trial(name="name_value") + assert arg == mock_val + + +def test_create_trial_flattened_error(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_trial( + vizier_service.CreateTrialRequest(), + parent="parent_value", + trial=study.Trial(name="name_value"), + ) + + +@pytest.mark.asyncio +async def test_create_trial_flattened_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.create_trial), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = study.Trial() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(study.Trial()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_trial( + parent="parent_value", + trial=study.Trial(name="name_value"), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].trial + mock_val = study.Trial(name="name_value") + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_create_trial_flattened_error_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.create_trial( + vizier_service.CreateTrialRequest(), + parent="parent_value", + trial=study.Trial(name="name_value"), + ) + + +@pytest.mark.parametrize( + "request_type", + [ + vizier_service.GetTrialRequest, + dict, + ], +) +def test_get_trial(request_type, transport: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_trial), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = study.Trial( + name="name_value", + id="id_value", + state=study.Trial.State.REQUESTED, + client_id="client_id_value", + infeasible_reason="infeasible_reason_value", + custom_job="custom_job_value", + ) + response = client.get_trial(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.GetTrialRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, study.Trial) + assert response.name == "name_value" + assert response.id == "id_value" + assert response.state == study.Trial.State.REQUESTED + assert response.client_id == "client_id_value" + assert response.infeasible_reason == "infeasible_reason_value" + assert response.custom_job == "custom_job_value" + + +def test_get_trial_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_trial), "__call__") as call: + client.get_trial() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.GetTrialRequest() + + +@pytest.mark.asyncio +async def test_get_trial_async( + transport: str = "grpc_asyncio", request_type=vizier_service.GetTrialRequest +): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_trial), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + study.Trial( + name="name_value", + id="id_value", + state=study.Trial.State.REQUESTED, + client_id="client_id_value", + infeasible_reason="infeasible_reason_value", + custom_job="custom_job_value", + ) + ) + response = await client.get_trial(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.GetTrialRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, study.Trial) + assert response.name == "name_value" + assert response.id == "id_value" + assert response.state == study.Trial.State.REQUESTED + assert response.client_id == "client_id_value" + assert response.infeasible_reason == "infeasible_reason_value" + assert response.custom_job == "custom_job_value" + + +@pytest.mark.asyncio +async def test_get_trial_async_from_dict(): + await test_get_trial_async(request_type=dict) + + +def test_get_trial_field_headers(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = vizier_service.GetTrialRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_trial), "__call__") as call: + call.return_value = study.Trial() + client.get_trial(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_trial_field_headers_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = vizier_service.GetTrialRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_trial), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(study.Trial()) + await client.get_trial(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_get_trial_flattened(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_trial), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = study.Trial() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_trial( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_get_trial_flattened_error(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_trial( + vizier_service.GetTrialRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_trial_flattened_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_trial), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = study.Trial() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(study.Trial()) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_trial( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_get_trial_flattened_error_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_trial( + vizier_service.GetTrialRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + vizier_service.ListTrialsRequest, + dict, + ], +) +def test_list_trials(request_type, transport: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_trials), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = vizier_service.ListTrialsResponse( + next_page_token="next_page_token_value", + ) + response = client.list_trials(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.ListTrialsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListTrialsPager) + assert response.next_page_token == "next_page_token_value" + + +def test_list_trials_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_trials), "__call__") as call: + client.list_trials() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.ListTrialsRequest() + + +@pytest.mark.asyncio +async def test_list_trials_async( + transport: str = "grpc_asyncio", request_type=vizier_service.ListTrialsRequest +): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_trials), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + vizier_service.ListTrialsResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.list_trials(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.ListTrialsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListTrialsAsyncPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_list_trials_async_from_dict(): + await test_list_trials_async(request_type=dict) + + +def test_list_trials_field_headers(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = vizier_service.ListTrialsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_trials), "__call__") as call: + call.return_value = vizier_service.ListTrialsResponse() + client.list_trials(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_trials_field_headers_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = vizier_service.ListTrialsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_trials), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + vizier_service.ListTrialsResponse() + ) + await client.list_trials(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_list_trials_flattened(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_trials), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = vizier_service.ListTrialsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_trials( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +def test_list_trials_flattened_error(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_trials( + vizier_service.ListTrialsRequest(), + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_trials_flattened_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_trials), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = vizier_service.ListTrialsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + vizier_service.ListTrialsResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_trials( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_list_trials_flattened_error_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_trials( + vizier_service.ListTrialsRequest(), + parent="parent_value", + ) + + +def test_list_trials_pager(transport_name: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_trials), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + vizier_service.ListTrialsResponse( + trials=[ + study.Trial(), + study.Trial(), + study.Trial(), + ], + next_page_token="abc", + ), + vizier_service.ListTrialsResponse( + trials=[], + next_page_token="def", + ), + vizier_service.ListTrialsResponse( + trials=[ + study.Trial(), + ], + next_page_token="ghi", + ), + vizier_service.ListTrialsResponse( + trials=[ + study.Trial(), + study.Trial(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_trials(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, study.Trial) for i in results) + + +def test_list_trials_pages(transport_name: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_trials), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + vizier_service.ListTrialsResponse( + trials=[ + study.Trial(), + study.Trial(), + study.Trial(), + ], + next_page_token="abc", + ), + vizier_service.ListTrialsResponse( + trials=[], + next_page_token="def", + ), + vizier_service.ListTrialsResponse( + trials=[ + study.Trial(), + ], + next_page_token="ghi", + ), + vizier_service.ListTrialsResponse( + trials=[ + study.Trial(), + study.Trial(), + ], + ), + RuntimeError, + ) + pages = list(client.list_trials(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.asyncio +async def test_list_trials_async_pager(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_trials), "__call__", new_callable=mock.AsyncMock + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + vizier_service.ListTrialsResponse( + trials=[ + study.Trial(), + study.Trial(), + study.Trial(), + ], + next_page_token="abc", + ), + vizier_service.ListTrialsResponse( + trials=[], + next_page_token="def", + ), + vizier_service.ListTrialsResponse( + trials=[ + study.Trial(), + ], + next_page_token="ghi", + ), + vizier_service.ListTrialsResponse( + trials=[ + study.Trial(), + study.Trial(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_trials( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, study.Trial) for i in responses) + + +@pytest.mark.asyncio +async def test_list_trials_async_pages(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_trials), "__call__", new_callable=mock.AsyncMock + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + vizier_service.ListTrialsResponse( + trials=[ + study.Trial(), + study.Trial(), + study.Trial(), + ], + next_page_token="abc", + ), + vizier_service.ListTrialsResponse( + trials=[], + next_page_token="def", + ), + vizier_service.ListTrialsResponse( + trials=[ + study.Trial(), + ], + next_page_token="ghi", + ), + vizier_service.ListTrialsResponse( + trials=[ + study.Trial(), + study.Trial(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.list_trials(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize( + "request_type", + [ + vizier_service.AddTrialMeasurementRequest, + dict, + ], +) +def test_add_trial_measurement(request_type, transport: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_trial_measurement), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = study.Trial( + name="name_value", + id="id_value", + state=study.Trial.State.REQUESTED, + client_id="client_id_value", + infeasible_reason="infeasible_reason_value", + custom_job="custom_job_value", + ) + response = client.add_trial_measurement(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.AddTrialMeasurementRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, study.Trial) + assert response.name == "name_value" + assert response.id == "id_value" + assert response.state == study.Trial.State.REQUESTED + assert response.client_id == "client_id_value" + assert response.infeasible_reason == "infeasible_reason_value" + assert response.custom_job == "custom_job_value" + + +def test_add_trial_measurement_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_trial_measurement), "__call__" + ) as call: + client.add_trial_measurement() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.AddTrialMeasurementRequest() + + +@pytest.mark.asyncio +async def test_add_trial_measurement_async( + transport: str = "grpc_asyncio", + request_type=vizier_service.AddTrialMeasurementRequest, +): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_trial_measurement), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + study.Trial( + name="name_value", + id="id_value", + state=study.Trial.State.REQUESTED, + client_id="client_id_value", + infeasible_reason="infeasible_reason_value", + custom_job="custom_job_value", + ) + ) + response = await client.add_trial_measurement(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.AddTrialMeasurementRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, study.Trial) + assert response.name == "name_value" + assert response.id == "id_value" + assert response.state == study.Trial.State.REQUESTED + assert response.client_id == "client_id_value" + assert response.infeasible_reason == "infeasible_reason_value" + assert response.custom_job == "custom_job_value" + + +@pytest.mark.asyncio +async def test_add_trial_measurement_async_from_dict(): + await test_add_trial_measurement_async(request_type=dict) + + +def test_add_trial_measurement_field_headers(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = vizier_service.AddTrialMeasurementRequest() + + request.trial_name = "trial_name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_trial_measurement), "__call__" + ) as call: + call.return_value = study.Trial() + client.add_trial_measurement(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "trial_name=trial_name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_add_trial_measurement_field_headers_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = vizier_service.AddTrialMeasurementRequest() + + request.trial_name = "trial_name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_trial_measurement), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(study.Trial()) + await client.add_trial_measurement(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "trial_name=trial_name_value", + ) in kw["metadata"] + + +@pytest.mark.parametrize( + "request_type", + [ + vizier_service.CompleteTrialRequest, + dict, + ], +) +def test_complete_trial(request_type, transport: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.complete_trial), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = study.Trial( + name="name_value", + id="id_value", + state=study.Trial.State.REQUESTED, + client_id="client_id_value", + infeasible_reason="infeasible_reason_value", + custom_job="custom_job_value", + ) + response = client.complete_trial(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.CompleteTrialRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, study.Trial) + assert response.name == "name_value" + assert response.id == "id_value" + assert response.state == study.Trial.State.REQUESTED + assert response.client_id == "client_id_value" + assert response.infeasible_reason == "infeasible_reason_value" + assert response.custom_job == "custom_job_value" + + +def test_complete_trial_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.complete_trial), "__call__") as call: + client.complete_trial() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.CompleteTrialRequest() + + +@pytest.mark.asyncio +async def test_complete_trial_async( + transport: str = "grpc_asyncio", request_type=vizier_service.CompleteTrialRequest +): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.complete_trial), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + study.Trial( + name="name_value", + id="id_value", + state=study.Trial.State.REQUESTED, + client_id="client_id_value", + infeasible_reason="infeasible_reason_value", + custom_job="custom_job_value", + ) + ) + response = await client.complete_trial(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.CompleteTrialRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, study.Trial) + assert response.name == "name_value" + assert response.id == "id_value" + assert response.state == study.Trial.State.REQUESTED + assert response.client_id == "client_id_value" + assert response.infeasible_reason == "infeasible_reason_value" + assert response.custom_job == "custom_job_value" + + +@pytest.mark.asyncio +async def test_complete_trial_async_from_dict(): + await test_complete_trial_async(request_type=dict) + + +def test_complete_trial_field_headers(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = vizier_service.CompleteTrialRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.complete_trial), "__call__") as call: + call.return_value = study.Trial() + client.complete_trial(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_complete_trial_field_headers_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = vizier_service.CompleteTrialRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.complete_trial), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(study.Trial()) + await client.complete_trial(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.parametrize( + "request_type", + [ + vizier_service.DeleteTrialRequest, + dict, + ], +) +def test_delete_trial(request_type, transport: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_trial), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_trial(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.DeleteTrialRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_trial_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_trial), "__call__") as call: + client.delete_trial() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.DeleteTrialRequest() + + +@pytest.mark.asyncio +async def test_delete_trial_async( + transport: str = "grpc_asyncio", request_type=vizier_service.DeleteTrialRequest +): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_trial), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_trial(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.DeleteTrialRequest() + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_trial_async_from_dict(): + await test_delete_trial_async(request_type=dict) + + +def test_delete_trial_field_headers(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = vizier_service.DeleteTrialRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_trial), "__call__") as call: + call.return_value = None + client.delete_trial(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_trial_field_headers_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = vizier_service.DeleteTrialRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_trial), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_trial(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_delete_trial_flattened(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_trial), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.delete_trial( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_delete_trial_flattened_error(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.delete_trial( + vizier_service.DeleteTrialRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_delete_trial_flattened_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_trial), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.delete_trial( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_delete_trial_flattened_error_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.delete_trial( + vizier_service.DeleteTrialRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + vizier_service.CheckTrialEarlyStoppingStateRequest, + dict, + ], +) +def test_check_trial_early_stopping_state(request_type, transport: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.check_trial_early_stopping_state), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.check_trial_early_stopping_state(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.CheckTrialEarlyStoppingStateRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_check_trial_early_stopping_state_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.check_trial_early_stopping_state), "__call__" + ) as call: + client.check_trial_early_stopping_state() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.CheckTrialEarlyStoppingStateRequest() + + +@pytest.mark.asyncio +async def test_check_trial_early_stopping_state_async( + transport: str = "grpc_asyncio", + request_type=vizier_service.CheckTrialEarlyStoppingStateRequest, +): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.check_trial_early_stopping_state), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.check_trial_early_stopping_state(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.CheckTrialEarlyStoppingStateRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_check_trial_early_stopping_state_async_from_dict(): + await test_check_trial_early_stopping_state_async(request_type=dict) + + +def test_check_trial_early_stopping_state_field_headers(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = vizier_service.CheckTrialEarlyStoppingStateRequest() + + request.trial_name = "trial_name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.check_trial_early_stopping_state), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.check_trial_early_stopping_state(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "trial_name=trial_name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_check_trial_early_stopping_state_field_headers_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = vizier_service.CheckTrialEarlyStoppingStateRequest() + + request.trial_name = "trial_name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.check_trial_early_stopping_state), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.check_trial_early_stopping_state(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "trial_name=trial_name_value", + ) in kw["metadata"] + + +@pytest.mark.parametrize( + "request_type", + [ + vizier_service.StopTrialRequest, + dict, + ], +) +def test_stop_trial(request_type, transport: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.stop_trial), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = study.Trial( + name="name_value", + id="id_value", + state=study.Trial.State.REQUESTED, + client_id="client_id_value", + infeasible_reason="infeasible_reason_value", + custom_job="custom_job_value", + ) + response = client.stop_trial(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.StopTrialRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, study.Trial) + assert response.name == "name_value" + assert response.id == "id_value" + assert response.state == study.Trial.State.REQUESTED + assert response.client_id == "client_id_value" + assert response.infeasible_reason == "infeasible_reason_value" + assert response.custom_job == "custom_job_value" + + +def test_stop_trial_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.stop_trial), "__call__") as call: + client.stop_trial() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.StopTrialRequest() + + +@pytest.mark.asyncio +async def test_stop_trial_async( + transport: str = "grpc_asyncio", request_type=vizier_service.StopTrialRequest +): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.stop_trial), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + study.Trial( + name="name_value", + id="id_value", + state=study.Trial.State.REQUESTED, + client_id="client_id_value", + infeasible_reason="infeasible_reason_value", + custom_job="custom_job_value", + ) + ) + response = await client.stop_trial(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.StopTrialRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, study.Trial) + assert response.name == "name_value" + assert response.id == "id_value" + assert response.state == study.Trial.State.REQUESTED + assert response.client_id == "client_id_value" + assert response.infeasible_reason == "infeasible_reason_value" + assert response.custom_job == "custom_job_value" + + +@pytest.mark.asyncio +async def test_stop_trial_async_from_dict(): + await test_stop_trial_async(request_type=dict) + + +def test_stop_trial_field_headers(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = vizier_service.StopTrialRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.stop_trial), "__call__") as call: + call.return_value = study.Trial() + client.stop_trial(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_stop_trial_field_headers_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = vizier_service.StopTrialRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.stop_trial), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(study.Trial()) + await client.stop_trial(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.parametrize( + "request_type", + [ + vizier_service.ListOptimalTrialsRequest, + dict, + ], +) +def test_list_optimal_trials(request_type, transport: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_optimal_trials), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = vizier_service.ListOptimalTrialsResponse() + response = client.list_optimal_trials(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.ListOptimalTrialsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, vizier_service.ListOptimalTrialsResponse) + + +def test_list_optimal_trials_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_optimal_trials), "__call__" + ) as call: + client.list_optimal_trials() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.ListOptimalTrialsRequest() + + +@pytest.mark.asyncio +async def test_list_optimal_trials_async( + transport: str = "grpc_asyncio", + request_type=vizier_service.ListOptimalTrialsRequest, +): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_optimal_trials), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + vizier_service.ListOptimalTrialsResponse() + ) + response = await client.list_optimal_trials(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == vizier_service.ListOptimalTrialsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, vizier_service.ListOptimalTrialsResponse) + + +@pytest.mark.asyncio +async def test_list_optimal_trials_async_from_dict(): + await test_list_optimal_trials_async(request_type=dict) + + +def test_list_optimal_trials_field_headers(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = vizier_service.ListOptimalTrialsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_optimal_trials), "__call__" + ) as call: + call.return_value = vizier_service.ListOptimalTrialsResponse() + client.list_optimal_trials(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_optimal_trials_field_headers_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = vizier_service.ListOptimalTrialsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_optimal_trials), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + vizier_service.ListOptimalTrialsResponse() + ) + await client.list_optimal_trials(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_list_optimal_trials_flattened(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_optimal_trials), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = vizier_service.ListOptimalTrialsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_optimal_trials( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +def test_list_optimal_trials_flattened_error(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_optimal_trials( + vizier_service.ListOptimalTrialsRequest(), + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_optimal_trials_flattened_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_optimal_trials), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = vizier_service.ListOptimalTrialsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + vizier_service.ListOptimalTrialsResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_optimal_trials( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_list_optimal_trials_flattened_error_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_optimal_trials( + vizier_service.ListOptimalTrialsRequest(), + parent="parent_value", + ) + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.VizierServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.VizierServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = VizierServiceClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide an api_key and a transport instance. + transport = transports.VizierServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = VizierServiceClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = VizierServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.VizierServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = VizierServiceClient( + client_options={"scopes": ["1", "2"]}, + transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.VizierServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + client = VizierServiceClient(transport=transport) + assert client.transport is transport + + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.VizierServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.VizierServiceGrpcAsyncIOTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.VizierServiceGrpcTransport, + transports.VizierServiceGrpcAsyncIOTransport, + ], +) +def test_transport_adc(transport_class): + # Test default credentials are used if not provided. + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class() + adc.assert_called_once() + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = VizierServiceClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + +def test_transport_grpc_default(): + # A client should use the gRPC transport by default. + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.VizierServiceGrpcTransport, + ) + + +def test_vizier_service_base_transport_error(): + # Passing both a credentials object and credentials_file should raise an error + with pytest.raises(core_exceptions.DuplicateCredentialArgs): + transport = transports.VizierServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + credentials_file="credentials.json", + ) + + +def test_vizier_service_base_transport(): + # Instantiate the base transport. + with mock.patch( + "google.cloud.aiplatform_v1.services.vizier_service.transports.VizierServiceTransport.__init__" + ) as Transport: + Transport.return_value = None + transport = transports.VizierServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Every method on the transport should just blindly + # raise NotImplementedError. + methods = ( + "create_study", + "get_study", + "list_studies", + "delete_study", + "lookup_study", + "suggest_trials", + "create_trial", + "get_trial", + "list_trials", + "add_trial_measurement", + "complete_trial", + "delete_trial", + "check_trial_early_stopping_state", + "stop_trial", + "list_optimal_trials", + "set_iam_policy", + "get_iam_policy", + "test_iam_permissions", + "get_location", + "list_locations", + "get_operation", + "wait_operation", + "cancel_operation", + "delete_operation", + "list_operations", + ) + for method in methods: + with pytest.raises(NotImplementedError): + getattr(transport, method)(request=object()) + + with pytest.raises(NotImplementedError): + transport.close() + + # Additionally, the LRO client (a property) should + # also raise NotImplementedError + with pytest.raises(NotImplementedError): + transport.operations_client + + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + + +def test_vizier_service_base_transport_with_credentials_file(): + # Instantiate the base transport with a credentials file + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch( + "google.cloud.aiplatform_v1.services.vizier_service.transports.VizierServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.VizierServiceTransport( + credentials_file="credentials.json", + quota_project_id="octopus", + ) + load_creds.assert_called_once_with( + "credentials.json", + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +def test_vizier_service_base_transport_with_adc(): + # Test the default credentials are used if credentials and credentials_file are None. + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( + "google.cloud.aiplatform_v1.services.vizier_service.transports.VizierServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.VizierServiceTransport() + adc.assert_called_once() + + +def test_vizier_service_auth_adc(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + VizierServiceClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id=None, + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.VizierServiceGrpcTransport, + transports.VizierServiceGrpcAsyncIOTransport, + ], +) +def test_vizier_service_transport_auth_adc(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.VizierServiceGrpcTransport, grpc_helpers), + (transports.VizierServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +def test_vizier_service_transport_create_channel(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=["1", "2"], + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.VizierServiceGrpcTransport, + transports.VizierServiceGrpcAsyncIOTransport, + ], +) +def test_vizier_service_grpc_transport_client_cert_source_for_mtls(transport_class): + cred = ga_credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds, + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback, + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, private_key=expected_key + ) + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_vizier_service_host_no_port(transport_name): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions( + api_endpoint="aiplatform.googleapis.com" + ), + transport=transport_name, + ) + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_vizier_service_host_with_port(transport_name): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions( + api_endpoint="aiplatform.googleapis.com:8000" + ), + transport=transport_name, + ) + assert client.transport._host == ("aiplatform.googleapis.com:8000") + + +def test_vizier_service_grpc_transport_channel(): + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.VizierServiceGrpcTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +def test_vizier_service_grpc_asyncio_transport_channel(): + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.VizierServiceGrpcAsyncIOTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize( + "transport_class", + [ + transports.VizierServiceGrpcTransport, + transports.VizierServiceGrpcAsyncIOTransport, + ], +) +def test_vizier_service_transport_channel_mtls_with_client_cert_source(transport_class): + with mock.patch( + "grpc.ssl_channel_credentials", autospec=True + ) as grpc_ssl_channel_cred: + with mock.patch.object( + transport_class, "create_channel" + ) as grpc_create_channel: + mock_ssl_cred = mock.Mock() + grpc_ssl_channel_cred.return_value = mock_ssl_cred + + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + + cred = ga_credentials.AnonymousCredentials() + with pytest.warns(DeprecationWarning): + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (cred, None) + transport = transport_class( + host="squid.clam.whelk", + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=client_cert_source_callback, + ) + adc.assert_called_once() + + grpc_ssl_channel_cred.assert_called_once_with( + certificate_chain=b"cert bytes", private_key=b"key bytes" + ) + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize( + "transport_class", + [ + transports.VizierServiceGrpcTransport, + transports.VizierServiceGrpcAsyncIOTransport, + ], +) +def test_vizier_service_transport_channel_mtls_with_adc(transport_class): + mock_ssl_cred = mock.Mock() + with mock.patch.multiple( + "google.auth.transport.grpc.SslCredentials", + __init__=mock.Mock(return_value=None), + ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), + ): + with mock.patch.object( + transport_class, "create_channel" + ) as grpc_create_channel: + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + mock_cred = mock.Mock() + + with pytest.warns(DeprecationWarning): + transport = transport_class( + host="squid.clam.whelk", + credentials=mock_cred, + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=None, + ) + + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=mock_cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + + +def test_vizier_service_grpc_lro_client(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_vizier_service_grpc_lro_async_client(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_custom_job_path(): + project = "squid" + location = "clam" + custom_job = "whelk" + expected = "projects/{project}/locations/{location}/customJobs/{custom_job}".format( + project=project, + location=location, + custom_job=custom_job, + ) + actual = VizierServiceClient.custom_job_path(project, location, custom_job) + assert expected == actual + + +def test_parse_custom_job_path(): + expected = { + "project": "octopus", + "location": "oyster", + "custom_job": "nudibranch", + } + path = VizierServiceClient.custom_job_path(**expected) + + # Check that the path construction is reversible. + actual = VizierServiceClient.parse_custom_job_path(path) + assert expected == actual + + +def test_study_path(): + project = "cuttlefish" + location = "mussel" + study = "winkle" + expected = "projects/{project}/locations/{location}/studies/{study}".format( + project=project, + location=location, + study=study, + ) + actual = VizierServiceClient.study_path(project, location, study) + assert expected == actual + + +def test_parse_study_path(): + expected = { + "project": "nautilus", + "location": "scallop", + "study": "abalone", + } + path = VizierServiceClient.study_path(**expected) + + # Check that the path construction is reversible. + actual = VizierServiceClient.parse_study_path(path) + assert expected == actual + + +def test_trial_path(): + project = "squid" + location = "clam" + study = "whelk" + trial = "octopus" + expected = ( + "projects/{project}/locations/{location}/studies/{study}/trials/{trial}".format( + project=project, + location=location, + study=study, + trial=trial, + ) + ) + actual = VizierServiceClient.trial_path(project, location, study, trial) + assert expected == actual + + +def test_parse_trial_path(): + expected = { + "project": "oyster", + "location": "nudibranch", + "study": "cuttlefish", + "trial": "mussel", + } + path = VizierServiceClient.trial_path(**expected) + + # Check that the path construction is reversible. + actual = VizierServiceClient.parse_trial_path(path) + assert expected == actual + + +def test_common_billing_account_path(): + billing_account = "winkle" + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + actual = VizierServiceClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "nautilus", + } + path = VizierServiceClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = VizierServiceClient.parse_common_billing_account_path(path) + assert expected == actual + + +def test_common_folder_path(): + folder = "scallop" + expected = "folders/{folder}".format( + folder=folder, + ) + actual = VizierServiceClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "abalone", + } + path = VizierServiceClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = VizierServiceClient.parse_common_folder_path(path) + assert expected == actual + + +def test_common_organization_path(): + organization = "squid" + expected = "organizations/{organization}".format( + organization=organization, + ) + actual = VizierServiceClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "clam", + } + path = VizierServiceClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = VizierServiceClient.parse_common_organization_path(path) + assert expected == actual + + +def test_common_project_path(): + project = "whelk" + expected = "projects/{project}".format( + project=project, + ) + actual = VizierServiceClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "octopus", + } + path = VizierServiceClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = VizierServiceClient.parse_common_project_path(path) + assert expected == actual + + +def test_common_location_path(): + project = "oyster" + location = "nudibranch" + expected = "projects/{project}/locations/{location}".format( + project=project, + location=location, + ) + actual = VizierServiceClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "cuttlefish", + "location": "mussel", + } + path = VizierServiceClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = VizierServiceClient.parse_common_location_path(path) + assert expected == actual + + +def test_client_with_default_client_info(): + client_info = gapic_v1.client_info.ClientInfo() + + with mock.patch.object( + transports.VizierServiceTransport, "_prep_wrapped_messages" + ) as prep: + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + with mock.patch.object( + transports.VizierServiceTransport, "_prep_wrapped_messages" + ) as prep: + transport_class = VizierServiceClient.get_transport_class() + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_delete_operation(transport: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_operation(transport: str = "grpc"): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_operation_field_headers(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = None + + client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_operation_field_headers_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_delete_operation_from_dict(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_delete_operation_from_dict_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_cancel_operation(transport: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation(transport: str = "grpc"): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_wait_operation(transport: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_wait_operation(transport: str = "grpc"): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_wait_operation_field_headers(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_wait_operation_field_headers_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_wait_operation_from_dict(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_wait_operation_from_dict_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_operation(transport: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_get_operation(transport: str = "grpc"): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_get_operation_field_headers(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_get_operation_from_dict(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_operations(transport: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + response = client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +@pytest.mark.asyncio +async def test_list_operations(transport: str = "grpc"): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +def test_list_operations_field_headers(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_operations_field_headers_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_operations_from_dict(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + response = client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_operations_from_dict_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_locations(transport: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + response = client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +@pytest.mark.asyncio +async def test_list_locations(transport: str = "grpc"): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +def test_list_locations_field_headers(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_locations_field_headers_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_locations_from_dict(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + response = client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_locations_from_dict_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_location(transport: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + response = client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +@pytest.mark.asyncio +async def test_get_location_async(transport: str = "grpc_asyncio"): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +def test_get_location_field_headers(): + client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials()) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = locations_pb2.Location() + + client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_location_field_headers_async(): + client = VizierServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials()) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +def test_get_location_from_dict(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + response = client.get_location( + request={ + "name": "locations/abc", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_location_from_dict_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_set_iam_policy(transport: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + response = client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + response = await client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_set_iam_policy_field_headers(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_set_iam_policy_field_headers_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_set_iam_policy_from_dict(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_set_iam_policy_from_dict_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +def test_get_iam_policy(transport: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + + response = client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + + response = await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_get_iam_policy_field_headers(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_iam_policy_field_headers_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_get_iam_policy_from_dict(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_iam_policy_from_dict_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +def test_test_iam_permissions(transport: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + + response = client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + ) + + response = await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +def test_test_iam_permissions_field_headers(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_field_headers_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_test_iam_permissions_from_dict(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + response = client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_from_dict_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + response = await client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (VizierServiceClient, transports.VizierServiceGrpcTransport), + (VizierServiceAsyncClient, transports.VizierServiceGrpcAsyncIOTransport), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) diff --git a/tests/unit/gapic/aiplatform_v1beta1/__init__.py b/tests/unit/gapic/aiplatform_v1beta1/__init__.py index 4de65971c2..e8e1c3845d 100644 --- a/tests/unit/gapic/aiplatform_v1beta1/__init__.py +++ b/tests/unit/gapic/aiplatform_v1beta1/__init__.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tests/unit/gapic/aiplatform_v1beta1/test_dataset_service.py b/tests/unit/gapic/aiplatform_v1beta1/test_dataset_service.py index 03b3c97547..94359d85a8 100644 --- a/tests/unit/gapic/aiplatform_v1beta1/test_dataset_service.py +++ b/tests/unit/gapic/aiplatform_v1beta1/test_dataset_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,8 +14,13 @@ # limitations under the License. # import os -import mock -import packaging.version + +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock +except ImportError: + import mock import grpc from grpc.experimental import aio @@ -30,8 +35,10 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.aiplatform_v1beta1.services.dataset_service import ( @@ -42,12 +49,6 @@ ) from google.cloud.aiplatform_v1beta1.services.dataset_service import pagers from google.cloud.aiplatform_v1beta1.services.dataset_service import transports -from google.cloud.aiplatform_v1beta1.services.dataset_service.transports.base import ( - _API_CORE_VERSION, -) -from google.cloud.aiplatform_v1beta1.services.dataset_service.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.aiplatform_v1beta1.types import annotation from google.cloud.aiplatform_v1beta1.types import annotation_spec from google.cloud.aiplatform_v1beta1.types import data_item @@ -57,6 +58,10 @@ from google.cloud.aiplatform_v1beta1.types import encryption_spec from google.cloud.aiplatform_v1beta1.types import io from google.cloud.aiplatform_v1beta1.types import operation as gca_operation +from google.cloud.location import locations_pb2 +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 from google.oauth2 import service_account from google.protobuf import field_mask_pb2 # type: ignore @@ -65,29 +70,6 @@ import google.auth -# TODO(busunkim): Once google-api-core >= 1.26.0 is required: -# - Delete all the api-core and auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - -requires_api_core_lt_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), - reason="This test requires google-api-core < 1.26.0", -) - -requires_api_core_gte_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), - reason="This test requires google-api-core >= 1.26.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -133,40 +115,77 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( - "client_class", [DatasetServiceClient, DatasetServiceAsyncClient,] + "client_class,transport_name", + [ + (DatasetServiceClient, "grpc"), + (DatasetServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_dataset_service_client_from_service_account_info(client_class): +def test_dataset_service_client_from_service_account_info(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.DatasetServiceGrpcTransport, "grpc"), + (transports.DatasetServiceGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_dataset_service_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() @pytest.mark.parametrize( - "client_class", [DatasetServiceClient, DatasetServiceAsyncClient,] + "client_class,transport_name", + [ + (DatasetServiceClient, "grpc"), + (DatasetServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_dataset_service_client_from_service_account_file(client_class): +def test_dataset_service_client_from_service_account_file(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") def test_dataset_service_client_get_transport_class(): @@ -219,7 +238,7 @@ def test_dataset_service_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -228,6 +247,7 @@ def test_dataset_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -235,7 +255,7 @@ def test_dataset_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -244,6 +264,7 @@ def test_dataset_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -251,7 +272,7 @@ def test_dataset_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -260,26 +281,27 @@ def test_dataset_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -288,6 +310,7 @@ def test_dataset_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -337,7 +360,7 @@ def test_dataset_service_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -354,6 +377,7 @@ def test_dataset_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case ADC client cert is provided. Whether client cert is used depends on @@ -378,7 +402,7 @@ def test_dataset_service_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -387,6 +411,7 @@ def test_dataset_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case client_cert_source and ADC client cert are not provided. @@ -399,7 +424,7 @@ def test_dataset_service_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -408,9 +433,91 @@ def test_dataset_service_client_mtls_env_auto( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) +@pytest.mark.parametrize( + "client_class", [DatasetServiceClient, DatasetServiceAsyncClient] +) +@mock.patch.object( + DatasetServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(DatasetServiceClient), +) +@mock.patch.object( + DatasetServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(DatasetServiceAsyncClient), +) +def test_dataset_service_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + @pytest.mark.parametrize( "client_class,transport_class,transport_name", [ @@ -426,10 +533,12 @@ def test_dataset_service_client_client_options_scopes( client_class, transport_class, transport_name ): # Check the case scopes are provided. - options = client_options.ClientOptions(scopes=["1", "2"],) + options = client_options.ClientOptions( + scopes=["1", "2"], + ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -438,28 +547,36 @@ def test_dataset_service_client_client_options_scopes( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (DatasetServiceClient, transports.DatasetServiceGrpcTransport, "grpc"), + ( + DatasetServiceClient, + transports.DatasetServiceGrpcTransport, + "grpc", + grpc_helpers, + ), ( DatasetServiceAsyncClient, transports.DatasetServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_dataset_service_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -468,6 +585,7 @@ def test_dataset_service_client_client_options_credentials_file( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -487,14 +605,87 @@ def test_dataset_service_client_client_options_from_dict(): client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) -def test_create_dataset( - transport: str = "grpc", request_type=dataset_service.CreateDatasetRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + DatasetServiceClient, + transports.DatasetServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + DatasetServiceAsyncClient, + transports.DatasetServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_dataset_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers ): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + dataset_service.CreateDatasetRequest, + dict, + ], +) +def test_create_dataset(request_type, transport: str = "grpc"): client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -516,15 +707,12 @@ def test_create_dataset( assert isinstance(response, future.Future) -def test_create_dataset_from_dict(): - test_create_dataset(request_type=dict) - - def test_create_dataset_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -540,7 +728,8 @@ async def test_create_dataset_async( transport: str = "grpc_asyncio", request_type=dataset_service.CreateDatasetRequest ): client = DatasetServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -570,13 +759,15 @@ async def test_create_dataset_async_from_dict(): def test_create_dataset_field_headers(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = dataset_service.CreateDatasetRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_dataset), "__call__") as call: @@ -590,7 +781,10 @@ def test_create_dataset_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -603,7 +797,7 @@ async def test_create_dataset_field_headers_async(): # a field header. Set these to a non-empty value. request = dataset_service.CreateDatasetRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_dataset), "__call__") as call: @@ -619,11 +813,16 @@ async def test_create_dataset_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_create_dataset_flattened(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_dataset), "__call__") as call: @@ -632,19 +831,26 @@ def test_create_dataset_flattened(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.create_dataset( - parent="parent_value", dataset=gca_dataset.Dataset(name="name_value"), + parent="parent_value", + dataset=gca_dataset.Dataset(name="name_value"), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].dataset == gca_dataset.Dataset(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].dataset + mock_val = gca_dataset.Dataset(name="name_value") + assert arg == mock_val def test_create_dataset_flattened_error(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -673,15 +879,20 @@ async def test_create_dataset_flattened_async(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. response = await client.create_dataset( - parent="parent_value", dataset=gca_dataset.Dataset(name="name_value"), + parent="parent_value", + dataset=gca_dataset.Dataset(name="name_value"), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].dataset == gca_dataset.Dataset(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].dataset + mock_val = gca_dataset.Dataset(name="name_value") + assert arg == mock_val @pytest.mark.asyncio @@ -700,11 +911,17 @@ async def test_create_dataset_flattened_error_async(): ) -def test_get_dataset( - transport: str = "grpc", request_type=dataset_service.GetDatasetRequest -): +@pytest.mark.parametrize( + "request_type", + [ + dataset_service.GetDatasetRequest, + dict, + ], +) +def test_get_dataset(request_type, transport: str = "grpc"): client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -717,6 +934,7 @@ def test_get_dataset( call.return_value = dataset.Dataset( name="name_value", display_name="display_name_value", + description="description_value", metadata_schema_uri="metadata_schema_uri_value", etag="etag_value", ) @@ -731,19 +949,17 @@ def test_get_dataset( assert isinstance(response, dataset.Dataset) assert response.name == "name_value" assert response.display_name == "display_name_value" + assert response.description == "description_value" assert response.metadata_schema_uri == "metadata_schema_uri_value" assert response.etag == "etag_value" -def test_get_dataset_from_dict(): - test_get_dataset(request_type=dict) - - def test_get_dataset_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -759,7 +975,8 @@ async def test_get_dataset_async( transport: str = "grpc_asyncio", request_type=dataset_service.GetDatasetRequest ): client = DatasetServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -773,6 +990,7 @@ async def test_get_dataset_async( dataset.Dataset( name="name_value", display_name="display_name_value", + description="description_value", metadata_schema_uri="metadata_schema_uri_value", etag="etag_value", ) @@ -788,6 +1006,7 @@ async def test_get_dataset_async( assert isinstance(response, dataset.Dataset) assert response.name == "name_value" assert response.display_name == "display_name_value" + assert response.description == "description_value" assert response.metadata_schema_uri == "metadata_schema_uri_value" assert response.etag == "etag_value" @@ -798,13 +1017,15 @@ async def test_get_dataset_async_from_dict(): def test_get_dataset_field_headers(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = dataset_service.GetDatasetRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_dataset), "__call__") as call: @@ -818,7 +1039,10 @@ def test_get_dataset_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -831,7 +1055,7 @@ async def test_get_dataset_field_headers_async(): # a field header. Set these to a non-empty value. request = dataset_service.GetDatasetRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_dataset), "__call__") as call: @@ -845,11 +1069,16 @@ async def test_get_dataset_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_get_dataset_flattened(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_dataset), "__call__") as call: @@ -857,23 +1086,30 @@ def test_get_dataset_flattened(): call.return_value = dataset.Dataset() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_dataset(name="name_value",) + client.get_dataset( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_dataset_flattened_error(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.get_dataset( - dataset_service.GetDatasetRequest(), name="name_value", + dataset_service.GetDatasetRequest(), + name="name_value", ) @@ -891,13 +1127,17 @@ async def test_get_dataset_flattened_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(dataset.Dataset()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_dataset(name="name_value",) + response = await client.get_dataset( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -910,15 +1150,22 @@ async def test_get_dataset_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.get_dataset( - dataset_service.GetDatasetRequest(), name="name_value", + dataset_service.GetDatasetRequest(), + name="name_value", ) -def test_update_dataset( - transport: str = "grpc", request_type=dataset_service.UpdateDatasetRequest -): +@pytest.mark.parametrize( + "request_type", + [ + dataset_service.UpdateDatasetRequest, + dict, + ], +) +def test_update_dataset(request_type, transport: str = "grpc"): client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -931,6 +1178,7 @@ def test_update_dataset( call.return_value = gca_dataset.Dataset( name="name_value", display_name="display_name_value", + description="description_value", metadata_schema_uri="metadata_schema_uri_value", etag="etag_value", ) @@ -945,19 +1193,17 @@ def test_update_dataset( assert isinstance(response, gca_dataset.Dataset) assert response.name == "name_value" assert response.display_name == "display_name_value" + assert response.description == "description_value" assert response.metadata_schema_uri == "metadata_schema_uri_value" assert response.etag == "etag_value" -def test_update_dataset_from_dict(): - test_update_dataset(request_type=dict) - - def test_update_dataset_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -973,7 +1219,8 @@ async def test_update_dataset_async( transport: str = "grpc_asyncio", request_type=dataset_service.UpdateDatasetRequest ): client = DatasetServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -987,6 +1234,7 @@ async def test_update_dataset_async( gca_dataset.Dataset( name="name_value", display_name="display_name_value", + description="description_value", metadata_schema_uri="metadata_schema_uri_value", etag="etag_value", ) @@ -1002,6 +1250,7 @@ async def test_update_dataset_async( assert isinstance(response, gca_dataset.Dataset) assert response.name == "name_value" assert response.display_name == "display_name_value" + assert response.description == "description_value" assert response.metadata_schema_uri == "metadata_schema_uri_value" assert response.etag == "etag_value" @@ -1012,13 +1261,15 @@ async def test_update_dataset_async_from_dict(): def test_update_dataset_field_headers(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = dataset_service.UpdateDatasetRequest() - request.dataset.name = "dataset.name/value" + request.dataset.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_dataset), "__call__") as call: @@ -1032,9 +1283,10 @@ def test_update_dataset_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "dataset.name=dataset.name/value",) in kw[ - "metadata" - ] + assert ( + "x-goog-request-params", + "dataset.name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1047,7 +1299,7 @@ async def test_update_dataset_field_headers_async(): # a field header. Set these to a non-empty value. request = dataset_service.UpdateDatasetRequest() - request.dataset.name = "dataset.name/value" + request.dataset.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_dataset), "__call__") as call: @@ -1061,13 +1313,16 @@ async def test_update_dataset_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "dataset.name=dataset.name/value",) in kw[ - "metadata" - ] + assert ( + "x-goog-request-params", + "dataset.name=name_value", + ) in kw["metadata"] def test_update_dataset_flattened(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_dataset), "__call__") as call: @@ -1084,12 +1339,18 @@ def test_update_dataset_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].dataset == gca_dataset.Dataset(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].dataset + mock_val = gca_dataset.Dataset(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val def test_update_dataset_flattened_error(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1124,8 +1385,12 @@ async def test_update_dataset_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].dataset == gca_dataset.Dataset(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].dataset + mock_val = gca_dataset.Dataset(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val @pytest.mark.asyncio @@ -1144,11 +1409,17 @@ async def test_update_dataset_flattened_error_async(): ) -def test_list_datasets( - transport: str = "grpc", request_type=dataset_service.ListDatasetsRequest -): +@pytest.mark.parametrize( + "request_type", + [ + dataset_service.ListDatasetsRequest, + dict, + ], +) +def test_list_datasets(request_type, transport: str = "grpc"): client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1173,15 +1444,12 @@ def test_list_datasets( assert response.next_page_token == "next_page_token_value" -def test_list_datasets_from_dict(): - test_list_datasets(request_type=dict) - - def test_list_datasets_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1197,7 +1465,8 @@ async def test_list_datasets_async( transport: str = "grpc_asyncio", request_type=dataset_service.ListDatasetsRequest ): client = DatasetServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1230,13 +1499,15 @@ async def test_list_datasets_async_from_dict(): def test_list_datasets_field_headers(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = dataset_service.ListDatasetsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_datasets), "__call__") as call: @@ -1250,7 +1521,10 @@ def test_list_datasets_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1263,7 +1537,7 @@ async def test_list_datasets_field_headers_async(): # a field header. Set these to a non-empty value. request = dataset_service.ListDatasetsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_datasets), "__call__") as call: @@ -1279,11 +1553,16 @@ async def test_list_datasets_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_datasets_flattened(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_datasets), "__call__") as call: @@ -1291,23 +1570,30 @@ def test_list_datasets_flattened(): call.return_value = dataset_service.ListDatasetsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_datasets(parent="parent_value",) + client.list_datasets( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_datasets_flattened_error(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.list_datasets( - dataset_service.ListDatasetsRequest(), parent="parent_value", + dataset_service.ListDatasetsRequest(), + parent="parent_value", ) @@ -1327,13 +1613,17 @@ async def test_list_datasets_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_datasets(parent="parent_value",) + response = await client.list_datasets( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1346,27 +1636,44 @@ async def test_list_datasets_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.list_datasets( - dataset_service.ListDatasetsRequest(), parent="parent_value", + dataset_service.ListDatasetsRequest(), + parent="parent_value", ) -def test_list_datasets_pager(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_datasets_pager(transport_name: str = "grpc"): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_datasets), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( dataset_service.ListDatasetsResponse( - datasets=[dataset.Dataset(), dataset.Dataset(), dataset.Dataset(),], + datasets=[ + dataset.Dataset(), + dataset.Dataset(), + dataset.Dataset(), + ], next_page_token="abc", ), - dataset_service.ListDatasetsResponse(datasets=[], next_page_token="def",), dataset_service.ListDatasetsResponse( - datasets=[dataset.Dataset(),], next_page_token="ghi", + datasets=[], + next_page_token="def", + ), + dataset_service.ListDatasetsResponse( + datasets=[ + dataset.Dataset(), + ], + next_page_token="ghi", ), dataset_service.ListDatasetsResponse( - datasets=[dataset.Dataset(), dataset.Dataset(),], + datasets=[ + dataset.Dataset(), + dataset.Dataset(), + ], ), RuntimeError, ) @@ -1379,28 +1686,44 @@ def test_list_datasets_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all(isinstance(i, dataset.Dataset) for i in results) -def test_list_datasets_pages(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_datasets_pages(transport_name: str = "grpc"): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_datasets), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( dataset_service.ListDatasetsResponse( - datasets=[dataset.Dataset(), dataset.Dataset(), dataset.Dataset(),], + datasets=[ + dataset.Dataset(), + dataset.Dataset(), + dataset.Dataset(), + ], next_page_token="abc", ), - dataset_service.ListDatasetsResponse(datasets=[], next_page_token="def",), dataset_service.ListDatasetsResponse( - datasets=[dataset.Dataset(),], next_page_token="ghi", + datasets=[], + next_page_token="def", ), dataset_service.ListDatasetsResponse( - datasets=[dataset.Dataset(), dataset.Dataset(),], + datasets=[ + dataset.Dataset(), + ], + next_page_token="ghi", + ), + dataset_service.ListDatasetsResponse( + datasets=[ + dataset.Dataset(), + dataset.Dataset(), + ], ), RuntimeError, ) @@ -1411,7 +1734,9 @@ def test_list_datasets_pages(): @pytest.mark.asyncio async def test_list_datasets_async_pager(): - client = DatasetServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1420,22 +1745,37 @@ async def test_list_datasets_async_pager(): # Set the response to a series of pages. call.side_effect = ( dataset_service.ListDatasetsResponse( - datasets=[dataset.Dataset(), dataset.Dataset(), dataset.Dataset(),], + datasets=[ + dataset.Dataset(), + dataset.Dataset(), + dataset.Dataset(), + ], next_page_token="abc", ), - dataset_service.ListDatasetsResponse(datasets=[], next_page_token="def",), dataset_service.ListDatasetsResponse( - datasets=[dataset.Dataset(),], next_page_token="ghi", + datasets=[], + next_page_token="def", + ), + dataset_service.ListDatasetsResponse( + datasets=[ + dataset.Dataset(), + ], + next_page_token="ghi", ), dataset_service.ListDatasetsResponse( - datasets=[dataset.Dataset(), dataset.Dataset(),], + datasets=[ + dataset.Dataset(), + dataset.Dataset(), + ], ), RuntimeError, ) - async_pager = await client.list_datasets(request={},) + async_pager = await client.list_datasets( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -1444,7 +1784,9 @@ async def test_list_datasets_async_pager(): @pytest.mark.asyncio async def test_list_datasets_async_pages(): - client = DatasetServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1453,30 +1795,51 @@ async def test_list_datasets_async_pages(): # Set the response to a series of pages. call.side_effect = ( dataset_service.ListDatasetsResponse( - datasets=[dataset.Dataset(), dataset.Dataset(), dataset.Dataset(),], + datasets=[ + dataset.Dataset(), + dataset.Dataset(), + dataset.Dataset(), + ], next_page_token="abc", ), - dataset_service.ListDatasetsResponse(datasets=[], next_page_token="def",), dataset_service.ListDatasetsResponse( - datasets=[dataset.Dataset(),], next_page_token="ghi", + datasets=[], + next_page_token="def", + ), + dataset_service.ListDatasetsResponse( + datasets=[ + dataset.Dataset(), + ], + next_page_token="ghi", ), dataset_service.ListDatasetsResponse( - datasets=[dataset.Dataset(), dataset.Dataset(),], + datasets=[ + dataset.Dataset(), + dataset.Dataset(), + ], ), RuntimeError, ) pages = [] - async for page_ in (await client.list_datasets(request={})).pages: + async for page_ in ( + await client.list_datasets(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_delete_dataset( - transport: str = "grpc", request_type=dataset_service.DeleteDatasetRequest -): +@pytest.mark.parametrize( + "request_type", + [ + dataset_service.DeleteDatasetRequest, + dict, + ], +) +def test_delete_dataset(request_type, transport: str = "grpc"): client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1498,15 +1861,12 @@ def test_delete_dataset( assert isinstance(response, future.Future) -def test_delete_dataset_from_dict(): - test_delete_dataset(request_type=dict) - - def test_delete_dataset_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1522,7 +1882,8 @@ async def test_delete_dataset_async( transport: str = "grpc_asyncio", request_type=dataset_service.DeleteDatasetRequest ): client = DatasetServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1552,13 +1913,15 @@ async def test_delete_dataset_async_from_dict(): def test_delete_dataset_field_headers(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = dataset_service.DeleteDatasetRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_dataset), "__call__") as call: @@ -1572,7 +1935,10 @@ def test_delete_dataset_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1585,7 +1951,7 @@ async def test_delete_dataset_field_headers_async(): # a field header. Set these to a non-empty value. request = dataset_service.DeleteDatasetRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_dataset), "__call__") as call: @@ -1601,11 +1967,16 @@ async def test_delete_dataset_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_delete_dataset_flattened(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_dataset), "__call__") as call: @@ -1613,23 +1984,30 @@ def test_delete_dataset_flattened(): call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_dataset(name="name_value",) + client.delete_dataset( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_delete_dataset_flattened_error(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.delete_dataset( - dataset_service.DeleteDatasetRequest(), name="name_value", + dataset_service.DeleteDatasetRequest(), + name="name_value", ) @@ -1649,13 +2027,17 @@ async def test_delete_dataset_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_dataset(name="name_value",) + response = await client.delete_dataset( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1668,15 +2050,22 @@ async def test_delete_dataset_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.delete_dataset( - dataset_service.DeleteDatasetRequest(), name="name_value", + dataset_service.DeleteDatasetRequest(), + name="name_value", ) -def test_import_data( - transport: str = "grpc", request_type=dataset_service.ImportDataRequest -): +@pytest.mark.parametrize( + "request_type", + [ + dataset_service.ImportDataRequest, + dict, + ], +) +def test_import_data(request_type, transport: str = "grpc"): client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1698,15 +2087,12 @@ def test_import_data( assert isinstance(response, future.Future) -def test_import_data_from_dict(): - test_import_data(request_type=dict) - - def test_import_data_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1722,7 +2108,8 @@ async def test_import_data_async( transport: str = "grpc_asyncio", request_type=dataset_service.ImportDataRequest ): client = DatasetServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1752,13 +2139,15 @@ async def test_import_data_async_from_dict(): def test_import_data_field_headers(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = dataset_service.ImportDataRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.import_data), "__call__") as call: @@ -1772,7 +2161,10 @@ def test_import_data_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1785,7 +2177,7 @@ async def test_import_data_field_headers_async(): # a field header. Set these to a non-empty value. request = dataset_service.ImportDataRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.import_data), "__call__") as call: @@ -1801,11 +2193,16 @@ async def test_import_data_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_import_data_flattened(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.import_data), "__call__") as call: @@ -1824,14 +2221,20 @@ def test_import_data_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].import_configs == [ + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].import_configs + mock_val = [ dataset.ImportDataConfig(gcs_source=io.GcsSource(uris=["uris_value"])) ] + assert arg == mock_val def test_import_data_flattened_error(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1872,10 +2275,14 @@ async def test_import_data_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].import_configs == [ + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].import_configs + mock_val = [ dataset.ImportDataConfig(gcs_source=io.GcsSource(uris=["uris_value"])) ] + assert arg == mock_val @pytest.mark.asyncio @@ -1896,11 +2303,17 @@ async def test_import_data_flattened_error_async(): ) -def test_export_data( - transport: str = "grpc", request_type=dataset_service.ExportDataRequest -): +@pytest.mark.parametrize( + "request_type", + [ + dataset_service.ExportDataRequest, + dict, + ], +) +def test_export_data(request_type, transport: str = "grpc"): client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1922,15 +2335,12 @@ def test_export_data( assert isinstance(response, future.Future) -def test_export_data_from_dict(): - test_export_data(request_type=dict) - - def test_export_data_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1946,7 +2356,8 @@ async def test_export_data_async( transport: str = "grpc_asyncio", request_type=dataset_service.ExportDataRequest ): client = DatasetServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1976,13 +2387,15 @@ async def test_export_data_async_from_dict(): def test_export_data_field_headers(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = dataset_service.ExportDataRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.export_data), "__call__") as call: @@ -1996,7 +2409,10 @@ def test_export_data_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2009,7 +2425,7 @@ async def test_export_data_field_headers_async(): # a field header. Set these to a non-empty value. request = dataset_service.ExportDataRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.export_data), "__call__") as call: @@ -2025,11 +2441,16 @@ async def test_export_data_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_export_data_flattened(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.export_data), "__call__") as call: @@ -2050,16 +2471,22 @@ def test_export_data_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].export_config == dataset.ExportDataConfig( + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].export_config + mock_val = dataset.ExportDataConfig( gcs_destination=io.GcsDestination( output_uri_prefix="output_uri_prefix_value" ) ) + assert arg == mock_val def test_export_data_flattened_error(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2104,12 +2531,16 @@ async def test_export_data_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].export_config == dataset.ExportDataConfig( + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].export_config + mock_val = dataset.ExportDataConfig( gcs_destination=io.GcsDestination( output_uri_prefix="output_uri_prefix_value" ) ) + assert arg == mock_val @pytest.mark.asyncio @@ -2132,11 +2563,17 @@ async def test_export_data_flattened_error_async(): ) -def test_list_data_items( - transport: str = "grpc", request_type=dataset_service.ListDataItemsRequest -): +@pytest.mark.parametrize( + "request_type", + [ + dataset_service.ListDataItemsRequest, + dict, + ], +) +def test_list_data_items(request_type, transport: str = "grpc"): client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2161,15 +2598,12 @@ def test_list_data_items( assert response.next_page_token == "next_page_token_value" -def test_list_data_items_from_dict(): - test_list_data_items(request_type=dict) - - def test_list_data_items_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2185,7 +2619,8 @@ async def test_list_data_items_async( transport: str = "grpc_asyncio", request_type=dataset_service.ListDataItemsRequest ): client = DatasetServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2218,13 +2653,15 @@ async def test_list_data_items_async_from_dict(): def test_list_data_items_field_headers(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = dataset_service.ListDataItemsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_data_items), "__call__") as call: @@ -2238,7 +2675,10 @@ def test_list_data_items_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2251,7 +2691,7 @@ async def test_list_data_items_field_headers_async(): # a field header. Set these to a non-empty value. request = dataset_service.ListDataItemsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_data_items), "__call__") as call: @@ -2267,11 +2707,16 @@ async def test_list_data_items_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_data_items_flattened(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_data_items), "__call__") as call: @@ -2279,23 +2724,30 @@ def test_list_data_items_flattened(): call.return_value = dataset_service.ListDataItemsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_data_items(parent="parent_value",) + client.list_data_items( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_data_items_flattened_error(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.list_data_items( - dataset_service.ListDataItemsRequest(), parent="parent_value", + dataset_service.ListDataItemsRequest(), + parent="parent_value", ) @@ -2315,13 +2767,17 @@ async def test_list_data_items_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_data_items(parent="parent_value",) + response = await client.list_data_items( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -2334,12 +2790,16 @@ async def test_list_data_items_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.list_data_items( - dataset_service.ListDataItemsRequest(), parent="parent_value", + dataset_service.ListDataItemsRequest(), + parent="parent_value", ) -def test_list_data_items_pager(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_data_items_pager(transport_name: str = "grpc"): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_data_items), "__call__") as call: @@ -2354,13 +2814,20 @@ def test_list_data_items_pager(): next_page_token="abc", ), dataset_service.ListDataItemsResponse( - data_items=[], next_page_token="def", + data_items=[], + next_page_token="def", ), dataset_service.ListDataItemsResponse( - data_items=[data_item.DataItem(),], next_page_token="ghi", + data_items=[ + data_item.DataItem(), + ], + next_page_token="ghi", ), dataset_service.ListDataItemsResponse( - data_items=[data_item.DataItem(), data_item.DataItem(),], + data_items=[ + data_item.DataItem(), + data_item.DataItem(), + ], ), RuntimeError, ) @@ -2373,13 +2840,16 @@ def test_list_data_items_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all(isinstance(i, data_item.DataItem) for i in results) -def test_list_data_items_pages(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_data_items_pages(transport_name: str = "grpc"): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_data_items), "__call__") as call: @@ -2394,13 +2864,20 @@ def test_list_data_items_pages(): next_page_token="abc", ), dataset_service.ListDataItemsResponse( - data_items=[], next_page_token="def", + data_items=[], + next_page_token="def", ), dataset_service.ListDataItemsResponse( - data_items=[data_item.DataItem(),], next_page_token="ghi", + data_items=[ + data_item.DataItem(), + ], + next_page_token="ghi", ), dataset_service.ListDataItemsResponse( - data_items=[data_item.DataItem(), data_item.DataItem(),], + data_items=[ + data_item.DataItem(), + data_item.DataItem(), + ], ), RuntimeError, ) @@ -2411,7 +2888,9 @@ def test_list_data_items_pages(): @pytest.mark.asyncio async def test_list_data_items_async_pager(): - client = DatasetServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2428,20 +2907,29 @@ async def test_list_data_items_async_pager(): next_page_token="abc", ), dataset_service.ListDataItemsResponse( - data_items=[], next_page_token="def", + data_items=[], + next_page_token="def", ), dataset_service.ListDataItemsResponse( - data_items=[data_item.DataItem(),], next_page_token="ghi", + data_items=[ + data_item.DataItem(), + ], + next_page_token="ghi", ), dataset_service.ListDataItemsResponse( - data_items=[data_item.DataItem(), data_item.DataItem(),], + data_items=[ + data_item.DataItem(), + data_item.DataItem(), + ], ), RuntimeError, ) - async_pager = await client.list_data_items(request={},) + async_pager = await client.list_data_items( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -2450,7 +2938,9 @@ async def test_list_data_items_async_pager(): @pytest.mark.asyncio async def test_list_data_items_async_pages(): - client = DatasetServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2467,28 +2957,43 @@ async def test_list_data_items_async_pages(): next_page_token="abc", ), dataset_service.ListDataItemsResponse( - data_items=[], next_page_token="def", + data_items=[], + next_page_token="def", ), dataset_service.ListDataItemsResponse( - data_items=[data_item.DataItem(),], next_page_token="ghi", + data_items=[ + data_item.DataItem(), + ], + next_page_token="ghi", ), dataset_service.ListDataItemsResponse( - data_items=[data_item.DataItem(), data_item.DataItem(),], + data_items=[ + data_item.DataItem(), + data_item.DataItem(), + ], ), RuntimeError, ) pages = [] - async for page_ in (await client.list_data_items(request={})).pages: + async for page_ in ( + await client.list_data_items(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_get_annotation_spec( - transport: str = "grpc", request_type=dataset_service.GetAnnotationSpecRequest -): +@pytest.mark.parametrize( + "request_type", + [ + dataset_service.GetAnnotationSpecRequest, + dict, + ], +) +def test_get_annotation_spec(request_type, transport: str = "grpc"): client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2501,7 +3006,9 @@ def test_get_annotation_spec( ) as call: # Designate an appropriate return value for the call. call.return_value = annotation_spec.AnnotationSpec( - name="name_value", display_name="display_name_value", etag="etag_value", + name="name_value", + display_name="display_name_value", + etag="etag_value", ) response = client.get_annotation_spec(request) @@ -2517,15 +3024,12 @@ def test_get_annotation_spec( assert response.etag == "etag_value" -def test_get_annotation_spec_from_dict(): - test_get_annotation_spec(request_type=dict) - - def test_get_annotation_spec_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2544,7 +3048,8 @@ async def test_get_annotation_spec_async( request_type=dataset_service.GetAnnotationSpecRequest, ): client = DatasetServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2558,7 +3063,9 @@ async def test_get_annotation_spec_async( # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( annotation_spec.AnnotationSpec( - name="name_value", display_name="display_name_value", etag="etag_value", + name="name_value", + display_name="display_name_value", + etag="etag_value", ) ) response = await client.get_annotation_spec(request) @@ -2581,13 +3088,15 @@ async def test_get_annotation_spec_async_from_dict(): def test_get_annotation_spec_field_headers(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = dataset_service.GetAnnotationSpecRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2603,7 +3112,10 @@ def test_get_annotation_spec_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2616,7 +3128,7 @@ async def test_get_annotation_spec_field_headers_async(): # a field header. Set these to a non-empty value. request = dataset_service.GetAnnotationSpecRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2634,11 +3146,16 @@ async def test_get_annotation_spec_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_get_annotation_spec_flattened(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2648,23 +3165,30 @@ def test_get_annotation_spec_flattened(): call.return_value = annotation_spec.AnnotationSpec() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_annotation_spec(name="name_value",) + client.get_annotation_spec( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_annotation_spec_flattened_error(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.get_annotation_spec( - dataset_service.GetAnnotationSpecRequest(), name="name_value", + dataset_service.GetAnnotationSpecRequest(), + name="name_value", ) @@ -2686,13 +3210,17 @@ async def test_get_annotation_spec_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_annotation_spec(name="name_value",) + response = await client.get_annotation_spec( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -2705,15 +3233,22 @@ async def test_get_annotation_spec_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.get_annotation_spec( - dataset_service.GetAnnotationSpecRequest(), name="name_value", + dataset_service.GetAnnotationSpecRequest(), + name="name_value", ) -def test_list_annotations( - transport: str = "grpc", request_type=dataset_service.ListAnnotationsRequest -): +@pytest.mark.parametrize( + "request_type", + [ + dataset_service.ListAnnotationsRequest, + dict, + ], +) +def test_list_annotations(request_type, transport: str = "grpc"): client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2738,15 +3273,12 @@ def test_list_annotations( assert response.next_page_token == "next_page_token_value" -def test_list_annotations_from_dict(): - test_list_annotations(request_type=dict) - - def test_list_annotations_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2762,7 +3294,8 @@ async def test_list_annotations_async( transport: str = "grpc_asyncio", request_type=dataset_service.ListAnnotationsRequest ): client = DatasetServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2795,13 +3328,15 @@ async def test_list_annotations_async_from_dict(): def test_list_annotations_field_headers(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = dataset_service.ListAnnotationsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_annotations), "__call__") as call: @@ -2815,7 +3350,10 @@ def test_list_annotations_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2828,7 +3366,7 @@ async def test_list_annotations_field_headers_async(): # a field header. Set these to a non-empty value. request = dataset_service.ListAnnotationsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_annotations), "__call__") as call: @@ -2844,11 +3382,16 @@ async def test_list_annotations_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_annotations_flattened(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_annotations), "__call__") as call: @@ -2856,23 +3399,30 @@ def test_list_annotations_flattened(): call.return_value = dataset_service.ListAnnotationsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_annotations(parent="parent_value",) + client.list_annotations( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_annotations_flattened_error(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.list_annotations( - dataset_service.ListAnnotationsRequest(), parent="parent_value", + dataset_service.ListAnnotationsRequest(), + parent="parent_value", ) @@ -2892,13 +3442,17 @@ async def test_list_annotations_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_annotations(parent="parent_value",) + response = await client.list_annotations( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -2911,12 +3465,16 @@ async def test_list_annotations_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.list_annotations( - dataset_service.ListAnnotationsRequest(), parent="parent_value", + dataset_service.ListAnnotationsRequest(), + parent="parent_value", ) -def test_list_annotations_pager(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_annotations_pager(transport_name: str = "grpc"): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_annotations), "__call__") as call: @@ -2931,13 +3489,20 @@ def test_list_annotations_pager(): next_page_token="abc", ), dataset_service.ListAnnotationsResponse( - annotations=[], next_page_token="def", + annotations=[], + next_page_token="def", ), dataset_service.ListAnnotationsResponse( - annotations=[annotation.Annotation(),], next_page_token="ghi", + annotations=[ + annotation.Annotation(), + ], + next_page_token="ghi", ), dataset_service.ListAnnotationsResponse( - annotations=[annotation.Annotation(), annotation.Annotation(),], + annotations=[ + annotation.Annotation(), + annotation.Annotation(), + ], ), RuntimeError, ) @@ -2950,13 +3515,16 @@ def test_list_annotations_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all(isinstance(i, annotation.Annotation) for i in results) -def test_list_annotations_pages(): - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_annotations_pages(transport_name: str = "grpc"): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_annotations), "__call__") as call: @@ -2971,13 +3539,20 @@ def test_list_annotations_pages(): next_page_token="abc", ), dataset_service.ListAnnotationsResponse( - annotations=[], next_page_token="def", + annotations=[], + next_page_token="def", ), dataset_service.ListAnnotationsResponse( - annotations=[annotation.Annotation(),], next_page_token="ghi", + annotations=[ + annotation.Annotation(), + ], + next_page_token="ghi", ), dataset_service.ListAnnotationsResponse( - annotations=[annotation.Annotation(), annotation.Annotation(),], + annotations=[ + annotation.Annotation(), + annotation.Annotation(), + ], ), RuntimeError, ) @@ -2988,7 +3563,9 @@ def test_list_annotations_pages(): @pytest.mark.asyncio async def test_list_annotations_async_pager(): - client = DatasetServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3005,20 +3582,29 @@ async def test_list_annotations_async_pager(): next_page_token="abc", ), dataset_service.ListAnnotationsResponse( - annotations=[], next_page_token="def", + annotations=[], + next_page_token="def", ), dataset_service.ListAnnotationsResponse( - annotations=[annotation.Annotation(),], next_page_token="ghi", + annotations=[ + annotation.Annotation(), + ], + next_page_token="ghi", ), dataset_service.ListAnnotationsResponse( - annotations=[annotation.Annotation(), annotation.Annotation(),], + annotations=[ + annotation.Annotation(), + annotation.Annotation(), + ], ), RuntimeError, ) - async_pager = await client.list_annotations(request={},) + async_pager = await client.list_annotations( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -3027,7 +3613,9 @@ async def test_list_annotations_async_pager(): @pytest.mark.asyncio async def test_list_annotations_async_pages(): - client = DatasetServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3044,18 +3632,27 @@ async def test_list_annotations_async_pages(): next_page_token="abc", ), dataset_service.ListAnnotationsResponse( - annotations=[], next_page_token="def", + annotations=[], + next_page_token="def", ), dataset_service.ListAnnotationsResponse( - annotations=[annotation.Annotation(),], next_page_token="ghi", + annotations=[ + annotation.Annotation(), + ], + next_page_token="ghi", ), dataset_service.ListAnnotationsResponse( - annotations=[annotation.Annotation(), annotation.Annotation(),], + annotations=[ + annotation.Annotation(), + annotation.Annotation(), + ], ), RuntimeError, ) pages = [] - async for page_ in (await client.list_annotations(request={})).pages: + async for page_ in ( + await client.list_annotations(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token @@ -3068,7 +3665,8 @@ def test_credentials_transport_error(): ) with pytest.raises(ValueError): client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # It is an error to provide a credentials file and a transport instance. @@ -3081,13 +3679,34 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.DatasetServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = DatasetServiceClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = DatasetServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.DatasetServiceGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = DatasetServiceClient( - client_options={"scopes": ["1", "2"]}, transport=transport, + client_options={"scopes": ["1", "2"]}, + transport=transport, ) @@ -3130,10 +3749,28 @@ def test_transport_adc(transport_class): adc.assert_called_once() +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = DatasetServiceClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + def test_transport_grpc_default(): # A client should use the gRPC transport by default. - client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials(),) - assert isinstance(client.transport, transports.DatasetServiceGrpcTransport,) + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.DatasetServiceGrpcTransport, + ) def test_dataset_service_base_transport_error(): @@ -3168,18 +3805,38 @@ def test_dataset_service_base_transport(): "list_data_items", "get_annotation_spec", "list_annotations", + "set_iam_policy", + "get_iam_policy", + "test_iam_permissions", + "get_location", + "list_locations", + "get_operation", + "wait_operation", + "cancel_operation", + "delete_operation", + "list_operations", ) for method in methods: with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + # Additionally, the LRO client (a property) should # also raise NotImplementedError with pytest.raises(NotImplementedError): transport.operations_client + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + -@requires_google_auth_gte_1_25_0 def test_dataset_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -3190,7 +3847,8 @@ def test_dataset_service_base_transport_with_credentials_file(): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.DatasetServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", + credentials_file="credentials.json", + quota_project_id="octopus", ) load_creds.assert_called_once_with( "credentials.json", @@ -3200,26 +3858,6 @@ def test_dataset_service_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_dataset_service_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.aiplatform_v1beta1.services.dataset_service.transports.DatasetServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.DatasetServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - def test_dataset_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( @@ -3231,7 +3869,6 @@ def test_dataset_service_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_dataset_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -3244,18 +3881,6 @@ def test_dataset_service_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_dataset_service_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - DatasetServiceClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -3263,7 +3888,6 @@ def test_dataset_service_auth_adc_old_google_auth(): transports.DatasetServiceGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_dataset_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -3277,26 +3901,6 @@ def test_dataset_service_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.DatasetServiceGrpcTransport, - transports.DatasetServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_dataset_service_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ @@ -3304,7 +3908,6 @@ def test_dataset_service_transport_auth_adc_old_google_auth(transport_class): (transports.DatasetServiceGrpcAsyncIOTransport, grpc_helpers_async), ], ) -@requires_api_core_gte_1_26_0 def test_dataset_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -3333,79 +3936,6 @@ def test_dataset_service_transport_create_channel(transport_class, grpc_helpers) ) -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.DatasetServiceGrpcTransport, grpc_helpers), - (transports.DatasetServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_dataset_service_transport_create_channel_old_api_core( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class(quota_project_id="octopus") - - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.DatasetServiceGrpcTransport, grpc_helpers), - (transports.DatasetServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_dataset_service_transport_create_channel_user_scopes( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=["1", "2"], - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -3428,7 +3958,7 @@ def test_dataset_service_grpc_transport_client_cert_source_for_mtls(transport_cl "squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_channel_creds, quota_project_id=None, options=[ @@ -3451,24 +3981,40 @@ def test_dataset_service_grpc_transport_client_cert_source_for_mtls(transport_cl ) -def test_dataset_service_host_no_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_dataset_service_host_no_port(transport_name): client = DatasetServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="aiplatform.googleapis.com" ), + transport=transport_name, ) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") -def test_dataset_service_host_with_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_dataset_service_host_with_port(transport_name): client = DatasetServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="aiplatform.googleapis.com:8000" ), + transport=transport_name, ) - assert client.transport._host == "aiplatform.googleapis.com:8000" + assert client.transport._host == ("aiplatform.googleapis.com:8000") def test_dataset_service_grpc_transport_channel(): @@ -3476,7 +4022,8 @@ def test_dataset_service_grpc_transport_channel(): # Check that channel is used if provided. transport = transports.DatasetServiceGrpcTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -3488,7 +4035,8 @@ def test_dataset_service_grpc_asyncio_transport_channel(): # Check that channel is used if provided. transport = transports.DatasetServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -3537,7 +4085,7 @@ def test_dataset_service_transport_channel_mtls_with_client_cert_source( "mtls.squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -3584,7 +4132,7 @@ def test_dataset_service_transport_channel_mtls_with_adc(transport_class): "mtls.squid.clam.whelk:443", credentials=mock_cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -3597,12 +4145,16 @@ def test_dataset_service_transport_channel_mtls_with_adc(transport_class): def test_dataset_service_grpc_lro_client(): client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -3610,12 +4162,16 @@ def test_dataset_service_grpc_lro_client(): def test_dataset_service_grpc_lro_async_client(): client = DatasetServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -3692,7 +4248,10 @@ def test_data_item_path(): dataset = "winkle" data_item = "nautilus" expected = "projects/{project}/locations/{location}/datasets/{dataset}/dataItems/{data_item}".format( - project=project, location=location, dataset=dataset, data_item=data_item, + project=project, + location=location, + dataset=dataset, + data_item=data_item, ) actual = DatasetServiceClient.data_item_path(project, location, dataset, data_item) assert expected == actual @@ -3717,7 +4276,9 @@ def test_dataset_path(): location = "octopus" dataset = "oyster" expected = "projects/{project}/locations/{location}/datasets/{dataset}".format( - project=project, location=location, dataset=dataset, + project=project, + location=location, + dataset=dataset, ) actual = DatasetServiceClient.dataset_path(project, location, dataset) assert expected == actual @@ -3758,7 +4319,9 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "scallop" - expected = "folders/{folder}".format(folder=folder,) + expected = "folders/{folder}".format( + folder=folder, + ) actual = DatasetServiceClient.common_folder_path(folder) assert expected == actual @@ -3776,7 +4339,9 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "squid" - expected = "organizations/{organization}".format(organization=organization,) + expected = "organizations/{organization}".format( + organization=organization, + ) actual = DatasetServiceClient.common_organization_path(organization) assert expected == actual @@ -3794,7 +4359,9 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "whelk" - expected = "projects/{project}".format(project=project,) + expected = "projects/{project}".format( + project=project, + ) actual = DatasetServiceClient.common_project_path(project) assert expected == actual @@ -3814,7 +4381,8 @@ def test_common_location_path(): project = "oyster" location = "nudibranch" expected = "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) actual = DatasetServiceClient.common_location_path(project, location) assert expected == actual @@ -3832,14 +4400,15 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( transports.DatasetServiceTransport, "_prep_wrapped_messages" ) as prep: client = DatasetServiceClient( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -3848,6 +4417,1593 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = DatasetServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_delete_operation(transport: str = "grpc"): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_operation(transport: str = "grpc"): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_operation_field_headers(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = None + + client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_operation_field_headers_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_delete_operation_from_dict(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_delete_operation_from_dict_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_cancel_operation(transport: str = "grpc"): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation(transport: str = "grpc"): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_wait_operation(transport: str = "grpc"): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_wait_operation(transport: str = "grpc"): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_wait_operation_field_headers(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_wait_operation_field_headers_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_wait_operation_from_dict(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_wait_operation_from_dict_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_operation(transport: str = "grpc"): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_get_operation(transport: str = "grpc"): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_get_operation_field_headers(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_get_operation_from_dict(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_operations(transport: str = "grpc"): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + response = client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +@pytest.mark.asyncio +async def test_list_operations(transport: str = "grpc"): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +def test_list_operations_field_headers(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_operations_field_headers_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_operations_from_dict(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + response = client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_operations_from_dict_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_locations(transport: str = "grpc"): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + response = client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +@pytest.mark.asyncio +async def test_list_locations(transport: str = "grpc"): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +def test_list_locations_field_headers(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_locations_field_headers_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_locations_from_dict(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + response = client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_locations_from_dict_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_location(transport: str = "grpc"): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + response = client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +@pytest.mark.asyncio +async def test_get_location_async(transport: str = "grpc_asyncio"): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +def test_get_location_field_headers(): + client = DatasetServiceClient(credentials=ga_credentials.AnonymousCredentials()) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = locations_pb2.Location() + + client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_location_field_headers_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials() + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +def test_get_location_from_dict(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + response = client.get_location( + request={ + "name": "locations/abc", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_location_from_dict_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_set_iam_policy(transport: str = "grpc"): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + response = client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + response = await client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_set_iam_policy_field_headers(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_set_iam_policy_field_headers_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_set_iam_policy_from_dict(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_set_iam_policy_from_dict_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +def test_get_iam_policy(transport: str = "grpc"): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + + response = client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + + response = await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_get_iam_policy_field_headers(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_iam_policy_field_headers_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_get_iam_policy_from_dict(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_iam_policy_from_dict_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +def test_test_iam_permissions(transport: str = "grpc"): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + + response = client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + ) + + response = await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +def test_test_iam_permissions_field_headers(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_field_headers_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_test_iam_permissions_from_dict(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + response = client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_from_dict_async(): + client = DatasetServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + response = await client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = DatasetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (DatasetServiceClient, transports.DatasetServiceGrpcTransport), + (DatasetServiceAsyncClient, transports.DatasetServiceGrpcAsyncIOTransport), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) diff --git a/tests/unit/gapic/aiplatform_v1beta1/test_endpoint_service.py b/tests/unit/gapic/aiplatform_v1beta1/test_endpoint_service.py index de53fedc34..7558b38ce0 100644 --- a/tests/unit/gapic/aiplatform_v1beta1/test_endpoint_service.py +++ b/tests/unit/gapic/aiplatform_v1beta1/test_endpoint_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,8 +14,13 @@ # limitations under the License. # import os -import mock -import packaging.version + +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock +except ImportError: + import mock import grpc from grpc.experimental import aio @@ -30,8 +35,10 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.aiplatform_v1beta1.services.endpoint_service import ( @@ -42,12 +49,6 @@ ) from google.cloud.aiplatform_v1beta1.services.endpoint_service import pagers from google.cloud.aiplatform_v1beta1.services.endpoint_service import transports -from google.cloud.aiplatform_v1beta1.services.endpoint_service.transports.base import ( - _API_CORE_VERSION, -) -from google.cloud.aiplatform_v1beta1.services.endpoint_service.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.aiplatform_v1beta1.types import accelerator_type from google.cloud.aiplatform_v1beta1.types import encryption_spec from google.cloud.aiplatform_v1beta1.types import endpoint @@ -55,8 +56,13 @@ from google.cloud.aiplatform_v1beta1.types import endpoint_service from google.cloud.aiplatform_v1beta1.types import explanation from google.cloud.aiplatform_v1beta1.types import explanation_metadata +from google.cloud.aiplatform_v1beta1.types import io from google.cloud.aiplatform_v1beta1.types import machine_resources from google.cloud.aiplatform_v1beta1.types import operation as gca_operation +from google.cloud.location import locations_pb2 +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 from google.oauth2 import service_account from google.protobuf import field_mask_pb2 # type: ignore @@ -65,29 +71,6 @@ import google.auth -# TODO(busunkim): Once google-api-core >= 1.26.0 is required: -# - Delete all the api-core and auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - -requires_api_core_lt_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), - reason="This test requires google-api-core < 1.26.0", -) - -requires_api_core_gte_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), - reason="This test requires google-api-core >= 1.26.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -133,40 +116,81 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( - "client_class", [EndpointServiceClient, EndpointServiceAsyncClient,] + "client_class,transport_name", + [ + (EndpointServiceClient, "grpc"), + (EndpointServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_endpoint_service_client_from_service_account_info(client_class): +def test_endpoint_service_client_from_service_account_info( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.EndpointServiceGrpcTransport, "grpc"), + (transports.EndpointServiceGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_endpoint_service_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() @pytest.mark.parametrize( - "client_class", [EndpointServiceClient, EndpointServiceAsyncClient,] + "client_class,transport_name", + [ + (EndpointServiceClient, "grpc"), + (EndpointServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_endpoint_service_client_from_service_account_file(client_class): +def test_endpoint_service_client_from_service_account_file( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") def test_endpoint_service_client_get_transport_class(): @@ -219,7 +243,7 @@ def test_endpoint_service_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -228,6 +252,7 @@ def test_endpoint_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -235,7 +260,7 @@ def test_endpoint_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -244,6 +269,7 @@ def test_endpoint_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -251,7 +277,7 @@ def test_endpoint_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -260,26 +286,27 @@ def test_endpoint_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -288,6 +315,7 @@ def test_endpoint_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -347,7 +375,7 @@ def test_endpoint_service_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -364,6 +392,7 @@ def test_endpoint_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case ADC client cert is provided. Whether client cert is used depends on @@ -388,7 +417,7 @@ def test_endpoint_service_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -397,6 +426,7 @@ def test_endpoint_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case client_cert_source and ADC client cert are not provided. @@ -409,7 +439,7 @@ def test_endpoint_service_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -418,9 +448,91 @@ def test_endpoint_service_client_mtls_env_auto( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) +@pytest.mark.parametrize( + "client_class", [EndpointServiceClient, EndpointServiceAsyncClient] +) +@mock.patch.object( + EndpointServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(EndpointServiceClient), +) +@mock.patch.object( + EndpointServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(EndpointServiceAsyncClient), +) +def test_endpoint_service_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + @pytest.mark.parametrize( "client_class,transport_class,transport_name", [ @@ -436,10 +548,12 @@ def test_endpoint_service_client_client_options_scopes( client_class, transport_class, transport_name ): # Check the case scopes are provided. - options = client_options.ClientOptions(scopes=["1", "2"],) + options = client_options.ClientOptions( + scopes=["1", "2"], + ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -448,28 +562,36 @@ def test_endpoint_service_client_client_options_scopes( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (EndpointServiceClient, transports.EndpointServiceGrpcTransport, "grpc"), + ( + EndpointServiceClient, + transports.EndpointServiceGrpcTransport, + "grpc", + grpc_helpers, + ), ( EndpointServiceAsyncClient, transports.EndpointServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_endpoint_service_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -478,6 +600,7 @@ def test_endpoint_service_client_client_options_credentials_file( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -497,14 +620,87 @@ def test_endpoint_service_client_client_options_from_dict(): client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) -def test_create_endpoint( - transport: str = "grpc", request_type=endpoint_service.CreateEndpointRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + EndpointServiceClient, + transports.EndpointServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + EndpointServiceAsyncClient, + transports.EndpointServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_endpoint_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers ): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + endpoint_service.CreateEndpointRequest, + dict, + ], +) +def test_create_endpoint(request_type, transport: str = "grpc"): client = EndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -526,15 +722,12 @@ def test_create_endpoint( assert isinstance(response, future.Future) -def test_create_endpoint_from_dict(): - test_create_endpoint(request_type=dict) - - def test_create_endpoint_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -550,7 +743,8 @@ async def test_create_endpoint_async( transport: str = "grpc_asyncio", request_type=endpoint_service.CreateEndpointRequest ): client = EndpointServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -580,13 +774,15 @@ async def test_create_endpoint_async_from_dict(): def test_create_endpoint_field_headers(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = endpoint_service.CreateEndpointRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_endpoint), "__call__") as call: @@ -600,7 +796,10 @@ def test_create_endpoint_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -613,7 +812,7 @@ async def test_create_endpoint_field_headers_async(): # a field header. Set these to a non-empty value. request = endpoint_service.CreateEndpointRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_endpoint), "__call__") as call: @@ -629,11 +828,16 @@ async def test_create_endpoint_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_create_endpoint_flattened(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_endpoint), "__call__") as call: @@ -642,19 +846,30 @@ def test_create_endpoint_flattened(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.create_endpoint( - parent="parent_value", endpoint=gca_endpoint.Endpoint(name="name_value"), + parent="parent_value", + endpoint=gca_endpoint.Endpoint(name="name_value"), + endpoint_id="endpoint_id_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].endpoint == gca_endpoint.Endpoint(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].endpoint + mock_val = gca_endpoint.Endpoint(name="name_value") + assert arg == mock_val + arg = args[0].endpoint_id + mock_val = "endpoint_id_value" + assert arg == mock_val def test_create_endpoint_flattened_error(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -663,6 +878,7 @@ def test_create_endpoint_flattened_error(): endpoint_service.CreateEndpointRequest(), parent="parent_value", endpoint=gca_endpoint.Endpoint(name="name_value"), + endpoint_id="endpoint_id_value", ) @@ -683,15 +899,24 @@ async def test_create_endpoint_flattened_async(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. response = await client.create_endpoint( - parent="parent_value", endpoint=gca_endpoint.Endpoint(name="name_value"), + parent="parent_value", + endpoint=gca_endpoint.Endpoint(name="name_value"), + endpoint_id="endpoint_id_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].endpoint == gca_endpoint.Endpoint(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].endpoint + mock_val = gca_endpoint.Endpoint(name="name_value") + assert arg == mock_val + arg = args[0].endpoint_id + mock_val = "endpoint_id_value" + assert arg == mock_val @pytest.mark.asyncio @@ -707,14 +932,21 @@ async def test_create_endpoint_flattened_error_async(): endpoint_service.CreateEndpointRequest(), parent="parent_value", endpoint=gca_endpoint.Endpoint(name="name_value"), + endpoint_id="endpoint_id_value", ) -def test_get_endpoint( - transport: str = "grpc", request_type=endpoint_service.GetEndpointRequest -): +@pytest.mark.parametrize( + "request_type", + [ + endpoint_service.GetEndpointRequest, + dict, + ], +) +def test_get_endpoint(request_type, transport: str = "grpc"): client = EndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -729,6 +961,9 @@ def test_get_endpoint( display_name="display_name_value", description="description_value", etag="etag_value", + network="network_value", + enable_private_service_connect=True, + model_deployment_monitoring_job="model_deployment_monitoring_job_value", ) response = client.get_endpoint(request) @@ -743,17 +978,20 @@ def test_get_endpoint( assert response.display_name == "display_name_value" assert response.description == "description_value" assert response.etag == "etag_value" - - -def test_get_endpoint_from_dict(): - test_get_endpoint(request_type=dict) + assert response.network == "network_value" + assert response.enable_private_service_connect is True + assert ( + response.model_deployment_monitoring_job + == "model_deployment_monitoring_job_value" + ) def test_get_endpoint_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -769,7 +1007,8 @@ async def test_get_endpoint_async( transport: str = "grpc_asyncio", request_type=endpoint_service.GetEndpointRequest ): client = EndpointServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -785,6 +1024,9 @@ async def test_get_endpoint_async( display_name="display_name_value", description="description_value", etag="etag_value", + network="network_value", + enable_private_service_connect=True, + model_deployment_monitoring_job="model_deployment_monitoring_job_value", ) ) response = await client.get_endpoint(request) @@ -800,6 +1042,12 @@ async def test_get_endpoint_async( assert response.display_name == "display_name_value" assert response.description == "description_value" assert response.etag == "etag_value" + assert response.network == "network_value" + assert response.enable_private_service_connect is True + assert ( + response.model_deployment_monitoring_job + == "model_deployment_monitoring_job_value" + ) @pytest.mark.asyncio @@ -808,13 +1056,15 @@ async def test_get_endpoint_async_from_dict(): def test_get_endpoint_field_headers(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = endpoint_service.GetEndpointRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_endpoint), "__call__") as call: @@ -828,7 +1078,10 @@ def test_get_endpoint_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -841,7 +1094,7 @@ async def test_get_endpoint_field_headers_async(): # a field header. Set these to a non-empty value. request = endpoint_service.GetEndpointRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_endpoint), "__call__") as call: @@ -855,11 +1108,16 @@ async def test_get_endpoint_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_get_endpoint_flattened(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_endpoint), "__call__") as call: @@ -867,23 +1125,30 @@ def test_get_endpoint_flattened(): call.return_value = endpoint.Endpoint() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_endpoint(name="name_value",) + client.get_endpoint( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_endpoint_flattened_error(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.get_endpoint( - endpoint_service.GetEndpointRequest(), name="name_value", + endpoint_service.GetEndpointRequest(), + name="name_value", ) @@ -901,13 +1166,17 @@ async def test_get_endpoint_flattened_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(endpoint.Endpoint()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_endpoint(name="name_value",) + response = await client.get_endpoint( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -920,15 +1189,22 @@ async def test_get_endpoint_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.get_endpoint( - endpoint_service.GetEndpointRequest(), name="name_value", + endpoint_service.GetEndpointRequest(), + name="name_value", ) -def test_list_endpoints( - transport: str = "grpc", request_type=endpoint_service.ListEndpointsRequest -): +@pytest.mark.parametrize( + "request_type", + [ + endpoint_service.ListEndpointsRequest, + dict, + ], +) +def test_list_endpoints(request_type, transport: str = "grpc"): client = EndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -953,15 +1229,12 @@ def test_list_endpoints( assert response.next_page_token == "next_page_token_value" -def test_list_endpoints_from_dict(): - test_list_endpoints(request_type=dict) - - def test_list_endpoints_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -977,7 +1250,8 @@ async def test_list_endpoints_async( transport: str = "grpc_asyncio", request_type=endpoint_service.ListEndpointsRequest ): client = EndpointServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1010,13 +1284,15 @@ async def test_list_endpoints_async_from_dict(): def test_list_endpoints_field_headers(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = endpoint_service.ListEndpointsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_endpoints), "__call__") as call: @@ -1030,7 +1306,10 @@ def test_list_endpoints_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1043,7 +1322,7 @@ async def test_list_endpoints_field_headers_async(): # a field header. Set these to a non-empty value. request = endpoint_service.ListEndpointsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_endpoints), "__call__") as call: @@ -1059,11 +1338,16 @@ async def test_list_endpoints_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_endpoints_flattened(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_endpoints), "__call__") as call: @@ -1071,23 +1355,30 @@ def test_list_endpoints_flattened(): call.return_value = endpoint_service.ListEndpointsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_endpoints(parent="parent_value",) + client.list_endpoints( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_endpoints_flattened_error(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.list_endpoints( - endpoint_service.ListEndpointsRequest(), parent="parent_value", + endpoint_service.ListEndpointsRequest(), + parent="parent_value", ) @@ -1107,13 +1398,17 @@ async def test_list_endpoints_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_endpoints(parent="parent_value",) + response = await client.list_endpoints( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1126,12 +1421,16 @@ async def test_list_endpoints_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.list_endpoints( - endpoint_service.ListEndpointsRequest(), parent="parent_value", + endpoint_service.ListEndpointsRequest(), + parent="parent_value", ) -def test_list_endpoints_pager(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_endpoints_pager(transport_name: str = "grpc"): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_endpoints), "__call__") as call: @@ -1146,13 +1445,20 @@ def test_list_endpoints_pager(): next_page_token="abc", ), endpoint_service.ListEndpointsResponse( - endpoints=[], next_page_token="def", + endpoints=[], + next_page_token="def", ), endpoint_service.ListEndpointsResponse( - endpoints=[endpoint.Endpoint(),], next_page_token="ghi", + endpoints=[ + endpoint.Endpoint(), + ], + next_page_token="ghi", ), endpoint_service.ListEndpointsResponse( - endpoints=[endpoint.Endpoint(), endpoint.Endpoint(),], + endpoints=[ + endpoint.Endpoint(), + endpoint.Endpoint(), + ], ), RuntimeError, ) @@ -1165,13 +1471,16 @@ def test_list_endpoints_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all(isinstance(i, endpoint.Endpoint) for i in results) -def test_list_endpoints_pages(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_endpoints_pages(transport_name: str = "grpc"): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_endpoints), "__call__") as call: @@ -1186,13 +1495,20 @@ def test_list_endpoints_pages(): next_page_token="abc", ), endpoint_service.ListEndpointsResponse( - endpoints=[], next_page_token="def", + endpoints=[], + next_page_token="def", ), endpoint_service.ListEndpointsResponse( - endpoints=[endpoint.Endpoint(),], next_page_token="ghi", + endpoints=[ + endpoint.Endpoint(), + ], + next_page_token="ghi", ), endpoint_service.ListEndpointsResponse( - endpoints=[endpoint.Endpoint(), endpoint.Endpoint(),], + endpoints=[ + endpoint.Endpoint(), + endpoint.Endpoint(), + ], ), RuntimeError, ) @@ -1222,20 +1538,29 @@ async def test_list_endpoints_async_pager(): next_page_token="abc", ), endpoint_service.ListEndpointsResponse( - endpoints=[], next_page_token="def", + endpoints=[], + next_page_token="def", ), endpoint_service.ListEndpointsResponse( - endpoints=[endpoint.Endpoint(),], next_page_token="ghi", + endpoints=[ + endpoint.Endpoint(), + ], + next_page_token="ghi", ), endpoint_service.ListEndpointsResponse( - endpoints=[endpoint.Endpoint(), endpoint.Endpoint(),], + endpoints=[ + endpoint.Endpoint(), + endpoint.Endpoint(), + ], ), RuntimeError, ) - async_pager = await client.list_endpoints(request={},) + async_pager = await client.list_endpoints( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -1263,28 +1588,43 @@ async def test_list_endpoints_async_pages(): next_page_token="abc", ), endpoint_service.ListEndpointsResponse( - endpoints=[], next_page_token="def", + endpoints=[], + next_page_token="def", ), endpoint_service.ListEndpointsResponse( - endpoints=[endpoint.Endpoint(),], next_page_token="ghi", + endpoints=[ + endpoint.Endpoint(), + ], + next_page_token="ghi", ), endpoint_service.ListEndpointsResponse( - endpoints=[endpoint.Endpoint(), endpoint.Endpoint(),], + endpoints=[ + endpoint.Endpoint(), + endpoint.Endpoint(), + ], ), RuntimeError, ) pages = [] - async for page_ in (await client.list_endpoints(request={})).pages: + async for page_ in ( + await client.list_endpoints(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_update_endpoint( - transport: str = "grpc", request_type=endpoint_service.UpdateEndpointRequest -): +@pytest.mark.parametrize( + "request_type", + [ + endpoint_service.UpdateEndpointRequest, + dict, + ], +) +def test_update_endpoint(request_type, transport: str = "grpc"): client = EndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1299,6 +1639,9 @@ def test_update_endpoint( display_name="display_name_value", description="description_value", etag="etag_value", + network="network_value", + enable_private_service_connect=True, + model_deployment_monitoring_job="model_deployment_monitoring_job_value", ) response = client.update_endpoint(request) @@ -1313,17 +1656,20 @@ def test_update_endpoint( assert response.display_name == "display_name_value" assert response.description == "description_value" assert response.etag == "etag_value" - - -def test_update_endpoint_from_dict(): - test_update_endpoint(request_type=dict) + assert response.network == "network_value" + assert response.enable_private_service_connect is True + assert ( + response.model_deployment_monitoring_job + == "model_deployment_monitoring_job_value" + ) def test_update_endpoint_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1339,7 +1685,8 @@ async def test_update_endpoint_async( transport: str = "grpc_asyncio", request_type=endpoint_service.UpdateEndpointRequest ): client = EndpointServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1355,6 +1702,9 @@ async def test_update_endpoint_async( display_name="display_name_value", description="description_value", etag="etag_value", + network="network_value", + enable_private_service_connect=True, + model_deployment_monitoring_job="model_deployment_monitoring_job_value", ) ) response = await client.update_endpoint(request) @@ -1370,6 +1720,12 @@ async def test_update_endpoint_async( assert response.display_name == "display_name_value" assert response.description == "description_value" assert response.etag == "etag_value" + assert response.network == "network_value" + assert response.enable_private_service_connect is True + assert ( + response.model_deployment_monitoring_job + == "model_deployment_monitoring_job_value" + ) @pytest.mark.asyncio @@ -1378,13 +1734,15 @@ async def test_update_endpoint_async_from_dict(): def test_update_endpoint_field_headers(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = endpoint_service.UpdateEndpointRequest() - request.endpoint.name = "endpoint.name/value" + request.endpoint.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_endpoint), "__call__") as call: @@ -1398,9 +1756,10 @@ def test_update_endpoint_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "endpoint.name=endpoint.name/value",) in kw[ - "metadata" - ] + assert ( + "x-goog-request-params", + "endpoint.name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1413,7 +1772,7 @@ async def test_update_endpoint_field_headers_async(): # a field header. Set these to a non-empty value. request = endpoint_service.UpdateEndpointRequest() - request.endpoint.name = "endpoint.name/value" + request.endpoint.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_endpoint), "__call__") as call: @@ -1429,13 +1788,16 @@ async def test_update_endpoint_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "endpoint.name=endpoint.name/value",) in kw[ - "metadata" - ] + assert ( + "x-goog-request-params", + "endpoint.name=name_value", + ) in kw["metadata"] def test_update_endpoint_flattened(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_endpoint), "__call__") as call: @@ -1452,12 +1814,18 @@ def test_update_endpoint_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].endpoint == gca_endpoint.Endpoint(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].endpoint + mock_val = gca_endpoint.Endpoint(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val def test_update_endpoint_flattened_error(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1494,8 +1862,12 @@ async def test_update_endpoint_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].endpoint == gca_endpoint.Endpoint(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].endpoint + mock_val = gca_endpoint.Endpoint(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val @pytest.mark.asyncio @@ -1514,11 +1886,17 @@ async def test_update_endpoint_flattened_error_async(): ) -def test_delete_endpoint( - transport: str = "grpc", request_type=endpoint_service.DeleteEndpointRequest -): +@pytest.mark.parametrize( + "request_type", + [ + endpoint_service.DeleteEndpointRequest, + dict, + ], +) +def test_delete_endpoint(request_type, transport: str = "grpc"): client = EndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1540,15 +1918,12 @@ def test_delete_endpoint( assert isinstance(response, future.Future) -def test_delete_endpoint_from_dict(): - test_delete_endpoint(request_type=dict) - - def test_delete_endpoint_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1564,7 +1939,8 @@ async def test_delete_endpoint_async( transport: str = "grpc_asyncio", request_type=endpoint_service.DeleteEndpointRequest ): client = EndpointServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1594,13 +1970,15 @@ async def test_delete_endpoint_async_from_dict(): def test_delete_endpoint_field_headers(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = endpoint_service.DeleteEndpointRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_endpoint), "__call__") as call: @@ -1614,7 +1992,10 @@ def test_delete_endpoint_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1627,7 +2008,7 @@ async def test_delete_endpoint_field_headers_async(): # a field header. Set these to a non-empty value. request = endpoint_service.DeleteEndpointRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_endpoint), "__call__") as call: @@ -1643,11 +2024,16 @@ async def test_delete_endpoint_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_delete_endpoint_flattened(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_endpoint), "__call__") as call: @@ -1655,23 +2041,30 @@ def test_delete_endpoint_flattened(): call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_endpoint(name="name_value",) + client.delete_endpoint( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_delete_endpoint_flattened_error(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.delete_endpoint( - endpoint_service.DeleteEndpointRequest(), name="name_value", + endpoint_service.DeleteEndpointRequest(), + name="name_value", ) @@ -1691,13 +2084,17 @@ async def test_delete_endpoint_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_endpoint(name="name_value",) + response = await client.delete_endpoint( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1710,15 +2107,22 @@ async def test_delete_endpoint_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.delete_endpoint( - endpoint_service.DeleteEndpointRequest(), name="name_value", + endpoint_service.DeleteEndpointRequest(), + name="name_value", ) -def test_deploy_model( - transport: str = "grpc", request_type=endpoint_service.DeployModelRequest -): +@pytest.mark.parametrize( + "request_type", + [ + endpoint_service.DeployModelRequest, + dict, + ], +) +def test_deploy_model(request_type, transport: str = "grpc"): client = EndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1740,15 +2144,12 @@ def test_deploy_model( assert isinstance(response, future.Future) -def test_deploy_model_from_dict(): - test_deploy_model(request_type=dict) - - def test_deploy_model_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1764,7 +2165,8 @@ async def test_deploy_model_async( transport: str = "grpc_asyncio", request_type=endpoint_service.DeployModelRequest ): client = EndpointServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1794,13 +2196,15 @@ async def test_deploy_model_async_from_dict(): def test_deploy_model_field_headers(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = endpoint_service.DeployModelRequest() - request.endpoint = "endpoint/value" + request.endpoint = "endpoint_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.deploy_model), "__call__") as call: @@ -1814,7 +2218,10 @@ def test_deploy_model_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "endpoint=endpoint/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "endpoint=endpoint_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1827,7 +2234,7 @@ async def test_deploy_model_field_headers_async(): # a field header. Set these to a non-empty value. request = endpoint_service.DeployModelRequest() - request.endpoint = "endpoint/value" + request.endpoint = "endpoint_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.deploy_model), "__call__") as call: @@ -1843,11 +2250,16 @@ async def test_deploy_model_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "endpoint=endpoint/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "endpoint=endpoint_value", + ) in kw["metadata"] def test_deploy_model_flattened(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.deploy_model), "__call__") as call: @@ -1871,19 +2283,27 @@ def test_deploy_model_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].endpoint == "endpoint_value" - assert args[0].deployed_model == gca_endpoint.DeployedModel( + arg = args[0].endpoint + mock_val = "endpoint_value" + assert arg == mock_val + arg = args[0].deployed_model + mock_val = gca_endpoint.DeployedModel( dedicated_resources=machine_resources.DedicatedResources( machine_spec=machine_resources.MachineSpec( machine_type="machine_type_value" ) ) ) - assert args[0].traffic_split == {"key_value": 541} + assert arg == mock_val + arg = args[0].traffic_split + mock_val = {"key_value": 541} + assert arg == mock_val def test_deploy_model_flattened_error(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1934,15 +2354,21 @@ async def test_deploy_model_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].endpoint == "endpoint_value" - assert args[0].deployed_model == gca_endpoint.DeployedModel( + arg = args[0].endpoint + mock_val = "endpoint_value" + assert arg == mock_val + arg = args[0].deployed_model + mock_val = gca_endpoint.DeployedModel( dedicated_resources=machine_resources.DedicatedResources( machine_spec=machine_resources.MachineSpec( machine_type="machine_type_value" ) ) ) - assert args[0].traffic_split == {"key_value": 541} + assert arg == mock_val + arg = args[0].traffic_split + mock_val = {"key_value": 541} + assert arg == mock_val @pytest.mark.asyncio @@ -1968,11 +2394,17 @@ async def test_deploy_model_flattened_error_async(): ) -def test_undeploy_model( - transport: str = "grpc", request_type=endpoint_service.UndeployModelRequest -): +@pytest.mark.parametrize( + "request_type", + [ + endpoint_service.UndeployModelRequest, + dict, + ], +) +def test_undeploy_model(request_type, transport: str = "grpc"): client = EndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1994,15 +2426,12 @@ def test_undeploy_model( assert isinstance(response, future.Future) -def test_undeploy_model_from_dict(): - test_undeploy_model(request_type=dict) - - def test_undeploy_model_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = EndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2018,7 +2447,8 @@ async def test_undeploy_model_async( transport: str = "grpc_asyncio", request_type=endpoint_service.UndeployModelRequest ): client = EndpointServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2048,13 +2478,15 @@ async def test_undeploy_model_async_from_dict(): def test_undeploy_model_field_headers(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = endpoint_service.UndeployModelRequest() - request.endpoint = "endpoint/value" + request.endpoint = "endpoint_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.undeploy_model), "__call__") as call: @@ -2068,7 +2500,10 @@ def test_undeploy_model_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "endpoint=endpoint/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "endpoint=endpoint_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2081,7 +2516,7 @@ async def test_undeploy_model_field_headers_async(): # a field header. Set these to a non-empty value. request = endpoint_service.UndeployModelRequest() - request.endpoint = "endpoint/value" + request.endpoint = "endpoint_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.undeploy_model), "__call__") as call: @@ -2097,11 +2532,16 @@ async def test_undeploy_model_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "endpoint=endpoint/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "endpoint=endpoint_value", + ) in kw["metadata"] def test_undeploy_model_flattened(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.undeploy_model), "__call__") as call: @@ -2119,13 +2559,21 @@ def test_undeploy_model_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].endpoint == "endpoint_value" - assert args[0].deployed_model_id == "deployed_model_id_value" - assert args[0].traffic_split == {"key_value": 541} + arg = args[0].endpoint + mock_val = "endpoint_value" + assert arg == mock_val + arg = args[0].deployed_model_id + mock_val = "deployed_model_id_value" + assert arg == mock_val + arg = args[0].traffic_split + mock_val = {"key_value": 541} + assert arg == mock_val def test_undeploy_model_flattened_error(): - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2164,9 +2612,15 @@ async def test_undeploy_model_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].endpoint == "endpoint_value" - assert args[0].deployed_model_id == "deployed_model_id_value" - assert args[0].traffic_split == {"key_value": 541} + arg = args[0].endpoint + mock_val = "endpoint_value" + assert arg == mock_val + arg = args[0].deployed_model_id + mock_val = "deployed_model_id_value" + assert arg == mock_val + arg = args[0].traffic_split + mock_val = {"key_value": 541} + assert arg == mock_val @pytest.mark.asyncio @@ -2193,7 +2647,8 @@ def test_credentials_transport_error(): ) with pytest.raises(ValueError): client = EndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # It is an error to provide a credentials file and a transport instance. @@ -2206,13 +2661,34 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.EndpointServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = EndpointServiceClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = EndpointServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.EndpointServiceGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = EndpointServiceClient( - client_options={"scopes": ["1", "2"]}, transport=transport, + client_options={"scopes": ["1", "2"]}, + transport=transport, ) @@ -2255,10 +2731,28 @@ def test_transport_adc(transport_class): adc.assert_called_once() +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = EndpointServiceClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + def test_transport_grpc_default(): # A client should use the gRPC transport by default. - client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials(),) - assert isinstance(client.transport, transports.EndpointServiceGrpcTransport,) + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.EndpointServiceGrpcTransport, + ) def test_endpoint_service_base_transport_error(): @@ -2290,18 +2784,38 @@ def test_endpoint_service_base_transport(): "delete_endpoint", "deploy_model", "undeploy_model", + "set_iam_policy", + "get_iam_policy", + "test_iam_permissions", + "get_location", + "list_locations", + "get_operation", + "wait_operation", + "cancel_operation", + "delete_operation", + "list_operations", ) for method in methods: with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + # Additionally, the LRO client (a property) should # also raise NotImplementedError with pytest.raises(NotImplementedError): transport.operations_client + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + -@requires_google_auth_gte_1_25_0 def test_endpoint_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -2312,7 +2826,8 @@ def test_endpoint_service_base_transport_with_credentials_file(): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.EndpointServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", + credentials_file="credentials.json", + quota_project_id="octopus", ) load_creds.assert_called_once_with( "credentials.json", @@ -2322,26 +2837,6 @@ def test_endpoint_service_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_endpoint_service_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.aiplatform_v1beta1.services.endpoint_service.transports.EndpointServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.EndpointServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - def test_endpoint_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( @@ -2353,7 +2848,6 @@ def test_endpoint_service_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_endpoint_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -2366,18 +2860,6 @@ def test_endpoint_service_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_endpoint_service_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - EndpointServiceClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -2385,7 +2867,6 @@ def test_endpoint_service_auth_adc_old_google_auth(): transports.EndpointServiceGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_endpoint_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -2399,26 +2880,6 @@ def test_endpoint_service_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.EndpointServiceGrpcTransport, - transports.EndpointServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_endpoint_service_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ @@ -2426,7 +2887,6 @@ def test_endpoint_service_transport_auth_adc_old_google_auth(transport_class): (transports.EndpointServiceGrpcAsyncIOTransport, grpc_helpers_async), ], ) -@requires_api_core_gte_1_26_0 def test_endpoint_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -2455,79 +2915,6 @@ def test_endpoint_service_transport_create_channel(transport_class, grpc_helpers ) -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.EndpointServiceGrpcTransport, grpc_helpers), - (transports.EndpointServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_endpoint_service_transport_create_channel_old_api_core( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class(quota_project_id="octopus") - - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.EndpointServiceGrpcTransport, grpc_helpers), - (transports.EndpointServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_endpoint_service_transport_create_channel_user_scopes( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=["1", "2"], - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -2550,7 +2937,7 @@ def test_endpoint_service_grpc_transport_client_cert_source_for_mtls(transport_c "squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_channel_creds, quota_project_id=None, options=[ @@ -2573,24 +2960,40 @@ def test_endpoint_service_grpc_transport_client_cert_source_for_mtls(transport_c ) -def test_endpoint_service_host_no_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_endpoint_service_host_no_port(transport_name): client = EndpointServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="aiplatform.googleapis.com" ), + transport=transport_name, ) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") -def test_endpoint_service_host_with_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_endpoint_service_host_with_port(transport_name): client = EndpointServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="aiplatform.googleapis.com:8000" ), + transport=transport_name, ) - assert client.transport._host == "aiplatform.googleapis.com:8000" + assert client.transport._host == ("aiplatform.googleapis.com:8000") def test_endpoint_service_grpc_transport_channel(): @@ -2598,7 +3001,8 @@ def test_endpoint_service_grpc_transport_channel(): # Check that channel is used if provided. transport = transports.EndpointServiceGrpcTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -2610,7 +3014,8 @@ def test_endpoint_service_grpc_asyncio_transport_channel(): # Check that channel is used if provided. transport = transports.EndpointServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -2659,7 +3064,7 @@ def test_endpoint_service_transport_channel_mtls_with_client_cert_source( "mtls.squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -2706,7 +3111,7 @@ def test_endpoint_service_transport_channel_mtls_with_adc(transport_class): "mtls.squid.clam.whelk:443", credentials=mock_cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -2719,12 +3124,16 @@ def test_endpoint_service_transport_channel_mtls_with_adc(transport_class): def test_endpoint_service_grpc_lro_client(): client = EndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -2732,12 +3141,16 @@ def test_endpoint_service_grpc_lro_client(): def test_endpoint_service_grpc_lro_async_client(): client = EndpointServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -2748,7 +3161,9 @@ def test_endpoint_path(): location = "clam" endpoint = "whelk" expected = "projects/{project}/locations/{location}/endpoints/{endpoint}".format( - project=project, location=location, endpoint=endpoint, + project=project, + location=location, + endpoint=endpoint, ) actual = EndpointServiceClient.endpoint_path(project, location, endpoint) assert expected == actual @@ -2772,7 +3187,9 @@ def test_model_path(): location = "mussel" model = "winkle" expected = "projects/{project}/locations/{location}/models/{model}".format( - project=project, location=location, model=model, + project=project, + location=location, + model=model, ) actual = EndpointServiceClient.model_path(project, location, model) assert expected == actual @@ -2791,54 +3208,109 @@ def test_parse_model_path(): assert expected == actual -def test_common_billing_account_path(): - billing_account = "squid" - expected = "billingAccounts/{billing_account}".format( - billing_account=billing_account, +def test_model_deployment_monitoring_job_path(): + project = "squid" + location = "clam" + model_deployment_monitoring_job = "whelk" + expected = "projects/{project}/locations/{location}/modelDeploymentMonitoringJobs/{model_deployment_monitoring_job}".format( + project=project, + location=location, + model_deployment_monitoring_job=model_deployment_monitoring_job, + ) + actual = EndpointServiceClient.model_deployment_monitoring_job_path( + project, location, model_deployment_monitoring_job ) - actual = EndpointServiceClient.common_billing_account_path(billing_account) assert expected == actual -def test_parse_common_billing_account_path(): +def test_parse_model_deployment_monitoring_job_path(): expected = { - "billing_account": "clam", + "project": "octopus", + "location": "oyster", + "model_deployment_monitoring_job": "nudibranch", } - path = EndpointServiceClient.common_billing_account_path(**expected) + path = EndpointServiceClient.model_deployment_monitoring_job_path(**expected) # Check that the path construction is reversible. - actual = EndpointServiceClient.parse_common_billing_account_path(path) + actual = EndpointServiceClient.parse_model_deployment_monitoring_job_path(path) assert expected == actual -def test_common_folder_path(): - folder = "whelk" - expected = "folders/{folder}".format(folder=folder,) - actual = EndpointServiceClient.common_folder_path(folder) +def test_network_path(): + project = "cuttlefish" + network = "mussel" + expected = "projects/{project}/global/networks/{network}".format( + project=project, + network=network, + ) + actual = EndpointServiceClient.network_path(project, network) assert expected == actual -def test_parse_common_folder_path(): +def test_parse_network_path(): expected = { - "folder": "octopus", + "project": "winkle", + "network": "nautilus", } - path = EndpointServiceClient.common_folder_path(**expected) + path = EndpointServiceClient.network_path(**expected) # Check that the path construction is reversible. - actual = EndpointServiceClient.parse_common_folder_path(path) + actual = EndpointServiceClient.parse_network_path(path) assert expected == actual -def test_common_organization_path(): - organization = "oyster" - expected = "organizations/{organization}".format(organization=organization,) - actual = EndpointServiceClient.common_organization_path(organization) +def test_common_billing_account_path(): + billing_account = "scallop" + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + actual = EndpointServiceClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "abalone", + } + path = EndpointServiceClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = EndpointServiceClient.parse_common_billing_account_path(path) + assert expected == actual + + +def test_common_folder_path(): + folder = "squid" + expected = "folders/{folder}".format( + folder=folder, + ) + actual = EndpointServiceClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "clam", + } + path = EndpointServiceClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = EndpointServiceClient.parse_common_folder_path(path) + assert expected == actual + + +def test_common_organization_path(): + organization = "whelk" + expected = "organizations/{organization}".format( + organization=organization, + ) + actual = EndpointServiceClient.common_organization_path(organization) assert expected == actual def test_parse_common_organization_path(): expected = { - "organization": "nudibranch", + "organization": "octopus", } path = EndpointServiceClient.common_organization_path(**expected) @@ -2848,15 +3320,17 @@ def test_parse_common_organization_path(): def test_common_project_path(): - project = "cuttlefish" - expected = "projects/{project}".format(project=project,) + project = "oyster" + expected = "projects/{project}".format( + project=project, + ) actual = EndpointServiceClient.common_project_path(project) assert expected == actual def test_parse_common_project_path(): expected = { - "project": "mussel", + "project": "nudibranch", } path = EndpointServiceClient.common_project_path(**expected) @@ -2866,10 +3340,11 @@ def test_parse_common_project_path(): def test_common_location_path(): - project = "winkle" - location = "nautilus" + project = "cuttlefish" + location = "mussel" expected = "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) actual = EndpointServiceClient.common_location_path(project, location) assert expected == actual @@ -2877,8 +3352,8 @@ def test_common_location_path(): def test_parse_common_location_path(): expected = { - "project": "scallop", - "location": "abalone", + "project": "winkle", + "location": "nautilus", } path = EndpointServiceClient.common_location_path(**expected) @@ -2887,14 +3362,15 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( transports.EndpointServiceTransport, "_prep_wrapped_messages" ) as prep: client = EndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2903,6 +3379,1593 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = EndpointServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_delete_operation(transport: str = "grpc"): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_operation(transport: str = "grpc"): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_operation_field_headers(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = None + + client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_operation_field_headers_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_delete_operation_from_dict(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_delete_operation_from_dict_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_cancel_operation(transport: str = "grpc"): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation(transport: str = "grpc"): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_wait_operation(transport: str = "grpc"): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_wait_operation(transport: str = "grpc"): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_wait_operation_field_headers(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_wait_operation_field_headers_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_wait_operation_from_dict(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_wait_operation_from_dict_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_operation(transport: str = "grpc"): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_get_operation(transport: str = "grpc"): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_get_operation_field_headers(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_get_operation_from_dict(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_operations(transport: str = "grpc"): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + response = client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +@pytest.mark.asyncio +async def test_list_operations(transport: str = "grpc"): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +def test_list_operations_field_headers(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_operations_field_headers_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_operations_from_dict(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + response = client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_operations_from_dict_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_locations(transport: str = "grpc"): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + response = client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +@pytest.mark.asyncio +async def test_list_locations(transport: str = "grpc"): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +def test_list_locations_field_headers(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_locations_field_headers_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_locations_from_dict(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + response = client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_locations_from_dict_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_location(transport: str = "grpc"): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + response = client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +@pytest.mark.asyncio +async def test_get_location_async(transport: str = "grpc_asyncio"): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +def test_get_location_field_headers(): + client = EndpointServiceClient(credentials=ga_credentials.AnonymousCredentials()) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = locations_pb2.Location() + + client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_location_field_headers_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials() + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +def test_get_location_from_dict(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + response = client.get_location( + request={ + "name": "locations/abc", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_location_from_dict_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_set_iam_policy(transport: str = "grpc"): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + response = client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + response = await client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_set_iam_policy_field_headers(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_set_iam_policy_field_headers_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_set_iam_policy_from_dict(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_set_iam_policy_from_dict_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +def test_get_iam_policy(transport: str = "grpc"): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + + response = client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + + response = await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_get_iam_policy_field_headers(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_iam_policy_field_headers_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_get_iam_policy_from_dict(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_iam_policy_from_dict_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +def test_test_iam_permissions(transport: str = "grpc"): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + + response = client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + ) + + response = await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +def test_test_iam_permissions_field_headers(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_field_headers_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_test_iam_permissions_from_dict(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + response = client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_from_dict_async(): + client = EndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + response = await client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = EndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (EndpointServiceClient, transports.EndpointServiceGrpcTransport), + (EndpointServiceAsyncClient, transports.EndpointServiceGrpcAsyncIOTransport), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) diff --git a/tests/unit/gapic/aiplatform_v1beta1/test_featurestore_online_serving_service.py b/tests/unit/gapic/aiplatform_v1beta1/test_featurestore_online_serving_service.py index 6645e05944..05170d9aed 100644 --- a/tests/unit/gapic/aiplatform_v1beta1/test_featurestore_online_serving_service.py +++ b/tests/unit/gapic/aiplatform_v1beta1/test_featurestore_online_serving_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,8 +14,13 @@ # limitations under the License. # import os -import mock -import packaging.version + +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock +except ImportError: + import mock import grpc from grpc.experimental import aio @@ -29,6 +34,7 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.aiplatform_v1beta1.services.featurestore_online_serving_service import ( @@ -40,41 +46,17 @@ from google.cloud.aiplatform_v1beta1.services.featurestore_online_serving_service import ( transports, ) -from google.cloud.aiplatform_v1beta1.services.featurestore_online_serving_service.transports.base import ( - _API_CORE_VERSION, -) -from google.cloud.aiplatform_v1beta1.services.featurestore_online_serving_service.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.aiplatform_v1beta1.types import feature_selector from google.cloud.aiplatform_v1beta1.types import featurestore_online_service +from google.cloud.location import locations_pb2 +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.oauth2 import service_account import google.auth -# TODO(busunkim): Once google-api-core >= 1.26.0 is required: -# - Delete all the api-core and auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - -requires_api_core_lt_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), - reason="This test requires google-api-core < 1.26.0", -) - -requires_api_core_gte_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), - reason="This test requires google-api-core >= 1.26.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -129,14 +111,14 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( - "client_class", + "client_class,transport_name", [ - FeaturestoreOnlineServingServiceClient, - FeaturestoreOnlineServingServiceAsyncClient, + (FeaturestoreOnlineServingServiceClient, "grpc"), + (FeaturestoreOnlineServingServiceAsyncClient, "grpc_asyncio"), ], ) def test_featurestore_online_serving_service_client_from_service_account_info( - client_class, + client_class, transport_name ): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( @@ -144,37 +126,69 @@ def test_featurestore_online_serving_service_client_from_service_account_info( ) as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") @pytest.mark.parametrize( - "client_class", + "transport_class,transport_name", [ - FeaturestoreOnlineServingServiceClient, - FeaturestoreOnlineServingServiceAsyncClient, + (transports.FeaturestoreOnlineServingServiceGrpcTransport, "grpc"), + ( + transports.FeaturestoreOnlineServingServiceGrpcAsyncIOTransport, + "grpc_asyncio", + ), + ], +) +def test_featurestore_online_serving_service_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + +@pytest.mark.parametrize( + "client_class,transport_name", + [ + (FeaturestoreOnlineServingServiceClient, "grpc"), + (FeaturestoreOnlineServingServiceAsyncClient, "grpc_asyncio"), ], ) def test_featurestore_online_serving_service_client_from_service_account_file( - client_class, + client_class, transport_name ): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") def test_featurestore_online_serving_service_client_get_transport_class(): @@ -235,7 +249,7 @@ def test_featurestore_online_serving_service_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -244,6 +258,7 @@ def test_featurestore_online_serving_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -251,7 +266,7 @@ def test_featurestore_online_serving_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -260,6 +275,7 @@ def test_featurestore_online_serving_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -267,7 +283,7 @@ def test_featurestore_online_serving_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -276,26 +292,27 @@ def test_featurestore_online_serving_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -304,6 +321,7 @@ def test_featurestore_online_serving_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -363,7 +381,7 @@ def test_featurestore_online_serving_service_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -380,6 +398,7 @@ def test_featurestore_online_serving_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case ADC client cert is provided. Whether client cert is used depends on @@ -404,7 +423,7 @@ def test_featurestore_online_serving_service_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -413,6 +432,7 @@ def test_featurestore_online_serving_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case client_cert_source and ADC client cert are not provided. @@ -425,7 +445,7 @@ def test_featurestore_online_serving_service_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -434,9 +454,97 @@ def test_featurestore_online_serving_service_client_mtls_env_auto( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) +@pytest.mark.parametrize( + "client_class", + [ + FeaturestoreOnlineServingServiceClient, + FeaturestoreOnlineServingServiceAsyncClient, + ], +) +@mock.patch.object( + FeaturestoreOnlineServingServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(FeaturestoreOnlineServingServiceClient), +) +@mock.patch.object( + FeaturestoreOnlineServingServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(FeaturestoreOnlineServingServiceAsyncClient), +) +def test_featurestore_online_serving_service_client_get_mtls_endpoint_and_cert_source( + client_class, +): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + @pytest.mark.parametrize( "client_class,transport_class,transport_name", [ @@ -456,10 +564,12 @@ def test_featurestore_online_serving_service_client_client_options_scopes( client_class, transport_class, transport_name ): # Check the case scopes are provided. - options = client_options.ClientOptions(scopes=["1", "2"],) + options = client_options.ClientOptions( + scopes=["1", "2"], + ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -468,32 +578,36 @@ def test_featurestore_online_serving_service_client_client_options_scopes( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ ( FeaturestoreOnlineServingServiceClient, transports.FeaturestoreOnlineServingServiceGrpcTransport, "grpc", + grpc_helpers, ), ( FeaturestoreOnlineServingServiceAsyncClient, transports.FeaturestoreOnlineServingServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_featurestore_online_serving_service_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -502,6 +616,7 @@ def test_featurestore_online_serving_service_client_client_options_credentials_f client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -521,15 +636,87 @@ def test_featurestore_online_serving_service_client_client_options_from_dict(): client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) -def test_read_feature_values( - transport: str = "grpc", - request_type=featurestore_online_service.ReadFeatureValuesRequest, +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + FeaturestoreOnlineServingServiceClient, + transports.FeaturestoreOnlineServingServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + FeaturestoreOnlineServingServiceAsyncClient, + transports.FeaturestoreOnlineServingServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_featurestore_online_serving_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers ): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + featurestore_online_service.ReadFeatureValuesRequest, + dict, + ], +) +def test_read_feature_values(request_type, transport: str = "grpc"): client = FeaturestoreOnlineServingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -553,15 +740,12 @@ def test_read_feature_values( assert isinstance(response, featurestore_online_service.ReadFeatureValuesResponse) -def test_read_feature_values_from_dict(): - test_read_feature_values(request_type=dict) - - def test_read_feature_values_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = FeaturestoreOnlineServingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -580,7 +764,8 @@ async def test_read_feature_values_async( request_type=featurestore_online_service.ReadFeatureValuesRequest, ): client = FeaturestoreOnlineServingServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -620,7 +805,7 @@ def test_read_feature_values_field_headers(): # a field header. Set these to a non-empty value. request = featurestore_online_service.ReadFeatureValuesRequest() - request.entity_type = "entity_type/value" + request.entity_type = "entity_type_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -636,7 +821,10 @@ def test_read_feature_values_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "entity_type=entity_type/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "entity_type=entity_type_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -649,7 +837,7 @@ async def test_read_feature_values_field_headers_async(): # a field header. Set these to a non-empty value. request = featurestore_online_service.ReadFeatureValuesRequest() - request.entity_type = "entity_type/value" + request.entity_type = "entity_type_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -667,7 +855,10 @@ async def test_read_feature_values_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "entity_type=entity_type/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "entity_type=entity_type_value", + ) in kw["metadata"] def test_read_feature_values_flattened(): @@ -683,13 +874,17 @@ def test_read_feature_values_flattened(): call.return_value = featurestore_online_service.ReadFeatureValuesResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.read_feature_values(entity_type="entity_type_value",) + client.read_feature_values( + entity_type="entity_type_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].entity_type == "entity_type_value" + arg = args[0].entity_type + mock_val = "entity_type_value" + assert arg == mock_val def test_read_feature_values_flattened_error(): @@ -724,13 +919,17 @@ async def test_read_feature_values_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.read_feature_values(entity_type="entity_type_value",) + response = await client.read_feature_values( + entity_type="entity_type_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].entity_type == "entity_type_value" + arg = args[0].entity_type + mock_val = "entity_type_value" + assert arg == mock_val @pytest.mark.asyncio @@ -748,12 +947,17 @@ async def test_read_feature_values_flattened_error_async(): ) -def test_streaming_read_feature_values( - transport: str = "grpc", - request_type=featurestore_online_service.StreamingReadFeatureValuesRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + featurestore_online_service.StreamingReadFeatureValuesRequest, + dict, + ], +) +def test_streaming_read_feature_values(request_type, transport: str = "grpc"): client = FeaturestoreOnlineServingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -784,15 +988,12 @@ def test_streaming_read_feature_values( ) -def test_streaming_read_feature_values_from_dict(): - test_streaming_read_feature_values(request_type=dict) - - def test_streaming_read_feature_values_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = FeaturestoreOnlineServingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -813,7 +1014,8 @@ async def test_streaming_read_feature_values_async( request_type=featurestore_online_service.StreamingReadFeatureValuesRequest, ): client = FeaturestoreOnlineServingServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -857,7 +1059,7 @@ def test_streaming_read_feature_values_field_headers(): # a field header. Set these to a non-empty value. request = featurestore_online_service.StreamingReadFeatureValuesRequest() - request.entity_type = "entity_type/value" + request.entity_type = "entity_type_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -875,7 +1077,10 @@ def test_streaming_read_feature_values_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "entity_type=entity_type/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "entity_type=entity_type_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -888,7 +1093,7 @@ async def test_streaming_read_feature_values_field_headers_async(): # a field header. Set these to a non-empty value. request = featurestore_online_service.StreamingReadFeatureValuesRequest() - request.entity_type = "entity_type/value" + request.entity_type = "entity_type_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -907,7 +1112,10 @@ async def test_streaming_read_feature_values_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "entity_type=entity_type/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "entity_type=entity_type_value", + ) in kw["metadata"] def test_streaming_read_feature_values_flattened(): @@ -925,13 +1133,17 @@ def test_streaming_read_feature_values_flattened(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.streaming_read_feature_values(entity_type="entity_type_value",) + client.streaming_read_feature_values( + entity_type="entity_type_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].entity_type == "entity_type_value" + arg = args[0].entity_type + mock_val = "entity_type_value" + assert arg == mock_val def test_streaming_read_feature_values_flattened_error(): @@ -974,7 +1186,9 @@ async def test_streaming_read_feature_values_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].entity_type == "entity_type_value" + arg = args[0].entity_type + mock_val = "entity_type_value" + assert arg == mock_val @pytest.mark.asyncio @@ -999,7 +1213,8 @@ def test_credentials_transport_error(): ) with pytest.raises(ValueError): client = FeaturestoreOnlineServingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # It is an error to provide a credentials file and a transport instance. @@ -1012,13 +1227,34 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.FeaturestoreOnlineServingServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = FeaturestoreOnlineServingServiceClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = FeaturestoreOnlineServingServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.FeaturestoreOnlineServingServiceGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = FeaturestoreOnlineServingServiceClient( - client_options={"scopes": ["1", "2"]}, transport=transport, + client_options={"scopes": ["1", "2"]}, + transport=transport, ) @@ -1061,13 +1297,29 @@ def test_transport_adc(transport_class): adc.assert_called_once() +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = FeaturestoreOnlineServingServiceClient.get_transport_class( + transport_name + )( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = FeaturestoreOnlineServingServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) assert isinstance( - client.transport, transports.FeaturestoreOnlineServingServiceGrpcTransport, + client.transport, + transports.FeaturestoreOnlineServingServiceGrpcTransport, ) @@ -1095,13 +1347,33 @@ def test_featurestore_online_serving_service_base_transport(): methods = ( "read_feature_values", "streaming_read_feature_values", + "set_iam_policy", + "get_iam_policy", + "test_iam_permissions", + "get_location", + "list_locations", + "get_operation", + "wait_operation", + "cancel_operation", + "delete_operation", + "list_operations", ) for method in methods: with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + -@requires_google_auth_gte_1_25_0 def test_featurestore_online_serving_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -1112,7 +1384,8 @@ def test_featurestore_online_serving_service_base_transport_with_credentials_fil Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.FeaturestoreOnlineServingServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", + credentials_file="credentials.json", + quota_project_id="octopus", ) load_creds.assert_called_once_with( "credentials.json", @@ -1122,26 +1395,6 @@ def test_featurestore_online_serving_service_base_transport_with_credentials_fil ) -@requires_google_auth_lt_1_25_0 -def test_featurestore_online_serving_service_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.aiplatform_v1beta1.services.featurestore_online_serving_service.transports.FeaturestoreOnlineServingServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.FeaturestoreOnlineServingServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - def test_featurestore_online_serving_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( @@ -1153,7 +1406,6 @@ def test_featurestore_online_serving_service_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_featurestore_online_serving_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -1166,18 +1418,6 @@ def test_featurestore_online_serving_service_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_featurestore_online_serving_service_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - FeaturestoreOnlineServingServiceClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -1185,7 +1425,6 @@ def test_featurestore_online_serving_service_auth_adc_old_google_auth(): transports.FeaturestoreOnlineServingServiceGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_featurestore_online_serving_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -1199,28 +1438,6 @@ def test_featurestore_online_serving_service_transport_auth_adc(transport_class) ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.FeaturestoreOnlineServingServiceGrpcTransport, - transports.FeaturestoreOnlineServingServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_featurestore_online_serving_service_transport_auth_adc_old_google_auth( - transport_class, -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ @@ -1231,7 +1448,6 @@ def test_featurestore_online_serving_service_transport_auth_adc_old_google_auth( ), ], ) -@requires_api_core_gte_1_26_0 def test_featurestore_online_serving_service_transport_create_channel( transport_class, grpc_helpers ): @@ -1263,95 +1479,16 @@ def test_featurestore_online_serving_service_transport_create_channel( @pytest.mark.parametrize( - "transport_class,grpc_helpers", + "transport_class", [ - (transports.FeaturestoreOnlineServingServiceGrpcTransport, grpc_helpers), - ( - transports.FeaturestoreOnlineServingServiceGrpcAsyncIOTransport, - grpc_helpers_async, - ), + transports.FeaturestoreOnlineServingServiceGrpcTransport, + transports.FeaturestoreOnlineServingServiceGrpcAsyncIOTransport, ], ) -@requires_api_core_lt_1_26_0 -def test_featurestore_online_serving_service_transport_create_channel_old_api_core( - transport_class, grpc_helpers +def test_featurestore_online_serving_service_grpc_transport_client_cert_source_for_mtls( + transport_class, ): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class(quota_project_id="octopus") - - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.FeaturestoreOnlineServingServiceGrpcTransport, grpc_helpers), - ( - transports.FeaturestoreOnlineServingServiceGrpcAsyncIOTransport, - grpc_helpers_async, - ), - ], -) -@requires_api_core_lt_1_26_0 -def test_featurestore_online_serving_service_transport_create_channel_user_scopes( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=["1", "2"], - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize( - "transport_class", - [ - transports.FeaturestoreOnlineServingServiceGrpcTransport, - transports.FeaturestoreOnlineServingServiceGrpcAsyncIOTransport, - ], -) -def test_featurestore_online_serving_service_grpc_transport_client_cert_source_for_mtls( - transport_class, -): - cred = ga_credentials.AnonymousCredentials() + cred = ga_credentials.AnonymousCredentials() # Check ssl_channel_credentials is used if provided. with mock.patch.object(transport_class, "create_channel") as mock_create_channel: @@ -1365,7 +1502,7 @@ def test_featurestore_online_serving_service_grpc_transport_client_cert_source_f "squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_channel_creds, quota_project_id=None, options=[ @@ -1388,24 +1525,40 @@ def test_featurestore_online_serving_service_grpc_transport_client_cert_source_f ) -def test_featurestore_online_serving_service_host_no_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_featurestore_online_serving_service_host_no_port(transport_name): client = FeaturestoreOnlineServingServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="aiplatform.googleapis.com" ), + transport=transport_name, ) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") -def test_featurestore_online_serving_service_host_with_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_featurestore_online_serving_service_host_with_port(transport_name): client = FeaturestoreOnlineServingServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="aiplatform.googleapis.com:8000" ), + transport=transport_name, ) - assert client.transport._host == "aiplatform.googleapis.com:8000" + assert client.transport._host == ("aiplatform.googleapis.com:8000") def test_featurestore_online_serving_service_grpc_transport_channel(): @@ -1413,7 +1566,8 @@ def test_featurestore_online_serving_service_grpc_transport_channel(): # Check that channel is used if provided. transport = transports.FeaturestoreOnlineServingServiceGrpcTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -1425,7 +1579,8 @@ def test_featurestore_online_serving_service_grpc_asyncio_transport_channel(): # Check that channel is used if provided. transport = transports.FeaturestoreOnlineServingServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -1474,7 +1629,7 @@ def test_featurestore_online_serving_service_transport_channel_mtls_with_client_ "mtls.squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -1523,7 +1678,7 @@ def test_featurestore_online_serving_service_transport_channel_mtls_with_adc( "mtls.squid.clam.whelk:443", credentials=mock_cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -1593,7 +1748,9 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "scallop" - expected = "folders/{folder}".format(folder=folder,) + expected = "folders/{folder}".format( + folder=folder, + ) actual = FeaturestoreOnlineServingServiceClient.common_folder_path(folder) assert expected == actual @@ -1611,7 +1768,9 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "squid" - expected = "organizations/{organization}".format(organization=organization,) + expected = "organizations/{organization}".format( + organization=organization, + ) actual = FeaturestoreOnlineServingServiceClient.common_organization_path( organization ) @@ -1631,7 +1790,9 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "whelk" - expected = "projects/{project}".format(project=project,) + expected = "projects/{project}".format( + project=project, + ) actual = FeaturestoreOnlineServingServiceClient.common_project_path(project) assert expected == actual @@ -1651,7 +1812,8 @@ def test_common_location_path(): project = "oyster" location = "nudibranch" expected = "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) actual = FeaturestoreOnlineServingServiceClient.common_location_path( project, location @@ -1671,14 +1833,15 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( transports.FeaturestoreOnlineServingServiceTransport, "_prep_wrapped_messages" ) as prep: client = FeaturestoreOnlineServingServiceClient( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -1687,6 +1850,1601 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = FeaturestoreOnlineServingServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_delete_operation(transport: str = "grpc"): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_operation(transport: str = "grpc"): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_operation_field_headers(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = None + + client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_operation_field_headers_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_delete_operation_from_dict(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_delete_operation_from_dict_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_cancel_operation(transport: str = "grpc"): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation(transport: str = "grpc"): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_wait_operation(transport: str = "grpc"): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_wait_operation(transport: str = "grpc"): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_wait_operation_field_headers(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_wait_operation_field_headers_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_wait_operation_from_dict(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_wait_operation_from_dict_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_operation(transport: str = "grpc"): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_get_operation(transport: str = "grpc"): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_get_operation_field_headers(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_get_operation_from_dict(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_operations(transport: str = "grpc"): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + response = client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +@pytest.mark.asyncio +async def test_list_operations(transport: str = "grpc"): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +def test_list_operations_field_headers(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_operations_field_headers_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_operations_from_dict(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + response = client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_operations_from_dict_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_locations(transport: str = "grpc"): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + response = client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +@pytest.mark.asyncio +async def test_list_locations(transport: str = "grpc"): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +def test_list_locations_field_headers(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_locations_field_headers_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_locations_from_dict(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + response = client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_locations_from_dict_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_location(transport: str = "grpc"): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + response = client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +@pytest.mark.asyncio +async def test_get_location_async(transport: str = "grpc_asyncio"): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +def test_get_location_field_headers(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials() + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = locations_pb2.Location() + + client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_location_field_headers_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials() + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +def test_get_location_from_dict(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + response = client.get_location( + request={ + "name": "locations/abc", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_location_from_dict_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_set_iam_policy(transport: str = "grpc"): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + response = client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + response = await client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_set_iam_policy_field_headers(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_set_iam_policy_field_headers_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_set_iam_policy_from_dict(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_set_iam_policy_from_dict_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +def test_get_iam_policy(transport: str = "grpc"): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + + response = client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + + response = await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_get_iam_policy_field_headers(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_iam_policy_field_headers_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_get_iam_policy_from_dict(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_iam_policy_from_dict_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +def test_test_iam_permissions(transport: str = "grpc"): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + + response = client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + ) + + response = await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +def test_test_iam_permissions_field_headers(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_field_headers_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_test_iam_permissions_from_dict(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + response = client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_from_dict_async(): + client = FeaturestoreOnlineServingServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + response = await client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = FeaturestoreOnlineServingServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + ( + FeaturestoreOnlineServingServiceClient, + transports.FeaturestoreOnlineServingServiceGrpcTransport, + ), + ( + FeaturestoreOnlineServingServiceAsyncClient, + transports.FeaturestoreOnlineServingServiceGrpcAsyncIOTransport, + ), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) diff --git a/tests/unit/gapic/aiplatform_v1beta1/test_featurestore_service.py b/tests/unit/gapic/aiplatform_v1beta1/test_featurestore_service.py index 5721f569ac..831ef99612 100644 --- a/tests/unit/gapic/aiplatform_v1beta1/test_featurestore_service.py +++ b/tests/unit/gapic/aiplatform_v1beta1/test_featurestore_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,8 +14,13 @@ # limitations under the License. # import os -import mock -import packaging.version + +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock +except ImportError: + import mock import grpc from grpc.experimental import aio @@ -30,8 +35,10 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.aiplatform_v1beta1.services.featurestore_service import ( @@ -42,12 +49,7 @@ ) from google.cloud.aiplatform_v1beta1.services.featurestore_service import pagers from google.cloud.aiplatform_v1beta1.services.featurestore_service import transports -from google.cloud.aiplatform_v1beta1.services.featurestore_service.transports.base import ( - _API_CORE_VERSION, -) -from google.cloud.aiplatform_v1beta1.services.featurestore_service.transports.base import ( - _GOOGLE_AUTH_VERSION, -) +from google.cloud.aiplatform_v1beta1.types import encryption_spec from google.cloud.aiplatform_v1beta1.types import entity_type from google.cloud.aiplatform_v1beta1.types import entity_type as gca_entity_type from google.cloud.aiplatform_v1beta1.types import feature @@ -60,6 +62,10 @@ from google.cloud.aiplatform_v1beta1.types import featurestore_service from google.cloud.aiplatform_v1beta1.types import io from google.cloud.aiplatform_v1beta1.types import operation as gca_operation +from google.cloud.location import locations_pb2 +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 from google.oauth2 import service_account from google.protobuf import duration_pb2 # type: ignore @@ -68,29 +74,6 @@ import google.auth -# TODO(busunkim): Once google-api-core >= 1.26.0 is required: -# - Delete all the api-core and auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - -requires_api_core_lt_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), - reason="This test requires google-api-core < 1.26.0", -) - -requires_api_core_gte_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), - reason="This test requires google-api-core >= 1.26.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -137,40 +120,81 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( - "client_class", [FeaturestoreServiceClient, FeaturestoreServiceAsyncClient,] + "client_class,transport_name", + [ + (FeaturestoreServiceClient, "grpc"), + (FeaturestoreServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_featurestore_service_client_from_service_account_info(client_class): +def test_featurestore_service_client_from_service_account_info( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.FeaturestoreServiceGrpcTransport, "grpc"), + (transports.FeaturestoreServiceGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_featurestore_service_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() @pytest.mark.parametrize( - "client_class", [FeaturestoreServiceClient, FeaturestoreServiceAsyncClient,] + "client_class,transport_name", + [ + (FeaturestoreServiceClient, "grpc"), + (FeaturestoreServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_featurestore_service_client_from_service_account_file(client_class): +def test_featurestore_service_client_from_service_account_file( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") def test_featurestore_service_client_get_transport_class(): @@ -227,7 +251,7 @@ def test_featurestore_service_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -236,6 +260,7 @@ def test_featurestore_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -243,7 +268,7 @@ def test_featurestore_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -252,6 +277,7 @@ def test_featurestore_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -259,7 +285,7 @@ def test_featurestore_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -268,26 +294,27 @@ def test_featurestore_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -296,6 +323,7 @@ def test_featurestore_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -355,7 +383,7 @@ def test_featurestore_service_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -372,6 +400,7 @@ def test_featurestore_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case ADC client cert is provided. Whether client cert is used depends on @@ -396,7 +425,7 @@ def test_featurestore_service_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -405,6 +434,7 @@ def test_featurestore_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case client_cert_source and ADC client cert are not provided. @@ -417,7 +447,7 @@ def test_featurestore_service_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -426,9 +456,91 @@ def test_featurestore_service_client_mtls_env_auto( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) +@pytest.mark.parametrize( + "client_class", [FeaturestoreServiceClient, FeaturestoreServiceAsyncClient] +) +@mock.patch.object( + FeaturestoreServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(FeaturestoreServiceClient), +) +@mock.patch.object( + FeaturestoreServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(FeaturestoreServiceAsyncClient), +) +def test_featurestore_service_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + @pytest.mark.parametrize( "client_class,transport_class,transport_name", [ @@ -448,10 +560,12 @@ def test_featurestore_service_client_client_options_scopes( client_class, transport_class, transport_name ): # Check the case scopes are provided. - options = client_options.ClientOptions(scopes=["1", "2"],) + options = client_options.ClientOptions( + scopes=["1", "2"], + ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -460,32 +574,36 @@ def test_featurestore_service_client_client_options_scopes( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ ( FeaturestoreServiceClient, transports.FeaturestoreServiceGrpcTransport, "grpc", + grpc_helpers, ), ( FeaturestoreServiceAsyncClient, transports.FeaturestoreServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_featurestore_service_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -494,6 +612,7 @@ def test_featurestore_service_client_client_options_credentials_file( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -513,14 +632,87 @@ def test_featurestore_service_client_client_options_from_dict(): client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) -def test_create_featurestore( - transport: str = "grpc", request_type=featurestore_service.CreateFeaturestoreRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + FeaturestoreServiceClient, + transports.FeaturestoreServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + FeaturestoreServiceAsyncClient, + transports.FeaturestoreServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_featurestore_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers ): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.CreateFeaturestoreRequest, + dict, + ], +) +def test_create_featurestore(request_type, transport: str = "grpc"): client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -544,15 +736,12 @@ def test_create_featurestore( assert isinstance(response, future.Future) -def test_create_featurestore_from_dict(): - test_create_featurestore(request_type=dict) - - def test_create_featurestore_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -571,7 +760,8 @@ async def test_create_featurestore_async( request_type=featurestore_service.CreateFeaturestoreRequest, ): client = FeaturestoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -611,7 +801,7 @@ def test_create_featurestore_field_headers(): # a field header. Set these to a non-empty value. request = featurestore_service.CreateFeaturestoreRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -627,7 +817,10 @@ def test_create_featurestore_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -640,7 +833,7 @@ async def test_create_featurestore_field_headers_async(): # a field header. Set these to a non-empty value. request = featurestore_service.CreateFeaturestoreRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -658,7 +851,10 @@ async def test_create_featurestore_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_create_featurestore_flattened(): @@ -677,14 +873,22 @@ def test_create_featurestore_flattened(): client.create_featurestore( parent="parent_value", featurestore=gca_featurestore.Featurestore(name="name_value"), + featurestore_id="featurestore_id_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].featurestore == gca_featurestore.Featurestore(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].featurestore + mock_val = gca_featurestore.Featurestore(name="name_value") + assert arg == mock_val + arg = args[0].featurestore_id + mock_val = "featurestore_id_value" + assert arg == mock_val def test_create_featurestore_flattened_error(): @@ -699,6 +903,7 @@ def test_create_featurestore_flattened_error(): featurestore_service.CreateFeaturestoreRequest(), parent="parent_value", featurestore=gca_featurestore.Featurestore(name="name_value"), + featurestore_id="featurestore_id_value", ) @@ -723,14 +928,22 @@ async def test_create_featurestore_flattened_async(): response = await client.create_featurestore( parent="parent_value", featurestore=gca_featurestore.Featurestore(name="name_value"), + featurestore_id="featurestore_id_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].featurestore == gca_featurestore.Featurestore(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].featurestore + mock_val = gca_featurestore.Featurestore(name="name_value") + assert arg == mock_val + arg = args[0].featurestore_id + mock_val = "featurestore_id_value" + assert arg == mock_val @pytest.mark.asyncio @@ -746,14 +959,21 @@ async def test_create_featurestore_flattened_error_async(): featurestore_service.CreateFeaturestoreRequest(), parent="parent_value", featurestore=gca_featurestore.Featurestore(name="name_value"), + featurestore_id="featurestore_id_value", ) -def test_get_featurestore( - transport: str = "grpc", request_type=featurestore_service.GetFeaturestoreRequest -): +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.GetFeaturestoreRequest, + dict, + ], +) +def test_get_featurestore(request_type, transport: str = "grpc"): client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -782,15 +1002,12 @@ def test_get_featurestore( assert response.state == featurestore.Featurestore.State.STABLE -def test_get_featurestore_from_dict(): - test_get_featurestore(request_type=dict) - - def test_get_featurestore_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -807,7 +1024,8 @@ async def test_get_featurestore_async( request_type=featurestore_service.GetFeaturestoreRequest, ): client = FeaturestoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -852,7 +1070,7 @@ def test_get_featurestore_field_headers(): # a field header. Set these to a non-empty value. request = featurestore_service.GetFeaturestoreRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_featurestore), "__call__") as call: @@ -866,7 +1084,10 @@ def test_get_featurestore_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -879,7 +1100,7 @@ async def test_get_featurestore_field_headers_async(): # a field header. Set these to a non-empty value. request = featurestore_service.GetFeaturestoreRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_featurestore), "__call__") as call: @@ -895,7 +1116,10 @@ async def test_get_featurestore_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_get_featurestore_flattened(): @@ -909,13 +1133,17 @@ def test_get_featurestore_flattened(): call.return_value = featurestore.Featurestore() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_featurestore(name="name_value",) + client.get_featurestore( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_featurestore_flattened_error(): @@ -927,7 +1155,8 @@ def test_get_featurestore_flattened_error(): # fields is an error. with pytest.raises(ValueError): client.get_featurestore( - featurestore_service.GetFeaturestoreRequest(), name="name_value", + featurestore_service.GetFeaturestoreRequest(), + name="name_value", ) @@ -947,13 +1176,17 @@ async def test_get_featurestore_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_featurestore(name="name_value",) + response = await client.get_featurestore( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -966,15 +1199,22 @@ async def test_get_featurestore_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.get_featurestore( - featurestore_service.GetFeaturestoreRequest(), name="name_value", + featurestore_service.GetFeaturestoreRequest(), + name="name_value", ) -def test_list_featurestores( - transport: str = "grpc", request_type=featurestore_service.ListFeaturestoresRequest -): +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.ListFeaturestoresRequest, + dict, + ], +) +def test_list_featurestores(request_type, transport: str = "grpc"): client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1001,15 +1241,12 @@ def test_list_featurestores( assert response.next_page_token == "next_page_token_value" -def test_list_featurestores_from_dict(): - test_list_featurestores(request_type=dict) - - def test_list_featurestores_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1028,7 +1265,8 @@ async def test_list_featurestores_async( request_type=featurestore_service.ListFeaturestoresRequest, ): client = FeaturestoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1071,7 +1309,7 @@ def test_list_featurestores_field_headers(): # a field header. Set these to a non-empty value. request = featurestore_service.ListFeaturestoresRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1087,7 +1325,10 @@ def test_list_featurestores_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1100,7 +1341,7 @@ async def test_list_featurestores_field_headers_async(): # a field header. Set these to a non-empty value. request = featurestore_service.ListFeaturestoresRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1118,7 +1359,10 @@ async def test_list_featurestores_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_featurestores_flattened(): @@ -1134,13 +1378,17 @@ def test_list_featurestores_flattened(): call.return_value = featurestore_service.ListFeaturestoresResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_featurestores(parent="parent_value",) + client.list_featurestores( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_featurestores_flattened_error(): @@ -1152,7 +1400,8 @@ def test_list_featurestores_flattened_error(): # fields is an error. with pytest.raises(ValueError): client.list_featurestores( - featurestore_service.ListFeaturestoresRequest(), parent="parent_value", + featurestore_service.ListFeaturestoresRequest(), + parent="parent_value", ) @@ -1174,13 +1423,17 @@ async def test_list_featurestores_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_featurestores(parent="parent_value",) + response = await client.list_featurestores( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1193,12 +1446,16 @@ async def test_list_featurestores_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.list_featurestores( - featurestore_service.ListFeaturestoresRequest(), parent="parent_value", + featurestore_service.ListFeaturestoresRequest(), + parent="parent_value", ) -def test_list_featurestores_pager(): - client = FeaturestoreServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_featurestores_pager(transport_name: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1215,10 +1472,14 @@ def test_list_featurestores_pager(): next_page_token="abc", ), featurestore_service.ListFeaturestoresResponse( - featurestores=[], next_page_token="def", + featurestores=[], + next_page_token="def", ), featurestore_service.ListFeaturestoresResponse( - featurestores=[featurestore.Featurestore(),], next_page_token="ghi", + featurestores=[ + featurestore.Featurestore(), + ], + next_page_token="ghi", ), featurestore_service.ListFeaturestoresResponse( featurestores=[ @@ -1237,13 +1498,16 @@ def test_list_featurestores_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all(isinstance(i, featurestore.Featurestore) for i in results) -def test_list_featurestores_pages(): - client = FeaturestoreServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_featurestores_pages(transport_name: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1260,10 +1524,14 @@ def test_list_featurestores_pages(): next_page_token="abc", ), featurestore_service.ListFeaturestoresResponse( - featurestores=[], next_page_token="def", + featurestores=[], + next_page_token="def", ), featurestore_service.ListFeaturestoresResponse( - featurestores=[featurestore.Featurestore(),], next_page_token="ghi", + featurestores=[ + featurestore.Featurestore(), + ], + next_page_token="ghi", ), featurestore_service.ListFeaturestoresResponse( featurestores=[ @@ -1301,10 +1569,14 @@ async def test_list_featurestores_async_pager(): next_page_token="abc", ), featurestore_service.ListFeaturestoresResponse( - featurestores=[], next_page_token="def", + featurestores=[], + next_page_token="def", ), featurestore_service.ListFeaturestoresResponse( - featurestores=[featurestore.Featurestore(),], next_page_token="ghi", + featurestores=[ + featurestore.Featurestore(), + ], + next_page_token="ghi", ), featurestore_service.ListFeaturestoresResponse( featurestores=[ @@ -1314,10 +1586,12 @@ async def test_list_featurestores_async_pager(): ), RuntimeError, ) - async_pager = await client.list_featurestores(request={},) + async_pager = await client.list_featurestores( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -1347,10 +1621,14 @@ async def test_list_featurestores_async_pages(): next_page_token="abc", ), featurestore_service.ListFeaturestoresResponse( - featurestores=[], next_page_token="def", + featurestores=[], + next_page_token="def", ), featurestore_service.ListFeaturestoresResponse( - featurestores=[featurestore.Featurestore(),], next_page_token="ghi", + featurestores=[ + featurestore.Featurestore(), + ], + next_page_token="ghi", ), featurestore_service.ListFeaturestoresResponse( featurestores=[ @@ -1361,17 +1639,25 @@ async def test_list_featurestores_async_pages(): RuntimeError, ) pages = [] - async for page_ in (await client.list_featurestores(request={})).pages: + async for page_ in ( + await client.list_featurestores(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_update_featurestore( - transport: str = "grpc", request_type=featurestore_service.UpdateFeaturestoreRequest -): +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.UpdateFeaturestoreRequest, + dict, + ], +) +def test_update_featurestore(request_type, transport: str = "grpc"): client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1395,15 +1681,12 @@ def test_update_featurestore( assert isinstance(response, future.Future) -def test_update_featurestore_from_dict(): - test_update_featurestore(request_type=dict) - - def test_update_featurestore_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1422,7 +1705,8 @@ async def test_update_featurestore_async( request_type=featurestore_service.UpdateFeaturestoreRequest, ): client = FeaturestoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1462,7 +1746,7 @@ def test_update_featurestore_field_headers(): # a field header. Set these to a non-empty value. request = featurestore_service.UpdateFeaturestoreRequest() - request.featurestore.name = "featurestore.name/value" + request.featurestore.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1480,7 +1764,7 @@ def test_update_featurestore_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "featurestore.name=featurestore.name/value", + "featurestore.name=name_value", ) in kw["metadata"] @@ -1494,7 +1778,7 @@ async def test_update_featurestore_field_headers_async(): # a field header. Set these to a non-empty value. request = featurestore_service.UpdateFeaturestoreRequest() - request.featurestore.name = "featurestore.name/value" + request.featurestore.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1514,7 +1798,7 @@ async def test_update_featurestore_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "featurestore.name=featurestore.name/value", + "featurestore.name=name_value", ) in kw["metadata"] @@ -1540,8 +1824,12 @@ def test_update_featurestore_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].featurestore == gca_featurestore.Featurestore(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].featurestore + mock_val = gca_featurestore.Featurestore(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val def test_update_featurestore_flattened_error(): @@ -1586,8 +1874,12 @@ async def test_update_featurestore_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].featurestore == gca_featurestore.Featurestore(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].featurestore + mock_val = gca_featurestore.Featurestore(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val @pytest.mark.asyncio @@ -1606,11 +1898,17 @@ async def test_update_featurestore_flattened_error_async(): ) -def test_delete_featurestore( - transport: str = "grpc", request_type=featurestore_service.DeleteFeaturestoreRequest -): +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.DeleteFeaturestoreRequest, + dict, + ], +) +def test_delete_featurestore(request_type, transport: str = "grpc"): client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1634,15 +1932,12 @@ def test_delete_featurestore( assert isinstance(response, future.Future) -def test_delete_featurestore_from_dict(): - test_delete_featurestore(request_type=dict) - - def test_delete_featurestore_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1661,7 +1956,8 @@ async def test_delete_featurestore_async( request_type=featurestore_service.DeleteFeaturestoreRequest, ): client = FeaturestoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1701,7 +1997,7 @@ def test_delete_featurestore_field_headers(): # a field header. Set these to a non-empty value. request = featurestore_service.DeleteFeaturestoreRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1717,7 +2013,10 @@ def test_delete_featurestore_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1730,7 +2029,7 @@ async def test_delete_featurestore_field_headers_async(): # a field header. Set these to a non-empty value. request = featurestore_service.DeleteFeaturestoreRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1748,7 +2047,10 @@ async def test_delete_featurestore_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_delete_featurestore_flattened(): @@ -1764,13 +2066,21 @@ def test_delete_featurestore_flattened(): call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_featurestore(name="name_value",) + client.delete_featurestore( + name="name_value", + force=True, + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].force + mock_val = True + assert arg == mock_val def test_delete_featurestore_flattened_error(): @@ -1782,7 +2092,9 @@ def test_delete_featurestore_flattened_error(): # fields is an error. with pytest.raises(ValueError): client.delete_featurestore( - featurestore_service.DeleteFeaturestoreRequest(), name="name_value", + featurestore_service.DeleteFeaturestoreRequest(), + name="name_value", + force=True, ) @@ -1804,13 +2116,21 @@ async def test_delete_featurestore_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_featurestore(name="name_value",) + response = await client.delete_featurestore( + name="name_value", + force=True, + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].force + mock_val = True + assert arg == mock_val @pytest.mark.asyncio @@ -1823,15 +2143,23 @@ async def test_delete_featurestore_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.delete_featurestore( - featurestore_service.DeleteFeaturestoreRequest(), name="name_value", + featurestore_service.DeleteFeaturestoreRequest(), + name="name_value", + force=True, ) -def test_create_entity_type( - transport: str = "grpc", request_type=featurestore_service.CreateEntityTypeRequest -): +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.CreateEntityTypeRequest, + dict, + ], +) +def test_create_entity_type(request_type, transport: str = "grpc"): client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1855,15 +2183,12 @@ def test_create_entity_type( assert isinstance(response, future.Future) -def test_create_entity_type_from_dict(): - test_create_entity_type(request_type=dict) - - def test_create_entity_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1882,7 +2207,8 @@ async def test_create_entity_type_async( request_type=featurestore_service.CreateEntityTypeRequest, ): client = FeaturestoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1922,7 +2248,7 @@ def test_create_entity_type_field_headers(): # a field header. Set these to a non-empty value. request = featurestore_service.CreateEntityTypeRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1938,7 +2264,10 @@ def test_create_entity_type_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1951,7 +2280,7 @@ async def test_create_entity_type_field_headers_async(): # a field header. Set these to a non-empty value. request = featurestore_service.CreateEntityTypeRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1969,7 +2298,10 @@ async def test_create_entity_type_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_create_entity_type_flattened(): @@ -1988,14 +2320,22 @@ def test_create_entity_type_flattened(): client.create_entity_type( parent="parent_value", entity_type=gca_entity_type.EntityType(name="name_value"), + entity_type_id="entity_type_id_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].entity_type == gca_entity_type.EntityType(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].entity_type + mock_val = gca_entity_type.EntityType(name="name_value") + assert arg == mock_val + arg = args[0].entity_type_id + mock_val = "entity_type_id_value" + assert arg == mock_val def test_create_entity_type_flattened_error(): @@ -2010,6 +2350,7 @@ def test_create_entity_type_flattened_error(): featurestore_service.CreateEntityTypeRequest(), parent="parent_value", entity_type=gca_entity_type.EntityType(name="name_value"), + entity_type_id="entity_type_id_value", ) @@ -2034,14 +2375,22 @@ async def test_create_entity_type_flattened_async(): response = await client.create_entity_type( parent="parent_value", entity_type=gca_entity_type.EntityType(name="name_value"), + entity_type_id="entity_type_id_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].entity_type == gca_entity_type.EntityType(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].entity_type + mock_val = gca_entity_type.EntityType(name="name_value") + assert arg == mock_val + arg = args[0].entity_type_id + mock_val = "entity_type_id_value" + assert arg == mock_val @pytest.mark.asyncio @@ -2057,14 +2406,21 @@ async def test_create_entity_type_flattened_error_async(): featurestore_service.CreateEntityTypeRequest(), parent="parent_value", entity_type=gca_entity_type.EntityType(name="name_value"), + entity_type_id="entity_type_id_value", ) -def test_get_entity_type( - transport: str = "grpc", request_type=featurestore_service.GetEntityTypeRequest -): +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.GetEntityTypeRequest, + dict, + ], +) +def test_get_entity_type(request_type, transport: str = "grpc"): client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2075,7 +2431,9 @@ def test_get_entity_type( with mock.patch.object(type(client.transport.get_entity_type), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = entity_type.EntityType( - name="name_value", description="description_value", etag="etag_value", + name="name_value", + description="description_value", + etag="etag_value", ) response = client.get_entity_type(request) @@ -2091,15 +2449,12 @@ def test_get_entity_type( assert response.etag == "etag_value" -def test_get_entity_type_from_dict(): - test_get_entity_type(request_type=dict) - - def test_get_entity_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2116,7 +2471,8 @@ async def test_get_entity_type_async( request_type=featurestore_service.GetEntityTypeRequest, ): client = FeaturestoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2128,8 +2484,10 @@ async def test_get_entity_type_async( # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( entity_type.EntityType( - name="name_value", description="description_value", etag="etag_value", - ) + name="name_value", + description="description_value", + etag="etag_value", + ) ) response = await client.get_entity_type(request) @@ -2159,7 +2517,7 @@ def test_get_entity_type_field_headers(): # a field header. Set these to a non-empty value. request = featurestore_service.GetEntityTypeRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_entity_type), "__call__") as call: @@ -2173,7 +2531,10 @@ def test_get_entity_type_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2186,7 +2547,7 @@ async def test_get_entity_type_field_headers_async(): # a field header. Set these to a non-empty value. request = featurestore_service.GetEntityTypeRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_entity_type), "__call__") as call: @@ -2202,7 +2563,10 @@ async def test_get_entity_type_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_get_entity_type_flattened(): @@ -2216,13 +2580,17 @@ def test_get_entity_type_flattened(): call.return_value = entity_type.EntityType() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_entity_type(name="name_value",) + client.get_entity_type( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_entity_type_flattened_error(): @@ -2234,7 +2602,8 @@ def test_get_entity_type_flattened_error(): # fields is an error. with pytest.raises(ValueError): client.get_entity_type( - featurestore_service.GetEntityTypeRequest(), name="name_value", + featurestore_service.GetEntityTypeRequest(), + name="name_value", ) @@ -2254,13 +2623,17 @@ async def test_get_entity_type_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_entity_type(name="name_value",) + response = await client.get_entity_type( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -2273,15 +2646,22 @@ async def test_get_entity_type_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.get_entity_type( - featurestore_service.GetEntityTypeRequest(), name="name_value", + featurestore_service.GetEntityTypeRequest(), + name="name_value", ) -def test_list_entity_types( - transport: str = "grpc", request_type=featurestore_service.ListEntityTypesRequest -): +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.ListEntityTypesRequest, + dict, + ], +) +def test_list_entity_types(request_type, transport: str = "grpc"): client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2308,15 +2688,12 @@ def test_list_entity_types( assert response.next_page_token == "next_page_token_value" -def test_list_entity_types_from_dict(): - test_list_entity_types(request_type=dict) - - def test_list_entity_types_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2335,7 +2712,8 @@ async def test_list_entity_types_async( request_type=featurestore_service.ListEntityTypesRequest, ): client = FeaturestoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2378,7 +2756,7 @@ def test_list_entity_types_field_headers(): # a field header. Set these to a non-empty value. request = featurestore_service.ListEntityTypesRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2394,7 +2772,10 @@ def test_list_entity_types_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2407,7 +2788,7 @@ async def test_list_entity_types_field_headers_async(): # a field header. Set these to a non-empty value. request = featurestore_service.ListEntityTypesRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2425,7 +2806,10 @@ async def test_list_entity_types_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_entity_types_flattened(): @@ -2441,13 +2825,17 @@ def test_list_entity_types_flattened(): call.return_value = featurestore_service.ListEntityTypesResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_entity_types(parent="parent_value",) + client.list_entity_types( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_entity_types_flattened_error(): @@ -2459,7 +2847,8 @@ def test_list_entity_types_flattened_error(): # fields is an error. with pytest.raises(ValueError): client.list_entity_types( - featurestore_service.ListEntityTypesRequest(), parent="parent_value", + featurestore_service.ListEntityTypesRequest(), + parent="parent_value", ) @@ -2481,13 +2870,17 @@ async def test_list_entity_types_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_entity_types(parent="parent_value",) + response = await client.list_entity_types( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -2500,12 +2893,16 @@ async def test_list_entity_types_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.list_entity_types( - featurestore_service.ListEntityTypesRequest(), parent="parent_value", + featurestore_service.ListEntityTypesRequest(), + parent="parent_value", ) -def test_list_entity_types_pager(): - client = FeaturestoreServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_entity_types_pager(transport_name: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2522,13 +2919,20 @@ def test_list_entity_types_pager(): next_page_token="abc", ), featurestore_service.ListEntityTypesResponse( - entity_types=[], next_page_token="def", + entity_types=[], + next_page_token="def", ), featurestore_service.ListEntityTypesResponse( - entity_types=[entity_type.EntityType(),], next_page_token="ghi", + entity_types=[ + entity_type.EntityType(), + ], + next_page_token="ghi", ), featurestore_service.ListEntityTypesResponse( - entity_types=[entity_type.EntityType(), entity_type.EntityType(),], + entity_types=[ + entity_type.EntityType(), + entity_type.EntityType(), + ], ), RuntimeError, ) @@ -2541,13 +2945,16 @@ def test_list_entity_types_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all(isinstance(i, entity_type.EntityType) for i in results) -def test_list_entity_types_pages(): - client = FeaturestoreServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_entity_types_pages(transport_name: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2564,13 +2971,20 @@ def test_list_entity_types_pages(): next_page_token="abc", ), featurestore_service.ListEntityTypesResponse( - entity_types=[], next_page_token="def", + entity_types=[], + next_page_token="def", ), featurestore_service.ListEntityTypesResponse( - entity_types=[entity_type.EntityType(),], next_page_token="ghi", + entity_types=[ + entity_type.EntityType(), + ], + next_page_token="ghi", ), featurestore_service.ListEntityTypesResponse( - entity_types=[entity_type.EntityType(), entity_type.EntityType(),], + entity_types=[ + entity_type.EntityType(), + entity_type.EntityType(), + ], ), RuntimeError, ) @@ -2602,20 +3016,29 @@ async def test_list_entity_types_async_pager(): next_page_token="abc", ), featurestore_service.ListEntityTypesResponse( - entity_types=[], next_page_token="def", + entity_types=[], + next_page_token="def", ), featurestore_service.ListEntityTypesResponse( - entity_types=[entity_type.EntityType(),], next_page_token="ghi", + entity_types=[ + entity_type.EntityType(), + ], + next_page_token="ghi", ), featurestore_service.ListEntityTypesResponse( - entity_types=[entity_type.EntityType(), entity_type.EntityType(),], + entity_types=[ + entity_type.EntityType(), + entity_type.EntityType(), + ], ), RuntimeError, ) - async_pager = await client.list_entity_types(request={},) + async_pager = await client.list_entity_types( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -2645,28 +3068,43 @@ async def test_list_entity_types_async_pages(): next_page_token="abc", ), featurestore_service.ListEntityTypesResponse( - entity_types=[], next_page_token="def", + entity_types=[], + next_page_token="def", ), featurestore_service.ListEntityTypesResponse( - entity_types=[entity_type.EntityType(),], next_page_token="ghi", + entity_types=[ + entity_type.EntityType(), + ], + next_page_token="ghi", ), featurestore_service.ListEntityTypesResponse( - entity_types=[entity_type.EntityType(), entity_type.EntityType(),], + entity_types=[ + entity_type.EntityType(), + entity_type.EntityType(), + ], ), RuntimeError, ) pages = [] - async for page_ in (await client.list_entity_types(request={})).pages: + async for page_ in ( + await client.list_entity_types(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_update_entity_type( - transport: str = "grpc", request_type=featurestore_service.UpdateEntityTypeRequest -): +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.UpdateEntityTypeRequest, + dict, + ], +) +def test_update_entity_type(request_type, transport: str = "grpc"): client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2679,7 +3117,9 @@ def test_update_entity_type( ) as call: # Designate an appropriate return value for the call. call.return_value = gca_entity_type.EntityType( - name="name_value", description="description_value", etag="etag_value", + name="name_value", + description="description_value", + etag="etag_value", ) response = client.update_entity_type(request) @@ -2695,15 +3135,12 @@ def test_update_entity_type( assert response.etag == "etag_value" -def test_update_entity_type_from_dict(): - test_update_entity_type(request_type=dict) - - def test_update_entity_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2722,7 +3159,8 @@ async def test_update_entity_type_async( request_type=featurestore_service.UpdateEntityTypeRequest, ): client = FeaturestoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2736,7 +3174,9 @@ async def test_update_entity_type_async( # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gca_entity_type.EntityType( - name="name_value", description="description_value", etag="etag_value", + name="name_value", + description="description_value", + etag="etag_value", ) ) response = await client.update_entity_type(request) @@ -2767,7 +3207,7 @@ def test_update_entity_type_field_headers(): # a field header. Set these to a non-empty value. request = featurestore_service.UpdateEntityTypeRequest() - request.entity_type.name = "entity_type.name/value" + request.entity_type.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2783,9 +3223,10 @@ def test_update_entity_type_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "entity_type.name=entity_type.name/value",) in kw[ - "metadata" - ] + assert ( + "x-goog-request-params", + "entity_type.name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2798,7 +3239,7 @@ async def test_update_entity_type_field_headers_async(): # a field header. Set these to a non-empty value. request = featurestore_service.UpdateEntityTypeRequest() - request.entity_type.name = "entity_type.name/value" + request.entity_type.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2816,9 +3257,10 @@ async def test_update_entity_type_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "entity_type.name=entity_type.name/value",) in kw[ - "metadata" - ] + assert ( + "x-goog-request-params", + "entity_type.name=name_value", + ) in kw["metadata"] def test_update_entity_type_flattened(): @@ -2843,8 +3285,12 @@ def test_update_entity_type_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].entity_type == gca_entity_type.EntityType(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].entity_type + mock_val = gca_entity_type.EntityType(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val def test_update_entity_type_flattened_error(): @@ -2889,8 +3335,12 @@ async def test_update_entity_type_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].entity_type == gca_entity_type.EntityType(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].entity_type + mock_val = gca_entity_type.EntityType(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val @pytest.mark.asyncio @@ -2909,11 +3359,17 @@ async def test_update_entity_type_flattened_error_async(): ) -def test_delete_entity_type( - transport: str = "grpc", request_type=featurestore_service.DeleteEntityTypeRequest -): +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.DeleteEntityTypeRequest, + dict, + ], +) +def test_delete_entity_type(request_type, transport: str = "grpc"): client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2937,15 +3393,12 @@ def test_delete_entity_type( assert isinstance(response, future.Future) -def test_delete_entity_type_from_dict(): - test_delete_entity_type(request_type=dict) - - def test_delete_entity_type_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2964,7 +3417,8 @@ async def test_delete_entity_type_async( request_type=featurestore_service.DeleteEntityTypeRequest, ): client = FeaturestoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3004,7 +3458,7 @@ def test_delete_entity_type_field_headers(): # a field header. Set these to a non-empty value. request = featurestore_service.DeleteEntityTypeRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3020,7 +3474,10 @@ def test_delete_entity_type_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -3033,7 +3490,7 @@ async def test_delete_entity_type_field_headers_async(): # a field header. Set these to a non-empty value. request = featurestore_service.DeleteEntityTypeRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3051,7 +3508,10 @@ async def test_delete_entity_type_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_delete_entity_type_flattened(): @@ -3067,13 +3527,21 @@ def test_delete_entity_type_flattened(): call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_entity_type(name="name_value",) + client.delete_entity_type( + name="name_value", + force=True, + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].force + mock_val = True + assert arg == mock_val def test_delete_entity_type_flattened_error(): @@ -3085,7 +3553,9 @@ def test_delete_entity_type_flattened_error(): # fields is an error. with pytest.raises(ValueError): client.delete_entity_type( - featurestore_service.DeleteEntityTypeRequest(), name="name_value", + featurestore_service.DeleteEntityTypeRequest(), + name="name_value", + force=True, ) @@ -3107,13 +3577,21 @@ async def test_delete_entity_type_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_entity_type(name="name_value",) + response = await client.delete_entity_type( + name="name_value", + force=True, + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].force + mock_val = True + assert arg == mock_val @pytest.mark.asyncio @@ -3126,15 +3604,23 @@ async def test_delete_entity_type_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.delete_entity_type( - featurestore_service.DeleteEntityTypeRequest(), name="name_value", + featurestore_service.DeleteEntityTypeRequest(), + name="name_value", + force=True, ) -def test_create_feature( - transport: str = "grpc", request_type=featurestore_service.CreateFeatureRequest -): +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.CreateFeatureRequest, + dict, + ], +) +def test_create_feature(request_type, transport: str = "grpc"): client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3156,15 +3642,12 @@ def test_create_feature( assert isinstance(response, future.Future) -def test_create_feature_from_dict(): - test_create_feature(request_type=dict) - - def test_create_feature_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3181,7 +3664,8 @@ async def test_create_feature_async( request_type=featurestore_service.CreateFeatureRequest, ): client = FeaturestoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3219,7 +3703,7 @@ def test_create_feature_field_headers(): # a field header. Set these to a non-empty value. request = featurestore_service.CreateFeatureRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_feature), "__call__") as call: @@ -3233,7 +3717,10 @@ def test_create_feature_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -3246,7 +3733,7 @@ async def test_create_feature_field_headers_async(): # a field header. Set these to a non-empty value. request = featurestore_service.CreateFeatureRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_feature), "__call__") as call: @@ -3262,7 +3749,10 @@ async def test_create_feature_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_create_feature_flattened(): @@ -3277,15 +3767,24 @@ def test_create_feature_flattened(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.create_feature( - parent="parent_value", feature=gca_feature.Feature(name="name_value"), + parent="parent_value", + feature=gca_feature.Feature(name="name_value"), + feature_id="feature_id_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].feature == gca_feature.Feature(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].feature + mock_val = gca_feature.Feature(name="name_value") + assert arg == mock_val + arg = args[0].feature_id + mock_val = "feature_id_value" + assert arg == mock_val def test_create_feature_flattened_error(): @@ -3300,6 +3799,7 @@ def test_create_feature_flattened_error(): featurestore_service.CreateFeatureRequest(), parent="parent_value", feature=gca_feature.Feature(name="name_value"), + feature_id="feature_id_value", ) @@ -3320,15 +3820,24 @@ async def test_create_feature_flattened_async(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. response = await client.create_feature( - parent="parent_value", feature=gca_feature.Feature(name="name_value"), + parent="parent_value", + feature=gca_feature.Feature(name="name_value"), + feature_id="feature_id_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].feature == gca_feature.Feature(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].feature + mock_val = gca_feature.Feature(name="name_value") + assert arg == mock_val + arg = args[0].feature_id + mock_val = "feature_id_value" + assert arg == mock_val @pytest.mark.asyncio @@ -3344,15 +3853,21 @@ async def test_create_feature_flattened_error_async(): featurestore_service.CreateFeatureRequest(), parent="parent_value", feature=gca_feature.Feature(name="name_value"), + feature_id="feature_id_value", ) -def test_batch_create_features( - transport: str = "grpc", - request_type=featurestore_service.BatchCreateFeaturesRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.BatchCreateFeaturesRequest, + dict, + ], +) +def test_batch_create_features(request_type, transport: str = "grpc"): client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3376,15 +3891,12 @@ def test_batch_create_features( assert isinstance(response, future.Future) -def test_batch_create_features_from_dict(): - test_batch_create_features(request_type=dict) - - def test_batch_create_features_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3403,7 +3915,8 @@ async def test_batch_create_features_async( request_type=featurestore_service.BatchCreateFeaturesRequest, ): client = FeaturestoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3443,7 +3956,7 @@ def test_batch_create_features_field_headers(): # a field header. Set these to a non-empty value. request = featurestore_service.BatchCreateFeaturesRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3459,7 +3972,10 @@ def test_batch_create_features_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -3472,7 +3988,7 @@ async def test_batch_create_features_field_headers_async(): # a field header. Set these to a non-empty value. request = featurestore_service.BatchCreateFeaturesRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3490,7 +4006,10 @@ async def test_batch_create_features_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_batch_create_features_flattened(): @@ -3515,10 +4034,12 @@ def test_batch_create_features_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].requests == [ - featurestore_service.CreateFeatureRequest(parent="parent_value") - ] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].requests + mock_val = [featurestore_service.CreateFeatureRequest(parent="parent_value")] + assert arg == mock_val def test_batch_create_features_flattened_error(): @@ -3563,10 +4084,12 @@ async def test_batch_create_features_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].requests == [ - featurestore_service.CreateFeatureRequest(parent="parent_value") - ] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].requests + mock_val = [featurestore_service.CreateFeatureRequest(parent="parent_value")] + assert arg == mock_val @pytest.mark.asyncio @@ -3585,11 +4108,17 @@ async def test_batch_create_features_flattened_error_async(): ) -def test_get_feature( - transport: str = "grpc", request_type=featurestore_service.GetFeatureRequest -): +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.GetFeatureRequest, + dict, + ], +) +def test_get_feature(request_type, transport: str = "grpc"): client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3604,6 +4133,7 @@ def test_get_feature( description="description_value", value_type=feature.Feature.ValueType.BOOL, etag="etag_value", + disable_monitoring=True, ) response = client.get_feature(request) @@ -3618,17 +4148,15 @@ def test_get_feature( assert response.description == "description_value" assert response.value_type == feature.Feature.ValueType.BOOL assert response.etag == "etag_value" - - -def test_get_feature_from_dict(): - test_get_feature(request_type=dict) + assert response.disable_monitoring is True def test_get_feature_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3644,7 +4172,8 @@ async def test_get_feature_async( transport: str = "grpc_asyncio", request_type=featurestore_service.GetFeatureRequest ): client = FeaturestoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3660,6 +4189,7 @@ async def test_get_feature_async( description="description_value", value_type=feature.Feature.ValueType.BOOL, etag="etag_value", + disable_monitoring=True, ) ) response = await client.get_feature(request) @@ -3675,6 +4205,7 @@ async def test_get_feature_async( assert response.description == "description_value" assert response.value_type == feature.Feature.ValueType.BOOL assert response.etag == "etag_value" + assert response.disable_monitoring is True @pytest.mark.asyncio @@ -3691,7 +4222,7 @@ def test_get_feature_field_headers(): # a field header. Set these to a non-empty value. request = featurestore_service.GetFeatureRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_feature), "__call__") as call: @@ -3705,7 +4236,10 @@ def test_get_feature_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -3718,7 +4252,7 @@ async def test_get_feature_field_headers_async(): # a field header. Set these to a non-empty value. request = featurestore_service.GetFeatureRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_feature), "__call__") as call: @@ -3732,7 +4266,10 @@ async def test_get_feature_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_get_feature_flattened(): @@ -3746,13 +4283,17 @@ def test_get_feature_flattened(): call.return_value = feature.Feature() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_feature(name="name_value",) + client.get_feature( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_feature_flattened_error(): @@ -3764,7 +4305,8 @@ def test_get_feature_flattened_error(): # fields is an error. with pytest.raises(ValueError): client.get_feature( - featurestore_service.GetFeatureRequest(), name="name_value", + featurestore_service.GetFeatureRequest(), + name="name_value", ) @@ -3782,13 +4324,17 @@ async def test_get_feature_flattened_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(feature.Feature()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_feature(name="name_value",) + response = await client.get_feature( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -3801,15 +4347,22 @@ async def test_get_feature_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.get_feature( - featurestore_service.GetFeatureRequest(), name="name_value", + featurestore_service.GetFeatureRequest(), + name="name_value", ) -def test_list_features( - transport: str = "grpc", request_type=featurestore_service.ListFeaturesRequest -): +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.ListFeaturesRequest, + dict, + ], +) +def test_list_features(request_type, transport: str = "grpc"): client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3834,15 +4387,12 @@ def test_list_features( assert response.next_page_token == "next_page_token_value" -def test_list_features_from_dict(): - test_list_features(request_type=dict) - - def test_list_features_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3859,7 +4409,8 @@ async def test_list_features_async( request_type=featurestore_service.ListFeaturesRequest, ): client = FeaturestoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3900,7 +4451,7 @@ def test_list_features_field_headers(): # a field header. Set these to a non-empty value. request = featurestore_service.ListFeaturesRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_features), "__call__") as call: @@ -3914,7 +4465,10 @@ def test_list_features_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -3927,7 +4481,7 @@ async def test_list_features_field_headers_async(): # a field header. Set these to a non-empty value. request = featurestore_service.ListFeaturesRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_features), "__call__") as call: @@ -3943,7 +4497,10 @@ async def test_list_features_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_features_flattened(): @@ -3957,13 +4514,17 @@ def test_list_features_flattened(): call.return_value = featurestore_service.ListFeaturesResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_features(parent="parent_value",) + client.list_features( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_features_flattened_error(): @@ -3975,7 +4536,8 @@ def test_list_features_flattened_error(): # fields is an error. with pytest.raises(ValueError): client.list_features( - featurestore_service.ListFeaturesRequest(), parent="parent_value", + featurestore_service.ListFeaturesRequest(), + parent="parent_value", ) @@ -3995,13 +4557,17 @@ async def test_list_features_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_features(parent="parent_value",) + response = await client.list_features( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -4014,29 +4580,44 @@ async def test_list_features_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.list_features( - featurestore_service.ListFeaturesRequest(), parent="parent_value", + featurestore_service.ListFeaturesRequest(), + parent="parent_value", ) -def test_list_features_pager(): - client = FeaturestoreServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_features_pager(transport_name: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_features), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( featurestore_service.ListFeaturesResponse( - features=[feature.Feature(), feature.Feature(), feature.Feature(),], + features=[ + feature.Feature(), + feature.Feature(), + feature.Feature(), + ], next_page_token="abc", ), featurestore_service.ListFeaturesResponse( - features=[], next_page_token="def", + features=[], + next_page_token="def", ), featurestore_service.ListFeaturesResponse( - features=[feature.Feature(),], next_page_token="ghi", + features=[ + feature.Feature(), + ], + next_page_token="ghi", ), featurestore_service.ListFeaturesResponse( - features=[feature.Feature(), feature.Feature(),], + features=[ + feature.Feature(), + feature.Feature(), + ], ), RuntimeError, ) @@ -4049,30 +4630,44 @@ def test_list_features_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all(isinstance(i, feature.Feature) for i in results) -def test_list_features_pages(): - client = FeaturestoreServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_features_pages(transport_name: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_features), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( featurestore_service.ListFeaturesResponse( - features=[feature.Feature(), feature.Feature(), feature.Feature(),], + features=[ + feature.Feature(), + feature.Feature(), + feature.Feature(), + ], next_page_token="abc", ), featurestore_service.ListFeaturesResponse( - features=[], next_page_token="def", + features=[], + next_page_token="def", ), featurestore_service.ListFeaturesResponse( - features=[feature.Feature(),], next_page_token="ghi", + features=[ + feature.Feature(), + ], + next_page_token="ghi", ), featurestore_service.ListFeaturesResponse( - features=[feature.Feature(), feature.Feature(),], + features=[ + feature.Feature(), + feature.Feature(), + ], ), RuntimeError, ) @@ -4094,24 +4689,37 @@ async def test_list_features_async_pager(): # Set the response to a series of pages. call.side_effect = ( featurestore_service.ListFeaturesResponse( - features=[feature.Feature(), feature.Feature(), feature.Feature(),], + features=[ + feature.Feature(), + feature.Feature(), + feature.Feature(), + ], next_page_token="abc", ), featurestore_service.ListFeaturesResponse( - features=[], next_page_token="def", + features=[], + next_page_token="def", ), featurestore_service.ListFeaturesResponse( - features=[feature.Feature(),], next_page_token="ghi", + features=[ + feature.Feature(), + ], + next_page_token="ghi", ), featurestore_service.ListFeaturesResponse( - features=[feature.Feature(), feature.Feature(),], + features=[ + feature.Feature(), + feature.Feature(), + ], ), RuntimeError, ) - async_pager = await client.list_features(request={},) + async_pager = await client.list_features( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -4131,32 +4739,51 @@ async def test_list_features_async_pages(): # Set the response to a series of pages. call.side_effect = ( featurestore_service.ListFeaturesResponse( - features=[feature.Feature(), feature.Feature(), feature.Feature(),], + features=[ + feature.Feature(), + feature.Feature(), + feature.Feature(), + ], next_page_token="abc", ), featurestore_service.ListFeaturesResponse( - features=[], next_page_token="def", + features=[], + next_page_token="def", ), featurestore_service.ListFeaturesResponse( - features=[feature.Feature(),], next_page_token="ghi", + features=[ + feature.Feature(), + ], + next_page_token="ghi", ), featurestore_service.ListFeaturesResponse( - features=[feature.Feature(), feature.Feature(),], + features=[ + feature.Feature(), + feature.Feature(), + ], ), RuntimeError, ) pages = [] - async for page_ in (await client.list_features(request={})).pages: + async for page_ in ( + await client.list_features(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_update_feature( - transport: str = "grpc", request_type=featurestore_service.UpdateFeatureRequest -): +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.UpdateFeatureRequest, + dict, + ], +) +def test_update_feature(request_type, transport: str = "grpc"): client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4171,6 +4798,7 @@ def test_update_feature( description="description_value", value_type=gca_feature.Feature.ValueType.BOOL, etag="etag_value", + disable_monitoring=True, ) response = client.update_feature(request) @@ -4185,17 +4813,15 @@ def test_update_feature( assert response.description == "description_value" assert response.value_type == gca_feature.Feature.ValueType.BOOL assert response.etag == "etag_value" - - -def test_update_feature_from_dict(): - test_update_feature(request_type=dict) + assert response.disable_monitoring is True def test_update_feature_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4212,7 +4838,8 @@ async def test_update_feature_async( request_type=featurestore_service.UpdateFeatureRequest, ): client = FeaturestoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4228,6 +4855,7 @@ async def test_update_feature_async( description="description_value", value_type=gca_feature.Feature.ValueType.BOOL, etag="etag_value", + disable_monitoring=True, ) ) response = await client.update_feature(request) @@ -4243,6 +4871,7 @@ async def test_update_feature_async( assert response.description == "description_value" assert response.value_type == gca_feature.Feature.ValueType.BOOL assert response.etag == "etag_value" + assert response.disable_monitoring is True @pytest.mark.asyncio @@ -4259,7 +4888,7 @@ def test_update_feature_field_headers(): # a field header. Set these to a non-empty value. request = featurestore_service.UpdateFeatureRequest() - request.feature.name = "feature.name/value" + request.feature.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_feature), "__call__") as call: @@ -4273,9 +4902,10 @@ def test_update_feature_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "feature.name=feature.name/value",) in kw[ - "metadata" - ] + assert ( + "x-goog-request-params", + "feature.name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -4288,7 +4918,7 @@ async def test_update_feature_field_headers_async(): # a field header. Set these to a non-empty value. request = featurestore_service.UpdateFeatureRequest() - request.feature.name = "feature.name/value" + request.feature.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_feature), "__call__") as call: @@ -4302,9 +4932,10 @@ async def test_update_feature_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "feature.name=feature.name/value",) in kw[ - "metadata" - ] + assert ( + "x-goog-request-params", + "feature.name=name_value", + ) in kw["metadata"] def test_update_feature_flattened(): @@ -4327,8 +4958,12 @@ def test_update_feature_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].feature == gca_feature.Feature(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].feature + mock_val = gca_feature.Feature(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val def test_update_feature_flattened_error(): @@ -4369,8 +5004,12 @@ async def test_update_feature_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].feature == gca_feature.Feature(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].feature + mock_val = gca_feature.Feature(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val @pytest.mark.asyncio @@ -4389,11 +5028,17 @@ async def test_update_feature_flattened_error_async(): ) -def test_delete_feature( - transport: str = "grpc", request_type=featurestore_service.DeleteFeatureRequest -): +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.DeleteFeatureRequest, + dict, + ], +) +def test_delete_feature(request_type, transport: str = "grpc"): client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4415,15 +5060,12 @@ def test_delete_feature( assert isinstance(response, future.Future) -def test_delete_feature_from_dict(): - test_delete_feature(request_type=dict) - - def test_delete_feature_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4440,7 +5082,8 @@ async def test_delete_feature_async( request_type=featurestore_service.DeleteFeatureRequest, ): client = FeaturestoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4478,7 +5121,7 @@ def test_delete_feature_field_headers(): # a field header. Set these to a non-empty value. request = featurestore_service.DeleteFeatureRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_feature), "__call__") as call: @@ -4492,7 +5135,10 @@ def test_delete_feature_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -4505,7 +5151,7 @@ async def test_delete_feature_field_headers_async(): # a field header. Set these to a non-empty value. request = featurestore_service.DeleteFeatureRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_feature), "__call__") as call: @@ -4521,8 +5167,11 @@ async def test_delete_feature_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] - + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + def test_delete_feature_flattened(): client = FeaturestoreServiceClient( @@ -4535,13 +5184,17 @@ def test_delete_feature_flattened(): call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_feature(name="name_value",) + client.delete_feature( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_delete_feature_flattened_error(): @@ -4553,7 +5206,8 @@ def test_delete_feature_flattened_error(): # fields is an error. with pytest.raises(ValueError): client.delete_feature( - featurestore_service.DeleteFeatureRequest(), name="name_value", + featurestore_service.DeleteFeatureRequest(), + name="name_value", ) @@ -4573,13 +5227,17 @@ async def test_delete_feature_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_feature(name="name_value",) + response = await client.delete_feature( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -4592,16 +5250,22 @@ async def test_delete_feature_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.delete_feature( - featurestore_service.DeleteFeatureRequest(), name="name_value", + featurestore_service.DeleteFeatureRequest(), + name="name_value", ) -def test_import_feature_values( - transport: str = "grpc", - request_type=featurestore_service.ImportFeatureValuesRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.ImportFeatureValuesRequest, + dict, + ], +) +def test_import_feature_values(request_type, transport: str = "grpc"): client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4625,15 +5289,12 @@ def test_import_feature_values( assert isinstance(response, future.Future) -def test_import_feature_values_from_dict(): - test_import_feature_values(request_type=dict) - - def test_import_feature_values_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4652,7 +5313,8 @@ async def test_import_feature_values_async( request_type=featurestore_service.ImportFeatureValuesRequest, ): client = FeaturestoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4692,7 +5354,7 @@ def test_import_feature_values_field_headers(): # a field header. Set these to a non-empty value. request = featurestore_service.ImportFeatureValuesRequest() - request.entity_type = "entity_type/value" + request.entity_type = "entity_type_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4708,7 +5370,10 @@ def test_import_feature_values_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "entity_type=entity_type/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "entity_type=entity_type_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -4721,7 +5386,7 @@ async def test_import_feature_values_field_headers_async(): # a field header. Set these to a non-empty value. request = featurestore_service.ImportFeatureValuesRequest() - request.entity_type = "entity_type/value" + request.entity_type = "entity_type_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4739,7 +5404,10 @@ async def test_import_feature_values_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "entity_type=entity_type/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "entity_type=entity_type_value", + ) in kw["metadata"] def test_import_feature_values_flattened(): @@ -4755,13 +5423,17 @@ def test_import_feature_values_flattened(): call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.import_feature_values(entity_type="entity_type_value",) + client.import_feature_values( + entity_type="entity_type_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].entity_type == "entity_type_value" + arg = args[0].entity_type + mock_val = "entity_type_value" + assert arg == mock_val def test_import_feature_values_flattened_error(): @@ -4796,13 +5468,17 @@ async def test_import_feature_values_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.import_feature_values(entity_type="entity_type_value",) + response = await client.import_feature_values( + entity_type="entity_type_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].entity_type == "entity_type_value" + arg = args[0].entity_type + mock_val = "entity_type_value" + assert arg == mock_val @pytest.mark.asyncio @@ -4820,12 +5496,17 @@ async def test_import_feature_values_flattened_error_async(): ) -def test_batch_read_feature_values( - transport: str = "grpc", - request_type=featurestore_service.BatchReadFeatureValuesRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.BatchReadFeatureValuesRequest, + dict, + ], +) +def test_batch_read_feature_values(request_type, transport: str = "grpc"): client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4849,15 +5530,12 @@ def test_batch_read_feature_values( assert isinstance(response, future.Future) -def test_batch_read_feature_values_from_dict(): - test_batch_read_feature_values(request_type=dict) - - def test_batch_read_feature_values_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4876,7 +5554,8 @@ async def test_batch_read_feature_values_async( request_type=featurestore_service.BatchReadFeatureValuesRequest, ): client = FeaturestoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4916,7 +5595,7 @@ def test_batch_read_feature_values_field_headers(): # a field header. Set these to a non-empty value. request = featurestore_service.BatchReadFeatureValuesRequest() - request.featurestore = "featurestore/value" + request.featurestore = "featurestore_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4932,9 +5611,10 @@ def test_batch_read_feature_values_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "featurestore=featurestore/value",) in kw[ - "metadata" - ] + assert ( + "x-goog-request-params", + "featurestore=featurestore_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -4947,7 +5627,7 @@ async def test_batch_read_feature_values_field_headers_async(): # a field header. Set these to a non-empty value. request = featurestore_service.BatchReadFeatureValuesRequest() - request.featurestore = "featurestore/value" + request.featurestore = "featurestore_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4965,9 +5645,10 @@ async def test_batch_read_feature_values_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "featurestore=featurestore/value",) in kw[ - "metadata" - ] + assert ( + "x-goog-request-params", + "featurestore=featurestore_value", + ) in kw["metadata"] def test_batch_read_feature_values_flattened(): @@ -4983,13 +5664,17 @@ def test_batch_read_feature_values_flattened(): call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.batch_read_feature_values(featurestore="featurestore_value",) + client.batch_read_feature_values( + featurestore="featurestore_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].featurestore == "featurestore_value" + arg = args[0].featurestore + mock_val = "featurestore_value" + assert arg == mock_val def test_batch_read_feature_values_flattened_error(): @@ -5032,7 +5717,9 @@ async def test_batch_read_feature_values_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].featurestore == "featurestore_value" + arg = args[0].featurestore + mock_val = "featurestore_value" + assert arg == mock_val @pytest.mark.asyncio @@ -5050,12 +5737,17 @@ async def test_batch_read_feature_values_flattened_error_async(): ) -def test_export_feature_values( - transport: str = "grpc", - request_type=featurestore_service.ExportFeatureValuesRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.ExportFeatureValuesRequest, + dict, + ], +) +def test_export_feature_values(request_type, transport: str = "grpc"): client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5079,15 +5771,12 @@ def test_export_feature_values( assert isinstance(response, future.Future) -def test_export_feature_values_from_dict(): - test_export_feature_values(request_type=dict) - - def test_export_feature_values_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5106,7 +5795,8 @@ async def test_export_feature_values_async( request_type=featurestore_service.ExportFeatureValuesRequest, ): client = FeaturestoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5146,7 +5836,7 @@ def test_export_feature_values_field_headers(): # a field header. Set these to a non-empty value. request = featurestore_service.ExportFeatureValuesRequest() - request.entity_type = "entity_type/value" + request.entity_type = "entity_type_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5162,7 +5852,10 @@ def test_export_feature_values_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "entity_type=entity_type/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "entity_type=entity_type_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -5175,7 +5868,7 @@ async def test_export_feature_values_field_headers_async(): # a field header. Set these to a non-empty value. request = featurestore_service.ExportFeatureValuesRequest() - request.entity_type = "entity_type/value" + request.entity_type = "entity_type_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5193,7 +5886,10 @@ async def test_export_feature_values_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "entity_type=entity_type/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "entity_type=entity_type_value", + ) in kw["metadata"] def test_export_feature_values_flattened(): @@ -5209,13 +5905,17 @@ def test_export_feature_values_flattened(): call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.export_feature_values(entity_type="entity_type_value",) + client.export_feature_values( + entity_type="entity_type_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].entity_type == "entity_type_value" + arg = args[0].entity_type + mock_val = "entity_type_value" + assert arg == mock_val def test_export_feature_values_flattened_error(): @@ -5250,13 +5950,17 @@ async def test_export_feature_values_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.export_feature_values(entity_type="entity_type_value",) + response = await client.export_feature_values( + entity_type="entity_type_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].entity_type == "entity_type_value" + arg = args[0].entity_type + mock_val = "entity_type_value" + assert arg == mock_val @pytest.mark.asyncio @@ -5274,11 +5978,17 @@ async def test_export_feature_values_flattened_error_async(): ) -def test_search_features( - transport: str = "grpc", request_type=featurestore_service.SearchFeaturesRequest -): +@pytest.mark.parametrize( + "request_type", + [ + featurestore_service.SearchFeaturesRequest, + dict, + ], +) +def test_search_features(request_type, transport: str = "grpc"): client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5303,15 +6013,12 @@ def test_search_features( assert response.next_page_token == "next_page_token_value" -def test_search_features_from_dict(): - test_search_features(request_type=dict) - - def test_search_features_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5328,7 +6035,8 @@ async def test_search_features_async( request_type=featurestore_service.SearchFeaturesRequest, ): client = FeaturestoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5369,7 +6077,7 @@ def test_search_features_field_headers(): # a field header. Set these to a non-empty value. request = featurestore_service.SearchFeaturesRequest() - request.location = "location/value" + request.location = "location_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.search_features), "__call__") as call: @@ -5383,7 +6091,10 @@ def test_search_features_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "location=location/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "location=location_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -5396,7 +6107,7 @@ async def test_search_features_field_headers_async(): # a field header. Set these to a non-empty value. request = featurestore_service.SearchFeaturesRequest() - request.location = "location/value" + request.location = "location_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.search_features), "__call__") as call: @@ -5412,7 +6123,10 @@ async def test_search_features_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "location=location/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "location=location_value", + ) in kw["metadata"] def test_search_features_flattened(): @@ -5426,13 +6140,21 @@ def test_search_features_flattened(): call.return_value = featurestore_service.SearchFeaturesResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.search_features(location="location_value",) + client.search_features( + location="location_value", + query="query_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].location == "location_value" + arg = args[0].location + mock_val = "location_value" + assert arg == mock_val + arg = args[0].query + mock_val = "query_value" + assert arg == mock_val def test_search_features_flattened_error(): @@ -5444,7 +6166,9 @@ def test_search_features_flattened_error(): # fields is an error. with pytest.raises(ValueError): client.search_features( - featurestore_service.SearchFeaturesRequest(), location="location_value", + featurestore_service.SearchFeaturesRequest(), + location="location_value", + query="query_value", ) @@ -5464,13 +6188,21 @@ async def test_search_features_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.search_features(location="location_value",) + response = await client.search_features( + location="location_value", + query="query_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].location == "location_value" + arg = args[0].location + mock_val = "location_value" + assert arg == mock_val + arg = args[0].query + mock_val = "query_value" + assert arg == mock_val @pytest.mark.asyncio @@ -5483,29 +6215,45 @@ async def test_search_features_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.search_features( - featurestore_service.SearchFeaturesRequest(), location="location_value", + featurestore_service.SearchFeaturesRequest(), + location="location_value", + query="query_value", ) -def test_search_features_pager(): - client = FeaturestoreServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_search_features_pager(transport_name: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.search_features), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( featurestore_service.SearchFeaturesResponse( - features=[feature.Feature(), feature.Feature(), feature.Feature(),], + features=[ + feature.Feature(), + feature.Feature(), + feature.Feature(), + ], next_page_token="abc", ), featurestore_service.SearchFeaturesResponse( - features=[], next_page_token="def", + features=[], + next_page_token="def", ), featurestore_service.SearchFeaturesResponse( - features=[feature.Feature(),], next_page_token="ghi", + features=[ + feature.Feature(), + ], + next_page_token="ghi", ), featurestore_service.SearchFeaturesResponse( - features=[feature.Feature(), feature.Feature(),], + features=[ + feature.Feature(), + feature.Feature(), + ], ), RuntimeError, ) @@ -5518,30 +6266,44 @@ def test_search_features_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all(isinstance(i, feature.Feature) for i in results) -def test_search_features_pages(): - client = FeaturestoreServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_search_features_pages(transport_name: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.search_features), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( featurestore_service.SearchFeaturesResponse( - features=[feature.Feature(), feature.Feature(), feature.Feature(),], + features=[ + feature.Feature(), + feature.Feature(), + feature.Feature(), + ], next_page_token="abc", ), featurestore_service.SearchFeaturesResponse( - features=[], next_page_token="def", + features=[], + next_page_token="def", ), featurestore_service.SearchFeaturesResponse( - features=[feature.Feature(),], next_page_token="ghi", + features=[ + feature.Feature(), + ], + next_page_token="ghi", ), featurestore_service.SearchFeaturesResponse( - features=[feature.Feature(), feature.Feature(),], + features=[ + feature.Feature(), + feature.Feature(), + ], ), RuntimeError, ) @@ -5563,24 +6325,37 @@ async def test_search_features_async_pager(): # Set the response to a series of pages. call.side_effect = ( featurestore_service.SearchFeaturesResponse( - features=[feature.Feature(), feature.Feature(), feature.Feature(),], + features=[ + feature.Feature(), + feature.Feature(), + feature.Feature(), + ], next_page_token="abc", ), featurestore_service.SearchFeaturesResponse( - features=[], next_page_token="def", + features=[], + next_page_token="def", ), featurestore_service.SearchFeaturesResponse( - features=[feature.Feature(),], next_page_token="ghi", + features=[ + feature.Feature(), + ], + next_page_token="ghi", ), featurestore_service.SearchFeaturesResponse( - features=[feature.Feature(), feature.Feature(),], + features=[ + feature.Feature(), + feature.Feature(), + ], ), RuntimeError, ) - async_pager = await client.search_features(request={},) + async_pager = await client.search_features( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -5600,22 +6375,35 @@ async def test_search_features_async_pages(): # Set the response to a series of pages. call.side_effect = ( featurestore_service.SearchFeaturesResponse( - features=[feature.Feature(), feature.Feature(), feature.Feature(),], + features=[ + feature.Feature(), + feature.Feature(), + feature.Feature(), + ], next_page_token="abc", ), featurestore_service.SearchFeaturesResponse( - features=[], next_page_token="def", + features=[], + next_page_token="def", ), featurestore_service.SearchFeaturesResponse( - features=[feature.Feature(),], next_page_token="ghi", + features=[ + feature.Feature(), + ], + next_page_token="ghi", ), featurestore_service.SearchFeaturesResponse( - features=[feature.Feature(), feature.Feature(),], + features=[ + feature.Feature(), + feature.Feature(), + ], ), RuntimeError, ) pages = [] - async for page_ in (await client.search_features(request={})).pages: + async for page_ in ( + await client.search_features(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token @@ -5628,7 +6416,8 @@ def test_credentials_transport_error(): ) with pytest.raises(ValueError): client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # It is an error to provide a credentials file and a transport instance. @@ -5641,13 +6430,34 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.FeaturestoreServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = FeaturestoreServiceClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = FeaturestoreServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.FeaturestoreServiceGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = FeaturestoreServiceClient( - client_options={"scopes": ["1", "2"]}, transport=transport, + client_options={"scopes": ["1", "2"]}, + transport=transport, ) @@ -5690,12 +6500,28 @@ def test_transport_adc(transport_class): adc.assert_called_once() +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = FeaturestoreServiceClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = FeaturestoreServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) - assert isinstance(client.transport, transports.FeaturestoreServiceGrpcTransport,) + assert isinstance( + client.transport, + transports.FeaturestoreServiceGrpcTransport, + ) def test_featurestore_service_base_transport_error(): @@ -5740,18 +6566,38 @@ def test_featurestore_service_base_transport(): "batch_read_feature_values", "export_feature_values", "search_features", + "set_iam_policy", + "get_iam_policy", + "test_iam_permissions", + "get_location", + "list_locations", + "get_operation", + "wait_operation", + "cancel_operation", + "delete_operation", + "list_operations", ) for method in methods: with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + # Additionally, the LRO client (a property) should # also raise NotImplementedError with pytest.raises(NotImplementedError): transport.operations_client + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + -@requires_google_auth_gte_1_25_0 def test_featurestore_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -5762,7 +6608,8 @@ def test_featurestore_service_base_transport_with_credentials_file(): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.FeaturestoreServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", + credentials_file="credentials.json", + quota_project_id="octopus", ) load_creds.assert_called_once_with( "credentials.json", @@ -5772,26 +6619,6 @@ def test_featurestore_service_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_featurestore_service_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.aiplatform_v1beta1.services.featurestore_service.transports.FeaturestoreServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.FeaturestoreServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - def test_featurestore_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( @@ -5803,7 +6630,6 @@ def test_featurestore_service_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_featurestore_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -5816,18 +6642,6 @@ def test_featurestore_service_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_featurestore_service_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - FeaturestoreServiceClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -5835,7 +6649,6 @@ def test_featurestore_service_auth_adc_old_google_auth(): transports.FeaturestoreServiceGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_featurestore_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -5849,26 +6662,6 @@ def test_featurestore_service_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.FeaturestoreServiceGrpcTransport, - transports.FeaturestoreServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_featurestore_service_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ @@ -5876,7 +6669,6 @@ def test_featurestore_service_transport_auth_adc_old_google_auth(transport_class (transports.FeaturestoreServiceGrpcAsyncIOTransport, grpc_helpers_async), ], ) -@requires_api_core_gte_1_26_0 def test_featurestore_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -5905,79 +6697,6 @@ def test_featurestore_service_transport_create_channel(transport_class, grpc_hel ) -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.FeaturestoreServiceGrpcTransport, grpc_helpers), - (transports.FeaturestoreServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_featurestore_service_transport_create_channel_old_api_core( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class(quota_project_id="octopus") - - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.FeaturestoreServiceGrpcTransport, grpc_helpers), - (transports.FeaturestoreServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_featurestore_service_transport_create_channel_user_scopes( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=["1", "2"], - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -6002,7 +6721,7 @@ def test_featurestore_service_grpc_transport_client_cert_source_for_mtls( "squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_channel_creds, quota_project_id=None, options=[ @@ -6025,24 +6744,40 @@ def test_featurestore_service_grpc_transport_client_cert_source_for_mtls( ) -def test_featurestore_service_host_no_port(): - client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_featurestore_service_host_no_port(transport_name): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="aiplatform.googleapis.com" ), + transport=transport_name, ) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") -def test_featurestore_service_host_with_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_featurestore_service_host_with_port(transport_name): client = FeaturestoreServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="aiplatform.googleapis.com:8000" ), + transport=transport_name, ) - assert client.transport._host == "aiplatform.googleapis.com:8000" + assert client.transport._host == ("aiplatform.googleapis.com:8000") def test_featurestore_service_grpc_transport_channel(): @@ -6050,7 +6785,8 @@ def test_featurestore_service_grpc_transport_channel(): # Check that channel is used if provided. transport = transports.FeaturestoreServiceGrpcTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -6062,7 +6798,8 @@ def test_featurestore_service_grpc_asyncio_transport_channel(): # Check that channel is used if provided. transport = transports.FeaturestoreServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -6111,7 +6848,7 @@ def test_featurestore_service_transport_channel_mtls_with_client_cert_source( "mtls.squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -6158,7 +6895,7 @@ def test_featurestore_service_transport_channel_mtls_with_adc(transport_class): "mtls.squid.clam.whelk:443", credentials=mock_cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -6171,12 +6908,16 @@ def test_featurestore_service_transport_channel_mtls_with_adc(transport_class): def test_featurestore_service_grpc_lro_client(): client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -6184,12 +6925,16 @@ def test_featurestore_service_grpc_lro_client(): def test_featurestore_service_grpc_lro_async_client(): client = FeaturestoreServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -6264,8 +7009,12 @@ def test_featurestore_path(): project = "cuttlefish" location = "mussel" featurestore = "winkle" - expected = "projects/{project}/locations/{location}/featurestores/{featurestore}".format( - project=project, location=location, featurestore=featurestore, + expected = ( + "projects/{project}/locations/{location}/featurestores/{featurestore}".format( + project=project, + location=location, + featurestore=featurestore, + ) ) actual = FeaturestoreServiceClient.featurestore_path( project, location, featurestore @@ -6308,7 +7057,9 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "whelk" - expected = "folders/{folder}".format(folder=folder,) + expected = "folders/{folder}".format( + folder=folder, + ) actual = FeaturestoreServiceClient.common_folder_path(folder) assert expected == actual @@ -6326,7 +7077,9 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "oyster" - expected = "organizations/{organization}".format(organization=organization,) + expected = "organizations/{organization}".format( + organization=organization, + ) actual = FeaturestoreServiceClient.common_organization_path(organization) assert expected == actual @@ -6344,7 +7097,9 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "cuttlefish" - expected = "projects/{project}".format(project=project,) + expected = "projects/{project}".format( + project=project, + ) actual = FeaturestoreServiceClient.common_project_path(project) assert expected == actual @@ -6364,7 +7119,8 @@ def test_common_location_path(): project = "winkle" location = "nautilus" expected = "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) actual = FeaturestoreServiceClient.common_location_path(project, location) assert expected == actual @@ -6382,14 +7138,15 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( transports.FeaturestoreServiceTransport, "_prep_wrapped_messages" ) as prep: client = FeaturestoreServiceClient( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -6398,6 +7155,1598 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = FeaturestoreServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_delete_operation(transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_operation(transport: str = "grpc"): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_operation_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = None + + client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_operation_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_delete_operation_from_dict(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_delete_operation_from_dict_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_cancel_operation(transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation(transport: str = "grpc"): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_wait_operation(transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_wait_operation(transport: str = "grpc"): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_wait_operation_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_wait_operation_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_wait_operation_from_dict(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_wait_operation_from_dict_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_operation(transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_get_operation(transport: str = "grpc"): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_get_operation_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_get_operation_from_dict(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_operations(transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + response = client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +@pytest.mark.asyncio +async def test_list_operations(transport: str = "grpc"): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +def test_list_operations_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_operations_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_operations_from_dict(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + response = client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_operations_from_dict_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_locations(transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + response = client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +@pytest.mark.asyncio +async def test_list_locations(transport: str = "grpc"): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +def test_list_locations_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_locations_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_locations_from_dict(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + response = client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_locations_from_dict_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_location(transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + response = client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +@pytest.mark.asyncio +async def test_get_location_async(transport: str = "grpc_asyncio"): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +def test_get_location_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials() + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = locations_pb2.Location() + + client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_location_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials() + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +def test_get_location_from_dict(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + response = client.get_location( + request={ + "name": "locations/abc", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_location_from_dict_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_set_iam_policy(transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + response = client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + response = await client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_set_iam_policy_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_set_iam_policy_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_set_iam_policy_from_dict(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_set_iam_policy_from_dict_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +def test_get_iam_policy(transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + + response = client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + + response = await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_get_iam_policy_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_iam_policy_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_get_iam_policy_from_dict(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_iam_policy_from_dict_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +def test_test_iam_permissions(transport: str = "grpc"): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + + response = client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + ) + + response = await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +def test_test_iam_permissions_field_headers(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_field_headers_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_test_iam_permissions_from_dict(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + response = client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_from_dict_async(): + client = FeaturestoreServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + response = await client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = FeaturestoreServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (FeaturestoreServiceClient, transports.FeaturestoreServiceGrpcTransport), + ( + FeaturestoreServiceAsyncClient, + transports.FeaturestoreServiceGrpcAsyncIOTransport, + ), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) diff --git a/tests/unit/gapic/aiplatform_v1beta1/test_index_endpoint_service.py b/tests/unit/gapic/aiplatform_v1beta1/test_index_endpoint_service.py index 8387d2a3b1..18400bae05 100644 --- a/tests/unit/gapic/aiplatform_v1beta1/test_index_endpoint_service.py +++ b/tests/unit/gapic/aiplatform_v1beta1/test_index_endpoint_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,8 +14,13 @@ # limitations under the License. # import os -import mock -import packaging.version + +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock +except ImportError: + import mock import grpc from grpc.experimental import aio @@ -30,8 +35,10 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.aiplatform_v1beta1.services.index_endpoint_service import ( @@ -42,17 +49,16 @@ ) from google.cloud.aiplatform_v1beta1.services.index_endpoint_service import pagers from google.cloud.aiplatform_v1beta1.services.index_endpoint_service import transports -from google.cloud.aiplatform_v1beta1.services.index_endpoint_service.transports.base import ( - _API_CORE_VERSION, -) -from google.cloud.aiplatform_v1beta1.services.index_endpoint_service.transports.base import ( - _GOOGLE_AUTH_VERSION, -) +from google.cloud.aiplatform_v1beta1.types import accelerator_type from google.cloud.aiplatform_v1beta1.types import index_endpoint from google.cloud.aiplatform_v1beta1.types import index_endpoint as gca_index_endpoint from google.cloud.aiplatform_v1beta1.types import index_endpoint_service from google.cloud.aiplatform_v1beta1.types import machine_resources from google.cloud.aiplatform_v1beta1.types import operation as gca_operation +from google.cloud.location import locations_pb2 +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 from google.oauth2 import service_account from google.protobuf import field_mask_pb2 # type: ignore @@ -60,29 +66,6 @@ import google.auth -# TODO(busunkim): Once google-api-core >= 1.26.0 is required: -# - Delete all the api-core and auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - -requires_api_core_lt_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), - reason="This test requires google-api-core < 1.26.0", -) - -requires_api_core_gte_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), - reason="This test requires google-api-core >= 1.26.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -129,40 +112,81 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( - "client_class", [IndexEndpointServiceClient, IndexEndpointServiceAsyncClient,] + "client_class,transport_name", + [ + (IndexEndpointServiceClient, "grpc"), + (IndexEndpointServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_index_endpoint_service_client_from_service_account_info(client_class): +def test_index_endpoint_service_client_from_service_account_info( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.IndexEndpointServiceGrpcTransport, "grpc"), + (transports.IndexEndpointServiceGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_index_endpoint_service_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() @pytest.mark.parametrize( - "client_class", [IndexEndpointServiceClient, IndexEndpointServiceAsyncClient,] + "client_class,transport_name", + [ + (IndexEndpointServiceClient, "grpc"), + (IndexEndpointServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_index_endpoint_service_client_from_service_account_file(client_class): +def test_index_endpoint_service_client_from_service_account_file( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") def test_index_endpoint_service_client_get_transport_class(): @@ -219,7 +243,7 @@ def test_index_endpoint_service_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -228,6 +252,7 @@ def test_index_endpoint_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -235,7 +260,7 @@ def test_index_endpoint_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -244,6 +269,7 @@ def test_index_endpoint_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -251,7 +277,7 @@ def test_index_endpoint_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -260,26 +286,27 @@ def test_index_endpoint_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -288,6 +315,7 @@ def test_index_endpoint_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -347,7 +375,7 @@ def test_index_endpoint_service_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -364,6 +392,7 @@ def test_index_endpoint_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case ADC client cert is provided. Whether client cert is used depends on @@ -388,7 +417,7 @@ def test_index_endpoint_service_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -397,6 +426,7 @@ def test_index_endpoint_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case client_cert_source and ADC client cert are not provided. @@ -409,7 +439,7 @@ def test_index_endpoint_service_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -418,9 +448,91 @@ def test_index_endpoint_service_client_mtls_env_auto( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) +@pytest.mark.parametrize( + "client_class", [IndexEndpointServiceClient, IndexEndpointServiceAsyncClient] +) +@mock.patch.object( + IndexEndpointServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(IndexEndpointServiceClient), +) +@mock.patch.object( + IndexEndpointServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(IndexEndpointServiceAsyncClient), +) +def test_index_endpoint_service_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + @pytest.mark.parametrize( "client_class,transport_class,transport_name", [ @@ -440,10 +552,12 @@ def test_index_endpoint_service_client_client_options_scopes( client_class, transport_class, transport_name ): # Check the case scopes are provided. - options = client_options.ClientOptions(scopes=["1", "2"],) + options = client_options.ClientOptions( + scopes=["1", "2"], + ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -452,32 +566,36 @@ def test_index_endpoint_service_client_client_options_scopes( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ ( IndexEndpointServiceClient, transports.IndexEndpointServiceGrpcTransport, "grpc", + grpc_helpers, ), ( IndexEndpointServiceAsyncClient, transports.IndexEndpointServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_index_endpoint_service_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -486,6 +604,7 @@ def test_index_endpoint_service_client_client_options_credentials_file( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -505,15 +624,87 @@ def test_index_endpoint_service_client_client_options_from_dict(): client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) -def test_create_index_endpoint( - transport: str = "grpc", - request_type=index_endpoint_service.CreateIndexEndpointRequest, +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + IndexEndpointServiceClient, + transports.IndexEndpointServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + IndexEndpointServiceAsyncClient, + transports.IndexEndpointServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_index_endpoint_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers ): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + index_endpoint_service.CreateIndexEndpointRequest, + dict, + ], +) +def test_create_index_endpoint(request_type, transport: str = "grpc"): client = IndexEndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -537,15 +728,12 @@ def test_create_index_endpoint( assert isinstance(response, future.Future) -def test_create_index_endpoint_from_dict(): - test_create_index_endpoint(request_type=dict) - - def test_create_index_endpoint_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IndexEndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -564,7 +752,8 @@ async def test_create_index_endpoint_async( request_type=index_endpoint_service.CreateIndexEndpointRequest, ): client = IndexEndpointServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -604,7 +793,7 @@ def test_create_index_endpoint_field_headers(): # a field header. Set these to a non-empty value. request = index_endpoint_service.CreateIndexEndpointRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -620,7 +809,10 @@ def test_create_index_endpoint_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -633,7 +825,7 @@ async def test_create_index_endpoint_field_headers_async(): # a field header. Set these to a non-empty value. request = index_endpoint_service.CreateIndexEndpointRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -651,7 +843,10 @@ async def test_create_index_endpoint_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_create_index_endpoint_flattened(): @@ -676,10 +871,12 @@ def test_create_index_endpoint_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].index_endpoint == gca_index_endpoint.IndexEndpoint( - name="name_value" - ) + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].index_endpoint + mock_val = gca_index_endpoint.IndexEndpoint(name="name_value") + assert arg == mock_val def test_create_index_endpoint_flattened_error(): @@ -724,10 +921,12 @@ async def test_create_index_endpoint_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].index_endpoint == gca_index_endpoint.IndexEndpoint( - name="name_value" - ) + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].index_endpoint + mock_val = gca_index_endpoint.IndexEndpoint(name="name_value") + assert arg == mock_val @pytest.mark.asyncio @@ -746,11 +945,17 @@ async def test_create_index_endpoint_flattened_error_async(): ) -def test_get_index_endpoint( - transport: str = "grpc", request_type=index_endpoint_service.GetIndexEndpointRequest -): +@pytest.mark.parametrize( + "request_type", + [ + index_endpoint_service.GetIndexEndpointRequest, + dict, + ], +) +def test_get_index_endpoint(request_type, transport: str = "grpc"): client = IndexEndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -768,6 +973,7 @@ def test_get_index_endpoint( description="description_value", etag="etag_value", network="network_value", + enable_private_service_connect=True, ) response = client.get_index_endpoint(request) @@ -783,17 +989,15 @@ def test_get_index_endpoint( assert response.description == "description_value" assert response.etag == "etag_value" assert response.network == "network_value" - - -def test_get_index_endpoint_from_dict(): - test_get_index_endpoint(request_type=dict) + assert response.enable_private_service_connect is True def test_get_index_endpoint_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IndexEndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -812,7 +1016,8 @@ async def test_get_index_endpoint_async( request_type=index_endpoint_service.GetIndexEndpointRequest, ): client = IndexEndpointServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -831,6 +1036,7 @@ async def test_get_index_endpoint_async( description="description_value", etag="etag_value", network="network_value", + enable_private_service_connect=True, ) ) response = await client.get_index_endpoint(request) @@ -847,6 +1053,7 @@ async def test_get_index_endpoint_async( assert response.description == "description_value" assert response.etag == "etag_value" assert response.network == "network_value" + assert response.enable_private_service_connect is True @pytest.mark.asyncio @@ -863,7 +1070,7 @@ def test_get_index_endpoint_field_headers(): # a field header. Set these to a non-empty value. request = index_endpoint_service.GetIndexEndpointRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -879,7 +1086,10 @@ def test_get_index_endpoint_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -892,7 +1102,7 @@ async def test_get_index_endpoint_field_headers_async(): # a field header. Set these to a non-empty value. request = index_endpoint_service.GetIndexEndpointRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -910,7 +1120,10 @@ async def test_get_index_endpoint_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_get_index_endpoint_flattened(): @@ -926,13 +1139,17 @@ def test_get_index_endpoint_flattened(): call.return_value = index_endpoint.IndexEndpoint() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_index_endpoint(name="name_value",) + client.get_index_endpoint( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_index_endpoint_flattened_error(): @@ -944,7 +1161,8 @@ def test_get_index_endpoint_flattened_error(): # fields is an error. with pytest.raises(ValueError): client.get_index_endpoint( - index_endpoint_service.GetIndexEndpointRequest(), name="name_value", + index_endpoint_service.GetIndexEndpointRequest(), + name="name_value", ) @@ -966,13 +1184,17 @@ async def test_get_index_endpoint_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_index_endpoint(name="name_value",) + response = await client.get_index_endpoint( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -985,16 +1207,22 @@ async def test_get_index_endpoint_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.get_index_endpoint( - index_endpoint_service.GetIndexEndpointRequest(), name="name_value", + index_endpoint_service.GetIndexEndpointRequest(), + name="name_value", ) -def test_list_index_endpoints( - transport: str = "grpc", - request_type=index_endpoint_service.ListIndexEndpointsRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + index_endpoint_service.ListIndexEndpointsRequest, + dict, + ], +) +def test_list_index_endpoints(request_type, transport: str = "grpc"): client = IndexEndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1021,15 +1249,12 @@ def test_list_index_endpoints( assert response.next_page_token == "next_page_token_value" -def test_list_index_endpoints_from_dict(): - test_list_index_endpoints(request_type=dict) - - def test_list_index_endpoints_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IndexEndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1048,7 +1273,8 @@ async def test_list_index_endpoints_async( request_type=index_endpoint_service.ListIndexEndpointsRequest, ): client = IndexEndpointServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1091,7 +1317,7 @@ def test_list_index_endpoints_field_headers(): # a field header. Set these to a non-empty value. request = index_endpoint_service.ListIndexEndpointsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1107,7 +1333,10 @@ def test_list_index_endpoints_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1120,7 +1349,7 @@ async def test_list_index_endpoints_field_headers_async(): # a field header. Set these to a non-empty value. request = index_endpoint_service.ListIndexEndpointsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1138,7 +1367,10 @@ async def test_list_index_endpoints_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_index_endpoints_flattened(): @@ -1154,13 +1386,17 @@ def test_list_index_endpoints_flattened(): call.return_value = index_endpoint_service.ListIndexEndpointsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_index_endpoints(parent="parent_value",) + client.list_index_endpoints( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_index_endpoints_flattened_error(): @@ -1172,7 +1408,8 @@ def test_list_index_endpoints_flattened_error(): # fields is an error. with pytest.raises(ValueError): client.list_index_endpoints( - index_endpoint_service.ListIndexEndpointsRequest(), parent="parent_value", + index_endpoint_service.ListIndexEndpointsRequest(), + parent="parent_value", ) @@ -1194,13 +1431,17 @@ async def test_list_index_endpoints_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_index_endpoints(parent="parent_value",) + response = await client.list_index_endpoints( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1213,13 +1454,15 @@ async def test_list_index_endpoints_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.list_index_endpoints( - index_endpoint_service.ListIndexEndpointsRequest(), parent="parent_value", + index_endpoint_service.ListIndexEndpointsRequest(), + parent="parent_value", ) -def test_list_index_endpoints_pager(): +def test_list_index_endpoints_pager(transport_name: str = "grpc"): client = IndexEndpointServiceClient( credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1237,10 +1480,13 @@ def test_list_index_endpoints_pager(): next_page_token="abc", ), index_endpoint_service.ListIndexEndpointsResponse( - index_endpoints=[], next_page_token="def", + index_endpoints=[], + next_page_token="def", ), index_endpoint_service.ListIndexEndpointsResponse( - index_endpoints=[index_endpoint.IndexEndpoint(),], + index_endpoints=[ + index_endpoint.IndexEndpoint(), + ], next_page_token="ghi", ), index_endpoint_service.ListIndexEndpointsResponse( @@ -1260,14 +1506,15 @@ def test_list_index_endpoints_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all(isinstance(i, index_endpoint.IndexEndpoint) for i in results) -def test_list_index_endpoints_pages(): +def test_list_index_endpoints_pages(transport_name: str = "grpc"): client = IndexEndpointServiceClient( credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1285,10 +1532,13 @@ def test_list_index_endpoints_pages(): next_page_token="abc", ), index_endpoint_service.ListIndexEndpointsResponse( - index_endpoints=[], next_page_token="def", + index_endpoints=[], + next_page_token="def", ), index_endpoint_service.ListIndexEndpointsResponse( - index_endpoints=[index_endpoint.IndexEndpoint(),], + index_endpoints=[ + index_endpoint.IndexEndpoint(), + ], next_page_token="ghi", ), index_endpoint_service.ListIndexEndpointsResponse( @@ -1327,10 +1577,13 @@ async def test_list_index_endpoints_async_pager(): next_page_token="abc", ), index_endpoint_service.ListIndexEndpointsResponse( - index_endpoints=[], next_page_token="def", + index_endpoints=[], + next_page_token="def", ), index_endpoint_service.ListIndexEndpointsResponse( - index_endpoints=[index_endpoint.IndexEndpoint(),], + index_endpoints=[ + index_endpoint.IndexEndpoint(), + ], next_page_token="ghi", ), index_endpoint_service.ListIndexEndpointsResponse( @@ -1341,10 +1594,12 @@ async def test_list_index_endpoints_async_pager(): ), RuntimeError, ) - async_pager = await client.list_index_endpoints(request={},) + async_pager = await client.list_index_endpoints( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -1374,10 +1629,13 @@ async def test_list_index_endpoints_async_pages(): next_page_token="abc", ), index_endpoint_service.ListIndexEndpointsResponse( - index_endpoints=[], next_page_token="def", + index_endpoints=[], + next_page_token="def", ), index_endpoint_service.ListIndexEndpointsResponse( - index_endpoints=[index_endpoint.IndexEndpoint(),], + index_endpoints=[ + index_endpoint.IndexEndpoint(), + ], next_page_token="ghi", ), index_endpoint_service.ListIndexEndpointsResponse( @@ -1389,18 +1647,25 @@ async def test_list_index_endpoints_async_pages(): RuntimeError, ) pages = [] - async for page_ in (await client.list_index_endpoints(request={})).pages: + async for page_ in ( + await client.list_index_endpoints(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_update_index_endpoint( - transport: str = "grpc", - request_type=index_endpoint_service.UpdateIndexEndpointRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + index_endpoint_service.UpdateIndexEndpointRequest, + dict, + ], +) +def test_update_index_endpoint(request_type, transport: str = "grpc"): client = IndexEndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1418,6 +1683,7 @@ def test_update_index_endpoint( description="description_value", etag="etag_value", network="network_value", + enable_private_service_connect=True, ) response = client.update_index_endpoint(request) @@ -1433,17 +1699,15 @@ def test_update_index_endpoint( assert response.description == "description_value" assert response.etag == "etag_value" assert response.network == "network_value" - - -def test_update_index_endpoint_from_dict(): - test_update_index_endpoint(request_type=dict) + assert response.enable_private_service_connect is True def test_update_index_endpoint_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IndexEndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1462,7 +1726,8 @@ async def test_update_index_endpoint_async( request_type=index_endpoint_service.UpdateIndexEndpointRequest, ): client = IndexEndpointServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1481,6 +1746,7 @@ async def test_update_index_endpoint_async( description="description_value", etag="etag_value", network="network_value", + enable_private_service_connect=True, ) ) response = await client.update_index_endpoint(request) @@ -1497,6 +1763,7 @@ async def test_update_index_endpoint_async( assert response.description == "description_value" assert response.etag == "etag_value" assert response.network == "network_value" + assert response.enable_private_service_connect is True @pytest.mark.asyncio @@ -1513,7 +1780,7 @@ def test_update_index_endpoint_field_headers(): # a field header. Set these to a non-empty value. request = index_endpoint_service.UpdateIndexEndpointRequest() - request.index_endpoint.name = "index_endpoint.name/value" + request.index_endpoint.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1531,7 +1798,7 @@ def test_update_index_endpoint_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "index_endpoint.name=index_endpoint.name/value", + "index_endpoint.name=name_value", ) in kw["metadata"] @@ -1545,7 +1812,7 @@ async def test_update_index_endpoint_field_headers_async(): # a field header. Set these to a non-empty value. request = index_endpoint_service.UpdateIndexEndpointRequest() - request.index_endpoint.name = "index_endpoint.name/value" + request.index_endpoint.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1565,7 +1832,7 @@ async def test_update_index_endpoint_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "index_endpoint.name=index_endpoint.name/value", + "index_endpoint.name=name_value", ) in kw["metadata"] @@ -1591,10 +1858,12 @@ def test_update_index_endpoint_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].index_endpoint == gca_index_endpoint.IndexEndpoint( - name="name_value" - ) - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].index_endpoint + mock_val = gca_index_endpoint.IndexEndpoint(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val def test_update_index_endpoint_flattened_error(): @@ -1639,10 +1908,12 @@ async def test_update_index_endpoint_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].index_endpoint == gca_index_endpoint.IndexEndpoint( - name="name_value" - ) - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].index_endpoint + mock_val = gca_index_endpoint.IndexEndpoint(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val @pytest.mark.asyncio @@ -1661,12 +1932,17 @@ async def test_update_index_endpoint_flattened_error_async(): ) -def test_delete_index_endpoint( - transport: str = "grpc", - request_type=index_endpoint_service.DeleteIndexEndpointRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + index_endpoint_service.DeleteIndexEndpointRequest, + dict, + ], +) +def test_delete_index_endpoint(request_type, transport: str = "grpc"): client = IndexEndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1690,15 +1966,12 @@ def test_delete_index_endpoint( assert isinstance(response, future.Future) -def test_delete_index_endpoint_from_dict(): - test_delete_index_endpoint(request_type=dict) - - def test_delete_index_endpoint_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IndexEndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1717,7 +1990,8 @@ async def test_delete_index_endpoint_async( request_type=index_endpoint_service.DeleteIndexEndpointRequest, ): client = IndexEndpointServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1757,7 +2031,7 @@ def test_delete_index_endpoint_field_headers(): # a field header. Set these to a non-empty value. request = index_endpoint_service.DeleteIndexEndpointRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1773,7 +2047,10 @@ def test_delete_index_endpoint_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1786,7 +2063,7 @@ async def test_delete_index_endpoint_field_headers_async(): # a field header. Set these to a non-empty value. request = index_endpoint_service.DeleteIndexEndpointRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1804,7 +2081,10 @@ async def test_delete_index_endpoint_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_delete_index_endpoint_flattened(): @@ -1820,13 +2100,17 @@ def test_delete_index_endpoint_flattened(): call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_index_endpoint(name="name_value",) + client.delete_index_endpoint( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_delete_index_endpoint_flattened_error(): @@ -1838,7 +2122,8 @@ def test_delete_index_endpoint_flattened_error(): # fields is an error. with pytest.raises(ValueError): client.delete_index_endpoint( - index_endpoint_service.DeleteIndexEndpointRequest(), name="name_value", + index_endpoint_service.DeleteIndexEndpointRequest(), + name="name_value", ) @@ -1860,13 +2145,17 @@ async def test_delete_index_endpoint_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_index_endpoint(name="name_value",) + response = await client.delete_index_endpoint( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1879,15 +2168,22 @@ async def test_delete_index_endpoint_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.delete_index_endpoint( - index_endpoint_service.DeleteIndexEndpointRequest(), name="name_value", + index_endpoint_service.DeleteIndexEndpointRequest(), + name="name_value", ) -def test_deploy_index( - transport: str = "grpc", request_type=index_endpoint_service.DeployIndexRequest -): +@pytest.mark.parametrize( + "request_type", + [ + index_endpoint_service.DeployIndexRequest, + dict, + ], +) +def test_deploy_index(request_type, transport: str = "grpc"): client = IndexEndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1909,15 +2205,12 @@ def test_deploy_index( assert isinstance(response, future.Future) -def test_deploy_index_from_dict(): - test_deploy_index(request_type=dict) - - def test_deploy_index_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IndexEndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1934,7 +2227,8 @@ async def test_deploy_index_async( request_type=index_endpoint_service.DeployIndexRequest, ): client = IndexEndpointServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1972,7 +2266,7 @@ def test_deploy_index_field_headers(): # a field header. Set these to a non-empty value. request = index_endpoint_service.DeployIndexRequest() - request.index_endpoint = "index_endpoint/value" + request.index_endpoint = "index_endpoint_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.deploy_index), "__call__") as call: @@ -1986,9 +2280,10 @@ def test_deploy_index_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "index_endpoint=index_endpoint/value",) in kw[ - "metadata" - ] + assert ( + "x-goog-request-params", + "index_endpoint=index_endpoint_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2001,7 +2296,7 @@ async def test_deploy_index_field_headers_async(): # a field header. Set these to a non-empty value. request = index_endpoint_service.DeployIndexRequest() - request.index_endpoint = "index_endpoint/value" + request.index_endpoint = "index_endpoint_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.deploy_index), "__call__") as call: @@ -2017,9 +2312,10 @@ async def test_deploy_index_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "index_endpoint=index_endpoint/value",) in kw[ - "metadata" - ] + assert ( + "x-goog-request-params", + "index_endpoint=index_endpoint_value", + ) in kw["metadata"] def test_deploy_index_flattened(): @@ -2042,8 +2338,12 @@ def test_deploy_index_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].index_endpoint == "index_endpoint_value" - assert args[0].deployed_index == gca_index_endpoint.DeployedIndex(id="id_value") + arg = args[0].index_endpoint + mock_val = "index_endpoint_value" + assert arg == mock_val + arg = args[0].deployed_index + mock_val = gca_index_endpoint.DeployedIndex(id="id_value") + assert arg == mock_val def test_deploy_index_flattened_error(): @@ -2086,8 +2386,12 @@ async def test_deploy_index_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].index_endpoint == "index_endpoint_value" - assert args[0].deployed_index == gca_index_endpoint.DeployedIndex(id="id_value") + arg = args[0].index_endpoint + mock_val = "index_endpoint_value" + assert arg == mock_val + arg = args[0].deployed_index + mock_val = gca_index_endpoint.DeployedIndex(id="id_value") + assert arg == mock_val @pytest.mark.asyncio @@ -2106,11 +2410,17 @@ async def test_deploy_index_flattened_error_async(): ) -def test_undeploy_index( - transport: str = "grpc", request_type=index_endpoint_service.UndeployIndexRequest -): +@pytest.mark.parametrize( + "request_type", + [ + index_endpoint_service.UndeployIndexRequest, + dict, + ], +) +def test_undeploy_index(request_type, transport: str = "grpc"): client = IndexEndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2132,15 +2442,12 @@ def test_undeploy_index( assert isinstance(response, future.Future) -def test_undeploy_index_from_dict(): - test_undeploy_index(request_type=dict) - - def test_undeploy_index_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IndexEndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2157,7 +2464,8 @@ async def test_undeploy_index_async( request_type=index_endpoint_service.UndeployIndexRequest, ): client = IndexEndpointServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2195,7 +2503,7 @@ def test_undeploy_index_field_headers(): # a field header. Set these to a non-empty value. request = index_endpoint_service.UndeployIndexRequest() - request.index_endpoint = "index_endpoint/value" + request.index_endpoint = "index_endpoint_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.undeploy_index), "__call__") as call: @@ -2209,9 +2517,10 @@ def test_undeploy_index_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "index_endpoint=index_endpoint/value",) in kw[ - "metadata" - ] + assert ( + "x-goog-request-params", + "index_endpoint=index_endpoint_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2224,7 +2533,7 @@ async def test_undeploy_index_field_headers_async(): # a field header. Set these to a non-empty value. request = index_endpoint_service.UndeployIndexRequest() - request.index_endpoint = "index_endpoint/value" + request.index_endpoint = "index_endpoint_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.undeploy_index), "__call__") as call: @@ -2240,9 +2549,10 @@ async def test_undeploy_index_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "index_endpoint=index_endpoint/value",) in kw[ - "metadata" - ] + assert ( + "x-goog-request-params", + "index_endpoint=index_endpoint_value", + ) in kw["metadata"] def test_undeploy_index_flattened(): @@ -2265,8 +2575,12 @@ def test_undeploy_index_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].index_endpoint == "index_endpoint_value" - assert args[0].deployed_index_id == "deployed_index_id_value" + arg = args[0].index_endpoint + mock_val = "index_endpoint_value" + assert arg == mock_val + arg = args[0].deployed_index_id + mock_val = "deployed_index_id_value" + assert arg == mock_val def test_undeploy_index_flattened_error(): @@ -2309,8 +2623,12 @@ async def test_undeploy_index_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].index_endpoint == "index_endpoint_value" - assert args[0].deployed_index_id == "deployed_index_id_value" + arg = args[0].index_endpoint + mock_val = "index_endpoint_value" + assert arg == mock_val + arg = args[0].deployed_index_id + mock_val = "deployed_index_id_value" + assert arg == mock_val @pytest.mark.asyncio @@ -2329,6 +2647,257 @@ async def test_undeploy_index_flattened_error_async(): ) +@pytest.mark.parametrize( + "request_type", + [ + index_endpoint_service.MutateDeployedIndexRequest, + dict, + ], +) +def test_mutate_deployed_index(request_type, transport: str = "grpc"): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.mutate_deployed_index), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.mutate_deployed_index(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == index_endpoint_service.MutateDeployedIndexRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_mutate_deployed_index_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.mutate_deployed_index), "__call__" + ) as call: + client.mutate_deployed_index() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == index_endpoint_service.MutateDeployedIndexRequest() + + +@pytest.mark.asyncio +async def test_mutate_deployed_index_async( + transport: str = "grpc_asyncio", + request_type=index_endpoint_service.MutateDeployedIndexRequest, +): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.mutate_deployed_index), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.mutate_deployed_index(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == index_endpoint_service.MutateDeployedIndexRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_mutate_deployed_index_async_from_dict(): + await test_mutate_deployed_index_async(request_type=dict) + + +def test_mutate_deployed_index_field_headers(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = index_endpoint_service.MutateDeployedIndexRequest() + + request.index_endpoint = "index_endpoint_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.mutate_deployed_index), "__call__" + ) as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.mutate_deployed_index(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "index_endpoint=index_endpoint_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_mutate_deployed_index_field_headers_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = index_endpoint_service.MutateDeployedIndexRequest() + + request.index_endpoint = "index_endpoint_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.mutate_deployed_index), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.mutate_deployed_index(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "index_endpoint=index_endpoint_value", + ) in kw["metadata"] + + +def test_mutate_deployed_index_flattened(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.mutate_deployed_index), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.mutate_deployed_index( + index_endpoint="index_endpoint_value", + deployed_index=gca_index_endpoint.DeployedIndex(id="id_value"), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].index_endpoint + mock_val = "index_endpoint_value" + assert arg == mock_val + arg = args[0].deployed_index + mock_val = gca_index_endpoint.DeployedIndex(id="id_value") + assert arg == mock_val + + +def test_mutate_deployed_index_flattened_error(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.mutate_deployed_index( + index_endpoint_service.MutateDeployedIndexRequest(), + index_endpoint="index_endpoint_value", + deployed_index=gca_index_endpoint.DeployedIndex(id="id_value"), + ) + + +@pytest.mark.asyncio +async def test_mutate_deployed_index_flattened_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.mutate_deployed_index), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/op") + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.mutate_deployed_index( + index_endpoint="index_endpoint_value", + deployed_index=gca_index_endpoint.DeployedIndex(id="id_value"), + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].index_endpoint + mock_val = "index_endpoint_value" + assert arg == mock_val + arg = args[0].deployed_index + mock_val = gca_index_endpoint.DeployedIndex(id="id_value") + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_mutate_deployed_index_flattened_error_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.mutate_deployed_index( + index_endpoint_service.MutateDeployedIndexRequest(), + index_endpoint="index_endpoint_value", + deployed_index=gca_index_endpoint.DeployedIndex(id="id_value"), + ) + + def test_credentials_transport_error(): # It is an error to provide credentials and a transport instance. transport = transports.IndexEndpointServiceGrpcTransport( @@ -2336,7 +2905,8 @@ def test_credentials_transport_error(): ) with pytest.raises(ValueError): client = IndexEndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # It is an error to provide a credentials file and a transport instance. @@ -2349,13 +2919,34 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.IndexEndpointServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = IndexEndpointServiceClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = IndexEndpointServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.IndexEndpointServiceGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = IndexEndpointServiceClient( - client_options={"scopes": ["1", "2"]}, transport=transport, + client_options={"scopes": ["1", "2"]}, + transport=transport, ) @@ -2398,12 +2989,28 @@ def test_transport_adc(transport_class): adc.assert_called_once() +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = IndexEndpointServiceClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = IndexEndpointServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) - assert isinstance(client.transport, transports.IndexEndpointServiceGrpcTransport,) + assert isinstance( + client.transport, + transports.IndexEndpointServiceGrpcTransport, + ) def test_index_endpoint_service_base_transport_error(): @@ -2435,18 +3042,39 @@ def test_index_endpoint_service_base_transport(): "delete_index_endpoint", "deploy_index", "undeploy_index", + "mutate_deployed_index", + "set_iam_policy", + "get_iam_policy", + "test_iam_permissions", + "get_location", + "list_locations", + "get_operation", + "wait_operation", + "cancel_operation", + "delete_operation", + "list_operations", ) for method in methods: with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + # Additionally, the LRO client (a property) should # also raise NotImplementedError with pytest.raises(NotImplementedError): transport.operations_client + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + -@requires_google_auth_gte_1_25_0 def test_index_endpoint_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -2457,7 +3085,8 @@ def test_index_endpoint_service_base_transport_with_credentials_file(): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.IndexEndpointServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", + credentials_file="credentials.json", + quota_project_id="octopus", ) load_creds.assert_called_once_with( "credentials.json", @@ -2467,26 +3096,6 @@ def test_index_endpoint_service_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_index_endpoint_service_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.aiplatform_v1beta1.services.index_endpoint_service.transports.IndexEndpointServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.IndexEndpointServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - def test_index_endpoint_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( @@ -2498,7 +3107,6 @@ def test_index_endpoint_service_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_index_endpoint_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -2511,18 +3119,6 @@ def test_index_endpoint_service_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_index_endpoint_service_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - IndexEndpointServiceClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -2530,7 +3126,6 @@ def test_index_endpoint_service_auth_adc_old_google_auth(): transports.IndexEndpointServiceGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_index_endpoint_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -2544,26 +3139,6 @@ def test_index_endpoint_service_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.IndexEndpointServiceGrpcTransport, - transports.IndexEndpointServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_index_endpoint_service_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ @@ -2571,7 +3146,6 @@ def test_index_endpoint_service_transport_auth_adc_old_google_auth(transport_cla (transports.IndexEndpointServiceGrpcAsyncIOTransport, grpc_helpers_async), ], ) -@requires_api_core_gte_1_26_0 def test_index_endpoint_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -2600,79 +3174,6 @@ def test_index_endpoint_service_transport_create_channel(transport_class, grpc_h ) -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.IndexEndpointServiceGrpcTransport, grpc_helpers), - (transports.IndexEndpointServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_index_endpoint_service_transport_create_channel_old_api_core( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class(quota_project_id="octopus") - - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.IndexEndpointServiceGrpcTransport, grpc_helpers), - (transports.IndexEndpointServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_index_endpoint_service_transport_create_channel_user_scopes( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=["1", "2"], - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -2697,7 +3198,7 @@ def test_index_endpoint_service_grpc_transport_client_cert_source_for_mtls( "squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_channel_creds, quota_project_id=None, options=[ @@ -2720,24 +3221,40 @@ def test_index_endpoint_service_grpc_transport_client_cert_source_for_mtls( ) -def test_index_endpoint_service_host_no_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_index_endpoint_service_host_no_port(transport_name): client = IndexEndpointServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="aiplatform.googleapis.com" ), + transport=transport_name, ) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") -def test_index_endpoint_service_host_with_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_index_endpoint_service_host_with_port(transport_name): client = IndexEndpointServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="aiplatform.googleapis.com:8000" ), + transport=transport_name, ) - assert client.transport._host == "aiplatform.googleapis.com:8000" + assert client.transport._host == ("aiplatform.googleapis.com:8000") def test_index_endpoint_service_grpc_transport_channel(): @@ -2745,7 +3262,8 @@ def test_index_endpoint_service_grpc_transport_channel(): # Check that channel is used if provided. transport = transports.IndexEndpointServiceGrpcTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -2757,7 +3275,8 @@ def test_index_endpoint_service_grpc_asyncio_transport_channel(): # Check that channel is used if provided. transport = transports.IndexEndpointServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -2806,7 +3325,7 @@ def test_index_endpoint_service_transport_channel_mtls_with_client_cert_source( "mtls.squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -2853,7 +3372,7 @@ def test_index_endpoint_service_transport_channel_mtls_with_adc(transport_class) "mtls.squid.clam.whelk:443", credentials=mock_cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -2866,12 +3385,16 @@ def test_index_endpoint_service_transport_channel_mtls_with_adc(transport_class) def test_index_endpoint_service_grpc_lro_client(): client = IndexEndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -2879,12 +3402,16 @@ def test_index_endpoint_service_grpc_lro_client(): def test_index_endpoint_service_grpc_lro_async_client(): client = IndexEndpointServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -2895,7 +3422,9 @@ def test_index_path(): location = "clam" index = "whelk" expected = "projects/{project}/locations/{location}/indexes/{index}".format( - project=project, location=location, index=index, + project=project, + location=location, + index=index, ) actual = IndexEndpointServiceClient.index_path(project, location, index) assert expected == actual @@ -2919,7 +3448,9 @@ def test_index_endpoint_path(): location = "mussel" index_endpoint = "winkle" expected = "projects/{project}/locations/{location}/indexEndpoints/{index_endpoint}".format( - project=project, location=location, index_endpoint=index_endpoint, + project=project, + location=location, + index_endpoint=index_endpoint, ) actual = IndexEndpointServiceClient.index_endpoint_path( project, location, index_endpoint @@ -2962,7 +3493,9 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "whelk" - expected = "folders/{folder}".format(folder=folder,) + expected = "folders/{folder}".format( + folder=folder, + ) actual = IndexEndpointServiceClient.common_folder_path(folder) assert expected == actual @@ -2980,7 +3513,9 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "oyster" - expected = "organizations/{organization}".format(organization=organization,) + expected = "organizations/{organization}".format( + organization=organization, + ) actual = IndexEndpointServiceClient.common_organization_path(organization) assert expected == actual @@ -2998,7 +3533,9 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "cuttlefish" - expected = "projects/{project}".format(project=project,) + expected = "projects/{project}".format( + project=project, + ) actual = IndexEndpointServiceClient.common_project_path(project) assert expected == actual @@ -3018,7 +3555,8 @@ def test_common_location_path(): project = "winkle" location = "nautilus" expected = "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) actual = IndexEndpointServiceClient.common_location_path(project, location) assert expected == actual @@ -3036,14 +3574,15 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( transports.IndexEndpointServiceTransport, "_prep_wrapped_messages" ) as prep: client = IndexEndpointServiceClient( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -3052,6 +3591,1598 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = IndexEndpointServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_delete_operation(transport: str = "grpc"): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_operation(transport: str = "grpc"): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_operation_field_headers(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = None + + client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_operation_field_headers_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_delete_operation_from_dict(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_delete_operation_from_dict_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_cancel_operation(transport: str = "grpc"): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation(transport: str = "grpc"): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_wait_operation(transport: str = "grpc"): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_wait_operation(transport: str = "grpc"): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_wait_operation_field_headers(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_wait_operation_field_headers_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_wait_operation_from_dict(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_wait_operation_from_dict_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_operation(transport: str = "grpc"): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_get_operation(transport: str = "grpc"): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_get_operation_field_headers(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_get_operation_from_dict(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_operations(transport: str = "grpc"): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + response = client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +@pytest.mark.asyncio +async def test_list_operations(transport: str = "grpc"): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +def test_list_operations_field_headers(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_operations_field_headers_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_operations_from_dict(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + response = client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_operations_from_dict_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_locations(transport: str = "grpc"): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + response = client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +@pytest.mark.asyncio +async def test_list_locations(transport: str = "grpc"): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +def test_list_locations_field_headers(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_locations_field_headers_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_locations_from_dict(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + response = client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_locations_from_dict_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_location(transport: str = "grpc"): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + response = client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +@pytest.mark.asyncio +async def test_get_location_async(transport: str = "grpc_asyncio"): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +def test_get_location_field_headers(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials() + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = locations_pb2.Location() + + client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_location_field_headers_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials() + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +def test_get_location_from_dict(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + response = client.get_location( + request={ + "name": "locations/abc", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_location_from_dict_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_set_iam_policy(transport: str = "grpc"): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + response = client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + response = await client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_set_iam_policy_field_headers(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_set_iam_policy_field_headers_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_set_iam_policy_from_dict(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_set_iam_policy_from_dict_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +def test_get_iam_policy(transport: str = "grpc"): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + + response = client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + + response = await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_get_iam_policy_field_headers(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_iam_policy_field_headers_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_get_iam_policy_from_dict(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_iam_policy_from_dict_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +def test_test_iam_permissions(transport: str = "grpc"): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + + response = client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + ) + + response = await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +def test_test_iam_permissions_field_headers(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_field_headers_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_test_iam_permissions_from_dict(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + response = client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_from_dict_async(): + client = IndexEndpointServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + response = await client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = IndexEndpointServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (IndexEndpointServiceClient, transports.IndexEndpointServiceGrpcTransport), + ( + IndexEndpointServiceAsyncClient, + transports.IndexEndpointServiceGrpcAsyncIOTransport, + ), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) diff --git a/tests/unit/gapic/aiplatform_v1beta1/test_index_service.py b/tests/unit/gapic/aiplatform_v1beta1/test_index_service.py index 4996d1a173..e889aacd43 100644 --- a/tests/unit/gapic/aiplatform_v1beta1/test_index_service.py +++ b/tests/unit/gapic/aiplatform_v1beta1/test_index_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,8 +14,13 @@ # limitations under the License. # import os -import mock -import packaging.version + +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock +except ImportError: + import mock import grpc from grpc.experimental import aio @@ -30,8 +35,10 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.aiplatform_v1beta1.services.index_service import ( @@ -40,17 +47,15 @@ from google.cloud.aiplatform_v1beta1.services.index_service import IndexServiceClient from google.cloud.aiplatform_v1beta1.services.index_service import pagers from google.cloud.aiplatform_v1beta1.services.index_service import transports -from google.cloud.aiplatform_v1beta1.services.index_service.transports.base import ( - _API_CORE_VERSION, -) -from google.cloud.aiplatform_v1beta1.services.index_service.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.aiplatform_v1beta1.types import deployed_index_ref from google.cloud.aiplatform_v1beta1.types import index from google.cloud.aiplatform_v1beta1.types import index as gca_index from google.cloud.aiplatform_v1beta1.types import index_service from google.cloud.aiplatform_v1beta1.types import operation as gca_operation +from google.cloud.location import locations_pb2 +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 from google.oauth2 import service_account from google.protobuf import field_mask_pb2 # type: ignore @@ -59,29 +64,6 @@ import google.auth -# TODO(busunkim): Once google-api-core >= 1.26.0 is required: -# - Delete all the api-core and auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - -requires_api_core_lt_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), - reason="This test requires google-api-core < 1.26.0", -) - -requires_api_core_gte_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), - reason="This test requires google-api-core >= 1.26.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -123,37 +105,78 @@ def test__get_default_mtls_endpoint(): assert IndexServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi -@pytest.mark.parametrize("client_class", [IndexServiceClient, IndexServiceAsyncClient,]) -def test_index_service_client_from_service_account_info(client_class): +@pytest.mark.parametrize( + "client_class,transport_name", + [ + (IndexServiceClient, "grpc"), + (IndexServiceAsyncClient, "grpc_asyncio"), + ], +) +def test_index_service_client_from_service_account_info(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") + +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.IndexServiceGrpcTransport, "grpc"), + (transports.IndexServiceGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_index_service_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() -@pytest.mark.parametrize("client_class", [IndexServiceClient, IndexServiceAsyncClient,]) -def test_index_service_client_from_service_account_file(client_class): + +@pytest.mark.parametrize( + "client_class,transport_name", + [ + (IndexServiceClient, "grpc"), + (IndexServiceAsyncClient, "grpc_asyncio"), + ], +) +def test_index_service_client_from_service_account_file(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") def test_index_service_client_get_transport_class(): @@ -204,7 +227,7 @@ def test_index_service_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -213,6 +236,7 @@ def test_index_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -220,7 +244,7 @@ def test_index_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -229,6 +253,7 @@ def test_index_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -236,7 +261,7 @@ def test_index_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -245,26 +270,27 @@ def test_index_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -273,6 +299,7 @@ def test_index_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -320,7 +347,7 @@ def test_index_service_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -337,6 +364,7 @@ def test_index_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case ADC client cert is provided. Whether client cert is used depends on @@ -361,7 +389,7 @@ def test_index_service_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -370,6 +398,7 @@ def test_index_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case client_cert_source and ADC client cert are not provided. @@ -382,7 +411,7 @@ def test_index_service_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -391,9 +420,87 @@ def test_index_service_client_mtls_env_auto( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) +@pytest.mark.parametrize("client_class", [IndexServiceClient, IndexServiceAsyncClient]) +@mock.patch.object( + IndexServiceClient, "DEFAULT_ENDPOINT", modify_default_endpoint(IndexServiceClient) +) +@mock.patch.object( + IndexServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(IndexServiceAsyncClient), +) +def test_index_service_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + @pytest.mark.parametrize( "client_class,transport_class,transport_name", [ @@ -409,10 +516,12 @@ def test_index_service_client_client_options_scopes( client_class, transport_class, transport_name ): # Check the case scopes are provided. - options = client_options.ClientOptions(scopes=["1", "2"],) + options = client_options.ClientOptions( + scopes=["1", "2"], + ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -421,28 +530,36 @@ def test_index_service_client_client_options_scopes( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (IndexServiceClient, transports.IndexServiceGrpcTransport, "grpc"), + ( + IndexServiceClient, + transports.IndexServiceGrpcTransport, + "grpc", + grpc_helpers, + ), ( IndexServiceAsyncClient, transports.IndexServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_index_service_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -451,6 +568,7 @@ def test_index_service_client_client_options_credentials_file( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -468,14 +586,87 @@ def test_index_service_client_client_options_from_dict(): client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) -def test_create_index( - transport: str = "grpc", request_type=index_service.CreateIndexRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + IndexServiceClient, + transports.IndexServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + IndexServiceAsyncClient, + transports.IndexServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_index_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers ): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + index_service.CreateIndexRequest, + dict, + ], +) +def test_create_index(request_type, transport: str = "grpc"): client = IndexServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -497,15 +688,12 @@ def test_create_index( assert isinstance(response, future.Future) -def test_create_index_from_dict(): - test_create_index(request_type=dict) - - def test_create_index_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IndexServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -521,7 +709,8 @@ async def test_create_index_async( transport: str = "grpc_asyncio", request_type=index_service.CreateIndexRequest ): client = IndexServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -551,13 +740,15 @@ async def test_create_index_async_from_dict(): def test_create_index_field_headers(): - client = IndexServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = index_service.CreateIndexRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_index), "__call__") as call: @@ -571,18 +762,23 @@ def test_create_index_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_create_index_field_headers_async(): - client = IndexServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = index_service.CreateIndexRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_index), "__call__") as call: @@ -598,11 +794,16 @@ async def test_create_index_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_create_index_flattened(): - client = IndexServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_index), "__call__") as call: @@ -611,19 +812,26 @@ def test_create_index_flattened(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.create_index( - parent="parent_value", index=gca_index.Index(name="name_value"), + parent="parent_value", + index=gca_index.Index(name="name_value"), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].index == gca_index.Index(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].index + mock_val = gca_index.Index(name="name_value") + assert arg == mock_val def test_create_index_flattened_error(): - client = IndexServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -637,7 +845,9 @@ def test_create_index_flattened_error(): @pytest.mark.asyncio async def test_create_index_flattened_async(): - client = IndexServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_index), "__call__") as call: @@ -650,20 +860,27 @@ async def test_create_index_flattened_async(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. response = await client.create_index( - parent="parent_value", index=gca_index.Index(name="name_value"), + parent="parent_value", + index=gca_index.Index(name="name_value"), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].index == gca_index.Index(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].index + mock_val = gca_index.Index(name="name_value") + assert arg == mock_val @pytest.mark.asyncio async def test_create_index_flattened_error_async(): - client = IndexServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -675,9 +892,17 @@ async def test_create_index_flattened_error_async(): ) -def test_get_index(transport: str = "grpc", request_type=index_service.GetIndexRequest): +@pytest.mark.parametrize( + "request_type", + [ + index_service.GetIndexRequest, + dict, + ], +) +def test_get_index(request_type, transport: str = "grpc"): client = IndexServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -710,15 +935,12 @@ def test_get_index(transport: str = "grpc", request_type=index_service.GetIndexR assert response.etag == "etag_value" -def test_get_index_from_dict(): - test_get_index(request_type=dict) - - def test_get_index_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IndexServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -734,7 +956,8 @@ async def test_get_index_async( transport: str = "grpc_asyncio", request_type=index_service.GetIndexRequest ): client = IndexServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -775,13 +998,15 @@ async def test_get_index_async_from_dict(): def test_get_index_field_headers(): - client = IndexServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = index_service.GetIndexRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_index), "__call__") as call: @@ -795,18 +1020,23 @@ def test_get_index_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_get_index_field_headers_async(): - client = IndexServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = index_service.GetIndexRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_index), "__call__") as call: @@ -820,11 +1050,16 @@ async def test_get_index_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_get_index_flattened(): - client = IndexServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_index), "__call__") as call: @@ -832,29 +1067,38 @@ def test_get_index_flattened(): call.return_value = index.Index() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_index(name="name_value",) + client.get_index( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_index_flattened_error(): - client = IndexServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.get_index( - index_service.GetIndexRequest(), name="name_value", + index_service.GetIndexRequest(), + name="name_value", ) @pytest.mark.asyncio async def test_get_index_flattened_async(): - client = IndexServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_index), "__call__") as call: @@ -864,32 +1108,45 @@ async def test_get_index_flattened_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(index.Index()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_index(name="name_value",) + response = await client.get_index( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio async def test_get_index_flattened_error_async(): - client = IndexServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.get_index( - index_service.GetIndexRequest(), name="name_value", + index_service.GetIndexRequest(), + name="name_value", ) -def test_list_indexes( - transport: str = "grpc", request_type=index_service.ListIndexesRequest -): +@pytest.mark.parametrize( + "request_type", + [ + index_service.ListIndexesRequest, + dict, + ], +) +def test_list_indexes(request_type, transport: str = "grpc"): client = IndexServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -914,15 +1171,12 @@ def test_list_indexes( assert response.next_page_token == "next_page_token_value" -def test_list_indexes_from_dict(): - test_list_indexes(request_type=dict) - - def test_list_indexes_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IndexServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -938,7 +1192,8 @@ async def test_list_indexes_async( transport: str = "grpc_asyncio", request_type=index_service.ListIndexesRequest ): client = IndexServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -949,7 +1204,9 @@ async def test_list_indexes_async( with mock.patch.object(type(client.transport.list_indexes), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - index_service.ListIndexesResponse(next_page_token="next_page_token_value",) + index_service.ListIndexesResponse( + next_page_token="next_page_token_value", + ) ) response = await client.list_indexes(request) @@ -969,13 +1226,15 @@ async def test_list_indexes_async_from_dict(): def test_list_indexes_field_headers(): - client = IndexServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = index_service.ListIndexesRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_indexes), "__call__") as call: @@ -989,18 +1248,23 @@ def test_list_indexes_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_list_indexes_field_headers_async(): - client = IndexServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = index_service.ListIndexesRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_indexes), "__call__") as call: @@ -1016,11 +1280,16 @@ async def test_list_indexes_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_indexes_flattened(): - client = IndexServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_indexes), "__call__") as call: @@ -1028,29 +1297,38 @@ def test_list_indexes_flattened(): call.return_value = index_service.ListIndexesResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_indexes(parent="parent_value",) + client.list_indexes( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_indexes_flattened_error(): - client = IndexServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.list_indexes( - index_service.ListIndexesRequest(), parent="parent_value", + index_service.ListIndexesRequest(), + parent="parent_value", ) @pytest.mark.asyncio async def test_list_indexes_flattened_async(): - client = IndexServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_indexes), "__call__") as call: @@ -1062,43 +1340,68 @@ async def test_list_indexes_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_indexes(parent="parent_value",) + response = await client.list_indexes( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio async def test_list_indexes_flattened_error_async(): - client = IndexServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.list_indexes( - index_service.ListIndexesRequest(), parent="parent_value", + index_service.ListIndexesRequest(), + parent="parent_value", ) -def test_list_indexes_pager(): - client = IndexServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_indexes_pager(transport_name: str = "grpc"): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_indexes), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( index_service.ListIndexesResponse( - indexes=[index.Index(), index.Index(), index.Index(),], + indexes=[ + index.Index(), + index.Index(), + index.Index(), + ], next_page_token="abc", ), - index_service.ListIndexesResponse(indexes=[], next_page_token="def",), index_service.ListIndexesResponse( - indexes=[index.Index(),], next_page_token="ghi", + indexes=[], + next_page_token="def", + ), + index_service.ListIndexesResponse( + indexes=[ + index.Index(), + ], + next_page_token="ghi", + ), + index_service.ListIndexesResponse( + indexes=[ + index.Index(), + index.Index(), + ], ), - index_service.ListIndexesResponse(indexes=[index.Index(), index.Index(),],), RuntimeError, ) @@ -1110,27 +1413,45 @@ def test_list_indexes_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all(isinstance(i, index.Index) for i in results) -def test_list_indexes_pages(): - client = IndexServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_indexes_pages(transport_name: str = "grpc"): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_indexes), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( index_service.ListIndexesResponse( - indexes=[index.Index(), index.Index(), index.Index(),], + indexes=[ + index.Index(), + index.Index(), + index.Index(), + ], next_page_token="abc", ), - index_service.ListIndexesResponse(indexes=[], next_page_token="def",), index_service.ListIndexesResponse( - indexes=[index.Index(),], next_page_token="ghi", + indexes=[], + next_page_token="def", + ), + index_service.ListIndexesResponse( + indexes=[ + index.Index(), + ], + next_page_token="ghi", + ), + index_service.ListIndexesResponse( + indexes=[ + index.Index(), + index.Index(), + ], ), - index_service.ListIndexesResponse(indexes=[index.Index(), index.Index(),],), RuntimeError, ) pages = list(client.list_indexes(request={}).pages) @@ -1140,7 +1461,9 @@ def test_list_indexes_pages(): @pytest.mark.asyncio async def test_list_indexes_async_pager(): - client = IndexServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1149,20 +1472,37 @@ async def test_list_indexes_async_pager(): # Set the response to a series of pages. call.side_effect = ( index_service.ListIndexesResponse( - indexes=[index.Index(), index.Index(), index.Index(),], + indexes=[ + index.Index(), + index.Index(), + index.Index(), + ], next_page_token="abc", ), - index_service.ListIndexesResponse(indexes=[], next_page_token="def",), index_service.ListIndexesResponse( - indexes=[index.Index(),], next_page_token="ghi", + indexes=[], + next_page_token="def", + ), + index_service.ListIndexesResponse( + indexes=[ + index.Index(), + ], + next_page_token="ghi", + ), + index_service.ListIndexesResponse( + indexes=[ + index.Index(), + index.Index(), + ], ), - index_service.ListIndexesResponse(indexes=[index.Index(), index.Index(),],), RuntimeError, ) - async_pager = await client.list_indexes(request={},) + async_pager = await client.list_indexes( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -1171,7 +1511,9 @@ async def test_list_indexes_async_pager(): @pytest.mark.asyncio async def test_list_indexes_async_pages(): - client = IndexServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1180,28 +1522,51 @@ async def test_list_indexes_async_pages(): # Set the response to a series of pages. call.side_effect = ( index_service.ListIndexesResponse( - indexes=[index.Index(), index.Index(), index.Index(),], + indexes=[ + index.Index(), + index.Index(), + index.Index(), + ], next_page_token="abc", ), - index_service.ListIndexesResponse(indexes=[], next_page_token="def",), index_service.ListIndexesResponse( - indexes=[index.Index(),], next_page_token="ghi", + indexes=[], + next_page_token="def", + ), + index_service.ListIndexesResponse( + indexes=[ + index.Index(), + ], + next_page_token="ghi", + ), + index_service.ListIndexesResponse( + indexes=[ + index.Index(), + index.Index(), + ], ), - index_service.ListIndexesResponse(indexes=[index.Index(), index.Index(),],), RuntimeError, ) pages = [] - async for page_ in (await client.list_indexes(request={})).pages: + async for page_ in ( + await client.list_indexes(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_update_index( - transport: str = "grpc", request_type=index_service.UpdateIndexRequest -): +@pytest.mark.parametrize( + "request_type", + [ + index_service.UpdateIndexRequest, + dict, + ], +) +def test_update_index(request_type, transport: str = "grpc"): client = IndexServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1223,15 +1588,12 @@ def test_update_index( assert isinstance(response, future.Future) -def test_update_index_from_dict(): - test_update_index(request_type=dict) - - def test_update_index_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IndexServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1247,7 +1609,8 @@ async def test_update_index_async( transport: str = "grpc_asyncio", request_type=index_service.UpdateIndexRequest ): client = IndexServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1277,13 +1640,15 @@ async def test_update_index_async_from_dict(): def test_update_index_field_headers(): - client = IndexServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = index_service.UpdateIndexRequest() - request.index.name = "index.name/value" + request.index.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_index), "__call__") as call: @@ -1297,18 +1662,23 @@ def test_update_index_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "index.name=index.name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "index.name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_update_index_field_headers_async(): - client = IndexServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = index_service.UpdateIndexRequest() - request.index.name = "index.name/value" + request.index.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_index), "__call__") as call: @@ -1324,11 +1694,16 @@ async def test_update_index_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "index.name=index.name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "index.name=name_value", + ) in kw["metadata"] def test_update_index_flattened(): - client = IndexServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_index), "__call__") as call: @@ -1345,12 +1720,18 @@ def test_update_index_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].index == gca_index.Index(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].index + mock_val = gca_index.Index(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val def test_update_index_flattened_error(): - client = IndexServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1364,7 +1745,9 @@ def test_update_index_flattened_error(): @pytest.mark.asyncio async def test_update_index_flattened_async(): - client = IndexServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_index), "__call__") as call: @@ -1385,13 +1768,19 @@ async def test_update_index_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].index == gca_index.Index(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].index + mock_val = gca_index.Index(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val @pytest.mark.asyncio async def test_update_index_flattened_error_async(): - client = IndexServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1403,11 +1792,17 @@ async def test_update_index_flattened_error_async(): ) -def test_delete_index( - transport: str = "grpc", request_type=index_service.DeleteIndexRequest -): +@pytest.mark.parametrize( + "request_type", + [ + index_service.DeleteIndexRequest, + dict, + ], +) +def test_delete_index(request_type, transport: str = "grpc"): client = IndexServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1429,15 +1824,12 @@ def test_delete_index( assert isinstance(response, future.Future) -def test_delete_index_from_dict(): - test_delete_index(request_type=dict) - - def test_delete_index_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = IndexServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1453,7 +1845,8 @@ async def test_delete_index_async( transport: str = "grpc_asyncio", request_type=index_service.DeleteIndexRequest ): client = IndexServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1483,13 +1876,15 @@ async def test_delete_index_async_from_dict(): def test_delete_index_field_headers(): - client = IndexServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = index_service.DeleteIndexRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_index), "__call__") as call: @@ -1503,18 +1898,23 @@ def test_delete_index_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_delete_index_field_headers_async(): - client = IndexServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = index_service.DeleteIndexRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_index), "__call__") as call: @@ -1530,11 +1930,16 @@ async def test_delete_index_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_delete_index_flattened(): - client = IndexServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_index), "__call__") as call: @@ -1542,29 +1947,38 @@ def test_delete_index_flattened(): call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_index(name="name_value",) + client.delete_index( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_delete_index_flattened_error(): - client = IndexServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.delete_index( - index_service.DeleteIndexRequest(), name="name_value", + index_service.DeleteIndexRequest(), + name="name_value", ) @pytest.mark.asyncio async def test_delete_index_flattened_async(): - client = IndexServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_index), "__call__") as call: @@ -1576,24 +1990,31 @@ async def test_delete_index_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_index(name="name_value",) + response = await client.delete_index( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio async def test_delete_index_flattened_error_async(): - client = IndexServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.delete_index( - index_service.DeleteIndexRequest(), name="name_value", + index_service.DeleteIndexRequest(), + name="name_value", ) @@ -1604,7 +2025,8 @@ def test_credentials_transport_error(): ) with pytest.raises(ValueError): client = IndexServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # It is an error to provide a credentials file and a transport instance. @@ -1617,13 +2039,34 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.IndexServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = IndexServiceClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = IndexServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.IndexServiceGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = IndexServiceClient( - client_options={"scopes": ["1", "2"]}, transport=transport, + client_options={"scopes": ["1", "2"]}, + transport=transport, ) @@ -1666,10 +2109,28 @@ def test_transport_adc(transport_class): adc.assert_called_once() +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = IndexServiceClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + def test_transport_grpc_default(): # A client should use the gRPC transport by default. - client = IndexServiceClient(credentials=ga_credentials.AnonymousCredentials(),) - assert isinstance(client.transport, transports.IndexServiceGrpcTransport,) + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.IndexServiceGrpcTransport, + ) def test_index_service_base_transport_error(): @@ -1699,18 +2160,38 @@ def test_index_service_base_transport(): "list_indexes", "update_index", "delete_index", + "set_iam_policy", + "get_iam_policy", + "test_iam_permissions", + "get_location", + "list_locations", + "get_operation", + "wait_operation", + "cancel_operation", + "delete_operation", + "list_operations", ) for method in methods: with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + # Additionally, the LRO client (a property) should # also raise NotImplementedError with pytest.raises(NotImplementedError): transport.operations_client + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + -@requires_google_auth_gte_1_25_0 def test_index_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -1721,7 +2202,8 @@ def test_index_service_base_transport_with_credentials_file(): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.IndexServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", + credentials_file="credentials.json", + quota_project_id="octopus", ) load_creds.assert_called_once_with( "credentials.json", @@ -1731,26 +2213,6 @@ def test_index_service_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_index_service_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.aiplatform_v1beta1.services.index_service.transports.IndexServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.IndexServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - def test_index_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( @@ -1762,7 +2224,6 @@ def test_index_service_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_index_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -1775,18 +2236,6 @@ def test_index_service_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_index_service_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - IndexServiceClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -1794,7 +2243,6 @@ def test_index_service_auth_adc_old_google_auth(): transports.IndexServiceGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_index_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -1808,26 +2256,6 @@ def test_index_service_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.IndexServiceGrpcTransport, - transports.IndexServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_index_service_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ @@ -1835,7 +2263,6 @@ def test_index_service_transport_auth_adc_old_google_auth(transport_class): (transports.IndexServiceGrpcAsyncIOTransport, grpc_helpers_async), ], ) -@requires_api_core_gte_1_26_0 def test_index_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -1864,79 +2291,6 @@ def test_index_service_transport_create_channel(transport_class, grpc_helpers): ) -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.IndexServiceGrpcTransport, grpc_helpers), - (transports.IndexServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_index_service_transport_create_channel_old_api_core( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class(quota_project_id="octopus") - - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.IndexServiceGrpcTransport, grpc_helpers), - (transports.IndexServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_index_service_transport_create_channel_user_scopes( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=["1", "2"], - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - @pytest.mark.parametrize( "transport_class", [transports.IndexServiceGrpcTransport, transports.IndexServiceGrpcAsyncIOTransport], @@ -1956,7 +2310,7 @@ def test_index_service_grpc_transport_client_cert_source_for_mtls(transport_clas "squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_channel_creds, quota_project_id=None, options=[ @@ -1979,24 +2333,40 @@ def test_index_service_grpc_transport_client_cert_source_for_mtls(transport_clas ) -def test_index_service_host_no_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_index_service_host_no_port(transport_name): client = IndexServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="aiplatform.googleapis.com" ), + transport=transport_name, ) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") -def test_index_service_host_with_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_index_service_host_with_port(transport_name): client = IndexServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="aiplatform.googleapis.com:8000" ), + transport=transport_name, ) - assert client.transport._host == "aiplatform.googleapis.com:8000" + assert client.transport._host == ("aiplatform.googleapis.com:8000") def test_index_service_grpc_transport_channel(): @@ -2004,7 +2374,8 @@ def test_index_service_grpc_transport_channel(): # Check that channel is used if provided. transport = transports.IndexServiceGrpcTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -2016,7 +2387,8 @@ def test_index_service_grpc_asyncio_transport_channel(): # Check that channel is used if provided. transport = transports.IndexServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -2060,7 +2432,7 @@ def test_index_service_transport_channel_mtls_with_client_cert_source(transport_ "mtls.squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -2104,7 +2476,7 @@ def test_index_service_transport_channel_mtls_with_adc(transport_class): "mtls.squid.clam.whelk:443", credentials=mock_cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -2117,12 +2489,16 @@ def test_index_service_transport_channel_mtls_with_adc(transport_class): def test_index_service_grpc_lro_client(): client = IndexServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -2130,12 +2506,16 @@ def test_index_service_grpc_lro_client(): def test_index_service_grpc_lro_async_client(): client = IndexServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -2146,7 +2526,9 @@ def test_index_path(): location = "clam" index = "whelk" expected = "projects/{project}/locations/{location}/indexes/{index}".format( - project=project, location=location, index=index, + project=project, + location=location, + index=index, ) actual = IndexServiceClient.index_path(project, location, index) assert expected == actual @@ -2170,7 +2552,9 @@ def test_index_endpoint_path(): location = "mussel" index_endpoint = "winkle" expected = "projects/{project}/locations/{location}/indexEndpoints/{index_endpoint}".format( - project=project, location=location, index_endpoint=index_endpoint, + project=project, + location=location, + index_endpoint=index_endpoint, ) actual = IndexServiceClient.index_endpoint_path(project, location, index_endpoint) assert expected == actual @@ -2211,7 +2595,9 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "whelk" - expected = "folders/{folder}".format(folder=folder,) + expected = "folders/{folder}".format( + folder=folder, + ) actual = IndexServiceClient.common_folder_path(folder) assert expected == actual @@ -2229,7 +2615,9 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "oyster" - expected = "organizations/{organization}".format(organization=organization,) + expected = "organizations/{organization}".format( + organization=organization, + ) actual = IndexServiceClient.common_organization_path(organization) assert expected == actual @@ -2247,7 +2635,9 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "cuttlefish" - expected = "projects/{project}".format(project=project,) + expected = "projects/{project}".format( + project=project, + ) actual = IndexServiceClient.common_project_path(project) assert expected == actual @@ -2267,7 +2657,8 @@ def test_common_location_path(): project = "winkle" location = "nautilus" expected = "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) actual = IndexServiceClient.common_location_path(project, location) assert expected == actual @@ -2285,14 +2676,15 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( transports.IndexServiceTransport, "_prep_wrapped_messages" ) as prep: client = IndexServiceClient( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2301,6 +2693,1591 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = IndexServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_delete_operation(transport: str = "grpc"): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_operation(transport: str = "grpc"): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_operation_field_headers(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = None + + client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_operation_field_headers_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_delete_operation_from_dict(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_delete_operation_from_dict_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_cancel_operation(transport: str = "grpc"): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation(transport: str = "grpc"): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_wait_operation(transport: str = "grpc"): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_wait_operation(transport: str = "grpc"): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_wait_operation_field_headers(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_wait_operation_field_headers_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_wait_operation_from_dict(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_wait_operation_from_dict_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_operation(transport: str = "grpc"): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_get_operation(transport: str = "grpc"): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_get_operation_field_headers(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_get_operation_from_dict(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_operations(transport: str = "grpc"): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + response = client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +@pytest.mark.asyncio +async def test_list_operations(transport: str = "grpc"): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +def test_list_operations_field_headers(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_operations_field_headers_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_operations_from_dict(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + response = client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_operations_from_dict_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_locations(transport: str = "grpc"): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + response = client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +@pytest.mark.asyncio +async def test_list_locations(transport: str = "grpc"): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +def test_list_locations_field_headers(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_locations_field_headers_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_locations_from_dict(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + response = client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_locations_from_dict_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_location(transport: str = "grpc"): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + response = client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +@pytest.mark.asyncio +async def test_get_location_async(transport: str = "grpc_asyncio"): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +def test_get_location_field_headers(): + client = IndexServiceClient(credentials=ga_credentials.AnonymousCredentials()) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = locations_pb2.Location() + + client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_location_field_headers_async(): + client = IndexServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials()) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +def test_get_location_from_dict(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + response = client.get_location( + request={ + "name": "locations/abc", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_location_from_dict_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_set_iam_policy(transport: str = "grpc"): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + response = client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + response = await client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_set_iam_policy_field_headers(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_set_iam_policy_field_headers_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_set_iam_policy_from_dict(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_set_iam_policy_from_dict_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +def test_get_iam_policy(transport: str = "grpc"): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + + response = client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + + response = await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_get_iam_policy_field_headers(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_iam_policy_field_headers_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_get_iam_policy_from_dict(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_iam_policy_from_dict_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +def test_test_iam_permissions(transport: str = "grpc"): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + + response = client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + ) + + response = await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +def test_test_iam_permissions_field_headers(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_field_headers_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_test_iam_permissions_from_dict(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + response = client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_from_dict_async(): + client = IndexServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + response = await client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = IndexServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (IndexServiceClient, transports.IndexServiceGrpcTransport), + (IndexServiceAsyncClient, transports.IndexServiceGrpcAsyncIOTransport), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) diff --git a/tests/unit/gapic/aiplatform_v1beta1/test_job_service.py b/tests/unit/gapic/aiplatform_v1beta1/test_job_service.py index 700ebee54b..4fb1425083 100644 --- a/tests/unit/gapic/aiplatform_v1beta1/test_job_service.py +++ b/tests/unit/gapic/aiplatform_v1beta1/test_job_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,8 +14,13 @@ # limitations under the License. # import os -import mock -import packaging.version + +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock +except ImportError: + import mock import grpc from grpc.experimental import aio @@ -30,20 +35,16 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.aiplatform_v1beta1.services.job_service import JobServiceAsyncClient from google.cloud.aiplatform_v1beta1.services.job_service import JobServiceClient from google.cloud.aiplatform_v1beta1.services.job_service import pagers from google.cloud.aiplatform_v1beta1.services.job_service import transports -from google.cloud.aiplatform_v1beta1.services.job_service.transports.base import ( - _API_CORE_VERSION, -) -from google.cloud.aiplatform_v1beta1.services.job_service.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.aiplatform_v1beta1.types import accelerator_type from google.cloud.aiplatform_v1beta1.types import batch_prediction_job from google.cloud.aiplatform_v1beta1.types import ( @@ -57,6 +58,7 @@ data_labeling_job as gca_data_labeling_job, ) from google.cloud.aiplatform_v1beta1.types import encryption_spec +from google.cloud.aiplatform_v1beta1.types import env_var from google.cloud.aiplatform_v1beta1.types import explanation from google.cloud.aiplatform_v1beta1.types import explanation_metadata from google.cloud.aiplatform_v1beta1.types import hyperparameter_tuning_job @@ -68,6 +70,7 @@ from google.cloud.aiplatform_v1beta1.types import job_state from google.cloud.aiplatform_v1beta1.types import machine_resources from google.cloud.aiplatform_v1beta1.types import manual_batch_tuning_parameters +from google.cloud.aiplatform_v1beta1.types import model from google.cloud.aiplatform_v1beta1.types import model_deployment_monitoring_job from google.cloud.aiplatform_v1beta1.types import ( model_deployment_monitoring_job as gca_model_deployment_monitoring_job, @@ -75,6 +78,11 @@ from google.cloud.aiplatform_v1beta1.types import model_monitoring from google.cloud.aiplatform_v1beta1.types import operation as gca_operation from google.cloud.aiplatform_v1beta1.types import study +from google.cloud.aiplatform_v1beta1.types import unmanaged_container_model +from google.cloud.location import locations_pb2 +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 from google.oauth2 import service_account from google.protobuf import any_pb2 # type: ignore @@ -87,29 +95,6 @@ import google.auth -# TODO(busunkim): Once google-api-core >= 1.26.0 is required: -# - Delete all the api-core and auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - -requires_api_core_lt_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), - reason="This test requires google-api-core < 1.26.0", -) - -requires_api_core_gte_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), - reason="This test requires google-api-core >= 1.26.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -151,37 +136,78 @@ def test__get_default_mtls_endpoint(): assert JobServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi -@pytest.mark.parametrize("client_class", [JobServiceClient, JobServiceAsyncClient,]) -def test_job_service_client_from_service_account_info(client_class): +@pytest.mark.parametrize( + "client_class,transport_name", + [ + (JobServiceClient, "grpc"), + (JobServiceAsyncClient, "grpc_asyncio"), + ], +) +def test_job_service_client_from_service_account_info(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") + +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.JobServiceGrpcTransport, "grpc"), + (transports.JobServiceGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_job_service_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() -@pytest.mark.parametrize("client_class", [JobServiceClient, JobServiceAsyncClient,]) -def test_job_service_client_from_service_account_file(client_class): + +@pytest.mark.parametrize( + "client_class,transport_name", + [ + (JobServiceClient, "grpc"), + (JobServiceAsyncClient, "grpc_asyncio"), + ], +) +def test_job_service_client_from_service_account_file(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") def test_job_service_client_get_transport_class(): @@ -232,7 +258,7 @@ def test_job_service_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -241,6 +267,7 @@ def test_job_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -248,7 +275,7 @@ def test_job_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -257,6 +284,7 @@ def test_job_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -264,7 +292,7 @@ def test_job_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -273,26 +301,27 @@ def test_job_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -301,6 +330,7 @@ def test_job_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -348,7 +378,7 @@ def test_job_service_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -365,6 +395,7 @@ def test_job_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case ADC client cert is provided. Whether client cert is used depends on @@ -389,7 +420,7 @@ def test_job_service_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -398,6 +429,7 @@ def test_job_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case client_cert_source and ADC client cert are not provided. @@ -410,7 +442,7 @@ def test_job_service_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -419,9 +451,87 @@ def test_job_service_client_mtls_env_auto( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) +@pytest.mark.parametrize("client_class", [JobServiceClient, JobServiceAsyncClient]) +@mock.patch.object( + JobServiceClient, "DEFAULT_ENDPOINT", modify_default_endpoint(JobServiceClient) +) +@mock.patch.object( + JobServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(JobServiceAsyncClient), +) +def test_job_service_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + @pytest.mark.parametrize( "client_class,transport_class,transport_name", [ @@ -437,10 +547,12 @@ def test_job_service_client_client_options_scopes( client_class, transport_class, transport_name ): # Check the case scopes are provided. - options = client_options.ClientOptions(scopes=["1", "2"],) + options = client_options.ClientOptions( + scopes=["1", "2"], + ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -449,28 +561,31 @@ def test_job_service_client_client_options_scopes( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (JobServiceClient, transports.JobServiceGrpcTransport, "grpc"), + (JobServiceClient, transports.JobServiceGrpcTransport, "grpc", grpc_helpers), ( JobServiceAsyncClient, transports.JobServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_job_service_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -479,6 +594,7 @@ def test_job_service_client_client_options_credentials_file( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -496,14 +612,82 @@ def test_job_service_client_client_options_from_dict(): client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) -def test_create_custom_job( - transport: str = "grpc", request_type=job_service.CreateCustomJobRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + (JobServiceClient, transports.JobServiceGrpcTransport, "grpc", grpc_helpers), + ( + JobServiceAsyncClient, + transports.JobServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_job_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers ): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + job_service.CreateCustomJobRequest, + dict, + ], +) +def test_create_custom_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -534,15 +718,12 @@ def test_create_custom_job( assert response.state == job_state.JobState.JOB_STATE_QUEUED -def test_create_custom_job_from_dict(): - test_create_custom_job(request_type=dict) - - def test_create_custom_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -560,7 +741,8 @@ async def test_create_custom_job_async( transport: str = "grpc_asyncio", request_type=job_service.CreateCustomJobRequest ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -599,13 +781,15 @@ async def test_create_custom_job_async_from_dict(): def test_create_custom_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.CreateCustomJobRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -621,18 +805,23 @@ def test_create_custom_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_create_custom_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.CreateCustomJobRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -650,11 +839,16 @@ async def test_create_custom_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_create_custom_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -673,12 +867,18 @@ def test_create_custom_job_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].custom_job == gca_custom_job.CustomJob(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].custom_job + mock_val = gca_custom_job.CustomJob(name="name_value") + assert arg == mock_val def test_create_custom_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -692,7 +892,9 @@ def test_create_custom_job_flattened_error(): @pytest.mark.asyncio async def test_create_custom_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -715,13 +917,19 @@ async def test_create_custom_job_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].custom_job == gca_custom_job.CustomJob(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].custom_job + mock_val = gca_custom_job.CustomJob(name="name_value") + assert arg == mock_val @pytest.mark.asyncio async def test_create_custom_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -733,11 +941,17 @@ async def test_create_custom_job_flattened_error_async(): ) -def test_get_custom_job( - transport: str = "grpc", request_type=job_service.GetCustomJobRequest -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.GetCustomJobRequest, + dict, + ], +) +def test_get_custom_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -766,15 +980,12 @@ def test_get_custom_job( assert response.state == job_state.JobState.JOB_STATE_QUEUED -def test_get_custom_job_from_dict(): - test_get_custom_job(request_type=dict) - - def test_get_custom_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -790,7 +1001,8 @@ async def test_get_custom_job_async( transport: str = "grpc_asyncio", request_type=job_service.GetCustomJobRequest ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -827,13 +1039,15 @@ async def test_get_custom_job_async_from_dict(): def test_get_custom_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.GetCustomJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_custom_job), "__call__") as call: @@ -847,18 +1061,23 @@ def test_get_custom_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_get_custom_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.GetCustomJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_custom_job), "__call__") as call: @@ -874,11 +1093,16 @@ async def test_get_custom_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_get_custom_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_custom_job), "__call__") as call: @@ -886,29 +1110,38 @@ def test_get_custom_job_flattened(): call.return_value = custom_job.CustomJob() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_custom_job(name="name_value",) + client.get_custom_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_custom_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.get_custom_job( - job_service.GetCustomJobRequest(), name="name_value", + job_service.GetCustomJobRequest(), + name="name_value", ) @pytest.mark.asyncio async def test_get_custom_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_custom_job), "__call__") as call: @@ -920,32 +1153,45 @@ async def test_get_custom_job_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_custom_job(name="name_value",) + response = await client.get_custom_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio async def test_get_custom_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.get_custom_job( - job_service.GetCustomJobRequest(), name="name_value", + job_service.GetCustomJobRequest(), + name="name_value", ) -def test_list_custom_jobs( - transport: str = "grpc", request_type=job_service.ListCustomJobsRequest -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.ListCustomJobsRequest, + dict, + ], +) +def test_list_custom_jobs(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -970,15 +1216,12 @@ def test_list_custom_jobs( assert response.next_page_token == "next_page_token_value" -def test_list_custom_jobs_from_dict(): - test_list_custom_jobs(request_type=dict) - - def test_list_custom_jobs_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -994,7 +1237,8 @@ async def test_list_custom_jobs_async( transport: str = "grpc_asyncio", request_type=job_service.ListCustomJobsRequest ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1005,7 +1249,9 @@ async def test_list_custom_jobs_async( with mock.patch.object(type(client.transport.list_custom_jobs), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - job_service.ListCustomJobsResponse(next_page_token="next_page_token_value",) + job_service.ListCustomJobsResponse( + next_page_token="next_page_token_value", + ) ) response = await client.list_custom_jobs(request) @@ -1025,13 +1271,15 @@ async def test_list_custom_jobs_async_from_dict(): def test_list_custom_jobs_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.ListCustomJobsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_custom_jobs), "__call__") as call: @@ -1045,18 +1293,23 @@ def test_list_custom_jobs_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_list_custom_jobs_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.ListCustomJobsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_custom_jobs), "__call__") as call: @@ -1072,11 +1325,16 @@ async def test_list_custom_jobs_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_custom_jobs_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_custom_jobs), "__call__") as call: @@ -1084,29 +1342,38 @@ def test_list_custom_jobs_flattened(): call.return_value = job_service.ListCustomJobsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_custom_jobs(parent="parent_value",) + client.list_custom_jobs( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_custom_jobs_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.list_custom_jobs( - job_service.ListCustomJobsRequest(), parent="parent_value", + job_service.ListCustomJobsRequest(), + parent="parent_value", ) @pytest.mark.asyncio async def test_list_custom_jobs_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_custom_jobs), "__call__") as call: @@ -1118,29 +1385,39 @@ async def test_list_custom_jobs_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_custom_jobs(parent="parent_value",) + response = await client.list_custom_jobs( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio async def test_list_custom_jobs_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.list_custom_jobs( - job_service.ListCustomJobsRequest(), parent="parent_value", + job_service.ListCustomJobsRequest(), + parent="parent_value", ) -def test_list_custom_jobs_pager(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_custom_jobs_pager(transport_name: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_custom_jobs), "__call__") as call: @@ -1154,12 +1431,21 @@ def test_list_custom_jobs_pager(): ], next_page_token="abc", ), - job_service.ListCustomJobsResponse(custom_jobs=[], next_page_token="def",), job_service.ListCustomJobsResponse( - custom_jobs=[custom_job.CustomJob(),], next_page_token="ghi", + custom_jobs=[], + next_page_token="def", + ), + job_service.ListCustomJobsResponse( + custom_jobs=[ + custom_job.CustomJob(), + ], + next_page_token="ghi", ), job_service.ListCustomJobsResponse( - custom_jobs=[custom_job.CustomJob(), custom_job.CustomJob(),], + custom_jobs=[ + custom_job.CustomJob(), + custom_job.CustomJob(), + ], ), RuntimeError, ) @@ -1172,13 +1458,16 @@ def test_list_custom_jobs_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all(isinstance(i, custom_job.CustomJob) for i in results) -def test_list_custom_jobs_pages(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_custom_jobs_pages(transport_name: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_custom_jobs), "__call__") as call: @@ -1192,12 +1481,21 @@ def test_list_custom_jobs_pages(): ], next_page_token="abc", ), - job_service.ListCustomJobsResponse(custom_jobs=[], next_page_token="def",), job_service.ListCustomJobsResponse( - custom_jobs=[custom_job.CustomJob(),], next_page_token="ghi", + custom_jobs=[], + next_page_token="def", + ), + job_service.ListCustomJobsResponse( + custom_jobs=[ + custom_job.CustomJob(), + ], + next_page_token="ghi", ), job_service.ListCustomJobsResponse( - custom_jobs=[custom_job.CustomJob(), custom_job.CustomJob(),], + custom_jobs=[ + custom_job.CustomJob(), + custom_job.CustomJob(), + ], ), RuntimeError, ) @@ -1208,7 +1506,9 @@ def test_list_custom_jobs_pages(): @pytest.mark.asyncio async def test_list_custom_jobs_async_pager(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1224,19 +1524,30 @@ async def test_list_custom_jobs_async_pager(): ], next_page_token="abc", ), - job_service.ListCustomJobsResponse(custom_jobs=[], next_page_token="def",), job_service.ListCustomJobsResponse( - custom_jobs=[custom_job.CustomJob(),], next_page_token="ghi", + custom_jobs=[], + next_page_token="def", ), job_service.ListCustomJobsResponse( - custom_jobs=[custom_job.CustomJob(), custom_job.CustomJob(),], + custom_jobs=[ + custom_job.CustomJob(), + ], + next_page_token="ghi", ), - RuntimeError, + job_service.ListCustomJobsResponse( + custom_jobs=[ + custom_job.CustomJob(), + custom_job.CustomJob(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_custom_jobs( + request={}, ) - async_pager = await client.list_custom_jobs(request={},) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -1245,7 +1556,9 @@ async def test_list_custom_jobs_async_pager(): @pytest.mark.asyncio async def test_list_custom_jobs_async_pages(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1261,27 +1574,44 @@ async def test_list_custom_jobs_async_pages(): ], next_page_token="abc", ), - job_service.ListCustomJobsResponse(custom_jobs=[], next_page_token="def",), job_service.ListCustomJobsResponse( - custom_jobs=[custom_job.CustomJob(),], next_page_token="ghi", + custom_jobs=[], + next_page_token="def", + ), + job_service.ListCustomJobsResponse( + custom_jobs=[ + custom_job.CustomJob(), + ], + next_page_token="ghi", ), job_service.ListCustomJobsResponse( - custom_jobs=[custom_job.CustomJob(), custom_job.CustomJob(),], + custom_jobs=[ + custom_job.CustomJob(), + custom_job.CustomJob(), + ], ), RuntimeError, ) pages = [] - async for page_ in (await client.list_custom_jobs(request={})).pages: + async for page_ in ( + await client.list_custom_jobs(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_delete_custom_job( - transport: str = "grpc", request_type=job_service.DeleteCustomJobRequest -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.DeleteCustomJobRequest, + dict, + ], +) +def test_delete_custom_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1305,15 +1635,12 @@ def test_delete_custom_job( assert isinstance(response, future.Future) -def test_delete_custom_job_from_dict(): - test_delete_custom_job(request_type=dict) - - def test_delete_custom_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1331,7 +1658,8 @@ async def test_delete_custom_job_async( transport: str = "grpc_asyncio", request_type=job_service.DeleteCustomJobRequest ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1363,13 +1691,15 @@ async def test_delete_custom_job_async_from_dict(): def test_delete_custom_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.DeleteCustomJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1385,18 +1715,23 @@ def test_delete_custom_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_delete_custom_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.DeleteCustomJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1414,11 +1749,16 @@ async def test_delete_custom_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_delete_custom_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1428,29 +1768,38 @@ def test_delete_custom_job_flattened(): call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_custom_job(name="name_value",) + client.delete_custom_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_delete_custom_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.delete_custom_job( - job_service.DeleteCustomJobRequest(), name="name_value", + job_service.DeleteCustomJobRequest(), + name="name_value", ) @pytest.mark.asyncio async def test_delete_custom_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1464,32 +1813,45 @@ async def test_delete_custom_job_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_custom_job(name="name_value",) + response = await client.delete_custom_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio async def test_delete_custom_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.delete_custom_job( - job_service.DeleteCustomJobRequest(), name="name_value", + job_service.DeleteCustomJobRequest(), + name="name_value", ) -def test_cancel_custom_job( - transport: str = "grpc", request_type=job_service.CancelCustomJobRequest -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.CancelCustomJobRequest, + dict, + ], +) +def test_cancel_custom_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1513,15 +1875,12 @@ def test_cancel_custom_job( assert response is None -def test_cancel_custom_job_from_dict(): - test_cancel_custom_job(request_type=dict) - - def test_cancel_custom_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1539,7 +1898,8 @@ async def test_cancel_custom_job_async( transport: str = "grpc_asyncio", request_type=job_service.CancelCustomJobRequest ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1569,13 +1929,15 @@ async def test_cancel_custom_job_async_from_dict(): def test_cancel_custom_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.CancelCustomJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1591,18 +1953,23 @@ def test_cancel_custom_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_cancel_custom_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.CancelCustomJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1618,11 +1985,16 @@ async def test_cancel_custom_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_cancel_custom_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1632,29 +2004,38 @@ def test_cancel_custom_job_flattened(): call.return_value = None # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.cancel_custom_job(name="name_value",) + client.cancel_custom_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_cancel_custom_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.cancel_custom_job( - job_service.CancelCustomJobRequest(), name="name_value", + job_service.CancelCustomJobRequest(), + name="name_value", ) @pytest.mark.asyncio async def test_cancel_custom_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1666,32 +2047,45 @@ async def test_cancel_custom_job_flattened_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.cancel_custom_job(name="name_value",) + response = await client.cancel_custom_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio async def test_cancel_custom_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.cancel_custom_job( - job_service.CancelCustomJobRequest(), name="name_value", + job_service.CancelCustomJobRequest(), + name="name_value", ) -def test_create_data_labeling_job( - transport: str = "grpc", request_type=job_service.CreateDataLabelingJobRequest -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.CreateDataLabelingJobRequest, + dict, + ], +) +def test_create_data_labeling_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1734,15 +2128,12 @@ def test_create_data_labeling_job( assert response.specialist_pools == ["specialist_pools_value"] -def test_create_data_labeling_job_from_dict(): - test_create_data_labeling_job(request_type=dict) - - def test_create_data_labeling_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1761,7 +2152,8 @@ async def test_create_data_labeling_job_async( request_type=job_service.CreateDataLabelingJobRequest, ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1812,13 +2204,15 @@ async def test_create_data_labeling_job_async_from_dict(): def test_create_data_labeling_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.CreateDataLabelingJobRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1834,18 +2228,23 @@ def test_create_data_labeling_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_create_data_labeling_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.CreateDataLabelingJobRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1863,11 +2262,16 @@ async def test_create_data_labeling_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_create_data_labeling_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1886,14 +2290,18 @@ def test_create_data_labeling_job_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].data_labeling_job == gca_data_labeling_job.DataLabelingJob( - name="name_value" - ) + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].data_labeling_job + mock_val = gca_data_labeling_job.DataLabelingJob(name="name_value") + assert arg == mock_val def test_create_data_labeling_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1907,7 +2315,9 @@ def test_create_data_labeling_job_flattened_error(): @pytest.mark.asyncio async def test_create_data_labeling_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1930,15 +2340,19 @@ async def test_create_data_labeling_job_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].data_labeling_job == gca_data_labeling_job.DataLabelingJob( - name="name_value" - ) + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].data_labeling_job + mock_val = gca_data_labeling_job.DataLabelingJob(name="name_value") + assert arg == mock_val @pytest.mark.asyncio async def test_create_data_labeling_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1950,11 +2364,17 @@ async def test_create_data_labeling_job_flattened_error_async(): ) -def test_get_data_labeling_job( - transport: str = "grpc", request_type=job_service.GetDataLabelingJobRequest -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.GetDataLabelingJobRequest, + dict, + ], +) +def test_get_data_labeling_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1997,15 +2417,12 @@ def test_get_data_labeling_job( assert response.specialist_pools == ["specialist_pools_value"] -def test_get_data_labeling_job_from_dict(): - test_get_data_labeling_job(request_type=dict) - - def test_get_data_labeling_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2023,7 +2440,8 @@ async def test_get_data_labeling_job_async( transport: str = "grpc_asyncio", request_type=job_service.GetDataLabelingJobRequest ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2074,13 +2492,15 @@ async def test_get_data_labeling_job_async_from_dict(): def test_get_data_labeling_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.GetDataLabelingJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2096,18 +2516,23 @@ def test_get_data_labeling_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_get_data_labeling_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.GetDataLabelingJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2125,11 +2550,16 @@ async def test_get_data_labeling_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_get_data_labeling_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2139,29 +2569,38 @@ def test_get_data_labeling_job_flattened(): call.return_value = data_labeling_job.DataLabelingJob() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_data_labeling_job(name="name_value",) + client.get_data_labeling_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_data_labeling_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.get_data_labeling_job( - job_service.GetDataLabelingJobRequest(), name="name_value", + job_service.GetDataLabelingJobRequest(), + name="name_value", ) @pytest.mark.asyncio async def test_get_data_labeling_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2175,32 +2614,45 @@ async def test_get_data_labeling_job_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_data_labeling_job(name="name_value",) + response = await client.get_data_labeling_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio async def test_get_data_labeling_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.get_data_labeling_job( - job_service.GetDataLabelingJobRequest(), name="name_value", + job_service.GetDataLabelingJobRequest(), + name="name_value", ) -def test_list_data_labeling_jobs( - transport: str = "grpc", request_type=job_service.ListDataLabelingJobsRequest -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.ListDataLabelingJobsRequest, + dict, + ], +) +def test_list_data_labeling_jobs(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2227,15 +2679,12 @@ def test_list_data_labeling_jobs( assert response.next_page_token == "next_page_token_value" -def test_list_data_labeling_jobs_from_dict(): - test_list_data_labeling_jobs(request_type=dict) - - def test_list_data_labeling_jobs_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2254,7 +2703,8 @@ async def test_list_data_labeling_jobs_async( request_type=job_service.ListDataLabelingJobsRequest, ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2289,13 +2739,15 @@ async def test_list_data_labeling_jobs_async_from_dict(): def test_list_data_labeling_jobs_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.ListDataLabelingJobsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2311,18 +2763,23 @@ def test_list_data_labeling_jobs_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_list_data_labeling_jobs_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.ListDataLabelingJobsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2340,11 +2797,16 @@ async def test_list_data_labeling_jobs_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_data_labeling_jobs_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2354,29 +2816,38 @@ def test_list_data_labeling_jobs_flattened(): call.return_value = job_service.ListDataLabelingJobsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_data_labeling_jobs(parent="parent_value",) + client.list_data_labeling_jobs( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_data_labeling_jobs_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.list_data_labeling_jobs( - job_service.ListDataLabelingJobsRequest(), parent="parent_value", + job_service.ListDataLabelingJobsRequest(), + parent="parent_value", ) @pytest.mark.asyncio async def test_list_data_labeling_jobs_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2390,29 +2861,39 @@ async def test_list_data_labeling_jobs_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_data_labeling_jobs(parent="parent_value",) + response = await client.list_data_labeling_jobs( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio async def test_list_data_labeling_jobs_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.list_data_labeling_jobs( - job_service.ListDataLabelingJobsRequest(), parent="parent_value", + job_service.ListDataLabelingJobsRequest(), + parent="parent_value", ) -def test_list_data_labeling_jobs_pager(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_data_labeling_jobs_pager(transport_name: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2429,10 +2910,13 @@ def test_list_data_labeling_jobs_pager(): next_page_token="abc", ), job_service.ListDataLabelingJobsResponse( - data_labeling_jobs=[], next_page_token="def", + data_labeling_jobs=[], + next_page_token="def", ), job_service.ListDataLabelingJobsResponse( - data_labeling_jobs=[data_labeling_job.DataLabelingJob(),], + data_labeling_jobs=[ + data_labeling_job.DataLabelingJob(), + ], next_page_token="ghi", ), job_service.ListDataLabelingJobsResponse( @@ -2452,13 +2936,16 @@ def test_list_data_labeling_jobs_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all(isinstance(i, data_labeling_job.DataLabelingJob) for i in results) -def test_list_data_labeling_jobs_pages(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_data_labeling_jobs_pages(transport_name: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2475,10 +2962,13 @@ def test_list_data_labeling_jobs_pages(): next_page_token="abc", ), job_service.ListDataLabelingJobsResponse( - data_labeling_jobs=[], next_page_token="def", + data_labeling_jobs=[], + next_page_token="def", ), job_service.ListDataLabelingJobsResponse( - data_labeling_jobs=[data_labeling_job.DataLabelingJob(),], + data_labeling_jobs=[ + data_labeling_job.DataLabelingJob(), + ], next_page_token="ghi", ), job_service.ListDataLabelingJobsResponse( @@ -2496,7 +2986,9 @@ def test_list_data_labeling_jobs_pages(): @pytest.mark.asyncio async def test_list_data_labeling_jobs_async_pager(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2515,10 +3007,13 @@ async def test_list_data_labeling_jobs_async_pager(): next_page_token="abc", ), job_service.ListDataLabelingJobsResponse( - data_labeling_jobs=[], next_page_token="def", + data_labeling_jobs=[], + next_page_token="def", ), job_service.ListDataLabelingJobsResponse( - data_labeling_jobs=[data_labeling_job.DataLabelingJob(),], + data_labeling_jobs=[ + data_labeling_job.DataLabelingJob(), + ], next_page_token="ghi", ), job_service.ListDataLabelingJobsResponse( @@ -2529,10 +3024,12 @@ async def test_list_data_labeling_jobs_async_pager(): ), RuntimeError, ) - async_pager = await client.list_data_labeling_jobs(request={},) + async_pager = await client.list_data_labeling_jobs( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -2541,7 +3038,9 @@ async def test_list_data_labeling_jobs_async_pager(): @pytest.mark.asyncio async def test_list_data_labeling_jobs_async_pages(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2560,10 +3059,13 @@ async def test_list_data_labeling_jobs_async_pages(): next_page_token="abc", ), job_service.ListDataLabelingJobsResponse( - data_labeling_jobs=[], next_page_token="def", + data_labeling_jobs=[], + next_page_token="def", ), job_service.ListDataLabelingJobsResponse( - data_labeling_jobs=[data_labeling_job.DataLabelingJob(),], + data_labeling_jobs=[ + data_labeling_job.DataLabelingJob(), + ], next_page_token="ghi", ), job_service.ListDataLabelingJobsResponse( @@ -2575,17 +3077,25 @@ async def test_list_data_labeling_jobs_async_pages(): RuntimeError, ) pages = [] - async for page_ in (await client.list_data_labeling_jobs(request={})).pages: + async for page_ in ( + await client.list_data_labeling_jobs(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_delete_data_labeling_job( - transport: str = "grpc", request_type=job_service.DeleteDataLabelingJobRequest -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.DeleteDataLabelingJobRequest, + dict, + ], +) +def test_delete_data_labeling_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2609,15 +3119,12 @@ def test_delete_data_labeling_job( assert isinstance(response, future.Future) -def test_delete_data_labeling_job_from_dict(): - test_delete_data_labeling_job(request_type=dict) - - def test_delete_data_labeling_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2636,7 +3143,8 @@ async def test_delete_data_labeling_job_async( request_type=job_service.DeleteDataLabelingJobRequest, ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2668,13 +3176,15 @@ async def test_delete_data_labeling_job_async_from_dict(): def test_delete_data_labeling_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.DeleteDataLabelingJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2690,18 +3200,23 @@ def test_delete_data_labeling_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_delete_data_labeling_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.DeleteDataLabelingJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2719,11 +3234,16 @@ async def test_delete_data_labeling_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_delete_data_labeling_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2733,29 +3253,38 @@ def test_delete_data_labeling_job_flattened(): call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_data_labeling_job(name="name_value",) + client.delete_data_labeling_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_delete_data_labeling_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.delete_data_labeling_job( - job_service.DeleteDataLabelingJobRequest(), name="name_value", + job_service.DeleteDataLabelingJobRequest(), + name="name_value", ) @pytest.mark.asyncio async def test_delete_data_labeling_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2769,32 +3298,45 @@ async def test_delete_data_labeling_job_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_data_labeling_job(name="name_value",) + response = await client.delete_data_labeling_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio async def test_delete_data_labeling_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.delete_data_labeling_job( - job_service.DeleteDataLabelingJobRequest(), name="name_value", + job_service.DeleteDataLabelingJobRequest(), + name="name_value", ) -def test_cancel_data_labeling_job( - transport: str = "grpc", request_type=job_service.CancelDataLabelingJobRequest -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.CancelDataLabelingJobRequest, + dict, + ], +) +def test_cancel_data_labeling_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2818,15 +3360,12 @@ def test_cancel_data_labeling_job( assert response is None -def test_cancel_data_labeling_job_from_dict(): - test_cancel_data_labeling_job(request_type=dict) - - def test_cancel_data_labeling_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2845,7 +3384,8 @@ async def test_cancel_data_labeling_job_async( request_type=job_service.CancelDataLabelingJobRequest, ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2875,13 +3415,15 @@ async def test_cancel_data_labeling_job_async_from_dict(): def test_cancel_data_labeling_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.CancelDataLabelingJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2897,18 +3439,23 @@ def test_cancel_data_labeling_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_cancel_data_labeling_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.CancelDataLabelingJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2924,11 +3471,16 @@ async def test_cancel_data_labeling_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_cancel_data_labeling_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2938,29 +3490,38 @@ def test_cancel_data_labeling_job_flattened(): call.return_value = None # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.cancel_data_labeling_job(name="name_value",) + client.cancel_data_labeling_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_cancel_data_labeling_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.cancel_data_labeling_job( - job_service.CancelDataLabelingJobRequest(), name="name_value", + job_service.CancelDataLabelingJobRequest(), + name="name_value", ) @pytest.mark.asyncio async def test_cancel_data_labeling_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2972,33 +3533,45 @@ async def test_cancel_data_labeling_job_flattened_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.cancel_data_labeling_job(name="name_value",) + response = await client.cancel_data_labeling_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio async def test_cancel_data_labeling_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.cancel_data_labeling_job( - job_service.CancelDataLabelingJobRequest(), name="name_value", + job_service.CancelDataLabelingJobRequest(), + name="name_value", ) -def test_create_hyperparameter_tuning_job( - transport: str = "grpc", - request_type=job_service.CreateHyperparameterTuningJobRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.CreateHyperparameterTuningJobRequest, + dict, + ], +) +def test_create_hyperparameter_tuning_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3035,15 +3608,12 @@ def test_create_hyperparameter_tuning_job( assert response.state == job_state.JobState.JOB_STATE_QUEUED -def test_create_hyperparameter_tuning_job_from_dict(): - test_create_hyperparameter_tuning_job(request_type=dict) - - def test_create_hyperparameter_tuning_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3062,7 +3632,8 @@ async def test_create_hyperparameter_tuning_job_async( request_type=job_service.CreateHyperparameterTuningJobRequest, ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3107,13 +3678,15 @@ async def test_create_hyperparameter_tuning_job_async_from_dict(): def test_create_hyperparameter_tuning_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.CreateHyperparameterTuningJobRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3129,18 +3702,23 @@ def test_create_hyperparameter_tuning_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_create_hyperparameter_tuning_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.CreateHyperparameterTuningJobRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3158,11 +3736,16 @@ async def test_create_hyperparameter_tuning_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_create_hyperparameter_tuning_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3183,16 +3766,20 @@ def test_create_hyperparameter_tuning_job_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[ - 0 - ].hyperparameter_tuning_job == gca_hyperparameter_tuning_job.HyperparameterTuningJob( + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].hyperparameter_tuning_job + mock_val = gca_hyperparameter_tuning_job.HyperparameterTuningJob( name="name_value" ) + assert arg == mock_val def test_create_hyperparameter_tuning_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -3208,7 +3795,9 @@ def test_create_hyperparameter_tuning_job_flattened_error(): @pytest.mark.asyncio async def test_create_hyperparameter_tuning_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3233,17 +3822,21 @@ async def test_create_hyperparameter_tuning_job_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[ - 0 - ].hyperparameter_tuning_job == gca_hyperparameter_tuning_job.HyperparameterTuningJob( + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].hyperparameter_tuning_job + mock_val = gca_hyperparameter_tuning_job.HyperparameterTuningJob( name="name_value" ) + assert arg == mock_val @pytest.mark.asyncio async def test_create_hyperparameter_tuning_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -3257,11 +3850,17 @@ async def test_create_hyperparameter_tuning_job_flattened_error_async(): ) -def test_get_hyperparameter_tuning_job( - transport: str = "grpc", request_type=job_service.GetHyperparameterTuningJobRequest -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.GetHyperparameterTuningJobRequest, + dict, + ], +) +def test_get_hyperparameter_tuning_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3298,15 +3897,12 @@ def test_get_hyperparameter_tuning_job( assert response.state == job_state.JobState.JOB_STATE_QUEUED -def test_get_hyperparameter_tuning_job_from_dict(): - test_get_hyperparameter_tuning_job(request_type=dict) - - def test_get_hyperparameter_tuning_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3325,7 +3921,8 @@ async def test_get_hyperparameter_tuning_job_async( request_type=job_service.GetHyperparameterTuningJobRequest, ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3370,13 +3967,15 @@ async def test_get_hyperparameter_tuning_job_async_from_dict(): def test_get_hyperparameter_tuning_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.GetHyperparameterTuningJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3392,18 +3991,23 @@ def test_get_hyperparameter_tuning_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_get_hyperparameter_tuning_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.GetHyperparameterTuningJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3421,11 +4025,16 @@ async def test_get_hyperparameter_tuning_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_get_hyperparameter_tuning_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3435,29 +4044,38 @@ def test_get_hyperparameter_tuning_job_flattened(): call.return_value = hyperparameter_tuning_job.HyperparameterTuningJob() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_hyperparameter_tuning_job(name="name_value",) + client.get_hyperparameter_tuning_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_hyperparameter_tuning_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.get_hyperparameter_tuning_job( - job_service.GetHyperparameterTuningJobRequest(), name="name_value", + job_service.GetHyperparameterTuningJobRequest(), + name="name_value", ) @pytest.mark.asyncio async def test_get_hyperparameter_tuning_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3471,33 +4089,45 @@ async def test_get_hyperparameter_tuning_job_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_hyperparameter_tuning_job(name="name_value",) + response = await client.get_hyperparameter_tuning_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio async def test_get_hyperparameter_tuning_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.get_hyperparameter_tuning_job( - job_service.GetHyperparameterTuningJobRequest(), name="name_value", + job_service.GetHyperparameterTuningJobRequest(), + name="name_value", ) -def test_list_hyperparameter_tuning_jobs( - transport: str = "grpc", - request_type=job_service.ListHyperparameterTuningJobsRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.ListHyperparameterTuningJobsRequest, + dict, + ], +) +def test_list_hyperparameter_tuning_jobs(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3524,15 +4154,12 @@ def test_list_hyperparameter_tuning_jobs( assert response.next_page_token == "next_page_token_value" -def test_list_hyperparameter_tuning_jobs_from_dict(): - test_list_hyperparameter_tuning_jobs(request_type=dict) - - def test_list_hyperparameter_tuning_jobs_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3551,7 +4178,8 @@ async def test_list_hyperparameter_tuning_jobs_async( request_type=job_service.ListHyperparameterTuningJobsRequest, ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3586,13 +4214,15 @@ async def test_list_hyperparameter_tuning_jobs_async_from_dict(): def test_list_hyperparameter_tuning_jobs_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.ListHyperparameterTuningJobsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3608,18 +4238,23 @@ def test_list_hyperparameter_tuning_jobs_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_list_hyperparameter_tuning_jobs_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.ListHyperparameterTuningJobsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3637,11 +4272,16 @@ async def test_list_hyperparameter_tuning_jobs_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_hyperparameter_tuning_jobs_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3651,29 +4291,38 @@ def test_list_hyperparameter_tuning_jobs_flattened(): call.return_value = job_service.ListHyperparameterTuningJobsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_hyperparameter_tuning_jobs(parent="parent_value",) + client.list_hyperparameter_tuning_jobs( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_hyperparameter_tuning_jobs_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.list_hyperparameter_tuning_jobs( - job_service.ListHyperparameterTuningJobsRequest(), parent="parent_value", + job_service.ListHyperparameterTuningJobsRequest(), + parent="parent_value", ) @pytest.mark.asyncio async def test_list_hyperparameter_tuning_jobs_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3687,29 +4336,39 @@ async def test_list_hyperparameter_tuning_jobs_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_hyperparameter_tuning_jobs(parent="parent_value",) + response = await client.list_hyperparameter_tuning_jobs( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio async def test_list_hyperparameter_tuning_jobs_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.list_hyperparameter_tuning_jobs( - job_service.ListHyperparameterTuningJobsRequest(), parent="parent_value", + job_service.ListHyperparameterTuningJobsRequest(), + parent="parent_value", ) -def test_list_hyperparameter_tuning_jobs_pager(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_hyperparameter_tuning_jobs_pager(transport_name: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3726,7 +4385,8 @@ def test_list_hyperparameter_tuning_jobs_pager(): next_page_token="abc", ), job_service.ListHyperparameterTuningJobsResponse( - hyperparameter_tuning_jobs=[], next_page_token="def", + hyperparameter_tuning_jobs=[], + next_page_token="def", ), job_service.ListHyperparameterTuningJobsResponse( hyperparameter_tuning_jobs=[ @@ -3751,7 +4411,7 @@ def test_list_hyperparameter_tuning_jobs_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all( isinstance(i, hyperparameter_tuning_job.HyperparameterTuningJob) @@ -3759,8 +4419,11 @@ def test_list_hyperparameter_tuning_jobs_pager(): ) -def test_list_hyperparameter_tuning_jobs_pages(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_hyperparameter_tuning_jobs_pages(transport_name: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3777,7 +4440,8 @@ def test_list_hyperparameter_tuning_jobs_pages(): next_page_token="abc", ), job_service.ListHyperparameterTuningJobsResponse( - hyperparameter_tuning_jobs=[], next_page_token="def", + hyperparameter_tuning_jobs=[], + next_page_token="def", ), job_service.ListHyperparameterTuningJobsResponse( hyperparameter_tuning_jobs=[ @@ -3800,7 +4464,9 @@ def test_list_hyperparameter_tuning_jobs_pages(): @pytest.mark.asyncio async def test_list_hyperparameter_tuning_jobs_async_pager(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3819,7 +4485,8 @@ async def test_list_hyperparameter_tuning_jobs_async_pager(): next_page_token="abc", ), job_service.ListHyperparameterTuningJobsResponse( - hyperparameter_tuning_jobs=[], next_page_token="def", + hyperparameter_tuning_jobs=[], + next_page_token="def", ), job_service.ListHyperparameterTuningJobsResponse( hyperparameter_tuning_jobs=[ @@ -3835,10 +4502,12 @@ async def test_list_hyperparameter_tuning_jobs_async_pager(): ), RuntimeError, ) - async_pager = await client.list_hyperparameter_tuning_jobs(request={},) + async_pager = await client.list_hyperparameter_tuning_jobs( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -3850,7 +4519,9 @@ async def test_list_hyperparameter_tuning_jobs_async_pager(): @pytest.mark.asyncio async def test_list_hyperparameter_tuning_jobs_async_pages(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3869,7 +4540,8 @@ async def test_list_hyperparameter_tuning_jobs_async_pages(): next_page_token="abc", ), job_service.ListHyperparameterTuningJobsResponse( - hyperparameter_tuning_jobs=[], next_page_token="def", + hyperparameter_tuning_jobs=[], + next_page_token="def", ), job_service.ListHyperparameterTuningJobsResponse( hyperparameter_tuning_jobs=[ @@ -3888,18 +4560,23 @@ async def test_list_hyperparameter_tuning_jobs_async_pages(): pages = [] async for page_ in ( await client.list_hyperparameter_tuning_jobs(request={}) - ).pages: + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_delete_hyperparameter_tuning_job( - transport: str = "grpc", - request_type=job_service.DeleteHyperparameterTuningJobRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.DeleteHyperparameterTuningJobRequest, + dict, + ], +) +def test_delete_hyperparameter_tuning_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3923,15 +4600,12 @@ def test_delete_hyperparameter_tuning_job( assert isinstance(response, future.Future) -def test_delete_hyperparameter_tuning_job_from_dict(): - test_delete_hyperparameter_tuning_job(request_type=dict) - - def test_delete_hyperparameter_tuning_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3950,7 +4624,8 @@ async def test_delete_hyperparameter_tuning_job_async( request_type=job_service.DeleteHyperparameterTuningJobRequest, ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3982,13 +4657,15 @@ async def test_delete_hyperparameter_tuning_job_async_from_dict(): def test_delete_hyperparameter_tuning_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.DeleteHyperparameterTuningJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4004,18 +4681,23 @@ def test_delete_hyperparameter_tuning_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_delete_hyperparameter_tuning_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.DeleteHyperparameterTuningJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4033,11 +4715,16 @@ async def test_delete_hyperparameter_tuning_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_delete_hyperparameter_tuning_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4047,29 +4734,38 @@ def test_delete_hyperparameter_tuning_job_flattened(): call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_hyperparameter_tuning_job(name="name_value",) + client.delete_hyperparameter_tuning_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_delete_hyperparameter_tuning_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.delete_hyperparameter_tuning_job( - job_service.DeleteHyperparameterTuningJobRequest(), name="name_value", + job_service.DeleteHyperparameterTuningJobRequest(), + name="name_value", ) @pytest.mark.asyncio async def test_delete_hyperparameter_tuning_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4083,33 +4779,45 @@ async def test_delete_hyperparameter_tuning_job_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_hyperparameter_tuning_job(name="name_value",) + response = await client.delete_hyperparameter_tuning_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio async def test_delete_hyperparameter_tuning_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.delete_hyperparameter_tuning_job( - job_service.DeleteHyperparameterTuningJobRequest(), name="name_value", + job_service.DeleteHyperparameterTuningJobRequest(), + name="name_value", ) -def test_cancel_hyperparameter_tuning_job( - transport: str = "grpc", - request_type=job_service.CancelHyperparameterTuningJobRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.CancelHyperparameterTuningJobRequest, + dict, + ], +) +def test_cancel_hyperparameter_tuning_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4133,15 +4841,12 @@ def test_cancel_hyperparameter_tuning_job( assert response is None -def test_cancel_hyperparameter_tuning_job_from_dict(): - test_cancel_hyperparameter_tuning_job(request_type=dict) - - def test_cancel_hyperparameter_tuning_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4160,7 +4865,8 @@ async def test_cancel_hyperparameter_tuning_job_async( request_type=job_service.CancelHyperparameterTuningJobRequest, ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4190,13 +4896,15 @@ async def test_cancel_hyperparameter_tuning_job_async_from_dict(): def test_cancel_hyperparameter_tuning_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) - - # Any value that is part of the HTTP/1.1 URI should be sent as + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.CancelHyperparameterTuningJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4212,18 +4920,23 @@ def test_cancel_hyperparameter_tuning_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_cancel_hyperparameter_tuning_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.CancelHyperparameterTuningJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4239,11 +4952,16 @@ async def test_cancel_hyperparameter_tuning_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_cancel_hyperparameter_tuning_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4253,29 +4971,38 @@ def test_cancel_hyperparameter_tuning_job_flattened(): call.return_value = None # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.cancel_hyperparameter_tuning_job(name="name_value",) + client.cancel_hyperparameter_tuning_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_cancel_hyperparameter_tuning_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.cancel_hyperparameter_tuning_job( - job_service.CancelHyperparameterTuningJobRequest(), name="name_value", + job_service.CancelHyperparameterTuningJobRequest(), + name="name_value", ) @pytest.mark.asyncio async def test_cancel_hyperparameter_tuning_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4287,32 +5014,45 @@ async def test_cancel_hyperparameter_tuning_job_flattened_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.cancel_hyperparameter_tuning_job(name="name_value",) + response = await client.cancel_hyperparameter_tuning_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio async def test_cancel_hyperparameter_tuning_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.cancel_hyperparameter_tuning_job( - job_service.CancelHyperparameterTuningJobRequest(), name="name_value", + job_service.CancelHyperparameterTuningJobRequest(), + name="name_value", ) -def test_create_batch_prediction_job( - transport: str = "grpc", request_type=job_service.CreateBatchPredictionJobRequest -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.CreateBatchPredictionJobRequest, + dict, + ], +) +def test_create_batch_prediction_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4328,6 +5068,8 @@ def test_create_batch_prediction_job( name="name_value", display_name="display_name_value", model="model_value", + model_version_id="model_version_id_value", + service_account="service_account_value", generate_explanation=True, state=job_state.JobState.JOB_STATE_QUEUED, ) @@ -4343,19 +5085,18 @@ def test_create_batch_prediction_job( assert response.name == "name_value" assert response.display_name == "display_name_value" assert response.model == "model_value" + assert response.model_version_id == "model_version_id_value" + assert response.service_account == "service_account_value" assert response.generate_explanation is True assert response.state == job_state.JobState.JOB_STATE_QUEUED -def test_create_batch_prediction_job_from_dict(): - test_create_batch_prediction_job(request_type=dict) - - def test_create_batch_prediction_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4374,7 +5115,8 @@ async def test_create_batch_prediction_job_async( request_type=job_service.CreateBatchPredictionJobRequest, ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4391,6 +5133,8 @@ async def test_create_batch_prediction_job_async( name="name_value", display_name="display_name_value", model="model_value", + model_version_id="model_version_id_value", + service_account="service_account_value", generate_explanation=True, state=job_state.JobState.JOB_STATE_QUEUED, ) @@ -4407,6 +5151,8 @@ async def test_create_batch_prediction_job_async( assert response.name == "name_value" assert response.display_name == "display_name_value" assert response.model == "model_value" + assert response.model_version_id == "model_version_id_value" + assert response.service_account == "service_account_value" assert response.generate_explanation is True assert response.state == job_state.JobState.JOB_STATE_QUEUED @@ -4417,13 +5163,15 @@ async def test_create_batch_prediction_job_async_from_dict(): def test_create_batch_prediction_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.CreateBatchPredictionJobRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4439,18 +5187,23 @@ def test_create_batch_prediction_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_create_batch_prediction_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.CreateBatchPredictionJobRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4468,11 +5221,16 @@ async def test_create_batch_prediction_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_create_batch_prediction_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4493,16 +5251,18 @@ def test_create_batch_prediction_job_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[ - 0 - ].batch_prediction_job == gca_batch_prediction_job.BatchPredictionJob( - name="name_value" - ) + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].batch_prediction_job + mock_val = gca_batch_prediction_job.BatchPredictionJob(name="name_value") + assert arg == mock_val def test_create_batch_prediction_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -4518,7 +5278,9 @@ def test_create_batch_prediction_job_flattened_error(): @pytest.mark.asyncio async def test_create_batch_prediction_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4543,17 +5305,19 @@ async def test_create_batch_prediction_job_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[ - 0 - ].batch_prediction_job == gca_batch_prediction_job.BatchPredictionJob( - name="name_value" - ) + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].batch_prediction_job + mock_val = gca_batch_prediction_job.BatchPredictionJob(name="name_value") + assert arg == mock_val @pytest.mark.asyncio async def test_create_batch_prediction_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -4567,11 +5331,17 @@ async def test_create_batch_prediction_job_flattened_error_async(): ) -def test_get_batch_prediction_job( - transport: str = "grpc", request_type=job_service.GetBatchPredictionJobRequest -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.GetBatchPredictionJobRequest, + dict, + ], +) +def test_get_batch_prediction_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4587,6 +5357,8 @@ def test_get_batch_prediction_job( name="name_value", display_name="display_name_value", model="model_value", + model_version_id="model_version_id_value", + service_account="service_account_value", generate_explanation=True, state=job_state.JobState.JOB_STATE_QUEUED, ) @@ -4602,19 +5374,18 @@ def test_get_batch_prediction_job( assert response.name == "name_value" assert response.display_name == "display_name_value" assert response.model == "model_value" + assert response.model_version_id == "model_version_id_value" + assert response.service_account == "service_account_value" assert response.generate_explanation is True assert response.state == job_state.JobState.JOB_STATE_QUEUED -def test_get_batch_prediction_job_from_dict(): - test_get_batch_prediction_job(request_type=dict) - - def test_get_batch_prediction_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4633,7 +5404,8 @@ async def test_get_batch_prediction_job_async( request_type=job_service.GetBatchPredictionJobRequest, ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4650,6 +5422,8 @@ async def test_get_batch_prediction_job_async( name="name_value", display_name="display_name_value", model="model_value", + model_version_id="model_version_id_value", + service_account="service_account_value", generate_explanation=True, state=job_state.JobState.JOB_STATE_QUEUED, ) @@ -4666,6 +5440,8 @@ async def test_get_batch_prediction_job_async( assert response.name == "name_value" assert response.display_name == "display_name_value" assert response.model == "model_value" + assert response.model_version_id == "model_version_id_value" + assert response.service_account == "service_account_value" assert response.generate_explanation is True assert response.state == job_state.JobState.JOB_STATE_QUEUED @@ -4676,13 +5452,15 @@ async def test_get_batch_prediction_job_async_from_dict(): def test_get_batch_prediction_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.GetBatchPredictionJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4698,18 +5476,23 @@ def test_get_batch_prediction_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_get_batch_prediction_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.GetBatchPredictionJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4727,11 +5510,16 @@ async def test_get_batch_prediction_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_get_batch_prediction_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4741,29 +5529,38 @@ def test_get_batch_prediction_job_flattened(): call.return_value = batch_prediction_job.BatchPredictionJob() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_batch_prediction_job(name="name_value",) + client.get_batch_prediction_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_batch_prediction_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.get_batch_prediction_job( - job_service.GetBatchPredictionJobRequest(), name="name_value", + job_service.GetBatchPredictionJobRequest(), + name="name_value", ) @pytest.mark.asyncio async def test_get_batch_prediction_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4777,32 +5574,45 @@ async def test_get_batch_prediction_job_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_batch_prediction_job(name="name_value",) + response = await client.get_batch_prediction_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio async def test_get_batch_prediction_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.get_batch_prediction_job( - job_service.GetBatchPredictionJobRequest(), name="name_value", + job_service.GetBatchPredictionJobRequest(), + name="name_value", ) -def test_list_batch_prediction_jobs( - transport: str = "grpc", request_type=job_service.ListBatchPredictionJobsRequest -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.ListBatchPredictionJobsRequest, + dict, + ], +) +def test_list_batch_prediction_jobs(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4829,15 +5639,12 @@ def test_list_batch_prediction_jobs( assert response.next_page_token == "next_page_token_value" -def test_list_batch_prediction_jobs_from_dict(): - test_list_batch_prediction_jobs(request_type=dict) - - def test_list_batch_prediction_jobs_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -4856,7 +5663,8 @@ async def test_list_batch_prediction_jobs_async( request_type=job_service.ListBatchPredictionJobsRequest, ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4891,13 +5699,15 @@ async def test_list_batch_prediction_jobs_async_from_dict(): def test_list_batch_prediction_jobs_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.ListBatchPredictionJobsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4913,18 +5723,23 @@ def test_list_batch_prediction_jobs_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_list_batch_prediction_jobs_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.ListBatchPredictionJobsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4942,11 +5757,16 @@ async def test_list_batch_prediction_jobs_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_batch_prediction_jobs_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4956,29 +5776,38 @@ def test_list_batch_prediction_jobs_flattened(): call.return_value = job_service.ListBatchPredictionJobsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_batch_prediction_jobs(parent="parent_value",) + client.list_batch_prediction_jobs( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_batch_prediction_jobs_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.list_batch_prediction_jobs( - job_service.ListBatchPredictionJobsRequest(), parent="parent_value", + job_service.ListBatchPredictionJobsRequest(), + parent="parent_value", ) @pytest.mark.asyncio async def test_list_batch_prediction_jobs_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -4992,29 +5821,39 @@ async def test_list_batch_prediction_jobs_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_batch_prediction_jobs(parent="parent_value",) + response = await client.list_batch_prediction_jobs( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio async def test_list_batch_prediction_jobs_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.list_batch_prediction_jobs( - job_service.ListBatchPredictionJobsRequest(), parent="parent_value", + job_service.ListBatchPredictionJobsRequest(), + parent="parent_value", ) -def test_list_batch_prediction_jobs_pager(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_batch_prediction_jobs_pager(transport_name: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5031,10 +5870,13 @@ def test_list_batch_prediction_jobs_pager(): next_page_token="abc", ), job_service.ListBatchPredictionJobsResponse( - batch_prediction_jobs=[], next_page_token="def", + batch_prediction_jobs=[], + next_page_token="def", ), job_service.ListBatchPredictionJobsResponse( - batch_prediction_jobs=[batch_prediction_job.BatchPredictionJob(),], + batch_prediction_jobs=[ + batch_prediction_job.BatchPredictionJob(), + ], next_page_token="ghi", ), job_service.ListBatchPredictionJobsResponse( @@ -5054,15 +5896,18 @@ def test_list_batch_prediction_jobs_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all( isinstance(i, batch_prediction_job.BatchPredictionJob) for i in results ) -def test_list_batch_prediction_jobs_pages(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_batch_prediction_jobs_pages(transport_name: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5079,10 +5924,13 @@ def test_list_batch_prediction_jobs_pages(): next_page_token="abc", ), job_service.ListBatchPredictionJobsResponse( - batch_prediction_jobs=[], next_page_token="def", + batch_prediction_jobs=[], + next_page_token="def", ), job_service.ListBatchPredictionJobsResponse( - batch_prediction_jobs=[batch_prediction_job.BatchPredictionJob(),], + batch_prediction_jobs=[ + batch_prediction_job.BatchPredictionJob(), + ], next_page_token="ghi", ), job_service.ListBatchPredictionJobsResponse( @@ -5100,7 +5948,9 @@ def test_list_batch_prediction_jobs_pages(): @pytest.mark.asyncio async def test_list_batch_prediction_jobs_async_pager(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5119,10 +5969,13 @@ async def test_list_batch_prediction_jobs_async_pager(): next_page_token="abc", ), job_service.ListBatchPredictionJobsResponse( - batch_prediction_jobs=[], next_page_token="def", + batch_prediction_jobs=[], + next_page_token="def", ), job_service.ListBatchPredictionJobsResponse( - batch_prediction_jobs=[batch_prediction_job.BatchPredictionJob(),], + batch_prediction_jobs=[ + batch_prediction_job.BatchPredictionJob(), + ], next_page_token="ghi", ), job_service.ListBatchPredictionJobsResponse( @@ -5133,10 +5986,12 @@ async def test_list_batch_prediction_jobs_async_pager(): ), RuntimeError, ) - async_pager = await client.list_batch_prediction_jobs(request={},) + async_pager = await client.list_batch_prediction_jobs( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -5147,7 +6002,9 @@ async def test_list_batch_prediction_jobs_async_pager(): @pytest.mark.asyncio async def test_list_batch_prediction_jobs_async_pages(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5166,10 +6023,13 @@ async def test_list_batch_prediction_jobs_async_pages(): next_page_token="abc", ), job_service.ListBatchPredictionJobsResponse( - batch_prediction_jobs=[], next_page_token="def", + batch_prediction_jobs=[], + next_page_token="def", ), job_service.ListBatchPredictionJobsResponse( - batch_prediction_jobs=[batch_prediction_job.BatchPredictionJob(),], + batch_prediction_jobs=[ + batch_prediction_job.BatchPredictionJob(), + ], next_page_token="ghi", ), job_service.ListBatchPredictionJobsResponse( @@ -5181,17 +6041,25 @@ async def test_list_batch_prediction_jobs_async_pages(): RuntimeError, ) pages = [] - async for page_ in (await client.list_batch_prediction_jobs(request={})).pages: + async for page_ in ( + await client.list_batch_prediction_jobs(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_delete_batch_prediction_job( - transport: str = "grpc", request_type=job_service.DeleteBatchPredictionJobRequest -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.DeleteBatchPredictionJobRequest, + dict, + ], +) +def test_delete_batch_prediction_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5215,15 +6083,12 @@ def test_delete_batch_prediction_job( assert isinstance(response, future.Future) -def test_delete_batch_prediction_job_from_dict(): - test_delete_batch_prediction_job(request_type=dict) - - def test_delete_batch_prediction_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5242,7 +6107,8 @@ async def test_delete_batch_prediction_job_async( request_type=job_service.DeleteBatchPredictionJobRequest, ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5274,13 +6140,15 @@ async def test_delete_batch_prediction_job_async_from_dict(): def test_delete_batch_prediction_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.DeleteBatchPredictionJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5296,18 +6164,23 @@ def test_delete_batch_prediction_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_delete_batch_prediction_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.DeleteBatchPredictionJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5325,11 +6198,16 @@ async def test_delete_batch_prediction_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_delete_batch_prediction_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5339,29 +6217,38 @@ def test_delete_batch_prediction_job_flattened(): call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_batch_prediction_job(name="name_value",) + client.delete_batch_prediction_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_delete_batch_prediction_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.delete_batch_prediction_job( - job_service.DeleteBatchPredictionJobRequest(), name="name_value", + job_service.DeleteBatchPredictionJobRequest(), + name="name_value", ) @pytest.mark.asyncio async def test_delete_batch_prediction_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5375,32 +6262,45 @@ async def test_delete_batch_prediction_job_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_batch_prediction_job(name="name_value",) + response = await client.delete_batch_prediction_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio async def test_delete_batch_prediction_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.delete_batch_prediction_job( - job_service.DeleteBatchPredictionJobRequest(), name="name_value", + job_service.DeleteBatchPredictionJobRequest(), + name="name_value", ) -def test_cancel_batch_prediction_job( - transport: str = "grpc", request_type=job_service.CancelBatchPredictionJobRequest -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.CancelBatchPredictionJobRequest, + dict, + ], +) +def test_cancel_batch_prediction_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5424,15 +6324,12 @@ def test_cancel_batch_prediction_job( assert response is None -def test_cancel_batch_prediction_job_from_dict(): - test_cancel_batch_prediction_job(request_type=dict) - - def test_cancel_batch_prediction_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5451,7 +6348,8 @@ async def test_cancel_batch_prediction_job_async( request_type=job_service.CancelBatchPredictionJobRequest, ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5481,13 +6379,15 @@ async def test_cancel_batch_prediction_job_async_from_dict(): def test_cancel_batch_prediction_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.CancelBatchPredictionJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5503,18 +6403,23 @@ def test_cancel_batch_prediction_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_cancel_batch_prediction_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.CancelBatchPredictionJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5530,11 +6435,16 @@ async def test_cancel_batch_prediction_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_cancel_batch_prediction_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5544,29 +6454,38 @@ def test_cancel_batch_prediction_job_flattened(): call.return_value = None # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.cancel_batch_prediction_job(name="name_value",) + client.cancel_batch_prediction_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_cancel_batch_prediction_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.cancel_batch_prediction_job( - job_service.CancelBatchPredictionJobRequest(), name="name_value", + job_service.CancelBatchPredictionJobRequest(), + name="name_value", ) @pytest.mark.asyncio async def test_cancel_batch_prediction_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5578,33 +6497,45 @@ async def test_cancel_batch_prediction_job_flattened_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.cancel_batch_prediction_job(name="name_value",) + response = await client.cancel_batch_prediction_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio async def test_cancel_batch_prediction_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) - - # Attempting to call a method with both a request object and flattened + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.cancel_batch_prediction_job( - job_service.CancelBatchPredictionJobRequest(), name="name_value", + job_service.CancelBatchPredictionJobRequest(), + name="name_value", ) -def test_create_model_deployment_monitoring_job( - transport: str = "grpc", - request_type=job_service.CreateModelDeploymentMonitoringJobRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.CreateModelDeploymentMonitoringJobRequest, + dict, + ], +) +def test_create_model_deployment_monitoring_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5624,6 +6555,7 @@ def test_create_model_deployment_monitoring_job( schedule_state=gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob.MonitoringScheduleState.PENDING, predict_instance_schema_uri="predict_instance_schema_uri_value", analysis_instance_schema_uri="analysis_instance_schema_uri_value", + enable_monitoring_pipeline_logs=True, ) response = client.create_model_deployment_monitoring_job(request) @@ -5646,17 +6578,15 @@ def test_create_model_deployment_monitoring_job( ) assert response.predict_instance_schema_uri == "predict_instance_schema_uri_value" assert response.analysis_instance_schema_uri == "analysis_instance_schema_uri_value" - - -def test_create_model_deployment_monitoring_job_from_dict(): - test_create_model_deployment_monitoring_job(request_type=dict) + assert response.enable_monitoring_pipeline_logs is True def test_create_model_deployment_monitoring_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5675,7 +6605,8 @@ async def test_create_model_deployment_monitoring_job_async( request_type=job_service.CreateModelDeploymentMonitoringJobRequest, ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5696,6 +6627,7 @@ async def test_create_model_deployment_monitoring_job_async( schedule_state=gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob.MonitoringScheduleState.PENDING, predict_instance_schema_uri="predict_instance_schema_uri_value", analysis_instance_schema_uri="analysis_instance_schema_uri_value", + enable_monitoring_pipeline_logs=True, ) ) response = await client.create_model_deployment_monitoring_job(request) @@ -5719,6 +6651,7 @@ async def test_create_model_deployment_monitoring_job_async( ) assert response.predict_instance_schema_uri == "predict_instance_schema_uri_value" assert response.analysis_instance_schema_uri == "analysis_instance_schema_uri_value" + assert response.enable_monitoring_pipeline_logs is True @pytest.mark.asyncio @@ -5727,13 +6660,15 @@ async def test_create_model_deployment_monitoring_job_async_from_dict(): def test_create_model_deployment_monitoring_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.CreateModelDeploymentMonitoringJobRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5751,18 +6686,23 @@ def test_create_model_deployment_monitoring_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_create_model_deployment_monitoring_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.CreateModelDeploymentMonitoringJobRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5780,11 +6720,16 @@ async def test_create_model_deployment_monitoring_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_create_model_deployment_monitoring_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5807,16 +6752,20 @@ def test_create_model_deployment_monitoring_job_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[ - 0 - ].model_deployment_monitoring_job == gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob( + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].model_deployment_monitoring_job + mock_val = gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob( name="name_value" ) + assert arg == mock_val def test_create_model_deployment_monitoring_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -5832,7 +6781,9 @@ def test_create_model_deployment_monitoring_job_flattened_error(): @pytest.mark.asyncio async def test_create_model_deployment_monitoring_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -5859,17 +6810,21 @@ async def test_create_model_deployment_monitoring_job_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[ - 0 - ].model_deployment_monitoring_job == gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob( + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].model_deployment_monitoring_job + mock_val = gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob( name="name_value" ) + assert arg == mock_val @pytest.mark.asyncio async def test_create_model_deployment_monitoring_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -5883,12 +6838,19 @@ async def test_create_model_deployment_monitoring_job_flattened_error_async(): ) +@pytest.mark.parametrize( + "request_type", + [ + job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest, + dict, + ], +) def test_search_model_deployment_monitoring_stats_anomalies( - transport: str = "grpc", - request_type=job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest, + request_type, transport: str = "grpc" ): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5901,8 +6863,10 @@ def test_search_model_deployment_monitoring_stats_anomalies( "__call__", ) as call: # Designate an appropriate return value for the call. - call.return_value = job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse( - next_page_token="next_page_token_value", + call.return_value = ( + job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse( + next_page_token="next_page_token_value", + ) ) response = client.search_model_deployment_monitoring_stats_anomalies(request) @@ -5921,15 +6885,12 @@ def test_search_model_deployment_monitoring_stats_anomalies( assert response.next_page_token == "next_page_token_value" -def test_search_model_deployment_monitoring_stats_anomalies_from_dict(): - test_search_model_deployment_monitoring_stats_anomalies(request_type=dict) - - def test_search_model_deployment_monitoring_stats_anomalies_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -5952,7 +6913,8 @@ async def test_search_model_deployment_monitoring_stats_anomalies_async( request_type=job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest, ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5997,13 +6959,15 @@ async def test_search_model_deployment_monitoring_stats_anomalies_async_from_dic def test_search_model_deployment_monitoring_stats_anomalies_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest() - request.model_deployment_monitoring_job = "model_deployment_monitoring_job/value" + request.model_deployment_monitoring_job = "model_deployment_monitoring_job_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -6024,19 +6988,21 @@ def test_search_model_deployment_monitoring_stats_anomalies_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "model_deployment_monitoring_job=model_deployment_monitoring_job/value", + "model_deployment_monitoring_job=model_deployment_monitoring_job_value", ) in kw["metadata"] @pytest.mark.asyncio async def test_search_model_deployment_monitoring_stats_anomalies_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.SearchModelDeploymentMonitoringStatsAnomaliesRequest() - request.model_deployment_monitoring_job = "model_deployment_monitoring_job/value" + request.model_deployment_monitoring_job = "model_deployment_monitoring_job_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -6057,12 +7023,14 @@ async def test_search_model_deployment_monitoring_stats_anomalies_field_headers_ _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "model_deployment_monitoring_job=model_deployment_monitoring_job/value", + "model_deployment_monitoring_job=model_deployment_monitoring_job_value", ) in kw["metadata"] def test_search_model_deployment_monitoring_stats_anomalies_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -6084,15 +7052,18 @@ def test_search_model_deployment_monitoring_stats_anomalies_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert ( - args[0].model_deployment_monitoring_job - == "model_deployment_monitoring_job_value" - ) - assert args[0].deployed_model_id == "deployed_model_id_value" + arg = args[0].model_deployment_monitoring_job + mock_val = "model_deployment_monitoring_job_value" + assert arg == mock_val + arg = args[0].deployed_model_id + mock_val = "deployed_model_id_value" + assert arg == mock_val def test_search_model_deployment_monitoring_stats_anomalies_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -6106,7 +7077,9 @@ def test_search_model_deployment_monitoring_stats_anomalies_flattened_error(): @pytest.mark.asyncio async def test_search_model_deployment_monitoring_stats_anomalies_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -6132,16 +7105,19 @@ async def test_search_model_deployment_monitoring_stats_anomalies_flattened_asyn # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert ( - args[0].model_deployment_monitoring_job - == "model_deployment_monitoring_job_value" - ) - assert args[0].deployed_model_id == "deployed_model_id_value" + arg = args[0].model_deployment_monitoring_job + mock_val = "model_deployment_monitoring_job_value" + assert arg == mock_val + arg = args[0].deployed_model_id + mock_val = "deployed_model_id_value" + assert arg == mock_val @pytest.mark.asyncio async def test_search_model_deployment_monitoring_stats_anomalies_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -6153,8 +7129,13 @@ async def test_search_model_deployment_monitoring_stats_anomalies_flattened_erro ) -def test_search_model_deployment_monitoring_stats_anomalies_pager(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_search_model_deployment_monitoring_stats_anomalies_pager( + transport_name: str = "grpc", +): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -6172,7 +7153,8 @@ def test_search_model_deployment_monitoring_stats_anomalies_pager(): next_page_token="abc", ), job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse( - monitoring_stats=[], next_page_token="def", + monitoring_stats=[], + next_page_token="def", ), job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse( monitoring_stats=[ @@ -6199,7 +7181,7 @@ def test_search_model_deployment_monitoring_stats_anomalies_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all( isinstance( @@ -6209,8 +7191,13 @@ def test_search_model_deployment_monitoring_stats_anomalies_pager(): ) -def test_search_model_deployment_monitoring_stats_anomalies_pages(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_search_model_deployment_monitoring_stats_anomalies_pages( + transport_name: str = "grpc", +): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -6228,7 +7215,8 @@ def test_search_model_deployment_monitoring_stats_anomalies_pages(): next_page_token="abc", ), job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse( - monitoring_stats=[], next_page_token="def", + monitoring_stats=[], + next_page_token="def", ), job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse( monitoring_stats=[ @@ -6253,7 +7241,9 @@ def test_search_model_deployment_monitoring_stats_anomalies_pages(): @pytest.mark.asyncio async def test_search_model_deployment_monitoring_stats_anomalies_async_pager(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -6272,7 +7262,8 @@ async def test_search_model_deployment_monitoring_stats_anomalies_async_pager(): next_page_token="abc", ), job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse( - monitoring_stats=[], next_page_token="def", + monitoring_stats=[], + next_page_token="def", ), job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse( monitoring_stats=[ @@ -6293,7 +7284,7 @@ async def test_search_model_deployment_monitoring_stats_anomalies_async_pager(): ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -6307,7 +7298,9 @@ async def test_search_model_deployment_monitoring_stats_anomalies_async_pager(): @pytest.mark.asyncio async def test_search_model_deployment_monitoring_stats_anomalies_async_pages(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -6326,7 +7319,8 @@ async def test_search_model_deployment_monitoring_stats_anomalies_async_pages(): next_page_token="abc", ), job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse( - monitoring_stats=[], next_page_token="def", + monitoring_stats=[], + next_page_token="def", ), job_service.SearchModelDeploymentMonitoringStatsAnomaliesResponse( monitoring_stats=[ @@ -6345,18 +7339,23 @@ async def test_search_model_deployment_monitoring_stats_anomalies_async_pages(): pages = [] async for page_ in ( await client.search_model_deployment_monitoring_stats_anomalies(request={}) - ).pages: + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_get_model_deployment_monitoring_job( - transport: str = "grpc", - request_type=job_service.GetModelDeploymentMonitoringJobRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.GetModelDeploymentMonitoringJobRequest, + dict, + ], +) +def test_get_model_deployment_monitoring_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -6376,6 +7375,7 @@ def test_get_model_deployment_monitoring_job( schedule_state=model_deployment_monitoring_job.ModelDeploymentMonitoringJob.MonitoringScheduleState.PENDING, predict_instance_schema_uri="predict_instance_schema_uri_value", analysis_instance_schema_uri="analysis_instance_schema_uri_value", + enable_monitoring_pipeline_logs=True, ) response = client.get_model_deployment_monitoring_job(request) @@ -6398,17 +7398,15 @@ def test_get_model_deployment_monitoring_job( ) assert response.predict_instance_schema_uri == "predict_instance_schema_uri_value" assert response.analysis_instance_schema_uri == "analysis_instance_schema_uri_value" - - -def test_get_model_deployment_monitoring_job_from_dict(): - test_get_model_deployment_monitoring_job(request_type=dict) + assert response.enable_monitoring_pipeline_logs is True def test_get_model_deployment_monitoring_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6427,7 +7425,8 @@ async def test_get_model_deployment_monitoring_job_async( request_type=job_service.GetModelDeploymentMonitoringJobRequest, ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -6448,6 +7447,7 @@ async def test_get_model_deployment_monitoring_job_async( schedule_state=model_deployment_monitoring_job.ModelDeploymentMonitoringJob.MonitoringScheduleState.PENDING, predict_instance_schema_uri="predict_instance_schema_uri_value", analysis_instance_schema_uri="analysis_instance_schema_uri_value", + enable_monitoring_pipeline_logs=True, ) ) response = await client.get_model_deployment_monitoring_job(request) @@ -6471,6 +7471,7 @@ async def test_get_model_deployment_monitoring_job_async( ) assert response.predict_instance_schema_uri == "predict_instance_schema_uri_value" assert response.analysis_instance_schema_uri == "analysis_instance_schema_uri_value" + assert response.enable_monitoring_pipeline_logs is True @pytest.mark.asyncio @@ -6479,13 +7480,15 @@ async def test_get_model_deployment_monitoring_job_async_from_dict(): def test_get_model_deployment_monitoring_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.GetModelDeploymentMonitoringJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -6503,18 +7506,23 @@ def test_get_model_deployment_monitoring_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_get_model_deployment_monitoring_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.GetModelDeploymentMonitoringJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -6532,11 +7540,16 @@ async def test_get_model_deployment_monitoring_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_get_model_deployment_monitoring_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -6548,29 +7561,38 @@ def test_get_model_deployment_monitoring_job_flattened(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_model_deployment_monitoring_job(name="name_value",) + client.get_model_deployment_monitoring_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_model_deployment_monitoring_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.get_model_deployment_monitoring_job( - job_service.GetModelDeploymentMonitoringJobRequest(), name="name_value", + job_service.GetModelDeploymentMonitoringJobRequest(), + name="name_value", ) @pytest.mark.asyncio async def test_get_model_deployment_monitoring_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -6586,33 +7608,45 @@ async def test_get_model_deployment_monitoring_job_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_model_deployment_monitoring_job(name="name_value",) + response = await client.get_model_deployment_monitoring_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio async def test_get_model_deployment_monitoring_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.get_model_deployment_monitoring_job( - job_service.GetModelDeploymentMonitoringJobRequest(), name="name_value", + job_service.GetModelDeploymentMonitoringJobRequest(), + name="name_value", ) -def test_list_model_deployment_monitoring_jobs( - transport: str = "grpc", - request_type=job_service.ListModelDeploymentMonitoringJobsRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.ListModelDeploymentMonitoringJobsRequest, + dict, + ], +) +def test_list_model_deployment_monitoring_jobs(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -6639,15 +7673,12 @@ def test_list_model_deployment_monitoring_jobs( assert response.next_page_token == "next_page_token_value" -def test_list_model_deployment_monitoring_jobs_from_dict(): - test_list_model_deployment_monitoring_jobs(request_type=dict) - - def test_list_model_deployment_monitoring_jobs_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -6666,7 +7697,8 @@ async def test_list_model_deployment_monitoring_jobs_async( request_type=job_service.ListModelDeploymentMonitoringJobsRequest, ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -6701,13 +7733,15 @@ async def test_list_model_deployment_monitoring_jobs_async_from_dict(): def test_list_model_deployment_monitoring_jobs_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.ListModelDeploymentMonitoringJobsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -6723,18 +7757,23 @@ def test_list_model_deployment_monitoring_jobs_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_list_model_deployment_monitoring_jobs_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.ListModelDeploymentMonitoringJobsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -6752,11 +7791,16 @@ async def test_list_model_deployment_monitoring_jobs_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_model_deployment_monitoring_jobs_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -6766,17 +7810,23 @@ def test_list_model_deployment_monitoring_jobs_flattened(): call.return_value = job_service.ListModelDeploymentMonitoringJobsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_model_deployment_monitoring_jobs(parent="parent_value",) + client.list_model_deployment_monitoring_jobs( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_model_deployment_monitoring_jobs_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -6789,7 +7839,9 @@ def test_list_model_deployment_monitoring_jobs_flattened_error(): @pytest.mark.asyncio async def test_list_model_deployment_monitoring_jobs_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -6811,12 +7863,16 @@ async def test_list_model_deployment_monitoring_jobs_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio async def test_list_model_deployment_monitoring_jobs_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -6827,8 +7883,11 @@ async def test_list_model_deployment_monitoring_jobs_flattened_error_async(): ) -def test_list_model_deployment_monitoring_jobs_pager(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_model_deployment_monitoring_jobs_pager(transport_name: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -6845,7 +7904,8 @@ def test_list_model_deployment_monitoring_jobs_pager(): next_page_token="abc", ), job_service.ListModelDeploymentMonitoringJobsResponse( - model_deployment_monitoring_jobs=[], next_page_token="def", + model_deployment_monitoring_jobs=[], + next_page_token="def", ), job_service.ListModelDeploymentMonitoringJobsResponse( model_deployment_monitoring_jobs=[ @@ -6870,7 +7930,7 @@ def test_list_model_deployment_monitoring_jobs_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all( isinstance(i, model_deployment_monitoring_job.ModelDeploymentMonitoringJob) @@ -6878,8 +7938,11 @@ def test_list_model_deployment_monitoring_jobs_pager(): ) -def test_list_model_deployment_monitoring_jobs_pages(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_model_deployment_monitoring_jobs_pages(transport_name: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -6896,7 +7959,8 @@ def test_list_model_deployment_monitoring_jobs_pages(): next_page_token="abc", ), job_service.ListModelDeploymentMonitoringJobsResponse( - model_deployment_monitoring_jobs=[], next_page_token="def", + model_deployment_monitoring_jobs=[], + next_page_token="def", ), job_service.ListModelDeploymentMonitoringJobsResponse( model_deployment_monitoring_jobs=[ @@ -6919,7 +7983,9 @@ def test_list_model_deployment_monitoring_jobs_pages(): @pytest.mark.asyncio async def test_list_model_deployment_monitoring_jobs_async_pager(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -6938,7 +8004,8 @@ async def test_list_model_deployment_monitoring_jobs_async_pager(): next_page_token="abc", ), job_service.ListModelDeploymentMonitoringJobsResponse( - model_deployment_monitoring_jobs=[], next_page_token="def", + model_deployment_monitoring_jobs=[], + next_page_token="def", ), job_service.ListModelDeploymentMonitoringJobsResponse( model_deployment_monitoring_jobs=[ @@ -6954,10 +8021,12 @@ async def test_list_model_deployment_monitoring_jobs_async_pager(): ), RuntimeError, ) - async_pager = await client.list_model_deployment_monitoring_jobs(request={},) + async_pager = await client.list_model_deployment_monitoring_jobs( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -6969,7 +8038,9 @@ async def test_list_model_deployment_monitoring_jobs_async_pager(): @pytest.mark.asyncio async def test_list_model_deployment_monitoring_jobs_async_pages(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -6988,7 +8059,8 @@ async def test_list_model_deployment_monitoring_jobs_async_pages(): next_page_token="abc", ), job_service.ListModelDeploymentMonitoringJobsResponse( - model_deployment_monitoring_jobs=[], next_page_token="def", + model_deployment_monitoring_jobs=[], + next_page_token="def", ), job_service.ListModelDeploymentMonitoringJobsResponse( model_deployment_monitoring_jobs=[ @@ -7007,18 +8079,23 @@ async def test_list_model_deployment_monitoring_jobs_async_pages(): pages = [] async for page_ in ( await client.list_model_deployment_monitoring_jobs(request={}) - ).pages: + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_update_model_deployment_monitoring_job( - transport: str = "grpc", - request_type=job_service.UpdateModelDeploymentMonitoringJobRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.UpdateModelDeploymentMonitoringJobRequest, + dict, + ], +) +def test_update_model_deployment_monitoring_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -7042,15 +8119,12 @@ def test_update_model_deployment_monitoring_job( assert isinstance(response, future.Future) -def test_update_model_deployment_monitoring_job_from_dict(): - test_update_model_deployment_monitoring_job(request_type=dict) - - def test_update_model_deployment_monitoring_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -7069,7 +8143,8 @@ async def test_update_model_deployment_monitoring_job_async( request_type=job_service.UpdateModelDeploymentMonitoringJobRequest, ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -7101,15 +8176,15 @@ async def test_update_model_deployment_monitoring_job_async_from_dict(): def test_update_model_deployment_monitoring_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.UpdateModelDeploymentMonitoringJobRequest() - request.model_deployment_monitoring_job.name = ( - "model_deployment_monitoring_job.name/value" - ) + request.model_deployment_monitoring_job.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -7127,21 +8202,21 @@ def test_update_model_deployment_monitoring_job_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "model_deployment_monitoring_job.name=model_deployment_monitoring_job.name/value", + "model_deployment_monitoring_job.name=name_value", ) in kw["metadata"] @pytest.mark.asyncio async def test_update_model_deployment_monitoring_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.UpdateModelDeploymentMonitoringJobRequest() - request.model_deployment_monitoring_job.name = ( - "model_deployment_monitoring_job.name/value" - ) + request.model_deployment_monitoring_job.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -7161,12 +8236,14 @@ async def test_update_model_deployment_monitoring_job_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "model_deployment_monitoring_job.name=model_deployment_monitoring_job.name/value", + "model_deployment_monitoring_job.name=name_value", ) in kw["metadata"] def test_update_model_deployment_monitoring_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -7187,16 +8264,20 @@ def test_update_model_deployment_monitoring_job_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[ - 0 - ].model_deployment_monitoring_job == gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob( + arg = args[0].model_deployment_monitoring_job + mock_val = gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob( name="name_value" ) - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val def test_update_model_deployment_monitoring_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -7212,7 +8293,9 @@ def test_update_model_deployment_monitoring_job_flattened_error(): @pytest.mark.asyncio async def test_update_model_deployment_monitoring_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -7237,17 +8320,21 @@ async def test_update_model_deployment_monitoring_job_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[ - 0 - ].model_deployment_monitoring_job == gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob( + arg = args[0].model_deployment_monitoring_job + mock_val = gca_model_deployment_monitoring_job.ModelDeploymentMonitoringJob( name="name_value" ) - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val @pytest.mark.asyncio async def test_update_model_deployment_monitoring_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -7261,12 +8348,17 @@ async def test_update_model_deployment_monitoring_job_flattened_error_async(): ) -def test_delete_model_deployment_monitoring_job( - transport: str = "grpc", - request_type=job_service.DeleteModelDeploymentMonitoringJobRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.DeleteModelDeploymentMonitoringJobRequest, + dict, + ], +) +def test_delete_model_deployment_monitoring_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -7290,15 +8382,12 @@ def test_delete_model_deployment_monitoring_job( assert isinstance(response, future.Future) -def test_delete_model_deployment_monitoring_job_from_dict(): - test_delete_model_deployment_monitoring_job(request_type=dict) - - def test_delete_model_deployment_monitoring_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -7317,7 +8406,8 @@ async def test_delete_model_deployment_monitoring_job_async( request_type=job_service.DeleteModelDeploymentMonitoringJobRequest, ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -7349,13 +8439,15 @@ async def test_delete_model_deployment_monitoring_job_async_from_dict(): def test_delete_model_deployment_monitoring_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.DeleteModelDeploymentMonitoringJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -7371,18 +8463,23 @@ def test_delete_model_deployment_monitoring_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_delete_model_deployment_monitoring_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.DeleteModelDeploymentMonitoringJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -7400,11 +8497,16 @@ async def test_delete_model_deployment_monitoring_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_delete_model_deployment_monitoring_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -7414,29 +8516,38 @@ def test_delete_model_deployment_monitoring_job_flattened(): call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_model_deployment_monitoring_job(name="name_value",) + client.delete_model_deployment_monitoring_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_delete_model_deployment_monitoring_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.delete_model_deployment_monitoring_job( - job_service.DeleteModelDeploymentMonitoringJobRequest(), name="name_value", + job_service.DeleteModelDeploymentMonitoringJobRequest(), + name="name_value", ) @pytest.mark.asyncio async def test_delete_model_deployment_monitoring_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -7458,27 +8569,37 @@ async def test_delete_model_deployment_monitoring_job_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio async def test_delete_model_deployment_monitoring_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.delete_model_deployment_monitoring_job( - job_service.DeleteModelDeploymentMonitoringJobRequest(), name="name_value", + job_service.DeleteModelDeploymentMonitoringJobRequest(), + name="name_value", ) -def test_pause_model_deployment_monitoring_job( - transport: str = "grpc", - request_type=job_service.PauseModelDeploymentMonitoringJobRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.PauseModelDeploymentMonitoringJobRequest, + dict, + ], +) +def test_pause_model_deployment_monitoring_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -7502,15 +8623,12 @@ def test_pause_model_deployment_monitoring_job( assert response is None -def test_pause_model_deployment_monitoring_job_from_dict(): - test_pause_model_deployment_monitoring_job(request_type=dict) - - def test_pause_model_deployment_monitoring_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -7529,7 +8647,8 @@ async def test_pause_model_deployment_monitoring_job_async( request_type=job_service.PauseModelDeploymentMonitoringJobRequest, ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -7559,13 +8678,15 @@ async def test_pause_model_deployment_monitoring_job_async_from_dict(): def test_pause_model_deployment_monitoring_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.PauseModelDeploymentMonitoringJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -7581,18 +8702,23 @@ def test_pause_model_deployment_monitoring_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_pause_model_deployment_monitoring_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.PauseModelDeploymentMonitoringJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -7608,11 +8734,16 @@ async def test_pause_model_deployment_monitoring_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_pause_model_deployment_monitoring_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -7622,29 +8753,38 @@ def test_pause_model_deployment_monitoring_job_flattened(): call.return_value = None # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.pause_model_deployment_monitoring_job(name="name_value",) + client.pause_model_deployment_monitoring_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_pause_model_deployment_monitoring_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.pause_model_deployment_monitoring_job( - job_service.PauseModelDeploymentMonitoringJobRequest(), name="name_value", + job_service.PauseModelDeploymentMonitoringJobRequest(), + name="name_value", ) @pytest.mark.asyncio async def test_pause_model_deployment_monitoring_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -7664,27 +8804,37 @@ async def test_pause_model_deployment_monitoring_job_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio async def test_pause_model_deployment_monitoring_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.pause_model_deployment_monitoring_job( - job_service.PauseModelDeploymentMonitoringJobRequest(), name="name_value", + job_service.PauseModelDeploymentMonitoringJobRequest(), + name="name_value", ) -def test_resume_model_deployment_monitoring_job( - transport: str = "grpc", - request_type=job_service.ResumeModelDeploymentMonitoringJobRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + job_service.ResumeModelDeploymentMonitoringJobRequest, + dict, + ], +) +def test_resume_model_deployment_monitoring_job(request_type, transport: str = "grpc"): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -7708,15 +8858,12 @@ def test_resume_model_deployment_monitoring_job( assert response is None -def test_resume_model_deployment_monitoring_job_from_dict(): - test_resume_model_deployment_monitoring_job(request_type=dict) - - def test_resume_model_deployment_monitoring_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -7735,7 +8882,8 @@ async def test_resume_model_deployment_monitoring_job_async( request_type=job_service.ResumeModelDeploymentMonitoringJobRequest, ): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -7765,13 +8913,15 @@ async def test_resume_model_deployment_monitoring_job_async_from_dict(): def test_resume_model_deployment_monitoring_job_field_headers(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.ResumeModelDeploymentMonitoringJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -7787,18 +8937,23 @@ def test_resume_model_deployment_monitoring_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_resume_model_deployment_monitoring_job_field_headers_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = job_service.ResumeModelDeploymentMonitoringJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -7814,11 +8969,16 @@ async def test_resume_model_deployment_monitoring_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_resume_model_deployment_monitoring_job_flattened(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -7828,29 +8988,38 @@ def test_resume_model_deployment_monitoring_job_flattened(): call.return_value = None # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.resume_model_deployment_monitoring_job(name="name_value",) + client.resume_model_deployment_monitoring_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_resume_model_deployment_monitoring_job_flattened_error(): - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.resume_model_deployment_monitoring_job( - job_service.ResumeModelDeploymentMonitoringJobRequest(), name="name_value", + job_service.ResumeModelDeploymentMonitoringJobRequest(), + name="name_value", ) @pytest.mark.asyncio async def test_resume_model_deployment_monitoring_job_flattened_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -7870,18 +9039,23 @@ async def test_resume_model_deployment_monitoring_job_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio async def test_resume_model_deployment_monitoring_job_flattened_error_async(): - client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.resume_model_deployment_monitoring_job( - job_service.ResumeModelDeploymentMonitoringJobRequest(), name="name_value", + job_service.ResumeModelDeploymentMonitoringJobRequest(), + name="name_value", ) @@ -7892,7 +9066,8 @@ def test_credentials_transport_error(): ) with pytest.raises(ValueError): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # It is an error to provide a credentials file and a transport instance. @@ -7905,13 +9080,34 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.JobServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = JobServiceClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = JobServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.JobServiceGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = JobServiceClient( - client_options={"scopes": ["1", "2"]}, transport=transport, + client_options={"scopes": ["1", "2"]}, + transport=transport, ) @@ -7941,7 +9137,10 @@ def test_transport_get_channel(): @pytest.mark.parametrize( "transport_class", - [transports.JobServiceGrpcTransport, transports.JobServiceGrpcAsyncIOTransport,], + [ + transports.JobServiceGrpcTransport, + transports.JobServiceGrpcAsyncIOTransport, + ], ) def test_transport_adc(transport_class): # Test default credentials are used if not provided. @@ -7951,10 +9150,28 @@ def test_transport_adc(transport_class): adc.assert_called_once() +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = JobServiceClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + def test_transport_grpc_default(): # A client should use the gRPC transport by default. - client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials(),) - assert isinstance(client.transport, transports.JobServiceGrpcTransport,) + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.JobServiceGrpcTransport, + ) def test_job_service_base_transport_error(): @@ -8007,18 +9224,38 @@ def test_job_service_base_transport(): "delete_model_deployment_monitoring_job", "pause_model_deployment_monitoring_job", "resume_model_deployment_monitoring_job", + "set_iam_policy", + "get_iam_policy", + "test_iam_permissions", + "get_location", + "list_locations", + "get_operation", + "wait_operation", + "cancel_operation", + "delete_operation", + "list_operations", ) for method in methods: with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + # Additionally, the LRO client (a property) should # also raise NotImplementedError with pytest.raises(NotImplementedError): transport.operations_client + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + -@requires_google_auth_gte_1_25_0 def test_job_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -8029,7 +9266,8 @@ def test_job_service_base_transport_with_credentials_file(): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.JobServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", + credentials_file="credentials.json", + quota_project_id="octopus", ) load_creds.assert_called_once_with( "credentials.json", @@ -8039,26 +9277,6 @@ def test_job_service_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_job_service_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.aiplatform_v1beta1.services.job_service.transports.JobServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.JobServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - def test_job_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( @@ -8070,7 +9288,6 @@ def test_job_service_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_job_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -8083,23 +9300,13 @@ def test_job_service_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_job_service_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - JobServiceClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", - [transports.JobServiceGrpcTransport, transports.JobServiceGrpcAsyncIOTransport,], + [ + transports.JobServiceGrpcTransport, + transports.JobServiceGrpcAsyncIOTransport, + ], ) -@requires_google_auth_gte_1_25_0 def test_job_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -8113,23 +9320,6 @@ def test_job_service_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [transports.JobServiceGrpcTransport, transports.JobServiceGrpcAsyncIOTransport,], -) -@requires_google_auth_lt_1_25_0 -def test_job_service_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ @@ -8137,7 +9327,6 @@ def test_job_service_transport_auth_adc_old_google_auth(transport_class): (transports.JobServiceGrpcAsyncIOTransport, grpc_helpers_async), ], ) -@requires_api_core_gte_1_26_0 def test_job_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -8166,79 +9355,6 @@ def test_job_service_transport_create_channel(transport_class, grpc_helpers): ) -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.JobServiceGrpcTransport, grpc_helpers), - (transports.JobServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_job_service_transport_create_channel_old_api_core( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class(quota_project_id="octopus") - - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.JobServiceGrpcTransport, grpc_helpers), - (transports.JobServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_job_service_transport_create_channel_user_scopes( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=["1", "2"], - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - @pytest.mark.parametrize( "transport_class", [transports.JobServiceGrpcTransport, transports.JobServiceGrpcAsyncIOTransport], @@ -8258,7 +9374,7 @@ def test_job_service_grpc_transport_client_cert_source_for_mtls(transport_class) "squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_channel_creds, quota_project_id=None, options=[ @@ -8281,24 +9397,40 @@ def test_job_service_grpc_transport_client_cert_source_for_mtls(transport_class) ) -def test_job_service_host_no_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_job_service_host_no_port(transport_name): client = JobServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="aiplatform.googleapis.com" ), + transport=transport_name, ) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") -def test_job_service_host_with_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_job_service_host_with_port(transport_name): client = JobServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="aiplatform.googleapis.com:8000" ), + transport=transport_name, ) - assert client.transport._host == "aiplatform.googleapis.com:8000" + assert client.transport._host == ("aiplatform.googleapis.com:8000") def test_job_service_grpc_transport_channel(): @@ -8306,7 +9438,8 @@ def test_job_service_grpc_transport_channel(): # Check that channel is used if provided. transport = transports.JobServiceGrpcTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -8318,7 +9451,8 @@ def test_job_service_grpc_asyncio_transport_channel(): # Check that channel is used if provided. transport = transports.JobServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -8362,7 +9496,7 @@ def test_job_service_transport_channel_mtls_with_client_cert_source(transport_cl "mtls.squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -8406,7 +9540,7 @@ def test_job_service_transport_channel_mtls_with_adc(transport_class): "mtls.squid.clam.whelk:443", credentials=mock_cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -8419,12 +9553,16 @@ def test_job_service_transport_channel_mtls_with_adc(transport_class): def test_job_service_grpc_lro_client(): client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -8432,12 +9570,16 @@ def test_job_service_grpc_lro_client(): def test_job_service_grpc_lro_async_client(): client = JobServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -8448,7 +9590,9 @@ def test_batch_prediction_job_path(): location = "clam" batch_prediction_job = "whelk" expected = "projects/{project}/locations/{location}/batchPredictionJobs/{batch_prediction_job}".format( - project=project, location=location, batch_prediction_job=batch_prediction_job, + project=project, + location=location, + batch_prediction_job=batch_prediction_job, ) actual = JobServiceClient.batch_prediction_job_path( project, location, batch_prediction_job @@ -8474,7 +9618,9 @@ def test_custom_job_path(): location = "mussel" custom_job = "winkle" expected = "projects/{project}/locations/{location}/customJobs/{custom_job}".format( - project=project, location=location, custom_job=custom_job, + project=project, + location=location, + custom_job=custom_job, ) actual = JobServiceClient.custom_job_path(project, location, custom_job) assert expected == actual @@ -8498,7 +9644,9 @@ def test_data_labeling_job_path(): location = "clam" data_labeling_job = "whelk" expected = "projects/{project}/locations/{location}/dataLabelingJobs/{data_labeling_job}".format( - project=project, location=location, data_labeling_job=data_labeling_job, + project=project, + location=location, + data_labeling_job=data_labeling_job, ) actual = JobServiceClient.data_labeling_job_path( project, location, data_labeling_job @@ -8524,7 +9672,9 @@ def test_dataset_path(): location = "mussel" dataset = "winkle" expected = "projects/{project}/locations/{location}/datasets/{dataset}".format( - project=project, location=location, dataset=dataset, + project=project, + location=location, + dataset=dataset, ) actual = JobServiceClient.dataset_path(project, location, dataset) assert expected == actual @@ -8548,7 +9698,9 @@ def test_endpoint_path(): location = "clam" endpoint = "whelk" expected = "projects/{project}/locations/{location}/endpoints/{endpoint}".format( - project=project, location=location, endpoint=endpoint, + project=project, + location=location, + endpoint=endpoint, ) actual = JobServiceClient.endpoint_path(project, location, endpoint) assert expected == actual @@ -8600,7 +9752,9 @@ def test_model_path(): location = "clam" model = "whelk" expected = "projects/{project}/locations/{location}/models/{model}".format( - project=project, location=location, model=model, + project=project, + location=location, + model=model, ) actual = JobServiceClient.model_path(project, location, model) assert expected == actual @@ -8651,7 +9805,8 @@ def test_network_path(): project = "squid" network = "clam" expected = "projects/{project}/global/networks/{network}".format( - project=project, network=network, + project=project, + network=network, ) actual = JobServiceClient.network_path(project, network) assert expected == actual @@ -8673,8 +9828,12 @@ def test_tensorboard_path(): project = "oyster" location = "nudibranch" tensorboard = "cuttlefish" - expected = "projects/{project}/locations/{location}/tensorboards/{tensorboard}".format( - project=project, location=location, tensorboard=tensorboard, + expected = ( + "projects/{project}/locations/{location}/tensorboards/{tensorboard}".format( + project=project, + location=location, + tensorboard=tensorboard, + ) ) actual = JobServiceClient.tensorboard_path(project, location, tensorboard) assert expected == actual @@ -8698,8 +9857,13 @@ def test_trial_path(): location = "abalone" study = "squid" trial = "clam" - expected = "projects/{project}/locations/{location}/studies/{study}/trials/{trial}".format( - project=project, location=location, study=study, trial=trial, + expected = ( + "projects/{project}/locations/{location}/studies/{study}/trials/{trial}".format( + project=project, + location=location, + study=study, + trial=trial, + ) ) actual = JobServiceClient.trial_path(project, location, study, trial) assert expected == actual @@ -8741,7 +9905,9 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "winkle" - expected = "folders/{folder}".format(folder=folder,) + expected = "folders/{folder}".format( + folder=folder, + ) actual = JobServiceClient.common_folder_path(folder) assert expected == actual @@ -8759,7 +9925,9 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "scallop" - expected = "organizations/{organization}".format(organization=organization,) + expected = "organizations/{organization}".format( + organization=organization, + ) actual = JobServiceClient.common_organization_path(organization) assert expected == actual @@ -8777,7 +9945,9 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "squid" - expected = "projects/{project}".format(project=project,) + expected = "projects/{project}".format( + project=project, + ) actual = JobServiceClient.common_project_path(project) assert expected == actual @@ -8797,7 +9967,8 @@ def test_common_location_path(): project = "whelk" location = "octopus" expected = "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) actual = JobServiceClient.common_location_path(project, location) assert expected == actual @@ -8815,14 +9986,15 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( transports.JobServiceTransport, "_prep_wrapped_messages" ) as prep: client = JobServiceClient( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -8831,6 +10003,1591 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = JobServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_delete_operation(transport: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_operation(transport: str = "grpc"): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_operation_field_headers(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = None + + client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_operation_field_headers_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_delete_operation_from_dict(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_delete_operation_from_dict_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_cancel_operation(transport: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation(transport: str = "grpc"): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_wait_operation(transport: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_wait_operation(transport: str = "grpc"): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_wait_operation_field_headers(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_wait_operation_field_headers_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_wait_operation_from_dict(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_wait_operation_from_dict_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_operation(transport: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_get_operation(transport: str = "grpc"): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_get_operation_field_headers(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_get_operation_from_dict(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_operations(transport: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + response = client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +@pytest.mark.asyncio +async def test_list_operations(transport: str = "grpc"): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +def test_list_operations_field_headers(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_operations_field_headers_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_operations_from_dict(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + response = client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_operations_from_dict_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_locations(transport: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + response = client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +@pytest.mark.asyncio +async def test_list_locations(transport: str = "grpc"): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +def test_list_locations_field_headers(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_locations_field_headers_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_locations_from_dict(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + response = client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_locations_from_dict_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_location(transport: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + response = client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +@pytest.mark.asyncio +async def test_get_location_async(transport: str = "grpc_asyncio"): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +def test_get_location_field_headers(): + client = JobServiceClient(credentials=ga_credentials.AnonymousCredentials()) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = locations_pb2.Location() + + client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_location_field_headers_async(): + client = JobServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials()) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +def test_get_location_from_dict(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + response = client.get_location( + request={ + "name": "locations/abc", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_location_from_dict_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_set_iam_policy(transport: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + response = client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + response = await client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_set_iam_policy_field_headers(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_set_iam_policy_field_headers_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_set_iam_policy_from_dict(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_set_iam_policy_from_dict_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +def test_get_iam_policy(transport: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + + response = client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + + response = await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_get_iam_policy_field_headers(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_iam_policy_field_headers_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_get_iam_policy_from_dict(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_iam_policy_from_dict_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +def test_test_iam_permissions(transport: str = "grpc"): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + + response = client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + ) + + response = await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +def test_test_iam_permissions_field_headers(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_field_headers_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_test_iam_permissions_from_dict(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + response = client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_from_dict_async(): + client = JobServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + response = await client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = JobServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (JobServiceClient, transports.JobServiceGrpcTransport), + (JobServiceAsyncClient, transports.JobServiceGrpcAsyncIOTransport), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) diff --git a/tests/unit/gapic/aiplatform_v1beta1/test_metadata_service.py b/tests/unit/gapic/aiplatform_v1beta1/test_metadata_service.py index 2b2ce80c5c..8111d69510 100644 --- a/tests/unit/gapic/aiplatform_v1beta1/test_metadata_service.py +++ b/tests/unit/gapic/aiplatform_v1beta1/test_metadata_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,8 +14,13 @@ # limitations under the License. # import os -import mock -import packaging.version + +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock +except ImportError: + import mock import grpc from grpc.experimental import aio @@ -30,8 +35,10 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.aiplatform_v1beta1.services.metadata_service import ( @@ -42,12 +49,6 @@ ) from google.cloud.aiplatform_v1beta1.services.metadata_service import pagers from google.cloud.aiplatform_v1beta1.services.metadata_service import transports -from google.cloud.aiplatform_v1beta1.services.metadata_service.transports.base import ( - _API_CORE_VERSION, -) -from google.cloud.aiplatform_v1beta1.services.metadata_service.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.aiplatform_v1beta1.types import artifact from google.cloud.aiplatform_v1beta1.types import artifact as gca_artifact from google.cloud.aiplatform_v1beta1.types import context @@ -63,6 +64,10 @@ from google.cloud.aiplatform_v1beta1.types import metadata_store from google.cloud.aiplatform_v1beta1.types import metadata_store as gca_metadata_store from google.cloud.aiplatform_v1beta1.types import operation as gca_operation +from google.cloud.location import locations_pb2 +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 from google.oauth2 import service_account from google.protobuf import field_mask_pb2 # type: ignore @@ -71,29 +76,6 @@ import google.auth -# TODO(busunkim): Once google-api-core >= 1.26.0 is required: -# - Delete all the api-core and auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - -requires_api_core_lt_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), - reason="This test requires google-api-core < 1.26.0", -) - -requires_api_core_gte_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), - reason="This test requires google-api-core >= 1.26.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -139,40 +121,81 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( - "client_class", [MetadataServiceClient, MetadataServiceAsyncClient,] + "client_class,transport_name", + [ + (MetadataServiceClient, "grpc"), + (MetadataServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_metadata_service_client_from_service_account_info(client_class): +def test_metadata_service_client_from_service_account_info( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.MetadataServiceGrpcTransport, "grpc"), + (transports.MetadataServiceGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_metadata_service_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() @pytest.mark.parametrize( - "client_class", [MetadataServiceClient, MetadataServiceAsyncClient,] + "client_class,transport_name", + [ + (MetadataServiceClient, "grpc"), + (MetadataServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_metadata_service_client_from_service_account_file(client_class): +def test_metadata_service_client_from_service_account_file( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") def test_metadata_service_client_get_transport_class(): @@ -225,7 +248,7 @@ def test_metadata_service_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -234,6 +257,7 @@ def test_metadata_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -241,7 +265,7 @@ def test_metadata_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -250,6 +274,7 @@ def test_metadata_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -257,7 +282,7 @@ def test_metadata_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -266,26 +291,27 @@ def test_metadata_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -294,6 +320,7 @@ def test_metadata_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -353,7 +380,7 @@ def test_metadata_service_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -370,6 +397,7 @@ def test_metadata_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case ADC client cert is provided. Whether client cert is used depends on @@ -394,7 +422,7 @@ def test_metadata_service_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -403,6 +431,7 @@ def test_metadata_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case client_cert_source and ADC client cert are not provided. @@ -415,7 +444,7 @@ def test_metadata_service_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -424,9 +453,91 @@ def test_metadata_service_client_mtls_env_auto( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) +@pytest.mark.parametrize( + "client_class", [MetadataServiceClient, MetadataServiceAsyncClient] +) +@mock.patch.object( + MetadataServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(MetadataServiceClient), +) +@mock.patch.object( + MetadataServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(MetadataServiceAsyncClient), +) +def test_metadata_service_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + @pytest.mark.parametrize( "client_class,transport_class,transport_name", [ @@ -442,10 +553,12 @@ def test_metadata_service_client_client_options_scopes( client_class, transport_class, transport_name ): # Check the case scopes are provided. - options = client_options.ClientOptions(scopes=["1", "2"],) + options = client_options.ClientOptions( + scopes=["1", "2"], + ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -454,28 +567,36 @@ def test_metadata_service_client_client_options_scopes( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (MetadataServiceClient, transports.MetadataServiceGrpcTransport, "grpc"), + ( + MetadataServiceClient, + transports.MetadataServiceGrpcTransport, + "grpc", + grpc_helpers, + ), ( MetadataServiceAsyncClient, transports.MetadataServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_metadata_service_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -484,6 +605,7 @@ def test_metadata_service_client_client_options_credentials_file( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -503,14 +625,87 @@ def test_metadata_service_client_client_options_from_dict(): client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) -def test_create_metadata_store( - transport: str = "grpc", request_type=metadata_service.CreateMetadataStoreRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + MetadataServiceClient, + transports.MetadataServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + MetadataServiceAsyncClient, + transports.MetadataServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_metadata_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers ): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.CreateMetadataStoreRequest, + dict, + ], +) +def test_create_metadata_store(request_type, transport: str = "grpc"): client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -534,15 +729,12 @@ def test_create_metadata_store( assert isinstance(response, future.Future) -def test_create_metadata_store_from_dict(): - test_create_metadata_store(request_type=dict) - - def test_create_metadata_store_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -561,7 +753,8 @@ async def test_create_metadata_store_async( request_type=metadata_service.CreateMetadataStoreRequest, ): client = MetadataServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -593,13 +786,15 @@ async def test_create_metadata_store_async_from_dict(): def test_create_metadata_store_field_headers(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = metadata_service.CreateMetadataStoreRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -615,7 +810,10 @@ def test_create_metadata_store_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -628,7 +826,7 @@ async def test_create_metadata_store_field_headers_async(): # a field header. Set these to a non-empty value. request = metadata_service.CreateMetadataStoreRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -646,11 +844,16 @@ async def test_create_metadata_store_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_create_metadata_store_flattened(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -670,15 +873,21 @@ def test_create_metadata_store_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].metadata_store == gca_metadata_store.MetadataStore( - name="name_value" - ) - assert args[0].metadata_store_id == "metadata_store_id_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].metadata_store + mock_val = gca_metadata_store.MetadataStore(name="name_value") + assert arg == mock_val + arg = args[0].metadata_store_id + mock_val = "metadata_store_id_value" + assert arg == mock_val def test_create_metadata_store_flattened_error(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -719,11 +928,15 @@ async def test_create_metadata_store_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].metadata_store == gca_metadata_store.MetadataStore( - name="name_value" - ) - assert args[0].metadata_store_id == "metadata_store_id_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].metadata_store + mock_val = gca_metadata_store.MetadataStore(name="name_value") + assert arg == mock_val + arg = args[0].metadata_store_id + mock_val = "metadata_store_id_value" + assert arg == mock_val @pytest.mark.asyncio @@ -743,11 +956,17 @@ async def test_create_metadata_store_flattened_error_async(): ) -def test_get_metadata_store( - transport: str = "grpc", request_type=metadata_service.GetMetadataStoreRequest -): +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.GetMetadataStoreRequest, + dict, + ], +) +def test_get_metadata_store(request_type, transport: str = "grpc"): client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -760,7 +979,8 @@ def test_get_metadata_store( ) as call: # Designate an appropriate return value for the call. call.return_value = metadata_store.MetadataStore( - name="name_value", description="description_value", + name="name_value", + description="description_value", ) response = client.get_metadata_store(request) @@ -775,15 +995,12 @@ def test_get_metadata_store( assert response.description == "description_value" -def test_get_metadata_store_from_dict(): - test_get_metadata_store(request_type=dict) - - def test_get_metadata_store_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -802,7 +1019,8 @@ async def test_get_metadata_store_async( request_type=metadata_service.GetMetadataStoreRequest, ): client = MetadataServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -816,7 +1034,8 @@ async def test_get_metadata_store_async( # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( metadata_store.MetadataStore( - name="name_value", description="description_value", + name="name_value", + description="description_value", ) ) response = await client.get_metadata_store(request) @@ -838,13 +1057,15 @@ async def test_get_metadata_store_async_from_dict(): def test_get_metadata_store_field_headers(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = metadata_service.GetMetadataStoreRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -860,7 +1081,10 @@ def test_get_metadata_store_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -873,7 +1097,7 @@ async def test_get_metadata_store_field_headers_async(): # a field header. Set these to a non-empty value. request = metadata_service.GetMetadataStoreRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -891,11 +1115,16 @@ async def test_get_metadata_store_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_get_metadata_store_flattened(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -905,23 +1134,30 @@ def test_get_metadata_store_flattened(): call.return_value = metadata_store.MetadataStore() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_metadata_store(name="name_value",) + client.get_metadata_store( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_metadata_store_flattened_error(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.get_metadata_store( - metadata_service.GetMetadataStoreRequest(), name="name_value", + metadata_service.GetMetadataStoreRequest(), + name="name_value", ) @@ -943,13 +1179,17 @@ async def test_get_metadata_store_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_metadata_store(name="name_value",) + response = await client.get_metadata_store( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -962,15 +1202,22 @@ async def test_get_metadata_store_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.get_metadata_store( - metadata_service.GetMetadataStoreRequest(), name="name_value", + metadata_service.GetMetadataStoreRequest(), + name="name_value", ) -def test_list_metadata_stores( - transport: str = "grpc", request_type=metadata_service.ListMetadataStoresRequest -): +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.ListMetadataStoresRequest, + dict, + ], +) +def test_list_metadata_stores(request_type, transport: str = "grpc"): client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -997,15 +1244,12 @@ def test_list_metadata_stores( assert response.next_page_token == "next_page_token_value" -def test_list_metadata_stores_from_dict(): - test_list_metadata_stores(request_type=dict) - - def test_list_metadata_stores_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1024,7 +1268,8 @@ async def test_list_metadata_stores_async( request_type=metadata_service.ListMetadataStoresRequest, ): client = MetadataServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1059,13 +1304,15 @@ async def test_list_metadata_stores_async_from_dict(): def test_list_metadata_stores_field_headers(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = metadata_service.ListMetadataStoresRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1081,7 +1328,10 @@ def test_list_metadata_stores_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1094,7 +1344,7 @@ async def test_list_metadata_stores_field_headers_async(): # a field header. Set these to a non-empty value. request = metadata_service.ListMetadataStoresRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1112,11 +1362,16 @@ async def test_list_metadata_stores_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_metadata_stores_flattened(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1126,23 +1381,30 @@ def test_list_metadata_stores_flattened(): call.return_value = metadata_service.ListMetadataStoresResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_metadata_stores(parent="parent_value",) + client.list_metadata_stores( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_metadata_stores_flattened_error(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.list_metadata_stores( - metadata_service.ListMetadataStoresRequest(), parent="parent_value", + metadata_service.ListMetadataStoresRequest(), + parent="parent_value", ) @@ -1164,13 +1426,17 @@ async def test_list_metadata_stores_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_metadata_stores(parent="parent_value",) + response = await client.list_metadata_stores( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1183,12 +1449,16 @@ async def test_list_metadata_stores_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.list_metadata_stores( - metadata_service.ListMetadataStoresRequest(), parent="parent_value", + metadata_service.ListMetadataStoresRequest(), + parent="parent_value", ) -def test_list_metadata_stores_pager(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_metadata_stores_pager(transport_name: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1205,10 +1475,13 @@ def test_list_metadata_stores_pager(): next_page_token="abc", ), metadata_service.ListMetadataStoresResponse( - metadata_stores=[], next_page_token="def", + metadata_stores=[], + next_page_token="def", ), metadata_service.ListMetadataStoresResponse( - metadata_stores=[metadata_store.MetadataStore(),], + metadata_stores=[ + metadata_store.MetadataStore(), + ], next_page_token="ghi", ), metadata_service.ListMetadataStoresResponse( @@ -1228,13 +1501,16 @@ def test_list_metadata_stores_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all(isinstance(i, metadata_store.MetadataStore) for i in results) -def test_list_metadata_stores_pages(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_metadata_stores_pages(transport_name: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1251,10 +1527,13 @@ def test_list_metadata_stores_pages(): next_page_token="abc", ), metadata_service.ListMetadataStoresResponse( - metadata_stores=[], next_page_token="def", + metadata_stores=[], + next_page_token="def", ), metadata_service.ListMetadataStoresResponse( - metadata_stores=[metadata_store.MetadataStore(),], + metadata_stores=[ + metadata_store.MetadataStore(), + ], next_page_token="ghi", ), metadata_service.ListMetadataStoresResponse( @@ -1293,10 +1572,13 @@ async def test_list_metadata_stores_async_pager(): next_page_token="abc", ), metadata_service.ListMetadataStoresResponse( - metadata_stores=[], next_page_token="def", + metadata_stores=[], + next_page_token="def", ), metadata_service.ListMetadataStoresResponse( - metadata_stores=[metadata_store.MetadataStore(),], + metadata_stores=[ + metadata_store.MetadataStore(), + ], next_page_token="ghi", ), metadata_service.ListMetadataStoresResponse( @@ -1307,10 +1589,12 @@ async def test_list_metadata_stores_async_pager(): ), RuntimeError, ) - async_pager = await client.list_metadata_stores(request={},) + async_pager = await client.list_metadata_stores( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -1340,10 +1624,13 @@ async def test_list_metadata_stores_async_pages(): next_page_token="abc", ), metadata_service.ListMetadataStoresResponse( - metadata_stores=[], next_page_token="def", + metadata_stores=[], + next_page_token="def", ), metadata_service.ListMetadataStoresResponse( - metadata_stores=[metadata_store.MetadataStore(),], + metadata_stores=[ + metadata_store.MetadataStore(), + ], next_page_token="ghi", ), metadata_service.ListMetadataStoresResponse( @@ -1355,17 +1642,25 @@ async def test_list_metadata_stores_async_pages(): RuntimeError, ) pages = [] - async for page_ in (await client.list_metadata_stores(request={})).pages: + async for page_ in ( + await client.list_metadata_stores(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_delete_metadata_store( - transport: str = "grpc", request_type=metadata_service.DeleteMetadataStoreRequest -): +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.DeleteMetadataStoreRequest, + dict, + ], +) +def test_delete_metadata_store(request_type, transport: str = "grpc"): client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1389,15 +1684,12 @@ def test_delete_metadata_store( assert isinstance(response, future.Future) -def test_delete_metadata_store_from_dict(): - test_delete_metadata_store(request_type=dict) - - def test_delete_metadata_store_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1416,7 +1708,8 @@ async def test_delete_metadata_store_async( request_type=metadata_service.DeleteMetadataStoreRequest, ): client = MetadataServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1448,13 +1741,15 @@ async def test_delete_metadata_store_async_from_dict(): def test_delete_metadata_store_field_headers(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = metadata_service.DeleteMetadataStoreRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1470,7 +1765,10 @@ def test_delete_metadata_store_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1483,7 +1781,7 @@ async def test_delete_metadata_store_field_headers_async(): # a field header. Set these to a non-empty value. request = metadata_service.DeleteMetadataStoreRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1501,11 +1799,16 @@ async def test_delete_metadata_store_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_delete_metadata_store_flattened(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1515,23 +1818,30 @@ def test_delete_metadata_store_flattened(): call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_metadata_store(name="name_value",) + client.delete_metadata_store( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_delete_metadata_store_flattened_error(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.delete_metadata_store( - metadata_service.DeleteMetadataStoreRequest(), name="name_value", + metadata_service.DeleteMetadataStoreRequest(), + name="name_value", ) @@ -1553,13 +1863,17 @@ async def test_delete_metadata_store_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_metadata_store(name="name_value",) + response = await client.delete_metadata_store( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1572,15 +1886,22 @@ async def test_delete_metadata_store_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.delete_metadata_store( - metadata_service.DeleteMetadataStoreRequest(), name="name_value", + metadata_service.DeleteMetadataStoreRequest(), + name="name_value", ) -def test_create_artifact( - transport: str = "grpc", request_type=metadata_service.CreateArtifactRequest -): +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.CreateArtifactRequest, + dict, + ], +) +def test_create_artifact(request_type, transport: str = "grpc"): client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1619,15 +1940,12 @@ def test_create_artifact( assert response.description == "description_value" -def test_create_artifact_from_dict(): - test_create_artifact(request_type=dict) - - def test_create_artifact_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1643,7 +1961,8 @@ async def test_create_artifact_async( transport: str = "grpc_asyncio", request_type=metadata_service.CreateArtifactRequest ): client = MetadataServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1690,13 +2009,15 @@ async def test_create_artifact_async_from_dict(): def test_create_artifact_field_headers(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = metadata_service.CreateArtifactRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_artifact), "__call__") as call: @@ -1710,7 +2031,10 @@ def test_create_artifact_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1723,7 +2047,7 @@ async def test_create_artifact_field_headers_async(): # a field header. Set these to a non-empty value. request = metadata_service.CreateArtifactRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_artifact), "__call__") as call: @@ -1739,11 +2063,16 @@ async def test_create_artifact_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_create_artifact_flattened(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_artifact), "__call__") as call: @@ -1761,13 +2090,21 @@ def test_create_artifact_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].artifact == gca_artifact.Artifact(name="name_value") - assert args[0].artifact_id == "artifact_id_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].artifact + mock_val = gca_artifact.Artifact(name="name_value") + assert arg == mock_val + arg = args[0].artifact_id + mock_val = "artifact_id_value" + assert arg == mock_val def test_create_artifact_flattened_error(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1806,9 +2143,15 @@ async def test_create_artifact_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].artifact == gca_artifact.Artifact(name="name_value") - assert args[0].artifact_id == "artifact_id_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].artifact + mock_val = gca_artifact.Artifact(name="name_value") + assert arg == mock_val + arg = args[0].artifact_id + mock_val = "artifact_id_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1828,11 +2171,17 @@ async def test_create_artifact_flattened_error_async(): ) -def test_get_artifact( - transport: str = "grpc", request_type=metadata_service.GetArtifactRequest -): +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.GetArtifactRequest, + dict, + ], +) +def test_get_artifact(request_type, transport: str = "grpc"): client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1871,15 +2220,12 @@ def test_get_artifact( assert response.description == "description_value" -def test_get_artifact_from_dict(): - test_get_artifact(request_type=dict) - - def test_get_artifact_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1895,7 +2241,8 @@ async def test_get_artifact_async( transport: str = "grpc_asyncio", request_type=metadata_service.GetArtifactRequest ): client = MetadataServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1942,13 +2289,15 @@ async def test_get_artifact_async_from_dict(): def test_get_artifact_field_headers(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = metadata_service.GetArtifactRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_artifact), "__call__") as call: @@ -1962,7 +2311,10 @@ def test_get_artifact_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1975,7 +2327,7 @@ async def test_get_artifact_field_headers_async(): # a field header. Set these to a non-empty value. request = metadata_service.GetArtifactRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_artifact), "__call__") as call: @@ -1989,11 +2341,16 @@ async def test_get_artifact_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_get_artifact_flattened(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_artifact), "__call__") as call: @@ -2001,23 +2358,30 @@ def test_get_artifact_flattened(): call.return_value = artifact.Artifact() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_artifact(name="name_value",) + client.get_artifact( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_artifact_flattened_error(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.get_artifact( - metadata_service.GetArtifactRequest(), name="name_value", + metadata_service.GetArtifactRequest(), + name="name_value", ) @@ -2035,13 +2399,17 @@ async def test_get_artifact_flattened_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(artifact.Artifact()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_artifact(name="name_value",) + response = await client.get_artifact( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -2054,15 +2422,22 @@ async def test_get_artifact_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.get_artifact( - metadata_service.GetArtifactRequest(), name="name_value", + metadata_service.GetArtifactRequest(), + name="name_value", ) -def test_list_artifacts( - transport: str = "grpc", request_type=metadata_service.ListArtifactsRequest -): +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.ListArtifactsRequest, + dict, + ], +) +def test_list_artifacts(request_type, transport: str = "grpc"): client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2087,15 +2462,12 @@ def test_list_artifacts( assert response.next_page_token == "next_page_token_value" -def test_list_artifacts_from_dict(): - test_list_artifacts(request_type=dict) - - def test_list_artifacts_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2111,7 +2483,8 @@ async def test_list_artifacts_async( transport: str = "grpc_asyncio", request_type=metadata_service.ListArtifactsRequest ): client = MetadataServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2144,13 +2517,15 @@ async def test_list_artifacts_async_from_dict(): def test_list_artifacts_field_headers(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = metadata_service.ListArtifactsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_artifacts), "__call__") as call: @@ -2164,7 +2539,10 @@ def test_list_artifacts_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2177,7 +2555,7 @@ async def test_list_artifacts_field_headers_async(): # a field header. Set these to a non-empty value. request = metadata_service.ListArtifactsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_artifacts), "__call__") as call: @@ -2193,11 +2571,16 @@ async def test_list_artifacts_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_artifacts_flattened(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_artifacts), "__call__") as call: @@ -2205,23 +2588,30 @@ def test_list_artifacts_flattened(): call.return_value = metadata_service.ListArtifactsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_artifacts(parent="parent_value",) + client.list_artifacts( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_artifacts_flattened_error(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.list_artifacts( - metadata_service.ListArtifactsRequest(), parent="parent_value", + metadata_service.ListArtifactsRequest(), + parent="parent_value", ) @@ -2241,13 +2631,17 @@ async def test_list_artifacts_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_artifacts(parent="parent_value",) + response = await client.list_artifacts( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -2260,12 +2654,16 @@ async def test_list_artifacts_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.list_artifacts( - metadata_service.ListArtifactsRequest(), parent="parent_value", + metadata_service.ListArtifactsRequest(), + parent="parent_value", ) -def test_list_artifacts_pager(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_artifacts_pager(transport_name: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_artifacts), "__call__") as call: @@ -2280,13 +2678,20 @@ def test_list_artifacts_pager(): next_page_token="abc", ), metadata_service.ListArtifactsResponse( - artifacts=[], next_page_token="def", + artifacts=[], + next_page_token="def", ), metadata_service.ListArtifactsResponse( - artifacts=[artifact.Artifact(),], next_page_token="ghi", + artifacts=[ + artifact.Artifact(), + ], + next_page_token="ghi", ), metadata_service.ListArtifactsResponse( - artifacts=[artifact.Artifact(), artifact.Artifact(),], + artifacts=[ + artifact.Artifact(), + artifact.Artifact(), + ], ), RuntimeError, ) @@ -2299,13 +2704,16 @@ def test_list_artifacts_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all(isinstance(i, artifact.Artifact) for i in results) -def test_list_artifacts_pages(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_artifacts_pages(transport_name: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_artifacts), "__call__") as call: @@ -2320,13 +2728,20 @@ def test_list_artifacts_pages(): next_page_token="abc", ), metadata_service.ListArtifactsResponse( - artifacts=[], next_page_token="def", + artifacts=[], + next_page_token="def", ), metadata_service.ListArtifactsResponse( - artifacts=[artifact.Artifact(),], next_page_token="ghi", + artifacts=[ + artifact.Artifact(), + ], + next_page_token="ghi", ), metadata_service.ListArtifactsResponse( - artifacts=[artifact.Artifact(), artifact.Artifact(),], + artifacts=[ + artifact.Artifact(), + artifact.Artifact(), + ], ), RuntimeError, ) @@ -2356,20 +2771,29 @@ async def test_list_artifacts_async_pager(): next_page_token="abc", ), metadata_service.ListArtifactsResponse( - artifacts=[], next_page_token="def", + artifacts=[], + next_page_token="def", ), metadata_service.ListArtifactsResponse( - artifacts=[artifact.Artifact(),], next_page_token="ghi", + artifacts=[ + artifact.Artifact(), + ], + next_page_token="ghi", ), metadata_service.ListArtifactsResponse( - artifacts=[artifact.Artifact(), artifact.Artifact(),], + artifacts=[ + artifact.Artifact(), + artifact.Artifact(), + ], ), RuntimeError, ) - async_pager = await client.list_artifacts(request={},) + async_pager = await client.list_artifacts( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -2397,28 +2821,43 @@ async def test_list_artifacts_async_pages(): next_page_token="abc", ), metadata_service.ListArtifactsResponse( - artifacts=[], next_page_token="def", + artifacts=[], + next_page_token="def", ), metadata_service.ListArtifactsResponse( - artifacts=[artifact.Artifact(),], next_page_token="ghi", + artifacts=[ + artifact.Artifact(), + ], + next_page_token="ghi", ), metadata_service.ListArtifactsResponse( - artifacts=[artifact.Artifact(), artifact.Artifact(),], + artifacts=[ + artifact.Artifact(), + artifact.Artifact(), + ], ), RuntimeError, ) pages = [] - async for page_ in (await client.list_artifacts(request={})).pages: + async for page_ in ( + await client.list_artifacts(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_update_artifact( - transport: str = "grpc", request_type=metadata_service.UpdateArtifactRequest -): +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.UpdateArtifactRequest, + dict, + ], +) +def test_update_artifact(request_type, transport: str = "grpc"): client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2457,15 +2896,12 @@ def test_update_artifact( assert response.description == "description_value" -def test_update_artifact_from_dict(): - test_update_artifact(request_type=dict) - - def test_update_artifact_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2481,7 +2917,8 @@ async def test_update_artifact_async( transport: str = "grpc_asyncio", request_type=metadata_service.UpdateArtifactRequest ): client = MetadataServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2528,13 +2965,15 @@ async def test_update_artifact_async_from_dict(): def test_update_artifact_field_headers(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = metadata_service.UpdateArtifactRequest() - request.artifact.name = "artifact.name/value" + request.artifact.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_artifact), "__call__") as call: @@ -2548,9 +2987,10 @@ def test_update_artifact_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "artifact.name=artifact.name/value",) in kw[ - "metadata" - ] + assert ( + "x-goog-request-params", + "artifact.name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2563,7 +3003,7 @@ async def test_update_artifact_field_headers_async(): # a field header. Set these to a non-empty value. request = metadata_service.UpdateArtifactRequest() - request.artifact.name = "artifact.name/value" + request.artifact.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_artifact), "__call__") as call: @@ -2579,13 +3019,16 @@ async def test_update_artifact_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "artifact.name=artifact.name/value",) in kw[ - "metadata" - ] + assert ( + "x-goog-request-params", + "artifact.name=name_value", + ) in kw["metadata"] def test_update_artifact_flattened(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.update_artifact), "__call__") as call: @@ -2602,12 +3045,18 @@ def test_update_artifact_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].artifact == gca_artifact.Artifact(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].artifact + mock_val = gca_artifact.Artifact(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val def test_update_artifact_flattened_error(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2644,8 +3093,12 @@ async def test_update_artifact_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].artifact == gca_artifact.Artifact(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].artifact + mock_val = gca_artifact.Artifact(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val @pytest.mark.asyncio @@ -2664,11 +3117,17 @@ async def test_update_artifact_flattened_error_async(): ) -def test_create_context( - transport: str = "grpc", request_type=metadata_service.CreateContextRequest -): +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.DeleteArtifactRequest, + dict, + ], +) +def test_delete_artifact(request_type, transport: str = "grpc"): client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2676,60 +3135,43 @@ def test_create_context( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_context), "__call__") as call: + with mock.patch.object(type(client.transport.delete_artifact), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = gca_context.Context( - name="name_value", - display_name="display_name_value", - etag="etag_value", - parent_contexts=["parent_contexts_value"], - schema_title="schema_title_value", - schema_version="schema_version_value", - description="description_value", - ) - response = client.create_context(request) + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.delete_artifact(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.CreateContextRequest() + assert args[0] == metadata_service.DeleteArtifactRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gca_context.Context) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.etag == "etag_value" - assert response.parent_contexts == ["parent_contexts_value"] - assert response.schema_title == "schema_title_value" - assert response.schema_version == "schema_version_value" - assert response.description == "description_value" - - -def test_create_context_from_dict(): - test_create_context(request_type=dict) + assert isinstance(response, future.Future) -def test_create_context_empty_call(): +def test_delete_artifact_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_context), "__call__") as call: - client.create_context() + with mock.patch.object(type(client.transport.delete_artifact), "__call__") as call: + client.delete_artifact() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.CreateContextRequest() + assert args[0] == metadata_service.DeleteArtifactRequest() @pytest.mark.asyncio -async def test_create_context_async( - transport: str = "grpc_asyncio", request_type=metadata_service.CreateContextRequest +async def test_delete_artifact_async( + transport: str = "grpc_asyncio", request_type=metadata_service.DeleteArtifactRequest ): client = MetadataServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2737,55 +3179,42 @@ async def test_create_context_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_context), "__call__") as call: + with mock.patch.object(type(client.transport.delete_artifact), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gca_context.Context( - name="name_value", - display_name="display_name_value", - etag="etag_value", - parent_contexts=["parent_contexts_value"], - schema_title="schema_title_value", - schema_version="schema_version_value", - description="description_value", - ) + operations_pb2.Operation(name="operations/spam") ) - response = await client.create_context(request) + response = await client.delete_artifact(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.CreateContextRequest() + assert args[0] == metadata_service.DeleteArtifactRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gca_context.Context) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.etag == "etag_value" - assert response.parent_contexts == ["parent_contexts_value"] - assert response.schema_title == "schema_title_value" - assert response.schema_version == "schema_version_value" - assert response.description == "description_value" + assert isinstance(response, future.Future) @pytest.mark.asyncio -async def test_create_context_async_from_dict(): - await test_create_context_async(request_type=dict) +async def test_delete_artifact_async_from_dict(): + await test_delete_artifact_async(request_type=dict) -def test_create_context_field_headers(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_delete_artifact_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = metadata_service.CreateContextRequest() + request = metadata_service.DeleteArtifactRequest() - request.parent = "parent/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_context), "__call__") as call: - call.return_value = gca_context.Context() - client.create_context(request) + with mock.patch.object(type(client.transport.delete_artifact), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_artifact(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -2794,25 +3223,30 @@ def test_create_context_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_create_context_field_headers_async(): +async def test_delete_artifact_field_headers_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = metadata_service.CreateContextRequest() + request = metadata_service.DeleteArtifactRequest() - request.parent = "parent/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_context), "__call__") as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gca_context.Context()) - await client.create_context(request) + with mock.patch.object(type(client.transport.delete_artifact), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.delete_artifact(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -2821,78 +3255,81 @@ async def test_create_context_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] -def test_create_context_flattened(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_delete_artifact_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_context), "__call__") as call: + with mock.patch.object(type(client.transport.delete_artifact), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = gca_context.Context() + call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.create_context( - parent="parent_value", - context=gca_context.Context(name="name_value"), - context_id="context_id_value", + client.delete_artifact( + name="name_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].context == gca_context.Context(name="name_value") - assert args[0].context_id == "context_id_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val -def test_create_context_flattened_error(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_delete_artifact_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.create_context( - metadata_service.CreateContextRequest(), - parent="parent_value", - context=gca_context.Context(name="name_value"), - context_id="context_id_value", + client.delete_artifact( + metadata_service.DeleteArtifactRequest(), + name="name_value", ) @pytest.mark.asyncio -async def test_create_context_flattened_async(): +async def test_delete_artifact_flattened_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_context), "__call__") as call: + with mock.patch.object(type(client.transport.delete_artifact), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = gca_context.Context() + call.return_value = operations_pb2.Operation(name="operations/op") - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gca_context.Context()) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.create_context( - parent="parent_value", - context=gca_context.Context(name="name_value"), - context_id="context_id_value", + response = await client.delete_artifact( + name="name_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].context == gca_context.Context(name="name_value") - assert args[0].context_id == "context_id_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio -async def test_create_context_flattened_error_async(): +async def test_delete_artifact_flattened_error_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -2900,19 +3337,23 @@ async def test_create_context_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.create_context( - metadata_service.CreateContextRequest(), - parent="parent_value", - context=gca_context.Context(name="name_value"), - context_id="context_id_value", + await client.delete_artifact( + metadata_service.DeleteArtifactRequest(), + name="name_value", ) -def test_get_context( - transport: str = "grpc", request_type=metadata_service.GetContextRequest -): - client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.PurgeArtifactsRequest, + dict, + ], +) +def test_purge_artifacts(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2920,60 +3361,43 @@ def test_get_context( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_context), "__call__") as call: + with mock.patch.object(type(client.transport.purge_artifacts), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = context.Context( - name="name_value", - display_name="display_name_value", - etag="etag_value", - parent_contexts=["parent_contexts_value"], - schema_title="schema_title_value", - schema_version="schema_version_value", - description="description_value", - ) - response = client.get_context(request) + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.purge_artifacts(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.GetContextRequest() + assert args[0] == metadata_service.PurgeArtifactsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, context.Context) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.etag == "etag_value" - assert response.parent_contexts == ["parent_contexts_value"] - assert response.schema_title == "schema_title_value" - assert response.schema_version == "schema_version_value" - assert response.description == "description_value" - - -def test_get_context_from_dict(): - test_get_context(request_type=dict) + assert isinstance(response, future.Future) -def test_get_context_empty_call(): +def test_purge_artifacts_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_context), "__call__") as call: - client.get_context() + with mock.patch.object(type(client.transport.purge_artifacts), "__call__") as call: + client.purge_artifacts() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.GetContextRequest() + assert args[0] == metadata_service.PurgeArtifactsRequest() @pytest.mark.asyncio -async def test_get_context_async( - transport: str = "grpc_asyncio", request_type=metadata_service.GetContextRequest +async def test_purge_artifacts_async( + transport: str = "grpc_asyncio", request_type=metadata_service.PurgeArtifactsRequest ): client = MetadataServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2981,55 +3405,42 @@ async def test_get_context_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_context), "__call__") as call: + with mock.patch.object(type(client.transport.purge_artifacts), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - context.Context( - name="name_value", - display_name="display_name_value", - etag="etag_value", - parent_contexts=["parent_contexts_value"], - schema_title="schema_title_value", - schema_version="schema_version_value", - description="description_value", - ) + operations_pb2.Operation(name="operations/spam") ) - response = await client.get_context(request) + response = await client.purge_artifacts(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.GetContextRequest() + assert args[0] == metadata_service.PurgeArtifactsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, context.Context) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.etag == "etag_value" - assert response.parent_contexts == ["parent_contexts_value"] - assert response.schema_title == "schema_title_value" - assert response.schema_version == "schema_version_value" - assert response.description == "description_value" + assert isinstance(response, future.Future) @pytest.mark.asyncio -async def test_get_context_async_from_dict(): - await test_get_context_async(request_type=dict) +async def test_purge_artifacts_async_from_dict(): + await test_purge_artifacts_async(request_type=dict) -def test_get_context_field_headers(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_purge_artifacts_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = metadata_service.GetContextRequest() + request = metadata_service.PurgeArtifactsRequest() - request.name = "name/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_context), "__call__") as call: - call.return_value = context.Context() - client.get_context(request) + with mock.patch.object(type(client.transport.purge_artifacts), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.purge_artifacts(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -3038,25 +3449,30 @@ def test_get_context_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_get_context_field_headers_async(): +async def test_purge_artifacts_field_headers_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = metadata_service.GetContextRequest() + request = metadata_service.PurgeArtifactsRequest() - request.name = "name/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_context), "__call__") as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(context.Context()) - await client.get_context(request) + with mock.patch.object(type(client.transport.purge_artifacts), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") + ) + await client.purge_artifacts(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -3065,63 +3481,81 @@ async def test_get_context_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] -def test_get_context_flattened(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_purge_artifacts_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_context), "__call__") as call: + with mock.patch.object(type(client.transport.purge_artifacts), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = context.Context() + call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_context(name="name_value",) + client.purge_artifacts( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val -def test_get_context_flattened_error(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_purge_artifacts_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_context( - metadata_service.GetContextRequest(), name="name_value", + client.purge_artifacts( + metadata_service.PurgeArtifactsRequest(), + parent="parent_value", ) @pytest.mark.asyncio -async def test_get_context_flattened_async(): +async def test_purge_artifacts_flattened_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_context), "__call__") as call: + with mock.patch.object(type(client.transport.purge_artifacts), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = context.Context() + call.return_value = operations_pb2.Operation(name="operations/op") - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(context.Context()) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_context(name="name_value",) + response = await client.purge_artifacts( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio -async def test_get_context_flattened_error_async(): +async def test_purge_artifacts_flattened_error_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -3129,16 +3563,23 @@ async def test_get_context_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.get_context( - metadata_service.GetContextRequest(), name="name_value", + await client.purge_artifacts( + metadata_service.PurgeArtifactsRequest(), + parent="parent_value", ) -def test_list_contexts( - transport: str = "grpc", request_type=metadata_service.ListContextsRequest -): +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.CreateContextRequest, + dict, + ], +) +def test_create_context(request_type, transport: str = "grpc"): client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3146,48 +3587,58 @@ def test_list_contexts( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_contexts), "__call__") as call: + with mock.patch.object(type(client.transport.create_context), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = metadata_service.ListContextsResponse( - next_page_token="next_page_token_value", + call.return_value = gca_context.Context( + name="name_value", + display_name="display_name_value", + etag="etag_value", + parent_contexts=["parent_contexts_value"], + schema_title="schema_title_value", + schema_version="schema_version_value", + description="description_value", ) - response = client.list_contexts(request) + response = client.create_context(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.ListContextsRequest() + assert args[0] == metadata_service.CreateContextRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListContextsPager) - assert response.next_page_token == "next_page_token_value" - - -def test_list_contexts_from_dict(): - test_list_contexts(request_type=dict) + assert isinstance(response, gca_context.Context) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.etag == "etag_value" + assert response.parent_contexts == ["parent_contexts_value"] + assert response.schema_title == "schema_title_value" + assert response.schema_version == "schema_version_value" + assert response.description == "description_value" -def test_list_contexts_empty_call(): +def test_create_context_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_contexts), "__call__") as call: - client.list_contexts() + with mock.patch.object(type(client.transport.create_context), "__call__") as call: + client.create_context() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.ListContextsRequest() + assert args[0] == metadata_service.CreateContextRequest() @pytest.mark.asyncio -async def test_list_contexts_async( - transport: str = "grpc_asyncio", request_type=metadata_service.ListContextsRequest +async def test_create_context_async( + transport: str = "grpc_asyncio", request_type=metadata_service.CreateContextRequest ): client = MetadataServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3195,43 +3646,57 @@ async def test_list_contexts_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_contexts), "__call__") as call: + with mock.patch.object(type(client.transport.create_context), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - metadata_service.ListContextsResponse( - next_page_token="next_page_token_value", + gca_context.Context( + name="name_value", + display_name="display_name_value", + etag="etag_value", + parent_contexts=["parent_contexts_value"], + schema_title="schema_title_value", + schema_version="schema_version_value", + description="description_value", ) ) - response = await client.list_contexts(request) + response = await client.create_context(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.ListContextsRequest() + assert args[0] == metadata_service.CreateContextRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListContextsAsyncPager) - assert response.next_page_token == "next_page_token_value" + assert isinstance(response, gca_context.Context) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.etag == "etag_value" + assert response.parent_contexts == ["parent_contexts_value"] + assert response.schema_title == "schema_title_value" + assert response.schema_version == "schema_version_value" + assert response.description == "description_value" @pytest.mark.asyncio -async def test_list_contexts_async_from_dict(): - await test_list_contexts_async(request_type=dict) +async def test_create_context_async_from_dict(): + await test_create_context_async(request_type=dict) -def test_list_contexts_field_headers(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_create_context_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = metadata_service.ListContextsRequest() + request = metadata_service.CreateContextRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_contexts), "__call__") as call: - call.return_value = metadata_service.ListContextsResponse() - client.list_contexts(request) + with mock.patch.object(type(client.transport.create_context), "__call__") as call: + call.return_value = gca_context.Context() + client.create_context(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -3240,27 +3705,28 @@ def test_list_contexts_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_list_contexts_field_headers_async(): +async def test_create_context_field_headers_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = metadata_service.ListContextsRequest() + request = metadata_service.CreateContextRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_contexts), "__call__") as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - metadata_service.ListContextsResponse() - ) - await client.list_contexts(request) + with mock.patch.object(type(client.transport.create_context), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gca_context.Context()) + await client.create_context(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -3269,65 +3735,97 @@ async def test_list_contexts_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] -def test_list_contexts_flattened(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_create_context_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_contexts), "__call__") as call: + with mock.patch.object(type(client.transport.create_context), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = metadata_service.ListContextsResponse() + call.return_value = gca_context.Context() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_contexts(parent="parent_value",) + client.create_context( + parent="parent_value", + context=gca_context.Context(name="name_value"), + context_id="context_id_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].context + mock_val = gca_context.Context(name="name_value") + assert arg == mock_val + arg = args[0].context_id + mock_val = "context_id_value" + assert arg == mock_val -def test_list_contexts_flattened_error(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_create_context_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_contexts( - metadata_service.ListContextsRequest(), parent="parent_value", + client.create_context( + metadata_service.CreateContextRequest(), + parent="parent_value", + context=gca_context.Context(name="name_value"), + context_id="context_id_value", ) @pytest.mark.asyncio -async def test_list_contexts_flattened_async(): +async def test_create_context_flattened_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_contexts), "__call__") as call: + with mock.patch.object(type(client.transport.create_context), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = metadata_service.ListContextsResponse() + call.return_value = gca_context.Context() - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - metadata_service.ListContextsResponse() - ) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gca_context.Context()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_contexts(parent="parent_value",) + response = await client.create_context( + parent="parent_value", + context=gca_context.Context(name="name_value"), + context_id="context_id_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].context + mock_val = gca_context.Context(name="name_value") + assert arg == mock_val + arg = args[0].context_id + mock_val = "context_id_value" + assert arg == mock_val @pytest.mark.asyncio -async def test_list_contexts_flattened_error_async(): +async def test_create_context_flattened_error_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -3335,142 +3833,25 @@ async def test_list_contexts_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.list_contexts( - metadata_service.ListContextsRequest(), parent="parent_value", - ) - - -def test_list_contexts_pager(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials,) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_contexts), "__call__") as call: - # Set the response to a series of pages. - call.side_effect = ( - metadata_service.ListContextsResponse( - contexts=[context.Context(), context.Context(), context.Context(),], - next_page_token="abc", - ), - metadata_service.ListContextsResponse(contexts=[], next_page_token="def",), - metadata_service.ListContextsResponse( - contexts=[context.Context(),], next_page_token="ghi", - ), - metadata_service.ListContextsResponse( - contexts=[context.Context(), context.Context(),], - ), - RuntimeError, - ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), - ) - pager = client.list_contexts(request={}) - - assert pager._metadata == metadata - - results = [i for i in pager] - assert len(results) == 6 - assert all(isinstance(i, context.Context) for i in results) - - -def test_list_contexts_pages(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials,) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_contexts), "__call__") as call: - # Set the response to a series of pages. - call.side_effect = ( - metadata_service.ListContextsResponse( - contexts=[context.Context(), context.Context(), context.Context(),], - next_page_token="abc", - ), - metadata_service.ListContextsResponse(contexts=[], next_page_token="def",), - metadata_service.ListContextsResponse( - contexts=[context.Context(),], next_page_token="ghi", - ), - metadata_service.ListContextsResponse( - contexts=[context.Context(), context.Context(),], - ), - RuntimeError, - ) - pages = list(client.list_contexts(request={}).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token - - -@pytest.mark.asyncio -async def test_list_contexts_async_pager(): - client = MetadataServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_contexts), "__call__", new_callable=mock.AsyncMock - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - metadata_service.ListContextsResponse( - contexts=[context.Context(), context.Context(), context.Context(),], - next_page_token="abc", - ), - metadata_service.ListContextsResponse(contexts=[], next_page_token="def",), - metadata_service.ListContextsResponse( - contexts=[context.Context(),], next_page_token="ghi", - ), - metadata_service.ListContextsResponse( - contexts=[context.Context(), context.Context(),], - ), - RuntimeError, - ) - async_pager = await client.list_contexts(request={},) - assert async_pager.next_page_token == "abc" - responses = [] - async for response in async_pager: - responses.append(response) - - assert len(responses) == 6 - assert all(isinstance(i, context.Context) for i in responses) - - -@pytest.mark.asyncio -async def test_list_contexts_async_pages(): - client = MetadataServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_contexts), "__call__", new_callable=mock.AsyncMock - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - metadata_service.ListContextsResponse( - contexts=[context.Context(), context.Context(), context.Context(),], - next_page_token="abc", - ), - metadata_service.ListContextsResponse(contexts=[], next_page_token="def",), - metadata_service.ListContextsResponse( - contexts=[context.Context(),], next_page_token="ghi", - ), - metadata_service.ListContextsResponse( - contexts=[context.Context(), context.Context(),], - ), - RuntimeError, + await client.create_context( + metadata_service.CreateContextRequest(), + parent="parent_value", + context=gca_context.Context(name="name_value"), + context_id="context_id_value", ) - pages = [] - async for page_ in (await client.list_contexts(request={})).pages: - pages.append(page_) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token -def test_update_context( - transport: str = "grpc", request_type=metadata_service.UpdateContextRequest -): +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.GetContextRequest, + dict, + ], +) +def test_get_context(request_type, transport: str = "grpc"): client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3478,9 +3859,9 @@ def test_update_context( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_context), "__call__") as call: + with mock.patch.object(type(client.transport.get_context), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = gca_context.Context( + call.return_value = context.Context( name="name_value", display_name="display_name_value", etag="etag_value", @@ -3489,15 +3870,15 @@ def test_update_context( schema_version="schema_version_value", description="description_value", ) - response = client.update_context(request) + response = client.get_context(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.UpdateContextRequest() + assert args[0] == metadata_service.GetContextRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gca_context.Context) + assert isinstance(response, context.Context) assert response.name == "name_value" assert response.display_name == "display_name_value" assert response.etag == "etag_value" @@ -3507,31 +3888,29 @@ def test_update_context( assert response.description == "description_value" -def test_update_context_from_dict(): - test_update_context(request_type=dict) - - -def test_update_context_empty_call(): +def test_get_context_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_context), "__call__") as call: - client.update_context() + with mock.patch.object(type(client.transport.get_context), "__call__") as call: + client.get_context() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.UpdateContextRequest() + assert args[0] == metadata_service.GetContextRequest() @pytest.mark.asyncio -async def test_update_context_async( - transport: str = "grpc_asyncio", request_type=metadata_service.UpdateContextRequest +async def test_get_context_async( + transport: str = "grpc_asyncio", request_type=metadata_service.GetContextRequest ): client = MetadataServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3539,10 +3918,10 @@ async def test_update_context_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_context), "__call__") as call: + with mock.patch.object(type(client.transport.get_context), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gca_context.Context( + context.Context( name="name_value", display_name="display_name_value", etag="etag_value", @@ -3552,15 +3931,15 @@ async def test_update_context_async( description="description_value", ) ) - response = await client.update_context(request) + response = await client.get_context(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.UpdateContextRequest() + assert args[0] == metadata_service.GetContextRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gca_context.Context) + assert isinstance(response, context.Context) assert response.name == "name_value" assert response.display_name == "display_name_value" assert response.etag == "etag_value" @@ -3571,23 +3950,25 @@ async def test_update_context_async( @pytest.mark.asyncio -async def test_update_context_async_from_dict(): - await test_update_context_async(request_type=dict) +async def test_get_context_async_from_dict(): + await test_get_context_async(request_type=dict) -def test_update_context_field_headers(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_get_context_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = metadata_service.UpdateContextRequest() + request = metadata_service.GetContextRequest() - request.context.name = "context.name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_context), "__call__") as call: - call.return_value = gca_context.Context() - client.update_context(request) + with mock.patch.object(type(client.transport.get_context), "__call__") as call: + call.return_value = context.Context() + client.get_context(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -3596,27 +3977,28 @@ def test_update_context_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "context.name=context.name/value",) in kw[ - "metadata" - ] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_update_context_field_headers_async(): +async def test_get_context_field_headers_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = metadata_service.UpdateContextRequest() + request = metadata_service.GetContextRequest() - request.context.name = "context.name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_context), "__call__") as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gca_context.Context()) - await client.update_context(request) + with mock.patch.object(type(client.transport.get_context), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(context.Context()) + await client.get_context(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -3625,75 +4007,79 @@ async def test_update_context_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "context.name=context.name/value",) in kw[ - "metadata" - ] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] -def test_update_context_flattened(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_get_context_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_context), "__call__") as call: + with mock.patch.object(type(client.transport.get_context), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = gca_context.Context() + call.return_value = context.Context() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.update_context( - context=gca_context.Context(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + client.get_context( + name="name_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].context == gca_context.Context(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val -def test_update_context_flattened_error(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_get_context_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.update_context( - metadata_service.UpdateContextRequest(), - context=gca_context.Context(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + client.get_context( + metadata_service.GetContextRequest(), + name="name_value", ) @pytest.mark.asyncio -async def test_update_context_flattened_async(): +async def test_get_context_flattened_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_context), "__call__") as call: + with mock.patch.object(type(client.transport.get_context), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = gca_context.Context() + call.return_value = context.Context() - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gca_context.Context()) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(context.Context()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.update_context( - context=gca_context.Context(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + response = await client.get_context( + name="name_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].context == gca_context.Context(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio -async def test_update_context_flattened_error_async(): +async def test_get_context_flattened_error_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -3701,18 +4087,23 @@ async def test_update_context_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.update_context( - metadata_service.UpdateContextRequest(), - context=gca_context.Context(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + await client.get_context( + metadata_service.GetContextRequest(), + name="name_value", ) -def test_delete_context( - transport: str = "grpc", request_type=metadata_service.DeleteContextRequest -): +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.ListContextsRequest, + dict, + ], +) +def test_list_contexts(request_type, transport: str = "grpc"): client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3720,45 +4111,46 @@ def test_delete_context( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_context), "__call__") as call: + with mock.patch.object(type(client.transport.list_contexts), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.delete_context(request) + call.return_value = metadata_service.ListContextsResponse( + next_page_token="next_page_token_value", + ) + response = client.list_contexts(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.DeleteContextRequest() + assert args[0] == metadata_service.ListContextsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_delete_context_from_dict(): - test_delete_context(request_type=dict) + assert isinstance(response, pagers.ListContextsPager) + assert response.next_page_token == "next_page_token_value" -def test_delete_context_empty_call(): +def test_list_contexts_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_context), "__call__") as call: - client.delete_context() + with mock.patch.object(type(client.transport.list_contexts), "__call__") as call: + client.list_contexts() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.DeleteContextRequest() + assert args[0] == metadata_service.ListContextsRequest() @pytest.mark.asyncio -async def test_delete_context_async( - transport: str = "grpc_asyncio", request_type=metadata_service.DeleteContextRequest +async def test_list_contexts_async( + transport: str = "grpc_asyncio", request_type=metadata_service.ListContextsRequest ): client = MetadataServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3766,40 +4158,45 @@ async def test_delete_context_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_context), "__call__") as call: + with mock.patch.object(type(client.transport.list_contexts), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") + metadata_service.ListContextsResponse( + next_page_token="next_page_token_value", + ) ) - response = await client.delete_context(request) + response = await client.list_contexts(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.DeleteContextRequest() + assert args[0] == metadata_service.ListContextsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) + assert isinstance(response, pagers.ListContextsAsyncPager) + assert response.next_page_token == "next_page_token_value" @pytest.mark.asyncio -async def test_delete_context_async_from_dict(): - await test_delete_context_async(request_type=dict) +async def test_list_contexts_async_from_dict(): + await test_list_contexts_async(request_type=dict) -def test_delete_context_field_headers(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_list_contexts_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = metadata_service.DeleteContextRequest() + request = metadata_service.ListContextsRequest() - request.name = "name/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_context), "__call__") as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_context(request) + with mock.patch.object(type(client.transport.list_contexts), "__call__") as call: + call.return_value = metadata_service.ListContextsResponse() + client.list_contexts(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -3808,27 +4205,30 @@ def test_delete_context_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_delete_context_field_headers_async(): +async def test_list_contexts_field_headers_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = metadata_service.DeleteContextRequest() + request = metadata_service.ListContextsRequest() - request.name = "name/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_context), "__call__") as call: + with mock.patch.object(type(client.transport.list_contexts), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/op") + metadata_service.ListContextsResponse() ) - await client.delete_context(request) + await client.list_contexts(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -3837,65 +4237,81 @@ async def test_delete_context_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] -def test_delete_context_flattened(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_list_contexts_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_context), "__call__") as call: + with mock.patch.object(type(client.transport.list_contexts), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name="operations/op") + call.return_value = metadata_service.ListContextsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_context(name="name_value",) + client.list_contexts( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val -def test_delete_context_flattened_error(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_list_contexts_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.delete_context( - metadata_service.DeleteContextRequest(), name="name_value", + client.list_contexts( + metadata_service.ListContextsRequest(), + parent="parent_value", ) @pytest.mark.asyncio -async def test_delete_context_flattened_async(): +async def test_list_contexts_flattened_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_context), "__call__") as call: + with mock.patch.object(type(client.transport.list_contexts), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name="operations/op") + call.return_value = metadata_service.ListContextsResponse() call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") + metadata_service.ListContextsResponse() ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_context(name="name_value",) + response = await client.list_contexts( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio -async def test_delete_context_flattened_error_async(): +async def test_list_contexts_flattened_error_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -3903,254 +4319,211 @@ async def test_delete_context_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.delete_context( - metadata_service.DeleteContextRequest(), name="name_value", + await client.list_contexts( + metadata_service.ListContextsRequest(), + parent="parent_value", ) -def test_add_context_artifacts_and_executions( - transport: str = "grpc", - request_type=metadata_service.AddContextArtifactsAndExecutionsRequest, -): +def test_list_contexts_pager(transport_name: str = "grpc"): client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.add_context_artifacts_and_executions), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = metadata_service.AddContextArtifactsAndExecutionsResponse() - response = client.add_context_artifacts_and_executions(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.AddContextArtifactsAndExecutionsRequest() + with mock.patch.object(type(client.transport.list_contexts), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + metadata_service.ListContextsResponse( + contexts=[ + context.Context(), + context.Context(), + context.Context(), + ], + next_page_token="abc", + ), + metadata_service.ListContextsResponse( + contexts=[], + next_page_token="def", + ), + metadata_service.ListContextsResponse( + contexts=[ + context.Context(), + ], + next_page_token="ghi", + ), + metadata_service.ListContextsResponse( + contexts=[ + context.Context(), + context.Context(), + ], + ), + RuntimeError, + ) - # Establish that the response is the type that we expect. - assert isinstance( - response, metadata_service.AddContextArtifactsAndExecutionsResponse - ) + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_contexts(request={}) + assert pager._metadata == metadata -def test_add_context_artifacts_and_executions_from_dict(): - test_add_context_artifacts_and_executions(request_type=dict) + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, context.Context) for i in results) -def test_add_context_artifacts_and_executions_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. +def test_list_contexts_pages(transport_name: str = "grpc"): client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.add_context_artifacts_and_executions), "__call__" - ) as call: - client.add_context_artifacts_and_executions() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.AddContextArtifactsAndExecutionsRequest() + with mock.patch.object(type(client.transport.list_contexts), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + metadata_service.ListContextsResponse( + contexts=[ + context.Context(), + context.Context(), + context.Context(), + ], + next_page_token="abc", + ), + metadata_service.ListContextsResponse( + contexts=[], + next_page_token="def", + ), + metadata_service.ListContextsResponse( + contexts=[ + context.Context(), + ], + next_page_token="ghi", + ), + metadata_service.ListContextsResponse( + contexts=[ + context.Context(), + context.Context(), + ], + ), + RuntimeError, + ) + pages = list(client.list_contexts(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token @pytest.mark.asyncio -async def test_add_context_artifacts_and_executions_async( - transport: str = "grpc_asyncio", - request_type=metadata_service.AddContextArtifactsAndExecutionsRequest, -): +async def test_list_contexts_async_pager(): client = MetadataServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials, ) - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.add_context_artifacts_and_executions), "__call__" + type(client.transport.list_contexts), "__call__", new_callable=mock.AsyncMock ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - metadata_service.AddContextArtifactsAndExecutionsResponse() + # Set the response to a series of pages. + call.side_effect = ( + metadata_service.ListContextsResponse( + contexts=[ + context.Context(), + context.Context(), + context.Context(), + ], + next_page_token="abc", + ), + metadata_service.ListContextsResponse( + contexts=[], + next_page_token="def", + ), + metadata_service.ListContextsResponse( + contexts=[ + context.Context(), + ], + next_page_token="ghi", + ), + metadata_service.ListContextsResponse( + contexts=[ + context.Context(), + context.Context(), + ], + ), + RuntimeError, ) - response = await client.add_context_artifacts_and_executions(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.AddContextArtifactsAndExecutionsRequest() - - # Establish that the response is the type that we expect. - assert isinstance( - response, metadata_service.AddContextArtifactsAndExecutionsResponse - ) - - -@pytest.mark.asyncio -async def test_add_context_artifacts_and_executions_async_from_dict(): - await test_add_context_artifacts_and_executions_async(request_type=dict) - - -def test_add_context_artifacts_and_executions_field_headers(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = metadata_service.AddContextArtifactsAndExecutionsRequest() - - request.context = "context/value" - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.add_context_artifacts_and_executions), "__call__" - ) as call: - call.return_value = metadata_service.AddContextArtifactsAndExecutionsResponse() - client.add_context_artifacts_and_executions(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == request + async_pager = await client.list_contexts( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "context=context/value",) in kw["metadata"] + assert len(responses) == 6 + assert all(isinstance(i, context.Context) for i in responses) @pytest.mark.asyncio -async def test_add_context_artifacts_and_executions_field_headers_async(): +async def test_list_contexts_async_pages(): client = MetadataServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), + credentials=ga_credentials.AnonymousCredentials, ) - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = metadata_service.AddContextArtifactsAndExecutionsRequest() - - request.context = "context/value" - # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.add_context_artifacts_and_executions), "__call__" + type(client.transport.list_contexts), "__call__", new_callable=mock.AsyncMock ) as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - metadata_service.AddContextArtifactsAndExecutionsResponse() - ) - await client.add_context_artifacts_and_executions(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == request - - # Establish that the field header was sent. - _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "context=context/value",) in kw["metadata"] - - -def test_add_context_artifacts_and_executions_flattened(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.add_context_artifacts_and_executions), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = metadata_service.AddContextArtifactsAndExecutionsResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.add_context_artifacts_and_executions( - context="context_value", - artifacts=["artifacts_value"], - executions=["executions_value"], - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0].context == "context_value" - assert args[0].artifacts == ["artifacts_value"] - assert args[0].executions == ["executions_value"] - - -def test_add_context_artifacts_and_executions_flattened_error(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - client.add_context_artifacts_and_executions( - metadata_service.AddContextArtifactsAndExecutionsRequest(), - context="context_value", - artifacts=["artifacts_value"], - executions=["executions_value"], - ) - - -@pytest.mark.asyncio -async def test_add_context_artifacts_and_executions_flattened_async(): - client = MetadataServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.add_context_artifacts_and_executions), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = metadata_service.AddContextArtifactsAndExecutionsResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - metadata_service.AddContextArtifactsAndExecutionsResponse() - ) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.add_context_artifacts_and_executions( - context="context_value", - artifacts=["artifacts_value"], - executions=["executions_value"], - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0].context == "context_value" - assert args[0].artifacts == ["artifacts_value"] - assert args[0].executions == ["executions_value"] - - -@pytest.mark.asyncio -async def test_add_context_artifacts_and_executions_flattened_error_async(): - client = MetadataServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Attempting to call a method with both a request object and flattened - # fields is an error. - with pytest.raises(ValueError): - await client.add_context_artifacts_and_executions( - metadata_service.AddContextArtifactsAndExecutionsRequest(), - context="context_value", - artifacts=["artifacts_value"], - executions=["executions_value"], + # Set the response to a series of pages. + call.side_effect = ( + metadata_service.ListContextsResponse( + contexts=[ + context.Context(), + context.Context(), + context.Context(), + ], + next_page_token="abc", + ), + metadata_service.ListContextsResponse( + contexts=[], + next_page_token="def", + ), + metadata_service.ListContextsResponse( + contexts=[ + context.Context(), + ], + next_page_token="ghi", + ), + metadata_service.ListContextsResponse( + contexts=[ + context.Context(), + context.Context(), + ], + ), + RuntimeError, ) + pages = [] + async for page_ in ( + await client.list_contexts(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token -def test_add_context_children( - transport: str = "grpc", request_type=metadata_service.AddContextChildrenRequest -): +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.UpdateContextRequest, + dict, + ], +) +def test_update_context(request_type, transport: str = "grpc"): client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4158,50 +4531,58 @@ def test_add_context_children( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.add_context_children), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_context), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = metadata_service.AddContextChildrenResponse() - response = client.add_context_children(request) + call.return_value = gca_context.Context( + name="name_value", + display_name="display_name_value", + etag="etag_value", + parent_contexts=["parent_contexts_value"], + schema_title="schema_title_value", + schema_version="schema_version_value", + description="description_value", + ) + response = client.update_context(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.AddContextChildrenRequest() + assert args[0] == metadata_service.UpdateContextRequest() # Establish that the response is the type that we expect. - assert isinstance(response, metadata_service.AddContextChildrenResponse) - - -def test_add_context_children_from_dict(): - test_add_context_children(request_type=dict) + assert isinstance(response, gca_context.Context) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.etag == "etag_value" + assert response.parent_contexts == ["parent_contexts_value"] + assert response.schema_title == "schema_title_value" + assert response.schema_version == "schema_version_value" + assert response.description == "description_value" -def test_add_context_children_empty_call(): +def test_update_context_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.add_context_children), "__call__" - ) as call: - client.add_context_children() + with mock.patch.object(type(client.transport.update_context), "__call__") as call: + client.update_context() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.AddContextChildrenRequest() + assert args[0] == metadata_service.UpdateContextRequest() @pytest.mark.asyncio -async def test_add_context_children_async( - transport: str = "grpc_asyncio", - request_type=metadata_service.AddContextChildrenRequest, +async def test_update_context_async( + transport: str = "grpc_asyncio", request_type=metadata_service.UpdateContextRequest ): client = MetadataServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4209,44 +4590,57 @@ async def test_add_context_children_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.add_context_children), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_context), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - metadata_service.AddContextChildrenResponse() + gca_context.Context( + name="name_value", + display_name="display_name_value", + etag="etag_value", + parent_contexts=["parent_contexts_value"], + schema_title="schema_title_value", + schema_version="schema_version_value", + description="description_value", + ) ) - response = await client.add_context_children(request) + response = await client.update_context(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.AddContextChildrenRequest() + assert args[0] == metadata_service.UpdateContextRequest() # Establish that the response is the type that we expect. - assert isinstance(response, metadata_service.AddContextChildrenResponse) + assert isinstance(response, gca_context.Context) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.etag == "etag_value" + assert response.parent_contexts == ["parent_contexts_value"] + assert response.schema_title == "schema_title_value" + assert response.schema_version == "schema_version_value" + assert response.description == "description_value" @pytest.mark.asyncio -async def test_add_context_children_async_from_dict(): - await test_add_context_children_async(request_type=dict) +async def test_update_context_async_from_dict(): + await test_update_context_async(request_type=dict) -def test_add_context_children_field_headers(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_update_context_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = metadata_service.AddContextChildrenRequest() + request = metadata_service.UpdateContextRequest() - request.context = "context/value" + request.context.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.add_context_children), "__call__" - ) as call: - call.return_value = metadata_service.AddContextChildrenResponse() - client.add_context_children(request) + with mock.patch.object(type(client.transport.update_context), "__call__") as call: + call.return_value = gca_context.Context() + client.update_context(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -4255,29 +4649,28 @@ def test_add_context_children_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "context=context/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "context.name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_add_context_children_field_headers_async(): +async def test_update_context_field_headers_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = metadata_service.AddContextChildrenRequest() + request = metadata_service.UpdateContextRequest() - request.context = "context/value" + request.context.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.add_context_children), "__call__" - ) as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - metadata_service.AddContextChildrenResponse() - ) - await client.add_context_children(request) + with mock.patch.object(type(client.transport.update_context), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gca_context.Context()) + await client.update_context(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -4286,77 +4679,88 @@ async def test_add_context_children_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "context=context/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "context.name=name_value", + ) in kw["metadata"] -def test_add_context_children_flattened(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_update_context_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.add_context_children), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_context), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = metadata_service.AddContextChildrenResponse() + call.return_value = gca_context.Context() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.add_context_children( - context="context_value", child_contexts=["child_contexts_value"], + client.update_context( + context=gca_context.Context(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].context == "context_value" - assert args[0].child_contexts == ["child_contexts_value"] + arg = args[0].context + mock_val = gca_context.Context(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val -def test_add_context_children_flattened_error(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_update_context_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.add_context_children( - metadata_service.AddContextChildrenRequest(), - context="context_value", - child_contexts=["child_contexts_value"], + client.update_context( + metadata_service.UpdateContextRequest(), + context=gca_context.Context(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @pytest.mark.asyncio -async def test_add_context_children_flattened_async(): +async def test_update_context_flattened_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.add_context_children), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_context), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = metadata_service.AddContextChildrenResponse() + call.return_value = gca_context.Context() - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - metadata_service.AddContextChildrenResponse() - ) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gca_context.Context()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.add_context_children( - context="context_value", child_contexts=["child_contexts_value"], + response = await client.update_context( + context=gca_context.Context(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].context == "context_value" - assert args[0].child_contexts == ["child_contexts_value"] + arg = args[0].context + mock_val = gca_context.Context(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val @pytest.mark.asyncio -async def test_add_context_children_flattened_error_async(): +async def test_update_context_flattened_error_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -4364,19 +4768,24 @@ async def test_add_context_children_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.add_context_children( - metadata_service.AddContextChildrenRequest(), - context="context_value", - child_contexts=["child_contexts_value"], + await client.update_context( + metadata_service.UpdateContextRequest(), + context=gca_context.Context(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) -def test_query_context_lineage_subgraph( - transport: str = "grpc", - request_type=metadata_service.QueryContextLineageSubgraphRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.DeleteContextRequest, + dict, + ], +) +def test_delete_context(request_type, transport: str = "grpc"): client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4384,50 +4793,43 @@ def test_query_context_lineage_subgraph( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.query_context_lineage_subgraph), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_context), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = lineage_subgraph.LineageSubgraph() - response = client.query_context_lineage_subgraph(request) + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.delete_context(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.QueryContextLineageSubgraphRequest() + assert args[0] == metadata_service.DeleteContextRequest() # Establish that the response is the type that we expect. - assert isinstance(response, lineage_subgraph.LineageSubgraph) - - -def test_query_context_lineage_subgraph_from_dict(): - test_query_context_lineage_subgraph(request_type=dict) + assert isinstance(response, future.Future) -def test_query_context_lineage_subgraph_empty_call(): +def test_delete_context_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.query_context_lineage_subgraph), "__call__" - ) as call: - client.query_context_lineage_subgraph() + with mock.patch.object(type(client.transport.delete_context), "__call__") as call: + client.delete_context() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.QueryContextLineageSubgraphRequest() + assert args[0] == metadata_service.DeleteContextRequest() @pytest.mark.asyncio -async def test_query_context_lineage_subgraph_async( - transport: str = "grpc_asyncio", - request_type=metadata_service.QueryContextLineageSubgraphRequest, +async def test_delete_context_async( + transport: str = "grpc_asyncio", request_type=metadata_service.DeleteContextRequest ): client = MetadataServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4435,44 +4837,42 @@ async def test_query_context_lineage_subgraph_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.query_context_lineage_subgraph), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_context), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - lineage_subgraph.LineageSubgraph() + operations_pb2.Operation(name="operations/spam") ) - response = await client.query_context_lineage_subgraph(request) + response = await client.delete_context(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.QueryContextLineageSubgraphRequest() + assert args[0] == metadata_service.DeleteContextRequest() # Establish that the response is the type that we expect. - assert isinstance(response, lineage_subgraph.LineageSubgraph) + assert isinstance(response, future.Future) @pytest.mark.asyncio -async def test_query_context_lineage_subgraph_async_from_dict(): - await test_query_context_lineage_subgraph_async(request_type=dict) +async def test_delete_context_async_from_dict(): + await test_delete_context_async(request_type=dict) -def test_query_context_lineage_subgraph_field_headers(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_delete_context_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = metadata_service.QueryContextLineageSubgraphRequest() + request = metadata_service.DeleteContextRequest() - request.context = "context/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.query_context_lineage_subgraph), "__call__" - ) as call: - call.return_value = lineage_subgraph.LineageSubgraph() - client.query_context_lineage_subgraph(request) + with mock.patch.object(type(client.transport.delete_context), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_context(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -4481,29 +4881,30 @@ def test_query_context_lineage_subgraph_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "context=context/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_query_context_lineage_subgraph_field_headers_async(): +async def test_delete_context_field_headers_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = metadata_service.QueryContextLineageSubgraphRequest() + request = metadata_service.DeleteContextRequest() - request.context = "context/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.query_context_lineage_subgraph), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_context), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - lineage_subgraph.LineageSubgraph() + operations_pb2.Operation(name="operations/op") ) - await client.query_context_lineage_subgraph(request) + await client.delete_context(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -4512,70 +4913,81 @@ async def test_query_context_lineage_subgraph_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "context=context/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] -def test_query_context_lineage_subgraph_flattened(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_delete_context_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.query_context_lineage_subgraph), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_context), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = lineage_subgraph.LineageSubgraph() + call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.query_context_lineage_subgraph(context="context_value",) + client.delete_context( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].context == "context_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val -def test_query_context_lineage_subgraph_flattened_error(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_delete_context_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.query_context_lineage_subgraph( - metadata_service.QueryContextLineageSubgraphRequest(), - context="context_value", + client.delete_context( + metadata_service.DeleteContextRequest(), + name="name_value", ) @pytest.mark.asyncio -async def test_query_context_lineage_subgraph_flattened_async(): +async def test_delete_context_flattened_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.query_context_lineage_subgraph), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_context), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = lineage_subgraph.LineageSubgraph() + call.return_value = operations_pb2.Operation(name="operations/op") call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - lineage_subgraph.LineageSubgraph() + operations_pb2.Operation(name="operations/spam") ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.query_context_lineage_subgraph(context="context_value",) + response = await client.delete_context( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].context == "context_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio -async def test_query_context_lineage_subgraph_flattened_error_async(): +async def test_delete_context_flattened_error_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -4583,17 +4995,23 @@ async def test_query_context_lineage_subgraph_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.query_context_lineage_subgraph( - metadata_service.QueryContextLineageSubgraphRequest(), - context="context_value", + await client.delete_context( + metadata_service.DeleteContextRequest(), + name="name_value", ) -def test_create_execution( - transport: str = "grpc", request_type=metadata_service.CreateExecutionRequest -): +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.PurgeContextsRequest, + dict, + ], +) +def test_purge_contexts(request_type, transport: str = "grpc"): client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4601,61 +5019,43 @@ def test_create_execution( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_execution), "__call__") as call: + with mock.patch.object(type(client.transport.purge_contexts), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = gca_execution.Execution( - name="name_value", - display_name="display_name_value", - state=gca_execution.Execution.State.NEW, - etag="etag_value", - schema_title="schema_title_value", - schema_version="schema_version_value", - description="description_value", - ) - response = client.create_execution(request) + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.purge_contexts(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.CreateExecutionRequest() + assert args[0] == metadata_service.PurgeContextsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gca_execution.Execution) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.state == gca_execution.Execution.State.NEW - assert response.etag == "etag_value" - assert response.schema_title == "schema_title_value" - assert response.schema_version == "schema_version_value" - assert response.description == "description_value" - - -def test_create_execution_from_dict(): - test_create_execution(request_type=dict) + assert isinstance(response, future.Future) -def test_create_execution_empty_call(): +def test_purge_contexts_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_execution), "__call__") as call: - client.create_execution() + with mock.patch.object(type(client.transport.purge_contexts), "__call__") as call: + client.purge_contexts() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.CreateExecutionRequest() + assert args[0] == metadata_service.PurgeContextsRequest() @pytest.mark.asyncio -async def test_create_execution_async( - transport: str = "grpc_asyncio", - request_type=metadata_service.CreateExecutionRequest, +async def test_purge_contexts_async( + transport: str = "grpc_asyncio", request_type=metadata_service.PurgeContextsRequest ): client = MetadataServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4663,55 +5063,42 @@ async def test_create_execution_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_execution), "__call__") as call: + with mock.patch.object(type(client.transport.purge_contexts), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gca_execution.Execution( - name="name_value", - display_name="display_name_value", - state=gca_execution.Execution.State.NEW, - etag="etag_value", - schema_title="schema_title_value", - schema_version="schema_version_value", - description="description_value", - ) + operations_pb2.Operation(name="operations/spam") ) - response = await client.create_execution(request) + response = await client.purge_contexts(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.CreateExecutionRequest() + assert args[0] == metadata_service.PurgeContextsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gca_execution.Execution) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.state == gca_execution.Execution.State.NEW - assert response.etag == "etag_value" - assert response.schema_title == "schema_title_value" - assert response.schema_version == "schema_version_value" - assert response.description == "description_value" + assert isinstance(response, future.Future) @pytest.mark.asyncio -async def test_create_execution_async_from_dict(): - await test_create_execution_async(request_type=dict) +async def test_purge_contexts_async_from_dict(): + await test_purge_contexts_async(request_type=dict) -def test_create_execution_field_headers(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_purge_contexts_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = metadata_service.CreateExecutionRequest() + request = metadata_service.PurgeContextsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_execution), "__call__") as call: - call.return_value = gca_execution.Execution() - client.create_execution(request) + with mock.patch.object(type(client.transport.purge_contexts), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.purge_contexts(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -4720,27 +5107,30 @@ def test_create_execution_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_create_execution_field_headers_async(): +async def test_purge_contexts_field_headers_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = metadata_service.CreateExecutionRequest() + request = metadata_service.PurgeContextsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_execution), "__call__") as call: + with mock.patch.object(type(client.transport.purge_contexts), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gca_execution.Execution() + operations_pb2.Operation(name="operations/op") ) - await client.create_execution(request) + await client.purge_contexts(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -4749,80 +5139,81 @@ async def test_create_execution_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] -def test_create_execution_flattened(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_purge_contexts_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_execution), "__call__") as call: + with mock.patch.object(type(client.transport.purge_contexts), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = gca_execution.Execution() + call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.create_execution( + client.purge_contexts( parent="parent_value", - execution=gca_execution.Execution(name="name_value"), - execution_id="execution_id_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].execution == gca_execution.Execution(name="name_value") - assert args[0].execution_id == "execution_id_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val -def test_create_execution_flattened_error(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_purge_contexts_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.create_execution( - metadata_service.CreateExecutionRequest(), + client.purge_contexts( + metadata_service.PurgeContextsRequest(), parent="parent_value", - execution=gca_execution.Execution(name="name_value"), - execution_id="execution_id_value", ) @pytest.mark.asyncio -async def test_create_execution_flattened_async(): +async def test_purge_contexts_flattened_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.create_execution), "__call__") as call: + with mock.patch.object(type(client.transport.purge_contexts), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = gca_execution.Execution() + call.return_value = operations_pb2.Operation(name="operations/op") call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gca_execution.Execution() + operations_pb2.Operation(name="operations/spam") ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.create_execution( + response = await client.purge_contexts( parent="parent_value", - execution=gca_execution.Execution(name="name_value"), - execution_id="execution_id_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].execution == gca_execution.Execution(name="name_value") - assert args[0].execution_id == "execution_id_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio -async def test_create_execution_flattened_error_async(): +async def test_purge_contexts_flattened_error_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -4830,19 +5221,23 @@ async def test_create_execution_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.create_execution( - metadata_service.CreateExecutionRequest(), + await client.purge_contexts( + metadata_service.PurgeContextsRequest(), parent="parent_value", - execution=gca_execution.Execution(name="name_value"), - execution_id="execution_id_value", ) -def test_get_execution( - transport: str = "grpc", request_type=metadata_service.GetExecutionRequest -): +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.AddContextArtifactsAndExecutionsRequest, + dict, + ], +) +def test_add_context_artifacts_and_executions(request_type, transport: str = "grpc"): client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4850,60 +5245,50 @@ def test_get_execution( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_execution), "__call__") as call: + with mock.patch.object( + type(client.transport.add_context_artifacts_and_executions), "__call__" + ) as call: # Designate an appropriate return value for the call. - call.return_value = execution.Execution( - name="name_value", - display_name="display_name_value", - state=execution.Execution.State.NEW, - etag="etag_value", - schema_title="schema_title_value", - schema_version="schema_version_value", - description="description_value", - ) - response = client.get_execution(request) + call.return_value = metadata_service.AddContextArtifactsAndExecutionsResponse() + response = client.add_context_artifacts_and_executions(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.GetExecutionRequest() + assert args[0] == metadata_service.AddContextArtifactsAndExecutionsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, execution.Execution) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.state == execution.Execution.State.NEW - assert response.etag == "etag_value" - assert response.schema_title == "schema_title_value" - assert response.schema_version == "schema_version_value" - assert response.description == "description_value" - - -def test_get_execution_from_dict(): - test_get_execution(request_type=dict) + assert isinstance( + response, metadata_service.AddContextArtifactsAndExecutionsResponse + ) -def test_get_execution_empty_call(): +def test_add_context_artifacts_and_executions_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_execution), "__call__") as call: - client.get_execution() + with mock.patch.object( + type(client.transport.add_context_artifacts_and_executions), "__call__" + ) as call: + client.add_context_artifacts_and_executions() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.GetExecutionRequest() + assert args[0] == metadata_service.AddContextArtifactsAndExecutionsRequest() @pytest.mark.asyncio -async def test_get_execution_async( - transport: str = "grpc_asyncio", request_type=metadata_service.GetExecutionRequest +async def test_add_context_artifacts_and_executions_async( + transport: str = "grpc_asyncio", + request_type=metadata_service.AddContextArtifactsAndExecutionsRequest, ): client = MetadataServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4911,55 +5296,48 @@ async def test_get_execution_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_execution), "__call__") as call: + with mock.patch.object( + type(client.transport.add_context_artifacts_and_executions), "__call__" + ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - execution.Execution( - name="name_value", - display_name="display_name_value", - state=execution.Execution.State.NEW, - etag="etag_value", - schema_title="schema_title_value", - schema_version="schema_version_value", - description="description_value", - ) + metadata_service.AddContextArtifactsAndExecutionsResponse() ) - response = await client.get_execution(request) + response = await client.add_context_artifacts_and_executions(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.GetExecutionRequest() + assert args[0] == metadata_service.AddContextArtifactsAndExecutionsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, execution.Execution) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.state == execution.Execution.State.NEW - assert response.etag == "etag_value" - assert response.schema_title == "schema_title_value" - assert response.schema_version == "schema_version_value" - assert response.description == "description_value" + assert isinstance( + response, metadata_service.AddContextArtifactsAndExecutionsResponse + ) @pytest.mark.asyncio -async def test_get_execution_async_from_dict(): - await test_get_execution_async(request_type=dict) +async def test_add_context_artifacts_and_executions_async_from_dict(): + await test_add_context_artifacts_and_executions_async(request_type=dict) -def test_get_execution_field_headers(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_add_context_artifacts_and_executions_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = metadata_service.GetExecutionRequest() + request = metadata_service.AddContextArtifactsAndExecutionsRequest() - request.name = "name/value" + request.context = "context_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_execution), "__call__") as call: - call.return_value = execution.Execution() - client.get_execution(request) + with mock.patch.object( + type(client.transport.add_context_artifacts_and_executions), "__call__" + ) as call: + call.return_value = metadata_service.AddContextArtifactsAndExecutionsResponse() + client.add_context_artifacts_and_executions(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -4968,25 +5346,32 @@ def test_get_execution_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "context=context_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_get_execution_field_headers_async(): +async def test_add_context_artifacts_and_executions_field_headers_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = metadata_service.GetExecutionRequest() + request = metadata_service.AddContextArtifactsAndExecutionsRequest() - request.name = "name/value" + request.context = "context_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_execution), "__call__") as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(execution.Execution()) - await client.get_execution(request) + with mock.patch.object( + type(client.transport.add_context_artifacts_and_executions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_service.AddContextArtifactsAndExecutionsResponse() + ) + await client.add_context_artifacts_and_executions(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -4995,63 +5380,103 @@ async def test_get_execution_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "context=context_value", + ) in kw["metadata"] -def test_get_execution_flattened(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_add_context_artifacts_and_executions_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_execution), "__call__") as call: + with mock.patch.object( + type(client.transport.add_context_artifacts_and_executions), "__call__" + ) as call: # Designate an appropriate return value for the call. - call.return_value = execution.Execution() + call.return_value = metadata_service.AddContextArtifactsAndExecutionsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_execution(name="name_value",) + client.add_context_artifacts_and_executions( + context="context_value", + artifacts=["artifacts_value"], + executions=["executions_value"], + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].context + mock_val = "context_value" + assert arg == mock_val + arg = args[0].artifacts + mock_val = ["artifacts_value"] + assert arg == mock_val + arg = args[0].executions + mock_val = ["executions_value"] + assert arg == mock_val -def test_get_execution_flattened_error(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_add_context_artifacts_and_executions_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_execution( - metadata_service.GetExecutionRequest(), name="name_value", + client.add_context_artifacts_and_executions( + metadata_service.AddContextArtifactsAndExecutionsRequest(), + context="context_value", + artifacts=["artifacts_value"], + executions=["executions_value"], ) @pytest.mark.asyncio -async def test_get_execution_flattened_async(): +async def test_add_context_artifacts_and_executions_flattened_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.get_execution), "__call__") as call: + with mock.patch.object( + type(client.transport.add_context_artifacts_and_executions), "__call__" + ) as call: # Designate an appropriate return value for the call. - call.return_value = execution.Execution() + call.return_value = metadata_service.AddContextArtifactsAndExecutionsResponse() - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(execution.Execution()) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_service.AddContextArtifactsAndExecutionsResponse() + ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_execution(name="name_value",) + response = await client.add_context_artifacts_and_executions( + context="context_value", + artifacts=["artifacts_value"], + executions=["executions_value"], + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].context + mock_val = "context_value" + assert arg == mock_val + arg = args[0].artifacts + mock_val = ["artifacts_value"] + assert arg == mock_val + arg = args[0].executions + mock_val = ["executions_value"] + assert arg == mock_val @pytest.mark.asyncio -async def test_get_execution_flattened_error_async(): +async def test_add_context_artifacts_and_executions_flattened_error_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -5059,16 +5484,25 @@ async def test_get_execution_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.get_execution( - metadata_service.GetExecutionRequest(), name="name_value", + await client.add_context_artifacts_and_executions( + metadata_service.AddContextArtifactsAndExecutionsRequest(), + context="context_value", + artifacts=["artifacts_value"], + executions=["executions_value"], ) -def test_list_executions( - transport: str = "grpc", request_type=metadata_service.ListExecutionsRequest -): +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.AddContextChildrenRequest, + dict, + ], +) +def test_add_context_children(request_type, transport: str = "grpc"): client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5076,48 +5510,48 @@ def test_list_executions( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_executions), "__call__") as call: + with mock.patch.object( + type(client.transport.add_context_children), "__call__" + ) as call: # Designate an appropriate return value for the call. - call.return_value = metadata_service.ListExecutionsResponse( - next_page_token="next_page_token_value", - ) - response = client.list_executions(request) + call.return_value = metadata_service.AddContextChildrenResponse() + response = client.add_context_children(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.ListExecutionsRequest() + assert args[0] == metadata_service.AddContextChildrenRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListExecutionsPager) - assert response.next_page_token == "next_page_token_value" - - -def test_list_executions_from_dict(): - test_list_executions(request_type=dict) + assert isinstance(response, metadata_service.AddContextChildrenResponse) -def test_list_executions_empty_call(): +def test_add_context_children_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_executions), "__call__") as call: - client.list_executions() + with mock.patch.object( + type(client.transport.add_context_children), "__call__" + ) as call: + client.add_context_children() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.ListExecutionsRequest() + assert args[0] == metadata_service.AddContextChildrenRequest() @pytest.mark.asyncio -async def test_list_executions_async( - transport: str = "grpc_asyncio", request_type=metadata_service.ListExecutionsRequest +async def test_add_context_children_async( + transport: str = "grpc_asyncio", + request_type=metadata_service.AddContextChildrenRequest, ): client = MetadataServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5125,43 +5559,46 @@ async def test_list_executions_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_executions), "__call__") as call: + with mock.patch.object( + type(client.transport.add_context_children), "__call__" + ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - metadata_service.ListExecutionsResponse( - next_page_token="next_page_token_value", - ) + metadata_service.AddContextChildrenResponse() ) - response = await client.list_executions(request) + response = await client.add_context_children(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.ListExecutionsRequest() + assert args[0] == metadata_service.AddContextChildrenRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListExecutionsAsyncPager) - assert response.next_page_token == "next_page_token_value" + assert isinstance(response, metadata_service.AddContextChildrenResponse) @pytest.mark.asyncio -async def test_list_executions_async_from_dict(): - await test_list_executions_async(request_type=dict) +async def test_add_context_children_async_from_dict(): + await test_add_context_children_async(request_type=dict) -def test_list_executions_field_headers(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_add_context_children_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = metadata_service.ListExecutionsRequest() + request = metadata_service.AddContextChildrenRequest() - request.parent = "parent/value" + request.context = "context_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_executions), "__call__") as call: - call.return_value = metadata_service.ListExecutionsResponse() - client.list_executions(request) + with mock.patch.object( + type(client.transport.add_context_children), "__call__" + ) as call: + call.return_value = metadata_service.AddContextChildrenResponse() + client.add_context_children(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -5170,27 +5607,32 @@ def test_list_executions_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "context=context_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_list_executions_field_headers_async(): +async def test_add_context_children_field_headers_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = metadata_service.ListExecutionsRequest() + request = metadata_service.AddContextChildrenRequest() - request.parent = "parent/value" + request.context = "context_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_executions), "__call__") as call: + with mock.patch.object( + type(client.transport.add_context_children), "__call__" + ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - metadata_service.ListExecutionsResponse() + metadata_service.AddContextChildrenResponse() ) - await client.list_executions(request) + await client.add_context_children(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -5199,65 +5641,94 @@ async def test_list_executions_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "context=context_value", + ) in kw["metadata"] -def test_list_executions_flattened(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_add_context_children_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_executions), "__call__") as call: + with mock.patch.object( + type(client.transport.add_context_children), "__call__" + ) as call: # Designate an appropriate return value for the call. - call.return_value = metadata_service.ListExecutionsResponse() + call.return_value = metadata_service.AddContextChildrenResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_executions(parent="parent_value",) + client.add_context_children( + context="context_value", + child_contexts=["child_contexts_value"], + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].context + mock_val = "context_value" + assert arg == mock_val + arg = args[0].child_contexts + mock_val = ["child_contexts_value"] + assert arg == mock_val -def test_list_executions_flattened_error(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_add_context_children_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_executions( - metadata_service.ListExecutionsRequest(), parent="parent_value", + client.add_context_children( + metadata_service.AddContextChildrenRequest(), + context="context_value", + child_contexts=["child_contexts_value"], ) @pytest.mark.asyncio -async def test_list_executions_flattened_async(): +async def test_add_context_children_flattened_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_executions), "__call__") as call: + with mock.patch.object( + type(client.transport.add_context_children), "__call__" + ) as call: # Designate an appropriate return value for the call. - call.return_value = metadata_service.ListExecutionsResponse() + call.return_value = metadata_service.AddContextChildrenResponse() call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - metadata_service.ListExecutionsResponse() + metadata_service.AddContextChildrenResponse() ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_executions(parent="parent_value",) + response = await client.add_context_children( + context="context_value", + child_contexts=["child_contexts_value"], + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].context + mock_val = "context_value" + assert arg == mock_val + arg = args[0].child_contexts + mock_val = ["child_contexts_value"] + assert arg == mock_val @pytest.mark.asyncio -async def test_list_executions_flattened_error_async(): +async def test_add_context_children_flattened_error_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -5265,166 +5736,24 @@ async def test_list_executions_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.list_executions( - metadata_service.ListExecutionsRequest(), parent="parent_value", - ) - - -def test_list_executions_pager(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials,) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_executions), "__call__") as call: - # Set the response to a series of pages. - call.side_effect = ( - metadata_service.ListExecutionsResponse( - executions=[ - execution.Execution(), - execution.Execution(), - execution.Execution(), - ], - next_page_token="abc", - ), - metadata_service.ListExecutionsResponse( - executions=[], next_page_token="def", - ), - metadata_service.ListExecutionsResponse( - executions=[execution.Execution(),], next_page_token="ghi", - ), - metadata_service.ListExecutionsResponse( - executions=[execution.Execution(), execution.Execution(),], - ), - RuntimeError, - ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), - ) - pager = client.list_executions(request={}) - - assert pager._metadata == metadata - - results = [i for i in pager] - assert len(results) == 6 - assert all(isinstance(i, execution.Execution) for i in results) - - -def test_list_executions_pages(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials,) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.list_executions), "__call__") as call: - # Set the response to a series of pages. - call.side_effect = ( - metadata_service.ListExecutionsResponse( - executions=[ - execution.Execution(), - execution.Execution(), - execution.Execution(), - ], - next_page_token="abc", - ), - metadata_service.ListExecutionsResponse( - executions=[], next_page_token="def", - ), - metadata_service.ListExecutionsResponse( - executions=[execution.Execution(),], next_page_token="ghi", - ), - metadata_service.ListExecutionsResponse( - executions=[execution.Execution(), execution.Execution(),], - ), - RuntimeError, - ) - pages = list(client.list_executions(request={}).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token - - -@pytest.mark.asyncio -async def test_list_executions_async_pager(): - client = MetadataServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_executions), "__call__", new_callable=mock.AsyncMock - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - metadata_service.ListExecutionsResponse( - executions=[ - execution.Execution(), - execution.Execution(), - execution.Execution(), - ], - next_page_token="abc", - ), - metadata_service.ListExecutionsResponse( - executions=[], next_page_token="def", - ), - metadata_service.ListExecutionsResponse( - executions=[execution.Execution(),], next_page_token="ghi", - ), - metadata_service.ListExecutionsResponse( - executions=[execution.Execution(), execution.Execution(),], - ), - RuntimeError, - ) - async_pager = await client.list_executions(request={},) - assert async_pager.next_page_token == "abc" - responses = [] - async for response in async_pager: - responses.append(response) - - assert len(responses) == 6 - assert all(isinstance(i, execution.Execution) for i in responses) - - -@pytest.mark.asyncio -async def test_list_executions_async_pages(): - client = MetadataServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_executions), "__call__", new_callable=mock.AsyncMock - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - metadata_service.ListExecutionsResponse( - executions=[ - execution.Execution(), - execution.Execution(), - execution.Execution(), - ], - next_page_token="abc", - ), - metadata_service.ListExecutionsResponse( - executions=[], next_page_token="def", - ), - metadata_service.ListExecutionsResponse( - executions=[execution.Execution(),], next_page_token="ghi", - ), - metadata_service.ListExecutionsResponse( - executions=[execution.Execution(), execution.Execution(),], - ), - RuntimeError, + await client.add_context_children( + metadata_service.AddContextChildrenRequest(), + context="context_value", + child_contexts=["child_contexts_value"], ) - pages = [] - async for page_ in (await client.list_executions(request={})).pages: - pages.append(page_) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token -def test_update_execution( - transport: str = "grpc", request_type=metadata_service.UpdateExecutionRequest -): +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.QueryContextLineageSubgraphRequest, + dict, + ], +) +def test_query_context_lineage_subgraph(request_type, transport: str = "grpc"): client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5432,61 +5761,48 @@ def test_update_execution( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_execution), "__call__") as call: + with mock.patch.object( + type(client.transport.query_context_lineage_subgraph), "__call__" + ) as call: # Designate an appropriate return value for the call. - call.return_value = gca_execution.Execution( - name="name_value", - display_name="display_name_value", - state=gca_execution.Execution.State.NEW, - etag="etag_value", - schema_title="schema_title_value", - schema_version="schema_version_value", - description="description_value", - ) - response = client.update_execution(request) + call.return_value = lineage_subgraph.LineageSubgraph() + response = client.query_context_lineage_subgraph(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.UpdateExecutionRequest() + assert args[0] == metadata_service.QueryContextLineageSubgraphRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gca_execution.Execution) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.state == gca_execution.Execution.State.NEW - assert response.etag == "etag_value" - assert response.schema_title == "schema_title_value" - assert response.schema_version == "schema_version_value" - assert response.description == "description_value" - - -def test_update_execution_from_dict(): - test_update_execution(request_type=dict) + assert isinstance(response, lineage_subgraph.LineageSubgraph) -def test_update_execution_empty_call(): +def test_query_context_lineage_subgraph_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_execution), "__call__") as call: - client.update_execution() + with mock.patch.object( + type(client.transport.query_context_lineage_subgraph), "__call__" + ) as call: + client.query_context_lineage_subgraph() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.UpdateExecutionRequest() + assert args[0] == metadata_service.QueryContextLineageSubgraphRequest() @pytest.mark.asyncio -async def test_update_execution_async( +async def test_query_context_lineage_subgraph_async( transport: str = "grpc_asyncio", - request_type=metadata_service.UpdateExecutionRequest, + request_type=metadata_service.QueryContextLineageSubgraphRequest, ): client = MetadataServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5494,55 +5810,46 @@ async def test_update_execution_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_execution), "__call__") as call: + with mock.patch.object( + type(client.transport.query_context_lineage_subgraph), "__call__" + ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gca_execution.Execution( - name="name_value", - display_name="display_name_value", - state=gca_execution.Execution.State.NEW, - etag="etag_value", - schema_title="schema_title_value", - schema_version="schema_version_value", - description="description_value", - ) + lineage_subgraph.LineageSubgraph() ) - response = await client.update_execution(request) + response = await client.query_context_lineage_subgraph(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.UpdateExecutionRequest() + assert args[0] == metadata_service.QueryContextLineageSubgraphRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gca_execution.Execution) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.state == gca_execution.Execution.State.NEW - assert response.etag == "etag_value" - assert response.schema_title == "schema_title_value" - assert response.schema_version == "schema_version_value" - assert response.description == "description_value" + assert isinstance(response, lineage_subgraph.LineageSubgraph) @pytest.mark.asyncio -async def test_update_execution_async_from_dict(): - await test_update_execution_async(request_type=dict) +async def test_query_context_lineage_subgraph_async_from_dict(): + await test_query_context_lineage_subgraph_async(request_type=dict) -def test_update_execution_field_headers(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_query_context_lineage_subgraph_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = metadata_service.UpdateExecutionRequest() + request = metadata_service.QueryContextLineageSubgraphRequest() - request.execution.name = "execution.name/value" + request.context = "context_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_execution), "__call__") as call: - call.return_value = gca_execution.Execution() - client.update_execution(request) + with mock.patch.object( + type(client.transport.query_context_lineage_subgraph), "__call__" + ) as call: + call.return_value = lineage_subgraph.LineageSubgraph() + client.query_context_lineage_subgraph(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -5551,29 +5858,32 @@ def test_update_execution_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "execution.name=execution.name/value",) in kw[ - "metadata" - ] + assert ( + "x-goog-request-params", + "context=context_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_update_execution_field_headers_async(): +async def test_query_context_lineage_subgraph_field_headers_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = metadata_service.UpdateExecutionRequest() + request = metadata_service.QueryContextLineageSubgraphRequest() - request.execution.name = "execution.name/value" + request.context = "context_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_execution), "__call__") as call: + with mock.patch.object( + type(client.transport.query_context_lineage_subgraph), "__call__" + ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gca_execution.Execution() + lineage_subgraph.LineageSubgraph() ) - await client.update_execution(request) + await client.query_context_lineage_subgraph(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -5582,77 +5892,85 @@ async def test_update_execution_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "execution.name=execution.name/value",) in kw[ - "metadata" - ] + assert ( + "x-goog-request-params", + "context=context_value", + ) in kw["metadata"] -def test_update_execution_flattened(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_query_context_lineage_subgraph_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_execution), "__call__") as call: + with mock.patch.object( + type(client.transport.query_context_lineage_subgraph), "__call__" + ) as call: # Designate an appropriate return value for the call. - call.return_value = gca_execution.Execution() + call.return_value = lineage_subgraph.LineageSubgraph() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.update_execution( - execution=gca_execution.Execution(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + client.query_context_lineage_subgraph( + context="context_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].execution == gca_execution.Execution(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].context + mock_val = "context_value" + assert arg == mock_val -def test_update_execution_flattened_error(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_query_context_lineage_subgraph_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.update_execution( - metadata_service.UpdateExecutionRequest(), - execution=gca_execution.Execution(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + client.query_context_lineage_subgraph( + metadata_service.QueryContextLineageSubgraphRequest(), + context="context_value", ) @pytest.mark.asyncio -async def test_update_execution_flattened_async(): +async def test_query_context_lineage_subgraph_flattened_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_execution), "__call__") as call: + with mock.patch.object( + type(client.transport.query_context_lineage_subgraph), "__call__" + ) as call: # Designate an appropriate return value for the call. - call.return_value = gca_execution.Execution() + call.return_value = lineage_subgraph.LineageSubgraph() call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gca_execution.Execution() + lineage_subgraph.LineageSubgraph() ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.update_execution( - execution=gca_execution.Execution(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + response = await client.query_context_lineage_subgraph( + context="context_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].execution == gca_execution.Execution(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].context + mock_val = "context_value" + assert arg == mock_val @pytest.mark.asyncio -async def test_update_execution_flattened_error_async(): +async def test_query_context_lineage_subgraph_flattened_error_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -5660,18 +5978,23 @@ async def test_update_execution_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.update_execution( - metadata_service.UpdateExecutionRequest(), - execution=gca_execution.Execution(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + await client.query_context_lineage_subgraph( + metadata_service.QueryContextLineageSubgraphRequest(), + context="context_value", ) -def test_add_execution_events( - transport: str = "grpc", request_type=metadata_service.AddExecutionEventsRequest -): +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.CreateExecutionRequest, + dict, + ], +) +def test_create_execution(request_type, transport: str = "grpc"): client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5679,50 +6002,59 @@ def test_add_execution_events( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.add_execution_events), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_execution), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = metadata_service.AddExecutionEventsResponse() - response = client.add_execution_events(request) + call.return_value = gca_execution.Execution( + name="name_value", + display_name="display_name_value", + state=gca_execution.Execution.State.NEW, + etag="etag_value", + schema_title="schema_title_value", + schema_version="schema_version_value", + description="description_value", + ) + response = client.create_execution(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.AddExecutionEventsRequest() + assert args[0] == metadata_service.CreateExecutionRequest() # Establish that the response is the type that we expect. - assert isinstance(response, metadata_service.AddExecutionEventsResponse) - - -def test_add_execution_events_from_dict(): - test_add_execution_events(request_type=dict) + assert isinstance(response, gca_execution.Execution) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.state == gca_execution.Execution.State.NEW + assert response.etag == "etag_value" + assert response.schema_title == "schema_title_value" + assert response.schema_version == "schema_version_value" + assert response.description == "description_value" -def test_add_execution_events_empty_call(): +def test_create_execution_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.add_execution_events), "__call__" - ) as call: - client.add_execution_events() + with mock.patch.object(type(client.transport.create_execution), "__call__") as call: + client.create_execution() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.AddExecutionEventsRequest() + assert args[0] == metadata_service.CreateExecutionRequest() @pytest.mark.asyncio -async def test_add_execution_events_async( +async def test_create_execution_async( transport: str = "grpc_asyncio", - request_type=metadata_service.AddExecutionEventsRequest, + request_type=metadata_service.CreateExecutionRequest, ): client = MetadataServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5730,44 +6062,57 @@ async def test_add_execution_events_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.add_execution_events), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_execution), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - metadata_service.AddExecutionEventsResponse() + gca_execution.Execution( + name="name_value", + display_name="display_name_value", + state=gca_execution.Execution.State.NEW, + etag="etag_value", + schema_title="schema_title_value", + schema_version="schema_version_value", + description="description_value", + ) ) - response = await client.add_execution_events(request) + response = await client.create_execution(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.AddExecutionEventsRequest() + assert args[0] == metadata_service.CreateExecutionRequest() # Establish that the response is the type that we expect. - assert isinstance(response, metadata_service.AddExecutionEventsResponse) + assert isinstance(response, gca_execution.Execution) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.state == gca_execution.Execution.State.NEW + assert response.etag == "etag_value" + assert response.schema_title == "schema_title_value" + assert response.schema_version == "schema_version_value" + assert response.description == "description_value" @pytest.mark.asyncio -async def test_add_execution_events_async_from_dict(): - await test_add_execution_events_async(request_type=dict) +async def test_create_execution_async_from_dict(): + await test_create_execution_async(request_type=dict) -def test_add_execution_events_field_headers(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_create_execution_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = metadata_service.AddExecutionEventsRequest() + request = metadata_service.CreateExecutionRequest() - request.execution = "execution/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.add_execution_events), "__call__" - ) as call: - call.return_value = metadata_service.AddExecutionEventsResponse() - client.add_execution_events(request) + with mock.patch.object(type(client.transport.create_execution), "__call__") as call: + call.return_value = gca_execution.Execution() + client.create_execution(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -5776,29 +6121,30 @@ def test_add_execution_events_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "execution=execution/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_add_execution_events_field_headers_async(): +async def test_create_execution_field_headers_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = metadata_service.AddExecutionEventsRequest() + request = metadata_service.CreateExecutionRequest() - request.execution = "execution/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.add_execution_events), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_execution), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - metadata_service.AddExecutionEventsResponse() + gca_execution.Execution() ) - await client.add_execution_events(request) + await client.create_execution(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -5807,79 +6153,99 @@ async def test_add_execution_events_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "execution=execution/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] -def test_add_execution_events_flattened(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_create_execution_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.add_execution_events), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_execution), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = metadata_service.AddExecutionEventsResponse() + call.return_value = gca_execution.Execution() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.add_execution_events( - execution="execution_value", - events=[event.Event(artifact="artifact_value")], + client.create_execution( + parent="parent_value", + execution=gca_execution.Execution(name="name_value"), + execution_id="execution_id_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].execution == "execution_value" - assert args[0].events == [event.Event(artifact="artifact_value")] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].execution + mock_val = gca_execution.Execution(name="name_value") + assert arg == mock_val + arg = args[0].execution_id + mock_val = "execution_id_value" + assert arg == mock_val -def test_add_execution_events_flattened_error(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_create_execution_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.add_execution_events( - metadata_service.AddExecutionEventsRequest(), - execution="execution_value", - events=[event.Event(artifact="artifact_value")], + client.create_execution( + metadata_service.CreateExecutionRequest(), + parent="parent_value", + execution=gca_execution.Execution(name="name_value"), + execution_id="execution_id_value", ) @pytest.mark.asyncio -async def test_add_execution_events_flattened_async(): +async def test_create_execution_flattened_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.add_execution_events), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_execution), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = metadata_service.AddExecutionEventsResponse() + call.return_value = gca_execution.Execution() call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - metadata_service.AddExecutionEventsResponse() + gca_execution.Execution() ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.add_execution_events( - execution="execution_value", - events=[event.Event(artifact="artifact_value")], + response = await client.create_execution( + parent="parent_value", + execution=gca_execution.Execution(name="name_value"), + execution_id="execution_id_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].execution == "execution_value" - assert args[0].events == [event.Event(artifact="artifact_value")] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].execution + mock_val = gca_execution.Execution(name="name_value") + assert arg == mock_val + arg = args[0].execution_id + mock_val = "execution_id_value" + assert arg == mock_val @pytest.mark.asyncio -async def test_add_execution_events_flattened_error_async(): +async def test_create_execution_flattened_error_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -5887,19 +6253,25 @@ async def test_add_execution_events_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.add_execution_events( - metadata_service.AddExecutionEventsRequest(), - execution="execution_value", - events=[event.Event(artifact="artifact_value")], + await client.create_execution( + metadata_service.CreateExecutionRequest(), + parent="parent_value", + execution=gca_execution.Execution(name="name_value"), + execution_id="execution_id_value", ) -def test_query_execution_inputs_and_outputs( - transport: str = "grpc", - request_type=metadata_service.QueryExecutionInputsAndOutputsRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.GetExecutionRequest, + dict, + ], +) +def test_get_execution(request_type, transport: str = "grpc"): client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5907,50 +6279,58 @@ def test_query_execution_inputs_and_outputs( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.query_execution_inputs_and_outputs), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_execution), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = lineage_subgraph.LineageSubgraph() - response = client.query_execution_inputs_and_outputs(request) + call.return_value = execution.Execution( + name="name_value", + display_name="display_name_value", + state=execution.Execution.State.NEW, + etag="etag_value", + schema_title="schema_title_value", + schema_version="schema_version_value", + description="description_value", + ) + response = client.get_execution(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.QueryExecutionInputsAndOutputsRequest() + assert args[0] == metadata_service.GetExecutionRequest() # Establish that the response is the type that we expect. - assert isinstance(response, lineage_subgraph.LineageSubgraph) - - -def test_query_execution_inputs_and_outputs_from_dict(): - test_query_execution_inputs_and_outputs(request_type=dict) + assert isinstance(response, execution.Execution) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.state == execution.Execution.State.NEW + assert response.etag == "etag_value" + assert response.schema_title == "schema_title_value" + assert response.schema_version == "schema_version_value" + assert response.description == "description_value" -def test_query_execution_inputs_and_outputs_empty_call(): +def test_get_execution_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.query_execution_inputs_and_outputs), "__call__" - ) as call: - client.query_execution_inputs_and_outputs() + with mock.patch.object(type(client.transport.get_execution), "__call__") as call: + client.get_execution() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.QueryExecutionInputsAndOutputsRequest() + assert args[0] == metadata_service.GetExecutionRequest() @pytest.mark.asyncio -async def test_query_execution_inputs_and_outputs_async( - transport: str = "grpc_asyncio", - request_type=metadata_service.QueryExecutionInputsAndOutputsRequest, +async def test_get_execution_async( + transport: str = "grpc_asyncio", request_type=metadata_service.GetExecutionRequest ): client = MetadataServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5958,44 +6338,57 @@ async def test_query_execution_inputs_and_outputs_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.query_execution_inputs_and_outputs), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_execution), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - lineage_subgraph.LineageSubgraph() + execution.Execution( + name="name_value", + display_name="display_name_value", + state=execution.Execution.State.NEW, + etag="etag_value", + schema_title="schema_title_value", + schema_version="schema_version_value", + description="description_value", + ) ) - response = await client.query_execution_inputs_and_outputs(request) + response = await client.get_execution(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.QueryExecutionInputsAndOutputsRequest() + assert args[0] == metadata_service.GetExecutionRequest() # Establish that the response is the type that we expect. - assert isinstance(response, lineage_subgraph.LineageSubgraph) + assert isinstance(response, execution.Execution) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.state == execution.Execution.State.NEW + assert response.etag == "etag_value" + assert response.schema_title == "schema_title_value" + assert response.schema_version == "schema_version_value" + assert response.description == "description_value" @pytest.mark.asyncio -async def test_query_execution_inputs_and_outputs_async_from_dict(): - await test_query_execution_inputs_and_outputs_async(request_type=dict) +async def test_get_execution_async_from_dict(): + await test_get_execution_async(request_type=dict) -def test_query_execution_inputs_and_outputs_field_headers(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_get_execution_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = metadata_service.QueryExecutionInputsAndOutputsRequest() + request = metadata_service.GetExecutionRequest() - request.execution = "execution/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.query_execution_inputs_and_outputs), "__call__" - ) as call: - call.return_value = lineage_subgraph.LineageSubgraph() - client.query_execution_inputs_and_outputs(request) + with mock.patch.object(type(client.transport.get_execution), "__call__") as call: + call.return_value = execution.Execution() + client.get_execution(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -6004,29 +6397,28 @@ def test_query_execution_inputs_and_outputs_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "execution=execution/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_query_execution_inputs_and_outputs_field_headers_async(): +async def test_get_execution_field_headers_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = metadata_service.QueryExecutionInputsAndOutputsRequest() + request = metadata_service.GetExecutionRequest() - request.execution = "execution/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.query_execution_inputs_and_outputs), "__call__" - ) as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - lineage_subgraph.LineageSubgraph() - ) - await client.query_execution_inputs_and_outputs(request) + with mock.patch.object(type(client.transport.get_execution), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(execution.Execution()) + await client.get_execution(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -6035,72 +6427,79 @@ async def test_query_execution_inputs_and_outputs_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "execution=execution/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] -def test_query_execution_inputs_and_outputs_flattened(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_get_execution_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.query_execution_inputs_and_outputs), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_execution), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = lineage_subgraph.LineageSubgraph() + call.return_value = execution.Execution() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.query_execution_inputs_and_outputs(execution="execution_value",) + client.get_execution( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].execution == "execution_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val -def test_query_execution_inputs_and_outputs_flattened_error(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_get_execution_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.query_execution_inputs_and_outputs( - metadata_service.QueryExecutionInputsAndOutputsRequest(), - execution="execution_value", + client.get_execution( + metadata_service.GetExecutionRequest(), + name="name_value", ) @pytest.mark.asyncio -async def test_query_execution_inputs_and_outputs_flattened_async(): +async def test_get_execution_flattened_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.query_execution_inputs_and_outputs), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_execution), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = lineage_subgraph.LineageSubgraph() + call.return_value = execution.Execution() - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - lineage_subgraph.LineageSubgraph() - ) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(execution.Execution()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.query_execution_inputs_and_outputs( - execution="execution_value", + response = await client.get_execution( + name="name_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].execution == "execution_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio -async def test_query_execution_inputs_and_outputs_flattened_error_async(): +async def test_get_execution_flattened_error_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -6108,17 +6507,23 @@ async def test_query_execution_inputs_and_outputs_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.query_execution_inputs_and_outputs( - metadata_service.QueryExecutionInputsAndOutputsRequest(), - execution="execution_value", + await client.get_execution( + metadata_service.GetExecutionRequest(), + name="name_value", ) -def test_create_metadata_schema( - transport: str = "grpc", request_type=metadata_service.CreateMetadataSchemaRequest -): +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.ListExecutionsRequest, + dict, + ], +) +def test_list_executions(request_type, transport: str = "grpc"): client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -6126,64 +6531,46 @@ def test_create_metadata_schema( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_metadata_schema), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_executions), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = gca_metadata_schema.MetadataSchema( - name="name_value", - schema_version="schema_version_value", - schema="schema_value", - schema_type=gca_metadata_schema.MetadataSchema.MetadataSchemaType.ARTIFACT_TYPE, - description="description_value", + call.return_value = metadata_service.ListExecutionsResponse( + next_page_token="next_page_token_value", ) - response = client.create_metadata_schema(request) + response = client.list_executions(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.CreateMetadataSchemaRequest() + assert args[0] == metadata_service.ListExecutionsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gca_metadata_schema.MetadataSchema) - assert response.name == "name_value" - assert response.schema_version == "schema_version_value" - assert response.schema == "schema_value" - assert ( - response.schema_type - == gca_metadata_schema.MetadataSchema.MetadataSchemaType.ARTIFACT_TYPE - ) - assert response.description == "description_value" - - -def test_create_metadata_schema_from_dict(): - test_create_metadata_schema(request_type=dict) + assert isinstance(response, pagers.ListExecutionsPager) + assert response.next_page_token == "next_page_token_value" -def test_create_metadata_schema_empty_call(): +def test_list_executions_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_metadata_schema), "__call__" - ) as call: - client.create_metadata_schema() + with mock.patch.object(type(client.transport.list_executions), "__call__") as call: + client.list_executions() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.CreateMetadataSchemaRequest() + assert args[0] == metadata_service.ListExecutionsRequest() @pytest.mark.asyncio -async def test_create_metadata_schema_async( - transport: str = "grpc_asyncio", - request_type=metadata_service.CreateMetadataSchemaRequest, +async def test_list_executions_async( + transport: str = "grpc_asyncio", request_type=metadata_service.ListExecutionsRequest ): client = MetadataServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -6191,58 +6578,45 @@ async def test_create_metadata_schema_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_metadata_schema), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_executions), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gca_metadata_schema.MetadataSchema( - name="name_value", - schema_version="schema_version_value", - schema="schema_value", - schema_type=gca_metadata_schema.MetadataSchema.MetadataSchemaType.ARTIFACT_TYPE, - description="description_value", + metadata_service.ListExecutionsResponse( + next_page_token="next_page_token_value", ) ) - response = await client.create_metadata_schema(request) + response = await client.list_executions(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.CreateMetadataSchemaRequest() + assert args[0] == metadata_service.ListExecutionsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gca_metadata_schema.MetadataSchema) - assert response.name == "name_value" - assert response.schema_version == "schema_version_value" - assert response.schema == "schema_value" - assert ( - response.schema_type - == gca_metadata_schema.MetadataSchema.MetadataSchemaType.ARTIFACT_TYPE - ) - assert response.description == "description_value" + assert isinstance(response, pagers.ListExecutionsAsyncPager) + assert response.next_page_token == "next_page_token_value" @pytest.mark.asyncio -async def test_create_metadata_schema_async_from_dict(): - await test_create_metadata_schema_async(request_type=dict) +async def test_list_executions_async_from_dict(): + await test_list_executions_async(request_type=dict) -def test_create_metadata_schema_field_headers(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_list_executions_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = metadata_service.CreateMetadataSchemaRequest() + request = metadata_service.ListExecutionsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_metadata_schema), "__call__" - ) as call: - call.return_value = gca_metadata_schema.MetadataSchema() - client.create_metadata_schema(request) + with mock.patch.object(type(client.transport.list_executions), "__call__") as call: + call.return_value = metadata_service.ListExecutionsResponse() + client.list_executions(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -6251,29 +6625,30 @@ def test_create_metadata_schema_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_create_metadata_schema_field_headers_async(): +async def test_list_executions_field_headers_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = metadata_service.CreateMetadataSchemaRequest() + request = metadata_service.ListExecutionsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_metadata_schema), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_executions), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gca_metadata_schema.MetadataSchema() + metadata_service.ListExecutionsResponse() ) - await client.create_metadata_schema(request) + await client.list_executions(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -6282,88 +6657,81 @@ async def test_create_metadata_schema_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] -def test_create_metadata_schema_flattened(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_list_executions_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_metadata_schema), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_executions), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = gca_metadata_schema.MetadataSchema() + call.return_value = metadata_service.ListExecutionsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.create_metadata_schema( + client.list_executions( parent="parent_value", - metadata_schema=gca_metadata_schema.MetadataSchema(name="name_value"), - metadata_schema_id="metadata_schema_id_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].metadata_schema == gca_metadata_schema.MetadataSchema( - name="name_value" - ) - assert args[0].metadata_schema_id == "metadata_schema_id_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val -def test_create_metadata_schema_flattened_error(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_list_executions_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.create_metadata_schema( - metadata_service.CreateMetadataSchemaRequest(), + client.list_executions( + metadata_service.ListExecutionsRequest(), parent="parent_value", - metadata_schema=gca_metadata_schema.MetadataSchema(name="name_value"), - metadata_schema_id="metadata_schema_id_value", ) @pytest.mark.asyncio -async def test_create_metadata_schema_flattened_async(): +async def test_list_executions_flattened_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.create_metadata_schema), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_executions), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = gca_metadata_schema.MetadataSchema() + call.return_value = metadata_service.ListExecutionsResponse() call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gca_metadata_schema.MetadataSchema() + metadata_service.ListExecutionsResponse() ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.create_metadata_schema( + response = await client.list_executions( parent="parent_value", - metadata_schema=gca_metadata_schema.MetadataSchema(name="name_value"), - metadata_schema_id="metadata_schema_id_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].metadata_schema == gca_metadata_schema.MetadataSchema( - name="name_value" - ) - assert args[0].metadata_schema_id == "metadata_schema_id_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio -async def test_create_metadata_schema_flattened_error_async(): +async def test_list_executions_flattened_error_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -6371,143 +6739,329 @@ async def test_create_metadata_schema_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.create_metadata_schema( - metadata_service.CreateMetadataSchemaRequest(), + await client.list_executions( + metadata_service.ListExecutionsRequest(), parent="parent_value", - metadata_schema=gca_metadata_schema.MetadataSchema(name="name_value"), - metadata_schema_id="metadata_schema_id_value", ) -def test_get_metadata_schema( - transport: str = "grpc", request_type=metadata_service.GetMetadataSchemaRequest -): +def test_list_executions_pager(transport_name: str = "grpc"): client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_metadata_schema), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = metadata_schema.MetadataSchema( - name="name_value", - schema_version="schema_version_value", - schema="schema_value", - schema_type=metadata_schema.MetadataSchema.MetadataSchemaType.ARTIFACT_TYPE, - description="description_value", + with mock.patch.object(type(client.transport.list_executions), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + metadata_service.ListExecutionsResponse( + executions=[ + execution.Execution(), + execution.Execution(), + execution.Execution(), + ], + next_page_token="abc", + ), + metadata_service.ListExecutionsResponse( + executions=[], + next_page_token="def", + ), + metadata_service.ListExecutionsResponse( + executions=[ + execution.Execution(), + ], + next_page_token="ghi", + ), + metadata_service.ListExecutionsResponse( + executions=[ + execution.Execution(), + execution.Execution(), + ], + ), + RuntimeError, ) - response = client.get_metadata_schema(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.GetMetadataSchemaRequest() - # Establish that the response is the type that we expect. - assert isinstance(response, metadata_schema.MetadataSchema) - assert response.name == "name_value" - assert response.schema_version == "schema_version_value" - assert response.schema == "schema_value" - assert ( - response.schema_type - == metadata_schema.MetadataSchema.MetadataSchemaType.ARTIFACT_TYPE - ) - assert response.description == "description_value" + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_executions(request={}) + assert pager._metadata == metadata -def test_get_metadata_schema_from_dict(): - test_get_metadata_schema(request_type=dict) + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, execution.Execution) for i in results) -def test_get_metadata_schema_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. +def test_list_executions_pages(transport_name: str = "grpc"): client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_metadata_schema), "__call__" - ) as call: - client.get_metadata_schema() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.GetMetadataSchemaRequest() + with mock.patch.object(type(client.transport.list_executions), "__call__") as call: + # Set the response to a series of pages. + call.side_effect = ( + metadata_service.ListExecutionsResponse( + executions=[ + execution.Execution(), + execution.Execution(), + execution.Execution(), + ], + next_page_token="abc", + ), + metadata_service.ListExecutionsResponse( + executions=[], + next_page_token="def", + ), + metadata_service.ListExecutionsResponse( + executions=[ + execution.Execution(), + ], + next_page_token="ghi", + ), + metadata_service.ListExecutionsResponse( + executions=[ + execution.Execution(), + execution.Execution(), + ], + ), + RuntimeError, + ) + pages = list(client.list_executions(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token @pytest.mark.asyncio -async def test_get_metadata_schema_async( - transport: str = "grpc_asyncio", - request_type=metadata_service.GetMetadataSchemaRequest, -): +async def test_list_executions_async_pager(): client = MetadataServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials, ) - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_metadata_schema), "__call__" + type(client.transport.list_executions), "__call__", new_callable=mock.AsyncMock ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - metadata_schema.MetadataSchema( - name="name_value", - schema_version="schema_version_value", - schema="schema_value", - schema_type=metadata_schema.MetadataSchema.MetadataSchemaType.ARTIFACT_TYPE, - description="description_value", - ) + # Set the response to a series of pages. + call.side_effect = ( + metadata_service.ListExecutionsResponse( + executions=[ + execution.Execution(), + execution.Execution(), + execution.Execution(), + ], + next_page_token="abc", + ), + metadata_service.ListExecutionsResponse( + executions=[], + next_page_token="def", + ), + metadata_service.ListExecutionsResponse( + executions=[ + execution.Execution(), + ], + next_page_token="ghi", + ), + metadata_service.ListExecutionsResponse( + executions=[ + execution.Execution(), + execution.Execution(), + ], + ), + RuntimeError, ) - response = await client.get_metadata_schema(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.GetMetadataSchemaRequest() + async_pager = await client.list_executions( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) - # Establish that the response is the type that we expect. - assert isinstance(response, metadata_schema.MetadataSchema) - assert response.name == "name_value" - assert response.schema_version == "schema_version_value" - assert response.schema == "schema_value" - assert ( - response.schema_type - == metadata_schema.MetadataSchema.MetadataSchemaType.ARTIFACT_TYPE - ) - assert response.description == "description_value" + assert len(responses) == 6 + assert all(isinstance(i, execution.Execution) for i in responses) @pytest.mark.asyncio -async def test_get_metadata_schema_async_from_dict(): - await test_get_metadata_schema_async(request_type=dict) - - -def test_get_metadata_schema_field_headers(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) - - # Any value that is part of the HTTP/1.1 URI should be sent as - # a field header. Set these to a non-empty value. - request = metadata_service.GetMetadataSchemaRequest() - - request.name = "name/value" +async def test_list_executions_async_pages(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_metadata_schema), "__call__" + type(client.transport.list_executions), "__call__", new_callable=mock.AsyncMock ) as call: - call.return_value = metadata_schema.MetadataSchema() - client.get_metadata_schema(request) + # Set the response to a series of pages. + call.side_effect = ( + metadata_service.ListExecutionsResponse( + executions=[ + execution.Execution(), + execution.Execution(), + execution.Execution(), + ], + next_page_token="abc", + ), + metadata_service.ListExecutionsResponse( + executions=[], + next_page_token="def", + ), + metadata_service.ListExecutionsResponse( + executions=[ + execution.Execution(), + ], + next_page_token="ghi", + ), + metadata_service.ListExecutionsResponse( + executions=[ + execution.Execution(), + execution.Execution(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.list_executions(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.UpdateExecutionRequest, + dict, + ], +) +def test_update_execution(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_execution), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = gca_execution.Execution( + name="name_value", + display_name="display_name_value", + state=gca_execution.Execution.State.NEW, + etag="etag_value", + schema_title="schema_title_value", + schema_version="schema_version_value", + description="description_value", + ) + response = client.update_execution(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.UpdateExecutionRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_execution.Execution) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.state == gca_execution.Execution.State.NEW + assert response.etag == "etag_value" + assert response.schema_title == "schema_title_value" + assert response.schema_version == "schema_version_value" + assert response.description == "description_value" + + +def test_update_execution_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_execution), "__call__") as call: + client.update_execution() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.UpdateExecutionRequest() + + +@pytest.mark.asyncio +async def test_update_execution_async( + transport: str = "grpc_asyncio", + request_type=metadata_service.UpdateExecutionRequest, +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_execution), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_execution.Execution( + name="name_value", + display_name="display_name_value", + state=gca_execution.Execution.State.NEW, + etag="etag_value", + schema_title="schema_title_value", + schema_version="schema_version_value", + description="description_value", + ) + ) + response = await client.update_execution(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.UpdateExecutionRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_execution.Execution) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.state == gca_execution.Execution.State.NEW + assert response.etag == "etag_value" + assert response.schema_title == "schema_title_value" + assert response.schema_version == "schema_version_value" + assert response.description == "description_value" + + +@pytest.mark.asyncio +async def test_update_execution_async_from_dict(): + await test_update_execution_async(request_type=dict) + + +def test_update_execution_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.UpdateExecutionRequest() + + request.execution.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_execution), "__call__") as call: + call.return_value = gca_execution.Execution() + client.update_execution(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -6516,29 +7070,30 @@ def test_get_metadata_schema_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "execution.name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_get_metadata_schema_field_headers_async(): +async def test_update_execution_field_headers_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = metadata_service.GetMetadataSchemaRequest() + request = metadata_service.UpdateExecutionRequest() - request.name = "name/value" + request.execution.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_metadata_schema), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_execution), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - metadata_schema.MetadataSchema() + gca_execution.Execution() ) - await client.get_metadata_schema(request) + await client.update_execution(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -6547,69 +7102,90 @@ async def test_get_metadata_schema_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "execution.name=name_value", + ) in kw["metadata"] -def test_get_metadata_schema_flattened(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_update_execution_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_metadata_schema), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_execution), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = metadata_schema.MetadataSchema() + call.return_value = gca_execution.Execution() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_metadata_schema(name="name_value",) + client.update_execution( + execution=gca_execution.Execution(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].execution + mock_val = gca_execution.Execution(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val -def test_get_metadata_schema_flattened_error(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_update_execution_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_metadata_schema( - metadata_service.GetMetadataSchemaRequest(), name="name_value", + client.update_execution( + metadata_service.UpdateExecutionRequest(), + execution=gca_execution.Execution(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @pytest.mark.asyncio -async def test_get_metadata_schema_flattened_async(): +async def test_update_execution_flattened_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_metadata_schema), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_execution), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = metadata_schema.MetadataSchema() + call.return_value = gca_execution.Execution() call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - metadata_schema.MetadataSchema() + gca_execution.Execution() ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_metadata_schema(name="name_value",) + response = await client.update_execution( + execution=gca_execution.Execution(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].execution + mock_val = gca_execution.Execution(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val @pytest.mark.asyncio -async def test_get_metadata_schema_flattened_error_async(): +async def test_update_execution_flattened_error_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -6617,16 +7193,24 @@ async def test_get_metadata_schema_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.get_metadata_schema( - metadata_service.GetMetadataSchemaRequest(), name="name_value", + await client.update_execution( + metadata_service.UpdateExecutionRequest(), + execution=gca_execution.Execution(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) -def test_list_metadata_schemas( - transport: str = "grpc", request_type=metadata_service.ListMetadataSchemasRequest -): +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.DeleteExecutionRequest, + dict, + ], +) +def test_delete_execution(request_type, transport: str = "grpc"): client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -6634,53 +7218,44 @@ def test_list_metadata_schemas( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_metadata_schemas), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_execution), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = metadata_service.ListMetadataSchemasResponse( - next_page_token="next_page_token_value", - ) - response = client.list_metadata_schemas(request) + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.delete_execution(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.ListMetadataSchemasRequest() + assert args[0] == metadata_service.DeleteExecutionRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListMetadataSchemasPager) - assert response.next_page_token == "next_page_token_value" - - -def test_list_metadata_schemas_from_dict(): - test_list_metadata_schemas(request_type=dict) + assert isinstance(response, future.Future) -def test_list_metadata_schemas_empty_call(): +def test_delete_execution_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_metadata_schemas), "__call__" - ) as call: - client.list_metadata_schemas() + with mock.patch.object(type(client.transport.delete_execution), "__call__") as call: + client.delete_execution() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.ListMetadataSchemasRequest() + assert args[0] == metadata_service.DeleteExecutionRequest() @pytest.mark.asyncio -async def test_list_metadata_schemas_async( +async def test_delete_execution_async( transport: str = "grpc_asyncio", - request_type=metadata_service.ListMetadataSchemasRequest, + request_type=metadata_service.DeleteExecutionRequest, ): client = MetadataServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -6688,47 +7263,42 @@ async def test_list_metadata_schemas_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_metadata_schemas), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_execution), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - metadata_service.ListMetadataSchemasResponse( - next_page_token="next_page_token_value", - ) + operations_pb2.Operation(name="operations/spam") ) - response = await client.list_metadata_schemas(request) + response = await client.delete_execution(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.ListMetadataSchemasRequest() + assert args[0] == metadata_service.DeleteExecutionRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListMetadataSchemasAsyncPager) - assert response.next_page_token == "next_page_token_value" + assert isinstance(response, future.Future) @pytest.mark.asyncio -async def test_list_metadata_schemas_async_from_dict(): - await test_list_metadata_schemas_async(request_type=dict) +async def test_delete_execution_async_from_dict(): + await test_delete_execution_async(request_type=dict) -def test_list_metadata_schemas_field_headers(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_delete_execution_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = metadata_service.ListMetadataSchemasRequest() + request = metadata_service.DeleteExecutionRequest() - request.parent = "parent/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_metadata_schemas), "__call__" - ) as call: - call.return_value = metadata_service.ListMetadataSchemasResponse() - client.list_metadata_schemas(request) + with mock.patch.object(type(client.transport.delete_execution), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_execution(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -6737,29 +7307,30 @@ def test_list_metadata_schemas_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_list_metadata_schemas_field_headers_async(): +async def test_delete_execution_field_headers_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = metadata_service.ListMetadataSchemasRequest() + request = metadata_service.DeleteExecutionRequest() - request.parent = "parent/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_metadata_schemas), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_execution), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - metadata_service.ListMetadataSchemasResponse() + operations_pb2.Operation(name="operations/op") ) - await client.list_metadata_schemas(request) + await client.delete_execution(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -6768,69 +7339,81 @@ async def test_list_metadata_schemas_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] -def test_list_metadata_schemas_flattened(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_delete_execution_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_metadata_schemas), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_execution), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = metadata_service.ListMetadataSchemasResponse() + call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_metadata_schemas(parent="parent_value",) + client.delete_execution( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val -def test_list_metadata_schemas_flattened_error(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_delete_execution_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_metadata_schemas( - metadata_service.ListMetadataSchemasRequest(), parent="parent_value", + client.delete_execution( + metadata_service.DeleteExecutionRequest(), + name="name_value", ) @pytest.mark.asyncio -async def test_list_metadata_schemas_flattened_async(): +async def test_delete_execution_flattened_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_metadata_schemas), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_execution), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = metadata_service.ListMetadataSchemasResponse() + call.return_value = operations_pb2.Operation(name="operations/op") call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - metadata_service.ListMetadataSchemasResponse() + operations_pb2.Operation(name="operations/spam") ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_metadata_schemas(parent="parent_value",) + response = await client.delete_execution( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio -async def test_list_metadata_schemas_flattened_error_async(): +async def test_delete_execution_flattened_error_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -6838,191 +7421,23 @@ async def test_list_metadata_schemas_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.list_metadata_schemas( - metadata_service.ListMetadataSchemasRequest(), parent="parent_value", - ) - - -def test_list_metadata_schemas_pager(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials,) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_metadata_schemas), "__call__" - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - metadata_service.ListMetadataSchemasResponse( - metadata_schemas=[ - metadata_schema.MetadataSchema(), - metadata_schema.MetadataSchema(), - metadata_schema.MetadataSchema(), - ], - next_page_token="abc", - ), - metadata_service.ListMetadataSchemasResponse( - metadata_schemas=[], next_page_token="def", - ), - metadata_service.ListMetadataSchemasResponse( - metadata_schemas=[metadata_schema.MetadataSchema(),], - next_page_token="ghi", - ), - metadata_service.ListMetadataSchemasResponse( - metadata_schemas=[ - metadata_schema.MetadataSchema(), - metadata_schema.MetadataSchema(), - ], - ), - RuntimeError, - ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), - ) - pager = client.list_metadata_schemas(request={}) - - assert pager._metadata == metadata - - results = [i for i in pager] - assert len(results) == 6 - assert all(isinstance(i, metadata_schema.MetadataSchema) for i in results) - - -def test_list_metadata_schemas_pages(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials,) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_metadata_schemas), "__call__" - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - metadata_service.ListMetadataSchemasResponse( - metadata_schemas=[ - metadata_schema.MetadataSchema(), - metadata_schema.MetadataSchema(), - metadata_schema.MetadataSchema(), - ], - next_page_token="abc", - ), - metadata_service.ListMetadataSchemasResponse( - metadata_schemas=[], next_page_token="def", - ), - metadata_service.ListMetadataSchemasResponse( - metadata_schemas=[metadata_schema.MetadataSchema(),], - next_page_token="ghi", - ), - metadata_service.ListMetadataSchemasResponse( - metadata_schemas=[ - metadata_schema.MetadataSchema(), - metadata_schema.MetadataSchema(), - ], - ), - RuntimeError, - ) - pages = list(client.list_metadata_schemas(request={}).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token - - -@pytest.mark.asyncio -async def test_list_metadata_schemas_async_pager(): - client = MetadataServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_metadata_schemas), - "__call__", - new_callable=mock.AsyncMock, - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - metadata_service.ListMetadataSchemasResponse( - metadata_schemas=[ - metadata_schema.MetadataSchema(), - metadata_schema.MetadataSchema(), - metadata_schema.MetadataSchema(), - ], - next_page_token="abc", - ), - metadata_service.ListMetadataSchemasResponse( - metadata_schemas=[], next_page_token="def", - ), - metadata_service.ListMetadataSchemasResponse( - metadata_schemas=[metadata_schema.MetadataSchema(),], - next_page_token="ghi", - ), - metadata_service.ListMetadataSchemasResponse( - metadata_schemas=[ - metadata_schema.MetadataSchema(), - metadata_schema.MetadataSchema(), - ], - ), - RuntimeError, - ) - async_pager = await client.list_metadata_schemas(request={},) - assert async_pager.next_page_token == "abc" - responses = [] - async for response in async_pager: - responses.append(response) - - assert len(responses) == 6 - assert all(isinstance(i, metadata_schema.MetadataSchema) for i in responses) - - -@pytest.mark.asyncio -async def test_list_metadata_schemas_async_pages(): - client = MetadataServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_metadata_schemas), - "__call__", - new_callable=mock.AsyncMock, - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - metadata_service.ListMetadataSchemasResponse( - metadata_schemas=[ - metadata_schema.MetadataSchema(), - metadata_schema.MetadataSchema(), - metadata_schema.MetadataSchema(), - ], - next_page_token="abc", - ), - metadata_service.ListMetadataSchemasResponse( - metadata_schemas=[], next_page_token="def", - ), - metadata_service.ListMetadataSchemasResponse( - metadata_schemas=[metadata_schema.MetadataSchema(),], - next_page_token="ghi", - ), - metadata_service.ListMetadataSchemasResponse( - metadata_schemas=[ - metadata_schema.MetadataSchema(), - metadata_schema.MetadataSchema(), - ], - ), - RuntimeError, + await client.delete_execution( + metadata_service.DeleteExecutionRequest(), + name="name_value", ) - pages = [] - async for page_ in (await client.list_metadata_schemas(request={})).pages: - pages.append(page_) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token -def test_query_artifact_lineage_subgraph( - transport: str = "grpc", - request_type=metadata_service.QueryArtifactLineageSubgraphRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.PurgeExecutionsRequest, + dict, + ], +) +def test_purge_executions(request_type, transport: str = "grpc"): client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -7030,50 +7445,44 @@ def test_query_artifact_lineage_subgraph( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.query_artifact_lineage_subgraph), "__call__" - ) as call: + with mock.patch.object(type(client.transport.purge_executions), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = lineage_subgraph.LineageSubgraph() - response = client.query_artifact_lineage_subgraph(request) + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.purge_executions(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.QueryArtifactLineageSubgraphRequest() + assert args[0] == metadata_service.PurgeExecutionsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, lineage_subgraph.LineageSubgraph) - - -def test_query_artifact_lineage_subgraph_from_dict(): - test_query_artifact_lineage_subgraph(request_type=dict) + assert isinstance(response, future.Future) -def test_query_artifact_lineage_subgraph_empty_call(): +def test_purge_executions_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.query_artifact_lineage_subgraph), "__call__" - ) as call: - client.query_artifact_lineage_subgraph() + with mock.patch.object(type(client.transport.purge_executions), "__call__") as call: + client.purge_executions() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.QueryArtifactLineageSubgraphRequest() + assert args[0] == metadata_service.PurgeExecutionsRequest() @pytest.mark.asyncio -async def test_query_artifact_lineage_subgraph_async( +async def test_purge_executions_async( transport: str = "grpc_asyncio", - request_type=metadata_service.QueryArtifactLineageSubgraphRequest, + request_type=metadata_service.PurgeExecutionsRequest, ): client = MetadataServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -7081,44 +7490,42 @@ async def test_query_artifact_lineage_subgraph_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.query_artifact_lineage_subgraph), "__call__" - ) as call: + with mock.patch.object(type(client.transport.purge_executions), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - lineage_subgraph.LineageSubgraph() + operations_pb2.Operation(name="operations/spam") ) - response = await client.query_artifact_lineage_subgraph(request) + response = await client.purge_executions(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == metadata_service.QueryArtifactLineageSubgraphRequest() + assert args[0] == metadata_service.PurgeExecutionsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, lineage_subgraph.LineageSubgraph) + assert isinstance(response, future.Future) @pytest.mark.asyncio -async def test_query_artifact_lineage_subgraph_async_from_dict(): - await test_query_artifact_lineage_subgraph_async(request_type=dict) +async def test_purge_executions_async_from_dict(): + await test_purge_executions_async(request_type=dict) -def test_query_artifact_lineage_subgraph_field_headers(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_purge_executions_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = metadata_service.QueryArtifactLineageSubgraphRequest() + request = metadata_service.PurgeExecutionsRequest() - request.artifact = "artifact/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.query_artifact_lineage_subgraph), "__call__" - ) as call: - call.return_value = lineage_subgraph.LineageSubgraph() - client.query_artifact_lineage_subgraph(request) + with mock.patch.object(type(client.transport.purge_executions), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.purge_executions(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -7127,29 +7534,30 @@ def test_query_artifact_lineage_subgraph_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "artifact=artifact/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_query_artifact_lineage_subgraph_field_headers_async(): +async def test_purge_executions_field_headers_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = metadata_service.QueryArtifactLineageSubgraphRequest() + request = metadata_service.PurgeExecutionsRequest() - request.artifact = "artifact/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.query_artifact_lineage_subgraph), "__call__" - ) as call: + with mock.patch.object(type(client.transport.purge_executions), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - lineage_subgraph.LineageSubgraph() + operations_pb2.Operation(name="operations/op") ) - await client.query_artifact_lineage_subgraph(request) + await client.purge_executions(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -7158,72 +7566,81 @@ async def test_query_artifact_lineage_subgraph_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "artifact=artifact/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] -def test_query_artifact_lineage_subgraph_flattened(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_purge_executions_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.query_artifact_lineage_subgraph), "__call__" - ) as call: + with mock.patch.object(type(client.transport.purge_executions), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = lineage_subgraph.LineageSubgraph() + call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.query_artifact_lineage_subgraph(artifact="artifact_value",) + client.purge_executions( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].artifact == "artifact_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val -def test_query_artifact_lineage_subgraph_flattened_error(): - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_purge_executions_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.query_artifact_lineage_subgraph( - metadata_service.QueryArtifactLineageSubgraphRequest(), - artifact="artifact_value", + client.purge_executions( + metadata_service.PurgeExecutionsRequest(), + parent="parent_value", ) @pytest.mark.asyncio -async def test_query_artifact_lineage_subgraph_flattened_async(): +async def test_purge_executions_flattened_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.query_artifact_lineage_subgraph), "__call__" - ) as call: + with mock.patch.object(type(client.transport.purge_executions), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = lineage_subgraph.LineageSubgraph() + call.return_value = operations_pb2.Operation(name="operations/op") call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - lineage_subgraph.LineageSubgraph() + operations_pb2.Operation(name="operations/spam") ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.query_artifact_lineage_subgraph( - artifact="artifact_value", + response = await client.purge_executions( + parent="parent_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].artifact == "artifact_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio -async def test_query_artifact_lineage_subgraph_flattened_error_async(): +async def test_purge_executions_flattened_error_async(): client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -7231,850 +7648,4145 @@ async def test_query_artifact_lineage_subgraph_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.query_artifact_lineage_subgraph( - metadata_service.QueryArtifactLineageSubgraphRequest(), - artifact="artifact_value", + await client.purge_executions( + metadata_service.PurgeExecutionsRequest(), + parent="parent_value", ) -def test_credentials_transport_error(): - # It is an error to provide credentials and a transport instance. - transport = transports.MetadataServiceGrpcTransport( +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.AddExecutionEventsRequest, + dict, + ], +) +def test_add_execution_events(request_type, transport: str = "grpc"): + client = MetadataServiceClient( credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - with pytest.raises(ValueError): - client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, - ) - # It is an error to provide a credentials file and a transport instance. - transport = transports.MetadataServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = MetadataServiceClient( - client_options={"credentials_file": "credentials.json"}, - transport=transport, - ) + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() - # It is an error to provide scopes and a transport instance. - transport = transports.MetadataServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = MetadataServiceClient( - client_options={"scopes": ["1", "2"]}, transport=transport, - ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_execution_events), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_service.AddExecutionEventsResponse() + response = client.add_execution_events(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.AddExecutionEventsRequest() -def test_transport_instance(): - # A client may be instantiated with a custom transport instance. - transport = transports.MetadataServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - client = MetadataServiceClient(transport=transport) - assert client.transport is transport + # Establish that the response is the type that we expect. + assert isinstance(response, metadata_service.AddExecutionEventsResponse) -def test_transport_get_channel(): - # A client may be instantiated with a custom transport instance. - transport = transports.MetadataServiceGrpcTransport( +def test_add_execution_events_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) - channel = transport.grpc_channel - assert channel - transport = transports.MetadataServiceGrpcAsyncIOTransport( + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_execution_events), "__call__" + ) as call: + client.add_execution_events() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.AddExecutionEventsRequest() + + +@pytest.mark.asyncio +async def test_add_execution_events_async( + transport: str = "grpc_asyncio", + request_type=metadata_service.AddExecutionEventsRequest, +): + client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - channel = transport.grpc_channel - assert channel + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() -@pytest.mark.parametrize( - "transport_class", - [ - transports.MetadataServiceGrpcTransport, - transports.MetadataServiceGrpcAsyncIOTransport, - ], -) -def test_transport_adc(transport_class): - # Test default credentials are used if not provided. - with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class() - adc.assert_called_once() - + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_execution_events), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_service.AddExecutionEventsResponse() + ) + response = await client.add_execution_events(request) -def test_transport_grpc_default(): - # A client should use the gRPC transport by default. - client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials(),) - assert isinstance(client.transport, transports.MetadataServiceGrpcTransport,) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.AddExecutionEventsRequest() + # Establish that the response is the type that we expect. + assert isinstance(response, metadata_service.AddExecutionEventsResponse) -def test_metadata_service_base_transport_error(): - # Passing both a credentials object and credentials_file should raise an error - with pytest.raises(core_exceptions.DuplicateCredentialArgs): - transport = transports.MetadataServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), - credentials_file="credentials.json", - ) +@pytest.mark.asyncio +async def test_add_execution_events_async_from_dict(): + await test_add_execution_events_async(request_type=dict) -def test_metadata_service_base_transport(): - # Instantiate the base transport. - with mock.patch( - "google.cloud.aiplatform_v1beta1.services.metadata_service.transports.MetadataServiceTransport.__init__" - ) as Transport: - Transport.return_value = None - transport = transports.MetadataServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - # Every method on the transport should just blindly - # raise NotImplementedError. - methods = ( - "create_metadata_store", - "get_metadata_store", - "list_metadata_stores", - "delete_metadata_store", - "create_artifact", - "get_artifact", - "list_artifacts", - "update_artifact", - "create_context", - "get_context", - "list_contexts", - "update_context", - "delete_context", - "add_context_artifacts_and_executions", - "add_context_children", - "query_context_lineage_subgraph", - "create_execution", - "get_execution", - "list_executions", - "update_execution", - "add_execution_events", - "query_execution_inputs_and_outputs", - "create_metadata_schema", - "get_metadata_schema", - "list_metadata_schemas", - "query_artifact_lineage_subgraph", +def test_add_execution_events_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), ) - for method in methods: - with pytest.raises(NotImplementedError): - getattr(transport, method)(request=object()) - # Additionally, the LRO client (a property) should - # also raise NotImplementedError - with pytest.raises(NotImplementedError): - transport.operations_client + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.AddExecutionEventsRequest() + request.execution = "execution_value" -@requires_google_auth_gte_1_25_0 -def test_metadata_service_base_transport_with_credentials_file(): - # Instantiate the base transport with a credentials file + # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.aiplatform_v1beta1.services.metadata_service.transports.MetadataServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.MetadataServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=None, - default_scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) + type(client.transport.add_execution_events), "__call__" + ) as call: + call.return_value = metadata_service.AddExecutionEventsResponse() + client.add_execution_events(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request -@requires_google_auth_lt_1_25_0 -def test_metadata_service_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.aiplatform_v1beta1.services.metadata_service.transports.MetadataServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.MetadataServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "execution=execution_value", + ) in kw["metadata"] -def test_metadata_service_base_transport_with_adc(): - # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.aiplatform_v1beta1.services.metadata_service.transports.MetadataServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.MetadataServiceTransport() - adc.assert_called_once() +@pytest.mark.asyncio +async def test_add_execution_events_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) -@requires_google_auth_gte_1_25_0 -def test_metadata_service_auth_adc(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - MetadataServiceClient() - adc.assert_called_once_with( - scopes=None, - default_scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.AddExecutionEventsRequest() + request.execution = "execution_value" -@requires_google_auth_lt_1_25_0 -def test_metadata_service_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - MetadataServiceClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_execution_events), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_service.AddExecutionEventsResponse() ) + await client.add_execution_events(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request -@pytest.mark.parametrize( - "transport_class", - [ - transports.MetadataServiceGrpcTransport, - transports.MetadataServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_gte_1_25_0 -def test_metadata_service_transport_auth_adc(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - adc.assert_called_once_with( - scopes=["1", "2"], - default_scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "execution=execution_value", + ) in kw["metadata"] -@pytest.mark.parametrize( - "transport_class", - [ - transports.MetadataServiceGrpcTransport, - transports.MetadataServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_metadata_service_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", +def test_add_execution_events_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.add_execution_events), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_service.AddExecutionEventsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.add_execution_events( + execution="execution_value", + events=[event.Event(artifact="artifact_value")], ) + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].execution + mock_val = "execution_value" + assert arg == mock_val + arg = args[0].events + mock_val = [event.Event(artifact="artifact_value")] + assert arg == mock_val -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.MetadataServiceGrpcTransport, grpc_helpers), - (transports.MetadataServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_gte_1_26_0 -def test_metadata_service_transport_create_channel(transport_class, grpc_helpers): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - default_scopes=("https://www.googleapis.com/auth/cloud-platform",), - scopes=["1", "2"], - default_host="aiplatform.googleapis.com", - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], +def test_add_execution_events_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.add_execution_events( + metadata_service.AddExecutionEventsRequest(), + execution="execution_value", + events=[event.Event(artifact="artifact_value")], ) -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.MetadataServiceGrpcTransport, grpc_helpers), - (transports.MetadataServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_metadata_service_transport_create_channel_old_api_core( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. +@pytest.mark.asyncio +async def test_add_execution_events_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class(quota_project_id="octopus") + type(client.transport.add_execution_events), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_service.AddExecutionEventsResponse() - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_service.AddExecutionEventsResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.add_execution_events( + execution="execution_value", + events=[event.Event(artifact="artifact_value")], ) + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].execution + mock_val = "execution_value" + assert arg == mock_val + arg = args[0].events + mock_val = [event.Event(artifact="artifact_value")] + assert arg == mock_val -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.MetadataServiceGrpcTransport, grpc_helpers), - (transports.MetadataServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_metadata_service_transport_create_channel_user_scopes( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class(quota_project_id="octopus", scopes=["1", "2"]) +@pytest.mark.asyncio +async def test_add_execution_events_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=["1", "2"], - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.add_execution_events( + metadata_service.AddExecutionEventsRequest(), + execution="execution_value", + events=[event.Event(artifact="artifact_value")], ) @pytest.mark.parametrize( - "transport_class", + "request_type", [ - transports.MetadataServiceGrpcTransport, - transports.MetadataServiceGrpcAsyncIOTransport, + metadata_service.QueryExecutionInputsAndOutputsRequest, + dict, ], ) -def test_metadata_service_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() +def test_query_execution_inputs_and_outputs(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) - # Check ssl_channel_credentials is used if provided. - with mock.patch.object(transport_class, "create_channel") as mock_create_channel: - mock_ssl_channel_creds = mock.Mock() - transport_class( - host="squid.clam.whelk", - credentials=cred, - ssl_channel_credentials=mock_ssl_channel_creds, + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_execution_inputs_and_outputs), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = lineage_subgraph.LineageSubgraph() + response = client.query_execution_inputs_and_outputs(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.QueryExecutionInputsAndOutputsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, lineage_subgraph.LineageSubgraph) + + +def test_query_execution_inputs_and_outputs_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_execution_inputs_and_outputs), "__call__" + ) as call: + client.query_execution_inputs_and_outputs() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.QueryExecutionInputsAndOutputsRequest() + + +@pytest.mark.asyncio +async def test_query_execution_inputs_and_outputs_async( + transport: str = "grpc_asyncio", + request_type=metadata_service.QueryExecutionInputsAndOutputsRequest, +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_execution_inputs_and_outputs), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + lineage_subgraph.LineageSubgraph() + ) + response = await client.query_execution_inputs_and_outputs(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.QueryExecutionInputsAndOutputsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, lineage_subgraph.LineageSubgraph) + + +@pytest.mark.asyncio +async def test_query_execution_inputs_and_outputs_async_from_dict(): + await test_query_execution_inputs_and_outputs_async(request_type=dict) + + +def test_query_execution_inputs_and_outputs_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.QueryExecutionInputsAndOutputsRequest() + + request.execution = "execution_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_execution_inputs_and_outputs), "__call__" + ) as call: + call.return_value = lineage_subgraph.LineageSubgraph() + client.query_execution_inputs_and_outputs(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "execution=execution_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_query_execution_inputs_and_outputs_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.QueryExecutionInputsAndOutputsRequest() + + request.execution = "execution_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_execution_inputs_and_outputs), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + lineage_subgraph.LineageSubgraph() + ) + await client.query_execution_inputs_and_outputs(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "execution=execution_value", + ) in kw["metadata"] + + +def test_query_execution_inputs_and_outputs_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_execution_inputs_and_outputs), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = lineage_subgraph.LineageSubgraph() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.query_execution_inputs_and_outputs( + execution="execution_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].execution + mock_val = "execution_value" + assert arg == mock_val + + +def test_query_execution_inputs_and_outputs_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.query_execution_inputs_and_outputs( + metadata_service.QueryExecutionInputsAndOutputsRequest(), + execution="execution_value", + ) + + +@pytest.mark.asyncio +async def test_query_execution_inputs_and_outputs_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_execution_inputs_and_outputs), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = lineage_subgraph.LineageSubgraph() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + lineage_subgraph.LineageSubgraph() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.query_execution_inputs_and_outputs( + execution="execution_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].execution + mock_val = "execution_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_query_execution_inputs_and_outputs_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.query_execution_inputs_and_outputs( + metadata_service.QueryExecutionInputsAndOutputsRequest(), + execution="execution_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.CreateMetadataSchemaRequest, + dict, + ], +) +def test_create_metadata_schema(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_metadata_schema), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gca_metadata_schema.MetadataSchema( + name="name_value", + schema_version="schema_version_value", + schema="schema_value", + schema_type=gca_metadata_schema.MetadataSchema.MetadataSchemaType.ARTIFACT_TYPE, + description="description_value", + ) + response = client.create_metadata_schema(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.CreateMetadataSchemaRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_metadata_schema.MetadataSchema) + assert response.name == "name_value" + assert response.schema_version == "schema_version_value" + assert response.schema == "schema_value" + assert ( + response.schema_type + == gca_metadata_schema.MetadataSchema.MetadataSchemaType.ARTIFACT_TYPE + ) + assert response.description == "description_value" + + +def test_create_metadata_schema_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_metadata_schema), "__call__" + ) as call: + client.create_metadata_schema() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.CreateMetadataSchemaRequest() + + +@pytest.mark.asyncio +async def test_create_metadata_schema_async( + transport: str = "grpc_asyncio", + request_type=metadata_service.CreateMetadataSchemaRequest, +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_metadata_schema), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_metadata_schema.MetadataSchema( + name="name_value", + schema_version="schema_version_value", + schema="schema_value", + schema_type=gca_metadata_schema.MetadataSchema.MetadataSchemaType.ARTIFACT_TYPE, + description="description_value", + ) + ) + response = await client.create_metadata_schema(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.CreateMetadataSchemaRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_metadata_schema.MetadataSchema) + assert response.name == "name_value" + assert response.schema_version == "schema_version_value" + assert response.schema == "schema_value" + assert ( + response.schema_type + == gca_metadata_schema.MetadataSchema.MetadataSchemaType.ARTIFACT_TYPE + ) + assert response.description == "description_value" + + +@pytest.mark.asyncio +async def test_create_metadata_schema_async_from_dict(): + await test_create_metadata_schema_async(request_type=dict) + + +def test_create_metadata_schema_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.CreateMetadataSchemaRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_metadata_schema), "__call__" + ) as call: + call.return_value = gca_metadata_schema.MetadataSchema() + client.create_metadata_schema(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_create_metadata_schema_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.CreateMetadataSchemaRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_metadata_schema), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_metadata_schema.MetadataSchema() + ) + await client.create_metadata_schema(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_create_metadata_schema_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_metadata_schema), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gca_metadata_schema.MetadataSchema() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.create_metadata_schema( + parent="parent_value", + metadata_schema=gca_metadata_schema.MetadataSchema(name="name_value"), + metadata_schema_id="metadata_schema_id_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].metadata_schema + mock_val = gca_metadata_schema.MetadataSchema(name="name_value") + assert arg == mock_val + arg = args[0].metadata_schema_id + mock_val = "metadata_schema_id_value" + assert arg == mock_val + + +def test_create_metadata_schema_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.create_metadata_schema( + metadata_service.CreateMetadataSchemaRequest(), + parent="parent_value", + metadata_schema=gca_metadata_schema.MetadataSchema(name="name_value"), + metadata_schema_id="metadata_schema_id_value", + ) + + +@pytest.mark.asyncio +async def test_create_metadata_schema_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.create_metadata_schema), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gca_metadata_schema.MetadataSchema() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_metadata_schema.MetadataSchema() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.create_metadata_schema( + parent="parent_value", + metadata_schema=gca_metadata_schema.MetadataSchema(name="name_value"), + metadata_schema_id="metadata_schema_id_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].metadata_schema + mock_val = gca_metadata_schema.MetadataSchema(name="name_value") + assert arg == mock_val + arg = args[0].metadata_schema_id + mock_val = "metadata_schema_id_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_create_metadata_schema_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.create_metadata_schema( + metadata_service.CreateMetadataSchemaRequest(), + parent="parent_value", + metadata_schema=gca_metadata_schema.MetadataSchema(name="name_value"), + metadata_schema_id="metadata_schema_id_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.GetMetadataSchemaRequest, + dict, + ], +) +def test_get_metadata_schema(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_metadata_schema), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_schema.MetadataSchema( + name="name_value", + schema_version="schema_version_value", + schema="schema_value", + schema_type=metadata_schema.MetadataSchema.MetadataSchemaType.ARTIFACT_TYPE, + description="description_value", + ) + response = client.get_metadata_schema(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.GetMetadataSchemaRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, metadata_schema.MetadataSchema) + assert response.name == "name_value" + assert response.schema_version == "schema_version_value" + assert response.schema == "schema_value" + assert ( + response.schema_type + == metadata_schema.MetadataSchema.MetadataSchemaType.ARTIFACT_TYPE + ) + assert response.description == "description_value" + + +def test_get_metadata_schema_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_metadata_schema), "__call__" + ) as call: + client.get_metadata_schema() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.GetMetadataSchemaRequest() + + +@pytest.mark.asyncio +async def test_get_metadata_schema_async( + transport: str = "grpc_asyncio", + request_type=metadata_service.GetMetadataSchemaRequest, +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_metadata_schema), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_schema.MetadataSchema( + name="name_value", + schema_version="schema_version_value", + schema="schema_value", + schema_type=metadata_schema.MetadataSchema.MetadataSchemaType.ARTIFACT_TYPE, + description="description_value", + ) + ) + response = await client.get_metadata_schema(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.GetMetadataSchemaRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, metadata_schema.MetadataSchema) + assert response.name == "name_value" + assert response.schema_version == "schema_version_value" + assert response.schema == "schema_value" + assert ( + response.schema_type + == metadata_schema.MetadataSchema.MetadataSchemaType.ARTIFACT_TYPE + ) + assert response.description == "description_value" + + +@pytest.mark.asyncio +async def test_get_metadata_schema_async_from_dict(): + await test_get_metadata_schema_async(request_type=dict) + + +def test_get_metadata_schema_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.GetMetadataSchemaRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_metadata_schema), "__call__" + ) as call: + call.return_value = metadata_schema.MetadataSchema() + client.get_metadata_schema(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_metadata_schema_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.GetMetadataSchemaRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_metadata_schema), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_schema.MetadataSchema() + ) + await client.get_metadata_schema(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_get_metadata_schema_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_metadata_schema), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_schema.MetadataSchema() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_metadata_schema( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_get_metadata_schema_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_metadata_schema( + metadata_service.GetMetadataSchemaRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_metadata_schema_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_metadata_schema), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_schema.MetadataSchema() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_schema.MetadataSchema() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_metadata_schema( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_get_metadata_schema_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_metadata_schema( + metadata_service.GetMetadataSchemaRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.ListMetadataSchemasRequest, + dict, + ], +) +def test_list_metadata_schemas(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_metadata_schemas), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_service.ListMetadataSchemasResponse( + next_page_token="next_page_token_value", + ) + response = client.list_metadata_schemas(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.ListMetadataSchemasRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListMetadataSchemasPager) + assert response.next_page_token == "next_page_token_value" + + +def test_list_metadata_schemas_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_metadata_schemas), "__call__" + ) as call: + client.list_metadata_schemas() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.ListMetadataSchemasRequest() + + +@pytest.mark.asyncio +async def test_list_metadata_schemas_async( + transport: str = "grpc_asyncio", + request_type=metadata_service.ListMetadataSchemasRequest, +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_metadata_schemas), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_service.ListMetadataSchemasResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.list_metadata_schemas(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.ListMetadataSchemasRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListMetadataSchemasAsyncPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_list_metadata_schemas_async_from_dict(): + await test_list_metadata_schemas_async(request_type=dict) + + +def test_list_metadata_schemas_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.ListMetadataSchemasRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_metadata_schemas), "__call__" + ) as call: + call.return_value = metadata_service.ListMetadataSchemasResponse() + client.list_metadata_schemas(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_metadata_schemas_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.ListMetadataSchemasRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_metadata_schemas), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_service.ListMetadataSchemasResponse() + ) + await client.list_metadata_schemas(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_list_metadata_schemas_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_metadata_schemas), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_service.ListMetadataSchemasResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_metadata_schemas( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +def test_list_metadata_schemas_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_metadata_schemas( + metadata_service.ListMetadataSchemasRequest(), + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_metadata_schemas_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_metadata_schemas), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = metadata_service.ListMetadataSchemasResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + metadata_service.ListMetadataSchemasResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_metadata_schemas( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_list_metadata_schemas_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_metadata_schemas( + metadata_service.ListMetadataSchemasRequest(), + parent="parent_value", + ) + + +def test_list_metadata_schemas_pager(transport_name: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_metadata_schemas), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + metadata_service.ListMetadataSchemasResponse( + metadata_schemas=[ + metadata_schema.MetadataSchema(), + metadata_schema.MetadataSchema(), + metadata_schema.MetadataSchema(), + ], + next_page_token="abc", + ), + metadata_service.ListMetadataSchemasResponse( + metadata_schemas=[], + next_page_token="def", + ), + metadata_service.ListMetadataSchemasResponse( + metadata_schemas=[ + metadata_schema.MetadataSchema(), + ], + next_page_token="ghi", + ), + metadata_service.ListMetadataSchemasResponse( + metadata_schemas=[ + metadata_schema.MetadataSchema(), + metadata_schema.MetadataSchema(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_metadata_schemas(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, metadata_schema.MetadataSchema) for i in results) + + +def test_list_metadata_schemas_pages(transport_name: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_metadata_schemas), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + metadata_service.ListMetadataSchemasResponse( + metadata_schemas=[ + metadata_schema.MetadataSchema(), + metadata_schema.MetadataSchema(), + metadata_schema.MetadataSchema(), + ], + next_page_token="abc", + ), + metadata_service.ListMetadataSchemasResponse( + metadata_schemas=[], + next_page_token="def", + ), + metadata_service.ListMetadataSchemasResponse( + metadata_schemas=[ + metadata_schema.MetadataSchema(), + ], + next_page_token="ghi", + ), + metadata_service.ListMetadataSchemasResponse( + metadata_schemas=[ + metadata_schema.MetadataSchema(), + metadata_schema.MetadataSchema(), + ], + ), + RuntimeError, + ) + pages = list(client.list_metadata_schemas(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.asyncio +async def test_list_metadata_schemas_async_pager(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_metadata_schemas), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + metadata_service.ListMetadataSchemasResponse( + metadata_schemas=[ + metadata_schema.MetadataSchema(), + metadata_schema.MetadataSchema(), + metadata_schema.MetadataSchema(), + ], + next_page_token="abc", + ), + metadata_service.ListMetadataSchemasResponse( + metadata_schemas=[], + next_page_token="def", + ), + metadata_service.ListMetadataSchemasResponse( + metadata_schemas=[ + metadata_schema.MetadataSchema(), + ], + next_page_token="ghi", + ), + metadata_service.ListMetadataSchemasResponse( + metadata_schemas=[ + metadata_schema.MetadataSchema(), + metadata_schema.MetadataSchema(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_metadata_schemas( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, metadata_schema.MetadataSchema) for i in responses) + + +@pytest.mark.asyncio +async def test_list_metadata_schemas_async_pages(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_metadata_schemas), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + metadata_service.ListMetadataSchemasResponse( + metadata_schemas=[ + metadata_schema.MetadataSchema(), + metadata_schema.MetadataSchema(), + metadata_schema.MetadataSchema(), + ], + next_page_token="abc", + ), + metadata_service.ListMetadataSchemasResponse( + metadata_schemas=[], + next_page_token="def", + ), + metadata_service.ListMetadataSchemasResponse( + metadata_schemas=[ + metadata_schema.MetadataSchema(), + ], + next_page_token="ghi", + ), + metadata_service.ListMetadataSchemasResponse( + metadata_schemas=[ + metadata_schema.MetadataSchema(), + metadata_schema.MetadataSchema(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.list_metadata_schemas(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize( + "request_type", + [ + metadata_service.QueryArtifactLineageSubgraphRequest, + dict, + ], +) +def test_query_artifact_lineage_subgraph(request_type, transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_artifact_lineage_subgraph), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = lineage_subgraph.LineageSubgraph() + response = client.query_artifact_lineage_subgraph(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.QueryArtifactLineageSubgraphRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, lineage_subgraph.LineageSubgraph) + + +def test_query_artifact_lineage_subgraph_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_artifact_lineage_subgraph), "__call__" + ) as call: + client.query_artifact_lineage_subgraph() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.QueryArtifactLineageSubgraphRequest() + + +@pytest.mark.asyncio +async def test_query_artifact_lineage_subgraph_async( + transport: str = "grpc_asyncio", + request_type=metadata_service.QueryArtifactLineageSubgraphRequest, +): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_artifact_lineage_subgraph), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + lineage_subgraph.LineageSubgraph() + ) + response = await client.query_artifact_lineage_subgraph(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == metadata_service.QueryArtifactLineageSubgraphRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, lineage_subgraph.LineageSubgraph) + + +@pytest.mark.asyncio +async def test_query_artifact_lineage_subgraph_async_from_dict(): + await test_query_artifact_lineage_subgraph_async(request_type=dict) + + +def test_query_artifact_lineage_subgraph_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.QueryArtifactLineageSubgraphRequest() + + request.artifact = "artifact_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_artifact_lineage_subgraph), "__call__" + ) as call: + call.return_value = lineage_subgraph.LineageSubgraph() + client.query_artifact_lineage_subgraph(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "artifact=artifact_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_query_artifact_lineage_subgraph_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = metadata_service.QueryArtifactLineageSubgraphRequest() + + request.artifact = "artifact_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_artifact_lineage_subgraph), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + lineage_subgraph.LineageSubgraph() + ) + await client.query_artifact_lineage_subgraph(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "artifact=artifact_value", + ) in kw["metadata"] + + +def test_query_artifact_lineage_subgraph_flattened(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_artifact_lineage_subgraph), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = lineage_subgraph.LineageSubgraph() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.query_artifact_lineage_subgraph( + artifact="artifact_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].artifact + mock_val = "artifact_value" + assert arg == mock_val + + +def test_query_artifact_lineage_subgraph_flattened_error(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.query_artifact_lineage_subgraph( + metadata_service.QueryArtifactLineageSubgraphRequest(), + artifact="artifact_value", + ) + + +@pytest.mark.asyncio +async def test_query_artifact_lineage_subgraph_flattened_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.query_artifact_lineage_subgraph), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = lineage_subgraph.LineageSubgraph() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + lineage_subgraph.LineageSubgraph() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.query_artifact_lineage_subgraph( + artifact="artifact_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].artifact + mock_val = "artifact_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_query_artifact_lineage_subgraph_flattened_error_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.query_artifact_lineage_subgraph( + metadata_service.QueryArtifactLineageSubgraphRequest(), + artifact="artifact_value", + ) + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.MetadataServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.MetadataServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = MetadataServiceClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide an api_key and a transport instance. + transport = transports.MetadataServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = MetadataServiceClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = MetadataServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.MetadataServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = MetadataServiceClient( + client_options={"scopes": ["1", "2"]}, + transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.MetadataServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + client = MetadataServiceClient(transport=transport) + assert client.transport is transport + + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.MetadataServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.MetadataServiceGrpcAsyncIOTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.MetadataServiceGrpcTransport, + transports.MetadataServiceGrpcAsyncIOTransport, + ], +) +def test_transport_adc(transport_class): + # Test default credentials are used if not provided. + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class() + adc.assert_called_once() + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = MetadataServiceClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + +def test_transport_grpc_default(): + # A client should use the gRPC transport by default. + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.MetadataServiceGrpcTransport, + ) + + +def test_metadata_service_base_transport_error(): + # Passing both a credentials object and credentials_file should raise an error + with pytest.raises(core_exceptions.DuplicateCredentialArgs): + transport = transports.MetadataServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + credentials_file="credentials.json", + ) + + +def test_metadata_service_base_transport(): + # Instantiate the base transport. + with mock.patch( + "google.cloud.aiplatform_v1beta1.services.metadata_service.transports.MetadataServiceTransport.__init__" + ) as Transport: + Transport.return_value = None + transport = transports.MetadataServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Every method on the transport should just blindly + # raise NotImplementedError. + methods = ( + "create_metadata_store", + "get_metadata_store", + "list_metadata_stores", + "delete_metadata_store", + "create_artifact", + "get_artifact", + "list_artifacts", + "update_artifact", + "delete_artifact", + "purge_artifacts", + "create_context", + "get_context", + "list_contexts", + "update_context", + "delete_context", + "purge_contexts", + "add_context_artifacts_and_executions", + "add_context_children", + "query_context_lineage_subgraph", + "create_execution", + "get_execution", + "list_executions", + "update_execution", + "delete_execution", + "purge_executions", + "add_execution_events", + "query_execution_inputs_and_outputs", + "create_metadata_schema", + "get_metadata_schema", + "list_metadata_schemas", + "query_artifact_lineage_subgraph", + "set_iam_policy", + "get_iam_policy", + "test_iam_permissions", + "get_location", + "list_locations", + "get_operation", + "wait_operation", + "cancel_operation", + "delete_operation", + "list_operations", + ) + for method in methods: + with pytest.raises(NotImplementedError): + getattr(transport, method)(request=object()) + + with pytest.raises(NotImplementedError): + transport.close() + + # Additionally, the LRO client (a property) should + # also raise NotImplementedError + with pytest.raises(NotImplementedError): + transport.operations_client + + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + + +def test_metadata_service_base_transport_with_credentials_file(): + # Instantiate the base transport with a credentials file + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch( + "google.cloud.aiplatform_v1beta1.services.metadata_service.transports.MetadataServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.MetadataServiceTransport( + credentials_file="credentials.json", + quota_project_id="octopus", + ) + load_creds.assert_called_once_with( + "credentials.json", + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +def test_metadata_service_base_transport_with_adc(): + # Test the default credentials are used if credentials and credentials_file are None. + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( + "google.cloud.aiplatform_v1beta1.services.metadata_service.transports.MetadataServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.MetadataServiceTransport() + adc.assert_called_once() + + +def test_metadata_service_auth_adc(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + MetadataServiceClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id=None, + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.MetadataServiceGrpcTransport, + transports.MetadataServiceGrpcAsyncIOTransport, + ], +) +def test_metadata_service_transport_auth_adc(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.MetadataServiceGrpcTransport, grpc_helpers), + (transports.MetadataServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +def test_metadata_service_transport_create_channel(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=["1", "2"], + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.MetadataServiceGrpcTransport, + transports.MetadataServiceGrpcAsyncIOTransport, + ], +) +def test_metadata_service_grpc_transport_client_cert_source_for_mtls(transport_class): + cred = ga_credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds, + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback, + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, private_key=expected_key + ) + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_metadata_service_host_no_port(transport_name): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions( + api_endpoint="aiplatform.googleapis.com" + ), + transport=transport_name, + ) + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_metadata_service_host_with_port(transport_name): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions( + api_endpoint="aiplatform.googleapis.com:8000" + ), + transport=transport_name, + ) + assert client.transport._host == ("aiplatform.googleapis.com:8000") + + +def test_metadata_service_grpc_transport_channel(): + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.MetadataServiceGrpcTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +def test_metadata_service_grpc_asyncio_transport_channel(): + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.MetadataServiceGrpcAsyncIOTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize( + "transport_class", + [ + transports.MetadataServiceGrpcTransport, + transports.MetadataServiceGrpcAsyncIOTransport, + ], +) +def test_metadata_service_transport_channel_mtls_with_client_cert_source( + transport_class, +): + with mock.patch( + "grpc.ssl_channel_credentials", autospec=True + ) as grpc_ssl_channel_cred: + with mock.patch.object( + transport_class, "create_channel" + ) as grpc_create_channel: + mock_ssl_cred = mock.Mock() + grpc_ssl_channel_cred.return_value = mock_ssl_cred + + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + + cred = ga_credentials.AnonymousCredentials() + with pytest.warns(DeprecationWarning): + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (cred, None) + transport = transport_class( + host="squid.clam.whelk", + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=client_cert_source_callback, + ) + adc.assert_called_once() + + grpc_ssl_channel_cred.assert_called_once_with( + certificate_chain=b"cert bytes", private_key=b"key bytes" + ) + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize( + "transport_class", + [ + transports.MetadataServiceGrpcTransport, + transports.MetadataServiceGrpcAsyncIOTransport, + ], +) +def test_metadata_service_transport_channel_mtls_with_adc(transport_class): + mock_ssl_cred = mock.Mock() + with mock.patch.multiple( + "google.auth.transport.grpc.SslCredentials", + __init__=mock.Mock(return_value=None), + ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), + ): + with mock.patch.object( + transport_class, "create_channel" + ) as grpc_create_channel: + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + mock_cred = mock.Mock() + + with pytest.warns(DeprecationWarning): + transport = transport_class( + host="squid.clam.whelk", + credentials=mock_cred, + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=None, + ) + + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=mock_cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + + +def test_metadata_service_grpc_lro_client(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_metadata_service_grpc_lro_async_client(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_artifact_path(): + project = "squid" + location = "clam" + metadata_store = "whelk" + artifact = "octopus" + expected = "projects/{project}/locations/{location}/metadataStores/{metadata_store}/artifacts/{artifact}".format( + project=project, + location=location, + metadata_store=metadata_store, + artifact=artifact, + ) + actual = MetadataServiceClient.artifact_path( + project, location, metadata_store, artifact + ) + assert expected == actual + + +def test_parse_artifact_path(): + expected = { + "project": "oyster", + "location": "nudibranch", + "metadata_store": "cuttlefish", + "artifact": "mussel", + } + path = MetadataServiceClient.artifact_path(**expected) + + # Check that the path construction is reversible. + actual = MetadataServiceClient.parse_artifact_path(path) + assert expected == actual + + +def test_context_path(): + project = "winkle" + location = "nautilus" + metadata_store = "scallop" + context = "abalone" + expected = "projects/{project}/locations/{location}/metadataStores/{metadata_store}/contexts/{context}".format( + project=project, + location=location, + metadata_store=metadata_store, + context=context, + ) + actual = MetadataServiceClient.context_path( + project, location, metadata_store, context + ) + assert expected == actual + + +def test_parse_context_path(): + expected = { + "project": "squid", + "location": "clam", + "metadata_store": "whelk", + "context": "octopus", + } + path = MetadataServiceClient.context_path(**expected) + + # Check that the path construction is reversible. + actual = MetadataServiceClient.parse_context_path(path) + assert expected == actual + + +def test_execution_path(): + project = "oyster" + location = "nudibranch" + metadata_store = "cuttlefish" + execution = "mussel" + expected = "projects/{project}/locations/{location}/metadataStores/{metadata_store}/executions/{execution}".format( + project=project, + location=location, + metadata_store=metadata_store, + execution=execution, + ) + actual = MetadataServiceClient.execution_path( + project, location, metadata_store, execution + ) + assert expected == actual + + +def test_parse_execution_path(): + expected = { + "project": "winkle", + "location": "nautilus", + "metadata_store": "scallop", + "execution": "abalone", + } + path = MetadataServiceClient.execution_path(**expected) + + # Check that the path construction is reversible. + actual = MetadataServiceClient.parse_execution_path(path) + assert expected == actual + + +def test_metadata_schema_path(): + project = "squid" + location = "clam" + metadata_store = "whelk" + metadata_schema = "octopus" + expected = "projects/{project}/locations/{location}/metadataStores/{metadata_store}/metadataSchemas/{metadata_schema}".format( + project=project, + location=location, + metadata_store=metadata_store, + metadata_schema=metadata_schema, + ) + actual = MetadataServiceClient.metadata_schema_path( + project, location, metadata_store, metadata_schema + ) + assert expected == actual + + +def test_parse_metadata_schema_path(): + expected = { + "project": "oyster", + "location": "nudibranch", + "metadata_store": "cuttlefish", + "metadata_schema": "mussel", + } + path = MetadataServiceClient.metadata_schema_path(**expected) + + # Check that the path construction is reversible. + actual = MetadataServiceClient.parse_metadata_schema_path(path) + assert expected == actual + + +def test_metadata_store_path(): + project = "winkle" + location = "nautilus" + metadata_store = "scallop" + expected = "projects/{project}/locations/{location}/metadataStores/{metadata_store}".format( + project=project, + location=location, + metadata_store=metadata_store, + ) + actual = MetadataServiceClient.metadata_store_path( + project, location, metadata_store + ) + assert expected == actual + + +def test_parse_metadata_store_path(): + expected = { + "project": "abalone", + "location": "squid", + "metadata_store": "clam", + } + path = MetadataServiceClient.metadata_store_path(**expected) + + # Check that the path construction is reversible. + actual = MetadataServiceClient.parse_metadata_store_path(path) + assert expected == actual + + +def test_common_billing_account_path(): + billing_account = "whelk" + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + actual = MetadataServiceClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "octopus", + } + path = MetadataServiceClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = MetadataServiceClient.parse_common_billing_account_path(path) + assert expected == actual + + +def test_common_folder_path(): + folder = "oyster" + expected = "folders/{folder}".format( + folder=folder, + ) + actual = MetadataServiceClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "nudibranch", + } + path = MetadataServiceClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = MetadataServiceClient.parse_common_folder_path(path) + assert expected == actual + + +def test_common_organization_path(): + organization = "cuttlefish" + expected = "organizations/{organization}".format( + organization=organization, + ) + actual = MetadataServiceClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "mussel", + } + path = MetadataServiceClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = MetadataServiceClient.parse_common_organization_path(path) + assert expected == actual + + +def test_common_project_path(): + project = "winkle" + expected = "projects/{project}".format( + project=project, + ) + actual = MetadataServiceClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "nautilus", + } + path = MetadataServiceClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = MetadataServiceClient.parse_common_project_path(path) + assert expected == actual + + +def test_common_location_path(): + project = "scallop" + location = "abalone" + expected = "projects/{project}/locations/{location}".format( + project=project, + location=location, + ) + actual = MetadataServiceClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "squid", + "location": "clam", + } + path = MetadataServiceClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = MetadataServiceClient.parse_common_location_path(path) + assert expected == actual + + +def test_client_with_default_client_info(): + client_info = gapic_v1.client_info.ClientInfo() + + with mock.patch.object( + transports.MetadataServiceTransport, "_prep_wrapped_messages" + ) as prep: + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + with mock.patch.object( + transports.MetadataServiceTransport, "_prep_wrapped_messages" + ) as prep: + transport_class = MetadataServiceClient.get_transport_class() + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_delete_operation(transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_operation(transport: str = "grpc"): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_operation_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = None + + client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_operation_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_delete_operation_from_dict(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_delete_operation_from_dict_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_cancel_operation(transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation(transport: str = "grpc"): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_wait_operation(transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_wait_operation(transport: str = "grpc"): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_wait_operation_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_wait_operation_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_wait_operation_from_dict(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_wait_operation_from_dict_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_operation(transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_get_operation(transport: str = "grpc"): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_get_operation_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_get_operation_from_dict(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_operations(transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + response = client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +@pytest.mark.asyncio +async def test_list_operations(transport: str = "grpc"): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +def test_list_operations_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_operations_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_operations_from_dict(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + response = client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_operations_from_dict_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_locations(transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + response = client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +@pytest.mark.asyncio +async def test_list_locations(transport: str = "grpc"): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +def test_list_locations_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_locations_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() ) - mock_create_channel.assert_called_once_with( - "squid.clam.whelk:443", - credentials=cred, - credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=mock_ssl_channel_creds, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], + await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_locations_from_dict(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + response = client.list_locations( + request={ + "name": "locations", + } ) + call.assert_called() - # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls - # is used. - with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): - with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: - transport_class( - credentials=cred, - client_cert_source_for_mtls=client_cert_source_callback, - ) - expected_cert, expected_key = client_cert_source_callback() - mock_ssl_cred.assert_called_once_with( - certificate_chain=expected_cert, private_key=expected_key + +@pytest.mark.asyncio +async def test_list_locations_from_dict_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_location(transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + response = client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +@pytest.mark.asyncio +async def test_get_location_async(transport: str = "grpc_asyncio"): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +def test_get_location_field_headers(): + client = MetadataServiceClient(credentials=ga_credentials.AnonymousCredentials()) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = locations_pb2.Location() + + client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_location_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials() + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +def test_get_location_from_dict(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + response = client.get_location( + request={ + "name": "locations/abc", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_location_from_dict_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_set_iam_policy(transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + response = client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", ) + ) + response = await client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_set_iam_policy_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_set_iam_policy_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_set_iam_policy_from_dict(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + response = client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() -def test_metadata_service_host_no_port(): - client = MetadataServiceClient( + +@pytest.mark.asyncio +async def test_set_iam_policy_from_dict_async(): + client = MetadataServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions( - api_endpoint="aiplatform.googleapis.com" - ), ) - assert client.transport._host == "aiplatform.googleapis.com:443" + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() -def test_metadata_service_host_with_port(): +def test_get_iam_policy(transport: str = "grpc"): client = MetadataServiceClient( credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions( - api_endpoint="aiplatform.googleapis.com:8000" - ), + transport=transport, ) - assert client.transport._host == "aiplatform.googleapis.com:8000" + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() -def test_metadata_service_grpc_transport_channel(): - channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) - # Check that channel is used if provided. - transport = transports.MetadataServiceGrpcTransport( - host="squid.clam.whelk", channel=channel, - ) - assert transport.grpc_channel == channel - assert transport._host == "squid.clam.whelk:443" - assert transport._ssl_channel_credentials == None + response = client.get_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] -def test_metadata_service_grpc_asyncio_transport_channel(): - channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) + assert args[0] == request - # Check that channel is used if provided. - transport = transports.MetadataServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", channel=channel, - ) - assert transport.grpc_channel == channel - assert transport._host == "squid.clam.whelk:443" - assert transport._ssl_channel_credentials == None + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + assert response.version == 774 -# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are -# removed from grpc/grpc_asyncio transport constructor. -@pytest.mark.parametrize( - "transport_class", - [ - transports.MetadataServiceGrpcTransport, - transports.MetadataServiceGrpcAsyncIOTransport, - ], -) -def test_metadata_service_transport_channel_mtls_with_client_cert_source( - transport_class, -): - with mock.patch( - "grpc.ssl_channel_credentials", autospec=True - ) as grpc_ssl_channel_cred: - with mock.patch.object( - transport_class, "create_channel" - ) as grpc_create_channel: - mock_ssl_cred = mock.Mock() - grpc_ssl_channel_cred.return_value = mock_ssl_cred + assert response.etag == b"etag_blob" - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel - cred = ga_credentials.AnonymousCredentials() - with pytest.warns(DeprecationWarning): - with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (cred, None) - transport = transport_class( - host="squid.clam.whelk", - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=client_cert_source_callback, - ) - adc.assert_called_once() +@pytest.mark.asyncio +async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) - grpc_ssl_channel_cred.assert_called_once_with( - certificate_chain=b"cert bytes", private_key=b"key bytes" - ) - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=cred, - credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", ) - assert transport.grpc_channel == mock_grpc_channel - assert transport._ssl_channel_credentials == mock_ssl_cred + ) + response = await client.get_iam_policy(request) -# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are -# removed from grpc/grpc_asyncio transport constructor. -@pytest.mark.parametrize( - "transport_class", - [ - transports.MetadataServiceGrpcTransport, - transports.MetadataServiceGrpcAsyncIOTransport, - ], -) -def test_metadata_service_transport_channel_mtls_with_adc(transport_class): - mock_ssl_cred = mock.Mock() - with mock.patch.multiple( - "google.auth.transport.grpc.SslCredentials", - __init__=mock.Mock(return_value=None), - ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), - ): - with mock.patch.object( - transport_class, "create_channel" - ) as grpc_create_channel: - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel - mock_cred = mock.Mock() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] - with pytest.warns(DeprecationWarning): - transport = transport_class( - host="squid.clam.whelk", - credentials=mock_cred, - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=None, - ) + assert args[0] == request - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=mock_cred, - credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - assert transport.grpc_channel == mock_grpc_channel + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + assert response.version == 774 -def test_metadata_service_grpc_lro_client(): + assert response.etag == b"etag_blob" + + +def test_get_iam_policy_field_headers(): client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), ) - transport = client.transport - # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsClient,) - - # Ensure that subsequent calls to the property send the exact same object. - assert transport.operations_client is transport.operations_client + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() -def test_metadata_service_grpc_lro_async_client(): - client = MetadataServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", - ) - transport = client.transport + client.get_iam_policy(request) - # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient,) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request - # Ensure that subsequent calls to the property send the exact same object. - assert transport.operations_client is transport.operations_client + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] -def test_artifact_path(): - project = "squid" - location = "clam" - metadata_store = "whelk" - artifact = "octopus" - expected = "projects/{project}/locations/{location}/metadataStores/{metadata_store}/artifacts/{artifact}".format( - project=project, - location=location, - metadata_store=metadata_store, - artifact=artifact, - ) - actual = MetadataServiceClient.artifact_path( - project, location, metadata_store, artifact +@pytest.mark.asyncio +async def test_get_iam_policy_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), ) - assert expected == actual + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" -def test_parse_artifact_path(): - expected = { - "project": "oyster", - "location": "nudibranch", - "metadata_store": "cuttlefish", - "artifact": "mussel", - } - path = MetadataServiceClient.artifact_path(**expected) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) - # Check that the path construction is reversible. - actual = MetadataServiceClient.parse_artifact_path(path) - assert expected == actual + await client.get_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request -def test_context_path(): - project = "winkle" - location = "nautilus" - metadata_store = "scallop" - context = "abalone" - expected = "projects/{project}/locations/{location}/metadataStores/{metadata_store}/contexts/{context}".format( - project=project, - location=location, - metadata_store=metadata_store, - context=context, - ) - actual = MetadataServiceClient.context_path( - project, location, metadata_store, context + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_get_iam_policy_from_dict(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), ) - assert expected == actual + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + response = client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() -def test_parse_context_path(): - expected = { - "project": "squid", - "location": "clam", - "metadata_store": "whelk", - "context": "octopus", - } - path = MetadataServiceClient.context_path(**expected) - # Check that the path construction is reversible. - actual = MetadataServiceClient.parse_context_path(path) - assert expected == actual +@pytest.mark.asyncio +async def test_get_iam_policy_from_dict_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() -def test_execution_path(): - project = "oyster" - location = "nudibranch" - metadata_store = "cuttlefish" - execution = "mussel" - expected = "projects/{project}/locations/{location}/metadataStores/{metadata_store}/executions/{execution}".format( - project=project, - location=location, - metadata_store=metadata_store, - execution=execution, - ) - actual = MetadataServiceClient.execution_path( - project, location, metadata_store, execution +def test_test_iam_permissions(transport: str = "grpc"): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - assert expected == actual - -def test_parse_execution_path(): - expected = { - "project": "winkle", - "location": "nautilus", - "metadata_store": "scallop", - "execution": "abalone", - } - path = MetadataServiceClient.execution_path(**expected) + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() - # Check that the path construction is reversible. - actual = MetadataServiceClient.parse_execution_path(path) - assert expected == actual + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + response = client.test_iam_permissions(request) -def test_metadata_schema_path(): - project = "squid" - location = "clam" - metadata_store = "whelk" - metadata_schema = "octopus" - expected = "projects/{project}/locations/{location}/metadataStores/{metadata_store}/metadataSchemas/{metadata_schema}".format( - project=project, - location=location, - metadata_store=metadata_store, - metadata_schema=metadata_schema, - ) - actual = MetadataServiceClient.metadata_schema_path( - project, location, metadata_store, metadata_schema - ) - assert expected == actual + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request -def test_parse_metadata_schema_path(): - expected = { - "project": "oyster", - "location": "nudibranch", - "metadata_store": "cuttlefish", - "metadata_schema": "mussel", - } - path = MetadataServiceClient.metadata_schema_path(**expected) + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) - # Check that the path construction is reversible. - actual = MetadataServiceClient.parse_metadata_schema_path(path) - assert expected == actual + assert response.permissions == ["permissions_value"] -def test_metadata_store_path(): - project = "winkle" - location = "nautilus" - metadata_store = "scallop" - expected = "projects/{project}/locations/{location}/metadataStores/{metadata_store}".format( - project=project, location=location, metadata_store=metadata_store, - ) - actual = MetadataServiceClient.metadata_store_path( - project, location, metadata_store +@pytest.mark.asyncio +async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - assert expected == actual + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() -def test_parse_metadata_store_path(): - expected = { - "project": "abalone", - "location": "squid", - "metadata_store": "clam", - } - path = MetadataServiceClient.metadata_store_path(**expected) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + ) - # Check that the path construction is reversible. - actual = MetadataServiceClient.parse_metadata_store_path(path) - assert expected == actual + response = await client.test_iam_permissions(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] -def test_common_billing_account_path(): - billing_account = "whelk" - expected = "billingAccounts/{billing_account}".format( - billing_account=billing_account, - ) - actual = MetadataServiceClient.common_billing_account_path(billing_account) - assert expected == actual + assert args[0] == request + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) -def test_parse_common_billing_account_path(): - expected = { - "billing_account": "octopus", - } - path = MetadataServiceClient.common_billing_account_path(**expected) + assert response.permissions == ["permissions_value"] - # Check that the path construction is reversible. - actual = MetadataServiceClient.parse_common_billing_account_path(path) - assert expected == actual +def test_test_iam_permissions_field_headers(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" -def test_common_folder_path(): - folder = "oyster" - expected = "folders/{folder}".format(folder=folder,) - actual = MetadataServiceClient.common_folder_path(folder) - assert expected == actual + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + client.test_iam_permissions(request) -def test_parse_common_folder_path(): - expected = { - "folder": "nudibranch", - } - path = MetadataServiceClient.common_folder_path(**expected) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request - # Check that the path construction is reversible. - actual = MetadataServiceClient.parse_common_folder_path(path) - assert expected == actual + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] -def test_common_organization_path(): - organization = "cuttlefish" - expected = "organizations/{organization}".format(organization=organization,) - actual = MetadataServiceClient.common_organization_path(organization) - assert expected == actual +@pytest.mark.asyncio +async def test_test_iam_permissions_field_headers_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" -def test_parse_common_organization_path(): - expected = { - "organization": "mussel", - } - path = MetadataServiceClient.common_organization_path(**expected) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) - # Check that the path construction is reversible. - actual = MetadataServiceClient.parse_common_organization_path(path) - assert expected == actual + await client.test_iam_permissions(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request -def test_common_project_path(): - project = "winkle" - expected = "projects/{project}".format(project=project,) - actual = MetadataServiceClient.common_project_path(project) - assert expected == actual + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] -def test_parse_common_project_path(): - expected = { - "project": "nautilus", - } - path = MetadataServiceClient.common_project_path(**expected) +def test_test_iam_permissions_from_dict(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() - # Check that the path construction is reversible. - actual = MetadataServiceClient.parse_common_project_path(path) - assert expected == actual + response = client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() -def test_common_location_path(): - project = "scallop" - location = "abalone" - expected = "projects/{project}/locations/{location}".format( - project=project, location=location, +@pytest.mark.asyncio +async def test_test_iam_permissions_from_dict_async(): + client = MetadataServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), ) - actual = MetadataServiceClient.common_location_path(project, location) - assert expected == actual + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + response = await client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() -def test_parse_common_location_path(): - expected = { - "project": "squid", - "location": "clam", - } - path = MetadataServiceClient.common_location_path(**expected) - # Check that the path construction is reversible. - actual = MetadataServiceClient.parse_common_location_path(path) - assert expected == actual +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + for transport, close_name in transports.items(): + client = MetadataServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() -def test_client_withDEFAULT_CLIENT_INFO(): - client_info = gapic_v1.client_info.ClientInfo() - with mock.patch.object( - transports.MetadataServiceTransport, "_prep_wrapped_messages" - ) as prep: +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: client = MetadataServiceClient( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), transport=transport ) - prep.assert_called_once_with(client_info) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (MetadataServiceClient, transports.MetadataServiceGrpcTransport), + (MetadataServiceAsyncClient, transports.MetadataServiceGrpcAsyncIOTransport), + ], +) +def test_api_key_credentials(client_class, transport_class): with mock.patch.object( - transports.MetadataServiceTransport, "_prep_wrapped_messages" - ) as prep: - transport_class = MetadataServiceClient.get_transport_class() - transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, - ) - prep.assert_called_once_with(client_info) + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) diff --git a/tests/unit/gapic/aiplatform_v1beta1/test_migration_service.py b/tests/unit/gapic/aiplatform_v1beta1/test_migration_service.py index c5bfb7e766..6d45586a12 100644 --- a/tests/unit/gapic/aiplatform_v1beta1/test_migration_service.py +++ b/tests/unit/gapic/aiplatform_v1beta1/test_migration_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,8 +14,13 @@ # limitations under the License. # import os -import mock -import packaging.version + +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock +except ImportError: + import mock import grpc from grpc.experimental import aio @@ -30,8 +35,10 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.aiplatform_v1beta1.services.migration_service import ( @@ -42,42 +49,17 @@ ) from google.cloud.aiplatform_v1beta1.services.migration_service import pagers from google.cloud.aiplatform_v1beta1.services.migration_service import transports -from google.cloud.aiplatform_v1beta1.services.migration_service.transports.base import ( - _API_CORE_VERSION, -) -from google.cloud.aiplatform_v1beta1.services.migration_service.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.aiplatform_v1beta1.types import migratable_resource from google.cloud.aiplatform_v1beta1.types import migration_service +from google.cloud.location import locations_pb2 +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 from google.oauth2 import service_account import google.auth -# TODO(busunkim): Once google-api-core >= 1.26.0 is required: -# - Delete all the api-core and auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - -requires_api_core_lt_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), - reason="This test requires google-api-core < 1.26.0", -) - -requires_api_core_gte_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), - reason="This test requires google-api-core >= 1.26.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -124,40 +106,81 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( - "client_class", [MigrationServiceClient, MigrationServiceAsyncClient,] + "client_class,transport_name", + [ + (MigrationServiceClient, "grpc"), + (MigrationServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_migration_service_client_from_service_account_info(client_class): +def test_migration_service_client_from_service_account_info( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.MigrationServiceGrpcTransport, "grpc"), + (transports.MigrationServiceGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_migration_service_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() @pytest.mark.parametrize( - "client_class", [MigrationServiceClient, MigrationServiceAsyncClient,] + "client_class,transport_name", + [ + (MigrationServiceClient, "grpc"), + (MigrationServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_migration_service_client_from_service_account_file(client_class): +def test_migration_service_client_from_service_account_file( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") def test_migration_service_client_get_transport_class(): @@ -210,7 +233,7 @@ def test_migration_service_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -219,6 +242,7 @@ def test_migration_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -226,7 +250,7 @@ def test_migration_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -235,6 +259,7 @@ def test_migration_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -242,7 +267,7 @@ def test_migration_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -251,26 +276,27 @@ def test_migration_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -279,6 +305,7 @@ def test_migration_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -338,7 +365,7 @@ def test_migration_service_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -355,6 +382,7 @@ def test_migration_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case ADC client cert is provided. Whether client cert is used depends on @@ -379,7 +407,7 @@ def test_migration_service_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -388,6 +416,7 @@ def test_migration_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case client_cert_source and ADC client cert are not provided. @@ -400,7 +429,7 @@ def test_migration_service_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -409,9 +438,91 @@ def test_migration_service_client_mtls_env_auto( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) +@pytest.mark.parametrize( + "client_class", [MigrationServiceClient, MigrationServiceAsyncClient] +) +@mock.patch.object( + MigrationServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(MigrationServiceClient), +) +@mock.patch.object( + MigrationServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(MigrationServiceAsyncClient), +) +def test_migration_service_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + @pytest.mark.parametrize( "client_class,transport_class,transport_name", [ @@ -427,10 +538,12 @@ def test_migration_service_client_client_options_scopes( client_class, transport_class, transport_name ): # Check the case scopes are provided. - options = client_options.ClientOptions(scopes=["1", "2"],) + options = client_options.ClientOptions( + scopes=["1", "2"], + ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -439,28 +552,36 @@ def test_migration_service_client_client_options_scopes( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (MigrationServiceClient, transports.MigrationServiceGrpcTransport, "grpc"), + ( + MigrationServiceClient, + transports.MigrationServiceGrpcTransport, + "grpc", + grpc_helpers, + ), ( MigrationServiceAsyncClient, transports.MigrationServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_migration_service_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -469,6 +590,7 @@ def test_migration_service_client_client_options_credentials_file( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -488,15 +610,87 @@ def test_migration_service_client_client_options_from_dict(): client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) -def test_search_migratable_resources( - transport: str = "grpc", - request_type=migration_service.SearchMigratableResourcesRequest, +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + MigrationServiceClient, + transports.MigrationServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + MigrationServiceAsyncClient, + transports.MigrationServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_migration_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers ): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + migration_service.SearchMigratableResourcesRequest, + dict, + ], +) +def test_search_migratable_resources(request_type, transport: str = "grpc"): client = MigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -523,15 +717,12 @@ def test_search_migratable_resources( assert response.next_page_token == "next_page_token_value" -def test_search_migratable_resources_from_dict(): - test_search_migratable_resources(request_type=dict) - - def test_search_migratable_resources_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = MigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -550,7 +741,8 @@ async def test_search_migratable_resources_async( request_type=migration_service.SearchMigratableResourcesRequest, ): client = MigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -585,13 +777,15 @@ async def test_search_migratable_resources_async_from_dict(): def test_search_migratable_resources_field_headers(): - client = MigrationServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = migration_service.SearchMigratableResourcesRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -607,7 +801,10 @@ def test_search_migratable_resources_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -620,7 +817,7 @@ async def test_search_migratable_resources_field_headers_async(): # a field header. Set these to a non-empty value. request = migration_service.SearchMigratableResourcesRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -638,11 +835,16 @@ async def test_search_migratable_resources_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_search_migratable_resources_flattened(): - client = MigrationServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -652,23 +854,30 @@ def test_search_migratable_resources_flattened(): call.return_value = migration_service.SearchMigratableResourcesResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.search_migratable_resources(parent="parent_value",) + client.search_migratable_resources( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_search_migratable_resources_flattened_error(): - client = MigrationServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.search_migratable_resources( - migration_service.SearchMigratableResourcesRequest(), parent="parent_value", + migration_service.SearchMigratableResourcesRequest(), + parent="parent_value", ) @@ -690,13 +899,17 @@ async def test_search_migratable_resources_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.search_migratable_resources(parent="parent_value",) + response = await client.search_migratable_resources( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -709,12 +922,16 @@ async def test_search_migratable_resources_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.search_migratable_resources( - migration_service.SearchMigratableResourcesRequest(), parent="parent_value", + migration_service.SearchMigratableResourcesRequest(), + parent="parent_value", ) -def test_search_migratable_resources_pager(): - client = MigrationServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_search_migratable_resources_pager(transport_name: str = "grpc"): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -731,10 +948,13 @@ def test_search_migratable_resources_pager(): next_page_token="abc", ), migration_service.SearchMigratableResourcesResponse( - migratable_resources=[], next_page_token="def", + migratable_resources=[], + next_page_token="def", ), migration_service.SearchMigratableResourcesResponse( - migratable_resources=[migratable_resource.MigratableResource(),], + migratable_resources=[ + migratable_resource.MigratableResource(), + ], next_page_token="ghi", ), migration_service.SearchMigratableResourcesResponse( @@ -754,15 +974,18 @@ def test_search_migratable_resources_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all( isinstance(i, migratable_resource.MigratableResource) for i in results ) -def test_search_migratable_resources_pages(): - client = MigrationServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_search_migratable_resources_pages(transport_name: str = "grpc"): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -779,10 +1002,13 @@ def test_search_migratable_resources_pages(): next_page_token="abc", ), migration_service.SearchMigratableResourcesResponse( - migratable_resources=[], next_page_token="def", + migratable_resources=[], + next_page_token="def", ), migration_service.SearchMigratableResourcesResponse( - migratable_resources=[migratable_resource.MigratableResource(),], + migratable_resources=[ + migratable_resource.MigratableResource(), + ], next_page_token="ghi", ), migration_service.SearchMigratableResourcesResponse( @@ -821,10 +1047,13 @@ async def test_search_migratable_resources_async_pager(): next_page_token="abc", ), migration_service.SearchMigratableResourcesResponse( - migratable_resources=[], next_page_token="def", + migratable_resources=[], + next_page_token="def", ), migration_service.SearchMigratableResourcesResponse( - migratable_resources=[migratable_resource.MigratableResource(),], + migratable_resources=[ + migratable_resource.MigratableResource(), + ], next_page_token="ghi", ), migration_service.SearchMigratableResourcesResponse( @@ -835,10 +1064,12 @@ async def test_search_migratable_resources_async_pager(): ), RuntimeError, ) - async_pager = await client.search_migratable_resources(request={},) + async_pager = await client.search_migratable_resources( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -870,10 +1101,13 @@ async def test_search_migratable_resources_async_pages(): next_page_token="abc", ), migration_service.SearchMigratableResourcesResponse( - migratable_resources=[], next_page_token="def", + migratable_resources=[], + next_page_token="def", ), migration_service.SearchMigratableResourcesResponse( - migratable_resources=[migratable_resource.MigratableResource(),], + migratable_resources=[ + migratable_resource.MigratableResource(), + ], next_page_token="ghi", ), migration_service.SearchMigratableResourcesResponse( @@ -885,17 +1119,25 @@ async def test_search_migratable_resources_async_pages(): RuntimeError, ) pages = [] - async for page_ in (await client.search_migratable_resources(request={})).pages: + async for page_ in ( + await client.search_migratable_resources(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_batch_migrate_resources( - transport: str = "grpc", request_type=migration_service.BatchMigrateResourcesRequest -): +@pytest.mark.parametrize( + "request_type", + [ + migration_service.BatchMigrateResourcesRequest, + dict, + ], +) +def test_batch_migrate_resources(request_type, transport: str = "grpc"): client = MigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -919,15 +1161,12 @@ def test_batch_migrate_resources( assert isinstance(response, future.Future) -def test_batch_migrate_resources_from_dict(): - test_batch_migrate_resources(request_type=dict) - - def test_batch_migrate_resources_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = MigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -946,7 +1185,8 @@ async def test_batch_migrate_resources_async( request_type=migration_service.BatchMigrateResourcesRequest, ): client = MigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -978,13 +1218,15 @@ async def test_batch_migrate_resources_async_from_dict(): def test_batch_migrate_resources_field_headers(): - client = MigrationServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = migration_service.BatchMigrateResourcesRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1000,7 +1242,10 @@ def test_batch_migrate_resources_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1013,7 +1258,7 @@ async def test_batch_migrate_resources_field_headers_async(): # a field header. Set these to a non-empty value. request = migration_service.BatchMigrateResourcesRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1031,11 +1276,16 @@ async def test_batch_migrate_resources_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_batch_migrate_resources_flattened(): - client = MigrationServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1060,18 +1310,24 @@ def test_batch_migrate_resources_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].migrate_resource_requests == [ + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].migrate_resource_requests + mock_val = [ migration_service.MigrateResourceRequest( migrate_ml_engine_model_version_config=migration_service.MigrateResourceRequest.MigrateMlEngineModelVersionConfig( endpoint="endpoint_value" ) ) ] + assert arg == mock_val def test_batch_migrate_resources_flattened_error(): - client = MigrationServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1122,14 +1378,18 @@ async def test_batch_migrate_resources_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].migrate_resource_requests == [ + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].migrate_resource_requests + mock_val = [ migration_service.MigrateResourceRequest( migrate_ml_engine_model_version_config=migration_service.MigrateResourceRequest.MigrateMlEngineModelVersionConfig( endpoint="endpoint_value" ) ) ] + assert arg == mock_val @pytest.mark.asyncio @@ -1161,7 +1421,8 @@ def test_credentials_transport_error(): ) with pytest.raises(ValueError): client = MigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # It is an error to provide a credentials file and a transport instance. @@ -1174,13 +1435,34 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.MigrationServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = MigrationServiceClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = MigrationServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.MigrationServiceGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = MigrationServiceClient( - client_options={"scopes": ["1", "2"]}, transport=transport, + client_options={"scopes": ["1", "2"]}, + transport=transport, ) @@ -1223,10 +1505,28 @@ def test_transport_adc(transport_class): adc.assert_called_once() +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = MigrationServiceClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + def test_transport_grpc_default(): # A client should use the gRPC transport by default. - client = MigrationServiceClient(credentials=ga_credentials.AnonymousCredentials(),) - assert isinstance(client.transport, transports.MigrationServiceGrpcTransport,) + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.MigrationServiceGrpcTransport, + ) def test_migration_service_base_transport_error(): @@ -1253,18 +1553,38 @@ def test_migration_service_base_transport(): methods = ( "search_migratable_resources", "batch_migrate_resources", + "set_iam_policy", + "get_iam_policy", + "test_iam_permissions", + "get_location", + "list_locations", + "get_operation", + "wait_operation", + "cancel_operation", + "delete_operation", + "list_operations", ) for method in methods: with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + # Additionally, the LRO client (a property) should # also raise NotImplementedError with pytest.raises(NotImplementedError): transport.operations_client + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + -@requires_google_auth_gte_1_25_0 def test_migration_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -1275,7 +1595,8 @@ def test_migration_service_base_transport_with_credentials_file(): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.MigrationServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", + credentials_file="credentials.json", + quota_project_id="octopus", ) load_creds.assert_called_once_with( "credentials.json", @@ -1285,26 +1606,6 @@ def test_migration_service_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_migration_service_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.aiplatform_v1beta1.services.migration_service.transports.MigrationServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.MigrationServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - def test_migration_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( @@ -1316,7 +1617,6 @@ def test_migration_service_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_migration_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -1329,18 +1629,6 @@ def test_migration_service_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_migration_service_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - MigrationServiceClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -1348,7 +1636,6 @@ def test_migration_service_auth_adc_old_google_auth(): transports.MigrationServiceGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_migration_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -1363,34 +1650,13 @@ def test_migration_service_transport_auth_adc(transport_class): @pytest.mark.parametrize( - "transport_class", + "transport_class,grpc_helpers", [ - transports.MigrationServiceGrpcTransport, - transports.MigrationServiceGrpcAsyncIOTransport, + (transports.MigrationServiceGrpcTransport, grpc_helpers), + (transports.MigrationServiceGrpcAsyncIOTransport, grpc_helpers_async), ], ) -@requires_google_auth_lt_1_25_0 -def test_migration_service_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.MigrationServiceGrpcTransport, grpc_helpers), - (transports.MigrationServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_gte_1_26_0 -def test_migration_service_transport_create_channel(transport_class, grpc_helpers): +def test_migration_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. with mock.patch.object( @@ -1418,79 +1684,6 @@ def test_migration_service_transport_create_channel(transport_class, grpc_helper ) -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.MigrationServiceGrpcTransport, grpc_helpers), - (transports.MigrationServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_migration_service_transport_create_channel_old_api_core( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class(quota_project_id="octopus") - - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.MigrationServiceGrpcTransport, grpc_helpers), - (transports.MigrationServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_migration_service_transport_create_channel_user_scopes( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=["1", "2"], - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -1513,7 +1706,7 @@ def test_migration_service_grpc_transport_client_cert_source_for_mtls(transport_ "squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_channel_creds, quota_project_id=None, options=[ @@ -1536,24 +1729,40 @@ def test_migration_service_grpc_transport_client_cert_source_for_mtls(transport_ ) -def test_migration_service_host_no_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_migration_service_host_no_port(transport_name): client = MigrationServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="aiplatform.googleapis.com" ), + transport=transport_name, ) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") -def test_migration_service_host_with_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_migration_service_host_with_port(transport_name): client = MigrationServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="aiplatform.googleapis.com:8000" ), + transport=transport_name, ) - assert client.transport._host == "aiplatform.googleapis.com:8000" + assert client.transport._host == ("aiplatform.googleapis.com:8000") def test_migration_service_grpc_transport_channel(): @@ -1561,7 +1770,8 @@ def test_migration_service_grpc_transport_channel(): # Check that channel is used if provided. transport = transports.MigrationServiceGrpcTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -1573,7 +1783,8 @@ def test_migration_service_grpc_asyncio_transport_channel(): # Check that channel is used if provided. transport = transports.MigrationServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -1622,7 +1833,7 @@ def test_migration_service_transport_channel_mtls_with_client_cert_source( "mtls.squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -1669,7 +1880,7 @@ def test_migration_service_transport_channel_mtls_with_adc(transport_class): "mtls.squid.clam.whelk:443", credentials=mock_cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -1682,12 +1893,16 @@ def test_migration_service_transport_channel_mtls_with_adc(transport_class): def test_migration_service_grpc_lro_client(): client = MigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -1695,12 +1910,16 @@ def test_migration_service_grpc_lro_client(): def test_migration_service_grpc_lro_async_client(): client = MigrationServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -1711,7 +1930,9 @@ def test_annotated_dataset_path(): dataset = "clam" annotated_dataset = "whelk" expected = "projects/{project}/datasets/{dataset}/annotatedDatasets/{annotated_dataset}".format( - project=project, dataset=dataset, annotated_dataset=annotated_dataset, + project=project, + dataset=dataset, + annotated_dataset=annotated_dataset, ) actual = MigrationServiceClient.annotated_dataset_path( project, dataset, annotated_dataset @@ -1737,7 +1958,9 @@ def test_dataset_path(): location = "mussel" dataset = "winkle" expected = "projects/{project}/locations/{location}/datasets/{dataset}".format( - project=project, location=location, dataset=dataset, + project=project, + location=location, + dataset=dataset, ) actual = MigrationServiceClient.dataset_path(project, location, dataset) assert expected == actual @@ -1760,7 +1983,8 @@ def test_dataset_path(): project = "squid" dataset = "clam" expected = "projects/{project}/datasets/{dataset}".format( - project=project, dataset=dataset, + project=project, + dataset=dataset, ) actual = MigrationServiceClient.dataset_path(project, dataset) assert expected == actual @@ -1783,7 +2007,9 @@ def test_dataset_path(): location = "nudibranch" dataset = "cuttlefish" expected = "projects/{project}/locations/{location}/datasets/{dataset}".format( - project=project, location=location, dataset=dataset, + project=project, + location=location, + dataset=dataset, ) actual = MigrationServiceClient.dataset_path(project, location, dataset) assert expected == actual @@ -1807,7 +2033,9 @@ def test_model_path(): location = "abalone" model = "squid" expected = "projects/{project}/locations/{location}/models/{model}".format( - project=project, location=location, model=model, + project=project, + location=location, + model=model, ) actual = MigrationServiceClient.model_path(project, location, model) assert expected == actual @@ -1831,7 +2059,9 @@ def test_model_path(): location = "nudibranch" model = "cuttlefish" expected = "projects/{project}/locations/{location}/models/{model}".format( - project=project, location=location, model=model, + project=project, + location=location, + model=model, ) actual = MigrationServiceClient.model_path(project, location, model) assert expected == actual @@ -1855,7 +2085,9 @@ def test_version_path(): model = "abalone" version = "squid" expected = "projects/{project}/models/{model}/versions/{version}".format( - project=project, model=model, version=version, + project=project, + model=model, + version=version, ) actual = MigrationServiceClient.version_path(project, model, version) assert expected == actual @@ -1896,7 +2128,9 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "cuttlefish" - expected = "folders/{folder}".format(folder=folder,) + expected = "folders/{folder}".format( + folder=folder, + ) actual = MigrationServiceClient.common_folder_path(folder) assert expected == actual @@ -1914,7 +2148,9 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "winkle" - expected = "organizations/{organization}".format(organization=organization,) + expected = "organizations/{organization}".format( + organization=organization, + ) actual = MigrationServiceClient.common_organization_path(organization) assert expected == actual @@ -1932,7 +2168,9 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "scallop" - expected = "projects/{project}".format(project=project,) + expected = "projects/{project}".format( + project=project, + ) actual = MigrationServiceClient.common_project_path(project) assert expected == actual @@ -1952,7 +2190,8 @@ def test_common_location_path(): project = "squid" location = "clam" expected = "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) actual = MigrationServiceClient.common_location_path(project, location) assert expected == actual @@ -1970,14 +2209,15 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( transports.MigrationServiceTransport, "_prep_wrapped_messages" ) as prep: client = MigrationServiceClient( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -1986,6 +2226,1593 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = MigrationServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_delete_operation(transport: str = "grpc"): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_operation(transport: str = "grpc"): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_operation_field_headers(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = None + + client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_operation_field_headers_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_delete_operation_from_dict(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_delete_operation_from_dict_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_cancel_operation(transport: str = "grpc"): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation(transport: str = "grpc"): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_wait_operation(transport: str = "grpc"): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_wait_operation(transport: str = "grpc"): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_wait_operation_field_headers(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_wait_operation_field_headers_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_wait_operation_from_dict(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_wait_operation_from_dict_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_operation(transport: str = "grpc"): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_get_operation(transport: str = "grpc"): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_get_operation_field_headers(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_get_operation_from_dict(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_operations(transport: str = "grpc"): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + response = client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +@pytest.mark.asyncio +async def test_list_operations(transport: str = "grpc"): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +def test_list_operations_field_headers(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_operations_field_headers_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_operations_from_dict(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + response = client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_operations_from_dict_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_locations(transport: str = "grpc"): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + response = client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +@pytest.mark.asyncio +async def test_list_locations(transport: str = "grpc"): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +def test_list_locations_field_headers(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_locations_field_headers_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_locations_from_dict(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + response = client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_locations_from_dict_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_location(transport: str = "grpc"): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + response = client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +@pytest.mark.asyncio +async def test_get_location_async(transport: str = "grpc_asyncio"): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +def test_get_location_field_headers(): + client = MigrationServiceClient(credentials=ga_credentials.AnonymousCredentials()) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = locations_pb2.Location() + + client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_location_field_headers_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials() + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +def test_get_location_from_dict(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + response = client.get_location( + request={ + "name": "locations/abc", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_location_from_dict_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_set_iam_policy(transport: str = "grpc"): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + response = client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + response = await client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_set_iam_policy_field_headers(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_set_iam_policy_field_headers_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_set_iam_policy_from_dict(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_set_iam_policy_from_dict_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +def test_get_iam_policy(transport: str = "grpc"): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + + response = client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + + response = await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_get_iam_policy_field_headers(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_iam_policy_field_headers_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_get_iam_policy_from_dict(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_iam_policy_from_dict_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +def test_test_iam_permissions(transport: str = "grpc"): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + + response = client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + ) + + response = await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +def test_test_iam_permissions_field_headers(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_field_headers_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_test_iam_permissions_from_dict(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + response = client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_from_dict_async(): + client = MigrationServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + response = await client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = MigrationServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (MigrationServiceClient, transports.MigrationServiceGrpcTransport), + (MigrationServiceAsyncClient, transports.MigrationServiceGrpcAsyncIOTransport), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) diff --git a/tests/unit/gapic/aiplatform_v1beta1/test_model_service.py b/tests/unit/gapic/aiplatform_v1beta1/test_model_service.py index d28fff4307..f97b689c08 100644 --- a/tests/unit/gapic/aiplatform_v1beta1/test_model_service.py +++ b/tests/unit/gapic/aiplatform_v1beta1/test_model_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,8 +14,13 @@ # limitations under the License. # import os -import mock -import packaging.version + +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock +except ImportError: + import mock import grpc from grpc.experimental import aio @@ -30,8 +35,10 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.aiplatform_v1beta1.services.model_service import ( @@ -40,12 +47,6 @@ from google.cloud.aiplatform_v1beta1.services.model_service import ModelServiceClient from google.cloud.aiplatform_v1beta1.services.model_service import pagers from google.cloud.aiplatform_v1beta1.services.model_service import transports -from google.cloud.aiplatform_v1beta1.services.model_service.transports.base import ( - _API_CORE_VERSION, -) -from google.cloud.aiplatform_v1beta1.services.model_service.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.aiplatform_v1beta1.types import deployed_model_ref from google.cloud.aiplatform_v1beta1.types import encryption_spec from google.cloud.aiplatform_v1beta1.types import env_var @@ -55,9 +56,16 @@ from google.cloud.aiplatform_v1beta1.types import model from google.cloud.aiplatform_v1beta1.types import model as gca_model from google.cloud.aiplatform_v1beta1.types import model_evaluation +from google.cloud.aiplatform_v1beta1.types import ( + model_evaluation as gca_model_evaluation, +) from google.cloud.aiplatform_v1beta1.types import model_evaluation_slice from google.cloud.aiplatform_v1beta1.types import model_service from google.cloud.aiplatform_v1beta1.types import operation as gca_operation +from google.cloud.location import locations_pb2 +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 from google.oauth2 import service_account from google.protobuf import field_mask_pb2 # type: ignore @@ -66,29 +74,6 @@ import google.auth -# TODO(busunkim): Once google-api-core >= 1.26.0 is required: -# - Delete all the api-core and auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - -requires_api_core_lt_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), - reason="This test requires google-api-core < 1.26.0", -) - -requires_api_core_gte_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), - reason="This test requires google-api-core >= 1.26.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -130,37 +115,78 @@ def test__get_default_mtls_endpoint(): assert ModelServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi -@pytest.mark.parametrize("client_class", [ModelServiceClient, ModelServiceAsyncClient,]) -def test_model_service_client_from_service_account_info(client_class): +@pytest.mark.parametrize( + "client_class,transport_name", + [ + (ModelServiceClient, "grpc"), + (ModelServiceAsyncClient, "grpc_asyncio"), + ], +) +def test_model_service_client_from_service_account_info(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") -@pytest.mark.parametrize("client_class", [ModelServiceClient, ModelServiceAsyncClient,]) -def test_model_service_client_from_service_account_file(client_class): +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.ModelServiceGrpcTransport, "grpc"), + (transports.ModelServiceGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_model_service_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() + + +@pytest.mark.parametrize( + "client_class,transport_name", + [ + (ModelServiceClient, "grpc"), + (ModelServiceAsyncClient, "grpc_asyncio"), + ], +) +def test_model_service_client_from_service_account_file(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") def test_model_service_client_get_transport_class(): @@ -211,7 +237,7 @@ def test_model_service_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -220,6 +246,7 @@ def test_model_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -227,7 +254,7 @@ def test_model_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -236,6 +263,7 @@ def test_model_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -243,7 +271,7 @@ def test_model_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -252,26 +280,27 @@ def test_model_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -280,6 +309,7 @@ def test_model_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -327,7 +357,7 @@ def test_model_service_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -344,6 +374,7 @@ def test_model_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case ADC client cert is provided. Whether client cert is used depends on @@ -368,7 +399,7 @@ def test_model_service_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -377,6 +408,7 @@ def test_model_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case client_cert_source and ADC client cert are not provided. @@ -389,7 +421,7 @@ def test_model_service_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -398,9 +430,87 @@ def test_model_service_client_mtls_env_auto( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) +@pytest.mark.parametrize("client_class", [ModelServiceClient, ModelServiceAsyncClient]) +@mock.patch.object( + ModelServiceClient, "DEFAULT_ENDPOINT", modify_default_endpoint(ModelServiceClient) +) +@mock.patch.object( + ModelServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(ModelServiceAsyncClient), +) +def test_model_service_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + @pytest.mark.parametrize( "client_class,transport_class,transport_name", [ @@ -416,10 +526,12 @@ def test_model_service_client_client_options_scopes( client_class, transport_class, transport_name ): # Check the case scopes are provided. - options = client_options.ClientOptions(scopes=["1", "2"],) + options = client_options.ClientOptions( + scopes=["1", "2"], + ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -428,28 +540,36 @@ def test_model_service_client_client_options_scopes( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (ModelServiceClient, transports.ModelServiceGrpcTransport, "grpc"), + ( + ModelServiceClient, + transports.ModelServiceGrpcTransport, + "grpc", + grpc_helpers, + ), ( ModelServiceAsyncClient, transports.ModelServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_model_service_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -458,6 +578,7 @@ def test_model_service_client_client_options_credentials_file( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -475,14 +596,87 @@ def test_model_service_client_client_options_from_dict(): client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) -def test_upload_model( - transport: str = "grpc", request_type=model_service.UploadModelRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + ModelServiceClient, + transports.ModelServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + ModelServiceAsyncClient, + transports.ModelServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_model_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers ): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + model_service.UploadModelRequest, + dict, + ], +) +def test_upload_model(request_type, transport: str = "grpc"): client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -504,15 +698,12 @@ def test_upload_model( assert isinstance(response, future.Future) -def test_upload_model_from_dict(): - test_upload_model(request_type=dict) - - def test_upload_model_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -528,7 +719,8 @@ async def test_upload_model_async( transport: str = "grpc_asyncio", request_type=model_service.UploadModelRequest ): client = ModelServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -558,13 +750,15 @@ async def test_upload_model_async_from_dict(): def test_upload_model_field_headers(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = model_service.UploadModelRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.upload_model), "__call__") as call: @@ -578,18 +772,23 @@ def test_upload_model_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_upload_model_field_headers_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = model_service.UploadModelRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.upload_model), "__call__") as call: @@ -605,11 +804,16 @@ async def test_upload_model_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_upload_model_flattened(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.upload_model), "__call__") as call: @@ -618,19 +822,26 @@ def test_upload_model_flattened(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.upload_model( - parent="parent_value", model=gca_model.Model(name="name_value"), + parent="parent_value", + model=gca_model.Model(name="name_value"), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].model == gca_model.Model(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].model + mock_val = gca_model.Model(name="name_value") + assert arg == mock_val def test_upload_model_flattened_error(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -644,7 +855,9 @@ def test_upload_model_flattened_error(): @pytest.mark.asyncio async def test_upload_model_flattened_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.upload_model), "__call__") as call: @@ -657,20 +870,27 @@ async def test_upload_model_flattened_async(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. response = await client.upload_model( - parent="parent_value", model=gca_model.Model(name="name_value"), + parent="parent_value", + model=gca_model.Model(name="name_value"), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].model == gca_model.Model(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].model + mock_val = gca_model.Model(name="name_value") + assert arg == mock_val @pytest.mark.asyncio async def test_upload_model_flattened_error_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -682,9 +902,17 @@ async def test_upload_model_flattened_error_async(): ) -def test_get_model(transport: str = "grpc", request_type=model_service.GetModelRequest): +@pytest.mark.parametrize( + "request_type", + [ + model_service.GetModelRequest, + dict, + ], +) +def test_get_model(request_type, transport: str = "grpc"): client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -696,8 +924,11 @@ def test_get_model(transport: str = "grpc", request_type=model_service.GetModelR # Designate an appropriate return value for the call. call.return_value = model.Model( name="name_value", + version_id="version_id_value", + version_aliases=["version_aliases_value"], display_name="display_name_value", description="description_value", + version_description="version_description_value", metadata_schema_uri="metadata_schema_uri_value", training_pipeline="training_pipeline_value", artifact_uri="artifact_uri_value", @@ -718,8 +949,11 @@ def test_get_model(transport: str = "grpc", request_type=model_service.GetModelR # Establish that the response is the type that we expect. assert isinstance(response, model.Model) assert response.name == "name_value" + assert response.version_id == "version_id_value" + assert response.version_aliases == ["version_aliases_value"] assert response.display_name == "display_name_value" assert response.description == "description_value" + assert response.version_description == "version_description_value" assert response.metadata_schema_uri == "metadata_schema_uri_value" assert response.training_pipeline == "training_pipeline_value" assert response.artifact_uri == "artifact_uri_value" @@ -735,15 +969,12 @@ def test_get_model(transport: str = "grpc", request_type=model_service.GetModelR assert response.etag == "etag_value" -def test_get_model_from_dict(): - test_get_model(request_type=dict) - - def test_get_model_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -759,7 +990,8 @@ async def test_get_model_async( transport: str = "grpc_asyncio", request_type=model_service.GetModelRequest ): client = ModelServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -772,8 +1004,11 @@ async def test_get_model_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( model.Model( name="name_value", + version_id="version_id_value", + version_aliases=["version_aliases_value"], display_name="display_name_value", description="description_value", + version_description="version_description_value", metadata_schema_uri="metadata_schema_uri_value", training_pipeline="training_pipeline_value", artifact_uri="artifact_uri_value", @@ -799,8 +1034,11 @@ async def test_get_model_async( # Establish that the response is the type that we expect. assert isinstance(response, model.Model) assert response.name == "name_value" + assert response.version_id == "version_id_value" + assert response.version_aliases == ["version_aliases_value"] assert response.display_name == "display_name_value" assert response.description == "description_value" + assert response.version_description == "version_description_value" assert response.metadata_schema_uri == "metadata_schema_uri_value" assert response.training_pipeline == "training_pipeline_value" assert response.artifact_uri == "artifact_uri_value" @@ -822,13 +1060,15 @@ async def test_get_model_async_from_dict(): def test_get_model_field_headers(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = model_service.GetModelRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_model), "__call__") as call: @@ -842,18 +1082,23 @@ def test_get_model_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_get_model_field_headers_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = model_service.GetModelRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_model), "__call__") as call: @@ -867,11 +1112,16 @@ async def test_get_model_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_get_model_flattened(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_model), "__call__") as call: @@ -879,29 +1129,38 @@ def test_get_model_flattened(): call.return_value = model.Model() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_model(name="name_value",) + client.get_model( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_model_flattened_error(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.get_model( - model_service.GetModelRequest(), name="name_value", + model_service.GetModelRequest(), + name="name_value", ) @pytest.mark.asyncio async def test_get_model_flattened_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_model), "__call__") as call: @@ -911,32 +1170,45 @@ async def test_get_model_flattened_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(model.Model()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_model(name="name_value",) + response = await client.get_model( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio async def test_get_model_flattened_error_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.get_model( - model_service.GetModelRequest(), name="name_value", + model_service.GetModelRequest(), + name="name_value", ) -def test_list_models( - transport: str = "grpc", request_type=model_service.ListModelsRequest -): +@pytest.mark.parametrize( + "request_type", + [ + model_service.ListModelsRequest, + dict, + ], +) +def test_list_models(request_type, transport: str = "grpc"): client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -961,15 +1233,12 @@ def test_list_models( assert response.next_page_token == "next_page_token_value" -def test_list_models_from_dict(): - test_list_models(request_type=dict) - - def test_list_models_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -985,7 +1254,8 @@ async def test_list_models_async( transport: str = "grpc_asyncio", request_type=model_service.ListModelsRequest ): client = ModelServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -996,7 +1266,9 @@ async def test_list_models_async( with mock.patch.object(type(client.transport.list_models), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - model_service.ListModelsResponse(next_page_token="next_page_token_value",) + model_service.ListModelsResponse( + next_page_token="next_page_token_value", + ) ) response = await client.list_models(request) @@ -1016,13 +1288,15 @@ async def test_list_models_async_from_dict(): def test_list_models_field_headers(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = model_service.ListModelsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_models), "__call__") as call: @@ -1036,18 +1310,23 @@ def test_list_models_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio async def test_list_models_field_headers_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = model_service.ListModelsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_models), "__call__") as call: @@ -1063,11 +1342,16 @@ async def test_list_models_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_models_flattened(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_models), "__call__") as call: @@ -1075,29 +1359,38 @@ def test_list_models_flattened(): call.return_value = model_service.ListModelsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_models(parent="parent_value",) + client.list_models( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_models_flattened_error(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.list_models( - model_service.ListModelsRequest(), parent="parent_value", + model_service.ListModelsRequest(), + parent="parent_value", ) @pytest.mark.asyncio async def test_list_models_flattened_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_models), "__call__") as call: @@ -1109,43 +1402,68 @@ async def test_list_models_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_models(parent="parent_value",) + response = await client.list_models( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio async def test_list_models_flattened_error_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): await client.list_models( - model_service.ListModelsRequest(), parent="parent_value", + model_service.ListModelsRequest(), + parent="parent_value", ) -def test_list_models_pager(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_models_pager(transport_name: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_models), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( model_service.ListModelsResponse( - models=[model.Model(), model.Model(), model.Model(),], + models=[ + model.Model(), + model.Model(), + model.Model(), + ], next_page_token="abc", ), - model_service.ListModelsResponse(models=[], next_page_token="def",), model_service.ListModelsResponse( - models=[model.Model(),], next_page_token="ghi", + models=[], + next_page_token="def", + ), + model_service.ListModelsResponse( + models=[ + model.Model(), + ], + next_page_token="ghi", + ), + model_service.ListModelsResponse( + models=[ + model.Model(), + model.Model(), + ], ), - model_service.ListModelsResponse(models=[model.Model(), model.Model(),],), RuntimeError, ) @@ -1157,27 +1475,45 @@ def test_list_models_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all(isinstance(i, model.Model) for i in results) -def test_list_models_pages(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_models_pages(transport_name: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_models), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( model_service.ListModelsResponse( - models=[model.Model(), model.Model(), model.Model(),], + models=[ + model.Model(), + model.Model(), + model.Model(), + ], next_page_token="abc", ), - model_service.ListModelsResponse(models=[], next_page_token="def",), model_service.ListModelsResponse( - models=[model.Model(),], next_page_token="ghi", + models=[], + next_page_token="def", + ), + model_service.ListModelsResponse( + models=[ + model.Model(), + ], + next_page_token="ghi", + ), + model_service.ListModelsResponse( + models=[ + model.Model(), + model.Model(), + ], ), - model_service.ListModelsResponse(models=[model.Model(), model.Model(),],), RuntimeError, ) pages = list(client.list_models(request={}).pages) @@ -1187,7 +1523,9 @@ def test_list_models_pages(): @pytest.mark.asyncio async def test_list_models_async_pager(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1196,20 +1534,37 @@ async def test_list_models_async_pager(): # Set the response to a series of pages. call.side_effect = ( model_service.ListModelsResponse( - models=[model.Model(), model.Model(), model.Model(),], + models=[ + model.Model(), + model.Model(), + model.Model(), + ], next_page_token="abc", ), - model_service.ListModelsResponse(models=[], next_page_token="def",), model_service.ListModelsResponse( - models=[model.Model(),], next_page_token="ghi", + models=[], + next_page_token="def", + ), + model_service.ListModelsResponse( + models=[ + model.Model(), + ], + next_page_token="ghi", + ), + model_service.ListModelsResponse( + models=[ + model.Model(), + model.Model(), + ], ), - model_service.ListModelsResponse(models=[model.Model(), model.Model(),],), RuntimeError, ) - async_pager = await client.list_models(request={},) + async_pager = await client.list_models( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -1218,7 +1573,9 @@ async def test_list_models_async_pager(): @pytest.mark.asyncio async def test_list_models_async_pages(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1227,28 +1584,51 @@ async def test_list_models_async_pages(): # Set the response to a series of pages. call.side_effect = ( model_service.ListModelsResponse( - models=[model.Model(), model.Model(), model.Model(),], + models=[ + model.Model(), + model.Model(), + model.Model(), + ], next_page_token="abc", ), - model_service.ListModelsResponse(models=[], next_page_token="def",), model_service.ListModelsResponse( - models=[model.Model(),], next_page_token="ghi", + models=[], + next_page_token="def", ), - model_service.ListModelsResponse(models=[model.Model(), model.Model(),],), - RuntimeError, + model_service.ListModelsResponse( + models=[ + model.Model(), + ], + next_page_token="ghi", + ), + model_service.ListModelsResponse( + models=[ + model.Model(), + model.Model(), + ], + ), + RuntimeError, ) pages = [] - async for page_ in (await client.list_models(request={})).pages: + async for page_ in ( + await client.list_models(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_update_model( - transport: str = "grpc", request_type=model_service.UpdateModelRequest -): +@pytest.mark.parametrize( + "request_type", + [ + model_service.ListModelVersionsRequest, + dict, + ], +) +def test_list_model_versions(request_type, transport: str = "grpc"): client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1256,74 +1636,50 @@ def test_update_model( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_model), "__call__") as call: + with mock.patch.object( + type(client.transport.list_model_versions), "__call__" + ) as call: # Designate an appropriate return value for the call. - call.return_value = gca_model.Model( - name="name_value", - display_name="display_name_value", - description="description_value", - metadata_schema_uri="metadata_schema_uri_value", - training_pipeline="training_pipeline_value", - artifact_uri="artifact_uri_value", - supported_deployment_resources_types=[ - gca_model.Model.DeploymentResourcesType.DEDICATED_RESOURCES - ], - supported_input_storage_formats=["supported_input_storage_formats_value"], - supported_output_storage_formats=["supported_output_storage_formats_value"], - etag="etag_value", + call.return_value = model_service.ListModelVersionsResponse( + next_page_token="next_page_token_value", ) - response = client.update_model(request) + response = client.list_model_versions(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == model_service.UpdateModelRequest() + assert args[0] == model_service.ListModelVersionsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gca_model.Model) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.description == "description_value" - assert response.metadata_schema_uri == "metadata_schema_uri_value" - assert response.training_pipeline == "training_pipeline_value" - assert response.artifact_uri == "artifact_uri_value" - assert response.supported_deployment_resources_types == [ - gca_model.Model.DeploymentResourcesType.DEDICATED_RESOURCES - ] - assert response.supported_input_storage_formats == [ - "supported_input_storage_formats_value" - ] - assert response.supported_output_storage_formats == [ - "supported_output_storage_formats_value" - ] - assert response.etag == "etag_value" - - -def test_update_model_from_dict(): - test_update_model(request_type=dict) + assert isinstance(response, pagers.ListModelVersionsPager) + assert response.next_page_token == "next_page_token_value" -def test_update_model_empty_call(): +def test_list_model_versions_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_model), "__call__") as call: - client.update_model() + with mock.patch.object( + type(client.transport.list_model_versions), "__call__" + ) as call: + client.list_model_versions() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == model_service.UpdateModelRequest() + assert args[0] == model_service.ListModelVersionsRequest() @pytest.mark.asyncio -async def test_update_model_async( - transport: str = "grpc_asyncio", request_type=model_service.UpdateModelRequest +async def test_list_model_versions_async( + transport: str = "grpc_asyncio", request_type=model_service.ListModelVersionsRequest ): client = ModelServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1331,73 +1687,49 @@ async def test_update_model_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_model), "__call__") as call: + with mock.patch.object( + type(client.transport.list_model_versions), "__call__" + ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gca_model.Model( - name="name_value", - display_name="display_name_value", - description="description_value", - metadata_schema_uri="metadata_schema_uri_value", - training_pipeline="training_pipeline_value", - artifact_uri="artifact_uri_value", - supported_deployment_resources_types=[ - gca_model.Model.DeploymentResourcesType.DEDICATED_RESOURCES - ], - supported_input_storage_formats=[ - "supported_input_storage_formats_value" - ], - supported_output_storage_formats=[ - "supported_output_storage_formats_value" - ], - etag="etag_value", + model_service.ListModelVersionsResponse( + next_page_token="next_page_token_value", ) ) - response = await client.update_model(request) + response = await client.list_model_versions(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == model_service.UpdateModelRequest() + assert args[0] == model_service.ListModelVersionsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gca_model.Model) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.description == "description_value" - assert response.metadata_schema_uri == "metadata_schema_uri_value" - assert response.training_pipeline == "training_pipeline_value" - assert response.artifact_uri == "artifact_uri_value" - assert response.supported_deployment_resources_types == [ - gca_model.Model.DeploymentResourcesType.DEDICATED_RESOURCES - ] - assert response.supported_input_storage_formats == [ - "supported_input_storage_formats_value" - ] - assert response.supported_output_storage_formats == [ - "supported_output_storage_formats_value" - ] - assert response.etag == "etag_value" + assert isinstance(response, pagers.ListModelVersionsAsyncPager) + assert response.next_page_token == "next_page_token_value" @pytest.mark.asyncio -async def test_update_model_async_from_dict(): - await test_update_model_async(request_type=dict) +async def test_list_model_versions_async_from_dict(): + await test_list_model_versions_async(request_type=dict) -def test_update_model_field_headers(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_list_model_versions_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = model_service.UpdateModelRequest() + request = model_service.ListModelVersionsRequest() - request.model.name = "model.name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_model), "__call__") as call: - call.return_value = gca_model.Model() - client.update_model(request) + with mock.patch.object( + type(client.transport.list_model_versions), "__call__" + ) as call: + call.return_value = model_service.ListModelVersionsResponse() + client.list_model_versions(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -1406,23 +1738,32 @@ def test_update_model_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "model.name=model.name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_update_model_field_headers_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_list_model_versions_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = model_service.UpdateModelRequest() + request = model_service.ListModelVersionsRequest() - request.model.name = "model.name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_model), "__call__") as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gca_model.Model()) - await client.update_model(request) + with mock.patch.object( + type(client.transport.list_model_versions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + model_service.ListModelVersionsResponse() + ) + await client.list_model_versions(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -1431,175 +1772,466 @@ async def test_update_model_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "model.name=model.name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] -def test_update_model_flattened(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_list_model_versions_flattened(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_model), "__call__") as call: + with mock.patch.object( + type(client.transport.list_model_versions), "__call__" + ) as call: # Designate an appropriate return value for the call. - call.return_value = gca_model.Model() + call.return_value = model_service.ListModelVersionsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.update_model( - model=gca_model.Model(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + client.list_model_versions( + name="name_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].model == gca_model.Model(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val -def test_update_model_flattened_error(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_list_model_versions_flattened_error(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.update_model( - model_service.UpdateModelRequest(), - model=gca_model.Model(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + client.list_model_versions( + model_service.ListModelVersionsRequest(), + name="name_value", ) @pytest.mark.asyncio -async def test_update_model_flattened_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_list_model_versions_flattened_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.update_model), "__call__") as call: + with mock.patch.object( + type(client.transport.list_model_versions), "__call__" + ) as call: # Designate an appropriate return value for the call. - call.return_value = gca_model.Model() + call.return_value = model_service.ListModelVersionsResponse() - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gca_model.Model()) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + model_service.ListModelVersionsResponse() + ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.update_model( - model=gca_model.Model(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + response = await client.list_model_versions( + name="name_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].model == gca_model.Model(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio -async def test_update_model_flattened_error_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_list_model_versions_flattened_error_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.update_model( - model_service.UpdateModelRequest(), - model=gca_model.Model(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + await client.list_model_versions( + model_service.ListModelVersionsRequest(), + name="name_value", ) -def test_delete_model( - transport: str = "grpc", request_type=model_service.DeleteModelRequest -): +def test_list_model_versions_pager(transport_name: str = "grpc"): client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_model), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.delete_model(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == model_service.DeleteModelRequest() + with mock.patch.object( + type(client.transport.list_model_versions), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + model_service.ListModelVersionsResponse( + models=[ + model.Model(), + model.Model(), + model.Model(), + ], + next_page_token="abc", + ), + model_service.ListModelVersionsResponse( + models=[], + next_page_token="def", + ), + model_service.ListModelVersionsResponse( + models=[ + model.Model(), + ], + next_page_token="ghi", + ), + model_service.ListModelVersionsResponse( + models=[ + model.Model(), + model.Model(), + ], + ), + RuntimeError, + ) - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", ""),)), + ) + pager = client.list_model_versions(request={}) + assert pager._metadata == metadata -def test_delete_model_from_dict(): - test_delete_model(request_type=dict) + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, model.Model) for i in results) -def test_delete_model_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. +def test_list_model_versions_pages(transport_name: str = "grpc"): client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_model), "__call__") as call: - client.delete_model() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == model_service.DeleteModelRequest() + with mock.patch.object( + type(client.transport.list_model_versions), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + model_service.ListModelVersionsResponse( + models=[ + model.Model(), + model.Model(), + model.Model(), + ], + next_page_token="abc", + ), + model_service.ListModelVersionsResponse( + models=[], + next_page_token="def", + ), + model_service.ListModelVersionsResponse( + models=[ + model.Model(), + ], + next_page_token="ghi", + ), + model_service.ListModelVersionsResponse( + models=[ + model.Model(), + model.Model(), + ], + ), + RuntimeError, + ) + pages = list(client.list_model_versions(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token @pytest.mark.asyncio -async def test_delete_model_async( - transport: str = "grpc_asyncio", request_type=model_service.DeleteModelRequest -): +async def test_list_model_versions_async_pager(): client = ModelServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials, ) - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_model), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") - ) - response = await client.delete_model(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == model_service.DeleteModelRequest() + with mock.patch.object( + type(client.transport.list_model_versions), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + model_service.ListModelVersionsResponse( + models=[ + model.Model(), + model.Model(), + model.Model(), + ], + next_page_token="abc", + ), + model_service.ListModelVersionsResponse( + models=[], + next_page_token="def", + ), + model_service.ListModelVersionsResponse( + models=[ + model.Model(), + ], + next_page_token="ghi", + ), + model_service.ListModelVersionsResponse( + models=[ + model.Model(), + model.Model(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_model_versions( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, model.Model) for i in responses) + + +@pytest.mark.asyncio +async def test_list_model_versions_async_pages(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_versions), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + model_service.ListModelVersionsResponse( + models=[ + model.Model(), + model.Model(), + model.Model(), + ], + next_page_token="abc", + ), + model_service.ListModelVersionsResponse( + models=[], + next_page_token="def", + ), + model_service.ListModelVersionsResponse( + models=[ + model.Model(), + ], + next_page_token="ghi", + ), + model_service.ListModelVersionsResponse( + models=[ + model.Model(), + model.Model(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.list_model_versions(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize( + "request_type", + [ + model_service.UpdateModelRequest, + dict, + ], +) +def test_update_model(request_type, transport: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_model), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = gca_model.Model( + name="name_value", + version_id="version_id_value", + version_aliases=["version_aliases_value"], + display_name="display_name_value", + description="description_value", + version_description="version_description_value", + metadata_schema_uri="metadata_schema_uri_value", + training_pipeline="training_pipeline_value", + artifact_uri="artifact_uri_value", + supported_deployment_resources_types=[ + gca_model.Model.DeploymentResourcesType.DEDICATED_RESOURCES + ], + supported_input_storage_formats=["supported_input_storage_formats_value"], + supported_output_storage_formats=["supported_output_storage_formats_value"], + etag="etag_value", + ) + response = client.update_model(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.UpdateModelRequest() # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) + assert isinstance(response, gca_model.Model) + assert response.name == "name_value" + assert response.version_id == "version_id_value" + assert response.version_aliases == ["version_aliases_value"] + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.version_description == "version_description_value" + assert response.metadata_schema_uri == "metadata_schema_uri_value" + assert response.training_pipeline == "training_pipeline_value" + assert response.artifact_uri == "artifact_uri_value" + assert response.supported_deployment_resources_types == [ + gca_model.Model.DeploymentResourcesType.DEDICATED_RESOURCES + ] + assert response.supported_input_storage_formats == [ + "supported_input_storage_formats_value" + ] + assert response.supported_output_storage_formats == [ + "supported_output_storage_formats_value" + ] + assert response.etag == "etag_value" + + +def test_update_model_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_model), "__call__") as call: + client.update_model() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.UpdateModelRequest() @pytest.mark.asyncio -async def test_delete_model_async_from_dict(): - await test_delete_model_async(request_type=dict) +async def test_update_model_async( + transport: str = "grpc_asyncio", request_type=model_service.UpdateModelRequest +): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() -def test_delete_model_field_headers(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.update_model), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_model.Model( + name="name_value", + version_id="version_id_value", + version_aliases=["version_aliases_value"], + display_name="display_name_value", + description="description_value", + version_description="version_description_value", + metadata_schema_uri="metadata_schema_uri_value", + training_pipeline="training_pipeline_value", + artifact_uri="artifact_uri_value", + supported_deployment_resources_types=[ + gca_model.Model.DeploymentResourcesType.DEDICATED_RESOURCES + ], + supported_input_storage_formats=[ + "supported_input_storage_formats_value" + ], + supported_output_storage_formats=[ + "supported_output_storage_formats_value" + ], + etag="etag_value", + ) + ) + response = await client.update_model(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.UpdateModelRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_model.Model) + assert response.name == "name_value" + assert response.version_id == "version_id_value" + assert response.version_aliases == ["version_aliases_value"] + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.version_description == "version_description_value" + assert response.metadata_schema_uri == "metadata_schema_uri_value" + assert response.training_pipeline == "training_pipeline_value" + assert response.artifact_uri == "artifact_uri_value" + assert response.supported_deployment_resources_types == [ + gca_model.Model.DeploymentResourcesType.DEDICATED_RESOURCES + ] + assert response.supported_input_storage_formats == [ + "supported_input_storage_formats_value" + ] + assert response.supported_output_storage_formats == [ + "supported_output_storage_formats_value" + ] + assert response.etag == "etag_value" + + +@pytest.mark.asyncio +async def test_update_model_async_from_dict(): + await test_update_model_async(request_type=dict) + + +def test_update_model_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = model_service.DeleteModelRequest() + request = model_service.UpdateModelRequest() - request.name = "name/value" + request.model.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_model), "__call__") as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_model(request) + with mock.patch.object(type(client.transport.update_model), "__call__") as call: + call.return_value = gca_model.Model() + client.update_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -1608,25 +2240,28 @@ def test_delete_model_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "model.name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_delete_model_field_headers_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_update_model_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = model_service.DeleteModelRequest() + request = model_service.UpdateModelRequest() - request.name = "name/value" + request.model.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_model), "__call__") as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/op") - ) - await client.delete_model(request) + with mock.patch.object(type(client.transport.update_model), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gca_model.Model()) + await client.update_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -1635,78 +2270,113 @@ async def test_delete_model_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "model.name=name_value", + ) in kw["metadata"] -def test_delete_model_flattened(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_update_model_flattened(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_model), "__call__") as call: + with mock.patch.object(type(client.transport.update_model), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name="operations/op") + call.return_value = gca_model.Model() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_model(name="name_value",) + client.update_model( + model=gca_model.Model(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].model + mock_val = gca_model.Model(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val -def test_delete_model_flattened_error(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_update_model_flattened_error(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.delete_model( - model_service.DeleteModelRequest(), name="name_value", + client.update_model( + model_service.UpdateModelRequest(), + model=gca_model.Model(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @pytest.mark.asyncio -async def test_delete_model_flattened_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_update_model_flattened_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.delete_model), "__call__") as call: + with mock.patch.object(type(client.transport.update_model), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name="operations/op") + call.return_value = gca_model.Model() - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") - ) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(gca_model.Model()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_model(name="name_value",) - + response = await client.update_model( + model=gca_model.Model(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].model + mock_val = gca_model.Model(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val @pytest.mark.asyncio -async def test_delete_model_flattened_error_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_update_model_flattened_error_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.delete_model( - model_service.DeleteModelRequest(), name="name_value", + await client.update_model( + model_service.UpdateModelRequest(), + model=gca_model.Model(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) -def test_export_model( - transport: str = "grpc", request_type=model_service.ExportModelRequest -): +@pytest.mark.parametrize( + "request_type", + [ + model_service.UpdateExplanationDatasetRequest, + dict, + ], +) +def test_update_explanation_dataset(request_type, transport: str = "grpc"): client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1714,45 +2384,48 @@ def test_export_model( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.export_model), "__call__") as call: + with mock.patch.object( + type(client.transport.update_explanation_dataset), "__call__" + ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.export_model(request) + response = client.update_explanation_dataset(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == model_service.ExportModelRequest() + assert args[0] == model_service.UpdateExplanationDatasetRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) -def test_export_model_from_dict(): - test_export_model(request_type=dict) - - -def test_export_model_empty_call(): +def test_update_explanation_dataset_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.export_model), "__call__") as call: - client.export_model() + with mock.patch.object( + type(client.transport.update_explanation_dataset), "__call__" + ) as call: + client.update_explanation_dataset() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == model_service.ExportModelRequest() + assert args[0] == model_service.UpdateExplanationDatasetRequest() @pytest.mark.asyncio -async def test_export_model_async( - transport: str = "grpc_asyncio", request_type=model_service.ExportModelRequest +async def test_update_explanation_dataset_async( + transport: str = "grpc_asyncio", + request_type=model_service.UpdateExplanationDatasetRequest, ): client = ModelServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1760,40 +2433,46 @@ async def test_export_model_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.export_model), "__call__") as call: + with mock.patch.object( + type(client.transport.update_explanation_dataset), "__call__" + ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") ) - response = await client.export_model(request) + response = await client.update_explanation_dataset(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == model_service.ExportModelRequest() + assert args[0] == model_service.UpdateExplanationDatasetRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) @pytest.mark.asyncio -async def test_export_model_async_from_dict(): - await test_export_model_async(request_type=dict) +async def test_update_explanation_dataset_async_from_dict(): + await test_update_explanation_dataset_async(request_type=dict) -def test_export_model_field_headers(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_update_explanation_dataset_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = model_service.ExportModelRequest() + request = model_service.UpdateExplanationDatasetRequest() - request.name = "name/value" + request.model = "model_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.export_model), "__call__") as call: + with mock.patch.object( + type(client.transport.update_explanation_dataset), "__call__" + ) as call: call.return_value = operations_pb2.Operation(name="operations/op") - client.export_model(request) + client.update_explanation_dataset(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -1802,25 +2481,32 @@ def test_export_model_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "model=model_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_export_model_field_headers_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_update_explanation_dataset_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = model_service.ExportModelRequest() + request = model_service.UpdateExplanationDatasetRequest() - request.name = "name/value" + request.model = "model_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.export_model), "__call__") as call: + with mock.patch.object( + type(client.transport.update_explanation_dataset), "__call__" + ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) - await client.export_model(request) + await client.update_explanation_dataset(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -1829,56 +2515,62 @@ async def test_export_model_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "model=model_value", + ) in kw["metadata"] -def test_export_model_flattened(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_update_explanation_dataset_flattened(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.export_model), "__call__") as call: + with mock.patch.object( + type(client.transport.update_explanation_dataset), "__call__" + ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.export_model( - name="name_value", - output_config=model_service.ExportModelRequest.OutputConfig( - export_format_id="export_format_id_value" - ), + client.update_explanation_dataset( + model="model_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].output_config == model_service.ExportModelRequest.OutputConfig( - export_format_id="export_format_id_value" - ) + arg = args[0].model + mock_val = "model_value" + assert arg == mock_val -def test_export_model_flattened_error(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_update_explanation_dataset_flattened_error(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.export_model( - model_service.ExportModelRequest(), - name="name_value", - output_config=model_service.ExportModelRequest.OutputConfig( - export_format_id="export_format_id_value" - ), + client.update_explanation_dataset( + model_service.UpdateExplanationDatasetRequest(), + model="model_value", ) @pytest.mark.asyncio -async def test_export_model_flattened_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_update_explanation_dataset_flattened_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.export_model), "__call__") as call: + with mock.patch.object( + type(client.transport.update_explanation_dataset), "__call__" + ) as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -1887,44 +2579,45 @@ async def test_export_model_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.export_model( - name="name_value", - output_config=model_service.ExportModelRequest.OutputConfig( - export_format_id="export_format_id_value" - ), + response = await client.update_explanation_dataset( + model="model_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" - assert args[0].output_config == model_service.ExportModelRequest.OutputConfig( - export_format_id="export_format_id_value" - ) + arg = args[0].model + mock_val = "model_value" + assert arg == mock_val @pytest.mark.asyncio -async def test_export_model_flattened_error_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_update_explanation_dataset_flattened_error_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.export_model( - model_service.ExportModelRequest(), - name="name_value", - output_config=model_service.ExportModelRequest.OutputConfig( - export_format_id="export_format_id_value" - ), + await client.update_explanation_dataset( + model_service.UpdateExplanationDatasetRequest(), + model="model_value", ) -def test_get_model_evaluation( - transport: str = "grpc", request_type=model_service.GetModelEvaluationRequest -): +@pytest.mark.parametrize( + "request_type", + [ + model_service.DeleteModelRequest, + dict, + ], +) +def test_delete_model(request_type, transport: str = "grpc"): client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1932,57 +2625,43 @@ def test_get_model_evaluation( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_model_evaluation), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_model), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = model_evaluation.ModelEvaluation( - name="name_value", - metrics_schema_uri="metrics_schema_uri_value", - slice_dimensions=["slice_dimensions_value"], - ) - response = client.get_model_evaluation(request) + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.delete_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == model_service.GetModelEvaluationRequest() + assert args[0] == model_service.DeleteModelRequest() # Establish that the response is the type that we expect. - assert isinstance(response, model_evaluation.ModelEvaluation) - assert response.name == "name_value" - assert response.metrics_schema_uri == "metrics_schema_uri_value" - assert response.slice_dimensions == ["slice_dimensions_value"] - - -def test_get_model_evaluation_from_dict(): - test_get_model_evaluation(request_type=dict) + assert isinstance(response, future.Future) -def test_get_model_evaluation_empty_call(): +def test_delete_model_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_model_evaluation), "__call__" - ) as call: - client.get_model_evaluation() + with mock.patch.object(type(client.transport.delete_model), "__call__") as call: + client.delete_model() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == model_service.GetModelEvaluationRequest() + assert args[0] == model_service.DeleteModelRequest() @pytest.mark.asyncio -async def test_get_model_evaluation_async( - transport: str = "grpc_asyncio", - request_type=model_service.GetModelEvaluationRequest, +async def test_delete_model_async( + transport: str = "grpc_asyncio", request_type=model_service.DeleteModelRequest ): client = ModelServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1990,51 +2669,42 @@ async def test_get_model_evaluation_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_model_evaluation), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_model), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - model_evaluation.ModelEvaluation( - name="name_value", - metrics_schema_uri="metrics_schema_uri_value", - slice_dimensions=["slice_dimensions_value"], - ) + operations_pb2.Operation(name="operations/spam") ) - response = await client.get_model_evaluation(request) + response = await client.delete_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == model_service.GetModelEvaluationRequest() + assert args[0] == model_service.DeleteModelRequest() # Establish that the response is the type that we expect. - assert isinstance(response, model_evaluation.ModelEvaluation) - assert response.name == "name_value" - assert response.metrics_schema_uri == "metrics_schema_uri_value" - assert response.slice_dimensions == ["slice_dimensions_value"] + assert isinstance(response, future.Future) @pytest.mark.asyncio -async def test_get_model_evaluation_async_from_dict(): - await test_get_model_evaluation_async(request_type=dict) +async def test_delete_model_async_from_dict(): + await test_delete_model_async(request_type=dict) -def test_get_model_evaluation_field_headers(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_delete_model_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = model_service.GetModelEvaluationRequest() + request = model_service.DeleteModelRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_model_evaluation), "__call__" - ) as call: - call.return_value = model_evaluation.ModelEvaluation() - client.get_model_evaluation(request) + with mock.patch.object(type(client.transport.delete_model), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -2043,27 +2713,30 @@ def test_get_model_evaluation_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_get_model_evaluation_field_headers_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_delete_model_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = model_service.GetModelEvaluationRequest() + request = model_service.DeleteModelRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_model_evaluation), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_model), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - model_evaluation.ModelEvaluation() + operations_pb2.Operation(name="operations/op") ) - await client.get_model_evaluation(request) + await client.delete_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -2072,82 +2745,105 @@ async def test_get_model_evaluation_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] -def test_get_model_evaluation_flattened(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_delete_model_flattened(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_model_evaluation), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_model), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = model_evaluation.ModelEvaluation() + call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_model_evaluation(name="name_value",) + client.delete_model( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val -def test_get_model_evaluation_flattened_error(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_delete_model_flattened_error(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_model_evaluation( - model_service.GetModelEvaluationRequest(), name="name_value", + client.delete_model( + model_service.DeleteModelRequest(), + name="name_value", ) @pytest.mark.asyncio -async def test_get_model_evaluation_flattened_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_delete_model_flattened_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_model_evaluation), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_model), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = model_evaluation.ModelEvaluation() + call.return_value = operations_pb2.Operation(name="operations/op") call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - model_evaluation.ModelEvaluation() + operations_pb2.Operation(name="operations/spam") ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_model_evaluation(name="name_value",) + response = await client.delete_model( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio -async def test_get_model_evaluation_flattened_error_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_delete_model_flattened_error_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.get_model_evaluation( - model_service.GetModelEvaluationRequest(), name="name_value", + await client.delete_model( + model_service.DeleteModelRequest(), + name="name_value", ) -def test_list_model_evaluations( - transport: str = "grpc", request_type=model_service.ListModelEvaluationsRequest -): +@pytest.mark.parametrize( + "request_type", + [ + model_service.DeleteModelVersionRequest, + dict, + ], +) +def test_delete_model_version(request_type, transport: str = "grpc"): client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2156,52 +2852,47 @@ def test_list_model_evaluations( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_model_evaluations), "__call__" + type(client.transport.delete_model_version), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = model_service.ListModelEvaluationsResponse( - next_page_token="next_page_token_value", - ) - response = client.list_model_evaluations(request) + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.delete_model_version(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == model_service.ListModelEvaluationsRequest() + assert args[0] == model_service.DeleteModelVersionRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListModelEvaluationsPager) - assert response.next_page_token == "next_page_token_value" - - -def test_list_model_evaluations_from_dict(): - test_list_model_evaluations(request_type=dict) + assert isinstance(response, future.Future) -def test_list_model_evaluations_empty_call(): +def test_delete_model_version_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_model_evaluations), "__call__" + type(client.transport.delete_model_version), "__call__" ) as call: - client.list_model_evaluations() + client.delete_model_version() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == model_service.ListModelEvaluationsRequest() + assert args[0] == model_service.DeleteModelVersionRequest() @pytest.mark.asyncio -async def test_list_model_evaluations_async( +async def test_delete_model_version_async( transport: str = "grpc_asyncio", - request_type=model_service.ListModelEvaluationsRequest, + request_type=model_service.DeleteModelVersionRequest, ): client = ModelServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2210,46 +2901,45 @@ async def test_list_model_evaluations_async( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_model_evaluations), "__call__" + type(client.transport.delete_model_version), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - model_service.ListModelEvaluationsResponse( - next_page_token="next_page_token_value", - ) + operations_pb2.Operation(name="operations/spam") ) - response = await client.list_model_evaluations(request) + response = await client.delete_model_version(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == model_service.ListModelEvaluationsRequest() + assert args[0] == model_service.DeleteModelVersionRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListModelEvaluationsAsyncPager) - assert response.next_page_token == "next_page_token_value" + assert isinstance(response, future.Future) @pytest.mark.asyncio -async def test_list_model_evaluations_async_from_dict(): - await test_list_model_evaluations_async(request_type=dict) +async def test_delete_model_version_async_from_dict(): + await test_delete_model_version_async(request_type=dict) -def test_list_model_evaluations_field_headers(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_delete_model_version_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = model_service.ListModelEvaluationsRequest() + request = model_service.DeleteModelVersionRequest() - request.parent = "parent/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_model_evaluations), "__call__" + type(client.transport.delete_model_version), "__call__" ) as call: - call.return_value = model_service.ListModelEvaluationsResponse() - client.list_model_evaluations(request) + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_model_version(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -2258,27 +2948,32 @@ def test_list_model_evaluations_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_list_model_evaluations_field_headers_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_delete_model_version_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = model_service.ListModelEvaluationsRequest() + request = model_service.DeleteModelVersionRequest() - request.parent = "parent/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_model_evaluations), "__call__" + type(client.transport.delete_model_version), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - model_service.ListModelEvaluationsResponse() + operations_pb2.Operation(name="operations/op") ) - await client.list_model_evaluations(request) + await client.delete_model_version(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -2287,356 +2982,279 @@ async def test_list_model_evaluations_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] -def test_list_model_evaluations_flattened(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_delete_model_version_flattened(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_model_evaluations), "__call__" + type(client.transport.delete_model_version), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = model_service.ListModelEvaluationsResponse() + call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_model_evaluations(parent="parent_value",) + client.delete_model_version( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val -def test_list_model_evaluations_flattened_error(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_delete_model_version_flattened_error(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_model_evaluations( - model_service.ListModelEvaluationsRequest(), parent="parent_value", + client.delete_model_version( + model_service.DeleteModelVersionRequest(), + name="name_value", ) @pytest.mark.asyncio -async def test_list_model_evaluations_flattened_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_delete_model_version_flattened_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_model_evaluations), "__call__" + type(client.transport.delete_model_version), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = model_service.ListModelEvaluationsResponse() + call.return_value = operations_pb2.Operation(name="operations/op") call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - model_service.ListModelEvaluationsResponse() + operations_pb2.Operation(name="operations/spam") ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_model_evaluations(parent="parent_value",) + response = await client.delete_model_version( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio -async def test_list_model_evaluations_flattened_error_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_delete_model_version_flattened_error_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.list_model_evaluations( - model_service.ListModelEvaluationsRequest(), parent="parent_value", + await client.delete_model_version( + model_service.DeleteModelVersionRequest(), + name="name_value", ) -def test_list_model_evaluations_pager(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials,) +@pytest.mark.parametrize( + "request_type", + [ + model_service.MergeVersionAliasesRequest, + dict, + ], +) +def test_merge_version_aliases(request_type, transport: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_model_evaluations), "__call__" + type(client.transport.merge_version_aliases), "__call__" ) as call: - # Set the response to a series of pages. - call.side_effect = ( - model_service.ListModelEvaluationsResponse( - model_evaluations=[ - model_evaluation.ModelEvaluation(), - model_evaluation.ModelEvaluation(), - model_evaluation.ModelEvaluation(), - ], - next_page_token="abc", - ), - model_service.ListModelEvaluationsResponse( - model_evaluations=[], next_page_token="def", - ), - model_service.ListModelEvaluationsResponse( - model_evaluations=[model_evaluation.ModelEvaluation(),], - next_page_token="ghi", - ), - model_service.ListModelEvaluationsResponse( - model_evaluations=[ - model_evaluation.ModelEvaluation(), - model_evaluation.ModelEvaluation(), - ], - ), - RuntimeError, - ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + # Designate an appropriate return value for the call. + call.return_value = model.Model( + name="name_value", + version_id="version_id_value", + version_aliases=["version_aliases_value"], + display_name="display_name_value", + description="description_value", + version_description="version_description_value", + metadata_schema_uri="metadata_schema_uri_value", + training_pipeline="training_pipeline_value", + artifact_uri="artifact_uri_value", + supported_deployment_resources_types=[ + model.Model.DeploymentResourcesType.DEDICATED_RESOURCES + ], + supported_input_storage_formats=["supported_input_storage_formats_value"], + supported_output_storage_formats=["supported_output_storage_formats_value"], + etag="etag_value", ) - pager = client.list_model_evaluations(request={}) + response = client.merge_version_aliases(request) - assert pager._metadata == metadata + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.MergeVersionAliasesRequest() - results = [i for i in pager] - assert len(results) == 6 - assert all(isinstance(i, model_evaluation.ModelEvaluation) for i in results) + # Establish that the response is the type that we expect. + assert isinstance(response, model.Model) + assert response.name == "name_value" + assert response.version_id == "version_id_value" + assert response.version_aliases == ["version_aliases_value"] + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.version_description == "version_description_value" + assert response.metadata_schema_uri == "metadata_schema_uri_value" + assert response.training_pipeline == "training_pipeline_value" + assert response.artifact_uri == "artifact_uri_value" + assert response.supported_deployment_resources_types == [ + model.Model.DeploymentResourcesType.DEDICATED_RESOURCES + ] + assert response.supported_input_storage_formats == [ + "supported_input_storage_formats_value" + ] + assert response.supported_output_storage_formats == [ + "supported_output_storage_formats_value" + ] + assert response.etag == "etag_value" -def test_list_model_evaluations_pages(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_merge_version_aliases_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_model_evaluations), "__call__" + type(client.transport.merge_version_aliases), "__call__" ) as call: - # Set the response to a series of pages. - call.side_effect = ( - model_service.ListModelEvaluationsResponse( - model_evaluations=[ - model_evaluation.ModelEvaluation(), - model_evaluation.ModelEvaluation(), - model_evaluation.ModelEvaluation(), - ], - next_page_token="abc", - ), - model_service.ListModelEvaluationsResponse( - model_evaluations=[], next_page_token="def", - ), - model_service.ListModelEvaluationsResponse( - model_evaluations=[model_evaluation.ModelEvaluation(),], - next_page_token="ghi", - ), - model_service.ListModelEvaluationsResponse( - model_evaluations=[ - model_evaluation.ModelEvaluation(), - model_evaluation.ModelEvaluation(), - ], - ), - RuntimeError, - ) - pages = list(client.list_model_evaluations(request={}).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token + client.merge_version_aliases() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.MergeVersionAliasesRequest() @pytest.mark.asyncio -async def test_list_model_evaluations_async_pager(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) +async def test_merge_version_aliases_async( + transport: str = "grpc_asyncio", + request_type=model_service.MergeVersionAliasesRequest, +): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_model_evaluations), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.merge_version_aliases), "__call__" ) as call: - # Set the response to a series of pages. - call.side_effect = ( - model_service.ListModelEvaluationsResponse( - model_evaluations=[ - model_evaluation.ModelEvaluation(), - model_evaluation.ModelEvaluation(), - model_evaluation.ModelEvaluation(), + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + model.Model( + name="name_value", + version_id="version_id_value", + version_aliases=["version_aliases_value"], + display_name="display_name_value", + description="description_value", + version_description="version_description_value", + metadata_schema_uri="metadata_schema_uri_value", + training_pipeline="training_pipeline_value", + artifact_uri="artifact_uri_value", + supported_deployment_resources_types=[ + model.Model.DeploymentResourcesType.DEDICATED_RESOURCES ], - next_page_token="abc", - ), - model_service.ListModelEvaluationsResponse( - model_evaluations=[], next_page_token="def", - ), - model_service.ListModelEvaluationsResponse( - model_evaluations=[model_evaluation.ModelEvaluation(),], - next_page_token="ghi", - ), - model_service.ListModelEvaluationsResponse( - model_evaluations=[ - model_evaluation.ModelEvaluation(), - model_evaluation.ModelEvaluation(), + supported_input_storage_formats=[ + "supported_input_storage_formats_value" ], - ), - RuntimeError, + supported_output_storage_formats=[ + "supported_output_storage_formats_value" + ], + etag="etag_value", + ) ) - async_pager = await client.list_model_evaluations(request={},) - assert async_pager.next_page_token == "abc" - responses = [] - async for response in async_pager: - responses.append(response) - - assert len(responses) == 6 - assert all(isinstance(i, model_evaluation.ModelEvaluation) for i in responses) - - -@pytest.mark.asyncio -async def test_list_model_evaluations_async_pages(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_model_evaluations), - "__call__", - new_callable=mock.AsyncMock, - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - model_service.ListModelEvaluationsResponse( - model_evaluations=[ - model_evaluation.ModelEvaluation(), - model_evaluation.ModelEvaluation(), - model_evaluation.ModelEvaluation(), - ], - next_page_token="abc", - ), - model_service.ListModelEvaluationsResponse( - model_evaluations=[], next_page_token="def", - ), - model_service.ListModelEvaluationsResponse( - model_evaluations=[model_evaluation.ModelEvaluation(),], - next_page_token="ghi", - ), - model_service.ListModelEvaluationsResponse( - model_evaluations=[ - model_evaluation.ModelEvaluation(), - model_evaluation.ModelEvaluation(), - ], - ), - RuntimeError, - ) - pages = [] - async for page_ in (await client.list_model_evaluations(request={})).pages: - pages.append(page_) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token - - -def test_get_model_evaluation_slice( - transport: str = "grpc", request_type=model_service.GetModelEvaluationSliceRequest -): - client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_model_evaluation_slice), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = model_evaluation_slice.ModelEvaluationSlice( - name="name_value", metrics_schema_uri="metrics_schema_uri_value", - ) - response = client.get_model_evaluation_slice(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == model_service.GetModelEvaluationSliceRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, model_evaluation_slice.ModelEvaluationSlice) - assert response.name == "name_value" - assert response.metrics_schema_uri == "metrics_schema_uri_value" - - -def test_get_model_evaluation_slice_from_dict(): - test_get_model_evaluation_slice(request_type=dict) - - -def test_get_model_evaluation_slice_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_model_evaluation_slice), "__call__" - ) as call: - client.get_model_evaluation_slice() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == model_service.GetModelEvaluationSliceRequest() - - -@pytest.mark.asyncio -async def test_get_model_evaluation_slice_async( - transport: str = "grpc_asyncio", - request_type=model_service.GetModelEvaluationSliceRequest, -): - client = ModelServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.get_model_evaluation_slice), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - model_evaluation_slice.ModelEvaluationSlice( - name="name_value", metrics_schema_uri="metrics_schema_uri_value", - ) - ) - response = await client.get_model_evaluation_slice(request) + response = await client.merge_version_aliases(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == model_service.GetModelEvaluationSliceRequest() + assert args[0] == model_service.MergeVersionAliasesRequest() # Establish that the response is the type that we expect. - assert isinstance(response, model_evaluation_slice.ModelEvaluationSlice) + assert isinstance(response, model.Model) assert response.name == "name_value" - assert response.metrics_schema_uri == "metrics_schema_uri_value" + assert response.version_id == "version_id_value" + assert response.version_aliases == ["version_aliases_value"] + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.version_description == "version_description_value" + assert response.metadata_schema_uri == "metadata_schema_uri_value" + assert response.training_pipeline == "training_pipeline_value" + assert response.artifact_uri == "artifact_uri_value" + assert response.supported_deployment_resources_types == [ + model.Model.DeploymentResourcesType.DEDICATED_RESOURCES + ] + assert response.supported_input_storage_formats == [ + "supported_input_storage_formats_value" + ] + assert response.supported_output_storage_formats == [ + "supported_output_storage_formats_value" + ] + assert response.etag == "etag_value" @pytest.mark.asyncio -async def test_get_model_evaluation_slice_async_from_dict(): - await test_get_model_evaluation_slice_async(request_type=dict) +async def test_merge_version_aliases_async_from_dict(): + await test_merge_version_aliases_async(request_type=dict) -def test_get_model_evaluation_slice_field_headers(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_merge_version_aliases_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = model_service.GetModelEvaluationSliceRequest() + request = model_service.MergeVersionAliasesRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_model_evaluation_slice), "__call__" + type(client.transport.merge_version_aliases), "__call__" ) as call: - call.return_value = model_evaluation_slice.ModelEvaluationSlice() - client.get_model_evaluation_slice(request) + call.return_value = model.Model() + client.merge_version_aliases(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -2645,27 +3263,30 @@ def test_get_model_evaluation_slice_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_get_model_evaluation_slice_field_headers_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_merge_version_aliases_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = model_service.GetModelEvaluationSliceRequest() + request = model_service.MergeVersionAliasesRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_model_evaluation_slice), "__call__" + type(client.transport.merge_version_aliases), "__call__" ) as call: - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - model_evaluation_slice.ModelEvaluationSlice() - ) - await client.get_model_evaluation_slice(request) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(model.Model()) + await client.merge_version_aliases(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -2674,82 +3295,117 @@ async def test_get_model_evaluation_slice_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] -def test_get_model_evaluation_slice_flattened(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_merge_version_aliases_flattened(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_model_evaluation_slice), "__call__" + type(client.transport.merge_version_aliases), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = model_evaluation_slice.ModelEvaluationSlice() + call.return_value = model.Model() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_model_evaluation_slice(name="name_value",) + client.merge_version_aliases( + name="name_value", + version_aliases=["version_aliases_value"], + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].version_aliases + mock_val = ["version_aliases_value"] + assert arg == mock_val -def test_get_model_evaluation_slice_flattened_error(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_merge_version_aliases_flattened_error(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_model_evaluation_slice( - model_service.GetModelEvaluationSliceRequest(), name="name_value", + client.merge_version_aliases( + model_service.MergeVersionAliasesRequest(), + name="name_value", + version_aliases=["version_aliases_value"], ) @pytest.mark.asyncio -async def test_get_model_evaluation_slice_flattened_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_merge_version_aliases_flattened_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_model_evaluation_slice), "__call__" + type(client.transport.merge_version_aliases), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = model_evaluation_slice.ModelEvaluationSlice() + call.return_value = model.Model() - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - model_evaluation_slice.ModelEvaluationSlice() - ) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(model.Model()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_model_evaluation_slice(name="name_value",) + response = await client.merge_version_aliases( + name="name_value", + version_aliases=["version_aliases_value"], + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].version_aliases + mock_val = ["version_aliases_value"] + assert arg == mock_val @pytest.mark.asyncio -async def test_get_model_evaluation_slice_flattened_error_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_merge_version_aliases_flattened_error_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.get_model_evaluation_slice( - model_service.GetModelEvaluationSliceRequest(), name="name_value", + await client.merge_version_aliases( + model_service.MergeVersionAliasesRequest(), + name="name_value", + version_aliases=["version_aliases_value"], ) -def test_list_model_evaluation_slices( - transport: str = "grpc", request_type=model_service.ListModelEvaluationSlicesRequest -): +@pytest.mark.parametrize( + "request_type", + [ + model_service.ExportModelRequest, + dict, + ], +) +def test_export_model(request_type, transport: str = "grpc"): client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2757,53 +3413,43 @@ def test_list_model_evaluation_slices( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_model_evaluation_slices), "__call__" - ) as call: + with mock.patch.object(type(client.transport.export_model), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = model_service.ListModelEvaluationSlicesResponse( - next_page_token="next_page_token_value", - ) - response = client.list_model_evaluation_slices(request) + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.export_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == model_service.ListModelEvaluationSlicesRequest() + assert args[0] == model_service.ExportModelRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListModelEvaluationSlicesPager) - assert response.next_page_token == "next_page_token_value" - - -def test_list_model_evaluation_slices_from_dict(): - test_list_model_evaluation_slices(request_type=dict) + assert isinstance(response, future.Future) -def test_list_model_evaluation_slices_empty_call(): +def test_export_model_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_model_evaluation_slices), "__call__" - ) as call: - client.list_model_evaluation_slices() + with mock.patch.object(type(client.transport.export_model), "__call__") as call: + client.export_model() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == model_service.ListModelEvaluationSlicesRequest() + assert args[0] == model_service.ExportModelRequest() @pytest.mark.asyncio -async def test_list_model_evaluation_slices_async( - transport: str = "grpc_asyncio", - request_type=model_service.ListModelEvaluationSlicesRequest, +async def test_export_model_async( + transport: str = "grpc_asyncio", request_type=model_service.ExportModelRequest ): client = ModelServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2811,47 +3457,42 @@ async def test_list_model_evaluation_slices_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_model_evaluation_slices), "__call__" - ) as call: + with mock.patch.object(type(client.transport.export_model), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - model_service.ListModelEvaluationSlicesResponse( - next_page_token="next_page_token_value", - ) + operations_pb2.Operation(name="operations/spam") ) - response = await client.list_model_evaluation_slices(request) + response = await client.export_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == model_service.ListModelEvaluationSlicesRequest() + assert args[0] == model_service.ExportModelRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListModelEvaluationSlicesAsyncPager) - assert response.next_page_token == "next_page_token_value" + assert isinstance(response, future.Future) @pytest.mark.asyncio -async def test_list_model_evaluation_slices_async_from_dict(): - await test_list_model_evaluation_slices_async(request_type=dict) +async def test_export_model_async_from_dict(): + await test_export_model_async(request_type=dict) -def test_list_model_evaluation_slices_field_headers(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_export_model_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = model_service.ListModelEvaluationSlicesRequest() + request = model_service.ExportModelRequest() - request.parent = "parent/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_model_evaluation_slices), "__call__" - ) as call: - call.return_value = model_service.ListModelEvaluationSlicesResponse() - client.list_model_evaluation_slices(request) + with mock.patch.object(type(client.transport.export_model), "__call__") as call: + call.return_value = operations_pb2.Operation(name="operations/op") + client.export_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -2860,27 +3501,30 @@ def test_list_model_evaluation_slices_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_list_model_evaluation_slices_field_headers_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_export_model_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = model_service.ListModelEvaluationSlicesRequest() + request = model_service.ExportModelRequest() - request.parent = "parent/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_model_evaluation_slices), "__call__" - ) as call: + with mock.patch.object(type(client.transport.export_model), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - model_service.ListModelEvaluationSlicesResponse() + operations_pb2.Operation(name="operations/op") ) - await client.list_model_evaluation_slices(request) + await client.export_model(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -2889,1059 +3533,4421 @@ async def test_list_model_evaluation_slices_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] -def test_list_model_evaluation_slices_flattened(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_export_model_flattened(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_model_evaluation_slices), "__call__" - ) as call: + with mock.patch.object(type(client.transport.export_model), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = model_service.ListModelEvaluationSlicesResponse() + call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_model_evaluation_slices(parent="parent_value",) + client.export_model( + name="name_value", + output_config=model_service.ExportModelRequest.OutputConfig( + export_format_id="export_format_id_value" + ), + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].output_config + mock_val = model_service.ExportModelRequest.OutputConfig( + export_format_id="export_format_id_value" + ) + assert arg == mock_val -def test_list_model_evaluation_slices_flattened_error(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_export_model_flattened_error(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_model_evaluation_slices( - model_service.ListModelEvaluationSlicesRequest(), parent="parent_value", + client.export_model( + model_service.ExportModelRequest(), + name="name_value", + output_config=model_service.ExportModelRequest.OutputConfig( + export_format_id="export_format_id_value" + ), ) @pytest.mark.asyncio -async def test_list_model_evaluation_slices_flattened_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_export_model_flattened_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_model_evaluation_slices), "__call__" - ) as call: + with mock.patch.object(type(client.transport.export_model), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = model_service.ListModelEvaluationSlicesResponse() + call.return_value = operations_pb2.Operation(name="operations/op") call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - model_service.ListModelEvaluationSlicesResponse() + operations_pb2.Operation(name="operations/spam") ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_model_evaluation_slices(parent="parent_value",) + response = await client.export_model( + name="name_value", + output_config=model_service.ExportModelRequest.OutputConfig( + export_format_id="export_format_id_value" + ), + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + arg = args[0].output_config + mock_val = model_service.ExportModelRequest.OutputConfig( + export_format_id="export_format_id_value" + ) + assert arg == mock_val @pytest.mark.asyncio -async def test_list_model_evaluation_slices_flattened_error_async(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials(),) +async def test_export_model_flattened_error_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.list_model_evaluation_slices( - model_service.ListModelEvaluationSlicesRequest(), parent="parent_value", + await client.export_model( + model_service.ExportModelRequest(), + name="name_value", + output_config=model_service.ExportModelRequest.OutputConfig( + export_format_id="export_format_id_value" + ), ) -def test_list_model_evaluation_slices_pager(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials,) +@pytest.mark.parametrize( + "request_type", + [ + model_service.ImportModelEvaluationRequest, + dict, + ], +) +def test_import_model_evaluation(request_type, transport: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_model_evaluation_slices), "__call__" + type(client.transport.import_model_evaluation), "__call__" ) as call: - # Set the response to a series of pages. - call.side_effect = ( - model_service.ListModelEvaluationSlicesResponse( - model_evaluation_slices=[ - model_evaluation_slice.ModelEvaluationSlice(), - model_evaluation_slice.ModelEvaluationSlice(), - model_evaluation_slice.ModelEvaluationSlice(), - ], - next_page_token="abc", - ), - model_service.ListModelEvaluationSlicesResponse( - model_evaluation_slices=[], next_page_token="def", - ), - model_service.ListModelEvaluationSlicesResponse( - model_evaluation_slices=[ - model_evaluation_slice.ModelEvaluationSlice(), - ], - next_page_token="ghi", - ), - model_service.ListModelEvaluationSlicesResponse( - model_evaluation_slices=[ - model_evaluation_slice.ModelEvaluationSlice(), - model_evaluation_slice.ModelEvaluationSlice(), - ], - ), - RuntimeError, - ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + # Designate an appropriate return value for the call. + call.return_value = gca_model_evaluation.ModelEvaluation( + name="name_value", + display_name="display_name_value", + metrics_schema_uri="metrics_schema_uri_value", + slice_dimensions=["slice_dimensions_value"], ) - pager = client.list_model_evaluation_slices(request={}) + response = client.import_model_evaluation(request) - assert pager._metadata == metadata + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.ImportModelEvaluationRequest() - results = [i for i in pager] - assert len(results) == 6 - assert all( - isinstance(i, model_evaluation_slice.ModelEvaluationSlice) for i in results - ) + # Establish that the response is the type that we expect. + assert isinstance(response, gca_model_evaluation.ModelEvaluation) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.metrics_schema_uri == "metrics_schema_uri_value" + assert response.slice_dimensions == ["slice_dimensions_value"] -def test_list_model_evaluation_slices_pages(): - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_import_model_evaluation_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_model_evaluation_slices), "__call__" + type(client.transport.import_model_evaluation), "__call__" ) as call: - # Set the response to a series of pages. - call.side_effect = ( - model_service.ListModelEvaluationSlicesResponse( - model_evaluation_slices=[ - model_evaluation_slice.ModelEvaluationSlice(), - model_evaluation_slice.ModelEvaluationSlice(), - model_evaluation_slice.ModelEvaluationSlice(), - ], - next_page_token="abc", - ), - model_service.ListModelEvaluationSlicesResponse( - model_evaluation_slices=[], next_page_token="def", - ), - model_service.ListModelEvaluationSlicesResponse( - model_evaluation_slices=[ - model_evaluation_slice.ModelEvaluationSlice(), - ], - next_page_token="ghi", - ), - model_service.ListModelEvaluationSlicesResponse( - model_evaluation_slices=[ - model_evaluation_slice.ModelEvaluationSlice(), - model_evaluation_slice.ModelEvaluationSlice(), - ], - ), - RuntimeError, - ) - pages = list(client.list_model_evaluation_slices(request={}).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token + client.import_model_evaluation() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.ImportModelEvaluationRequest() @pytest.mark.asyncio -async def test_list_model_evaluation_slices_async_pager(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) +async def test_import_model_evaluation_async( + transport: str = "grpc_asyncio", + request_type=model_service.ImportModelEvaluationRequest, +): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_model_evaluation_slices), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.import_model_evaluation), "__call__" ) as call: - # Set the response to a series of pages. - call.side_effect = ( - model_service.ListModelEvaluationSlicesResponse( - model_evaluation_slices=[ - model_evaluation_slice.ModelEvaluationSlice(), - model_evaluation_slice.ModelEvaluationSlice(), - model_evaluation_slice.ModelEvaluationSlice(), - ], - next_page_token="abc", - ), - model_service.ListModelEvaluationSlicesResponse( - model_evaluation_slices=[], next_page_token="def", - ), - model_service.ListModelEvaluationSlicesResponse( - model_evaluation_slices=[ - model_evaluation_slice.ModelEvaluationSlice(), - ], - next_page_token="ghi", - ), - model_service.ListModelEvaluationSlicesResponse( - model_evaluation_slices=[ - model_evaluation_slice.ModelEvaluationSlice(), - model_evaluation_slice.ModelEvaluationSlice(), - ], - ), - RuntimeError, + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_model_evaluation.ModelEvaluation( + name="name_value", + display_name="display_name_value", + metrics_schema_uri="metrics_schema_uri_value", + slice_dimensions=["slice_dimensions_value"], + ) ) - async_pager = await client.list_model_evaluation_slices(request={},) - assert async_pager.next_page_token == "abc" - responses = [] - async for response in async_pager: - responses.append(response) + response = await client.import_model_evaluation(request) - assert len(responses) == 6 - assert all( - isinstance(i, model_evaluation_slice.ModelEvaluationSlice) - for i in responses - ) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.ImportModelEvaluationRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, gca_model_evaluation.ModelEvaluation) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.metrics_schema_uri == "metrics_schema_uri_value" + assert response.slice_dimensions == ["slice_dimensions_value"] @pytest.mark.asyncio -async def test_list_model_evaluation_slices_async_pages(): - client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) +async def test_import_model_evaluation_async_from_dict(): + await test_import_model_evaluation_async(request_type=dict) - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_model_evaluation_slices), - "__call__", - new_callable=mock.AsyncMock, - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - model_service.ListModelEvaluationSlicesResponse( - model_evaluation_slices=[ - model_evaluation_slice.ModelEvaluationSlice(), - model_evaluation_slice.ModelEvaluationSlice(), - model_evaluation_slice.ModelEvaluationSlice(), - ], - next_page_token="abc", - ), - model_service.ListModelEvaluationSlicesResponse( - model_evaluation_slices=[], next_page_token="def", - ), - model_service.ListModelEvaluationSlicesResponse( - model_evaluation_slices=[ - model_evaluation_slice.ModelEvaluationSlice(), - ], - next_page_token="ghi", - ), - model_service.ListModelEvaluationSlicesResponse( - model_evaluation_slices=[ - model_evaluation_slice.ModelEvaluationSlice(), - model_evaluation_slice.ModelEvaluationSlice(), - ], - ), - RuntimeError, - ) - pages = [] - async for page_ in ( - await client.list_model_evaluation_slices(request={}) - ).pages: - pages.append(page_) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token - -def test_credentials_transport_error(): - # It is an error to provide credentials and a transport instance. - transport = transports.ModelServiceGrpcTransport( +def test_import_model_evaluation_field_headers(): + client = ModelServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) - with pytest.raises(ValueError): - client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, - ) - # It is an error to provide a credentials file and a transport instance. - transport = transports.ModelServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = ModelServiceClient( - client_options={"credentials_file": "credentials.json"}, - transport=transport, - ) + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = model_service.ImportModelEvaluationRequest() - # It is an error to provide scopes and a transport instance. - transport = transports.ModelServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = ModelServiceClient( - client_options={"scopes": ["1", "2"]}, transport=transport, - ) + request.parent = "parent_value" + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.import_model_evaluation), "__call__" + ) as call: + call.return_value = gca_model_evaluation.ModelEvaluation() + client.import_model_evaluation(request) -def test_transport_instance(): - # A client may be instantiated with a custom transport instance. - transport = transports.ModelServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - client = ModelServiceClient(transport=transport) - assert client.transport is transport + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] -def test_transport_get_channel(): - # A client may be instantiated with a custom transport instance. - transport = transports.ModelServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel - transport = transports.ModelServiceGrpcAsyncIOTransport( +@pytest.mark.asyncio +async def test_import_model_evaluation_field_headers_async(): + client = ModelServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) - channel = transport.grpc_channel - assert channel + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = model_service.ImportModelEvaluationRequest() -@pytest.mark.parametrize( - "transport_class", - [ - transports.ModelServiceGrpcTransport, - transports.ModelServiceGrpcAsyncIOTransport, - ], -) -def test_transport_adc(transport_class): - # Test default credentials are used if not provided. - with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class() - adc.assert_called_once() + request.parent = "parent_value" + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.import_model_evaluation), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_model_evaluation.ModelEvaluation() + ) + await client.import_model_evaluation(request) -def test_transport_grpc_default(): - # A client should use the gRPC transport by default. - client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials(),) - assert isinstance(client.transport, transports.ModelServiceGrpcTransport,) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] -def test_model_service_base_transport_error(): - # Passing both a credentials object and credentials_file should raise an error - with pytest.raises(core_exceptions.DuplicateCredentialArgs): - transport = transports.ModelServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), - credentials_file="credentials.json", - ) +def test_import_model_evaluation_flattened(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) -def test_model_service_base_transport(): - # Instantiate the base transport. - with mock.patch( - "google.cloud.aiplatform_v1beta1.services.model_service.transports.ModelServiceTransport.__init__" - ) as Transport: - Transport.return_value = None - transport = transports.ModelServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.import_model_evaluation), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gca_model_evaluation.ModelEvaluation() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.import_model_evaluation( + parent="parent_value", + model_evaluation=gca_model_evaluation.ModelEvaluation(name="name_value"), ) - # Every method on the transport should just blindly - # raise NotImplementedError. - methods = ( - "upload_model", - "get_model", - "list_models", - "update_model", - "delete_model", - "export_model", - "get_model_evaluation", - "list_model_evaluations", - "get_model_evaluation_slice", - "list_model_evaluation_slices", - ) - for method in methods: - with pytest.raises(NotImplementedError): - getattr(transport, method)(request=object()) + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].model_evaluation + mock_val = gca_model_evaluation.ModelEvaluation(name="name_value") + assert arg == mock_val - # Additionally, the LRO client (a property) should - # also raise NotImplementedError - with pytest.raises(NotImplementedError): - transport.operations_client +def test_import_model_evaluation_flattened_error(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) -@requires_google_auth_gte_1_25_0 -def test_model_service_base_transport_with_credentials_file(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.aiplatform_v1beta1.services.model_service.transports.ModelServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ModelServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=None, - default_scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.import_model_evaluation( + model_service.ImportModelEvaluationRequest(), + parent="parent_value", + model_evaluation=gca_model_evaluation.ModelEvaluation(name="name_value"), ) -@requires_google_auth_lt_1_25_0 -def test_model_service_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file +@pytest.mark.asyncio +async def test_import_model_evaluation_flattened_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.aiplatform_v1beta1.services.model_service.transports.ModelServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ModelServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", + type(client.transport.import_model_evaluation), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = gca_model_evaluation.ModelEvaluation() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + gca_model_evaluation.ModelEvaluation() ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.import_model_evaluation( + parent="parent_value", + model_evaluation=gca_model_evaluation.ModelEvaluation(name="name_value"), ) + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].model_evaluation + mock_val = gca_model_evaluation.ModelEvaluation(name="name_value") + assert arg == mock_val -def test_model_service_base_transport_with_adc(): - # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.aiplatform_v1beta1.services.model_service.transports.ModelServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.ModelServiceTransport() - adc.assert_called_once() - - -@requires_google_auth_gte_1_25_0 -def test_model_service_auth_adc(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - ModelServiceClient() - adc.assert_called_once_with( - scopes=None, - default_scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) +@pytest.mark.asyncio +async def test_import_model_evaluation_flattened_error_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) -@requires_google_auth_lt_1_25_0 -def test_model_service_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - ModelServiceClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.import_model_evaluation( + model_service.ImportModelEvaluationRequest(), + parent="parent_value", + model_evaluation=gca_model_evaluation.ModelEvaluation(name="name_value"), ) @pytest.mark.parametrize( - "transport_class", + "request_type", [ - transports.ModelServiceGrpcTransport, - transports.ModelServiceGrpcAsyncIOTransport, + model_service.BatchImportModelEvaluationSlicesRequest, + dict, ], ) -@requires_google_auth_gte_1_25_0 -def test_model_service_transport_auth_adc(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - adc.assert_called_once_with( - scopes=["1", "2"], - default_scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) +def test_batch_import_model_evaluation_slices(request_type, transport: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() -@pytest.mark.parametrize( - "transport_class", - [ - transports.ModelServiceGrpcTransport, - transports.ModelServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_model_service_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_import_model_evaluation_slices), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = model_service.BatchImportModelEvaluationSlicesResponse( + imported_model_evaluation_slices=["imported_model_evaluation_slices_value"], ) + response = client.batch_import_model_evaluation_slices(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.BatchImportModelEvaluationSlicesRequest() -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.ModelServiceGrpcTransport, grpc_helpers), - (transports.ModelServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_gte_1_26_0 -def test_model_service_transport_create_channel(transport_class, grpc_helpers): - # If credentials and host are not provided, the transport class should use - # ADC credentials. + # Establish that the response is the type that we expect. + assert isinstance(response, model_service.BatchImportModelEvaluationSlicesResponse) + assert response.imported_model_evaluation_slices == [ + "imported_model_evaluation_slices_value" + ] + + +def test_batch_import_model_evaluation_slices_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class(quota_project_id="octopus", scopes=["1", "2"]) + type(client.transport.batch_import_model_evaluation_slices), "__call__" + ) as call: + client.batch_import_model_evaluation_slices() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.BatchImportModelEvaluationSlicesRequest() - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - default_scopes=("https://www.googleapis.com/auth/cloud-platform",), - scopes=["1", "2"], - default_host="aiplatform.googleapis.com", - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], + +@pytest.mark.asyncio +async def test_batch_import_model_evaluation_slices_async( + transport: str = "grpc_asyncio", + request_type=model_service.BatchImportModelEvaluationSlicesRequest, +): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_import_model_evaluation_slices), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + model_service.BatchImportModelEvaluationSlicesResponse( + imported_model_evaluation_slices=[ + "imported_model_evaluation_slices_value" + ], + ) ) + response = await client.batch_import_model_evaluation_slices(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.BatchImportModelEvaluationSlicesRequest() -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.ModelServiceGrpcTransport, grpc_helpers), - (transports.ModelServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_model_service_transport_create_channel_old_api_core( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. + # Establish that the response is the type that we expect. + assert isinstance(response, model_service.BatchImportModelEvaluationSlicesResponse) + assert response.imported_model_evaluation_slices == [ + "imported_model_evaluation_slices_value" + ] + + +@pytest.mark.asyncio +async def test_batch_import_model_evaluation_slices_async_from_dict(): + await test_batch_import_model_evaluation_slices_async(request_type=dict) + + +def test_batch_import_model_evaluation_slices_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = model_service.BatchImportModelEvaluationSlicesRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class(quota_project_id="octopus") + type(client.transport.batch_import_model_evaluation_slices), "__call__" + ) as call: + call.return_value = model_service.BatchImportModelEvaluationSlicesResponse() + client.batch_import_model_evaluation_slices(request) - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.ModelServiceGrpcTransport, grpc_helpers), - (transports.ModelServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_model_service_transport_create_channel_user_scopes( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. + +@pytest.mark.asyncio +async def test_batch_import_model_evaluation_slices_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = model_service.BatchImportModelEvaluationSlicesRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) + type(client.transport.batch_import_model_evaluation_slices), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + model_service.BatchImportModelEvaluationSlicesResponse() + ) + await client.batch_import_model_evaluation_slices(request) - transport_class(quota_project_id="octopus", scopes=["1", "2"]) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=["1", "2"], - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_batch_import_model_evaluation_slices_flattened(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_import_model_evaluation_slices), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = model_service.BatchImportModelEvaluationSlicesResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.batch_import_model_evaluation_slices( + parent="parent_value", + model_evaluation_slices=[ + model_evaluation_slice.ModelEvaluationSlice(name="name_value") ], ) + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].model_evaluation_slices + mock_val = [model_evaluation_slice.ModelEvaluationSlice(name="name_value")] + assert arg == mock_val -@pytest.mark.parametrize( - "transport_class", - [transports.ModelServiceGrpcTransport, transports.ModelServiceGrpcAsyncIOTransport], -) -def test_model_service_grpc_transport_client_cert_source_for_mtls(transport_class): - cred = ga_credentials.AnonymousCredentials() - # Check ssl_channel_credentials is used if provided. - with mock.patch.object(transport_class, "create_channel") as mock_create_channel: - mock_ssl_channel_creds = mock.Mock() - transport_class( - host="squid.clam.whelk", - credentials=cred, - ssl_channel_credentials=mock_ssl_channel_creds, - ) - mock_create_channel.assert_called_once_with( - "squid.clam.whelk:443", - credentials=cred, - credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=mock_ssl_channel_creds, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), +def test_batch_import_model_evaluation_slices_flattened_error(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.batch_import_model_evaluation_slices( + model_service.BatchImportModelEvaluationSlicesRequest(), + parent="parent_value", + model_evaluation_slices=[ + model_evaluation_slice.ModelEvaluationSlice(name="name_value") ], ) - # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls - # is used. - with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): - with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: - transport_class( - credentials=cred, - client_cert_source_for_mtls=client_cert_source_callback, + +@pytest.mark.asyncio +async def test_batch_import_model_evaluation_slices_flattened_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.batch_import_model_evaluation_slices), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = model_service.BatchImportModelEvaluationSlicesResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + model_service.BatchImportModelEvaluationSlicesResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.batch_import_model_evaluation_slices( + parent="parent_value", + model_evaluation_slices=[ + model_evaluation_slice.ModelEvaluationSlice(name="name_value") + ], + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].model_evaluation_slices + mock_val = [model_evaluation_slice.ModelEvaluationSlice(name="name_value")] + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_batch_import_model_evaluation_slices_flattened_error_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.batch_import_model_evaluation_slices( + model_service.BatchImportModelEvaluationSlicesRequest(), + parent="parent_value", + model_evaluation_slices=[ + model_evaluation_slice.ModelEvaluationSlice(name="name_value") + ], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + model_service.GetModelEvaluationRequest, + dict, + ], +) +def test_get_model_evaluation(request_type, transport: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_model_evaluation), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = model_evaluation.ModelEvaluation( + name="name_value", + display_name="display_name_value", + metrics_schema_uri="metrics_schema_uri_value", + slice_dimensions=["slice_dimensions_value"], + ) + response = client.get_model_evaluation(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.GetModelEvaluationRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, model_evaluation.ModelEvaluation) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.metrics_schema_uri == "metrics_schema_uri_value" + assert response.slice_dimensions == ["slice_dimensions_value"] + + +def test_get_model_evaluation_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_model_evaluation), "__call__" + ) as call: + client.get_model_evaluation() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.GetModelEvaluationRequest() + + +@pytest.mark.asyncio +async def test_get_model_evaluation_async( + transport: str = "grpc_asyncio", + request_type=model_service.GetModelEvaluationRequest, +): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_model_evaluation), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + model_evaluation.ModelEvaluation( + name="name_value", + display_name="display_name_value", + metrics_schema_uri="metrics_schema_uri_value", + slice_dimensions=["slice_dimensions_value"], ) - expected_cert, expected_key = client_cert_source_callback() - mock_ssl_cred.assert_called_once_with( - certificate_chain=expected_cert, private_key=expected_key + ) + response = await client.get_model_evaluation(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.GetModelEvaluationRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, model_evaluation.ModelEvaluation) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.metrics_schema_uri == "metrics_schema_uri_value" + assert response.slice_dimensions == ["slice_dimensions_value"] + + +@pytest.mark.asyncio +async def test_get_model_evaluation_async_from_dict(): + await test_get_model_evaluation_async(request_type=dict) + + +def test_get_model_evaluation_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = model_service.GetModelEvaluationRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_model_evaluation), "__call__" + ) as call: + call.return_value = model_evaluation.ModelEvaluation() + client.get_model_evaluation(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_model_evaluation_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = model_service.GetModelEvaluationRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_model_evaluation), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + model_evaluation.ModelEvaluation() + ) + await client.get_model_evaluation(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_get_model_evaluation_flattened(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_model_evaluation), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = model_evaluation.ModelEvaluation() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_model_evaluation( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_get_model_evaluation_flattened_error(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_model_evaluation( + model_service.GetModelEvaluationRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_model_evaluation_flattened_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_model_evaluation), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = model_evaluation.ModelEvaluation() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + model_evaluation.ModelEvaluation() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_model_evaluation( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_get_model_evaluation_flattened_error_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_model_evaluation( + model_service.GetModelEvaluationRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + model_service.ListModelEvaluationsRequest, + dict, + ], +) +def test_list_model_evaluations(request_type, transport: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluations), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = model_service.ListModelEvaluationsResponse( + next_page_token="next_page_token_value", + ) + response = client.list_model_evaluations(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.ListModelEvaluationsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListModelEvaluationsPager) + assert response.next_page_token == "next_page_token_value" + + +def test_list_model_evaluations_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluations), "__call__" + ) as call: + client.list_model_evaluations() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.ListModelEvaluationsRequest() + + +@pytest.mark.asyncio +async def test_list_model_evaluations_async( + transport: str = "grpc_asyncio", + request_type=model_service.ListModelEvaluationsRequest, +): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluations), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + model_service.ListModelEvaluationsResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.list_model_evaluations(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.ListModelEvaluationsRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListModelEvaluationsAsyncPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_list_model_evaluations_async_from_dict(): + await test_list_model_evaluations_async(request_type=dict) + + +def test_list_model_evaluations_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = model_service.ListModelEvaluationsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluations), "__call__" + ) as call: + call.return_value = model_service.ListModelEvaluationsResponse() + client.list_model_evaluations(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_model_evaluations_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = model_service.ListModelEvaluationsRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluations), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + model_service.ListModelEvaluationsResponse() + ) + await client.list_model_evaluations(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_list_model_evaluations_flattened(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluations), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = model_service.ListModelEvaluationsResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_model_evaluations( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +def test_list_model_evaluations_flattened_error(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_model_evaluations( + model_service.ListModelEvaluationsRequest(), + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_model_evaluations_flattened_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluations), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = model_service.ListModelEvaluationsResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + model_service.ListModelEvaluationsResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_model_evaluations( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_list_model_evaluations_flattened_error_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_model_evaluations( + model_service.ListModelEvaluationsRequest(), + parent="parent_value", + ) + + +def test_list_model_evaluations_pager(transport_name: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluations), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + model_service.ListModelEvaluationsResponse( + model_evaluations=[ + model_evaluation.ModelEvaluation(), + model_evaluation.ModelEvaluation(), + model_evaluation.ModelEvaluation(), + ], + next_page_token="abc", + ), + model_service.ListModelEvaluationsResponse( + model_evaluations=[], + next_page_token="def", + ), + model_service.ListModelEvaluationsResponse( + model_evaluations=[ + model_evaluation.ModelEvaluation(), + ], + next_page_token="ghi", + ), + model_service.ListModelEvaluationsResponse( + model_evaluations=[ + model_evaluation.ModelEvaluation(), + model_evaluation.ModelEvaluation(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_model_evaluations(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, model_evaluation.ModelEvaluation) for i in results) + + +def test_list_model_evaluations_pages(transport_name: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluations), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + model_service.ListModelEvaluationsResponse( + model_evaluations=[ + model_evaluation.ModelEvaluation(), + model_evaluation.ModelEvaluation(), + model_evaluation.ModelEvaluation(), + ], + next_page_token="abc", + ), + model_service.ListModelEvaluationsResponse( + model_evaluations=[], + next_page_token="def", + ), + model_service.ListModelEvaluationsResponse( + model_evaluations=[ + model_evaluation.ModelEvaluation(), + ], + next_page_token="ghi", + ), + model_service.ListModelEvaluationsResponse( + model_evaluations=[ + model_evaluation.ModelEvaluation(), + model_evaluation.ModelEvaluation(), + ], + ), + RuntimeError, + ) + pages = list(client.list_model_evaluations(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.asyncio +async def test_list_model_evaluations_async_pager(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluations), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + model_service.ListModelEvaluationsResponse( + model_evaluations=[ + model_evaluation.ModelEvaluation(), + model_evaluation.ModelEvaluation(), + model_evaluation.ModelEvaluation(), + ], + next_page_token="abc", + ), + model_service.ListModelEvaluationsResponse( + model_evaluations=[], + next_page_token="def", + ), + model_service.ListModelEvaluationsResponse( + model_evaluations=[ + model_evaluation.ModelEvaluation(), + ], + next_page_token="ghi", + ), + model_service.ListModelEvaluationsResponse( + model_evaluations=[ + model_evaluation.ModelEvaluation(), + model_evaluation.ModelEvaluation(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_model_evaluations( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all(isinstance(i, model_evaluation.ModelEvaluation) for i in responses) + + +@pytest.mark.asyncio +async def test_list_model_evaluations_async_pages(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluations), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + model_service.ListModelEvaluationsResponse( + model_evaluations=[ + model_evaluation.ModelEvaluation(), + model_evaluation.ModelEvaluation(), + model_evaluation.ModelEvaluation(), + ], + next_page_token="abc", + ), + model_service.ListModelEvaluationsResponse( + model_evaluations=[], + next_page_token="def", + ), + model_service.ListModelEvaluationsResponse( + model_evaluations=[ + model_evaluation.ModelEvaluation(), + ], + next_page_token="ghi", + ), + model_service.ListModelEvaluationsResponse( + model_evaluations=[ + model_evaluation.ModelEvaluation(), + model_evaluation.ModelEvaluation(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.list_model_evaluations(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize( + "request_type", + [ + model_service.GetModelEvaluationSliceRequest, + dict, + ], +) +def test_get_model_evaluation_slice(request_type, transport: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_model_evaluation_slice), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = model_evaluation_slice.ModelEvaluationSlice( + name="name_value", + metrics_schema_uri="metrics_schema_uri_value", + ) + response = client.get_model_evaluation_slice(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.GetModelEvaluationSliceRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, model_evaluation_slice.ModelEvaluationSlice) + assert response.name == "name_value" + assert response.metrics_schema_uri == "metrics_schema_uri_value" + + +def test_get_model_evaluation_slice_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_model_evaluation_slice), "__call__" + ) as call: + client.get_model_evaluation_slice() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.GetModelEvaluationSliceRequest() + + +@pytest.mark.asyncio +async def test_get_model_evaluation_slice_async( + transport: str = "grpc_asyncio", + request_type=model_service.GetModelEvaluationSliceRequest, +): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_model_evaluation_slice), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + model_evaluation_slice.ModelEvaluationSlice( + name="name_value", + metrics_schema_uri="metrics_schema_uri_value", + ) + ) + response = await client.get_model_evaluation_slice(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.GetModelEvaluationSliceRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, model_evaluation_slice.ModelEvaluationSlice) + assert response.name == "name_value" + assert response.metrics_schema_uri == "metrics_schema_uri_value" + + +@pytest.mark.asyncio +async def test_get_model_evaluation_slice_async_from_dict(): + await test_get_model_evaluation_slice_async(request_type=dict) + + +def test_get_model_evaluation_slice_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = model_service.GetModelEvaluationSliceRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_model_evaluation_slice), "__call__" + ) as call: + call.return_value = model_evaluation_slice.ModelEvaluationSlice() + client.get_model_evaluation_slice(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_model_evaluation_slice_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = model_service.GetModelEvaluationSliceRequest() + + request.name = "name_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_model_evaluation_slice), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + model_evaluation_slice.ModelEvaluationSlice() + ) + await client.get_model_evaluation_slice(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] + + +def test_get_model_evaluation_slice_flattened(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_model_evaluation_slice), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = model_evaluation_slice.ModelEvaluationSlice() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.get_model_evaluation_slice( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +def test_get_model_evaluation_slice_flattened_error(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.get_model_evaluation_slice( + model_service.GetModelEvaluationSliceRequest(), + name="name_value", + ) + + +@pytest.mark.asyncio +async def test_get_model_evaluation_slice_flattened_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.get_model_evaluation_slice), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = model_evaluation_slice.ModelEvaluationSlice() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + model_evaluation_slice.ModelEvaluationSlice() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.get_model_evaluation_slice( + name="name_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_get_model_evaluation_slice_flattened_error_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.get_model_evaluation_slice( + model_service.GetModelEvaluationSliceRequest(), + name="name_value", + ) + + +@pytest.mark.parametrize( + "request_type", + [ + model_service.ListModelEvaluationSlicesRequest, + dict, + ], +) +def test_list_model_evaluation_slices(request_type, transport: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluation_slices), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = model_service.ListModelEvaluationSlicesResponse( + next_page_token="next_page_token_value", + ) + response = client.list_model_evaluation_slices(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.ListModelEvaluationSlicesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListModelEvaluationSlicesPager) + assert response.next_page_token == "next_page_token_value" + + +def test_list_model_evaluation_slices_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluation_slices), "__call__" + ) as call: + client.list_model_evaluation_slices() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.ListModelEvaluationSlicesRequest() + + +@pytest.mark.asyncio +async def test_list_model_evaluation_slices_async( + transport: str = "grpc_asyncio", + request_type=model_service.ListModelEvaluationSlicesRequest, +): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluation_slices), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + model_service.ListModelEvaluationSlicesResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.list_model_evaluation_slices(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == model_service.ListModelEvaluationSlicesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListModelEvaluationSlicesAsyncPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_list_model_evaluation_slices_async_from_dict(): + await test_list_model_evaluation_slices_async(request_type=dict) + + +def test_list_model_evaluation_slices_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = model_service.ListModelEvaluationSlicesRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluation_slices), "__call__" + ) as call: + call.return_value = model_service.ListModelEvaluationSlicesResponse() + client.list_model_evaluation_slices(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_model_evaluation_slices_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = model_service.ListModelEvaluationSlicesRequest() + + request.parent = "parent_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluation_slices), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + model_service.ListModelEvaluationSlicesResponse() + ) + await client.list_model_evaluation_slices(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] + + +def test_list_model_evaluation_slices_flattened(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluation_slices), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = model_service.ListModelEvaluationSlicesResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.list_model_evaluation_slices( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +def test_list_model_evaluation_slices_flattened_error(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.list_model_evaluation_slices( + model_service.ListModelEvaluationSlicesRequest(), + parent="parent_value", + ) + + +@pytest.mark.asyncio +async def test_list_model_evaluation_slices_flattened_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluation_slices), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = model_service.ListModelEvaluationSlicesResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + model_service.ListModelEvaluationSlicesResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.list_model_evaluation_slices( + parent="parent_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_list_model_evaluation_slices_flattened_error_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.list_model_evaluation_slices( + model_service.ListModelEvaluationSlicesRequest(), + parent="parent_value", + ) + + +def test_list_model_evaluation_slices_pager(transport_name: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluation_slices), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + model_service.ListModelEvaluationSlicesResponse( + model_evaluation_slices=[ + model_evaluation_slice.ModelEvaluationSlice(), + model_evaluation_slice.ModelEvaluationSlice(), + model_evaluation_slice.ModelEvaluationSlice(), + ], + next_page_token="abc", + ), + model_service.ListModelEvaluationSlicesResponse( + model_evaluation_slices=[], + next_page_token="def", + ), + model_service.ListModelEvaluationSlicesResponse( + model_evaluation_slices=[ + model_evaluation_slice.ModelEvaluationSlice(), + ], + next_page_token="ghi", + ), + model_service.ListModelEvaluationSlicesResponse( + model_evaluation_slices=[ + model_evaluation_slice.ModelEvaluationSlice(), + model_evaluation_slice.ModelEvaluationSlice(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_model_evaluation_slices(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all( + isinstance(i, model_evaluation_slice.ModelEvaluationSlice) for i in results + ) + + +def test_list_model_evaluation_slices_pages(transport_name: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluation_slices), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + model_service.ListModelEvaluationSlicesResponse( + model_evaluation_slices=[ + model_evaluation_slice.ModelEvaluationSlice(), + model_evaluation_slice.ModelEvaluationSlice(), + model_evaluation_slice.ModelEvaluationSlice(), + ], + next_page_token="abc", + ), + model_service.ListModelEvaluationSlicesResponse( + model_evaluation_slices=[], + next_page_token="def", + ), + model_service.ListModelEvaluationSlicesResponse( + model_evaluation_slices=[ + model_evaluation_slice.ModelEvaluationSlice(), + ], + next_page_token="ghi", + ), + model_service.ListModelEvaluationSlicesResponse( + model_evaluation_slices=[ + model_evaluation_slice.ModelEvaluationSlice(), + model_evaluation_slice.ModelEvaluationSlice(), + ], + ), + RuntimeError, + ) + pages = list(client.list_model_evaluation_slices(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.asyncio +async def test_list_model_evaluation_slices_async_pager(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluation_slices), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + model_service.ListModelEvaluationSlicesResponse( + model_evaluation_slices=[ + model_evaluation_slice.ModelEvaluationSlice(), + model_evaluation_slice.ModelEvaluationSlice(), + model_evaluation_slice.ModelEvaluationSlice(), + ], + next_page_token="abc", + ), + model_service.ListModelEvaluationSlicesResponse( + model_evaluation_slices=[], + next_page_token="def", + ), + model_service.ListModelEvaluationSlicesResponse( + model_evaluation_slices=[ + model_evaluation_slice.ModelEvaluationSlice(), + ], + next_page_token="ghi", + ), + model_service.ListModelEvaluationSlicesResponse( + model_evaluation_slices=[ + model_evaluation_slice.ModelEvaluationSlice(), + model_evaluation_slice.ModelEvaluationSlice(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_model_evaluation_slices( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all( + isinstance(i, model_evaluation_slice.ModelEvaluationSlice) + for i in responses + ) + + +@pytest.mark.asyncio +async def test_list_model_evaluation_slices_async_pages(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_model_evaluation_slices), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + model_service.ListModelEvaluationSlicesResponse( + model_evaluation_slices=[ + model_evaluation_slice.ModelEvaluationSlice(), + model_evaluation_slice.ModelEvaluationSlice(), + model_evaluation_slice.ModelEvaluationSlice(), + ], + next_page_token="abc", + ), + model_service.ListModelEvaluationSlicesResponse( + model_evaluation_slices=[], + next_page_token="def", + ), + model_service.ListModelEvaluationSlicesResponse( + model_evaluation_slices=[ + model_evaluation_slice.ModelEvaluationSlice(), + ], + next_page_token="ghi", + ), + model_service.ListModelEvaluationSlicesResponse( + model_evaluation_slices=[ + model_evaluation_slice.ModelEvaluationSlice(), + model_evaluation_slice.ModelEvaluationSlice(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.list_model_evaluation_slices(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.ModelServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.ModelServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ModelServiceClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide an api_key and a transport instance. + transport = transports.ModelServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = ModelServiceClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = ModelServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.ModelServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = ModelServiceClient( + client_options={"scopes": ["1", "2"]}, + transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.ModelServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + client = ModelServiceClient(transport=transport) + assert client.transport is transport + + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.ModelServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.ModelServiceGrpcAsyncIOTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.ModelServiceGrpcTransport, + transports.ModelServiceGrpcAsyncIOTransport, + ], +) +def test_transport_adc(transport_class): + # Test default credentials are used if not provided. + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class() + adc.assert_called_once() + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = ModelServiceClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + +def test_transport_grpc_default(): + # A client should use the gRPC transport by default. + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.ModelServiceGrpcTransport, + ) + + +def test_model_service_base_transport_error(): + # Passing both a credentials object and credentials_file should raise an error + with pytest.raises(core_exceptions.DuplicateCredentialArgs): + transport = transports.ModelServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + credentials_file="credentials.json", + ) + + +def test_model_service_base_transport(): + # Instantiate the base transport. + with mock.patch( + "google.cloud.aiplatform_v1beta1.services.model_service.transports.ModelServiceTransport.__init__" + ) as Transport: + Transport.return_value = None + transport = transports.ModelServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Every method on the transport should just blindly + # raise NotImplementedError. + methods = ( + "upload_model", + "get_model", + "list_models", + "list_model_versions", + "update_model", + "update_explanation_dataset", + "delete_model", + "delete_model_version", + "merge_version_aliases", + "export_model", + "import_model_evaluation", + "batch_import_model_evaluation_slices", + "get_model_evaluation", + "list_model_evaluations", + "get_model_evaluation_slice", + "list_model_evaluation_slices", + "set_iam_policy", + "get_iam_policy", + "test_iam_permissions", + "get_location", + "list_locations", + "get_operation", + "wait_operation", + "cancel_operation", + "delete_operation", + "list_operations", + ) + for method in methods: + with pytest.raises(NotImplementedError): + getattr(transport, method)(request=object()) + + with pytest.raises(NotImplementedError): + transport.close() + + # Additionally, the LRO client (a property) should + # also raise NotImplementedError + with pytest.raises(NotImplementedError): + transport.operations_client + + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + + +def test_model_service_base_transport_with_credentials_file(): + # Instantiate the base transport with a credentials file + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch( + "google.cloud.aiplatform_v1beta1.services.model_service.transports.ModelServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ModelServiceTransport( + credentials_file="credentials.json", + quota_project_id="octopus", + ) + load_creds.assert_called_once_with( + "credentials.json", + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +def test_model_service_base_transport_with_adc(): + # Test the default credentials are used if credentials and credentials_file are None. + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( + "google.cloud.aiplatform_v1beta1.services.model_service.transports.ModelServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.ModelServiceTransport() + adc.assert_called_once() + + +def test_model_service_auth_adc(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + ModelServiceClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id=None, + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.ModelServiceGrpcTransport, + transports.ModelServiceGrpcAsyncIOTransport, + ], +) +def test_model_service_transport_auth_adc(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.ModelServiceGrpcTransport, grpc_helpers), + (transports.ModelServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +def test_model_service_transport_create_channel(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=["1", "2"], + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class", + [transports.ModelServiceGrpcTransport, transports.ModelServiceGrpcAsyncIOTransport], +) +def test_model_service_grpc_transport_client_cert_source_for_mtls(transport_class): + cred = ga_credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds, + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback, + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( + certificate_chain=expected_cert, private_key=expected_key + ) + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_model_service_host_no_port(transport_name): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions( + api_endpoint="aiplatform.googleapis.com" + ), + transport=transport_name, + ) + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_model_service_host_with_port(transport_name): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions( + api_endpoint="aiplatform.googleapis.com:8000" + ), + transport=transport_name, + ) + assert client.transport._host == ("aiplatform.googleapis.com:8000") + + +def test_model_service_grpc_transport_channel(): + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.ModelServiceGrpcTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +def test_model_service_grpc_asyncio_transport_channel(): + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.ModelServiceGrpcAsyncIOTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize( + "transport_class", + [transports.ModelServiceGrpcTransport, transports.ModelServiceGrpcAsyncIOTransport], +) +def test_model_service_transport_channel_mtls_with_client_cert_source(transport_class): + with mock.patch( + "grpc.ssl_channel_credentials", autospec=True + ) as grpc_ssl_channel_cred: + with mock.patch.object( + transport_class, "create_channel" + ) as grpc_create_channel: + mock_ssl_cred = mock.Mock() + grpc_ssl_channel_cred.return_value = mock_ssl_cred + + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + + cred = ga_credentials.AnonymousCredentials() + with pytest.warns(DeprecationWarning): + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (cred, None) + transport = transport_class( + host="squid.clam.whelk", + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=client_cert_source_callback, + ) + adc.assert_called_once() + + grpc_ssl_channel_cred.assert_called_once_with( + certificate_chain=b"cert bytes", private_key=b"key bytes" + ) + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize( + "transport_class", + [transports.ModelServiceGrpcTransport, transports.ModelServiceGrpcAsyncIOTransport], +) +def test_model_service_transport_channel_mtls_with_adc(transport_class): + mock_ssl_cred = mock.Mock() + with mock.patch.multiple( + "google.auth.transport.grpc.SslCredentials", + __init__=mock.Mock(return_value=None), + ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), + ): + with mock.patch.object( + transport_class, "create_channel" + ) as grpc_create_channel: + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + mock_cred = mock.Mock() + + with pytest.warns(DeprecationWarning): + transport = transport_class( + host="squid.clam.whelk", + credentials=mock_cred, + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=None, + ) + + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=mock_cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + + +def test_model_service_grpc_lro_client(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_model_service_grpc_lro_async_client(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_endpoint_path(): + project = "squid" + location = "clam" + endpoint = "whelk" + expected = "projects/{project}/locations/{location}/endpoints/{endpoint}".format( + project=project, + location=location, + endpoint=endpoint, + ) + actual = ModelServiceClient.endpoint_path(project, location, endpoint) + assert expected == actual + + +def test_parse_endpoint_path(): + expected = { + "project": "octopus", + "location": "oyster", + "endpoint": "nudibranch", + } + path = ModelServiceClient.endpoint_path(**expected) + + # Check that the path construction is reversible. + actual = ModelServiceClient.parse_endpoint_path(path) + assert expected == actual + + +def test_model_path(): + project = "cuttlefish" + location = "mussel" + model = "winkle" + expected = "projects/{project}/locations/{location}/models/{model}".format( + project=project, + location=location, + model=model, + ) + actual = ModelServiceClient.model_path(project, location, model) + assert expected == actual + + +def test_parse_model_path(): + expected = { + "project": "nautilus", + "location": "scallop", + "model": "abalone", + } + path = ModelServiceClient.model_path(**expected) + + # Check that the path construction is reversible. + actual = ModelServiceClient.parse_model_path(path) + assert expected == actual + + +def test_model_evaluation_path(): + project = "squid" + location = "clam" + model = "whelk" + evaluation = "octopus" + expected = "projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}".format( + project=project, + location=location, + model=model, + evaluation=evaluation, + ) + actual = ModelServiceClient.model_evaluation_path( + project, location, model, evaluation + ) + assert expected == actual + + +def test_parse_model_evaluation_path(): + expected = { + "project": "oyster", + "location": "nudibranch", + "model": "cuttlefish", + "evaluation": "mussel", + } + path = ModelServiceClient.model_evaluation_path(**expected) + + # Check that the path construction is reversible. + actual = ModelServiceClient.parse_model_evaluation_path(path) + assert expected == actual + + +def test_model_evaluation_slice_path(): + project = "winkle" + location = "nautilus" + model = "scallop" + evaluation = "abalone" + slice = "squid" + expected = "projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}/slices/{slice}".format( + project=project, + location=location, + model=model, + evaluation=evaluation, + slice=slice, + ) + actual = ModelServiceClient.model_evaluation_slice_path( + project, location, model, evaluation, slice + ) + assert expected == actual + + +def test_parse_model_evaluation_slice_path(): + expected = { + "project": "clam", + "location": "whelk", + "model": "octopus", + "evaluation": "oyster", + "slice": "nudibranch", + } + path = ModelServiceClient.model_evaluation_slice_path(**expected) + + # Check that the path construction is reversible. + actual = ModelServiceClient.parse_model_evaluation_slice_path(path) + assert expected == actual + + +def test_training_pipeline_path(): + project = "cuttlefish" + location = "mussel" + training_pipeline = "winkle" + expected = "projects/{project}/locations/{location}/trainingPipelines/{training_pipeline}".format( + project=project, + location=location, + training_pipeline=training_pipeline, + ) + actual = ModelServiceClient.training_pipeline_path( + project, location, training_pipeline + ) + assert expected == actual + + +def test_parse_training_pipeline_path(): + expected = { + "project": "nautilus", + "location": "scallop", + "training_pipeline": "abalone", + } + path = ModelServiceClient.training_pipeline_path(**expected) + + # Check that the path construction is reversible. + actual = ModelServiceClient.parse_training_pipeline_path(path) + assert expected == actual + + +def test_common_billing_account_path(): + billing_account = "squid" + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + actual = ModelServiceClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "clam", + } + path = ModelServiceClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = ModelServiceClient.parse_common_billing_account_path(path) + assert expected == actual + + +def test_common_folder_path(): + folder = "whelk" + expected = "folders/{folder}".format( + folder=folder, + ) + actual = ModelServiceClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "octopus", + } + path = ModelServiceClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = ModelServiceClient.parse_common_folder_path(path) + assert expected == actual + + +def test_common_organization_path(): + organization = "oyster" + expected = "organizations/{organization}".format( + organization=organization, + ) + actual = ModelServiceClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "nudibranch", + } + path = ModelServiceClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = ModelServiceClient.parse_common_organization_path(path) + assert expected == actual + + +def test_common_project_path(): + project = "cuttlefish" + expected = "projects/{project}".format( + project=project, + ) + actual = ModelServiceClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "mussel", + } + path = ModelServiceClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = ModelServiceClient.parse_common_project_path(path) + assert expected == actual + + +def test_common_location_path(): + project = "winkle" + location = "nautilus" + expected = "projects/{project}/locations/{location}".format( + project=project, + location=location, + ) + actual = ModelServiceClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "scallop", + "location": "abalone", + } + path = ModelServiceClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = ModelServiceClient.parse_common_location_path(path) + assert expected == actual + + +def test_client_with_default_client_info(): + client_info = gapic_v1.client_info.ClientInfo() + + with mock.patch.object( + transports.ModelServiceTransport, "_prep_wrapped_messages" + ) as prep: + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + with mock.patch.object( + transports.ModelServiceTransport, "_prep_wrapped_messages" + ) as prep: + transport_class = ModelServiceClient.get_transport_class() + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_delete_operation(transport: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_operation(transport: str = "grpc"): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_operation_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = None + + client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_operation_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_delete_operation_from_dict(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_delete_operation_from_dict_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_cancel_operation(transport: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation(transport: str = "grpc"): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_wait_operation(transport: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_wait_operation(transport: str = "grpc"): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_wait_operation_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_wait_operation_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_wait_operation_from_dict(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_wait_operation_from_dict_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_operation(transport: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_get_operation(transport: str = "grpc"): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_get_operation_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_get_operation_from_dict(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_operations(transport: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + response = client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +@pytest.mark.asyncio +async def test_list_operations(transport: str = "grpc"): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +def test_list_operations_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_operations_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_operations_from_dict(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + response = client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_operations_from_dict_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_locations(transport: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + response = client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +@pytest.mark.asyncio +async def test_list_locations(transport: str = "grpc"): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +def test_list_locations_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_locations_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_locations_from_dict(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + response = client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_locations_from_dict_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_location(transport: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + response = client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +@pytest.mark.asyncio +async def test_get_location_async(transport: str = "grpc_asyncio"): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +def test_get_location_field_headers(): + client = ModelServiceClient(credentials=ga_credentials.AnonymousCredentials()) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = locations_pb2.Location() + + client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_location_field_headers_async(): + client = ModelServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials()) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +def test_get_location_from_dict(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + response = client.get_location( + request={ + "name": "locations/abc", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_location_from_dict_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_set_iam_policy(transport: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + response = client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", ) + ) + response = await client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_set_iam_policy_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] -def test_model_service_host_no_port(): - client = ModelServiceClient( +@pytest.mark.asyncio +async def test_set_iam_policy_field_headers_async(): + client = ModelServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions( - api_endpoint="aiplatform.googleapis.com" - ), ) - assert client.transport._host == "aiplatform.googleapis.com:443" + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy(request) -def test_model_service_host_with_port(): + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_set_iam_policy_from_dict(): client = ModelServiceClient( credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions( - api_endpoint="aiplatform.googleapis.com:8000" - ), ) - assert client.transport._host == "aiplatform.googleapis.com:8000" + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + response = client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() -def test_model_service_grpc_transport_channel(): - channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) - # Check that channel is used if provided. - transport = transports.ModelServiceGrpcTransport( - host="squid.clam.whelk", channel=channel, +@pytest.mark.asyncio +async def test_set_iam_policy_from_dict_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), ) - assert transport.grpc_channel == channel - assert transport._host == "squid.clam.whelk:443" - assert transport._ssl_channel_credentials == None + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + response = await client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() -def test_model_service_grpc_asyncio_transport_channel(): - channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) - # Check that channel is used if provided. - transport = transports.ModelServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", channel=channel, +def test_get_iam_policy(transport: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - assert transport.grpc_channel == channel - assert transport._host == "squid.clam.whelk:443" - assert transport._ssl_channel_credentials == None + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() -# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are -# removed from grpc/grpc_asyncio transport constructor. -@pytest.mark.parametrize( - "transport_class", - [transports.ModelServiceGrpcTransport, transports.ModelServiceGrpcAsyncIOTransport], -) -def test_model_service_transport_channel_mtls_with_client_cert_source(transport_class): - with mock.patch( - "grpc.ssl_channel_credentials", autospec=True - ) as grpc_ssl_channel_cred: - with mock.patch.object( - transport_class, "create_channel" - ) as grpc_create_channel: - mock_ssl_cred = mock.Mock() - grpc_ssl_channel_cred.return_value = mock_ssl_cred + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel + response = client.get_iam_policy(request) - cred = ga_credentials.AnonymousCredentials() - with pytest.warns(DeprecationWarning): - with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (cred, None) - transport = transport_class( - host="squid.clam.whelk", - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=client_cert_source_callback, - ) - adc.assert_called_once() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] - grpc_ssl_channel_cred.assert_called_once_with( - certificate_chain=b"cert bytes", private_key=b"key bytes" - ) - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=cred, - credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - assert transport.grpc_channel == mock_grpc_channel - assert transport._ssl_channel_credentials == mock_ssl_cred + assert args[0] == request + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) -# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are -# removed from grpc/grpc_asyncio transport constructor. -@pytest.mark.parametrize( - "transport_class", - [transports.ModelServiceGrpcTransport, transports.ModelServiceGrpcAsyncIOTransport], -) -def test_model_service_transport_channel_mtls_with_adc(transport_class): - mock_ssl_cred = mock.Mock() - with mock.patch.multiple( - "google.auth.transport.grpc.SslCredentials", - __init__=mock.Mock(return_value=None), - ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), - ): - with mock.patch.object( - transport_class, "create_channel" - ) as grpc_create_channel: - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel - mock_cred = mock.Mock() + assert response.version == 774 - with pytest.warns(DeprecationWarning): - transport = transport_class( - host="squid.clam.whelk", - credentials=mock_cred, - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=None, - ) + assert response.etag == b"etag_blob" - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=mock_cred, - credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], + +@pytest.mark.asyncio +async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", ) - assert transport.grpc_channel == mock_grpc_channel + ) + response = await client.get_iam_policy(request) -def test_model_service_grpc_lro_client(): - client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", - ) - transport = client.transport + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] - # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsClient,) + assert args[0] == request - # Ensure that subsequent calls to the property send the exact same object. - assert transport.operations_client is transport.operations_client + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + assert response.version == 774 -def test_model_service_grpc_lro_async_client(): - client = ModelServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + assert response.etag == b"etag_blob" + + +def test_get_iam_policy_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), ) - transport = client.transport - # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient,) + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" - # Ensure that subsequent calls to the property send the exact same object. - assert transport.operations_client is transport.operations_client + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + client.get_iam_policy(request) -def test_endpoint_path(): - project = "squid" - location = "clam" - endpoint = "whelk" - expected = "projects/{project}/locations/{location}/endpoints/{endpoint}".format( - project=project, location=location, endpoint=endpoint, + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_iam_policy_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), ) - actual = ModelServiceClient.endpoint_path(project, location, endpoint) - assert expected == actual + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" -def test_parse_endpoint_path(): - expected = { - "project": "octopus", - "location": "oyster", - "endpoint": "nudibranch", - } - path = ModelServiceClient.endpoint_path(**expected) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) - # Check that the path construction is reversible. - actual = ModelServiceClient.parse_endpoint_path(path) - assert expected == actual + await client.get_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request -def test_model_path(): - project = "cuttlefish" - location = "mussel" - model = "winkle" - expected = "projects/{project}/locations/{location}/models/{model}".format( - project=project, location=location, model=model, + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_get_iam_policy_from_dict(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), ) - actual = ModelServiceClient.model_path(project, location, model) - assert expected == actual + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + response = client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() -def test_parse_model_path(): - expected = { - "project": "nautilus", - "location": "scallop", - "model": "abalone", - } - path = ModelServiceClient.model_path(**expected) - # Check that the path construction is reversible. - actual = ModelServiceClient.parse_model_path(path) - assert expected == actual +@pytest.mark.asyncio +async def test_get_iam_policy_from_dict_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() -def test_model_evaluation_path(): - project = "squid" - location = "clam" - model = "whelk" - evaluation = "octopus" - expected = "projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}".format( - project=project, location=location, model=model, evaluation=evaluation, - ) - actual = ModelServiceClient.model_evaluation_path( - project, location, model, evaluation +def test_test_iam_permissions(transport: str = "grpc"): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - assert expected == actual + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() -def test_parse_model_evaluation_path(): - expected = { - "project": "oyster", - "location": "nudibranch", - "model": "cuttlefish", - "evaluation": "mussel", - } - path = ModelServiceClient.model_evaluation_path(**expected) - - # Check that the path construction is reversible. - actual = ModelServiceClient.parse_model_evaluation_path(path) - assert expected == actual + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + response = client.test_iam_permissions(request) -def test_model_evaluation_slice_path(): - project = "winkle" - location = "nautilus" - model = "scallop" - evaluation = "abalone" - slice = "squid" - expected = "projects/{project}/locations/{location}/models/{model}/evaluations/{evaluation}/slices/{slice}".format( - project=project, - location=location, - model=model, - evaluation=evaluation, - slice=slice, - ) - actual = ModelServiceClient.model_evaluation_slice_path( - project, location, model, evaluation, slice - ) - assert expected == actual + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request -def test_parse_model_evaluation_slice_path(): - expected = { - "project": "clam", - "location": "whelk", - "model": "octopus", - "evaluation": "oyster", - "slice": "nudibranch", - } - path = ModelServiceClient.model_evaluation_slice_path(**expected) + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) - # Check that the path construction is reversible. - actual = ModelServiceClient.parse_model_evaluation_slice_path(path) - assert expected == actual + assert response.permissions == ["permissions_value"] -def test_training_pipeline_path(): - project = "cuttlefish" - location = "mussel" - training_pipeline = "winkle" - expected = "projects/{project}/locations/{location}/trainingPipelines/{training_pipeline}".format( - project=project, location=location, training_pipeline=training_pipeline, - ) - actual = ModelServiceClient.training_pipeline_path( - project, location, training_pipeline +@pytest.mark.asyncio +async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - assert expected == actual + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() -def test_parse_training_pipeline_path(): - expected = { - "project": "nautilus", - "location": "scallop", - "training_pipeline": "abalone", - } - path = ModelServiceClient.training_pipeline_path(**expected) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + ) - # Check that the path construction is reversible. - actual = ModelServiceClient.parse_training_pipeline_path(path) - assert expected == actual + response = await client.test_iam_permissions(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] -def test_common_billing_account_path(): - billing_account = "squid" - expected = "billingAccounts/{billing_account}".format( - billing_account=billing_account, - ) - actual = ModelServiceClient.common_billing_account_path(billing_account) - assert expected == actual + assert args[0] == request + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) -def test_parse_common_billing_account_path(): - expected = { - "billing_account": "clam", - } - path = ModelServiceClient.common_billing_account_path(**expected) + assert response.permissions == ["permissions_value"] - # Check that the path construction is reversible. - actual = ModelServiceClient.parse_common_billing_account_path(path) - assert expected == actual +def test_test_iam_permissions_field_headers(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" -def test_common_folder_path(): - folder = "whelk" - expected = "folders/{folder}".format(folder=folder,) - actual = ModelServiceClient.common_folder_path(folder) - assert expected == actual + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + client.test_iam_permissions(request) -def test_parse_common_folder_path(): - expected = { - "folder": "octopus", - } - path = ModelServiceClient.common_folder_path(**expected) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request - # Check that the path construction is reversible. - actual = ModelServiceClient.parse_common_folder_path(path) - assert expected == actual + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] -def test_common_organization_path(): - organization = "oyster" - expected = "organizations/{organization}".format(organization=organization,) - actual = ModelServiceClient.common_organization_path(organization) - assert expected == actual +@pytest.mark.asyncio +async def test_test_iam_permissions_field_headers_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" -def test_parse_common_organization_path(): - expected = { - "organization": "nudibranch", - } - path = ModelServiceClient.common_organization_path(**expected) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) - # Check that the path construction is reversible. - actual = ModelServiceClient.parse_common_organization_path(path) - assert expected == actual + await client.test_iam_permissions(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request -def test_common_project_path(): - project = "cuttlefish" - expected = "projects/{project}".format(project=project,) - actual = ModelServiceClient.common_project_path(project) - assert expected == actual + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] -def test_parse_common_project_path(): - expected = { - "project": "mussel", - } - path = ModelServiceClient.common_project_path(**expected) +def test_test_iam_permissions_from_dict(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() - # Check that the path construction is reversible. - actual = ModelServiceClient.parse_common_project_path(path) - assert expected == actual + response = client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() -def test_common_location_path(): - project = "winkle" - location = "nautilus" - expected = "projects/{project}/locations/{location}".format( - project=project, location=location, +@pytest.mark.asyncio +async def test_test_iam_permissions_from_dict_async(): + client = ModelServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), ) - actual = ModelServiceClient.common_location_path(project, location) - assert expected == actual + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + response = await client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() -def test_parse_common_location_path(): - expected = { - "project": "scallop", - "location": "abalone", - } - path = ModelServiceClient.common_location_path(**expected) - # Check that the path construction is reversible. - actual = ModelServiceClient.parse_common_location_path(path) - assert expected == actual +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + for transport, close_name in transports.items(): + client = ModelServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() -def test_client_withDEFAULT_CLIENT_INFO(): - client_info = gapic_v1.client_info.ClientInfo() - with mock.patch.object( - transports.ModelServiceTransport, "_prep_wrapped_messages" - ) as prep: +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: client = ModelServiceClient( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), transport=transport ) - prep.assert_called_once_with(client_info) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (ModelServiceClient, transports.ModelServiceGrpcTransport), + (ModelServiceAsyncClient, transports.ModelServiceGrpcAsyncIOTransport), + ], +) +def test_api_key_credentials(client_class, transport_class): with mock.patch.object( - transports.ModelServiceTransport, "_prep_wrapped_messages" - ) as prep: - transport_class = ModelServiceClient.get_transport_class() - transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, - ) - prep.assert_called_once_with(client_info) + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) diff --git a/tests/unit/gapic/aiplatform_v1beta1/test_pipeline_service.py b/tests/unit/gapic/aiplatform_v1beta1/test_pipeline_service.py index 7c78097cd6..f35c5aed19 100644 --- a/tests/unit/gapic/aiplatform_v1beta1/test_pipeline_service.py +++ b/tests/unit/gapic/aiplatform_v1beta1/test_pipeline_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,8 +14,13 @@ # limitations under the License. # import os -import mock -import packaging.version + +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock +except ImportError: + import mock import grpc from grpc.experimental import aio @@ -30,8 +35,10 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.aiplatform_v1beta1.services.pipeline_service import ( @@ -42,12 +49,6 @@ ) from google.cloud.aiplatform_v1beta1.services.pipeline_service import pagers from google.cloud.aiplatform_v1beta1.services.pipeline_service import transports -from google.cloud.aiplatform_v1beta1.services.pipeline_service.transports.base import ( - _API_CORE_VERSION, -) -from google.cloud.aiplatform_v1beta1.services.pipeline_service.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.aiplatform_v1beta1.types import artifact from google.cloud.aiplatform_v1beta1.types import context from google.cloud.aiplatform_v1beta1.types import deployed_model_ref @@ -59,6 +60,7 @@ from google.cloud.aiplatform_v1beta1.types import io from google.cloud.aiplatform_v1beta1.types import model from google.cloud.aiplatform_v1beta1.types import operation as gca_operation +from google.cloud.aiplatform_v1beta1.types import pipeline_failure_policy from google.cloud.aiplatform_v1beta1.types import pipeline_job from google.cloud.aiplatform_v1beta1.types import pipeline_job as gca_pipeline_job from google.cloud.aiplatform_v1beta1.types import pipeline_service @@ -68,6 +70,10 @@ training_pipeline as gca_training_pipeline, ) from google.cloud.aiplatform_v1beta1.types import value +from google.cloud.location import locations_pb2 +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 from google.oauth2 import service_account from google.protobuf import any_pb2 # type: ignore @@ -78,29 +84,6 @@ import google.auth -# TODO(busunkim): Once google-api-core >= 1.26.0 is required: -# - Delete all the api-core and auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - -requires_api_core_lt_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), - reason="This test requires google-api-core < 1.26.0", -) - -requires_api_core_gte_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), - reason="This test requires google-api-core >= 1.26.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -146,40 +129,81 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( - "client_class", [PipelineServiceClient, PipelineServiceAsyncClient,] + "client_class,transport_name", + [ + (PipelineServiceClient, "grpc"), + (PipelineServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_pipeline_service_client_from_service_account_info(client_class): +def test_pipeline_service_client_from_service_account_info( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.PipelineServiceGrpcTransport, "grpc"), + (transports.PipelineServiceGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_pipeline_service_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() @pytest.mark.parametrize( - "client_class", [PipelineServiceClient, PipelineServiceAsyncClient,] + "client_class,transport_name", + [ + (PipelineServiceClient, "grpc"), + (PipelineServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_pipeline_service_client_from_service_account_file(client_class): +def test_pipeline_service_client_from_service_account_file( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") def test_pipeline_service_client_get_transport_class(): @@ -232,7 +256,7 @@ def test_pipeline_service_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -241,6 +265,7 @@ def test_pipeline_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -248,7 +273,7 @@ def test_pipeline_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -257,6 +282,7 @@ def test_pipeline_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -264,7 +290,7 @@ def test_pipeline_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -273,26 +299,27 @@ def test_pipeline_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -301,6 +328,7 @@ def test_pipeline_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -360,7 +388,7 @@ def test_pipeline_service_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -377,6 +405,7 @@ def test_pipeline_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case ADC client cert is provided. Whether client cert is used depends on @@ -401,7 +430,7 @@ def test_pipeline_service_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -410,6 +439,7 @@ def test_pipeline_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case client_cert_source and ADC client cert are not provided. @@ -422,7 +452,7 @@ def test_pipeline_service_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -431,9 +461,91 @@ def test_pipeline_service_client_mtls_env_auto( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) +@pytest.mark.parametrize( + "client_class", [PipelineServiceClient, PipelineServiceAsyncClient] +) +@mock.patch.object( + PipelineServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(PipelineServiceClient), +) +@mock.patch.object( + PipelineServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(PipelineServiceAsyncClient), +) +def test_pipeline_service_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + @pytest.mark.parametrize( "client_class,transport_class,transport_name", [ @@ -449,10 +561,12 @@ def test_pipeline_service_client_client_options_scopes( client_class, transport_class, transport_name ): # Check the case scopes are provided. - options = client_options.ClientOptions(scopes=["1", "2"],) + options = client_options.ClientOptions( + scopes=["1", "2"], + ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -461,28 +575,36 @@ def test_pipeline_service_client_client_options_scopes( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (PipelineServiceClient, transports.PipelineServiceGrpcTransport, "grpc"), + ( + PipelineServiceClient, + transports.PipelineServiceGrpcTransport, + "grpc", + grpc_helpers, + ), ( PipelineServiceAsyncClient, transports.PipelineServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_pipeline_service_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -491,6 +613,7 @@ def test_pipeline_service_client_client_options_credentials_file( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -510,14 +633,87 @@ def test_pipeline_service_client_client_options_from_dict(): client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) -def test_create_training_pipeline( - transport: str = "grpc", request_type=pipeline_service.CreateTrainingPipelineRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + PipelineServiceClient, + transports.PipelineServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + PipelineServiceAsyncClient, + transports.PipelineServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_pipeline_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers ): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + pipeline_service.CreateTrainingPipelineRequest, + dict, + ], +) +def test_create_training_pipeline(request_type, transport: str = "grpc"): client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -533,6 +729,8 @@ def test_create_training_pipeline( name="name_value", display_name="display_name_value", training_task_definition="training_task_definition_value", + model_id="model_id_value", + parent_model="parent_model_value", state=pipeline_state.PipelineState.PIPELINE_STATE_QUEUED, ) response = client.create_training_pipeline(request) @@ -547,18 +745,17 @@ def test_create_training_pipeline( assert response.name == "name_value" assert response.display_name == "display_name_value" assert response.training_task_definition == "training_task_definition_value" + assert response.model_id == "model_id_value" + assert response.parent_model == "parent_model_value" assert response.state == pipeline_state.PipelineState.PIPELINE_STATE_QUEUED -def test_create_training_pipeline_from_dict(): - test_create_training_pipeline(request_type=dict) - - def test_create_training_pipeline_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -577,7 +774,8 @@ async def test_create_training_pipeline_async( request_type=pipeline_service.CreateTrainingPipelineRequest, ): client = PipelineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -594,6 +792,8 @@ async def test_create_training_pipeline_async( name="name_value", display_name="display_name_value", training_task_definition="training_task_definition_value", + model_id="model_id_value", + parent_model="parent_model_value", state=pipeline_state.PipelineState.PIPELINE_STATE_QUEUED, ) ) @@ -609,6 +809,8 @@ async def test_create_training_pipeline_async( assert response.name == "name_value" assert response.display_name == "display_name_value" assert response.training_task_definition == "training_task_definition_value" + assert response.model_id == "model_id_value" + assert response.parent_model == "parent_model_value" assert response.state == pipeline_state.PipelineState.PIPELINE_STATE_QUEUED @@ -618,13 +820,15 @@ async def test_create_training_pipeline_async_from_dict(): def test_create_training_pipeline_field_headers(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = pipeline_service.CreateTrainingPipelineRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -640,7 +844,10 @@ def test_create_training_pipeline_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -653,7 +860,7 @@ async def test_create_training_pipeline_field_headers_async(): # a field header. Set these to a non-empty value. request = pipeline_service.CreateTrainingPipelineRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -671,11 +878,16 @@ async def test_create_training_pipeline_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_create_training_pipeline_flattened(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -694,14 +906,18 @@ def test_create_training_pipeline_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].training_pipeline == gca_training_pipeline.TrainingPipeline( - name="name_value" - ) + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].training_pipeline + mock_val = gca_training_pipeline.TrainingPipeline(name="name_value") + assert arg == mock_val def test_create_training_pipeline_flattened_error(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -740,10 +956,12 @@ async def test_create_training_pipeline_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].training_pipeline == gca_training_pipeline.TrainingPipeline( - name="name_value" - ) + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].training_pipeline + mock_val = gca_training_pipeline.TrainingPipeline(name="name_value") + assert arg == mock_val @pytest.mark.asyncio @@ -762,11 +980,17 @@ async def test_create_training_pipeline_flattened_error_async(): ) -def test_get_training_pipeline( - transport: str = "grpc", request_type=pipeline_service.GetTrainingPipelineRequest -): +@pytest.mark.parametrize( + "request_type", + [ + pipeline_service.GetTrainingPipelineRequest, + dict, + ], +) +def test_get_training_pipeline(request_type, transport: str = "grpc"): client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -782,6 +1006,8 @@ def test_get_training_pipeline( name="name_value", display_name="display_name_value", training_task_definition="training_task_definition_value", + model_id="model_id_value", + parent_model="parent_model_value", state=pipeline_state.PipelineState.PIPELINE_STATE_QUEUED, ) response = client.get_training_pipeline(request) @@ -796,18 +1022,17 @@ def test_get_training_pipeline( assert response.name == "name_value" assert response.display_name == "display_name_value" assert response.training_task_definition == "training_task_definition_value" + assert response.model_id == "model_id_value" + assert response.parent_model == "parent_model_value" assert response.state == pipeline_state.PipelineState.PIPELINE_STATE_QUEUED -def test_get_training_pipeline_from_dict(): - test_get_training_pipeline(request_type=dict) - - def test_get_training_pipeline_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -826,7 +1051,8 @@ async def test_get_training_pipeline_async( request_type=pipeline_service.GetTrainingPipelineRequest, ): client = PipelineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -843,6 +1069,8 @@ async def test_get_training_pipeline_async( name="name_value", display_name="display_name_value", training_task_definition="training_task_definition_value", + model_id="model_id_value", + parent_model="parent_model_value", state=pipeline_state.PipelineState.PIPELINE_STATE_QUEUED, ) ) @@ -858,6 +1086,8 @@ async def test_get_training_pipeline_async( assert response.name == "name_value" assert response.display_name == "display_name_value" assert response.training_task_definition == "training_task_definition_value" + assert response.model_id == "model_id_value" + assert response.parent_model == "parent_model_value" assert response.state == pipeline_state.PipelineState.PIPELINE_STATE_QUEUED @@ -867,13 +1097,15 @@ async def test_get_training_pipeline_async_from_dict(): def test_get_training_pipeline_field_headers(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = pipeline_service.GetTrainingPipelineRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -889,7 +1121,10 @@ def test_get_training_pipeline_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -902,7 +1137,7 @@ async def test_get_training_pipeline_field_headers_async(): # a field header. Set these to a non-empty value. request = pipeline_service.GetTrainingPipelineRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -920,11 +1155,16 @@ async def test_get_training_pipeline_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_get_training_pipeline_flattened(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -934,23 +1174,30 @@ def test_get_training_pipeline_flattened(): call.return_value = training_pipeline.TrainingPipeline() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_training_pipeline(name="name_value",) + client.get_training_pipeline( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_training_pipeline_flattened_error(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.get_training_pipeline( - pipeline_service.GetTrainingPipelineRequest(), name="name_value", + pipeline_service.GetTrainingPipelineRequest(), + name="name_value", ) @@ -972,13 +1219,17 @@ async def test_get_training_pipeline_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_training_pipeline(name="name_value",) + response = await client.get_training_pipeline( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -991,15 +1242,22 @@ async def test_get_training_pipeline_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.get_training_pipeline( - pipeline_service.GetTrainingPipelineRequest(), name="name_value", + pipeline_service.GetTrainingPipelineRequest(), + name="name_value", ) -def test_list_training_pipelines( - transport: str = "grpc", request_type=pipeline_service.ListTrainingPipelinesRequest -): +@pytest.mark.parametrize( + "request_type", + [ + pipeline_service.ListTrainingPipelinesRequest, + dict, + ], +) +def test_list_training_pipelines(request_type, transport: str = "grpc"): client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1026,15 +1284,12 @@ def test_list_training_pipelines( assert response.next_page_token == "next_page_token_value" -def test_list_training_pipelines_from_dict(): - test_list_training_pipelines(request_type=dict) - - def test_list_training_pipelines_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1053,7 +1308,8 @@ async def test_list_training_pipelines_async( request_type=pipeline_service.ListTrainingPipelinesRequest, ): client = PipelineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1088,13 +1344,15 @@ async def test_list_training_pipelines_async_from_dict(): def test_list_training_pipelines_field_headers(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = pipeline_service.ListTrainingPipelinesRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1110,7 +1368,10 @@ def test_list_training_pipelines_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1123,7 +1384,7 @@ async def test_list_training_pipelines_field_headers_async(): # a field header. Set these to a non-empty value. request = pipeline_service.ListTrainingPipelinesRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1141,11 +1402,16 @@ async def test_list_training_pipelines_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_training_pipelines_flattened(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1155,23 +1421,30 @@ def test_list_training_pipelines_flattened(): call.return_value = pipeline_service.ListTrainingPipelinesResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_training_pipelines(parent="parent_value",) + client.list_training_pipelines( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_training_pipelines_flattened_error(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.list_training_pipelines( - pipeline_service.ListTrainingPipelinesRequest(), parent="parent_value", + pipeline_service.ListTrainingPipelinesRequest(), + parent="parent_value", ) @@ -1193,13 +1466,17 @@ async def test_list_training_pipelines_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_training_pipelines(parent="parent_value",) + response = await client.list_training_pipelines( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1212,12 +1489,16 @@ async def test_list_training_pipelines_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.list_training_pipelines( - pipeline_service.ListTrainingPipelinesRequest(), parent="parent_value", + pipeline_service.ListTrainingPipelinesRequest(), + parent="parent_value", ) -def test_list_training_pipelines_pager(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_training_pipelines_pager(transport_name: str = "grpc"): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1234,10 +1515,13 @@ def test_list_training_pipelines_pager(): next_page_token="abc", ), pipeline_service.ListTrainingPipelinesResponse( - training_pipelines=[], next_page_token="def", + training_pipelines=[], + next_page_token="def", ), pipeline_service.ListTrainingPipelinesResponse( - training_pipelines=[training_pipeline.TrainingPipeline(),], + training_pipelines=[ + training_pipeline.TrainingPipeline(), + ], next_page_token="ghi", ), pipeline_service.ListTrainingPipelinesResponse( @@ -1257,13 +1541,16 @@ def test_list_training_pipelines_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all(isinstance(i, training_pipeline.TrainingPipeline) for i in results) -def test_list_training_pipelines_pages(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_training_pipelines_pages(transport_name: str = "grpc"): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1280,10 +1567,13 @@ def test_list_training_pipelines_pages(): next_page_token="abc", ), pipeline_service.ListTrainingPipelinesResponse( - training_pipelines=[], next_page_token="def", + training_pipelines=[], + next_page_token="def", ), pipeline_service.ListTrainingPipelinesResponse( - training_pipelines=[training_pipeline.TrainingPipeline(),], + training_pipelines=[ + training_pipeline.TrainingPipeline(), + ], next_page_token="ghi", ), pipeline_service.ListTrainingPipelinesResponse( @@ -1322,10 +1612,13 @@ async def test_list_training_pipelines_async_pager(): next_page_token="abc", ), pipeline_service.ListTrainingPipelinesResponse( - training_pipelines=[], next_page_token="def", + training_pipelines=[], + next_page_token="def", ), pipeline_service.ListTrainingPipelinesResponse( - training_pipelines=[training_pipeline.TrainingPipeline(),], + training_pipelines=[ + training_pipeline.TrainingPipeline(), + ], next_page_token="ghi", ), pipeline_service.ListTrainingPipelinesResponse( @@ -1336,10 +1629,12 @@ async def test_list_training_pipelines_async_pager(): ), RuntimeError, ) - async_pager = await client.list_training_pipelines(request={},) + async_pager = await client.list_training_pipelines( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -1369,10 +1664,13 @@ async def test_list_training_pipelines_async_pages(): next_page_token="abc", ), pipeline_service.ListTrainingPipelinesResponse( - training_pipelines=[], next_page_token="def", + training_pipelines=[], + next_page_token="def", ), pipeline_service.ListTrainingPipelinesResponse( - training_pipelines=[training_pipeline.TrainingPipeline(),], + training_pipelines=[ + training_pipeline.TrainingPipeline(), + ], next_page_token="ghi", ), pipeline_service.ListTrainingPipelinesResponse( @@ -1384,17 +1682,25 @@ async def test_list_training_pipelines_async_pages(): RuntimeError, ) pages = [] - async for page_ in (await client.list_training_pipelines(request={})).pages: + async for page_ in ( + await client.list_training_pipelines(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_delete_training_pipeline( - transport: str = "grpc", request_type=pipeline_service.DeleteTrainingPipelineRequest -): +@pytest.mark.parametrize( + "request_type", + [ + pipeline_service.DeleteTrainingPipelineRequest, + dict, + ], +) +def test_delete_training_pipeline(request_type, transport: str = "grpc"): client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1418,15 +1724,12 @@ def test_delete_training_pipeline( assert isinstance(response, future.Future) -def test_delete_training_pipeline_from_dict(): - test_delete_training_pipeline(request_type=dict) - - def test_delete_training_pipeline_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1445,7 +1748,8 @@ async def test_delete_training_pipeline_async( request_type=pipeline_service.DeleteTrainingPipelineRequest, ): client = PipelineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1477,13 +1781,15 @@ async def test_delete_training_pipeline_async_from_dict(): def test_delete_training_pipeline_field_headers(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = pipeline_service.DeleteTrainingPipelineRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1499,7 +1805,10 @@ def test_delete_training_pipeline_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1512,7 +1821,7 @@ async def test_delete_training_pipeline_field_headers_async(): # a field header. Set these to a non-empty value. request = pipeline_service.DeleteTrainingPipelineRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1530,11 +1839,16 @@ async def test_delete_training_pipeline_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_delete_training_pipeline_flattened(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1544,23 +1858,30 @@ def test_delete_training_pipeline_flattened(): call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_training_pipeline(name="name_value",) + client.delete_training_pipeline( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_delete_training_pipeline_flattened_error(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.delete_training_pipeline( - pipeline_service.DeleteTrainingPipelineRequest(), name="name_value", + pipeline_service.DeleteTrainingPipelineRequest(), + name="name_value", ) @@ -1582,13 +1903,17 @@ async def test_delete_training_pipeline_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_training_pipeline(name="name_value",) + response = await client.delete_training_pipeline( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1601,15 +1926,22 @@ async def test_delete_training_pipeline_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.delete_training_pipeline( - pipeline_service.DeleteTrainingPipelineRequest(), name="name_value", + pipeline_service.DeleteTrainingPipelineRequest(), + name="name_value", ) -def test_cancel_training_pipeline( - transport: str = "grpc", request_type=pipeline_service.CancelTrainingPipelineRequest -): +@pytest.mark.parametrize( + "request_type", + [ + pipeline_service.CancelTrainingPipelineRequest, + dict, + ], +) +def test_cancel_training_pipeline(request_type, transport: str = "grpc"): client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1633,15 +1965,12 @@ def test_cancel_training_pipeline( assert response is None -def test_cancel_training_pipeline_from_dict(): - test_cancel_training_pipeline(request_type=dict) - - def test_cancel_training_pipeline_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1660,7 +1989,8 @@ async def test_cancel_training_pipeline_async( request_type=pipeline_service.CancelTrainingPipelineRequest, ): client = PipelineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1690,13 +2020,15 @@ async def test_cancel_training_pipeline_async_from_dict(): def test_cancel_training_pipeline_field_headers(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) - - # Any value that is part of the HTTP/1.1 URI should be sent as + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = pipeline_service.CancelTrainingPipelineRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1712,7 +2044,10 @@ def test_cancel_training_pipeline_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1725,7 +2060,7 @@ async def test_cancel_training_pipeline_field_headers_async(): # a field header. Set these to a non-empty value. request = pipeline_service.CancelTrainingPipelineRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1741,11 +2076,16 @@ async def test_cancel_training_pipeline_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_cancel_training_pipeline_flattened(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1755,23 +2095,30 @@ def test_cancel_training_pipeline_flattened(): call.return_value = None # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.cancel_training_pipeline(name="name_value",) + client.cancel_training_pipeline( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_cancel_training_pipeline_flattened_error(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.cancel_training_pipeline( - pipeline_service.CancelTrainingPipelineRequest(), name="name_value", + pipeline_service.CancelTrainingPipelineRequest(), + name="name_value", ) @@ -1791,13 +2138,17 @@ async def test_cancel_training_pipeline_flattened_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.cancel_training_pipeline(name="name_value",) + response = await client.cancel_training_pipeline( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1810,15 +2161,22 @@ async def test_cancel_training_pipeline_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.cancel_training_pipeline( - pipeline_service.CancelTrainingPipelineRequest(), name="name_value", + pipeline_service.CancelTrainingPipelineRequest(), + name="name_value", ) -def test_create_pipeline_job( - transport: str = "grpc", request_type=pipeline_service.CreatePipelineJobRequest -): +@pytest.mark.parametrize( + "request_type", + [ + pipeline_service.CreatePipelineJobRequest, + dict, + ], +) +def test_create_pipeline_job(request_type, transport: str = "grpc"): client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1836,6 +2194,7 @@ def test_create_pipeline_job( state=pipeline_state.PipelineState.PIPELINE_STATE_QUEUED, service_account="service_account_value", network="network_value", + template_uri="template_uri_value", ) response = client.create_pipeline_job(request) @@ -1851,17 +2210,15 @@ def test_create_pipeline_job( assert response.state == pipeline_state.PipelineState.PIPELINE_STATE_QUEUED assert response.service_account == "service_account_value" assert response.network == "network_value" - - -def test_create_pipeline_job_from_dict(): - test_create_pipeline_job(request_type=dict) + assert response.template_uri == "template_uri_value" def test_create_pipeline_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1880,7 +2237,8 @@ async def test_create_pipeline_job_async( request_type=pipeline_service.CreatePipelineJobRequest, ): client = PipelineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1899,6 +2257,7 @@ async def test_create_pipeline_job_async( state=pipeline_state.PipelineState.PIPELINE_STATE_QUEUED, service_account="service_account_value", network="network_value", + template_uri="template_uri_value", ) ) response = await client.create_pipeline_job(request) @@ -1915,6 +2274,7 @@ async def test_create_pipeline_job_async( assert response.state == pipeline_state.PipelineState.PIPELINE_STATE_QUEUED assert response.service_account == "service_account_value" assert response.network == "network_value" + assert response.template_uri == "template_uri_value" @pytest.mark.asyncio @@ -1923,13 +2283,15 @@ async def test_create_pipeline_job_async_from_dict(): def test_create_pipeline_job_field_headers(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = pipeline_service.CreatePipelineJobRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1945,7 +2307,10 @@ def test_create_pipeline_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1958,7 +2323,7 @@ async def test_create_pipeline_job_field_headers_async(): # a field header. Set these to a non-empty value. request = pipeline_service.CreatePipelineJobRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1976,11 +2341,16 @@ async def test_create_pipeline_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_create_pipeline_job_flattened(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2000,13 +2370,21 @@ def test_create_pipeline_job_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].pipeline_job == gca_pipeline_job.PipelineJob(name="name_value") - assert args[0].pipeline_job_id == "pipeline_job_id_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].pipeline_job + mock_val = gca_pipeline_job.PipelineJob(name="name_value") + assert arg == mock_val + arg = args[0].pipeline_job_id + mock_val = "pipeline_job_id_value" + assert arg == mock_val def test_create_pipeline_job_flattened_error(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -2047,9 +2425,15 @@ async def test_create_pipeline_job_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].pipeline_job == gca_pipeline_job.PipelineJob(name="name_value") - assert args[0].pipeline_job_id == "pipeline_job_id_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].pipeline_job + mock_val = gca_pipeline_job.PipelineJob(name="name_value") + assert arg == mock_val + arg = args[0].pipeline_job_id + mock_val = "pipeline_job_id_value" + assert arg == mock_val @pytest.mark.asyncio @@ -2069,11 +2453,17 @@ async def test_create_pipeline_job_flattened_error_async(): ) -def test_get_pipeline_job( - transport: str = "grpc", request_type=pipeline_service.GetPipelineJobRequest -): +@pytest.mark.parametrize( + "request_type", + [ + pipeline_service.GetPipelineJobRequest, + dict, + ], +) +def test_get_pipeline_job(request_type, transport: str = "grpc"): client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2089,6 +2479,7 @@ def test_get_pipeline_job( state=pipeline_state.PipelineState.PIPELINE_STATE_QUEUED, service_account="service_account_value", network="network_value", + template_uri="template_uri_value", ) response = client.get_pipeline_job(request) @@ -2104,17 +2495,15 @@ def test_get_pipeline_job( assert response.state == pipeline_state.PipelineState.PIPELINE_STATE_QUEUED assert response.service_account == "service_account_value" assert response.network == "network_value" - - -def test_get_pipeline_job_from_dict(): - test_get_pipeline_job(request_type=dict) + assert response.template_uri == "template_uri_value" def test_get_pipeline_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2130,7 +2519,8 @@ async def test_get_pipeline_job_async( transport: str = "grpc_asyncio", request_type=pipeline_service.GetPipelineJobRequest ): client = PipelineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2147,6 +2537,7 @@ async def test_get_pipeline_job_async( state=pipeline_state.PipelineState.PIPELINE_STATE_QUEUED, service_account="service_account_value", network="network_value", + template_uri="template_uri_value", ) ) response = await client.get_pipeline_job(request) @@ -2163,6 +2554,7 @@ async def test_get_pipeline_job_async( assert response.state == pipeline_state.PipelineState.PIPELINE_STATE_QUEUED assert response.service_account == "service_account_value" assert response.network == "network_value" + assert response.template_uri == "template_uri_value" @pytest.mark.asyncio @@ -2171,13 +2563,15 @@ async def test_get_pipeline_job_async_from_dict(): def test_get_pipeline_job_field_headers(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = pipeline_service.GetPipelineJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_pipeline_job), "__call__") as call: @@ -2191,7 +2585,10 @@ def test_get_pipeline_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2204,7 +2601,7 @@ async def test_get_pipeline_job_field_headers_async(): # a field header. Set these to a non-empty value. request = pipeline_service.GetPipelineJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_pipeline_job), "__call__") as call: @@ -2220,11 +2617,16 @@ async def test_get_pipeline_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_get_pipeline_job_flattened(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_pipeline_job), "__call__") as call: @@ -2232,23 +2634,30 @@ def test_get_pipeline_job_flattened(): call.return_value = pipeline_job.PipelineJob() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_pipeline_job(name="name_value",) + client.get_pipeline_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_pipeline_job_flattened_error(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.get_pipeline_job( - pipeline_service.GetPipelineJobRequest(), name="name_value", + pipeline_service.GetPipelineJobRequest(), + name="name_value", ) @@ -2268,13 +2677,17 @@ async def test_get_pipeline_job_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_pipeline_job(name="name_value",) + response = await client.get_pipeline_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -2287,15 +2700,22 @@ async def test_get_pipeline_job_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.get_pipeline_job( - pipeline_service.GetPipelineJobRequest(), name="name_value", + pipeline_service.GetPipelineJobRequest(), + name="name_value", ) -def test_list_pipeline_jobs( - transport: str = "grpc", request_type=pipeline_service.ListPipelineJobsRequest -): +@pytest.mark.parametrize( + "request_type", + [ + pipeline_service.ListPipelineJobsRequest, + dict, + ], +) +def test_list_pipeline_jobs(request_type, transport: str = "grpc"): client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2322,15 +2742,12 @@ def test_list_pipeline_jobs( assert response.next_page_token == "next_page_token_value" -def test_list_pipeline_jobs_from_dict(): - test_list_pipeline_jobs(request_type=dict) - - def test_list_pipeline_jobs_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2349,7 +2766,8 @@ async def test_list_pipeline_jobs_async( request_type=pipeline_service.ListPipelineJobsRequest, ): client = PipelineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2384,13 +2802,15 @@ async def test_list_pipeline_jobs_async_from_dict(): def test_list_pipeline_jobs_field_headers(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = pipeline_service.ListPipelineJobsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2406,7 +2826,10 @@ def test_list_pipeline_jobs_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2419,7 +2842,7 @@ async def test_list_pipeline_jobs_field_headers_async(): # a field header. Set these to a non-empty value. request = pipeline_service.ListPipelineJobsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2437,11 +2860,16 @@ async def test_list_pipeline_jobs_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_pipeline_jobs_flattened(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2451,23 +2879,30 @@ def test_list_pipeline_jobs_flattened(): call.return_value = pipeline_service.ListPipelineJobsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_pipeline_jobs(parent="parent_value",) + client.list_pipeline_jobs( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_pipeline_jobs_flattened_error(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.list_pipeline_jobs( - pipeline_service.ListPipelineJobsRequest(), parent="parent_value", + pipeline_service.ListPipelineJobsRequest(), + parent="parent_value", ) @@ -2489,13 +2924,17 @@ async def test_list_pipeline_jobs_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_pipeline_jobs(parent="parent_value",) + response = await client.list_pipeline_jobs( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -2508,12 +2947,16 @@ async def test_list_pipeline_jobs_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.list_pipeline_jobs( - pipeline_service.ListPipelineJobsRequest(), parent="parent_value", + pipeline_service.ListPipelineJobsRequest(), + parent="parent_value", ) -def test_list_pipeline_jobs_pager(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_pipeline_jobs_pager(transport_name: str = "grpc"): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2530,13 +2973,20 @@ def test_list_pipeline_jobs_pager(): next_page_token="abc", ), pipeline_service.ListPipelineJobsResponse( - pipeline_jobs=[], next_page_token="def", + pipeline_jobs=[], + next_page_token="def", ), pipeline_service.ListPipelineJobsResponse( - pipeline_jobs=[pipeline_job.PipelineJob(),], next_page_token="ghi", + pipeline_jobs=[ + pipeline_job.PipelineJob(), + ], + next_page_token="ghi", ), pipeline_service.ListPipelineJobsResponse( - pipeline_jobs=[pipeline_job.PipelineJob(), pipeline_job.PipelineJob(),], + pipeline_jobs=[ + pipeline_job.PipelineJob(), + pipeline_job.PipelineJob(), + ], ), RuntimeError, ) @@ -2549,13 +2999,16 @@ def test_list_pipeline_jobs_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all(isinstance(i, pipeline_job.PipelineJob) for i in results) -def test_list_pipeline_jobs_pages(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_pipeline_jobs_pages(transport_name: str = "grpc"): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2572,13 +3025,20 @@ def test_list_pipeline_jobs_pages(): next_page_token="abc", ), pipeline_service.ListPipelineJobsResponse( - pipeline_jobs=[], next_page_token="def", + pipeline_jobs=[], + next_page_token="def", ), pipeline_service.ListPipelineJobsResponse( - pipeline_jobs=[pipeline_job.PipelineJob(),], next_page_token="ghi", + pipeline_jobs=[ + pipeline_job.PipelineJob(), + ], + next_page_token="ghi", ), pipeline_service.ListPipelineJobsResponse( - pipeline_jobs=[pipeline_job.PipelineJob(), pipeline_job.PipelineJob(),], + pipeline_jobs=[ + pipeline_job.PipelineJob(), + pipeline_job.PipelineJob(), + ], ), RuntimeError, ) @@ -2610,20 +3070,29 @@ async def test_list_pipeline_jobs_async_pager(): next_page_token="abc", ), pipeline_service.ListPipelineJobsResponse( - pipeline_jobs=[], next_page_token="def", + pipeline_jobs=[], + next_page_token="def", ), pipeline_service.ListPipelineJobsResponse( - pipeline_jobs=[pipeline_job.PipelineJob(),], next_page_token="ghi", + pipeline_jobs=[ + pipeline_job.PipelineJob(), + ], + next_page_token="ghi", ), pipeline_service.ListPipelineJobsResponse( - pipeline_jobs=[pipeline_job.PipelineJob(), pipeline_job.PipelineJob(),], + pipeline_jobs=[ + pipeline_job.PipelineJob(), + pipeline_job.PipelineJob(), + ], ), RuntimeError, ) - async_pager = await client.list_pipeline_jobs(request={},) + async_pager = await client.list_pipeline_jobs( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -2653,28 +3122,43 @@ async def test_list_pipeline_jobs_async_pages(): next_page_token="abc", ), pipeline_service.ListPipelineJobsResponse( - pipeline_jobs=[], next_page_token="def", + pipeline_jobs=[], + next_page_token="def", ), pipeline_service.ListPipelineJobsResponse( - pipeline_jobs=[pipeline_job.PipelineJob(),], next_page_token="ghi", + pipeline_jobs=[ + pipeline_job.PipelineJob(), + ], + next_page_token="ghi", ), pipeline_service.ListPipelineJobsResponse( - pipeline_jobs=[pipeline_job.PipelineJob(), pipeline_job.PipelineJob(),], + pipeline_jobs=[ + pipeline_job.PipelineJob(), + pipeline_job.PipelineJob(), + ], ), RuntimeError, ) pages = [] - async for page_ in (await client.list_pipeline_jobs(request={})).pages: + async for page_ in ( + await client.list_pipeline_jobs(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_delete_pipeline_job( - transport: str = "grpc", request_type=pipeline_service.DeletePipelineJobRequest -): +@pytest.mark.parametrize( + "request_type", + [ + pipeline_service.DeletePipelineJobRequest, + dict, + ], +) +def test_delete_pipeline_job(request_type, transport: str = "grpc"): client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2698,15 +3182,12 @@ def test_delete_pipeline_job( assert isinstance(response, future.Future) -def test_delete_pipeline_job_from_dict(): - test_delete_pipeline_job(request_type=dict) - - def test_delete_pipeline_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2725,7 +3206,8 @@ async def test_delete_pipeline_job_async( request_type=pipeline_service.DeletePipelineJobRequest, ): client = PipelineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2757,13 +3239,15 @@ async def test_delete_pipeline_job_async_from_dict(): def test_delete_pipeline_job_field_headers(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = pipeline_service.DeletePipelineJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2779,7 +3263,10 @@ def test_delete_pipeline_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2792,7 +3279,7 @@ async def test_delete_pipeline_job_field_headers_async(): # a field header. Set these to a non-empty value. request = pipeline_service.DeletePipelineJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2810,11 +3297,16 @@ async def test_delete_pipeline_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_delete_pipeline_job_flattened(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2824,23 +3316,30 @@ def test_delete_pipeline_job_flattened(): call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_pipeline_job(name="name_value",) + client.delete_pipeline_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_delete_pipeline_job_flattened_error(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.delete_pipeline_job( - pipeline_service.DeletePipelineJobRequest(), name="name_value", + pipeline_service.DeletePipelineJobRequest(), + name="name_value", ) @@ -2862,13 +3361,17 @@ async def test_delete_pipeline_job_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_pipeline_job(name="name_value",) + response = await client.delete_pipeline_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -2881,15 +3384,22 @@ async def test_delete_pipeline_job_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.delete_pipeline_job( - pipeline_service.DeletePipelineJobRequest(), name="name_value", + pipeline_service.DeletePipelineJobRequest(), + name="name_value", ) -def test_cancel_pipeline_job( - transport: str = "grpc", request_type=pipeline_service.CancelPipelineJobRequest -): +@pytest.mark.parametrize( + "request_type", + [ + pipeline_service.CancelPipelineJobRequest, + dict, + ], +) +def test_cancel_pipeline_job(request_type, transport: str = "grpc"): client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2913,15 +3423,12 @@ def test_cancel_pipeline_job( assert response is None -def test_cancel_pipeline_job_from_dict(): - test_cancel_pipeline_job(request_type=dict) - - def test_cancel_pipeline_job_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2940,7 +3447,8 @@ async def test_cancel_pipeline_job_async( request_type=pipeline_service.CancelPipelineJobRequest, ): client = PipelineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2970,13 +3478,15 @@ async def test_cancel_pipeline_job_async_from_dict(): def test_cancel_pipeline_job_field_headers(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = pipeline_service.CancelPipelineJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2992,7 +3502,10 @@ def test_cancel_pipeline_job_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -3005,7 +3518,7 @@ async def test_cancel_pipeline_job_field_headers_async(): # a field header. Set these to a non-empty value. request = pipeline_service.CancelPipelineJobRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3021,11 +3534,16 @@ async def test_cancel_pipeline_job_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_cancel_pipeline_job_flattened(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3035,23 +3553,30 @@ def test_cancel_pipeline_job_flattened(): call.return_value = None # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.cancel_pipeline_job(name="name_value",) + client.cancel_pipeline_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_cancel_pipeline_job_flattened_error(): - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.cancel_pipeline_job( - pipeline_service.CancelPipelineJobRequest(), name="name_value", + pipeline_service.CancelPipelineJobRequest(), + name="name_value", ) @@ -3071,13 +3596,17 @@ async def test_cancel_pipeline_job_flattened_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.cancel_pipeline_job(name="name_value",) + response = await client.cancel_pipeline_job( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -3090,7 +3619,8 @@ async def test_cancel_pipeline_job_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.cancel_pipeline_job( - pipeline_service.CancelPipelineJobRequest(), name="name_value", + pipeline_service.CancelPipelineJobRequest(), + name="name_value", ) @@ -3101,7 +3631,8 @@ def test_credentials_transport_error(): ) with pytest.raises(ValueError): client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # It is an error to provide a credentials file and a transport instance. @@ -3114,13 +3645,34 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.PipelineServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = PipelineServiceClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = PipelineServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.PipelineServiceGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = PipelineServiceClient( - client_options={"scopes": ["1", "2"]}, transport=transport, + client_options={"scopes": ["1", "2"]}, + transport=transport, ) @@ -3163,10 +3715,28 @@ def test_transport_adc(transport_class): adc.assert_called_once() +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = PipelineServiceClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + def test_transport_grpc_default(): # A client should use the gRPC transport by default. - client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials(),) - assert isinstance(client.transport, transports.PipelineServiceGrpcTransport,) + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.PipelineServiceGrpcTransport, + ) def test_pipeline_service_base_transport_error(): @@ -3201,18 +3771,38 @@ def test_pipeline_service_base_transport(): "list_pipeline_jobs", "delete_pipeline_job", "cancel_pipeline_job", + "set_iam_policy", + "get_iam_policy", + "test_iam_permissions", + "get_location", + "list_locations", + "get_operation", + "wait_operation", + "cancel_operation", + "delete_operation", + "list_operations", ) for method in methods: with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + # Additionally, the LRO client (a property) should # also raise NotImplementedError with pytest.raises(NotImplementedError): transport.operations_client + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + -@requires_google_auth_gte_1_25_0 def test_pipeline_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -3223,7 +3813,8 @@ def test_pipeline_service_base_transport_with_credentials_file(): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PipelineServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", + credentials_file="credentials.json", + quota_project_id="octopus", ) load_creds.assert_called_once_with( "credentials.json", @@ -3233,26 +3824,6 @@ def test_pipeline_service_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_pipeline_service_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.aiplatform_v1beta1.services.pipeline_service.transports.PipelineServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.PipelineServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - def test_pipeline_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( @@ -3264,7 +3835,6 @@ def test_pipeline_service_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_pipeline_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -3277,18 +3847,6 @@ def test_pipeline_service_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_pipeline_service_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - PipelineServiceClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -3296,7 +3854,6 @@ def test_pipeline_service_auth_adc_old_google_auth(): transports.PipelineServiceGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_pipeline_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -3311,33 +3868,12 @@ def test_pipeline_service_transport_auth_adc(transport_class): @pytest.mark.parametrize( - "transport_class", - [ - transports.PipelineServiceGrpcTransport, - transports.PipelineServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_pipeline_service_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", + "transport_class,grpc_helpers", [ (transports.PipelineServiceGrpcTransport, grpc_helpers), (transports.PipelineServiceGrpcAsyncIOTransport, grpc_helpers_async), ], ) -@requires_api_core_gte_1_26_0 def test_pipeline_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -3366,79 +3902,6 @@ def test_pipeline_service_transport_create_channel(transport_class, grpc_helpers ) -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.PipelineServiceGrpcTransport, grpc_helpers), - (transports.PipelineServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_pipeline_service_transport_create_channel_old_api_core( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class(quota_project_id="octopus") - - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.PipelineServiceGrpcTransport, grpc_helpers), - (transports.PipelineServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_pipeline_service_transport_create_channel_user_scopes( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=["1", "2"], - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -3461,7 +3924,7 @@ def test_pipeline_service_grpc_transport_client_cert_source_for_mtls(transport_c "squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_channel_creds, quota_project_id=None, options=[ @@ -3484,24 +3947,40 @@ def test_pipeline_service_grpc_transport_client_cert_source_for_mtls(transport_c ) -def test_pipeline_service_host_no_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_pipeline_service_host_no_port(transport_name): client = PipelineServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="aiplatform.googleapis.com" ), + transport=transport_name, ) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") -def test_pipeline_service_host_with_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_pipeline_service_host_with_port(transport_name): client = PipelineServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="aiplatform.googleapis.com:8000" ), + transport=transport_name, ) - assert client.transport._host == "aiplatform.googleapis.com:8000" + assert client.transport._host == ("aiplatform.googleapis.com:8000") def test_pipeline_service_grpc_transport_channel(): @@ -3509,7 +3988,8 @@ def test_pipeline_service_grpc_transport_channel(): # Check that channel is used if provided. transport = transports.PipelineServiceGrpcTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -3521,7 +4001,8 @@ def test_pipeline_service_grpc_asyncio_transport_channel(): # Check that channel is used if provided. transport = transports.PipelineServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -3570,7 +4051,7 @@ def test_pipeline_service_transport_channel_mtls_with_client_cert_source( "mtls.squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -3617,7 +4098,7 @@ def test_pipeline_service_transport_channel_mtls_with_adc(transport_class): "mtls.squid.clam.whelk:443", credentials=mock_cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -3630,12 +4111,16 @@ def test_pipeline_service_transport_channel_mtls_with_adc(transport_class): def test_pipeline_service_grpc_lro_client(): client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -3643,12 +4128,16 @@ def test_pipeline_service_grpc_lro_client(): def test_pipeline_service_grpc_lro_async_client(): client = PipelineServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -3721,7 +4210,9 @@ def test_custom_job_path(): location = "nudibranch" custom_job = "cuttlefish" expected = "projects/{project}/locations/{location}/customJobs/{custom_job}".format( - project=project, location=location, custom_job=custom_job, + project=project, + location=location, + custom_job=custom_job, ) actual = PipelineServiceClient.custom_job_path(project, location, custom_job) assert expected == actual @@ -3745,7 +4236,9 @@ def test_endpoint_path(): location = "abalone" endpoint = "squid" expected = "projects/{project}/locations/{location}/endpoints/{endpoint}".format( - project=project, location=location, endpoint=endpoint, + project=project, + location=location, + endpoint=endpoint, ) actual = PipelineServiceClient.endpoint_path(project, location, endpoint) assert expected == actual @@ -3800,7 +4293,9 @@ def test_model_path(): location = "clam" model = "whelk" expected = "projects/{project}/locations/{location}/models/{model}".format( - project=project, location=location, model=model, + project=project, + location=location, + model=model, ) actual = PipelineServiceClient.model_path(project, location, model) assert expected == actual @@ -3823,7 +4318,8 @@ def test_network_path(): project = "cuttlefish" network = "mussel" expected = "projects/{project}/global/networks/{network}".format( - project=project, network=network, + project=project, + network=network, ) actual = PipelineServiceClient.network_path(project, network) assert expected == actual @@ -3845,8 +4341,12 @@ def test_pipeline_job_path(): project = "scallop" location = "abalone" pipeline_job = "squid" - expected = "projects/{project}/locations/{location}/pipelineJobs/{pipeline_job}".format( - project=project, location=location, pipeline_job=pipeline_job, + expected = ( + "projects/{project}/locations/{location}/pipelineJobs/{pipeline_job}".format( + project=project, + location=location, + pipeline_job=pipeline_job, + ) ) actual = PipelineServiceClient.pipeline_job_path(project, location, pipeline_job) assert expected == actual @@ -3870,7 +4370,9 @@ def test_training_pipeline_path(): location = "nudibranch" training_pipeline = "cuttlefish" expected = "projects/{project}/locations/{location}/trainingPipelines/{training_pipeline}".format( - project=project, location=location, training_pipeline=training_pipeline, + project=project, + location=location, + training_pipeline=training_pipeline, ) actual = PipelineServiceClient.training_pipeline_path( project, location, training_pipeline @@ -3913,7 +4415,9 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "squid" - expected = "folders/{folder}".format(folder=folder,) + expected = "folders/{folder}".format( + folder=folder, + ) actual = PipelineServiceClient.common_folder_path(folder) assert expected == actual @@ -3931,7 +4435,9 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "whelk" - expected = "organizations/{organization}".format(organization=organization,) + expected = "organizations/{organization}".format( + organization=organization, + ) actual = PipelineServiceClient.common_organization_path(organization) assert expected == actual @@ -3949,7 +4455,9 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "oyster" - expected = "projects/{project}".format(project=project,) + expected = "projects/{project}".format( + project=project, + ) actual = PipelineServiceClient.common_project_path(project) assert expected == actual @@ -3969,7 +4477,8 @@ def test_common_location_path(): project = "cuttlefish" location = "mussel" expected = "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) actual = PipelineServiceClient.common_location_path(project, location) assert expected == actual @@ -3987,14 +4496,15 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( transports.PipelineServiceTransport, "_prep_wrapped_messages" ) as prep: client = PipelineServiceClient( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4003,6 +4513,1593 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = PipelineServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_delete_operation(transport: str = "grpc"): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_operation(transport: str = "grpc"): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_operation_field_headers(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = None + + client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_operation_field_headers_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_delete_operation_from_dict(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_delete_operation_from_dict_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_cancel_operation(transport: str = "grpc"): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation(transport: str = "grpc"): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_wait_operation(transport: str = "grpc"): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_wait_operation(transport: str = "grpc"): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_wait_operation_field_headers(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_wait_operation_field_headers_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_wait_operation_from_dict(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_wait_operation_from_dict_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_operation(transport: str = "grpc"): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_get_operation(transport: str = "grpc"): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_get_operation_field_headers(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_get_operation_from_dict(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_operations(transport: str = "grpc"): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + response = client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +@pytest.mark.asyncio +async def test_list_operations(transport: str = "grpc"): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +def test_list_operations_field_headers(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_operations_field_headers_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_operations_from_dict(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + response = client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_operations_from_dict_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_locations(transport: str = "grpc"): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + response = client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +@pytest.mark.asyncio +async def test_list_locations(transport: str = "grpc"): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +def test_list_locations_field_headers(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_locations_field_headers_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_locations_from_dict(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + response = client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_locations_from_dict_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_location(transport: str = "grpc"): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + response = client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +@pytest.mark.asyncio +async def test_get_location_async(transport: str = "grpc_asyncio"): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +def test_get_location_field_headers(): + client = PipelineServiceClient(credentials=ga_credentials.AnonymousCredentials()) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = locations_pb2.Location() + + client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_location_field_headers_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials() + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +def test_get_location_from_dict(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + response = client.get_location( + request={ + "name": "locations/abc", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_location_from_dict_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_set_iam_policy(transport: str = "grpc"): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + response = client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + response = await client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_set_iam_policy_field_headers(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_set_iam_policy_field_headers_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_set_iam_policy_from_dict(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_set_iam_policy_from_dict_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +def test_get_iam_policy(transport: str = "grpc"): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + + response = client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + + response = await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_get_iam_policy_field_headers(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_iam_policy_field_headers_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_get_iam_policy_from_dict(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_iam_policy_from_dict_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +def test_test_iam_permissions(transport: str = "grpc"): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + + response = client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + ) + + response = await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +def test_test_iam_permissions_field_headers(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_field_headers_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_test_iam_permissions_from_dict(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + response = client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_from_dict_async(): + client = PipelineServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + response = await client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = PipelineServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (PipelineServiceClient, transports.PipelineServiceGrpcTransport), + (PipelineServiceAsyncClient, transports.PipelineServiceGrpcAsyncIOTransport), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) diff --git a/tests/unit/gapic/aiplatform_v1beta1/test_prediction_service.py b/tests/unit/gapic/aiplatform_v1beta1/test_prediction_service.py index a36714bb87..d9e59879e3 100644 --- a/tests/unit/gapic/aiplatform_v1beta1/test_prediction_service.py +++ b/tests/unit/gapic/aiplatform_v1beta1/test_prediction_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,8 +14,13 @@ # limitations under the License. # import os -import mock -import packaging.version + +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock +except ImportError: + import mock import grpc from grpc.experimental import aio @@ -24,11 +29,13 @@ from proto.marshal.rules.dates import DurationRule, TimestampRule +from google.api import httpbody_pb2 # type: ignore from google.api_core import client_options from google.api_core import exceptions as core_exceptions from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.aiplatform_v1beta1.services.prediction_service import ( @@ -38,42 +45,20 @@ PredictionServiceClient, ) from google.cloud.aiplatform_v1beta1.services.prediction_service import transports -from google.cloud.aiplatform_v1beta1.services.prediction_service.transports.base import ( - _API_CORE_VERSION, -) -from google.cloud.aiplatform_v1beta1.services.prediction_service.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.aiplatform_v1beta1.types import explanation +from google.cloud.aiplatform_v1beta1.types import io from google.cloud.aiplatform_v1beta1.types import prediction_service +from google.cloud.location import locations_pb2 +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore +from google.longrunning import operations_pb2 from google.oauth2 import service_account +from google.protobuf import any_pb2 # type: ignore from google.protobuf import struct_pb2 # type: ignore import google.auth -# TODO(busunkim): Once google-api-core >= 1.26.0 is required: -# - Delete all the api-core and auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - -requires_api_core_lt_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), - reason="This test requires google-api-core < 1.26.0", -) - -requires_api_core_gte_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), - reason="This test requires google-api-core >= 1.26.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -120,40 +105,81 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( - "client_class", [PredictionServiceClient, PredictionServiceAsyncClient,] + "client_class,transport_name", + [ + (PredictionServiceClient, "grpc"), + (PredictionServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_prediction_service_client_from_service_account_info(client_class): +def test_prediction_service_client_from_service_account_info( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.PredictionServiceGrpcTransport, "grpc"), + (transports.PredictionServiceGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_prediction_service_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() @pytest.mark.parametrize( - "client_class", [PredictionServiceClient, PredictionServiceAsyncClient,] + "client_class,transport_name", + [ + (PredictionServiceClient, "grpc"), + (PredictionServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_prediction_service_client_from_service_account_file(client_class): +def test_prediction_service_client_from_service_account_file( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") def test_prediction_service_client_get_transport_class(): @@ -206,7 +232,7 @@ def test_prediction_service_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -215,6 +241,7 @@ def test_prediction_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -222,7 +249,7 @@ def test_prediction_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -231,6 +258,7 @@ def test_prediction_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -238,7 +266,7 @@ def test_prediction_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -247,26 +275,27 @@ def test_prediction_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -275,6 +304,7 @@ def test_prediction_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -334,7 +364,7 @@ def test_prediction_service_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -351,6 +381,7 @@ def test_prediction_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case ADC client cert is provided. Whether client cert is used depends on @@ -375,7 +406,7 @@ def test_prediction_service_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -384,6 +415,7 @@ def test_prediction_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case client_cert_source and ADC client cert are not provided. @@ -396,7 +428,7 @@ def test_prediction_service_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -405,9 +437,91 @@ def test_prediction_service_client_mtls_env_auto( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) +@pytest.mark.parametrize( + "client_class", [PredictionServiceClient, PredictionServiceAsyncClient] +) +@mock.patch.object( + PredictionServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(PredictionServiceClient), +) +@mock.patch.object( + PredictionServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(PredictionServiceAsyncClient), +) +def test_prediction_service_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + @pytest.mark.parametrize( "client_class,transport_class,transport_name", [ @@ -423,10 +537,12 @@ def test_prediction_service_client_client_options_scopes( client_class, transport_class, transport_name ): # Check the case scopes are provided. - options = client_options.ClientOptions(scopes=["1", "2"],) + options = client_options.ClientOptions( + scopes=["1", "2"], + ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -435,28 +551,36 @@ def test_prediction_service_client_client_options_scopes( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (PredictionServiceClient, transports.PredictionServiceGrpcTransport, "grpc"), + ( + PredictionServiceClient, + transports.PredictionServiceGrpcTransport, + "grpc", + grpc_helpers, + ), ( PredictionServiceAsyncClient, transports.PredictionServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_prediction_service_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -465,6 +589,7 @@ def test_prediction_service_client_client_options_credentials_file( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -484,14 +609,87 @@ def test_prediction_service_client_client_options_from_dict(): client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) -def test_predict( - transport: str = "grpc", request_type=prediction_service.PredictRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + PredictionServiceClient, + transports.PredictionServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + PredictionServiceAsyncClient, + transports.PredictionServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_prediction_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers ): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + prediction_service.PredictRequest, + dict, + ], +) +def test_predict(request_type, transport: str = "grpc"): client = PredictionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -503,6 +701,9 @@ def test_predict( # Designate an appropriate return value for the call. call.return_value = prediction_service.PredictResponse( deployed_model_id="deployed_model_id_value", + model="model_value", + model_version_id="model_version_id_value", + model_display_name="model_display_name_value", ) response = client.predict(request) @@ -514,17 +715,17 @@ def test_predict( # Establish that the response is the type that we expect. assert isinstance(response, prediction_service.PredictResponse) assert response.deployed_model_id == "deployed_model_id_value" - - -def test_predict_from_dict(): - test_predict(request_type=dict) + assert response.model == "model_value" + assert response.model_version_id == "model_version_id_value" + assert response.model_display_name == "model_display_name_value" def test_predict_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = PredictionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -540,7 +741,8 @@ async def test_predict_async( transport: str = "grpc_asyncio", request_type=prediction_service.PredictRequest ): client = PredictionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -553,6 +755,9 @@ async def test_predict_async( call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( prediction_service.PredictResponse( deployed_model_id="deployed_model_id_value", + model="model_value", + model_version_id="model_version_id_value", + model_display_name="model_display_name_value", ) ) response = await client.predict(request) @@ -565,6 +770,9 @@ async def test_predict_async( # Establish that the response is the type that we expect. assert isinstance(response, prediction_service.PredictResponse) assert response.deployed_model_id == "deployed_model_id_value" + assert response.model == "model_value" + assert response.model_version_id == "model_version_id_value" + assert response.model_display_name == "model_display_name_value" @pytest.mark.asyncio @@ -573,13 +781,15 @@ async def test_predict_async_from_dict(): def test_predict_field_headers(): - client = PredictionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = prediction_service.PredictRequest() - request.endpoint = "endpoint/value" + request.endpoint = "endpoint_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.predict), "__call__") as call: @@ -593,7 +803,10 @@ def test_predict_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "endpoint=endpoint/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "endpoint=endpoint_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -606,7 +819,7 @@ async def test_predict_field_headers_async(): # a field header. Set these to a non-empty value. request = prediction_service.PredictRequest() - request.endpoint = "endpoint/value" + request.endpoint = "endpoint_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.predict), "__call__") as call: @@ -622,38 +835,16 @@ async def test_predict_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "endpoint=endpoint/value",) in kw["metadata"] - - -def test_predict_flattened(): - client = PredictionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.predict), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = prediction_service.PredictResponse() - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - client.predict( - endpoint="endpoint_value", - instances=[struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE)], - parameters=struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE), - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0].endpoint == "endpoint_value" - assert args[0].instances == [ - struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE) - ] - # https://github.com/googleapis/gapic-generator-python/issues/414 - # assert args[0].parameters == struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE) + assert ( + "x-goog-request-params", + "endpoint=endpoint_value", + ) in kw["metadata"] def test_predict_flattened_error(): - client = PredictionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -666,40 +857,6 @@ def test_predict_flattened_error(): ) -@pytest.mark.asyncio -async def test_predict_flattened_async(): - client = PredictionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.predict), "__call__") as call: - # Designate an appropriate return value for the call. - call.return_value = prediction_service.PredictResponse() - - call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - prediction_service.PredictResponse() - ) - # Call the method with a truthy value for each flattened field, - # using the keyword arguments to the method. - response = await client.predict( - endpoint="endpoint_value", - instances=[struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE)], - parameters=struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE), - ) - - # Establish that the underlying call was made with the expected - # request object values. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0].endpoint == "endpoint_value" - assert args[0].instances == [ - struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE) - ] - # https://github.com/googleapis/gapic-generator-python/issues/414 - # assert args[0].parameters == struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE) - - @pytest.mark.asyncio async def test_predict_flattened_error_async(): client = PredictionServiceAsyncClient( @@ -717,11 +874,17 @@ async def test_predict_flattened_error_async(): ) -def test_explain( - transport: str = "grpc", request_type=prediction_service.ExplainRequest -): +@pytest.mark.parametrize( + "request_type", + [ + prediction_service.RawPredictRequest, + dict, + ], +) +def test_raw_predict(request_type, transport: str = "grpc"): client = PredictionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -729,48 +892,48 @@ def test_explain( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.explain), "__call__") as call: + with mock.patch.object(type(client.transport.raw_predict), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = prediction_service.ExplainResponse( - deployed_model_id="deployed_model_id_value", + call.return_value = httpbody_pb2.HttpBody( + content_type="content_type_value", + data=b"data_blob", ) - response = client.explain(request) + response = client.raw_predict(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == prediction_service.ExplainRequest() + assert args[0] == prediction_service.RawPredictRequest() # Establish that the response is the type that we expect. - assert isinstance(response, prediction_service.ExplainResponse) - assert response.deployed_model_id == "deployed_model_id_value" - - -def test_explain_from_dict(): - test_explain(request_type=dict) + assert isinstance(response, httpbody_pb2.HttpBody) + assert response.content_type == "content_type_value" + assert response.data == b"data_blob" -def test_explain_empty_call(): +def test_raw_predict_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = PredictionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.explain), "__call__") as call: - client.explain() + with mock.patch.object(type(client.transport.raw_predict), "__call__") as call: + client.raw_predict() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == prediction_service.ExplainRequest() + assert args[0] == prediction_service.RawPredictRequest() @pytest.mark.asyncio -async def test_explain_async( - transport: str = "grpc_asyncio", request_type=prediction_service.ExplainRequest +async def test_raw_predict_async( + transport: str = "grpc_asyncio", request_type=prediction_service.RawPredictRequest ): client = PredictionServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -778,43 +941,47 @@ async def test_explain_async( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.explain), "__call__") as call: + with mock.patch.object(type(client.transport.raw_predict), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - prediction_service.ExplainResponse( - deployed_model_id="deployed_model_id_value", + httpbody_pb2.HttpBody( + content_type="content_type_value", + data=b"data_blob", ) ) - response = await client.explain(request) + response = await client.raw_predict(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == prediction_service.ExplainRequest() + assert args[0] == prediction_service.RawPredictRequest() # Establish that the response is the type that we expect. - assert isinstance(response, prediction_service.ExplainResponse) - assert response.deployed_model_id == "deployed_model_id_value" + assert isinstance(response, httpbody_pb2.HttpBody) + assert response.content_type == "content_type_value" + assert response.data == b"data_blob" @pytest.mark.asyncio -async def test_explain_async_from_dict(): - await test_explain_async(request_type=dict) +async def test_raw_predict_async_from_dict(): + await test_raw_predict_async(request_type=dict) -def test_explain_field_headers(): - client = PredictionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_raw_predict_field_headers(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = prediction_service.ExplainRequest() + request = prediction_service.RawPredictRequest() - request.endpoint = "endpoint/value" + request.endpoint = "endpoint_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.explain), "__call__") as call: - call.return_value = prediction_service.ExplainResponse() - client.explain(request) + with mock.patch.object(type(client.transport.raw_predict), "__call__") as call: + call.return_value = httpbody_pb2.HttpBody() + client.raw_predict(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -823,27 +990,30 @@ def test_explain_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "endpoint=endpoint/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "endpoint=endpoint_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_explain_field_headers_async(): +async def test_raw_predict_field_headers_async(): client = PredictionServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = prediction_service.ExplainRequest() + request = prediction_service.RawPredictRequest() - request.endpoint = "endpoint/value" + request.endpoint = "endpoint_value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.explain), "__call__") as call: + with mock.patch.object(type(client.transport.raw_predict), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - prediction_service.ExplainResponse() + httpbody_pb2.HttpBody() ) - await client.explain(request) + await client.raw_predict(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -852,91 +1022,90 @@ async def test_explain_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "endpoint=endpoint/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "endpoint=endpoint_value", + ) in kw["metadata"] -def test_explain_flattened(): - client = PredictionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_raw_predict_flattened(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.explain), "__call__") as call: + with mock.patch.object(type(client.transport.raw_predict), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = prediction_service.ExplainResponse() + call.return_value = httpbody_pb2.HttpBody() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.explain( + client.raw_predict( endpoint="endpoint_value", - instances=[struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE)], - parameters=struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE), - deployed_model_id="deployed_model_id_value", + http_body=httpbody_pb2.HttpBody(content_type="content_type_value"), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].endpoint == "endpoint_value" - assert args[0].instances == [ - struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE) - ] - # https://github.com/googleapis/gapic-generator-python/issues/414 - # assert args[0].parameters == struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE) - assert args[0].deployed_model_id == "deployed_model_id_value" + arg = args[0].endpoint + mock_val = "endpoint_value" + assert arg == mock_val + arg = args[0].http_body + mock_val = httpbody_pb2.HttpBody(content_type="content_type_value") + assert arg == mock_val -def test_explain_flattened_error(): - client = PredictionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) +def test_raw_predict_flattened_error(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.explain( - prediction_service.ExplainRequest(), + client.raw_predict( + prediction_service.RawPredictRequest(), endpoint="endpoint_value", - instances=[struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE)], - parameters=struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE), - deployed_model_id="deployed_model_id_value", + http_body=httpbody_pb2.HttpBody(content_type="content_type_value"), ) @pytest.mark.asyncio -async def test_explain_flattened_async(): +async def test_raw_predict_flattened_async(): client = PredictionServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client.transport.explain), "__call__") as call: + with mock.patch.object(type(client.transport.raw_predict), "__call__") as call: # Designate an appropriate return value for the call. - call.return_value = prediction_service.ExplainResponse() + call.return_value = httpbody_pb2.HttpBody() call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - prediction_service.ExplainResponse() + httpbody_pb2.HttpBody() ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.explain( + response = await client.raw_predict( endpoint="endpoint_value", - instances=[struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE)], - parameters=struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE), - deployed_model_id="deployed_model_id_value", + http_body=httpbody_pb2.HttpBody(content_type="content_type_value"), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].endpoint == "endpoint_value" - assert args[0].instances == [ - struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE) - ] - # https://github.com/googleapis/gapic-generator-python/issues/414 - # assert args[0].parameters == struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE) - assert args[0].deployed_model_id == "deployed_model_id_value" + arg = args[0].endpoint + mock_val = "endpoint_value" + assert arg == mock_val + arg = args[0].http_body + mock_val = httpbody_pb2.HttpBody(content_type="content_type_value") + assert arg == mock_val @pytest.mark.asyncio -async def test_explain_flattened_error_async(): +async def test_raw_predict_flattened_error_async(): client = PredictionServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -944,10 +1113,193 @@ async def test_explain_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.explain( - prediction_service.ExplainRequest(), + await client.raw_predict( + prediction_service.RawPredictRequest(), endpoint="endpoint_value", - instances=[struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE)], + http_body=httpbody_pb2.HttpBody(content_type="content_type_value"), + ) + + +@pytest.mark.parametrize( + "request_type", + [ + prediction_service.ExplainRequest, + dict, + ], +) +def test_explain(request_type, transport: str = "grpc"): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.explain), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = prediction_service.ExplainResponse( + deployed_model_id="deployed_model_id_value", + ) + response = client.explain(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == prediction_service.ExplainRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, prediction_service.ExplainResponse) + assert response.deployed_model_id == "deployed_model_id_value" + + +def test_explain_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.explain), "__call__") as call: + client.explain() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == prediction_service.ExplainRequest() + + +@pytest.mark.asyncio +async def test_explain_async( + transport: str = "grpc_asyncio", request_type=prediction_service.ExplainRequest +): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.explain), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + prediction_service.ExplainResponse( + deployed_model_id="deployed_model_id_value", + ) + ) + response = await client.explain(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == prediction_service.ExplainRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, prediction_service.ExplainResponse) + assert response.deployed_model_id == "deployed_model_id_value" + + +@pytest.mark.asyncio +async def test_explain_async_from_dict(): + await test_explain_async(request_type=dict) + + +def test_explain_field_headers(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = prediction_service.ExplainRequest() + + request.endpoint = "endpoint_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.explain), "__call__") as call: + call.return_value = prediction_service.ExplainResponse() + client.explain(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "endpoint=endpoint_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_explain_field_headers_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = prediction_service.ExplainRequest() + + request.endpoint = "endpoint_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.explain), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + prediction_service.ExplainResponse() + ) + await client.explain(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "endpoint=endpoint_value", + ) in kw["metadata"] + + +def test_explain_flattened_error(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.explain( + prediction_service.ExplainRequest(), + endpoint="endpoint_value", + instances=[struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE)], + parameters=struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE), + deployed_model_id="deployed_model_id_value", + ) + + +@pytest.mark.asyncio +async def test_explain_flattened_error_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.explain( + prediction_service.ExplainRequest(), + endpoint="endpoint_value", + instances=[struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE)], parameters=struct_pb2.Value(null_value=struct_pb2.NullValue.NULL_VALUE), deployed_model_id="deployed_model_id_value", ) @@ -960,7 +1312,8 @@ def test_credentials_transport_error(): ) with pytest.raises(ValueError): client = PredictionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # It is an error to provide a credentials file and a transport instance. @@ -973,13 +1326,34 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.PredictionServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = PredictionServiceClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = PredictionServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.PredictionServiceGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = PredictionServiceClient( - client_options={"scopes": ["1", "2"]}, transport=transport, + client_options={"scopes": ["1", "2"]}, + transport=transport, ) @@ -1022,10 +1396,28 @@ def test_transport_adc(transport_class): adc.assert_called_once() +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = PredictionServiceClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + def test_transport_grpc_default(): # A client should use the gRPC transport by default. - client = PredictionServiceClient(credentials=ga_credentials.AnonymousCredentials(),) - assert isinstance(client.transport, transports.PredictionServiceGrpcTransport,) + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.PredictionServiceGrpcTransport, + ) def test_prediction_service_base_transport_error(): @@ -1051,14 +1443,35 @@ def test_prediction_service_base_transport(): # raise NotImplementedError. methods = ( "predict", + "raw_predict", "explain", + "set_iam_policy", + "get_iam_policy", + "test_iam_permissions", + "get_location", + "list_locations", + "get_operation", + "wait_operation", + "cancel_operation", + "delete_operation", + "list_operations", ) for method in methods: with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + -@requires_google_auth_gte_1_25_0 def test_prediction_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -1069,7 +1482,8 @@ def test_prediction_service_base_transport_with_credentials_file(): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.PredictionServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", + credentials_file="credentials.json", + quota_project_id="octopus", ) load_creds.assert_called_once_with( "credentials.json", @@ -1079,26 +1493,6 @@ def test_prediction_service_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_prediction_service_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.aiplatform_v1beta1.services.prediction_service.transports.PredictionServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.PredictionServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - def test_prediction_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( @@ -1110,7 +1504,6 @@ def test_prediction_service_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_prediction_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -1123,18 +1516,6 @@ def test_prediction_service_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_prediction_service_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - PredictionServiceClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -1142,7 +1523,6 @@ def test_prediction_service_auth_adc_old_google_auth(): transports.PredictionServiceGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_prediction_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -1156,26 +1536,6 @@ def test_prediction_service_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.PredictionServiceGrpcTransport, - transports.PredictionServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_prediction_service_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ @@ -1183,7 +1543,6 @@ def test_prediction_service_transport_auth_adc_old_google_auth(transport_class): (transports.PredictionServiceGrpcAsyncIOTransport, grpc_helpers_async), ], ) -@requires_api_core_gte_1_26_0 def test_prediction_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -1213,83 +1572,10 @@ def test_prediction_service_transport_create_channel(transport_class, grpc_helpe @pytest.mark.parametrize( - "transport_class,grpc_helpers", + "transport_class", [ - (transports.PredictionServiceGrpcTransport, grpc_helpers), - (transports.PredictionServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_prediction_service_transport_create_channel_old_api_core( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class(quota_project_id="octopus") - - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.PredictionServiceGrpcTransport, grpc_helpers), - (transports.PredictionServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_prediction_service_transport_create_channel_user_scopes( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=["1", "2"], - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize( - "transport_class", - [ - transports.PredictionServiceGrpcTransport, - transports.PredictionServiceGrpcAsyncIOTransport, + transports.PredictionServiceGrpcTransport, + transports.PredictionServiceGrpcAsyncIOTransport, ], ) def test_prediction_service_grpc_transport_client_cert_source_for_mtls(transport_class): @@ -1307,7 +1593,7 @@ def test_prediction_service_grpc_transport_client_cert_source_for_mtls(transport "squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_channel_creds, quota_project_id=None, options=[ @@ -1330,24 +1616,40 @@ def test_prediction_service_grpc_transport_client_cert_source_for_mtls(transport ) -def test_prediction_service_host_no_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_prediction_service_host_no_port(transport_name): client = PredictionServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="aiplatform.googleapis.com" ), + transport=transport_name, ) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") -def test_prediction_service_host_with_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_prediction_service_host_with_port(transport_name): client = PredictionServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="aiplatform.googleapis.com:8000" ), + transport=transport_name, ) - assert client.transport._host == "aiplatform.googleapis.com:8000" + assert client.transport._host == ("aiplatform.googleapis.com:8000") def test_prediction_service_grpc_transport_channel(): @@ -1355,7 +1657,8 @@ def test_prediction_service_grpc_transport_channel(): # Check that channel is used if provided. transport = transports.PredictionServiceGrpcTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -1367,7 +1670,8 @@ def test_prediction_service_grpc_asyncio_transport_channel(): # Check that channel is used if provided. transport = transports.PredictionServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -1416,7 +1720,7 @@ def test_prediction_service_transport_channel_mtls_with_client_cert_source( "mtls.squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -1463,7 +1767,7 @@ def test_prediction_service_transport_channel_mtls_with_adc(transport_class): "mtls.squid.clam.whelk:443", credentials=mock_cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -1479,7 +1783,9 @@ def test_endpoint_path(): location = "clam" endpoint = "whelk" expected = "projects/{project}/locations/{location}/endpoints/{endpoint}".format( - project=project, location=location, endpoint=endpoint, + project=project, + location=location, + endpoint=endpoint, ) actual = PredictionServiceClient.endpoint_path(project, location, endpoint) assert expected == actual @@ -1498,8 +1804,34 @@ def test_parse_endpoint_path(): assert expected == actual +def test_model_path(): + project = "cuttlefish" + location = "mussel" + model = "winkle" + expected = "projects/{project}/locations/{location}/models/{model}".format( + project=project, + location=location, + model=model, + ) + actual = PredictionServiceClient.model_path(project, location, model) + assert expected == actual + + +def test_parse_model_path(): + expected = { + "project": "nautilus", + "location": "scallop", + "model": "abalone", + } + path = PredictionServiceClient.model_path(**expected) + + # Check that the path construction is reversible. + actual = PredictionServiceClient.parse_model_path(path) + assert expected == actual + + def test_common_billing_account_path(): - billing_account = "cuttlefish" + billing_account = "squid" expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -1509,7 +1841,7 @@ def test_common_billing_account_path(): def test_parse_common_billing_account_path(): expected = { - "billing_account": "mussel", + "billing_account": "clam", } path = PredictionServiceClient.common_billing_account_path(**expected) @@ -1519,15 +1851,17 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): - folder = "winkle" - expected = "folders/{folder}".format(folder=folder,) + folder = "whelk" + expected = "folders/{folder}".format( + folder=folder, + ) actual = PredictionServiceClient.common_folder_path(folder) assert expected == actual def test_parse_common_folder_path(): expected = { - "folder": "nautilus", + "folder": "octopus", } path = PredictionServiceClient.common_folder_path(**expected) @@ -1537,15 +1871,17 @@ def test_parse_common_folder_path(): def test_common_organization_path(): - organization = "scallop" - expected = "organizations/{organization}".format(organization=organization,) + organization = "oyster" + expected = "organizations/{organization}".format( + organization=organization, + ) actual = PredictionServiceClient.common_organization_path(organization) assert expected == actual def test_parse_common_organization_path(): expected = { - "organization": "abalone", + "organization": "nudibranch", } path = PredictionServiceClient.common_organization_path(**expected) @@ -1555,15 +1891,17 @@ def test_parse_common_organization_path(): def test_common_project_path(): - project = "squid" - expected = "projects/{project}".format(project=project,) + project = "cuttlefish" + expected = "projects/{project}".format( + project=project, + ) actual = PredictionServiceClient.common_project_path(project) assert expected == actual def test_parse_common_project_path(): expected = { - "project": "clam", + "project": "mussel", } path = PredictionServiceClient.common_project_path(**expected) @@ -1573,10 +1911,11 @@ def test_parse_common_project_path(): def test_common_location_path(): - project = "whelk" - location = "octopus" + project = "winkle" + location = "nautilus" expected = "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) actual = PredictionServiceClient.common_location_path(project, location) assert expected == actual @@ -1584,8 +1923,8 @@ def test_common_location_path(): def test_parse_common_location_path(): expected = { - "project": "oyster", - "location": "nudibranch", + "project": "scallop", + "location": "abalone", } path = PredictionServiceClient.common_location_path(**expected) @@ -1594,14 +1933,15 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( transports.PredictionServiceTransport, "_prep_wrapped_messages" ) as prep: client = PredictionServiceClient( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -1610,6 +1950,1596 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = PredictionServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_delete_operation(transport: str = "grpc"): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_operation(transport: str = "grpc"): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_operation_field_headers(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = None + + client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_operation_field_headers_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_delete_operation_from_dict(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_delete_operation_from_dict_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_cancel_operation(transport: str = "grpc"): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation(transport: str = "grpc"): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_wait_operation(transport: str = "grpc"): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_wait_operation(transport: str = "grpc"): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_wait_operation_field_headers(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_wait_operation_field_headers_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_wait_operation_from_dict(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_wait_operation_from_dict_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_operation(transport: str = "grpc"): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_get_operation(transport: str = "grpc"): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_get_operation_field_headers(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_get_operation_from_dict(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_operations(transport: str = "grpc"): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + response = client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +@pytest.mark.asyncio +async def test_list_operations(transport: str = "grpc"): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +def test_list_operations_field_headers(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_operations_field_headers_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_operations_from_dict(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + response = client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_operations_from_dict_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_locations(transport: str = "grpc"): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + response = client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +@pytest.mark.asyncio +async def test_list_locations(transport: str = "grpc"): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +def test_list_locations_field_headers(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_locations_field_headers_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_locations_from_dict(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + response = client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_locations_from_dict_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_location(transport: str = "grpc"): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + response = client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +@pytest.mark.asyncio +async def test_get_location_async(transport: str = "grpc_asyncio"): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +def test_get_location_field_headers(): + client = PredictionServiceClient(credentials=ga_credentials.AnonymousCredentials()) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = locations_pb2.Location() + + client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_location_field_headers_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials() + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +def test_get_location_from_dict(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + response = client.get_location( + request={ + "name": "locations/abc", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_location_from_dict_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_set_iam_policy(transport: str = "grpc"): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + response = client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + response = await client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_set_iam_policy_field_headers(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_set_iam_policy_field_headers_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_set_iam_policy_from_dict(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_set_iam_policy_from_dict_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +def test_get_iam_policy(transport: str = "grpc"): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + + response = client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + + response = await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_get_iam_policy_field_headers(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_iam_policy_field_headers_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_get_iam_policy_from_dict(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_iam_policy_from_dict_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +def test_test_iam_permissions(transport: str = "grpc"): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + + response = client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + ) + + response = await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +def test_test_iam_permissions_field_headers(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_field_headers_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_test_iam_permissions_from_dict(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + response = client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_from_dict_async(): + client = PredictionServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + response = await client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = PredictionServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (PredictionServiceClient, transports.PredictionServiceGrpcTransport), + ( + PredictionServiceAsyncClient, + transports.PredictionServiceGrpcAsyncIOTransport, + ), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) diff --git a/tests/unit/gapic/aiplatform_v1beta1/test_specialist_pool_service.py b/tests/unit/gapic/aiplatform_v1beta1/test_specialist_pool_service.py index d9f0d11522..e95ea31367 100644 --- a/tests/unit/gapic/aiplatform_v1beta1/test_specialist_pool_service.py +++ b/tests/unit/gapic/aiplatform_v1beta1/test_specialist_pool_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,8 +14,13 @@ # limitations under the License. # import os -import mock -import packaging.version + +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock +except ImportError: + import mock import grpc from grpc.experimental import aio @@ -30,8 +35,10 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.aiplatform_v1beta1.services.specialist_pool_service import ( @@ -42,45 +49,20 @@ ) from google.cloud.aiplatform_v1beta1.services.specialist_pool_service import pagers from google.cloud.aiplatform_v1beta1.services.specialist_pool_service import transports -from google.cloud.aiplatform_v1beta1.services.specialist_pool_service.transports.base import ( - _API_CORE_VERSION, -) -from google.cloud.aiplatform_v1beta1.services.specialist_pool_service.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.aiplatform_v1beta1.types import operation as gca_operation from google.cloud.aiplatform_v1beta1.types import specialist_pool from google.cloud.aiplatform_v1beta1.types import specialist_pool as gca_specialist_pool from google.cloud.aiplatform_v1beta1.types import specialist_pool_service +from google.cloud.location import locations_pb2 +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 from google.oauth2 import service_account from google.protobuf import field_mask_pb2 # type: ignore import google.auth -# TODO(busunkim): Once google-api-core >= 1.26.0 is required: -# - Delete all the api-core and auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - -requires_api_core_lt_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), - reason="This test requires google-api-core < 1.26.0", -) - -requires_api_core_gte_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), - reason="This test requires google-api-core >= 1.26.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -127,40 +109,81 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( - "client_class", [SpecialistPoolServiceClient, SpecialistPoolServiceAsyncClient,] + "client_class,transport_name", + [ + (SpecialistPoolServiceClient, "grpc"), + (SpecialistPoolServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_specialist_pool_service_client_from_service_account_info(client_class): +def test_specialist_pool_service_client_from_service_account_info( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.SpecialistPoolServiceGrpcTransport, "grpc"), + (transports.SpecialistPoolServiceGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_specialist_pool_service_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() @pytest.mark.parametrize( - "client_class", [SpecialistPoolServiceClient, SpecialistPoolServiceAsyncClient,] + "client_class,transport_name", + [ + (SpecialistPoolServiceClient, "grpc"), + (SpecialistPoolServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_specialist_pool_service_client_from_service_account_file(client_class): +def test_specialist_pool_service_client_from_service_account_file( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") def test_specialist_pool_service_client_get_transport_class(): @@ -217,7 +240,7 @@ def test_specialist_pool_service_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -226,6 +249,7 @@ def test_specialist_pool_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -233,7 +257,7 @@ def test_specialist_pool_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -242,6 +266,7 @@ def test_specialist_pool_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -249,7 +274,7 @@ def test_specialist_pool_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -258,26 +283,27 @@ def test_specialist_pool_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -286,6 +312,7 @@ def test_specialist_pool_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -345,7 +372,7 @@ def test_specialist_pool_service_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -362,6 +389,7 @@ def test_specialist_pool_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case ADC client cert is provided. Whether client cert is used depends on @@ -386,7 +414,7 @@ def test_specialist_pool_service_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -395,6 +423,7 @@ def test_specialist_pool_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case client_cert_source and ADC client cert are not provided. @@ -407,7 +436,7 @@ def test_specialist_pool_service_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -416,9 +445,91 @@ def test_specialist_pool_service_client_mtls_env_auto( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) +@pytest.mark.parametrize( + "client_class", [SpecialistPoolServiceClient, SpecialistPoolServiceAsyncClient] +) +@mock.patch.object( + SpecialistPoolServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(SpecialistPoolServiceClient), +) +@mock.patch.object( + SpecialistPoolServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(SpecialistPoolServiceAsyncClient), +) +def test_specialist_pool_service_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + @pytest.mark.parametrize( "client_class,transport_class,transport_name", [ @@ -438,10 +549,12 @@ def test_specialist_pool_service_client_client_options_scopes( client_class, transport_class, transport_name ): # Check the case scopes are provided. - options = client_options.ClientOptions(scopes=["1", "2"],) + options = client_options.ClientOptions( + scopes=["1", "2"], + ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -450,32 +563,36 @@ def test_specialist_pool_service_client_client_options_scopes( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ ( SpecialistPoolServiceClient, transports.SpecialistPoolServiceGrpcTransport, "grpc", + grpc_helpers, ), ( SpecialistPoolServiceAsyncClient, transports.SpecialistPoolServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_specialist_pool_service_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -484,6 +601,7 @@ def test_specialist_pool_service_client_client_options_credentials_file( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -503,15 +621,87 @@ def test_specialist_pool_service_client_client_options_from_dict(): client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) -def test_create_specialist_pool( - transport: str = "grpc", - request_type=specialist_pool_service.CreateSpecialistPoolRequest, +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + SpecialistPoolServiceClient, + transports.SpecialistPoolServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + SpecialistPoolServiceAsyncClient, + transports.SpecialistPoolServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_specialist_pool_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers ): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + specialist_pool_service.CreateSpecialistPoolRequest, + dict, + ], +) +def test_create_specialist_pool(request_type, transport: str = "grpc"): client = SpecialistPoolServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -535,15 +725,12 @@ def test_create_specialist_pool( assert isinstance(response, future.Future) -def test_create_specialist_pool_from_dict(): - test_create_specialist_pool(request_type=dict) - - def test_create_specialist_pool_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SpecialistPoolServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -562,7 +749,8 @@ async def test_create_specialist_pool_async( request_type=specialist_pool_service.CreateSpecialistPoolRequest, ): client = SpecialistPoolServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -602,7 +790,7 @@ def test_create_specialist_pool_field_headers(): # a field header. Set these to a non-empty value. request = specialist_pool_service.CreateSpecialistPoolRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -618,7 +806,10 @@ def test_create_specialist_pool_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -631,7 +822,7 @@ async def test_create_specialist_pool_field_headers_async(): # a field header. Set these to a non-empty value. request = specialist_pool_service.CreateSpecialistPoolRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -649,7 +840,10 @@ async def test_create_specialist_pool_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_create_specialist_pool_flattened(): @@ -674,10 +868,12 @@ def test_create_specialist_pool_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].specialist_pool == gca_specialist_pool.SpecialistPool( - name="name_value" - ) + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].specialist_pool + mock_val = gca_specialist_pool.SpecialistPool(name="name_value") + assert arg == mock_val def test_create_specialist_pool_flattened_error(): @@ -722,10 +918,12 @@ async def test_create_specialist_pool_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].specialist_pool == gca_specialist_pool.SpecialistPool( - name="name_value" - ) + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].specialist_pool + mock_val = gca_specialist_pool.SpecialistPool(name="name_value") + assert arg == mock_val @pytest.mark.asyncio @@ -744,12 +942,17 @@ async def test_create_specialist_pool_flattened_error_async(): ) -def test_get_specialist_pool( - transport: str = "grpc", - request_type=specialist_pool_service.GetSpecialistPoolRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + specialist_pool_service.GetSpecialistPoolRequest, + dict, + ], +) +def test_get_specialist_pool(request_type, transport: str = "grpc"): client = SpecialistPoolServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -767,6 +970,7 @@ def test_get_specialist_pool( specialist_managers_count=2662, specialist_manager_emails=["specialist_manager_emails_value"], pending_data_labeling_jobs=["pending_data_labeling_jobs_value"], + specialist_worker_emails=["specialist_worker_emails_value"], ) response = client.get_specialist_pool(request) @@ -782,17 +986,15 @@ def test_get_specialist_pool( assert response.specialist_managers_count == 2662 assert response.specialist_manager_emails == ["specialist_manager_emails_value"] assert response.pending_data_labeling_jobs == ["pending_data_labeling_jobs_value"] - - -def test_get_specialist_pool_from_dict(): - test_get_specialist_pool(request_type=dict) + assert response.specialist_worker_emails == ["specialist_worker_emails_value"] def test_get_specialist_pool_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SpecialistPoolServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -811,7 +1013,8 @@ async def test_get_specialist_pool_async( request_type=specialist_pool_service.GetSpecialistPoolRequest, ): client = SpecialistPoolServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -830,6 +1033,7 @@ async def test_get_specialist_pool_async( specialist_managers_count=2662, specialist_manager_emails=["specialist_manager_emails_value"], pending_data_labeling_jobs=["pending_data_labeling_jobs_value"], + specialist_worker_emails=["specialist_worker_emails_value"], ) ) response = await client.get_specialist_pool(request) @@ -846,6 +1050,7 @@ async def test_get_specialist_pool_async( assert response.specialist_managers_count == 2662 assert response.specialist_manager_emails == ["specialist_manager_emails_value"] assert response.pending_data_labeling_jobs == ["pending_data_labeling_jobs_value"] + assert response.specialist_worker_emails == ["specialist_worker_emails_value"] @pytest.mark.asyncio @@ -862,7 +1067,7 @@ def test_get_specialist_pool_field_headers(): # a field header. Set these to a non-empty value. request = specialist_pool_service.GetSpecialistPoolRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -878,7 +1083,10 @@ def test_get_specialist_pool_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -891,7 +1099,7 @@ async def test_get_specialist_pool_field_headers_async(): # a field header. Set these to a non-empty value. request = specialist_pool_service.GetSpecialistPoolRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -909,7 +1117,10 @@ async def test_get_specialist_pool_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_get_specialist_pool_flattened(): @@ -925,13 +1136,17 @@ def test_get_specialist_pool_flattened(): call.return_value = specialist_pool.SpecialistPool() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_specialist_pool(name="name_value",) + client.get_specialist_pool( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_specialist_pool_flattened_error(): @@ -943,7 +1158,8 @@ def test_get_specialist_pool_flattened_error(): # fields is an error. with pytest.raises(ValueError): client.get_specialist_pool( - specialist_pool_service.GetSpecialistPoolRequest(), name="name_value", + specialist_pool_service.GetSpecialistPoolRequest(), + name="name_value", ) @@ -965,13 +1181,17 @@ async def test_get_specialist_pool_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_specialist_pool(name="name_value",) + response = await client.get_specialist_pool( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -984,16 +1204,22 @@ async def test_get_specialist_pool_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.get_specialist_pool( - specialist_pool_service.GetSpecialistPoolRequest(), name="name_value", + specialist_pool_service.GetSpecialistPoolRequest(), + name="name_value", ) -def test_list_specialist_pools( - transport: str = "grpc", - request_type=specialist_pool_service.ListSpecialistPoolsRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + specialist_pool_service.ListSpecialistPoolsRequest, + dict, + ], +) +def test_list_specialist_pools(request_type, transport: str = "grpc"): client = SpecialistPoolServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1020,15 +1246,12 @@ def test_list_specialist_pools( assert response.next_page_token == "next_page_token_value" -def test_list_specialist_pools_from_dict(): - test_list_specialist_pools(request_type=dict) - - def test_list_specialist_pools_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SpecialistPoolServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1047,7 +1270,8 @@ async def test_list_specialist_pools_async( request_type=specialist_pool_service.ListSpecialistPoolsRequest, ): client = SpecialistPoolServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1090,7 +1314,7 @@ def test_list_specialist_pools_field_headers(): # a field header. Set these to a non-empty value. request = specialist_pool_service.ListSpecialistPoolsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1106,7 +1330,10 @@ def test_list_specialist_pools_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1119,7 +1346,7 @@ async def test_list_specialist_pools_field_headers_async(): # a field header. Set these to a non-empty value. request = specialist_pool_service.ListSpecialistPoolsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1137,7 +1364,10 @@ async def test_list_specialist_pools_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_specialist_pools_flattened(): @@ -1153,13 +1383,17 @@ def test_list_specialist_pools_flattened(): call.return_value = specialist_pool_service.ListSpecialistPoolsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_specialist_pools(parent="parent_value",) + client.list_specialist_pools( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_specialist_pools_flattened_error(): @@ -1171,7 +1405,8 @@ def test_list_specialist_pools_flattened_error(): # fields is an error. with pytest.raises(ValueError): client.list_specialist_pools( - specialist_pool_service.ListSpecialistPoolsRequest(), parent="parent_value", + specialist_pool_service.ListSpecialistPoolsRequest(), + parent="parent_value", ) @@ -1193,13 +1428,17 @@ async def test_list_specialist_pools_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_specialist_pools(parent="parent_value",) + response = await client.list_specialist_pools( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1212,13 +1451,15 @@ async def test_list_specialist_pools_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.list_specialist_pools( - specialist_pool_service.ListSpecialistPoolsRequest(), parent="parent_value", + specialist_pool_service.ListSpecialistPoolsRequest(), + parent="parent_value", ) -def test_list_specialist_pools_pager(): +def test_list_specialist_pools_pager(transport_name: str = "grpc"): client = SpecialistPoolServiceClient( credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1236,10 +1477,13 @@ def test_list_specialist_pools_pager(): next_page_token="abc", ), specialist_pool_service.ListSpecialistPoolsResponse( - specialist_pools=[], next_page_token="def", + specialist_pools=[], + next_page_token="def", ), specialist_pool_service.ListSpecialistPoolsResponse( - specialist_pools=[specialist_pool.SpecialistPool(),], + specialist_pools=[ + specialist_pool.SpecialistPool(), + ], next_page_token="ghi", ), specialist_pool_service.ListSpecialistPoolsResponse( @@ -1259,14 +1503,15 @@ def test_list_specialist_pools_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all(isinstance(i, specialist_pool.SpecialistPool) for i in results) -def test_list_specialist_pools_pages(): +def test_list_specialist_pools_pages(transport_name: str = "grpc"): client = SpecialistPoolServiceClient( credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1284,10 +1529,13 @@ def test_list_specialist_pools_pages(): next_page_token="abc", ), specialist_pool_service.ListSpecialistPoolsResponse( - specialist_pools=[], next_page_token="def", + specialist_pools=[], + next_page_token="def", ), specialist_pool_service.ListSpecialistPoolsResponse( - specialist_pools=[specialist_pool.SpecialistPool(),], + specialist_pools=[ + specialist_pool.SpecialistPool(), + ], next_page_token="ghi", ), specialist_pool_service.ListSpecialistPoolsResponse( @@ -1326,10 +1574,13 @@ async def test_list_specialist_pools_async_pager(): next_page_token="abc", ), specialist_pool_service.ListSpecialistPoolsResponse( - specialist_pools=[], next_page_token="def", + specialist_pools=[], + next_page_token="def", ), specialist_pool_service.ListSpecialistPoolsResponse( - specialist_pools=[specialist_pool.SpecialistPool(),], + specialist_pools=[ + specialist_pool.SpecialistPool(), + ], next_page_token="ghi", ), specialist_pool_service.ListSpecialistPoolsResponse( @@ -1340,10 +1591,12 @@ async def test_list_specialist_pools_async_pager(): ), RuntimeError, ) - async_pager = await client.list_specialist_pools(request={},) + async_pager = await client.list_specialist_pools( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -1373,10 +1626,13 @@ async def test_list_specialist_pools_async_pages(): next_page_token="abc", ), specialist_pool_service.ListSpecialistPoolsResponse( - specialist_pools=[], next_page_token="def", + specialist_pools=[], + next_page_token="def", ), specialist_pool_service.ListSpecialistPoolsResponse( - specialist_pools=[specialist_pool.SpecialistPool(),], + specialist_pools=[ + specialist_pool.SpecialistPool(), + ], next_page_token="ghi", ), specialist_pool_service.ListSpecialistPoolsResponse( @@ -1388,18 +1644,25 @@ async def test_list_specialist_pools_async_pages(): RuntimeError, ) pages = [] - async for page_ in (await client.list_specialist_pools(request={})).pages: + async for page_ in ( + await client.list_specialist_pools(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_delete_specialist_pool( - transport: str = "grpc", - request_type=specialist_pool_service.DeleteSpecialistPoolRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + specialist_pool_service.DeleteSpecialistPoolRequest, + dict, + ], +) +def test_delete_specialist_pool(request_type, transport: str = "grpc"): client = SpecialistPoolServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1423,15 +1686,12 @@ def test_delete_specialist_pool( assert isinstance(response, future.Future) -def test_delete_specialist_pool_from_dict(): - test_delete_specialist_pool(request_type=dict) - - def test_delete_specialist_pool_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SpecialistPoolServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1450,7 +1710,8 @@ async def test_delete_specialist_pool_async( request_type=specialist_pool_service.DeleteSpecialistPoolRequest, ): client = SpecialistPoolServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1490,7 +1751,7 @@ def test_delete_specialist_pool_field_headers(): # a field header. Set these to a non-empty value. request = specialist_pool_service.DeleteSpecialistPoolRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1506,7 +1767,10 @@ def test_delete_specialist_pool_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1519,7 +1783,7 @@ async def test_delete_specialist_pool_field_headers_async(): # a field header. Set these to a non-empty value. request = specialist_pool_service.DeleteSpecialistPoolRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1537,7 +1801,10 @@ async def test_delete_specialist_pool_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_delete_specialist_pool_flattened(): @@ -1553,13 +1820,17 @@ def test_delete_specialist_pool_flattened(): call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_specialist_pool(name="name_value",) + client.delete_specialist_pool( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_delete_specialist_pool_flattened_error(): @@ -1571,7 +1842,8 @@ def test_delete_specialist_pool_flattened_error(): # fields is an error. with pytest.raises(ValueError): client.delete_specialist_pool( - specialist_pool_service.DeleteSpecialistPoolRequest(), name="name_value", + specialist_pool_service.DeleteSpecialistPoolRequest(), + name="name_value", ) @@ -1593,13 +1865,17 @@ async def test_delete_specialist_pool_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_specialist_pool(name="name_value",) + response = await client.delete_specialist_pool( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1612,16 +1888,22 @@ async def test_delete_specialist_pool_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.delete_specialist_pool( - specialist_pool_service.DeleteSpecialistPoolRequest(), name="name_value", + specialist_pool_service.DeleteSpecialistPoolRequest(), + name="name_value", ) -def test_update_specialist_pool( - transport: str = "grpc", - request_type=specialist_pool_service.UpdateSpecialistPoolRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + specialist_pool_service.UpdateSpecialistPoolRequest, + dict, + ], +) +def test_update_specialist_pool(request_type, transport: str = "grpc"): client = SpecialistPoolServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1645,15 +1927,12 @@ def test_update_specialist_pool( assert isinstance(response, future.Future) -def test_update_specialist_pool_from_dict(): - test_update_specialist_pool(request_type=dict) - - def test_update_specialist_pool_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = SpecialistPoolServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1672,7 +1951,8 @@ async def test_update_specialist_pool_async( request_type=specialist_pool_service.UpdateSpecialistPoolRequest, ): client = SpecialistPoolServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1712,7 +1992,7 @@ def test_update_specialist_pool_field_headers(): # a field header. Set these to a non-empty value. request = specialist_pool_service.UpdateSpecialistPoolRequest() - request.specialist_pool.name = "specialist_pool.name/value" + request.specialist_pool.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1730,7 +2010,7 @@ def test_update_specialist_pool_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "specialist_pool.name=specialist_pool.name/value", + "specialist_pool.name=name_value", ) in kw["metadata"] @@ -1744,7 +2024,7 @@ async def test_update_specialist_pool_field_headers_async(): # a field header. Set these to a non-empty value. request = specialist_pool_service.UpdateSpecialistPoolRequest() - request.specialist_pool.name = "specialist_pool.name/value" + request.specialist_pool.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1764,7 +2044,7 @@ async def test_update_specialist_pool_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "specialist_pool.name=specialist_pool.name/value", + "specialist_pool.name=name_value", ) in kw["metadata"] @@ -1790,10 +2070,12 @@ def test_update_specialist_pool_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].specialist_pool == gca_specialist_pool.SpecialistPool( - name="name_value" - ) - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].specialist_pool + mock_val = gca_specialist_pool.SpecialistPool(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val def test_update_specialist_pool_flattened_error(): @@ -1838,10 +2120,12 @@ async def test_update_specialist_pool_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].specialist_pool == gca_specialist_pool.SpecialistPool( - name="name_value" - ) - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].specialist_pool + mock_val = gca_specialist_pool.SpecialistPool(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val @pytest.mark.asyncio @@ -1867,7 +2151,8 @@ def test_credentials_transport_error(): ) with pytest.raises(ValueError): client = SpecialistPoolServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # It is an error to provide a credentials file and a transport instance. @@ -1880,13 +2165,34 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.SpecialistPoolServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = SpecialistPoolServiceClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = SpecialistPoolServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.SpecialistPoolServiceGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = SpecialistPoolServiceClient( - client_options={"scopes": ["1", "2"]}, transport=transport, + client_options={"scopes": ["1", "2"]}, + transport=transport, ) @@ -1929,12 +2235,28 @@ def test_transport_adc(transport_class): adc.assert_called_once() +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = SpecialistPoolServiceClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = SpecialistPoolServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) - assert isinstance(client.transport, transports.SpecialistPoolServiceGrpcTransport,) + assert isinstance( + client.transport, + transports.SpecialistPoolServiceGrpcTransport, + ) def test_specialist_pool_service_base_transport_error(): @@ -1964,18 +2286,38 @@ def test_specialist_pool_service_base_transport(): "list_specialist_pools", "delete_specialist_pool", "update_specialist_pool", + "set_iam_policy", + "get_iam_policy", + "test_iam_permissions", + "get_location", + "list_locations", + "get_operation", + "wait_operation", + "cancel_operation", + "delete_operation", + "list_operations", ) for method in methods: with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + # Additionally, the LRO client (a property) should # also raise NotImplementedError with pytest.raises(NotImplementedError): transport.operations_client + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + -@requires_google_auth_gte_1_25_0 def test_specialist_pool_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -1986,7 +2328,8 @@ def test_specialist_pool_service_base_transport_with_credentials_file(): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.SpecialistPoolServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", + credentials_file="credentials.json", + quota_project_id="octopus", ) load_creds.assert_called_once_with( "credentials.json", @@ -1996,26 +2339,6 @@ def test_specialist_pool_service_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_specialist_pool_service_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.aiplatform_v1beta1.services.specialist_pool_service.transports.SpecialistPoolServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.SpecialistPoolServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - def test_specialist_pool_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( @@ -2027,7 +2350,6 @@ def test_specialist_pool_service_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_specialist_pool_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -2040,18 +2362,6 @@ def test_specialist_pool_service_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_specialist_pool_service_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - SpecialistPoolServiceClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -2059,7 +2369,6 @@ def test_specialist_pool_service_auth_adc_old_google_auth(): transports.SpecialistPoolServiceGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_specialist_pool_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -2073,26 +2382,6 @@ def test_specialist_pool_service_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.SpecialistPoolServiceGrpcTransport, - transports.SpecialistPoolServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_specialist_pool_service_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ @@ -2100,7 +2389,6 @@ def test_specialist_pool_service_transport_auth_adc_old_google_auth(transport_cl (transports.SpecialistPoolServiceGrpcAsyncIOTransport, grpc_helpers_async), ], ) -@requires_api_core_gte_1_26_0 def test_specialist_pool_service_transport_create_channel( transport_class, grpc_helpers ): @@ -2131,79 +2419,6 @@ def test_specialist_pool_service_transport_create_channel( ) -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.SpecialistPoolServiceGrpcTransport, grpc_helpers), - (transports.SpecialistPoolServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_specialist_pool_service_transport_create_channel_old_api_core( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class(quota_project_id="octopus") - - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.SpecialistPoolServiceGrpcTransport, grpc_helpers), - (transports.SpecialistPoolServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_specialist_pool_service_transport_create_channel_user_scopes( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=["1", "2"], - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -2228,7 +2443,7 @@ def test_specialist_pool_service_grpc_transport_client_cert_source_for_mtls( "squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_channel_creds, quota_project_id=None, options=[ @@ -2251,24 +2466,40 @@ def test_specialist_pool_service_grpc_transport_client_cert_source_for_mtls( ) -def test_specialist_pool_service_host_no_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_specialist_pool_service_host_no_port(transport_name): client = SpecialistPoolServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="aiplatform.googleapis.com" ), + transport=transport_name, ) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") -def test_specialist_pool_service_host_with_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_specialist_pool_service_host_with_port(transport_name): client = SpecialistPoolServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="aiplatform.googleapis.com:8000" ), + transport=transport_name, ) - assert client.transport._host == "aiplatform.googleapis.com:8000" + assert client.transport._host == ("aiplatform.googleapis.com:8000") def test_specialist_pool_service_grpc_transport_channel(): @@ -2276,7 +2507,8 @@ def test_specialist_pool_service_grpc_transport_channel(): # Check that channel is used if provided. transport = transports.SpecialistPoolServiceGrpcTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -2288,7 +2520,8 @@ def test_specialist_pool_service_grpc_asyncio_transport_channel(): # Check that channel is used if provided. transport = transports.SpecialistPoolServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -2337,7 +2570,7 @@ def test_specialist_pool_service_transport_channel_mtls_with_client_cert_source( "mtls.squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -2384,7 +2617,7 @@ def test_specialist_pool_service_transport_channel_mtls_with_adc(transport_class "mtls.squid.clam.whelk:443", credentials=mock_cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -2397,12 +2630,16 @@ def test_specialist_pool_service_transport_channel_mtls_with_adc(transport_class def test_specialist_pool_service_grpc_lro_client(): client = SpecialistPoolServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -2410,12 +2647,16 @@ def test_specialist_pool_service_grpc_lro_client(): def test_specialist_pool_service_grpc_lro_async_client(): client = SpecialistPoolServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -2426,7 +2667,9 @@ def test_specialist_pool_path(): location = "clam" specialist_pool = "whelk" expected = "projects/{project}/locations/{location}/specialistPools/{specialist_pool}".format( - project=project, location=location, specialist_pool=specialist_pool, + project=project, + location=location, + specialist_pool=specialist_pool, ) actual = SpecialistPoolServiceClient.specialist_pool_path( project, location, specialist_pool @@ -2469,7 +2712,9 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "winkle" - expected = "folders/{folder}".format(folder=folder,) + expected = "folders/{folder}".format( + folder=folder, + ) actual = SpecialistPoolServiceClient.common_folder_path(folder) assert expected == actual @@ -2487,7 +2732,9 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "scallop" - expected = "organizations/{organization}".format(organization=organization,) + expected = "organizations/{organization}".format( + organization=organization, + ) actual = SpecialistPoolServiceClient.common_organization_path(organization) assert expected == actual @@ -2505,7 +2752,9 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "squid" - expected = "projects/{project}".format(project=project,) + expected = "projects/{project}".format( + project=project, + ) actual = SpecialistPoolServiceClient.common_project_path(project) assert expected == actual @@ -2525,7 +2774,8 @@ def test_common_location_path(): project = "whelk" location = "octopus" expected = "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) actual = SpecialistPoolServiceClient.common_location_path(project, location) assert expected == actual @@ -2543,14 +2793,15 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( transports.SpecialistPoolServiceTransport, "_prep_wrapped_messages" ) as prep: client = SpecialistPoolServiceClient( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -2559,6 +2810,1598 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = SpecialistPoolServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_delete_operation(transport: str = "grpc"): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_operation(transport: str = "grpc"): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_operation_field_headers(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = None + + client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_operation_field_headers_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_delete_operation_from_dict(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_delete_operation_from_dict_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_cancel_operation(transport: str = "grpc"): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation(transport: str = "grpc"): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_wait_operation(transport: str = "grpc"): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_wait_operation(transport: str = "grpc"): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_wait_operation_field_headers(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_wait_operation_field_headers_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_wait_operation_from_dict(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_wait_operation_from_dict_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_operation(transport: str = "grpc"): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_get_operation(transport: str = "grpc"): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_get_operation_field_headers(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_get_operation_from_dict(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_operations(transport: str = "grpc"): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + response = client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +@pytest.mark.asyncio +async def test_list_operations(transport: str = "grpc"): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +def test_list_operations_field_headers(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_operations_field_headers_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_operations_from_dict(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + response = client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_operations_from_dict_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_locations(transport: str = "grpc"): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + response = client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +@pytest.mark.asyncio +async def test_list_locations(transport: str = "grpc"): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +def test_list_locations_field_headers(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_locations_field_headers_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_locations_from_dict(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + response = client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_locations_from_dict_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_location(transport: str = "grpc"): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + response = client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +@pytest.mark.asyncio +async def test_get_location_async(transport: str = "grpc_asyncio"): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +def test_get_location_field_headers(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials() + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = locations_pb2.Location() + + client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_location_field_headers_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials() + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +def test_get_location_from_dict(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + response = client.get_location( + request={ + "name": "locations/abc", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_location_from_dict_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_set_iam_policy(transport: str = "grpc"): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + response = client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + response = await client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_set_iam_policy_field_headers(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_set_iam_policy_field_headers_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_set_iam_policy_from_dict(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_set_iam_policy_from_dict_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +def test_get_iam_policy(transport: str = "grpc"): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + + response = client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + + response = await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_get_iam_policy_field_headers(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_iam_policy_field_headers_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_get_iam_policy_from_dict(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_iam_policy_from_dict_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +def test_test_iam_permissions(transport: str = "grpc"): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + + response = client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + ) + + response = await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +def test_test_iam_permissions_field_headers(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_field_headers_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_test_iam_permissions_from_dict(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + response = client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_from_dict_async(): + client = SpecialistPoolServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + response = await client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = SpecialistPoolServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (SpecialistPoolServiceClient, transports.SpecialistPoolServiceGrpcTransport), + ( + SpecialistPoolServiceAsyncClient, + transports.SpecialistPoolServiceGrpcAsyncIOTransport, + ), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) diff --git a/tests/unit/gapic/aiplatform_v1beta1/test_tensorboard_service.py b/tests/unit/gapic/aiplatform_v1beta1/test_tensorboard_service.py index aab827e031..00b170caf2 100644 --- a/tests/unit/gapic/aiplatform_v1beta1/test_tensorboard_service.py +++ b/tests/unit/gapic/aiplatform_v1beta1/test_tensorboard_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,8 +14,13 @@ # limitations under the License. # import os -import mock -import packaging.version + +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock +except ImportError: + import mock import grpc from grpc.experimental import aio @@ -30,8 +35,10 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.aiplatform_v1beta1.services.tensorboard_service import ( @@ -42,12 +49,6 @@ ) from google.cloud.aiplatform_v1beta1.services.tensorboard_service import pagers from google.cloud.aiplatform_v1beta1.services.tensorboard_service import transports -from google.cloud.aiplatform_v1beta1.services.tensorboard_service.transports.base import ( - _API_CORE_VERSION, -) -from google.cloud.aiplatform_v1beta1.services.tensorboard_service.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.aiplatform_v1beta1.types import encryption_spec from google.cloud.aiplatform_v1beta1.types import operation as gca_operation from google.cloud.aiplatform_v1beta1.types import tensorboard @@ -64,6 +65,10 @@ from google.cloud.aiplatform_v1beta1.types import ( tensorboard_time_series as gca_tensorboard_time_series, ) +from google.cloud.location import locations_pb2 +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 from google.oauth2 import service_account from google.protobuf import field_mask_pb2 # type: ignore @@ -71,29 +76,6 @@ import google.auth -# TODO(busunkim): Once google-api-core >= 1.26.0 is required: -# - Delete all the api-core and auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - -requires_api_core_lt_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), - reason="This test requires google-api-core < 1.26.0", -) - -requires_api_core_gte_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), - reason="This test requires google-api-core >= 1.26.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -140,40 +122,81 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( - "client_class", [TensorboardServiceClient, TensorboardServiceAsyncClient,] + "client_class,transport_name", + [ + (TensorboardServiceClient, "grpc"), + (TensorboardServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_tensorboard_service_client_from_service_account_info(client_class): +def test_tensorboard_service_client_from_service_account_info( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.TensorboardServiceGrpcTransport, "grpc"), + (transports.TensorboardServiceGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_tensorboard_service_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() @pytest.mark.parametrize( - "client_class", [TensorboardServiceClient, TensorboardServiceAsyncClient,] + "client_class,transport_name", + [ + (TensorboardServiceClient, "grpc"), + (TensorboardServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_tensorboard_service_client_from_service_account_file(client_class): +def test_tensorboard_service_client_from_service_account_file( + client_class, transport_name +): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") def test_tensorboard_service_client_get_transport_class(): @@ -226,7 +249,7 @@ def test_tensorboard_service_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -235,6 +258,7 @@ def test_tensorboard_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -242,7 +266,7 @@ def test_tensorboard_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -251,6 +275,7 @@ def test_tensorboard_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -258,7 +283,7 @@ def test_tensorboard_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -267,26 +292,27 @@ def test_tensorboard_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -295,6 +321,7 @@ def test_tensorboard_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -354,7 +381,7 @@ def test_tensorboard_service_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -371,6 +398,7 @@ def test_tensorboard_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case ADC client cert is provided. Whether client cert is used depends on @@ -395,7 +423,7 @@ def test_tensorboard_service_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -404,6 +432,7 @@ def test_tensorboard_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case client_cert_source and ADC client cert are not provided. @@ -416,7 +445,7 @@ def test_tensorboard_service_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -425,9 +454,91 @@ def test_tensorboard_service_client_mtls_env_auto( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) +@pytest.mark.parametrize( + "client_class", [TensorboardServiceClient, TensorboardServiceAsyncClient] +) +@mock.patch.object( + TensorboardServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(TensorboardServiceClient), +) +@mock.patch.object( + TensorboardServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(TensorboardServiceAsyncClient), +) +def test_tensorboard_service_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + @pytest.mark.parametrize( "client_class,transport_class,transport_name", [ @@ -443,10 +554,12 @@ def test_tensorboard_service_client_client_options_scopes( client_class, transport_class, transport_name ): # Check the case scopes are provided. - options = client_options.ClientOptions(scopes=["1", "2"],) + options = client_options.ClientOptions( + scopes=["1", "2"], + ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -455,28 +568,36 @@ def test_tensorboard_service_client_client_options_scopes( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (TensorboardServiceClient, transports.TensorboardServiceGrpcTransport, "grpc"), + ( + TensorboardServiceClient, + transports.TensorboardServiceGrpcTransport, + "grpc", + grpc_helpers, + ), ( TensorboardServiceAsyncClient, transports.TensorboardServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_tensorboard_service_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -485,6 +606,7 @@ def test_tensorboard_service_client_client_options_credentials_file( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -504,14 +626,87 @@ def test_tensorboard_service_client_client_options_from_dict(): client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) -def test_create_tensorboard( - transport: str = "grpc", request_type=tensorboard_service.CreateTensorboardRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + TensorboardServiceClient, + transports.TensorboardServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + TensorboardServiceAsyncClient, + transports.TensorboardServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_tensorboard_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers ): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.CreateTensorboardRequest, + dict, + ], +) +def test_create_tensorboard(request_type, transport: str = "grpc"): client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -535,15 +730,12 @@ def test_create_tensorboard( assert isinstance(response, future.Future) -def test_create_tensorboard_from_dict(): - test_create_tensorboard(request_type=dict) - - def test_create_tensorboard_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -562,7 +754,8 @@ async def test_create_tensorboard_async( request_type=tensorboard_service.CreateTensorboardRequest, ): client = TensorboardServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -602,7 +795,7 @@ def test_create_tensorboard_field_headers(): # a field header. Set these to a non-empty value. request = tensorboard_service.CreateTensorboardRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -618,7 +811,10 @@ def test_create_tensorboard_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -631,7 +827,7 @@ async def test_create_tensorboard_field_headers_async(): # a field header. Set these to a non-empty value. request = tensorboard_service.CreateTensorboardRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -649,7 +845,10 @@ async def test_create_tensorboard_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_create_tensorboard_flattened(): @@ -674,8 +873,12 @@ def test_create_tensorboard_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].tensorboard == gca_tensorboard.Tensorboard(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].tensorboard + mock_val = gca_tensorboard.Tensorboard(name="name_value") + assert arg == mock_val def test_create_tensorboard_flattened_error(): @@ -720,8 +923,12 @@ async def test_create_tensorboard_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].tensorboard == gca_tensorboard.Tensorboard(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].tensorboard + mock_val = gca_tensorboard.Tensorboard(name="name_value") + assert arg == mock_val @pytest.mark.asyncio @@ -740,11 +947,17 @@ async def test_create_tensorboard_flattened_error_async(): ) -def test_get_tensorboard( - transport: str = "grpc", request_type=tensorboard_service.GetTensorboardRequest -): +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.GetTensorboardRequest, + dict, + ], +) +def test_get_tensorboard(request_type, transport: str = "grpc"): client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -779,15 +992,12 @@ def test_get_tensorboard( assert response.etag == "etag_value" -def test_get_tensorboard_from_dict(): - test_get_tensorboard(request_type=dict) - - def test_get_tensorboard_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -804,7 +1014,8 @@ async def test_get_tensorboard_async( request_type=tensorboard_service.GetTensorboardRequest, ): client = TensorboardServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -855,7 +1066,7 @@ def test_get_tensorboard_field_headers(): # a field header. Set these to a non-empty value. request = tensorboard_service.GetTensorboardRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_tensorboard), "__call__") as call: @@ -869,7 +1080,10 @@ def test_get_tensorboard_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -882,7 +1096,7 @@ async def test_get_tensorboard_field_headers_async(): # a field header. Set these to a non-empty value. request = tensorboard_service.GetTensorboardRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_tensorboard), "__call__") as call: @@ -898,7 +1112,10 @@ async def test_get_tensorboard_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_get_tensorboard_flattened(): @@ -912,13 +1129,17 @@ def test_get_tensorboard_flattened(): call.return_value = tensorboard.Tensorboard() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_tensorboard(name="name_value",) + client.get_tensorboard( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_tensorboard_flattened_error(): @@ -930,7 +1151,8 @@ def test_get_tensorboard_flattened_error(): # fields is an error. with pytest.raises(ValueError): client.get_tensorboard( - tensorboard_service.GetTensorboardRequest(), name="name_value", + tensorboard_service.GetTensorboardRequest(), + name="name_value", ) @@ -950,13 +1172,17 @@ async def test_get_tensorboard_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_tensorboard(name="name_value",) + response = await client.get_tensorboard( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -969,15 +1195,22 @@ async def test_get_tensorboard_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.get_tensorboard( - tensorboard_service.GetTensorboardRequest(), name="name_value", + tensorboard_service.GetTensorboardRequest(), + name="name_value", ) -def test_update_tensorboard( - transport: str = "grpc", request_type=tensorboard_service.UpdateTensorboardRequest -): +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.UpdateTensorboardRequest, + dict, + ], +) +def test_update_tensorboard(request_type, transport: str = "grpc"): client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1001,15 +1234,12 @@ def test_update_tensorboard( assert isinstance(response, future.Future) -def test_update_tensorboard_from_dict(): - test_update_tensorboard(request_type=dict) - - def test_update_tensorboard_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1028,7 +1258,8 @@ async def test_update_tensorboard_async( request_type=tensorboard_service.UpdateTensorboardRequest, ): client = TensorboardServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1068,7 +1299,7 @@ def test_update_tensorboard_field_headers(): # a field header. Set these to a non-empty value. request = tensorboard_service.UpdateTensorboardRequest() - request.tensorboard.name = "tensorboard.name/value" + request.tensorboard.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1084,9 +1315,10 @@ def test_update_tensorboard_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "tensorboard.name=tensorboard.name/value",) in kw[ - "metadata" - ] + assert ( + "x-goog-request-params", + "tensorboard.name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1099,7 +1331,7 @@ async def test_update_tensorboard_field_headers_async(): # a field header. Set these to a non-empty value. request = tensorboard_service.UpdateTensorboardRequest() - request.tensorboard.name = "tensorboard.name/value" + request.tensorboard.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1117,9 +1349,10 @@ async def test_update_tensorboard_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "tensorboard.name=tensorboard.name/value",) in kw[ - "metadata" - ] + assert ( + "x-goog-request-params", + "tensorboard.name=name_value", + ) in kw["metadata"] def test_update_tensorboard_flattened(): @@ -1144,8 +1377,12 @@ def test_update_tensorboard_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].tensorboard == gca_tensorboard.Tensorboard(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].tensorboard + mock_val = gca_tensorboard.Tensorboard(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val def test_update_tensorboard_flattened_error(): @@ -1190,8 +1427,12 @@ async def test_update_tensorboard_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].tensorboard == gca_tensorboard.Tensorboard(name="name_value") - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].tensorboard + mock_val = gca_tensorboard.Tensorboard(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val @pytest.mark.asyncio @@ -1210,11 +1451,17 @@ async def test_update_tensorboard_flattened_error_async(): ) -def test_list_tensorboards( - transport: str = "grpc", request_type=tensorboard_service.ListTensorboardsRequest -): +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.ListTensorboardsRequest, + dict, + ], +) +def test_list_tensorboards(request_type, transport: str = "grpc"): client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1241,15 +1488,12 @@ def test_list_tensorboards( assert response.next_page_token == "next_page_token_value" -def test_list_tensorboards_from_dict(): - test_list_tensorboards(request_type=dict) - - def test_list_tensorboards_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1268,7 +1512,8 @@ async def test_list_tensorboards_async( request_type=tensorboard_service.ListTensorboardsRequest, ): client = TensorboardServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1311,7 +1556,7 @@ def test_list_tensorboards_field_headers(): # a field header. Set these to a non-empty value. request = tensorboard_service.ListTensorboardsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1327,7 +1572,10 @@ def test_list_tensorboards_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1340,7 +1588,7 @@ async def test_list_tensorboards_field_headers_async(): # a field header. Set these to a non-empty value. request = tensorboard_service.ListTensorboardsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1358,7 +1606,10 @@ async def test_list_tensorboards_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_tensorboards_flattened(): @@ -1374,13 +1625,17 @@ def test_list_tensorboards_flattened(): call.return_value = tensorboard_service.ListTensorboardsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_tensorboards(parent="parent_value",) + client.list_tensorboards( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_tensorboards_flattened_error(): @@ -1392,7 +1647,8 @@ def test_list_tensorboards_flattened_error(): # fields is an error. with pytest.raises(ValueError): client.list_tensorboards( - tensorboard_service.ListTensorboardsRequest(), parent="parent_value", + tensorboard_service.ListTensorboardsRequest(), + parent="parent_value", ) @@ -1414,13 +1670,17 @@ async def test_list_tensorboards_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_tensorboards(parent="parent_value",) + response = await client.list_tensorboards( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1433,12 +1693,16 @@ async def test_list_tensorboards_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.list_tensorboards( - tensorboard_service.ListTensorboardsRequest(), parent="parent_value", + tensorboard_service.ListTensorboardsRequest(), + parent="parent_value", ) -def test_list_tensorboards_pager(): - client = TensorboardServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_tensorboards_pager(transport_name: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1455,13 +1719,20 @@ def test_list_tensorboards_pager(): next_page_token="abc", ), tensorboard_service.ListTensorboardsResponse( - tensorboards=[], next_page_token="def", + tensorboards=[], + next_page_token="def", ), tensorboard_service.ListTensorboardsResponse( - tensorboards=[tensorboard.Tensorboard(),], next_page_token="ghi", + tensorboards=[ + tensorboard.Tensorboard(), + ], + next_page_token="ghi", ), tensorboard_service.ListTensorboardsResponse( - tensorboards=[tensorboard.Tensorboard(), tensorboard.Tensorboard(),], + tensorboards=[ + tensorboard.Tensorboard(), + tensorboard.Tensorboard(), + ], ), RuntimeError, ) @@ -1474,13 +1745,16 @@ def test_list_tensorboards_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all(isinstance(i, tensorboard.Tensorboard) for i in results) -def test_list_tensorboards_pages(): - client = TensorboardServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_tensorboards_pages(transport_name: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1497,13 +1771,20 @@ def test_list_tensorboards_pages(): next_page_token="abc", ), tensorboard_service.ListTensorboardsResponse( - tensorboards=[], next_page_token="def", + tensorboards=[], + next_page_token="def", ), tensorboard_service.ListTensorboardsResponse( - tensorboards=[tensorboard.Tensorboard(),], next_page_token="ghi", + tensorboards=[ + tensorboard.Tensorboard(), + ], + next_page_token="ghi", ), tensorboard_service.ListTensorboardsResponse( - tensorboards=[tensorboard.Tensorboard(), tensorboard.Tensorboard(),], + tensorboards=[ + tensorboard.Tensorboard(), + tensorboard.Tensorboard(), + ], ), RuntimeError, ) @@ -1535,20 +1816,29 @@ async def test_list_tensorboards_async_pager(): next_page_token="abc", ), tensorboard_service.ListTensorboardsResponse( - tensorboards=[], next_page_token="def", + tensorboards=[], + next_page_token="def", ), tensorboard_service.ListTensorboardsResponse( - tensorboards=[tensorboard.Tensorboard(),], next_page_token="ghi", + tensorboards=[ + tensorboard.Tensorboard(), + ], + next_page_token="ghi", ), tensorboard_service.ListTensorboardsResponse( - tensorboards=[tensorboard.Tensorboard(), tensorboard.Tensorboard(),], + tensorboards=[ + tensorboard.Tensorboard(), + tensorboard.Tensorboard(), + ], ), RuntimeError, ) - async_pager = await client.list_tensorboards(request={},) + async_pager = await client.list_tensorboards( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -1578,28 +1868,43 @@ async def test_list_tensorboards_async_pages(): next_page_token="abc", ), tensorboard_service.ListTensorboardsResponse( - tensorboards=[], next_page_token="def", + tensorboards=[], + next_page_token="def", ), tensorboard_service.ListTensorboardsResponse( - tensorboards=[tensorboard.Tensorboard(),], next_page_token="ghi", + tensorboards=[ + tensorboard.Tensorboard(), + ], + next_page_token="ghi", ), tensorboard_service.ListTensorboardsResponse( - tensorboards=[tensorboard.Tensorboard(), tensorboard.Tensorboard(),], + tensorboards=[ + tensorboard.Tensorboard(), + tensorboard.Tensorboard(), + ], ), RuntimeError, ) pages = [] - async for page_ in (await client.list_tensorboards(request={})).pages: + async for page_ in ( + await client.list_tensorboards(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_delete_tensorboard( - transport: str = "grpc", request_type=tensorboard_service.DeleteTensorboardRequest -): +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.DeleteTensorboardRequest, + dict, + ], +) +def test_delete_tensorboard(request_type, transport: str = "grpc"): client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1623,15 +1928,12 @@ def test_delete_tensorboard( assert isinstance(response, future.Future) -def test_delete_tensorboard_from_dict(): - test_delete_tensorboard(request_type=dict) - - def test_delete_tensorboard_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1650,7 +1952,8 @@ async def test_delete_tensorboard_async( request_type=tensorboard_service.DeleteTensorboardRequest, ): client = TensorboardServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1690,7 +1993,7 @@ def test_delete_tensorboard_field_headers(): # a field header. Set these to a non-empty value. request = tensorboard_service.DeleteTensorboardRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1706,7 +2009,10 @@ def test_delete_tensorboard_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1719,7 +2025,7 @@ async def test_delete_tensorboard_field_headers_async(): # a field header. Set these to a non-empty value. request = tensorboard_service.DeleteTensorboardRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1737,7 +2043,10 @@ async def test_delete_tensorboard_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_delete_tensorboard_flattened(): @@ -1753,13 +2062,17 @@ def test_delete_tensorboard_flattened(): call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_tensorboard(name="name_value",) - - # Establish that the underlying call was made with the expected + client.delete_tensorboard( + name="name_value", + ) + + # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_delete_tensorboard_flattened_error(): @@ -1771,7 +2084,8 @@ def test_delete_tensorboard_flattened_error(): # fields is an error. with pytest.raises(ValueError): client.delete_tensorboard( - tensorboard_service.DeleteTensorboardRequest(), name="name_value", + tensorboard_service.DeleteTensorboardRequest(), + name="name_value", ) @@ -1793,13 +2107,17 @@ async def test_delete_tensorboard_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_tensorboard(name="name_value",) + response = await client.delete_tensorboard( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1812,16 +2130,22 @@ async def test_delete_tensorboard_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.delete_tensorboard( - tensorboard_service.DeleteTensorboardRequest(), name="name_value", + tensorboard_service.DeleteTensorboardRequest(), + name="name_value", ) -def test_create_tensorboard_experiment( - transport: str = "grpc", - request_type=tensorboard_service.CreateTensorboardExperimentRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.CreateTensorboardExperimentRequest, + dict, + ], +) +def test_create_tensorboard_experiment(request_type, transport: str = "grpc"): client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1856,15 +2180,12 @@ def test_create_tensorboard_experiment( assert response.source == "source_value" -def test_create_tensorboard_experiment_from_dict(): - test_create_tensorboard_experiment(request_type=dict) - - def test_create_tensorboard_experiment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1883,7 +2204,8 @@ async def test_create_tensorboard_experiment_async( request_type=tensorboard_service.CreateTensorboardExperimentRequest, ): client = TensorboardServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1934,7 +2256,7 @@ def test_create_tensorboard_experiment_field_headers(): # a field header. Set these to a non-empty value. request = tensorboard_service.CreateTensorboardExperimentRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1950,7 +2272,10 @@ def test_create_tensorboard_experiment_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1963,7 +2288,7 @@ async def test_create_tensorboard_experiment_field_headers_async(): # a field header. Set these to a non-empty value. request = tensorboard_service.CreateTensorboardExperimentRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1981,7 +2306,10 @@ async def test_create_tensorboard_experiment_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_create_tensorboard_experiment_flattened(): @@ -2009,13 +2337,15 @@ def test_create_tensorboard_experiment_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[ - 0 - ].tensorboard_experiment == gca_tensorboard_experiment.TensorboardExperiment( - name="name_value" - ) - assert args[0].tensorboard_experiment_id == "tensorboard_experiment_id_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].tensorboard_experiment + mock_val = gca_tensorboard_experiment.TensorboardExperiment(name="name_value") + assert arg == mock_val + arg = args[0].tensorboard_experiment_id + mock_val = "tensorboard_experiment_id_value" + assert arg == mock_val def test_create_tensorboard_experiment_flattened_error(): @@ -2066,13 +2396,15 @@ async def test_create_tensorboard_experiment_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[ - 0 - ].tensorboard_experiment == gca_tensorboard_experiment.TensorboardExperiment( - name="name_value" - ) - assert args[0].tensorboard_experiment_id == "tensorboard_experiment_id_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].tensorboard_experiment + mock_val = gca_tensorboard_experiment.TensorboardExperiment(name="name_value") + assert arg == mock_val + arg = args[0].tensorboard_experiment_id + mock_val = "tensorboard_experiment_id_value" + assert arg == mock_val @pytest.mark.asyncio @@ -2094,12 +2426,17 @@ async def test_create_tensorboard_experiment_flattened_error_async(): ) -def test_get_tensorboard_experiment( - transport: str = "grpc", - request_type=tensorboard_service.GetTensorboardExperimentRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.GetTensorboardExperimentRequest, + dict, + ], +) +def test_get_tensorboard_experiment(request_type, transport: str = "grpc"): client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2134,15 +2471,12 @@ def test_get_tensorboard_experiment( assert response.source == "source_value" -def test_get_tensorboard_experiment_from_dict(): - test_get_tensorboard_experiment(request_type=dict) - - def test_get_tensorboard_experiment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2161,7 +2495,8 @@ async def test_get_tensorboard_experiment_async( request_type=tensorboard_service.GetTensorboardExperimentRequest, ): client = TensorboardServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2212,7 +2547,7 @@ def test_get_tensorboard_experiment_field_headers(): # a field header. Set these to a non-empty value. request = tensorboard_service.GetTensorboardExperimentRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2228,7 +2563,10 @@ def test_get_tensorboard_experiment_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2241,7 +2579,7 @@ async def test_get_tensorboard_experiment_field_headers_async(): # a field header. Set these to a non-empty value. request = tensorboard_service.GetTensorboardExperimentRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2259,7 +2597,10 @@ async def test_get_tensorboard_experiment_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_get_tensorboard_experiment_flattened(): @@ -2275,13 +2616,17 @@ def test_get_tensorboard_experiment_flattened(): call.return_value = tensorboard_experiment.TensorboardExperiment() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_tensorboard_experiment(name="name_value",) + client.get_tensorboard_experiment( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_tensorboard_experiment_flattened_error(): @@ -2293,7 +2638,8 @@ def test_get_tensorboard_experiment_flattened_error(): # fields is an error. with pytest.raises(ValueError): client.get_tensorboard_experiment( - tensorboard_service.GetTensorboardExperimentRequest(), name="name_value", + tensorboard_service.GetTensorboardExperimentRequest(), + name="name_value", ) @@ -2315,13 +2661,17 @@ async def test_get_tensorboard_experiment_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_tensorboard_experiment(name="name_value",) + response = await client.get_tensorboard_experiment( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -2334,16 +2684,22 @@ async def test_get_tensorboard_experiment_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.get_tensorboard_experiment( - tensorboard_service.GetTensorboardExperimentRequest(), name="name_value", + tensorboard_service.GetTensorboardExperimentRequest(), + name="name_value", ) -def test_update_tensorboard_experiment( - transport: str = "grpc", - request_type=tensorboard_service.UpdateTensorboardExperimentRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.UpdateTensorboardExperimentRequest, + dict, + ], +) +def test_update_tensorboard_experiment(request_type, transport: str = "grpc"): client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2378,15 +2734,12 @@ def test_update_tensorboard_experiment( assert response.source == "source_value" -def test_update_tensorboard_experiment_from_dict(): - test_update_tensorboard_experiment(request_type=dict) - - def test_update_tensorboard_experiment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2405,7 +2758,8 @@ async def test_update_tensorboard_experiment_async( request_type=tensorboard_service.UpdateTensorboardExperimentRequest, ): client = TensorboardServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2456,7 +2810,7 @@ def test_update_tensorboard_experiment_field_headers(): # a field header. Set these to a non-empty value. request = tensorboard_service.UpdateTensorboardExperimentRequest() - request.tensorboard_experiment.name = "tensorboard_experiment.name/value" + request.tensorboard_experiment.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2474,7 +2828,7 @@ def test_update_tensorboard_experiment_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "tensorboard_experiment.name=tensorboard_experiment.name/value", + "tensorboard_experiment.name=name_value", ) in kw["metadata"] @@ -2488,7 +2842,7 @@ async def test_update_tensorboard_experiment_field_headers_async(): # a field header. Set these to a non-empty value. request = tensorboard_service.UpdateTensorboardExperimentRequest() - request.tensorboard_experiment.name = "tensorboard_experiment.name/value" + request.tensorboard_experiment.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2508,7 +2862,7 @@ async def test_update_tensorboard_experiment_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "tensorboard_experiment.name=tensorboard_experiment.name/value", + "tensorboard_experiment.name=name_value", ) in kw["metadata"] @@ -2536,12 +2890,12 @@ def test_update_tensorboard_experiment_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[ - 0 - ].tensorboard_experiment == gca_tensorboard_experiment.TensorboardExperiment( - name="name_value" - ) - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].tensorboard_experiment + mock_val = gca_tensorboard_experiment.TensorboardExperiment(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val def test_update_tensorboard_experiment_flattened_error(): @@ -2590,12 +2944,12 @@ async def test_update_tensorboard_experiment_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[ - 0 - ].tensorboard_experiment == gca_tensorboard_experiment.TensorboardExperiment( - name="name_value" - ) - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].tensorboard_experiment + mock_val = gca_tensorboard_experiment.TensorboardExperiment(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val @pytest.mark.asyncio @@ -2616,12 +2970,17 @@ async def test_update_tensorboard_experiment_flattened_error_async(): ) -def test_list_tensorboard_experiments( - transport: str = "grpc", - request_type=tensorboard_service.ListTensorboardExperimentsRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.ListTensorboardExperimentsRequest, + dict, + ], +) +def test_list_tensorboard_experiments(request_type, transport: str = "grpc"): client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2648,15 +3007,12 @@ def test_list_tensorboard_experiments( assert response.next_page_token == "next_page_token_value" -def test_list_tensorboard_experiments_from_dict(): - test_list_tensorboard_experiments(request_type=dict) - - def test_list_tensorboard_experiments_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2675,7 +3031,8 @@ async def test_list_tensorboard_experiments_async( request_type=tensorboard_service.ListTensorboardExperimentsRequest, ): client = TensorboardServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2718,7 +3075,7 @@ def test_list_tensorboard_experiments_field_headers(): # a field header. Set these to a non-empty value. request = tensorboard_service.ListTensorboardExperimentsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2734,7 +3091,10 @@ def test_list_tensorboard_experiments_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2747,7 +3107,7 @@ async def test_list_tensorboard_experiments_field_headers_async(): # a field header. Set these to a non-empty value. request = tensorboard_service.ListTensorboardExperimentsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2765,7 +3125,10 @@ async def test_list_tensorboard_experiments_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_tensorboard_experiments_flattened(): @@ -2781,13 +3144,17 @@ def test_list_tensorboard_experiments_flattened(): call.return_value = tensorboard_service.ListTensorboardExperimentsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_tensorboard_experiments(parent="parent_value",) + client.list_tensorboard_experiments( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_tensorboard_experiments_flattened_error(): @@ -2822,13 +3189,17 @@ async def test_list_tensorboard_experiments_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_tensorboard_experiments(parent="parent_value",) + response = await client.list_tensorboard_experiments( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -2846,8 +3217,11 @@ async def test_list_tensorboard_experiments_flattened_error_async(): ) -def test_list_tensorboard_experiments_pager(): - client = TensorboardServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_tensorboard_experiments_pager(transport_name: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2864,7 +3238,8 @@ def test_list_tensorboard_experiments_pager(): next_page_token="abc", ), tensorboard_service.ListTensorboardExperimentsResponse( - tensorboard_experiments=[], next_page_token="def", + tensorboard_experiments=[], + next_page_token="def", ), tensorboard_service.ListTensorboardExperimentsResponse( tensorboard_experiments=[ @@ -2889,15 +3264,18 @@ def test_list_tensorboard_experiments_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all( isinstance(i, tensorboard_experiment.TensorboardExperiment) for i in results ) -def test_list_tensorboard_experiments_pages(): - client = TensorboardServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_tensorboard_experiments_pages(transport_name: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2914,7 +3292,8 @@ def test_list_tensorboard_experiments_pages(): next_page_token="abc", ), tensorboard_service.ListTensorboardExperimentsResponse( - tensorboard_experiments=[], next_page_token="def", + tensorboard_experiments=[], + next_page_token="def", ), tensorboard_service.ListTensorboardExperimentsResponse( tensorboard_experiments=[ @@ -2958,7 +3337,8 @@ async def test_list_tensorboard_experiments_async_pager(): next_page_token="abc", ), tensorboard_service.ListTensorboardExperimentsResponse( - tensorboard_experiments=[], next_page_token="def", + tensorboard_experiments=[], + next_page_token="def", ), tensorboard_service.ListTensorboardExperimentsResponse( tensorboard_experiments=[ @@ -2974,10 +3354,12 @@ async def test_list_tensorboard_experiments_async_pager(): ), RuntimeError, ) - async_pager = await client.list_tensorboard_experiments(request={},) + async_pager = await client.list_tensorboard_experiments( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -3010,7 +3392,8 @@ async def test_list_tensorboard_experiments_async_pages(): next_page_token="abc", ), tensorboard_service.ListTensorboardExperimentsResponse( - tensorboard_experiments=[], next_page_token="def", + tensorboard_experiments=[], + next_page_token="def", ), tensorboard_service.ListTensorboardExperimentsResponse( tensorboard_experiments=[ @@ -3029,18 +3412,23 @@ async def test_list_tensorboard_experiments_async_pages(): pages = [] async for page_ in ( await client.list_tensorboard_experiments(request={}) - ).pages: + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_delete_tensorboard_experiment( - transport: str = "grpc", - request_type=tensorboard_service.DeleteTensorboardExperimentRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.DeleteTensorboardExperimentRequest, + dict, + ], +) +def test_delete_tensorboard_experiment(request_type, transport: str = "grpc"): client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3064,15 +3452,12 @@ def test_delete_tensorboard_experiment( assert isinstance(response, future.Future) -def test_delete_tensorboard_experiment_from_dict(): - test_delete_tensorboard_experiment(request_type=dict) - - def test_delete_tensorboard_experiment_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3091,7 +3476,8 @@ async def test_delete_tensorboard_experiment_async( request_type=tensorboard_service.DeleteTensorboardExperimentRequest, ): client = TensorboardServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3131,7 +3517,7 @@ def test_delete_tensorboard_experiment_field_headers(): # a field header. Set these to a non-empty value. request = tensorboard_service.DeleteTensorboardExperimentRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3147,7 +3533,10 @@ def test_delete_tensorboard_experiment_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -3160,7 +3549,7 @@ async def test_delete_tensorboard_experiment_field_headers_async(): # a field header. Set these to a non-empty value. request = tensorboard_service.DeleteTensorboardExperimentRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3178,7 +3567,10 @@ async def test_delete_tensorboard_experiment_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_delete_tensorboard_experiment_flattened(): @@ -3194,13 +3586,17 @@ def test_delete_tensorboard_experiment_flattened(): call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_tensorboard_experiment(name="name_value",) + client.delete_tensorboard_experiment( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_delete_tensorboard_experiment_flattened_error(): @@ -3212,7 +3608,8 @@ def test_delete_tensorboard_experiment_flattened_error(): # fields is an error. with pytest.raises(ValueError): client.delete_tensorboard_experiment( - tensorboard_service.DeleteTensorboardExperimentRequest(), name="name_value", + tensorboard_service.DeleteTensorboardExperimentRequest(), + name="name_value", ) @@ -3234,13 +3631,17 @@ async def test_delete_tensorboard_experiment_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_tensorboard_experiment(name="name_value",) + response = await client.delete_tensorboard_experiment( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -3253,16 +3654,22 @@ async def test_delete_tensorboard_experiment_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.delete_tensorboard_experiment( - tensorboard_service.DeleteTensorboardExperimentRequest(), name="name_value", + tensorboard_service.DeleteTensorboardExperimentRequest(), + name="name_value", ) -def test_create_tensorboard_run( - transport: str = "grpc", - request_type=tensorboard_service.CreateTensorboardRunRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.CreateTensorboardRunRequest, + dict, + ], +) +def test_create_tensorboard_run(request_type, transport: str = "grpc"): client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3295,15 +3702,12 @@ def test_create_tensorboard_run( assert response.etag == "etag_value" -def test_create_tensorboard_run_from_dict(): - test_create_tensorboard_run(request_type=dict) - - def test_create_tensorboard_run_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3322,7 +3726,8 @@ async def test_create_tensorboard_run_async( request_type=tensorboard_service.CreateTensorboardRunRequest, ): client = TensorboardServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3371,7 +3776,7 @@ def test_create_tensorboard_run_field_headers(): # a field header. Set these to a non-empty value. request = tensorboard_service.CreateTensorboardRunRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3387,7 +3792,10 @@ def test_create_tensorboard_run_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -3400,7 +3808,7 @@ async def test_create_tensorboard_run_field_headers_async(): # a field header. Set these to a non-empty value. request = tensorboard_service.CreateTensorboardRunRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3418,7 +3826,10 @@ async def test_create_tensorboard_run_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_create_tensorboard_run_flattened(): @@ -3444,11 +3855,15 @@ def test_create_tensorboard_run_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].tensorboard_run == gca_tensorboard_run.TensorboardRun( - name="name_value" - ) - assert args[0].tensorboard_run_id == "tensorboard_run_id_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].tensorboard_run + mock_val = gca_tensorboard_run.TensorboardRun(name="name_value") + assert arg == mock_val + arg = args[0].tensorboard_run_id + mock_val = "tensorboard_run_id_value" + assert arg == mock_val def test_create_tensorboard_run_flattened_error(): @@ -3495,11 +3910,15 @@ async def test_create_tensorboard_run_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].tensorboard_run == gca_tensorboard_run.TensorboardRun( - name="name_value" - ) - assert args[0].tensorboard_run_id == "tensorboard_run_id_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].tensorboard_run + mock_val = gca_tensorboard_run.TensorboardRun(name="name_value") + assert arg == mock_val + arg = args[0].tensorboard_run_id + mock_val = "tensorboard_run_id_value" + assert arg == mock_val @pytest.mark.asyncio @@ -3519,11 +3938,17 @@ async def test_create_tensorboard_run_flattened_error_async(): ) -def test_get_tensorboard_run( - transport: str = "grpc", request_type=tensorboard_service.GetTensorboardRunRequest -): +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.BatchCreateTensorboardRunsRequest, + dict, + ], +) +def test_batch_create_tensorboard_runs(request_type, transport: str = "grpc"): client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3532,58 +3957,47 @@ def test_get_tensorboard_run( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_tensorboard_run), "__call__" + type(client.transport.batch_create_tensorboard_runs), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = tensorboard_run.TensorboardRun( - name="name_value", - display_name="display_name_value", - description="description_value", - etag="etag_value", - ) - response = client.get_tensorboard_run(request) + call.return_value = tensorboard_service.BatchCreateTensorboardRunsResponse() + response = client.batch_create_tensorboard_runs(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.GetTensorboardRunRequest() + assert args[0] == tensorboard_service.BatchCreateTensorboardRunsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, tensorboard_run.TensorboardRun) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.description == "description_value" - assert response.etag == "etag_value" - + assert isinstance(response, tensorboard_service.BatchCreateTensorboardRunsResponse) -def test_get_tensorboard_run_from_dict(): - test_get_tensorboard_run(request_type=dict) - -def test_get_tensorboard_run_empty_call(): +def test_batch_create_tensorboard_runs_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_tensorboard_run), "__call__" + type(client.transport.batch_create_tensorboard_runs), "__call__" ) as call: - client.get_tensorboard_run() + client.batch_create_tensorboard_runs() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.GetTensorboardRunRequest() + assert args[0] == tensorboard_service.BatchCreateTensorboardRunsRequest() @pytest.mark.asyncio -async def test_get_tensorboard_run_async( +async def test_batch_create_tensorboard_runs_async( transport: str = "grpc_asyncio", - request_type=tensorboard_service.GetTensorboardRunRequest, + request_type=tensorboard_service.BatchCreateTensorboardRunsRequest, ): client = TensorboardServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3592,54 +4006,45 @@ async def test_get_tensorboard_run_async( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_tensorboard_run), "__call__" + type(client.transport.batch_create_tensorboard_runs), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - tensorboard_run.TensorboardRun( - name="name_value", - display_name="display_name_value", - description="description_value", - etag="etag_value", - ) + tensorboard_service.BatchCreateTensorboardRunsResponse() ) - response = await client.get_tensorboard_run(request) + response = await client.batch_create_tensorboard_runs(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.GetTensorboardRunRequest() + assert args[0] == tensorboard_service.BatchCreateTensorboardRunsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, tensorboard_run.TensorboardRun) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.description == "description_value" - assert response.etag == "etag_value" + assert isinstance(response, tensorboard_service.BatchCreateTensorboardRunsResponse) @pytest.mark.asyncio -async def test_get_tensorboard_run_async_from_dict(): - await test_get_tensorboard_run_async(request_type=dict) +async def test_batch_create_tensorboard_runs_async_from_dict(): + await test_batch_create_tensorboard_runs_async(request_type=dict) -def test_get_tensorboard_run_field_headers(): +def test_batch_create_tensorboard_runs_field_headers(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = tensorboard_service.GetTensorboardRunRequest() + request = tensorboard_service.BatchCreateTensorboardRunsRequest() - request.name = "name/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_tensorboard_run), "__call__" + type(client.transport.batch_create_tensorboard_runs), "__call__" ) as call: - call.return_value = tensorboard_run.TensorboardRun() - client.get_tensorboard_run(request) + call.return_value = tensorboard_service.BatchCreateTensorboardRunsResponse() + client.batch_create_tensorboard_runs(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -3648,29 +4053,32 @@ def test_get_tensorboard_run_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_get_tensorboard_run_field_headers_async(): +async def test_batch_create_tensorboard_runs_field_headers_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = tensorboard_service.GetTensorboardRunRequest() + request = tensorboard_service.BatchCreateTensorboardRunsRequest() - request.name = "name/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_tensorboard_run), "__call__" + type(client.transport.batch_create_tensorboard_runs), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - tensorboard_run.TensorboardRun() + tensorboard_service.BatchCreateTensorboardRunsResponse() ) - await client.get_tensorboard_run(request) + await client.batch_create_tensorboard_runs(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -3679,32 +4087,47 @@ async def test_get_tensorboard_run_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] -def test_get_tensorboard_run_flattened(): +def test_batch_create_tensorboard_runs_flattened(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_tensorboard_run), "__call__" + type(client.transport.batch_create_tensorboard_runs), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = tensorboard_run.TensorboardRun() + call.return_value = tensorboard_service.BatchCreateTensorboardRunsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_tensorboard_run(name="name_value",) + client.batch_create_tensorboard_runs( + parent="parent_value", + requests=[ + tensorboard_service.CreateTensorboardRunRequest(parent="parent_value") + ], + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].requests + mock_val = [ + tensorboard_service.CreateTensorboardRunRequest(parent="parent_value") + ] + assert arg == mock_val -def test_get_tensorboard_run_flattened_error(): +def test_batch_create_tensorboard_runs_flattened_error(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -3712,40 +4135,56 @@ def test_get_tensorboard_run_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_tensorboard_run( - tensorboard_service.GetTensorboardRunRequest(), name="name_value", + client.batch_create_tensorboard_runs( + tensorboard_service.BatchCreateTensorboardRunsRequest(), + parent="parent_value", + requests=[ + tensorboard_service.CreateTensorboardRunRequest(parent="parent_value") + ], ) @pytest.mark.asyncio -async def test_get_tensorboard_run_flattened_async(): +async def test_batch_create_tensorboard_runs_flattened_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_tensorboard_run), "__call__" + type(client.transport.batch_create_tensorboard_runs), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = tensorboard_run.TensorboardRun() + call.return_value = tensorboard_service.BatchCreateTensorboardRunsResponse() call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - tensorboard_run.TensorboardRun() + tensorboard_service.BatchCreateTensorboardRunsResponse() ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_tensorboard_run(name="name_value",) + response = await client.batch_create_tensorboard_runs( + parent="parent_value", + requests=[ + tensorboard_service.CreateTensorboardRunRequest(parent="parent_value") + ], + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].requests + mock_val = [ + tensorboard_service.CreateTensorboardRunRequest(parent="parent_value") + ] + assert arg == mock_val @pytest.mark.asyncio -async def test_get_tensorboard_run_flattened_error_async(): +async def test_batch_create_tensorboard_runs_flattened_error_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -3753,17 +4192,26 @@ async def test_get_tensorboard_run_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.get_tensorboard_run( - tensorboard_service.GetTensorboardRunRequest(), name="name_value", + await client.batch_create_tensorboard_runs( + tensorboard_service.BatchCreateTensorboardRunsRequest(), + parent="parent_value", + requests=[ + tensorboard_service.CreateTensorboardRunRequest(parent="parent_value") + ], ) -def test_update_tensorboard_run( - transport: str = "grpc", - request_type=tensorboard_service.UpdateTensorboardRunRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.GetTensorboardRunRequest, + dict, + ], +) +def test_get_tensorboard_run(request_type, transport: str = "grpc"): client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3772,58 +4220,56 @@ def test_update_tensorboard_run( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_tensorboard_run), "__call__" + type(client.transport.get_tensorboard_run), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = gca_tensorboard_run.TensorboardRun( + call.return_value = tensorboard_run.TensorboardRun( name="name_value", display_name="display_name_value", description="description_value", etag="etag_value", ) - response = client.update_tensorboard_run(request) + response = client.get_tensorboard_run(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.UpdateTensorboardRunRequest() + assert args[0] == tensorboard_service.GetTensorboardRunRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gca_tensorboard_run.TensorboardRun) + assert isinstance(response, tensorboard_run.TensorboardRun) assert response.name == "name_value" assert response.display_name == "display_name_value" assert response.description == "description_value" assert response.etag == "etag_value" -def test_update_tensorboard_run_from_dict(): - test_update_tensorboard_run(request_type=dict) - - -def test_update_tensorboard_run_empty_call(): +def test_get_tensorboard_run_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_tensorboard_run), "__call__" + type(client.transport.get_tensorboard_run), "__call__" ) as call: - client.update_tensorboard_run() + client.get_tensorboard_run() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.UpdateTensorboardRunRequest() + assert args[0] == tensorboard_service.GetTensorboardRunRequest() @pytest.mark.asyncio -async def test_update_tensorboard_run_async( +async def test_get_tensorboard_run_async( transport: str = "grpc_asyncio", - request_type=tensorboard_service.UpdateTensorboardRunRequest, + request_type=tensorboard_service.GetTensorboardRunRequest, ): client = TensorboardServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3832,26 +4278,26 @@ async def test_update_tensorboard_run_async( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_tensorboard_run), "__call__" + type(client.transport.get_tensorboard_run), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gca_tensorboard_run.TensorboardRun( + tensorboard_run.TensorboardRun( name="name_value", display_name="display_name_value", description="description_value", etag="etag_value", ) ) - response = await client.update_tensorboard_run(request) + response = await client.get_tensorboard_run(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.UpdateTensorboardRunRequest() + assert args[0] == tensorboard_service.GetTensorboardRunRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gca_tensorboard_run.TensorboardRun) + assert isinstance(response, tensorboard_run.TensorboardRun) assert response.name == "name_value" assert response.display_name == "display_name_value" assert response.description == "description_value" @@ -3859,27 +4305,27 @@ async def test_update_tensorboard_run_async( @pytest.mark.asyncio -async def test_update_tensorboard_run_async_from_dict(): - await test_update_tensorboard_run_async(request_type=dict) +async def test_get_tensorboard_run_async_from_dict(): + await test_get_tensorboard_run_async(request_type=dict) -def test_update_tensorboard_run_field_headers(): +def test_get_tensorboard_run_field_headers(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = tensorboard_service.UpdateTensorboardRunRequest() + request = tensorboard_service.GetTensorboardRunRequest() - request.tensorboard_run.name = "tensorboard_run.name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_tensorboard_run), "__call__" + type(client.transport.get_tensorboard_run), "__call__" ) as call: - call.return_value = gca_tensorboard_run.TensorboardRun() - client.update_tensorboard_run(request) + call.return_value = tensorboard_run.TensorboardRun() + client.get_tensorboard_run(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -3890,30 +4336,30 @@ def test_update_tensorboard_run_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "tensorboard_run.name=tensorboard_run.name/value", + "name=name_value", ) in kw["metadata"] @pytest.mark.asyncio -async def test_update_tensorboard_run_field_headers_async(): +async def test_get_tensorboard_run_field_headers_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = tensorboard_service.UpdateTensorboardRunRequest() + request = tensorboard_service.GetTensorboardRunRequest() - request.tensorboard_run.name = "tensorboard_run.name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_tensorboard_run), "__call__" + type(client.transport.get_tensorboard_run), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gca_tensorboard_run.TensorboardRun() + tensorboard_run.TensorboardRun() ) - await client.update_tensorboard_run(request) + await client.get_tensorboard_run(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -3924,39 +4370,37 @@ async def test_update_tensorboard_run_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "tensorboard_run.name=tensorboard_run.name/value", + "name=name_value", ) in kw["metadata"] -def test_update_tensorboard_run_flattened(): +def test_get_tensorboard_run_flattened(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_tensorboard_run), "__call__" + type(client.transport.get_tensorboard_run), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = gca_tensorboard_run.TensorboardRun() + call.return_value = tensorboard_run.TensorboardRun() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.update_tensorboard_run( - tensorboard_run=gca_tensorboard_run.TensorboardRun(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + client.get_tensorboard_run( + name="name_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].tensorboard_run == gca_tensorboard_run.TensorboardRun( - name="name_value" - ) - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val -def test_update_tensorboard_run_flattened_error(): +def test_get_tensorboard_run_flattened_error(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -3964,48 +4408,45 @@ def test_update_tensorboard_run_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.update_tensorboard_run( - tensorboard_service.UpdateTensorboardRunRequest(), - tensorboard_run=gca_tensorboard_run.TensorboardRun(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + client.get_tensorboard_run( + tensorboard_service.GetTensorboardRunRequest(), + name="name_value", ) @pytest.mark.asyncio -async def test_update_tensorboard_run_flattened_async(): +async def test_get_tensorboard_run_flattened_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_tensorboard_run), "__call__" + type(client.transport.get_tensorboard_run), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = gca_tensorboard_run.TensorboardRun() + call.return_value = tensorboard_run.TensorboardRun() call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gca_tensorboard_run.TensorboardRun() + tensorboard_run.TensorboardRun() ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.update_tensorboard_run( - tensorboard_run=gca_tensorboard_run.TensorboardRun(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + response = await client.get_tensorboard_run( + name="name_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].tensorboard_run == gca_tensorboard_run.TensorboardRun( - name="name_value" - ) - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio -async def test_update_tensorboard_run_flattened_error_async(): +async def test_get_tensorboard_run_flattened_error_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -4013,18 +4454,23 @@ async def test_update_tensorboard_run_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.update_tensorboard_run( - tensorboard_service.UpdateTensorboardRunRequest(), - tensorboard_run=gca_tensorboard_run.TensorboardRun(name="name_value"), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + await client.get_tensorboard_run( + tensorboard_service.GetTensorboardRunRequest(), + name="name_value", ) -def test_list_tensorboard_runs( - transport: str = "grpc", request_type=tensorboard_service.ListTensorboardRunsRequest -): +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.UpdateTensorboardRunRequest, + dict, + ], +) +def test_update_tensorboard_run(request_type, transport: str = "grpc"): client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4033,52 +4479,56 @@ def test_list_tensorboard_runs( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_tensorboard_runs), "__call__" + type(client.transport.update_tensorboard_run), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = tensorboard_service.ListTensorboardRunsResponse( - next_page_token="next_page_token_value", + call.return_value = gca_tensorboard_run.TensorboardRun( + name="name_value", + display_name="display_name_value", + description="description_value", + etag="etag_value", ) - response = client.list_tensorboard_runs(request) + response = client.update_tensorboard_run(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.ListTensorboardRunsRequest() + assert args[0] == tensorboard_service.UpdateTensorboardRunRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListTensorboardRunsPager) - assert response.next_page_token == "next_page_token_value" - - -def test_list_tensorboard_runs_from_dict(): - test_list_tensorboard_runs(request_type=dict) + assert isinstance(response, gca_tensorboard_run.TensorboardRun) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.etag == "etag_value" -def test_list_tensorboard_runs_empty_call(): +def test_update_tensorboard_run_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_tensorboard_runs), "__call__" + type(client.transport.update_tensorboard_run), "__call__" ) as call: - client.list_tensorboard_runs() + client.update_tensorboard_run() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.ListTensorboardRunsRequest() + assert args[0] == tensorboard_service.UpdateTensorboardRunRequest() @pytest.mark.asyncio -async def test_list_tensorboard_runs_async( +async def test_update_tensorboard_run_async( transport: str = "grpc_asyncio", - request_type=tensorboard_service.ListTensorboardRunsRequest, + request_type=tensorboard_service.UpdateTensorboardRunRequest, ): client = TensorboardServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4087,48 +4537,54 @@ async def test_list_tensorboard_runs_async( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_tensorboard_runs), "__call__" + type(client.transport.update_tensorboard_run), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - tensorboard_service.ListTensorboardRunsResponse( - next_page_token="next_page_token_value", + gca_tensorboard_run.TensorboardRun( + name="name_value", + display_name="display_name_value", + description="description_value", + etag="etag_value", ) ) - response = await client.list_tensorboard_runs(request) + response = await client.update_tensorboard_run(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.ListTensorboardRunsRequest() + assert args[0] == tensorboard_service.UpdateTensorboardRunRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListTensorboardRunsAsyncPager) - assert response.next_page_token == "next_page_token_value" + assert isinstance(response, gca_tensorboard_run.TensorboardRun) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert response.etag == "etag_value" @pytest.mark.asyncio -async def test_list_tensorboard_runs_async_from_dict(): - await test_list_tensorboard_runs_async(request_type=dict) +async def test_update_tensorboard_run_async_from_dict(): + await test_update_tensorboard_run_async(request_type=dict) -def test_list_tensorboard_runs_field_headers(): +def test_update_tensorboard_run_field_headers(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = tensorboard_service.ListTensorboardRunsRequest() + request = tensorboard_service.UpdateTensorboardRunRequest() - request.parent = "parent/value" + request.tensorboard_run.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_tensorboard_runs), "__call__" + type(client.transport.update_tensorboard_run), "__call__" ) as call: - call.return_value = tensorboard_service.ListTensorboardRunsResponse() - client.list_tensorboard_runs(request) + call.return_value = gca_tensorboard_run.TensorboardRun() + client.update_tensorboard_run(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -4137,29 +4593,32 @@ def test_list_tensorboard_runs_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "tensorboard_run.name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_list_tensorboard_runs_field_headers_async(): +async def test_update_tensorboard_run_field_headers_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = tensorboard_service.ListTensorboardRunsRequest() + request = tensorboard_service.UpdateTensorboardRunRequest() - request.parent = "parent/value" + request.tensorboard_run.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_tensorboard_runs), "__call__" + type(client.transport.update_tensorboard_run), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - tensorboard_service.ListTensorboardRunsResponse() + gca_tensorboard_run.TensorboardRun() ) - await client.list_tensorboard_runs(request) + await client.update_tensorboard_run(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -4168,32 +4627,43 @@ async def test_list_tensorboard_runs_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "tensorboard_run.name=name_value", + ) in kw["metadata"] -def test_list_tensorboard_runs_flattened(): +def test_update_tensorboard_run_flattened(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_tensorboard_runs), "__call__" + type(client.transport.update_tensorboard_run), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = tensorboard_service.ListTensorboardRunsResponse() + call.return_value = gca_tensorboard_run.TensorboardRun() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_tensorboard_runs(parent="parent_value",) + client.update_tensorboard_run( + tensorboard_run=gca_tensorboard_run.TensorboardRun(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].tensorboard_run + mock_val = gca_tensorboard_run.TensorboardRun(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val -def test_list_tensorboard_runs_flattened_error(): +def test_update_tensorboard_run_flattened_error(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -4201,40 +4671,50 @@ def test_list_tensorboard_runs_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_tensorboard_runs( - tensorboard_service.ListTensorboardRunsRequest(), parent="parent_value", + client.update_tensorboard_run( + tensorboard_service.UpdateTensorboardRunRequest(), + tensorboard_run=gca_tensorboard_run.TensorboardRun(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @pytest.mark.asyncio -async def test_list_tensorboard_runs_flattened_async(): +async def test_update_tensorboard_run_flattened_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_tensorboard_runs), "__call__" + type(client.transport.update_tensorboard_run), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = tensorboard_service.ListTensorboardRunsResponse() + call.return_value = gca_tensorboard_run.TensorboardRun() call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - tensorboard_service.ListTensorboardRunsResponse() + gca_tensorboard_run.TensorboardRun() ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_tensorboard_runs(parent="parent_value",) + response = await client.update_tensorboard_run( + tensorboard_run=gca_tensorboard_run.TensorboardRun(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].tensorboard_run + mock_val = gca_tensorboard_run.TensorboardRun(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val @pytest.mark.asyncio -async def test_list_tensorboard_runs_flattened_error_async(): +async def test_update_tensorboard_run_flattened_error_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -4242,242 +4722,76 @@ async def test_list_tensorboard_runs_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.list_tensorboard_runs( - tensorboard_service.ListTensorboardRunsRequest(), parent="parent_value", + await client.update_tensorboard_run( + tensorboard_service.UpdateTensorboardRunRequest(), + tensorboard_run=gca_tensorboard_run.TensorboardRun(name="name_value"), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) -def test_list_tensorboard_runs_pager(): - client = TensorboardServiceClient(credentials=ga_credentials.AnonymousCredentials,) +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.ListTensorboardRunsRequest, + dict, + ], +) +def test_list_tensorboard_runs(request_type, transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( type(client.transport.list_tensorboard_runs), "__call__" ) as call: - # Set the response to a series of pages. - call.side_effect = ( - tensorboard_service.ListTensorboardRunsResponse( - tensorboard_runs=[ - tensorboard_run.TensorboardRun(), - tensorboard_run.TensorboardRun(), - tensorboard_run.TensorboardRun(), - ], - next_page_token="abc", - ), - tensorboard_service.ListTensorboardRunsResponse( - tensorboard_runs=[], next_page_token="def", - ), - tensorboard_service.ListTensorboardRunsResponse( - tensorboard_runs=[tensorboard_run.TensorboardRun(),], - next_page_token="ghi", - ), - tensorboard_service.ListTensorboardRunsResponse( - tensorboard_runs=[ - tensorboard_run.TensorboardRun(), - tensorboard_run.TensorboardRun(), - ], - ), - RuntimeError, - ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + # Designate an appropriate return value for the call. + call.return_value = tensorboard_service.ListTensorboardRunsResponse( + next_page_token="next_page_token_value", ) - pager = client.list_tensorboard_runs(request={}) - - assert pager._metadata == metadata + response = client.list_tensorboard_runs(request) - results = [i for i in pager] - assert len(results) == 6 - assert all(isinstance(i, tensorboard_run.TensorboardRun) for i in results) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.ListTensorboardRunsRequest() + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListTensorboardRunsPager) + assert response.next_page_token == "next_page_token_value" -def test_list_tensorboard_runs_pages(): - client = TensorboardServiceClient(credentials=ga_credentials.AnonymousCredentials,) - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_tensorboard_runs), "__call__" - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - tensorboard_service.ListTensorboardRunsResponse( - tensorboard_runs=[ - tensorboard_run.TensorboardRun(), - tensorboard_run.TensorboardRun(), - tensorboard_run.TensorboardRun(), - ], - next_page_token="abc", - ), - tensorboard_service.ListTensorboardRunsResponse( - tensorboard_runs=[], next_page_token="def", - ), - tensorboard_service.ListTensorboardRunsResponse( - tensorboard_runs=[tensorboard_run.TensorboardRun(),], - next_page_token="ghi", - ), - tensorboard_service.ListTensorboardRunsResponse( - tensorboard_runs=[ - tensorboard_run.TensorboardRun(), - tensorboard_run.TensorboardRun(), - ], - ), - RuntimeError, - ) - pages = list(client.list_tensorboard_runs(request={}).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token - - -@pytest.mark.asyncio -async def test_list_tensorboard_runs_async_pager(): - client = TensorboardServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_tensorboard_runs), - "__call__", - new_callable=mock.AsyncMock, - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - tensorboard_service.ListTensorboardRunsResponse( - tensorboard_runs=[ - tensorboard_run.TensorboardRun(), - tensorboard_run.TensorboardRun(), - tensorboard_run.TensorboardRun(), - ], - next_page_token="abc", - ), - tensorboard_service.ListTensorboardRunsResponse( - tensorboard_runs=[], next_page_token="def", - ), - tensorboard_service.ListTensorboardRunsResponse( - tensorboard_runs=[tensorboard_run.TensorboardRun(),], - next_page_token="ghi", - ), - tensorboard_service.ListTensorboardRunsResponse( - tensorboard_runs=[ - tensorboard_run.TensorboardRun(), - tensorboard_run.TensorboardRun(), - ], - ), - RuntimeError, - ) - async_pager = await client.list_tensorboard_runs(request={},) - assert async_pager.next_page_token == "abc" - responses = [] - async for response in async_pager: - responses.append(response) - - assert len(responses) == 6 - assert all(isinstance(i, tensorboard_run.TensorboardRun) for i in responses) - - -@pytest.mark.asyncio -async def test_list_tensorboard_runs_async_pages(): - client = TensorboardServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_tensorboard_runs), - "__call__", - new_callable=mock.AsyncMock, - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - tensorboard_service.ListTensorboardRunsResponse( - tensorboard_runs=[ - tensorboard_run.TensorboardRun(), - tensorboard_run.TensorboardRun(), - tensorboard_run.TensorboardRun(), - ], - next_page_token="abc", - ), - tensorboard_service.ListTensorboardRunsResponse( - tensorboard_runs=[], next_page_token="def", - ), - tensorboard_service.ListTensorboardRunsResponse( - tensorboard_runs=[tensorboard_run.TensorboardRun(),], - next_page_token="ghi", - ), - tensorboard_service.ListTensorboardRunsResponse( - tensorboard_runs=[ - tensorboard_run.TensorboardRun(), - tensorboard_run.TensorboardRun(), - ], - ), - RuntimeError, - ) - pages = [] - async for page_ in (await client.list_tensorboard_runs(request={})).pages: - pages.append(page_) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token - - -def test_delete_tensorboard_run( - transport: str = "grpc", - request_type=tensorboard_service.DeleteTensorboardRunRequest, -): - client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_tensorboard_run), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.delete_tensorboard_run(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.DeleteTensorboardRunRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_delete_tensorboard_run_from_dict(): - test_delete_tensorboard_run(request_type=dict) - - -def test_delete_tensorboard_run_empty_call(): +def test_list_tensorboard_runs_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_tensorboard_run), "__call__" + type(client.transport.list_tensorboard_runs), "__call__" ) as call: - client.delete_tensorboard_run() + client.list_tensorboard_runs() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.DeleteTensorboardRunRequest() + assert args[0] == tensorboard_service.ListTensorboardRunsRequest() @pytest.mark.asyncio -async def test_delete_tensorboard_run_async( +async def test_list_tensorboard_runs_async( transport: str = "grpc_asyncio", - request_type=tensorboard_service.DeleteTensorboardRunRequest, + request_type=tensorboard_service.ListTensorboardRunsRequest, ): client = TensorboardServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4486,45 +4800,48 @@ async def test_delete_tensorboard_run_async( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_tensorboard_run), "__call__" + type(client.transport.list_tensorboard_runs), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") + tensorboard_service.ListTensorboardRunsResponse( + next_page_token="next_page_token_value", + ) ) - response = await client.delete_tensorboard_run(request) + response = await client.list_tensorboard_runs(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.DeleteTensorboardRunRequest() + assert args[0] == tensorboard_service.ListTensorboardRunsRequest() # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) + assert isinstance(response, pagers.ListTensorboardRunsAsyncPager) + assert response.next_page_token == "next_page_token_value" @pytest.mark.asyncio -async def test_delete_tensorboard_run_async_from_dict(): - await test_delete_tensorboard_run_async(request_type=dict) +async def test_list_tensorboard_runs_async_from_dict(): + await test_list_tensorboard_runs_async(request_type=dict) -def test_delete_tensorboard_run_field_headers(): +def test_list_tensorboard_runs_field_headers(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = tensorboard_service.DeleteTensorboardRunRequest() + request = tensorboard_service.ListTensorboardRunsRequest() - request.name = "name/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_tensorboard_run), "__call__" + type(client.transport.list_tensorboard_runs), "__call__" ) as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_tensorboard_run(request) + call.return_value = tensorboard_service.ListTensorboardRunsResponse() + client.list_tensorboard_runs(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -4533,29 +4850,32 @@ def test_delete_tensorboard_run_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_delete_tensorboard_run_field_headers_async(): +async def test_list_tensorboard_runs_field_headers_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = tensorboard_service.DeleteTensorboardRunRequest() + request = tensorboard_service.ListTensorboardRunsRequest() - request.name = "name/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_tensorboard_run), "__call__" + type(client.transport.list_tensorboard_runs), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/op") + tensorboard_service.ListTensorboardRunsResponse() ) - await client.delete_tensorboard_run(request) + await client.list_tensorboard_runs(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -4564,32 +4884,39 @@ async def test_delete_tensorboard_run_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] -def test_delete_tensorboard_run_flattened(): +def test_list_tensorboard_runs_flattened(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_tensorboard_run), "__call__" + type(client.transport.list_tensorboard_runs), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name="operations/op") + call.return_value = tensorboard_service.ListTensorboardRunsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_tensorboard_run(name="name_value",) + client.list_tensorboard_runs( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val -def test_delete_tensorboard_run_flattened_error(): +def test_list_tensorboard_runs_flattened_error(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -4597,40 +4924,45 @@ def test_delete_tensorboard_run_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.delete_tensorboard_run( - tensorboard_service.DeleteTensorboardRunRequest(), name="name_value", + client.list_tensorboard_runs( + tensorboard_service.ListTensorboardRunsRequest(), + parent="parent_value", ) @pytest.mark.asyncio -async def test_delete_tensorboard_run_flattened_async(): +async def test_list_tensorboard_runs_flattened_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_tensorboard_run), "__call__" + type(client.transport.list_tensorboard_runs), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name="operations/op") + call.return_value = tensorboard_service.ListTensorboardRunsResponse() call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") + tensorboard_service.ListTensorboardRunsResponse() ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_tensorboard_run(name="name_value",) + response = await client.list_tensorboard_runs( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio -async def test_delete_tensorboard_run_flattened_error_async(): +async def test_list_tensorboard_runs_flattened_error_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -4638,86 +4970,268 @@ async def test_delete_tensorboard_run_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.delete_tensorboard_run( - tensorboard_service.DeleteTensorboardRunRequest(), name="name_value", + await client.list_tensorboard_runs( + tensorboard_service.ListTensorboardRunsRequest(), + parent="parent_value", ) -def test_create_tensorboard_time_series( - transport: str = "grpc", - request_type=tensorboard_service.CreateTensorboardTimeSeriesRequest, -): +def test_list_tensorboard_runs_pager(transport_name: str = "grpc"): client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.create_tensorboard_time_series), "__call__" + type(client.transport.list_tensorboard_runs), "__call__" ) as call: - # Designate an appropriate return value for the call. - call.return_value = gca_tensorboard_time_series.TensorboardTimeSeries( - name="name_value", - display_name="display_name_value", - description="description_value", - value_type=gca_tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR, - etag="etag_value", - plugin_name="plugin_name_value", - plugin_data=b"plugin_data_blob", - ) - response = client.create_tensorboard_time_series(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.CreateTensorboardTimeSeriesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, gca_tensorboard_time_series.TensorboardTimeSeries) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.description == "description_value" - assert ( - response.value_type - == gca_tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR + # Set the response to a series of pages. + call.side_effect = ( + tensorboard_service.ListTensorboardRunsResponse( + tensorboard_runs=[ + tensorboard_run.TensorboardRun(), + tensorboard_run.TensorboardRun(), + tensorboard_run.TensorboardRun(), + ], + next_page_token="abc", + ), + tensorboard_service.ListTensorboardRunsResponse( + tensorboard_runs=[], + next_page_token="def", + ), + tensorboard_service.ListTensorboardRunsResponse( + tensorboard_runs=[ + tensorboard_run.TensorboardRun(), + ], + next_page_token="ghi", + ), + tensorboard_service.ListTensorboardRunsResponse( + tensorboard_runs=[ + tensorboard_run.TensorboardRun(), + tensorboard_run.TensorboardRun(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_tensorboard_runs(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, tensorboard_run.TensorboardRun) for i in results) + + +def test_list_tensorboard_runs_pages(transport_name: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) - assert response.etag == "etag_value" - assert response.plugin_name == "plugin_name_value" - assert response.plugin_data == b"plugin_data_blob" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_runs), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + tensorboard_service.ListTensorboardRunsResponse( + tensorboard_runs=[ + tensorboard_run.TensorboardRun(), + tensorboard_run.TensorboardRun(), + tensorboard_run.TensorboardRun(), + ], + next_page_token="abc", + ), + tensorboard_service.ListTensorboardRunsResponse( + tensorboard_runs=[], + next_page_token="def", + ), + tensorboard_service.ListTensorboardRunsResponse( + tensorboard_runs=[ + tensorboard_run.TensorboardRun(), + ], + next_page_token="ghi", + ), + tensorboard_service.ListTensorboardRunsResponse( + tensorboard_runs=[ + tensorboard_run.TensorboardRun(), + tensorboard_run.TensorboardRun(), + ], + ), + RuntimeError, + ) + pages = list(client.list_tensorboard_runs(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token -def test_create_tensorboard_time_series_from_dict(): - test_create_tensorboard_time_series(request_type=dict) +@pytest.mark.asyncio +async def test_list_tensorboard_runs_async_pager(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_runs), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + tensorboard_service.ListTensorboardRunsResponse( + tensorboard_runs=[ + tensorboard_run.TensorboardRun(), + tensorboard_run.TensorboardRun(), + tensorboard_run.TensorboardRun(), + ], + next_page_token="abc", + ), + tensorboard_service.ListTensorboardRunsResponse( + tensorboard_runs=[], + next_page_token="def", + ), + tensorboard_service.ListTensorboardRunsResponse( + tensorboard_runs=[ + tensorboard_run.TensorboardRun(), + ], + next_page_token="ghi", + ), + tensorboard_service.ListTensorboardRunsResponse( + tensorboard_runs=[ + tensorboard_run.TensorboardRun(), + tensorboard_run.TensorboardRun(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_tensorboard_runs( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) -def test_create_tensorboard_time_series_empty_call(): + assert len(responses) == 6 + assert all(isinstance(i, tensorboard_run.TensorboardRun) for i in responses) + + +@pytest.mark.asyncio +async def test_list_tensorboard_runs_async_pages(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_runs), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + tensorboard_service.ListTensorboardRunsResponse( + tensorboard_runs=[ + tensorboard_run.TensorboardRun(), + tensorboard_run.TensorboardRun(), + tensorboard_run.TensorboardRun(), + ], + next_page_token="abc", + ), + tensorboard_service.ListTensorboardRunsResponse( + tensorboard_runs=[], + next_page_token="def", + ), + tensorboard_service.ListTensorboardRunsResponse( + tensorboard_runs=[ + tensorboard_run.TensorboardRun(), + ], + next_page_token="ghi", + ), + tensorboard_service.ListTensorboardRunsResponse( + tensorboard_runs=[ + tensorboard_run.TensorboardRun(), + tensorboard_run.TensorboardRun(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.list_tensorboard_runs(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.DeleteTensorboardRunRequest, + dict, + ], +) +def test_delete_tensorboard_run(request_type, transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_tensorboard_run), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.delete_tensorboard_run(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.DeleteTensorboardRunRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_delete_tensorboard_run_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.create_tensorboard_time_series), "__call__" + type(client.transport.delete_tensorboard_run), "__call__" ) as call: - client.create_tensorboard_time_series() + client.delete_tensorboard_run() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.CreateTensorboardTimeSeriesRequest() + assert args[0] == tensorboard_service.DeleteTensorboardRunRequest() @pytest.mark.asyncio -async def test_create_tensorboard_time_series_async( +async def test_delete_tensorboard_run_async( transport: str = "grpc_asyncio", - request_type=tensorboard_service.CreateTensorboardTimeSeriesRequest, + request_type=tensorboard_service.DeleteTensorboardRunRequest, ): client = TensorboardServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4726,63 +5240,45 @@ async def test_create_tensorboard_time_series_async( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.create_tensorboard_time_series), "__call__" + type(client.transport.delete_tensorboard_run), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gca_tensorboard_time_series.TensorboardTimeSeries( - name="name_value", - display_name="display_name_value", - description="description_value", - value_type=gca_tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR, - etag="etag_value", - plugin_name="plugin_name_value", - plugin_data=b"plugin_data_blob", - ) + operations_pb2.Operation(name="operations/spam") ) - response = await client.create_tensorboard_time_series(request) + response = await client.delete_tensorboard_run(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.CreateTensorboardTimeSeriesRequest() + assert args[0] == tensorboard_service.DeleteTensorboardRunRequest() # Establish that the response is the type that we expect. - assert isinstance(response, gca_tensorboard_time_series.TensorboardTimeSeries) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.description == "description_value" - assert ( - response.value_type - == gca_tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR - ) - assert response.etag == "etag_value" - assert response.plugin_name == "plugin_name_value" - assert response.plugin_data == b"plugin_data_blob" + assert isinstance(response, future.Future) @pytest.mark.asyncio -async def test_create_tensorboard_time_series_async_from_dict(): - await test_create_tensorboard_time_series_async(request_type=dict) +async def test_delete_tensorboard_run_async_from_dict(): + await test_delete_tensorboard_run_async(request_type=dict) -def test_create_tensorboard_time_series_field_headers(): +def test_delete_tensorboard_run_field_headers(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = tensorboard_service.CreateTensorboardTimeSeriesRequest() + request = tensorboard_service.DeleteTensorboardRunRequest() - request.parent = "parent/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.create_tensorboard_time_series), "__call__" + type(client.transport.delete_tensorboard_run), "__call__" ) as call: - call.return_value = gca_tensorboard_time_series.TensorboardTimeSeries() - client.create_tensorboard_time_series(request) + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_tensorboard_run(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -4791,29 +5287,32 @@ def test_create_tensorboard_time_series_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_create_tensorboard_time_series_field_headers_async(): +async def test_delete_tensorboard_run_field_headers_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = tensorboard_service.CreateTensorboardTimeSeriesRequest() + request = tensorboard_service.DeleteTensorboardRunRequest() - request.parent = "parent/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.create_tensorboard_time_series), "__call__" + type(client.transport.delete_tensorboard_run), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gca_tensorboard_time_series.TensorboardTimeSeries() + operations_pb2.Operation(name="operations/op") ) - await client.create_tensorboard_time_series(request) + await client.delete_tensorboard_run(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -4822,42 +5321,39 @@ async def test_create_tensorboard_time_series_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] -def test_create_tensorboard_time_series_flattened(): +def test_delete_tensorboard_run_flattened(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.create_tensorboard_time_series), "__call__" + type(client.transport.delete_tensorboard_run), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = gca_tensorboard_time_series.TensorboardTimeSeries() + call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.create_tensorboard_time_series( - parent="parent_value", - tensorboard_time_series=gca_tensorboard_time_series.TensorboardTimeSeries( - name="name_value" - ), + client.delete_tensorboard_run( + name="name_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[ - 0 - ].tensorboard_time_series == gca_tensorboard_time_series.TensorboardTimeSeries( - name="name_value" - ) + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val -def test_create_tensorboard_time_series_flattened_error(): +def test_delete_tensorboard_run_flattened_error(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -4865,54 +5361,45 @@ def test_create_tensorboard_time_series_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.create_tensorboard_time_series( - tensorboard_service.CreateTensorboardTimeSeriesRequest(), - parent="parent_value", - tensorboard_time_series=gca_tensorboard_time_series.TensorboardTimeSeries( - name="name_value" - ), + client.delete_tensorboard_run( + tensorboard_service.DeleteTensorboardRunRequest(), + name="name_value", ) @pytest.mark.asyncio -async def test_create_tensorboard_time_series_flattened_async(): +async def test_delete_tensorboard_run_flattened_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.create_tensorboard_time_series), "__call__" + type(client.transport.delete_tensorboard_run), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = gca_tensorboard_time_series.TensorboardTimeSeries() + call.return_value = operations_pb2.Operation(name="operations/op") call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - gca_tensorboard_time_series.TensorboardTimeSeries() + operations_pb2.Operation(name="operations/spam") ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.create_tensorboard_time_series( - parent="parent_value", - tensorboard_time_series=gca_tensorboard_time_series.TensorboardTimeSeries( - name="name_value" - ), + response = await client.delete_tensorboard_run( + name="name_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[ - 0 - ].tensorboard_time_series == gca_tensorboard_time_series.TensorboardTimeSeries( - name="name_value" - ) + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio -async def test_create_tensorboard_time_series_flattened_error_async(): +async def test_delete_tensorboard_run_flattened_error_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -4920,21 +5407,23 @@ async def test_create_tensorboard_time_series_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.create_tensorboard_time_series( - tensorboard_service.CreateTensorboardTimeSeriesRequest(), - parent="parent_value", - tensorboard_time_series=gca_tensorboard_time_series.TensorboardTimeSeries( - name="name_value" - ), + await client.delete_tensorboard_run( + tensorboard_service.DeleteTensorboardRunRequest(), + name="name_value", ) -def test_get_tensorboard_time_series( - transport: str = "grpc", - request_type=tensorboard_service.GetTensorboardTimeSeriesRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.BatchCreateTensorboardTimeSeriesRequest, + dict, + ], +) +def test_batch_create_tensorboard_time_series(request_type, transport: str = "grpc"): client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -4943,67 +5432,51 @@ def test_get_tensorboard_time_series( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_tensorboard_time_series), "__call__" + type(client.transport.batch_create_tensorboard_time_series), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = tensorboard_time_series.TensorboardTimeSeries( - name="name_value", - display_name="display_name_value", - description="description_value", - value_type=tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR, - etag="etag_value", - plugin_name="plugin_name_value", - plugin_data=b"plugin_data_blob", + call.return_value = ( + tensorboard_service.BatchCreateTensorboardTimeSeriesResponse() ) - response = client.get_tensorboard_time_series(request) + response = client.batch_create_tensorboard_time_series(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.GetTensorboardTimeSeriesRequest() + assert args[0] == tensorboard_service.BatchCreateTensorboardTimeSeriesRequest() # Establish that the response is the type that we expect. - assert isinstance(response, tensorboard_time_series.TensorboardTimeSeries) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.description == "description_value" - assert ( - response.value_type - == tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR + assert isinstance( + response, tensorboard_service.BatchCreateTensorboardTimeSeriesResponse ) - assert response.etag == "etag_value" - assert response.plugin_name == "plugin_name_value" - assert response.plugin_data == b"plugin_data_blob" -def test_get_tensorboard_time_series_from_dict(): - test_get_tensorboard_time_series(request_type=dict) - - -def test_get_tensorboard_time_series_empty_call(): +def test_batch_create_tensorboard_time_series_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_tensorboard_time_series), "__call__" + type(client.transport.batch_create_tensorboard_time_series), "__call__" ) as call: - client.get_tensorboard_time_series() + client.batch_create_tensorboard_time_series() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.GetTensorboardTimeSeriesRequest() + assert args[0] == tensorboard_service.BatchCreateTensorboardTimeSeriesRequest() @pytest.mark.asyncio -async def test_get_tensorboard_time_series_async( +async def test_batch_create_tensorboard_time_series_async( transport: str = "grpc_asyncio", - request_type=tensorboard_service.GetTensorboardTimeSeriesRequest, + request_type=tensorboard_service.BatchCreateTensorboardTimeSeriesRequest, ): client = TensorboardServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5012,63 +5485,49 @@ async def test_get_tensorboard_time_series_async( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_tensorboard_time_series), "__call__" + type(client.transport.batch_create_tensorboard_time_series), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - tensorboard_time_series.TensorboardTimeSeries( - name="name_value", - display_name="display_name_value", - description="description_value", - value_type=tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR, - etag="etag_value", - plugin_name="plugin_name_value", - plugin_data=b"plugin_data_blob", - ) + tensorboard_service.BatchCreateTensorboardTimeSeriesResponse() ) - response = await client.get_tensorboard_time_series(request) + response = await client.batch_create_tensorboard_time_series(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.GetTensorboardTimeSeriesRequest() + assert args[0] == tensorboard_service.BatchCreateTensorboardTimeSeriesRequest() # Establish that the response is the type that we expect. - assert isinstance(response, tensorboard_time_series.TensorboardTimeSeries) - assert response.name == "name_value" - assert response.display_name == "display_name_value" - assert response.description == "description_value" - assert ( - response.value_type - == tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR + assert isinstance( + response, tensorboard_service.BatchCreateTensorboardTimeSeriesResponse ) - assert response.etag == "etag_value" - assert response.plugin_name == "plugin_name_value" - assert response.plugin_data == b"plugin_data_blob" @pytest.mark.asyncio -async def test_get_tensorboard_time_series_async_from_dict(): - await test_get_tensorboard_time_series_async(request_type=dict) +async def test_batch_create_tensorboard_time_series_async_from_dict(): + await test_batch_create_tensorboard_time_series_async(request_type=dict) -def test_get_tensorboard_time_series_field_headers(): +def test_batch_create_tensorboard_time_series_field_headers(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = tensorboard_service.GetTensorboardTimeSeriesRequest() + request = tensorboard_service.BatchCreateTensorboardTimeSeriesRequest() - request.name = "name/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_tensorboard_time_series), "__call__" + type(client.transport.batch_create_tensorboard_time_series), "__call__" ) as call: - call.return_value = tensorboard_time_series.TensorboardTimeSeries() - client.get_tensorboard_time_series(request) + call.return_value = ( + tensorboard_service.BatchCreateTensorboardTimeSeriesResponse() + ) + client.batch_create_tensorboard_time_series(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -5077,29 +5536,32 @@ def test_get_tensorboard_time_series_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_get_tensorboard_time_series_field_headers_async(): +async def test_batch_create_tensorboard_time_series_field_headers_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = tensorboard_service.GetTensorboardTimeSeriesRequest() + request = tensorboard_service.BatchCreateTensorboardTimeSeriesRequest() - request.name = "name/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_tensorboard_time_series), "__call__" + type(client.transport.batch_create_tensorboard_time_series), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - tensorboard_time_series.TensorboardTimeSeries() + tensorboard_service.BatchCreateTensorboardTimeSeriesResponse() ) - await client.get_tensorboard_time_series(request) + await client.batch_create_tensorboard_time_series(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -5108,32 +5570,53 @@ async def test_get_tensorboard_time_series_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] -def test_get_tensorboard_time_series_flattened(): +def test_batch_create_tensorboard_time_series_flattened(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_tensorboard_time_series), "__call__" + type(client.transport.batch_create_tensorboard_time_series), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = tensorboard_time_series.TensorboardTimeSeries() + call.return_value = ( + tensorboard_service.BatchCreateTensorboardTimeSeriesResponse() + ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_tensorboard_time_series(name="name_value",) + client.batch_create_tensorboard_time_series( + parent="parent_value", + requests=[ + tensorboard_service.CreateTensorboardTimeSeriesRequest( + parent="parent_value" + ) + ], + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].requests + mock_val = [ + tensorboard_service.CreateTensorboardTimeSeriesRequest( + parent="parent_value" + ) + ] + assert arg == mock_val -def test_get_tensorboard_time_series_flattened_error(): +def test_batch_create_tensorboard_time_series_flattened_error(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -5141,40 +5624,64 @@ def test_get_tensorboard_time_series_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.get_tensorboard_time_series( - tensorboard_service.GetTensorboardTimeSeriesRequest(), name="name_value", + client.batch_create_tensorboard_time_series( + tensorboard_service.BatchCreateTensorboardTimeSeriesRequest(), + parent="parent_value", + requests=[ + tensorboard_service.CreateTensorboardTimeSeriesRequest( + parent="parent_value" + ) + ], ) @pytest.mark.asyncio -async def test_get_tensorboard_time_series_flattened_async(): +async def test_batch_create_tensorboard_time_series_flattened_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.get_tensorboard_time_series), "__call__" + type(client.transport.batch_create_tensorboard_time_series), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = tensorboard_time_series.TensorboardTimeSeries() + call.return_value = ( + tensorboard_service.BatchCreateTensorboardTimeSeriesResponse() + ) call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - tensorboard_time_series.TensorboardTimeSeries() + tensorboard_service.BatchCreateTensorboardTimeSeriesResponse() ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_tensorboard_time_series(name="name_value",) + response = await client.batch_create_tensorboard_time_series( + parent="parent_value", + requests=[ + tensorboard_service.CreateTensorboardTimeSeriesRequest( + parent="parent_value" + ) + ], + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].requests + mock_val = [ + tensorboard_service.CreateTensorboardTimeSeriesRequest( + parent="parent_value" + ) + ] + assert arg == mock_val @pytest.mark.asyncio -async def test_get_tensorboard_time_series_flattened_error_async(): +async def test_batch_create_tensorboard_time_series_flattened_error_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -5182,17 +5689,28 @@ async def test_get_tensorboard_time_series_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.get_tensorboard_time_series( - tensorboard_service.GetTensorboardTimeSeriesRequest(), name="name_value", + await client.batch_create_tensorboard_time_series( + tensorboard_service.BatchCreateTensorboardTimeSeriesRequest(), + parent="parent_value", + requests=[ + tensorboard_service.CreateTensorboardTimeSeriesRequest( + parent="parent_value" + ) + ], ) -def test_update_tensorboard_time_series( - transport: str = "grpc", - request_type=tensorboard_service.UpdateTensorboardTimeSeriesRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.CreateTensorboardTimeSeriesRequest, + dict, + ], +) +def test_create_tensorboard_time_series(request_type, transport: str = "grpc"): client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5201,7 +5719,7 @@ def test_update_tensorboard_time_series( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_tensorboard_time_series), "__call__" + type(client.transport.create_tensorboard_time_series), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gca_tensorboard_time_series.TensorboardTimeSeries( @@ -5213,12 +5731,12 @@ def test_update_tensorboard_time_series( plugin_name="plugin_name_value", plugin_data=b"plugin_data_blob", ) - response = client.update_tensorboard_time_series(request) + response = client.create_tensorboard_time_series(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.UpdateTensorboardTimeSeriesRequest() + assert args[0] == tensorboard_service.CreateTensorboardTimeSeriesRequest() # Establish that the response is the type that we expect. assert isinstance(response, gca_tensorboard_time_series.TensorboardTimeSeries) @@ -5234,34 +5752,32 @@ def test_update_tensorboard_time_series( assert response.plugin_data == b"plugin_data_blob" -def test_update_tensorboard_time_series_from_dict(): - test_update_tensorboard_time_series(request_type=dict) - - -def test_update_tensorboard_time_series_empty_call(): +def test_create_tensorboard_time_series_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_tensorboard_time_series), "__call__" + type(client.transport.create_tensorboard_time_series), "__call__" ) as call: - client.update_tensorboard_time_series() + client.create_tensorboard_time_series() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.UpdateTensorboardTimeSeriesRequest() + assert args[0] == tensorboard_service.CreateTensorboardTimeSeriesRequest() @pytest.mark.asyncio -async def test_update_tensorboard_time_series_async( +async def test_create_tensorboard_time_series_async( transport: str = "grpc_asyncio", - request_type=tensorboard_service.UpdateTensorboardTimeSeriesRequest, + request_type=tensorboard_service.CreateTensorboardTimeSeriesRequest, ): client = TensorboardServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5270,7 +5786,7 @@ async def test_update_tensorboard_time_series_async( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_tensorboard_time_series), "__call__" + type(client.transport.create_tensorboard_time_series), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -5284,12 +5800,12 @@ async def test_update_tensorboard_time_series_async( plugin_data=b"plugin_data_blob", ) ) - response = await client.update_tensorboard_time_series(request) + response = await client.create_tensorboard_time_series(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.UpdateTensorboardTimeSeriesRequest() + assert args[0] == tensorboard_service.CreateTensorboardTimeSeriesRequest() # Establish that the response is the type that we expect. assert isinstance(response, gca_tensorboard_time_series.TensorboardTimeSeries) @@ -5306,27 +5822,27 @@ async def test_update_tensorboard_time_series_async( @pytest.mark.asyncio -async def test_update_tensorboard_time_series_async_from_dict(): - await test_update_tensorboard_time_series_async(request_type=dict) +async def test_create_tensorboard_time_series_async_from_dict(): + await test_create_tensorboard_time_series_async(request_type=dict) -def test_update_tensorboard_time_series_field_headers(): +def test_create_tensorboard_time_series_field_headers(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = tensorboard_service.UpdateTensorboardTimeSeriesRequest() + request = tensorboard_service.CreateTensorboardTimeSeriesRequest() - request.tensorboard_time_series.name = "tensorboard_time_series.name/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_tensorboard_time_series), "__call__" + type(client.transport.create_tensorboard_time_series), "__call__" ) as call: call.return_value = gca_tensorboard_time_series.TensorboardTimeSeries() - client.update_tensorboard_time_series(request) + client.create_tensorboard_time_series(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -5337,30 +5853,30 @@ def test_update_tensorboard_time_series_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "tensorboard_time_series.name=tensorboard_time_series.name/value", + "parent=parent_value", ) in kw["metadata"] @pytest.mark.asyncio -async def test_update_tensorboard_time_series_field_headers_async(): +async def test_create_tensorboard_time_series_field_headers_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = tensorboard_service.UpdateTensorboardTimeSeriesRequest() + request = tensorboard_service.CreateTensorboardTimeSeriesRequest() - request.tensorboard_time_series.name = "tensorboard_time_series.name/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_tensorboard_time_series), "__call__" + type(client.transport.create_tensorboard_time_series), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gca_tensorboard_time_series.TensorboardTimeSeries() ) - await client.update_tensorboard_time_series(request) + await client.create_tensorboard_time_series(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -5371,43 +5887,43 @@ async def test_update_tensorboard_time_series_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "tensorboard_time_series.name=tensorboard_time_series.name/value", + "parent=parent_value", ) in kw["metadata"] -def test_update_tensorboard_time_series_flattened(): +def test_create_tensorboard_time_series_flattened(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_tensorboard_time_series), "__call__" + type(client.transport.create_tensorboard_time_series), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gca_tensorboard_time_series.TensorboardTimeSeries() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.update_tensorboard_time_series( + client.create_tensorboard_time_series( + parent="parent_value", tensorboard_time_series=gca_tensorboard_time_series.TensorboardTimeSeries( name="name_value" ), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[ - 0 - ].tensorboard_time_series == gca_tensorboard_time_series.TensorboardTimeSeries( - name="name_value" - ) - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].tensorboard_time_series + mock_val = gca_tensorboard_time_series.TensorboardTimeSeries(name="name_value") + assert arg == mock_val -def test_update_tensorboard_time_series_flattened_error(): +def test_create_tensorboard_time_series_flattened_error(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -5415,24 +5931,24 @@ def test_update_tensorboard_time_series_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.update_tensorboard_time_series( - tensorboard_service.UpdateTensorboardTimeSeriesRequest(), - tensorboard_time_series=gca_tensorboard_time_series.TensorboardTimeSeries( - name="name_value" + client.create_tensorboard_time_series( + tensorboard_service.CreateTensorboardTimeSeriesRequest(), + parent="parent_value", + tensorboard_time_series=gca_tensorboard_time_series.TensorboardTimeSeries( + name="name_value" ), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @pytest.mark.asyncio -async def test_update_tensorboard_time_series_flattened_async(): +async def test_create_tensorboard_time_series_flattened_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.update_tensorboard_time_series), "__call__" + type(client.transport.create_tensorboard_time_series), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = gca_tensorboard_time_series.TensorboardTimeSeries() @@ -5442,27 +5958,27 @@ async def test_update_tensorboard_time_series_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.update_tensorboard_time_series( + response = await client.create_tensorboard_time_series( + parent="parent_value", tensorboard_time_series=gca_tensorboard_time_series.TensorboardTimeSeries( name="name_value" ), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[ - 0 - ].tensorboard_time_series == gca_tensorboard_time_series.TensorboardTimeSeries( - name="name_value" - ) - assert args[0].update_mask == field_mask_pb2.FieldMask(paths=["paths_value"]) + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].tensorboard_time_series + mock_val = gca_tensorboard_time_series.TensorboardTimeSeries(name="name_value") + assert arg == mock_val @pytest.mark.asyncio -async def test_update_tensorboard_time_series_flattened_error_async(): +async def test_create_tensorboard_time_series_flattened_error_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -5470,21 +5986,26 @@ async def test_update_tensorboard_time_series_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.update_tensorboard_time_series( - tensorboard_service.UpdateTensorboardTimeSeriesRequest(), + await client.create_tensorboard_time_series( + tensorboard_service.CreateTensorboardTimeSeriesRequest(), + parent="parent_value", tensorboard_time_series=gca_tensorboard_time_series.TensorboardTimeSeries( name="name_value" ), - update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) -def test_list_tensorboard_time_series( - transport: str = "grpc", - request_type=tensorboard_service.ListTensorboardTimeSeriesRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.GetTensorboardTimeSeriesRequest, + dict, + ], +) +def test_get_tensorboard_time_series(request_type, transport: str = "grpc"): client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5493,52 +6014,65 @@ def test_list_tensorboard_time_series( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_tensorboard_time_series), "__call__" + type(client.transport.get_tensorboard_time_series), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = tensorboard_service.ListTensorboardTimeSeriesResponse( - next_page_token="next_page_token_value", + call.return_value = tensorboard_time_series.TensorboardTimeSeries( + name="name_value", + display_name="display_name_value", + description="description_value", + value_type=tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR, + etag="etag_value", + plugin_name="plugin_name_value", + plugin_data=b"plugin_data_blob", ) - response = client.list_tensorboard_time_series(request) + response = client.get_tensorboard_time_series(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.ListTensorboardTimeSeriesRequest() + assert args[0] == tensorboard_service.GetTensorboardTimeSeriesRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListTensorboardTimeSeriesPager) - assert response.next_page_token == "next_page_token_value" - - -def test_list_tensorboard_time_series_from_dict(): - test_list_tensorboard_time_series(request_type=dict) + assert isinstance(response, tensorboard_time_series.TensorboardTimeSeries) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert ( + response.value_type + == tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR + ) + assert response.etag == "etag_value" + assert response.plugin_name == "plugin_name_value" + assert response.plugin_data == b"plugin_data_blob" -def test_list_tensorboard_time_series_empty_call(): +def test_get_tensorboard_time_series_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_tensorboard_time_series), "__call__" + type(client.transport.get_tensorboard_time_series), "__call__" ) as call: - client.list_tensorboard_time_series() + client.get_tensorboard_time_series() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.ListTensorboardTimeSeriesRequest() + assert args[0] == tensorboard_service.GetTensorboardTimeSeriesRequest() @pytest.mark.asyncio -async def test_list_tensorboard_time_series_async( +async def test_get_tensorboard_time_series_async( transport: str = "grpc_asyncio", - request_type=tensorboard_service.ListTensorboardTimeSeriesRequest, + request_type=tensorboard_service.GetTensorboardTimeSeriesRequest, ): client = TensorboardServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5547,48 +6081,63 @@ async def test_list_tensorboard_time_series_async( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_tensorboard_time_series), "__call__" + type(client.transport.get_tensorboard_time_series), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - tensorboard_service.ListTensorboardTimeSeriesResponse( - next_page_token="next_page_token_value", + tensorboard_time_series.TensorboardTimeSeries( + name="name_value", + display_name="display_name_value", + description="description_value", + value_type=tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR, + etag="etag_value", + plugin_name="plugin_name_value", + plugin_data=b"plugin_data_blob", ) ) - response = await client.list_tensorboard_time_series(request) + response = await client.get_tensorboard_time_series(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.ListTensorboardTimeSeriesRequest() + assert args[0] == tensorboard_service.GetTensorboardTimeSeriesRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ListTensorboardTimeSeriesAsyncPager) - assert response.next_page_token == "next_page_token_value" + assert isinstance(response, tensorboard_time_series.TensorboardTimeSeries) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert ( + response.value_type + == tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR + ) + assert response.etag == "etag_value" + assert response.plugin_name == "plugin_name_value" + assert response.plugin_data == b"plugin_data_blob" @pytest.mark.asyncio -async def test_list_tensorboard_time_series_async_from_dict(): - await test_list_tensorboard_time_series_async(request_type=dict) +async def test_get_tensorboard_time_series_async_from_dict(): + await test_get_tensorboard_time_series_async(request_type=dict) -def test_list_tensorboard_time_series_field_headers(): +def test_get_tensorboard_time_series_field_headers(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = tensorboard_service.ListTensorboardTimeSeriesRequest() + request = tensorboard_service.GetTensorboardTimeSeriesRequest() - request.parent = "parent/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_tensorboard_time_series), "__call__" + type(client.transport.get_tensorboard_time_series), "__call__" ) as call: - call.return_value = tensorboard_service.ListTensorboardTimeSeriesResponse() - client.list_tensorboard_time_series(request) + call.return_value = tensorboard_time_series.TensorboardTimeSeries() + client.get_tensorboard_time_series(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -5597,29 +6146,32 @@ def test_list_tensorboard_time_series_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_list_tensorboard_time_series_field_headers_async(): +async def test_get_tensorboard_time_series_field_headers_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = tensorboard_service.ListTensorboardTimeSeriesRequest() + request = tensorboard_service.GetTensorboardTimeSeriesRequest() - request.parent = "parent/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_tensorboard_time_series), "__call__" + type(client.transport.get_tensorboard_time_series), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - tensorboard_service.ListTensorboardTimeSeriesResponse() + tensorboard_time_series.TensorboardTimeSeries() ) - await client.list_tensorboard_time_series(request) + await client.get_tensorboard_time_series(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -5628,32 +6180,39 @@ async def test_list_tensorboard_time_series_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] -def test_list_tensorboard_time_series_flattened(): +def test_get_tensorboard_time_series_flattened(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_tensorboard_time_series), "__call__" + type(client.transport.get_tensorboard_time_series), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = tensorboard_service.ListTensorboardTimeSeriesResponse() + call.return_value = tensorboard_time_series.TensorboardTimeSeries() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_tensorboard_time_series(parent="parent_value",) + client.get_tensorboard_time_series( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val -def test_list_tensorboard_time_series_flattened_error(): +def test_get_tensorboard_time_series_flattened_error(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -5661,41 +6220,45 @@ def test_list_tensorboard_time_series_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.list_tensorboard_time_series( - tensorboard_service.ListTensorboardTimeSeriesRequest(), - parent="parent_value", + client.get_tensorboard_time_series( + tensorboard_service.GetTensorboardTimeSeriesRequest(), + name="name_value", ) @pytest.mark.asyncio -async def test_list_tensorboard_time_series_flattened_async(): +async def test_get_tensorboard_time_series_flattened_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_tensorboard_time_series), "__call__" + type(client.transport.get_tensorboard_time_series), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = tensorboard_service.ListTensorboardTimeSeriesResponse() + call.return_value = tensorboard_time_series.TensorboardTimeSeries() call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - tensorboard_service.ListTensorboardTimeSeriesResponse() + tensorboard_time_series.TensorboardTimeSeries() ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_tensorboard_time_series(parent="parent_value",) + response = await client.get_tensorboard_time_series( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio -async def test_list_tensorboard_time_series_flattened_error_async(): +async def test_get_tensorboard_time_series_flattened_error_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -5703,259 +6266,90 @@ async def test_list_tensorboard_time_series_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.list_tensorboard_time_series( - tensorboard_service.ListTensorboardTimeSeriesRequest(), - parent="parent_value", + await client.get_tensorboard_time_series( + tensorboard_service.GetTensorboardTimeSeriesRequest(), + name="name_value", ) -def test_list_tensorboard_time_series_pager(): - client = TensorboardServiceClient(credentials=ga_credentials.AnonymousCredentials,) +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.UpdateTensorboardTimeSeriesRequest, + dict, + ], +) +def test_update_tensorboard_time_series(request_type, transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_tensorboard_time_series), "__call__" + type(client.transport.update_tensorboard_time_series), "__call__" ) as call: - # Set the response to a series of pages. - call.side_effect = ( - tensorboard_service.ListTensorboardTimeSeriesResponse( - tensorboard_time_series=[ - tensorboard_time_series.TensorboardTimeSeries(), - tensorboard_time_series.TensorboardTimeSeries(), - tensorboard_time_series.TensorboardTimeSeries(), - ], - next_page_token="abc", - ), - tensorboard_service.ListTensorboardTimeSeriesResponse( - tensorboard_time_series=[], next_page_token="def", - ), - tensorboard_service.ListTensorboardTimeSeriesResponse( - tensorboard_time_series=[ - tensorboard_time_series.TensorboardTimeSeries(), - ], - next_page_token="ghi", - ), - tensorboard_service.ListTensorboardTimeSeriesResponse( - tensorboard_time_series=[ - tensorboard_time_series.TensorboardTimeSeries(), - tensorboard_time_series.TensorboardTimeSeries(), - ], - ), - RuntimeError, - ) - - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + # Designate an appropriate return value for the call. + call.return_value = gca_tensorboard_time_series.TensorboardTimeSeries( + name="name_value", + display_name="display_name_value", + description="description_value", + value_type=gca_tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR, + etag="etag_value", + plugin_name="plugin_name_value", + plugin_data=b"plugin_data_blob", ) - pager = client.list_tensorboard_time_series(request={}) + response = client.update_tensorboard_time_series(request) - assert pager._metadata == metadata + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.UpdateTensorboardTimeSeriesRequest() - results = [i for i in pager] - assert len(results) == 6 - assert all( - isinstance(i, tensorboard_time_series.TensorboardTimeSeries) - for i in results - ) + # Establish that the response is the type that we expect. + assert isinstance(response, gca_tensorboard_time_series.TensorboardTimeSeries) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert ( + response.value_type + == gca_tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR + ) + assert response.etag == "etag_value" + assert response.plugin_name == "plugin_name_value" + assert response.plugin_data == b"plugin_data_blob" -def test_list_tensorboard_time_series_pages(): - client = TensorboardServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_update_tensorboard_time_series_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.list_tensorboard_time_series), "__call__" + type(client.transport.update_tensorboard_time_series), "__call__" ) as call: - # Set the response to a series of pages. - call.side_effect = ( - tensorboard_service.ListTensorboardTimeSeriesResponse( - tensorboard_time_series=[ - tensorboard_time_series.TensorboardTimeSeries(), - tensorboard_time_series.TensorboardTimeSeries(), - tensorboard_time_series.TensorboardTimeSeries(), - ], - next_page_token="abc", - ), - tensorboard_service.ListTensorboardTimeSeriesResponse( - tensorboard_time_series=[], next_page_token="def", - ), - tensorboard_service.ListTensorboardTimeSeriesResponse( - tensorboard_time_series=[ - tensorboard_time_series.TensorboardTimeSeries(), - ], - next_page_token="ghi", - ), - tensorboard_service.ListTensorboardTimeSeriesResponse( - tensorboard_time_series=[ - tensorboard_time_series.TensorboardTimeSeries(), - tensorboard_time_series.TensorboardTimeSeries(), - ], - ), - RuntimeError, - ) - pages = list(client.list_tensorboard_time_series(request={}).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token - - -@pytest.mark.asyncio -async def test_list_tensorboard_time_series_async_pager(): - client = TensorboardServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_tensorboard_time_series), - "__call__", - new_callable=mock.AsyncMock, - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - tensorboard_service.ListTensorboardTimeSeriesResponse( - tensorboard_time_series=[ - tensorboard_time_series.TensorboardTimeSeries(), - tensorboard_time_series.TensorboardTimeSeries(), - tensorboard_time_series.TensorboardTimeSeries(), - ], - next_page_token="abc", - ), - tensorboard_service.ListTensorboardTimeSeriesResponse( - tensorboard_time_series=[], next_page_token="def", - ), - tensorboard_service.ListTensorboardTimeSeriesResponse( - tensorboard_time_series=[ - tensorboard_time_series.TensorboardTimeSeries(), - ], - next_page_token="ghi", - ), - tensorboard_service.ListTensorboardTimeSeriesResponse( - tensorboard_time_series=[ - tensorboard_time_series.TensorboardTimeSeries(), - tensorboard_time_series.TensorboardTimeSeries(), - ], - ), - RuntimeError, - ) - async_pager = await client.list_tensorboard_time_series(request={},) - assert async_pager.next_page_token == "abc" - responses = [] - async for response in async_pager: - responses.append(response) - - assert len(responses) == 6 - assert all( - isinstance(i, tensorboard_time_series.TensorboardTimeSeries) - for i in responses - ) - - -@pytest.mark.asyncio -async def test_list_tensorboard_time_series_async_pages(): - client = TensorboardServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.list_tensorboard_time_series), - "__call__", - new_callable=mock.AsyncMock, - ) as call: - # Set the response to a series of pages. - call.side_effect = ( - tensorboard_service.ListTensorboardTimeSeriesResponse( - tensorboard_time_series=[ - tensorboard_time_series.TensorboardTimeSeries(), - tensorboard_time_series.TensorboardTimeSeries(), - tensorboard_time_series.TensorboardTimeSeries(), - ], - next_page_token="abc", - ), - tensorboard_service.ListTensorboardTimeSeriesResponse( - tensorboard_time_series=[], next_page_token="def", - ), - tensorboard_service.ListTensorboardTimeSeriesResponse( - tensorboard_time_series=[ - tensorboard_time_series.TensorboardTimeSeries(), - ], - next_page_token="ghi", - ), - tensorboard_service.ListTensorboardTimeSeriesResponse( - tensorboard_time_series=[ - tensorboard_time_series.TensorboardTimeSeries(), - tensorboard_time_series.TensorboardTimeSeries(), - ], - ), - RuntimeError, - ) - pages = [] - async for page_ in ( - await client.list_tensorboard_time_series(request={}) - ).pages: - pages.append(page_) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token - - -def test_delete_tensorboard_time_series( - transport: str = "grpc", - request_type=tensorboard_service.DeleteTensorboardTimeSeriesRequest, -): - client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, - ) - - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_tensorboard_time_series), "__call__" - ) as call: - # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name="operations/spam") - response = client.delete_tensorboard_time_series(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.DeleteTensorboardTimeSeriesRequest() - - # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) - - -def test_delete_tensorboard_time_series_from_dict(): - test_delete_tensorboard_time_series(request_type=dict) - - -def test_delete_tensorboard_time_series_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. - client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", - ) - - # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client.transport.delete_tensorboard_time_series), "__call__" - ) as call: - client.delete_tensorboard_time_series() + client.update_tensorboard_time_series() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.DeleteTensorboardTimeSeriesRequest() + assert args[0] == tensorboard_service.UpdateTensorboardTimeSeriesRequest() @pytest.mark.asyncio -async def test_delete_tensorboard_time_series_async( +async def test_update_tensorboard_time_series_async( transport: str = "grpc_asyncio", - request_type=tensorboard_service.DeleteTensorboardTimeSeriesRequest, + request_type=tensorboard_service.UpdateTensorboardTimeSeriesRequest, ): client = TensorboardServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -5964,45 +6358,63 @@ async def test_delete_tensorboard_time_series_async( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_tensorboard_time_series), "__call__" + type(client.transport.update_tensorboard_time_series), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") + gca_tensorboard_time_series.TensorboardTimeSeries( + name="name_value", + display_name="display_name_value", + description="description_value", + value_type=gca_tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR, + etag="etag_value", + plugin_name="plugin_name_value", + plugin_data=b"plugin_data_blob", + ) ) - response = await client.delete_tensorboard_time_series(request) + response = await client.update_tensorboard_time_series(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.DeleteTensorboardTimeSeriesRequest() + assert args[0] == tensorboard_service.UpdateTensorboardTimeSeriesRequest() # Establish that the response is the type that we expect. - assert isinstance(response, future.Future) + assert isinstance(response, gca_tensorboard_time_series.TensorboardTimeSeries) + assert response.name == "name_value" + assert response.display_name == "display_name_value" + assert response.description == "description_value" + assert ( + response.value_type + == gca_tensorboard_time_series.TensorboardTimeSeries.ValueType.SCALAR + ) + assert response.etag == "etag_value" + assert response.plugin_name == "plugin_name_value" + assert response.plugin_data == b"plugin_data_blob" @pytest.mark.asyncio -async def test_delete_tensorboard_time_series_async_from_dict(): - await test_delete_tensorboard_time_series_async(request_type=dict) +async def test_update_tensorboard_time_series_async_from_dict(): + await test_update_tensorboard_time_series_async(request_type=dict) -def test_delete_tensorboard_time_series_field_headers(): +def test_update_tensorboard_time_series_field_headers(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = tensorboard_service.DeleteTensorboardTimeSeriesRequest() + request = tensorboard_service.UpdateTensorboardTimeSeriesRequest() - request.name = "name/value" + request.tensorboard_time_series.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_tensorboard_time_series), "__call__" + type(client.transport.update_tensorboard_time_series), "__call__" ) as call: - call.return_value = operations_pb2.Operation(name="operations/op") - client.delete_tensorboard_time_series(request) + call.return_value = gca_tensorboard_time_series.TensorboardTimeSeries() + client.update_tensorboard_time_series(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -6011,29 +6423,32 @@ def test_delete_tensorboard_time_series_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "tensorboard_time_series.name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_delete_tensorboard_time_series_field_headers_async(): +async def test_update_tensorboard_time_series_field_headers_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = tensorboard_service.DeleteTensorboardTimeSeriesRequest() + request = tensorboard_service.UpdateTensorboardTimeSeriesRequest() - request.name = "name/value" + request.tensorboard_time_series.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_tensorboard_time_series), "__call__" + type(client.transport.update_tensorboard_time_series), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/op") + gca_tensorboard_time_series.TensorboardTimeSeries() ) - await client.delete_tensorboard_time_series(request) + await client.update_tensorboard_time_series(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -6042,32 +6457,45 @@ async def test_delete_tensorboard_time_series_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "tensorboard_time_series.name=name_value", + ) in kw["metadata"] -def test_delete_tensorboard_time_series_flattened(): +def test_update_tensorboard_time_series_flattened(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_tensorboard_time_series), "__call__" + type(client.transport.update_tensorboard_time_series), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name="operations/op") + call.return_value = gca_tensorboard_time_series.TensorboardTimeSeries() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_tensorboard_time_series(name="name_value",) + client.update_tensorboard_time_series( + tensorboard_time_series=gca_tensorboard_time_series.TensorboardTimeSeries( + name="name_value" + ), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].tensorboard_time_series + mock_val = gca_tensorboard_time_series.TensorboardTimeSeries(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val -def test_delete_tensorboard_time_series_flattened_error(): +def test_update_tensorboard_time_series_flattened_error(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -6075,40 +6503,54 @@ def test_delete_tensorboard_time_series_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.delete_tensorboard_time_series( - tensorboard_service.DeleteTensorboardTimeSeriesRequest(), name="name_value", + client.update_tensorboard_time_series( + tensorboard_service.UpdateTensorboardTimeSeriesRequest(), + tensorboard_time_series=gca_tensorboard_time_series.TensorboardTimeSeries( + name="name_value" + ), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) @pytest.mark.asyncio -async def test_delete_tensorboard_time_series_flattened_async(): +async def test_update_tensorboard_time_series_flattened_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.delete_tensorboard_time_series), "__call__" + type(client.transport.update_tensorboard_time_series), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = operations_pb2.Operation(name="operations/op") + call.return_value = gca_tensorboard_time_series.TensorboardTimeSeries() call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - operations_pb2.Operation(name="operations/spam") + gca_tensorboard_time_series.TensorboardTimeSeries() ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_tensorboard_time_series(name="name_value",) - + response = await client.update_tensorboard_time_series( + tensorboard_time_series=gca_tensorboard_time_series.TensorboardTimeSeries( + name="name_value" + ), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), + ) + # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].tensorboard_time_series + mock_val = gca_tensorboard_time_series.TensorboardTimeSeries(name="name_value") + assert arg == mock_val + arg = args[0].update_mask + mock_val = field_mask_pb2.FieldMask(paths=["paths_value"]) + assert arg == mock_val @pytest.mark.asyncio -async def test_delete_tensorboard_time_series_flattened_error_async(): +async def test_update_tensorboard_time_series_flattened_error_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -6116,17 +6558,26 @@ async def test_delete_tensorboard_time_series_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.delete_tensorboard_time_series( - tensorboard_service.DeleteTensorboardTimeSeriesRequest(), name="name_value", + await client.update_tensorboard_time_series( + tensorboard_service.UpdateTensorboardTimeSeriesRequest(), + tensorboard_time_series=gca_tensorboard_time_series.TensorboardTimeSeries( + name="name_value" + ), + update_mask=field_mask_pb2.FieldMask(paths=["paths_value"]), ) -def test_read_tensorboard_time_series_data( - transport: str = "grpc", - request_type=tensorboard_service.ReadTensorboardTimeSeriesDataRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.ListTensorboardTimeSeriesRequest, + dict, + ], +) +def test_list_tensorboard_time_series(request_type, transport: str = "grpc"): client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -6135,51 +6586,50 @@ def test_read_tensorboard_time_series_data( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.read_tensorboard_time_series_data), "__call__" + type(client.transport.list_tensorboard_time_series), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = tensorboard_service.ReadTensorboardTimeSeriesDataResponse() - response = client.read_tensorboard_time_series_data(request) + call.return_value = tensorboard_service.ListTensorboardTimeSeriesResponse( + next_page_token="next_page_token_value", + ) + response = client.list_tensorboard_time_series(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.ReadTensorboardTimeSeriesDataRequest() + assert args[0] == tensorboard_service.ListTensorboardTimeSeriesRequest() # Establish that the response is the type that we expect. - assert isinstance( - response, tensorboard_service.ReadTensorboardTimeSeriesDataResponse - ) - - -def test_read_tensorboard_time_series_data_from_dict(): - test_read_tensorboard_time_series_data(request_type=dict) + assert isinstance(response, pagers.ListTensorboardTimeSeriesPager) + assert response.next_page_token == "next_page_token_value" -def test_read_tensorboard_time_series_data_empty_call(): +def test_list_tensorboard_time_series_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.read_tensorboard_time_series_data), "__call__" + type(client.transport.list_tensorboard_time_series), "__call__" ) as call: - client.read_tensorboard_time_series_data() + client.list_tensorboard_time_series() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.ReadTensorboardTimeSeriesDataRequest() + assert args[0] == tensorboard_service.ListTensorboardTimeSeriesRequest() @pytest.mark.asyncio -async def test_read_tensorboard_time_series_data_async( +async def test_list_tensorboard_time_series_async( transport: str = "grpc_asyncio", - request_type=tensorboard_service.ReadTensorboardTimeSeriesDataRequest, + request_type=tensorboard_service.ListTensorboardTimeSeriesRequest, ): client = TensorboardServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -6188,47 +6638,48 @@ async def test_read_tensorboard_time_series_data_async( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.read_tensorboard_time_series_data), "__call__" + type(client.transport.list_tensorboard_time_series), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - tensorboard_service.ReadTensorboardTimeSeriesDataResponse() + tensorboard_service.ListTensorboardTimeSeriesResponse( + next_page_token="next_page_token_value", + ) ) - response = await client.read_tensorboard_time_series_data(request) + response = await client.list_tensorboard_time_series(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.ReadTensorboardTimeSeriesDataRequest() + assert args[0] == tensorboard_service.ListTensorboardTimeSeriesRequest() # Establish that the response is the type that we expect. - assert isinstance( - response, tensorboard_service.ReadTensorboardTimeSeriesDataResponse - ) + assert isinstance(response, pagers.ListTensorboardTimeSeriesAsyncPager) + assert response.next_page_token == "next_page_token_value" @pytest.mark.asyncio -async def test_read_tensorboard_time_series_data_async_from_dict(): - await test_read_tensorboard_time_series_data_async(request_type=dict) +async def test_list_tensorboard_time_series_async_from_dict(): + await test_list_tensorboard_time_series_async(request_type=dict) -def test_read_tensorboard_time_series_data_field_headers(): +def test_list_tensorboard_time_series_field_headers(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = tensorboard_service.ReadTensorboardTimeSeriesDataRequest() + request = tensorboard_service.ListTensorboardTimeSeriesRequest() - request.tensorboard_time_series = "tensorboard_time_series/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.read_tensorboard_time_series_data), "__call__" + type(client.transport.list_tensorboard_time_series), "__call__" ) as call: - call.return_value = tensorboard_service.ReadTensorboardTimeSeriesDataResponse() - client.read_tensorboard_time_series_data(request) + call.return_value = tensorboard_service.ListTensorboardTimeSeriesResponse() + client.list_tensorboard_time_series(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -6239,30 +6690,30 @@ def test_read_tensorboard_time_series_data_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "tensorboard_time_series=tensorboard_time_series/value", + "parent=parent_value", ) in kw["metadata"] @pytest.mark.asyncio -async def test_read_tensorboard_time_series_data_field_headers_async(): +async def test_list_tensorboard_time_series_field_headers_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = tensorboard_service.ReadTensorboardTimeSeriesDataRequest() + request = tensorboard_service.ListTensorboardTimeSeriesRequest() - request.tensorboard_time_series = "tensorboard_time_series/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.read_tensorboard_time_series_data), "__call__" + type(client.transport.list_tensorboard_time_series), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - tensorboard_service.ReadTensorboardTimeSeriesDataResponse() + tensorboard_service.ListTensorboardTimeSeriesResponse() ) - await client.read_tensorboard_time_series_data(request) + await client.list_tensorboard_time_series(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -6273,35 +6724,37 @@ async def test_read_tensorboard_time_series_data_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "tensorboard_time_series=tensorboard_time_series/value", + "parent=parent_value", ) in kw["metadata"] -def test_read_tensorboard_time_series_data_flattened(): +def test_list_tensorboard_time_series_flattened(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.read_tensorboard_time_series_data), "__call__" + type(client.transport.list_tensorboard_time_series), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = tensorboard_service.ReadTensorboardTimeSeriesDataResponse() + call.return_value = tensorboard_service.ListTensorboardTimeSeriesResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.read_tensorboard_time_series_data( - tensorboard_time_series="tensorboard_time_series_value", + client.list_tensorboard_time_series( + parent="parent_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].tensorboard_time_series == "tensorboard_time_series_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val -def test_read_tensorboard_time_series_data_flattened_error(): +def test_list_tensorboard_time_series_flattened_error(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -6309,43 +6762,45 @@ def test_read_tensorboard_time_series_data_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.read_tensorboard_time_series_data( - tensorboard_service.ReadTensorboardTimeSeriesDataRequest(), - tensorboard_time_series="tensorboard_time_series_value", + client.list_tensorboard_time_series( + tensorboard_service.ListTensorboardTimeSeriesRequest(), + parent="parent_value", ) @pytest.mark.asyncio -async def test_read_tensorboard_time_series_data_flattened_async(): +async def test_list_tensorboard_time_series_flattened_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.read_tensorboard_time_series_data), "__call__" + type(client.transport.list_tensorboard_time_series), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = tensorboard_service.ReadTensorboardTimeSeriesDataResponse() + call.return_value = tensorboard_service.ListTensorboardTimeSeriesResponse() call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - tensorboard_service.ReadTensorboardTimeSeriesDataResponse() + tensorboard_service.ListTensorboardTimeSeriesResponse() ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.read_tensorboard_time_series_data( - tensorboard_time_series="tensorboard_time_series_value", + response = await client.list_tensorboard_time_series( + parent="parent_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].tensorboard_time_series == "tensorboard_time_series_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio -async def test_read_tensorboard_time_series_data_flattened_error_async(): +async def test_list_tensorboard_time_series_flattened_error_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -6353,123 +6808,321 @@ async def test_read_tensorboard_time_series_data_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.read_tensorboard_time_series_data( - tensorboard_service.ReadTensorboardTimeSeriesDataRequest(), - tensorboard_time_series="tensorboard_time_series_value", + await client.list_tensorboard_time_series( + tensorboard_service.ListTensorboardTimeSeriesRequest(), + parent="parent_value", ) -def test_read_tensorboard_blob_data( - transport: str = "grpc", - request_type=tensorboard_service.ReadTensorboardBlobDataRequest, -): +def test_list_tensorboard_time_series_pager(transport_name: str = "grpc"): client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.read_tensorboard_blob_data), "__call__" + type(client.transport.list_tensorboard_time_series), "__call__" ) as call: - # Designate an appropriate return value for the call. - call.return_value = iter( - [tensorboard_service.ReadTensorboardBlobDataResponse()] + # Set the response to a series of pages. + call.side_effect = ( + tensorboard_service.ListTensorboardTimeSeriesResponse( + tensorboard_time_series=[ + tensorboard_time_series.TensorboardTimeSeries(), + tensorboard_time_series.TensorboardTimeSeries(), + tensorboard_time_series.TensorboardTimeSeries(), + ], + next_page_token="abc", + ), + tensorboard_service.ListTensorboardTimeSeriesResponse( + tensorboard_time_series=[], + next_page_token="def", + ), + tensorboard_service.ListTensorboardTimeSeriesResponse( + tensorboard_time_series=[ + tensorboard_time_series.TensorboardTimeSeries(), + ], + next_page_token="ghi", + ), + tensorboard_service.ListTensorboardTimeSeriesResponse( + tensorboard_time_series=[ + tensorboard_time_series.TensorboardTimeSeries(), + tensorboard_time_series.TensorboardTimeSeries(), + ], + ), + RuntimeError, ) - response = client.read_tensorboard_blob_data(request) - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) == 1 - _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.ReadTensorboardBlobDataRequest() - - # Establish that the response is the type that we expect. - for message in response: - assert isinstance(message, tensorboard_service.ReadTensorboardBlobDataResponse) + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", ""),)), + ) + pager = client.list_tensorboard_time_series(request={}) + assert pager._metadata == metadata -def test_read_tensorboard_blob_data_from_dict(): - test_read_tensorboard_blob_data(request_type=dict) + results = list(pager) + assert len(results) == 6 + assert all( + isinstance(i, tensorboard_time_series.TensorboardTimeSeries) + for i in results + ) -def test_read_tensorboard_blob_data_empty_call(): - # This test is a coverage failsafe to make sure that totally empty calls, - # i.e. request == None and no flattened fields passed, work. +def test_list_tensorboard_time_series_pages(transport_name: str = "grpc"): client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.read_tensorboard_blob_data), "__call__" + type(client.transport.list_tensorboard_time_series), "__call__" ) as call: - client.read_tensorboard_blob_data() - call.assert_called() - _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.ReadTensorboardBlobDataRequest() + # Set the response to a series of pages. + call.side_effect = ( + tensorboard_service.ListTensorboardTimeSeriesResponse( + tensorboard_time_series=[ + tensorboard_time_series.TensorboardTimeSeries(), + tensorboard_time_series.TensorboardTimeSeries(), + tensorboard_time_series.TensorboardTimeSeries(), + ], + next_page_token="abc", + ), + tensorboard_service.ListTensorboardTimeSeriesResponse( + tensorboard_time_series=[], + next_page_token="def", + ), + tensorboard_service.ListTensorboardTimeSeriesResponse( + tensorboard_time_series=[ + tensorboard_time_series.TensorboardTimeSeries(), + ], + next_page_token="ghi", + ), + tensorboard_service.ListTensorboardTimeSeriesResponse( + tensorboard_time_series=[ + tensorboard_time_series.TensorboardTimeSeries(), + tensorboard_time_series.TensorboardTimeSeries(), + ], + ), + RuntimeError, + ) + pages = list(client.list_tensorboard_time_series(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token @pytest.mark.asyncio -async def test_read_tensorboard_blob_data_async( - transport: str = "grpc_asyncio", - request_type=tensorboard_service.ReadTensorboardBlobDataRequest, -): +async def test_list_tensorboard_time_series_async_pager(): client = TensorboardServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials, ) - # Everything is optional in proto3 as far as the runtime is concerned, - # and we are mocking out the actual API, so just send an empty request. - request = request_type() - # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.read_tensorboard_blob_data), "__call__" + type(client.transport.list_tensorboard_time_series), + "__call__", + new_callable=mock.AsyncMock, ) as call: - # Designate an appropriate return value for the call. - call.return_value = mock.Mock(aio.UnaryStreamCall, autospec=True) - call.return_value.read = mock.AsyncMock( - side_effect=[tensorboard_service.ReadTensorboardBlobDataResponse()] - ) - response = await client.read_tensorboard_blob_data(request) - - # Establish that the underlying gRPC stub method was called. - assert len(call.mock_calls) - _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.ReadTensorboardBlobDataRequest() - - # Establish that the response is the type that we expect. - message = await response.read() - assert isinstance(message, tensorboard_service.ReadTensorboardBlobDataResponse) - + # Set the response to a series of pages. + call.side_effect = ( + tensorboard_service.ListTensorboardTimeSeriesResponse( + tensorboard_time_series=[ + tensorboard_time_series.TensorboardTimeSeries(), + tensorboard_time_series.TensorboardTimeSeries(), + tensorboard_time_series.TensorboardTimeSeries(), + ], + next_page_token="abc", + ), + tensorboard_service.ListTensorboardTimeSeriesResponse( + tensorboard_time_series=[], + next_page_token="def", + ), + tensorboard_service.ListTensorboardTimeSeriesResponse( + tensorboard_time_series=[ + tensorboard_time_series.TensorboardTimeSeries(), + ], + next_page_token="ghi", + ), + tensorboard_service.ListTensorboardTimeSeriesResponse( + tensorboard_time_series=[ + tensorboard_time_series.TensorboardTimeSeries(), + tensorboard_time_series.TensorboardTimeSeries(), + ], + ), + RuntimeError, + ) + async_pager = await client.list_tensorboard_time_series( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all( + isinstance(i, tensorboard_time_series.TensorboardTimeSeries) + for i in responses + ) + @pytest.mark.asyncio -async def test_read_tensorboard_blob_data_async_from_dict(): - await test_read_tensorboard_blob_data_async(request_type=dict) +async def test_list_tensorboard_time_series_async_pages(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.list_tensorboard_time_series), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + tensorboard_service.ListTensorboardTimeSeriesResponse( + tensorboard_time_series=[ + tensorboard_time_series.TensorboardTimeSeries(), + tensorboard_time_series.TensorboardTimeSeries(), + tensorboard_time_series.TensorboardTimeSeries(), + ], + next_page_token="abc", + ), + tensorboard_service.ListTensorboardTimeSeriesResponse( + tensorboard_time_series=[], + next_page_token="def", + ), + tensorboard_service.ListTensorboardTimeSeriesResponse( + tensorboard_time_series=[ + tensorboard_time_series.TensorboardTimeSeries(), + ], + next_page_token="ghi", + ), + tensorboard_service.ListTensorboardTimeSeriesResponse( + tensorboard_time_series=[ + tensorboard_time_series.TensorboardTimeSeries(), + tensorboard_time_series.TensorboardTimeSeries(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.list_tensorboard_time_series(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token -def test_read_tensorboard_blob_data_field_headers(): +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.DeleteTensorboardTimeSeriesRequest, + dict, + ], +) +def test_delete_tensorboard_time_series(request_type, transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_tensorboard_time_series), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation(name="operations/spam") + response = client.delete_tensorboard_time_series(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.DeleteTensorboardTimeSeriesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +def test_delete_tensorboard_time_series_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_tensorboard_time_series), "__call__" + ) as call: + client.delete_tensorboard_time_series() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.DeleteTensorboardTimeSeriesRequest() + + +@pytest.mark.asyncio +async def test_delete_tensorboard_time_series_async( + transport: str = "grpc_asyncio", + request_type=tensorboard_service.DeleteTensorboardTimeSeriesRequest, +): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.delete_tensorboard_time_series), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) + response = await client.delete_tensorboard_time_series(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.DeleteTensorboardTimeSeriesRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, future.Future) + + +@pytest.mark.asyncio +async def test_delete_tensorboard_time_series_async_from_dict(): + await test_delete_tensorboard_time_series_async(request_type=dict) + + +def test_delete_tensorboard_time_series_field_headers(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = tensorboard_service.ReadTensorboardBlobDataRequest() + request = tensorboard_service.DeleteTensorboardTimeSeriesRequest() - request.time_series = "time_series/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.read_tensorboard_blob_data), "__call__" + type(client.transport.delete_tensorboard_time_series), "__call__" ) as call: - call.return_value = iter( - [tensorboard_service.ReadTensorboardBlobDataResponse()] - ) - client.read_tensorboard_blob_data(request) + call.return_value = operations_pb2.Operation(name="operations/op") + client.delete_tensorboard_time_series(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -6478,30 +7131,32 @@ def test_read_tensorboard_blob_data_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "time_series=time_series/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_read_tensorboard_blob_data_field_headers_async(): +async def test_delete_tensorboard_time_series_field_headers_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = tensorboard_service.ReadTensorboardBlobDataRequest() + request = tensorboard_service.DeleteTensorboardTimeSeriesRequest() - request.time_series = "time_series/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.read_tensorboard_blob_data), "__call__" + type(client.transport.delete_tensorboard_time_series), "__call__" ) as call: - call.return_value = mock.Mock(aio.UnaryStreamCall, autospec=True) - call.return_value.read = mock.AsyncMock( - side_effect=[tensorboard_service.ReadTensorboardBlobDataResponse()] + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/op") ) - await client.read_tensorboard_blob_data(request) + await client.delete_tensorboard_time_series(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -6510,34 +7165,39 @@ async def test_read_tensorboard_blob_data_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "time_series=time_series/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] -def test_read_tensorboard_blob_data_flattened(): +def test_delete_tensorboard_time_series_flattened(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.read_tensorboard_blob_data), "__call__" + type(client.transport.delete_tensorboard_time_series), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = iter( - [tensorboard_service.ReadTensorboardBlobDataResponse()] - ) + call.return_value = operations_pb2.Operation(name="operations/op") # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.read_tensorboard_blob_data(time_series="time_series_value",) + client.delete_tensorboard_time_series( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].time_series == "time_series_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val -def test_read_tensorboard_blob_data_flattened_error(): +def test_delete_tensorboard_time_series_flattened_error(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -6545,43 +7205,45 @@ def test_read_tensorboard_blob_data_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.read_tensorboard_blob_data( - tensorboard_service.ReadTensorboardBlobDataRequest(), - time_series="time_series_value", + client.delete_tensorboard_time_series( + tensorboard_service.DeleteTensorboardTimeSeriesRequest(), + name="name_value", ) @pytest.mark.asyncio -async def test_read_tensorboard_blob_data_flattened_async(): +async def test_delete_tensorboard_time_series_flattened_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.read_tensorboard_blob_data), "__call__" + type(client.transport.delete_tensorboard_time_series), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = iter( - [tensorboard_service.ReadTensorboardBlobDataResponse()] - ) + call.return_value = operations_pb2.Operation(name="operations/op") - call.return_value = mock.Mock(aio.UnaryStreamCall, autospec=True) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation(name="operations/spam") + ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.read_tensorboard_blob_data( - time_series="time_series_value", + response = await client.delete_tensorboard_time_series( + name="name_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].time_series == "time_series_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio -async def test_read_tensorboard_blob_data_flattened_error_async(): +async def test_delete_tensorboard_time_series_flattened_error_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -6589,18 +7251,23 @@ async def test_read_tensorboard_blob_data_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.read_tensorboard_blob_data( - tensorboard_service.ReadTensorboardBlobDataRequest(), - time_series="time_series_value", + await client.delete_tensorboard_time_series( + tensorboard_service.DeleteTensorboardTimeSeriesRequest(), + name="name_value", ) -def test_write_tensorboard_run_data( - transport: str = "grpc", - request_type=tensorboard_service.WriteTensorboardRunDataRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest, + dict, + ], +) +def test_batch_read_tensorboard_time_series_data(request_type, transport: str = "grpc"): client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -6609,49 +7276,55 @@ def test_write_tensorboard_run_data( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.write_tensorboard_run_data), "__call__" + type(client.transport.batch_read_tensorboard_time_series_data), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = tensorboard_service.WriteTensorboardRunDataResponse() - response = client.write_tensorboard_run_data(request) + call.return_value = ( + tensorboard_service.BatchReadTensorboardTimeSeriesDataResponse() + ) + response = client.batch_read_tensorboard_time_series_data(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.WriteTensorboardRunDataRequest() + assert ( + args[0] == tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest() + ) # Establish that the response is the type that we expect. - assert isinstance(response, tensorboard_service.WriteTensorboardRunDataResponse) - - -def test_write_tensorboard_run_data_from_dict(): - test_write_tensorboard_run_data(request_type=dict) + assert isinstance( + response, tensorboard_service.BatchReadTensorboardTimeSeriesDataResponse + ) -def test_write_tensorboard_run_data_empty_call(): +def test_batch_read_tensorboard_time_series_data_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.write_tensorboard_run_data), "__call__" + type(client.transport.batch_read_tensorboard_time_series_data), "__call__" ) as call: - client.write_tensorboard_run_data() + client.batch_read_tensorboard_time_series_data() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.WriteTensorboardRunDataRequest() + assert ( + args[0] == tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest() + ) @pytest.mark.asyncio -async def test_write_tensorboard_run_data_async( +async def test_batch_read_tensorboard_time_series_data_async( transport: str = "grpc_asyncio", - request_type=tensorboard_service.WriteTensorboardRunDataRequest, + request_type=tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest, ): client = TensorboardServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -6660,45 +7333,51 @@ async def test_write_tensorboard_run_data_async( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.write_tensorboard_run_data), "__call__" + type(client.transport.batch_read_tensorboard_time_series_data), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - tensorboard_service.WriteTensorboardRunDataResponse() + tensorboard_service.BatchReadTensorboardTimeSeriesDataResponse() ) - response = await client.write_tensorboard_run_data(request) + response = await client.batch_read_tensorboard_time_series_data(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.WriteTensorboardRunDataRequest() + assert ( + args[0] == tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest() + ) # Establish that the response is the type that we expect. - assert isinstance(response, tensorboard_service.WriteTensorboardRunDataResponse) + assert isinstance( + response, tensorboard_service.BatchReadTensorboardTimeSeriesDataResponse + ) @pytest.mark.asyncio -async def test_write_tensorboard_run_data_async_from_dict(): - await test_write_tensorboard_run_data_async(request_type=dict) +async def test_batch_read_tensorboard_time_series_data_async_from_dict(): + await test_batch_read_tensorboard_time_series_data_async(request_type=dict) -def test_write_tensorboard_run_data_field_headers(): +def test_batch_read_tensorboard_time_series_data_field_headers(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = tensorboard_service.WriteTensorboardRunDataRequest() + request = tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest() - request.tensorboard_run = "tensorboard_run/value" + request.tensorboard = "tensorboard_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.write_tensorboard_run_data), "__call__" + type(client.transport.batch_read_tensorboard_time_series_data), "__call__" ) as call: - call.return_value = tensorboard_service.WriteTensorboardRunDataResponse() - client.write_tensorboard_run_data(request) + call.return_value = ( + tensorboard_service.BatchReadTensorboardTimeSeriesDataResponse() + ) + client.batch_read_tensorboard_time_series_data(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -6707,31 +7386,32 @@ def test_write_tensorboard_run_data_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "tensorboard_run=tensorboard_run/value",) in kw[ - "metadata" - ] + assert ( + "x-goog-request-params", + "tensorboard=tensorboard_value", + ) in kw["metadata"] @pytest.mark.asyncio -async def test_write_tensorboard_run_data_field_headers_async(): +async def test_batch_read_tensorboard_time_series_data_field_headers_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = tensorboard_service.WriteTensorboardRunDataRequest() + request = tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest() - request.tensorboard_run = "tensorboard_run/value" + request.tensorboard = "tensorboard_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.write_tensorboard_run_data), "__call__" + type(client.transport.batch_read_tensorboard_time_series_data), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - tensorboard_service.WriteTensorboardRunDataResponse() + tensorboard_service.BatchReadTensorboardTimeSeriesDataResponse() ) - await client.write_tensorboard_run_data(request) + await client.batch_read_tensorboard_time_series_data(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -6740,46 +7420,41 @@ async def test_write_tensorboard_run_data_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "tensorboard_run=tensorboard_run/value",) in kw[ - "metadata" - ] + assert ( + "x-goog-request-params", + "tensorboard=tensorboard_value", + ) in kw["metadata"] -def test_write_tensorboard_run_data_flattened(): +def test_batch_read_tensorboard_time_series_data_flattened(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.write_tensorboard_run_data), "__call__" + type(client.transport.batch_read_tensorboard_time_series_data), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = tensorboard_service.WriteTensorboardRunDataResponse() + call.return_value = ( + tensorboard_service.BatchReadTensorboardTimeSeriesDataResponse() + ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.write_tensorboard_run_data( - tensorboard_run="tensorboard_run_value", - time_series_data=[ - tensorboard_data.TimeSeriesData( - tensorboard_time_series_id="tensorboard_time_series_id_value" - ) - ], + client.batch_read_tensorboard_time_series_data( + tensorboard="tensorboard_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].tensorboard_run == "tensorboard_run_value" - assert args[0].time_series_data == [ - tensorboard_data.TimeSeriesData( - tensorboard_time_series_id="tensorboard_time_series_id_value" - ) - ] + arg = args[0].tensorboard + mock_val = "tensorboard_value" + assert arg == mock_val -def test_write_tensorboard_run_data_flattened_error(): +def test_batch_read_tensorboard_time_series_data_flattened_error(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -6787,58 +7462,47 @@ def test_write_tensorboard_run_data_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.write_tensorboard_run_data( - tensorboard_service.WriteTensorboardRunDataRequest(), - tensorboard_run="tensorboard_run_value", - time_series_data=[ - tensorboard_data.TimeSeriesData( - tensorboard_time_series_id="tensorboard_time_series_id_value" - ) - ], + client.batch_read_tensorboard_time_series_data( + tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest(), + tensorboard="tensorboard_value", ) @pytest.mark.asyncio -async def test_write_tensorboard_run_data_flattened_async(): +async def test_batch_read_tensorboard_time_series_data_flattened_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.write_tensorboard_run_data), "__call__" + type(client.transport.batch_read_tensorboard_time_series_data), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = tensorboard_service.WriteTensorboardRunDataResponse() + call.return_value = ( + tensorboard_service.BatchReadTensorboardTimeSeriesDataResponse() + ) call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - tensorboard_service.WriteTensorboardRunDataResponse() + tensorboard_service.BatchReadTensorboardTimeSeriesDataResponse() ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.write_tensorboard_run_data( - tensorboard_run="tensorboard_run_value", - time_series_data=[ - tensorboard_data.TimeSeriesData( - tensorboard_time_series_id="tensorboard_time_series_id_value" - ) - ], + response = await client.batch_read_tensorboard_time_series_data( + tensorboard="tensorboard_value", ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].tensorboard_run == "tensorboard_run_value" - assert args[0].time_series_data == [ - tensorboard_data.TimeSeriesData( - tensorboard_time_series_id="tensorboard_time_series_id_value" - ) - ] + arg = args[0].tensorboard + mock_val = "tensorboard_value" + assert arg == mock_val @pytest.mark.asyncio -async def test_write_tensorboard_run_data_flattened_error_async(): +async def test_batch_read_tensorboard_time_series_data_flattened_error_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -6846,23 +7510,23 @@ async def test_write_tensorboard_run_data_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.write_tensorboard_run_data( - tensorboard_service.WriteTensorboardRunDataRequest(), - tensorboard_run="tensorboard_run_value", - time_series_data=[ - tensorboard_data.TimeSeriesData( - tensorboard_time_series_id="tensorboard_time_series_id_value" - ) - ], + await client.batch_read_tensorboard_time_series_data( + tensorboard_service.BatchReadTensorboardTimeSeriesDataRequest(), + tensorboard="tensorboard_value", ) -def test_export_tensorboard_time_series_data( - transport: str = "grpc", - request_type=tensorboard_service.ExportTensorboardTimeSeriesDataRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.ReadTensorboardTimeSeriesDataRequest, + dict, + ], +) +def test_read_tensorboard_time_series_data(request_type, transport: str = "grpc"): client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -6871,52 +7535,49 @@ def test_export_tensorboard_time_series_data( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.export_tensorboard_time_series_data), "__call__" + type(client.transport.read_tensorboard_time_series_data), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = tensorboard_service.ExportTensorboardTimeSeriesDataResponse( - next_page_token="next_page_token_value", - ) - response = client.export_tensorboard_time_series_data(request) + call.return_value = tensorboard_service.ReadTensorboardTimeSeriesDataResponse() + response = client.read_tensorboard_time_series_data(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.ExportTensorboardTimeSeriesDataRequest() + assert args[0] == tensorboard_service.ReadTensorboardTimeSeriesDataRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ExportTensorboardTimeSeriesDataPager) - assert response.next_page_token == "next_page_token_value" - - -def test_export_tensorboard_time_series_data_from_dict(): - test_export_tensorboard_time_series_data(request_type=dict) + assert isinstance( + response, tensorboard_service.ReadTensorboardTimeSeriesDataResponse + ) -def test_export_tensorboard_time_series_data_empty_call(): +def test_read_tensorboard_time_series_data_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.export_tensorboard_time_series_data), "__call__" + type(client.transport.read_tensorboard_time_series_data), "__call__" ) as call: - client.export_tensorboard_time_series_data() + client.read_tensorboard_time_series_data() call.assert_called() _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.ExportTensorboardTimeSeriesDataRequest() + assert args[0] == tensorboard_service.ReadTensorboardTimeSeriesDataRequest() @pytest.mark.asyncio -async def test_export_tensorboard_time_series_data_async( +async def test_read_tensorboard_time_series_data_async( transport: str = "grpc_asyncio", - request_type=tensorboard_service.ExportTensorboardTimeSeriesDataRequest, + request_type=tensorboard_service.ReadTensorboardTimeSeriesDataRequest, ): client = TensorboardServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -6925,50 +7586,47 @@ async def test_export_tensorboard_time_series_data_async( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.export_tensorboard_time_series_data), "__call__" + type(client.transport.read_tensorboard_time_series_data), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - tensorboard_service.ExportTensorboardTimeSeriesDataResponse( - next_page_token="next_page_token_value", - ) + tensorboard_service.ReadTensorboardTimeSeriesDataResponse() ) - response = await client.export_tensorboard_time_series_data(request) + response = await client.read_tensorboard_time_series_data(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == tensorboard_service.ExportTensorboardTimeSeriesDataRequest() + assert args[0] == tensorboard_service.ReadTensorboardTimeSeriesDataRequest() # Establish that the response is the type that we expect. - assert isinstance(response, pagers.ExportTensorboardTimeSeriesDataAsyncPager) - assert response.next_page_token == "next_page_token_value" + assert isinstance( + response, tensorboard_service.ReadTensorboardTimeSeriesDataResponse + ) @pytest.mark.asyncio -async def test_export_tensorboard_time_series_data_async_from_dict(): - await test_export_tensorboard_time_series_data_async(request_type=dict) +async def test_read_tensorboard_time_series_data_async_from_dict(): + await test_read_tensorboard_time_series_data_async(request_type=dict) -def test_export_tensorboard_time_series_data_field_headers(): +def test_read_tensorboard_time_series_data_field_headers(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = tensorboard_service.ExportTensorboardTimeSeriesDataRequest() + request = tensorboard_service.ReadTensorboardTimeSeriesDataRequest() - request.tensorboard_time_series = "tensorboard_time_series/value" + request.tensorboard_time_series = "tensorboard_time_series_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.export_tensorboard_time_series_data), "__call__" + type(client.transport.read_tensorboard_time_series_data), "__call__" ) as call: - call.return_value = ( - tensorboard_service.ExportTensorboardTimeSeriesDataResponse() - ) - client.export_tensorboard_time_series_data(request) + call.return_value = tensorboard_service.ReadTensorboardTimeSeriesDataResponse() + client.read_tensorboard_time_series_data(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) == 1 @@ -6979,30 +7637,30 @@ def test_export_tensorboard_time_series_data_field_headers(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "tensorboard_time_series=tensorboard_time_series/value", + "tensorboard_time_series=tensorboard_time_series_value", ) in kw["metadata"] @pytest.mark.asyncio -async def test_export_tensorboard_time_series_data_field_headers_async(): +async def test_read_tensorboard_time_series_data_field_headers_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. - request = tensorboard_service.ExportTensorboardTimeSeriesDataRequest() + request = tensorboard_service.ReadTensorboardTimeSeriesDataRequest() - request.tensorboard_time_series = "tensorboard_time_series/value" + request.tensorboard_time_series = "tensorboard_time_series_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.export_tensorboard_time_series_data), "__call__" + type(client.transport.read_tensorboard_time_series_data), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - tensorboard_service.ExportTensorboardTimeSeriesDataResponse() + tensorboard_service.ReadTensorboardTimeSeriesDataResponse() ) - await client.export_tensorboard_time_series_data(request) + await client.read_tensorboard_time_series_data(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) @@ -7013,26 +7671,24 @@ async def test_export_tensorboard_time_series_data_field_headers_async(): _, _, kw = call.mock_calls[0] assert ( "x-goog-request-params", - "tensorboard_time_series=tensorboard_time_series/value", + "tensorboard_time_series=tensorboard_time_series_value", ) in kw["metadata"] -def test_export_tensorboard_time_series_data_flattened(): +def test_read_tensorboard_time_series_data_flattened(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.export_tensorboard_time_series_data), "__call__" + type(client.transport.read_tensorboard_time_series_data), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = ( - tensorboard_service.ExportTensorboardTimeSeriesDataResponse() - ) + call.return_value = tensorboard_service.ReadTensorboardTimeSeriesDataResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.export_tensorboard_time_series_data( + client.read_tensorboard_time_series_data( tensorboard_time_series="tensorboard_time_series_value", ) @@ -7040,10 +7696,12 @@ def test_export_tensorboard_time_series_data_flattened(): # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].tensorboard_time_series == "tensorboard_time_series_value" + arg = args[0].tensorboard_time_series + mock_val = "tensorboard_time_series_value" + assert arg == mock_val -def test_export_tensorboard_time_series_data_flattened_error(): +def test_read_tensorboard_time_series_data_flattened_error(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -7051,33 +7709,31 @@ def test_export_tensorboard_time_series_data_flattened_error(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - client.export_tensorboard_time_series_data( - tensorboard_service.ExportTensorboardTimeSeriesDataRequest(), + client.read_tensorboard_time_series_data( + tensorboard_service.ReadTensorboardTimeSeriesDataRequest(), tensorboard_time_series="tensorboard_time_series_value", ) @pytest.mark.asyncio -async def test_export_tensorboard_time_series_data_flattened_async(): +async def test_read_tensorboard_time_series_data_flattened_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.export_tensorboard_time_series_data), "__call__" + type(client.transport.read_tensorboard_time_series_data), "__call__" ) as call: # Designate an appropriate return value for the call. - call.return_value = ( - tensorboard_service.ExportTensorboardTimeSeriesDataResponse() - ) + call.return_value = tensorboard_service.ReadTensorboardTimeSeriesDataResponse() call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - tensorboard_service.ExportTensorboardTimeSeriesDataResponse() + tensorboard_service.ReadTensorboardTimeSeriesDataResponse() ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.export_tensorboard_time_series_data( + response = await client.read_tensorboard_time_series_data( tensorboard_time_series="tensorboard_time_series_value", ) @@ -7085,11 +7741,13 @@ async def test_export_tensorboard_time_series_data_flattened_async(): # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].tensorboard_time_series == "tensorboard_time_series_value" + arg = args[0].tensorboard_time_series + mock_val = "tensorboard_time_series_value" + assert arg == mock_val @pytest.mark.asyncio -async def test_export_tensorboard_time_series_data_flattened_error_async(): +async def test_read_tensorboard_time_series_data_flattened_error_async(): client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) @@ -7097,1008 +7755,3649 @@ async def test_export_tensorboard_time_series_data_flattened_error_async(): # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): - await client.export_tensorboard_time_series_data( - tensorboard_service.ExportTensorboardTimeSeriesDataRequest(), + await client.read_tensorboard_time_series_data( + tensorboard_service.ReadTensorboardTimeSeriesDataRequest(), tensorboard_time_series="tensorboard_time_series_value", ) -def test_export_tensorboard_time_series_data_pager(): - client = TensorboardServiceClient(credentials=ga_credentials.AnonymousCredentials,) +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.ReadTensorboardBlobDataRequest, + dict, + ], +) +def test_read_tensorboard_blob_data(request_type, transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.export_tensorboard_time_series_data), "__call__" + type(client.transport.read_tensorboard_blob_data), "__call__" ) as call: - # Set the response to a series of pages. - call.side_effect = ( - tensorboard_service.ExportTensorboardTimeSeriesDataResponse( - time_series_data_points=[ - tensorboard_data.TimeSeriesDataPoint(), - tensorboard_data.TimeSeriesDataPoint(), - tensorboard_data.TimeSeriesDataPoint(), - ], - next_page_token="abc", - ), - tensorboard_service.ExportTensorboardTimeSeriesDataResponse( - time_series_data_points=[], next_page_token="def", - ), - tensorboard_service.ExportTensorboardTimeSeriesDataResponse( - time_series_data_points=[tensorboard_data.TimeSeriesDataPoint(),], - next_page_token="ghi", - ), - tensorboard_service.ExportTensorboardTimeSeriesDataResponse( - time_series_data_points=[ - tensorboard_data.TimeSeriesDataPoint(), - tensorboard_data.TimeSeriesDataPoint(), - ], - ), - RuntimeError, + # Designate an appropriate return value for the call. + call.return_value = iter( + [tensorboard_service.ReadTensorboardBlobDataResponse()] ) + response = client.read_tensorboard_blob_data(request) - metadata = () - metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata( - (("tensorboard_time_series", ""),) - ), - ) - pager = client.export_tensorboard_time_series_data(request={}) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.ReadTensorboardBlobDataRequest() - assert pager._metadata == metadata + # Establish that the response is the type that we expect. + for message in response: + assert isinstance(message, tensorboard_service.ReadTensorboardBlobDataResponse) - results = [i for i in pager] - assert len(results) == 6 - assert all(isinstance(i, tensorboard_data.TimeSeriesDataPoint) for i in results) - -def test_export_tensorboard_time_series_data_pages(): - client = TensorboardServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_read_tensorboard_blob_data_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.export_tensorboard_time_series_data), "__call__" + type(client.transport.read_tensorboard_blob_data), "__call__" ) as call: - # Set the response to a series of pages. - call.side_effect = ( - tensorboard_service.ExportTensorboardTimeSeriesDataResponse( - time_series_data_points=[ - tensorboard_data.TimeSeriesDataPoint(), - tensorboard_data.TimeSeriesDataPoint(), - tensorboard_data.TimeSeriesDataPoint(), - ], - next_page_token="abc", - ), - tensorboard_service.ExportTensorboardTimeSeriesDataResponse( - time_series_data_points=[], next_page_token="def", - ), - tensorboard_service.ExportTensorboardTimeSeriesDataResponse( - time_series_data_points=[tensorboard_data.TimeSeriesDataPoint(),], - next_page_token="ghi", - ), - tensorboard_service.ExportTensorboardTimeSeriesDataResponse( - time_series_data_points=[ - tensorboard_data.TimeSeriesDataPoint(), - tensorboard_data.TimeSeriesDataPoint(), - ], - ), - RuntimeError, - ) - pages = list(client.export_tensorboard_time_series_data(request={}).pages) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token + client.read_tensorboard_blob_data() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.ReadTensorboardBlobDataRequest() @pytest.mark.asyncio -async def test_export_tensorboard_time_series_data_async_pager(): +async def test_read_tensorboard_blob_data_async( + transport: str = "grpc_asyncio", + request_type=tensorboard_service.ReadTensorboardBlobDataRequest, +): client = TensorboardServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.export_tensorboard_time_series_data), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.read_tensorboard_blob_data), "__call__" ) as call: - # Set the response to a series of pages. - call.side_effect = ( - tensorboard_service.ExportTensorboardTimeSeriesDataResponse( - time_series_data_points=[ - tensorboard_data.TimeSeriesDataPoint(), - tensorboard_data.TimeSeriesDataPoint(), - tensorboard_data.TimeSeriesDataPoint(), - ], - next_page_token="abc", - ), - tensorboard_service.ExportTensorboardTimeSeriesDataResponse( - time_series_data_points=[], next_page_token="def", - ), - tensorboard_service.ExportTensorboardTimeSeriesDataResponse( - time_series_data_points=[tensorboard_data.TimeSeriesDataPoint(),], - next_page_token="ghi", - ), - tensorboard_service.ExportTensorboardTimeSeriesDataResponse( - time_series_data_points=[ - tensorboard_data.TimeSeriesDataPoint(), - tensorboard_data.TimeSeriesDataPoint(), - ], - ), - RuntimeError, + # Designate an appropriate return value for the call. + call.return_value = mock.Mock(aio.UnaryStreamCall, autospec=True) + call.return_value.read = mock.AsyncMock( + side_effect=[tensorboard_service.ReadTensorboardBlobDataResponse()] ) - async_pager = await client.export_tensorboard_time_series_data(request={},) - assert async_pager.next_page_token == "abc" - responses = [] - async for response in async_pager: - responses.append(response) + response = await client.read_tensorboard_blob_data(request) - assert len(responses) == 6 - assert all( - isinstance(i, tensorboard_data.TimeSeriesDataPoint) for i in responses - ) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.ReadTensorboardBlobDataRequest() + + # Establish that the response is the type that we expect. + message = await response.read() + assert isinstance(message, tensorboard_service.ReadTensorboardBlobDataResponse) @pytest.mark.asyncio -async def test_export_tensorboard_time_series_data_async_pages(): - client = TensorboardServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials, +async def test_read_tensorboard_blob_data_async_from_dict(): + await test_read_tensorboard_blob_data_async(request_type=dict) + + +def test_read_tensorboard_blob_data_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), ) + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.ReadTensorboardBlobDataRequest() + + request.time_series = "time_series_value" + # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client.transport.export_tensorboard_time_series_data), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.read_tensorboard_blob_data), "__call__" ) as call: - # Set the response to a series of pages. - call.side_effect = ( - tensorboard_service.ExportTensorboardTimeSeriesDataResponse( - time_series_data_points=[ - tensorboard_data.TimeSeriesDataPoint(), - tensorboard_data.TimeSeriesDataPoint(), - tensorboard_data.TimeSeriesDataPoint(), - ], - next_page_token="abc", - ), - tensorboard_service.ExportTensorboardTimeSeriesDataResponse( - time_series_data_points=[], next_page_token="def", - ), - tensorboard_service.ExportTensorboardTimeSeriesDataResponse( - time_series_data_points=[tensorboard_data.TimeSeriesDataPoint(),], - next_page_token="ghi", - ), - tensorboard_service.ExportTensorboardTimeSeriesDataResponse( - time_series_data_points=[ - tensorboard_data.TimeSeriesDataPoint(), - tensorboard_data.TimeSeriesDataPoint(), - ], - ), - RuntimeError, + call.return_value = iter( + [tensorboard_service.ReadTensorboardBlobDataResponse()] ) - pages = [] - async for page_ in ( - await client.export_tensorboard_time_series_data(request={}) - ).pages: - pages.append(page_) - for page_, token in zip(pages, ["abc", "def", "ghi", ""]): - assert page_.raw_page.next_page_token == token + client.read_tensorboard_blob_data(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request -def test_credentials_transport_error(): - # It is an error to provide credentials and a transport instance. - transport = transports.TensorboardServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - with pytest.raises(ValueError): - client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, - ) + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "time_series=time_series_value", + ) in kw["metadata"] - # It is an error to provide a credentials file and a transport instance. - transport = transports.TensorboardServiceGrpcTransport( + +@pytest.mark.asyncio +async def test_read_tensorboard_blob_data_field_headers_async(): + client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) - with pytest.raises(ValueError): - client = TensorboardServiceClient( - client_options={"credentials_file": "credentials.json"}, - transport=transport, + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.ReadTensorboardBlobDataRequest() + + request.time_series = "time_series_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.read_tensorboard_blob_data), "__call__" + ) as call: + call.return_value = mock.Mock(aio.UnaryStreamCall, autospec=True) + call.return_value.read = mock.AsyncMock( + side_effect=[tensorboard_service.ReadTensorboardBlobDataResponse()] ) + await client.read_tensorboard_blob_data(request) - # It is an error to provide scopes and a transport instance. - transport = transports.TensorboardServiceGrpcTransport( + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "time_series=time_series_value", + ) in kw["metadata"] + + +def test_read_tensorboard_blob_data_flattened(): + client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) - with pytest.raises(ValueError): - client = TensorboardServiceClient( - client_options={"scopes": ["1", "2"]}, transport=transport, + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.read_tensorboard_blob_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iter( + [tensorboard_service.ReadTensorboardBlobDataResponse()] + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.read_tensorboard_blob_data( + time_series="time_series_value", ) + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].time_series + mock_val = "time_series_value" + assert arg == mock_val + -def test_transport_instance(): - # A client may be instantiated with a custom transport instance. - transport = transports.TensorboardServiceGrpcTransport( +def test_read_tensorboard_blob_data_flattened_error(): + client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), ) - client = TensorboardServiceClient(transport=transport) - assert client.transport is transport + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.read_tensorboard_blob_data( + tensorboard_service.ReadTensorboardBlobDataRequest(), + time_series="time_series_value", + ) -def test_transport_get_channel(): - # A client may be instantiated with a custom transport instance. - transport = transports.TensorboardServiceGrpcTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - channel = transport.grpc_channel - assert channel - transport = transports.TensorboardServiceGrpcAsyncIOTransport( +@pytest.mark.asyncio +async def test_read_tensorboard_blob_data_flattened_async(): + client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) - channel = transport.grpc_channel - assert channel + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.read_tensorboard_blob_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iter( + [tensorboard_service.ReadTensorboardBlobDataResponse()] + ) + + call.return_value = mock.Mock(aio.UnaryStreamCall, autospec=True) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.read_tensorboard_blob_data( + time_series="time_series_value", + ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.TensorboardServiceGrpcTransport, - transports.TensorboardServiceGrpcAsyncIOTransport, - ], -) -def test_transport_adc(transport_class): - # Test default credentials are used if not provided. - with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class() - adc.assert_called_once() - + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].time_series + mock_val = "time_series_value" + assert arg == mock_val -def test_transport_grpc_default(): - # A client should use the gRPC transport by default. - client = TensorboardServiceClient( + +@pytest.mark.asyncio +async def test_read_tensorboard_blob_data_flattened_error_async(): + client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), ) - assert isinstance(client.transport, transports.TensorboardServiceGrpcTransport,) - -def test_tensorboard_service_base_transport_error(): - # Passing both a credentials object and credentials_file should raise an error - with pytest.raises(core_exceptions.DuplicateCredentialArgs): - transport = transports.TensorboardServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), - credentials_file="credentials.json", + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.read_tensorboard_blob_data( + tensorboard_service.ReadTensorboardBlobDataRequest(), + time_series="time_series_value", ) -def test_tensorboard_service_base_transport(): - # Instantiate the base transport. - with mock.patch( - "google.cloud.aiplatform_v1beta1.services.tensorboard_service.transports.TensorboardServiceTransport.__init__" - ) as Transport: - Transport.return_value = None - transport = transports.TensorboardServiceTransport( - credentials=ga_credentials.AnonymousCredentials(), - ) - - # Every method on the transport should just blindly - # raise NotImplementedError. - methods = ( - "create_tensorboard", - "get_tensorboard", - "update_tensorboard", - "list_tensorboards", - "delete_tensorboard", - "create_tensorboard_experiment", - "get_tensorboard_experiment", - "update_tensorboard_experiment", - "list_tensorboard_experiments", - "delete_tensorboard_experiment", - "create_tensorboard_run", - "get_tensorboard_run", - "update_tensorboard_run", - "list_tensorboard_runs", - "delete_tensorboard_run", - "create_tensorboard_time_series", - "get_tensorboard_time_series", - "update_tensorboard_time_series", - "list_tensorboard_time_series", - "delete_tensorboard_time_series", - "read_tensorboard_time_series_data", - "read_tensorboard_blob_data", - "write_tensorboard_run_data", - "export_tensorboard_time_series_data", +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.WriteTensorboardExperimentDataRequest, + dict, + ], +) +def test_write_tensorboard_experiment_data(request_type, transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - for method in methods: - with pytest.raises(NotImplementedError): - getattr(transport, method)(request=object()) - - # Additionally, the LRO client (a property) should - # also raise NotImplementedError - with pytest.raises(NotImplementedError): - transport.operations_client + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() -@requires_google_auth_gte_1_25_0 -def test_tensorboard_service_base_transport_with_credentials_file(): - # Instantiate the base transport with a credentials file + # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.aiplatform_v1beta1.services.tensorboard_service.transports.TensorboardServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.TensorboardServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=None, - default_scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) + type(client.transport.write_tensorboard_experiment_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_service.WriteTensorboardExperimentDataResponse() + response = client.write_tensorboard_experiment_data(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.WriteTensorboardExperimentDataRequest() -@requires_google_auth_lt_1_25_0 -def test_tensorboard_service_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file + # Establish that the response is the type that we expect. + assert isinstance( + response, tensorboard_service.WriteTensorboardExperimentDataResponse + ) + + +def test_write_tensorboard_experiment_data_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.aiplatform_v1beta1.services.tensorboard_service.transports.TensorboardServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.TensorboardServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) + type(client.transport.write_tensorboard_experiment_data), "__call__" + ) as call: + client.write_tensorboard_experiment_data() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.WriteTensorboardExperimentDataRequest() -def test_tensorboard_service_base_transport_with_adc(): - # Test the default credentials are used if credentials and credentials_file are None. - with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( - "google.cloud.aiplatform_v1beta1.services.tensorboard_service.transports.TensorboardServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.TensorboardServiceTransport() - adc.assert_called_once() +@pytest.mark.asyncio +async def test_write_tensorboard_experiment_data_async( + transport: str = "grpc_asyncio", + request_type=tensorboard_service.WriteTensorboardExperimentDataRequest, +): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() -@requires_google_auth_gte_1_25_0 -def test_tensorboard_service_auth_adc(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - TensorboardServiceClient() - adc.assert_called_once_with( - scopes=None, - default_scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.write_tensorboard_experiment_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.WriteTensorboardExperimentDataResponse() ) + response = await client.write_tensorboard_experiment_data(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.WriteTensorboardExperimentDataRequest() -@requires_google_auth_lt_1_25_0 -def test_tensorboard_service_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - TensorboardServiceClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) + # Establish that the response is the type that we expect. + assert isinstance( + response, tensorboard_service.WriteTensorboardExperimentDataResponse + ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.TensorboardServiceGrpcTransport, - transports.TensorboardServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_gte_1_25_0 -def test_tensorboard_service_transport_auth_adc(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - adc.assert_called_once_with( - scopes=["1", "2"], - default_scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) +@pytest.mark.asyncio +async def test_write_tensorboard_experiment_data_async_from_dict(): + await test_write_tensorboard_experiment_data_async(request_type=dict) -@pytest.mark.parametrize( - "transport_class", - [ - transports.TensorboardServiceGrpcTransport, - transports.TensorboardServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_tensorboard_service_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) +def test_write_tensorboard_experiment_data_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.WriteTensorboardExperimentDataRequest() -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.TensorboardServiceGrpcTransport, grpc_helpers), - (transports.TensorboardServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_gte_1_26_0 -def test_tensorboard_service_transport_create_channel(transport_class, grpc_helpers): - # If credentials and host are not provided, the transport class should use - # ADC credentials. + request.tensorboard_experiment = "tensorboard_experiment_value" + + # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class(quota_project_id="octopus", scopes=["1", "2"]) + type(client.transport.write_tensorboard_experiment_data), "__call__" + ) as call: + call.return_value = tensorboard_service.WriteTensorboardExperimentDataResponse() + client.write_tensorboard_experiment_data(request) - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - default_scopes=("https://www.googleapis.com/auth/cloud-platform",), - scopes=["1", "2"], - default_host="aiplatform.googleapis.com", - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "tensorboard_experiment=tensorboard_experiment_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_write_tensorboard_experiment_data_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.WriteTensorboardExperimentDataRequest() + + request.tensorboard_experiment = "tensorboard_experiment_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.write_tensorboard_experiment_data), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.WriteTensorboardExperimentDataResponse() ) + await client.write_tensorboard_experiment_data(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.TensorboardServiceGrpcTransport, grpc_helpers), - (transports.TensorboardServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_tensorboard_service_transport_create_channel_old_api_core( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "tensorboard_experiment=tensorboard_experiment_value", + ) in kw["metadata"] + + +def test_write_tensorboard_experiment_data_flattened(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class(quota_project_id="octopus") + type(client.transport.write_tensorboard_experiment_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_service.WriteTensorboardExperimentDataResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.write_tensorboard_experiment_data( + tensorboard_experiment="tensorboard_experiment_value", + write_run_data_requests=[ + tensorboard_service.WriteTensorboardRunDataRequest( + tensorboard_run="tensorboard_run_value" + ) + ], + ) - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].tensorboard_experiment + mock_val = "tensorboard_experiment_value" + assert arg == mock_val + arg = args[0].write_run_data_requests + mock_val = [ + tensorboard_service.WriteTensorboardRunDataRequest( + tensorboard_run="tensorboard_run_value" + ) + ] + assert arg == mock_val + + +def test_write_tensorboard_experiment_data_flattened_error(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.write_tensorboard_experiment_data( + tensorboard_service.WriteTensorboardExperimentDataRequest(), + tensorboard_experiment="tensorboard_experiment_value", + write_run_data_requests=[ + tensorboard_service.WriteTensorboardRunDataRequest( + tensorboard_run="tensorboard_run_value" + ) ], ) -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.TensorboardServiceGrpcTransport, grpc_helpers), - (transports.TensorboardServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_tensorboard_service_transport_create_channel_user_scopes( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. +@pytest.mark.asyncio +async def test_write_tensorboard_experiment_data_flattened_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) + type(client.transport.write_tensorboard_experiment_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_service.WriteTensorboardExperimentDataResponse() - transport_class(quota_project_id="octopus", scopes=["1", "2"]) + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.WriteTensorboardExperimentDataResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.write_tensorboard_experiment_data( + tensorboard_experiment="tensorboard_experiment_value", + write_run_data_requests=[ + tensorboard_service.WriteTensorboardRunDataRequest( + tensorboard_run="tensorboard_run_value" + ) + ], + ) - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=["1", "2"], - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].tensorboard_experiment + mock_val = "tensorboard_experiment_value" + assert arg == mock_val + arg = args[0].write_run_data_requests + mock_val = [ + tensorboard_service.WriteTensorboardRunDataRequest( + tensorboard_run="tensorboard_run_value" + ) + ] + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_write_tensorboard_experiment_data_flattened_error_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.write_tensorboard_experiment_data( + tensorboard_service.WriteTensorboardExperimentDataRequest(), + tensorboard_experiment="tensorboard_experiment_value", + write_run_data_requests=[ + tensorboard_service.WriteTensorboardRunDataRequest( + tensorboard_run="tensorboard_run_value" + ) ], ) @pytest.mark.parametrize( - "transport_class", + "request_type", [ - transports.TensorboardServiceGrpcTransport, - transports.TensorboardServiceGrpcAsyncIOTransport, + tensorboard_service.WriteTensorboardRunDataRequest, + dict, ], ) -def test_tensorboard_service_grpc_transport_client_cert_source_for_mtls( - transport_class, +def test_write_tensorboard_run_data(request_type, transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.write_tensorboard_run_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_service.WriteTensorboardRunDataResponse() + response = client.write_tensorboard_run_data(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.WriteTensorboardRunDataRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, tensorboard_service.WriteTensorboardRunDataResponse) + + +def test_write_tensorboard_run_data_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.write_tensorboard_run_data), "__call__" + ) as call: + client.write_tensorboard_run_data() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.WriteTensorboardRunDataRequest() + + +@pytest.mark.asyncio +async def test_write_tensorboard_run_data_async( + transport: str = "grpc_asyncio", + request_type=tensorboard_service.WriteTensorboardRunDataRequest, ): - cred = ga_credentials.AnonymousCredentials() + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) - # Check ssl_channel_credentials is used if provided. - with mock.patch.object(transport_class, "create_channel") as mock_create_channel: - mock_ssl_channel_creds = mock.Mock() - transport_class( - host="squid.clam.whelk", - credentials=cred, - ssl_channel_credentials=mock_ssl_channel_creds, - ) - mock_create_channel.assert_called_once_with( - "squid.clam.whelk:443", - credentials=cred, - credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=mock_ssl_channel_creds, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.write_tensorboard_run_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.WriteTensorboardRunDataResponse() ) + response = await client.write_tensorboard_run_data(request) - # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls - # is used. - with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): - with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: - transport_class( - credentials=cred, - client_cert_source_for_mtls=client_cert_source_callback, - ) - expected_cert, expected_key = client_cert_source_callback() - mock_ssl_cred.assert_called_once_with( + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.WriteTensorboardRunDataRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, tensorboard_service.WriteTensorboardRunDataResponse) + + +@pytest.mark.asyncio +async def test_write_tensorboard_run_data_async_from_dict(): + await test_write_tensorboard_run_data_async(request_type=dict) + + +def test_write_tensorboard_run_data_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.WriteTensorboardRunDataRequest() + + request.tensorboard_run = "tensorboard_run_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.write_tensorboard_run_data), "__call__" + ) as call: + call.return_value = tensorboard_service.WriteTensorboardRunDataResponse() + client.write_tensorboard_run_data(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "tensorboard_run=tensorboard_run_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_write_tensorboard_run_data_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.WriteTensorboardRunDataRequest() + + request.tensorboard_run = "tensorboard_run_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.write_tensorboard_run_data), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.WriteTensorboardRunDataResponse() + ) + await client.write_tensorboard_run_data(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "tensorboard_run=tensorboard_run_value", + ) in kw["metadata"] + + +def test_write_tensorboard_run_data_flattened(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.write_tensorboard_run_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_service.WriteTensorboardRunDataResponse() + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.write_tensorboard_run_data( + tensorboard_run="tensorboard_run_value", + time_series_data=[ + tensorboard_data.TimeSeriesData( + tensorboard_time_series_id="tensorboard_time_series_id_value" + ) + ], + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].tensorboard_run + mock_val = "tensorboard_run_value" + assert arg == mock_val + arg = args[0].time_series_data + mock_val = [ + tensorboard_data.TimeSeriesData( + tensorboard_time_series_id="tensorboard_time_series_id_value" + ) + ] + assert arg == mock_val + + +def test_write_tensorboard_run_data_flattened_error(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.write_tensorboard_run_data( + tensorboard_service.WriteTensorboardRunDataRequest(), + tensorboard_run="tensorboard_run_value", + time_series_data=[ + tensorboard_data.TimeSeriesData( + tensorboard_time_series_id="tensorboard_time_series_id_value" + ) + ], + ) + + +@pytest.mark.asyncio +async def test_write_tensorboard_run_data_flattened_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.write_tensorboard_run_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_service.WriteTensorboardRunDataResponse() + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.WriteTensorboardRunDataResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.write_tensorboard_run_data( + tensorboard_run="tensorboard_run_value", + time_series_data=[ + tensorboard_data.TimeSeriesData( + tensorboard_time_series_id="tensorboard_time_series_id_value" + ) + ], + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].tensorboard_run + mock_val = "tensorboard_run_value" + assert arg == mock_val + arg = args[0].time_series_data + mock_val = [ + tensorboard_data.TimeSeriesData( + tensorboard_time_series_id="tensorboard_time_series_id_value" + ) + ] + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_write_tensorboard_run_data_flattened_error_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.write_tensorboard_run_data( + tensorboard_service.WriteTensorboardRunDataRequest(), + tensorboard_run="tensorboard_run_value", + time_series_data=[ + tensorboard_data.TimeSeriesData( + tensorboard_time_series_id="tensorboard_time_series_id_value" + ) + ], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + tensorboard_service.ExportTensorboardTimeSeriesDataRequest, + dict, + ], +) +def test_export_tensorboard_time_series_data(request_type, transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.export_tensorboard_time_series_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = tensorboard_service.ExportTensorboardTimeSeriesDataResponse( + next_page_token="next_page_token_value", + ) + response = client.export_tensorboard_time_series_data(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.ExportTensorboardTimeSeriesDataRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ExportTensorboardTimeSeriesDataPager) + assert response.next_page_token == "next_page_token_value" + + +def test_export_tensorboard_time_series_data_empty_call(): + # This test is a coverage failsafe to make sure that totally empty calls, + # i.e. request == None and no flattened fields passed, work. + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.export_tensorboard_time_series_data), "__call__" + ) as call: + client.export_tensorboard_time_series_data() + call.assert_called() + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.ExportTensorboardTimeSeriesDataRequest() + + +@pytest.mark.asyncio +async def test_export_tensorboard_time_series_data_async( + transport: str = "grpc_asyncio", + request_type=tensorboard_service.ExportTensorboardTimeSeriesDataRequest, +): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = request_type() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.export_tensorboard_time_series_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.ExportTensorboardTimeSeriesDataResponse( + next_page_token="next_page_token_value", + ) + ) + response = await client.export_tensorboard_time_series_data(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == tensorboard_service.ExportTensorboardTimeSeriesDataRequest() + + # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ExportTensorboardTimeSeriesDataAsyncPager) + assert response.next_page_token == "next_page_token_value" + + +@pytest.mark.asyncio +async def test_export_tensorboard_time_series_data_async_from_dict(): + await test_export_tensorboard_time_series_data_async(request_type=dict) + + +def test_export_tensorboard_time_series_data_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.ExportTensorboardTimeSeriesDataRequest() + + request.tensorboard_time_series = "tensorboard_time_series_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.export_tensorboard_time_series_data), "__call__" + ) as call: + call.return_value = ( + tensorboard_service.ExportTensorboardTimeSeriesDataResponse() + ) + client.export_tensorboard_time_series_data(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "tensorboard_time_series=tensorboard_time_series_value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_export_tensorboard_time_series_data_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = tensorboard_service.ExportTensorboardTimeSeriesDataRequest() + + request.tensorboard_time_series = "tensorboard_time_series_value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.export_tensorboard_time_series_data), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.ExportTensorboardTimeSeriesDataResponse() + ) + await client.export_tensorboard_time_series_data(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "tensorboard_time_series=tensorboard_time_series_value", + ) in kw["metadata"] + + +def test_export_tensorboard_time_series_data_flattened(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.export_tensorboard_time_series_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = ( + tensorboard_service.ExportTensorboardTimeSeriesDataResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + client.export_tensorboard_time_series_data( + tensorboard_time_series="tensorboard_time_series_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + arg = args[0].tensorboard_time_series + mock_val = "tensorboard_time_series_value" + assert arg == mock_val + + +def test_export_tensorboard_time_series_data_flattened_error(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + client.export_tensorboard_time_series_data( + tensorboard_service.ExportTensorboardTimeSeriesDataRequest(), + tensorboard_time_series="tensorboard_time_series_value", + ) + + +@pytest.mark.asyncio +async def test_export_tensorboard_time_series_data_flattened_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.export_tensorboard_time_series_data), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = ( + tensorboard_service.ExportTensorboardTimeSeriesDataResponse() + ) + + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + tensorboard_service.ExportTensorboardTimeSeriesDataResponse() + ) + # Call the method with a truthy value for each flattened field, + # using the keyword arguments to the method. + response = await client.export_tensorboard_time_series_data( + tensorboard_time_series="tensorboard_time_series_value", + ) + + # Establish that the underlying call was made with the expected + # request object values. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + arg = args[0].tensorboard_time_series + mock_val = "tensorboard_time_series_value" + assert arg == mock_val + + +@pytest.mark.asyncio +async def test_export_tensorboard_time_series_data_flattened_error_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Attempting to call a method with both a request object and flattened + # fields is an error. + with pytest.raises(ValueError): + await client.export_tensorboard_time_series_data( + tensorboard_service.ExportTensorboardTimeSeriesDataRequest(), + tensorboard_time_series="tensorboard_time_series_value", + ) + + +def test_export_tensorboard_time_series_data_pager(transport_name: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.export_tensorboard_time_series_data), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + tensorboard_service.ExportTensorboardTimeSeriesDataResponse( + time_series_data_points=[ + tensorboard_data.TimeSeriesDataPoint(), + tensorboard_data.TimeSeriesDataPoint(), + tensorboard_data.TimeSeriesDataPoint(), + ], + next_page_token="abc", + ), + tensorboard_service.ExportTensorboardTimeSeriesDataResponse( + time_series_data_points=[], + next_page_token="def", + ), + tensorboard_service.ExportTensorboardTimeSeriesDataResponse( + time_series_data_points=[ + tensorboard_data.TimeSeriesDataPoint(), + ], + next_page_token="ghi", + ), + tensorboard_service.ExportTensorboardTimeSeriesDataResponse( + time_series_data_points=[ + tensorboard_data.TimeSeriesDataPoint(), + tensorboard_data.TimeSeriesDataPoint(), + ], + ), + RuntimeError, + ) + + metadata = () + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("tensorboard_time_series", ""),) + ), + ) + pager = client.export_tensorboard_time_series_data(request={}) + + assert pager._metadata == metadata + + results = list(pager) + assert len(results) == 6 + assert all(isinstance(i, tensorboard_data.TimeSeriesDataPoint) for i in results) + + +def test_export_tensorboard_time_series_data_pages(transport_name: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.export_tensorboard_time_series_data), "__call__" + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + tensorboard_service.ExportTensorboardTimeSeriesDataResponse( + time_series_data_points=[ + tensorboard_data.TimeSeriesDataPoint(), + tensorboard_data.TimeSeriesDataPoint(), + tensorboard_data.TimeSeriesDataPoint(), + ], + next_page_token="abc", + ), + tensorboard_service.ExportTensorboardTimeSeriesDataResponse( + time_series_data_points=[], + next_page_token="def", + ), + tensorboard_service.ExportTensorboardTimeSeriesDataResponse( + time_series_data_points=[ + tensorboard_data.TimeSeriesDataPoint(), + ], + next_page_token="ghi", + ), + tensorboard_service.ExportTensorboardTimeSeriesDataResponse( + time_series_data_points=[ + tensorboard_data.TimeSeriesDataPoint(), + tensorboard_data.TimeSeriesDataPoint(), + ], + ), + RuntimeError, + ) + pages = list(client.export_tensorboard_time_series_data(request={}).pages) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +@pytest.mark.asyncio +async def test_export_tensorboard_time_series_data_async_pager(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.export_tensorboard_time_series_data), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + tensorboard_service.ExportTensorboardTimeSeriesDataResponse( + time_series_data_points=[ + tensorboard_data.TimeSeriesDataPoint(), + tensorboard_data.TimeSeriesDataPoint(), + tensorboard_data.TimeSeriesDataPoint(), + ], + next_page_token="abc", + ), + tensorboard_service.ExportTensorboardTimeSeriesDataResponse( + time_series_data_points=[], + next_page_token="def", + ), + tensorboard_service.ExportTensorboardTimeSeriesDataResponse( + time_series_data_points=[ + tensorboard_data.TimeSeriesDataPoint(), + ], + next_page_token="ghi", + ), + tensorboard_service.ExportTensorboardTimeSeriesDataResponse( + time_series_data_points=[ + tensorboard_data.TimeSeriesDataPoint(), + tensorboard_data.TimeSeriesDataPoint(), + ], + ), + RuntimeError, + ) + async_pager = await client.export_tensorboard_time_series_data( + request={}, + ) + assert async_pager.next_page_token == "abc" + responses = [] + async for response in async_pager: # pragma: no branch + responses.append(response) + + assert len(responses) == 6 + assert all( + isinstance(i, tensorboard_data.TimeSeriesDataPoint) for i in responses + ) + + +@pytest.mark.asyncio +async def test_export_tensorboard_time_series_data_async_pages(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.export_tensorboard_time_series_data), + "__call__", + new_callable=mock.AsyncMock, + ) as call: + # Set the response to a series of pages. + call.side_effect = ( + tensorboard_service.ExportTensorboardTimeSeriesDataResponse( + time_series_data_points=[ + tensorboard_data.TimeSeriesDataPoint(), + tensorboard_data.TimeSeriesDataPoint(), + tensorboard_data.TimeSeriesDataPoint(), + ], + next_page_token="abc", + ), + tensorboard_service.ExportTensorboardTimeSeriesDataResponse( + time_series_data_points=[], + next_page_token="def", + ), + tensorboard_service.ExportTensorboardTimeSeriesDataResponse( + time_series_data_points=[ + tensorboard_data.TimeSeriesDataPoint(), + ], + next_page_token="ghi", + ), + tensorboard_service.ExportTensorboardTimeSeriesDataResponse( + time_series_data_points=[ + tensorboard_data.TimeSeriesDataPoint(), + tensorboard_data.TimeSeriesDataPoint(), + ], + ), + RuntimeError, + ) + pages = [] + async for page_ in ( + await client.export_tensorboard_time_series_data(request={}) + ).pages: # pragma: no branch + pages.append(page_) + for page_, token in zip(pages, ["abc", "def", "ghi", ""]): + assert page_.raw_page.next_page_token == token + + +def test_credentials_transport_error(): + # It is an error to provide credentials and a transport instance. + transport = transports.TensorboardServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # It is an error to provide a credentials file and a transport instance. + transport = transports.TensorboardServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = TensorboardServiceClient( + client_options={"credentials_file": "credentials.json"}, + transport=transport, + ) + + # It is an error to provide an api_key and a transport instance. + transport = transports.TensorboardServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = TensorboardServiceClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = TensorboardServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + + # It is an error to provide scopes and a transport instance. + transport = transports.TensorboardServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + with pytest.raises(ValueError): + client = TensorboardServiceClient( + client_options={"scopes": ["1", "2"]}, + transport=transport, + ) + + +def test_transport_instance(): + # A client may be instantiated with a custom transport instance. + transport = transports.TensorboardServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + client = TensorboardServiceClient(transport=transport) + assert client.transport is transport + + +def test_transport_get_channel(): + # A client may be instantiated with a custom transport instance. + transport = transports.TensorboardServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + transport = transports.TensorboardServiceGrpcAsyncIOTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + channel = transport.grpc_channel + assert channel + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.TensorboardServiceGrpcTransport, + transports.TensorboardServiceGrpcAsyncIOTransport, + ], +) +def test_transport_adc(transport_class): + # Test default credentials are used if not provided. + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class() + adc.assert_called_once() + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = TensorboardServiceClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + +def test_transport_grpc_default(): + # A client should use the gRPC transport by default. + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.TensorboardServiceGrpcTransport, + ) + + +def test_tensorboard_service_base_transport_error(): + # Passing both a credentials object and credentials_file should raise an error + with pytest.raises(core_exceptions.DuplicateCredentialArgs): + transport = transports.TensorboardServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + credentials_file="credentials.json", + ) + + +def test_tensorboard_service_base_transport(): + # Instantiate the base transport. + with mock.patch( + "google.cloud.aiplatform_v1beta1.services.tensorboard_service.transports.TensorboardServiceTransport.__init__" + ) as Transport: + Transport.return_value = None + transport = transports.TensorboardServiceTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Every method on the transport should just blindly + # raise NotImplementedError. + methods = ( + "create_tensorboard", + "get_tensorboard", + "update_tensorboard", + "list_tensorboards", + "delete_tensorboard", + "create_tensorboard_experiment", + "get_tensorboard_experiment", + "update_tensorboard_experiment", + "list_tensorboard_experiments", + "delete_tensorboard_experiment", + "create_tensorboard_run", + "batch_create_tensorboard_runs", + "get_tensorboard_run", + "update_tensorboard_run", + "list_tensorboard_runs", + "delete_tensorboard_run", + "batch_create_tensorboard_time_series", + "create_tensorboard_time_series", + "get_tensorboard_time_series", + "update_tensorboard_time_series", + "list_tensorboard_time_series", + "delete_tensorboard_time_series", + "batch_read_tensorboard_time_series_data", + "read_tensorboard_time_series_data", + "read_tensorboard_blob_data", + "write_tensorboard_experiment_data", + "write_tensorboard_run_data", + "export_tensorboard_time_series_data", + "set_iam_policy", + "get_iam_policy", + "test_iam_permissions", + "get_location", + "list_locations", + "get_operation", + "wait_operation", + "cancel_operation", + "delete_operation", + "list_operations", + ) + for method in methods: + with pytest.raises(NotImplementedError): + getattr(transport, method)(request=object()) + + with pytest.raises(NotImplementedError): + transport.close() + + # Additionally, the LRO client (a property) should + # also raise NotImplementedError + with pytest.raises(NotImplementedError): + transport.operations_client + + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + + +def test_tensorboard_service_base_transport_with_credentials_file(): + # Instantiate the base transport with a credentials file + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch( + "google.cloud.aiplatform_v1beta1.services.tensorboard_service.transports.TensorboardServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.TensorboardServiceTransport( + credentials_file="credentials.json", + quota_project_id="octopus", + ) + load_creds.assert_called_once_with( + "credentials.json", + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +def test_tensorboard_service_base_transport_with_adc(): + # Test the default credentials are used if credentials and credentials_file are None. + with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( + "google.cloud.aiplatform_v1beta1.services.tensorboard_service.transports.TensorboardServiceTransport._prep_wrapped_messages" + ) as Transport: + Transport.return_value = None + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport = transports.TensorboardServiceTransport() + adc.assert_called_once() + + +def test_tensorboard_service_auth_adc(): + # If no credentials are provided, we should use ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + TensorboardServiceClient() + adc.assert_called_once_with( + scopes=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id=None, + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.TensorboardServiceGrpcTransport, + transports.TensorboardServiceGrpcAsyncIOTransport, + ], +) +def test_tensorboard_service_transport_auth_adc(transport_class): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object(google.auth, "default", autospec=True) as adc: + adc.return_value = (ga_credentials.AnonymousCredentials(), None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + adc.assert_called_once_with( + scopes=["1", "2"], + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + quota_project_id="octopus", + ) + + +@pytest.mark.parametrize( + "transport_class,grpc_helpers", + [ + (transports.TensorboardServiceGrpcTransport, grpc_helpers), + (transports.TensorboardServiceGrpcAsyncIOTransport, grpc_helpers_async), + ], +) +def test_tensorboard_service_transport_create_channel(transport_class, grpc_helpers): + # If credentials and host are not provided, the transport class should use + # ADC credentials. + with mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel", autospec=True + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + adc.return_value = (creds, None) + transport_class(quota_project_id="octopus", scopes=["1", "2"]) + + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=creds, + credentials_file=None, + quota_project_id="octopus", + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=["1", "2"], + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "transport_class", + [ + transports.TensorboardServiceGrpcTransport, + transports.TensorboardServiceGrpcAsyncIOTransport, + ], +) +def test_tensorboard_service_grpc_transport_client_cert_source_for_mtls( + transport_class, +): + cred = ga_credentials.AnonymousCredentials() + + # Check ssl_channel_credentials is used if provided. + with mock.patch.object(transport_class, "create_channel") as mock_create_channel: + mock_ssl_channel_creds = mock.Mock() + transport_class( + host="squid.clam.whelk", + credentials=cred, + ssl_channel_credentials=mock_ssl_channel_creds, + ) + mock_create_channel.assert_called_once_with( + "squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_channel_creds, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + # Check if ssl_channel_credentials is not provided, then client_cert_source_for_mtls + # is used. + with mock.patch.object(transport_class, "create_channel", return_value=mock.Mock()): + with mock.patch("grpc.ssl_channel_credentials") as mock_ssl_cred: + transport_class( + credentials=cred, + client_cert_source_for_mtls=client_cert_source_callback, + ) + expected_cert, expected_key = client_cert_source_callback() + mock_ssl_cred.assert_called_once_with( certificate_chain=expected_cert, private_key=expected_key ) -def test_tensorboard_service_host_no_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_tensorboard_service_host_no_port(transport_name): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions( + api_endpoint="aiplatform.googleapis.com" + ), + transport=transport_name, + ) + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_tensorboard_service_host_with_port(transport_name): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_options=client_options.ClientOptions( + api_endpoint="aiplatform.googleapis.com:8000" + ), + transport=transport_name, + ) + assert client.transport._host == ("aiplatform.googleapis.com:8000") + + +def test_tensorboard_service_grpc_transport_channel(): + channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.TensorboardServiceGrpcTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +def test_tensorboard_service_grpc_asyncio_transport_channel(): + channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) + + # Check that channel is used if provided. + transport = transports.TensorboardServiceGrpcAsyncIOTransport( + host="squid.clam.whelk", + channel=channel, + ) + assert transport.grpc_channel == channel + assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize( + "transport_class", + [ + transports.TensorboardServiceGrpcTransport, + transports.TensorboardServiceGrpcAsyncIOTransport, + ], +) +def test_tensorboard_service_transport_channel_mtls_with_client_cert_source( + transport_class, +): + with mock.patch( + "grpc.ssl_channel_credentials", autospec=True + ) as grpc_ssl_channel_cred: + with mock.patch.object( + transport_class, "create_channel" + ) as grpc_create_channel: + mock_ssl_cred = mock.Mock() + grpc_ssl_channel_cred.return_value = mock_ssl_cred + + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + + cred = ga_credentials.AnonymousCredentials() + with pytest.warns(DeprecationWarning): + with mock.patch.object(google.auth, "default") as adc: + adc.return_value = (cred, None) + transport = transport_class( + host="squid.clam.whelk", + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=client_cert_source_callback, + ) + adc.assert_called_once() + + grpc_ssl_channel_cred.assert_called_once_with( + certificate_chain=b"cert bytes", private_key=b"key bytes" + ) + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred + + +# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are +# removed from grpc/grpc_asyncio transport constructor. +@pytest.mark.parametrize( + "transport_class", + [ + transports.TensorboardServiceGrpcTransport, + transports.TensorboardServiceGrpcAsyncIOTransport, + ], +) +def test_tensorboard_service_transport_channel_mtls_with_adc(transport_class): + mock_ssl_cred = mock.Mock() + with mock.patch.multiple( + "google.auth.transport.grpc.SslCredentials", + __init__=mock.Mock(return_value=None), + ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), + ): + with mock.patch.object( + transport_class, "create_channel" + ) as grpc_create_channel: + mock_grpc_channel = mock.Mock() + grpc_create_channel.return_value = mock_grpc_channel + mock_cred = mock.Mock() + + with pytest.warns(DeprecationWarning): + transport = transport_class( + host="squid.clam.whelk", + credentials=mock_cred, + api_mtls_endpoint="mtls.squid.clam.whelk", + client_cert_source=None, + ) + + grpc_create_channel.assert_called_once_with( + "mtls.squid.clam.whelk:443", + credentials=mock_cred, + credentials_file=None, + scopes=None, + ssl_credentials=mock_ssl_cred, + quota_project_id=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + assert transport.grpc_channel == mock_grpc_channel + + +def test_tensorboard_service_grpc_lro_client(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_tensorboard_service_grpc_lro_async_client(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + transport = client.transport + + # Ensure that we have a api-core operations client. + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) + + # Ensure that subsequent calls to the property send the exact same object. + assert transport.operations_client is transport.operations_client + + +def test_tensorboard_path(): + project = "squid" + location = "clam" + tensorboard = "whelk" + expected = ( + "projects/{project}/locations/{location}/tensorboards/{tensorboard}".format( + project=project, + location=location, + tensorboard=tensorboard, + ) + ) + actual = TensorboardServiceClient.tensorboard_path(project, location, tensorboard) + assert expected == actual + + +def test_parse_tensorboard_path(): + expected = { + "project": "octopus", + "location": "oyster", + "tensorboard": "nudibranch", + } + path = TensorboardServiceClient.tensorboard_path(**expected) + + # Check that the path construction is reversible. + actual = TensorboardServiceClient.parse_tensorboard_path(path) + assert expected == actual + + +def test_tensorboard_experiment_path(): + project = "cuttlefish" + location = "mussel" + tensorboard = "winkle" + experiment = "nautilus" + expected = "projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}".format( + project=project, + location=location, + tensorboard=tensorboard, + experiment=experiment, + ) + actual = TensorboardServiceClient.tensorboard_experiment_path( + project, location, tensorboard, experiment + ) + assert expected == actual + + +def test_parse_tensorboard_experiment_path(): + expected = { + "project": "scallop", + "location": "abalone", + "tensorboard": "squid", + "experiment": "clam", + } + path = TensorboardServiceClient.tensorboard_experiment_path(**expected) + + # Check that the path construction is reversible. + actual = TensorboardServiceClient.parse_tensorboard_experiment_path(path) + assert expected == actual + + +def test_tensorboard_run_path(): + project = "whelk" + location = "octopus" + tensorboard = "oyster" + experiment = "nudibranch" + run = "cuttlefish" + expected = "projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}".format( + project=project, + location=location, + tensorboard=tensorboard, + experiment=experiment, + run=run, + ) + actual = TensorboardServiceClient.tensorboard_run_path( + project, location, tensorboard, experiment, run + ) + assert expected == actual + + +def test_parse_tensorboard_run_path(): + expected = { + "project": "mussel", + "location": "winkle", + "tensorboard": "nautilus", + "experiment": "scallop", + "run": "abalone", + } + path = TensorboardServiceClient.tensorboard_run_path(**expected) + + # Check that the path construction is reversible. + actual = TensorboardServiceClient.parse_tensorboard_run_path(path) + assert expected == actual + + +def test_tensorboard_time_series_path(): + project = "squid" + location = "clam" + tensorboard = "whelk" + experiment = "octopus" + run = "oyster" + time_series = "nudibranch" + expected = "projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}/timeSeries/{time_series}".format( + project=project, + location=location, + tensorboard=tensorboard, + experiment=experiment, + run=run, + time_series=time_series, + ) + actual = TensorboardServiceClient.tensorboard_time_series_path( + project, location, tensorboard, experiment, run, time_series + ) + assert expected == actual + + +def test_parse_tensorboard_time_series_path(): + expected = { + "project": "cuttlefish", + "location": "mussel", + "tensorboard": "winkle", + "experiment": "nautilus", + "run": "scallop", + "time_series": "abalone", + } + path = TensorboardServiceClient.tensorboard_time_series_path(**expected) + + # Check that the path construction is reversible. + actual = TensorboardServiceClient.parse_tensorboard_time_series_path(path) + assert expected == actual + + +def test_common_billing_account_path(): + billing_account = "squid" + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + actual = TensorboardServiceClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "clam", + } + path = TensorboardServiceClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = TensorboardServiceClient.parse_common_billing_account_path(path) + assert expected == actual + + +def test_common_folder_path(): + folder = "whelk" + expected = "folders/{folder}".format( + folder=folder, + ) + actual = TensorboardServiceClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "octopus", + } + path = TensorboardServiceClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = TensorboardServiceClient.parse_common_folder_path(path) + assert expected == actual + + +def test_common_organization_path(): + organization = "oyster" + expected = "organizations/{organization}".format( + organization=organization, + ) + actual = TensorboardServiceClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "nudibranch", + } + path = TensorboardServiceClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = TensorboardServiceClient.parse_common_organization_path(path) + assert expected == actual + + +def test_common_project_path(): + project = "cuttlefish" + expected = "projects/{project}".format( + project=project, + ) + actual = TensorboardServiceClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "mussel", + } + path = TensorboardServiceClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = TensorboardServiceClient.parse_common_project_path(path) + assert expected == actual + + +def test_common_location_path(): + project = "winkle" + location = "nautilus" + expected = "projects/{project}/locations/{location}".format( + project=project, + location=location, + ) + actual = TensorboardServiceClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "scallop", + "location": "abalone", + } + path = TensorboardServiceClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = TensorboardServiceClient.parse_common_location_path(path) + assert expected == actual + + +def test_client_with_default_client_info(): + client_info = gapic_v1.client_info.ClientInfo() + + with mock.patch.object( + transports.TensorboardServiceTransport, "_prep_wrapped_messages" + ) as prep: + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + with mock.patch.object( + transports.TensorboardServiceTransport, "_prep_wrapped_messages" + ) as prep: + transport_class = TensorboardServiceClient.get_transport_class() + transport = transport_class( + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, + ) + prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_delete_operation(transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_operation(transport: str = "grpc"): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_operation_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = None + + client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_operation_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_delete_operation_from_dict(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_delete_operation_from_dict_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_cancel_operation(transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation(transport: str = "grpc"): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_wait_operation(transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_wait_operation(transport: str = "grpc"): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_wait_operation_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_wait_operation_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_wait_operation_from_dict(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_wait_operation_from_dict_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_operation(transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_get_operation(transport: str = "grpc"): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_get_operation_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_get_operation_from_dict(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_operations(transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + response = client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +@pytest.mark.asyncio +async def test_list_operations(transport: str = "grpc"): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +def test_list_operations_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_operations_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_operations_from_dict(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + response = client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_operations_from_dict_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_locations(transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + response = client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +@pytest.mark.asyncio +async def test_list_locations(transport: str = "grpc"): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +def test_list_locations_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_locations_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_locations_from_dict(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + response = client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_locations_from_dict_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_location(transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + response = client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +@pytest.mark.asyncio +async def test_get_location_async(transport: str = "grpc_asyncio"): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +def test_get_location_field_headers(): + client = TensorboardServiceClient(credentials=ga_credentials.AnonymousCredentials()) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = locations_pb2.Location() + + client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_location_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials() + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +def test_get_location_from_dict(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + response = client.get_location( + request={ + "name": "locations/abc", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_location_from_dict_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_set_iam_policy(transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + response = client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + response = await client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_set_iam_policy_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_set_iam_policy_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_set_iam_policy_from_dict(): client = TensorboardServiceClient( credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions( - api_endpoint="aiplatform.googleapis.com" - ), ) - assert client.transport._host == "aiplatform.googleapis.com:443" + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + response = client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() -def test_tensorboard_service_host_with_port(): - client = TensorboardServiceClient( + +@pytest.mark.asyncio +async def test_set_iam_policy_from_dict_async(): + client = TensorboardServiceAsyncClient( credentials=ga_credentials.AnonymousCredentials(), - client_options=client_options.ClientOptions( - api_endpoint="aiplatform.googleapis.com:8000" - ), ) - assert client.transport._host == "aiplatform.googleapis.com:8000" + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + response = await client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() -def test_tensorboard_service_grpc_transport_channel(): - channel = grpc.secure_channel("http://localhost/", grpc.local_channel_credentials()) - # Check that channel is used if provided. - transport = transports.TensorboardServiceGrpcTransport( - host="squid.clam.whelk", channel=channel, +def test_get_iam_policy(transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - assert transport.grpc_channel == channel - assert transport._host == "squid.clam.whelk:443" - assert transport._ssl_channel_credentials == None + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() -def test_tensorboard_service_grpc_asyncio_transport_channel(): - channel = aio.secure_channel("http://localhost/", grpc.local_channel_credentials()) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) - # Check that channel is used if provided. - transport = transports.TensorboardServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", channel=channel, - ) - assert transport.grpc_channel == channel - assert transport._host == "squid.clam.whelk:443" - assert transport._ssl_channel_credentials == None + response = client.get_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] -# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are -# removed from grpc/grpc_asyncio transport constructor. -@pytest.mark.parametrize( - "transport_class", - [ - transports.TensorboardServiceGrpcTransport, - transports.TensorboardServiceGrpcAsyncIOTransport, - ], -) -def test_tensorboard_service_transport_channel_mtls_with_client_cert_source( - transport_class, -): - with mock.patch( - "grpc.ssl_channel_credentials", autospec=True - ) as grpc_ssl_channel_cred: - with mock.patch.object( - transport_class, "create_channel" - ) as grpc_create_channel: - mock_ssl_cred = mock.Mock() - grpc_ssl_channel_cred.return_value = mock_ssl_cred + assert args[0] == request - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) - cred = ga_credentials.AnonymousCredentials() - with pytest.warns(DeprecationWarning): - with mock.patch.object(google.auth, "default") as adc: - adc.return_value = (cred, None) - transport = transport_class( - host="squid.clam.whelk", - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=client_cert_source_callback, - ) - adc.assert_called_once() + assert response.version == 774 - grpc_ssl_channel_cred.assert_called_once_with( - certificate_chain=b"cert bytes", private_key=b"key bytes" - ) - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=cred, - credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - assert transport.grpc_channel == mock_grpc_channel - assert transport._ssl_channel_credentials == mock_ssl_cred + assert response.etag == b"etag_blob" -# Remove this test when deprecated arguments (api_mtls_endpoint, client_cert_source) are -# removed from grpc/grpc_asyncio transport constructor. -@pytest.mark.parametrize( - "transport_class", - [ - transports.TensorboardServiceGrpcTransport, - transports.TensorboardServiceGrpcAsyncIOTransport, - ], -) -def test_tensorboard_service_transport_channel_mtls_with_adc(transport_class): - mock_ssl_cred = mock.Mock() - with mock.patch.multiple( - "google.auth.transport.grpc.SslCredentials", - __init__=mock.Mock(return_value=None), - ssl_credentials=mock.PropertyMock(return_value=mock_ssl_cred), - ): - with mock.patch.object( - transport_class, "create_channel" - ) as grpc_create_channel: - mock_grpc_channel = mock.Mock() - grpc_create_channel.return_value = mock_grpc_channel - mock_cred = mock.Mock() +@pytest.mark.asyncio +async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) - with pytest.warns(DeprecationWarning): - transport = transport_class( - host="squid.clam.whelk", - credentials=mock_cred, - api_mtls_endpoint="mtls.squid.clam.whelk", - client_cert_source=None, - ) + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() - grpc_create_channel.assert_called_once_with( - "mtls.squid.clam.whelk:443", - credentials=mock_cred, - credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=mock_ssl_cred, - quota_project_id=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", ) - assert transport.grpc_channel == mock_grpc_channel + ) + response = await client.get_iam_policy(request) -def test_tensorboard_service_grpc_lro_client(): - client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", - ) - transport = client.transport + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] - # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsClient,) + assert args[0] == request - # Ensure that subsequent calls to the property send the exact same object. - assert transport.operations_client is transport.operations_client + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + assert response.version == 774 -def test_tensorboard_service_grpc_lro_async_client(): - client = TensorboardServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", - ) - transport = client.transport + assert response.etag == b"etag_blob" - # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient,) - # Ensure that subsequent calls to the property send the exact same object. - assert transport.operations_client is transport.operations_client +def test_get_iam_policy_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" -def test_tensorboard_path(): - project = "squid" - location = "clam" - tensorboard = "whelk" - expected = "projects/{project}/locations/{location}/tensorboards/{tensorboard}".format( - project=project, location=location, tensorboard=tensorboard, - ) - actual = TensorboardServiceClient.tensorboard_path(project, location, tensorboard) - assert expected == actual + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + client.get_iam_policy(request) -def test_parse_tensorboard_path(): - expected = { - "project": "octopus", - "location": "oyster", - "tensorboard": "nudibranch", - } - path = TensorboardServiceClient.tensorboard_path(**expected) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request - # Check that the path construction is reversible. - actual = TensorboardServiceClient.parse_tensorboard_path(path) - assert expected == actual + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] -def test_tensorboard_experiment_path(): - project = "cuttlefish" - location = "mussel" - tensorboard = "winkle" - experiment = "nautilus" - expected = "projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}".format( - project=project, - location=location, - tensorboard=tensorboard, - experiment=experiment, - ) - actual = TensorboardServiceClient.tensorboard_experiment_path( - project, location, tensorboard, experiment +@pytest.mark.asyncio +async def test_get_iam_policy_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), ) - assert expected == actual + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" -def test_parse_tensorboard_experiment_path(): - expected = { - "project": "scallop", - "location": "abalone", - "tensorboard": "squid", - "experiment": "clam", - } - path = TensorboardServiceClient.tensorboard_experiment_path(**expected) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) - # Check that the path construction is reversible. - actual = TensorboardServiceClient.parse_tensorboard_experiment_path(path) - assert expected == actual + await client.get_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request -def test_tensorboard_run_path(): - project = "whelk" - location = "octopus" - tensorboard = "oyster" - experiment = "nudibranch" - run = "cuttlefish" - expected = "projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}".format( - project=project, - location=location, - tensorboard=tensorboard, - experiment=experiment, - run=run, - ) - actual = TensorboardServiceClient.tensorboard_run_path( - project, location, tensorboard, experiment, run + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_get_iam_policy_from_dict(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), ) - assert expected == actual + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + response = client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() -def test_parse_tensorboard_run_path(): - expected = { - "project": "mussel", - "location": "winkle", - "tensorboard": "nautilus", - "experiment": "scallop", - "run": "abalone", - } - path = TensorboardServiceClient.tensorboard_run_path(**expected) - # Check that the path construction is reversible. - actual = TensorboardServiceClient.parse_tensorboard_run_path(path) - assert expected == actual +@pytest.mark.asyncio +async def test_get_iam_policy_from_dict_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + response = await client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() -def test_tensorboard_time_series_path(): - project = "squid" - location = "clam" - tensorboard = "whelk" - experiment = "octopus" - run = "oyster" - time_series = "nudibranch" - expected = "projects/{project}/locations/{location}/tensorboards/{tensorboard}/experiments/{experiment}/runs/{run}/timeSeries/{time_series}".format( - project=project, - location=location, - tensorboard=tensorboard, - experiment=experiment, - run=run, - time_series=time_series, - ) - actual = TensorboardServiceClient.tensorboard_time_series_path( - project, location, tensorboard, experiment, run, time_series + +def test_test_iam_permissions(transport: str = "grpc"): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) - assert expected == actual + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() -def test_parse_tensorboard_time_series_path(): - expected = { - "project": "cuttlefish", - "location": "mussel", - "tensorboard": "winkle", - "experiment": "nautilus", - "run": "scallop", - "time_series": "abalone", - } - path = TensorboardServiceClient.tensorboard_time_series_path(**expected) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) - # Check that the path construction is reversible. - actual = TensorboardServiceClient.parse_tensorboard_time_series_path(path) - assert expected == actual + response = client.test_iam_permissions(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] -def test_common_billing_account_path(): - billing_account = "squid" - expected = "billingAccounts/{billing_account}".format( - billing_account=billing_account, - ) - actual = TensorboardServiceClient.common_billing_account_path(billing_account) - assert expected == actual + assert args[0] == request + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) -def test_parse_common_billing_account_path(): - expected = { - "billing_account": "clam", - } - path = TensorboardServiceClient.common_billing_account_path(**expected) + assert response.permissions == ["permissions_value"] - # Check that the path construction is reversible. - actual = TensorboardServiceClient.parse_common_billing_account_path(path) - assert expected == actual +@pytest.mark.asyncio +async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) -def test_common_folder_path(): - folder = "whelk" - expected = "folders/{folder}".format(folder=folder,) - actual = TensorboardServiceClient.common_folder_path(folder) - assert expected == actual + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + ) -def test_parse_common_folder_path(): - expected = { - "folder": "octopus", - } - path = TensorboardServiceClient.common_folder_path(**expected) + response = await client.test_iam_permissions(request) - # Check that the path construction is reversible. - actual = TensorboardServiceClient.parse_common_folder_path(path) - assert expected == actual + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request -def test_common_organization_path(): - organization = "oyster" - expected = "organizations/{organization}".format(organization=organization,) - actual = TensorboardServiceClient.common_organization_path(organization) - assert expected == actual + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + assert response.permissions == ["permissions_value"] -def test_parse_common_organization_path(): - expected = { - "organization": "nudibranch", - } - path = TensorboardServiceClient.common_organization_path(**expected) - # Check that the path construction is reversible. - actual = TensorboardServiceClient.parse_common_organization_path(path) - assert expected == actual +def test_test_iam_permissions_field_headers(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" -def test_common_project_path(): - project = "cuttlefish" - expected = "projects/{project}".format(project=project,) - actual = TensorboardServiceClient.common_project_path(project) - assert expected == actual + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + client.test_iam_permissions(request) -def test_parse_common_project_path(): - expected = { - "project": "mussel", - } - path = TensorboardServiceClient.common_project_path(**expected) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request - # Check that the path construction is reversible. - actual = TensorboardServiceClient.parse_common_project_path(path) - assert expected == actual + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] -def test_common_location_path(): - project = "winkle" - location = "nautilus" - expected = "projects/{project}/locations/{location}".format( - project=project, location=location, +@pytest.mark.asyncio +async def test_test_iam_permissions_field_headers_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), ) - actual = TensorboardServiceClient.common_location_path(project, location) - assert expected == actual + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" -def test_parse_common_location_path(): - expected = { - "project": "scallop", - "location": "abalone", - } - path = TensorboardServiceClient.common_location_path(**expected) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) - # Check that the path construction is reversible. - actual = TensorboardServiceClient.parse_common_location_path(path) - assert expected == actual + await client.test_iam_permissions(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request -def test_client_withDEFAULT_CLIENT_INFO(): - client_info = gapic_v1.client_info.ClientInfo() + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + +def test_test_iam_permissions_from_dict(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - transports.TensorboardServiceTransport, "_prep_wrapped_messages" - ) as prep: - client = TensorboardServiceClient( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + response = client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } ) - prep.assert_called_once_with(client_info) + call.assert_called() + +@pytest.mark.asyncio +async def test_test_iam_permissions_from_dict_async(): + client = TensorboardServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - transports.TensorboardServiceTransport, "_prep_wrapped_messages" - ) as prep: - transport_class = TensorboardServiceClient.get_transport_class() - transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() ) - prep.assert_called_once_with(client_info) + + response = await client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = TensorboardServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (TensorboardServiceClient, transports.TensorboardServiceGrpcTransport), + ( + TensorboardServiceAsyncClient, + transports.TensorboardServiceGrpcAsyncIOTransport, + ), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) diff --git a/tests/unit/gapic/aiplatform_v1beta1/test_vizier_service.py b/tests/unit/gapic/aiplatform_v1beta1/test_vizier_service.py index e4df5b0517..550c3c13a5 100644 --- a/tests/unit/gapic/aiplatform_v1beta1/test_vizier_service.py +++ b/tests/unit/gapic/aiplatform_v1beta1/test_vizier_service.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2020 Google LLC +# Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -14,8 +14,13 @@ # limitations under the License. # import os -import mock -import packaging.version + +# try/except added for compatibility with python < 3.8 +try: + from unittest import mock + from unittest.mock import AsyncMock +except ImportError: + import mock import grpc from grpc.experimental import aio @@ -30,8 +35,10 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 +from google.api_core import path_template from google.auth import credentials as ga_credentials from google.auth.exceptions import MutualTLSChannelError from google.cloud.aiplatform_v1beta1.services.vizier_service import ( @@ -40,15 +47,13 @@ from google.cloud.aiplatform_v1beta1.services.vizier_service import VizierServiceClient from google.cloud.aiplatform_v1beta1.services.vizier_service import pagers from google.cloud.aiplatform_v1beta1.services.vizier_service import transports -from google.cloud.aiplatform_v1beta1.services.vizier_service.transports.base import ( - _API_CORE_VERSION, -) -from google.cloud.aiplatform_v1beta1.services.vizier_service.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.aiplatform_v1beta1.types import study from google.cloud.aiplatform_v1beta1.types import study as gca_study from google.cloud.aiplatform_v1beta1.types import vizier_service +from google.cloud.location import locations_pb2 +from google.iam.v1 import iam_policy_pb2 # type: ignore +from google.iam.v1 import options_pb2 # type: ignore +from google.iam.v1 import policy_pb2 # type: ignore from google.longrunning import operations_pb2 from google.oauth2 import service_account from google.protobuf import duration_pb2 # type: ignore @@ -57,29 +62,6 @@ import google.auth -# TODO(busunkim): Once google-api-core >= 1.26.0 is required: -# - Delete all the api-core and auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - -requires_api_core_lt_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) >= packaging.version.parse("1.26.0"), - reason="This test requires google-api-core < 1.26.0", -) - -requires_api_core_gte_1_26_0 = pytest.mark.skipif( - packaging.version.parse(_API_CORE_VERSION) < packaging.version.parse("1.26.0"), - reason="This test requires google-api-core >= 1.26.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -125,40 +107,77 @@ def test__get_default_mtls_endpoint(): @pytest.mark.parametrize( - "client_class", [VizierServiceClient, VizierServiceAsyncClient,] + "client_class,transport_name", + [ + (VizierServiceClient, "grpc"), + (VizierServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_vizier_service_client_from_service_account_info(client_class): +def test_vizier_service_client_from_service_account_info(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_info" ) as factory: factory.return_value = creds info = {"valid": True} - client = client_class.from_service_account_info(info) + client = client_class.from_service_account_info(info, transport=transport_name) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") + + +@pytest.mark.parametrize( + "transport_class,transport_name", + [ + (transports.VizierServiceGrpcTransport, "grpc"), + (transports.VizierServiceGrpcAsyncIOTransport, "grpc_asyncio"), + ], +) +def test_vizier_service_client_service_account_always_use_jwt( + transport_class, transport_name +): + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=True) + use_jwt.assert_called_once_with(True) + + with mock.patch.object( + service_account.Credentials, "with_always_use_jwt_access", create=True + ) as use_jwt: + creds = service_account.Credentials(None, None, None) + transport = transport_class(credentials=creds, always_use_jwt_access=False) + use_jwt.assert_not_called() @pytest.mark.parametrize( - "client_class", [VizierServiceClient, VizierServiceAsyncClient,] + "client_class,transport_name", + [ + (VizierServiceClient, "grpc"), + (VizierServiceAsyncClient, "grpc_asyncio"), + ], ) -def test_vizier_service_client_from_service_account_file(client_class): +def test_vizier_service_client_from_service_account_file(client_class, transport_name): creds = ga_credentials.AnonymousCredentials() with mock.patch.object( service_account.Credentials, "from_service_account_file" ) as factory: factory.return_value = creds - client = client_class.from_service_account_file("dummy/file/path.json") + client = client_class.from_service_account_file( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - client = client_class.from_service_account_json("dummy/file/path.json") + client = client_class.from_service_account_json( + "dummy/file/path.json", transport=transport_name + ) assert client.transport._credentials == creds assert isinstance(client, client_class) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") def test_vizier_service_client_get_transport_class(): @@ -211,7 +230,7 @@ def test_vizier_service_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -220,6 +239,7 @@ def test_vizier_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -227,7 +247,7 @@ def test_vizier_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -236,6 +256,7 @@ def test_vizier_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT is @@ -243,7 +264,7 @@ def test_vizier_service_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -252,26 +273,27 @@ def test_vizier_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case api_endpoint is not provided and GOOGLE_API_USE_MTLS_ENDPOINT has # unsupported value. with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "Unsupported"}): with pytest.raises(MutualTLSChannelError): - client = client_class() + client = client_class(transport=transport_name) # Check the case GOOGLE_API_USE_CLIENT_CERTIFICATE has unsupported value. with mock.patch.dict( os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "Unsupported"} ): with pytest.raises(ValueError): - client = client_class() + client = client_class(transport=transport_name) # Check the case quota_project_id is provided options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -280,6 +302,7 @@ def test_vizier_service_client_client_options( client_cert_source_for_mtls=None, quota_project_id="octopus", client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -329,7 +352,7 @@ def test_vizier_service_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) if use_client_cert_env == "false": expected_client_cert_source = None @@ -346,6 +369,7 @@ def test_vizier_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case ADC client cert is provided. Whether client cert is used depends on @@ -370,7 +394,7 @@ def test_vizier_service_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -379,6 +403,7 @@ def test_vizier_service_client_mtls_env_auto( client_cert_source_for_mtls=expected_client_cert_source, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) # Check the case client_cert_source and ADC client cert are not provided. @@ -391,7 +416,7 @@ def test_vizier_service_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -400,9 +425,91 @@ def test_vizier_service_client_mtls_env_auto( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) +@pytest.mark.parametrize( + "client_class", [VizierServiceClient, VizierServiceAsyncClient] +) +@mock.patch.object( + VizierServiceClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(VizierServiceClient), +) +@mock.patch.object( + VizierServiceAsyncClient, + "DEFAULT_ENDPOINT", + modify_default_endpoint(VizierServiceAsyncClient), +) +def test_vizier_service_client_get_mtls_endpoint_and_cert_source(client_class): + mock_client_cert_source = mock.Mock() + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "true". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source == mock_client_cert_source + + # Test the case GOOGLE_API_USE_CLIENT_CERTIFICATE is "false". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "false"}): + mock_client_cert_source = mock.Mock() + mock_api_endpoint = "foo" + options = client_options.ClientOptions( + client_cert_source=mock_client_cert_source, api_endpoint=mock_api_endpoint + ) + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source( + options + ) + assert api_endpoint == mock_api_endpoint + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "never". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "always". + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert doesn't exist. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=False, + ): + api_endpoint, cert_source = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_ENDPOINT + assert cert_source is None + + # Test the case GOOGLE_API_USE_MTLS_ENDPOINT is "auto" and default cert exists. + with mock.patch.dict(os.environ, {"GOOGLE_API_USE_CLIENT_CERTIFICATE": "true"}): + with mock.patch( + "google.auth.transport.mtls.has_default_client_cert_source", + return_value=True, + ): + with mock.patch( + "google.auth.transport.mtls.default_client_cert_source", + return_value=mock_client_cert_source, + ): + ( + api_endpoint, + cert_source, + ) = client_class.get_mtls_endpoint_and_cert_source() + assert api_endpoint == client_class.DEFAULT_MTLS_ENDPOINT + assert cert_source == mock_client_cert_source + + @pytest.mark.parametrize( "client_class,transport_class,transport_name", [ @@ -418,10 +525,12 @@ def test_vizier_service_client_client_options_scopes( client_class, transport_class, transport_name ): # Check the case scopes are provided. - options = client_options.ClientOptions(scopes=["1", "2"],) + options = client_options.ClientOptions( + scopes=["1", "2"], + ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -430,28 +539,36 @@ def test_vizier_service_client_client_options_scopes( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (VizierServiceClient, transports.VizierServiceGrpcTransport, "grpc"), + ( + VizierServiceClient, + transports.VizierServiceGrpcTransport, + "grpc", + grpc_helpers, + ), ( VizierServiceAsyncClient, transports.VizierServiceGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_vizier_service_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(client_options=options, transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -460,6 +577,7 @@ def test_vizier_service_client_client_options_credentials_file( client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) @@ -479,14 +597,87 @@ def test_vizier_service_client_client_options_from_dict(): client_cert_source_for_mtls=None, quota_project_id=None, client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, ) -def test_create_study( - transport: str = "grpc", request_type=vizier_service.CreateStudyRequest +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + VizierServiceClient, + transports.VizierServiceGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + VizierServiceAsyncClient, + transports.VizierServiceGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_vizier_service_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers ): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "aiplatform.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, + default_host="aiplatform.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + +@pytest.mark.parametrize( + "request_type", + [ + vizier_service.CreateStudyRequest, + dict, + ], +) +def test_create_study(request_type, transport: str = "grpc"): client = VizierServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -517,15 +708,12 @@ def test_create_study( assert response.inactive_reason == "inactive_reason_value" -def test_create_study_from_dict(): - test_create_study(request_type=dict) - - def test_create_study_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = VizierServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -541,7 +729,8 @@ async def test_create_study_async( transport: str = "grpc_asyncio", request_type=vizier_service.CreateStudyRequest ): client = VizierServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -580,13 +769,15 @@ async def test_create_study_async_from_dict(): def test_create_study_field_headers(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = vizier_service.CreateStudyRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_study), "__call__") as call: @@ -600,7 +791,10 @@ def test_create_study_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -613,7 +807,7 @@ async def test_create_study_field_headers_async(): # a field header. Set these to a non-empty value. request = vizier_service.CreateStudyRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_study), "__call__") as call: @@ -627,11 +821,16 @@ async def test_create_study_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_create_study_flattened(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_study), "__call__") as call: @@ -640,19 +839,26 @@ def test_create_study_flattened(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.create_study( - parent="parent_value", study=gca_study.Study(name="name_value"), + parent="parent_value", + study=gca_study.Study(name="name_value"), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].study == gca_study.Study(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].study + mock_val = gca_study.Study(name="name_value") + assert arg == mock_val def test_create_study_flattened_error(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -679,15 +885,20 @@ async def test_create_study_flattened_async(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. response = await client.create_study( - parent="parent_value", study=gca_study.Study(name="name_value"), + parent="parent_value", + study=gca_study.Study(name="name_value"), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].study == gca_study.Study(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].study + mock_val = gca_study.Study(name="name_value") + assert arg == mock_val @pytest.mark.asyncio @@ -706,11 +917,17 @@ async def test_create_study_flattened_error_async(): ) -def test_get_study( - transport: str = "grpc", request_type=vizier_service.GetStudyRequest -): +@pytest.mark.parametrize( + "request_type", + [ + vizier_service.GetStudyRequest, + dict, + ], +) +def test_get_study(request_type, transport: str = "grpc"): client = VizierServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -741,15 +958,12 @@ def test_get_study( assert response.inactive_reason == "inactive_reason_value" -def test_get_study_from_dict(): - test_get_study(request_type=dict) - - def test_get_study_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = VizierServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -765,7 +979,8 @@ async def test_get_study_async( transport: str = "grpc_asyncio", request_type=vizier_service.GetStudyRequest ): client = VizierServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -804,13 +1019,15 @@ async def test_get_study_async_from_dict(): def test_get_study_field_headers(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = vizier_service.GetStudyRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_study), "__call__") as call: @@ -824,7 +1041,10 @@ def test_get_study_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -837,7 +1057,7 @@ async def test_get_study_field_headers_async(): # a field header. Set these to a non-empty value. request = vizier_service.GetStudyRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_study), "__call__") as call: @@ -851,11 +1071,16 @@ async def test_get_study_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_get_study_flattened(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_study), "__call__") as call: @@ -863,23 +1088,30 @@ def test_get_study_flattened(): call.return_value = study.Study() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_study(name="name_value",) + client.get_study( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_study_flattened_error(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.get_study( - vizier_service.GetStudyRequest(), name="name_value", + vizier_service.GetStudyRequest(), + name="name_value", ) @@ -897,13 +1129,17 @@ async def test_get_study_flattened_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(study.Study()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_study(name="name_value",) + response = await client.get_study( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -916,15 +1152,22 @@ async def test_get_study_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.get_study( - vizier_service.GetStudyRequest(), name="name_value", + vizier_service.GetStudyRequest(), + name="name_value", ) -def test_list_studies( - transport: str = "grpc", request_type=vizier_service.ListStudiesRequest -): +@pytest.mark.parametrize( + "request_type", + [ + vizier_service.ListStudiesRequest, + dict, + ], +) +def test_list_studies(request_type, transport: str = "grpc"): client = VizierServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -949,15 +1192,12 @@ def test_list_studies( assert response.next_page_token == "next_page_token_value" -def test_list_studies_from_dict(): - test_list_studies(request_type=dict) - - def test_list_studies_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = VizierServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -973,7 +1213,8 @@ async def test_list_studies_async( transport: str = "grpc_asyncio", request_type=vizier_service.ListStudiesRequest ): client = VizierServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -984,7 +1225,9 @@ async def test_list_studies_async( with mock.patch.object(type(client.transport.list_studies), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - vizier_service.ListStudiesResponse(next_page_token="next_page_token_value",) + vizier_service.ListStudiesResponse( + next_page_token="next_page_token_value", + ) ) response = await client.list_studies(request) @@ -1004,13 +1247,15 @@ async def test_list_studies_async_from_dict(): def test_list_studies_field_headers(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = vizier_service.ListStudiesRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_studies), "__call__") as call: @@ -1024,7 +1269,10 @@ def test_list_studies_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1037,7 +1285,7 @@ async def test_list_studies_field_headers_async(): # a field header. Set these to a non-empty value. request = vizier_service.ListStudiesRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_studies), "__call__") as call: @@ -1053,11 +1301,16 @@ async def test_list_studies_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_studies_flattened(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_studies), "__call__") as call: @@ -1065,23 +1318,30 @@ def test_list_studies_flattened(): call.return_value = vizier_service.ListStudiesResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_studies(parent="parent_value",) + client.list_studies( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_studies_flattened_error(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.list_studies( - vizier_service.ListStudiesRequest(), parent="parent_value", + vizier_service.ListStudiesRequest(), + parent="parent_value", ) @@ -1101,13 +1361,17 @@ async def test_list_studies_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_studies(parent="parent_value",) + response = await client.list_studies( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1120,27 +1384,44 @@ async def test_list_studies_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.list_studies( - vizier_service.ListStudiesRequest(), parent="parent_value", + vizier_service.ListStudiesRequest(), + parent="parent_value", ) -def test_list_studies_pager(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_studies_pager(transport_name: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_studies), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( vizier_service.ListStudiesResponse( - studies=[study.Study(), study.Study(), study.Study(),], + studies=[ + study.Study(), + study.Study(), + study.Study(), + ], next_page_token="abc", ), - vizier_service.ListStudiesResponse(studies=[], next_page_token="def",), vizier_service.ListStudiesResponse( - studies=[study.Study(),], next_page_token="ghi", + studies=[], + next_page_token="def", ), vizier_service.ListStudiesResponse( - studies=[study.Study(), study.Study(),], + studies=[ + study.Study(), + ], + next_page_token="ghi", + ), + vizier_service.ListStudiesResponse( + studies=[ + study.Study(), + study.Study(), + ], ), RuntimeError, ) @@ -1153,28 +1434,44 @@ def test_list_studies_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all(isinstance(i, study.Study) for i in results) -def test_list_studies_pages(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_studies_pages(transport_name: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_studies), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( vizier_service.ListStudiesResponse( - studies=[study.Study(), study.Study(), study.Study(),], + studies=[ + study.Study(), + study.Study(), + study.Study(), + ], next_page_token="abc", ), - vizier_service.ListStudiesResponse(studies=[], next_page_token="def",), vizier_service.ListStudiesResponse( - studies=[study.Study(),], next_page_token="ghi", + studies=[], + next_page_token="def", + ), + vizier_service.ListStudiesResponse( + studies=[ + study.Study(), + ], + next_page_token="ghi", ), vizier_service.ListStudiesResponse( - studies=[study.Study(), study.Study(),], + studies=[ + study.Study(), + study.Study(), + ], ), RuntimeError, ) @@ -1185,7 +1482,9 @@ def test_list_studies_pages(): @pytest.mark.asyncio async def test_list_studies_async_pager(): - client = VizierServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1194,22 +1493,37 @@ async def test_list_studies_async_pager(): # Set the response to a series of pages. call.side_effect = ( vizier_service.ListStudiesResponse( - studies=[study.Study(), study.Study(), study.Study(),], + studies=[ + study.Study(), + study.Study(), + study.Study(), + ], next_page_token="abc", ), - vizier_service.ListStudiesResponse(studies=[], next_page_token="def",), vizier_service.ListStudiesResponse( - studies=[study.Study(),], next_page_token="ghi", + studies=[], + next_page_token="def", + ), + vizier_service.ListStudiesResponse( + studies=[ + study.Study(), + ], + next_page_token="ghi", ), vizier_service.ListStudiesResponse( - studies=[study.Study(), study.Study(),], + studies=[ + study.Study(), + study.Study(), + ], ), RuntimeError, ) - async_pager = await client.list_studies(request={},) + async_pager = await client.list_studies( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -1218,7 +1532,9 @@ async def test_list_studies_async_pager(): @pytest.mark.asyncio async def test_list_studies_async_pages(): - client = VizierServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -1227,30 +1543,51 @@ async def test_list_studies_async_pages(): # Set the response to a series of pages. call.side_effect = ( vizier_service.ListStudiesResponse( - studies=[study.Study(), study.Study(), study.Study(),], + studies=[ + study.Study(), + study.Study(), + study.Study(), + ], next_page_token="abc", ), - vizier_service.ListStudiesResponse(studies=[], next_page_token="def",), vizier_service.ListStudiesResponse( - studies=[study.Study(),], next_page_token="ghi", + studies=[], + next_page_token="def", + ), + vizier_service.ListStudiesResponse( + studies=[ + study.Study(), + ], + next_page_token="ghi", ), vizier_service.ListStudiesResponse( - studies=[study.Study(), study.Study(),], + studies=[ + study.Study(), + study.Study(), + ], ), RuntimeError, ) pages = [] - async for page_ in (await client.list_studies(request={})).pages: + async for page_ in ( + await client.list_studies(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_delete_study( - transport: str = "grpc", request_type=vizier_service.DeleteStudyRequest -): +@pytest.mark.parametrize( + "request_type", + [ + vizier_service.DeleteStudyRequest, + dict, + ], +) +def test_delete_study(request_type, transport: str = "grpc"): client = VizierServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1272,15 +1609,12 @@ def test_delete_study( assert response is None -def test_delete_study_from_dict(): - test_delete_study(request_type=dict) - - def test_delete_study_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = VizierServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1296,7 +1630,8 @@ async def test_delete_study_async( transport: str = "grpc_asyncio", request_type=vizier_service.DeleteStudyRequest ): client = VizierServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1324,13 +1659,15 @@ async def test_delete_study_async_from_dict(): def test_delete_study_field_headers(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = vizier_service.DeleteStudyRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_study), "__call__") as call: @@ -1344,7 +1681,10 @@ def test_delete_study_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1357,7 +1697,7 @@ async def test_delete_study_field_headers_async(): # a field header. Set these to a non-empty value. request = vizier_service.DeleteStudyRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_study), "__call__") as call: @@ -1371,11 +1711,16 @@ async def test_delete_study_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_delete_study_flattened(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_study), "__call__") as call: @@ -1383,23 +1728,30 @@ def test_delete_study_flattened(): call.return_value = None # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_study(name="name_value",) + client.delete_study( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_delete_study_flattened_error(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.delete_study( - vizier_service.DeleteStudyRequest(), name="name_value", + vizier_service.DeleteStudyRequest(), + name="name_value", ) @@ -1417,13 +1769,17 @@ async def test_delete_study_flattened_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_study(name="name_value",) + response = await client.delete_study( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1436,15 +1792,22 @@ async def test_delete_study_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.delete_study( - vizier_service.DeleteStudyRequest(), name="name_value", + vizier_service.DeleteStudyRequest(), + name="name_value", ) -def test_lookup_study( - transport: str = "grpc", request_type=vizier_service.LookupStudyRequest -): +@pytest.mark.parametrize( + "request_type", + [ + vizier_service.LookupStudyRequest, + dict, + ], +) +def test_lookup_study(request_type, transport: str = "grpc"): client = VizierServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1475,15 +1838,12 @@ def test_lookup_study( assert response.inactive_reason == "inactive_reason_value" -def test_lookup_study_from_dict(): - test_lookup_study(request_type=dict) - - def test_lookup_study_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = VizierServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1499,7 +1859,8 @@ async def test_lookup_study_async( transport: str = "grpc_asyncio", request_type=vizier_service.LookupStudyRequest ): client = VizierServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1538,13 +1899,15 @@ async def test_lookup_study_async_from_dict(): def test_lookup_study_field_headers(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = vizier_service.LookupStudyRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.lookup_study), "__call__") as call: @@ -1558,7 +1921,10 @@ def test_lookup_study_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1571,7 +1937,7 @@ async def test_lookup_study_field_headers_async(): # a field header. Set these to a non-empty value. request = vizier_service.LookupStudyRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.lookup_study), "__call__") as call: @@ -1585,11 +1951,16 @@ async def test_lookup_study_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_lookup_study_flattened(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.lookup_study), "__call__") as call: @@ -1597,23 +1968,30 @@ def test_lookup_study_flattened(): call.return_value = study.Study() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.lookup_study(parent="parent_value",) + client.lookup_study( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_lookup_study_flattened_error(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.lookup_study( - vizier_service.LookupStudyRequest(), parent="parent_value", + vizier_service.LookupStudyRequest(), + parent="parent_value", ) @@ -1631,13 +2009,17 @@ async def test_lookup_study_flattened_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(study.Study()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.lookup_study(parent="parent_value",) + response = await client.lookup_study( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -1650,15 +2032,22 @@ async def test_lookup_study_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.lookup_study( - vizier_service.LookupStudyRequest(), parent="parent_value", + vizier_service.LookupStudyRequest(), + parent="parent_value", ) -def test_suggest_trials( - transport: str = "grpc", request_type=vizier_service.SuggestTrialsRequest -): +@pytest.mark.parametrize( + "request_type", + [ + vizier_service.SuggestTrialsRequest, + dict, + ], +) +def test_suggest_trials(request_type, transport: str = "grpc"): client = VizierServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1680,15 +2069,12 @@ def test_suggest_trials( assert isinstance(response, future.Future) -def test_suggest_trials_from_dict(): - test_suggest_trials(request_type=dict) - - def test_suggest_trials_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = VizierServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1704,7 +2090,8 @@ async def test_suggest_trials_async( transport: str = "grpc_asyncio", request_type=vizier_service.SuggestTrialsRequest ): client = VizierServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1734,13 +2121,15 @@ async def test_suggest_trials_async_from_dict(): def test_suggest_trials_field_headers(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = vizier_service.SuggestTrialsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.suggest_trials), "__call__") as call: @@ -1754,7 +2143,10 @@ def test_suggest_trials_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1767,7 +2159,7 @@ async def test_suggest_trials_field_headers_async(): # a field header. Set these to a non-empty value. request = vizier_service.SuggestTrialsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.suggest_trials), "__call__") as call: @@ -1783,14 +2175,23 @@ async def test_suggest_trials_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] -def test_create_trial( - transport: str = "grpc", request_type=vizier_service.CreateTrialRequest -): +@pytest.mark.parametrize( + "request_type", + [ + vizier_service.CreateTrialRequest, + dict, + ], +) +def test_create_trial(request_type, transport: str = "grpc"): client = VizierServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1825,15 +2226,12 @@ def test_create_trial( assert response.custom_job == "custom_job_value" -def test_create_trial_from_dict(): - test_create_trial(request_type=dict) - - def test_create_trial_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = VizierServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -1849,7 +2247,8 @@ async def test_create_trial_async( transport: str = "grpc_asyncio", request_type=vizier_service.CreateTrialRequest ): client = VizierServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -1892,13 +2291,15 @@ async def test_create_trial_async_from_dict(): def test_create_trial_field_headers(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = vizier_service.CreateTrialRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_trial), "__call__") as call: @@ -1912,7 +2313,10 @@ def test_create_trial_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -1925,7 +2329,7 @@ async def test_create_trial_field_headers_async(): # a field header. Set these to a non-empty value. request = vizier_service.CreateTrialRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_trial), "__call__") as call: @@ -1939,11 +2343,16 @@ async def test_create_trial_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_create_trial_flattened(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.create_trial), "__call__") as call: @@ -1952,19 +2361,26 @@ def test_create_trial_flattened(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. client.create_trial( - parent="parent_value", trial=study.Trial(name="name_value"), + parent="parent_value", + trial=study.Trial(name="name_value"), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].trial == study.Trial(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].trial + mock_val = study.Trial(name="name_value") + assert arg == mock_val def test_create_trial_flattened_error(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. @@ -1991,15 +2407,20 @@ async def test_create_trial_flattened_async(): # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. response = await client.create_trial( - parent="parent_value", trial=study.Trial(name="name_value"), + parent="parent_value", + trial=study.Trial(name="name_value"), ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" - assert args[0].trial == study.Trial(name="name_value") + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val + arg = args[0].trial + mock_val = study.Trial(name="name_value") + assert arg == mock_val @pytest.mark.asyncio @@ -2018,11 +2439,17 @@ async def test_create_trial_flattened_error_async(): ) -def test_get_trial( - transport: str = "grpc", request_type=vizier_service.GetTrialRequest -): +@pytest.mark.parametrize( + "request_type", + [ + vizier_service.GetTrialRequest, + dict, + ], +) +def test_get_trial(request_type, transport: str = "grpc"): client = VizierServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2057,15 +2484,12 @@ def test_get_trial( assert response.custom_job == "custom_job_value" -def test_get_trial_from_dict(): - test_get_trial(request_type=dict) - - def test_get_trial_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = VizierServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2081,7 +2505,8 @@ async def test_get_trial_async( transport: str = "grpc_asyncio", request_type=vizier_service.GetTrialRequest ): client = VizierServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2124,13 +2549,15 @@ async def test_get_trial_async_from_dict(): def test_get_trial_field_headers(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = vizier_service.GetTrialRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_trial), "__call__") as call: @@ -2144,7 +2571,10 @@ def test_get_trial_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2157,7 +2587,7 @@ async def test_get_trial_field_headers_async(): # a field header. Set these to a non-empty value. request = vizier_service.GetTrialRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_trial), "__call__") as call: @@ -2171,11 +2601,16 @@ async def test_get_trial_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_get_trial_flattened(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.get_trial), "__call__") as call: @@ -2183,23 +2618,30 @@ def test_get_trial_flattened(): call.return_value = study.Trial() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.get_trial(name="name_value",) + client.get_trial( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_get_trial_flattened_error(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.get_trial( - vizier_service.GetTrialRequest(), name="name_value", + vizier_service.GetTrialRequest(), + name="name_value", ) @@ -2217,13 +2659,17 @@ async def test_get_trial_flattened_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(study.Trial()) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.get_trial(name="name_value",) + response = await client.get_trial( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -2236,15 +2682,22 @@ async def test_get_trial_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.get_trial( - vizier_service.GetTrialRequest(), name="name_value", + vizier_service.GetTrialRequest(), + name="name_value", ) -def test_list_trials( - transport: str = "grpc", request_type=vizier_service.ListTrialsRequest -): +@pytest.mark.parametrize( + "request_type", + [ + vizier_service.ListTrialsRequest, + dict, + ], +) +def test_list_trials(request_type, transport: str = "grpc"): client = VizierServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2269,15 +2722,12 @@ def test_list_trials( assert response.next_page_token == "next_page_token_value" -def test_list_trials_from_dict(): - test_list_trials(request_type=dict) - - def test_list_trials_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = VizierServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2293,7 +2743,8 @@ async def test_list_trials_async( transport: str = "grpc_asyncio", request_type=vizier_service.ListTrialsRequest ): client = VizierServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2304,7 +2755,9 @@ async def test_list_trials_async( with mock.patch.object(type(client.transport.list_trials), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( - vizier_service.ListTrialsResponse(next_page_token="next_page_token_value",) + vizier_service.ListTrialsResponse( + next_page_token="next_page_token_value", + ) ) response = await client.list_trials(request) @@ -2324,13 +2777,15 @@ async def test_list_trials_async_from_dict(): def test_list_trials_field_headers(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = vizier_service.ListTrialsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_trials), "__call__") as call: @@ -2344,7 +2799,10 @@ def test_list_trials_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2357,7 +2815,7 @@ async def test_list_trials_field_headers_async(): # a field header. Set these to a non-empty value. request = vizier_service.ListTrialsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_trials), "__call__") as call: @@ -2373,11 +2831,16 @@ async def test_list_trials_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_trials_flattened(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_trials), "__call__") as call: @@ -2385,23 +2848,30 @@ def test_list_trials_flattened(): call.return_value = vizier_service.ListTrialsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_trials(parent="parent_value",) + client.list_trials( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_trials_flattened_error(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.list_trials( - vizier_service.ListTrialsRequest(), parent="parent_value", + vizier_service.ListTrialsRequest(), + parent="parent_value", ) @@ -2421,13 +2891,17 @@ async def test_list_trials_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_trials(parent="parent_value",) + response = await client.list_trials( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -2440,26 +2914,45 @@ async def test_list_trials_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.list_trials( - vizier_service.ListTrialsRequest(), parent="parent_value", + vizier_service.ListTrialsRequest(), + parent="parent_value", ) -def test_list_trials_pager(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_trials_pager(transport_name: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_trials), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( vizier_service.ListTrialsResponse( - trials=[study.Trial(), study.Trial(), study.Trial(),], + trials=[ + study.Trial(), + study.Trial(), + study.Trial(), + ], next_page_token="abc", ), - vizier_service.ListTrialsResponse(trials=[], next_page_token="def",), vizier_service.ListTrialsResponse( - trials=[study.Trial(),], next_page_token="ghi", + trials=[], + next_page_token="def", + ), + vizier_service.ListTrialsResponse( + trials=[ + study.Trial(), + ], + next_page_token="ghi", + ), + vizier_service.ListTrialsResponse( + trials=[ + study.Trial(), + study.Trial(), + ], ), - vizier_service.ListTrialsResponse(trials=[study.Trial(), study.Trial(),],), RuntimeError, ) @@ -2471,27 +2964,45 @@ def test_list_trials_pager(): assert pager._metadata == metadata - results = [i for i in pager] + results = list(pager) assert len(results) == 6 assert all(isinstance(i, study.Trial) for i in results) -def test_list_trials_pages(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials,) +def test_list_trials_pages(transport_name: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials, + transport=transport_name, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.list_trials), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( vizier_service.ListTrialsResponse( - trials=[study.Trial(), study.Trial(), study.Trial(),], + trials=[ + study.Trial(), + study.Trial(), + study.Trial(), + ], next_page_token="abc", ), - vizier_service.ListTrialsResponse(trials=[], next_page_token="def",), vizier_service.ListTrialsResponse( - trials=[study.Trial(),], next_page_token="ghi", + trials=[], + next_page_token="def", + ), + vizier_service.ListTrialsResponse( + trials=[ + study.Trial(), + ], + next_page_token="ghi", + ), + vizier_service.ListTrialsResponse( + trials=[ + study.Trial(), + study.Trial(), + ], ), - vizier_service.ListTrialsResponse(trials=[study.Trial(), study.Trial(),],), RuntimeError, ) pages = list(client.list_trials(request={}).pages) @@ -2501,7 +3012,9 @@ def test_list_trials_pages(): @pytest.mark.asyncio async def test_list_trials_async_pager(): - client = VizierServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2510,20 +3023,37 @@ async def test_list_trials_async_pager(): # Set the response to a series of pages. call.side_effect = ( vizier_service.ListTrialsResponse( - trials=[study.Trial(), study.Trial(), study.Trial(),], + trials=[ + study.Trial(), + study.Trial(), + study.Trial(), + ], next_page_token="abc", ), - vizier_service.ListTrialsResponse(trials=[], next_page_token="def",), vizier_service.ListTrialsResponse( - trials=[study.Trial(),], next_page_token="ghi", + trials=[], + next_page_token="def", + ), + vizier_service.ListTrialsResponse( + trials=[ + study.Trial(), + ], + next_page_token="ghi", + ), + vizier_service.ListTrialsResponse( + trials=[ + study.Trial(), + study.Trial(), + ], ), - vizier_service.ListTrialsResponse(trials=[study.Trial(), study.Trial(),],), RuntimeError, ) - async_pager = await client.list_trials(request={},) + async_pager = await client.list_trials( + request={}, + ) assert async_pager.next_page_token == "abc" responses = [] - async for response in async_pager: + async for response in async_pager: # pragma: no branch responses.append(response) assert len(responses) == 6 @@ -2532,7 +3062,9 @@ async def test_list_trials_async_pager(): @pytest.mark.asyncio async def test_list_trials_async_pages(): - client = VizierServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials,) + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials, + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2541,28 +3073,51 @@ async def test_list_trials_async_pages(): # Set the response to a series of pages. call.side_effect = ( vizier_service.ListTrialsResponse( - trials=[study.Trial(), study.Trial(), study.Trial(),], + trials=[ + study.Trial(), + study.Trial(), + study.Trial(), + ], next_page_token="abc", ), - vizier_service.ListTrialsResponse(trials=[], next_page_token="def",), vizier_service.ListTrialsResponse( - trials=[study.Trial(),], next_page_token="ghi", + trials=[], + next_page_token="def", + ), + vizier_service.ListTrialsResponse( + trials=[ + study.Trial(), + ], + next_page_token="ghi", + ), + vizier_service.ListTrialsResponse( + trials=[ + study.Trial(), + study.Trial(), + ], ), - vizier_service.ListTrialsResponse(trials=[study.Trial(), study.Trial(),],), RuntimeError, ) pages = [] - async for page_ in (await client.list_trials(request={})).pages: + async for page_ in ( + await client.list_trials(request={}) + ).pages: # pragma: no branch pages.append(page_) for page_, token in zip(pages, ["abc", "def", "ghi", ""]): assert page_.raw_page.next_page_token == token -def test_add_trial_measurement( - transport: str = "grpc", request_type=vizier_service.AddTrialMeasurementRequest -): +@pytest.mark.parametrize( + "request_type", + [ + vizier_service.AddTrialMeasurementRequest, + dict, + ], +) +def test_add_trial_measurement(request_type, transport: str = "grpc"): client = VizierServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2599,15 +3154,12 @@ def test_add_trial_measurement( assert response.custom_job == "custom_job_value" -def test_add_trial_measurement_from_dict(): - test_add_trial_measurement(request_type=dict) - - def test_add_trial_measurement_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = VizierServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2626,7 +3178,8 @@ async def test_add_trial_measurement_async( request_type=vizier_service.AddTrialMeasurementRequest, ): client = VizierServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2671,13 +3224,15 @@ async def test_add_trial_measurement_async_from_dict(): def test_add_trial_measurement_field_headers(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = vizier_service.AddTrialMeasurementRequest() - request.trial_name = "trial_name/value" + request.trial_name = "trial_name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2693,7 +3248,10 @@ def test_add_trial_measurement_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "trial_name=trial_name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "trial_name=trial_name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2706,7 +3264,7 @@ async def test_add_trial_measurement_field_headers_async(): # a field header. Set these to a non-empty value. request = vizier_service.AddTrialMeasurementRequest() - request.trial_name = "trial_name/value" + request.trial_name = "trial_name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -2722,14 +3280,23 @@ async def test_add_trial_measurement_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "trial_name=trial_name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "trial_name=trial_name_value", + ) in kw["metadata"] -def test_complete_trial( - transport: str = "grpc", request_type=vizier_service.CompleteTrialRequest -): +@pytest.mark.parametrize( + "request_type", + [ + vizier_service.CompleteTrialRequest, + dict, + ], +) +def test_complete_trial(request_type, transport: str = "grpc"): client = VizierServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2764,15 +3331,12 @@ def test_complete_trial( assert response.custom_job == "custom_job_value" -def test_complete_trial_from_dict(): - test_complete_trial(request_type=dict) - - def test_complete_trial_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = VizierServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2788,7 +3352,8 @@ async def test_complete_trial_async( transport: str = "grpc_asyncio", request_type=vizier_service.CompleteTrialRequest ): client = VizierServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2831,13 +3396,15 @@ async def test_complete_trial_async_from_dict(): def test_complete_trial_field_headers(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = vizier_service.CompleteTrialRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.complete_trial), "__call__") as call: @@ -2851,7 +3418,10 @@ def test_complete_trial_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2864,7 +3434,7 @@ async def test_complete_trial_field_headers_async(): # a field header. Set these to a non-empty value. request = vizier_service.CompleteTrialRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.complete_trial), "__call__") as call: @@ -2878,14 +3448,23 @@ async def test_complete_trial_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] -def test_delete_trial( - transport: str = "grpc", request_type=vizier_service.DeleteTrialRequest -): +@pytest.mark.parametrize( + "request_type", + [ + vizier_service.DeleteTrialRequest, + dict, + ], +) +def test_delete_trial(request_type, transport: str = "grpc"): client = VizierServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2907,15 +3486,12 @@ def test_delete_trial( assert response is None -def test_delete_trial_from_dict(): - test_delete_trial(request_type=dict) - - def test_delete_trial_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = VizierServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -2931,7 +3507,8 @@ async def test_delete_trial_async( transport: str = "grpc_asyncio", request_type=vizier_service.DeleteTrialRequest ): client = VizierServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -2959,13 +3536,15 @@ async def test_delete_trial_async_from_dict(): def test_delete_trial_field_headers(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = vizier_service.DeleteTrialRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_trial), "__call__") as call: @@ -2979,7 +3558,10 @@ def test_delete_trial_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -2992,7 +3574,7 @@ async def test_delete_trial_field_headers_async(): # a field header. Set these to a non-empty value. request = vizier_service.DeleteTrialRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_trial), "__call__") as call: @@ -3006,11 +3588,16 @@ async def test_delete_trial_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] def test_delete_trial_flattened(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.delete_trial), "__call__") as call: @@ -3018,23 +3605,30 @@ def test_delete_trial_flattened(): call.return_value = None # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.delete_trial(name="name_value",) + client.delete_trial( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val def test_delete_trial_flattened_error(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.delete_trial( - vizier_service.DeleteTrialRequest(), name="name_value", + vizier_service.DeleteTrialRequest(), + name="name_value", ) @@ -3052,13 +3646,17 @@ async def test_delete_trial_flattened_async(): call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.delete_trial(name="name_value",) + response = await client.delete_trial( + name="name_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].name == "name_value" + arg = args[0].name + mock_val = "name_value" + assert arg == mock_val @pytest.mark.asyncio @@ -3071,16 +3669,22 @@ async def test_delete_trial_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.delete_trial( - vizier_service.DeleteTrialRequest(), name="name_value", + vizier_service.DeleteTrialRequest(), + name="name_value", ) -def test_check_trial_early_stopping_state( - transport: str = "grpc", - request_type=vizier_service.CheckTrialEarlyStoppingStateRequest, -): +@pytest.mark.parametrize( + "request_type", + [ + vizier_service.CheckTrialEarlyStoppingStateRequest, + dict, + ], +) +def test_check_trial_early_stopping_state(request_type, transport: str = "grpc"): client = VizierServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3104,15 +3708,12 @@ def test_check_trial_early_stopping_state( assert isinstance(response, future.Future) -def test_check_trial_early_stopping_state_from_dict(): - test_check_trial_early_stopping_state(request_type=dict) - - def test_check_trial_early_stopping_state_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = VizierServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3131,7 +3732,8 @@ async def test_check_trial_early_stopping_state_async( request_type=vizier_service.CheckTrialEarlyStoppingStateRequest, ): client = VizierServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3163,13 +3765,15 @@ async def test_check_trial_early_stopping_state_async_from_dict(): def test_check_trial_early_stopping_state_field_headers(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = vizier_service.CheckTrialEarlyStoppingStateRequest() - request.trial_name = "trial_name/value" + request.trial_name = "trial_name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3185,7 +3789,10 @@ def test_check_trial_early_stopping_state_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "trial_name=trial_name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "trial_name=trial_name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -3198,7 +3805,7 @@ async def test_check_trial_early_stopping_state_field_headers_async(): # a field header. Set these to a non-empty value. request = vizier_service.CheckTrialEarlyStoppingStateRequest() - request.trial_name = "trial_name/value" + request.trial_name = "trial_name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3216,14 +3823,23 @@ async def test_check_trial_early_stopping_state_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "trial_name=trial_name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "trial_name=trial_name_value", + ) in kw["metadata"] -def test_stop_trial( - transport: str = "grpc", request_type=vizier_service.StopTrialRequest -): +@pytest.mark.parametrize( + "request_type", + [ + vizier_service.StopTrialRequest, + dict, + ], +) +def test_stop_trial(request_type, transport: str = "grpc"): client = VizierServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3258,15 +3874,12 @@ def test_stop_trial( assert response.custom_job == "custom_job_value" -def test_stop_trial_from_dict(): - test_stop_trial(request_type=dict) - - def test_stop_trial_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = VizierServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3282,7 +3895,8 @@ async def test_stop_trial_async( transport: str = "grpc_asyncio", request_type=vizier_service.StopTrialRequest ): client = VizierServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3325,13 +3939,15 @@ async def test_stop_trial_async_from_dict(): def test_stop_trial_field_headers(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = vizier_service.StopTrialRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.stop_trial), "__call__") as call: @@ -3345,7 +3961,10 @@ def test_stop_trial_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -3358,7 +3977,7 @@ async def test_stop_trial_field_headers_async(): # a field header. Set these to a non-empty value. request = vizier_service.StopTrialRequest() - request.name = "name/value" + request.name = "name_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.stop_trial), "__call__") as call: @@ -3372,14 +3991,23 @@ async def test_stop_trial_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "name=name/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "name=name_value", + ) in kw["metadata"] -def test_list_optimal_trials( - transport: str = "grpc", request_type=vizier_service.ListOptimalTrialsRequest -): +@pytest.mark.parametrize( + "request_type", + [ + vizier_service.ListOptimalTrialsRequest, + dict, + ], +) +def test_list_optimal_trials(request_type, transport: str = "grpc"): client = VizierServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3403,15 +4031,12 @@ def test_list_optimal_trials( assert isinstance(response, vizier_service.ListOptimalTrialsResponse) -def test_list_optimal_trials_from_dict(): - test_list_optimal_trials(request_type=dict) - - def test_list_optimal_trials_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = VizierServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. @@ -3430,7 +4055,8 @@ async def test_list_optimal_trials_async( request_type=vizier_service.ListOptimalTrialsRequest, ): client = VizierServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, @@ -3462,13 +4088,15 @@ async def test_list_optimal_trials_async_from_dict(): def test_list_optimal_trials_field_headers(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Any value that is part of the HTTP/1.1 URI should be sent as # a field header. Set these to a non-empty value. request = vizier_service.ListOptimalTrialsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3484,7 +4112,10 @@ def test_list_optimal_trials_field_headers(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] @pytest.mark.asyncio @@ -3497,7 +4128,7 @@ async def test_list_optimal_trials_field_headers_async(): # a field header. Set these to a non-empty value. request = vizier_service.ListOptimalTrialsRequest() - request.parent = "parent/value" + request.parent = "parent_value" # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3515,11 +4146,16 @@ async def test_list_optimal_trials_field_headers_async(): # Establish that the field header was sent. _, _, kw = call.mock_calls[0] - assert ("x-goog-request-params", "parent=parent/value",) in kw["metadata"] + assert ( + "x-goog-request-params", + "parent=parent_value", + ) in kw["metadata"] def test_list_optimal_trials_flattened(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( @@ -3529,23 +4165,30 @@ def test_list_optimal_trials_flattened(): call.return_value = vizier_service.ListOptimalTrialsResponse() # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - client.list_optimal_trials(parent="parent_value",) + client.list_optimal_trials( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) == 1 _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val def test_list_optimal_trials_flattened_error(): - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials(),) + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) # Attempting to call a method with both a request object and flattened # fields is an error. with pytest.raises(ValueError): client.list_optimal_trials( - vizier_service.ListOptimalTrialsRequest(), parent="parent_value", + vizier_service.ListOptimalTrialsRequest(), + parent="parent_value", ) @@ -3567,13 +4210,17 @@ async def test_list_optimal_trials_flattened_async(): ) # Call the method with a truthy value for each flattened field, # using the keyword arguments to the method. - response = await client.list_optimal_trials(parent="parent_value",) + response = await client.list_optimal_trials( + parent="parent_value", + ) # Establish that the underlying call was made with the expected # request object values. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0].parent == "parent_value" + arg = args[0].parent + mock_val = "parent_value" + assert arg == mock_val @pytest.mark.asyncio @@ -3586,7 +4233,8 @@ async def test_list_optimal_trials_flattened_error_async(): # fields is an error. with pytest.raises(ValueError): await client.list_optimal_trials( - vizier_service.ListOptimalTrialsRequest(), parent="parent_value", + vizier_service.ListOptimalTrialsRequest(), + parent="parent_value", ) @@ -3597,7 +4245,8 @@ def test_credentials_transport_error(): ) with pytest.raises(ValueError): client = VizierServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport=transport, + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, ) # It is an error to provide a credentials file and a transport instance. @@ -3610,13 +4259,34 @@ def test_credentials_transport_error(): transport=transport, ) + # It is an error to provide an api_key and a transport instance. + transport = transports.VizierServiceGrpcTransport( + credentials=ga_credentials.AnonymousCredentials(), + ) + options = client_options.ClientOptions() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = VizierServiceClient( + client_options=options, + transport=transport, + ) + + # It is an error to provide an api_key and a credential. + options = mock.Mock() + options.api_key = "api_key" + with pytest.raises(ValueError): + client = VizierServiceClient( + client_options=options, credentials=ga_credentials.AnonymousCredentials() + ) + # It is an error to provide scopes and a transport instance. transport = transports.VizierServiceGrpcTransport( credentials=ga_credentials.AnonymousCredentials(), ) with pytest.raises(ValueError): client = VizierServiceClient( - client_options={"scopes": ["1", "2"]}, transport=transport, + client_options={"scopes": ["1", "2"]}, + transport=transport, ) @@ -3659,10 +4329,28 @@ def test_transport_adc(transport_class): adc.assert_called_once() +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + ], +) +def test_transport_kind(transport_name): + transport = VizierServiceClient.get_transport_class(transport_name)( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert transport.kind == transport_name + + def test_transport_grpc_default(): # A client should use the gRPC transport by default. - client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials(),) - assert isinstance(client.transport, transports.VizierServiceGrpcTransport,) + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + assert isinstance( + client.transport, + transports.VizierServiceGrpcTransport, + ) def test_vizier_service_base_transport_error(): @@ -3702,18 +4390,38 @@ def test_vizier_service_base_transport(): "check_trial_early_stopping_state", "stop_trial", "list_optimal_trials", + "set_iam_policy", + "get_iam_policy", + "test_iam_permissions", + "get_location", + "list_locations", + "get_operation", + "wait_operation", + "cancel_operation", + "delete_operation", + "list_operations", ) for method in methods: with pytest.raises(NotImplementedError): getattr(transport, method)(request=object()) + with pytest.raises(NotImplementedError): + transport.close() + # Additionally, the LRO client (a property) should # also raise NotImplementedError with pytest.raises(NotImplementedError): transport.operations_client + # Catch all for all remaining methods and properties + remainder = [ + "kind", + ] + for r in remainder: + with pytest.raises(NotImplementedError): + getattr(transport, r)() + -@requires_google_auth_gte_1_25_0 def test_vizier_service_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -3724,7 +4432,8 @@ def test_vizier_service_base_transport_with_credentials_file(): Transport.return_value = None load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) transport = transports.VizierServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", + credentials_file="credentials.json", + quota_project_id="octopus", ) load_creds.assert_called_once_with( "credentials.json", @@ -3734,26 +4443,6 @@ def test_vizier_service_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_vizier_service_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.aiplatform_v1beta1.services.vizier_service.transports.VizierServiceTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.VizierServiceTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - def test_vizier_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( @@ -3765,7 +4454,6 @@ def test_vizier_service_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_vizier_service_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -3778,18 +4466,6 @@ def test_vizier_service_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_vizier_service_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - VizierServiceClient() - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -3797,7 +4473,6 @@ def test_vizier_service_auth_adc_old_google_auth(): transports.VizierServiceGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_vizier_service_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -3811,26 +4486,6 @@ def test_vizier_service_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.VizierServiceGrpcTransport, - transports.VizierServiceGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_vizier_service_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=("https://www.googleapis.com/auth/cloud-platform",), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ @@ -3838,7 +4493,6 @@ def test_vizier_service_transport_auth_adc_old_google_auth(transport_class): (transports.VizierServiceGrpcAsyncIOTransport, grpc_helpers_async), ], ) -@requires_api_core_gte_1_26_0 def test_vizier_service_transport_create_channel(transport_class, grpc_helpers): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -3867,79 +4521,6 @@ def test_vizier_service_transport_create_channel(transport_class, grpc_helpers): ) -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.VizierServiceGrpcTransport, grpc_helpers), - (transports.VizierServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_vizier_service_transport_create_channel_old_api_core( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - transport_class(quota_project_id="octopus") - - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=("https://www.googleapis.com/auth/cloud-platform",), - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - -@pytest.mark.parametrize( - "transport_class,grpc_helpers", - [ - (transports.VizierServiceGrpcTransport, grpc_helpers), - (transports.VizierServiceGrpcAsyncIOTransport, grpc_helpers_async), - ], -) -@requires_api_core_lt_1_26_0 -def test_vizier_service_transport_create_channel_user_scopes( - transport_class, grpc_helpers -): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object( - google.auth, "default", autospec=True - ) as adc, mock.patch.object( - grpc_helpers, "create_channel", autospec=True - ) as create_channel: - creds = ga_credentials.AnonymousCredentials() - adc.return_value = (creds, None) - - transport_class(quota_project_id="octopus", scopes=["1", "2"]) - - create_channel.assert_called_with( - "aiplatform.googleapis.com:443", - credentials=creds, - credentials_file=None, - quota_project_id="octopus", - scopes=["1", "2"], - ssl_credentials=None, - options=[ - ("grpc.max_send_message_length", -1), - ("grpc.max_receive_message_length", -1), - ], - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -3962,7 +4543,7 @@ def test_vizier_service_grpc_transport_client_cert_source_for_mtls(transport_cla "squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_channel_creds, quota_project_id=None, options=[ @@ -3985,24 +4566,40 @@ def test_vizier_service_grpc_transport_client_cert_source_for_mtls(transport_cla ) -def test_vizier_service_host_no_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_vizier_service_host_no_port(transport_name): client = VizierServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="aiplatform.googleapis.com" ), + transport=transport_name, ) - assert client.transport._host == "aiplatform.googleapis.com:443" + assert client.transport._host == ("aiplatform.googleapis.com:443") -def test_vizier_service_host_with_port(): +@pytest.mark.parametrize( + "transport_name", + [ + "grpc", + "grpc_asyncio", + ], +) +def test_vizier_service_host_with_port(transport_name): client = VizierServiceClient( credentials=ga_credentials.AnonymousCredentials(), client_options=client_options.ClientOptions( api_endpoint="aiplatform.googleapis.com:8000" ), + transport=transport_name, ) - assert client.transport._host == "aiplatform.googleapis.com:8000" + assert client.transport._host == ("aiplatform.googleapis.com:8000") def test_vizier_service_grpc_transport_channel(): @@ -4010,7 +4607,8 @@ def test_vizier_service_grpc_transport_channel(): # Check that channel is used if provided. transport = transports.VizierServiceGrpcTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -4022,7 +4620,8 @@ def test_vizier_service_grpc_asyncio_transport_channel(): # Check that channel is used if provided. transport = transports.VizierServiceGrpcAsyncIOTransport( - host="squid.clam.whelk", channel=channel, + host="squid.clam.whelk", + channel=channel, ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" @@ -4069,7 +4668,7 @@ def test_vizier_service_transport_channel_mtls_with_client_cert_source(transport "mtls.squid.clam.whelk:443", credentials=cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -4116,7 +4715,7 @@ def test_vizier_service_transport_channel_mtls_with_adc(transport_class): "mtls.squid.clam.whelk:443", credentials=mock_cred, credentials_file=None, - scopes=("https://www.googleapis.com/auth/cloud-platform",), + scopes=None, ssl_credentials=mock_ssl_cred, quota_project_id=None, options=[ @@ -4129,12 +4728,16 @@ def test_vizier_service_transport_channel_mtls_with_adc(transport_class): def test_vizier_service_grpc_lro_client(): client = VizierServiceClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -4142,12 +4745,16 @@ def test_vizier_service_grpc_lro_client(): def test_vizier_service_grpc_lro_async_client(): client = VizierServiceAsyncClient( - credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", ) transport = client.transport # Ensure that we have a api-core operations client. - assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient,) + assert isinstance( + transport.operations_client, + operations_v1.OperationsAsyncClient, + ) # Ensure that subsequent calls to the property send the exact same object. assert transport.operations_client is transport.operations_client @@ -4158,7 +4765,9 @@ def test_custom_job_path(): location = "clam" custom_job = "whelk" expected = "projects/{project}/locations/{location}/customJobs/{custom_job}".format( - project=project, location=location, custom_job=custom_job, + project=project, + location=location, + custom_job=custom_job, ) actual = VizierServiceClient.custom_job_path(project, location, custom_job) assert expected == actual @@ -4182,7 +4791,9 @@ def test_study_path(): location = "mussel" study = "winkle" expected = "projects/{project}/locations/{location}/studies/{study}".format( - project=project, location=location, study=study, + project=project, + location=location, + study=study, ) actual = VizierServiceClient.study_path(project, location, study) assert expected == actual @@ -4206,8 +4817,13 @@ def test_trial_path(): location = "clam" study = "whelk" trial = "octopus" - expected = "projects/{project}/locations/{location}/studies/{study}/trials/{trial}".format( - project=project, location=location, study=study, trial=trial, + expected = ( + "projects/{project}/locations/{location}/studies/{study}/trials/{trial}".format( + project=project, + location=location, + study=study, + trial=trial, + ) ) actual = VizierServiceClient.trial_path(project, location, study, trial) assert expected == actual @@ -4249,7 +4865,9 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): folder = "scallop" - expected = "folders/{folder}".format(folder=folder,) + expected = "folders/{folder}".format( + folder=folder, + ) actual = VizierServiceClient.common_folder_path(folder) assert expected == actual @@ -4267,7 +4885,9 @@ def test_parse_common_folder_path(): def test_common_organization_path(): organization = "squid" - expected = "organizations/{organization}".format(organization=organization,) + expected = "organizations/{organization}".format( + organization=organization, + ) actual = VizierServiceClient.common_organization_path(organization) assert expected == actual @@ -4285,7 +4905,9 @@ def test_parse_common_organization_path(): def test_common_project_path(): project = "whelk" - expected = "projects/{project}".format(project=project,) + expected = "projects/{project}".format( + project=project, + ) actual = VizierServiceClient.common_project_path(project) assert expected == actual @@ -4305,7 +4927,8 @@ def test_common_location_path(): project = "oyster" location = "nudibranch" expected = "projects/{project}/locations/{location}".format( - project=project, location=location, + project=project, + location=location, ) actual = VizierServiceClient.common_location_path(project, location) assert expected == actual @@ -4323,14 +4946,15 @@ def test_parse_common_location_path(): assert expected == actual -def test_client_withDEFAULT_CLIENT_INFO(): +def test_client_with_default_client_info(): client_info = gapic_v1.client_info.ClientInfo() with mock.patch.object( transports.VizierServiceTransport, "_prep_wrapped_messages" ) as prep: client = VizierServiceClient( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) @@ -4339,6 +4963,1591 @@ def test_client_withDEFAULT_CLIENT_INFO(): ) as prep: transport_class = VizierServiceClient.get_transport_class() transport = transport_class( - credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, + credentials=ga_credentials.AnonymousCredentials(), + client_info=client_info, ) prep.assert_called_once_with(client_info) + + +@pytest.mark.asyncio +async def test_transport_close_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport="grpc_asyncio", + ) + with mock.patch.object( + type(getattr(client.transport, "grpc_channel")), "close" + ) as close: + async with client: + close.assert_not_called() + close.assert_called_once() + + +def test_delete_operation(transport: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_delete_operation(transport: str = "grpc"): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.DeleteOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_delete_operation_field_headers(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = None + + client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_delete_operation_field_headers_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.DeleteOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.delete_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_delete_operation_from_dict(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_delete_operation_from_dict_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.delete_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_cancel_operation(transport: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + response = client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +@pytest.mark.asyncio +async def test_cancel_operation(transport: str = "grpc"): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.CancelOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert response is None + + +def test_cancel_operation_field_headers(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = None + + client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_cancel_operation_field_headers_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.CancelOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + await client.cancel_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_cancel_operation_from_dict(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + response = client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_cancel_operation_from_dict_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) + response = await client.cancel_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_wait_operation(transport: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_wait_operation(transport: str = "grpc"): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.WaitOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_wait_operation_field_headers(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_wait_operation_field_headers_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.WaitOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.wait_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_wait_operation_from_dict(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_wait_operation_from_dict_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.wait_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_operation(transport: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + response = client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +@pytest.mark.asyncio +async def test_get_operation(transport: str = "grpc"): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.GetOperationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.Operation) + + +def test_get_operation_field_headers(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = operations_pb2.Operation() + + client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_operation_field_headers_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.GetOperationRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_get_operation_from_dict(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + response = client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_operation_from_dict_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + response = await client.get_operation( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_operations(transport: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + response = client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +@pytest.mark.asyncio +async def test_list_operations(transport: str = "grpc"): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = operations_pb2.ListOperationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, operations_pb2.ListOperationsResponse) + + +def test_list_operations_field_headers(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_operations_field_headers_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = operations_pb2.ListOperationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_operations_from_dict(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + response = client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_operations_from_dict_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + response = await client.list_operations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_list_locations(transport: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + response = client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +@pytest.mark.asyncio +async def test_list_locations(transport: str = "grpc"): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.ListLocationsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.ListLocationsResponse) + + +def test_list_locations_field_headers(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_list_locations_field_headers_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.ListLocationsRequest() + request.name = "locations" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations", + ) in kw["metadata"] + + +def test_list_locations_from_dict(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + response = client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_list_locations_from_dict_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + response = await client.list_locations( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_get_location(transport: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + response = client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +@pytest.mark.asyncio +async def test_get_location_async(transport: str = "grpc_asyncio"): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = locations_pb2.GetLocationRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, locations_pb2.Location) + + +def test_get_location_field_headers(): + client = VizierServiceClient(credentials=ga_credentials.AnonymousCredentials()) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = locations_pb2.Location() + + client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_location_field_headers_async(): + client = VizierServiceAsyncClient(credentials=ga_credentials.AnonymousCredentials()) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = locations_pb2.GetLocationRequest() + request.name = "locations/abc" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "name=locations/abc", + ) in kw["metadata"] + + +def test_get_location_from_dict(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + response = client.get_location( + request={ + "name": "locations/abc", + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_location_from_dict_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + response = await client.get_location( + request={ + "name": "locations", + } + ) + call.assert_called() + + +def test_set_iam_policy(transport: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + response = client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_set_iam_policy_async(transport: str = "grpc_asyncio"): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.SetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + response = await client.set_iam_policy(request) + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_set_iam_policy_field_headers(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_set_iam_policy_field_headers_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.SetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.set_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_set_iam_policy_from_dict(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_set_iam_policy_from_dict_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.set_iam_policy( + request={ + "resource": "resource_value", + "policy": policy_pb2.Policy(version=774), + } + ) + call.assert_called() + + +def test_get_iam_policy(transport: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + + response = client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +@pytest.mark.asyncio +async def test_get_iam_policy_async(transport: str = "grpc_asyncio"): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.GetIamPolicyRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy( + version=774, + etag=b"etag_blob", + ) + ) + + response = await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, policy_pb2.Policy) + + assert response.version == 774 + + assert response.etag == b"etag_blob" + + +def test_get_iam_policy_field_headers(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = policy_pb2.Policy() + + client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_get_iam_policy_field_headers_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.GetIamPolicyRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + await client.get_iam_policy(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_get_iam_policy_from_dict(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + response = client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_get_iam_policy_from_dict_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(policy_pb2.Policy()) + + response = await client.get_iam_policy( + request={ + "resource": "resource_value", + "options": options_pb2.GetPolicyOptions(requested_policy_version=2598), + } + ) + call.assert_called() + + +def test_test_iam_permissions(transport: str = "grpc"): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + + response = client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_async(transport: str = "grpc_asyncio"): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + transport=transport, + ) + + # Everything is optional in proto3 as far as the runtime is concerned, + # and we are mocking out the actual API, so just send an empty request. + request = iam_policy_pb2.TestIamPermissionsRequest() + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse( + permissions=["permissions_value"], + ) + ) + + response = await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + + assert args[0] == request + + # Establish that the response is the type that we expect. + assert isinstance(response, iam_policy_pb2.TestIamPermissionsResponse) + + assert response.permissions == ["permissions_value"] + + +def test_test_iam_permissions_field_headers(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +@pytest.mark.asyncio +async def test_test_iam_permissions_field_headers_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Any value that is part of the HTTP/1.1 URI should be sent as + # a field header. Set these to a non-empty value. + request = iam_policy_pb2.TestIamPermissionsRequest() + request.resource = "resource/value" + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions(request) + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) + _, args, _ = call.mock_calls[0] + assert args[0] == request + + # Establish that the field header was sent. + _, _, kw = call.mock_calls[0] + assert ( + "x-goog-request-params", + "resource=resource/value", + ) in kw["metadata"] + + +def test_test_iam_permissions_from_dict(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + response = client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_from_dict_async(): + client = VizierServiceAsyncClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object( + type(client.transport.test_iam_permissions), "__call__" + ) as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + response = await client.test_iam_permissions( + request={ + "resource": "resource_value", + "permissions": ["permissions_value"], + } + ) + call.assert_called() + + +def test_transport_close(): + transports = { + "grpc": "_grpc_channel", + } + + for transport, close_name in transports.items(): + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + with mock.patch.object( + type(getattr(client.transport, close_name)), "close" + ) as close: + with client: + close.assert_not_called() + close.assert_called_once() + + +def test_client_ctx(): + transports = [ + "grpc", + ] + for transport in transports: + client = VizierServiceClient( + credentials=ga_credentials.AnonymousCredentials(), transport=transport + ) + # Test client calls underlying transport. + with mock.patch.object(type(client.transport), "close") as close: + close.assert_not_called() + with client: + pass + close.assert_called() + + +@pytest.mark.parametrize( + "client_class,transport_class", + [ + (VizierServiceClient, transports.VizierServiceGrpcTransport), + (VizierServiceAsyncClient, transports.VizierServiceGrpcAsyncIOTransport), + ], +) +def test_api_key_credentials(client_class, transport_class): + with mock.patch.object( + google.auth._default, "get_api_key_credentials", create=True + ) as get_api_key_credentials: + mock_cred = mock.Mock() + get_api_key_credentials.return_value = mock_cred + options = client_options.ClientOptions() + options.api_key = "api_key" + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options) + patched.assert_called_once_with( + credentials=mock_cred, + credentials_file=None, + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) diff --git a/tests/unit/gapic/definition_v1/__init__.py b/tests/unit/gapic/definition_v1/__init__.py new file mode 100644 index 0000000000..e8e1c3845d --- /dev/null +++ b/tests/unit/gapic/definition_v1/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# diff --git a/tests/unit/gapic/definition_v1beta1/__init__.py b/tests/unit/gapic/definition_v1beta1/__init__.py new file mode 100644 index 0000000000..e8e1c3845d --- /dev/null +++ b/tests/unit/gapic/definition_v1beta1/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# diff --git a/tests/unit/gapic/instance_v1/__init__.py b/tests/unit/gapic/instance_v1/__init__.py new file mode 100644 index 0000000000..e8e1c3845d --- /dev/null +++ b/tests/unit/gapic/instance_v1/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# diff --git a/tests/unit/gapic/instance_v1beta1/__init__.py b/tests/unit/gapic/instance_v1beta1/__init__.py new file mode 100644 index 0000000000..e8e1c3845d --- /dev/null +++ b/tests/unit/gapic/instance_v1beta1/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# diff --git a/tests/unit/gapic/params_v1/__init__.py b/tests/unit/gapic/params_v1/__init__.py new file mode 100644 index 0000000000..e8e1c3845d --- /dev/null +++ b/tests/unit/gapic/params_v1/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# diff --git a/tests/unit/gapic/params_v1beta1/__init__.py b/tests/unit/gapic/params_v1beta1/__init__.py new file mode 100644 index 0000000000..e8e1c3845d --- /dev/null +++ b/tests/unit/gapic/params_v1beta1/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# diff --git a/tests/unit/gapic/prediction_v1/__init__.py b/tests/unit/gapic/prediction_v1/__init__.py new file mode 100644 index 0000000000..e8e1c3845d --- /dev/null +++ b/tests/unit/gapic/prediction_v1/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +# diff --git a/tests/unit/gapic/prediction_v1beta1/__init__.py b/tests/unit/gapic/prediction_v1beta1/__init__.py new file mode 100644 index 0000000000..e8e1c3845d --- /dev/null +++ b/tests/unit/gapic/prediction_v1beta1/__init__.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Copyright 2022 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. +#